29 Commits
Author SHA1 Message Date
Len 1f88f6ea0d Stub for SavedInventory 2025-11-12 23:18:24 +01:00
Len 798946b386 Refactor Events 2025-11-12 23:17:44 +01:00
Len c32bd21f0f Refactor Events 2025-11-12 23:16:56 +01:00
Len 99dcb318ad Use reflection to load feature event listeners 2025-06-29 17:03:11 +02:00
Len fa289a8737 Only add player equipment to EquipmentArgumentType 2025-06-29 16:34:18 +02:00
Len b68835918f Implement CuffFeature 2025-06-29 14:36:59 +02:00
Len d3cd059af1 Implement FlightFeature 2025-06-29 13:35:57 +02:00
Len 612a0281d6 Implement GodModeFeature 2025-06-29 13:33:21 +02:00
Len d4f33b8c2e Implement EssentiaFeatures 2025-06-29 13:01:37 +02:00
Len 9fa43c8c65 Add Timer.java 2025-06-29 12:50:51 +02:00
Len 13a78515c5 Switch to use Cosmos 2025-06-29 08:31:59 +02:00
Len 91e6d3be8e Inline logging in Config.java 2025-06-29 08:28:07 +02:00
Len 06a8aa0f65 Implement base for RTP 2024-10-20 14:22:45 +02:00
Len 139c51e9b8 Make plugin load postworld 2024-10-15 21:38:46 +02:00
Len ed0d15b3d4 Add KillallCommand.java 2024-10-05 16:06:01 +02:00
Len 76ae3103de Add SpawnMobCommand.java 2024-10-04 22:48:44 +02:00
Len 434cf6ac15 Remove EnchantmentArgument.java 2024-10-04 22:46:24 +02:00
Len d786ebcff5 Add EssentiaCommandArgument 2024-10-04 22:43:32 +02:00
Len 2ef960b189 Fix commands not being loaded by reflection. 2024-10-04 21:24:18 +02:00
Len 4dba5f3c41 Add RepairCommand 2024-10-04 21:05:26 +02:00
Len dbb3f45898 Move command permissions to EssentiaCommand interface. 2024-10-04 18:34:02 +02:00
Len 162ffd3599 Update GameModeCommand to use native GameModeArgument 2024-10-04 17:04:34 +02:00
Len 430e6fb898 Fix typo in EnchantmentArgument.java 2024-10-04 17:04:34 +02:00
Len aede22811a Add TimeCommand 2024-08-15 21:08:08 +02:00
Len a8221a68af Add reset option to pweather 2024-08-15 17:49:45 +02:00
Len 29559b83c4 Add SetSpawnCommand.java 2024-08-15 17:43:31 +02:00
Len be8b7e20df Add PlayerWeatherCommand.java and WeatherArgument.java 2024-08-15 17:23:12 +02:00
Len 6a8e21852c Add WeatherCommand.java 2024-08-15 17:15:31 +02:00
Len ff2824f287 Switch to brigadier for commands 2024-08-15 15:58:25 +02:00
88 changed files with 2154 additions and 327 deletions
@@ -1,5 +1,6 @@
package com.alttd.essentia;
import com.alttd.essentia.api.model.randomteleport.LocationValidator;
import org.jetbrains.annotations.ApiStatus;
public interface EssentiaAPI {
@@ -19,4 +20,6 @@ public interface EssentiaAPI {
Provider.instance = instance;
}
}
public void addLocationValidator(LocationValidator locationValidator);
}
@@ -0,0 +1,40 @@
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,5 +1,6 @@
package com.alttd.essentia.api.events;
package com.alttd.essentia.api.events.player;
import com.alttd.essentia.api.events.EssentiaEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
@@ -1,5 +1,6 @@
package com.alttd.essentia.api.events;
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;
@@ -1,5 +1,6 @@
package com.alttd.essentia.api.events;
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;
@@ -1,5 +1,6 @@
package com.alttd.essentia.api.events;
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;
@@ -1,5 +1,6 @@
package com.alttd.essentia.api.events;
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;
@@ -0,0 +1,23 @@
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
}
@@ -0,0 +1,8 @@
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"
}
+1 -9
View File
@@ -5,7 +5,7 @@ plugins {
dependencies {
implementation(project(":api"))
compileOnly("com.alttd:Galaxy-API:1.21.1-R0.1-SNAPSHOT")
compileOnly("com.alttd.cosmos:cosmos-api:1.21.6-R0.1-SNAPSHOT")
api("org.reflections:reflections:0.10.2")
compileOnly("org.projectlombok:lombok:1.18.34")
@@ -25,11 +25,3 @@ tasks {
}
}
}
//bukkit {
// name = rootProject.name
// main = "$group.${rootProject.name}Plugin"
// version = "${rootProject.version}"
// apiVersion = "1.20"
// authors = listOf("destro174")
//}
@@ -2,11 +2,15 @@ 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;
@@ -18,6 +22,8 @@ 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 {
@@ -27,10 +33,15 @@ 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;
@@ -39,11 +50,15 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
@Override
public void onEnable() {
loadConfiguration();
loadCommands();
loadEventListeners();
loadManagers();
loadStorageProvider();
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);
});
}
@Override
@@ -57,6 +72,11 @@ 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());
@@ -67,6 +87,13 @@ 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());
@@ -77,12 +104,21 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
void loadEventListeners() {
final PluginManager pluginManager = getServer().getPluginManager();
Reflections reflections = new Reflections("com.alttd.essentia.listeners");
Reflections reflections = new Reflections("com.alttd.essentia.listeners"); // These are plugin required listeners eg player data loading on login.
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());
@@ -100,4 +136,26 @@ 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);
}
}
@@ -0,0 +1,41 @@
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,6 +9,8 @@ import java.util.List;
// TODO -- add optional -s -silent parameters to commands?
public interface EssentiaCommand {
String commandName();
@NotNull LiteralCommandNode<CommandSourceStack> command();
default String description() {
@@ -19,4 +21,20 @@ 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,14 +16,17 @@ import org.jetbrains.annotations.NotNull;
public class BurnCommand implements EssentiaCommand {
static String commandName = "burn";
@Override
public String commandName() {
return "burn";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
@@ -33,10 +36,10 @@ public class BurnCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
execute(source.getSource().getSender(), target);
return 1;
@@ -16,14 +16,17 @@ import org.jetbrains.annotations.NotNull;
public class ClearInventoryCommand implements EssentiaCommand {
static String commandName = "clearinventory";
@Override
public String commandName() {
return "clearinventory";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
@@ -34,10 +37,10 @@ public class ClearInventoryCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
execute(source.getSource().getSender(), target);
return 1;
@@ -19,21 +19,24 @@ import org.jetbrains.annotations.NotNull;
public class CuffCommand implements EssentiaCommand {
static String commandName = "cuff";
@Override
public String commandName() {
return "cuff";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
)
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
execute(source.getSource().getSender(), target);
return 1;
@@ -1,7 +1,6 @@
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;
@@ -9,6 +8,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.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,17 +20,20 @@ import org.jetbrains.annotations.NotNull;
public class EnchantCommand implements EssentiaCommand {
static String commandName = "enchant";
@Override
public String commandName() {
return "enchant";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
)
.then(
Commands.argument("enchantment", new EnchantmentArgument())
Commands.argument("enchantment", ArgumentTypes.resource(RegistryKey.ENCHANTMENT))
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
@@ -51,10 +54,10 @@ public class EnchantCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
Enchantment enchantment = source.getArgument("enchantment", Enchantment.class);
int level = source.getArgument("level", Integer.class);
execute(source.getSource().getSender(), target, enchantment, level);
@@ -10,11 +10,16 @@ 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("essentia")
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin.reload"))
Commands.literal(commandName())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()))
.executes((commandContext -> 1))
.then(
Commands.literal("reload")
@@ -16,14 +16,17 @@ import org.jetbrains.annotations.NotNull;
public class FeedCommand implements EssentiaCommand {
static String commandName = "feed";
@Override
public String commandName() {
return "feed";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
@@ -34,10 +37,10 @@ public class FeedCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
execute(source.getSource().getSender(), target);
return 1;
@@ -20,14 +20,17 @@ import org.jetbrains.annotations.NotNull;
public class FlyCommand implements EssentiaCommand {
static String commandName = "fly";
@Override
public String commandName() {
return "fly";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
@@ -38,10 +41,10 @@ public class FlyCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
execute(source.getSource().getSender(), target);
return 1;
@@ -18,14 +18,17 @@ import org.jetbrains.annotations.NotNull;
public class FlySpeedCommand implements EssentiaCommand {
static String commandName = "flyspeed";
@Override
public String commandName() {
return "flyspeed";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
).then(
Commands.argument("speed", FloatArgumentType.floatArg(-1, 1))
.executes((source) -> {
@@ -39,10 +42,10 @@ public class FlySpeedCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
float speed = source.getArgument("speed", Float.class);
execute(source.getSource().getSender(), target, speed);
@@ -1,7 +1,6 @@
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;
@@ -9,7 +8,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.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;
@@ -19,17 +17,20 @@ import org.jetbrains.annotations.NotNull;
public class GameModeCommand implements EssentiaCommand {
static String commandName = "gamemode";
@Override
public String commandName() {
return "gamemode";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
)
.then(
Commands.argument("gamemode", new GameModeArgument())
Commands.argument("gamemode", ArgumentTypes.gameMode())
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
@@ -40,10 +41,10 @@ public class GameModeCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
GameMode gameMode = source.getArgument("gamemode", GameMode.class);
execute(source.getSource().getSender(), target, gameMode);
return 1;
@@ -20,14 +20,17 @@ import org.jetbrains.annotations.NotNull;
public class GodCommand implements EssentiaCommand {
static String commandName = "god";
@Override
public String commandName() {
return "god";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
@@ -38,10 +41,10 @@ public class GodCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
execute(source.getSource().getSender(), target);
return 1;
@@ -14,17 +14,19 @@ 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 {
static String commandName = "heal";
@Override
public String commandName() {
return "heal";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
@@ -35,10 +37,10 @@ public class HealCommand
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
execute(source.getSource().getSender(), target);
return 1;
@@ -15,14 +15,17 @@ import org.jetbrains.annotations.NotNull;
public class InfoCommand implements EssentiaCommand {
static String commandName = "info";
@Override
public String commandName() {
return "info";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
@@ -32,10 +35,10 @@ public class InfoCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
execute(source.getSource().getSender(), target);
return 1;
@@ -0,0 +1,246 @@
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++;
}
}
}
}
@@ -0,0 +1,97 @@
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");
}
}
@@ -0,0 +1,80 @@
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");
}
}
@@ -0,0 +1,58 @@
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);
}
}
@@ -0,0 +1,79 @@
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);
}
}
@@ -0,0 +1,48 @@
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,14 +18,17 @@ import java.util.List;
public class SmiteCommand implements EssentiaCommand {
static String commandName = "smite";
@Override
public String commandName() {
return "smite";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
@@ -35,10 +38,10 @@ public class SmiteCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
execute(source.getSource().getSender(), target);
return 1;
@@ -0,0 +1,55 @@
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,9 +7,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 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;
@@ -17,22 +14,25 @@ import java.util.List;
public class TeleportCommand implements EssentiaCommand {
static String commandName = "teleport";
@Override
public String commandName() {
return "teleport";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
execute((Player) source.getSource().getSender(), target);
return 1;
@@ -14,22 +14,25 @@ import java.util.List;
public class TeleportHereCommand implements EssentiaCommand {
static String commandName = "teleporthere";
@Override
public String commandName() {
return "teleporthere";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
execute((Player) source.getSource().getSender(), target);
return 1;
@@ -16,14 +16,17 @@ import java.util.List;
public class TeleportPositionCommand implements EssentiaCommand {
static String commandName = "teleportposition";
@Override
public String commandName() {
return "teleportposition";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.then(
@@ -39,13 +42,13 @@ public class TeleportPositionCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
BlockPosition position = source.getArgument("pos", BlockPositionResolver.class).resolve(sourceStack);
execute(player, target, position);
return 1;
@@ -0,0 +1,93 @@
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,21 +19,24 @@ import org.jetbrains.annotations.NotNull;
public class UnCuffCommand implements EssentiaCommand {
static String commandName = "uncuff";
@Override
public String commandName() {
return "uncuff";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
)
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
execute(source.getSource().getSender(), target);
return 1;
@@ -18,14 +18,17 @@ import org.jetbrains.annotations.NotNull;
public class WalkSpeedCommand implements EssentiaCommand {
static String commandName = "walkspeed";
@Override
public String commandName() {
return "walkspeed";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
).then(
Commands.argument("speed", FloatArgumentType.floatArg(-1, 1))
.executes((source) -> {
@@ -39,10 +42,10 @@ public class WalkSpeedCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
float speed = source.getArgument("speed", Float.class);
execute(source.getSource().getSender(), target, speed);
@@ -0,0 +1,103 @@
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,19 +13,21 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
public class WorkBenchCommand implements EssentiaCommand {
static String commandName = "workbench";
@Override
public String commandName() {
return "workbench";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
@@ -35,10 +37,10 @@ public class WorkBenchCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
execute(source.getSource().getSender(), target);
return 1;
@@ -0,0 +1,52 @@
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);
}
}
@@ -0,0 +1,54 @@
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,5 +1,7 @@
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;
@@ -12,19 +14,20 @@ 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 GameModeArgument implements CustomArgumentType.Converted<GameMode, String> {
public class MobDataArgumentType implements CustomArgumentType.Converted<MobData, String>, EssentiaArgument {
@Override
public @NotNull GameMode convert(String nativeType) throws CommandSyntaxException {
public @NotNull MobData convert(String nativeType) throws CommandSyntaxException {
try {
return GameMode.valueOf(nativeType.toUpperCase());
return MobData.valueOf(nativeType.toUpperCase());
} catch (Exception e) {
Message message = MessageComponentSerializer.message().serialize(Component.text("Invalid gamemode %s!".formatted(nativeType), NamedTextColor.RED));
Message message = MessageComponentSerializer.message().serialize(Component.text("Invalid mobdatatype %s!".formatted(nativeType), NamedTextColor.RED));
throw new CommandSyntaxException(new SimpleCommandExceptionType(message), message);
}
@@ -37,12 +40,12 @@ public class GameModeArgument implements CustomArgumentType.Converted<GameMode,
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
for (GameMode gameMode : GameMode.values()) {
builder.suggest(gameMode.name().toLowerCase());
Collection<String> possibleValues = new ArrayList<>();
for (MobData mobData : MobData.values()) {
possibleValues.add(mobData.name().toLowerCase());
}
return CompletableFuture.completedFuture(
builder.build()
);
return completedFuture(builder, possibleValues);
}
}
@@ -1,5 +1,7 @@
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;
@@ -17,9 +19,11 @@ 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> {
public class OfflinePlayerCompletingArgument implements CustomArgumentType.Converted<OfflinePlayer, String>, EssentiaArgument {
@Override
public @NotNull OfflinePlayer convert(String nativeType) throws CommandSyntaxException {
@@ -39,12 +43,11 @@ 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()) {
builder.suggest(player.getName(), MessageComponentSerializer.message().serialize(player.displayName()));
possibleValues.add(new Pair<>(player.getName(), MessageComponentSerializer.message().serialize(player.displayName())));
}
return CompletableFuture.completedFuture(
builder.build()
);
return completedFuturePair(builder, possibleValues);
}
}
@@ -1,5 +1,6 @@
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;
@@ -10,26 +11,23 @@ import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import io.papermc.paper.command.brigadier.MessageComponentSerializer;
import io.papermc.paper.command.brigadier.argument.CustomArgumentType;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.GameMode;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.WeatherType;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;
public class EnchantmentArgument implements CustomArgumentType.Converted<Enchantment, String> {
public class WeatherArgument implements CustomArgumentType.Converted<WeatherType, String>, EssentiaArgument {
@Override
public @NotNull Enchantment convert(String nativeType) throws CommandSyntaxException {
public @NotNull WeatherType convert(String nativeType) throws CommandSyntaxException {
try {
return Enchantment.getByKey(NamespacedKey.minecraft(nativeType));
return WeatherType.valueOf(nativeType.toUpperCase());
} catch (Exception e) {
Message message = MessageComponentSerializer.message().serialize(Component.text("Invalid gamemode %s!".formatted(nativeType), NamedTextColor.RED));
Message message = MessageComponentSerializer.message().serialize(Component.text("Invalid WeatherType %s!".formatted(nativeType), NamedTextColor.RED));
throw new CommandSyntaxException(new SimpleCommandExceptionType(message), message);
}
@@ -42,12 +40,11 @@ public class EnchantmentArgument implements CustomArgumentType.Converted<Enchant
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
for (Enchantment enchantment : RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT)) {
builder.suggest(enchantment.getKey().value());
Collection<String> possibleValues = new ArrayList<>();
for (WeatherType weatherType : WeatherType.values()) {
possibleValues.add(weatherType.name().toLowerCase());
}
return CompletableFuture.completedFuture(
builder.build()
);
return completedFuture(builder, possibleValues);
}
}
@@ -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.PlayerTeleportBackEvent;
import com.alttd.essentia.api.events.player.PlayerTeleportBackEvent;
import com.alttd.essentia.api.user.User;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
@@ -18,14 +18,17 @@ import org.jetbrains.annotations.NotNull;
public class BackCommand implements EssentiaCommand {
static String commandName = "back";
@Override
public String commandName() {
return "back";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
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.PlayerTeleportBackEvent;
import com.alttd.essentia.api.events.player.PlayerTeleportBackEvent;
import com.alttd.essentia.tasks.TeleportSounds;
import com.alttd.essentia.api.user.User;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
@@ -20,14 +20,17 @@ import java.util.List;
public class DeathBackCommand implements EssentiaCommand {
static String commandName = "deathback";
@Override
public String commandName() {
return "deathback";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
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.PlayerRemoveHomeEvent;
import com.alttd.essentia.api.events.player.PlayerRemoveHomeEvent;
import com.alttd.essentia.api.user.User;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
@@ -23,14 +23,17 @@ import java.util.Collection;
public class DelHomeCommand implements EssentiaCommand {
static String commandName = "delhome";
@Override
public String commandName() {
return "delhome";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
@@ -70,11 +73,11 @@ public class DelHomeCommand implements EssentiaCommand {
)
.then(
Commands.argument("player", new OfflinePlayerArgument())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
.then(
Commands.argument("home", StringArgumentType.word())
.suggests((context, suggestionsBuilder) -> {
if (!(context.getSource().getSender() instanceof Player player))
if (!(context.getSource().getSender() instanceof Player))
return Suggestions.empty();
OfflinePlayer target = context.getArgument("player", OfflinePlayer.class);
@@ -18,14 +18,17 @@ import org.jetbrains.annotations.NotNull;
public class DisposeCommand implements EssentiaCommand {
static String commandName = "dispose";
@Override
public String commandName() {
return "dispose";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName)
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission())
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
@@ -35,10 +38,10 @@ public class DisposeCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
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.PlayerTeleportHomeEvent;
import com.alttd.essentia.api.events.player.PlayerTeleportHomeEvent;
import com.alttd.essentia.api.model.Home;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
@@ -10,32 +10,33 @@ 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.List;
import java.util.ArrayList;
import java.util.Collection;
// TODO - home other
public class HomeCommand implements EssentiaCommand {
static String commandName = "home";
@Override
public String commandName() {
return "home";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
@@ -46,6 +47,24 @@ 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;
@@ -83,9 +102,8 @@ 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", homeName))
target.sendRichMessage(Config.HOME_TELEPORT, Placeholder.unparsed("home", home))
);
}
@@ -19,14 +19,17 @@ import java.util.List;
public class HomeListCommand implements EssentiaCommand {
static String commandName = "homelist";
@Override
public String commandName() {
return "homelist";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName)
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission())
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
@@ -36,10 +39,9 @@ public class HomeListCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", new OfflinePlayerCompletingArgument())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
OfflinePlayer target = source.getArgument("player", OfflinePlayer.class);;
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.PlayerSetHomeEvent;
import com.alttd.essentia.api.events.player.PlayerSetHomeEvent;
import com.alttd.essentia.api.user.User;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.commands.argumement.OfflinePlayerArgument;
@@ -20,14 +20,17 @@ import org.jetbrains.annotations.NotNull;
public class SetHomeCommand implements EssentiaCommand {
static String commandName = "sethome";
@Override
public String commandName() {
return "sethome";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
@@ -49,7 +52,7 @@ public class SetHomeCommand implements EssentiaCommand {
)
.then(
Commands.argument("player", new OfflinePlayerArgument())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
.then(
Commands.argument("name", StringArgumentType.word())
.executes((source) -> {
@@ -1,8 +1,7 @@
package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.api.events.PlayerTeleportBackEvent;
import com.alttd.essentia.api.events.PlayerTeleportSpawnEvent;
import com.alttd.essentia.api.events.player.PlayerTeleportSpawnEvent;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
import com.alttd.essentia.api.events.EssentiaEvent;
@@ -22,14 +21,17 @@ import org.jetbrains.annotations.NotNull;
public class SpawnCommand implements EssentiaCommand {
static String commandName = "spawn";
@Override
public String commandName() {
return "spawn";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName)
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission())
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
@@ -39,11 +41,11 @@ public class SpawnCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
execute((Player) source.getSource().getSender(), target);
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
execute(source.getSource().getSender(), target);
return 1;
})
@@ -16,14 +16,17 @@ import java.util.List;
public class TeleportAcceptCommand implements EssentiaCommand {
static String commandName = "teleportaccept";
@Override
public String commandName() {
return "teleportaccept";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
@@ -16,14 +16,17 @@ import java.util.List;
public class TeleportDenyCommand implements EssentiaCommand {
static String commandName = "teleportdeny";
@Override
public String commandName() {
return "teleportdeny";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
@@ -20,25 +20,28 @@ import java.util.List;
public class TeleportRequestCommand implements EssentiaCommand {
static String commandName = "teleportrequesthere";
@Override
public String commandName() {
return "teleportrequesthere";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
execute(player, target);
return 1;
@@ -20,25 +20,28 @@ import java.util.List;
public class TeleportRequestHereCommand implements EssentiaCommand {
static String commandName = "teleportrequesthere";
@Override
public String commandName() {
return "teleportrequesthere";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
execute(player, target);
return 1;
@@ -21,14 +21,17 @@ import java.util.List;
public class TeleportToggleCommand implements EssentiaCommand {
static String commandName = "teleporttoggle";
@Override
public String commandName() {
return "teleporttoggle";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName)
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission())
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
@@ -38,10 +41,10 @@ public class TeleportToggleCommand implements EssentiaCommand {
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).get(0);
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
execute(source.getSource().getSender(), target);
return 1;
@@ -2,7 +2,8 @@ package com.alttd.essentia.configuration;
import com.alttd.essentia.EssentiaPlugin;
import com.google.common.base.Throwables;
import org.bukkit.Bukkit;
import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
import org.bukkit.Sound;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -35,7 +36,7 @@ public class Config {
config.load(CONFIG_FILE);
} catch (IOException ignore) {
} catch (InvalidConfigurationException ex) {
EssentiaPlugin.instance().getLogger().log(Level.SEVERE, "Could not load config.yml, please correct your syntax errors", ex);
log(Level.SEVERE, "Could not load config.yml, please correct your syntax errors", ex);
Throwables.throwIfUnchecked(ex);
}
config.options().header(HEADER);
@@ -44,7 +45,7 @@ public class Config {
version = getInt("config-version", 1);
set("config-version", 1);
EssentiaPlugin.instance().getLogger().info("Essentia Configuration loaded!");
log(Level.INFO,"Essentia Configuration loaded!");
readConfig(Config.class, null);
}
@@ -58,7 +59,7 @@ public class Config {
} catch (InvocationTargetException ex) {
Throwables.throwIfUnchecked(ex);
} catch (Exception ex) {
EssentiaPlugin.instance().getLogger().log(Level.SEVERE, "Error invoking " + method, ex);
log(Level.SEVERE, "Error invoking " + method, ex);
}
}
}
@@ -66,11 +67,11 @@ public class Config {
saveConfig();
}
static void saveConfig() {
public static void saveConfig() {
try {
config.save(CONFIG_FILE);
} catch (IOException ex) {
EssentiaPlugin.instance().getLogger().log(Level.SEVERE, "Could not save " + CONFIG_FILE, ex);
log(Level.SEVERE, "Could not save " + CONFIG_FILE, ex);
}
}
@@ -108,6 +109,10 @@ 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;
@@ -271,4 +276,10 @@ 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);
}
}
@@ -0,0 +1,19 @@
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();
}
}
@@ -0,0 +1,57 @@
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);
}
}
@@ -0,0 +1,30 @@
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,9 +1,9 @@
package com.alttd.essentia.listeners;
package com.alttd.essentia.feature.cuff;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.api.user.User;
import com.alttd.essentia.api.user.UserManager;
import com.alttd.essentia.configuration.Config;
import io.papermc.paper.event.player.AsyncChatEvent;
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 isCuffed(Player player) {
private boolean isNotCuffed(Player player) {
UserManager userManager = plugin.userManager();
User user = userManager.getUser(player);
if (user == null)
return false;
return true;
return user.isCuffed();
return !user.isCuffed();
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (!isCuffed(event.getPlayer()))
if (isNotCuffed(event.getPlayer()))
return;
cancelEvent(event, event.getPlayer());
}
@EventHandler
public void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
if (!isCuffed(event.getPlayer()))
public void onAsyncPlayerChat(AsyncChatEvent event) {
if (isNotCuffed(event.getPlayer()))
return;
// TODO
@@ -57,7 +57,7 @@ public class CuffListener implements Listener {
if (!(event.getWhoClicked() instanceof Player player))
return;
if (!isCuffed(player))
if (isNotCuffed(player))
return;
cancelEvent(event, player);
@@ -65,7 +65,7 @@ public class CuffListener implements Listener {
@EventHandler
public void onPlayerDropItemEvent(PlayerDropItemEvent event) {
if (!isCuffed(event.getPlayer()))
if (isNotCuffed(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 (!isCuffed(player))
if (isNotCuffed(player))
return;
cancelEvent(event, player);
@@ -87,7 +87,7 @@ public class CuffListener implements Listener {
if (!(event.getDamager() instanceof Player player))
return;
if (!isCuffed(player))
if (isNotCuffed(player))
return;
cancelEvent(event, player);
@@ -98,7 +98,7 @@ public class CuffListener implements Listener {
if (!(event.getEntity() instanceof Player player))
return;
if (!isCuffed(player))
if (isNotCuffed(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 (!isCuffed(player))
if (isNotCuffed(player))
return;
Location from = event.getFrom();
@@ -120,7 +120,6 @@ public class CuffListener implements Listener {
if (from.getWorld() != to.getWorld() || from.getBlockX() != to.getBlockX() || from.getBlockZ() != to.getBlockZ()) {
cancelEvent(event, player);
return;
}
}
@@ -0,0 +1,31 @@
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,4 +1,4 @@
package com.alttd.essentia.listeners;
package com.alttd.essentia.feature.flight;
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,45 @@
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();
}
}
@@ -0,0 +1,114 @@
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);
}
}
@@ -0,0 +1,29 @@
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;
}
}
@@ -0,0 +1,28 @@
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;
}
}
@@ -0,0 +1,14 @@
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;
}
}
@@ -0,0 +1,13 @@
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);
}
}
@@ -0,0 +1,4 @@
package com.alttd.essentia.feature.savedinventory;
public class SavedInventoryFeature {
}
@@ -0,0 +1,27 @@
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
}
}
@@ -0,0 +1,8 @@
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,67 +0,0 @@
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;
@@ -1,4 +0,0 @@
package com.alttd.essentia.model;
public record PlayerInventory() {
}
@@ -0,0 +1,8 @@
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) { }
@@ -0,0 +1,12 @@
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 {
private final EssentiaPlugin plugin;
protected final EssentiaPlugin plugin;
@Getter private final Player requester;
@Getter private final Player target;
private final RequestTimeout timeoutTask;
@Getter private final RequestTimeout timeoutTask;
TagResolver placeholders;
@@ -0,0 +1,168 @@
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,8 +1,6 @@
package com.alttd.essentia.storage;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.storage.mysql.SQLStorageProvider;
import com.alttd.essentia.storage.sqlite.SQLiteStorageProvider;
import com.alttd.essentia.storage.yaml.YamlStorageProvider;
import java.io.File;
@@ -45,9 +45,9 @@ public class DatabaseQuery {
void edit(PreparedStatement preparedStatement) throws SQLException;
default void onSuccess(ResultSet resultSet) throws SQLException {};
default void onSuccess(ResultSet resultSet) throws SQLException {}
default void onSuccess() throws SQLException {};
default void onSuccess() throws SQLException {}
default void onFailure(SQLException e) {
e.printStackTrace();
@@ -0,0 +1,5 @@
package com.alttd.essentia.util;
public record Pair<X, Y>(X x, Y y) {
}
@@ -0,0 +1,17 @@
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,6 +2,7 @@ name: Essentia
version: ${version}
main: com.alttd.essentia.EssentiaPlugin
description: Altitude essentials ;)
load: POSTWORLD
authors:
- destro174
api-version: "1.21"