Skip to content

Commit

Permalink
Fixes and improvements to the tag blocking process
Browse files Browse the repository at this point in the history
This should fix the memory leak I suspect.
  • Loading branch information
Wild1145 committed Sep 14, 2019
1 parent c1c333e commit bc722b3
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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;
Expand Down Expand Up @@ -97,6 +98,7 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
public Jumppads jp;
public Trailer tr;
public HTTPDaemon hd;
public PlayerBlocker plb;
//
// Bridges
public ServiceManager<TotalFreedomMod> bridges;
Expand Down Expand Up @@ -197,6 +199,8 @@ public void enable()

// HTTPD
hd = services.registerService(HTTPDaemon.class);
plb = services.registerService(PlayerBlocker.class);
// Start Services
services.start();

// Start bridges
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> blockedTags = Lists.newArrayList();

public PlayerBlocker(TotalFreedomMod plugin)
{
super(plugin);
}

@Override
protected void onStart()
{
// Load banned tags
blockedTags.clear();
blockedTags.addAll((Collection<? extends String>) ConfigEntry.BLOCKED_TAGS.getList());
FLog.info("Loaded " + blockedTags.size() + " banned tags.");
}

@Override
protected void onStop()
{
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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;
Expand All @@ -19,18 +20,10 @@
public class Command_tag extends FreedomCommand
{

public final List<String> 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<? extends String>) ConfigEntry.BLOCKED_TAGS.getList());
FLog.info("Loaded " + FORBIDDEN_WORDS.size() + " forbidden tags.");


if (args.length == 1)
{
if ("list".equalsIgnoreCase(args[0]))
Expand Down Expand Up @@ -138,7 +131,7 @@ else if ("set".equalsIgnoreCase(args[0]))
return true;
}

for (String word : FORBIDDEN_WORDS)
for (String word : PlayerBlocker.blockedTags)
{
if (rawTag.contains(word))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -30,7 +31,7 @@ public boolean run(CommandSender sender, Player playerSender, Command cmd, Strin
}

String tagStr = tag.toString();
for (String word : Command_tag.FORBIDDEN_WORDS)
for (String word : PlayerBlocker.blockedTags)
{
if (tagStr.contains(word))
{
Expand Down

0 comments on commit bc722b3

Please sign in to comment.