transition to paper plugin
All checks were successful
Build / build (push) Successful in 3m22s

This commit is contained in:
unurled 2024-07-03 18:44:00 +02:00
parent ce0ffdbdfc
commit 7816bbe384
19 changed files with 417 additions and 525 deletions

View file

@ -29,8 +29,7 @@ dependencies {
implementation("redis.clients:jedis:${redisVersion}")
implementation("xyz.xenondevs.invui:invui-core:${invuiVersion}")
implementation("xyz.xenondevs.invui:inventory-access-r20:${invuiVersion}:remapped-mojang")
compileOnly("xyz.xenondevs.invui:invui:${invuiVersion}")
}
java {
@ -55,7 +54,7 @@ tasks {
"apiVersion" to "1.20"
)
inputs.properties(props)
filesMatching("plugin.yml") {
filesMatching("paper-plugin.yml") {
expand(props)
}
}
@ -70,7 +69,7 @@ tasks {
relocate("org.jetbrains", "libs.org.jetbrains")
relocate("org.json", "libs.org.json")
relocate("redis", "libs.redis")
relocate("xyz.xenondevs", "libs.xyz.xenondevs")
// relocate("xyz.xenondevs", "libs.xyz.xenondevs")
exclude("org.slf4j")
}
sonar {

View file

@ -2,11 +2,11 @@ package me.unurled.sacredrealms.sr;
import me.unurled.sacredrealms.sr.managers.Managers;
import org.bukkit.plugin.java.JavaPlugin;
import xyz.xenondevs.invui.InvUI;
public final class SR extends JavaPlugin {
private static SR instance;
private Managers managers;
public static SR getInstance() {
@ -17,6 +17,8 @@ public final class SR extends JavaPlugin {
public void onEnable() {
instance = this;
InvUI.getInstance().setPlugin(this);
managers = new Managers();
}

View file

@ -0,0 +1,34 @@
package me.unurled.sacredrealms.sr;
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
import io.papermc.paper.plugin.bootstrap.PluginBootstrap;
import io.papermc.paper.plugin.bootstrap.PluginProviderContext;
import me.unurled.sacredrealms.sr.commands.CommandManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
public class SRBootstrap implements PluginBootstrap {
/**
* Called by the server, allowing you to bootstrap the plugin with a context that provides things
* like a logger and your shared plugin configuration file.
*
* @param context the server provided context
*/
@Override
public void bootstrap(@NotNull BootstrapContext context) {
CommandManager.loadCommands(context);
}
/**
* Called by the server to instantiate your main class. Plugins may override this logic to define
* custom creation logic for said instance, like passing addition constructor arguments.
*
* @param context the server created bootstrap object
* @return the server requested instance of the plugins main class.
*/
@Override
public @NotNull JavaPlugin createPlugin(@NotNull PluginProviderContext context) {
return PluginBootstrap.super.createPlugin(context);
}
}

View file

@ -0,0 +1,26 @@
package me.unurled.sacredrealms.sr;
import io.papermc.paper.plugin.loader.PluginClasspathBuilder;
import io.papermc.paper.plugin.loader.PluginLoader;
import io.papermc.paper.plugin.loader.library.impl.MavenLibraryResolver;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.graph.Dependency;
import org.eclipse.aether.repository.RemoteRepository;
import org.jetbrains.annotations.NotNull;
public class SRLoader implements PluginLoader {
@Override
public void classloader(@NotNull PluginClasspathBuilder classpathBuilder) {
MavenLibraryResolver resolver = new MavenLibraryResolver();
resolver.addDependency(
new Dependency(new DefaultArtifact("xyz.xenondevs.invui:inventory-access-r20:1.32"), null));
resolver.addDependency(
new Dependency(new DefaultArtifact("xyz.xenondevs.invui:invui-core:1.32"), null));
resolver.addRepository(
new RemoteRepository.Builder("invui", "default", "https://repo.xenondevs.xyz/releases/")
.build());
classpathBuilder.addLibrary(resolver);
}
}

View file

@ -1,9 +1,13 @@
package me.unurled.sacredrealms.sr.commands;
import static me.unurled.sacredrealms.sr.utils.Logger.error;
import static me.unurled.sacredrealms.sr.utils.Logger.log;
import java.lang.reflect.InvocationTargetException;
import me.unurled.sacredrealms.sr.SR;
import io.papermc.paper.command.brigadier.BasicCommand;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
import me.unurled.sacredrealms.sr.commands.admin.AttributeCommand;
import me.unurled.sacredrealms.sr.commands.admin.ClientBuildCommand;
import me.unurled.sacredrealms.sr.commands.admin.EntityTypeCommand;
@ -14,42 +18,41 @@ import me.unurled.sacredrealms.sr.commands.admin.TreasureCommand;
import me.unurled.sacredrealms.sr.commands.player.DifficultyCommand;
import me.unurled.sacredrealms.sr.commands.player.ResetAdventureCommand;
import me.unurled.sacredrealms.sr.managers.Manager;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.TabExecutor;
public class CommandManager extends Manager {
private static <T extends TabExecutor> void registerCommand(String command, Class<T> clazz) {
PluginCommand pluginCommand = SR.getInstance().getCommand(command);
if (pluginCommand != null) {
try {
T instance = clazz.getDeclaredConstructor().newInstance();
pluginCommand.setExecutor(instance);
pluginCommand.setTabCompleter(instance);
} catch (InstantiationException
| IllegalAccessException
| InvocationTargetException
| NoSuchMethodException e) {
error("Failed to register command " + command + "\n" + e.getMessage());
}
private static <T extends BasicCommand> void registerCommand(
String command, String description, BootstrapContext ctx, Class<T> clazz) {
LifecycleEventManager<BootstrapContext> man = ctx.getLifecycleManager();
try {
T instance = clazz.getDeclaredConstructor().newInstance();
man.registerEventHandler(
LifecycleEvents.COMMANDS,
event -> {
final Commands commands = event.registrar();
commands.register(command, description, instance);
});
log("Registered command: " + command);
} catch (Exception e) {
error("Failed to register command: " + command + " - " + e.getMessage());
}
}
/** Load the manager */
@Override
public void load() {
super.load();
public static void loadCommands(BootstrapContext ctx) {
registerCommand("attributes", AttributeCommand.class);
registerCommand("clientbuild", ClientBuildCommand.class);
registerCommand("level", LevelCommand.class);
registerCommand("entitytype", EntityTypeCommand.class);
registerCommand("item", ItemCommand.class);
registerCommand("treasure", ItemCommand.class);
registerCommand("spawnentity", SpawnEntityCommand.class);
registerCommand("treasure", TreasureCommand.class);
registerCommand("attributes", "Set the attributes of the player.", ctx, AttributeCommand.class);
registerCommand(
"clientbuild", "Set the client build of the player.", ctx, ClientBuildCommand.class);
registerCommand("level", "Set the level of the player.", ctx, LevelCommand.class);
registerCommand("entitytype", "Create a new entity type.", ctx, EntityTypeCommand.class);
registerCommand("item", "Create/modify an item.", ctx, ItemCommand.class);
registerCommand("treasure", " Create a treasure chest.", ctx, TreasureCommand.class);
registerCommand("spawnentity", "Spawn an entity.", ctx, SpawnEntityCommand.class);
registerCommand("resetadventure", ResetAdventureCommand.class);
registerCommand("difficulty", DifficultyCommand.class);
registerCommand(
"resetadventure", "Reset the adventure of the player.", ctx, ResetAdventureCommand.class);
registerCommand(
"difficulty", "Set the difficulty of the player.", ctx, DifficultyCommand.class);
}
}

View file

@ -3,7 +3,10 @@ package me.unurled.sacredrealms.sr.commands.admin;
import static me.unurled.sacredrealms.sr.utils.Component.comp;
import static me.unurled.sacredrealms.sr.utils.SRPlayerUtils.syncSRToPlayer;
import io.papermc.paper.command.brigadier.BasicCommand;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import me.unurled.sacredrealms.sr.components.attributes.Attribute;
@ -12,15 +15,13 @@ import me.unurled.sacredrealms.sr.components.player.SRPlayer;
import me.unurled.sacredrealms.sr.gui.attributes.AttributesGUI;
import me.unurled.sacredrealms.sr.managers.Manager;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.xenondevs.invui.window.Window;
public class AttributeCommand implements TabExecutor {
public class AttributeCommand implements BasicCommand {
public static final String FOR = " for ";
public static final String REMOVE = "remove";
@ -66,7 +67,7 @@ public class AttributeCommand implements TabExecutor {
private static void set(
@NotNull CommandSender sender,
@NotNull String @NotNull [] args,
Attribute attribute,
@NotNull Attribute attribute,
Player target) {
try {
double value = Double.parseDouble(args[3]);
@ -172,7 +173,7 @@ public class AttributeCommand implements TabExecutor {
@NotNull CommandSender sender,
@NotNull String @NotNull [] args,
Player target,
Attribute attribute) {
@NotNull Attribute attribute) {
double value = Double.parseDouble(args[3]);
if (value < attribute.getMinValue() || value > attribute.getMaxValue()) {
sender.sendMessage(
@ -188,48 +189,39 @@ public class AttributeCommand implements TabExecutor {
}
/**
* Executes the given command, returning its success. <br>
* If false is returned, then the "usage" plugin.yml entry for this command (if defined) will be
* sent to the player.
* Executes the command with the given {@link CommandSourceStack} and arguments.
*
* @param sender Source of the command
* @param command Command which was executed
* @param label Alias of the command which was used
* @param args Passed command arguments
* @return true if a valid command, otherwise false
* @param commandSourceStack the commandSourceStack of the command
* @param args the arguments of the command ignoring repeated spaces
*/
@Override
public boolean onCommand(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String label,
@NotNull String[] args) {
// set, get, remove, gui
public void execute(@NotNull CommandSourceStack commandSourceStack, @NotNull String[] args) {
CommandSender sender = commandSourceStack.getSender();
if (!sender.hasPermission("sr.attributes")) {
sender.sendMessage("Unknown command. Type \"/help\" for help.");
return true;
return;
}
if (args.length < 2) {
sender.sendMessage(
"Usage: /attribute <set|get|remove|gui> <player|item-in-hand> <attribute> [value]");
return true;
return;
}
if (args[0].equals("set") && args.length < 4) {
sender.sendMessage("Usage: /attribute set <player|item-in-hand> <attribute> <value>");
return true;
return;
}
if (args[0].equals("gui")) {
gui(sender, args);
return true;
return;
}
if (args[1].equals("item-in-hand")) {
itemInHand(sender, args);
return true;
return;
}
Player target = Bukkit.getPlayer(args[1]);
if (target == null) {
sender.sendMessage("Player not found.");
return true;
return;
}
Attribute attribute;
@ -237,46 +229,38 @@ public class AttributeCommand implements TabExecutor {
attribute = Attribute.valueOf(args[2].toUpperCase());
} catch (IllegalArgumentException | ArrayIndexOutOfBoundsException e) {
sender.sendMessage("Attribute not found.");
return true;
return;
}
if (args[0].equalsIgnoreCase("set")) {
set(sender, args, attribute, target);
return true;
return;
}
if (args[0].equalsIgnoreCase("get")) {
get(sender, target, attribute);
return true;
return;
}
if (args[0].equalsIgnoreCase(REMOVE)) {
remove(sender, target, attribute);
return true;
return;
}
sender.sendMessage("Usage: /attribute <set|get|remove> <player> <attribute> [value]");
return true;
}
/**
* Requests a list of possible completions for a command argument.
* Suggests possible completions for the given command {@link CommandSourceStack} and arguments.
*
* @param sender Source of the command. For players tab-completing a command inside of a command
* block, this will be the player, not the command block.
* @param command Command which was executed
* @param label Alias of the command which was used
* @param args The arguments passed to the command, including final partial argument to be
* completed
* @return A List of possible completions for the final argument, or null to default to the
* command executor
* @param commandSourceStack the commandSourceStack of the command
* @param args the arguments of the command including repeated spaces
* @return a collection of suggestions
*/
@Override
public @Nullable List<String> onTabComplete(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String label,
public @NotNull Collection<String> suggest(@NotNull CommandSourceStack commandSourceStack,
@NotNull String[] args) {
CommandSender sender = commandSourceStack.getSender();
if (!sender.hasPermission("sr.attributes")) {
return null;
return List.of();
}
if (args.length == 1) {
return List.of("set", "get", "gui", REMOVE);
@ -294,7 +278,7 @@ public class AttributeCommand implements TabExecutor {
attributes.removeIf(s -> !s.startsWith(args[2]));
return attributes;
}
return null;
return List.of();
}
private record Result(double value, SRPlayer player) {}

View file

@ -4,7 +4,10 @@ import static me.unurled.sacredrealms.sr.utils.Component.ERROR;
import static me.unurled.sacredrealms.sr.utils.Component.textComp;
import static me.unurled.sacredrealms.sr.utils.Logger.log;
import io.papermc.paper.command.brigadier.BasicCommand;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@ -17,9 +20,7 @@ import me.unurled.sacredrealms.sr.managers.Manager;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -27,9 +28,8 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class ClientBuildCommand implements TabExecutor, Listener {
public class ClientBuildCommand implements BasicCommand, Listener {
public static final String USAGE =
"Usage: /clientbuild <create|delete|modify|save|display> <name>";
@ -179,72 +179,6 @@ public class ClientBuildCommand implements TabExecutor, Listener {
if (build != null) sender.sendMessage(build.getName());
}
}
/**
* Executes the given command, returning its success. <br>
* If false is returned, then the "usage" plugin.yml entry for this command (if defined) will be
* sent to the player.
*
* @param sender Source of the command
* @param command Command which was executed
* @param label Alias of the command which was used
* @param args Passed command arguments
* @return true if a valid command, otherwise false
*/
@Override
public boolean onCommand(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String label,
@NotNull String[] args) {
if (!sender.hasPermission("sr.clientbuild")) {
sender.sendMessage("You do not have permission to use this command.");
return true;
}
if (!(sender instanceof Player p)) {
sender.sendMessage("You must be a player to use this command.");
return true;
}
if (args.length == 0) {
sender.sendMessage("Usage: /clientbuild <create|delete|list|modify|save|display>");
return true;
}
ClientBuildManager clientBuildManager = Manager.getInstance(ClientBuildManager.class);
if (args.length == 1) {
if (args[0].equalsIgnoreCase("list")) {
list(sender, clientBuildManager);
return true;
}
sender.sendMessage(USAGE);
return true;
} else if (args.length == 2) {
// create, delete, modify, save, display
if (args[0].equalsIgnoreCase("create")) {
create(sender, args, p, clientBuildManager);
return true;
} else if (args[0].equalsIgnoreCase(DELETE)) {
delete(sender, args, clientBuildManager);
return true;
} else if (args[0].equalsIgnoreCase(MODIFY)) {
modify(sender, args, p, clientBuildManager);
return true;
} else if (args[0].equalsIgnoreCase("save")) {
save(sender, args, p, clientBuildManager);
return true;
} else if (args[0].equalsIgnoreCase(DISPLAY)) {
display(sender, args, p, clientBuildManager);
return true;
}
sender.sendMessage(USAGE);
return true;
}
sender.sendMessage(USAGE);
return true;
}
@EventHandler
public void onBlockPlace(@NotNull BlockPlaceEvent e) {
Player p = e.getPlayer();
@ -289,29 +223,77 @@ public class ClientBuildCommand implements TabExecutor, Listener {
}
/**
* Requests a list of possible completions for a command argument.
* Executes the command with the given {@link CommandSourceStack} and arguments.
*
* @param sender Source of the command. For players tab-completing a command inside a command
* block, this will be the player, not the command block.
* @param command Command which was executed
* @param label Alias of the command which was used
* @param args The arguments passed to the command, including final partial argument to be
* completed
* @return A List of possible completions for the final argument, or null to default to the
* command executor
* @param commandSourceStack the commandSourceStack of the command
* @param args the arguments of the command ignoring repeated spaces
*/
@Override
public @Nullable List<String> onTabComplete(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String label,
public void execute(@NotNull CommandSourceStack commandSourceStack, @NotNull String[] args) {
CommandSender sender = commandSourceStack.getSender();
if (!sender.hasPermission("sr.clientbuild")) {
sender.sendMessage("You do not have permission to use this command.");
return;
}
if (!(sender instanceof Player p)) {
sender.sendMessage("You must be a player to use this command.");
return;
}
if (args.length == 0) {
sender.sendMessage("Usage: /clientbuild <create|delete|list|modify|save|display>");
return;
}
ClientBuildManager clientBuildManager = Manager.getInstance(ClientBuildManager.class);
if (args.length == 1) {
if (args[0].equalsIgnoreCase("list")) {
list(sender, clientBuildManager);
return;
}
sender.sendMessage(USAGE);
return;
} else if (args.length == 2) {
// create, delete, modify, save, display
if (args[0].equalsIgnoreCase("create")) {
create(sender, args, p, clientBuildManager);
return;
} else if (args[0].equalsIgnoreCase(DELETE)) {
delete(sender, args, clientBuildManager);
return;
} else if (args[0].equalsIgnoreCase(MODIFY)) {
modify(sender, args, p, clientBuildManager);
return;
} else if (args[0].equalsIgnoreCase("save")) {
save(sender, args, p, clientBuildManager);
return;
} else if (args[0].equalsIgnoreCase(DISPLAY)) {
display(sender, args, p, clientBuildManager);
return;
}
sender.sendMessage(USAGE);
return;
}
sender.sendMessage(USAGE);
}
/**
* Suggests possible completions for the given command {@link CommandSourceStack} and arguments.
*
* @param commandSourceStack the commandSourceStack of the command
* @param args the arguments of the command including repeated spaces
* @return a collection of suggestions
*/
@Override
public @NotNull Collection<String> suggest(@NotNull CommandSourceStack commandSourceStack,
@NotNull String[] args) {
if (args.length == 1) {
return List.of("create", DELETE, "list", MODIFY, "save", DISPLAY);
} else if (args.length == 2
&& (args[0].equalsIgnoreCase(DELETE)
|| args[0].equalsIgnoreCase(MODIFY)
|| args[0].equalsIgnoreCase(DISPLAY))) {
|| args[0].equalsIgnoreCase(MODIFY)
|| args[0].equalsIgnoreCase(DISPLAY))) {
ClientBuildManager clientBuildManager = Manager.getInstance(ClientBuildManager.class);
List<String> buildNames = clientBuildManager.getBuildNames();
if (nameCompletions.isEmpty() || !new HashSet<>(nameCompletions).containsAll(buildNames)) {
@ -319,6 +301,6 @@ public class ClientBuildCommand implements TabExecutor, Listener {
}
return nameCompletions;
}
return null;
return List.of();
}
}

View file

@ -4,24 +4,22 @@ import static me.unurled.sacredrealms.sr.utils.Component.NOT_PLAYER;
import static me.unurled.sacredrealms.sr.utils.Component.comp;
import static me.unurled.sacredrealms.sr.utils.Component.textComp;
import io.papermc.paper.command.brigadier.BasicCommand;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import me.unurled.sacredrealms.sr.components.entity.EntityManager;
import me.unurled.sacredrealms.sr.components.entity.SREntityType;
import me.unurled.sacredrealms.sr.gui.entitytype.EntityTypeGUI;
import me.unurled.sacredrealms.sr.managers.Manager;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.xenondevs.invui.window.Window;
public class EntityTypeCommand implements TabExecutor {
public class EntityTypeCommand implements BasicCommand {
private static void list(@NotNull CommandSender sender, @NotNull String @NotNull [] args) {
if (!(sender instanceof Player p)) {
@ -37,7 +35,6 @@ public class EntityTypeCommand implements TabExecutor {
Window window =
Window.single().setViewer(p).setTitle(args[1]).setGui(EntityTypeGUI.listGui()).build();
window.open();
return;
}
private static void edit(@NotNull CommandSender sender, @NotNull String @NotNull [] args) {
@ -77,10 +74,10 @@ public class EntityTypeCommand implements TabExecutor {
try {
EntityType type = EntityType.valueOf(args[4]);
EntityManager em = Manager.getInstance(EntityManager.class);
if (setType(sender, args, em, type)) return;
if (setType(sender, args, em, type)) {
}
} catch (IllegalArgumentException e) {
sender.sendMessage("Invalid entity type.");
return;
}
}
}
@ -93,7 +90,6 @@ public class EntityTypeCommand implements TabExecutor {
EntityManager em = Manager.getInstance(EntityManager.class);
if (!em.getTypes().stream().map(SREntityType::getId).toList().contains(args[1])) {
sender.sendMessage("Invalid entity type.");
return;
}
// em.removeEntityType(em.getType(args[1]));
}
@ -138,73 +134,44 @@ public class EntityTypeCommand implements TabExecutor {
}
/**
* Executes the given command, returning its success. <br>
* If false is returned, then the "usage" plugin.yml entry for this command (if defined) will be
* sent to the player.
* Executes the command with the given {@link CommandSourceStack} and arguments.
*
* @param sender Source of the command
* @param command Command which was executed
* @param label Alias of the command which was used
* @param args Passed command arguments
* @return true if a valid command, otherwise false
* @param commandSourceStack the commandSourceStack of the command
* @param args the arguments of the command ignoring repeated spaces
*/
@Override
public boolean onCommand(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String label,
@NotNull String[] args) {
public void execute(@NotNull CommandSourceStack commandSourceStack, @NotNull String[] args) {
CommandSender sender = commandSourceStack.getSender();
if (!sender.hasPermission("sr.entitytype")) {
sender.sendMessage("You do not have permission to use this command.");
return true;
return;
}
if (args.length == 0) {
sender.sendMessage("Usage: /entitytype <create|delete|edit|list>");
return true;
return;
}
switch (args[0].toLowerCase()) {
case "create" -> {
create(sender, args);
return true;
}
case "delete" -> {
delete(sender, args);
return true;
}
case "edit" -> {
edit(sender, args);
return true;
}
case "list" -> {
list(sender, args);
return true;
}
case "create" -> create(sender, args);
case "delete" -> delete(sender, args);
case "edit" -> edit(sender, args);
case "list" -> list(sender, args);
default -> sender.sendMessage("Usage: /entitytype <create|delete|edit|list>");
}
return true;
}
/**
* Requests a list of possible completions for a command argument.
* Suggests possible completions for the given command {@link CommandSourceStack} and arguments.
*
* @param sender Source of the command. For players tab-completing a command inside of a command
* block, this will be the player, not the command block.
* @param command Command which was executed
* @param label Alias of the command which was used
* @param args The arguments passed to the command, including final partial argument to be
* completed
* @return A List of possible completions for the final argument, or null to default to the
* command executor
* @param commandSourceStack the commandSourceStack of the command
* @param args the arguments of the command including repeated spaces
* @return a collection of suggestions
*/
@Override
public @Nullable List<String> onTabComplete(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String label,
public @NotNull Collection<String> suggest(@NotNull CommandSourceStack commandSourceStack,
@NotNull String[] args) {
CommandSender sender = commandSourceStack.getSender();
if (sender.hasPermission("sr.entitytype")) {
if (args.length == 1) {
return List.of("create", "delete", "edit", "list");
@ -225,6 +192,6 @@ public class EntityTypeCommand implements TabExecutor {
.toList();
}
}
return null;
return List.of();
}
}

View file

@ -3,7 +3,10 @@ package me.unurled.sacredrealms.sr.commands.admin;
import static me.unurled.sacredrealms.sr.utils.Component.comp;
import static me.unurled.sacredrealms.sr.utils.Logger.error;
import io.papermc.paper.command.brigadier.BasicCommand;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import me.unurled.sacredrealms.sr.components.attributes.Attribute;
import me.unurled.sacredrealms.sr.components.item.Item;
@ -15,14 +18,12 @@ import me.unurled.sacredrealms.sr.components.item.enchantments.Enchantment;
import me.unurled.sacredrealms.sr.managers.Manager;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class ItemCommand implements TabExecutor {
public class ItemCommand implements BasicCommand {
public static final String DELETE = "delete";
public static final String DOES_NOT_EXIST = "<red>An item with that ID does not exist.";
@ -443,83 +444,65 @@ public class ItemCommand implements TabExecutor {
}
/**
* Executes the given command, returning its success. <br>
* If false is returned, then the "usage" plugin.yml entry for this command (if defined) will be
* sent to the player.
* Executes the command with the given {@link CommandSourceStack} and arguments.
*
* @param sender Source of the command
* @param command Command which was executed
* @param label Alias of the command which was used
* @param args Passed command arguments
* @return true if a valid command, otherwise false
* @param commandSourceStack the commandSourceStack of the command
* @param args the arguments of the command ignoring repeated spaces
*/
@Override
public boolean onCommand(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String label,
@NotNull String[] args) {
public void execute(@NotNull CommandSourceStack commandSourceStack, @NotNull String[] args) {
CommandSender sender = commandSourceStack.getSender();
if (!(sender instanceof Player p)) {
sender.sendMessage("You must be a player to use this command.");
return true;
return;
}
if (!p.hasPermission("sr.admin.item")) {
p.sendMessage("You do not have permission to use this command.");
return true;
return;
}
if (args.length == 0) {
p.sendMessage("Usage: /item <list|create|delete|give|modify>");
return true;
return;
}
if (args[0].equalsIgnoreCase("list")) {
list(sender, p);
return true;
return;
}
if (args[0].equalsIgnoreCase("create")) {
create(sender, args);
return true;
return;
}
if (args[0].equalsIgnoreCase(DELETE)) {
delete(sender, args, p);
return true;
return;
}
if (args[0].equalsIgnoreCase("give")) {
give(sender, args, p);
return true;
return;
}
if (args[0].equalsIgnoreCase(MODIFY)) {
modify(sender, args, p);
return true;
}
return true;
}
/**
* Requests a list of possible completions for a command argument.
* Suggests possible completions for the given command {@link CommandSourceStack} and arguments.
*
* @param sender Source of the command. For players tab-completing a command inside of a command
* block, this will be the player, not the command block.
* @param command Command which was executed
* @param label Alias of the command which was used
* @param args The arguments passed to the command, including final partial argument to be
* completed
* @return A List of possible completions for the final argument, or null to default to the
* command executor
* @param commandSourceStack the commandSourceStack of the command
* @param args the arguments of the command including repeated spaces
* @return a collection of suggestions
*/
@Override
public @Nullable List<String> onTabComplete(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String label,
@NotNull String[] args) {
public @NotNull Collection<String> suggest(
@NotNull CommandSourceStack commandSourceStack, @NotNull String[] args) {
CommandSender sender = commandSourceStack.getSender();
if (!(sender instanceof Player) || !sender.hasPermission("sr.admin.item")) {
return List.of("");
}
@ -530,8 +513,8 @@ public class ItemCommand implements TabExecutor {
if (args.length == 2
&& (args[0].equalsIgnoreCase(DELETE)
|| args[0].equalsIgnoreCase("give")
|| args[0].equalsIgnoreCase(MODIFY))) {
|| args[0].equalsIgnoreCase("give")
|| args[0].equalsIgnoreCase(MODIFY))) {
ItemManager im = Manager.getInstance(ItemManager.class);
return im.getItemIDs();
}
@ -556,6 +539,6 @@ public class ItemCommand implements TabExecutor {
}
}
return List.of("");
return List.of();
}
}

View file

@ -1,50 +1,42 @@
package me.unurled.sacredrealms.sr.commands.admin;
import io.papermc.paper.command.brigadier.BasicCommand;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import java.util.Collection;
import java.util.List;
import me.unurled.sacredrealms.sr.components.player.PlayerManager;
import me.unurled.sacredrealms.sr.components.player.SRPlayer;
import me.unurled.sacredrealms.sr.managers.Manager;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class LevelCommand implements TabExecutor {
public class LevelCommand implements BasicCommand {
/**
* Executes the given command, returning its success. <br>
* If false is returned, then the "usage" plugin.yml entry for this command (if defined) will be
* sent to the player.
* Executes the command with the given {@link CommandSourceStack} and arguments.
*
* @param sender Source of the command
* @param command Command which was executed
* @param label Alias of the command which was used
* @param args Passed command arguments
* @return true if a valid command, otherwise false
* @param commandSourceStack the commandSourceStack of the command
* @param args the arguments of the command ignoring repeated spaces
*/
@Override
public boolean onCommand(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String label,
@NotNull String[] args) {
public void execute(@NotNull CommandSourceStack commandSourceStack, @NotNull String[] args) {
CommandSender sender = commandSourceStack.getSender();
if (!sender.hasPermission("sr.level")) {
sender.sendMessage("You do not have permission to use this command.");
return true;
return;
}
if (args.length != 2) {
sender.sendMessage("Usage: /level <player> <level>");
return true;
return;
}
Player target = sender.getServer().getPlayer(args[0]);
if (target == null) {
sender.sendMessage("Player not found.");
return true;
return;
}
PlayerManager pm = Manager.getInstance(PlayerManager.class);
@ -59,27 +51,18 @@ public class LevelCommand implements TabExecutor {
} else {
sender.sendMessage("Player not found.");
}
return true;
}
/**
* Requests a list of possible completions for a command argument.
* Suggests possible completions for the given command {@link CommandSourceStack} and arguments.
*
* @param sender Source of the command. For players tab-completing a command inside of a command
* block, this will be the player, not the command block.
* @param command Command which was executed
* @param label Alias of the command which was used
* @param args The arguments passed to the command, including final partial argument to be
* completed
* @return A List of possible completions for the final argument, or null to default to the
* command executor
* @param commandSourceStack the commandSourceStack of the command
* @param args the arguments of the command including repeated spaces
* @return a collection of suggestions
*/
@Override
public @Nullable List<String> onTabComplete(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String label,
@NotNull String[] args) {
return null;
public @NotNull Collection<String> suggest(
@NotNull CommandSourceStack commandSourceStack, @NotNull String[] args) {
return List.of();
}
}

View file

@ -3,19 +3,19 @@ package me.unurled.sacredrealms.sr.commands.admin;
import static me.unurled.sacredrealms.sr.utils.Component.NO_PERMISSION;
import static me.unurled.sacredrealms.sr.utils.Component.textComp;
import io.papermc.paper.command.brigadier.BasicCommand;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import java.util.Collection;
import java.util.List;
import me.unurled.sacredrealms.sr.components.entity.EntityManager;
import me.unurled.sacredrealms.sr.components.entity.SREntityType;
import me.unurled.sacredrealms.sr.managers.Manager;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class SpawnEntityCommand implements TabExecutor {
public class SpawnEntityCommand implements BasicCommand {
private static final String USAGE =
"Usage: /spawnentity <entityType> [amount] [x] [y] [z] " + "[world]";
@ -35,7 +35,7 @@ public class SpawnEntityCommand implements TabExecutor {
em.spawnEntity(eType, amount, x, y, z, world);
}
private int getAmount(CommandSender sender, String[] args) {
private int getAmount(CommandSender sender, String @NotNull [] args) {
if (args.length > 1 && (args.length < 5 || args.length > 6)) {
try {
return Integer.parseInt(args[1]);
@ -47,30 +47,22 @@ public class SpawnEntityCommand implements TabExecutor {
}
/**
* Executes the given command, returning its success. <br>
* If false is returned, then the "usage" plugin.yml entry for this command (if defined) will be
* sent to the player.
* Executes the command with the given {@link CommandSourceStack} and arguments.
*
* @param sender Source of the command
* @param command Command which was executed
* @param label Alias of the command which was used
* @param args Passed command arguments
* @return true if a valid command, otherwise false
* @param commandSourceStack the commandSourceStack of the command
* @param args the arguments of the command ignoring repeated spaces
*/
@Override
public boolean onCommand(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String label,
@NotNull String[] args) {
public void execute(@NotNull CommandSourceStack commandSourceStack, @NotNull String[] args) {
CommandSender sender = commandSourceStack.getSender();
if (!sender.hasPermission("sr.spawn-entity")) {
sender.sendMessage(textComp(NO_PERMISSION));
return true;
return;
}
if (args.length == 0) {
sender.sendMessage(USAGE);
return true;
return;
}
double x;
double y;
@ -85,7 +77,7 @@ public class SpawnEntityCommand implements TabExecutor {
x = Double.parseDouble(args[2]);
} catch (NumberFormatException e) {
sender.sendMessage("Invalid x location.");
return true;
return;
}
}
if (args[3].equals("~")) {
@ -95,7 +87,7 @@ public class SpawnEntityCommand implements TabExecutor {
y = Double.parseDouble(args[3]);
} catch (NumberFormatException e) {
sender.sendMessage("Invalid y location.");
return true;
return;
}
}
if (args[4].equals("~")) {
@ -105,7 +97,7 @@ public class SpawnEntityCommand implements TabExecutor {
z = Double.parseDouble(args[4]);
} catch (NumberFormatException e) {
sender.sendMessage("Invalid z location.");
return true;
return;
}
}
world = p.getWorld();
@ -117,13 +109,13 @@ public class SpawnEntityCommand implements TabExecutor {
world = sender.getServer().getWorld(args[5]);
} catch (NumberFormatException e) {
sender.sendMessage("Invalid location.");
return true;
return;
}
}
} else {
if (!(sender instanceof Player player)) {
sender.sendMessage("You must set the location if you are not a player.");
return true;
return;
}
x = player.getLocation().getX();
y = player.getLocation().getY();
@ -135,32 +127,24 @@ public class SpawnEntityCommand implements TabExecutor {
if (world == null) {
sender.sendMessage("Invalid world.");
return true;
return;
}
// spawn entity
return true;
spawnEntity(sender, args[0], amount, x, y, z, world);
}
/**
* Requests a list of possible completions for a command argument.
* Suggests possible completions for the given command {@link CommandSourceStack} and arguments.
*
* @param sender Source of the command. For players tab-completing a command inside of a command
* block, this will be the player, not the command block.
* @param command Command which was executed
* @param label Alias of the command which was used
* @param args The arguments passed to the command, including final partial argument to be
* completed
* @return A List of possible completions for the final argument, or null to default to the
* command executor
* @param commandSourceStack the commandSourceStack of the command
* @param args the arguments of the command including repeated spaces
* @return a collection of suggestions
*/
@Override
public @Nullable List<String> onTabComplete(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String label,
public @NotNull Collection<String> suggest(@NotNull CommandSourceStack commandSourceStack,
@NotNull String[] args) {
CommandSender sender = commandSourceStack.getSender();
if (sender.hasPermission("sr.spawn-entity")) {
if (args.length == 1) {
return Manager.getInstance(EntityManager.class).getTypes().stream()

View file

@ -3,6 +3,9 @@ package me.unurled.sacredrealms.sr.commands.admin;
import static me.unurled.sacredrealms.sr.utils.Component.NOT_PLAYER;
import static me.unurled.sacredrealms.sr.utils.Component.textComp;
import io.papermc.paper.command.brigadier.BasicCommand;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import me.unurled.sacredrealms.sr.components.treasure.Treasure;
@ -12,15 +15,12 @@ import me.unurled.sacredrealms.sr.managers.Manager;
import net.kyori.adventure.text.Component;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.xenondevs.invui.window.Window;
public class TreasureCommand implements TabExecutor {
public class TreasureCommand implements BasicCommand {
public static final Set<Material> TRANSPARENT =
Set.of(Material.AIR, Material.CAVE_AIR, Material.VOID_AIR, Material.WATER, Material.LAVA);
@ -117,26 +117,17 @@ public class TreasureCommand implements TabExecutor {
}
/**
* Executes the given command, returning its success. <br>
* If false is returned, then the "usage" plugin.yml entry for this command (if defined) will be
* sent to the player.
* Executes the command with the given {@link CommandSourceStack} and arguments.
*
* @param sender Source of the command
* @param command Command which was executed
* @param label Alias of the command which was used
* @param args Passed command arguments
* @return true if a valid command, otherwise false
* @param commandSourceStack the commandSourceStack of the command
* @param args the arguments of the command ignoring repeated spaces
*/
@Override
public boolean onCommand(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String label,
@NotNull String @NotNull [] args) {
// create, modify, list, get, delete
public void execute(@NotNull CommandSourceStack commandSourceStack, @NotNull String @NotNull [] args) {
CommandSender sender = commandSourceStack.getSender();
if (args.length == 0) {
sender.sendMessage("Usage: /treasure <create|modify|list|delete>");
return true;
return;
}
final TreasureManager instance = Manager.getInstance(TreasureManager.class);
switch (args[0]) {
@ -146,27 +137,18 @@ public class TreasureCommand implements TabExecutor {
case DELETE -> delete(sender, instance);
default -> sender.sendMessage("Usage: /treasure <create|modify|list|delete>");
}
return true;
}
/**
* Requests a list of possible completions for a command argument.
* Suggests possible completions for the given command {@link CommandSourceStack} and arguments.
*
* @param sender Source of the command. For players tab-completing a command inside of a command
* block, this will be the player, not the command block.
* @param command Command which was executed
* @param label Alias of the command which was used
* @param args The arguments passed to the command, including final partial argument to be
* completed
* @return A List of possible completions for the final argument, or null to default to the
* command executor
* @param commandSourceStack the commandSourceStack of the command
* @param args the arguments of the command including repeated spaces
* @return a collection of suggestions
*/
@Override
public @Nullable List<String> onTabComplete(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String label,
@NotNull String @NotNull [] args) {
public @NotNull Collection<String> suggest(@NotNull CommandSourceStack commandSourceStack,
@NotNull String[] args) {
if (args.length == 0) {
return List.of(CREATE, MODIFY, LIST, DELETE);
}

View file

@ -5,7 +5,10 @@ import static me.unurled.sacredrealms.sr.utils.Component.NO_PERMISSION;
import static me.unurled.sacredrealms.sr.utils.Component.PLAYER_NOT_FOUND;
import static me.unurled.sacredrealms.sr.utils.Component.textComp;
import io.papermc.paper.command.brigadier.BasicCommand;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import me.unurled.sacredrealms.sr.components.difficulty.Difficulty;
import me.unurled.sacredrealms.sr.components.player.PlayerManager;
@ -15,19 +18,16 @@ import me.unurled.sacredrealms.sr.managers.Manager;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.xenondevs.invui.window.Window;
/**
* /difficulty ~open a gui for current player~ /difficulty [player] ~open a gui for another player~
* /difficulty [player] [difficulty] ~set the difficulty for another player~
*/
public class DifficultyCommand implements TabExecutor {
public class DifficultyCommand implements BasicCommand {
public static final String DIFFICULTY_SELF = "sr.difficulty.self";
public static final String DIFFICULTY_MANAGE = "sr.difficulty.manage";
@ -161,48 +161,32 @@ public class DifficultyCommand implements TabExecutor {
}
/**
* Executes the given command, returning its success. <br>
* If false is returned, then the "usage" plugin.yml entry for this command (if defined) will be
* sent to the player.
* Executes the command with the given {@link CommandSourceStack} and arguments.
*
* @param sender Source of the command
* @param command Command which was executed
* @param label Alias of the command which was used
* @param args Passed command arguments
* @return true if a valid command, otherwise false
* @param commandSourceStack the commandSourceStack of the command
* @param args the arguments of the command ignoring repeated spaces
*/
@Override
public boolean onCommand(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String label,
@NotNull String[] args) {
public void execute(@NotNull CommandSourceStack commandSourceStack, @NotNull String[] args) {
CommandSender sender = commandSourceStack.getSender();
if (sender instanceof Player p) {
playerHandling(sender, args, p);
} else {
consoleHandler(sender, args);
}
return true;
}
/**
* Requests a list of possible completions for a command argument.
* Suggests possible completions for the given command {@link CommandSourceStack} and arguments.
*
* @param sender Source of the command. For players tab-completing a command inside of a command
* block, this will be the player, not the command block.
* @param command Command which was executed
* @param label Alias of the command which was used
* @param args The arguments passed to the command, including final partial argument to be
* completed
* @return A List of possible completions for the final argument, or null to default to the
* command executor
* @param commandSourceStack the commandSourceStack of the command
* @param args the arguments of the command including repeated spaces
* @return a collection of suggestions
*/
@Override
public @Nullable List<String> onTabComplete(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String label,
@NotNull String @NotNull [] args) {
public @NotNull Collection<String> suggest(@NotNull CommandSourceStack commandSourceStack,
@NotNull String[] args) {
CommandSender sender = commandSourceStack.getSender();
if (args.length == 0 && sender.hasPermission(DIFFICULTY_MANAGE)) {
return Bukkit.getOnlinePlayers().stream().map(Player::getName).toList();
}

View file

@ -2,7 +2,10 @@ package me.unurled.sacredrealms.sr.commands.player;
import static me.unurled.sacredrealms.sr.utils.Component.comp;
import io.papermc.paper.command.brigadier.BasicCommand;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
@ -12,69 +15,17 @@ import me.unurled.sacredrealms.sr.data.DataManager;
import me.unurled.sacredrealms.sr.managers.Manager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class ResetAdventureCommand implements TabExecutor {
public class ResetAdventureCommand implements BasicCommand {
private static final Long COOLDOWN = 120L;
private final HashMap<Player, Long> cooldowns = new HashMap<>();
/**
* Executes the given command, returning its success. <br>
* If false is returned, then the "usage" plugin.yml entry for this command (if defined) will be
* sent to the player.
*
* @param sender Source of the command
* @param command Command which was executed
* @param label Alias of the command which was used
* @param args Passed command arguments
* @return true if a valid command, otherwise false
*/
@Override
public boolean onCommand(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String label,
@NotNull String[] args) {
if (sender.hasPermission("sr.resetadventure")) {
reset(sender, args);
return true;
}
if (args.length > 0) {
sender.sendMessage(comp("<red>Usage: /resetadventure"));
return true;
}
if (sender instanceof Player player) {
if (cooldowns.containsKey(player)) {
long lastUsed = cooldowns.get(player);
long secondsLeft = ((lastUsed / 1000) + COOLDOWN) - (System.currentTimeMillis() / 1000);
if (secondsLeft > 0) {
sender.sendMessage(
comp(
"<red>You must wait "
+ secondsLeft
+ " seconds before using this command again."));
return true;
}
}
boolean status = resetAdventure(player);
if (status) {
sender.sendMessage(comp("<green>Your adventure has been reset."));
} else {
sender.sendMessage(comp("<red>Failed to reset your adventure."));
}
cooldowns.put(player, System.currentTimeMillis());
}
return true;
}
private void reset(@NotNull CommandSender sender, @NotNull String[] args) {
private void reset(@NotNull CommandSender sender, @NotNull String @NotNull [] args) {
if (args.length > 2) {
sender.sendMessage(comp("<red>Usage: /resetadventure <player>"));
return;
@ -111,24 +62,58 @@ public class ResetAdventureCommand implements TabExecutor {
return false;
}
/**
* Requests a list of possible completions for a command argument.
* Executes the command with the given {@link CommandSourceStack} and arguments.
*
* @param sender Source of the command. For players tab-completing a command inside of a command
* block, this will be the player, not the command block.
* @param command Command which was executed
* @param label Alias of the command which was used
* @param args The arguments passed to the command, including final partial argument to be
* completed
* @return A List of possible completions for the final argument, or null to default to the
* command executor
* @param commandSourceStack the commandSourceStack of the command
* @param args the arguments of the command ignoring repeated spaces
*/
@Override
public @Nullable List<String> onTabComplete(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String label,
public void execute(@NotNull CommandSourceStack commandSourceStack, @NotNull String[] args) {
CommandSender sender = commandSourceStack.getSender();
if (sender.hasPermission("sr.resetadventure")) {
reset(sender, args);
return;
}
if (args.length > 0) {
sender.sendMessage(comp("<red>Usage: /resetadventure"));
return;
}
if (sender instanceof Player player) {
if (cooldowns.containsKey(player)) {
long lastUsed = cooldowns.get(player);
long secondsLeft = ((lastUsed / 1000) + COOLDOWN) - (System.currentTimeMillis() / 1000);
if (secondsLeft > 0) {
sender.sendMessage(
comp(
"<red>You must wait "
+ secondsLeft
+ " seconds before using this command again."));
return;
}
}
boolean status = resetAdventure(player);
if (status) {
sender.sendMessage(comp("<green>Your adventure has been reset."));
} else {
sender.sendMessage(comp("<red>Failed to reset your adventure."));
}
cooldowns.put(player, System.currentTimeMillis());
}
}
/**
* Suggests possible completions for the given command {@link CommandSourceStack} and arguments.
*
* @param commandSourceStack the commandSourceStack of the command
* @param args the arguments of the command including repeated spaces
* @return a collection of suggestions
*/
@Override
public @NotNull Collection<String> suggest(@NotNull CommandSourceStack commandSourceStack,
@NotNull String[] args) {
CommandSender sender = commandSourceStack.getSender();
if (sender.hasPermission("sr.resetadventure")) {
if (args.length == 1) {
return null;
@ -150,6 +135,6 @@ public class ResetAdventureCommand implements TabExecutor {
.limit(10)
.toList();
}
return null;
return List.of();
}
}

View file

@ -136,7 +136,7 @@ public class SREntityType {
}
public EntityType getType() {
return type;
return type = type == null ? EntityType.ZOMBIE : type;
}
public void setType(EntityType type) {
@ -144,7 +144,7 @@ public class SREntityType {
}
public ItemStack getItem() {
return item == null ? new ItemStack(Material.BONE) : item;
return item == null ? new ItemStack(Material.BARRIER) : item;
}
public void setItem(ItemStack item) {
@ -153,10 +153,10 @@ public class SREntityType {
public List<ItemStack> getArmor() {
if (armor.isEmpty()) {
armor.add(new ItemStack(Material.AIR));
armor.add(new ItemStack(Material.AIR));
armor.add(new ItemStack(Material.AIR));
armor.add(new ItemStack(Material.AIR));
armor.add(new ItemStack(Material.BARRIER));
armor.add(new ItemStack(Material.BARRIER));
armor.add(new ItemStack(Material.BARRIER));
armor.add(new ItemStack(Material.BARRIER));
}
return armor;
}
@ -167,7 +167,7 @@ public class SREntityType {
}
public ItemStack getHandItem() {
return handItem == null ? new ItemStack(Material.AIR) : handItem;
return handItem == null ? new ItemStack(Material.BARRIER) : handItem;
}
@SuppressWarnings("unused")
@ -176,7 +176,7 @@ public class SREntityType {
}
public ItemStack getSecondHandItem() {
return secondHandItem == null ? new ItemStack(Material.AIR) : secondHandItem;
return secondHandItem == null ? new ItemStack(Material.BARRIER) : secondHandItem;
}
@SuppressWarnings("unused")

View file

@ -20,7 +20,7 @@ public class EntityTypeItem extends AbstractItem {
private final EntityType type;
public EntityTypeItem(SREntityType type) {
public EntityTypeItem(@NotNull SREntityType type) {
this.type = type.getType();
}

View file

@ -6,7 +6,6 @@ import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import me.unurled.sacredrealms.sr.SR;
import me.unurled.sacredrealms.sr.commands.CommandManager;
import me.unurled.sacredrealms.sr.components.clientbuild.ClientBuildManager;
import me.unurled.sacredrealms.sr.components.combat.CombatManager;
import me.unurled.sacredrealms.sr.components.entity.EntityManager;
@ -31,7 +30,6 @@ public class Managers {
DataManager.class,
PlayerManager.class,
CombatManager.class,
CommandManager.class,
ItemManager.class,
EntityManager.class,
ClientBuildManager.class,

View file

@ -1,33 +1,36 @@
package me.unurled.sacredrealms.sr.utils;
import me.unurled.sacredrealms.sr.SR;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
public class Logger {
private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger("SR");
private static final ComponentLogger componentLogger = ComponentLogger.logger("SR");
private Logger() {}
public static void log(String message) {
SR.getInstance().getLogger().info(message);
logger.info(message);
}
public static void warn(String message) {
SR.getInstance().getLogger().warning(message);
logger.warning(message);
}
public static void error(String message) {
SR.getInstance().getLogger().severe(message);
logger.severe(message);
}
public static void log(Component message) {
SR.getInstance().getComponentLogger().info(message);
componentLogger.info(message);
}
public static void warn(Component message) {
SR.getInstance().getComponentLogger().warn(message);
componentLogger.warn(message);
}
public static void error(Component message) {
SR.getInstance().getComponentLogger().error(message);
componentLogger.error(message);
}
}

View file

@ -3,11 +3,25 @@ version: $version
main: me.unurled.sacredrealms.sr.SR
api-version: "$apiVersion"
description: $description
load: POSTWORLD
authors:
- unurled
loader: me.unurled.sacredrealms.sr.SRLoader
bootstrapper: me.unurled.sacredrealms.sr.SRBootstrap
permissions:
sr.*:
description: Gives access to all Sacred Realms permissions
default: op
children:
sr.tutorial: true
sr.spawn: true
sr.attributes: true
sr.clientbuild: true
sr.level: true
sr.entitytype: true
sr.spawn-entity: true
sr.admin.item: true
sr.resetadventure: true
sr.treasure.manage: true
sr.difficulty.*: true
sr.tutorial:
default: not op
description: When the player joins and doesn't have finished the tutorial.
@ -38,29 +52,8 @@ permissions:
sr.treasure.manage:
default: op
description: When the player has permission for the command /treasure create
sr.difficulty.manage:
default: op
description: When the player has permission for the command /difficulty set player
sr.difficulty.self:
default: not op
description: When the player has permission for the command /difficulty
commands:
attributes:
description: Set the attributes of the player.
clientbuild:
description: Set the client build of the player.
level:
description: Set the level of the player.
entitytype:
description: Create a new entity type.
spawnentity:
description: Spawn an entity.
item:
description: Create/modify an item.
resetadventure:
description: Reset the adventure of the player
treasure:
description: Create a treasure chest.
difficulty:
description: Set the difficulty of the player.
sr.difficulty.*:
description: gives permission for all difficulty commands
children:
sr.difficulty.manage: true
sr.difficulty.self: true