Essentia plugin
Basic plugin with some essential utilities and commands.
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package com.alttd.essentia;
|
||||
|
||||
import com.alttd.essentia.commands.admin.*;
|
||||
import com.alttd.essentia.commands.player.*;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.listeners.PlayerListener;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
||||
|
||||
@Getter
|
||||
private static EssentiaPlugin instance;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
instance = this;
|
||||
EssentiaAPI.Provider.register(instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
loadConfiguration();
|
||||
loadCommands();
|
||||
loadEventListeners();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
getServer().getScheduler().cancelTasks(this);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
public void loadEventListeners() {
|
||||
final PluginManager pluginManager = getServer().getPluginManager();
|
||||
pluginManager.registerEvents(new PlayerListener(this), this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
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.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ClearInventoryCommand extends AdminSubCommand {
|
||||
|
||||
public ClearInventoryCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "clearinventory");
|
||||
// TODO - register clear other subcommand
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
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 org.bukkit.command.CommandSender;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class EnchantCommand extends AdminSubCommand {
|
||||
|
||||
public EnchantCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "enchant");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(CommandSender sender, String... args) {
|
||||
// TODO
|
||||
return true;
|
||||
}
|
||||
|
||||
@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());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
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.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class FeedCommand extends AdminSubCommand {
|
||||
|
||||
public FeedCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "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;
|
||||
}
|
||||
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("requester", sender.name()),
|
||||
Placeholder.component("target", target.displayName())
|
||||
);
|
||||
|
||||
target.setFoodLevel(20);
|
||||
target.setSaturation(20);
|
||||
sender.sendRichMessage(target == sender ? Config.FEED_SELF : Config.FEED_OTHER, placeholders);
|
||||
if (target != sender)
|
||||
target.sendRichMessage(Config.FEED_BY_OTHER, placeholders);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
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.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 extends AdminSubCommand {
|
||||
|
||||
public FlyCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "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;
|
||||
}
|
||||
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
if (target == null) {
|
||||
sender.sendRichMessage(Config.PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
target.setAllowFlight(!target.getAllowFlight());
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
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.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class HealCommand extends AdminSubCommand {
|
||||
|
||||
public HealCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.tasks.TeleportSounds;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class BackCommand extends PlayerSubCommand {
|
||||
|
||||
public BackCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "back");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
Location back = playerConfig.getBackLocation(false);
|
||||
|
||||
if (back == null) {
|
||||
player.sendRichMessage(Config.NO_BACK_LOCATION);
|
||||
return true;
|
||||
}
|
||||
|
||||
new TeleportSounds(back, player.getLocation())
|
||||
.runTaskLater(plugin, 1);
|
||||
|
||||
player.teleportAsync(back).thenAccept(result ->
|
||||
player.sendRichMessage(Config.TELEPORTING_BACK));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.tasks.TeleportSounds;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class DeathBackCommand extends PlayerSubCommand {
|
||||
|
||||
public DeathBackCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "back");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
Location back = playerConfig.getBackLocation(true);
|
||||
|
||||
if (back == null) {
|
||||
player.sendRichMessage(Config.NO_DEATH_LOCATION);
|
||||
return true;
|
||||
}
|
||||
|
||||
new TeleportSounds(back, player.getLocation())
|
||||
.runTaskLater(plugin, 1);
|
||||
|
||||
player.teleportAsync(back).thenAccept(result ->
|
||||
player.sendRichMessage(Config.TELEPORTING_BACK_DEATH));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class DelHomeCommand extends PlayerSubCommand {
|
||||
|
||||
public DelHomeCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "deletehome");
|
||||
}
|
||||
|
||||
@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;
|
||||
// }
|
||||
// }
|
||||
|
||||
String home = (args.length > 0) ? args[0] : "home";
|
||||
if (playerConfig.getHome(home) == null) {
|
||||
player.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.unparsed("home", home));
|
||||
return true;
|
||||
}
|
||||
|
||||
playerConfig.setHome(home, null);
|
||||
player.sendRichMessage(Config.HOME_DELETED, Placeholder.unparsed("home", home));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.tasks.TeleportSounds;
|
||||
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;
|
||||
|
||||
public class HomeCommand extends PlayerSubCommand {
|
||||
|
||||
public HomeCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "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
|
||||
// }
|
||||
// }
|
||||
|
||||
Location homeLoc = home.equalsIgnoreCase("bed") ?
|
||||
player.getBedSpawnLocation() : playerConfig.getHome(home);
|
||||
if (homeLoc == null) {
|
||||
player.sendRichMessage(Config.HOME_DOES_NOT_EXIST);
|
||||
return true;
|
||||
}
|
||||
|
||||
new TeleportSounds(homeLoc, player.getLocation())
|
||||
.runTaskLater(plugin, 1);
|
||||
|
||||
String homeName = home;
|
||||
player.teleportAsync(homeLoc).thenAccept(result ->
|
||||
player.sendRichMessage(Config.HOME_TELEPORT, Placeholder.unparsed("home", homeName))
|
||||
);
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class HomeListCommand extends PlayerSubCommand {
|
||||
|
||||
public HomeListCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "homes");
|
||||
}
|
||||
|
||||
@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;
|
||||
// }
|
||||
// }
|
||||
|
||||
// TODO - clickable homes that run /home <name>
|
||||
player.sendRichMessage(Config.HOME_LIST, Placeholder.unparsed("homelist", String.join(", ", playerConfig.getHomeList())));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class SetHomeCommand extends PlayerSubCommand {
|
||||
|
||||
|
||||
public SetHomeCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "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;
|
||||
// }
|
||||
// }
|
||||
|
||||
String home = (args.length > 0) ? args[0] : "home";
|
||||
if (home.equalsIgnoreCase("bed") || home.contains(".")) {
|
||||
player.sendRichMessage(Config.INVALID_HOME_NAME);
|
||||
return true;
|
||||
}
|
||||
|
||||
int limit = 5; // TODO -- player home limits hardcoded for now
|
||||
int count = playerConfig.getHomeCount();
|
||||
if (limit >= 0 && count >= limit) {
|
||||
player.sendRichMessage(Config.HOME_SET_MAX, Placeholder.unparsed("limit", String.valueOf(limit)));
|
||||
return true;
|
||||
}
|
||||
|
||||
playerConfig.setHome(home, player.getLocation());
|
||||
player.sendRichMessage(Config.HOME_SET, Placeholder.unparsed("home", home));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.request.Request;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TeleportAcceptCommand extends PlayerSubCommand {
|
||||
|
||||
public TeleportAcceptCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "teleportaccept");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
Request request = playerConfig.request();
|
||||
if (request == null) {
|
||||
player.sendRichMessage(Config.NO_PENDING_REQUESTS);
|
||||
return true;
|
||||
}
|
||||
|
||||
request.accept();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.request.Request;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TeleportDenyCommand extends PlayerSubCommand {
|
||||
|
||||
public TeleportDenyCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "teleportdeny");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
Request request = playerConfig.request();
|
||||
if (request == null) {
|
||||
player.sendRichMessage(Config.NO_PENDING_REQUESTS);
|
||||
return true;
|
||||
}
|
||||
|
||||
request.deny();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
import com.alttd.essentia.request.TeleportRequest;
|
||||
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 TeleportRequestCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "teleportrequest");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
if (args.length < 1) {
|
||||
player.sendRichMessage(Config.NO_PLAYER_SPECIFIED);
|
||||
return true;
|
||||
}
|
||||
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
if (target == null) {
|
||||
player.sendRichMessage(Config.PLAYER_NOT_ONLINE);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (target == player) {
|
||||
player.sendRichMessage(Config.REQUEST_TO_SELF);
|
||||
return true;
|
||||
}
|
||||
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("target", target.displayName())
|
||||
);
|
||||
|
||||
PlayerConfig targetConfig = PlayerConfig.getConfig(target);
|
||||
if (targetConfig.request() != null) {
|
||||
player.sendRichMessage(Config.TARGET_HAS_PENDING_REQUEST, placeholders);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!targetConfig.allowTeleports()) {
|
||||
player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders);
|
||||
return true;
|
||||
}
|
||||
|
||||
targetConfig.request(new TeleportRequest(plugin, player, target));
|
||||
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 Bukkit.getOnlinePlayers().stream()
|
||||
.map(Player::getName)
|
||||
.filter(playerName -> playerName.toLowerCase().startsWith(name)).collect(Collectors.toList());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
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 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 TeleportRequestHereCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "teleportrequesthere");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||
if (args.length < 1) {
|
||||
player.sendRichMessage(Config.NO_PLAYER_SPECIFIED);
|
||||
return true;
|
||||
}
|
||||
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
if (target == null) {
|
||||
player.sendRichMessage(Config.PLAYER_NOT_ONLINE);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (target == player) {
|
||||
player.sendRichMessage(Config.REQUEST_TO_SELF);
|
||||
return true;
|
||||
}
|
||||
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("target", target.displayName())
|
||||
);
|
||||
|
||||
PlayerConfig targetConfig = PlayerConfig.getConfig(target);
|
||||
if (targetConfig.request() != null) {
|
||||
player.sendRichMessage(Config.TARGET_HAS_PENDING_REQUEST, placeholders);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!targetConfig.allowTeleports()) {
|
||||
player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders);
|
||||
return true;
|
||||
}
|
||||
|
||||
targetConfig.request(new TeleportHereRequest(plugin, player, target));
|
||||
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 Bukkit.getOnlinePlayers().stream()
|
||||
.map(Player::getName)
|
||||
.filter(playerName -> playerName.toLowerCase().startsWith(name)).collect(Collectors.toList());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
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.entity.Player;
|
||||
|
||||
public class TeleportToggleCommand extends PlayerSubCommand {
|
||||
|
||||
public TeleportToggleCommand(EssentiaPlugin plugin) {
|
||||
super(plugin, "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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
package com.alttd.essentia.configuration;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.google.common.base.Throwables;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Config {
|
||||
|
||||
private static final String HEADER = """
|
||||
Essentia main configuration file
|
||||
""";
|
||||
|
||||
private static File CONFIG_FILE;
|
||||
public static File CONFIG_PATH;
|
||||
public static YamlConfiguration config;
|
||||
|
||||
static int version;
|
||||
|
||||
public static void init() {
|
||||
CONFIG_PATH = EssentiaPlugin.instance().getDataFolder();
|
||||
CONFIG_FILE = new File(CONFIG_PATH, "config.yml");
|
||||
config = new YamlConfiguration();
|
||||
try {
|
||||
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);
|
||||
Throwables.throwIfUnchecked(ex);
|
||||
}
|
||||
config.options().header(HEADER);
|
||||
config.options().copyDefaults(true);
|
||||
|
||||
version = getInt("config-version", 1);
|
||||
set("config-version", 1);
|
||||
|
||||
readConfig(Config.class, null);
|
||||
}
|
||||
|
||||
static void readConfig(Class<?> clazz, Object instance) {
|
||||
for (Method method : clazz.getDeclaredMethods()) {
|
||||
if (Modifier.isPrivate(method.getModifiers())) {
|
||||
if (method.getParameterTypes().length == 0 && method.getReturnType() == Void.TYPE) {
|
||||
try {
|
||||
method.setAccessible(true);
|
||||
method.invoke(instance);
|
||||
} catch (InvocationTargetException ex) {
|
||||
Throwables.throwIfUnchecked(ex);
|
||||
} catch (Exception ex) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Error invoking " + method, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
static void saveConfig() {
|
||||
try {
|
||||
config.save(CONFIG_FILE);
|
||||
} catch (IOException ex) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Could not save " + CONFIG_FILE, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static void set(String path, Object val) {
|
||||
config.addDefault(path, val);
|
||||
config.set(path, val);
|
||||
}
|
||||
|
||||
private static boolean getBoolean(String path, boolean def) {
|
||||
config.addDefault(path, def);
|
||||
return config.getBoolean(path, config.getBoolean(path));
|
||||
}
|
||||
|
||||
private static double getDouble(String path, double def) {
|
||||
config.addDefault(path, def);
|
||||
return config.getDouble(path, config.getDouble(path));
|
||||
}
|
||||
|
||||
private static int getInt(String path, int def) {
|
||||
config.addDefault(path, def);
|
||||
return config.getInt(path, config.getInt(path));
|
||||
}
|
||||
|
||||
private static <T> List getList(String path, T def) {
|
||||
config.addDefault(path, def);
|
||||
return config.getList(path, config.getList(path));
|
||||
}
|
||||
|
||||
private static String getString(String path, String def) {
|
||||
config.addDefault(path, def);
|
||||
return config.getString(path, config.getString(path));
|
||||
}
|
||||
|
||||
protected static void log(Level level, String s) {
|
||||
Bukkit.getLogger().log(level, s);
|
||||
}
|
||||
|
||||
public static int TELEPORT_REQUEST_TIMEOUT = 30;
|
||||
public static boolean TELEPORT_REQUEST_TIMEOUT_MESSAGES = true;
|
||||
public static boolean BACK_ON_DEATH = false;
|
||||
public static boolean TELEPORT_SOUNDS = true;
|
||||
public static Sound SOUND_TO;
|
||||
public static Sound SOUND_FROM;
|
||||
public static int BACK_COOLDOWN = 60;
|
||||
public static boolean UNSAFE_ENCHANTMENTS = false;
|
||||
private static void settings() {
|
||||
TELEPORT_REQUEST_TIMEOUT = getInt("teleport-request-timeout", TELEPORT_REQUEST_TIMEOUT);
|
||||
TELEPORT_REQUEST_TIMEOUT_MESSAGES = getBoolean("teleport-request-timeout-message", TELEPORT_REQUEST_TIMEOUT_MESSAGES);
|
||||
BACK_ON_DEATH = getBoolean("back-on-death", BACK_ON_DEATH);
|
||||
TELEPORT_SOUNDS = getBoolean("use-teleport-sounds", TELEPORT_SOUNDS);
|
||||
try {
|
||||
SOUND_TO = Sound.valueOf(config.getString("sound-to", "ENTITY_ENDERMAN_TELEPORT"));
|
||||
} catch (IllegalArgumentException e) {
|
||||
SOUND_TO = Sound.ENTITY_ENDERMAN_TELEPORT;
|
||||
}
|
||||
try {
|
||||
SOUND_FROM = Sound.valueOf(config.getString("sound-from", "ENTITY_ENDERMAN_TELEPORT"));
|
||||
} catch (IllegalArgumentException e) {
|
||||
SOUND_FROM = Sound.ENTITY_ENDERMAN_TELEPORT;
|
||||
}
|
||||
UNSAFE_ENCHANTMENTS = getBoolean("unsafe-enchantments", UNSAFE_ENCHANTMENTS);
|
||||
BACK_COOLDOWN = getInt("back-cooldown", BACK_COOLDOWN);
|
||||
}
|
||||
|
||||
public static String REQUEST_TIMED_OUT = "Your teleport request has timed out!";
|
||||
public static String TELEPORT_ACCEPT_REQUESTER = "<target> has accepted your teleport request.";
|
||||
public static String TELEPORT_ACCEPT_TARGET = "You have accepted the teleport request from <requester>.";
|
||||
public static String TELEPORT_DENIED_REQUESTER = "<target> has denied your teleport request.";
|
||||
public static String TELEPORT_DENIED_TARGET = "You have denied the teleport request from <requester>.";
|
||||
public static String TELEPORT_REQUEST_REQUESTER = "Teleport request sent to <target>.";
|
||||
public static String TELEPORT_REQUEST_TARGET = "<requester> has requested to teleport to you. Type /tpaccept or /tpdeny.";
|
||||
public static String TELEPORT_REQUESTHERE_REQUESTER = "Teleport here request sent to <target>.";
|
||||
public static String TELEPORT_REQUESTHERE_TARGET = "<requester> has requested you to teleport to them. Type <gold>/tpaccept</gold> or <gold>/tpdeny</gold>.";
|
||||
public static String TELEPORT_TOGGLE_SET = "Teleport requests toggled <gold><toggle></gold>.";
|
||||
public static String NO_PENDING_REQUESTS = "You do not have any pending teleport requests.";
|
||||
public static String TELEPORT_TOGGLED_OFF = "<target> has teleports toggled off!";
|
||||
public static String TARGET_HAS_PENDING_REQUEST = "<target> has pending request!";
|
||||
public static String REQUEST_TO_SELF = "You can not teleport to yourself!";
|
||||
|
||||
public static String PLAYER_ONLY_COMMAND = "<red>This command is only available to players.";
|
||||
public static String NO_PLAYER_SPECIFIED = "You must specify a player name!";
|
||||
public static String PLAYER_NOT_FOUND = "That player does not exist!";
|
||||
public static String PLAYER_NOT_ONLINE = "That player is not online right now!";
|
||||
public static String COMMAND_NO_PERMISSION = "You do not have permission for that command!";
|
||||
public static String PLAYER_INVENTORY_CLEARED = "You have cleared the inventory of <target>.";
|
||||
public static String INVENTORY_CLEARED_BY_OTHER = "Your inventory has been cleared by <requester>";
|
||||
public static String INVENTORY_CLEARED = "You have cleared your inventory.";
|
||||
public static String SPECIFY_HOME = "Please specify a home!<newline><homelist>";
|
||||
public static String HOME_NOT_SET = "You have not set a home!";
|
||||
public static String HOME_DOES_NOT_EXIST = "Home <home> does not exist!";
|
||||
public static String HOME_TELEPORT = "Teleporting to home <home>.";
|
||||
public static String HOME_LIST = "Homes: <homelist>";
|
||||
public static String HOME_SET = "Home <home> set.";
|
||||
public static String HOME_SET_MAX = "You have reached the maximum of <limit> homes.";
|
||||
public static String INVALID_HOME_NAME = "Invalid home name!";
|
||||
public static String HOME_DELETED = "The home <home> has been deleted.";
|
||||
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 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!";
|
||||
public static String TELEPORTING_BACK_DEATH = "Teleporting back to previous death location.";
|
||||
public static String BACK_DEATH_HINT = "Type /dback to go back to where you died.";
|
||||
public static String GAMEMODE_SET = "Gamemode set to <gamemode>.";
|
||||
public static String GAMEMODE_SET_OTHER = "Gamemode for <target> set to <gamemode>.";
|
||||
public static String GAMEMODE_SET_BY_OTHER = "Gamemode set to <gamemode> by <requester>.";
|
||||
|
||||
public static String HEAL_SELF = "Your health has been restored.";
|
||||
public static String HEAL_OTHER = "<target>'s health has been restored.";
|
||||
public static String HEAL_BY_OTHER = "<requester> has restored your health.";
|
||||
|
||||
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.";
|
||||
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);
|
||||
TELEPORT_ACCEPT_REQUESTER = getString("messages.request.teleport-accept-requester", TELEPORT_ACCEPT_REQUESTER);
|
||||
TELEPORT_DENIED_TARGET = getString("messages.request.teleport-denied-target", TELEPORT_DENIED_TARGET);
|
||||
TELEPORT_DENIED_REQUESTER = getString("messages.request.teleport-denied-requester", TELEPORT_DENIED_REQUESTER);
|
||||
TELEPORT_REQUESTHERE_TARGET = getString("messages.request.teleport-requesthere-target", TELEPORT_REQUESTHERE_TARGET);
|
||||
TELEPORT_REQUEST_TARGET = getString("messages.request.teleport-request-target", TELEPORT_REQUEST_TARGET);
|
||||
TELEPORT_TOGGLE_SET = getString("messages.request.teleport-toggle-set", TELEPORT_TOGGLE_SET);
|
||||
NO_PENDING_REQUESTS = getString("messages.request.no-pending-requests", NO_PENDING_REQUESTS);
|
||||
TELEPORT_TOGGLED_OFF = getString("messages.request.target-toggled-off", TELEPORT_TOGGLED_OFF);
|
||||
TARGET_HAS_PENDING_REQUEST = getString("messages.request.target-has-pending-request", TARGET_HAS_PENDING_REQUEST);
|
||||
REQUEST_TO_SELF = getString("messages.request.request-to-self", REQUEST_TO_SELF);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
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 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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.alttd.essentia.listeners;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.configuration.PlayerConfig;
|
||||
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.PlayerTeleportEvent;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
|
||||
private EssentiaPlugin plugin;
|
||||
private final Set<PlayerTeleportEvent.TeleportCause> backAllowCauses = new HashSet<>();
|
||||
|
||||
public PlayerListener(EssentiaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
backAllowCauses.add(PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||
backAllowCauses.add(PlayerTeleportEvent.TeleportCause.COMMAND);
|
||||
backAllowCauses.add(PlayerTeleportEvent.TeleportCause.UNKNOWN);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void backOnDeath(PlayerDeathEvent event) {
|
||||
if (!Config.BACK_ON_DEATH) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getEntity();
|
||||
if (!player.hasPermission("essentia.command.deathback")) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerConfig playerConfig = PlayerConfig.getConfig(player);
|
||||
playerConfig.setBackLocation(true, player.getLocation());
|
||||
player.sendRichMessage(Config.BACK_DEATH_HINT);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void backOnTeleport(PlayerTeleportEvent event) {
|
||||
if (!backAllowCauses.contains(event.getCause())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
if (!player.hasPermission("essentia.command.back")) {
|
||||
return;
|
||||
}
|
||||
|
||||
Location to = event.getTo();
|
||||
Location from = event.getFrom();
|
||||
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.alttd.essentia.request;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
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;
|
||||
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 {
|
||||
|
||||
private final EssentiaPlugin plugin;
|
||||
@Getter private final Player requester;
|
||||
@Getter private final Player target;
|
||||
private final RequestTimeout timeoutTask;
|
||||
|
||||
TagResolver placeholders;
|
||||
|
||||
public Request(EssentiaPlugin plugin, Player requester, Player target) {
|
||||
this.plugin = plugin;
|
||||
this.requester = requester;
|
||||
this.target = target;
|
||||
|
||||
this.timeoutTask = new RequestTimeout(this);
|
||||
|
||||
if (Config.TELEPORT_REQUEST_TIMEOUT > 0) {
|
||||
this.timeoutTask.runTaskLater(plugin,
|
||||
Config.TELEPORT_REQUEST_TIMEOUT * 20L);
|
||||
}
|
||||
|
||||
placeholders = TagResolver.resolver(
|
||||
Placeholder.component("requester", requester().displayName()),
|
||||
Placeholder.component("target", target().displayName())
|
||||
);
|
||||
}
|
||||
|
||||
public void accept() {
|
||||
teleport();
|
||||
|
||||
target.sendRichMessage(Config.TELEPORT_ACCEPT_TARGET, placeholders);
|
||||
requester.sendRichMessage(Config.TELEPORT_ACCEPT_REQUESTER, placeholders);
|
||||
|
||||
cancel();
|
||||
}
|
||||
|
||||
public void deny() {
|
||||
target.sendRichMessage(Config.TELEPORT_DENIED_TARGET, placeholders);
|
||||
requester.sendRichMessage(Config.TELEPORT_DENIED_REQUESTER, placeholders);
|
||||
|
||||
cancel();
|
||||
}
|
||||
|
||||
protected abstract void teleport();
|
||||
|
||||
void playTeleportSounds() {
|
||||
if (Config.TELEPORT_SOUNDS) {
|
||||
new TeleportSounds(target.getLocation(), requester.getLocation())
|
||||
.runTaskLater(plugin, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
try {
|
||||
timeoutTask.cancel();
|
||||
PlayerConfig.getConfig(target).request(null);
|
||||
} catch (IllegalStateException ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.alttd.essentia.request;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TeleportHereRequest extends Request {
|
||||
|
||||
public TeleportHereRequest(EssentiaPlugin plugin, Player requester, Player target) {
|
||||
super(plugin, requester, target);
|
||||
|
||||
target.sendRichMessage(Config.TELEPORT_REQUEST_TARGET, placeholders);
|
||||
requester.sendRichMessage(Config.TELEPORT_REQUESTHERE_REQUESTER, placeholders);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void teleport() {
|
||||
if (!target().isOnline() || !requester().isOnline()) {
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
target().teleportAsync(requester().getLocation()).thenAccept(result -> playTeleportSounds());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.alttd.essentia.request;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TeleportRequest extends Request {
|
||||
|
||||
public TeleportRequest(EssentiaPlugin plugin, Player requester, Player target) {
|
||||
super(plugin, requester, target);
|
||||
|
||||
target.sendRichMessage(Config.TELEPORT_REQUESTHERE_TARGET, placeholders);
|
||||
requester.sendRichMessage(Config.TELEPORT_REQUEST_REQUESTER, placeholders);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void teleport() {
|
||||
if (!target().isOnline() || !requester().isOnline()) {
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
target().teleportAsync(requester().getLocation()).thenAccept(result -> playTeleportSounds());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.alttd.essentia.tasks;
|
||||
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.request.Request;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class RequestTimeout extends BukkitRunnable {
|
||||
private final Request request;
|
||||
|
||||
public RequestTimeout(Request request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!request.target().isOnline() || !request.requester().isOnline()) {
|
||||
request.cancel();
|
||||
return;
|
||||
}
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("requester", request.requester().displayName()),
|
||||
Placeholder.component("target", request.target().displayName())
|
||||
);
|
||||
request.requester().sendRichMessage(Config.REQUEST_TIMED_OUT, placeholders);
|
||||
request.target().sendRichMessage(Config.REQUEST_TIMED_OUT, placeholders);
|
||||
|
||||
request.cancel();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.alttd.essentia.tasks;
|
||||
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class TeleportSounds extends BukkitRunnable {
|
||||
|
||||
private final Location to;
|
||||
private final Location from;
|
||||
|
||||
public TeleportSounds(Location to, Location from) {
|
||||
this.to = to;
|
||||
this.from = from;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (Config.TELEPORT_SOUNDS) {
|
||||
if (Config.SOUND_TO != null) {
|
||||
to.getWorld().playSound(to, Config.SOUND_TO, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
if (Config.SOUND_FROM != null) {
|
||||
from.getWorld().playSound(from, Config.SOUND_FROM, 1.0F, 1.0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
name: Essentia
|
||||
version: ${version}
|
||||
main: com.alttd.essentia.EssentiaPlugin
|
||||
description: Altitude essentials ;)
|
||||
authors:
|
||||
- destro174
|
||||
api-version: "1.20"
|
||||
|
||||
commands:
|
||||
essentia:
|
||||
description: Reload configs.
|
||||
permission: essentia.command.essentia-reload
|
||||
usage: /<command> (reload)
|
||||
teleportaccept:
|
||||
description: Accept teleport request.
|
||||
permission: essentia.command.teleportaccept
|
||||
usage: /<command>
|
||||
aliases:
|
||||
- tpaccept
|
||||
teleportdeny:
|
||||
description: Decline teleport request.
|
||||
permission: essentia.command.teleportdeny
|
||||
usage: /<command>
|
||||
aliases:
|
||||
- tpdeny
|
||||
teleportrequest:
|
||||
description: Request to teleport to another player.
|
||||
permission: essentia.command.teleportrequest
|
||||
usage: /<command> player
|
||||
aliases:
|
||||
- tpa
|
||||
- tprequest
|
||||
- tparequest
|
||||
teleportrequesthere:
|
||||
description: Request another player to teleport to you.
|
||||
permission: essentia.command.teleportrequesthere
|
||||
usage: /<command> player
|
||||
aliases:
|
||||
- tpah
|
||||
- tpahere
|
||||
teleporttoggle:
|
||||
description: Toggle teleport requests on/off.
|
||||
permission: essentia.command.teleporttoggle
|
||||
usage: /<command>
|
||||
aliases:
|
||||
- tptoggle
|
||||
clearinventory:
|
||||
description: Clears your inventory.
|
||||
permission: essentia.command.clearinventory
|
||||
usage: /<command> (player)
|
||||
home:
|
||||
description: Teleports the player home.
|
||||
permission: essentia.command.home
|
||||
usage: /<command> (home (player))
|
||||
homes:
|
||||
description: List the player's homes.
|
||||
permission: essentia.command.homes
|
||||
usage: /<command> (player)
|
||||
aliases:
|
||||
- listhomes
|
||||
sethome:
|
||||
description: Sets the player's home.
|
||||
permission: essentia.command.sethome
|
||||
usage: /<command> (home (player))
|
||||
aliases:
|
||||
- homeset
|
||||
deletehome:
|
||||
description: Deletes a home.
|
||||
permission: essentia.command.deletehome
|
||||
usage: /<command> [home (player)]
|
||||
aliases:
|
||||
- delhome
|
||||
back:
|
||||
description: Go back to previous location.
|
||||
permission: essentia.command.back
|
||||
usage: /<command>
|
||||
deathback:
|
||||
description: Go back to previous death location.
|
||||
permission: essentia.command.deathback
|
||||
usage: /<command>
|
||||
aliases:
|
||||
- dback
|
||||
fly:
|
||||
description: Toggles creative flymode for yourself or another player.
|
||||
permission: essentia.command.fly
|
||||
usage: /<command> (player)
|
||||
gamemode:
|
||||
description: Set gamemode for yourself or another player.
|
||||
permission: essentia.command.gamemode
|
||||
usage: /<command> (player)
|
||||
aliases:
|
||||
- gm
|
||||
heal:
|
||||
description: Heals yourself or another player.
|
||||
permission: essentia.command.heal
|
||||
usage: /<command> (player)
|
||||
aliases:
|
||||
- health
|
||||
feed:
|
||||
description: Refill hunger and saturation.
|
||||
permission: essentia.command.feed
|
||||
usage: /<command> (player)
|
||||
enchant:
|
||||
description: Enchants the item in hand
|
||||
permission: essentia.command.enchant
|
||||
usage: /<command> [enchantment/all] (level) (unsafe)
|
||||
Reference in New Issue
Block a user