Began refactor
This commit is contained in:
@@ -16,7 +16,7 @@ import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public abstract class AbstractConfig extends AbstractUndefinedConfig {
|
||||
public abstract class AbstractConfig extends ConfigWrapper {
|
||||
/**
|
||||
* The physical config file, as stored on disk.
|
||||
*/
|
||||
|
||||
@@ -17,7 +17,7 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@SuppressWarnings({"unchecked", "unused"})
|
||||
public abstract class AbstractUndefinedConfig extends PluginDependent {
|
||||
public abstract class ConfigWrapper extends PluginDependent {
|
||||
/**
|
||||
* The linked {@link YamlConfiguration} where values are physically stored.
|
||||
*/
|
||||
@@ -35,8 +35,8 @@ public abstract class AbstractUndefinedConfig extends PluginDependent {
|
||||
* @param configName The name of the config
|
||||
* @param plugin The plugin.
|
||||
*/
|
||||
protected AbstractUndefinedConfig(@NotNull final String configName,
|
||||
@NotNull final AbstractEcoPlugin plugin) {
|
||||
protected ConfigWrapper(@NotNull final String configName,
|
||||
@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.willfp.eco.internal.drops.impl;
|
||||
|
||||
import com.willfp.eco.internal.drops.AbstractDropQueue;
|
||||
import com.willfp.eco.util.drops.telekinesis.TelekinesisUtils;
|
||||
import com.willfp.eco.util.TelekinesisUtils;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.willfp.eco.internal.extensions;
|
||||
|
||||
import com.willfp.eco.util.extensions.Extension;
|
||||
import com.willfp.eco.util.extensions.MalformedExtensionException;
|
||||
import com.willfp.eco.util.extensions.loader.ExtensionLoader;
|
||||
import com.willfp.eco.util.extensions.ExtensionLoader;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.apache.commons.lang.Validate;
|
||||
@@ -99,7 +99,7 @@ public class EcoExtensionLoader extends PluginDependent implements ExtensionLoad
|
||||
Validate.notNull(name, "Name is missing!");
|
||||
Validate.notNull(version, "Version is missing!");
|
||||
|
||||
Extension.ExtensionMetadata metadata = new Extension.ExtensionMetadata(version, name);
|
||||
ExtensionMetadata metadata = new ExtensionMetadata(version, name);
|
||||
|
||||
Class<?> cls;
|
||||
Object object = null;
|
||||
@@ -129,15 +129,6 @@ public class EcoExtensionLoader extends PluginDependent implements ExtensionLoad
|
||||
extensions.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unloads, then loads all extensions.
|
||||
*/
|
||||
@Override
|
||||
public void reloadExtensions() {
|
||||
unloadExtensions();
|
||||
loadExtensions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all loaded extensions.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.willfp.eco.internal.extensions;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ExtensionMetadata {
|
||||
/**
|
||||
* The version of the extension.
|
||||
*/
|
||||
@NotNull
|
||||
@Getter
|
||||
private final String version;
|
||||
|
||||
/**
|
||||
* The extension's name.
|
||||
*/
|
||||
@NotNull
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Create a new extension metadata.
|
||||
*
|
||||
* @param version The version for the extension to be.
|
||||
* @param name The name of the extension.
|
||||
*/
|
||||
public ExtensionMetadata(@NotNull final String version,
|
||||
@NotNull final String name) {
|
||||
this.version = version;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.drops.telekinesis;
|
||||
package com.willfp.eco.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.willfp.eco.util.config;
|
||||
|
||||
import com.willfp.eco.internal.config.AbstractUndefinedConfig;
|
||||
import com.willfp.eco.internal.config.ConfigWrapper;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class StaticOptionalConfig extends AbstractUndefinedConfig {
|
||||
public abstract class StaticOptionalConfig extends ConfigWrapper {
|
||||
/**
|
||||
* Config implementation for passing YamlConfigurations.
|
||||
* <p>
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.willfp.eco.util.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
public class ArmorEquipEvent extends PlayerEvent {
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
public ArmorEquipEvent(@NotNull final Player player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of handlers handling this event.
|
||||
*
|
||||
* @return A list of handlers handling this event.
|
||||
*/
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.events.entitydeathbyentity;
|
||||
package com.willfp.eco.util.events;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.events.naturalexpgainevent;
|
||||
package com.willfp.eco.util.events;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.event.Event;
|
||||
@@ -1,127 +0,0 @@
|
||||
package com.willfp.eco.util.events.armorequip;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Arnah
|
||||
* @since Jul 30, 2015
|
||||
*/
|
||||
public class ArmorEquipEvent extends PlayerEvent implements Cancellable {
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
private boolean cancel = false;
|
||||
private final EquipMethod equipType;
|
||||
private final ArmorType type;
|
||||
private ItemStack oldArmorPiece;
|
||||
private ItemStack newArmorPiece;
|
||||
|
||||
public ArmorEquipEvent(@NotNull final Player player,
|
||||
@Nullable final EquipMethod equipType,
|
||||
@Nullable final ArmorType type,
|
||||
@Nullable final ItemStack oldArmorPiece,
|
||||
@Nullable final ItemStack newArmorPiece) {
|
||||
super(player);
|
||||
this.equipType = equipType;
|
||||
this.type = type;
|
||||
this.oldArmorPiece = oldArmorPiece;
|
||||
this.newArmorPiece = newArmorPiece;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of handlers handling this event.
|
||||
*
|
||||
* @return A list of handlers handling this event.
|
||||
*/
|
||||
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if this event should be cancelled.
|
||||
*
|
||||
* @param cancel If this event should be cancelled.
|
||||
*/
|
||||
public final void setCancelled(final boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if this event is cancelled.
|
||||
*
|
||||
* @return If this event is cancelled
|
||||
*/
|
||||
public final boolean isCancelled() {
|
||||
return cancel;
|
||||
}
|
||||
|
||||
public final ArmorType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public final ItemStack getOldArmorPiece() {
|
||||
return oldArmorPiece;
|
||||
}
|
||||
|
||||
public final void setOldArmorPiece(final ItemStack oldArmorPiece) {
|
||||
this.oldArmorPiece = oldArmorPiece;
|
||||
}
|
||||
|
||||
public final ItemStack getNewArmorPiece() {
|
||||
return newArmorPiece;
|
||||
}
|
||||
|
||||
public final void setNewArmorPiece(final ItemStack newArmorPiece) {
|
||||
this.newArmorPiece = newArmorPiece;
|
||||
}
|
||||
|
||||
public EquipMethod getMethod() {
|
||||
return equipType;
|
||||
}
|
||||
|
||||
public enum EquipMethod {
|
||||
/**
|
||||
* When you shift click an armor piece to equip or unequip
|
||||
*/
|
||||
SHIFT_CLICK,
|
||||
/**
|
||||
* When you drag and drop the item to equip or unequip
|
||||
*/
|
||||
DRAG,
|
||||
/**
|
||||
* When you manually equip or unequip the item. Use to be DRAG
|
||||
*/
|
||||
PICK_DROP,
|
||||
/**
|
||||
* When you right click an armor piece in the hotbar without the inventory open to equip.
|
||||
*/
|
||||
HOTBAR,
|
||||
/**
|
||||
* When you press the hotbar slot number while hovering over the armor slot to equip or unequip
|
||||
*/
|
||||
HOTBAR_SWAP,
|
||||
/**
|
||||
* When in range of a dispenser that shoots an armor piece to equip.<br>
|
||||
* Requires the spigot version to have {@link org.bukkit.event.block.BlockDispenseArmorEvent} implemented.
|
||||
*/
|
||||
DISPENSER,
|
||||
/**
|
||||
* When an armor piece is removed due to it losing all durability.
|
||||
*/
|
||||
BROKE,
|
||||
/**
|
||||
* When you die causing all armor to unequip
|
||||
*/
|
||||
DEATH
|
||||
}
|
||||
}
|
||||
@@ -1,240 +0,0 @@
|
||||
package com.willfp.eco.util.events.armorequip;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Result;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.inventory.InventoryType.SlotType;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerItemBreakEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static com.willfp.eco.util.events.armorequip.ArmorEquipEvent.EquipMethod;
|
||||
|
||||
/**
|
||||
* @author Arnah
|
||||
* @since Jul 30, 2015
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ArmorListener implements Listener {
|
||||
//Event Priority is highest because other plugins might cancel the events before we check.
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public final void inventoryClick(@NotNull final InventoryClickEvent event) {
|
||||
boolean shift = false;
|
||||
boolean numberkey = false;
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
if (event.getAction() == InventoryAction.NOTHING) {
|
||||
return;
|
||||
}
|
||||
if (event.getClick().equals(ClickType.SHIFT_LEFT) || event.getClick().equals(ClickType.SHIFT_RIGHT)) {
|
||||
shift = true;
|
||||
}
|
||||
if (event.getClick().equals(ClickType.NUMBER_KEY)) {
|
||||
numberkey = true;
|
||||
}
|
||||
if (event.getSlotType() != SlotType.ARMOR && event.getSlotType() != SlotType.QUICKBAR && event.getSlotType() != SlotType.CONTAINER) {
|
||||
return;
|
||||
}
|
||||
if (event.getClickedInventory() != null && !event.getClickedInventory().getType().equals(InventoryType.PLAYER)) {
|
||||
return;
|
||||
}
|
||||
if (!event.getInventory().getType().equals(InventoryType.CRAFTING) && !event.getInventory().getType().equals(InventoryType.PLAYER)) {
|
||||
return;
|
||||
}
|
||||
if (!(event.getWhoClicked() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
ArmorType newArmorType = ArmorType.matchType(shift ? event.getCurrentItem() : event.getCursor());
|
||||
if (!shift && newArmorType != null && event.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(event.getCurrentItem());
|
||||
if (newArmorType != null) {
|
||||
boolean equipping = true;
|
||||
if (event.getRawSlot() == newArmorType.getSlot()) {
|
||||
equipping = false;
|
||||
}
|
||||
if (newArmorType.equals(ArmorType.HELMET)
|
||||
&& (equipping == isAirOrNull(event.getWhoClicked().getInventory().getHelmet()))
|
||||
|| newArmorType.equals(ArmorType.CHESTPLATE)
|
||||
&& (equipping == isAirOrNull(event.getWhoClicked().getInventory().getChestplate()))
|
||||
|| newArmorType.equals(ArmorType.LEGGINGS)
|
||||
&& (equipping == isAirOrNull(event.getWhoClicked().getInventory().getLeggings()))
|
||||
|| newArmorType.equals(ArmorType.BOOTS)
|
||||
&& (equipping == isAirOrNull(event.getWhoClicked().getInventory().getBoots()))) {
|
||||
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent(
|
||||
(Player) event.getWhoClicked(),
|
||||
EquipMethod.SHIFT_CLICK,
|
||||
newArmorType,
|
||||
equipping ? null : event.getCurrentItem(),
|
||||
equipping ? event.getCurrentItem() : null
|
||||
);
|
||||
Bukkit.getPluginManager().callEvent(armorEquipEvent);
|
||||
if (armorEquipEvent.isCancelled()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ItemStack newArmorPiece = event.getCursor();
|
||||
ItemStack oldArmorPiece = event.getCurrentItem();
|
||||
if (numberkey) {
|
||||
if (event.getClickedInventory().getType().equals(InventoryType.PLAYER)) {
|
||||
ItemStack hotbarItem = event.getClickedInventory().getItem(event.getHotbarButton());
|
||||
if (!isAirOrNull(hotbarItem)) {
|
||||
newArmorType = ArmorType.matchType(hotbarItem);
|
||||
newArmorPiece = hotbarItem;
|
||||
oldArmorPiece = event.getClickedInventory().getItem(event.getSlot());
|
||||
} else {
|
||||
newArmorType = ArmorType.matchType(!isAirOrNull(event.getCurrentItem()) ? event.getCurrentItem() : event.getCursor());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (isAirOrNull(event.getCursor()) && !isAirOrNull(event.getCurrentItem())) {
|
||||
newArmorType = ArmorType.matchType(event.getCurrentItem());
|
||||
}
|
||||
}
|
||||
if (newArmorType != null && event.getRawSlot() == newArmorType.getSlot()) {
|
||||
ArmorEquipEvent.EquipMethod method = ArmorEquipEvent.EquipMethod.PICK_DROP;
|
||||
if (event.getAction().equals(InventoryAction.HOTBAR_SWAP) || numberkey) {
|
||||
method = ArmorEquipEvent.EquipMethod.HOTBAR_SWAP;
|
||||
}
|
||||
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent((Player) event.getWhoClicked(), method, newArmorType, oldArmorPiece, newArmorPiece);
|
||||
Bukkit.getPluginManager().callEvent(armorEquipEvent);
|
||||
if (armorEquipEvent.isCancelled()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void playerInteractEvent(@NotNull final PlayerInteractEvent e) {
|
||||
if (e.useItemInHand().equals(Result.DENY)) {
|
||||
return;
|
||||
}
|
||||
if (e.getAction() == Action.PHYSICAL) {
|
||||
return;
|
||||
}
|
||||
if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Player player = e.getPlayer();
|
||||
if (!e.useInteractedBlock().equals(Result.DENY)) {
|
||||
if (e.getClickedBlock() != null && e.getAction() == Action.RIGHT_CLICK_BLOCK && !player.isSneaking()) {
|
||||
Material mat = e.getClickedBlock().getType();
|
||||
}
|
||||
}
|
||||
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())) {
|
||||
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent(e.getPlayer(), ArmorEquipEvent.EquipMethod.HOTBAR, ArmorType.matchType(e.getItem()), null, e.getItem());
|
||||
Bukkit.getPluginManager().callEvent(armorEquipEvent);
|
||||
if (armorEquipEvent.isCancelled()) {
|
||||
e.setCancelled(true);
|
||||
player.updateInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void inventoryDrag(@NotNull final 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.
|
||||
ArmorType type = ArmorType.matchType(event.getOldCursor());
|
||||
if (event.getRawSlots().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
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.getPluginManager().callEvent(armorEquipEvent);
|
||||
if (armorEquipEvent.isCancelled()) {
|
||||
event.setResult(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
// Debug shit
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerJoinEvent(@NotNull final PlayerJoinEvent event) {
|
||||
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent(event.getPlayer(), null, null, null, null);
|
||||
Bukkit.getPluginManager().callEvent(armorEquipEvent);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerRespawnEvent(@NotNull final PlayerRespawnEvent event) {
|
||||
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent(event.getPlayer(), null, null, null, null);
|
||||
Bukkit.getPluginManager().callEvent(armorEquipEvent);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void itemBreakEvent(@NotNull final PlayerItemBreakEvent event) {
|
||||
ArmorType type = ArmorType.matchType(event.getBrokenItem());
|
||||
if (type != null) {
|
||||
Player p = event.getPlayer();
|
||||
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent(p, EquipMethod.BROKE, type, event.getBrokenItem(), null);
|
||||
Bukkit.getPluginManager().callEvent(armorEquipEvent);
|
||||
if (armorEquipEvent.isCancelled()) {
|
||||
ItemStack i = event.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerDeathEvent(@NotNull final PlayerDeathEvent event) {
|
||||
Player p = event.getEntity();
|
||||
if (event.getKeepInventory()) {
|
||||
return;
|
||||
}
|
||||
for (ItemStack i : p.getInventory().getArmorContents()) {
|
||||
if (!isAirOrNull(i)) {
|
||||
Bukkit.getPluginManager().callEvent(new ArmorEquipEvent(p, EquipMethod.DEATH, ArmorType.matchType(i), i, null));
|
||||
// No way to cancel a death event.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isAirOrNull(@Nullable final ItemStack item) {
|
||||
return item == null || item.getType().equals(Material.AIR);
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package com.willfp.eco.util.events.armorequip;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* @author Arnah
|
||||
* @since Jul 30, 2015
|
||||
*/
|
||||
public enum ArmorType {
|
||||
HELMET(5),
|
||||
CHESTPLATE(6),
|
||||
LEGGINGS(7),
|
||||
BOOTS(8);
|
||||
|
||||
private final int slot;
|
||||
|
||||
ArmorType(final int slot) {
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to match the ArmorType for the specified ItemStack.
|
||||
*
|
||||
* @param itemStack The ItemStack to parse the type of.
|
||||
*
|
||||
* @return The parsed ArmorType, or null if not found.
|
||||
*/
|
||||
public static ArmorType matchType(final ItemStack itemStack) {
|
||||
if (ArmorListener.isAirOrNull(itemStack)) {
|
||||
return null;
|
||||
}
|
||||
String type = itemStack.getType().name();
|
||||
if (type.endsWith("_HELMET") || type.endsWith("_SKULL") || type.endsWith("PLAYER_HEAD")) {
|
||||
return HELMET;
|
||||
} else if (type.endsWith("_CHESTPLATE") || type.endsWith("ELYTRA")) {
|
||||
return CHESTPLATE;
|
||||
} else if (type.endsWith("_LEGGINGS")) {
|
||||
return LEGGINGS;
|
||||
} else if (type.endsWith("_BOOTS")) {
|
||||
return BOOTS;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public int getSlot() {
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.willfp.eco.util.events.armorequip;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockDispenseArmorEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Arnah
|
||||
* @since Feb 08, 2019
|
||||
*/
|
||||
public class DispenserArmorListener implements Listener {
|
||||
@EventHandler
|
||||
public void dispenseArmorEvent(@NotNull final BlockDispenseArmorEvent event) {
|
||||
ArmorType type = ArmorType.matchType(event.getItem());
|
||||
if (type != null && event.getTargetEntity() instanceof Player) {
|
||||
Player p = (Player) event.getTargetEntity();
|
||||
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent(p, ArmorEquipEvent.EquipMethod.DISPENSER, type, null, event.getItem());
|
||||
Bukkit.getPluginManager().callEvent(armorEquipEvent);
|
||||
if (armorEquipEvent.isCancelled()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.willfp.eco.util.extensions;
|
||||
|
||||
import com.willfp.eco.internal.extensions.ExtensionMetadata;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class Extension {
|
||||
@@ -71,7 +71,7 @@ public abstract class Extension {
|
||||
*/
|
||||
public final String getName() {
|
||||
Validate.notNull(metadata, "Metadata cannot be null!");
|
||||
return this.metadata.name;
|
||||
return this.metadata.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,36 +81,6 @@ public abstract class Extension {
|
||||
*/
|
||||
public final String getVersion() {
|
||||
Validate.notNull(metadata, "Metadata cannot be null!");
|
||||
return this.metadata.version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for the string and version of the extension.
|
||||
* Contains versions and name.
|
||||
* Designed for internal use.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public static final class ExtensionMetadata {
|
||||
/**
|
||||
* The version of the extension.
|
||||
*/
|
||||
private final @NotNull String version;
|
||||
|
||||
/**
|
||||
* The extension's name.
|
||||
*/
|
||||
private final @NotNull String name;
|
||||
|
||||
/**
|
||||
* Create a new extension metadata.
|
||||
*
|
||||
* @param version The version for the extension to be.
|
||||
* @param name The name of the extension.
|
||||
*/
|
||||
public ExtensionMetadata(@NotNull final String version,
|
||||
@NotNull final String name) {
|
||||
this.version = version;
|
||||
this.name = name;
|
||||
}
|
||||
return this.metadata.getVersion();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
package com.willfp.eco.util.extensions.loader;
|
||||
|
||||
import com.willfp.eco.util.extensions.Extension;
|
||||
package com.willfp.eco.util.extensions;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@@ -20,11 +18,6 @@ public interface ExtensionLoader {
|
||||
*/
|
||||
void unloadExtensions();
|
||||
|
||||
/**
|
||||
* Reload all extensions.
|
||||
*/
|
||||
void reloadExtensions();
|
||||
|
||||
/**
|
||||
* Retrieve a set of all loaded extensions.
|
||||
*
|
||||
@@ -17,7 +17,7 @@ import com.willfp.eco.util.config.configs.Lang;
|
||||
import com.willfp.eco.util.config.updating.ConfigHandler;
|
||||
import com.willfp.eco.util.display.Display;
|
||||
import com.willfp.eco.util.display.DisplayModule;
|
||||
import com.willfp.eco.util.extensions.loader.ExtensionLoader;
|
||||
import com.willfp.eco.util.extensions.ExtensionLoader;
|
||||
import com.willfp.eco.util.integrations.IntegrationLoader;
|
||||
import com.willfp.eco.util.integrations.placeholder.PlaceholderManager;
|
||||
import com.willfp.eco.util.integrations.placeholder.plugins.PlaceholderIntegrationPAPI;
|
||||
|
||||
Reference in New Issue
Block a user