diff --git a/core/src/main/java/com/songoda/epicenchants/effect/effects/SpawnMob.java b/core/src/main/java/com/songoda/epicenchants/effect/effects/SpawnMob.java index b4203d4..5f97301 100644 --- a/core/src/main/java/com/songoda/epicenchants/effect/effects/SpawnMob.java +++ b/core/src/main/java/com/songoda/epicenchants/effect/effects/SpawnMob.java @@ -26,13 +26,13 @@ public class SpawnMob extends EffectExecutor { private LeveledModifier health; private ItemBuilder helmet, chestPlate, leggings, boots, handItem; private boolean hostile; - private LeveledModifier maxAmount; + private LeveledModifier amount; public SpawnMob(ConfigurationSection section) { super(section); - entityType = EntityType.valueOf(section.getName()); - maxAmount = of(section.getString("max-amount")); + entityType = EntityType.valueOf(section.getString("mob-type")); + amount = of(section.getString("amount")); health = of(section.getString("health")); attackDamage = of(section.getString("attack-damage")); equipmentDropChance = LeveledModifier.of(section.getString("equipment-drop-chance")); @@ -49,7 +49,7 @@ public class SpawnMob extends EffectExecutor { public void execute(@NotNull Player user, @Nullable LivingEntity opponent, int level, EventType eventType) { Location location = user.getLocation(); - for (int i = 0; i < current().nextInt((int) (maxAmount.get(level, 1, user, opponent) + 1)); i++) { + for (int i = 0; i < amount.get(level, 1, user, opponent); i++) { Location spawnLocation = location.clone().add(current().nextInt(-3, 3), 0, current().nextInt(-3, 3)); int y = location.getWorld().getHighestBlockAt(spawnLocation).getY(); @@ -64,6 +64,7 @@ public class SpawnMob extends EffectExecutor { if (entity instanceof LivingEntity) { LivingEntity livingEntity = (LivingEntity) entity; + livingEntity.setRemoveWhenFarAway(true); int dropChance = (int) equipmentDropChance.get(level, 0, user, opponent); if (helmet != null) diff --git a/core/src/main/java/com/songoda/epicenchants/effect/effects/Tnt.java b/core/src/main/java/com/songoda/epicenchants/effect/effects/SpawnTnt.java similarity index 57% rename from core/src/main/java/com/songoda/epicenchants/effect/effects/Tnt.java rename to core/src/main/java/com/songoda/epicenchants/effect/effects/SpawnTnt.java index 9bef7b7..494e9b2 100644 --- a/core/src/main/java/com/songoda/epicenchants/effect/effects/Tnt.java +++ b/core/src/main/java/com/songoda/epicenchants/effect/effects/SpawnTnt.java @@ -3,6 +3,7 @@ package com.songoda.epicenchants.effect.effects; import com.songoda.epicenchants.effect.EffectExecutor; import com.songoda.epicenchants.enums.EventType; import com.songoda.epicenchants.objects.LeveledModifier; +import org.bukkit.Location; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; @@ -10,8 +11,10 @@ import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import org.jetbrains.annotations.NotNull; -public class Tnt extends EffectExecutor { - public Tnt(ConfigurationSection section) { +import static java.util.concurrent.ThreadLocalRandom.current; + +public class SpawnTnt extends EffectExecutor { + public SpawnTnt(ConfigurationSection section) { super(section); } @@ -19,8 +22,17 @@ public class Tnt extends EffectExecutor { public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) { consume(player -> { for (int i = 0; i < LeveledModifier.of(getSection().getString("amount")).get(level, 1, user, opponent); i++) { - TNTPrimed tntPrimed = (TNTPrimed) player.getWorld().spawnEntity(player.getLocation(), EntityType.PRIMED_TNT); + Location spawnLocation = player.getLocation().clone().add(current().nextInt(-3, 3), 0, current().nextInt(-3, 3)); + int y = player.getLocation().getWorld().getHighestBlockAt(spawnLocation).getY(); + + if (y < player.getLocation().getY() - 10 || y > player.getLocation().getY() + 10) { + continue; + } + + TNTPrimed tntPrimed = (TNTPrimed) player.getWorld().spawnEntity(spawnLocation, EntityType.PRIMED_TNT); tntPrimed.setFuseTicks((int) LeveledModifier.of(getSection().getString("fuse")).get(level, 60, user, opponent)); + tntPrimed.setCustomName("ee"); + tntPrimed.setCustomNameVisible(false); } }, user, opponent); } diff --git a/core/src/main/java/com/songoda/epicenchants/listeners/EntityListener.java b/core/src/main/java/com/songoda/epicenchants/listeners/EntityListener.java index fb6c91a..fbaf268 100644 --- a/core/src/main/java/com/songoda/epicenchants/listeners/EntityListener.java +++ b/core/src/main/java/com/songoda/epicenchants/listeners/EntityListener.java @@ -3,7 +3,10 @@ package com.songoda.epicenchants.listeners; import com.songoda.epicenchants.EpicEnchants; import com.songoda.epicenchants.enums.TriggerType; import de.tr7zw.itemnbtapi.NBTEntity; -import org.bukkit.entity.*; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Monster; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -121,4 +124,11 @@ public class EntityListener implements Listener { event.setCancelled(true); } } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) + public void onEntityExplode(EntityExplodeEvent event) { + if (event.getEntity().getCustomName().equals("ee")) { + event.blockList().clear(); + } + } } diff --git a/core/src/main/java/com/songoda/epicenchants/managers/CommandManager.java b/core/src/main/java/com/songoda/epicenchants/managers/CommandManager.java index d6da6c2..cde0f17 100644 --- a/core/src/main/java/com/songoda/epicenchants/managers/CommandManager.java +++ b/core/src/main/java/com/songoda/epicenchants/managers/CommandManager.java @@ -25,7 +25,7 @@ public class CommandManager extends BukkitCommandManager { // COMPLETIONS getCommandCompletions().registerCompletion("enchants", c -> - instance.getEnchantManager().getValues().stream().map(Enchant::getIdentifier).collect(Collectors.toList())); + instance.getEnchantManager().getKeys().stream().map(s -> s.replaceAll("\\s", "_")).collect(Collectors.toList())); getCommandCompletions().registerCompletion("giveType", c -> Arrays.stream(GiveType.values()).map(s -> s.toString().replace("_", "").toLowerCase()).collect(Collectors.toList())); @@ -45,7 +45,7 @@ public class CommandManager extends BukkitCommandManager { // CONTEXTS getCommandContexts().registerContext(Enchant.class, c -> - instance.getEnchantManager().getValue(c.popFirstArg()).orElseThrow(() -> + instance.getEnchantManager().getValue(c.popFirstArg().replaceAll("_", " ")).orElseThrow(() -> new InvalidCommandArgument("No enchant exists by that name", false))); getCommandContexts().registerContext(GiveType.class, c -> Arrays.stream(GiveType.values()) diff --git a/core/src/main/java/com/songoda/epicenchants/managers/Manager.java b/core/src/main/java/com/songoda/epicenchants/managers/Manager.java index 314653d..e119889 100644 --- a/core/src/main/java/com/songoda/epicenchants/managers/Manager.java +++ b/core/src/main/java/com/songoda/epicenchants/managers/Manager.java @@ -30,6 +30,10 @@ public abstract class Manager { return Collections.unmodifiableCollection(map.values()); } + public Collection getKeys() { + return Collections.unmodifiableCollection(map.keySet()); + } + public void clear() { map.clear(); } diff --git a/core/src/main/java/com/songoda/epicenchants/utils/single/Placeholders.java b/core/src/main/java/com/songoda/epicenchants/utils/single/Placeholders.java index 81e31f0..93d9ce4 100644 --- a/core/src/main/java/com/songoda/epicenchants/utils/single/Placeholders.java +++ b/core/src/main/java/com/songoda/epicenchants/utils/single/Placeholders.java @@ -78,7 +78,7 @@ public class Placeholders { return; } - Map args = Arrays.stream(matcher.group(1).replaceAll("/\\s/g", "").split(",")) + Map args = Arrays.stream(matcher.group(1).replaceAll("\\s", "").split(",")) .collect(Collectors.toMap(s -> s.split("=")[0], s -> Integer.parseInt(s.split("=")[1]))); reference.getAndUpdate(s -> s.replaceAll(pattern.pattern(), "" + ThreadLocalRandom.current().nextInt(args.get("low"), args.get("up"))));