From c7d9c604814aab05394521635e0874f952d16c27 Mon Sep 17 00:00:00 2001 From: Grzybol Date: Fri, 28 Jun 2024 03:21:42 +0200 Subject: [PATCH 1/7] - fixes --- pom.xml | 2 +- .../mine/game/betterelo/CustomMobsFileManager.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b46aed8..cb4b704 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ betterbox.mine.game BetterElo - 4.3.47-SNAPSHOT + 4.4.1-SNAPSHOT jar BetterElo diff --git a/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java b/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java index 980b9fa..53f8475 100644 --- a/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java +++ b/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java @@ -340,6 +340,15 @@ private ItemStack loadItemStack(YamlConfiguration mobData, String path) { } } } + try {// Ustawienie przedmiotu jako niezniszczalnego + if (mobData.contains(path + ".unbreakable") && mobData.getBoolean(path + ".unbreakable")) { + ItemMeta meta = itemStack.getItemMeta(); + meta.setUnbreakable(true); + itemStack.setItemMeta(meta); + } + }catch (Exception e){ + pluginLogger.log(PluginLogger.LogLevel.ERROR, "cannot read unbreakable from file. Exception: "+e.getMessage()); + } return itemStack; } From baa6cc447662b38fa374e07929dc68ca13ea7520 Mon Sep 17 00:00:00 2001 From: Grzybol Date: Fri, 28 Jun 2024 23:59:43 +0200 Subject: [PATCH 2/7] - fixed droptable command --- pom.xml | 2 +- .../betterbox/mine/game/betterelo/Event.java | 16 ++++++++------ .../game/betterelo/FileRewardManager.java | 22 +++++++++++++++---- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index cb4b704..3fb4b00 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ betterbox.mine.game BetterElo - 4.4.1-SNAPSHOT + 4.4.6-SNAPSHOT jar BetterElo diff --git a/src/main/java/betterbox/mine/game/betterelo/Event.java b/src/main/java/betterbox/mine/game/betterelo/Event.java index fe2e76d..39575f9 100644 --- a/src/main/java/betterbox/mine/game/betterelo/Event.java +++ b/src/main/java/betterbox/mine/game/betterelo/Event.java @@ -1317,7 +1317,7 @@ public void onInventoryClick(InventoryClickEvent event) { return; } if(event.getCurrentItem().getType() == Material.GRAY_STAINED_GLASS_PANE || event.getCurrentItem().getType() == Material.GREEN_WOOL){ - pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick green wool or blank pane clicked, cancelling.."); + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick green wool or blank pane clicked, cancelling.."); event.setCancelled(true); } @@ -1327,7 +1327,7 @@ public void onInventoryClick(InventoryClickEvent event) { ItemStack[] savedInventory = playerInventory.getContents(); String title = event.getView().getTitle(); - pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick called. title:"+title); + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick called. title:"+title); if (!Arrays.asList("Set Rewards", "Add Items", "Select Top", "AvgDmg bonus change").contains(title)) { return; } @@ -1370,13 +1370,13 @@ public void onInventoryClick(InventoryClickEvent event) { case "Add Items": //save button check pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick Add Items"); - if (currentItem.getType() == Material.GREEN_WOOL && (event.getSlot() == 35 || event.getSlot() == 53)) { + if (currentItem.getType() == Material.GREEN_WOOL && (event.getSlot() == 53)) { pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick Add Items - save called."); event.setCancelled(true); Inventory inventory = event.getInventory(); List itemsToSave = new ArrayList<>(); for (int i = 0; i < inventory.getSize(); i++) { - if (i == 35 || i == 53) { // Pomijamy slot przycisku "Save" + if (i == 53) { // Pomijamy slot przycisku "Save" pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick save button, skipping."); continue; } @@ -1389,14 +1389,16 @@ public void onInventoryClick(InventoryClickEvent event) { } - String fileName=guiManager.periodType+"_"+guiManager.rewardType; - pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick calling fileRewardManager.saveRewards("+fileName+",itemsToSave)"); + String fileName=guiManager.periodType+"_"+guiManager.dropTable; + + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick guiManager.periodType="+guiManager.periodType); if(guiManager.periodType.equals("dropTable")){ fileName=guiManager.dropTable; pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick droptable: "+fileName); + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick calling fileRewardManager.saveCustomDrops("+fileName+",itemsToSave)"); fileRewardManager.saveCustomDrops(fileName, itemsToSave); }else{ - fileRewardManager.saveRewards(fileName, itemsToSave); + fileRewardManager.saveCustomDrops(fileName, itemsToSave); } } diff --git a/src/main/java/betterbox/mine/game/betterelo/FileRewardManager.java b/src/main/java/betterbox/mine/game/betterelo/FileRewardManager.java index deb6d76..c05cd9e 100644 --- a/src/main/java/betterbox/mine/game/betterelo/FileRewardManager.java +++ b/src/main/java/betterbox/mine/game/betterelo/FileRewardManager.java @@ -143,22 +143,32 @@ public void saveCustomDrops(String fileName, List rewards) { pluginLogger.log(PluginLogger.LogLevel.DEBUG, "FileRewardManager.saveCustomDrops called, fileName: "+fileName); File customDropsFolder = new File(plugin.getDataFolder() + File.separator + "customDrops"); if (!customDropsFolder.exists()) { + pluginLogger.log(PluginLogger.LogLevel.INFO, "customDropsFolder does not exist, creating a new one"); customDropsFolder.mkdirs(); } File customDropTablesFolder = new File(plugin.getDataFolder() + File.separator + "customDropTables"); if (!customDropTablesFolder.exists()) { + pluginLogger.log(PluginLogger.LogLevel.INFO, "customDropTablesFolder does not exist, creating a new one"); customDropTablesFolder.mkdirs(); } File dropTableFile = new File(customDropTablesFolder, fileName + ".yml"); + pluginLogger.log(PluginLogger.LogLevel.INFO, "Droptable will be saved to "+fileName+".yml"); FileConfiguration dropTableConfig = new YamlConfiguration(); int index = 0; for (ItemStack item : rewards) { + if (item == null) { + pluginLogger.log(PluginLogger.LogLevel.ERROR, "ItemStack is null at index: " + index); + continue; + } + ; String itemFileName = fileName + "_item" + index + ".yml"; - File itemFile = new File(customDropsFolder, itemFileName); + pluginLogger.log(PluginLogger.LogLevel.INFO, "Droptable "+fileName+", itemFileName "+itemFileName+", index "+index+", saving item: "+item.getItemMeta().toString()); + try { + File itemFile = new File(customDropsFolder, itemFileName); itemFile.createNewFile(); FileConfiguration itemConfig = YamlConfiguration.loadConfiguration(itemFile); itemConfig.set("item", item); @@ -171,9 +181,13 @@ public void saveCustomDrops(String fileName, List rewards) { String itemNameString = item.getType().toString(); dropTableConfig.set("Item" + index + ".itemName", itemNameString); // Tutaj można ustawić faktyczną szansę na drop dropTableConfig.set("Item" + index + ".avgDmgBonus", false); // Tutaj można ustawić faktyczną szansę na drop - dropTableConfig.set("Item" + index + ".description", item.getItemMeta().lore().toString()); // Tutaj można ustawić faktyczną szansę na drop + if(item.getItemMeta().hasLore()) { + dropTableConfig.set("Item" + index + ".description", item.getItemMeta().lore().toString()); // Tutaj można ustawić faktyczną szansę na drop + } index++; - } catch (IOException e) { + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "dropTableConfig with index "+index+" saved"); + + } catch (Exception e) { pluginLogger.log(PluginLogger.LogLevel.ERROR, "Cannot save the item : "+index +", error: "+ e.getMessage()); } } @@ -181,7 +195,7 @@ public void saveCustomDrops(String fileName, List rewards) { try { dropTableConfig.save(dropTableFile); pluginLogger.log(PluginLogger.LogLevel.DEBUG, "dropTableConfig saved "); - } catch (IOException e) { + } catch (Exception e) { pluginLogger.log(PluginLogger.LogLevel.ERROR, "Nie można zapisać tabeli dropów: " + e.getMessage()); } } From d1d5813b9f1f492c731ea949c12092ba198f7407 Mon Sep 17 00:00:00 2001 From: Grzybol Date: Sat, 29 Jun 2024 02:30:54 +0200 Subject: [PATCH 3/7] - added display of current AvgDmg bonus in /be reroll - fixes - other stuff (idk, I forgot what I did, but it for sure was necessary) --- pom.xml | 2 +- .../betterbox/mine/game/betterelo/Event.java | 35 +++++++++++++++++++ .../game/betterelo/FileRewardManager.java | 2 ++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3fb4b00..8355cbd 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ betterbox.mine.game BetterElo - 4.4.6-SNAPSHOT + 4.4.10-SNAPSHOT jar BetterElo diff --git a/src/main/java/betterbox/mine/game/betterelo/Event.java b/src/main/java/betterbox/mine/game/betterelo/Event.java index 39575f9..a7d01e0 100644 --- a/src/main/java/betterbox/mine/game/betterelo/Event.java +++ b/src/main/java/betterbox/mine/game/betterelo/Event.java @@ -1451,6 +1451,41 @@ public void run() { inventory.setItem(3, result); pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick result placed back in slot 3"); + + ItemStack greenWoolItem = inventory.getItem(5); + if (greenWoolItem != null && greenWoolItem.hasItemMeta()) { + ItemMeta greenWoolMeta = greenWoolItem.getItemMeta(); + List greenWoolLore = greenWoolMeta.hasLore() ? new ArrayList<>(greenWoolMeta.getLore()) : new ArrayList<>(); + String avgDmgLine = lore.stream().filter(line -> line.contains("Average Damage")).findFirst().orElse("Average Damage +0%"); + + // Ustalanie indeksów dla "current bonus:" i wartości + int bonusIndex = -1; + for (int i = 0; i < greenWoolLore.size(); i++) { + if (greenWoolLore.get(i).equals("current bonus:")) { + bonusIndex = i; + break; + } + } + + if (bonusIndex != -1 && bonusIndex + 1 < greenWoolLore.size()) { + // Aktualizujemy istniejącą wartość jeśli jest miejsce w lore + greenWoolLore.set(bonusIndex + 1, "<" + avgDmgLine + ">"); + } else if (bonusIndex == -1) { + // Dodajemy nowe linie jeśli "current bonus:" nie istnieje + greenWoolLore.add("current bonus:"); + greenWoolLore.add("<" + avgDmgLine + ">"); + } else { + // Jeśli "current bonus:" jest na końcu listy, dodajemy wartość + greenWoolLore.add("<" + avgDmgLine + ">"); + } + + greenWoolMeta.setLore(greenWoolLore); + greenWoolItem.setItemMeta(greenWoolMeta); + inventory.setItem(5, greenWoolItem); + + + } + } } } diff --git a/src/main/java/betterbox/mine/game/betterelo/FileRewardManager.java b/src/main/java/betterbox/mine/game/betterelo/FileRewardManager.java index c05cd9e..a8c983b 100644 --- a/src/main/java/betterbox/mine/game/betterelo/FileRewardManager.java +++ b/src/main/java/betterbox/mine/game/betterelo/FileRewardManager.java @@ -184,6 +184,8 @@ public void saveCustomDrops(String fileName, List rewards) { if(item.getItemMeta().hasLore()) { dropTableConfig.set("Item" + index + ".description", item.getItemMeta().lore().toString()); // Tutaj można ustawić faktyczną szansę na drop } + dropTableConfig.set("Item" + index + ".itemName", item.displayName().toString()); + index++; pluginLogger.log(PluginLogger.LogLevel.DEBUG, "dropTableConfig with index "+index+" saved"); From 3b4370fe843b00d5a44ab53afefa664d37c6cc9a Mon Sep 17 00:00:00 2001 From: Grzybol Date: Sat, 29 Jun 2024 17:40:09 +0200 Subject: [PATCH 4/7] - roving also 1 cobweb above, not only at the legs height --- pom.xml | 2 +- src/main/java/betterbox/mine/game/betterelo/Event.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8355cbd..4cf3021 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ betterbox.mine.game BetterElo - 4.4.10-SNAPSHOT + 4.4.11-SNAPSHOT jar BetterElo diff --git a/src/main/java/betterbox/mine/game/betterelo/Event.java b/src/main/java/betterbox/mine/game/betterelo/Event.java index a7d01e0..65bd14e 100644 --- a/src/main/java/betterbox/mine/game/betterelo/Event.java +++ b/src/main/java/betterbox/mine/game/betterelo/Event.java @@ -13,6 +13,7 @@ import net.kyori.adventure.title.Title; import org.bukkit.*; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -1548,6 +1549,12 @@ public void onEntityMove(EntityMoveEvent event) { // Można tutaj dodać dodatkowe działania, np. wysłanie informacji do logów serwera pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.onEntityInteract: Mob is removing player-placed cobweb"); } + Block blockAbove = block.getRelative(BlockFace.UP); + + if (blockAbove.hasMetadata("placed_by_player") && blockAbove.getType() == Material.COBWEB) { + blockAbove.setType(Material.AIR); + pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.onEntityInteract: Mob is removing player-placed cobweb above"); + } } } From 3970967afd50e3d1ab16bcee5cdaf4e04c3df9d9 Mon Sep 17 00:00:00 2001 From: Grzybol Date: Sun, 30 Jun 2024 21:31:22 +0200 Subject: [PATCH 5/7] - configurable armor and damage (vanilla minecraft) attributes for mobs eq --- pom.xml | 2 +- .../game/betterelo/CustomMobsFileManager.java | 23 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 4cf3021..138743b 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ betterbox.mine.game BetterElo - 4.4.11-SNAPSHOT + 4.4.12-SNAPSHOT jar BetterElo diff --git a/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java b/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java index 53f8475..fff97b1 100644 --- a/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java +++ b/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java @@ -2,20 +2,21 @@ import it.unimi.dsi.fastutil.Pair; import org.bukkit.Material; +import org.bukkit.attribute.Attribute; +import org.bukkit.attribute.AttributeModifier; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.EntityType; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.plugin.java.JavaPlugin; import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; + import org.bukkit.Location; public class CustomMobsFileManager { @@ -350,6 +351,20 @@ private ItemStack loadItemStack(YamlConfiguration mobData, String path) { pluginLogger.log(PluginLogger.LogLevel.ERROR, "cannot read unbreakable from file. Exception: "+e.getMessage()); } + // Wczytanie atrybutów armor i damage + try { + ItemMeta meta = itemStack.getItemMeta(); + if (mobData.contains(path + ".attributes.damage")) { + meta.addAttributeModifier(Attribute.GENERIC_ATTACK_DAMAGE, new AttributeModifier(UUID.randomUUID(), "generic.attackDamage", mobData.getDouble(path + ".attributes.damage"), AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.HAND)); + } + if (mobData.contains(path + ".attributes.armor")) { + meta.addAttributeModifier(Attribute.GENERIC_ARMOR, new AttributeModifier(UUID.randomUUID(), "generic.armor", mobData.getDouble(path + ".attributes.armor"), AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.CHEST)); + } + itemStack.setItemMeta(meta); + } catch (Exception e) { + pluginLogger.log(PluginLogger.LogLevel.ERROR, "Error reading attributes from file. Exception: " + e.getMessage()); + } + return itemStack; } public List getCustomMobFiles() { From 0490db1188174560dd5944f4837f8e8fc1298ff5 Mon Sep 17 00:00:00 2001 From: Grzybol Date: Sun, 7 Jul 2024 20:55:28 +0200 Subject: [PATCH 6/7] - fixes --- .idea/jarRepositories.xml | 5 +++++ pom.xml | 2 +- .../betterbox/mine/game/betterelo/CustomMobs.java | 1 + .../java/betterbox/mine/game/betterelo/Event.java | 14 +++++++++++++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml index 33d0680..bd97413 100644 --- a/.idea/jarRepositories.xml +++ b/.idea/jarRepositories.xml @@ -1,6 +1,11 @@ + +