Renamed TNT effect. Made some fixes.

This commit is contained in:
GB6 2019-04-08 15:37:46 +02:00
parent 007f75d229
commit dffd2d7864
6 changed files with 38 additions and 11 deletions

View File

@ -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)

View File

@ -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);
}

View File

@ -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();
}
}
}

View File

@ -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())

View File

@ -30,6 +30,10 @@ public abstract class Manager<K, V> {
return Collections.unmodifiableCollection(map.values());
}
public Collection<K> getKeys() {
return Collections.unmodifiableCollection(map.keySet());
}
public void clear() {
map.clear();
}

View File

@ -78,7 +78,7 @@ public class Placeholders {
return;
}
Map<String, Integer> args = Arrays.stream(matcher.group(1).replaceAll("/\\s/g", "").split(","))
Map<String, Integer> 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"))));