Switch to brigadier for commands
This commit is contained in:
parent
c4055358b1
commit
ff2824f287
|
|
@ -39,4 +39,8 @@ public interface User {
|
|||
Request request();
|
||||
|
||||
void request(Request request);
|
||||
|
||||
boolean isCuffed();
|
||||
|
||||
void setCuffed(boolean cuffed);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ dependencies {
|
|||
tasks {
|
||||
shadowJar {
|
||||
archiveFileName.set("${project.name}.jar")
|
||||
minimize() {
|
||||
minimize {
|
||||
exclude {
|
||||
it.moduleName == "api"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,12 +24,4 @@ tasks {
|
|||
expand(Pair("version", rootProject.version))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//bukkit {
|
||||
// name = rootProject.name
|
||||
// main = "$group.${rootProject.name}Plugin"
|
||||
// version = "${rootProject.version}"
|
||||
// apiVersion = "1.20"
|
||||
// authors = listOf("destro174")
|
||||
//}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
package com.alttd.essentia.commands;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
|
||||
public abstract class AdminSubCommand extends SubCommand {
|
||||
|
||||
protected AdminSubCommand(EssentiaPlugin plugin, String name, String... aliases) {
|
||||
super(plugin, name, aliases);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
package com.alttd.essentia.commands;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
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, plugin.userManager().getUser(player), args);
|
||||
}
|
||||
|
||||
protected abstract boolean execute(Player player, User user, String... args);
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
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;
|
||||
protected 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());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +1,66 @@
|
|||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.AdminSubCommand;
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
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;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BurnCommand extends AdminSubCommand {
|
||||
public class BurnCommand implements EssentiaCommand {
|
||||
|
||||
public BurnCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "burn");
|
||||
static String commandName = "burn";
|
||||
|
||||
@Override
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
|
||||
)
|
||||
.executes((source) -> {
|
||||
if (source.getSource().getSender() instanceof Player player)
|
||||
execute(player, player);
|
||||
|
||||
return 1;
|
||||
})
|
||||
.then(
|
||||
Commands.argument("player", ArgumentTypes.player())
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
||||
.executes((source) -> {
|
||||
CommandSourceStack sourceStack = source.getSource();
|
||||
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
|
||||
execute(source.getSource().getSender(), target);
|
||||
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@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." + name + (target != sender ? ".other" : "")) ) {
|
||||
sender.sendRichMessage(Config.COMMAND_NO_PERMISSION);
|
||||
return true;
|
||||
}
|
||||
public String description() {
|
||||
return "Set yourself or another player on fire!";
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, Player target) { // TODO - optional time?
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("requester", sender.name()),
|
||||
Placeholder.component("target", target.displayName())
|
||||
);
|
||||
|
||||
target.setFireTicks((int) (3000L / 50));
|
||||
sender.sendRichMessage(target == sender ? Config.BURN_SELF : Config.BURN_OTHER, placeholders);
|
||||
if (target != sender)
|
||||
target.sendRichMessage(Config.BURN_BY_OTHER, placeholders);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,49 +1,63 @@
|
|||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.AdminSubCommand;
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
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;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ClearInventoryCommand extends AdminSubCommand {
|
||||
public class ClearInventoryCommand implements EssentiaCommand {
|
||||
|
||||
public ClearInventoryCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "clearinventory");
|
||||
// TODO - register clear other subcommand
|
||||
}
|
||||
static String commandName = "clearinventory";
|
||||
|
||||
@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;
|
||||
}
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
|
||||
commandSourceStack.getSender() instanceof Player
|
||||
)
|
||||
.executes((source) -> {
|
||||
if (source.getSource().getSender() instanceof Player player)
|
||||
execute(player, player);
|
||||
|
||||
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;
|
||||
return 1;
|
||||
})
|
||||
.then(
|
||||
Commands.argument("player", ArgumentTypes.player())
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
||||
.executes((source) -> {
|
||||
CommandSourceStack sourceStack = source.getSource();
|
||||
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
|
||||
|
||||
execute(source.getSource().getSender(), target);
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, Player target) {
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("requester", sender.name()),
|
||||
Placeholder.component("target", target.displayName())
|
||||
);
|
||||
|
||||
target.getInventory().clear();
|
||||
sender.sendRichMessage(target == sender ? Config.INVENTORY_CLEARED : Config.PLAYER_INVENTORY_CLEARED, placeholders);
|
||||
|
||||
if (target != sender)
|
||||
target.sendRichMessage(Config.INVENTORY_CLEARED_BY_OTHER, placeholders);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import com.alttd.essentia.api.user.UserManager;
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
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;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CuffCommand implements EssentiaCommand {
|
||||
|
||||
static String commandName = "cuff";
|
||||
|
||||
@Override
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
|
||||
)
|
||||
.then(
|
||||
Commands.argument("player", ArgumentTypes.player())
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
||||
.executes((source) -> {
|
||||
CommandSourceStack sourceStack = source.getSource();
|
||||
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
|
||||
execute(source.getSource().getSender(), target);
|
||||
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, Player target) {
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("requester", sender.name()),
|
||||
Placeholder.component("target", target.displayName())
|
||||
);
|
||||
|
||||
UserManager userManager = EssentiaPlugin.instance().userManager();
|
||||
if (!userManager.hasUser(target.getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
User user = userManager.getUser(target);
|
||||
if (user.isCuffed()) {
|
||||
sender.sendRichMessage("<target> is already cuffed."); // TODO - CONFIG messages
|
||||
return;
|
||||
}
|
||||
|
||||
user.setCuffed(true);
|
||||
// TODO - CONFIG messages
|
||||
sender.sendRichMessage(target == sender ? Config.BURN_SELF : Config.BURN_OTHER, placeholders);
|
||||
if (target != sender)
|
||||
target.sendRichMessage(Config.BURN_BY_OTHER, placeholders);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,38 +1,110 @@
|
|||
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 com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.alttd.essentia.commands.argumement.EnchantmentArgument;
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
public class EnchantCommand implements EssentiaCommand {
|
||||
|
||||
public class EnchantCommand extends AdminSubCommand {
|
||||
|
||||
public EnchantCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "enchant");
|
||||
}
|
||||
static String commandName = "enchant";
|
||||
|
||||
@Override
|
||||
protected boolean execute(CommandSender sender, String... args) {
|
||||
// TODO
|
||||
return true;
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
|
||||
)
|
||||
.then(
|
||||
Commands.argument("enchantment", new EnchantmentArgument())
|
||||
.executes((source) -> {
|
||||
if (!(source.getSource().getSender() instanceof Player player))
|
||||
return 1;
|
||||
|
||||
Enchantment enchantment = source.getArgument("enchantment", Enchantment.class);
|
||||
execute(source.getSource().getSender(), player, enchantment);
|
||||
return 1;
|
||||
}).then(
|
||||
Commands.argument("level", IntegerArgumentType.integer(1, 100))
|
||||
.executes((source) -> {
|
||||
if (!(source.getSource().getSender() instanceof Player player))
|
||||
return 1;
|
||||
|
||||
Enchantment enchantment = source.getArgument("enchantment", Enchantment.class);
|
||||
int level = source.getArgument("level", Integer.class);
|
||||
execute(source.getSource().getSender(), player, enchantment, level);
|
||||
return 1;
|
||||
})
|
||||
.then(
|
||||
Commands.argument("player", ArgumentTypes.player())
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
||||
.executes((source) -> {
|
||||
CommandSourceStack sourceStack = source.getSource();
|
||||
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
|
||||
Enchantment enchantment = source.getArgument("enchantment", Enchantment.class);
|
||||
int level = source.getArgument("level", Integer.class);
|
||||
execute(source.getSource().getSender(), target, enchantment, level);
|
||||
return 1;
|
||||
})
|
||||
)
|
||||
)
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@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());
|
||||
private void execute(CommandSender sender, Player target, Enchantment enchantment) {
|
||||
execute(sender, target, enchantment, 1, false);
|
||||
}
|
||||
|
||||
private void execute(CommandSender sender, Player target, Enchantment enchantment, int level) {
|
||||
execute(sender, target, enchantment, level, false);
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, Player target, Enchantment enchantment, int level, boolean unsafe) {
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("requester", sender.name()),
|
||||
Placeholder.component("target", target.displayName()),
|
||||
Placeholder.unparsed("enchantment", enchantment.getKey().value())
|
||||
);
|
||||
|
||||
// target.setGameMode(gameMode);
|
||||
ItemStack itemStack = target.getInventory().getItemInMainHand();
|
||||
if (itemStack.getType() == Material.AIR) {
|
||||
sender.sendRichMessage("Hold the item you want to enchant", placeholders);
|
||||
return;
|
||||
}
|
||||
return null;
|
||||
if (unsafe) {
|
||||
itemStack.addUnsafeEnchantment(enchantment, level);
|
||||
} else {
|
||||
if ((level > enchantment.getMaxLevel())) {
|
||||
level = enchantment.getMaxLevel();
|
||||
}
|
||||
if (!enchantment.canEnchantItem(itemStack)) {
|
||||
sender.sendRichMessage("You can not enchant this item with <enchantment>", placeholders);
|
||||
return;
|
||||
}
|
||||
|
||||
itemStack.addEnchantment(enchantment, level);
|
||||
}
|
||||
|
||||
sender.sendRichMessage(target == sender ? "You enchanted your item with <enchantment>." : "<sender> enchanted your item with <enchantment>.", placeholders);
|
||||
if (target != sender)
|
||||
target.sendRichMessage("You enchanted <target>'s item with <enchantment>.", placeholders);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EssentiaAdminCommand implements EssentiaCommand {
|
||||
|
||||
@Override
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal("essentia")
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin.reload"))
|
||||
.executes((commandContext -> 1))
|
||||
.then(
|
||||
Commands.literal("reload")
|
||||
.executes((cmd) -> {
|
||||
EssentiaPlugin.instance().reloadConfig();
|
||||
return com.mojang.brigadier.Command.SINGLE_SUCCESS;
|
||||
})
|
||||
)
|
||||
;
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,31 +1,52 @@
|
|||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.AdminSubCommand;
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
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;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FeedCommand extends AdminSubCommand {
|
||||
public class FeedCommand implements EssentiaCommand {
|
||||
|
||||
public FeedCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "feed");
|
||||
}
|
||||
static String commandName = "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;
|
||||
}
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
|
||||
commandSourceStack.getSender() instanceof Player
|
||||
)
|
||||
.executes((source) -> {
|
||||
if (source.getSource().getSender() instanceof Player player)
|
||||
execute(player, player);
|
||||
|
||||
return 1;
|
||||
})
|
||||
.then(
|
||||
Commands.argument("player", ArgumentTypes.player())
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
||||
.executes((source) -> {
|
||||
CommandSourceStack sourceStack = source.getSource();
|
||||
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
|
||||
|
||||
execute(source.getSource().getSender(), target);
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, Player target) {
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("requester", sender.name()),
|
||||
Placeholder.component("target", target.displayName())
|
||||
|
|
@ -36,6 +57,7 @@ public class FeedCommand extends AdminSubCommand {
|
|||
sender.sendRichMessage(target == sender ? Config.FEED_SELF : Config.FEED_OTHER, placeholders);
|
||||
if (target != sender)
|
||||
target.sendRichMessage(Config.FEED_BY_OTHER, placeholders);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,56 +1,74 @@
|
|||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.AdminSubCommand;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import com.alttd.essentia.api.user.UserManager;
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
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.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FlyCommand extends AdminSubCommand {
|
||||
public class FlyCommand implements EssentiaCommand {
|
||||
|
||||
public FlyCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "fly");
|
||||
}
|
||||
static String commandName = "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;
|
||||
}
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
|
||||
commandSourceStack.getSender() instanceof Player
|
||||
)
|
||||
.executes((source) -> {
|
||||
if (source.getSource().getSender() instanceof Player player)
|
||||
execute(player, player);
|
||||
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
if (target == null) {
|
||||
sender.sendRichMessage(Config.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
target.setAllowFlight(!target.getAllowFlight());
|
||||
return 1;
|
||||
})
|
||||
.then(
|
||||
Commands.argument("player", ArgumentTypes.player())
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
||||
.executes((source) -> {
|
||||
CommandSourceStack sourceStack = source.getSource();
|
||||
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
|
||||
|
||||
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;
|
||||
execute(source.getSource().getSender(), target);
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, Player target) {
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("player", sender.name()),
|
||||
Placeholder.component("target", target.name()),
|
||||
Placeholder.unparsed("status", BooleanUtils.toStringOnOff(!target.getAllowFlight()))
|
||||
);
|
||||
|
||||
UserManager userManager = EssentiaPlugin.instance().userManager();
|
||||
if (!userManager.hasUser(target.getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
User user = userManager.getUser(target);
|
||||
user.getUserSettings().flying(!user.getUserSettings().flying());
|
||||
target.setFlying(!user.getUserSettings().flying());
|
||||
sender.sendRichMessage(target == sender ? Config.TOGGLED_FLIGHT : Config.TOGGLED_FLIGHT_PLAYER, placeholders);
|
||||
if (target != sender)
|
||||
target.sendRichMessage(Config.TOGGLED_FLIGHT_BY_OTHER, placeholders);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.mojang.brigadier.arguments.FloatArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
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.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FlySpeedCommand implements EssentiaCommand {
|
||||
|
||||
static String commandName = "flyspeed";
|
||||
|
||||
@Override
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
|
||||
).then(
|
||||
Commands.argument("speed", FloatArgumentType.floatArg(-1, 1))
|
||||
.executes((source) -> {
|
||||
if (!(source.getSource().getSender() instanceof Player player))
|
||||
return 1;
|
||||
|
||||
Enchantment enchantment = source.getArgument("enchantment", Enchantment.class);
|
||||
float speed = source.getArgument("speed", Float.class);
|
||||
execute(source.getSource().getSender(), player, speed);
|
||||
return 1;
|
||||
})
|
||||
.then(
|
||||
Commands.argument("player", ArgumentTypes.player())
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
||||
.executes((source) -> {
|
||||
CommandSourceStack sourceStack = source.getSource();
|
||||
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
|
||||
float speed = source.getArgument("speed", Float.class);
|
||||
execute(source.getSource().getSender(), target, speed);
|
||||
|
||||
return 1;
|
||||
})
|
||||
)
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, Player target, float speed) {
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("requester", sender.name()),
|
||||
Placeholder.component("target", target.displayName())
|
||||
);
|
||||
|
||||
target.setFlySpeed(speed);
|
||||
// TODO - Config messages
|
||||
sender.sendRichMessage(target == sender ? Config.FEED_SELF : Config.FEED_OTHER, placeholders);
|
||||
if (target != sender)
|
||||
target.sendRichMessage(Config.FEED_BY_OTHER, placeholders);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.alttd.essentia.commands.argumement.GameModeArgument;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class GameModeCommand implements EssentiaCommand {
|
||||
|
||||
static String commandName = "gamemode";
|
||||
|
||||
@Override
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
|
||||
)
|
||||
.then(
|
||||
Commands.argument("gamemode", new GameModeArgument())
|
||||
.executes((source) -> {
|
||||
if (!(source.getSource().getSender() instanceof Player player))
|
||||
return 1;
|
||||
|
||||
GameMode gameMode = source.getArgument("gamemode", GameMode.class);
|
||||
execute(source.getSource().getSender(), player, gameMode);
|
||||
return 1;
|
||||
})
|
||||
.then(
|
||||
Commands.argument("player", ArgumentTypes.player())
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
||||
.executes((source) -> {
|
||||
CommandSourceStack sourceStack = source.getSource();
|
||||
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
|
||||
GameMode gameMode = source.getArgument("gamemode", GameMode.class);
|
||||
execute(source.getSource().getSender(), target, gameMode);
|
||||
return 1;
|
||||
})
|
||||
)
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, Player target, GameMode gameMode) {
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("requester", sender.name()),
|
||||
Placeholder.component("target", target.displayName()),
|
||||
Placeholder.unparsed("gamemode", gameMode.toString().toLowerCase())
|
||||
);
|
||||
|
||||
target.setGameMode(gameMode);
|
||||
sender.sendRichMessage(target == sender ? Config.GAMEMODE_SET : Config.GAMEMODE_SET_OTHER, placeholders);
|
||||
if (target != sender)
|
||||
target.sendRichMessage(Config.GAMEMODE_SET_BY_OTHER, placeholders);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
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,73 @@
|
|||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import com.alttd.essentia.api.user.UserManager;
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
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.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class GodCommand implements EssentiaCommand {
|
||||
|
||||
static String commandName = "god";
|
||||
|
||||
@Override
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
|
||||
commandSourceStack.getSender() instanceof Player
|
||||
)
|
||||
.executes((source) -> {
|
||||
if (source.getSource().getSender() instanceof Player player)
|
||||
execute(player, player);
|
||||
|
||||
return 1;
|
||||
})
|
||||
.then(
|
||||
Commands.argument("player", ArgumentTypes.player())
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
||||
.executes((source) -> {
|
||||
CommandSourceStack sourceStack = source.getSource();
|
||||
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
|
||||
|
||||
execute(source.getSource().getSender(), target);
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, Player target) {
|
||||
UserManager userManager = EssentiaPlugin.instance().userManager();
|
||||
User user = userManager.getUser(target);
|
||||
if (user == null)
|
||||
return;
|
||||
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("player", sender.name()),
|
||||
Placeholder.component("target", target.name()),
|
||||
Placeholder.unparsed("status", BooleanUtils.toStringOnOff(!user.getUserSettings().godMode()))
|
||||
);
|
||||
|
||||
user.getUserSettings().godMode(!user.getUserSettings().godMode());
|
||||
target.setInvulnerable(!user.getUserSettings().godMode());
|
||||
sender.sendRichMessage(target == sender ? Config.TOGGLED_GOD : Config.TOGGLED_GOD_PLAYER, placeholders);
|
||||
if (target != sender)
|
||||
target.sendRichMessage(Config.TOGGLED_GOD_BY_OTHER, placeholders);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,39 +1,63 @@
|
|||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.AdminSubCommand;
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
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;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class HealCommand extends AdminSubCommand {
|
||||
public class HealCommand
|
||||
implements EssentiaCommand {
|
||||
|
||||
public HealCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "heal");
|
||||
}
|
||||
static String commandName = "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;
|
||||
}
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
|
||||
commandSourceStack.getSender() instanceof Player
|
||||
)
|
||||
.executes((source) -> {
|
||||
if (source.getSource().getSender() instanceof Player player)
|
||||
execute(player, player);
|
||||
|
||||
return 1;
|
||||
})
|
||||
.then(
|
||||
Commands.argument("player", ArgumentTypes.player())
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
||||
.executes((source) -> {
|
||||
CommandSourceStack sourceStack = source.getSource();
|
||||
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
|
||||
|
||||
execute(source.getSource().getSender(), target);
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, Player target) {
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,40 +1,55 @@
|
|||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.AdminSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
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;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class InfoCommand extends AdminSubCommand {
|
||||
public class InfoCommand implements EssentiaCommand {
|
||||
|
||||
public InfoCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "info");
|
||||
}
|
||||
static String commandName = "info";
|
||||
|
||||
@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." + name + (target != sender ? ".other" : "")) ) {
|
||||
sender.sendRichMessage(Config.COMMAND_NO_PERMISSION);
|
||||
return true;
|
||||
}
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
|
||||
)
|
||||
.executes((source) -> {
|
||||
if (source.getSource().getSender() instanceof Player player)
|
||||
execute(player, player);
|
||||
|
||||
return 1;
|
||||
})
|
||||
.then(
|
||||
Commands.argument("player", ArgumentTypes.player())
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
||||
.executes((source) -> {
|
||||
CommandSourceStack sourceStack = source.getSource();
|
||||
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
|
||||
execute(source.getSource().getSender(), target);
|
||||
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, Player target) { // TODO - implement player info
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("requester", sender.name()),
|
||||
Placeholder.component("target", target.displayName())
|
||||
);
|
||||
// Todo Show player info
|
||||
// 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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
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,71 @@
|
|||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
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;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SmiteCommand implements EssentiaCommand {
|
||||
|
||||
static String commandName = "smite";
|
||||
|
||||
@Override
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
|
||||
)
|
||||
.executes((source) -> {
|
||||
if (source.getSource().getSender() instanceof Player player)
|
||||
execute(player, player);
|
||||
|
||||
return 1;
|
||||
})
|
||||
.then(
|
||||
Commands.argument("player", ArgumentTypes.player())
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
||||
.executes((source) -> {
|
||||
CommandSourceStack sourceStack = source.getSource();
|
||||
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
|
||||
execute(source.getSource().getSender(), target);
|
||||
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, Player target) {
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("requester", sender.name()),
|
||||
Placeholder.component("target", target.displayName())
|
||||
);
|
||||
|
||||
if (sender instanceof Player player)
|
||||
target.damage(100.0D, player);
|
||||
|
||||
target.setHealth(0.0D);
|
||||
target.getWorld().strikeLightningEffect(target.getLocation());
|
||||
sender.sendRichMessage(target == sender ? Config.SMITE_SELF : Config.SMITE_OTHER, placeholders);
|
||||
if (target != sender)
|
||||
target.sendRichMessage(Config.SMITE_BY_OTHER, placeholders);
|
||||
|
||||
}
|
||||
|
||||
public List<String> aliases() {
|
||||
return List.of("kill");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TeleportCommand implements EssentiaCommand {
|
||||
|
||||
static String commandName = "teleport";
|
||||
|
||||
@Override
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
|
||||
commandSourceStack.getSender() instanceof Player
|
||||
)
|
||||
.then(
|
||||
Commands.argument("player", ArgumentTypes.player())
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
||||
.executes((source) -> {
|
||||
CommandSourceStack sourceStack = source.getSource();
|
||||
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
|
||||
execute((Player) source.getSource().getSender(), target);
|
||||
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(Player sender, Player target) {
|
||||
sender.teleport(target);
|
||||
}
|
||||
|
||||
public List<String> aliases() {
|
||||
return List.of("tp");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TeleportHereCommand implements EssentiaCommand {
|
||||
|
||||
static String commandName = "teleporthere";
|
||||
|
||||
@Override
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
|
||||
commandSourceStack.getSender() instanceof Player
|
||||
)
|
||||
.then(
|
||||
Commands.argument("player", ArgumentTypes.player())
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
||||
.executes((source) -> {
|
||||
CommandSourceStack sourceStack = source.getSource();
|
||||
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
|
||||
execute((Player) source.getSource().getSender(), target);
|
||||
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(Player sender, Player target) {
|
||||
target.teleport(sender);
|
||||
}
|
||||
|
||||
public List<String> aliases() {
|
||||
return List.of("tp", "tphere");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.BlockPositionResolver;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
import io.papermc.paper.math.BlockPosition;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TeleportPositionCommand implements EssentiaCommand {
|
||||
|
||||
static String commandName = "teleportposition";
|
||||
|
||||
@Override
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
|
||||
commandSourceStack.getSender() instanceof Player
|
||||
)
|
||||
.then(
|
||||
Commands.argument("pos", ArgumentTypes.blockPosition())
|
||||
.executes((source) -> {
|
||||
if (!(source.getSource().getSender() instanceof Player player))
|
||||
return 1;
|
||||
|
||||
CommandSourceStack sourceStack = source.getSource();
|
||||
BlockPosition position = source.getArgument("pos", BlockPositionResolver.class).resolve(sourceStack);
|
||||
execute(player, player, position);
|
||||
return 1;
|
||||
})
|
||||
.then(
|
||||
Commands.argument("player", ArgumentTypes.player())
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
||||
.executes((source) -> {
|
||||
if (!(source.getSource().getSender() instanceof Player player))
|
||||
return 1;
|
||||
|
||||
CommandSourceStack sourceStack = source.getSource();
|
||||
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
|
||||
BlockPosition position = source.getArgument("pos", BlockPositionResolver.class).resolve(sourceStack);
|
||||
execute(player, target, position);
|
||||
return 1;
|
||||
})
|
||||
)
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(Player sender, Player target, BlockPosition position) {
|
||||
target.teleport(position.toLocation(target.getWorld()));
|
||||
}
|
||||
|
||||
public List<String> aliases() {
|
||||
return List.of("tppos");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import com.alttd.essentia.api.user.UserManager;
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
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;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class UnCuffCommand implements EssentiaCommand {
|
||||
|
||||
static String commandName = "uncuff";
|
||||
|
||||
@Override
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
|
||||
)
|
||||
.then(
|
||||
Commands.argument("player", ArgumentTypes.player())
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
||||
.executes((source) -> {
|
||||
CommandSourceStack sourceStack = source.getSource();
|
||||
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
|
||||
execute(source.getSource().getSender(), target);
|
||||
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, Player target) {
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("requester", sender.name()),
|
||||
Placeholder.component("target", target.displayName())
|
||||
);
|
||||
|
||||
UserManager userManager = EssentiaPlugin.instance().userManager();
|
||||
if (!userManager.hasUser(target.getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
User user = userManager.getUser(target);
|
||||
if (!user.isCuffed()) {
|
||||
sender.sendRichMessage("<target> is not cuffed."); // TODO - CONFIG messages
|
||||
return;
|
||||
}
|
||||
|
||||
user.setCuffed(false);
|
||||
// TODO - CONFIG messages
|
||||
sender.sendRichMessage(target == sender ? Config.BURN_SELF : Config.BURN_OTHER, placeholders);
|
||||
if (target != sender)
|
||||
target.sendRichMessage(Config.BURN_BY_OTHER, placeholders);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.mojang.brigadier.arguments.FloatArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
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.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class WalkSpeedCommand implements EssentiaCommand {
|
||||
|
||||
static String commandName = "walkspeed";
|
||||
|
||||
@Override
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
|
||||
).then(
|
||||
Commands.argument("speed", FloatArgumentType.floatArg(-1, 1))
|
||||
.executes((source) -> {
|
||||
if (!(source.getSource().getSender() instanceof Player player))
|
||||
return 1;
|
||||
|
||||
Enchantment enchantment = source.getArgument("enchantment", Enchantment.class);
|
||||
float speed = source.getArgument("speed", Float.class);
|
||||
execute(source.getSource().getSender(), player, speed);
|
||||
return 1;
|
||||
})
|
||||
.then(
|
||||
Commands.argument("player", ArgumentTypes.player())
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
||||
.executes((source) -> {
|
||||
CommandSourceStack sourceStack = source.getSource();
|
||||
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
|
||||
float speed = source.getArgument("speed", Float.class);
|
||||
execute(source.getSource().getSender(), target, speed);
|
||||
|
||||
return 1;
|
||||
})
|
||||
)
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, Player target, float speed) {
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("requester", sender.name()),
|
||||
Placeholder.component("target", target.displayName())
|
||||
);
|
||||
|
||||
target.setFlySpeed(speed);
|
||||
// TODO - Config messages
|
||||
sender.sendRichMessage(target == sender ? Config.FEED_SELF : Config.FEED_OTHER, placeholders);
|
||||
if (target != sender)
|
||||
target.sendRichMessage(Config.FEED_BY_OTHER, placeholders);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
package com.alttd.essentia.commands.admin;
|
||||
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
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;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class WorkBenchCommand implements EssentiaCommand {
|
||||
|
||||
static String commandName = "workbench";
|
||||
|
||||
@Override
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
|
||||
)
|
||||
.executes((source) -> {
|
||||
if (source.getSource().getSender() instanceof Player player)
|
||||
execute(player, player);
|
||||
|
||||
return 1;
|
||||
})
|
||||
.then(
|
||||
Commands.argument("player", ArgumentTypes.player())
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
||||
.executes((source) -> {
|
||||
CommandSourceStack sourceStack = source.getSource();
|
||||
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
|
||||
execute(source.getSource().getSender(), target);
|
||||
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, Player target) {
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("requester", sender.name()),
|
||||
Placeholder.component("target", target.displayName())
|
||||
);
|
||||
|
||||
target.openWorkbench(null, true);
|
||||
// TODO - output config messages
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> aliases() {
|
||||
return List.of("craft", "craftingtable");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
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 smiteCommand extends AdminSubCommand {
|
||||
|
||||
public smiteCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "smite");
|
||||
}
|
||||
|
||||
@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." + name + (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())
|
||||
);
|
||||
// Todo smite the user xD
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -14,9 +14,7 @@ import io.papermc.paper.registry.RegistryAccess;
|
|||
import io.papermc.paper.registry.RegistryKey;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,39 +1,62 @@
|
|||
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.api.events.EssentiaEvent;
|
||||
import com.alttd.essentia.api.events.PlayerTeleportBackEvent;
|
||||
import com.alttd.essentia.tasks.TeleportSounds;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.tasks.TeleportSounds;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BackCommand extends PlayerSubCommand {
|
||||
public class BackCommand implements EssentiaCommand {
|
||||
|
||||
public BackCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "back");
|
||||
}
|
||||
static String commandName = "back";
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, User user, String... args) {
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
|
||||
commandSourceStack.getSender() instanceof Player
|
||||
)
|
||||
.executes((source) -> {
|
||||
if (source.getSource().getSender() instanceof Player player)
|
||||
execute(player, player);
|
||||
|
||||
return 1;
|
||||
});
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, Player target) {
|
||||
User user = EssentiaPlugin.instance().userManager().getUser(target);
|
||||
if (user == null)
|
||||
return;
|
||||
|
||||
Location back = user.getBackLocation(false);
|
||||
|
||||
if (back == null) {
|
||||
player.sendRichMessage(Config.NO_BACK_LOCATION);
|
||||
return true;
|
||||
target.sendRichMessage(Config.NO_BACK_LOCATION);
|
||||
return;
|
||||
}
|
||||
EssentiaEvent event = new PlayerTeleportBackEvent(player, back);
|
||||
EssentiaEvent event = new PlayerTeleportBackEvent(target, back);
|
||||
if (!event.callEvent()) {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
new TeleportSounds(back, player.getLocation())
|
||||
.runTaskLater(plugin, 1);
|
||||
|
||||
player.teleportAsync(back).thenAccept(result ->
|
||||
player.sendRichMessage(Config.TELEPORTING_BACK));
|
||||
return true;
|
||||
new TeleportSounds(back, target.getLocation())
|
||||
.runTaskLater(EssentiaPlugin.instance(), 1);
|
||||
|
||||
target.teleportAsync(back).thenAccept(result ->
|
||||
target.sendRichMessage(Config.TELEPORTING_BACK));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,39 +1,68 @@
|
|||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.api.events.EssentiaEvent;
|
||||
import com.alttd.essentia.api.events.PlayerTeleportBackEvent;
|
||||
import com.alttd.essentia.tasks.TeleportSounds;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DeathBackCommand extends PlayerSubCommand {
|
||||
import java.util.List;
|
||||
|
||||
public DeathBackCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "back");
|
||||
}
|
||||
public class DeathBackCommand implements EssentiaCommand {
|
||||
|
||||
static String commandName = "deathback";
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, User user, String... args) {
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
|
||||
commandSourceStack.getSender() instanceof Player
|
||||
)
|
||||
.executes((source) -> {
|
||||
if (source.getSource().getSender() instanceof Player player)
|
||||
execute(player, player);
|
||||
|
||||
return 1;
|
||||
});
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, Player target) {
|
||||
User user = EssentiaPlugin.instance().userManager().getUser(target);
|
||||
if (user == null)
|
||||
return;
|
||||
|
||||
Location back = user.getBackLocation(true);
|
||||
|
||||
if (back == null) {
|
||||
player.sendRichMessage(Config.NO_DEATH_LOCATION);
|
||||
return true;
|
||||
target.sendRichMessage(Config.NO_DEATH_LOCATION);
|
||||
return;
|
||||
}
|
||||
EssentiaEvent event = new PlayerTeleportBackEvent(player, back);
|
||||
EssentiaEvent event = new PlayerTeleportBackEvent(target, back);
|
||||
if (!event.callEvent()) {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
new TeleportSounds(back, player.getLocation())
|
||||
.runTaskLater(plugin, 1);
|
||||
new TeleportSounds(back, target.getLocation())
|
||||
.runTaskLater(EssentiaPlugin.instance(), 1);
|
||||
|
||||
player.teleportAsync(back).thenAccept(result ->
|
||||
player.sendRichMessage(Config.TELEPORTING_BACK_DEATH));
|
||||
return true;
|
||||
target.teleportAsync(back).thenAccept(result ->
|
||||
target.sendRichMessage(Config.TELEPORTING_BACK_DEATH));
|
||||
}
|
||||
|
||||
public List<String> aliases() {
|
||||
return List.of("dback");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,41 +1,150 @@
|
|||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.alttd.essentia.commands.argumement.OfflinePlayerArgument;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.api.events.EssentiaEvent;
|
||||
import com.alttd.essentia.api.events.PlayerRemoveHomeEvent;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DelHomeCommand extends PlayerSubCommand {
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
public DelHomeCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "deletehome");
|
||||
}
|
||||
public class DelHomeCommand implements EssentiaCommand {
|
||||
|
||||
static String commandName = "delhome";
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, User user, String... args) {
|
||||
// TODO -- subcommand to remove other player homes
|
||||
// if (args.length > 1) {
|
||||
// if (!player.hasPermission("essentia.command.delhome.other")) {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
|
||||
commandSourceStack.getSender() instanceof Player
|
||||
)
|
||||
.executes((source) -> {
|
||||
if (source.getSource().getSender() instanceof Player player)
|
||||
execute(player, player);
|
||||
|
||||
String home = (args.length > 0) ? args[0] : "home";
|
||||
return 1;
|
||||
})
|
||||
.then(
|
||||
Commands.argument("home", StringArgumentType.word())
|
||||
.suggests((context, suggestionsBuilder) -> {
|
||||
if (!(context.getSource().getSender() instanceof Player player))
|
||||
return Suggestions.empty();
|
||||
|
||||
User user = EssentiaPlugin.instance().userManager().getUser(player);
|
||||
Collection<String> possibleValues = new ArrayList<>(user.getHomes());
|
||||
|
||||
if(possibleValues.isEmpty())
|
||||
return Suggestions.empty();
|
||||
|
||||
String remaining = suggestionsBuilder.getRemaining().toLowerCase();
|
||||
for (String str : possibleValues) {
|
||||
if (str.toLowerCase().startsWith(remaining)) {
|
||||
suggestionsBuilder.suggest(StringArgumentType.escapeIfRequired(str));
|
||||
}
|
||||
}
|
||||
return suggestionsBuilder.buildFuture();
|
||||
})
|
||||
.executes((source) -> {
|
||||
if (!(source.getSource().getSender() instanceof Player player))
|
||||
return 1;
|
||||
|
||||
String home = source.getArgument("home", String.class);
|
||||
execute(player, player, home);
|
||||
return 1;
|
||||
})
|
||||
)
|
||||
.then(
|
||||
Commands.argument("player", new OfflinePlayerArgument())
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
|
||||
.then(
|
||||
Commands.argument("home", StringArgumentType.word())
|
||||
.suggests((context, suggestionsBuilder) -> {
|
||||
if (!(context.getSource().getSender() instanceof Player))
|
||||
return Suggestions.empty();
|
||||
|
||||
OfflinePlayer target = context.getArgument("player", OfflinePlayer.class);
|
||||
|
||||
User user = EssentiaPlugin.instance().userManager().getUser(target.getUniqueId());
|
||||
if (user == null)
|
||||
user = EssentiaPlugin.instance().storageProvider().loadUser(target.getUniqueId());
|
||||
|
||||
Collection<String> possibleValues = new ArrayList<>(user.getHomes());
|
||||
|
||||
if(possibleValues.isEmpty())
|
||||
return Suggestions.empty();
|
||||
|
||||
String remaining = suggestionsBuilder.getRemaining().toLowerCase();
|
||||
for (String str : possibleValues) {
|
||||
if (str.toLowerCase().startsWith(remaining)) {
|
||||
suggestionsBuilder.suggest(StringArgumentType.escapeIfRequired(str));
|
||||
}
|
||||
}
|
||||
return suggestionsBuilder.buildFuture();
|
||||
})
|
||||
.executes((source) -> {
|
||||
if (!(source.getSource().getSender() instanceof Player player))
|
||||
return 1;
|
||||
|
||||
OfflinePlayer target = source.getArgument("player", OfflinePlayer.class);
|
||||
String home = source.getArgument("home", String.class);
|
||||
execute(player, target, home);
|
||||
return 1;
|
||||
})
|
||||
)
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(Player sender, Player target) {
|
||||
execute(sender, target, "home");
|
||||
}
|
||||
|
||||
public void execute(Player sender, OfflinePlayer target, String home) {
|
||||
User user = EssentiaPlugin.instance().userManager().getUser(target.getUniqueId());
|
||||
if (user == null)
|
||||
return;
|
||||
|
||||
user = EssentiaPlugin.instance().storageProvider().loadUser(target.getUniqueId());
|
||||
|
||||
delHome(sender, user, home);
|
||||
}
|
||||
|
||||
public void execute(Player sender, Player target, String home) {
|
||||
User user = EssentiaPlugin.instance().userManager().getUser(target);
|
||||
if (user == null)
|
||||
return;
|
||||
|
||||
delHome(sender, user, home);
|
||||
}
|
||||
|
||||
private void delHome(Player sender, User user, String home) {
|
||||
if (!user.hasHome(home)) {
|
||||
player.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.unparsed("home", home));
|
||||
return true;
|
||||
sender.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.unparsed("home", home));
|
||||
return;
|
||||
}
|
||||
EssentiaEvent event = new PlayerRemoveHomeEvent(player, home);
|
||||
|
||||
EssentiaEvent event = new PlayerRemoveHomeEvent(sender, home);
|
||||
if (!event.callEvent()) {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
user.setHome(home, null);
|
||||
player.sendRichMessage(Config.HOME_DELETED, Placeholder.unparsed("home", home));
|
||||
return true;
|
||||
sender.sendRichMessage(Config.HOME_DELETED, Placeholder.unparsed("home", home));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
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;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DisposeCommand implements EssentiaCommand {
|
||||
|
||||
static String commandName = "dispose";
|
||||
|
||||
@Override
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName)
|
||||
)
|
||||
.executes((source) -> {
|
||||
if (source.getSource().getSender() instanceof Player player)
|
||||
execute(player, player);
|
||||
|
||||
return 1;
|
||||
})
|
||||
.then(
|
||||
Commands.argument("player", ArgumentTypes.player())
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
|
||||
.executes((source) -> {
|
||||
CommandSourceStack sourceStack = source.getSource();
|
||||
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
|
||||
execute(source.getSource().getSender(), target);
|
||||
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, Player target) {
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("requester", sender.name()),
|
||||
Placeholder.component("target", target.displayName())
|
||||
);
|
||||
|
||||
Inventory inventory = Bukkit.createInventory(null, 36, MiniMessage.miniMessage().deserialize("Item Disposal")); // TODO - config
|
||||
// TODO - PlayerItemDisposeEvent
|
||||
target.openInventory(inventory);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,82 +1,108 @@
|
|||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.api.model.Home;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.api.events.EssentiaEvent;
|
||||
import com.alttd.essentia.api.events.PlayerTeleportHomeEvent;
|
||||
import com.alttd.essentia.tasks.TeleportSounds;
|
||||
import com.alttd.essentia.api.model.Home;
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import com.alttd.essentia.tasks.TeleportSounds;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
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;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
public class HomeCommand extends PlayerSubCommand {
|
||||
// TODO - home other
|
||||
public class HomeCommand implements EssentiaCommand {
|
||||
|
||||
public HomeCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "home");
|
||||
}
|
||||
static String commandName = "home";
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, User user, String... args) {
|
||||
String home;
|
||||
if (args.length == 0) {
|
||||
int count = user.getHomeCount();
|
||||
if (count <= 1) {
|
||||
home = user.getHomes().stream().findFirst().orElse(null);
|
||||
} else {
|
||||
player.sendRichMessage(Config.SPECIFY_HOME, Placeholder.unparsed("homelist", String.join(", ", user.getHomes())));
|
||||
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
|
||||
// }
|
||||
// }
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
|
||||
commandSourceStack.getSender() instanceof Player
|
||||
)
|
||||
.executes((source) -> {
|
||||
if (source.getSource().getSender() instanceof Player player)
|
||||
execute(player, player, "home");
|
||||
|
||||
return 1;
|
||||
})
|
||||
.then(
|
||||
Commands.argument("name", StringArgumentType.word())
|
||||
.suggests((context, suggestionsBuilder) -> {
|
||||
if (!(context.getSource().getSender() instanceof Player player))
|
||||
return Suggestions.empty();
|
||||
|
||||
User user = EssentiaPlugin.instance().userManager().getUser(player);
|
||||
Collection<String> possibleValues = new ArrayList<>(user.getHomes());
|
||||
|
||||
if(possibleValues.isEmpty())
|
||||
return Suggestions.empty();
|
||||
|
||||
String remaining = suggestionsBuilder.getRemaining().toLowerCase();
|
||||
for (String str : possibleValues) {
|
||||
if (str.toLowerCase().startsWith(remaining)) {
|
||||
suggestionsBuilder.suggest(StringArgumentType.escapeIfRequired(str));
|
||||
}
|
||||
}
|
||||
return suggestionsBuilder.buildFuture();
|
||||
})
|
||||
.executes((source) -> {
|
||||
if (!(source.getSource().getSender() instanceof Player player))
|
||||
return 1;
|
||||
|
||||
String name = source.getArgument("name", String.class);
|
||||
execute(player, player, name);
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, Player target, String home) {
|
||||
User user = EssentiaPlugin.instance().userManager().getUser(target);
|
||||
if (user == null)
|
||||
return;
|
||||
|
||||
Home essentiaHome = user.getHome(home);
|
||||
if (essentiaHome == null) {
|
||||
player.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.parsed("home", home));
|
||||
return true;
|
||||
sender.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.parsed("home", home));
|
||||
return;
|
||||
}
|
||||
|
||||
Location homeLoc = essentiaHome.location();
|
||||
if (homeLoc == null) {
|
||||
player.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.parsed("home", home));
|
||||
return true;
|
||||
sender.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.parsed("home", home));
|
||||
sender.sendRichMessage(Config.SPECIFY_HOME, Placeholder.unparsed("homelist", String.join(", ", user.getHomes())));
|
||||
return;
|
||||
}
|
||||
EssentiaEvent event = new PlayerTeleportHomeEvent(player, homeLoc, home);
|
||||
|
||||
EssentiaEvent event = new PlayerTeleportHomeEvent(target, homeLoc, home);
|
||||
if (!event.callEvent()) {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
new TeleportSounds(homeLoc, player.getLocation())
|
||||
.runTaskLater(plugin, 1);
|
||||
new TeleportSounds(homeLoc, target.getLocation())
|
||||
.runTaskLater(EssentiaPlugin.instance(), 1);
|
||||
|
||||
String homeName = home;
|
||||
player.teleportAsync(homeLoc).thenAccept(result ->
|
||||
player.sendRichMessage(Config.HOME_TELEPORT, Placeholder.unparsed("home", homeName))
|
||||
target.teleportAsync(homeLoc).thenAccept(result ->
|
||||
target.sendRichMessage(Config.HOME_TELEPORT, Placeholder.unparsed("home", home))
|
||||
);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (args.length == 1) {
|
||||
return plugin.userManager().getUser((Player) sender).getMatchingHomeNames(args[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,65 @@
|
|||
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.api.user.User;
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.alttd.essentia.commands.argumement.OfflinePlayerCompletingArgument;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class HomeListCommand extends PlayerSubCommand {
|
||||
import java.util.List;
|
||||
|
||||
public HomeListCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "homes");
|
||||
}
|
||||
public class HomeListCommand implements EssentiaCommand {
|
||||
|
||||
static String commandName = "homelist";
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, User user, String... args) {
|
||||
// TODO - subcommand to list other homes
|
||||
// if (args.length > 0) {
|
||||
// if (!player.hasPermission("essentia.command.homes.other")) {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName)
|
||||
)
|
||||
.executes((source) -> {
|
||||
if (source.getSource().getSender() instanceof Player player)
|
||||
execute(player, player);
|
||||
|
||||
return 1;
|
||||
})
|
||||
.then(
|
||||
Commands.argument("player", new OfflinePlayerCompletingArgument())
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
|
||||
.executes((source) -> {
|
||||
OfflinePlayer target = source.getArgument("player", OfflinePlayer.class);
|
||||
execute(source.getSource().getSender(), target);
|
||||
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, OfflinePlayer target) {
|
||||
User user = EssentiaPlugin.instance().userManager().getUser(target.getUniqueId());
|
||||
if (user == null)
|
||||
return;
|
||||
|
||||
user = EssentiaPlugin.instance().storageProvider().loadUser(target.getUniqueId());
|
||||
|
||||
// TODO - clickable homes that run /home <name>
|
||||
player.sendRichMessage(Config.HOME_LIST, Placeholder.unparsed("homelist", String.join(", ", user.getHomes())));
|
||||
return true;
|
||||
sender.sendRichMessage(Config.HOME_LIST, Placeholder.unparsed("homelist", String.join(", ", user.getHomes())));
|
||||
}
|
||||
|
||||
public List<String> aliases() {
|
||||
return List.of("homes");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,50 +1,120 @@
|
|||
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.api.events.EssentiaEvent;
|
||||
import com.alttd.essentia.api.events.PlayerSetHomeEvent;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.alttd.essentia.commands.argumement.OfflinePlayerArgument;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SetHomeCommand extends PlayerSubCommand {
|
||||
public class SetHomeCommand implements EssentiaCommand {
|
||||
|
||||
|
||||
public SetHomeCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "sethome");
|
||||
}
|
||||
static String commandName = "sethome";
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, User user, String... args) {
|
||||
// TODO -- subcommand to allow setting other player homes
|
||||
// if (args.length > 1) {
|
||||
// if (!player.hasPermission("essentia.command.sethome.other")) {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
|
||||
commandSourceStack.getSender() instanceof Player
|
||||
)
|
||||
.executes((source) -> {
|
||||
if (source.getSource().getSender() instanceof Player player)
|
||||
execute(player, player);
|
||||
|
||||
String home = (args.length > 0) ? args[0] : "home";
|
||||
return 1;
|
||||
})
|
||||
.then(
|
||||
Commands.argument("name", StringArgumentType.word())
|
||||
.executes((source) -> {
|
||||
if (!(source.getSource().getSender() instanceof Player player))
|
||||
return 1;
|
||||
|
||||
String name = source.getArgument("name", String.class);
|
||||
execute(player, player, name);
|
||||
return 1;
|
||||
})
|
||||
)
|
||||
.then(
|
||||
Commands.argument("player", new OfflinePlayerArgument())
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
|
||||
.then(
|
||||
Commands.argument("name", StringArgumentType.word())
|
||||
.executes((source) -> {
|
||||
if (!(source.getSource().getSender() instanceof Player player))
|
||||
return 1;
|
||||
|
||||
OfflinePlayer target = source.getArgument("player", OfflinePlayer.class);
|
||||
String name = source.getArgument("name", String.class);
|
||||
execute(player, target, name);
|
||||
return 1;
|
||||
})
|
||||
)
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(Player sender, Player target) {
|
||||
execute(sender, target, "home");
|
||||
}
|
||||
|
||||
public void execute(Player sender, OfflinePlayer target, String home) {
|
||||
User user = EssentiaPlugin.instance().userManager().getUser(target.getUniqueId());
|
||||
if (user == null)
|
||||
return;
|
||||
|
||||
user = EssentiaPlugin.instance().storageProvider().loadUser(target.getUniqueId());
|
||||
|
||||
setHome(sender, user, home);
|
||||
}
|
||||
|
||||
public void execute(Player sender, Player target, String home) {
|
||||
User user = EssentiaPlugin.instance().userManager().getUser(target);
|
||||
if (user == null)
|
||||
return;
|
||||
|
||||
setHome(sender, user, home);
|
||||
}
|
||||
|
||||
private void setHome(Player sender, User user, String home) {
|
||||
if (home.contains(".")) {
|
||||
player.sendRichMessage(Config.INVALID_HOME_NAME);
|
||||
return true;
|
||||
sender.sendRichMessage(Config.INVALID_HOME_NAME);
|
||||
return;
|
||||
}
|
||||
|
||||
if (user.hasHome(home)) {
|
||||
sender.sendRichMessage("<home> already exists.", Placeholder.unparsed("home", home)); // TODO -- CONFIG
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int limit = 5; // TODO -- player home limits hardcoded for now
|
||||
int count = user.getHomeCount();
|
||||
if (limit >= 0 && count >= limit) {
|
||||
player.sendRichMessage(Config.HOME_SET_MAX, Placeholder.unparsed("limit", String.valueOf(limit)));
|
||||
return true;
|
||||
sender.sendRichMessage(Config.HOME_SET_MAX, Placeholder.unparsed("limit", String.valueOf(limit)));
|
||||
return;
|
||||
}
|
||||
Location homeLoc = player.getLocation();
|
||||
EssentiaEvent event = new PlayerSetHomeEvent(player, homeLoc, home);
|
||||
|
||||
Location homeLoc = sender.getLocation();
|
||||
EssentiaEvent event = new PlayerSetHomeEvent(sender, homeLoc, home);
|
||||
if (!event.callEvent()) {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
user.setHome(home, homeLoc);
|
||||
player.sendRichMessage(Config.HOME_SET, Placeholder.unparsed("home", home));
|
||||
return true;
|
||||
sender.sendRichMessage(Config.HOME_SET, Placeholder.unparsed("home", home));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,40 +1,75 @@
|
|||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.api.events.PlayerTeleportSpawnEvent;
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.api.events.EssentiaEvent;
|
||||
import com.alttd.essentia.api.events.PlayerTeleportSpawnEvent;
|
||||
import com.alttd.essentia.tasks.TeleportSounds;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SpawnCommand extends PlayerSubCommand {
|
||||
public class SpawnCommand implements EssentiaCommand {
|
||||
|
||||
public SpawnCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "back");
|
||||
}
|
||||
static String commandName = "spawn";
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, User user, String... args) {
|
||||
World world = plugin.getServer().getWorld(Config.SPAWN_WORLD);
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName)
|
||||
)
|
||||
.executes((source) -> {
|
||||
if (source.getSource().getSender() instanceof Player player)
|
||||
execute(player, player);
|
||||
|
||||
return 1;
|
||||
})
|
||||
.then(
|
||||
Commands.argument("player", ArgumentTypes.player())
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
|
||||
.executes((source) -> {
|
||||
CommandSourceStack sourceStack = source.getSource();
|
||||
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
|
||||
execute(source.getSource().getSender(), target);
|
||||
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, Player target) {
|
||||
User user = EssentiaPlugin.instance().userManager().getUser(target);
|
||||
if (user == null)
|
||||
return;
|
||||
|
||||
World world = EssentiaPlugin.instance().getServer().getWorld(Config.SPAWN_WORLD);
|
||||
if (world == null) {
|
||||
player.sendRichMessage("<red>Could not get the configured spawn world! contact and administrator");
|
||||
return true;
|
||||
sender.sendRichMessage("<red>Could not get the configured spawn world! contact an administrator");
|
||||
return;
|
||||
}
|
||||
Location spawnLocation = world.getSpawnLocation();
|
||||
EssentiaEvent event = new PlayerTeleportSpawnEvent(player, spawnLocation);
|
||||
EssentiaEvent event = new PlayerTeleportSpawnEvent(target, spawnLocation);
|
||||
if (!event.callEvent()) {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
new TeleportSounds(spawnLocation, player.getLocation())
|
||||
.runTaskLater(plugin, 1);
|
||||
new TeleportSounds(spawnLocation, target.getLocation())
|
||||
.runTaskLater(EssentiaPlugin.instance(), 1);
|
||||
|
||||
player.teleportAsync(spawnLocation).thenAccept(result ->
|
||||
player.sendRichMessage("Teleporting to spawn"));
|
||||
return true;
|
||||
target.teleportAsync(spawnLocation).thenAccept(result ->
|
||||
target.sendRichMessage("Teleporting to spawn"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,57 @@
|
|||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.api.request.Request;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TeleportAcceptCommand extends PlayerSubCommand {
|
||||
import java.util.List;
|
||||
|
||||
public TeleportAcceptCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "teleportaccept");
|
||||
}
|
||||
public class TeleportAcceptCommand implements EssentiaCommand {
|
||||
|
||||
static String commandName = "teleportaccept";
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, User user, String... args) {
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
|
||||
commandSourceStack.getSender() instanceof Player
|
||||
)
|
||||
.executes((source) -> {
|
||||
if (source.getSource().getSender() instanceof Player player)
|
||||
execute(player, player);
|
||||
|
||||
return 1;
|
||||
});
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(Player player, Player target) {
|
||||
User user = EssentiaPlugin.instance().userManager().getUser(target);
|
||||
if (user == null)
|
||||
return;
|
||||
|
||||
Request request = user.request();
|
||||
if (request == null) {
|
||||
player.sendRichMessage(Config.NO_PENDING_REQUESTS);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
request.accept();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> aliases() {
|
||||
return List.of("tpyes", "tpaccpt");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,57 @@
|
|||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.api.request.Request;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TeleportDenyCommand extends PlayerSubCommand {
|
||||
import java.util.List;
|
||||
|
||||
public TeleportDenyCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "teleportdeny");
|
||||
}
|
||||
public class TeleportDenyCommand implements EssentiaCommand {
|
||||
|
||||
static String commandName = "teleportdeny";
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, User user, String... args) {
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
|
||||
commandSourceStack.getSender() instanceof Player
|
||||
)
|
||||
.executes((source) -> {
|
||||
if (source.getSource().getSender() instanceof Player player)
|
||||
execute(player, player);
|
||||
|
||||
return 1;
|
||||
});
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(Player player, Player target) {
|
||||
User user = EssentiaPlugin.instance().userManager().getUser(target);
|
||||
if (user == null)
|
||||
return;
|
||||
|
||||
Request request = user.request();
|
||||
if (request == null) {
|
||||
player.sendRichMessage(Config.NO_PENDING_REQUESTS);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
request.deny();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> aliases() {
|
||||
return List.of("tpdeny", "tpno");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,72 +1,84 @@
|
|||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.request.TeleportEssentiaRequest;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
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 class TeleportRequestCommand implements EssentiaCommand {
|
||||
|
||||
public TeleportRequestCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "teleportrequest");
|
||||
}
|
||||
static String commandName = "teleportrequesthere";
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, User user, String... args) {
|
||||
if (args.length < 1) {
|
||||
player.sendRichMessage(Config.NO_PLAYER_SPECIFIED);
|
||||
return true;
|
||||
}
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
|
||||
commandSourceStack.getSender() instanceof Player
|
||||
)
|
||||
.then(
|
||||
Commands.argument("player", ArgumentTypes.player())
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
|
||||
.executes((source) -> {
|
||||
if (!(source.getSource().getSender() instanceof Player player))
|
||||
return 1;
|
||||
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
CommandSourceStack sourceStack = source.getSource();
|
||||
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
|
||||
execute(player, target);
|
||||
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(Player player, Player target) {
|
||||
if (target == null) {
|
||||
player.sendRichMessage(Config.PLAYER_NOT_ONLINE);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (target == player) {
|
||||
player.sendRichMessage(Config.REQUEST_TO_SELF);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("target", target.displayName())
|
||||
);
|
||||
|
||||
User targetUser = plugin.userManager().getUser(target);
|
||||
User targetUser = EssentiaPlugin.instance().userManager().getUser(target);
|
||||
if (targetUser.request() != null) {
|
||||
player.sendRichMessage(Config.TARGET_HAS_PENDING_REQUEST, placeholders);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!targetUser.getUserSettings().allowTeleports()) {
|
||||
player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
targetUser.request(new TeleportEssentiaRequest(plugin, player, target));
|
||||
return true;
|
||||
targetUser.request(new TeleportEssentiaRequest(EssentiaPlugin.instance(), player, target));
|
||||
}
|
||||
|
||||
@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;
|
||||
public List<String> aliases() {
|
||||
return List.of("tpa");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,72 +1,84 @@
|
|||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.request.TeleportHereEssentiaRequest;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import com.alttd.essentia.request.TeleportHereEssentiaRequest;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
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 class TeleportRequestHereCommand implements EssentiaCommand {
|
||||
|
||||
public TeleportRequestHereCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "teleportrequesthere");
|
||||
}
|
||||
static String commandName = "teleportrequesthere";
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, User user, String... args) {
|
||||
if (args.length < 1) {
|
||||
player.sendRichMessage(Config.NO_PLAYER_SPECIFIED);
|
||||
return true;
|
||||
}
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
|
||||
commandSourceStack.getSender() instanceof Player
|
||||
)
|
||||
.then(
|
||||
Commands.argument("player", ArgumentTypes.player())
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
|
||||
.executes((source) -> {
|
||||
if (!(source.getSource().getSender() instanceof Player player))
|
||||
return 1;
|
||||
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
CommandSourceStack sourceStack = source.getSource();
|
||||
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
|
||||
execute(player, target);
|
||||
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(Player player, Player target) {
|
||||
if (target == null) {
|
||||
player.sendRichMessage(Config.PLAYER_NOT_ONLINE);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (target == player) {
|
||||
player.sendRichMessage(Config.REQUEST_TO_SELF);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("target", target.displayName())
|
||||
);
|
||||
|
||||
User targetUser = plugin.userManager().getUser(target);
|
||||
User targetUser = EssentiaPlugin.instance().userManager().getUser(target);
|
||||
if (targetUser.request() != null) {
|
||||
player.sendRichMessage(Config.TARGET_HAS_PENDING_REQUEST, placeholders);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!targetUser.getUserSettings().allowTeleports()) {
|
||||
player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
targetUser.request(new TeleportHereEssentiaRequest(plugin, player, target));
|
||||
return true;
|
||||
targetUser.request(new TeleportHereEssentiaRequest(EssentiaPlugin.instance(), player, target));
|
||||
}
|
||||
|
||||
@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;
|
||||
public List<String> aliases() {
|
||||
return List.of("tpahere", "tphere");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,70 @@
|
|||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.commands.EssentiaCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
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.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TeleportToggleCommand extends PlayerSubCommand {
|
||||
import java.util.List;
|
||||
|
||||
public TeleportToggleCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "teleporttoggle");
|
||||
}
|
||||
public class TeleportToggleCommand implements EssentiaCommand {
|
||||
|
||||
static String commandName = "teleporttoggle";
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, User user, String... args) {
|
||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||
Commands.literal(commandName)
|
||||
.requires(
|
||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName)
|
||||
)
|
||||
.executes((source) -> {
|
||||
if (source.getSource().getSender() instanceof Player player)
|
||||
execute(player, player);
|
||||
|
||||
return 1;
|
||||
})
|
||||
.then(
|
||||
Commands.argument("player", ArgumentTypes.player())
|
||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
|
||||
.executes((source) -> {
|
||||
CommandSourceStack sourceStack = source.getSource();
|
||||
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
|
||||
execute(source.getSource().getSender(), target);
|
||||
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, Player target) {
|
||||
User user = EssentiaPlugin.instance().userManager().getUser(target);
|
||||
if (user == null)
|
||||
return;
|
||||
|
||||
user.getUserSettings().allowTeleports(!user.getUserSettings().allowTeleports());
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.parsed("toggle", BooleanUtils.toStringOnOff(user.getUserSettings().allowTeleports()))
|
||||
);
|
||||
player.sendRichMessage(Config.TELEPORT_TOGGLE_SET, placeholders);
|
||||
return true;
|
||||
sender.sendRichMessage(Config.TELEPORT_TOGGLE_SET, placeholders);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> aliases() {
|
||||
return List.of("tptoggle");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,130 @@
|
|||
package com.alttd.essentia.listeners;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import com.alttd.essentia.api.user.UserManager;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.ProjectileLaunchEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
|
||||
public class CuffListener implements Listener {
|
||||
|
||||
private final EssentiaPlugin plugin;
|
||||
|
||||
public CuffListener() {
|
||||
this.plugin = EssentiaPlugin.instance();
|
||||
}
|
||||
|
||||
private boolean isNotCuffed(Player player) {
|
||||
UserManager userManager = plugin.userManager();
|
||||
User user = userManager.getUser(player);
|
||||
if (user == null)
|
||||
return true;
|
||||
|
||||
return !user.isCuffed();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (isNotCuffed(event.getPlayer()))
|
||||
return;
|
||||
|
||||
cancelEvent(event, event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onAsyncPlayerChat(AsyncChatEvent event) {
|
||||
if (isNotCuffed(event.getPlayer()))
|
||||
return;
|
||||
|
||||
// TODO
|
||||
// if (!Config.TALKWHILECUFFED)
|
||||
// return;
|
||||
|
||||
cancelEvent(event, event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
if (!(event.getWhoClicked() instanceof Player player))
|
||||
return;
|
||||
|
||||
if (isNotCuffed(player))
|
||||
return;
|
||||
|
||||
cancelEvent(event, player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDropItemEvent(PlayerDropItemEvent event) {
|
||||
if (isNotCuffed(event.getPlayer()))
|
||||
return;
|
||||
|
||||
cancelEvent(event, event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onProjectileLaunchEvent(ProjectileLaunchEvent event) {
|
||||
if (!(event.getEntity().getShooter() instanceof Player player))
|
||||
return;
|
||||
|
||||
if (isNotCuffed(player))
|
||||
return;
|
||||
|
||||
cancelEvent(event, player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onnEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
if (!(event.getDamager() instanceof Player player))
|
||||
return;
|
||||
|
||||
if (isNotCuffed(player))
|
||||
return;
|
||||
|
||||
cancelEvent(event, player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
if (!(event.getEntity() instanceof Player player))
|
||||
return;
|
||||
|
||||
if (isNotCuffed(player))
|
||||
return;
|
||||
|
||||
cancelEvent(event, player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (isNotCuffed(player))
|
||||
return;
|
||||
|
||||
Location from = event.getFrom();
|
||||
Location to = event.getTo();
|
||||
|
||||
if (from.getBlockY() < to.getBlockY() && player.isFlying()) {
|
||||
cancelEvent(event, player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (from.getWorld() != to.getWorld() || from.getBlockX() != to.getBlockX() || from.getBlockZ() != to.getBlockZ()) {
|
||||
cancelEvent(event, player);
|
||||
}
|
||||
}
|
||||
|
||||
void cancelEvent(Cancellable event, Player player) {
|
||||
event.setCancelled(true);
|
||||
player.sendRichMessage("You can not do this while cuffed."); // TODO - config
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package com.alttd.essentia.listeners;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.api.model.UserSettings;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import com.alttd.essentia.api.user.UserManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
|
||||
public class FlightListener implements Listener {
|
||||
|
||||
private final EssentiaPlugin plugin;
|
||||
|
||||
public FlightListener() {
|
||||
this.plugin = EssentiaPlugin.instance();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
UserManager userManager = plugin.userManager();
|
||||
User user = userManager.getUser(player);
|
||||
if (user == null)
|
||||
return;
|
||||
|
||||
UserSettings userSettings = user.getUserSettings();
|
||||
if (userSettings.flying())
|
||||
player.setFlying(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
package com.alttd.essentia.listeners;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.api.model.UserSettings;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import com.alttd.essentia.api.user.UserManager;
|
||||
import com.destroystokyo.paper.event.entity.PhantomPreSpawnEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
|
||||
public class GodModeListener implements Listener {
|
||||
|
||||
private final EssentiaPlugin plugin;
|
||||
|
||||
public GodModeListener() {
|
||||
this.plugin = EssentiaPlugin.instance();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFoodLevelChange(FoodLevelChangeEvent event) {
|
||||
if (!(event.getEntity() instanceof Player player))
|
||||
return;
|
||||
|
||||
if (!hasGodMode(player))
|
||||
return;
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onPhantomPreSpawn(PhantomPreSpawnEvent event) {
|
||||
if (!(event.getSpawningEntity() instanceof Player player))
|
||||
return;
|
||||
|
||||
if (!hasGodMode(player))
|
||||
return;
|
||||
|
||||
event.setCancelled(true);
|
||||
event.setShouldAbortSpawn(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityTargetLivingEntity(EntityTargetLivingEntityEvent event) {
|
||||
if (!(event.getEntity() instanceof Player player))
|
||||
return;
|
||||
|
||||
if (!hasGodMode(player))
|
||||
return;
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
private boolean hasGodMode(Player player) {
|
||||
UserManager userManager = plugin.userManager();
|
||||
User user = userManager.getUser(player);
|
||||
if (user == null)
|
||||
return false;
|
||||
|
||||
UserSettings userSettings = user.getUserSettings();
|
||||
return userSettings.godMode();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -22,8 +22,8 @@ public class PlayerListener implements Listener {
|
|||
private final EssentiaPlugin plugin;
|
||||
private final Set<PlayerTeleportEvent.TeleportCause> backAllowCauses = new HashSet<>();
|
||||
|
||||
public PlayerListener(EssentiaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
public PlayerListener() {
|
||||
this.plugin = EssentiaPlugin.instance();
|
||||
|
||||
backAllowCauses.add(PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||
backAllowCauses.add(PlayerTeleportEvent.TeleportCause.COMMAND);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package com.alttd.essentia.model;
|
|||
|
||||
import com.alttd.essentia.api.model.UserSettings;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
public class EssentiaUserSettings implements UserSettings {
|
||||
|
|
@ -18,7 +17,7 @@ public class EssentiaUserSettings implements UserSettings {
|
|||
private boolean needsSaving;
|
||||
|
||||
private EssentiaUserSettings(Builder builder) {
|
||||
this.godMode = builder.godMode;;
|
||||
this.godMode = builder.godMode;
|
||||
this.flying = builder.flying;
|
||||
this.flySpeed = builder.flySpeed;
|
||||
this.walkSpeed = builder.walkSpeed;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
package com.alttd.essentia.storage;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.storage.mysql.SQLStorageProvider;
|
||||
import com.alttd.essentia.storage.sqlite.SQLiteStorageProvider;
|
||||
import com.alttd.essentia.storage.yaml.YamlStorageProvider;
|
||||
|
||||
import java.io.File;
|
||||
|
|
|
|||
|
|
@ -45,9 +45,9 @@ public class DatabaseQuery {
|
|||
|
||||
void edit(PreparedStatement preparedStatement) throws SQLException;
|
||||
|
||||
default void onSuccess(ResultSet resultSet) throws SQLException {};
|
||||
default void onSuccess(ResultSet resultSet) throws SQLException {}
|
||||
|
||||
default void onSuccess() throws SQLException {};
|
||||
default void onSuccess() throws SQLException {}
|
||||
|
||||
default void onFailure(SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ public class YamlStorageProvider extends StorageProvider {
|
|||
.backLocation(getStoredLocation(config,"teleports.back"))
|
||||
.deathLocation(getStoredLocation(config,"teleports.death"))
|
||||
.homes(getHomeData(config))
|
||||
.cuffed(config.getBoolean("cuffed", false))
|
||||
.userSettings(new EssentiaUserSettings
|
||||
.Builder()
|
||||
.flying(config.getBoolean("flying", false))
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ public class EssentiaUser implements User {
|
|||
protected Map<String, Home> homes;
|
||||
protected UserSettings userSettings;
|
||||
protected Request request;
|
||||
protected boolean cuffed;
|
||||
|
||||
private boolean saving;
|
||||
private boolean needsSaving; // can we use a decorator for this to set it to true on every change?
|
||||
|
|
@ -126,6 +127,16 @@ public class EssentiaUser implements User {
|
|||
this.request = request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCuffed() {
|
||||
return cuffed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCuffed(boolean cuffed) {
|
||||
this.cuffed = cuffed;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
protected UUID uuid;
|
||||
|
|
@ -133,6 +144,7 @@ public class EssentiaUser implements User {
|
|||
protected Location deathLocation = null;
|
||||
protected Map<String, Home> homes = new HashMap<>();
|
||||
protected UserSettings userSettings = null;
|
||||
protected boolean cuffed = false;
|
||||
|
||||
public Builder uuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
|
|
@ -159,6 +171,11 @@ public class EssentiaUser implements User {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder cuffed(boolean cuffed) {
|
||||
this.cuffed = cuffed;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EssentiaUser build() {
|
||||
return new EssentiaUser(this);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user