Merge branch 'development'

This commit is contained in:
Brianna 2020-07-20 13:24:26 -05:00
commit e91c23d619
12 changed files with 154 additions and 116 deletions

View File

@ -2,7 +2,7 @@
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>UltimateKits</artifactId> <artifactId>UltimateKits</artifactId>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<version>2.6.6</version> <version>2.6.7</version>
<build> <build>
<defaultGoal>clean install</defaultGoal> <defaultGoal>clean install</defaultGoal>
<finalName>UltimateKits-${project.version}</finalName> <finalName>UltimateKits-${project.version}</finalName>
@ -101,7 +101,7 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId> <artifactId>spigot</artifactId>
<version>1.15</version> <version>1.16.1</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -182,7 +182,6 @@ public class UltimateKits extends SongodaPlugin {
displayItemHandler.start(); displayItemHandler.start();
particleHandler.start(); particleHandler.start();
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> saveKits(false), 6000, 6000);
} }
@Override @Override
@ -302,8 +301,9 @@ public class UltimateKits extends SongodaPlugin {
for (String keyName : keyFile.getConfigurationSection("Keys").getKeys(false)) { for (String keyName : keyFile.getConfigurationSection("Keys").getKeys(false)) {
int amt = keyFile.getInt("Keys." + keyName + ".Item Amount"); int amt = keyFile.getInt("Keys." + keyName + ".Item Amount");
int kitAmount = keyFile.getInt("Keys." + keyName + ".Amount of kit received"); 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); keyManager.addKey(key);
} }
} }
@ -508,6 +508,7 @@ public class UltimateKits extends SongodaPlugin {
keyFile.set("Keys.Ultra.Amount of kit received", 1); keyFile.set("Keys.Ultra.Amount of kit received", 1);
keyFile.set("Keys.Insane.Item Amount", -1); keyFile.set("Keys.Insane.Item Amount", -1);
keyFile.set("Keys.Insane.Amount of kit received", 2); keyFile.set("Keys.Insane.Amount of kit received", 2);
keyFile.set("Keys.Insane.Enchanted", true);
} }
private void checkCrateDefaults() { private void checkCrateDefaults() {

View File

@ -338,7 +338,8 @@ public class KitEditorGui extends DoubleGui {
ItemMeta meta = itemStack.getItemMeta(); ItemMeta meta = itemStack.getItemMeta();
List<String> newLore = new ArrayList<>(); List<String> newLore = new ArrayList<>();
for (String line : meta.getLore()) { for (String line : meta.getLore()) {
if (TextUtils.convertFromInvisibleString(line).equals("----")) break; if (line.contains("Moveable")) continue;
if (line.equals(TextUtils.formatText("&8----"))) break;
newLore.add(line); newLore.add(line);
} }
meta.setLore(newLore); meta.setLore(newLore);
@ -421,8 +422,9 @@ public class KitEditorGui extends DoubleGui {
if (meta.hasLore()) itemLore = meta.getLore(); if (meta.hasLore()) itemLore = meta.getLore();
else itemLore = new ArrayList<>(); else itemLore = new ArrayList<>();
itemLore.add(TextUtils.convertToInvisibleLoreString("----")); itemLore.add(TextUtils.formatText("&8----"));
itemLore.add(ChatColor.GRAY.toString() + plugin.getLocale().getMessage("general.type.chance") + ": " + ChatColor.GOLD.toString() + item.getChance() + "%"); itemLore.add(ChatColor.GRAY.toString() + plugin.getLocale().getMessage("general.type.chance").getMessage().replaceFirst("^" + ChatColor.RESET.toString(), "")
+ ": " + ChatColor.GOLD.toString() + item.getChance() + "%"); //TODO use a placeholder message in locales
if (isInFunction) { if (isInFunction) {
itemLore.addAll(Arrays.asList(plugin.getLocale().getMessage("interface.kiteditor.itemfunctionlore") itemLore.addAll(Arrays.asList(plugin.getLocale().getMessage("interface.kiteditor.itemfunctionlore")
.processPlaceholder("item", item.getDisplayItem() == null ? "" : item.getDisplayItem().name()) .processPlaceholder("item", item.getDisplayItem() == null ? "" : item.getDisplayItem().name())

View File

@ -84,6 +84,8 @@ public class KitGeneralOptionsGui extends Gui {
guiManager.showGUI(event.player, gui); guiManager.showGUI(event.player, gui);
} else if (event.clickType == ClickType.RIGHT) { } else if (event.clickType == ClickType.RIGHT) {
kit.setCategory(null); kit.setCategory(null);
updateItemLore(event.slot, plugin.getLocale().getMessage("interface.kitoptions.categorylore")
.processPlaceholder("category", kit.getCategory() == null ? "none" : kit.getCategory().getName()).getMessage().split("\\|"));
} }
}); });

View File

@ -144,8 +144,7 @@ public class KitSelectorGui extends Gui {
.processPlaceholder("kit", TextUtils.formatText(kitItem, true)).getMessage(); .processPlaceholder("kit", TextUtils.formatText(kitItem, true)).getMessage();
setButton(row, col, GuiUtils.createButtonItem( setButton(row, col, GuiUtils.createButtonItem(
kit.getDisplayItem() != null ? kit.getDisplayItem() : CompatibleMaterial.ENCHANTED_BOOK, kit.getDisplayItem() != null ? kit.getDisplayItem() : CompatibleMaterial.ENCHANTED_BOOK,kitTitle,
TextUtils.convertToInvisibleString(kitItem + ":") + kitTitle,
getKitLore(kit)), getKitLore(kit)),
event -> { event -> {
if (event.clickType == ClickType.MIDDLE && player.hasPermission("ultimatekits.admin")) { if (event.clickType == ClickType.MIDDLE && player.hasPermission("ultimatekits.admin")) {

View File

@ -118,7 +118,7 @@ public class PreviewKitGui extends Gui {
|| (Settings.DONT_PREVIEW_COMMANDS.getBoolean() || (Settings.DONT_PREVIEW_COMMANDS.getBoolean()
&& item.getType() == Material.PAPER && item.getType() == Material.PAPER
&& item.getItemMeta().hasDisplayName() && item.getItemMeta().hasDisplayName()
&& item.getItemMeta().getDisplayName().equals(plugin.getLocale().getMessage("general.type.command")))) { && item.getItemMeta().getDisplayName().equals(plugin.getLocale().getMessage("general.type.command").getMessage()))) {
setItem(row, col, AIR); setItem(row, col, AIR);
} else if (item.getAmount() <= 64) { } else if (item.getAmount() <= 64) {
// display item // display item

View File

@ -1,5 +1,7 @@
package com.songoda.ultimatekits.handlers; package com.songoda.ultimatekits.handlers;
import com.songoda.core.nms.NmsManager;
import com.songoda.core.nms.nbt.NBTItem;
import com.songoda.core.utils.TextUtils; import com.songoda.core.utils.TextUtils;
import com.songoda.ultimatekits.UltimateKits; import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.kit.Kit; import com.songoda.ultimatekits.kit.Kit;
@ -15,6 +17,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
@ -62,7 +65,10 @@ public class DisplayItemHandler {
if (!kitBlockData.isDisplayingItems()) e.remove(); if (!kitBlockData.isDisplayingItems()) e.remove();
int inum = Integer.parseInt(i.getItemStack().getItemMeta().getDisplayName().replace(String.valueOf(ChatColor.COLOR_CHAR), "")) + 1;
NBTItem nbtItem = NmsManager.getNbt().of(i.getItemStack());
int inum = nbtItem.has("num") ? nbtItem.getNBTObject("num").asInt() + 1 : 1;
if (inum > list.size()) inum = 1; if (inum > list.size()) inum = 1;
ItemStack is = list.get(inum - 1); ItemStack is = list.get(inum - 1);
@ -70,11 +76,13 @@ public class DisplayItemHandler {
if (kit.getDisplayItem() != null) if (kit.getDisplayItem() != null)
is = kit.getDisplayItem().getItem(); is = kit.getDisplayItem().getItem();
} }
ItemMeta meta = is.getItemMeta();
is.setAmount(1); is.setAmount(1);
meta.setDisplayName(TextUtils.convertToInvisibleString(Integer.toString(inum))); ItemMeta meta = is.getItemMeta();
meta.setDisplayName(null);
is.setItemMeta(meta); is.setItemMeta(meta);
i.setItemStack(is); nbtItem = NmsManager.getNbt().of(is);
nbtItem.set("num", inum);
i.setItemStack(nbtItem.finish());
i.setPickupDelay(9999); i.setPickupDelay(9999);
return; return;
} }
@ -83,13 +91,18 @@ public class DisplayItemHandler {
ItemStack is = list.get(0); ItemStack is = list.get(0);
is.setAmount(1); is.setAmount(1);
ItemMeta meta = is.getItemMeta(); ItemMeta meta = is.getItemMeta();
meta.setDisplayName(TextUtils.convertFromInvisibleString("0")); meta.setLore(Collections.singletonList("Display Item"));
is.setItemMeta(meta); is.setItemMeta(meta);
NBTItem nbtItem = NmsManager.getNbt().of(is);
nbtItem.set("num", 0);
Bukkit.getScheduler().runTask(instance, () -> { Bukkit.getScheduler().runTask(instance, () -> {
Item item = location.getWorld().dropItem(location.add(0, 1, 0), list.get(0)); Item item = location.getWorld().dropItem(location.add(0, 1, 0), nbtItem.finish());
Vector vec = new Vector(0, 0, 0); Vector vec = new Vector(0, 0, 0);
item.setVelocity(vec); item.setVelocity(vec);
item.setPickupDelay(9999); item.setPickupDelay(9999);
item.setCustomName(null);
item.setMetadata("US_EXEMPT", new FixedMetadataValue(UltimateKits.getInstance(), true)); item.setMetadata("US_EXEMPT", new FixedMetadataValue(UltimateKits.getInstance(), true));
item.setMetadata("displayItem", new FixedMetadataValue(UltimateKits.getInstance(), true)); item.setMetadata("displayItem", new FixedMetadataValue(UltimateKits.getInstance(), true));
item.setMetadata("betterdrops_ignore", new FixedMetadataValue(UltimateKits.getInstance(), true)); item.setMetadata("betterdrops_ignore", new FixedMetadataValue(UltimateKits.getInstance(), true));

View File

@ -1,57 +1,62 @@
package com.songoda.ultimatekits.key; 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.core.utils.TextUtils;
import com.songoda.ultimatekits.UltimateKits; import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.kit.Kit; import com.songoda.ultimatekits.kit.Kit;
import org.bukkit.Material; import com.songoda.ultimatekits.settings.Settings;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.bukkit.ChatColor;
public class Key { public class Key {
// The name of the 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; // 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. // 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.name = name;
this.amount = amount; this.amount = amount;
this.kitAmount = kitAmount; this.kitAmount = kitAmount;
this.enchanted = enchanted;
} }
public ItemStack getKeyItem(Kit kit, int amount) {
public ItemStack getKeyItem(Kit kit, int amt) {
UltimateKits plugin = UltimateKits.getInstance(); UltimateKits plugin = UltimateKits.getInstance();
ItemStack is = new ItemStack(Material.TRIPWIRE_HOOK, amt); ItemStack item = Settings.KEY_MATERIAL.getMaterial().getItem();
item.setAmount(amount);
String kitName; String kitName = kit != null ? TextUtils.formatText(kit.getName(), true)
if (kit != null) : plugin.getLocale().getMessage("general.type.any").getMessage();
kitName = TextUtils.formatText(kit.getName(), true);
else
kitName = "Any";
ItemMeta meta = is.getItemMeta(); ItemMeta meta = item.getItemMeta();
meta.setDisplayName(plugin.getLocale().getMessage("interface.key.title") meta.setDisplayName(plugin.getLocale().getMessage("interface.key.title")
.processPlaceholder("kit", kitName).getMessage()); .processPlaceholder("kit", kitName).getMessage());
meta.addEnchant(Enchantment.DURABILITY, 1, true); if (enchanted)
ItemUtils.addGlow(item);
List<String> lore = new ArrayList<>(); 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") String desc1 = plugin.getLocale().getMessage("interface.key.description1")
.processPlaceholder("kit", kitName).getMessage(); .processPlaceholder("kit", kitName).getMessage();
if (kitName.equals("Any")) if (kit == null)
desc1 = desc1.replaceAll("\\[.*?\\]", ""); desc1 = desc1.replaceAll("\\[.*?\\]", "");
else else
desc1 = desc1.replace("[", "").replace("]", ""); desc1 = desc1.replace("[", "").replace("]", "");
@ -66,12 +71,15 @@ public class Key {
.processPlaceholder("amt", this.kitAmount).getMessage()); .processPlaceholder("amt", this.kitAmount).getMessage());
meta.setLore(lore); 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() { public String getName() {
return name; return name;
} }
@ -83,4 +91,8 @@ public class Key {
public int getKitAmount() { public int getKitAmount() {
return kitAmount; return kitAmount;
} }
public boolean isEnchanted() {
return enchanted;
}
} }

View File

@ -7,6 +7,8 @@ import com.songoda.core.configuration.Config;
import com.songoda.core.gui.Gui; import com.songoda.core.gui.Gui;
import com.songoda.core.gui.GuiManager; import com.songoda.core.gui.GuiManager;
import com.songoda.core.hooks.EconomyManager; 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.ItemUtils;
import com.songoda.core.utils.TextUtils; import com.songoda.core.utils.TextUtils;
import com.songoda.ultimatekits.UltimateKits; import com.songoda.ultimatekits.UltimateKits;
@ -84,39 +86,40 @@ public class Kit {
private boolean hasRoom(Player player, int itemAmount) { private boolean hasRoom(Player player, int itemAmount) {
int space = 0; int space = 0;
for (ItemStack content : player.getInventory().getContents()) { for (ItemStack content : player.getInventory().getStorageContents()) {
if (content == null) { if (content == null) {
space++; space++;
} }
} }
// Since roulette only gives one item, we don't need to check if the user has room for the whole kit.
if (kitAnimation == KitAnimation.ROULETTE && space >= 1)
return true;
return space >= itemAmount; return space >= itemAmount;
} }
public void processKeyUse(Player player) { public void processKeyUse(Player player) {
ItemStack item = player.getItemInHand(); 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; return;
}
Key key = plugin.getKeyManager().getKey(ChatColor.stripColor(item.getItemMeta().getLore().get(0)).replace(" Key", ""));
// This is some legacy support crap. String keyName = nbtItem.getNBTObject("key").asString();
String title = plugin.getLocale().getMessage("interface.key.title") String kitName = nbtItem.getNBTObject("kit").asString();
.processPlaceholder("kit", name).getMessage();
if (title.startsWith(ChatColor.COLOR_CHAR + "f"))
title = title.substring(2);
String titleAny = plugin.getLocale().getMessage("interface.key.title") boolean any = kitName.equals("ANY");
.processPlaceholder("kit", "Any").getMessage(); Key key = plugin.getKeyManager().getKey(keyName);
if (titleAny.startsWith(ChatColor.COLOR_CHAR + "f"))
titleAny = titleAny.substring(2);
if (!item.getItemMeta().getDisplayName().equals(title) if (key == null && !any)
&& !item.getItemMeta().getDisplayName().equals(titleAny)) { return;
if (!any && !kitName.equals(name)) {
plugin.getLocale().getMessage("event.crate.wrongkey").sendPrefixedMessage(player); plugin.getLocale().getMessage("event.crate.wrongkey").sendPrefixedMessage(player);
return; return;
} }
if (giveKit(player, key)) { if (giveKit(player, key)) {
plugin.getLocale().getMessage("event.key.success") plugin.getLocale().getMessage("event.key.success")
.processPlaceholder("kit", name).sendPrefixedMessage(player); .processPlaceholder("kit", name).sendPrefixedMessage(player);
@ -217,7 +220,8 @@ public class Kit {
ItemMeta meta = is.getItemMeta(); ItemMeta meta = is.getItemMeta();
List<String> newLore = new ArrayList<>(); List<String> newLore = new ArrayList<>();
for (String line : meta.getLore()) { for (String line : meta.getLore()) {
if (TextUtils.convertFromInvisibleString(line).equals("----")) break; if (line.contains("Moveable")) continue;
if (line.equals(TextUtils.formatText("&8----"))) break;
newLore.add(line); newLore.add(line);
} }
meta.setLore(newLore); meta.setLore(newLore);
@ -285,7 +289,15 @@ public class Kit {
} }
private boolean giveKit(Player player, int itemAmount, int kitAmount) { private boolean giveKit(Player player, int itemAmount, int kitAmount) {
if (Settings.NO_REDEEM_WHEN_FULL.getBoolean() && !hasRoom(player, itemAmount)) { List<KitItem> innerContents = new ArrayList<>(getContents());
int kitSize = innerContents.size();
// Amount of items from the kit to give to the player.
if (kitAnimation == KitAnimation.ROULETTE) itemAmount = 1; //TODO how about kitAmount > 1? generateRandomItem() will only give 1 random item instead of kitAmount
int itemGiveAmount = itemAmount > 0 ? itemAmount : kitSize;
if (kitAmount > 0) itemGiveAmount = itemGiveAmount * kitAmount;
if (Settings.NO_REDEEM_WHEN_FULL.getBoolean() && !hasRoom(player, itemGiveAmount)) {
plugin.getLocale().getMessage("event.claim.full").sendPrefixedMessage(player); plugin.getLocale().getMessage("event.claim.full").sendPrefixedMessage(player);
return false; return false;
} }
@ -293,18 +305,10 @@ public class Kit {
if (Settings.SOUNDS_ENABLED.getBoolean() && kitAnimation == KitAnimation.NONE) if (Settings.SOUNDS_ENABLED.getBoolean() && kitAnimation == KitAnimation.NONE)
CompatibleSound.ENTITY_PLAYER_LEVELUP.play(player, 0.6F, 15.0F); 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 = itemAmount > 0 ? itemAmount : kitSize;
if (kitAmount > 0) itemGiveAmount = itemGiveAmount * kitAmount;
return generateRandomItem(innerContents, itemGiveAmount, player); return generateRandomItem(innerContents, itemGiveAmount, player);
} }
private boolean generateRandomItem(List<KitItem> innerContents, int itemGiveAmount, Player player) { private boolean generateRandomItem(List<KitItem> innerContents, int itemGiveAmount, Player player) {
if (innerContents.size() != itemGiveAmount || kitAnimation != KitAnimation.NONE) if (innerContents.size() != itemGiveAmount || kitAnimation != KitAnimation.NONE)
Collections.shuffle(innerContents); Collections.shuffle(innerContents);
@ -312,8 +316,8 @@ public class Kit {
if (itemGiveAmount == 0) break; if (itemGiveAmount == 0) break;
double ch = item.getChance() == 0 ? 100 : item.getChance(); double ch = item.getChance() == 0 ? 100 : item.getChance();
double rand = Math.random() * 100; double rand = Math.random() * 100;
if (rand < ch || ch == 100) {
itemGiveAmount--; itemGiveAmount--;
if (rand < ch || ch == 100) {
ItemStack parseStack = item.getContent().process(player); ItemStack parseStack = item.getContent().process(player);
if (kitAnimation != KitAnimation.NONE) { if (kitAnimation != KitAnimation.NONE) {

View File

@ -1,5 +1,7 @@
package com.songoda.ultimatekits.kit; package com.songoda.ultimatekits.kit;
import com.songoda.core.nms.NmsManager;
import com.songoda.core.nms.nbt.NBTItem;
import com.songoda.core.utils.TextUtils; import com.songoda.core.utils.TextUtils;
import com.songoda.ultimatekits.UltimateKits; import com.songoda.ultimatekits.UltimateKits;
import com.songoda.ultimatekits.kit.type.KitContent; import com.songoda.ultimatekits.kit.type.KitContent;
@ -13,9 +15,7 @@ import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayDeque; import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
public class KitItem { public class KitItem {
@ -32,26 +32,13 @@ public class KitItem {
} }
public KitItem(ItemStack item, String line) { public KitItem(ItemStack item, String line) {
ItemStack itemStack = item.clone(); translateTags(item);
ItemMeta meta = itemStack.getItemMeta();
if (itemStack.hasItemMeta() && meta.hasDisplayName() && meta.getDisplayName().contains(";")) {
translateLine(meta.getDisplayName());
}
processContent(line, null); processContent(line, null);
} }
public KitItem(ItemStack item) { public KitItem(ItemStack item) {
ItemStack itemStack = item.clone(); translateTags(item);
ItemMeta meta = itemStack.getItemMeta(); processContent(null, item.clone());
if (itemStack.hasItemMeta() && meta.hasDisplayName() && meta.getDisplayName().contains(";")) {
String translated = translateLine(meta.getDisplayName()).replace(TextUtils.convertToInvisibleString("faqe"), "");
if (translated.equalsIgnoreCase(WordUtils.capitalize(item.getType().toString().toLowerCase().replace("_", " "))))
meta.setDisplayName(null);
else
meta.setDisplayName(translated);
itemStack.setItemMeta(meta);
}
processContent(null, itemStack);
} }
private void processContent(String line, ItemStack item) { private void processContent(String line, ItemStack item) {
@ -65,6 +52,18 @@ public class KitItem {
} }
} }
private void translateTags(ItemStack item) {
NBTItem nbtItem = NmsManager.getNbt().of(item);
if (nbtItem.has("chance"))
chance = nbtItem.getNBTObject("chance").asDouble();
if (nbtItem.has("display-item"))
displayItem = Material.valueOf(nbtItem.getNBTObject("display-item").asString());
if (nbtItem.has("display-name"))
displayName = nbtItem.getNBTObject("display-name").asString();
if (nbtItem.has("display-lore"))
displayLore = nbtItem.getNBTObject("display-lore").asString();
}
private String translateLine(String line) { private String translateLine(String line) {
String[] lineSplit = line.trim().split(";", 2); String[] lineSplit = line.trim().split(";", 2);
String[] kitOptions = lineSplit[0].replace(String.valueOf(ChatColor.COLOR_CHAR), "").split("~"); String[] kitOptions = lineSplit[0].replace(String.valueOf(ChatColor.COLOR_CHAR), "").split("~");
@ -94,7 +93,19 @@ public class KitItem {
return lineSplit[1]; return lineSplit[1];
} }
private String compileOptions() { private ItemStack compileOptions(ItemStack item) {
NBTItem nbtItem = NmsManager.getNbt().of(item);
if (chance != 0)
nbtItem.set("chance", chance);
if (displayItem != null)
nbtItem.set("display-item", displayItem.name());
if (displayName != null)
nbtItem.set("display-name", displayName);
if (displayLore != null)
nbtItem.set("display-lore", displayLore);
return nbtItem.finish();
}
private String compileOptionsText() {
String line = ""; String line = "";
if (chance != 0) if (chance != 0)
line += "chance:" + chance; line += "chance:" + chance;
@ -114,7 +125,7 @@ public class KitItem {
public String getSerialized() { public String getSerialized() {
if (chance == 0 && displayItem == null && displayName == null && displayLore == null) if (chance == 0 && displayItem == null && displayName == null && displayLore == null)
return this.content.getSerialized(); return this.content.getSerialized();
return compileOptions() + ";" + this.content.getSerialized(); return compileOptionsText() + ";" + this.content.getSerialized();
} }
public double getChance() { public double getChance() {
@ -155,17 +166,15 @@ public class KitItem {
public ItemStack getMoveableItem() { public ItemStack getMoveableItem() {
if (content == null) return null; if (content == null) return null;
ItemStack item = content.getItemForDisplay(); ItemStack item = content.getItemForDisplay().clone();
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
if (chance != 0 || displayItem != null || displayName != null || displayLore != null) { List<String> lore = meta.hasLore() && meta.getLore().get(0).equals(TextUtils.formatText("&8&oMoveable"))
String capitalizedName = meta.hasDisplayName() ? meta.getDisplayName() : ? new ArrayList<>() : new ArrayList<>(Collections.singletonList(TextUtils.formatText("&8&oMoveable")));
WordUtils.capitalize(item.getType().toString().toLowerCase().replace("_", " ")); if (meta.hasLore())
if (capitalizedName.contains(TextUtils.convertToInvisibleString(";faqe"))) lore.addAll(meta.getLore());
capitalizedName = meta.getDisplayName().split(TextUtils.convertToInvisibleString(";faqe"))[1]; meta.setLore(lore);
meta.setDisplayName(TextUtils.convertToInvisibleString(compileOptions() + ";faqe") + capitalizedName);
}
item.setItemMeta(meta); item.setItemMeta(meta);
return item; return compileOptions(item);
} }
public ItemStack getItemForDisplay() { public ItemStack getItemForDisplay() {
@ -181,19 +190,18 @@ public class KitItem {
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', displayName)); meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', displayName));
} }
if (displayLore != null) { if (displayLore != null) {
meta.setLore(Arrays.asList(ChatColor.translateAlternateColorCodes('&', displayLore))); meta.setLore(Collections.singletonList(ChatColor.translateAlternateColorCodes('&', displayLore)));
} }
if (UltimateKits.getInstance().getConfig().getBoolean("Main.Display Chance In Preview")) { if (UltimateKits.getInstance().getConfig().getBoolean("Main.Display Chance In Preview")) {
ArrayDeque<String> lore; ArrayDeque<String> lore;
if (meta.hasLore()) { if (meta.hasLore())
lore = new ArrayDeque<>(meta.getLore()); lore = new ArrayDeque<>(meta.getLore());
} else { else
lore = new ArrayDeque<>(); lore = new ArrayDeque<>();
}
if (!lore.isEmpty()) lore.addFirst(""); if (!lore.isEmpty()) lore.addFirst("");
lore.addFirst(ChatColor.GRAY.toString() + UltimateKits.getInstance().getLocale().getMessage("general.type.chance") + ": " + ChatColor.GOLD + (chance == 0 ? 100 : chance) + "%"); lore.addFirst(ChatColor.GRAY.toString() + UltimateKits.getInstance().getLocale().getMessage("general.type.chance").getMessage() + ": " + ChatColor.GOLD + (chance == 0 ? 100 : chance) + "%");
meta.setLore(new ArrayList<>(lore)); meta.setLore(new ArrayList<>(lore));
} }

View File

@ -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 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 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 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(), public static final ConfigSetting ECONOMY_PLUGIN = new ConfigSetting(config, "Main.Economy", EconomyManager.getEconomy() == null ? "Vault" : EconomyManager.getEconomy().getName(),
"Which economy plugin should be used?", "Which economy plugin should be used?",

View File

@ -10,9 +10,8 @@ general:
money: '&6Money' money: '&6Money'
link: '&9Link' link: '&9Link'
free: Free free: Free
any: Any
# Interface Messages # Interface Messages
interface: interface:
selector: selector:
kit: '&c%kit%' kit: '&c%kit%'
@ -51,19 +50,19 @@ interface:
'no': '&c&lNo' 'no': '&c&lNo'
key: key:
title: '&5%kit% &fKit Key' title: '&5%kit% &fKit Key'
description1: '&rRight-Click on [a ]&c&l%kit%&r kit' name: '&e%name% &fKey'
description2: '&rand receive its contents!' description1: '&fRight-Click on [a ]&c&l%kit%&f kit'
description3: '&rand receive some of its contents!' description2: '&fand receive its contents!'
description4: '&rGives kit &c&l%amt% &rtimes.' description3: '&fand receive some of its contents!'
description4: '&fGives kit &c&l%amt% &ftimes.'
crate: crate:
title: '&5%kit% &f%crate% Crate' title: '&5%kit% &f%crate% Crate'
description1: '&rRight-Click to open' description1: '&fRight-Click to open'
description2: '&rand receive its contents!' description2: '&fand receive its contents!'
description3: '&rand receive some of its contents!' description3: '&fand receive some of its contents!'
description4: '&rLeft-Click to preview' description4: '&fLeft-Click to preview'
# Administrative interfaces
# Administrative interfaces
kitblock: kitblock:
title: '&8This contains &a%kit%' title: '&8This contains &a%kit%'
switchtype: '&5&lSwitch kit type' switchtype: '&5&lSwitch kit type'
@ -164,9 +163,7 @@ interface:
switchtokitfunctionslore: '&7Click to switch back|&7to the kit functions.' 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.' 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.' saved: '&8Changes to &a%kit% &8saved successfully.'
# Command Messages # Command Messages
command: command:
general: general:
noperms: '&cYou do not have permission to do that!' noperms: '&cYou do not have permission to do that!'
@ -179,9 +176,7 @@ command:
crate: crate:
given: '&9Gave &7%player% &9crate &7%crate% &9for kit &7%kit%.' given: '&9Gave &7%player% &9crate &7%crate% &9for kit &7%kit%.'
doesntexist: '&cThis crate is not loaded.' doesntexist: '&cThis crate is not loaded.'
# Event Messages # Event Messages
event: event:
preview: preview:
kit: '&9You are now previewing kit &7%kit%&9.' kit: '&9You are now previewing kit &7%kit%&9.'