Compare commits

...

10 Commits

Author SHA1 Message Date
Len 4faaa48a06 Switch to brigadier for commands 2024-08-15 15:31:39 +02:00
Len c4055358b1 Add brigadier ArgumentTypes 2024-08-15 15:30:22 +02:00
Len ad7e61ffe8 Use Reflection to load commands. 2024-08-14 20:48:27 +02:00
Len 628e18858a Load more UserSettings in YamlStorageProvider 2024-08-14 20:47:15 +02:00
Len 563d17d53b Use plugin logger. 2024-08-14 20:46:24 +02:00
Len bd3e537199 Remove commands from plugin.yml 2024-08-14 20:43:36 +02:00
Len 3bc58b7f9c Use reflection to load event listeners 2024-08-14 20:43:00 +02:00
Len 52e51f99da Update default storageprovider to YAML. 2024-08-13 21:22:14 +02:00
Len 6a0fdbbc1e Update references to 1.12.1 2024-08-13 21:21:37 +02:00
Len 2df6a71e6a Update archiveFileName in build.gradle.kts 2024-08-12 10:01:45 +02:00
60 changed files with 2462 additions and 823 deletions

View File

@ -3,7 +3,7 @@ plugins {
} }
dependencies { dependencies {
compileOnly("com.alttd:Galaxy-API:1.20.4-R0.1-SNAPSHOT") compileOnly("com.alttd:Galaxy-API:1.21.1-R0.1-SNAPSHOT")
} }
tasks { tasks {

View File

@ -39,4 +39,8 @@ public interface User {
Request request(); Request request();
void request(Request request); void request(Request request);
boolean isCuffed();
void setCuffed(boolean cuffed);
} }

View File

@ -5,25 +5,27 @@ import java.io.ByteArrayOutputStream
plugins { plugins {
id("java") id("java")
id("java-library") id("java-library")
id("com.github.johnrengelman.shadow") version "8.1.1" id("io.github.goooler.shadow") version "8.1.8"
id("maven-publish") id("maven-publish")
} }
allprojects { allprojects {
group = "com.alttd.essentia" group = "com.alttd.essentia"
version = "Build-" + (System.getenv("BUILD_NUMBER") ?: gitCommit()) version = "Build-" + (System.getenv("BUILD_NUMBER") ?: gitCommit())
description = "Altitude essentials ;)" description = "Altitude essentials ;)"
apply<JavaLibraryPlugin>()
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}
} }
subprojects { subprojects {
apply<JavaLibraryPlugin>() apply<JavaLibraryPlugin>()
apply(plugin = "maven-publish") apply(plugin = "maven-publish")
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
publishing { publishing {
configure<PublishingExtension> { configure<PublishingExtension> {
repositories { repositories {
@ -64,14 +66,10 @@ tasks {
jar { jar {
// enabled = false // enabled = false
// archiveFileName.set("${rootProject.name}.jar") archiveFileName.set("${rootProject.name}.jar")
} }
} }
dependencies {
compileOnly("com.alttd:Galaxy-API:1.20.4-R0.1-SNAPSHOT")
}
fun gitCommit(): String { fun gitCommit(): String {
val os = ByteArrayOutputStream() val os = ByteArrayOutputStream()
project.exec { project.exec {

View File

@ -5,10 +5,11 @@ plugins {
dependencies { dependencies {
implementation(project(":api")) implementation(project(":api"))
compileOnly("com.alttd:Galaxy-API:1.20.4-R0.1-SNAPSHOT") compileOnly("com.alttd:Galaxy-API:1.21.1-R0.1-SNAPSHOT")
api("org.reflections:reflections:0.10.2")
compileOnly("org.projectlombok:lombok:1.18.24") compileOnly("org.projectlombok:lombok:1.18.34")
annotationProcessor("org.projectlombok:lombok:1.18.24") annotationProcessor("org.projectlombok:lombok:1.18.34")
} }
tasks { tasks {

View File

@ -1,17 +1,24 @@
package com.alttd.essentia; package com.alttd.essentia;
import com.alttd.essentia.commands.admin.*; import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.commands.player.*;
import com.alttd.essentia.configuration.Config; import com.alttd.essentia.configuration.Config;
import com.alttd.essentia.listeners.PlayerListener;
import com.alttd.essentia.storage.StorageManager; import com.alttd.essentia.storage.StorageManager;
import com.alttd.essentia.storage.StorageProvider; import com.alttd.essentia.storage.StorageProvider;
import com.alttd.essentia.storage.StorageType; import com.alttd.essentia.storage.StorageType;
import com.alttd.essentia.user.EssentiaUserManager; import com.alttd.essentia.user.EssentiaUserManager;
import com.alttd.essentia.api.user.UserManager; import com.alttd.essentia.api.user.UserManager;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
import lombok.Getter; import lombok.Getter;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.reflections.Reflections;
import org.reflections.scanners.Scanners;
import java.util.Set;
public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI { public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
@ -51,30 +58,36 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
} }
void loadCommands() { void loadCommands() {
getCommand("essentia").setExecutor(new EssentiaCommand(this)); Reflections reflections = new Reflections("com.alttd.essentia.commands");
getCommand("teleportaccept").setExecutor(new TeleportAcceptCommand(this)); Set<Class<?>> subTypes = reflections.get(Scanners.SubTypes.of(EssentiaCommand.class).asClass());
getCommand("teleportdeny").setExecutor(new TeleportDenyCommand(this));
getCommand("teleportrequest").setExecutor(new TeleportRequestCommand(this)); LifecycleEventManager<Plugin> manager = this.getLifecycleManager();
getCommand("teleportrequesthere").setExecutor(new TeleportRequestHereCommand(this)); manager.registerEventHandler(LifecycleEvents.COMMANDS, event -> {
getCommand("teleporttoggle").setExecutor(new TeleportToggleCommand(this)); final Commands commands = event.registrar();
getCommand("clearinventory").setExecutor(new ClearInventoryCommand(this)); subTypes.forEach(clazz -> {
getCommand("home").setExecutor(new HomeCommand(this)); try {
getCommand("homes").setExecutor(new HomeListCommand(this)); EssentiaCommand essentiaCommand = (EssentiaCommand) clazz.getDeclaredConstructor().newInstance();
getCommand("sethome").setExecutor(new SetHomeCommand(this)); commands.register(essentiaCommand.command(), essentiaCommand.description(), essentiaCommand.aliases());
getCommand("deletehome").setExecutor(new DelHomeCommand(this)); } catch (Exception e) {
getCommand("back").setExecutor(new BackCommand(this)); EssentiaPlugin.instance().getLogger().severe("Failed to register command " + clazz.getSimpleName());
getCommand("deathback").setExecutor(new DeathBackCommand(this)); }
getCommand("fly").setExecutor(new FlyCommand(this)); });
getCommand("gamemode").setExecutor(new GamemodeCommand(this)); });
getCommand("heal").setExecutor(new HealCommand(this));
getCommand("feed").setExecutor(new FeedCommand(this));
getCommand("enchant").setExecutor(new EnchantCommand(this));
getCommand("spawn").setExecutor(new SpawnCommand(this));
} }
void loadEventListeners() { void loadEventListeners() {
final PluginManager pluginManager = getServer().getPluginManager(); final PluginManager pluginManager = getServer().getPluginManager();
pluginManager.registerEvents(new PlayerListener(this), this); Reflections reflections = new Reflections("com.alttd.essentia.listeners");
Set<Class<?>> subTypes = reflections.get(Scanners.SubTypes.of(Listener.class).asClass());
subTypes.forEach(clazz -> {
try {
Listener listener = (Listener) clazz.getDeclaredConstructor().newInstance();
pluginManager.registerEvents(listener, this);
} catch (Exception e) {
EssentiaPlugin.instance().getLogger().severe("Failed to register event listener " + clazz.getSimpleName());
}
});
} }
void loadManagers() { void loadManagers() {

View File

@ -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);
}
}

View File

@ -0,0 +1,22 @@
package com.alttd.essentia.commands;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
// TODO -- add optional -s -silent parameters to commands?
public interface EssentiaCommand {
@NotNull LiteralCommandNode<CommandSourceStack> command();
default String description() {
return null;
}
default List<String> aliases() {
return Collections.emptyList();
}
}

View File

@ -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);
}

View File

@ -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());
}
}

View File

@ -1,39 +1,66 @@
package com.alttd.essentia.commands.admin; package com.alttd.essentia.commands.admin;
import com.alttd.essentia.EssentiaPlugin; import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.commands.AdminSubCommand;
import com.alttd.essentia.configuration.Config; 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.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class BurnCommand extends AdminSubCommand { public class BurnCommand implements EssentiaCommand {
public BurnCommand(EssentiaPlugin plugin) { static String commandName = "burn";
super(plugin, "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).get(0);
execute(source.getSource().getSender(), target);
return 1;
})
);
return builder.build();
} }
@Override @Override
protected boolean execute(CommandSender sender, String... args) { public String description() {
Player target = args.length > 0 ? org.bukkit.Bukkit.getPlayer(args[0]) : sender instanceof Player player ? player : null; return "Set yourself or another player on fire!";
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 void execute(CommandSender sender, Player target) { // TODO - optional time?
TagResolver placeholders = TagResolver.resolver( TagResolver placeholders = TagResolver.resolver(
Placeholder.component("requester", sender.name()), Placeholder.component("requester", sender.name()),
Placeholder.component("target", target.displayName()) Placeholder.component("target", target.displayName())
); );
target.setFireTicks((int) (3000L / 50)); target.setFireTicks((int) (3000L / 50));
sender.sendRichMessage(target == sender ? Config.BURN_SELF : Config.BURN_OTHER, placeholders); sender.sendRichMessage(target == sender ? Config.BURN_SELF : Config.BURN_OTHER, placeholders);
if (target != sender) if (target != sender)
target.sendRichMessage(Config.BURN_BY_OTHER, placeholders); target.sendRichMessage(Config.BURN_BY_OTHER, placeholders);
return true;
} }
} }

View File

@ -1,49 +1,63 @@
package com.alttd.essentia.commands.admin; package com.alttd.essentia.commands.admin;
import com.alttd.essentia.EssentiaPlugin; import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.commands.AdminSubCommand;
import com.alttd.essentia.configuration.Config; 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.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class ClearInventoryCommand extends AdminSubCommand { public class ClearInventoryCommand implements EssentiaCommand {
public ClearInventoryCommand(EssentiaPlugin plugin) { static String commandName = "clearinventory";
super(plugin, "clearinventory");
// TODO - register clear other subcommand
}
@Override @Override
protected boolean execute(CommandSender sender, String... args) { public @NotNull LiteralCommandNode<CommandSourceStack> command() {
if (args.length > 0) { // TODO - make this into a subcommand final LiteralArgumentBuilder<CommandSourceStack> builder =
if (!sender.hasPermission("essentia.command.clearinventory.other")) { Commands.literal(commandName)
sender.sendRichMessage(Config.COMMAND_NO_PERMISSION); .requires(
return true; commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
} commandSourceStack.getSender() instanceof Player
Player player = Bukkit.getPlayer(args[0]); )
if (player == null) { .executes((source) -> {
sender.sendRichMessage(Config.PLAYER_NOT_FOUND); if (source.getSource().getSender() instanceof Player player)
return true; execute(player, player);
}
TagResolver placeholders = TagResolver.resolver( return 1;
Placeholder.component("requester", sender.name()), })
Placeholder.component("target", player.displayName()) .then(
); Commands.argument("player", ArgumentTypes.player())
sender.sendRichMessage(Config.PLAYER_INVENTORY_CLEARED, placeholders); .requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
player.sendRichMessage(Config.INVENTORY_CLEARED_BY_OTHER, placeholders); .executes((source) -> {
player.getInventory().clear(); CommandSourceStack sourceStack = source.getSource();
return true; Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
}
if (!(sender instanceof Player player)) { execute(source.getSource().getSender(), target);
sender.sendRichMessage(Config.PLAYER_ONLY_COMMAND); return 1;
return true; })
} );
player.getInventory().clear(); return builder.build();
player.sendRichMessage(Config.INVENTORY_CLEARED);
return true;
} }
}
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);
}
}

View File

@ -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).get(0);
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);
}
}

View File

@ -1,38 +1,110 @@
package com.alttd.essentia.commands.admin; package com.alttd.essentia.commands.admin;
import com.alttd.essentia.EssentiaPlugin; import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.commands.AdminSubCommand; import com.alttd.essentia.commands.argumement.EnchantmentArgument;
import org.bukkit.NamespacedKey; import com.mojang.brigadier.arguments.IntegerArgumentType;
import org.bukkit.command.Command; 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.command.CommandSender;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Arrays; public class EnchantCommand implements EssentiaCommand {
import java.util.List;
import java.util.stream.Collectors;
public class EnchantCommand extends AdminSubCommand { static String commandName = "enchant";
public EnchantCommand(EssentiaPlugin plugin) {
super(plugin, "enchant");
}
@Override @Override
protected boolean execute(CommandSender sender, String... args) { public @NotNull LiteralCommandNode<CommandSourceStack> command() {
// TODO final LiteralArgumentBuilder<CommandSourceStack> builder =
return true; 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).get(0);
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 private void execute(CommandSender sender, Player target, Enchantment enchantment) {
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String @NotNull [] args) { execute(sender, target, enchantment, 1, false);
if (args.length == 1) { }
return Arrays.stream(Enchantment.values())
.map(Enchantment::getKey) private void execute(CommandSender sender, Player target, Enchantment enchantment, int level) {
.map(NamespacedKey::getKey) execute(sender, target, enchantment, level, false);
.filter(name -> name.toLowerCase().startsWith(args[0].toLowerCase())) }
.collect(Collectors.toList());
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);
} }
}
}

View File

@ -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();
}
}

View File

@ -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;
}
}

View File

@ -1,31 +1,52 @@
package com.alttd.essentia.commands.admin; package com.alttd.essentia.commands.admin;
import com.alttd.essentia.EssentiaPlugin; import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.commands.AdminSubCommand;
import com.alttd.essentia.configuration.Config; 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.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class FeedCommand extends AdminSubCommand { public class FeedCommand implements EssentiaCommand {
public FeedCommand(EssentiaPlugin plugin) { static String commandName = "feed";
super(plugin, "feed");
}
@Override @Override
protected boolean execute(CommandSender sender, String... args) { public @NotNull LiteralCommandNode<CommandSourceStack> command() {
Player target = args.length > 0 ? org.bukkit.Bukkit.getPlayer(args[0]) : sender instanceof Player player ? player : null; final LiteralArgumentBuilder<CommandSourceStack> builder =
if (target == null) { Commands.literal(commandName)
sender.sendRichMessage(Config.PLAYER_NOT_FOUND); .requires(
return true; commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
} commandSourceStack.getSender() instanceof Player
if (!sender.hasPermission("essentia.command.feed" + (target != sender ? ".other" : "")) ) { )
sender.sendRichMessage(Config.COMMAND_NO_PERMISSION); .executes((source) -> {
return true; 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).get(0);
execute(source.getSource().getSender(), target);
return 1;
})
);
return builder.build();
}
public void execute(CommandSender sender, Player target) {
TagResolver placeholders = TagResolver.resolver( TagResolver placeholders = TagResolver.resolver(
Placeholder.component("requester", sender.name()), Placeholder.component("requester", sender.name()),
Placeholder.component("target", target.displayName()) 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); sender.sendRichMessage(target == sender ? Config.FEED_SELF : Config.FEED_OTHER, placeholders);
if (target != sender) if (target != sender)
target.sendRichMessage(Config.FEED_BY_OTHER, placeholders); target.sendRichMessage(Config.FEED_BY_OTHER, placeholders);
return true;
} }
} }

View File

@ -1,56 +1,74 @@
package com.alttd.essentia.commands.admin; package com.alttd.essentia.commands.admin;
import com.alttd.essentia.EssentiaPlugin; 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.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.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.BooleanUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class FlyCommand extends AdminSubCommand { public class FlyCommand implements EssentiaCommand {
public FlyCommand(EssentiaPlugin plugin) { static String commandName = "fly";
super(plugin, "fly");
}
@Override @Override
protected boolean execute(CommandSender sender, String... args) { public @NotNull LiteralCommandNode<CommandSourceStack> command() {
if (args.length > 0) { final LiteralArgumentBuilder<CommandSourceStack> builder =
if (!sender.hasPermission("essentia.command.fly.other")) { Commands.literal(commandName)
sender.sendRichMessage(Config.COMMAND_NO_PERMISSION); .requires(
return true; 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]); return 1;
if (target == null) { })
sender.sendRichMessage(Config.PLAYER_NOT_FOUND); .then(
return true; Commands.argument("player", ArgumentTypes.player())
} .requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
target.setAllowFlight(!target.getAllowFlight()); .executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
TagResolver placeholders = TagResolver.resolver( execute(source.getSource().getSender(), target);
Placeholder.component("player", sender.name()), return 1;
Placeholder.component("target", target.name()), })
Placeholder.unparsed("status", BooleanUtils.toStringOnOff(target.getAllowFlight())) );
); return builder.build();
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;
} }
}
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);
}
}

View File

@ -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).get(0);
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);
}
}

View File

@ -0,0 +1,70 @@
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 io.papermc.paper.command.brigadier.argument.resolvers.selector.SelectorArgumentResolver;
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).get(0);
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);
}
}

View File

@ -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;
}
}

View File

@ -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).get(0);
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);
}
}

View File

@ -1,39 +1,63 @@
package com.alttd.essentia.commands.admin; package com.alttd.essentia.commands.admin;
import com.alttd.essentia.EssentiaPlugin; import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.commands.AdminSubCommand;
import com.alttd.essentia.configuration.Config; 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.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class HealCommand extends AdminSubCommand { public class HealCommand
implements EssentiaCommand {
public HealCommand(EssentiaPlugin plugin) { static String commandName = "heal";
super(plugin, "heal");
}
@Override @Override
protected boolean execute(CommandSender sender, String... args) { public @NotNull LiteralCommandNode<CommandSourceStack> command() {
Player target = args.length > 0 ? org.bukkit.Bukkit.getPlayer(args[0]) : sender instanceof Player player ? player : null; final LiteralArgumentBuilder<CommandSourceStack> builder =
if (target == null) { Commands.literal(commandName)
sender.sendRichMessage(Config.PLAYER_NOT_FOUND); .requires(
return true; commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
} commandSourceStack.getSender() instanceof Player
if (!sender.hasPermission("essentia.command.heal" + (target != sender ? ".other" : "")) ) { )
sender.sendRichMessage(Config.COMMAND_NO_PERMISSION); .executes((source) -> {
return true; 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).get(0);
execute(source.getSource().getSender(), target);
return 1;
})
);
return builder.build();
}
public void execute(CommandSender sender, Player target) {
TagResolver placeholders = TagResolver.resolver( TagResolver placeholders = TagResolver.resolver(
Placeholder.component("requester", sender.name()), Placeholder.component("requester", sender.name()),
Placeholder.component("target", target.displayName()) Placeholder.component("target", target.displayName())
); );
target.setHealth(20); target.setHealth(20);
sender.sendRichMessage(target == sender ? Config.HEAL_SELF : Config.HEAL_OTHER, placeholders); sender.sendRichMessage(target == sender ? Config.HEAL_SELF : Config.HEAL_OTHER, placeholders);
if (target != sender) if (target != sender)
target.sendRichMessage(Config.HEAL_BY_OTHER, placeholders); target.sendRichMessage(Config.HEAL_BY_OTHER, placeholders);
return true;
} }
}
}

View File

@ -1,40 +1,55 @@
package com.alttd.essentia.commands.admin; package com.alttd.essentia.commands.admin;
import com.alttd.essentia.EssentiaPlugin; import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.commands.AdminSubCommand; import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.alttd.essentia.configuration.Config; 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.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class InfoCommand extends AdminSubCommand { public class InfoCommand implements EssentiaCommand {
public InfoCommand(EssentiaPlugin plugin) { static String commandName = "info";
super(plugin, "info");
}
@Override @Override
protected boolean execute(CommandSender sender, String... args) { public @NotNull LiteralCommandNode<CommandSourceStack> command() {
Player target = args.length > 0 ? org.bukkit.Bukkit.getPlayer(args[0]) : sender instanceof Player player ? player : null; final LiteralArgumentBuilder<CommandSourceStack> builder =
if (target == null) { Commands.literal(commandName)
sender.sendRichMessage(Config.PLAYER_NOT_FOUND); .requires(
return true; commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
} )
if (!sender.hasPermission("essentia.command." + name + (target != sender ? ".other" : "")) ) { .executes((source) -> {
sender.sendRichMessage(Config.COMMAND_NO_PERMISSION); if (source.getSource().getSender() instanceof Player player)
return true; 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).get(0);
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( TagResolver placeholders = TagResolver.resolver(
Placeholder.component("requester", sender.name()), Placeholder.component("requester", sender.name()),
Placeholder.component("target", target.displayName()) 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;
} }
} }

View File

@ -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;
}
}

View File

@ -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).get(0);
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");
}
}

View File

@ -0,0 +1,52 @@
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 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).get(0);
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");
}
}

View File

@ -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).get(0);
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");
}
}

View File

@ -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).get(0);
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");
}
}

View File

@ -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).get(0);
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);
}
}

View File

@ -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).get(0);
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);
}
}

View File

@ -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.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.Collections;
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).get(0);
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");
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1,53 @@
package com.alttd.essentia.commands.argumement;
import com.mojang.brigadier.Message;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import io.papermc.paper.command.brigadier.MessageComponentSerializer;
import io.papermc.paper.command.brigadier.argument.CustomArgumentType;
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;
import java.util.concurrent.CompletableFuture;
public class EnchantmentArgument implements CustomArgumentType.Converted<Enchantment, String> {
@Override
public @NotNull Enchantment convert(String nativeType) throws CommandSyntaxException {
try {
return Enchantment.getByKey(NamespacedKey.minecraft(nativeType));
} catch (Exception e) {
Message message = MessageComponentSerializer.message().serialize(Component.text("Invalid gamemode %s!".formatted(nativeType), NamedTextColor.RED));
throw new CommandSyntaxException(new SimpleCommandExceptionType(message), message);
}
}
@Override
public @NotNull ArgumentType<String> getNativeType() {
return StringArgumentType.word();
}
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
for (Enchantment enchantment : RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT)) {
builder.suggest(enchantment.getKey().value());
}
return CompletableFuture.completedFuture(
builder.build()
);
}
}

View File

@ -0,0 +1,48 @@
package com.alttd.essentia.commands.argumement;
import com.mojang.brigadier.Message;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import io.papermc.paper.command.brigadier.MessageComponentSerializer;
import io.papermc.paper.command.brigadier.argument.CustomArgumentType;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.GameMode;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.CompletableFuture;
public class GameModeArgument implements CustomArgumentType.Converted<GameMode, String> {
@Override
public @NotNull GameMode convert(String nativeType) throws CommandSyntaxException {
try {
return GameMode.valueOf(nativeType.toUpperCase());
} catch (Exception e) {
Message message = MessageComponentSerializer.message().serialize(Component.text("Invalid gamemode %s!".formatted(nativeType), NamedTextColor.RED));
throw new CommandSyntaxException(new SimpleCommandExceptionType(message), message);
}
}
@Override
public @NotNull ArgumentType<String> getNativeType() {
return StringArgumentType.word();
}
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
for (GameMode gameMode : GameMode.values()) {
builder.suggest(gameMode.name().toLowerCase());
}
return CompletableFuture.completedFuture(
builder.build()
);
}
}

View File

@ -0,0 +1,58 @@
package com.alttd.essentia.commands.argumement;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.api.model.Home;
import com.alttd.essentia.api.user.User;
import com.mojang.brigadier.Message;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import io.papermc.paper.command.brigadier.MessageComponentSerializer;
import io.papermc.paper.command.brigadier.argument.CustomArgumentType;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.CompletableFuture;
public class HomeArgument implements CustomArgumentType.Converted<Home, String> {
User user;
public HomeArgument(OfflinePlayer offlinePlayer) {
user = EssentiaPlugin.instance().userManager().getUser(offlinePlayer.getUniqueId());
if (user == null)
user = EssentiaPlugin.instance().storageProvider().loadUser(offlinePlayer.getUniqueId());
}
@Override
public @NotNull Home convert(String nativeType) throws CommandSyntaxException {
try {
return user.getHome(nativeType);
} catch (Exception e) {
Message message = MessageComponentSerializer.message().serialize(Component.text("Invalid Home %s!".formatted(nativeType), NamedTextColor.RED));
throw new CommandSyntaxException(new SimpleCommandExceptionType(message), message);
}
}
@Override
public @NotNull ArgumentType<String> getNativeType() {
return StringArgumentType.word();
}
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
for (String home : user.getHomes()) {
builder.suggest(home);
}
return CompletableFuture.completedFuture(
builder.build()
);
}
}

View File

@ -0,0 +1,34 @@
package com.alttd.essentia.commands.argumement;
import com.mojang.brigadier.Message;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import io.papermc.paper.command.brigadier.MessageComponentSerializer;
import io.papermc.paper.command.brigadier.argument.CustomArgumentType;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
public class OfflinePlayerArgument implements CustomArgumentType.Converted<OfflinePlayer, String> {
@Override
public @NotNull OfflinePlayer convert(String nativeType) throws CommandSyntaxException {
try {
return Bukkit.getOfflinePlayer(nativeType);
} catch (Exception e) {
Message message = MessageComponentSerializer.message().serialize(Component.text("Invalid PlayerName %s!".formatted(nativeType), NamedTextColor.RED));
throw new CommandSyntaxException(new SimpleCommandExceptionType(message), message);
}
}
@Override
public @NotNull ArgumentType<String> getNativeType() {
return StringArgumentType.word();
}
}

View File

@ -0,0 +1,50 @@
package com.alttd.essentia.commands.argumement;
import com.mojang.brigadier.Message;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import io.papermc.paper.command.brigadier.MessageComponentSerializer;
import io.papermc.paper.command.brigadier.argument.CustomArgumentType;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.CompletableFuture;
public class OfflinePlayerCompletingArgument implements CustomArgumentType.Converted<OfflinePlayer, String> {
@Override
public @NotNull OfflinePlayer convert(String nativeType) throws CommandSyntaxException {
try {
return Bukkit.getOfflinePlayer(nativeType);
} catch (Exception e) {
Message message = MessageComponentSerializer.message().serialize(Component.text("Invalid PlayerName %s!".formatted(nativeType), NamedTextColor.RED));
throw new CommandSyntaxException(new SimpleCommandExceptionType(message), message);
}
}
@Override
public @NotNull ArgumentType<String> getNativeType() {
return StringArgumentType.word();
}
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
for (Player player : Bukkit.getOnlinePlayers()) {
builder.suggest(player.getName(), MessageComponentSerializer.message().serialize(player.displayName()));
}
return CompletableFuture.completedFuture(
builder.build()
);
}
}

View File

@ -1,39 +1,62 @@
package com.alttd.essentia.commands.player; package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin; 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.EssentiaEvent;
import com.alttd.essentia.api.events.PlayerTeleportBackEvent; import com.alttd.essentia.api.events.PlayerTeleportBackEvent;
import com.alttd.essentia.tasks.TeleportSounds;
import com.alttd.essentia.api.user.User; 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.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class BackCommand extends PlayerSubCommand { public class BackCommand implements EssentiaCommand {
public BackCommand(EssentiaPlugin plugin) { static String commandName = "back";
super(plugin, "back");
}
@Override @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); Location back = user.getBackLocation(false);
if (back == null) { if (back == null) {
player.sendRichMessage(Config.NO_BACK_LOCATION); target.sendRichMessage(Config.NO_BACK_LOCATION);
return true; return;
} }
EssentiaEvent event = new PlayerTeleportBackEvent(player, back); EssentiaEvent event = new PlayerTeleportBackEvent(target, back);
if (!event.callEvent()) { if (!event.callEvent()) {
return true; return;
} }
new TeleportSounds(back, player.getLocation())
.runTaskLater(plugin, 1);
player.teleportAsync(back).thenAccept(result -> new TeleportSounds(back, target.getLocation())
player.sendRichMessage(Config.TELEPORTING_BACK)); .runTaskLater(EssentiaPlugin.instance(), 1);
return true;
target.teleportAsync(back).thenAccept(result ->
target.sendRichMessage(Config.TELEPORTING_BACK));
} }
} }

View File

@ -1,39 +1,68 @@
package com.alttd.essentia.commands.player; package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin; 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.configuration.Config;
import com.alttd.essentia.api.events.EssentiaEvent; import com.alttd.essentia.api.events.EssentiaEvent;
import com.alttd.essentia.api.events.PlayerTeleportBackEvent; import com.alttd.essentia.api.events.PlayerTeleportBackEvent;
import com.alttd.essentia.tasks.TeleportSounds; import com.alttd.essentia.tasks.TeleportSounds;
import com.alttd.essentia.api.user.User; 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.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class DeathBackCommand extends PlayerSubCommand { import java.util.List;
public DeathBackCommand(EssentiaPlugin plugin) { public class DeathBackCommand implements EssentiaCommand {
super(plugin, "back");
} static String commandName = "deathback";
@Override @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); Location back = user.getBackLocation(true);
if (back == null) { if (back == null) {
player.sendRichMessage(Config.NO_DEATH_LOCATION); target.sendRichMessage(Config.NO_DEATH_LOCATION);
return true; return;
} }
EssentiaEvent event = new PlayerTeleportBackEvent(player, back); EssentiaEvent event = new PlayerTeleportBackEvent(target, back);
if (!event.callEvent()) { if (!event.callEvent()) {
return true; return;
} }
new TeleportSounds(back, player.getLocation()) new TeleportSounds(back, target.getLocation())
.runTaskLater(plugin, 1); .runTaskLater(EssentiaPlugin.instance(), 1);
player.teleportAsync(back).thenAccept(result -> target.teleportAsync(back).thenAccept(result ->
player.sendRichMessage(Config.TELEPORTING_BACK_DEATH)); target.sendRichMessage(Config.TELEPORTING_BACK_DEATH));
return true; }
public List<String> aliases() {
return List.of("dback");
} }
} }

View File

@ -1,41 +1,150 @@
package com.alttd.essentia.commands.player; package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin; 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.configuration.Config;
import com.alttd.essentia.api.events.EssentiaEvent; import com.alttd.essentia.api.events.EssentiaEvent;
import com.alttd.essentia.api.events.PlayerRemoveHomeEvent; import com.alttd.essentia.api.events.PlayerRemoveHomeEvent;
import com.alttd.essentia.api.user.User; 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 net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; 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) { public class DelHomeCommand implements EssentiaCommand {
super(plugin, "deletehome");
} static String commandName = "delhome";
@Override @Override
protected boolean execute(Player player, User user, String... args) { public @NotNull LiteralCommandNode<CommandSourceStack> command() {
// TODO -- subcommand to remove other player homes final LiteralArgumentBuilder<CommandSourceStack> builder =
// if (args.length > 1) { Commands.literal(commandName)
// if (!player.hasPermission("essentia.command.delhome.other")) { .requires(
// return true; 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 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)) { if (!user.hasHome(home)) {
player.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.unparsed("home", home)); sender.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.unparsed("home", home));
return true; return;
} }
EssentiaEvent event = new PlayerRemoveHomeEvent(player, home);
EssentiaEvent event = new PlayerRemoveHomeEvent(sender, home);
if (!event.callEvent()) { if (!event.callEvent()) {
return true; return;
} }
user.setHome(home, null); user.setHome(home, null);
player.sendRichMessage(Config.HOME_DELETED, Placeholder.unparsed("home", home)); sender.sendRichMessage(Config.HOME_DELETED, Placeholder.unparsed("home", home));
return true;
} }
} }

View File

@ -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).get(0);
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);
}
}

View File

@ -1,82 +1,93 @@
package com.alttd.essentia.commands.player; package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin; 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.EssentiaEvent;
import com.alttd.essentia.api.events.PlayerTeleportHomeEvent; 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.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.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.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.apache.commons.lang3.BooleanUtils;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.List; import java.util.List;
public class HomeCommand extends PlayerSubCommand { // TODO - home other
public class HomeCommand implements EssentiaCommand {
public HomeCommand(EssentiaPlugin plugin) { static String commandName = "home";
super(plugin, "home");
}
@Override @Override
protected boolean execute(Player player, User user, String... args) { public @NotNull LiteralCommandNode<CommandSourceStack> command() {
String home; final LiteralArgumentBuilder<CommandSourceStack> builder =
if (args.length == 0) { Commands.literal(commandName)
int count = user.getHomeCount(); .requires(
if (count <= 1) { commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
home = user.getHomes().stream().findFirst().orElse(null); commandSourceStack.getSender() instanceof Player
} else { )
player.sendRichMessage(Config.SPECIFY_HOME, Placeholder.unparsed("homelist", String.join(", ", user.getHomes()))); .executes((source) -> {
return true; if (source.getSource().getSender() instanceof Player player)
} execute(player, player, "home");
if (home == null || home.isEmpty()) {
player.sendRichMessage(Config.HOME_NOT_SET); return 1;
return true; })
} .then(
return true; Commands.argument("name", StringArgumentType.word())
} else { .executes((source) -> {
home = args[0]; if (!(source.getSource().getSender() instanceof Player player))
} return 1;
// TODO - subcommand to teleport to others homes
// if (args.length > 1) { String name = source.getArgument("name", String.class);
// if (!player.hasPermission("essentia.command.home.other")) { execute(player, player, name);
// return true 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); Home essentiaHome = user.getHome(home);
if (essentiaHome == null) { if (essentiaHome == null) {
player.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.parsed("home", home)); sender.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.parsed("home", home));
return true; return;
} }
Location homeLoc = essentiaHome.location(); Location homeLoc = essentiaHome.location();
if (homeLoc == null) { if (homeLoc == null) {
player.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.parsed("home", home)); sender.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.parsed("home", home));
return true; 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()) { if (!event.callEvent()) {
return true; return;
} }
new TeleportSounds(homeLoc, player.getLocation()) new TeleportSounds(homeLoc, target.getLocation())
.runTaskLater(plugin, 1); .runTaskLater(EssentiaPlugin.instance(), 1);
String homeName = home; String homeName = home;
player.teleportAsync(homeLoc).thenAccept(result -> target.teleportAsync(homeLoc).thenAccept(result ->
player.sendRichMessage(Config.HOME_TELEPORT, Placeholder.unparsed("home", homeName)) target.sendRichMessage(Config.HOME_TELEPORT, Placeholder.unparsed("home", homeName))
); );
return true;
} }
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
if (args.length == 1) {
return plugin.userManager().getUser((Player) sender).getMatchingHomeNames(args[0]);
}
return null;
}
} }

View File

@ -1,29 +1,66 @@
package com.alttd.essentia.commands.player; package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin; 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.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 net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class HomeListCommand extends PlayerSubCommand { import java.util.List;
public HomeListCommand(EssentiaPlugin plugin) { public class HomeListCommand implements EssentiaCommand {
super(plugin, "homes");
} static String commandName = "homelist";
@Override @Override
protected boolean execute(Player player, User user, String... args) { public @NotNull LiteralCommandNode<CommandSourceStack> command() {
// TODO - subcommand to list other homes final LiteralArgumentBuilder<CommandSourceStack> builder =
// if (args.length > 0) { Commands.literal(commandName)
// if (!player.hasPermission("essentia.command.homes.other")) { .requires(
// return true; 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) -> {
CommandSourceStack sourceStack = source.getSource();
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> // TODO - clickable homes that run /home <name>
player.sendRichMessage(Config.HOME_LIST, Placeholder.unparsed("homelist", String.join(", ", user.getHomes()))); sender.sendRichMessage(Config.HOME_LIST, Placeholder.unparsed("homelist", String.join(", ", user.getHomes())));
return true;
} }
public List<String> aliases() {
return List.of("homes");
}
} }

View File

@ -1,50 +1,120 @@
package com.alttd.essentia.commands.player; package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin; 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.EssentiaEvent;
import com.alttd.essentia.api.events.PlayerSetHomeEvent; import com.alttd.essentia.api.events.PlayerSetHomeEvent;
import com.alttd.essentia.api.user.User; 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 net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class SetHomeCommand extends PlayerSubCommand { public class SetHomeCommand implements EssentiaCommand {
static String commandName = "sethome";
public SetHomeCommand(EssentiaPlugin plugin) {
super(plugin, "sethome");
}
@Override @Override
protected boolean execute(Player player, User user, String... args) { public @NotNull LiteralCommandNode<CommandSourceStack> command() {
// TODO -- subcommand to allow setting other player homes final LiteralArgumentBuilder<CommandSourceStack> builder =
// if (args.length > 1) { Commands.literal(commandName)
// if (!player.hasPermission("essentia.command.sethome.other")) { .requires(
// return true; 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(".")) { if (home.contains(".")) {
player.sendRichMessage(Config.INVALID_HOME_NAME); sender.sendRichMessage(Config.INVALID_HOME_NAME);
return true; 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 limit = 5; // TODO -- player home limits hardcoded for now
int count = user.getHomeCount(); int count = user.getHomeCount();
if (limit >= 0 && count >= limit) { if (limit >= 0 && count >= limit) {
player.sendRichMessage(Config.HOME_SET_MAX, Placeholder.unparsed("limit", String.valueOf(limit))); sender.sendRichMessage(Config.HOME_SET_MAX, Placeholder.unparsed("limit", String.valueOf(limit)));
return true; 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()) { if (!event.callEvent()) {
return true; return;
} }
user.setHome(home, homeLoc); user.setHome(home, homeLoc);
player.sendRichMessage(Config.HOME_SET, Placeholder.unparsed("home", home)); sender.sendRichMessage(Config.HOME_SET, Placeholder.unparsed("home", home));
return true;
} }
} }

View File

@ -1,40 +1,76 @@
package com.alttd.essentia.commands.player; package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin; import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.commands.PlayerSubCommand; import com.alttd.essentia.api.events.PlayerTeleportBackEvent;
import com.alttd.essentia.api.events.PlayerTeleportSpawnEvent;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config; import com.alttd.essentia.configuration.Config;
import com.alttd.essentia.api.events.EssentiaEvent; import com.alttd.essentia.api.events.EssentiaEvent;
import com.alttd.essentia.api.events.PlayerTeleportSpawnEvent;
import com.alttd.essentia.tasks.TeleportSounds; import com.alttd.essentia.tasks.TeleportSounds;
import com.alttd.essentia.api.user.User; 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.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class SpawnCommand extends PlayerSubCommand { public class SpawnCommand implements EssentiaCommand {
public SpawnCommand(EssentiaPlugin plugin) { static String commandName = "spawn";
super(plugin, "back");
}
@Override @Override
protected boolean execute(Player player, User user, String... args) { public @NotNull LiteralCommandNode<CommandSourceStack> command() {
World world = plugin.getServer().getWorld(Config.SPAWN_WORLD); 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).get(0);
execute((Player) 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) { if (world == null) {
player.sendRichMessage("<red>Could not get the configured spawn world! contact and administrator"); sender.sendRichMessage("<red>Could not get the configured spawn world! contact an administrator");
return true; return;
} }
Location spawnLocation = world.getSpawnLocation(); Location spawnLocation = world.getSpawnLocation();
EssentiaEvent event = new PlayerTeleportSpawnEvent(player, spawnLocation); EssentiaEvent event = new PlayerTeleportSpawnEvent(target, spawnLocation);
if (!event.callEvent()) { if (!event.callEvent()) {
return true; return;
} }
new TeleportSounds(spawnLocation, player.getLocation()) new TeleportSounds(spawnLocation, target.getLocation())
.runTaskLater(plugin, 1); .runTaskLater(EssentiaPlugin.instance(), 1);
player.teleportAsync(spawnLocation).thenAccept(result -> target.teleportAsync(spawnLocation).thenAccept(result ->
player.sendRichMessage("Teleporting to spawn")); target.sendRichMessage("Teleporting to spawn"));
return true;
} }
} }

View File

@ -1,27 +1,57 @@
package com.alttd.essentia.commands.player; package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin; 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.configuration.Config;
import com.alttd.essentia.api.request.Request; import com.alttd.essentia.api.request.Request;
import com.alttd.essentia.api.user.User; 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.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class TeleportAcceptCommand extends PlayerSubCommand { import java.util.List;
public TeleportAcceptCommand(EssentiaPlugin plugin) { public class TeleportAcceptCommand implements EssentiaCommand {
super(plugin, "teleportaccept");
} static String commandName = "teleportaccept";
@Override @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(); Request request = user.request();
if (request == null) { if (request == null) {
player.sendRichMessage(Config.NO_PENDING_REQUESTS); player.sendRichMessage(Config.NO_PENDING_REQUESTS);
return true; return;
} }
request.accept(); request.accept();
return true;
} }
@Override
public List<String> aliases() {
return List.of("tpyes", "tpaccpt");
}
} }

View File

@ -1,27 +1,57 @@
package com.alttd.essentia.commands.player; package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin; 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.configuration.Config;
import com.alttd.essentia.api.request.Request; import com.alttd.essentia.api.request.Request;
import com.alttd.essentia.api.user.User; 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.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class TeleportDenyCommand extends PlayerSubCommand { import java.util.List;
public TeleportDenyCommand(EssentiaPlugin plugin) { public class TeleportDenyCommand implements EssentiaCommand {
super(plugin, "teleportdeny");
} static String commandName = "teleportdeny";
@Override @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(); Request request = user.request();
if (request == null) { if (request == null) {
player.sendRichMessage(Config.NO_PENDING_REQUESTS); player.sendRichMessage(Config.NO_PENDING_REQUESTS);
return true; return;
} }
request.deny(); request.deny();
return true;
} }
@Override
public List<String> aliases() {
return List.of("tpdeny", "tpno");
}
} }

View File

@ -1,72 +1,84 @@
package com.alttd.essentia.commands.player; package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin; 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.configuration.Config;
import com.alttd.essentia.request.TeleportEssentiaRequest; import com.alttd.essentia.request.TeleportEssentiaRequest;
import com.alttd.essentia.api.user.User; 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.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; 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.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public class TeleportRequestCommand extends PlayerSubCommand { public class TeleportRequestCommand implements EssentiaCommand {
public TeleportRequestCommand(EssentiaPlugin plugin) { static String commandName = "teleportrequesthere";
super(plugin, "teleportrequest");
}
@Override @Override
protected boolean execute(Player player, User user, String... args) { public @NotNull LiteralCommandNode<CommandSourceStack> command() {
if (args.length < 1) { final LiteralArgumentBuilder<CommandSourceStack> builder =
player.sendRichMessage(Config.NO_PLAYER_SPECIFIED); Commands.literal(commandName)
return true; .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).get(0);
execute(player, target);
return 1;
})
);
return builder.build();
}
public void execute(Player player, Player target) {
if (target == null) { if (target == null) {
player.sendRichMessage(Config.PLAYER_NOT_ONLINE); player.sendRichMessage(Config.PLAYER_NOT_ONLINE);
return true; return;
} }
if (target == player) { if (target == player) {
player.sendRichMessage(Config.REQUEST_TO_SELF); player.sendRichMessage(Config.REQUEST_TO_SELF);
return true; return;
} }
TagResolver placeholders = TagResolver.resolver( TagResolver placeholders = TagResolver.resolver(
Placeholder.component("target", target.displayName()) Placeholder.component("target", target.displayName())
); );
User targetUser = plugin.userManager().getUser(target); User targetUser = EssentiaPlugin.instance().userManager().getUser(target);
if (targetUser.request() != null) { if (targetUser.request() != null) {
player.sendRichMessage(Config.TARGET_HAS_PENDING_REQUEST, placeholders); player.sendRichMessage(Config.TARGET_HAS_PENDING_REQUEST, placeholders);
return true; return;
} }
if (!targetUser.getUserSettings().allowTeleports()) { if (!targetUser.getUserSettings().allowTeleports()) {
player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders); player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders);
return true; return;
} }
targetUser.request(new TeleportEssentiaRequest(plugin, player, target)); targetUser.request(new TeleportEssentiaRequest(EssentiaPlugin.instance(), player, target));
return true;
} }
@Override @Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { public List<String> aliases() {
if (args.length == 1) { return List.of("tpa");
String name = args[0].trim().toLowerCase();
return Bukkit.getOnlinePlayers().stream()
.map(Player::getName)
.filter(playerName -> playerName.toLowerCase().startsWith(name)).collect(Collectors.toList());
}
return null;
} }
} }

View File

@ -1,72 +1,84 @@
package com.alttd.essentia.commands.player; package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin; 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.configuration.Config;
import com.alttd.essentia.request.TeleportHereEssentiaRequest;
import com.alttd.essentia.api.user.User; 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.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; 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.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public class TeleportRequestHereCommand extends PlayerSubCommand { public class TeleportRequestHereCommand implements EssentiaCommand {
public TeleportRequestHereCommand(EssentiaPlugin plugin) { static String commandName = "teleportrequesthere";
super(plugin, "teleportrequesthere");
}
@Override @Override
protected boolean execute(Player player, User user, String... args) { public @NotNull LiteralCommandNode<CommandSourceStack> command() {
if (args.length < 1) { final LiteralArgumentBuilder<CommandSourceStack> builder =
player.sendRichMessage(Config.NO_PLAYER_SPECIFIED); Commands.literal(commandName)
return true; .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).get(0);
execute(player, target);
return 1;
})
);
return builder.build();
}
public void execute(Player player, Player target) {
if (target == null) { if (target == null) {
player.sendRichMessage(Config.PLAYER_NOT_ONLINE); player.sendRichMessage(Config.PLAYER_NOT_ONLINE);
return true; return;
} }
if (target == player) { if (target == player) {
player.sendRichMessage(Config.REQUEST_TO_SELF); player.sendRichMessage(Config.REQUEST_TO_SELF);
return true; return;
} }
TagResolver placeholders = TagResolver.resolver( TagResolver placeholders = TagResolver.resolver(
Placeholder.component("target", target.displayName()) Placeholder.component("target", target.displayName())
); );
User targetUser = plugin.userManager().getUser(target); User targetUser = EssentiaPlugin.instance().userManager().getUser(target);
if (targetUser.request() != null) { if (targetUser.request() != null) {
player.sendRichMessage(Config.TARGET_HAS_PENDING_REQUEST, placeholders); player.sendRichMessage(Config.TARGET_HAS_PENDING_REQUEST, placeholders);
return true; return;
} }
if (!targetUser.getUserSettings().allowTeleports()) { if (!targetUser.getUserSettings().allowTeleports()) {
player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders); player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders);
return true; return;
} }
targetUser.request(new TeleportHereEssentiaRequest(plugin, player, target)); targetUser.request(new TeleportHereEssentiaRequest(EssentiaPlugin.instance(), player, target));
return true;
} }
@Override @Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { public List<String> aliases() {
if (args.length == 1) { return List.of("tpahere", "tphere");
String name = args[0].trim().toLowerCase();
return Bukkit.getOnlinePlayers().stream()
.map(Player::getName)
.filter(playerName -> playerName.toLowerCase().startsWith(name)).collect(Collectors.toList());
}
return null;
} }
} }

View File

@ -1,27 +1,70 @@
package com.alttd.essentia.commands.player; package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin; 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.configuration.Config;
import com.alttd.essentia.api.user.User; 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.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.BooleanUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class TeleportToggleCommand extends PlayerSubCommand { import java.util.List;
public TeleportToggleCommand(EssentiaPlugin plugin) { public class TeleportToggleCommand implements EssentiaCommand {
super(plugin, "teleporttoggle");
} static String commandName = "teleporttoggle";
@Override @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).get(0);
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()); user.getUserSettings().allowTeleports(!user.getUserSettings().allowTeleports());
TagResolver placeholders = TagResolver.resolver( TagResolver placeholders = TagResolver.resolver(
Placeholder.parsed("toggle", BooleanUtils.toStringOnOff(user.getUserSettings().allowTeleports())) Placeholder.parsed("toggle", BooleanUtils.toStringOnOff(user.getUserSettings().allowTeleports()))
); );
player.sendRichMessage(Config.TELEPORT_TOGGLE_SET, placeholders); sender.sendRichMessage(Config.TELEPORT_TOGGLE_SET, placeholders);
return true;
} }
@Override
public List<String> aliases() {
return List.of("tptoggle");
}
} }

View File

@ -35,7 +35,7 @@ public class Config {
config.load(CONFIG_FILE); config.load(CONFIG_FILE);
} catch (IOException ignore) { } catch (IOException ignore) {
} catch (InvalidConfigurationException ex) { } catch (InvalidConfigurationException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Could not load config.yml, please correct your syntax errors", ex); EssentiaPlugin.instance().getLogger().log(Level.SEVERE, "Could not load config.yml, please correct your syntax errors", ex);
Throwables.throwIfUnchecked(ex); Throwables.throwIfUnchecked(ex);
} }
config.options().header(HEADER); config.options().header(HEADER);
@ -44,6 +44,7 @@ public class Config {
version = getInt("config-version", 1); version = getInt("config-version", 1);
set("config-version", 1); set("config-version", 1);
EssentiaPlugin.instance().getLogger().info("Essentia Configuration loaded!");
readConfig(Config.class, null); readConfig(Config.class, null);
} }
@ -57,7 +58,7 @@ public class Config {
} catch (InvocationTargetException ex) { } catch (InvocationTargetException ex) {
Throwables.throwIfUnchecked(ex); Throwables.throwIfUnchecked(ex);
} catch (Exception ex) { } catch (Exception ex) {
Bukkit.getLogger().log(Level.SEVERE, "Error invoking " + method, ex); EssentiaPlugin.instance().getLogger().log(Level.SEVERE, "Error invoking " + method, ex);
} }
} }
} }
@ -69,7 +70,7 @@ public class Config {
try { try {
config.save(CONFIG_FILE); config.save(CONFIG_FILE);
} catch (IOException ex) { } catch (IOException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Could not save " + CONFIG_FILE, ex); EssentiaPlugin.instance().getLogger().log(Level.SEVERE, "Could not save " + CONFIG_FILE, ex);
} }
} }
@ -104,7 +105,7 @@ public class Config {
} }
protected static void log(Level level, String s) { protected static void log(Level level, String s) {
Bukkit.getLogger().log(level, s); EssentiaPlugin.instance().getLogger().log(level, s);
} }
public static int TELEPORT_REQUEST_TIMEOUT = 30; public static int TELEPORT_REQUEST_TIMEOUT = 30;
@ -171,6 +172,9 @@ public class Config {
public static String TOGGLED_FLIGHT_BY_OTHER = "Toggled flight <status> on <target>."; public static String TOGGLED_FLIGHT_BY_OTHER = "Toggled flight <status> on <target>.";
public static String TOGGLED_FLIGHT_PLAYER = "<player> toggled flight <status>."; public static String TOGGLED_FLIGHT_PLAYER = "<player> toggled flight <status>.";
public static String TOGGLED_FLIGHT = "Toggled fly <status>."; public static String TOGGLED_FLIGHT = "Toggled fly <status>.";
public static String TOGGLED_GOD_BY_OTHER = "Toggled God mode <status> on <target>.";
public static String TOGGLED_GOD_PLAYER = "<player> toggled God mode <status>.";
public static String TOGGLED_GOD = "Toggled God mode <status>.";
public static String NO_BACK_LOCATION = "No back location found!"; public static String NO_BACK_LOCATION = "No back location found!";
public static String TELEPORTING_BACK = "Teleporting back to previous location."; public static String TELEPORTING_BACK = "Teleporting back to previous location.";
public static String NO_DEATH_LOCATION = "No death location found!"; public static String NO_DEATH_LOCATION = "No death location found!";
@ -191,6 +195,10 @@ public class Config {
public static String BURN_SELF = "You have set yourself on fire."; public static String BURN_SELF = "You have set yourself on fire.";
public static String BURN_OTHER = "<target>'s has been set in fire."; public static String BURN_OTHER = "<target>'s has been set in fire.";
public static String BURN_BY_OTHER = "<requester> has set you on fire."; public static String BURN_BY_OTHER = "<requester> has set you on fire.";
public static String SMITE_SELF = "You have smited yourself.";
public static String SMITE_OTHER = "<target> has been smited.";
public static String SMITE_BY_OTHER = "<requester> has smited you.";
private static void messages() { private static void messages() {
REQUEST_TIMED_OUT = getString("messages.request.time-out", REQUEST_TIMED_OUT); REQUEST_TIMED_OUT = getString("messages.request.time-out", REQUEST_TIMED_OUT);
TELEPORT_ACCEPT_TARGET = getString("messages.request.teleport-accept-target", TELEPORT_ACCEPT_TARGET); TELEPORT_ACCEPT_TARGET = getString("messages.request.teleport-accept-target", TELEPORT_ACCEPT_TARGET);
@ -242,7 +250,7 @@ public class Config {
FEED_BY_OTHER = getString("messages.command.feed.feed-by-other", FEED_BY_OTHER); FEED_BY_OTHER = getString("messages.command.feed.feed-by-other", FEED_BY_OTHER);
} }
public static String STORAGE_TYPE = "mysql"; public static String STORAGE_TYPE = "YAML";
public static boolean AUTO_SAVE = true; public static boolean AUTO_SAVE = true;
public static int AUTO_SAVE_DELAY = 60; public static int AUTO_SAVE_DELAY = 60;
public static String MYSQL_IP = "localhost"; public static String MYSQL_IP = "localhost";

View File

@ -0,0 +1,131 @@
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 com.alttd.essentia.configuration.Config;
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 isCuffed(Player player) {
UserManager userManager = plugin.userManager();
User user = userManager.getUser(player);
if (user == null)
return false;
return user.isCuffed();
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (!isCuffed(event.getPlayer()))
return;
cancelEvent(event, event.getPlayer());
}
@EventHandler
public void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
if (!isCuffed(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 (!isCuffed(player))
return;
cancelEvent(event, player);
}
@EventHandler
public void onPlayerDropItemEvent(PlayerDropItemEvent event) {
if (!isCuffed(event.getPlayer()))
return;
cancelEvent(event, event.getPlayer());
}
@EventHandler
public void onProjectileLaunchEvent(ProjectileLaunchEvent event) {
if (!(event.getEntity().getShooter() instanceof Player player))
return;
if (!isCuffed(player))
return;
cancelEvent(event, player);
}
@EventHandler
public void onnEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player player))
return;
if (!isCuffed(player))
return;
cancelEvent(event, player);
}
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
if (!(event.getEntity() instanceof Player player))
return;
if (!isCuffed(player))
return;
cancelEvent(event, player);
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
if (!isCuffed(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);
return;
}
}
void cancelEvent(Cancellable event, Player player) {
event.setCancelled(true);
player.sendRichMessage("You can not do this while cuffed."); // TODO - config
}
}

View File

@ -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);
}
}

View File

@ -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 (!isGodMode(player))
return;
event.setCancelled(true);
}
@EventHandler
public void onPhantomPreSpawn(PhantomPreSpawnEvent event) {
if (!(event.getSpawningEntity() instanceof Player player))
return;
if (!isGodMode(player))
return;
event.setCancelled(true);
event.setShouldAbortSpawn(true);
}
@EventHandler
public void onEntityTargetLivingEntity(EntityTargetLivingEntityEvent event) {
if (!(event.getEntity() instanceof Player player))
return;
if (!isGodMode(player))
return;
event.setCancelled(true);
}
private boolean isGodMode(Player player) {
UserManager userManager = plugin.userManager();
User user = userManager.getUser(player);
if (user == null)
return false;
UserSettings userSettings = user.getUserSettings();
return userSettings.godMode();
}
}

View File

@ -22,8 +22,8 @@ public class PlayerListener implements Listener {
private final EssentiaPlugin plugin; private final EssentiaPlugin plugin;
private final Set<PlayerTeleportEvent.TeleportCause> backAllowCauses = new HashSet<>(); private final Set<PlayerTeleportEvent.TeleportCause> backAllowCauses = new HashSet<>();
public PlayerListener(EssentiaPlugin plugin) { public PlayerListener() {
this.plugin = plugin; this.plugin = EssentiaPlugin.instance();
backAllowCauses.add(PlayerTeleportEvent.TeleportCause.PLUGIN); backAllowCauses.add(PlayerTeleportEvent.TeleportCause.PLUGIN);
backAllowCauses.add(PlayerTeleportEvent.TeleportCause.COMMAND); backAllowCauses.add(PlayerTeleportEvent.TeleportCause.COMMAND);

View File

@ -2,7 +2,6 @@ package com.alttd.essentia.model;
import com.alttd.essentia.api.model.UserSettings; import com.alttd.essentia.api.model.UserSettings;
import lombok.Getter; import lombok.Getter;
import lombok.Setter;
@Getter @Getter
public class EssentiaUserSettings implements UserSettings { public class EssentiaUserSettings implements UserSettings {

View File

@ -2,6 +2,7 @@ package com.alttd.essentia.storage;
import com.alttd.essentia.EssentiaPlugin; import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.storage.mysql.SQLStorageProvider; import com.alttd.essentia.storage.mysql.SQLStorageProvider;
import com.alttd.essentia.storage.sqlite.SQLiteStorageProvider;
import com.alttd.essentia.storage.yaml.YamlStorageProvider; import com.alttd.essentia.storage.yaml.YamlStorageProvider;
import java.io.File; import java.io.File;
@ -16,9 +17,10 @@ public class StorageManager {
public StorageProvider storageProvider(StorageType type) { public StorageProvider storageProvider(StorageType type) {
return switch (type) { return switch (type) {
case MYSQL -> new SQLStorageProvider(plugin); // case MYSQL -> new SQLStorageProvider(plugin); // FIXME
case YAML -> new YamlStorageProvider(plugin, plugin.getDataFolder().getPath() + File.separator + "PlayerData"); case YAML -> new YamlStorageProvider(plugin, plugin.getDataFolder().getPath() + File.separator + "PlayerData");
case SQLITE -> throw new UnsupportedOperationException(); // FIXME // case SQLITE -> new SQLiteStorageProvider(plugin); // FIXME
default -> throw new UnsupportedOperationException();
}; };
} }

View File

@ -39,9 +39,12 @@ public class YamlStorageProvider extends StorageProvider {
.backLocation(getStoredLocation(config,"teleports.back")) .backLocation(getStoredLocation(config,"teleports.back"))
.deathLocation(getStoredLocation(config,"teleports.death")) .deathLocation(getStoredLocation(config,"teleports.death"))
.homes(getHomeData(config)) .homes(getHomeData(config))
.cuffed(config.getBoolean("cuffed", false))
.userSettings(new EssentiaUserSettings .userSettings(new EssentiaUserSettings
.Builder() .Builder()
.flying(config.getBoolean("flying", false))
.allowTeleports(config.getBoolean("allow-teleports", true)) .allowTeleports(config.getBoolean("allow-teleports", true))
.godMode(config.getBoolean("god", false))
.build()) .build())
.build(); .build();
} }

View File

@ -19,6 +19,7 @@ public class EssentiaUser implements User {
protected Map<String, Home> homes; protected Map<String, Home> homes;
protected UserSettings userSettings; protected UserSettings userSettings;
protected Request request; protected Request request;
protected boolean cuffed;
private boolean saving; private boolean saving;
private boolean needsSaving; // can we use a decorator for this to set it to true on every change? 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; this.request = request;
} }
@Override
public boolean isCuffed() {
return cuffed;
}
@Override
public void setCuffed(boolean cuffed) {
this.cuffed = cuffed;
}
public static class Builder { public static class Builder {
protected UUID uuid; protected UUID uuid;
@ -133,6 +144,7 @@ public class EssentiaUser implements User {
protected Location deathLocation = null; protected Location deathLocation = null;
protected Map<String, Home> homes = new HashMap<>(); protected Map<String, Home> homes = new HashMap<>();
protected UserSettings userSettings = null; protected UserSettings userSettings = null;
protected boolean cuffed = false;
public Builder uuid(UUID uuid) { public Builder uuid(UUID uuid) {
this.uuid = uuid; this.uuid = uuid;
@ -159,6 +171,11 @@ public class EssentiaUser implements User {
return this; return this;
} }
public Builder cuffed(boolean cuffed) {
this.cuffed = cuffed;
return this;
}
public EssentiaUser build() { public EssentiaUser build() {
return new EssentiaUser(this); return new EssentiaUser(this);
} }

View File

@ -4,107 +4,4 @@ main: com.alttd.essentia.EssentiaPlugin
description: Altitude essentials ;) description: Altitude essentials ;)
authors: authors:
- destro174 - destro174
api-version: "1.20" api-version: "1.21"
commands:
essentia:
description: Reload configs.
permission: essentia.command.essentia-reload
usage: /<command> (reload)
teleportaccept:
description: Accept teleport request.
permission: essentia.command.teleportaccept
usage: /<command>
aliases:
- tpaccept
teleportdeny:
description: Decline teleport request.
permission: essentia.command.teleportdeny
usage: /<command>
aliases:
- tpdeny
teleportrequest:
description: Request to teleport to another player.
permission: essentia.command.teleportrequest
usage: /<command> player
aliases:
- tpa
- tprequest
- tparequest
teleportrequesthere:
description: Request another player to teleport to you.
permission: essentia.command.teleportrequesthere
usage: /<command> player
aliases:
- tpah
- tpahere
teleporttoggle:
description: Toggle teleport requests on/off.
permission: essentia.command.teleporttoggle
usage: /<command>
aliases:
- tptoggle
clearinventory:
description: Clears your inventory.
permission: essentia.command.clearinventory
usage: /<command> (player)
home:
description: Teleports the player home.
permission: essentia.command.home
usage: /<command> (home (player))
homes:
description: List the player's homes.
permission: essentia.command.homes
usage: /<command> (player)
aliases:
- listhomes
sethome:
description: Sets the player's home.
permission: essentia.command.sethome
usage: /<command> (home (player))
aliases:
- homeset
deletehome:
description: Deletes a home.
permission: essentia.command.deletehome
usage: /<command> [home (player)]
aliases:
- delhome
back:
description: Go back to previous location.
permission: essentia.command.back
usage: /<command>
deathback:
description: Go back to previous death location.
permission: essentia.command.deathback
usage: /<command>
aliases:
- dback
fly:
description: Toggles creative flymode for yourself or another player.
permission: essentia.command.fly
usage: /<command> (player)
gamemode:
description: Set gamemode for yourself or another player.
permission: essentia.command.gamemode
usage: /<command> (player)
aliases:
- gm
heal:
description: Heals yourself or another player.
permission: essentia.command.heal
usage: /<command> (player)
aliases:
- health
feed:
description: Refill hunger and saturation.
permission: essentia.command.feed
usage: /<command> (player)
enchant:
description: Enchants the item in hand
permission: essentia.command.enchant
usage: /<command> [enchantment/all] (level) (unsafe)
spawn:
description: Teleport yourself or another player to spawn.
permission: essentia.command.spawn
usage: /<command>