mirror of
https://github.com/Auxilor/EcoMobs.git
synced 2025-12-23 17:09:27 +00:00
Removed unused classes
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
package com.willfp.illusioner.nms.api;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* NMS Interface for breaking blocks as player
|
||||
*/
|
||||
public interface BlockBreakWrapper {
|
||||
void breakBlock(Player player, Block block);
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.willfp.illusioner.nms.api;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* NMS Interface for getting attack cooldown
|
||||
*/
|
||||
public interface CooldownWrapper {
|
||||
double getAttackCooldown(Player player);
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package com.willfp.illusioner.nms.api;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface OpenInventoryWrapper {
|
||||
Object getOpenInventory(Player player);
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.willfp.illusioner.nms.api;
|
||||
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* NMS Interface for getting an ItemStack from a Trident
|
||||
*/
|
||||
public interface TridentStackWrapper {
|
||||
ItemStack getTridentStack(Trident trident);
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.willfp.illusioner.v1_15_R1;
|
||||
|
||||
import com.willfp.illusioner.nms.api.BlockBreakWrapper;
|
||||
import net.minecraft.server.v1_15_R1.BlockPosition;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class BlockBreak implements BlockBreakWrapper {
|
||||
@Override
|
||||
public void breakBlock(Player player, Block block) {
|
||||
((CraftPlayer)player).getHandle().playerInteractManager.breakBlock(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.willfp.illusioner.v1_15_R1;
|
||||
|
||||
import com.willfp.illusioner.nms.api.CooldownWrapper;
|
||||
import net.minecraft.server.v1_15_R1.EntityHuman;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Cooldown implements CooldownWrapper {
|
||||
@Override
|
||||
public double getAttackCooldown(Player player) {
|
||||
EntityHuman entityHuman = ((CraftPlayer) player).getHandle();
|
||||
return entityHuman.s(0);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.willfp.illusioner.v1_15_R1;
|
||||
|
||||
import com.willfp.illusioner.nms.api.OpenInventoryWrapper;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class OpenInventory implements OpenInventoryWrapper {
|
||||
@Override
|
||||
public Object getOpenInventory(Player player) {
|
||||
return ((CraftPlayer) player).getHandle().activeContainer;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.willfp.illusioner.v1_15_R1;
|
||||
|
||||
import com.willfp.illusioner.nms.api.TridentStackWrapper;
|
||||
import net.minecraft.server.v1_15_R1.EntityThrownTrident;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftTrident;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class TridentStack implements TridentStackWrapper {
|
||||
@Override
|
||||
public ItemStack getTridentStack(Trident trident) {
|
||||
EntityThrownTrident t = ((CraftTrident) trident).getHandle();
|
||||
return CraftItemStack.asBukkitCopy(t.trident);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.willfp.illusioner.v1_16_R1;
|
||||
|
||||
import com.willfp.illusioner.nms.api.BlockBreakWrapper;
|
||||
import net.minecraft.server.v1_16_R1.BlockPosition;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class BlockBreak implements BlockBreakWrapper {
|
||||
@Override
|
||||
public void breakBlock(Player player, Block block) {
|
||||
((CraftPlayer)player).getHandle().playerInteractManager.breakBlock(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.willfp.illusioner.v1_16_R1;
|
||||
|
||||
import com.willfp.illusioner.nms.api.CooldownWrapper;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Cooldown implements CooldownWrapper {
|
||||
@Override
|
||||
public double getAttackCooldown(Player player) {
|
||||
return player.getAttackCooldown();
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.willfp.illusioner.v1_16_R1;
|
||||
|
||||
import com.willfp.illusioner.nms.api.OpenInventoryWrapper;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class OpenInventory implements OpenInventoryWrapper {
|
||||
@Override
|
||||
public Object getOpenInventory(Player player) {
|
||||
return ((CraftPlayer) player).getHandle().activeContainer;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.willfp.illusioner.v1_16_R1;
|
||||
|
||||
import com.willfp.illusioner.nms.api.TridentStackWrapper;
|
||||
import net.minecraft.server.v1_16_R1.EntityThrownTrident;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftTrident;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class TridentStack implements TridentStackWrapper {
|
||||
@Override
|
||||
public ItemStack getTridentStack(Trident trident) {
|
||||
EntityThrownTrident t = ((CraftTrident) trident).getHandle();
|
||||
return CraftItemStack.asBukkitCopy(t.trident);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.willfp.illusioner.v1_16_R2;
|
||||
|
||||
import com.willfp.illusioner.nms.api.BlockBreakWrapper;
|
||||
import net.minecraft.server.v1_16_R2.BlockPosition;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class BlockBreak implements BlockBreakWrapper {
|
||||
@Override
|
||||
public void breakBlock(Player player, Block block) {
|
||||
((CraftPlayer)player).getHandle().playerInteractManager.breakBlock(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.willfp.illusioner.v1_16_R2;
|
||||
|
||||
import com.willfp.illusioner.nms.api.CooldownWrapper;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Cooldown implements CooldownWrapper {
|
||||
@Override
|
||||
public double getAttackCooldown(Player player) {
|
||||
return player.getAttackCooldown();
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.willfp.illusioner.v1_16_R2;
|
||||
|
||||
import com.willfp.illusioner.nms.api.OpenInventoryWrapper;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class OpenInventory implements OpenInventoryWrapper {
|
||||
@Override
|
||||
public Object getOpenInventory(Player player) {
|
||||
return ((CraftPlayer) player).getHandle().activeContainer;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.willfp.illusioner.v1_16_R2;
|
||||
|
||||
import com.willfp.illusioner.nms.api.TridentStackWrapper;
|
||||
import net.minecraft.server.v1_16_R2.EntityThrownTrident;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.entity.CraftTrident;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class TridentStack implements TridentStackWrapper {
|
||||
@Override
|
||||
public ItemStack getTridentStack(Trident trident) {
|
||||
EntityThrownTrident t = ((CraftTrident) trident).getHandle();
|
||||
return CraftItemStack.asBukkitCopy(t.trident);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.willfp.illusioner.v1_16_R3;
|
||||
|
||||
import com.willfp.illusioner.nms.api.BlockBreakWrapper;
|
||||
import net.minecraft.server.v1_16_R3.BlockPosition;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class BlockBreak implements BlockBreakWrapper {
|
||||
@Override
|
||||
public void breakBlock(Player player, Block block) {
|
||||
((CraftPlayer)player).getHandle().playerInteractManager.breakBlock(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.willfp.illusioner.v1_16_R3;
|
||||
|
||||
import com.willfp.illusioner.nms.api.CooldownWrapper;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Cooldown implements CooldownWrapper {
|
||||
@Override
|
||||
public double getAttackCooldown(Player player) {
|
||||
return player.getAttackCooldown();
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.willfp.illusioner.v1_16_R3;
|
||||
|
||||
import com.willfp.illusioner.nms.api.OpenInventoryWrapper;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class OpenInventory implements OpenInventoryWrapper {
|
||||
@Override
|
||||
public Object getOpenInventory(Player player) {
|
||||
return ((CraftPlayer) player).getHandle().activeContainer;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.willfp.illusioner.v1_16_R3;
|
||||
|
||||
import com.willfp.illusioner.nms.api.TridentStackWrapper;
|
||||
import net.minecraft.server.v1_16_R3.EntityThrownTrident;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftTrident;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class TridentStack implements TridentStackWrapper {
|
||||
@Override
|
||||
public ItemStack getTridentStack(Trident trident) {
|
||||
EntityThrownTrident t = ((CraftTrident) trident).getHandle();
|
||||
return CraftItemStack.asBukkitCopy(t.trident);
|
||||
}
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
package com.willfp.illusioner.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;
|
||||
|
||||
/**
|
||||
* @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, newArmorPiece;
|
||||
|
||||
public ArmorEquipEvent(final Player player, final EquipMethod equipType, final ArmorType type, final ItemStack oldArmorPiece, 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 {// These have got to be the worst documentations ever.
|
||||
/**
|
||||
* 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,204 +0,0 @@
|
||||
package com.willfp.illusioner.events.armorequip;
|
||||
|
||||
import com.willfp.illusioner.events.armorequip.ArmorEquipEvent.EquipMethod;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @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(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??
|
||||
if (e.getClick().equals(ClickType.SHIFT_LEFT) || e.getClick().equals(ClickType.SHIFT_RIGHT)) {
|
||||
shift = true;
|
||||
}
|
||||
if (e.getClick().equals(ClickType.NUMBER_KEY)) {
|
||||
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) {
|
||||
boolean equipping = true;
|
||||
if (e.getRawSlot() == newArmorType.getSlot()) {
|
||||
equipping = false;
|
||||
}
|
||||
if (newArmorType.equals(ArmorType.HELMET) && (equipping == isAirOrNull(e.getWhoClicked().getInventory().getHelmet())) || newArmorType.equals(ArmorType.CHESTPLATE) && (equipping == isAirOrNull(e.getWhoClicked().getInventory().getChestplate())) || newArmorType.equals(ArmorType.LEGGINGS) && (equipping == isAirOrNull(e.getWhoClicked().getInventory().getLeggings())) || newArmorType.equals(ArmorType.BOOTS) && (equipping == isAirOrNull(e.getWhoClicked().getInventory().getBoots()))) {
|
||||
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent((Player) e.getWhoClicked(), EquipMethod.SHIFT_CLICK, newArmorType, equipping ? null : e.getCurrentItem(), equipping ? e.getCurrentItem() : null);
|
||||
Bukkit.getPluginManager().callEvent(armorEquipEvent);
|
||||
if (armorEquipEvent.isCancelled()) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ItemStack newArmorPiece = e.getCursor();
|
||||
ItemStack oldArmorPiece = e.getCurrentItem();
|
||||
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.
|
||||
// e.getRawSlot() == The slot the item is going to.
|
||||
// e.getSlot() == Armor slot, can't use e.getRawSlot() as that gives a hotbar slot ;-;
|
||||
ItemStack hotbarItem = e.getClickedInventory().getItem(e.getHotbarButton());
|
||||
if (!isAirOrNull(hotbarItem)) {// Equipping
|
||||
newArmorType = ArmorType.matchType(hotbarItem);
|
||||
newArmorPiece = hotbarItem;
|
||||
oldArmorPiece = e.getClickedInventory().getItem(e.getSlot());
|
||||
} else {// Unequipping
|
||||
newArmorType = ArmorType.matchType(!isAirOrNull(e.getCurrentItem()) ? e.getCurrentItem() : e.getCursor());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (isAirOrNull(e.getCursor()) && !isAirOrNull(e.getCurrentItem())) {// unequip with no new item going into the slot.
|
||||
newArmorType = ArmorType.matchType(e.getCurrentItem());
|
||||
}
|
||||
// e.getCurrentItem() == Unequip
|
||||
// e.getCursor() == Equip
|
||||
// newArmorType = ArmorType.matchType(!isAirOrNull(e.getCurrentItem()) ? e.getCurrentItem() : e.getCursor());
|
||||
}
|
||||
if (newArmorType != null && e.getRawSlot() == newArmorType.getSlot()) {
|
||||
EquipMethod method = EquipMethod.PICK_DROP;
|
||||
if (e.getAction().equals(InventoryAction.HOTBAR_SWAP) || numberkey) method = EquipMethod.HOTBAR_SWAP;
|
||||
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent((Player) e.getWhoClicked(), method, newArmorType, oldArmorPiece, newArmorPiece);
|
||||
Bukkit.getPluginManager().callEvent(armorEquipEvent);
|
||||
if (armorEquipEvent.isCancelled()) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void playerInteractEvent(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()) {// 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.
|
||||
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(), 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(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;// 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.getPluginManager().callEvent(armorEquipEvent);
|
||||
if (armorEquipEvent.isCancelled()) {
|
||||
event.setResult(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
// Debug shit
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerJoinEvent(PlayerJoinEvent e) {
|
||||
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent(e.getPlayer(), null, null, null, null);
|
||||
Bukkit.getPluginManager().callEvent(armorEquipEvent);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerRespawnEvent(PlayerRespawnEvent e) {
|
||||
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent(e.getPlayer(), null, null, null, null);
|
||||
Bukkit.getPluginManager().callEvent(armorEquipEvent);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void itemBreakEvent(PlayerItemBreakEvent e) {
|
||||
ArmorType type = ArmorType.matchType(e.getBrokenItem());
|
||||
if (type != null) {
|
||||
Player p = e.getPlayer();
|
||||
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent(p, EquipMethod.BROKE, type, e.getBrokenItem(), null);
|
||||
Bukkit.getPluginManager().callEvent(armorEquipEvent);
|
||||
if (armorEquipEvent.isCancelled()) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerDeathEvent(PlayerDeathEvent e) {
|
||||
Player p = e.getEntity();
|
||||
if (e.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(ItemStack item) {
|
||||
return item == null || item.getType().equals(Material.AIR);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.willfp.illusioner.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(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,28 +0,0 @@
|
||||
package com.willfp.illusioner.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;
|
||||
|
||||
/**
|
||||
* @author Arnah
|
||||
* @since Feb 08, 2019
|
||||
*/
|
||||
public class DispenserArmorListener implements Listener {
|
||||
@EventHandler
|
||||
public void dispenseArmorEvent(BlockDispenseArmorEvent event) {
|
||||
ArmorType type = ArmorType.matchType(event.getItem());
|
||||
if (type != null) {
|
||||
if (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,46 +0,0 @@
|
||||
package com.willfp.illusioner.events.naturalexpgainevent;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.player.PlayerExpChangeEvent;
|
||||
|
||||
class NaturalExpGainBuilder {
|
||||
private final LivingEntity victim = null;
|
||||
private boolean cancelled = false;
|
||||
private PlayerExpChangeEvent event;
|
||||
private Location loc;
|
||||
|
||||
public NaturalExpGainBuilder() {
|
||||
|
||||
}
|
||||
|
||||
public LivingEntity getVictim() {
|
||||
return this.victim;
|
||||
}
|
||||
|
||||
public void setEvent(PlayerExpChangeEvent event) {
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
|
||||
public void setLoc(Location location) {
|
||||
this.loc = location;
|
||||
}
|
||||
|
||||
public Location getLoc() {
|
||||
return this.loc;
|
||||
}
|
||||
|
||||
public void push() {
|
||||
if(this.event == null) return;
|
||||
if(this.cancelled) return;
|
||||
|
||||
NaturalExpGainEvent naturalExpGainEvent = new NaturalExpGainEvent(event);
|
||||
|
||||
Bukkit.getPluginManager().callEvent(naturalExpGainEvent);
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package com.willfp.illusioner.events.naturalexpgainevent;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerExpChangeEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Event triggered when player receives experience not from bottle
|
||||
*/
|
||||
public class NaturalExpGainEvent extends Event {
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
/**
|
||||
* The associated {@link PlayerExpChangeEvent}
|
||||
*/
|
||||
private final PlayerExpChangeEvent event;
|
||||
|
||||
/**
|
||||
* Create event based off parameters
|
||||
*
|
||||
* @param event The associate PlayerExpChangeEvent
|
||||
*/
|
||||
public NaturalExpGainEvent(@NotNull PlayerExpChangeEvent event) {
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get associated {@link PlayerExpChangeEvent}
|
||||
* Use this to modify event parameters.
|
||||
*
|
||||
* @return The associated {@link PlayerExpChangeEvent}
|
||||
*/
|
||||
public PlayerExpChangeEvent getExpChangeEvent() {
|
||||
return this.event;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package com.willfp.illusioner.events.naturalexpgainevent;
|
||||
|
||||
import com.willfp.illusioner.IllusionerPlugin;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.ExpBottleEvent;
|
||||
import org.bukkit.event.player.PlayerExpChangeEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class NaturalExpGainListeners implements Listener {
|
||||
|
||||
final Set<NaturalExpGainBuilder> events = new HashSet<>();
|
||||
|
||||
@EventHandler
|
||||
public void onExpChange(PlayerExpChangeEvent event) {
|
||||
NaturalExpGainBuilder builtEvent = new NaturalExpGainBuilder();
|
||||
builtEvent.setEvent(event);
|
||||
|
||||
AtomicBoolean isNatural = new AtomicBoolean(true);
|
||||
AtomicReference<NaturalExpGainBuilder> atomicBuiltEvent = new AtomicReference<>();
|
||||
|
||||
Set<NaturalExpGainBuilder> eventsClone = new HashSet<>(events);
|
||||
eventsClone.forEach((builder) -> {
|
||||
if(builder.getLoc().getWorld().getNearbyEntities(builder.getLoc(), 7.25, 7.25, 7.25).contains(event.getPlayer())) {
|
||||
events.remove(builder);
|
||||
isNatural.set(false);
|
||||
atomicBuiltEvent.set(builder);
|
||||
}
|
||||
});
|
||||
|
||||
if(isNatural.get()) {
|
||||
events.remove(atomicBuiltEvent.get());
|
||||
builtEvent.push();
|
||||
}
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
events.remove(builtEvent);
|
||||
}
|
||||
}.runTaskLater(IllusionerPlugin.getInstance(), 1);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onExpBottle(ExpBottleEvent event) {
|
||||
NaturalExpGainBuilder builtEvent = new NaturalExpGainBuilder();
|
||||
builtEvent.setLoc(event.getEntity().getLocation());
|
||||
|
||||
events.add(builtEvent);
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package com.willfp.illusioner.nms;
|
||||
|
||||
import com.willfp.illusioner.IllusionerPlugin;
|
||||
import com.willfp.illusioner.nms.api.BlockBreakWrapper;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* Utility class to break a block as if the player had done it manually
|
||||
*/
|
||||
public class BlockBreak {
|
||||
private static BlockBreakWrapper blockBreakWrapper;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static boolean init() {
|
||||
try {
|
||||
final Class<?> class2 = Class.forName("com.willfp.illusioner." + IllusionerPlugin.NMS_VERSION + ".BlockBreak");
|
||||
if (BlockBreakWrapper.class.isAssignableFrom(class2)) {
|
||||
blockBreakWrapper = (BlockBreakWrapper) class2.getConstructor().newInstance();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
blockBreakWrapper = null;
|
||||
}
|
||||
return blockBreakWrapper != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Break a block as a player
|
||||
*
|
||||
* @param player The player to break the block as
|
||||
* @param block The block to break
|
||||
*/
|
||||
public static void breakBlock(Player player, Block block) {
|
||||
assert blockBreakWrapper != null;
|
||||
blockBreakWrapper.breakBlock(player, block);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.willfp.illusioner.nms;
|
||||
|
||||
import com.willfp.illusioner.IllusionerPlugin;
|
||||
import com.willfp.illusioner.nms.api.CooldownWrapper;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* Utility class to get the attack cooldown of a player
|
||||
*/
|
||||
public class Cooldown {
|
||||
private static CooldownWrapper cooldown;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static boolean init() {
|
||||
try {
|
||||
final Class<?> class2 = Class.forName("com.willfp.illusioner." + IllusionerPlugin.NMS_VERSION + ".Cooldown");
|
||||
if (CooldownWrapper.class.isAssignableFrom(class2)) {
|
||||
cooldown = (CooldownWrapper) class2.getConstructor().newInstance();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
cooldown = null;
|
||||
}
|
||||
return cooldown != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a player's attack cooldown
|
||||
*
|
||||
* @param player The player to check
|
||||
* @return A value between 0 and 1, with 1 representing max strength
|
||||
*/
|
||||
public static double getCooldown(Player player) {
|
||||
assert cooldown != null;
|
||||
return cooldown.getAttackCooldown(player);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.willfp.illusioner.nms;
|
||||
|
||||
import com.willfp.illusioner.IllusionerPlugin;
|
||||
import com.willfp.illusioner.nms.api.OpenInventoryWrapper;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* Utility class to get the NMS implementation of a players' currently open inventory
|
||||
*/
|
||||
public class OpenInventory {
|
||||
private static OpenInventoryWrapper openInventoryWrapper;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static boolean init() {
|
||||
try {
|
||||
final Class<?> class2 = Class.forName("com.willfp.illusioner." + IllusionerPlugin.NMS_VERSION + ".OpenInventory");
|
||||
if (OpenInventoryWrapper.class.isAssignableFrom(class2)) {
|
||||
openInventoryWrapper = (OpenInventoryWrapper) class2.getConstructor().newInstance();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
openInventoryWrapper = null;
|
||||
}
|
||||
return openInventoryWrapper != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the NMS container of the inventory
|
||||
*
|
||||
* @param player The player to check
|
||||
* @return The NMS container
|
||||
*/
|
||||
public static Object getOpenInventory(Player player) {
|
||||
assert openInventoryWrapper != null;
|
||||
return openInventoryWrapper.getOpenInventory(player);
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package com.willfp.illusioner.nms;
|
||||
|
||||
|
||||
import com.willfp.illusioner.IllusionerPlugin;
|
||||
import com.willfp.illusioner.nms.api.TridentStackWrapper;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* Utility class to get the {@link ItemStack} of a given {@link Trident}
|
||||
*/
|
||||
public class TridentStack {
|
||||
private static TridentStackWrapper tridentStackWrapper;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static boolean init() {
|
||||
try {
|
||||
final Class<?> class2 = Class.forName("com.willfp.illusioner." + IllusionerPlugin.NMS_VERSION + ".TridentStack");
|
||||
if (TridentStackWrapper.class.isAssignableFrom(class2)) {
|
||||
tridentStackWrapper = (TridentStackWrapper) class2.getConstructor().newInstance();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
tridentStackWrapper = null;
|
||||
}
|
||||
return tridentStackWrapper != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link ItemStack} of a given {@link Trident}
|
||||
*
|
||||
* @param trident The trident to get the ItemStack from
|
||||
* @return The ItemStack associated with the trident
|
||||
*/
|
||||
public static ItemStack getTridentStack(Trident trident) {
|
||||
assert tridentStackWrapper != null;
|
||||
return tridentStackWrapper.getTridentStack(trident);
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.willfp.illusioner.util;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class BlockUtils {
|
||||
private static Set<Block> getNearbyBlocks(Block start, List<Material> allowedMaterials, HashSet<Block> blocks, int limit) {
|
||||
for (BlockFace face : BlockFace.values()) {
|
||||
Block block = start.getRelative(face);
|
||||
if (!blocks.contains(block) && allowedMaterials.contains(block.getType())) {
|
||||
blocks.add(block);
|
||||
if (blocks.size() > limit) return blocks;
|
||||
if (blocks.size() > 2500) return blocks; // anti stack overflow
|
||||
blocks.addAll(getNearbyBlocks(block, allowedMaterials, blocks, limit));
|
||||
}
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a set of all blocks in contact with each other of a specific type
|
||||
*
|
||||
* @param start The initial block
|
||||
* @param allowedMaterials A list of all valid {@link Material}s
|
||||
* @param limit The maximum size of vein to return
|
||||
* @return A set of all {@link Block}s
|
||||
*/
|
||||
public static Set<Block> getVein(Block start, List<Material> allowedMaterials, int limit) {
|
||||
return getNearbyBlocks(start, allowedMaterials, new HashSet<>(), limit);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.willfp.illusioner.util;
|
||||
|
||||
public class ClassUtils {
|
||||
/**
|
||||
* Get if a class exists
|
||||
*
|
||||
* @param className The class to check
|
||||
* @return If the class exists
|
||||
* @see Class#forName(String)
|
||||
*/
|
||||
public static boolean exists(String className) {
|
||||
try {
|
||||
Class.forName(className);
|
||||
return true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
package com.willfp.illusioner.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.SoundCategory;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerItemBreakEvent;
|
||||
import org.bukkit.event.player.PlayerItemDamageEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
/**
|
||||
* Contains methods for damaging/repairing items
|
||||
*/
|
||||
public class DurabilityUtils {
|
||||
/**
|
||||
* Damage an item in a player's inventory
|
||||
* The slot of a held item can be obtained with {@link PlayerInventory#getHeldItemSlot()}
|
||||
* Armor slots are 39 (helmet), 38 (chestplate), 37 (leggings), 36 (boots)
|
||||
*
|
||||
* @param player The player
|
||||
* @param item The item to damage
|
||||
* @param damage The amount of damage to deal
|
||||
* @param slot The slot in the inventory of the item
|
||||
*/
|
||||
public static void damageItem(Player player, ItemStack item, int damage, int slot) {
|
||||
if (item == null) return;
|
||||
if (item.getItemMeta() == null) return;
|
||||
|
||||
if (item.getItemMeta().isUnbreakable()) return;
|
||||
|
||||
PlayerItemDamageEvent event3 = new PlayerItemDamageEvent(player, item, damage);
|
||||
Bukkit.getPluginManager().callEvent(event3);
|
||||
|
||||
if (!event3.isCancelled()) {
|
||||
int damage2 = event3.getDamage();
|
||||
if (item.getItemMeta() instanceof Damageable) {
|
||||
Damageable meta = (Damageable) item.getItemMeta();
|
||||
meta.setDamage(meta.getDamage() + damage2);
|
||||
|
||||
if (meta.getDamage() >= item.getType().getMaxDurability()) {
|
||||
meta.setDamage(item.getType().getMaxDurability());
|
||||
item.setItemMeta((ItemMeta) meta);
|
||||
PlayerItemBreakEvent event = new PlayerItemBreakEvent(player, item);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
player.getInventory().clear(slot);
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, SoundCategory.BLOCKS, 1, 1);
|
||||
} else {
|
||||
item.setItemMeta((ItemMeta) meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Damage an item in a player's inventory without breaking it
|
||||
* The slot of a held item can be obtained with {@link PlayerInventory#getHeldItemSlot()}
|
||||
* Armor slots are 39 (helmet), 38 (chestplate), 37 (leggings), 36 (boots)
|
||||
*
|
||||
* @param item The item to damage
|
||||
* @param damage The amount of damage to deal
|
||||
* @param player The player
|
||||
*/
|
||||
public static void damageItemNoBreak(ItemStack item, int damage, Player player) {
|
||||
if (item == null) return;
|
||||
if (item.getItemMeta() == null) return;
|
||||
|
||||
if (item.getItemMeta().isUnbreakable()) return;
|
||||
|
||||
PlayerItemDamageEvent event3 = new PlayerItemDamageEvent(player, item, damage);
|
||||
Bukkit.getPluginManager().callEvent(event3);
|
||||
|
||||
if (!event3.isCancelled()) {
|
||||
int damage2 = event3.getDamage();
|
||||
if (item.getItemMeta() instanceof Damageable) {
|
||||
Damageable meta = (Damageable) item.getItemMeta();
|
||||
meta.setDamage(meta.getDamage() + damage2);
|
||||
|
||||
if (meta.getDamage() >= item.getType().getMaxDurability()) {
|
||||
meta.setDamage(item.getType().getMaxDurability() - 1);
|
||||
}
|
||||
item.setItemMeta((ItemMeta) meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Repair an item in a player's inventory
|
||||
* The slot of a held item can be obtained with {@link PlayerInventory#getHeldItemSlot()}
|
||||
* Armor slots are 39 (helmet), 38 (chestplate), 37 (leggings), 36 (boots)
|
||||
*
|
||||
* @param item The item to damage
|
||||
* @param repair The amount of damage to heal
|
||||
*/
|
||||
public static void repairItem(ItemStack item, int repair) {
|
||||
if (item == null) return;
|
||||
if (item.getItemMeta() == null) return;
|
||||
|
||||
if (item.getItemMeta().isUnbreakable()) return;
|
||||
if (item.getItemMeta() instanceof Damageable) {
|
||||
Damageable meta = (Damageable) item.getItemMeta();
|
||||
meta.setDamage(meta.getDamage() - repair);
|
||||
|
||||
if (meta.getDamage() < 0) {
|
||||
meta.setDamage(0);
|
||||
}
|
||||
item.setItemMeta((ItemMeta) meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.willfp.illusioner.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
/**
|
||||
* Class containing methods for striking lightning
|
||||
*/
|
||||
public class LightningUtils {
|
||||
|
||||
/**
|
||||
* Strike lightning on player without fire
|
||||
*
|
||||
* @param victim The entity to smite
|
||||
* @param damage The damage to deal
|
||||
*/
|
||||
public static void strike(LivingEntity victim, double damage) {
|
||||
if (victim == null) return;
|
||||
|
||||
Location loc = victim.getLocation();
|
||||
|
||||
victim.getWorld().strikeLightningEffect(loc);
|
||||
|
||||
victim.damage(damage);
|
||||
}
|
||||
}
|
||||
@@ -1,141 +0,0 @@
|
||||
package com.willfp.illusioner.util;
|
||||
|
||||
import org.bukkit.util.NumberConversions;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class VectorUtils {
|
||||
/**
|
||||
* If vector has all components as finite
|
||||
*
|
||||
* @param vector The vector to check
|
||||
* @return If the vector is finite
|
||||
*/
|
||||
public static boolean isFinite(Vector vector) {
|
||||
try {
|
||||
NumberConversions.checkFinite(vector.getX(), "x not finite");
|
||||
NumberConversions.checkFinite(vector.getY(), "y not finite");
|
||||
NumberConversions.checkFinite(vector.getZ(), "z not finite");
|
||||
} catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only keep largest part of normalised vector.
|
||||
* For example: -0.8, 0.01, -0.2 would become -1, 0, 0
|
||||
*
|
||||
* @param vec The vector to simplify
|
||||
* @return The vector, simplified
|
||||
*/
|
||||
public static Vector simplifyVector(Vector vec) {
|
||||
double x = Math.abs(vec.getX());
|
||||
double y = Math.abs(vec.getY());
|
||||
double z = Math.abs(vec.getZ());
|
||||
double max = Math.max(x, Math.max(y, z));
|
||||
if (x > 1 || z > 1) {
|
||||
max = y;
|
||||
}
|
||||
if (max == x) {
|
||||
if (vec.getX() < 0) {
|
||||
return new Vector(-1, 0, 0);
|
||||
}
|
||||
return new Vector(1, 0, 0);
|
||||
} else if (max == y) {
|
||||
if (vec.getY() < 0) {
|
||||
return new Vector(0, -1, 0);
|
||||
}
|
||||
return new Vector(0, 1, 0);
|
||||
} else {
|
||||
if (vec.getZ() < 0) {
|
||||
return new Vector(0, 0, -1);
|
||||
}
|
||||
return new Vector(0, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get circle as relative vectors
|
||||
*
|
||||
* @param radius The radius
|
||||
* @return An array of {@link Vector}s
|
||||
*/
|
||||
public static Vector[] getCircle(int radius) {
|
||||
ArrayList<Vector> circleVecs = new ArrayList<>();
|
||||
|
||||
int xoffset = -radius;
|
||||
int zoffset = -radius;
|
||||
|
||||
while (zoffset <= radius) {
|
||||
while (xoffset <= radius) {
|
||||
if (Math.round(Math.sqrt((xoffset * xoffset) + (zoffset * zoffset))) <= radius) {
|
||||
circleVecs.add(new Vector(xoffset, 0, zoffset));
|
||||
} else {
|
||||
xoffset++;
|
||||
continue;
|
||||
}
|
||||
xoffset++;
|
||||
}
|
||||
xoffset = -radius;
|
||||
zoffset++;
|
||||
}
|
||||
|
||||
return circleVecs.toArray(new Vector[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get square as relative vectors
|
||||
*
|
||||
* @param radius The radius of the square
|
||||
* @return An array of {@link Vector}s
|
||||
*/
|
||||
public static Vector[] getSquare(int radius) {
|
||||
ArrayList<Vector> circleVecs = new ArrayList<>();
|
||||
|
||||
int xoffset = -radius;
|
||||
int zoffset = -radius;
|
||||
|
||||
while (zoffset <= radius) {
|
||||
while (xoffset <= radius) {
|
||||
circleVecs.add(new Vector(xoffset, 0, zoffset));
|
||||
xoffset++;
|
||||
}
|
||||
xoffset = -radius;
|
||||
zoffset++;
|
||||
}
|
||||
|
||||
return circleVecs.toArray(new Vector[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cube as relative vectors
|
||||
*
|
||||
* @param radius The radius of the cube
|
||||
* @return An array of {@link Vector}s
|
||||
*/
|
||||
public static Vector[] getCube(int radius) {
|
||||
ArrayList<Vector> cubeVecs = new ArrayList<>();
|
||||
|
||||
int xoffset = -radius;
|
||||
int zoffset = -radius;
|
||||
int yoffset = -radius;
|
||||
|
||||
while (yoffset <= radius) {
|
||||
while (zoffset <= radius) {
|
||||
while (xoffset <= radius) {
|
||||
cubeVecs.add(new Vector(xoffset, yoffset, zoffset));
|
||||
xoffset++;
|
||||
}
|
||||
xoffset = -radius;
|
||||
zoffset++;
|
||||
}
|
||||
zoffset = -radius;
|
||||
yoffset++;
|
||||
}
|
||||
|
||||
return cubeVecs.toArray(new Vector[0]);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.willfp.illusioner.util.interfaces;
|
||||
|
||||
/**
|
||||
* Functional Interface to return a value of a specified type given a certain parameter
|
||||
*
|
||||
* @param <A> The type of object to return
|
||||
* @param <B> The type of object for the parameter
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ObjectBiCallable<A, B> {
|
||||
A call(B object);
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.willfp.illusioner.util.interfaces;
|
||||
|
||||
/**
|
||||
* Functional Interface to return a value of a given type
|
||||
*
|
||||
* @param <A> The type to return
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ObjectCallable<A> {
|
||||
A call();
|
||||
}
|
||||
@@ -4,21 +4,13 @@ import com.willfp.illusioner.IllusionerPlugin;
|
||||
import com.willfp.illusioner.command.commands.CommandIldebug;
|
||||
import com.willfp.illusioner.command.commands.CommandIlreload;
|
||||
import com.willfp.illusioner.config.ConfigManager;
|
||||
import com.willfp.illusioner.events.armorequip.ArmorListener;
|
||||
import com.willfp.illusioner.events.armorequip.DispenserArmorListener;
|
||||
import com.willfp.illusioner.events.entitydeathbyentity.EntityDeathByEntityListeners;
|
||||
import com.willfp.illusioner.events.naturalexpgainevent.NaturalExpGainListeners;
|
||||
import com.willfp.illusioner.illusioner.IllusionerManager;
|
||||
import com.willfp.illusioner.illusioner.listeners.AttackListeners;
|
||||
import com.willfp.illusioner.illusioner.listeners.DeathListeners;
|
||||
import com.willfp.illusioner.illusioner.listeners.SpawnListeners;
|
||||
import com.willfp.illusioner.integrations.ecoenchants.EcoEnchantsManager;
|
||||
import com.willfp.illusioner.integrations.ecoenchants.plugins.EcoEnchantsIntegrationImpl;
|
||||
import com.willfp.illusioner.nms.BlockBreak;
|
||||
import com.willfp.illusioner.nms.Cooldown;
|
||||
import com.willfp.illusioner.nms.NMSIllusioner;
|
||||
import com.willfp.illusioner.nms.OpenInventory;
|
||||
import com.willfp.illusioner.nms.TridentStack;
|
||||
import com.willfp.illusioner.util.interfaces.Callable;
|
||||
import com.willfp.illusioner.util.internal.updater.PlayerJoinListener;
|
||||
import com.willfp.illusioner.util.internal.updater.UpdateChecker;
|
||||
@@ -62,38 +54,6 @@ public class Loader {
|
||||
|
||||
Logger.info("Loading NMS APIs...");
|
||||
|
||||
if (Cooldown.init()) {
|
||||
Logger.info("Cooldown: &aSUCCESS");
|
||||
} else {
|
||||
Logger.info("Cooldown: &cFAILURE");
|
||||
Logger.error("&cAborting...");
|
||||
Bukkit.getPluginManager().disablePlugin(IllusionerPlugin.getInstance());
|
||||
}
|
||||
|
||||
if (TridentStack.init()) {
|
||||
Logger.info("Trident API: &aSUCCESS");
|
||||
} else {
|
||||
Logger.info("Trident API: &cFAILURE");
|
||||
Logger.error("&cAborting...");
|
||||
Bukkit.getPluginManager().disablePlugin(IllusionerPlugin.getInstance());
|
||||
}
|
||||
|
||||
if (BlockBreak.init()) {
|
||||
Logger.info("Block Break: &aSUCCESS");
|
||||
} else {
|
||||
Logger.info("Block Break: &cFAILURE");
|
||||
Logger.error("&cAborting...");
|
||||
Bukkit.getPluginManager().disablePlugin(IllusionerPlugin.getInstance());
|
||||
}
|
||||
|
||||
if (OpenInventory.init()) {
|
||||
Logger.info("Open Inventory: &aSUCCESS");
|
||||
} else {
|
||||
Logger.info("Open Inventory: &cFAILURE");
|
||||
Logger.error("&cAborting...");
|
||||
Bukkit.getPluginManager().disablePlugin(IllusionerPlugin.getInstance());
|
||||
}
|
||||
|
||||
if (NMSIllusioner.init()) {
|
||||
Logger.info("NMS Illusioner: &aSUCCESS");
|
||||
} else {
|
||||
@@ -134,11 +94,7 @@ public class Loader {
|
||||
*/
|
||||
|
||||
Logger.info("Registering Events...");
|
||||
Bukkit.getPluginManager().registerEvents(new ArmorListener(), IllusionerPlugin.getInstance());
|
||||
Bukkit.getPluginManager().registerEvents(new DispenserArmorListener(), IllusionerPlugin.getInstance());
|
||||
Bukkit.getPluginManager().registerEvents(new PlayerJoinListener(), IllusionerPlugin.getInstance());
|
||||
Bukkit.getPluginManager().registerEvents(new EntityDeathByEntityListeners(), IllusionerPlugin.getInstance());
|
||||
Bukkit.getPluginManager().registerEvents(new NaturalExpGainListeners(), IllusionerPlugin.getInstance());
|
||||
Bukkit.getPluginManager().registerEvents(new AttackListeners(), IllusionerPlugin.getInstance());
|
||||
Bukkit.getPluginManager().registerEvents(new DeathListeners(), IllusionerPlugin.getInstance());
|
||||
Bukkit.getPluginManager().registerEvents(new SpawnListeners(), IllusionerPlugin.getInstance());
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
package com.willfp.illusioner.util.tuplets;
|
||||
|
||||
/**
|
||||
* Spigot doesn't include javafx
|
||||
*/
|
||||
public class Triplet<A, B, C> {
|
||||
private A first;
|
||||
private B second;
|
||||
private C third;
|
||||
|
||||
/**
|
||||
* Create a triplet
|
||||
*
|
||||
* @param first The first item in the tuplet
|
||||
* @param second The second item in the tuplet
|
||||
* @param third The third item in the tuplet
|
||||
*/
|
||||
public Triplet(A first, B second, C third) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
this.third = third;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first item in the tuplet
|
||||
*
|
||||
* @return The first item
|
||||
*/
|
||||
public A getFirst() {
|
||||
return first;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the second item in the tuplet
|
||||
*
|
||||
* @return The second item
|
||||
*/
|
||||
public B getSecond() {
|
||||
return second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the third item in the tuplet
|
||||
*
|
||||
* @return The third item
|
||||
*/
|
||||
public C getThird() {
|
||||
return third;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the first item in the tuplet
|
||||
*
|
||||
* @param first The value to set
|
||||
*/
|
||||
public void setFirst(A first) {
|
||||
this.first = first;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the second item in the tuplet
|
||||
*
|
||||
* @param second The value to set
|
||||
*/
|
||||
public void setSecond(B second) {
|
||||
this.second = second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the third item in the tuplet
|
||||
*
|
||||
* @param third The value to set
|
||||
*/
|
||||
public void setThird(C third) {
|
||||
this.third = third;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Triplet{" +
|
||||
"first=" + first +
|
||||
", second=" + second +
|
||||
", third=" + third +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user