From acd7de715e7502dac42a81566adf97c313a8d983 Mon Sep 17 00:00:00 2001 From: Ivan Date: Fri, 29 Nov 2019 11:41:18 -0500 Subject: [PATCH] new commands, fix /tempban, etc --- .../command/Command_scare.java | 56 +++++++++++++++++ .../command/Command_tabcolor.java | 63 +++++++++++++++++++ .../command/Command_tempban.java | 24 ++++--- .../totalfreedommod/util/FUtil.java | 2 + 4 files changed, 137 insertions(+), 8 deletions(-) create mode 100644 src/main/java/me/totalfreedom/totalfreedommod/command/Command_scare.java create mode 100644 src/main/java/me/totalfreedom/totalfreedommod/command/Command_tabcolor.java diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_scare.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_scare.java new file mode 100644 index 00000000..40b3f17e --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_scare.java @@ -0,0 +1,56 @@ +package me.totalfreedom.totalfreedommod.command; + +import java.util.Collections; +import java.util.List; +import me.totalfreedom.totalfreedommod.rank.Rank; +import me.totalfreedom.totalfreedommod.util.FUtil; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.ChatColor; +import org.bukkit.Particle; +import org.bukkit.Sound; + +@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.BOTH) +@CommandParameters(description = "Surprise someone.", usage = "/ ") +public class Command_scare extends FreedomCommand +{ + /* This command will not work on Paper because there was a patch to remove it. This will work on Spigot and Bukkit. */ + @Override + public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + + if (args.length == 0) + { + return false; + } + + final Player player = getPlayer(args[0]); + + if (player == null) + { + msg(FreedomCommand.PLAYER_NOT_FOUND); + return true; + } + + msg("Scared " + player.getName()); + + player.spawnParticle(Particle.MOB_APPEARANCE, player.getLocation(), 4); + for (int i = 0; i < 10; ++i) { + player.playSound(player.getLocation(), Sound.ENTITY_ENDERMAN_SCREAM, 1, 0); + } + + + return true; + } + + @Override + public List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) + { + if (args.length == 1 && plugin.al.isAdmin(sender)) + { + return FUtil.getPlayerList(); + } + return Collections.emptyList(); + } +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tabcolor.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tabcolor.java new file mode 100644 index 00000000..1f6f1027 --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tabcolor.java @@ -0,0 +1,63 @@ +package me.totalfreedom.totalfreedommod.command; + +import java.util.Iterator; +import java.util.Map; +import me.totalfreedom.totalfreedommod.rank.Rank; +import me.totalfreedom.totalfreedommod.util.FUtil; +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; + +@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.ONLY_IN_GAME) +@CommandParameters(description = "Change your tab color", usage = "/ ") +public class Command_tabcolor extends FreedomCommand +{ + + @Override + public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + + if (!FUtil.isExecutive(sender.getName())) + { + return noPerms(); + } + + if (args.length != 1) + { + return false; + } + + if ("list".equalsIgnoreCase(args[0])) + { + msg("Colors: " + StringUtils.join(FUtil.CHAT_COLOR_NAMES.keySet(), ", ")); + return true; + } + + final String needle = args[0].trim().toLowerCase(); + ChatColor color = null; + final Iterator> it = FUtil.CHAT_COLOR_NAMES.entrySet().iterator(); + while (it.hasNext()) + { + final Map.Entry entry = it.next(); + if (entry.getKey().contains(needle)) + { + color = entry.getValue(); + break; + } + } + + if (color == null) + { + msg("Invalid color: " + needle + " - Use \"/tabcolor list\" to list colors."); + return true; + } + + playerSender.setPlayerListName(StringUtils.substring(color + sender.getName(), 0, 16)); + + msg("ok dad"); + + return true; + } +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tempban.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tempban.java index fa24bbfc..dd77450a 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tempban.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tempban.java @@ -37,17 +37,25 @@ public class Command_tempban extends FreedomCommand final List ips = new ArrayList<>(); final Player player = getPlayer(args[0]); - final PlayerData entry = plugin.pl.getData(args[0]); - - if (player == null) { - msg(FreedomCommand.PLAYER_NOT_FOUND); - return true; - } + final PlayerData entry = plugin.pl.getData(args[0]); - username = entry.getUsername(); - ips.addAll(entry.getIps()); + if (entry == null) + { + msg("Can't find that user. If target is not logged in, make sure that you spelled the name exactly."); + return true; + } + + username = entry.getUsername(); + ips.addAll(entry.getIps()); + } + else + { + final PlayerData entry = plugin.pl.getData(player); + username = player.getName(); + ips.addAll(entry.getIps()); + } final StringBuilder message = new StringBuilder("Temporarily banned " + player.getName()); Date expires = FUtil.parseDateOffset("30m"); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java index 22834364..e4ea4928 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java @@ -42,6 +42,8 @@ public class FUtil public static String DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z"; public static final Map CHAT_COLOR_NAMES = new HashMap<>(); public static final List CHAT_COLOR_POOL = Arrays.asList( + ChatColor.WHITE, + ChatColor.BLACK, ChatColor.DARK_RED, ChatColor.RED, ChatColor.GOLD,