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

禁止将绑定物品放置在盔甲架上

This commit is contained in:
john180 2016-02-02 18:47:43 +08:00
parent b558cd9bdb
commit 2185518737
3 changed files with 219 additions and 184 deletions

View File

@ -2,6 +2,7 @@ package com.me.tft_02.soulbound;
import java.io.File;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.PluginManager;
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.config.Config;
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.EntityListener;
import com.me.tft_02.soulbound.listeners.InventoryListener;
@ -115,10 +117,14 @@ public class Soulbound extends JavaPlugin {
private void registerEvents() {
final PluginManager pm = getServer().getPluginManager();
final String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
pm.registerEvents(new PlayerListener(), this);
pm.registerEvents(new InventoryListener(), this);
pm.registerEvents(new EntityListener(), 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() {

View File

@ -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);
}
}
}

View File

@ -37,199 +37,205 @@ import com.me.tft_02.soulbound.util.PlayerData;
public class PlayerListener implements Listener {
@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.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(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)) {
event.setCancelled(true);
}
return;
}
if (ItemUtils.isBindOnPickup(itemStack) || ItemsConfig.isActionItem(itemStack, ActionType.PICKUP_ITEM)) {
ItemUtils.soulbindItem(player, itemStack);
}
if(player.getItemOnCursor()!=null && ItemUtils.isSoulbound(player.getItemOnCursor())){
item.setPickupDelay(40);
event.setCancelled(true);
}
}
@EventHandler(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)) {
event.setCancelled(true);
}
return;
}
if (ItemUtils.isBindOnPickup(itemStack) || ItemsConfig.isActionItem(itemStack, ActionType.PICKUP_ITEM)) {
ItemUtils.soulbindItem(player, itemStack);
}
if (player.getItemOnCursor() != null && ItemUtils.isSoulbound(player.getItemOnCursor())) {
item.setPickupDelay(40);
event.setCancelled(true);
}
}
/**
* Watch PlayerCommandPreprocessEvent events.
*
* @param event The event to watch
*/
@EventHandler(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(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);
}
}
@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);
}
@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)
public void onPlayerFish(final PlayerFishEvent event) {
final ItemStack itemInHand = event.getPlayer().getItemInHand();
DurabilityUtils.handleInfiniteDurability(itemInHand);
}
/**
* 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);
}
/**
* 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;
}
}
@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)
public 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)
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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
}