mirror of
https://github.com/songoda/UltimateKits.git
synced 2024-11-23 02:35:28 +01:00
Moved kit keys to nbt.
This commit is contained in:
parent
a54eddc3e7
commit
5a1643c59d
@ -301,8 +301,9 @@ public class UltimateKits extends SongodaPlugin {
|
||||
for (String keyName : keyFile.getConfigurationSection("Keys").getKeys(false)) {
|
||||
int amt = keyFile.getInt("Keys." + keyName + ".Item Amount");
|
||||
int kitAmount = keyFile.getInt("Keys." + keyName + ".Amount of kit received");
|
||||
boolean enchanted = keyFile.getBoolean("Keys." + keyName + ".Enchanted");
|
||||
|
||||
Key key = new Key(keyName, amt, kitAmount);
|
||||
Key key = new Key(keyName, amt, kitAmount, enchanted);
|
||||
keyManager.addKey(key);
|
||||
}
|
||||
}
|
||||
@ -507,6 +508,7 @@ public class UltimateKits extends SongodaPlugin {
|
||||
keyFile.set("Keys.Ultra.Amount of kit received", 1);
|
||||
keyFile.set("Keys.Insane.Item Amount", -1);
|
||||
keyFile.set("Keys.Insane.Amount of kit received", 2);
|
||||
keyFile.set("Keys.Insane.Enchanted", true);
|
||||
}
|
||||
|
||||
private void checkCrateDefaults() {
|
||||
|
@ -1,57 +1,62 @@
|
||||
package com.songoda.ultimatekits.key;
|
||||
|
||||
import com.songoda.core.nms.NmsManager;
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import com.songoda.core.utils.ItemUtils;
|
||||
import com.songoda.core.utils.TextUtils;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import com.songoda.ultimatekits.settings.Settings;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class Key {
|
||||
|
||||
// The name of the key.
|
||||
private String name;
|
||||
private final String name;
|
||||
|
||||
// The amount of items this key will give you. -1 is all;
|
||||
private int amount;
|
||||
private final int amount;
|
||||
|
||||
// Should the key be enchanted?
|
||||
private final boolean enchanted;
|
||||
|
||||
// The amount of kit given when the key is used.
|
||||
private int kitAmount;
|
||||
private final int kitAmount;
|
||||
|
||||
public Key(String name, int amount, int kitAmount) {
|
||||
public Key(String name, int amount, int kitAmount, boolean enchanted) {
|
||||
this.name = name;
|
||||
this.amount = amount;
|
||||
this.kitAmount = kitAmount;
|
||||
this.enchanted = enchanted;
|
||||
}
|
||||
|
||||
|
||||
public ItemStack getKeyItem(Kit kit, int amt) {
|
||||
public ItemStack getKeyItem(Kit kit, int amount) {
|
||||
UltimateKits plugin = UltimateKits.getInstance();
|
||||
ItemStack is = new ItemStack(Material.TRIPWIRE_HOOK, amt);
|
||||
ItemStack item = Settings.KEY_MATERIAL.getMaterial().getItem();
|
||||
item.setAmount(amount);
|
||||
|
||||
String kitName;
|
||||
if (kit != null)
|
||||
kitName = TextUtils.formatText(kit.getName(), true);
|
||||
else
|
||||
kitName = "Any";
|
||||
String kitName = kit != null ? TextUtils.formatText(kit.getName(), true)
|
||||
: plugin.getLocale().getMessage("general.type.any").getMessage();
|
||||
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(plugin.getLocale().getMessage("interface.key.title")
|
||||
.processPlaceholder("kit", kitName).getMessage());
|
||||
|
||||
meta.addEnchant(Enchantment.DURABILITY, 1, true);
|
||||
if (enchanted)
|
||||
ItemUtils.addGlow(item);
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(ChatColor.YELLOW + name + " " + ChatColor.WHITE + "Key");
|
||||
lore.add(plugin.getLocale().getMessage("interface.key.name")
|
||||
.processPlaceholder("name", name).getMessage());
|
||||
|
||||
String desc1 = plugin.getLocale().getMessage("interface.key.description1")
|
||||
.processPlaceholder("kit", kitName).getMessage();
|
||||
|
||||
if (kitName.equals("Any"))
|
||||
if (kit == null)
|
||||
desc1 = desc1.replaceAll("\\[.*?\\]", "");
|
||||
else
|
||||
desc1 = desc1.replace("[", "").replace("]", "");
|
||||
@ -66,12 +71,15 @@ public class Key {
|
||||
.processPlaceholder("amt", this.kitAmount).getMessage());
|
||||
meta.setLore(lore);
|
||||
|
||||
is.setItemMeta(meta);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
return is;
|
||||
NBTItem nbtItem = NmsManager.getNbt().of(item);
|
||||
nbtItem.set("key", name);
|
||||
nbtItem.set("kit", kit == null ? "ANY" : kit.getName());
|
||||
|
||||
return nbtItem.finish();
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@ -83,4 +91,8 @@ public class Key {
|
||||
public int getKitAmount() {
|
||||
return kitAmount;
|
||||
}
|
||||
|
||||
public boolean isEnchanted() {
|
||||
return enchanted;
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ 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.nms.NmsManager;
|
||||
import com.songoda.core.nms.nbt.NBTItem;
|
||||
import com.songoda.core.utils.ItemUtils;
|
||||
import com.songoda.core.utils.TextUtils;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
@ -99,27 +101,25 @@ public class Kit {
|
||||
|
||||
public void processKeyUse(Player player) {
|
||||
ItemStack item = player.getItemInHand();
|
||||
if (item.getType() != Material.TRIPWIRE_HOOK || !item.hasItemMeta()) {
|
||||
NBTItem nbtItem = NmsManager.getNbt().of(item);
|
||||
|
||||
if (!nbtItem.has("key") || !nbtItem.has("kit"))
|
||||
return;
|
||||
}
|
||||
Key key = plugin.getKeyManager().getKey(ChatColor.stripColor(item.getItemMeta().getLore().get(0)).replace(" Key", ""));
|
||||
|
||||
// This is some legacy support crap.
|
||||
String title = plugin.getLocale().getMessage("interface.key.title")
|
||||
.processPlaceholder("kit", name).getMessage();
|
||||
if (title.startsWith(ChatColor.COLOR_CHAR + "f"))
|
||||
title = title.substring(2);
|
||||
String keyName = nbtItem.getNBTObject("key").asString();
|
||||
String kitName = nbtItem.getNBTObject("kit").asString();
|
||||
|
||||
String titleAny = plugin.getLocale().getMessage("interface.key.title")
|
||||
.processPlaceholder("kit", "Any").getMessage();
|
||||
if (titleAny.startsWith(ChatColor.COLOR_CHAR + "f"))
|
||||
titleAny = titleAny.substring(2);
|
||||
boolean any = kitName.equals("ANY");
|
||||
Key key = plugin.getKeyManager().getKey(keyName);
|
||||
|
||||
if (!item.getItemMeta().getDisplayName().equals(title)
|
||||
&& !item.getItemMeta().getDisplayName().equals(titleAny)) {
|
||||
if (key == null && !any)
|
||||
return;
|
||||
|
||||
if (!any && !kitName.equals(name)) {
|
||||
plugin.getLocale().getMessage("event.crate.wrongkey").sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (giveKit(player, key)) {
|
||||
plugin.getLocale().getMessage("event.key.success")
|
||||
.processPlaceholder("kit", name).sendPrefixedMessage(player);
|
||||
|
@ -22,6 +22,8 @@ public class Settings {
|
||||
public static final ConfigSetting CHANCE_IN_PREVIEW = new ConfigSetting(config, "Main.Display Chance In Preview", true);
|
||||
public static final ConfigSetting CURRENCY_SYMBOL = new ConfigSetting(config, "Main.Currency Symbol", "$");
|
||||
public static final ConfigSetting STARTER_KIT = new ConfigSetting(config, "Main.Starter Kit", "none");
|
||||
public static final ConfigSetting KEY_MATERIAL = new ConfigSetting(config, "Main.Key Material", "TRIPWIRE_HOOK",
|
||||
"What type of material should be used for kit keys?");
|
||||
|
||||
public static final ConfigSetting ECONOMY_PLUGIN = new ConfigSetting(config, "Main.Economy", EconomyManager.getEconomy() == null ? "Vault" : EconomyManager.getEconomy().getName(),
|
||||
"Which economy plugin should be used?",
|
||||
|
@ -10,9 +10,8 @@ general:
|
||||
money: '&6Money'
|
||||
link: '&9Link'
|
||||
free: Free
|
||||
|
||||
any: Any
|
||||
# Interface Messages
|
||||
|
||||
interface:
|
||||
selector:
|
||||
kit: '&c%kit%'
|
||||
@ -51,19 +50,19 @@ interface:
|
||||
'no': '&c&lNo'
|
||||
key:
|
||||
title: '&5%kit% &fKit Key'
|
||||
description1: '&rRight-Click on [a ]&c&l%kit%&r kit'
|
||||
description2: '&rand receive its contents!'
|
||||
description3: '&rand receive some of its contents!'
|
||||
description4: '&rGives kit &c&l%amt% &rtimes.'
|
||||
name: '&e%name% &fKey'
|
||||
description1: '&fRight-Click on [a ]&c&l%kit%&f kit'
|
||||
description2: '&fand receive its contents!'
|
||||
description3: '&fand receive some of its contents!'
|
||||
description4: '&fGives kit &c&l%amt% &ftimes.'
|
||||
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
|
||||
description1: '&fRight-Click to open'
|
||||
description2: '&fand receive its contents!'
|
||||
description3: '&fand receive some of its contents!'
|
||||
description4: '&fLeft-Click to preview'
|
||||
|
||||
# Administrative interfaces
|
||||
kitblock:
|
||||
title: '&8This contains &a%kit%'
|
||||
switchtype: '&5&lSwitch kit type'
|
||||
@ -164,9 +163,7 @@ interface:
|
||||
switchtokitfunctionslore: '&7Click to switch back|&7to the kit functions.'
|
||||
itemfunctionlore: '&7Display Item: &6%item%|&7Display Name: &6%name%|&7Display Lore: &6%lore%||&7Left-Click: &6To set a display item.|&7Middle-Click: &6To set a display name.|&7Right-Click: &6To set display lore.|&7Shift-Click: &6To set chance.||&7Display options only show up on display.|&7This can be useful if you want to explain|&7What an item does without putting it in the|&7permanent lore.||&6Leave function mode to move items.'
|
||||
saved: '&8Changes to &a%kit% &8saved successfully.'
|
||||
|
||||
# Command Messages
|
||||
|
||||
command:
|
||||
general:
|
||||
noperms: '&cYou do not have permission to do that!'
|
||||
@ -179,9 +176,7 @@ command:
|
||||
crate:
|
||||
given: '&9Gave &7%player% &9crate &7%crate% &9for kit &7%kit%.'
|
||||
doesntexist: '&cThis crate is not loaded.'
|
||||
|
||||
# Event Messages
|
||||
|
||||
event:
|
||||
preview:
|
||||
kit: '&9You are now previewing kit &7%kit%&9.'
|
||||
@ -208,4 +203,4 @@ event:
|
||||
cancelled: '&cPurchase Canceled.'
|
||||
key:
|
||||
given: '&9You have received a &a%kit% &9kit key.'
|
||||
success: '&9You have successfully redeemed a key for the kit &7%kit%&9.'
|
||||
success: '&9You have successfully redeemed a key for the kit &7%kit%&9.'
|
||||
|
Loading…
Reference in New Issue
Block a user