diff --git a/lang.yml b/lang.yml new file mode 100644 index 0000000..dd4856c --- /dev/null +++ b/lang.yml @@ -0,0 +1,56 @@ +# _ _ _ +# | | /\ (_) | | +# | | __ _ __ _ / \ ___ ___ _ ___| |_ +# | | / _` |/ _` | / /\ \ / __/ __| / __| __| +# | |___| (_| | (_| |/ ____ \\__ \__ \ \__ \ |_ +# |______\__,_|\__, /_/ \_\___/___/_|___/\__| +# __/ | +# |___/ By EntryRise +# +# This is the default language configuration. You can edit any text you want. +# If you need help configuring it, please visit our dedicated Discord Server. +# DISCORD: https://discord.gg/4aWWPcb + +# What should LagAssist write in the beginning of most of the sentences? +prefix: "§2§lLag§f§lAssist §e» §f" + +errors: + chunkanalyse: + console-execution: "You cannot analyse the current chunk from console." + +debug: + ping: + #What should LagAssist debug if it receives a MOTD ping from anyone? + received: "Received ping from $1" + response: "API ping response to $1" + +chunkanalyse: + result1: + - "" + - "§2§l⬛⬛⬛⬛⬛⬛ §f§lCHUNKANALYSER §2§l⬛⬛⬛⬛⬛⬛" + - "" + - "$1" + - "" + - "⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛" + result2: + - "" + - "⬛⬛⬛⬛⬛⬛ §f§lCHUNKANALYSER ⬛⬛⬛⬛⬛⬛" + - "" + - " ✸ Chunk ($1) - Score $2" + - "" + - "§2§l⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛" + result3: + - "§2§l⬛⬛⬛⬛⬛⬛ §f§lCHUNK STATS §2§l⬛⬛⬛⬛⬛⬛" + - "" + - " §2✸ §fChunk coordonates: §7$1" + - "" + - " §2✸ §fEntity Amount: §7$2" + - " §2✸ §fTiles Amount: §7$3" + - "" + # CAUTION: Do not delete the "HOVERTEXT" text which is at the end of the sentence. The LagAssist will take care of it, "HOVERTEXT" text makes the string hoverable. + - " §2✸ §fDetailed Info §7(HOVER) HOVERTEXT" + - "" + - "§2§l⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛" + +# This allows the system to update the config if the plugin is updated. +version: 1 \ No newline at end of file diff --git a/src/com/entryrise/lagassist/Main.java b/src/com/entryrise/lagassist/Main.java index 2d0a72a..3ce54f5 100644 --- a/src/com/entryrise/lagassist/Main.java +++ b/src/com/entryrise/lagassist/Main.java @@ -1,148 +1,153 @@ -package com.entryrise.lagassist; - -import java.io.File; - -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.event.Listener; -import org.bukkit.plugin.java.JavaPlugin; - -import com.entryrise.lagassist.api.APIManager; -import com.entryrise.lagassist.chunks.ChkAnalyse; -import com.entryrise.lagassist.chunks.ChkLimiter; -import com.entryrise.lagassist.chunks.DynViewer; -import com.entryrise.lagassist.client.ClientMain; -import com.entryrise.lagassist.cmd.CommandListener; -import com.entryrise.lagassist.cmd.CommandTabListener; -import com.entryrise.lagassist.cmd.StatsAnalyse; -import com.entryrise.lagassist.economy.EconomyManager; -import com.entryrise.lagassist.gui.DataGUI; -import com.entryrise.lagassist.hoppers.HopperManager; -import com.entryrise.lagassist.logpurger.PurgerMain; -import com.entryrise.lagassist.metrics.MetricsManager; -import com.entryrise.lagassist.microfeatures.MicroManager; -import com.entryrise.lagassist.mobs.SmartMob; -import com.entryrise.lagassist.mobs.SpawnerMgr; -import com.entryrise.lagassist.packets.PacketInjector; -import com.entryrise.lagassist.packets.PacketMain; -import com.entryrise.lagassist.packets.Reflection; -import com.entryrise.lagassist.safety.SafetyManager; -import com.entryrise.lagassist.stacker.StackManager; -import com.entryrise.lagassist.updater.SmartUpdater; -import com.entryrise.lagassist.utils.Others; -import com.entryrise.lagassist.utils.VersionMgr; -import com.entryrise.lagassist.utils.WorldMgr; - -public class Main extends JavaPlugin implements Listener { - - public static String USER = "%%__USER__%%"; - - public static final String PREFIX = "§2§lLag§f§lAssist §e» §f"; - - public static JavaPlugin p; - public static boolean paper = false; - - // Debug mode means people will get verbose info. - public static int debug = 0; - - private static File file; - public static FileConfiguration config = new YamlConfiguration(); - - @Override - public void onEnable() { - p = this; - - file = new File(getDataFolder(), "server.yml"); - config = Others.getConfig(file, 32); - - paper = VersionMgr.isPaper(); - - // Start Smart updater to check for updates. - SmartUpdater.Enabler(); - - Bukkit.getLogger().info(Main.PREFIX + "Enabling Systems:"); - EnableClasses(false); - - getServer().getPluginManager().registerEvents(this, this); - getCommand("lagassist").setExecutor(new CommandListener()); - getCommand("lagassist").setTabCompleter(new CommandTabListener()); - } - - private static void EnableClasses(boolean reload) { - - EconomyManager.Enabler(reload); - - SafetyManager.Enabler(reload); - Reflection.Enabler(); - Data.Enabler(); - SmartMob.Enabler(reload); - MicroManager.Enabler(reload); - HopperManager.Enabler(reload); - StackManager.Enabler(reload); - Redstone.Enabler(reload); - Physics.Enabler(reload); - Monitor.Enabler(reload); - MonTools.Enabler(reload); - WorldMgr.Enabler(); - ChkAnalyse.Enabler(); - ChkLimiter.Enabler(reload); - StatsAnalyse.Enabler(reload); - PurgerMain.Enabler(); - - SpawnerMgr.Enabler(reload); - DynViewer.Enabler(reload); - ClientMain.Enabler(); - DataGUI.Enabler(reload); - - MetricsManager.Enabler(reload); - - PacketMain.Enabler(reload); - - // API ICON - APIManager.Enabler(reload); - } - - public static void ReloadPlugin(CommandSender s) { - config = Others.getConfig(file, 32); - - Bukkit.getLogger().info(Main.PREFIX + "Reloading Systems:"); - EnableClasses(true); - - s.sendMessage(Main.PREFIX + "Reloaded the config successfully."); - } - - @Override - public void onDisable() { - if (PacketMain.isPacketEnabled()) { - PacketInjector.Disabler(); - } - StackManager.Disabler(); - } - - public static void sendDebug(String msg, int mindebug) { - if (mindebug > debug) { - return; - } - - for (Player p : Bukkit.getOnlinePlayers()) { - if (!p.hasPermission("lagassist.debug")) { - continue; - } - - p.sendMessage(msg + "(MINDEBUG: " + mindebug + ")"); - } - - if (debug == 3) { - try { - throw new Exception(msg); - } catch (Exception e) { - e.printStackTrace(); - } - return; - } - } - -} +package com.entryrise.lagassist; + +import java.io.File; + +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; +import org.bukkit.plugin.java.JavaPlugin; + +import com.entryrise.lagassist.api.APIManager; +import com.entryrise.lagassist.chunks.ChkAnalyse; +import com.entryrise.lagassist.chunks.ChkLimiter; +import com.entryrise.lagassist.chunks.DynViewer; +import com.entryrise.lagassist.client.ClientMain; +import com.entryrise.lagassist.cmd.CommandListener; +import com.entryrise.lagassist.cmd.CommandTabListener; +import com.entryrise.lagassist.cmd.StatsAnalyse; +import com.entryrise.lagassist.economy.EconomyManager; +import com.entryrise.lagassist.gui.DataGUI; +import com.entryrise.lagassist.hoppers.HopperManager; +import com.entryrise.lagassist.logpurger.PurgerMain; +import com.entryrise.lagassist.metrics.MetricsManager; +import com.entryrise.lagassist.microfeatures.MicroManager; +import com.entryrise.lagassist.mobs.SmartMob; +import com.entryrise.lagassist.mobs.SpawnerMgr; +import com.entryrise.lagassist.packets.PacketInjector; +import com.entryrise.lagassist.packets.PacketMain; +import com.entryrise.lagassist.packets.Reflection; +import com.entryrise.lagassist.safety.SafetyManager; +import com.entryrise.lagassist.stacker.StackManager; +import com.entryrise.lagassist.updater.SmartUpdater; +import com.entryrise.lagassist.utils.Others; +import com.entryrise.lagassist.utils.VersionMgr; +import com.entryrise.lagassist.utils.WorldMgr; + +public class Main extends JavaPlugin implements Listener { + + public static String USER = "%%__USER__%%"; + + public static JavaPlugin p; + public static boolean paper = false; + + // Debug mode means people will get verbose info. + public static int debug = 0; + + private static File file; + public static FileConfiguration config = new YamlConfiguration(); + + private static File langfile = new File(getDataFolder(), "lang.yml"); + public static YamlConfiguration lang = new YamlConfiguration(); + + public static final String PREFIX = "§2§lLag§f§lAssist §e» §f"; + + @Override + public void onEnable() { + p = this; + + file = new File(getDataFolder(), "server.yml"); + + config = Others.getConfig(file, 32); + lang = Others.getConfig(langfile, 1); + + paper = VersionMgr.isPaper(); + + // Start Smart updater to check for updates. + SmartUpdater.Enabler(); + + Bukkit.getLogger().info(Main.PREFIX + "Enabling Systems:"); + EnableClasses(false); + + getServer().getPluginManager().registerEvents(this, this); + getCommand("lagassist").setExecutor(new CommandListener()); + getCommand("lagassist").setTabCompleter(new CommandTabListener()); + } + + private static void EnableClasses(boolean reload) { + + EconomyManager.Enabler(reload); + + SafetyManager.Enabler(reload); + Reflection.Enabler(); + Data.Enabler(); + SmartMob.Enabler(reload); + MicroManager.Enabler(reload); + HopperManager.Enabler(reload); + StackManager.Enabler(reload); + Redstone.Enabler(reload); + Physics.Enabler(reload); + Monitor.Enabler(reload); + MonTools.Enabler(reload); + WorldMgr.Enabler(); + ChkAnalyse.Enabler(); + ChkLimiter.Enabler(reload); + StatsAnalyse.Enabler(reload); + PurgerMain.Enabler(); + + SpawnerMgr.Enabler(reload); + DynViewer.Enabler(reload); + ClientMain.Enabler(); + DataGUI.Enabler(reload); + + MetricsManager.Enabler(reload); + + PacketMain.Enabler(reload); + + // API ICON + APIManager.Enabler(reload); + } + + public static void ReloadPlugin(CommandSender s) { + config = Others.getConfig(file, 32); + + Bukkit.getLogger().info(Main.PREFIX + "Reloading Systems:"); + EnableClasses(true); + + s.sendMessage(Main.PREFIX + "Reloaded the config successfully."); + } + + @Override + public void onDisable() { + if (PacketMain.isPacketEnabled()) { + PacketInjector.Disabler(); + } + StackManager.Disabler(); + } + + public static void sendDebug(String msg, int mindebug) { + if (mindebug > debug) { + return; + } + + for (Player p : Bukkit.getOnlinePlayers()) { + if (!p.hasPermission("lagassist.debug")) { + continue; + } + + p.sendMessage(msg + "(MINDEBUG: " + mindebug + ")"); + } + + if (debug == 3) { + try { + throw new Exception(msg); + } catch (Exception e) { + e.printStackTrace(); + } + return; + } + } + +} diff --git a/src/com/entryrise/lagassist/api/MotdAPI.java b/src/com/entryrise/lagassist/api/MotdAPI.java index 4d7c89e..cb8a42b 100644 --- a/src/com/entryrise/lagassist/api/MotdAPI.java +++ b/src/com/entryrise/lagassist/api/MotdAPI.java @@ -24,7 +24,7 @@ public class MotdAPI implements Listener { String saddr = addr.getHostAddress(); - Main.sendDebug("Received ping from " + saddr, 1); + Main.sendDebug(Main.lang.getString("debug.ping.received").replace("$1", saddr), 1); boolean found = false; @@ -41,7 +41,7 @@ public class MotdAPI implements Listener { return; } - Main.sendDebug("API ping response to " + saddr, 1); + Main.sendDebug(Main.lang.getString("debug.ping.response").replace("$1", saddr), 1); try { e.setServerIcon(generateIcon()); diff --git a/src/com/entryrise/lagassist/chunks/ChkAnalyse.java b/src/com/entryrise/lagassist/chunks/ChkAnalyse.java index 90d2f54..e96500b 100644 --- a/src/com/entryrise/lagassist/chunks/ChkAnalyse.java +++ b/src/com/entryrise/lagassist/chunks/ChkAnalyse.java @@ -1,145 +1,135 @@ -package com.entryrise.lagassist.chunks; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.bukkit.Bukkit; -import org.bukkit.Chunk; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.block.BlockState; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; - -import com.entryrise.lagassist.Main; - -public class ChkAnalyse { - - protected static int ammoshow = Main.config.getInt("chunkanalyse.ammount"); - protected static Map values = new HashMap(); - private static List scores = new ArrayList(); - - public static void Enabler() { - Bukkit.getLogger().info(" §e[§a✔§e] §fChunk Analyser."); - - Set slist = Main.config.getConfigurationSection("chunkanalyse.values").getKeys(false); - - for (String s : slist) { - int value = Main.config.getInt("chunkanalyse.values." + s); - values.put(s.toLowerCase(), value); - } - } - - public static void analyseChunks(Player p) { - scores.clear(); - for (World w : Bukkit.getWorlds()) { - for (Chunk ch : w.getLoadedChunks()) { - scores.add(new ChkStats(ch, false)); - } - } - Bukkit.getScheduler().runTaskAsynchronously(Main.p, new Runnable() { - @Override - public void run() { - - for (ChkStats ch : scores) { - ch.genScores(); - } - Collections.sort(scores); - p.sendMessage(""); - p.sendMessage("§2§l⬛⬛⬛⬛⬛⬛ §f§lCHUNKANALYSER §2§l⬛⬛⬛⬛⬛⬛"); - p.sendMessage(""); - - for (int i = 0; i < ammoshow; i++) { - ChkStats cs = scores.get(i); - p.spigot().sendMessage(cs.genText()); - } - - p.sendMessage(""); - p.sendMessage("§2§l⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛"); - } - }); - - } - - public static void analyseChunks(CommandSender p) { - Map chunkscore = new HashMap(); - for (World w : Bukkit.getWorlds()) { - for (Chunk ch : w.getLoadedChunks()) { - if (!chunkscore.containsKey(ch)) { - chunkscore.put(ch, 0); - } - BlockState[] tiles = ch.getTileEntities(); - for (BlockState blkst : tiles) { - String m = blkst.getType().toString().toLowerCase(); - if (values.containsKey(m)) { - chunkscore.put(ch, chunkscore.get(ch) + values.get(m)); - } - } - Entity[] ents = ch.getEntities(); - for (Entity e : ents) { - String et = e.getType().toString().toLowerCase(); - if (values.containsKey(et)) { - chunkscore.put(ch, chunkscore.get(ch) + values.get(et)); - } - } - - } - } - p.sendMessage(""); - p.sendMessage("⬛⬛⬛⬛⬛⬛ §f§lCHUNKANALYSER ⬛⬛⬛⬛⬛⬛"); - p.sendMessage(""); - - Stream> sorted = chunkscore.entrySet().stream() - .sorted(Collections.reverseOrder(Map.Entry.comparingByValue())); - - Map topTen = sorted.limit(ammoshow) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); - - for (Chunk ch : topTen.keySet()) { - int score = chunkscore.get(ch); - p.sendMessage(" ✸ Chunk (" + String.valueOf(ch.getX()) + " " + String.valueOf(ch.getZ()) + ") - Score " - + String.valueOf(score)); - } - p.sendMessage(""); - p.sendMessage("⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛"); - - } - - public static void analyseCurrentChunk(CommandSender s) { - if (!(s instanceof Player)) { - s.sendMessage(Main.PREFIX + "You cannot analyse the current chunk from console."); - return; - } - Player p = (Player) s; - Location l = p.getLocation(); - ChkStats stats = new ChkStats(l.getChunk(), true); - - int coords[] = stats.getCoords(); - - String crds = String.valueOf(coords[0]) + " " + String.valueOf(coords[1]); - - String cmd = "lagassist tpchunk " + p.getWorld().getName() + " " + String.valueOf(coords[0]) + " " - + String.valueOf(coords[1]); - - p.sendMessage("§2§l⬛⬛⬛⬛⬛⬛ §f§lCHUNK STATS §2§l⬛⬛⬛⬛⬛⬛"); - p.sendMessage(""); - p.sendMessage(" §2✸ §fChunk coordonates: §7" + crds); - p.sendMessage(""); - p.sendMessage(" §2✸ §fEntity Amount: §7" + stats.getEnts().length); - p.sendMessage(" §2✸ §fTiles Amount: §7" + stats.getTiles().length); - p.sendMessage(""); - p.spigot().sendMessage(stats.genMobCount(" §2✸ §fDetailed Info §7(HOVER)", cmd)); - p.sendMessage(""); - p.sendMessage("§2§l⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛"); - - } - -} +package com.entryrise.lagassist.chunks; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.bukkit.Bukkit; +import org.bukkit.Chunk; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.BlockState; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +import com.entryrise.lagassist.Main; + +public class ChkAnalyse { + + protected static int ammoshow = Main.config.getInt("chunkanalyse.amount"); + protected static Map values = new HashMap(); + private static List scores = new ArrayList(); + + public static void Enabler() { + Bukkit.getLogger().info(" §e[§a✔§e] §fChunk Analyser."); + + Set slist = Main.config.getConfigurationSection("chunkanalyse.values").getKeys(false); + + for (String s : slist) { + int value = Main.config.getInt("chunkanalyse.values." + s); + values.put(s.toLowerCase(), value); + } + } + + public static void analyseChunks(Player p) { + scores.clear(); + for (World w : Bukkit.getWorlds()) { + for (Chunk ch : w.getLoadedChunks()) { + scores.add(new ChkStats(ch, false)); + } + } + Bukkit.getScheduler().runTaskAsynchronously(Main.p, new Runnable() { + @Override + public void run() { + + for (ChkStats ch : scores) { + ch.genScores(); + } + Collections.sort(scores); + + for (int i = 0; i < ammoshow; i++) { + ChkStats cs = scores.get(i); + for (String str : Main.lang.getStringList("chunkanalyse.result1")) { + if (str.contains("$1")) { + p.spigot().sendMessage(cs.genText()) + } else { + p.sendMessage(str.replace("$1", cs.genText())) + } + } + } + } + }); + + } + + public static void analyseChunks(CommandSender p) { + Map chunkscore = new HashMap(); + for (World w : Bukkit.getWorlds()) { + for (Chunk ch : w.getLoadedChunks()) { + if (!chunkscore.containsKey(ch)) { + chunkscore.put(ch, 0); + } + BlockState[] tiles = ch.getTileEntities(); + for (BlockState blkst : tiles) { + String m = blkst.getType().toString().toLowerCase(); + if (values.containsKey(m)) { + chunkscore.put(ch, chunkscore.get(ch) + values.get(m)); + } + } + Entity[] ents = ch.getEntities(); + for (Entity e : ents) { + String et = e.getType().toString().toLowerCase(); + if (values.containsKey(et)) { + chunkscore.put(ch, chunkscore.get(ch) + values.get(et)); + } + } + + } + } + Stream> sorted = chunkscore.entrySet().stream() + .sorted(Collections.reverseOrder(Map.Entry.comparingByValue())); + + Map topTen = sorted.limit(ammoshow) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); + + for (Chunk ch : topTen.keySet()) { + int score = chunkscore.get(ch); + for (String str : Main.lang.getStringList("chunkanalyse.result2")) { + p.sendMessage(str.replace("$1", String.valueOf(ch.getX()) + " " + String.valueOf(ch.getZ())).replace("$2", String.valueOf(score))) + } + } + } + + public static void analyseCurrentChunk(CommandSender s) { + if (!(s instanceof Player)) { + s.sendMessage(Main.PREFIX + Main.lang.getString("errors.chunkanalyse.console-execution")); + return; + } + Player p = (Player) s; + Location l = p.getLocation(); + ChkStats stats = new ChkStats(l.getChunk(), true); + + int coords[] = stats.getCoords(); + + String crds = String.valueOf(coords[0]) + " " + String.valueOf(coords[1]); + + String cmd = "lagassist tpchunk " + p.getWorld().getName() + " " + String.valueOf(coords[0]) + " " + + String.valueOf(coords[1]); + + for (String str : Main.lang.getStringList("chunkanalyse.result3")) { + if (str.endsWith("HOVERTEXT")) { + p.spigot().sendMessage(stats.genMobCount(str, cmd).replaceAll("HOVERTEXT", "")) + } else { + p.sendMessage(str.replace("$1", crds).replace("$2", stats.getEnts().length).replace("$3", stats.getTiles().length)) + } + } + } + +}