diff --git a/src/main/java/me/totalfreedom/plex/cache/DataUtils.java b/src/main/java/me/totalfreedom/plex/cache/DataUtils.java index 142c36d..2e70789 100644 --- a/src/main/java/me/totalfreedom/plex/cache/DataUtils.java +++ b/src/main/java/me/totalfreedom/plex/cache/DataUtils.java @@ -4,10 +4,10 @@ import java.util.UUID; import me.totalfreedom.plex.Plex; import me.totalfreedom.plex.player.PlexPlayer; import me.totalfreedom.plex.storage.StorageType; +import org.bukkit.Bukkit; public class DataUtils { - public static boolean hasPlayedBefore(UUID uuid) { if (Plex.get().getStorageType() == StorageType.MONGO) @@ -37,6 +37,11 @@ public class DataUtils } } + public static PlexPlayer getPlayer(String name) + { + return getPlayer(Bukkit.getPlayer(name).getUniqueId()); + } + public static void update(PlexPlayer plexPlayer) { if (Plex.get().getStorageType() == StorageType.MONGO) diff --git a/src/main/java/me/totalfreedom/plex/command/IPlexCommand.java b/src/main/java/me/totalfreedom/plex/command/IPlexCommand.java index 5f37245..624d726 100644 --- a/src/main/java/me/totalfreedom/plex/command/IPlexCommand.java +++ b/src/main/java/me/totalfreedom/plex/command/IPlexCommand.java @@ -5,9 +5,7 @@ import me.totalfreedom.plex.command.source.CommandSource; public interface IPlexCommand { - void execute(CommandSource sender, String[] args); List onTabComplete(CommandSource sender, String[] args); - } diff --git a/src/main/java/me/totalfreedom/plex/command/PlexCommand.java b/src/main/java/me/totalfreedom/plex/command/PlexCommand.java index 41fd009..29288f2 100644 --- a/src/main/java/me/totalfreedom/plex/command/PlexCommand.java +++ b/src/main/java/me/totalfreedom/plex/command/PlexCommand.java @@ -5,6 +5,7 @@ import java.util.Arrays; import java.util.List; import java.util.UUID; import me.totalfreedom.plex.Plex; +import me.totalfreedom.plex.cache.DataUtils; import me.totalfreedom.plex.cache.PlayerCache; import me.totalfreedom.plex.command.annotation.CommandParameters; import me.totalfreedom.plex.command.annotation.CommandPermissions; @@ -16,6 +17,7 @@ import me.totalfreedom.plex.command.source.RequiredCommandSource; import me.totalfreedom.plex.player.PlexPlayer; import me.totalfreedom.plex.rank.enums.Rank; import me.totalfreedom.plex.util.PlexLog; +import me.totalfreedom.plex.util.PlexUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.World; @@ -25,7 +27,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; -import static me.totalfreedom.plex.util.PlexUtils.tl; public abstract class PlexCommand extends Command implements TabExecutor, IPlexCommand { @@ -178,6 +179,27 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC player.sendMessage(s); } + protected boolean isAdmin(PlexPlayer plexPlayer) + { + return Plex.get().getRankManager().isAdmin(plexPlayer); + } + + protected boolean isAdmin(String name) + { + PlexPlayer plexPlayer = DataUtils.getPlayer(name); + return Plex.get().getRankManager().isAdmin(plexPlayer); + } + + protected boolean isConsole() + { + return sender instanceof ConsoleCommandSender; + } + + protected String tl(String s, Object... objects) + { + return PlexUtils.tl(s, objects); + } + protected String usage(String s) { return ChatColor.YELLOW + "Correct Usage: " + ChatColor.GRAY + s; diff --git a/src/main/java/me/totalfreedom/plex/command/exception/ConsoleMustDefinePlayerException.java b/src/main/java/me/totalfreedom/plex/command/exception/ConsoleMustDefinePlayerException.java new file mode 100644 index 0000000..eda08ed --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/command/exception/ConsoleMustDefinePlayerException.java @@ -0,0 +1,11 @@ +package me.totalfreedom.plex.command.exception; + +import static me.totalfreedom.plex.util.PlexUtils.tl; + +public class ConsoleMustDefinePlayerException extends RuntimeException +{ + public ConsoleMustDefinePlayerException() + { + super(tl("consoleMustDefinePlayer")); + } +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/command/impl/AdminCMD.java b/src/main/java/me/totalfreedom/plex/command/impl/AdminCMD.java index ff4fcb8..8c4dfa6 100644 --- a/src/main/java/me/totalfreedom/plex/command/impl/AdminCMD.java +++ b/src/main/java/me/totalfreedom/plex/command/impl/AdminCMD.java @@ -20,7 +20,7 @@ import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; @CommandPermissions(level = Rank.SENIOR_ADMIN, source = RequiredCommandSource.CONSOLE) -@CommandParameters(usage = "/ [player] [rank]", aliases = "adminconfig,adminmanage", description = "Manages all admins") +@CommandParameters(usage = "/ [player] [rank]", aliases = "saconfig,slconfig,adminconfig,adminmanage", description = "Manage all admins") public class AdminCMD extends PlexCommand { public AdminCMD() @@ -49,7 +49,7 @@ public class AdminCMD extends PlexCommand if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID)) { - sender.send(PlexUtils.tl("playerNotFound")); + sender.send(tl("playerNotFound")); return; } PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID); @@ -70,7 +70,7 @@ public class AdminCMD extends PlexCommand if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID)) { - sender.send(PlexUtils.tl("playerNotFound")); + sender.send(tl("playerNotFound")); return; } PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID); @@ -92,7 +92,7 @@ public class AdminCMD extends PlexCommand if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID)) { - sender.send(PlexUtils.tl("playerNotFound")); + sender.send(tl("playerNotFound")); return; } diff --git a/src/main/java/me/totalfreedom/plex/command/impl/AdventureCMD.java b/src/main/java/me/totalfreedom/plex/command/impl/AdventureCMD.java new file mode 100644 index 0000000..ab5aeb7 --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/command/impl/AdventureCMD.java @@ -0,0 +1,71 @@ +package me.totalfreedom.plex.command.impl; + +import java.util.Collections; +import java.util.List; +import me.totalfreedom.plex.command.PlexCommand; +import me.totalfreedom.plex.command.annotation.CommandParameters; +import me.totalfreedom.plex.command.annotation.CommandPermissions; +import me.totalfreedom.plex.command.exception.CommandFailException; +import me.totalfreedom.plex.command.source.CommandSource; +import me.totalfreedom.plex.command.source.RequiredCommandSource; +import me.totalfreedom.plex.rank.enums.Rank; +import me.totalfreedom.plex.util.PlexUtils; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.entity.Player; + +@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY) +@CommandParameters(aliases = "gma", description = "Set your own or another player's gamemode to adventure mode") +public class AdventureCMD extends PlexCommand +{ + public AdventureCMD() + { + super("adventure"); + } + + @Override + public void execute(CommandSource sender, String[] args) + { + if (args.length == 0) + { + // doesn't work + if (isConsole()) + { + throw new CommandFailException("You must define a player when using the console!"); + } + + sender.getPlayer().setGameMode(GameMode.ADVENTURE); + send(tl("gameModeSetTo", "adventure")); + return; + } + + if (isAdmin(sender.getPlexPlayer())) + { + if (args[0].equals("-a")) + { + for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers()) + { + targetPlayer.setGameMode(GameMode.ADVENTURE); + } + send(tl("gameModeSetTo", "adventure")); + return; + } + + Player player = getNonNullPlayer(args[0]); + send(tl("setOtherPlayerGameModeTo", player.getName(), "adventure")); + // use send + player.sendMessage(tl("playerSetOtherGameMode", sender.getName(), "adventure")); + player.setGameMode(GameMode.ADVENTURE); + } + } + + @Override + public List onTabComplete(CommandSource sender, String[] args) + { + if (isAdmin(sender.getPlexPlayer())) + { + return PlexUtils.getPlayerNameList(); + } + return Collections.emptyList(); + } +} diff --git a/src/main/java/me/totalfreedom/plex/command/impl/CreativeCMD.java b/src/main/java/me/totalfreedom/plex/command/impl/CreativeCMD.java new file mode 100644 index 0000000..e76b1a0 --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/command/impl/CreativeCMD.java @@ -0,0 +1,70 @@ +package me.totalfreedom.plex.command.impl; + +import java.util.Collections; +import java.util.List; +import me.totalfreedom.plex.command.PlexCommand; +import me.totalfreedom.plex.command.annotation.CommandParameters; +import me.totalfreedom.plex.command.annotation.CommandPermissions; +import me.totalfreedom.plex.command.exception.CommandFailException; +import me.totalfreedom.plex.command.source.CommandSource; +import me.totalfreedom.plex.command.source.RequiredCommandSource; +import me.totalfreedom.plex.rank.enums.Rank; +import me.totalfreedom.plex.util.PlexUtils; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.entity.Player; + +@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY) +@CommandParameters(aliases = "gmc", description = "Set your own or another player's gamemode to creative mode") +public class CreativeCMD extends PlexCommand +{ + public CreativeCMD() + { + super("creative"); + } + + @Override + public void execute(CommandSource sender, String[] args) + { + if (args.length == 0) + { + // doesn't work + if (isConsole()) + { + throw new CommandFailException("You must define a player when using the console!"); + } + + sender.getPlayer().setGameMode(GameMode.CREATIVE); + send(tl("gameModeSetTo", "creative")); + return; + } + + if (isAdmin(sender.getPlexPlayer())) + { + if (args[0].equals("-a")) + { + for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers()) + { + targetPlayer.setGameMode(GameMode.CREATIVE); + } + send(tl("gameModeSetTo", "creative")); + return; + } + + Player player = getNonNullPlayer(args[0]); + send(tl("setOtherPlayerGameModeTo", player.getName(), "creative")); + player.sendMessage(tl("playerSetOtherGameMode", sender.getName(), "creative")); + player.setGameMode(GameMode.CREATIVE); + } + } + + @Override + public List onTabComplete(CommandSource sender, String[] args) + { + if (isAdmin(sender.getPlexPlayer())) + { + return PlexUtils.getPlayerNameList(); + } + return Collections.emptyList(); + } +} diff --git a/src/main/java/me/totalfreedom/plex/command/impl/FionnCMD.java b/src/main/java/me/totalfreedom/plex/command/impl/FionnCMD.java index 3cbcd87..ff2ac7b 100644 --- a/src/main/java/me/totalfreedom/plex/command/impl/FionnCMD.java +++ b/src/main/java/me/totalfreedom/plex/command/impl/FionnCMD.java @@ -27,7 +27,6 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.entity.Strider; import org.bukkit.scheduler.BukkitRunnable; -import static me.totalfreedom.plex.util.PlexUtils.tl; @CommandParameters(description = "Subliminal message.") @CommandPermissions(source = RequiredCommandSource.IN_GAME) diff --git a/src/main/java/me/totalfreedom/plex/command/impl/FreezeCMD.java b/src/main/java/me/totalfreedom/plex/command/impl/FreezeCMD.java index 0df2ac5..96ed3e8 100644 --- a/src/main/java/me/totalfreedom/plex/command/impl/FreezeCMD.java +++ b/src/main/java/me/totalfreedom/plex/command/impl/FreezeCMD.java @@ -12,7 +12,6 @@ import me.totalfreedom.plex.player.PunishedPlayer; import me.totalfreedom.plex.rank.enums.Rank; import me.totalfreedom.plex.util.PlexUtils; import org.bukkit.entity.Player; -import static me.totalfreedom.plex.util.PlexUtils.tl; @CommandParameters(description = "Freeze/unfreeze a player on the server", usage = "/ ") @CommandPermissions(level = Rank.ADMIN) diff --git a/src/main/java/me/totalfreedom/plex/command/impl/NameHistoryCMD.java b/src/main/java/me/totalfreedom/plex/command/impl/NameHistoryCMD.java index 3f33348..1c24c3b 100644 --- a/src/main/java/me/totalfreedom/plex/command/impl/NameHistoryCMD.java +++ b/src/main/java/me/totalfreedom/plex/command/impl/NameHistoryCMD.java @@ -15,7 +15,6 @@ import me.totalfreedom.plex.util.PlexUtils; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.ParseException; -import static me.totalfreedom.plex.util.PlexUtils.tl; @CommandParameters(description = "Get the name history of a player", usage = "/ ", aliases = "nh") @CommandPermissions(level = Rank.OP) diff --git a/src/main/java/me/totalfreedom/plex/command/impl/OpAllCMD.java b/src/main/java/me/totalfreedom/plex/command/impl/OpAllCMD.java index bd45232..24653f9 100644 --- a/src/main/java/me/totalfreedom/plex/command/impl/OpAllCMD.java +++ b/src/main/java/me/totalfreedom/plex/command/impl/OpAllCMD.java @@ -10,7 +10,6 @@ import me.totalfreedom.plex.rank.enums.Rank; import me.totalfreedom.plex.util.PlexUtils; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import static me.totalfreedom.plex.util.PlexUtils.tl; @CommandParameters(description = "Op everyone on the server", aliases = "opa") @CommandPermissions(level = Rank.ADMIN) diff --git a/src/main/java/me/totalfreedom/plex/command/impl/OpCMD.java b/src/main/java/me/totalfreedom/plex/command/impl/OpCMD.java index 26471ed..68482ee 100644 --- a/src/main/java/me/totalfreedom/plex/command/impl/OpCMD.java +++ b/src/main/java/me/totalfreedom/plex/command/impl/OpCMD.java @@ -10,7 +10,6 @@ import me.totalfreedom.plex.command.source.CommandSource; import me.totalfreedom.plex.rank.enums.Rank; import me.totalfreedom.plex.util.PlexUtils; import org.bukkit.entity.Player; -import static me.totalfreedom.plex.util.PlexUtils.tl; @CommandParameters(description = "Op a player on the server", usage = "/ ") @CommandPermissions(level = Rank.OP) diff --git a/src/main/java/me/totalfreedom/plex/command/impl/PlexCMD.java b/src/main/java/me/totalfreedom/plex/command/impl/PlexCMD.java index 7c6c7b8..a62aaf9 100644 --- a/src/main/java/me/totalfreedom/plex/command/impl/PlexCMD.java +++ b/src/main/java/me/totalfreedom/plex/command/impl/PlexCMD.java @@ -29,4 +29,4 @@ public class PlexCMD extends PlexCommand { return Arrays.asList("Telesphoreo", "super", "Taahh"); } -} +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/command/impl/SpectatorCMD.java b/src/main/java/me/totalfreedom/plex/command/impl/SpectatorCMD.java new file mode 100644 index 0000000..4ae6901 --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/command/impl/SpectatorCMD.java @@ -0,0 +1,67 @@ +package me.totalfreedom.plex.command.impl; + +import java.util.Collections; +import java.util.List; +import me.totalfreedom.plex.command.PlexCommand; +import me.totalfreedom.plex.command.annotation.CommandParameters; +import me.totalfreedom.plex.command.annotation.CommandPermissions; +import me.totalfreedom.plex.command.exception.CommandFailException; +import me.totalfreedom.plex.command.source.CommandSource; +import me.totalfreedom.plex.command.source.RequiredCommandSource; +import me.totalfreedom.plex.rank.enums.Rank; +import me.totalfreedom.plex.util.PlexUtils; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.entity.Player; + +@CommandPermissions(level = Rank.ADMIN, source = RequiredCommandSource.ANY) +@CommandParameters(aliases = "gmsp", description = "Set your own or another player's gamemode to spectator mode") +public class SpectatorCMD extends PlexCommand +{ + public SpectatorCMD() + { + super("spectator"); + } + + @Override + public void execute(CommandSource sender, String[] args) + { + if (args.length == 0) + { + // doesn't work + if (isConsole()) + { + throw new CommandFailException("You must define a player when using the console!"); + } + + sender.getPlayer().setGameMode(GameMode.SPECTATOR); + send(tl("gameModeSetTo", "spectator")); + return; + } + + if (args[0].equals("-a")) + { + for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers()) + { + targetPlayer.setGameMode(GameMode.SPECTATOR); + } + send(tl("gameModeSetTo", "spectator")); + return; + } + + Player player = getNonNullPlayer(args[0]); + send(tl("setOtherPlayerGameModeTo", player.getName(), "spectator")); + player.sendMessage(tl("playerSetOtherGameMode", sender.getName(), "spectator")); + player.setGameMode(GameMode.SPECTATOR); + } + + @Override + public List onTabComplete(CommandSource sender, String[] args) + { + if (isAdmin(sender.getPlexPlayer())) + { + return PlexUtils.getPlayerNameList(); + } + return Collections.emptyList(); + } +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/command/impl/SurvivalCMD.java b/src/main/java/me/totalfreedom/plex/command/impl/SurvivalCMD.java new file mode 100644 index 0000000..21e0b36 --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/command/impl/SurvivalCMD.java @@ -0,0 +1,70 @@ +package me.totalfreedom.plex.command.impl; + +import java.util.Collections; +import java.util.List; +import me.totalfreedom.plex.command.PlexCommand; +import me.totalfreedom.plex.command.annotation.CommandParameters; +import me.totalfreedom.plex.command.annotation.CommandPermissions; +import me.totalfreedom.plex.command.exception.CommandFailException; +import me.totalfreedom.plex.command.source.CommandSource; +import me.totalfreedom.plex.command.source.RequiredCommandSource; +import me.totalfreedom.plex.rank.enums.Rank; +import me.totalfreedom.plex.util.PlexUtils; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.entity.Player; + +@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY) +@CommandParameters(aliases = "gms", description = "Set your own or another player's gamemode to survival mode") +public class SurvivalCMD extends PlexCommand +{ + public SurvivalCMD() + { + super("survival"); + } + + @Override + public void execute(CommandSource sender, String[] args) + { + if (args.length == 0) + { + // doesn't work + if (isConsole()) + { + throw new CommandFailException("You must define a player when using the console!"); + } + + sender.getPlayer().setGameMode(GameMode.SURVIVAL); + send(tl("gameModeSetTo", "survival")); + return; + } + + if (isAdmin(sender.getPlexPlayer())) + { + if (args[0].equals("-a")) + { + for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers()) + { + targetPlayer.setGameMode(GameMode.SURVIVAL); + } + send(tl("gameModeSetTo", "survival")); + return; + } + + Player player = getNonNullPlayer(args[0]); + send(tl("setOtherPlayerGameModeTo", player.getName(), "survival")); + player.sendMessage(tl("playerSetOtherGameMode", sender.getName(), "survival")); + player.setGameMode(GameMode.SURVIVAL); + } + } + + @Override + public List onTabComplete(CommandSource sender, String[] args) + { + if (isAdmin(sender.getPlexPlayer())) + { + return PlexUtils.getPlayerNameList(); + } + return Collections.emptyList(); + } +} diff --git a/src/main/java/me/totalfreedom/plex/command/impl/TestCMD.java b/src/main/java/me/totalfreedom/plex/command/impl/TestCMD.java index d111db2..4f3e391 100644 --- a/src/main/java/me/totalfreedom/plex/command/impl/TestCMD.java +++ b/src/main/java/me/totalfreedom/plex/command/impl/TestCMD.java @@ -9,7 +9,6 @@ import me.totalfreedom.plex.command.annotation.CommandPermissions; import me.totalfreedom.plex.command.source.CommandSource; import me.totalfreedom.plex.command.source.RequiredCommandSource; import me.totalfreedom.plex.rank.enums.Rank; -import static me.totalfreedom.plex.util.PlexUtils.tl; @CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY) @CommandParameters(aliases = "tst,tast", description = "HELLO") @@ -35,5 +34,4 @@ public class TestCMD extends PlexCommand } return ImmutableList.of(); } - } diff --git a/src/main/java/me/totalfreedom/plex/command/impl/WorldCMD.java b/src/main/java/me/totalfreedom/plex/command/impl/WorldCMD.java index 186adce..2dc2d00 100644 --- a/src/main/java/me/totalfreedom/plex/command/impl/WorldCMD.java +++ b/src/main/java/me/totalfreedom/plex/command/impl/WorldCMD.java @@ -13,7 +13,6 @@ import me.totalfreedom.plex.rank.enums.Rank; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; -import static me.totalfreedom.plex.util.PlexUtils.tl; @CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME) @CommandParameters(description = "Teleport to a world.", usage = "/ ") diff --git a/src/main/java/me/totalfreedom/plex/command/source/CommandSource.java b/src/main/java/me/totalfreedom/plex/command/source/CommandSource.java index dfab73b..3330453 100644 --- a/src/main/java/me/totalfreedom/plex/command/source/CommandSource.java +++ b/src/main/java/me/totalfreedom/plex/command/source/CommandSource.java @@ -10,7 +10,7 @@ import org.bukkit.entity.Player; @Getter public class CommandSource { - private CommandSender sender; + private final CommandSender sender; private final Player player; private final PlexPlayer plexPlayer; @@ -21,6 +21,8 @@ public class CommandSource this.plexPlayer = sender instanceof Player ? PlayerCache.getPlexPlayerMap().get(((Player)sender).getUniqueId()) : null; } + // there's a bug here where it sends it to the player not the console + // i assume this is because there's no checking. no idea why but it always sends it to the player even if executed from the console public void send(String s) { sender.sendMessage(s); diff --git a/src/main/java/me/totalfreedom/plex/handlers/CommandHandler.java b/src/main/java/me/totalfreedom/plex/handlers/CommandHandler.java index cd434f0..f768344 100644 --- a/src/main/java/me/totalfreedom/plex/handlers/CommandHandler.java +++ b/src/main/java/me/totalfreedom/plex/handlers/CommandHandler.java @@ -4,19 +4,22 @@ import com.google.common.collect.Lists; import java.util.List; import me.totalfreedom.plex.command.PlexCommand; import me.totalfreedom.plex.command.impl.AdminCMD; +import me.totalfreedom.plex.command.impl.AdventureCMD; +import me.totalfreedom.plex.command.impl.CreativeCMD; import me.totalfreedom.plex.command.impl.FionnCMD; import me.totalfreedom.plex.command.impl.FreezeCMD; import me.totalfreedom.plex.command.impl.NameHistoryCMD; import me.totalfreedom.plex.command.impl.OpAllCMD; import me.totalfreedom.plex.command.impl.OpCMD; import me.totalfreedom.plex.command.impl.PlexCMD; +import me.totalfreedom.plex.command.impl.SpectatorCMD; +import me.totalfreedom.plex.command.impl.SurvivalCMD; import me.totalfreedom.plex.command.impl.TestCMD; import me.totalfreedom.plex.command.impl.WorldCMD; import me.totalfreedom.plex.util.PlexLog; public class CommandHandler { - private List commands = Lists.newArrayList(); public CommandHandler() @@ -30,8 +33,10 @@ public class CommandHandler commands.add(new FreezeCMD()); commands.add(new NameHistoryCMD()); commands.add(new AdminCMD()); - + commands.add(new AdventureCMD()); + commands.add(new CreativeCMD()); + commands.add(new SurvivalCMD()); + commands.add(new SpectatorCMD()); PlexLog.log(String.format("Registered %s commands!", commands.size())); } - } diff --git a/src/main/java/me/totalfreedom/plex/handlers/ListenerHandler.java b/src/main/java/me/totalfreedom/plex/handlers/ListenerHandler.java index ae117f9..4d50dd9 100644 --- a/src/main/java/me/totalfreedom/plex/handlers/ListenerHandler.java +++ b/src/main/java/me/totalfreedom/plex/handlers/ListenerHandler.java @@ -6,22 +6,21 @@ import me.totalfreedom.plex.listener.PlexListener; import me.totalfreedom.plex.listener.impl.ChatListener; import me.totalfreedom.plex.listener.impl.FreezeListener; import me.totalfreedom.plex.listener.impl.PlayerListener; +import me.totalfreedom.plex.listener.impl.ServerListener; import me.totalfreedom.plex.listener.impl.WorldListener; import me.totalfreedom.plex.util.PlexLog; public class ListenerHandler { - private List listeners = Lists.newArrayList(); public ListenerHandler() { + listeners.add(new ServerListener()); listeners.add(new ChatListener()); listeners.add(new PlayerListener()); listeners.add(new WorldListener()); listeners.add(new FreezeListener()); - PlexLog.log(String.format("Registered %s listeners!", listeners.size())); } - } diff --git a/src/main/java/me/totalfreedom/plex/listener/PlexListener.java b/src/main/java/me/totalfreedom/plex/listener/PlexListener.java index b09ad6b..cddb826 100644 --- a/src/main/java/me/totalfreedom/plex/listener/PlexListener.java +++ b/src/main/java/me/totalfreedom/plex/listener/PlexListener.java @@ -5,10 +5,8 @@ import org.bukkit.event.Listener; public abstract class PlexListener extends PlexBase implements Listener { - public PlexListener() { plugin.getServer().getPluginManager().registerEvents(this, plugin); } - } diff --git a/src/main/java/me/totalfreedom/plex/listener/impl/ServerListener.java b/src/main/java/me/totalfreedom/plex/listener/impl/ServerListener.java new file mode 100644 index 0000000..56346c9 --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/listener/impl/ServerListener.java @@ -0,0 +1,32 @@ +package me.totalfreedom.plex.listener.impl; + +import me.totalfreedom.plex.listener.PlexListener; +import me.totalfreedom.plex.util.PlexUtils; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.server.ServerListPingEvent; + +public class ServerListener extends PlexListener +{ + @EventHandler + public void onServerPing(ServerListPingEvent event) + { + String baseMotd = plugin.config.getString("server.motd"); + baseMotd = baseMotd.replace("\\n", "\n"); + baseMotd = baseMotd.replace("%servername%", plugin.config.getString("server.name")); + baseMotd = baseMotd.replace("%mcversion%", Bukkit.getBukkitVersion().split("-")[0]); + if (plugin.config.getBoolean("server.colorize_motd")) + { + final StringBuilder motd = new StringBuilder(); + for (final String word : baseMotd.split(" ")) + { + motd.append(PlexUtils.randomChatColor()).append(word).append(" "); + } + event.setMotd(motd.toString().trim()); + } + else + { + event.setMotd(baseMotd.trim()); + } + } +} diff --git a/src/main/java/me/totalfreedom/plex/rank/enums/Rank.java b/src/main/java/me/totalfreedom/plex/rank/enums/Rank.java index 3e6ca9b..61d7766 100644 --- a/src/main/java/me/totalfreedom/plex/rank/enums/Rank.java +++ b/src/main/java/me/totalfreedom/plex/rank/enums/Rank.java @@ -7,11 +7,11 @@ import org.bukkit.ChatColor; public enum Rank { IMPOSTOR(-1, ChatColor.AQUA + "an " + ChatColor.YELLOW + "Impostor", ChatColor.YELLOW + "[Imp]"), - NONOP(0, ChatColor.WHITE + "a " + ChatColor.WHITE + "Non-Op", ChatColor.WHITE + ""), - OP(1, ChatColor.GREEN + "an " + ChatColor.GREEN + "Operator", ChatColor.GREEN + "[OP]"), - ADMIN(2, ChatColor.DARK_GREEN + "an " + ChatColor.DARK_GREEN + "Admin", ChatColor.DARK_GREEN + "[Admin]"), - SENIOR_ADMIN(3, ChatColor.GOLD + "a " + ChatColor.GOLD + "Senior Admin", ChatColor.GOLD + "[SrA]"), - EXECUTIVE(4, ChatColor.RED + "an " + ChatColor.RED + "Executive", ChatColor.RED + "[Exec]"); + NONOP(0, "a " + ChatColor.WHITE + "Non-Op", ChatColor.WHITE + ""), + OP(1, "an " + ChatColor.GREEN + "Operator", ChatColor.GREEN + "[OP]"), + ADMIN(2, "an " + ChatColor.DARK_GREEN + "Admin", ChatColor.DARK_GREEN + "[Admin]"), + SENIOR_ADMIN(3, "a " + ChatColor.GOLD + "Senior Admin", ChatColor.GOLD + "[SrA]"), + EXECUTIVE(4, "an " + ChatColor.RED + "Executive", ChatColor.RED + "[Exec]"); private String loginMessage; private String prefix; diff --git a/src/main/java/me/totalfreedom/plex/util/PlexUtils.java b/src/main/java/me/totalfreedom/plex/util/PlexUtils.java index 81c20f9..95cdcc8 100644 --- a/src/main/java/me/totalfreedom/plex/util/PlexUtils.java +++ b/src/main/java/me/totalfreedom/plex/util/PlexUtils.java @@ -7,7 +7,11 @@ import java.net.HttpURLConnection; import java.net.URL; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Random; import java.util.UUID; import java.util.stream.Collectors; import me.totalfreedom.plex.Plex; @@ -28,6 +32,26 @@ import org.json.simple.parser.ParseException; public class PlexUtils { + public static Map CHAT_COLOR_NAMES; + public static List CHAT_COLOR_POOL; + private static Random RANDOM; + + static + { + RANDOM = new Random(); + CHAT_COLOR_NAMES = new HashMap<>(); + CHAT_COLOR_POOL = Arrays.asList(ChatColor.DARK_RED, ChatColor.RED, ChatColor.GOLD, ChatColor.YELLOW, ChatColor.GREEN, ChatColor.DARK_GREEN, ChatColor.AQUA, ChatColor.DARK_AQUA, ChatColor.BLUE, ChatColor.DARK_BLUE, ChatColor.DARK_PURPLE, ChatColor.LIGHT_PURPLE); + for (final ChatColor chatColor : CHAT_COLOR_POOL) + { + CHAT_COLOR_NAMES.put(chatColor.name().toLowerCase().replace("_", ""), chatColor); + } + } + + public static ChatColor randomChatColor() + { + return CHAT_COLOR_POOL.get(RANDOM.nextInt(CHAT_COLOR_POOL.size())); + } + public static void testConnections() { if (Plex.get().getSqlConnection().getCon() != null) @@ -79,6 +103,11 @@ public class PlexUtils return ChatColor.translateAlternateColorCodes('&', s); } + public static String colorize(final String string) + { + return ChatColor.translateAlternateColorCodes('&', string); + } + // if you think the name of this method is dumb feel free to change it i just thought it'd be cool public static String tl(String s, Object... objects) { diff --git a/src/main/java/me/totalfreedom/plex/world/BlockMapChunkGenerator.java b/src/main/java/me/totalfreedom/plex/world/BlockMapChunkGenerator.java index 8c3fff5..7f5f624 100644 --- a/src/main/java/me/totalfreedom/plex/world/BlockMapChunkGenerator.java +++ b/src/main/java/me/totalfreedom/plex/world/BlockMapChunkGenerator.java @@ -2,14 +2,11 @@ package me.totalfreedom.plex.world; import java.util.LinkedHashMap; import java.util.Map; -import me.totalfreedom.plex.Plex; import org.bukkit.Material; import org.bukkit.generator.BlockPopulator; public class BlockMapChunkGenerator extends FlatChunkGenerator { - private static Plex plugin = Plex.get(); - protected LinkedHashMap blockMap; public BlockMapChunkGenerator(LinkedHashMap blockMap, BlockPopulator... populators) diff --git a/src/main/java/me/totalfreedom/plex/world/ConfigurationChunkGenerator.java b/src/main/java/me/totalfreedom/plex/world/ConfigurationChunkGenerator.java index 48ce3fd..badfaad 100644 --- a/src/main/java/me/totalfreedom/plex/world/ConfigurationChunkGenerator.java +++ b/src/main/java/me/totalfreedom/plex/world/ConfigurationChunkGenerator.java @@ -7,7 +7,7 @@ import org.bukkit.generator.BlockPopulator; public class ConfigurationChunkGenerator extends BlockMapChunkGenerator { - private static Plex plugin = Plex.get(); + private static final Plex plugin = Plex.get(); public ConfigurationChunkGenerator(String worldName, BlockPopulator... populators) { diff --git a/src/main/java/me/totalfreedom/plex/world/CustomWorld.java b/src/main/java/me/totalfreedom/plex/world/CustomWorld.java index cb74b78..881a95a 100644 --- a/src/main/java/me/totalfreedom/plex/world/CustomWorld.java +++ b/src/main/java/me/totalfreedom/plex/world/CustomWorld.java @@ -13,7 +13,7 @@ import org.bukkit.generator.ChunkGenerator; public class CustomWorld extends WorldCreator { - private static Plex plugin = Plex.get(); + private static final Plex plugin = Plex.get(); private final CustomChunkGenerator chunks; diff --git a/src/main/java/me/totalfreedom/plex/world/OctaveChunkGenerator.java b/src/main/java/me/totalfreedom/plex/world/OctaveChunkGenerator.java index a2843b3..1fe3db2 100644 --- a/src/main/java/me/totalfreedom/plex/world/OctaveChunkGenerator.java +++ b/src/main/java/me/totalfreedom/plex/world/OctaveChunkGenerator.java @@ -7,7 +7,7 @@ import org.bukkit.util.noise.PerlinOctaveGenerator; public abstract class OctaveChunkGenerator extends CustomChunkGenerator { - private OctaveOptions options; + private final OctaveOptions options; public OctaveChunkGenerator(int height, OctaveOptions options, BlockPopulator... populators) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 1a530b7..7d25d9f 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -2,8 +2,8 @@ server: name: "TotalFreedom" - test: "test string" - motd: "&~%servername% &8- %mcversion%" + motd: "%servername% - Minecraft %mcversion%" + colorize_motd: true data: central: diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index c254fbb..63d2b11 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -50,4 +50,8 @@ nameHistoryTitle: Name History of # 2: when the user changed to that username nameHistoryBody: " - ()" # 1: the username that failed -nameHistoryFail: Something went wrong while trying to retrieve name history of ! Try again later! \ No newline at end of file +nameHistoryFail: Something went wrong while trying to retrieve name history of ! Try again later! +gameModeSetTo: Your gamemode has been set to . +setOtherPlayerGameModeTo: You set 's gamemode to . +playerSetOtherGameMode: set your gamemode to . +consoleMustDefinePlayer: You must define a player since you are running this command from console. \ No newline at end of file