From bbaa325ad6d240bc29f3fbb7691f84e6617eb728 Mon Sep 17 00:00:00 2001 From: Paul Reilly Date: Fri, 11 Aug 2023 14:08:49 -0500 Subject: [PATCH 1/3] Create Cladis (NetworkManager Hook) Signed-off-by: Paul Reilly --- Cladis/.gitignore | 42 ++++ Cladis/build.gradle | 25 ++ Cladis/src/main/java/fns/cladis/Cladis.java | 45 ++++ Cladis/src/main/java/fns/cladis/NMLink.java | 118 ++++++++++ .../java/fns/cladis/command/DeopCommand.java | 64 ++++++ .../fns/cladis/command/ModStaffCommand.java | 217 ++++++++++++++++++ .../java/fns/cladis/command/OpCommand.java | 65 ++++++ .../fns/patchwork/command/CommandHandler.java | 30 +++ .../patchwork/provider/ContextProvider.java | 19 +- settings.gradle | 2 +- 10 files changed, 621 insertions(+), 6 deletions(-) create mode 100644 Cladis/.gitignore create mode 100644 Cladis/build.gradle create mode 100644 Cladis/src/main/java/fns/cladis/Cladis.java create mode 100644 Cladis/src/main/java/fns/cladis/NMLink.java create mode 100644 Cladis/src/main/java/fns/cladis/command/DeopCommand.java create mode 100644 Cladis/src/main/java/fns/cladis/command/ModStaffCommand.java create mode 100644 Cladis/src/main/java/fns/cladis/command/OpCommand.java diff --git a/Cladis/.gitignore b/Cladis/.gitignore new file mode 100644 index 0000000..b63da45 --- /dev/null +++ b/Cladis/.gitignore @@ -0,0 +1,42 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/Cladis/build.gradle b/Cladis/build.gradle new file mode 100644 index 0000000..16166a3 --- /dev/null +++ b/Cladis/build.gradle @@ -0,0 +1,25 @@ +plugins { + id 'java' +} + +group = 'fns.cladis' +version = '1.0.0' + +repositories { + mavenCentral() + maven { + url 'https://repo.networkmanager.xyz/repository/maven-public/' + } +} + +dependencies { + compileOnly project(":Patchwork") + compileOnly 'nl.chimpgamer.networkmanager:api:2.13.1' + + testImplementation platform('org.junit:junit-bom:5.9.1') + testImplementation 'org.junit.jupiter:junit-jupiter' +} + +test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/Cladis/src/main/java/fns/cladis/Cladis.java b/Cladis/src/main/java/fns/cladis/Cladis.java new file mode 100644 index 0000000..5222bec --- /dev/null +++ b/Cladis/src/main/java/fns/cladis/Cladis.java @@ -0,0 +1,45 @@ +package fns.cladis; + +import fns.cladis.command.OpCommand; +import fns.patchwork.base.Registration; +import fns.patchwork.command.CommandHandler; +import org.bukkit.plugin.java.JavaPlugin; + +public class Cladis extends JavaPlugin +{ + private NMLink nmLink; + + @Override + public void onEnable() + { + if (this.getServer().getPluginManager().getPlugin("NetworkManager") == null) + { + getLogger().severe("NetworkManager not found! Disabling Cladis..."); + this.getServer().getPluginManager().disablePlugin(this); + return; + } + + this.nmLink = new NMLink(this); + + new CommandHandler(this).registerCommands(OpCommand.class); + + Registration.getModuleRegistry() + .addModule(this); + + getLogger().info("Cladis enabled!"); + } + + @Override + public void onDisable() + { + Registration.getModuleRegistry() + .removeModule(this); + + getLogger().info("Cladis disabled!"); + } + + public NMLink getNMLink() + { + return this.nmLink; + } +} diff --git a/Cladis/src/main/java/fns/cladis/NMLink.java b/Cladis/src/main/java/fns/cladis/NMLink.java new file mode 100644 index 0000000..4e456b0 --- /dev/null +++ b/Cladis/src/main/java/fns/cladis/NMLink.java @@ -0,0 +1,118 @@ +package fns.cladis; + +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; +import nl.chimpgamer.networkmanager.api.NetworkManagerPlugin; +import nl.chimpgamer.networkmanager.api.NetworkManagerProvider; +import nl.chimpgamer.networkmanager.api.cache.CacheManager; +import nl.chimpgamer.networkmanager.api.models.permissions.Group; +import nl.chimpgamer.networkmanager.api.models.permissions.PermissionPlayer; +import nl.chimpgamer.networkmanager.api.models.player.Player; + +public class NMLink +{ + private NetworkManagerPlugin networkManager; + + public NMLink(final Cladis plugin) + { + this.networkManager = NetworkManagerProvider.Companion.get(); + plugin.getSLF4JLogger().info("NetworkManager successfully linked!"); + } + + public CacheManager getCacheManager() + { + return this.networkManager.getCacheManager(); + } + + public Optional getPlayer(final UUID uuid) + { + return getCacheManager().getCachedPlayers().getPlayerSafe(uuid); + } + + public PermissionPlayer getPermissionsPlayer(final UUID uuid) + { + return networkManager.getPermissionManager().getPermissionPlayer(uuid); + } + + public List getPlayerGroups(final UUID uuid) + { + return getPermissionsPlayer(uuid).getGroups(); + } + + public Map getLoadedGroups() + { + return networkManager.getPermissionManager().getGroups(); + } + + public Optional locateGroup(final String name) + { + return Optional.of(networkManager.getPermissionManager().getGroup(name)); + } + + public Group opGroup() + { + return locateGroup("fake_op").orElse(null); + } + + public Group deopGroup() + { + return locateGroup("fake_deop").orElse(null); + } + + public Group masterBuilderGroup() + { + return locateGroup("master_builder").orElse(null); + } + + public Group adminGroup() + { + return locateGroup("admin").orElse(null); + } + + public Group seniorGroup() + { + return locateGroup("senior").orElse(null); + } + + public Group devGroup() + { + return locateGroup("developer").orElse(null); + } + + public Group execGroup() + { + return locateGroup("executive").orElse(null); + } + + public boolean isOp(final UUID uuid) + { + return getPlayerGroups(uuid).contains(opGroup()); + } + + public boolean isDeop(final UUID uuid) + { + return getPlayerGroups(uuid).contains(deopGroup()); + } + + public boolean isAdmin(final UUID uuid) + { + return getPlayerGroups(uuid).contains(seniorGroup()) || getPlayerGroups(uuid).contains(adminGroup()); + } + + public boolean isSenior(final UUID uuid) + { + return getPlayerGroups(uuid).contains(seniorGroup()); + } + + public boolean isDev(final UUID uuid) + { + return getPlayerGroups(uuid).contains(devGroup()); + } + + public boolean isExec(final UUID uuid) + { + return getPlayerGroups(uuid).contains(execGroup()); + } +} diff --git a/Cladis/src/main/java/fns/cladis/command/DeopCommand.java b/Cladis/src/main/java/fns/cladis/command/DeopCommand.java new file mode 100644 index 0000000..fe9aff8 --- /dev/null +++ b/Cladis/src/main/java/fns/cladis/command/DeopCommand.java @@ -0,0 +1,64 @@ +package fns.cladis.command; + +import fns.cladis.Cladis; +import fns.cladis.NMLink; +import fns.patchwork.base.Shortcuts; +import fns.patchwork.command.Commander; +import fns.patchwork.command.annotation.Completion; +import fns.patchwork.command.annotation.Info; +import fns.patchwork.command.annotation.Permissive; +import fns.patchwork.command.annotation.Subcommand; +import nl.chimpgamer.networkmanager.api.models.permissions.Group; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; + +@Info( + name = "deop", + description = "Deop a player.", + usage = "/deop " +) +@Permissive(perm = "cladis.deop") +@Completion(index = 0, args = {"%player%"}) +public class DeopCommand extends Commander +{ + + /** + * Initializes this command object. The provided {@link JavaPlugin} should be the plugin which contains the + * command. + *

+ * This constructor will automatically register all subcommands and completions for this command. It will also + * automatically infer all required information from the provided {@link Info} and {@link Permissive} annotations. + * + * @param plugin The plugin which contains this command. + */ + protected DeopCommand(@NotNull final JavaPlugin plugin) + { + super(plugin); + } + + @Subcommand(permission = "cladis.deop", args = {Player.class}) + public void deop(final CommandSender sender, final Player player) + { + final NMLink nmLink = Shortcuts.provideModule(Cladis.class).getNMLink(); + final Group opGroup = nmLink.deopGroup(); + + if (opGroup == null) + { + sender.sendPlainMessage("Unable to deop player. Please contact an administrator."); + return; + } + + if (nmLink.isDeop(player.getUniqueId())) + { + sender.sendPlainMessage("Player is not op."); + return; + } + + nmLink.getPlayerGroups(player.getUniqueId()).remove(opGroup); + + sender.sendPlainMessage("Player deopped."); + player.sendPlainMessage("You have been deopped!"); + } +} diff --git a/Cladis/src/main/java/fns/cladis/command/ModStaffCommand.java b/Cladis/src/main/java/fns/cladis/command/ModStaffCommand.java new file mode 100644 index 0000000..8c25953 --- /dev/null +++ b/Cladis/src/main/java/fns/cladis/command/ModStaffCommand.java @@ -0,0 +1,217 @@ +package fns.cladis.command; + +import fns.cladis.Cladis; +import fns.cladis.NMLink; +import fns.patchwork.base.Shortcuts; +import fns.patchwork.command.Commander; +import fns.patchwork.command.annotation.Base; +import fns.patchwork.command.annotation.Completion; +import fns.patchwork.command.annotation.Info; +import fns.patchwork.command.annotation.Permissive; +import fns.patchwork.command.annotation.Subcommand; +import java.util.Map; +import nl.chimpgamer.networkmanager.api.models.permissions.Group; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; + +@Info( + name = "modstaff", + description = "Mod a player.", + usage = """ + /modstaff + /modstaff info + /modstaff + /modstaff + """, + aliases = {"ms", "saconfig", "adminlist", "al"} +) +@Permissive(perm = "cladis.modstaff") +@Completion(index = 0, args = {"info", "add", "remove", "promote", "demote"}) +@Completion(index = 1, args = {"%player%"}) +@Completion(index = 2, args = {""}) +public class ModStaffCommand extends Commander +{ + + public static final String USER_NOT_FOUND = "That user does not exist!"; + + /** + * Initializes this command object. The provided {@link JavaPlugin} should be the plugin which contains the + * command. + *

+ * This constructor will automatically register all subcommands and completions for this command. It will also + * automatically infer all required information from the provided {@link Info} and {@link Permissive} annotations. + * + * @param plugin The plugin which contains this command. + */ + public ModStaffCommand(@NotNull final JavaPlugin plugin) + { + super(plugin); + } + + @Base + public void base(final CommandSender sender) + { + final NMLink nmLink = Shortcuts.provideModule(Cladis.class).getNMLink(); + final StringBuilder stringBuilder = new StringBuilder(); + nmLink.getCacheManager() + .getCachedPlayers() + .getPlayers() + .forEach((u, p) -> + { + if (nmLink.isAdmin(u) || nmLink.isSenior(u)) + { + stringBuilder.append(nmLink.getPermissionsPlayer(u) + .getPrimaryGroup() + .getPrefixes() + .values() + .stream() + .findFirst() + .orElseGet(() -> "[Admin]")) + .append(" ") + .append(p.getName()).append(", "); + } + }); + + sender.sendPlainMessage(stringBuilder.toString()); + } + + @Subcommand(permission = "cladis.modstaff.info", args = {String.class, Player.class}) + public void info(final CommandSender sender, final String info, final Player player) + { + if (!info.equalsIgnoreCase("info")) + return; + + final NMLink nmLink = Shortcuts.provideModule(Cladis.class).getNMLink(); + final StringBuilder stringBuilder = new StringBuilder(); + final nl.chimpgamer.networkmanager.api.models.player.Player nmPlayer = + nmLink.getPlayer(player.getUniqueId()).orElse(null); + + if (nmPlayer == null) + { + sender.sendPlainMessage(USER_NOT_FOUND); + return; + } + + stringBuilder.append("Player: ") + .append(player.getName()) + .append("\n"); + stringBuilder.append("UUID: ") + .append(nmPlayer.getUuid()) + .append("\n"); + stringBuilder.append("Rank: ") + .append(nmLink.getPermissionsPlayer(player.getUniqueId()).getPrimaryGroup().getName()) + .append("\n"); + stringBuilder.append("IP: ") + .append(nmPlayer.getIp()) + .append("\n"); + stringBuilder.append("Playtime: ") + .append(nmPlayer.getPlaytime()) + .append("\n"); + stringBuilder.append("Last Online: ") + .append(nmPlayer.getLastlogin()) + .append("\n"); + + sender.sendPlainMessage(stringBuilder.toString()); + } + + @Subcommand(permission = "cladis.modstaff.modify", args = {String.class, Player.class, String.class}) + public void modify(final CommandSender sender, final String arg, final Player target, final String group) + { + final NMLink nmLink = Shortcuts.provideModule(Cladis.class).getNMLink(); + final nl.chimpgamer.networkmanager.api.models.player.Player nmPlayer = + nmLink.getPlayer(target.getUniqueId()).orElse(null); + + if (nmPlayer == null) + { + sender.sendPlainMessage(USER_NOT_FOUND); + return; + } + + final Map.Entry g = + nmLink.getLoadedGroups().entrySet().stream().filter(e -> e.getValue().getName().equalsIgnoreCase(group)) + .findFirst().orElse(null); + + if (g == null) + { + sender.sendPlainMessage("That group does not exist!"); + return; + } + + if (sender instanceof Player player && (nmLink.getPermissionsPlayer(player.getUniqueId()) + .getPrimaryGroup() + .getId() <= g.getKey())) + { + sender.sendPlainMessage("You cannot modify a player to a higher rank than yourself!"); + return; + } + + if (arg.equalsIgnoreCase("add")) + { + nmLink.getPermissionsPlayer(target.getUniqueId()).getGroups().add(g.getValue()); + sender.sendPlainMessage("Added " + target.getName() + " to " + group); + } + else if (arg.equalsIgnoreCase("remove")) + { + nmLink.getPermissionsPlayer(target.getUniqueId()).getGroups().remove(g.getValue()); + sender.sendPlainMessage("Removed " + target.getName() + " from " + group); + } + else + { + sender.sendPlainMessage("Invalid argument!"); + } + } + + @Subcommand(permission = "cladis.modstaff.track", args = {String.class, Player.class}) + public void track(final CommandSender sender, final String arg, final Player target) + { + final NMLink nmLink = Shortcuts.provideModule(Cladis.class).getNMLink(); + final nl.chimpgamer.networkmanager.api.models.player.Player nmPlayer = + nmLink.getPlayer(target.getUniqueId()).orElse(null); + + if (nmPlayer == null) + { + sender.sendPlainMessage(USER_NOT_FOUND); + return; + } + + final Group primary = nmLink.getPermissionsPlayer(target.getUniqueId()).getPrimaryGroup(); + final int groupLevel = primary.getId(); + + if (arg.equalsIgnoreCase("promote")) + { + final Group promo = nmLink.getLoadedGroups().get(groupLevel + 1); + if (promo == null) + { + sender.sendPlainMessage("That user is already at the highest rank!"); + return; + } + + nmLink.getPermissionsPlayer(target.getUniqueId()).getGroups().remove(primary); + nmLink.getPermissionsPlayer(target.getUniqueId()) + .getGroups() + .add(promo); + sender.sendPlainMessage("Promoted " + target.getName()); + } + else if (arg.equalsIgnoreCase("demote")) + { + final Group demo = nmLink.getLoadedGroups().get(groupLevel - 1); + if (demo == null) + { + sender.sendPlainMessage("That user is already at the lowest rank!"); + return; + } + + nmLink.getPermissionsPlayer(target.getUniqueId()).getGroups().remove(primary); + nmLink.getPermissionsPlayer(target.getUniqueId()) + .getGroups() + .add(demo); + sender.sendPlainMessage("Demoted " + target.getName()); + } + else + { + sender.sendPlainMessage("Invalid argument!"); + } + } +} diff --git a/Cladis/src/main/java/fns/cladis/command/OpCommand.java b/Cladis/src/main/java/fns/cladis/command/OpCommand.java new file mode 100644 index 0000000..604112a --- /dev/null +++ b/Cladis/src/main/java/fns/cladis/command/OpCommand.java @@ -0,0 +1,65 @@ +package fns.cladis.command; + + +import fns.cladis.Cladis; +import fns.cladis.NMLink; +import fns.patchwork.base.Shortcuts; +import fns.patchwork.command.Commander; +import fns.patchwork.command.annotation.Completion; +import fns.patchwork.command.annotation.Info; +import fns.patchwork.command.annotation.Permissive; +import fns.patchwork.command.annotation.Subcommand; +import nl.chimpgamer.networkmanager.api.models.permissions.Group; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; + +@Info( + name = "op", + description = "Op a player.", + usage = "/op " +) +@Permissive(perm = "cladis.op") +@Completion(index = 0, args = {"%player%"}) +public class OpCommand extends Commander +{ + /** + * Initializes this command object. The provided {@link JavaPlugin} should be the plugin which contains the + * command. + *

+ * This constructor will automatically register all subcommands and completions for this command. It will also + * automatically infer all required information from the provided {@link Info} and {@link Permissive} annotations. + * + * @param plugin The plugin which contains this command. + */ + public OpCommand(@NotNull final JavaPlugin plugin) + { + super(plugin); + } + + @Subcommand(permission = "cladis.op", args = {Player.class}) + public void op(@NotNull final CommandSender sender, final Player player) + { + final NMLink nmLink = Shortcuts.provideModule(Cladis.class).getNMLink(); + final Group opGroup = nmLink.locateGroup("fake_op").orElse(null); + + if (opGroup == null) + { + sender.sendPlainMessage("Unable to op player. Please contact an administrator."); + return; + } + + if (nmLink.isOp(player.getUniqueId())) + { + sender.sendPlainMessage("Player is already op."); + return; + } + + + nmLink.getPermissionsPlayer(player.getUniqueId()).getGroups().add(opGroup); + + sender.sendPlainMessage("You have opped " + player.getName() + "."); + player.sendPlainMessage("You have been opped."); + } +} diff --git a/Patchwork/src/main/java/fns/patchwork/command/CommandHandler.java b/Patchwork/src/main/java/fns/patchwork/command/CommandHandler.java index cda6bf8..a77ae98 100644 --- a/Patchwork/src/main/java/fns/patchwork/command/CommandHandler.java +++ b/Patchwork/src/main/java/fns/patchwork/command/CommandHandler.java @@ -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 The type of the command. + */ + public void registerCommands(final Class 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); + } } diff --git a/Patchwork/src/main/java/fns/patchwork/provider/ContextProvider.java b/Patchwork/src/main/java/fns/patchwork/provider/ContextProvider.java index 24020a0..7757c1f 100644 --- a/Patchwork/src/main/java/fns/patchwork/provider/ContextProvider.java +++ b/Patchwork/src/main/java/fns/patchwork/provider/ContextProvider.java @@ -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 fromString(final String string, final Class 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) diff --git a/settings.gradle b/settings.gradle index d401c15..bcbf063 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,4 +3,4 @@ include 'Patchwork' include 'Datura' include 'Fossil' include 'Corvo' - +include 'Cladis' \ No newline at end of file From dd353b4429714ef33126a0a67f92f2051881096d Mon Sep 17 00:00:00 2001 From: Paul Reilly Date: Fri, 11 Aug 2023 15:26:05 -0500 Subject: [PATCH 2/3] Addressed requested changes Signed-off-by: Paul Reilly --- .../java/fns/cladis/command/DeopCommand.java | 30 ++++++++++- .../fns/cladis/command/ModStaffCommand.java | 54 +++++++++++++------ .../java/fns/cladis/command/OpCommand.java | 29 +++++++++- Datura/src/main/java/fns/datura/Datura.java | 10 ++-- Fossil/src/main/java/fns/fossil/Fossil.java | 8 ++- 5 files changed, 106 insertions(+), 25 deletions(-) diff --git a/Cladis/src/main/java/fns/cladis/command/DeopCommand.java b/Cladis/src/main/java/fns/cladis/command/DeopCommand.java index fe9aff8..0c348fd 100644 --- a/Cladis/src/main/java/fns/cladis/command/DeopCommand.java +++ b/Cladis/src/main/java/fns/cladis/command/DeopCommand.java @@ -1,3 +1,26 @@ +/* + * This file is part of Freedom-Network-Suite - https://github.com/AtlasMediaGroup/Freedom-Network-Suite + * Copyright (C) 2023 Total Freedom Server Network and contributors + * + * 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 fns.cladis.command; import fns.cladis.Cladis; @@ -8,6 +31,7 @@ import fns.patchwork.command.annotation.Completion; import fns.patchwork.command.annotation.Info; import fns.patchwork.command.annotation.Permissive; import fns.patchwork.command.annotation.Subcommand; +import java.util.UUID; import nl.chimpgamer.networkmanager.api.models.permissions.Group; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -41,6 +65,8 @@ public class DeopCommand extends Commander @Subcommand(permission = "cladis.deop", args = {Player.class}) public void deop(final CommandSender sender, final Player player) { + final UUID playerUUID = player.getUniqueId(); + final NMLink nmLink = Shortcuts.provideModule(Cladis.class).getNMLink(); final Group opGroup = nmLink.deopGroup(); @@ -50,13 +76,13 @@ public class DeopCommand extends Commander return; } - if (nmLink.isDeop(player.getUniqueId())) + if (nmLink.isDeop(playerUUID)) { sender.sendPlainMessage("Player is not op."); return; } - nmLink.getPlayerGroups(player.getUniqueId()).remove(opGroup); + nmLink.getPlayerGroups(playerUUID).remove(opGroup); sender.sendPlainMessage("Player deopped."); player.sendPlainMessage("You have been deopped!"); diff --git a/Cladis/src/main/java/fns/cladis/command/ModStaffCommand.java b/Cladis/src/main/java/fns/cladis/command/ModStaffCommand.java index 8c25953..0cf96ab 100644 --- a/Cladis/src/main/java/fns/cladis/command/ModStaffCommand.java +++ b/Cladis/src/main/java/fns/cladis/command/ModStaffCommand.java @@ -1,3 +1,26 @@ +/* + * This file is part of Freedom-Network-Suite - https://github.com/AtlasMediaGroup/Freedom-Network-Suite + * Copyright (C) 2023 Total Freedom Server Network and contributors + * + * 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 fns.cladis.command; import fns.cladis.Cladis; @@ -10,6 +33,7 @@ import fns.patchwork.command.annotation.Info; import fns.patchwork.command.annotation.Permissive; import fns.patchwork.command.annotation.Subcommand; import java.util.Map; +import java.util.UUID; import nl.chimpgamer.networkmanager.api.models.permissions.Group; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -119,9 +143,10 @@ public class ModStaffCommand extends Commander @Subcommand(permission = "cladis.modstaff.modify", args = {String.class, Player.class, String.class}) public void modify(final CommandSender sender, final String arg, final Player target, final String group) { + final UUID playerUUID = target.getUniqueId(); final NMLink nmLink = Shortcuts.provideModule(Cladis.class).getNMLink(); final nl.chimpgamer.networkmanager.api.models.player.Player nmPlayer = - nmLink.getPlayer(target.getUniqueId()).orElse(null); + nmLink.getPlayer(playerUUID).orElse(null); if (nmPlayer == null) { @@ -139,9 +164,9 @@ public class ModStaffCommand extends Commander return; } - if (sender instanceof Player player && (nmLink.getPermissionsPlayer(player.getUniqueId()) - .getPrimaryGroup() - .getId() <= g.getKey())) + if (sender instanceof Player s && (nmLink.getPermissionsPlayer(s.getUniqueId()) + .getPrimaryGroup() + .getId() <= g.getKey())) { sender.sendPlainMessage("You cannot modify a player to a higher rank than yourself!"); return; @@ -149,12 +174,12 @@ public class ModStaffCommand extends Commander if (arg.equalsIgnoreCase("add")) { - nmLink.getPermissionsPlayer(target.getUniqueId()).getGroups().add(g.getValue()); + nmLink.getPlayerGroups(playerUUID).add(g.getValue()); sender.sendPlainMessage("Added " + target.getName() + " to " + group); } else if (arg.equalsIgnoreCase("remove")) { - nmLink.getPermissionsPlayer(target.getUniqueId()).getGroups().remove(g.getValue()); + nmLink.getPlayerGroups(playerUUID).remove(g.getValue()); sender.sendPlainMessage("Removed " + target.getName() + " from " + group); } else @@ -166,9 +191,10 @@ public class ModStaffCommand extends Commander @Subcommand(permission = "cladis.modstaff.track", args = {String.class, Player.class}) public void track(final CommandSender sender, final String arg, final Player target) { + final UUID playerUUID = target.getUniqueId(); final NMLink nmLink = Shortcuts.provideModule(Cladis.class).getNMLink(); final nl.chimpgamer.networkmanager.api.models.player.Player nmPlayer = - nmLink.getPlayer(target.getUniqueId()).orElse(null); + nmLink.getPlayer(playerUUID).orElse(null); if (nmPlayer == null) { @@ -176,7 +202,7 @@ public class ModStaffCommand extends Commander return; } - final Group primary = nmLink.getPermissionsPlayer(target.getUniqueId()).getPrimaryGroup(); + final Group primary = nmLink.getPermissionsPlayer(playerUUID).getPrimaryGroup(); final int groupLevel = primary.getId(); if (arg.equalsIgnoreCase("promote")) @@ -188,10 +214,8 @@ public class ModStaffCommand extends Commander return; } - nmLink.getPermissionsPlayer(target.getUniqueId()).getGroups().remove(primary); - nmLink.getPermissionsPlayer(target.getUniqueId()) - .getGroups() - .add(promo); + nmLink.getPlayerGroups(playerUUID).remove(primary); + nmLink.getPlayerGroups(playerUUID).add(promo); sender.sendPlainMessage("Promoted " + target.getName()); } else if (arg.equalsIgnoreCase("demote")) @@ -203,10 +227,8 @@ public class ModStaffCommand extends Commander return; } - nmLink.getPermissionsPlayer(target.getUniqueId()).getGroups().remove(primary); - nmLink.getPermissionsPlayer(target.getUniqueId()) - .getGroups() - .add(demo); + nmLink.getPlayerGroups(playerUUID).remove(primary); + nmLink.getPlayerGroups(playerUUID).add(demo); sender.sendPlainMessage("Demoted " + target.getName()); } else diff --git a/Cladis/src/main/java/fns/cladis/command/OpCommand.java b/Cladis/src/main/java/fns/cladis/command/OpCommand.java index 604112a..559eba0 100644 --- a/Cladis/src/main/java/fns/cladis/command/OpCommand.java +++ b/Cladis/src/main/java/fns/cladis/command/OpCommand.java @@ -1,3 +1,26 @@ +/* + * This file is part of Freedom-Network-Suite - https://github.com/AtlasMediaGroup/Freedom-Network-Suite + * Copyright (C) 2023 Total Freedom Server Network and contributors + * + * 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 fns.cladis.command; @@ -9,6 +32,7 @@ import fns.patchwork.command.annotation.Completion; import fns.patchwork.command.annotation.Info; import fns.patchwork.command.annotation.Permissive; import fns.patchwork.command.annotation.Subcommand; +import java.util.UUID; import nl.chimpgamer.networkmanager.api.models.permissions.Group; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -43,6 +67,7 @@ public class OpCommand extends Commander { final NMLink nmLink = Shortcuts.provideModule(Cladis.class).getNMLink(); final Group opGroup = nmLink.locateGroup("fake_op").orElse(null); + final UUID playerUUID = player.getUniqueId(); if (opGroup == null) { @@ -50,14 +75,14 @@ public class OpCommand extends Commander return; } - if (nmLink.isOp(player.getUniqueId())) + if (nmLink.isOp(playerUUID)) { sender.sendPlainMessage("Player is already op."); return; } - nmLink.getPermissionsPlayer(player.getUniqueId()).getGroups().add(opGroup); + nmLink.getPlayerGroups(playerUUID).add(opGroup); sender.sendPlainMessage("You have opped " + player.getName() + "."); player.sendPlainMessage("You have been opped."); diff --git a/Datura/src/main/java/fns/datura/Datura.java b/Datura/src/main/java/fns/datura/Datura.java index f62b1cc..5089516 100644 --- a/Datura/src/main/java/fns/datura/Datura.java +++ b/Datura/src/main/java/fns/datura/Datura.java @@ -23,6 +23,7 @@ package fns.datura; +import fns.datura.cmd.LockerCommand; import fns.datura.features.CommandSpy; import fns.datura.features.Fuckoff; import fns.datura.punishment.Cager; @@ -30,6 +31,7 @@ import fns.datura.punishment.Halter; import fns.datura.punishment.Locker; import fns.datura.sql.MySQL; import fns.patchwork.base.Registration; +import fns.patchwork.command.CommandHandler; import fns.patchwork.service.SubscriptionProvider; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; @@ -55,17 +57,19 @@ public class Datura extends JavaPlugin Registration.getServiceTaskRegistry() .registerService(SubscriptionProvider.syncService(this, locker)); Registration.getServiceTaskRegistry() - .registerService(SubscriptionProvider.syncService(this, cager)); + .registerService(SubscriptionProvider.syncService(this, cager)); Registration.getServiceTaskRegistry() - .registerService(SubscriptionProvider.syncService(this, fuckoff)); + .registerService(SubscriptionProvider.syncService(this, fuckoff)); Bukkit.getPluginManager() .registerEvents(halter, this); Bukkit.getPluginManager() .registerEvents(commandSpy, this); + new CommandHandler(this).registerCommands(LockerCommand.class); + Registration.getModuleRegistry() - .addModule(this); + .addModule(this); } public MySQL getSQL() diff --git a/Fossil/src/main/java/fns/fossil/Fossil.java b/Fossil/src/main/java/fns/fossil/Fossil.java index 2b49ea7..ab20c18 100644 --- a/Fossil/src/main/java/fns/fossil/Fossil.java +++ b/Fossil/src/main/java/fns/fossil/Fossil.java @@ -23,8 +23,10 @@ package fns.fossil; +import fns.fossil.cmd.CakeCommand; import fns.fossil.trail.Trailer; import fns.patchwork.base.Registration; +import fns.patchwork.command.CommandHandler; import fns.patchwork.service.SubscriptionProvider; import org.bukkit.plugin.java.JavaPlugin; @@ -36,9 +38,11 @@ public class Fossil extends JavaPlugin { Registration.getServiceTaskRegistry() .registerService( - SubscriptionProvider.syncService(this, trailer)); + SubscriptionProvider.syncService(this, trailer)); + + new CommandHandler(this).registerCommands(CakeCommand.class); Registration.getModuleRegistry() - .addModule(this); + .addModule(this); } } From 6ef6eacea0c21e16c73056c19ee6a8e10c3d2fa2 Mon Sep 17 00:00:00 2001 From: Paul Reilly Date: Fri, 11 Aug 2023 15:26:26 -0500 Subject: [PATCH 3/3] Addressed requested changes Signed-off-by: Paul Reilly --- .../src/main/java/fns/patchwork/provider/ContextProvider.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Patchwork/src/main/java/fns/patchwork/provider/ContextProvider.java b/Patchwork/src/main/java/fns/patchwork/provider/ContextProvider.java index 7757c1f..2cfd6a7 100644 --- a/Patchwork/src/main/java/fns/patchwork/provider/ContextProvider.java +++ b/Patchwork/src/main/java/fns/patchwork/provider/ContextProvider.java @@ -126,7 +126,7 @@ public class ContextProvider private @Nullable Long toLong(final String string, final Class clazz) { - if (clazz != Long.class || string.endsWith("L")) + if (clazz != Long.class || !string.endsWith("L")) return null; try @@ -141,7 +141,7 @@ public class ContextProvider private @Nullable Float toFloat(final String string, final Class clazz) { - if (clazz != Float.class) + if (clazz != Float.class || !string.endsWith("F")) return null; try