mirror of
https://github.com/plexusorg/Sunburst.git
synced 2025-02-05 14:36:11 +00:00
Add clearinventory command + reflections
This commit is contained in:
parent
6e30af29f8
commit
50ee0e2677
9 changed files with 192 additions and 31 deletions
20
.gitignore
vendored
20
.gitignore
vendored
|
@ -1,6 +1,16 @@
|
||||||
/.gradle/
|
|
||||||
/**/*/build/
|
|
||||||
/build/
|
|
||||||
/.idea/
|
/.idea/
|
||||||
/**/*/gradle/
|
*.iml
|
||||||
/**/*/gradlew*
|
/target/
|
||||||
|
|
||||||
|
# OS
|
||||||
|
.DS_Store
|
||||||
|
._*
|
||||||
|
.Spotlight-V100
|
||||||
|
.Trashes
|
||||||
|
ehthumbs.db
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# Gradle
|
||||||
|
/build/
|
||||||
|
/*/build/
|
||||||
|
/.gradle/
|
|
@ -8,8 +8,8 @@ dependencies {
|
||||||
compileOnly("io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT")
|
compileOnly("io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT")
|
||||||
implementation(project(":sunburst-api"))
|
implementation(project(":sunburst-api"))
|
||||||
|
|
||||||
library("org.projectlombok:lombok:1.18.22")
|
library("org.projectlombok:lombok:1.18.24")
|
||||||
annotationProcessor("org.projectlombok:lombok:1.18.22")
|
annotationProcessor("org.projectlombok:lombok:1.18.24")
|
||||||
|
|
||||||
library("org.json:json:20220320")
|
library("org.json:json:20220320")
|
||||||
library("org.apache.httpcomponents:httpclient:4.5.13")
|
library("org.apache.httpcomponents:httpclient:4.5.13")
|
||||||
|
@ -19,6 +19,9 @@ bukkit {
|
||||||
name = "Sunburst"
|
name = "Sunburst"
|
||||||
version = project.version as String
|
version = project.version as String
|
||||||
main = "dev.plex.Sunburst"
|
main = "dev.plex.Sunburst"
|
||||||
|
website = "https://plex.us.org"
|
||||||
|
authors = listOf("Taahh", "Telesphoreo")
|
||||||
|
apiVersion = "1.18"
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
package dev.plex;
|
package dev.plex;
|
||||||
|
|
||||||
import dev.plex.command.impl.*;
|
import dev.plex.handler.CommandHandler;
|
||||||
import dev.plex.listener.impl.player.ChatListener;
|
import dev.plex.handler.ListenerHandler;
|
||||||
import dev.plex.listener.impl.player.GodListener;
|
|
||||||
import dev.plex.listener.impl.player.JoinListener;
|
|
||||||
import dev.plex.listener.impl.player.SpawnListener;
|
|
||||||
import dev.plex.permission.PermissionHandlerImpl;
|
import dev.plex.permission.PermissionHandlerImpl;
|
||||||
import dev.plex.player.ISunburstPlayer;
|
import dev.plex.player.ISunburstPlayer;
|
||||||
import dev.plex.player.PlayerCache;
|
import dev.plex.player.PlayerCache;
|
||||||
|
@ -46,7 +43,8 @@ public final class Sunburst extends SunburstPlugin
|
||||||
this.messages.load();
|
this.messages.load();
|
||||||
|
|
||||||
this.getObjectHolder().setPermissionHandler(new PermissionHandlerImpl());
|
this.getObjectHolder().setPermissionHandler(new PermissionHandlerImpl());
|
||||||
this.getObjectHolder().setChatRenderer((source, sourceDisplayName, message, viewer) -> {
|
this.getObjectHolder().setChatRenderer((source, sourceDisplayName, message, viewer) ->
|
||||||
|
{
|
||||||
Logger.log("Spokenz");
|
Logger.log("Spokenz");
|
||||||
Logger.log(ComponentUtil.mmCustom(sourceDisplayName, ComponentUtil.REGULAR_TAGS));
|
Logger.log(ComponentUtil.mmCustom(sourceDisplayName, ComponentUtil.REGULAR_TAGS));
|
||||||
return ComponentUtil.configComponent("chatFormat",
|
return ComponentUtil.configComponent("chatFormat",
|
||||||
|
@ -61,22 +59,12 @@ public final class Sunburst extends SunburstPlugin
|
||||||
@Override
|
@Override
|
||||||
public void onEnable()
|
public void onEnable()
|
||||||
{
|
{
|
||||||
|
new ListenerHandler();
|
||||||
|
new CommandHandler();
|
||||||
|
|
||||||
this.getObjectHolder().setStorageSystem(new FileStorage());
|
this.getObjectHolder().setStorageSystem(new FileStorage());
|
||||||
this.jsonWorldManager = new JsonWorldManager();
|
this.jsonWorldManager = new JsonWorldManager();
|
||||||
|
|
||||||
new JoinListener();
|
|
||||||
new ChatListener();
|
|
||||||
new GodListener();
|
|
||||||
new SpawnListener();
|
|
||||||
|
|
||||||
new NicknameCMD();
|
|
||||||
new SunburstCMD();
|
|
||||||
new MessageCMD();
|
|
||||||
new ReplyCMD();
|
|
||||||
new GodCMD();
|
|
||||||
new SetSpawnCMD();
|
|
||||||
new SpawnCMD();
|
|
||||||
|
|
||||||
Bukkit.getOnlinePlayers().forEach(player ->
|
Bukkit.getOnlinePlayers().forEach(player ->
|
||||||
{
|
{
|
||||||
ISunburstPlayer sunburstPlayer = plugin.getObjectHolder().getStorageSystem().getPlayer(player.getUniqueId());
|
ISunburstPlayer sunburstPlayer = plugin.getObjectHolder().getStorageSystem().getPlayer(player.getUniqueId());
|
||||||
|
@ -96,7 +84,8 @@ public final class Sunburst extends SunburstPlugin
|
||||||
@Override
|
@Override
|
||||||
public void onDisable()
|
public void onDisable()
|
||||||
{
|
{
|
||||||
plugin.getPlayerCache().getPlayers().forEach(sunburstPlayer -> {
|
plugin.getPlayerCache().getPlayers().forEach(sunburstPlayer ->
|
||||||
|
{
|
||||||
plugin.getObjectHolder().getStorageSystem().updatePlayer(sunburstPlayer);
|
plugin.getObjectHolder().getStorageSystem().updatePlayer(sunburstPlayer);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package dev.plex.command.impl;
|
||||||
|
|
||||||
|
import dev.plex.command.SunburstCommand;
|
||||||
|
import dev.plex.command.util.CommandInfo;
|
||||||
|
import dev.plex.command.util.CommandPerms;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
@CommandInfo(name = "clearinventory", description = "Clears your inventory, or optionally a different player", usage = "/<command> [player]", aliases = {"clear", "ci", "clearinv", "clean"})
|
||||||
|
@CommandPerms(permission = "sunburst.command.clearinventory")
|
||||||
|
public class ClearInventoryCMD extends SunburstCommand
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Component execute(@NotNull CommandSender sender, @Nullable Player player, String[] args)
|
||||||
|
{
|
||||||
|
if (args.length == 0)
|
||||||
|
{
|
||||||
|
if (sender instanceof ConsoleCommandSender)
|
||||||
|
{
|
||||||
|
return usage();
|
||||||
|
}
|
||||||
|
if (player != null)
|
||||||
|
{
|
||||||
|
player.getInventory().clear();
|
||||||
|
}
|
||||||
|
return confMsg("clearedInventory");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,11 +1,9 @@
|
||||||
package dev.plex.command.impl;
|
package dev.plex.command.impl;
|
||||||
|
|
||||||
import dev.plex.Sunburst;
|
|
||||||
import dev.plex.command.SunburstCommand;
|
import dev.plex.command.SunburstCommand;
|
||||||
import dev.plex.command.util.CommandInfo;
|
import dev.plex.command.util.CommandInfo;
|
||||||
import dev.plex.command.util.CommandPerms;
|
import dev.plex.command.util.CommandPerms;
|
||||||
import dev.plex.command.util.RequiredSource;
|
import dev.plex.command.util.RequiredSource;
|
||||||
import dev.plex.util.ComponentUtil;
|
|
||||||
import dev.plex.util.XYZLocation;
|
import dev.plex.util.XYZLocation;
|
||||||
import dev.plex.world.WorldSettingsImpl;
|
import dev.plex.world.WorldSettingsImpl;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
@ -25,7 +23,9 @@ public class SetSpawnCMD extends SunburstCommand
|
||||||
if (plugin.getWorldManager().getSettings(player.getWorld()) != null)
|
if (plugin.getWorldManager().getSettings(player.getWorld()) != null)
|
||||||
{
|
{
|
||||||
plugin.getWorldManager().getSettings(player.getWorld()).spawnLocation(location);
|
plugin.getWorldManager().getSettings(player.getWorld()).spawnLocation(location);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
WorldSettingsImpl worldSettings = new WorldSettingsImpl();
|
WorldSettingsImpl worldSettings = new WorldSettingsImpl();
|
||||||
worldSettings.world(player.getWorld());
|
worldSettings.world(player.getWorld());
|
||||||
worldSettings.spawnLocation(location);
|
worldSettings.spawnLocation(location);
|
||||||
|
|
33
server/src/main/java/dev/plex/handler/CommandHandler.java
Normal file
33
server/src/main/java/dev/plex/handler/CommandHandler.java
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
package dev.plex.handler;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import dev.plex.command.SunburstCommand;
|
||||||
|
import dev.plex.util.Logger;
|
||||||
|
import dev.plex.util.ReflectionsUtil;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
// Reflections from Plex, done by Fleek
|
||||||
|
public class CommandHandler
|
||||||
|
{
|
||||||
|
public CommandHandler()
|
||||||
|
{
|
||||||
|
Set<Class<? extends SunburstCommand>> commandSet = ReflectionsUtil.getClassesBySubType("dev.plex.command.impl", SunburstCommand.class);
|
||||||
|
List<SunburstCommand> commands = Lists.newArrayList();
|
||||||
|
|
||||||
|
commandSet.forEach(clazz ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
commands.add(clazz.getConstructor().newInstance());
|
||||||
|
}
|
||||||
|
catch (InvocationTargetException | InstantiationException | IllegalAccessException |
|
||||||
|
NoSuchMethodException ex)
|
||||||
|
{
|
||||||
|
Logger.error("Failed to register " + clazz.getSimpleName() + " as a command!");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Logger.log(String.format("Registered %s commands from %s classes!", commands.size(), commandSet.size()));
|
||||||
|
}
|
||||||
|
}
|
33
server/src/main/java/dev/plex/handler/ListenerHandler.java
Normal file
33
server/src/main/java/dev/plex/handler/ListenerHandler.java
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
package dev.plex.handler;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import dev.plex.listener.SunburstListener;
|
||||||
|
import dev.plex.util.Logger;
|
||||||
|
import dev.plex.util.ReflectionsUtil;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
// Reflections from Plex, done by Fleek
|
||||||
|
public class ListenerHandler
|
||||||
|
{
|
||||||
|
public ListenerHandler()
|
||||||
|
{
|
||||||
|
Set<Class<? extends SunburstListener>> listenerSet = ReflectionsUtil.getClassesBySubType("dev.plex.listener.impl.player", SunburstListener.class);
|
||||||
|
List<SunburstListener> listeners = Lists.newArrayList();
|
||||||
|
|
||||||
|
listenerSet.forEach(clazz ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
listeners.add(clazz.getConstructor().newInstance());
|
||||||
|
}
|
||||||
|
catch (InvocationTargetException | InstantiationException | IllegalAccessException |
|
||||||
|
NoSuchMethodException ex)
|
||||||
|
{
|
||||||
|
Logger.error("Failed to register " + clazz.getSimpleName() + " as a listener!");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Logger.log(String.format("Registered %s listeners from %s classes!", listeners.size(), listenerSet.size()));
|
||||||
|
}
|
||||||
|
}
|
57
server/src/main/java/dev/plex/util/ReflectionsUtil.java
Normal file
57
server/src/main/java/dev/plex/util/ReflectionsUtil.java
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
package dev.plex.util;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.reflect.ClassPath;
|
||||||
|
import dev.plex.Sunburst;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class ReflectionsUtil
|
||||||
|
{
|
||||||
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
|
public static Set<Class<?>> getClassesFrom(String packageName)
|
||||||
|
{
|
||||||
|
Set<Class<?>> classes = new HashSet<>();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ClassPath path = ClassPath.from(Sunburst.class.getClassLoader());
|
||||||
|
ImmutableSet<ClassPath.ClassInfo> infoSet = path.getTopLevelClasses(packageName);
|
||||||
|
infoSet.forEach(info ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Class<?> clazz = Class.forName(info.getName());
|
||||||
|
classes.add(clazz);
|
||||||
|
}
|
||||||
|
catch (ClassNotFoundException ex)
|
||||||
|
{
|
||||||
|
Logger.error("Unable to find class " + info.getName() + " in " + packageName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
Logger.error("Something went wrong while fetching classes from " + packageName);
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
return Collections.unmodifiableSet(classes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static <T> Set<Class<? extends T>> getClassesBySubType(String packageName, Class<T> subType)
|
||||||
|
{
|
||||||
|
Set<Class<?>> loadedClasses = getClassesFrom(packageName);
|
||||||
|
Set<Class<? extends T>> classes = new HashSet<>();
|
||||||
|
loadedClasses.forEach(clazz ->
|
||||||
|
{
|
||||||
|
if (clazz.getSuperclass() == subType || Arrays.asList(clazz.getInterfaces()).contains(subType))
|
||||||
|
{
|
||||||
|
classes.add((Class<? extends T>)clazz);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return Collections.unmodifiableSet(classes);
|
||||||
|
}
|
||||||
|
}
|
|
@ -49,3 +49,5 @@ messengerNotFound: "<red>You have not messaged anyone!"
|
||||||
godModeToggle: "<gold>God mode has been turned {0}"
|
godModeToggle: "<gold>God mode has been turned {0}"
|
||||||
|
|
||||||
spawnSet: "<green>This world's spawn location has been set!"
|
spawnSet: "<green>This world's spawn location has been set!"
|
||||||
|
|
||||||
|
clearedInventory: "<gold>Your inventory has been cleared."
|
Loading…
Reference in a new issue