Compare commits

...

52 Commits

Author SHA1 Message Date
Len 1f88f6ea0d Stub for SavedInventory 2025-11-12 23:18:24 +01:00
Len 798946b386 Refactor Events 2025-11-12 23:17:44 +01:00
Len c32bd21f0f Refactor Events 2025-11-12 23:16:56 +01:00
Len 99dcb318ad Use reflection to load feature event listeners 2025-06-29 17:03:11 +02:00
Len fa289a8737 Only add player equipment to EquipmentArgumentType 2025-06-29 16:34:18 +02:00
Len b68835918f Implement CuffFeature 2025-06-29 14:36:59 +02:00
Len d3cd059af1 Implement FlightFeature 2025-06-29 13:35:57 +02:00
Len 612a0281d6 Implement GodModeFeature 2025-06-29 13:33:21 +02:00
Len d4f33b8c2e Implement EssentiaFeatures 2025-06-29 13:01:37 +02:00
Len 9fa43c8c65 Add Timer.java 2025-06-29 12:50:51 +02:00
Len 13a78515c5 Switch to use Cosmos 2025-06-29 08:31:59 +02:00
Len 91e6d3be8e Inline logging in Config.java 2025-06-29 08:28:07 +02:00
Len 06a8aa0f65 Implement base for RTP 2024-10-20 14:22:45 +02:00
Len 139c51e9b8 Make plugin load postworld 2024-10-15 21:38:46 +02:00
Len ed0d15b3d4 Add KillallCommand.java 2024-10-05 16:06:01 +02:00
Len 76ae3103de Add SpawnMobCommand.java 2024-10-04 22:48:44 +02:00
Len 434cf6ac15 Remove EnchantmentArgument.java 2024-10-04 22:46:24 +02:00
Len d786ebcff5 Add EssentiaCommandArgument 2024-10-04 22:43:32 +02:00
Len 2ef960b189 Fix commands not being loaded by reflection. 2024-10-04 21:24:18 +02:00
Len 4dba5f3c41 Add RepairCommand 2024-10-04 21:05:26 +02:00
Len dbb3f45898 Move command permissions to EssentiaCommand interface. 2024-10-04 18:34:02 +02:00
Len 162ffd3599 Update GameModeCommand to use native GameModeArgument 2024-10-04 17:04:34 +02:00
Len 430e6fb898 Fix typo in EnchantmentArgument.java 2024-10-04 17:04:34 +02:00
Len aede22811a Add TimeCommand 2024-08-15 21:08:08 +02:00
Len a8221a68af Add reset option to pweather 2024-08-15 17:49:45 +02:00
Len 29559b83c4 Add SetSpawnCommand.java 2024-08-15 17:43:31 +02:00
Len be8b7e20df Add PlayerWeatherCommand.java and WeatherArgument.java 2024-08-15 17:23:12 +02:00
Len 6a8e21852c Add WeatherCommand.java 2024-08-15 17:15:31 +02:00
Len ff2824f287 Switch to brigadier for commands 2024-08-15 15:58:25 +02:00
Len c4055358b1 Add brigadier ArgumentTypes 2024-08-15 15:30:22 +02:00
Len ad7e61ffe8 Use Reflection to load commands. 2024-08-14 20:48:27 +02:00
Len 628e18858a Load more UserSettings in YamlStorageProvider 2024-08-14 20:47:15 +02:00
Len 563d17d53b Use plugin logger. 2024-08-14 20:46:24 +02:00
Len bd3e537199 Remove commands from plugin.yml 2024-08-14 20:43:36 +02:00
Len 3bc58b7f9c Use reflection to load event listeners 2024-08-14 20:43:00 +02:00
Len 52e51f99da Update default storageprovider to YAML. 2024-08-13 21:22:14 +02:00
Len 6a0fdbbc1e Update references to 1.12.1 2024-08-13 21:21:37 +02:00
Len 2df6a71e6a Update archiveFileName in build.gradle.kts 2024-08-12 10:01:45 +02:00
Len e2a32c1ebd Load homes from SQL 2024-08-12 09:53:44 +02:00
Len a7f14eb573 Remove lombok setters 2024-07-28 14:57:48 +02:00
Len cf0bcefd06 Add loading for EssentiaUserSettings 2024-07-28 14:47:49 +02:00
Len fe83919200 Refactor 2024-07-28 12:52:55 +02:00
Len 5cc798c482 Load user data from sql 2024-06-19 10:25:05 +02:00
Len f6dd31ba33 Do not expose saving tasks to the api and change the way saving data is handled. 2024-06-18 10:40:31 +02:00
Len d1872f6e95 Fix saving into sql 2024-06-18 09:53:44 +02:00
Len bacc44b2b9 Load in users and create new users if needed. 2024-06-17 10:56:07 +02:00
Len dacdacf68e Fix Config.java not loading and saving. 2024-06-17 10:12:26 +02:00
Len 2e2d370bc6 initiate and disable storage providers. 2024-06-17 09:29:22 +02:00
Len 5ed4c32cc1 Start working on storage providers. 2024-06-16 23:54:31 +02:00
Len 767d248ac8 Refactor to make use of the new user bean. 2024-06-16 21:30:07 +02:00
Len 41c5725ea8 Add API and beans for User and UserManager. 2024-06-16 20:40:12 +02:00
Len f5da67cc69 Switch to Galaxy 2024-06-16 16:14:27 +02:00
119 changed files with 5707 additions and 1045 deletions

View File

@ -3,7 +3,7 @@ plugins {
}
dependencies {
compileOnly("com.alttd:Comet-API:1.20.4-R0.1-SNAPSHOT")
compileOnly("com.alttd:Galaxy-API:1.21.1-R0.1-SNAPSHOT")
}
tasks {
@ -16,7 +16,7 @@ publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
artifactId = "${rootProject.name}-${project.name}-$version.jar"
artifactId = "${project.name}-$version.jar"
}
}
}

View File

@ -1,5 +1,6 @@
package com.alttd.essentia;
import com.alttd.essentia.api.model.randomteleport.LocationValidator;
import org.jetbrains.annotations.ApiStatus;
public interface EssentiaAPI {
@ -19,4 +20,6 @@ public interface EssentiaAPI {
Provider.instance = instance;
}
}
public void addLocationValidator(LocationValidator locationValidator);
}

View File

@ -1,4 +1,4 @@
package com.alttd.essentia.events;
package com.alttd.essentia.api.events;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;

View File

@ -0,0 +1,32 @@
package com.alttd.essentia.api.events;
import com.alttd.essentia.api.user.User;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class EssentiaUserLoadEvent extends EssentiaEvent {
private static final HandlerList handlerList = new HandlerList();
private final User user;
public EssentiaUserLoadEvent(User user) {
this.user = user;
}
public User getUser() {
return user;
}
@NotNull
@Override
public HandlerList getHandlers() {
return handlerList;
}
@NotNull
public static HandlerList getHandlerList() {
return handlerList;
}
}

View File

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

View File

@ -1,6 +1,6 @@
package com.alttd.essentia.events;
package com.alttd.essentia.api.events.player;
import org.bukkit.Location;
import com.alttd.essentia.api.events.EssentiaEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;

View File

@ -1,5 +1,6 @@
package com.alttd.essentia.events;
package com.alttd.essentia.api.events.player;
import com.alttd.essentia.api.events.EssentiaEvent;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;

View File

@ -1,5 +1,6 @@
package com.alttd.essentia.events;
package com.alttd.essentia.api.events.player;
import com.alttd.essentia.api.events.EssentiaEvent;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;

View File

@ -1,5 +1,6 @@
package com.alttd.essentia.events;
package com.alttd.essentia.api.events.player;
import com.alttd.essentia.api.events.EssentiaEvent;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;

View File

@ -1,5 +1,6 @@
package com.alttd.essentia.events;
package com.alttd.essentia.api.events.player;
import com.alttd.essentia.api.events.EssentiaEvent;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;

View File

@ -0,0 +1,10 @@
package com.alttd.essentia.api.model;
import org.bukkit.Location;
public interface Home {
String name();
Location location();
}

View File

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

View File

@ -0,0 +1,16 @@
package com.alttd.essentia.api.model;
public interface UserSettings {
boolean godMode();
void godMode(boolean godMode);
boolean allowTeleports();
void allowTeleports(boolean allowTeleports);
boolean flying();
void flying(boolean flying);
}

View File

@ -0,0 +1,8 @@
package com.alttd.essentia.api.model.randomteleport;
import org.bukkit.Location;
public interface LocationValidator {
boolean validate(Location location);
}

View File

@ -0,0 +1,10 @@
package com.alttd.essentia.api.request;
public interface Request {
void accept();
void deny();
void cancel();
}

View File

@ -0,0 +1,46 @@
package com.alttd.essentia.api.user;
import com.alttd.essentia.api.model.Home;
import com.alttd.essentia.api.model.UserSettings;
import com.alttd.essentia.api.request.Request;
import org.bukkit.Location;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
public interface User {
UUID getUUID();
Location getBackLocation(boolean death);
void setBackLocation(boolean death, Location location);
boolean hasHome(String name);
Home getHome(String name);
void setHome(String name, Location location);
void removeHome(String name);
int getHomeCount();
List<String> getMatchingHomeNames(String homeName);
Map<String, Home> getHomeData();
Set<String> getHomes();
UserSettings getUserSettings();
Request request();
void request(Request request);
boolean isCuffed();
void setCuffed(boolean cuffed);
}

View File

@ -0,0 +1,26 @@
package com.alttd.essentia.api.user;
import org.bukkit.entity.Player;
import java.util.Map;
import java.util.UUID;
public interface UserManager {
User getUser(Player player);
User getUser(UUID uuid);
void addUser(User user);
void removeUser(UUID uuid);
boolean hasUser(UUID uuid);
Map<UUID, User> getUsers();
User createNewUser(UUID uuid);
void saveAllUsers();
}

View File

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

View File

@ -5,10 +5,11 @@ plugins {
dependencies {
implementation(project(":api"))
compileOnly("com.alttd:Comet-API:1.20.4-R0.1-SNAPSHOT")
compileOnly("com.alttd.cosmos:cosmos-api:1.21.6-R0.1-SNAPSHOT")
api("org.reflections:reflections:0.10.2")
compileOnly("org.projectlombok:lombok:1.18.24")
annotationProcessor("org.projectlombok:lombok:1.18.24")
compileOnly("org.projectlombok:lombok:1.18.34")
annotationProcessor("org.projectlombok:lombok:1.18.34")
}
tasks {
@ -23,12 +24,4 @@ tasks {
expand(Pair("version", rootProject.version))
}
}
}
//bukkit {
// name = rootProject.name
// main = "$group.${rootProject.name}Plugin"
// version = "${rootProject.version}"
// apiVersion = "1.20"
// authors = listOf("destro174")
//}
}

View File

@ -1,21 +1,47 @@
package com.alttd.essentia;
import com.alttd.essentia.commands.admin.*;
import com.alttd.essentia.commands.player.*;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
import com.alttd.essentia.listeners.PlayerListener;
import com.alttd.essentia.api.model.randomteleport.LocationValidator;
import com.alttd.essentia.feature.Features;
import com.alttd.essentia.model.annotations.Depends;
import com.alttd.essentia.storage.StorageManager;
import com.alttd.essentia.storage.StorageProvider;
import com.alttd.essentia.storage.StorageType;
import com.alttd.essentia.user.EssentiaUserManager;
import com.alttd.essentia.api.user.UserManager;
import com.alttd.essentia.util.Timer;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
import lombok.Getter;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.slf4j.Logger;
import org.reflections.Reflections;
import org.reflections.scanners.Scanners;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
@Getter
private static EssentiaPlugin instance;
@Getter
private UserManager userManager;
@Getter
private List<LocationValidator> locationValidators;
@Getter
private StorageProvider storageProvider;
@Getter
private Features features;
@Override
public void onLoad() {
instance = this;
@ -24,45 +50,112 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
@Override
public void onEnable() {
loadConfiguration();
loadCommands();
loadEventListeners();
new Timer("onEnable", () -> {
new Timer("loadConfiguration", this::loadConfiguration);
new Timer("loadFeatures", this::loadFeatures);
new Timer("loadCommands", this::loadCommands);
new Timer("loadEventListeners", this::loadEventListeners);
new Timer("loadManagers", this::loadManagers);
new Timer("loadStorageProvider", this::loadStorageProvider);
new Timer("loadLocationValidators", this::loadLocationValidators);
});
}
@Override
public void onDisable() {
getServer().getScheduler().cancelTasks(this);
userManager().saveAllUsers();
storageProvider().disable();
}
public void loadConfiguration() {
Config.init();
}
public void loadCommands() {
getCommand("essentia").setExecutor(new EssentiaCommand(this));
getCommand("teleportaccept").setExecutor(new TeleportAcceptCommand(this));
getCommand("teleportdeny").setExecutor(new TeleportDenyCommand(this));
getCommand("teleportrequest").setExecutor(new TeleportRequestCommand(this));
getCommand("teleportrequesthere").setExecutor(new TeleportRequestHereCommand(this));
getCommand("teleporttoggle").setExecutor(new TeleportToggleCommand(this));
getCommand("clearinventory").setExecutor(new ClearInventoryCommand(this));
getCommand("home").setExecutor(new HomeCommand(this));
getCommand("homes").setExecutor(new HomeListCommand(this));
getCommand("sethome").setExecutor(new SetHomeCommand(this));
getCommand("deletehome").setExecutor(new DelHomeCommand(this));
getCommand("back").setExecutor(new BackCommand(this));
getCommand("deathback").setExecutor(new DeathBackCommand(this));
getCommand("fly").setExecutor(new FlyCommand(this));
getCommand("gamemode").setExecutor(new GamemodeCommand(this));
getCommand("heal").setExecutor(new HealCommand(this));
getCommand("feed").setExecutor(new FeedCommand(this));
getCommand("enchant").setExecutor(new EnchantCommand(this));
getCommand("spawn").setExecutor(new SpawnCommand(this));
public void loadFeatures() {
features = new Features(this);
features.registerAll();
}
public void loadEventListeners() {
void loadCommands() {
Reflections reflections = new Reflections("com.alttd.essentia.commands");
Set<Class<?>> subTypes = reflections.get(Scanners.SubTypes.of(EssentiaCommand.class).asClass());
LifecycleEventManager<Plugin> manager = this.getLifecycleManager();
manager.registerEventHandler(LifecycleEvents.COMMANDS, event -> {
final Commands commands = event.registrar();
subTypes.forEach(clazz -> {
try {
EssentiaCommand essentiaCommand = (EssentiaCommand) clazz.getDeclaredConstructor().newInstance();
final Depends depends = clazz.getAnnotation(Depends.class);
if (depends != null) {
if (!features.isEnabled(depends.value())) {
return;
}
}
commands.register(essentiaCommand.command(), essentiaCommand.description(), essentiaCommand.aliases());
} catch (Exception e) {
EssentiaPlugin.instance().getLogger().severe("Failed to register command " + clazz.getSimpleName());
}
});
});
}
void loadEventListeners() {
final PluginManager pluginManager = getServer().getPluginManager();
pluginManager.registerEvents(new PlayerListener(this), this);
Reflections reflections = new Reflections("com.alttd.essentia.listeners"); // These are plugin required listeners eg player data loading on login.
Set<Class<?>> subTypes = reflections.get(Scanners.SubTypes.of(Listener.class).asClass());
reflections = new Reflections("com.alttd.essentia.feature"); // These are them listeners for the features.
subTypes.addAll(reflections.get(Scanners.SubTypes.of(Listener.class).asClass()));
subTypes.forEach(clazz -> {
try {
Listener listener = (Listener) clazz.getDeclaredConstructor().newInstance();
final Depends depends = clazz.getAnnotation(Depends.class);
if (depends != null) {
if (!features.isEnabled(depends.value())) {
return;
}
}
pluginManager.registerEvents(listener, this);
} catch (Exception e) {
EssentiaPlugin.instance().getLogger().severe("Failed to register event listener " + clazz.getSimpleName());
}
});
}
void loadManagers() {
userManager = new EssentiaUserManager(this);
}
void loadStorageProvider() {
StorageManager storageManager = new StorageManager(this);
storageProvider = storageManager.storageProvider(StorageType.valueOf(Config.STORAGE_TYPE.toUpperCase()));
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);
}
}

View File

@ -1,13 +0,0 @@
package com.alttd.essentia.commands;
import com.alttd.essentia.EssentiaPlugin;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public abstract class AdminSubCommand extends SubCommand {
protected AdminSubCommand(EssentiaPlugin plugin, String name, String... aliases) {
super(plugin, name, aliases);
}
}

View File

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

View File

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

View File

@ -1,26 +0,0 @@
package com.alttd.essentia.commands;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.configuration.Config;
import com.alttd.essentia.configuration.PlayerConfig;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public abstract class PlayerSubCommand extends SubCommand {
protected PlayerSubCommand(EssentiaPlugin plugin, String name, String... aliases) {
super(plugin, name, aliases);
}
@Override
public boolean execute(CommandSender sender, String... args) {
if (!(sender instanceof Player player)) {
sender.sendRichMessage(Config.PLAYER_ONLY_COMMAND);
return true;
}
return execute(player, PlayerConfig.getConfig(player), args);
}
protected abstract boolean execute(Player player, PlayerConfig playerConfig, String... args);
}

View File

@ -1,70 +0,0 @@
package com.alttd.essentia.commands;
import com.alttd.essentia.EssentiaPlugin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public abstract class SubCommand implements TabExecutor {
protected EssentiaPlugin plugin;
private final String name;
private final String[] aliases;
private final Map<String, SubCommand> subCommands = new LinkedHashMap<>();
protected SubCommand(EssentiaPlugin plugin, String name, String... aliases) {
this.plugin = plugin;
this.name = name;
this.aliases = aliases;
}
protected abstract boolean execute(CommandSender sender, String... args);
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
if (args.length > 0) {
SubCommand subCommand = getSubCommand(args[0]);
if (subCommand != null) {
return subCommand.onCommand(sender, cmd, args[0], Arrays.copyOfRange(args, 1, args.length));
}
}
return execute(sender, args);
}
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
if (args.length == 0) {
return subCommands.keySet().stream()
.sorted(String::compareToIgnoreCase)
.collect(Collectors.toList());
}
SubCommand subCommand = getSubCommand(args[0]);
if (subCommand != null) {
return subCommand.onTabComplete(sender, command, args[0], Arrays.copyOfRange(args, 1, args.length));
} else if (args.length == 1) {
return subCommands.keySet().stream()
.filter(s -> s.toLowerCase().startsWith(args[0]))
.sorted(String::compareToIgnoreCase)
.collect(Collectors.toList());
}
return null;
}
public void registerSubCommand(SubCommand subCommand) {
subCommands.put(subCommand.name.toLowerCase(), subCommand);
for (String alias : subCommand.aliases) {
subCommands.putIfAbsent(alias.toLowerCase(), subCommand);
}
}
private SubCommand getSubCommand(String name) {
return subCommands.get(name.toLowerCase());
}
}

View File

@ -0,0 +1,69 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class BurnCommand implements EssentiaCommand {
@Override
public String commandName() {
return "burn";
}
@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("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 "Set yourself or another player on fire!";
}
public void execute(CommandSender sender, Player target) { // TODO - optional time?
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("requester", sender.name()),
Placeholder.component("target", target.displayName())
);
target.setFireTicks((int) (3000L / 50));
sender.sendRichMessage(target == sender ? Config.BURN_SELF : Config.BURN_OTHER, placeholders);
if (target != sender)
target.sendRichMessage(Config.BURN_BY_OTHER, placeholders);
}
}

View File

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

View File

@ -0,0 +1,73 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.api.user.User;
import com.alttd.essentia.api.user.UserManager;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class CuffCommand implements EssentiaCommand {
@Override
public String commandName() {
return "cuff";
}
@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();
}
public void execute(CommandSender sender, Player target) {
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("requester", sender.name()),
Placeholder.component("target", target.displayName())
);
UserManager userManager = EssentiaPlugin.instance().userManager();
if (!userManager.hasUser(target.getUniqueId())) {
return;
}
User user = userManager.getUser(target);
if (user.isCuffed()) {
sender.sendRichMessage("<target> is already cuffed."); // TODO - CONFIG messages
return;
}
user.setCuffed(true);
// TODO - CONFIG messages
sender.sendRichMessage(target == sender ? Config.BURN_SELF : Config.BURN_OTHER, placeholders);
if (target != sender)
target.sendRichMessage(Config.BURN_BY_OTHER, placeholders);
}
}

View File

@ -1,38 +1,113 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.commands.AdminSubCommand;
import org.bukkit.NamespacedKey;
import org.bukkit.command.Command;
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 io.papermc.paper.registry.RegistryKey;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class EnchantCommand implements EssentiaCommand {
public class EnchantCommand extends AdminSubCommand {
public EnchantCommand(EssentiaPlugin plugin) {
super(plugin, "enchant");
@Override
public String commandName() {
return "enchant";
}
@Override
protected boolean execute(CommandSender sender, String... args) {
// TODO
return true;
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
)
.then(
Commands.argument("enchantment", ArgumentTypes.resource(RegistryKey.ENCHANTMENT))
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
Enchantment enchantment = source.getArgument("enchantment", Enchantment.class);
execute(source.getSource().getSender(), player, enchantment);
return 1;
}).then(
Commands.argument("level", IntegerArgumentType.integer(1, 100))
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
Enchantment enchantment = source.getArgument("enchantment", Enchantment.class);
int level = source.getArgument("level", Integer.class);
execute(source.getSource().getSender(), player, enchantment, level);
return 1;
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
Enchantment enchantment = source.getArgument("enchantment", Enchantment.class);
int level = source.getArgument("level", Integer.class);
execute(source.getSource().getSender(), target, enchantment, level);
return 1;
})
)
)
);
return builder.build();
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String @NotNull [] args) {
if (args.length == 1) {
return Arrays.stream(Enchantment.values())
.map(Enchantment::getKey)
.map(NamespacedKey::getKey)
.filter(name -> name.toLowerCase().startsWith(args[0].toLowerCase()))
.collect(Collectors.toList());
private void execute(CommandSender sender, Player target, Enchantment enchantment) {
execute(sender, target, enchantment, 1, false);
}
private void execute(CommandSender sender, Player target, Enchantment enchantment, int level) {
execute(sender, target, enchantment, level, false);
}
public void execute(CommandSender sender, Player target, Enchantment enchantment, int level, boolean unsafe) {
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("requester", sender.name()),
Placeholder.component("target", target.displayName()),
Placeholder.unparsed("enchantment", enchantment.getKey().value())
);
// target.setGameMode(gameMode);
ItemStack itemStack = target.getInventory().getItemInMainHand();
if (itemStack.getType() == Material.AIR) {
sender.sendRichMessage("Hold the item you want to enchant", placeholders);
return;
}
return null;
if (unsafe) {
itemStack.addUnsafeEnchantment(enchantment, level);
} else {
if ((level > enchantment.getMaxLevel())) {
level = enchantment.getMaxLevel();
}
if (!enchantment.canEnchantItem(itemStack)) {
sender.sendRichMessage("You can not enchant this item with <enchantment>", placeholders);
return;
}
itemStack.addEnchantment(enchantment, level);
}
sender.sendRichMessage(target == sender ? "You enchanted your item with <enchantment>." : "<sender> enchanted your item with <enchantment>.", placeholders);
if (target != sender)
target.sendRichMessage("You enchanted <target>'s item with <enchantment>.", placeholders);
}
}
}

View File

@ -0,0 +1,35 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.commands.EssentiaCommand;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import org.jetbrains.annotations.NotNull;
public class EssentiaAdminCommand implements EssentiaCommand {
@Override
public String commandName() {
return "essentiareload";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission()))
.executes((commandContext -> 1))
.then(
Commands.literal("reload")
.executes((cmd) -> {
EssentiaPlugin.instance().reloadConfig();
return com.mojang.brigadier.Command.SINGLE_SUCCESS;
})
)
;
return builder.build();
}
}

View File

@ -1,19 +0,0 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.commands.SubCommand;
import org.bukkit.command.CommandSender;
public class EssentiaCommand extends SubCommand {
public EssentiaCommand(EssentiaPlugin plugin) {
super(plugin, "essentia");
registerSubCommand(new ReloadCommand(plugin));
}
@Override
protected boolean execute(CommandSender sender, String... args) {
return true;
}
}

View File

@ -1,31 +1,55 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.commands.AdminSubCommand;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class FeedCommand extends AdminSubCommand {
public class FeedCommand implements EssentiaCommand {
public FeedCommand(EssentiaPlugin plugin) {
super(plugin, "feed");
@Override
public String commandName() {
return "feed";
}
@Override
protected boolean execute(CommandSender sender, String... args) {
Player target = args.length > 0 ? org.bukkit.Bukkit.getPlayer(args[0]) : sender instanceof Player player ? player : null;
if (target == null) {
sender.sendRichMessage(Config.PLAYER_NOT_FOUND);
return true;
}
if (!sender.hasPermission("essentia.command.feed" + (target != sender ? ".other" : "")) ) {
sender.sendRichMessage(Config.COMMAND_NO_PERMISSION);
return true;
}
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;
})
.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();
}
public void execute(CommandSender sender, Player target) {
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("requester", sender.name()),
Placeholder.component("target", target.displayName())
@ -36,6 +60,7 @@ public class FeedCommand extends AdminSubCommand {
sender.sendRichMessage(target == sender ? Config.FEED_SELF : Config.FEED_OTHER, placeholders);
if (target != sender)
target.sendRichMessage(Config.FEED_BY_OTHER, placeholders);
return true;
}
}

View File

@ -1,61 +1,77 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.commands.AdminSubCommand;
import com.alttd.essentia.api.user.User;
import com.alttd.essentia.api.user.UserManager;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.apache.commons.lang3.BooleanUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.stream.Collectors;
public class FlyCommand implements EssentiaCommand {
public class FlyCommand extends AdminSubCommand {
public FlyCommand(EssentiaPlugin plugin) {
super(plugin, "fly");
@Override
public String commandName() {
return "fly";
}
@Override
protected boolean execute(CommandSender sender, String... args) {
if (args.length > 0) {
if (!sender.hasPermission("essentia.command.fly.other")) {
sender.sendRichMessage(Config.COMMAND_NO_PERMISSION);
return true;
}
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);
Player target = Bukkit.getPlayer(args[0]);
if (target == null) {
sender.sendRichMessage(Config.PLAYER_NOT_FOUND);
return true;
}
target.setAllowFlight(!target.getAllowFlight());
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();
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("player", sender.name()),
Placeholder.component("target", target.name()),
Placeholder.unparsed("status", BooleanUtils.toStringOnOff(target.getAllowFlight()))
);
sender.sendRichMessage(Config.TOGGLED_FLIGHT_BY_OTHER, placeholders);
target.sendRichMessage(Config.TOGGLED_FLIGHT_PLAYER, placeholders);
return true;
}
if (!(sender instanceof Player player)) {
sender.sendRichMessage(Config.PLAYER_ONLY_COMMAND);
return true;
}
player.setAllowFlight(!player.getAllowFlight());
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("player", player.name()),
Placeholder.parsed("status", BooleanUtils.toStringOnOff(player.getAllowFlight()))
);
sender.sendRichMessage(Config.TOGGLED_FLIGHT, placeholders);
return true;
execute(source.getSource().getSender(), target);
return 1;
})
);
return builder.build();
}
}
public void execute(CommandSender sender, Player target) {
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("player", sender.name()),
Placeholder.component("target", target.name()),
Placeholder.unparsed("status", BooleanUtils.toStringOnOff(!target.getAllowFlight()))
);
UserManager userManager = EssentiaPlugin.instance().userManager();
if (!userManager.hasUser(target.getUniqueId())) {
return;
}
User user = userManager.getUser(target);
user.getUserSettings().flying(!user.getUserSettings().flying());
target.setFlying(!user.getUserSettings().flying());
sender.sendRichMessage(target == sender ? Config.TOGGLED_FLIGHT : Config.TOGGLED_FLIGHT_PLAYER, placeholders);
if (target != sender)
target.sendRichMessage(Config.TOGGLED_FLIGHT_BY_OTHER, placeholders);
}
}

View File

@ -0,0 +1,73 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
import com.mojang.brigadier.arguments.FloatArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class FlySpeedCommand implements EssentiaCommand {
@Override
public String commandName() {
return "flyspeed";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
).then(
Commands.argument("speed", FloatArgumentType.floatArg(-1, 1))
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
Enchantment enchantment = source.getArgument("enchantment", Enchantment.class);
float speed = source.getArgument("speed", Float.class);
execute(source.getSource().getSender(), player, speed);
return 1;
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
float speed = source.getArgument("speed", Float.class);
execute(source.getSource().getSender(), target, speed);
return 1;
})
)
);
return builder.build();
}
public void execute(CommandSender sender, Player target, float speed) {
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("requester", sender.name()),
Placeholder.component("target", target.displayName())
);
target.setFlySpeed(speed);
// TODO - Config messages
sender.sendRichMessage(target == sender ? Config.FEED_SELF : Config.FEED_OTHER, placeholders);
if (target != sender)
target.sendRichMessage(Config.FEED_BY_OTHER, placeholders);
}
}

View File

@ -0,0 +1,71 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.GameMode;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class GameModeCommand implements EssentiaCommand {
@Override
public String commandName() {
return "gamemode";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
)
.then(
Commands.argument("gamemode", ArgumentTypes.gameMode())
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
GameMode gameMode = source.getArgument("gamemode", GameMode.class);
execute(source.getSource().getSender(), player, gameMode);
return 1;
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
GameMode gameMode = source.getArgument("gamemode", GameMode.class);
execute(source.getSource().getSender(), target, gameMode);
return 1;
})
)
);
return builder.build();
}
public void execute(CommandSender sender, Player target, GameMode gameMode) {
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("requester", sender.name()),
Placeholder.component("target", target.displayName()),
Placeholder.unparsed("gamemode", gameMode.toString().toLowerCase())
);
target.setGameMode(gameMode);
sender.sendRichMessage(target == sender ? Config.GAMEMODE_SET : Config.GAMEMODE_SET_OTHER, placeholders);
if (target != sender)
target.sendRichMessage(Config.GAMEMODE_SET_BY_OTHER, placeholders);
}
}

View File

@ -1,66 +0,0 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.commands.AdminSubCommand;
import com.alttd.essentia.configuration.Config;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class GamemodeCommand extends AdminSubCommand {
public GamemodeCommand(EssentiaPlugin plugin) {
super(plugin, "gamemode");
}
@Override
protected boolean execute(CommandSender sender, String... args) {
// TODO -- refactor all "other" subcommands to follow this style, cleaner and easier?
Player target = args.length > 1 ? Bukkit.getPlayer(args[1]) : sender instanceof Player player ? player : null;
if (target == null) {
sender.sendRichMessage(Config.PLAYER_NOT_FOUND);
return true;
}
if (!sender.hasPermission("essentia.command.gamemode" + (target != sender ? ".other" : "")) ) {
sender.sendRichMessage(Config.COMMAND_NO_PERMISSION);
return true;
}
GameMode gameMode = GameMode.SURVIVAL;
switch (args[0].toLowerCase()) {
case "creative", "c" -> gameMode = GameMode.CREATIVE;
case "spectator", "sp" -> gameMode = GameMode.SPECTATOR;
}
target.setGameMode(gameMode);
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("requester", sender.name()),
Placeholder.component("target", target.displayName()),
Placeholder.unparsed("gamemode", gameMode.toString())
);
sender.sendRichMessage(target == sender ? Config.GAMEMODE_SET : Config.GAMEMODE_SET_OTHER, placeholders);
if (target != sender)
target.sendRichMessage(Config.GAMEMODE_SET_BY_OTHER, placeholders);
return true;
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
if (args.length == 1) {
String name = args[0].trim().toLowerCase();
return Arrays.stream(GameMode.values()).map(GameMode::toString)
.filter(string -> string.toLowerCase().startsWith(name)).collect(Collectors.toList());
}
return null;
}
}

View File

@ -0,0 +1,76 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.api.user.User;
import com.alttd.essentia.api.user.UserManager;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.apache.commons.lang3.BooleanUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class GodCommand implements EssentiaCommand {
@Override
public String commandName() {
return "god";
}
@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;
})
.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();
}
public void execute(CommandSender sender, Player target) {
UserManager userManager = EssentiaPlugin.instance().userManager();
User user = userManager.getUser(target);
if (user == null)
return;
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("player", sender.name()),
Placeholder.component("target", target.name()),
Placeholder.unparsed("status", BooleanUtils.toStringOnOff(!user.getUserSettings().godMode()))
);
user.getUserSettings().godMode(!user.getUserSettings().godMode());
target.setInvulnerable(!user.getUserSettings().godMode());
sender.sendRichMessage(target == sender ? Config.TOGGLED_GOD : Config.TOGGLED_GOD_PLAYER, placeholders);
if (target != sender)
target.sendRichMessage(Config.TOGGLED_GOD_BY_OTHER, placeholders);
}
}

View File

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

View File

@ -0,0 +1,58 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.commands.EssentiaCommand;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class InfoCommand implements EssentiaCommand {
@Override
public String commandName() {
return "info";
}
@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("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();
}
public void execute(CommandSender sender, Player target) { // TODO - implement player info
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("requester", sender.name()),
Placeholder.component("target", target.displayName())
);
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -1,19 +0,0 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.commands.AdminSubCommand;
import org.bukkit.command.CommandSender;
public class ReloadCommand extends AdminSubCommand {
public ReloadCommand(EssentiaPlugin plugin) {
super(plugin, "reload");
}
@Override
protected boolean execute(CommandSender sender, String... args) {
plugin.loadConfiguration();
return true;
}
}

View File

@ -0,0 +1,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);
}
}

View File

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

View File

@ -0,0 +1,74 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class SmiteCommand implements EssentiaCommand {
@Override
public String commandName() {
return "smite";
}
@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("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();
}
public void execute(CommandSender sender, Player target) {
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("requester", sender.name()),
Placeholder.component("target", target.displayName())
);
if (sender instanceof Player player)
target.damage(100.0D, player);
target.setHealth(0.0D);
target.getWorld().strikeLightningEffect(target.getLocation());
sender.sendRichMessage(target == sender ? Config.SMITE_SELF : Config.SMITE_OTHER, placeholders);
if (target != sender)
target.sendRichMessage(Config.SMITE_BY_OTHER, placeholders);
}
public List<String> aliases() {
return List.of("kill");
}
}

View File

@ -0,0 +1,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);
}
}

View File

@ -0,0 +1,52 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.commands.EssentiaCommand;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class TeleportCommand implements EssentiaCommand {
@Override
public String commandName() {
return "teleport";
}
@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("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((Player) source.getSource().getSender(), target);
return 1;
})
);
return builder.build();
}
public void execute(Player sender, Player target) {
sender.teleport(target);
}
public List<String> aliases() {
return List.of("tp");
}
}

View File

@ -0,0 +1,52 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.commands.EssentiaCommand;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class TeleportHereCommand implements EssentiaCommand {
@Override
public String commandName() {
return "teleporthere";
}
@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("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((Player) source.getSource().getSender(), target);
return 1;
})
);
return builder.build();
}
public void execute(Player sender, Player target) {
target.teleport(sender);
}
public List<String> aliases() {
return List.of("tp", "tphere");
}
}

View File

@ -0,0 +1,69 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.commands.EssentiaCommand;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.BlockPositionResolver;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import io.papermc.paper.math.BlockPosition;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class TeleportPositionCommand implements EssentiaCommand {
@Override
public String commandName() {
return "teleportposition";
}
@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("pos", ArgumentTypes.blockPosition())
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
CommandSourceStack sourceStack = source.getSource();
BlockPosition position = source.getArgument("pos", BlockPositionResolver.class).resolve(sourceStack);
execute(player, player, position);
return 1;
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
BlockPosition position = source.getArgument("pos", BlockPositionResolver.class).resolve(sourceStack);
execute(player, target, position);
return 1;
})
)
);
return builder.build();
}
public void execute(Player sender, Player target, BlockPosition position) {
target.teleport(position.toLocation(target.getWorld()));
}
public List<String> aliases() {
return List.of("tppos");
}
}

View File

@ -0,0 +1,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);
}
}

View File

@ -0,0 +1,73 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.api.user.User;
import com.alttd.essentia.api.user.UserManager;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class UnCuffCommand implements EssentiaCommand {
@Override
public String commandName() {
return "uncuff";
}
@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();
}
public void execute(CommandSender sender, Player target) {
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("requester", sender.name()),
Placeholder.component("target", target.displayName())
);
UserManager userManager = EssentiaPlugin.instance().userManager();
if (!userManager.hasUser(target.getUniqueId())) {
return;
}
User user = userManager.getUser(target);
if (!user.isCuffed()) {
sender.sendRichMessage("<target> is not cuffed."); // TODO - CONFIG messages
return;
}
user.setCuffed(false);
// TODO - CONFIG messages
sender.sendRichMessage(target == sender ? Config.BURN_SELF : Config.BURN_OTHER, placeholders);
if (target != sender)
target.sendRichMessage(Config.BURN_BY_OTHER, placeholders);
}
}

View File

@ -0,0 +1,73 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
import com.mojang.brigadier.arguments.FloatArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class WalkSpeedCommand implements EssentiaCommand {
@Override
public String commandName() {
return "walkspeed";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
).then(
Commands.argument("speed", FloatArgumentType.floatArg(-1, 1))
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
Enchantment enchantment = source.getArgument("enchantment", Enchantment.class);
float speed = source.getArgument("speed", Float.class);
execute(source.getSource().getSender(), player, speed);
return 1;
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(adminOtherCommandPermission()))
.executes((source) -> {
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
float speed = source.getArgument("speed", Float.class);
execute(source.getSource().getSender(), target, speed);
return 1;
})
)
);
return builder.build();
}
public void execute(CommandSender sender, Player target, float speed) {
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("requester", sender.name()),
Placeholder.component("target", target.displayName())
);
target.setFlySpeed(speed);
// TODO - Config messages
sender.sendRichMessage(target == sender ? Config.FEED_SELF : Config.FEED_OTHER, placeholders);
if (target != sender)
target.sendRichMessage(Config.FEED_BY_OTHER, placeholders);
}
}

View File

@ -0,0 +1,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);
}
}

View File

@ -0,0 +1,68 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.commands.EssentiaCommand;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class WorkBenchCommand implements EssentiaCommand {
@Override
public String commandName() {
return "workbench";
}
@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("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();
}
public void execute(CommandSender sender, Player target) {
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("requester", sender.name()),
Placeholder.component("target", target.displayName())
);
target.openWorkbench(null, true);
// TODO - output config messages
}
@Override
public List<String> aliases() {
return List.of("craft", "craftingtable");
}
}

View File

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

View File

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

View File

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

View File

@ -0,0 +1,51 @@
package com.alttd.essentia.commands.argumement;
import com.alttd.essentia.api.model.MobData;
import com.alttd.essentia.commands.EssentiaArgument;
import com.mojang.brigadier.Message;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
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.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;
public class MobDataArgumentType implements CustomArgumentType.Converted<MobData, String>, EssentiaArgument {
@Override
public @NotNull MobData convert(String nativeType) throws CommandSyntaxException {
try {
return MobData.valueOf(nativeType.toUpperCase());
} catch (Exception e) {
Message message = MessageComponentSerializer.message().serialize(Component.text("Invalid mobdatatype %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 (MobData mobData : MobData.values()) {
possibleValues.add(mobData.name().toLowerCase());
}
return completedFuture(builder, possibleValues);
}
}

View File

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

View File

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

View File

@ -0,0 +1,50 @@
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.WeatherType;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;
public class WeatherArgument implements CustomArgumentType.Converted<WeatherType, String>, EssentiaArgument {
@Override
public @NotNull WeatherType convert(String nativeType) throws CommandSyntaxException {
try {
return WeatherType.valueOf(nativeType.toUpperCase());
} catch (Exception e) {
Message message = MessageComponentSerializer.message().serialize(Component.text("Invalid WeatherType %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 (WeatherType weatherType : WeatherType.values()) {
possibleValues.add(weatherType.name().toLowerCase());
}
return completedFuture(builder, possibleValues);
}
}

View File

@ -1,39 +1,65 @@
package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.commands.PlayerSubCommand;
import com.alttd.essentia.api.events.EssentiaEvent;
import com.alttd.essentia.api.events.player.PlayerTeleportBackEvent;
import com.alttd.essentia.api.user.User;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
import com.alttd.essentia.configuration.PlayerConfig;
import com.alttd.essentia.events.EssentiaEvent;
import com.alttd.essentia.events.PlayerTeleportBackEvent;
import com.alttd.essentia.tasks.TeleportSounds;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class BackCommand extends PlayerSubCommand {
public class BackCommand implements EssentiaCommand {
public BackCommand(EssentiaPlugin plugin) {
super(plugin, "back");
@Override
public String commandName() {
return "back";
}
@Override
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
Location back = playerConfig.getBackLocation(false);
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
execute(player, player);
if (back == null) {
player.sendRichMessage(Config.NO_BACK_LOCATION);
return true;
}
EssentiaEvent event = new PlayerTeleportBackEvent(player, back);
if (!event.callEvent()) {
return true;
}
new TeleportSounds(back, player.getLocation())
.runTaskLater(plugin, 1);
player.teleportAsync(back).thenAccept(result ->
player.sendRichMessage(Config.TELEPORTING_BACK));
return true;
return 1;
});
return builder.build();
}
public void execute(CommandSender sender, Player target) {
User user = EssentiaPlugin.instance().userManager().getUser(target);
if (user == null)
return;
Location back = user.getBackLocation(false);
if (back == null) {
target.sendRichMessage(Config.NO_BACK_LOCATION);
return;
}
EssentiaEvent event = new PlayerTeleportBackEvent(target, back);
if (!event.callEvent()) {
return;
}
new TeleportSounds(back, target.getLocation())
.runTaskLater(EssentiaPlugin.instance(), 1);
target.teleportAsync(back).thenAccept(result ->
target.sendRichMessage(Config.TELEPORTING_BACK));
}
}

View File

@ -1,39 +1,71 @@
package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.commands.PlayerSubCommand;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
import com.alttd.essentia.configuration.PlayerConfig;
import com.alttd.essentia.events.EssentiaEvent;
import com.alttd.essentia.events.PlayerTeleportBackEvent;
import com.alttd.essentia.api.events.EssentiaEvent;
import com.alttd.essentia.api.events.player.PlayerTeleportBackEvent;
import com.alttd.essentia.tasks.TeleportSounds;
import com.alttd.essentia.api.user.User;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class DeathBackCommand extends PlayerSubCommand {
import java.util.List;
public DeathBackCommand(EssentiaPlugin plugin) {
super(plugin, "back");
public class DeathBackCommand implements EssentiaCommand {
@Override
public String commandName() {
return "deathback";
}
@Override
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
Location back = playerConfig.getBackLocation(true);
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
execute(player, player);
return 1;
});
return builder.build();
}
public void execute(CommandSender sender, Player target) {
User user = EssentiaPlugin.instance().userManager().getUser(target);
if (user == null)
return;
Location back = user.getBackLocation(true);
if (back == null) {
player.sendRichMessage(Config.NO_DEATH_LOCATION);
return true;
target.sendRichMessage(Config.NO_DEATH_LOCATION);
return;
}
EssentiaEvent event = new PlayerTeleportBackEvent(player, back);
EssentiaEvent event = new PlayerTeleportBackEvent(target, back);
if (!event.callEvent()) {
return true;
return;
}
new TeleportSounds(back, player.getLocation())
.runTaskLater(plugin, 1);
new TeleportSounds(back, target.getLocation())
.runTaskLater(EssentiaPlugin.instance(), 1);
player.teleportAsync(back).thenAccept(result ->
player.sendRichMessage(Config.TELEPORTING_BACK_DEATH));
return true;
target.teleportAsync(back).thenAccept(result ->
target.sendRichMessage(Config.TELEPORTING_BACK_DEATH));
}
public List<String> aliases() {
return List.of("dback");
}
}

View File

@ -1,42 +1,153 @@
package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.commands.PlayerSubCommand;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.commands.argumement.OfflinePlayerArgument;
import com.alttd.essentia.configuration.Config;
import com.alttd.essentia.configuration.PlayerConfig;
import com.alttd.essentia.events.EssentiaEvent;
import com.alttd.essentia.events.PlayerRemoveHomeEvent;
import com.alttd.essentia.events.PlayerTeleportBackEvent;
import com.alttd.essentia.api.events.EssentiaEvent;
import com.alttd.essentia.api.events.player.PlayerRemoveHomeEvent;
import com.alttd.essentia.api.user.User;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class DelHomeCommand extends PlayerSubCommand {
import java.util.ArrayList;
import java.util.Collection;
public DelHomeCommand(EssentiaPlugin plugin) {
super(plugin, "deletehome");
public class DelHomeCommand implements EssentiaCommand {
@Override
public String commandName() {
return "delhome";
}
@Override
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
// TODO -- subcommand to remove other player homes
// if (args.length > 1) {
// if (!player.hasPermission("essentia.command.delhome.other")) {
// return true;
// }
// }
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
execute(player, player);
String home = (args.length > 0) ? args[0] : "home";
if (!playerConfig.hasHome(home)) {
player.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.unparsed("home", home));
return true;
return 1;
})
.then(
Commands.argument("home", StringArgumentType.word())
.suggests((context, suggestionsBuilder) -> {
if (!(context.getSource().getSender() instanceof Player player))
return Suggestions.empty();
User user = EssentiaPlugin.instance().userManager().getUser(player);
Collection<String> possibleValues = new ArrayList<>(user.getHomes());
if(possibleValues.isEmpty())
return Suggestions.empty();
String remaining = suggestionsBuilder.getRemaining().toLowerCase();
for (String str : possibleValues) {
if (str.toLowerCase().startsWith(remaining)) {
suggestionsBuilder.suggest(StringArgumentType.escapeIfRequired(str));
}
}
return suggestionsBuilder.buildFuture();
})
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
String home = source.getArgument("home", String.class);
execute(player, player, home);
return 1;
})
)
.then(
Commands.argument("player", new OfflinePlayerArgument())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
.then(
Commands.argument("home", StringArgumentType.word())
.suggests((context, suggestionsBuilder) -> {
if (!(context.getSource().getSender() instanceof Player))
return Suggestions.empty();
OfflinePlayer target = context.getArgument("player", OfflinePlayer.class);
User user = EssentiaPlugin.instance().userManager().getUser(target.getUniqueId());
if (user == null)
user = EssentiaPlugin.instance().storageProvider().loadUser(target.getUniqueId());
Collection<String> possibleValues = new ArrayList<>(user.getHomes());
if(possibleValues.isEmpty())
return Suggestions.empty();
String remaining = suggestionsBuilder.getRemaining().toLowerCase();
for (String str : possibleValues) {
if (str.toLowerCase().startsWith(remaining)) {
suggestionsBuilder.suggest(StringArgumentType.escapeIfRequired(str));
}
}
return suggestionsBuilder.buildFuture();
})
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
OfflinePlayer target = source.getArgument("player", OfflinePlayer.class);
String home = source.getArgument("home", String.class);
execute(player, target, home);
return 1;
})
)
);
return builder.build();
}
public void execute(Player sender, Player target) {
execute(sender, target, "home");
}
public void execute(Player sender, OfflinePlayer target, String home) {
User user = EssentiaPlugin.instance().userManager().getUser(target.getUniqueId());
if (user == null)
return;
user = EssentiaPlugin.instance().storageProvider().loadUser(target.getUniqueId());
delHome(sender, user, home);
}
public void execute(Player sender, Player target, String home) {
User user = EssentiaPlugin.instance().userManager().getUser(target);
if (user == null)
return;
delHome(sender, user, home);
}
private void delHome(Player sender, User user, String home) {
if (!user.hasHome(home)) {
sender.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.unparsed("home", home));
return;
}
EssentiaEvent event = new PlayerRemoveHomeEvent(player, home);
EssentiaEvent event = new PlayerRemoveHomeEvent(sender, home);
if (!event.callEvent()) {
return true;
return;
}
playerConfig.setHome(home, null);
player.sendRichMessage(Config.HOME_DELETED, Placeholder.unparsed("home", home));
return true;
user.setHome(home, null);
sender.sendRichMessage(Config.HOME_DELETED, Placeholder.unparsed("home", home));
}
}

View File

@ -0,0 +1,64 @@
package com.alttd.essentia.commands.player;
import com.alttd.essentia.commands.EssentiaCommand;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class DisposeCommand implements EssentiaCommand {
@Override
public String commandName() {
return "dispose";
}
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission())
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
execute(player, player);
return 1;
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
.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();
}
public void execute(CommandSender sender, Player target) {
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("requester", sender.name()),
Placeholder.component("target", target.displayName())
);
Inventory inventory = Bukkit.createInventory(null, 36, MiniMessage.miniMessage().deserialize("Item Disposal")); // TODO - config
// TODO - PlayerItemDisposeEvent
target.openInventory(inventory);
}
}

View File

@ -1,84 +1,111 @@
package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.commands.PlayerSubCommand;
import com.alttd.essentia.api.events.EssentiaEvent;
import com.alttd.essentia.api.events.player.PlayerTeleportHomeEvent;
import com.alttd.essentia.api.model.Home;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
import com.alttd.essentia.configuration.PlayerConfig;
import com.alttd.essentia.events.EssentiaEvent;
import com.alttd.essentia.events.PlayerTeleportBackEvent;
import com.alttd.essentia.events.PlayerTeleportHomeEvent;
import com.alttd.essentia.api.user.User;
import com.alttd.essentia.tasks.TeleportSounds;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.ArrayList;
import java.util.Collection;
public class HomeCommand extends PlayerSubCommand {
// TODO - home other
public class HomeCommand implements EssentiaCommand {
public HomeCommand(EssentiaPlugin plugin) {
super(plugin, "home");
@Override
public String commandName() {
return "home";
}
@Override
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
String home = null;
if (args.length == 0) {
int count = playerConfig.getHomeCount();
if (count == 0) {
if (player.getBedSpawnLocation() != null) {
home = "bed";
}
} else if (count == 1) {
home = playerConfig.getConfigurationSection("home").getKeys(false)
.stream().findFirst().orElse(null);
} else {
player.sendRichMessage(Config.SPECIFY_HOME, Placeholder.unparsed("homelist", String.join(", ", playerConfig.getHomeList())));
return true;
}
if (home == null || home.isEmpty()) {
player.sendRichMessage(Config.HOME_NOT_SET);
return true;
}
return true;
} else {
home = args[0];
}
// TODO - subcommand to teleport to others homes
// if (args.length > 1) {
// if (!player.hasPermission("essentia.command.home.other")) {
// return true
// }
// }
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
execute(player, player, "home");
Location homeLoc = home.equalsIgnoreCase("bed") ?
player.getBedSpawnLocation() : playerConfig.getHome(home);
return 1;
})
.then(
Commands.argument("name", StringArgumentType.word())
.suggests((context, suggestionsBuilder) -> {
if (!(context.getSource().getSender() instanceof Player player))
return Suggestions.empty();
User user = EssentiaPlugin.instance().userManager().getUser(player);
Collection<String> possibleValues = new ArrayList<>(user.getHomes());
if(possibleValues.isEmpty())
return Suggestions.empty();
String remaining = suggestionsBuilder.getRemaining().toLowerCase();
for (String str : possibleValues) {
if (str.toLowerCase().startsWith(remaining)) {
suggestionsBuilder.suggest(StringArgumentType.escapeIfRequired(str));
}
}
return suggestionsBuilder.buildFuture();
})
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
String name = source.getArgument("name", String.class);
execute(player, player, name);
return 1;
})
);
return builder.build();
}
public void execute(CommandSender sender, Player target, String home) {
User user = EssentiaPlugin.instance().userManager().getUser(target);
if (user == null)
return;
Home essentiaHome = user.getHome(home);
if (essentiaHome == null) {
sender.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.parsed("home", home));
return;
}
Location homeLoc = essentiaHome.location();
if (homeLoc == null) {
player.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.parsed("home", home));
return true;
sender.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.parsed("home", home));
sender.sendRichMessage(Config.SPECIFY_HOME, Placeholder.unparsed("homelist", String.join(", ", user.getHomes())));
return;
}
EssentiaEvent event = new PlayerTeleportHomeEvent(player, homeLoc, home);
EssentiaEvent event = new PlayerTeleportHomeEvent(target, homeLoc, home);
if (!event.callEvent()) {
return true;
return;
}
new TeleportSounds(homeLoc, player.getLocation())
.runTaskLater(plugin, 1);
new TeleportSounds(homeLoc, target.getLocation())
.runTaskLater(EssentiaPlugin.instance(), 1);
String homeName = home;
player.teleportAsync(homeLoc).thenAccept(result ->
player.sendRichMessage(Config.HOME_TELEPORT, Placeholder.unparsed("home", homeName))
target.teleportAsync(homeLoc).thenAccept(result ->
target.sendRichMessage(Config.HOME_TELEPORT, Placeholder.unparsed("home", home))
);
return true;
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
if (args.length == 1) {
return PlayerConfig.getConfig((Player) sender).getMatchingHomeNames(args[0]);
}
return null;
}
}

View File

@ -1,29 +1,68 @@
package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.commands.PlayerSubCommand;
import com.alttd.essentia.api.user.User;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.commands.argumement.OfflinePlayerCompletingArgument;
import com.alttd.essentia.configuration.Config;
import com.alttd.essentia.configuration.PlayerConfig;
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 org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class HomeListCommand extends PlayerSubCommand {
import java.util.List;
public HomeListCommand(EssentiaPlugin plugin) {
super(plugin, "homes");
public class HomeListCommand implements EssentiaCommand {
@Override
public String commandName() {
return "homelist";
}
@Override
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
// TODO - subcommand to list other homes
// if (args.length > 0) {
// if (!player.hasPermission("essentia.command.homes.other")) {
// return true;
// }
// }
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission())
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
execute(player, player);
return 1;
})
.then(
Commands.argument("player", new OfflinePlayerCompletingArgument())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
.executes((source) -> {
OfflinePlayer target = source.getArgument("player", OfflinePlayer.class);
execute(source.getSource().getSender(), target);
return 1;
})
);
return builder.build();
}
public void execute(CommandSender sender, OfflinePlayer target) {
User user = EssentiaPlugin.instance().userManager().getUser(target.getUniqueId());
if (user == null)
return;
user = EssentiaPlugin.instance().storageProvider().loadUser(target.getUniqueId());
// TODO - clickable homes that run /home <name>
player.sendRichMessage(Config.HOME_LIST, Placeholder.unparsed("homelist", String.join(", ", playerConfig.getHomeList())));
return true;
sender.sendRichMessage(Config.HOME_LIST, Placeholder.unparsed("homelist", String.join(", ", user.getHomes())));
}
public List<String> aliases() {
return List.of("homes");
}
}

View File

@ -1,51 +1,123 @@
package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.commands.PlayerSubCommand;
import com.alttd.essentia.api.events.EssentiaEvent;
import com.alttd.essentia.api.events.player.PlayerSetHomeEvent;
import com.alttd.essentia.api.user.User;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.commands.argumement.OfflinePlayerArgument;
import com.alttd.essentia.configuration.Config;
import com.alttd.essentia.configuration.PlayerConfig;
import com.alttd.essentia.events.EssentiaEvent;
import com.alttd.essentia.events.PlayerSetHomeEvent;
import com.alttd.essentia.events.PlayerTeleportHomeEvent;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class SetHomeCommand extends PlayerSubCommand {
public class SetHomeCommand implements EssentiaCommand {
public SetHomeCommand(EssentiaPlugin plugin) {
super(plugin, "sethome");
@Override
public String commandName() {
return "sethome";
}
@Override
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
// TODO -- subcommand to allow setting other player homes
// if (args.length > 1) {
// if (!player.hasPermission("essentia.command.sethome.other")) {
// return true;
// }
// }
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
execute(player, player);
String home = (args.length > 0) ? args[0] : "home";
if (home.equalsIgnoreCase("bed") || home.contains(".")) {
player.sendRichMessage(Config.INVALID_HOME_NAME);
return true;
return 1;
})
.then(
Commands.argument("name", StringArgumentType.word())
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
String name = source.getArgument("name", String.class);
execute(player, player, name);
return 1;
})
)
.then(
Commands.argument("player", new OfflinePlayerArgument())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
.then(
Commands.argument("name", StringArgumentType.word())
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
OfflinePlayer target = source.getArgument("player", OfflinePlayer.class);
String name = source.getArgument("name", String.class);
execute(player, target, name);
return 1;
})
)
);
return builder.build();
}
public void execute(Player sender, Player target) {
execute(sender, target, "home");
}
public void execute(Player sender, OfflinePlayer target, String home) {
User user = EssentiaPlugin.instance().userManager().getUser(target.getUniqueId());
if (user == null)
return;
user = EssentiaPlugin.instance().storageProvider().loadUser(target.getUniqueId());
setHome(sender, user, home);
}
public void execute(Player sender, Player target, String home) {
User user = EssentiaPlugin.instance().userManager().getUser(target);
if (user == null)
return;
setHome(sender, user, home);
}
private void setHome(Player sender, User user, String home) {
if (home.contains(".")) {
sender.sendRichMessage(Config.INVALID_HOME_NAME);
return;
}
if (user.hasHome(home)) {
sender.sendRichMessage("<home> already exists.", Placeholder.unparsed("home", home)); // TODO -- CONFIG
return;
}
int limit = 5; // TODO -- player home limits hardcoded for now
int count = playerConfig.getHomeCount();
int count = user.getHomeCount();
if (limit >= 0 && count >= limit) {
player.sendRichMessage(Config.HOME_SET_MAX, Placeholder.unparsed("limit", String.valueOf(limit)));
return true;
sender.sendRichMessage(Config.HOME_SET_MAX, Placeholder.unparsed("limit", String.valueOf(limit)));
return;
}
Location homeLoc = player.getLocation();
EssentiaEvent event = new PlayerSetHomeEvent(player, homeLoc, home);
Location homeLoc = sender.getLocation();
EssentiaEvent event = new PlayerSetHomeEvent(sender, homeLoc, home);
if (!event.callEvent()) {
return true;
return;
}
playerConfig.setHome(home, homeLoc);
player.sendRichMessage(Config.HOME_SET, Placeholder.unparsed("home", home));
return true;
user.setHome(home, homeLoc);
sender.sendRichMessage(Config.HOME_SET, Placeholder.unparsed("home", home));
}
}

View File

@ -1,41 +1,78 @@
package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.commands.PlayerSubCommand;
import com.alttd.essentia.api.events.player.PlayerTeleportSpawnEvent;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
import com.alttd.essentia.configuration.PlayerConfig;
import com.alttd.essentia.events.EssentiaEvent;
import com.alttd.essentia.events.PlayerSetHomeEvent;
import com.alttd.essentia.events.PlayerTeleportSpawnEvent;
import com.alttd.essentia.api.events.EssentiaEvent;
import com.alttd.essentia.tasks.TeleportSounds;
import com.alttd.essentia.api.user.User;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class SpawnCommand extends PlayerSubCommand {
public class SpawnCommand implements EssentiaCommand {
public SpawnCommand(EssentiaPlugin plugin) {
super(plugin, "back");
@Override
public String commandName() {
return "spawn";
}
@Override
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
World world = plugin.getServer().getWorld(Config.SPAWN_WORLD);
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission())
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
execute(player, player);
return 1;
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
.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();
}
public void execute(CommandSender sender, Player target) {
User user = EssentiaPlugin.instance().userManager().getUser(target);
if (user == null)
return;
World world = EssentiaPlugin.instance().getServer().getWorld(Config.SPAWN_WORLD);
if (world == null) {
player.sendRichMessage("<red>Could not get the configured spawn world! contact and administrator");
return true;
sender.sendRichMessage("<red>Could not get the configured spawn world! contact an administrator");
return;
}
Location spawnLocation = world.getSpawnLocation();
EssentiaEvent event = new PlayerTeleportSpawnEvent(player, spawnLocation);
EssentiaEvent event = new PlayerTeleportSpawnEvent(target, spawnLocation);
if (!event.callEvent()) {
return true;
return;
}
new TeleportSounds(spawnLocation, player.getLocation())
.runTaskLater(plugin, 1);
new TeleportSounds(spawnLocation, target.getLocation())
.runTaskLater(EssentiaPlugin.instance(), 1);
player.teleportAsync(spawnLocation).thenAccept(result ->
player.sendRichMessage("Teleporting to spawn"));
return true;
target.teleportAsync(spawnLocation).thenAccept(result ->
target.sendRichMessage("Teleporting to spawn"));
}
}

View File

@ -1,27 +1,60 @@
package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.commands.PlayerSubCommand;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
import com.alttd.essentia.configuration.PlayerConfig;
import com.alttd.essentia.request.Request;
import com.alttd.essentia.api.request.Request;
import com.alttd.essentia.api.user.User;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class TeleportAcceptCommand extends PlayerSubCommand {
import java.util.List;
public TeleportAcceptCommand(EssentiaPlugin plugin) {
super(plugin, "teleportaccept");
public class TeleportAcceptCommand implements EssentiaCommand {
@Override
public String commandName() {
return "teleportaccept";
}
@Override
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
Request request = playerConfig.request();
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
execute(player, player);
return 1;
});
return builder.build();
}
public void execute(Player player, Player target) {
User user = EssentiaPlugin.instance().userManager().getUser(target);
if (user == null)
return;
Request request = user.request();
if (request == null) {
player.sendRichMessage(Config.NO_PENDING_REQUESTS);
return true;
return;
}
request.accept();
return true;
}
@Override
public List<String> aliases() {
return List.of("tpyes", "tpaccpt");
}
}

View File

@ -1,27 +1,60 @@
package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.commands.PlayerSubCommand;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
import com.alttd.essentia.configuration.PlayerConfig;
import com.alttd.essentia.request.Request;
import com.alttd.essentia.api.request.Request;
import com.alttd.essentia.api.user.User;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class TeleportDenyCommand extends PlayerSubCommand {
import java.util.List;
public TeleportDenyCommand(EssentiaPlugin plugin) {
super(plugin, "teleportdeny");
public class TeleportDenyCommand implements EssentiaCommand {
@Override
public String commandName() {
return "teleportdeny";
}
@Override
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
Request request = playerConfig.request();
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
execute(player, player);
return 1;
});
return builder.build();
}
public void execute(Player player, Player target) {
User user = EssentiaPlugin.instance().userManager().getUser(target);
if (user == null)
return;
Request request = user.request();
if (request == null) {
player.sendRichMessage(Config.NO_PENDING_REQUESTS);
return true;
return;
}
request.deny();
return true;
}
@Override
public List<String> aliases() {
return List.of("tpdeny", "tpno");
}
}

View File

@ -1,72 +1,87 @@
package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.commands.PlayerSubCommand;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
import com.alttd.essentia.configuration.PlayerConfig;
import com.alttd.essentia.request.TeleportRequest;
import com.alttd.essentia.request.TeleportEssentiaRequest;
import com.alttd.essentia.api.user.User;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.stream.Collectors;
public class TeleportRequestCommand extends PlayerSubCommand {
public class TeleportRequestCommand implements EssentiaCommand {
public TeleportRequestCommand(EssentiaPlugin plugin) {
super(plugin, "teleportrequest");
@Override
public String commandName() {
return "teleportrequesthere";
}
@Override
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
if (args.length < 1) {
player.sendRichMessage(Config.NO_PLAYER_SPECIFIED);
return true;
}
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
Player target = Bukkit.getPlayer(args[0]);
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
execute(player, target);
return 1;
})
);
return builder.build();
}
public void execute(Player player, Player target) {
if (target == null) {
player.sendRichMessage(Config.PLAYER_NOT_ONLINE);
return true;
return;
}
if (target == player) {
player.sendRichMessage(Config.REQUEST_TO_SELF);
return true;
return;
}
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("target", target.displayName())
);
PlayerConfig targetConfig = PlayerConfig.getConfig(target);
if (targetConfig.request() != null) {
User targetUser = EssentiaPlugin.instance().userManager().getUser(target);
if (targetUser.request() != null) {
player.sendRichMessage(Config.TARGET_HAS_PENDING_REQUEST, placeholders);
return true;
return;
}
if (!targetConfig.allowTeleports()) {
if (!targetUser.getUserSettings().allowTeleports()) {
player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders);
return true;
return;
}
targetConfig.request(new TeleportRequest(plugin, player, target));
return true;
targetUser.request(new TeleportEssentiaRequest(EssentiaPlugin.instance(), player, target));
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
if (args.length == 1) {
String name = args[0].trim().toLowerCase();
return Bukkit.getOnlinePlayers().stream()
.map(Player::getName)
.filter(playerName -> playerName.toLowerCase().startsWith(name)).collect(Collectors.toList());
}
return null;
public List<String> aliases() {
return List.of("tpa");
}
}

View File

@ -1,73 +1,87 @@
package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.commands.PlayerSubCommand;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
import com.alttd.essentia.configuration.PlayerConfig;
import com.alttd.essentia.request.TeleportHereRequest;
import com.alttd.essentia.request.TeleportRequest;
import com.alttd.essentia.api.user.User;
import com.alttd.essentia.request.TeleportHereEssentiaRequest;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.stream.Collectors;
public class TeleportRequestHereCommand extends PlayerSubCommand {
public class TeleportRequestHereCommand implements EssentiaCommand {
public TeleportRequestHereCommand(EssentiaPlugin plugin) {
super(plugin, "teleportrequesthere");
@Override
public String commandName() {
return "teleportrequesthere";
}
@Override
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
if (args.length < 1) {
player.sendRichMessage(Config.NO_PLAYER_SPECIFIED);
return true;
}
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission()) &&
commandSourceStack.getSender() instanceof Player
)
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;
Player target = Bukkit.getPlayer(args[0]);
CommandSourceStack sourceStack = source.getSource();
Player target = source.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
execute(player, target);
return 1;
})
);
return builder.build();
}
public void execute(Player player, Player target) {
if (target == null) {
player.sendRichMessage(Config.PLAYER_NOT_ONLINE);
return true;
return;
}
if (target == player) {
player.sendRichMessage(Config.REQUEST_TO_SELF);
return true;
return;
}
TagResolver placeholders = TagResolver.resolver(
Placeholder.component("target", target.displayName())
);
PlayerConfig targetConfig = PlayerConfig.getConfig(target);
if (targetConfig.request() != null) {
User targetUser = EssentiaPlugin.instance().userManager().getUser(target);
if (targetUser.request() != null) {
player.sendRichMessage(Config.TARGET_HAS_PENDING_REQUEST, placeholders);
return true;
return;
}
if (!targetConfig.allowTeleports()) {
if (!targetUser.getUserSettings().allowTeleports()) {
player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders);
return true;
return;
}
targetConfig.request(new TeleportHereRequest(plugin, player, target));
return true;
targetUser.request(new TeleportHereEssentiaRequest(EssentiaPlugin.instance(), player, target));
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
if (args.length == 1) {
String name = args[0].trim().toLowerCase();
return Bukkit.getOnlinePlayers().stream()
.map(Player::getName)
.filter(playerName -> playerName.toLowerCase().startsWith(name)).collect(Collectors.toList());
}
return null;
public List<String> aliases() {
return List.of("tpahere", "tphere");
}
}

View File

@ -1,27 +1,73 @@
package com.alttd.essentia.commands.player;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.commands.PlayerSubCommand;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
import com.alttd.essentia.configuration.PlayerConfig;
import com.alttd.essentia.api.user.User;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.apache.commons.lang3.BooleanUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class TeleportToggleCommand extends PlayerSubCommand {
import java.util.List;
public TeleportToggleCommand(EssentiaPlugin plugin) {
super(plugin, "teleporttoggle");
public class TeleportToggleCommand implements EssentiaCommand {
@Override
public String commandName() {
return "teleporttoggle";
}
@Override
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
playerConfig.setAllowTeleports(!playerConfig.allowTeleports());
TagResolver placeholders = TagResolver.resolver(
Placeholder.parsed("toggle", BooleanUtils.toStringOnOff(playerConfig.allowTeleports()))
);
player.sendRichMessage(Config.TELEPORT_TOGGLE_SET, placeholders);
return true;
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName())
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission(baseCommandPermission())
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
execute(player, player);
return 1;
})
.then(
Commands.argument("player", ArgumentTypes.player())
.requires(commandSourceStack -> commandSourceStack.getSender().hasPermission(baseOtherCommandPermission()))
.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();
}
public void execute(CommandSender sender, Player target) {
User user = EssentiaPlugin.instance().userManager().getUser(target);
if (user == null)
return;
user.getUserSettings().allowTeleports(!user.getUserSettings().allowTeleports());
TagResolver placeholders = TagResolver.resolver(
Placeholder.parsed("toggle", BooleanUtils.toStringOnOff(user.getUserSettings().allowTeleports()))
);
sender.sendRichMessage(Config.TELEPORT_TOGGLE_SET, placeholders);
}
@Override
public List<String> aliases() {
return List.of("tptoggle");
}
}

View File

@ -2,7 +2,8 @@ package com.alttd.essentia.configuration;
import com.alttd.essentia.EssentiaPlugin;
import com.google.common.base.Throwables;
import org.bukkit.Bukkit;
import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
import org.bukkit.Sound;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
@ -35,7 +36,7 @@ public class Config {
config.load(CONFIG_FILE);
} catch (IOException ignore) {
} catch (InvalidConfigurationException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Could not load config.yml, please correct your syntax errors", ex);
log(Level.SEVERE, "Could not load config.yml, please correct your syntax errors", ex);
Throwables.throwIfUnchecked(ex);
}
config.options().header(HEADER);
@ -44,6 +45,7 @@ public class Config {
version = getInt("config-version", 1);
set("config-version", 1);
log(Level.INFO,"Essentia Configuration loaded!");
readConfig(Config.class, null);
}
@ -57,7 +59,7 @@ public class Config {
} catch (InvocationTargetException ex) {
Throwables.throwIfUnchecked(ex);
} catch (Exception ex) {
Bukkit.getLogger().log(Level.SEVERE, "Error invoking " + method, ex);
log(Level.SEVERE, "Error invoking " + method, ex);
}
}
}
@ -65,11 +67,11 @@ public class Config {
saveConfig();
}
static void saveConfig() {
public static void saveConfig() {
try {
config.save(CONFIG_FILE);
} catch (IOException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Could not save " + CONFIG_FILE, ex);
log(Level.SEVERE, "Could not save " + CONFIG_FILE, ex);
}
}
@ -104,7 +106,11 @@ public class Config {
}
protected static void log(Level level, String s) {
Bukkit.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;
@ -171,6 +177,9 @@ public class Config {
public static String TOGGLED_FLIGHT_BY_OTHER = "Toggled flight <status> on <target>.";
public static String TOGGLED_FLIGHT_PLAYER = "<player> toggled flight <status>.";
public static String TOGGLED_FLIGHT = "Toggled fly <status>.";
public static String TOGGLED_GOD_BY_OTHER = "Toggled God mode <status> on <target>.";
public static String TOGGLED_GOD_PLAYER = "<player> toggled God mode <status>.";
public static String TOGGLED_GOD = "Toggled God mode <status>.";
public static String NO_BACK_LOCATION = "No back location found!";
public static String TELEPORTING_BACK = "Teleporting back to previous location.";
public static String NO_DEATH_LOCATION = "No death location found!";
@ -187,6 +196,14 @@ public class Config {
public static String FEED_SELF = "You just fed yourself.";
public static String FEED_OTHER = "You have fed <target>.";
public static String FEED_BY_OTHER = "<requester> has fed you.";
public static String BURN_SELF = "You have set yourself on fire.";
public static String BURN_OTHER = "<target>'s has been set in fire.";
public static String BURN_BY_OTHER = "<requester> has set you on fire.";
public static String SMITE_SELF = "You have smited yourself.";
public static String SMITE_OTHER = "<target> has been smited.";
public static String SMITE_BY_OTHER = "<requester> has smited you.";
private static void messages() {
REQUEST_TIMED_OUT = getString("messages.request.time-out", REQUEST_TIMED_OUT);
TELEPORT_ACCEPT_TARGET = getString("messages.request.teleport-accept-target", TELEPORT_ACCEPT_TARGET);
@ -203,39 +220,66 @@ public class Config {
PLAYER_ONLY_COMMAND = getString("messages.command.player-only-command", PLAYER_ONLY_COMMAND);
NO_PLAYER_SPECIFIED = getString("messages.command.no-player-specified", NO_PLAYER_SPECIFIED);
PLAYER_NOT_FOUND = config.getString("messages.command.player-not-found", PLAYER_NOT_FOUND);
PLAYER_NOT_ONLINE = config.getString("messages.command.player-not-online", PLAYER_NOT_ONLINE);
COMMAND_NO_PERMISSION = config.getString("messages.command.no-permission", COMMAND_NO_PERMISSION);
PLAYER_INVENTORY_CLEARED = config.getString("messages.command.clear-inventory.player-inventory-cleared", PLAYER_INVENTORY_CLEARED);
INVENTORY_CLEARED_BY_OTHER = config.getString("messages.command.clear-inventory.inventory-clear-by-other", INVENTORY_CLEARED_BY_OTHER);
INVENTORY_CLEARED = config.getString("messages.command.clear-inventory.inventory-cleared", INVENTORY_CLEARED);
SPECIFY_HOME = config.getString("messages.command.home.specify-home", SPECIFY_HOME);
HOME_NOT_SET = config.getString("messages.command.home.home-not-set", HOME_NOT_SET);
HOME_DOES_NOT_EXIST = config.getString("messages.command.home.home-does-not-exist", HOME_DOES_NOT_EXIST);
HOME_TELEPORT = config.getString("messages.command.home.home-teleport", HOME_TELEPORT);
HOME_LIST = config.getString("messages.command.home.home-list", HOME_LIST);
HOME_SET = config.getString("messages.command.home.home-set", HOME_SET);
HOME_SET_MAX = config.getString("messages.command.home.home-set-max", HOME_SET_MAX);
INVALID_HOME_NAME = config.getString("messages.command.home.invalid-home-name", INVALID_HOME_NAME);
HOME_DELETED = config.getString("messages.command.home.invalid-home-name", HOME_DELETED);
PLAYER_NOT_FOUND = getString("messages.command.player-not-found", PLAYER_NOT_FOUND);
PLAYER_NOT_ONLINE = getString("messages.command.player-not-online", PLAYER_NOT_ONLINE);
COMMAND_NO_PERMISSION = getString("messages.command.no-permission", COMMAND_NO_PERMISSION);
PLAYER_INVENTORY_CLEARED = getString("messages.command.clear-inventory.player-inventory-cleared", PLAYER_INVENTORY_CLEARED);
INVENTORY_CLEARED_BY_OTHER = getString("messages.command.clear-inventory.inventory-clear-by-other", INVENTORY_CLEARED_BY_OTHER);
INVENTORY_CLEARED = getString("messages.command.clear-inventory.inventory-cleared", INVENTORY_CLEARED);
SPECIFY_HOME = getString("messages.command.home.specify-home", SPECIFY_HOME);
HOME_NOT_SET = getString("messages.command.home.home-not-set", HOME_NOT_SET);
HOME_DOES_NOT_EXIST = getString("messages.command.home.home-does-not-exist", HOME_DOES_NOT_EXIST);
HOME_TELEPORT = getString("messages.command.home.home-teleport", HOME_TELEPORT);
HOME_LIST = getString("messages.command.home.home-list", HOME_LIST);
HOME_SET = getString("messages.command.home.home-set", HOME_SET);
HOME_SET_MAX = getString("messages.command.home.home-set-max", HOME_SET_MAX);
INVALID_HOME_NAME = getString("messages.command.home.invalid-home-name", INVALID_HOME_NAME);
HOME_DELETED = getString("messages.command.home.invalid-home-name", HOME_DELETED);
TOGGLED_FLIGHT_BY_OTHER = config.getString("messages.command.fly.toggled-by-other", TOGGLED_FLIGHT_BY_OTHER);
TOGGLED_FLIGHT_PLAYER = config.getString("messages.command.fly.toggled-flight-other", TOGGLED_FLIGHT_PLAYER);
TOGGLED_FLIGHT = config.getString("messages.command.fly.toggled-flight", TOGGLED_FLIGHT);
NO_BACK_LOCATION = config.getString("messages.command.back.no-back-location", NO_BACK_LOCATION);
TELEPORTING_BACK = config.getString("messages.command.back.teleporting-back", TELEPORTING_BACK);
NO_DEATH_LOCATION = config.getString("messages.command.back.no-death-location", NO_DEATH_LOCATION);
TELEPORTING_BACK_DEATH = config.getString("messages.command.back.teleporting-back-death", TELEPORTING_BACK_DEATH);
BACK_DEATH_HINT = config.getString("messages.command.back.dback-hint", BACK_DEATH_HINT);
GAMEMODE_SET = config.getString("messages.command.gamemode.gamemode-set", GAMEMODE_SET);
GAMEMODE_SET_OTHER = config.getString("messages.command.gamemode.gamemode-set-other", GAMEMODE_SET_OTHER);
GAMEMODE_SET_BY_OTHER = config.getString("messages.command.gamemode.gamemode-set-by-other", GAMEMODE_SET_BY_OTHER);
HEAL_SELF = config.getString("messages.command.heal.heal-self", HEAL_SELF);
HEAL_OTHER = config.getString("messages.command.heal.heal-other", HEAL_OTHER);
HEAL_BY_OTHER = config.getString("messages.command.heal.heal-by-other", HEAL_BY_OTHER);
FEED_SELF = config.getString("messages.command.feed.feed-self", FEED_SELF);
FEED_OTHER = config.getString("messages.command.feed.feed-other", FEED_OTHER);
FEED_BY_OTHER = config.getString("messages.command.feed.feed-by-other", FEED_BY_OTHER);
TOGGLED_FLIGHT_BY_OTHER = getString("messages.command.fly.toggled-by-other", TOGGLED_FLIGHT_BY_OTHER);
TOGGLED_FLIGHT_PLAYER = getString("messages.command.fly.toggled-flight-other", TOGGLED_FLIGHT_PLAYER);
TOGGLED_FLIGHT = getString("messages.command.fly.toggled-flight", TOGGLED_FLIGHT);
NO_BACK_LOCATION = getString("messages.command.back.no-back-location", NO_BACK_LOCATION);
TELEPORTING_BACK = getString("messages.command.back.teleporting-back", TELEPORTING_BACK);
NO_DEATH_LOCATION = getString("messages.command.back.no-death-location", NO_DEATH_LOCATION);
TELEPORTING_BACK_DEATH = getString("messages.command.back.teleporting-back-death", TELEPORTING_BACK_DEATH);
BACK_DEATH_HINT = getString("messages.command.back.dback-hint", BACK_DEATH_HINT);
GAMEMODE_SET = getString("messages.command.gamemode.gamemode-set", GAMEMODE_SET);
GAMEMODE_SET_OTHER = getString("messages.command.gamemode.gamemode-set-other", GAMEMODE_SET_OTHER);
GAMEMODE_SET_BY_OTHER = getString("messages.command.gamemode.gamemode-set-by-other", GAMEMODE_SET_BY_OTHER);
HEAL_SELF = getString("messages.command.heal.heal-self", HEAL_SELF);
HEAL_OTHER = getString("messages.command.heal.heal-other", HEAL_OTHER);
HEAL_BY_OTHER = getString("messages.command.heal.heal-by-other", HEAL_BY_OTHER);
FEED_SELF = getString("messages.command.feed.feed-self", FEED_SELF);
FEED_OTHER = getString("messages.command.feed.feed-other", FEED_OTHER);
FEED_BY_OTHER = getString("messages.command.feed.feed-by-other", FEED_BY_OTHER);
}
public static String STORAGE_TYPE = "YAML";
public static boolean AUTO_SAVE = true;
public static int AUTO_SAVE_DELAY = 60;
public static String MYSQL_IP = "localhost";
public static String MYSQL_PORT = "3306";
public static String MYSQL_DATABASE_NAME = "essentia";
public static String MYSQL_USERNAME = "root";
public static String MYSQL_PASSWORD = "root";
public static int MYSQL_CONNECTIONS = 10;
public static int MYSQL_QUEUE_DELAY = 5;
private static void storage() {
STORAGE_TYPE = getString("storage.type", STORAGE_TYPE);
AUTO_SAVE = getBoolean("storage.auto-save", AUTO_SAVE);
AUTO_SAVE_DELAY = getInt("storaeg.auto-save-delay", AUTO_SAVE_DELAY);
MYSQL_IP = getString("storage.mysql.ip", MYSQL_IP);
MYSQL_PORT = getString("storage.mysql.port", MYSQL_PORT);
MYSQL_DATABASE_NAME = getString("storage.mysql.database", MYSQL_DATABASE_NAME);
MYSQL_USERNAME = getString("storage.mysql.username", MYSQL_USERNAME);
MYSQL_PASSWORD = getString("storage.mysql.password", MYSQL_PASSWORD);
}
public static Object2BooleanMap<String> enabledFeatures = new Object2BooleanOpenHashMap<>();
private static void features() {
enabledFeatures.clear();
enabledFeatures.defaultReturnValue(true);
}
}

View File

@ -1,186 +0,0 @@
package com.alttd.essentia.configuration;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.request.Request;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class PlayerConfig extends YamlConfiguration {
private static final Map<Player, PlayerConfig> configs = new HashMap<>();
public static PlayerConfig getConfig(Player player) {
synchronized (configs) {
return configs.computeIfAbsent(player, k -> new PlayerConfig(player));
}
}
public static void remove(Player player) {
synchronized (configs) {
configs.remove(player);
}
}
public static void removeAll() {
synchronized (configs) {
configs.clear();
}
}
private final File file;
private final Object saveLock = new Object();
private final OfflinePlayer player;
@Getter @Setter private Request request;
private PlayerConfig(Player player) {
super();
this.player = player;
this.file = new File(EssentiaPlugin.instance().getDataFolder(), "PlayerData" + File.separator + player.getUniqueId() + ".yml");
reload();
}
private void reload() {
synchronized (saveLock) {
try {
load(file);
} catch (Exception ignore) {
}
}
}
private void save() {
synchronized (saveLock) {
try {
save(file);
} catch (Exception ignore) {
}
}
}
Location getStoredLocation(String path) {
if (get(path) == null) {
return null;
}
World world = Bukkit.getWorld(getString(path + ".world", ""));
if (world == null) {
return null;
}
double x = getDouble(path + ".x");
double y = getDouble(path + ".y");
double z = getDouble(path + ".z");
float pitch = (float) getDouble(path + ".pitch");
float yaw = (float) getDouble(path + ".yaw");
return new Location(world, x, y, z, yaw, pitch);
}
void setStoredLocation(String path, Location location) {
if (location == null) {
set(path, null);
save();
return;
}
set(path + ".world", location.getWorld().getName());
set(path + ".x", location.getX());
set(path + ".y", location.getY());
set(path + ".z", location.getZ());
set(path + ".pitch", location.getPitch());
set(path + ".yaw", location.getYaw());
save();
}
public Location getBackLocation(boolean death) {
return getStoredLocation(death ? "teleports.death" : "teleports.back");
}
public void setBackLocation(boolean death, Location location) {
setStoredLocation(death ? "teleports.death" : "teleports.back", location);
}
public boolean hasHome(String name) {
ConfigurationSection section = getConfigurationSection("home." + name);
return section != null;
}
public Location getHome(String name) {
return getStoredLocation("home." + name);
}
public void setHome(String name, Location location) {
setStoredLocation("home." + name, location);
}
public int getHomeCount() {
ConfigurationSection section = getConfigurationSection("home");
if (section == null) {
return 0;
}
return section.getKeys(false).size();
}
public List<String> getMatchingHomeNames(String name) {
ConfigurationSection section = getConfigurationSection("home");
if (section == null) {
return null;
}
List<String> list = section.getValues(false).keySet().stream()
.filter(home -> home.toLowerCase().startsWith(name.toLowerCase()))
.collect(Collectors.toList());
if (player.getBedSpawnLocation() != null && "bed".startsWith(name.toLowerCase()))
list.add("bed");
return list;
}
public Map<String, Location> getHomeData() {
ConfigurationSection section = getConfigurationSection("home");
if (section == null) {
return null;
}
Map<String, Location> map = new HashMap<>();
for (String key : section.getValues(false).keySet()) {
map.put(key, getHome(key));
}
if (player.getBedSpawnLocation() != null)
map.put("bed", player.getBedSpawnLocation());
return map;
}
public List<String> getHomeList() {
ConfigurationSection section = getConfigurationSection("home");
if (section == null) {
return null;
}
List<String> list = new ArrayList<>(section.getValues(false).keySet());
if (player.getBedSpawnLocation() != null)
list.add("bed");
return list;
}
public boolean allowTeleports() {
return getBoolean("allow-teleports", true);
}
public void setAllowTeleports(boolean allowTeleports) {
set("allow-teleports", allowTeleports);
save();
}
}

View File

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

View File

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

View File

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

View File

@ -0,0 +1,130 @@
package com.alttd.essentia.feature.cuff;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.api.user.User;
import com.alttd.essentia.api.user.UserManager;
import io.papermc.paper.event.player.AsyncChatEvent;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.*;
public class CuffListener implements Listener {
private final EssentiaPlugin plugin;
public CuffListener() {
this.plugin = EssentiaPlugin.instance();
}
private boolean isNotCuffed(Player player) {
UserManager userManager = plugin.userManager();
User user = userManager.getUser(player);
if (user == null)
return true;
return !user.isCuffed();
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (isNotCuffed(event.getPlayer()))
return;
cancelEvent(event, event.getPlayer());
}
@EventHandler
public void onAsyncPlayerChat(AsyncChatEvent event) {
if (isNotCuffed(event.getPlayer()))
return;
// TODO
// if (!Config.TALKWHILECUFFED)
// return;
cancelEvent(event, event.getPlayer());
}
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
if (!(event.getWhoClicked() instanceof Player player))
return;
if (isNotCuffed(player))
return;
cancelEvent(event, player);
}
@EventHandler
public void onPlayerDropItemEvent(PlayerDropItemEvent event) {
if (isNotCuffed(event.getPlayer()))
return;
cancelEvent(event, event.getPlayer());
}
@EventHandler
public void onProjectileLaunchEvent(ProjectileLaunchEvent event) {
if (!(event.getEntity().getShooter() instanceof Player player))
return;
if (isNotCuffed(player))
return;
cancelEvent(event, player);
}
@EventHandler
public void onnEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player player))
return;
if (isNotCuffed(player))
return;
cancelEvent(event, player);
}
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
if (!(event.getEntity() instanceof Player player))
return;
if (isNotCuffed(player))
return;
cancelEvent(event, player);
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
if (isNotCuffed(player))
return;
Location from = event.getFrom();
Location to = event.getTo();
if (from.getBlockY() < to.getBlockY() && player.isFlying()) {
cancelEvent(event, player);
return;
}
if (from.getWorld() != to.getWorld() || from.getBlockX() != to.getBlockX() || from.getBlockZ() != to.getBlockZ()) {
cancelEvent(event, player);
}
}
void cancelEvent(Cancellable event, Player player) {
event.setCancelled(true);
player.sendRichMessage("You can not do this while cuffed."); // TODO - config
}
}

View File

@ -0,0 +1,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;
}
}

View File

@ -0,0 +1,33 @@
package com.alttd.essentia.feature.flight;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.api.model.UserSettings;
import com.alttd.essentia.api.user.User;
import com.alttd.essentia.api.user.UserManager;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
// TODO -- set flight and flying when player logs in!
public class FlightListener implements Listener {
private final EssentiaPlugin plugin;
public FlightListener() {
this.plugin = EssentiaPlugin.instance();
}
@EventHandler
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
Player player = event.getPlayer();
UserManager userManager = plugin.userManager();
User user = userManager.getUser(player);
if (user == null)
return;
UserSettings userSettings = user.getUserSettings();
if (userSettings.flying())
player.setFlying(true);
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,4 @@
package com.alttd.essentia.feature.savedinventory;
public class SavedInventoryFeature {
}

View File

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

View File

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

View File

@ -2,12 +2,16 @@ package com.alttd.essentia.listeners;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.configuration.Config;
import com.alttd.essentia.configuration.PlayerConfig;
import com.alttd.essentia.user.EssentiaUser;
import com.alttd.essentia.api.user.User;
import com.alttd.essentia.api.user.UserManager;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import java.util.HashSet;
@ -15,11 +19,11 @@ import java.util.Set;
public class PlayerListener implements Listener {
private EssentiaPlugin plugin;
private final EssentiaPlugin plugin;
private final Set<PlayerTeleportEvent.TeleportCause> backAllowCauses = new HashSet<>();
public PlayerListener(EssentiaPlugin plugin) {
this.plugin = plugin;
public PlayerListener() {
this.plugin = EssentiaPlugin.instance();
backAllowCauses.add(PlayerTeleportEvent.TeleportCause.PLUGIN);
backAllowCauses.add(PlayerTeleportEvent.TeleportCause.COMMAND);
@ -36,8 +40,8 @@ public class PlayerListener implements Listener {
return;
}
PlayerConfig playerConfig = PlayerConfig.getConfig(player);
playerConfig.setBackLocation(true, player.getLocation());
User user = plugin.userManager().getUser(player);
user.setBackLocation(true, player.getLocation());
player.sendRichMessage(Config.BACK_DEATH_HINT);
}
@ -57,7 +61,33 @@ public class PlayerListener implements Listener {
// only save location if teleporting more than 5 blocks
if (!to.getWorld().equals(from.getWorld()) || to.distanceSquared(from) > 25) {
PlayerConfig.getConfig(player).setBackLocation(false, event.getFrom());
User user = plugin.userManager().getUser(player);
user.setBackLocation(false, event.getFrom());
}
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
if (plugin.userManager().hasUser(player.getUniqueId()))
return;
plugin.storageProvider().loadUser(player.getUniqueId());
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
UserManager userManager = plugin.userManager();
if (!userManager.hasUser(player.getUniqueId())) {
return;
}
User user = userManager.getUser(player);
try {
if (user instanceof EssentiaUser essentiaUser)
plugin.storageProvider().save(essentiaUser);
userManager.removeUser(player.getUniqueId());
} catch (Exception ignored) {}
}
}

View File

@ -0,0 +1,5 @@
package com.alttd.essentia.model;
import org.bukkit.Location;
public record EssentiaHome(String name, Location location) implements com.alttd.essentia.api.model.Home {}

View File

@ -0,0 +1,98 @@
package com.alttd.essentia.model;
import com.alttd.essentia.api.model.UserSettings;
import lombok.Getter;
@Getter
public class EssentiaUserSettings implements UserSettings {
boolean godMode;
boolean flying;
double flySpeed;
double walkSpeed;
boolean pTime;
boolean pWeather;
boolean allowTeleports;
private boolean needsSaving;
private EssentiaUserSettings(Builder builder) {
this.godMode = builder.godMode;
this.flying = builder.flying;
this.flySpeed = builder.flySpeed;
this.walkSpeed = builder.walkSpeed;
this.pTime = builder.pTime;
this.pWeather = builder.pWeather;
this.allowTeleports = builder.allowTeleports;
}
@Override
public void godMode(boolean godMode) {
this.godMode = godMode;
this.needsSaving = true;
}
@Override
public void allowTeleports(boolean allowTeleports) {
this.allowTeleports = allowTeleports;
this.needsSaving = true;
}
@Override
public void flying(boolean flying) {
this.flying = flying;
this.needsSaving = true;
}
public static class Builder {
// TODO - defaults?
protected boolean godMode;
protected boolean flying;
protected double flySpeed;
protected double walkSpeed;
protected boolean pTime;
protected boolean pWeather;
protected boolean allowTeleports;
public Builder godMode(boolean godMode) {
this.godMode = godMode;
return this;
}
public Builder flying(boolean flying) {
this.flying = flying;
return this;
}
public Builder flySpeed(double flySpeed) {
this.flySpeed = flySpeed;
return this;
}
public Builder walkSpeed(double walkSpeed) {
this.walkSpeed = walkSpeed;
return this;
}
public Builder pTime(boolean pTime) {
this.pTime = pTime;
return this;
}
public Builder pWeather(boolean pWeather) {
this.pWeather = pWeather;
return this;
}
public Builder allowTeleports(boolean allowTeleports) {
this.allowTeleports = allowTeleports;
return this;
}
public EssentiaUserSettings build() {
return new EssentiaUserSettings(this);
}
}
}

View File

@ -0,0 +1,3 @@
package com.alttd.essentia.model;
public record Kit() {}

View File

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

View File

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

View File

@ -1,8 +1,8 @@
package com.alttd.essentia.request;
import com.alttd.essentia.EssentiaPlugin;
import com.alttd.essentia.api.request.Request;
import com.alttd.essentia.configuration.Config;
import com.alttd.essentia.configuration.PlayerConfig;
import com.alttd.essentia.tasks.RequestTimeout;
import com.alttd.essentia.tasks.TeleportSounds;
import lombok.Getter;
@ -10,16 +10,16 @@ import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.entity.Player;
public abstract class Request {
public abstract class EssentiaRequest implements Request {
private final EssentiaPlugin plugin;
protected final EssentiaPlugin plugin;
@Getter private final Player requester;
@Getter private final Player target;
private final RequestTimeout timeoutTask;
@Getter private final RequestTimeout timeoutTask;
TagResolver placeholders;
public Request(EssentiaPlugin plugin, Player requester, Player target) {
public EssentiaRequest(EssentiaPlugin plugin, Player requester, Player target) {
this.plugin = plugin;
this.requester = requester;
this.target = target;
@ -65,7 +65,7 @@ public abstract class Request {
public void cancel() {
try {
timeoutTask.cancel();
PlayerConfig.getConfig(target).request(null);
plugin.userManager().getUser(target).request(null);
} catch (IllegalStateException ignore) {
}
}

Some files were not shown because too many files have changed in this diff Show More