From c627a003e1bb27f8a7caa1bdfc7ebd04a8a076d5 Mon Sep 17 00:00:00 2001 From: Grzybol Date: Tue, 9 Jul 2024 01:28:29 +0200 Subject: [PATCH 1/7] - fixed elo gain --- pom.xml | 2 +- .../betterbox/mine/game/betterelo/Event.java | 24 +++++++++---------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index b303012..32dc905 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ betterbox.mine.game BetterElo - 4.4.29-SNAPSHOT + 4.4.30-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 40be049..4e7058b 100644 --- a/src/main/java/betterbox/mine/game/betterelo/Event.java +++ b/src/main/java/betterbox/mine/game/betterelo/Event.java @@ -193,23 +193,23 @@ private Player getLastAttacker(Player victim) { @EventHandler(priority = EventPriority.LOWEST) public void onPlayerDeath(PlayerDeathEvent event) { - if(deathEventCounter==1){ - pluginLogger.log(PluginLogger.LogLevel.KILL_EVENT, "Event.onPlayerDeath event already handled!"); + Player victim = event.getEntity(); + + if (victim.hasMetadata("handledDeath")) { + pluginLogger.log(PluginLogger.LogLevel.KILL_EVENT, "Event.onPlayerDeath event already handled! killer: "+victim.getName()); return; } - deathEventCounter=1; + victim.setMetadata("handledDeath", new FixedMetadataValue(plugin, true)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> victim.removeMetadata("handledDeath", plugin), 1L); + pluginLogger.log(PluginLogger.LogLevel.KILL_EVENT, "Event.handleKillEvent added handledDeath metadata to "+victim.getName()); Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { try { - Player victim = event.getEntity(); + Player killer = victim.getKiller(); - if (killer.hasMetadata("handledDeath")) { - pluginLogger.log(PluginLogger.LogLevel.KILL_EVENT, "Event.onPlayerDeath event already handled! killer: "+victim.getName()); - return; - } - deathEventCounter=0; + if (!cheaters.getCheatersList().contains(victim.getName()) && !cheaters.getCheatersList().contains(killer.getName())) { pluginLogger.log(PluginLogger.LogLevel.KILL_EVENT, "Event: onPlayerDeath: victim: " + victim + " killer: " + killer); @@ -293,9 +293,7 @@ public void onPlayerDeath(PlayerDeathEvent event) { killer.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo] " + ChatColor.DARK_RED + "Your Elo difference in the Event ranking is too big! No reward for this one."); } } - killer.setMetadata("handledDeath", new FixedMetadataValue(plugin, true)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> killer.removeMetadata("handledDeath", plugin), 2L); - pluginLogger.log(PluginLogger.LogLevel.KILL_EVENT, "Event.handleKillEvent added handledDeath metadata to "+killer.getName()); + } else { @@ -324,7 +322,7 @@ private void notifyPlayersAboutPoints(Player killer, Player victim, double point victim.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[BetterElo]" + ChatColor.RED + "You have lost "+ChatColor.DARK_RED + "" + ChatColor.BOLD +df.format(pointsEarned)+" Elo"); } private void notifyPlayerAboutPoints(Player player, double pointsEarned, Double blockReward) { - pluginLogger.log(PluginLogger.LogLevel.KILL_EVENT, "Event: notifyPlayersAboutPoints called with parameters: "+player+" "+pointsEarned); + pluginLogger.log(PluginLogger.LogLevel.DEBUG, "Event: notifyPlayersAboutPoints called with parameters: "+player+" "+pointsEarned); DecimalFormat df = new DecimalFormat("#.##"); Duration fadeIn = Duration.ofMillis(300); // czas pojawiania się From c8c547b5429ff3d45511f0847378060aba435c8e Mon Sep 17 00:00:00 2001 From: Grzybol Date: Tue, 9 Jul 2024 01:51:41 +0200 Subject: [PATCH 2/7] - added /be forcespawn --- pom.xml | 2 +- .../mine/game/betterelo/BetterEloCommand.java | 5 + .../mine/game/betterelo/CustomMobs.java | 127 +++++++++++++----- .../game/betterelo/CustomMobsFileManager.java | 9 ++ 4 files changed, 107 insertions(+), 36 deletions(-) diff --git a/pom.xml b/pom.xml index 32dc905..bc66129 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ betterbox.mine.game BetterElo - 4.4.30-SNAPSHOT + 4.4.31-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 47e78a0..09cc18c 100644 --- a/src/main/java/betterbox/mine/game/betterelo/BetterEloCommand.java +++ b/src/main/java/betterbox/mine/game/betterelo/BetterEloCommand.java @@ -267,6 +267,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St break; case 2: switch (args[0].toLowerCase()) { + case "forcespawn": + if(sender.isOp()||sender.hasPermission("betterelo.forcespawn")){ + customMobs.spawnerForceSpawn(args[1]); + } + break; case "droptable": if(sender.isOp()||sender.hasPermission("betterelo.droptable")){ handleCreateDropTable(sender,args[1]); diff --git a/src/main/java/betterbox/mine/game/betterelo/CustomMobs.java b/src/main/java/betterbox/mine/game/betterelo/CustomMobs.java index 042eb29..c866fcf 100644 --- a/src/main/java/betterbox/mine/game/betterelo/CustomMobs.java +++ b/src/main/java/betterbox/mine/game/betterelo/CustomMobs.java @@ -40,39 +40,39 @@ static class CustomMob { boolean dropEMKS; EntityType entityType; LivingEntity entity; - ItemStack helmet, chestplate, leggings, boots,weapon; + ItemStack helmet, chestplate, leggings, boots, weapon; //HashMap< Double,ItemStack> dropTable; List dropTable; double armor, speed, attackDamage, EMKSchance; - int hp,attackSpeed,defense; + 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, int defense) { + 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; this.mobName = mobName; this.entity = entity; - if(weapon!=null){ + if (weapon != null) { this.weapon = weapon; - }else{ - plugin.getLogger().warning(mobName+" does not have weapon set. Setting AIR"); + } else { + plugin.getLogger().warning(mobName + " does not have weapon set. Setting AIR"); this.weapon = new ItemStack(Material.AIR); } this.entityType = entityType; - if(helmet!=null) { + if (helmet != null) { this.helmet = helmet; } - if(chestplate!=null) { + if (chestplate != null) { this.chestplate = chestplate; } - if(leggings!=null) { + if (leggings != null) { this.leggings = leggings; } - if(boots!=null) { + if (boots != null) { this.boots = boots; } this.dropFileManager = dropFileManager; @@ -88,7 +88,8 @@ static class CustomMob { 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, int defense) { + + 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; @@ -119,17 +120,18 @@ public void spawnMob(Location location) { setupMob(); // Teraz wywołujemy setupMob() po stworzeniu encji ((BetterElo) plugin).registerCustomMob(this.entity, this); } + public CustomMob cloneForSpawn(Location spawnLocation, String mobType) { CustomMob newMob = null; - if (mobType.equals("SKELETON")|| mobType.equals("ZOMBIE")) { - newMob = new CustomMob(this.plugin, this.dropFileManager, this.mobName, this.entityType, + if (mobType.equals("SKELETON") || mobType.equals("ZOMBIE")) { + newMob = new CustomMob(this.plugin, this.dropFileManager, this.mobName, this.entityType, 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.defense); newMob.spawnMob(spawnLocation); - }else{ + } 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.defense); @@ -150,10 +152,10 @@ private void setupMob() { entity.getEquipment().setLeggings(leggings); entity.getEquipment().setBoots(boots); entity.setPersistent(true); - if(weapon!=null){ + if (weapon != null) { entity.getEquipment().setItemInMainHand(weapon); - }else{ - plugin.getLogger().warning(mobName+" does not have weapon set. Setting AIR"); + } else { + plugin.getLogger().warning(mobName + " does not have weapon set. Setting AIR"); entity.getEquipment().setItemInMainHand(new ItemStack(Material.AIR)); } entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(hp); @@ -172,44 +174,45 @@ private void setupMob() { entity.setMetadata("armor", new FixedMetadataValue(plugin, armor)); entity.setMetadata("defense", new FixedMetadataValue(plugin, defense)); } + public String getMobName() { return this.mobName; } - } - - public CustomMobs(PluginLogger pluginLogger, JavaPlugin plugin, CustomMobsFileManager fileManager,FileRewardManager fileRewardManager){ + public CustomMobs(PluginLogger pluginLogger, JavaPlugin plugin, CustomMobsFileManager fileManager, FileRewardManager fileRewardManager) { this.plugin = plugin; this.pluginLogger = pluginLogger; this.fileManager = fileManager; this.fileRewardManager = fileRewardManager; loadCustomMobs(); } + public void spawnModifiedZombie(Player player, String mobName, int mobCount) { - pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS,"CustomMobs.spawnModifiedZombie called, player: "+player.getName()+", mobName: "+mobName+", mobCount: "+mobCount); + pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobs.spawnModifiedZombie called, player: " + player.getName() + ", mobName: " + mobName + ", mobCount: " + mobCount); Location playerLocation = player.getLocation(); //World world = player.getWorld(); - for (int i=0;i values = mob.getMetadata("MobName"); MetadataValue value = values.get(0); String customName = value.asString(); Component nameComponent; - nameComponent = Component.text(customName, NamedTextColor.DARK_RED) - .append(Component.text(" HP: " + Math.round(mob.getHealth()) + "/" + Math.round(mob.getMaxHealth()), NamedTextColor.WHITE)); + nameComponent = Component.text(customName, NamedTextColor.DARK_RED) + .append(Component.text(" HP: " + Math.round(mob.getHealth()) + "/" + Math.round(mob.getMaxHealth()), NamedTextColor.WHITE)); mob.customName(nameComponent); @@ -219,7 +222,7 @@ public void updateCustomMobName(LivingEntity mob) { public static String dropAverageDamage() { // Używamy funkcji wykładniczej do zmniejszenia prawdopodobieństwa wyższych wartości double x = -Math.log(random.nextDouble()) / 10.0; // Dostosuj parametr 10.0, aby zmienić rozkład - //double y = random. + //double y = random. int bonus = (int) Math.round(x * 60); // Skalowanie wyniku // Ograniczamy wartość bonusu do maksymalnie 60% @@ -230,7 +233,7 @@ public static String dropAverageDamage() { public void spawnCustomMobFromSpawner() { Map spawnersData = fileManager.spawnersData; - pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnCustomMobFromSpawner called. Loaded spawners: "+spawnersData); + pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnCustomMobFromSpawner called. Loaded spawners: " + spawnersData); // Sprawdzenie, czy istnieją spawnerzy w pliku if (spawnersData.isEmpty()) { pluginLogger.log(PluginLogger.LogLevel.ERROR, "No spawners found in spawners.yml."); @@ -240,14 +243,14 @@ public void spawnCustomMobFromSpawner() { long currentTime = System.currentTimeMillis(); for (Map.Entry entry : spawnersData.entrySet()) { - pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnZombieFromSpawner checking spawner: "+entry); + pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnZombieFromSpawner checking spawner: " + entry); String spawnerName = entry.getKey(); CustomMobsFileManager.SpawnerData spawnerData = entry.getValue(); Location location = getLocationFromString(spawnerData.location); // Sprawdzenie cooldownu if (!canSpawnMobs(spawnerName, fileManager.getSpawnerCooldown(spawnerName))) { - pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "Spawner " + spawnerName + " is on cooldown. Current spawnedMobCount: "+spawnerData.spawnedMobCount); + pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "Spawner " + spawnerName + " is on cooldown. Current spawnedMobCount: " + spawnerData.spawnedMobCount); continue; // Skip spawning if on cooldown } @@ -261,19 +264,73 @@ public void spawnCustomMobFromSpawner() { int remainingSlots = Math.max(0, maxMobs - spawnerData.spawnedMobCount); String mobName = fileManager.getSpawnerMobName(spawnerName); //pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnZombieFromSpawner "+spawnerName+", maxMobs: "+maxMobs+", remaining slots: "+remainingSlots); - if(remainingSlots==0){ - pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnZombieFromSpawner 0 remaining slots for "+spawnerName); + if (remainingSlots == 0) { + pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnZombieFromSpawner 0 remaining slots for " + spawnerName); + continue; + } + int mobsToSpawn = Math.min(mobCount, remainingSlots); + int spawnedMobs = 0; + pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnZombieFromSpawner " + spawnerName + ", maxMobs: " + maxMobs + ", remaining slots: " + remainingSlots + ", mobsToSpawn: " + mobsToSpawn + ", spawnerData.spawnedMobCount: " + spawnerData.spawnedMobCount); + for (int i = 0; i < mobsToSpawn; i++) { + spawnCustomMob(location, spawnerName, mobName); + spawnerData.spawnedMobCount++; + spawnedMobs++; + } + pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnZombieFromSpawner spawnedMobs: " + spawnedMobs); + // Ustawianie czasu ostatniego respa mobów z tego spawnera + spawnerLastSpawnTimes.put(spawnerName, currentTime); + } else { + pluginLogger.log(PluginLogger.LogLevel.ERROR, "Invalid world specified for spawner " + spawnerName); + } + } else { + pluginLogger.log(PluginLogger.LogLevel.ERROR, "Invalid location specified for spawner " + spawnerName); + } + } + } + + public void spawnerForceSpawn(String spawnerName) { + Map spawnersData = fileManager.spawnersData; + pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnCustomMobFromSpawner called. Loaded spawners: " + spawnersData); + // Sprawdzenie, czy istnieją spawnerzy w pliku + if (spawnersData.isEmpty()) { + pluginLogger.log(PluginLogger.LogLevel.ERROR, "No spawners found in spawners.yml."); + return; + } + + long currentTime = System.currentTimeMillis(); + + for (Map.Entry entry : spawnersData.entrySet()) { + if(entry.getKey()!=spawnerName){ + continue; + } + pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnZombieFromSpawner checking spawner: " + entry); + CustomMobsFileManager.SpawnerData spawnerData = entry.getValue(); + Location location = getLocationFromString(spawnerData.location); + + + // Spawnowanie zombiaków na podanej lokalizacji + if (location != null) { + World world = location.getWorld(); + if (world != null) { + int mobCount = spawnerData.mobCount; + // Get the remaining slots for spawning mobs + int maxMobs = fileManager.getSpawnerMaxMobs(spawnerName); + int remainingSlots = Math.max(0, maxMobs - spawnerData.spawnedMobCount); + String mobName = fileManager.getSpawnerMobName(spawnerName); + //pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnZombieFromSpawner "+spawnerName+", maxMobs: "+maxMobs+", remaining slots: "+remainingSlots); + if (remainingSlots == 0) { + pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnZombieFromSpawner 0 remaining slots for " + spawnerName); continue; } int mobsToSpawn = Math.min(mobCount, remainingSlots); int spawnedMobs = 0; - pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnZombieFromSpawner "+spawnerName+", maxMobs: "+maxMobs+", remaining slots: "+remainingSlots+", mobsToSpawn: "+mobsToSpawn+", spawnerData.spawnedMobCount: "+spawnerData.spawnedMobCount); + pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnZombieFromSpawner " + spawnerName + ", maxMobs: " + maxMobs + ", remaining slots: " + remainingSlots + ", mobsToSpawn: " + mobsToSpawn + ", spawnerData.spawnedMobCount: " + spawnerData.spawnedMobCount); for (int i = 0; i < mobsToSpawn; i++) { - spawnCustomMob(location,spawnerName,mobName); + spawnCustomMob(location, spawnerName, mobName); spawnerData.spawnedMobCount++; spawnedMobs++; } - pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnZombieFromSpawner spawnedMobs: "+spawnedMobs); + pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnZombieFromSpawner spawnedMobs: " + spawnedMobs); // Ustawianie czasu ostatniego respa mobów z tego spawnera spawnerLastSpawnTimes.put(spawnerName, currentTime); } else { diff --git a/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java b/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java index fff97b1..677ffeb 100644 --- a/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java +++ b/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java @@ -57,6 +57,15 @@ static class SpawnerData { public int getSpawnedMobCount() { return this.spawnedMobCount; } + public int getMaxMobs() { + return this.maxMobs; + } + public int getMobsPerSpawn() { + return this.mobCount; + } + public int getCooldown() { + return this.cooldown; + } } public class DropItem { private double dropChance; From 5bb0d0c40badb747433d67dd89516a8add5bb9c6 Mon Sep 17 00:00:00 2001 From: Grzybol Date: Tue, 9 Jul 2024 19:09:16 +0200 Subject: [PATCH 3/7] - fixes --- pom.xml | 2 +- .../mine/game/betterelo/CustomMobs.java | 22 +++++++------------ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index bc66129..b5b1809 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ betterbox.mine.game BetterElo - 4.4.31-SNAPSHOT + 4.4.33-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 c866fcf..2705368 100644 --- a/src/main/java/betterbox/mine/game/betterelo/CustomMobs.java +++ b/src/main/java/betterbox/mine/game/betterelo/CustomMobs.java @@ -290,7 +290,7 @@ public void spawnCustomMobFromSpawner() { public void spawnerForceSpawn(String spawnerName) { Map spawnersData = fileManager.spawnersData; - pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnCustomMobFromSpawner called. Loaded spawners: " + spawnersData); + pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnerForceSpawn called. Loaded spawners: " + spawnersData); // Sprawdzenie, czy istnieją spawnerzy w pliku if (spawnersData.isEmpty()) { pluginLogger.log(PluginLogger.LogLevel.ERROR, "No spawners found in spawners.yml."); @@ -300,10 +300,11 @@ public void spawnerForceSpawn(String spawnerName) { long currentTime = System.currentTimeMillis(); for (Map.Entry entry : spawnersData.entrySet()) { - if(entry.getKey()!=spawnerName){ + if(!entry.getKey().equals(spawnerName)){ + pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnerForceSpawn checking spawner: " + entry); continue; } - pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnZombieFromSpawner checking spawner: " + entry); + pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnerForceSpawn spawner: " + spawnerName+" found."); CustomMobsFileManager.SpawnerData spawnerData = entry.getValue(); Location location = getLocationFromString(spawnerData.location); @@ -313,24 +314,17 @@ public void spawnerForceSpawn(String spawnerName) { World world = location.getWorld(); if (world != null) { int mobCount = spawnerData.mobCount; - // Get the remaining slots for spawning mobs - int maxMobs = fileManager.getSpawnerMaxMobs(spawnerName); - int remainingSlots = Math.max(0, maxMobs - spawnerData.spawnedMobCount); + String mobName = fileManager.getSpawnerMobName(spawnerName); //pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnZombieFromSpawner "+spawnerName+", maxMobs: "+maxMobs+", remaining slots: "+remainingSlots); - if (remainingSlots == 0) { - pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnZombieFromSpawner 0 remaining slots for " + spawnerName); - continue; - } - int mobsToSpawn = Math.min(mobCount, remainingSlots); int spawnedMobs = 0; - pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnZombieFromSpawner " + spawnerName + ", maxMobs: " + maxMobs + ", remaining slots: " + remainingSlots + ", mobsToSpawn: " + mobsToSpawn + ", spawnerData.spawnedMobCount: " + spawnerData.spawnedMobCount); - for (int i = 0; i < mobsToSpawn; i++) { + pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnerForceSpawn " + spawnerName + ", spawnerData.spawnedMobCount: " + spawnerData.spawnedMobCount); + for (int i = 0; i < mobCount; i++) { spawnCustomMob(location, spawnerName, mobName); spawnerData.spawnedMobCount++; spawnedMobs++; } - pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnZombieFromSpawner spawnedMobs: " + spawnedMobs); + pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnerForceSpawn spawnedMobs: " + spawnedMobs); // Ustawianie czasu ostatniego respa mobów z tego spawnera spawnerLastSpawnTimes.put(spawnerName, currentTime); } else { From d359819079c66ef889f6a7027f71b5dcf14f2301 Mon Sep 17 00:00:00 2001 From: Grzybol Date: Wed, 10 Jul 2024 00:07:47 +0200 Subject: [PATCH 4/7] - configurable maxDistance for spawners - forcespawn command now kills all mobs from given spawner before resping new ones --- pom.xml | 2 +- .../mine/game/betterelo/BetterElo.java | 14 ++++-- .../mine/game/betterelo/CustomMobs.java | 49 ++++++++++++++++++- .../game/betterelo/CustomMobsFileManager.java | 37 ++++++++++++-- .../betterbox/mine/game/betterelo/Event.java | 31 +++++++++++- 5 files changed, 123 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index b5b1809..af372b3 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ betterbox.mine.game BetterElo - 4.4.33-SNAPSHOT + 4.4.48-SNAPSHOT jar BetterElo diff --git a/src/main/java/betterbox/mine/game/betterelo/BetterElo.java b/src/main/java/betterbox/mine/game/betterelo/BetterElo.java index 48c511b..57ee304 100644 --- a/src/main/java/betterbox/mine/game/betterelo/BetterElo.java +++ b/src/main/java/betterbox/mine/game/betterelo/BetterElo.java @@ -117,7 +117,7 @@ public void onEnable() { customMobsFileManager = new CustomMobsFileManager(folderPath,this, pluginLogger); pluginLogger.log(PluginLogger.LogLevel.DEBUG,"BetterElo: onEnable: calling customMobsFileManager.loadSpawners()"); customMobsFileManager.loadSpawners(); - customMobs = new CustomMobs(pluginLogger,this,customMobsFileManager, fileRewardManager); + customMobs = new CustomMobs(pluginLogger,this,customMobsFileManager, fileRewardManager,this ); pluginLogger.log(PluginLogger.LogLevel.INFO,"Starting spawners scheduler..."); customMobs.startSpawnerScheduler(); @@ -126,7 +126,7 @@ public void onEnable() { betterRanksCheaters = new BetterRanksCheaters(this,pluginLogger); CheaterCheckScheduler cheaterCheckScheduler = new CheaterCheckScheduler(this, betterRanksCheaters, getServer().getScheduler(), pluginLogger); // Rejestracja listenera eventów - event = new Event(dataManager, pluginLogger,this,betterRanksCheaters,configManager,this,customMobs,fileRewardManager,guiManager); + event = new Event(dataManager, pluginLogger,this,betterRanksCheaters,configManager,this,customMobs,fileRewardManager,guiManager,customMobsFileManager); getServer().getPluginManager().registerEvents(event, this); getCommand("be").setExecutor(new BetterEloCommand(this, dataManager, guiManager, pluginLogger, this, configManager,event,PKDB, customMobs, customMobsFileManager)); pluginLogger.log(PluginLogger.LogLevel.DEBUG,"BetterElo: onEnable: Plugin BetterElo został włączony pomyślnie."); @@ -610,6 +610,13 @@ public void killAllCustomMobs() { pluginLogger.log(PluginLogger.LogLevel.INFO, "BetterElo.killAllCustomMobs killed "+killedMobCount+" custom mobs."); } public void removeAndKillAllCustomMobs() { + for (CustomMobs.CustomMob customMob : customMobsMap.values()) { + // Sprawdzanie, czy encja jest nadal żywa przed próbą jej zabicia + if (customMob.entity != null && !customMob.entity.isDead()) { + customMob.entity.remove(); // Usuwa encję z świata + + } + } for (CustomMobs.CustomMob customMob : customMobsMap.values()) { // Sprawdzanie, czy encja jest nadal żywa przed próbą jej zabicia if (customMob.entity != null && !customMob.entity.isDead()) { @@ -645,6 +652,7 @@ public void run() { customMobs.decreaseMobCount(entry.getValue().spawnerName); iterator.remove(); String spawnerName = entry.getValue().spawnerName; + customMobs.spawnedMobsMap.remove(entry.getKey().getUniqueId()); if(!entry.getKey().isValid()){ @@ -665,7 +673,7 @@ public void run() { } } } - }.runTaskTimer(this, 0L, 20L * 60); // Uruchom co 1 minutę (20 ticków = 1 sekunda) + }.runTaskTimer(this, 0L, 20L * 10); // Uruchom co 1 minutę (20 ticków = 1 sekunda) } } diff --git a/src/main/java/betterbox/mine/game/betterelo/CustomMobs.java b/src/main/java/betterbox/mine/game/betterelo/CustomMobs.java index 2705368..3d674d9 100644 --- a/src/main/java/betterbox/mine/game/betterelo/CustomMobs.java +++ b/src/main/java/betterbox/mine/game/betterelo/CustomMobs.java @@ -29,11 +29,13 @@ public class CustomMobs { private Map customMobsMap = new HashMap<>(); private final PluginLogger pluginLogger; private final JavaPlugin plugin; + private final BetterElo betterElo; private final FileRewardManager fileRewardManager; private final CustomMobsFileManager fileManager; private static final Random random = new Random(); private BukkitTask spawnerTask; public Map spawnerLastSpawnTimes = new HashMap<>(); // Mapa przechowująca czas ostatniego respa mobów z każdego spawnera + public Map spawnedMobsMap = new HashMap<>(); static class CustomMob { String mobName, dropTableName, spawnerName; @@ -183,8 +185,9 @@ public String getMobName() { } - public CustomMobs(PluginLogger pluginLogger, JavaPlugin plugin, CustomMobsFileManager fileManager, FileRewardManager fileRewardManager) { + public CustomMobs(PluginLogger pluginLogger, JavaPlugin plugin, CustomMobsFileManager fileManager, FileRewardManager fileRewardManager, BetterElo betterElo) { this.plugin = plugin; + this.betterElo = betterElo; this.pluginLogger = pluginLogger; this.fileManager = fileManager; this.fileRewardManager = fileRewardManager; @@ -289,7 +292,34 @@ public void spawnCustomMobFromSpawner() { } public void spawnerForceSpawn(String spawnerName) { + //pluginLogger.log(PluginLogger.LogLevel.INFO, "CustomMobs.spawnerForceSpawn called with " + spawnerName+" spawnedMobsMap"+spawnedMobsMap.toString()); + Map spawnersData = fileManager.spawnersData; + if (spawnedMobsMap == null || spawnedMobsMap.isEmpty()) { + pluginLogger.log(PluginLogger.LogLevel.WARNING, "CustomMobs.spawnerForceSpawn. The spawnedMobsMap is empty or null."); + }else { + try { + + Iterator> iterator = spawnedMobsMap.entrySet().iterator(); + //CustomMob customMob = betterElo.getCustomMobFromEntity(entity) ; + while (iterator.hasNext()) { + Map.Entry entry = iterator.next(); + pluginLogger.log(PluginLogger.LogLevel.INFO, "CustomMobs.spawnerForceSpawn. Checking key " + entry.getKey() + " with value " + entry.getValue()); + if (spawnerName.equals(entry.getValue())) { + pluginLogger.log(PluginLogger.LogLevel.INFO, "CustomMobs.spawnerForceSpawn. " + spawnerName + " matching key " + entry.getKey() + ", value " + entry.getValue()); + Entity entity = Bukkit.getServer().getEntity(entry.getKey()); + if (entity != null && !entity.isDead()) { + entity.remove(); // Usuwa encję z świata + + iterator.remove(); // Bezpieczne usuwanie wpisu podczas iteracji + pluginLogger.log(PluginLogger.LogLevel.INFO, "CustomMobs.spawnerForceSpawn. Removing living mob from spawner" + spawnerName); + } + } + } + } catch (Exception e) { + pluginLogger.log(PluginLogger.LogLevel.ERROR, "CustomMobs.spawnerForceSpawn exception: " + e.getMessage()); + } + } pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnerForceSpawn called. Loaded spawners: " + spawnersData); // Sprawdzenie, czy istnieją spawnerzy w pliku if (spawnersData.isEmpty()) { @@ -333,10 +363,11 @@ public void spawnerForceSpawn(String spawnerName) { } else { pluginLogger.log(PluginLogger.LogLevel.ERROR, "Invalid location specified for spawner " + spawnerName); } + pluginLogger.log(PluginLogger.LogLevel.INFO, "CustomMobs.spawnerForceSpawn spawnedMobsMap"+spawnedMobsMap.toString()); } } - private Location getLocationFromString(String locationString) { + public Location getLocationFromString(String locationString) { try { String[] parts = locationString.split(","); if (parts.length == 4) { @@ -465,6 +496,14 @@ public CustomMob getCustomMob(String mobName) { // Zwróć customowego moba na podstawie nazwy return customMobsMap.get(mobName); } + public Entity getEntityForCustomMob(CustomMob customMob) { + // Sprawdzenie, czy przypisana encja do moba istnieje + if (customMob != null && customMob.entity != null) { + return customMob.entity; // Zwróć encję, jeśli jest już przypisana + } + // W przypadku braku encji, możemy zwrócić null lub rozważyć inne działanie, np. logowanie + return null; // Zwróć null, jeśli encja nie jest ustawiona + } public void spawnCustomMob(Location location, String spawnerName, String mobName) { pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobs.spawnCustomMob called, mobName: " + mobName+", spawnerName: "+spawnerName+", location: "+location); @@ -477,6 +516,12 @@ public void spawnCustomMob(Location location, String spawnerName, String mobName //newMob.dropTable = fileManager.loadCustomDrops(newMob.dropTableName); pluginLogger.log(PluginLogger.LogLevel.DROP, "CustomMobs.spawnCustomMob newMob.dropTablename: "+newMob.dropTableName+", newMob.dropTable: "+newMob.dropTable); pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobs.spawnCustomMob newMob.spawnerName: "+newMob.spawnerName); + try{ + spawnedMobsMap.put(newMob.entity.getUniqueId(), spawnerName); + pluginLogger.log(PluginLogger.LogLevel.INFO, "Mob spawned with UUID: " + newMob.entity.getUniqueId() + ", spawnerName:" + newMob.spawnerName); + }catch (Exception e){ + pluginLogger.log(PluginLogger.LogLevel.ERROR, "CustomMobs.spawnCustomMob exception: "+e.getMessage()); + } } else { pluginLogger.log(PluginLogger.LogLevel.ERROR, "CustomMobs.spawnCustomMob failed, mob not found: " + mobName); } diff --git a/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java b/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java index 677ffeb..24012c3 100644 --- a/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java +++ b/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java @@ -38,6 +38,7 @@ public CustomMobsFileManager(String folderPath, JavaPlugin plugin, PluginLogger // Klasa wewnętrzna do przechowywania danych spawnera static class SpawnerData { String spawnerName; + int maxDistance; String location; String mobName; int cooldown; @@ -45,13 +46,14 @@ static class SpawnerData { int spawnedMobCount; // Counter for spawned mobs int maxMobs; - SpawnerData(String spawnerName, String location, String mobName, int cooldown, int mobCount, int maxMobs) { + SpawnerData(String spawnerName, String location, String mobName, int cooldown, int mobCount, int maxMobs, int maxDistance) { this.spawnerName = spawnerName; this.location = location; this.mobName = mobName; this.cooldown = cooldown; this.mobCount = mobCount; this.maxMobs = maxMobs; + this.maxDistance = maxDistance; this.spawnedMobCount = 0; // Initialize the spawned mob counter to 0 } public int getSpawnedMobCount() { @@ -66,6 +68,7 @@ public int getMobsPerSpawn() { public int getCooldown() { return this.cooldown; } + public int getMaxDistance() {return this.maxDistance;} } public class DropItem { private double dropChance; @@ -165,8 +168,11 @@ public void loadSpawners() { int cooldown = spawnerSection.getInt("cooldown"); int mobCount = spawnerSection.getInt("mobsPerSpawn"); int maxMobs = spawnerSection.getInt("maxMobs"); + //default 20 blocks + int maxDistance = 20; + maxDistance=spawnerSection.getInt("maxDistance"); // Zapisywanie danych spawnera do struktury w pamięci - spawnersData.put(key, new SpawnerData(key,location, mobName, cooldown,mobCount, maxMobs)); + spawnersData.put(key, new SpawnerData(key,location, mobName, cooldown,mobCount, maxMobs,maxDistance)); pluginLogger.log(PluginLogger.LogLevel.INFO, "Spawner "+key+" with mobName: "+mobName+", location: ("+location+"), cooldown: "+cooldown+", mobsPerSpawn: "+mobCount+", maxMobs: "+maxMobs+" loaded!"); } } @@ -191,6 +197,19 @@ public void saveSpawner(Location location, String spawnerName, String mobName, i } } + public int getMaxDistance(String spawnerName){ + if (spawnersData.containsKey(spawnerName)) { + // Retrieve the SpawnerData object corresponding to the spawnerName + SpawnerData spawnerData = spawnersData.get(spawnerName); + // Return the cooldown value + pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "Spawner '" + spawnerName + "' spawnerData.maxDistance: "+spawnerData.maxDistance); + return spawnerData.maxDistance; + } else { + // If the spawnerName is not found, log an error and return a default value or throw an exception + pluginLogger.log(PluginLogger.LogLevel.ERROR, "Spawner '" + spawnerName + "' not found."); + return 20; // or any other default value that indicates an error + } + } public String getSpawnerMobName(String spawnerName){ if (spawnersData.containsKey(spawnerName)) { // Retrieve the SpawnerData object corresponding to the spawnerName @@ -203,6 +222,18 @@ public String getSpawnerMobName(String spawnerName){ return null; // or any other default value that indicates an error } } + public String getSpawnerLocation(String spawnerName){ + if (spawnersData.containsKey(spawnerName)) { + // Retrieve the SpawnerData object corresponding to the spawnerName + SpawnerData spawnerData = spawnersData.get(spawnerName); + // Return the cooldown value + return spawnerData.location; + } else { + // If the spawnerName is not found, log an error and return a default value or throw an exception + pluginLogger.log(PluginLogger.LogLevel.ERROR, "Spawner '" + spawnerName + "' not found."); + return null; // or any other default value that indicates an error + } + } public int getSpawnerCooldown(String spawnerName) { // Check if the spawnerName exists in the spawnersData map if (spawnersData.containsKey(spawnerName)) { @@ -255,7 +286,7 @@ public CustomMobs.CustomMob loadCustomMob(JavaPlugin plugin, FileRewardManager d ItemStack leggings=null; ItemStack boots=null; ItemStack weapon=null; - + pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob entityTypeString: "+entityTypeString); if (entityTypeString.equals("SKELETON")||entityTypeString.equals("ZOMBIE")) {// Wczytanie wyposażenia z pliku pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobsFileManager.loadCustomMob mob is ZOMBIE or SKELETON"); helmet = loadItemStack(mobData, "equipment.helmet"); diff --git a/src/main/java/betterbox/mine/game/betterelo/Event.java b/src/main/java/betterbox/mine/game/betterelo/Event.java index 4e7058b..e342f7e 100644 --- a/src/main/java/betterbox/mine/game/betterelo/Event.java +++ b/src/main/java/betterbox/mine/game/betterelo/Event.java @@ -55,13 +55,14 @@ public class Event implements Listener { private HashMap lastZephyrUsage = new HashMap<>(); private HashMap lastFlameUsage = new HashMap<>(); private CustomMobs customMobs; + private CustomMobsFileManager customMobsFileManager; private GuiManager guiManager; private FileRewardManager fileRewardManager; private int deathEventCounter; private final Random random = new Random(); //public final long cooldownMillis = 1500; // 1.5s - public Event(DataManager dataManager, PluginLogger pluginLogger, JavaPlugin plugin, BetterRanksCheaters cheaters, ExtendedConfigManager configManager, BetterElo betterElo, CustomMobs customMobs, FileRewardManager fileRewardManager, GuiManager guiManager) { + public Event(DataManager dataManager, PluginLogger pluginLogger, JavaPlugin plugin, BetterRanksCheaters cheaters, ExtendedConfigManager configManager, BetterElo betterElo, CustomMobs customMobs, FileRewardManager fileRewardManager, GuiManager guiManager, CustomMobsFileManager customMobsFileManager) { this.dataManager = dataManager; this.fileRewardManager = fileRewardManager; this.pluginLogger = pluginLogger; @@ -70,6 +71,7 @@ public Event(DataManager dataManager, PluginLogger pluginLogger, JavaPlugin plug this.cheaters = cheaters; this.configManager = configManager; this.customMobs = customMobs; + this.customMobsFileManager = customMobsFileManager; this.guiManager = guiManager; Bukkit.getPluginManager().registerEvents(this, plugin); } @@ -1572,6 +1574,33 @@ public void onInventoryClose(InventoryCloseEvent event) { } } } + @EventHandler + public void onEntityMove(EntityMoveEvent event) { + Entity entity = event.getEntity(); + CustomMobs.CustomMob customMob = null; + customMob = betterElo.getCustomMobFromEntity(entity); + + if (customMob != null) { + Location entityLocation = entity.getLocation(); + String spawnerLocationString = customMobsFileManager.getSpawnerLocation(customMob.spawnerName); + Location spawnerLocation = customMobs.getLocationFromString(spawnerLocationString); + + int maxDistance = customMobsFileManager.getMaxDistance(customMob.spawnerName); + if(maxDistance==0){ + maxDistance=20; + } + if (spawnerLocation==null){ + return; + } + if (entityLocation.distance(spawnerLocation) > maxDistance) { + // Teleportacja entity z powrotem do spawnerLocation + pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "Event.onEntityMove teleporting mob: "+customMob.mobName); + entity.teleport(spawnerLocation); + } + + + } + } From 9fbea545f514fbbd5858b517f355b8f9699df41b Mon Sep 17 00:00:00 2001 From: Grzybol Date: Wed, 10 Jul 2024 00:14:13 +0200 Subject: [PATCH 5/7] - fixed log levels --- pom.xml | 2 +- .../java/betterbox/mine/game/betterelo/CustomMobs.java | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index af372b3..031b169 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ betterbox.mine.game BetterElo - 4.4.48-SNAPSHOT + 4.4.49-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 3d674d9..3ea3b26 100644 --- a/src/main/java/betterbox/mine/game/betterelo/CustomMobs.java +++ b/src/main/java/betterbox/mine/game/betterelo/CustomMobs.java @@ -304,15 +304,15 @@ public void spawnerForceSpawn(String spawnerName) { //CustomMob customMob = betterElo.getCustomMobFromEntity(entity) ; while (iterator.hasNext()) { Map.Entry entry = iterator.next(); - pluginLogger.log(PluginLogger.LogLevel.INFO, "CustomMobs.spawnerForceSpawn. Checking key " + entry.getKey() + " with value " + entry.getValue()); + pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnerForceSpawn. Checking key " + entry.getKey() + " with value " + entry.getValue()); if (spawnerName.equals(entry.getValue())) { - pluginLogger.log(PluginLogger.LogLevel.INFO, "CustomMobs.spawnerForceSpawn. " + spawnerName + " matching key " + entry.getKey() + ", value " + entry.getValue()); + pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnerForceSpawn. " + spawnerName + " matching key " + entry.getKey() + ", value " + entry.getValue()); Entity entity = Bukkit.getServer().getEntity(entry.getKey()); if (entity != null && !entity.isDead()) { entity.remove(); // Usuwa encję z świata iterator.remove(); // Bezpieczne usuwanie wpisu podczas iteracji - pluginLogger.log(PluginLogger.LogLevel.INFO, "CustomMobs.spawnerForceSpawn. Removing living mob from spawner" + spawnerName); + pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnerForceSpawn. Removing living mob from spawner" + spawnerName); } } } @@ -363,7 +363,7 @@ public void spawnerForceSpawn(String spawnerName) { } else { pluginLogger.log(PluginLogger.LogLevel.ERROR, "Invalid location specified for spawner " + spawnerName); } - pluginLogger.log(PluginLogger.LogLevel.INFO, "CustomMobs.spawnerForceSpawn spawnedMobsMap"+spawnedMobsMap.toString()); + pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnerForceSpawn spawnedMobsMap"+spawnedMobsMap.toString()); } } @@ -518,7 +518,7 @@ public void spawnCustomMob(Location location, String spawnerName, String mobName pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "CustomMobs.spawnCustomMob newMob.spawnerName: "+newMob.spawnerName); try{ spawnedMobsMap.put(newMob.entity.getUniqueId(), spawnerName); - pluginLogger.log(PluginLogger.LogLevel.INFO, "Mob spawned with UUID: " + newMob.entity.getUniqueId() + ", spawnerName:" + newMob.spawnerName); + pluginLogger.log(PluginLogger.LogLevel.CUSTOM_MOBS, "Mob spawned with UUID: " + newMob.entity.getUniqueId() + ", spawnerName:" + newMob.spawnerName); }catch (Exception e){ pluginLogger.log(PluginLogger.LogLevel.ERROR, "CustomMobs.spawnCustomMob exception: "+e.getMessage()); } From ba1b29f6b1496a549f9dff6992bc4502306442a3 Mon Sep 17 00:00:00 2001 From: Grzybol Date: Wed, 10 Jul 2024 00:36:42 +0200 Subject: [PATCH 6/7] - fixed mob teleport --- pom.xml | 2 +- .../betterbox/mine/game/betterelo/CustomMobs.java | 11 +++++++++++ .../java/betterbox/mine/game/betterelo/Event.java | 9 +++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 031b169..07b87b1 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ betterbox.mine.game BetterElo - 4.4.49-SNAPSHOT + 4.4.52-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 3ea3b26..f255f1b 100644 --- a/src/main/java/betterbox/mine/game/betterelo/CustomMobs.java +++ b/src/main/java/betterbox/mine/game/betterelo/CustomMobs.java @@ -251,6 +251,16 @@ public void spawnCustomMobFromSpawner() { CustomMobsFileManager.SpawnerData spawnerData = entry.getValue(); Location location = getLocationFromString(spawnerData.location); + while (location.getBlock().getType() != Material.AIR) { + location.add(0, 1, 0); // Zwiększ y o 1 + if (location.getBlockY() > location.getWorld().getMaxHeight()) { + // Jeśli przekraczamy maksymalną wysokość, przerwij pętlę, aby uniknąć pętli nieskończonej + System.out.println("Reached the top of the world without finding an AIR block."); + break; + } + } + location.add(0, 1, 0); + // Sprawdzenie cooldownu if (!canSpawnMobs(spawnerName, fileManager.getSpawnerCooldown(spawnerName))) { pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "Spawner " + spawnerName + " is on cooldown. Current spawnedMobCount: " + spawnerData.spawnedMobCount); @@ -271,6 +281,7 @@ public void spawnCustomMobFromSpawner() { pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnZombieFromSpawner 0 remaining slots for " + spawnerName); continue; } + int mobsToSpawn = Math.min(mobCount, remainingSlots); int spawnedMobs = 0; pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "CustomMobs.spawnZombieFromSpawner " + spawnerName + ", maxMobs: " + maxMobs + ", remaining slots: " + remainingSlots + ", mobsToSpawn: " + mobsToSpawn + ", spawnerData.spawnedMobCount: " + spawnerData.spawnedMobCount); diff --git a/src/main/java/betterbox/mine/game/betterelo/Event.java b/src/main/java/betterbox/mine/game/betterelo/Event.java index e342f7e..73a6654 100644 --- a/src/main/java/betterbox/mine/game/betterelo/Event.java +++ b/src/main/java/betterbox/mine/game/betterelo/Event.java @@ -1595,6 +1595,15 @@ public void onEntityMove(EntityMoveEvent event) { if (entityLocation.distance(spawnerLocation) > maxDistance) { // Teleportacja entity z powrotem do spawnerLocation pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "Event.onEntityMove teleporting mob: "+customMob.mobName); + while (spawnerLocation.getBlock().getType() != Material.AIR) { + spawnerLocation.add(0, 1, 0); // Zwiększ y o 1 + if (spawnerLocation.getBlockY() > spawnerLocation.getWorld().getMaxHeight()) { + // Jeśli przekraczamy maksymalną wysokość, przerwij pętlę, aby uniknąć pętli nieskończonej + System.out.println("Reached the top of the world without finding an AIR block."); + break; + } + } + spawnerLocation.add(0, 1, 0); entity.teleport(spawnerLocation); } From 250d143761b99e02c82ebe603d9e02ac473a9552 Mon Sep 17 00:00:00 2001 From: Grzybol Date: Fri, 12 Jul 2024 17:02:06 +0200 Subject: [PATCH 7/7] - fixed log levels --- .../betterbox/mine/game/betterelo/CustomMobsFileManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java b/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java index 24012c3..4bfed10 100644 --- a/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java +++ b/src/main/java/betterbox/mine/game/betterelo/CustomMobsFileManager.java @@ -202,7 +202,7 @@ public int getMaxDistance(String spawnerName){ // Retrieve the SpawnerData object corresponding to the spawnerName SpawnerData spawnerData = spawnersData.get(spawnerName); // Return the cooldown value - pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "Spawner '" + spawnerName + "' spawnerData.maxDistance: "+spawnerData.maxDistance); + //pluginLogger.log(PluginLogger.LogLevel.SPAWNERS, "Spawner '" + spawnerName + "' spawnerData.maxDistance: "+spawnerData.maxDistance); return spawnerData.maxDistance; } else { // If the spawnerName is not found, log an error and return a default value or throw an exception