diff --git a/pom.xml b/pom.xml index 9a04426..e694c35 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ betterbox.mine.game BetterElo - 4.3.15-SNAPSHOT + 4.3.25-SNAPSHOT jar BetterElo diff --git a/src/main/java/betterbox/mine/game/betterelo/BetterEloCommand.java b/src/main/java/betterbox/mine/game/betterelo/BetterEloCommand.java index 781a85f..47e78a0 100644 --- a/src/main/java/betterbox/mine/game/betterelo/BetterEloCommand.java +++ b/src/main/java/betterbox/mine/game/betterelo/BetterEloCommand.java @@ -73,6 +73,14 @@ public boolean onCommand(CommandSender sender, Command command, String label, St break; case 1: switch (args[0].toLowerCase()) { + case "enchantitem": + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterEloCommand.onCommand enchantitem called, sender: "+sender); + if(!sender.isOp()){ + sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.DARK_RED + " You don't have permission to use that command!"); + break; + } + createEncahntItem(sender); + break; case "reroll": if(sender.isOp() || sender.hasPermission("betterelo.reroll")) { handleRerollCommand(sender); @@ -755,6 +763,17 @@ public void handleRerollCommand (CommandSender sender){ guiManager.openReRollGui(player); } } + + private void createEncahntItem(CommandSender sender){ + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "BetterEloCommand.createEncahntItem called, sender: "+sender); + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.DARK_RED + " This command can only be used by online players."); + return ; + } + Player player = (Player) sender; + ItemStack enchantItem = guiManager.getEnchantItem(); + player.getInventory().addItem(enchantItem); + } public void addAntywebLore(Player player, ItemStack itemStack, int radius) { ItemMeta itemMeta = itemStack.getItemMeta(); if (itemMeta == null) { diff --git a/src/main/java/betterbox/mine/game/betterelo/CustomMobs.java b/src/main/java/betterbox/mine/game/betterelo/CustomMobs.java index 1f7a6ee..1b74629 100644 --- a/src/main/java/betterbox/mine/game/betterelo/CustomMobs.java +++ b/src/main/java/betterbox/mine/game/betterelo/CustomMobs.java @@ -62,10 +62,18 @@ static class CustomMob { } this.entityType = entityType; - this.helmet = helmet; - this.chestplate = chestplate; - this.leggings = leggings; - this.boots = boots; + if(helmet!=null) { + this.helmet = helmet; + } + if(chestplate!=null) { + this.chestplate = chestplate; + } + if(leggings!=null) { + this.leggings = leggings; + } + if(boots!=null) { + this.boots = boots; + } this.dropFileManager = dropFileManager; this.dropTableName = dropTableName; //this.dropTable = dropFileManager.loadCustomDrops(dropTableName); @@ -357,6 +365,9 @@ public void loadCustomMobs() { CustomMob customMob = fileManager.loadCustomMob(plugin, fileRewardManager, mobFile); if (customMob != null) { customMobsMap.put(customMob.getMobName(), customMob); + }else + { + pluginLogger.log(PluginLogger.LogLevel.ERROR, "CustomMobs.loadCustomMobs could not load custom mob "+customMob); } } catch (Exception e) { pluginLogger.log(PluginLogger.LogLevel.ERROR, "CustomMobs.loadCustomMobs exception: " + e.getMessage()); diff --git a/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java b/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java index 987f3d7..2986794 100644 --- a/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java +++ b/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java @@ -258,21 +258,21 @@ public CustomMobs.CustomMob loadCustomMob(JavaPlugin plugin, FileRewardManager d if(mobData.contains("dropEMKS")){ dropEMKS = mobData.getBoolean("dropEMKS"); - pluginLogger.log(PluginLogger.LogLevel.DEBUG, "CustomMobsFileManager.loadCustomMob loaded dropEMKS:" + dropEMKS); + pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob loaded dropEMKS:" + dropEMKS); } if(mobData.contains("EMKSchance")){ EKMSchance = mobData.getDouble("EMKSchance"); - pluginLogger.log(PluginLogger.LogLevel.DEBUG, "CustomMobsFileManager.loadCustomMob loaded EKMSchance:" + EKMSchance); + pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob loaded EKMSchance:" + EKMSchance); } if(mobData.contains("attackSpeed")){ attackSpeed = mobData.getInt("attackSpeed"); - pluginLogger.log(PluginLogger.LogLevel.DEBUG, "CustomMobsFileManager.loadCustomMob loaded AttackSpeed:" + attackSpeed); + pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob loaded AttackSpeed:" + attackSpeed); } String entityTypeString = mobData.getString("type"); String mobName = mobData.getString("mobName"); String dropTableName = mobData.getString("dropTable"); - pluginLogger.log(PluginLogger.LogLevel.DEBUG, "CustomMobsFileManager.loadCustomMob armor:" + armor + ", hp: " + hp + ", speed: " + speed + ", attackDamage: " + attackDamage + ", type: " + entityTypeString+", dropEMKS: "+dropEMKS+", EKMSchance: "+EKMSchance+", dropTablename: "+dropTableName); + pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob armor:" + armor + ", hp: " + hp + ", speed: " + speed + ", attackDamage: " + attackDamage + ", type: " + entityTypeString+", dropEMKS: "+dropEMKS+", EKMSchance: "+EKMSchance+", dropTablename: "+dropTableName); EntityType entityType = EntityType.valueOf(entityTypeString); // Wczytanie niestandardowych metadanych i ustawienie spawnerName diff --git a/src/main/java/betterbox/mine/game/betterelo/Event.java b/src/main/java/betterbox/mine/game/betterelo/Event.java index 541375a..fbb0d54 100644 --- a/src/main/java/betterbox/mine/game/betterelo/Event.java +++ b/src/main/java/betterbox/mine/game/betterelo/Event.java @@ -416,7 +416,11 @@ public void onBreak(BlockBreakEvent event) { Player player = event.getPlayer(); String uuid = player.getUniqueId().toString(); double base = configManager.blockBase; - + if(!isEloAllowed(player,player.getLocation())){ + pluginLogger.log(PluginLogger.LogLevel.DEBUG_LVL2, "Event: onPlayerDeath noElo zone!"); + player.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo] " + ChatColor.DARK_RED + "No elo reward in this zone!"); + return; + } double playerElo = dataManager.getPoints(uuid,"main"); double pointsEarnedMain = calculatePointsEarnedFromBlock(base,playerElo,blockReward, dataManager.getMaxElo("main"), dataManager.getMinElo("main")); addPoints(uuid,pointsEarnedMain,"main"); @@ -1357,10 +1361,13 @@ public void onInventoryClick(InventoryClickEvent event) { ItemStack result = item0.clone(); ItemMeta resultMeta = result.getItemMeta(); List lore = new ArrayList<>(resultMeta.getLore()); + boolean mobDamage=false; for (int i = 0; i < lore.size(); i++) { - if (lore.get(i).contains("Average Damage")) { + if(lore.get(i).contains("Mob Damage")) + mobDamage=true; + if (lore.get(i).contains("Average Damage") && mobDamage) { pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick reroll, Average Damage lore line found i: " + i); - if( guiManager.checkAndRemoveBetterCoins(player)) { + if( guiManager.checkAndRemoveEnchantItem(player)) { pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick reroll, player paid, re-rolling..." ); lore.set(i, customMobs.dropAverageDamage()); player.setMetadata("avgDmgRerolled", new FixedMetadataValue(plugin, true)); diff --git a/src/main/java/betterbox/mine/game/betterelo/GuiManager.java b/src/main/java/betterbox/mine/game/betterelo/GuiManager.java index ab42e6f..fa96426 100644 --- a/src/main/java/betterbox/mine/game/betterelo/GuiManager.java +++ b/src/main/java/betterbox/mine/game/betterelo/GuiManager.java @@ -3,6 +3,7 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -10,6 +11,7 @@ import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.plugin.java.JavaPlugin; @@ -120,8 +122,11 @@ private void updateResultSlot(Inventory inv) { ItemStack result = item0.clone(); ItemMeta resultMeta = result.getItemMeta(); List lore = new ArrayList<>(resultMeta.getLore()); + boolean mobDamage = false; for (int i = 0; i < lore.size(); i++) { - if (lore.get(i).contains("Average Damage")) { + if(lore.get(i).contains("Mob Damage")) + mobDamage=true; + if (lore.get(i).contains("Average Damage")&& mobDamage) { lore.set(i, customMobs.dropAverageDamage()); break; } @@ -157,7 +162,7 @@ public void openReRollGui(Player player){ createItem(inv, blank, 1, "", ""); createItem(inv, blank, 2, "", ""); createItem(inv, blank, 4, "", ""); - createItem(inv, Material.GREEN_WOOL, 5, "Re-Roll Average Damage bonus", "Cost: 64x BetterCoin"); + createItem(inv, Material.GREEN_WOOL, 5, "Re-Roll Average Damage bonus", "Cost: 1x "+ChatColor.DARK_PURPLE+""+ChatColor.BOLD+"Enchant Item"); createItem(inv, blank, 6, "", ""); createItem(inv, blank, 7, "", ""); createItem(inv, blank, 8, "", ""); @@ -180,6 +185,44 @@ public boolean checkAndRemoveBetterCoins(Player player) { pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.checkAndRemoveBetterCoins 64 BetterCoin not found"); return false; } + public boolean checkAndRemoveEnchantItem(Player player) { + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.checkAndRemoveEnchantItem called, player : "+player); + Inventory inventory = player.getInventory(); + ItemStack enchantItemStack = getEnchantItem(); + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.checkAndRemoveEnchantItem betterCoinStack: "+enchantItemStack); + // Sprawdź, czy gracz ma co najmniej 64 BetterCoin w ekwipunku + if (inventory.containsAtLeast(enchantItemStack, 1)) { + // Usuń 64 sztuki BetterCoin z ekwipunku gracza + inventory.removeItem(enchantItemStack); + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.checkAndRemoveEnchantItem 1 Enchant Item found, removing : "+enchantItemStack); + return true; + } + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.checkAndRemoveEnchantItem 1 Enchant Item not found"); + return false; + } + public ItemStack getEnchantItem(){ + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.getEnchantItem called"); + Material material = Material.GHAST_TEAR; + int amount = 1; + + ItemStack stack = new ItemStack(material, amount); + ItemMeta meta = stack.getItemMeta(); + if (meta != null) { + meta.setDisplayName(ChatColor.DARK_PURPLE+""+ ChatColor.BOLD+"Enchant Item"); + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.getEnchantItem meta.getDisplayName(): "+meta.getDisplayName()); + //Component displayNameComponent = new Component("BetterCoin"); + List lore = List.of(ChatColor.GRAY+ "Removes current the Average Damage bonus",ChatColor.GRAY+ " from the item and adds new one."); + meta.setLore(lore); + // Dodajemy niestandardowy enchant, który nie wpływa na działanie itemu + meta.addEnchant(Enchantment.LUCK, 1, true); + + // Ukrywamy wszystkie informacje o zaklęciach na itemie + meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); + + stack.setItemMeta(meta); + } + return stack; + } private ItemStack getBetterCoinStack() { pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.getBetterCoinStack called");