refactor(global): unify global components into a single parent class
This commit is contained in:
parent
567e005e16
commit
bf09e24c4b
59 changed files with 425 additions and 341 deletions
69
nicko-core/src/main/java/net/artelnatif/nicko/Nicko.java
Normal file
69
nicko-core/src/main/java/net/artelnatif/nicko/Nicko.java
Normal file
|
@ -0,0 +1,69 @@
|
|||
package net.artelnatif.nicko;
|
||||
|
||||
import net.artelnatif.nicko.config.Configuration;
|
||||
import net.artelnatif.nicko.config.ConfigurationManager;
|
||||
import net.artelnatif.nicko.storage.PlayerDataStore;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class Nicko {
|
||||
private ConfigurationManager configManager;
|
||||
private Logger logger;
|
||||
private File dataFolder;
|
||||
private Configuration config;
|
||||
|
||||
private PlayerDataStore dataStore;
|
||||
|
||||
public void initBungeecord(Plugin bungee) {
|
||||
logger = bungee.getLogger();
|
||||
dataFolder = bungee.getDataFolder();
|
||||
initNicko();
|
||||
}
|
||||
|
||||
public void initBukkit(JavaPlugin bukkit) {
|
||||
logger = bukkit.getLogger();
|
||||
dataFolder = bukkit.getDataFolder();
|
||||
initNicko();
|
||||
}
|
||||
|
||||
private void initNicko() {
|
||||
configManager = new ConfigurationManager(this);
|
||||
configManager.saveDefaultConfig();
|
||||
|
||||
dataStore = new PlayerDataStore(this);
|
||||
}
|
||||
|
||||
public Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
public PlayerDataStore getDataStore() {
|
||||
return dataStore;
|
||||
}
|
||||
|
||||
public File getDataFolder() {
|
||||
return dataFolder;
|
||||
}
|
||||
|
||||
public ConfigurationManager getConfigManager() {
|
||||
return configManager;
|
||||
}
|
||||
|
||||
public Configuration getConfig() {
|
||||
try {
|
||||
if (config == null) { return config = configManager.load(); }
|
||||
return config;
|
||||
} catch (IOException e) {
|
||||
logger.severe("Failed to load configuration file: " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setConfig(Configuration config) {
|
||||
this.config = config;
|
||||
}
|
||||
}
|
|
@ -1,23 +1,23 @@
|
|||
package net.artelnatif.nicko;
|
||||
package net.artelnatif.nicko.bukkit;
|
||||
|
||||
import de.studiocode.invui.gui.structure.Structure;
|
||||
import de.studiocode.invui.item.builder.ItemBuilder;
|
||||
import de.studiocode.invui.item.impl.SimpleItem;
|
||||
import net.artelnatif.nicko.Nicko;
|
||||
import net.artelnatif.nicko.bukkit.command.NickoCommand;
|
||||
import net.artelnatif.nicko.bukkit.gui.items.main.ExitGUI;
|
||||
import net.artelnatif.nicko.bukkit.pluginchannel.PluginMessageHandler;
|
||||
import net.artelnatif.nicko.bungee.BungeeCordSupport;
|
||||
import net.artelnatif.nicko.bungee.NickoBungee;
|
||||
import net.artelnatif.nicko.command.NickoCommand;
|
||||
import net.artelnatif.nicko.config.NickoConfiguration;
|
||||
import net.artelnatif.nicko.config.Configuration;
|
||||
import net.artelnatif.nicko.event.PlayerJoinListener;
|
||||
import net.artelnatif.nicko.event.PlayerQuitListener;
|
||||
import net.artelnatif.nicko.gui.items.main.ExitGUI;
|
||||
import net.artelnatif.nicko.i18n.Locale;
|
||||
import net.artelnatif.nicko.i18n.LocaleFileManager;
|
||||
import net.artelnatif.nicko.impl.Internals;
|
||||
import net.artelnatif.nicko.impl.InternalsProvider;
|
||||
import net.artelnatif.nicko.mojang.MojangAPI;
|
||||
import net.artelnatif.nicko.placeholder.PlaceHolderHook;
|
||||
import net.artelnatif.nicko.pluginchannel.PluginMessageHandler;
|
||||
import net.artelnatif.nicko.storage.PlayerDataStore;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
|
@ -29,11 +29,10 @@ import java.io.File;
|
|||
public class NickoBukkit extends JavaPlugin {
|
||||
private static NickoBukkit plugin;
|
||||
|
||||
private final Nicko nicko = new Nicko();
|
||||
private final boolean unitTesting;
|
||||
|
||||
private NickoConfiguration config;
|
||||
private MojangAPI mojangAPI;
|
||||
private PlayerDataStore dataStore;
|
||||
private LocaleFileManager localeFileManager;
|
||||
|
||||
public NickoBukkit() { this.unitTesting = false; }
|
||||
|
@ -41,10 +40,10 @@ public class NickoBukkit extends JavaPlugin {
|
|||
/**
|
||||
* Used by MockBukkit
|
||||
*/
|
||||
protected NickoBukkit(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file, NickoConfiguration config) {
|
||||
protected NickoBukkit(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file, Configuration config) {
|
||||
super(loader, description, dataFolder, file);
|
||||
unitTesting = true;
|
||||
this.config = config;
|
||||
nicko.setConfig(config);
|
||||
getLogger().info("Unit Testing Mode enabled.");
|
||||
}
|
||||
|
||||
|
@ -60,39 +59,35 @@ public class NickoBukkit extends JavaPlugin {
|
|||
}
|
||||
|
||||
public void onUnitTestingStartup() {
|
||||
getLogger().info("Loading persistence...");
|
||||
dataStore = new PlayerDataStore(this);
|
||||
nicko.initBukkit(this);
|
||||
|
||||
if (!dataStore.getStorage().getProvider().init()) {
|
||||
dataStore.getStorage().setError(true);
|
||||
if (!nicko.getDataStore().getStorage().getProvider().init()) {
|
||||
nicko.getDataStore().getStorage().setError(true);
|
||||
getLogger().severe("Failed to open persistence, data will NOT be saved!");
|
||||
}
|
||||
}
|
||||
|
||||
public void onPluginStartup() {
|
||||
getLogger().info("Loading configuration...");
|
||||
saveDefaultConfig();
|
||||
config = new NickoConfiguration(this);
|
||||
dataStore = new PlayerDataStore(this);
|
||||
nicko.initBukkit(this);
|
||||
|
||||
getLogger().info("Loading internals...");
|
||||
if (getInternals() == null) {
|
||||
getLogger().severe("Nicko could not find a valid implementation for this server version. Is your server supported?");
|
||||
dataStore.getStorage().setError(true);
|
||||
nicko.getDataStore().getStorage().setError(true);
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
}
|
||||
|
||||
if (getServer().getPluginManager().isPluginEnabled(this) && !dataStore.getStorage().isError()) {
|
||||
if (getServer().getPluginManager().isPluginEnabled(this) && !nicko.getDataStore().getStorage().isError()) {
|
||||
getLogger().info("Loading persistence...");
|
||||
if (!dataStore.getStorage().getProvider().init()) {
|
||||
dataStore.getStorage().setError(true);
|
||||
if (!nicko.getDataStore().getStorage().getProvider().init()) {
|
||||
nicko.getDataStore().getStorage().setError(true);
|
||||
getLogger().severe("Failed to open persistence, data will NOT be saved!");
|
||||
}
|
||||
|
||||
mojangAPI = new MojangAPI(this);
|
||||
|
||||
localeFileManager = new LocaleFileManager();
|
||||
if (config.isCustomLocale()) {
|
||||
if (nicko.getConfig().customLocale()) {
|
||||
if (localeFileManager.dumpFromLocale(Locale.ENGLISH)) {
|
||||
getLogger().info("Successfully loaded custom language file.");
|
||||
} else {
|
||||
|
@ -116,7 +111,7 @@ public class NickoBukkit extends JavaPlugin {
|
|||
|
||||
final BungeeCordSupport support = new BungeeCordSupport(this);
|
||||
support.warnNickoNotHookedToBungeeCord();
|
||||
if (config.isBungeecordSupport()) {
|
||||
if (nicko.getConfig().bungeecord()) {
|
||||
if (support.stopIfBungeeCordIsNotEnabled()) {
|
||||
getLogger().info("Enabling BungeeCord support...");
|
||||
getServer().getMessenger().registerIncomingPluginChannel(this, NickoBungee.PROXY_UPDATE, new PluginMessageHandler());
|
||||
|
@ -129,16 +124,16 @@ public class NickoBukkit extends JavaPlugin {
|
|||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (!dataStore.getStorage().isError()) {
|
||||
if (!nicko.getDataStore().getStorage().isError()) {
|
||||
getLogger().info("Closing persistence...");
|
||||
dataStore.removeAllNames();
|
||||
dataStore.saveAll();
|
||||
if (!dataStore.getStorage().getProvider().close()) {
|
||||
nicko.getDataStore().removeAllNames();
|
||||
nicko.getDataStore().saveAll();
|
||||
if (!nicko.getDataStore().getStorage().getProvider().close()) {
|
||||
getLogger().severe("Failed to close persistence!");
|
||||
}
|
||||
}
|
||||
|
||||
if (config.isBungeecordSupport()) {
|
||||
if (nicko.getConfig().bungeecord()) {
|
||||
getServer().getMessenger().unregisterIncomingPluginChannel(this);
|
||||
getServer().getMessenger().unregisterOutgoingPluginChannel(this);
|
||||
}
|
||||
|
@ -150,14 +145,14 @@ public class NickoBukkit extends JavaPlugin {
|
|||
return plugin;
|
||||
}
|
||||
|
||||
public Nicko getNicko() {
|
||||
return nicko;
|
||||
}
|
||||
|
||||
public MojangAPI getMojangAPI() {
|
||||
return mojangAPI;
|
||||
}
|
||||
|
||||
public NickoConfiguration getNickoConfig() { return config; }
|
||||
|
||||
public PlayerDataStore getDataStore() { return dataStore; }
|
||||
|
||||
public LocaleFileManager getLocaleFileManager() {
|
||||
return localeFileManager;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package net.artelnatif.nicko.anvil;
|
||||
package net.artelnatif.nicko.bukkit.anvil;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
import net.artelnatif.nicko.disguise.AppearanceManager;
|
||||
import net.artelnatif.nicko.disguise.ActionResult;
|
||||
import net.artelnatif.nicko.i18n.I18N;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package net.artelnatif.nicko.command;
|
||||
package net.artelnatif.nicko.bukkit.command;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.command.sub.NickoCheckSubCmd;
|
||||
import net.artelnatif.nicko.command.sub.NickoDebugSubCmd;
|
||||
import net.artelnatif.nicko.gui.MainGUI;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
import net.artelnatif.nicko.bukkit.command.sub.NickoCheckSubCmd;
|
||||
import net.artelnatif.nicko.bukkit.command.sub.NickoDebugSubCmd;
|
||||
import net.artelnatif.nicko.bukkit.gui.MainGUI;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package net.artelnatif.nicko.command.sub;
|
||||
package net.artelnatif.nicko.bukkit.command.sub;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
import net.artelnatif.nicko.disguise.AppearanceManager;
|
||||
import net.artelnatif.nicko.i18n.I18N;
|
||||
import net.artelnatif.nicko.i18n.I18NDict;
|
||||
|
@ -28,7 +28,7 @@ public class NickoCheckSubCmd {
|
|||
}
|
||||
|
||||
final StringJoiner builder = new StringJoiner("\n");
|
||||
builder.add("§c" + NickoBukkit.getInstance().getNickoConfig().getPrefix() + "§6Check for: §f§o" + targetName);
|
||||
builder.add("§c" + NickoBukkit.getInstance().getNicko().getConfig().prefix() + "§6Check for: §f§o" + targetName);
|
||||
if (!appearanceManager.hasData()) {
|
||||
builder.add("§cThis player has not data.");
|
||||
} else {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package net.artelnatif.nicko.command.sub;
|
||||
package net.artelnatif.nicko.bukkit.command.sub;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
import net.artelnatif.nicko.disguise.AppearanceManager;
|
||||
import net.artelnatif.nicko.mojang.MojangUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -10,6 +10,8 @@ import org.bukkit.entity.Player;
|
|||
|
||||
public class NickoDebugSubCmd {
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
final String prefix = NickoBukkit.getInstance().getNicko().getConfig().prefix();
|
||||
|
||||
Player target;
|
||||
String name, skin;
|
||||
if (args.length == 3) {
|
||||
|
@ -18,7 +20,7 @@ public class NickoDebugSubCmd {
|
|||
skin = args[2];
|
||||
} else {
|
||||
if (args.length < 3) {
|
||||
sender.sendMessage(NickoBukkit.getInstance().getNickoConfig().getPrefix() + "§cMissing argument.");
|
||||
sender.sendMessage(prefix + "§cMissing argument.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -28,7 +30,7 @@ public class NickoDebugSubCmd {
|
|||
|
||||
target = Bukkit.getPlayer(playerName);
|
||||
if (target == null) {
|
||||
sender.sendMessage(NickoBukkit.getInstance().getNickoConfig().getPrefix() + "§cSpecified player is offline.");
|
||||
sender.sendMessage(prefix + "§cSpecified player is offline.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -36,11 +38,11 @@ public class NickoDebugSubCmd {
|
|||
final AppearanceManager appearanceManager = AppearanceManager.get(target.getPlayer());
|
||||
|
||||
if (MojangUtils.isUsernameInvalid(name) || MojangUtils.isUsernameInvalid(skin)) {
|
||||
sender.sendMessage(NickoBukkit.getInstance().getNickoConfig().getPrefix() + "§cSpecified username is invalid.");
|
||||
sender.sendMessage(prefix + "§cSpecified username is invalid.");
|
||||
}
|
||||
|
||||
appearanceManager.setNameAndSkin(name, skin);
|
||||
target.sendMessage(NickoBukkit.getInstance().getNickoConfig().getPrefix() + "§aWhoosh!");
|
||||
target.sendMessage(prefix + "§aWhoosh!");
|
||||
target.playSound(target.getLocation(), Sound.ENTITY_ITEM_FRAME_PLACE, 1, 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package net.artelnatif.nicko.gui;
|
||||
package net.artelnatif.nicko.bukkit.gui;
|
||||
|
||||
import de.studiocode.invui.gui.GUI;
|
||||
import de.studiocode.invui.gui.builder.GUIBuilder;
|
||||
import de.studiocode.invui.gui.builder.guitype.GUIType;
|
||||
import de.studiocode.invui.window.impl.single.SimpleWindow;
|
||||
import net.artelnatif.nicko.gui.items.admin.ManageCache;
|
||||
import net.artelnatif.nicko.gui.items.common.GoBack;
|
||||
import net.artelnatif.nicko.bukkit.gui.items.common.GoBack;
|
||||
import net.artelnatif.nicko.bukkit.gui.items.admin.ManageCache;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class AdminGUI {
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package net.artelnatif.nicko.gui;
|
||||
package net.artelnatif.nicko.bukkit.gui;
|
||||
|
||||
import de.studiocode.invui.gui.GUI;
|
||||
import de.studiocode.invui.gui.builder.GUIBuilder;
|
||||
import de.studiocode.invui.gui.builder.guitype.GUIType;
|
||||
import de.studiocode.invui.window.impl.single.SimpleWindow;
|
||||
import net.artelnatif.nicko.gui.items.common.GoBack;
|
||||
import net.artelnatif.nicko.gui.items.skin.ChangeName;
|
||||
import net.artelnatif.nicko.gui.items.skin.ChangeNameAndSkin;
|
||||
import net.artelnatif.nicko.gui.items.skin.ChangeSkin;
|
||||
import net.artelnatif.nicko.bukkit.gui.items.common.GoBack;
|
||||
import net.artelnatif.nicko.bukkit.gui.items.skin.ChangeSkin;
|
||||
import net.artelnatif.nicko.bukkit.gui.items.skin.ChangeName;
|
||||
import net.artelnatif.nicko.bukkit.gui.items.skin.ChangeNameAndSkin;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class AppearanceManagerGUI {
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package net.artelnatif.nicko.gui;
|
||||
package net.artelnatif.nicko.bukkit.gui;
|
||||
|
||||
import de.studiocode.invui.gui.GUI;
|
||||
import de.studiocode.invui.gui.builder.GUIBuilder;
|
||||
import de.studiocode.invui.gui.builder.guitype.GUIType;
|
||||
import de.studiocode.invui.window.impl.single.SimpleWindow;
|
||||
import net.artelnatif.nicko.gui.items.main.AdminSubGUI;
|
||||
import net.artelnatif.nicko.gui.items.main.ResetAppearance;
|
||||
import net.artelnatif.nicko.gui.items.main.SettingsSubGUI;
|
||||
import net.artelnatif.nicko.gui.items.main.AppearanceManagerSubGUI;
|
||||
import net.artelnatif.nicko.bukkit.gui.items.main.AdminSubGUI;
|
||||
import net.artelnatif.nicko.bukkit.gui.items.main.AppearanceManagerSubGUI;
|
||||
import net.artelnatif.nicko.bukkit.gui.items.main.ResetAppearance;
|
||||
import net.artelnatif.nicko.bukkit.gui.items.main.SettingsSubGUI;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class MainGUI {
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package net.artelnatif.nicko.gui;
|
||||
package net.artelnatif.nicko.bukkit.gui;
|
||||
|
||||
import de.studiocode.invui.gui.GUI;
|
||||
import de.studiocode.invui.gui.builder.GUIBuilder;
|
||||
import de.studiocode.invui.gui.builder.guitype.GUIType;
|
||||
import de.studiocode.invui.window.impl.single.SimpleWindow;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.gui.items.common.GoBack;
|
||||
import net.artelnatif.nicko.gui.items.settings.BungeeCordCycling;
|
||||
import net.artelnatif.nicko.gui.items.settings.LanguageCycling;
|
||||
import net.artelnatif.nicko.gui.items.settings.OptionUnavailable;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
import net.artelnatif.nicko.bukkit.gui.items.settings.LanguageCycling;
|
||||
import net.artelnatif.nicko.bukkit.gui.items.common.GoBack;
|
||||
import net.artelnatif.nicko.bukkit.gui.items.settings.BungeeCordCycling;
|
||||
import net.artelnatif.nicko.bukkit.gui.items.settings.OptionUnavailable;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class SettingsGUI {
|
||||
|
@ -22,7 +22,7 @@ public class SettingsGUI {
|
|||
"B # # # # # # # #"
|
||||
};
|
||||
|
||||
if (!NickoBukkit.getInstance().getNickoConfig().isBungeecordSupport()) {
|
||||
if (!NickoBukkit.getInstance().getNicko().getConfig().bungeecord()) {
|
||||
dynamicStructure[1] = dynamicStructure[1].replace("T", "U");
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package net.artelnatif.nicko.gui.admin;
|
||||
package net.artelnatif.nicko.bukkit.gui.admin;
|
||||
|
||||
import de.studiocode.invui.gui.GUI;
|
||||
import de.studiocode.invui.gui.builder.GUIBuilder;
|
||||
import de.studiocode.invui.gui.builder.guitype.GUIType;
|
||||
import de.studiocode.invui.window.impl.single.SimpleWindow;
|
||||
import net.artelnatif.nicko.gui.AdminGUI;
|
||||
import net.artelnatif.nicko.gui.items.admin.cache.CacheDetailed;
|
||||
import net.artelnatif.nicko.gui.items.admin.cache.CacheInvalidate;
|
||||
import net.artelnatif.nicko.gui.items.admin.cache.CacheOverview;
|
||||
import net.artelnatif.nicko.gui.items.common.GoBack;
|
||||
import net.artelnatif.nicko.bukkit.gui.AdminGUI;
|
||||
import net.artelnatif.nicko.bukkit.gui.items.admin.cache.CacheDetailed;
|
||||
import net.artelnatif.nicko.bukkit.gui.items.admin.cache.CacheInvalidate;
|
||||
import net.artelnatif.nicko.bukkit.gui.items.admin.cache.CacheOverview;
|
||||
import net.artelnatif.nicko.bukkit.gui.items.common.GoBack;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CacheManagementGUI {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package net.artelnatif.nicko.gui.admin.cache;
|
||||
package net.artelnatif.nicko.bukkit.gui.admin.cache;
|
||||
|
||||
import de.studiocode.invui.gui.GUI;
|
||||
import de.studiocode.invui.gui.builder.GUIBuilder;
|
||||
|
@ -6,12 +6,12 @@ import de.studiocode.invui.gui.builder.guitype.GUIType;
|
|||
import de.studiocode.invui.gui.structure.Markers;
|
||||
import de.studiocode.invui.item.Item;
|
||||
import de.studiocode.invui.window.impl.single.SimpleWindow;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.gui.admin.CacheManagementGUI;
|
||||
import net.artelnatif.nicko.gui.items.admin.cache.SkinPlaceholder;
|
||||
import net.artelnatif.nicko.gui.items.common.GoBack;
|
||||
import net.artelnatif.nicko.gui.items.common.ScrollDown;
|
||||
import net.artelnatif.nicko.gui.items.common.ScrollUp;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
import net.artelnatif.nicko.bukkit.gui.items.admin.cache.SkinPlaceholder;
|
||||
import net.artelnatif.nicko.bukkit.gui.admin.CacheManagementGUI;
|
||||
import net.artelnatif.nicko.bukkit.gui.items.common.GoBack;
|
||||
import net.artelnatif.nicko.bukkit.gui.items.common.ScrollDown;
|
||||
import net.artelnatif.nicko.bukkit.gui.items.common.ScrollUp;
|
||||
import net.artelnatif.nicko.mojang.MojangSkin;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package net.artelnatif.nicko.gui.items.admin;
|
||||
package net.artelnatif.nicko.bukkit.gui.items.admin;
|
||||
|
||||
import de.studiocode.invui.item.builder.ItemBuilder;
|
||||
import de.studiocode.invui.item.builder.SkullBuilder;
|
||||
import de.studiocode.invui.item.impl.AsyncItem;
|
||||
import net.artelnatif.nicko.gui.admin.CacheManagementGUI;
|
||||
import net.artelnatif.nicko.bukkit.gui.admin.CacheManagementGUI;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package net.artelnatif.nicko.gui.items.admin.cache;
|
||||
package net.artelnatif.nicko.bukkit.gui.items.admin.cache;
|
||||
|
||||
import de.studiocode.invui.item.ItemProvider;
|
||||
import de.studiocode.invui.item.builder.ItemBuilder;
|
||||
import de.studiocode.invui.item.impl.BaseItem;
|
||||
import net.artelnatif.nicko.gui.admin.cache.CacheDetailledGUI;
|
||||
import net.artelnatif.nicko.bukkit.gui.admin.cache.CacheDetailledGUI;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package net.artelnatif.nicko.gui.items.admin.cache;
|
||||
package net.artelnatif.nicko.bukkit.gui.items.admin.cache;
|
||||
|
||||
import de.studiocode.invui.item.ItemProvider;
|
||||
import de.studiocode.invui.item.builder.ItemBuilder;
|
||||
import de.studiocode.invui.item.impl.BaseItem;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
import net.artelnatif.nicko.i18n.I18N;
|
||||
import net.artelnatif.nicko.i18n.I18NDict;
|
||||
import org.bukkit.Material;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package net.artelnatif.nicko.gui.items.admin.cache;
|
||||
package net.artelnatif.nicko.bukkit.gui.items.admin.cache;
|
||||
|
||||
import com.google.common.cache.CacheStats;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import de.studiocode.invui.item.ItemProvider;
|
||||
import de.studiocode.invui.item.builder.ItemBuilder;
|
||||
import de.studiocode.invui.item.impl.BaseItem;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
import net.artelnatif.nicko.mojang.MojangSkin;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package net.artelnatif.nicko.gui.items.admin.cache;
|
||||
package net.artelnatif.nicko.bukkit.gui.items.admin.cache;
|
||||
|
||||
import de.studiocode.invui.item.builder.ItemBuilder;
|
||||
import de.studiocode.invui.item.builder.SkullBuilder;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package net.artelnatif.nicko.gui.items.common;
|
||||
package net.artelnatif.nicko.bukkit.gui.items.common;
|
||||
|
||||
import de.studiocode.invui.gui.GUI;
|
||||
import de.studiocode.invui.item.ItemProvider;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package net.artelnatif.nicko.gui.items.common;
|
||||
package net.artelnatif.nicko.bukkit.gui.items.common;
|
||||
|
||||
import de.studiocode.invui.gui.impl.ScrollGUI;
|
||||
import de.studiocode.invui.item.ItemProvider;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package net.artelnatif.nicko.gui.items.common;
|
||||
package net.artelnatif.nicko.bukkit.gui.items.common;
|
||||
|
||||
import de.studiocode.invui.gui.impl.ScrollGUI;
|
||||
import de.studiocode.invui.item.ItemProvider;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package net.artelnatif.nicko.gui.items.main;
|
||||
package net.artelnatif.nicko.bukkit.gui.items.main;
|
||||
|
||||
import de.studiocode.invui.item.ItemProvider;
|
||||
import de.studiocode.invui.item.builder.ItemBuilder;
|
||||
import de.studiocode.invui.item.impl.BaseItem;
|
||||
import net.artelnatif.nicko.gui.AdminGUI;
|
||||
import net.artelnatif.nicko.bukkit.gui.AdminGUI;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package net.artelnatif.nicko.gui.items.main;
|
||||
package net.artelnatif.nicko.bukkit.gui.items.main;
|
||||
|
||||
import de.studiocode.invui.item.ItemProvider;
|
||||
import de.studiocode.invui.item.builder.ItemBuilder;
|
||||
import de.studiocode.invui.item.impl.BaseItem;
|
||||
import net.artelnatif.nicko.gui.AppearanceManagerGUI;
|
||||
import net.artelnatif.nicko.bukkit.gui.AppearanceManagerGUI;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package net.artelnatif.nicko.gui.items.main;
|
||||
package net.artelnatif.nicko.bukkit.gui.items.main;
|
||||
|
||||
import de.studiocode.invui.item.ItemProvider;
|
||||
import de.studiocode.invui.item.builder.ItemBuilder;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package net.artelnatif.nicko.gui.items.main;
|
||||
package net.artelnatif.nicko.bukkit.gui.items.main;
|
||||
|
||||
import de.studiocode.invui.item.ItemProvider;
|
||||
import de.studiocode.invui.item.builder.ItemBuilder;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package net.artelnatif.nicko.gui.items.main;
|
||||
package net.artelnatif.nicko.bukkit.gui.items.main;
|
||||
|
||||
import de.studiocode.invui.item.ItemProvider;
|
||||
import de.studiocode.invui.item.builder.ItemBuilder;
|
||||
import de.studiocode.invui.item.impl.BaseItem;
|
||||
import net.artelnatif.nicko.gui.SettingsGUI;
|
||||
import net.artelnatif.nicko.bukkit.gui.SettingsGUI;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package net.artelnatif.nicko.gui.items.settings;
|
||||
package net.artelnatif.nicko.bukkit.gui.items.settings;
|
||||
|
||||
import de.studiocode.invui.item.ItemProvider;
|
||||
import de.studiocode.invui.item.builder.ItemBuilder;
|
||||
import de.studiocode.invui.item.impl.BaseItem;
|
||||
import de.studiocode.invui.item.impl.CycleItem;
|
||||
import de.studiocode.invui.item.impl.SimpleItem;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
|
@ -20,7 +20,7 @@ public class BungeeCordCycling {
|
|||
};
|
||||
|
||||
public BaseItem get(Player player) {
|
||||
Optional<NickoProfile> profile = NickoBukkit.getInstance().getDataStore().getData(player.getUniqueId());
|
||||
Optional<NickoProfile> profile = NickoBukkit.getInstance().getNicko().getDataStore().getData(player.getUniqueId());
|
||||
if (profile.isPresent()) {
|
||||
final NickoProfile nickoProfile = profile.get();
|
||||
int startingState = nickoProfile.isBungeecordTransfer() ? 0 : 1;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package net.artelnatif.nicko.gui.items.settings;
|
||||
package net.artelnatif.nicko.bukkit.gui.items.settings;
|
||||
|
||||
import de.studiocode.invui.item.ItemProvider;
|
||||
import de.studiocode.invui.item.builder.ItemBuilder;
|
||||
import de.studiocode.invui.item.impl.BaseItem;
|
||||
import de.studiocode.invui.item.impl.CycleItem;
|
||||
import de.studiocode.invui.item.impl.SimpleItem;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||
import net.artelnatif.nicko.i18n.Locale;
|
||||
import org.bukkit.Material;
|
||||
|
@ -19,7 +19,7 @@ public class LanguageCycling {
|
|||
|
||||
public BaseItem get(Player player) {
|
||||
final NickoBukkit instance = NickoBukkit.getInstance();
|
||||
Optional<NickoProfile> profile = instance.getDataStore().getData(player.getUniqueId());
|
||||
Optional<NickoProfile> profile = instance.getNicko().getDataStore().getData(player.getUniqueId());
|
||||
if (profile.isPresent()) {
|
||||
final NickoProfile nickoProfile = profile.get();
|
||||
int localeOrdinal = nickoProfile.getLocale().ordinal();
|
||||
|
@ -52,7 +52,7 @@ public class LanguageCycling {
|
|||
|
||||
final ArrayList<Locale> localesToGenerate = new ArrayList<>();
|
||||
Collections.addAll(localesToGenerate, Locale.values());
|
||||
if (!instance.getNickoConfig().isCustomLocale()) {
|
||||
if (!instance.getNicko().getConfig().customLocale()) {
|
||||
localesToGenerate.remove(Locale.CUSTOM);
|
||||
}
|
||||
localesToGenerate.forEach(locale -> items.add(generateItem(locale, localesToGenerate)));
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package net.artelnatif.nicko.gui.items.settings;
|
||||
package net.artelnatif.nicko.bukkit.gui.items.settings;
|
||||
|
||||
import de.studiocode.invui.item.ItemProvider;
|
||||
import de.studiocode.invui.item.builder.ItemBuilder;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package net.artelnatif.nicko.gui.items.skin;
|
||||
package net.artelnatif.nicko.bukkit.gui.items.skin;
|
||||
|
||||
import de.studiocode.invui.item.ItemProvider;
|
||||
import de.studiocode.invui.item.builder.ItemBuilder;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package net.artelnatif.nicko.gui.items.skin;
|
||||
package net.artelnatif.nicko.bukkit.gui.items.skin;
|
||||
|
||||
import de.studiocode.invui.item.ItemProvider;
|
||||
import de.studiocode.invui.item.builder.ItemBuilder;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package net.artelnatif.nicko.gui.items.skin;
|
||||
package net.artelnatif.nicko.bukkit.gui.items.skin;
|
||||
|
||||
import de.studiocode.invui.item.ItemProvider;
|
||||
import de.studiocode.invui.item.builder.ItemBuilder;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package net.artelnatif.nicko.pluginchannel;
|
||||
package net.artelnatif.nicko.bukkit.pluginchannel;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
import net.artelnatif.nicko.bungee.NickoBungee;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package net.artelnatif.nicko.bungee;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
|
@ -14,7 +14,7 @@ public class BungeeCordSupport {
|
|||
public void warnNickoNotHookedToBungeeCord() {
|
||||
final Server server = instance.getServer();
|
||||
final YamlConfiguration config = server.spigot().getConfig();
|
||||
if (config.getConfigurationSection("settings").getBoolean("bungeecord") && !instance.getNickoConfig().isBungeecordSupport()) {
|
||||
if (config.getConfigurationSection("settings").getBoolean("bungeecord") && !instance.getNicko().getConfig().bungeecord()) {
|
||||
instance.getLogger().warning("Hummm. Your server is hooked to BungeeCord, but it seems");
|
||||
instance.getLogger().warning("that BungeeCord support is not enabled inside Nicko.");
|
||||
instance.getLogger().warning("If this is intentional, you can safely ignore this message.");
|
||||
|
@ -25,7 +25,7 @@ public class BungeeCordSupport {
|
|||
public boolean stopIfBungeeCordIsNotEnabled() {
|
||||
final Server server = instance.getServer();
|
||||
final YamlConfiguration config = server.spigot().getConfig();
|
||||
if (!config.getConfigurationSection("settings").getBoolean("bungeecord") && instance.getNickoConfig().isBungeecordSupport()) {
|
||||
if (!config.getConfigurationSection("settings").getBoolean("bungeecord") && instance.getNicko().getConfig().bungeecord()) {
|
||||
instance.getLogger().severe("Hummm. You have enabled BungeeCord support inside Nicko,");
|
||||
instance.getLogger().severe("but it seems that your server is not hooked to your BungeeCord instance.");
|
||||
instance.getLogger().severe("Please enable BungeeCord support inside your spigot.yml as well.");
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package net.artelnatif.nicko.bungee;
|
||||
|
||||
import net.artelnatif.nicko.bungee.event.ServerSwitchListener;
|
||||
import net.artelnatif.nicko.bungee.event.UpdateMessageListener;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
public class NickoBungee extends Plugin {
|
||||
public static final String NICKO_PLUGIN_CHANNEL_BASE = "nicko:";
|
||||
public static final String NICKO_PLUGIN_CHANNEL_UPDATE = NICKO_PLUGIN_CHANNEL_BASE + "update";
|
||||
public static final String PROXY_UPDATE = NICKO_PLUGIN_CHANNEL_BASE + "update";
|
||||
public static final String PROXY_FETCH = NICKO_PLUGIN_CHANNEL_BASE + "fetch";
|
||||
public static final String SERVER_DATA = NICKO_PLUGIN_CHANNEL_BASE + "data";
|
||||
|
||||
private static NickoBungee plugin;
|
||||
|
||||
|
@ -14,10 +16,10 @@ public class NickoBungee extends Plugin {
|
|||
plugin = this;
|
||||
|
||||
getLogger().info("Registering channel...");
|
||||
getProxy().registerChannel(NICKO_PLUGIN_CHANNEL_UPDATE);
|
||||
getProxy().registerChannel(SERVER_DATA);
|
||||
|
||||
getLogger().info("Registering listeners...");
|
||||
getProxy().getPluginManager().registerListener(this, new ServerSwitchListener());
|
||||
getLogger().info("Registering listener...");
|
||||
getProxy().getPluginManager().registerListener(this, new UpdateMessageListener());
|
||||
|
||||
getLogger().info("Nicko (Bungee) has been enabled.");
|
||||
}
|
||||
|
@ -25,7 +27,7 @@ public class NickoBungee extends Plugin {
|
|||
@Override
|
||||
public void onDisable() {
|
||||
getLogger().info("Unregistering channels...");
|
||||
getProxy().unregisterChannel(NICKO_PLUGIN_CHANNEL_UPDATE);
|
||||
getProxy().unregisterChannel(PROXY_UPDATE);
|
||||
|
||||
getLogger().info("Nicko (Bungee) has been disabled.");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package net.artelnatif.nicko.bungee.event;
|
||||
|
||||
import net.artelnatif.nicko.bungee.NickoBungee;
|
||||
import net.artelnatif.nicko.bungee.message.PluginMessageSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
public class FetchMessageListener implements Listener {
|
||||
@EventHandler
|
||||
public void onMessage(PluginMessageEvent event) {
|
||||
if (!event.getTag().equals(NickoBungee.PROXY_FETCH)) { return; }
|
||||
|
||||
try (DataInputStream input = new DataInputStream(new ByteArrayInputStream(event.getData()))) {
|
||||
final ProxyServer proxy = NickoBungee.getInstance().getProxy();
|
||||
|
||||
final String uuid = input.readUTF();
|
||||
final ProxiedPlayer player = proxy.getPlayer(UUID.fromString(uuid));
|
||||
final ServerInfo serverInfo = player.getServer().getInfo();
|
||||
|
||||
// TODO: 1/28/23 FETCH PROFILE
|
||||
final ArrayList<String> payload = new ArrayList<>();
|
||||
payload.add(player.getUniqueId().toString());
|
||||
|
||||
PluginMessageSender.send(serverInfo, NickoBungee.SERVER_DATA, payload);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package net.artelnatif.nicko.bungee.event;
|
||||
|
||||
import net.artelnatif.nicko.bungee.NickoBungee;
|
||||
import net.artelnatif.nicko.bungee.message.MessageDecoder;
|
||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class UpdateMessageListener implements Listener {
|
||||
@EventHandler
|
||||
public void onMessage(PluginMessageEvent event) {
|
||||
if (!event.getTag().equals(NickoBungee.PROXY_UPDATE)) { return; }
|
||||
|
||||
try (DataInputStream input = new DataInputStream(new ByteArrayInputStream(event.getData()))) {
|
||||
final NickoProfile profile = MessageDecoder.decode(input);
|
||||
|
||||
// TODO: 1/28/23 STORE PROFILE
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package net.artelnatif.nicko.bungee.message;
|
||||
|
||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||
import net.artelnatif.nicko.i18n.Locale;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class MessageDecoder {
|
||||
public static final int STRING_SIZE = 3;
|
||||
|
||||
public static NickoProfile decode(DataInputStream input) throws IOException {
|
||||
final String[] stringValues = new String[3];
|
||||
for (int i = 1; i < STRING_SIZE; i++) { stringValues[i] = input.readUTF(); }
|
||||
return new NickoProfile(stringValues[0], stringValues[1], Locale.valueOf(stringValues[2]), true);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package net.artelnatif.nicko.bungee.pluginchannel;
|
||||
package net.artelnatif.nicko.bungee.message;
|
||||
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
|
|
@ -1,130 +0,0 @@
|
|||
package net.artelnatif.nicko.config;
|
||||
|
||||
import net.artelnatif.nicko.Nicko;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
import net.artelnatif.nicko.bungee.NickoBungee;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public class NickoConfiguration {
|
||||
private final Nicko nicko;
|
||||
private String prefix;
|
||||
|
||||
private Boolean bungeecordSupport;
|
||||
private Boolean localStorage;
|
||||
private Boolean customLocale;
|
||||
|
||||
private String sqlUsername, sqlPassword, sqlAddress;
|
||||
|
||||
public NickoConfiguration(Nicko nicko) {
|
||||
this.nicko = nicko;
|
||||
}
|
||||
|
||||
//.............
|
||||
// SECTION ACCESSORS
|
||||
//.............
|
||||
|
||||
public ConfigurationSection getBungeecordSection() { return getConfig().getConfigurationSection("bungeecord"); }
|
||||
|
||||
// Unused for now
|
||||
public ConfigurationSection getRedisSection() { return getBungeecordSection().getConfigurationSection("redis"); }
|
||||
|
||||
public ConfigurationSection getLocaleSection() { return getConfig().getConfigurationSection("locale"); }
|
||||
|
||||
public ConfigurationSection getStorageSection() { return getConfig().getConfigurationSection("storage"); }
|
||||
|
||||
//.............
|
||||
// GLOBAL
|
||||
//.............
|
||||
|
||||
public String getPrefix() {
|
||||
if (prefix == null) {
|
||||
return prefix = getConfig().getString("prefix");
|
||||
}
|
||||
return prefix;
|
||||
}
|
||||
|
||||
//.............
|
||||
// BUNGEECORD
|
||||
//.............
|
||||
|
||||
public boolean isBungeecordSupport() {
|
||||
if (bungeecordSupport == null) {
|
||||
return bungeecordSupport = getBungeecordSection().getBoolean("enabled");
|
||||
}
|
||||
return bungeecordSupport;
|
||||
}
|
||||
|
||||
public void setBungeecordSupport(Boolean bungeecordSupport) {
|
||||
this.bungeecordSupport = bungeecordSupport;
|
||||
}
|
||||
|
||||
//.............
|
||||
// LOCALE
|
||||
//.............
|
||||
|
||||
public boolean isCustomLocale() {
|
||||
if (customLocale == null) {
|
||||
return customLocale = getLocaleSection().getBoolean("use_custom_locale");
|
||||
}
|
||||
return customLocale;
|
||||
}
|
||||
|
||||
public void setCustomLocale(boolean customLocale) {
|
||||
this.customLocale = customLocale;
|
||||
}
|
||||
|
||||
//.............
|
||||
// STORAGE
|
||||
//.............
|
||||
|
||||
public boolean isLocalStorage() {
|
||||
if (localStorage == null) {
|
||||
return localStorage = getStorageSection().getBoolean("local");
|
||||
}
|
||||
return localStorage;
|
||||
}
|
||||
|
||||
public void setLocalStorage(boolean localStorage) {
|
||||
this.localStorage = localStorage;
|
||||
}
|
||||
|
||||
public String getSQLUsername() {
|
||||
if (sqlUsername == null) {
|
||||
return sqlUsername = getStorageSection().getString("username");
|
||||
}
|
||||
return sqlUsername;
|
||||
}
|
||||
|
||||
public void setSQLUsername(String sqlUsername) {
|
||||
this.sqlUsername = sqlUsername;
|
||||
}
|
||||
|
||||
public String getSQLPassword() {
|
||||
if (sqlPassword == null) {
|
||||
return sqlPassword = getStorageSection().getString("password");
|
||||
}
|
||||
return sqlPassword;
|
||||
}
|
||||
|
||||
public void setSQLPassword(String sqlPassword) {
|
||||
this.sqlPassword = sqlPassword;
|
||||
}
|
||||
|
||||
public String getSQLAddress() {
|
||||
if (sqlAddress == null) {
|
||||
return sqlAddress = getStorageSection().getString("address");
|
||||
}
|
||||
return sqlAddress;
|
||||
}
|
||||
|
||||
public void setSQLAddress(String sqlAddress) {
|
||||
this.sqlAddress = sqlAddress;
|
||||
}
|
||||
|
||||
private FileConfiguration getConfig() {
|
||||
final YamlConfiguration configuration = new YamlConfiguration();
|
||||
return ;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package net.artelnatif.nicko.config;
|
||||
|
||||
public record Configuration(
|
||||
String address,
|
||||
String username,
|
||||
String password,
|
||||
String prefix,
|
||||
Boolean local,
|
||||
Boolean bungeecord,
|
||||
Boolean customLocale) { }
|
|
@ -0,0 +1,48 @@
|
|||
package net.artelnatif.nicko.config;
|
||||
|
||||
import net.artelnatif.nicko.Nicko;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
public class ConfigurationManager {
|
||||
private final Nicko nicko;
|
||||
private final Yaml yaml = new Yaml();
|
||||
private final File directory;
|
||||
private final File file;
|
||||
|
||||
public ConfigurationManager(Nicko nicko) {
|
||||
this.nicko = nicko;
|
||||
this.directory = nicko.getDataFolder();
|
||||
this.file = new File(directory, "config.yml");
|
||||
}
|
||||
|
||||
public void save(Configuration configuration) throws IOException {
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
|
||||
yaml.dump(configuration, writer);
|
||||
writer.flush();
|
||||
}
|
||||
}
|
||||
|
||||
public void saveDefaultConfig() {
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
final InputStream input = ConfigurationManager.class.getResourceAsStream("config.yml");
|
||||
if (input != null) {
|
||||
nicko.getLogger().info("Saved default configuration as config.yml");
|
||||
Files.copy(input, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Configuration load() throws IOException {
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
|
||||
return yaml.loadAs(reader, Configuration.class);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package net.artelnatif.nicko.disguise;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
import net.artelnatif.nicko.storage.PlayerDataStore;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -11,7 +11,7 @@ public class AppearanceManager {
|
|||
private final NickoProfile profile;
|
||||
private final Player player;
|
||||
private final NickoBukkit instance = NickoBukkit.getInstance();
|
||||
private final PlayerDataStore dataStore = instance.getDataStore();
|
||||
private final PlayerDataStore dataStore = instance.getNicko().getDataStore();
|
||||
|
||||
private AppearanceManager(UUID uuid) {
|
||||
this.player = Bukkit.getPlayer(uuid);
|
||||
|
@ -65,21 +65,21 @@ public class AppearanceManager {
|
|||
updatePlayer(true);
|
||||
}
|
||||
|
||||
public ActionResult reset() {
|
||||
final String defaultName = instance.getDataStore().getStoredName(player);
|
||||
public ActionResult<Void> reset() {
|
||||
final String defaultName = instance.getNicko().getDataStore().getStoredName(player);
|
||||
this.profile.setName(defaultName);
|
||||
this.profile.setSkin(defaultName);
|
||||
final ActionResult actionResult = resetPlayer();
|
||||
final ActionResult<Void> actionResult = resetPlayer();
|
||||
this.profile.setSkin(null);
|
||||
this.profile.setName(null);
|
||||
return actionResult;
|
||||
}
|
||||
|
||||
public ActionResult resetPlayer() {
|
||||
public ActionResult<Void> resetPlayer() {
|
||||
return NickoBukkit.getInstance().getInternals().updateProfile(player, profile, true, true);
|
||||
}
|
||||
|
||||
public ActionResult updatePlayer(boolean skinChange) {
|
||||
public ActionResult<Void> updatePlayer(boolean skinChange) {
|
||||
return NickoBukkit.getInstance().getInternals().updateProfile(player, profile, skinChange, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package net.artelnatif.nicko.event;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
import net.artelnatif.nicko.disguise.AppearanceManager;
|
||||
import net.artelnatif.nicko.disguise.ActionResult;
|
||||
import net.artelnatif.nicko.i18n.I18N;
|
||||
|
@ -15,14 +15,14 @@ public class PlayerJoinListener implements Listener {
|
|||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
NickoBukkit.getInstance().getDataStore().storeName(player);
|
||||
NickoBukkit.getInstance().getNicko().getDataStore().storeName(player);
|
||||
Bukkit.getScheduler().runTaskLater(NickoBukkit.getInstance(), () -> {
|
||||
final AppearanceManager appearanceManager = AppearanceManager.get(player);
|
||||
|
||||
// TODO: 12/5/22 Update from BungeeCord
|
||||
|
||||
if (appearanceManager.hasData()) {
|
||||
final ActionResult actionResult = appearanceManager.updatePlayer(appearanceManager.needsASkinChange());
|
||||
final ActionResult<Void> actionResult = appearanceManager.updatePlayer(appearanceManager.needsASkinChange());
|
||||
if (!actionResult.isError()) {
|
||||
player.sendMessage(I18N.translate(player, I18NDict.Event.PreviousSkin.SUCCESS));
|
||||
} else {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package net.artelnatif.nicko.event;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
@ -10,6 +10,6 @@ public class PlayerQuitListener implements Listener {
|
|||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
NickoBukkit.getInstance().getDataStore().saveData(player);
|
||||
NickoBukkit.getInstance().getNicko().getDataStore().saveData(player);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package net.artelnatif.nicko.i18n;
|
||||
|
||||
import com.github.jsixface.YamlConfig;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
@ -15,7 +15,7 @@ public class I18N {
|
|||
private static Locale getLocale(Player player) {
|
||||
final NickoBukkit instance = NickoBukkit.getInstance();
|
||||
try {
|
||||
final Optional<NickoProfile> profile = instance.getDataStore().getData(player.getUniqueId());
|
||||
final Optional<NickoProfile> profile = instance.getNicko().getDataStore().getData(player.getUniqueId());
|
||||
return profile.isEmpty() ? Locale.FALLBACK_LOCALE : profile.get().getLocale();
|
||||
} catch (IllegalArgumentException exception) {
|
||||
instance.getLogger().severe("Invalid locale provided by " + player.getName() + ", defaulting to " + Locale.FALLBACK_LOCALE.getCode() + ".");
|
||||
|
@ -29,9 +29,9 @@ public class I18N {
|
|||
|
||||
try {
|
||||
formatter.applyPattern(translation);
|
||||
return instance.getNickoConfig().getPrefix() + formatter.format(arguments);
|
||||
return instance.getNicko().getConfig().prefix() + formatter.format(arguments);
|
||||
} catch (Exception e) {
|
||||
return instance.getNickoConfig().getPrefix() + key.key();
|
||||
return instance.getNicko().getConfig().prefix() + key.key();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ package net.artelnatif.nicko.i18n;
|
|||
|
||||
import com.github.jsixface.YamlConfig;
|
||||
import de.studiocode.invui.util.IOUtils;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package net.artelnatif.nicko.impl;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||
import net.artelnatif.nicko.disguise.ActionResult;
|
||||
import net.artelnatif.nicko.i18n.I18NDict;
|
||||
|
|
|
@ -7,7 +7,7 @@ import com.google.gson.JsonElement;
|
|||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonParser;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package net.artelnatif.nicko.placeholder;
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -48,7 +48,7 @@ public class NickoExpansion extends PlaceholderExpansion {
|
|||
locale = "N/A";
|
||||
bungeecord = true;
|
||||
|
||||
final Optional<NickoProfile> optionalProfile = instance.getDataStore().getData(player.getUniqueId());
|
||||
final Optional<NickoProfile> optionalProfile = instance.getNicko().getDataStore().getData(player.getUniqueId());
|
||||
if (optionalProfile.isPresent()) {
|
||||
final NickoProfile profile = optionalProfile.get();
|
||||
if (!profile.isEmpty()) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package net.artelnatif.nicko.placeholder;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class PlaceHolderHook {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package net.artelnatif.nicko.storage;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.Nicko;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||
import net.artelnatif.nicko.mojang.MojangUtils;
|
||||
import net.artelnatif.nicko.storage.json.JSONStorage;
|
||||
|
@ -18,8 +19,8 @@ public class PlayerDataStore {
|
|||
private final HashMap<UUID, NickoProfile> profiles = new HashMap<>();
|
||||
private final HashMap<UUID, String> names = new HashMap<>();
|
||||
|
||||
public PlayerDataStore(NickoBukkit instance) {
|
||||
this.storage = instance.getNickoConfig().isLocalStorage() ? new JSONStorage(instance) : new SQLStorage(instance);
|
||||
public PlayerDataStore(Nicko nicko) {
|
||||
this.storage = nicko.getConfig().local() ? new JSONStorage(nicko) : new SQLStorage(nicko);
|
||||
}
|
||||
|
||||
public void storeName(Player player) {
|
||||
|
|
|
@ -2,27 +2,26 @@ package net.artelnatif.nicko.storage.json;
|
|||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.Nicko;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
import net.artelnatif.nicko.disguise.ActionResult;
|
||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||
import net.artelnatif.nicko.i18n.I18NDict;
|
||||
import net.artelnatif.nicko.storage.Storage;
|
||||
import net.artelnatif.nicko.storage.StorageProvider;
|
||||
import net.artelnatif.nicko.storage.sql.SQLStorageProvider;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class JSONStorage extends Storage {
|
||||
private final NickoBukkit instance;
|
||||
private final Nicko nicko;
|
||||
private final Gson gson = new GsonBuilder().serializeNulls().setPrettyPrinting().create();
|
||||
private final File directory = new File(NickoBukkit.getInstance().getDataFolder() + "/players/");
|
||||
|
||||
private JSONStorageProvider provider;
|
||||
|
||||
final Gson gson = new GsonBuilder().serializeNulls().setPrettyPrinting().create();
|
||||
final File directory = new File(NickoBukkit.getInstance().getDataFolder() + "/players/");
|
||||
|
||||
public JSONStorage(NickoBukkit instance) { this.instance = instance; }
|
||||
public JSONStorage(Nicko nicko) { this.nicko = nicko; }
|
||||
|
||||
@Override
|
||||
public StorageProvider getProvider() {
|
||||
|
@ -44,12 +43,12 @@ public class JSONStorage extends Storage {
|
|||
writer.write(profileToJson);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
instance.getLogger().warning("Could not write to file.");
|
||||
nicko.getLogger().warning("Could not write to file.");
|
||||
return new ActionResult<>(I18NDict.Error.JSON_ERROR);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
instance.getLogger().warning("Could not create file.");
|
||||
nicko.getLogger().warning("Could not create file.");
|
||||
return new ActionResult<>(I18NDict.Error.JSON_ERROR);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package net.artelnatif.nicko.storage.sql;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.Nicko;
|
||||
import net.artelnatif.nicko.disguise.ActionResult;
|
||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||
import net.artelnatif.nicko.i18n.I18NDict;
|
||||
|
@ -15,18 +15,18 @@ import java.util.Optional;
|
|||
import java.util.UUID;
|
||||
|
||||
public class SQLStorage extends Storage {
|
||||
private final NickoBukkit instance;
|
||||
private final Nicko nicko;
|
||||
|
||||
private SQLStorageProvider provider;
|
||||
|
||||
public SQLStorage(NickoBukkit instance) {
|
||||
this.instance = instance;
|
||||
public SQLStorage(Nicko nicko) {
|
||||
this.nicko = nicko;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLStorageProvider getProvider() {
|
||||
if (provider == null) {
|
||||
provider = new SQLStorageProvider(instance);
|
||||
provider = new SQLStorageProvider(nicko);
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public class SQLStorage extends Storage {
|
|||
statement.executeUpdate();
|
||||
return new ActionResult<>();
|
||||
} catch (SQLException e) {
|
||||
instance.getLogger().warning("Couldn't send SQL Request: " + e.getMessage());
|
||||
nicko.getLogger().warning("Couldn't send SQL Request: " + e.getMessage());
|
||||
return new ActionResult<>(I18NDict.Error.SQL_ERROR);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package net.artelnatif.nicko.storage.sql;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.config.NickoConfiguration;
|
||||
import net.artelnatif.nicko.Nicko;
|
||||
import net.artelnatif.nicko.config.Configuration;
|
||||
import net.artelnatif.nicko.storage.StorageProvider;
|
||||
import org.mariadb.jdbc.MariaDbDataSource;
|
||||
|
||||
|
@ -10,37 +10,37 @@ import java.sql.PreparedStatement;
|
|||
import java.sql.SQLException;
|
||||
|
||||
public class SQLStorageProvider implements StorageProvider {
|
||||
private final NickoBukkit instance;
|
||||
private final Nicko nicko;
|
||||
private Connection connection;
|
||||
private MariaDbDataSource dataSource;
|
||||
|
||||
private final String schemaName = "nicko";
|
||||
|
||||
public SQLStorageProvider(NickoBukkit instance) {
|
||||
this.instance = instance;
|
||||
public SQLStorageProvider(Nicko nicko) {
|
||||
this.nicko = nicko;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean init() {
|
||||
try {
|
||||
final NickoConfiguration config = instance.getNickoConfig();
|
||||
final Configuration config = nicko.getConfig();
|
||||
dataSource = new MariaDbDataSource();
|
||||
dataSource.setUrl("jdbc:mariadb://" + config.getSQLAddress());
|
||||
dataSource.setUser(config.getSQLUsername());
|
||||
dataSource.setPassword(config.getSQLPassword());
|
||||
dataSource.setUrl("jdbc:mariadb://" + config.address());
|
||||
dataSource.setUser(config.username());
|
||||
dataSource.setPassword(config.password());
|
||||
connection = dataSource.getConnection();
|
||||
final boolean initialized = connection != null && !connection.isClosed();
|
||||
|
||||
if (!initialized) return false;
|
||||
|
||||
instance.getLogger().info("Creating SQL database...");
|
||||
nicko.getLogger().info("Creating SQL database...");
|
||||
createDatabase();
|
||||
|
||||
instance.getLogger().info("Creating SQL table...");
|
||||
nicko.getLogger().info("Creating SQL table...");
|
||||
createTable();
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
instance.getLogger().severe("Couldn't establish a connection to the MySQL database: " + e.getMessage());
|
||||
nicko.getLogger().severe("Couldn't establish a connection to the MySQL database: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: Nicko
|
||||
main: net.artelnatif.nicko.NickoBukkit
|
||||
main: net.artelnatif.nicko.bukkit.NickoBukkit
|
||||
version: 1.0-SNAPSHOT
|
||||
author: Aro
|
||||
api-version: 1.19
|
||||
|
|
|
@ -1,29 +1,32 @@
|
|||
package net.artelnatif.nicko.test;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import be.seeseemelk.mockbukkit.ServerMock;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.config.NickoConfiguration;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
import net.artelnatif.nicko.config.Configuration;
|
||||
import org.junit.jupiter.api.*;
|
||||
|
||||
public class NickoPluginTest {
|
||||
private static ServerMock server;
|
||||
private static NickoBukkit plugin;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
final NickoConfiguration config = new NickoConfiguration(null);
|
||||
config.setLocalStorage(true);
|
||||
config.setBungeecordSupport(false);
|
||||
server = MockBukkit.mock();
|
||||
final Configuration config = new Configuration(
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
true,
|
||||
false,
|
||||
false);
|
||||
MockBukkit.mock();
|
||||
plugin = MockBukkit.load(NickoBukkit.class, config);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Plugin Initialization")
|
||||
public void testPluginInitialization() {
|
||||
Assertions.assertNotNull(plugin.getDataStore().getStorage().getProvider());
|
||||
Assertions.assertNotNull(plugin.getNickoConfig());
|
||||
Assertions.assertNotNull(plugin.getNicko().getDataStore().getStorage().getProvider());
|
||||
Assertions.assertNotNull(plugin.getNicko().getConfig());
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
|
|
|
@ -3,8 +3,8 @@ package net.artelnatif.nicko.test.storage;
|
|||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import be.seeseemelk.mockbukkit.ServerMock;
|
||||
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.config.NickoConfiguration;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
import net.artelnatif.nicko.config.Configuration;
|
||||
import net.artelnatif.nicko.disguise.ActionResult;
|
||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||
import net.artelnatif.nicko.i18n.Locale;
|
||||
|
@ -16,13 +16,14 @@ public class BrokenSQLTest {
|
|||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
final NickoConfiguration config = new NickoConfiguration(null);
|
||||
config.setLocalStorage(false);
|
||||
config.setBungeecordSupport(false);
|
||||
config.setSQLAddress("127.0.0.1");
|
||||
config.setSQLUsername("root");
|
||||
config.setSQLPassword("INVALID_PASSWORD");
|
||||
|
||||
final Configuration config = new Configuration(
|
||||
"127.0.0.1",
|
||||
"root",
|
||||
"INVALID_PASSWORD",
|
||||
"",
|
||||
false,
|
||||
false,
|
||||
false);
|
||||
server = MockBukkit.mock();
|
||||
plugin = MockBukkit.load(NickoBukkit.class, config);
|
||||
}
|
||||
|
@ -30,7 +31,7 @@ public class BrokenSQLTest {
|
|||
@Test
|
||||
@DisplayName("Fail to create Tables")
|
||||
public void createSQLTables() {
|
||||
Assertions.assertTrue(plugin.getDataStore().getStorage().isError());
|
||||
Assertions.assertTrue(plugin.getNicko().getDataStore().getStorage().isError());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -38,7 +39,7 @@ public class BrokenSQLTest {
|
|||
public void storePlayer() {
|
||||
final PlayerMock playerMock = server.addPlayer();
|
||||
final NickoProfile profile = new NickoProfile("Notch", "Notch", Locale.ENGLISH, true);
|
||||
final ActionResult<Void> storeAction = plugin.getDataStore().getStorage().store(playerMock.getUniqueId(), profile);
|
||||
final ActionResult<Void> storeAction = plugin.getNicko().getDataStore().getStorage().store(playerMock.getUniqueId(), profile);
|
||||
Assertions.assertTrue(storeAction.isError());
|
||||
}
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@ package net.artelnatif.nicko.test.storage;
|
|||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import be.seeseemelk.mockbukkit.ServerMock;
|
||||
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.config.NickoConfiguration;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
import net.artelnatif.nicko.config.Configuration;
|
||||
import net.artelnatif.nicko.disguise.ActionResult;
|
||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||
import net.artelnatif.nicko.i18n.Locale;
|
||||
|
@ -16,13 +16,14 @@ public class SQLStorageTest {
|
|||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
final NickoConfiguration config = new NickoConfiguration(null);
|
||||
config.setLocalStorage(false);
|
||||
config.setBungeecordSupport(false);
|
||||
config.setSQLAddress("127.0.0.1");
|
||||
config.setSQLUsername("root");
|
||||
config.setSQLPassword("12345"); // https://howsecureismypassword.net/ "Your password would be cracked: Instantly"
|
||||
|
||||
final Configuration config = new Configuration(
|
||||
"127.0.0.1",
|
||||
"root",
|
||||
"12345",
|
||||
"",
|
||||
false,
|
||||
false,
|
||||
false);
|
||||
server = MockBukkit.mock();
|
||||
plugin = MockBukkit.load(NickoBukkit.class, config);
|
||||
}
|
||||
|
@ -30,7 +31,7 @@ public class SQLStorageTest {
|
|||
@Test
|
||||
@DisplayName("Create SQL Tables")
|
||||
public void createSQLTables() {
|
||||
Assertions.assertFalse(plugin.getDataStore().getStorage().isError());
|
||||
Assertions.assertFalse(plugin.getNicko().getDataStore().getStorage().isError());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -38,7 +39,7 @@ public class SQLStorageTest {
|
|||
public void storePlayer() {
|
||||
final PlayerMock playerMock = server.addPlayer();
|
||||
final NickoProfile profile = new NickoProfile("Notch", "Notch", Locale.ENGLISH, true);
|
||||
final ActionResult<Void> storeAction = plugin.getDataStore().getStorage().store(playerMock.getUniqueId(), profile);
|
||||
final ActionResult<Void> storeAction = plugin.getNicko().getDataStore().getStorage().store(playerMock.getUniqueId(), profile);
|
||||
Assertions.assertFalse(storeAction.isError());
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ package net.artelnatif.nicko.impl;
|
|||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.bukkit.NickoBukkit;
|
||||
import net.artelnatif.nicko.disguise.ActionResult;
|
||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||
import net.artelnatif.nicko.mojang.MojangSkin;
|
||||
|
|
Loading…
Reference in a new issue