forked from Minecraft/QoL
Add CheckupCommand (#33)
parent
d587210405
commit
af7abe9ca7
|
@ -105,6 +105,8 @@ public class QoL extends JavaPlugin {
|
||||||
this.getCommand("deathmute").setExecutor(deathMuteCommand);
|
this.getCommand("deathmute").setExecutor(deathMuteCommand);
|
||||||
KaratTrophyCommand karatTrophyCommand = new KaratTrophyCommand(this);
|
KaratTrophyCommand karatTrophyCommand = new KaratTrophyCommand(this);
|
||||||
this.getCommand("karattrophy").setExecutor(karatTrophyCommand);
|
this.getCommand("karattrophy").setExecutor(karatTrophyCommand);
|
||||||
|
CheckupCommand checkupCommand = new CheckupCommand(this);
|
||||||
|
this.getCommand("checkup").setExecutor(checkupCommand);
|
||||||
|
|
||||||
if (getConfig().getStringList("list").size() > 0) {
|
if (getConfig().getStringList("list").size() > 0) {
|
||||||
ListCommand listCommand = new ListCommand(this);
|
ListCommand listCommand = new ListCommand(this);
|
||||||
|
|
|
@ -0,0 +1,140 @@
|
||||||
|
package xyz.etztech.qol.commands;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import xyz.etztech.qol.EtzTechUtil;
|
||||||
|
import xyz.etztech.qol.Lang;
|
||||||
|
import xyz.etztech.qol.QoL;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class CheckupCommand implements CommandExecutor {
|
||||||
|
|
||||||
|
|
||||||
|
QoL plugin;
|
||||||
|
private static HashMap<UUID, Checkup> checkups = new HashMap<>();
|
||||||
|
|
||||||
|
public CheckupCommand(QoL paramQoL)
|
||||||
|
{
|
||||||
|
this.plugin = paramQoL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void join(Player player) {
|
||||||
|
Checkup checkup;
|
||||||
|
checkup:
|
||||||
|
for (UUID uuid : checkups.keySet()) {
|
||||||
|
checkup = checkups.get(uuid);
|
||||||
|
for (Player pl : checkup.players) {
|
||||||
|
if (pl.getUniqueId().equals(player.getUniqueId())) {
|
||||||
|
continue checkup; // Don't check twice, even if they re-logged
|
||||||
|
}
|
||||||
|
}
|
||||||
|
checkup.players.add(player);
|
||||||
|
checkups.put(uuid, checkup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
|
||||||
|
if (!( commandSender instanceof Player)) {
|
||||||
|
EtzTechUtil.sms(commandSender, Lang.NO_CONSOLE.getDef());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!commandSender.hasPermission("qol.checkup")) {
|
||||||
|
EtzTechUtil.sms(commandSender, Lang.NO_PERMISSION.getDef());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (args.length < 1) {
|
||||||
|
EtzTechUtil.sms(commandSender, ChatColor.RED + "Please specify a sub-command. `/checkup <start|stop|next>`");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) commandSender;
|
||||||
|
switch (args[0].toLowerCase()) {
|
||||||
|
case "start":
|
||||||
|
start(player);
|
||||||
|
break;
|
||||||
|
case "stop":
|
||||||
|
stop(player);
|
||||||
|
break;
|
||||||
|
case "next":
|
||||||
|
next(player);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
EtzTechUtil.sms(commandSender, ChatColor.RED + "Invalid sub-command. `/checkup <start|stop|next>`");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void start(Player player) {
|
||||||
|
if (checkups.containsKey(player.getUniqueId())) {
|
||||||
|
EtzTechUtil.sms(player, ChatColor.RED + "You are already performing a checkup. Stop with `/checkup stop` or continue with `/checkup next`");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
checkups.put(player.getUniqueId(), new Checkup(new ArrayList<>(Bukkit.getOnlinePlayers()), player.getLocation()));
|
||||||
|
next(player); // Start the checkup
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stop(Player player) {
|
||||||
|
if (!checkups.containsKey(player.getUniqueId())) {
|
||||||
|
EtzTechUtil.sms(player, ChatColor.RED + "You aren't currently performing a checkup. Start one with `/checkup start`");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Checkup checkup = checkups.get(player.getUniqueId());
|
||||||
|
checkups.remove(player.getUniqueId());
|
||||||
|
player.teleport(checkup.back);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void next(Player player) {
|
||||||
|
if (!checkups.containsKey(player.getUniqueId())) {
|
||||||
|
EtzTechUtil.sms(player, ChatColor.RED + "You aren't currently performing a checkup. Start one with `/checkup start`");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Checkup checkup = checkups.get(player.getUniqueId());
|
||||||
|
Player next;
|
||||||
|
while (checkup.hasNext()) {
|
||||||
|
// Loop until next player is online
|
||||||
|
next = checkup.next();
|
||||||
|
if (next.isOnline()) {
|
||||||
|
player.teleport(next.getLocation());
|
||||||
|
EtzTechUtil.sms(player, ChatColor.GREEN + "You are now checking on " + ChatColor.YELLOW + next.getName());
|
||||||
|
checkups.put(player.getUniqueId(), checkup);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EtzTechUtil.sms(player, ChatColor.GREEN + "This is the last player in the checkup. Once you are finished, use `/checkup stop`");
|
||||||
|
}
|
||||||
|
|
||||||
|
private class Checkup {
|
||||||
|
Integer index;
|
||||||
|
List<Player> players;
|
||||||
|
Location back;
|
||||||
|
|
||||||
|
private Checkup(List<Player> players, Location back) {
|
||||||
|
this.index = 0;
|
||||||
|
this.players = players;
|
||||||
|
this.back = back;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasNext() {
|
||||||
|
return this.index < this.players.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Player next() {
|
||||||
|
return this.players.get(this.index++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,11 +9,9 @@ import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerLoginEvent;
|
import org.bukkit.event.player.PlayerLoginEvent;
|
||||||
import xyz.etztech.qol.QoL;
|
import xyz.etztech.qol.QoL;
|
||||||
|
import xyz.etztech.qol.commands.CheckupCommand;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class JoinListener implements Listener {
|
public class JoinListener implements Listener {
|
||||||
|
|
||||||
|
@ -60,6 +58,7 @@ public class JoinListener implements Listener {
|
||||||
|
|
||||||
plugin.updatePlayerViewDistance(player);
|
plugin.updatePlayerViewDistance(player);
|
||||||
|
|
||||||
|
CheckupCommand.join(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,8 @@ commands:
|
||||||
karattrophy:
|
karattrophy:
|
||||||
description: 24 karat trophy command
|
description: 24 karat trophy command
|
||||||
aliases: [trophy]
|
aliases: [trophy]
|
||||||
|
checkup:
|
||||||
|
description: Checkup command
|
||||||
permissions:
|
permissions:
|
||||||
qol.admin:
|
qol.admin:
|
||||||
description: Ability to reload the plugin
|
description: Ability to reload the plugin
|
||||||
|
@ -77,6 +79,9 @@ permissions:
|
||||||
qol.karattrophy:
|
qol.karattrophy:
|
||||||
description: Ability to use the Karat Trophy Command
|
description: Ability to use the Karat Trophy Command
|
||||||
default: op
|
default: op
|
||||||
|
qol.checkup:
|
||||||
|
description: Ability to use the Checkup Command
|
||||||
|
default: op
|
||||||
qol.auditable:
|
qol.auditable:
|
||||||
description: Audits command usage
|
description: Audits command usage
|
||||||
default: op
|
default: op
|
||||||
|
|
Loading…
Reference in New Issue