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>
<groupId>com.me.tft_02.soulbound</groupId>
<artifactId>Soulbound</artifactId>
<version>1.2</version>
<version>1.3</version>
<name>Soulbound</name>
<description>Soulbound items for your RPG servers!</description>
<url>https://github.com/TfT-02/Soulbound</url>
@ -60,21 +60,18 @@
</build>
<properties>
<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>
</properties>
<repositories>
<repository>
<id>mengcraft-repo</id>
<url>http://ci.mengcraft.com:8080/plugin/repository/everything/</url>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>citycraft-repo</id>
<url>http://ci.citycraft.cn:8800/jenkins/plugin/repository/everything/</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
<url>${jenkins.url}/plugin/repository/everything/</url>
</repository>
</repositories>
<dependencies>
@ -82,7 +79,7 @@
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<type>jar</type>
<version>1.8.3-R0.1-SNAPSHOT</version>
<version>1.8.8-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.citycraft</groupId>

View File

@ -37,213 +37,200 @@ import com.me.tft_02.soulbound.util.PlayerData;
public class PlayerListener implements Listener {
/**
* 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();
/**
* 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) && Config.getBlockedCommands().contains(command)) {
player.sendMessage(ChatColor.RED + "不允许使用命令 " + ChatColor.GOLD + command + ChatColor.RED + " 当拿着绑定物品的时候.");
event.setCancelled(true);
}
}
if (ItemUtils.isSoulbound(itemStack) && Config.getBlockedCommands().contains(command)) {
player.sendMessage(ChatColor.RED + "不允许使用命令 " + ChatColor.GOLD + command + ChatColor.RED + " 当拿着绑定物品的时候.");
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.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 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.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);
}
}
/**
* Watch PlayerInteract events.
*
* @param event
* The event to watch
*/
@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:
case LEFT_CLICK_AIR:
case LEFT_CLICK_BLOCK:
if (ItemUtils.isEquipable(inHand)) {
new UpdateArmorTask(player).runTaskLater(Soulbound.p, 2);
} else if (ItemUtils.isBindOnUse(inHand)) {
ItemUtils.soulbindItem(player, inHand);
}
default:
break;
}
}
/**
* Watch PlayerInteract events.
*
* @param event The event to watch
*/
@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:
case LEFT_CLICK_AIR:
case LEFT_CLICK_BLOCK:
if (ItemUtils.isEquipable(inHand)) {
new UpdateArmorTask(player).runTaskLater(Soulbound.p, 2);
} else if (ItemUtils.isBindOnUse(inHand)) {
ItemUtils.soulbindItem(player, inHand);
}
default:
break;
}
}
/**
* 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);
}
/**
* 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.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.getDeleteOnDrop()) {
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F);
event.getItemDrop().remove();
return;
}
if (ItemsConfig.isActionItem(itemStack, ActionType.DROP_ITEM)) {
ItemUtils.soulbindItem(player, itemStack);
return;
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onItemDrop(final PlayerDropItemEvent event) {
final Player player = event.getPlayer();
if (!player.isValid()) {
return;
}
final Item item = event.getItemDrop();
final ItemStack itemStack = item.getItemStack();
if (Config.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.getDeleteOnDrop()) {
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F);
event.getItemDrop().remove();
return;
}
if (ItemsConfig.isActionItem(itemStack, ActionType.DROP_ITEM)) {
ItemUtils.soulbindItem(player, itemStack);
}
}
@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.isActionItem(itemStack, ActionType.PICKUP_ITEM)) {
ItemUtils.soulbindItem(player, itemStack);
return;
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public 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.isActionItem(itemStack, ActionType.PICKUP_ITEM)) {
ItemUtils.soulbindItem(player, itemStack);
}
}
@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);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public 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<>();
if (!keepOnDeath && !deleteOnDeath) {
return;
}
for (final ItemStack item : new ArrayList<>(event.getDrops())) {
if (ItemUtils.isSoulbound(item) && ItemUtils.isBindedPlayer(player, item)) {
if (keepOnDeath) {
items.add(item);
}
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(final PlayerFishEvent event) {
final ItemStack itemInHand = event.getPlayer().getItemInHand();
/**
* Monitor PlayerFishEvent events.
*
* @param event The event to monitor
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerFish(final PlayerFishEvent event) {
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)
private void onPlayerRespawn(final PlayerRespawnEvent event) {
new SoulbindInventoryTask(event.getPlayer(), ActionType.RESPAWN).runTask(Soulbound.p);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerRespawnHighest(final PlayerRespawnEvent event) {
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) {
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(final PlayerShearEntityEvent event) {
final ItemStack itemInHand = event.getPlayer().getItemInHand();
DurabilityUtils.handleInfiniteDurability(itemInHand);
}
/**
* Monitor PlayerShearEntityEvent events.
*
* @param event The event to monitor
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public 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) {
final String playerName = player.getName();
if (playerSoulboundItems.containsKey(playerName)) {
return playerSoulboundItems.get(playerName);
} else {
return null;
}
return playerSoulboundItems.get(player.getName());
}
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);
playerSoulboundItems.put(player.getName(), items);
}
}