Essentia plugin
Basic plugin with some essential utilities and commands.
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package com.alttd.essentia.commands;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class AdminSubCommand extends SubCommand {
|
||||
|
||||
protected AdminSubCommand(EssentiaPlugin plugin, String name, String... aliases) {
|
||||
super(plugin, name, aliases);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.alttd.essentia.commands;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class PlayerSubCommand extends SubCommand {
|
||||
|
||||
protected PlayerSubCommand(EssentiaPlugin plugin, String name, String... aliases) {
|
||||
super(plugin, name, aliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String... args) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
sender.sendRichMessage(Config.PLAYER_ONLY_COMMAND);
|
||||
return true;
|
||||
}
|
||||
|
||||
return execute(player, PlayerConfig.getConfig(player), args);
|
||||
}
|
||||
|
||||
protected abstract boolean execute(Player player, PlayerConfig playerConfig, String... args);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.alttd.essentia.commands;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class SubCommand implements TabExecutor {
|
||||
|
||||
protected EssentiaPlugin plugin;
|
||||
private final String name;
|
||||
private final String[] aliases;
|
||||
private final Map<String, SubCommand> subCommands = new LinkedHashMap<>();
|
||||
|
||||
protected SubCommand(EssentiaPlugin plugin, String name, String... aliases) {
|
||||
this.plugin = plugin;
|
||||
this.name = name;
|
||||
this.aliases = aliases;
|
||||
}
|
||||
|
||||
protected abstract boolean execute(CommandSender sender, String... args);
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
|
||||
if (args.length > 0) {
|
||||
SubCommand subCommand = getSubCommand(args[0]);
|
||||
if (subCommand != null) {
|
||||
return subCommand.onCommand(sender, cmd, args[0], Arrays.copyOfRange(args, 1, args.length));
|
||||
}
|
||||
}
|
||||
return execute(sender, args);
|
||||
}
|
||||
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
|
||||
if (args.length == 0) {
|
||||
return subCommands.keySet().stream()
|
||||
.sorted(String::compareToIgnoreCase)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
SubCommand subCommand = getSubCommand(args[0]);
|
||||
if (subCommand != null) {
|
||||
return subCommand.onTabComplete(sender, command, args[0], Arrays.copyOfRange(args, 1, args.length));
|
||||
} else if (args.length == 1) {
|
||||
return subCommands.keySet().stream()
|
||||
.filter(s -> s.toLowerCase().startsWith(args[0]))
|
||||
.sorted(String::compareToIgnoreCase)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void registerSubCommand(SubCommand subCommand) {
|
||||
subCommands.put(subCommand.name.toLowerCase(), subCommand);
|
||||
for (String alias : subCommand.aliases) {
|
||||
subCommands.putIfAbsent(alias.toLowerCase(), subCommand);
|
||||
}
|
||||
}
|
||||
|
||||
private SubCommand getSubCommand(String name) {
|
||||
return subCommands.get(name.toLowerCase());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.AdminSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ClearInventoryCommand extends AdminSubCommand {
|
||||
|
||||
public ClearInventoryCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "clearinventory");
|
||||
// TODO - register clear other subcommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(CommandSender sender, String... args) {
|
||||
if (args.length > 0) { // TODO - make this into a subcommand
|
||||
if (!sender.hasPermission("essentia.command.clearinventory.other")) {
|
||||
sender.sendRichMessage(Config.COMMAND_NO_PERMISSION);
|
||||
return true;
|
||||
}
|
||||
Player player = Bukkit.getPlayer(args[0]);
|
||||
if (player == null) {
|
||||
sender.sendRichMessage(Config.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("requester", sender.name()),
|
||||
Placeholder.component("target", player.displayName())
|
||||
);
|
||||
sender.sendRichMessage(Config.PLAYER_INVENTORY_CLEARED, placeholders);
|
||||
player.sendRichMessage(Config.INVENTORY_CLEARED_BY_OTHER, placeholders);
|
||||
player.getInventory().clear();
|
||||
return true;
|
||||
}
|
||||
if (!(sender instanceof Player player)) {
|
||||
sender.sendRichMessage(Config.PLAYER_ONLY_COMMAND);
|
||||
return true;
|
||||
}
|
||||
player.getInventory().clear();
|
||||
player.sendRichMessage(Config.INVENTORY_CLEARED);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.AdminSubCommand;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class EnchantCommand extends AdminSubCommand {
|
||||
|
||||
public EnchantCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "enchant");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(CommandSender sender, String... args) {
|
||||
// TODO
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String @NotNull [] args) {
|
||||
if (args.length == 1) {
|
||||
return Arrays.stream(Enchantment.values())
|
||||
.map(Enchantment::getKey)
|
||||
.map(NamespacedKey::getKey)
|
||||
.filter(name -> name.toLowerCase().startsWith(args[0].toLowerCase()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.SubCommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class EssentiaCommand extends SubCommand {
|
||||
|
||||
public EssentiaCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "essentia");
|
||||
|
||||
registerSubCommand(new ReloadCommand(plugin));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(CommandSender sender, String... args) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.AdminSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class FeedCommand extends AdminSubCommand {
|
||||
|
||||
public FeedCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "feed");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(CommandSender sender, String... args) {
|
||||
Player target = args.length > 0 ? org.bukkit.Bukkit.getPlayer(args[0]) : sender instanceof Player player ? player : null;
|
||||
if (target == null) {
|
||||
sender.sendRichMessage(Config.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
if (!sender.hasPermission("essentia.command.feed" + (target != sender ? ".other" : "")) ) {
|
||||
sender.sendRichMessage(Config.COMMAND_NO_PERMISSION);
|
||||
return true;
|
||||
}
|
||||
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("requester", sender.name()),
|
||||
Placeholder.component("target", target.displayName())
|
||||
);
|
||||
|
||||
target.setFoodLevel(20);
|
||||
target.setSaturation(20);
|
||||
sender.sendRichMessage(target == sender ? Config.FEED_SELF : Config.FEED_OTHER, placeholders);
|
||||
if (target != sender)
|
||||
target.sendRichMessage(Config.FEED_BY_OTHER, placeholders);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.AdminSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class FlyCommand extends AdminSubCommand {
|
||||
|
||||
public FlyCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "fly");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(CommandSender sender, String... args) {
|
||||
if (args.length > 0) {
|
||||
if (!sender.hasPermission("essentia.command.fly.other")) {
|
||||
sender.sendRichMessage(Config.COMMAND_NO_PERMISSION);
|
||||
return true;
|
||||
}
|
||||
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
if (target == null) {
|
||||
sender.sendRichMessage(Config.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
target.setAllowFlight(!target.getAllowFlight());
|
||||
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("player", sender.name()),
|
||||
Placeholder.component("target", target.name()),
|
||||
Placeholder.unparsed("status", BooleanUtils.toStringOnOff(target.getAllowFlight()))
|
||||
);
|
||||
sender.sendRichMessage(Config.TOGGLED_FLIGHT_BY_OTHER, placeholders);
|
||||
target.sendRichMessage(Config.TOGGLED_FLIGHT_PLAYER, placeholders);
|
||||
return true;
|
||||
}
|
||||
if (!(sender instanceof Player player)) {
|
||||
sender.sendRichMessage(Config.PLAYER_ONLY_COMMAND);
|
||||
return true;
|
||||
}
|
||||
|
||||
player.setAllowFlight(!player.getAllowFlight());
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("player", player.name()),
|
||||
Placeholder.parsed("status", BooleanUtils.toStringOnOff(player.getAllowFlight()))
|
||||
);
|
||||
sender.sendRichMessage(Config.TOGGLED_FLIGHT, placeholders);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.AdminSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GamemodeCommand extends AdminSubCommand {
|
||||
|
||||
public GamemodeCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "gamemode");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(CommandSender sender, String... args) {
|
||||
// TODO -- refactor all "other" subcommands to follow this style, cleaner and easier?
|
||||
Player target = args.length > 1 ? Bukkit.getPlayer(args[1]) : sender instanceof Player player ? player : null;
|
||||
if (target == null) {
|
||||
sender.sendRichMessage(Config.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!sender.hasPermission("essentia.command.gamemode" + (target != sender ? ".other" : "")) ) {
|
||||
sender.sendRichMessage(Config.COMMAND_NO_PERMISSION);
|
||||
return true;
|
||||
}
|
||||
|
||||
GameMode gameMode = GameMode.SURVIVAL;
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "creative", "c" -> gameMode = GameMode.CREATIVE;
|
||||
case "spectator", "sp" -> gameMode = GameMode.SPECTATOR;
|
||||
}
|
||||
target.setGameMode(gameMode);
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("requester", sender.name()),
|
||||
Placeholder.component("target", target.displayName()),
|
||||
Placeholder.unparsed("gamemode", gameMode.toString())
|
||||
);
|
||||
sender.sendRichMessage(target == sender ? Config.GAMEMODE_SET : Config.GAMEMODE_SET_OTHER, placeholders);
|
||||
if (target != sender)
|
||||
target.sendRichMessage(Config.GAMEMODE_SET_BY_OTHER, placeholders);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (args.length == 1) {
|
||||
String name = args[0].trim().toLowerCase();
|
||||
return Arrays.stream(GameMode.values()).map(GameMode::toString)
|
||||
.filter(string -> string.toLowerCase().startsWith(name)).collect(Collectors.toList());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.AdminSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class HealCommand extends AdminSubCommand {
|
||||
|
||||
public HealCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "heal");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(CommandSender sender, String... args) {
|
||||
Player target = args.length > 0 ? org.bukkit.Bukkit.getPlayer(args[0]) : sender instanceof Player player ? player : null;
|
||||
if (target == null) {
|
||||
sender.sendRichMessage(Config.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
if (!sender.hasPermission("essentia.command.heal" + (target != sender ? ".other" : "")) ) {
|
||||
sender.sendRichMessage(Config.COMMAND_NO_PERMISSION);
|
||||
return true;
|
||||
}
|
||||
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("requester", sender.name()),
|
||||
Placeholder.component("target", target.displayName())
|
||||
);
|
||||
target.setHealth(20);
|
||||
sender.sendRichMessage(target == sender ? Config.HEAL_SELF : Config.HEAL_OTHER, placeholders);
|
||||
if (target != sender)
|
||||
target.sendRichMessage(Config.HEAL_BY_OTHER, placeholders);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.AdminSubCommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class ReloadCommand extends AdminSubCommand {
|
||||
|
||||
public ReloadCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "reload");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(CommandSender sender, String... args) {
|
||||
plugin.loadConfiguration();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.tasks.TeleportSounds;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class BackCommand extends PlayerSubCommand {
|
||||
|
||||
public BackCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "back");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
Location back = playerConfig.getBackLocation(false);
|
||||
|
||||
if (back == null) {
|
||||
player.sendRichMessage(Config.NO_BACK_LOCATION);
|
||||
return true;
|
||||
}
|
||||
|
||||
new TeleportSounds(back, player.getLocation())
|
||||
.runTaskLater(plugin, 1);
|
||||
|
||||
player.teleportAsync(back).thenAccept(result ->
|
||||
player.sendRichMessage(Config.TELEPORTING_BACK));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.tasks.TeleportSounds;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class DeathBackCommand extends PlayerSubCommand {
|
||||
|
||||
public DeathBackCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "back");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
Location back = playerConfig.getBackLocation(true);
|
||||
|
||||
if (back == null) {
|
||||
player.sendRichMessage(Config.NO_DEATH_LOCATION);
|
||||
return true;
|
||||
}
|
||||
|
||||
new TeleportSounds(back, player.getLocation())
|
||||
.runTaskLater(plugin, 1);
|
||||
|
||||
player.teleportAsync(back).thenAccept(result ->
|
||||
player.sendRichMessage(Config.TELEPORTING_BACK_DEATH));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class DelHomeCommand extends PlayerSubCommand {
|
||||
|
||||
public DelHomeCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "deletehome");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
// TODO -- subcommand to remove other player homes
|
||||
// if (args.length > 1) {
|
||||
// if (!player.hasPermission("essentia.command.delhome.other")) {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
|
||||
String home = (args.length > 0) ? args[0] : "home";
|
||||
if (playerConfig.getHome(home) == null) {
|
||||
player.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.unparsed("home", home));
|
||||
return true;
|
||||
}
|
||||
|
||||
playerConfig.setHome(home, null);
|
||||
player.sendRichMessage(Config.HOME_DELETED, Placeholder.unparsed("home", home));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.tasks.TeleportSounds;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class HomeCommand extends PlayerSubCommand {
|
||||
|
||||
public HomeCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "home");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
String home = null;
|
||||
if (args.length == 0) {
|
||||
int count = playerConfig.getHomeCount();
|
||||
if (count == 0) {
|
||||
if (player.getBedSpawnLocation() != null) {
|
||||
home = "bed";
|
||||
}
|
||||
} else if (count == 1) {
|
||||
home = playerConfig.getConfigurationSection("home").getKeys(false)
|
||||
.stream().findFirst().orElse(null);
|
||||
} else {
|
||||
player.sendRichMessage(Config.SPECIFY_HOME, Placeholder.unparsed("homelist", String.join(", ", playerConfig.getHomeList())));
|
||||
return true;
|
||||
}
|
||||
if (home == null || home.isEmpty()) {
|
||||
player.sendRichMessage(Config.HOME_NOT_SET);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
home = args[0];
|
||||
}
|
||||
// TODO - subcommand to teleport to others homes
|
||||
// if (args.length > 1) {
|
||||
// if (!player.hasPermission("essentia.command.home.other")) {
|
||||
// return true
|
||||
// }
|
||||
// }
|
||||
|
||||
Location homeLoc = home.equalsIgnoreCase("bed") ?
|
||||
player.getBedSpawnLocation() : playerConfig.getHome(home);
|
||||
if (homeLoc == null) {
|
||||
player.sendRichMessage(Config.HOME_DOES_NOT_EXIST);
|
||||
return true;
|
||||
}
|
||||
|
||||
new TeleportSounds(homeLoc, player.getLocation())
|
||||
.runTaskLater(plugin, 1);
|
||||
|
||||
String homeName = home;
|
||||
player.teleportAsync(homeLoc).thenAccept(result ->
|
||||
player.sendRichMessage(Config.HOME_TELEPORT, Placeholder.unparsed("home", homeName))
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (args.length == 1) {
|
||||
return PlayerConfig.getConfig((Player) sender).getMatchingHomeNames(args[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class HomeListCommand extends PlayerSubCommand {
|
||||
|
||||
public HomeListCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "homes");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
// TODO - subcommand to list other homes
|
||||
// if (args.length > 0) {
|
||||
// if (!player.hasPermission("essentia.command.homes.other")) {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
|
||||
// TODO - clickable homes that run /home <name>
|
||||
player.sendRichMessage(Config.HOME_LIST, Placeholder.unparsed("homelist", String.join(", ", playerConfig.getHomeList())));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class SetHomeCommand extends PlayerSubCommand {
|
||||
|
||||
|
||||
public SetHomeCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "sethome");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
// TODO -- subcommand to allow setting other player homes
|
||||
// if (args.length > 1) {
|
||||
// if (!player.hasPermission("essentia.command.sethome.other")) {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
|
||||
String home = (args.length > 0) ? args[0] : "home";
|
||||
if (home.equalsIgnoreCase("bed") || home.contains(".")) {
|
||||
player.sendRichMessage(Config.INVALID_HOME_NAME);
|
||||
return true;
|
||||
}
|
||||
|
||||
int limit = 5; // TODO -- player home limits hardcoded for now
|
||||
int count = playerConfig.getHomeCount();
|
||||
if (limit >= 0 && count >= limit) {
|
||||
player.sendRichMessage(Config.HOME_SET_MAX, Placeholder.unparsed("limit", String.valueOf(limit)));
|
||||
return true;
|
||||
}
|
||||
|
||||
playerConfig.setHome(home, player.getLocation());
|
||||
player.sendRichMessage(Config.HOME_SET, Placeholder.unparsed("home", home));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.request.Request;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TeleportAcceptCommand extends PlayerSubCommand {
|
||||
|
||||
public TeleportAcceptCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "teleportaccept");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
Request request = playerConfig.request();
|
||||
if (request == null) {
|
||||
player.sendRichMessage(Config.NO_PENDING_REQUESTS);
|
||||
return true;
|
||||
}
|
||||
|
||||
request.accept();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.request.Request;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TeleportDenyCommand extends PlayerSubCommand {
|
||||
|
||||
public TeleportDenyCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "teleportdeny");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
Request request = playerConfig.request();
|
||||
if (request == null) {
|
||||
player.sendRichMessage(Config.NO_PENDING_REQUESTS);
|
||||
return true;
|
||||
}
|
||||
|
||||
request.deny();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.request.TeleportRequest;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TeleportRequestCommand extends PlayerSubCommand {
|
||||
|
||||
public TeleportRequestCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "teleportrequest");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
if (args.length < 1) {
|
||||
player.sendRichMessage(Config.NO_PLAYER_SPECIFIED);
|
||||
return true;
|
||||
}
|
||||
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
if (target == null) {
|
||||
player.sendRichMessage(Config.PLAYER_NOT_ONLINE);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (target == player) {
|
||||
player.sendRichMessage(Config.REQUEST_TO_SELF);
|
||||
return true;
|
||||
}
|
||||
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("target", target.displayName())
|
||||
);
|
||||
|
||||
PlayerConfig targetConfig = PlayerConfig.getConfig(target);
|
||||
if (targetConfig.request() != null) {
|
||||
player.sendRichMessage(Config.TARGET_HAS_PENDING_REQUEST, placeholders);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!targetConfig.allowTeleports()) {
|
||||
player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders);
|
||||
return true;
|
||||
}
|
||||
|
||||
targetConfig.request(new TeleportRequest(plugin, player, target));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (args.length == 1) {
|
||||
String name = args[0].trim().toLowerCase();
|
||||
return Bukkit.getOnlinePlayers().stream()
|
||||
.map(Player::getName)
|
||||
.filter(playerName -> playerName.toLowerCase().startsWith(name)).collect(Collectors.toList());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.request.TeleportHereRequest;
|
||||
import com.alttd.essentia.request.TeleportRequest;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TeleportRequestHereCommand extends PlayerSubCommand {
|
||||
|
||||
public TeleportRequestHereCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "teleportrequesthere");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
if (args.length < 1) {
|
||||
player.sendRichMessage(Config.NO_PLAYER_SPECIFIED);
|
||||
return true;
|
||||
}
|
||||
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
if (target == null) {
|
||||
player.sendRichMessage(Config.PLAYER_NOT_ONLINE);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (target == player) {
|
||||
player.sendRichMessage(Config.REQUEST_TO_SELF);
|
||||
return true;
|
||||
}
|
||||
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("target", target.displayName())
|
||||
);
|
||||
|
||||
PlayerConfig targetConfig = PlayerConfig.getConfig(target);
|
||||
if (targetConfig.request() != null) {
|
||||
player.sendRichMessage(Config.TARGET_HAS_PENDING_REQUEST, placeholders);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!targetConfig.allowTeleports()) {
|
||||
player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders);
|
||||
return true;
|
||||
}
|
||||
|
||||
targetConfig.request(new TeleportHereRequest(plugin, player, target));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (args.length == 1) {
|
||||
String name = args[0].trim().toLowerCase();
|
||||
return Bukkit.getOnlinePlayers().stream()
|
||||
.map(Player::getName)
|
||||
.filter(playerName -> playerName.toLowerCase().startsWith(name)).collect(Collectors.toList());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TeleportToggleCommand extends PlayerSubCommand {
|
||||
|
||||
public TeleportToggleCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "teleporttoggle");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
playerConfig.setAllowTeleports(!playerConfig.allowTeleports());
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.parsed("toggle", BooleanUtils.toStringOnOff(playerConfig.allowTeleports()))
|
||||
);
|
||||
player.sendRichMessage(Config.TELEPORT_TOGGLE_SET, placeholders);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user