mirror of
https://e.coding.net/circlecloud/Soulbound.git
synced 2024-11-21 01:39:10 +00:00
update project...
Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
parent
ae50ac1251
commit
48e71f0b55
@ -10,10 +10,9 @@ import com.me.tft_02.soulbound.util.DurabilityUtils;
|
||||
|
||||
public class BlockListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
ItemStack itemStack = event.getPlayer().getItemInHand();
|
||||
|
||||
DurabilityUtils.handleInfiniteDurability(itemStack);
|
||||
}
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onBlockBreak(final BlockBreakEvent event) {
|
||||
final ItemStack itemStack = event.getPlayer().getItemInHand();
|
||||
DurabilityUtils.handleInfiniteDurability(itemStack);
|
||||
}
|
||||
}
|
||||
|
@ -16,65 +16,61 @@ import com.me.tft_02.soulbound.util.DurabilityUtils;
|
||||
|
||||
public class EntityListener implements Listener {
|
||||
|
||||
/**
|
||||
* Check EntityDamageByEntityEvent events.
|
||||
*
|
||||
* @param event The event to check
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onEntityDeath(EntityDamageByEntityEvent event) {
|
||||
if (event.getDamage() == 0 || event.getEntity().isDead()) {
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Check EntityDamageByEntityEvent events.
|
||||
*
|
||||
* @param event
|
||||
* The event to check
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onEntityDeath(final EntityDamageByEntityEvent event) {
|
||||
if (event.getDamage() == 0 || event.getEntity().isDead()) {
|
||||
return;
|
||||
}
|
||||
if (event.getEntity() instanceof LivingEntity) {
|
||||
combatChecks(event);
|
||||
}
|
||||
}
|
||||
|
||||
if (event.getEntity() instanceof LivingEntity) {
|
||||
combatChecks(event);
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
private void onEntityDamage(final EntityDamageEvent event) {
|
||||
if (event.getDamage() == 0 || event.getEntity().isDead()) {
|
||||
return;
|
||||
}
|
||||
final Entity entity = event.getEntity();
|
||||
if (entity instanceof Player) {
|
||||
final Player player = (Player) entity;
|
||||
|
||||
/**
|
||||
* Apply combat modifiers
|
||||
*
|
||||
* @param event The event to run the combat checks on.
|
||||
*/
|
||||
void combatChecks(EntityDamageByEntityEvent event) {
|
||||
Entity damager = event.getDamager();
|
||||
EntityType damagerType = damager.getType();
|
||||
for (final ItemStack itemStack : player.getInventory().getArmorContents()) {
|
||||
DurabilityUtils.handleInfiniteDurability(itemStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (damagerType) {
|
||||
case PLAYER:
|
||||
Player attacker = (Player) event.getDamager();
|
||||
ItemStack itemInHand = attacker.getItemInHand();
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
private void onEntityShootBow(final EntityShootBowEvent event) {
|
||||
final Entity entity = event.getEntity();
|
||||
if (entity instanceof Player) {
|
||||
DurabilityUtils.handleInfiniteDurability(((Player) entity).getItemInHand());
|
||||
}
|
||||
}
|
||||
|
||||
DurabilityUtils.handleInfiniteDurability(itemInHand);
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
private void onEntityShootBow(EntityShootBowEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
|
||||
if (entity instanceof Player) {
|
||||
DurabilityUtils.handleInfiniteDurability(((Player) entity).getItemInHand());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
private void onEntityDamage(EntityDamageEvent event) {
|
||||
if (event.getDamage() == 0 || event.getEntity().isDead()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = event.getEntity();
|
||||
|
||||
if (entity instanceof Player) {
|
||||
Player player = (Player) entity;
|
||||
|
||||
for (ItemStack itemStack : player.getInventory().getArmorContents()) {
|
||||
DurabilityUtils.handleInfiniteDurability(itemStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Apply combat modifiers
|
||||
*
|
||||
* @param event
|
||||
* The event to run the combat checks on.
|
||||
*/
|
||||
void combatChecks(final EntityDamageByEntityEvent event) {
|
||||
final Entity damager = event.getDamager();
|
||||
final EntityType damagerType = damager.getType();
|
||||
switch (damagerType) {
|
||||
case PLAYER:
|
||||
final Player attacker = (Player) event.getDamager();
|
||||
final ItemStack itemInHand = attacker.getItemInHand();
|
||||
DurabilityUtils.handleInfiniteDurability(itemInHand);
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,153 +27,133 @@ import com.me.tft_02.soulbound.util.Permissions;
|
||||
|
||||
public class InventoryListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
void onInventoryClick(InventoryClickEvent event) {
|
||||
HumanEntity entity = event.getWhoClicked();
|
||||
ItemStack itemStack = event.getCurrentItem();
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onInventoryClickEvent(final InventoryClickEvent event) {
|
||||
final HumanEntity entity = event.getWhoClicked();
|
||||
if (!(entity instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
final Player player = (Player) entity;
|
||||
final ItemStack itemStack = event.getCurrentItem();
|
||||
final InventoryType inventoryType = event.getInventory().getType();
|
||||
if (inventoryType == null) {
|
||||
return;
|
||||
}
|
||||
final ItemType itemType = ItemUtils.getItemType(itemStack);
|
||||
if (itemType != ItemType.SOULBOUND) {
|
||||
return;
|
||||
}
|
||||
if (!Config.getInstance().getAllowItemStoring() && !(inventoryType == InventoryType.CRAFTING)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
if (ItemUtils.isBindedPlayer(player, itemStack) || Permissions.pickupBypass(player)) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
SlotType slotType = event.getSlotType();
|
||||
InventoryType inventoryType = event.getInventory().getType();
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onInventoryMoveEvent(final InventoryMoveItemEvent event) {
|
||||
final ItemStack itemStack = event.getItem();
|
||||
final ItemType itemType = ItemUtils.getItemType(itemStack);
|
||||
if (itemType == ItemType.SOULBOUND) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (inventoryType == null) {
|
||||
return;
|
||||
}
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onInventoryOpen(final InventoryOpenEvent event) {
|
||||
final HumanEntity humanEntity = event.getPlayer();
|
||||
final Inventory inventory = event.getInventory();
|
||||
if (!(humanEntity instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
final Player player = (Player) humanEntity;
|
||||
for (final ItemStack itemStack : inventory.getContents()) {
|
||||
if (itemStack != null && ItemsConfig.getInstance().isActionItem(itemStack, ActionType.OPEN_CHEST)) {
|
||||
ItemUtils.soulbindItem(player, itemStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (itemStack == null) {
|
||||
return;
|
||||
}
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onInventoryPickupItemEvent(final InventoryPickupItemEvent event) {
|
||||
final ItemStack itemStack = event.getItem().getItemStack();
|
||||
final ItemType itemType = ItemUtils.getItemType(itemStack);
|
||||
if (itemType == ItemType.SOULBOUND) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (entity instanceof Player) {
|
||||
Player player = (Player) entity;
|
||||
switch (slotType) {
|
||||
case ARMOR:
|
||||
new UpdateArmorTask(player).runTaskLater(Soulbound.p, 2);
|
||||
return;
|
||||
case CONTAINER:
|
||||
ItemType itemType = ItemUtils.getItemType(itemStack);
|
||||
switch (itemType) {
|
||||
case BIND_ON_PICKUP:
|
||||
ItemUtils.soulbindItem(player, itemStack);
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
default:
|
||||
if (ItemUtils.isEquipable(itemStack) && event.isShiftClick()) {
|
||||
new UpdateArmorTask(player).runTaskLater(Soulbound.p, 2);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Check CraftItemEvent events.
|
||||
*
|
||||
* @param event
|
||||
* The event to check
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
private void onCraftItem(final CraftItemEvent event) {
|
||||
final HumanEntity humanEntity = event.getWhoClicked();
|
||||
if (!(humanEntity instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
final Player player = (Player) humanEntity;
|
||||
final ItemStack itemStack = event.getRecipe().getResult();
|
||||
if (ItemsConfig.getInstance().isActionItem(itemStack, ActionType.CRAFT)) {
|
||||
event.getInventory().setResult(ItemUtils.soulbindItem(player, itemStack));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onInventoryClickEvent(InventoryClickEvent event) {
|
||||
HumanEntity entity = event.getWhoClicked();
|
||||
/**
|
||||
* Check EnchantItemEvent events.
|
||||
*
|
||||
* @param event
|
||||
* The event to check
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
private void onEnchantItem(final EnchantItemEvent event) {
|
||||
final Player player = event.getEnchanter();
|
||||
final ItemStack itemStack = event.getItem();
|
||||
if (ItemUtils.isBindOnUse(itemStack)) {
|
||||
ItemUtils.soulbindItem(player, itemStack);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(entity instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) entity;
|
||||
ItemStack itemStack = event.getCurrentItem();
|
||||
InventoryType inventoryType = event.getInventory().getType();
|
||||
|
||||
if (inventoryType == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemType itemType = ItemUtils.getItemType(itemStack);
|
||||
|
||||
if (itemType != ItemType.SOULBOUND) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Config.getInstance().getAllowItemStoring() && !(inventoryType == InventoryType.CRAFTING)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
if (ItemUtils.isBindedPlayer(player, itemStack) || Permissions.pickupBypass(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onInventoryMoveEvent(InventoryMoveItemEvent event) {
|
||||
ItemStack itemStack = event.getItem();
|
||||
ItemType itemType = ItemUtils.getItemType(itemStack);
|
||||
|
||||
if (itemType == ItemType.SOULBOUND) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onInventoryPickupItemEvent(InventoryPickupItemEvent event) {
|
||||
ItemStack itemStack = event.getItem().getItemStack();
|
||||
ItemType itemType = ItemUtils.getItemType(itemStack);
|
||||
|
||||
if (itemType == ItemType.SOULBOUND) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onInventoryOpen(InventoryOpenEvent event) {
|
||||
HumanEntity humanEntity = event.getPlayer();
|
||||
Inventory inventory = event.getInventory();
|
||||
|
||||
if (!(humanEntity instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) humanEntity;
|
||||
|
||||
for (ItemStack itemStack : inventory.getContents()) {
|
||||
if (itemStack != null && ItemsConfig.getInstance().isActionItem(itemStack, ActionType.OPEN_CHEST)) {
|
||||
ItemUtils.soulbindItem(player, itemStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check CraftItemEvent events.
|
||||
*
|
||||
* @param event The event to check
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
private void onCraftItem(CraftItemEvent event) {
|
||||
HumanEntity humanEntity = event.getWhoClicked();
|
||||
|
||||
if (!(humanEntity instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) humanEntity;
|
||||
|
||||
ItemStack itemStack = event.getRecipe().getResult();
|
||||
|
||||
if (ItemsConfig.getInstance().isActionItem(itemStack, ActionType.CRAFT)) {
|
||||
event.getInventory().setResult(ItemUtils.soulbindItem(player, itemStack));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check EnchantItemEvent events.
|
||||
*
|
||||
* @param event The event to check
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
private void onEnchantItem(EnchantItemEvent event) {
|
||||
Player player = event.getEnchanter();
|
||||
ItemStack itemStack = event.getItem();
|
||||
|
||||
if (ItemUtils.isBindOnUse(itemStack)) {
|
||||
ItemUtils.soulbindItem(player, itemStack);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
void onInventoryClick(final InventoryClickEvent event) {
|
||||
final HumanEntity entity = event.getWhoClicked();
|
||||
final ItemStack itemStack = event.getCurrentItem();
|
||||
final SlotType slotType = event.getSlotType();
|
||||
final InventoryType inventoryType = event.getInventory().getType();
|
||||
if (inventoryType == null) {
|
||||
return;
|
||||
}
|
||||
if (itemStack == null) {
|
||||
return;
|
||||
}
|
||||
if (entity instanceof Player) {
|
||||
final Player player = (Player) entity;
|
||||
switch (slotType) {
|
||||
case ARMOR:
|
||||
new UpdateArmorTask(player).runTaskLater(Soulbound.p, 2);
|
||||
return;
|
||||
case CONTAINER:
|
||||
final ItemType itemType = ItemUtils.getItemType(itemStack);
|
||||
switch (itemType) {
|
||||
case BIND_ON_PICKUP:
|
||||
ItemUtils.soulbindItem(player, itemStack);
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
default:
|
||||
if (ItemUtils.isEquipable(itemStack) && event.isShiftClick()) {
|
||||
new UpdateArmorTask(player).runTaskLater(Soulbound.p, 2);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,118 +37,52 @@ import com.me.tft_02.soulbound.util.PlayerData;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
|
||||
@EventHandler(
|
||||
priority = EventPriority.LOWEST,
|
||||
ignoreCancelled = true)
|
||||
private void onItemPickup(PlayerPickupItemEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Item item = event.getItem();
|
||||
ItemStack itemStack = item.getItemStack();
|
||||
/**
|
||||
* Watch PlayerCommandPreprocessEvent events.
|
||||
*
|
||||
* @param event
|
||||
* The event to watch
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerCommand(final PlayerCommandPreprocessEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final ItemStack itemStack = player.getItemInHand();
|
||||
final String command = event.getMessage();
|
||||
|
||||
if (ItemUtils.isSoulbound(itemStack) && !ItemUtils.isBindedPlayer(player, itemStack)) {
|
||||
if (Permissions.pickupBypass(player)) {
|
||||
if (ItemUtils.isSoulbound(itemStack) && Config.getInstance().getBlockedCommands().contains(command)) {
|
||||
player.sendMessage(ChatColor.RED + "You're not allowed to use " + ChatColor.GOLD + command + ChatColor.RED + " command while holding a Soulbound item.");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitor PlayerCommandPreprocessEvent events.
|
||||
*
|
||||
* @param event
|
||||
* The event to monitor
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerCommandMonitor(final PlayerCommandPreprocessEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final ItemStack inHand = player.getItemInHand();
|
||||
final String command = event.getMessage();
|
||||
final String[] args = CommandUtils.extractArgs(command);
|
||||
if (!ItemUtils.isSoulbound(inHand) && Config.getInstance().getBindCommands().contains(command)) {
|
||||
ItemUtils.soulbindItem(player, inHand);
|
||||
return;
|
||||
}
|
||||
if (command.contains("kit")) {
|
||||
Player target;
|
||||
if (args.length >= 2) {
|
||||
target = Soulbound.p.getServer().getPlayer(args[1]);
|
||||
} else {
|
||||
target = player;
|
||||
}
|
||||
if (target == null) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
new SoulbindInventoryTask(target, ActionType.KIT).runTask(Soulbound.p);
|
||||
}
|
||||
|
||||
if (ItemUtils.isBindOnPickup(itemStack)) {
|
||||
ItemUtils.soulbindItem(player, itemStack);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ItemsConfig.getInstance().isActionItem(itemStack, ActionType.PICKUP_ITEM)) {
|
||||
ItemUtils.soulbindItem(player, itemStack);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(
|
||||
priority = EventPriority.HIGHEST,
|
||||
ignoreCancelled = true)
|
||||
private void onItemDrop(PlayerDropItemEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Item item = event.getItemDrop();
|
||||
ItemStack itemStack = item.getItemStack();
|
||||
|
||||
if (Config.getInstance().getPreventItemDrop()) {
|
||||
if (ItemUtils.isSoulbound(itemStack) && ItemUtils.isBindedPlayer(player, itemStack)) {
|
||||
item.setPickupDelay(2 * 20);
|
||||
event.setCancelled(true);
|
||||
new UpdateInventoryTask(player).runTask(Soulbound.p);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (Config.getInstance().getDeleteOnDrop()) {
|
||||
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F);
|
||||
event.getItemDrop().remove();
|
||||
return;
|
||||
}
|
||||
|
||||
if (ItemsConfig.getInstance().isActionItem(itemStack, ActionType.DROP_ITEM)) {
|
||||
ItemUtils.soulbindItem(player, itemStack);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(
|
||||
priority = EventPriority.HIGHEST,
|
||||
ignoreCancelled = true)
|
||||
private void onPlayerDeath(PlayerDeathEvent event) {
|
||||
Player player = event.getEntity();
|
||||
|
||||
boolean deleteOnDeath = Permissions.deleteOnDeath(player);
|
||||
boolean keepOnDeath = Permissions.keepOnDeath(player);
|
||||
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
|
||||
if (!keepOnDeath && !deleteOnDeath) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (ItemStack item : new ArrayList<ItemStack>(event.getDrops())) {
|
||||
if (ItemUtils.isSoulbound(item) && ItemUtils.isBindedPlayer(player, item)) {
|
||||
if (keepOnDeath) {
|
||||
items.add(item);
|
||||
event.getDrops().remove(item);
|
||||
} else if (deleteOnDeath) {
|
||||
event.getDrops().remove(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PlayerData.storeItemsDeath(player, items);
|
||||
}
|
||||
|
||||
@EventHandler(
|
||||
priority = EventPriority.NORMAL,
|
||||
ignoreCancelled = true)
|
||||
private void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
new SoulbindInventoryTask(event.getPlayer(), ActionType.RESPAWN).runTask(Soulbound.p);
|
||||
}
|
||||
|
||||
@EventHandler(
|
||||
priority = EventPriority.HIGHEST,
|
||||
ignoreCancelled = true)
|
||||
private void onPlayerRespawnHighest(PlayerRespawnEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
boolean keepOnDeath = Permissions.keepOnDeath(player);
|
||||
|
||||
if (!keepOnDeath) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
items = PlayerData.retrieveItemsDeath(player);
|
||||
if (items != null) {
|
||||
for (ItemStack item : items) {
|
||||
player.getInventory().addItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
new UpdateInventoryTask(player).runTask(Soulbound.p);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -157,13 +91,11 @@ public class PlayerListener implements Listener {
|
||||
* @param event
|
||||
* The event to watch
|
||||
*/
|
||||
@EventHandler(
|
||||
priority = EventPriority.LOW)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Action action = event.getAction();
|
||||
ItemStack inHand = player.getItemInHand();
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerInteract(final PlayerInteractEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final Action action = event.getAction();
|
||||
final ItemStack inHand = player.getItemInHand();
|
||||
switch (action) {
|
||||
case RIGHT_CLICK_BLOCK:
|
||||
case RIGHT_CLICK_AIR:
|
||||
@ -179,119 +111,139 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitor ServerCommandEvent events.
|
||||
*
|
||||
* @param event
|
||||
* The event to monitor
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onServerCommand(final ServerCommandEvent event) {
|
||||
final String command = event.getCommand();
|
||||
final String[] args = CommandUtils.extractArgs(command);
|
||||
if (!command.contains("kit")) {
|
||||
return;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
return;
|
||||
}
|
||||
final Player target = Soulbound.p.getServer().getPlayer(args[1]);
|
||||
new SoulbindInventoryTask(target, ActionType.KIT).runTask(Soulbound.p);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
private void onItemDrop(final PlayerDropItemEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final Item item = event.getItemDrop();
|
||||
final ItemStack itemStack = item.getItemStack();
|
||||
if (Config.getInstance().getPreventItemDrop()) {
|
||||
if (ItemUtils.isSoulbound(itemStack) && ItemUtils.isBindedPlayer(player, itemStack)) {
|
||||
item.setPickupDelay(2 * 20);
|
||||
event.setCancelled(true);
|
||||
new UpdateInventoryTask(player).runTask(Soulbound.p);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (Config.getInstance().getDeleteOnDrop()) {
|
||||
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F);
|
||||
event.getItemDrop().remove();
|
||||
return;
|
||||
}
|
||||
if (ItemsConfig.getInstance().isActionItem(itemStack, ActionType.DROP_ITEM)) {
|
||||
ItemUtils.soulbindItem(player, itemStack);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
private void onItemPickup(final PlayerPickupItemEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final Item item = event.getItem();
|
||||
final ItemStack itemStack = item.getItemStack();
|
||||
if (ItemUtils.isSoulbound(itemStack) && !ItemUtils.isBindedPlayer(player, itemStack)) {
|
||||
if (Permissions.pickupBypass(player)) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (ItemUtils.isBindOnPickup(itemStack)) {
|
||||
ItemUtils.soulbindItem(player, itemStack);
|
||||
return;
|
||||
}
|
||||
if (ItemsConfig.getInstance().isActionItem(itemStack, ActionType.PICKUP_ITEM)) {
|
||||
ItemUtils.soulbindItem(player, itemStack);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
private void onPlayerDeath(final PlayerDeathEvent event) {
|
||||
final Player player = event.getEntity();
|
||||
final boolean deleteOnDeath = Permissions.deleteOnDeath(player);
|
||||
final boolean keepOnDeath = Permissions.keepOnDeath(player);
|
||||
final List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
if (!keepOnDeath && !deleteOnDeath) {
|
||||
return;
|
||||
}
|
||||
for (final ItemStack item : new ArrayList<ItemStack>(event.getDrops())) {
|
||||
if (ItemUtils.isSoulbound(item) && ItemUtils.isBindedPlayer(player, item)) {
|
||||
if (keepOnDeath) {
|
||||
items.add(item);
|
||||
event.getDrops().remove(item);
|
||||
} else if (deleteOnDeath) {
|
||||
event.getDrops().remove(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
PlayerData.storeItemsDeath(player, items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitor PlayerFishEvent events.
|
||||
*
|
||||
* @param event
|
||||
* The event to monitor
|
||||
*/
|
||||
@EventHandler(
|
||||
priority = EventPriority.LOWEST,
|
||||
ignoreCancelled = true)
|
||||
private void onPlayerFish(PlayerFishEvent event) {
|
||||
ItemStack itemInHand = event.getPlayer().getItemInHand();
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
private void onPlayerFish(final PlayerFishEvent event) {
|
||||
final ItemStack itemInHand = event.getPlayer().getItemInHand();
|
||||
|
||||
DurabilityUtils.handleInfiniteDurability(itemInHand);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
private void onPlayerRespawn(final PlayerRespawnEvent event) {
|
||||
new SoulbindInventoryTask(event.getPlayer(), ActionType.RESPAWN).runTask(Soulbound.p);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
private void onPlayerRespawnHighest(final PlayerRespawnEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final boolean keepOnDeath = Permissions.keepOnDeath(player);
|
||||
if (!keepOnDeath) {
|
||||
return;
|
||||
}
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
items = PlayerData.retrieveItemsDeath(player);
|
||||
if (items != null) {
|
||||
for (final ItemStack item : items) {
|
||||
player.getInventory().addItem(item);
|
||||
}
|
||||
}
|
||||
new UpdateInventoryTask(player).runTask(Soulbound.p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitor PlayerShearEntityEvent events.
|
||||
*
|
||||
* @param event
|
||||
* The event to monitor
|
||||
*/
|
||||
@EventHandler(
|
||||
priority = EventPriority.LOWEST,
|
||||
ignoreCancelled = true)
|
||||
private void onPlayerShearEntity(PlayerShearEntityEvent event) {
|
||||
ItemStack itemInHand = event.getPlayer().getItemInHand();
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
private void onPlayerShearEntity(final PlayerShearEntityEvent event) {
|
||||
final ItemStack itemInHand = event.getPlayer().getItemInHand();
|
||||
|
||||
DurabilityUtils.handleInfiniteDurability(itemInHand);
|
||||
}
|
||||
|
||||
/**
|
||||
* Watch PlayerCommandPreprocessEvent events.
|
||||
*
|
||||
* @param event
|
||||
* The event to watch
|
||||
*/
|
||||
@EventHandler(
|
||||
priority = EventPriority.NORMAL,
|
||||
ignoreCancelled = true)
|
||||
public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
ItemStack itemStack = player.getItemInHand();
|
||||
String command = event.getMessage();
|
||||
|
||||
if (ItemUtils.isSoulbound(itemStack)
|
||||
&& Config.getInstance().getBlockedCommands().contains(command)) {
|
||||
player.sendMessage(ChatColor.RED + "You're not allowed to use " + ChatColor.GOLD
|
||||
+ command + ChatColor.RED + " command while holding a Soulbound item.");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitor PlayerCommandPreprocessEvent events.
|
||||
*
|
||||
* @param event
|
||||
* The event to monitor
|
||||
*/
|
||||
@EventHandler(
|
||||
priority = EventPriority.MONITOR,
|
||||
ignoreCancelled = true)
|
||||
public void onPlayerCommandMonitor(PlayerCommandPreprocessEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
ItemStack inHand = player.getItemInHand();
|
||||
String command = event.getMessage();
|
||||
String[] args = CommandUtils.extractArgs(command);
|
||||
|
||||
if (!ItemUtils.isSoulbound(inHand)
|
||||
&& Config.getInstance().getBindCommands().contains(command)) {
|
||||
ItemUtils.soulbindItem(player, inHand);
|
||||
return;
|
||||
}
|
||||
|
||||
if (command.contains("kit")) {
|
||||
Player target;
|
||||
|
||||
if (args.length >= 2) {
|
||||
target = Soulbound.p.getServer().getPlayer(args[1]);
|
||||
} else {
|
||||
target = player;
|
||||
}
|
||||
|
||||
if (target == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
new SoulbindInventoryTask(target, ActionType.KIT).runTask(Soulbound.p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitor ServerCommandEvent events.
|
||||
*
|
||||
* @param event
|
||||
* The event to monitor
|
||||
*/
|
||||
@EventHandler(
|
||||
priority = EventPriority.MONITOR,
|
||||
ignoreCancelled = true)
|
||||
public void onServerCommand(ServerCommandEvent event) {
|
||||
String command = event.getCommand();
|
||||
String[] args = CommandUtils.extractArgs(command);
|
||||
|
||||
if (!command.contains("kit")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player target = Soulbound.p.getServer().getPlayer(args[1]);
|
||||
|
||||
new SoulbindInventoryTask(target, ActionType.KIT).runTask(Soulbound.p);
|
||||
}
|
||||
}
|
||||
|
@ -14,25 +14,23 @@ import com.me.tft_02.soulbound.util.Permissions;
|
||||
|
||||
public class SelfListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
private void onItemSoulbound(SoulbindItemEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Inventory inventory = player.getInventory();
|
||||
int maxAmount = Permissions.getSoulbindMaximum(player);
|
||||
|
||||
if (maxAmount < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for (ItemStack itemStack : inventory.getContents()) {
|
||||
if (itemStack != null && ItemUtils.isSoulbound(itemStack)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count >= maxAmount) {
|
||||
player.sendMessage(ChatColor.RED + "Cannot Soulbind any more items, maximum amount reached! " + ChatColor.GOLD + "(" + maxAmount + ")");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
private void onItemSoulbound(final SoulbindItemEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final Inventory inventory = player.getInventory();
|
||||
final int maxAmount = Permissions.getSoulbindMaximum(player);
|
||||
if (maxAmount < 0) {
|
||||
return;
|
||||
}
|
||||
int count = 0;
|
||||
for (final ItemStack itemStack : inventory.getContents()) {
|
||||
if (itemStack != null && ItemUtils.isSoulbound(itemStack)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count >= maxAmount) {
|
||||
player.sendMessage(ChatColor.RED + "Cannot Soulbind any more items, maximum amount reached! " + ChatColor.GOLD + "(" + maxAmount + ")");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,32 +9,29 @@ import org.bukkit.inventory.ItemStack;
|
||||
import com.me.tft_02.soulbound.Soulbound;
|
||||
|
||||
public class PlayerData {
|
||||
Soulbound plugin;
|
||||
public static HashMap<String, List<ItemStack>> playerSoulboundItems = new HashMap<String, List<ItemStack>>();
|
||||
|
||||
public PlayerData(Soulbound instance) {
|
||||
plugin = instance;
|
||||
}
|
||||
Soulbound plugin;
|
||||
|
||||
public static HashMap<String, List<ItemStack>> playerSoulboundItems = new HashMap<String, List<ItemStack>>();
|
||||
public PlayerData(final Soulbound instance) {
|
||||
plugin = instance;
|
||||
}
|
||||
|
||||
public static void storeItemsDeath(Player player, List<ItemStack> items) {
|
||||
String playerName = player.getName();
|
||||
public static List<ItemStack> retrieveItemsDeath(final Player player) {
|
||||
final String playerName = player.getName();
|
||||
|
||||
if (playerSoulboundItems.containsKey(playerName)) {
|
||||
playerSoulboundItems.put(playerName, null);
|
||||
}
|
||||
if (playerSoulboundItems.containsKey(playerName)) {
|
||||
return playerSoulboundItems.get(playerName);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
playerSoulboundItems.put(playerName, items);
|
||||
}
|
||||
|
||||
public static List<ItemStack> retrieveItemsDeath(Player player) {
|
||||
String playerName = player.getName();
|
||||
|
||||
if (playerSoulboundItems.containsKey(playerName)) {
|
||||
return playerSoulboundItems.get(playerName);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static void storeItemsDeath(final Player player, final List<ItemStack> items) {
|
||||
final String playerName = player.getName();
|
||||
if (playerSoulboundItems.containsKey(playerName)) {
|
||||
playerSoulboundItems.put(playerName, null);
|
||||
}
|
||||
playerSoulboundItems.put(playerName, items);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user