diff --git a/.gitignore b/.gitignore index fb7e571b..cfe9fa50 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ .idea/dictionaries .idea/misc.xml .idea/libraries +.idea/kotlinc.xml # Package Files # diff --git a/commands.iml b/commands.iml index a4adc74c..dc5f4005 100644 --- a/commands.iml +++ b/commands.iml @@ -1,6 +1,15 @@ - - + + + + + + PAPER + + + + + diff --git a/src/main/java/co/aikar/commands/ACF.java b/src/main/java/co/aikar/commands/ACF.java new file mode 100644 index 00000000..8c5b6ed0 --- /dev/null +++ b/src/main/java/co/aikar/commands/ACF.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2016-2017 Daniel Ennis (Aikar) - MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package co.aikar.commands; + +import co.aikar.commands.managers.BukkitCommandManager; +import co.aikar.commands.managers.CommandManager; +import co.aikar.commands.managers.PaperCommandManager; +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; + +/** + * Aikar Command Framework + */ +public final class ACF { + private ACF() {} + + /** + * Creates a manager for your current supported platform. + * @param plugin Bukkit Plugin + * @return Command Manager + */ + public CommandManager createManager(Plugin plugin) { + try { + Class.forName("com.destroystokyo.paper.PaperConfig"); + return new PaperCommandManager(plugin); + } catch (ClassNotFoundException ignored) {} + return new BukkitCommandManager(plugin); + } +} diff --git a/src/main/java/co/aikar/commands/managers/BukkitCommandManager.java b/src/main/java/co/aikar/commands/managers/BukkitCommandManager.java new file mode 100644 index 00000000..95d1a919 --- /dev/null +++ b/src/main/java/co/aikar/commands/managers/BukkitCommandManager.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2016-2017 Daniel Ennis (Aikar) - MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package co.aikar.commands.managers; + +import co.aikar.commands.BaseCommand; +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; + +public class BukkitCommandManager implements CommandManager { + + @SuppressWarnings("WeakerAccess") + protected final Plugin plugin; + + public BukkitCommandManager(Plugin plugin) { + this.plugin = plugin; + } + + @Override + public boolean register(BaseCommand command) { + return Bukkit.getServer().getCommandMap().register(this.plugin.getDescription().getName(), command); + } + + @Override + public boolean register(BaseCommand command, String commandName) { + return Bukkit.getServer().getCommandMap().register(commandName, this.plugin.getDescription().getName(), command); + } +} diff --git a/src/main/java/co/aikar/commands/managers/CommandManager.java b/src/main/java/co/aikar/commands/managers/CommandManager.java new file mode 100644 index 00000000..0113a407 --- /dev/null +++ b/src/main/java/co/aikar/commands/managers/CommandManager.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2016-2017 Daniel Ennis (Aikar) - MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package co.aikar.commands.managers; + +import co.aikar.commands.BaseCommand; + +public interface CommandManager { + + /** + * Registers a command with ACF + * + * @param command The command to register + * @return boolean + */ + boolean register(BaseCommand command); + + /** + * Registers a command with ACF + * + * @param command The command to register + * @param commandName Specific command name to register as + * @return boolean + */ + boolean register(BaseCommand command, String commandName); +} diff --git a/src/main/java/co/aikar/commands/managers/PaperCommandManager.java b/src/main/java/co/aikar/commands/managers/PaperCommandManager.java new file mode 100644 index 00000000..4b3df50e --- /dev/null +++ b/src/main/java/co/aikar/commands/managers/PaperCommandManager.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2016-2017 Daniel Ennis (Aikar) - MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package co.aikar.commands.managers; + +import org.bukkit.plugin.Plugin; + +public class PaperCommandManager extends BukkitCommandManager { + + // If we get anything Paper specific + public PaperCommandManager(Plugin plugin) { + super(plugin); + } +}