mirror of
https://e.coding.net/circlecloud/Soulbound.git
synced 2024-11-22 01:49:09 +00:00
源代码格式化...
This commit is contained in:
parent
a51e7638c5
commit
e20796ff6b
@ -16,52 +16,12 @@ import com.me.tft_02.soulbound.util.DurabilityUtils;
|
||||
|
||||
public class EntityListener implements Listener {
|
||||
|
||||
/**
|
||||
* Check EntityDamageByEntityEvent events.
|
||||
*
|
||||
* @param event
|
||||
* The event to check
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onEntityDeath(final EntityDamageByEntityEvent event) {
|
||||
if (event.getDamage() == 0 || event.getEntity().isDead()) {
|
||||
return;
|
||||
}
|
||||
if (event.getEntity() instanceof LivingEntity) {
|
||||
combatChecks(event);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
private void onEntityDamage(final EntityDamageEvent event) {
|
||||
if (event.getDamage() == 0 || event.getEntity().isDead()) {
|
||||
return;
|
||||
}
|
||||
final Entity entity = event.getEntity();
|
||||
if (entity instanceof Player) {
|
||||
final Player player = (Player) entity;
|
||||
|
||||
for (final ItemStack itemStack : player.getInventory().getArmorContents()) {
|
||||
DurabilityUtils.handleInfiniteDurability(itemStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
private void onEntityShootBow(final EntityShootBowEvent event) {
|
||||
final Entity entity = event.getEntity();
|
||||
if (entity instanceof Player) {
|
||||
DurabilityUtils.handleInfiniteDurability(((Player) entity).getItemInHand());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply combat modifiers
|
||||
*
|
||||
* @param event
|
||||
* The event to run the combat checks on.
|
||||
* @param event The event to run the combat checks on.
|
||||
*/
|
||||
void combatChecks(final EntityDamageByEntityEvent event) {
|
||||
public void onCombat(final EntityDamageByEntityEvent event) {
|
||||
final Entity damager = event.getDamager();
|
||||
final EntityType damagerType = damager.getType();
|
||||
switch (damagerType) {
|
||||
@ -73,4 +33,41 @@ public class EntityListener implements Listener {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onEntityDamage(final EntityDamageEvent event) {
|
||||
if (event.getDamage() == 0 || event.getEntity().isDead()) {
|
||||
return;
|
||||
}
|
||||
final Entity entity = event.getEntity();
|
||||
if (entity instanceof Player) {
|
||||
final Player player = (Player) entity;
|
||||
for (final ItemStack itemStack : player.getInventory().getArmorContents()) {
|
||||
DurabilityUtils.handleInfiniteDurability(itemStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check EntityDamageByEntityEvent events.
|
||||
*
|
||||
* @param event The event to check
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onEntityDeath(final EntityDamageByEntityEvent event) {
|
||||
if (event.getDamage() == 0 || event.getEntity().isDead()) {
|
||||
return;
|
||||
}
|
||||
if (event.getEntity() instanceof LivingEntity) {
|
||||
onCombat(event);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onEntityShootBow(final EntityShootBowEvent event) {
|
||||
final Entity entity = event.getEntity();
|
||||
if (entity instanceof Player) {
|
||||
DurabilityUtils.handleInfiniteDurability(((Player) entity).getItemInHand());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,12 +37,54 @@ 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(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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Watch PlayerCommandPreprocessEvent events.
|
||||
*
|
||||
* @param event The event to watch
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerCommand(final PlayerCommandPreprocessEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final ItemStack itemStack = player.getItemInHand();
|
||||
@ -83,97 +125,6 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
@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)
|
||||
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)
|
||||
public void onPlayerDeath(final PlayerDeathEvent event) {
|
||||
final Player player = event.getEntity();
|
||||
@ -205,6 +156,31 @@ public class PlayerListener implements Listener {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerRespawn(final PlayerRespawnEvent event) {
|
||||
new SoulbindInventoryTask(event.getPlayer(), ActionType.RESPAWN).runTask(Soulbound.p);
|
||||
@ -233,4 +209,23 @@ public class PlayerListener implements Listener {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user