diff --git a/pom.xml b/pom.xml
index b6168dc..a1ad657 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2,7 +2,7 @@
com.songoda
UltimateKits
4.0.0
- 2.6
+ 2.6.1
clean install
UltimateKits-${project.version}
diff --git a/src/main/java/com/songoda/ultimatekits/commands/CommandCrate.java b/src/main/java/com/songoda/ultimatekits/commands/CommandCrate.java
index 0d0953e..573e545 100644
--- a/src/main/java/com/songoda/ultimatekits/commands/CommandCrate.java
+++ b/src/main/java/com/songoda/ultimatekits/commands/CommandCrate.java
@@ -25,9 +25,7 @@ public class CommandCrate extends AbstractCommand {
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
- if (args.length < 3) return ReturnType.SYNTAX_ERROR;
-
- if (args.length > 4) return ReturnType.SYNTAX_ERROR;
+ if (args.length < 3 || args.length > 4) return ReturnType.SYNTAX_ERROR;
OfflinePlayer target = Bukkit.getPlayer(args[0]);
diff --git a/src/main/java/com/songoda/ultimatekits/crate/CrateManager.java b/src/main/java/com/songoda/ultimatekits/crate/CrateManager.java
index f46be21..fabe0a4 100644
--- a/src/main/java/com/songoda/ultimatekits/crate/CrateManager.java
+++ b/src/main/java/com/songoda/ultimatekits/crate/CrateManager.java
@@ -4,6 +4,7 @@ import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -12,8 +13,7 @@ public class CrateManager {
private final Set registeredCrates = new HashSet<>();
public boolean addCrate(Crate crate) {
- if (crate == null) return false;
- return registeredCrates.add(crate);
+ return crate != null && registeredCrates.add(crate);
}
public Crate getCrate(String name) {
for (Crate crate : registeredCrates)
@@ -30,7 +30,7 @@ public class CrateManager {
}
public Set getRegisteredCrates() {
- return registeredCrates;
+ return Collections.unmodifiableSet(registeredCrates);
}
public void clear() {
diff --git a/src/main/java/com/songoda/ultimatekits/gui/CategoryEditorGui.java b/src/main/java/com/songoda/ultimatekits/gui/CategoryEditorGui.java
index b958b79..c0692a9 100644
--- a/src/main/java/com/songoda/ultimatekits/gui/CategoryEditorGui.java
+++ b/src/main/java/com/songoda/ultimatekits/gui/CategoryEditorGui.java
@@ -10,6 +10,7 @@ import com.songoda.ultimatekits.category.Category;
import com.songoda.ultimatekits.category.CategoryManager;
import com.songoda.ultimatekits.settings.Settings;
import com.songoda.ultimatekits.utils.Methods;
+import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
@@ -51,7 +52,7 @@ public class CategoryEditorGui extends Gui {
categoryManager.addCategory(key, msg);
plugin.getLocale().newMessage("&aCategory added successfully!").sendPrefixedMessage(player);
- player.closeInventory();
+ Bukkit.getScheduler().runTask(plugin, player::closeInventory);
}).setOnClose(() -> {
event.manager.showGUI(event.player, new CategoryEditorGui(plugin, event.player));
});
diff --git a/src/main/java/com/songoda/ultimatekits/gui/KitEditorGui.java b/src/main/java/com/songoda/ultimatekits/gui/KitEditorGui.java
index 22a32ff..5da5997 100644
--- a/src/main/java/com/songoda/ultimatekits/gui/KitEditorGui.java
+++ b/src/main/java/com/songoda/ultimatekits/gui/KitEditorGui.java
@@ -257,7 +257,7 @@ public class KitEditorGui extends DoubleGui {
.sendPrefixedMessage(player);
this.inventory.addItem(parseStack);
- player.closeInventory();
+ Bukkit.getScheduler().runTask(plugin, event.player::closeInventory);
}).setOnClose(() -> {
event.manager.showGUI(event.player, this);
})
diff --git a/src/main/java/com/songoda/ultimatekits/gui/KitGeneralOptionsGui.java b/src/main/java/com/songoda/ultimatekits/gui/KitGeneralOptionsGui.java
index 4faae3e..20bf5cb 100644
--- a/src/main/java/com/songoda/ultimatekits/gui/KitGeneralOptionsGui.java
+++ b/src/main/java/com/songoda/ultimatekits/gui/KitGeneralOptionsGui.java
@@ -46,7 +46,7 @@ public class KitGeneralOptionsGui extends Gui {
AnvilGui gui = new AnvilGui(event.player, this);
gui.setTitle(plugin.getLocale().getMessage("interface.kitoptions.delayprompt").getMessage());
gui.setAction(aevent -> {
- final String msg = gui.getInputText();
+ final String msg = gui.getInputText().trim();
try {
kit.setDelay(Integer.parseInt(msg));
updateItemLore(event.slot, plugin.getLocale().getMessage("interface.kitoptions.delaylore")
diff --git a/src/main/java/com/songoda/ultimatekits/handlers/ParticleHandler.java b/src/main/java/com/songoda/ultimatekits/handlers/ParticleHandler.java
index 488654f..b56ca98 100644
--- a/src/main/java/com/songoda/ultimatekits/handlers/ParticleHandler.java
+++ b/src/main/java/com/songoda/ultimatekits/handlers/ParticleHandler.java
@@ -7,6 +7,7 @@ import com.songoda.ultimatekits.settings.Settings;
import org.bukkit.Bukkit;
import org.bukkit.Location;
+import java.util.ArrayList;
import java.util.Map;
/**
@@ -35,7 +36,7 @@ public class ParticleHandler {
private void applyParticles() {
Map kitBlocks = plugin.getKitManager().getKitLocations();
- for (KitBlockData kitBlockData : kitBlocks.values()) {
+ for (KitBlockData kitBlockData : new ArrayList<>(kitBlocks.values())) {
if (kitBlockData.getLocation().getWorld() == null || !kitBlockData.hasParticles()) continue;
Location location = kitBlockData.getLocation();
diff --git a/src/main/java/com/songoda/ultimatekits/kit/Kit.java b/src/main/java/com/songoda/ultimatekits/kit/Kit.java
index 88d4466..8858e3b 100644
--- a/src/main/java/com/songoda/ultimatekits/kit/Kit.java
+++ b/src/main/java/com/songoda/ultimatekits/kit/Kit.java
@@ -1,5 +1,6 @@
package com.songoda.ultimatekits.kit;
+import com.songoda.core.compatibility.CompatibleHand;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.CompatibleSound;
import com.songoda.core.compatibility.ServerVersion;
@@ -7,6 +8,7 @@ import com.songoda.core.configuration.Config;
import com.songoda.core.gui.Gui;
import com.songoda.core.gui.GuiManager;
import com.songoda.core.hooks.EconomyManager;
+import com.songoda.core.utils.ItemUtils;
import com.songoda.core.utils.TextUtils;
import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.category.Category;
@@ -128,18 +130,13 @@ public class Kit {
}
}
- public void processCrateUse(Player player, ItemStack item) {
+ public void processCrateUse(Player player, ItemStack item, CompatibleHand hand) {
Crate crate = plugin.getCrateManager().getCrate(item);
- if (crate == null) {
+ if (crate == null || !giveKit(player, crate))
return;
- }
- if (!giveKit(player, crate)) {
- return;
- }
-
- Methods.consumeItem(player, item);
+ ItemUtils.takeActiveItem(player, hand);
plugin.getLocale().getMessage("event.crate.success")
.processPlaceholder("crate", name).sendPrefixedMessage(player);
@@ -284,8 +281,7 @@ public class Kit {
}
private boolean giveKit(Player player, Key key) {
- if (key == null) return giveKit(player);
- return giveKit(player, key.getAmount(), key.getKitAmount());
+ return key == null ? giveKit(player) : giveKit(player, key.getAmount(), key.getKitAmount());
}
private boolean giveKit(Player player, Crate crate) {
diff --git a/src/main/java/com/songoda/ultimatekits/listeners/InteractListeners.java b/src/main/java/com/songoda/ultimatekits/listeners/InteractListeners.java
index adc8030..dcecf5d 100644
--- a/src/main/java/com/songoda/ultimatekits/listeners/InteractListeners.java
+++ b/src/main/java/com/songoda/ultimatekits/listeners/InteractListeners.java
@@ -1,5 +1,6 @@
package com.songoda.ultimatekits.listeners;
+import com.songoda.core.compatibility.CompatibleHand;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.core.gui.GuiManager;
@@ -98,9 +99,10 @@ public class InteractListeners implements Listener {
public void onCrateClick(PlayerInteractEvent event) {
// Would be better to use NBT to make the item persist over aesthetic changes.
- if (event.getAction() == Action.PHYSICAL || // Filter physical actions (pressure plates, buttons)
- event.getItem() == null ||
- event.getItem().getType() == CompatibleMaterial.AIR.getMaterial())
+ // Filter physical actions (pressure plates, buttons)
+ if (event.getAction() == Action.PHYSICAL
+ || event.getItem() == null
+ || event.getItem().getType() == CompatibleMaterial.AIR.getMaterial())
return;
ItemStack item = event.getItem();
@@ -117,7 +119,7 @@ public class InteractListeners implements Listener {
// Function
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
// Open the crate
- kit.processCrateUse(player, item);
+ kit.processCrateUse(player, item, CompatibleHand.getHand(event));
} else // There are only left click actions left
kit.display(player, guiManager, null);
}
diff --git a/src/main/java/com/songoda/ultimatekits/utils/Methods.java b/src/main/java/com/songoda/ultimatekits/utils/Methods.java
index 93d8448..ab7cce1 100644
--- a/src/main/java/com/songoda/ultimatekits/utils/Methods.java
+++ b/src/main/java/com/songoda/ultimatekits/utils/Methods.java
@@ -34,23 +34,6 @@ public class Methods {
return false;
}
- public static void consumeItem(Player player, ItemStack original) {
- ItemStack item = original.clone();
-
- // Remove or lower amount
- if (item.getAmount() > 1)
- item.setAmount(item.getAmount() - 1);
- else item = null;
-
- // setItemInHand doesn't work with off hand, would result in a bug (endless crate/key opening)
- if (ServerVersion.isServerVersionAbove(ServerVersion.V1_8)) {
- if (original.isSimilar(player.getInventory().getItemInMainHand()))
- player.getInventory().setItemInMainHand(item);
- else if (original.isSimilar(player.getInventory().getItemInOffHand()))
- player.getInventory().setItemInOffHand(item);
- } else player.setItemInHand(item);
- }
-
/**
* Serializes the location of the block specified.
*