public void run(CommandSender sender, String[] args) { if (args.length < 3) { Util.invalidArgCount( sender, "Jail", "Send a player to a place where they cannot speak, place blocks, etc.", "/jail [player] [timestamp] [jail]", "/jail [player] [timestamp] [jail] <reason>", "/jail unjail [player]"); return; } if (args[0].equalsIgnoreCase("unjail")) { if (args.length == 1) { Util.invalidArgCount(sender, "Jail", "Unjail a jailed player.", "/jail unjail [player]"); return; } Player target = Bukkit.getPlayer(args[1]); if (target == null) { Util.offline(sender, "Jail", args[1]); return; } pd = new PlayerData(target.getUniqueId()); if (!(Store.muted.contains(target.getName()))) { sender.sendMessage( "§cJail: §4The chosen player §o(" + target.getName() + ") §4is not jailed!"); return; } else if (Store.muted.contains(target.getName())) { Store.muted.remove(target.getName()); Bukkit.broadcastMessage( prefix + "§ePlayer §c" + sender.getName() + "§e unjailed §c" + target.getDisplayName()); } target.teleport(pd.getLocation()); return; } args[1] = args[1].toLowerCase(); final Player target = Bukkit.getPlayer(args[0]); if (target == null) { Util.offline(sender, "Jail", args[0]); return; } if (target.isOp()) { Util.punishOps(sender, "Jail"); return; } if (Store.jailed.contains(target.getName())) { sender.sendMessage( "§cJail: §4The selected player §o(" + target.getName() + ") §cis already jailed!"); return; } String regex = "(?:(?<h>\\d+)h)?(?:(?<m>\\d+)m)?(?:(?<s>\\d+)s)?(?:(?<d>\\d+)d)?"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(args[1].toString()); String timeValue = args[1].replaceFirst(".*?(\\d+).*", "$1"); if (m.matches()) { if (m.group(1) != null) { long time = Integer.parseInt(timeValue) * 72000; Bukkit.getScheduler() .scheduleSyncDelayedTask( pl, new Runnable() { @Override public void run() { Store.jailed.remove(target.getName()); target.teleport(pd.getLocation()); target.sendMessage("§cJail: §4You've been unjailed with a warning."); } }, time); } else if (m.group(2) != null) { long time = Integer.parseInt(timeValue) * 1200; Bukkit.getScheduler() .scheduleSyncDelayedTask( pl, new Runnable() { @Override public void run() { Store.jailed.remove(target.getName()); target.teleport(pd.getLocation()); target.sendMessage("§cJail: §4You've been unjailed with a warning."); } }, time); } else if (m.group(3) != null) { long time = Integer.parseInt(timeValue) * 20; Bukkit.getScheduler() .scheduleSyncDelayedTask( pl, new Runnable() { @Override public void run() { Store.jailed.remove(target.getName()); target.teleport(pd.getLocation()); target.sendMessage("§cJail: §4You've been unjailed with a warning."); } }, time); } else if (m.group(4) != null) { long time = Integer.parseInt(timeValue) * 1728000; Bukkit.getScheduler() .scheduleSyncDelayedTask( pl, new Runnable() { @Override public void run() { Store.jailed.remove(target.getName()); target.teleport(pd.getLocation()); target.sendMessage("§cJail: §4You've been unjailed with a warning."); } }, time); } } else { Util.invalidTimestamp(sender, "Jail", args[1]); return; } if (j.getConfig().getConfigurationSection(args[2]) == null) { sender.sendMessage("§cJail: §4The jail §o(" + args[2] + ") §4does not exist!"); if (j.getConfig().getStringList("existing").size() == 0) { sender.sendMessage("§4There are no existing jails, please create one!"); } else { sender.sendMessage("§4Existing jails:"); for (int i = 0; i < j.getConfig().getStringList("existing").size(); i++) { sender.sendMessage("§c- " + j.getConfig().getStringList("existing").get(i)); } } return; } Location loc = j.getLocation(args[2]); target.teleport(loc); SimpleDateFormat sdf = new SimpleDateFormat("(z) dd/MM/yy hh:mm:ss a"); Date date = new Date(); if (args.length == 3) { pd = new PlayerData(target.getUniqueId()); pd.addHistory(Types.JAIL, "Misconduct", sender.getName(), sdf.format(date), args[1]); Bukkit.broadcastMessage( prefix + "§ePlayer §c" + sender.getName() + " §ejailed §c" + pd.getDisplayName() + " §efor " + args[1] + "!"); } else { String msg = ""; for (int i = 3; i < args.length; i++) { msg = msg + args[i] + " "; } pd = new PlayerData(target.getUniqueId()); pd.addHistory(Types.JAIL, msg.trim(), sender.getName(), sdf.format(date), args[1]); Bukkit.broadcastMessage( prefix + "§ePlayer §c" + sender.getName() + " §ejailed §c" + pd.getDisplayName() + " §efor " + args[1] + " because " + msg.trim() + "!"); } Store.jailed.add(target.getName()); Util.sendActionBar(target, prefix + "§eJail expires in " + args[1] + "!"); }
public void run(CommandSender sender, String[] args) throws Exception { if (!(sender instanceof Player)) throw new ConsoleSenderException(getName()); if (args.length == 0) { Util.invalidArgCount( sender, "TPA", "Request to teleport to another player, or accept/deny a request.", "/tpa [player]", "/tpa [accept|deny]"); return; } if (args.length == 1) { if (args[0].equalsIgnoreCase("accept")) { if (Request.hasRequest(sender.getName())) { Request accept = Request.getCurrentRequested(sender.getName()); Player player = Bukkit.getPlayer(accept.getRequester().getName()); Player target = Bukkit.getPlayer(accept.getRequestee().getName()); if (target == null || player == null) { sender.sendMessage("§cTPA: §4The requester is not online."); Store.tpa.remove(accept); return; } Location current = player.getLocation(); Location loc = null; World w = target.getWorld(); double x = target.getLocation().getX(); double y = target.getLocation().getY(); double z = target.getLocation().getZ(); float yaw = target.getLocation().getYaw(); float pitch = target.getLocation().getPitch(); boolean playerSolid = false; while (playerSolid == false) { loc = new Location(w, x, y, z, yaw, pitch); if (loc.getBlock().getType() != Material.AIR) { playerSolid = true; } else if (player.getAllowFlight() == true && loc.getBlock().getType() == Material.AIR) { playerSolid = true; player.setFlying(true); } else { y--; } } PlayerData pd = new PlayerData(player.getUniqueId()); pd.setBackLocation(player.getLocation()); player.teleport(loc); sender.sendMessage("§6TPA: §eTeleporting to location..."); target.sendMessage("§6TPA: §eRequest accepted"); if (loc.getY() <= 1) { player.teleport(current); sender.sendMessage( "§cTPA: §4The location was beyond the void, so you'll stay where you are."); return; } Store.tpa.remove(accept); } else { sender.sendMessage("§cTPA: §4You have no pending requests."); } } else if (args[0].equalsIgnoreCase("deny")) { if (Request.hasRequest(sender.getName())) { Request denied = Request.getCurrentRequested(sender.getName()); Player player = Bukkit.getPlayer(denied.getRequester().getName()); Player target = Bukkit.getPlayer(denied.getRequestee().getName()); if (target == null || player == null) { sender.sendMessage("§cTPA: §4The requester is not online."); Store.tpa.remove(denied); return; } if (target != null) target.sendMessage("§cTPA: §4" + sender.getName() + " has denied your request."); Store.tpa.remove(denied); } else { sender.sendMessage("§cTPA: §4You have no pending requests."); } } else { Player player = (Player) sender; Player target = Bukkit.getPlayer(args[0]); if (target == null) { Util.offline(sender, "TPA", args[0]); return; } if (target.getName().equalsIgnoreCase(sender.getName())) { sender.sendMessage("§cTPA: §4You cannot request to tp to yourself!"); return; } if (Store.tptoggle.contains(target.getName())) { sender.sendMessage("§cTPA: §4" + target.getDisplayName() + " §4has a TP Toggle enabled."); return; } Request request = new Request(player, target); sender.sendMessage("§6TPA: §eRequest sent!"); Store.tpa.add(request); } } }