2015-10-19 17:43:46 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.commands;
|
2013-08-12 02:02:18 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
|
|
|
import me.totalfreedom.totalfreedommod.world.WorldTime;
|
|
|
|
import me.totalfreedom.totalfreedommod.world.WorldWeather;
|
2013-08-22 00:07:14 +00:00
|
|
|
import org.bukkit.World;
|
2013-08-12 02:02:18 +00:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
@CommandPermissions(level = PlayerRank.OP, source = SourceType.BOTH)
|
2013-08-23 18:43:58 +00:00
|
|
|
@CommandParameters(description = "Go to the AdminWorld.", usage = "/<command> [guest < list | purge | add <player> | remove <player> > | time <morning | noon | evening | night> | weather <off | on | storm>]")
|
2015-10-19 17:43:46 +00:00
|
|
|
public class Command_adminworld extends FreedomCommand
|
2013-08-12 02:02:18 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
|
2013-08-15 21:40:35 +00:00
|
|
|
private enum CommandMode
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
|
2014-06-22 15:53:50 +00:00
|
|
|
TELEPORT, GUEST, TIME, WEATHER;
|
2013-08-15 21:40:35 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 02:02:18 +00:00
|
|
|
@Override
|
|
|
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
|
|
{
|
2013-08-15 21:40:35 +00:00
|
|
|
CommandMode commandMode = null;
|
|
|
|
|
|
|
|
if (args.length == 0)
|
|
|
|
{
|
|
|
|
commandMode = CommandMode.TELEPORT;
|
|
|
|
}
|
|
|
|
else if (args.length >= 2)
|
2013-08-12 16:51:30 +00:00
|
|
|
{
|
2013-08-15 21:40:35 +00:00
|
|
|
if ("guest".equalsIgnoreCase(args[0]))
|
|
|
|
{
|
|
|
|
commandMode = CommandMode.GUEST;
|
|
|
|
}
|
|
|
|
else if ("time".equalsIgnoreCase(args[0]))
|
|
|
|
{
|
|
|
|
commandMode = CommandMode.TIME;
|
|
|
|
}
|
2013-08-17 01:36:25 +00:00
|
|
|
else if ("weather".equalsIgnoreCase(args[0]))
|
|
|
|
{
|
|
|
|
commandMode = CommandMode.WEATHER;
|
|
|
|
}
|
2013-08-12 16:51:30 +00:00
|
|
|
}
|
2013-08-15 21:40:35 +00:00
|
|
|
|
|
|
|
if (commandMode == null)
|
2013-08-12 16:51:30 +00:00
|
|
|
{
|
2013-08-15 21:40:35 +00:00
|
|
|
return false;
|
2013-08-12 16:51:30 +00:00
|
|
|
}
|
2013-08-15 21:40:35 +00:00
|
|
|
|
2013-08-23 18:43:58 +00:00
|
|
|
try
|
2013-08-15 21:40:35 +00:00
|
|
|
{
|
2013-08-23 18:43:58 +00:00
|
|
|
switch (commandMode)
|
2013-08-15 21:40:35 +00:00
|
|
|
{
|
2013-08-23 18:43:58 +00:00
|
|
|
case TELEPORT:
|
2013-08-22 00:07:14 +00:00
|
|
|
{
|
2013-08-23 20:59:31 +00:00
|
|
|
if (!(sender instanceof Player) || sender_p == null)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-23 18:43:58 +00:00
|
|
|
World adminWorld = null;
|
|
|
|
try
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
adminWorld = plugin.wm.adminworld.getWorld();
|
2013-08-23 18:43:58 +00:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
}
|
2013-08-15 21:40:35 +00:00
|
|
|
|
2013-08-23 18:43:58 +00:00
|
|
|
if (adminWorld == null || sender_p.getWorld() == adminWorld)
|
2013-08-15 21:40:35 +00:00
|
|
|
{
|
2013-08-23 18:43:58 +00:00
|
|
|
playerMsg("Going to the main world.");
|
|
|
|
sender_p.teleport(server.getWorlds().get(0).getSpawnLocation());
|
2013-08-15 21:40:35 +00:00
|
|
|
}
|
2013-08-23 18:43:58 +00:00
|
|
|
else
|
2013-08-22 19:26:12 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
if (plugin.wm.adminworld.canAccessWorld(sender_p))
|
2013-08-23 20:59:31 +00:00
|
|
|
{
|
|
|
|
playerMsg("Going to the AdminWorld.");
|
2015-10-19 17:43:46 +00:00
|
|
|
plugin.wm.adminworld.sendToWorld(sender_p);
|
2013-08-23 20:59:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
playerMsg("You don't have permission to access the AdminWorld.");
|
|
|
|
}
|
2013-08-22 19:26:12 +00:00
|
|
|
}
|
|
|
|
|
2013-08-23 18:43:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GUEST:
|
|
|
|
{
|
|
|
|
if (args.length == 2)
|
2013-08-15 21:40:35 +00:00
|
|
|
{
|
2013-08-23 18:43:58 +00:00
|
|
|
if ("list".equalsIgnoreCase(args[1]))
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
playerMsg("AdminWorld guest list: " + plugin.wm.adminworld.guestListToString());
|
2013-08-23 18:43:58 +00:00
|
|
|
}
|
|
|
|
else if ("purge".equalsIgnoreCase(args[1]))
|
|
|
|
{
|
|
|
|
assertCommandPerms(sender, sender_p);
|
2015-10-19 17:43:46 +00:00
|
|
|
plugin.wm.adminworld.purgeGuestList();
|
|
|
|
FUtil.adminAction(sender.getName(), "AdminWorld guest list purged.", false);
|
2013-08-23 18:43:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-08-15 21:40:35 +00:00
|
|
|
}
|
2013-08-23 18:43:58 +00:00
|
|
|
else if (args.length == 3)
|
2013-08-15 21:40:35 +00:00
|
|
|
{
|
2013-08-23 18:43:58 +00:00
|
|
|
assertCommandPerms(sender, sender_p);
|
|
|
|
|
|
|
|
if ("add".equalsIgnoreCase(args[1]))
|
|
|
|
{
|
2014-04-26 11:55:24 +00:00
|
|
|
final Player player = getPlayer(args[2]);
|
|
|
|
|
|
|
|
if (player == null)
|
2013-08-23 18:43:58 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
|
2013-08-23 18:43:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-08-23 20:29:46 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
if (plugin.wm.adminworld.addGuest(player, sender_p))
|
2013-08-23 20:29:46 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FUtil.adminAction(sender.getName(), "AdminWorld guest added: " + player.getName(), false);
|
2013-08-23 20:29:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
playerMsg("Could not add player to guest list.");
|
|
|
|
}
|
2013-08-23 18:43:58 +00:00
|
|
|
}
|
2014-05-05 13:31:12 +00:00
|
|
|
else if ("remove".equals(args[1]))
|
2013-08-23 18:43:58 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
final Player player = plugin.wm.adminworld.removeGuest(args[2]);
|
2013-08-23 18:43:58 +00:00
|
|
|
if (player != null)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FUtil.adminAction(sender.getName(), "AdminWorld guest removed: " + player.getName(), false);
|
2013-08-23 18:43:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
playerMsg("Can't find guest entry for: " + args[2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-08-15 21:40:35 +00:00
|
|
|
}
|
2013-08-23 18:43:58 +00:00
|
|
|
|
|
|
|
break;
|
2013-08-15 21:40:35 +00:00
|
|
|
}
|
2013-08-23 18:43:58 +00:00
|
|
|
case TIME:
|
|
|
|
{
|
|
|
|
assertCommandPerms(sender, sender_p);
|
2013-08-15 21:40:35 +00:00
|
|
|
|
2013-08-23 18:43:58 +00:00
|
|
|
if (args.length == 2)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
WorldTime timeOfDay = WorldTime.getByAlias(args[1]);
|
2013-08-24 01:22:13 +00:00
|
|
|
if (timeOfDay != null)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
plugin.wm.adminworld.setTimeOfDay(timeOfDay);
|
2013-08-24 01:22:13 +00:00
|
|
|
playerMsg("AdminWorld time set to: " + timeOfDay.name());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
playerMsg("Invalid time of day. Can be: sunrise, noon, sunset, midnight");
|
|
|
|
}
|
2013-08-23 18:43:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-08-22 19:26:12 +00:00
|
|
|
|
2013-08-23 18:43:58 +00:00
|
|
|
break;
|
2013-08-15 21:40:35 +00:00
|
|
|
}
|
2013-08-23 18:43:58 +00:00
|
|
|
case WEATHER:
|
|
|
|
{
|
|
|
|
assertCommandPerms(sender, sender_p);
|
2013-08-15 21:40:35 +00:00
|
|
|
|
2013-08-23 18:43:58 +00:00
|
|
|
if (args.length == 2)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
WorldWeather weatherMode = WorldWeather.getByAlias(args[1]);
|
2013-08-24 01:22:13 +00:00
|
|
|
if (weatherMode != null)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
plugin.wm.adminworld.setWeatherMode(weatherMode);
|
2013-08-24 01:22:13 +00:00
|
|
|
playerMsg("AdminWorld weather set to: " + weatherMode.name());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
playerMsg("Invalid weather mode. Can be: off, rain, storm");
|
|
|
|
}
|
2013-08-23 18:43:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-08-22 19:26:12 +00:00
|
|
|
|
2013-08-23 18:43:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2013-08-17 01:36:25 +00:00
|
|
|
{
|
2013-08-23 18:43:58 +00:00
|
|
|
return false;
|
2013-08-17 01:36:25 +00:00
|
|
|
}
|
2013-08-15 21:40:35 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-23 18:43:58 +00:00
|
|
|
catch (PermissionDeniedException ex)
|
|
|
|
{
|
|
|
|
sender.sendMessage(ex.getMessage());
|
|
|
|
}
|
2013-08-15 21:40:35 +00:00
|
|
|
|
2013-08-12 02:02:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-08-23 18:43:58 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
// TODO: Redo this properly
|
2013-08-23 18:43:58 +00:00
|
|
|
private void assertCommandPerms(CommandSender sender, Player sender_p) throws PermissionDeniedException
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
if (!(sender instanceof Player) || sender_p == null || !isAdmin(sender))
|
2013-08-23 18:43:58 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
throw new PermissionDeniedException(FreedomCommand.MSG_NO_PERMS);
|
2013-08-23 18:43:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class PermissionDeniedException extends Exception
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
|
2014-06-22 15:53:50 +00:00
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
|
|
private PermissionDeniedException(String string)
|
2013-08-23 18:43:58 +00:00
|
|
|
{
|
|
|
|
super(string);
|
|
|
|
}
|
|
|
|
}
|
2015-10-19 17:43:46 +00:00
|
|
|
|
2013-08-12 02:02:18 +00:00
|
|
|
}
|