108 lines
3.8 KiB
Java
108 lines
3.8 KiB
Java
package me.unurled.raxen.commands.admin;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import me.unurled.raxen.Raxen;
|
|
import me.unurled.raxen.utils.Utils;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.command.TabExecutor;
|
|
import org.bukkit.entity.Player;
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
public class BuildCommand implements TabExecutor {
|
|
|
|
private Raxen raxen;
|
|
|
|
List<String> complete = new ArrayList<>();
|
|
|
|
public BuildCommand(Raxen raxen) {
|
|
this.raxen = raxen;
|
|
}
|
|
|
|
@Override
|
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
|
|
@NotNull String label, @NotNull String[] args) {
|
|
if (!(sender instanceof Player)) {
|
|
Utils.errorConsoleSender(sender);
|
|
return true;
|
|
}
|
|
Player p = (Player) sender;
|
|
if (args.length == 0) {
|
|
p.sendMessage(Utils.colorComp(
|
|
"<reset><yellow>/build [discard|edit|hide|list|on|remove|save|show|tp]"));
|
|
return true;
|
|
}
|
|
if (args.length == 1) {
|
|
switch (args[0]) {
|
|
case "discard":
|
|
p.sendMessage(Utils.colorComp("<reset><yellow>Discarded build!"));
|
|
return true;
|
|
case "edit":
|
|
p.sendMessage(Utils.colorComp("<reset><yellow>Editing build!"));
|
|
return true;
|
|
case "hide":
|
|
p.sendMessage(Utils.colorComp("<reset><yellow>Hiding build!"));
|
|
return true;
|
|
case "list":
|
|
p.sendMessage(Utils.colorComp("<reset><yellow>Listing builds!"));
|
|
return true;
|
|
case "on":
|
|
p.sendMessage(Utils.colorComp("<reset><yellow>Build mode enabled!"));
|
|
return true;
|
|
case "remove":
|
|
p.sendMessage(Utils.colorComp("<reset><yellow>Removed build!"));
|
|
return true;
|
|
case "save":
|
|
p.sendMessage(Utils.colorComp("<reset><yellow>Saved build!"));
|
|
return true;
|
|
case "show":
|
|
p.sendMessage(Utils.colorComp("<reset><yellow>Showing build!"));
|
|
return true;
|
|
case "tp":
|
|
p.sendMessage(Utils.colorComp("<reset><yellow>Teleporting to build!"));
|
|
return true;
|
|
default:
|
|
p.sendMessage(Utils.colorComp(
|
|
"<reset><yellow>/build [discard|edit|hide|list|on|remove|save|show|tp]"));
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender,
|
|
@NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
|
if (complete.isEmpty()) {
|
|
complete.add("discard");
|
|
complete.add("edit");
|
|
complete.add("hide");
|
|
complete.add("list");
|
|
complete.add("on");
|
|
complete.add("remove");
|
|
complete.add("save");
|
|
complete.add("show");
|
|
complete.add("tp");
|
|
}
|
|
List<String> result = new ArrayList<>();
|
|
if (args.length == 1) {
|
|
for (String s : complete) {
|
|
if (s.toLowerCase().startsWith(args[0].toLowerCase())) {
|
|
result.add(s);
|
|
}
|
|
}
|
|
return result;
|
|
} else if (args.length == 2) {
|
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
|
if (p.getName().toLowerCase().startsWith(args[1].toLowerCase())) {
|
|
result.add(p.getName());
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
return null;
|
|
}
|
|
}
|