From 76bddee9792029ae429e84aba723b5188f069435 Mon Sep 17 00:00:00 2001 From: Stefatorus Date: Fri, 10 Sep 2021 22:08:37 +0300 Subject: [PATCH] Preparation for advert manager & solve client-side optimizer for 1.17 --- plugin.yml | 2 +- server.yml | 6 +- src/cx/sfy/LagAssist/Data.java | 12 +++ src/cx/sfy/LagAssist/chunks/ChkLimiter.java | 4 + src/cx/sfy/LagAssist/client/ClientPacket.java | 5 +- src/cx/sfy/LagAssist/cmd/CommandListener.java | 3 + .../LagAssist/microfeatures/AdvertRunner.java | 75 +++++++++++++++++++ src/cx/sfy/LagAssist/mobs/SmartMob.java | 9 ++- src/cx/sfy/LagAssist/utils/Chat.java | 7 ++ 9 files changed, 116 insertions(+), 7 deletions(-) create mode 100644 src/cx/sfy/LagAssist/microfeatures/AdvertRunner.java diff --git a/plugin.yml b/plugin.yml index a87406f..e08d2eb 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: LagAssist author: Stefatorus -version: 2.24.0 +version: 2.24.2 api-version: 1.13 description: LagAssist is an advanced anti-lag solution that allows server owners find and remove lag using multiple advanced and efficient methods. main: cx.sfy.LagAssist.Main diff --git a/server.yml b/server.yml index 71375b6..c9879d3 100644 --- a/server.yml +++ b/server.yml @@ -78,7 +78,7 @@ smart-stacker: tag-visibility: true # Size is required if you want stacking to work. tag-format: "&f{type} &cx{size}" - # What entity types don't you want to be stackable. + # What entity types you want to be stackable. stackable: # - "SKELETON" # - "ZOMBIE" @@ -484,6 +484,8 @@ limiter: # The amount of time between chunk cleans. Setting it to a small amount can make your server have more lag, while a larger amount may mean slower # responses timer-time: 1200 + # Should the limiter ignore named mobs? + ignore-named-mobs: false mobs: # The maximum limit of mobs that can spawn per chunk. Set this to a larger number, and use # the per-limit system to set limits for certain types of mobs. @@ -762,4 +764,4 @@ hooks: # What message should show up to players that get paid. %amount% for paid amount. message: "&c&lLag&f&lAssist &e» &fYou were paid %amount% in the paywave." # This allows the system to update the config if the plugin is updated. -version: 29 \ No newline at end of file +version: 30 \ No newline at end of file diff --git a/src/cx/sfy/LagAssist/Data.java b/src/cx/sfy/LagAssist/Data.java index 6fac2b8..5ce5461 100644 --- a/src/cx/sfy/LagAssist/Data.java +++ b/src/cx/sfy/LagAssist/Data.java @@ -13,6 +13,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.OfflinePlayer; import org.bukkit.block.Hopper; +import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; @@ -198,4 +199,15 @@ public class Data { saveData(); } + + public static void toggleAdvertising(CommandSender sender) { + boolean advertising = !data.getBoolean("disable-advertising", false); + data.set("disable-advertising", advertising); + sender.sendMessage(Main.PREFIX + "Advertising disabled: " + advertising); + saveData(); + } + + public static boolean isAdvertising() { + return !data.getBoolean("disable-advertising"); + } } diff --git a/src/cx/sfy/LagAssist/chunks/ChkLimiter.java b/src/cx/sfy/LagAssist/chunks/ChkLimiter.java index 903e044..42910b4 100644 --- a/src/cx/sfy/LagAssist/chunks/ChkLimiter.java +++ b/src/cx/sfy/LagAssist/chunks/ChkLimiter.java @@ -161,6 +161,10 @@ public class ChkLimiter implements Listener { // VERIFIERS (CODE QUALITY IMPROVERS) private static boolean isDeniedMob(Entity ent) { + if (Main.config.getBoolean("limiter.ignore-named-mobs") && ent.getCustomName() != null) { + return false; + } + EntityType etype = ent.getType(); // Fix issues with destroying player objects. diff --git a/src/cx/sfy/LagAssist/client/ClientPacket.java b/src/cx/sfy/LagAssist/client/ClientPacket.java index b96f5d9..9c95551 100644 --- a/src/cx/sfy/LagAssist/client/ClientPacket.java +++ b/src/cx/sfy/LagAssist/client/ClientPacket.java @@ -37,7 +37,10 @@ public class ClientPacket { int z = ((int) Reflection.getFieldValue(msg, "d")) / 32; Location loc = new Location(p.getWorld(), x, y, z); ent = Reflection.getEntity(loc); - } else if (VersionMgr.isNewMaterials()) { + } else if (VersionMgr.isV1_17()) { + UUID u = (UUID) Reflection.getFieldValue(msg, "d"); + ent = Bukkit.getEntity(u); + } if (VersionMgr.isNewMaterials()) { UUID u = (UUID) Reflection.getFieldValue(msg, "b"); ent = Bukkit.getEntity(u); } else { diff --git a/src/cx/sfy/LagAssist/cmd/CommandListener.java b/src/cx/sfy/LagAssist/cmd/CommandListener.java index 4893fd6..b60ef73 100644 --- a/src/cx/sfy/LagAssist/cmd/CommandListener.java +++ b/src/cx/sfy/LagAssist/cmd/CommandListener.java @@ -12,6 +12,7 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import cx.sfy.LagAssist.Data; import cx.sfy.LagAssist.Main; import cx.sfy.LagAssist.MonTools; import cx.sfy.LagAssist.MsrExec; @@ -99,6 +100,8 @@ public class CommandListener implements CommandExecutor { } else if (arg.equalsIgnoreCase("debugmode")) { Main.debug = Main.debug >= 3 ? 0 : Main.debug+1; sender.sendMessage(Main.PREFIX + "Debug setting currently at: " + Main.debug); + } else if (arg.equalsIgnoreCase("advertising")) { + Data.toggleAdvertising(sender); } else { sendHelp(sender); } diff --git a/src/cx/sfy/LagAssist/microfeatures/AdvertRunner.java b/src/cx/sfy/LagAssist/microfeatures/AdvertRunner.java new file mode 100644 index 0000000..df54674 --- /dev/null +++ b/src/cx/sfy/LagAssist/microfeatures/AdvertRunner.java @@ -0,0 +1,75 @@ +package cx.sfy.LagAssist.microfeatures; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.plugin.messaging.PluginMessageListener; + +import cx.sfy.LagAssist.Data; +import cx.sfy.LagAssist.Main; +import cx.sfy.LagAssist.utils.Chat; +import net.minecraft.server.v1_12_R1.AdvancementProgress.a; + +public class AdvertRunner implements Listener, PluginMessageListener { + + public AdvertRunner() { + Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(Main.p, "BungeeCord"); + Bukkit.getServer().getMessenger().registerIncomingPluginChannel(Main.p, "BungeeCord", this); + } + + @EventHandler + public void onJoin(PlayerJoinEvent e) { + Player p = e.getPlayer(); + + if (!Data.isAdvertising()) { + return; + } + + if (!p.isOp()) { + return; + } + + if (Bukkit.spigot().getSpigotConfig().getBoolean("bungeecord")) { + p.sendPluginMessage(Main.p, "BungeeCord", new byte[1]); + } else { + // TODO: FINSIH non-lousy advertising + sendAdvertising(null, 1); + } + + } + + @Override + public void onPluginMessageReceived(String channel, Player player, byte[] message) { + // TODO Auto-generated method stub + + } + + private static void sendAdvertising(Player p, int players) { + if (players < 75) { + return; + } + + String plan = players > 300 ? "§f§lPLATINUM" : players > 100 ? "§6§lGOLD" : "§7§lSILVER"; + + String ad = "§2§l⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛§f§l ENTRYRISE §2§l⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛" + + "\n\n" + + " §a✸ §7We have noticed that your server is popular. Hooray!\n" + + " §a✸ §7Entryrise, the team behind LagAssist, provides system\n" + + " §a✸ §7administration and server management services for\n" + + " §a✸ §7servers, including enterprise networks with thousands of concurrent players.\n\n" + + " §a✸ §7The " + plan + "§7 plan should be ideal for your usecase.\n\n"; + + + ad = ad + " §a✸ §7Click here for more info or to disable the ad." + + "§2§l⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛"; + + final String adf = ad; + + Bukkit.getScheduler().runTaskLaterAsynchronously(Main.p, () -> { + p.spigot().sendMessage(Chat.genHoverAndLinkComponent(adf + "", "https://www.entryrise.com", "Use /lagassist advertising to disable this message from showing")); + }, 60); + } + +} diff --git a/src/cx/sfy/LagAssist/mobs/SmartMob.java b/src/cx/sfy/LagAssist/mobs/SmartMob.java index 8eea5a3..04b6ac3 100644 --- a/src/cx/sfy/LagAssist/mobs/SmartMob.java +++ b/src/cx/sfy/LagAssist/mobs/SmartMob.java @@ -107,10 +107,13 @@ public class SmartMob implements Listener { @EventHandler(priority = EventPriority.LOWEST) public void SpawnListener(CreatureSpawnEvent e) { + + if (!WorldMgr.blacklist.contains(e.getEntity().getWorld().getName())) { + return; + } + if (!Spawning) { - if (!WorldMgr.blacklist.contains(e.getEntity().getWorld().getName())) { - e.setCancelled(true); - } + e.setCancelled(true); return; } Entity ent = e.getEntity(); diff --git a/src/cx/sfy/LagAssist/utils/Chat.java b/src/cx/sfy/LagAssist/utils/Chat.java index 0cca2c5..3a995d0 100644 --- a/src/cx/sfy/LagAssist/utils/Chat.java +++ b/src/cx/sfy/LagAssist/utils/Chat.java @@ -27,6 +27,13 @@ public class Chat { return msg; } + public static TextComponent genHoverAndLinkComponent(String show, String url, String hover) { + TextComponent msg = new TextComponent(show); + msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(hover).create())); + msg.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url)); + return msg; + } + public static String capitalize(String stg) { return stg.substring(0, 1).toUpperCase() + stg.substring(1); }