1 Commits
Author SHA1 Message Date
Len 4faaa48a06 Switch to brigadier for commands 2024-08-15 15:31:39 +02:00
88 changed files with 327 additions and 2154 deletions
@@ -1,6 +1,5 @@
package com.alttd.essentia;
import com.alttd.essentia.api.model.randomteleport.LocationValidator;
import org.jetbrains.annotations.ApiStatus;
public interface EssentiaAPI {
@@ -20,6 +19,4 @@ public interface EssentiaAPI {
Provider.instance = instance;
}
}
public void addLocationValidator(LocationValidator locationValidator);
}
@@ -1,6 +1,5 @@
package com.alttd.essentia.api.events.player;
package com.alttd.essentia.api.events;
import com.alttd.essentia.api.events.EssentiaEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
@@ -1,6 +1,5 @@
package com.alttd.essentia.api.events.player;
package com.alttd.essentia.api.events;
import com.alttd.essentia.api.events.EssentiaEvent;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
@@ -1,6 +1,5 @@
package com.alttd.essentia.api.events.player;
package com.alttd.essentia.api.events;
import com.alttd.essentia.api.events.EssentiaEvent;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
@@ -1,6 +1,5 @@
package com.alttd.essentia.api.events.player;
package com.alttd.essentia.api.events;
import com.alttd.essentia.api.events.EssentiaEvent;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
@@ -1,6 +1,5 @@
package com.alttd.essentia.api.events.player;
package com.alttd.essentia.api.events;
import com.alttd.essentia.api.events.EssentiaEvent;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
@@ -1,40 +0,0 @@
package com.alttd.essentia.api.events.player;
import com.alttd.essentia.api.events.EssentiaEvent;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class PlayerRandomTeleportEvent extends EssentiaEvent {
private static final HandlerList handlerList = new HandlerList();
private final Player player;
private final Location location;
public PlayerRandomTeleportEvent(Player player, Location location) {
this.player = player;
this.location = location;
}
public Player getPlayer() {
return player;
}
public Location getLocation() {
return location;
}
@NotNull
@Override
public HandlerList getHandlers() {
return handlerList;
}
@NotNull
public static HandlerList getHandlerList() {
return handlerList;
}
}
@@ -1,23 +0,0 @@
package com.alttd.essentia.api.model;
public enum MobData {
ITEMS,
ARROWS,
BOATS,
MINECARTS,
XP,
PAINTINGS,
ITEMFRAMES,
ENDERCRYSTALS,
FIREWORKS,
HOSTILE,
MONSTERS,
PASSIVE,
ANIMALS,
AMBIENT,
MOBS,
ENTITIES,
TAMED
}
@@ -1,8 +0,0 @@
package com.alttd.essentia.api.model.randomteleport;
import org.bukkit.Location;
public interface LocationValidator {
boolean validate(Location location);
}
+1 -1
View File
@@ -47,7 +47,7 @@ dependencies {
tasks {
shadowJar {
archiveFileName.set("${project.name}.jar")
minimize {
minimize() {
exclude {
it.moduleName == "api"
}
+9 -1
View File
@@ -5,7 +5,7 @@ plugins {
dependencies {
implementation(project(":api"))
compileOnly("com.alttd.cosmos:cosmos-api:1.21.6-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.34")
@@ -25,3 +25,11 @@ tasks {
}
}
}
//bukkit {
// name = rootProject.name
// main = "$group.${rootProject.name}Plugin"
// version = "${rootProject.version}"
// apiVersion = "1.20"
// authors = listOf("destro174")
//}
@@ -2,15 +2,11 @@ package com.alttd.essentia;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
import com.alttd.essentia.api.model.randomteleport.LocationValidator;
import com.alttd.essentia.feature.Features;
import com.alttd.essentia.model.annotations.Depends;
import com.alttd.essentia.storage.StorageManager;
import com.alttd.essentia.storage.StorageProvider;
import com.alttd.essentia.storage.StorageType;
import com.alttd.essentia.user.EssentiaUserManager;
import com.alttd.essentia.api.user.UserManager;
import com.alttd.essentia.util.Timer;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
@@ -22,8 +18,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.reflections.Reflections;
import org.reflections.scanners.Scanners;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
@@ -33,15 +27,10 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
@Getter
private UserManager userManager;
@Getter
private List<LocationValidator> locationValidators;
@Getter
private StorageProvider storageProvider;
@Getter
private Features features;
@Override
public void onLoad() {
instance = this;
@@ -50,15 +39,11 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
@Override
public void onEnable() {
new Timer("onEnable", () -> {
new Timer("loadConfiguration", this::loadConfiguration);
new Timer("loadFeatures", this::loadFeatures);
new Timer("loadCommands", this::loadCommands);
new Timer("loadEventListeners", this::loadEventListeners);
new Timer("loadManagers", this::loadManagers);
new Timer("loadStorageProvider", this::loadStorageProvider);
new Timer("loadLocationValidators", this::loadLocationValidators);
});
loadConfiguration();
loadCommands();
loadEventListeners();
loadManagers();
loadStorageProvider();
}
@Override
@@ -72,11 +57,6 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
Config.init();
}
public void loadFeatures() {
features = new Features(this);
features.registerAll();
}
void loadCommands() {
Reflections reflections = new Reflections("com.alttd.essentia.commands");
Set<Class<?>> subTypes = reflections.get(Scanners.SubTypes.of(EssentiaCommand.class).asClass());
@@ -87,13 +67,6 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
subTypes.forEach(clazz -> {
try {
EssentiaCommand essentiaCommand = (EssentiaCommand) clazz.getDeclaredConstructor().newInstance();
final Depends depends = clazz.getAnnotation(Depends.class);
if (depends != null) {
if (!features.isEnabled(depends.value())) {
return;
}
}
commands.register(essentiaCommand.command(), essentiaCommand.description(), essentiaCommand.aliases());
} catch (Exception e) {
EssentiaPlugin.instance().getLogger().severe("Failed to register command " + clazz.getSimpleName());
@@ -104,21 +77,12 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
void loadEventListeners() {
final PluginManager pluginManager = getServer().getPluginManager();
Reflections reflections = new Reflections("com.alttd.essentia.listeners"); // These are plugin required listeners eg player data loading on login.
Reflections reflections = new Reflections("com.alttd.essentia.listeners");
Set<Class<?>> subTypes = reflections.get(Scanners.SubTypes.of(Listener.class).asClass());
reflections = new Reflections("com.alttd.essentia.feature"); // These are them listeners for the features.
subTypes.addAll(reflections.get(Scanners.SubTypes.of(Listener.class).asClass()));
subTypes.forEach(clazz -> {
try {
Listener listener = (Listener) clazz.getDeclaredConstructor().newInstance();
final Depends depends = clazz.getAnnotation(Depends.class);
if (depends != null) {
if (!features.isEnabled(depends.value())) {
return;
}
}
pluginManager.registerEvents(listener, this);
} catch (Exception e) {
EssentiaPlugin.instance().getLogger().severe("Failed to register event listener " + clazz.getSimpleName());
@@ -136,26 +100,4 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
storageProvider.startAutoSaving();
}
void loadLocationValidators() {
this.locationValidators = new ArrayList<>();
Reflections reflections = new Reflections("com.alttd.essentia.feature.randomteleport.validator");
Set<Class<?>> subTypes = reflections.get(Scanners.SubTypes.of(LocationValidator.class).asClass());
subTypes.forEach(clazz -> {
try {
LocationValidator locationValidator = (LocationValidator) clazz.getDeclaredConstructor().newInstance();
addLocationValidator(locationValidator);
} catch (Exception e) {
EssentiaPlugin.instance().getLogger().severe("Failed to add locationValidator " + clazz.getSimpleName());
EssentiaPlugin.instance().getLogger().severe(e.getMessage());
}
});
}
// TODO -- make this reload proof for API
@Override
public void addLocationValidator(LocationValidator locationValidator) {
locationValidators.add(locationValidator);
}
}
@@ -1,41 +0,0 @@
package com.alttd.essentia.commands;
import com.alttd.essentia.util.Pair;
import com.mojang.brigadier.Message;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;
public interface EssentiaArgument {
default <S> CompletableFuture<Suggestions> completedFuture(SuggestionsBuilder builder, Collection<String> possibleValues) {
String remaining = builder.getRemaining().toLowerCase();
for (String str : possibleValues) {
if (str.toLowerCase().startsWith(remaining)) {
builder.suggest(StringArgumentType.escapeIfRequired(str));
}
}
return CompletableFuture.completedFuture(
builder.build()
);
}
default <S> CompletableFuture<Suggestions> completedFuturePair(SuggestionsBuilder builder, Collection<Pair<String, Message>> possibleValues) {
String remaining = builder.getRemaining().toLowerCase();
for (Pair<String, Message> pair : possibleValues) {
String str = pair.x();
if (str.toLowerCase().startsWith(remaining)) {
builder.suggest(StringArgumentType.escapeIfRequired(str), pair.y());
}
}
return CompletableFuture.completedFuture(
builder.build()
);
}
}
@@ -9,8 +9,6 @@ import java.util.List;
// TODO -- add optional -s -silent parameters to commands?
public interface EssentiaCommand {
String commandName();
@NotNull LiteralCommandNode<CommandSourceStack> command();
default String description() {
@@ -21,20 +19,4 @@ public interface EssentiaCommand {
return Collections.emptyList();
}
default String baseCommandPermission() {
return "essentia.command.player." + commandName();
}
default String baseOtherCommandPermission() {
return "essentia.command.player." + commandName() + "other";
}
default String adminCommandPermission() {
return "essentia.command.admin." + commandName();
}
default String adminOtherCommandPermission() {
return "essentia.command.admin." + commandName() + "other";
}
}
@@ -16,17 +16,14 @@ import org.jetbrains.annotations.NotNull;
public class BurnCommand implements EssentiaCommand {
@Override
public String commandName() {
return "burn";
}
static String commandName = "burn";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
@@ -36,10 +33,10 @@ public class BurnCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
execute(source.getSource().getSender(), target);
return 1;
@@ -16,17 +16,14 @@ import org.jetbrains.annotations.NotNull;
public class ClearInventoryCommand implements EssentiaCommand {
@Override
public String commandName() {
return "clearinventory";
}
static String commandName = "clearinventory";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
@@ -37,10 +34,10 @@ public class ClearInventoryCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
execute(source.getSource().getSender(), target);
return 1;
@@ -19,24 +19,21 @@ import org.jetbrains.annotations.NotNull;
public class CuffCommand implements EssentiaCommand {
@Override
public String commandName() {
return "cuff";
}
static String commandName = "cuff";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
)
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
execute(source.getSource().getSender(), target);
return 1;
@@ -1,6 +1,7 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.commands.argumement.EnchantmentArgument;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
@@ -8,7 +9,6 @@ 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.registry.RegistryKey;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.Material;
@@ -20,20 +20,17 @@ import org.jetbrains.annotations.NotNull;
public class EnchantCommand implements EssentiaCommand {
@Override
public String commandName() {
return "enchant";
}
static String commandName = "enchant";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
)
.then(
Commands.argument("enchantment", ArgumentTypes.resource(RegistryKey.ENCHANTMENT))
Commands.argument("enchantment", new EnchantmentArgument())
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
@@ -54,10 +51,10 @@ public class EnchantCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
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);
@@ -10,16 +10,11 @@ import org.jetbrains.annotations.NotNull;
public class EssentiaAdminCommand implements EssentiaCommand {
@Override
public String commandName() {
return "essentiareload";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()))
Commands.literal("essentia")
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin.reload"))
.executes((commandContext -> 1))
.then(
Commands.literal("reload")
@@ -16,17 +16,14 @@ import org.jetbrains.annotations.NotNull;
public class FeedCommand implements EssentiaCommand {
@Override
public String commandName() {
return "feed";
}
static String commandName = "feed";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
@@ -37,10 +34,10 @@ public class FeedCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
execute(source.getSource().getSender(), target);
return 1;
@@ -20,17 +20,14 @@ import org.jetbrains.annotations.NotNull;
public class FlyCommand implements EssentiaCommand {
@Override
public String commandName() {
return "fly";
}
static String commandName = "fly";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
@@ -41,10 +38,10 @@ public class FlyCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
execute(source.getSource().getSender(), target);
return 1;
@@ -18,17 +18,14 @@ import org.jetbrains.annotations.NotNull;
public class FlySpeedCommand implements EssentiaCommand {
@Override
public String commandName() {
return "flyspeed";
}
static String commandName = "flyspeed";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
).then(
Commands.argument("speed", FloatArgumentType.floatArg(-1, 1))
.executes((source) -> {
@@ -42,10 +39,10 @@ public class FlySpeedCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
float speed = source.getArgument("speed", Float.class);
execute(source.getSource().getSender(), target, speed);
@@ -1,6 +1,7 @@
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;
@@ -8,6 +9,7 @@ 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;
@@ -17,20 +19,17 @@ import org.jetbrains.annotations.NotNull;
public class GameModeCommand implements EssentiaCommand {
@Override
public String commandName() {
return "gamemode";
}
static String commandName = "gamemode";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
)
.then(
Commands.argument("gamemode", ArgumentTypes.gameMode())
Commands.argument("gamemode", new GameModeArgument())
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
@@ -41,10 +40,10 @@ public class GameModeCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
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;
@@ -20,17 +20,14 @@ import org.jetbrains.annotations.NotNull;
public class GodCommand implements EssentiaCommand {
@Override
public String commandName() {
return "god";
}
static String commandName = "god";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
@@ -41,10 +38,10 @@ public class GodCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
execute(source.getSource().getSender(), target);
return 1;
@@ -14,19 +14,17 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class HealCommand implements EssentiaCommand {
public class HealCommand
implements EssentiaCommand {
@Override
public String commandName() {
return "heal";
}
static String commandName = "heal";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
@@ -37,10 +35,10 @@ public class HealCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
execute(source.getSource().getSender(), target);
return 1;
@@ -15,17 +15,14 @@ import org.jetbrains.annotations.NotNull;
public class InfoCommand implements EssentiaCommand {
@Override
public String commandName() {
return "info";
}
static String commandName = "info";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
@@ -35,10 +32,10 @@ public class InfoCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
execute(source.getSource().getSender(), target);
return 1;
@@ -1,246 +0,0 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.api.model.MobData;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.commands.argumement.EntityTypeArgumentType;
import com.alttd.essentia.commands.argumement.MobDataArgumentType;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.*;
import org.jetbrains.annotations.NotNull;
public class KillallCommand implements EssentiaCommand {
@Override
public String commandName() {
return "killall";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.then(Commands.argument("mobdata", new MobDataArgumentType())
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
MobData mobData = source.getArgument("mobdata", MobData.class);
execute(source.getSource().getSender(), player, mobData, 50, false);
return 1;
})
.then(Commands.argument("radius", IntegerArgumentType.integer(0, 250))
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
MobData mobData = source.getArgument("mobdata", MobData.class);
int radius = source.getArgument("radius", Integer.class);
execute(source.getSource().getSender(), player, mobData, radius, false);
return 1;
})
.then(Commands.literal("named")
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
MobData mobData = source.getArgument("mobdata", MobData.class);
int radius = source.getArgument("range", Integer.class);
execute(source.getSource().getSender(), player, mobData, radius, true);
return 1;
})
)
)
)
// .then(Commands.argument("entitytype", new EntityTypeArgumentType())
// .executes((source) -> {
// if (!(source.getSource().getSender() instanceof Player player))
// return 1;
//
// EntityType entityType = source.getArgument("entitytype", EntityType.class);
// execute(source.getSource().getSender(), player, entityType, 50, false);
// return 1;
// })
// .then(Commands.argument("radius", IntegerArgumentType.integer(0, 250))
// .executes((source) -> {
// if (!(source.getSource().getSender() instanceof Player player))
// return 1;
//
// EntityType entityType = source.getArgument("entitytype", EntityType.class);
// int radius = source.getArgument("radius", Integer.class);
// execute(source.getSource().getSender(), player, entityType, radius, false);
// return 1;
// })
// .then(Commands.literal("named")
// .executes((source) -> {
// if (!(source.getSource().getSender() instanceof Player player))
// return 1;
//
// EntityType entityType = source.getArgument("entitytype", EntityType.class);
// int radius = source.getArgument("range", Integer.class);
// execute(source.getSource().getSender(), player, entityType, radius, true);
// return 1;
// })
// )
//
// )
// )
;
return builder.build();
}
public void execute(CommandSender sender, Player target, MobData mobData, int radius, boolean named) { // TODO - Messages from config, placeholders
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("requester", sender.name()),
Placeholder.component("target", target.displayName())
);
int removed = 0;
for (Entity entity : target.getNearbyEntities(radius, radius, radius)) {
if (entity instanceof HumanEntity)
continue;
// PERFORMANCE hit?
if (entity instanceof Tameable tameable && (tameable.isTamed() && tameable.getOwner() instanceof Player || tameable.getOwner() instanceof OfflinePlayer) && mobData != MobData.TAMED)
continue;
// TODO - named entities
if (entity instanceof LivingEntity && entity.customName() != null)
continue;
switch (mobData) {
case ITEMS -> {
if (entity instanceof Item) {
entity.remove();
removed++;
}
}
case ARROWS -> {
if (entity instanceof Projectile) {
entity.remove();
removed++;
}
}
case BOATS -> {
if (entity instanceof Boat) {
entity.remove();
removed++;
}
}
case MINECARTS -> {
if (entity instanceof Minecart) {
entity.remove();
removed++;
}
}
case XP -> {
if (entity instanceof ExperienceOrb) {
entity.remove();
removed++;
}
}
case PAINTINGS -> {
if (entity instanceof Painting) {
entity.remove();
removed++;
}
}
case ITEMFRAMES -> {
if (entity instanceof ItemFrame) {
entity.remove();
removed++;
}
}
case ENDERCRYSTALS -> {
if (entity instanceof EnderCrystal) {
entity.remove();
removed++;
}
}
case FIREWORKS -> {
if (entity instanceof Firework) {
entity.remove();
removed++;
}
}
case HOSTILE, MONSTERS -> {
if (entity instanceof Monster ||entity instanceof ComplexLivingEntity || entity instanceof Flying || entity instanceof Slime) {
entity.remove();
removed++;
}
}
case PASSIVE, ANIMALS -> {
if (entity instanceof Animals || entity instanceof Snowman || entity instanceof WaterMob || entity instanceof Ambient) {
entity.remove();
removed++;
}
}
case AMBIENT -> {
if (entity instanceof Ambient) {
entity.remove();
removed++;
}
}
case MOBS -> {
if (entity instanceof Monster ||entity instanceof ComplexLivingEntity || entity instanceof Flying || entity instanceof Slime || entity instanceof Animals || entity instanceof Snowman || entity instanceof WaterMob || entity instanceof Ambient) {
entity.remove();
removed++;
}
}
case ENTITIES -> {
entity.remove();
removed++;
}
case TAMED -> {
if (entity instanceof Tameable tameable && tameable.isTamed()) {
entity.remove();
removed++;
}
}
}
}
}
public void execute(CommandSender sender, Player target, EntityType entityType, int radius, boolean named) { // TODO - Messages from config, placeholders
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("requester", sender.name()),
Placeholder.component("target", target.displayName())
);
int removed = 0;
for (Entity entity : target.getNearbyEntities(radius, radius, radius)) {
if (entity instanceof HumanEntity)
continue;
// PERFORMANCE hit?
if (entity instanceof Tameable tameable && (tameable.isTamed() && tameable.getOwner() instanceof Player || tameable.getOwner() instanceof OfflinePlayer))
continue;
// TODO - named entities
if (entity instanceof LivingEntity && entity.customName() != null)
continue;
if (entity.getType() == entityType) {
entity.remove();
removed++;
}
}
}
}
@@ -1,97 +0,0 @@
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 org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
// TODO -- output messages
public class PlayerTimeCommand implements EssentiaCommand {
@Override
public String commandName() {
return "playertime";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.then(
Commands.literal("freeze")
.executes(commandContext -> {
if (commandContext.getSource().getSender() instanceof Player player)
setTime(player, player.getPlayerTime());
return 1;
})
)
.then(
Commands.literal("unfreeze")
.executes(commandContext -> {
if (commandContext.getSource().getSender() instanceof Player player)
reset(player);
return 1;
})
)
.then(
Commands.literal("day")
.executes(commandContext -> {
if (commandContext.getSource().getSender() instanceof Player player)
setTime(player, 1000);
return 1;
})
)
.then(
Commands.literal("noon")
.executes(commandContext -> {
if (commandContext.getSource().getSender() instanceof Player player)
setTime(player, 6000);
return 1;
})
)
.then(
Commands.literal("night")
.executes(commandContext -> {
if (commandContext.getSource().getSender() instanceof Player player)
setTime(player, 13000);
return 1;
})
)
.then(
Commands.literal("midnight")
.executes(commandContext -> {
if (commandContext.getSource().getSender() instanceof Player player)
setTime(player, 18000);
return 1;
})
);
return builder.build();
}
void reset(Player player) {
player.resetPlayerTime();
}
void setTime(Player player, long time) {
player.setPlayerTime(time, false);
}
public List<String> aliases() {
return List.of("ptime");
}
}
@@ -1,80 +0,0 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.commands.argumement.WeatherArgument;
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.WeatherType;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
// TODO -- output messages
public class PlayerWeatherCommand implements EssentiaCommand {
@Override
public String commandName() {
return "playerweather";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.then(
Commands.literal("reset")
.executes(commandContext -> {
if (commandContext.getSource().getSender() instanceof Player player)
resetWeather(player);
return 1;
})
)
.then(
Commands.argument("weather", new WeatherArgument())
.executes(commandContext -> {
if (!(commandContext.getSource().getSender() instanceof Player player))
return 1;
WeatherType weatherType = commandContext.getArgument("weather", WeatherType.class);
execute(commandContext.getSource().getSender(), player, weatherType);
return 1;
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes(commandContext -> {
CommandSourceStack sourceStack = commandContext.getSource();
Player target = commandContext.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
WeatherType weatherType = commandContext.getArgument("weather", WeatherType.class);
execute(commandContext.getSource().getSender(), target, weatherType);
return 1;
})
)
);
return builder.build();
}
public void execute(CommandSender sender, Player target, WeatherType weatherType) {
target.setPlayerWeather(weatherType);
}
void resetWeather(Player player) {
player.resetPlayerWeather();
}
public List<String> aliases() {
return List.of("pweather");
}
}
@@ -1,58 +0,0 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.request.RandomTeleportRequest;
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 RandomTeleportCommand implements EssentiaCommand {
@Override
public String commandName() {
return "randomteleport";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()))
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
execute(source.getSource().getSender(), target);
return 1;
})
);
return builder.build();
}
@Override
public String description() {
return "Teleport a player to a random location!";
}
public void execute(CommandSender sender, Player target) { // TODO - messages
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("requester", sender.name()),
Placeholder.component("target", target.displayName())
);
new RandomTeleportRequest(EssentiaPlugin.instance(), target, target);
}
}
@@ -1,79 +0,0 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.commands.argumement.EquipmentArgumentType;
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.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.jetbrains.annotations.NotNull;
public class RepairCommand implements EssentiaCommand {
@Override
public String commandName() {
return "repair";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()))
// .executes((source) -> {
// if (source.getSource().getSender() instanceof Player player)
// execute(player, player);
//
// return 1;
// })
.then(Commands.argument("equipmentslot", new EquipmentArgumentType())
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
EquipmentSlot equipmentSlot = source.getArgument("equipmentslot", EquipmentSlot.class);
execute(source.getSource().getSender(), player, equipmentSlot);
return 1;
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
EquipmentSlot equipmentSlot = source.getArgument("equipmentslot", EquipmentSlot.class);
execute(source.getSource().getSender(), target, equipmentSlot);
return 1;
})
)
);
return builder.build();
}
// TODO - placeholders and messages from config
public void execute(CommandSender sender, Player target, EquipmentSlot equipmentSlot) {
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("requester", sender.name()),
Placeholder.component("target", target.displayName())
);
ItemStack itemStack = target.getInventory().getItem(equipmentSlot);
if (!(itemStack.getItemMeta() instanceof Damageable damageable))
return; // send message can not repair this item
damageable.setDamage(0);
sender.sendRichMessage(target == sender ? "You have repaired your <item>." : "<sender> has repaired your <item>.", placeholders);
if (target != sender)
target.sendRichMessage("You repaired <target>'s <item>.", placeholders);
}
}
@@ -1,48 +0,0 @@
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 org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class SetSpawnCommand implements EssentiaCommand {
@Override
public String commandName() {
return "setspawn";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
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) {
// Todo - output messages
World world = target.getWorld();
world.setSpawnLocation(target.getLocation());
// TODO -- method in config to update & save
Config.config.set("spawn-world", world.getName());
Config.SPAWN_WORLD = world.getName();
Config.saveConfig();
}
}
@@ -18,17 +18,14 @@ import java.util.List;
public class SmiteCommand implements EssentiaCommand {
@Override
public String commandName() {
return "smite";
}
static String commandName = "smite";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
@@ -38,10 +35,10 @@ public class SmiteCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
execute(source.getSource().getSender(), target);
return 1;
@@ -1,55 +0,0 @@
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.registry.RegistryKey;
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.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.jetbrains.annotations.NotNull;
// TODO -- FINISH ME - messages and options?
public class SpawnMobCommand implements EssentiaCommand {
@Override
public String commandName() {
return "spawnmob";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
)
.then(
Commands.argument("entity", ArgumentTypes.resource(RegistryKey.ENTITY_TYPE))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes((source) -> {
EntityType entityType = source.getArgument("entity", EntityType.class);
execute(source.getSource().getSender(), (Player) source.getSource().getSender(), entityType);
return 1;
})
);
return builder.build();
}
public void execute(CommandSender sender, Player target, EntityType entityType) { // TODO - implement player info
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("requester", sender.name()),
Placeholder.component("target", target.displayName())
);
target.getWorld().spawn(target.getLocation(), entityType.getEntityClass(), CreatureSpawnEvent.SpawnReason.COMMAND);
}
}
@@ -7,6 +7,9 @@ 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;
@@ -14,25 +17,22 @@ import java.util.List;
public class TeleportCommand implements EssentiaCommand {
@Override
public String commandName() {
return "teleport";
}
static String commandName = "teleport";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
commandSourceStack.getSender() instanceof Player
)
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
execute((Player) source.getSource().getSender(), target);
return 1;
@@ -14,25 +14,22 @@ import java.util.List;
public class TeleportHereCommand implements EssentiaCommand {
@Override
public String commandName() {
return "teleporthere";
}
static String commandName = "teleporthere";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
commandSourceStack.getSender() instanceof Player
)
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
execute((Player) source.getSource().getSender(), target);
return 1;
@@ -16,17 +16,14 @@ import java.util.List;
public class TeleportPositionCommand implements EssentiaCommand {
@Override
public String commandName() {
return "teleportposition";
}
static String commandName = "teleportposition";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
commandSourceStack.getSender() instanceof Player
)
.then(
@@ -42,13 +39,13 @@ public class TeleportPositionCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
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;
@@ -1,93 +0,0 @@
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 org.bukkit.GameRule;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
// TODO -- output messages
public class TimeCommand implements EssentiaCommand {
@Override
public String commandName() {
return "time";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.then(
Commands.literal("freeze")
.executes(commandContext -> {
if (commandContext.getSource().getSender() instanceof Player player)
freeze(player, true);
return 1;
})
)
.then(
Commands.literal("unfreeze")
.executes(commandContext -> {
if (commandContext.getSource().getSender() instanceof Player player)
freeze(player, false);
return 1;
})
)
.then(
Commands.literal("day")
.executes(commandContext -> {
if (commandContext.getSource().getSender() instanceof Player player)
setTime(player, 1000);
return 1;
})
)
.then(
Commands.literal("noon")
.executes(commandContext -> {
if (commandContext.getSource().getSender() instanceof Player player)
setTime(player, 6000);
return 1;
})
)
.then(
Commands.literal("night")
.executes(commandContext -> {
if (commandContext.getSource().getSender() instanceof Player player)
setTime(player, 13000);
return 1;
})
)
.then(
Commands.literal("midnight")
.executes(commandContext -> {
if (commandContext.getSource().getSender() instanceof Player player)
setTime(player, 18000);
return 1;
})
);
return builder.build();
}
void freeze(Player player, boolean value) {
player.getWorld().setGameRule(GameRule.DO_DAYLIGHT_CYCLE, value);
}
void setTime(Player player, int time) {
player.getWorld().setTime(time);
}
}
@@ -19,24 +19,21 @@ import org.jetbrains.annotations.NotNull;
public class UnCuffCommand implements EssentiaCommand {
@Override
public String commandName() {
return "uncuff";
}
static String commandName = "uncuff";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
)
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
execute(source.getSource().getSender(), target);
return 1;
@@ -18,17 +18,14 @@ import org.jetbrains.annotations.NotNull;
public class WalkSpeedCommand implements EssentiaCommand {
@Override
public String commandName() {
return "walkspeed";
}
static String commandName = "walkspeed";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
).then(
Commands.argument("speed", FloatArgumentType.floatArg(-1, 1))
.executes((source) -> {
@@ -42,10 +39,10 @@ public class WalkSpeedCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
float speed = source.getArgument("speed", Float.class);
execute(source.getSource().getSender(), target, speed);
@@ -1,103 +0,0 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.commands.EssentiaCommand;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Random;
// TODO -- output messages
public class WeatherCommand implements EssentiaCommand {
@Override
public String commandName() {
return "weather";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.then(
Commands.literal("clear")
.executes(commandContext -> {
if (commandContext.getSource().getSender() instanceof Player player)
clearWeather(player, -1);
return 1;
})
.then(
Commands.argument("duration", ArgumentTypes.time())
.executes(commandContext -> {
int duration = commandContext.getArgument("duration", Integer.class);
if (commandContext.getSource().getSender() instanceof Player player)
clearWeather(player, duration);
return 1;
})
)
)
.then(
Commands.literal("rain")
.executes(commandContext -> {
if (commandContext.getSource().getSender() instanceof Player player)
setRain(player, -1, false);
return 1;
})
.then(
Commands.argument("duration", ArgumentTypes.time())
.executes(commandContext -> {
int duration = commandContext.getArgument("duration", Integer.class);
if (commandContext.getSource().getSender() instanceof Player player)
setRain(player, duration, false);
return 1;
})
)
)
.then(
Commands.literal("thunder")
.executes(commandContext -> {
if (commandContext.getSource().getSender() instanceof Player player)
setRain(player, -1, true);
return 1;
})
.then(
Commands.argument("duration", ArgumentTypes.time())
.executes(commandContext -> {
int duration = commandContext.getArgument("duration", Integer.class);
if (commandContext.getSource().getSender() instanceof Player player)
setRain(player, duration, true);
return 1;
})
)
);
return builder.build();
}
public void clearWeather(Player player, int duration) {
player.getWorld().setClearWeatherDuration(duration == -1 ? new Random().nextInt() : duration);
}
public void setRain(Player player, int duration, boolean thunder) {
player.getWorld().setStorm(thunder);
player.getWorld().setWeatherDuration(duration == -1 ? new Random().nextInt() : duration);
}
}
@@ -13,21 +13,19 @@ 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 {
@Override
public String commandName() {
return "workbench";
}
static String commandName = "workbench";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
@@ -37,10 +35,10 @@ public class WorkBenchCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
execute(source.getSource().getSender(), target);
return 1;
@@ -1,6 +1,5 @@
package com.alttd.essentia.commands.argumement;
import com.alttd.essentia.commands.EssentiaArgument;
import com.mojang.brigadier.Message;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
@@ -11,23 +10,26 @@ 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.WeatherType;
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.ArrayList;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;
public class WeatherArgument implements CustomArgumentType.Converted<WeatherType, String>, EssentiaArgument {
public class EnchantmentArgument implements CustomArgumentType.Converted<Enchantment, String> {
@Override
public @NotNull WeatherType convert(String nativeType) throws CommandSyntaxException {
public @NotNull Enchantment convert(String nativeType) throws CommandSyntaxException {
try {
return WeatherType.valueOf(nativeType.toUpperCase());
return Enchantment.getByKey(NamespacedKey.minecraft(nativeType));
} catch (Exception e) {
Message message = MessageComponentSerializer.message().serialize(Component.text("Invalid WeatherType %s!".formatted(nativeType), NamedTextColor.RED));
Message message = MessageComponentSerializer.message().serialize(Component.text("Invalid gamemode %s!".formatted(nativeType), NamedTextColor.RED));
throw new CommandSyntaxException(new SimpleCommandExceptionType(message), message);
}
@@ -40,11 +42,12 @@ public class WeatherArgument implements CustomArgumentType.Converted<WeatherType
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
Collection<String> possibleValues = new ArrayList<>();
for (WeatherType weatherType : WeatherType.values()) {
possibleValues.add(weatherType.name().toLowerCase());
for (Enchantment enchantment : RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT)) {
builder.suggest(enchantment.getKey().value());
}
return completedFuture(builder, possibleValues);
return CompletableFuture.completedFuture(
builder.build()
);
}
}
@@ -1,52 +0,0 @@
package com.alttd.essentia.commands.argumement;
import com.alttd.essentia.commands.EssentiaArgument;
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.entity.EntityType;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;
// TODO -- add a wrapper for entitytype and only list those we want to list as this large list breaks tabcomplete
public class EntityTypeArgumentType implements CustomArgumentType.Converted<EntityType, String>, EssentiaArgument {
@Override
public @NotNull EntityType convert(String nativeType) throws CommandSyntaxException {
try {
return EntityType.valueOf(nativeType.toUpperCase());
} catch (Exception e) {
Message message = MessageComponentSerializer.message().serialize(Component.text("Invalid EntityType %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) {
Collection<String> possibleValues = new ArrayList<>();
for (EntityType entityType : EntityType.values()) {
possibleValues.add(entityType.name().toLowerCase());
}
return completedFuture(builder, possibleValues);
}
}
@@ -1,54 +0,0 @@
package com.alttd.essentia.commands.argumement;
import com.alttd.essentia.commands.EssentiaArgument;
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.inventory.EquipmentSlot;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;
public class EquipmentArgumentType implements CustomArgumentType.Converted<EquipmentSlot, String>, EssentiaArgument {
@Override
public @NotNull EquipmentSlot convert(String nativeType) throws CommandSyntaxException {
try {
return EquipmentSlot.valueOf(nativeType.toUpperCase());
} catch (Exception e) {
Message message = MessageComponentSerializer.message().serialize(Component.text("Invalid EquipmentSlot %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) {
Collection<String> possibleValues = new ArrayList<>();
for (EquipmentSlot equipmentSlot : EquipmentSlot.values()) {
if (!equipmentSlot.isHand() || !equipmentSlot.isArmor())
continue;
possibleValues.add(equipmentSlot.name().toLowerCase());
}
return completedFuture(builder, possibleValues);
}
}
@@ -1,7 +1,5 @@
package com.alttd.essentia.commands.argumement;
import com.alttd.essentia.api.model.MobData;
import com.alttd.essentia.commands.EssentiaArgument;
import com.mojang.brigadier.Message;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
@@ -14,20 +12,19 @@ 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.ArrayList;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;
public class MobDataArgumentType implements CustomArgumentType.Converted<MobData, String>, EssentiaArgument {
public class GameModeArgument implements CustomArgumentType.Converted<GameMode, String> {
@Override
public @NotNull MobData convert(String nativeType) throws CommandSyntaxException {
public @NotNull GameMode convert(String nativeType) throws CommandSyntaxException {
try {
return MobData.valueOf(nativeType.toUpperCase());
return GameMode.valueOf(nativeType.toUpperCase());
} catch (Exception e) {
Message message = MessageComponentSerializer.message().serialize(Component.text("Invalid mobdatatype %s!".formatted(nativeType), NamedTextColor.RED));
Message message = MessageComponentSerializer.message().serialize(Component.text("Invalid gamemode %s!".formatted(nativeType), NamedTextColor.RED));
throw new CommandSyntaxException(new SimpleCommandExceptionType(message), message);
}
@@ -40,12 +37,12 @@ public class MobDataArgumentType implements CustomArgumentType.Converted<MobData
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
Collection<String> possibleValues = new ArrayList<>();
for (MobData mobData : MobData.values()) {
possibleValues.add(mobData.name().toLowerCase());
for (GameMode gameMode : GameMode.values()) {
builder.suggest(gameMode.name().toLowerCase());
}
return completedFuture(builder, possibleValues);
return CompletableFuture.completedFuture(
builder.build()
);
}
}
@@ -1,7 +1,5 @@
package com.alttd.essentia.commands.argumement;
import com.alttd.essentia.commands.EssentiaArgument;
import com.alttd.essentia.util.Pair;
import com.mojang.brigadier.Message;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
@@ -19,11 +17,9 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;
public class OfflinePlayerCompletingArgument implements CustomArgumentType.Converted<OfflinePlayer, String>, EssentiaArgument {
public class OfflinePlayerCompletingArgument implements CustomArgumentType.Converted<OfflinePlayer, String> {
@Override
public @NotNull OfflinePlayer convert(String nativeType) throws CommandSyntaxException {
@@ -43,11 +39,12 @@ public class OfflinePlayerCompletingArgument implements CustomArgumentType.Conve
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
Collection<Pair<String, Message>> possibleValues = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers()) {
possibleValues.add(new Pair<>(player.getName(), MessageComponentSerializer.message().serialize(player.displayName())));
builder.suggest(player.getName(), MessageComponentSerializer.message().serialize(player.displayName()));
}
return completedFuturePair(builder, possibleValues);
return CompletableFuture.completedFuture(
builder.build()
);
}
}
@@ -2,7 +2,7 @@ package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.api.events.EssentiaEvent;
import com.alttd.essentia.api.events.player.PlayerTeleportBackEvent;
import com.alttd.essentia.api.events.PlayerTeleportBackEvent;
import com.alttd.essentia.api.user.User;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
@@ -18,17 +18,14 @@ import org.jetbrains.annotations.NotNull;
public class BackCommand implements EssentiaCommand {
@Override
public String commandName() {
return "back";
}
static String commandName = "back";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
@@ -4,7 +4,7 @@ import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
import com.alttd.essentia.api.events.EssentiaEvent;
import com.alttd.essentia.api.events.player.PlayerTeleportBackEvent;
import com.alttd.essentia.api.events.PlayerTeleportBackEvent;
import com.alttd.essentia.tasks.TeleportSounds;
import com.alttd.essentia.api.user.User;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
@@ -20,17 +20,14 @@ import java.util.List;
public class DeathBackCommand implements EssentiaCommand {
@Override
public String commandName() {
return "deathback";
}
static String commandName = "deathback";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
@@ -5,7 +5,7 @@ import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.commands.argumement.OfflinePlayerArgument;
import com.alttd.essentia.configuration.Config;
import com.alttd.essentia.api.events.EssentiaEvent;
import com.alttd.essentia.api.events.player.PlayerRemoveHomeEvent;
import com.alttd.essentia.api.events.PlayerRemoveHomeEvent;
import com.alttd.essentia.api.user.User;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
@@ -23,17 +23,14 @@ import java.util.Collection;
public class DelHomeCommand implements EssentiaCommand {
@Override
public String commandName() {
return "delhome";
}
static String commandName = "delhome";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
@@ -73,11 +70,11 @@ public class DelHomeCommand implements EssentiaCommand {
)
.then(
Commands.argument("player", new OfflinePlayerArgument())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
.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))
if (!(context.getSource().getSender() instanceof Player player))
return Suggestions.empty();
OfflinePlayer target = context.getArgument("player", OfflinePlayer.class);
@@ -18,17 +18,14 @@ import org.jetbrains.annotations.NotNull;
public class DisposeCommand implements EssentiaCommand {
@Override
public String commandName() {
return "dispose";
}
static String commandName = "dispose";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission())
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName)
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
@@ -38,10 +35,10 @@ public class DisposeCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
execute(source.getSource().getSender(), target);
return 1;
@@ -2,7 +2,7 @@ package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.api.events.EssentiaEvent;
import com.alttd.essentia.api.events.player.PlayerTeleportHomeEvent;
import com.alttd.essentia.api.events.PlayerTeleportHomeEvent;
import com.alttd.essentia.api.model.Home;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
@@ -10,33 +10,32 @@ import com.alttd.essentia.api.user.User;
import com.alttd.essentia.tasks.TeleportSounds;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import 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.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
// TODO - home other
public class HomeCommand implements EssentiaCommand {
@Override
public String commandName() {
return "home";
}
static String commandName = "home";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
@@ -47,24 +46,6 @@ public class HomeCommand implements EssentiaCommand {
})
.then(
Commands.argument("name", StringArgumentType.word())
.suggests((context, suggestionsBuilder) -> {
if (!(context.getSource().getSender() instanceof Player player))
return Suggestions.empty();
User user = EssentiaPlugin.instance().userManager().getUser(player);
Collection<String> possibleValues = new ArrayList<>(user.getHomes());
if(possibleValues.isEmpty())
return Suggestions.empty();
String remaining = suggestionsBuilder.getRemaining().toLowerCase();
for (String str : possibleValues) {
if (str.toLowerCase().startsWith(remaining)) {
suggestionsBuilder.suggest(StringArgumentType.escapeIfRequired(str));
}
}
return suggestionsBuilder.buildFuture();
})
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
@@ -102,8 +83,9 @@ public class HomeCommand implements EssentiaCommand {
new TeleportSounds(homeLoc, target.getLocation())
.runTaskLater(EssentiaPlugin.instance(), 1);
String homeName = home;
target.teleportAsync(homeLoc).thenAccept(result ->
target.sendRichMessage(Config.HOME_TELEPORT, Placeholder.unparsed("home", home))
target.sendRichMessage(Config.HOME_TELEPORT, Placeholder.unparsed("home", homeName))
);
}
@@ -19,17 +19,14 @@ import java.util.List;
public class HomeListCommand implements EssentiaCommand {
@Override
public String commandName() {
return "homelist";
}
static String commandName = "homelist";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission())
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName)
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
@@ -39,9 +36,10 @@ public class HomeListCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", new OfflinePlayerCompletingArgument())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
.executes((source) -> {
OfflinePlayer target = source.getArgument("player", OfflinePlayer.class);
CommandSourceStack sourceStack = source.getSource();
OfflinePlayer target = source.getArgument("player", OfflinePlayer.class);;
execute(source.getSource().getSender(), target);
return 1;
@@ -2,7 +2,7 @@ package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.api.events.EssentiaEvent;
import com.alttd.essentia.api.events.player.PlayerSetHomeEvent;
import com.alttd.essentia.api.events.PlayerSetHomeEvent;
import com.alttd.essentia.api.user.User;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.commands.argumement.OfflinePlayerArgument;
@@ -20,17 +20,14 @@ import org.jetbrains.annotations.NotNull;
public class SetHomeCommand implements EssentiaCommand {
@Override
public String commandName() {
return "sethome";
}
static String commandName = "sethome";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
@@ -52,7 +49,7 @@ public class SetHomeCommand implements EssentiaCommand {
)
.then(
Commands.argument("player", new OfflinePlayerArgument())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
.then(
Commands.argument("name", StringArgumentType.word())
.executes((source) -> {
@@ -1,7 +1,8 @@
package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.api.events.player.PlayerTeleportSpawnEvent;
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.api.events.EssentiaEvent;
@@ -21,17 +22,14 @@ import org.jetbrains.annotations.NotNull;
public class SpawnCommand implements EssentiaCommand {
@Override
public String commandName() {
return "spawn";
}
static String commandName = "spawn";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission())
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName)
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
@@ -41,11 +39,11 @@ public class SpawnCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
execute(source.getSource().getSender(), target);
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
execute((Player) source.getSource().getSender(), target);
return 1;
})
@@ -16,17 +16,14 @@ import java.util.List;
public class TeleportAcceptCommand implements EssentiaCommand {
@Override
public String commandName() {
return "teleportaccept";
}
static String commandName = "teleportaccept";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
@@ -16,17 +16,14 @@ import java.util.List;
public class TeleportDenyCommand implements EssentiaCommand {
@Override
public String commandName() {
return "teleportdeny";
}
static String commandName = "teleportdeny";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
@@ -20,28 +20,25 @@ import java.util.List;
public class TeleportRequestCommand implements EssentiaCommand {
@Override
public String commandName() {
return "teleportrequesthere";
}
static String commandName = "teleportrequesthere";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
commandSourceStack.getSender() instanceof Player
)
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
execute(player, target);
return 1;
@@ -20,28 +20,25 @@ import java.util.List;
public class TeleportRequestHereCommand implements EssentiaCommand {
@Override
public String commandName() {
return "teleportrequesthere";
}
static String commandName = "teleportrequesthere";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
commandSourceStack.getSender() instanceof Player
)
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
execute(player, target);
return 1;
@@ -21,17 +21,14 @@ import java.util.List;
public class TeleportToggleCommand implements EssentiaCommand {
@Override
public String commandName() {
return "teleporttoggle";
}
static String commandName = "teleporttoggle";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission())
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName)
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
@@ -41,10 +38,10 @@ public class TeleportToggleCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
execute(source.getSource().getSender(), target);
return 1;
@@ -2,8 +2,7 @@ package com.alttd.essentia.configuration;
import com.alttd.essentia.EssentiaPlugin;
import com.google.common.base.Throwables;
import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -36,7 +35,7 @@ public class Config {
config.load(CONFIG_FILE);
} catch (IOException ignore) {
} catch (InvalidConfigurationException ex) {
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);
}
config.options().header(HEADER);
@@ -45,7 +44,7 @@ public class Config {
version = getInt("config-version", 1);
set("config-version", 1);
log(Level.INFO,"Essentia Configuration loaded!");
EssentiaPlugin.instance().getLogger().info("Essentia Configuration loaded!");
readConfig(Config.class, null);
}
@@ -59,7 +58,7 @@ public class Config {
} catch (InvocationTargetException ex) {
Throwables.throwIfUnchecked(ex);
} catch (Exception ex) {
log(Level.SEVERE, "Error invoking " + method, ex);
EssentiaPlugin.instance().getLogger().log(Level.SEVERE, "Error invoking " + method, ex);
}
}
}
@@ -67,11 +66,11 @@ public class Config {
saveConfig();
}
public static void saveConfig() {
static void saveConfig() {
try {
config.save(CONFIG_FILE);
} catch (IOException ex) {
log(Level.SEVERE, "Could not save " + CONFIG_FILE, ex);
EssentiaPlugin.instance().getLogger().log(Level.SEVERE, "Could not save " + CONFIG_FILE, ex);
}
}
@@ -109,10 +108,6 @@ public class Config {
EssentiaPlugin.instance().getLogger().log(level, s);
}
protected static void log(Level level, String s, Throwable thrown) {
EssentiaPlugin.instance().getLogger().log(level, s, thrown);
}
public static int TELEPORT_REQUEST_TIMEOUT = 30;
public static boolean TELEPORT_REQUEST_TIMEOUT_MESSAGES = true;
public static boolean BACK_ON_DEATH = false;
@@ -276,10 +271,4 @@ public class Config {
MYSQL_PASSWORD = getString("storage.mysql.password", MYSQL_PASSWORD);
}
public static Object2BooleanMap<String> enabledFeatures = new Object2BooleanOpenHashMap<>();
private static void features() {
enabledFeatures.clear();
enabledFeatures.defaultReturnValue(true);
}
}
@@ -1,19 +0,0 @@
package com.alttd.essentia.feature;
public interface EssentiaFeature {
String featureName();
void register();
boolean isEnabled();
default void start() {}
default void stop() {}
default void reload() {
stop();
start();
}
}
@@ -1,57 +0,0 @@
package com.alttd.essentia.feature;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.configuration.Config;
import org.reflections.Reflections;
import org.reflections.scanners.Scanners;
import java.util.*;
import java.util.logging.Level;
public class Features {
private final EssentiaPlugin plugin;
private final Map<String, EssentiaFeature> features;
public Features(EssentiaPlugin plugin) {
this.plugin = plugin;
features = new HashMap<>();
}
public boolean isEnabled(String featureName) {
if (features.containsKey(featureName)) {
return features.get(featureName).isEnabled();
}
return false;
}
public void registerAll() {
Reflections reflections = new Reflections("com.alttd.essentia.feature");
Set<Class<?>> subTypes = reflections.get(Scanners.SubTypes.of(EssentiaFeature.class).asClass());
subTypes.forEach(clazz -> {
try {
EssentiaFeature essentiaFeature = (EssentiaFeature) clazz.getDeclaredConstructor().newInstance();
if (!Config.enabledFeatures.getBoolean(essentiaFeature.featureName())) {
return;
}
essentiaFeature.register();
essentiaFeature.reload();
features.putIfAbsent(essentiaFeature.featureName(), essentiaFeature);
} catch (Exception e) {
log(Level.SEVERE,"Failed to register feature " + clazz.getSimpleName(), e);
}
});
}
protected void log(Level level, String s) {
plugin.getLogger().log(level, s);
}
protected void log(Level level, String s, Throwable thrown) {
plugin.getLogger().log(level, s, thrown);
}
}
@@ -1,30 +0,0 @@
package com.alttd.essentia.feature.cuff;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.feature.EssentiaFeature;
public class CuffFeature implements EssentiaFeature {
private final EssentiaPlugin plugin;
private boolean enabled = false;
public CuffFeature() {
this.plugin = EssentiaPlugin.instance();
}
@Override
public String featureName() {
return "cuff";
}
@Override
public void register() {
this.enabled = true;
}
@Override
public boolean isEnabled() {
return enabled;
}
}
@@ -1,31 +0,0 @@
package com.alttd.essentia.feature.flight;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.feature.EssentiaFeature;
public class FlightFeature implements EssentiaFeature {
private final EssentiaPlugin plugin;
private boolean enabled = false;
public FlightFeature() {
this.plugin = EssentiaPlugin.instance();
}
@Override
public String featureName() {
return "flight";
}
@Override
public void register() {
this.enabled = true;
}
@Override
public boolean isEnabled() {
return enabled;
}
}
@@ -1,45 +0,0 @@
package com.alttd.essentia.feature.godmode;
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.alttd.essentia.feature.EssentiaFeature;
import org.bukkit.entity.Player;
public class GodModeFeature implements EssentiaFeature {
private final EssentiaPlugin plugin;
private boolean enabled = false;
public GodModeFeature() {
this.plugin = EssentiaPlugin.instance();
}
@Override
public String featureName() {
return "GodMode";
}
@Override
public void register() {
this.enabled = true;
}
@Override
public boolean isEnabled() {
return enabled;
}
protected boolean isGodModeEnabled(Player player) {
UserManager userManager = plugin.userManager();
User user = userManager.getUser(player);
if (user == null)
return false;
UserSettings userSettings = user.getUserSettings();
return userSettings.godMode();
}
}
@@ -1,114 +0,0 @@
package com.alttd.essentia.feature.godmode;
import com.destroystokyo.paper.event.entity.PhantomPreSpawnEvent;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.*;
public class GodModeListener implements Listener {
private GodModeFeature godModeFeature;
public GodModeListener(GodModeFeature godModeFeature) {
this.godModeFeature = godModeFeature;
}
@EventHandler
public void onFoodLevelChange(FoodLevelChangeEvent event) {
if (!(event.getEntity() instanceof Player player))
return;
if (!isGodModeEnabled(player))
return;
event.setCancelled(true);
}
@EventHandler
public void onPhantomPreSpawn(PhantomPreSpawnEvent event) {
if (!(event.getSpawningEntity() instanceof Player player))
return;
if (!isGodModeEnabled(player))
return;
event.setCancelled(true);
event.setShouldAbortSpawn(true);
}
@EventHandler
public void onEntityTargetLivingEntity(EntityTargetLivingEntityEvent event) {
if (!(event.getEntity() instanceof Player player))
return;
if (!isGodModeEnabled(player))
return;
event.setCancelled(true);
}
@EventHandler
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
if (!(event.getEntity() instanceof Player player))
return;
if (!isGodModeEnabled(player))
return;
event.setCancelled(true);
}
@EventHandler
public void onPotionSplashEvent(PotionSplashEvent event) {
for (LivingEntity entity : event.getAffectedEntities()) {
if (!(entity instanceof Player player))
continue;
if (!isGodModeEnabled(player))
return;
event.setIntensity(player, 0f);
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onEntityCombustByEntityEvent(EntityCombustByEntityEvent event) {
if (!(event.getEntity() instanceof Player player))
return;
if (!isGodModeEnabled(player))
return;
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEntityCombust(final EntityCombustEvent event) {
if (!(event.getEntity() instanceof Player player))
return;
if (!isGodModeEnabled(player))
return;
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEntityDamage(final EntityDamageEvent event) {
if (!(event.getEntity() instanceof Player player))
return;
if (!isGodModeEnabled(player))
return;
event.setCancelled(true);
}
private boolean isGodModeEnabled(Player player) {
return godModeFeature.isGodModeEnabled(player);
}
}
@@ -1,29 +0,0 @@
package com.alttd.essentia.feature.randomteleport;
import com.alttd.essentia.api.model.randomteleport.LocationValidator;
import org.bukkit.Location;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import java.util.HashSet;
import java.util.Set;
// TODO - load biomes from config
public class BiomeValidator implements LocationValidator {
private final boolean whitelist;
private final Set<Biome> biomes;
public BiomeValidator() {
this.biomes = new HashSet<>();
this.whitelist = false;
this.biomes.add(Biome.OCEAN);
}
@Override
public boolean validate(Location location) {
Block block = location.getBlock();
return biomes.contains(block.getBiome()) == whitelist;
}
}
@@ -1,28 +0,0 @@
package com.alttd.essentia.feature.randomteleport;
import com.alttd.essentia.api.model.randomteleport.LocationValidator;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import java.util.HashSet;
import java.util.Set;
// TODO - load block list from config
public class BlockValidator implements LocationValidator {
private final boolean whitelist;
private final Set<Material> materials;
public BlockValidator() {
materials = new HashSet<>();
this.whitelist = false;
}
@Override
public boolean validate(Location location) {
Block block = location.getBlock();
return materials.contains(block.getType()) == whitelist;
}
}
@@ -1,14 +0,0 @@
package com.alttd.essentia.feature.randomteleport;
import com.alttd.essentia.api.model.randomteleport.LocationValidator;
import org.bukkit.Location;
// TODO - claim hooks for GP. LandClaims should hook into the plugin and add the validator.
public class ProtectionValidator implements LocationValidator {
@Override
public boolean validate(Location location) {
return false;
}
}
@@ -1,13 +0,0 @@
package com.alttd.essentia.feature.randomteleport;
import com.alttd.essentia.api.model.randomteleport.LocationValidator;
import org.bukkit.Location;
public class WorldBorderValidator implements LocationValidator {
@Override
public boolean validate(Location location) {
return location.getWorld().getWorldBorder().isInside(location);
}
}
@@ -1,4 +0,0 @@
package com.alttd.essentia.feature.savedinventory;
public class SavedInventoryFeature {
}
@@ -1,27 +0,0 @@
package com.alttd.essentia.feature.savedinventory;
import com.alttd.essentia.EssentiaPlugin;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class SavedInventoryListener implements Listener {
private final EssentiaPlugin plugin;
public SavedInventoryListener() {
this.plugin = EssentiaPlugin.instance();
}
@EventHandler(ignoreCancelled = true)
public void onPlayerDeath(PlayerDeathEvent event) {
// TODO -- add config value to save on death
}
@EventHandler()
public void onPlayerQuit(PlayerQuitEvent event) {
// TODO -- add config value to save on leave
}
}
@@ -1,8 +0,0 @@
package com.alttd.essentia.feature.savedinventory.gui;
public class SavedInventoryPreviewGUI {
// preview saved inventory, also acts as the live preview of another player's inventory/ec
}
@@ -1,9 +1,9 @@
package com.alttd.essentia.feature.cuff;
package com.alttd.essentia.listeners;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.api.user.User;
import com.alttd.essentia.api.user.UserManager;
import io.papermc.paper.event.player.AsyncChatEvent;
import com.alttd.essentia.configuration.Config;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
@@ -23,26 +23,26 @@ public class CuffListener implements Listener {
this.plugin = EssentiaPlugin.instance();
}
private boolean isNotCuffed(Player player) {
private boolean isCuffed(Player player) {
UserManager userManager = plugin.userManager();
User user = userManager.getUser(player);
if (user == null)
return true;
return false;
return !user.isCuffed();
return user.isCuffed();
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (isNotCuffed(event.getPlayer()))
if (!isCuffed(event.getPlayer()))
return;
cancelEvent(event, event.getPlayer());
}
@EventHandler
public void onAsyncPlayerChat(AsyncChatEvent event) {
if (isNotCuffed(event.getPlayer()))
public void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
if (!isCuffed(event.getPlayer()))
return;
// TODO
@@ -57,7 +57,7 @@ public class CuffListener implements Listener {
if (!(event.getWhoClicked() instanceof Player player))
return;
if (isNotCuffed(player))
if (!isCuffed(player))
return;
cancelEvent(event, player);
@@ -65,7 +65,7 @@ public class CuffListener implements Listener {
@EventHandler
public void onPlayerDropItemEvent(PlayerDropItemEvent event) {
if (isNotCuffed(event.getPlayer()))
if (!isCuffed(event.getPlayer()))
return;
cancelEvent(event, event.getPlayer());
@@ -76,7 +76,7 @@ public class CuffListener implements Listener {
if (!(event.getEntity().getShooter() instanceof Player player))
return;
if (isNotCuffed(player))
if (!isCuffed(player))
return;
cancelEvent(event, player);
@@ -87,7 +87,7 @@ public class CuffListener implements Listener {
if (!(event.getDamager() instanceof Player player))
return;
if (isNotCuffed(player))
if (!isCuffed(player))
return;
cancelEvent(event, player);
@@ -98,7 +98,7 @@ public class CuffListener implements Listener {
if (!(event.getEntity() instanceof Player player))
return;
if (isNotCuffed(player))
if (!isCuffed(player))
return;
cancelEvent(event, player);
@@ -107,7 +107,7 @@ public class CuffListener implements Listener {
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
if (isNotCuffed(player))
if (!isCuffed(player))
return;
Location from = event.getFrom();
@@ -120,6 +120,7 @@ public class CuffListener implements Listener {
if (from.getWorld() != to.getWorld() || from.getBlockX() != to.getBlockX() || from.getBlockZ() != to.getBlockZ()) {
cancelEvent(event, player);
return;
}
}
@@ -1,4 +1,4 @@
package com.alttd.essentia.feature.flight;
package com.alttd.essentia.listeners;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.api.model.UserSettings;
@@ -8,7 +8,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
// TODO -- set flight and flying when player logs in!
public class FlightListener implements Listener {
private final EssentiaPlugin plugin;
@@ -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();
}
}
@@ -17,7 +17,7 @@ public class EssentiaUserSettings implements UserSettings {
private boolean needsSaving;
private EssentiaUserSettings(Builder builder) {
this.godMode = builder.godMode;
this.godMode = builder.godMode;;
this.flying = builder.flying;
this.flySpeed = builder.flySpeed;
this.walkSpeed = builder.walkSpeed;
@@ -0,0 +1,4 @@
package com.alttd.essentia.model;
public record PlayerInventory() {
}
@@ -1,8 +0,0 @@
package com.alttd.essentia.model;
import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;
import java.util.UUID;
public record SavedInventory(int id, ItemStack[] storageContents, ItemStack[] armorContents, UUID ownerUUID, String saveReason, Location location, long date) { }
@@ -1,12 +0,0 @@
package com.alttd.essentia.model.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Depends {
String value();
}
@@ -12,10 +12,10 @@ import org.bukkit.entity.Player;
public abstract class EssentiaRequest implements Request {
protected final EssentiaPlugin plugin;
private final EssentiaPlugin plugin;
@Getter private final Player requester;
@Getter private final Player target;
@Getter private final RequestTimeout timeoutTask;
private final RequestTimeout timeoutTask;
TagResolver placeholders;
@@ -1,168 +0,0 @@
package com.alttd.essentia.request;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.api.model.randomteleport.LocationValidator;
import com.google.common.collect.Multimap;
import com.google.common.collect.MultimapBuilder;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
public class RandomTeleportRequest extends EssentiaRequest {
private static final List<int[]> CHUNK_POS = new ArrayList<>();
private final Multimap<Integer, Integer> checked = MultimapBuilder.hashKeys().hashSetValues().build();
private final Random random;
private final Location center; // todo - config
private final int minRadius; // todo - config
private final int maxRadius; // todo - config
private final int maxTries = 100; // TODO - config
private int checks;
CompletableFuture<Location> future;
static {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
CHUNK_POS.add(new int[]{x, z});
}
}
}
public RandomTeleportRequest(EssentiaPlugin plugin, Player requester, Player target) {
super(plugin, requester, target);
this.random = new Random();
this.center = Bukkit.getWorlds().getFirst().getSpawnLocation(); // todo - config and sanity check for worlds
this.minRadius = 50;
this.maxRadius = 20000;
this.timeoutTask().cancel();
this.teleport();
}
/**
* Start searching for a safe random location within the world
*
* @return A CompletableFuture for when the searching is finished.
*/
public CompletableFuture<Location> startSearch() {
future = new CompletableFuture<>();
target().sendRichMessage("Running search task");
plugin.getServer().getScheduler().runTask(plugin, () -> searchRandomLocation(future));
return future;
}
// needs to be a task
private void searchRandomLocation(CompletableFuture<Location> future) {
if (future.isCancelled() || future.isDone() || future.isCompletedExceptionally()) {
return;
}
Location randomLoc = center.clone();
int minChunk = minRadius >> 4;
int maxChunk = maxRadius >> 4;
int randChunkX;
int randChunkZ;
do {
checks++;
if (checks >= maxTries) {
future.completeExceptionally(new Exception("Could not find random location within %s tries".formatted(maxTries + "")));
return;
}
randChunkX = (random.nextBoolean() ? 1 : -1) * random.nextInt(maxChunk + 1);
randChunkZ = (random.nextBoolean() ? 1 : -1) * random.nextInt(maxChunk + 1);
target().sendRichMessage("randChunkX: " + randChunkX + ", randChunkZ: " + randChunkZ);
} while (!checked.put(randChunkX, randChunkZ)
|| !inRadius(Math.abs(randChunkX), Math.abs(randChunkZ), minChunk, maxChunk)
/*|| randomLoc.getWorld().isChunkGenerated(randChunkX, randChunkZ)*/);
randomLoc.setX(((center.getBlockX() >> 4) + randChunkX) * 16);
randomLoc.setZ(((center.getBlockZ() >> 4) + randChunkZ) * 16);
randomLoc.getWorld().getChunkAtAsync(randomLoc).thenApply(chunk -> {
if (chunk == null) {
searchRandomLocation(future);
return false;
}
chunk.addPluginChunkTicket(plugin);
try {
int indexOffset = random.nextInt(CHUNK_POS.size());
Location foundLoc = null;
for (int i = 0; i < CHUNK_POS.size(); i++) {
int index = (i + indexOffset) % CHUNK_POS.size();
boolean validated = true;
Location loc = randomLoc.clone().add(CHUNK_POS.get(index)[0], 0, CHUNK_POS.get(index)[1]);
if (!inRadius(loc)) {
continue;
}
for (LocationValidator validator : plugin.locationValidators()) {
if (!validator.validate(loc)) {
validated = false;
break;
}
}
if (validated) {
foundLoc = loc;
break;
}
}
if (foundLoc != null) {
// all checks are for the top block, put we want a location above that so add 1 to y
future.complete(foundLoc.add(0, 1, 0));
return true;
}
plugin.getServer().getScheduler().runTaskLater(plugin, () -> searchRandomLocation(future), 1);
return false;
} finally {
chunk.removePluginChunkTicket(plugin);
}
}).exceptionally(future::completeExceptionally);
}
private boolean inRadius(Location location) {
int diffX = Math.abs(location.getBlockX() - center.getBlockX());
int diffZ = Math.abs(location.getBlockZ() - center.getBlockZ());
return inRadius(diffX, diffZ, minRadius, maxRadius);
}
private boolean inRadius(int diffX, int diffZ, int minRadius, int maxRadius) {
return diffX >= minRadius && diffX <= maxRadius && diffZ <= maxRadius
|| diffZ >= minRadius && diffZ <= maxRadius && diffX <= maxRadius;
}
@Override
protected void teleport() {
startSearch().thenApply(randomLocation -> {
randomLocation.setX(randomLocation.getBlockX() + 0.5);
randomLocation.setY(randomLocation.getY() + 0.5);
randomLocation.setZ(randomLocation.getBlockZ() + 0.5);
target().teleportAsync(randomLocation)
.whenComplete((success, exception) -> {
target().sendMessage("You have been teleported to a random location."); // todo -- config
});
return true;
});
if (!target().isOnline() || !requester().isOnline()) {
cancel();
return;
}
}
@Override
public void cancel() {
try {
timeoutTask().cancel();
} catch (IllegalStateException ignore) {
}
}
}
@@ -1,6 +1,8 @@
package com.alttd.essentia.storage;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.storage.mysql.SQLStorageProvider;
import com.alttd.essentia.storage.sqlite.SQLiteStorageProvider;
import com.alttd.essentia.storage.yaml.YamlStorageProvider;
import java.io.File;
@@ -45,9 +45,9 @@ public class DatabaseQuery {
void edit(PreparedStatement preparedStatement) throws SQLException;
default void onSuccess(ResultSet resultSet) throws SQLException {}
default void onSuccess(ResultSet resultSet) throws SQLException {};
default void onSuccess() throws SQLException {}
default void onSuccess() throws SQLException {};
default void onFailure(SQLException e) {
e.printStackTrace();
@@ -1,5 +0,0 @@
package com.alttd.essentia.util;
public record Pair<X, Y>(X x, Y y) {
}
@@ -1,17 +0,0 @@
package com.alttd.essentia.util;
import com.alttd.essentia.EssentiaPlugin;
public class Timer {
public Timer(String id, Runnable runnable) {
long startTime = System.currentTimeMillis();
runnable.run();
long duration = System.currentTimeMillis() - startTime;
EssentiaPlugin.instance().getLogger().info("Loading " + id + " took " + duration + "ms");
}
}
-1
View File
@@ -2,7 +2,6 @@ name: Essentia
version: ${version}
main: com.alttd.essentia.EssentiaPlugin
description: Altitude essentials ;)
load: POSTWORLD
authors:
- destro174
api-version: "1.21"