public PlayerState(final Player player) { name = player.getName(); debug.i("creating PlayerState of " + name, player); fireticks = player.getFireTicks(); foodlevel = player.getFoodLevel(); gamemode = player.getGameMode().getValue(); health = player.getHealth(); maxhealth = player.getMaxHealth(); exhaustion = player.getExhaustion(); experience = player.getExp(); explevel = player.getLevel(); saturation = player.getSaturation(); potionEffects = player.getActivePotionEffects(); flying = player.isFlying(); final ArenaPlayer aPlayer = ArenaPlayer.parsePlayer(player.getName()); final Arena arena = aPlayer.getArena(); if (arena.getArenaConfig().getBoolean(CFG.CHAT_COLORNICK)) { displayname = player.getDisplayName(); } fullReset(arena, player); final int time = arena.getArenaConfig().getInt(CFG.GENERAL_TIME); if (time != -1) { player.setPlayerTime(time, false); } }
@Override public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) { if (cmd.getName().equals("playertime")) { if (!plugin.isAuthorized(cs, "rcmds.playertime")) { RUtils.dispNoPerms(cs); return true; } if (args.length < 1) { cs.sendMessage(cmd.getDescription()); return false; } Player t = plugin.getServer().getPlayer(args[0]); if (t == null || plugin.isVanished(t, cs)) { cs.sendMessage(ChatColor.RED + "That player does not exist!"); return true; } String possessive = (t.getName().toLowerCase().endsWith("s")) ? "'" : "'s"; Integer time = null; if (args.length > 1) { try { time = Integer.valueOf(args[1]); } catch (Exception e) { cs.sendMessage(ChatColor.RED + "That time was invalid!"); return true; } } if (time == null) { t.resetPlayerTime(); cs.sendMessage( ChatColor.BLUE + "Synced " + ChatColor.GRAY + t.getName() + possessive + ChatColor.BLUE + " time with the server's."); return true; } if (plugin.smoothTime) smoothPlayerTimeChange(time, t); t.setPlayerTime(time, true); cs.sendMessage( ChatColor.BLUE + "Set " + ChatColor.GRAY + t.getName() + possessive + ChatColor.BLUE + " time to " + ChatColor.GRAY + time + " ticks" + ChatColor.BLUE + "."); return true; } return false; }
@Command( aliases = {"playertime"}, usage = "[filter] <time|\"current\">", desc = "Get/change a player's time", flags = "rsw", min = 0, max = 2) public void playertime(CommandContext args, CommandSender sender) throws CommandException { Iterable<Player> players = null; String timeStr = "current"; boolean included = false; boolean reset = args.hasFlag('r'); if (args.argsLength() < 2) { if (args.argsLength() == 1) { timeStr = args.getString(0); if (reset) { players = PlayerUtil.matchPlayers(sender, timeStr); } } if (players == null) { players = PlayerUtil.matchPlayers(PlayerUtil.checkPlayer(sender)); } } else { players = PlayerUtil.matchPlayers(sender, args.getString(0)); timeStr = args.getString(1); } for (Player player : players) { if (player != sender) { CommandBook.inst().checkPermission(sender, "commandbook.time.player.other"); break; } else { CommandBook.inst().checkPermission(sender, "commandbook.time.player"); } } if (args.hasFlag('r')) { for (Player player : players) { player.resetPlayerTime(); if (!args.hasFlag('s')) { player.sendMessage(ChatColor.YELLOW + "Your time was reset to world time"); } if (sender instanceof Player && sender.equals(player)) { included = true; } } if (!included) { sender.sendMessage(ChatColor.YELLOW + "Player times reset"); } return; } if (timeStr.equalsIgnoreCase("current") || timeStr.equalsIgnoreCase("cur") || timeStr.equalsIgnoreCase("now")) { CommandBook.inst().checkPermission(sender, "commandbook.time.player.check"); sender.sendMessage( ChatColor.YELLOW + "Player Time: " + CommandBookUtil.getTimeString( PlayerUtil.matchSinglePlayer( sender, args.getString(0, PlayerUtil.checkPlayer(sender).getName())) .getPlayerTime())); return; } for (Player player : players) { if (!player.equals(sender)) { player.sendMessage( ChatColor.YELLOW + "Your time set to " + CommandBookUtil.getTimeString(player.getPlayerTime())); } else { player.sendMessage( ChatColor.YELLOW + "Your time set to " + CommandBookUtil.getTimeString(player.getPlayerTime())); included = true; } player.setPlayerTime( args.hasFlag('w') ? Integer.parseInt(timeStr) : matchTime(timeStr), args.hasFlag('w')); } if (!included) { sender.sendMessage( ChatColor.YELLOW + "Player times set to " + CommandBookUtil.getTimeString(matchTime(timeStr))); } }
@Override public void setPlayerTime(long time, boolean relative) { caller.setPlayerTime(time, relative); }
@Override public void setTime(long time) { player.setPlayerTime(time, false); }