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

@ -40,8 +40,7 @@ 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) {
@ -58,8 +57,7 @@ public class PlayerListener implements Listener {
/** /**
* 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) {
@ -88,8 +86,7 @@ public class PlayerListener implements Listener {
/** /**
* 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) {
@ -114,8 +111,7 @@ public class PlayerListener implements Listener {
/** /**
* 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) {
@ -132,8 +128,11 @@ public class PlayerListener implements Listener {
} }
@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();
if (!player.isValid()) {
return;
}
final Item item = event.getItemDrop(); final Item item = event.getItemDrop();
final ItemStack itemStack = item.getItemStack(); final ItemStack itemStack = item.getItemStack();
if (Config.getPreventItemDrop()) { if (Config.getPreventItemDrop()) {
@ -151,12 +150,11 @@ public class PlayerListener implements Listener {
} }
if (ItemsConfig.isActionItem(itemStack, ActionType.DROP_ITEM)) { if (ItemsConfig.isActionItem(itemStack, ActionType.DROP_ITEM)) {
ItemUtils.soulbindItem(player, itemStack); ItemUtils.soulbindItem(player, itemStack);
return;
} }
} }
@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();
@ -173,27 +171,24 @@ public class PlayerListener implements Listener {
} }
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);
@ -202,34 +197,28 @@ public class PlayerListener implements Listener {
/** /**
* 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)
private void onPlayerFish(final PlayerFishEvent event) { public 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) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onPlayerRespawn(final PlayerRespawnEvent event) { public void onPlayerRespawn(final PlayerRespawnEvent event) {
new SoulbindInventoryTask(event.getPlayer(), ActionType.RESPAWN).runTask(Soulbound.p); new SoulbindInventoryTask(event.getPlayer(), ActionType.RESPAWN).runTask(Soulbound.p);
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onPlayerRespawnHighest(final PlayerRespawnEvent event) { public void onPlayerRespawnHighest(final PlayerRespawnEvent event) {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final boolean keepOnDeath = Permissions.keepOnDeath(player); if (!Permissions.keepOnDeath(player)) {
if (!keepOnDeath) {
return; return;
} }
List<ItemStack> items = new ArrayList<ItemStack>(); final ItemStack[] items = PlayerData.retrieveItemsDeath(player).toArray(new ItemStack[0]);
items = PlayerData.retrieveItemsDeath(player);
if (items != null) { if (items != null) {
for (final ItemStack item : items) { player.getInventory().addItem(items);
player.getInventory().addItem(item);
}
} }
new UpdateInventoryTask(player).runTask(Soulbound.p); new UpdateInventoryTask(player).runTask(Soulbound.p);
} }
@ -237,13 +226,11 @@ public class PlayerListener implements Listener {
/** /**
* Monitor PlayerShearEntityEvent events. * Monitor PlayerShearEntityEvent 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)
private void onPlayerShearEntity(final PlayerShearEntityEvent event) { public void onPlayerShearEntity(final PlayerShearEntityEvent event) {
final ItemStack itemInHand = event.getPlayer().getItemInHand(); final ItemStack itemInHand = event.getPlayer().getItemInHand();
DurabilityUtils.handleInfiniteDurability(itemInHand); 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);
} }
} }