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:
parent
ae50ac1251
commit
48e71f0b55
@ -11,9 +11,8 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,62 +19,58 @@ 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)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onEntityDeath(EntityDamageByEntityEvent event) {
|
public void onEntityDeath(final EntityDamageByEntityEvent event) {
|
||||||
if (event.getDamage() == 0 || event.getEntity().isDead()) {
|
if (event.getDamage() == 0 || event.getEntity().isDead()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.getEntity() instanceof LivingEntity) {
|
if (event.getEntity() instanceof LivingEntity) {
|
||||||
combatChecks(event);
|
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;
|
||||||
|
|
||||||
|
for (final ItemStack itemStack : player.getInventory().getArmorContents()) {
|
||||||
|
DurabilityUtils.handleInfiniteDurability(itemStack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply combat modifiers
|
* Apply combat modifiers
|
||||||
*
|
*
|
||||||
* @param event The event to run the combat checks on.
|
* @param event
|
||||||
|
* The event to run the combat checks on.
|
||||||
*/
|
*/
|
||||||
void combatChecks(EntityDamageByEntityEvent event) {
|
void combatChecks(final EntityDamageByEntityEvent event) {
|
||||||
Entity damager = event.getDamager();
|
final Entity damager = event.getDamager();
|
||||||
EntityType damagerType = damager.getType();
|
final EntityType damagerType = damager.getType();
|
||||||
|
|
||||||
switch (damagerType) {
|
switch (damagerType) {
|
||||||
case PLAYER:
|
case PLAYER:
|
||||||
Player attacker = (Player) event.getDamager();
|
final Player attacker = (Player) event.getDamager();
|
||||||
ItemStack itemInHand = attacker.getItemInHand();
|
final ItemStack itemInHand = attacker.getItemInHand();
|
||||||
|
|
||||||
DurabilityUtils.handleInfiniteDurability(itemInHand);
|
DurabilityUtils.handleInfiniteDurability(itemInHand);
|
||||||
default:
|
default:
|
||||||
return;
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -27,30 +27,119 @@ 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;
|
||||||
SlotType slotType = event.getSlotType();
|
}
|
||||||
InventoryType inventoryType = event.getInventory().getType();
|
final Player player = (Player) entity;
|
||||||
|
final ItemStack itemStack = event.getCurrentItem();
|
||||||
|
final InventoryType inventoryType = event.getInventory().getType();
|
||||||
if (inventoryType == null) {
|
if (inventoryType == null) {
|
||||||
return;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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) {
|
if (itemStack == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entity instanceof Player) {
|
if (entity instanceof Player) {
|
||||||
Player player = (Player) entity;
|
final Player player = (Player) entity;
|
||||||
switch (slotType) {
|
switch (slotType) {
|
||||||
case ARMOR:
|
case ARMOR:
|
||||||
new UpdateArmorTask(player).runTaskLater(Soulbound.p, 2);
|
new UpdateArmorTask(player).runTaskLater(Soulbound.p, 2);
|
||||||
return;
|
return;
|
||||||
case CONTAINER:
|
case CONTAINER:
|
||||||
ItemType itemType = ItemUtils.getItemType(itemStack);
|
final ItemType itemType = ItemUtils.getItemType(itemStack);
|
||||||
switch (itemType) {
|
switch (itemType) {
|
||||||
case BIND_ON_PICKUP:
|
case BIND_ON_PICKUP:
|
||||||
ItemUtils.soulbindItem(player, itemStack);
|
ItemUtils.soulbindItem(player, itemStack);
|
||||||
@ -67,113 +156,4 @@ public class InventoryListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
|
||||||
public void onInventoryClickEvent(InventoryClickEvent event) {
|
|
||||||
HumanEntity entity = event.getWhoClicked();
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -37,133 +37,65 @@ 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.");
|
||||||
return;
|
|
||||||
}
|
|
||||||
event.setCancelled(true);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
if (command.contains("kit")) {
|
||||||
if (ItemUtils.isBindOnPickup(itemStack)) {
|
Player target;
|
||||||
ItemUtils.soulbindItem(player, itemStack);
|
if (args.length >= 2) {
|
||||||
|
target = Soulbound.p.getServer().getPlayer(args[1]);
|
||||||
|
} else {
|
||||||
|
target = player;
|
||||||
|
}
|
||||||
|
if (target == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
new SoulbindInventoryTask(target, ActionType.KIT).runTask(Soulbound.p);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Watch PlayerInteract events.
|
* Watch PlayerInteract events.
|
||||||
*
|
*
|
||||||
* @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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -15,17 +15,15 @@ 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;
|
int count = 0;
|
||||||
for (ItemStack itemStack : inventory.getContents()) {
|
for (final ItemStack itemStack : inventory.getContents()) {
|
||||||
if (itemStack != null && ItemUtils.isSoulbound(itemStack)) {
|
if (itemStack != null && ItemUtils.isSoulbound(itemStack)) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
||||||
|
public static HashMap<String, List<ItemStack>> playerSoulboundItems = new HashMap<String, List<ItemStack>>();
|
||||||
|
|
||||||
Soulbound plugin;
|
Soulbound plugin;
|
||||||
|
|
||||||
public PlayerData(Soulbound instance) {
|
public PlayerData(final Soulbound instance) {
|
||||||
plugin = instance;
|
plugin = instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HashMap<String, List<ItemStack>> playerSoulboundItems = new HashMap<String, List<ItemStack>>();
|
public static List<ItemStack> retrieveItemsDeath(final Player player) {
|
||||||
|
final String playerName = player.getName();
|
||||||
public static void storeItemsDeath(Player player, List<ItemStack> items) {
|
|
||||||
String playerName = player.getName();
|
|
||||||
|
|
||||||
if (playerSoulboundItems.containsKey(playerName)) {
|
|
||||||
playerSoulboundItems.put(playerName, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
playerSoulboundItems.put(playerName, items);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<ItemStack> retrieveItemsDeath(Player player) {
|
|
||||||
String playerName = player.getName();
|
|
||||||
|
|
||||||
if (playerSoulboundItems.containsKey(playerName)) {
|
if (playerSoulboundItems.containsKey(playerName)) {
|
||||||
return playerSoulboundItems.get(playerName);
|
return playerSoulboundItems.get(playerName);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return null;
|
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