From bc722b3b7b05f37ce575397ee324386cfee47562 Mon Sep 17 00:00:00 2001 From: Ryan Wild Date: Sat, 14 Sep 2019 19:44:10 +0100 Subject: [PATCH] Fixes and improvements to the tag blocking process This should fix the memory leak I suspect. --- .../totalfreedommod/TotalFreedomMod.java | 4 ++ .../blocking/PlayerBlocker.java | 44 +++++++++++++++++++ .../totalfreedommod/command/Command_tag.java | 11 +---- .../command/Command_tagnyan.java | 3 +- 4 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 src/main/java/me/totalfreedom/totalfreedommod/blocking/PlayerBlocker.java diff --git a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java index db4b2af..308ff1a 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java @@ -13,6 +13,7 @@ import me.totalfreedom.totalfreedommod.blocking.InteractBlocker; import me.totalfreedom.totalfreedommod.blocking.MobBlocker; import me.totalfreedom.totalfreedommod.blocking.PotionBlocker; import me.totalfreedom.totalfreedommod.blocking.command.CommandBlocker; +import me.totalfreedom.totalfreedommod.blocking.PlayerBlocker; import me.totalfreedom.totalfreedommod.bridge.BukkitTelnetBridge; import me.totalfreedom.totalfreedommod.bridge.EssentialsBridge; import me.totalfreedom.totalfreedommod.bridge.LibsDisguisesBridge; @@ -97,6 +98,7 @@ public class TotalFreedomMod extends AeroPlugin public Jumppads jp; public Trailer tr; public HTTPDaemon hd; + public PlayerBlocker plb; // // Bridges public ServiceManager bridges; @@ -197,6 +199,8 @@ public class TotalFreedomMod extends AeroPlugin // HTTPD hd = services.registerService(HTTPDaemon.class); + plb = services.registerService(PlayerBlocker.class); + // Start Services services.start(); // Start bridges diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/PlayerBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/PlayerBlocker.java new file mode 100644 index 0000000..1a58dc0 --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/PlayerBlocker.java @@ -0,0 +1,44 @@ +package me.totalfreedom.totalfreedommod.blocking; + +import com.google.common.collect.Lists; +import me.totalfreedom.totalfreedommod.FreedomService; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import me.totalfreedom.totalfreedommod.util.FLog; +import me.totalfreedom.totalfreedommod.util.FUtil; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.inventory.ItemStack; + +import java.util.Collection; +import java.util.List; + +public class PlayerBlocker extends FreedomService +{ + + public static final List blockedTags = Lists.newArrayList(); + + public PlayerBlocker(TotalFreedomMod plugin) + { + super(plugin); + } + + @Override + protected void onStart() + { + // Load banned tags + blockedTags.clear(); + blockedTags.addAll((Collection) ConfigEntry.BLOCKED_TAGS.getList()); + FLog.info("Loaded " + blockedTags.size() + " banned tags."); + } + + @Override + protected void onStop() + { + } + +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java index 84c70df..1e5e288 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tag.java @@ -5,6 +5,7 @@ import java.util.Collection; import java.util.List; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.FPlayer; +import me.totalfreedom.totalfreedommod.blocking.PlayerBlocker; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -19,18 +20,10 @@ import org.bukkit.entity.Player; public class Command_tag extends FreedomCommand { - public final List FORBIDDEN_WORDS = Lists.newArrayList(); - @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - // Load unbannable usernames - FORBIDDEN_WORDS.clear(); - FORBIDDEN_WORDS.addAll((Collection) ConfigEntry.BLOCKED_TAGS.getList()); - FLog.info("Loaded " + FORBIDDEN_WORDS.size() + " forbidden tags."); - - if (args.length == 1) { if ("list".equalsIgnoreCase(args[0])) @@ -138,7 +131,7 @@ public class Command_tag extends FreedomCommand return true; } - for (String word : FORBIDDEN_WORDS) + for (String word : PlayerBlocker.blockedTags) { if (rawTag.contains(word)) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tagnyan.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tagnyan.java index 70eef74..81859e4 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tagnyan.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tagnyan.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.blocking.PlayerBlocker; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -30,7 +31,7 @@ public class Command_tagnyan extends FreedomCommand } String tagStr = tag.toString(); - for (String word : Command_tag.FORBIDDEN_WORDS) + for (String word : PlayerBlocker.blockedTags) { if (tagStr.contains(word)) {