public boolean executeCommand( CommandSender sender, String command, String[] args, TweakcraftUtils plugin) throws PermissionsException, CommandSenderException, CommandUsageException, CommandException { if (sender instanceof Player) if (!plugin.check((Player) sender, "getpos")) throw new PermissionsException(command); Location loc = null; /** Permissions checking! */ if (args.length == 0 && !(sender instanceof Player)) throw new CommandUsageException( "If you're going to call this from a console i need a player to check!"); if (args.length == 0 && sender instanceof Player) loc = ((Player) sender).getLocation().clone(); if (args.length > 0 && sender instanceof Player) if (!plugin.check((Player) sender, "getpos.other")) throw new PermissionsException(command); if (args.length > 0) { List<Player> plist = plugin.getServer().matchPlayer(args[0]); if (plist.size() == 0) { throw new CommandUsageException(ChatColor.YELLOW + "Can't find player!"); } else if (plist.size() > 1) { throw new CommandUsageException( ChatColor.YELLOW + "Can't match player, got more than one result!"); } else { loc = plist.get(0).getLocation().clone(); } } if (loc != null) { Integer x, y, z, yaw, pitch; x = Math.round((float) loc.getX()); y = Math.round((float) loc.getY()); z = Math.round((float) loc.getZ()); yaw = Math.round((float) loc.getYaw()); pitch = Math.round((float) loc.getPitch()); sender.sendMessage(ChatColor.YELLOW + "Pos X: " + x + " Y: " + y + " Z: " + z); sender.sendMessage(ChatColor.YELLOW + "Rotation: " + yaw + " Pitch: " + pitch); sender.sendMessage(ChatColor.YELLOW + "World: " + loc.getWorld().getName()); String dir = plugin.getCompassDirection(loc.getYaw()); double degreeRotation = ((loc.getYaw() - 90) % 360); if (degreeRotation < 0) degreeRotation += 360.0; sender.sendMessage( ChatColor.YELLOW + "Compass: "******" (" + (Math.round(degreeRotation * 10) / 10.0) + ")"); } else { throw new CommandException("This isn't supposed to happen!"); } return true; }
@Override public boolean executeCommand( final CommandSender sender, String command, String[] args, TweakcraftUtils plugin) throws PermissionsException, CommandSenderException, CommandUsageException, CommandException { if (sender instanceof Player) if (!plugin.check((Player) sender, "debug")) throw new PermissionsException(command); if (args.length > 0 && args[0].equalsIgnoreCase("clock")) { int expected = 5; if (args.length == 2) { Integer iex; try { iex = Integer.parseInt(args[1]); } catch (NumberFormatException ex) { iex = 1; } expected = Math.min(30, Math.max(1, iex)); } final World world = plugin.getServer().getWorlds().get(0); final double expectedTime = expected * 1000; final double expectedSecs = expected; final int expectedTicks = 20 * (int) expectedSecs; final long start = System.currentTimeMillis(); final long startTicks = world.getFullTime(); sender.sendMessage( ChatColor.DARK_RED + "Timing clock test for " + expected + " IN-GAME seconds..."); sender.sendMessage( ChatColor.DARK_RED + "DO NOT CHANGE A WORLD'S TIME OR PERFORM A HEAVY OPERATION."); Runnable task = new Runnable() { public void run() { long now = System.currentTimeMillis(); long nowTicks = world.getFullTime(); long elapsedTime = now - start; double elapsedSecs = elapsedTime / 1000.0; int elapsedTicks = (int) (nowTicks - startTicks); double error = (expectedTime - elapsedTime) / elapsedTime * 100; double grumror = (expectedTime - elapsedTime) / expectedTime * 100; double clockRate = elapsedTicks / elapsedSecs; if (expectedTicks != elapsedTicks) { sender.sendMessage( ChatColor.DARK_RED + "Warning: Bukkit scheduler inaccurate; expected " + expectedTicks + ", got " + elapsedTicks); } if (Math.round(clockRate) == 20) { sender.sendMessage( ChatColor.YELLOW + "Clock test result: " + ChatColor.GREEN + "EXCELLENT"); } else { if (elapsedSecs > expectedSecs) { if (clockRate < 19) { sender.sendMessage( ChatColor.YELLOW + "Clock test result: " + ChatColor.DARK_RED + "CLOCK BEHIND"); sender.sendMessage( ChatColor.DARK_RED + "WARNING: You have potential block respawn issues."); } else { sender.sendMessage( ChatColor.YELLOW + "Clock test result: " + ChatColor.DARK_RED + "CLOCK BEHIND"); } } else { sender.sendMessage( ChatColor.YELLOW + "Clock test result: " + ChatColor.DARK_RED + "CLOCK AHEAD"); } } sender.sendMessage(ChatColor.GRAY + "Expected time elapsed: " + expectedTime + "ms"); sender.sendMessage(ChatColor.GRAY + "Time elapsed: " + elapsedTime + "ms"); sender.sendMessage(ChatColor.GRAY + "Error: " + error + "%"); sender.sendMessage(ChatColor.GRAY + "Grumror: " + grumror + "%"); sender.sendMessage(ChatColor.GRAY + "Actual clock rate: " + clockRate + " ticks/sec"); sender.sendMessage(ChatColor.GRAY + "Expected clock rate: 20 ticks/sec"); } }; plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, task, expectedTicks); } else { sender.sendMessage(ChatColor.GOLD + "Possible modes: clock"); } return true; }
@Override public boolean executeCommand( CommandSender sender, String command, String[] args, TweakcraftUtils plugin) throws PermissionsException, CommandSenderException, CommandUsageException, CommandException { if (sender instanceof Player) { if (!plugin.check((Player) sender, "weather")) throw new PermissionsException(command); Player player = (Player) sender; boolean left = false; if (args.length == 0) { left = false; } else if (args[0].equalsIgnoreCase("true")) { left = true; } else if (args[0].equalsIgnoreCase("reset")) { if (plugin.getConfigHandler().getLsbindmap().containsKey(player.getName())) { plugin.getConfigHandler().getLsbindmap().remove(player.getName()); } sender.sendMessage(ChatColor.GOLD + "Strike tool unbound!"); return true; } else if (args[0].equalsIgnoreCase("lockdown")) { Location lockdownloc; LockdownLocation lockdownlocation = null; if (args.length > 1) { if (args[1].equalsIgnoreCase("reset")) { if (plugin.getConfigHandler().getLockdowns().containsKey(player.getName())) { plugin.getConfigHandler().getLockdowns().remove(player.getName()); } sender.sendMessage(ChatColor.YELLOW + "Lockdown target reset!"); } else { List<Player> targeta = plugin.getServer().matchPlayer(args[1]); if (targeta.size() != 1) { throw new CommandException("Can't find player!"); } else { lockdownlocation = new LockdownLocation(null, targeta.get(0), true); sender.sendMessage( ChatColor.YELLOW + "Lockdown set to " + targeta.get(0).getDisplayName() + ChatColor.YELLOW + "!"); } } } else { lockdownloc = player.getTargetBlock(null, 200).getLocation(); lockdownloc.setY(lockdownloc.getY() + 1); lockdownlocation = new LockdownLocation(lockdownloc, null, false); sender.sendMessage(ChatColor.YELLOW + "Lockdown to current cursor position!"); } if (lockdownlocation != null) { plugin.getConfigHandler().getLockdowns().put(player.getName(), lockdownlocation); } return true; } int item = player.getItemInHand().getTypeId(); if (item > 0 && item < 255) { player.sendMessage( ChatColor.GOLD + "Can't bind to " + ItemType.toName(item) + ". Can't use blocks!"); } else if (item == 263 || item == 348 || item == 0) { player.sendMessage( ChatColor.GOLD + "Can't bind to " + ItemType.toName(item) + ". Item is nog usable!"); } else { player.sendMessage( ChatColor.GOLD + "Strike tool bound to " + ItemType.toName(item) + "." + (left ? " (left click)" : "")); Map<Integer, Boolean> itemmap = new HashMap<Integer, Boolean>(); itemmap.put(item, left); plugin.getConfigHandler().getLsbindmap().put(player.getName(), itemmap); } } else { throw new CommandSenderException("What's there to bind to?"); } return true; }