From f3ac19a616a1b40aa7db481e8415b318d15ba3fd Mon Sep 17 00:00:00 2001 From: JeromSar Date: Mon, 12 Aug 2013 12:26:49 +0200 Subject: [PATCH] Added /tag Minor cleanup --- appinfo.properties | 6 +- buildnumber.properties | 4 +- .../Commands/Command_rawsay.java | 3 +- .../Commands/Command_saconfig.java | 2 +- .../TotalFreedomMod/Commands/Command_tag.java | 58 +++++++++++++++++++ .../Listener/TFM_PlayerListener.java | 8 ++- .../TotalFreedomMod/TFM_CommandBlocker.java | 2 +- .../TFM_CommandBlockerNew.java | 2 +- .../TotalFreedomMod/TFM_PlayerData.java | 19 ++++++ .../TotalFreedomMod/TFM_UserList.java | 18 +++--- .../TotalFreedomMod/TFM_Util.java | 6 ++ 11 files changed, 107 insertions(+), 21 deletions(-) create mode 100644 src/me/StevenLawson/TotalFreedomMod/Commands/Command_tag.java diff --git a/appinfo.properties b/appinfo.properties index bb5aad83..f897067a 100644 --- a/appinfo.properties +++ b/appinfo.properties @@ -1,5 +1,5 @@ -#Sat, 10 Aug 2013 15:43:16 -0400 +#Mon, 12 Aug 2013 12:25:56 +0200 program.VERSION=2.22 -program.BUILDNUM=392 -program.BUILDDATE=08/10/2013 03\:43 PM +program.BUILDNUM=400 +program.BUILDDATE=08/12/2013 12\:25 PM diff --git a/buildnumber.properties b/buildnumber.properties index cb0e152b..1c121000 100644 --- a/buildnumber.properties +++ b/buildnumber.properties @@ -1,3 +1,3 @@ #Build Number for ANT. Do not edit! -#Sat Aug 10 15:43:16 EDT 2013 -build.number=393 +#Mon Aug 12 12:25:56 CEST 2013 +build.number=401 diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rawsay.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rawsay.java index d6a36a79..32b29acd 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rawsay.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rawsay.java @@ -2,7 +2,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; import me.StevenLawson.TotalFreedomMod.TFM_Util; import org.apache.commons.lang.StringUtils; -import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -16,7 +15,7 @@ public class Command_rawsay extends TFM_Command { if (args.length > 0) { - TFM_Util.bcastMsg(ChatColor.translateAlternateColorCodes('&', StringUtils.join(args, " "))); + TFM_Util.bcastMsg(TFM_Util.colorise(StringUtils.join(args, " "))); } return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java index 8e1798c8..1752e80f 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java @@ -77,7 +77,7 @@ public class Command_saconfig extends TFM_Command } else { - playerMsg(ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', superadmin.toString()))); + playerMsg(ChatColor.stripColor(TFM_Util.colorise(superadmin.toString()))); } return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tag.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tag.java new file mode 100644 index 00000000..e672f655 --- /dev/null +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tag.java @@ -0,0 +1,58 @@ +package me.StevenLawson.TotalFreedomMod.Commands; + +import java.util.Arrays; +import java.util.List; +import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; +import me.StevenLawson.TotalFreedomMod.TFM_Util; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandPermissions(level = AdminLevel.OP, source = SourceType.ONLY_IN_GAME) +@CommandParameters(description = "Sets yourself a prefix", usage = "/ [ | off]") +public class Command_tag extends TFM_Command +{ + + public static final List FORBIDDEN_WORDS = Arrays.asList(new String[]{"admin", "owner", "moderator", "developer"}); + + @Override + public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + if (args.length != 1) + { + return false; + } + + if (TFM_Util.isStopCommand(args[0])) + { + TFM_PlayerData.getPlayerData(sender_p).setTag(null); + playerMsg("Removed your tag."); + return true; + } + + if (args[0].length() > 15) + { + playerMsg("That tag is too long."); + return true; + } + + if (!TFM_SuperadminList.isUserSuperadmin(sender)) + { + for (String word : FORBIDDEN_WORDS) + { + if (args[0].toLowerCase().contains(word)) + { + playerMsg("That tag contains a forbidden word."); + return true; + } + } + } + + TFM_PlayerData.getPlayerData(sender_p).setTag(args[0]); + playerMsg("Tag set."); + + return true; + } + +} diff --git a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java index d1e36237..5183b36e 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java @@ -50,7 +50,6 @@ public class TFM_PlayerListener implements Listener player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1)); player.sendMessage(ChatColor.GRAY + "Water buckets are currently disabled."); event.setCancelled(true); - return; } break; } @@ -61,7 +60,6 @@ public class TFM_PlayerListener implements Listener player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1)); player.sendMessage(ChatColor.GRAY + "Lava buckets are currently disabled."); event.setCancelled(true); - return; } break; } @@ -442,6 +440,12 @@ public class TFM_PlayerListener implements Listener // Finally, set message event.setMessage(message); + + // Set the tag + if (playerdata.getTag() != null) { + p.setDisplayName((playerdata.getTag() + " " + p.getDisplayName().replaceAll(" ", ""))); + } + } catch (Exception ex) { diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_CommandBlocker.java b/src/me/StevenLawson/TotalFreedomMod/TFM_CommandBlocker.java index 5203bd8d..2c18de10 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_CommandBlocker.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_CommandBlocker.java @@ -71,7 +71,7 @@ public class TFM_CommandBlocker } else { - sender.sendMessage(ChatColor.GRAY + ChatColor.translateAlternateColorCodes('&', parts[3])); + sender.sendMessage(ChatColor.GRAY + TFM_Util.colorise(parts[3])); } } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_CommandBlockerNew.java b/src/me/StevenLawson/TotalFreedomMod/TFM_CommandBlockerNew.java index 0b0e16df..478a71b5 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_CommandBlockerNew.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_CommandBlockerNew.java @@ -308,7 +308,7 @@ public class TFM_CommandBlockerNew } else { - response = ChatColor.GRAY + ChatColor.translateAlternateColorCodes('&', this.message); + response = ChatColor.GRAY + TFM_Util.colorise(this.message); } sender.sendMessage(response); diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerData.java b/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerData.java index cce1a3ad..d48e5fec 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerData.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_PlayerData.java @@ -53,6 +53,7 @@ public class TFM_PlayerData private Boolean superadmin_id_verified = null; private String last_command = ""; private boolean cmdspy_enabled = false; + private String tag = null; public TFM_PlayerData(Player player) { @@ -504,4 +505,22 @@ public class TFM_PlayerData { return cmdspy_enabled; } + + public void setTag(String tag) + { + if (tag == null) + { + this.tag = null; + } + else + { + this.tag = TFM_Util.colorise(tag) + ChatColor.WHITE; + } + } + + public String getTag() + { + return this.tag; + } + } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_UserList.java b/src/me/StevenLawson/TotalFreedomMod/TFM_UserList.java index c85d54f3..57b7e174 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_UserList.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_UserList.java @@ -148,35 +148,35 @@ public class TFM_UserList public class TFM_UserListEntry { - private String _username; - private List _ip_addresses = new ArrayList(); + private String username; + private List ip_addresses = new ArrayList(); public TFM_UserListEntry(String username, List ip_addresses) { - _username = username; - _ip_addresses = ip_addresses; + this.username = username; + this.ip_addresses = ip_addresses; } public TFM_UserListEntry(String username) { - _username = username; + this.username = username; } public List getIpAddresses() { - return _ip_addresses; + return ip_addresses; } public String getUsername() { - return _username; + return username; } public boolean addIpAddress(String ip_address) { - if (!_ip_addresses.contains(ip_address)) + if (!ip_addresses.contains(ip_address)) { - _ip_addresses.add(ip_address); + ip_addresses.add(ip_address); return true; } return false; diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java index f65e54e7..eabb673d 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java @@ -906,6 +906,7 @@ public class TFM_Util while (checkClass.getSuperclass() != Object.class && ((checkClass = checkClass.getSuperclass()) != null)); return null; } + public static final List COLOR_POOL = Arrays.asList( ChatColor.DARK_BLUE, ChatColor.DARK_GREEN, @@ -925,4 +926,9 @@ public class TFM_Util { return COLOR_POOL.get(RANDOM.nextInt(COLOR_POOL.size())); } + + public static String colorise(String string) + { + return ChatColor.translateAlternateColorCodes('&', string); + } }