Merge branch 'development'
This commit is contained in:
commit
1bb603fe91
2
pom.xml
2
pom.xml
|
@ -2,7 +2,7 @@
|
|||
<groupId>com.songoda</groupId>
|
||||
<artifactId>UltimateKits</artifactId>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>2.5.2</version>
|
||||
<version>2.6</version>
|
||||
<build>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<finalName>UltimateKits-${project.version}</finalName>
|
||||
|
|
|
@ -17,6 +17,8 @@ import com.songoda.ultimatekits.category.Category;
|
|||
import com.songoda.ultimatekits.category.CategoryManager;
|
||||
import com.songoda.ultimatekits.commands.*;
|
||||
import com.songoda.ultimatekits.conversion.Convert;
|
||||
import com.songoda.ultimatekits.crate.Crate;
|
||||
import com.songoda.ultimatekits.crate.CrateManager;
|
||||
import com.songoda.ultimatekits.database.DataManager;
|
||||
import com.songoda.ultimatekits.database.migrations._1_InitialMigration;
|
||||
import com.songoda.ultimatekits.database.migrations._2_DuplicateMigration;
|
||||
|
@ -47,6 +49,7 @@ public class UltimateKits extends SongodaPlugin {
|
|||
private final Config categoryConfig = new Config(this, "category.yml");
|
||||
private final Config dataFile = new Config(this, "data.yml");
|
||||
private final Config keyFile = new Config(this, "keys.yml");
|
||||
private final Config crateFile = new Config(this, "crates.yml");
|
||||
|
||||
private final GuiManager guiManager = new GuiManager(this);
|
||||
private final ParticleHandler particleHandler = new ParticleHandler(this);
|
||||
|
@ -55,6 +58,7 @@ public class UltimateKits extends SongodaPlugin {
|
|||
private KitManager kitManager;
|
||||
private CommandManager commandManager;
|
||||
private KeyManager keyManager;
|
||||
private CrateManager crateManager;
|
||||
private CategoryManager categoryManager;
|
||||
|
||||
private ItemSerializer itemSerializer;
|
||||
|
@ -103,6 +107,7 @@ public class UltimateKits extends SongodaPlugin {
|
|||
|
||||
this.kitManager = new KitManager();
|
||||
this.keyManager = new KeyManager();
|
||||
this.crateManager = new CrateManager();
|
||||
this.categoryManager = new CategoryManager(this);
|
||||
|
||||
kitConfig.load();
|
||||
|
@ -113,9 +118,12 @@ public class UltimateKits extends SongodaPlugin {
|
|||
// load kits
|
||||
dataFile.load();
|
||||
keyFile.load();
|
||||
crateFile.load();
|
||||
checkKeyDefaults();
|
||||
checkCrateDefaults();
|
||||
loadKits();
|
||||
keyFile.saveChanges();
|
||||
crateFile.saveChanges();
|
||||
|
||||
// setup commands
|
||||
this.commandManager = new CommandManager(this);
|
||||
|
@ -129,7 +137,9 @@ public class UltimateKits extends SongodaPlugin {
|
|||
.addSubCommand(new CommandEdit(guiManager))
|
||||
.addSubCommand(new CommandKey())
|
||||
.addSubCommand(new CommandSet())
|
||||
.addSubCommand(new CommandRemove());
|
||||
.addSubCommand(new CommandRemove())
|
||||
|
||||
.addSubCommand(new CommandCrate());
|
||||
|
||||
|
||||
// Event registration
|
||||
|
@ -186,7 +196,7 @@ public class UltimateKits extends SongodaPlugin {
|
|||
|
||||
@Override
|
||||
public List<Config> getExtraConfig() {
|
||||
return Arrays.asList(kitConfig, keyFile, categoryConfig);
|
||||
return Arrays.asList(kitConfig, keyFile, categoryConfig, crateFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -196,6 +206,8 @@ public class UltimateKits extends SongodaPlugin {
|
|||
this.dataManager.bulkUpdateBlockData(this.getKitManager().getKitLocations());
|
||||
kitConfig.load();
|
||||
categoryConfig.load();
|
||||
keyFile.load();
|
||||
crateFile.load();
|
||||
loadKits();
|
||||
}
|
||||
|
||||
|
@ -277,9 +289,11 @@ public class UltimateKits extends SongodaPlugin {
|
|||
|
||||
//Apply default keys.
|
||||
checkKeyDefaults();
|
||||
checkCrateDefaults();
|
||||
|
||||
//Empty keys from manager.
|
||||
keyManager.clear();
|
||||
crateManager.clear();
|
||||
|
||||
/*
|
||||
* Register keys into KitManager from Configuration.
|
||||
|
@ -293,6 +307,19 @@ public class UltimateKits extends SongodaPlugin {
|
|||
keyManager.addKey(key);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Register Crates
|
||||
* */
|
||||
if (crateFile.contains("Crates")) {
|
||||
for (String crateName : crateFile.getConfigurationSection("Crates").getKeys(false)) {
|
||||
int amt = crateFile.getInt("Crates." + crateName + ".Item Amount");
|
||||
int kitAmount = crateFile.getInt("Crates." + crateName + ".Amount of kit received");
|
||||
|
||||
Crate crate = new Crate(crateName, amt, kitAmount);
|
||||
crateManager.addCrate(crate);
|
||||
}
|
||||
}
|
||||
this.loaded = true;
|
||||
|
||||
}, 10);
|
||||
|
@ -464,7 +491,6 @@ public class UltimateKits extends SongodaPlugin {
|
|||
categoryConfig.set("Categories." + category.getKey() + ".material", category.getMaterial().name());
|
||||
}
|
||||
|
||||
|
||||
// Save to file
|
||||
kitConfig.saveChanges();
|
||||
categoryConfig.saveChanges();
|
||||
|
@ -484,6 +510,17 @@ public class UltimateKits extends SongodaPlugin {
|
|||
keyFile.set("Keys.Insane.Amount of kit received", 2);
|
||||
}
|
||||
|
||||
private void checkCrateDefaults() {
|
||||
if (crateFile.contains("Crates")) return;
|
||||
crateFile.set("Crates.Regular.Item Amount", 3);
|
||||
crateFile.set("Crates.Regular.Amount overrides", Collections.singletonList("Tools:2"));
|
||||
crateFile.set("Crates.Regular.Amount of kit received", 1);
|
||||
crateFile.set("Crates.Ultra.Item Amount", -1);
|
||||
crateFile.set("Crates.Ultra.Amount of kit received", 1);
|
||||
crateFile.set("Crates.Insane.Item Amount", -1);
|
||||
crateFile.set("Crates.Insane.Amount of kit received", 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get instance of KitManager
|
||||
*
|
||||
|
@ -502,6 +539,10 @@ public class UltimateKits extends SongodaPlugin {
|
|||
return keyManager;
|
||||
}
|
||||
|
||||
public CrateManager getCrateManager() {
|
||||
return crateManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab instance of Kit File Configuration Wrapper
|
||||
*
|
||||
|
|
|
@ -0,0 +1,134 @@
|
|||
package com.songoda.ultimatekits.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.crate.Crate;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandCrate extends AbstractCommand {
|
||||
|
||||
public CommandCrate() {
|
||||
super(CommandType.CONSOLE_OK, "crate");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
|
||||
if (args.length < 3) return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
if (args.length > 4) return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
OfflinePlayer target = Bukkit.getPlayer(args[0]);
|
||||
|
||||
if (!args[0].equalsIgnoreCase("all") && (target == null || !target.isOnline())) {
|
||||
UltimateKits.getInstance().getLocale().newMessage("&cThat username does not exist, or the user is offline!").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
Kit kit = UltimateKits.getInstance().getKitManager().getKit(args[1]);
|
||||
|
||||
if (kit == null) {
|
||||
UltimateKits.getInstance().getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
Crate crate = UltimateKits.getInstance().getCrateManager().getCrate(args[2]);
|
||||
|
||||
if (crate == null) {
|
||||
UltimateKits.getInstance().getLocale().getMessage("command.crate.doesntexist").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
int amount = 1;
|
||||
if (args.length > 3) {
|
||||
if (!Methods.isNumeric(args[3])) {
|
||||
amount = 0;
|
||||
} else {
|
||||
amount = Integer.parseInt(args[3]);
|
||||
}
|
||||
}
|
||||
|
||||
if (amount == 0) {
|
||||
UltimateKits.getInstance().getLocale().newMessage("&a" + args[3] + " &cis not a number.").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
ItemStack item = crate.getCrateItem(kit, amount);
|
||||
|
||||
if (args[0].equalsIgnoreCase("all")) {
|
||||
// Give and send msg to all players online
|
||||
for (Player loopPlayer : Bukkit.getOnlinePlayers()) {
|
||||
loopPlayer.getInventory().addItem(item);
|
||||
UltimateKits.getInstance().getLocale().getMessage("event.crate.given")
|
||||
.processPlaceholder("kit", kit.getName())
|
||||
.processPlaceholder("crate", crate.getName())
|
||||
.sendPrefixedMessage(loopPlayer);
|
||||
}
|
||||
} else {
|
||||
// Give to player and send msg
|
||||
target.getPlayer().getInventory().addItem(item);
|
||||
UltimateKits.getInstance().getLocale().getMessage("event.crate.given")
|
||||
.processPlaceholder("kit", kit.getName())
|
||||
.processPlaceholder("crate", crate.getName())
|
||||
.sendPrefixedMessage(target.getPlayer());
|
||||
}
|
||||
|
||||
// Send msg to admin
|
||||
UltimateKits.getInstance().getLocale().getMessage("command.crate.given")
|
||||
.processPlaceholder("kit", kit.getName())
|
||||
.processPlaceholder("crate", crate.getName())
|
||||
.processPlaceholder("player", args[0].equalsIgnoreCase("all") ? "all players" : target.getName());
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
List<String> tab = new ArrayList<>();
|
||||
|
||||
if (args.length == 1) {
|
||||
// Players
|
||||
tab.add("all");
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
tab.add(player.getName());
|
||||
return tab;
|
||||
} else if (args.length == 2) {
|
||||
// Kits
|
||||
return UltimateKits.getInstance().getKitManager().getKits().stream()
|
||||
.map(Kit::getName).collect(Collectors.toList());
|
||||
} else if (args.length == 3) {
|
||||
// Crates
|
||||
return UltimateKits.getInstance().getCrateManager().getRegisteredCrates().stream()
|
||||
.map(Crate::getName).collect(Collectors.toList());
|
||||
} else if (args.length == 4) {
|
||||
return Collections.singletonList("amount");
|
||||
}
|
||||
|
||||
return tab;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "ultimatekits.admin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/KitAdmin crate <player/all> <kit> <crate> (amount)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Gives a crate to a player.";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,114 @@
|
|||
package com.songoda.ultimatekits.crate;
|
||||
|
||||
import com.songoda.core.utils.TextUtils;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Crate {
|
||||
|
||||
// Name of the crate
|
||||
private String name;
|
||||
|
||||
// The amount of items this crate will give you
|
||||
private int amount;
|
||||
|
||||
// The amount of kits the player is given
|
||||
private int kitAmount;
|
||||
|
||||
public Crate(String name, int amount, int kitAmount) {
|
||||
this.name = name;
|
||||
this.amount = amount;
|
||||
this.kitAmount = kitAmount;
|
||||
}
|
||||
|
||||
public ItemStack getCrateItem(Kit kit, int amount) {
|
||||
UltimateKits plugin = UltimateKits.getInstance();
|
||||
|
||||
ItemStack itemStack = new ItemStack(Material.CHEST, amount);
|
||||
|
||||
String kitName;
|
||||
if (kit != null)
|
||||
kitName = TextUtils.formatText(kit.getName(), true);
|
||||
else
|
||||
kitName = "Any";
|
||||
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
meta.setDisplayName(plugin.getLocale().getMessage("interface.crate.title")
|
||||
.processPlaceholder("kit", kitName)
|
||||
.processPlaceholder("crate", name)
|
||||
.getMessage());
|
||||
|
||||
meta.addEnchant(Enchantment.DURABILITY, 1, true);
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
// Dtools Ultra Crate
|
||||
lore.add(ChatColor.DARK_PURPLE + kitName + " " + ChatColor.YELLOW + name + " " + ChatColor.WHITE + "Crate");
|
||||
|
||||
String desc1 = plugin.getLocale().getMessage("interface.crate.description1")
|
||||
.processPlaceholder("kit", kitName)
|
||||
.processPlaceholder("crate", name)
|
||||
.getMessage();
|
||||
|
||||
if (kitName.equals("Any"))
|
||||
desc1 = desc1.replaceAll("\\[.*?]", "");
|
||||
else
|
||||
desc1 = desc1.replace("[", "").replace("]", "");
|
||||
|
||||
lore.add(desc1);
|
||||
if (this.amount == -1)
|
||||
lore.add(plugin.getLocale().getMessage("interface.crate.description2")
|
||||
.processPlaceholder("kit", kitName)
|
||||
.processPlaceholder("crate", name)
|
||||
.getMessage());
|
||||
else
|
||||
lore.add(plugin.getLocale().getMessage("interface.crate.description3")
|
||||
.processPlaceholder("kit", kitName)
|
||||
.processPlaceholder("crate", name)
|
||||
.getMessage());
|
||||
if (kitAmount > 1)
|
||||
lore.add(plugin.getLocale().getMessage("interface.crate.description4")
|
||||
.processPlaceholder("amt", this.kitAmount)
|
||||
.processPlaceholder("kit", kitName)
|
||||
.processPlaceholder("crate", name)
|
||||
.getMessage());
|
||||
|
||||
meta.setLore(lore);
|
||||
|
||||
itemStack.setItemMeta(meta);
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(int amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public int getKitAmount() {
|
||||
return kitAmount;
|
||||
}
|
||||
|
||||
public void setKitAmount(int kitAmount) {
|
||||
this.kitAmount = kitAmount;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.songoda.ultimatekits.crate;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class CrateManager {
|
||||
|
||||
private final Set<Crate> registeredCrates = new HashSet<>();
|
||||
|
||||
public boolean addCrate(Crate crate) {
|
||||
if (crate == null) return false;
|
||||
return registeredCrates.add(crate);
|
||||
}
|
||||
public Crate getCrate(String name) {
|
||||
for (Crate crate : registeredCrates)
|
||||
if (crate.getName().equalsIgnoreCase(name))
|
||||
return crate;
|
||||
return null;
|
||||
}
|
||||
|
||||
public Crate getCrate(ItemStack item) {
|
||||
if (item == null || !item.hasItemMeta() || !item.getItemMeta().hasLore() || item.getType() != Material.CHEST)
|
||||
return null;
|
||||
|
||||
return getCrate(ChatColor.stripColor(item.getItemMeta().getLore().get(0)).split(" ")[1]);
|
||||
}
|
||||
|
||||
public Set<Crate> getRegisteredCrates() {
|
||||
return registeredCrates;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
registeredCrates.clear();
|
||||
}
|
||||
}
|
|
@ -52,9 +52,8 @@ public class KitEditorGui extends DoubleGui {
|
|||
|
||||
setInvItems();
|
||||
setOnClose((event) -> {
|
||||
restoreItemsInstance();
|
||||
this.saveKit(player, inventory, false);
|
||||
if (!isInInventory)
|
||||
restoreItemsInstance();
|
||||
CompatibleSound.ENTITY_VILLAGER_YES.play(player);
|
||||
});
|
||||
|
||||
|
@ -72,7 +71,7 @@ public class KitEditorGui extends DoubleGui {
|
|||
setButton(0, 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(CompatibleMaterial.OAK_DOOR),
|
||||
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
|
||||
ClickType.LEFT,
|
||||
event -> exit());
|
||||
event -> player.closeInventory());
|
||||
|
||||
// back button
|
||||
if (parent != null)
|
||||
|
@ -197,6 +196,8 @@ public class KitEditorGui extends DoubleGui {
|
|||
}
|
||||
|
||||
private void restoreItemsInstance() {
|
||||
if (!isInInventory)
|
||||
player.getInventory().clear();
|
||||
setPlayerUnlockedRange(0, 0, 3, 8);
|
||||
if (stash != null)
|
||||
player.getInventory().setContents(stash);
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.songoda.ultimatekits.kit;
|
|||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.CompatibleSound;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import com.songoda.core.configuration.Config;
|
||||
import com.songoda.core.gui.Gui;
|
||||
import com.songoda.core.gui.GuiManager;
|
||||
|
@ -9,6 +10,7 @@ import com.songoda.core.hooks.EconomyManager;
|
|||
import com.songoda.core.utils.TextUtils;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.category.Category;
|
||||
import com.songoda.ultimatekits.crate.Crate;
|
||||
import com.songoda.ultimatekits.gui.AnimatedKitGui;
|
||||
import com.songoda.ultimatekits.gui.ConfirmBuyGui;
|
||||
import com.songoda.ultimatekits.gui.PreviewKitGui;
|
||||
|
@ -126,6 +128,23 @@ public class Kit {
|
|||
}
|
||||
}
|
||||
|
||||
public void processCrateUse(Player player, ItemStack item) {
|
||||
Crate crate = plugin.getCrateManager().getCrate(item);
|
||||
|
||||
if (crate == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!giveKit(player, crate)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Methods.consumeItem(player, item);
|
||||
|
||||
plugin.getLocale().getMessage("event.crate.success")
|
||||
.processPlaceholder("crate", name).sendPrefixedMessage(player);
|
||||
}
|
||||
|
||||
public void processPurchaseUse(Player player) {
|
||||
if (!EconomyManager.isEnabled()) return;
|
||||
|
||||
|
@ -261,23 +280,33 @@ public class Kit {
|
|||
}
|
||||
|
||||
public boolean giveKit(Player player) {
|
||||
return giveKit(player, null);
|
||||
return giveKit(player, -1, -1);
|
||||
}
|
||||
|
||||
private boolean giveKit(Player player, Key key) {
|
||||
if (key == null) return giveKit(player);
|
||||
return giveKit(player, key.getAmount(), key.getKitAmount());
|
||||
}
|
||||
|
||||
private boolean giveKit(Player player, Crate crate) {
|
||||
return giveKit(player, crate.getAmount(), crate.getKitAmount());
|
||||
}
|
||||
|
||||
private boolean giveKit(Player player, int itemAmount, int kitAmount) {
|
||||
if (Settings.NO_REDEEM_WHEN_FULL.getBoolean() && !hasRoom(player)) {
|
||||
plugin.getLocale().getMessage("event.claim.full").sendPrefixedMessage(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Settings.SOUNDS_ENABLED.getBoolean() && kitAnimation == KitAnimation.NONE)
|
||||
CompatibleSound.ENTITY_PLAYER_LEVELUP.play(player, 0.6F, 15.0F);
|
||||
|
||||
List<KitItem> innerContents = new ArrayList<>(getContents());
|
||||
int kitSize = innerContents.size();
|
||||
|
||||
// Amount of items from the kit to give to the player.
|
||||
int itemGiveAmount = key == null ? kitSize : key.getAmount();
|
||||
if (itemGiveAmount == -1) itemGiveAmount = kitSize;
|
||||
if (key != null) itemGiveAmount = itemGiveAmount * key.getKitAmount();
|
||||
int itemGiveAmount = itemAmount > 0 ? itemAmount : kitSize;
|
||||
if (kitAmount > 0) itemGiveAmount = itemGiveAmount * kitAmount;
|
||||
|
||||
return generateRandomItem(innerContents, itemGiveAmount, player, -1);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.songoda.ultimatekits.listeners;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import com.songoda.core.gui.GuiManager;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
|
@ -8,6 +9,7 @@ import com.songoda.ultimatekits.kit.Kit;
|
|||
import com.songoda.ultimatekits.kit.KitBlockData;
|
||||
import com.songoda.ultimatekits.kit.KitType;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -17,6 +19,7 @@ import org.bukkit.event.block.Action;
|
|||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class InteractListeners implements Listener {
|
||||
|
||||
|
@ -90,5 +93,32 @@ public class InteractListeners implements Listener {
|
|||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
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())
|
||||
return;
|
||||
|
||||
ItemStack item = event.getItem();
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (!item.hasItemMeta() || !item.getItemMeta().hasLore()) return;
|
||||
|
||||
Kit kit = UltimateKits.getInstance().getKitManager().getKit(ChatColor.stripColor(item.getItemMeta().getLore().get(0).split(" ")[0]));
|
||||
|
||||
if (kit == null) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
// Function
|
||||
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
// Open the crate
|
||||
kit.processCrateUse(player, item);
|
||||
} else // There are only left click actions left
|
||||
kit.display(player, guiManager, null);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package com.songoda.ultimatekits.utils;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import com.songoda.core.gui.Gui;
|
||||
import com.songoda.core.gui.GuiUtils;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
|
@ -33,6 +34,23 @@ 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.
|
||||
*
|
||||
|
|
|
@ -55,6 +55,12 @@ interface:
|
|||
description2: '&rand receive its contents!'
|
||||
description3: '&rand receive some of its contents!'
|
||||
description4: '&rGives kit &c&l%amt% &rtimes.'
|
||||
crate:
|
||||
title: '&5%kit% &f%crate% Crate'
|
||||
description1: '&rRight-Click to open'
|
||||
description2: '&rand receive its contents!'
|
||||
description3: '&rand receive some of its contents!'
|
||||
description4: '&rLeft-Click to preview'
|
||||
|
||||
# Administrative interfaces
|
||||
|
||||
|
@ -170,6 +176,9 @@ command:
|
|||
nokitatblock: '&8This block does not contain a kit.'
|
||||
kitalreadyexists: '&cThat kit already exists.'
|
||||
playernotfound: '&cThis player is not online or doesn''t exist.'
|
||||
crate:
|
||||
given: '&9Gave &7%player% &9crate &7%crate% &9for kit &7%kit%.'
|
||||
doesntexist: '&cThis crate is not loaded.'
|
||||
|
||||
# Event Messages
|
||||
|
||||
|
@ -179,6 +188,8 @@ event:
|
|||
crate:
|
||||
notyet: '&cYou need to wait &4%time% &cbefore you can use this.'
|
||||
wrongkey: '&cThis key doesn''t belong to this kit..'
|
||||
success: '&9Successfully opened a crate.'
|
||||
given: '&9You have received a %crate% %kit% crate.'
|
||||
claim:
|
||||
cannotafford: '&9You cannot afford to buy kit &7%kit%&9.'
|
||||
nottwice: '&9You can only receive this kit once.'
|
||||
|
|
Loading…
Reference in New Issue