op commands and more messages

This commit is contained in:
Super_ 2020-11-02 15:50:51 -05:00
parent 668488dfd1
commit 3517c05054
5 changed files with 106 additions and 9 deletions

View File

@ -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<String> onTabComplete(CommandSender sender, String[] args) {
return null;
}
}

View File

@ -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 = "/<command> <player>")
@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<String> onTabComplete(CommandSender sender, String[] args) {
return null;
}
}

View File

@ -2,10 +2,7 @@ package me.totalfreedom.plex.handlers;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import me.totalfreedom.plex.command.PlexCommand; import me.totalfreedom.plex.command.PlexCommand;
import me.totalfreedom.plex.command.impl.FionnCMD; import me.totalfreedom.plex.command.impl.*;
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.util.PlexLog; import me.totalfreedom.plex.util.PlexLog;
import java.util.List; import java.util.List;
@ -21,6 +18,8 @@ public class CommandHandler
commands.add(new PlexCMD()); commands.add(new PlexCMD());
commands.add(new FionnCMD()); commands.add(new FionnCMD());
commands.add(new WorldCMD()); commands.add(new WorldCMD());
commands.add(new OpAllCMD());
commands.add(new OpCMD());
PlexLog.log(String.format("Registered %s commands!", commands.size())); PlexLog.log(String.format("Registered %s commands!", commands.size()));
} }

View File

@ -71,17 +71,20 @@ public class PlexUtils
public static String tl(String s, Object... objects) public static String tl(String s, Object... objects)
{ {
Plex plugin = Plex.get(); Plex plugin = Plex.get();
if (s.equals("baseColor") || s.equals("errorColor")) if (s.equals("baseColor") || s.equals("errorColor") || s.equals("broadcastColor"))
return getChatColorFromConfig(plugin.messages, (s.equals("baseColor") ? ChatColor.GRAY : ChatColor.RED), s).toString(); return getChatColorFromConfig(plugin.messages, ChatColor.WHITE, s).toString();
String f = plugin.messages.getString(s); String f = plugin.messages.getString(s);
if (f == null) if (f == null)
return ChatColor.RED + "No message"; return ChatColor.RED + "No message";
for (Object object : objects) for (Object object : objects)
f = f.replace("<v>", String.valueOf(object)); f = f.replace("<v>", String.valueOf(object));
ChatColor base = getChatColorFromConfig(plugin.messages, ChatColor.GRAY, "baseColor"); ChatColor base = getChatColorFromConfig(plugin.messages, ChatColor.GRAY, "baseColor");
ChatColor broadcast = getChatColorFromConfig(plugin.messages, ChatColor.AQUA, "broadcastColor");
ChatColor error = getChatColorFromConfig(plugin.messages, ChatColor.RED, "errorColor"); ChatColor error = getChatColorFromConfig(plugin.messages, ChatColor.RED, "errorColor");
f = f.replaceAll("<r>", base.toString()); f = f.replaceAll("<r>", base.toString());
f = f.replaceAll("<b>", broadcast.toString());
f = f.replaceAll("<e>", error.toString()); f = f.replaceAll("<e>", error.toString());
f = color(f);
return base + f; return base + f;
} }
@ -124,4 +127,9 @@ public class PlexUtils
} }
} }
} }
public static void broadcast(String s)
{
Bukkit.broadcastMessage(s);
}
} }

View File

@ -4,19 +4,31 @@
# Warning: not all commands have customizable messages # Warning: not all commands have customizable messages
# Base color - the main color prefix; will be used following each of the messages below # 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 # Error color - the color of an error; will be used when an error is thrown from a command
baseColor: "7" baseColor: "7"
broadcastColor: "b"
errorColor: "c" errorColor: "c"
# Variables <v> - these are code-defined replacements for things that should be inserted into messages. (e.g. names, statuses, numbers) # Variables <v> - 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. # 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.
# message variables are used in numerical order that is unchangeable from this file. # 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 <r> - this will reset the color of the message to the base color defined above. # Reset color <r> - this will reset the color of the message to the base color defined above.
# Broadcast color <b> - this will make the color of the message the broadcast color defined above.
# Error color <e> - this will make the color of the message the error color defined above. # Error color <e> - this will make the color of the message the error color defined above.
test: this is a test message! test: this is a test message!
# 1: the command sender's username
variableTest: variable test with <v>! variableTest: variable test with <v>!
playerNotFound: Player not found!
noAdminWorldBlockPlace: <e>You are not allowed to place blocks in the admin world! noAdminWorldBlockPlace: <e>You are not allowed to place blocks in the admin world!
noAdminWorldBlockBreak: <e>You are not allowed to break blocks in the admin world! noAdminWorldBlockBreak: <e>You are not allowed to break blocks in the admin world!
playerWorldTeleport: You have been teleported to <v>. # 1: the world you have been teleported to
playerWorldTeleport: You have been teleported to <v>.
# 1: the command sender who opped everyone
oppedAllPlayers: <b><v> has opped all players on the server
# 1: the person who is opping
# 2: the person who has been opped
oppedPlayer: <v> has opped <v>