Merge branch 'development'

This commit is contained in:
Brianna 2020-04-13 04:37:47 -04:00
commit cf8e896e5e
10 changed files with 23 additions and 42 deletions

View File

@ -2,7 +2,7 @@
<groupId>com.songoda</groupId>
<artifactId>UltimateKits</artifactId>
<modelVersion>4.0.0</modelVersion>
<version>2.6</version>
<version>2.6.1</version>
<build>
<defaultGoal>clean install</defaultGoal>
<finalName>UltimateKits-${project.version}</finalName>

View File

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

View File

@ -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<Crate> 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<Crate> getRegisteredCrates() {
return registeredCrates;
return Collections.unmodifiableSet(registeredCrates);
}
public void clear() {

View File

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

View File

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

View File

@ -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")

View File

@ -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<Location, KitBlockData> 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();

View File

@ -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) {

View File

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

View File

@ -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.
*