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

修复Prevent_Item_Drop设置为TRUE时死亡物品消失的问题...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092 2015-12-09 16:27:09 +08:00
parent 6195f57d62
commit a51e7638c5
3 changed files with 194 additions and 220 deletions

17
pom.xml
View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.me.tft_02.soulbound</groupId> <groupId>com.me.tft_02.soulbound</groupId>
<artifactId>Soulbound</artifactId> <artifactId>Soulbound</artifactId>
<version>1.2</version> <version>1.3</version>
<name>Soulbound</name> <name>Soulbound</name>
<description>Soulbound items for your RPG servers!</description> <description>Soulbound items for your RPG servers!</description>
<url>https://github.com/TfT-02/Soulbound</url> <url>https://github.com/TfT-02/Soulbound</url>
@ -60,21 +60,18 @@
</build> </build>
<properties> <properties>
<jenkins.url>http://ci.citycraft.cn:8080</jenkins.url> <jenkins.url>http://ci.citycraft.cn:8080</jenkins.url>
<update.description>&amp;c修复自动获取版本错误...</update.description> <env.BUILD_NUMBER>Debug</env.BUILD_NUMBER>
<update.description>&amp;c修复Prevent_Item_Drop设置为TRUE时死亡物品消失的问题...</update.description>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<repositories> <repositories>
<repository> <repository>
<id>mengcraft-repo</id> <id>spigot-repo</id>
<url>http://ci.mengcraft.com:8080/plugin/repository/everything/</url> <url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository> </repository>
<repository> <repository>
<id>citycraft-repo</id> <id>citycraft-repo</id>
<url>http://ci.citycraft.cn:8800/jenkins/plugin/repository/everything/</url> <url>${jenkins.url}/plugin/repository/everything/</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository> </repository>
</repositories> </repositories>
<dependencies> <dependencies>
@ -82,7 +79,7 @@
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<type>jar</type> <type>jar</type>
<version>1.8.3-R0.1-SNAPSHOT</version> <version>1.8.8-R0.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>cn.citycraft</groupId> <groupId>cn.citycraft</groupId>

View File

@ -37,213 +37,200 @@ import com.me.tft_02.soulbound.util.PlayerData;
public class PlayerListener implements Listener { public class PlayerListener implements Listener {
/** /**
* Watch PlayerCommandPreprocessEvent events. * Watch PlayerCommandPreprocessEvent events.
* *
* @param event * @param event The event to watch
* The event to watch */
*/ @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onPlayerCommand(final PlayerCommandPreprocessEvent event) {
public void onPlayerCommand(final PlayerCommandPreprocessEvent event) { final Player player = event.getPlayer();
final Player player = event.getPlayer(); final ItemStack itemStack = player.getItemInHand();
final ItemStack itemStack = player.getItemInHand(); final String command = event.getMessage();
final String command = event.getMessage();
if (ItemUtils.isSoulbound(itemStack) && Config.getBlockedCommands().contains(command)) { if (ItemUtils.isSoulbound(itemStack) && Config.getBlockedCommands().contains(command)) {
player.sendMessage(ChatColor.RED + "不允许使用命令 " + ChatColor.GOLD + command + ChatColor.RED + " 当拿着绑定物品的时候."); player.sendMessage(ChatColor.RED + "不允许使用命令 " + ChatColor.GOLD + command + ChatColor.RED + " 当拿着绑定物品的时候.");
event.setCancelled(true); event.setCancelled(true);
} }
} }
/** /**
* Monitor PlayerCommandPreprocessEvent events. * Monitor PlayerCommandPreprocessEvent events.
* *
* @param event * @param event The event to monitor
* The event to monitor */
*/ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerCommandMonitor(final PlayerCommandPreprocessEvent event) {
public void onPlayerCommandMonitor(final PlayerCommandPreprocessEvent event) { final Player player = event.getPlayer();
final Player player = event.getPlayer(); final ItemStack inHand = player.getItemInHand();
final ItemStack inHand = player.getItemInHand(); final String command = event.getMessage();
final String command = event.getMessage(); final String[] args = CommandUtils.extractArgs(command);
final String[] args = CommandUtils.extractArgs(command); if (!ItemUtils.isSoulbound(inHand) && Config.getBindCommands().contains(command)) {
if (!ItemUtils.isSoulbound(inHand) && Config.getBindCommands().contains(command)) { ItemUtils.soulbindItem(player, inHand);
ItemUtils.soulbindItem(player, inHand); return;
return; }
} if (command.contains("kit")) {
if (command.contains("kit")) { Player target;
Player target; if (args.length >= 2) {
if (args.length >= 2) { target = Soulbound.p.getServer().getPlayer(args[1]);
target = Soulbound.p.getServer().getPlayer(args[1]); } else {
} else { target = player;
target = player; }
} if (target == null) {
if (target == null) { return;
return; }
} new SoulbindInventoryTask(target, ActionType.KIT).runTask(Soulbound.p);
new SoulbindInventoryTask(target, ActionType.KIT).runTask(Soulbound.p); }
} }
}
/** /**
* Watch PlayerInteract events. * Watch PlayerInteract events.
* *
* @param event * @param event The event to watch
* The event to watch */
*/ @EventHandler(priority = EventPriority.LOW)
@EventHandler(priority = EventPriority.LOW) public void onPlayerInteract(final PlayerInteractEvent event) {
public void onPlayerInteract(final PlayerInteractEvent event) { final Player player = event.getPlayer();
final Player player = event.getPlayer(); final Action action = event.getAction();
final Action action = event.getAction(); final ItemStack inHand = player.getItemInHand();
final ItemStack inHand = player.getItemInHand(); switch (action) {
switch (action) { case RIGHT_CLICK_BLOCK:
case RIGHT_CLICK_BLOCK: case RIGHT_CLICK_AIR:
case RIGHT_CLICK_AIR: case LEFT_CLICK_AIR:
case LEFT_CLICK_AIR: case LEFT_CLICK_BLOCK:
case LEFT_CLICK_BLOCK: if (ItemUtils.isEquipable(inHand)) {
if (ItemUtils.isEquipable(inHand)) { new UpdateArmorTask(player).runTaskLater(Soulbound.p, 2);
new UpdateArmorTask(player).runTaskLater(Soulbound.p, 2); } else if (ItemUtils.isBindOnUse(inHand)) {
} else if (ItemUtils.isBindOnUse(inHand)) { ItemUtils.soulbindItem(player, inHand);
ItemUtils.soulbindItem(player, inHand); }
} default:
default: break;
break; }
} }
}
/** /**
* Monitor ServerCommandEvent events. * Monitor ServerCommandEvent events.
* *
* @param event * @param event The event to monitor
* The event to monitor */
*/ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onServerCommand(final ServerCommandEvent event) {
public void onServerCommand(final ServerCommandEvent event) { final String command = event.getCommand();
final String command = event.getCommand(); final String[] args = CommandUtils.extractArgs(command);
final String[] args = CommandUtils.extractArgs(command); if (!command.contains("kit")) {
if (!command.contains("kit")) { return;
return; }
} if (args.length < 2) {
if (args.length < 2) { return;
return; }
} final Player target = Soulbound.p.getServer().getPlayer(args[1]);
final Player target = Soulbound.p.getServer().getPlayer(args[1]); new SoulbindInventoryTask(target, ActionType.KIT).runTask(Soulbound.p);
new SoulbindInventoryTask(target, ActionType.KIT).runTask(Soulbound.p); }
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onItemDrop(final PlayerDropItemEvent event) { public void onItemDrop(final PlayerDropItemEvent event) {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final Item item = event.getItemDrop(); if (!player.isValid()) {
final ItemStack itemStack = item.getItemStack(); return;
if (Config.getPreventItemDrop()) { }
if (ItemUtils.isSoulbound(itemStack) && ItemUtils.isBindedPlayer(player, itemStack)) { final Item item = event.getItemDrop();
item.setPickupDelay(2 * 20); final ItemStack itemStack = item.getItemStack();
event.setCancelled(true); if (Config.getPreventItemDrop()) {
new UpdateInventoryTask(player).runTask(Soulbound.p); if (ItemUtils.isSoulbound(itemStack) && ItemUtils.isBindedPlayer(player, itemStack)) {
} item.setPickupDelay(2 * 20);
return; event.setCancelled(true);
} new UpdateInventoryTask(player).runTask(Soulbound.p);
if (Config.getDeleteOnDrop()) { }
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F); return;
event.getItemDrop().remove(); }
return; if (Config.getDeleteOnDrop()) {
} player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F);
if (ItemsConfig.isActionItem(itemStack, ActionType.DROP_ITEM)) { event.getItemDrop().remove();
ItemUtils.soulbindItem(player, itemStack); return;
return; }
} if (ItemsConfig.isActionItem(itemStack, ActionType.DROP_ITEM)) {
} ItemUtils.soulbindItem(player, itemStack);
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
private void onItemPickup(final PlayerPickupItemEvent event) { public void onItemPickup(final PlayerPickupItemEvent event) {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final Item item = event.getItem(); final Item item = event.getItem();
final ItemStack itemStack = item.getItemStack(); final ItemStack itemStack = item.getItemStack();
if (ItemUtils.isSoulbound(itemStack) && !ItemUtils.isBindedPlayer(player, itemStack)) { if (ItemUtils.isSoulbound(itemStack) && !ItemUtils.isBindedPlayer(player, itemStack)) {
if (Permissions.pickupBypass(player)) { if (Permissions.pickupBypass(player)) {
return; return;
} }
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (ItemUtils.isBindOnPickup(itemStack)) { if (ItemUtils.isBindOnPickup(itemStack)) {
ItemUtils.soulbindItem(player, itemStack); ItemUtils.soulbindItem(player, itemStack);
return; return;
} }
if (ItemsConfig.isActionItem(itemStack, ActionType.PICKUP_ITEM)) { if (ItemsConfig.isActionItem(itemStack, ActionType.PICKUP_ITEM)) {
ItemUtils.soulbindItem(player, itemStack); ItemUtils.soulbindItem(player, itemStack);
return; }
} }
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onPlayerDeath(final PlayerDeathEvent event) { public void onPlayerDeath(final PlayerDeathEvent event) {
final Player player = event.getEntity(); final Player player = event.getEntity();
final boolean deleteOnDeath = Permissions.deleteOnDeath(player); final boolean deleteOnDeath = Permissions.deleteOnDeath(player);
final boolean keepOnDeath = Permissions.keepOnDeath(player); final boolean keepOnDeath = Permissions.keepOnDeath(player);
final List<ItemStack> items = new ArrayList<ItemStack>(); final List<ItemStack> items = new ArrayList<>();
if (!keepOnDeath && !deleteOnDeath) { if (!keepOnDeath && !deleteOnDeath) {
return; return;
} }
for (final ItemStack item : new ArrayList<ItemStack>(event.getDrops())) { for (final ItemStack item : new ArrayList<>(event.getDrops())) {
if (ItemUtils.isSoulbound(item) && ItemUtils.isBindedPlayer(player, item)) { if (ItemUtils.isSoulbound(item) && ItemUtils.isBindedPlayer(player, item)) {
if (keepOnDeath) { if (keepOnDeath) {
items.add(item); items.add(item);
event.getDrops().remove(item); }
} else if (deleteOnDeath) { event.getDrops().remove(item);
event.getDrops().remove(item); }
} }
} PlayerData.storeItemsDeath(player, items);
} }
PlayerData.storeItemsDeath(player, items);
}
/** /**
* Monitor PlayerFishEvent events. * Monitor PlayerFishEvent events.
* *
* @param event * @param event The event to monitor
* The event to monitor */
*/ @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onPlayerFish(final PlayerFishEvent event) {
private void onPlayerFish(final PlayerFishEvent event) { final ItemStack itemInHand = event.getPlayer().getItemInHand();
final ItemStack itemInHand = event.getPlayer().getItemInHand(); DurabilityUtils.handleInfiniteDurability(itemInHand);
}
DurabilityUtils.handleInfiniteDurability(itemInHand); @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
} public void onPlayerRespawn(final PlayerRespawnEvent event) {
new SoulbindInventoryTask(event.getPlayer(), ActionType.RESPAWN).runTask(Soulbound.p);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onPlayerRespawn(final PlayerRespawnEvent event) { public void onPlayerRespawnHighest(final PlayerRespawnEvent event) {
new SoulbindInventoryTask(event.getPlayer(), ActionType.RESPAWN).runTask(Soulbound.p); final Player player = event.getPlayer();
} if (!Permissions.keepOnDeath(player)) {
return;
}
final ItemStack[] items = PlayerData.retrieveItemsDeath(player).toArray(new ItemStack[0]);
if (items != null) {
player.getInventory().addItem(items);
}
new UpdateInventoryTask(player).runTask(Soulbound.p);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) /**
private void onPlayerRespawnHighest(final PlayerRespawnEvent event) { * Monitor PlayerShearEntityEvent events.
final Player player = event.getPlayer(); *
final boolean keepOnDeath = Permissions.keepOnDeath(player); * @param event The event to monitor
if (!keepOnDeath) { */
return; @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
} public void onPlayerShearEntity(final PlayerShearEntityEvent event) {
List<ItemStack> items = new ArrayList<ItemStack>(); final ItemStack itemInHand = event.getPlayer().getItemInHand();
items = PlayerData.retrieveItemsDeath(player); DurabilityUtils.handleInfiniteDurability(itemInHand);
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(final PlayerShearEntityEvent event) {
final ItemStack itemInHand = event.getPlayer().getItemInHand();
DurabilityUtils.handleInfiniteDurability(itemInHand);
}
} }

View File

@ -18,20 +18,10 @@ public class PlayerData {
} }
public static List<ItemStack> retrieveItemsDeath(final Player player) { public static List<ItemStack> retrieveItemsDeath(final Player player) {
final String playerName = player.getName(); return playerSoulboundItems.get(player.getName());
if (playerSoulboundItems.containsKey(playerName)) {
return playerSoulboundItems.get(playerName);
} else {
return null;
}
} }
public static void storeItemsDeath(final Player player, final List<ItemStack> items) { public static void storeItemsDeath(final Player player, final List<ItemStack> items) {
final String playerName = player.getName(); playerSoulboundItems.put(player.getName(), items);
if (playerSoulboundItems.containsKey(playerName)) {
playerSoulboundItems.put(playerName, null);
}
playerSoulboundItems.put(playerName, items);
} }
} }