From 06dcafc47c435e91d955bd63da04d16576606392 Mon Sep 17 00:00:00 2001 From: Brianna Date: Sat, 27 Apr 2019 18:24:16 -0400 Subject: [PATCH] Added HolographicDisplays. Removed Arconix. Added Songoda Updater. --- pom.xml | 37 +++++++++++- .../songoda/ultimatekits/UltimateKits.java | 49 ++++------------ .../ultimatekits/gui/GUIBlockEditor.java | 4 ++ .../ultimatekits/gui/GUIDisplayKit.java | 1 - .../handlers/DisplayItemHandler.java | 7 +-- .../hologram/HologramArconix.java | 47 ---------------- .../hologram/HologramHolographicDisplays.java | 56 +++++++++++++++++++ .../songoda/ultimatekits/kit/KitManager.java | 5 +- .../listeners/BlockListeners.java | 4 +- .../ultimatekits/utils/SettingsManager.java | 1 - .../utils/updateModules/LocaleModule.java | 32 +++++++++++ src/main/resources/plugin.yml | 2 +- 12 files changed, 148 insertions(+), 97 deletions(-) delete mode 100644 src/main/java/com/songoda/ultimatekits/hologram/HologramArconix.java create mode 100644 src/main/java/com/songoda/ultimatekits/hologram/HologramHolographicDisplays.java create mode 100644 src/main/java/com/songoda/ultimatekits/utils/updateModules/LocaleModule.java diff --git a/pom.xml b/pom.xml index 0b2ef36..f163958 100644 --- a/pom.xml +++ b/pom.xml @@ -38,6 +38,39 @@ + + 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 + + + + + + + @@ -54,8 +87,8 @@ com.songoda - arconix - 2.0.0 + songodaupdater + 1 org diff --git a/src/main/java/com/songoda/ultimatekits/UltimateKits.java b/src/main/java/com/songoda/ultimatekits/UltimateKits.java index 337d658..587c78f 100644 --- a/src/main/java/com/songoda/ultimatekits/UltimateKits.java +++ b/src/main/java/com/songoda/ultimatekits/UltimateKits.java @@ -2,15 +2,18 @@ package com.songoda.ultimatekits; import com.songoda.ultimatekits.command.CommandManager; import com.songoda.ultimatekits.conversion.Convert; +import com.songoda.ultimatekits.hologram.HologramHolographicDisplays; import com.songoda.ultimatekits.listeners.*; import com.songoda.ultimatekits.handlers.DisplayItemHandler; import com.songoda.ultimatekits.handlers.ParticleHandler; import com.songoda.ultimatekits.hologram.Hologram; -import com.songoda.ultimatekits.hologram.HologramArconix; import com.songoda.ultimatekits.key.Key; import com.songoda.ultimatekits.key.KeyManager; import com.songoda.ultimatekits.kit.*; import com.songoda.ultimatekits.utils.*; +import com.songoda.ultimatekits.utils.updateModules.LocaleModule; +import com.songoda.update.Plugin; +import com.songoda.update.SongodaUpdate; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; @@ -112,9 +115,10 @@ public class UltimateKits extends JavaPlugin { Locale.saveDefaultLocale("en_US"); this.locale = Locale.getLocale(getConfig().getString("System.Language Mode", langMode)); - if (getConfig().getBoolean("System.Download Needed Data Files")) { - this.update(); - } + //Running Songoda Updater + Plugin plugin = new Plugin(this, 14); + plugin.addModule(new LocaleModule()); + SongodaUpdate.load(plugin); this.references = new References(); @@ -125,8 +129,8 @@ public class UltimateKits extends JavaPlugin { PluginManager pluginManager = getServer().getPluginManager(); // Register Hologram Plugin - if (pluginManager.isPluginEnabled("Arconix")) - hologram = new HologramArconix(this); + if (pluginManager.isPluginEnabled("HolographicDisplays")) + hologram = new HologramHolographicDisplays(this); // Event registration pluginManager.registerEvents(new BlockListeners(this), this); @@ -157,39 +161,6 @@ public class UltimateKits extends JavaPlugin { console.sendMessage(Methods.formatText("&a=============================")); } - 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]; - StringBuffer sb = new StringBuffer(); - 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; - - switch ((String) file.get("type")) { - case "locale": - InputStream in = new URL((String) file.get("link")).openStream(); - Locale.saveDefaultLocale(in, (String) file.get("name")); - break; - } - } - } catch (Exception e) { - System.out.println("Failed to update."); - //e.printStackTrace(); - } - } - /* * Load configuration files into memory. */ diff --git a/src/main/java/com/songoda/ultimatekits/gui/GUIBlockEditor.java b/src/main/java/com/songoda/ultimatekits/gui/GUIBlockEditor.java index f39e020..9bd9a08 100644 --- a/src/main/java/com/songoda/ultimatekits/gui/GUIBlockEditor.java +++ b/src/main/java/com/songoda/ultimatekits/gui/GUIBlockEditor.java @@ -82,11 +82,15 @@ public class GUIBlockEditor extends AbstractGUI { registerClickable(11, (player, inventory, cursor, slot, type) -> { UltimateKits instance = UltimateKits.getInstance(); + if (instance.getHologram() != null) + instance.getHologram().remove(kitBlockData); + if (kitBlockData.getType() == KitType.PREVIEW) kitBlockData.setType(KitType.CRATE); else if (kitBlockData.getType() == KitType.CRATE) kitBlockData.setType(KitType.CLAIM); else if (kitBlockData.getType() == KitType.CLAIM) kitBlockData.setType(KitType.PREVIEW); instance.saveConfig(); + if (instance.getHologram() != null) instance.getHologram().update(kitBlockData); constructGUI(); }); diff --git a/src/main/java/com/songoda/ultimatekits/gui/GUIDisplayKit.java b/src/main/java/com/songoda/ultimatekits/gui/GUIDisplayKit.java index 36e3969..3c84652 100644 --- a/src/main/java/com/songoda/ultimatekits/gui/GUIDisplayKit.java +++ b/src/main/java/com/songoda/ultimatekits/gui/GUIDisplayKit.java @@ -155,7 +155,6 @@ public class GUIDisplayKit extends AbstractGUI { if (num == 17 || num == (max - 18)) num++; if (num == 18 && max == 36) num++; } - System.out.println("hit " + num); ItemMeta meta = is.hasItemMeta() ? is.getItemMeta() : Bukkit.getItemFactory().getItemMeta(is.getType()); ArrayDeque lore; diff --git a/src/main/java/com/songoda/ultimatekits/handlers/DisplayItemHandler.java b/src/main/java/com/songoda/ultimatekits/handlers/DisplayItemHandler.java index daa0550..2eb5d46 100644 --- a/src/main/java/com/songoda/ultimatekits/handlers/DisplayItemHandler.java +++ b/src/main/java/com/songoda/ultimatekits/handlers/DisplayItemHandler.java @@ -55,10 +55,9 @@ public class DisplayItemHandler { continue; } Item i = (Item) e; - if (i.getItemStack().getItemMeta().getDisplayName() == null) { - i.remove(); - return; - } + + if (!kitBlockData.isDisplayingItems()) e.remove(); + int inum = Integer.parseInt(i.getItemStack().getItemMeta().getDisplayName().replace(String.valueOf(ChatColor.COLOR_CHAR), "")) + 1; if (inum > list.size()) inum = 1; diff --git a/src/main/java/com/songoda/ultimatekits/hologram/HologramArconix.java b/src/main/java/com/songoda/ultimatekits/hologram/HologramArconix.java deleted file mode 100644 index 3f95984..0000000 --- a/src/main/java/com/songoda/ultimatekits/hologram/HologramArconix.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.songoda.ultimatekits.hologram; - -import com.songoda.arconix.api.hologram.HologramObject; -import com.songoda.arconix.plugin.Arconix; -import com.songoda.ultimatekits.UltimateKits; -import org.bukkit.Bukkit; -import org.bukkit.Location; - -import java.util.ArrayList; - -public class HologramArconix extends Hologram { - - private com.songoda.arconix.api.packets.Hologram hologramManager; - - public HologramArconix(UltimateKits instance) { - super(instance); - this.hologramManager = Arconix.pl().getApi().packetLibrary.getHologramManager(); - } - - @Override - public void add(Location location, ArrayList lines) { - fixLocation(location); - HologramObject hologram = new HologramObject(null, location, lines); - hologramManager.addHologram(hologram); - } - - @Override - public void remove(Location location) { - fixLocation(location); - location.add(0, 0.25, 0); - hologramManager.removeHologram(location, 5); - } - - @Override - public void update(Location location, ArrayList lines) { - remove(location.clone()); - fixLocation(location); - HologramObject hologram = new HologramObject(null, location, lines); - Bukkit.getScheduler().scheduleSyncDelayedTask(UltimateKits.getInstance(), () -> { - hologramManager.addHologram(hologram); - }, 1L); - } - - private void fixLocation(Location location) { - location.add(0.5, 0.75, 0.5); - } -} diff --git a/src/main/java/com/songoda/ultimatekits/hologram/HologramHolographicDisplays.java b/src/main/java/com/songoda/ultimatekits/hologram/HologramHolographicDisplays.java new file mode 100644 index 0000000..0bd51f2 --- /dev/null +++ b/src/main/java/com/songoda/ultimatekits/hologram/HologramHolographicDisplays.java @@ -0,0 +1,56 @@ +package com.songoda.ultimatekits.hologram; + +import com.gmail.filoghost.holographicdisplays.api.HologramsAPI; +import com.songoda.ultimatekits.UltimateKits; +import org.bukkit.Location; + +import java.util.ArrayList; + +public class HologramHolographicDisplays extends Hologram { + + + public HologramHolographicDisplays(UltimateKits instance) { + super(instance); + } + + @Override + public void add(Location location, ArrayList lines) { + fixLocation(location); + + com.gmail.filoghost.holographicdisplays.api.Hologram hologram = HologramsAPI.createHologram(instance, location); + for (String line : lines) { + hologram.appendTextLine(line); + } + } + + @Override + public void remove(Location location) { + fixLocation(location); + for (com.gmail.filoghost.holographicdisplays.api.Hologram hologram : HologramsAPI.getHolograms(instance)) { + if (hologram.getX() != location.getX() + || hologram.getY() != location.getY() + || hologram.getZ() != location.getZ()) continue; + hologram.delete(); + } + } + + @Override + public void update(Location location, ArrayList lines) { + for (com.gmail.filoghost.holographicdisplays.api.Hologram hologram : HologramsAPI.getHolograms(instance)) { + if (hologram.getX() != location.getX() + || hologram.getY() != location.getY() + || hologram.getZ() != location.getZ()) continue; + fixLocation(location); + hologram.clearLines(); + for (String line : lines) { + hologram.appendTextLine(line); + } + return; + } + add(location, lines); + } + + private void fixLocation(Location location) { + location.add(.5, 1.3, .5); + } +} diff --git a/src/main/java/com/songoda/ultimatekits/kit/KitManager.java b/src/main/java/com/songoda/ultimatekits/kit/KitManager.java index c06ac48..25dbb59 100644 --- a/src/main/java/com/songoda/ultimatekits/kit/KitManager.java +++ b/src/main/java/com/songoda/ultimatekits/kit/KitManager.java @@ -1,5 +1,6 @@ package com.songoda.ultimatekits.kit; +import com.songoda.ultimatekits.UltimateKits; import org.bukkit.Location; import java.util.*; @@ -33,7 +34,9 @@ public final class KitManager { } public void addKitToLocation(Kit kit, Location location, KitType type, boolean hologram, boolean particles, boolean items, boolean itemOverride) { - kitsAtLocations.put(roundLocation(location), new KitBlockData(kit, location, type, hologram, particles, items, itemOverride)); + KitBlockData kitBlockData = kitsAtLocations.put(roundLocation(location), new KitBlockData(kit, location, type, hologram, particles, items, itemOverride)); + if (UltimateKits.getInstance().getHologram() != null) + UltimateKits.getInstance().getHologram().update(kitBlockData); } public Kit removeKitFromLocation(Location location) { diff --git a/src/main/java/com/songoda/ultimatekits/listeners/BlockListeners.java b/src/main/java/com/songoda/ultimatekits/listeners/BlockListeners.java index 1f878fe..24ec30c 100644 --- a/src/main/java/com/songoda/ultimatekits/listeners/BlockListeners.java +++ b/src/main/java/com/songoda/ultimatekits/listeners/BlockListeners.java @@ -30,10 +30,12 @@ public class BlockListeners implements Listener { KitBlockData kitBlockData = instance.getKitManager().getKit(block.getLocation()); if (kitBlockData == null) return; Kit kit = kitBlockData.getKit(); - instance.getKitManager().removeKitFromLocation(block.getLocation()); if (instance.getHologram() != null) instance.getHologram().remove(kitBlockData); + + instance.getKitManager().removeKitFromLocation(block.getLocation()); + event.getPlayer().sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&8Kit &9" + kit.getName() + " &8unassigned from: &a" + block.getType() + "&8.")); } catch (Exception e) { diff --git a/src/main/java/com/songoda/ultimatekits/utils/SettingsManager.java b/src/main/java/com/songoda/ultimatekits/utils/SettingsManager.java index d1bf5c7..33e673d 100644 --- a/src/main/java/com/songoda/ultimatekits/utils/SettingsManager.java +++ b/src/main/java/com/songoda/ultimatekits/utils/SettingsManager.java @@ -234,7 +234,6 @@ public class SettingsManager implements Listener { o14("Rainbow-Glass", "Interfaces.Replace Glass Type 1 With Rainbow Glass", false), o15("glassless", "Interfaces.Do Not Use Glass Borders", false), - DOWNLOAD_FILES("-", "System.Download Needed Data Files", true), LANGUGE_MODE("-", "System.Language Mode", "en_US"), o16("Debug-Mode", "System.Debugger Enabled", false); diff --git a/src/main/java/com/songoda/ultimatekits/utils/updateModules/LocaleModule.java b/src/main/java/com/songoda/ultimatekits/utils/updateModules/LocaleModule.java new file mode 100644 index 0000000..c182865 --- /dev/null +++ b/src/main/java/com/songoda/ultimatekits/utils/updateModules/LocaleModule.java @@ -0,0 +1,32 @@ +package com.songoda.ultimatekits.utils.updateModules; + +import com.songoda.ultimatekits.UltimateKits; +import com.songoda.update.Module; +import com.songoda.update.Plugin; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +public class LocaleModule implements Module { + + @Override + public void run(Plugin plugin) { + JSONObject json = plugin.getJson(); + try { + JSONArray files = (JSONArray) json.get("neededFiles"); + for (Object o : files) { + JSONObject file = (JSONObject) o; + + if (file.get("type").equals("locale")) { + InputStream in = new URL((String) file.get("link")).openStream(); + UltimateKits.getInstance().getLocale().saveDefaultLocale(in, (String) file.get("name")); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 970dfc9..665f9ba 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: UltimateKits main: com.songoda.ultimatekits.UltimateKits version: maven-version-number -softdepend: [Arconix, PlaceholderAPI, Vault, UltimateCore, Essentials, MiniKitPvP] +softdepend: [HolographicDisplays, PlaceholderAPI, Vault, UltimateCore, Essentials, MiniKitPvP] description: View a kit before you purchase it! author: Songoda api-version: 1.13