Compare commits
29
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1f88f6ea0d | ||
|
|
798946b386 | ||
|
|
c32bd21f0f | ||
|
|
99dcb318ad | ||
|
|
fa289a8737 | ||
|
|
b68835918f | ||
|
|
d3cd059af1 | ||
|
|
612a0281d6 | ||
|
|
d4f33b8c2e | ||
|
|
9fa43c8c65 | ||
|
|
13a78515c5 | ||
|
|
91e6d3be8e | ||
|
|
06a8aa0f65 | ||
|
|
139c51e9b8 | ||
|
|
ed0d15b3d4 | ||
|
|
76ae3103de | ||
|
|
434cf6ac15 | ||
|
|
d786ebcff5 | ||
|
|
2ef960b189 | ||
|
|
4dba5f3c41 | ||
|
|
dbb3f45898 | ||
|
|
162ffd3599 | ||
|
|
430e6fb898 | ||
|
|
aede22811a | ||
|
|
a8221a68af | ||
|
|
29559b83c4 | ||
|
|
be8b7e20df | ||
|
|
6a8e21852c | ||
|
|
ff2824f287 |
@@ -1,5 +1,6 @@
|
|||||||
package com.alttd.essentia;
|
package com.alttd.essentia;
|
||||||
|
|
||||||
|
import com.alttd.essentia.api.model.randomteleport.LocationValidator;
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
|
||||||
public interface EssentiaAPI {
|
public interface EssentiaAPI {
|
||||||
@@ -19,4 +20,6 @@ public interface EssentiaAPI {
|
|||||||
Provider.instance = instance;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+2
-1
@@ -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.entity.Player;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
+2
-1
@@ -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.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
+2
-1
@@ -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.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
+2
-1
@@ -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.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
+2
-1
@@ -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.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.HandlerList;
|
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
@@ -47,7 +47,7 @@ dependencies {
|
|||||||
tasks {
|
tasks {
|
||||||
shadowJar {
|
shadowJar {
|
||||||
archiveFileName.set("${project.name}.jar")
|
archiveFileName.set("${project.name}.jar")
|
||||||
minimize() {
|
minimize {
|
||||||
exclude {
|
exclude {
|
||||||
it.moduleName == "api"
|
it.moduleName == "api"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ plugins {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(":api"))
|
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")
|
api("org.reflections:reflections:0.10.2")
|
||||||
|
|
||||||
compileOnly("org.projectlombok:lombok:1.18.34")
|
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.commands.EssentiaCommand;
|
||||||
import com.alttd.essentia.configuration.Config;
|
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.StorageManager;
|
||||||
import com.alttd.essentia.storage.StorageProvider;
|
import com.alttd.essentia.storage.StorageProvider;
|
||||||
import com.alttd.essentia.storage.StorageType;
|
import com.alttd.essentia.storage.StorageType;
|
||||||
import com.alttd.essentia.user.EssentiaUserManager;
|
import com.alttd.essentia.user.EssentiaUserManager;
|
||||||
import com.alttd.essentia.api.user.UserManager;
|
import com.alttd.essentia.api.user.UserManager;
|
||||||
|
import com.alttd.essentia.util.Timer;
|
||||||
import io.papermc.paper.command.brigadier.Commands;
|
import io.papermc.paper.command.brigadier.Commands;
|
||||||
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
|
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
|
||||||
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
|
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.Reflections;
|
||||||
import org.reflections.scanners.Scanners;
|
import org.reflections.scanners.Scanners;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
||||||
@@ -27,10 +33,15 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
|||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private UserManager userManager;
|
private UserManager userManager;
|
||||||
|
@Getter
|
||||||
|
private List<LocationValidator> locationValidators;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private StorageProvider storageProvider;
|
private StorageProvider storageProvider;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private Features features;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
instance = this;
|
instance = this;
|
||||||
@@ -39,11 +50,15 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
loadConfiguration();
|
new Timer("onEnable", () -> {
|
||||||
loadCommands();
|
new Timer("loadConfiguration", this::loadConfiguration);
|
||||||
loadEventListeners();
|
new Timer("loadFeatures", this::loadFeatures);
|
||||||
loadManagers();
|
new Timer("loadCommands", this::loadCommands);
|
||||||
loadStorageProvider();
|
new Timer("loadEventListeners", this::loadEventListeners);
|
||||||
|
new Timer("loadManagers", this::loadManagers);
|
||||||
|
new Timer("loadStorageProvider", this::loadStorageProvider);
|
||||||
|
new Timer("loadLocationValidators", this::loadLocationValidators);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -57,6 +72,11 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
|||||||
Config.init();
|
Config.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void loadFeatures() {
|
||||||
|
features = new Features(this);
|
||||||
|
features.registerAll();
|
||||||
|
}
|
||||||
|
|
||||||
void loadCommands() {
|
void loadCommands() {
|
||||||
Reflections reflections = new Reflections("com.alttd.essentia.commands");
|
Reflections reflections = new Reflections("com.alttd.essentia.commands");
|
||||||
Set<Class<?>> subTypes = reflections.get(Scanners.SubTypes.of(EssentiaCommand.class).asClass());
|
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 -> {
|
subTypes.forEach(clazz -> {
|
||||||
try {
|
try {
|
||||||
EssentiaCommand essentiaCommand = (EssentiaCommand) clazz.getDeclaredConstructor().newInstance();
|
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());
|
commands.register(essentiaCommand.command(), essentiaCommand.description(), essentiaCommand.aliases());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
EssentiaPlugin.instance().getLogger().severe("Failed to register command " + clazz.getSimpleName());
|
EssentiaPlugin.instance().getLogger().severe("Failed to register command " + clazz.getSimpleName());
|
||||||
@@ -77,12 +104,21 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
|||||||
|
|
||||||
void loadEventListeners() {
|
void loadEventListeners() {
|
||||||
final PluginManager pluginManager = getServer().getPluginManager();
|
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());
|
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 -> {
|
subTypes.forEach(clazz -> {
|
||||||
try {
|
try {
|
||||||
Listener listener = (Listener) clazz.getDeclaredConstructor().newInstance();
|
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);
|
pluginManager.registerEvents(listener, this);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
EssentiaPlugin.instance().getLogger().severe("Failed to register event listener " + clazz.getSimpleName());
|
EssentiaPlugin.instance().getLogger().severe("Failed to register event listener " + clazz.getSimpleName());
|
||||||
@@ -100,4 +136,26 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
|||||||
storageProvider.startAutoSaving();
|
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?
|
// TODO -- add optional -s -silent parameters to commands?
|
||||||
public interface EssentiaCommand {
|
public interface EssentiaCommand {
|
||||||
|
|
||||||
|
String commandName();
|
||||||
|
|
||||||
@NotNull LiteralCommandNode<CommandSourceStack> command();
|
@NotNull LiteralCommandNode<CommandSourceStack> command();
|
||||||
|
|
||||||
default String description() {
|
default String description() {
|
||||||
@@ -19,4 +21,20 @@ public interface EssentiaCommand {
|
|||||||
return Collections.emptyList();
|
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 {
|
public class BurnCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "burn";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "burn";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
|
||||||
)
|
)
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
if (source.getSource().getSender() instanceof Player player)
|
if (source.getSource().getSender() instanceof Player player)
|
||||||
@@ -33,10 +36,10 @@ public class BurnCommand implements EssentiaCommand {
|
|||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("player", ArgumentTypes.player())
|
Commands.argument("player", ArgumentTypes.player())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
CommandSourceStack sourceStack = source.getSource();
|
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);
|
execute(source.getSource().getSender(), target);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -16,14 +16,17 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class ClearInventoryCommand implements EssentiaCommand {
|
public class ClearInventoryCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "clearinventory";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "clearinventory";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
|
||||||
commandSourceStack.getSender() instanceof Player
|
commandSourceStack.getSender() instanceof Player
|
||||||
)
|
)
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
@@ -34,10 +37,10 @@ public class ClearInventoryCommand implements EssentiaCommand {
|
|||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("player", ArgumentTypes.player())
|
Commands.argument("player", ArgumentTypes.player())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
CommandSourceStack sourceStack = source.getSource();
|
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);
|
execute(source.getSource().getSender(), target);
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -19,21 +19,24 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class CuffCommand implements EssentiaCommand {
|
public class CuffCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "cuff";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "cuff";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
|
||||||
)
|
)
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("player", ArgumentTypes.player())
|
Commands.argument("player", ArgumentTypes.player())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
CommandSourceStack sourceStack = source.getSource();
|
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);
|
execute(source.getSource().getSender(), target);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.alttd.essentia.commands.admin;
|
package com.alttd.essentia.commands.admin;
|
||||||
|
|
||||||
import com.alttd.essentia.commands.EssentiaCommand;
|
import com.alttd.essentia.commands.EssentiaCommand;
|
||||||
import com.alttd.essentia.commands.argumement.EnchantmentArgument;
|
|
||||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
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.Commands;
|
||||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
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.PlayerSelectorArgumentResolver;
|
||||||
|
import io.papermc.paper.registry.RegistryKey;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -20,17 +20,20 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class EnchantCommand implements EssentiaCommand {
|
public class EnchantCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "enchant";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "enchant";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
|
||||||
)
|
)
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("enchantment", new EnchantmentArgument())
|
Commands.argument("enchantment", ArgumentTypes.resource(RegistryKey.ENCHANTMENT))
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
if (!(source.getSource().getSender() instanceof Player player))
|
if (!(source.getSource().getSender() instanceof Player player))
|
||||||
return 1;
|
return 1;
|
||||||
@@ -51,10 +54,10 @@ public class EnchantCommand implements EssentiaCommand {
|
|||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("player", ArgumentTypes.player())
|
Commands.argument("player", ArgumentTypes.player())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
CommandSourceStack sourceStack = source.getSource();
|
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);
|
Enchantment enchantment = source.getArgument("enchantment", Enchantment.class);
|
||||||
int level = source.getArgument("level", Integer.class);
|
int level = source.getArgument("level", Integer.class);
|
||||||
execute(source.getSource().getSender(), target, enchantment, level);
|
execute(source.getSource().getSender(), target, enchantment, level);
|
||||||
|
|||||||
@@ -10,11 +10,16 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class EssentiaAdminCommand implements EssentiaCommand {
|
public class EssentiaAdminCommand implements EssentiaCommand {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "essentiareload";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal("essentia")
|
Commands.literal(commandName())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin.reload"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()))
|
||||||
.executes((commandContext -> 1))
|
.executes((commandContext -> 1))
|
||||||
.then(
|
.then(
|
||||||
Commands.literal("reload")
|
Commands.literal("reload")
|
||||||
|
|||||||
@@ -16,14 +16,17 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class FeedCommand implements EssentiaCommand {
|
public class FeedCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "feed";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "feed";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
|
||||||
commandSourceStack.getSender() instanceof Player
|
commandSourceStack.getSender() instanceof Player
|
||||||
)
|
)
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
@@ -34,10 +37,10 @@ public class FeedCommand implements EssentiaCommand {
|
|||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("player", ArgumentTypes.player())
|
Commands.argument("player", ArgumentTypes.player())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
CommandSourceStack sourceStack = source.getSource();
|
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);
|
execute(source.getSource().getSender(), target);
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -20,14 +20,17 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class FlyCommand implements EssentiaCommand {
|
public class FlyCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "fly";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "fly";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
|
||||||
commandSourceStack.getSender() instanceof Player
|
commandSourceStack.getSender() instanceof Player
|
||||||
)
|
)
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
@@ -38,10 +41,10 @@ public class FlyCommand implements EssentiaCommand {
|
|||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("player", ArgumentTypes.player())
|
Commands.argument("player", ArgumentTypes.player())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
CommandSourceStack sourceStack = source.getSource();
|
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);
|
execute(source.getSource().getSender(), target);
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -18,14 +18,17 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class FlySpeedCommand implements EssentiaCommand {
|
public class FlySpeedCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "flyspeed";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "flyspeed";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
|
||||||
).then(
|
).then(
|
||||||
Commands.argument("speed", FloatArgumentType.floatArg(-1, 1))
|
Commands.argument("speed", FloatArgumentType.floatArg(-1, 1))
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
@@ -39,10 +42,10 @@ public class FlySpeedCommand implements EssentiaCommand {
|
|||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("player", ArgumentTypes.player())
|
Commands.argument("player", ArgumentTypes.player())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
CommandSourceStack sourceStack = source.getSource();
|
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);
|
float speed = source.getArgument("speed", Float.class);
|
||||||
execute(source.getSource().getSender(), target, speed);
|
execute(source.getSource().getSender(), target, speed);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.alttd.essentia.commands.admin;
|
package com.alttd.essentia.commands.admin;
|
||||||
|
|
||||||
import com.alttd.essentia.commands.EssentiaCommand;
|
import com.alttd.essentia.commands.EssentiaCommand;
|
||||||
import com.alttd.essentia.commands.argumement.GameModeArgument;
|
|
||||||
import com.alttd.essentia.configuration.Config;
|
import com.alttd.essentia.configuration.Config;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
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.Commands;
|
||||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
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.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.Placeholder;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
@@ -19,17 +17,20 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class GameModeCommand implements EssentiaCommand {
|
public class GameModeCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "gamemode";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "gamemode";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
|
||||||
)
|
)
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("gamemode", new GameModeArgument())
|
Commands.argument("gamemode", ArgumentTypes.gameMode())
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
if (!(source.getSource().getSender() instanceof Player player))
|
if (!(source.getSource().getSender() instanceof Player player))
|
||||||
return 1;
|
return 1;
|
||||||
@@ -40,10 +41,10 @@ public class GameModeCommand implements EssentiaCommand {
|
|||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("player", ArgumentTypes.player())
|
Commands.argument("player", ArgumentTypes.player())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
CommandSourceStack sourceStack = source.getSource();
|
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);
|
GameMode gameMode = source.getArgument("gamemode", GameMode.class);
|
||||||
execute(source.getSource().getSender(), target, gameMode);
|
execute(source.getSource().getSender(), target, gameMode);
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -20,14 +20,17 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class GodCommand implements EssentiaCommand {
|
public class GodCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "god";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "god";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
|
||||||
commandSourceStack.getSender() instanceof Player
|
commandSourceStack.getSender() instanceof Player
|
||||||
)
|
)
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
@@ -38,10 +41,10 @@ public class GodCommand implements EssentiaCommand {
|
|||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("player", ArgumentTypes.player())
|
Commands.argument("player", ArgumentTypes.player())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
CommandSourceStack sourceStack = source.getSource();
|
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);
|
execute(source.getSource().getSender(), target);
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -14,17 +14,19 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class HealCommand
|
public class HealCommand implements EssentiaCommand {
|
||||||
implements EssentiaCommand {
|
|
||||||
|
|
||||||
static String commandName = "heal";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "heal";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
|
||||||
commandSourceStack.getSender() instanceof Player
|
commandSourceStack.getSender() instanceof Player
|
||||||
)
|
)
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
@@ -35,10 +37,10 @@ public class HealCommand
|
|||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("player", ArgumentTypes.player())
|
Commands.argument("player", ArgumentTypes.player())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
CommandSourceStack sourceStack = source.getSource();
|
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);
|
execute(source.getSource().getSender(), target);
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -15,14 +15,17 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class InfoCommand implements EssentiaCommand {
|
public class InfoCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "info";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "info";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
|
||||||
)
|
)
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
if (source.getSource().getSender() instanceof Player player)
|
if (source.getSource().getSender() instanceof Player player)
|
||||||
@@ -32,10 +35,10 @@ public class InfoCommand implements EssentiaCommand {
|
|||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("player", ArgumentTypes.player())
|
Commands.argument("player", ArgumentTypes.player())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
CommandSourceStack sourceStack = source.getSource();
|
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);
|
execute(source.getSource().getSender(), target);
|
||||||
|
|
||||||
return 1;
|
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 {
|
public class SmiteCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "smite";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "smite";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
|
||||||
)
|
)
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
if (source.getSource().getSender() instanceof Player player)
|
if (source.getSource().getSender() instanceof Player player)
|
||||||
@@ -35,10 +38,10 @@ public class SmiteCommand implements EssentiaCommand {
|
|||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("player", ArgumentTypes.player())
|
Commands.argument("player", ArgumentTypes.player())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
CommandSourceStack sourceStack = source.getSource();
|
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);
|
execute(source.getSource().getSender(), target);
|
||||||
|
|
||||||
return 1;
|
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.Commands;
|
||||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
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.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.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -17,22 +14,25 @@ import java.util.List;
|
|||||||
|
|
||||||
public class TeleportCommand implements EssentiaCommand {
|
public class TeleportCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "teleport";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "teleport";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
|
||||||
commandSourceStack.getSender() instanceof Player
|
commandSourceStack.getSender() instanceof Player
|
||||||
)
|
)
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("player", ArgumentTypes.player())
|
Commands.argument("player", ArgumentTypes.player())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
CommandSourceStack sourceStack = source.getSource();
|
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);
|
execute((Player) source.getSource().getSender(), target);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -14,22 +14,25 @@ import java.util.List;
|
|||||||
|
|
||||||
public class TeleportHereCommand implements EssentiaCommand {
|
public class TeleportHereCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "teleporthere";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "teleporthere";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
|
||||||
commandSourceStack.getSender() instanceof Player
|
commandSourceStack.getSender() instanceof Player
|
||||||
)
|
)
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("player", ArgumentTypes.player())
|
Commands.argument("player", ArgumentTypes.player())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
CommandSourceStack sourceStack = source.getSource();
|
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);
|
execute((Player) source.getSource().getSender(), target);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -16,14 +16,17 @@ import java.util.List;
|
|||||||
|
|
||||||
public class TeleportPositionCommand implements EssentiaCommand {
|
public class TeleportPositionCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "teleportposition";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "teleportposition";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()) &&
|
||||||
commandSourceStack.getSender() instanceof Player
|
commandSourceStack.getSender() instanceof Player
|
||||||
)
|
)
|
||||||
.then(
|
.then(
|
||||||
@@ -39,13 +42,13 @@ public class TeleportPositionCommand implements EssentiaCommand {
|
|||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("player", ArgumentTypes.player())
|
Commands.argument("player", ArgumentTypes.player())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
if (!(source.getSource().getSender() instanceof Player player))
|
if (!(source.getSource().getSender() instanceof Player player))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
CommandSourceStack sourceStack = source.getSource();
|
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);
|
BlockPosition position = source.getArgument("pos", BlockPositionResolver.class).resolve(sourceStack);
|
||||||
execute(player, target, position);
|
execute(player, target, position);
|
||||||
return 1;
|
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 {
|
public class UnCuffCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "uncuff";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "uncuff";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
|
||||||
)
|
)
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("player", ArgumentTypes.player())
|
Commands.argument("player", ArgumentTypes.player())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
CommandSourceStack sourceStack = source.getSource();
|
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);
|
execute(source.getSource().getSender(), target);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -18,14 +18,17 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class WalkSpeedCommand implements EssentiaCommand {
|
public class WalkSpeedCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "walkspeed";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "walkspeed";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
|
||||||
).then(
|
).then(
|
||||||
Commands.argument("speed", FloatArgumentType.floatArg(-1, 1))
|
Commands.argument("speed", FloatArgumentType.floatArg(-1, 1))
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
@@ -39,10 +42,10 @@ public class WalkSpeedCommand implements EssentiaCommand {
|
|||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("player", ArgumentTypes.player())
|
Commands.argument("player", ArgumentTypes.player())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
CommandSourceStack sourceStack = source.getSource();
|
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);
|
float speed = source.getArgument("speed", Float.class);
|
||||||
execute(source.getSource().getSender(), target, speed);
|
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.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class WorkBenchCommand implements EssentiaCommand {
|
public class WorkBenchCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "workbench";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "workbench";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName)
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
|
||||||
)
|
)
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
if (source.getSource().getSender() instanceof Player player)
|
if (source.getSource().getSender() instanceof Player player)
|
||||||
@@ -35,10 +37,10 @@ public class WorkBenchCommand implements EssentiaCommand {
|
|||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("player", ArgumentTypes.player())
|
Commands.argument("player", ArgumentTypes.player())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName + ".other"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
CommandSourceStack sourceStack = source.getSource();
|
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);
|
execute(source.getSource().getSender(), target);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
+52
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+54
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+13
-10
@@ -1,5 +1,7 @@
|
|||||||
package com.alttd.essentia.commands.argumement;
|
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.Message;
|
||||||
import com.mojang.brigadier.arguments.ArgumentType;
|
import com.mojang.brigadier.arguments.ArgumentType;
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
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 io.papermc.paper.command.brigadier.argument.CustomArgumentType;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.bukkit.GameMode;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class GameModeArgument implements CustomArgumentType.Converted<GameMode, String> {
|
public class MobDataArgumentType implements CustomArgumentType.Converted<MobData, String>, EssentiaArgument {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull GameMode convert(String nativeType) throws CommandSyntaxException {
|
public @NotNull MobData convert(String nativeType) throws CommandSyntaxException {
|
||||||
try {
|
try {
|
||||||
return GameMode.valueOf(nativeType.toUpperCase());
|
return MobData.valueOf(nativeType.toUpperCase());
|
||||||
} catch (Exception e) {
|
} 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);
|
throw new CommandSyntaxException(new SimpleCommandExceptionType(message), message);
|
||||||
}
|
}
|
||||||
@@ -37,12 +40,12 @@ public class GameModeArgument implements CustomArgumentType.Converted<GameMode,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
||||||
for (GameMode gameMode : GameMode.values()) {
|
Collection<String> possibleValues = new ArrayList<>();
|
||||||
builder.suggest(gameMode.name().toLowerCase());
|
for (MobData mobData : MobData.values()) {
|
||||||
|
possibleValues.add(mobData.name().toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
return CompletableFuture.completedFuture(
|
return completedFuture(builder, possibleValues);
|
||||||
builder.build()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+8
-5
@@ -1,5 +1,7 @@
|
|||||||
package com.alttd.essentia.commands.argumement;
|
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.Message;
|
||||||
import com.mojang.brigadier.arguments.ArgumentType;
|
import com.mojang.brigadier.arguments.ArgumentType;
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
@@ -17,9 +19,11 @@ import org.bukkit.OfflinePlayer;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class OfflinePlayerCompletingArgument implements CustomArgumentType.Converted<OfflinePlayer, String> {
|
public class OfflinePlayerCompletingArgument implements CustomArgumentType.Converted<OfflinePlayer, String>, EssentiaArgument {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull OfflinePlayer convert(String nativeType) throws CommandSyntaxException {
|
public @NotNull OfflinePlayer convert(String nativeType) throws CommandSyntaxException {
|
||||||
@@ -39,12 +43,11 @@ public class OfflinePlayerCompletingArgument implements CustomArgumentType.Conve
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
||||||
|
Collection<Pair<String, Message>> possibleValues = new ArrayList<>();
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
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(
|
return completedFuturePair(builder, possibleValues);
|
||||||
builder.build()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+12
-15
@@ -1,5 +1,6 @@
|
|||||||
package com.alttd.essentia.commands.argumement;
|
package com.alttd.essentia.commands.argumement;
|
||||||
|
|
||||||
|
import com.alttd.essentia.commands.EssentiaArgument;
|
||||||
import com.mojang.brigadier.Message;
|
import com.mojang.brigadier.Message;
|
||||||
import com.mojang.brigadier.arguments.ArgumentType;
|
import com.mojang.brigadier.arguments.ArgumentType;
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
@@ -10,26 +11,23 @@ import com.mojang.brigadier.suggestion.Suggestions;
|
|||||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||||
import io.papermc.paper.command.brigadier.MessageComponentSerializer;
|
import io.papermc.paper.command.brigadier.MessageComponentSerializer;
|
||||||
import io.papermc.paper.command.brigadier.argument.CustomArgumentType;
|
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.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.WeatherType;
|
||||||
import org.bukkit.NamespacedKey;
|
|
||||||
import org.bukkit.Registry;
|
|
||||||
import org.bukkit.enchantments.Enchantment;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class EnchantmentArgument implements CustomArgumentType.Converted<Enchantment, String> {
|
public class WeatherArgument implements CustomArgumentType.Converted<WeatherType, String>, EssentiaArgument {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Enchantment convert(String nativeType) throws CommandSyntaxException {
|
public @NotNull WeatherType convert(String nativeType) throws CommandSyntaxException {
|
||||||
try {
|
try {
|
||||||
return Enchantment.getByKey(NamespacedKey.minecraft(nativeType));
|
return WeatherType.valueOf(nativeType.toUpperCase());
|
||||||
} catch (Exception e) {
|
} 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);
|
throw new CommandSyntaxException(new SimpleCommandExceptionType(message), message);
|
||||||
}
|
}
|
||||||
@@ -42,12 +40,11 @@ public class EnchantmentArgument implements CustomArgumentType.Converted<Enchant
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
||||||
for (Enchantment enchantment : RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT)) {
|
Collection<String> possibleValues = new ArrayList<>();
|
||||||
builder.suggest(enchantment.getKey().value());
|
for (WeatherType weatherType : WeatherType.values()) {
|
||||||
|
possibleValues.add(weatherType.name().toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
return CompletableFuture.completedFuture(
|
return completedFuture(builder, possibleValues);
|
||||||
builder.build()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@ package com.alttd.essentia.commands.player;
|
|||||||
|
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.alttd.essentia.api.events.EssentiaEvent;
|
import com.alttd.essentia.api.events.EssentiaEvent;
|
||||||
import com.alttd.essentia.api.events.PlayerTeleportBackEvent;
|
import com.alttd.essentia.api.events.player.PlayerTeleportBackEvent;
|
||||||
import com.alttd.essentia.api.user.User;
|
import com.alttd.essentia.api.user.User;
|
||||||
import com.alttd.essentia.commands.EssentiaCommand;
|
import com.alttd.essentia.commands.EssentiaCommand;
|
||||||
import com.alttd.essentia.configuration.Config;
|
import com.alttd.essentia.configuration.Config;
|
||||||
@@ -18,14 +18,17 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class BackCommand implements EssentiaCommand {
|
public class BackCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "back";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "back";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
|
||||||
commandSourceStack.getSender() instanceof Player
|
commandSourceStack.getSender() instanceof Player
|
||||||
)
|
)
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import com.alttd.essentia.EssentiaPlugin;
|
|||||||
import com.alttd.essentia.commands.EssentiaCommand;
|
import com.alttd.essentia.commands.EssentiaCommand;
|
||||||
import com.alttd.essentia.configuration.Config;
|
import com.alttd.essentia.configuration.Config;
|
||||||
import com.alttd.essentia.api.events.EssentiaEvent;
|
import com.alttd.essentia.api.events.EssentiaEvent;
|
||||||
import com.alttd.essentia.api.events.PlayerTeleportBackEvent;
|
import com.alttd.essentia.api.events.player.PlayerTeleportBackEvent;
|
||||||
import com.alttd.essentia.tasks.TeleportSounds;
|
import com.alttd.essentia.tasks.TeleportSounds;
|
||||||
import com.alttd.essentia.api.user.User;
|
import com.alttd.essentia.api.user.User;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
@@ -20,14 +20,17 @@ import java.util.List;
|
|||||||
|
|
||||||
public class DeathBackCommand implements EssentiaCommand {
|
public class DeathBackCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "deathback";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "deathback";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
|
||||||
commandSourceStack.getSender() instanceof Player
|
commandSourceStack.getSender() instanceof Player
|
||||||
)
|
)
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import com.alttd.essentia.commands.EssentiaCommand;
|
|||||||
import com.alttd.essentia.commands.argumement.OfflinePlayerArgument;
|
import com.alttd.essentia.commands.argumement.OfflinePlayerArgument;
|
||||||
import com.alttd.essentia.configuration.Config;
|
import com.alttd.essentia.configuration.Config;
|
||||||
import com.alttd.essentia.api.events.EssentiaEvent;
|
import com.alttd.essentia.api.events.EssentiaEvent;
|
||||||
import com.alttd.essentia.api.events.PlayerRemoveHomeEvent;
|
import com.alttd.essentia.api.events.player.PlayerRemoveHomeEvent;
|
||||||
import com.alttd.essentia.api.user.User;
|
import com.alttd.essentia.api.user.User;
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
@@ -23,14 +23,17 @@ import java.util.Collection;
|
|||||||
|
|
||||||
public class DelHomeCommand implements EssentiaCommand {
|
public class DelHomeCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "delhome";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "delhome";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
|
||||||
commandSourceStack.getSender() instanceof Player
|
commandSourceStack.getSender() instanceof Player
|
||||||
)
|
)
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
@@ -70,11 +73,11 @@ public class DelHomeCommand implements EssentiaCommand {
|
|||||||
)
|
)
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("player", new OfflinePlayerArgument())
|
Commands.argument("player", new OfflinePlayerArgument())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("home", StringArgumentType.word())
|
Commands.argument("home", StringArgumentType.word())
|
||||||
.suggests((context, suggestionsBuilder) -> {
|
.suggests((context, suggestionsBuilder) -> {
|
||||||
if (!(context.getSource().getSender() instanceof Player player))
|
if (!(context.getSource().getSender() instanceof Player))
|
||||||
return Suggestions.empty();
|
return Suggestions.empty();
|
||||||
|
|
||||||
OfflinePlayer target = context.getArgument("player", OfflinePlayer.class);
|
OfflinePlayer target = context.getArgument("player", OfflinePlayer.class);
|
||||||
|
|||||||
@@ -18,14 +18,17 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class DisposeCommand implements EssentiaCommand {
|
public class DisposeCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "dispose";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "dispose";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName)
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission())
|
||||||
)
|
)
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
if (source.getSource().getSender() instanceof Player player)
|
if (source.getSource().getSender() instanceof Player player)
|
||||||
@@ -35,10 +38,10 @@ public class DisposeCommand implements EssentiaCommand {
|
|||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("player", ArgumentTypes.player())
|
Commands.argument("player", ArgumentTypes.player())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
CommandSourceStack sourceStack = source.getSource();
|
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);
|
execute(source.getSource().getSender(), target);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.alttd.essentia.commands.player;
|
|||||||
|
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.alttd.essentia.api.events.EssentiaEvent;
|
import com.alttd.essentia.api.events.EssentiaEvent;
|
||||||
import com.alttd.essentia.api.events.PlayerTeleportHomeEvent;
|
import com.alttd.essentia.api.events.player.PlayerTeleportHomeEvent;
|
||||||
import com.alttd.essentia.api.model.Home;
|
import com.alttd.essentia.api.model.Home;
|
||||||
import com.alttd.essentia.commands.EssentiaCommand;
|
import com.alttd.essentia.commands.EssentiaCommand;
|
||||||
import com.alttd.essentia.configuration.Config;
|
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.alttd.essentia.tasks.TeleportSounds;
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
import io.papermc.paper.command.brigadier.Commands;
|
import io.papermc.paper.command.brigadier.Commands;
|
||||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
|
||||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
|
||||||
import org.apache.commons.lang3.BooleanUtils;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
// TODO - home other
|
// TODO - home other
|
||||||
public class HomeCommand implements EssentiaCommand {
|
public class HomeCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "home";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "home";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
|
||||||
commandSourceStack.getSender() instanceof Player
|
commandSourceStack.getSender() instanceof Player
|
||||||
)
|
)
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
@@ -46,6 +47,24 @@ public class HomeCommand implements EssentiaCommand {
|
|||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("name", StringArgumentType.word())
|
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) -> {
|
.executes((source) -> {
|
||||||
if (!(source.getSource().getSender() instanceof Player player))
|
if (!(source.getSource().getSender() instanceof Player player))
|
||||||
return 1;
|
return 1;
|
||||||
@@ -83,9 +102,8 @@ public class HomeCommand implements EssentiaCommand {
|
|||||||
new TeleportSounds(homeLoc, target.getLocation())
|
new TeleportSounds(homeLoc, target.getLocation())
|
||||||
.runTaskLater(EssentiaPlugin.instance(), 1);
|
.runTaskLater(EssentiaPlugin.instance(), 1);
|
||||||
|
|
||||||
String homeName = home;
|
|
||||||
target.teleportAsync(homeLoc).thenAccept(result ->
|
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 {
|
public class HomeListCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "homelist";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "homelist";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName)
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission())
|
||||||
)
|
)
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
if (source.getSource().getSender() instanceof Player player)
|
if (source.getSource().getSender() instanceof Player player)
|
||||||
@@ -36,10 +39,9 @@ public class HomeListCommand implements EssentiaCommand {
|
|||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("player", new OfflinePlayerCompletingArgument())
|
Commands.argument("player", new OfflinePlayerCompletingArgument())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
|
||||||
.executes((source) -> {
|
.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);
|
execute(source.getSource().getSender(), target);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.alttd.essentia.commands.player;
|
|||||||
|
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.alttd.essentia.api.events.EssentiaEvent;
|
import com.alttd.essentia.api.events.EssentiaEvent;
|
||||||
import com.alttd.essentia.api.events.PlayerSetHomeEvent;
|
import com.alttd.essentia.api.events.player.PlayerSetHomeEvent;
|
||||||
import com.alttd.essentia.api.user.User;
|
import com.alttd.essentia.api.user.User;
|
||||||
import com.alttd.essentia.commands.EssentiaCommand;
|
import com.alttd.essentia.commands.EssentiaCommand;
|
||||||
import com.alttd.essentia.commands.argumement.OfflinePlayerArgument;
|
import com.alttd.essentia.commands.argumement.OfflinePlayerArgument;
|
||||||
@@ -20,14 +20,17 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class SetHomeCommand implements EssentiaCommand {
|
public class SetHomeCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "sethome";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "sethome";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
|
||||||
commandSourceStack.getSender() instanceof Player
|
commandSourceStack.getSender() instanceof Player
|
||||||
)
|
)
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
@@ -49,7 +52,7 @@ public class SetHomeCommand implements EssentiaCommand {
|
|||||||
)
|
)
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("player", new OfflinePlayerArgument())
|
Commands.argument("player", new OfflinePlayerArgument())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("name", StringArgumentType.word())
|
Commands.argument("name", StringArgumentType.word())
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
package com.alttd.essentia.commands.player;
|
package com.alttd.essentia.commands.player;
|
||||||
|
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.alttd.essentia.api.events.PlayerTeleportBackEvent;
|
import com.alttd.essentia.api.events.player.PlayerTeleportSpawnEvent;
|
||||||
import com.alttd.essentia.api.events.PlayerTeleportSpawnEvent;
|
|
||||||
import com.alttd.essentia.commands.EssentiaCommand;
|
import com.alttd.essentia.commands.EssentiaCommand;
|
||||||
import com.alttd.essentia.configuration.Config;
|
import com.alttd.essentia.configuration.Config;
|
||||||
import com.alttd.essentia.api.events.EssentiaEvent;
|
import com.alttd.essentia.api.events.EssentiaEvent;
|
||||||
@@ -22,14 +21,17 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class SpawnCommand implements EssentiaCommand {
|
public class SpawnCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "spawn";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "spawn";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName)
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission())
|
||||||
)
|
)
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
if (source.getSource().getSender() instanceof Player player)
|
if (source.getSource().getSender() instanceof Player player)
|
||||||
@@ -39,11 +41,11 @@ public class SpawnCommand implements EssentiaCommand {
|
|||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("player", ArgumentTypes.player())
|
Commands.argument("player", ArgumentTypes.player())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
CommandSourceStack sourceStack = source.getSource();
|
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);
|
execute(source.getSource().getSender(), target);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -16,14 +16,17 @@ import java.util.List;
|
|||||||
|
|
||||||
public class TeleportAcceptCommand implements EssentiaCommand {
|
public class TeleportAcceptCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "teleportaccept";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "teleportaccept";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
|
||||||
commandSourceStack.getSender() instanceof Player
|
commandSourceStack.getSender() instanceof Player
|
||||||
)
|
)
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
|
|||||||
@@ -16,14 +16,17 @@ import java.util.List;
|
|||||||
|
|
||||||
public class TeleportDenyCommand implements EssentiaCommand {
|
public class TeleportDenyCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "teleportdeny";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "teleportdeny";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
|
||||||
commandSourceStack.getSender() instanceof Player
|
commandSourceStack.getSender() instanceof Player
|
||||||
)
|
)
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
|
|||||||
@@ -20,25 +20,28 @@ import java.util.List;
|
|||||||
|
|
||||||
public class TeleportRequestCommand implements EssentiaCommand {
|
public class TeleportRequestCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "teleportrequesthere";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "teleportrequesthere";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
|
||||||
commandSourceStack.getSender() instanceof Player
|
commandSourceStack.getSender() instanceof Player
|
||||||
)
|
)
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("player", ArgumentTypes.player())
|
Commands.argument("player", ArgumentTypes.player())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
if (!(source.getSource().getSender() instanceof Player player))
|
if (!(source.getSource().getSender() instanceof Player player))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
CommandSourceStack sourceStack = source.getSource();
|
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);
|
execute(player, target);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
+8
-5
@@ -20,25 +20,28 @@ import java.util.List;
|
|||||||
|
|
||||||
public class TeleportRequestHereCommand implements EssentiaCommand {
|
public class TeleportRequestHereCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "teleportrequesthere";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "teleportrequesthere";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName) &&
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
|
||||||
commandSourceStack.getSender() instanceof Player
|
commandSourceStack.getSender() instanceof Player
|
||||||
)
|
)
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("player", ArgumentTypes.player())
|
Commands.argument("player", ArgumentTypes.player())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
if (!(source.getSource().getSender() instanceof Player player))
|
if (!(source.getSource().getSender() instanceof Player player))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
CommandSourceStack sourceStack = source.getSource();
|
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);
|
execute(player, target);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -21,14 +21,17 @@ import java.util.List;
|
|||||||
|
|
||||||
public class TeleportToggleCommand implements EssentiaCommand {
|
public class TeleportToggleCommand implements EssentiaCommand {
|
||||||
|
|
||||||
static String commandName = "teleporttoggle";
|
@Override
|
||||||
|
public String commandName() {
|
||||||
|
return "teleporttoggle";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
|
||||||
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
final LiteralArgumentBuilder<CommandSourceStack> builder =
|
||||||
Commands.literal(commandName)
|
Commands.literal(commandName())
|
||||||
.requires(
|
.requires(
|
||||||
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName)
|
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission())
|
||||||
)
|
)
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
if (source.getSource().getSender() instanceof Player player)
|
if (source.getSource().getSender() instanceof Player player)
|
||||||
@@ -38,10 +41,10 @@ public class TeleportToggleCommand implements EssentiaCommand {
|
|||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
Commands.argument("player", ArgumentTypes.player())
|
Commands.argument("player", ArgumentTypes.player())
|
||||||
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.player." + commandName + ".other"))
|
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
|
||||||
.executes((source) -> {
|
.executes((source) -> {
|
||||||
CommandSourceStack sourceStack = source.getSource();
|
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);
|
execute(source.getSource().getSender(), target);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ package com.alttd.essentia.configuration;
|
|||||||
|
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.google.common.base.Throwables;
|
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.Sound;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
@@ -35,7 +36,7 @@ public class Config {
|
|||||||
config.load(CONFIG_FILE);
|
config.load(CONFIG_FILE);
|
||||||
} catch (IOException ignore) {
|
} catch (IOException ignore) {
|
||||||
} catch (InvalidConfigurationException ex) {
|
} 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);
|
Throwables.throwIfUnchecked(ex);
|
||||||
}
|
}
|
||||||
config.options().header(HEADER);
|
config.options().header(HEADER);
|
||||||
@@ -44,7 +45,7 @@ public class Config {
|
|||||||
version = getInt("config-version", 1);
|
version = getInt("config-version", 1);
|
||||||
set("config-version", 1);
|
set("config-version", 1);
|
||||||
|
|
||||||
EssentiaPlugin.instance().getLogger().info("Essentia Configuration loaded!");
|
log(Level.INFO,"Essentia Configuration loaded!");
|
||||||
readConfig(Config.class, null);
|
readConfig(Config.class, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +59,7 @@ public class Config {
|
|||||||
} catch (InvocationTargetException ex) {
|
} catch (InvocationTargetException ex) {
|
||||||
Throwables.throwIfUnchecked(ex);
|
Throwables.throwIfUnchecked(ex);
|
||||||
} catch (Exception 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();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void saveConfig() {
|
public static void saveConfig() {
|
||||||
try {
|
try {
|
||||||
config.save(CONFIG_FILE);
|
config.save(CONFIG_FILE);
|
||||||
} catch (IOException ex) {
|
} 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);
|
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 int TELEPORT_REQUEST_TIMEOUT = 30;
|
||||||
public static boolean TELEPORT_REQUEST_TIMEOUT_MESSAGES = true;
|
public static boolean TELEPORT_REQUEST_TIMEOUT_MESSAGES = true;
|
||||||
public static boolean BACK_ON_DEATH = false;
|
public static boolean BACK_ON_DEATH = false;
|
||||||
@@ -271,4 +276,10 @@ public class Config {
|
|||||||
MYSQL_PASSWORD = getString("storage.mysql.password", MYSQL_PASSWORD);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+14
-15
@@ -1,9 +1,9 @@
|
|||||||
package com.alttd.essentia.listeners;
|
package com.alttd.essentia.feature.cuff;
|
||||||
|
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.alttd.essentia.api.user.User;
|
import com.alttd.essentia.api.user.User;
|
||||||
import com.alttd.essentia.api.user.UserManager;
|
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.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
@@ -23,26 +23,26 @@ public class CuffListener implements Listener {
|
|||||||
this.plugin = EssentiaPlugin.instance();
|
this.plugin = EssentiaPlugin.instance();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isCuffed(Player player) {
|
private boolean isNotCuffed(Player player) {
|
||||||
UserManager userManager = plugin.userManager();
|
UserManager userManager = plugin.userManager();
|
||||||
User user = userManager.getUser(player);
|
User user = userManager.getUser(player);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
return false;
|
return true;
|
||||||
|
|
||||||
return user.isCuffed();
|
return !user.isCuffed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
if (!isCuffed(event.getPlayer()))
|
if (isNotCuffed(event.getPlayer()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
cancelEvent(event, event.getPlayer());
|
cancelEvent(event, event.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
|
public void onAsyncPlayerChat(AsyncChatEvent event) {
|
||||||
if (!isCuffed(event.getPlayer()))
|
if (isNotCuffed(event.getPlayer()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
@@ -57,7 +57,7 @@ public class CuffListener implements Listener {
|
|||||||
if (!(event.getWhoClicked() instanceof Player player))
|
if (!(event.getWhoClicked() instanceof Player player))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!isCuffed(player))
|
if (isNotCuffed(player))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
cancelEvent(event, player);
|
cancelEvent(event, player);
|
||||||
@@ -65,7 +65,7 @@ public class CuffListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerDropItemEvent(PlayerDropItemEvent event) {
|
public void onPlayerDropItemEvent(PlayerDropItemEvent event) {
|
||||||
if (!isCuffed(event.getPlayer()))
|
if (isNotCuffed(event.getPlayer()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
cancelEvent(event, event.getPlayer());
|
cancelEvent(event, event.getPlayer());
|
||||||
@@ -76,7 +76,7 @@ public class CuffListener implements Listener {
|
|||||||
if (!(event.getEntity().getShooter() instanceof Player player))
|
if (!(event.getEntity().getShooter() instanceof Player player))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!isCuffed(player))
|
if (isNotCuffed(player))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
cancelEvent(event, player);
|
cancelEvent(event, player);
|
||||||
@@ -87,7 +87,7 @@ public class CuffListener implements Listener {
|
|||||||
if (!(event.getDamager() instanceof Player player))
|
if (!(event.getDamager() instanceof Player player))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!isCuffed(player))
|
if (isNotCuffed(player))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
cancelEvent(event, player);
|
cancelEvent(event, player);
|
||||||
@@ -98,7 +98,7 @@ public class CuffListener implements Listener {
|
|||||||
if (!(event.getEntity() instanceof Player player))
|
if (!(event.getEntity() instanceof Player player))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!isCuffed(player))
|
if (isNotCuffed(player))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
cancelEvent(event, player);
|
cancelEvent(event, player);
|
||||||
@@ -107,7 +107,7 @@ public class CuffListener implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerMove(PlayerMoveEvent event) {
|
public void onPlayerMove(PlayerMoveEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (!isCuffed(player))
|
if (isNotCuffed(player))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Location from = event.getFrom();
|
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()) {
|
if (from.getWorld() != to.getWorld() || from.getBlockX() != to.getBlockX() || from.getBlockZ() != to.getBlockZ()) {
|
||||||
cancelEvent(event, player);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
package com.alttd.essentia.listeners;
|
package com.alttd.essentia.feature.flight;
|
||||||
|
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.alttd.essentia.api.model.UserSettings;
|
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.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||||
|
// TODO -- set flight and flying when player logs in!
|
||||||
public class FlightListener implements Listener {
|
public class FlightListener implements Listener {
|
||||||
|
|
||||||
private final EssentiaPlugin plugin;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+14
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+13
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
package com.alttd.essentia.feature.savedinventory;
|
||||||
|
|
||||||
|
public class SavedInventoryFeature {
|
||||||
|
}
|
||||||
+27
@@ -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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+8
@@ -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 boolean needsSaving;
|
||||||
|
|
||||||
private EssentiaUserSettings(Builder builder) {
|
private EssentiaUserSettings(Builder builder) {
|
||||||
this.godMode = builder.godMode;;
|
this.godMode = builder.godMode;
|
||||||
this.flying = builder.flying;
|
this.flying = builder.flying;
|
||||||
this.flySpeed = builder.flySpeed;
|
this.flySpeed = builder.flySpeed;
|
||||||
this.walkSpeed = builder.walkSpeed;
|
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 {
|
public abstract class EssentiaRequest implements Request {
|
||||||
|
|
||||||
private final EssentiaPlugin plugin;
|
protected final EssentiaPlugin plugin;
|
||||||
@Getter private final Player requester;
|
@Getter private final Player requester;
|
||||||
@Getter private final Player target;
|
@Getter private final Player target;
|
||||||
private final RequestTimeout timeoutTask;
|
@Getter private final RequestTimeout timeoutTask;
|
||||||
|
|
||||||
TagResolver placeholders;
|
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;
|
package com.alttd.essentia.storage;
|
||||||
|
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.alttd.essentia.storage.mysql.SQLStorageProvider;
|
|
||||||
import com.alttd.essentia.storage.sqlite.SQLiteStorageProvider;
|
|
||||||
import com.alttd.essentia.storage.yaml.YamlStorageProvider;
|
import com.alttd.essentia.storage.yaml.YamlStorageProvider;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|||||||
@@ -45,9 +45,9 @@ public class DatabaseQuery {
|
|||||||
|
|
||||||
void edit(PreparedStatement preparedStatement) throws SQLException;
|
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) {
|
default void onFailure(SQLException e) {
|
||||||
e.printStackTrace();
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ name: Essentia
|
|||||||
version: ${version}
|
version: ${version}
|
||||||
main: com.alttd.essentia.EssentiaPlugin
|
main: com.alttd.essentia.EssentiaPlugin
|
||||||
description: Altitude essentials ;)
|
description: Altitude essentials ;)
|
||||||
|
load: POSTWORLD
|
||||||
authors:
|
authors:
|
||||||
- destro174
|
- destro174
|
||||||
api-version: "1.21"
|
api-version: "1.21"
|
||||||
Reference in New Issue
Block a user