From 3517c050545a73e97456c2ec4d9de01682d9badc Mon Sep 17 00:00:00 2001 From: Super_ Date: Mon, 2 Nov 2020 15:50:51 -0500 Subject: [PATCH] op commands and more messages --- .../plex/command/impl/OpAllCMD.java | 37 +++++++++++++++++ .../totalfreedom/plex/command/impl/OpCMD.java | 41 +++++++++++++++++++ .../plex/handlers/CommandHandler.java | 7 ++-- .../me/totalfreedom/plex/util/PlexUtils.java | 12 +++++- src/main/resources/messages.yml | 18 ++++++-- 5 files changed, 106 insertions(+), 9 deletions(-) create mode 100644 src/main/java/me/totalfreedom/plex/command/impl/OpAllCMD.java create mode 100644 src/main/java/me/totalfreedom/plex/command/impl/OpCMD.java diff --git a/src/main/java/me/totalfreedom/plex/command/impl/OpAllCMD.java b/src/main/java/me/totalfreedom/plex/command/impl/OpAllCMD.java new file mode 100644 index 0000000..c82e2ca --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/command/impl/OpAllCMD.java @@ -0,0 +1,37 @@ +package me.totalfreedom.plex.command.impl; + +import me.totalfreedom.plex.command.PlexCommand; +import me.totalfreedom.plex.command.annotations.CommandParameters; +import me.totalfreedom.plex.command.annotations.CommandPermissions; +import me.totalfreedom.plex.rank.enums.Rank; +import me.totalfreedom.plex.util.PlexUtils; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.List; + +import static me.totalfreedom.plex.util.PlexUtils.tl; + +@CommandParameters(description = "Op everyone on the server", aliases = "opa") +@CommandPermissions(level = Rank.ADMIN) +public class OpAllCMD extends PlexCommand +{ + public OpAllCMD() + { + super("opall"); + } + + @Override + public void execute(CommandSender sender, String[] args) + { + for (Player player : Bukkit.getOnlinePlayers()) + player.setOp(true); + PlexUtils.broadcast(tl("oppedAllPlayers", sender.getName())); + } + + @Override + public List onTabComplete(CommandSender sender, String[] args) { + return null; + } +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/command/impl/OpCMD.java b/src/main/java/me/totalfreedom/plex/command/impl/OpCMD.java new file mode 100644 index 0000000..302fba5 --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/command/impl/OpCMD.java @@ -0,0 +1,41 @@ +package me.totalfreedom.plex.command.impl; + +import me.totalfreedom.plex.command.PlexCommand; +import me.totalfreedom.plex.command.annotations.CommandParameters; +import me.totalfreedom.plex.command.annotations.CommandPermissions; +import me.totalfreedom.plex.rank.enums.Rank; +import me.totalfreedom.plex.util.PlexUtils; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.List; + +import static me.totalfreedom.plex.util.PlexUtils.tl; + +@CommandParameters(description = "Op a player on the server", usage = "/ ") +@CommandPermissions(level = Rank.OP) +public class OpCMD extends PlexCommand +{ + public OpCMD() + { + super("op"); + } + + @Override + public void execute(CommandSender sender, String[] args) + { + Player player = Bukkit.getPlayer(args[0]); + if (player == null) + { + sender.sendMessage(tl("playerNotFound")); + return; + } + PlexUtils.broadcast(tl("oppedPlayer", sender.getName(), player.getName())); + } + + @Override + public List onTabComplete(CommandSender sender, String[] args) { + return null; + } +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/handlers/CommandHandler.java b/src/main/java/me/totalfreedom/plex/handlers/CommandHandler.java index 1e479ae..3fd6442 100644 --- a/src/main/java/me/totalfreedom/plex/handlers/CommandHandler.java +++ b/src/main/java/me/totalfreedom/plex/handlers/CommandHandler.java @@ -2,10 +2,7 @@ package me.totalfreedom.plex.handlers; import com.google.common.collect.Lists; import me.totalfreedom.plex.command.PlexCommand; -import me.totalfreedom.plex.command.impl.FionnCMD; -import me.totalfreedom.plex.command.impl.PlexCMD; -import me.totalfreedom.plex.command.impl.TestCMD; -import me.totalfreedom.plex.command.impl.WorldCMD; +import me.totalfreedom.plex.command.impl.*; import me.totalfreedom.plex.util.PlexLog; import java.util.List; @@ -21,6 +18,8 @@ public class CommandHandler commands.add(new PlexCMD()); commands.add(new FionnCMD()); commands.add(new WorldCMD()); + commands.add(new OpAllCMD()); + commands.add(new OpCMD()); PlexLog.log(String.format("Registered %s commands!", commands.size())); } diff --git a/src/main/java/me/totalfreedom/plex/util/PlexUtils.java b/src/main/java/me/totalfreedom/plex/util/PlexUtils.java index 20c97de..64bd1fa 100644 --- a/src/main/java/me/totalfreedom/plex/util/PlexUtils.java +++ b/src/main/java/me/totalfreedom/plex/util/PlexUtils.java @@ -71,17 +71,20 @@ public class PlexUtils public static String tl(String s, Object... objects) { Plex plugin = Plex.get(); - if (s.equals("baseColor") || s.equals("errorColor")) - return getChatColorFromConfig(plugin.messages, (s.equals("baseColor") ? ChatColor.GRAY : ChatColor.RED), s).toString(); + if (s.equals("baseColor") || s.equals("errorColor") || s.equals("broadcastColor")) + return getChatColorFromConfig(plugin.messages, ChatColor.WHITE, s).toString(); String f = plugin.messages.getString(s); if (f == null) return ChatColor.RED + "No message"; for (Object object : objects) f = f.replace("", String.valueOf(object)); ChatColor base = getChatColorFromConfig(plugin.messages, ChatColor.GRAY, "baseColor"); + ChatColor broadcast = getChatColorFromConfig(plugin.messages, ChatColor.AQUA, "broadcastColor"); ChatColor error = getChatColorFromConfig(plugin.messages, ChatColor.RED, "errorColor"); f = f.replaceAll("", base.toString()); + f = f.replaceAll("", broadcast.toString()); f = f.replaceAll("", error.toString()); + f = color(f); return base + f; } @@ -124,4 +127,9 @@ public class PlexUtils } } } + + public static void broadcast(String s) + { + Bukkit.broadcastMessage(s); + } } diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index a759a00..4600e62 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -4,19 +4,31 @@ # Warning: not all commands have customizable messages # Base color - the main color prefix; will be used following each of the messages below +# Broadcast color - the color used when broadcasting a message # Error color - the color of an error; will be used when an error is thrown from a command baseColor: "7" +broadcastColor: "b" errorColor: "c" # Variables - these are code-defined replacements for things that should be inserted into messages. (e.g. names, statuses, numbers) -# if any of these variables are defined within a message, some documentation is provided to give more context to what the variables indicate. -# message variables are used in numerical order that is unchangeable from this file. +# if any of these variables are supposed to be used within a message, some documentation is provided to give more context to what the variables indicate. +# you are unable to change the order the variables are used due to it being a code-side functionality. +# if you are wishing to change these messages it's recommended you use the same amount of variables as stated in the documentation, however it's not required. # Reset color - this will reset the color of the message to the base color defined above. +# Broadcast color - this will make the color of the message the broadcast color defined above. # Error color - this will make the color of the message the error color defined above. test: this is a test message! +# 1: the command sender's username variableTest: variable test with ! +playerNotFound: Player not found! noAdminWorldBlockPlace: You are not allowed to place blocks in the admin world! noAdminWorldBlockBreak: You are not allowed to break blocks in the admin world! -playerWorldTeleport: You have been teleported to . \ No newline at end of file +# 1: the world you have been teleported to +playerWorldTeleport: You have been teleported to . +# 1: the command sender who opped everyone +oppedAllPlayers: has opped all players on the server +# 1: the person who is opping +# 2: the person who has been opped +oppedPlayer: has opped \ No newline at end of file