Even more bug fixes

This commit is contained in:
GB6 2019-02-11 11:49:22 +01:00
parent eff885270e
commit a4ced7b7ac
24 changed files with 170 additions and 289 deletions

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>EpicEnchants-Parent</artifactId>
<groupId>com.songoda</groupId>
<version>1.0</version>
<version>1.0.1-ALPHA</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,9 +5,14 @@ import co.aikar.commands.InvalidCommandArgument;
import com.songoda.epicenchants.commands.EnchantCommand;
import com.songoda.epicenchants.enums.GiveType;
import com.songoda.epicenchants.listeners.*;
import com.songoda.epicenchants.managers.*;
import com.songoda.epicenchants.managers.EnchantManager;
import com.songoda.epicenchants.managers.FileManager;
import com.songoda.epicenchants.managers.GroupManager;
import com.songoda.epicenchants.managers.InfoManager;
import com.songoda.epicenchants.objects.Enchant;
import com.songoda.epicenchants.utils.*;
import com.songoda.epicenchants.utils.EnchantUtils;
import com.songoda.epicenchants.utils.FastInv;
import com.songoda.epicenchants.utils.SpecialItems;
import lombok.Getter;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
@ -18,7 +23,9 @@ import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static com.songoda.epicenchants.utils.GeneralUtils.color;
import static org.bukkit.Bukkit.getConsoleSender;
@ -61,7 +68,6 @@ public class EpicEnchants extends JavaPlugin {
setupCommands();
setupListeners();
setupVersion();
if (!enchantManager.getEnchants().isEmpty()) {
getLogger().info("Successfully loaded enchants: " + enchantManager.getEnchants().stream().map(Enchant::getIdentifier).collect(Collectors.joining(", ")));
@ -86,6 +92,8 @@ public class EpicEnchants extends JavaPlugin {
commandManager.getCommandCompletions().registerCompletion("enchants", c -> enchantManager.getEnchants().stream().map(Enchant::getIdentifier).collect(Collectors.toList()));
commandManager.getCommandCompletions().registerCompletion("enchantFiles", c -> fileManager.getYmlFiles("enchants").orElse(Collections.emptyList()).stream().map(File::getName).collect(Collectors.toList()));
commandManager.getCommandCompletions().registerCompletion("giveType", c -> Arrays.stream(GiveType.values()).map(s -> s.toString().replace("_", "").toLowerCase()).collect(Collectors.toList()));
commandManager.getCommandCompletions().registerCompletion("levels", c -> IntStream.rangeClosed(1, c.getContextValue(Enchant.class).getMaxLevel()).boxed().map(Objects::toString).collect(Collectors.toList()));
commandManager.getCommandCompletions().registerCompletion("increment", c -> IntStream.rangeClosed(0, 100).filter(i -> i % 10 == 0).boxed().map(Objects::toString).collect(Collectors.toList()));
commandManager.getCommandContexts().registerContext(Enchant.class, c -> enchantManager.getEnchant(c.popFirstArg()).orElseThrow(() -> new InvalidCommandArgument("No enchant exists by that name")));
commandManager.getCommandContexts().registerContext(File.class, c -> enchantManager.getEnchantFile(c.popFirstArg()).orElseThrow(() -> new InvalidCommandArgument("No EnchantFile exists by that name")));
@ -109,11 +117,6 @@ public class EpicEnchants extends JavaPlugin {
}}.forEach(listener -> Bukkit.getPluginManager().registerEvents(listener, this));
}
private void setupVersion() {
int currentVersion = Integer.parseInt(getServer().getClass().getPackage().getName().split("\\.")[3].split("_")[1]);
VersionDependent.initLegacy(currentVersion);
}
public void reload() {
reloadConfig();
locale.reloadMessages();

View File

@ -33,11 +33,11 @@ public class EnchantCommand extends BaseCommand {
//ee give book {player} {enchant} {group}
@Subcommand("give book")
@CommandCompletion("@players @enchants @nothing @nothing @nothing")
@CommandCompletion("@players @enchants @levels @increment @increment")
@Description("Give enchant books to players")
@CommandPermission("epicenchants.give")
public void onGiveBook(CommandSender sender, @Flags("other") Player target, Enchant enchant, @Optional Integer level, @Optional Integer successRate, @Optional Integer destroyRate) {
if (level > enchant.getMaxLevel()) {
if (level != null && level > enchant.getMaxLevel()) {
sender.sendMessage(instance.getLocale().getMessageWithPrefix("command.book.maxlevel",
of("enchant", enchant.getIdentifier()),
of("max-level", enchant.getMaxLevel())));

View File

@ -1,7 +1,7 @@
package com.songoda.epicenchants.effect;
import com.songoda.epicenchants.enums.EffectType;
import com.songoda.epicenchants.enums.EventType;
import com.songoda.epicenchants.enums.TriggerType;
import com.songoda.epicenchants.objects.LeveledModifier;
import com.songoda.epicenchants.utils.GeneralUtils;
import lombok.Getter;
@ -20,22 +20,22 @@ import static com.songoda.epicenchants.effect.EffectExecutor.Who.WEARER;
public abstract class EffectExecutor {
@Getter private final ConfigurationSection section;
@Getter private final EffectType effectType;
private EffectType[] allowedEffects;
@Getter private final TriggerType triggerType;
private TriggerType[] allowedEffects;
public EffectExecutor(ConfigurationSection section, EffectType... allowedEffects) {
public EffectExecutor(ConfigurationSection section, TriggerType... allowedEffects) {
this.section = section;
this.effectType = EffectType.valueOf(section.getString("type"));
this.triggerType = TriggerType.valueOf(section.getString("trigger"));
this.allowedEffects = allowedEffects;
}
public void testAndRun(@NotNull Player wearer, @Nullable LivingEntity opponent, int level, EffectType type, Event event, EventType eventType) {
if (type != effectType) {
public void testAndRun(@NotNull Player wearer, @Nullable LivingEntity opponent, int level, TriggerType type, Event event, EventType eventType) {
if (type != triggerType) {
return;
}
if (allowedEffects.length != 0 && Arrays.stream(allowedEffects).noneMatch(t -> t == effectType)) {
throw new IllegalStateException(section.getName() + " cannot be triggered by " + effectType.toString());
if (allowedEffects.length != 0 && Arrays.stream(allowedEffects).noneMatch(t -> t == triggerType)) {
throw new IllegalStateException(section.getName() + " cannot be triggered by " + triggerType.toString());
}
if (section.isString("chance") && !GeneralUtils.chance(LeveledModifier.of(section.getString("chance")).get(level, 100))) {
@ -65,7 +65,7 @@ public abstract class EffectExecutor {
}
public void consume(Consumer<LivingEntity> playerConsumer, Player wearer, @Nullable LivingEntity opponent) {
if (effectType == EffectType.HELD_ITEM || effectType == EffectType.STATIC_EFFECT) {
if (triggerType == TriggerType.HELD_ITEM || triggerType == TriggerType.STATIC_EFFECT) {
playerConsumer.accept(wearer);
return;
}

View File

@ -7,7 +7,8 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Optional;
import static com.google.common.base.CaseFormat.*;
import static com.google.common.base.CaseFormat.UPPER_CAMEL;
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
public class EffectManager {
@ -23,6 +24,7 @@ public class EffectManager {
Object object = constructor.newInstance(section);
return Optional.of((EffectExecutor) object);
} catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException | ClassCastException e) {
e.printStackTrace();
Bukkit.getLogger().severe("Invalid effect: " + section.getName());
}

View File

@ -7,9 +7,9 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import static com.songoda.epicenchants.enums.EffectType.HELD_ITEM;
import static com.songoda.epicenchants.enums.EffectType.STATIC_EFFECT;
import static com.songoda.epicenchants.enums.EventType.ON;
import static com.songoda.epicenchants.enums.TriggerType.HELD_ITEM;
import static com.songoda.epicenchants.enums.TriggerType.STATIC_EFFECT;
public class Fly extends EffectExecutor {
public Fly(ConfigurationSection section) {

View File

@ -1,7 +1,6 @@
package com.songoda.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EffectType;
import com.songoda.epicenchants.enums.EventType;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
@ -10,8 +9,8 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class ModifyFood extends EffectExecutor {
public ModifyFood(ConfigurationSection section, EffectType... allowedEffects) {
super(section, allowedEffects);
public ModifyFood(ConfigurationSection section) {
super(section);
}
@Override

View File

@ -20,7 +20,7 @@ public class ModifyHealth extends EffectExecutor {
if (entity.getHealth() + amount > entity.getMaxHealth()) {
entity.setHealth(entity.getMaxHealth());
} else if (entity.getHealth() + amount < 0) {
entity.setHealth(0);
entity.setHealth(0D);
} else {
entity.setHealth(entity.getHealth() + amount);
}

View File

@ -1,8 +1,8 @@
package com.songoda.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EffectType;
import com.songoda.epicenchants.enums.EventType;
import com.songoda.epicenchants.enums.TriggerType;
import com.songoda.epicenchants.objects.LeveledModifier;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
@ -29,7 +29,7 @@ public class Potion extends EffectExecutor {
return;
}
if (getEffectType() == EffectType.STATIC_EFFECT || getEffectType() == EffectType.HELD_ITEM) {
if (this.getTriggerType() == TriggerType.STATIC_EFFECT || this.getTriggerType() == TriggerType.HELD_ITEM) {
if (eventType == EventType.ON) {
consume(entity -> entity.addPotionEffect(new PotionEffect(effectType, Integer.MAX_VALUE, ((int) amplifier.get(level, 0)),
false, false)), wearer, opponent);

View File

@ -15,7 +15,28 @@ public class StealHealth extends EffectExecutor {
@Override
public void execute(@NotNull Player wearer, LivingEntity opponent, int level, EventType eventType) {
double amount = getAmount().get(level, 0);
wearer.setHealth(wearer.getHealth() + amount);
opponent.setHealth(opponent.getHealth() - amount);
if (opponent == null) {
return;
}
double opponentHealth = opponent.getHealth() - amount;
double wearerHealth = wearer.getHealth() + amount;
if (opponentHealth <= 0) {
opponent.setHealth(0);
} else if (opponentHealth > opponent.getMaxHealth()) {
opponent.setHealth(opponent.getMaxHealth());
} else {
opponent.setHealth(opponentHealth);
}
if (wearerHealth <= 0) {
wearer.setHealth(0);
} else if (wearerHealth > wearer.getMaxHealth()) {
wearer.setHealth(wearer.getMaxHealth());
} else {
wearer.setHealth(wearerHealth);
}
}
}

View File

@ -1,6 +1,6 @@
package com.songoda.epicenchants.enums;
public enum EffectType {
public enum TriggerType {
ATTACK_PLAYER_MELEE,
ATTACK_PLAYER_RANGE,

View File

@ -3,11 +3,8 @@ package com.songoda.epicenchants.listeners;
import com.songoda.epicenchants.events.ArmorEquipEvent;
import com.songoda.epicenchants.events.ArmorEquipEvent.ArmorType;
import com.songoda.epicenchants.events.ArmorEquipEvent.EquipMethod;
import com.songoda.epicenchants.utils.VersionDependent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Result;
import org.bukkit.event.EventHandler;
@ -20,30 +17,49 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemBreakEvent;
import org.bukkit.inventory.ItemStack;
import static org.bukkit.event.EventPriority.HIGHEST;
public class ArmorListener implements Listener {
@EventHandler
@EventHandler(ignoreCancelled = true)
public final void onInventoryClick(final InventoryClickEvent e) {
boolean shift = false, numberkey = false;
if (e.isCancelled()) return;
if (e.getAction() == InventoryAction.NOTHING) return;// Why does this get called if nothing happens??
boolean shift = false, numberKey = false;
if (e.getAction() == InventoryAction.NOTHING) {
return;
}
if (!(e.getWhoClicked() instanceof Player)) {
return;
}
if (e.getSlotType() != SlotType.ARMOR && e.getSlotType() != SlotType.QUICKBAR && e.getSlotType() != SlotType.CONTAINER) {
return;
}
if (e.getClickedInventory() != null && !e.getClickedInventory().getType().equals(InventoryType.PLAYER)) {
return;
}
if (!e.getInventory().getType().equals(InventoryType.CRAFTING) && !e.getInventory().getType().equals(InventoryType.PLAYER)) {
return;
}
if (e.getClick().equals(ClickType.SHIFT_LEFT) || e.getClick().equals(ClickType.SHIFT_RIGHT)) {
shift = true;
}
if (e.getClick().equals(ClickType.NUMBER_KEY)) {
numberkey = true;
numberKey = true;
}
if (e.getSlotType() != SlotType.ARMOR && e.getSlotType() != SlotType.QUICKBAR && e.getSlotType() != SlotType.CONTAINER)
return;
if (e.getClickedInventory() != null && !e.getClickedInventory().getType().equals(InventoryType.PLAYER)) return;
if (!e.getInventory().getType().equals(InventoryType.CRAFTING) && !e.getInventory().getType().equals(InventoryType.PLAYER))
return;
if (!(e.getWhoClicked() instanceof Player)) return;
ArmorType newArmorType = ArmorType.matchType(shift ? e.getCurrentItem() : e.getCursor());
if (!shift && newArmorType != null && e.getRawSlot() != newArmorType.getSlot()) {
// Used for drag and drop checking to make sure you aren't trying to place a helmet in the boots slot.
return;
}
if (shift) {
newArmorType = ArmorType.matchType(e.getCurrentItem());
if (newArmorType != null) {
@ -62,7 +78,7 @@ public class ArmorListener implements Listener {
} else {
ItemStack newArmorPiece = e.getCursor();
ItemStack oldArmorPiece = e.getCurrentItem();
if (numberkey) {
if (numberKey) {
if (e.getClickedInventory().getType().equals(InventoryType.PLAYER)) {// Prevents shit in the 2by2 crafting
// e.getClickedInventory() == The players inventory
// e.getHotBarButton() == key people are pressing to equip or unequip the item to or from.
@ -87,7 +103,7 @@ public class ArmorListener implements Listener {
}
if (newArmorType != null && e.getRawSlot() == newArmorType.getSlot()) {
EquipMethod method = EquipMethod.PICK_DROP;
if (e.getAction().equals(InventoryAction.HOTBAR_SWAP) || numberkey) method = EquipMethod.HOTBAR_SWAP;
if (e.getAction().equals(InventoryAction.HOTBAR_SWAP) || numberKey) method = EquipMethod.HOTBAR_SWAP;
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent((Player) e.getWhoClicked(), method, newArmorType, oldArmorPiece, newArmorPiece);
Bukkit.getServer().getPluginManager().callEvent(armorEquipEvent);
if (armorEquipEvent.isCancelled()) {
@ -97,7 +113,7 @@ public class ArmorListener implements Listener {
}
}
@EventHandler
@EventHandler(priority = HIGHEST)
public void playerInteractEvent(PlayerInteractEvent e) {
if (e.getAction() == Action.PHYSICAL) {
return;
@ -106,10 +122,11 @@ public class ArmorListener implements Listener {
final Player player = e.getPlayer();
if (e.getClickedBlock() != null && e.getAction() == Action.RIGHT_CLICK_BLOCK) {// Having both of these checks is useless, might as well do it though.
// Some blocks have actions when you right click them which stops the client from equipping the armor in hand.
if (VersionDependent.getBlackList().stream().anyMatch(type -> e.getClickedBlock().getType().equals(type))) {
/*if (VersionDependent.getBlackList().stream().anyMatch(type -> e.getClickedBlock().getType().equals(type))) {
return;
}
}*/
}
ArmorType newArmorType = ArmorType.matchType(e.getItem());
if (newArmorType != null) {
if (newArmorType.equals(ArmorType.HELMET) && isAirOrNull(e.getPlayer().getInventory().getHelmet()) || newArmorType.equals(ArmorType.CHESTPLATE) && isAirOrNull(e.getPlayer().getInventory().getChestplate()) || newArmorType.equals(ArmorType.LEGGINGS) && isAirOrNull(e.getPlayer().getInventory().getLeggings()) || newArmorType.equals(ArmorType.BOOTS) && isAirOrNull(e.getPlayer().getInventory().getBoots())) {
@ -126,12 +143,12 @@ public class ArmorListener implements Listener {
@EventHandler
public void inventoryDrag(InventoryDragEvent event) {
// getType() seems to always be even.
// Old Cursor gives the item you are equipping
// Raw slot is the ArmorType slot
// Can't replace armor using this method making getCursor() useless.
if (event.getRawSlots().isEmpty()) {
return;
}
ArmorType type = ArmorType.matchType(event.getOldCursor());
if (event.getRawSlots().isEmpty()) return;// Idk if this will ever happen
if (type != null && type.getSlot() == event.getRawSlots().stream().findFirst().orElse(0)) {
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent((Player) event.getWhoClicked(), EquipMethod.DRAG, type, null, event.getOldCursor());
Bukkit.getServer().getPluginManager().callEvent(armorEquipEvent);
@ -153,35 +170,34 @@ public class ArmorListener implements Listener {
ItemStack i = e.getBrokenItem().clone();
i.setAmount(1);
i.setDurability((short) (i.getDurability() - 1));
if (type.equals(ArmorType.HELMET)) {
p.getInventory().setHelmet(i);
} else if (type.equals(ArmorType.CHESTPLATE)) {
p.getInventory().setChestplate(i);
} else if (type.equals(ArmorType.LEGGINGS)) {
p.getInventory().setLeggings(i);
} else if (type.equals(ArmorType.BOOTS)) {
p.getInventory().setBoots(i);
switch (type) {
case HELMET:
p.getInventory().setHelmet(i);
break;
case CHESTPLATE:
p.getInventory().setChestplate(i);
break;
case LEGGINGS:
p.getInventory().setLeggings(i);
break;
case BOOTS:
p.getInventory().setBoots(i);
break;
}
}
}
}
@EventHandler
public void playerDeathEvent(PlayerDeathEvent e) {
Player p = e.getEntity();
for (ItemStack i : p.getInventory().getArmorContents()) {
public void playerDeathEvent(PlayerDeathEvent event) {
for (ItemStack i : event.getEntity().getInventory().getArmorContents()) {
if (!isAirOrNull(i)) {
Bukkit.getServer().getPluginManager().callEvent(new ArmorEquipEvent(p, EquipMethod.DEATH, ArmorType.matchType(i), i, null));
Bukkit.getServer().getPluginManager().callEvent(new ArmorEquipEvent(event.getEntity(), EquipMethod.DEATH, ArmorType.matchType(i), i, null));
// No way to cancel a death event.
}
}
}
private Location shift(Location start, BlockFace direction, int multiplier) {
if (multiplier == 0) return start;
return new Location(start.getWorld(), start.getX() + direction.getModX() * multiplier, start.getY() + direction.getModY() * multiplier, start.getZ() + direction.getModZ() * multiplier);
}
/**
* A utility method to support versions that use null or air ItemStacks.
*/

View File

@ -7,6 +7,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.jetbrains.annotations.Nullable;
public class BlackScrollListener {
private final EpicEnchants instance;
@ -21,9 +22,13 @@ public class BlackScrollListener {
return;
}
NBTItem nbtItem = new NBTItem(event.getCursor());
@Nullable NBTItem nbtItem = new NBTItem(event.getCursor());
NBTItem toApplyTo = new NBTItem(event.getCurrentItem());
if (nbtItem == null) {
return;
}
if (!nbtItem.getBoolean("black-scroll")) {
return;
}

View File

@ -1,16 +1,22 @@
package com.songoda.epicenchants.listeners;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.enums.EffectType;
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;
import org.bukkit.event.entity.*;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
import org.bukkit.projectiles.ProjectileSource;
import static com.songoda.epicenchants.enums.EffectType.*;
import static com.songoda.epicenchants.enums.TriggerType.*;
public class EntityListener implements Listener {
private final EpicEnchants instance;
@ -40,12 +46,12 @@ public class EntityListener implements Listener {
if (hitEntity instanceof Player) {
LivingEntity opponent = source instanceof LivingEntity ? ((LivingEntity) source) : null;
EffectType type = source instanceof Player ? DEFENSE_PLAYER_RANGE : DEFENSE_MOB_RANGE;
TriggerType type = source instanceof Player ? DEFENSE_PLAYER_RANGE : DEFENSE_MOB_RANGE;
instance.getEnchantUtils().handlePlayer(((Player) hitEntity), opponent, event, type);
}
if (source instanceof Player) {
EffectType type = event.getEntity() instanceof Player ? ATTACK_PLAYER_RANGE : ATTACK_MOB_RANGE;
TriggerType type = event.getEntity() instanceof Player ? ATTACK_PLAYER_RANGE : ATTACK_MOB_RANGE;
instance.getEnchantUtils().handlePlayer(((Player) source), hitEntity, event, type);
}
}
@ -54,35 +60,35 @@ public class EntityListener implements Listener {
//Player got hit
if (event.getEntity() instanceof Player) {
Player defender = (Player) event.getEntity();
EffectType effectType = null;
TriggerType triggerType = null;
LivingEntity opponent = null;
if (event.getDamager() instanceof Player) {
opponent = ((LivingEntity) event.getDamager());
effectType = DEFENSE_PLAYER_MELEE;
triggerType = DEFENSE_PLAYER_MELEE;
} else if (event.getDamager() instanceof LivingEntity && !(event.getDamager() instanceof Player)) {
opponent = ((LivingEntity) event.getDamager());
effectType = DEFENSE_MOB_MELEE;
triggerType = DEFENSE_MOB_MELEE;
}
if (effectType != null) {
instance.getEnchantUtils().handlePlayer(defender, opponent, event, effectType);
if (triggerType != null) {
instance.getEnchantUtils().handlePlayer(defender, opponent, event, triggerType);
}
}
//Player damaged an entity
if (event.getDamager() instanceof Player) {
Player attacker = (Player) event.getDamager();
EffectType effectType = null;
TriggerType triggerType = null;
if (event.getEntity() instanceof Player) {
effectType = ATTACK_PLAYER_MELEE;
triggerType = ATTACK_PLAYER_MELEE;
} else if (event.getEntity() instanceof LivingEntity) {
effectType = ATTACK_MOB_MELEE;
triggerType = ATTACK_MOB_MELEE;
}
if (effectType != null) {
instance.getEnchantUtils().handlePlayer(attacker, ((LivingEntity) event.getEntity()), event, effectType);
if (triggerType != null) {
instance.getEnchantUtils().handlePlayer(attacker, ((LivingEntity) event.getEntity()), event, triggerType);
}
}
}

View File

@ -16,9 +16,9 @@ import org.bukkit.event.player.PlayerJoinEvent;
import java.util.Arrays;
import java.util.Map;
import static com.songoda.epicenchants.enums.EffectType.*;
import static com.songoda.epicenchants.enums.EventType.OFF;
import static com.songoda.epicenchants.enums.EventType.ON;
import static com.songoda.epicenchants.enums.TriggerType.*;
public class PlayerListener implements Listener {
private final EpicEnchants instance;

View File

@ -25,6 +25,10 @@ public class WhiteScrollListener implements Listener {
NBTItem nbtItem = new NBTItem(event.getCursor());
NBTItem toApplyTo = new NBTItem(event.getCurrentItem());
if (nbtItem == null) {
return;
}
if (!nbtItem.getBoolean("white-scroll")) {
return;
}

View File

@ -1,8 +1,8 @@
package com.songoda.epicenchants.objects;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EffectType;
import com.songoda.epicenchants.enums.EventType;
import com.songoda.epicenchants.enums.TriggerType;
import com.songoda.epicenchants.wrappers.MobWrapper;
import lombok.Builder;
import lombok.Getter;
@ -30,9 +30,9 @@ public class Enchant {
@Nullable private BookItem bookItem;
private LeveledModifier modifyDamage;
public void onAction(@NotNull Player wearer, @Nullable LivingEntity opponent, Event event, int level, EffectType effectType, EventType eventType) {
effectExecutors.forEach(effect -> effect.testAndRun(wearer, opponent, level, effectType, event, eventType));
mobs.forEach(mobWrapper -> mobWrapper.trySpawn(wearer, opponent, level, effectType));
public void onAction(@NotNull Player wearer, @Nullable LivingEntity opponent, Event event, int level, TriggerType triggerType, EventType eventType) {
effectExecutors.forEach(effect -> effect.testAndRun(wearer, opponent, level, triggerType, event, eventType));
mobs.forEach(mobWrapper -> mobWrapper.trySpawn(wearer, opponent, level, triggerType));
}
public BookItem getBookItem() {

View File

@ -2,7 +2,7 @@ package com.songoda.epicenchants.utils;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.effect.EffectManager;
import com.songoda.epicenchants.enums.EffectType;
import com.songoda.epicenchants.enums.TriggerType;
import com.songoda.epicenchants.objects.BookItem;
import com.songoda.epicenchants.objects.Enchant;
import com.songoda.epicenchants.objects.Group;
@ -49,7 +49,7 @@ public class ConfigParser {
public static MobWrapper parseMobWrapper(ConfigurationSection section) {
return section != null ? MobWrapper.builder()
.effectType(EffectType.valueOf(section.getString("effect-type")))
.triggerType(TriggerType.valueOf(section.getString("trigger")))
.entityType(EntityType.valueOf(section.getName()))
.maxAmount(LeveledModifier.of(section.getString("max-amount")))
.spawnPercentage(LeveledModifier.of(section.getString("spawn-percentage")))

View File

@ -1,9 +1,9 @@
package com.songoda.epicenchants.utils;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.enums.EffectType;
import com.songoda.epicenchants.enums.EnchantResult;
import com.songoda.epicenchants.enums.EventType;
import com.songoda.epicenchants.enums.TriggerType;
import com.songoda.epicenchants.objects.Enchant;
import de.tr7zw.itemnbtapi.NBTCompound;
import de.tr7zw.itemnbtapi.NBTItem;
@ -19,8 +19,8 @@ import javax.annotation.Nullable;
import java.util.*;
import java.util.stream.Collectors;
import static com.songoda.epicenchants.enums.EffectType.HELD_ITEM;
import static com.songoda.epicenchants.enums.EnchantResult.*;
import static com.songoda.epicenchants.enums.TriggerType.HELD_ITEM;
public class EnchantUtils {
@ -78,17 +78,17 @@ public class EnchantUtils {
.collect(Collectors.toMap(key -> instance.getEnchantManager().getEnchantUnsafe(key), compound::getInteger));
}
public void handlePlayer(@NotNull Player player, @Nullable LivingEntity opponent, Event event, EffectType effectType) {
public void handlePlayer(@NotNull Player player, @Nullable LivingEntity opponent, Event event, TriggerType triggerType) {
List<ItemStack> stacks = new ArrayList<>(Arrays.asList(player.getInventory().getArmorContents()));
stacks.add(player.getItemInHand());
stacks.removeIf(Objects::isNull);
if (effectType == HELD_ITEM) {
if (triggerType == HELD_ITEM) {
stacks = Collections.singletonList(player.getItemInHand());
}
stacks.stream().map(this::getEnchants).forEach(list -> list.forEach((enchant, level) -> {
enchant.onAction(player, opponent, event, level, effectType, EventType.NONE);
enchant.onAction(player, opponent, event, level, triggerType, EventType.NONE);
}));
}
}

View File

@ -1,176 +0,0 @@
package com.songoda.epicenchants.utils;
import org.bukkit.Material;
import java.util.HashSet;
import java.util.Set;
import static org.bukkit.Material.valueOf;
public class VersionDependent {
private static Set<Material> blacklist;
private static int version;
public static void initLegacy(int serverVersion) {
version = serverVersion;
blacklist = new HashSet<Material>() {
{
add(valueOf("FURNACE"));
add(valueOf("CHEST"));
add(valueOf("TRAPPED_CHEST"));
add(valueOf("BEACON"));
add(valueOf("DISPENSER"));
add(valueOf("DROPPER"));
add(valueOf("HOPPER"));
add(valueOf("WORKBENCH"));
add(valueOf("ENCHANTMENT_TABLE"));
add(valueOf("ENDER_CHEST"));
add(valueOf("ANVIL"));
add(valueOf("BED_BLOCK"));
add(valueOf("FENCE_GATE"));
add(valueOf("SPRUCE_FENCE_GATE"));
add(valueOf("BIRCH_FENCE_GATE"));
add(valueOf("ACACIA_FENCE_GATE"));
add(valueOf("JUNGLE_FENCE_GATE"));
add(valueOf("DARK_OAK_FENCE_GATE"));
add(valueOf("IRON_DOOR_BLOCK"));
add(valueOf("WOODEN_DOOR"));
add(valueOf("SPRUCE_DOOR"));
add(valueOf("BIRCH_DOOR"));
add(valueOf("JUNGLE_DOOR"));
add(valueOf("ACACIA_DOOR"));
add(valueOf("DARK_OAK_DOOR"));
add(valueOf("WOOD_BUTTON"));
add(valueOf("STONE_BUTTON"));
add(valueOf("TRAP_DOOR"));
add(valueOf("IRON_TRAPDOOR"));
add(valueOf("DIODE_BLOCK_OFF"));
add(valueOf("DIODE_BLOCK_ON"));
add(valueOf("REDSTONE_COMPARATOR_OFF"));
add(valueOf("REDSTONE_COMPARATOR_ON"));
add(valueOf("FENCE"));
add(valueOf("SPRUCE_FENCE"));
add(valueOf("BIRCH_FENCE"));
add(valueOf("JUNGLE_FENCE"));
add(valueOf("DARK_OAK_FENCE"));
add(valueOf("ACACIA_FENCE"));
add(valueOf("NETHER_FENCE"));
add(valueOf("BREWING_STAND"));
add(valueOf("CAULDRON"));
add(valueOf("SIGN_POST"));
add(valueOf("WALL_SIGN"));
add(valueOf("SIGN"));
add(valueOf("LEVER"));
add(valueOf("DAYLIGHT_DETECTOR_INVERTED"));
add(valueOf("DAYLIGHT_DETECTOR"));
}
};
}
/*public static void initDefault(int serverVersion) {
version = serverVersion;
blacklist = new HashSet<Material>() {
{
add(valueOf("FURNACE"));
add(valueOf("CHEST"));
add(valueOf("TRAPPED_CHEST"));
add(valueOf("BEACON"));
add(valueOf("DISPENSER"));
add(valueOf("DROPPER"));
add(valueOf("HOPPER"));
add(valueOf("CRAFTING_TABLE"));
add(valueOf("ENCHANTING_TABLE"));
add(valueOf("BLACK_BED"));
add(valueOf("BLUE_BED"));
add(valueOf("BROWN_BED"));
add(valueOf("CYAN_BED"));
add(valueOf("GRAY_BED"));
add(valueOf("GREEN_BED"));
add(valueOf("LIGHT_BLUE_BED"));
add(valueOf("LIGHT_GRAY_BED"));
add(valueOf("LIME_BED"));
add(valueOf("MAGENTA_BED"));
add(valueOf("ORANGE_BED"));
add(valueOf("PINK_BED"));
add(valueOf("PURPLE_BED"));
add(valueOf("RED_BED"));
add(valueOf("WHITE_BED"));
add(valueOf("YELLOW_BED"));
add(valueOf("ENDER_CHEST"));
add(valueOf("ANVIL"));
add(valueOf("ACACIA_FENCE_GATE"));
add(valueOf("BIRCH_FENCE_GATE"));
add(valueOf("DARK_OAK_FENCE_GATE"));
add(valueOf("JUNGLE_FENCE_GATE"));
add(valueOf("OAK_FENCE_GATE"));
add(valueOf("SPRUCE_FENCE_GATE"));
add(valueOf("IRON_DOOR"));
add(valueOf("ACACIA_DOOR"));
add(valueOf("BIRCH_DOOR"));
add(valueOf("DARK_OAK_DOOR"));
add(valueOf("JUNGLE_DOOR"));
add(valueOf("OAK_DOOR"));
add(valueOf("SPRUCE_DOOR"));
add(valueOf("ACACIA_TRAPDOOR"));
add(valueOf("BIRCH_TRAPDOOR"));
add(valueOf("DARK_OAK_TRAPDOOR"));
add(valueOf("JUNGLE_TRAPDOOR"));
add(valueOf("OAK_TRAPDOOR"));
add(valueOf("SPRUCE_TRAPDOOR"));
add(valueOf("ACACIA_BUTTON"));
add(valueOf("BIRCH_BUTTON"));
add(valueOf("DARK_OAK_BUTTON"));
add(valueOf("JUNGLE_BUTTON"));
add(valueOf("OAK_BUTTON"));
add(valueOf("SPRUCE_BUTTON"));
add(valueOf("ACACIA_FENCE"));
add(valueOf("BIRCH_FENCE"));
add(valueOf("DARK_OAK_FENCE"));
add(valueOf("JUNGLE_FENCE"));
add(valueOf("OAK_FENCE"));
add(valueOf("SPRUCE_FENCE"));
add(valueOf("REPEATER"));
add(valueOf("COMPARATOR"));
add(valueOf("BREWING_STAND"));
add(valueOf("CAULDRON"));
add(valueOf("WALL_SIGN"));
add(valueOf("SIGN"));
add(valueOf("LEVER"));
add(valueOf("DAYLIGHT_DETECTOR"));
add(valueOf("SHULKER_BOX"));
add(valueOf("BLACK_SHULKER_BOX"));
add(valueOf("BLUE_SHULKER_BOX"));
add(valueOf("BROWN_SHULKER_BOX"));
add(valueOf("CYAN_SHULKER_BOX"));
add(valueOf("GRAY_SHULKER_BOX"));
add(valueOf("GREEN_SHULKER_BOX"));
add(valueOf("LIGHT_BLUE_SHULKER_BOX"));
add(valueOf("LIGHT_GRAY_SHULKER_BOX"));
add(valueOf("LIME_SHULKER_BOX"));
add(valueOf("MAGENTA_SHULKER_BOX"));
add(valueOf("ORANGE_SHULKER_BOX"));
add(valueOf("PINK_SHULKER_BOX"));
add(valueOf("PURPLE_SHULKER_BOX"));
add(valueOf("RED_SHULKER_BOX"));
add(valueOf("WHITE_SHULKER_BOX"));
add(valueOf("YELLOW_SHULKER_BOX"));
}
};
}*/
public static Set<Material> getBlackList() {
return blacklist;
}
}

View File

@ -1,6 +1,6 @@
package com.songoda.epicenchants.wrappers;
import com.songoda.epicenchants.enums.EffectType;
import com.songoda.epicenchants.enums.TriggerType;
import com.songoda.epicenchants.objects.LeveledModifier;
import com.songoda.epicenchants.utils.GeneralUtils;
import com.songoda.epicenchants.utils.ItemBuilder;
@ -21,7 +21,7 @@ public class MobWrapper {
private String displayName;
private EntityType entityType;
private LeveledModifier attackDamage;
private EffectType effectType;
private TriggerType triggerType;
private LeveledModifier equipmentDropChance;
private LeveledModifier spawnPercentage;
private LeveledModifier health;
@ -29,8 +29,8 @@ public class MobWrapper {
private boolean hostile;
private LeveledModifier maxAmount;
public void trySpawn(@NotNull Player player, @Nullable LivingEntity opponent, int level, EffectType effectType) {
if (this.effectType != effectType) {
public void trySpawn(@NotNull Player player, @Nullable LivingEntity opponent, int level, TriggerType triggerType) {
if (this.triggerType != triggerType) {
return;
}

View File

@ -34,8 +34,8 @@ conflicting-enchants:
effects:
# The "-1" is added because every effect key has to be unique.
POTION-1:
# The Effect Type
type: DEFENSE_PLAYER_MELEE
# The trigger that will fire this effect
trigger: DEFENSE_PLAYER_MELEE
# What player should the effect be ran on: WEARER/OPPONENT.
who: WEARER
# Potion Effect that should be applied.
@ -47,7 +47,7 @@ effects:
# Amplifier of 0 = SPEED 1 a Amplifier of 1 = SPEED 2, etc.
amplifier: "{level} - 1"
POTION-2:
type: STATIC_EFFECT
trigger: STATIC_EFFECT
who: WEARER
potion-type: INCREASE_DAMAGE
amplifier: "{level} - 1"
@ -57,7 +57,7 @@ mobs:
# Type of Mob
ZOMBIE:
# Trigger event that spawns the mob.
effect-type: DEFENSE_PLAYER_MELEE
trigger: DEFENSE_PLAYER_MELEE
# Max amount mobs that will be spawned.
max-amount: "{level}"
# Chance of trigger the mob spawning.

View File

@ -3,4 +3,5 @@ version: ${project.version}
main: com.songoda.epicenchants.EpicEnchants
authors: [GB6]
website: https://songoda.com/
depend: [Vault]
depend: [Vault]
api-version: 1.13

View File

@ -7,7 +7,7 @@
<groupId>com.songoda</groupId>
<artifactId>EpicEnchants-Parent</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<version>1.0.1-ALPHA</version>
<modules>
<module>core</module>
</modules>