From 87f1f567bae89bf6bdf0d0bd92955a647a90db4a Mon Sep 17 00:00:00 2001 From: Grzybol Date: Tue, 25 Jun 2024 01:24:30 +0200 Subject: [PATCH 1/8] - mobs are removing Cobwebs from now --- pom.xml | 2 +- .../betterbox/mine/game/betterelo/Event.java | 71 ++++++++++++------- .../game/betterelo/FileRewardManager.java | 3 +- 3 files changed, 50 insertions(+), 26 deletions(-) diff --git a/pom.xml b/pom.xml index 7430f73..a219a07 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ betterbox.mine.game BetterElo - 4.3.28-SNAPSHOT + 4.3.34-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 fbb0d54..896f9c2 100644 --- a/src/main/java/betterbox/mine/game/betterelo/Event.java +++ b/src/main/java/betterbox/mine/game/betterelo/Event.java @@ -8,6 +8,7 @@ import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.RegionContainer; import com.sk89q.worldguard.protection.ApplicableRegionSet; +import io.papermc.paper.event.entity.EntityMoveEvent; import net.kyori.adventure.text.Component; import net.kyori.adventure.title.Title; import org.bukkit.*; @@ -22,10 +23,7 @@ import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityDeathEvent; -import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.entity.*; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.player.PlayerInteractEvent; @@ -1295,7 +1293,7 @@ public void onInventoryClick(InventoryClickEvent event) { case "Select Top": event.setCancelled(true); guiManager.rewardType = currentItem.getItemMeta().getDisplayName(); - pluginLogger.log("GuiManager.onInventoryClick: rewardType:" + guiManager.rewardType + " periodType:" + guiManager.periodType); + pluginLogger.log("Event.onInventoryClick: rewardType:" + guiManager.rewardType + " periodType:" + guiManager.periodType); fileRewardManager.setRewardType(guiManager.periodType, guiManager.rewardType); List currentRewards = fileRewardManager.loadRewards(); inv = Bukkit.createInventory(null, 36, "Add Items"); @@ -1307,31 +1305,31 @@ public void onInventoryClick(InventoryClickEvent event) { break; case "Add Items": //save button check - pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick Add Items"); + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick Add Items"); if (currentItem.getType() == Material.GREEN_WOOL && (event.getSlot() == 35 || event.getSlot() == 53)) { - pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick Add Items - save called."); + 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" - pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick save button, skipping."); + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick save button, skipping."); continue; } ItemStack item = inventory.getItem(i); - pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick save: item: "+item); + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick save: item: "+item); if (item != null && item.getType() != Material.AIR) { - pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick no air save: item: "+item); + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick no air save: item: "+item); itemsToSave.add(item); } } String fileName=guiManager.periodType+"_"+guiManager.rewardType; - pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick calling fileRewardManager.saveRewards("+fileName+",itemsToSave)"); + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick calling fileRewardManager.saveRewards("+fileName+",itemsToSave)"); if(guiManager.periodType.equals("dropTable")){ fileName=guiManager.dropTable; - pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick droptable: "+fileName); + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick droptable: "+fileName); fileRewardManager.saveCustomDrops(fileName, itemsToSave); }else{ fileRewardManager.saveRewards(fileName, itemsToSave); @@ -1340,22 +1338,22 @@ public void onInventoryClick(InventoryClickEvent event) { } break; case "AvgDmg bonus change": - pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick Average Damage bonus re-roll"); + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick Average Damage bonus re-roll"); if (currentItem.getType() == Material.GREEN_WOOL && event.getSlot() == 5){ playerInventory.setContents(savedInventory); event.setCancelled(true); - pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick Average Damage bonus re-roll clicked"); + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick Average Damage bonus re-roll clicked"); Inventory inventory = event.getInventory(); ItemStack item0 = inventory.getItem(3); if (item0 != null && item0.hasItemMeta()) { - pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick reroll, item0: "+item0+", item0.hasItemMeta(): "+item0.hasItemMeta()); + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick reroll, item0: "+item0+", item0.hasItemMeta(): "+item0.hasItemMeta()); ItemMeta meta0 = item0.getItemMeta(); boolean slot0Condition = meta0.getLore().stream().anyMatch(line -> line.contains("Average Damage")); ItemMeta meta = item0.getItemMeta(); //List lore = meta.getLore(); - pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick reroll, slot0Condition: "+slot0Condition); + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick reroll, slot0Condition: "+slot0Condition); if (slot0Condition) { ItemStack result = item0.clone(); @@ -1366,9 +1364,9 @@ public void onInventoryClick(InventoryClickEvent event) { 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); + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick reroll, Average Damage lore line found i: " + i); if( guiManager.checkAndRemoveEnchantItem(player)) { - pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick reroll, player paid, re-rolling..." ); + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick reroll, player paid, re-rolling..." ); lore.set(i, customMobs.dropAverageDamage()); player.setMetadata("avgDmgRerolled", new FixedMetadataValue(plugin, true)); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @@ -1379,13 +1377,13 @@ public void run() { }, 1L); break; } - pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick reroll, player has no money for the re-roll." ); + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick reroll, player has no money for the re-roll." ); } } resultMeta.setLore(lore); result.setItemMeta(resultMeta); inventory.setItem(3, result); - pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClick result placed back in slot 3"); + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClick result placed back in slot 3"); } } @@ -1401,23 +1399,23 @@ public void onInventoryClose(InventoryCloseEvent event) { // Check if the closed inventory is the same one we're interested in if (event.getView().getTitle().equalsIgnoreCase("AvgDmg bonus change")) { - pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClose: Checking items in closed GUI"); + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClose: Checking items in closed GUI"); ItemStack itemInSlot0 = closedInventory.getItem(3); if (itemInSlot0 != null) { ItemMeta meta = itemInSlot0.getItemMeta(); //if (meta.getLore().stream().anyMatch(line -> line.contains("Average Damage"))) { - pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClose: Item with 'Average damage' found in slot 0"); + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClose: Item with 'Average damage' found in slot 0"); // Optional: Directly give back the item to the player's inventory if (player.getInventory().addItem(itemInSlot0).size() == 0) { // Item successfully added to player's inventory - pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClose: Item returned to player inventory"); + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClose: Item returned to player inventory"); closedInventory.clear(3); // Clear the slot after returning item } else { // Inventory full, drop item at player's location player.getWorld().dropItem(player.getLocation(), itemInSlot0); - pluginLogger.log(PluginLogger.LogLevel.DEBUG, "GuiManager.onInventoryClose: Inventory full, item dropped at player's location"); + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onInventoryClose: Inventory full, item dropped at player's location"); closedInventory.clear(3); // Clear the slot } //} @@ -1425,5 +1423,30 @@ public void onInventoryClose(InventoryCloseEvent event) { } } + @EventHandler + public void onEntityMove(EntityMoveEvent event) { + + //pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.onEntityInteract called"); + if (!event.getEntity().hasMetadata("CustomMob")){ + return; + } + //pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.onEntityInteract: CustomMob CHECK PASSED"); + + // Pobieranie bloku, z którym wchodzi w interakcję mob + Block block = event.getTo().getBlock(); + if(!block.hasMetadata("placed_by_player")){ + return; + } + //pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.onEntityInteract: COMWEB placed_by_player CHECK PASSED"); + // Sprawdzanie, czy blok to pajęczyna + if (block.getType() == Material.COBWEB) { + // Usunięcie pajęczyny, gdy mob wejdzie w nią + block.setType(Material.AIR); + + // 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"); + } + } + } diff --git a/src/main/java/betterbox/mine/game/betterelo/FileRewardManager.java b/src/main/java/betterbox/mine/game/betterelo/FileRewardManager.java index d4dc2dc..deb6d76 100644 --- a/src/main/java/betterbox/mine/game/betterelo/FileRewardManager.java +++ b/src/main/java/betterbox/mine/game/betterelo/FileRewardManager.java @@ -171,9 +171,10 @@ 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 index++; } catch (IOException e) { - pluginLogger.log(PluginLogger.LogLevel.ERROR, "Nie można zapisać przedmiotu: " + e.getMessage()); + pluginLogger.log(PluginLogger.LogLevel.ERROR, "Cannot save the item : "+index +", error: "+ e.getMessage()); } } From 597705dcfde9ce7047c72a97ee14c27b3ba83d50 Mon Sep 17 00:00:00 2001 From: Grzybol Date: Tue, 25 Jun 2024 02:27:35 +0200 Subject: [PATCH 2/8] - fixes --- pom.xml | 2 +- .../betterbox/mine/game/betterelo/Event.java | 42 +++++++++++++++++-- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index a219a07..c1a7ee8 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ betterbox.mine.game BetterElo - 4.3.34-SNAPSHOT + 4.3.40-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 896f9c2..faf5cbc 100644 --- a/src/main/java/betterbox/mine/game/betterelo/Event.java +++ b/src/main/java/betterbox/mine/game/betterelo/Event.java @@ -1059,11 +1059,12 @@ private ItemStack dropMobKillerSword(){ @EventHandler(priority = EventPriority.HIGHEST) public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { //pluginLogger.log(PluginLogger.LogLevel.KILL_EVENT, "Event.onEntityDamageByEntity onEntityDamageByEntity called"); - - if (event.getDamager() instanceof Player && event.getEntity() instanceof Player && !event.isCancelled()) { - + Entity damagerEntity = event.getDamager(); + Entity victimEntity = event.getEntity(); + if (damagerEntity instanceof Player && victimEntity instanceof Player && !event.isCancelled()) { Player damager = (Player) event.getDamager(); Player victim = (Player) event.getEntity(); + if (damager.hasMetadata("handledDamage")) { pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event.onEntityDamageByEntity event already handled!"); return; @@ -1090,20 +1091,52 @@ public void run() { damager.removeMetadata("handledDamage", plugin); } }, 1L); + return; } LivingEntity entity = (LivingEntity) event.getEntity(); - if (entity.hasMetadata("CustomMob")){ + if (victimEntity.hasMetadata("CustomMob")){ pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.onEntityDamageByEntity custom mob detected"); customEntityDamageEvent(event); //CustomMobs.CustomMob customMob = (CustomMobs.CustomMob) entity; //Zombie zombie = (Zombie) entity; pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.EntityDamageEvent calling customMobs.updateZombieCustomName(zombie)"); //customMobs.updateCustomMobName(zombie); + return; } + if (damagerEntity.hasMetadata("CustomMob") && victimEntity instanceof Player) { + pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.EntityDamageEvent getFinalDamage: "+event.getFinalDamage()); + event.setDamage(event.getFinalDamage()*(1-(0.04*customArmorBonus((Player) victimEntity)))); + } } + public int customArmorBonus (Player player){ + int CustomArmorBonus=0; + List equippedItems = getPlayerEquippedItems(player); + if(equippedItems==null){ + return CustomArmorBonus; + } + for (ItemStack item : equippedItems){ + ItemMeta meta = item.getItemMeta(); + if (meta != null && meta.hasLore()) { + List lore = meta.getLore(); + for (String line : lore) { + if (line.startsWith("§6§lMob Defense ")) { + try { + String percentString = line.replace("§6§lMob Defense ", "").replace("%", ""); + pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.customArmorBonus percentString: " + percentString); + CustomArmorBonus += Integer.parseInt(percentString); + pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.customArmorBonus added CustomArmorBonus: " + CustomArmorBonus); + } catch (NumberFormatException e) { + pluginLogger.log(PluginLogger.LogLevel.ERROR, "Error parsing average damage bonus from lore: " + line); + } + } + } + } + } + return CustomArmorBonus; + } public void customEntityDamageEvent(EntityDamageByEntityEvent event){ pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.customEntityDamageEvent triggered"); @@ -1423,6 +1456,7 @@ public void onInventoryClose(InventoryCloseEvent event) { } } + @EventHandler public void onEntityMove(EntityMoveEvent event) { From dc8ce41df2074c22cc8c065d65817fb3f315b218 Mon Sep 17 00:00:00 2001 From: Grzybol Date: Wed, 26 Jun 2024 00:19:09 +0200 Subject: [PATCH 3/8] - changed Mob defense bonus to 0.1 of previous value --- pom.xml | 2 +- src/main/java/betterbox/mine/game/betterelo/Event.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index c1a7ee8..c03012d 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ betterbox.mine.game BetterElo - 4.3.40-SNAPSHOT + 4.3.41-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 faf5cbc..e7e1046 100644 --- a/src/main/java/betterbox/mine/game/betterelo/Event.java +++ b/src/main/java/betterbox/mine/game/betterelo/Event.java @@ -1105,7 +1105,7 @@ public void run() { } if (damagerEntity.hasMetadata("CustomMob") && victimEntity instanceof Player) { pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.EntityDamageEvent getFinalDamage: "+event.getFinalDamage()); - event.setDamage(event.getFinalDamage()*(1-(0.04*customArmorBonus((Player) victimEntity)))); + event.setDamage(event.getFinalDamage()*(1-(0.004*customArmorBonus((Player) victimEntity)))); } From 5e0187db7508375224af6216280e25c9c00d8581 Mon Sep 17 00:00:00 2001 From: Grzybol Date: Wed, 26 Jun 2024 22:22:07 +0200 Subject: [PATCH 4/8] - damage to mobs is reduced by their armor and defense --- pom.xml | 2 +- .../betterbox/mine/game/betterelo/CustomMobs.java | 14 +++++++++----- .../game/betterelo/CustomMobsFileManager.java | 15 ++++++++++++--- .../java/betterbox/mine/game/betterelo/Event.java | 11 ++++++++++- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index c03012d..7491b4b 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ betterbox.mine.game BetterElo - 4.3.41-SNAPSHOT + 4.3.43-SNAPSHOT jar BetterElo diff --git a/src/main/java/betterbox/mine/game/betterelo/CustomMobs.java b/src/main/java/betterbox/mine/game/betterelo/CustomMobs.java index a3ec613..1d3138b 100644 --- a/src/main/java/betterbox/mine/game/betterelo/CustomMobs.java +++ b/src/main/java/betterbox/mine/game/betterelo/CustomMobs.java @@ -43,12 +43,12 @@ static class CustomMob { //HashMap< Double,ItemStack> dropTable; List dropTable; double armor, speed, attackDamage, EMKSchance; - int hp,attackSpeed; + int hp,attackSpeed,defense; Map customMetadata; // Nowe pole do przechowywania niestandardowych metadanych JavaPlugin plugin; CustomMobsFileManager dropFileManager; - CustomMob(JavaPlugin plugin,CustomMobsFileManager dropFileManager, String mobName, EntityType entityType, ItemStack helmet, ItemStack chestplate, ItemStack leggings, ItemStack boots,ItemStack weapon, double armor, int hp, double speed, double attackDamage, int attackSpeed, Map customMetadata, String dropTableName, Boolean dropEMKS, double EMKSchance) { + CustomMob(JavaPlugin plugin,CustomMobsFileManager dropFileManager, String mobName, EntityType entityType, ItemStack helmet, ItemStack chestplate, ItemStack leggings, ItemStack boots,ItemStack weapon, double armor, int hp, double speed, double attackDamage, int attackSpeed, Map customMetadata, String dropTableName, Boolean dropEMKS, double EMKSchance, int defense) { this.plugin = plugin; this.dropEMKS = dropEMKS; this.EMKSchance = EMKSchance; @@ -82,11 +82,12 @@ static class CustomMob { this.hp = hp; this.attackSpeed = attackSpeed; this.speed = speed; + this.defense = defense; this.attackDamage = attackDamage; this.customMetadata = customMetadata; //setupMob(); } - CustomMob(JavaPlugin plugin,CustomMobsFileManager dropFileManager, String mobName, EntityType entityType, double armor, int hp, double speed, double attackDamage, int attackSpeed, Map customMetadata, String dropTableName, Boolean dropEMKS, double EMKSchance) { + CustomMob(JavaPlugin plugin,CustomMobsFileManager dropFileManager, String mobName, EntityType entityType, double armor, int hp, double speed, double attackDamage, int attackSpeed, Map customMetadata, String dropTableName, Boolean dropEMKS, double EMKSchance, int defense) { this.plugin = plugin; this.dropEMKS = dropEMKS; this.EMKSchance = EMKSchance; @@ -101,6 +102,7 @@ static class CustomMob { this.hp = hp; this.attackSpeed = attackSpeed; this.speed = speed; + this.defense = defense; this.attackDamage = attackDamage; this.customMetadata = customMetadata; //setupMob(); @@ -124,12 +126,12 @@ public CustomMob cloneForSpawn(Location spawnLocation, String mobType) { this.helmet.clone(), this.chestplate.clone(), this.leggings.clone(), this.boots.clone(), this.weapon.clone(), this.armor, this.hp, this.speed, - this.attackDamage, this.attackSpeed, new HashMap<>(this.customMetadata), this.dropTableName, this.dropEMKS, this.EMKSchance); + this.attackDamage, this.attackSpeed, new HashMap<>(this.customMetadata), this.dropTableName, this.dropEMKS, this.EMKSchance, this.defense); newMob.spawnMob(spawnLocation); }else{ newMob = new CustomMob(this.plugin, this.dropFileManager, this.mobName, this.entityType, this.armor, this.hp, this.speed, - this.attackDamage, this.attackSpeed, new HashMap<>(this.customMetadata), this.dropTableName, this.dropEMKS, this.EMKSchance); + this.attackDamage, this.attackSpeed, new HashMap<>(this.customMetadata), this.dropTableName, this.dropEMKS, this.EMKSchance, this.defense); newMob.spawnMob(spawnLocation); } return newMob; @@ -166,6 +168,8 @@ private void setupMob() { // Ustawianie niestandardowych metadanych customMetadata.forEach((key, value) -> entity.setMetadata(key, new FixedMetadataValue(plugin, value))); + entity.setMetadata("armor", new FixedMetadataValue(plugin, armor)); + entity.setMetadata("defense", new FixedMetadataValue(plugin, defense)); } public String getMobName() { return this.mobName; diff --git a/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java b/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java index 4ebdf78..980b9fa 100644 --- a/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java +++ b/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java @@ -255,13 +255,14 @@ public CustomMobs.CustomMob loadCustomMob(JavaPlugin plugin, FileRewardManager d weapon = loadItemStack(mobData, "equipment.weapon"); } // Wczytanie pozostałych danych - double armor = mobData.getDouble("armor"); + double armor = 1; int hp = mobData.getInt("hp"); double speed = mobData.getDouble("speed"); double attackDamage = mobData.getDouble("attackDamage"); double EKMSchance = 0.0d; boolean dropEMKS = false; int attackSpeed = 1; + int defense = 0; if(mobData.contains("dropEMKS")){ @@ -276,6 +277,14 @@ public CustomMobs.CustomMob loadCustomMob(JavaPlugin plugin, FileRewardManager d attackSpeed = mobData.getInt("attackSpeed"); pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob loaded AttackSpeed:" + attackSpeed); } + if(mobData.contains("defense")){ + defense = mobData.getInt("defense"); + pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob loaded defense:" + defense); + } + if(mobData.contains("armor")){ + armor = mobData.getDouble("armor"); + pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob loaded armor:" + armor); + } String mobName = mobData.getString("mobName"); String dropTableName = mobData.getString("dropTable"); @@ -292,10 +301,10 @@ public CustomMobs.CustomMob loadCustomMob(JavaPlugin plugin, FileRewardManager d CustomMobs.CustomMob customMob=null; if (entityTypeString.equals("SKELETON")||entityTypeString.equals("ZOMBIE")){ pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob mob is ZOMBIE or SKELETON"); - customMob = new CustomMobs.CustomMob(plugin, this, mobName, entityType, helmet, chestplate, leggings, boots,weapon, armor, hp, speed, attackDamage,attackSpeed, customMetadata, dropTableName, dropEMKS, EKMSchance); + customMob = new CustomMobs.CustomMob(plugin, this, mobName, entityType, helmet, chestplate, leggings, boots,weapon, armor, hp, speed, attackDamage,attackSpeed, customMetadata, dropTableName, dropEMKS, EKMSchance, defense); }else{ - customMob = new CustomMobs.CustomMob(plugin, this, mobName, entityType, armor, hp, speed, attackDamage,attackSpeed, customMetadata, dropTableName, dropEMKS, EKMSchance); + customMob = new CustomMobs.CustomMob(plugin, this, mobName, entityType, armor, hp, speed, attackDamage,attackSpeed, customMetadata, dropTableName, dropEMKS, EKMSchance, defense); } diff --git a/src/main/java/betterbox/mine/game/betterelo/Event.java b/src/main/java/betterbox/mine/game/betterelo/Event.java index e7e1046..ad3a43c 100644 --- a/src/main/java/betterbox/mine/game/betterelo/Event.java +++ b/src/main/java/betterbox/mine/game/betterelo/Event.java @@ -1176,7 +1176,16 @@ public void customEntityDamageEvent(EntityDamageByEntityEvent event){ int bonusDamage = (int) (averageDamage * (averageDamageBonusPercent / 100.0)); // Obliczenie bonusu double totalDamage = minDamage + random.nextInt(maxDamage - minDamage + 1) + bonusDamage; // Całkowite obrażenia pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.customEntityDamageEvent minDamage: "+minDamage+", maxDamage: "+maxDamage+", averageDamage: "+averageDamage+", bonusAverageDamage: "+bonusDamage); - event.setDamage(totalDamage); + double armor=1; + if (event.getEntity().hasMetadata("armor")) { + List values = event.getEntity().getMetadata("armor"); + armor = values.get(0).asDouble(); // Uzyskanie wartości armor + if(armor==0){ + armor=1; + } + } + + event.setDamage(totalDamage-armor); pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.customEntityDamageEvent totalDamage: " + totalDamage+", bonusDamage: "+bonusDamage); return; From 7307fc99191ca3ab693bc298f9822bbf59d62dc3 Mon Sep 17 00:00:00 2001 From: Grzybol Date: Wed, 26 Jun 2024 22:24:13 +0200 Subject: [PATCH 5/8] - fix --- pom.xml | 2 +- src/main/java/betterbox/mine/game/betterelo/Event.java | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 7491b4b..af4c3ae 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ betterbox.mine.game BetterElo - 4.3.43-SNAPSHOT + 4.3.44-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 ad3a43c..e550bc4 100644 --- a/src/main/java/betterbox/mine/game/betterelo/Event.java +++ b/src/main/java/betterbox/mine/game/betterelo/Event.java @@ -1176,7 +1176,7 @@ public void customEntityDamageEvent(EntityDamageByEntityEvent event){ int bonusDamage = (int) (averageDamage * (averageDamageBonusPercent / 100.0)); // Obliczenie bonusu double totalDamage = minDamage + random.nextInt(maxDamage - minDamage + 1) + bonusDamage; // Całkowite obrażenia pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.customEntityDamageEvent minDamage: "+minDamage+", maxDamage: "+maxDamage+", averageDamage: "+averageDamage+", bonusAverageDamage: "+bonusDamage); - double armor=1; + double armor=1, defense=0; if (event.getEntity().hasMetadata("armor")) { List values = event.getEntity().getMetadata("armor"); armor = values.get(0).asDouble(); // Uzyskanie wartości armor @@ -1184,8 +1184,12 @@ public void customEntityDamageEvent(EntityDamageByEntityEvent event){ armor=1; } } + if (event.getEntity().hasMetadata("defense")) { + List values = event.getEntity().getMetadata("defense"); + defense = values.get(0).asDouble(); // Uzyskanie wartości defense + } - event.setDamage(totalDamage-armor); + event.setDamage((totalDamage-armor)*(1-(0.01*defense))); pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.customEntityDamageEvent totalDamage: " + totalDamage+", bonusDamage: "+bonusDamage); return; From 5da9b0b00ba9296c5fe534c5099a96f3fc8eed64 Mon Sep 17 00:00:00 2001 From: Grzybol Date: Thu, 27 Jun 2024 00:57:15 +0200 Subject: [PATCH 6/8] - fix --- src/main/java/betterbox/mine/game/betterelo/Event.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/betterbox/mine/game/betterelo/Event.java b/src/main/java/betterbox/mine/game/betterelo/Event.java index e550bc4..c3bd3e8 100644 --- a/src/main/java/betterbox/mine/game/betterelo/Event.java +++ b/src/main/java/betterbox/mine/game/betterelo/Event.java @@ -1187,6 +1187,9 @@ public void customEntityDamageEvent(EntityDamageByEntityEvent event){ if (event.getEntity().hasMetadata("defense")) { List values = event.getEntity().getMetadata("defense"); defense = values.get(0).asDouble(); // Uzyskanie wartości defense + if (defense>=100){ + defense=0; + } } event.setDamage((totalDamage-armor)*(1-(0.01*defense))); From 75b01759693b132ca044c225eb26191359365e42 Mon Sep 17 00:00:00 2001 From: Grzybol Date: Thu, 27 Jun 2024 01:16:10 +0200 Subject: [PATCH 7/8] - fix --- src/main/java/betterbox/mine/game/betterelo/Event.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/betterbox/mine/game/betterelo/Event.java b/src/main/java/betterbox/mine/game/betterelo/Event.java index c3bd3e8..c011986 100644 --- a/src/main/java/betterbox/mine/game/betterelo/Event.java +++ b/src/main/java/betterbox/mine/game/betterelo/Event.java @@ -1191,8 +1191,11 @@ public void customEntityDamageEvent(EntityDamageByEntityEvent event){ defense=0; } } + double finalDamage =((totalDamage-armor)*(1-(0.01*defense))); + if(finalDamage<=0) + finalDamage=0; - event.setDamage((totalDamage-armor)*(1-(0.01*defense))); + event.setDamage(finalDamage); pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.customEntityDamageEvent totalDamage: " + totalDamage+", bonusDamage: "+bonusDamage); return; From 8788100669b277a4a5a13b5fe9d0e9007d27feed Mon Sep 17 00:00:00 2001 From: Grzybol Date: Thu, 27 Jun 2024 23:58:35 +0200 Subject: [PATCH 8/8] - fixed dmg calculations --- pom.xml | 2 +- .../betterbox/mine/game/betterelo/Event.java | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index af4c3ae..b46aed8 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ betterbox.mine.game BetterElo - 4.3.44-SNAPSHOT + 4.3.47-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 c011986..fe2e76d 100644 --- a/src/main/java/betterbox/mine/game/betterelo/Event.java +++ b/src/main/java/betterbox/mine/game/betterelo/Event.java @@ -1187,16 +1187,28 @@ public void customEntityDamageEvent(EntityDamageByEntityEvent event){ if (event.getEntity().hasMetadata("defense")) { List values = event.getEntity().getMetadata("defense"); defense = values.get(0).asDouble(); // Uzyskanie wartości defense + pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.customEntityDamageEvent defense from metadata: "+defense); if (defense>=100){ + pluginLogger.log(PluginLogger.LogLevel.WARNING, "Damage event: Mob has defense higher than 100! setting def=0:"); defense=0; } + }else{ + pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.customEntityDamageEvent defense metadata not found for mob: "+event.getEntity().getMetadata("MobName")); + } + CustomMobs.CustomMob customMob = null; + customMob = betterElo.getCustomMobFromEntity(event.getEntity()); + if(customMob!=null) + { + defense = customMob.defense; + pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.customEntityDamageEvent defense from customMob object: "+defense); } - double finalDamage =((totalDamage-armor)*(1-(0.01*defense))); + double defDmgReduction= (1-(0.01*defense)); + double finalDamage =((totalDamage-armor)*defDmgReduction); if(finalDamage<=0) finalDamage=0; event.setDamage(finalDamage); - pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.customEntityDamageEvent totalDamage: " + totalDamage+", bonusDamage: "+bonusDamage); + pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Event.customEntityDamageEvent finalDamage: "+finalDamage+", totalDamage: " + totalDamage+", bonusDamage: "+bonusDamage+", defDmgReduction(1-(0.01*defense)): "+defDmgReduction+", armor: "+armor); return; }