mirror of
https://github.com/songoda/UltimateKits.git
synced 2024-09-29 22:27:35 +02:00
Start converting to core
This commit is contained in:
parent
63e6b8e090
commit
2213fa048b
@ -1,20 +1,23 @@
|
||||
package com.songoda.ultimatekits;
|
||||
|
||||
import com.songoda.ultimatekits.command.CommandManager;
|
||||
import com.songoda.core.SongodaCore;
|
||||
import com.songoda.core.SongodaPlugin;
|
||||
import com.songoda.core.commands.CommandManager;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.configuration.Config;
|
||||
import com.songoda.core.database.DataMigrationManager;
|
||||
import com.songoda.core.database.DatabaseConnector;
|
||||
import com.songoda.core.gui.GuiManager;
|
||||
import com.songoda.core.hooks.EconomyManager;
|
||||
import com.songoda.core.hooks.HologramManager;
|
||||
import com.songoda.ultimatekits.commands.*;
|
||||
import com.songoda.ultimatekits.conversion.Convert;
|
||||
import com.songoda.ultimatekits.database.DataManager;
|
||||
import com.songoda.ultimatekits.database.DataMigrationManager;
|
||||
import com.songoda.ultimatekits.database.DatabaseConnector;
|
||||
import com.songoda.ultimatekits.database.MySQLConnector;
|
||||
import com.songoda.ultimatekits.database.SQLiteConnector;
|
||||
import com.songoda.ultimatekits.economy.Economy;
|
||||
import com.songoda.ultimatekits.economy.PlayerPointsEconomy;
|
||||
import com.songoda.ultimatekits.economy.ReserveEconomy;
|
||||
import com.songoda.ultimatekits.economy.VaultEconomy;
|
||||
import com.songoda.ultimatekits.database.migrations._1_InitialMigration;
|
||||
import com.songoda.ultimatekits.handlers.DisplayItemHandler;
|
||||
import com.songoda.ultimatekits.handlers.ParticleHandler;
|
||||
import com.songoda.ultimatekits.hologram.Hologram;
|
||||
import com.songoda.ultimatekits.hologram.HologramHolographicDisplays;
|
||||
import com.songoda.ultimatekits.key.Key;
|
||||
import com.songoda.ultimatekits.key.KeyManager;
|
||||
import com.songoda.ultimatekits.kit.*;
|
||||
@ -23,45 +26,31 @@ import com.songoda.ultimatekits.listeners.ChatListeners;
|
||||
import com.songoda.ultimatekits.listeners.EntityListeners;
|
||||
import com.songoda.ultimatekits.listeners.InteractListeners;
|
||||
import com.songoda.ultimatekits.utils.*;
|
||||
import com.songoda.ultimatekits.utils.locale.Locale;
|
||||
import com.songoda.ultimatekits.utils.settings.Setting;
|
||||
import com.songoda.ultimatekits.utils.settings.SettingsManager;
|
||||
import com.songoda.ultimatekits.utils.updateModules.LocaleModule;
|
||||
import com.songoda.update.Plugin;
|
||||
import com.songoda.update.SongodaUpdate;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import com.songoda.ultimatekits.settings.Settings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class UltimateKits extends JavaPlugin {
|
||||
public class UltimateKits extends SongodaPlugin {
|
||||
private static UltimateKits INSTANCE;
|
||||
|
||||
private static CommandSender console = Bukkit.getConsoleSender();
|
||||
private final Config kitFile = new Config(this, "kit.yml");
|
||||
private final Config dataFile = new Config(this, "data.yml");
|
||||
private final Config keyFile = new Config(this, "keys.yml");
|
||||
|
||||
private final GuiManager guiManager = new GuiManager(this);
|
||||
private final ParticleHandler particleHandler = new ParticleHandler(this);
|
||||
private final DisplayItemHandler displayItemHandler = new DisplayItemHandler(this);
|
||||
|
||||
private Locale locale;
|
||||
|
||||
private ServerVersion serverVersion = ServerVersion.fromPackageName(Bukkit.getServer().getClass().getPackage().getName());
|
||||
|
||||
private ConfigWrapper kitFile = new ConfigWrapper(this, "", "kit.yml");
|
||||
private ConfigWrapper dataFile = new ConfigWrapper(this, "", "data.yml");
|
||||
private ConfigWrapper keyFile = new ConfigWrapper(this, "", "keys.yml");
|
||||
|
||||
private SettingsManager settingsManager;
|
||||
private KitManager kitManager;
|
||||
private CommandManager commandManager;
|
||||
private KeyManager keyManager;
|
||||
private DisplayItemHandler displayItemHandler;
|
||||
private Hologram hologram;
|
||||
private Economy economy;
|
||||
|
||||
private ItemSerializer itemSerializer;
|
||||
|
||||
@ -78,82 +67,74 @@ public class UltimateKits extends JavaPlugin {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/*
|
||||
* On plugin enable.
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
public void onPluginLoad() {
|
||||
INSTANCE = this;
|
||||
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
console.sendMessage(Methods.formatText("&7UltimateKits " + this.getDescription().getVersion() + " by &5Songoda <3!"));
|
||||
console.sendMessage(Methods.formatText("&7Action: &aEnabling&7..."));
|
||||
|
||||
try {
|
||||
this.itemSerializer = new ItemSerializer();
|
||||
} catch (NoSuchMethodException | SecurityException | ClassNotFoundException e) {
|
||||
console.sendMessage(Methods.formatText("&cCould not load the serialization class! Please report this error."));
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
this.settingsManager = new SettingsManager(this);
|
||||
this.settingsManager.setupConfig();
|
||||
@Override
|
||||
public void onPluginEnable() {
|
||||
SongodaCore.registerPlugin(this, 14, CompatibleMaterial.BEACON);
|
||||
|
||||
new Locale(this, "en_US");
|
||||
this.locale = Locale.getLocale(getConfig().getString("System.Language Mode"));
|
||||
// Load Economy
|
||||
EconomyManager.load();
|
||||
// Register Hologram Plugin
|
||||
HologramManager.load(this);
|
||||
|
||||
new Convert(this);
|
||||
// Setup Config
|
||||
Settings.setupConfig();
|
||||
this.setLocale(Settings.LANGUGE_MODE.getString(), false);
|
||||
|
||||
// Set economy preference
|
||||
EconomyManager.getManager().setPreferredHook(Settings.ECONOMY_PLUGIN.getString());
|
||||
|
||||
new ParticleHandler(this);
|
||||
this.displayItemHandler = new DisplayItemHandler(this);
|
||||
// load kits
|
||||
dataFile.load();
|
||||
checkKeyDefaults();
|
||||
loadKits();
|
||||
keyFile.saveChanges();
|
||||
|
||||
// setup commands
|
||||
this.commandManager = new CommandManager(this);
|
||||
|
||||
//Running Songoda Updater
|
||||
Plugin plugin = new Plugin(this, 14);
|
||||
plugin.addModule(new LocaleModule());
|
||||
SongodaUpdate.load(plugin);
|
||||
this.commandManager.addCommand(new CommandKit(guiManager));
|
||||
this.commandManager.addCommand(new CommandPreviewKit(guiManager));
|
||||
this.commandManager.addCommand(new CommandUltimateKits())
|
||||
.addSubCommand(new CommandReload())
|
||||
.addSubCommand(new CommandSettings(guiManager))
|
||||
.addSubCommand(new CommandCreatekit(guiManager))
|
||||
.addSubCommand(new CommandEdit(guiManager))
|
||||
.addSubCommand(new CommandKey())
|
||||
.addSubCommand(new CommandSet())
|
||||
.addSubCommand(new CommandRemove());
|
||||
|
||||
this.kitManager = new KitManager();
|
||||
this.keyManager = new KeyManager();
|
||||
this.commandManager = new CommandManager(this);
|
||||
|
||||
PluginManager pluginManager = getServer().getPluginManager();
|
||||
|
||||
// Setup Economy
|
||||
if (Setting.VAULT_ECONOMY.getBoolean() && pluginManager.isPluginEnabled("Vault"))
|
||||
this.economy = new VaultEconomy();
|
||||
else if (Setting.RESERVE_ECONOMY.getBoolean() && pluginManager.isPluginEnabled("Reserve"))
|
||||
this.economy = new ReserveEconomy();
|
||||
else if (Setting.PLAYER_POINTS_ECONOMY.getBoolean() && pluginManager.isPluginEnabled("PlayerPoints"))
|
||||
this.economy = new PlayerPointsEconomy();
|
||||
|
||||
// Register Hologram Plugin
|
||||
if (pluginManager.isPluginEnabled("HolographicDisplays"))
|
||||
hologram = new HologramHolographicDisplays(this);
|
||||
|
||||
Convert.runKitConversions();
|
||||
|
||||
// Event registration
|
||||
PluginManager pluginManager = getServer().getPluginManager();
|
||||
guiManager.init();
|
||||
pluginManager.registerEvents(new BlockListeners(this), this);
|
||||
pluginManager.registerEvents(new ChatListeners(this), this);
|
||||
pluginManager.registerEvents(new EntityListeners(this), this);
|
||||
pluginManager.registerEvents(new InteractListeners(this), this);
|
||||
|
||||
this.loadFromFile();
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this::saveToFile, 6000, 6000);
|
||||
|
||||
// Starting Metrics
|
||||
new Metrics(this);
|
||||
pluginManager.registerEvents(new InteractListeners(this, guiManager), this);
|
||||
|
||||
try {
|
||||
if (Setting.MYSQL_ENABLED.getBoolean()) {
|
||||
String hostname = Setting.MYSQL_HOSTNAME.getString();
|
||||
int port = Setting.MYSQL_PORT.getInt();
|
||||
String database = Setting.MYSQL_DATABASE.getString();
|
||||
String username = Setting.MYSQL_USERNAME.getString();
|
||||
String password = Setting.MYSQL_PASSWORD.getString();
|
||||
boolean useSSL = Setting.MYSQL_USE_SSL.getBoolean();
|
||||
if (Settings.MYSQL_ENABLED.getBoolean()) {
|
||||
String hostname = Settings.MYSQL_HOSTNAME.getString();
|
||||
int port = Settings.MYSQL_PORT.getInt();
|
||||
String database = Settings.MYSQL_DATABASE.getString();
|
||||
String username = Settings.MYSQL_USERNAME.getString();
|
||||
String password = Settings.MYSQL_PASSWORD.getString();
|
||||
boolean useSSL = Settings.MYSQL_USE_SSL.getBoolean();
|
||||
|
||||
this.databaseConnector = new MySQLConnector(this, hostname, port, database, username, password, useSSL);
|
||||
this.getLogger().info("Data handler connected using MySQL.");
|
||||
@ -161,46 +142,57 @@ public class UltimateKits extends JavaPlugin {
|
||||
this.databaseConnector = new SQLiteConnector(this);
|
||||
this.getLogger().info("Data handler connected using SQLite.");
|
||||
}
|
||||
|
||||
this.dataManager = new DataManager(this.databaseConnector, this);
|
||||
this.dataMigrationManager = new DataMigrationManager(this.databaseConnector, this.dataManager,
|
||||
new _1_InitialMigration());
|
||||
this.dataMigrationManager.runMigrations();
|
||||
|
||||
} catch (Exception ex) {
|
||||
this.getLogger().severe("Fatal error trying to connect to database. " +
|
||||
"Please make sure all your connection settings are correct and try again. Plugin has been disabled.");
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
emergencyStop();
|
||||
return;
|
||||
}
|
||||
|
||||
this.dataManager = new DataManager(this.databaseConnector, this);
|
||||
this.dataMigrationManager = new DataMigrationManager(this.databaseConnector, this.dataManager);
|
||||
this.dataMigrationManager.runMigrations();
|
||||
|
||||
displayItemHandler.start();
|
||||
particleHandler.start();
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this::saveKits, 6000, 6000);
|
||||
Bukkit.getScheduler().runTaskLater(this, () -> {
|
||||
this.dataManager.getBlockData((blockData) -> {
|
||||
this.kitManager.setKitLocations(blockData);
|
||||
kitManager.getKitLocations().forEach((location, data) -> {
|
||||
if (hologram != null) UltimateKits.getInstance().getHologram().add(data);
|
||||
});
|
||||
if(HologramManager.isEnabled()) {
|
||||
loadHolograms();
|
||||
}
|
||||
});
|
||||
}, 20L);
|
||||
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
}
|
||||
|
||||
/*
|
||||
* On plugin disable.
|
||||
*/
|
||||
public void onDisable() {
|
||||
saveToFile();
|
||||
dataFile.saveConfig();
|
||||
@Override
|
||||
public void onPluginDisable() {
|
||||
saveKits();
|
||||
dataFile.save();
|
||||
this.dataManager.bulkUpdateBlockData(this.getKitManager().getKitLocations());
|
||||
kitManager.clearKits();
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
console.sendMessage(Methods.formatText("&7UltimateKits " + this.getDescription().getVersion() + " by &5Songoda <3!"));
|
||||
console.sendMessage(Methods.formatText("&7Action: &cDisabling&7..."));
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
HologramManager.removeAllHolograms();
|
||||
}
|
||||
|
||||
/*
|
||||
* Load configuration files into memory.
|
||||
*/
|
||||
private void loadFromFile() {
|
||||
@Override
|
||||
public List<Config> getExtraConfig() {
|
||||
return Arrays.asList(kitFile, keyFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigReload() {
|
||||
this.setLocale(Settings.LANGUGE_MODE.getString(), true);
|
||||
|
||||
this.dataManager.bulkUpdateBlockData(this.getKitManager().getKitLocations());
|
||||
loadKits();
|
||||
}
|
||||
|
||||
void loadKits() {
|
||||
kitFile.load();
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(this, () -> {
|
||||
|
||||
//Empty kits from manager.
|
||||
@ -209,15 +201,15 @@ public class UltimateKits extends JavaPlugin {
|
||||
/*
|
||||
* Register kit into KitManager from Configuration.
|
||||
*/
|
||||
for (String kitName : kitFile.getConfig().getConfigurationSection("Kits").getKeys(false)) {
|
||||
int delay = kitFile.getConfig().getInt("Kits." + kitName + ".delay");
|
||||
String title = kitFile.getConfig().getString("Kits." + kitName + ".title");
|
||||
String link = kitFile.getConfig().getString("Kits." + kitName + ".link");
|
||||
Material material = kitFile.getConfig().contains("Kits." + kitName + ".displayItem") ? Material.valueOf(kitFile.getConfig().getString("Kits." + kitName + ".displayItem")) : null;
|
||||
boolean hidden = kitFile.getConfig().getBoolean("Kits." + kitName + ".hidden");
|
||||
double price = kitFile.getConfig().getDouble("Kits." + kitName + ".price");
|
||||
List<String> strContents = kitFile.getConfig().getStringList("Kits." + kitName + ".items");
|
||||
String kitAnimation = kitFile.getConfig().getString("Kits." + kitName + ".animation", KitAnimation.NONE.name());
|
||||
for (String kitName : kitFile.getConfigurationSection("Kits").getKeys(false)) {
|
||||
int delay = kitFile.getInt("Kits." + kitName + ".delay");
|
||||
String title = kitFile.getString("Kits." + kitName + ".title");
|
||||
String link = kitFile.getString("Kits." + kitName + ".link");
|
||||
Material material = kitFile.contains("Kits." + kitName + ".displayItem") ? Material.valueOf(kitFile.getString("Kits." + kitName + ".displayItem")) : null;
|
||||
boolean hidden = kitFile.getBoolean("Kits." + kitName + ".hidden");
|
||||
double price = kitFile.getDouble("Kits." + kitName + ".price");
|
||||
List<String> strContents = kitFile.getStringList("Kits." + kitName + ".items");
|
||||
String kitAnimation = kitFile.getString("Kits." + kitName + ".animation", KitAnimation.NONE.name());
|
||||
|
||||
List<KitItem> contents = new ArrayList<>();
|
||||
|
||||
@ -232,17 +224,17 @@ public class UltimateKits extends JavaPlugin {
|
||||
/*
|
||||
* Register kit locations into KitManager from Configuration.
|
||||
*/
|
||||
if (dataFile.getConfig().contains("BlockData")) {
|
||||
for (String key : dataFile.getConfig().getConfigurationSection("BlockData").getKeys(false)) {
|
||||
if (dataFile.contains("BlockData")) {
|
||||
for (String key : dataFile.getConfigurationSection("BlockData").getKeys(false)) {
|
||||
Location location = Methods.unserializeLocation(key);
|
||||
Kit kit = kitManager.getKit(dataFile.getConfig().getString("BlockData." + key + ".kit"));
|
||||
KitType type = KitType.valueOf(dataFile.getConfig().getString("BlockData." + key + ".type", "PREVIEW"));
|
||||
boolean holograms = dataFile.getConfig().getBoolean("BlockData." + key + ".holograms");
|
||||
boolean displayItems = dataFile.getConfig().getBoolean("BlockData." + key + ".displayItems");
|
||||
boolean particles = dataFile.getConfig().getBoolean("BlockData." + key + ".particles");
|
||||
boolean itemOverride = dataFile.getConfig().getBoolean("BlockData." + key + ".itemOverride");
|
||||
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");
|
||||
|
||||
if (kit == null) dataFile.getConfig().set("BlockData." + key, null);
|
||||
if (kit == null) dataFile.set("BlockData." + key, null);
|
||||
else
|
||||
kitManager.addKitToLocation(kit, location, type, holograms, particles, displayItems, itemOverride);
|
||||
}
|
||||
@ -257,104 +249,174 @@ public class UltimateKits extends JavaPlugin {
|
||||
/*
|
||||
* Register keys into KitManager from Configuration.
|
||||
*/
|
||||
if (keyFile.getConfig().contains("Keys")) {
|
||||
for (String keyName : keyFile.getConfig().getConfigurationSection("Keys").getKeys(false)) {
|
||||
int amt = keyFile.getConfig().getInt("Keys." + keyName + ".Item Amount");
|
||||
int kitAmount = keyFile.getConfig().getInt("Keys." + keyName + ".Amount of kit received");
|
||||
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");
|
||||
|
||||
Key key = new Key(keyName, amt, kitAmount);
|
||||
keyManager.addKey(key);
|
||||
}
|
||||
}
|
||||
|
||||
if (hologram != null)
|
||||
hologram.loadHolograms();
|
||||
|
||||
|
||||
}, 10);
|
||||
}
|
||||
|
||||
public ServerVersion getServerVersion() {
|
||||
return serverVersion;
|
||||
public void removeHologram(KitBlockData data) {
|
||||
if(HologramManager.isEnabled()) {
|
||||
Location location = getKitLocation(data, Settings.HOLOGRAM_LAYOUT.getStringList().size());
|
||||
HologramManager.removeHologram(location);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isServerVersion(ServerVersion version) {
|
||||
return serverVersion == version;
|
||||
public void updateHologram(KitBlockData data) {
|
||||
if (data != null && data.isInLoadedChunk() && HologramManager.isEnabled()) {
|
||||
List<String> lines = formatHologram(data);
|
||||
|
||||
if (!lines.isEmpty()) {
|
||||
Location location = getKitLocation(data, lines.size());
|
||||
if (!data.showHologram()) {
|
||||
HologramManager.removeHologram(location);
|
||||
} else {
|
||||
HologramManager.updateHologram(location, lines);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isServerVersion(ServerVersion... versions) {
|
||||
return ArrayUtils.contains(versions, serverVersion);
|
||||
private void loadHolograms() {
|
||||
Collection<KitBlockData> kitBlocks = getKitManager().getKitLocations().values();
|
||||
if (kitBlocks.isEmpty()) return;
|
||||
|
||||
for (KitBlockData data : kitBlocks) {
|
||||
updateHologram(data);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isServerVersionAtLeast(ServerVersion version) {
|
||||
return serverVersion.ordinal() >= version.ordinal();
|
||||
private Location getKitLocation(KitBlockData data, int lines) {
|
||||
Location location = data.getLocation();
|
||||
double multi = .25 * lines;
|
||||
if (data.isDisplayingItems()) {
|
||||
multi += .40;
|
||||
}
|
||||
Material type = location.getBlock().getType();
|
||||
if (type == Material.TRAPPED_CHEST
|
||||
|| type == Material.CHEST
|
||||
|| type.name().contains("SIGN")
|
||||
|| type == Material.ENDER_CHEST) {
|
||||
multi -= .15;
|
||||
}
|
||||
location.add(0, multi, 0);
|
||||
return location;
|
||||
}
|
||||
|
||||
private List<String> formatHologram(KitBlockData data) {
|
||||
getDataManager().updateBlockData(data);
|
||||
KitType kitType = data.getType();
|
||||
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
|
||||
List<String> order = Settings.HOLOGRAM_LAYOUT.getStringList();
|
||||
|
||||
Kit kit = data.getKit();
|
||||
|
||||
for (String o : order) {
|
||||
switch (o.toUpperCase()) {
|
||||
case "{TITLE}":
|
||||
String title = kit.getTitle();
|
||||
if (title == null) {
|
||||
lines.add(Methods.formatText("&5" + Methods.formatText(kit.getName(), true)));
|
||||
} else {
|
||||
lines.add(Methods.formatText("&5" + Methods.formatText(title)));
|
||||
}
|
||||
break;
|
||||
case "{RIGHT-CLICK}":
|
||||
if (kitType == KitType.CRATE) {
|
||||
lines.add(Methods.formatText(getLocale().getMessage("interface.hologram.crate")
|
||||
.getMessage()));
|
||||
break;
|
||||
}
|
||||
if (kit.getLink() != null) {
|
||||
lines.add(Methods.formatText(getLocale().getMessage("interface.hologram.buylink")
|
||||
.getMessage()));
|
||||
break;
|
||||
}
|
||||
if (kit.getPrice() != 0) {
|
||||
lines.add(Methods.formatText(getLocale().getMessage("interface.hologram.buyeco")
|
||||
.processPlaceholder("price", kit.getPrice() != 0
|
||||
? Methods.formatEconomy(kit.getPrice())
|
||||
: getLocale().getMessage("general.type.free").getMessage())
|
||||
.getMessage()));
|
||||
}
|
||||
break;
|
||||
case "{LEFT-CLICK}":
|
||||
if (kitType == KitType.CLAIM) {
|
||||
lines.add(Methods.formatText(getLocale().getMessage("interface.hologram.daily")
|
||||
.getMessage()));
|
||||
break;
|
||||
}
|
||||
if (kit.getLink() == null && kit.getPrice() == 0) {
|
||||
lines.add(Methods.formatText(getLocale().getMessage("interface.hologram.previewonly")
|
||||
.getMessage()));
|
||||
} else {
|
||||
lines.add(Methods.formatText(getLocale().getMessage("interface.hologram.preview")
|
||||
.getMessage()));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
lines.add(Methods.formatText(o));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
/*
|
||||
* Saves registered kits to file.
|
||||
*/
|
||||
private void saveToFile() {
|
||||
private void saveKits() {
|
||||
|
||||
// Wipe old kit information
|
||||
kitFile.getConfig().set("Kits", null);
|
||||
kitFile.set("Kits", null);
|
||||
|
||||
/*
|
||||
* Save kit from KitManager to Configuration.
|
||||
*/
|
||||
for (Kit kit : kitManager.getKits()) {
|
||||
kitFile.getConfig().set("Kits." + kit.getName() + ".delay", kit.getDelay());
|
||||
kitFile.getConfig().set("Kits." + kit.getName() + ".title", kit.getTitle());
|
||||
kitFile.getConfig().set("Kits." + kit.getName() + ".link", kit.getLink());
|
||||
kitFile.getConfig().set("Kits." + kit.getName() + ".price", kit.getPrice());
|
||||
kitFile.getConfig().set("Kits." + kit.getName() + ".hidden", kit.isHidden());
|
||||
kitFile.getConfig().set("Kits." + kit.getName() + ".animation", kit.getKitAnimation().name());
|
||||
kitFile.set("Kits." + kit.getName() + ".delay", kit.getDelay());
|
||||
kitFile.set("Kits." + kit.getName() + ".title", kit.getTitle());
|
||||
kitFile.set("Kits." + kit.getName() + ".link", kit.getLink());
|
||||
kitFile.set("Kits." + kit.getName() + ".price", kit.getPrice());
|
||||
kitFile.set("Kits." + kit.getName() + ".hidden", kit.isHidden());
|
||||
kitFile.set("Kits." + kit.getName() + ".animation", kit.getKitAnimation().name());
|
||||
if (kit.getDisplayItem() != null)
|
||||
kitFile.getConfig().set("Kits." + kit.getName() + ".displayItem", kit.getDisplayItem().toString());
|
||||
kitFile.set("Kits." + kit.getName() + ".displayItem", kit.getDisplayItem().toString());
|
||||
|
||||
List<KitItem> contents = kit.getContents();
|
||||
List<String> strContents = new ArrayList<>();
|
||||
|
||||
for (KitItem item : contents) strContents.add(item.getSerialized());
|
||||
|
||||
kitFile.getConfig().set("Kits." + kit.getName() + ".items", strContents);
|
||||
kitFile.set("Kits." + kit.getName() + ".items", strContents);
|
||||
}
|
||||
|
||||
// Save to file
|
||||
kitFile.saveConfig();
|
||||
kitFile.saveChanges();
|
||||
}
|
||||
|
||||
/*
|
||||
* Insert default key list into config.
|
||||
*/
|
||||
private void checkKeyDefaults() {
|
||||
if (keyFile.getConfig().contains("Keys")) return;
|
||||
keyFile.getConfig().set("Keys.Regular.Item Amount", 3);
|
||||
keyFile.getConfig().set("Keys.Regular.Amount overrides", Collections.singletonList("Tools:2"));
|
||||
keyFile.getConfig().set("Keys.Regular.Amount of kit received", 1);
|
||||
keyFile.getConfig().set("Keys.Ultra.Item Amount", -1);
|
||||
keyFile.getConfig().set("Keys.Ultra.Amount of kit received", 1);
|
||||
keyFile.getConfig().set("Keys.Insane.Item Amount", -1);
|
||||
keyFile.getConfig().set("Keys.Insane.Amount of kit received", 2);
|
||||
keyFile.saveConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload plugin yaml files.
|
||||
*/
|
||||
public void reload() {
|
||||
this.dataManager.bulkUpdateBlockData(this.getKitManager().getKitLocations());
|
||||
kitFile.reloadConfig();
|
||||
this.locale = Locale.getLocale(getConfig().getString("System.Language Mode"));
|
||||
this.locale.reloadMessages();
|
||||
settingsManager.reloadConfig();
|
||||
loadFromFile();
|
||||
Bukkit.getScheduler().runTaskLater(this, () -> {
|
||||
this.dataManager.getBlockData((blockData) -> {
|
||||
this.kitManager.setKitLocations(blockData);
|
||||
kitManager.getKitLocations().forEach((location, data) -> {
|
||||
UltimateKits.getInstance().getHologram().add(data);
|
||||
});
|
||||
});
|
||||
}, 20L);
|
||||
if(keyFile.contains("Keys")) return;
|
||||
keyFile.set("Keys.Regular.Item Amount", 3);
|
||||
keyFile.set("Keys.Regular.Amount overrides", Collections.singletonList("Tools:2"));
|
||||
keyFile.set("Keys.Regular.Amount of kit received", 1);
|
||||
keyFile.set("Keys.Ultra.Item Amount", -1);
|
||||
keyFile.set("Keys.Ultra.Amount of kit received", 1);
|
||||
keyFile.set("Keys.Insane.Item Amount", -1);
|
||||
keyFile.set("Keys.Insane.Amount of kit received", 2);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -380,7 +442,7 @@ public class UltimateKits extends JavaPlugin {
|
||||
*
|
||||
* @return instance of KitFile
|
||||
*/
|
||||
public ConfigWrapper getKitFile() {
|
||||
public Config getKitFile() {
|
||||
return kitFile;
|
||||
}
|
||||
|
||||
@ -389,28 +451,14 @@ public class UltimateKits extends JavaPlugin {
|
||||
*
|
||||
* @return instance of DataFile
|
||||
*/
|
||||
public ConfigWrapper getDataFile() {
|
||||
public Config getDataFile() {
|
||||
return dataFile;
|
||||
}
|
||||
|
||||
|
||||
public SettingsManager getSettingsManager() {
|
||||
return settingsManager;
|
||||
}
|
||||
|
||||
public CommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
public Hologram getHologram() {
|
||||
return hologram;
|
||||
}
|
||||
|
||||
|
||||
public Economy getEconomy() {
|
||||
return economy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab instance of the item serializer
|
||||
*
|
||||
@ -420,10 +468,6 @@ public class UltimateKits extends JavaPlugin {
|
||||
return this.itemSerializer;
|
||||
}
|
||||
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
public DisplayItemHandler getDisplayItemHandler() {
|
||||
return displayItemHandler;
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
package com.songoda.ultimatekits.animation;
|
||||
|
||||
public abstract class Animation {
|
||||
|
||||
public abstract void start();
|
||||
public abstract void stop();
|
||||
public abstract boolean isDone();
|
||||
public abstract void tick();
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.songoda.ultimatekits.animation;
|
||||
|
||||
public class RouletteAnimation extends Animation {
|
||||
|
||||
boolean _done = false;
|
||||
@Override
|
||||
public void start() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDone() {
|
||||
return _done;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
}
|
||||
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
package com.songoda.ultimatekits.command;
|
||||
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractCommand {
|
||||
|
||||
private final boolean noConsole;
|
||||
private AbstractCommand parent = null;
|
||||
private boolean hasArgs = false;
|
||||
private String command;
|
||||
|
||||
private List<String> subCommand = new ArrayList<>();
|
||||
|
||||
protected AbstractCommand(AbstractCommand parent, boolean noConsole, String... command) {
|
||||
if (parent != null) {
|
||||
this.subCommand = Arrays.asList(command);
|
||||
} else {
|
||||
this.command = Arrays.asList(command).get(0);
|
||||
}
|
||||
this.parent = parent;
|
||||
this.noConsole = noConsole;
|
||||
}
|
||||
|
||||
protected AbstractCommand(boolean noConsole, boolean hasArgs, String... command) {
|
||||
this.command = Arrays.asList(command).get(0);
|
||||
|
||||
this.hasArgs = hasArgs;
|
||||
this.noConsole = noConsole;
|
||||
}
|
||||
|
||||
public AbstractCommand getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public List<String> getSubCommand() {
|
||||
return subCommand;
|
||||
}
|
||||
|
||||
public void addSubCommand(String command) {
|
||||
subCommand.add(command);
|
||||
}
|
||||
|
||||
protected abstract ReturnType runCommand(UltimateKits instance, CommandSender sender, String... args);
|
||||
|
||||
protected abstract List<String> onTab(UltimateKits instance, CommandSender sender, String... args);
|
||||
|
||||
public abstract String getPermissionNode();
|
||||
|
||||
public abstract String getSyntax();
|
||||
|
||||
public abstract String getDescription();
|
||||
|
||||
public boolean hasArgs() {
|
||||
return hasArgs;
|
||||
}
|
||||
|
||||
public boolean isNoConsole() {
|
||||
return noConsole;
|
||||
}
|
||||
|
||||
public enum ReturnType {SUCCESS, FAILURE, SYNTAX_ERROR}
|
||||
}
|
||||
|
@ -1,95 +0,0 @@
|
||||
package com.songoda.ultimatekits.command;
|
||||
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.command.commands.*;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandManager implements CommandExecutor {
|
||||
|
||||
private UltimateKits plugin;
|
||||
private TabManager tabManager;
|
||||
|
||||
private List<AbstractCommand> commands = new ArrayList<>();
|
||||
|
||||
public CommandManager(UltimateKits plugin) {
|
||||
this.plugin = plugin;
|
||||
this.tabManager = new TabManager(this);
|
||||
|
||||
plugin.getCommand("kitadmin").setExecutor(this);
|
||||
plugin.getCommand("kit").setExecutor(this);
|
||||
plugin.getCommand("previewkit").setExecutor(this);
|
||||
|
||||
addCommand(new CommandKit());
|
||||
addCommand(new CommandPreviewKit());
|
||||
AbstractCommand commandUltimateKits = addCommand(new CommandUltimateKits());
|
||||
|
||||
addCommand(new CommandReload(commandUltimateKits));
|
||||
addCommand(new CommandSettings(commandUltimateKits));
|
||||
addCommand(new CommandCreatekit(commandUltimateKits));
|
||||
addCommand(new CommandEdit(commandUltimateKits));
|
||||
addCommand(new CommandKey(commandUltimateKits));
|
||||
addCommand(new CommandSet(commandUltimateKits));
|
||||
addCommand(new CommandRemove(commandUltimateKits));
|
||||
|
||||
for (AbstractCommand abstractCommand : commands) {
|
||||
if (abstractCommand.getParent() != null) continue;
|
||||
plugin.getCommand(abstractCommand.getCommand()).setTabCompleter(tabManager);
|
||||
}
|
||||
}
|
||||
|
||||
private AbstractCommand addCommand(AbstractCommand abstractCommand) {
|
||||
commands.add(abstractCommand);
|
||||
return abstractCommand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
|
||||
for (AbstractCommand abstractCommand : commands) {
|
||||
if (abstractCommand.getCommand() != null && abstractCommand.getCommand().equalsIgnoreCase(command.getName().toLowerCase())) {
|
||||
if (strings.length == 0 || abstractCommand.hasArgs()) {
|
||||
processRequirements(abstractCommand, commandSender, strings);
|
||||
return true;
|
||||
}
|
||||
} else if (strings.length != 0 && abstractCommand.getParent() != null && abstractCommand.getParent().getCommand().equalsIgnoreCase(command.getName())) {
|
||||
String cmd = strings[0];
|
||||
String cmd2 = strings.length >= 2 ? String.join(" ", strings[0], strings[1]) : null;
|
||||
for (String cmds : abstractCommand.getSubCommand()) {
|
||||
if (cmd.equalsIgnoreCase(cmds) || (cmd2 != null && cmd2.equalsIgnoreCase(cmds))) {
|
||||
processRequirements(abstractCommand, commandSender, strings);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
plugin.getLocale().newMessage("&7The command you entered does not exist or is spelt incorrectly.").sendPrefixedMessage(commandSender);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void processRequirements(AbstractCommand command, CommandSender sender, String[] strings) {
|
||||
if (!(sender instanceof Player) && command.isNoConsole()) {
|
||||
sender.sendMessage("You must be a player to use this command.");
|
||||
return;
|
||||
}
|
||||
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
|
||||
AbstractCommand.ReturnType returnType = command.runCommand(plugin, sender, strings);
|
||||
if (returnType == AbstractCommand.ReturnType.SYNTAX_ERROR) {
|
||||
plugin.getLocale().newMessage("&cInvalid Syntax!").sendPrefixedMessage(sender);
|
||||
plugin.getLocale().newMessage("&7The valid syntax is: &6" + command.getSyntax() + "&7.").sendPrefixedMessage(sender);
|
||||
}
|
||||
return;
|
||||
}
|
||||
plugin.getLocale().getMessage("event.general.nopermission").sendPrefixedMessage(sender);
|
||||
}
|
||||
|
||||
public List<AbstractCommand> getCommands() {
|
||||
return Collections.unmodifiableList(commands);
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
package com.songoda.ultimatekits.command;
|
||||
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TabManager implements TabCompleter {
|
||||
|
||||
private final CommandManager commandManager;
|
||||
|
||||
TabManager(CommandManager commandManager) {
|
||||
this.commandManager = commandManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] strings) {
|
||||
for (AbstractCommand abstractCommand : commandManager.getCommands()) {
|
||||
if (command.getPermission() != null && !sender.hasPermission(command.getPermission())) continue;
|
||||
if (abstractCommand.getCommand() != null && abstractCommand.getCommand().equalsIgnoreCase(command.getName()) && !abstractCommand.hasArgs()) {
|
||||
if (strings.length == 1) {
|
||||
List<String> subs = new ArrayList<>();
|
||||
for (AbstractCommand ac : commandManager.getCommands()) {
|
||||
if (ac.getSubCommand() == null) continue;
|
||||
subs.addAll(ac.getSubCommand());
|
||||
}
|
||||
subs.removeIf(s -> !s.toLowerCase().startsWith(strings[0].toLowerCase()));
|
||||
return subs;
|
||||
}
|
||||
} else if (strings.length != 0 && abstractCommand.getParent() != null && abstractCommand.getParent().getCommand().equalsIgnoreCase(command.getName())
|
||||
|| abstractCommand.hasArgs() && abstractCommand.getCommand().equalsIgnoreCase(command.getName())) {
|
||||
String[] args = abstractCommand.hasArgs() ? (String[]) ArrayUtils.add(strings, 0, command.getName()) : strings;
|
||||
String cmd = abstractCommand.hasArgs() ? command.getName() : args[0];
|
||||
String cmd2 = args.length >= 2 ? String.join(" ", args[0], args[1]) : null;
|
||||
if (!abstractCommand.hasArgs()) {
|
||||
for (String cmds : abstractCommand.getSubCommand()) {
|
||||
if (cmd.equalsIgnoreCase(cmds) || (cmd2 != null && cmd2.equalsIgnoreCase(cmds))) {
|
||||
return fetchList(abstractCommand, args, sender);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return fetchList(abstractCommand, args, sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
private List<String> fetchList(AbstractCommand abstractCommand, String[] args, CommandSender sender) {
|
||||
List<String> list = abstractCommand.onTab(UltimateKits.getInstance(), sender, args);
|
||||
String str = args[args.length - 1];
|
||||
if (list != null && str != null && str.length() >= 1) {
|
||||
try {
|
||||
list.removeIf(s -> !s.toLowerCase().startsWith(str.toLowerCase()));
|
||||
} catch (UnsupportedOperationException ignored) {
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
@ -1,28 +1,33 @@
|
||||
package com.songoda.ultimatekits.command.commands;
|
||||
package com.songoda.ultimatekits.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.core.gui.GuiManager;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.command.AbstractCommand;
|
||||
import com.songoda.ultimatekits.gui.GUIKitEditor;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandCreatekit extends AbstractCommand {
|
||||
|
||||
public CommandCreatekit(AbstractCommand parent) {
|
||||
super(parent, true, "createkit");
|
||||
final UltimateKits instance = UltimateKits.getInstance();
|
||||
final GuiManager guiManager;
|
||||
|
||||
public CommandCreatekit(GuiManager guiManager) {
|
||||
super(true, "createkit");
|
||||
this.guiManager = guiManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateKits instance, CommandSender sender, String... args) {
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
Player player = (Player) sender;
|
||||
if (args.length != 2) return ReturnType.SYNTAX_ERROR;
|
||||
String kitStr = args[1].toLowerCase();
|
||||
if (args.length != 1) {
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
String kitStr = args[0].toLowerCase();
|
||||
if (instance.getKitManager().getKit(kitStr) != null) {
|
||||
instance.getLocale().getMessage("command.kit.kitalreadyexists").sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
@ -36,7 +41,7 @@ public class CommandCreatekit extends AbstractCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateKits instance, CommandSender sender, String... args) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
return Arrays.asList("name");
|
||||
}
|
||||
|
@ -1,14 +1,12 @@
|
||||
package com.songoda.ultimatekits.command.commands;
|
||||
package com.songoda.ultimatekits.commands;
|
||||
|
||||
import bammerbom.ultimatecore.bukkit.UltimateMetrics;
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.core.gui.GuiManager;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.command.AbstractCommand;
|
||||
import com.songoda.ultimatekits.gui.GUIBlockEditor;
|
||||
import com.songoda.ultimatekits.gui.GUIKitEditor;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.kit.KitBlockData;
|
||||
import com.songoda.ultimatekits.kit.KitManager;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -18,25 +16,29 @@ import java.util.List;
|
||||
|
||||
public class CommandEdit extends AbstractCommand {
|
||||
|
||||
public CommandEdit(AbstractCommand parent) {
|
||||
super(parent, true, "edit");
|
||||
final UltimateKits instance = UltimateKits.getInstance();
|
||||
final GuiManager guiManager;
|
||||
|
||||
public CommandEdit(GuiManager guiManager) {
|
||||
super(true, "edit");
|
||||
this.guiManager = guiManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateKits instance, CommandSender sender, String... args) {
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
Player player = (Player) sender;
|
||||
Block block = player.getTargetBlock(null, 200);
|
||||
KitBlockData kitBlockData = instance.getKitManager().getKit(block.getLocation());
|
||||
if (args.length > 2) return ReturnType.SYNTAX_ERROR;
|
||||
if (args.length > 1) return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
if (args.length == 1) {
|
||||
if (args.length == 0) {
|
||||
if (kitBlockData == null) {
|
||||
instance.getLocale().newMessage("&8This block does not contain a kit.").sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
new GUIBlockEditor(instance, player, block.getLocation());
|
||||
} else {
|
||||
String kitStr = args[1].toLowerCase().trim();
|
||||
String kitStr = args[0].toLowerCase().trim();
|
||||
if (instance.getKitManager().getKit(kitStr) == null) {
|
||||
instance.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
@ -48,7 +50,7 @@ public class CommandEdit extends AbstractCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateKits instance, CommandSender sender, String... args) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
if (!(sender instanceof Player)) return null;
|
||||
|
||||
List<String> tab = new ArrayList<>();
|
@ -1,7 +1,8 @@
|
||||
package com.songoda.ultimatekits.command.commands;
|
||||
package com.songoda.ultimatekits.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.core.utils.PlayerUtils;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.command.AbstractCommand;
|
||||
import com.songoda.ultimatekits.key.Key;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
@ -14,31 +15,34 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandKey extends AbstractCommand {
|
||||
|
||||
final UltimateKits instance = UltimateKits.getInstance();
|
||||
|
||||
public CommandKey(AbstractCommand parent) {
|
||||
super(parent, false, "key");
|
||||
public CommandKey() {
|
||||
super(false, "key");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateKits instance, CommandSender sender, String... args) {
|
||||
if (args.length != 4 && args.length != 5) {
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length != 3 && args.length != 4) {
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
Kit kit = instance.getKitManager().getKit(args[1]);
|
||||
if (kit == null && !args[1].toLowerCase().equals("all")) {
|
||||
Kit kit = instance.getKitManager().getKit(args[0]);
|
||||
if (kit == null && !args[0].toLowerCase().equals("all")) {
|
||||
instance.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
if (Bukkit.getPlayer(args[3]) == null && !args[3].trim().equalsIgnoreCase("all")) {
|
||||
Player playerTo = null;
|
||||
if (!args[2].trim().equalsIgnoreCase("all") && (playerTo = Bukkit.getPlayer(args[2])) == null) {
|
||||
instance.getLocale().newMessage("&cThat username does not exist, or the user is offline!").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
int amt = 1;
|
||||
if (args.length == 5) {
|
||||
if (!Methods.isNumeric(args[4])) {
|
||||
if (args.length == 4) {
|
||||
if (!Methods.isNumeric(args[3])) {
|
||||
amt = 0;
|
||||
} else {
|
||||
amt = Integer.parseInt(args[4]);
|
||||
amt = Integer.parseInt(args[3]);
|
||||
}
|
||||
}
|
||||
if (amt == 0) {
|
||||
@ -46,23 +50,22 @@ public class CommandKey extends AbstractCommand {
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
Key key = instance.getKeyManager().getKey(args[2]);
|
||||
Key key = instance.getKeyManager().getKey(args[1]);
|
||||
if (key == null) {
|
||||
instance.getLocale().newMessage("&a" + args[3] + " &cis not a key.").sendPrefixedMessage(sender);
|
||||
instance.getLocale().newMessage("&a" + args[1] + " &cis not a key.").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
|
||||
if (!args[3].trim().equals("all")) {
|
||||
Player p = Bukkit.getPlayer(args[3]);
|
||||
p.getInventory().addItem(key.getKeyItem(kit, amt));
|
||||
if (playerTo != null) {
|
||||
PlayerUtils.giveItem(playerTo, key.getKeyItem(kit, amt));
|
||||
instance.getLocale().getMessage("event.key.given")
|
||||
.processPlaceholder("kit", kit == null ? "Any" : kit.getShowableName())
|
||||
.sendPrefixedMessage(p);
|
||||
.sendPrefixedMessage(playerTo);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
for (Player pl : instance.getServer().getOnlinePlayers()) {
|
||||
pl.getInventory().addItem(key.getKeyItem(kit, amt));
|
||||
PlayerUtils.giveItem(playerTo, key.getKeyItem(kit, amt));
|
||||
instance.getLocale().getMessage("event.key.given")
|
||||
.processPlaceholder("kit", kit == null ? "Any" : kit.getShowableName())
|
||||
.sendPrefixedMessage(pl);
|
||||
@ -71,7 +74,7 @@ public class CommandKey extends AbstractCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateKits instance, CommandSender sender, String... args) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
if (!(sender instanceof Player)) return null;
|
||||
|
||||
List<String> tab = new ArrayList<>();
|
@ -1,7 +1,8 @@
|
||||
package com.songoda.ultimatekits.command.commands;
|
||||
package com.songoda.ultimatekits.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.core.gui.GuiManager;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.command.AbstractCommand;
|
||||
import com.songoda.ultimatekits.gui.GUIKitSelector;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
@ -14,12 +15,16 @@ import java.util.List;
|
||||
|
||||
public class CommandKit extends AbstractCommand {
|
||||
|
||||
public CommandKit() {
|
||||
super(false, true,"kit");
|
||||
final UltimateKits instance = UltimateKits.getInstance();
|
||||
final GuiManager guiManager;
|
||||
|
||||
public CommandKit(GuiManager guiManager) {
|
||||
super(true, "kit");
|
||||
this.guiManager = guiManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateKits instance, CommandSender sender, String... args) {
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (!(sender instanceof Player) && args.length != 2) {
|
||||
sender.sendMessage("Kits:");
|
||||
for (Kit kit : instance.getKitManager().getKits()) {
|
||||
@ -29,9 +34,7 @@ public class CommandKit extends AbstractCommand {
|
||||
}
|
||||
if (args.length == 0) {
|
||||
new GUIKitSelector(instance, (Player) sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
if (args.length == 1) {
|
||||
} else if (args.length == 1) {
|
||||
Player player = (Player) sender;
|
||||
String kitName = args[0].toLowerCase();
|
||||
if (instance.getKitManager().getKit(kitName) == null) {
|
||||
@ -44,20 +47,18 @@ public class CommandKit extends AbstractCommand {
|
||||
} else {
|
||||
kit.buy(player);
|
||||
}
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
if (args.length == 2) {
|
||||
} else if (args.length == 2) {
|
||||
String kitName = args[0].toLowerCase();
|
||||
if (instance.getKitManager().getKit(kitName) == null) {
|
||||
instance.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
if (Bukkit.getPlayerExact(args[1]) == null) {
|
||||
Player player2 = Bukkit.getPlayer(args[1]);
|
||||
if (player2 == null || !player2.isOnline()) {
|
||||
instance.getLocale().getMessage("command.kit.playernotfound").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
Player player2 = Bukkit.getPlayer(args[1]);
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if (!Methods.canGiveKit(player)) {
|
||||
@ -70,13 +71,14 @@ public class CommandKit extends AbstractCommand {
|
||||
kit.processGenericUse(player2, true);
|
||||
instance.getLocale().newMessage("&7You gave &9" + player2.getDisplayName() + "&7 kit &9" + kit.getShowableName() + "&7.")
|
||||
.sendPrefixedMessage(sender);
|
||||
return ReturnType.SUCCESS;
|
||||
} else {
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateKits instance, CommandSender sender, String... args) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
package com.songoda.ultimatekits.command.commands;
|
||||
package com.songoda.ultimatekits.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.core.gui.GuiManager;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.command.AbstractCommand;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -11,20 +12,24 @@ import java.util.List;
|
||||
|
||||
public class CommandPreviewKit extends AbstractCommand {
|
||||
|
||||
public CommandPreviewKit() {
|
||||
super(true, true,"PreviewKit");
|
||||
final UltimateKits instance = UltimateKits.getInstance();
|
||||
final GuiManager guiManager;
|
||||
|
||||
public CommandPreviewKit(GuiManager guiManager) {
|
||||
super(true, "PreviewKit");
|
||||
this.guiManager = guiManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateKits plugin, CommandSender sender, String... args) {
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
Player player = (Player) sender;
|
||||
if (args.length != 1) {
|
||||
plugin.getLocale().getMessage("command.kit.nokitsupplied").sendPrefixedMessage(player);
|
||||
instance.getLocale().getMessage("command.kit.nokitsupplied").sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
Kit kit = plugin.getKitManager().getKit(args[0].toLowerCase().trim());
|
||||
Kit kit = instance.getKitManager().getKit(args[0].toLowerCase().trim());
|
||||
if (kit == null) {
|
||||
plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(player);
|
||||
instance.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
kit.display(player, null);
|
||||
@ -32,13 +37,16 @@ public class CommandPreviewKit extends AbstractCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateKits instance, CommandSender sender, String... args) {
|
||||
if (!(sender instanceof Player)) return null;
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (args.length == 2) {
|
||||
List<String> tab = new ArrayList<>();
|
||||
for (Kit kit : UltimateKits.getInstance().getKitManager().getKits())
|
||||
for (Kit kit : UltimateKits.getInstance().getKitManager().getKits()) {
|
||||
tab.add(kit.getName());
|
||||
}
|
||||
return tab;
|
||||
}
|
||||
return new ArrayList<>();
|
@ -1,8 +1,7 @@
|
||||
package com.songoda.ultimatekits.command.commands;
|
||||
package com.songoda.ultimatekits.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.command.AbstractCommand;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -10,19 +9,20 @@ import java.util.List;
|
||||
|
||||
public class CommandReload extends AbstractCommand {
|
||||
|
||||
public CommandReload(AbstractCommand parent) {
|
||||
super(parent, false, "reload");
|
||||
final UltimateKits instance = UltimateKits.getInstance();
|
||||
public CommandReload() {
|
||||
super(false, "reload");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateKits instance, CommandSender sender, String... args) {
|
||||
instance.reload();
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
instance.reloadConfig();
|
||||
instance.getLocale().getMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateKits instance, CommandSender sender, String... args) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
package com.songoda.ultimatekits.command.commands;
|
||||
package com.songoda.ultimatekits.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.core.hooks.HologramManager;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.command.AbstractCommand;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -12,29 +13,30 @@ import java.util.List;
|
||||
|
||||
public class CommandRemove extends AbstractCommand {
|
||||
|
||||
public CommandRemove(AbstractCommand parent) {
|
||||
super(parent, true, "remove");
|
||||
final UltimateKits instance = UltimateKits.getInstance();
|
||||
public CommandRemove() {
|
||||
super(true, "remove");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateKits instance, CommandSender sender, String... args) {
|
||||
if (args.length != 1) {
|
||||
instance.getLocale().getMessage("command.kit.nokitsupplied").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
Player player = (Player) sender;
|
||||
Block block = player.getTargetBlock(null, 200);
|
||||
Kit kit = instance.getKitManager().removeKitFromLocation(block.getLocation());
|
||||
if (kit == null) return ReturnType.FAILURE;
|
||||
|
||||
if (instance.getHologram() != null)
|
||||
instance.getHologram().remove(kit);
|
||||
if (HologramManager.isEnabled()) {
|
||||
instance.getKitManager().getKitLocations().values().stream()
|
||||
.filter(data -> data.getKit() == kit)
|
||||
.forEach(data -> instance.removeHologram(data));
|
||||
}
|
||||
|
||||
instance.getLocale().newMessage("&8Kit &9" + kit.getName() + " &8unassigned from: &a" + block.getType().toString() + "&8.").sendPrefixedMessage(player);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateKits instance, CommandSender sender, String... args) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
package com.songoda.ultimatekits.command.commands;
|
||||
package com.songoda.ultimatekits.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.command.AbstractCommand;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -13,18 +12,20 @@ import java.util.List;
|
||||
|
||||
public class CommandSet extends AbstractCommand {
|
||||
|
||||
public CommandSet(AbstractCommand parent) {
|
||||
super(parent, true, "set");
|
||||
final UltimateKits instance = UltimateKits.getInstance();
|
||||
|
||||
public CommandSet() {
|
||||
super(true, "set");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateKits instance, CommandSender sender, String... args) {
|
||||
if (args.length != 2) {
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length != 1) {
|
||||
instance.getLocale().getMessage("command.kit.nokitsupplied").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
String kit = args[1].toLowerCase();
|
||||
String kit = args[0].toLowerCase();
|
||||
if (instance.getKitManager().getKit(kit) == null) {
|
||||
instance.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
@ -37,13 +38,16 @@ public class CommandSet extends AbstractCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateKits instance, CommandSender sender, String... args) {
|
||||
if (!(sender instanceof Player)) return null;
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (args.length == 2) {
|
||||
List<String> tab = new ArrayList<>();
|
||||
for (Kit kit : UltimateKits.getInstance().getKitManager().getKits())
|
||||
for (Kit kit : UltimateKits.getInstance().getKitManager().getKits()) {
|
||||
tab.add(kit.getName());
|
||||
}
|
||||
return tab;
|
||||
}
|
||||
return new ArrayList<>();
|
@ -1,7 +1,9 @@
|
||||
package com.songoda.ultimatekits.command.commands;
|
||||
package com.songoda.ultimatekits.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.core.configuration.editor.PluginConfigGui;
|
||||
import com.songoda.core.gui.GuiManager;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.command.AbstractCommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -10,18 +12,22 @@ import java.util.List;
|
||||
|
||||
public class CommandSettings extends AbstractCommand {
|
||||
|
||||
public CommandSettings(AbstractCommand parent) {
|
||||
super(parent, true, "settings");
|
||||
final UltimateKits instance = UltimateKits.getInstance();
|
||||
final GuiManager guiManager;
|
||||
|
||||
public CommandSettings(GuiManager guiManager) {
|
||||
super(true, "settings");
|
||||
this.guiManager = guiManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateKits instance, CommandSender sender, String... args) {
|
||||
instance.getSettingsManager().openSettingsManager((Player) sender);
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
guiManager.showGUI((Player) sender, new PluginConfigGui(instance));
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateKits instance, CommandSender sender, String... args) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.songoda.ultimatekits.command.commands;
|
||||
package com.songoda.ultimatekits.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.command.AbstractCommand;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@ -10,17 +10,19 @@ import java.util.List;
|
||||
|
||||
public class CommandUltimateKits extends AbstractCommand {
|
||||
|
||||
final UltimateKits instance = UltimateKits.getInstance();
|
||||
|
||||
public CommandUltimateKits() {
|
||||
super(null, false, "KitAdmin");
|
||||
super(false, "KitAdmin");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractCommand.ReturnType runCommand(UltimateKits instance, CommandSender sender, String... args) {
|
||||
protected AbstractCommand.ReturnType runCommand(CommandSender sender, String... args) {
|
||||
sender.sendMessage("");
|
||||
instance.getLocale().newMessage("&7Version " + instance.getDescription().getVersion()
|
||||
+ " Created with <3 by &5&l&oSongoda").sendPrefixedMessage(sender);
|
||||
|
||||
for (AbstractCommand command : instance.getCommandManager().getCommands()) {
|
||||
for (AbstractCommand command : instance.getCommandManager().getAllCommands()) {
|
||||
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
|
||||
sender.sendMessage(Methods.formatText("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription()));
|
||||
}
|
||||
@ -31,7 +33,7 @@ public class CommandUltimateKits extends AbstractCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateKits instance, CommandSender sender, String... args) {
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
@ -10,68 +10,53 @@ import org.bukkit.inventory.ItemStack;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class Convert {
|
||||
|
||||
private final UltimateKits instance;
|
||||
|
||||
private Hook hook;
|
||||
|
||||
public Convert(UltimateKits instance) {
|
||||
this.instance = instance;
|
||||
if (instance.getServer().getPluginManager().getPlugin("Essentials") != null) {
|
||||
try {
|
||||
Class.forName("com.earth2me.essentials.metrics.MetricsListener");
|
||||
hook = new DefaultHook();
|
||||
} catch (ClassNotFoundException ex) {
|
||||
hook = new EssentialsHook();
|
||||
public static void runKitConversions() {
|
||||
if (!UltimateKits.getInstance().getKitFile().contains("Kits")) {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("Essentials")) {
|
||||
try {
|
||||
Class.forName("com.earth2me.essentials.metrics.MetricsListener");
|
||||
} catch (ClassNotFoundException ex) {
|
||||
convertKits(new EssentialsHook());
|
||||
}
|
||||
}
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("UltimateCore")) {
|
||||
convertKits(new UltimateCoreHook());
|
||||
}
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("CMI")) {
|
||||
convertKits(new CMIHook());
|
||||
}
|
||||
} else if (instance.getServer().getPluginManager().getPlugin("UltimateCore") != null) {
|
||||
hook = new UltimateCoreHook();
|
||||
|
||||
} else if (instance.getServer().getPluginManager().getPlugin("CMI") != null) {
|
||||
hook = new CMIHook();
|
||||
} else {
|
||||
hook = new DefaultHook();
|
||||
}
|
||||
|
||||
if (hook.getKits().size() == 0)
|
||||
hook = new DefaultHook();
|
||||
|
||||
convertKits();
|
||||
if (!isInJsonFormat()) {
|
||||
convertKits(new DefaultHook());
|
||||
}
|
||||
}
|
||||
|
||||
private void convertKits() {
|
||||
private static void convertKits(Hook hook) {
|
||||
Set<String> kits = hook.getKits();
|
||||
|
||||
if (!instance.getKitFile().getConfig().contains("Kits")) {
|
||||
this.convertKits(kits);
|
||||
} else if (!isInJsonFormat()) {
|
||||
hook = new DefaultHook();
|
||||
this.convertKits(hook.getKits());
|
||||
}
|
||||
}
|
||||
|
||||
private void convertKits(Set<String> kits) {
|
||||
for (String kit : kits) {
|
||||
List<String> serializedItems = new ArrayList<>();
|
||||
for (ItemStack item : hook.getItems(kit)) {
|
||||
serializedItems.add(instance.getItemSerializer().serializeItemStackToJson(item));
|
||||
serializedItems.add(UltimateKits.getInstance().getItemSerializer().serializeItemStackToJson(item));
|
||||
}
|
||||
instance.getKitFile().getConfig().set("Kits." + kit + ".items", serializedItems);
|
||||
instance.getKitFile().getConfig().set("Kits." + kit + ".delay", hook.getDelay(kit));
|
||||
instance.getKitFile().getConfig().set("Kits." + kit + ".price", 0D);
|
||||
UltimateKits.getInstance().getKitFile().set("Kits." + kit + ".items", serializedItems);
|
||||
UltimateKits.getInstance().getKitFile().set("Kits." + kit + ".delay", hook.getDelay(kit));
|
||||
UltimateKits.getInstance().getKitFile().set("Kits." + kit + ".price", 0D);
|
||||
}
|
||||
instance.getKitFile().saveConfig();
|
||||
UltimateKits.getInstance().getKitFile().save();
|
||||
}
|
||||
|
||||
private boolean isInJsonFormat() {
|
||||
for (String kit : instance.getKitFile().getConfig().getConfigurationSection("Kits").getKeys(false)) {
|
||||
if (instance.getKitFile().getConfig().contains("Kits." + kit + ".items")) {
|
||||
List<String> itemList = instance.getKitFile().getConfig().getStringList("Kits." + kit + ".items");
|
||||
private static boolean isInJsonFormat() {
|
||||
for (String kit : UltimateKits.getInstance().getKitFile().getConfigurationSection("Kits").getKeys(false)) {
|
||||
if (UltimateKits.getInstance().getKitFile().contains("Kits." + kit + ".items")) {
|
||||
List<String> itemList = UltimateKits.getInstance().getKitFile().getStringList("Kits." + kit + ".items");
|
||||
if (itemList.size() > 0) {
|
||||
if (itemList.get(0).startsWith("{"))
|
||||
if (itemList.get(0).startsWith("{")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,35 +1,26 @@
|
||||
package com.songoda.ultimatekits.database;
|
||||
|
||||
import com.songoda.core.database.DataManagerAbstract;
|
||||
import com.songoda.core.database.DatabaseConnector;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.KitBlockData;
|
||||
import com.songoda.ultimatekits.kit.KitType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class DataManager {
|
||||
|
||||
private final DatabaseConnector databaseConnector;
|
||||
private final Plugin plugin;
|
||||
public class DataManager extends DataManagerAbstract {
|
||||
|
||||
public DataManager(DatabaseConnector databaseConnector, Plugin plugin) {
|
||||
this.databaseConnector = databaseConnector;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public String getTablePrefix() {
|
||||
return this.plugin.getDescription().getName().toLowerCase() + '_';
|
||||
super(databaseConnector, plugin);
|
||||
}
|
||||
|
||||
public void bulkUpdateBlockData(Map<Location, KitBlockData> blockData) {
|
||||
@ -145,30 +136,4 @@ public class DataManager {
|
||||
this.sync(() -> callback.accept(blockData));
|
||||
}));
|
||||
}
|
||||
|
||||
private int lastInsertedId(Connection connection) {
|
||||
String query;
|
||||
if (this.databaseConnector instanceof SQLiteConnector) {
|
||||
query = "SELECT last_insert_rowid()";
|
||||
} else {
|
||||
query = "SELECT LAST_INSERT_ID()";
|
||||
}
|
||||
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
ResultSet result = statement.executeQuery(query);
|
||||
result.next();
|
||||
return result.getInt(1);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public void async(Runnable runnable) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, runnable);
|
||||
}
|
||||
|
||||
public void sync(Runnable runnable) {
|
||||
Bukkit.getScheduler().runTask(this.plugin, runnable);
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +0,0 @@
|
||||
package com.songoda.ultimatekits.database;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public abstract class DataMigration {
|
||||
|
||||
private final int revision;
|
||||
|
||||
public DataMigration(int revision) {
|
||||
this.revision = revision;
|
||||
}
|
||||
|
||||
public abstract void migrate(Connection connection, String tablePrefix) throws SQLException;
|
||||
|
||||
public int getRevision() {
|
||||
return this.revision;
|
||||
}
|
||||
}
|
@ -1,108 +0,0 @@
|
||||
package com.songoda.ultimatekits.database;
|
||||
|
||||
import com.songoda.ultimatekits.database.migrations._1_InitialMigration;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DataMigrationManager {
|
||||
|
||||
private List<DataMigration> migrations;
|
||||
private DatabaseConnector databaseConnector;
|
||||
private DataManager dataManager;
|
||||
|
||||
public DataMigrationManager(DatabaseConnector databaseConnector, DataManager dataManager) {
|
||||
this.databaseConnector = databaseConnector;
|
||||
this.dataManager = dataManager;
|
||||
|
||||
this.migrations = Arrays.asList(
|
||||
new _1_InitialMigration()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs any needed data migrations
|
||||
*/
|
||||
public void runMigrations() {
|
||||
this.databaseConnector.connect((connection -> {
|
||||
int currentMigration = -1;
|
||||
boolean migrationsExist;
|
||||
|
||||
String query;
|
||||
if (this.databaseConnector instanceof SQLiteConnector) {
|
||||
query = "SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?";
|
||||
} else {
|
||||
query = "SHOW TABLES LIKE ?";
|
||||
}
|
||||
|
||||
try (PreparedStatement statement = connection.prepareStatement(query)) {
|
||||
statement.setString(1, this.getMigrationsTableName());
|
||||
migrationsExist = statement.executeQuery().next();
|
||||
}
|
||||
|
||||
if (!migrationsExist) {
|
||||
// No migration table exists, create one
|
||||
String createTable = "CREATE TABLE " + this.getMigrationsTableName() + " (migration_version INT NOT NULL)";
|
||||
try (PreparedStatement statement = connection.prepareStatement(createTable)) {
|
||||
statement.execute();
|
||||
}
|
||||
|
||||
// Insert primary row into migration table
|
||||
String insertRow = "INSERT INTO " + this.getMigrationsTableName() + " VALUES (?)";
|
||||
try (PreparedStatement statement = connection.prepareStatement(insertRow)) {
|
||||
statement.setInt(1, -1);
|
||||
statement.execute();
|
||||
}
|
||||
} else {
|
||||
// Grab the current migration version
|
||||
String selectVersion = "SELECT migration_version FROM " + this.getMigrationsTableName();
|
||||
try (PreparedStatement statement = connection.prepareStatement(selectVersion)) {
|
||||
ResultSet result = statement.executeQuery();
|
||||
result.next();
|
||||
currentMigration = result.getInt("migration_version");
|
||||
}
|
||||
}
|
||||
|
||||
// Grab required migrations
|
||||
int finalCurrentMigration = currentMigration;
|
||||
List<DataMigration> requiredMigrations = this.migrations
|
||||
.stream()
|
||||
.filter(x -> x.getRevision() > finalCurrentMigration)
|
||||
.sorted(Comparator.comparingInt(DataMigration::getRevision))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// Nothing to migrate, abort
|
||||
if (requiredMigrations.isEmpty())
|
||||
return;
|
||||
|
||||
// Migrate the data
|
||||
for (DataMigration dataMigration : requiredMigrations)
|
||||
dataMigration.migrate(connection, this.dataManager.getTablePrefix());
|
||||
|
||||
// Set the new current migration to be the highest migrated to
|
||||
currentMigration = requiredMigrations
|
||||
.stream()
|
||||
.map(DataMigration::getRevision)
|
||||
.max(Integer::compareTo)
|
||||
.orElse(-1);
|
||||
|
||||
String updateVersion = "UPDATE " + this.getMigrationsTableName() + " SET migration_version = ?";
|
||||
try (PreparedStatement statement = connection.prepareStatement(updateVersion)) {
|
||||
statement.setInt(1, currentMigration);
|
||||
statement.execute();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name of the migrations table
|
||||
*/
|
||||
private String getMigrationsTableName() {
|
||||
return this.dataManager.getTablePrefix() + "migrations";
|
||||
}
|
||||
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package com.songoda.ultimatekits.database;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public interface DatabaseConnector {
|
||||
|
||||
/**
|
||||
* Checks if the connection to the database has been created
|
||||
*
|
||||
* @return true if the connection is created, otherwise false
|
||||
*/
|
||||
boolean isInitialized();
|
||||
|
||||
/**
|
||||
* Closes all open connections to the database
|
||||
*/
|
||||
void closeConnection();
|
||||
|
||||
/**
|
||||
* Executes a callback with a Connection passed and automatically closes it when finished
|
||||
*
|
||||
* @param callback The callback to execute once the connection is retrieved
|
||||
*/
|
||||
void connect(ConnectionCallback callback);
|
||||
|
||||
/**
|
||||
* Wraps a connection in a callback which will automagically handle catching sql errors
|
||||
*/
|
||||
interface ConnectionCallback {
|
||||
void accept(Connection connection) throws SQLException;
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.songoda.ultimatekits.database;
|
||||
|
||||
import com.songoda.core.database.DatabaseConnector;
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
@ -30,14 +31,17 @@ public class MySQLConnector implements DatabaseConnector {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInitialized() {
|
||||
return this.initializedSuccessfully;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeConnection() {
|
||||
this.hikari.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(ConnectionCallback callback) {
|
||||
try (Connection connection = this.hikari.getConnection()) {
|
||||
callback.accept(connection);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.songoda.ultimatekits.database;
|
||||
|
||||
import com.songoda.core.database.DatabaseConnector;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.io.File;
|
||||
@ -24,10 +25,12 @@ public class SQLiteConnector implements DatabaseConnector {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInitialized() {
|
||||
return true; // Always available
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeConnection() {
|
||||
try {
|
||||
if (this.connection != null) {
|
||||
@ -38,6 +41,7 @@ public class SQLiteConnector implements DatabaseConnector {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(ConnectionCallback callback) {
|
||||
if (this.connection == null) {
|
||||
try {
|
||||
|
@ -1,8 +1,6 @@
|
||||
package com.songoda.ultimatekits.database.migrations;
|
||||
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.database.DataMigration;
|
||||
import com.songoda.ultimatekits.database.MySQLConnector;
|
||||
import com.songoda.core.database.DataMigration;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
@ -16,8 +14,8 @@ public class _1_InitialMigration extends DataMigration {
|
||||
|
||||
@Override
|
||||
public void migrate(Connection connection, String tablePrefix) throws SQLException {
|
||||
String autoIncrement = UltimateKits.getInstance().getDatabaseConnector() instanceof
|
||||
MySQLConnector ? " AUTO_INCREMENT" : "";
|
||||
// String autoIncrement = UltimateKits.getInstance().getDatabaseConnector() instanceof
|
||||
// MySQLConnector ? " AUTO_INCREMENT" : "";
|
||||
|
||||
// Create plugin settings table
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
|
@ -1,12 +0,0 @@
|
||||
package com.songoda.ultimatekits.economy;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
public interface Economy {
|
||||
|
||||
boolean hasBalance(OfflinePlayer player, double cost);
|
||||
|
||||
boolean withdrawBalance(OfflinePlayer player, double cost);
|
||||
|
||||
boolean deposit(OfflinePlayer player, double amount);
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
package com.songoda.ultimatekits.economy;
|
||||
|
||||
import org.black_ixx.playerpoints.PlayerPoints;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
public class PlayerPointsEconomy implements Economy {
|
||||
|
||||
private final PlayerPoints playerPoints;
|
||||
|
||||
public PlayerPointsEconomy() {
|
||||
this.playerPoints = (PlayerPoints) Bukkit.getServer().getPluginManager().getPlugin("PlayerPoints");
|
||||
}
|
||||
|
||||
private int convertAmount(double amount) {
|
||||
return (int) Math.ceil(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBalance(OfflinePlayer player, double cost) {
|
||||
int amount = convertAmount(cost);
|
||||
return playerPoints.getAPI().look(player.getUniqueId()) >= amount;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean withdrawBalance(OfflinePlayer player, double cost) {
|
||||
int amount = convertAmount(cost);
|
||||
return playerPoints.getAPI().take(player.getUniqueId(), amount);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deposit(OfflinePlayer player, double amount) {
|
||||
int amt = convertAmount(amount);
|
||||
return playerPoints.getAPI().give(player.getUniqueId(), amt);
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package com.songoda.ultimatekits.economy;
|
||||
|
||||
import net.tnemc.core.Reserve;
|
||||
import net.tnemc.core.economy.EconomyAPI;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class ReserveEconomy implements Economy {
|
||||
|
||||
EconomyAPI economyAPI;
|
||||
|
||||
public ReserveEconomy() {
|
||||
if (Reserve.instance().economyProvided())
|
||||
economyAPI = Reserve.instance().economy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBalance(OfflinePlayer player, double cost) {
|
||||
return economyAPI.hasHoldings(player.getUniqueId(), new BigDecimal(cost));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean withdrawBalance(OfflinePlayer player, double cost) {
|
||||
return economyAPI.removeHoldings(player.getUniqueId(), new BigDecimal(cost));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deposit(OfflinePlayer player, double amount) {
|
||||
return economyAPI.addHoldings(player.getUniqueId(), new BigDecimal(amount));
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package com.songoda.ultimatekits.economy;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
public class VaultEconomy implements Economy {
|
||||
private final net.milkbowl.vault.economy.Economy vault;
|
||||
|
||||
public VaultEconomy() {
|
||||
this.vault = Bukkit.getServicesManager().
|
||||
getRegistration(net.milkbowl.vault.economy.Economy.class).getProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBalance(OfflinePlayer player, double cost) {
|
||||
return vault.has(player, cost);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean withdrawBalance(OfflinePlayer player, double cost) {
|
||||
return vault.withdrawPlayer(player, cost).transactionSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deposit(OfflinePlayer player, double amount) {
|
||||
return vault.depositPlayer(player, amount).transactionSuccess();
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.songoda.ultimatekits.gui;
|
||||
|
||||
import com.songoda.core.utils.ItemUtils;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.kit.KitBlockData;
|
||||
@ -54,8 +55,7 @@ public class GUIDecorOptions extends AbstractGUI {
|
||||
createButton(8, Material.valueOf(UltimateKits.getInstance().getConfig().getString("Interfaces.Exit Icon")),
|
||||
UltimateKits.getInstance().getLocale().getMessage("interface.button.exit").getMessage());
|
||||
|
||||
ItemStack head = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3);
|
||||
ItemStack back = Methods.addTexture(head, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
ItemStack back = ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
inventory.setItem(0, back);
|
||||
|
||||
createButton(0, back, UltimateKits.getInstance().getLocale().getMessage("interface.button.back").getMessage());
|
||||
|
@ -1,47 +1,44 @@
|
||||
package com.songoda.ultimatekits.gui;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.gui.Gui;
|
||||
import com.songoda.core.gui.GuiUtils;
|
||||
import com.songoda.core.utils.ItemUtils;
|
||||
import com.songoda.core.utils.TextUtils;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.settings.Settings;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import com.songoda.ultimatekits.utils.ServerVersion;
|
||||
import com.songoda.ultimatekits.utils.gui.AbstractGUI;
|
||||
import org.bukkit.Bukkit;
|
||||
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.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class GUIDisplayKit extends AbstractGUI {
|
||||
public class GUIDisplayKit extends Gui {
|
||||
|
||||
private Kit kit;
|
||||
private Player player;
|
||||
private UltimateKits plugin;
|
||||
private AbstractGUI back;
|
||||
private final Kit kit;
|
||||
private final Player player;
|
||||
private final UltimateKits plugin;
|
||||
private final boolean buyable;
|
||||
private final List<ItemStack> list;
|
||||
private final boolean useGlassBorder = !Settings.DO_NOT_USE_GLASS_BORDERS.getBoolean();
|
||||
static final Random rand = new Random();
|
||||
|
||||
private int max;
|
||||
private boolean buyable;
|
||||
private List<ItemStack> list;
|
||||
|
||||
public GUIDisplayKit(UltimateKits plugin, AbstractGUI back, Player player, Kit kit) {
|
||||
super(player);
|
||||
public GUIDisplayKit(UltimateKits plugin, Gui back, Player player, Kit kit) {
|
||||
super(back);
|
||||
this.kit = kit;
|
||||
this.player = player;
|
||||
this.plugin = plugin;
|
||||
this.back = back;
|
||||
this.list = kit.getReadableContents(player, true, true, false);
|
||||
this.buyable = (kit.getLink() != null || kit.getPrice() != 0);
|
||||
|
||||
String guititle = Methods.formatTitle(plugin.getLocale().getMessage("interface.preview.title")
|
||||
.processPlaceholder("kit", kit.getShowableName()).getMessage());
|
||||
if (kit.getTitle() != null) {
|
||||
guititle = plugin.getLocale().getMessage("interface.preview.title")
|
||||
.processPlaceholder("kit", Methods.formatText(kit.getTitle(), true)).getMessage();
|
||||
}
|
||||
|
||||
list = kit.getReadableContents(player, true, true, false);
|
||||
setTitle(plugin.getLocale().getMessage("interface.preview.title")
|
||||
.processPlaceholder("kit", kit.getTitle() != null ? TextUtils.formatText(kit.getTitle(), true) : kit.getShowableName()).getMessage());
|
||||
|
||||
int amt = 0;
|
||||
for (ItemStack is : list) {
|
||||
@ -61,179 +58,160 @@ public class GUIDisplayKit extends AbstractGUI {
|
||||
}
|
||||
}
|
||||
|
||||
buyable = false;
|
||||
if (kit.getLink() != null || kit.getPrice() != 0) {
|
||||
buyable = true;
|
||||
}
|
||||
|
||||
int min = 0;
|
||||
if (plugin.getConfig().getBoolean("Interfaces.Do Not Use Glass Borders")) {
|
||||
min = 9;
|
||||
if (!useGlassBorder) {
|
||||
min = 1;
|
||||
if (!buyable) {
|
||||
min = min + 9;
|
||||
++min;
|
||||
}
|
||||
}
|
||||
|
||||
max = 54 - min;
|
||||
if (amt <= 7) {
|
||||
max = 27 - min;
|
||||
setRows(3 - min);
|
||||
} else if (amt <= 15) {
|
||||
max = 36 - min;
|
||||
setRows(4 - min);
|
||||
} else if (amt <= 23) {
|
||||
max = 45 - min;
|
||||
}
|
||||
init(guititle, max);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void constructGUI() {
|
||||
int num = 0;
|
||||
if (!plugin.getConfig().getBoolean("Interfaces.Do Not Use Glass Borders")) {
|
||||
ItemStack exit = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.Exit Icon")), 1);
|
||||
ItemMeta exitmeta = exit.getItemMeta();
|
||||
exitmeta.setDisplayName(plugin.getLocale().getMessage("interface.button.exit").getMessage());
|
||||
exit.setItemMeta(exitmeta);
|
||||
while (num != 10) {
|
||||
inventory.setItem(num, Methods.getGlass());
|
||||
num++;
|
||||
}
|
||||
int num2 = max - 10;
|
||||
while (num2 != max) {
|
||||
inventory.setItem(num2, Methods.getGlass());
|
||||
num2++;
|
||||
}
|
||||
inventory.setItem(8, exit);
|
||||
|
||||
inventory.setItem(0, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(1, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(9, Methods.getBackgroundGlass(true));
|
||||
|
||||
inventory.setItem(7, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(17, Methods.getBackgroundGlass(true));
|
||||
|
||||
inventory.setItem(max - 18, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(max - 9, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(max - 8, Methods.getBackgroundGlass(true));
|
||||
|
||||
inventory.setItem(max - 10, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(max - 2, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(max - 1, Methods.getBackgroundGlass(true));
|
||||
|
||||
inventory.setItem(2, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(6, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(max - 7, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(max - 3, Methods.getBackgroundGlass(false));
|
||||
setRows(5 - min);
|
||||
} else {
|
||||
setRows(6 - min);
|
||||
}
|
||||
|
||||
if (!useGlassBorder) {
|
||||
setDefaultItem(AIR);
|
||||
} else {
|
||||
|
||||
ItemStack glass2 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_2.getMaterial(CompatibleMaterial.BLUE_STAINED_GLASS_PANE));
|
||||
ItemStack glass3 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_3.getMaterial(CompatibleMaterial.LIGHT_BLUE_STAINED_GLASS_PANE));
|
||||
|
||||
// edges will be type 3
|
||||
setDefaultItem(glass3);
|
||||
|
||||
// decorate corners
|
||||
GuiUtils.mirrorFill(this, 0, 0, true, true, glass2);
|
||||
GuiUtils.mirrorFill(this, 1, 0, true, true, glass2);
|
||||
GuiUtils.mirrorFill(this, 0, 1, true, true, glass2);
|
||||
|
||||
if (Settings.RAINBOW.getBoolean()) {
|
||||
for (int col = 2; col < 7; ++col) {
|
||||
setItem(0, col, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneColor(rand.nextInt(16))));
|
||||
setItem(rows - 1, col, GuiUtils.getBorderItem(CompatibleMaterial.getGlassPaneColor(rand.nextInt(16))));
|
||||
}
|
||||
} else {
|
||||
ItemStack topBottom = GuiUtils.getBorderItem(Settings.GLASS_TYPE_2.getMaterial(CompatibleMaterial.GRAY_STAINED_GLASS_PANE));
|
||||
for (int col = 2; col < 7; ++col) {
|
||||
setItem(0, col, topBottom);
|
||||
setItem(rows - 1, col, topBottom);
|
||||
}
|
||||
}
|
||||
|
||||
// exit button is only visible with a glass border
|
||||
setButton(0, 8, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(CompatibleMaterial.OAK_DOOR),
|
||||
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()),
|
||||
event -> event.player.closeInventory());
|
||||
}
|
||||
}
|
||||
// purchase button
|
||||
if (buyable) {
|
||||
ItemStack link = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.Buy Icon")), 1);
|
||||
ItemMeta linkmeta = link.getItemMeta();
|
||||
linkmeta.setDisplayName(plugin.getLocale().getMessage("interface.button.buynow").getMessage());
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
if (kit.hasPermission(player) && plugin.getConfig().getBoolean("Main.Allow Players To Receive Kits For Free If They Have Permission")) {
|
||||
lore.add(plugin.getLocale().getMessage("interface.button.clickeco")
|
||||
.processPlaceholder("price", "0").getMessage());
|
||||
if (player.isOp()) {
|
||||
lore.add("");
|
||||
lore.add(Methods.formatText("&7This is free because"));
|
||||
lore.add(Methods.formatText("&7you have perms for it."));
|
||||
lore.add(Methods.formatText("&7Everyone else buys"));
|
||||
lore.add(Methods.formatText("&7this for &a$" + Methods.formatEconomy(kit.getPrice()) + "&7."));
|
||||
setButton(rows - 1, 4, GuiUtils.createButtonItem(Settings.BUY_ICON.getMaterial(CompatibleMaterial.EMERALD),
|
||||
plugin.getLocale().getMessage("interface.button.buynow").getMessage(),
|
||||
getBuyLore()),
|
||||
event -> {
|
||||
exit();
|
||||
kit.buy(player);
|
||||
});
|
||||
}
|
||||
|
||||
// display the kit items here
|
||||
Iterator<ItemStack> items = list.iterator();
|
||||
int startRow = useGlassBorder ? 1 : 0;
|
||||
int endRow = useGlassBorder ? rows - 2 : rows - 1;
|
||||
int startCol = useGlassBorder ? 1 : 0;
|
||||
int endCol = useGlassBorder ? 8 : 7;
|
||||
for (int row = startRow; row <= endRow; ++row) {
|
||||
for (int col = startCol; col <= endCol; ++col) {
|
||||
ItemStack item;
|
||||
if (!items.hasNext()) {
|
||||
setItem(row, col, AIR);
|
||||
} else if ((item = items.next()) == null
|
||||
|| (Settings.DONT_PREVIEW_COMMANDS.getBoolean()
|
||||
&& item.getType() == Material.PAPER
|
||||
&& item.getItemMeta().hasDisplayName()
|
||||
&& item.getItemMeta().getDisplayName().equals(plugin.getLocale().getMessage("general.type.command")))) {
|
||||
setItem(row, col, AIR);
|
||||
} else if (item.getAmount() <= 64) {
|
||||
// display item
|
||||
setItem(row, col, getKitItem(item));
|
||||
} else {
|
||||
// correct item amounts (up to three slots)
|
||||
int itAmt = item.getAmount(), slots = 0;
|
||||
for (; itAmt > 0 && slots < 3 && row <= endRow; ++row) {
|
||||
for (; itAmt > 0 && slots < 3 && col <= endCol; ++col) {
|
||||
setItem(row, col, getKitItem(item, Math.min(64, itAmt)));
|
||||
itAmt -= 64;
|
||||
++slots;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
lore.add(plugin.getLocale().getMessage("interface.button.clickeco")
|
||||
.processPlaceholder("price", Methods.formatEconomy(kit.getPrice())).getMessage());
|
||||
}
|
||||
if (kit.getDelay() != 0 && player.isOp()) {
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack getKitItem(ItemStack is) {
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
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()));
|
||||
}
|
||||
}
|
||||
meta.setLore(newLore);
|
||||
is.setItemMeta(meta);
|
||||
return is;
|
||||
}
|
||||
|
||||
ItemStack getKitItem(ItemStack is, int amount) {
|
||||
ItemStack is2 = is.clone();
|
||||
ItemMeta meta = is2.getItemMeta();
|
||||
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()));
|
||||
}
|
||||
}
|
||||
meta.setLore(newLore);
|
||||
is2.setItemMeta(meta);
|
||||
is2.setAmount(amount);
|
||||
return is;
|
||||
}
|
||||
|
||||
List<String> getBuyLore() {
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
if (kit.hasPermission(player) && plugin.getConfig().getBoolean("Main.Allow Players To Receive Kits For Free If They Have Permission")) {
|
||||
lore.add(plugin.getLocale().getMessage("interface.button.clickeco")
|
||||
.processPlaceholder("price", "0").getMessage());
|
||||
if (player.isOp()) {
|
||||
lore.add("");
|
||||
lore.add(Methods.formatText("&7You do not have a delay"));
|
||||
lore.add(Methods.formatText("&7because you have perms"));
|
||||
lore.add(Methods.formatText("&7to bypass the delay."));
|
||||
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 &a$" + Methods.formatEconomy(kit.getPrice()) + ChatColor.GRAY + ".");
|
||||
}
|
||||
linkmeta.setLore(lore);
|
||||
link.setItemMeta(linkmeta);
|
||||
inventory.setItem(max - 5, link);
|
||||
|
||||
registerClickable(max - 5, ((player1, inventory1, cursor, slot, type) -> {
|
||||
player.closeInventory();
|
||||
String kitName = kit.getName();
|
||||
Kit kit = plugin.getKitManager().getKit(kitName);
|
||||
kit.buy(player);
|
||||
}));
|
||||
} else {
|
||||
lore.add(plugin.getLocale().getMessage("interface.button.clickeco")
|
||||
.processPlaceholder("price", Methods.formatEconomy(kit.getPrice())).getMessage());
|
||||
}
|
||||
|
||||
for (ItemStack is : list) {
|
||||
if (!plugin.getConfig().getBoolean("Interfaces.Do Not Use Glass Borders")) {
|
||||
if (num == 17 || num == (max - 18)) num++;
|
||||
if (num == 18 && max == 36) num++;
|
||||
}
|
||||
|
||||
ItemMeta meta = is.hasItemMeta() ? is.getItemMeta() : Bukkit.getItemFactory().getItemMeta(is.getType());
|
||||
ArrayDeque<String> lore;
|
||||
if (meta.hasLore()) {
|
||||
lore = new ArrayDeque<>(meta.getLore());
|
||||
} else {
|
||||
lore = new ArrayDeque<>();
|
||||
}
|
||||
|
||||
List<String> newLore = new ArrayList<>();
|
||||
for (String str : lore) {
|
||||
str = str.replace("{PLAYER}", player.getName()).replace("<PLAYER>", player.getName());
|
||||
newLore.add(str);
|
||||
}
|
||||
|
||||
meta.setLore(newLore);
|
||||
is.setItemMeta(meta);
|
||||
|
||||
if (is.getAmount() > 64) {
|
||||
int overflow = is.getAmount() % 64;
|
||||
int stackamt = is.getAmount() / 64;
|
||||
int num3 = 0;
|
||||
while (num3 != stackamt) {
|
||||
is.setAmount(64);
|
||||
inventory.setItem(num, is);
|
||||
num++;
|
||||
num3++;
|
||||
}
|
||||
if (overflow != 0) {
|
||||
is.setAmount(overflow);
|
||||
inventory.setItem(num, is);
|
||||
num++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!plugin.getConfig().getBoolean("Main.Dont Preview Commands In Kits") || is.getType() != Material.PAPER || !is.getItemMeta().hasDisplayName() || !is.getItemMeta().getDisplayName().equals(plugin.getLocale().getMessage("general.type.command"))) {
|
||||
inventory.setItem(num, is);
|
||||
num++;
|
||||
}
|
||||
if (kit.getDelay() != 0 && player.isOp()) {
|
||||
lore.add("");
|
||||
lore.add(ChatColor.GRAY + "You do not have a delay");
|
||||
lore.add(ChatColor.GRAY + "because you have perms");
|
||||
lore.add(ChatColor.GRAY + "to bypass the delay.");
|
||||
}
|
||||
|
||||
if (back != null && !plugin.getConfig().getBoolean("Interfaces.Do Not Use Glass Borders")) {
|
||||
|
||||
ItemStack head = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3);
|
||||
ItemStack skull2 = Methods.addTexture(head, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
SkullMeta skull2Meta = (SkullMeta) skull2.getItemMeta();
|
||||
skull2.setDurability((short) 3);
|
||||
skull2Meta.setDisplayName(plugin.getLocale().getMessage("interface.button.back").getMessage());
|
||||
skull2.setItemMeta(skull2Meta);
|
||||
inventory.setItem(0, skull2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerClickables() {
|
||||
registerClickable(0, (player, inventory, cursor, slot, type) -> {
|
||||
if (back == null) return;
|
||||
back.init(back.getSetTitle(), back.getInventory().getSize());
|
||||
});
|
||||
|
||||
registerClickable(8, (player, inventory, cursor, slot, type) -> player.closeInventory());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerOnCloses() {
|
||||
|
||||
return lore;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.songoda.ultimatekits.gui;
|
||||
|
||||
import com.songoda.core.utils.ItemUtils;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
@ -54,8 +55,7 @@ public class GUIGUIOptions extends AbstractGUI {
|
||||
createButton(8, Material.valueOf(UltimateKits.getInstance().getConfig().getString("Interfaces.Exit Icon")),
|
||||
UltimateKits.getInstance().getLocale().getMessage("interface.button.exit").getMessage());
|
||||
|
||||
ItemStack head = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3);
|
||||
ItemStack back = Methods.addTexture(head, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
ItemStack back = ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
SkullMeta skull2Meta = (SkullMeta) back.getItemMeta();
|
||||
back.setDurability((short) 3);
|
||||
skull2Meta.setDisplayName(UltimateKits.getInstance().getLocale().getMessage("interface.button.back").getMessage());
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.songoda.ultimatekits.gui;
|
||||
|
||||
import com.songoda.core.utils.ItemUtils;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
@ -52,8 +53,7 @@ public class GUIGeneralOptions extends AbstractGUI {
|
||||
createButton(8, Material.valueOf(UltimateKits.getInstance().getConfig().getString("Interfaces.Exit Icon")),
|
||||
UltimateKits.getInstance().getLocale().getMessage("interface.button.exit").getMessage());
|
||||
|
||||
ItemStack head = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3);
|
||||
ItemStack back = Methods.addTexture(head, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
ItemStack back = ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
SkullMeta skull2Meta = (SkullMeta) back.getItemMeta();
|
||||
back.setDurability((short) 3);
|
||||
skull2Meta.setDisplayName(UltimateKits.getInstance().getLocale().getMessage("interface.button.back")
|
||||
|
@ -1,18 +1,18 @@
|
||||
package com.songoda.ultimatekits.gui;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleSound;
|
||||
import com.songoda.core.utils.ItemUtils;
|
||||
import com.songoda.core.utils.TextUtils;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.kit.KitAnimation;
|
||||
import com.songoda.ultimatekits.kit.KitItem;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import com.songoda.ultimatekits.utils.ServerVersion;
|
||||
import com.songoda.ultimatekits.utils.gui.AbstractAnvilGUI;
|
||||
import com.songoda.ultimatekits.utils.gui.AbstractGUI;
|
||||
import com.songoda.ultimatekits.utils.gui.Range;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
@ -67,9 +67,7 @@ public class GUIKitEditor extends AbstractGUI {
|
||||
createButton(8, Material.valueOf(UltimateKits.getInstance().getConfig().getString("Interfaces.Exit Icon")),
|
||||
UltimateKits.getInstance().getLocale().getMessage("interface.button.exit").getMessage());
|
||||
|
||||
ItemStack head = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3);
|
||||
ItemStack back;
|
||||
back = Methods.addTexture(head, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
ItemStack back = ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
SkullMeta skull2Meta = (SkullMeta) back.getItemMeta();
|
||||
back.setDurability((short) 3);
|
||||
skull2Meta.setDisplayName(UltimateKits.getInstance().getLocale().getMessage("interface.button.back").getMessage());
|
||||
@ -116,7 +114,7 @@ public class GUIKitEditor extends AbstractGUI {
|
||||
|
||||
if (meta.hasLore()) itemLore = meta.getLore();
|
||||
else itemLore = new ArrayList<>();
|
||||
itemLore.add(Methods.convertToInvisibleString("----"));
|
||||
itemLore.add(TextUtils.convertToInvisibleLoreString("----"));
|
||||
itemLore.add(Methods.formatText("&7" + plugin.getLocale().getMessage("general.type.chance") + ": &6" + item.getChance() + "%"));
|
||||
if (isInFuction) {
|
||||
itemLore.add(Methods.formatText("&7Display Item: &6" + (item.getDisplayItem() == null ? "" : item.getDisplayItem().name())));
|
||||
@ -286,7 +284,7 @@ public class GUIKitEditor extends AbstractGUI {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
List<String> newLore = new ArrayList<>();
|
||||
for (String line : meta.getLore()) {
|
||||
if (line.equals(Methods.convertToInvisibleString("----"))) break;
|
||||
if (TextUtils.convertFromInvisibleString(line).equals("----")) break;
|
||||
newLore.add(line);
|
||||
}
|
||||
meta.setLore(newLore);
|
||||
@ -529,7 +527,7 @@ public class GUIKitEditor extends AbstractGUI {
|
||||
player.updateInventory();
|
||||
}
|
||||
|
||||
player.playSound(player.getLocation(), plugin.isServerVersionAtLeast(ServerVersion.V1_9) ? Sound.ENTITY_VILLAGER_YES : Sound.valueOf("VILLAGER_YES"), 1F, 1F);
|
||||
CompatibleSound.ENTITY_VILLAGER_YES.play(player);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.songoda.ultimatekits.gui;
|
||||
|
||||
import com.songoda.core.utils.ItemUtils;
|
||||
import com.songoda.core.utils.TextUtils;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
@ -156,7 +158,7 @@ public class GUIKitSelector extends AbstractGUI {
|
||||
if (kit.getDisplayItem() != null)
|
||||
item.setType(kit.getDisplayItem());
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(Methods.convertToInvisibleString(kitItem + ":") + Methods.formatText(title));
|
||||
meta.setDisplayName(TextUtils.convertToInvisibleString(kitItem + ":") + Methods.formatText(title));
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
if (kit.getPrice() != 0)
|
||||
lore.add(Methods.formatText("&7This kit costs &a$" + kit.getPrice() + "&7."));
|
||||
@ -261,14 +263,13 @@ public class GUIKitSelector extends AbstractGUI {
|
||||
infometa.setLore(lore);
|
||||
info.setItemMeta(infometa);
|
||||
|
||||
ItemStack head = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3);
|
||||
ItemStack skull = Methods.addTexture(head, "http://textures.minecraft.net/texture/1b6f1a25b6bc199946472aedb370522584ff6f4e83221e5946bd2e41b5ca13b");
|
||||
ItemStack skull = ItemUtils.getCustomHead("1b6f1a25b6bc199946472aedb370522584ff6f4e83221e5946bd2e41b5ca13b");
|
||||
SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
|
||||
skull.setDurability((short) 3);
|
||||
skullMeta.setDisplayName(plugin.getLocale().getMessage("interface.button.next").getMessage());
|
||||
skull.setItemMeta(skullMeta);
|
||||
|
||||
ItemStack skull2 = Methods.addTexture(head, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
ItemStack skull2 = ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
SkullMeta skull2Meta = (SkullMeta) skull2.getItemMeta();
|
||||
skull2.setDurability((short) 3);
|
||||
skull2Meta.setDisplayName(plugin.getLocale().getMessage("interface.button.next").getMessage());
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.songoda.ultimatekits.gui;
|
||||
|
||||
import com.songoda.core.utils.ItemUtils;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import com.songoda.ultimatekits.utils.ServerVersion;
|
||||
import com.songoda.ultimatekits.utils.gui.AbstractAnvilGUI;
|
||||
import com.songoda.ultimatekits.utils.gui.AbstractGUI;
|
||||
import org.bukkit.Material;
|
||||
@ -54,8 +54,7 @@ public class GUISellingOptions extends AbstractGUI {
|
||||
createButton(8, Material.valueOf(UltimateKits.getInstance().getConfig().getString("Interfaces.Exit Icon")),
|
||||
UltimateKits.getInstance().getLocale().getMessage("interface.button.exit").getMessage());
|
||||
|
||||
ItemStack head = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3);
|
||||
ItemStack back = Methods.addTexture(head, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
ItemStack back = ItemUtils.getCustomHead("3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
SkullMeta skull2Meta = (SkullMeta) back.getItemMeta();
|
||||
back.setDurability((short) 3);
|
||||
skull2Meta.setDisplayName(UltimateKits.getInstance().getLocale().getMessage("interface.button.back")
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.songoda.ultimatekits.handlers;
|
||||
|
||||
import com.songoda.core.utils.TextUtils;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.kit.KitBlockData;
|
||||
@ -26,6 +27,9 @@ public class DisplayItemHandler {
|
||||
|
||||
public DisplayItemHandler(UltimateKits instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(UltimateKits.getInstance(), this::displayItems, 30L, 30L);
|
||||
}
|
||||
|
||||
@ -39,10 +43,11 @@ public class DisplayItemHandler {
|
||||
location.add(0.5, 0, 0.5);
|
||||
|
||||
Kit kit = kitBlockData.getKit();
|
||||
|
||||
if (kit.getReadableContents(null, false, false, false) == null) return;
|
||||
if (kit == null) return;
|
||||
|
||||
List<ItemStack> list = kit.getReadableContents(null, false, false, false);
|
||||
if (list == null) return;
|
||||
|
||||
if (list.isEmpty()) return;
|
||||
for (Entity e : location.getChunk().getEntities()) {
|
||||
if (e.getType() != EntityType.DROPPED_ITEM
|
||||
@ -64,7 +69,7 @@ public class DisplayItemHandler {
|
||||
}
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
is.setAmount(1);
|
||||
meta.setDisplayName(Methods.convertToInvisibleString(Integer.toString(inum)));
|
||||
meta.setDisplayName(TextUtils.convertToInvisibleString(Integer.toString(inum)));
|
||||
is.setItemMeta(meta);
|
||||
i.setItemStack(is);
|
||||
i.setPickupDelay(9999);
|
||||
@ -75,7 +80,7 @@ public class DisplayItemHandler {
|
||||
ItemStack is = list.get(0);
|
||||
is.setAmount(1);
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
meta.setDisplayName(Methods.convertToInvisibleString("0"));
|
||||
meta.setDisplayName(TextUtils.convertFromInvisibleString("0"));
|
||||
is.setItemMeta(meta);
|
||||
Item item = location.getWorld().dropItem(location.add(0, 1, 0), list.get(0));
|
||||
Vector vec = new Vector(0, 0, 0);
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.songoda.ultimatekits.handlers;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleParticleHandler;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.KitBlockData;
|
||||
import com.songoda.ultimatekits.utils.ServerVersion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
||||
@ -14,17 +14,26 @@ import java.util.Map;
|
||||
public class ParticleHandler {
|
||||
|
||||
private final UltimateKits plugin;
|
||||
int amt;
|
||||
String typeName;
|
||||
CompatibleParticleHandler.ParticleType type;
|
||||
|
||||
public ParticleHandler(UltimateKits plugin) {
|
||||
this.plugin = plugin;
|
||||
checkDefaults();
|
||||
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(UltimateKits.getInstance(), this::applyParticles, 0, 10L);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
amt = plugin.getConfig().getInt("data.particlesettings.ammount") / 2;
|
||||
typeName = plugin.getConfig().getString("data.particlesettings.type");
|
||||
type = CompatibleParticleHandler.ParticleType.getParticle(typeName);
|
||||
if (type == null) {
|
||||
type = CompatibleParticleHandler.ParticleType.SPELL_WITCH;
|
||||
}
|
||||
Bukkit.getServer().getScheduler().runTaskTimerAsynchronously(UltimateKits.getInstance(), this::applyParticles, 0, 5L);
|
||||
}
|
||||
|
||||
private void applyParticles() {
|
||||
int amt = plugin.getConfig().getInt("data.particlesettings.ammount");
|
||||
String type = plugin.getConfig().getString("data.particlesettings.type");
|
||||
|
||||
Map<Location, KitBlockData> kitBlocks = plugin.getKitManager().getKitLocations();
|
||||
for (KitBlockData kitBlockData : kitBlocks.values()) {
|
||||
if (kitBlockData.getLocation().getWorld() == null || !kitBlockData.hasParticles()) continue;
|
||||
@ -32,9 +41,7 @@ public class ParticleHandler {
|
||||
Location location = kitBlockData.getLocation();
|
||||
location.add(.5, 0, .5);
|
||||
|
||||
if (plugin.isServerVersionAtLeast(ServerVersion.V1_9))
|
||||
location.getWorld().spawnParticle(org.bukkit.Particle.valueOf(type), location, amt, 0.25, 0.25, 0.25);
|
||||
|
||||
CompatibleParticleHandler.spawnParticles(type, location, amt, 0.25, 0.25, 0.25, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,176 +0,0 @@
|
||||
package com.songoda.ultimatekits.hologram;
|
||||
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.kit.KitBlockData;
|
||||
import com.songoda.ultimatekits.kit.KitType;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class Hologram {
|
||||
|
||||
protected final UltimateKits instance;
|
||||
|
||||
Hologram(UltimateKits instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public void loadHolograms() {
|
||||
Collection<KitBlockData> kitBlocks = instance.getKitManager().getKitLocations().values();
|
||||
if (kitBlocks.size() == 0) return;
|
||||
|
||||
for (KitBlockData data : kitBlocks) {
|
||||
if (data.getWorld() == null) continue;
|
||||
add(data);
|
||||
}
|
||||
}
|
||||
|
||||
public void unloadHolograms() {
|
||||
Collection<KitBlockData> kitBlocks = instance.getKitManager().getKitLocations().values();
|
||||
if (kitBlocks.size() == 0) return;
|
||||
|
||||
for (KitBlockData data : kitBlocks) {
|
||||
if (data.getWorld() == null) continue;
|
||||
remove(data);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(KitBlockData data) {
|
||||
format(data, Action.ADD);
|
||||
}
|
||||
|
||||
public void remove(KitBlockData data) {
|
||||
format(data, Action.REMOVE);
|
||||
}
|
||||
|
||||
public void remove(Kit kit) {
|
||||
for (KitBlockData data : instance.getKitManager().getKitLocations().values()) {
|
||||
if (data.getKit() != kit) continue;
|
||||
remove(data);
|
||||
}
|
||||
}
|
||||
|
||||
public void update(KitBlockData data) {
|
||||
format(data, Action.UPDATE);
|
||||
}
|
||||
|
||||
public void update(Kit kit) {
|
||||
for (KitBlockData data : instance.getKitManager().getKitLocations().values()) {
|
||||
if (data.getKit() != kit) continue;
|
||||
update(data);
|
||||
}
|
||||
}
|
||||
|
||||
private void format(KitBlockData data, Action action) {
|
||||
if (data == null) return;
|
||||
instance.getDataManager().updateBlockData(data);
|
||||
KitType kitType = data.getType();
|
||||
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
|
||||
List<String> order = instance.getConfig().getStringList("Main.Hologram Layout");
|
||||
|
||||
Kit kit = data.getKit();
|
||||
|
||||
for (String o : order) {
|
||||
switch (o.toUpperCase()) {
|
||||
case "{TITLE}":
|
||||
String title = kit.getTitle();
|
||||
if (title == null) {
|
||||
lines.add(Methods.formatText("&5" + Methods.formatText(kit.getName(), true)));
|
||||
} else {
|
||||
lines.add(Methods.formatText("&5" + Methods.formatText(title)));
|
||||
}
|
||||
break;
|
||||
case "{RIGHT-CLICK}":
|
||||
if (kitType == KitType.CRATE) {
|
||||
lines.add(Methods.formatText(instance.getLocale().getMessage("interface.hologram.crate")
|
||||
.getMessage()));
|
||||
break;
|
||||
}
|
||||
if (kit.getLink() != null) {
|
||||
lines.add(Methods.formatText(instance.getLocale().getMessage("interface.hologram.buylink")
|
||||
.getMessage()));
|
||||
break;
|
||||
}
|
||||
if (kit.getPrice() != 0) {
|
||||
lines.add(Methods.formatText(instance.getLocale().getMessage("interface.hologram.buyeco")
|
||||
.processPlaceholder("price", kit.getPrice() != 0
|
||||
? Methods.formatEconomy(kit.getPrice())
|
||||
: instance.getLocale().getMessage("general.type.free").getMessage())
|
||||
.getMessage()));
|
||||
}
|
||||
break;
|
||||
case "{LEFT-CLICK}":
|
||||
if (kitType == KitType.CLAIM) {
|
||||
lines.add(Methods.formatText(instance.getLocale().getMessage("interface.hologram.daily")
|
||||
.getMessage()));
|
||||
break;
|
||||
}
|
||||
if (kit.getLink() == null && kit.getPrice() == 0) {
|
||||
lines.add(Methods.formatText(instance.getLocale().getMessage("interface.hologram.previewonly")
|
||||
.getMessage()));
|
||||
} else {
|
||||
lines.add(Methods.formatText(instance.getLocale().getMessage("interface.hologram.preview")
|
||||
.getMessage()));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
lines.add(Methods.formatText(o));
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
double multi = .25 * lines.size();
|
||||
Location location = data.getLocation();
|
||||
Block b = location.getBlock();
|
||||
|
||||
if (data.isDisplayingItems()) multi += .40;
|
||||
|
||||
if (b.getType() == Material.TRAPPED_CHEST
|
||||
|| b.getType() == Material.CHEST
|
||||
|| b.getType().name().contains("SIGN")
|
||||
|| b.getType() == Material.ENDER_CHEST) multi -= .15;
|
||||
|
||||
location.add(0, multi, 0);
|
||||
|
||||
if (!data.showHologram()) {
|
||||
remove(location);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
case UPDATE:
|
||||
update(location, lines);
|
||||
break;
|
||||
case ADD:
|
||||
add(location, lines);
|
||||
break;
|
||||
case REMOVE:
|
||||
remove(location);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void add(Location location, ArrayList<String> lines);
|
||||
|
||||
protected abstract void remove(Location location);
|
||||
|
||||
protected abstract void update(Location location, ArrayList<String> lines);
|
||||
|
||||
public enum Action {
|
||||
|
||||
UPDATE, ADD, REMOVE
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
package com.songoda.ultimatekits.hologram;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class HologramHolographicDisplays extends Hologram {
|
||||
|
||||
|
||||
public HologramHolographicDisplays(UltimateKits instance) {
|
||||
super(instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Location location, ArrayList<String> lines) {
|
||||
fixLocation(location);
|
||||
|
||||
com.gmail.filoghost.holographicdisplays.api.Hologram hologram = HologramsAPI.createHologram(instance, location);
|
||||
for (String line : lines) {
|
||||
hologram.appendTextLine(line);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Location location) {
|
||||
fixLocation(location);
|
||||
for (com.gmail.filoghost.holographicdisplays.api.Hologram hologram : HologramsAPI.getHolograms(instance)) {
|
||||
if (hologram.getX() != location.getX()
|
||||
|| hologram.getY() != location.getY()
|
||||
|| hologram.getZ() != location.getZ()) continue;
|
||||
hologram.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Location location, ArrayList<String> lines) {
|
||||
for (com.gmail.filoghost.holographicdisplays.api.Hologram hologram : HologramsAPI.getHolograms(instance)) {
|
||||
if (hologram.getX() != location.getX()
|
||||
|| hologram.getY() != location.getY()
|
||||
|| hologram.getZ() != location.getZ()) continue;
|
||||
fixLocation(location);
|
||||
hologram.clearLines();
|
||||
for (String line : lines) {
|
||||
hologram.appendTextLine(line);
|
||||
}
|
||||
return;
|
||||
}
|
||||
add(location, lines);
|
||||
}
|
||||
|
||||
private void fixLocation(Location location) {
|
||||
location.add(.5, 1.3, .5);
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.songoda.ultimatekits.key;
|
||||
|
||||
import com.songoda.core.utils.TextUtils;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
@ -10,6 +11,7 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class Key {
|
||||
|
||||
@ -35,7 +37,7 @@ public class Key {
|
||||
|
||||
String kitName;
|
||||
if (kit != null)
|
||||
kitName = Methods.formatText(kit.getShowableName(), true);
|
||||
kitName = TextUtils.formatText(kit.getShowableName(), true);
|
||||
else
|
||||
kitName = "Any";
|
||||
|
||||
@ -45,7 +47,7 @@ public class Key {
|
||||
|
||||
meta.addEnchant(Enchantment.DURABILITY, 1, true);
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(Methods.formatText("&e" + name + " &fKey"));
|
||||
lore.add(ChatColor.YELLOW + name + " " + ChatColor.WHITE + "Key");
|
||||
|
||||
String desc1 = plugin.getLocale().getMessage("interface.key.description1")
|
||||
.processPlaceholder("kit", kitName).getMessage();
|
||||
@ -55,7 +57,7 @@ public class Key {
|
||||
else
|
||||
desc1 = desc1.replace("[", "").replace("]", "");
|
||||
|
||||
lore.add(Methods.formatText(desc1));
|
||||
lore.add(desc1);
|
||||
if (this.amt == -1)
|
||||
lore.add(plugin.getLocale().getMessage("interface.key.description2").getMessage());
|
||||
else
|
||||
|
@ -1,5 +1,11 @@
|
||||
package com.songoda.ultimatekits.kit;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleSound;
|
||||
import com.songoda.core.configuration.Config;
|
||||
import com.songoda.core.gui.Gui;
|
||||
import com.songoda.core.gui.GuiManager;
|
||||
import com.songoda.core.hooks.EconomyManager;
|
||||
import com.songoda.core.utils.TextUtils;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.gui.GUIConfirmBuy;
|
||||
import com.songoda.ultimatekits.gui.GUIDisplayKit;
|
||||
@ -10,15 +16,12 @@ import com.songoda.ultimatekits.kit.type.KitContentItem;
|
||||
import com.songoda.ultimatekits.tasks.CrateAnimateTask;
|
||||
import com.songoda.ultimatekits.utils.ArmorType;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import com.songoda.ultimatekits.utils.ServerVersion;
|
||||
import com.songoda.ultimatekits.utils.gui.AbstractGUI;
|
||||
import com.songoda.ultimatekits.utils.settings.Setting;
|
||||
import com.songoda.ultimatekits.settings.Settings;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@ -139,13 +142,13 @@ public class Kit {
|
||||
}
|
||||
|
||||
public void processPurchaseUse(Player player) {
|
||||
if (plugin.getEconomy() == null) return;
|
||||
if (!EconomyManager.isEnabled()) return;
|
||||
|
||||
if (!player.hasPermission("ultimatekits.buy." + name)) {
|
||||
UltimateKits.getInstance().getLocale().getMessage("command.general.noperms")
|
||||
.sendPrefixedMessage(player);
|
||||
return;
|
||||
} else if (!plugin.getEconomy().hasBalance(player, price)) {
|
||||
} else if (!EconomyManager.hasBalance(player, price)) {
|
||||
plugin.getLocale().getMessage("event.claim.cannotafford")
|
||||
.processPlaceholder("kit", showableName).sendPrefixedMessage(player);
|
||||
return;
|
||||
@ -161,7 +164,7 @@ public class Kit {
|
||||
}
|
||||
}
|
||||
if (giveKit(player)) {
|
||||
plugin.getEconomy().withdrawBalance(player, price);
|
||||
EconomyManager.withdrawBalance(player, price);
|
||||
if (delay != 0)
|
||||
updateDelay(player); //updates delay on buy
|
||||
}
|
||||
@ -188,7 +191,7 @@ public class Kit {
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void display(Player player, AbstractGUI back) {
|
||||
public void display(Player player, GuiManager manager, Gui back) {
|
||||
if (!player.hasPermission("previewkit.use")
|
||||
&& !player.hasPermission("previewkit." + name)
|
||||
&& !player.hasPermission("ultimatekits.use")
|
||||
@ -216,7 +219,7 @@ public class Kit {
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
List<String> newLore = new ArrayList<>();
|
||||
for (String line : meta.getLore()) {
|
||||
if (line.equals(Methods.convertToInvisibleString("----"))) break;
|
||||
if (TextUtils.convertFromInvisibleString(line).equals("----")) break;
|
||||
newLore.add(line);
|
||||
}
|
||||
meta.setLore(newLore);
|
||||
@ -244,7 +247,7 @@ public class Kit {
|
||||
public List<ItemStack> getReadableContents(Player player, boolean preview, boolean commands, boolean moveable) {
|
||||
List<ItemStack> stacks = new ArrayList<>();
|
||||
for (KitItem item : getContents()) {
|
||||
if ((!item.getSerialized().startsWith("/") && !item.getSerialized().startsWith(plugin.getConfig().getString("Main.Currency Symbol"))) || commands) { //ToDO: I doubt this is correct.
|
||||
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();
|
||||
|
||||
@ -274,10 +277,8 @@ public class Kit {
|
||||
plugin.getLocale().getMessage("event.claim.full").sendPrefixedMessage(player);
|
||||
return false;
|
||||
}
|
||||
if (plugin.getConfig().getBoolean("Main.Sounds Enabled")
|
||||
&& kitAnimation == KitAnimation.NONE
|
||||
&& UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_12))
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 0.6F, 15.0F);
|
||||
if (plugin.getConfig().getBoolean("Main.Sounds Enabled") && kitAnimation == KitAnimation.NONE)
|
||||
CompatibleSound.ENTITY_PLAYER_LEVELUP.play(player, 0.6F, 15.0F);
|
||||
|
||||
List<KitItem> innerContents = new ArrayList<>(getContents());
|
||||
int amt = innerContents.size();
|
||||
@ -293,7 +294,7 @@ public class Kit {
|
||||
if (rand - ch < 0 || ch == 100) {
|
||||
if (item.getContent() instanceof KitContentEconomy) {
|
||||
try {
|
||||
Methods.pay(player, ((KitContentEconomy) item.getContent()).getAmount());
|
||||
EconomyManager.deposit(player, ((KitContentEconomy) item.getContent()).getAmount());
|
||||
plugin.getLocale().getMessage("event.claim.eco")
|
||||
.processPlaceholder("amt", Methods.formatEconomy(((KitContentEconomy) item.getContent()).getAmount()))
|
||||
.sendPrefixedMessage(player);
|
||||
@ -331,7 +332,7 @@ public class Kit {
|
||||
new CrateAnimateTask(plugin, player, this, item.getItem());
|
||||
return true;
|
||||
} else {
|
||||
if (Setting.AUTO_EQUIP_ARMOR.getBoolean() && ArmorType.equip(player, item.getItem())) continue;
|
||||
if (Settings.AUTO_EQUIP_ARMOR.getBoolean() && ArmorType.equip(player, item.getItem())) continue;
|
||||
|
||||
Map<Integer, ItemStack> overfilled = player.getInventory().addItem(item.getItem());
|
||||
for (ItemStack item2 : overfilled.values()) {
|
||||
@ -346,18 +347,17 @@ public class Kit {
|
||||
}
|
||||
|
||||
public void updateDelay(Player player) {
|
||||
plugin.getDataFile().getConfig().set("Kits." + name + ".delays." + player.getUniqueId().toString(), System.currentTimeMillis());
|
||||
plugin.getDataFile().set("Kits." + name + ".delays." + player.getUniqueId().toString(), System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public Long getNextUse(Player player) {
|
||||
String configSectionPlayer = "Kits." + name + ".delays." + player.getUniqueId().toString();
|
||||
FileConfiguration config = plugin.getDataFile().getConfig();
|
||||
Config config = plugin.getDataFile();
|
||||
|
||||
if (!config.contains(configSectionPlayer)) {
|
||||
return 0L;
|
||||
} else if (this.delay == -1) return -1L;
|
||||
|
||||
|
||||
long last = config.getLong(configSectionPlayer);
|
||||
long delay = (long) this.delay * 1000;
|
||||
|
||||
|
@ -34,8 +34,7 @@ public class KitBlockData {
|
||||
setHasParticles(false);
|
||||
UltimateKits.getInstance().getDisplayItemHandler().displayItem(this);
|
||||
|
||||
if (UltimateKits.getInstance().getHologram() != null)
|
||||
UltimateKits.getInstance().getHologram().remove(this);
|
||||
UltimateKits.getInstance().removeHologram(this);
|
||||
UltimateKits.getInstance().getDataManager().updateBlockData(this);
|
||||
}
|
||||
|
||||
@ -47,6 +46,10 @@ public class KitBlockData {
|
||||
return location.clone();
|
||||
}
|
||||
|
||||
public boolean isInLoadedChunk() {
|
||||
return location != null && location.getWorld() != null && location.getWorld().isChunkLoaded(((int) location.getX()) >> 4, ((int) location.getZ()) >> 4);
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return location.getBlockX();
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
package com.songoda.ultimatekits.kit;
|
||||
|
||||
import com.songoda.core.utils.TextUtils;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.kit.type.KitContent;
|
||||
import com.songoda.ultimatekits.kit.type.KitContentCommand;
|
||||
import com.songoda.ultimatekits.kit.type.KitContentEconomy;
|
||||
import com.songoda.ultimatekits.kit.type.KitContentItem;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import com.songoda.ultimatekits.utils.settings.Setting;
|
||||
import com.songoda.ultimatekits.settings.Settings;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -56,7 +56,7 @@ public class KitItem {
|
||||
}
|
||||
|
||||
private void processContent(String line, ItemStack item) {
|
||||
if (line.startsWith(Setting.CURRENCY_SYMBOL.getString())) {
|
||||
if (line.startsWith(Settings.CURRENCY_SYMBOL.getString())) {
|
||||
this.content = new KitContentEconomy(Double.parseDouble(line.substring(1).trim()));
|
||||
} else if (line.startsWith("/")) {
|
||||
this.content = new KitContentCommand(line.substring(1));
|
||||
@ -159,9 +159,9 @@ public class KitItem {
|
||||
if (chance != 0 || displayItem != null || displayName != null || displayLore != null) {
|
||||
String capitalizedName = meta.hasDisplayName() ? meta.getDisplayName() :
|
||||
WordUtils.capitalize(item.getType().toString().toLowerCase().replace("_", " "));
|
||||
if (capitalizedName.contains(Methods.convertToInvisibleString(";faqe")))
|
||||
capitalizedName = meta.getDisplayName().split(Methods.convertToInvisibleString(";faqe"))[1];
|
||||
meta.setDisplayName(Methods.convertToInvisibleString(compileOptions() + ";faqe") + ChatColor.RESET + capitalizedName);
|
||||
if (capitalizedName.contains(TextUtils.convertToInvisibleString(";faqe")))
|
||||
capitalizedName = meta.getDisplayName().split(TextUtils.convertToInvisibleString(";faqe"))[1];
|
||||
meta.setDisplayName(TextUtils.convertToInvisibleString(compileOptions() + ";faqe") + ChatColor.RESET + capitalizedName);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
@ -175,10 +175,10 @@ public class KitItem {
|
||||
item.setType(displayItem);
|
||||
}
|
||||
if (displayName != null) {
|
||||
meta.setDisplayName(Methods.formatText(displayName));
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', displayName));
|
||||
}
|
||||
if (displayLore != null) {
|
||||
meta.setLore(Arrays.asList(Methods.formatText(displayLore)));
|
||||
meta.setLore(Arrays.asList(ChatColor.translateAlternateColorCodes('&', displayLore)));
|
||||
}
|
||||
|
||||
if (UltimateKits.getInstance().getConfig().getBoolean("Main.Display Chance In Preview")) {
|
||||
@ -190,7 +190,7 @@ public class KitItem {
|
||||
}
|
||||
|
||||
if (lore.size() != 0) lore.addFirst("");
|
||||
lore.addFirst(Methods.formatText("&7" + UltimateKits.getInstance().getLocale().getMessage("general.type.chance") + ": &6" + (chance == 0 ? 100 : chance) + "%"));
|
||||
lore.addFirst(ChatColor.GRAY.toString() + UltimateKits.getInstance().getLocale().getMessage("general.type.chance") + ": " + ChatColor.GOLD + (chance == 0 ? 100 : chance) + "%");
|
||||
meta.setLore(new ArrayList<>(lore));
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.songoda.ultimatekits.kit;
|
||||
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.*;
|
||||
@ -37,8 +36,7 @@ public final class KitManager {
|
||||
|
||||
public void addKitToLocation(Kit kit, Location location, KitType type, boolean hologram, boolean particles, boolean items, boolean itemOverride) {
|
||||
KitBlockData kitBlockData = kitsAtLocations.put(roundLocation(location), new KitBlockData(kit, location, type, hologram, particles, items, itemOverride));
|
||||
if (UltimateKits.getInstance().getHologram() != null)
|
||||
UltimateKits.getInstance().getHologram().update(kitBlockData);
|
||||
UltimateKits.getInstance().updateHologram(kitBlockData);
|
||||
}
|
||||
|
||||
public Kit removeKitFromLocation(Location location) {
|
||||
|
@ -1,16 +1,16 @@
|
||||
package com.songoda.ultimatekits.kit.type;
|
||||
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class KitContentCommand implements KitContent {
|
||||
|
||||
private String command; // Stored like "eco give <player> 100"
|
||||
private final String command; // Stored like "eco give <player> 100"
|
||||
|
||||
public KitContentCommand(String command) {
|
||||
this.command = command;
|
||||
@ -32,7 +32,7 @@ public class KitContentCommand implements KitContent {
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
int index = 0;
|
||||
while (index < command.length()) {
|
||||
lore.add(Methods.formatText("&a" + (index == 0 ? "/" : "") + "&a" + command.substring(index, Math.min(index + 30, command.length()))));
|
||||
lore.add(ChatColor.GREEN + (index == 0 ? "/" : "") + ChatColor.GREEN + command.substring(index, Math.min(index + 30, command.length())));
|
||||
index += 30;
|
||||
}
|
||||
meta.setLore(lore);
|
||||
|
@ -1,16 +1,16 @@
|
||||
package com.songoda.ultimatekits.kit.type;
|
||||
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class KitContentEconomy implements KitContent {
|
||||
|
||||
private double amount;
|
||||
private final double amount;
|
||||
|
||||
public KitContentEconomy(double amount) {
|
||||
this.amount = amount;
|
||||
@ -34,7 +34,7 @@ public class KitContentEconomy implements KitContent {
|
||||
|
||||
int index = 0;
|
||||
while (index < String.valueOf(amount).length()) {
|
||||
lore.add(Methods.formatText("&a" + (index == 0 ? UltimateKits.getInstance().getConfig().getString("Main.Currency Symbol") : "") + "&a" + String.valueOf(amount).substring(index, Math.min(index + 30, 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())));
|
||||
index += 30;
|
||||
}
|
||||
meta.setLore(lore);
|
||||
|
@ -5,7 +5,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class KitContentItem implements KitContent {
|
||||
|
||||
private ItemStack itemStack;
|
||||
private final ItemStack itemStack;
|
||||
|
||||
private String serialized = null;
|
||||
|
||||
|
@ -28,8 +28,7 @@ public class BlockListeners implements Listener {
|
||||
if (kitBlockData == null) return;
|
||||
Kit kit = kitBlockData.getKit();
|
||||
|
||||
if (instance.getHologram() != null)
|
||||
instance.getHologram().remove(kitBlockData);
|
||||
instance.removeHologram(kitBlockData);
|
||||
|
||||
instance.getKitManager().removeKitFromLocation(block.getLocation());
|
||||
|
||||
|
@ -1,12 +1,13 @@
|
||||
package com.songoda.ultimatekits.listeners;
|
||||
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import com.songoda.core.gui.GuiManager;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.gui.GUIBlockEditor;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.kit.KitBlockData;
|
||||
import com.songoda.ultimatekits.kit.KitType;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import com.songoda.ultimatekits.utils.ServerVersion;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -20,14 +21,16 @@ import org.bukkit.inventory.InventoryHolder;
|
||||
public class InteractListeners implements Listener {
|
||||
|
||||
private final UltimateKits plugin;
|
||||
private final GuiManager guiManager;
|
||||
|
||||
public InteractListeners(UltimateKits plugin) {
|
||||
public InteractListeners(UltimateKits plugin, GuiManager guiManager) {
|
||||
this.plugin = plugin;
|
||||
this.guiManager = guiManager;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockInteract(PlayerInteractEvent event) {
|
||||
if (plugin.isServerVersionAtLeast(ServerVersion.V1_9))
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9))
|
||||
if (event.getHand() == EquipmentSlot.OFF_HAND) return;
|
||||
|
||||
Block block = event.getClickedBlock();
|
||||
@ -68,7 +71,7 @@ public class InteractListeners implements Listener {
|
||||
} else if (kit.getLink() != null || kit.getPrice() != 0) {
|
||||
kit.buy(player);
|
||||
} else {
|
||||
kit.display(player, null);
|
||||
kit.display(player, guiManager, null);
|
||||
}
|
||||
} else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
if (block.getState() instanceof InventoryHolder || block.getType() == Material.ENDER_CHEST) {
|
||||
@ -83,7 +86,7 @@ public class InteractListeners implements Listener {
|
||||
kit.processKeyUse(player);
|
||||
return;
|
||||
}
|
||||
kit.display(player, null);
|
||||
kit.display(player, guiManager, null);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,82 @@
|
||||
package com.songoda.ultimatekits.settings;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.configuration.Config;
|
||||
import com.songoda.core.configuration.ConfigSetting;
|
||||
import com.songoda.core.hooks.EconomyManager;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Settings {
|
||||
|
||||
static final Config config = UltimateKits.getInstance().getConfig().getCoreConfig();
|
||||
|
||||
public static final ConfigSetting ONLY_SHOW_KITS_WITH_PERMS = new ConfigSetting(config, "Main.Only Show Players Kits They Have Permission To Use", false);
|
||||
public static final ConfigSetting KITS_FREE_WITH_PERMS = new ConfigSetting(config, "Main.Allow Players To Receive Kits For Free If They Have Permission", true);
|
||||
public static final ConfigSetting DONT_PREVIEW_COMMANDS = new ConfigSetting(config, "Main.Dont Preview Commands In Kits", false);
|
||||
public static final ConfigSetting HOLOGRAM_LAYOUT = new ConfigSetting(config, "Main.Hologram Layout", Arrays.asList("{TITLE}", "{LEFT-CLICK}", "{RIGHT-CLICK}"));
|
||||
public static final ConfigSetting SOUNDS_ENABLED = new ConfigSetting(config, "Main.Sounds Enabled", true);
|
||||
public static final ConfigSetting NO_REDEEM_WHEN_FULL = new ConfigSetting(config, "Main.Prevent The Redeeming of a Kit When Inventory Is Full", true);
|
||||
public static final ConfigSetting AUTO_EQUIP_ARMOR = new ConfigSetting(config, "Main.Automatically Equip Armor Given From a Kit", true);
|
||||
public static final ConfigSetting AUTO_EQUIP_ARMOR_ROULETTE = new ConfigSetting(config, "Main.Automatically Equip Armor Given From a Kit with the Roulette Animation", false);
|
||||
public static final ConfigSetting CHANCE_IN_PREVIEW = new ConfigSetting(config, "Main.Display Chance In Preview", true);
|
||||
public static final ConfigSetting CURRENCY_SYMBOL = new ConfigSetting(config, "Main.Currency Symbol", "$");
|
||||
|
||||
public static final ConfigSetting ECONOMY_PLUGIN = new ConfigSetting(config, "Main.Economy", EconomyManager.getEconomy() == null ? "Vault" : EconomyManager.getEconomy().getName(),
|
||||
"Which economy plugin should be used?",
|
||||
"Supported plugins you have installed: \"" + EconomyManager.getManager().getRegisteredPlugins().stream().collect(Collectors.joining("\", \"")) + "\".");
|
||||
|
||||
public static final ConfigSetting EXIT_ICON = new ConfigSetting(config, "Interfaces.Exit Icon", "OAK_DOOR");
|
||||
public static final ConfigSetting BUY_ICON = new ConfigSetting(config, "Interfaces.Buy Icon", "EMERALD");
|
||||
public static final ConfigSetting GLASS_TYPE_1 = new ConfigSetting(config, "Interfaces.Glass Type 1", 7);
|
||||
public static final ConfigSetting GLASS_TYPE_2 = new ConfigSetting(config, "Interfaces.Glass Type 2", 11);
|
||||
public static final ConfigSetting GLASS_TYPE_3 = new ConfigSetting(config, "Interfaces.Glass Type 3", 3);
|
||||
public static final ConfigSetting RAINBOW = new ConfigSetting(config, "Interfaces.Replace Glass Type 1 With Rainbow Glass", false);
|
||||
public static final ConfigSetting DO_NOT_USE_GLASS_BORDERS = new ConfigSetting(config, "Interfaces.Do Not Use Glass Borders", false);
|
||||
|
||||
public static final ConfigSetting LANGUGE_MODE = new ConfigSetting(config, "System.Language Mode", "en_US",
|
||||
"The enabled language file.",
|
||||
"More language files (if available) can be found in the plugins data folder.");
|
||||
|
||||
public static final ConfigSetting MYSQL_ENABLED = new ConfigSetting(config, "MySQL.Enabled", false, "Set to 'true' to use MySQL for data storage.");
|
||||
public static final ConfigSetting MYSQL_HOSTNAME = new ConfigSetting(config, "MySQL.Hostname", "localhost");
|
||||
public static final ConfigSetting MYSQL_PORT = new ConfigSetting(config, "MySQL.Port", 3306);
|
||||
public static final ConfigSetting MYSQL_DATABASE = new ConfigSetting(config, "MySQL.Database", "your-database");
|
||||
public static final ConfigSetting MYSQL_USERNAME = new ConfigSetting(config, "MySQL.Username", "user");
|
||||
public static final ConfigSetting MYSQL_PASSWORD = new ConfigSetting(config, "MySQL.Password", "pass");
|
||||
public static final ConfigSetting MYSQL_USE_SSL = new ConfigSetting(config, "MySQL.Use SSL", false);
|
||||
|
||||
/**
|
||||
* In order to set dynamic economy comment correctly, this needs to be
|
||||
* called after EconomyManager load
|
||||
*/
|
||||
public static void setupConfig() {
|
||||
config.load();
|
||||
config.setAutoremove(true).setAutosave(true);
|
||||
|
||||
// convert glass pane settings
|
||||
int color;
|
||||
if ((color = GLASS_TYPE_1.getInt(-1)) != -1) {
|
||||
config.set(GLASS_TYPE_1.getKey(), CompatibleMaterial.getGlassPaneColor(color).name());
|
||||
}
|
||||
if ((color = GLASS_TYPE_2.getInt(-1)) != -1) {
|
||||
config.set(GLASS_TYPE_2.getKey(), CompatibleMaterial.getGlassPaneColor(color).name());
|
||||
}
|
||||
if ((color = GLASS_TYPE_3.getInt(-1)) != -1) {
|
||||
config.set(GLASS_TYPE_3.getKey(), CompatibleMaterial.getGlassPaneColor(color).name());
|
||||
}
|
||||
|
||||
// convert economy settings
|
||||
if (config.getBoolean("Economy.Use Vault Economy") && EconomyManager.getManager().isEnabled("Vault")) {
|
||||
config.set("Main.Economy", "Vault");
|
||||
} else if (config.getBoolean("Economy.Use Reserve Economy") && EconomyManager.getManager().isEnabled("Reserve")) {
|
||||
config.set("Main.Economy", "Reserve");
|
||||
} else if (config.getBoolean("Economy.Use Player Points Economy") && EconomyManager.getManager().isEnabled("PlayerPoints")) {
|
||||
config.set("Main.Economy", "PlayerPoints");
|
||||
}
|
||||
|
||||
config.saveChanges();
|
||||
}
|
||||
}
|
@ -5,8 +5,7 @@ import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.kit.KitItem;
|
||||
import com.songoda.ultimatekits.utils.ArmorType;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import com.songoda.ultimatekits.utils.ServerVersion;
|
||||
import com.songoda.ultimatekits.utils.settings.Setting;
|
||||
import com.songoda.ultimatekits.settings.Settings;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@ -110,7 +109,7 @@ public class CrateAnimateTask extends BukkitRunnable {
|
||||
if (finish) {
|
||||
if (inventory.getItem(13).isSimilar(give)) {
|
||||
if (!done) {
|
||||
if (!Setting.AUTO_EQUIP_ARMOR_ROULETTE.getBoolean()
|
||||
if (!Settings.AUTO_EQUIP_ARMOR_ROULETTE.getBoolean()
|
||||
|| !ArmorType.equip(player, give)) {
|
||||
Map<Integer, ItemStack> overfilled = player.getInventory().addItem(give);
|
||||
for (ItemStack item2 : overfilled.values()) {
|
||||
|
@ -1,67 +0,0 @@
|
||||
package com.songoda.ultimatekits.utils;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* ConfigWrapper made by @clip
|
||||
*/
|
||||
public class ConfigWrapper {
|
||||
|
||||
private final JavaPlugin plugin;
|
||||
private final String folderName, fileName;
|
||||
private FileConfiguration config;
|
||||
private File configFile;
|
||||
|
||||
public ConfigWrapper(final JavaPlugin instance, final String folderName, final String fileName) {
|
||||
this.plugin = instance;
|
||||
this.folderName = folderName;
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public void createNewFile(final String message, final String header) {
|
||||
reloadConfig();
|
||||
saveConfig();
|
||||
loadConfig(header);
|
||||
|
||||
if (message != null) {
|
||||
plugin.getLogger().info(message);
|
||||
}
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig() {
|
||||
if (config == null) {
|
||||
reloadConfig();
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
public void loadConfig(final String header) {
|
||||
config.options().header(header);
|
||||
config.options().copyDefaults(true);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
if (configFile == null) {
|
||||
configFile = new File(plugin.getDataFolder() + folderName, fileName);
|
||||
}
|
||||
config = YamlConfiguration.loadConfiguration(configFile);
|
||||
}
|
||||
|
||||
public void saveConfig() {
|
||||
if (config == null || configFile == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
getConfig().save(configFile);
|
||||
} catch (final IOException ex) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Could not save config to " + configFile, ex);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.ultimatekits.utils;
|
||||
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -38,9 +38,9 @@ public class ItemSerializer {
|
||||
*/
|
||||
public ItemSerializer() throws NoSuchMethodException, SecurityException, ClassNotFoundException {
|
||||
methodParseString = classMojangsonParser.getMethod("parse", String.class);
|
||||
if (UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_13))
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13))
|
||||
methodToItemStack = classItemStack.getMethod("a", classNBTTagCompound);
|
||||
else if (UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_11))
|
||||
else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11))
|
||||
constructorItemStack = classItemStack.getConstructor(classNBTTagCompound);
|
||||
else
|
||||
methodCreateStack = classItemStack.getMethod("createStack", classNBTTagCompound);
|
||||
@ -74,9 +74,9 @@ public class ItemSerializer {
|
||||
Object nbtTagCompound = methodParseString.invoke(null, jsonString);
|
||||
Object citemStack;
|
||||
|
||||
if (UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_13))
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13))
|
||||
citemStack = methodToItemStack.invoke(null, nbtTagCompound);
|
||||
else if (UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_11))
|
||||
else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11))
|
||||
citemStack = constructorItemStack.newInstance(nbtTagCompound);
|
||||
else
|
||||
citemStack = methodCreateStack.invoke(null, nbtTagCompound);
|
||||
|
@ -1,19 +1,12 @@
|
||||
package com.songoda.ultimatekits.utils;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -23,43 +16,6 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
public class Methods {
|
||||
|
||||
|
||||
public static ItemStack getGlass() {
|
||||
UltimateKits instance = UltimateKits.getInstance();
|
||||
return Methods.getGlass(instance.getConfig().getBoolean("Interfaces.Replace Glass Type 1 With Rainbow Glass"), instance.getConfig().getInt("Interfaces.Glass Type 1"));
|
||||
}
|
||||
|
||||
public static ItemStack getBackgroundGlass(boolean type) {
|
||||
UltimateKits instance = UltimateKits.getInstance();
|
||||
if (type)
|
||||
return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 2"));
|
||||
else
|
||||
return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 3"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a glass itemstack
|
||||
*
|
||||
* @param rainbow Whether or not to assign a random color to the glass.
|
||||
* @param type If rainbow is false, the glass color.
|
||||
* @return A glass itemstack conforming to the params.
|
||||
*/
|
||||
public static ItemStack getGlass(boolean rainbow, int type) {
|
||||
int randomNum = 1 + (int) (Math.random() * 6);
|
||||
ItemStack glass;
|
||||
if (rainbow) {
|
||||
glass = new ItemStack(UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ?
|
||||
Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) randomNum);
|
||||
} else {
|
||||
glass = new ItemStack(UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ?
|
||||
Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) type);
|
||||
}
|
||||
ItemMeta glassmeta = glass.getItemMeta();
|
||||
glassmeta.setDisplayName("§l");
|
||||
glass.setItemMeta(glassmeta);
|
||||
return glass;
|
||||
}
|
||||
|
||||
public static boolean canGiveKit(Player player) {
|
||||
if (player.hasPermission("ultimatekits.cangive")) return true;
|
||||
|
||||
@ -67,22 +23,10 @@ public class Methods {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean pay(Player p, double amount) {
|
||||
if (UltimateKits.getInstance().getServer().getPluginManager().getPlugin("Vault") == null) return false;
|
||||
RegisteredServiceProvider<Economy> rsp = UltimateKits.getInstance().getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
|
||||
net.milkbowl.vault.economy.Economy econ = rsp.getProvider();
|
||||
|
||||
econ.depositPlayer(p, amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static String getKitFromLocation(Location location) {
|
||||
return UltimateKits.getInstance().getConfig().getString("data.block." + serializeLocation(location));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Serializes the location of the block specified.
|
||||
*
|
||||
@ -138,40 +82,6 @@ public class Methods {
|
||||
return location;
|
||||
}
|
||||
|
||||
|
||||
public static String convertToInvisibleString(String s) {
|
||||
if (s == null || s.equals(""))
|
||||
return "";
|
||||
StringBuilder hidden = new StringBuilder();
|
||||
for (char c : s.toCharArray()) hidden.append(ChatColor.COLOR_CHAR + "").append(c);
|
||||
return hidden.toString();
|
||||
}
|
||||
|
||||
public static String formatTitle(String text) {
|
||||
if (text == null || text.equals(""))
|
||||
return "";
|
||||
if (!UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_9)) {
|
||||
if (text.length() > 31)
|
||||
text = text.substring(0, 29) + "...";
|
||||
}
|
||||
text = formatText(text);
|
||||
return text;
|
||||
}
|
||||
|
||||
public static String formatText(String text) {
|
||||
if (text == null || text.equals(""))
|
||||
return "";
|
||||
return formatText(text, false);
|
||||
}
|
||||
|
||||
public static String formatText(String text, boolean cap) {
|
||||
if (text == null || text.equals(""))
|
||||
return "";
|
||||
if (cap)
|
||||
text = text.substring(0, 1).toUpperCase() + text.substring(1);
|
||||
return ChatColor.translateAlternateColorCodes('&', text);
|
||||
}
|
||||
|
||||
public static String makeReadable(Long time) {
|
||||
if (time == null)
|
||||
return "";
|
||||
@ -194,7 +104,6 @@ public class Methods {
|
||||
return sb.toString().trim();
|
||||
}
|
||||
|
||||
|
||||
public static long parseTime(String input) {
|
||||
long result = 0;
|
||||
StringBuilder number = new StringBuilder();
|
||||
@ -224,7 +133,6 @@ public class Methods {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Formats the specified double into the Economy format specified in the Arconix config.
|
||||
*
|
||||
@ -258,50 +166,4 @@ public class Methods {
|
||||
return false;
|
||||
return s.matches("[-+]?\\d*\\.?\\d+");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fills the provided inventory with glass panes of the specified color type.
|
||||
*
|
||||
* @param i The inventory to fill.
|
||||
*/
|
||||
public static void fillGlass(Inventory i) {
|
||||
ItemStack glass = getGlass();
|
||||
ItemMeta glassMeta = glass.getItemMeta();
|
||||
glassMeta.setDisplayName("§5");
|
||||
glass.setItemMeta(glassMeta);
|
||||
|
||||
int nu = 0;
|
||||
while (nu != 27) {
|
||||
i.setItem(nu, glass);
|
||||
nu++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified texture to the supplied head itemstack.
|
||||
*
|
||||
* @param item A head to apply the texture to.
|
||||
* @param headURL The URL of the texture to apply.
|
||||
* @return The head with the textrue.
|
||||
*/
|
||||
public static ItemStack addTexture(ItemStack item, String headURL) {
|
||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
||||
|
||||
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
|
||||
byte[] encodedData = Base64.getEncoder().encode(String.format("{textures:{SKIN:{url:\"%s\"}}}", new Object[]{headURL}).getBytes());
|
||||
profile.getProperties().put("textures", new Property("textures", new String(encodedData)));
|
||||
|
||||
Field profileField;
|
||||
try {
|
||||
profileField = meta.getClass().getDeclaredField("profile");
|
||||
profileField.setAccessible(true);
|
||||
profileField.set(meta, profile);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
}
|
@ -1,695 +0,0 @@
|
||||
package com.songoda.ultimatekits.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.logging.Level;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
/**
|
||||
* bStats collects some data for plugin authors.
|
||||
* <p>
|
||||
* Check out https://bStats.org/ to learn more about bStats!
|
||||
*/
|
||||
@SuppressWarnings({"WeakerAccess", "unused"})
|
||||
public class Metrics {
|
||||
|
||||
static {
|
||||
// You can use the property to disable the check in your test environment
|
||||
if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) {
|
||||
// Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D
|
||||
final String defaultPackage = new String(
|
||||
new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'});
|
||||
final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
|
||||
// We want to make sure nobody just copy & pastes the example and use the wrong package names
|
||||
if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) {
|
||||
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The version of this bStats class
|
||||
public static final int B_STATS_VERSION = 1;
|
||||
|
||||
// The url to which the data is sent
|
||||
private static final String URL = "https://bStats.org/submitData/bukkit";
|
||||
|
||||
// Is bStats enabled on this server?
|
||||
private boolean enabled;
|
||||
|
||||
// Should failed requests be logged?
|
||||
private static boolean logFailedRequests;
|
||||
|
||||
// Should the sent data be logged?
|
||||
private static boolean logSentData;
|
||||
|
||||
// Should the response text be logged?
|
||||
private static boolean logResponseStatusText;
|
||||
|
||||
// The uuid of the server
|
||||
private static String serverUUID;
|
||||
|
||||
// The plugin
|
||||
private final Plugin plugin;
|
||||
|
||||
// A list with all custom charts
|
||||
private final List<CustomChart> charts = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param plugin The plugin which stats should be submitted.
|
||||
*/
|
||||
public Metrics(Plugin plugin) {
|
||||
if (plugin == null) {
|
||||
throw new IllegalArgumentException("Plugin cannot be null!");
|
||||
}
|
||||
this.plugin = plugin;
|
||||
|
||||
// Get the config file
|
||||
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
|
||||
File configFile = new File(bStatsFolder, "config.yml");
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
||||
|
||||
// Check if the config file exists
|
||||
if (!config.isSet("serverUuid")) {
|
||||
|
||||
// Add default values
|
||||
config.addDefault("enabled", true);
|
||||
// Every server gets it's unique random id.
|
||||
config.addDefault("serverUuid", UUID.randomUUID().toString());
|
||||
// Should failed request be logged?
|
||||
config.addDefault("logFailedRequests", false);
|
||||
// Should the sent data be logged?
|
||||
config.addDefault("logSentData", false);
|
||||
// Should the response text be logged?
|
||||
config.addDefault("logResponseStatusText", false);
|
||||
|
||||
// Inform the server owners about bStats
|
||||
config.options().header(
|
||||
"bStats collects some data for plugin authors like how many servers are using their plugins.\n" +
|
||||
"To honor their work, you should not disable it.\n" +
|
||||
"This has nearly no effect on the server performance!\n" +
|
||||
"Check out https://bStats.org/ to learn more :)"
|
||||
).copyDefaults(true);
|
||||
try {
|
||||
config.save(configFile);
|
||||
} catch (IOException ignored) { }
|
||||
}
|
||||
|
||||
// Load the data
|
||||
enabled = config.getBoolean("enabled", true);
|
||||
serverUUID = config.getString("serverUuid");
|
||||
logFailedRequests = config.getBoolean("logFailedRequests", false);
|
||||
logSentData = config.getBoolean("logSentData", false);
|
||||
logResponseStatusText = config.getBoolean("logResponseStatusText", false);
|
||||
|
||||
if (enabled) {
|
||||
boolean found = false;
|
||||
// Search for all other bStats Metrics classes to see if we are the first one
|
||||
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
|
||||
try {
|
||||
service.getField("B_STATS_VERSION"); // Our identifier :)
|
||||
found = true; // We aren't the first
|
||||
break;
|
||||
} catch (NoSuchFieldException ignored) { }
|
||||
}
|
||||
// Register our service
|
||||
Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal);
|
||||
if (!found) {
|
||||
// We are the first!
|
||||
startSubmitting();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if bStats is enabled.
|
||||
*
|
||||
* @return Whether bStats is enabled or not.
|
||||
*/
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a custom chart.
|
||||
*
|
||||
* @param chart The chart to add.
|
||||
*/
|
||||
public void addCustomChart(CustomChart chart) {
|
||||
if (chart == null) {
|
||||
throw new IllegalArgumentException("Chart cannot be null!");
|
||||
}
|
||||
charts.add(chart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the Scheduler which submits our data every 30 minutes.
|
||||
*/
|
||||
private void startSubmitting() {
|
||||
final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!plugin.isEnabled()) { // Plugin was disabled
|
||||
timer.cancel();
|
||||
return;
|
||||
}
|
||||
// Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
|
||||
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
|
||||
Bukkit.getScheduler().runTask(plugin, () -> submitData());
|
||||
}
|
||||
}, 1000 * 60 * 5, 1000 * 60 * 30);
|
||||
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
|
||||
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
|
||||
// WARNING: Just don't do it!
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin specific data.
|
||||
* This method is called using Reflection.
|
||||
*
|
||||
* @return The plugin specific data.
|
||||
*/
|
||||
public JSONObject getPluginData() {
|
||||
JSONObject data = new JSONObject();
|
||||
|
||||
String pluginName = plugin.getDescription().getName();
|
||||
String pluginVersion = plugin.getDescription().getVersion();
|
||||
|
||||
data.put("pluginName", pluginName); // Append the name of the plugin
|
||||
data.put("pluginVersion", pluginVersion); // Append the version of the plugin
|
||||
JSONArray customCharts = new JSONArray();
|
||||
for (CustomChart customChart : charts) {
|
||||
// Add the data of the custom charts
|
||||
JSONObject chart = customChart.getRequestJsonObject();
|
||||
if (chart == null) { // If the chart is null, we skip it
|
||||
continue;
|
||||
}
|
||||
customCharts.add(chart);
|
||||
}
|
||||
data.put("customCharts", customCharts);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the server specific data.
|
||||
*
|
||||
* @return The server specific data.
|
||||
*/
|
||||
private JSONObject getServerData() {
|
||||
// Minecraft specific data
|
||||
int playerAmount;
|
||||
try {
|
||||
// Around MC 1.8 the return type was changed to a collection from an array,
|
||||
// This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
|
||||
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
|
||||
playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
|
||||
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
|
||||
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
|
||||
} catch (Exception e) {
|
||||
playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
|
||||
}
|
||||
int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
|
||||
String bukkitVersion = Bukkit.getVersion();
|
||||
|
||||
// OS/Java specific data
|
||||
String javaVersion = System.getProperty("java.version");
|
||||
String osName = System.getProperty("os.name");
|
||||
String osArch = System.getProperty("os.arch");
|
||||
String osVersion = System.getProperty("os.version");
|
||||
int coreCount = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
JSONObject data = new JSONObject();
|
||||
|
||||
data.put("serverUUID", serverUUID);
|
||||
|
||||
data.put("playerAmount", playerAmount);
|
||||
data.put("onlineMode", onlineMode);
|
||||
data.put("bukkitVersion", bukkitVersion);
|
||||
|
||||
data.put("javaVersion", javaVersion);
|
||||
data.put("osName", osName);
|
||||
data.put("osArch", osArch);
|
||||
data.put("osVersion", osVersion);
|
||||
data.put("coreCount", coreCount);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects the data and sends it afterwards.
|
||||
*/
|
||||
private void submitData() {
|
||||
final JSONObject data = getServerData();
|
||||
|
||||
JSONArray pluginData = new JSONArray();
|
||||
// Search for all other bStats Metrics classes to get their plugin data
|
||||
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
|
||||
try {
|
||||
service.getField("B_STATS_VERSION"); // Our identifier :)
|
||||
|
||||
for (RegisteredServiceProvider<?> provider : Bukkit.getServicesManager().getRegistrations(service)) {
|
||||
try {
|
||||
pluginData.add(provider.getService().getMethod("getPluginData").invoke(provider.getProvider()));
|
||||
} catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { }
|
||||
}
|
||||
} catch (NoSuchFieldException ignored) { }
|
||||
}
|
||||
|
||||
data.put("plugins", pluginData);
|
||||
|
||||
// Create a new thread for the connection to the bStats server
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
// Send the data
|
||||
sendData(plugin, data);
|
||||
} catch (Exception e) {
|
||||
// Something went wrong! :(
|
||||
if (logFailedRequests) {
|
||||
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the data to the bStats server.
|
||||
*
|
||||
* @param plugin Any plugin. It's just used to get a logger instance.
|
||||
* @param data The data to send.
|
||||
* @throws Exception If the request failed.
|
||||
*/
|
||||
private static void sendData(Plugin plugin, JSONObject data) throws Exception {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Data cannot be null!");
|
||||
}
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
throw new IllegalAccessException("This method must not be called from the main thread!");
|
||||
}
|
||||
if (logSentData) {
|
||||
plugin.getLogger().info("Sending data to bStats: " + data.toString());
|
||||
}
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
|
||||
|
||||
// Compress the data to save bandwidth
|
||||
byte[] compressedData = compress(data.toString());
|
||||
|
||||
// Add headers
|
||||
connection.setRequestMethod("POST");
|
||||
connection.addRequestProperty("Accept", "application/json");
|
||||
connection.addRequestProperty("Connection", "close");
|
||||
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
|
||||
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
|
||||
connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
|
||||
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
|
||||
|
||||
// Send data
|
||||
connection.setDoOutput(true);
|
||||
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
|
||||
outputStream.write(compressedData);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
InputStream inputStream = connection.getInputStream();
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
builder.append(line);
|
||||
}
|
||||
bufferedReader.close();
|
||||
if (logResponseStatusText) {
|
||||
plugin.getLogger().info("Sent data to bStats and received response: " + builder.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gzips the given String.
|
||||
*
|
||||
* @param str The string to gzip.
|
||||
* @return The gzipped String.
|
||||
* @throws IOException If the compression failed.
|
||||
*/
|
||||
private static byte[] compress(final String str) throws IOException {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzip = new GZIPOutputStream(outputStream);
|
||||
gzip.write(str.getBytes(StandardCharsets.UTF_8));
|
||||
gzip.close();
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom chart.
|
||||
*/
|
||||
public static abstract class CustomChart {
|
||||
|
||||
// The id of the chart
|
||||
final String chartId;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
*/
|
||||
CustomChart(String chartId) {
|
||||
if (chartId == null || chartId.isEmpty()) {
|
||||
throw new IllegalArgumentException("ChartId cannot be null or empty!");
|
||||
}
|
||||
this.chartId = chartId;
|
||||
}
|
||||
|
||||
private JSONObject getRequestJsonObject() {
|
||||
JSONObject chart = new JSONObject();
|
||||
chart.put("chartId", chartId);
|
||||
try {
|
||||
JSONObject data = getChartData();
|
||||
if (data == null) {
|
||||
// If the data is null we don't send the chart.
|
||||
return null;
|
||||
}
|
||||
chart.put("data", data);
|
||||
} catch (Throwable t) {
|
||||
if (logFailedRequests) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return chart;
|
||||
}
|
||||
|
||||
protected abstract JSONObject getChartData() throws Exception;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom simple pie.
|
||||
*/
|
||||
public static class SimplePie extends CustomChart {
|
||||
|
||||
private final Callable<String> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SimplePie(String chartId, Callable<String> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
String value = callable.call();
|
||||
if (value == null || value.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("value", value);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom advanced pie.
|
||||
*/
|
||||
public static class AdvancedPie extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
if (entry.getValue() == 0) {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
values.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom drilldown pie.
|
||||
*/
|
||||
public static class DrilldownPie extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Map<String, Integer>>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
Map<String, Map<String, Integer>> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean reallyAllSkipped = true;
|
||||
for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet()) {
|
||||
JSONObject value = new JSONObject();
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
|
||||
value.put(valueEntry.getKey(), valueEntry.getValue());
|
||||
allSkipped = false;
|
||||
}
|
||||
if (!allSkipped) {
|
||||
reallyAllSkipped = false;
|
||||
values.put(entryValues.getKey(), value);
|
||||
}
|
||||
}
|
||||
if (reallyAllSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom single line chart.
|
||||
*/
|
||||
public static class SingleLineChart extends CustomChart {
|
||||
|
||||
private final Callable<Integer> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SingleLineChart(String chartId, Callable<Integer> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
int value = callable.call();
|
||||
if (value == 0) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("value", value);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom multi line chart.
|
||||
*/
|
||||
public static class MultiLineChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
if (entry.getValue() == 0) {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
values.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom simple bar chart.
|
||||
*/
|
||||
public static class SimpleBarChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
JSONArray categoryValues = new JSONArray();
|
||||
categoryValues.add(entry.getValue());
|
||||
values.put(entry.getKey(), categoryValues);
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom advanced bar chart.
|
||||
*/
|
||||
public static class AdvancedBarChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, int[]>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
Map<String, int[]> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, int[]> entry : map.entrySet()) {
|
||||
if (entry.getValue().length == 0) {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
JSONArray categoryValues = new JSONArray();
|
||||
for (int categoryValue : entry.getValue()) {
|
||||
categoryValues.add(categoryValue);
|
||||
}
|
||||
values.put(entry.getKey(), categoryValues);
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package com.songoda.ultimatekits.utils;
|
||||
|
||||
public enum ServerVersion {
|
||||
|
||||
UNKNOWN("unknown_server_version"),
|
||||
V1_7("org.bukkit.craftbukkit.v1_7"),
|
||||
V1_8("org.bukkit.craftbukkit.v1_8"),
|
||||
V1_9("org.bukkit.craftbukkit.v1_9"),
|
||||
V1_10("org.bukkit.craftbukkit.v1_10"),
|
||||
V1_11("org.bukkit.craftbukkit.v1_11"),
|
||||
V1_12("org.bukkit.craftbukkit.v1_12"),
|
||||
V1_13("org.bukkit.craftbukkit.v1_13"),
|
||||
V1_14("org.bukkit.craftbukkit.v1_14");
|
||||
|
||||
|
||||
private final String packagePrefix;
|
||||
|
||||
private ServerVersion(String packagePrefix) {
|
||||
this.packagePrefix = packagePrefix;
|
||||
}
|
||||
|
||||
public static ServerVersion fromPackageName(String packageName) {
|
||||
for (ServerVersion version : values())
|
||||
if (packageName.startsWith(version.packagePrefix)) return version;
|
||||
return ServerVersion.UNKNOWN;
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package com.songoda.ultimatekits.utils.gui;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface Clickable {
|
||||
|
||||
void Clickable(Player player, Inventory inventory, ItemStack cursor, int slot, ClickType type);
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package com.songoda.ultimatekits.utils.gui;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public interface OnClose {
|
||||
|
||||
void onClose(Player player, Inventory inventory);
|
||||
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package com.songoda.ultimatekits.utils.gui;
|
||||
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.utils.ServerVersion;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
public class Range {
|
||||
|
||||
private int min;
|
||||
private int max;
|
||||
private ClickType clickType;
|
||||
private boolean bottom;
|
||||
private Sound onClickSound;
|
||||
|
||||
public Range(int min, int max, ClickType clickType, boolean bottom) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.clickType = clickType;
|
||||
this.bottom = bottom;
|
||||
if (UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_9)) onClickSound = Sound.UI_BUTTON_CLICK;
|
||||
}
|
||||
|
||||
public Range(int min, int max, Sound onClickSound, ClickType clickType, boolean bottom) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.onClickSound = onClickSound;
|
||||
this.clickType = clickType;
|
||||
this.bottom = bottom;
|
||||
}
|
||||
|
||||
public int getMin() {
|
||||
return min;
|
||||
}
|
||||
|
||||
public int getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
public ClickType getClickType() {
|
||||
return clickType;
|
||||
}
|
||||
|
||||
public boolean isBottom() {
|
||||
return bottom;
|
||||
}
|
||||
|
||||
public Sound getOnClickSound() {
|
||||
return onClickSound;
|
||||
}
|
||||
}
|
@ -1,302 +0,0 @@
|
||||
package com.songoda.ultimatekits.utils.locale;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Assists in the utilization of localization files.
|
||||
* Created to be used by the Songoda Team.
|
||||
*
|
||||
* @author Brianna O'Keefe - Songoda
|
||||
*/
|
||||
public class Locale {
|
||||
|
||||
private static final List<Locale> LOCALES = new ArrayList<>();
|
||||
private static final Pattern NODE_PATTERN = Pattern.compile("(\\w+(?:\\.{1}\\w+)*)\\s*=\\s*\"(.*)\"");
|
||||
private static final String FILE_EXTENSION = ".lang";
|
||||
private static JavaPlugin plugin;
|
||||
private static File localeFolder;
|
||||
|
||||
private final Map<String, String> nodes = new HashMap<>();
|
||||
|
||||
private static String defaultLocale;
|
||||
|
||||
private File file;
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* Instantiate the Locale class for future use
|
||||
*
|
||||
* @param name the name of the instantiated language
|
||||
*/
|
||||
private Locale(String name) {
|
||||
if (plugin == null)
|
||||
return;
|
||||
|
||||
this.name = name;
|
||||
|
||||
String fileName = name + FILE_EXTENSION;
|
||||
this.file = new File(localeFolder, fileName);
|
||||
|
||||
if (!this.reloadMessages()) return;
|
||||
|
||||
plugin.getLogger().info("Loaded locale \"" + fileName + "\"");
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the class to load all existing language files and update them.
|
||||
* This must be called before any other methods in this class as otherwise
|
||||
* the methods will fail to invoke
|
||||
*
|
||||
* @param plugin the plugin instance
|
||||
* @param defaultLocale the default language
|
||||
*/
|
||||
public Locale(JavaPlugin plugin, String defaultLocale) {
|
||||
|
||||
Locale.plugin = plugin;
|
||||
Locale.localeFolder = new File(plugin.getDataFolder(), "locales/");
|
||||
|
||||
if (!localeFolder.exists()) localeFolder.mkdirs();
|
||||
|
||||
//Save the default locale file.
|
||||
Locale.defaultLocale = defaultLocale;
|
||||
saveLocale(defaultLocale);
|
||||
|
||||
for (File file : localeFolder.listFiles()) {
|
||||
String fileName = file.getName();
|
||||
if (!fileName.endsWith(FILE_EXTENSION)) continue;
|
||||
|
||||
String name = fileName.substring(0, fileName.lastIndexOf('.'));
|
||||
|
||||
if (name.split("_").length != 2) continue;
|
||||
if (localeLoaded(name)) continue;
|
||||
|
||||
LOCALES.add(new Locale(name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a locale file from the InputStream, to the locale folder
|
||||
*
|
||||
* @param fileName the name of the file to save
|
||||
* @return true if the operation was successful, false otherwise
|
||||
*/
|
||||
public static boolean saveLocale(String fileName) {
|
||||
return saveLocale(plugin.getResource(defaultLocale + FILE_EXTENSION), fileName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save a locale file from the InputStream, to the locale folder
|
||||
*
|
||||
* @param in file to save
|
||||
* @param fileName the name of the file to save
|
||||
* @return true if the operation was successful, false otherwise
|
||||
*/
|
||||
public static boolean saveLocale(InputStream in, String fileName) {
|
||||
if (!localeFolder.exists()) localeFolder.mkdirs();
|
||||
|
||||
if (!fileName.endsWith(FILE_EXTENSION))
|
||||
fileName = (fileName.lastIndexOf(".") == -1 ? fileName : fileName.substring(0, fileName.lastIndexOf('.'))) + FILE_EXTENSION;
|
||||
|
||||
File destinationFile = new File(localeFolder, fileName);
|
||||
if (destinationFile.exists())
|
||||
return compareFiles(in, destinationFile);
|
||||
|
||||
try (OutputStream outputStream = new FileOutputStream(destinationFile)) {
|
||||
copy(in, outputStream);
|
||||
|
||||
fileName = fileName.substring(0, fileName.lastIndexOf('.'));
|
||||
|
||||
if (fileName.split("_").length != 2) return false;
|
||||
|
||||
LOCALES.add(new Locale(fileName));
|
||||
if (defaultLocale == null) defaultLocale = fileName;
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Write new changes to existing files, if any at all
|
||||
private static boolean compareFiles(InputStream in, File existingFile) {
|
||||
InputStream defaultFile =
|
||||
in == null ? plugin.getResource((defaultLocale != null ? defaultLocale : "en_US") + FILE_EXTENSION) : in;
|
||||
|
||||
boolean changed = false;
|
||||
|
||||
List<String> defaultLines, existingLines;
|
||||
try (BufferedReader defaultReader = new BufferedReader(new InputStreamReader(defaultFile));
|
||||
BufferedReader existingReader = new BufferedReader(new FileReader(existingFile));
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(existingFile, true))) {
|
||||
defaultLines = defaultReader.lines().collect(Collectors.toList());
|
||||
existingLines = existingReader.lines().map(s -> s.split("\\s*=")[0]).collect(Collectors.toList());
|
||||
|
||||
for (String defaultValue : defaultLines) {
|
||||
if (defaultValue.isEmpty() || defaultValue.startsWith("#")) continue;
|
||||
|
||||
String key = defaultValue.split("\\s*=")[0];
|
||||
|
||||
if (!existingLines.contains(key)) {
|
||||
if (!changed) {
|
||||
writer.newLine();
|
||||
writer.newLine();
|
||||
// Leave a note alerting the user of the newly added messages.
|
||||
writer.write("# New messages for " + plugin.getName() + " v" + plugin.getDescription().getVersion() + ".");
|
||||
|
||||
// If changes were found outside of the default file leave a note explaining that.
|
||||
if (in == null) {
|
||||
writer.newLine();
|
||||
writer.write("# These translations were found untranslated, join");
|
||||
writer.newLine();
|
||||
writer.write("# our translation Discord https://discord.gg/f7fpZEf");
|
||||
writer.newLine();
|
||||
writer.write("# to request an official update!");
|
||||
}
|
||||
}
|
||||
|
||||
writer.newLine();
|
||||
writer.write(defaultValue);
|
||||
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (in != null && !changed) compareFiles(null, existingFile);
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check whether a locale exists and is registered or not
|
||||
*
|
||||
* @param name the whole language tag (i.e. "en_US")
|
||||
* @return true if it exists
|
||||
*/
|
||||
public static boolean localeLoaded(String name) {
|
||||
for (Locale locale : LOCALES)
|
||||
if (locale.getName().equals(name)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a locale by its entire proper name (i.e. "en_US")
|
||||
*
|
||||
* @param name the full name of the locale
|
||||
* @return locale of the specified name
|
||||
*/
|
||||
public static Locale getLocale(String name) {
|
||||
for (Locale locale : LOCALES)
|
||||
if (locale.getName().equalsIgnoreCase(name)) return locale;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the previous message cache and load new messages directly from file
|
||||
*
|
||||
* @return reload messages from file
|
||||
*/
|
||||
public boolean reloadMessages() {
|
||||
if (!this.file.exists()) {
|
||||
plugin.getLogger().warning("Could not find file for locale \"" + this.name + "\"");
|
||||
return false;
|
||||
}
|
||||
|
||||
this.nodes.clear(); // Clear previous data (if any)
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
|
||||
String line;
|
||||
for (int lineNumber = 0; (line = reader.readLine()) != null; lineNumber++) {
|
||||
if (line.trim().isEmpty() || line.startsWith("#") /* Comment */) continue;
|
||||
|
||||
Matcher matcher = NODE_PATTERN.matcher(line);
|
||||
if (!matcher.find()) {
|
||||
System.err.println("Invalid locale syntax at (line=" + lineNumber + ")");
|
||||
continue;
|
||||
}
|
||||
|
||||
nodes.put(matcher.group(1), matcher.group(2));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Supply the Message object with the plugins prefix.
|
||||
*
|
||||
* @param message message to be applied
|
||||
* @return applied message
|
||||
*/
|
||||
private Message supplyPrefix(Message message) {
|
||||
return message.setPrefix(this.nodes.getOrDefault("general.nametag.prefix", "[Plugin]"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new unsaved Message
|
||||
*
|
||||
* @param message the message to create
|
||||
* @return the created message
|
||||
*/
|
||||
public Message newMessage(String message) {
|
||||
return supplyPrefix(new Message(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a message set for a specific node.
|
||||
*
|
||||
* @param node the node to get
|
||||
* @return the message for the specified node
|
||||
*/
|
||||
public Message getMessage(String node) {
|
||||
return this.getMessageOrDefault(node, node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a message set for a specific node
|
||||
*
|
||||
* @param node the node to get
|
||||
* @param defaultValue the default value given that a value for the node was not found
|
||||
* @return the message for the specified node. Default if none found
|
||||
*/
|
||||
public Message getMessageOrDefault(String node, String defaultValue) {
|
||||
return supplyPrefix(new Message(this.nodes.getOrDefault(node, defaultValue)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the locale name (i.e. "en_US")
|
||||
*
|
||||
* @return the locale name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
private static void copy(InputStream input, OutputStream output) {
|
||||
int n;
|
||||
byte[] buffer = new byte[1024 * 4];
|
||||
|
||||
try {
|
||||
while ((n = input.read(buffer)) != -1) {
|
||||
output.write(buffer, 0, n);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,115 +0,0 @@
|
||||
package com.songoda.ultimatekits.utils.locale;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* The Message object. This holds the message to be sent
|
||||
* as well as the plugins prefix so that they can both be
|
||||
* easily manipulated then deployed
|
||||
*/
|
||||
public class Message {
|
||||
|
||||
private String prefix = null;
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* create a new message
|
||||
*
|
||||
* @param message the message text
|
||||
*/
|
||||
public Message(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format and send the held message to a player
|
||||
*
|
||||
* @param player player to send the message to
|
||||
*/
|
||||
public void sendMessage(Player player) {
|
||||
player.sendMessage(this.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Format and send the held message with the
|
||||
* appended plugin prefix to a player
|
||||
*
|
||||
* @param player player to send the message to
|
||||
*/
|
||||
public void sendPrefixedMessage(Player player) {
|
||||
player.sendMessage(this.getPrefixedMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Format and send the held message to a player
|
||||
*
|
||||
* @param sender command sender to send the message to
|
||||
*/
|
||||
public void sendMessage(CommandSender sender) {
|
||||
sender.sendMessage(this.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Format and send the held message with the
|
||||
* appended plugin prefix to a command sender
|
||||
*
|
||||
* @param sender command sender to send the message to
|
||||
*/
|
||||
public void sendPrefixedMessage(CommandSender sender) {
|
||||
sender.sendMessage(this.getPrefixedMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the held message and append the plugins
|
||||
* prefix
|
||||
*
|
||||
* @return the prefixed message
|
||||
*/
|
||||
public String getPrefixedMessage() {
|
||||
return ChatColor.translateAlternateColorCodes('&',(prefix == null ? "" : this.prefix)
|
||||
+ " " + this.message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and format the held message
|
||||
*
|
||||
* @return the message
|
||||
*/
|
||||
public String getMessage() {
|
||||
return ChatColor.translateAlternateColorCodes('&', this.message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the held message
|
||||
*
|
||||
* @return the message
|
||||
*/
|
||||
public String getUnformattedMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the provided placeholder with the
|
||||
* provided object
|
||||
*
|
||||
* @param placeholder the placeholder to replace
|
||||
* @param replacement the replacement object
|
||||
* @return the modified Message
|
||||
*/
|
||||
public Message processPlaceholder(String placeholder, Object replacement) {
|
||||
this.message = message.replace("%" + placeholder + "%", replacement.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
Message setPrefix(String prefix) {
|
||||
this.prefix = prefix;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.message;
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.songoda.ultimatekits.utils.settings;
|
||||
|
||||
public enum Category {
|
||||
|
||||
MAIN("General settings and options."),
|
||||
|
||||
INTERFACES("These settings allow you to alter the way interfaces look.",
|
||||
"They are used in GUI's to make patterns, change them up then open up a",
|
||||
"GUI to see how it works."),
|
||||
|
||||
SYSTEM("System related settings.");
|
||||
|
||||
private String[] comments;
|
||||
|
||||
|
||||
Category(String... comments) {
|
||||
this.comments = comments;
|
||||
}
|
||||
|
||||
public String[] getComments() {
|
||||
return comments;
|
||||
}
|
||||
}
|
@ -1,118 +0,0 @@
|
||||
package com.songoda.ultimatekits.utils.settings;
|
||||
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.utils.ServerVersion;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public enum Setting {
|
||||
|
||||
ONLY_SHOW_KITS_WITH_PERMS("Main.Only Show Players Kits They Have Permission To Use", false),
|
||||
KITS_FREE_WITH_PERMS("Main.Allow Players To Receive Kits For Free If They Have Permission", true),
|
||||
DONT_PREVIEW_COMMANDS("Main.Dont Preview Commands In Kits", false),
|
||||
HOLOGRAM_LAYOUT("Main.Hologram Layout", Arrays.asList("{TITLE}", "{LEFT-CLICK}", "{RIGHT-CLICK}")),
|
||||
SOUNDS_ENABLED("Main.Sounds Enabled", true),
|
||||
NO_REDEEM_WHEN_FULL("Main.Prevent The Redeeming of a Kit When Inventory Is Full", true),
|
||||
AUTO_EQUIP_ARMOR("Main.Automatically Equip Armor Given From a Kit", true),
|
||||
AUTO_EQUIP_ARMOR_ROULETTE("Main.Automatically Equip Armor Given From a Kit with the Roulette Animation", false),
|
||||
CHANCE_IN_PREVIEW("Main.Display Chance In Preview", true),
|
||||
CURRENCY_SYMBOL("Main.Currency Symbol", "$"),
|
||||
|
||||
VAULT_ECONOMY("Economy.Use Vault Economy", true,
|
||||
"Should Vault be used?"),
|
||||
|
||||
RESERVE_ECONOMY("Economy.Use Reserve Economy", true,
|
||||
"Should Reserve be used?"),
|
||||
|
||||
PLAYER_POINTS_ECONOMY("Economy.Use Player Points Economy", false,
|
||||
"Should PlayerPoints be used?"),
|
||||
|
||||
EXIT_ICON("Interfaces.Exit Icon", UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? "OAK_DOOR" : "WOOD_DOOR"),
|
||||
BUY_ICON("Interfaces.Buy Icon", "EMERALD"),
|
||||
GLASS_TYPE_1("Interfaces.Glass Type 1", 7),
|
||||
GLASS_TYPE_2("Interfaces.Glass Type 2", 11),
|
||||
GLASS_TYPE_3("Interfaces.Glass Type 3", 3),
|
||||
RAINBOW("Interfaces.Replace Glass Type 1 With Rainbow Glass", false),
|
||||
DO_NOT_USE_GLASS_BORDERS("Interfaces.Do Not Use Glass Borders", false),
|
||||
|
||||
LANGUGE_MODE("System.Language Mode", "en_US",
|
||||
"The enabled language file.",
|
||||
"More language files (if available) can be found in the plugins data folder."),
|
||||
|
||||
MYSQL_ENABLED("MySQL.Enabled", false, "Set to 'true' to use MySQL for data storage."),
|
||||
MYSQL_HOSTNAME("MySQL.Hostname", "localhost"),
|
||||
MYSQL_PORT("MySQL.Port", 3306),
|
||||
MYSQL_DATABASE("MySQL.Database", "your-database"),
|
||||
MYSQL_USERNAME("MySQL.Username", "user"),
|
||||
MYSQL_PASSWORD("MySQL.Password", "pass"),
|
||||
MYSQL_USE_SSL("MySQL.Use SSL", false);
|
||||
|
||||
private String setting;
|
||||
private Object option;
|
||||
private String[] comments;
|
||||
|
||||
Setting(String setting, Object option, String... comments) {
|
||||
this.setting = setting;
|
||||
this.option = option;
|
||||
this.comments = comments;
|
||||
}
|
||||
|
||||
Setting(String setting, Object option) {
|
||||
this.setting = setting;
|
||||
this.option = option;
|
||||
this.comments = null;
|
||||
}
|
||||
|
||||
public static Setting getSetting(String setting) {
|
||||
List<Setting> settings = Arrays.stream(values()).filter(setting1 -> setting1.setting.equals(setting)).collect(Collectors.toList());
|
||||
if (settings.isEmpty()) return null;
|
||||
return settings.get(0);
|
||||
}
|
||||
|
||||
public String getSetting() {
|
||||
return setting;
|
||||
}
|
||||
|
||||
public Object getOption() {
|
||||
return option;
|
||||
}
|
||||
|
||||
public String[] getComments() {
|
||||
return comments;
|
||||
}
|
||||
|
||||
public List<Integer> getIntegerList() {
|
||||
return UltimateKits.getInstance().getConfig().getIntegerList(setting);
|
||||
}
|
||||
|
||||
public List<String> getStringList() {
|
||||
return UltimateKits.getInstance().getConfig().getStringList(setting);
|
||||
}
|
||||
|
||||
public boolean getBoolean() {
|
||||
return UltimateKits.getInstance().getConfig().getBoolean(setting);
|
||||
}
|
||||
|
||||
public int getInt() {
|
||||
return UltimateKits.getInstance().getConfig().getInt(setting);
|
||||
}
|
||||
|
||||
public long getLong() {
|
||||
return UltimateKits.getInstance().getConfig().getLong(setting);
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
return UltimateKits.getInstance().getConfig().getString(setting);
|
||||
}
|
||||
|
||||
public char getChar() {
|
||||
return UltimateKits.getInstance().getConfig().getString(setting).charAt(0);
|
||||
}
|
||||
|
||||
public double getDouble() {
|
||||
return UltimateKits.getInstance().getConfig().getDouble(setting);
|
||||
}
|
||||
|
||||
}
|
@ -1,311 +0,0 @@
|
||||
package com.songoda.ultimatekits.utils.settings;
|
||||
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import com.songoda.ultimatekits.utils.ServerVersion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by songoda on 6/4/2017.
|
||||
*/
|
||||
public class SettingsManager implements Listener {
|
||||
|
||||
private final UltimateKits plugin;
|
||||
private Map<Player, String> cat = new HashMap<>();
|
||||
private Map<Player, String> current = new HashMap<>();
|
||||
|
||||
public SettingsManager(UltimateKits plugin) {
|
||||
this.plugin = plugin;
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
if (event.getView().getType() != InventoryType.CHEST) return;
|
||||
ItemStack clickedItem = event.getCurrentItem();
|
||||
|
||||
if (event.getInventory() != event.getWhoClicked().getOpenInventory().getTopInventory()
|
||||
|| clickedItem == null || !clickedItem.hasItemMeta()
|
||||
|| !clickedItem.getItemMeta().hasDisplayName()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getView().getTitle().equals(plugin.getName() + " Settings Manager")) {
|
||||
event.setCancelled(true);
|
||||
if (clickedItem.getType().name().contains("STAINED_GLASS")) return;
|
||||
|
||||
String type = ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName());
|
||||
this.cat.put((Player) event.getWhoClicked(), type);
|
||||
this.openEditor((Player) event.getWhoClicked());
|
||||
} else if (event.getView().getTitle().equals(plugin.getName() + " Settings Editor")) {
|
||||
event.setCancelled(true);
|
||||
if (clickedItem.getType().name().contains("STAINED_GLASS")) return;
|
||||
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
|
||||
String key = cat.get(player) + "." + ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName());
|
||||
|
||||
if (plugin.getConfig().get(key).getClass().getName().equals("java.lang.Boolean")) {
|
||||
this.plugin.getConfig().set(key, !plugin.getConfig().getBoolean(key));
|
||||
this.finishEditing(player);
|
||||
} else {
|
||||
this.editObject(player, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChat(AsyncPlayerChatEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (!current.containsKey(player)) return;
|
||||
|
||||
String value = current.get(player);
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
if (config.isLong(value)) {
|
||||
config.set(value, Long.parseLong(event.getMessage()));
|
||||
} else if (config.isInt(value)) {
|
||||
config.set(value, Integer.parseInt(event.getMessage()));
|
||||
} else if (config.isDouble(value)) {
|
||||
config.set(value, Double.parseDouble(event.getMessage()));
|
||||
} else if (config.isString(value)) {
|
||||
config.set(value, event.getMessage());
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(UltimateKits.getInstance(), () ->
|
||||
this.finishEditing(player), 0L);
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
private void finishEditing(Player player) {
|
||||
this.current.remove(player);
|
||||
this.saveConfig();
|
||||
this.openEditor(player);
|
||||
}
|
||||
|
||||
private void editObject(Player player, String current) {
|
||||
this.current.put(player, ChatColor.stripColor(current));
|
||||
|
||||
player.closeInventory();
|
||||
player.sendMessage("");
|
||||
player.sendMessage(Methods.formatText("&7Please enter a value for &6" + current + "&7."));
|
||||
if (plugin.getConfig().isInt(current) || plugin.getConfig().isDouble(current)) {
|
||||
player.sendMessage(Methods.formatText("&cUse only numbers."));
|
||||
}
|
||||
player.sendMessage("");
|
||||
}
|
||||
|
||||
public void openSettingsManager(Player player) {
|
||||
Inventory inventory = Bukkit.createInventory(null, 27, plugin.getName() + " Settings Manager");
|
||||
ItemStack glass = Methods.getGlass();
|
||||
for (int i = 0; i < inventory.getSize(); i++) {
|
||||
inventory.setItem(i, glass);
|
||||
}
|
||||
|
||||
int slot = 10;
|
||||
for (String key : plugin.getConfig().getDefaultSection().getKeys(false)) {
|
||||
ItemStack item = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.LEGACY_WOOL : Material.valueOf("WOOL"), 1, (byte) (slot - 9));
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setLore(Collections.singletonList(Methods.formatText("&6Click To Edit This Category.")));
|
||||
meta.setDisplayName(Methods.formatText("&f&l" + key));
|
||||
item.setItemMeta(meta);
|
||||
inventory.setItem(slot, item);
|
||||
slot++;
|
||||
}
|
||||
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
private void openEditor(Player player) {
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, plugin.getName() + " Settings Editor");
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
|
||||
int slot = 0;
|
||||
for (String key : config.getConfigurationSection(cat.get(player)).getKeys(true)) {
|
||||
String fKey = cat.get(player) + "." + key;
|
||||
ItemStack item = new ItemStack(Material.DIAMOND_HELMET);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(Methods.formatText("&6" + key));
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
if (config.isBoolean(fKey)) {
|
||||
item.setType(Material.LEVER);
|
||||
lore.add(Methods.formatText(config.getBoolean(fKey) ? "&atrue" : "&cfalse"));
|
||||
} else if (config.isString(fKey)) {
|
||||
item.setType(Material.PAPER);
|
||||
lore.add(Methods.formatText("&7" + config.getString(fKey)));
|
||||
} else if (config.isInt(fKey)) {
|
||||
item.setType(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH"));
|
||||
lore.add(Methods.formatText("&7" + config.getInt(fKey)));
|
||||
} else if (config.isLong(fKey)) {
|
||||
item.setType(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH"));
|
||||
lore.add(Methods.formatText("&7" + config.getLong(fKey)));
|
||||
} else if (config.isDouble(fKey)) {
|
||||
item.setType(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH"));
|
||||
lore.add(Methods.formatText("&7" + config.getDouble(fKey)));
|
||||
}
|
||||
|
||||
Setting setting = Setting.getSetting(fKey);
|
||||
|
||||
if (setting != null && setting.getComments() != null) {
|
||||
lore.add("");
|
||||
|
||||
String comment = String.join(" ", setting.getComments());
|
||||
|
||||
int lastIndex = 0;
|
||||
for (int n = 0; n < comment.length(); n++) {
|
||||
if (n - lastIndex < 30)
|
||||
continue;
|
||||
|
||||
if (comment.charAt(n) == ' ') {
|
||||
lore.add(Methods.formatText("&8" + comment.substring(lastIndex, n).trim()));
|
||||
lastIndex = n;
|
||||
}
|
||||
}
|
||||
|
||||
if (lastIndex - comment.length() < 30)
|
||||
lore.add(Methods.formatText("&8" + comment.substring(lastIndex).trim()));
|
||||
|
||||
}
|
||||
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
inventory.setItem(slot, item);
|
||||
slot++;
|
||||
}
|
||||
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
plugin.reloadConfig();
|
||||
this.setupConfig();
|
||||
}
|
||||
|
||||
public void setupConfig() {
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
|
||||
for (Setting setting : Setting.values()) {
|
||||
config.addDefault(setting.getSetting(), setting.getOption());
|
||||
}
|
||||
plugin.getConfig().options().copyDefaults(true);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
private void saveConfig() {
|
||||
String dump = plugin.getConfig().saveToString();
|
||||
|
||||
StringBuilder config = new StringBuilder();
|
||||
|
||||
BufferedReader bufReader = new BufferedReader(new StringReader(dump));
|
||||
|
||||
try {
|
||||
boolean first = true;
|
||||
|
||||
String line;
|
||||
int currentTab = 0;
|
||||
String category = "";
|
||||
|
||||
while ((line = bufReader.readLine()) != null) {
|
||||
if (line.trim().startsWith("#")) continue;
|
||||
|
||||
int tabChange = line.length() - line.trim().length();
|
||||
if (currentTab != tabChange) {
|
||||
category = category.contains(".") && tabChange != 0 ? category.substring(0, category.indexOf(".")) : "";
|
||||
currentTab = tabChange;
|
||||
}
|
||||
|
||||
if (line.endsWith(":")) {
|
||||
bufReader.mark(1000);
|
||||
String found = bufReader.readLine();
|
||||
bufReader.reset();
|
||||
|
||||
if (!found.trim().startsWith("-")) {
|
||||
|
||||
String newCategory = line.substring(0, line.length() - 1).trim();
|
||||
|
||||
if (category.equals(""))
|
||||
category = newCategory;
|
||||
else
|
||||
category += "." + newCategory;
|
||||
|
||||
currentTab = tabChange + 2;
|
||||
|
||||
if (!first) {
|
||||
config.append("\n\n");
|
||||
} else {
|
||||
first = false;
|
||||
}
|
||||
|
||||
if (!category.contains("."))
|
||||
config.append("#").append("\n");
|
||||
try {
|
||||
Category categoryObj = Category.valueOf(category.toUpperCase()
|
||||
.replace(" ", "_")
|
||||
.replace(".", "_"));
|
||||
|
||||
config.append(new String(new char[tabChange]).replace('\0', ' '));
|
||||
for (String l : categoryObj.getComments())
|
||||
config.append("# ").append(l).append("\n");
|
||||
} catch (IllegalArgumentException e) {
|
||||
config.append("# ").append(category).append("\n");
|
||||
}
|
||||
if (!category.contains("."))
|
||||
config.append("#").append("\n");
|
||||
|
||||
config.append(line).append("\n");
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (line.trim().startsWith("-")) {
|
||||
config.append(line).append("\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
String key = category + "." + (line.split(":")[0].trim());
|
||||
for (Setting setting : Setting.values()) {
|
||||
if (!setting.getSetting().equals(key) || setting.getComments() == null) continue;
|
||||
config.append(" ").append("\n");
|
||||
for (String l : setting.getComments()) {
|
||||
config.append(new String(new char[currentTab]).replace('\0', ' '));
|
||||
config.append("# ").append(l).append("\n");
|
||||
}
|
||||
}
|
||||
config.append(line).append("\n");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
if (!plugin.getDataFolder().exists())
|
||||
plugin.getDataFolder().mkdir();
|
||||
BufferedWriter writer =
|
||||
new BufferedWriter(new FileWriter(new File(plugin.getDataFolder() + File.separator + "config.yml")));
|
||||
writer.write(config.toString());
|
||||
writer.flush();
|
||||
writer.close();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package com.songoda.ultimatekits.utils.updateModules;
|
||||
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.update.Module;
|
||||
import com.songoda.update.Plugin;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
public class LocaleModule implements Module {
|
||||
|
||||
@Override
|
||||
public void run(Plugin plugin) {
|
||||
JSONObject json = plugin.getJson();
|
||||
try {
|
||||
JSONArray files = (JSONArray) json.get("neededFiles");
|
||||
for (Object o : files) {
|
||||
JSONObject file = (JSONObject) o;
|
||||
|
||||
if (file.get("type").equals("locale")) {
|
||||
InputStream in = new URL((String) file.get("link")).openStream();
|
||||
UltimateKits.getInstance().getLocale().saveLocale(in, (String) file.get("name"));
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
package com.songoda.ultimatekits.utils.version;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class NMSUtil {
|
||||
|
||||
public static String getVersion() {
|
||||
String name = Bukkit.getServer().getClass().getPackage().getName();
|
||||
return name.substring(name.lastIndexOf('.') + 1) + ".";
|
||||
}
|
||||
|
||||
public static int getVersionNumber() {
|
||||
String name = getVersion().substring(3);
|
||||
return Integer.valueOf(name.substring(0, name.length() - 4));
|
||||
}
|
||||
|
||||
public static int getVersionReleaseNumber() {
|
||||
String NMSVersion = getVersion();
|
||||
return Integer.valueOf(NMSVersion.substring(NMSVersion.length() - 2).replace(".", ""));
|
||||
}
|
||||
|
||||
public static Class<?> getNMSClass(String className) {
|
||||
try {
|
||||
String fullName = "net.minecraft.server." + getVersion() + className;
|
||||
Class<?> clazz = Class.forName(fullName);
|
||||
return clazz;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Class<?> getCraftClass(String className) {
|
||||
try {
|
||||
String fullName = "org.bukkit.craftbukkit." + getVersion() + className;
|
||||
Class<?> clazz = Class.forName(fullName);
|
||||
return clazz;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Field getField(Class<?> clazz, String name, boolean declared) {
|
||||
try {
|
||||
Field field;
|
||||
|
||||
if (declared) {
|
||||
field = clazz.getDeclaredField(name);
|
||||
} else {
|
||||
field = clazz.getField(name);
|
||||
}
|
||||
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Object getFieldObject(Object object, Field field) {
|
||||
try {
|
||||
return field.get(object);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setField(Object object, String fieldName, Object fieldValue, boolean declared) {
|
||||
try {
|
||||
Field field;
|
||||
|
||||
if (declared) {
|
||||
field = object.getClass().getDeclaredField(fieldName);
|
||||
} else {
|
||||
field = object.getClass().getField(fieldName);
|
||||
}
|
||||
|
||||
field.setAccessible(true);
|
||||
field.set(object, fieldValue);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPacket(Player player, Object packet) {
|
||||
try {
|
||||
Object handle = player.getClass().getMethod("getHandle").invoke(player);
|
||||
Object playerConnection = handle.getClass().getField("playerConnection").get(handle);
|
||||
playerConnection.getClass().getMethod("sendPacket", getNMSClass("Packet")).invoke(playerConnection, packet);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user