From 91beb09104afaf5e954469b9ce404f94bce182cb Mon Sep 17 00:00:00 2001 From: Arasple Date: Fri, 31 Jan 2020 22:10:06 +0800 Subject: [PATCH] Reformat code --- .../mc/trhologram/TrHologramLoader.java | 11 ++-- .../mc/trhologram/TrHologramPlugin.java | 8 +-- .../api/events/HologramInteractEvent.java | 8 +-- .../mc/trhologram/hologram/Hologram.java | 64 +++++++++---------- .../trhologram/hologram/HologramContent.java | 29 ++++----- .../trhologram/hologram/HologramManager.java | 3 +- .../listeners/ListenerPlayerMove.java | 2 +- .../mc/trhologram/updater/Updater.java | 20 +++--- 8 files changed, 71 insertions(+), 74 deletions(-) diff --git a/src/main/java/me/arasple/mc/trhologram/TrHologramLoader.java b/src/main/java/me/arasple/mc/trhologram/TrHologramLoader.java index c4739fc..f4174ce 100644 --- a/src/main/java/me/arasple/mc/trhologram/TrHologramLoader.java +++ b/src/main/java/me/arasple/mc/trhologram/TrHologramLoader.java @@ -14,22 +14,21 @@ */ public class TrHologramLoader { + static void unload() { + HologramManager.write(); + TLocale.sendToConsole("PLUGIN.DISABLED"); + } + void init() { TLocale.sendToConsole("PLUGIN.LOADING"); updateConfig(); Updater.init(TrHologram.getPlugin()); } - void load() { TLocale.sendToConsole("PLUGIN.ENABLED", TrHologram.getPlugin().getDescription().getVersion()); } - static void unload() { - HologramManager.write(); - TLocale.sendToConsole("PLUGIN.DISABLED"); - } - private void updateConfig() { TConfig oldCfg = TrHologram.getSettings(); YamlConfiguration newCfg = YamlConfiguration.loadConfiguration(new InputStreamReader(TrHologram.getPlugin().getResource("settings.yml"))); diff --git a/src/main/java/me/arasple/mc/trhologram/TrHologramPlugin.java b/src/main/java/me/arasple/mc/trhologram/TrHologramPlugin.java index 2295976..8b3ff1b 100644 --- a/src/main/java/me/arasple/mc/trhologram/TrHologramPlugin.java +++ b/src/main/java/me/arasple/mc/trhologram/TrHologramPlugin.java @@ -423,14 +423,14 @@ public static TrHologramPlugin getPlugin() { return plugin; } - public File getPluginFile() { - return getFile(); - } - public static File getLibFile() { return libFile; } + public File getPluginFile() { + return getFile(); + } + @Override public final void onLoad() { if (initFailed) { diff --git a/src/main/java/me/arasple/mc/trhologram/api/events/HologramInteractEvent.java b/src/main/java/me/arasple/mc/trhologram/api/events/HologramInteractEvent.java index 02f411d..78702ad 100644 --- a/src/main/java/me/arasple/mc/trhologram/api/events/HologramInteractEvent.java +++ b/src/main/java/me/arasple/mc/trhologram/api/events/HologramInteractEvent.java @@ -21,14 +21,14 @@ public HologramInteractEvent(Player who, Hologram hologram) { this.hologram = hologram; } - public void call() { - Bukkit.getPluginManager().callEvent(this); - } - public static HandlerList getHandlerList() { return HANDLERS; } + public void call() { + Bukkit.getPluginManager().callEvent(this); + } + public Hologram getHologram() { return hologram; } diff --git a/src/main/java/me/arasple/mc/trhologram/hologram/Hologram.java b/src/main/java/me/arasple/mc/trhologram/hologram/Hologram.java index 073eea9..caa0fc2 100644 --- a/src/main/java/me/arasple/mc/trhologram/hologram/Hologram.java +++ b/src/main/java/me/arasple/mc/trhologram/hologram/Hologram.java @@ -144,6 +144,10 @@ public List getViewers() { return viewers; } + public void setViewers(List viewers) { + this.viewers = viewers; + } + private List getViewersAsPlayer() { List players = Lists.newArrayList(); viewers.forEach(viewer -> { @@ -155,10 +159,6 @@ private List getViewersAsPlayer() { return players; } - public void setViewers(List viewers) { - this.viewers = viewers; - } - public Location getLocation() { return location; } @@ -177,6 +177,30 @@ public List getContents() { return contents; } + public void setContents(List contents) { + while (contents.size() < getContents().size()) { + HologramContent hologramContent = getContents().get(getContents().size() - 1); + getViewersAsPlayer().forEach(hologramContent::destroy); + getContents().remove(getContents().size() - 1); + } + int size = getContents().size(); + for (int i = 0; i < contents.size(); i++) { + if (size > i) { + getContents().get(i).setText(contents.get(i)); + } else { + HologramContent content = new HologramContent(contents.get(i)); + getContents().add(content); + } + } + initOffsets(); + getContents().forEach(content -> { + if (!content.isArmorstandInited()) { + content.initArmorstand(); + getViewersAsPlayer().forEach(content::display); + } + }); + } + public String getViewCondition() { return viewCondition; } @@ -189,14 +213,14 @@ public String getViewDistance() { return viewDistance; } - public Object getExactViewDistance() { - return NumberUtils.isParsable(getViewDistance()) ? NumberUtils.toDouble(getViewDistance(), -1) : getViewDistance(); - } - public void setViewDistance(String viewDistance) { this.viewDistance = viewDistance; } + public Object getExactViewDistance() { + return NumberUtils.isParsable(getViewDistance()) ? NumberUtils.toDouble(getViewDistance(), -1) : getViewDistance(); + } + public double getFinalViewDistance() { return finalViewDistance; } @@ -223,28 +247,4 @@ public List getContentsAsList() { return contents; } - public void setContents(List contents) { - while (contents.size() < getContents().size()) { - HologramContent hologramContent = getContents().get(getContents().size() - 1); - getViewersAsPlayer().forEach(hologramContent::destroy); - getContents().remove(getContents().size() - 1); - } - int size = getContents().size(); - for (int i = 0; i < contents.size(); i++) { - if (size > i) { - getContents().get(i).setText(contents.get(i)); - } else { - HologramContent content = new HologramContent(contents.get(i)); - getContents().add(content); - } - } - initOffsets(); - getContents().forEach(content -> { - if (!content.isArmorstandInited()) { - content.initArmorstand(); - getViewersAsPlayer().forEach(content::display); - } - }); - } - } diff --git a/src/main/java/me/arasple/mc/trhologram/hologram/HologramContent.java b/src/main/java/me/arasple/mc/trhologram/hologram/HologramContent.java index d01b5fb..6531071 100644 --- a/src/main/java/me/arasple/mc/trhologram/hologram/HologramContent.java +++ b/src/main/java/me/arasple/mc/trhologram/hologram/HologramContent.java @@ -25,11 +25,16 @@ public HologramContent(String text) { this.text = text; } + public static List createList(List lines) { + List holoLines = Lists.newArrayList(); + lines.forEach(l -> holoLines.add(new HologramContent(l))); + return holoLines; + } + public void updateLocation(Player... players) { HoloPackets.getInst().teleportArmorstand(getArmorstand(), location, players); } - public void update(Player... players) { for (Player player : players) { HoloPackets.getInst().setArmorstandName(getArmorstand(), Vars.replace(player, text)); @@ -61,12 +66,6 @@ public void initArmorstand() { setId(HoloPackets.getInst().getEntityId(getArmorstand())); } - public static List createList(List lines) { - List holoLines = Lists.newArrayList(); - lines.forEach(l -> holoLines.add(new HologramContent(l))); - return holoLines; - } - /* GETTERS & SETTERS */ @@ -75,6 +74,10 @@ public Location getLocation() { return location; } + public void setLocation(Location location) { + this.location = location; + } + public void setLocation(Location location, List players) { this.location = location; @@ -83,10 +86,6 @@ public void setLocation(Location location, List players) { } } - public void setLocation(Location location) { - this.location = location; - } - public String getText() { return text; } @@ -102,14 +101,14 @@ public Object getArmorstand() { return armorstand; } - public boolean isArmorstandInited() { - return armorstand != null; - } - public void setArmorstand(Object armorstand) { this.armorstand = armorstand; } + public boolean isArmorstandInited() { + return armorstand != null; + } + public int getId() { return id; } diff --git a/src/main/java/me/arasple/mc/trhologram/hologram/HologramManager.java b/src/main/java/me/arasple/mc/trhologram/hologram/HologramManager.java index 408dd60..1ecd54d 100644 --- a/src/main/java/me/arasple/mc/trhologram/hologram/HologramManager.java +++ b/src/main/java/me/arasple/mc/trhologram/hologram/HologramManager.java @@ -25,6 +25,7 @@ public class HologramManager { @TInject("holograms.yml") private static TConfig hologramsData; private static List holograms = Lists.newArrayList(); + private static boolean writing; @TSchedule static void setup() { @@ -134,6 +135,4 @@ public static void write() { writing = false; } - private static boolean writing; - } diff --git a/src/main/java/me/arasple/mc/trhologram/listeners/ListenerPlayerMove.java b/src/main/java/me/arasple/mc/trhologram/listeners/ListenerPlayerMove.java index f9cbba6..19f51c8 100644 --- a/src/main/java/me/arasple/mc/trhologram/listeners/ListenerPlayerMove.java +++ b/src/main/java/me/arasple/mc/trhologram/listeners/ListenerPlayerMove.java @@ -20,7 +20,7 @@ public void onMove(PlayerMoveEvent e) { HologramManager.getHolograms().stream().forEach(hologram -> { if (hologram.isVisible(player)) { hologram.display(player); - }else { + } else { hologram.destroy(player); } }); diff --git a/src/main/java/me/arasple/mc/trhologram/updater/Updater.java b/src/main/java/me/arasple/mc/trhologram/updater/Updater.java index 8a73391..1150772 100644 --- a/src/main/java/me/arasple/mc/trhologram/updater/Updater.java +++ b/src/main/java/me/arasple/mc/trhologram/updater/Updater.java @@ -87,16 +87,6 @@ private static void grabInfo() { } } - @EventHandler - public void onJoin(PlayerJoinEvent e) { - Player p = e.getPlayer(); - - if (old && !noticed.contains(p.getUniqueId()) && p.hasPermission("trmenu.admin")) { - noticed.add(p.getUniqueId()); - Bukkit.getScheduler().runTaskLaterAsynchronously(TrHologram.getPlugin(), () -> TLocale.sendTo(p, "PLUGIN.UPDATER.OLD", newVersion), 1); - } - } - public static boolean isOld() { return old; } @@ -109,4 +99,14 @@ public static double getVersion() { return version; } + @EventHandler + public void onJoin(PlayerJoinEvent e) { + Player p = e.getPlayer(); + + if (old && !noticed.contains(p.getUniqueId()) && p.hasPermission("trmenu.admin")) { + noticed.add(p.getUniqueId()); + Bukkit.getScheduler().runTaskLaterAsynchronously(TrHologram.getPlugin(), () -> TLocale.sendTo(p, "PLUGIN.UPDATER.OLD", newVersion), 1); + } + } + }