mirror of
https://e.coding.net/circlecloud/Soulbound.git
synced 2024-11-21 01:39:10 +00:00
Accept Merge Request #4 : ( J_twitter : master -> 502647092 : master )
修复盔甲架导致绑定物品转移的问题
This commit is contained in:
commit
b0395c0bf0
@ -2,6 +2,7 @@ package com.me.tft_02.soulbound;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@ -14,6 +15,7 @@ import com.me.tft_02.soulbound.commands.SoulboundCommand;
|
|||||||
import com.me.tft_02.soulbound.commands.UnbindCommand;
|
import com.me.tft_02.soulbound.commands.UnbindCommand;
|
||||||
import com.me.tft_02.soulbound.config.Config;
|
import com.me.tft_02.soulbound.config.Config;
|
||||||
import com.me.tft_02.soulbound.config.ItemsConfig;
|
import com.me.tft_02.soulbound.config.ItemsConfig;
|
||||||
|
import com.me.tft_02.soulbound.listeners.ArmorStandListener;
|
||||||
import com.me.tft_02.soulbound.listeners.BlockListener;
|
import com.me.tft_02.soulbound.listeners.BlockListener;
|
||||||
import com.me.tft_02.soulbound.listeners.EntityListener;
|
import com.me.tft_02.soulbound.listeners.EntityListener;
|
||||||
import com.me.tft_02.soulbound.listeners.InventoryListener;
|
import com.me.tft_02.soulbound.listeners.InventoryListener;
|
||||||
@ -115,10 +117,14 @@ public class Soulbound extends JavaPlugin {
|
|||||||
|
|
||||||
private void registerEvents() {
|
private void registerEvents() {
|
||||||
final PluginManager pm = getServer().getPluginManager();
|
final PluginManager pm = getServer().getPluginManager();
|
||||||
|
final String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
||||||
pm.registerEvents(new PlayerListener(), this);
|
pm.registerEvents(new PlayerListener(), this);
|
||||||
pm.registerEvents(new InventoryListener(), this);
|
pm.registerEvents(new InventoryListener(), this);
|
||||||
pm.registerEvents(new EntityListener(), this);
|
pm.registerEvents(new EntityListener(), this);
|
||||||
pm.registerEvents(new BlockListener(), this);
|
pm.registerEvents(new BlockListener(), this);
|
||||||
|
if (version.equals("v1_8_R1") || version.equals("v1_8_R2") || version.equals("v1_8_R3")) {
|
||||||
|
pm.registerEvents(new ArmorStandListener(), this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupFilePaths() {
|
private void setupFilePaths() {
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.me.tft_02.soulbound.listeners;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerArmorStandManipulateEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import com.me.tft_02.soulbound.util.ItemUtils;
|
||||||
|
|
||||||
|
public class ArmorStandListener implements Listener {
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
|
public void onPlayerArmorStandManipulate(PlayerArmorStandManipulateEvent event) {
|
||||||
|
final Player player = event.getPlayer();
|
||||||
|
final ItemStack itemStack = event.getPlayerItem();
|
||||||
|
if (itemStack != null && ItemUtils.isSoulbound(itemStack)) {
|
||||||
|
player.sendMessage(ChatColor.RED + "绑定物品不允许被放置在盔甲架上.");
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -37,199 +37,205 @@ import com.me.tft_02.soulbound.util.PlayerData;
|
|||||||
|
|
||||||
public class PlayerListener implements Listener {
|
public class PlayerListener implements Listener {
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onItemDrop(final PlayerDropItemEvent event) {
|
public void onItemDrop(final PlayerDropItemEvent event) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
if (!player.isValid()) {
|
if (!player.isValid()) {
|
||||||
return;
|
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()) {
|
||||||
if (ItemUtils.isSoulbound(itemStack) && ItemUtils.isBindedPlayer(player, itemStack)) {
|
if (ItemUtils.isSoulbound(itemStack) && ItemUtils.isBindedPlayer(player, itemStack)) {
|
||||||
item.setPickupDelay(2 * 20);
|
item.setPickupDelay(2 * 20);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
new UpdateInventoryTask(player).runTask(Soulbound.p);
|
new UpdateInventoryTask(player).runTask(Soulbound.p);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Config.getDeleteOnDrop()) {
|
if (Config.getDeleteOnDrop()) {
|
||||||
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F);
|
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F);
|
||||||
event.getItemDrop().remove();
|
event.getItemDrop().remove();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ItemsConfig.isActionItem(itemStack, ActionType.DROP_ITEM)) {
|
if (ItemsConfig.isActionItem(itemStack, ActionType.DROP_ITEM)) {
|
||||||
ItemUtils.soulbindItem(player, itemStack);
|
ItemUtils.soulbindItem(player, itemStack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public 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)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ItemUtils.isBindOnPickup(itemStack) || ItemsConfig.isActionItem(itemStack, ActionType.PICKUP_ITEM)) {
|
if (ItemUtils.isBindOnPickup(itemStack) || ItemsConfig.isActionItem(itemStack, ActionType.PICKUP_ITEM)) {
|
||||||
ItemUtils.soulbindItem(player, itemStack);
|
ItemUtils.soulbindItem(player, itemStack);
|
||||||
}
|
}
|
||||||
if(player.getItemOnCursor()!=null && ItemUtils.isSoulbound(player.getItemOnCursor())){
|
if (player.getItemOnCursor() != null && ItemUtils.isSoulbound(player.getItemOnCursor())) {
|
||||||
item.setPickupDelay(40);
|
item.setPickupDelay(40);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Watch PlayerCommandPreprocessEvent events.
|
* Watch PlayerCommandPreprocessEvent events.
|
||||||
*
|
*
|
||||||
* @param event The event to watch
|
* @param event
|
||||||
*/
|
* The event to watch
|
||||||
@EventHandler(ignoreCancelled = true)
|
*/
|
||||||
public void onPlayerCommand(final PlayerCommandPreprocessEvent event) {
|
@EventHandler(ignoreCancelled = true)
|
||||||
final Player player = event.getPlayer();
|
public void onPlayerCommand(final PlayerCommandPreprocessEvent event) {
|
||||||
final ItemStack itemStack = player.getItemInHand();
|
final Player player = event.getPlayer();
|
||||||
final String command = event.getMessage();
|
final ItemStack itemStack = player.getItemInHand();
|
||||||
|
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 The event to monitor
|
* @param event
|
||||||
*/
|
* The event to monitor
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
*/
|
||||||
public void onPlayerCommandMonitor(final PlayerCommandPreprocessEvent event) {
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
final Player player = event.getPlayer();
|
public void onPlayerCommandMonitor(final PlayerCommandPreprocessEvent event) {
|
||||||
final ItemStack inHand = player.getItemInHand();
|
final Player player = event.getPlayer();
|
||||||
final String command = event.getMessage();
|
final ItemStack inHand = player.getItemInHand();
|
||||||
final String[] args = CommandUtils.extractArgs(command);
|
final String command = event.getMessage();
|
||||||
if (!ItemUtils.isSoulbound(inHand) && Config.getBindCommands().contains(command)) {
|
final String[] args = CommandUtils.extractArgs(command);
|
||||||
ItemUtils.soulbindItem(player, inHand);
|
if (!ItemUtils.isSoulbound(inHand) && Config.getBindCommands().contains(command)) {
|
||||||
return;
|
ItemUtils.soulbindItem(player, inHand);
|
||||||
}
|
return;
|
||||||
if (command.contains("kit")) {
|
}
|
||||||
Player target;
|
if (command.contains("kit")) {
|
||||||
if (args.length >= 2) {
|
Player target;
|
||||||
target = Soulbound.p.getServer().getPlayer(args[1]);
|
if (args.length >= 2) {
|
||||||
} else {
|
target = Soulbound.p.getServer().getPlayer(args[1]);
|
||||||
target = player;
|
} else {
|
||||||
}
|
target = player;
|
||||||
if (target == null) {
|
}
|
||||||
return;
|
if (target == null) {
|
||||||
}
|
return;
|
||||||
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)
|
||||||
public 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<>();
|
final List<ItemStack> items = new ArrayList<>();
|
||||||
if (!keepOnDeath && !deleteOnDeath) {
|
if (!keepOnDeath && !deleteOnDeath) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (final ItemStack item : new ArrayList<>(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);
|
event.getDrops().remove(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerData.storeItemsDeath(player, items);
|
PlayerData.storeItemsDeath(player, items);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Monitor PlayerFishEvent events.
|
* Monitor PlayerFishEvent events.
|
||||||
*
|
*
|
||||||
* @param event The event to monitor
|
* @param event
|
||||||
*/
|
* The event to monitor
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
*/
|
||||||
public void onPlayerFish(final PlayerFishEvent event) {
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
final ItemStack itemInHand = event.getPlayer().getItemInHand();
|
public void onPlayerFish(final PlayerFishEvent event) {
|
||||||
DurabilityUtils.handleInfiniteDurability(itemInHand);
|
final ItemStack itemInHand = event.getPlayer().getItemInHand();
|
||||||
}
|
DurabilityUtils.handleInfiniteDurability(itemInHand);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Watch PlayerInteract events.
|
* Watch PlayerInteract events.
|
||||||
*
|
*
|
||||||
* @param event The event to watch
|
* @param event
|
||||||
*/
|
* The event to watch
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
*/
|
||||||
public void onPlayerInteract(final PlayerInteractEvent event) {
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
final Player player = event.getPlayer();
|
public void onPlayerInteract(final PlayerInteractEvent event) {
|
||||||
final Action action = event.getAction();
|
final Player player = event.getPlayer();
|
||||||
final ItemStack inHand = player.getItemInHand();
|
final Action action = event.getAction();
|
||||||
switch (action) {
|
final ItemStack inHand = player.getItemInHand();
|
||||||
case RIGHT_CLICK_BLOCK:
|
switch (action) {
|
||||||
case RIGHT_CLICK_AIR:
|
case RIGHT_CLICK_BLOCK:
|
||||||
case LEFT_CLICK_AIR:
|
case RIGHT_CLICK_AIR:
|
||||||
case LEFT_CLICK_BLOCK:
|
case LEFT_CLICK_AIR:
|
||||||
if (ItemUtils.isEquipable(inHand)) {
|
case LEFT_CLICK_BLOCK:
|
||||||
new UpdateArmorTask(player).runTaskLater(Soulbound.p, 2);
|
if (ItemUtils.isEquipable(inHand)) {
|
||||||
} else if (ItemUtils.isBindOnUse(inHand)) {
|
new UpdateArmorTask(player).runTaskLater(Soulbound.p, 2);
|
||||||
ItemUtils.soulbindItem(player, inHand);
|
} else if (ItemUtils.isBindOnUse(inHand)) {
|
||||||
}
|
ItemUtils.soulbindItem(player, inHand);
|
||||||
default:
|
}
|
||||||
break;
|
default:
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
public 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)
|
||||||
public void onPlayerRespawnHighest(final PlayerRespawnEvent event) {
|
public void onPlayerRespawnHighest(final PlayerRespawnEvent event) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
if (!Permissions.keepOnDeath(player)) {
|
if (!Permissions.keepOnDeath(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final ItemStack[] items = PlayerData.retrieveItemsDeath(player).toArray(new ItemStack[0]);
|
final ItemStack[] items = PlayerData.retrieveItemsDeath(player).toArray(new ItemStack[0]);
|
||||||
if (items != null) {
|
if (items != null) {
|
||||||
player.getInventory().addItem(items);
|
player.getInventory().addItem(items);
|
||||||
}
|
}
|
||||||
new UpdateInventoryTask(player).runTask(Soulbound.p);
|
new UpdateInventoryTask(player).runTask(Soulbound.p);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Monitor PlayerShearEntityEvent events.
|
* Monitor PlayerShearEntityEvent events.
|
||||||
*
|
*
|
||||||
* @param event The event to monitor
|
* @param event
|
||||||
*/
|
* The event to monitor
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
*/
|
||||||
public void onPlayerShearEntity(final PlayerShearEntityEvent event) {
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
final ItemStack itemInHand = event.getPlayer().getItemInHand();
|
public void onPlayerShearEntity(final PlayerShearEntityEvent event) {
|
||||||
DurabilityUtils.handleInfiniteDurability(itemInHand);
|
final ItemStack itemInHand = event.getPlayer().getItemInHand();
|
||||||
}
|
DurabilityUtils.handleInfiniteDurability(itemInHand);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Monitor ServerCommandEvent events.
|
* Monitor ServerCommandEvent events.
|
||||||
*
|
*
|
||||||
* @param event The event to monitor
|
* @param event
|
||||||
*/
|
* The event to monitor
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
*/
|
||||||
public void onServerCommand(final ServerCommandEvent event) {
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
final String command = event.getCommand();
|
public void onServerCommand(final ServerCommandEvent event) {
|
||||||
final String[] args = CommandUtils.extractArgs(command);
|
final String command = event.getCommand();
|
||||||
if (!command.contains("kit")) {
|
final String[] args = CommandUtils.extractArgs(command);
|
||||||
return;
|
if (!command.contains("kit")) {
|
||||||
}
|
return;
|
||||||
if (args.length < 2) {
|
}
|
||||||
return;
|
if (args.length < 2) {
|
||||||
}
|
return;
|
||||||
final Player target = Soulbound.p.getServer().getPlayer(args[1]);
|
}
|
||||||
new SoulbindInventoryTask(target, ActionType.KIT).runTask(Soulbound.p);
|
final Player target = Soulbound.p.getServer().getPlayer(args[1]);
|
||||||
}
|
new SoulbindInventoryTask(target, ActionType.KIT).runTask(Soulbound.p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user