New command manager

This commit is contained in:
cyberpwn 2021-08-13 10:39:35 -04:00
parent f1b4a973a8
commit f69c244080
2 changed files with 67 additions and 12 deletions

View File

@ -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<GroupedExecutor> 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<Runnable> 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<br>
* DecreeSystem extends {@link DecreeCommand} so don't bother implementing both on the root class
*
* @return The root command class
*/
@Override
public Class<? extends DecreeCommand> getRoot() {
return this.getClass();
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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<VirtualDecreeCommand> commandCache = new AtomicCache<>();
private final transient AtomicCache<KList<String>> 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;
});
}
}