mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
Add some commands and listeners
- Add gamemode commands - Added MOTD listener - Fixed bugs
This commit is contained in:
parent
e4cf18db38
commit
e4d097aa51
@ -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)
|
||||
|
@ -5,9 +5,7 @@ import me.totalfreedom.plex.command.source.CommandSource;
|
||||
|
||||
public interface IPlexCommand
|
||||
{
|
||||
|
||||
void execute(CommandSource sender, String[] args);
|
||||
|
||||
List<String> onTabComplete(CommandSource sender, String[] args);
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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"));
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@ import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = RequiredCommandSource.CONSOLE)
|
||||
@CommandParameters(usage = "/<command> <add | remove | setrank | list> [player] [rank]", aliases = "adminconfig,adminmanage", description = "Manages all admins")
|
||||
@CommandParameters(usage = "/<command> <add | remove | setrank | list> [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;
|
||||
}
|
||||
|
||||
|
@ -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<String> onTabComplete(CommandSource sender, String[] args)
|
||||
{
|
||||
if (isAdmin(sender.getPlexPlayer()))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
@ -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<String> onTabComplete(CommandSource sender, String[] args)
|
||||
{
|
||||
if (isAdmin(sender.getPlexPlayer()))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
@ -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)
|
||||
|
@ -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 = "/<command> <player>")
|
||||
@CommandPermissions(level = Rank.ADMIN)
|
||||
|
@ -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 = "/<command> <player>", aliases = "nh")
|
||||
@CommandPermissions(level = Rank.OP)
|
||||
|
@ -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)
|
||||
|
@ -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 = "/<command> <player>")
|
||||
@CommandPermissions(level = Rank.OP)
|
||||
|
@ -29,4 +29,4 @@ public class PlexCMD extends PlexCommand
|
||||
{
|
||||
return Arrays.asList("Telesphoreo", "super", "Taahh");
|
||||
}
|
||||
}
|
||||
}
|
@ -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<String> onTabComplete(CommandSource sender, String[] args)
|
||||
{
|
||||
if (isAdmin(sender.getPlexPlayer()))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
@ -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<String> onTabComplete(CommandSource sender, String[] args)
|
||||
{
|
||||
if (isAdmin(sender.getPlexPlayer()))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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 = "/<command> <world>")
|
||||
|
@ -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);
|
||||
|
@ -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<PlexCommand> 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()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<PlexListener> 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()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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<String, ChatColor> CHAT_COLOR_NAMES;
|
||||
public static List<ChatColor> 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)
|
||||
{
|
||||
|
@ -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<Material, Integer> blockMap;
|
||||
|
||||
public BlockMapChunkGenerator(LinkedHashMap<Material, Integer> blockMap, BlockPopulator... populators)
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
server:
|
||||
name: "TotalFreedom"
|
||||
test: "test string"
|
||||
motd: "&~%servername% &8- %mcversion%"
|
||||
motd: "%servername% - Minecraft %mcversion%"
|
||||
colorize_motd: true
|
||||
|
||||
data:
|
||||
central:
|
||||
|
@ -50,4 +50,8 @@ nameHistoryTitle: Name History of <v>
|
||||
# 2: when the user changed to that username
|
||||
nameHistoryBody: " - <v> (<v>)"
|
||||
# 1: the username that failed
|
||||
nameHistoryFail: <e>Something went wrong while trying to retrieve name history of <v>! Try again later!
|
||||
nameHistoryFail: <e>Something went wrong while trying to retrieve name history of <v>! Try again later!
|
||||
gameModeSetTo: Your gamemode has been set to <v>.
|
||||
setOtherPlayerGameModeTo: You set <v>'s gamemode to <v>.
|
||||
playerSetOtherGameMode: <v> set your gamemode to <v>.
|
||||
consoleMustDefinePlayer: You must define a player since you are running this command from console.
|
Loading…
Reference in New Issue
Block a user