mirror of
https://github.com/songoda/UltimateKits.git
synced 2025-03-14 07:29:10 +01:00
Heavy code style changes and slight refactoring
This commit is contained in:
parent
f8ee4fd6ad
commit
b5f442bdb9
@ -9,12 +9,8 @@ import com.craftaro.core.gui.GuiManager;
|
||||
import com.craftaro.core.hooks.EconomyManager;
|
||||
import com.craftaro.core.hooks.HologramManager;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.utils.NumberUtils;
|
||||
import com.craftaro.core.utils.TextUtils;
|
||||
import com.craftaro.ultimatekits.handlers.DisplayItemHandler;
|
||||
import com.craftaro.ultimatekits.handlers.ParticleHandler;
|
||||
import com.craftaro.ultimatekits.key.KeyManager;
|
||||
import com.craftaro.ultimatekits.kit.KitItem;
|
||||
import com.craftaro.ultimatekits.kit.KitType;
|
||||
import com.craftaro.ultimatekits.category.Category;
|
||||
import com.craftaro.ultimatekits.category.CategoryManager;
|
||||
import com.craftaro.ultimatekits.commands.CommandCategories;
|
||||
@ -34,11 +30,16 @@ import com.craftaro.ultimatekits.crate.CrateManager;
|
||||
import com.craftaro.ultimatekits.database.DataManager;
|
||||
import com.craftaro.ultimatekits.database.migrations._1_InitialMigration;
|
||||
import com.craftaro.ultimatekits.database.migrations._2_DuplicateMigration;
|
||||
import com.craftaro.ultimatekits.handlers.DisplayItemHandler;
|
||||
import com.craftaro.ultimatekits.handlers.ParticleHandler;
|
||||
import com.craftaro.ultimatekits.key.Key;
|
||||
import com.craftaro.ultimatekits.key.KeyManager;
|
||||
import com.craftaro.ultimatekits.kit.Kit;
|
||||
import com.craftaro.ultimatekits.kit.KitAnimation;
|
||||
import com.craftaro.ultimatekits.kit.KitBlockData;
|
||||
import com.craftaro.ultimatekits.kit.KitItem;
|
||||
import com.craftaro.ultimatekits.kit.KitManager;
|
||||
import com.craftaro.ultimatekits.kit.KitType;
|
||||
import com.craftaro.ultimatekits.listeners.BlockListeners;
|
||||
import com.craftaro.ultimatekits.listeners.ChatListeners;
|
||||
import com.craftaro.ultimatekits.listeners.ChunkListeners;
|
||||
@ -64,8 +65,6 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class UltimateKits extends SongodaPlugin {
|
||||
private static UltimateKits INSTANCE;
|
||||
|
||||
private final Config kitConfig = new Config(this, "kit.yml");
|
||||
private final Config categoryConfig = new Config(this, "category.yml");
|
||||
private final Config dataFile = new Config(this, "data.yml");
|
||||
@ -85,13 +84,16 @@ public class UltimateKits extends SongodaPlugin {
|
||||
|
||||
private boolean loaded = false;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link org.bukkit.plugin.java.JavaPlugin#getPlugin(Class)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static UltimateKits getInstance() {
|
||||
return INSTANCE;
|
||||
return getPlugin(UltimateKits.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginLoad() {
|
||||
INSTANCE = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -118,7 +120,7 @@ public class UltimateKits extends SongodaPlugin {
|
||||
this.categoryManager = new CategoryManager(this);
|
||||
|
||||
this.kitConfig.load();
|
||||
Convert.runKitConversions();
|
||||
Convert.runKitConversions(this);
|
||||
|
||||
this.categoryConfig.load();
|
||||
|
||||
@ -145,7 +147,7 @@ public class UltimateKits extends SongodaPlugin {
|
||||
.addSubCommand(new CommandSet(this))
|
||||
.addSubCommand(new CommandRemove(this))
|
||||
|
||||
.addSubCommand(new CommandCrate());
|
||||
.addSubCommand(new CommandCrate(this));
|
||||
|
||||
|
||||
// Event registration
|
||||
@ -156,7 +158,7 @@ public class UltimateKits extends SongodaPlugin {
|
||||
pluginManager.registerEvents(new ChatListeners(), this);
|
||||
pluginManager.registerEvents(new EntityListeners(this), this);
|
||||
pluginManager.registerEvents(new InteractListeners(this, this.guiManager), this);
|
||||
pluginManager.registerEvents(new PlayerListeners(), this);
|
||||
pluginManager.registerEvents(new PlayerListeners(this), this);
|
||||
|
||||
this.displayItemHandler.start();
|
||||
this.particleHandler.start();
|
||||
@ -165,19 +167,19 @@ public class UltimateKits extends SongodaPlugin {
|
||||
@Override
|
||||
public void onDataLoad() {
|
||||
// Empty categories from manager
|
||||
categoryManager.clearCategories();
|
||||
this.categoryManager.clearCategories();
|
||||
|
||||
/*
|
||||
* Register categories into CategoryManager from Configuration
|
||||
*/
|
||||
if (categoryConfig.getConfigurationSection("Categories") != null) {
|
||||
for (String key : categoryConfig.getConfigurationSection("Categories").getKeys(false)) {
|
||||
ConfigurationSection section = categoryConfig.getConfigurationSection("Categories." + key);
|
||||
if (this.categoryConfig.getConfigurationSection("Categories") != null) {
|
||||
for (String key : this.categoryConfig.getConfigurationSection("Categories").getKeys(false)) {
|
||||
ConfigurationSection section = this.categoryConfig.getConfigurationSection("Categories." + key);
|
||||
if (section == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Category category = categoryManager.addCategory(key, section.getString("name"));
|
||||
Category category = this.categoryManager.addCategory(key, section.getString("name"));
|
||||
if (section.contains("material")) {
|
||||
category.setMaterial(CompatibleMaterial.getMaterial(section.getString("material")).get().parseMaterial());
|
||||
}
|
||||
@ -185,14 +187,14 @@ public class UltimateKits extends SongodaPlugin {
|
||||
}
|
||||
|
||||
// Empty kits from manager.
|
||||
kitManager.clearKits();
|
||||
this.kitManager.clearKits();
|
||||
|
||||
/*
|
||||
* Register kits into KitManager from Configuration
|
||||
*/
|
||||
if (kitConfig.getConfigurationSection("Kits") != null) {
|
||||
for (String kitName : kitConfig.getConfigurationSection("Kits").getKeys(false)) {
|
||||
ConfigurationSection section = kitConfig.getConfigurationSection("Kits." + kitName);
|
||||
if (this.kitConfig.getConfigurationSection("Kits") != null) {
|
||||
for (String kitName : this.kitConfig.getConfigurationSection("Kits").getKeys(false)) {
|
||||
ConfigurationSection section = this.kitConfig.getConfigurationSection("Kits." + kitName);
|
||||
if (section == null) {
|
||||
continue;
|
||||
}
|
||||
@ -209,12 +211,12 @@ public class UltimateKits extends SongodaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
kitManager.addKit(new Kit(kitName)
|
||||
this.kitManager.addKit(new Kit(kitName)
|
||||
.setTitle(section.getString("title"))
|
||||
.setDelay(section.getLong("delay"))
|
||||
.setLink(section.getString("link"))
|
||||
.setDisplayItem(item)
|
||||
.setCategory(categoryManager.getCategory(section.getString("category")))
|
||||
.setCategory(this.categoryManager.getCategory(section.getString("category")))
|
||||
.setHidden(section.getBoolean("hidden"))
|
||||
.setPrice(section.getDouble("price"))
|
||||
.setContents(section.getStringList("items").stream().map(KitItem::new).collect(Collectors.toList()))
|
||||
@ -226,20 +228,20 @@ public class UltimateKits extends SongodaPlugin {
|
||||
/*
|
||||
* Register legacy kit locations into KitManager from Configuration
|
||||
*/
|
||||
if (dataFile.contains("BlockData")) {
|
||||
for (String key : dataFile.getConfigurationSection("BlockData").getKeys(false)) {
|
||||
if (this.dataFile.contains("BlockData")) {
|
||||
for (String key : this.dataFile.getConfigurationSection("BlockData").getKeys(false)) {
|
||||
Location location = Methods.unserializeLocation(key);
|
||||
Kit kit = kitManager.getKit(dataFile.getString("BlockData." + key + ".kit"));
|
||||
KitType type = KitType.valueOf(dataFile.getString("BlockData." + key + ".type", "PREVIEW"));
|
||||
boolean holograms = dataFile.getBoolean("BlockData." + key + ".holograms");
|
||||
boolean displayItems = dataFile.getBoolean("BlockData." + key + ".displayItems");
|
||||
boolean particles = dataFile.getBoolean("BlockData." + key + ".particles");
|
||||
boolean itemOverride = dataFile.getBoolean("BlockData." + key + ".itemOverride");
|
||||
Kit kit = this.kitManager.getKit(this.dataFile.getString("BlockData." + key + ".kit"));
|
||||
KitType type = KitType.valueOf(this.dataFile.getString("BlockData." + key + ".type", "PREVIEW"));
|
||||
boolean holograms = this.dataFile.getBoolean("BlockData." + key + ".holograms");
|
||||
boolean displayItems = this.dataFile.getBoolean("BlockData." + key + ".displayItems");
|
||||
boolean particles = this.dataFile.getBoolean("BlockData." + key + ".particles");
|
||||
boolean itemOverride = this.dataFile.getBoolean("BlockData." + key + ".itemOverride");
|
||||
|
||||
if (kit == null) {
|
||||
dataFile.set("BlockData." + key, null);
|
||||
this.dataFile.set("BlockData." + key, null);
|
||||
} else {
|
||||
updateHologram(kitManager.addKitToLocation(kit, location, type, holograms, particles, displayItems, itemOverride));
|
||||
updateHologram(this.kitManager.addKitToLocation(kit, location, type, holograms, particles, displayItems, itemOverride));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -262,33 +264,33 @@ public class UltimateKits extends SongodaPlugin {
|
||||
checkCrateDefaults();
|
||||
|
||||
// Empty keys from manager
|
||||
keyManager.clear();
|
||||
crateManager.clear();
|
||||
this.keyManager.clear();
|
||||
this.crateManager.clear();
|
||||
|
||||
/*
|
||||
* Register keys into KitManager from Configuration
|
||||
*/
|
||||
if (keyFile.contains("Keys")) {
|
||||
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");
|
||||
if (this.keyFile.contains("Keys")) {
|
||||
for (String keyName : this.keyFile.getConfigurationSection("Keys").getKeys(false)) {
|
||||
int amt = this.keyFile.getInt("Keys." + keyName + ".Item Amount");
|
||||
int kitAmount = this.keyFile.getInt("Keys." + keyName + ".Amount of kit received");
|
||||
boolean enchanted = this.keyFile.getBoolean("Keys." + keyName + ".Enchanted");
|
||||
|
||||
Key key = new Key(keyName, amt, kitAmount, enchanted);
|
||||
keyManager.addKey(key);
|
||||
this.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");
|
||||
if (this.crateFile.contains("Crates")) {
|
||||
for (String crateName : this.crateFile.getConfigurationSection("Crates").getKeys(false)) {
|
||||
int amt = this.crateFile.getInt("Crates." + crateName + ".Item Amount");
|
||||
int kitAmount = this.crateFile.getInt("Crates." + crateName + ".Amount of kit received");
|
||||
|
||||
Crate crate = new Crate(crateName, amt, kitAmount);
|
||||
crateManager.addCrate(crate);
|
||||
this.crateManager.addCrate(crate);
|
||||
}
|
||||
}
|
||||
this.loaded = true;
|
||||
@ -408,7 +410,7 @@ public class UltimateKits extends SongodaPlugin {
|
||||
if (kit.getPrice() != 0) {
|
||||
lines.add(getLocale().getMessage("interface.hologram.buyeco")
|
||||
.processPlaceholder("price", kit.getPrice() != 0
|
||||
? Methods.formatEconomy(kit.getPrice())
|
||||
? NumberUtils.formatNumber(kit.getPrice())
|
||||
: getLocale().getMessage("general.type.free").getMessage())
|
||||
.getMessage());
|
||||
}
|
||||
@ -439,64 +441,74 @@ public class UltimateKits extends SongodaPlugin {
|
||||
* Saves registered kits to file
|
||||
*/
|
||||
public void saveKits(boolean force) {
|
||||
if (!loaded && !force) return;
|
||||
if (!this.loaded && !force) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If we're changing the order the file needs to be wiped
|
||||
if (kitManager.hasOrderChanged()) {
|
||||
kitConfig.clearConfig(true);
|
||||
kitManager.savedOrderChange();
|
||||
if (this.kitManager.hasOrderChanged()) {
|
||||
this.kitConfig.clearConfig(true);
|
||||
this.kitManager.savedOrderChange();
|
||||
}
|
||||
|
||||
// Hot fix for kit file resets
|
||||
if (kitConfig.contains("Kits"))
|
||||
for (String kitName : kitConfig.getConfigurationSection("Kits").getKeys(false)) {
|
||||
if (kitManager.getKits().stream().noneMatch(kit -> kit.getKey().equals(kitName)))
|
||||
kitConfig.set("Kits." + kitName, null);
|
||||
if (this.kitConfig.contains("Kits")) {
|
||||
for (String kitName : this.kitConfig.getConfigurationSection("Kits").getKeys(false)) {
|
||||
if (this.kitManager.getKits().stream().noneMatch(kit -> kit.getKey().equals(kitName))) {
|
||||
this.kitConfig.set("Kits." + kitName, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Hot fix for category file resets
|
||||
if (categoryConfig.contains("Categories"))
|
||||
for (String key : categoryConfig.getConfigurationSection("Categories").getKeys(false)) {
|
||||
if (categoryManager.getCategories().stream().noneMatch(category -> category.getKey().equals(key)))
|
||||
categoryConfig.set("Categories." + key, null);
|
||||
if (this.categoryConfig.contains("Categories")) {
|
||||
for (String key : this.categoryConfig.getConfigurationSection("Categories").getKeys(false)) {
|
||||
if (this.categoryManager.getCategories().stream().noneMatch(category -> category.getKey().equals(key))) {
|
||||
this.categoryConfig.set("Categories." + key, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Save kits from KitManager to Configuration
|
||||
*/
|
||||
for (Kit kit : kitManager.getKits()) {
|
||||
kitConfig.set("Kits." + kit.getKey() + ".delay", kit.getDelay());
|
||||
kitConfig.set("Kits." + kit.getKey() + ".title", kit.getTitle());
|
||||
kitConfig.set("Kits." + kit.getKey() + ".link", kit.getLink());
|
||||
kitConfig.set("Kits." + kit.getKey() + ".price", kit.getPrice());
|
||||
kitConfig.set("Kits." + kit.getKey() + ".hidden", kit.isHidden());
|
||||
kitConfig.set("Kits." + kit.getKey() + ".animation", kit.getKitAnimation().name());
|
||||
if (kit.getCategory() != null)
|
||||
kitConfig.set("Kits." + kit.getKey() + ".category", kit.getCategory().getKey());
|
||||
if (kit.getDisplayItem() != null)
|
||||
kitConfig.set("Kits." + kit.getKey() + ".displayItem", ItemSerializer.serializeItemStackToJson(kit.getDisplayItem()));
|
||||
else
|
||||
kitConfig.set("Kits." + kit.getKey() + ".displayItem", null);
|
||||
for (Kit kit : this.kitManager.getKits()) {
|
||||
this.kitConfig.set("Kits." + kit.getKey() + ".delay", kit.getDelay());
|
||||
this.kitConfig.set("Kits." + kit.getKey() + ".title", kit.getTitle());
|
||||
this.kitConfig.set("Kits." + kit.getKey() + ".link", kit.getLink());
|
||||
this.kitConfig.set("Kits." + kit.getKey() + ".price", kit.getPrice());
|
||||
this.kitConfig.set("Kits." + kit.getKey() + ".hidden", kit.isHidden());
|
||||
this.kitConfig.set("Kits." + kit.getKey() + ".animation", kit.getKitAnimation().name());
|
||||
if (kit.getCategory() != null) {
|
||||
this.kitConfig.set("Kits." + kit.getKey() + ".category", kit.getCategory().getKey());
|
||||
}
|
||||
if (kit.getDisplayItem() != null) {
|
||||
this.kitConfig.set("Kits." + kit.getKey() + ".displayItem", ItemSerializer.serializeItemStackToJson(kit.getDisplayItem()));
|
||||
} else {
|
||||
this.kitConfig.set("Kits." + kit.getKey() + ".displayItem", null);
|
||||
}
|
||||
|
||||
List<KitItem> contents = kit.getContents();
|
||||
List<String> strContents = new ArrayList<>();
|
||||
|
||||
for (KitItem item : contents) strContents.add(item.getSerialized());
|
||||
for (KitItem item : contents) {
|
||||
strContents.add(item.getSerialized());
|
||||
}
|
||||
|
||||
kitConfig.set("Kits." + kit.getKey() + ".items", strContents);
|
||||
this.kitConfig.set("Kits." + kit.getKey() + ".items", strContents);
|
||||
}
|
||||
|
||||
/*
|
||||
* Save categories from CategoryManager to Configuration
|
||||
*/
|
||||
for (Category category : categoryManager.getCategories()) {
|
||||
categoryConfig.set("Categories." + category.getKey() + ".name", category.getName());
|
||||
categoryConfig.set("Categories." + category.getKey() + ".material", category.getMaterial().name());
|
||||
for (Category category : this.categoryManager.getCategories()) {
|
||||
this.categoryConfig.set("Categories." + category.getKey() + ".name", category.getName());
|
||||
this.categoryConfig.set("Categories." + category.getKey() + ".material", category.getMaterial().name());
|
||||
}
|
||||
|
||||
// Save to file
|
||||
kitConfig.saveChanges();
|
||||
categoryConfig.saveChanges();
|
||||
this.kitConfig.saveChanges();
|
||||
this.categoryConfig.saveChanges();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,7 +5,6 @@ import org.bukkit.Material;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Category {
|
||||
|
||||
private final String key;
|
||||
private String name;
|
||||
private Material material = Material.DIAMOND;
|
||||
@ -16,11 +15,11 @@ public class Category {
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
@ -28,7 +27,7 @@ public class Category {
|
||||
}
|
||||
|
||||
public Material getMaterial() {
|
||||
return material;
|
||||
return this.material;
|
||||
}
|
||||
|
||||
public void setMaterial(Material material) {
|
||||
@ -37,14 +36,19 @@ public class Category {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(key);
|
||||
return Objects.hash(this.key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Category category = (Category) o;
|
||||
return Objects.equals(key, category.key);
|
||||
return Objects.equals(this.key, category.key);
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CategoryManager {
|
||||
|
||||
private final UltimateKits plugin;
|
||||
|
||||
private final Map<String, Category> registeredCategories = new LinkedHashMap<>();
|
||||
@ -21,33 +20,35 @@ public class CategoryManager {
|
||||
}
|
||||
|
||||
public Category getCategory(String key) {
|
||||
return registeredCategories.get(key);
|
||||
return this.registeredCategories.get(key);
|
||||
}
|
||||
|
||||
public Category getCategoryByName(String name) {
|
||||
return registeredCategories.values().stream()
|
||||
return this.registeredCategories.values().stream()
|
||||
.filter(c -> ChatColor.stripColor(TextUtils.formatText(c.getName())).equalsIgnoreCase(name))
|
||||
.findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public Category addCategory(String key, String name) {
|
||||
Category category = new Category(key, name);
|
||||
registeredCategories.put(key, category);
|
||||
this.registeredCategories.put(key, category);
|
||||
return category;
|
||||
}
|
||||
|
||||
public void removeCategory(Category category) {
|
||||
registeredCategories.remove(category.getKey());
|
||||
for (Kit kit : plugin.getKitManager().getKits())
|
||||
if (kit.getCategory() == category)
|
||||
this.registeredCategories.remove(category.getKey());
|
||||
for (Kit kit : this.plugin.getKitManager().getKits()) {
|
||||
if (kit.getCategory() == category) {
|
||||
kit.setCategory(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Category> getCategories() {
|
||||
return new LinkedList(registeredCategories.values());
|
||||
return new LinkedList<>(this.registeredCategories.values());
|
||||
}
|
||||
|
||||
public void clearCategories() {
|
||||
registeredCategories.clear();
|
||||
this.registeredCategories.clear();
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import org.bukkit.entity.Player;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandCategories extends AbstractCommand {
|
||||
|
||||
private final UltimateKits plugin;
|
||||
private final GuiManager guiManager;
|
||||
|
||||
@ -22,7 +21,7 @@ public class CommandCategories extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
guiManager.showGUI((Player) sender, new CategoryEditorGui(plugin, (Player) sender));
|
||||
this.guiManager.showGUI((Player) sender, new CategoryEditorGui(this.plugin, (Player) sender));
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.craftaro.ultimatekits.commands;
|
||||
|
||||
import com.craftaro.core.commands.AbstractCommand;
|
||||
import com.craftaro.core.utils.NumberUtils;
|
||||
import com.craftaro.ultimatekits.UltimateKits;
|
||||
import com.craftaro.ultimatekits.kit.Kit;
|
||||
import com.craftaro.ultimatekits.utils.Methods;
|
||||
import com.craftaro.ultimatekits.crate.Crate;
|
||||
import com.craftaro.ultimatekits.kit.Kit;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -17,39 +17,43 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandCrate extends AbstractCommand {
|
||||
private final UltimateKits plugin;
|
||||
|
||||
public CommandCrate() {
|
||||
public CommandCrate(UltimateKits plugin) {
|
||||
super(CommandType.CONSOLE_OK, "crate");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length < 3 || args.length > 4) return ReturnType.SYNTAX_ERROR;
|
||||
if (args.length < 3 || 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);
|
||||
this.plugin.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]);
|
||||
Kit kit = this.plugin.getKitManager().getKit(args[1]);
|
||||
|
||||
if (kit == null) {
|
||||
UltimateKits.getInstance().getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(sender);
|
||||
this.plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
Crate crate = UltimateKits.getInstance().getCrateManager().getCrate(args[2]);
|
||||
Crate crate = this.plugin.getCrateManager().getCrate(args[2]);
|
||||
|
||||
if (crate == null) {
|
||||
UltimateKits.getInstance().getLocale().getMessage("command.crate.doesntexist").sendPrefixedMessage(sender);
|
||||
this.plugin.getLocale().getMessage("command.crate.doesntexist").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
int amount = 1;
|
||||
if (args.length > 3) {
|
||||
if (!Methods.isNumeric(args[3])) {
|
||||
if (!NumberUtils.isInt(args[3])) {
|
||||
amount = 0;
|
||||
} else {
|
||||
amount = Integer.parseInt(args[3]);
|
||||
@ -57,7 +61,7 @@ public class CommandCrate extends AbstractCommand {
|
||||
}
|
||||
|
||||
if (amount == 0) {
|
||||
UltimateKits.getInstance().getLocale().newMessage("&a" + args[3] + " &cis not a number.").sendPrefixedMessage(sender);
|
||||
this.plugin.getLocale().newMessage("&a" + args[3] + " &cis not a number.").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
@ -67,7 +71,7 @@ public class CommandCrate extends AbstractCommand {
|
||||
// Give and send msg to all players online
|
||||
for (Player loopPlayer : Bukkit.getOnlinePlayers()) {
|
||||
loopPlayer.getInventory().addItem(item);
|
||||
UltimateKits.getInstance().getLocale().getMessage("event.crate.given")
|
||||
this.plugin.getLocale().getMessage("event.crate.given")
|
||||
.processPlaceholder("kit", kit.getName())
|
||||
.processPlaceholder("crate", crate.getName())
|
||||
.sendPrefixedMessage(loopPlayer);
|
||||
@ -75,14 +79,14 @@ public class CommandCrate extends AbstractCommand {
|
||||
} else {
|
||||
// Give to player and send msg
|
||||
target.getPlayer().getInventory().addItem(item);
|
||||
UltimateKits.getInstance().getLocale().getMessage("event.crate.given")
|
||||
this.plugin.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")
|
||||
this.plugin.getLocale().getMessage("command.crate.given")
|
||||
.processPlaceholder("kit", kit.getName())
|
||||
.processPlaceholder("crate", crate.getName())
|
||||
.processPlaceholder("player", args[0].equalsIgnoreCase("all") ? "all players" : target.getName());
|
||||
@ -96,16 +100,17 @@ public class CommandCrate extends AbstractCommand {
|
||||
if (args.length == 1) {
|
||||
// Players
|
||||
tab.add("all");
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
tab.add(player.getName());
|
||||
}
|
||||
return tab;
|
||||
} else if (args.length == 2) {
|
||||
// Kits
|
||||
return UltimateKits.getInstance().getKitManager().getKits().stream()
|
||||
return this.plugin.getKitManager().getKits().stream()
|
||||
.map(Kit::getName).collect(Collectors.toList());
|
||||
} else if (args.length == 3) {
|
||||
// Crates
|
||||
return UltimateKits.getInstance().getCrateManager().getRegisteredCrates().stream()
|
||||
return this.plugin.getCrateManager().getRegisteredCrates().stream()
|
||||
.map(Crate::getName).collect(Collectors.toList());
|
||||
} else if (args.length == 4) {
|
||||
return Collections.singletonList("amount");
|
||||
|
@ -9,10 +9,10 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandCreatekit extends AbstractCommand {
|
||||
|
||||
private final UltimateKits plugin;
|
||||
private final GuiManager guiManager;
|
||||
|
||||
@ -29,21 +29,21 @@ public class CommandCreatekit extends AbstractCommand {
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
String kitStr = args[0].toLowerCase().trim();
|
||||
if (plugin.getKitManager().getKit(kitStr) != null) {
|
||||
plugin.getLocale().getMessage("command.kit.kitalreadyexists").sendPrefixedMessage(player);
|
||||
if (this.plugin.getKitManager().getKit(kitStr) != null) {
|
||||
this.plugin.getLocale().getMessage("command.kit.kitalreadyexists").sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
plugin.getLocale().newMessage("&aThat kit doesn't exist. Creating it now.").sendPrefixedMessage(player);
|
||||
this.plugin.getLocale().newMessage("&aThat kit doesn't exist. Creating it now.").sendPrefixedMessage(player);
|
||||
Kit kit = new Kit(kitStr);
|
||||
plugin.getKitManager().addKit(kit);
|
||||
guiManager.showGUI(player, new KitEditorGui(plugin, player, kit, null));
|
||||
this.plugin.getKitManager().addKit(kit);
|
||||
this.guiManager.showGUI(player, new KitEditorGui(this.plugin, player, kit, null));
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
return Arrays.asList("name");
|
||||
return Collections.singletonList("name");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -15,7 +15,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandEdit extends AbstractCommand {
|
||||
|
||||
private final UltimateKits plugin;
|
||||
private final GuiManager guiManager;
|
||||
|
||||
@ -27,25 +26,27 @@ public class CommandEdit extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length > 1) return ReturnType.SYNTAX_ERROR;
|
||||
if (args.length > 1) {
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
final Player player = (Player) sender;
|
||||
|
||||
if (args.length == 0) {
|
||||
Block block = player.getTargetBlock(null, 200);
|
||||
KitBlockData kitBlockData = plugin.getKitManager().getKit(block.getLocation());
|
||||
KitBlockData kitBlockData = this.plugin.getKitManager().getKit(block.getLocation());
|
||||
if (kitBlockData == null) {
|
||||
plugin.getLocale().newMessage("command.kit.nokitatblock").sendPrefixedMessage(player);
|
||||
this.plugin.getLocale().newMessage("command.kit.nokitatblock").sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
guiManager.showGUI(player, new BlockEditorGui(plugin, kitBlockData));
|
||||
this.guiManager.showGUI(player, new BlockEditorGui(this.plugin, kitBlockData));
|
||||
} else {
|
||||
String kitStr = args[0].toLowerCase().trim();
|
||||
if (plugin.getKitManager().getKit(kitStr) == null) {
|
||||
plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(player);
|
||||
if (this.plugin.getKitManager().getKit(kitStr) == null) {
|
||||
this.plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
guiManager.showGUI(player, new KitEditorGui(plugin, player, plugin.getKitManager().getKit(kitStr), null));
|
||||
this.guiManager.showGUI(player, new KitEditorGui(this.plugin, player, this.plugin.getKitManager().getKit(kitStr), null));
|
||||
}
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
@ -53,11 +54,13 @@ public class CommandEdit extends AbstractCommand {
|
||||
@Override
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
List<String> tab = new ArrayList<>();
|
||||
|
||||
if (args.length == 1) {
|
||||
for (Kit kit : plugin.getKitManager().getKits())
|
||||
for (Kit kit : this.plugin.getKitManager().getKits()) {
|
||||
tab.add(kit.getKey());
|
||||
return tab;
|
||||
}
|
||||
}
|
||||
|
||||
return tab;
|
||||
}
|
||||
|
||||
|
@ -1,21 +1,20 @@
|
||||
package com.craftaro.ultimatekits.commands;
|
||||
|
||||
import com.craftaro.core.commands.AbstractCommand;
|
||||
import com.craftaro.core.utils.NumberUtils;
|
||||
import com.craftaro.core.utils.PlayerUtils;
|
||||
import com.craftaro.ultimatekits.UltimateKits;
|
||||
import com.craftaro.ultimatekits.key.Key;
|
||||
import com.craftaro.ultimatekits.kit.Kit;
|
||||
import com.craftaro.ultimatekits.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandKey extends AbstractCommand {
|
||||
|
||||
private final UltimateKits plugin;
|
||||
|
||||
public CommandKey(UltimateKits plugin) {
|
||||
@ -28,46 +27,46 @@ public class CommandKey extends AbstractCommand {
|
||||
if (args.length != 3 && args.length != 4) {
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
Kit kit = plugin.getKitManager().getKit(args[0]);
|
||||
if (kit == null && !args[0].toLowerCase().equals("all")) {
|
||||
plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(sender);
|
||||
Kit kit = this.plugin.getKitManager().getKit(args[0]);
|
||||
if (kit == null && !args[0].equalsIgnoreCase("all")) {
|
||||
this.plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
Player playerTo = null;
|
||||
if (!args[2].trim().equalsIgnoreCase("all") && (playerTo = Bukkit.getPlayer(args[2])) == null) {
|
||||
plugin.getLocale().newMessage("&cThat username does not exist, or the user is offline!").sendPrefixedMessage(sender);
|
||||
this.plugin.getLocale().newMessage("&cThat username does not exist, or the user is offline!").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
int amt = 1;
|
||||
if (args.length == 4) {
|
||||
if (!Methods.isNumeric(args[3])) {
|
||||
if (!NumberUtils.isInt(args[3])) {
|
||||
amt = 0;
|
||||
} else {
|
||||
amt = Integer.parseInt(args[3]);
|
||||
}
|
||||
}
|
||||
if (amt == 0) {
|
||||
plugin.getLocale().newMessage("&a" + args[3] + " &cis not a number.").sendPrefixedMessage(sender);
|
||||
this.plugin.getLocale().newMessage("&a" + args[3] + " &cis not a number.").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
Key key = plugin.getKeyManager().getKey(args[1]);
|
||||
Key key = this.plugin.getKeyManager().getKey(args[1]);
|
||||
if (key == null) {
|
||||
plugin.getLocale().newMessage("&a" + args[1] + " &cis not a key.").sendPrefixedMessage(sender);
|
||||
this.plugin.getLocale().newMessage("&a" + args[1] + " &cis not a key.").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
|
||||
if (playerTo != null) {
|
||||
PlayerUtils.giveItem(playerTo, key.getKeyItem(kit, amt));
|
||||
plugin.getLocale().getMessage("event.key.given")
|
||||
this.plugin.getLocale().getMessage("event.key.given")
|
||||
.processPlaceholder("kit", kit == null ? "Any" : kit.getName())
|
||||
.sendPrefixedMessage(playerTo);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
for (Player pl : plugin.getServer().getOnlinePlayers()) {
|
||||
for (Player pl : this.plugin.getServer().getOnlinePlayers()) {
|
||||
PlayerUtils.giveItem(pl, key.getKeyItem(kit, amt));
|
||||
plugin.getLocale().getMessage("event.key.given")
|
||||
this.plugin.getLocale().getMessage("event.key.given")
|
||||
.processPlaceholder("kit", kit == null ? "Any" : kit.getName())
|
||||
.sendPrefixedMessage(pl);
|
||||
}
|
||||
@ -76,25 +75,32 @@ public class CommandKey extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
if (!(sender instanceof Player)) return null;
|
||||
if (!(sender instanceof Player)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<String> tab = new ArrayList<>();
|
||||
|
||||
if (args.length == 1) {
|
||||
tab.add("all");
|
||||
for (Kit kit : UltimateKits.getInstance().getKitManager().getKits())
|
||||
for (Kit kit : this.plugin.getKitManager().getKits()) {
|
||||
tab.add(kit.getKey());
|
||||
}
|
||||
return tab;
|
||||
} else if (args.length == 2) {
|
||||
for (Key key : UltimateKits.getInstance().getKeyManager().getKeys())
|
||||
for (Key key : this.plugin.getKeyManager().getKeys()) {
|
||||
tab.add(key.getName());
|
||||
}
|
||||
return tab;
|
||||
} else if (args.length == 3) {
|
||||
tab.add("all");
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
tab.add(player.getName());
|
||||
}
|
||||
return tab;
|
||||
} else if (args.length == 4) return Arrays.asList("amount");
|
||||
} else if (args.length == 4) {
|
||||
return Collections.singletonList("amount");
|
||||
}
|
||||
return tab;
|
||||
}
|
||||
|
||||
@ -106,7 +112,7 @@ public class CommandKey extends AbstractCommand {
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
StringBuilder keys = new StringBuilder();
|
||||
for (Key key : UltimateKits.getInstance().getKeyManager().getKeys()) {
|
||||
for (Key key : this.plugin.getKeyManager().getKeys()) {
|
||||
keys.append("/").append(key.getName());
|
||||
}
|
||||
return "key <kit/all> <" + keys.substring(1) + "> <player/all> <amount>";
|
||||
|
@ -14,7 +14,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandKit extends AbstractCommand {
|
||||
|
||||
private final UltimateKits plugin;
|
||||
private final GuiManager guiManager;
|
||||
|
||||
@ -26,46 +25,50 @@ public class CommandKit extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length > 2) return ReturnType.SYNTAX_ERROR;
|
||||
if (args.length > 2) {
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
if (args.length == 0 && sender instanceof Player) {
|
||||
// /kit - Opens GUI.
|
||||
if (plugin.getKitManager().getKits().stream().anyMatch(kit -> kit.getCategory() != null))
|
||||
guiManager.showGUI((Player) sender, new CategorySelectorGui(plugin, (Player) sender));
|
||||
else
|
||||
guiManager.showGUI((Player) sender, new KitSelectorGui(plugin, (Player) sender, null));
|
||||
if (this.plugin.getKitManager().getKits().stream().anyMatch(kit -> kit.getCategory() != null)) {
|
||||
this.guiManager.showGUI((Player) sender, new CategorySelectorGui(this.plugin, (Player) sender));
|
||||
} else {
|
||||
this.guiManager.showGUI((Player) sender, new KitSelectorGui(this.plugin, (Player) sender, null));
|
||||
}
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
if (plugin.getKitManager().getKit(args[0]) == null) {
|
||||
plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(sender);
|
||||
if (this.plugin.getKitManager().getKit(args[0]) == null) {
|
||||
this.plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
Kit kit = plugin.getKitManager().getKit(args[0]);
|
||||
Kit kit = this.plugin.getKitManager().getKit(args[0]);
|
||||
|
||||
if (args.length == 1) {
|
||||
// /kit <kit> - Gives kit to self.
|
||||
if (!(sender instanceof Player))
|
||||
if (!(sender instanceof Player)) {
|
||||
return ReturnType.NEEDS_PLAYER;
|
||||
}
|
||||
|
||||
if (!kit.hasPermissionToClaim((Player) sender)) {
|
||||
plugin.getLocale().getMessage("command.general.noperms").sendPrefixedMessage(sender);
|
||||
this.plugin.getLocale().getMessage("command.general.noperms").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
kit.processGenericUse((Player) sender, false);
|
||||
return ReturnType.SUCCESS;
|
||||
} else if (args.length == 2) {
|
||||
} else {
|
||||
// /kit <kit> <player> - Gives kit to another player.
|
||||
|
||||
if (!sender.hasPermission("ultimatekits.admin")) {
|
||||
plugin.getLocale().getMessage("command.general.noperms").sendPrefixedMessage(sender);
|
||||
this.plugin.getLocale().getMessage("command.general.noperms").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
if (!args[1].equalsIgnoreCase("all") && Bukkit.getPlayer(args[1]) == null) {
|
||||
plugin.getLocale().newMessage("&cThat username does not exist, or the user is offline!").sendPrefixedMessage(sender);
|
||||
this.plugin.getLocale().newMessage("&cThat username does not exist, or the user is offline!").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
@ -74,34 +77,36 @@ public class CommandKit extends AbstractCommand {
|
||||
|
||||
if (player != null) {
|
||||
kit.processGenericUse(player, true);
|
||||
plugin.getLocale().getMessage("event.claim.givesuccess")
|
||||
this.plugin.getLocale().getMessage("event.claim.givesuccess")
|
||||
.processPlaceholder("kit", kit.getName())
|
||||
.sendPrefixedMessage(sender);
|
||||
} else {
|
||||
Bukkit.getOnlinePlayers().forEach(onlinePlayer -> {
|
||||
kit.processGenericUse(onlinePlayer, true);
|
||||
plugin.getLocale().getMessage("event.claim.givesuccess")
|
||||
this.plugin.getLocale().getMessage("event.claim.givesuccess")
|
||||
.processPlaceholder("kit", kit.getName())
|
||||
.sendPrefixedMessage(sender);
|
||||
});
|
||||
}
|
||||
|
||||
plugin.getLocale().newMessage("&7You gave &9" + who + "&7 kit &9" + kit.getName() + "&7.")
|
||||
this.plugin.getLocale().newMessage("&7You gave &9" + who + "&7 kit &9" + kit.getName() + "&7.")
|
||||
.sendPrefixedMessage(sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
List<String> tab = new ArrayList<>();
|
||||
|
||||
if (!(sender instanceof Player)) return tab;
|
||||
if (!(sender instanceof Player)) {
|
||||
return tab;
|
||||
}
|
||||
|
||||
if (args.length == 1) {
|
||||
for (Kit kit : plugin.getKitManager().getKits()) tab.add(kit.getKey());
|
||||
for (Kit kit : this.plugin.getKitManager().getKits()) {
|
||||
tab.add(kit.getKey());
|
||||
}
|
||||
} else if (args.length == 2) {
|
||||
tab.add("all");
|
||||
Bukkit.getOnlinePlayers().forEach(player -> tab.add(player.getName()));
|
||||
|
@ -11,7 +11,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandPreviewKit extends AbstractCommand {
|
||||
|
||||
private final UltimateKits plugin;
|
||||
private final GuiManager guiManager;
|
||||
|
||||
@ -25,15 +24,15 @@ public class CommandPreviewKit extends AbstractCommand {
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
Player player = (Player) sender;
|
||||
if (args.length != 1) {
|
||||
plugin.getLocale().getMessage("command.kit.nokitsupplied").sendPrefixedMessage(player);
|
||||
this.plugin.getLocale().getMessage("command.kit.nokitsupplied").sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
Kit kit = plugin.getKitManager().getKit(args[0].toLowerCase().trim());
|
||||
Kit kit = this.plugin.getKitManager().getKit(args[0].toLowerCase().trim());
|
||||
if (kit == null) {
|
||||
plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(player);
|
||||
this.plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
kit.display(player, guiManager, null);
|
||||
kit.display(player, this.guiManager, null);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@ -45,7 +44,7 @@ public class CommandPreviewKit extends AbstractCommand {
|
||||
|
||||
if (args.length == 2) {
|
||||
List<String> tab = new ArrayList<>();
|
||||
for (Kit kit : UltimateKits.getInstance().getKitManager().getKits()) {
|
||||
for (Kit kit : this.plugin.getKitManager().getKits()) {
|
||||
tab.add(kit.getKey());
|
||||
}
|
||||
return tab;
|
||||
|
@ -8,7 +8,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandReload extends AbstractCommand {
|
||||
|
||||
private final UltimateKits plugin;
|
||||
|
||||
public CommandReload(UltimateKits plugin) {
|
||||
@ -18,8 +17,8 @@ public class CommandReload extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
plugin.reloadConfig();
|
||||
plugin.getLocale().getMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender);
|
||||
this.plugin.reloadConfig();
|
||||
this.plugin.getLocale().getMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandRemove extends AbstractCommand {
|
||||
|
||||
private final UltimateKits plugin;
|
||||
|
||||
public CommandRemove(UltimateKits plugin) {
|
||||
@ -24,16 +23,18 @@ public class CommandRemove extends AbstractCommand {
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
Player player = (Player) sender;
|
||||
Block block = player.getTargetBlock(null, 200);
|
||||
Kit kit = plugin.getKitManager().removeKitFromLocation(block.getLocation());
|
||||
if (kit == null) return ReturnType.FAILURE;
|
||||
|
||||
if (HologramManager.isEnabled()) {
|
||||
plugin.getKitManager().getKitLocations().values().stream()
|
||||
.filter(data -> data.getKit() == kit)
|
||||
.forEach(data -> plugin.removeHologram(data));
|
||||
Kit kit = this.plugin.getKitManager().removeKitFromLocation(block.getLocation());
|
||||
if (kit == null) {
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
plugin.getLocale().newMessage("&8Kit &9" + kit.getKey() + " &8unassigned from: &a" + block.getType().toString() + "&8.").sendPrefixedMessage(player);
|
||||
if (HologramManager.isEnabled()) {
|
||||
this.plugin.getKitManager().getKitLocations().values().stream()
|
||||
.filter(data -> data.getKit() == kit)
|
||||
.forEach(this.plugin::removeHologram);
|
||||
}
|
||||
|
||||
this.plugin.getLocale().newMessage("&8Kit &9" + kit.getKey() + " &8unassigned from: &a" + block.getType() + "&8.").sendPrefixedMessage(player);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandSet extends AbstractCommand {
|
||||
|
||||
private final UltimateKits plugin;
|
||||
|
||||
public CommandSet(UltimateKits plugin) {
|
||||
@ -23,19 +22,19 @@ public class CommandSet extends AbstractCommand {
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length != 1) {
|
||||
plugin.getLocale().getMessage("command.kit.nokitsupplied").sendPrefixedMessage(sender);
|
||||
this.plugin.getLocale().getMessage("command.kit.nokitsupplied").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
Kit kit = plugin.getKitManager().getKit(args[0].toLowerCase());
|
||||
Kit kit = this.plugin.getKitManager().getKit(args[0].toLowerCase());
|
||||
if (kit == null) {
|
||||
plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(sender);
|
||||
this.plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
Block b = player.getTargetBlock(null, 200);
|
||||
KitBlockData data = plugin.getKitManager().addKitToLocation(kit, b.getLocation());
|
||||
UltimateKits.getInstance().getKitDataManager().createBlockData(data);
|
||||
plugin.getLocale().newMessage("&8Kit &a" + kit.getKey() + " &8set to: &a" + b.getType().toString() + "&8.")
|
||||
KitBlockData data = this.plugin.getKitManager().addKitToLocation(kit, b.getLocation());
|
||||
this.plugin.getKitDataManager().createBlockData(data);
|
||||
this.plugin.getLocale().newMessage("&8Kit &a" + kit.getKey() + " &8set to: &a" + b.getType() + "&8.")
|
||||
.sendPrefixedMessage(sender);
|
||||
return ReturnType.SUCCESS;
|
||||
|
||||
@ -49,7 +48,7 @@ public class CommandSet extends AbstractCommand {
|
||||
|
||||
if (args.length == 1) {
|
||||
List<String> tab = new ArrayList<>();
|
||||
for (Kit kit : UltimateKits.getInstance().getKitManager().getKits()) {
|
||||
for (Kit kit : this.plugin.getKitManager().getKits()) {
|
||||
tab.add(kit.getKey());
|
||||
}
|
||||
return tab;
|
||||
|
@ -11,7 +11,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandSettings extends AbstractCommand {
|
||||
|
||||
private final UltimateKits plugin;
|
||||
private final GuiManager guiManager;
|
||||
|
||||
@ -23,7 +22,7 @@ public class CommandSettings extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
guiManager.showGUI((Player) sender, new PluginConfigGui(plugin));
|
||||
this.guiManager.showGUI((Player) sender, new PluginConfigGui(this.plugin));
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
package com.craftaro.ultimatekits.conversion;
|
||||
|
||||
import com.craftaro.ultimatekits.UltimateKits;
|
||||
import com.craftaro.ultimatekits.kit.Kit;
|
||||
import com.craftaro.ultimatekits.kit.KitItem;
|
||||
import com.craftaro.ultimatekits.conversion.hooks.CMIHook;
|
||||
import com.craftaro.ultimatekits.conversion.hooks.DefaultHook;
|
||||
import com.craftaro.ultimatekits.conversion.hooks.EssentialsHook;
|
||||
import com.craftaro.ultimatekits.conversion.hooks.UltimateCoreHook;
|
||||
import com.craftaro.ultimatekits.kit.Kit;
|
||||
import com.craftaro.ultimatekits.kit.KitItem;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -15,9 +15,8 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class Convert {
|
||||
|
||||
public static void runKitConversions() {
|
||||
if (!UltimateKits.getInstance().getKitConfig().contains("Kits")) {
|
||||
public static void runKitConversions(UltimateKits plugin) {
|
||||
if (!plugin.getKitConfig().contains("Kits")) {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("Essentials")) {
|
||||
try {
|
||||
Class.forName("com.earth2me.essentials.metrics.MetricsListener");
|
||||
@ -42,9 +41,13 @@ public class Convert {
|
||||
Set<String> kits = hook.getKits();
|
||||
for (String kit : kits) {
|
||||
Kit kitObj = UltimateKits.getInstance().getKitManager().addKit(new Kit(kit));
|
||||
if (kitObj == null) continue;
|
||||
if (kitObj == null) {
|
||||
continue;
|
||||
}
|
||||
for (ItemStack item : hook.getItems(kit)) {
|
||||
if (item == null || item.getType() == Material.AIR) continue;
|
||||
if (item == null || item.getType() == Material.AIR) {
|
||||
continue;
|
||||
}
|
||||
kitObj.getContents().add(new KitItem(item));
|
||||
}
|
||||
kitObj.setDelay(hook.getDelay(kit));
|
||||
@ -56,17 +59,21 @@ public class Convert {
|
||||
}
|
||||
|
||||
private static boolean isInJsonFormat() {
|
||||
if (!UltimateKits.getInstance().getKitConfig().contains("Kits")) return false;
|
||||
if (!UltimateKits.getInstance().getKitConfig().contains("Kits")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (String kit : UltimateKits.getInstance().getKitConfig().getConfigurationSection("Kits").getKeys(false)) {
|
||||
if (UltimateKits.getInstance().getKitConfig().contains("Kits." + kit + ".items")) {
|
||||
List<String> itemList = UltimateKits.getInstance().getKitConfig().getStringList("Kits." + kit + ".items");
|
||||
if (itemList.size() > 0) {
|
||||
if (!itemList.isEmpty()) {
|
||||
if (itemList.get(0).startsWith("{")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,10 +5,9 @@ import org.bukkit.inventory.ItemStack;
|
||||
import java.util.Set;
|
||||
|
||||
public interface Hook {
|
||||
|
||||
Set<String> getKits();
|
||||
|
||||
Set<ItemStack> getItems(String kit);
|
||||
Set<ItemStack> getItems(String kitName);
|
||||
|
||||
long getDelay(String kit);
|
||||
}
|
||||
long getDelay(String kitName);
|
||||
}
|
||||
|
@ -2,45 +2,46 @@ package com.craftaro.ultimatekits.conversion.hooks;
|
||||
|
||||
import com.Zrips.CMI.CMI;
|
||||
import com.Zrips.CMI.Modules.Kits.Kit;
|
||||
import com.craftaro.ultimatekits.UltimateKits;
|
||||
import com.craftaro.ultimatekits.conversion.Hook;
|
||||
import com.craftaro.ultimatekits.kit.type.KitContentCommand;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class CMIHook implements Hook {
|
||||
|
||||
private CMI cmi;
|
||||
private final CMI cmi;
|
||||
|
||||
public CMIHook() {
|
||||
cmi = (CMI) UltimateKits.getInstance().getServer().getPluginManager().getPlugin("CMI");
|
||||
this.cmi = (CMI) Bukkit.getPluginManager().getPlugin("CMI");
|
||||
}
|
||||
|
||||
public Set<ItemStack> getItems(String kitName) {
|
||||
Set<ItemStack> stacks = new HashSet<>();
|
||||
try {
|
||||
Kit kit = cmi.getKitsManager().getKit(kitName, true);
|
||||
Kit kit = this.cmi.getKitsManager().getKit(kitName, true);
|
||||
|
||||
for (ItemStack item : kit.getItems()) {
|
||||
if (item != null) stacks.add(item);
|
||||
if (item != null) {
|
||||
stacks.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
for (String command : kit.getCommands()) {
|
||||
stacks.add(new KitContentCommand(command).getItemForDisplay());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return stacks;
|
||||
}
|
||||
|
||||
public Set<String> getKits() {
|
||||
return cmi.getKitsManager().getKitMap().keySet();
|
||||
return this.cmi.getKitsManager().getKitMap().keySet();
|
||||
}
|
||||
|
||||
public long getDelay(String kitName) {
|
||||
return cmi.getKitsManager().getKit(kitName, true).getDelay();
|
||||
return this.cmi.getKitsManager().getKit(kitName, true).getDelay();
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,10 @@ public class DefaultHook implements Hook {
|
||||
Set<ItemStack> items = new HashSet<>();
|
||||
|
||||
for (Kits kit : Kits.values()) {
|
||||
if (!kit.name().equalsIgnoreCase(kitName)) continue;
|
||||
if (!kit.name().equalsIgnoreCase(kitName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (String string : kit.items) {
|
||||
items.add(ItemSerializer.deserializeItemStackFromJson(string));
|
||||
}
|
||||
@ -27,7 +30,9 @@ public class DefaultHook implements Hook {
|
||||
|
||||
for (Kits kit : Kits.values()) {
|
||||
if (kit == Kits.BRIANNA_1_12 && ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)
|
||||
|| kit == Kits.BRIANNA_1_13 && !ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) continue;
|
||||
|| kit == Kits.BRIANNA_1_13 && !ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
|
||||
continue;
|
||||
}
|
||||
kits.add(kit.name().toLowerCase().replace("_1_12", "").replace("_1_13", ""));
|
||||
}
|
||||
|
||||
@ -36,7 +41,9 @@ public class DefaultHook implements Hook {
|
||||
|
||||
public long getDelay(String kitName) {
|
||||
for (Kits kit : Kits.values()) {
|
||||
if (!kit.name().equalsIgnoreCase(kitName)) continue;
|
||||
if (!kit.name().equalsIgnoreCase(kitName)) {
|
||||
continue;
|
||||
}
|
||||
return kit.delay;
|
||||
}
|
||||
return 0;
|
||||
@ -57,8 +64,8 @@ public class DefaultHook implements Hook {
|
||||
|
||||
BRIANNA_1_13(0, "{id:\"minecraft:player_head\",Count:1b,tag:{SkullOwner:{Id:\"2626974f-5838-44c6-994d-f6c723d40b79\",Properties:{textures:[{Signature:\"tQRjs3H+5H5A8Id/Hb2a3E+VDQY8sUKQYacc9ZYDsBncagNO6imX6h6qsDmtTDtliTh8ZzHRIAw/6gQeiODJnOm4PAB2vPnUv0VFAP2awbikJeOSuK3WZsvcUN78+hXLFFtvBUt/oGKpsTj5P//2+qH7QLqmrxFD72jGpmyS8Fp6AHuQqzeHn40isvKT2+oTItFb3wQ3H2QgudGxEhOX6Onz0M2xmH61+HF5ajPS+/2hUl5kjRk8uRLc2AJD162dECdYOUJ8/j47Fl9pJXG1dcG6cGMuRlDAim3AqfdJFTW0CI78YEpTTGZcLL+O+/yUMQD9hOQqjP7y63YIOZ9kAZ7DRzu5hQaHLevhUcTwZnkqs+F9eUuQR00y8PoVoSEOMrV4LIWAJFutdziNZX9I7MI9tJ0x96imA18yYC9Skwx7JHurC1wpdtSqS/F7gCeU3+2QiFufxX9ft9BPHSBX7z08nqQkwxYh0O/06OX+H0NJTLwYrK+hoTXT1A5dNrJIHzGuK9/qUaitH4yz0zv5aGd3vVytdKCULFqOTiqur1QYPvF9sI2fhvfcHqUc30yU1di0Ws5SOQzCAFLOypjUH1ezQMOK+Xy3ixB0a8HXI9RL8ewOvKaVepbWS1vomNNWfiCgpudbLW8x6bPvQLmZn8YWPjCAL0WFycnw8lm6JDg=\",Value:\"eyJ0aW1lc3RhbXAiOjE1NzA5MDI0MDg4ODEsInByb2ZpbGVJZCI6IjA2Y2NiMGU0MWM3NjQ0YjE5OGZiYzk5OTBhODcwNjAwIiwicHJvZmlsZU5hbWUiOiJCcmlhbm5hIiwic2lnbmF0dXJlUmVxdWlyZWQiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS8yN2I3MjM5Yzk2OWNhNzY0NWJmMTQzODc4M2Y1Y2FiZjdlMDhhYTViODY4OGFkODg3NWJhNzNlNTVhNDBlMjIiLCJtZXRhZGF0YSI6eyJtb2RlbCI6InNsaW0ifX19fQ==\"}]},Name:\"Brianna\"},Damage:3}}");
|
||||
|
||||
public String[] items;
|
||||
public int delay;
|
||||
public final String[] items;
|
||||
public final int delay;
|
||||
|
||||
Kits(int delay, String... items) {
|
||||
this.items = items;
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.craftaro.ultimatekits.conversion.hooks;
|
||||
|
||||
import com.craftaro.ultimatekits.UltimateKits;
|
||||
import com.craftaro.ultimatekits.conversion.Hook;
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.Kit;
|
||||
import com.earth2me.essentials.MetaItemStack;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -12,39 +12,38 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class EssentialsHook implements Hook {
|
||||
|
||||
private Essentials essentials;
|
||||
private final Essentials essentials;
|
||||
|
||||
public EssentialsHook() {
|
||||
essentials = (Essentials) UltimateKits.getInstance().getServer().getPluginManager().getPlugin("Essentials");
|
||||
this.essentials = (Essentials) Bukkit.getServer().getPluginManager().getPlugin("Essentials");
|
||||
}
|
||||
|
||||
public Set<ItemStack> getItems(String kitName) {
|
||||
Set<ItemStack> stacks = new HashSet<>();
|
||||
try {
|
||||
Kit kit = new Kit(kitName, essentials);
|
||||
Kit kit = new Kit(kitName, this.essentials);
|
||||
|
||||
for (String nonParse : kit.getItems()) {
|
||||
String[] parts = nonParse.split(" +");
|
||||
ItemStack item = essentials.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1);
|
||||
ItemStack item = this.essentials.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1);
|
||||
MetaItemStack metaStack = new MetaItemStack(item);
|
||||
if (parts.length > 2 != nonParse.startsWith("/")) {
|
||||
try {
|
||||
metaStack.parseStringMeta(null, true, parts, 2, essentials);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
metaStack.parseStringMeta(null, true, parts, 2, this.essentials);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
stacks.add(metaStack.getItemStack());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return stacks;
|
||||
}
|
||||
|
||||
public Set<String> getKits() {
|
||||
ConfigurationSection cs = essentials.getSettings().getKits();
|
||||
ConfigurationSection cs = this.essentials.getSettings().getKits();
|
||||
Set<String> kits = new HashSet<>();
|
||||
try {
|
||||
cs.getKeys(false);
|
||||
@ -56,11 +55,11 @@ public class EssentialsHook implements Hook {
|
||||
}
|
||||
|
||||
public long getDelay(String kitName) {
|
||||
Object object = essentials.getSettings().getKit(kitName).getOrDefault("delay", 0);
|
||||
Object object = this.essentials.getSettings().getKit(kitName).getOrDefault("delay", 0);
|
||||
try {
|
||||
return Integer.toUnsignedLong((int) object);
|
||||
} catch (Exception e) {
|
||||
} catch (Exception ex) {
|
||||
return (long) object;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class UltimateCoreHook implements Hook {
|
||||
|
||||
@Override
|
||||
public Set<String> getKits() {
|
||||
Set<String> list = new HashSet<>();
|
||||
@ -22,14 +21,13 @@ public class UltimateCoreHook implements Hook {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ItemStack> getItems(String kit) {
|
||||
UKit uKit = new UKit(kit);
|
||||
Set<ItemStack> items = new HashSet<>(uKit.getItems());
|
||||
return items;
|
||||
public Set<ItemStack> getItems(String kitName) {
|
||||
UKit uKit = new UKit(kitName);
|
||||
return new HashSet<>(uKit.getItems());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDelay(String kit) {
|
||||
public long getDelay(String kitName) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Crate {
|
||||
|
||||
// Name of the crate
|
||||
private String name;
|
||||
|
||||
@ -35,51 +34,55 @@ public class Crate {
|
||||
ItemStack itemStack = new ItemStack(Material.CHEST, amount);
|
||||
|
||||
String kitName;
|
||||
if (kit != null)
|
||||
if (kit != null) {
|
||||
kitName = TextUtils.formatText(kit.getName(), true);
|
||||
else
|
||||
} else {
|
||||
kitName = "Any";
|
||||
}
|
||||
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
meta.setDisplayName(plugin.getLocale().getMessage("interface.crate.title")
|
||||
.processPlaceholder("kit", kitName)
|
||||
.processPlaceholder("crate", name)
|
||||
.processPlaceholder("crate", this.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");
|
||||
lore.add(ChatColor.DARK_PURPLE + kitName + " " + ChatColor.YELLOW + this.name + " " + ChatColor.WHITE + "Crate");
|
||||
|
||||
String desc1 = plugin.getLocale().getMessage("interface.crate.description1")
|
||||
.processPlaceholder("kit", kitName)
|
||||
.processPlaceholder("crate", name)
|
||||
.processPlaceholder("crate", this.name)
|
||||
.getMessage();
|
||||
|
||||
if (kitName.equals("Any"))
|
||||
if (kitName.equals("Any")) {
|
||||
desc1 = desc1.replaceAll("\\[.*?]", "");
|
||||
else
|
||||
} else {
|
||||
desc1 = desc1.replace("[", "").replace("]", "");
|
||||
}
|
||||
|
||||
lore.add(desc1);
|
||||
if (this.amount == -1)
|
||||
if (this.amount == -1) {
|
||||
lore.add(plugin.getLocale().getMessage("interface.crate.description2")
|
||||
.processPlaceholder("kit", kitName)
|
||||
.processPlaceholder("crate", name)
|
||||
.processPlaceholder("crate", this.name)
|
||||
.getMessage());
|
||||
else
|
||||
} else {
|
||||
lore.add(plugin.getLocale().getMessage("interface.crate.description3")
|
||||
.processPlaceholder("kit", kitName)
|
||||
.processPlaceholder("crate", name)
|
||||
.processPlaceholder("crate", this.name)
|
||||
.getMessage());
|
||||
if (kitAmount > 1)
|
||||
}
|
||||
if (this.kitAmount > 1) {
|
||||
lore.add(plugin.getLocale().getMessage("interface.crate.description4")
|
||||
.processPlaceholder("amt", this.kitAmount)
|
||||
.processPlaceholder("kit", kitName)
|
||||
.processPlaceholder("crate", name)
|
||||
.processPlaceholder("crate", this.name)
|
||||
.getMessage());
|
||||
}
|
||||
|
||||
meta.setLore(lore);
|
||||
|
||||
@ -89,7 +92,7 @@ public class Crate {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
@ -97,7 +100,7 @@ public class Crate {
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
return this.amount;
|
||||
}
|
||||
|
||||
public void setAmount(int amount) {
|
||||
@ -105,7 +108,7 @@ public class Crate {
|
||||
}
|
||||
|
||||
public int getKitAmount() {
|
||||
return kitAmount;
|
||||
return this.kitAmount;
|
||||
}
|
||||
|
||||
public void setKitAmount(int kitAmount) {
|
||||
|
@ -9,32 +9,34 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class CrateManager {
|
||||
|
||||
private final Set<Crate> registeredCrates = new HashSet<>();
|
||||
|
||||
public boolean addCrate(Crate crate) {
|
||||
return crate != null && registeredCrates.add(crate);
|
||||
return crate != null && this.registeredCrates.add(crate);
|
||||
}
|
||||
|
||||
public Crate getCrate(String name) {
|
||||
for (Crate crate : registeredCrates)
|
||||
if (crate.getName().equalsIgnoreCase(name))
|
||||
for (Crate crate : this.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)
|
||||
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 Collections.unmodifiableSet(registeredCrates);
|
||||
return Collections.unmodifiableSet(this.registeredCrates);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
registeredCrates.clear();
|
||||
this.registeredCrates.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,20 +17,22 @@ import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class DataManager {
|
||||
|
||||
private final UltimateKits plugin;
|
||||
|
||||
public DataManager(UltimateKits plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void bulkUpdateBlockData(Map<Location, KitBlockData> blockData) {
|
||||
try (Connection connection = plugin.getDataManager().getDatabaseConnector().getConnection()) {
|
||||
String updateData = "UPDATE " + plugin.getDataManager().getTablePrefix() + "blockdata SET type = ?, kit = ?, holograms = ?, " +
|
||||
try (Connection connection = this.plugin.getDataManager().getDatabaseConnector().getConnection()) {
|
||||
String updateData = "UPDATE " + this.plugin.getDataManager().getTablePrefix() + "blockdata SET type = ?, kit = ?, holograms = ?, " +
|
||||
"displayItems = ?, particles = ?, itemOverride = ? " +
|
||||
"WHERE world = ? AND x = ? AND y = ? AND z = ?";
|
||||
PreparedStatement statement = connection.prepareStatement(updateData);
|
||||
for (KitBlockData data : blockData.values()) {
|
||||
if (data == null || data.getWorld() == null) continue;
|
||||
if (data == null || data.getWorld() == null) {
|
||||
continue;
|
||||
}
|
||||
statement.setString(1, data.getType().toString());
|
||||
statement.setString(2, data.getKit().getKey());
|
||||
statement.setBoolean(3, data.showHologram());
|
||||
@ -51,11 +53,13 @@ public class DataManager {
|
||||
}
|
||||
|
||||
public void updateBlockData(KitBlockData blockData) {
|
||||
if (blockData.getWorld() == null) return;
|
||||
if (blockData.getWorld() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try (Connection connection = plugin.getDataManager().getDatabaseConnector().getConnection()) {
|
||||
String updateData = "UPDATE " + plugin.getDataManager().getTablePrefix() + "blockdata SET type = ?, kit = ?, holograms = ?, " +
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
try (Connection connection = this.plugin.getDataManager().getDatabaseConnector().getConnection()) {
|
||||
String updateData = "UPDATE " + this.plugin.getDataManager().getTablePrefix() + "blockdata SET type = ?, kit = ?, holograms = ?, " +
|
||||
"displayItems = ?, particles = ?, itemOverride = ? " +
|
||||
"WHERE world = ? AND x = ? AND y = ? AND z = ?";
|
||||
PreparedStatement statement = connection.prepareStatement(updateData);
|
||||
@ -77,10 +81,12 @@ public class DataManager {
|
||||
}
|
||||
|
||||
public void createBlockData(KitBlockData blockData) {
|
||||
if (blockData.getWorld() == null) return;
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try (Connection connection = plugin.getDataManager().getDatabaseConnector().getConnection()) {
|
||||
String createData = "INSERT INTO " + plugin.getDataManager().getTablePrefix() + "blockdata (" +
|
||||
if (blockData.getWorld() == null) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
try (Connection connection = this.plugin.getDataManager().getDatabaseConnector().getConnection()) {
|
||||
String createData = "INSERT INTO " + this.plugin.getDataManager().getTablePrefix() + "blockdata (" +
|
||||
"type, kit, holograms, displayItems, particles, itemOverride, world, x, y, z)" +
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
PreparedStatement statement = connection.prepareStatement(createData);
|
||||
@ -102,9 +108,9 @@ public class DataManager {
|
||||
}
|
||||
|
||||
public void deleteBlockData(KitBlockData blockData) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try (Connection connection = plugin.getDataManager().getDatabaseConnector().getConnection()) {
|
||||
String deleteData = "DELETE FROM " + plugin.getDataManager().getTablePrefix() + "blockdata WHERE world = ? " +
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
try (Connection connection = this.plugin.getDataManager().getDatabaseConnector().getConnection()) {
|
||||
String deleteData = "DELETE FROM " + this.plugin.getDataManager().getTablePrefix() + "blockdata WHERE world = ? " +
|
||||
"AND x = ? AND y = ? AND z = ?";
|
||||
PreparedStatement statement = connection.prepareStatement(deleteData);
|
||||
statement.setString(1, blockData.getWorld().getName());
|
||||
@ -119,20 +125,24 @@ public class DataManager {
|
||||
}
|
||||
|
||||
public void getBlockData(Consumer<Map<Location, KitBlockData>> callback) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try (Connection connection = plugin.getDataManager().getDatabaseConnector().getConnection()) {
|
||||
String selectData = "SELECT * FROM " + plugin.getDataManager().getTablePrefix() + "blockdata";
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
try (Connection connection = this.plugin.getDataManager().getDatabaseConnector().getConnection()) {
|
||||
String selectData = "SELECT * FROM " + this.plugin.getDataManager().getTablePrefix() + "blockdata";
|
||||
Map<Location, KitBlockData> blockData = new HashMap<>();
|
||||
Statement statement = connection.createStatement();
|
||||
ResultSet result = statement.executeQuery(selectData);
|
||||
while (result.next()) {
|
||||
|
||||
World world = Bukkit.getWorld(result.getString("world"));
|
||||
if (world == null) continue;
|
||||
if (world == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Kit kit = UltimateKits.getInstance().getKitManager().getKit(result.getString("kit"));
|
||||
KitType type = KitType.getKitType(result.getString("type"));
|
||||
if (kit == null || type == null) continue;
|
||||
if (kit == null || type == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean holograms = result.getBoolean("holograms");
|
||||
boolean displayItems = result.getBoolean("displayItems");
|
||||
@ -146,7 +156,7 @@ public class DataManager {
|
||||
blockData.put(location, new KitBlockData(kit, location, type, holograms, particles, displayItems, itemOverride));
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTask(plugin, () -> callback.accept(blockData));
|
||||
Bukkit.getScheduler().runTask(this.plugin, () -> callback.accept(blockData));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ public class _2_DuplicateMigration extends DataMigration {
|
||||
// Fix duplicate data caused by old sqlite data duplication bug
|
||||
boolean sqlite = connection instanceof SQLiteConnector;
|
||||
if (sqlite) {
|
||||
HashMap<String, TempKitData> data = new HashMap();
|
||||
HashMap<String, TempKitData> data = new HashMap<>();
|
||||
// grab a copy of the unique data values
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
ResultSet allData = statement.executeQuery("SELECT * FROM " + tablePrefix + "blockdata");
|
||||
@ -44,7 +44,9 @@ public class _2_DuplicateMigration extends DataMigration {
|
||||
}
|
||||
allData.close();
|
||||
}
|
||||
if (data.isEmpty()) return;
|
||||
if (data.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
connection.setAutoCommit(false);
|
||||
// first delete old data
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
|
@ -23,13 +23,12 @@ import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class AnimatedKitGui extends Gui {
|
||||
|
||||
static final Random rand = new Random();
|
||||
|
||||
private final UltimateKits plugin;
|
||||
private final Player player;
|
||||
private final ItemStack give;
|
||||
private final ArrayDeque<KitItem> items = new ArrayDeque();
|
||||
private final ArrayDeque<KitItem> items = new ArrayDeque<>();
|
||||
private boolean finish = false;
|
||||
private boolean done = false;
|
||||
private int tick = 0, updateTick = 0;
|
||||
@ -54,84 +53,83 @@ public class AnimatedKitGui extends Gui {
|
||||
Collections.shuffle(kitItems);
|
||||
this.items.addAll(kitItems);
|
||||
while (this.items.size() < 10) {
|
||||
items.addAll(kitItems);
|
||||
this.items.addAll(kitItems);
|
||||
}
|
||||
|
||||
setItem(4, GuiUtils.getBorderItem(XMaterial.TRIPWIRE_HOOK));
|
||||
setItem(22, GuiUtils.getBorderItem(XMaterial.TRIPWIRE_HOOK));
|
||||
tick();
|
||||
setOnOpen(event -> {
|
||||
task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> tick(), 1L, 1L);
|
||||
});
|
||||
setOnOpen(event -> this.task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, this::tick, 1L, 1L));
|
||||
}
|
||||
|
||||
private void tick() {
|
||||
if (++tick < ticksPerUpdate) {
|
||||
if (++this.tick < this.ticksPerUpdate) {
|
||||
return;
|
||||
}
|
||||
tick = 0;
|
||||
this.tick = 0;
|
||||
int updatesPerSlow = 6;
|
||||
if (++updateTick >= updatesPerSlow) {
|
||||
updateTick = 0;
|
||||
if (++this.updateTick >= updatesPerSlow) {
|
||||
this.updateTick = 0;
|
||||
int ticksPerUpdateSlow = Settings.ROULETTE_LENGTH_MULTIPLIER.getInt();
|
||||
if (++ticksPerUpdate >= ticksPerUpdateSlow) {
|
||||
finish = true;
|
||||
if (++this.ticksPerUpdate >= ticksPerUpdateSlow) {
|
||||
this.finish = true;
|
||||
}
|
||||
}
|
||||
// now update the display
|
||||
// rainbow disco!
|
||||
for (int col = 0; col < 9; ++col) {
|
||||
if (col == 4) continue;
|
||||
if (col == 4) {
|
||||
continue;
|
||||
}
|
||||
|
||||
setItem(0, col, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneForColor(rand.nextInt(16))));
|
||||
setItem(2, col, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneForColor(rand.nextInt(16))));
|
||||
}
|
||||
|
||||
// item slider
|
||||
if (!done) {
|
||||
XSound.UI_BUTTON_CLICK.play(player, 5F, 5F);
|
||||
items.addFirst(items.getLast());
|
||||
items.removeLast();
|
||||
Iterator<KitItem> itemIter = items.iterator();
|
||||
if (!this.done) {
|
||||
XSound.UI_BUTTON_CLICK.play(this.player, 5F, 5F);
|
||||
this.items.addFirst(this.items.getLast());
|
||||
this.items.removeLast();
|
||||
Iterator<KitItem> itemIter = this.items.iterator();
|
||||
for (int i = 9; i < 18; i++) {
|
||||
setItem(0, i, itemIter.next().getItem());
|
||||
}
|
||||
}
|
||||
|
||||
// should we try to wrap it up?
|
||||
if (finish) {
|
||||
if (this.finish) {
|
||||
ItemStack item = getItem(13);
|
||||
KitItem kitItem = items.stream().filter(i -> i.getItem().isSimilar(item)).findFirst().orElse(null);
|
||||
KitItem kitItem = this.items.stream().filter(i -> i.getItem().isSimilar(item)).findFirst().orElse(null);
|
||||
if (item == null) {
|
||||
done = true; // idk.
|
||||
} else if (item.isSimilar(give)) {
|
||||
if (!done) {
|
||||
done = true;
|
||||
if (!Settings.AUTO_EQUIP_ARMOR_ROULETTE.getBoolean() || !ArmorType.equip(player, give)) {
|
||||
this.done = true; // idk.
|
||||
} else if (item.isSimilar(this.give)) {
|
||||
if (!this.done) {
|
||||
this.done = true;
|
||||
if (!Settings.AUTO_EQUIP_ARMOR_ROULETTE.getBoolean() || !ArmorType.equip(this.player, this.give)) {
|
||||
|
||||
ItemStack processedItem = kitItem.getContent().process(player);
|
||||
ItemStack processedItem = kitItem.getContent().process(this.player);
|
||||
if (processedItem != null) {
|
||||
Map<Integer, ItemStack> overfilled = player.getInventory().addItem(give);
|
||||
Map<Integer, ItemStack> overfilled = this.player.getInventory().addItem(this.give);
|
||||
for (ItemStack item2 : overfilled.values()) {
|
||||
player.getWorld().dropItemNaturally(player.getLocation(), item2);
|
||||
this.player.getWorld().dropItemNaturally(this.player.getLocation(), item2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
XSound.ENTITY_PLAYER_LEVELUP.play(player, 10f, 10f);
|
||||
plugin.getLocale().getMessage("event.create.won")
|
||||
.processPlaceholder("item", WordUtils.capitalize(give.getType().name().toLowerCase().replace("_", " ")))
|
||||
.sendPrefixedMessage(player);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, this::finish, 50);
|
||||
XSound.ENTITY_PLAYER_LEVELUP.play(this.player, 10f, 10f);
|
||||
this.plugin.getLocale().getMessage("event.create.won")
|
||||
.processPlaceholder("item", WordUtils.capitalize(this.give.getType().name().toLowerCase().replace("_", " ")))
|
||||
.sendPrefixedMessage(this.player);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, this::finish, 50);
|
||||
setAllowClose(true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void finish() {
|
||||
Bukkit.getScheduler().cancelTask(task);
|
||||
Bukkit.getScheduler().cancelTask(this.task);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ import com.craftaro.core.gui.Gui;
|
||||
import com.craftaro.core.gui.GuiUtils;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.ultimatekits.UltimateKits;
|
||||
import com.craftaro.ultimatekits.kit.KitType;
|
||||
import com.craftaro.ultimatekits.kit.KitBlockData;
|
||||
import com.craftaro.ultimatekits.kit.KitType;
|
||||
import com.craftaro.ultimatekits.settings.Settings;
|
||||
import com.craftaro.ultimatekits.utils.Methods;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -15,7 +15,6 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class BlockEditorGui extends Gui {
|
||||
|
||||
private final KitBlockData kitBlockData;
|
||||
|
||||
public BlockEditorGui(UltimateKits plugin, KitBlockData kitBlockData) {
|
||||
@ -30,14 +29,14 @@ public class BlockEditorGui extends Gui {
|
||||
|
||||
// exit button
|
||||
setButton(0, 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(XMaterial.OAK_DOOR),
|
||||
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
|
||||
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
|
||||
ClickType.LEFT,
|
||||
event -> event.player.closeInventory());
|
||||
|
||||
// kit type
|
||||
setButton(1, 2, GuiUtils.createButtonItem(XMaterial.COMPARATOR,
|
||||
plugin.getLocale().getMessage("interface.kitblock.switchtype").getMessage(),
|
||||
kitTypeLore(plugin)),
|
||||
plugin.getLocale().getMessage("interface.kitblock.switchtype").getMessage(),
|
||||
kitTypeLore(plugin)),
|
||||
ClickType.LEFT,
|
||||
event -> {
|
||||
plugin.removeHologram(kitBlockData);
|
||||
@ -58,18 +57,18 @@ public class BlockEditorGui extends Gui {
|
||||
|
||||
// decor options
|
||||
setButton(1, 4, GuiUtils.createButtonItem(XMaterial.POPPY,
|
||||
plugin.getLocale().getMessage("interface.kitblock.decor").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kitblock.decorlore").getMessage().split("\\|")),
|
||||
plugin.getLocale().getMessage("interface.kitblock.decor").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kitblock.decorlore").getMessage().split("\\|")),
|
||||
ClickType.LEFT,
|
||||
event -> event.manager.showGUI(event.player, new KitDecorOptionsGui(plugin, kitBlockData, this)));
|
||||
|
||||
// edit
|
||||
setButton(1, 6, GuiUtils.createButtonItem(XMaterial.DIAMOND_PICKAXE,
|
||||
plugin.getLocale().getMessage("interface.kitblock.edit").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kitblock.editlore").getMessage().split("\\|")),
|
||||
plugin.getLocale().getMessage("interface.kitblock.edit").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kitblock.editlore").getMessage().split("\\|")),
|
||||
ClickType.LEFT,
|
||||
event -> {
|
||||
guiManager.showGUI(event.player, new KitEditorGui(UltimateKits.getInstance(), event.player, kitBlockData.getKit(), this));
|
||||
this.guiManager.showGUI(event.player, new KitEditorGui(UltimateKits.getInstance(), event.player, kitBlockData.getKit(), this));
|
||||
});
|
||||
|
||||
}
|
||||
@ -78,9 +77,8 @@ public class BlockEditorGui extends Gui {
|
||||
String[] type = plugin.getLocale().getMessage("interface.kitblock.switchtypelore").getMessage().split("\\|");
|
||||
return Arrays.asList(
|
||||
type[0],
|
||||
(kitBlockData.getType() == KitType.PREVIEW ? ChatColor.GOLD : ChatColor.GRAY) + (type.length > 1 ? type[1] : "Preview"),
|
||||
(kitBlockData.getType() == KitType.CRATE ? ChatColor.GOLD : ChatColor.GRAY) + (type.length > 2 ? type[2] : "Crate"),
|
||||
(kitBlockData.getType() == KitType.CLAIM ? ChatColor.GOLD : ChatColor.GRAY) + (type.length > 3 ? type[3] : "Claim"));
|
||||
(this.kitBlockData.getType() == KitType.PREVIEW ? ChatColor.GOLD : ChatColor.GRAY) + (type.length > 1 ? type[1] : "Preview"),
|
||||
(this.kitBlockData.getType() == KitType.CRATE ? ChatColor.GOLD : ChatColor.GRAY) + (type.length > 2 ? type[2] : "Crate"),
|
||||
(this.kitBlockData.getType() == KitType.CLAIM ? ChatColor.GOLD : ChatColor.GRAY) + (type.length > 3 ? type[3] : "Claim"));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ import org.bukkit.event.inventory.ClickType;
|
||||
import java.util.List;
|
||||
|
||||
public class CategoryEditorGui extends Gui {
|
||||
|
||||
private final UltimateKits plugin;
|
||||
private final Player player;
|
||||
private final CategoryManager categoryManager;
|
||||
@ -36,7 +35,7 @@ public class CategoryEditorGui extends Gui {
|
||||
|
||||
setButton(4, GuiUtils.createButtonItem(XMaterial.GREEN_DYE, "Create Category"),
|
||||
(event) -> {
|
||||
if (categoryManager.getCategories().size() >= 7) {
|
||||
if (this.categoryManager.getCategories().size() >= 7) {
|
||||
plugin.getLocale().newMessage("&cYou already have the maximum amount of categories...").sendPrefixedMessage(player);
|
||||
} else {
|
||||
ChatPrompt.showPrompt(event.manager.getPlugin(), event.player, "Enter a category name:", response -> {
|
||||
@ -44,12 +43,12 @@ public class CategoryEditorGui extends Gui {
|
||||
|
||||
String key = msg.toUpperCase().replace(" ", "_");
|
||||
|
||||
if (categoryManager.getCategory(key) != null) {
|
||||
if (this.categoryManager.getCategory(key) != null) {
|
||||
plugin.getLocale().newMessage("&cA category with that name already exists...").sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
|
||||
categoryManager.addCategory(key, msg);
|
||||
this.categoryManager.addCategory(key, msg);
|
||||
plugin.getLocale().newMessage("&aCategory added successfully!").sendPrefixedMessage(player);
|
||||
|
||||
Bukkit.getScheduler().runTask(plugin, player::closeInventory);
|
||||
@ -62,14 +61,14 @@ public class CategoryEditorGui extends Gui {
|
||||
|
||||
// exit button
|
||||
setButton(0, 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(XMaterial.OAK_DOOR),
|
||||
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
|
||||
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
|
||||
ClickType.LEFT,
|
||||
event -> exit());
|
||||
paint();
|
||||
}
|
||||
|
||||
private void paint() {
|
||||
List<Category> categories = categoryManager.getCategories();
|
||||
List<Category> categories = this.categoryManager.getCategories();
|
||||
for (int i = 0; i < categories.size(); i++) {
|
||||
Category category = categories.get(i);
|
||||
setButton(i + 10,
|
||||
@ -83,17 +82,17 @@ public class CategoryEditorGui extends Gui {
|
||||
TextUtils.formatText("&cRight click to remove."),
|
||||
TextUtils.formatText("&c(Kits will not be removed)")),
|
||||
(event) -> {
|
||||
if (event.clickType == ClickType.LEFT)
|
||||
if (event.clickType == ClickType.LEFT) {
|
||||
ChatPrompt.showPrompt(event.manager.getPlugin(), event.player, "Enter a name:", response -> {
|
||||
category.setName(response.getMessage().trim());
|
||||
event.manager.showGUI(event.player, new CategoryEditorGui(plugin, event.player));
|
||||
event.manager.showGUI(event.player, new CategoryEditorGui(this.plugin, event.player));
|
||||
});
|
||||
else if (event.clickType == ClickType.MIDDLE) {
|
||||
category.setMaterial(player.getItemInHand().getType());
|
||||
event.manager.showGUI(event.player, new CategoryEditorGui(plugin, event.player));
|
||||
} else if (event.clickType == ClickType.MIDDLE) {
|
||||
category.setMaterial(this.player.getItemInHand().getType());
|
||||
event.manager.showGUI(event.player, new CategoryEditorGui(this.plugin, event.player));
|
||||
} else if (event.clickType == ClickType.RIGHT) {
|
||||
categoryManager.removeCategory(category);
|
||||
event.manager.showGUI(event.player, new CategoryEditorGui(plugin, event.player));
|
||||
this.categoryManager.removeCategory(category);
|
||||
event.manager.showGUI(event.player, new CategoryEditorGui(this.plugin, event.player));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -6,8 +6,8 @@ import com.craftaro.core.gui.GuiUtils;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.utils.TextUtils;
|
||||
import com.craftaro.ultimatekits.UltimateKits;
|
||||
import com.craftaro.ultimatekits.kit.Kit;
|
||||
import com.craftaro.ultimatekits.category.Category;
|
||||
import com.craftaro.ultimatekits.kit.Kit;
|
||||
import com.craftaro.ultimatekits.settings.Settings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@ -19,7 +19,6 @@ import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class CategorySelectorGui extends Gui {
|
||||
|
||||
private int timer;
|
||||
private static final Random rand = new Random();
|
||||
|
||||
@ -28,9 +27,11 @@ public class CategorySelectorGui extends Gui {
|
||||
|
||||
Set<Category> categories = new LinkedHashSet<>();
|
||||
|
||||
for (Kit kit : plugin.getKitManager().getKits())
|
||||
if (kit.hasPermissionToPreview(player) && kit.getCategory() != null)
|
||||
for (Kit kit : plugin.getKitManager().getKits()) {
|
||||
if (kit.hasPermissionToPreview(player) && kit.getCategory() != null) {
|
||||
categories.add(kit.getCategory());
|
||||
}
|
||||
}
|
||||
|
||||
setTitle(plugin.getLocale().getMessage("interface.categoryselector.title").getMessage());
|
||||
|
||||
@ -43,8 +44,8 @@ public class CategorySelectorGui extends Gui {
|
||||
.processPlaceholder("player", player.getName()).getMessage().split("\\|")));
|
||||
|
||||
if (!glassless) {
|
||||
setButton(rows - 1, 4, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(XMaterial.OAK_DOOR),
|
||||
UltimateKits.getInstance().getLocale().getMessage("interface.button.exit").getMessage()),
|
||||
setButton(this.rows - 1, 4, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(XMaterial.OAK_DOOR),
|
||||
UltimateKits.getInstance().getLocale().getMessage("interface.button.exit").getMessage()),
|
||||
event -> exit());
|
||||
}
|
||||
|
||||
@ -55,11 +56,13 @@ public class CategorySelectorGui extends Gui {
|
||||
if (!glassless) {
|
||||
if (Settings.RAINBOW.getBoolean()) {
|
||||
animateGlass();
|
||||
timer = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
|
||||
if (inventory.getViewers().isEmpty()) return;
|
||||
this.timer = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
|
||||
if (this.inventory.getViewers().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
animateGlass();
|
||||
}, 20L, 20L);
|
||||
setOnClose(event -> Bukkit.getScheduler().cancelTask(timer));
|
||||
setOnClose(event -> Bukkit.getScheduler().cancelTask(this.timer));
|
||||
} else {
|
||||
ItemStack glass1 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_1.getMaterial());
|
||||
ItemStack glass3 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_3.getMaterial());
|
||||
@ -74,11 +77,11 @@ public class CategorySelectorGui extends Gui {
|
||||
int i = 10;
|
||||
for (Category category : categories) {
|
||||
setButton(i, GuiUtils.createButtonItem(XMaterial.matchXMaterial(category.getMaterial()),
|
||||
TextUtils.formatText(category.getName()),
|
||||
"",
|
||||
plugin.getLocale().getMessage("interface.categoryselector.view").getMessage()),
|
||||
TextUtils.formatText(category.getName()),
|
||||
"",
|
||||
plugin.getLocale().getMessage("interface.categoryselector.view").getMessage()),
|
||||
event -> {
|
||||
guiManager.showGUI(player, new KitSelectorGui(plugin, player, category));
|
||||
this.guiManager.showGUI(player, new KitSelectorGui(plugin, player, category));
|
||||
});
|
||||
i++;
|
||||
}
|
||||
@ -88,12 +91,14 @@ public class CategorySelectorGui extends Gui {
|
||||
private void animateGlass() {
|
||||
for (int col = 1; col < 8; ++col) {
|
||||
ItemStack it;
|
||||
if ((it = getItem(0, col)) == null || it.getType() == Material.AIR || it.getType().name().contains("PANE"))
|
||||
if ((it = getItem(0, col)) == null || it.getType() == Material.AIR || it.getType().name().contains("PANE")) {
|
||||
setItem(0, col, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneForColor(rand.nextInt(16))));
|
||||
if ((it = getItem(rows - 1, col)) == null || it.getType() == Material.AIR || it.getType().name().contains("PANE"))
|
||||
setItem(rows - 1, col, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneForColor(rand.nextInt(16))));
|
||||
}
|
||||
if ((it = getItem(this.rows - 1, col)) == null || it.getType() == Material.AIR || it.getType().name().contains("PANE")) {
|
||||
setItem(this.rows - 1, col, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneForColor(rand.nextInt(16))));
|
||||
}
|
||||
}
|
||||
for (int row = 1; row + 1 < rows; ++row) {
|
||||
for (int row = 1; row + 1 < this.rows; ++row) {
|
||||
setItem(row, 0, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneForColor(rand.nextInt(16))));
|
||||
setItem(row, 8, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneForColor(rand.nextInt(16))));
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.craftaro.ultimatekits.gui;
|
||||
import com.craftaro.core.gui.Gui;
|
||||
import com.craftaro.core.gui.GuiUtils;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.utils.NumberUtils;
|
||||
import com.craftaro.core.utils.TextUtils;
|
||||
import com.craftaro.ultimatekits.UltimateKits;
|
||||
import com.craftaro.ultimatekits.kit.Kit;
|
||||
@ -12,14 +13,14 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ConfirmBuyGui extends Gui {
|
||||
|
||||
public ConfirmBuyGui(UltimateKits plugin, Player player, Kit kit, Gui back) {
|
||||
super(back);
|
||||
setRows(3);
|
||||
|
||||
double cost = kit.getPrice();
|
||||
if (kit.hasPermissionToClaim(player))
|
||||
if (kit.hasPermissionToClaim(player)) {
|
||||
cost = 0;
|
||||
}
|
||||
|
||||
setTitle(plugin.getLocale().getMessage("interface.yesno.title")
|
||||
.processPlaceholder("price", cost)
|
||||
@ -31,11 +32,11 @@ public class ConfirmBuyGui extends Gui {
|
||||
// Kit information
|
||||
setItem(0, 4, GuiUtils.createButtonItem(kit.getDisplayItem() != null ? kit.getDisplayItem() : XMaterial.DIAMOND_HELMET.parseItem(),
|
||||
ChatColor.RED + TextUtils.formatText(kit.getKey().toLowerCase(), true),
|
||||
ChatColor.GREEN + Settings.CURRENCY_SYMBOL.getString() + Methods.formatEconomy(cost)));
|
||||
ChatColor.GREEN + Settings.CURRENCY_SYMBOL.getString() + NumberUtils.formatNumber(cost)));
|
||||
|
||||
// confirm button
|
||||
setButton(1, 2, GuiUtils.createButtonItem(Settings.BUY_ICON.getMaterial(XMaterial.EMERALD),
|
||||
plugin.getLocale().getMessage("interface.yesno.yes").getMessage()),
|
||||
plugin.getLocale().getMessage("interface.yesno.yes").getMessage()),
|
||||
event -> {
|
||||
kit.processPurchaseUse(event.player);
|
||||
exit();
|
||||
@ -43,12 +44,10 @@ public class ConfirmBuyGui extends Gui {
|
||||
|
||||
// cancel button
|
||||
setButton(1, 6, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(XMaterial.OAK_DOOR),
|
||||
plugin.getLocale().getMessage("interface.yesno.no").getMessage()),
|
||||
plugin.getLocale().getMessage("interface.yesno.no").getMessage()),
|
||||
event -> {
|
||||
plugin.getLocale().getMessage("event.purchase.cancelled").sendPrefixedMessage(event.player);
|
||||
event.player.closeInventory();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import com.craftaro.ultimatekits.utils.Methods;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
public class KitDecorOptionsGui extends Gui {
|
||||
|
||||
public KitDecorOptionsGui(UltimateKits plugin, KitBlockData kitBlockData, Gui parent) {
|
||||
super(parent);
|
||||
setRows(3);
|
||||
@ -27,13 +26,13 @@ public class KitDecorOptionsGui extends Gui {
|
||||
|
||||
// exit button
|
||||
setButton(0, 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(XMaterial.OAK_DOOR),
|
||||
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
|
||||
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
|
||||
ClickType.LEFT,
|
||||
event -> exit());
|
||||
|
||||
// back button
|
||||
setButton(0, 0, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
|
||||
plugin.getLocale().getMessage("interface.button.back").getMessage()),
|
||||
plugin.getLocale().getMessage("interface.button.back").getMessage()),
|
||||
ClickType.LEFT,
|
||||
event -> event.player.closeInventory());
|
||||
|
||||
@ -42,8 +41,8 @@ public class KitDecorOptionsGui extends Gui {
|
||||
|
||||
// Hologram
|
||||
setButton(1, 1, GuiUtils.createButtonItem(XMaterial.NAME_TAG,
|
||||
plugin.getLocale().getMessage("interface.kitdecor.hologram").getMessage(),
|
||||
kitBlockData.showHologram() ? enableLore : disableLore),
|
||||
plugin.getLocale().getMessage("interface.kitdecor.hologram").getMessage(),
|
||||
kitBlockData.showHologram() ? enableLore : disableLore),
|
||||
event -> {
|
||||
kitBlockData.setShowHologram(!kitBlockData.showHologram());
|
||||
plugin.updateHologram(kitBlockData);
|
||||
@ -52,8 +51,8 @@ public class KitDecorOptionsGui extends Gui {
|
||||
|
||||
// Particle effects
|
||||
setButton(1, 3, GuiUtils.createButtonItem(XMaterial.POTION,
|
||||
plugin.getLocale().getMessage("interface.kitdecor.particle").getMessage(),
|
||||
kitBlockData.hasParticles() ? enableLore : disableLore),
|
||||
plugin.getLocale().getMessage("interface.kitdecor.particle").getMessage(),
|
||||
kitBlockData.hasParticles() ? enableLore : disableLore),
|
||||
event -> {
|
||||
kitBlockData.setHasParticles(!kitBlockData.hasParticles());
|
||||
updateItemLore(event.slot, kitBlockData.hasParticles() ? enableLore : disableLore);
|
||||
@ -61,8 +60,8 @@ public class KitDecorOptionsGui extends Gui {
|
||||
|
||||
// Item Display
|
||||
setButton(1, 5, GuiUtils.createButtonItem(XMaterial.DIAMOND,
|
||||
plugin.getLocale().getMessage("interface.kitdecor.display").getMessage(),
|
||||
kitBlockData.isDisplayingItems() ? enableLore : disableLore),
|
||||
plugin.getLocale().getMessage("interface.kitdecor.display").getMessage(),
|
||||
kitBlockData.isDisplayingItems() ? enableLore : disableLore),
|
||||
event -> {
|
||||
plugin.removeHologram(kitBlockData);
|
||||
kitBlockData.setDisplayingItems(!kitBlockData.isDisplayingItems());
|
||||
@ -72,15 +71,13 @@ public class KitDecorOptionsGui extends Gui {
|
||||
|
||||
// Item Display Override
|
||||
setButton(1, 7, GuiUtils.createButtonItem(kit.getDisplayItem() != null ? kit.getDisplayItem() : XMaterial.BEACON.parseItem(),
|
||||
plugin.getLocale().getMessage("interface.kitdecor.displayone").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kitdecor.displayonelore")
|
||||
.processPlaceholder("enabled", kitBlockData.isItemOverride() ? enableLore : disableLore)
|
||||
.getMessage().split("\\|")),
|
||||
plugin.getLocale().getMessage("interface.kitdecor.displayone").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kitdecor.displayonelore")
|
||||
.processPlaceholder("enabled", kitBlockData.isItemOverride() ? enableLore : disableLore)
|
||||
.getMessage().split("\\|")),
|
||||
event -> {
|
||||
kitBlockData.setItemOverride(!kitBlockData.isItemOverride());
|
||||
updateItemLore(event.slot, kitBlockData.isItemOverride() ? enableLore : disableLore);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class KitEditorGui extends DoubleGui {
|
||||
|
||||
private final UltimateKits plugin;
|
||||
private final Kit kit;
|
||||
private final Player player;
|
||||
@ -54,7 +53,7 @@ public class KitEditorGui extends DoubleGui {
|
||||
|
||||
setOnClose((event) -> {
|
||||
restoreItemsInstance();
|
||||
saveKit(player, inventory, false);
|
||||
saveKit(player, this.inventory, false);
|
||||
XSound.ENTITY_VILLAGER_YES.play(player);
|
||||
});
|
||||
|
||||
@ -70,19 +69,20 @@ public class KitEditorGui extends DoubleGui {
|
||||
|
||||
// exit button
|
||||
setButton(0, 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(XMaterial.OAK_DOOR),
|
||||
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
|
||||
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
|
||||
ClickType.LEFT,
|
||||
event -> player.closeInventory());
|
||||
|
||||
// back button
|
||||
if (parent != null)
|
||||
if (this.parent != null) {
|
||||
setButton(0, 0, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
|
||||
plugin.getLocale().getMessage("interface.button.back").getMessage()),
|
||||
plugin.getLocale().getMessage("interface.button.back").getMessage()),
|
||||
ClickType.LEFT,
|
||||
event -> {
|
||||
player.closeInventory();
|
||||
guiManager.showGUI(player, back);
|
||||
this.guiManager.showGUI(player, back);
|
||||
});
|
||||
}
|
||||
|
||||
// info icon
|
||||
setItem(0, 4, GuiUtils.createButtonItem(XMaterial.CHEST,
|
||||
@ -100,40 +100,42 @@ public class KitEditorGui extends DoubleGui {
|
||||
|
||||
private void paint() {
|
||||
for (int i = 10; i < 44; i++) {
|
||||
if (i == 17 || i == 36)
|
||||
if (i == 17 || i == 36) {
|
||||
continue;
|
||||
}
|
||||
setItem(i, null);
|
||||
}
|
||||
|
||||
int num = 10;
|
||||
for (ItemStack itemStack : kit.getReadableContents(player, false, true, true)) {
|
||||
if (num == 17 || num == 36)
|
||||
for (ItemStack itemStack : this.kit.getReadableContents(this.player, false, true, true)) {
|
||||
if (num == 17 || num == 36) {
|
||||
num++;
|
||||
}
|
||||
|
||||
KitItem item = new KitItem(itemStack);
|
||||
ItemStack is = getCompiledMeta(item);
|
||||
|
||||
|
||||
if (!isInFunction)
|
||||
if (!this.isInFunction) {
|
||||
setButton(num, is, null);
|
||||
else {
|
||||
} else {
|
||||
setButton(num, is,
|
||||
(event) -> {
|
||||
switch (event.clickType) {
|
||||
case SHIFT_LEFT:
|
||||
replaceItem(Action.CHANCE_UP, player, event.clickedItem, event.slot);
|
||||
replaceItem(Action.CHANCE_UP, this.player, event.clickedItem, event.slot);
|
||||
break;
|
||||
case SHIFT_RIGHT:
|
||||
replaceItem(Action.CHANCE_DOWN, player, event.clickedItem, event.slot);
|
||||
replaceItem(Action.CHANCE_DOWN, this.player, event.clickedItem, event.slot);
|
||||
break;
|
||||
case LEFT:
|
||||
replaceItem(Action.DISPLAY_ITEM, player, event.clickedItem, event.slot);
|
||||
replaceItem(Action.DISPLAY_ITEM, this.player, event.clickedItem, event.slot);
|
||||
break;
|
||||
case MIDDLE:
|
||||
replaceItem(Action.DISPLAY_NAME, player, event.clickedItem, event.slot);
|
||||
replaceItem(Action.DISPLAY_NAME, this.player, event.clickedItem, event.slot);
|
||||
break;
|
||||
case RIGHT:
|
||||
replaceItem(Action.DISPLAY_LORE, player, event.clickedItem, event.slot);
|
||||
replaceItem(Action.DISPLAY_LORE, this.player, event.clickedItem, event.slot);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -147,41 +149,41 @@ public class KitEditorGui extends DoubleGui {
|
||||
private void updateInvButton() {
|
||||
ItemStack item;
|
||||
|
||||
if (!isInFunction) {
|
||||
if (!this.isInFunction) {
|
||||
setUnlockedRange(1, 1, 1, 7);
|
||||
setUnlockedRange(2, 0, 3, 8);
|
||||
setUnlockedRange(4, 1, 4, 7);
|
||||
|
||||
item = GuiUtils.createButtonItem(XMaterial.PAPER,
|
||||
plugin.getLocale().getMessage("interface.kiteditor.itemediting").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kiteditor.itemeditinglore").getMessage().split("\\|"));
|
||||
this.plugin.getLocale().getMessage("interface.kiteditor.itemediting").getMessage(),
|
||||
this.plugin.getLocale().getMessage("interface.kiteditor.itemeditinglore").getMessage().split("\\|"));
|
||||
} else {
|
||||
unlockedCells.clear();
|
||||
this.unlockedCells.clear();
|
||||
|
||||
item = GuiUtils.createButtonItem(XMaterial.PAPER,
|
||||
plugin.getLocale().getMessage("interface.kiteditor.itemmoving").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kiteditor.itemmovinglore").getMessage().split("\\|"));
|
||||
this.plugin.getLocale().getMessage("interface.kiteditor.itemmoving").getMessage(),
|
||||
this.plugin.getLocale().getMessage("interface.kiteditor.itemmovinglore").getMessage().split("\\|"));
|
||||
}
|
||||
|
||||
setButton(48, item,
|
||||
(event) -> {
|
||||
isInFunction = !isInFunction;
|
||||
saveKit(player, inventory, true);
|
||||
this.isInFunction = !this.isInFunction;
|
||||
saveKit(this.player, this.inventory, true);
|
||||
paint();
|
||||
});
|
||||
|
||||
ItemStack item2;
|
||||
|
||||
item2 = isInInventory ? GuiUtils.createButtonItem(XMaterial.ITEM_FRAME,
|
||||
plugin.getLocale().getMessage("interface.kiteditor.switchtokitfunctions").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kiteditor.switchtokitfunctionslore").getMessage().split("\\|"))
|
||||
item2 = this.isInInventory ? GuiUtils.createButtonItem(XMaterial.ITEM_FRAME,
|
||||
this.plugin.getLocale().getMessage("interface.kiteditor.switchtokitfunctions").getMessage(),
|
||||
this.plugin.getLocale().getMessage("interface.kiteditor.switchtokitfunctionslore").getMessage().split("\\|"))
|
||||
: GuiUtils.createButtonItem(XMaterial.ITEM_FRAME,
|
||||
plugin.getLocale().getMessage("interface.kiteditor.switchtoinventory").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kiteditor.switchtoinventorylore").getMessage().split("\\|"));
|
||||
this.plugin.getLocale().getMessage("interface.kiteditor.switchtoinventory").getMessage(),
|
||||
this.plugin.getLocale().getMessage("interface.kiteditor.switchtoinventorylore").getMessage().split("\\|"));
|
||||
|
||||
setButton(50, item2,
|
||||
event -> {
|
||||
if (!isInInventory) {
|
||||
if (!this.isInInventory) {
|
||||
restoreItemsInstance();
|
||||
setPlayerActionForRange(0, 0, 3, 8, null);
|
||||
setAcceptsItems(true);
|
||||
@ -196,77 +198,79 @@ public class KitEditorGui extends DoubleGui {
|
||||
|
||||
private void saveItemsInstance() {
|
||||
setPlayerUnlockedRange(0, 0, 3, 8, false);
|
||||
stash = player.getInventory().getContents().clone();
|
||||
player.getInventory().clear();
|
||||
isInInventory = false;
|
||||
this.stash = this.player.getInventory().getContents().clone();
|
||||
this.player.getInventory().clear();
|
||||
this.isInInventory = false;
|
||||
}
|
||||
|
||||
private void restoreItemsInstance() {
|
||||
if (!isInInventory)
|
||||
player.getInventory().clear();
|
||||
if (!this.isInInventory) {
|
||||
this.player.getInventory().clear();
|
||||
}
|
||||
setPlayerUnlockedRange(0, 0, 3, 8);
|
||||
if (stash != null)
|
||||
player.getInventory().setContents(stash);
|
||||
player.updateInventory();
|
||||
isInInventory = true;
|
||||
if (this.stash != null) {
|
||||
this.player.getInventory().setContents(this.stash);
|
||||
}
|
||||
this.player.updateInventory();
|
||||
this.isInInventory = true;
|
||||
}
|
||||
|
||||
private void setInvItems() {
|
||||
setPlayerButton(0, GuiUtils.createButtonItem(XMaterial.REDSTONE_TORCH,
|
||||
plugin.getLocale().getMessage("interface.kiteditor.generaloptions").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kiteditor.generaloptionslore").getMessage().split("\\|")),
|
||||
this.plugin.getLocale().getMessage("interface.kiteditor.generaloptions").getMessage(),
|
||||
this.plugin.getLocale().getMessage("interface.kiteditor.generaloptionslore").getMessage().split("\\|")),
|
||||
(event) -> {
|
||||
player.closeInventory();
|
||||
guiManager.showGUI(player, new KitGeneralOptionsGui(plugin, player, kit, back));
|
||||
this.player.closeInventory();
|
||||
this.guiManager.showGUI(this.player, new KitGeneralOptionsGui(this.plugin, this.player, this.kit, this.back));
|
||||
});
|
||||
|
||||
setPlayerButton(1, GuiUtils.createButtonItem(XMaterial.EMERALD,
|
||||
plugin.getLocale().getMessage("interface.kiteditor.sellingoptions").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kiteditor.sellingoptionslore").getMessage().split("\\|")),
|
||||
this.plugin.getLocale().getMessage("interface.kiteditor.sellingoptions").getMessage(),
|
||||
this.plugin.getLocale().getMessage("interface.kiteditor.sellingoptionslore").getMessage().split("\\|")),
|
||||
(event) -> {
|
||||
player.closeInventory();
|
||||
guiManager.showGUI(player, new KitSellingOptionsGui(plugin, player, kit, back));
|
||||
this.player.closeInventory();
|
||||
this.guiManager.showGUI(this.player, new KitSellingOptionsGui(this.plugin, this.player, this.kit, this.back));
|
||||
});
|
||||
|
||||
setPlayerButton(3, GuiUtils.createButtonItem(XMaterial.ITEM_FRAME,
|
||||
plugin.getLocale().getMessage("interface.kiteditor.guioptions").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kiteditor.guioptionslore").getMessage().split("\\|")),
|
||||
this.plugin.getLocale().getMessage("interface.kiteditor.guioptions").getMessage(),
|
||||
this.plugin.getLocale().getMessage("interface.kiteditor.guioptionslore").getMessage().split("\\|")),
|
||||
(event) -> {
|
||||
player.closeInventory();
|
||||
guiManager.showGUI(player, new KitGuiOptionsGui(plugin, player, kit, back));
|
||||
this.player.closeInventory();
|
||||
this.guiManager.showGUI(this.player, new KitGuiOptionsGui(this.plugin, this.player, this.kit, this.back));
|
||||
});
|
||||
|
||||
setPlayerButton(4, GuiUtils.createButtonItem(XMaterial.PAPER,
|
||||
plugin.getLocale().getMessage("interface.kiteditor.addcommand").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kiteditor.addcommandlore").getMessage().split("\\|")),
|
||||
this.plugin.getLocale().getMessage("interface.kiteditor.addcommand").getMessage(),
|
||||
this.plugin.getLocale().getMessage("interface.kiteditor.addcommandlore").getMessage().split("\\|")),
|
||||
(event) -> {
|
||||
event.gui.exit();
|
||||
ChatPrompt.showPrompt(event.manager.getPlugin(), event.player, "Enter a command for this kit:", response -> {
|
||||
String msg = response.getMessage().trim();
|
||||
String msg = response.getMessage().trim();
|
||||
|
||||
ItemStack parseStack = new ItemStack(Material.PAPER, 1);
|
||||
ItemMeta meta = parseStack.getItemMeta();
|
||||
ItemStack parseStack = new ItemStack(Material.PAPER, 1);
|
||||
ItemMeta meta = parseStack.getItemMeta();
|
||||
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
|
||||
int index = 0;
|
||||
while (index < msg.length()) {
|
||||
lore.add(ChatColor.GREEN + (index == 0 ? "/" : "") + msg.substring(index, Math.min(index + 30, msg.length())));
|
||||
index += 30;
|
||||
}
|
||||
meta.setLore(lore);
|
||||
meta.setDisplayName(plugin.getLocale().getMessage("general.type.command").getMessage());
|
||||
parseStack.setItemMeta(meta);
|
||||
int index = 0;
|
||||
while (index < msg.length()) {
|
||||
lore.add(ChatColor.GREEN + (index == 0 ? "/" : "") + msg.substring(index, Math.min(index + 30, msg.length())));
|
||||
index += 30;
|
||||
}
|
||||
meta.setLore(lore);
|
||||
meta.setDisplayName(this.plugin.getLocale().getMessage("general.type.command").getMessage());
|
||||
parseStack.setItemMeta(meta);
|
||||
|
||||
plugin.getLocale().newMessage(plugin.getLocale().getMessage("interface.kiteditor.addcommandok")
|
||||
.processPlaceholder("command", msg).getMessage())
|
||||
.sendPrefixedMessage(player);
|
||||
this.plugin.getLocale().newMessage(this.plugin.getLocale().getMessage("interface.kiteditor.addcommandok")
|
||||
.processPlaceholder("command", msg).getMessage())
|
||||
.sendPrefixedMessage(this.player);
|
||||
|
||||
inventory.addItem(parseStack);
|
||||
Bukkit.getScheduler().runTask(plugin, event.player::closeInventory);
|
||||
}).setOnClose(() -> {
|
||||
event.manager.showGUI(event.player, this);
|
||||
})
|
||||
this.inventory.addItem(parseStack);
|
||||
Bukkit.getScheduler().runTask(this.plugin, event.player::closeInventory);
|
||||
}).setOnClose(() -> {
|
||||
event.manager.showGUI(event.player, this);
|
||||
})
|
||||
.setOnCancel(() -> {
|
||||
event.player.sendMessage(ChatColor.RED + "Edit canceled");
|
||||
event.manager.showGUI(event.player, this);
|
||||
@ -274,11 +278,11 @@ public class KitEditorGui extends DoubleGui {
|
||||
});
|
||||
|
||||
setPlayerButton(5, GuiUtils.createButtonItem(XMaterial.SUNFLOWER,
|
||||
plugin.getLocale().getMessage("interface.kiteditor.addeconomy").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kiteditor.addeconomylore").getMessage().split("\\|")),
|
||||
this.plugin.getLocale().getMessage("interface.kiteditor.addeconomy").getMessage(),
|
||||
this.plugin.getLocale().getMessage("interface.kiteditor.addeconomylore").getMessage().split("\\|")),
|
||||
(event) -> {
|
||||
AnvilGui gui = new AnvilGui(player, this);
|
||||
gui.setTitle(plugin.getLocale().getMessage("interface.kiteditor.addeconomyprompt").getMessage());
|
||||
AnvilGui gui = new AnvilGui(this.player, this);
|
||||
gui.setTitle(this.plugin.getLocale().getMessage("interface.kiteditor.addeconomyprompt").getMessage());
|
||||
gui.setAction(aevent -> {
|
||||
String msg = gui.getInputText().trim();
|
||||
|
||||
@ -293,57 +297,57 @@ public class KitEditorGui extends DoubleGui {
|
||||
index += 30;
|
||||
}
|
||||
meta.setLore(lore);
|
||||
meta.setDisplayName(plugin.getLocale().getMessage("general.type.money").getMessage());
|
||||
meta.setDisplayName(this.plugin.getLocale().getMessage("general.type.money").getMessage());
|
||||
parseStack.setItemMeta(meta);
|
||||
|
||||
plugin.getLocale().getMessage("interface.kiteditor.addeconomyok").processPlaceholder("amount", msg.trim())
|
||||
.sendPrefixedMessage(player);
|
||||
this.plugin.getLocale().getMessage("interface.kiteditor.addeconomyok").processPlaceholder("amount", msg.trim())
|
||||
.sendPrefixedMessage(this.player);
|
||||
|
||||
this.inventory.addItem(parseStack);
|
||||
player.closeInventory();
|
||||
this.player.closeInventory();
|
||||
|
||||
});
|
||||
guiManager.showGUI(event.player, gui);
|
||||
this.guiManager.showGUI(event.player, gui);
|
||||
});
|
||||
|
||||
setPlayerButton(7, GuiUtils.createButtonItem(XMaterial.SHEEP_SPAWN_EGG,
|
||||
plugin.getLocale().getMessage("interface.kiteditor.clone").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kiteditor.clonelore")
|
||||
.getMessage().split("\\|")),
|
||||
this.plugin.getLocale().getMessage("interface.kiteditor.clone").getMessage(),
|
||||
this.plugin.getLocale().getMessage("interface.kiteditor.clonelore")
|
||||
.getMessage().split("\\|")),
|
||||
(event) -> {
|
||||
AnvilGui gui = new AnvilGui(player, this);
|
||||
AnvilGui gui = new AnvilGui(this.player, this);
|
||||
gui.setTitle("Enter a new kit name");
|
||||
gui.setAction(evnt -> {
|
||||
String kitStr = gui.getInputText().toLowerCase().trim();
|
||||
|
||||
if (plugin.getKitManager().getKit(kitStr) != null) {
|
||||
plugin.getLocale().getMessage("command.kit.kitalreadyexists").sendPrefixedMessage(player);
|
||||
player.closeInventory();
|
||||
if (this.plugin.getKitManager().getKit(kitStr) != null) {
|
||||
this.plugin.getLocale().getMessage("command.kit.kitalreadyexists").sendPrefixedMessage(this.player);
|
||||
this.player.closeInventory();
|
||||
} else {
|
||||
Kit newKit = kit.clone(kitStr);
|
||||
plugin.getKitManager().addKit(newKit);
|
||||
Kit newKit = this.kit.clone(kitStr);
|
||||
this.plugin.getKitManager().addKit(newKit);
|
||||
|
||||
restoreItemsInstance();
|
||||
saveKit(player, inventory, false);
|
||||
XSound.ENTITY_VILLAGER_YES.play(player);
|
||||
saveKit(this.player, this.inventory, false);
|
||||
XSound.ENTITY_VILLAGER_YES.play(this.player);
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () ->
|
||||
guiManager.showGUI(player, new KitEditorGui(plugin, player, newKit, null)), 5L);
|
||||
Bukkit.getScheduler().runTaskLater(this.plugin, () ->
|
||||
this.guiManager.showGUI(this.player, new KitEditorGui(this.plugin, this.player, newKit, null)), 5L);
|
||||
}
|
||||
});
|
||||
guiManager.showGUI(player, gui);
|
||||
this.guiManager.showGUI(this.player, gui);
|
||||
});
|
||||
|
||||
setPlayerButton(8, GuiUtils.createButtonItem(XMaterial.CHEST,
|
||||
plugin.getLocale().getMessage("interface.kiteditor.animation").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kiteditor.animationlore")
|
||||
.processPlaceholder("animation", kit.getKitAnimation().name())
|
||||
.getMessage().split("\\|")),
|
||||
this.plugin.getLocale().getMessage("interface.kiteditor.animation").getMessage(),
|
||||
this.plugin.getLocale().getMessage("interface.kiteditor.animationlore")
|
||||
.processPlaceholder("animation", this.kit.getKitAnimation().name())
|
||||
.getMessage().split("\\|")),
|
||||
(event) -> {
|
||||
if (kit.getKitAnimation() == KitAnimation.NONE) {
|
||||
kit.setKitAnimation(KitAnimation.ROULETTE);
|
||||
if (this.kit.getKitAnimation() == KitAnimation.NONE) {
|
||||
this.kit.setKitAnimation(KitAnimation.ROULETTE);
|
||||
} else {
|
||||
kit.setKitAnimation(KitAnimation.NONE);
|
||||
this.kit.setKitAnimation(KitAnimation.NONE);
|
||||
}
|
||||
setInvItems();
|
||||
});
|
||||
@ -361,11 +365,12 @@ public class KitEditorGui extends DoubleGui {
|
||||
|
||||
items = Arrays.copyOf(items, items.length - 10);
|
||||
|
||||
kit.saveKit(Arrays.asList(items));
|
||||
if (!muteSave)
|
||||
plugin.getLocale().getMessage("interface.kiteditor.saved")
|
||||
.processPlaceholder("kit", kit.getName())
|
||||
this.kit.saveKit(Arrays.asList(items));
|
||||
if (!muteSave) {
|
||||
this.plugin.getLocale().getMessage("interface.kiteditor.saved")
|
||||
.processPlaceholder("kit", this.kit.getName())
|
||||
.sendPrefixedMessage(player);
|
||||
}
|
||||
}
|
||||
|
||||
public void replaceItem(Action action, Player player, ItemStack itemStack, int slot) {
|
||||
@ -373,8 +378,12 @@ public class KitEditorGui extends DoubleGui {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
List<String> newLore = new ArrayList<>();
|
||||
for (String line : meta.getLore()) {
|
||||
if (line.contains("Moveable")) continue;
|
||||
if (line.equals(TextUtils.formatText("&8----"))) break;
|
||||
if (line.contains("Moveable")) {
|
||||
continue;
|
||||
}
|
||||
if (line.equals(TextUtils.formatText("&8----"))) {
|
||||
break;
|
||||
}
|
||||
newLore.add(line);
|
||||
}
|
||||
meta.setLore(newLore);
|
||||
@ -386,13 +395,14 @@ public class KitEditorGui extends DoubleGui {
|
||||
switch (action) {
|
||||
case CHANCE_UP:
|
||||
case CHANCE_DOWN:
|
||||
if (action == Action.CHANCE_UP)
|
||||
if (action == Action.CHANCE_UP) {
|
||||
item.setChance(item.getChance() >= 100 ? 5 : (item.getChance() + 5));
|
||||
else
|
||||
} else {
|
||||
item.setChance(item.getChance() <= 0 ? 100 : (item.getChance() - 5));
|
||||
}
|
||||
|
||||
setItem(slot, getCompiledMeta(item));
|
||||
saveKit(player, inventory, true);
|
||||
saveKit(player, this.inventory, true);
|
||||
paint();
|
||||
break;
|
||||
case DISPLAY_ITEM: {
|
||||
@ -408,11 +418,11 @@ public class KitEditorGui extends DoubleGui {
|
||||
newItem.setDisplayItem(material);
|
||||
setItem(slot, newItem.getMoveableItem());
|
||||
player.closeInventory();
|
||||
saveKit(player, inventory, true);
|
||||
saveKit(player, this.inventory, true);
|
||||
paint();
|
||||
}
|
||||
});
|
||||
guiManager.showGUI(player, gui);
|
||||
this.guiManager.showGUI(player, gui);
|
||||
}
|
||||
break;
|
||||
case DISPLAY_NAME: {
|
||||
@ -423,10 +433,10 @@ public class KitEditorGui extends DoubleGui {
|
||||
newItem.setDisplayName(gui.getInputText());
|
||||
setItem(slot, getCompiledMeta(newItem));
|
||||
player.closeInventory();
|
||||
saveKit(player, inventory, true);
|
||||
saveKit(player, this.inventory, true);
|
||||
paint();
|
||||
});
|
||||
guiManager.showGUI(player, gui);
|
||||
this.guiManager.showGUI(player, gui);
|
||||
}
|
||||
break;
|
||||
case DISPLAY_LORE: {
|
||||
@ -437,10 +447,10 @@ public class KitEditorGui extends DoubleGui {
|
||||
newItem.setDisplayLore(gui.getInputText());
|
||||
setItem(slot, getCompiledMeta(newItem));
|
||||
player.closeInventory();
|
||||
saveKit(player, inventory, true);
|
||||
saveKit(player, this.inventory, true);
|
||||
paint();
|
||||
});
|
||||
guiManager.showGUI(player, gui);
|
||||
this.guiManager.showGUI(player, gui);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -453,18 +463,24 @@ public class KitEditorGui extends DoubleGui {
|
||||
ItemStack is = item.getMoveableItem();
|
||||
ItemMeta meta;
|
||||
|
||||
if (is.hasItemMeta()) meta = is.getItemMeta();
|
||||
else meta = Bukkit.getItemFactory().getItemMeta(is.getType());
|
||||
if (is.hasItemMeta()) {
|
||||
meta = is.getItemMeta();
|
||||
} else {
|
||||
meta = Bukkit.getItemFactory().getItemMeta(is.getType());
|
||||
}
|
||||
|
||||
List<String> itemLore;
|
||||
|
||||
if (meta.hasLore()) itemLore = meta.getLore();
|
||||
else itemLore = new ArrayList<>();
|
||||
if (meta.hasLore()) {
|
||||
itemLore = meta.getLore();
|
||||
} else {
|
||||
itemLore = new ArrayList<>();
|
||||
}
|
||||
itemLore.add(TextUtils.formatText("&8----"));
|
||||
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) {
|
||||
itemLore.addAll(Arrays.asList(plugin.getLocale().getMessage("interface.kiteditor.itemfunctionlore")
|
||||
itemLore.add(ChatColor.GRAY + this.plugin.getLocale().getMessage("general.type.chance").getMessage().replaceFirst("^" + ChatColor.RESET, "")
|
||||
+ ": " + ChatColor.GOLD + item.getChance() + "%"); //TODO use a placeholder message in locales
|
||||
if (this.isInFunction) {
|
||||
itemLore.addAll(Arrays.asList(this.plugin.getLocale().getMessage("interface.kiteditor.itemfunctionlore")
|
||||
.processPlaceholder("item", item.getDisplayItem() == null ? "" : item.getDisplayItem().name())
|
||||
.processPlaceholder("name", item.getDisplayName())
|
||||
.processPlaceholder("lore", item.getDisplayLore())
|
||||
|
@ -14,7 +14,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
public class KitGeneralOptionsGui extends Gui {
|
||||
|
||||
public KitGeneralOptionsGui(UltimateKits plugin, Player player, Kit kit, Gui back) {
|
||||
super(3);
|
||||
setTitle(plugin.getLocale().getMessage("interface.kitoptions.title")
|
||||
@ -26,21 +25,21 @@ public class KitGeneralOptionsGui extends Gui {
|
||||
|
||||
// exit button
|
||||
setButton(0, 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(XMaterial.OAK_DOOR),
|
||||
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
|
||||
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
|
||||
ClickType.LEFT,
|
||||
event -> exit());
|
||||
|
||||
// back button
|
||||
setButton(0, 0, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
|
||||
plugin.getLocale().getMessage("interface.button.back").getMessage()),
|
||||
plugin.getLocale().getMessage("interface.button.back").getMessage()),
|
||||
ClickType.LEFT,
|
||||
event -> guiManager.showGUI(player, new KitEditorGui(plugin, player, kit, back)));
|
||||
event -> this.guiManager.showGUI(player, new KitEditorGui(plugin, player, kit, back)));
|
||||
|
||||
// edit delay
|
||||
setButton(1, 2, GuiUtils.createButtonItem(XMaterial.CLOCK,
|
||||
plugin.getLocale().getMessage("interface.kitoptions.delay").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kitoptions.delaylore")
|
||||
.processPlaceholder("delay", kit.getDelay()).getMessage().split("\\|")),
|
||||
plugin.getLocale().getMessage("interface.kitoptions.delay").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kitoptions.delaylore")
|
||||
.processPlaceholder("delay", kit.getDelay()).getMessage().split("\\|")),
|
||||
event -> {
|
||||
AnvilGui gui = new AnvilGui(event.player, this);
|
||||
gui.setTitle(plugin.getLocale().getMessage("interface.kitoptions.delayprompt").getMessage());
|
||||
@ -57,14 +56,14 @@ public class KitGeneralOptionsGui extends Gui {
|
||||
plugin.getLocale().getMessage("interface.kitoptions.delaynonumber").processPlaceholder("input", msg).sendPrefixedMessage(player);
|
||||
plugin.saveKits(false);
|
||||
});
|
||||
guiManager.showGUI(event.player, gui);
|
||||
this.guiManager.showGUI(event.player, gui);
|
||||
});
|
||||
|
||||
// edit category
|
||||
setButton(1, 4, GuiUtils.createButtonItem(XMaterial.BOOK,
|
||||
plugin.getLocale().getMessage("interface.kitoptions.category").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kitoptions.categorylore")
|
||||
.processPlaceholder("category", kit.getCategory() == null ? "none" : kit.getCategory().getName()).getMessage().split("\\|")),
|
||||
plugin.getLocale().getMessage("interface.kitoptions.category").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kitoptions.categorylore")
|
||||
.processPlaceholder("category", kit.getCategory() == null ? "none" : kit.getCategory().getName()).getMessage().split("\\|")),
|
||||
event -> {
|
||||
if (event.clickType == ClickType.LEFT) {
|
||||
AnvilGui gui = new AnvilGui(event.player, this);
|
||||
@ -82,7 +81,7 @@ public class KitGeneralOptionsGui extends Gui {
|
||||
plugin.getLocale().getMessage("interface.kitoptions.notacategory").processPlaceholder("input", msg).sendPrefixedMessage(player);
|
||||
plugin.saveKits(false);
|
||||
});
|
||||
guiManager.showGUI(event.player, gui);
|
||||
this.guiManager.showGUI(event.player, gui);
|
||||
} else if (event.clickType == ClickType.RIGHT) {
|
||||
kit.setCategory(null);
|
||||
updateItemLore(event.slot, plugin.getLocale().getMessage("interface.kitoptions.categorylore")
|
||||
@ -92,8 +91,8 @@ public class KitGeneralOptionsGui extends Gui {
|
||||
|
||||
// delete
|
||||
setButton(1, 6, GuiUtils.createButtonItem(XMaterial.TNT,
|
||||
plugin.getLocale().getMessage("interface.kitoptions.destroy").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kitoptions.destroylore").getMessage().split("\\|")),
|
||||
plugin.getLocale().getMessage("interface.kitoptions.destroy").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kitoptions.destroylore").getMessage().split("\\|")),
|
||||
event -> {
|
||||
AnvilGui gui = new AnvilGui(event.player);
|
||||
gui.setTitle(plugin.getLocale().getMessage("interface.kitoptions.destroyprompt").processPlaceholder("kit", kit.getKey()).getMessage());
|
||||
@ -109,9 +108,7 @@ public class KitGeneralOptionsGui extends Gui {
|
||||
aevent.player.closeInventory();
|
||||
plugin.saveKits(false);
|
||||
});
|
||||
guiManager.showGUI(event.player, gui);
|
||||
this.guiManager.showGUI(event.player, gui);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class KitGuiOptionsGui extends Gui {
|
||||
|
||||
private final UltimateKits plugin;
|
||||
private final Kit kit;
|
||||
private final Player player;
|
||||
@ -35,90 +34,90 @@ public class KitGuiOptionsGui extends Gui {
|
||||
|
||||
// exit button
|
||||
setButton(0, 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(XMaterial.OAK_DOOR),
|
||||
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
|
||||
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
|
||||
ClickType.LEFT,
|
||||
event -> exit());
|
||||
|
||||
// back button
|
||||
setButton(0, 0, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
|
||||
plugin.getLocale().getMessage("interface.button.back").getMessage()),
|
||||
plugin.getLocale().getMessage("interface.button.back").getMessage()),
|
||||
ClickType.LEFT,
|
||||
event -> guiManager.showGUI(player, new KitEditorGui(plugin, player, kit, back)));
|
||||
event -> this.guiManager.showGUI(player, new KitEditorGui(plugin, player, kit, back)));
|
||||
paint();
|
||||
}
|
||||
|
||||
private void paint() {
|
||||
// set hologram title
|
||||
setButton(1, 2, GuiUtils.createButtonItem(XMaterial.NAME_TAG,
|
||||
plugin.getLocale().getMessage("interface.kitguioptions.holo").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kitguioptions.hololore")
|
||||
.processPlaceholder("onoff",
|
||||
kit.getTitle() != null ? plugin.getLocale().getMessage("interface.kitguioptions.holoon").processPlaceholder("title", kit.getTitle()).getMessage()
|
||||
: plugin.getLocale().getMessage("interface.kitguioptions.holooff").getMessage()
|
||||
).getMessage().split("\\|")),
|
||||
this.plugin.getLocale().getMessage("interface.kitguioptions.holo").getMessage(),
|
||||
this.plugin.getLocale().getMessage("interface.kitguioptions.hololore")
|
||||
.processPlaceholder("onoff",
|
||||
this.kit.getTitle() != null ? this.plugin.getLocale().getMessage("interface.kitguioptions.holoon").processPlaceholder("title", this.kit.getTitle()).getMessage()
|
||||
: this.plugin.getLocale().getMessage("interface.kitguioptions.holooff").getMessage()
|
||||
).getMessage().split("\\|")),
|
||||
ClickType.LEFT,
|
||||
event -> {
|
||||
AnvilGui gui = new AnvilGui(event.player, this);
|
||||
gui.setTitle(plugin.getLocale().getMessage("interface.kitguioptions.holoprompt").getMessage());
|
||||
gui.setTitle(this.plugin.getLocale().getMessage("interface.kitguioptions.holoprompt").getMessage());
|
||||
gui.setAction(evnt -> {
|
||||
final String msg = gui.getInputText().trim();
|
||||
kit.setTitle(msg);
|
||||
plugin.getLocale().getMessage("interface.kitguioptions.holoset")
|
||||
this.kit.setTitle(msg);
|
||||
this.plugin.getLocale().getMessage("interface.kitguioptions.holoset")
|
||||
.processPlaceholder("title", msg)
|
||||
.processPlaceholder("kit", kit.getName())
|
||||
.sendPrefixedMessage(player);
|
||||
.processPlaceholder("kit", this.kit.getName())
|
||||
.sendPrefixedMessage(this.player);
|
||||
|
||||
plugin.updateHologram(kit);
|
||||
this.plugin.updateHologram(this.kit);
|
||||
evnt.player.closeInventory();
|
||||
paint();
|
||||
plugin.saveKits(false);
|
||||
this.plugin.saveKits(false);
|
||||
});
|
||||
guiManager.showGUI(event.player, gui);
|
||||
this.guiManager.showGUI(event.player, gui);
|
||||
});
|
||||
setAction(1, 2, ClickType.RIGHT, event -> {
|
||||
kit.setTitle(null);
|
||||
plugin.updateHologram(kit);
|
||||
this.kit.setTitle(null);
|
||||
this.plugin.updateHologram(this.kit);
|
||||
paint();
|
||||
plugin.saveKits(false);
|
||||
this.plugin.saveKits(false);
|
||||
});
|
||||
|
||||
setButton(1, 4, GuiUtils.createButtonItem(kit.getDisplayItem() != null ? kit.getDisplayItem() : XMaterial.BEACON.parseItem(),
|
||||
plugin.getLocale().getMessage("interface.kitguioptions.item").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kitguioptions.itemlore")
|
||||
.processPlaceholder("onoff",
|
||||
kit.getDisplayItem() != null ? plugin.getLocale().getMessage("interface.kitguioptions.itemon")
|
||||
.processPlaceholder("item", kit.getDisplayItem().toString()).getMessage()
|
||||
: plugin.getLocale().getMessage("interface.kitguioptions.itemoff").getMessage()
|
||||
).getMessage().split("\\|")),
|
||||
setButton(1, 4, GuiUtils.createButtonItem(this.kit.getDisplayItem() != null ? this.kit.getDisplayItem() : XMaterial.BEACON.parseItem(),
|
||||
this.plugin.getLocale().getMessage("interface.kitguioptions.item").getMessage(),
|
||||
this.plugin.getLocale().getMessage("interface.kitguioptions.itemlore")
|
||||
.processPlaceholder("onoff",
|
||||
this.kit.getDisplayItem() != null ? this.plugin.getLocale().getMessage("interface.kitguioptions.itemon")
|
||||
.processPlaceholder("item", this.kit.getDisplayItem().toString()).getMessage()
|
||||
: this.plugin.getLocale().getMessage("interface.kitguioptions.itemoff").getMessage()
|
||||
).getMessage().split("\\|")),
|
||||
ClickType.LEFT,
|
||||
event -> {
|
||||
ItemStack is = player.getItemInHand();
|
||||
ItemStack is = this.player.getItemInHand();
|
||||
if (is.getType() == Material.AIR) {
|
||||
plugin.getLocale().getMessage("interface.kitguioptions.itemnoitem").sendPrefixedMessage(player);
|
||||
this.plugin.getLocale().getMessage("interface.kitguioptions.itemnoitem").sendPrefixedMessage(this.player);
|
||||
} else {
|
||||
kit.setDisplayItem(is);
|
||||
plugin.getLocale().getMessage("interface.kitguioptions.itemset").processPlaceholder("item", kit.getName()).sendPrefixedMessage(player);
|
||||
this.kit.setDisplayItem(is);
|
||||
this.plugin.getLocale().getMessage("interface.kitguioptions.itemset").processPlaceholder("item", this.kit.getName()).sendPrefixedMessage(this.player);
|
||||
paint();
|
||||
}
|
||||
plugin.saveKits(false);
|
||||
this.plugin.saveKits(false);
|
||||
});
|
||||
setAction(1, 4, ClickType.RIGHT, event -> {
|
||||
kit.setDisplayItem(null);
|
||||
plugin.getLocale().getMessage("interface.kitguioptions.itemremoved").processPlaceholder("kit", kit.getName()).sendPrefixedMessage(player);
|
||||
this.kit.setDisplayItem(null);
|
||||
this.plugin.getLocale().getMessage("interface.kitguioptions.itemremoved").processPlaceholder("kit", this.kit.getName()).sendPrefixedMessage(this.player);
|
||||
paint();
|
||||
});
|
||||
|
||||
setButton(1, 6, GuiUtils.createButtonItem(XMaterial.COAL,
|
||||
plugin.getLocale().getMessage("interface.kitguioptions.hide").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kitguioptions.hidelore")
|
||||
.processPlaceholder("onoff", plugin.getLocale().getMessage(
|
||||
kit.isHidden() ? "interface.kitguioptions.hideon" : "interface.kitguioptions.hideoff").getMessage()
|
||||
).getMessage().split("\\|")),
|
||||
this.plugin.getLocale().getMessage("interface.kitguioptions.hide").getMessage(),
|
||||
this.plugin.getLocale().getMessage("interface.kitguioptions.hidelore")
|
||||
.processPlaceholder("onoff", this.plugin.getLocale().getMessage(
|
||||
this.kit.isHidden() ? "interface.kitguioptions.hideon" : "interface.kitguioptions.hideoff").getMessage()
|
||||
).getMessage().split("\\|")),
|
||||
ClickType.LEFT,
|
||||
event -> {
|
||||
kit.setHidden(!kit.isHidden());
|
||||
this.kit.setHidden(!this.kit.isHidden());
|
||||
paint();
|
||||
plugin.saveKits(false);
|
||||
this.plugin.saveKits(false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -6,11 +6,11 @@ import com.craftaro.core.gui.GuiUtils;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.utils.ItemUtils;
|
||||
import com.craftaro.core.utils.TextUtils;
|
||||
import com.craftaro.core.utils.TimeUtils;
|
||||
import com.craftaro.ultimatekits.UltimateKits;
|
||||
import com.craftaro.ultimatekits.kit.Kit;
|
||||
import com.craftaro.ultimatekits.category.Category;
|
||||
import com.craftaro.ultimatekits.kit.Kit;
|
||||
import com.craftaro.ultimatekits.settings.Settings;
|
||||
import com.craftaro.ultimatekits.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -25,7 +25,6 @@ import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class KitSelectorGui extends Gui {
|
||||
|
||||
private final Player player;
|
||||
private final UltimateKits plugin;
|
||||
|
||||
@ -41,32 +40,32 @@ public class KitSelectorGui extends Gui {
|
||||
this.player = player;
|
||||
this.plugin = plugin;
|
||||
this.category = category;
|
||||
glassless = Settings.DO_NOT_USE_GLASS_BORDERS.getBoolean();
|
||||
this.glassless = Settings.DO_NOT_USE_GLASS_BORDERS.getBoolean();
|
||||
|
||||
setTitle(plugin.getLocale().getMessage("interface.selector.title").getMessage());
|
||||
loadKits();
|
||||
int showPerRow = glassless ? 9 : 7;
|
||||
int nrows = (int) Math.ceil(kitList.size() / (double) showPerRow);
|
||||
setRows(glassless ? nrows : nrows + 2);
|
||||
showPerPage = showPerRow * (glassless ? (nrows == 6 ? 6 : 5) : 4);
|
||||
setPages(kitList.size() / showPerPage);
|
||||
int showPerRow = this.glassless ? 9 : 7;
|
||||
int nrows = (int) Math.ceil(this.kitList.size() / (double) showPerRow);
|
||||
setRows(this.glassless ? nrows : nrows + 2);
|
||||
this.showPerPage = showPerRow * (this.glassless ? (nrows == 6 ? 6 : 5) : 4);
|
||||
setPages(this.kitList.size() / this.showPerPage);
|
||||
|
||||
setItem(0, 4, GuiUtils.createButtonItem(XMaterial.BOOK,
|
||||
plugin.getLocale().getMessage("interface.selector.details")
|
||||
.processPlaceholder("player", player.getName()).getMessage().split("\\|")));
|
||||
|
||||
if (pages > 1) {
|
||||
this.setNextPage(rows - 1, 5, GuiUtils.createButtonItem(ItemUtils.getCustomHead("1b6f1a25b6bc199946472aedb370522584ff6f4e83221e5946bd2e41b5ca13b"),
|
||||
if (this.pages > 1) {
|
||||
this.setNextPage(this.rows - 1, 5, GuiUtils.createButtonItem(ItemUtils.getCustomHead("1b6f1a25b6bc199946472aedb370522584ff6f4e83221e5946bd2e41b5ca13b"),
|
||||
plugin.getLocale().getMessage("interface.button.next").getMessage()));
|
||||
|
||||
this.setPrevPage(rows - 1, 3, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
|
||||
this.setPrevPage(this.rows - 1, 3, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
|
||||
plugin.getLocale().getMessage("interface.button.last").getMessage()));
|
||||
|
||||
this.setOnPage(pager -> showPage());
|
||||
}
|
||||
|
||||
if (!glassless) {
|
||||
setButton(rows - 1, 4, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(XMaterial.OAK_DOOR),
|
||||
if (!this.glassless) {
|
||||
setButton(this.rows - 1, 4, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(XMaterial.OAK_DOOR),
|
||||
UltimateKits.getInstance().getLocale().getMessage("interface.button.exit").getMessage()),
|
||||
event -> exit());
|
||||
}
|
||||
@ -75,14 +74,16 @@ public class KitSelectorGui extends Gui {
|
||||
setDefaultItem(AIR);
|
||||
mirrorFill(0, 0, true, true, glass2);
|
||||
|
||||
if (!glassless) {
|
||||
if (!this.glassless) {
|
||||
if (Settings.RAINBOW.getBoolean()) {
|
||||
animateGlass();
|
||||
timer = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
|
||||
if (inventory.getViewers().isEmpty()) return;
|
||||
this.timer = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
|
||||
if (this.inventory.getViewers().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
animateGlass();
|
||||
}, 20L, 20L);
|
||||
setOnClose(event -> Bukkit.getScheduler().cancelTask(timer));
|
||||
setOnClose(event -> Bukkit.getScheduler().cancelTask(this.timer));
|
||||
} else {
|
||||
ItemStack glass1 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_1.getMaterial());
|
||||
ItemStack glass3 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_3.getMaterial());
|
||||
@ -94,19 +95,20 @@ public class KitSelectorGui extends Gui {
|
||||
}
|
||||
}
|
||||
|
||||
if (category != null)
|
||||
if (category != null) {
|
||||
setButton(0, 0, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
|
||||
plugin.getLocale().getMessage("interface.button.back").getMessage()),
|
||||
event -> guiManager.showGUI(player, new CategorySelectorGui(plugin, player)));
|
||||
event -> this.guiManager.showGUI(player, new CategorySelectorGui(plugin, player)));
|
||||
}
|
||||
|
||||
|
||||
showPage();
|
||||
}
|
||||
|
||||
private void loadKits() {
|
||||
kitList = plugin.getKitManager().getKits().stream()
|
||||
.filter(kit -> !kit.isHidden() && kit.hasPermissionToPreview(player)
|
||||
&& (category == null || kit.getCategory() == category))
|
||||
this.kitList = this.plugin.getKitManager().getKits().stream()
|
||||
.filter(kit -> !kit.isHidden() && kit.hasPermissionToPreview(this.player)
|
||||
&& (this.category == null || kit.getCategory() == this.category))
|
||||
.map(Kit::getKey)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
@ -116,52 +118,54 @@ public class KitSelectorGui extends Gui {
|
||||
private void animateGlass() {
|
||||
for (int col = 1; col < 8; ++col) {
|
||||
ItemStack it;
|
||||
if ((it = getItem(0, col)) == null || it.getType() == Material.AIR || it.getType().name().contains("PANE"))
|
||||
if ((it = getItem(0, col)) == null || it.getType() == Material.AIR || it.getType().name().contains("PANE")) {
|
||||
setItem(0, col, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneForColor(rand.nextInt(16))));
|
||||
if ((it = getItem(rows - 1, col)) == null || it.getType() == Material.AIR || it.getType().name().contains("PANE"))
|
||||
setItem(rows - 1, col, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneForColor(rand.nextInt(16))));
|
||||
}
|
||||
if ((it = getItem(this.rows - 1, col)) == null || it.getType() == Material.AIR || it.getType().name().contains("PANE")) {
|
||||
setItem(this.rows - 1, col, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneForColor(rand.nextInt(16))));
|
||||
}
|
||||
}
|
||||
for (int row = 1; row + 1 < rows; ++row) {
|
||||
for (int row = 1; row + 1 < this.rows; ++row) {
|
||||
setItem(row, 0, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneForColor(rand.nextInt(16))));
|
||||
setItem(row, 8, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneForColor(rand.nextInt(16))));
|
||||
}
|
||||
}
|
||||
|
||||
private void showPage() {
|
||||
int index = (page - 1) * showPerPage;
|
||||
for (int row = glassless ? 0 : 1; row < (!glassless || pages != 1 ? rows - 1 : rows); ++row) {
|
||||
for (int col = glassless ? 0 : 1; col < (glassless ? 9 : 8); ++col) {
|
||||
if (index >= kitList.size()) {
|
||||
int index = (this.page - 1) * this.showPerPage;
|
||||
for (int row = this.glassless ? 0 : 1; row < (!this.glassless || this.pages != 1 ? this.rows - 1 : this.rows); ++row) {
|
||||
for (int col = this.glassless ? 0 : 1; col < (this.glassless ? 9 : 8); ++col) {
|
||||
if (index >= this.kitList.size()) {
|
||||
setItem(row, col, null);
|
||||
clearActions(row, col);
|
||||
continue;
|
||||
}
|
||||
final String kitItem = kitList.get(index++);
|
||||
final Kit kit = plugin.getKitManager().getKit(kitItem);
|
||||
final String kitItem = this.kitList.get(index++);
|
||||
final Kit kit = this.plugin.getKitManager().getKit(kitItem);
|
||||
|
||||
String kitTitle = kit.getTitle() != null
|
||||
? ChatColor.translateAlternateColorCodes('&', kit.getTitle())
|
||||
: plugin.getLocale().getMessage("interface.selector.kit")
|
||||
: this.plugin.getLocale().getMessage("interface.selector.kit")
|
||||
.processPlaceholder("kit", TextUtils.formatText(kitItem, true)).getMessage();
|
||||
|
||||
setButton(row, col, GuiUtils.createButtonItem(
|
||||
kit.getDisplayItem() != null ? kit.getDisplayItem() : XMaterial.ENCHANTED_BOOK.parseItem(), kitTitle,
|
||||
getKitLore(kit)),
|
||||
event -> {
|
||||
if (event.clickType == ClickType.MIDDLE && player.hasPermission("ultimatekits.admin")) {
|
||||
kitsmode = !kitsmode;
|
||||
if (event.clickType == ClickType.MIDDLE && this.player.hasPermission("ultimatekits.admin")) {
|
||||
this.kitsmode = !this.kitsmode;
|
||||
showPage();
|
||||
} else if (kitsmode) {
|
||||
} else if (this.kitsmode) {
|
||||
if (event.clickType == ClickType.RIGHT) {
|
||||
plugin.getKitManager().moveKit(kit, true);
|
||||
this.plugin.getKitManager().moveKit(kit, true);
|
||||
} else if (event.clickType == ClickType.LEFT) {
|
||||
plugin.getKitManager().moveKit(kit, false);
|
||||
this.plugin.getKitManager().moveKit(kit, false);
|
||||
}
|
||||
loadKits();
|
||||
plugin.saveKits(false);
|
||||
this.plugin.saveKits(false);
|
||||
showPage();
|
||||
} else if (event.clickType == ClickType.LEFT) {
|
||||
kit.display(player, guiManager, this);
|
||||
kit.display(this.player, this.guiManager, this);
|
||||
} else if (event.clickType == ClickType.RIGHT) {
|
||||
kit.buy(event.player, event.manager);
|
||||
}
|
||||
@ -172,50 +176,52 @@ public class KitSelectorGui extends Gui {
|
||||
|
||||
private List<String> getKitLore(Kit kit) {
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
if (kit.getPrice() != 0)
|
||||
lore.add(plugin.getLocale().getMessage("interface.selector.aboutkitprice")
|
||||
if (kit.getPrice() != 0) {
|
||||
lore.add(this.plugin.getLocale().getMessage("interface.selector.aboutkitprice")
|
||||
.processPlaceholder("price", String.valueOf(kit.getPrice()))
|
||||
.getMessage());
|
||||
else if (kit.getLink() != null)
|
||||
lore.add(plugin.getLocale().getMessage("general.type.link").getMessage());
|
||||
} else if (kit.getLink() != null) {
|
||||
lore.add(this.plugin.getLocale().getMessage("general.type.link").getMessage());
|
||||
}
|
||||
|
||||
if (!kitsmode) {
|
||||
if (!plugin.getLocale().getMessage("interface.selector.aboutkit").getMessage().trim().equals("")) {
|
||||
String[] parts = plugin.getLocale().getMessage("interface.selector.aboutkit").getMessage().split("\\|");
|
||||
if (!this.kitsmode) {
|
||||
if (!this.plugin.getLocale().getMessage("interface.selector.aboutkit").getMessage().trim().equals("")) {
|
||||
String[] parts = this.plugin.getLocale().getMessage("interface.selector.aboutkit").getMessage().split("\\|");
|
||||
lore.add("");
|
||||
for (String line : parts)
|
||||
for (String line : parts) {
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', line));
|
||||
}
|
||||
}
|
||||
if (kit.hasPermissionToClaim(player)) {
|
||||
if (kit.getNextUse(player) == -1) {
|
||||
lore.add(plugin.getLocale().getMessage("event.claim.once").getMessage());
|
||||
} else if (kit.getNextUse(player) > 0) {
|
||||
if (!plugin.getLocale().getMessage("event.claim.wait").getMessage().trim().equals("")) {
|
||||
lore.add(plugin.getLocale().getMessage("event.claim.wait")
|
||||
.processPlaceholder("time", Methods.makeReadable(kit.getNextUse(player)))
|
||||
if (kit.hasPermissionToClaim(this.player)) {
|
||||
if (kit.getNextUse(this.player) == -1) {
|
||||
lore.add(this.plugin.getLocale().getMessage("event.claim.once").getMessage());
|
||||
} else if (kit.getNextUse(this.player) > 0) {
|
||||
if (!this.plugin.getLocale().getMessage("event.claim.wait").getMessage().trim().equals("")) {
|
||||
lore.add(this.plugin.getLocale().getMessage("event.claim.wait")
|
||||
.processPlaceholder("time", TimeUtils.makeReadable(kit.getNextUse(this.player)))
|
||||
.getMessage());
|
||||
}
|
||||
} else if (!plugin.getLocale().getMessage("event.claim.ready").getMessage().trim().equals("")) {
|
||||
lore.add(plugin.getLocale().getMessage("event.claim.ready").getMessage());
|
||||
} else if (!this.plugin.getLocale().getMessage("event.claim.ready").getMessage().trim().equals("")) {
|
||||
lore.add(this.plugin.getLocale().getMessage("event.claim.ready").getMessage());
|
||||
}
|
||||
} else
|
||||
lore.add(plugin.getLocale().getMessage("event.claim.noaccess").getMessage());
|
||||
} else {
|
||||
lore.add(this.plugin.getLocale().getMessage("event.claim.noaccess").getMessage());
|
||||
}
|
||||
lore.add("");
|
||||
lore.add(plugin.getLocale().getMessage("interface.selector.leftpreview").getMessage());
|
||||
if (kit.hasPermissionToClaim(player)) {
|
||||
lore.add(plugin.getLocale().getMessage("interface.selector.rightclaim").getMessage());
|
||||
lore.add(this.plugin.getLocale().getMessage("interface.selector.leftpreview").getMessage());
|
||||
if (kit.hasPermissionToClaim(this.player)) {
|
||||
lore.add(this.plugin.getLocale().getMessage("interface.selector.rightclaim").getMessage());
|
||||
} else if (kit.getPrice() != 0 || kit.getLink() != null) {
|
||||
lore.add(plugin.getLocale().getMessage("interface.selector.rightbuy").getMessage());
|
||||
lore.add(this.plugin.getLocale().getMessage("interface.selector.rightbuy").getMessage());
|
||||
}
|
||||
|
||||
if (player.hasPermission("ultimatekits.admin")) {
|
||||
if (this.player.hasPermission("ultimatekits.admin")) {
|
||||
lore.add("");
|
||||
lore.add(plugin.getLocale().getMessage("interface.selector.adminlore").getMessage());
|
||||
lore.add(this.plugin.getLocale().getMessage("interface.selector.adminlore").getMessage());
|
||||
}
|
||||
} else {
|
||||
lore.addAll(Arrays.asList(plugin.getLocale().getMessage("interface.selector.editlore").getMessage().split("\\|")));
|
||||
lore.addAll(Arrays.asList(this.plugin.getLocale().getMessage("interface.selector.editlore").getMessage().split("\\|")));
|
||||
}
|
||||
return lore;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
public class KitSellingOptionsGui extends Gui {
|
||||
|
||||
private final UltimateKits plugin;
|
||||
private final Player player;
|
||||
private final Kit kit;
|
||||
@ -33,74 +32,74 @@ public class KitSellingOptionsGui extends Gui {
|
||||
|
||||
// exit button
|
||||
setButton(0, 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(XMaterial.OAK_DOOR),
|
||||
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
|
||||
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
|
||||
ClickType.LEFT,
|
||||
event -> exit());
|
||||
|
||||
// back button
|
||||
setButton(0, 0, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
|
||||
plugin.getLocale().getMessage("interface.button.back").getMessage()),
|
||||
plugin.getLocale().getMessage("interface.button.back").getMessage()),
|
||||
ClickType.LEFT,
|
||||
event -> guiManager.showGUI(player, new KitEditorGui(plugin, player, kit, back)));
|
||||
event -> this.guiManager.showGUI(player, new KitEditorGui(plugin, player, kit, back)));
|
||||
paint();
|
||||
}
|
||||
|
||||
private void paint() {
|
||||
// remove sale
|
||||
setButton(1, 2, GuiUtils.createButtonItem(XMaterial.BARRIER,
|
||||
plugin.getLocale().getMessage("interface.kitsell.nosell").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kitsell.noselllore")
|
||||
.processPlaceholder("onoff", plugin.getLocale().getMessage(
|
||||
kit.getPrice() != 0 || kit.getLink() != null ? "interface.kitsell.nosellon" : "interface.kitsell.noselloff").getMessage()
|
||||
).getMessage().split("\\|")),
|
||||
this.plugin.getLocale().getMessage("interface.kitsell.nosell").getMessage(),
|
||||
this.plugin.getLocale().getMessage("interface.kitsell.noselllore")
|
||||
.processPlaceholder("onoff", this.plugin.getLocale().getMessage(
|
||||
this.kit.getPrice() != 0 || this.kit.getLink() != null ? "interface.kitsell.nosellon" : "interface.kitsell.noselloff").getMessage()
|
||||
).getMessage().split("\\|")),
|
||||
event -> {
|
||||
kit.setPrice(0);
|
||||
kit.setLink(null);
|
||||
this.kit.setPrice(0);
|
||||
this.kit.setLink(null);
|
||||
paint();
|
||||
});
|
||||
|
||||
// kit link
|
||||
setButton(1, 4, GuiUtils.createButtonItem(XMaterial.PAPER,
|
||||
plugin.getLocale().getMessage("interface.kitsell.link").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kitsell.linklore")
|
||||
.processPlaceholder("onoff",
|
||||
kit.getLink() != null ? plugin.getLocale().getMessage("interface.kitsell.linkon").processPlaceholder("kit", kit.getLink()).getMessage()
|
||||
: plugin.getLocale().getMessage("interface.kitsell.linkoff").getMessage()
|
||||
).getMessage().split("\\|")),
|
||||
this.plugin.getLocale().getMessage("interface.kitsell.link").getMessage(),
|
||||
this.plugin.getLocale().getMessage("interface.kitsell.linklore")
|
||||
.processPlaceholder("onoff",
|
||||
this.kit.getLink() != null ? this.plugin.getLocale().getMessage("interface.kitsell.linkon").processPlaceholder("kit", this.kit.getLink()).getMessage()
|
||||
: this.plugin.getLocale().getMessage("interface.kitsell.linkoff").getMessage()
|
||||
).getMessage().split("\\|")),
|
||||
event -> {
|
||||
AnvilGui gui = new AnvilGui(event.player, this);
|
||||
gui.setTitle(plugin.getLocale().getMessage("interface.kitsell.linkprompt").getMessage());
|
||||
gui.setTitle(this.plugin.getLocale().getMessage("interface.kitsell.linkprompt").getMessage());
|
||||
gui.setAction(aevent -> {
|
||||
final String msg = gui.getInputText().trim();
|
||||
if (kit.getPrice() != 0) {
|
||||
kit.setPrice(0);
|
||||
plugin.getLocale().getMessage("interface.kitsell.linknoeco").sendPrefixedMessage(player);
|
||||
if (this.kit.getPrice() != 0) {
|
||||
this.kit.setPrice(0);
|
||||
this.plugin.getLocale().getMessage("interface.kitsell.linknoeco").sendPrefixedMessage(this.player);
|
||||
}
|
||||
kit.setLink(msg);
|
||||
plugin.updateHologram(kit);
|
||||
this.kit.setLink(msg);
|
||||
this.plugin.updateHologram(this.kit);
|
||||
aevent.player.closeInventory();
|
||||
paint();
|
||||
plugin.saveKits(false);
|
||||
this.plugin.saveKits(false);
|
||||
});
|
||||
guiManager.showGUI(event.player, gui);
|
||||
this.guiManager.showGUI(event.player, gui);
|
||||
});
|
||||
|
||||
// kit price
|
||||
setButton(1, 6, GuiUtils.createButtonItem(XMaterial.SUNFLOWER,
|
||||
plugin.getLocale().getMessage("interface.kitsell.price").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.kitsell.pricelore")
|
||||
.processPlaceholder("onoff",
|
||||
kit.getPrice() != 0 ? plugin.getLocale().getMessage("interface.kitsell.priceon")
|
||||
.processPlaceholder("price", kit.getPrice()).getMessage()
|
||||
: plugin.getLocale().getMessage("interface.kitsell.priceoff").getMessage()
|
||||
).getMessage().split("\\|")),
|
||||
this.plugin.getLocale().getMessage("interface.kitsell.price").getMessage(),
|
||||
this.plugin.getLocale().getMessage("interface.kitsell.pricelore")
|
||||
.processPlaceholder("onoff",
|
||||
this.kit.getPrice() != 0 ? this.plugin.getLocale().getMessage("interface.kitsell.priceon")
|
||||
.processPlaceholder("price", this.kit.getPrice()).getMessage()
|
||||
: this.plugin.getLocale().getMessage("interface.kitsell.priceoff").getMessage()
|
||||
).getMessage().split("\\|")),
|
||||
event -> {
|
||||
if (!EconomyManager.isEnabled()) {
|
||||
plugin.getLocale().getMessage("interface.kitsell.pricenoeco").sendPrefixedMessage(event.player);
|
||||
this.plugin.getLocale().getMessage("interface.kitsell.pricenoeco").sendPrefixedMessage(event.player);
|
||||
return;
|
||||
}
|
||||
AnvilGui gui = new AnvilGui(event.player, this);
|
||||
gui.setTitle(plugin.getLocale().getMessage("interface.kitsell.priceprompt").getMessage());
|
||||
gui.setTitle(this.plugin.getLocale().getMessage("interface.kitsell.priceprompt").getMessage());
|
||||
gui.setAction(aevent -> {
|
||||
final String msg = gui.getInputText().trim();
|
||||
double d = 0;
|
||||
@ -109,20 +108,20 @@ public class KitSellingOptionsGui extends Gui {
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
if (d <= 0) {
|
||||
plugin.getLocale().getMessage("interface.kitsell.pricenonumber").processPlaceholder("input", msg).sendPrefixedMessage(player);
|
||||
this.plugin.getLocale().getMessage("interface.kitsell.pricenonumber").processPlaceholder("input", msg).sendPrefixedMessage(this.player);
|
||||
} else {
|
||||
if (kit.getLink() != null) {
|
||||
kit.setLink(null);
|
||||
plugin.getLocale().getMessage("interface.kitsell.pricenolink").sendPrefixedMessage(player);
|
||||
if (this.kit.getLink() != null) {
|
||||
this.kit.setLink(null);
|
||||
this.plugin.getLocale().getMessage("interface.kitsell.pricenolink").sendPrefixedMessage(this.player);
|
||||
}
|
||||
kit.setPrice(d);
|
||||
plugin.updateHologram(kit);
|
||||
this.kit.setPrice(d);
|
||||
this.plugin.updateHologram(this.kit);
|
||||
aevent.player.closeInventory();
|
||||
paint();
|
||||
plugin.saveKits(false);
|
||||
this.plugin.saveKits(false);
|
||||
}
|
||||
});
|
||||
guiManager.showGUI(event.player, gui);
|
||||
this.guiManager.showGUI(event.player, gui);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,9 @@ package com.craftaro.ultimatekits.gui;
|
||||
|
||||
import com.craftaro.core.gui.Gui;
|
||||
import com.craftaro.core.gui.GuiUtils;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.SkullUtils;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.utils.ItemUtils;
|
||||
import com.craftaro.core.utils.NumberUtils;
|
||||
import com.craftaro.core.utils.TextUtils;
|
||||
import com.craftaro.ultimatekits.UltimateKits;
|
||||
import com.craftaro.ultimatekits.kit.Kit;
|
||||
@ -14,13 +15,13 @@ import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class PreviewKitGui extends Gui {
|
||||
|
||||
private final Kit kit;
|
||||
private final Player player;
|
||||
private final UltimateKits plugin;
|
||||
@ -82,20 +83,23 @@ public class PreviewKitGui extends Gui {
|
||||
|
||||
// exit button is only visible with a glass border
|
||||
setButton(0, 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(XMaterial.OAK_DOOR),
|
||||
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
|
||||
plugin.getLocale().getMessage("interface.button.exit").getMessage()),
|
||||
event -> exit());
|
||||
|
||||
if (back != null) {
|
||||
setButton(0, 0, GuiUtils.createButtonItem(ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23"),
|
||||
plugin.getLocale().getMessage("interface.button.back").getMessage()),
|
||||
ItemStack buttonItem = XMaterial.PLAYER_HEAD.parseItem();
|
||||
SkullMeta meta = SkullUtils.applySkin(buttonItem.getItemMeta(), "3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
buttonItem.setItemMeta(meta);
|
||||
|
||||
setButton(0, 0, GuiUtils.createButtonItem(buttonItem, plugin.getLocale().getMessage("interface.button.back").getMessage()),
|
||||
event -> event.player.closeInventory());
|
||||
}
|
||||
}
|
||||
// purchase button
|
||||
if (buyable) {
|
||||
setButton(rows - 1, 4, GuiUtils.createButtonItem(Settings.BUY_ICON.getMaterial(XMaterial.EMERALD),
|
||||
plugin.getLocale().getMessage("interface.button.buynow").getMessage(),
|
||||
getBuyLore()),
|
||||
setButton(this.rows - 1, 4, GuiUtils.createButtonItem(Settings.BUY_ICON.getMaterial(XMaterial.EMERALD),
|
||||
plugin.getLocale().getMessage("interface.button.buynow").getMessage(),
|
||||
getBuyLore()),
|
||||
event -> {
|
||||
exit();
|
||||
kit.buy(event.player, event.manager);
|
||||
@ -105,7 +109,7 @@ public class PreviewKitGui extends Gui {
|
||||
// display the kit items here
|
||||
Iterator<ItemStack> items = list.iterator();
|
||||
int startRow = useGlassBorder ? 1 : 0;
|
||||
int endRow = useGlassBorder ? rows - 2 : rows - 1;
|
||||
int endRow = useGlassBorder ? this.rows - 2 : this.rows - 1;
|
||||
int startCol = useGlassBorder ? 1 : 0;
|
||||
int endCol = useGlassBorder ? 7 : 8;
|
||||
for (int row = startRow; row <= endRow; ++row) {
|
||||
@ -143,7 +147,7 @@ public class PreviewKitGui extends Gui {
|
||||
List<String> newLore = new ArrayList<>();
|
||||
if (meta != null && meta.hasLore()) {
|
||||
for (String str : meta.getLore()) {
|
||||
newLore.add(str.replace("{PLAYER}", player.getName()).replace("<PLAYER>", player.getName()));
|
||||
newLore.add(str.replace("{PLAYER}", this.player.getName()).replace("<PLAYER>", this.player.getName()));
|
||||
}
|
||||
meta.setLore(newLore);
|
||||
}
|
||||
@ -157,7 +161,7 @@ public class PreviewKitGui extends Gui {
|
||||
List<String> newLore = new ArrayList<>();
|
||||
if (meta != null && meta.hasLore()) {
|
||||
for (String str : meta.getLore()) {
|
||||
newLore.add(str.replace("{PLAYER}", player.getName()).replace("<PLAYER>", player.getName()));
|
||||
newLore.add(str.replace("{PLAYER}", this.player.getName()).replace("<PLAYER>", this.player.getName()));
|
||||
}
|
||||
}
|
||||
meta.setLore(newLore);
|
||||
@ -168,21 +172,21 @@ public class PreviewKitGui extends Gui {
|
||||
|
||||
private List<String> getBuyLore() {
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
if (kit.hasPermissionToClaim(player)) {
|
||||
lore.add(plugin.getLocale().getMessage("interface.button.clickeco")
|
||||
if (this.kit.hasPermissionToClaim(this.player)) {
|
||||
lore.add(this.plugin.getLocale().getMessage("interface.button.clickeco")
|
||||
.processPlaceholder("price", "0").getMessage());
|
||||
if (player.isOp()) {
|
||||
if (this.player.isOp()) {
|
||||
lore.add("");
|
||||
lore.add(ChatColor.GRAY + "This is free because");
|
||||
lore.add(ChatColor.GRAY + "you have perms for it.");
|
||||
lore.add(ChatColor.GRAY + "Everyone else buys");
|
||||
lore.add(ChatColor.GRAY + "this for " + ChatColor.GREEN + "$" + Methods.formatEconomy(kit.getPrice()) + ChatColor.GRAY + ".");
|
||||
lore.add(ChatColor.GRAY + "this for " + ChatColor.GREEN + "$" + NumberUtils.formatNumber(this.kit.getPrice()) + ChatColor.GRAY + ".");
|
||||
}
|
||||
} else {
|
||||
lore.add(plugin.getLocale().getMessage("interface.button.clickeco")
|
||||
.processPlaceholder("price", Methods.formatEconomy(kit.getPrice())).getMessage());
|
||||
lore.add(this.plugin.getLocale().getMessage("interface.button.clickeco")
|
||||
.processPlaceholder("price", NumberUtils.formatNumber(this.kit.getPrice())).getMessage());
|
||||
}
|
||||
if (kit.getDelay() != 0 && player.isOp()) {
|
||||
if (this.kit.getDelay() != 0 && this.player.isOp()) {
|
||||
lore.add("");
|
||||
lore.add(ChatColor.GRAY + "You do not have a delay");
|
||||
lore.add(ChatColor.GRAY + "because you have perms");
|
||||
@ -190,5 +194,4 @@ public class PreviewKitGui extends Gui {
|
||||
}
|
||||
return lore;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,11 +17,7 @@ import org.bukkit.util.Vector;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/24/2017.
|
||||
*/
|
||||
public class DisplayItemHandler {
|
||||
|
||||
private final UltimateKits plugin;
|
||||
|
||||
public DisplayItemHandler(UltimateKits plugin) {
|
||||
@ -29,12 +25,13 @@ public class DisplayItemHandler {
|
||||
}
|
||||
|
||||
public void start() {
|
||||
Bukkit.getServer().getScheduler().runTaskTimer(plugin, this::displayItems, 30L, 30L);
|
||||
Bukkit.getServer().getScheduler().runTaskTimer(this.plugin, this::displayItems, 30L, 30L);
|
||||
}
|
||||
|
||||
private void displayItems() {
|
||||
for (KitBlockData kitBlockData : plugin.getKitManager().getKitLocations().values())
|
||||
for (KitBlockData kitBlockData : this.plugin.getKitManager().getKitLocations().values()) {
|
||||
displayItem(kitBlockData);
|
||||
}
|
||||
}
|
||||
|
||||
public void displayItem(KitBlockData kitBlockData) {
|
||||
@ -42,15 +39,22 @@ public class DisplayItemHandler {
|
||||
location.add(0.5, 0, 0.5);
|
||||
|
||||
Kit kit = kitBlockData.getKit();
|
||||
if (kit == null) return;
|
||||
if (kit == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<ItemStack> list = kit.getReadableContents(null, false, false, false);
|
||||
if (list == null) return;
|
||||
|
||||
if (list.isEmpty()) return;
|
||||
|
||||
if (!location.getWorld().isChunkLoaded((int) location.getX() >> 4, (int) location.getZ() >> 4))
|
||||
if (list == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (list.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!location.getWorld().isChunkLoaded((int) location.getX() >> 4, (int) location.getZ() >> 4)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Entity e : location.getChunk().getEntities()) {
|
||||
if (e.getType() != EntityType.DROPPED_ITEM
|
||||
@ -60,19 +64,24 @@ public class DisplayItemHandler {
|
||||
}
|
||||
Item i = (Item) e;
|
||||
|
||||
if (!kitBlockData.isDisplayingItems()) e.remove();
|
||||
if (!kitBlockData.isDisplayingItems()) {
|
||||
e.remove();
|
||||
}
|
||||
|
||||
|
||||
NBTItem nbtItem = new NBTItem(i.getItemStack());
|
||||
int inum = nbtItem.hasKey("num") ? nbtItem.getInteger("num") + 1 : 0;
|
||||
int inum = nbtItem.hasTag("num") ? nbtItem.getInteger("num") + 1 : 0;
|
||||
|
||||
int size = list.size();
|
||||
if (inum > size || inum <= 0) inum = 1;
|
||||
if (inum > size || inum <= 0) {
|
||||
inum = 1;
|
||||
}
|
||||
|
||||
ItemStack is = list.get(inum - 1);
|
||||
if (kitBlockData.isItemOverride()) {
|
||||
if (kit.getDisplayItem() != null)
|
||||
if (kit.getDisplayItem() != null) {
|
||||
is = kit.getDisplayItem();
|
||||
}
|
||||
}
|
||||
is.setAmount(1);
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
@ -85,7 +94,9 @@ public class DisplayItemHandler {
|
||||
i.setPickupDelay(9999);
|
||||
return;
|
||||
}
|
||||
if (!kitBlockData.isDisplayingItems()) return;
|
||||
if (!kitBlockData.isDisplayingItems()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack is = list.get(0);
|
||||
is.setAmount(1);
|
||||
@ -96,15 +107,15 @@ public class DisplayItemHandler {
|
||||
NBTItem nbtItem = new NBTItem(is);
|
||||
nbtItem.setInteger("num", 0);
|
||||
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
Bukkit.getScheduler().runTask(this.plugin, () -> {
|
||||
Item item = location.getWorld().dropItem(location.add(0, 1, 0), nbtItem.getItem());
|
||||
Vector vec = new Vector(0, 0, 0);
|
||||
item.setVelocity(vec);
|
||||
item.setPickupDelay(9999);
|
||||
item.setCustomName(null);
|
||||
item.setMetadata("US_EXEMPT", new FixedMetadataValue(UltimateKits.getInstance(), true));
|
||||
item.setMetadata("displayItem", new FixedMetadataValue(UltimateKits.getInstance(), true));
|
||||
item.setMetadata("betterdrops_ignore", new FixedMetadataValue(UltimateKits.getInstance(), true));
|
||||
item.setMetadata("US_EXEMPT", new FixedMetadataValue(this.plugin, true));
|
||||
item.setMetadata("displayItem", new FixedMetadataValue(this.plugin, true));
|
||||
item.setMetadata("betterdrops_ignore", new FixedMetadataValue(this.plugin, true));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -10,11 +10,7 @@ import org.bukkit.Location;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/24/2017.
|
||||
*/
|
||||
public class ParticleHandler {
|
||||
|
||||
private final UltimateKits plugin;
|
||||
private int amt;
|
||||
private CompatibleParticleHandler.ParticleType type;
|
||||
@ -24,25 +20,26 @@ public class ParticleHandler {
|
||||
}
|
||||
|
||||
public void start() {
|
||||
amt = Settings.PARTICLE_AMOUNT.getInt() / 2;
|
||||
this.amt = Settings.PARTICLE_AMOUNT.getInt() / 2;
|
||||
String typeName = Settings.PARTICLE_TYPE.getString();
|
||||
type = CompatibleParticleHandler.ParticleType.getParticle(typeName);
|
||||
if (type == null) {
|
||||
type = CompatibleParticleHandler.ParticleType.SPELL_WITCH;
|
||||
this.type = CompatibleParticleHandler.ParticleType.getParticle(typeName);
|
||||
if (this.type == null) {
|
||||
this.type = CompatibleParticleHandler.ParticleType.SPELL_WITCH;
|
||||
}
|
||||
Bukkit.getServer().getScheduler().runTaskTimerAsynchronously(UltimateKits.getInstance(), this::applyParticles, 0, 5L);
|
||||
}
|
||||
|
||||
private void applyParticles() {
|
||||
Map<Location, KitBlockData> kitBlocks = plugin.getKitManager().getKitLocations();
|
||||
Map<Location, KitBlockData> kitBlocks = this.plugin.getKitManager().getKitLocations();
|
||||
for (KitBlockData kitBlockData : new ArrayList<>(kitBlocks.values())) {
|
||||
if (kitBlockData.getLocation().getWorld() == null || !kitBlockData.hasParticles()) continue;
|
||||
if (kitBlockData.getLocation().getWorld() == null || !kitBlockData.hasParticles()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Location location = kitBlockData.getLocation();
|
||||
location.add(.5, 0, .5);
|
||||
|
||||
CompatibleParticleHandler.spawnParticles(type, location, amt, 0.25, 0.25, 0.25, 0.5);
|
||||
CompatibleParticleHandler.spawnParticles(this.type, location, this.amt, 0.25, 0.25, 0.25, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,11 +13,10 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Key {
|
||||
|
||||
// The name of the key.
|
||||
private final String name;
|
||||
|
||||
// The amount of items this key will give you. -1 is all;
|
||||
// The number of items this key will give you; -1 is all
|
||||
private final int amount;
|
||||
|
||||
// Should the key be enchanted?
|
||||
@ -45,53 +44,57 @@ public class Key {
|
||||
meta.setDisplayName(plugin.getLocale().getMessage("interface.key.title")
|
||||
.processPlaceholder("kit", kitName).getMessage());
|
||||
|
||||
if (enchanted)
|
||||
if (this.enchanted) {
|
||||
ItemUtils.addGlow(item);
|
||||
}
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(plugin.getLocale().getMessage("interface.key.name")
|
||||
.processPlaceholder("name", name).getMessage());
|
||||
.processPlaceholder("name", this.name).getMessage());
|
||||
|
||||
String desc1 = plugin.getLocale().getMessage("interface.key.description1")
|
||||
.processPlaceholder("kit", kitName).getMessage();
|
||||
|
||||
if (kit == null)
|
||||
if (kit == null) {
|
||||
desc1 = desc1.replaceAll("\\[.*?\\]", "");
|
||||
else
|
||||
} else {
|
||||
desc1 = desc1.replace("[", "").replace("]", "");
|
||||
}
|
||||
|
||||
lore.add(desc1);
|
||||
if (this.amount == -1)
|
||||
if (this.amount == -1) {
|
||||
lore.add(plugin.getLocale().getMessage("interface.key.description2").getMessage());
|
||||
else
|
||||
} else {
|
||||
lore.add(plugin.getLocale().getMessage("interface.key.description3").getMessage());
|
||||
if (kitAmount > 1)
|
||||
}
|
||||
if (this.kitAmount > 1) {
|
||||
lore.add(plugin.getLocale().getMessage("interface.key.description4")
|
||||
.processPlaceholder("amt", this.kitAmount).getMessage());
|
||||
}
|
||||
meta.setLore(lore);
|
||||
|
||||
item.setItemMeta(meta);
|
||||
|
||||
NBTItem nbtItem = new NBTItem(item);
|
||||
nbtItem.setString("key", name);
|
||||
nbtItem.setString("key", this.name);
|
||||
nbtItem.setString("kit", kit == null ? "ANY" : kit.getName());
|
||||
|
||||
return nbtItem.getItem();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
return this.amount;
|
||||
}
|
||||
|
||||
public int getKitAmount() {
|
||||
return kitAmount;
|
||||
return this.kitAmount;
|
||||
}
|
||||
|
||||
public boolean isEnchanted() {
|
||||
return enchanted;
|
||||
return this.enchanted;
|
||||
}
|
||||
}
|
||||
|
@ -5,30 +5,35 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public final class KeyManager {
|
||||
|
||||
private final Set<Key> registeredKeys = new HashSet<>();
|
||||
|
||||
public boolean addKey(Key key) {
|
||||
if (key == null) return false;
|
||||
return registeredKeys.add(key);
|
||||
if (key == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.registeredKeys.add(key);
|
||||
}
|
||||
|
||||
public void removeKey(Key key) {
|
||||
registeredKeys.remove(key);
|
||||
this.registeredKeys.remove(key);
|
||||
}
|
||||
|
||||
public Key getKey(String name) {
|
||||
for (Key key : registeredKeys)
|
||||
if (key.getName().equalsIgnoreCase(name)) return key;
|
||||
for (Key key : this.registeredKeys) {
|
||||
if (key.getName().equalsIgnoreCase(name)) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public Set<Key> getKeys() {
|
||||
return Collections.unmodifiableSet(registeredKeys);
|
||||
return Collections.unmodifiableSet(this.registeredKeys);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
registeredKeys.clear();
|
||||
this.registeredKeys.clear();
|
||||
}
|
||||
}
|
||||
|
@ -9,18 +9,18 @@ import com.craftaro.core.third_party.com.cryptomorin.xseries.XSound;
|
||||
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
|
||||
import com.craftaro.core.utils.ItemUtils;
|
||||
import com.craftaro.core.utils.TextUtils;
|
||||
import com.craftaro.core.utils.TimeUtils;
|
||||
import com.craftaro.ultimatekits.UltimateKits;
|
||||
import com.craftaro.ultimatekits.gui.PreviewKitGui;
|
||||
import com.craftaro.ultimatekits.key.Key;
|
||||
import com.craftaro.ultimatekits.kit.type.KitContentCommand;
|
||||
import com.craftaro.ultimatekits.kit.type.KitContentEconomy;
|
||||
import com.craftaro.ultimatekits.category.Category;
|
||||
import com.craftaro.ultimatekits.crate.Crate;
|
||||
import com.craftaro.ultimatekits.gui.AnimatedKitGui;
|
||||
import com.craftaro.ultimatekits.gui.ConfirmBuyGui;
|
||||
import com.craftaro.ultimatekits.gui.PreviewKitGui;
|
||||
import com.craftaro.ultimatekits.key.Key;
|
||||
import com.craftaro.ultimatekits.kit.type.KitContentCommand;
|
||||
import com.craftaro.ultimatekits.kit.type.KitContentEconomy;
|
||||
import com.craftaro.ultimatekits.settings.Settings;
|
||||
import com.craftaro.ultimatekits.utils.ArmorType;
|
||||
import com.craftaro.ultimatekits.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -53,8 +53,9 @@ public class Kit implements Cloneable {
|
||||
private KitAnimation kitAnimation = KitAnimation.NONE;
|
||||
|
||||
public Kit(String key) {
|
||||
if (plugin == null)
|
||||
if (plugin == null) {
|
||||
plugin = UltimateKits.getInstance();
|
||||
}
|
||||
this.key = key;
|
||||
this.name = TextUtils.formatText(key, true);
|
||||
}
|
||||
@ -71,12 +72,12 @@ public class Kit implements Cloneable {
|
||||
return;
|
||||
}
|
||||
|
||||
if (link != null) {
|
||||
if (this.link != null) {
|
||||
player.sendMessage("");
|
||||
plugin.getLocale().newMessage("&a" + link).sendPrefixedMessage(player);
|
||||
plugin.getLocale().newMessage("&a" + this.link).sendPrefixedMessage(player);
|
||||
player.sendMessage("");
|
||||
player.closeInventory();
|
||||
} else if (price != 0) {
|
||||
} else if (this.price != 0) {
|
||||
manager.showGUI(player, new ConfirmBuyGui(plugin, player, this, null));
|
||||
} else {
|
||||
UltimateKits.getInstance().getLocale().getMessage("command.general.noperms")
|
||||
@ -95,8 +96,9 @@ public class Kit implements Cloneable {
|
||||
}
|
||||
|
||||
// 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)
|
||||
if (this.kitAnimation == KitAnimation.ROULETTE && space >= 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return space >= itemAmount;
|
||||
}
|
||||
@ -105,8 +107,9 @@ public class Kit implements Cloneable {
|
||||
ItemStack item = player.getItemInHand();
|
||||
NBTItem nbtItem = new NBTItem(item);
|
||||
|
||||
if (!nbtItem.hasKey("key") || !nbtItem.hasKey("kit"))
|
||||
if (!nbtItem.hasKey("key") || !nbtItem.hasKey("kit")) {
|
||||
return;
|
||||
}
|
||||
|
||||
String keyName = nbtItem.getString("key");
|
||||
String kitName = nbtItem.getString("kit");
|
||||
@ -114,17 +117,18 @@ public class Kit implements Cloneable {
|
||||
boolean any = kitName.equals("ANY");
|
||||
Key key = plugin.getKeyManager().getKey(keyName);
|
||||
|
||||
if (key == null && !any)
|
||||
if (key == null && !any) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!any && !kitName.equals(name)) {
|
||||
if (!any && !kitName.equals(this.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);
|
||||
.processPlaceholder("kit", this.name).sendPrefixedMessage(player);
|
||||
if (player.getInventory().getItemInHand().getAmount() != 1) {
|
||||
item.setAmount(item.getAmount() - 1);
|
||||
player.setItemInHand(item);
|
||||
@ -137,31 +141,34 @@ public class Kit implements Cloneable {
|
||||
public void processCrateUse(Player player, ItemStack item, CompatibleHand hand) {
|
||||
Crate crate = plugin.getCrateManager().getCrate(item);
|
||||
|
||||
if (crate == null || !giveKit(player, crate))
|
||||
if (crate == null || !giveKit(player, crate)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemUtils.takeActiveItem(player, hand);
|
||||
|
||||
plugin.getLocale().getMessage("event.crate.success")
|
||||
.processPlaceholder("crate", name).sendPrefixedMessage(player);
|
||||
.processPlaceholder("crate", this.name).sendPrefixedMessage(player);
|
||||
}
|
||||
|
||||
public void processPurchaseUse(Player player) {
|
||||
if (!EconomyManager.isEnabled()) return;
|
||||
if (!EconomyManager.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!player.hasPermission("ultimatekits.buy." + key)) {
|
||||
if (!player.hasPermission("ultimatekits.buy." + this.key)) {
|
||||
UltimateKits.getInstance().getLocale().getMessage("command.general.noperms")
|
||||
.sendPrefixedMessage(player);
|
||||
return;
|
||||
} else if (!EconomyManager.hasBalance(player, price)) {
|
||||
} else if (!EconomyManager.hasBalance(player, this.price)) {
|
||||
plugin.getLocale().getMessage("event.claim.cannotafford")
|
||||
.processPlaceholder("kit", name).sendPrefixedMessage(player);
|
||||
.processPlaceholder("kit", this.name).sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
if (this.delay > 0) {
|
||||
if (getNextUse(player) != 0) {
|
||||
plugin.getLocale().getMessage("event.claim.delay")
|
||||
.processPlaceholder("time", Methods.makeReadable(this.getNextUse(player)))
|
||||
.processPlaceholder("time", TimeUtils.makeReadable(this.getNextUse(player)))
|
||||
.sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
@ -170,12 +177,13 @@ public class Kit implements Cloneable {
|
||||
return;
|
||||
}
|
||||
if (giveKit(player)) {
|
||||
EconomyManager.withdrawBalance(player, price);
|
||||
if (delay != 0)
|
||||
EconomyManager.withdrawBalance(player, this.price);
|
||||
if (this.delay != 0) {
|
||||
updateDelay(player); //updates delay on buy
|
||||
}
|
||||
|
||||
plugin.getLocale().getMessage("event.claim.purchasesuccess")
|
||||
.processPlaceholder("kit", name).sendPrefixedMessage(player);
|
||||
.processPlaceholder("kit", this.name).sendPrefixedMessage(player);
|
||||
}
|
||||
}
|
||||
|
||||
@ -185,13 +193,14 @@ public class Kit implements Cloneable {
|
||||
} else if (getNextUse(player) <= 0 || forced) {
|
||||
if (giveKit(player)) {
|
||||
updateDelay(player);
|
||||
if (kitAnimation == KitAnimation.NONE)
|
||||
if (this.kitAnimation == KitAnimation.NONE) {
|
||||
plugin.getLocale().getMessage("event.claim.givesuccess")
|
||||
.processPlaceholder("kit", name).sendPrefixedMessage(player);
|
||||
.processPlaceholder("kit", this.name).sendPrefixedMessage(player);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
plugin.getLocale().getMessage("event.claim.delay")
|
||||
.processPlaceholder("time", Methods.makeReadable(getNextUse(player)))
|
||||
.processPlaceholder("time", TimeUtils.makeReadable(getNextUse(player)))
|
||||
.sendPrefixedMessage(player);
|
||||
}
|
||||
}
|
||||
@ -203,13 +212,13 @@ public class Kit implements Cloneable {
|
||||
.sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
if (key == null) {
|
||||
if (this.key == null) {
|
||||
plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getLocale().getMessage("event.preview.kit")
|
||||
.processPlaceholder("kit", name).sendPrefixedMessage(player);
|
||||
.processPlaceholder("kit", this.name).sendPrefixedMessage(player);
|
||||
manager.showGUI(player, new PreviewKitGui(plugin, player, this, back));
|
||||
}
|
||||
|
||||
@ -222,8 +231,12 @@ public class Kit implements Cloneable {
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
List<String> newLore = new ArrayList<>();
|
||||
for (String line : meta.getLore()) {
|
||||
if (line.contains("Moveable")) continue;
|
||||
if (line.equals(TextUtils.formatText("&8----"))) break;
|
||||
if (line.contains("Moveable")) {
|
||||
continue;
|
||||
}
|
||||
if (line.equals(TextUtils.formatText("&8----"))) {
|
||||
break;
|
||||
}
|
||||
newLore.add(line);
|
||||
}
|
||||
meta.setLore(newLore);
|
||||
@ -248,7 +261,7 @@ public class Kit implements Cloneable {
|
||||
}
|
||||
}
|
||||
}
|
||||
contents = list;
|
||||
this.contents = list;
|
||||
plugin.saveKits(false);
|
||||
}
|
||||
|
||||
@ -258,8 +271,12 @@ public class Kit implements Cloneable {
|
||||
for (KitItem item : getContents()) {
|
||||
if ((!item.getSerialized().startsWith("/") && !item.getSerialized().startsWith(Settings.CURRENCY_SYMBOL.getString())) || commands) { //ToDO: I doubt this is correct.
|
||||
ItemStack stack = moveable ? item.getMoveableItem() : item.getItem();
|
||||
if (preview) stack = item.getItemForDisplay();
|
||||
if (stack == null) continue;
|
||||
if (preview) {
|
||||
stack = item.getItemForDisplay();
|
||||
}
|
||||
if (stack == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack fin = stack;
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI") && stack.getItemMeta().getLore() != null) {
|
||||
@ -279,7 +296,7 @@ public class Kit implements Cloneable {
|
||||
}
|
||||
|
||||
public boolean giveKit(Player player) {
|
||||
return giveKit(player, contents.size(), -1);
|
||||
return giveKit(player, this.contents.size(), -1);
|
||||
}
|
||||
|
||||
private boolean giveKit(Player player, Key key) {
|
||||
@ -291,7 +308,7 @@ public class Kit implements Cloneable {
|
||||
if (amount == -1) {
|
||||
// FIXME: I don't understand how Crates, Keys, etc. actually are supposed to work.
|
||||
// I think the give-algorithms are generally wrongly implemented and confusing naming is making it hard to understand.
|
||||
amount = contents.size();
|
||||
amount = this.contents.size();
|
||||
}
|
||||
return giveKit(player, amount, key.getKitAmount());
|
||||
}
|
||||
@ -301,7 +318,7 @@ public class Kit implements Cloneable {
|
||||
if (amount == -1) {
|
||||
// FIXME: I don't understand how Crates, Keys, etc. actually are supposed to work.
|
||||
// I think the give-algorithms are generally wrongly implemented and confusing naming is making it hard to understand.
|
||||
amount = contents.size();
|
||||
amount = this.contents.size();
|
||||
}
|
||||
return giveKit(player, amount, crate.getKitAmount());
|
||||
}
|
||||
@ -310,8 +327,9 @@ public class Kit implements Cloneable {
|
||||
List<KitItem> innerContents = new ArrayList<>(getContents());
|
||||
|
||||
// Amount of items from the kit to give to the player.
|
||||
if (kitAnimation == KitAnimation.ROULETTE)
|
||||
if (this.kitAnimation == KitAnimation.ROULETTE) {
|
||||
itemAmount = 1; //TODO how about kitAmount > 1? generateRandomItem() will only give 1 random item instead of kitAmount
|
||||
}
|
||||
int itemGiveAmount = kitAmount > 0 ? itemAmount * kitAmount : itemAmount;
|
||||
|
||||
if (Settings.NO_REDEEM_WHEN_FULL.getBoolean() && !hasRoom(player, itemGiveAmount)) {
|
||||
@ -319,24 +337,28 @@ public class Kit implements Cloneable {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Settings.SOUNDS_ENABLED.getBoolean() && kitAnimation == KitAnimation.NONE)
|
||||
if (Settings.SOUNDS_ENABLED.getBoolean() && this.kitAnimation == KitAnimation.NONE) {
|
||||
XSound.ENTITY_PLAYER_LEVELUP.play(player, 0.6F, 15.0F);
|
||||
}
|
||||
|
||||
return generateRandomItem(innerContents, itemGiveAmount, 0, player);
|
||||
}
|
||||
|
||||
private boolean generateRandomItem(List<KitItem> innerContents, int itemGiveAmount, int itemGivenAmount, Player player) {
|
||||
if (innerContents.size() != itemGiveAmount || kitAnimation != KitAnimation.NONE)
|
||||
if (innerContents.size() != itemGiveAmount || this.kitAnimation != KitAnimation.NONE) {
|
||||
Collections.shuffle(innerContents);
|
||||
}
|
||||
|
||||
for (KitItem item : new ArrayList<>(innerContents)) {
|
||||
if (itemGiveAmount <= 0 && itemGivenAmount != 0) break;
|
||||
if (itemGiveAmount <= 0 && itemGivenAmount != 0) {
|
||||
break;
|
||||
}
|
||||
double ch = item.getChance() == 0 ? 100 : item.getChance();
|
||||
double rand = Math.random() * 100;
|
||||
itemGiveAmount--;
|
||||
if (rand < ch || ch == 100) {
|
||||
itemGivenAmount++;
|
||||
if (kitAnimation != KitAnimation.NONE) {
|
||||
if (this.kitAnimation != KitAnimation.NONE) {
|
||||
// TODO: this is a very bad way to solve this problem.
|
||||
// Giving the player kit rewards really should be done outside of the Kit class.
|
||||
plugin.getGuiManager().showGUI(player, new AnimatedKitGui(plugin, player, this, item.getItem()));
|
||||
@ -344,12 +366,15 @@ public class Kit implements Cloneable {
|
||||
} else {
|
||||
ItemStack parseStack = item.getContent().process(player);
|
||||
if (item.getContent() instanceof KitContentEconomy
|
||||
|| item.getContent() instanceof KitContentCommand)
|
||||
|| item.getContent() instanceof KitContentCommand) {
|
||||
continue;
|
||||
}
|
||||
|
||||
innerContents.remove(item);
|
||||
|
||||
if (Settings.AUTO_EQUIP_ARMOR.getBoolean() && ArmorType.equip(player, parseStack)) continue;
|
||||
if (Settings.AUTO_EQUIP_ARMOR.getBoolean() && ArmorType.equip(player, parseStack)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Map<Integer, ItemStack> overfilled = player.getInventory().addItem(parseStack);
|
||||
for (ItemStack item2 : overfilled.values()) {
|
||||
@ -359,24 +384,27 @@ public class Kit implements Cloneable {
|
||||
}
|
||||
}
|
||||
|
||||
if ((itemGiveAmount > 0 || itemGivenAmount == 0) && !innerContents.isEmpty())
|
||||
if ((itemGiveAmount > 0 || itemGivenAmount == 0) && !innerContents.isEmpty()) {
|
||||
return generateRandomItem(innerContents, itemGiveAmount, itemGivenAmount, player);
|
||||
}
|
||||
|
||||
player.updateInventory();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void updateDelay(Player player) {
|
||||
plugin.getDataFile().set("Kits." + key + ".delays." + player.getUniqueId().toString(), System.currentTimeMillis());
|
||||
plugin.getDataFile().set("Kits." + this.key + ".delays." + player.getUniqueId(), System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public Long getNextUse(Player player) {
|
||||
String configSectionPlayer = "Kits." + key + ".delays." + player.getUniqueId().toString();
|
||||
String configSectionPlayer = "Kits." + this.key + ".delays." + player.getUniqueId();
|
||||
Config config = plugin.getDataFile();
|
||||
|
||||
if (!config.contains(configSectionPlayer)) {
|
||||
return 0L;
|
||||
} else if (this.delay == -1) return -1L;
|
||||
} else if (this.delay == -1) {
|
||||
return -1L;
|
||||
}
|
||||
|
||||
long last = config.getLong(configSectionPlayer);
|
||||
long delay = this.delay * 1000;
|
||||
@ -385,19 +413,19 @@ public class Kit implements Cloneable {
|
||||
}
|
||||
|
||||
public boolean hasPermissionToClaim(Player player) {
|
||||
return player.hasPermission("ultimatekits.claim." + key.toLowerCase());
|
||||
return player.hasPermission("ultimatekits.claim." + this.key.toLowerCase());
|
||||
}
|
||||
|
||||
public boolean hasPermissionToPreview(Player player) {
|
||||
return player.hasPermission("ultimatekits.preview." + key.toLowerCase());
|
||||
return player.hasPermission("ultimatekits.preview." + this.key.toLowerCase());
|
||||
}
|
||||
|
||||
public boolean hasPermissionToBuy(Player player) {
|
||||
return player.hasPermission("ultimatekits.buy." + key.toLowerCase());
|
||||
return player.hasPermission("ultimatekits.buy." + this.key.toLowerCase());
|
||||
}
|
||||
|
||||
public double getPrice() {
|
||||
return price;
|
||||
return this.price;
|
||||
}
|
||||
|
||||
public Kit setPrice(double price) {
|
||||
@ -406,7 +434,7 @@ public class Kit implements Cloneable {
|
||||
}
|
||||
|
||||
public String getLink() {
|
||||
return link;
|
||||
return this.link;
|
||||
}
|
||||
|
||||
public Kit setLink(String link) {
|
||||
@ -415,7 +443,7 @@ public class Kit implements Cloneable {
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public Kit setTitle(String title) {
|
||||
@ -424,7 +452,7 @@ public class Kit implements Cloneable {
|
||||
}
|
||||
|
||||
public long getDelay() {
|
||||
return delay;
|
||||
return this.delay;
|
||||
}
|
||||
|
||||
public Kit setDelay(long delay) {
|
||||
@ -433,7 +461,7 @@ public class Kit implements Cloneable {
|
||||
}
|
||||
|
||||
public Category getCategory() {
|
||||
return category;
|
||||
return this.category;
|
||||
}
|
||||
|
||||
public Kit setCategory(Category category) {
|
||||
@ -451,15 +479,15 @@ public class Kit implements Cloneable {
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public ItemStack getDisplayItem() {
|
||||
return displayItem;
|
||||
return this.displayItem;
|
||||
}
|
||||
|
||||
public Kit setDisplayItem(ItemStack item) {
|
||||
@ -468,7 +496,7 @@ public class Kit implements Cloneable {
|
||||
}
|
||||
|
||||
public boolean isHidden() {
|
||||
return hidden;
|
||||
return this.hidden;
|
||||
}
|
||||
|
||||
public Kit setHidden(boolean hidden) {
|
||||
@ -477,7 +505,7 @@ public class Kit implements Cloneable {
|
||||
}
|
||||
|
||||
public KitAnimation getKitAnimation() {
|
||||
return kitAnimation;
|
||||
return this.kitAnimation;
|
||||
}
|
||||
|
||||
public Kit setKitAnimation(KitAnimation kitAnimation) {
|
||||
@ -491,8 +519,9 @@ public class Kit implements Cloneable {
|
||||
|
||||
List<KitItem> contents = new ArrayList<>();
|
||||
|
||||
for (KitItem item : newKit.contents)
|
||||
for (KitItem item : newKit.contents) {
|
||||
contents.add(item.clone());
|
||||
}
|
||||
|
||||
newKit.setContents(contents);
|
||||
|
||||
@ -507,16 +536,19 @@ public class Kit implements Cloneable {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * (key != null ? key.hashCode() : 0);
|
||||
return 31 * (this.key != null ? this.key.hashCode() : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Kit)) return false;
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof Kit)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Kit kit = (Kit) o;
|
||||
return Objects.equals(key, kit.key);
|
||||
Kit kit = (Kit) obj;
|
||||
return Objects.equals(this.key, kit.key);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import org.bukkit.World;
|
||||
import java.util.UUID;
|
||||
|
||||
public class KitBlockData {
|
||||
|
||||
// This is the unique identifier for this block data.
|
||||
// It is reset on every plugin load.
|
||||
// Used for holograms.
|
||||
@ -44,35 +43,35 @@ public class KitBlockData {
|
||||
}
|
||||
|
||||
public Kit getKit() {
|
||||
return kit;
|
||||
return this.kit;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location.clone();
|
||||
return this.location.clone();
|
||||
}
|
||||
|
||||
public boolean isInLoadedChunk() {
|
||||
return location != null && location.getWorld() != null && location.getWorld().isChunkLoaded(((int) location.getX()) >> 4, ((int) location.getZ()) >> 4);
|
||||
return this.location != null && this.location.getWorld() != null && this.location.getWorld().isChunkLoaded(((int) this.location.getX()) >> 4, ((int) this.location.getZ()) >> 4);
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return location.getBlockX();
|
||||
return this.location.getBlockX();
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return location.getBlockY();
|
||||
return this.location.getBlockY();
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return location.getBlockZ();
|
||||
return this.location.getBlockZ();
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return location.getWorld();
|
||||
return this.location.getWorld();
|
||||
}
|
||||
|
||||
public boolean showHologram() {
|
||||
return hologram;
|
||||
return this.hologram;
|
||||
}
|
||||
|
||||
public void setShowHologram(boolean hologram) {
|
||||
@ -80,7 +79,7 @@ public class KitBlockData {
|
||||
}
|
||||
|
||||
public boolean hasParticles() {
|
||||
return particles;
|
||||
return this.particles;
|
||||
}
|
||||
|
||||
public void setHasParticles(boolean particles) {
|
||||
@ -88,7 +87,7 @@ public class KitBlockData {
|
||||
}
|
||||
|
||||
public boolean isDisplayingItems() {
|
||||
return items;
|
||||
return this.items;
|
||||
}
|
||||
|
||||
public void setDisplayingItems(boolean items) {
|
||||
@ -96,7 +95,7 @@ public class KitBlockData {
|
||||
}
|
||||
|
||||
public boolean isItemOverride() {
|
||||
return itemOverride;
|
||||
return this.itemOverride;
|
||||
}
|
||||
|
||||
public void setItemOverride(boolean itemOverride) {
|
||||
@ -104,7 +103,7 @@ public class KitBlockData {
|
||||
}
|
||||
|
||||
public KitType getType() {
|
||||
return type;
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setType(KitType type) {
|
||||
@ -112,6 +111,6 @@ public class KitBlockData {
|
||||
}
|
||||
|
||||
public String getHologramId() {
|
||||
return "UltimateKits-" + uniqueId;
|
||||
return "UltimateKits-" + this.uniqueId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,10 @@ package com.craftaro.ultimatekits.kit;
|
||||
|
||||
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
|
||||
import com.craftaro.core.utils.TextUtils;
|
||||
import com.craftaro.ultimatekits.UltimateKits;
|
||||
import com.craftaro.ultimatekits.kit.type.KitContent;
|
||||
import com.craftaro.ultimatekits.kit.type.KitContentCommand;
|
||||
import com.craftaro.ultimatekits.kit.type.KitContentEconomy;
|
||||
import com.craftaro.ultimatekits.UltimateKits;
|
||||
import com.craftaro.ultimatekits.kit.type.KitContentItem;
|
||||
import com.craftaro.ultimatekits.settings.Settings;
|
||||
import com.craftaro.ultimatekits.utils.ItemSerializer;
|
||||
@ -20,7 +20,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class KitItem implements Cloneable {
|
||||
|
||||
private KitContent content;
|
||||
private KitItemType type;
|
||||
private String displayName, displayLore = null;
|
||||
@ -59,41 +58,51 @@ public class KitItem implements Cloneable {
|
||||
}
|
||||
|
||||
private void translateTags(ItemStack item) {
|
||||
if (item == null) return;
|
||||
if (item == null) {
|
||||
return;
|
||||
}
|
||||
NBTItem nbtItem = new NBTItem(item);
|
||||
if (nbtItem.hasKey("chance"))
|
||||
chance = nbtItem.getDouble("chance");
|
||||
if (nbtItem.hasKey("display-item"))
|
||||
displayItem = Material.valueOf(nbtItem.getString("display-item"));
|
||||
if (nbtItem.hasKey("display-name"))
|
||||
displayName = nbtItem.getString("display-name");
|
||||
if (nbtItem.hasKey("display-lore"))
|
||||
displayLore = nbtItem.getString("display-lore");
|
||||
if (nbtItem.hasKey("chance")) {
|
||||
this.chance = nbtItem.getDouble("chance");
|
||||
}
|
||||
if (nbtItem.hasKey("display-item")) {
|
||||
this.displayItem = Material.valueOf(nbtItem.getString("display-item"));
|
||||
}
|
||||
if (nbtItem.hasKey("display-name")) {
|
||||
this.displayName = nbtItem.getString("display-name");
|
||||
}
|
||||
if (nbtItem.hasKey("display-lore")) {
|
||||
this.displayLore = nbtItem.getString("display-lore");
|
||||
}
|
||||
}
|
||||
|
||||
private String translateLine(String line) {
|
||||
String[] lineSplit = line.trim().split(";", 2);
|
||||
String[] kitOptions = lineSplit[0].replace(String.valueOf(ChatColor.COLOR_CHAR), "").split("~");
|
||||
for (String s : kitOptions) {
|
||||
if (s.equals("")) continue;
|
||||
if (s.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
String[] sSplit = s.split(":", 2);
|
||||
if (sSplit.length != 2) return line;
|
||||
if (sSplit.length != 2) {
|
||||
return line;
|
||||
}
|
||||
String option = sSplit[0].toLowerCase();
|
||||
String value = sSplit[1].trim();
|
||||
|
||||
switch (option) {
|
||||
case "chance":
|
||||
//chance = Integer.parseInt(value);
|
||||
chance = Double.parseDouble(value);
|
||||
this.chance = Double.parseDouble(value);
|
||||
break;
|
||||
case "display-item":
|
||||
displayItem = Material.valueOf(value);
|
||||
this.displayItem = Material.valueOf(value);
|
||||
break;
|
||||
case "display-lore":
|
||||
displayLore = value;
|
||||
this.displayLore = value;
|
||||
break;
|
||||
case "display-name":
|
||||
displayName = value;
|
||||
this.displayName = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -102,42 +111,51 @@ public class KitItem implements Cloneable {
|
||||
|
||||
private ItemStack compileOptions(ItemStack item) {
|
||||
NBTItem nbtItem = new NBTItem(item);
|
||||
if (chance != 0)
|
||||
nbtItem.setDouble("chance", chance);
|
||||
if (displayItem != null)
|
||||
nbtItem.setString("display-item", displayItem.name());
|
||||
if (displayName != null)
|
||||
nbtItem.setString("display-name", displayName);
|
||||
if (displayLore != null)
|
||||
nbtItem.setString("display-lore", displayLore);
|
||||
if (this.chance != 0) {
|
||||
nbtItem.setDouble("chance", this.chance);
|
||||
}
|
||||
if (this.displayItem != null) {
|
||||
nbtItem.setString("display-item", this.displayItem.name());
|
||||
}
|
||||
if (this.displayName != null) {
|
||||
nbtItem.setString("display-name", this.displayName);
|
||||
}
|
||||
if (this.displayLore != null) {
|
||||
nbtItem.setString("display-lore", this.displayLore);
|
||||
}
|
||||
return nbtItem.getItem();
|
||||
}
|
||||
|
||||
private String compileOptionsText() {
|
||||
String line = "";
|
||||
if (chance != 0)
|
||||
line += "chance:" + chance;
|
||||
if (displayItem != null)
|
||||
line += "~display-item:" + displayItem;
|
||||
if (displayName != null)
|
||||
line += "~display-name:" + displayName;
|
||||
if (displayLore != null)
|
||||
line += "~display-lore:" + displayLore;
|
||||
if (this.chance != 0) {
|
||||
line += "chance:" + this.chance;
|
||||
}
|
||||
if (this.displayItem != null) {
|
||||
line += "~display-item:" + this.displayItem;
|
||||
}
|
||||
if (this.displayName != null) {
|
||||
line += "~display-name:" + this.displayName;
|
||||
}
|
||||
if (this.displayLore != null) {
|
||||
line += "~display-lore:" + this.displayLore;
|
||||
}
|
||||
return line.trim();
|
||||
}
|
||||
|
||||
public KitContent getContent() {
|
||||
return content;
|
||||
return this.content;
|
||||
}
|
||||
|
||||
public String getSerialized() {
|
||||
if (chance == 0 && displayItem == null && displayName == null && displayLore == null)
|
||||
if (this.chance == 0 && this.displayItem == null && this.displayName == null && this.displayLore == null) {
|
||||
return this.content.getSerialized();
|
||||
}
|
||||
return compileOptionsText() + ";" + this.content.getSerialized();
|
||||
}
|
||||
|
||||
public double getChance() {
|
||||
return chance == 0 ? 100 : chance;
|
||||
return this.chance == 0 ? 100 : this.chance;
|
||||
}
|
||||
|
||||
public void setChance(double chance) {
|
||||
@ -145,7 +163,7 @@ public class KitItem implements Cloneable {
|
||||
}
|
||||
|
||||
public Material getDisplayItem() {
|
||||
return displayItem;
|
||||
return this.displayItem;
|
||||
}
|
||||
|
||||
public void setDisplayItem(Material displayItem) {
|
||||
@ -153,7 +171,7 @@ public class KitItem implements Cloneable {
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
return this.displayName;
|
||||
}
|
||||
|
||||
public void setDisplayName(String displayName) {
|
||||
@ -161,7 +179,7 @@ public class KitItem implements Cloneable {
|
||||
}
|
||||
|
||||
public String getDisplayLore() {
|
||||
return displayLore;
|
||||
return this.displayLore;
|
||||
}
|
||||
|
||||
public void setDisplayLore(String displayLore) {
|
||||
@ -169,48 +187,56 @@ public class KitItem implements Cloneable {
|
||||
}
|
||||
|
||||
public ItemStack getItem() {
|
||||
return content.getItemForDisplay();
|
||||
return this.content.getItemForDisplay();
|
||||
}
|
||||
|
||||
public ItemStack getMoveableItem() {
|
||||
if (content == null) return null;
|
||||
ItemStack item = content.getItemForDisplay().clone();
|
||||
if (this.content == null) {
|
||||
return null;
|
||||
}
|
||||
ItemStack item = this.content.getItemForDisplay().clone();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
List<String> lore = meta.hasLore() && meta.getLore().get(0).equals(TextUtils.formatText("&8&oMoveable"))
|
||||
? new ArrayList<>() : new ArrayList<>(Collections.singletonList(TextUtils.formatText("&8&oMoveable")));
|
||||
if (meta.hasLore())
|
||||
if (meta.hasLore()) {
|
||||
lore.addAll(meta.getLore());
|
||||
}
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
return compileOptions(item);
|
||||
}
|
||||
|
||||
public ItemStack getItemForDisplay() {
|
||||
if (content == null) return null;
|
||||
ItemStack item = content.getItemForDisplay();
|
||||
if (this.content == null) {
|
||||
return null;
|
||||
}
|
||||
ItemStack item = this.content.getItemForDisplay();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
if (displayItem != null) {
|
||||
item.setType(displayItem);
|
||||
if (this.displayItem != null) {
|
||||
item.setType(this.displayItem);
|
||||
meta = item.getItemMeta();
|
||||
}
|
||||
if (meta != null) {
|
||||
if (displayName != null) {
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', displayName));
|
||||
if (this.displayName != null) {
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', this.displayName));
|
||||
}
|
||||
if (displayLore != null) {
|
||||
meta.setLore(Collections.singletonList(ChatColor.translateAlternateColorCodes('&', displayLore)));
|
||||
if (this.displayLore != null) {
|
||||
meta.setLore(Collections.singletonList(ChatColor.translateAlternateColorCodes('&', this.displayLore)));
|
||||
}
|
||||
|
||||
if (UltimateKits.getInstance().getConfig().getBoolean("Main.Display Chance In Preview")) {
|
||||
ArrayDeque<String> lore;
|
||||
if (meta.hasLore())
|
||||
if (meta.hasLore()) {
|
||||
lore = new ArrayDeque<>(meta.getLore());
|
||||
else
|
||||
} else {
|
||||
lore = new ArrayDeque<>();
|
||||
}
|
||||
|
||||
if (!lore.isEmpty()) lore.addFirst("");
|
||||
lore.addFirst(ChatColor.GRAY.toString() + UltimateKits.getInstance().getLocale().getMessage("general.type.chance").getMessage() + ": " + ChatColor.GOLD + (chance == 0 ? 100 : chance) + "%");
|
||||
if (!lore.isEmpty()) {
|
||||
lore.addFirst("");
|
||||
}
|
||||
lore.addFirst(ChatColor.GRAY + UltimateKits.getInstance().getLocale().getMessage("general.type.chance").getMessage() + ": " + ChatColor.GOLD + (this.chance == 0 ? 100 : this.chance) + "%");
|
||||
meta.setLore(new ArrayList<>(lore));
|
||||
}
|
||||
|
||||
@ -220,7 +246,7 @@ public class KitItem implements Cloneable {
|
||||
}
|
||||
|
||||
public KitItemType getType() {
|
||||
return type;
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public KitItem clone() throws CloneNotSupportedException {
|
||||
@ -230,12 +256,11 @@ public class KitItem implements Cloneable {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "KitItem:{"
|
||||
+ "Item:\"" + content.getSerialized() + "\","
|
||||
+ "Chance:" + chance + "\","
|
||||
+ "Display Item:" + displayItem + "\","
|
||||
+ "Display Name:" + displayName + "\","
|
||||
+ "Display Lore:" + displayLore
|
||||
+ "Item:\"" + this.content.getSerialized() + "\","
|
||||
+ "Chance:" + this.chance + "\","
|
||||
+ "Display Item:" + this.displayItem + "\","
|
||||
+ "Display Name:" + this.displayName + "\","
|
||||
+ "Display Lore:" + this.displayLore
|
||||
+ "}";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.craftaro.ultimatekits.kit;
|
||||
|
||||
public enum KitItemType {
|
||||
|
||||
ITEM, ECONOMY, COMMAND
|
||||
|
||||
}
|
||||
|
@ -11,75 +11,79 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public final class KitManager {
|
||||
|
||||
private final Map<Location, KitBlockData> kitsAtLocations = new HashMap<>();
|
||||
private final List<Kit> registeredKits = new LinkedList<>();
|
||||
private boolean hasOrderChanged = false;
|
||||
|
||||
public Kit addKit(Kit kit) {
|
||||
if (kit == null) return null;
|
||||
registeredKits.add(kit);
|
||||
if (kit == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
this.registeredKits.add(kit);
|
||||
return kit;
|
||||
}
|
||||
|
||||
public void removeKit(Kit kit) {
|
||||
registeredKits.remove(kit);
|
||||
this.registeredKits.remove(kit);
|
||||
removeLocationsFromKit(kit);
|
||||
}
|
||||
|
||||
public void removeLocationsFromKit(Kit kit) {
|
||||
for (Map.Entry<Location, KitBlockData> entry : new ArrayList<>(kitsAtLocations.entrySet())) {
|
||||
for (Map.Entry<Location, KitBlockData> entry : new ArrayList<>(this.kitsAtLocations.entrySet())) {
|
||||
if (entry.getValue().getKit() == kit) {
|
||||
entry.getValue().reset();
|
||||
kitsAtLocations.remove(entry.getKey());
|
||||
this.kitsAtLocations.remove(entry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public KitBlockData addKitToLocation(Kit kit, Location location) {
|
||||
KitBlockData data = new KitBlockData(kit, location);
|
||||
kitsAtLocations.put(roundLocation(location), data);
|
||||
this.kitsAtLocations.put(roundLocation(location), data);
|
||||
return data;
|
||||
}
|
||||
|
||||
public KitBlockData addKitToLocation(Kit kit, Location location, KitType type, boolean hologram, boolean particles, boolean items, boolean itemOverride) {
|
||||
KitBlockData data = new KitBlockData(kit, location, type, hologram, particles, items, itemOverride);
|
||||
kitsAtLocations.put(roundLocation(location), data);
|
||||
this.kitsAtLocations.put(roundLocation(location), data);
|
||||
return data;
|
||||
}
|
||||
|
||||
public Kit removeKitFromLocation(Location location) {
|
||||
KitBlockData kit = getKit(roundLocation(location));
|
||||
|
||||
if (kit == null) return null;
|
||||
if (kit == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
kit.reset();
|
||||
|
||||
KitBlockData removed = kitsAtLocations.remove(roundLocation(location));
|
||||
KitBlockData removed = this.kitsAtLocations.remove(roundLocation(location));
|
||||
UltimateKits.getInstance().getKitDataManager().deleteBlockData(removed);
|
||||
return (removed != null ? removed.getKit() : null);
|
||||
}
|
||||
|
||||
public Kit getKit(String name) {
|
||||
return registeredKits.stream().filter(kit -> kit.getKey().equalsIgnoreCase(name.trim()))
|
||||
return this.registeredKits.stream().filter(kit -> kit.getKey().equalsIgnoreCase(name.trim()))
|
||||
.findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public KitBlockData getKit(Location location) {
|
||||
return kitsAtLocations.get(roundLocation(location));
|
||||
return this.kitsAtLocations.get(roundLocation(location));
|
||||
}
|
||||
|
||||
public List<Kit> getKits() {
|
||||
return Collections.unmodifiableList(registeredKits);
|
||||
return Collections.unmodifiableList(this.registeredKits);
|
||||
}
|
||||
|
||||
public Map<Location, KitBlockData> getKitLocations() {
|
||||
return Collections.unmodifiableMap(kitsAtLocations);
|
||||
return Collections.unmodifiableMap(this.kitsAtLocations);
|
||||
}
|
||||
|
||||
public void setKitLocations(Map<Location, KitBlockData> kits) {
|
||||
kitsAtLocations.clear();
|
||||
kitsAtLocations.putAll(kits);
|
||||
this.kitsAtLocations.clear();
|
||||
this.kitsAtLocations.putAll(kits);
|
||||
}
|
||||
|
||||
public void clearKits() {
|
||||
@ -96,28 +100,34 @@ public final class KitManager {
|
||||
}
|
||||
|
||||
public void moveKit(Kit kit, boolean up) {
|
||||
if (kit == null) return;
|
||||
if (kit == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (Kit kit2 : registeredKits) {
|
||||
if (kit == kit2)
|
||||
for (Kit kit2 : this.registeredKits) {
|
||||
if (kit == kit2) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
int action = i - 1;
|
||||
if (up) action = i + 1;
|
||||
if (up) {
|
||||
action = i + 1;
|
||||
}
|
||||
|
||||
if (action >= 0 && action < registeredKits.size())
|
||||
Collections.swap(registeredKits, i, action);
|
||||
hasOrderChanged = true;
|
||||
if (action >= 0 && action < this.registeredKits.size()) {
|
||||
Collections.swap(this.registeredKits, i, action);
|
||||
}
|
||||
this.hasOrderChanged = true;
|
||||
}
|
||||
|
||||
public boolean hasOrderChanged() {
|
||||
return hasOrderChanged;
|
||||
return this.hasOrderChanged;
|
||||
}
|
||||
|
||||
public void savedOrderChange() {
|
||||
hasOrderChanged = false;
|
||||
this.hasOrderChanged = false;
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,16 @@
|
||||
package com.craftaro.ultimatekits.kit;
|
||||
|
||||
public enum KitType {
|
||||
|
||||
PREVIEW, CRATE, CLAIM;
|
||||
|
||||
public static KitType getKitType(String search) {
|
||||
if (search != null) {
|
||||
for (KitType t : values()) {
|
||||
if (t.name().equalsIgnoreCase(search)) {
|
||||
return t;
|
||||
}
|
||||
if (search == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (KitType t : values()) {
|
||||
if (t.name().equalsIgnoreCase(search)) {
|
||||
return t;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -4,11 +4,9 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface KitContent {
|
||||
|
||||
String getSerialized();
|
||||
|
||||
ItemStack getItemForDisplay();
|
||||
|
||||
ItemStack process(Player player);
|
||||
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class KitContentCommand implements KitContent {
|
||||
|
||||
private final String command; // Stored like "eco give <player> 100"
|
||||
|
||||
public KitContentCommand(String command) {
|
||||
@ -19,12 +18,12 @@ public class KitContentCommand implements KitContent {
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return command;
|
||||
return this.command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSerialized() {
|
||||
return "/" + command;
|
||||
return "/" + this.command;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -33,8 +32,8 @@ public class KitContentCommand implements KitContent {
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
int index = 0;
|
||||
while (index < command.length()) {
|
||||
lore.add(ChatColor.GREEN + (index == 0 ? "/" : "") + ChatColor.GREEN + command.substring(index, Math.min(index + 30, command.length())));
|
||||
while (index < this.command.length()) {
|
||||
lore.add(ChatColor.GREEN + (index == 0 ? "/" : "") + ChatColor.GREEN + this.command.substring(index, Math.min(index + 30, this.command.length())));
|
||||
index += 30;
|
||||
}
|
||||
meta.setLore(lore);
|
||||
@ -45,7 +44,7 @@ public class KitContentCommand implements KitContent {
|
||||
|
||||
@Override
|
||||
public ItemStack process(Player player) {
|
||||
String parsed = command;
|
||||
String parsed = this.command;
|
||||
parsed = parsed.replace("{player}", player.getName());
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), parsed);
|
||||
return null;
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.craftaro.ultimatekits.kit.type;
|
||||
|
||||
import com.craftaro.core.hooks.EconomyManager;
|
||||
import com.craftaro.core.utils.NumberUtils;
|
||||
import com.craftaro.ultimatekits.UltimateKits;
|
||||
import com.craftaro.ultimatekits.utils.Methods;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -12,7 +12,6 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class KitContentEconomy implements KitContent {
|
||||
|
||||
private final double amount;
|
||||
|
||||
public KitContentEconomy(double amount) {
|
||||
@ -20,12 +19,12 @@ public class KitContentEconomy implements KitContent {
|
||||
}
|
||||
|
||||
public double getAmount() {
|
||||
return amount;
|
||||
return this.amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSerialized() {
|
||||
return UltimateKits.getInstance().getConfig().getString("Main.Currency Symbol") + amount;
|
||||
return UltimateKits.getInstance().getConfig().getString("Main.Currency Symbol") + this.amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -36,8 +35,8 @@ public class KitContentEconomy implements KitContent {
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
|
||||
int index = 0;
|
||||
while (index < String.valueOf(amount).length()) {
|
||||
lore.add(ChatColor.GREEN + (index == 0 ? UltimateKits.getInstance().getConfig().getString("Main.Currency Symbol") : "") + ChatColor.GREEN + String.valueOf(amount).substring(index, Math.min(index + 30, String.valueOf(amount).length())));
|
||||
while (index < String.valueOf(this.amount).length()) {
|
||||
lore.add(ChatColor.GREEN + (index == 0 ? UltimateKits.getInstance().getConfig().getString("Main.Currency Symbol") : "") + ChatColor.GREEN + String.valueOf(this.amount).substring(index, Math.min(index + 30, String.valueOf(this.amount).length())));
|
||||
index += 30;
|
||||
}
|
||||
meta.setLore(lore);
|
||||
@ -49,9 +48,9 @@ public class KitContentEconomy implements KitContent {
|
||||
@Override
|
||||
public ItemStack process(Player player) {
|
||||
try {
|
||||
EconomyManager.deposit(player, amount);
|
||||
EconomyManager.deposit(player, this.amount);
|
||||
UltimateKits.getInstance().getLocale().getMessage("event.claim.eco")
|
||||
.processPlaceholder("amt", Methods.formatEconomy(amount))
|
||||
.processPlaceholder("amt", NumberUtils.formatNumber(this.amount))
|
||||
.sendPrefixedMessage(player);
|
||||
} catch (NumberFormatException ex) {
|
||||
ex.printStackTrace();
|
||||
|
@ -9,7 +9,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class KitContentItem implements KitContent {
|
||||
|
||||
private final ItemStack itemStack;
|
||||
|
||||
private String serialized = null;
|
||||
@ -19,24 +18,27 @@ public class KitContentItem implements KitContent {
|
||||
}
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
return itemStack;
|
||||
return this.itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSerialized() {
|
||||
if (serialized != null) return serialized;
|
||||
serialized = ItemSerializer.serializeItemStackToJson(itemStack);
|
||||
return serialized;
|
||||
if (this.serialized != null) {
|
||||
return this.serialized;
|
||||
}
|
||||
|
||||
this.serialized = ItemSerializer.serializeItemStackToJson(this.itemStack);
|
||||
return this.serialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemForDisplay() {
|
||||
return itemStack.clone();
|
||||
return this.itemStack.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack process(Player player) {
|
||||
ItemStack parseStack = itemStack;
|
||||
ItemStack parseStack = this.itemStack;
|
||||
|
||||
if (parseStack.hasItemMeta() && parseStack.getItemMeta().hasLore()) {
|
||||
ItemMeta meta = parseStack.getItemMeta();
|
||||
|
@ -14,11 +14,7 @@ import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/24/2017.
|
||||
*/
|
||||
public class BlockListeners implements Listener {
|
||||
|
||||
private final UltimateKits plugin;
|
||||
|
||||
public BlockListeners(UltimateKits plugin) {
|
||||
@ -28,30 +24,33 @@ public class BlockListeners implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
Block block = event.getBlock();
|
||||
KitBlockData kitBlockData = plugin.getKitManager().getKit(block.getLocation());
|
||||
if (kitBlockData == null) return;
|
||||
KitBlockData kitBlockData = this.plugin.getKitManager().getKit(block.getLocation());
|
||||
if (kitBlockData == null) {
|
||||
return;
|
||||
}
|
||||
Kit kit = kitBlockData.getKit();
|
||||
|
||||
plugin.removeHologram(kitBlockData);
|
||||
this.plugin.removeHologram(kitBlockData);
|
||||
|
||||
plugin.getKitManager().removeKitFromLocation(block.getLocation());
|
||||
this.plugin.getKitManager().removeKitFromLocation(block.getLocation());
|
||||
|
||||
plugin.getLocale().newMessage("&8Kit &9" + kit.getKey() + " &8unassigned from: &a" + block.getType() + "&8.")
|
||||
this.plugin.getLocale().newMessage("&8Kit &9" + kit.getKey() + " &8unassigned from: &a" + block.getType() + "&8.")
|
||||
.sendPrefixedMessage(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockPlace(BlockPlaceEvent e) {
|
||||
Block block = e.getBlockAgainst();
|
||||
KitBlockData kitBlockData = plugin.getKitManager().getKit(block.getLocation());
|
||||
KitBlockData kitBlockData = this.plugin.getKitManager().getKit(block.getLocation());
|
||||
if (kitBlockData != null) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
ItemStack item = e.getItemInHand();
|
||||
if (item.getType() == Material.TRIPWIRE_HOOK && item.hasItemMeta() && item.getItemMeta().hasDisplayName()) {
|
||||
Key key = plugin.getKeyManager().getKey(ChatColor.stripColor(item.getItemMeta().getLore().get(0)).replace(" Key", ""));
|
||||
if (key != null)
|
||||
Key key = this.plugin.getKeyManager().getKey(ChatColor.stripColor(item.getItemMeta().getLore().get(0)).replace(" Key", ""));
|
||||
if (key != null) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,15 +4,11 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/24/2017.
|
||||
*/
|
||||
public class ChatListeners implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onCommandPreprocess(AsyncPlayerChatEvent event) {
|
||||
if (event.getMessage().equalsIgnoreCase("/kit") || event.getMessage().equalsIgnoreCase("/kit")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,11 +6,7 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/24/2017.
|
||||
*/
|
||||
public class ChunkListeners implements Listener {
|
||||
|
||||
private final UltimateKits plugin;
|
||||
|
||||
public ChunkListeners(UltimateKits plugin) {
|
||||
@ -19,10 +15,10 @@ public class ChunkListeners implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onChunkLoad(ChunkLoadEvent event) {
|
||||
plugin.getKitManager().getKitLocations().values().stream()
|
||||
this.plugin.getKitManager().getKitLocations().values().stream()
|
||||
.filter(l -> l.getLocation().getWorld() == event.getWorld()
|
||||
&& l.getLocation().getBlockX() >> 4 == event.getChunk().getX()
|
||||
&& l.getLocation().getBlockZ() >> 4 == event.getChunk().getZ())
|
||||
.forEach(plugin::updateHologram);
|
||||
.forEach(this.plugin::updateHologram);
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
||||
|
||||
public class EntityListeners implements Listener {
|
||||
|
||||
private final UltimateKits plugin;
|
||||
|
||||
public EntityListeners(UltimateKits plugin) {
|
||||
@ -21,12 +20,12 @@ public class EntityListeners implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerEntityInteract(EntityDamageEvent event) {
|
||||
if (event.getEntity().getType() != EntityType.ARMOR_STAND || plugin.getConfig().getString("data.hologramHandler") == null) {
|
||||
if (event.getEntity().getType() != EntityType.ARMOR_STAND || this.plugin.getConfig().getString("data.hologramHandler") == null) {
|
||||
return;
|
||||
}
|
||||
ConfigurationSection section = plugin.getConfig().getConfigurationSection("data.hologramHandler");
|
||||
ConfigurationSection section = this.plugin.getConfig().getConfigurationSection("data.hologramHandler");
|
||||
for (String loc : section.getKeys(false)) {
|
||||
String str[] = loc.split(":");
|
||||
String[] str = loc.split(":");
|
||||
World world = Bukkit.getServer().getWorld(str[1].substring(0, str[1].length() - 1));
|
||||
double x = Double.parseDouble(str[2].substring(0, str[2].length() - 1)) + .5;
|
||||
double z = Double.parseDouble(str[4]) + .5;
|
||||
@ -38,12 +37,13 @@ public class EntityListeners implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerEntityInteract(PlayerInteractAtEntityEvent event) {
|
||||
if (event.getRightClicked().getType() != EntityType.ARMOR_STAND || plugin.getConfig().getString("data.hologramHandler") == null) {
|
||||
if (event.getRightClicked().getType() != EntityType.ARMOR_STAND || this.plugin.getConfig().getString("data.hologramHandler") == null) {
|
||||
return;
|
||||
}
|
||||
ConfigurationSection section = plugin.getConfig().getConfigurationSection("data.hologramHandler");
|
||||
|
||||
ConfigurationSection section = this.plugin.getConfig().getConfigurationSection("data.hologramHandler");
|
||||
for (String loc : section.getKeys(false)) {
|
||||
String str[] = loc.split(":");
|
||||
String[] str = loc.split(":");
|
||||
World w = Bukkit.getServer().getWorld(str[1].substring(0, str[1].length() - 1));
|
||||
double x = Double.parseDouble(str[2].substring(0, str[2].length() - 1)) + .5;
|
||||
double z = Double.parseDouble(str[4]) + .5;
|
||||
|
@ -4,12 +4,12 @@ import com.craftaro.core.compatibility.CompatibleHand;
|
||||
import com.craftaro.core.compatibility.ServerVersion;
|
||||
import com.craftaro.core.gui.GuiManager;
|
||||
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.core.utils.TimeUtils;
|
||||
import com.craftaro.ultimatekits.UltimateKits;
|
||||
import com.craftaro.ultimatekits.gui.BlockEditorGui;
|
||||
import com.craftaro.ultimatekits.kit.Kit;
|
||||
import com.craftaro.ultimatekits.kit.KitBlockData;
|
||||
import com.craftaro.ultimatekits.kit.KitType;
|
||||
import com.craftaro.ultimatekits.utils.Methods;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -34,23 +34,30 @@ public class InteractListeners implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onBlockInteract(PlayerInteractEvent event) {
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9))
|
||||
if (event.getHand() == EquipmentSlot.OFF_HAND) return;
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9)) {
|
||||
if (event.getHand() == EquipmentSlot.OFF_HAND) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Block block = event.getClickedBlock();
|
||||
if (block == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getClickedBlock() == null) return;
|
||||
|
||||
KitBlockData kitBlockData = plugin.getKitManager().getKit(block.getLocation());
|
||||
|
||||
if (kitBlockData == null) return;
|
||||
KitBlockData kitBlockData = this.plugin.getKitManager().getKit(block.getLocation());
|
||||
if (kitBlockData == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Kit kit = kitBlockData.getKit();
|
||||
|
||||
Player player = event.getPlayer();
|
||||
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
|
||||
if (player.isSneaking()) return;
|
||||
if (player.isSneaking()) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
|
||||
if (player.getItemInHand().getType() == Material.TRIPWIRE_HOOK) {
|
||||
@ -61,7 +68,7 @@ public class InteractListeners implements Listener {
|
||||
|
||||
if (kitBlockData.getType() != KitType.PREVIEW) {
|
||||
if (!kit.hasPermissionToClaim(player)) {
|
||||
plugin.getLocale().getMessage("command.general.noperms").sendPrefixedMessage(player);
|
||||
this.plugin.getLocale().getMessage("command.general.noperms").sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
if (kit.getNextUse(player) <= 0) {
|
||||
@ -69,20 +76,23 @@ public class InteractListeners implements Listener {
|
||||
kit.updateDelay(player);
|
||||
} else {
|
||||
long time = kit.getNextUse(player);
|
||||
plugin.getLocale().getMessage("event.crate.notyet").processPlaceholder("time",
|
||||
Methods.makeReadable(time)).sendPrefixedMessage(player);
|
||||
this.plugin
|
||||
.getLocale()
|
||||
.getMessage("event.crate.notyet")
|
||||
.processPlaceholder("time", TimeUtils.makeReadable(time))
|
||||
.sendPrefixedMessage(player);
|
||||
}
|
||||
} else if (kit.getLink() != null || kit.getPrice() != 0) {
|
||||
kit.buy(player, guiManager);
|
||||
kit.buy(player, this.guiManager);
|
||||
} else {
|
||||
kit.display(player, guiManager, null);
|
||||
kit.display(player, this.guiManager, null);
|
||||
}
|
||||
} else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
if (block.getState() instanceof InventoryHolder || block.getType() == Material.ENDER_CHEST) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
if (player.isSneaking() && player.hasPermission("ultimatekits.admin")) {
|
||||
guiManager.showGUI(player, new BlockEditorGui(plugin, kitBlockData));
|
||||
this.guiManager.showGUI(player, new BlockEditorGui(this.plugin, kitBlockData));
|
||||
return;
|
||||
}
|
||||
if (player.getItemInHand().getType() == Material.TRIPWIRE_HOOK) {
|
||||
@ -90,7 +100,7 @@ public class InteractListeners implements Listener {
|
||||
kit.processKeyUse(player);
|
||||
return;
|
||||
}
|
||||
kit.display(player, guiManager, null);
|
||||
kit.display(player, this.guiManager, null);
|
||||
|
||||
}
|
||||
}
|
||||
@ -104,17 +114,22 @@ public class InteractListeners implements Listener {
|
||||
if (event.getAction() == Action.PHYSICAL
|
||||
|| event.getItem() == null
|
||||
|| event.getItem().getType() == XMaterial.AIR.parseMaterial()
|
||||
|| XMaterial.matchXMaterial(event.getItem()) != XMaterial.CHEST)
|
||||
|| XMaterial.matchXMaterial(event.getItem()) != XMaterial.CHEST) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack item = event.getItem();
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (!item.hasItemMeta() || !item.getItemMeta().hasLore() || item.getItemMeta().getLore().size() == 0) return;
|
||||
if (!item.hasItemMeta() || !item.getItemMeta().hasLore() || item.getItemMeta().getLore().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Kit kit = UltimateKits.getInstance().getKitManager().getKit(ChatColor.stripColor(item.getItemMeta().getLore().get(0).split(" ")[0]));
|
||||
|
||||
if (kit == null) return;
|
||||
if (kit == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
@ -123,6 +138,8 @@ public class InteractListeners implements Listener {
|
||||
// Open the crate
|
||||
kit.processCrateUse(player, item, CompatibleHand.getHand(event));
|
||||
} else // There are only left click actions left
|
||||
kit.display(player, guiManager, null);
|
||||
{
|
||||
kit.display(player, this.guiManager, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,23 +8,25 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class PlayerListeners implements Listener {
|
||||
|
||||
private final UltimateKits plugin;
|
||||
|
||||
public PlayerListeners() {
|
||||
plugin = UltimateKits.getInstance();
|
||||
public PlayerListeners(UltimateKits plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player.hasPlayedBefore()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.hasPlayedBefore()) return;
|
||||
|
||||
if (plugin.getKitManager().getKit(Settings.STARTER_KIT.getString()) == null
|
||||
if (this.plugin.getKitManager().getKit(Settings.STARTER_KIT.getString()) == null
|
||||
|| Settings.STARTER_KIT.getString() == null
|
||||
|| Settings.STARTER_KIT.getString().equalsIgnoreCase("none")) return;
|
||||
|| Settings.STARTER_KIT.getString().equalsIgnoreCase("none")) {
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getKitManager().getKit(Settings.STARTER_KIT.getString()).giveKit(player);
|
||||
this.plugin.getKitManager().getKit(Settings.STARTER_KIT.getString()).giveKit(player);
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Settings {
|
||||
|
||||
static final Config config = UltimateKits.getInstance().getCoreConfig();
|
||||
|
||||
public static final ConfigSetting DONT_PREVIEW_COMMANDS = new ConfigSetting(config, "Main.Dont Preview Commands In Kits", false);
|
||||
|
@ -5,7 +5,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public enum ArmorType {
|
||||
|
||||
LEATHER_BOOTS("Boots"),
|
||||
LEATHER_CHESTPLATE("Chestplate"),
|
||||
LEATHER_HELMET("Helmet"),
|
||||
@ -41,7 +40,7 @@ public enum ArmorType {
|
||||
ELYTRA("Chestplate"),
|
||||
SHIELD("OffHand");
|
||||
|
||||
String slot;
|
||||
final String slot;
|
||||
|
||||
ArmorType(String slot) {
|
||||
this.slot = slot;
|
||||
@ -49,51 +48,51 @@ public enum ArmorType {
|
||||
}
|
||||
|
||||
public boolean isHelmet() {
|
||||
return slot.equalsIgnoreCase("Helmet");
|
||||
return this.slot.equalsIgnoreCase("Helmet");
|
||||
}
|
||||
|
||||
public boolean isChestplate() {
|
||||
return slot.equalsIgnoreCase("Chestplate");
|
||||
return this.slot.equalsIgnoreCase("Chestplate");
|
||||
}
|
||||
|
||||
public boolean isLeggings() {
|
||||
return slot.equalsIgnoreCase("Leggings");
|
||||
return this.slot.equalsIgnoreCase("Leggings");
|
||||
}
|
||||
|
||||
public boolean isBoots() {
|
||||
return slot.equalsIgnoreCase("Boots");
|
||||
return this.slot.equalsIgnoreCase("Boots");
|
||||
}
|
||||
|
||||
public boolean isOffHand() {
|
||||
return slot.equalsIgnoreCase("OffHand");
|
||||
return this.slot.equalsIgnoreCase("OffHand");
|
||||
}
|
||||
|
||||
public static boolean equip(Player player, ItemStack item) {
|
||||
try {
|
||||
ArmorType type = ArmorType.valueOf(item.getType().toString());
|
||||
|
||||
boolean equipped = false;
|
||||
|
||||
if ((type.isHelmet() && player.getInventory().getHelmet() == null)
|
||||
boolean equipped = (type.isHelmet() && player.getInventory().getHelmet() == null)
|
||||
|| (type.isChestplate() && player.getInventory().getChestplate() == null)
|
||||
|| (type.isLeggings() && player.getInventory().getLeggings() == null)
|
||||
|| (type.isBoots() && player.getInventory().getBoots() == null)
|
||||
|| (type.isOffHand() && player.getInventory().getItemInOffHand().getType() == Material.AIR))
|
||||
equipped = true;
|
||||
|| (type.isOffHand() && player.getInventory().getItemInOffHand().getType() == Material.AIR);
|
||||
|
||||
if (type.isHelmet() && player.getInventory().getHelmet() == null)
|
||||
if (type.isHelmet() && player.getInventory().getHelmet() == null) {
|
||||
player.getInventory().setHelmet(item);
|
||||
if (type.isChestplate() && player.getInventory().getChestplate() == null)
|
||||
}
|
||||
if (type.isChestplate() && player.getInventory().getChestplate() == null) {
|
||||
player.getInventory().setChestplate(item);
|
||||
if (type.isLeggings() && player.getInventory().getLeggings() == null)
|
||||
}
|
||||
if (type.isLeggings() && player.getInventory().getLeggings() == null) {
|
||||
player.getInventory().setLeggings(item);
|
||||
if (type.isBoots() && player.getInventory().getBoots() == null)
|
||||
}
|
||||
if (type.isBoots() && player.getInventory().getBoots() == null) {
|
||||
player.getInventory().setBoots(item);
|
||||
if (type.isOffHand() && player.getInventory().getItemInOffHand().getType() == Material.AIR)
|
||||
}
|
||||
if (type.isOffHand() && player.getInventory().getItemInOffHand().getType() == Material.AIR) {
|
||||
player.getInventory().setItemInOffHand(item);
|
||||
}
|
||||
|
||||
return equipped;
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
|
@ -51,7 +51,6 @@ public class ItemSerializer {
|
||||
* Deserializes a JSON String
|
||||
*
|
||||
* @param jsonString the JSON String to parse
|
||||
*
|
||||
* @return the deserialized ItemStack
|
||||
*/
|
||||
public static ItemStack deserializeItemStackFromJson(String jsonString) {
|
||||
@ -79,7 +78,6 @@ public class ItemSerializer {
|
||||
* Serializes an item stack
|
||||
*
|
||||
* @param itemStack the ItemStack to parse
|
||||
*
|
||||
* @return condensed JSON String
|
||||
*/
|
||||
public static String serializeItemStackToJson(ItemStack itemStack) {
|
||||
|
@ -8,63 +8,17 @@ import com.craftaro.ultimatekits.settings.Settings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/24/2017.
|
||||
*/
|
||||
public class Methods {
|
||||
|
||||
private static final Random rand = new Random();
|
||||
|
||||
public static boolean canGiveKit(Player player) {
|
||||
if (player.hasPermission("ultimatekits.cangive")) return true;
|
||||
|
||||
if (player.hasPermission("essentials.kit.others")) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the location of the block specified.
|
||||
*
|
||||
* @param block The block whose location is to be saved.
|
||||
* @return The serialized data.
|
||||
*/
|
||||
public static String serializeLocation(Block block) {
|
||||
if (block == null)
|
||||
return "";
|
||||
return serializeLocation(block.getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the location specified.
|
||||
*
|
||||
* @param location The location that is to be saved.
|
||||
* @return The serialized data.
|
||||
*/
|
||||
public static String serializeLocation(Location location) {
|
||||
if (location == null || location.getWorld() == null)
|
||||
return null;
|
||||
String w = location.getWorld().getName();
|
||||
double x = location.getX();
|
||||
double y = location.getY();
|
||||
double z = location.getZ();
|
||||
String str = w + ":" + x + ":" + y + ":" + z;
|
||||
str = str.replace(".0", "").replace("/", "");
|
||||
return str;
|
||||
}
|
||||
|
||||
private static Map<String, Location> serializeCache = new HashMap<>();
|
||||
private static final Map<String, Location> serializeCache = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Deserializes a location from the string.
|
||||
@ -73,8 +27,9 @@ public class Methods {
|
||||
* @return The location that was serialized in the string.
|
||||
*/
|
||||
public static Location unserializeLocation(String str) {
|
||||
if (str == null || str.equals(""))
|
||||
if (str == null || str.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
if (serializeCache.containsKey(str)) {
|
||||
return serializeCache.get(str).clone();
|
||||
}
|
||||
@ -91,95 +46,7 @@ public class Methods {
|
||||
return location;
|
||||
}
|
||||
|
||||
public static String makeReadable(Long time) {
|
||||
if (time == null)
|
||||
return "1s";
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
long days = TimeUnit.MILLISECONDS.toDays(time);
|
||||
long hours = TimeUnit.MILLISECONDS.toHours(time) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(time));
|
||||
long minutes = TimeUnit.MILLISECONDS.toMinutes(time) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time));
|
||||
long seconds = TimeUnit.MILLISECONDS.toSeconds(time) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time));
|
||||
|
||||
if (days != 0L)
|
||||
sb.append(" ").append(days).append("d");
|
||||
if (hours != 0L)
|
||||
sb.append(" ").append(hours).append("h");
|
||||
if (minutes != 0L)
|
||||
sb.append(" ").append(minutes).append("m");
|
||||
if (seconds != 0L)
|
||||
sb.append(" ").append(seconds).append("s");
|
||||
if (sb.length() == 0)
|
||||
sb.append("1s");
|
||||
return sb.toString().trim();
|
||||
}
|
||||
|
||||
public static long parseTime(String input) {
|
||||
long result = 0;
|
||||
StringBuilder number = new StringBuilder();
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
char c = input.charAt(i);
|
||||
if (Character.isDigit(c)) {
|
||||
number.append(c);
|
||||
} else if (Character.isLetter(c) && (number.length() > 0)) {
|
||||
result += convert(Integer.parseInt(number.toString()), c);
|
||||
number = new StringBuilder();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static long convert(long value, char unit) {
|
||||
switch (unit) {
|
||||
case 'd':
|
||||
return value * 1000 * 60 * 60 * 24;
|
||||
case 'h':
|
||||
return value * 1000 * 60 * 60;
|
||||
case 'm':
|
||||
return value * 1000 * 60;
|
||||
case 's':
|
||||
return value * 1000;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the specified double into the Economy format specified in the Arconix config.
|
||||
*
|
||||
* @param amt The double to format.
|
||||
* @return The economy formatted double.
|
||||
*/
|
||||
public static String formatEconomy(double amt) {
|
||||
DecimalFormat formatter = new DecimalFormat("#,###.00");
|
||||
return formatter.format(amt);
|
||||
}
|
||||
|
||||
public static boolean isInt(String number) {
|
||||
if (number == null || number.equals(""))
|
||||
return false;
|
||||
try {
|
||||
Integer.parseInt(number);
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the provided string is a valid number (int, double, float, or otherwise).
|
||||
*
|
||||
* @param s The string to check.
|
||||
* @return <code>true</code> if the string is numeric, otherwise <code>false</code>
|
||||
*/
|
||||
public static boolean isNumeric(String s) {
|
||||
if (s == null || s.equals(""))
|
||||
return false;
|
||||
return s.matches("[-+]?\\d*\\.?\\d+");
|
||||
}
|
||||
|
||||
public static void fillGlass(Gui gui) {
|
||||
|
||||
// fill center with glass
|
||||
if (Settings.RAINBOW.getBoolean()) {
|
||||
for (int row = 0; row < gui.getRows(); ++row) {
|
||||
@ -197,11 +64,11 @@ public class Methods {
|
||||
|
||||
// edges will be type 3
|
||||
gui.mirrorFill(0, 2, true, true, glass3);
|
||||
gui.mirrorFill( 1, 1, false, true, glass3);
|
||||
gui.mirrorFill(1, 1, false, true, glass3);
|
||||
|
||||
// decorate corners with type 2
|
||||
gui.mirrorFill( 0, 0, true, true, glass2);
|
||||
gui.mirrorFill( 1, 0, true, true, glass2);
|
||||
gui.mirrorFill(0, 0, true, true, glass2);
|
||||
gui.mirrorFill(1, 0, true, true, glass2);
|
||||
gui.mirrorFill(0, 1, true, true, glass2);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user