From 9eb122a5202b54338e68078a9a14bdfbc2d5d921 Mon Sep 17 00:00:00 2001 From: Dereku Date: Fri, 13 Apr 2018 09:18:11 +0700 Subject: [PATCH 1/4] I hope that I did not break that --- .../event/listener/ArmorEquipListener.java | 114 +++++++++++------- 1 file changed, 73 insertions(+), 41 deletions(-) diff --git a/src/main/java/ru/endlesscode/rpginventory/event/listener/ArmorEquipListener.java b/src/main/java/ru/endlesscode/rpginventory/event/listener/ArmorEquipListener.java index efeee9a..52bc2d8 100644 --- a/src/main/java/ru/endlesscode/rpginventory/event/listener/ArmorEquipListener.java +++ b/src/main/java/ru/endlesscode/rpginventory/event/listener/ArmorEquipListener.java @@ -19,7 +19,9 @@ package ru.endlesscode.rpginventory.event.listener; import org.bukkit.Location; -import org.bukkit.block.BlockFace; +import org.bukkit.block.Block; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -32,7 +34,7 @@ import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.*; +import org.jetbrains.annotations.NotNull; import ru.endlesscode.rpginventory.RPGInventory; import ru.endlesscode.rpginventory.api.InventoryAPI; import ru.endlesscode.rpginventory.inventory.ActionType; @@ -44,6 +46,8 @@ import ru.endlesscode.rpginventory.utils.ItemUtils; import ru.endlesscode.rpginventory.utils.PlayerUtils; +import java.util.Collection; + /** * Created by OsipXD on 08.04.2016 * It is part of the RpgInventory. @@ -144,48 +148,76 @@ public void onNormalEquip(@NotNull InventoryClickEvent event) { } @EventHandler - public void onDispenseEquip(@NotNull BlockDispenseEvent event) { + public void onDispenseEquip(BlockDispenseEvent event) { ArmorType type = ArmorType.matchType(event.getItem()); Location blockLoc = event.getBlock().getLocation(); + Collection nearbyEntities = blockLoc.getWorld().getNearbyEntities(blockLoc, 3D, 1.2D, 3D); + for (Entity entity : nearbyEntities) { + if (entity.getType() != EntityType.PLAYER) { + continue; + } - for (Player player : blockLoc.getWorld().getPlayers()) { - Location playerLoc = player.getLocation(); - - if (blockLoc.getBlockY() - playerLoc.getBlockY() >= -1 - && blockLoc.getBlockY() - playerLoc.getBlockY() <= 1) { - - if (type == ArmorType.HELMET && player.getInventory().getHelmet() == null - || type == ArmorType.CHESTPLATE && player.getInventory().getChestplate() == null - || type == ArmorType.LEGGINGS && player.getInventory().getLeggings() == null - || type == ArmorType.BOOTS && player.getInventory().getBoots() == null) { - - org.bukkit.block.Dispenser dispenser = (org.bukkit.block.Dispenser) event.getBlock().getState(); - org.bukkit.material.Dispenser dis = (org.bukkit.material.Dispenser) dispenser.getData(); - BlockFace directionFacing = dis.getFacing(); - - // Someone told me not to do big if checks because it's hard to read, look at me doing it -_- - if (directionFacing == BlockFace.EAST && playerLoc.getBlockX() != blockLoc.getBlockX() - && playerLoc.getX() <= blockLoc.getX() + 2.3 && playerLoc.getX() >= blockLoc.getX() - || directionFacing == BlockFace.WEST && playerLoc.getX() >= blockLoc.getX() - 1.3 - && playerLoc.getX() <= blockLoc.getX() - || directionFacing == BlockFace.SOUTH - && playerLoc.getBlockZ() != blockLoc.getBlockZ() - && playerLoc.getZ() <= blockLoc.getZ() + 2.3 && playerLoc.getZ() >= blockLoc.getZ() - || directionFacing == BlockFace.NORTH && playerLoc.getZ() >= blockLoc.getZ() - 1.3 - && playerLoc.getZ() <= blockLoc.getZ()) { - - if (!InventoryManager.playerIsLoaded(player)) { - return; - } - - Slot armorSlot = SlotManager.instance().getSlot(type.name()); - event.setCancelled(armorSlot != null - && !InventoryManager.validateArmor( - player, InventoryAction.PLACE_ONE, armorSlot, event.getItem())); - return; - } - } + Player player = (Player) entity; + if (!this.isPlayerInRightPosition(event.getBlock(), player)) { + continue; + } + if (this.hasInventoryArmorByType(type, player)) { + continue; } + if (!InventoryManager.playerIsLoaded(player)) { + break; + } + + Slot armorSlot = SlotManager.instance().getSlot(type.name()); + event.setCancelled(armorSlot != null + && !InventoryManager.validateArmor(player, InventoryAction.PLACE_ONE, armorSlot, event.getItem())); + break; + } + } + + //Read helpers \:D/ + private boolean hasInventoryArmorByType(ArmorType type, Player player) { + switch (type) { + case HELMET: + return player.getInventory().getHelmet() != null; + case CHESTPLATE: + return player.getInventory().getChestplate() != null; + case LEGGINGS: + return player.getInventory().getLeggings() != null; + case BOOTS: + return player.getInventory().getBoots() != null; + case UNKNOWN: + default: + return true; //Why no? + } + } + + private boolean isPlayerInRightPosition(Block block, Player player) { + final Location blockLoc = block.getLocation(); + final Location playerLoc = player.getLocation(); + org.bukkit.block.Dispenser dispenser = (org.bukkit.block.Dispenser) block.getState(); + org.bukkit.material.Dispenser dispenserData = (org.bukkit.material.Dispenser) dispenser.getData(); + /* + From old 'if' statement + // Someone told me not to do big if checks because it's hard to read, look at me doing it -_- + + directionFacing == BlockFace.EAST && playerLoc.getBlockX() != blockLoc.getBlockX() && playerLoc.getX() <= blockLoc.getX() + 2.3 && playerLoc.getX() >= blockLoc.getX() + || directionFacing == BlockFace.WEST && playerLoc.getX() >= blockLoc.getX() - 1.3 && playerLoc.getX() <= blockLoc.getX() + || directionFacing == BlockFace.SOUTH && playerLoc.getBlockZ() != blockLoc.getBlockZ() && playerLoc.getZ() <= blockLoc.getZ() + 2.3 && playerLoc.getZ() >= lockLoc.getZ() + || directionFacing == BlockFace.NORTH && playerLoc.getZ() >= blockLoc.getZ() - 1.3 && playerLoc.getZ() <= blockLoc.getZ()+ + */ + switch (dispenserData.getFacing()) { + case EAST: + return playerLoc.getBlockX() != blockLoc.getBlockX() && playerLoc.getX() <= blockLoc.getX() + 2.3 && playerLoc.getX() >= blockLoc.getX(); + case WEST: + return playerLoc.getX() >= blockLoc.getX() - 1.3 && playerLoc.getX() <= blockLoc.getX(); + case SOUTH: + return playerLoc.getBlockZ() != blockLoc.getBlockZ() && playerLoc.getZ() <= blockLoc.getZ() + 2.3 && playerLoc.getZ() >= blockLoc.getZ(); + case NORTH: + return playerLoc.getZ() >= blockLoc.getZ() - 1.3 && playerLoc.getZ() <= blockLoc.getZ(); + default: + return false; + } } -} +} \ No newline at end of file From f00950121a35d0862a016a452619d5f7b4988e63 Mon Sep 17 00:00:00 2001 From: Dereku Date: Fri, 13 Apr 2018 10:14:03 +0700 Subject: [PATCH 2/4] Another miscellaneous edit --- .../inventory/InventoryLocker.java | 67 ++++++++++--------- .../inventory/InventoryManager.java | 28 ++++---- .../rpginventory/inventory/slot/Slot.java | 4 +- .../inventory/slot/SlotManager.java | 29 ++++---- .../endlesscode/rpginventory/pet/PetType.java | 1 - 5 files changed, 65 insertions(+), 64 deletions(-) diff --git a/src/main/java/ru/endlesscode/rpginventory/inventory/InventoryLocker.java b/src/main/java/ru/endlesscode/rpginventory/inventory/InventoryLocker.java index 6224bc4..e184bd9 100644 --- a/src/main/java/ru/endlesscode/rpginventory/inventory/InventoryLocker.java +++ b/src/main/java/ru/endlesscode/rpginventory/inventory/InventoryLocker.java @@ -20,6 +20,7 @@ import org.bukkit.GameMode; import org.bukkit.OfflinePlayer; +import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -44,8 +45,8 @@ */ public class InventoryLocker { - private static ItemStack lockedSlot = null; - private static ItemStack buyableSlot = null; + private static ItemStack LOCKED_SLOT = null; + private static ItemStack BUYABLE_SLOT = null; private InventoryLocker() { } @@ -57,24 +58,23 @@ public static boolean init(@NotNull RPGInventory instance) { try { // Setup locked slot - lockedSlot = ItemUtils.getTexturedItem(Config.getConfig().getString("slots.locked")); - ItemMeta meta = lockedSlot.getItemMeta(); + InventoryLocker.LOCKED_SLOT = ItemUtils.getTexturedItem(Config.getConfig().getString("slots.locked")); + ItemMeta meta = InventoryLocker.LOCKED_SLOT.getItemMeta(); meta.setDisplayName(RPGInventory.getLanguage().getMessage("locked.name")); meta.setLore(Collections.singletonList(RPGInventory.getLanguage().getMessage("locked.lore"))); - lockedSlot.setItemMeta(meta); - lockedSlot = addId(lockedSlot); + InventoryLocker.LOCKED_SLOT.setItemMeta(meta); + InventoryLocker.LOCKED_SLOT = addId(InventoryLocker.LOCKED_SLOT); // Setup buyable slot - buyableSlot = ItemUtils.getTexturedItem(Config.getConfig().getString("slots.buyable")); - meta = buyableSlot.getItemMeta(); + InventoryLocker.BUYABLE_SLOT = ItemUtils.getTexturedItem(Config.getConfig().getString("slots.buyable")); + meta = InventoryLocker.BUYABLE_SLOT.getItemMeta(); meta.setDisplayName(RPGInventory.getLanguage().getMessage("buyable.name")); meta.setLore(Collections.singletonList(RPGInventory.getLanguage().getMessage("buyable.lore"))); - buyableSlot.setItemMeta(meta); - buyableSlot = addId(buyableSlot); + InventoryLocker.BUYABLE_SLOT.setItemMeta(meta); + InventoryLocker.BUYABLE_SLOT = addId(InventoryLocker.BUYABLE_SLOT); } catch (Exception e) { - e.printStackTrace(); return false; } @@ -88,14 +88,16 @@ private static boolean isEnabled() { } public static boolean buySlot(@NotNull Player player, int line) { - if (RPGInventory.economyConnected() && RPGInventory.getEconomy().withdrawPlayer(player, Config.getConfig().getDouble("slots.money.cost.line" + line)).transactionSuccess()) { - if (RPGInventory.getLevelSystem() == PlayerUtils.LevelSystem.EXP && Config.getConfig().getBoolean("slots.level.spend")) { - player.setLevel(player.getLevel() - Config.getConfig().getInt("slots.level.required.line" + line)); + if (!RPGInventory.economyConnected()) { + return false; + } + final FileConfiguration config = Config.getConfig(); + if (RPGInventory.getEconomy().withdrawPlayer(player, config.getDouble("slots.money.cost.line" + line)).transactionSuccess()) { + if (RPGInventory.getLevelSystem() == PlayerUtils.LevelSystem.EXP && config.getBoolean("slots.level.spend")) { + player.setLevel(player.getLevel() - config.getInt("slots.level.required.line" + line)); } - return true; } - return false; } @@ -106,17 +108,17 @@ public static int getLine(int slot) { @NotNull public static ItemStack getBuyableSlotForLine(int line) { - ItemStack slot = buyableSlot.clone(); + ItemStack slot = InventoryLocker.BUYABLE_SLOT.clone(); ItemMeta im = slot.getItemMeta(); List lore = im.getLore(); FileLanguage lang = RPGInventory.getLanguage(); - - if (Config.getConfig().getBoolean("slots.money.enabled")) { - lore.add(lang.getMessage("buyable.money", StringUtils.doubleToString(Config.getConfig().getDouble("slots.money.cost.line" + line)))); + final FileConfiguration config = Config.getConfig(); + if (config.getBoolean("slots.money.enabled")) { + lore.add(lang.getMessage("buyable.money", StringUtils.doubleToString(config.getDouble("slots.money.cost.line" + line)))); } - if (Config.getConfig().getBoolean("slots.level.enabled")) { - lore.add(lang.getMessage("buyable.level", Config.getConfig().getInt("slots.level.required.line" + line))); + if (config.getBoolean("slots.level.enabled")) { + lore.add(lang.getMessage("buyable.level", config.getInt("slots.level.required.line" + line))); } im.setLore(lore); slot.setItemMeta(im); @@ -130,11 +132,11 @@ private static ItemStack addId(ItemStack item) { } public static boolean isLockedSlot(@Nullable ItemStack item) { - return isEnabled() && !ItemUtils.isEmpty(item) && ItemUtils.hasTag(item, "locked"); + return InventoryLocker.isEnabled() && !ItemUtils.isEmpty(item) && ItemUtils.hasTag(item, "locked"); } public static boolean isBuyableSlot(ItemStack currentItem, int line) { - return getBuyableSlotForLine(line).equals(currentItem); + return InventoryLocker.getBuyableSlotForLine(line).equals(currentItem); } public static void lockSlots(@NotNull Player player) { @@ -146,10 +148,10 @@ public static void lockSlots(@NotNull Player player, boolean force) { return; } - if (isEnabled()) { + if (InventoryLocker.isEnabled()) { int maxSlot = getSlots(player) + 8; for (int i = 35; i > maxSlot; i--) { - player.getInventory().setItem(i, lockedSlot); + player.getInventory().setItem(i, InventoryLocker.LOCKED_SLOT); } if (maxSlot < 35) { @@ -162,10 +164,10 @@ public static void lockSlots(@NotNull Player player, boolean force) { } public static void unlockSlots(@NotNull Player player) { - if (isEnabled()) { + if (InventoryLocker.isEnabled()) { for (int i = 8 + getSlots(player); i < 36; i++) { ItemStack itemStack = player.getInventory().getItem(i); - if (isLockedSlot(itemStack)) { + if (InventoryLocker.isLockedSlot(itemStack)) { player.getInventory().setItem(i, null); } } @@ -176,16 +178,17 @@ public static void unlockSlots(@NotNull Player player) { } public static boolean canBuySlot(@NotNull Player player, int line) { - if (Config.getConfig().getBoolean("slots.money.enabled")) { - double cost = Config.getConfig().getDouble("slots.money.cost.line" + line); + final FileConfiguration config = Config.getConfig(); + if (config.getBoolean("slots.money.enabled")) { + double cost = config.getDouble("slots.money.cost.line" + line); if (!PlayerUtils.checkMoney(player, cost)) { return false; } } - if (Config.getConfig().getBoolean("slots.level.enabled")) { - int requirement = Config.getConfig().getInt("slots.level.required.line" + line); + if (config.getBoolean("slots.level.enabled")) { + int requirement = config.getInt("slots.level.required.line" + line); if (!PlayerUtils.checkLevel(player, requirement)) { PlayerUtils.sendMessage(player, RPGInventory.getLanguage().getMessage("error.level", requirement)); diff --git a/src/main/java/ru/endlesscode/rpginventory/inventory/InventoryManager.java b/src/main/java/ru/endlesscode/rpginventory/inventory/InventoryManager.java index 8027390..6211978 100644 --- a/src/main/java/ru/endlesscode/rpginventory/inventory/InventoryManager.java +++ b/src/main/java/ru/endlesscode/rpginventory/inventory/InventoryManager.java @@ -62,17 +62,17 @@ public class InventoryManager { static final String TITLE = RPGInventory.getLanguage().getMessage("title"); private static final Map INVENTORIES = new HashMap<>(); - private static ItemStack fillSlot = null; + private static ItemStack FILL_SLOT = null; private InventoryManager() { } public static boolean init(@NotNull RPGInventory instance) { try { - fillSlot = ItemUtils.getTexturedItem(Config.getConfig().getString("fill")); - ItemMeta meta = fillSlot.getItemMeta(); + InventoryManager.FILL_SLOT = ItemUtils.getTexturedItem(Config.getConfig().getString("fill")); + ItemMeta meta = InventoryManager.FILL_SLOT.getItemMeta(); meta.setDisplayName(" "); - fillSlot.setItemMeta(meta); + InventoryManager.FILL_SLOT.setItemMeta(meta); } catch (Exception e) { e.printStackTrace(); return false; @@ -91,7 +91,7 @@ public static boolean validateUpdate(Player player, ActionType actionType, @NotN @NotNull public static ItemStack getFillSlot() { - return fillSlot; + return InventoryManager.FILL_SLOT; } public static boolean validatePet(Player player, InventoryAction action, @Nullable ItemStack currentItem, @NotNull ItemStack cursor) { @@ -401,7 +401,7 @@ public static void lockEmptySlots(Inventory inventory) { for (int i = 0; i < inventory.getSize(); i++) { Slot slot = SlotManager.instance().getSlot(i, InventoryType.SlotType.CONTAINER); if (slot == null) { - inventory.setItem(i, fillSlot); + inventory.setItem(i, FILL_SLOT); } else if (ItemUtils.isEmpty(inventory.getItem(i))) { inventory.setItem(i, slot.getCup()); } @@ -475,7 +475,7 @@ private static boolean isNewPlayer(Player player) { public static void loadPlayerInventory(Player player) { if (!InventoryManager.isAllowedWorld(player.getWorld())) { - INVENTORIES.remove(player.getUniqueId()); + InventoryManager.INVENTORIES.remove(player.getUniqueId()); return; } @@ -502,7 +502,7 @@ public static void loadPlayerInventory(Player player) { return; } - INVENTORIES.put(player.getUniqueId(), playerWrapper); + InventoryManager.INVENTORIES.put(player.getUniqueId(), playerWrapper); } catch (IOException e) { e.printStackTrace(); } @@ -520,11 +520,11 @@ public static void unloadPlayerInventory(@NotNull Player player) { player.closeInventory(); - INVENTORIES.get(player.getUniqueId()).onUnload(); + InventoryManager.INVENTORIES.get(player.getUniqueId()).onUnload(); savePlayerInventory(player); InventoryLocker.unlockSlots(player); - INVENTORIES.remove(player.getUniqueId()); + InventoryManager.INVENTORIES.remove(player.getUniqueId()); RPGInventory.getInstance().getServer().getPluginManager().callEvent(new PlayerInventoryUnloadEvent.Post(player)); } @@ -534,7 +534,7 @@ public static void savePlayerInventory(@NotNull Player player) { return; } - PlayerWrapper playerWrapper = INVENTORIES.get(player.getUniqueId()); + PlayerWrapper playerWrapper = InventoryManager.INVENTORIES.get(player.getUniqueId()); try { Path dataFolder = RPGInventory.getInstance().getDataPath(); Path folder = dataFolder.resolve("inventories"); @@ -553,7 +553,7 @@ public static PlayerWrapper get(@Nullable OfflinePlayer player) { if (player == null) { throw new IllegalArgumentException("OfflinePlayer can not be null!"); } - PlayerWrapper playerWrapper = INVENTORIES.get(player.getUniqueId()); + PlayerWrapper playerWrapper = InventoryManager.INVENTORIES.get(player.getUniqueId()); if (playerWrapper == null) { throw new IllegalArgumentException(player.getName() + "'s inventory is not loaded!"); } @@ -572,7 +572,7 @@ public static boolean isQuickEmptySlot(@Nullable ItemStack item) { } public static boolean isFilledSlot(@Nullable ItemStack item) { - return fillSlot.equals(item); + return InventoryManager.FILL_SLOT.equals(item); } public static boolean isEmptySlot(@Nullable ItemStack item) { @@ -588,7 +588,7 @@ public static boolean isEmptySlot(@Nullable ItemStack item) { @Contract("null -> false") @SuppressWarnings("BooleanMethodIsAlwaysInverted") public static boolean playerIsLoaded(@Nullable AnimalTamer player) { - return player != null && INVENTORIES.containsKey(player.getUniqueId()); + return player != null && InventoryManager.INVENTORIES.containsKey(player.getUniqueId()); } @SuppressWarnings("BooleanMethodIsAlwaysInverted") diff --git a/src/main/java/ru/endlesscode/rpginventory/inventory/slot/Slot.java b/src/main/java/ru/endlesscode/rpginventory/inventory/slot/Slot.java index cdee4ed..c7170ec 100644 --- a/src/main/java/ru/endlesscode/rpginventory/inventory/slot/Slot.java +++ b/src/main/java/ru/endlesscode/rpginventory/inventory/slot/Slot.java @@ -59,8 +59,8 @@ public class Slot { public Slot(String name, ConfigurationSection config) { this.name = name; this.slotType = SlotType.valueOf(config.getString("type")); - this.slotIds = config.getIntegerList("slot").size() == 0 ? Collections.singletonList(config.getInt("slot")) - : config.getIntegerList("slot"); + final List slotList = config.getIntegerList("slot"); + this.slotIds = slotList.isEmpty() ? Collections.singletonList(config.getInt("slot")) : slotList; this.requiredLevel = config.getInt("cost.required-level", 0); this.cost = config.getInt("cost.money", 0); this.drop = config.getBoolean("drop", true); diff --git a/src/main/java/ru/endlesscode/rpginventory/inventory/slot/SlotManager.java b/src/main/java/ru/endlesscode/rpginventory/inventory/slot/SlotManager.java index 81c5194..406b587 100644 --- a/src/main/java/ru/endlesscode/rpginventory/inventory/slot/SlotManager.java +++ b/src/main/java/ru/endlesscode/rpginventory/inventory/slot/SlotManager.java @@ -22,7 +22,8 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.event.inventory.InventoryType; -import org.jetbrains.annotations.*; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import ru.endlesscode.rpginventory.RPGInventory; import java.io.IOException; @@ -30,6 +31,7 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * Created by OsipXD on 05.09.2015 @@ -54,28 +56,28 @@ private SlotManager() { } this.slotsConfig = YamlConfiguration.loadConfiguration(slotsFile.toFile()); - - for (String key : this.slotsConfig.getConfigurationSection("slots").getKeys(false)) { - ConfigurationSection config = this.slotsConfig.getConfigurationSection("slots." + key); + final ConfigurationSection slots = this.slotsConfig.getConfigurationSection("slots"); + for (String slotName : slots.getKeys(false)) { + ConfigurationSection slotConfiguration = slots.getConfigurationSection(slotName); + Slot.SlotType slotType = Slot.SlotType.valueOf(slotConfiguration.getString("type")); Slot slot; - Slot.SlotType slotType = Slot.SlotType.valueOf(config.getString("type")); if (slotType == Slot.SlotType.ACTION) { - slot = new ActionSlot(key, config); + slot = new ActionSlot(slotName, slotConfiguration); } else { - slot = new Slot(key, config); + slot = new Slot(slotName, slotConfiguration); } if (this.validateSlot(slot)) { this.slots.add(slot); } else { - RPGInventory.getPluginLogger().warning("Slot " + slot.getName() + " not been added."); + RPGInventory.getPluginLogger().warning("Slot \"" + slot.getName() + "\" was not been added."); } } } public static boolean init() { try { - slotManager = new SlotManager(); + SlotManager.slotManager = new SlotManager(); } catch (Exception e) { e.printStackTrace(); return false; @@ -86,11 +88,7 @@ public static boolean init() { @NotNull public static SlotManager instance() { - if (slotManager == null) { - slotManager = new SlotManager(); - } - - return slotManager; + return Objects.requireNonNull(SlotManager.slotManager, "Plugin is not initialized yet."); } private boolean validateSlot(Slot slot) { @@ -176,7 +174,8 @@ public List getQuickSlots() { public List getPassiveSlots() { List passiveSlots = new ArrayList<>(); for (Slot slot : this.slots) { - if (slot.getSlotType() == Slot.SlotType.PASSIVE || slot.getSlotType() == Slot.SlotType.BACKPACK || slot.getSlotType() == Slot.SlotType.ELYTRA) { + final Slot.SlotType type = slot.getSlotType(); + if (type == Slot.SlotType.PASSIVE || type == Slot.SlotType.BACKPACK || type == Slot.SlotType.ELYTRA) { passiveSlots.add(slot); } } diff --git a/src/main/java/ru/endlesscode/rpginventory/pet/PetType.java b/src/main/java/ru/endlesscode/rpginventory/pet/PetType.java index 1f0fe4b..a5d43be 100644 --- a/src/main/java/ru/endlesscode/rpginventory/pet/PetType.java +++ b/src/main/java/ru/endlesscode/rpginventory/pet/PetType.java @@ -98,7 +98,6 @@ public static boolean isPetItem(ItemStack item) { } @Nullable - @Contract("null -> null") public static ItemStack clone(@NotNull ItemStack oldItem) { PetType petType = PetManager.getPetFromItem(oldItem); From fd383bc142d3fb18b1e62f9c10fa9776be2d6c92 Mon Sep 17 00:00:00 2001 From: Dereku Date: Fri, 13 Apr 2018 10:43:16 +0700 Subject: [PATCH 3/4] break -> return --- .../rpginventory/event/listener/ArmorEquipListener.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/endlesscode/rpginventory/event/listener/ArmorEquipListener.java b/src/main/java/ru/endlesscode/rpginventory/event/listener/ArmorEquipListener.java index 52bc2d8..7ff7b62 100644 --- a/src/main/java/ru/endlesscode/rpginventory/event/listener/ArmorEquipListener.java +++ b/src/main/java/ru/endlesscode/rpginventory/event/listener/ArmorEquipListener.java @@ -165,13 +165,13 @@ public void onDispenseEquip(BlockDispenseEvent event) { continue; } if (!InventoryManager.playerIsLoaded(player)) { - break; + return; } Slot armorSlot = SlotManager.instance().getSlot(type.name()); event.setCancelled(armorSlot != null && !InventoryManager.validateArmor(player, InventoryAction.PLACE_ONE, armorSlot, event.getItem())); - break; + return; } } From 3a99fe4b8612aed210e65377b69ab64eb8bcc422 Mon Sep 17 00:00:00 2001 From: Dereku Date: Fri, 13 Apr 2018 10:47:35 +0700 Subject: [PATCH 4/4] Ok Codacy, got it. --- .../event/listener/ArmorEquipListener.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/ru/endlesscode/rpginventory/event/listener/ArmorEquipListener.java b/src/main/java/ru/endlesscode/rpginventory/event/listener/ArmorEquipListener.java index 7ff7b62..e4dab34 100644 --- a/src/main/java/ru/endlesscode/rpginventory/event/listener/ArmorEquipListener.java +++ b/src/main/java/ru/endlesscode/rpginventory/event/listener/ArmorEquipListener.java @@ -164,14 +164,13 @@ public void onDispenseEquip(BlockDispenseEvent event) { if (this.hasInventoryArmorByType(type, player)) { continue; } - if (!InventoryManager.playerIsLoaded(player)) { + if (InventoryManager.playerIsLoaded(player)) { + Slot armorSlot = SlotManager.instance().getSlot(type.name()); + event.setCancelled(armorSlot != null + && !InventoryManager.validateArmor(player, InventoryAction.PLACE_ONE, armorSlot, event.getItem()) + ); return; } - - Slot armorSlot = SlotManager.instance().getSlot(type.name()); - event.setCancelled(armorSlot != null - && !InventoryManager.validateArmor(player, InventoryAction.PLACE_ONE, armorSlot, event.getItem())); - return; } }