Compare commits
2 Commits
5f9afca286
...
339371125f
| Author | SHA1 | Date |
|---|---|---|
|
|
339371125f | 2 years ago |
|
|
9bb87ca1ca | 2 years ago |
14 changed files with 589 additions and 41 deletions
@ -0,0 +1,61 @@ |
|||||||
|
package xyz.mineconomia.mineconomiacore.commands; |
||||||
|
|
||||||
|
import org.bukkit.Bukkit; |
||||||
|
import org.bukkit.Material; |
||||||
|
import org.bukkit.Sound; |
||||||
|
import org.bukkit.command.Command; |
||||||
|
import org.bukkit.command.CommandExecutor; |
||||||
|
import org.bukkit.command.CommandSender; |
||||||
|
import org.bukkit.entity.Player; |
||||||
|
import org.bukkit.inventory.Inventory; |
||||||
|
import org.bukkit.inventory.ItemStack; |
||||||
|
import org.bukkit.plugin.Plugin; |
||||||
|
import org.jetbrains.annotations.NotNull; |
||||||
|
import xyz.mineconomia.mineconomiacore.MineconomiaCore; |
||||||
|
import xyz.mineconomia.mineconomiacore.events.shopInteract; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Collections; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
public class gamble implements CommandExecutor { |
||||||
|
@Override |
||||||
|
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) { |
||||||
|
Inventory gambleGui = Bukkit.createInventory(null, 27, "GAMBLE GAMBLE GAMBLE"); |
||||||
|
for (int i = 0; i<9; i++){ |
||||||
|
gambleGui.setItem( i,shopInteract.newItemStack(" ", Material.BLACK_STAINED_GLASS_PANE)); |
||||||
|
gambleGui.setItem( i + 18,shopInteract.newItemStack(" ", Material.BLACK_STAINED_GLASS_PANE)); |
||||||
|
} |
||||||
|
gambleGui.setItem(4, shopInteract.newItemStack(" ", Material.LIME_STAINED_GLASS_PANE)); |
||||||
|
gambleGui.setItem(22, shopInteract.newItemStack(" ", Material.LIME_STAINED_GLASS_PANE)); |
||||||
|
Player p = (Player) commandSender; |
||||||
|
|
||||||
|
List<ItemStack> itemStackList = new ArrayList<>(); |
||||||
|
for (Material m : Material.values()){ |
||||||
|
gambleGui.setItem(15, new ItemStack(m)); |
||||||
|
if (gambleGui.getItem(15) != null){ |
||||||
|
itemStackList.add(new ItemStack(m)); |
||||||
|
} |
||||||
|
} |
||||||
|
p.openInventory(gambleGui); |
||||||
|
Collections.shuffle(itemStackList); |
||||||
|
for(int i = 0; i < 100; i++){ |
||||||
|
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(MineconomiaCore.getPlugin(MineconomiaCore.class), new Runnable() { |
||||||
|
public void run() { |
||||||
|
ItemStack itemStackToEnd = itemStackList.get(0); |
||||||
|
itemStackList.remove(0); |
||||||
|
itemStackList.add(itemStackToEnd); |
||||||
|
for (int i = 0; i<9; i++){ |
||||||
|
gambleGui.setItem(i+9, itemStackList.get(i)); |
||||||
|
if (gambleGui.getItem(i+9) == null){ |
||||||
|
gambleGui.setItem(i+9, new ItemStack(Material.STICK)); |
||||||
|
} |
||||||
|
} |
||||||
|
p.playSound(p, Sound.BLOCK_NOTE_BLOCK_BANJO, 100, 1); |
||||||
|
} |
||||||
|
}, Long.parseLong(String.valueOf(i+1))); |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,36 @@ |
|||||||
|
package xyz.mineconomia.mineconomiacore.commands; |
||||||
|
|
||||||
|
import com.arangodb.ArangoCollection; |
||||||
|
import com.arangodb.entity.BaseDocument; |
||||||
|
import org.bukkit.command.Command; |
||||||
|
import org.bukkit.command.CommandExecutor; |
||||||
|
import org.bukkit.command.CommandSender; |
||||||
|
import org.bukkit.entity.Player; |
||||||
|
import org.bukkit.inventory.ItemStack; |
||||||
|
import org.jetbrains.annotations.NotNull; |
||||||
|
import xyz.mineconomia.mineconomiacore.serialization; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
import static xyz.mineconomia.mineconomiacore.database.database; |
||||||
|
|
||||||
|
public class sample implements CommandExecutor { |
||||||
|
@Override |
||||||
|
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) { |
||||||
|
ArangoCollection collection = database.collection("shops"); |
||||||
|
if (collection.documentExists(strings[0])){ |
||||||
|
BaseDocument baseDocument = collection.getDocument(strings[0], BaseDocument.class); |
||||||
|
Map<String, Object> shopData = baseDocument.getProperties(); |
||||||
|
shopData.get("item"); |
||||||
|
try { |
||||||
|
((Player) commandSender).getInventory().addItem((ItemStack) serialization.stringToBukkitObject((String) shopData.get("item"))); |
||||||
|
} catch (IOException | ClassNotFoundException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} |
||||||
|
}else{ |
||||||
|
commandSender.sendMessage("Shop není!"); |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,21 @@ |
|||||||
|
package xyz.mineconomia.mineconomiacore.commands; |
||||||
|
|
||||||
|
import org.bukkit.Bukkit; |
||||||
|
import org.bukkit.ChatColor; |
||||||
|
import org.bukkit.command.Command; |
||||||
|
import org.bukkit.command.CommandExecutor; |
||||||
|
import org.bukkit.command.CommandSender; |
||||||
|
import org.bukkit.entity.Player; |
||||||
|
import org.bukkit.persistence.PersistentDataType; |
||||||
|
import org.jetbrains.annotations.NotNull; |
||||||
|
import xyz.mineconomia.mineconomiacore.PDC; |
||||||
|
|
||||||
|
public class sell implements CommandExecutor { |
||||||
|
@Override |
||||||
|
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) { |
||||||
|
Player p = (Player) commandSender; |
||||||
|
PDC.WritePlayerPDC(p, "sellGUIOpen", PersistentDataType.INTEGER, 1); |
||||||
|
p.openInventory(Bukkit.createInventory(null, 36, ChatColor.GREEN + "" + ChatColor.BOLD + "Vlož itemy, které chceš prodat")); |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,127 @@ |
|||||||
|
package xyz.mineconomia.mineconomiacore.events; |
||||||
|
|
||||||
|
import net.milkbowl.vault.economy.Economy; |
||||||
|
import org.bukkit.Bukkit; |
||||||
|
import org.bukkit.ChatColor; |
||||||
|
import org.bukkit.OfflinePlayer; |
||||||
|
import org.bukkit.entity.Player; |
||||||
|
import org.bukkit.event.EventHandler; |
||||||
|
import org.bukkit.event.Listener; |
||||||
|
import org.bukkit.event.inventory.InventoryAction; |
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent; |
||||||
|
import org.bukkit.event.inventory.InventoryCloseEvent; |
||||||
|
import org.bukkit.inventory.Inventory; |
||||||
|
import org.bukkit.inventory.ItemStack; |
||||||
|
import xyz.mineconomia.mineconomiacore.MineconomiaCore; |
||||||
|
import xyz.mineconomia.mineconomiacore.invTools; |
||||||
|
import xyz.mineconomia.mineconomiacore.serialization; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Objects; |
||||||
|
|
||||||
|
|
||||||
|
public class shopGuiInteract implements Listener { |
||||||
|
public static HashMap<Player, Map<String, Object>> storeDatas = new HashMap<>(); |
||||||
|
@EventHandler |
||||||
|
public void clickEvent(InventoryClickEvent event) throws IOException, ClassNotFoundException { |
||||||
|
Player player = (Player) event.getWhoClicked(); |
||||||
|
Map<String, Object> storeData = storeDatas.get(player); |
||||||
|
|
||||||
|
if (storeData == null) return; |
||||||
|
|
||||||
|
event.setCancelled(true); |
||||||
|
|
||||||
|
if (!event.getAction().equals(InventoryAction.PICKUP_ALL)) return; |
||||||
|
|
||||||
|
String noSpaceMessage; |
||||||
|
String noMoneyMessage; |
||||||
|
String successUserMessage; |
||||||
|
String successUserMessageEight; |
||||||
|
String successOwnerMessage; |
||||||
|
String successOwnerMessageEight; |
||||||
|
String noItemsMessage; |
||||||
|
String count = (String) storeData.get("count"); |
||||||
|
String price = (String) storeData.get("price"); |
||||||
|
String countEight = (String) storeData.get("countEight"); |
||||||
|
String priceEight = (String) storeData.get("priceEight"); |
||||||
|
String itemType = ((String) storeData.get("itemType")).toLowerCase(); |
||||||
|
ItemStack item = (ItemStack) serialization.stringToBukkitObject((String) storeData.get("item")); |
||||||
|
Inventory buyerInventory = (Inventory) storeData.get("buyerInventory"); |
||||||
|
Inventory sellerInventory = (Inventory) storeData.get("sellerInventory"); |
||||||
|
OfflinePlayer buyer = (OfflinePlayer) storeData.get("buyer"); |
||||||
|
OfflinePlayer seller = (OfflinePlayer) storeData.get("seller"); |
||||||
|
OfflinePlayer owner = Bukkit.getOfflinePlayer((String) storeData.get("owner")); |
||||||
|
Economy eco = MineconomiaCore.getEconomy(); |
||||||
|
|
||||||
|
if (storeData.get("regime").equals("buy")){ |
||||||
|
noSpaceMessage = ChatColor.RED + "Nemáš dost místa v inventáři"; |
||||||
|
noMoneyMessage = ChatColor.RED + "Nemáš dost peněz"; |
||||||
|
noItemsMessage = ChatColor.RED + "Prodejce nemá dost itemů ve skladišti"; |
||||||
|
successUserMessage = ChatColor.GREEN + "Koupil jsi" + count + "x " + itemType + "za" + price; |
||||||
|
successUserMessageEight = ChatColor.GREEN + "Koupil jsi" + countEight + "x " + itemType + " za " + priceEight + "$"; |
||||||
|
successOwnerMessage = ChatColor.GREEN + "Hráč " + player.getDisplayName() + "si koupil " + count + "x " + itemType + " za " + price + "%"; |
||||||
|
successOwnerMessageEight = ChatColor.GREEN + "Hráč " + player.getDisplayName() + "si koupil " + countEight + "x " + itemType + " za " + priceEight + "%"; |
||||||
|
}else{ |
||||||
|
noSpaceMessage = ChatColor.RED + "Prodejce nemá dost místa ve skladišti"; |
||||||
|
noMoneyMessage = ChatColor.RED + "Prodejce nemá dost peněz"; |
||||||
|
noItemsMessage = ChatColor.RED + "Nemáš dost itemů"; |
||||||
|
successUserMessage = ChatColor.GREEN + "Prodal jsi" + count + "x " + itemType + "za" + price; |
||||||
|
successUserMessageEight = ChatColor.GREEN + "Prodal jsi" + countEight + "x " + itemType + " za " + priceEight + "$"; |
||||||
|
successOwnerMessage = ChatColor.GREEN + "Hráč " + player.getDisplayName() + "ti prodal " + count + "x " + itemType + " za " + price + "%"; |
||||||
|
successOwnerMessageEight = ChatColor.GREEN + "Hráč " + player.getDisplayName() + "ti prodal " + countEight + "x " + itemType + " za " + priceEight + "%"; |
||||||
|
|
||||||
|
} |
||||||
|
double finalPrice = Double.parseDouble(price); |
||||||
|
int finalCount = Integer.parseInt(count); |
||||||
|
int slot = event.getSlot(); |
||||||
|
if (slot == 1){ |
||||||
|
finalCount = Integer.parseInt(countEight); |
||||||
|
finalPrice = Double.parseDouble(priceEight); |
||||||
|
} |
||||||
|
if (slot == 0 || slot == 1){ |
||||||
|
if (seller.equals(buyer)){ |
||||||
|
player.sendMessage(ChatColor.RED + "Sám sobě nic prodat nemůžeš"); |
||||||
|
return; |
||||||
|
} |
||||||
|
if(invTools.getFreeSpaceForItem(buyerInventory, item) < finalCount){ |
||||||
|
player.sendMessage(noSpaceMessage); |
||||||
|
return; |
||||||
|
} |
||||||
|
if (finalPrice > eco.getBalance(buyer)){ |
||||||
|
player.sendMessage(noMoneyMessage); |
||||||
|
return; |
||||||
|
} |
||||||
|
if (invTools.itemAmount(sellerInventory, item) < finalCount){ |
||||||
|
player.sendMessage(noItemsMessage); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
item.setAmount(finalCount); |
||||||
|
sellerInventory.removeItem(item); |
||||||
|
buyerInventory.addItem(item); |
||||||
|
eco.withdrawPlayer(buyer, finalPrice); |
||||||
|
eco.depositPlayer(seller, finalPrice); |
||||||
|
if (slot == 0){ |
||||||
|
player.sendMessage(successUserMessage); |
||||||
|
sendIfOnline(owner, successOwnerMessage); |
||||||
|
}else{ |
||||||
|
player.sendMessage(successUserMessageEight); |
||||||
|
sendIfOnline(owner, successOwnerMessageEight); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
@EventHandler |
||||||
|
public void closeEvent(InventoryCloseEvent event){ |
||||||
|
Player player = (Player) event.getPlayer(); |
||||||
|
storeDatas.remove(player); |
||||||
|
} |
||||||
|
|
||||||
|
public static void sendIfOnline(OfflinePlayer player, String message){ |
||||||
|
if (player.isOnline()) Objects.requireNonNull(player.getPlayer()).sendMessage(message); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,140 @@ |
|||||||
|
package xyz.mineconomia.mineconomiacore.events; |
||||||
|
|
||||||
|
import com.arangodb.ArangoCollection; |
||||||
|
import com.arangodb.entity.BaseDocument; |
||||||
|
import org.bukkit.*; |
||||||
|
import org.bukkit.block.BlockState; |
||||||
|
import org.bukkit.block.Container; |
||||||
|
import org.bukkit.block.Sign; |
||||||
|
import org.bukkit.entity.Player; |
||||||
|
import org.bukkit.event.EventHandler; |
||||||
|
import org.bukkit.event.Listener; |
||||||
|
import org.bukkit.event.block.Action; |
||||||
|
import org.bukkit.event.player.PlayerInteractEvent; |
||||||
|
import org.bukkit.inventory.Inventory; |
||||||
|
import org.bukkit.inventory.ItemStack; |
||||||
|
import org.bukkit.inventory.meta.ItemMeta; |
||||||
|
import org.bukkit.persistence.PersistentDataType; |
||||||
|
import xyz.mineconomia.mineconomiacore.PDC; |
||||||
|
import xyz.mineconomia.mineconomiacore.serialization; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.text.DecimalFormat; |
||||||
|
import java.text.NumberFormat; |
||||||
|
import java.util.*; |
||||||
|
|
||||||
|
import static xyz.mineconomia.mineconomiacore.database.database; |
||||||
|
|
||||||
|
public class shopInteract implements Listener { |
||||||
|
|
||||||
|
@EventHandler |
||||||
|
public static void savePosition(PlayerInteractEvent event) throws IOException, ClassNotFoundException { |
||||||
|
if (event.getAction() == Action.RIGHT_CLICK_BLOCK){ |
||||||
|
Player player = event.getPlayer(); |
||||||
|
BlockState blockState = Objects.requireNonNull(event.getClickedBlock()).getState(); |
||||||
|
if (blockState instanceof Sign sign){ |
||||||
|
if (PDC.GetTileStatePDC(sign, "shop", PersistentDataType.STRING) != null){ |
||||||
|
ArangoCollection collection = database.collection("shops"); |
||||||
|
event.setCancelled(true); |
||||||
|
String shopid = (String) PDC.GetTileStatePDC(sign, "shop", PersistentDataType.STRING); |
||||||
|
player.sendMessage(ChatColor.GREEN + "Načítám data obchodu..."); |
||||||
|
if (collection.documentExists(shopid)){ |
||||||
|
BaseDocument baseDocument = collection.getDocument(shopid, BaseDocument.class); |
||||||
|
Map<String, Object> shopData = baseDocument.getProperties(); |
||||||
|
NumberFormat formatInteger = new DecimalFormat("0"); |
||||||
|
NumberFormat formatter = new DecimalFormat("0.00"); |
||||||
|
String regime = (String) shopData.get("regime"); |
||||||
|
String ownerPrefix = ""; |
||||||
|
if (((String) shopData.get("type")).contains("group")){ |
||||||
|
ownerPrefix = "Skupina "; |
||||||
|
} |
||||||
|
String count = (String) formatInteger.format(shopData.get("count")); |
||||||
|
String price = formatter.format( shopData.get("price")); |
||||||
|
String countEight = formatInteger.format(Math.multiplyExact((Long) shopData.get("count"), 8)); |
||||||
|
String priceEight = formatter.format(Math.multiplyExact((Long) shopData.get("price"),8)); |
||||||
|
Inventory inventory; |
||||||
|
Inventory sellerInventory; |
||||||
|
Inventory buyerInventory; |
||||||
|
String shopPrefix; |
||||||
|
OfflinePlayer buyer; |
||||||
|
OfflinePlayer seller; |
||||||
|
|
||||||
|
String shopErrorMoney; |
||||||
|
String shopErrorProduct; |
||||||
|
Material shopMaterial; |
||||||
|
Material shopErrorMaterial; |
||||||
|
if (shopData.get("regime").equals("buy")) { |
||||||
|
sellerInventory = ((Container) ((Location) serialization.stringToBukkitObject((String) shopData.get("containerLocation"))).getBlock().getState()).getInventory(); |
||||||
|
buyerInventory = player.getInventory(); |
||||||
|
shopPrefix = "&aKoupit "; |
||||||
|
shopMaterial = Material.LIME_WOOL; |
||||||
|
shopErrorMaterial = Material.LIME_STAINED_GLASS; |
||||||
|
inventory = Bukkit.createInventory(null, 9, ChatColor.DARK_GREEN+ ""+ChatColor.BOLD +"Prodej"); |
||||||
|
shopErrorMoney = "&cNemáš dost peněz"; |
||||||
|
shopErrorProduct = "&cMajitel nemá dostatek itemů"; |
||||||
|
buyer = player; |
||||||
|
seller = Bukkit.getOfflinePlayer((String) shopData.get("owner")); |
||||||
|
|
||||||
|
}else{ |
||||||
|
sellerInventory = player.getInventory();; |
||||||
|
buyerInventory = ((Container) ((Location) serialization.stringToBukkitObject((String) shopData.get("containerLocation"))).getBlock().getState()).getInventory(); |
||||||
|
shopPrefix = "&eProdat "; |
||||||
|
shopMaterial = Material.YELLOW_WOOL; |
||||||
|
shopErrorMaterial = Material.YELLOW_STAINED_GLASS; |
||||||
|
inventory = Bukkit.createInventory(null, 9, ChatColor.GOLD + ""+ ChatColor.BOLD +"Výkup"); |
||||||
|
shopErrorMoney = "&cMajitel nemá dost peněz"; |
||||||
|
shopErrorProduct = "&cNemáš dostatek itemů"; |
||||||
|
buyer = Bukkit.getOfflinePlayer((String) shopData.get("owner")); |
||||||
|
seller = player; |
||||||
|
} |
||||||
|
|
||||||
|
inventory.setItem(0, newItemStack(shopPrefix + count + "ks za " + price + "$", shopMaterial)); |
||||||
|
inventory.setItem(1, newItemStack(shopPrefix + countEight + "ks za " + priceEight + "$", shopMaterial)); |
||||||
|
inventory.setItem(7, (ItemStack) serialization.stringToBukkitObject((String) shopData.get("item"))); |
||||||
|
inventory.setItem(8, newItemStack("&l&bInformace o obchodu:", Material.PLAYER_HEAD, List.of("&eMajitel: " + ownerPrefix + shopData.get("owner")))); |
||||||
|
shopData.put("buyerInventory", buyerInventory); |
||||||
|
shopData.put("sellerInventory", sellerInventory); |
||||||
|
shopData.put("seller", seller); |
||||||
|
shopData.put("buyer", buyer); |
||||||
|
shopData.put("price", price); |
||||||
|
shopData.put("priceEight", priceEight); |
||||||
|
shopData.put("count", count); |
||||||
|
shopData.put("countEight", countEight); |
||||||
|
shopGuiInteract.storeDatas.put(player, shopData); |
||||||
|
player.openInventory(inventory); |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}else{ |
||||||
|
player.sendMessage(ChatColor.RED + "Data obchodu nebyla nalezena"); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
public static ItemStack newItemStack(String name, Material material){ |
||||||
|
ItemStack itemStack = new ItemStack(material); |
||||||
|
ItemMeta itemMeta = itemStack.getItemMeta(); |
||||||
|
assert itemMeta != null; |
||||||
|
itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); |
||||||
|
itemStack.setItemMeta(itemMeta); |
||||||
|
return itemStack; |
||||||
|
} |
||||||
|
public static ItemStack newItemStack(String name, Material material, List<String> list){ |
||||||
|
ItemStack itemStack = new ItemStack(material); |
||||||
|
ItemMeta itemMeta = itemStack.getItemMeta(); |
||||||
|
assert itemMeta != null; |
||||||
|
itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); |
||||||
|
List<String> lore = new ArrayList<>(); |
||||||
|
for (String loreline: list){ |
||||||
|
lore.add(ChatColor.translateAlternateColorCodes('&', loreline)); |
||||||
|
} |
||||||
|
itemMeta.setLore(lore); |
||||||
|
itemStack.setItemMeta(itemMeta); |
||||||
|
return itemStack; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,35 @@ |
|||||||
|
package xyz.mineconomia.mineconomiacore; |
||||||
|
|
||||||
|
import org.bukkit.inventory.Inventory; |
||||||
|
import org.bukkit.inventory.ItemStack; |
||||||
|
|
||||||
|
import java.util.Objects; |
||||||
|
|
||||||
|
public class invTools { |
||||||
|
public static int getFreeSpaceForItem(Inventory inventory, ItemStack itemStack){ |
||||||
|
int count = 0; |
||||||
|
int stackSize = itemStack.getMaxStackSize(); |
||||||
|
for (int i = 0; inventory.getSize() > i; i++){ |
||||||
|
if (inventory.getItem(i) == null){ |
||||||
|
count += stackSize; |
||||||
|
} else if (Objects.requireNonNull(inventory.getItem(i)).isSimilar(itemStack)) { |
||||||
|
count += stackSize - Objects.requireNonNull(inventory.getItem(i)).getAmount(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
return count; |
||||||
|
} |
||||||
|
public static int itemAmount(Inventory inventory, ItemStack itemStack){ |
||||||
|
int count = 0; |
||||||
|
for(int i = 0; inventory.getSize() > i; i++){ |
||||||
|
ItemStack comparedItem = inventory.getItem(i); |
||||||
|
if (comparedItem != null){ |
||||||
|
if (itemStack.isSimilar(comparedItem)){ |
||||||
|
count += comparedItem.getAmount(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return count; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -1,8 +1,12 @@ |
|||||||
package xyz.mineconomia.mineconomiacore; |
package xyz.mineconomia.mineconomiacore; |
||||||
|
|
||||||
|
import com.arangodb.entity.BaseDocument; |
||||||
import org.bukkit.configuration.file.FileConfiguration; |
import org.bukkit.configuration.file.FileConfiguration; |
||||||
|
|
||||||
public interface config { |
import java.util.HashMap; |
||||||
|
|
||||||
|
public interface publicValues { |
||||||
FileConfiguration config = MineconomiaCore.getPlugin(MineconomiaCore.class).getConfig(); |
FileConfiguration config = MineconomiaCore.getPlugin(MineconomiaCore.class).getConfig(); |
||||||
|
HashMap<String, Object> shops = new HashMap<>(); |
||||||
} |
} |
||||||
|
|
||||||
@ -0,0 +1,30 @@ |
|||||||
|
package xyz.mineconomia.mineconomiacore; |
||||||
|
|
||||||
|
import org.bukkit.inventory.ItemStack; |
||||||
|
import org.bukkit.util.io.BukkitObjectInputStream; |
||||||
|
import org.bukkit.util.io.BukkitObjectOutputStream; |
||||||
|
|
||||||
|
import java.io.*; |
||||||
|
import java.util.Base64; |
||||||
|
|
||||||
|
public class serialization { |
||||||
|
public static String bukkitObjectToString(Object object){ |
||||||
|
byte[] serializedObject = null; |
||||||
|
try { |
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
||||||
|
BukkitObjectOutputStream oos = new BukkitObjectOutputStream(baos); |
||||||
|
oos.writeObject(object); |
||||||
|
oos.close(); |
||||||
|
serializedObject = baos.toByteArray(); |
||||||
|
|
||||||
|
} catch (IOException e) { |
||||||
|
MineconomiaCore.logger.info("it's fucked: " + e); |
||||||
|
} |
||||||
|
return Base64.getEncoder().encodeToString(serializedObject); |
||||||
|
} |
||||||
|
public static Object stringToBukkitObject(String string) throws IOException, ClassNotFoundException { |
||||||
|
byte[] byteArray = Base64.getDecoder().decode(string); |
||||||
|
BukkitObjectInputStream in = new BukkitObjectInputStream(new ByteArrayInputStream(byteArray)); |
||||||
|
return in.readObject(); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue