From f69c244080a010c58e0fe1fe14d944d540c343df Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Fri, 13 Aug 2021 10:39:35 -0400 Subject: [PATCH] New command manager --- src/main/java/com/volmit/iris/Iris.java | 15 +---- .../com/volmit/iris/core/CommandManager.java | 64 +++++++++++++++++++ 2 files changed, 67 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/volmit/iris/core/CommandManager.java diff --git a/src/main/java/com/volmit/iris/Iris.java b/src/main/java/com/volmit/iris/Iris.java index 2c64fc8ce..76eb3cc77 100644 --- a/src/main/java/com/volmit/iris/Iris.java +++ b/src/main/java/com/volmit/iris/Iris.java @@ -79,7 +79,7 @@ import java.net.URL; import java.util.Date; @SuppressWarnings("CanBeFinal") -public class Iris extends VolmitPlugin implements Listener, DecreeSystem { +public class Iris extends VolmitPlugin implements Listener { public static KList executors = new KList<>(); public static Iris instance; public static BukkitAudiences audiences; @@ -91,6 +91,7 @@ public class Iris extends VolmitPlugin implements Listener, DecreeSystem { public static MultiverseCoreLink linkMultiverseCore; public static OraxenLink linkOraxen; public static MythicMobsLink linkMythicMobs; + public static CommandManager commandManager; public static TreeManager saplingManager; private static final Queue syncJobs = new ShurikenQueue<>(); public static IrisCompat compat; @@ -130,6 +131,7 @@ public class Iris extends VolmitPlugin implements Listener, DecreeSystem { saplingManager = new TreeManager(); edit = new EditManager(); configWatcher = new FileWatcher(getDataFile("settings.json")); + commandManager = new CommandManager(); getServer().getPluginManager().registerEvents(new CommandLocate(), this); getServer().getPluginManager().registerEvents(new WandManager(), this); getServer().getPluginManager().registerEvents(new DolphinManager(), this); @@ -723,15 +725,4 @@ public class Iris extends VolmitPlugin implements Listener, DecreeSystem { } } - - /** - * Should return the root command class
- * DecreeSystem extends {@link DecreeCommand} so don't bother implementing both on the root class - * - * @return The root command class - */ - @Override - public Class getRoot() { - return this.getClass(); - } } diff --git a/src/main/java/com/volmit/iris/core/CommandManager.java b/src/main/java/com/volmit/iris/core/CommandManager.java new file mode 100644 index 000000000..5411c9873 --- /dev/null +++ b/src/main/java/com/volmit/iris/core/CommandManager.java @@ -0,0 +1,64 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.volmit.iris.core; + +import com.volmit.iris.Iris; +import com.volmit.iris.core.decrees.DecreeIris; +import com.volmit.iris.engine.data.cache.AtomicCache; +import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.decree.DecreeCommand; +import com.volmit.iris.util.decree.DecreeSystem; +import com.volmit.iris.util.decree.virtual.VirtualDecreeCommand; +import com.volmit.iris.util.plugin.VolmitSender; +import com.volmit.iris.util.scheduling.J; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.server.ServerCommandEvent; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.Console; +import java.util.List; + +public class CommandManager implements DecreeSystem { + private final transient AtomicCache commandCache = new AtomicCache<>(); + private final transient AtomicCache> startsCache = new AtomicCache<>(); + + public CommandManager(){ + Iris.instance.getCommand("irisd").setExecutor(this); + } + + @Override + public VirtualDecreeCommand getRoot() { + return commandCache.aquire(() -> { + try { + return VirtualDecreeCommand.createRoot(new DecreeIris()); + } catch (Throwable e) { + e.printStackTrace(); + } + + return null; + }); + } +}