From 92110f78c4d80094a302034f9ee19555cf2fb74f Mon Sep 17 00:00:00 2001 From: Jerom van der Sar Date: Mon, 17 Sep 2012 18:29:43 +0200 Subject: [PATCH] General stuff & whitelist (work in progress) --- .../Commands/Command_adminmode.java | 4 +- .../Commands/Command_doom.java | 21 ++++- .../TotalFreedomMod/Commands/Command_ops.java | 14 +-- .../Commands/Command_qdeop.java | 4 +- .../TotalFreedomMod/Commands/Command_qop.java | 4 +- .../Commands/Command_saconfig.java | 5 + .../Commands/Command_stfu.java | 27 +++++- .../Commands/Command_whitelist.java | 93 +++++++++++++++++++ .../Listener/TFM_PlayerListener.java | 33 ++++--- .../TotalFreedomMod/TFM_Util.java | 27 +++++- .../TotalFreedomMod/TFM_message.java | 26 ++++++ .../TotalFreedomMod/TotalFreedomMod.java | 1 + src/plugin.yml | 9 +- 13 files changed, 221 insertions(+), 47 deletions(-) create mode 100644 src/me/StevenLawson/TotalFreedomMod/Commands/Command_whitelist.java create mode 100644 src/me/StevenLawson/TotalFreedomMod/TFM_message.java diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminmode.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminmode.java index 37eee7e8..3995bbec 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminmode.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminmode.java @@ -21,13 +21,13 @@ public class Command_adminmode extends TFM_Command if (args[0].equalsIgnoreCase("off")) { TotalFreedomMod.adminOnlyMode = false; - TFM_Util.bcastMsg("Server is now open to all players.", ChatColor.RED); + TFM_Util.adminAction(sender.getName(), "Opening the server to all players.", true); return true; } else if (args[0].equalsIgnoreCase("on")) { TotalFreedomMod.adminOnlyMode = true; - TFM_Util.bcastMsg("Server is now closed to non-superadmins.", ChatColor.RED); + TFM_Util.adminAction(sender.getName(), "Closing the server to non-superadmins.", true); for (Player p : server.getOnlinePlayers()) { if (!TFM_Util.isUserSuperadmin(p)) diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_doom.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_doom.java index 85702ff6..e5924bf9 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_doom.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_doom.java @@ -1,5 +1,8 @@ package me.StevenLawson.TotalFreedomMod.Commands; +import java.util.Arrays; +import java.util.List; + import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; @@ -12,10 +15,22 @@ import org.bukkit.entity.Player; public class Command_doom extends TFM_Command { + public String[] p = + { + "madgeek", + "darth", + "madgeek1450", + "mark", + "markbyron", + "darthsalamon" + }; + + public List players = Arrays.asList(p); + @Override public boolean run(final CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if(!(TFM_Util.isUserSuperadmin(sender))) + if(!(senderIsConsole && players.contains(sender.getName().toLowerCase()))) { sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); return true; @@ -39,7 +54,7 @@ public class Command_doom extends TFM_Command TFM_Util.adminAction(sender.getName(), "Casting oblivion over " + p.getName(), true); - TFM_Util.bcastMsg(p.getName() + " will be completely obliveriated!", ChatColor.RED); + TFM_Util.bcastMsg(p.getName() + " will be completely obliviated!", ChatColor.RED); final String IP = p.getAddress().getAddress().getHostAddress().trim(); @@ -98,7 +113,7 @@ public class Command_doom extends TFM_Command p.getWorld().createExplosion(p.getLocation(), 4F); // kick player - p.kickPlayer(ChatColor.RED + "You, my dear friend must FUCKOFF!"); + p.kickPlayer(ChatColor.RED + "FUCKOFF, and get your shit together!"); } }, 60L); // 3 seconds diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_ops.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_ops.java index af6baa40..dabae056 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_ops.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_ops.java @@ -26,16 +26,10 @@ public class Command_ops extends TFM_Command if (args[0].equalsIgnoreCase("list")) { - String ops = ""; - String delim = ""; - for (OfflinePlayer p : server.getOperators()) - { - ops += delim; - ops += p.getName(); - delim = ","; - } + String ops = TFM_Util.arrayToString(server.getOperators()); - TFM_Util.playerMsg(sender, "Operators: " + ops); + TFM_Util.playerMsg(sender, "Operators:"); + TFM_Util.playerMsg(sender, ops); return true; } @@ -68,7 +62,7 @@ public class Command_ops extends TFM_Command if (args[0].equalsIgnoreCase("purge")) { - if (!(TFM_Util.isUserSuperadmin(sender) || senderIsConsole)) + if (!senderIsConsole) { sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_qdeop.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_qdeop.java index b5ad7698..b03d1f91 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_qdeop.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_qdeop.java @@ -24,11 +24,11 @@ public class Command_qdeop extends TFM_Command boolean matched_player = false; - String target_name = args[0].toLowerCase(); + String target = args[0].toLowerCase(); for (Player p : server.getOnlinePlayers()) { - if (p.getName().toLowerCase().indexOf(target_name) > 0 || p.getDisplayName().toLowerCase().indexOf(target_name) > 0) + if (p.getName().toLowerCase().contains(target)) { matched_player = true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_qop.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_qop.java index 57d09a15..f8a5f998 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_qop.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_qop.java @@ -24,11 +24,11 @@ public class Command_qop extends TFM_Command boolean matched_player = false; - String target_name = args[0].toLowerCase(); + String target = args[0].toLowerCase(); for (Player p : server.getOnlinePlayers()) { - if (p.getName().toLowerCase().indexOf(target_name) > 0 || p.getDisplayName().toLowerCase().indexOf(target_name) > 0) + if (p.getName().toLowerCase().contains(target)) { matched_player = true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java index 49adf4ab..db01fe8a 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_saconfig.java @@ -36,6 +36,11 @@ public class Command_saconfig extends TFM_Command return true; } + if (sender.getName().equalsIgnoreCase("remotebukkit")) + { + sender.sendMessage(TotalFreedomMod.NOT_FROM_CONSOLE); + } + if (args.length < 2) { return false; diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_stfu.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_stfu.java index 7579657b..096a6c04 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_stfu.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_stfu.java @@ -3,7 +3,6 @@ package me.StevenLawson.TotalFreedomMod.Commands; import me.StevenLawson.TotalFreedomMod.TFM_UserInfo; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; -import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -15,7 +14,7 @@ public class Command_stfu extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (args.length < 1 || args.length > 1) + if (args.length != 1) { return false; } @@ -49,7 +48,7 @@ public class Command_stfu extends TFM_Command if (args[0].equalsIgnoreCase("purge")) { - TFM_Util.bcastMsg(ChatColor.RED + sender.getName() + " - Unmuting all players."); + TFM_Util.adminAction(sender.getName(), "Unmuting all players.", true); TFM_UserInfo info; int count = 0; for (Player mp : server.getOnlinePlayers()) @@ -64,7 +63,27 @@ public class Command_stfu extends TFM_Command TFM_Util.playerMsg(sender, "Unmuted " + count + " players."); return true; } - + + if(args[0].equalsIgnoreCase("all")) + { + TFM_Util.adminAction(sender.getName(), "Muting all non-Superadmins", true); + + TFM_UserInfo playerdata; + int counter = 0; + for(Player p : server.getOnlinePlayers()) + { + if(!TFM_Util.isUserSuperadmin(p)) + { + playerdata = TFM_UserInfo.getPlayerData(p); + playerdata.setMuted(true); + counter++; + } + } + + TFM_Util.playerMsg(sender, "Muted " + counter + " players."); + + } + Player p; try { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_whitelist.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_whitelist.java new file mode 100644 index 00000000..bc6dea5b --- /dev/null +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_whitelist.java @@ -0,0 +1,93 @@ +package me.StevenLawson.TotalFreedomMod.Commands; + +import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; + +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Command_whitelist extends TFM_Command +{ + @Override + public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + if(args.length < 1) + { + return false; + } + + if(!sender.isOp()) + { + sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); + return true; + } + + // list + if(args[0].equalsIgnoreCase("list")) + { + String players = TFM_Util.arrayToString(server.getWhitelistedPlayers()); + + TFM_Util.playerMsg(sender, "Whitelisted players:"); + TFM_Util.playerMsg(sender, players); + return true; + } + + // count + if(args[0].equalsIgnoreCase("count")) + { + int onlineWPs = 0; + int offlineWPs = 0; + int totalWPs = 0; + + for (OfflinePlayer p : server.getWhitelistedPlayers()) + { + if (p.isOnline()) + { + onlineWPs++; + } + else + { + offlineWPs++; + } + totalWPs++; + } + + sender.sendMessage(ChatColor.GRAY + "Online whitelisted players: " + onlineWPs); + sender.sendMessage(ChatColor.GRAY + "Offline whitelisted players: " + offlineWPs); + sender.sendMessage(ChatColor.GRAY + "Total whitelisted players: " + totalWPs); + + return true; + } + + // all commands past this line are superadmin-only + if(!(senderIsConsole || TFM_Util.isUserSuperadmin(sender))) + { + sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); + return true; + } + + + // addall + if(args[0].equalsIgnoreCase("addall")) + { + TFM_Util.adminAction(sender.getName(), "Adding all online players to the whitelist", false); + int counter = 0; + for(Player p : server.getOnlinePlayers()) + { + if(!p.isWhitelisted()) + { + p.setWhitelisted(true); + counter++; + } + } + + TFM_Util.playerMsg(sender, "Whitelisted " + counter + " players."); + } + + + return true; + } +} diff --git a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java index aa171372..6b0f7b85 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java @@ -231,25 +231,24 @@ public class TFM_PlayerListener implements Listener p.setVelocity(new Vector(0, playerdata.orbitStrength(), 0)); } } + /* + if (p.getItemInHand().getType() == Material.SPECKLED_MELON) + { + if (TFM_Util.isUserSuperadmin(p)) + { + Location from_pos = event.getFrom().clone(); + Location to_pos = event.getTo().clone(); -// if (p.getItemInHand().getType() == Material.SPECKLED_MELON) -// { -// if (TFM_Util.isUserSuperadmin(p)) -// { -// Location from_pos = event.getFrom().clone(); -// Location to_pos = event.getTo().clone(); -// -// /* -// Block block_pos = user_pos.clone().add(user_pos.getDirection().multiply(-2.0)).getBlock(); -// -// if ((block_pos.isEmpty() || block_pos.isLiquid())) -// { -// block_pos.setTypeIdAndData(Material.WOOL.getId(), DyeColor.values()[randomGenerator.nextInt(DyeColor.values().length)].getData(), false); -// } -// */ -// } -// } + + Block block_pos = user_pos.clone().add(user_pos.getDirection().multiply(-2.0)).getBlock(); + if ((block_pos.isEmpty() || block_pos.isLiquid())) + { + block_pos.setTypeIdAndData(Material.WOOL.getId(), DyeColor.values()[randomGenerator.nextInt(DyeColor.values().length)].getData(), false); + } + } + } + */ if (TotalFreedomMod.landminesEnabled && TotalFreedomMod.allowExplosions) { Iterator landmines = TFM_LandmineData.landmines.iterator(); diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java index d20e0309..ccbc1789 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java @@ -712,16 +712,20 @@ public class TFM_Util if (sender.getName().equalsIgnoreCase("markbyron")) { - return "the " + ChatColor.LIGHT_PURPLE + "server owner" + ChatColor.AQUA + "."; + return "the " + ChatColor.LIGHT_PURPLE + "owner" + ChatColor.AQUA + "."; } if (sender.getName().equalsIgnoreCase("madgeek1450")) { - return "the " + ChatColor.DARK_PURPLE + "server chief-developer" + ChatColor.AQUA + "."; + return "the " + ChatColor.DARK_PURPLE + "developer" + ChatColor.AQUA + "."; } if (sender.getName().equalsIgnoreCase("darthsalamon")) { - return "a " + ChatColor.DARK_PURPLE + "server developer" + ChatColor.AQUA + "!"; + return "a " + ChatColor.DARK_PURPLE + "developer" + ChatColor.AQUA + "!"; + } + if (sender.getName().equalsIgnoreCase("miwojedk")) + { + return "a " + ChatColor.DARK_RED+ "master-builder" + ChatColor.AQUA + "!"; } if (TFM_Util.isUserSuperadmin(sender)) @@ -734,7 +738,7 @@ public class TFM_Util return "an " + ChatColor.DARK_GREEN + "OP" + ChatColor.AQUA + "."; } - return "a " + ChatColor.GREEN + "standard player" + ChatColor.AQUA + "."; + return "a " + ChatColor.GREEN + "non-OP" + ChatColor.AQUA + "."; } public static void banUsername(String name, String reason, String source, Date expire_date) @@ -921,6 +925,21 @@ public class TFM_Util return c.getTime(); } + + public static String arrayToString(Set set) + { + String players = ""; + String delim = ""; + + for (OfflinePlayer p : set) + { + players += delim; + players += p.getName(); + delim = ", "; + } + + return players; + } // I wrote all this before i discovered getTargetBlock >.> - might come in handy some day... // public static final double LOOKAT_VIEW_HEIGHT = 1.65; // public static final double LOOKAT_STEP_DISTANCE = 0.2; diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_message.java b/src/me/StevenLawson/TotalFreedomMod/TFM_message.java new file mode 100644 index 00000000..ba794933 --- /dev/null +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_message.java @@ -0,0 +1,26 @@ +package me.StevenLawson.TotalFreedomMod; + +import org.bukkit.ChatColor; + +// Work in progress +@Deprecated +public enum TFM_message { + NO_PERMS(ChatColor.YELLOW + "You do not have permission to use this command."), + YOU_ARE_OP(ChatColor.YELLOW + "You are now op!"), + YOU_ARE_NOT_OP(ChatColor.YELLOW + "You are no longer op!"), + CAKE_LYRICS("But there's no sense crying over every mistake. You just keep on trying till you run out of cake."), + NOT_FROM_CONSOLE("This command may not be used from the console.") + ; + private final String message; + + TFM_message(String message) + { + this.message = message; + } + + @Override + public String toString() + { + return message; + } +} diff --git a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java index 193abf0f..12c9b101 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java +++ b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java @@ -29,6 +29,7 @@ public class TotalFreedomMod extends JavaPlugin public static final String SUPERADMIN_FILE = "superadmin.yml"; public static final String COMMAND_PATH = "me.StevenLawson.TotalFreedomMod.Commands"; public static final String COMMAND_PREFIX = "Command_"; + public static final String MSG_NO_PERMS = ChatColor.YELLOW + "You do not have permission to use this command."; public static final String YOU_ARE_OP = ChatColor.YELLOW + "You are now op!"; public static final String YOU_ARE_NOT_OP = ChatColor.YELLOW + "You are no longer op!"; diff --git a/src/plugin.yml b/src/plugin.yml index 40024c6d..bb5dc72d 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -32,7 +32,7 @@ commands: description: Superadmin command - Deop everyone on the server. usage: / doom: - description: Owner command - For the worst of the worst, completely remove a player. + description: Owner command - For the bad Superadmins. usage: / enchant: description: Enchant items. @@ -165,7 +165,7 @@ commands: usage: / stfu: description: Superadmin Command - Mutes a player with brute force. - usage: / [list | purge | ] + usage: / [ | list | purge | all] aliases: [mute] stop: description: Superadmin command - Kicks everyone and stops the server. @@ -194,11 +194,14 @@ commands: waterplace: description: Superadmin command - Enable/disable water placement. usage: / + whitelist: + description: Superadmin command - Manage the whitelist. + usage: / | remove | addall | purge> wildcard: description: Superadmin command - Run any command on all users, username placeholder = ?. usage: / [fluff] ? [fluff] ? # wipeflatlands: -# description: Console Command - Wipe the flatlands map. +# description: Owner command - Wipe the flatlands map. # usage: / ziptool: description: Owner command - Zip and unzip files.