mirror of
https://github.com/xHyroM/lighteco.git
synced 2024-11-21 22:41:06 +01:00
refactor: cleanup, rename bukkit to paper
This commit is contained in:
parent
35eebc1609
commit
ce2743bd36
23 changed files with 187 additions and 203 deletions
|
@ -18,6 +18,7 @@ tasks {
|
|||
filesMatching(listOf("plugin.yml")) {
|
||||
expand(
|
||||
"name" to project.name,
|
||||
"coreName" to "LightEco",
|
||||
"version" to project.version,
|
||||
"description" to project.description,
|
||||
"author" to "xHyroM"
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
package dev.xhyrom.lighteco.bukkit.listeners;
|
||||
|
||||
import com.destroystokyo.paper.event.brigadier.AsyncPlayerSendCommandsEvent;
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import dev.xhyrom.lighteco.bukkit.BukkitLightEcoPlugin;
|
||||
import dev.xhyrom.lighteco.bukkit.brigadier.BukkitBrigadier;
|
||||
import dev.xhyrom.lighteco.bukkit.chat.BukkitCommandSender;
|
||||
import dev.xhyrom.lighteco.common.command.CommandSource;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class BukkitCommandSuggestionsListener implements Listener {
|
||||
private final BukkitLightEcoPlugin plugin;
|
||||
|
||||
public BukkitCommandSuggestionsListener(BukkitLightEcoPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked", "deprecation"})
|
||||
@EventHandler
|
||||
public void onPlayerSendCommandsEvent(AsyncPlayerSendCommandsEvent<?> event) {
|
||||
BukkitCommandSender sender = new BukkitCommandSender(event.getPlayer(), this.plugin.getCommandManager().audienceFactory);
|
||||
CommandSource source = new CommandSource(this.plugin, sender);
|
||||
if (event.isAsynchronous() || !event.hasFiredAsync()) {
|
||||
for (CommandNode<CommandSource> command : this.plugin.getCommandManager().getDispatcher().getRoot().getChildren()) {
|
||||
BukkitBrigadier.removeChild(event.getCommandNode(), command.getName());
|
||||
BukkitBrigadier.removeChild(event.getCommandNode(), command.getName() + ":" + command.getName());
|
||||
|
||||
if (!command.canUse(source)) continue;
|
||||
|
||||
CommandNode<CommandSource> clone = new LiteralCommandNode(command.getName(), command.getCommand(), command.getRequirement(), command.getRedirect(), command.getRedirectModifier(), command.isFork());
|
||||
|
||||
for (CommandNode<CommandSource> child : command.getChildren()) {
|
||||
if (child.canUse(source))
|
||||
clone.addChild(child);
|
||||
}
|
||||
|
||||
event.getCommandNode().addChild((CommandNode) clone);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
package dev.xhyrom.lighteco.bukkit.manager;
|
||||
|
||||
import com.mojang.brigadier.ParseResults;
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
import dev.xhyrom.lighteco.bukkit.chat.BukkitCommandSender;
|
||||
import dev.xhyrom.lighteco.common.command.CommandManager;
|
||||
import dev.xhyrom.lighteco.common.command.CommandSource;
|
||||
import dev.xhyrom.lighteco.common.command.abstraction.Command;
|
||||
import dev.xhyrom.lighteco.common.model.currency.Currency;
|
||||
import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BukkitCommandManager extends CommandManager {
|
||||
public final BukkitAudiences audienceFactory;
|
||||
private CommandMap commandMap;
|
||||
|
||||
public BukkitCommandManager(LightEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
|
||||
this.audienceFactory = BukkitAudiences.create((JavaPlugin) this.plugin.getBootstrap().getLoader());
|
||||
|
||||
try {
|
||||
Field field = Bukkit.getServer().getClass().getDeclaredField("commandMap");
|
||||
|
||||
field.setAccessible(true);
|
||||
this.commandMap = (CommandMap) field.get(Bukkit.getServer());
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Command[] register(Currency currency, boolean main) {
|
||||
Command[] commands = super.register(currency, main);
|
||||
|
||||
for (Command command : commands) {
|
||||
this.registerToBukkit(command);
|
||||
}
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
private void registerToBukkit(Command command) {
|
||||
org.bukkit.command.Command bukkitCommand = new org.bukkit.command.Command(
|
||||
command.getName(),
|
||||
command.getDescription(),
|
||||
"/" + command.getName(),
|
||||
command.getAliases()
|
||||
) {
|
||||
private final CommandNode<CommandSource> node = getDispatcher().getRoot().getChild(getName());
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) {
|
||||
bukkitCommandManagerExecute(new BukkitCommandSender(commandSender, audienceFactory), s, strings);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException {
|
||||
final List<String> suggestions = new ArrayList<>();
|
||||
final CommandSource source = new CommandSource(plugin, new BukkitCommandSender(sender, audienceFactory));
|
||||
|
||||
final ParseResults<CommandSource> parseResults = getDispatcher().parse(
|
||||
getName() + (args.length > 0 ? " " + String.join(" ", args) : ""),
|
||||
source
|
||||
);
|
||||
|
||||
getDispatcher().getCompletionSuggestions(
|
||||
parseResults
|
||||
).join().getList().forEach(suggestion -> suggestions.add(suggestion.getText()));
|
||||
|
||||
return suggestions;
|
||||
}
|
||||
};
|
||||
|
||||
commandMap.register(command.getName(), bukkitCommand);
|
||||
}
|
||||
|
||||
private void bukkitCommandManagerExecute(dev.xhyrom.lighteco.common.model.chat.CommandSender sender, String name, String[] args) {
|
||||
super.execute(sender, name, args);
|
||||
}
|
||||
}
|
|
@ -7,4 +7,4 @@ api-version: 1.20
|
|||
|
||||
softdepend:
|
||||
- Vault
|
||||
- lighteco-bukkit
|
||||
- LightEco
|
|
@ -8,4 +8,4 @@ load: STARTUP
|
|||
|
||||
softdepend:
|
||||
- Vault
|
||||
- lighteco-bukkit
|
||||
- LightEco
|
||||
|
|
0
bukkit/.gitignore → paper/.gitignore
vendored
0
bukkit/.gitignore → paper/.gitignore
vendored
|
@ -1,6 +1,6 @@
|
|||
package dev.xhyrom.lighteco.bukkit;
|
||||
package dev.xhyrom.lighteco.paper;
|
||||
|
||||
import dev.xhyrom.lighteco.bukkit.logger.BukkitLogger;
|
||||
import dev.xhyrom.lighteco.paper.logger.PaperLogger;
|
||||
import dev.xhyrom.lighteco.common.plugin.bootstrap.LightEcoBootstrap;
|
||||
import dev.xhyrom.lighteco.common.plugin.bootstrap.LoaderBootstrap;
|
||||
import dev.xhyrom.lighteco.common.plugin.logger.PluginLogger;
|
||||
|
@ -20,8 +20,8 @@ import java.util.Optional;
|
|||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
public class BukkitLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstrap {
|
||||
private final BukkitLightEcoPlugin plugin = new BukkitLightEcoPlugin(this);
|
||||
public class PaperLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstrap {
|
||||
private final PaperLightEcoPlugin plugin = new PaperLightEcoPlugin(this);
|
||||
|
||||
@Getter
|
||||
private final JavaPlugin loader;
|
||||
|
@ -29,12 +29,13 @@ public class BukkitLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstr
|
|||
private final PluginLogger logger;
|
||||
@Getter
|
||||
private final SchedulerAdapter scheduler;
|
||||
@Getter
|
||||
private BukkitAudiences audience;
|
||||
|
||||
public BukkitLightEcoBootstrap(JavaPlugin loader) {
|
||||
public PaperLightEcoBootstrap(JavaPlugin loader) {
|
||||
this.loader = loader;
|
||||
this.logger = new BukkitLogger(loader.getLogger());
|
||||
this.scheduler = new BukkitSchedulerAdapter(this);
|
||||
this.logger = new PaperLogger(loader.getLogger());
|
||||
this.scheduler = new PaperSchedulerAdapter(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -46,7 +47,7 @@ public class BukkitLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstr
|
|||
public void onEnable() {
|
||||
this.plugin.enable();
|
||||
|
||||
this.audience = BukkitAudiences.create(loader);
|
||||
this.audience = BukkitAudiences.create(this.loader);
|
||||
}
|
||||
|
||||
@Override
|
|
@ -1,14 +1,14 @@
|
|||
package dev.xhyrom.lighteco.bukkit;
|
||||
package dev.xhyrom.lighteco.paper;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
// Used inside plugin.yml
|
||||
@SuppressWarnings("unused")
|
||||
public class BukkitLightEcoLoader extends JavaPlugin {
|
||||
private final BukkitLightEcoBootstrap bootstrap;
|
||||
public class PaperLightEcoLoader extends JavaPlugin {
|
||||
private final PaperLightEcoBootstrap bootstrap;
|
||||
|
||||
public BukkitLightEcoLoader() {
|
||||
this.bootstrap = new BukkitLightEcoBootstrap(this);
|
||||
public PaperLightEcoLoader() {
|
||||
this.bootstrap = new PaperLightEcoBootstrap(this);
|
||||
}
|
||||
|
||||
@Override
|
|
@ -1,13 +1,13 @@
|
|||
package dev.xhyrom.lighteco.bukkit;
|
||||
package dev.xhyrom.lighteco.paper;
|
||||
|
||||
import dev.xhyrom.lighteco.api.LightEco;
|
||||
import dev.xhyrom.lighteco.api.manager.ContextManager;
|
||||
import dev.xhyrom.lighteco.api.platform.Platform;
|
||||
import dev.xhyrom.lighteco.bukkit.hooks.Hooks;
|
||||
import dev.xhyrom.lighteco.bukkit.listeners.BukkitCommandSuggestionsListener;
|
||||
import dev.xhyrom.lighteco.bukkit.listeners.BukkitConnectionListener;
|
||||
import dev.xhyrom.lighteco.bukkit.manager.BukkitCommandManager;
|
||||
import dev.xhyrom.lighteco.bukkit.manager.BukkitContextManager;
|
||||
import dev.xhyrom.lighteco.paper.hooks.Hooks;
|
||||
import dev.xhyrom.lighteco.paper.listeners.PaperCommandSuggestionsListener;
|
||||
import dev.xhyrom.lighteco.paper.listeners.PaperConnectionListener;
|
||||
import dev.xhyrom.lighteco.paper.manager.PaperCommandManager;
|
||||
import dev.xhyrom.lighteco.paper.manager.PaperContextManager;
|
||||
import dev.xhyrom.lighteco.common.manager.currency.StandardCurrencyManager;
|
||||
import dev.xhyrom.lighteco.common.messaging.MessagingFactory;
|
||||
import dev.xhyrom.lighteco.common.plugin.AbstractLightEcoPlugin;
|
||||
|
@ -18,34 +18,34 @@ import org.bukkit.plugin.ServicePriority;
|
|||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
@Getter
|
||||
public class BukkitLightEcoPlugin extends AbstractLightEcoPlugin {
|
||||
private final BukkitLightEcoBootstrap bootstrap;
|
||||
public class PaperLightEcoPlugin extends AbstractLightEcoPlugin {
|
||||
private final PaperLightEcoBootstrap bootstrap;
|
||||
|
||||
@Getter
|
||||
private StandardUserManager userManager;
|
||||
@Getter
|
||||
private StandardCurrencyManager currencyManager;
|
||||
@Getter
|
||||
private BukkitCommandManager commandManager;
|
||||
private PaperCommandManager commandManager;
|
||||
@Getter
|
||||
private ContextManager<Player> contextManager;
|
||||
|
||||
public BukkitLightEcoPlugin(BukkitLightEcoBootstrap bootstrap) {
|
||||
public PaperLightEcoPlugin(PaperLightEcoBootstrap bootstrap) {
|
||||
this.bootstrap = bootstrap;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerListeners() {
|
||||
this.bootstrap.getLoader().getServer().getPluginManager().registerEvents(new BukkitConnectionListener(this), this.bootstrap.getLoader());
|
||||
this.bootstrap.getLoader().getServer().getPluginManager().registerEvents(new BukkitCommandSuggestionsListener(this), this.bootstrap.getLoader());
|
||||
this.bootstrap.getLoader().getServer().getPluginManager().registerEvents(new PaperConnectionListener(this), this.bootstrap.getLoader());
|
||||
this.bootstrap.getLoader().getServer().getPluginManager().registerEvents(new PaperCommandSuggestionsListener(this), this.bootstrap.getLoader());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupManagers() {
|
||||
this.userManager = new StandardUserManager(this);
|
||||
this.currencyManager = new StandardCurrencyManager(this);
|
||||
this.commandManager = new BukkitCommandManager(this);
|
||||
this.contextManager = new BukkitContextManager();
|
||||
this.commandManager = new PaperCommandManager(this);
|
||||
this.contextManager = new PaperContextManager();
|
||||
}
|
||||
|
||||
@Override
|
|
@ -1,21 +1,20 @@
|
|||
package dev.xhyrom.lighteco.bukkit;
|
||||
package dev.xhyrom.lighteco.paper;
|
||||
|
||||
import dev.xhyrom.lighteco.common.plugin.scheduler.SchedulerAdapter;
|
||||
import dev.xhyrom.lighteco.common.plugin.scheduler.SchedulerTask;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class BukkitSchedulerAdapter implements SchedulerAdapter {
|
||||
public class PaperSchedulerAdapter implements SchedulerAdapter {
|
||||
private final Executor async;
|
||||
|
||||
private final BukkitLightEcoBootstrap bootstrap;
|
||||
private final PaperLightEcoBootstrap bootstrap;
|
||||
private final BukkitScheduler scheduler;
|
||||
|
||||
public BukkitSchedulerAdapter(BukkitLightEcoBootstrap bootstrap) {
|
||||
public PaperSchedulerAdapter(PaperLightEcoBootstrap bootstrap) {
|
||||
this.bootstrap = bootstrap;
|
||||
this.scheduler = bootstrap.getLoader().getServer().getScheduler();
|
||||
|
|
@ -1,21 +1,15 @@
|
|||
package dev.xhyrom.lighteco.bukkit.chat;
|
||||
package dev.xhyrom.lighteco.paper.chat;
|
||||
|
||||
import dev.xhyrom.lighteco.common.model.chat.AbstractCommandSender;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class BukkitCommandSender extends AbstractCommandSender<CommandSender> {
|
||||
private final Audience audience;
|
||||
|
||||
public BukkitCommandSender(CommandSender sender, BukkitAudiences audienceFactory) {
|
||||
public class PaperCommandSender extends AbstractCommandSender<CommandSender> {
|
||||
public PaperCommandSender(CommandSender sender) {
|
||||
super(sender);
|
||||
|
||||
this.audience = audienceFactory.sender(sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,6 +33,6 @@ public class BukkitCommandSender extends AbstractCommandSender<CommandSender> {
|
|||
|
||||
@Override
|
||||
public void sendMessage(Component message) {
|
||||
this.audience.sendMessage(message);
|
||||
this.delegate.sendMessage(message);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package dev.xhyrom.lighteco.bukkit.hooks;
|
||||
package dev.xhyrom.lighteco.paper.hooks;
|
||||
|
||||
import dev.xhyrom.lighteco.bukkit.BukkitLightEcoPlugin;
|
||||
import dev.xhyrom.lighteco.paper.PaperLightEcoPlugin;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
|
@ -8,7 +8,7 @@ import org.bukkit.Bukkit;
|
|||
public class Hooks {
|
||||
private static PlaceholderAPIExpansion placeholderAPIExpansion;
|
||||
|
||||
public static void register(BukkitLightEcoPlugin plugin) {
|
||||
public static void register(PaperLightEcoPlugin plugin) {
|
||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
placeholderAPIExpansion = new PlaceholderAPIExpansion(plugin);
|
||||
placeholderAPIExpansion.register();
|
|
@ -1,6 +1,6 @@
|
|||
package dev.xhyrom.lighteco.bukkit.hooks;
|
||||
package dev.xhyrom.lighteco.paper.hooks;
|
||||
|
||||
import dev.xhyrom.lighteco.bukkit.BukkitLightEcoPlugin;
|
||||
import dev.xhyrom.lighteco.paper.PaperLightEcoPlugin;
|
||||
import dev.xhyrom.lighteco.common.model.currency.Currency;
|
||||
import dev.xhyrom.lighteco.common.model.user.User;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
@ -11,7 +11,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||
|
||||
@RequiredArgsConstructor
|
||||
public class PlaceholderAPIExpansion extends PlaceholderExpansion {
|
||||
private final BukkitLightEcoPlugin plugin;
|
||||
private final PaperLightEcoPlugin plugin;
|
||||
|
||||
@Override
|
||||
public @NonNull String getIdentifier() {
|
|
@ -0,0 +1,55 @@
|
|||
package dev.xhyrom.lighteco.paper.listeners;
|
||||
|
||||
import com.destroystokyo.paper.event.brigadier.AsyncPlayerSendCommandsEvent;
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import dev.xhyrom.lighteco.paper.PaperLightEcoPlugin;
|
||||
import dev.xhyrom.lighteco.paper.util.PaperBrigadier;
|
||||
import dev.xhyrom.lighteco.paper.chat.PaperCommandSender;
|
||||
import dev.xhyrom.lighteco.common.command.CommandSource;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class PaperCommandSuggestionsListener implements Listener {
|
||||
private final PaperLightEcoPlugin plugin;
|
||||
|
||||
public PaperCommandSuggestionsListener(PaperLightEcoPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler
|
||||
public void onPlayerSendCommandsEvent(AsyncPlayerSendCommandsEvent<?> event) {
|
||||
PaperCommandSender sender = new PaperCommandSender(event.getPlayer());
|
||||
CommandSource source = new CommandSource(this.plugin, sender);
|
||||
if (event.isAsynchronous() || !event.hasFiredAsync()) {
|
||||
for (CommandNode<CommandSource> command : this.plugin.getCommandManager().getDispatcher().getRoot().getChildren()) {
|
||||
PaperBrigadier.removeChild(event.getCommandNode(), command.getName());
|
||||
PaperBrigadier.removeChild(event.getCommandNode(), this.plugin.getBootstrap().getLoader().getName().toLowerCase() + ":" + command.getName());
|
||||
|
||||
if (!command.canUse(source)) continue;
|
||||
|
||||
addChild(event, source, command, createClone(command));
|
||||
addChild(event, source, command, createClone(this.plugin.getBootstrap().getLoader().getName().toLowerCase() + ":" + command.getName(), command));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked", "deprecation"})
|
||||
private void addChild(AsyncPlayerSendCommandsEvent<?> event, CommandSource source, CommandNode<CommandSource> command, CommandNode<CommandSource> clone) {
|
||||
for (CommandNode<CommandSource> child : command.getChildren()) {
|
||||
if (child.canUse(source))
|
||||
clone.addChild(child);
|
||||
}
|
||||
|
||||
event.getCommandNode().addChild((CommandNode) clone);
|
||||
}
|
||||
|
||||
private CommandNode<CommandSource> createClone(CommandNode<CommandSource> command) {
|
||||
return createClone(command.getName(), command);
|
||||
}
|
||||
|
||||
private CommandNode<CommandSource> createClone(String name, CommandNode<CommandSource> command) {
|
||||
return new LiteralCommandNode<>(name, command.getCommand(), command.getRequirement(), command.getRedirect(), command.getRedirectModifier(), command.isFork());
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package dev.xhyrom.lighteco.bukkit.listeners;
|
||||
package dev.xhyrom.lighteco.paper.listeners;
|
||||
|
||||
import dev.xhyrom.lighteco.bukkit.BukkitLightEcoPlugin;
|
||||
import dev.xhyrom.lighteco.paper.PaperLightEcoPlugin;
|
||||
import dev.xhyrom.lighteco.common.model.currency.Currency;
|
||||
import dev.xhyrom.lighteco.common.model.user.User;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
@ -14,11 +14,11 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
|||
|
||||
import java.util.UUID;
|
||||
|
||||
public class BukkitConnectionListener implements Listener {
|
||||
private final BukkitLightEcoPlugin plugin;
|
||||
public class PaperConnectionListener implements Listener {
|
||||
private final PaperLightEcoPlugin plugin;
|
||||
private final MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
|
||||
public BukkitConnectionListener(BukkitLightEcoPlugin plugin) {
|
||||
public PaperConnectionListener(PaperLightEcoPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
package dev.xhyrom.lighteco.bukkit.logger;
|
||||
package dev.xhyrom.lighteco.paper.logger;
|
||||
|
||||
import dev.xhyrom.lighteco.common.plugin.logger.PluginLogger;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class BukkitLogger implements PluginLogger {
|
||||
public class PaperLogger implements PluginLogger {
|
||||
private final Logger logger;
|
||||
|
||||
public BukkitLogger(Logger logger) {
|
||||
public PaperLogger(Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
package dev.xhyrom.lighteco.paper.manager;
|
||||
|
||||
import com.mojang.brigadier.ParseResults;
|
||||
import dev.xhyrom.lighteco.paper.chat.PaperCommandSender;
|
||||
import dev.xhyrom.lighteco.common.command.CommandManager;
|
||||
import dev.xhyrom.lighteco.common.command.CommandSource;
|
||||
import dev.xhyrom.lighteco.common.command.abstraction.Command;
|
||||
import dev.xhyrom.lighteco.common.model.currency.Currency;
|
||||
import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin;
|
||||
import dev.xhyrom.lighteco.paper.util.PaperCommandMapUtil;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PaperCommandManager extends CommandManager {
|
||||
private final PaperCommandMapUtil commandMapUtil;
|
||||
|
||||
public PaperCommandManager(LightEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
|
||||
this.commandMapUtil = new PaperCommandMapUtil(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Command[] register(Currency currency, boolean main) {
|
||||
Command[] commands = super.register(currency, main);
|
||||
|
||||
for (Command command : commands) {
|
||||
this.registerToBukkit(command);
|
||||
}
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
private void registerToBukkit(Command command) {
|
||||
CommandExecutor executor = (sender, bukkitCommand, s, args) -> {
|
||||
if (s.startsWith("lighteco:")) {
|
||||
s = s.substring(9);
|
||||
}
|
||||
|
||||
execute(new PaperCommandSender(sender), s, args);
|
||||
return true;
|
||||
};
|
||||
|
||||
TabCompleter completer = (sender, bukkitCommand, s, args) -> {
|
||||
final List<String> suggestions = new ArrayList<>();
|
||||
final CommandSource source = new CommandSource(plugin, new PaperCommandSender(sender));
|
||||
|
||||
final ParseResults<CommandSource> parseResults = getDispatcher().parse(
|
||||
command.getName() + (args.length > 0 ? " " + String.join(" ", args) : ""),
|
||||
source
|
||||
);
|
||||
|
||||
getDispatcher().getCompletionSuggestions(
|
||||
parseResults
|
||||
).join().getList().forEach(suggestion -> suggestions.add(suggestion.getText()));
|
||||
|
||||
return suggestions;
|
||||
};
|
||||
|
||||
List<String> aliases = new ArrayList<>(command.getAliases());
|
||||
aliases.add(command.getName());
|
||||
|
||||
this.commandMapUtil.register(
|
||||
executor,
|
||||
completer,
|
||||
aliases
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package dev.xhyrom.lighteco.bukkit.manager;
|
||||
package dev.xhyrom.lighteco.paper.manager;
|
||||
|
||||
import dev.xhyrom.lighteco.api.manager.ContextManager;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -6,7 +6,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||
|
||||
import java.util.UUID;
|
||||
|
||||
public class BukkitContextManager implements ContextManager<Player> {
|
||||
public class PaperContextManager implements ContextManager<Player> {
|
||||
@Override
|
||||
public @NonNull UUID getPlayerUniqueId(@NonNull Player player) {
|
||||
return player.getUniqueId();
|
|
@ -1,16 +1,12 @@
|
|||
package dev.xhyrom.lighteco.bukkit.brigadier;
|
||||
package dev.xhyrom.lighteco.paper.util;
|
||||
|
||||
import com.mojang.brigadier.suggestion.SuggestionProvider;
|
||||
import com.mojang.brigadier.tree.ArgumentCommandNode;
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import com.mojang.brigadier.tree.RootCommandNode;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
public class BukkitBrigadier {
|
||||
public class PaperBrigadier {
|
||||
private static final Field CHILDREN_FIELD;
|
||||
private static final Field LITERALS_FIELD;
|
||||
private static final Field ARGUMENTS_FIELD;
|
|
@ -1,7 +1,7 @@
|
|||
name: ${name}
|
||||
name: ${coreName}
|
||||
description: ${description}
|
||||
version: ${version}
|
||||
main: dev.xhyrom.lighteco.bukkit.BukkitLightEcoLoader
|
||||
main: dev.xhyrom.lighteco.paper.PaperLightEcoLoader
|
||||
author: ${author}
|
||||
api-version: 1.16
|
||||
load: STARTUP
|
|
@ -3,7 +3,7 @@ rootProject.name = "lighteco-parent"
|
|||
sequenceOf(
|
||||
"api",
|
||||
"common",
|
||||
"bukkit",
|
||||
"paper",
|
||||
"bukkittest",
|
||||
"sponge-8",
|
||||
"currency-money"
|
||||
|
|
Loading…
Reference in a new issue