mirror of
https://github.com/SimplexDevelopment/FreedomNetworkSuite.git
synced 2025-06-28 04:06:40 +00:00
Create Cladis (NetworkManager Hook)
Signed-off-by: Paul Reilly <pawereus@gmail.com>
This commit is contained in:
@ -23,9 +23,11 @@
|
||||
|
||||
package fns.patchwork.command;
|
||||
|
||||
import java.util.Objects;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.reflections.Reflections;
|
||||
|
||||
/**
|
||||
* Handles the registration of commands. The plugin which initializes this class should be the plugin that is
|
||||
@ -64,4 +66,32 @@ public class CommandHandler
|
||||
Bukkit.getCommandMap()
|
||||
.register(plugin.getName(), delegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers all commands in the specified package that contains the provided class. This method will automatically
|
||||
* delegate the command information to the Bukkit API and register with the {@link CommandMap}.
|
||||
*
|
||||
* @param commandClass The class to register commands from.
|
||||
* @param <T> The type of the command.
|
||||
*/
|
||||
public <T extends Commander> void registerCommands(final Class<T> commandClass)
|
||||
{
|
||||
final Reflections reflections = new Reflections(commandClass.getPackageName());
|
||||
reflections.getSubTypesOf(commandClass)
|
||||
.stream()
|
||||
.map(c ->
|
||||
{
|
||||
try
|
||||
{
|
||||
return c.getDeclaredConstructor(JavaPlugin.class).newInstance(this);
|
||||
}
|
||||
catch (ReflectiveOperationException ex)
|
||||
{
|
||||
plugin.getSLF4JLogger().error("Unable to register command: " + c.getName(), ex);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.forEach(this::registerCommand);
|
||||
}
|
||||
}
|
||||
|
@ -23,8 +23,6 @@
|
||||
|
||||
package fns.patchwork.provider;
|
||||
|
||||
import fns.patchwork.command.BukkitDelegate;
|
||||
import fns.patchwork.command.annotation.Subcommand;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@ -33,8 +31,8 @@ import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -65,12 +63,13 @@ public class ContextProvider
|
||||
public <T> T fromString(final String string, final Class<T> clazz)
|
||||
{
|
||||
return Stream.of(toBoolean(string, clazz),
|
||||
toLong(string, clazz),
|
||||
toDouble(string, clazz),
|
||||
toInt(string, clazz),
|
||||
toLong(string, clazz),
|
||||
toFloat(string, clazz),
|
||||
toMaterial(string, clazz),
|
||||
toPlayer(string, clazz),
|
||||
toOfflinePlayer(string, clazz),
|
||||
toWorld(string, clazz),
|
||||
toLocation(string, clazz),
|
||||
toComponent(string, clazz))
|
||||
@ -127,7 +126,7 @@ public class ContextProvider
|
||||
|
||||
private @Nullable Long toLong(final String string, final Class<?> clazz)
|
||||
{
|
||||
if (clazz != Long.class)
|
||||
if (clazz != Long.class || string.endsWith("L"))
|
||||
return null;
|
||||
|
||||
try
|
||||
@ -169,6 +168,16 @@ public class ContextProvider
|
||||
return Bukkit.getPlayer(string);
|
||||
}
|
||||
|
||||
private OfflinePlayer toOfflinePlayer(final String string, final Class<?> clazz)
|
||||
{
|
||||
if (clazz != OfflinePlayer.class)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return Bukkit.getOfflinePlayer(string);
|
||||
}
|
||||
|
||||
private @Nullable World toWorld(final String string, final Class<?> clazz)
|
||||
{
|
||||
if (clazz != World.class)
|
||||
|
Reference in New Issue
Block a user