1
0
mirror of https://e.coding.net/circlecloud/Soulbound.git synced 2024-11-22 01:49:09 +00:00

update project...

Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
j502647092 2015-09-28 23:02:17 +08:00
parent ae50ac1251
commit 48e71f0b55
6 changed files with 383 additions and 461 deletions

View File

@ -10,10 +10,9 @@ import com.me.tft_02.soulbound.util.DurabilityUtils;
public class BlockListener implements Listener { public class BlockListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) { public void onBlockBreak(final BlockBreakEvent event) {
ItemStack itemStack = event.getPlayer().getItemInHand(); final ItemStack itemStack = event.getPlayer().getItemInHand();
DurabilityUtils.handleInfiniteDurability(itemStack);
DurabilityUtils.handleInfiniteDurability(itemStack); }
}
} }

View File

@ -16,65 +16,61 @@ import com.me.tft_02.soulbound.util.DurabilityUtils;
public class EntityListener implements Listener { public class EntityListener implements Listener {
/** /**
* Check EntityDamageByEntityEvent events. * Check EntityDamageByEntityEvent events.
* *
* @param event The event to check * @param event
*/ * The event to check
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) */
public void onEntityDeath(EntityDamageByEntityEvent event) { @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
if (event.getDamage() == 0 || event.getEntity().isDead()) { public void onEntityDeath(final EntityDamageByEntityEvent event) {
return; if (event.getDamage() == 0 || event.getEntity().isDead()) {
} return;
}
if (event.getEntity() instanceof LivingEntity) {
combatChecks(event);
}
}
if (event.getEntity() instanceof LivingEntity) { @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
combatChecks(event); 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;
/** for (final ItemStack itemStack : player.getInventory().getArmorContents()) {
* Apply combat modifiers DurabilityUtils.handleInfiniteDurability(itemStack);
* }
* @param event The event to run the combat checks on. }
*/ }
void combatChecks(EntityDamageByEntityEvent event) {
Entity damager = event.getDamager();
EntityType damagerType = damager.getType();
switch (damagerType) { @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
case PLAYER: private void onEntityShootBow(final EntityShootBowEvent event) {
Player attacker = (Player) event.getDamager(); final Entity entity = event.getEntity();
ItemStack itemInHand = attacker.getItemInHand(); if (entity instanceof Player) {
DurabilityUtils.handleInfiniteDurability(((Player) entity).getItemInHand());
}
}
DurabilityUtils.handleInfiniteDurability(itemInHand); /**
default: * Apply combat modifiers
return; *
} * @param event
} * The event to run the combat checks on.
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) void combatChecks(final EntityDamageByEntityEvent event) {
private void onEntityShootBow(EntityShootBowEvent event) { final Entity damager = event.getDamager();
Entity entity = event.getEntity(); final EntityType damagerType = damager.getType();
switch (damagerType) {
if (entity instanceof Player) { case PLAYER:
DurabilityUtils.handleInfiniteDurability(((Player) entity).getItemInHand()); final Player attacker = (Player) event.getDamager();
} final ItemStack itemInHand = attacker.getItemInHand();
} DurabilityUtils.handleInfiniteDurability(itemInHand);
default:
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) return;
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);
}
}
}
} }

View File

@ -27,153 +27,133 @@ import com.me.tft_02.soulbound.util.Permissions;
public class InventoryListener implements Listener { public class InventoryListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
void onInventoryClick(InventoryClickEvent event) { public void onInventoryClickEvent(final InventoryClickEvent event) {
HumanEntity entity = event.getWhoClicked(); final HumanEntity entity = event.getWhoClicked();
ItemStack itemStack = event.getCurrentItem(); 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(); @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
InventoryType inventoryType = event.getInventory().getType(); 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) { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
return; 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) { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
return; 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; * Check CraftItemEvent events.
switch (slotType) { *
case ARMOR: * @param event
new UpdateArmorTask(player).runTaskLater(Soulbound.p, 2); * The event to check
return; */
case CONTAINER: @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
ItemType itemType = ItemUtils.getItemType(itemStack); private void onCraftItem(final CraftItemEvent event) {
switch (itemType) { final HumanEntity humanEntity = event.getWhoClicked();
case BIND_ON_PICKUP: if (!(humanEntity instanceof Player)) {
ItemUtils.soulbindItem(player, itemStack); return;
return; }
default: final Player player = (Player) humanEntity;
return; final ItemStack itemStack = event.getRecipe().getResult();
} if (ItemsConfig.getInstance().isActionItem(itemStack, ActionType.CRAFT)) {
default: event.getInventory().setResult(ItemUtils.soulbindItem(player, itemStack));
if (ItemUtils.isEquipable(itemStack) && event.isShiftClick()) { }
new UpdateArmorTask(player).runTaskLater(Soulbound.p, 2); }
return;
}
break;
}
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) /**
public void onInventoryClickEvent(InventoryClickEvent event) { * Check EnchantItemEvent events.
HumanEntity entity = event.getWhoClicked(); *
* @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)) { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
return; void onInventoryClick(final InventoryClickEvent event) {
} final HumanEntity entity = event.getWhoClicked();
final ItemStack itemStack = event.getCurrentItem();
Player player = (Player) entity; final SlotType slotType = event.getSlotType();
ItemStack itemStack = event.getCurrentItem(); final InventoryType inventoryType = event.getInventory().getType();
InventoryType inventoryType = event.getInventory().getType(); if (inventoryType == null) {
return;
if (inventoryType == null) { }
return; if (itemStack == null) {
} return;
}
ItemType itemType = ItemUtils.getItemType(itemStack); if (entity instanceof Player) {
final Player player = (Player) entity;
if (itemType != ItemType.SOULBOUND) { switch (slotType) {
return; case ARMOR:
} new UpdateArmorTask(player).runTaskLater(Soulbound.p, 2);
return;
if (!Config.getInstance().getAllowItemStoring() && !(inventoryType == InventoryType.CRAFTING)) { case CONTAINER:
event.setCancelled(true); final ItemType itemType = ItemUtils.getItemType(itemStack);
} switch (itemType) {
case BIND_ON_PICKUP:
if (ItemUtils.isBindedPlayer(player, itemStack) || Permissions.pickupBypass(player)) { ItemUtils.soulbindItem(player, itemStack);
return; return;
} default:
return;
event.setCancelled(true); }
} default:
if (ItemUtils.isEquipable(itemStack) && event.isShiftClick()) {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) new UpdateArmorTask(player).runTaskLater(Soulbound.p, 2);
public void onInventoryMoveEvent(InventoryMoveItemEvent event) { return;
ItemStack itemStack = event.getItem(); }
ItemType itemType = ItemUtils.getItemType(itemStack); break;
}
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;
}
}
} }

View File

@ -37,118 +37,52 @@ import com.me.tft_02.soulbound.util.PlayerData;
public class PlayerListener implements Listener { public class PlayerListener implements Listener {
@EventHandler( /**
priority = EventPriority.LOWEST, * Watch PlayerCommandPreprocessEvent events.
ignoreCancelled = true) *
private void onItemPickup(PlayerPickupItemEvent event) { * @param event
Player player = event.getPlayer(); * The event to watch
Item item = event.getItem(); */
ItemStack itemStack = item.getItemStack(); @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 (ItemUtils.isSoulbound(itemStack) && Config.getInstance().getBlockedCommands().contains(command)) {
if (Permissions.pickupBypass(player)) { 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; return;
} }
event.setCancelled(true); new SoulbindInventoryTask(target, ActionType.KIT).runTask(Soulbound.p);
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 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 * @param event
* The event to watch * The event to watch
*/ */
@EventHandler( @EventHandler(priority = EventPriority.LOW)
priority = EventPriority.LOW) public void onPlayerInteract(final PlayerInteractEvent event) {
public void onPlayerInteract(PlayerInteractEvent event) { final Player player = event.getPlayer();
Player player = event.getPlayer(); final Action action = event.getAction();
Action action = event.getAction(); final ItemStack inHand = player.getItemInHand();
ItemStack inHand = player.getItemInHand();
switch (action) { switch (action) {
case RIGHT_CLICK_BLOCK: case RIGHT_CLICK_BLOCK:
case RIGHT_CLICK_AIR: 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. * Monitor PlayerFishEvent events.
* *
* @param event * @param event
* The event to monitor * The event to monitor
*/ */
@EventHandler( @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
priority = EventPriority.LOWEST, private void onPlayerFish(final PlayerFishEvent event) {
ignoreCancelled = true) final ItemStack itemInHand = event.getPlayer().getItemInHand();
private void onPlayerFish(PlayerFishEvent event) {
ItemStack itemInHand = event.getPlayer().getItemInHand();
DurabilityUtils.handleInfiniteDurability(itemInHand); 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. * Monitor PlayerShearEntityEvent events.
* *
* @param event * @param event
* The event to monitor * The event to monitor
*/ */
@EventHandler( @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
priority = EventPriority.LOWEST, private void onPlayerShearEntity(final PlayerShearEntityEvent event) {
ignoreCancelled = true) final ItemStack itemInHand = event.getPlayer().getItemInHand();
private void onPlayerShearEntity(PlayerShearEntityEvent event) {
ItemStack itemInHand = event.getPlayer().getItemInHand();
DurabilityUtils.handleInfiniteDurability(itemInHand); 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);
}
} }

View File

@ -14,25 +14,23 @@ import com.me.tft_02.soulbound.util.Permissions;
public class SelfListener implements Listener { public class SelfListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onItemSoulbound(SoulbindItemEvent event) { private void onItemSoulbound(final SoulbindItemEvent event) {
Player player = event.getPlayer(); final Player player = event.getPlayer();
Inventory inventory = player.getInventory(); final Inventory inventory = player.getInventory();
int maxAmount = Permissions.getSoulbindMaximum(player); final int maxAmount = Permissions.getSoulbindMaximum(player);
if (maxAmount < 0) {
if (maxAmount < 0) { return;
return; }
} int count = 0;
for (final ItemStack itemStack : inventory.getContents()) {
int count = 0; if (itemStack != null && ItemUtils.isSoulbound(itemStack)) {
for (ItemStack itemStack : inventory.getContents()) { count++;
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 + ")");
if (count >= maxAmount) { event.setCancelled(true);
player.sendMessage(ChatColor.RED + "Cannot Soulbind any more items, maximum amount reached! " + ChatColor.GOLD + "(" + maxAmount + ")"); }
event.setCancelled(true); }
}
}
} }

View File

@ -9,32 +9,29 @@ import org.bukkit.inventory.ItemStack;
import com.me.tft_02.soulbound.Soulbound; import com.me.tft_02.soulbound.Soulbound;
public class PlayerData { public class PlayerData {
Soulbound plugin; public static HashMap<String, List<ItemStack>> playerSoulboundItems = new HashMap<String, List<ItemStack>>();
public PlayerData(Soulbound instance) { Soulbound plugin;
plugin = instance;
}
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) { public static List<ItemStack> retrieveItemsDeath(final Player player) {
String playerName = player.getName(); final String playerName = player.getName();
if (playerSoulboundItems.containsKey(playerName)) { if (playerSoulboundItems.containsKey(playerName)) {
playerSoulboundItems.put(playerName, null); return playerSoulboundItems.get(playerName);
} } else {
return null;
}
}
playerSoulboundItems.put(playerName, items); public static void storeItemsDeath(final Player player, final List<ItemStack> items) {
} final String playerName = player.getName();
if (playerSoulboundItems.containsKey(playerName)) {
public static List<ItemStack> retrieveItemsDeath(Player player) { playerSoulboundItems.put(playerName, null);
String playerName = player.getName(); }
playerSoulboundItems.put(playerName, items);
if (playerSoulboundItems.containsKey(playerName)) { }
return playerSoulboundItems.get(playerName);
}
else {
return null;
}
}
} }