diff --git a/Corvo/src/main/java/fns/corvo/Corvo.java b/Corvo/src/main/java/fns/corvo/Corvo.java new file mode 100644 index 0000000..69d9c7a --- /dev/null +++ b/Corvo/src/main/java/fns/corvo/Corvo.java @@ -0,0 +1,22 @@ +package fns.corvo; + +import fns.patchwork.base.Patchwork; +import fns.patchwork.base.Registration; +import org.bukkit.plugin.java.JavaPlugin; + +public class Corvo extends JavaPlugin +{ + @Override + public void onDisable() + { + Registration.getModuleRegistry() + .removeModule(this); + } + + @Override + public void onEnable() + { + Registration.getModuleRegistry() + .addModule(this); + } +} diff --git a/Corvo/src/main/java/me/totalfreedom/corvo/listener/PlayerInteractionListener.java b/Corvo/src/main/java/fns/corvo/listener/PlayerInteractionListener.java similarity index 95% rename from Corvo/src/main/java/me/totalfreedom/corvo/listener/PlayerInteractionListener.java rename to Corvo/src/main/java/fns/corvo/listener/PlayerInteractionListener.java index 0704003..86a5036 100644 --- a/Corvo/src/main/java/me/totalfreedom/corvo/listener/PlayerInteractionListener.java +++ b/Corvo/src/main/java/fns/corvo/listener/PlayerInteractionListener.java @@ -1,4 +1,4 @@ -package me.totalfreedom.corvo.listener; +package fns.corvo.listener; import io.papermc.paper.event.block.BlockBreakBlockEvent; import org.bukkit.event.EventHandler; diff --git a/Corvo/src/main/java/me/totalfreedom/corvo/Corvo.java b/Corvo/src/main/java/me/totalfreedom/corvo/Corvo.java deleted file mode 100644 index ba1670b..0000000 --- a/Corvo/src/main/java/me/totalfreedom/corvo/Corvo.java +++ /dev/null @@ -1,25 +0,0 @@ -package me.totalfreedom.corvo; - -import me.totalfreedom.base.CommonsBase; -import org.bukkit.plugin.java.JavaPlugin; - -public class Corvo extends JavaPlugin -{ - @Override - public void onDisable() - { - CommonsBase.getInstance() - .getRegistrations() - .getModuleRegistry() - .removeModule(this); - } - - @Override - public void onEnable() - { - CommonsBase.getInstance() - .getRegistrations() - .getModuleRegistry() - .addModule(this); - } -} diff --git a/Corvo/src/main/resources/plugin.yml b/Corvo/src/main/resources/plugin.yml index 557f40e..db2b827 100644 --- a/Corvo/src/main/resources/plugin.yml +++ b/Corvo/src/main/resources/plugin.yml @@ -1,5 +1,6 @@ name: Corvo -main: me.totalfreedom.corvo.Corvo +main: fns.corvo.Corvo +api-version: 1.20 version: 1.0.0 author: TotalFreedom description: Services and Listeners for the Freedom Network Suite diff --git a/Datura/src/main/java/fns/datura/Datura.java b/Datura/src/main/java/fns/datura/Datura.java new file mode 100644 index 0000000..cebc77e --- /dev/null +++ b/Datura/src/main/java/fns/datura/Datura.java @@ -0,0 +1,77 @@ +package fns.datura; + +import fns.datura.features.CommandSpy; +import fns.datura.features.Fuckoff; +import fns.datura.punishment.Cager; +import fns.datura.punishment.Halter; +import fns.datura.punishment.Locker; +import fns.datura.sql.MySQL; +import fns.patchwork.base.Registration; +import fns.patchwork.service.SubscriptionProvider; +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; + +public class Datura extends JavaPlugin +{ + private final MySQL sql = new MySQL("localhost", 3011, "master"); + + // Punishment + private final Halter halter = new Halter(); + private final Locker locker = new Locker(); + private Cager cager; + + // Features + private final CommandSpy commandSpy = new CommandSpy(); + private final Fuckoff fuckoff = new Fuckoff(); + + @Override + public void onEnable() + { + cager = new Cager(this); + + Registration.getServiceTaskRegistry() + .registerService(SubscriptionProvider.syncService(this, locker)); + Registration.getServiceTaskRegistry() + .registerService(SubscriptionProvider.syncService(this, cager)); + Registration.getServiceTaskRegistry() + .registerService(SubscriptionProvider.syncService(this, fuckoff)); + + Bukkit.getPluginManager() + .registerEvents(halter, this); + Bukkit.getPluginManager() + .registerEvents(commandSpy, this); + + Registration.getModuleRegistry() + .addModule(this); + } + + public MySQL getSQL() + { + return sql; + } + + public Halter getHalter() + { + return halter; + } + + public Locker getLocker() + { + return locker; + } + + public Cager getCager() + { + return cager; + } + + public CommandSpy getCommandSpy() + { + return commandSpy; + } + + public Fuckoff getFuckoff() + { + return fuckoff; + } +} diff --git a/Datura/src/main/java/fns/datura/cmd/AdminChatCommand.java b/Datura/src/main/java/fns/datura/cmd/AdminChatCommand.java new file mode 100644 index 0000000..aff79a4 --- /dev/null +++ b/Datura/src/main/java/fns/datura/cmd/AdminChatCommand.java @@ -0,0 +1,65 @@ +package fns.datura.cmd; + +import fns.patchwork.base.Patchwork; +import fns.patchwork.base.Shortcuts; +import fns.patchwork.command.Commander; +import fns.patchwork.command.annotation.Base; +import fns.patchwork.command.annotation.Info; +import fns.patchwork.command.annotation.Permissive; +import fns.patchwork.command.annotation.Subcommand; +import net.kyori.adventure.text.Component; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; + +@Info(name = "") +@Permissive(perm = "") +public class AdminChatCommand 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 AdminChatCommand(@NotNull final JavaPlugin plugin) + { + super(plugin); + } + + @Base + public void onAdminChat(final CommandSender sender) + { + if (!(sender instanceof Player)) return; + + final Player player = (Player) sender; + + Shortcuts.provideModule(Patchwork.class) + .getAdminChatDisplay() + .toggleChat(player); + + final boolean toggled = Shortcuts.provideModule(Patchwork.class) + .getAdminChatDisplay() + .isToggled(player); + + String message = "Toggled adminchat "; + + message += toggled ? "on" : "off"; + + player.sendPlainMessage(message + "."); + } + + // String here will automatically have all additional args appended to it :) + @Subcommand(permission = "patchwork.adminchat", args = {String.class}) + public void sendMessage(final CommandSender sender, final String message) + { + Shortcuts.provideModule(Patchwork.class) + .getAdminChatDisplay() + .adminChatMessage(sender, Component.text(message)); + } +} diff --git a/Datura/src/main/java/me/totalfreedom/datura/cmd/CageCommand.java b/Datura/src/main/java/fns/datura/cmd/CageCommand.java similarity index 55% rename from Datura/src/main/java/me/totalfreedom/datura/cmd/CageCommand.java rename to Datura/src/main/java/fns/datura/cmd/CageCommand.java index 38b2050..ecec841 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/cmd/CageCommand.java +++ b/Datura/src/main/java/fns/datura/cmd/CageCommand.java @@ -19,14 +19,15 @@ * THE SOFTWARE. */ -package me.totalfreedom.datura.cmd; +package fns.datura.cmd; -import me.totalfreedom.command.Commander; -import me.totalfreedom.command.annotation.Completion; -import me.totalfreedom.command.annotation.Info; -import me.totalfreedom.command.annotation.Permissive; -import me.totalfreedom.command.annotation.Subcommand; -import me.totalfreedom.datura.Datura; +import fns.datura.Datura; +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 org.bukkit.Material; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -36,54 +37,48 @@ import org.jetbrains.annotations.NotNull; @Info(name = "cage", description = "Cage a player.", usage = "/cage [material]") @Permissive(perm = "datura.cage") +@Completion(args = {"%player%"}, index = 0) +@Completion(args = {"on", "off"}, index = 1) +@Completion(args = {"[material]"}, index = 2) public class CageCommand extends Commander { - protected CageCommand(final @NotNull JavaPlugin plugin) + public CageCommand(final @NotNull JavaPlugin plugin) { super(plugin); } - @Completion(args = {"%player%"}, index = 0) - @Completion(args = {"on", "off"}, index = 1) @Subcommand(permission = "datura.cage", args = {Player.class, String.class}) public void cagePlayer(final CommandSender sender, final Player player, final String string) { - switch (string.toLowerCase()) + if (string.equalsIgnoreCase("on")) { - case "on" -> - { - ((Datura) getPlugin()).getCager() - .cagePlayer(player.getUniqueId()); - sender.sendPlainMessage("Caged " + player.getName() + "."); - } - case "off" -> - { - ((Datura) getPlugin()).getCager() - .uncagePlayer(player.getUniqueId()); - sender.sendPlainMessage("Liberated " + player.getName() + "."); - } + ((Datura) getPlugin()).getCager() + .cagePlayer(player.getUniqueId()); + sender.sendPlainMessage("Caged " + player.getName() + "."); + } else if (string.equalsIgnoreCase("off")) + { + ((Datura) getPlugin()).getCager() + .uncagePlayer(player.getUniqueId()); + sender.sendPlainMessage("Liberated " + player.getName() + "."); } } - @Completion(args = {"[material]"}, index = 2) @Subcommand(permission = "datura.cage.custom", args = {Player.class, String.class, Material.class}) public void cagePlayer(final CommandSender sender, final Player player, final String string, final Material material) { - switch (string.toLowerCase()) + if (string.equalsIgnoreCase("on")) { - case "on" -> - { - ((Datura) getPlugin()).getCager() - .cagePlayer(player.getUniqueId(), material); - sender.sendPlainMessage("Caged " + player.getName() + "."); - } - case "off" -> - { - ((Datura) getPlugin()).getCager() - .uncagePlayer(player.getUniqueId()); - sender.sendPlainMessage("Liberated " + player.getName() + "."); - } + Shortcuts.provideModule(Datura.class) + .getCager() + .cagePlayer(player.getUniqueId(), material); + sender.sendPlainMessage("Caged " + player.getName() + "."); + } else if (string.equalsIgnoreCase("off")) + { + Shortcuts.provideModule(Datura.class) + .getCager() + .uncagePlayer(player.getUniqueId()); + sender.sendPlainMessage("Liberated " + player.getName() + "."); } } } diff --git a/Datura/src/main/java/fns/datura/cmd/ClearDropsCommand.java b/Datura/src/main/java/fns/datura/cmd/ClearDropsCommand.java new file mode 100644 index 0000000..e0912cf --- /dev/null +++ b/Datura/src/main/java/fns/datura/cmd/ClearDropsCommand.java @@ -0,0 +1,94 @@ +package fns.datura.cmd; + + +import fns.datura.Datura; +import fns.patchwork.base.Patchwork; +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 org.bukkit.World; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Item; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; + +@Info(name = "cleardrops", description = "Clears all item drops in the world" + ".", usage = "/", aliases = + {"cd", "clearitems", "ci", "wipeitems", "wi", "removedrops", "rd"}) +@Permissive(perm = "datura.cleardrops") +@Completion(index = 0, args = {"%world%"}) +public class ClearDropsCommand 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 ClearDropsCommand(final @NotNull JavaPlugin plugin) + { + super(plugin); + } + + @Base + public void clearDrops(final CommandSender sender) + { + if (!(sender instanceof Player)) + { + sender.sendPlainMessage("You must define a world."); + return; + } + + final Player player = (Player) sender; + Shortcuts.provideModule(Patchwork.class) + .getExecutor() + .delayedExecutor(Shortcuts.provideModule(Datura.class), 20 * 10L) + .execute(() -> + { + int i = 0; + for (final Entity entity : player.getWorld().getEntities()) + { + if (entity instanceof Item) + { + entity.remove(); + i++; + } + } + + player.sendPlainMessage("Successfully removed " + i + " items."); + }); + } + + @Subcommand(permission = "datura.cleardrops", args = {World.class}) + public void clearDrops(final CommandSender sender, final World world) + { + Shortcuts.provideModule(Patchwork.class) + .getExecutor() + .delayedExecutor(Shortcuts.provideModule(Datura.class), 20 * 10L) + .execute(() -> + { + int i = 0; + for (final Entity entity : world.getEntities()) + { + if (entity instanceof Item) + { + entity.remove(); + i++; + } + } + + sender.sendPlainMessage("Successfully removed " + i + " items."); + }); + } +} diff --git a/Datura/src/main/java/fns/datura/cmd/ClearEntitiesCommand.java b/Datura/src/main/java/fns/datura/cmd/ClearEntitiesCommand.java new file mode 100644 index 0000000..fd14a1c --- /dev/null +++ b/Datura/src/main/java/fns/datura/cmd/ClearEntitiesCommand.java @@ -0,0 +1,74 @@ +package fns.datura.cmd; + +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 fns.patchwork.utils.Tagged; +import org.bukkit.World; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; + +@Info(name = "clearentities", description = "Clears all entities in the world.", usage = "/ [world]", + aliases = {"ew", "ce", "entitywipe", "entityclear", "ec"}) +@Permissive(perm = "datura.clearentities") +@Completion(index = 0, args = {"%world%"}) +public class ClearEntitiesCommand 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 ClearEntitiesCommand(final @NotNull JavaPlugin plugin) + { + super(plugin); + } + + @Base + public void clearEntities(final CommandSender sender) + { + if (!(sender instanceof Player)) + { + sender.sendPlainMessage("You must specify a world to clear entities from."); + return; + } + + final Player player = (Player) sender; + + int i = 0; + for (final Entity entity : player.getWorld().getEntities()) + { + if (!Tagged.NON_WIPEABLE.isTagged(entity.getType())) + { + entity.remove(); + i++; + } + } + sender.sendPlainMessage("Cleared " + i + " entities."); + } + + @Subcommand(permission = "datura.clearentities", args = {World.class}) + public void clearEntities(final CommandSender sender, final World world) + { + int i = 0; + for (final Entity entity : world.getEntities()) + { + if (!Tagged.NON_WIPEABLE.isTagged(entity.getType())) + { + entity.remove(); + i++; + } + } + sender.sendPlainMessage("Cleared " + i + " entities."); + } +} diff --git a/Datura/src/main/java/fns/datura/cmd/CommandSpyCommand.java b/Datura/src/main/java/fns/datura/cmd/CommandSpyCommand.java new file mode 100644 index 0000000..bd9a13d --- /dev/null +++ b/Datura/src/main/java/fns/datura/cmd/CommandSpyCommand.java @@ -0,0 +1,51 @@ +package fns.datura.cmd; + +import fns.datura.Datura; +import fns.patchwork.command.Commander; +import fns.patchwork.command.annotation.Base; +import fns.patchwork.command.annotation.Info; +import fns.patchwork.command.annotation.Permissive; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; + +@Info(name = "commandspy", description = "Spy on commands executed by players.", usage = "/commandspy") +@Permissive(perm = "datura.commandspy", onlyPlayers = true) +public class CommandSpyCommand 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 CommandSpyCommand(@NotNull final Datura plugin) + { + super(plugin); + } + + @Base + public void commandSpy(final Player sender) + { + final var commandSpy = ((Datura) getPlugin()). + getCommandSpy(); + + final var uuid = sender. + getUniqueId(); + + if (commandSpy.isSpying(uuid)) + { + commandSpy.stop(uuid); + sender.sendPlainMessage("CommandSpy disabled."); + } + else + { + commandSpy.spy(uuid); + sender.sendPlainMessage("CommandSpy enabled."); + } + } +} diff --git a/Datura/src/main/java/fns/datura/cmd/FuckoffCommand.java b/Datura/src/main/java/fns/datura/cmd/FuckoffCommand.java new file mode 100644 index 0000000..a24822d --- /dev/null +++ b/Datura/src/main/java/fns/datura/cmd/FuckoffCommand.java @@ -0,0 +1,64 @@ +package fns.datura.cmd; + +import fns.datura.Datura; +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 org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; + +@Info(name = "fuckoff", description = "You'll never even see it coming - repeatedly push players away from you until command is untoggled.", usage = "/fuckoff [radius]") +@Permissive(perm = "datura.fuckoff", onlyPlayers = true) +@Completion(args = {"on", "off"}, index = 0) +@Completion(args = {"[radius]"}, index = 1) +public class FuckoffCommand extends Commander +{ + private final Datura plugin = Shortcuts.provideModule(Datura.class); + + /** + * 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 FuckoffCommand(@NotNull final JavaPlugin plugin) + { + super(plugin); + } + + @Subcommand(permission = "datura.fuckoff", args = {String.class}) + public void fuckOff(final Player sender, final String toggle) + { + execute(sender, toggle, 15); + } + + @Subcommand(permission = "datura.fuckoff", args = {String.class, Integer.class}) + public void fuckOff(final Player sender, final String toggle, final Integer radius) + { + execute(sender, toggle, radius); + } + + private void execute(final Player sender, final String toggle, final int radius) + { + if (toggle.equalsIgnoreCase("on")) + { + plugin.getFuckoff(). + add(sender, radius); + + sender.sendPlainMessage("FuckOff enabled."); + } else if (toggle.equalsIgnoreCase("off")) + { + plugin.getFuckoff(). + remove(sender); + + sender.sendPlainMessage("FuckOff disabled."); + } + } +} diff --git a/Datura/src/main/java/fns/datura/cmd/HaltCommand.java b/Datura/src/main/java/fns/datura/cmd/HaltCommand.java new file mode 100644 index 0000000..82b7559 --- /dev/null +++ b/Datura/src/main/java/fns/datura/cmd/HaltCommand.java @@ -0,0 +1,88 @@ +package fns.datura.cmd; + +import fns.datura.Datura; +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 net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; + +@Info(name = "halt", description = "Halt a single player, or every player.", usage = "/ ") +@Permissive(perm = "datura.halt") +@Completion(index = 0, args = {"%player%", "all"}) +@Completion(index = 1, args = {"on", "off"}) +public class HaltCommand extends Commander +{ + private final Datura plugin = Shortcuts.provideModule(Datura.class); + + /** + * 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 HaltCommand(@NotNull final JavaPlugin plugin) + { + super(plugin); + } + + @Subcommand(permission = "datura.halt", args = {Player.class, String.class}) + public void haltPlayer(final CommandSender sender, final Player target, final String toggle) + { + if (toggle.equalsIgnoreCase("on")) + { + plugin.getHalter() + .halt(target.getUniqueId()); + + target.sendPlainMessage("You have been frozen!"); + sender.sendPlainMessage("You have halted " + target.getName() + "."); + } else if (toggle.equalsIgnoreCase("off")) + { + plugin.getHalter() + .stop(target.getUniqueId()); + + target.sendPlainMessage("You have been unfrozen!"); + sender.sendPlainMessage("You have unhalted " + target.getName() + "."); + } + } + + @Subcommand(permission = "datura.halt.all", args = {String.class, String.class}) + public void haltAll(final CommandSender sender, final String all, final String toggle) + { + if (all.equalsIgnoreCase("all")) + { + if (toggle.equalsIgnoreCase("on")) + { + Bukkit.getServer() + .getOnlinePlayers() + .forEach(player -> plugin.getHalter() + .halt(player.getUniqueId())); + + final Component message = sender.name() + .append(Component.text(": Freezing all players")) + .color(NamedTextColor.AQUA); + + Bukkit.broadcast(message); + sender.sendPlainMessage("All players have been halted."); + } else if (toggle.equalsIgnoreCase("off")) + { + plugin.getHalter() + .clear(); + + Bukkit.broadcast(Component.text("All players have been unfrozen!", NamedTextColor.AQUA)); + sender.sendPlainMessage("All players have been unhalted."); + } + } + } +} diff --git a/Datura/src/main/java/me/totalfreedom/datura/cmd/LockerCommand.java b/Datura/src/main/java/fns/datura/cmd/LockerCommand.java similarity index 73% rename from Datura/src/main/java/me/totalfreedom/datura/cmd/LockerCommand.java rename to Datura/src/main/java/fns/datura/cmd/LockerCommand.java index 38f9f2c..8ddffcf 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/cmd/LockerCommand.java +++ b/Datura/src/main/java/fns/datura/cmd/LockerCommand.java @@ -1,11 +1,11 @@ -package me.totalfreedom.datura.cmd; +package fns.datura.cmd; -import me.totalfreedom.command.Commander; -import me.totalfreedom.command.annotation.Completion; -import me.totalfreedom.command.annotation.Info; -import me.totalfreedom.command.annotation.Permissive; -import me.totalfreedom.command.annotation.Subcommand; -import me.totalfreedom.datura.Datura; +import fns.datura.Datura; +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 org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -13,6 +13,8 @@ import org.jetbrains.annotations.NotNull; @Info(name = "locker", description = "Lock a player, preventing them from interacting with their game client.", usage = "/locker ", aliases = {"lock", "lockup"}) @Permissive(perm = "datura.locker") +@Completion(args = {"%player%"}, index = 0) +@Completion(args = {"on", "off"}, index = 1) public final class LockerCommand extends Commander { public LockerCommand(final @NotNull Datura plugin) @@ -20,8 +22,6 @@ public final class LockerCommand extends Commander super(plugin); } - @Completion(args = {"%player%"}, index = 0) - @Completion(args = {"on", "off"}, index = 1) @Subcommand(permission = "datura.locker", args = {Player.class, String.class}) public void lockPlayer(final CommandSender sender, final Player player, final String string) { diff --git a/Datura/src/main/java/fns/datura/cmd/ManageUserCommand.java b/Datura/src/main/java/fns/datura/cmd/ManageUserCommand.java new file mode 100644 index 0000000..1bd446e --- /dev/null +++ b/Datura/src/main/java/fns/datura/cmd/ManageUserCommand.java @@ -0,0 +1,93 @@ +package fns.datura.cmd; + +import fns.datura.perms.PermissionNodeBuilder; +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 fns.patchwork.security.Node; +import fns.patchwork.security.NodeType; +import fns.patchwork.security.PermissionHolder; +import fns.patchwork.user.User; +import java.time.Duration; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; + +@Info(name = "manageuser", description = "Manage a user's permissions", usage = "/manageuser )>", aliases = {"mu", "userdata", "ud", "usermanager", "um"}) +@Permissive(perm = "datura.manageuser") +@Completion(index = 0, args = {"%player%"}) +@Completion(index = 1, args = {"info", "add", "remove"}) +@Completion(index = 2, args = {""}) +public class ManageUserCommand 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 ManageUserCommand(final @NotNull JavaPlugin plugin) + { + super(plugin); + } + + @Subcommand(permission = "datura.manageuser", args = {Player.class, String.class, String.class, Long.class}) + public void manageUser(final CommandSender sender, final Player player, final String addOrRemove, + final String permission, final long duration) + { + final PermissionHolder user = Shortcuts.getUser(player); + final Node node = new PermissionNodeBuilder().key(permission) + .type(NodeType.PERMISSION) + .expiry(Duration.ofMinutes(duration) + .getSeconds() + System.currentTimeMillis()) + .build(); + ifElse(addOrRemove, user, node); + } + + @Subcommand(permission = "datura.manageuser", args = {Player.class, String.class, String.class}) + public void manageUser(final CommandSender sender, final Player player, final String addOrRemove, + final String permission) + { + final PermissionHolder user = Shortcuts.getUser(player); + final Node node = new PermissionNodeBuilder().key(permission).type(NodeType.PERMISSION).build(); + ifElse(addOrRemove, user, node); + } + + @Subcommand(permission = "datura.manageuser", args = {Player.class, String.class}) + public void userInfo(final CommandSender sender, final Player player, final String info) + { + final User user = Shortcuts.getUser(player); + if (info.equalsIgnoreCase("info")) + { + final StringBuilder permissions = new StringBuilder(); + user.getEffectivePermissions().forEach(node -> permissions.append(node.getPermission())); + final String text = """ + User: %s + Group: %s + Permissions: %s""".formatted(user.getName(), user.getUserData().getGroup(), + permissions.toString()); + sender.sendPlainMessage(text); + } + } + + private void ifElse(final String addOrRemove, final PermissionHolder user, final Node node) + { + if (addOrRemove.equalsIgnoreCase("add")) + { + user.addPermission(node); + } + else if (addOrRemove.equalsIgnoreCase("remove")) + { + user.removePermission(node); + } + } +} diff --git a/Datura/src/main/java/fns/datura/cmd/SmiteCommand.java b/Datura/src/main/java/fns/datura/cmd/SmiteCommand.java new file mode 100644 index 0000000..1e83ff9 --- /dev/null +++ b/Datura/src/main/java/fns/datura/cmd/SmiteCommand.java @@ -0,0 +1,51 @@ +package fns.datura.cmd; + +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 org.bukkit.Location; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; + +@Info(name = "smite", description = "Smite a player.", usage = "/smite ", aliases = {"sm"}) +@Permissive(perm = "datura.smite") +@Completion(index = 0, args = {"%player%"}) +public class SmiteCommand 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 SmiteCommand(@NotNull final JavaPlugin plugin) + { + super(plugin); + } + + @Subcommand(permission = "datura.smite", args = {Player.class}) + public void smite(final CommandSender sender, final Player player) + { + final double size = 5D; + for (int i = 0; i < size * size * size; i++) + { + final double x = i % size; + final double y = (i / size) % size; + final double z = (i / size / size) % size; + + final Location location = player.getLocation() + .clone() + .add(x - size / 2, y - size / 2, z - size / 2); + + player.getWorld() + .strikeLightning(location); + } + } +} diff --git a/Datura/src/main/java/me/totalfreedom/datura/event/UserDataUpdateEvent.java b/Datura/src/main/java/fns/datura/event/UserDataUpdateEvent.java similarity index 76% rename from Datura/src/main/java/me/totalfreedom/datura/event/UserDataUpdateEvent.java rename to Datura/src/main/java/fns/datura/event/UserDataUpdateEvent.java index b3ef7b4..8bbd675 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/event/UserDataUpdateEvent.java +++ b/Datura/src/main/java/fns/datura/event/UserDataUpdateEvent.java @@ -1,7 +1,7 @@ -package me.totalfreedom.datura.event; +package fns.datura.event; -import me.totalfreedom.event.FEvent; -import me.totalfreedom.user.UserData; +import fns.patchwork.event.FEvent; +import fns.patchwork.user.UserData; public class UserDataUpdateEvent extends FEvent { diff --git a/Datura/src/main/java/fns/datura/features/CommandSpy.java b/Datura/src/main/java/fns/datura/features/CommandSpy.java new file mode 100644 index 0000000..8f761fa --- /dev/null +++ b/Datura/src/main/java/fns/datura/features/CommandSpy.java @@ -0,0 +1,54 @@ +package fns.datura.features; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +public class CommandSpy implements Listener +{ + + private final Set commandWatchers; + + public CommandSpy() + { + this.commandWatchers = new HashSet<>(); + } + + public void spy(final UUID uuid) + { + this.commandWatchers.add(uuid); + } + + public void stop(final UUID uuid) + { + this.commandWatchers.remove(uuid); + } + + public void clear() + { + this.commandWatchers.clear(); + } + + public boolean isSpying(final UUID uuid) + { + return this.commandWatchers.contains(uuid); + } + + @EventHandler + public void commandProcess(final PlayerCommandPreprocessEvent event) + { + Bukkit.getOnlinePlayers().stream() + .filter(player -> isSpying(player.getUniqueId())) + .forEach(player -> player.sendMessage(Component.text(event.getPlayer().getName(), NamedTextColor.GRAY) + .append(Component.text(": ", NamedTextColor.GRAY)) + .append(Component.text(event.getMessage(), NamedTextColor.GRAY)) + ) + ); + } +} diff --git a/Datura/src/main/java/fns/datura/features/Fuckoff.java b/Datura/src/main/java/fns/datura/features/Fuckoff.java new file mode 100644 index 0000000..2bf25cf --- /dev/null +++ b/Datura/src/main/java/fns/datura/features/Fuckoff.java @@ -0,0 +1,61 @@ +package fns.datura.features; + +import fns.patchwork.service.Service; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +public class Fuckoff extends Service +{ + private final Map players = new ConcurrentHashMap<>(); + + public Fuckoff() + { + super("fuckoff-service"); + } + + public void add(final Player player, final int radius) + { + players.put(player.getUniqueId(), radius); + } + + public void remove(final Player player) + { + players.remove(player.getUniqueId()); + } + + @Override + public void tick() + { + for (final Map.Entry entry : players.entrySet()) + { + final var player = Bukkit.getPlayer(entry.getKey()); + + if (player == null) + { + players.remove(entry.getKey()); + continue; + } + + pushPlayers(player, entry.getValue()); + } + } + + private void pushPlayers(@NotNull final Player player, final int radius) + { + Bukkit.getOnlinePlayers() + .stream() + .filter(onlinePlayer -> onlinePlayer.getLocation() + .clone() + .distanceSquared(player.getLocation()) < Math.pow(radius, 2)) + .forEach(onlinePlayer -> + onlinePlayer.setVelocity(player.getLocation() + .toVector() + .add(onlinePlayer.getLocation().toVector()) + .normalize() + .multiply(radius))); + } +} diff --git a/Datura/src/main/java/me/totalfreedom/datura/perms/DefaultNodes.java b/Datura/src/main/java/fns/datura/perms/DefaultNodes.java similarity index 72% rename from Datura/src/main/java/me/totalfreedom/datura/perms/DefaultNodes.java rename to Datura/src/main/java/fns/datura/perms/DefaultNodes.java index 6357cdc..fd85f65 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/perms/DefaultNodes.java +++ b/Datura/src/main/java/fns/datura/perms/DefaultNodes.java @@ -1,36 +1,32 @@ -package me.totalfreedom.datura.perms; +package fns.datura.perms; -import me.totalfreedom.security.Node; -import me.totalfreedom.security.NodeType; +import fns.patchwork.security.Node; +import fns.patchwork.security.NodeType; public class DefaultNodes { public static final Node OP = new PermissionNodeBuilder() .key("freedom.master_key") - .value(true) + .expiry(-1) .type(NodeType.PERMISSION) - .negated(false) .wildcard(true) .build(); public static final Node NON_OP = new PermissionNodeBuilder() .key("freedom.default") - .value(true) + .expiry(-1) .type(NodeType.PERMISSION) - .negated(false) .wildcard(false) .build(); public static final Node ALL = new PermissionNodeBuilder() .key("*") - .value(true) + .expiry(-1) .type(NodeType.PERMISSION) - .negated(false) .wildcard(true) .build(); public static final Node NONE = new PermissionNodeBuilder() .key("freedom.none") - .value(true) + .expiry(-1) .type(NodeType.PERMISSION) - .negated(false) .wildcard(false) .build(); diff --git a/Datura/src/main/java/me/totalfreedom/datura/perms/FreedomGroup.java b/Datura/src/main/java/fns/datura/perms/FreedomGroup.java similarity index 92% rename from Datura/src/main/java/me/totalfreedom/datura/perms/FreedomGroup.java rename to Datura/src/main/java/fns/datura/perms/FreedomGroup.java index a2ccc5d..7694147 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/perms/FreedomGroup.java +++ b/Datura/src/main/java/fns/datura/perms/FreedomGroup.java @@ -1,8 +1,13 @@ -package me.totalfreedom.datura.perms; +package fns.datura.perms; -import me.totalfreedom.base.CommonsBase; -import me.totalfreedom.security.Group; -import me.totalfreedom.security.Node; +import fns.patchwork.base.Patchwork; +import fns.patchwork.base.Shortcuts; +import fns.patchwork.security.Group; +import fns.patchwork.security.Node; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; +import java.util.stream.Collectors; import net.kyori.adventure.text.Component; import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionAttachment; @@ -11,11 +16,6 @@ import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; -import java.util.stream.Collectors; - public class FreedomGroup implements Group { private final Component name; @@ -41,7 +41,7 @@ public class FreedomGroup implements Group this.isDefault = isDefault; this.isHidden = isHidden; this.permissions = new HashSet<>(); - this.attachment = new PermissionAttachment(CommonsBase.getInstance(), this); + this.attachment = new PermissionAttachment(Shortcuts.provideModule(Patchwork.class), this); } @Override @@ -114,7 +114,7 @@ public class FreedomGroup implements Group .findFirst() .orElse(null); - return node != null && node.value(); + return node != null; } @Override @@ -127,7 +127,7 @@ public class FreedomGroup implements Group .findFirst() .orElse(null); - return node != null && node.value(); + return node != null; } @Override @@ -139,7 +139,7 @@ public class FreedomGroup implements Group .findFirst() .orElse(null); - return node != null && node.value(); + return node != null; } @Override @@ -152,7 +152,7 @@ public class FreedomGroup implements Group .findFirst() .orElse(null); - return node != null && node.value(); + return node != null; } /** @@ -214,8 +214,7 @@ public class FreedomGroup implements Group .map(n -> new PermissionAttachmentInfo( this, n.key(), - attachment, - n.value())) + attachment, true)) .collect(Collectors.toSet()); } @@ -228,7 +227,7 @@ public class FreedomGroup implements Group .findFirst() .orElse(null); - return node != null && node.value(); + return node != null; } @Override diff --git a/Datura/src/main/java/me/totalfreedom/datura/perms/FreedomUser.java b/Datura/src/main/java/fns/datura/perms/FreedomUser.java similarity index 86% rename from Datura/src/main/java/me/totalfreedom/datura/perms/FreedomUser.java rename to Datura/src/main/java/fns/datura/perms/FreedomUser.java index 3f1510f..d246cad 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/perms/FreedomUser.java +++ b/Datura/src/main/java/fns/datura/perms/FreedomUser.java @@ -1,11 +1,18 @@ -package me.totalfreedom.datura.perms; +package fns.datura.perms; -import me.totalfreedom.base.CommonsBase; -import me.totalfreedom.datura.Datura; -import me.totalfreedom.datura.user.SimpleUserData; -import me.totalfreedom.security.Node; -import me.totalfreedom.user.User; -import me.totalfreedom.user.UserData; +import fns.datura.Datura; +import fns.datura.user.SimpleUserData; +import fns.patchwork.base.Patchwork; +import fns.patchwork.base.Registration; +import fns.patchwork.base.Shortcuts; +import fns.patchwork.security.Node; +import fns.patchwork.user.User; +import fns.patchwork.user.UserData; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.UUID; import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -16,12 +23,6 @@ import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.UUID; - /** * The superinterface User extends PermissionHolder, which is an extension of * {@link org.bukkit.permissions.Permissible}. This means that our permission data can be interchanged with other @@ -33,7 +34,7 @@ public class FreedomUser implements User private final Set permissions; private final Map bukkitAttachments = new HashMap<>(); private final Component displayName; - private final String NOT_ONLINE = "Player is not online"; + private static final String NOT_ONLINE = "Player is not online"; private final UserData userData; public FreedomUser(final Player player) @@ -42,11 +43,7 @@ public class FreedomUser implements User this.permissions = new HashSet<>(); this.displayName = player.displayName(); - final Datura datura = CommonsBase.getInstance() - .getRegistrations() - .getModuleRegistry() - .getProvider(Datura.class) - .getModule(); + final Datura datura = Shortcuts.provideModule(Datura.class); UserData data = SimpleUserData.fromSQL(datura.getSQL(), uuid.toString()); @@ -57,10 +54,9 @@ public class FreedomUser implements User this.userData = data; - CommonsBase.getInstance() - .getRegistrations() - .getUserRegistry() - .registerUserData(this, userData); + Registration + .getUserRegistry() + .registerUserData(this, userData); } @Override @@ -96,7 +92,8 @@ public class FreedomUser implements User @Override public boolean addPermission(final Node node) { - final PermissionAttachment attachment = addAttachment(CommonsBase.getInstance(), node.key(), node.value()); + final boolean value = !node.isTemporary() || node.isExpired(); + final PermissionAttachment attachment = addAttachment(Shortcuts.provideModule(Patchwork.class), node.key(), value); bukkitAttachments.put(node, attachment); return permissions().add(node); } diff --git a/Datura/src/main/java/fns/datura/perms/PermissionNode.java b/Datura/src/main/java/fns/datura/perms/PermissionNode.java new file mode 100644 index 0000000..bb70275 --- /dev/null +++ b/Datura/src/main/java/fns/datura/perms/PermissionNode.java @@ -0,0 +1,39 @@ +package fns.datura.perms; + +import fns.patchwork.security.Node; +import fns.patchwork.security.NodeType; +import org.bukkit.permissions.Permission; +import org.bukkit.permissions.PermissionDefault; + +record PermissionNode(String key, long expiry, NodeType type, boolean wildcard) implements Node +{ + + @Override + public Permission bukkit() + { + return new Permission(key(), PermissionDefault.FALSE); + } + + @Override + public boolean compare(final Node node) + { + return node.key().equalsIgnoreCase(key()) && node.type().equals(type()) && !node.isExpired(); + } + + @Override + public boolean isExpired() + { + if (!isTemporary()) + { + return false; + } + + return System.currentTimeMillis() > expiry(); + } + + @Override + public boolean isTemporary() + { + return expiry() > -1; + } +} diff --git a/Datura/src/main/java/me/totalfreedom/datura/perms/PermissionNodeBuilder.java b/Datura/src/main/java/fns/datura/perms/PermissionNodeBuilder.java similarity index 57% rename from Datura/src/main/java/me/totalfreedom/datura/perms/PermissionNodeBuilder.java rename to Datura/src/main/java/fns/datura/perms/PermissionNodeBuilder.java index a89e69b..b1c3a0b 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/perms/PermissionNodeBuilder.java +++ b/Datura/src/main/java/fns/datura/perms/PermissionNodeBuilder.java @@ -1,17 +1,15 @@ -package me.totalfreedom.datura.perms; +package fns.datura.perms; -import me.totalfreedom.security.Node; -import me.totalfreedom.security.NodeBuilder; -import me.totalfreedom.security.NodeType; +import fns.patchwork.security.Node; +import fns.patchwork.security.NodeBuilder; +import fns.patchwork.security.NodeType; public class PermissionNodeBuilder implements NodeBuilder { private String key = "freedom.default"; - private boolean value = true; private long expiry = -1; private NodeType type = NodeType.PERMISSION; private boolean wildcard = false; - private boolean negated = false; @Override public NodeBuilder key(final String key) @@ -20,13 +18,6 @@ public class PermissionNodeBuilder implements NodeBuilder return this; } - @Override - public NodeBuilder value(final boolean value) - { - this.value = value; - return this; - } - @Override public NodeBuilder expiry(final long expiry) { @@ -48,16 +39,9 @@ public class PermissionNodeBuilder implements NodeBuilder return this; } - @Override - public NodeBuilder negated(final boolean negated) - { - this.negated = negated; - return this; - } - @Override public Node build() { - return new PermissionNode(key, value, expiry, type, wildcard, negated); + return new PermissionNode(key, expiry, type, wildcard); } } diff --git a/Datura/src/main/java/me/totalfreedom/datura/punishment/Cager.java b/Datura/src/main/java/fns/datura/punishment/Cager.java similarity index 94% rename from Datura/src/main/java/me/totalfreedom/datura/punishment/Cager.java rename to Datura/src/main/java/fns/datura/punishment/Cager.java index 52920aa..3a962d0 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/punishment/Cager.java +++ b/Datura/src/main/java/fns/datura/punishment/Cager.java @@ -1,8 +1,17 @@ -package me.totalfreedom.datura.punishment; +package fns.datura.punishment; -import me.totalfreedom.base.CommonsBase; -import me.totalfreedom.service.Service; -import me.totalfreedom.utils.ShapeUtils; +import fns.datura.Datura; +import fns.patchwork.base.Patchwork; +import fns.patchwork.service.Service; +import fns.patchwork.utils.ShapeUtils; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.function.DoubleUnaryOperator; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -12,27 +21,20 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.player.PlayerQuitEvent; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.function.DoubleUnaryOperator; +import javax.sound.midi.Patch; public class Cager extends Service { private final Set cagedPlayers; private final Map cageLocations; - public Cager() + public Cager(final Datura datura) { super("cager-service"); this.cagedPlayers = new HashSet<>(); this.cageLocations = new HashMap<>(); Bukkit.getPluginManager() - .registerEvents(new CageListener(), CommonsBase.getInstance()); + .registerEvents(new CageListener(), datura); } /** diff --git a/Datura/src/main/java/me/totalfreedom/datura/punishment/Halter.java b/Datura/src/main/java/fns/datura/punishment/Halter.java similarity index 78% rename from Datura/src/main/java/me/totalfreedom/datura/punishment/Halter.java rename to Datura/src/main/java/fns/datura/punishment/Halter.java index 11ef9be..d417bbf 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/punishment/Halter.java +++ b/Datura/src/main/java/fns/datura/punishment/Halter.java @@ -1,12 +1,11 @@ -package me.totalfreedom.datura.punishment; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerMoveEvent; +package fns.datura.punishment; import java.util.HashSet; import java.util.Set; import java.util.UUID; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerMoveEvent; public class Halter implements Listener { @@ -22,6 +21,16 @@ public class Halter implements Listener this.haltedPlayers.add(uuid); } + public void stop(final UUID uuid) + { + this.haltedPlayers.remove(uuid); + } + + public void clear() + { + this.haltedPlayers.clear(); + } + @EventHandler public void playerMove(final PlayerMoveEvent event) { diff --git a/Datura/src/main/java/me/totalfreedom/datura/punishment/Locker.java b/Datura/src/main/java/fns/datura/punishment/Locker.java similarity index 83% rename from Datura/src/main/java/me/totalfreedom/datura/punishment/Locker.java rename to Datura/src/main/java/fns/datura/punishment/Locker.java index 9e1e027..4649ff0 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/punishment/Locker.java +++ b/Datura/src/main/java/fns/datura/punishment/Locker.java @@ -1,18 +1,18 @@ -package me.totalfreedom.datura.punishment; +package fns.datura.punishment; -import me.totalfreedom.base.CommonsBase; -import me.totalfreedom.service.Service; +import fns.patchwork.base.Patchwork; +import fns.patchwork.base.Shortcuts; +import fns.patchwork.service.Service; +import java.util.HashSet; +import java.util.Set; +import java.util.SplittableRandom; +import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; -import java.util.HashSet; -import java.util.Set; -import java.util.SplittableRandom; -import java.util.UUID; - public class Locker extends Service { private final Set lockedPlayers = new HashSet<>(); @@ -35,10 +35,10 @@ public class Locker extends Service @Override public void tick() { - lockedPlayers.removeIf(uuid -> !CommonsBase.getInstance() - .getServer() - .getOfflinePlayer(uuid) - .isOnline()); + lockedPlayers.removeIf(uuid -> !Shortcuts.provideModule(Patchwork.class) + .getServer() + .getOfflinePlayer(uuid) + .isOnline()); for (final UUID uuid : lockedPlayers) { diff --git a/Datura/src/main/java/me/totalfreedom/datura/sql/MySQL.java b/Datura/src/main/java/fns/datura/sql/MySQL.java similarity index 83% rename from Datura/src/main/java/me/totalfreedom/datura/sql/MySQL.java rename to Datura/src/main/java/fns/datura/sql/MySQL.java index 9446e08..57afd1b 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/sql/MySQL.java +++ b/Datura/src/main/java/fns/datura/sql/MySQL.java @@ -1,9 +1,9 @@ -package me.totalfreedom.datura.sql; - -import me.totalfreedom.base.CommonsBase; -import me.totalfreedom.sql.SQL; -import me.totalfreedom.utils.container.Identity; +package fns.datura.sql; +import fns.patchwork.base.Patchwork; +import fns.patchwork.base.Shortcuts; +import fns.patchwork.sql.SQL; +import fns.patchwork.utils.container.Identity; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; @@ -75,9 +75,9 @@ public class MySQL implements SQL throw new CompletionException("Failed to prepare statement: " + query + "\n", ex); } - }, CommonsBase.getInstance() - .getExecutor() - .getAsync()); + }, Shortcuts.provideModule(Patchwork.class) + .getExecutor() + .getAsync()); } private CompletableFuture getConnection() @@ -92,9 +92,9 @@ public class MySQL implements SQL throw new CompletionException("Failed to connect to the database: " + url.toString() + "\n", ex); } - }, CommonsBase.getInstance() - .getExecutor() - .getAsync()); + }, Shortcuts.provideModule(Patchwork.class) + .getExecutor() + .getAsync()); } @Override @@ -112,9 +112,9 @@ public class MySQL implements SQL "Failed to retrieve a result set from query: " + query + "\n", ex); } - }, CommonsBase.getInstance() - .getExecutor() - .getAsync()); + }, Shortcuts.provideModule(Patchwork.class) + .getExecutor() + .getAsync()); } @Override @@ -131,9 +131,9 @@ public class MySQL implements SQL throw new CompletionException("Failed to execute update: " + query + "\n", ex); } - }, CommonsBase.getInstance() - .getExecutor() - .getAsync()); + }, Shortcuts.provideModule(Patchwork.class) + .getExecutor() + .getAsync()); } @Override @@ -150,9 +150,9 @@ public class MySQL implements SQL throw new CompletionException("Failed to execute statement: " + query + "\n", ex); } - }, CommonsBase.getInstance() - .getExecutor() - .getAsync()); + }, Shortcuts.provideModule(Patchwork.class) + .getExecutor() + .getAsync()); } @Override @@ -194,26 +194,26 @@ public class MySQL implements SQL ex); } return null; - }, CommonsBase.getInstance() - .getExecutor() - .getAsync()); + }, Shortcuts.provideModule(Patchwork.class) + .getExecutor() + .getAsync()); } public CompletableFuture updateColumn(final String table, final String column, final Object value, final String key, final Identity identity) { return executeUpdate("UPDATE ? SET ? = ? WHERE ? = ?", table, column, value, key, identity.getId()) - .thenApplyAsync(result -> result > 0, CommonsBase.getInstance() - .getExecutor() - .getAsync()); + .thenApplyAsync(result -> result > 0, Shortcuts.provideModule(Patchwork.class) + .getExecutor() + .getAsync()); } public CompletableFuture deleteRow(final String table, final String key, final Identity identity) { return executeUpdate("DELETE FROM ? WHERE ? = ?", table, key, identity.getId()) - .thenApplyAsync(result -> result > 0, CommonsBase.getInstance() - .getExecutor() - .getAsync()); + .thenApplyAsync(result -> result > 0, Shortcuts.provideModule(Patchwork.class) + .getExecutor() + .getAsync()); } public CompletableFuture insertRow(final String table, final Object... values) diff --git a/Datura/src/main/java/me/totalfreedom/datura/sql/Result.java b/Datura/src/main/java/fns/datura/sql/Result.java similarity index 83% rename from Datura/src/main/java/me/totalfreedom/datura/sql/Result.java rename to Datura/src/main/java/fns/datura/sql/Result.java index 9fd214b..7f51cee 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/sql/Result.java +++ b/Datura/src/main/java/fns/datura/sql/Result.java @@ -1,4 +1,4 @@ -package me.totalfreedom.datura.sql; +package fns.datura.sql; import com.google.errorprone.annotations.Immutable; diff --git a/Datura/src/main/java/me/totalfreedom/datura/user/ServerEconomyHolder.java b/Datura/src/main/java/fns/datura/user/ServerEconomyHolder.java similarity index 96% rename from Datura/src/main/java/me/totalfreedom/datura/user/ServerEconomyHolder.java rename to Datura/src/main/java/fns/datura/user/ServerEconomyHolder.java index 768ac91..5ac8649 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/user/ServerEconomyHolder.java +++ b/Datura/src/main/java/fns/datura/user/ServerEconomyHolder.java @@ -1,7 +1,7 @@ -package me.totalfreedom.datura.user; +package fns.datura.user; -import me.totalfreedom.economy.EconomicEntity; -import me.totalfreedom.economy.EconomicEntityData; +import fns.patchwork.economy.EconomicEntity; +import fns.patchwork.economy.EconomicEntityData; /** * Represents the server's economy holder. diff --git a/Datura/src/main/java/me/totalfreedom/datura/user/SimpleUserData.java b/Datura/src/main/java/fns/datura/user/SimpleUserData.java similarity index 78% rename from Datura/src/main/java/me/totalfreedom/datura/user/SimpleUserData.java rename to Datura/src/main/java/fns/datura/user/SimpleUserData.java index 014876c..f313ef3 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/user/SimpleUserData.java +++ b/Datura/src/main/java/fns/datura/user/SimpleUserData.java @@ -1,23 +1,25 @@ -package me.totalfreedom.datura.user; +package fns.datura.user; -import me.totalfreedom.base.CommonsBase; -import me.totalfreedom.datura.event.UserDataUpdateEvent; -import me.totalfreedom.datura.perms.FreedomUser; -import me.totalfreedom.security.Group; -import me.totalfreedom.sql.SQL; -import me.totalfreedom.user.User; -import me.totalfreedom.user.UserData; -import me.totalfreedom.utils.logging.FreedomLogger; +import fns.datura.event.UserDataUpdateEvent; +import fns.datura.perms.FreedomUser; +import fns.patchwork.base.Patchwork; +import fns.patchwork.base.Registration; +import fns.patchwork.base.Shortcuts; +import fns.patchwork.display.adminchat.AdminChatFormat; +import fns.patchwork.security.Group; +import fns.patchwork.sql.SQL; +import fns.patchwork.user.User; +import fns.patchwork.user.UserData; +import fns.patchwork.utils.logging.FreedomLogger; +import java.sql.SQLException; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicLong; import org.apache.commons.lang3.exception.ExceptionUtils; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.sql.SQLException; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicLong; - public class SimpleUserData implements UserData { private final UUID uuid; @@ -29,6 +31,8 @@ public class SimpleUserData implements UserData private boolean canInteract; private AtomicLong balance; private boolean transactionsFrozen; + private boolean hasCustomACFormat = false; + private String customACFormat; public SimpleUserData(final Player player) { @@ -36,9 +40,9 @@ public class SimpleUserData implements UserData this.username = player.getName(); this.user = new FreedomUser(player); - CommonsBase.getInstance() - .getEventBus() - .addEvent(event); + Shortcuts.provideModule(Patchwork.class) + .getEventBus() + .addEvent(event); } private SimpleUserData( @@ -59,6 +63,7 @@ public class SimpleUserData implements UserData this.canInteract = canInteract; this.balance = new AtomicLong(balance); this.transactionsFrozen = transactionsFrozen; + this.customACFormat = AdminChatFormat.DEFAULT.serialize(); } public static SimpleUserData fromSQL(final SQL sql, final String uuid) @@ -81,10 +86,9 @@ public class SimpleUserData implements UserData throw new IllegalStateException("Player should be online but they are not!"); final User user = new FreedomUser(player); - final Group group = CommonsBase.getInstance() - .getRegistrations() - .getGroupRegistry() - .getGroup(g); + final Group group = Registration + .getGroupRegistry() + .getGroup(g); final long playtime = result.getLong("playtime"); final boolean canInteract = result.getBoolean("canInteract"); @@ -113,9 +117,9 @@ public class SimpleUserData implements UserData if (player == null) throw new IllegalStateException("Player should be online but they are not!"); return new SimpleUserData(player); - }, CommonsBase.getInstance() - .getExecutor() - .getAsync()) + }, Shortcuts.provideModule(Patchwork.class) + .getExecutor() + .getAsync()) .join(); } @@ -219,4 +223,23 @@ public class SimpleUserData implements UserData { return balance.addAndGet(-amount); } + + @Override + public boolean hasCustomACFormat() + { + return hasCustomACFormat; + } + + @Override + public AdminChatFormat getCustomACFormat() + { + return AdminChatFormat.deserialize(customACFormat); + } + + @Override + public void setCustomACFormat(final String format) + { + this.hasCustomACFormat = format.equals(AdminChatFormat.DEFAULT.serialize()); + this.customACFormat = format; + } } diff --git a/Datura/src/main/java/me/totalfreedom/datura/Datura.java b/Datura/src/main/java/me/totalfreedom/datura/Datura.java deleted file mode 100644 index da40da4..0000000 --- a/Datura/src/main/java/me/totalfreedom/datura/Datura.java +++ /dev/null @@ -1,60 +0,0 @@ -package me.totalfreedom.datura; - -import me.totalfreedom.base.CommonsBase; -import me.totalfreedom.datura.punishment.Cager; -import me.totalfreedom.datura.punishment.Halter; -import me.totalfreedom.datura.punishment.Locker; -import me.totalfreedom.datura.sql.MySQL; -import me.totalfreedom.service.SubscriptionProvider; -import org.bukkit.Bukkit; -import org.bukkit.plugin.java.JavaPlugin; - -public class Datura extends JavaPlugin -{ - private final MySQL sql = new MySQL("localhost", 3011, "master"); - private final Halter halter = new Halter(); - private final Locker locker = new Locker(); - private final Cager cager = new Cager(); - - - @Override - public void onEnable() - { - CommonsBase.getInstance() - .getRegistrations() - .getModuleRegistry() - .addModule(this); - - CommonsBase.getInstance() - .getRegistrations() - .getServiceTaskRegistry() - .registerService(SubscriptionProvider.syncService(this, locker)); - CommonsBase.getInstance() - .getRegistrations() - .getServiceTaskRegistry() - .registerService(SubscriptionProvider.syncService(this, cager)); - - Bukkit.getPluginManager() - .registerEvents(halter, this); - } - - public MySQL getSQL() - { - return sql; - } - - public Halter getHalter() - { - return halter; - } - - public Locker getLocker() - { - return locker; - } - - public Cager getCager() - { - return cager; - } -} diff --git a/Datura/src/main/java/me/totalfreedom/datura/perms/PermissionNode.java b/Datura/src/main/java/me/totalfreedom/datura/perms/PermissionNode.java deleted file mode 100644 index 48870b9..0000000 --- a/Datura/src/main/java/me/totalfreedom/datura/perms/PermissionNode.java +++ /dev/null @@ -1,49 +0,0 @@ -package me.totalfreedom.datura.perms; - -import me.totalfreedom.security.Node; -import me.totalfreedom.security.NodeType; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionDefault; - -record PermissionNode(String key, - boolean value, - long expiry, - NodeType type, - boolean wildcard) implements Node -{ - - @Override - public Permission bukkit() - { - return new Permission(key(), - value() - ? PermissionDefault.TRUE - : PermissionDefault.FALSE); - } - - @Override - public boolean compare(final Node node) - { - return node.key() - .equalsIgnoreCase(key()) - && node.value() == value() - && node.type() == type(); - } - - @Override - public boolean isExpired() - { - if (!isTemporary()) - { - return false; - } - - return System.currentTimeMillis() > expiry(); - } - - @Override - public boolean isTemporary() - { - return expiry() > -1; - } -} diff --git a/Datura/src/main/resources/plugin.yml b/Datura/src/main/resources/plugin.yml index 0455676..a70371e 100644 --- a/Datura/src/main/resources/plugin.yml +++ b/Datura/src/main/resources/plugin.yml @@ -1,5 +1,6 @@ name: Datura -main: me.totalfreedom.datura.Datura +main: fns.datura.Datura +api-version: 1.20 version: 1.0.0 author: TotalFreedom description: Data Manager for the Freedom Network Suite diff --git a/Fossil/src/main/java/fns/fossil/Fossil.java b/Fossil/src/main/java/fns/fossil/Fossil.java new file mode 100644 index 0000000..7a470b5 --- /dev/null +++ b/Fossil/src/main/java/fns/fossil/Fossil.java @@ -0,0 +1,21 @@ +package fns.fossil; + +import fns.fossil.trail.Trailer; +import fns.patchwork.base.Registration; +import fns.patchwork.service.SubscriptionProvider; +import org.bukkit.plugin.java.JavaPlugin; + +public class Fossil extends JavaPlugin +{ + private final Trailer trailer = new Trailer(); + @Override + public void onEnable() + { + Registration.getServiceTaskRegistry() + .registerService( + SubscriptionProvider.syncService(this, trailer)); + + Registration.getModuleRegistry() + .addModule(this); + } +} diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/bouncypads/BouncyPad.java b/Fossil/src/main/java/fns/fossil/bouncypads/BouncyPad.java similarity index 99% rename from Fossil/src/main/java/me/totalfreedom/fossil/bouncypads/BouncyPad.java rename to Fossil/src/main/java/fns/fossil/bouncypads/BouncyPad.java index cacd37a..176af05 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/bouncypads/BouncyPad.java +++ b/Fossil/src/main/java/fns/fossil/bouncypads/BouncyPad.java @@ -1,12 +1,11 @@ -package me.totalfreedom.fossil.bouncypads; +package fns.fossil.bouncypads; import com.google.errorprone.annotations.Immutable; +import java.util.SplittableRandom; import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import java.util.SplittableRandom; - /** * Represents a bouncy pad. Has a velocity and a type. */ diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/bouncypads/PadHolder.java b/Fossil/src/main/java/fns/fossil/bouncypads/PadHolder.java similarity index 92% rename from Fossil/src/main/java/me/totalfreedom/fossil/bouncypads/PadHolder.java rename to Fossil/src/main/java/fns/fossil/bouncypads/PadHolder.java index cd4842e..487a263 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/bouncypads/PadHolder.java +++ b/Fossil/src/main/java/fns/fossil/bouncypads/PadHolder.java @@ -1,7 +1,12 @@ -package me.totalfreedom.fossil.bouncypads; +package fns.fossil.bouncypads; -import me.totalfreedom.base.CommonsBase; -import me.totalfreedom.fossil.Fossil; +import fns.fossil.Fossil; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Stream; + +import fns.patchwork.base.Shortcuts; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Tag; @@ -12,11 +17,6 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerMoveEvent; import org.jetbrains.annotations.Nullable; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; -import java.util.stream.Stream; - /** * Holds all the active pads for each player, and also manages player pad interaction. */ @@ -33,12 +33,7 @@ public class PadHolder implements Listener public PadHolder() { Bukkit.getPluginManager() - .registerEvents(this, CommonsBase - .getInstance() - .getRegistrations() - .getModuleRegistry() - .getProvider(Fossil.class) - .getModule()); + .registerEvents(this, Shortcuts.provideModule(Fossil.class)); } /** diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/bouncypads/PadType.java b/Fossil/src/main/java/fns/fossil/bouncypads/PadType.java similarity index 94% rename from Fossil/src/main/java/me/totalfreedom/fossil/bouncypads/PadType.java rename to Fossil/src/main/java/fns/fossil/bouncypads/PadType.java index 2c58591..a6f4c33 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/bouncypads/PadType.java +++ b/Fossil/src/main/java/fns/fossil/bouncypads/PadType.java @@ -1,4 +1,4 @@ -package me.totalfreedom.fossil.bouncypads; +package fns.fossil.bouncypads; import org.bukkit.block.BlockFace; diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/cmd/CakeCommand.java b/Fossil/src/main/java/fns/fossil/cmd/CakeCommand.java similarity index 73% rename from Fossil/src/main/java/me/totalfreedom/fossil/cmd/CakeCommand.java rename to Fossil/src/main/java/fns/fossil/cmd/CakeCommand.java index 7a5c7b0..3328a66 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/cmd/CakeCommand.java +++ b/Fossil/src/main/java/fns/fossil/cmd/CakeCommand.java @@ -19,13 +19,13 @@ * THE SOFTWARE. */ -package me.totalfreedom.fossil.cmd; +package fns.fossil.cmd; -import me.totalfreedom.command.Commander; -import me.totalfreedom.command.annotation.Base; -import me.totalfreedom.command.annotation.Info; -import me.totalfreedom.command.annotation.Permissive; -import me.totalfreedom.utils.kyori.FreedomMiniMessage; +import fns.patchwork.command.Commander; +import fns.patchwork.command.annotation.Base; +import fns.patchwork.command.annotation.Info; +import fns.patchwork.command.annotation.Permissive; +import fns.patchwork.utils.kyori.FreedomMiniMessage; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.command.CommandSender; @@ -46,9 +46,11 @@ public class CakeCommand extends Commander @Base public void broadcastCake(final CommandSender sender) { - Bukkit.broadcast(FreedomMiniMessage.deserialize(true, - "But there's no sense crying over every mistake. You just keep on trying till you run out of " + - "cake.")); + Bukkit.getServer().sendMessage(FreedomMiniMessage.deserialize(true, + "But there's no sense crying over " + + "every mistake. You just keep on trying " + + "till you run out of " + + "cake.")); final ItemStack stack = new ItemStack(Material.CAKE, 1); final ItemMeta meta = stack.getItemMeta(); diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleCompletedTransaction.java b/Fossil/src/main/java/fns/fossil/economy/SimpleCompletedTransaction.java similarity index 80% rename from Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleCompletedTransaction.java rename to Fossil/src/main/java/fns/fossil/economy/SimpleCompletedTransaction.java index d9c666a..fe0af1f 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleCompletedTransaction.java +++ b/Fossil/src/main/java/fns/fossil/economy/SimpleCompletedTransaction.java @@ -1,9 +1,9 @@ -package me.totalfreedom.fossil.economy; +package fns.fossil.economy; -import me.totalfreedom.economy.CompletedTransaction; -import me.totalfreedom.economy.EconomicEntity; -import me.totalfreedom.economy.Transaction; -import me.totalfreedom.economy.TransactionResult; +import fns.patchwork.economy.CompletedTransaction; +import fns.patchwork.economy.EconomicEntity; +import fns.patchwork.economy.Transaction; +import fns.patchwork.economy.TransactionResult; public class SimpleCompletedTransaction implements CompletedTransaction { diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleLoggedTransactor.java b/Fossil/src/main/java/fns/fossil/economy/SimpleLoggedTransactor.java similarity index 79% rename from Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleLoggedTransactor.java rename to Fossil/src/main/java/fns/fossil/economy/SimpleLoggedTransactor.java index 440c0b3..3a18dcc 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleLoggedTransactor.java +++ b/Fossil/src/main/java/fns/fossil/economy/SimpleLoggedTransactor.java @@ -1,9 +1,9 @@ -package me.totalfreedom.fossil.economy; +package fns.fossil.economy; -import me.totalfreedom.economy.CompletedTransaction; -import me.totalfreedom.economy.MutableTransaction; -import me.totalfreedom.economy.TransactionLogger; -import me.totalfreedom.economy.Transactor; +import fns.patchwork.economy.CompletedTransaction; +import fns.patchwork.economy.MutableTransaction; +import fns.patchwork.economy.TransactionLogger; +import fns.patchwork.economy.Transactor; public class SimpleLoggedTransactor implements Transactor { diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleMutableTransaction.java b/Fossil/src/main/java/fns/fossil/economy/SimpleMutableTransaction.java similarity index 81% rename from Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleMutableTransaction.java rename to Fossil/src/main/java/fns/fossil/economy/SimpleMutableTransaction.java index 9aadb26..9c46559 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleMutableTransaction.java +++ b/Fossil/src/main/java/fns/fossil/economy/SimpleMutableTransaction.java @@ -1,7 +1,7 @@ -package me.totalfreedom.fossil.economy; +package fns.fossil.economy; -import me.totalfreedom.economy.EconomicEntity; -import me.totalfreedom.economy.MutableTransaction; +import fns.patchwork.economy.EconomicEntity; +import fns.patchwork.economy.MutableTransaction; public class SimpleMutableTransaction extends SimpleTransaction implements MutableTransaction { diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransaction.java b/Fossil/src/main/java/fns/fossil/economy/SimpleTransaction.java similarity index 85% rename from Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransaction.java rename to Fossil/src/main/java/fns/fossil/economy/SimpleTransaction.java index 93bf7b7..1d1fcc9 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransaction.java +++ b/Fossil/src/main/java/fns/fossil/economy/SimpleTransaction.java @@ -1,8 +1,7 @@ -package me.totalfreedom.fossil.economy; - -import me.totalfreedom.economy.EconomicEntity; -import me.totalfreedom.economy.Transaction; +package fns.fossil.economy; +import fns.patchwork.economy.EconomicEntity; +import fns.patchwork.economy.Transaction; import java.util.concurrent.atomic.AtomicLong; public class SimpleTransaction implements Transaction diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransactionLogger.java b/Fossil/src/main/java/fns/fossil/economy/SimpleTransactionLogger.java similarity index 84% rename from Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransactionLogger.java rename to Fossil/src/main/java/fns/fossil/economy/SimpleTransactionLogger.java index 80ba2d2..3f5730f 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransactionLogger.java +++ b/Fossil/src/main/java/fns/fossil/economy/SimpleTransactionLogger.java @@ -1,11 +1,11 @@ -package me.totalfreedom.fossil.economy; +package fns.fossil.economy; -import me.totalfreedom.audience.MutableAudienceForwarder; -import me.totalfreedom.economy.CompletedTransaction; -import me.totalfreedom.economy.EconomicEntity; -import me.totalfreedom.economy.TransactionLogger; -import me.totalfreedom.economy.TransactionResult; -import me.totalfreedom.utils.logging.FreedomLogger; +import fns.patchwork.audience.MutableAudienceForwarder; +import fns.patchwork.economy.CompletedTransaction; +import fns.patchwork.economy.EconomicEntity; +import fns.patchwork.economy.TransactionLogger; +import fns.patchwork.economy.TransactionResult; +import fns.patchwork.utils.logging.FreedomLogger; import net.kyori.adventure.text.Component; public class SimpleTransactionLogger implements TransactionLogger diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransactionResult.java b/Fossil/src/main/java/fns/fossil/economy/SimpleTransactionResult.java similarity index 75% rename from Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransactionResult.java rename to Fossil/src/main/java/fns/fossil/economy/SimpleTransactionResult.java index e0ee389..1f15eb4 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransactionResult.java +++ b/Fossil/src/main/java/fns/fossil/economy/SimpleTransactionResult.java @@ -1,6 +1,6 @@ -package me.totalfreedom.fossil.economy; +package fns.fossil.economy; -import me.totalfreedom.economy.TransactionResult; +import fns.patchwork.economy.TransactionResult; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -15,20 +15,20 @@ public class SimpleTransactionResult implements TransactionResult "The source has an insufficient balance to carry out this transaction.", false); private final String message; private final Component component; - private final boolean successful; + private final boolean isSuccessful; - public SimpleTransactionResult(final String message, final boolean successful) + public SimpleTransactionResult(final String message, final boolean isSuccessful) { - this(message, Component.text(message, successful - ? NamedTextColor.GREEN - : NamedTextColor.RED), successful); + this(message, Component.text(message, isSuccessful + ? NamedTextColor.GREEN + : NamedTextColor.RED), isSuccessful); } - public SimpleTransactionResult(final String message, final Component component, final boolean successful) + public SimpleTransactionResult(final String message, final Component component, final boolean isSuccessful) { this.message = message; this.component = component; - this.successful = successful; + this.isSuccessful = isSuccessful; } @Override @@ -40,7 +40,7 @@ public class SimpleTransactionResult implements TransactionResult @Override public boolean isSuccessful() { - return successful; + return isSuccessful; } @Override diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransactor.java b/Fossil/src/main/java/fns/fossil/economy/SimpleTransactor.java similarity index 84% rename from Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransactor.java rename to Fossil/src/main/java/fns/fossil/economy/SimpleTransactor.java index 09858ab..7e24be4 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransactor.java +++ b/Fossil/src/main/java/fns/fossil/economy/SimpleTransactor.java @@ -1,10 +1,10 @@ -package me.totalfreedom.fossil.economy; +package fns.fossil.economy; -import me.totalfreedom.economy.CompletedTransaction; -import me.totalfreedom.economy.EconomicEntity; -import me.totalfreedom.economy.EconomicEntityData; -import me.totalfreedom.economy.MutableTransaction; -import me.totalfreedom.economy.Transactor; +import fns.patchwork.economy.CompletedTransaction; +import fns.patchwork.economy.EconomicEntity; +import fns.patchwork.economy.EconomicEntityData; +import fns.patchwork.economy.MutableTransaction; +import fns.patchwork.economy.Transactor; public class SimpleTransactor implements Transactor { diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/items/ClownfishItem.java b/Fossil/src/main/java/fns/fossil/items/ClownfishItem.java similarity index 95% rename from Fossil/src/main/java/me/totalfreedom/fossil/items/ClownfishItem.java rename to Fossil/src/main/java/fns/fossil/items/ClownfishItem.java index 0bf1131..972094a 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/items/ClownfishItem.java +++ b/Fossil/src/main/java/fns/fossil/items/ClownfishItem.java @@ -1,4 +1,4 @@ -package me.totalfreedom.fossil.items; +package fns.fossil.items; import org.bukkit.Location; import org.bukkit.Material; diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/items/ShopItem.java b/Fossil/src/main/java/fns/fossil/items/ShopItem.java similarity index 95% rename from Fossil/src/main/java/me/totalfreedom/fossil/items/ShopItem.java rename to Fossil/src/main/java/fns/fossil/items/ShopItem.java index 04f6bb9..5ec1c9d 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/items/ShopItem.java +++ b/Fossil/src/main/java/fns/fossil/items/ShopItem.java @@ -1,4 +1,4 @@ -package me.totalfreedom.fossil.items; +package fns.fossil.items; import org.bukkit.Material; import org.bukkit.entity.Entity; diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/items/TrailItem.java b/Fossil/src/main/java/fns/fossil/items/TrailItem.java similarity index 91% rename from Fossil/src/main/java/me/totalfreedom/fossil/items/TrailItem.java rename to Fossil/src/main/java/fns/fossil/items/TrailItem.java index ea95de6..9ecae33 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/items/TrailItem.java +++ b/Fossil/src/main/java/fns/fossil/items/TrailItem.java @@ -1,4 +1,4 @@ -package me.totalfreedom.fossil.items; +package fns.fossil.items; import org.bukkit.Material; import org.bukkit.entity.Entity; diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/reactions/CopyCatReaction.java b/Fossil/src/main/java/fns/fossil/reactions/CopyCatReaction.java similarity index 78% rename from Fossil/src/main/java/me/totalfreedom/fossil/reactions/CopyCatReaction.java rename to Fossil/src/main/java/fns/fossil/reactions/CopyCatReaction.java index 52460e8..6ec3932 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/reactions/CopyCatReaction.java +++ b/Fossil/src/main/java/fns/fossil/reactions/CopyCatReaction.java @@ -1,15 +1,13 @@ -package me.totalfreedom.fossil.reactions; +package fns.fossil.reactions; -import me.totalfreedom.display.BossBarDisplay; -import me.totalfreedom.economy.EconomicEntity; -import me.totalfreedom.shop.Reaction; -import me.totalfreedom.shop.ReactionType; +import fns.patchwork.display.BossBarDisplay; +import fns.patchwork.economy.EconomicEntity; +import fns.patchwork.shop.Reaction; +import fns.patchwork.shop.ReactionType; +import java.util.SplittableRandom; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.bossbar.BossBar; -import java.util.SplittableRandom; -import java.util.function.Consumer; - /** * Represents a single chat reaction that can be performed by a player. */ @@ -29,12 +27,6 @@ public final class CopyCatReaction extends Reaction return reward; } - @Override - public void onReact(final Consumer entity) - { - entity.accept(null); - } - @Override public void display(final Audience audience) { @@ -44,6 +36,12 @@ public final class CopyCatReaction extends Reaction .build(); } + @Override + public void onReact(final EconomicEntity entity) + { + // + } + public String getRandomCharacterString() { final SplittableRandom random = new SplittableRandom(); diff --git a/Fossil/src/main/java/fns/fossil/shop/Shoppe.java b/Fossil/src/main/java/fns/fossil/shop/Shoppe.java new file mode 100644 index 0000000..8836bae --- /dev/null +++ b/Fossil/src/main/java/fns/fossil/shop/Shoppe.java @@ -0,0 +1,5 @@ +package fns.fossil.shop; + +public class Shoppe +{ +} diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/shop/menus/MainMenu.java b/Fossil/src/main/java/fns/fossil/shop/menus/MainMenu.java similarity index 59% rename from Fossil/src/main/java/me/totalfreedom/fossil/shop/menus/MainMenu.java rename to Fossil/src/main/java/fns/fossil/shop/menus/MainMenu.java index c637c56..2ea0394 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/shop/menus/MainMenu.java +++ b/Fossil/src/main/java/fns/fossil/shop/menus/MainMenu.java @@ -1,6 +1,6 @@ -package me.totalfreedom.fossil.shop.menus; +package fns.fossil.shop.menus; -import me.totalfreedom.display.AbstractMenu; +import fns.patchwork.display.AbstractMenu; public final class MainMenu extends AbstractMenu { diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/trail/Trailer.java b/Fossil/src/main/java/fns/fossil/trail/Trailer.java similarity index 85% rename from Fossil/src/main/java/me/totalfreedom/fossil/trail/Trailer.java rename to Fossil/src/main/java/fns/fossil/trail/Trailer.java index b530595..ef9e05b 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/trail/Trailer.java +++ b/Fossil/src/main/java/fns/fossil/trail/Trailer.java @@ -1,8 +1,7 @@ -package me.totalfreedom.fossil.trail; - -import me.totalfreedom.particle.Trail; -import me.totalfreedom.service.Service; +package fns.fossil.trail; +import fns.patchwork.particle.Trail; +import fns.patchwork.service.Service; import java.util.ArrayList; import java.util.List; diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/trail/types/BasicTrail.java b/Fossil/src/main/java/fns/fossil/trail/types/BasicTrail.java similarity index 92% rename from Fossil/src/main/java/me/totalfreedom/fossil/trail/types/BasicTrail.java rename to Fossil/src/main/java/fns/fossil/trail/types/BasicTrail.java index 6d6ee9b..f9746f8 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/trail/types/BasicTrail.java +++ b/Fossil/src/main/java/fns/fossil/trail/types/BasicTrail.java @@ -1,6 +1,6 @@ -package me.totalfreedom.fossil.trail.types; +package fns.fossil.trail.types; -import me.totalfreedom.particle.TrailType; +import fns.patchwork.particle.TrailType; import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.Particle; diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/trail/types/FlameTrail.java b/Fossil/src/main/java/fns/fossil/trail/types/FlameTrail.java similarity index 90% rename from Fossil/src/main/java/me/totalfreedom/fossil/trail/types/FlameTrail.java rename to Fossil/src/main/java/fns/fossil/trail/types/FlameTrail.java index 2fe823e..e141cb7 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/trail/types/FlameTrail.java +++ b/Fossil/src/main/java/fns/fossil/trail/types/FlameTrail.java @@ -1,6 +1,6 @@ -package me.totalfreedom.fossil.trail.types; +package fns.fossil.trail.types; -import me.totalfreedom.particle.TrailType; +import fns.patchwork.particle.TrailType; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.util.Vector; diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/trail/types/HeartTrail.java b/Fossil/src/main/java/fns/fossil/trail/types/HeartTrail.java similarity index 88% rename from Fossil/src/main/java/me/totalfreedom/fossil/trail/types/HeartTrail.java rename to Fossil/src/main/java/fns/fossil/trail/types/HeartTrail.java index 968a6ef..8bc2784 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/trail/types/HeartTrail.java +++ b/Fossil/src/main/java/fns/fossil/trail/types/HeartTrail.java @@ -1,6 +1,6 @@ -package me.totalfreedom.fossil.trail.types; +package fns.fossil.trail.types; -import me.totalfreedom.particle.TrailType; +import fns.patchwork.particle.TrailType; import org.bukkit.Location; import org.bukkit.entity.Player; diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/trail/types/RainbowTrail.java b/Fossil/src/main/java/fns/fossil/trail/types/RainbowTrail.java similarity index 90% rename from Fossil/src/main/java/me/totalfreedom/fossil/trail/types/RainbowTrail.java rename to Fossil/src/main/java/fns/fossil/trail/types/RainbowTrail.java index b020349..5f80dd9 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/trail/types/RainbowTrail.java +++ b/Fossil/src/main/java/fns/fossil/trail/types/RainbowTrail.java @@ -1,14 +1,13 @@ -package me.totalfreedom.fossil.trail.types; +package fns.fossil.trail.types; -import me.totalfreedom.particle.TrailType; -import me.totalfreedom.utils.InterpolationUtils; +import fns.patchwork.particle.TrailType; +import fns.patchwork.utils.InterpolationUtils; +import java.util.Iterator; import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.Particle; import org.bukkit.entity.Player; -import java.util.Iterator; - public final class RainbowTrail extends SimpleTrail { private Iterator currentColor; diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/trail/types/SimpleTrail.java b/Fossil/src/main/java/fns/fossil/trail/types/SimpleTrail.java similarity index 93% rename from Fossil/src/main/java/me/totalfreedom/fossil/trail/types/SimpleTrail.java rename to Fossil/src/main/java/fns/fossil/trail/types/SimpleTrail.java index 6988ba5..bf2c249 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/trail/types/SimpleTrail.java +++ b/Fossil/src/main/java/fns/fossil/trail/types/SimpleTrail.java @@ -1,7 +1,9 @@ -package me.totalfreedom.fossil.trail.types; +package fns.fossil.trail.types; -import me.totalfreedom.particle.Trail; -import me.totalfreedom.particle.TrailType; +import fns.patchwork.particle.Trail; +import fns.patchwork.particle.TrailType; +import java.util.Set; +import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.OfflinePlayer; @@ -9,9 +11,6 @@ import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Set; -import java.util.UUID; - public abstract class SimpleTrail implements Trail { private final UUID associatedPlayerUUID; diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/trail/types/StrobeTrail.java b/Fossil/src/main/java/fns/fossil/trail/types/StrobeTrail.java similarity index 91% rename from Fossil/src/main/java/me/totalfreedom/fossil/trail/types/StrobeTrail.java rename to Fossil/src/main/java/fns/fossil/trail/types/StrobeTrail.java index 1e444c5..541aa93 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/trail/types/StrobeTrail.java +++ b/Fossil/src/main/java/fns/fossil/trail/types/StrobeTrail.java @@ -1,6 +1,6 @@ -package me.totalfreedom.fossil.trail.types; +package fns.fossil.trail.types; -import me.totalfreedom.particle.TrailType; +import fns.patchwork.particle.TrailType; import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.Particle; diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/trail/types/TrailProvider.java b/Fossil/src/main/java/fns/fossil/trail/types/TrailProvider.java similarity index 80% rename from Fossil/src/main/java/me/totalfreedom/fossil/trail/types/TrailProvider.java rename to Fossil/src/main/java/fns/fossil/trail/types/TrailProvider.java index 1110266..55ec075 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/trail/types/TrailProvider.java +++ b/Fossil/src/main/java/fns/fossil/trail/types/TrailProvider.java @@ -1,4 +1,4 @@ -package me.totalfreedom.fossil.trail.types; +package fns.fossil.trail.types; import org.bukkit.entity.Player; diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/Fossil.java b/Fossil/src/main/java/me/totalfreedom/fossil/Fossil.java deleted file mode 100644 index 18dc7fb..0000000 --- a/Fossil/src/main/java/me/totalfreedom/fossil/Fossil.java +++ /dev/null @@ -1,25 +0,0 @@ -package me.totalfreedom.fossil; - -import me.totalfreedom.base.CommonsBase; -import me.totalfreedom.base.Registration; -import me.totalfreedom.fossil.trail.Trailer; -import me.totalfreedom.service.SubscriptionProvider; -import org.bukkit.plugin.java.JavaPlugin; - -public class Fossil extends JavaPlugin -{ - private final Trailer trailer = new Trailer(); - private final Registration registration = CommonsBase.getInstance() - .getRegistrations(); - - @Override - public void onEnable() - { - registration.getModuleRegistry() - .addModule(this); - - registration.getServiceTaskRegistry() - .registerService( - SubscriptionProvider.syncService(this, trailer)); - } -} diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/shop/Shoppe.java b/Fossil/src/main/java/me/totalfreedom/fossil/shop/Shoppe.java deleted file mode 100644 index d586412..0000000 --- a/Fossil/src/main/java/me/totalfreedom/fossil/shop/Shoppe.java +++ /dev/null @@ -1,5 +0,0 @@ -package me.totalfreedom.fossil.shop; - -public class Shoppe -{ -} diff --git a/Fossil/src/main/resources/plugin.yml b/Fossil/src/main/resources/plugin.yml index 99f537c..f3212a7 100644 --- a/Fossil/src/main/resources/plugin.yml +++ b/Fossil/src/main/resources/plugin.yml @@ -1,6 +1,7 @@ name: Fossil version: 1.0 -main: me.totalfreedom.fossil.Fossil +main: fns.fossil.Fossil +api-version: 1.20 author: TotalFreedom description: The Fun Module for the Freedom Network. depend: diff --git a/Patchwork/src/main/java/me/totalfreedom/api/Context.java b/Patchwork/src/main/java/fns/patchwork/api/Context.java similarity index 98% rename from Patchwork/src/main/java/me/totalfreedom/api/Context.java rename to Patchwork/src/main/java/fns/patchwork/api/Context.java index 321cca6..063a48b 100644 --- a/Patchwork/src/main/java/me/totalfreedom/api/Context.java +++ b/Patchwork/src/main/java/fns/patchwork/api/Context.java @@ -1,6 +1,7 @@ -package me.totalfreedom.api; +package fns.patchwork.api; -import me.totalfreedom.provider.ContextProvider; +import fns.patchwork.provider.ContextProvider; +import java.util.function.Function; import net.kyori.adventure.text.Component; import org.bukkit.Location; import org.bukkit.World; @@ -12,8 +13,6 @@ import org.bukkit.event.block.Action; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.function.Function; - /** * Represents an object context. This class is a simple generic type wrapper that can be used to ensure data types. This * class is also used to provide a simple way to map data types. diff --git a/Patchwork/src/main/java/me/totalfreedom/api/Interpolator.java b/Patchwork/src/main/java/fns/patchwork/api/Interpolator.java similarity index 95% rename from Patchwork/src/main/java/me/totalfreedom/api/Interpolator.java rename to Patchwork/src/main/java/fns/patchwork/api/Interpolator.java index 0a6c598..1acd20c 100644 --- a/Patchwork/src/main/java/me/totalfreedom/api/Interpolator.java +++ b/Patchwork/src/main/java/fns/patchwork/api/Interpolator.java @@ -1,4 +1,4 @@ -package me.totalfreedom.api; +package fns.patchwork.api; /** * Interpolates a range of values and returns the results in a {@link Double} array. diff --git a/Patchwork/src/main/java/me/totalfreedom/api/Serializable.java b/Patchwork/src/main/java/fns/patchwork/api/Serializable.java similarity index 96% rename from Patchwork/src/main/java/me/totalfreedom/api/Serializable.java rename to Patchwork/src/main/java/fns/patchwork/api/Serializable.java index 3dc62a6..37b38ff 100644 --- a/Patchwork/src/main/java/me/totalfreedom/api/Serializable.java +++ b/Patchwork/src/main/java/fns/patchwork/api/Serializable.java @@ -1,4 +1,4 @@ -package me.totalfreedom.api; +package fns.patchwork.api; /** * This interface represents a Serializable object. Objects which require custom serialization and cannot simply diff --git a/Patchwork/src/main/java/me/totalfreedom/audience/MutableAudienceForwarder.java b/Patchwork/src/main/java/fns/patchwork/audience/MutableAudienceForwarder.java similarity index 99% rename from Patchwork/src/main/java/me/totalfreedom/audience/MutableAudienceForwarder.java rename to Patchwork/src/main/java/fns/patchwork/audience/MutableAudienceForwarder.java index f725d73..802154f 100644 --- a/Patchwork/src/main/java/me/totalfreedom/audience/MutableAudienceForwarder.java +++ b/Patchwork/src/main/java/fns/patchwork/audience/MutableAudienceForwarder.java @@ -1,5 +1,9 @@ -package me.totalfreedom.audience; +package fns.patchwork.audience; +import java.util.HashSet; +import java.util.Set; +import java.util.function.Consumer; +import java.util.function.Predicate; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.bossbar.BossBar; import net.kyori.adventure.chat.ChatType; @@ -13,13 +17,8 @@ import net.kyori.adventure.title.Title; import net.kyori.adventure.title.TitlePart; import org.jetbrains.annotations.NotNull; -import java.util.HashSet; -import java.util.Set; -import java.util.function.Consumer; -import java.util.function.Predicate; - /** - * A replacement for {@link net.kyori.adventure.audience.ForwardingAudience} that allows for audiences to be removed & + * A replacement for {@link net.kyori.adventure.audience.ForwardingAudience} that allows for audiences to be removed and * added at will. Not thread safe. *

* This is intended for use in toggleable logging systems, for example, potion spy. diff --git a/Patchwork/src/main/java/me/totalfreedom/base/CommonsBase.java b/Patchwork/src/main/java/fns/patchwork/base/Patchwork.java similarity index 50% rename from Patchwork/src/main/java/me/totalfreedom/base/CommonsBase.java rename to Patchwork/src/main/java/fns/patchwork/base/Patchwork.java index 69bade0..64d4099 100644 --- a/Patchwork/src/main/java/me/totalfreedom/base/CommonsBase.java +++ b/Patchwork/src/main/java/fns/patchwork/base/Patchwork.java @@ -1,61 +1,59 @@ -package me.totalfreedom.base; +package fns.patchwork.base; -import me.totalfreedom.event.EventBus; -import me.totalfreedom.service.FreedomExecutor; -import me.totalfreedom.service.SubscriptionProvider; +import fns.patchwork.display.adminchat.AdminChatDisplay; +import fns.patchwork.event.EventBus; +import fns.patchwork.service.FreedomExecutor; +import fns.patchwork.service.SubscriptionProvider; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; /** * The base class for Patchwork. */ -public class CommonsBase extends JavaPlugin +public class Patchwork extends JavaPlugin { /** * The {@link EventBus} for this plugin. */ - private final EventBus eventBus = new EventBus(this); - /** - * The {@link Registration} object for this plugin. - */ - private final Registration registration = new Registration(); + private EventBus eventBus; /** * The {@link FreedomExecutor} for this plugin. */ - private final FreedomExecutor executor = new FreedomExecutor(); - + private FreedomExecutor executor; /** - * Provides this plugin instance through a safe static method. This is effectively the same thing as using - * {@link JavaPlugin#getPlugin(Class)} - * - * @return the plugin instance + * The {@link AdminChatDisplay} for this plugin. */ - public static CommonsBase getInstance() - { - return JavaPlugin.getPlugin(CommonsBase.class); - } + private AdminChatDisplay acdisplay; @Override public void onDisable() { Bukkit.getScheduler() - .runTaskLater(this, () -> getRegistrations() + .runTaskLater(this, () -> Registration .getServiceTaskRegistry() .stopAllServices(), 1L); - getRegistrations().getServiceTaskRegistry() + Registration.getServiceTaskRegistry() .unregisterService(EventBus.class); } @Override public void onEnable() { - getRegistrations().getServiceTaskRegistry() + eventBus = new EventBus(this); + executor = new FreedomExecutor(this); + acdisplay = new AdminChatDisplay(this); + + + Registration.getServiceTaskRegistry() .registerService(SubscriptionProvider.asyncService(this, eventBus)); + getExecutor().getSync() - .execute(() -> getRegistrations() + .execute(() -> Registration .getServiceTaskRegistry() .startAllServices()); + + Registration.getModuleRegistry().addModule(this); } /** @@ -68,17 +66,6 @@ public class CommonsBase extends JavaPlugin return executor; } - /** - * Get's the Registration object for this plugin. This object contains every registry class for the various features - * provided by this plugin. - * - * @return the Registration object - */ - public Registration getRegistrations() - { - return registration; - } - /** * Gets the {@link EventBus} for this plugin. The EventBus is used to register and listen to custom events provided * by Freedom Network Suite. @@ -89,4 +76,15 @@ public class CommonsBase extends JavaPlugin { return eventBus; } + + /** + * Gets the {@link AdminChatDisplay} for this plugin. The AdminChatDisplay is used to display messages sent in + * adminchat. + * + * @return the {@link AdminChatDisplay} + */ + public AdminChatDisplay getAdminChatDisplay() + { + return acdisplay; + } } diff --git a/Patchwork/src/main/java/fns/patchwork/base/Registration.java b/Patchwork/src/main/java/fns/patchwork/base/Registration.java new file mode 100644 index 0000000..bbe5048 --- /dev/null +++ b/Patchwork/src/main/java/fns/patchwork/base/Registration.java @@ -0,0 +1,95 @@ +package fns.patchwork.base; + +import fns.patchwork.data.ConfigRegistry; +import fns.patchwork.data.EventRegistry; +import fns.patchwork.data.GroupRegistry; +import fns.patchwork.data.ModuleRegistry; +import fns.patchwork.data.ServiceTaskRegistry; +import fns.patchwork.data.UserRegistry; + +/** + * This class is a holder for each registry in the data package. + *
+ * Registries such as {@link ModuleRegistry} and {@link ServiceTaskRegistry} can be found as final objects in this + * class. + */ +public class Registration +{ + /** + * The {@link EventRegistry} + */ + private static final EventRegistry eventRegistry = new EventRegistry(); + /** + * The {@link UserRegistry} + */ + private static final UserRegistry userRegistry = new UserRegistry(); + /** + * The {@link ServiceTaskRegistry} + */ + private static final ServiceTaskRegistry serviceTaskRegistry = new ServiceTaskRegistry(); + /** + * The {@link ModuleRegistry} + */ + private static final ModuleRegistry moduleRegistry = new ModuleRegistry(); + /** + * The {@link GroupRegistry} + */ + private static final GroupRegistry groupRegistry = new GroupRegistry(); + /** + * The {@link ConfigRegistry} + */ + private static final ConfigRegistry configRegistry = new ConfigRegistry(); + + private Registration() + { + throw new AssertionError(); + } + + /** + * @return The {@link ModuleRegistry} + */ + public static ModuleRegistry getModuleRegistry() + { + return moduleRegistry; + } + + /** + * @return The {@link EventRegistry} + */ + public static EventRegistry getEventRegistry() + { + return eventRegistry; + } + + /** + * @return The {@link UserRegistry} + */ + public static UserRegistry getUserRegistry() + { + return userRegistry; + } + + /** + * @return The {@link ServiceTaskRegistry} + */ + public static ServiceTaskRegistry getServiceTaskRegistry() + { + return serviceTaskRegistry; + } + + /** + * @return The {@link GroupRegistry} + */ + public static GroupRegistry getGroupRegistry() + { + return groupRegistry; + } + + /** + * @return The {@link ConfigRegistry} + */ + public static ConfigRegistry getConfigRegistry() + { + return configRegistry; + } +} \ No newline at end of file diff --git a/Patchwork/src/main/java/fns/patchwork/base/Shortcuts.java b/Patchwork/src/main/java/fns/patchwork/base/Shortcuts.java new file mode 100644 index 0000000..b591929 --- /dev/null +++ b/Patchwork/src/main/java/fns/patchwork/base/Shortcuts.java @@ -0,0 +1,26 @@ +package fns.patchwork.base; + +import fns.patchwork.user.User; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +public final class Shortcuts +{ + private Shortcuts() + { + throw new AssertionError(); + } + + public static T provideModule(final Class pluginClass) + { + return Registration.getModuleRegistry() + .getProvider(pluginClass) + .getModule(); + } + + public static User getUser(final Player player) + { + return Registration.getUserRegistry() + .getUser(player); + } +} diff --git a/Patchwork/src/main/java/me/totalfreedom/command/BukkitDelegate.java b/Patchwork/src/main/java/fns/patchwork/command/BukkitDelegate.java similarity index 68% rename from Patchwork/src/main/java/me/totalfreedom/command/BukkitDelegate.java rename to Patchwork/src/main/java/fns/patchwork/command/BukkitDelegate.java index 0a740d6..45b4965 100644 --- a/Patchwork/src/main/java/me/totalfreedom/command/BukkitDelegate.java +++ b/Patchwork/src/main/java/fns/patchwork/command/BukkitDelegate.java @@ -1,33 +1,31 @@ -package me.totalfreedom.command; +package fns.patchwork.command; -import me.totalfreedom.api.Context; -import me.totalfreedom.command.annotation.Completion; -import me.totalfreedom.command.annotation.Subcommand; -import me.totalfreedom.provider.ContextProvider; -import me.totalfreedom.utils.logging.FreedomLogger; +import fns.patchwork.command.annotation.Completion; +import fns.patchwork.command.annotation.Subcommand; +import fns.patchwork.provider.ContextProvider; +import fns.patchwork.utils.logging.FreedomLogger; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Set; import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.PluginIdentifiableCommand; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Set; - /** * This class is acts as a delegate between our custom command implementation and the Bukkit API. *
* This class is not meant to be used directly, and is only public to allow for the Bukkit API to access it. As a * result, this file will remain undocumented. - * + *
*
* This class is not thread-safe. *
@@ -36,7 +34,6 @@ import java.util.Set; * This class is not meant to be instantiated. *
* This class is not meant to be used outside Patchwork. - *
*/ public final class BukkitDelegate extends Command implements PluginIdentifiableCommand { @@ -69,7 +66,7 @@ public final class BukkitDelegate extends Command implements PluginIdentifiableC @NotNull final String commandLabel, @NotNull final String[] args) { - if (sender instanceof ConsoleCommandSender && noConsole) + if (!(sender instanceof Player) && noConsole) { sender.sendMessage(Component.text("This command can only be run by players.")); return true; @@ -101,9 +98,18 @@ public final class BukkitDelegate extends Command implements PluginIdentifiableC { try { - command.getBaseMethod() - .invoke(command, sender); - } catch (Exception ex) + if (noConsole) + { + command.getBaseMethod() + .invoke(command, (Player) sender); + } + else + { + command.getBaseMethod() + .invoke(command, sender); + } + } + catch (Exception ex) { FreedomLogger.getLogger("Patchwork") .error(ex); @@ -120,7 +126,7 @@ public final class BukkitDelegate extends Command implements PluginIdentifiableC final Subcommand node) { final Class[] argTypes = node.args(); - if (argTypes.length != args.length) + if (argTypes.length > args.length) return; final Object[] objects = new Object[argTypes.length + 1]; @@ -130,18 +136,52 @@ public final class BukkitDelegate extends Command implements PluginIdentifiableC final Class argType = argTypes[i]; final String arg = args[i]; - if (argType == String.class) - continue; + if (argType.equals(String.class)) + { + if (i == argTypes.length - 1) + { + final String[] reasonArgs = Arrays.copyOfRange(args, i, args.length - 1); + final String reason = String.join(" ", reasonArgs); + objects[i] = reason; + } + else + { + continue; + } + } - final Context context = () -> provider.fromString(arg, argType); - objects[i] = context.get(); + if (argType.equals(Location.class)) + { + final String[] locationArgs = Arrays.copyOfRange(args, i, i + 3); + final String location = String.join(" ", locationArgs); + objects[i] = location; + } + + final Object obj = provider.fromString(arg, argType); + if (obj == null) + { + FreedomLogger.getLogger("Datura") + .error("Failed to parse argument " + arg + " for type " + argType.getName()); + return; + } + objects[i] = obj; } try { - command.getSubcommands() - .get(node) - .invoke(command, sender, objects); - } catch (Exception ex) + if (noConsole) + { + command.getSubcommands() + .get(node) + .invoke(command, (Player) sender, objects); + } + else + { + command.getSubcommands() + .get(node) + .invoke(command, sender, objects); + } + } + catch (Exception ex) { FreedomLogger.getLogger("Patchwork") .error(ex); @@ -173,17 +213,17 @@ public final class BukkitDelegate extends Command implements PluginIdentifiableC .map(World::getName) .toList()); case "%number%" -> results.addAll(List.of( - "0", - "1", - "2", - "3", - "4", - "5", - "6", - "7", - "8", - "9")); - case "%location%" -> results.add("world,x,y,z"); + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9")); + case "%location%" -> results.add("world x y z"); default -> results.add(p); } } diff --git a/Patchwork/src/main/java/me/totalfreedom/command/CommandHandler.java b/Patchwork/src/main/java/fns/patchwork/command/CommandHandler.java similarity index 97% rename from Patchwork/src/main/java/me/totalfreedom/command/CommandHandler.java rename to Patchwork/src/main/java/fns/patchwork/command/CommandHandler.java index cfcdd90..0851811 100644 --- a/Patchwork/src/main/java/me/totalfreedom/command/CommandHandler.java +++ b/Patchwork/src/main/java/fns/patchwork/command/CommandHandler.java @@ -1,4 +1,4 @@ -package me.totalfreedom.command; +package fns.patchwork.command; import org.bukkit.Bukkit; import org.bukkit.command.CommandMap; diff --git a/Patchwork/src/main/java/me/totalfreedom/command/Commander.java b/Patchwork/src/main/java/fns/patchwork/command/Commander.java similarity index 91% rename from Patchwork/src/main/java/me/totalfreedom/command/Commander.java rename to Patchwork/src/main/java/fns/patchwork/command/Commander.java index 2830a84..920a853 100644 --- a/Patchwork/src/main/java/me/totalfreedom/command/Commander.java +++ b/Patchwork/src/main/java/fns/patchwork/command/Commander.java @@ -1,14 +1,10 @@ -package me.totalfreedom.command; - -import me.totalfreedom.command.annotation.Base; -import me.totalfreedom.command.annotation.Completion; -import me.totalfreedom.command.annotation.Info; -import me.totalfreedom.command.annotation.Permissive; -import me.totalfreedom.command.annotation.Subcommand; -import org.bukkit.plugin.java.JavaPlugin; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +package fns.patchwork.command; +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.lang.reflect.Method; import java.util.HashMap; import java.util.HashSet; @@ -16,6 +12,9 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Stream; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * This is the base command class which should be extended when creating a new command. Commands must be annotated with @@ -28,9 +27,7 @@ import java.util.stream.Stream; * You are allowed to have as many methods as you want which are annotated with the {@link Subcommand} annotation. These * methods will be called when the command is executed with the specified subcommand. *
- * You are also allowed to use multiple {@link Completion} annotations per method to define multiple tab completions for - * a single subcommand. This would be useful in the case where you would like to include specific completion cases, but - * also support basic String completion cases. + * You are also allowed to use multiple {@link Completion} annotations per class to define the tab completions for each method. *
* When creating {@link Completion} annotations, you only need to register arguments a single time per class. For more * information, see {@link Subcommand}. diff --git a/Patchwork/src/main/java/me/totalfreedom/command/annotation/Base.java b/Patchwork/src/main/java/fns/patchwork/command/annotation/Base.java similarity index 88% rename from Patchwork/src/main/java/me/totalfreedom/command/annotation/Base.java rename to Patchwork/src/main/java/fns/patchwork/command/annotation/Base.java index c230186..765a04a 100644 --- a/Patchwork/src/main/java/me/totalfreedom/command/annotation/Base.java +++ b/Patchwork/src/main/java/fns/patchwork/command/annotation/Base.java @@ -1,4 +1,4 @@ -package me.totalfreedom.command.annotation; +package fns.patchwork.command.annotation; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/Patchwork/src/main/java/me/totalfreedom/command/annotation/Completion.java b/Patchwork/src/main/java/fns/patchwork/command/annotation/Completion.java similarity index 92% rename from Patchwork/src/main/java/me/totalfreedom/command/annotation/Completion.java rename to Patchwork/src/main/java/fns/patchwork/command/annotation/Completion.java index d32efa4..b52a08a 100644 --- a/Patchwork/src/main/java/me/totalfreedom/command/annotation/Completion.java +++ b/Patchwork/src/main/java/fns/patchwork/command/annotation/Completion.java @@ -1,4 +1,4 @@ -package me.totalfreedom.command.annotation; +package fns.patchwork.command.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Repeatable; @@ -12,7 +12,7 @@ import java.lang.annotation.Target; * This will register at class level, and does not retain method information. As a result, you only need to register the * arguments a single time, and it will always be used in tab completions. */ -@Target(ElementType.METHOD) +@Target(ElementType.TYPE) @Repeatable(Completions.class) @Retention(RetentionPolicy.RUNTIME) public @interface Completion diff --git a/Patchwork/src/main/java/me/totalfreedom/command/annotation/Completions.java b/Patchwork/src/main/java/fns/patchwork/command/annotation/Completions.java similarity index 65% rename from Patchwork/src/main/java/me/totalfreedom/command/annotation/Completions.java rename to Patchwork/src/main/java/fns/patchwork/command/annotation/Completions.java index 694804e..aa06d6f 100644 --- a/Patchwork/src/main/java/me/totalfreedom/command/annotation/Completions.java +++ b/Patchwork/src/main/java/fns/patchwork/command/annotation/Completions.java @@ -1,4 +1,4 @@ -package me.totalfreedom.command.annotation; +package fns.patchwork.command.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -8,10 +8,10 @@ import java.lang.annotation.Target; /** * A marker interface which represents a holder for multiple {@link Completion} annotations. *
- * This interface is NOT intended for implementation and should - * NOT be used. + * This interface is NOT intended for implementation and should + * NOT be used. */ -@Target(ElementType.METHOD) +@Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface Completions { diff --git a/Patchwork/src/main/java/me/totalfreedom/command/annotation/Info.java b/Patchwork/src/main/java/fns/patchwork/command/annotation/Info.java similarity index 96% rename from Patchwork/src/main/java/me/totalfreedom/command/annotation/Info.java rename to Patchwork/src/main/java/fns/patchwork/command/annotation/Info.java index 5ab0bbc..a6ba2a9 100644 --- a/Patchwork/src/main/java/me/totalfreedom/command/annotation/Info.java +++ b/Patchwork/src/main/java/fns/patchwork/command/annotation/Info.java @@ -1,4 +1,4 @@ -package me.totalfreedom.command.annotation; +package fns.patchwork.command.annotation; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/Patchwork/src/main/java/me/totalfreedom/command/annotation/Permissive.java b/Patchwork/src/main/java/fns/patchwork/command/annotation/Permissive.java similarity index 95% rename from Patchwork/src/main/java/me/totalfreedom/command/annotation/Permissive.java rename to Patchwork/src/main/java/fns/patchwork/command/annotation/Permissive.java index 90c5739..60f1218 100644 --- a/Patchwork/src/main/java/me/totalfreedom/command/annotation/Permissive.java +++ b/Patchwork/src/main/java/fns/patchwork/command/annotation/Permissive.java @@ -1,4 +1,4 @@ -package me.totalfreedom.command.annotation; +package fns.patchwork.command.annotation; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/Patchwork/src/main/java/me/totalfreedom/command/annotation/Subcommand.java b/Patchwork/src/main/java/fns/patchwork/command/annotation/Subcommand.java similarity index 57% rename from Patchwork/src/main/java/me/totalfreedom/command/annotation/Subcommand.java rename to Patchwork/src/main/java/fns/patchwork/command/annotation/Subcommand.java index b203761..9315599 100644 --- a/Patchwork/src/main/java/me/totalfreedom/command/annotation/Subcommand.java +++ b/Patchwork/src/main/java/fns/patchwork/command/annotation/Subcommand.java @@ -1,8 +1,7 @@ -package me.totalfreedom.command.annotation; - -import me.totalfreedom.command.CommandHandler; -import me.totalfreedom.provider.ContextProvider; +package fns.patchwork.command.annotation; +import fns.patchwork.command.CommandHandler; +import fns.patchwork.provider.ContextProvider; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -10,19 +9,26 @@ import java.lang.annotation.Target; /** * This annotation should be used to mark methods as subcommand methods. Subcommand methods can have custom arguments - * (current supported arguments can be found in the {@link ContextProvider}), and can also have a custom permission. - * These subcommands can also be annotated with {@link Completions} to provide tab completions for the subcommand. The - * subcommand method must be public, and must be in a class that is registered with the {@link CommandHandler}. - *
+ * (current supported arguments can be found in the {@link ContextProvider}), and can also have a custom + * permission. These subcommands can also be annotated with {@link Completions} to provide tab completions for the + * subcommand. The subcommand method must be public, and must be in a class that is registered with the + * {@link CommandHandler}. + *

* Tab completions with the {@link Completions} annotation are only supported for subcommands. When registering * completions, you only need to define the completion arguments a single time. If there are other methods which * function as optional additional arguments for the subcommand, the previously registered arguments will still be * present when the user does their tab completion. - *
+ *

* For example, if you have a subcommand method with the arguments {@code (Player, String)}, and another method which * has the arguments {@code (Player, String, String)}, the tab completions for the second method will still have the * {@code Player} and {@code String} arguments registered from the first method. You will only need to provide a * {@link Completion} for the additional 3rd argument. + *

+ * Additionally, if the final argument is a String object, the BukkitDelegate will automatically append any additional + * arguments to the end of the String. For example, if you have a subcommand method with the arguments + * {@code (Player, String)}, and the user executes the command with the arguments {@code /command playerName arg2 arg3}, + * the {@code String} argument will be {@code "arg2 arg3"}. This allows for us to use a String at the end of our + * subcommand arguments to allow for the user to input a reason. */ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) diff --git a/Patchwork/src/main/java/me/totalfreedom/config/Configuration.java b/Patchwork/src/main/java/fns/patchwork/config/Configuration.java similarity index 96% rename from Patchwork/src/main/java/me/totalfreedom/config/Configuration.java rename to Patchwork/src/main/java/fns/patchwork/config/Configuration.java index 728ead2..10a630a 100644 --- a/Patchwork/src/main/java/me/totalfreedom/config/Configuration.java +++ b/Patchwork/src/main/java/fns/patchwork/config/Configuration.java @@ -1,8 +1,7 @@ -package me.totalfreedom.config; - -import me.totalfreedom.api.Context; -import me.totalfreedom.provider.ContextProvider; +package fns.patchwork.config; +import fns.patchwork.api.Context; +import fns.patchwork.provider.ContextProvider; import java.io.File; import java.io.IOException; import java.util.List; diff --git a/Patchwork/src/main/java/me/totalfreedom/config/YamlWrapper.java b/Patchwork/src/main/java/fns/patchwork/config/YamlWrapper.java similarity index 53% rename from Patchwork/src/main/java/me/totalfreedom/config/YamlWrapper.java rename to Patchwork/src/main/java/fns/patchwork/config/YamlWrapper.java index eefd27c..d38933a 100644 --- a/Patchwork/src/main/java/me/totalfreedom/config/YamlWrapper.java +++ b/Patchwork/src/main/java/fns/patchwork/config/YamlWrapper.java @@ -1,4 +1,4 @@ -package me.totalfreedom.config; +package fns.patchwork.config; public final class YamlWrapper { diff --git a/Patchwork/src/main/java/me/totalfreedom/data/ConfigRegistry.java b/Patchwork/src/main/java/fns/patchwork/data/ConfigRegistry.java similarity index 93% rename from Patchwork/src/main/java/me/totalfreedom/data/ConfigRegistry.java rename to Patchwork/src/main/java/fns/patchwork/data/ConfigRegistry.java index 7db90f2..f45e4f0 100644 --- a/Patchwork/src/main/java/me/totalfreedom/data/ConfigRegistry.java +++ b/Patchwork/src/main/java/fns/patchwork/data/ConfigRegistry.java @@ -1,7 +1,6 @@ -package me.totalfreedom.data; - -import me.totalfreedom.config.Configuration; +package fns.patchwork.data; +import fns.patchwork.config.Configuration; import java.util.HashMap; import java.util.Map; diff --git a/Patchwork/src/main/java/me/totalfreedom/data/EventRegistry.java b/Patchwork/src/main/java/fns/patchwork/data/EventRegistry.java similarity index 91% rename from Patchwork/src/main/java/me/totalfreedom/data/EventRegistry.java rename to Patchwork/src/main/java/fns/patchwork/data/EventRegistry.java index c5fb292..2130b46 100644 --- a/Patchwork/src/main/java/me/totalfreedom/data/EventRegistry.java +++ b/Patchwork/src/main/java/fns/patchwork/data/EventRegistry.java @@ -1,8 +1,7 @@ -package me.totalfreedom.data; - -import me.totalfreedom.event.FEvent; -import me.totalfreedom.provider.EventProvider; +package fns.patchwork.data; +import fns.patchwork.event.FEvent; +import fns.patchwork.provider.EventProvider; import java.util.ArrayList; import java.util.List; diff --git a/Patchwork/src/main/java/me/totalfreedom/data/GroupRegistry.java b/Patchwork/src/main/java/fns/patchwork/data/GroupRegistry.java similarity index 95% rename from Patchwork/src/main/java/me/totalfreedom/data/GroupRegistry.java rename to Patchwork/src/main/java/fns/patchwork/data/GroupRegistry.java index aec9b76..66c6456 100644 --- a/Patchwork/src/main/java/me/totalfreedom/data/GroupRegistry.java +++ b/Patchwork/src/main/java/fns/patchwork/data/GroupRegistry.java @@ -1,10 +1,9 @@ -package me.totalfreedom.data; - -import me.totalfreedom.security.Group; -import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; +package fns.patchwork.data; +import fns.patchwork.security.Group; import java.util.ArrayList; import java.util.List; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; /** * A registry for {@link Group}s. diff --git a/Patchwork/src/main/java/me/totalfreedom/data/ModuleRegistry.java b/Patchwork/src/main/java/fns/patchwork/data/ModuleRegistry.java similarity index 94% rename from Patchwork/src/main/java/me/totalfreedom/data/ModuleRegistry.java rename to Patchwork/src/main/java/fns/patchwork/data/ModuleRegistry.java index cdc26c0..ecd4c43 100644 --- a/Patchwork/src/main/java/me/totalfreedom/data/ModuleRegistry.java +++ b/Patchwork/src/main/java/fns/patchwork/data/ModuleRegistry.java @@ -1,10 +1,9 @@ -package me.totalfreedom.data; - -import me.totalfreedom.provider.ModuleProvider; -import org.bukkit.plugin.java.JavaPlugin; +package fns.patchwork.data; +import fns.patchwork.provider.ModuleProvider; import java.util.ArrayList; import java.util.List; +import org.bukkit.plugin.java.JavaPlugin; /** * A registry for modules. diff --git a/Patchwork/src/main/java/me/totalfreedom/data/ServiceTaskRegistry.java b/Patchwork/src/main/java/fns/patchwork/data/ServiceTaskRegistry.java similarity index 97% rename from Patchwork/src/main/java/me/totalfreedom/data/ServiceTaskRegistry.java rename to Patchwork/src/main/java/fns/patchwork/data/ServiceTaskRegistry.java index 2cf3e8d..fa7eaaf 100644 --- a/Patchwork/src/main/java/me/totalfreedom/data/ServiceTaskRegistry.java +++ b/Patchwork/src/main/java/fns/patchwork/data/ServiceTaskRegistry.java @@ -1,14 +1,13 @@ -package me.totalfreedom.data; - -import me.totalfreedom.service.Service; -import me.totalfreedom.service.ServiceSubscription; -import me.totalfreedom.service.SubscriptionProvider; -import me.totalfreedom.service.Task; -import me.totalfreedom.service.TaskSubscription; -import org.jetbrains.annotations.Nullable; +package fns.patchwork.data; +import fns.patchwork.service.Service; +import fns.patchwork.service.ServiceSubscription; +import fns.patchwork.service.SubscriptionProvider; +import fns.patchwork.service.Task; +import fns.patchwork.service.TaskSubscription; import java.util.ArrayList; import java.util.List; +import org.jetbrains.annotations.Nullable; /** * A registry for all services and tasks registered with Patchwork. @@ -284,7 +283,7 @@ public class ServiceTaskRegistry *
* The service should have been registered previously as a ServiceSubscription. * - * @param service The service you are trying to unregister. + * @param clazz The service you are trying to unregister. * @see #registerService(ServiceSubscription) * @see ServiceSubscription */ diff --git a/Patchwork/src/main/java/me/totalfreedom/data/UserRegistry.java b/Patchwork/src/main/java/fns/patchwork/data/UserRegistry.java similarity index 96% rename from Patchwork/src/main/java/me/totalfreedom/data/UserRegistry.java rename to Patchwork/src/main/java/fns/patchwork/data/UserRegistry.java index 64bf824..19b5ec3 100644 --- a/Patchwork/src/main/java/me/totalfreedom/data/UserRegistry.java +++ b/Patchwork/src/main/java/fns/patchwork/data/UserRegistry.java @@ -1,11 +1,10 @@ -package me.totalfreedom.data; - -import me.totalfreedom.user.User; -import me.totalfreedom.user.UserData; -import org.bukkit.entity.Player; +package fns.patchwork.data; +import fns.patchwork.user.User; +import fns.patchwork.user.UserData; import java.util.HashMap; import java.util.Map; +import org.bukkit.entity.Player; /** * A registry for {@link UserData} objects. diff --git a/Patchwork/src/main/java/me/totalfreedom/display/AbstractMenu.java b/Patchwork/src/main/java/fns/patchwork/display/AbstractMenu.java similarity index 99% rename from Patchwork/src/main/java/me/totalfreedom/display/AbstractMenu.java rename to Patchwork/src/main/java/fns/patchwork/display/AbstractMenu.java index 9baa4df..7377e38 100644 --- a/Patchwork/src/main/java/me/totalfreedom/display/AbstractMenu.java +++ b/Patchwork/src/main/java/fns/patchwork/display/AbstractMenu.java @@ -1,5 +1,10 @@ -package me.totalfreedom.display; +package fns.patchwork.display; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -9,12 +14,6 @@ import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - /** * Represents a menu that can be opened by a player. */ diff --git a/Patchwork/src/main/java/me/totalfreedom/display/BossBarDisplay.java b/Patchwork/src/main/java/fns/patchwork/display/BossBarDisplay.java similarity index 99% rename from Patchwork/src/main/java/me/totalfreedom/display/BossBarDisplay.java rename to Patchwork/src/main/java/fns/patchwork/display/BossBarDisplay.java index 2239b4b..2720f12 100644 --- a/Patchwork/src/main/java/me/totalfreedom/display/BossBarDisplay.java +++ b/Patchwork/src/main/java/fns/patchwork/display/BossBarDisplay.java @@ -1,5 +1,8 @@ -package me.totalfreedom.display; +package fns.patchwork.display; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.ForwardingAudience; import net.kyori.adventure.bossbar.BossBar; @@ -7,10 +10,6 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.TextColor; import org.jetbrains.annotations.Range; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - /** * This class is a wrapper for {@link BossBar} objects. It provides some handy methods for changing the boss bar's * properties, displaying the bar to {@link Audience}s, and a {@link BossBarBuilder} to easily create new boss bars. diff --git a/Patchwork/src/main/java/me/totalfreedom/display/BossBarTimer.java b/Patchwork/src/main/java/fns/patchwork/display/BossBarTimer.java similarity index 93% rename from Patchwork/src/main/java/me/totalfreedom/display/BossBarTimer.java rename to Patchwork/src/main/java/fns/patchwork/display/BossBarTimer.java index dfa3eb1..dd66c5d 100644 --- a/Patchwork/src/main/java/me/totalfreedom/display/BossBarTimer.java +++ b/Patchwork/src/main/java/fns/patchwork/display/BossBarTimer.java @@ -1,9 +1,8 @@ -package me.totalfreedom.display; - -import me.totalfreedom.service.Task; -import org.bukkit.Bukkit; +package fns.patchwork.display; +import fns.patchwork.service.Task; import java.time.Duration; +import org.bukkit.Bukkit; public class BossBarTimer extends Task { diff --git a/Patchwork/src/main/java/me/totalfreedom/display/ClickAction.java b/Patchwork/src/main/java/fns/patchwork/display/ClickAction.java similarity index 92% rename from Patchwork/src/main/java/me/totalfreedom/display/ClickAction.java rename to Patchwork/src/main/java/fns/patchwork/display/ClickAction.java index 70aa1ad..afdd8a7 100644 --- a/Patchwork/src/main/java/me/totalfreedom/display/ClickAction.java +++ b/Patchwork/src/main/java/fns/patchwork/display/ClickAction.java @@ -1,4 +1,4 @@ -package me.totalfreedom.display; +package fns.patchwork.display; import org.bukkit.entity.Player; diff --git a/Patchwork/src/main/java/me/totalfreedom/display/Displayable.java b/Patchwork/src/main/java/fns/patchwork/display/Displayable.java similarity index 99% rename from Patchwork/src/main/java/me/totalfreedom/display/Displayable.java rename to Patchwork/src/main/java/fns/patchwork/display/Displayable.java index 56a5fff..f790422 100644 --- a/Patchwork/src/main/java/me/totalfreedom/display/Displayable.java +++ b/Patchwork/src/main/java/fns/patchwork/display/Displayable.java @@ -1,5 +1,9 @@ -package me.totalfreedom.display; +package fns.patchwork.display; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.ListIterator; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.HumanEntity; @@ -10,11 +14,6 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.ListIterator; - /** * A class that represents an inventory that can be displayed to players. This class also represents the inventory * holder which contains the inventory. diff --git a/Patchwork/src/main/java/me/totalfreedom/display/DisplayableView.java b/Patchwork/src/main/java/fns/patchwork/display/DisplayableView.java similarity index 94% rename from Patchwork/src/main/java/me/totalfreedom/display/DisplayableView.java rename to Patchwork/src/main/java/fns/patchwork/display/DisplayableView.java index 26c5138..7f27bd4 100644 --- a/Patchwork/src/main/java/me/totalfreedom/display/DisplayableView.java +++ b/Patchwork/src/main/java/fns/patchwork/display/DisplayableView.java @@ -1,6 +1,6 @@ -package me.totalfreedom.display; +package fns.patchwork.display; -import me.totalfreedom.utils.kyori.FreedomAdventure; +import fns.patchwork.utils.kyori.FreedomAdventure; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryType; @@ -78,6 +78,7 @@ public class DisplayableView extends InventoryView } @Override + @Deprecated(forRemoval = true, since = "1.16") public @NotNull String getTitle() { return title; diff --git a/Patchwork/src/main/java/me/totalfreedom/display/TitleDisplay.java b/Patchwork/src/main/java/fns/patchwork/display/TitleDisplay.java similarity index 99% rename from Patchwork/src/main/java/me/totalfreedom/display/TitleDisplay.java rename to Patchwork/src/main/java/fns/patchwork/display/TitleDisplay.java index b6bf7cc..a225c66 100644 --- a/Patchwork/src/main/java/me/totalfreedom/display/TitleDisplay.java +++ b/Patchwork/src/main/java/fns/patchwork/display/TitleDisplay.java @@ -1,13 +1,12 @@ -package me.totalfreedom.display; +package fns.patchwork.display; +import java.time.Duration; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.ForwardingAudience; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.title.Title; -import java.time.Duration; - /** * A wrapper class for {@link Title}s that allows for easy display to an {@link Audience}. */ diff --git a/Patchwork/src/main/java/fns/patchwork/display/adminchat/ACFormatBuilder.java b/Patchwork/src/main/java/fns/patchwork/display/adminchat/ACFormatBuilder.java new file mode 100644 index 0000000..44730ad --- /dev/null +++ b/Patchwork/src/main/java/fns/patchwork/display/adminchat/ACFormatBuilder.java @@ -0,0 +1,119 @@ +package fns.patchwork.display.adminchat; + +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextColor; + +public class ACFormatBuilder +{ + private char openTag = '['; + private char closeTag = ']'; + private TextColor prefixColor = NamedTextColor.DARK_RED; + private TextColor bracketColor = NamedTextColor.WHITE; + private TextColor nameColor = NamedTextColor.AQUA; + private TextColor rankColor = NamedTextColor.GOLD; + private String prefix = "Admin"; + private String chatSplitter = ">>"; + + private ACFormatBuilder() + { + + } + + public static ACFormatBuilder format() + { + return new ACFormatBuilder(); + } + + public ACFormatBuilder openBracket(final char openTag) + { + this.openTag = openTag; + return this; + } + + public ACFormatBuilder closeBracket(final char closeTag) + { + this.closeTag = closeTag; + return this; + } + + public ACFormatBuilder prefixColor(final TextColor prefixColor) + { + this.prefixColor = prefixColor; + return this; + } + + public ACFormatBuilder bracketColor(final TextColor bracketColor) + { + this.bracketColor = bracketColor; + return this; + } + + public ACFormatBuilder prefix(final String prefix) + { + this.prefix = prefix; + return this; + } + + public ACFormatBuilder chatSplitter(final String chatSplitter) + { + this.chatSplitter = chatSplitter; + return this; + } + + public ACFormatBuilder nameColor(final TextColor nameColor) + { + this.nameColor = nameColor; + return this; + } + + public ACFormatBuilder rankColor(final TextColor rankColor) + { + this.rankColor = rankColor; + return this; + } + + String openBracket() + { + return String.valueOf(openTag); + } + + String closeBracket() + { + return String.valueOf(closeTag); + } + + TextColor prefixColor() + { + return prefixColor; + } + + TextColor bracketColor() + { + return bracketColor; + } + + TextColor nameColor() + { + return nameColor; + } + + TextColor rankColor() + { + return rankColor; + } + + String prefix() + { + return prefix; + } + + String chatSplitter() + { + return chatSplitter; + } + + public AdminChatFormat build() + { + return new AdminChatFormat(this); + } +} diff --git a/Patchwork/src/main/java/fns/patchwork/display/adminchat/AdminChatDisplay.java b/Patchwork/src/main/java/fns/patchwork/display/adminchat/AdminChatDisplay.java new file mode 100644 index 0000000..3f6f250 --- /dev/null +++ b/Patchwork/src/main/java/fns/patchwork/display/adminchat/AdminChatDisplay.java @@ -0,0 +1,140 @@ +package fns.patchwork.display.adminchat; + +import fns.patchwork.base.Patchwork; +import fns.patchwork.base.Registration; +import fns.patchwork.base.Shortcuts; +import fns.patchwork.security.Groups; +import fns.patchwork.user.UserData; +import io.papermc.paper.event.player.AsyncChatEvent; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import net.kyori.adventure.text.Component; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +public class AdminChatDisplay +{ + protected static final String ACPERM = "patchwork.adminchat"; + private final Map adminChatFormat = new HashMap<>(); + private final Set toggledChat = new HashSet<>(); + + public AdminChatDisplay(final Patchwork patchwork) + { + new ACListener(this, patchwork); + } + + public void addPlayer(final Player player, final AdminChatFormat format) + { + adminChatFormat.put(player.getUniqueId(), format); + } + + public void removePlayer(final Player player) + { + adminChatFormat.remove(player.getUniqueId()); + } + + public boolean hasPlayer(final Player player) + { + return adminChatFormat.containsKey(player.getUniqueId()); + } + + public void updateFormat(final Player player, final AdminChatFormat newFormat) + { + adminChatFormat.put(player.getUniqueId(), newFormat); + } + + public AdminChatFormat getFormat(final Player player) + { + return adminChatFormat.get(player.getUniqueId()); + } + + public Set getPlayers() + { + return adminChatFormat.keySet(); + } + + public Map getAdminChatFormat() + { + return adminChatFormat; + } + + public boolean isToggled(final Player player) + { + return toggledChat.contains(player.getUniqueId()); + } + + public void toggleChat(final Player player) + { + if (toggledChat.contains(player.getUniqueId())) + { + toggledChat.remove(player.getUniqueId()); + } else + { + toggledChat.add(player.getUniqueId()); + } + } + + public void adminChatMessage(final CommandSender sender, final Component message) + { + Bukkit.getOnlinePlayers() + .forEach(player -> + { + if (player.hasPermission(ACPERM)) + { + final Component formatted = Component.empty(); + formatted.append(getFormat(player).format(sender.getName(), Groups.fromSender(sender))) + .append(Component.space()) + .append(message); + + player.sendMessage(formatted); + } + }); + } + + public static final class ACListener implements Listener + { + private final AdminChatDisplay display; + + public ACListener(final AdminChatDisplay display, final Patchwork patchwork) + { + this.display = display; + Bukkit.getPluginManager() + .registerEvents(this, patchwork); + } + + @EventHandler + public void playerChat(final AsyncChatEvent event) + { + if (display.isToggled(event.getPlayer())) + { + event.setCancelled(true); + display.adminChatMessage(event.getPlayer(), event.message()); + } + } + + @EventHandler + public void playerJoin(final PlayerJoinEvent event) + { + final Player player = event.getPlayer(); + if (player.hasPermission(ACPERM)) + { + final UserData data = Registration.getUserRegistry() + .fromPlayer(player); + if (data.hasCustomACFormat()) + { + display.addPlayer(player, data.getCustomACFormat()); + } else + { + display.addPlayer(player, AdminChatFormat.DEFAULT); + } + } + } + } +} diff --git a/Patchwork/src/main/java/fns/patchwork/display/adminchat/AdminChatFormat.java b/Patchwork/src/main/java/fns/patchwork/display/adminchat/AdminChatFormat.java new file mode 100644 index 0000000..03cf434 --- /dev/null +++ b/Patchwork/src/main/java/fns/patchwork/display/adminchat/AdminChatFormat.java @@ -0,0 +1,107 @@ +package fns.patchwork.display.adminchat; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; + +public final class AdminChatFormat +{ + public static final AdminChatFormat DEFAULT = ACFormatBuilder.format() + .build(); + private final Component prefix; + private final Component userName; + private final Component rank; + private final Component chatSplitter; + private final Component fullFormat; + + + AdminChatFormat(final ACFormatBuilder builder) + { + this.prefix = Component.text(builder.openBracket(), builder.bracketColor()) + .append(Component.text(builder.prefix(), builder.prefixColor())) + .append(Component.text(builder.closeBracket(), builder.bracketColor())); + this.userName = Component.text("%name%", builder.nameColor()); + this.rank = Component.text(builder.openBracket(), builder.bracketColor()) + .append(Component.text("%rank%", builder.rankColor())) + .append(Component.text(builder.closeBracket(), builder.bracketColor())); + + // Nice formatting :( + if (builder.chatSplitter() + .equals(":")) + { + this.chatSplitter = Component.text(":", NamedTextColor.WHITE); + } else + { + this.chatSplitter = Component.space() + .append(Component.text(builder.chatSplitter(), NamedTextColor.WHITE)); + } + + // Formatting because []: is cleaner than [] :, but anything else such as [] >> or [] -> looks better with the space between. + this.fullFormat = prefix.appendSpace() + .append(userName) + .appendSpace() + .append(rank) + .append(chatSplitter) + .appendSpace(); + } + + public static AdminChatFormat deserialize(final String serialized) + { + final Component dez = LegacyComponentSerializer.legacyAmpersand() + .deserialize(serialized); + final Component prefix = dez.children() + .get(0); + final Component userName = dez.children() + .get(1); + final Component rank = dez.children() + .get(2); + final Component chatSplitter = dez.children() + .get(3); + + return ACFormatBuilder.format() + .prefix(((TextComponent) prefix).content()) + .prefixColor(prefix.color()) + .nameColor(userName.color()) + .rankColor(rank.color()) + .chatSplitter(((TextComponent) chatSplitter).content()) + .build(); + } + + public Component getPrefix() + { + return prefix; + } + + public Component getUserName() + { + return userName; + } + + public Component getRank() + { + return rank; + } + + public Component getFullFormat() + { + return fullFormat; + } + + public Component format(final String name, final String rank) + { + return fullFormat.replaceText(b -> + { + b.matchLiteral("%name%") + .replacement(name); + b.matchLiteral("%rank%") + .replacement(rank); + }); + } + + public String serialize() + { + return LegacyComponentSerializer.legacyAmpersand() + .serialize(fullFormat); + } +} diff --git a/Patchwork/src/main/java/me/totalfreedom/economy/CompletedTransaction.java b/Patchwork/src/main/java/fns/patchwork/economy/CompletedTransaction.java similarity index 90% rename from Patchwork/src/main/java/me/totalfreedom/economy/CompletedTransaction.java rename to Patchwork/src/main/java/fns/patchwork/economy/CompletedTransaction.java index 50af8c9..63d72b2 100644 --- a/Patchwork/src/main/java/me/totalfreedom/economy/CompletedTransaction.java +++ b/Patchwork/src/main/java/fns/patchwork/economy/CompletedTransaction.java @@ -1,4 +1,4 @@ -package me.totalfreedom.economy; +package fns.patchwork.economy; /** * Represents an immutable transaction that has been fully handled by a {@link Transactor} instance diff --git a/Patchwork/src/main/java/me/totalfreedom/economy/EconomicEntity.java b/Patchwork/src/main/java/fns/patchwork/economy/EconomicEntity.java similarity index 94% rename from Patchwork/src/main/java/me/totalfreedom/economy/EconomicEntity.java rename to Patchwork/src/main/java/fns/patchwork/economy/EconomicEntity.java index f2b2c69..887e5a3 100644 --- a/Patchwork/src/main/java/me/totalfreedom/economy/EconomicEntity.java +++ b/Patchwork/src/main/java/fns/patchwork/economy/EconomicEntity.java @@ -1,4 +1,4 @@ -package me.totalfreedom.economy; +package fns.patchwork.economy; /** * An entity that is able to transfer sums of currency between other {@link EconomicEntity} diff --git a/Patchwork/src/main/java/me/totalfreedom/economy/EconomicEntityData.java b/Patchwork/src/main/java/fns/patchwork/economy/EconomicEntityData.java similarity index 96% rename from Patchwork/src/main/java/me/totalfreedom/economy/EconomicEntityData.java rename to Patchwork/src/main/java/fns/patchwork/economy/EconomicEntityData.java index ac3d372..80065f0 100644 --- a/Patchwork/src/main/java/me/totalfreedom/economy/EconomicEntityData.java +++ b/Patchwork/src/main/java/fns/patchwork/economy/EconomicEntityData.java @@ -1,4 +1,4 @@ -package me.totalfreedom.economy; +package fns.patchwork.economy; /** * Metadata associated with a {@link EconomicEntity} diff --git a/Patchwork/src/main/java/me/totalfreedom/economy/MutableTransaction.java b/Patchwork/src/main/java/fns/patchwork/economy/MutableTransaction.java similarity index 96% rename from Patchwork/src/main/java/me/totalfreedom/economy/MutableTransaction.java rename to Patchwork/src/main/java/fns/patchwork/economy/MutableTransaction.java index 89a14a4..8ea0540 100644 --- a/Patchwork/src/main/java/me/totalfreedom/economy/MutableTransaction.java +++ b/Patchwork/src/main/java/fns/patchwork/economy/MutableTransaction.java @@ -1,4 +1,4 @@ -package me.totalfreedom.economy; +package fns.patchwork.economy; /** * A transaction that can be changed. diff --git a/Patchwork/src/main/java/me/totalfreedom/economy/Transaction.java b/Patchwork/src/main/java/fns/patchwork/economy/Transaction.java similarity index 92% rename from Patchwork/src/main/java/me/totalfreedom/economy/Transaction.java rename to Patchwork/src/main/java/fns/patchwork/economy/Transaction.java index 5968265..7780f07 100644 --- a/Patchwork/src/main/java/me/totalfreedom/economy/Transaction.java +++ b/Patchwork/src/main/java/fns/patchwork/economy/Transaction.java @@ -1,4 +1,4 @@ -package me.totalfreedom.economy; +package fns.patchwork.economy; /** * A class that denotes the transfer of currency between two EconomicEntity instances. diff --git a/Patchwork/src/main/java/me/totalfreedom/economy/TransactionLogger.java b/Patchwork/src/main/java/fns/patchwork/economy/TransactionLogger.java similarity index 91% rename from Patchwork/src/main/java/me/totalfreedom/economy/TransactionLogger.java rename to Patchwork/src/main/java/fns/patchwork/economy/TransactionLogger.java index 1d57fdd..000ca77 100644 --- a/Patchwork/src/main/java/me/totalfreedom/economy/TransactionLogger.java +++ b/Patchwork/src/main/java/fns/patchwork/economy/TransactionLogger.java @@ -1,4 +1,4 @@ -package me.totalfreedom.economy; +package fns.patchwork.economy; /** * A class that intercepts transactions after they are completed and logs them to a data point diff --git a/Patchwork/src/main/java/me/totalfreedom/economy/TransactionResult.java b/Patchwork/src/main/java/fns/patchwork/economy/TransactionResult.java similarity index 87% rename from Patchwork/src/main/java/me/totalfreedom/economy/TransactionResult.java rename to Patchwork/src/main/java/fns/patchwork/economy/TransactionResult.java index 9859a99..74cb16b 100644 --- a/Patchwork/src/main/java/me/totalfreedom/economy/TransactionResult.java +++ b/Patchwork/src/main/java/fns/patchwork/economy/TransactionResult.java @@ -1,4 +1,4 @@ -package me.totalfreedom.economy; +package fns.patchwork.economy; import net.kyori.adventure.text.Component; diff --git a/Patchwork/src/main/java/me/totalfreedom/economy/Transactor.java b/Patchwork/src/main/java/fns/patchwork/economy/Transactor.java similarity index 90% rename from Patchwork/src/main/java/me/totalfreedom/economy/Transactor.java rename to Patchwork/src/main/java/fns/patchwork/economy/Transactor.java index 60e1b3c..5bbf78a 100644 --- a/Patchwork/src/main/java/me/totalfreedom/economy/Transactor.java +++ b/Patchwork/src/main/java/fns/patchwork/economy/Transactor.java @@ -1,4 +1,4 @@ -package me.totalfreedom.economy; +package fns.patchwork.economy; /** * A class that implements the completion of transactions. diff --git a/Patchwork/src/main/java/me/totalfreedom/event/Callback.java b/Patchwork/src/main/java/fns/patchwork/event/Callback.java similarity index 75% rename from Patchwork/src/main/java/me/totalfreedom/event/Callback.java rename to Patchwork/src/main/java/fns/patchwork/event/Callback.java index 585d144..bc8b280 100644 --- a/Patchwork/src/main/java/me/totalfreedom/event/Callback.java +++ b/Patchwork/src/main/java/fns/patchwork/event/Callback.java @@ -1,4 +1,4 @@ -package me.totalfreedom.event; +package fns.patchwork.event; @FunctionalInterface public interface Callback diff --git a/Patchwork/src/main/java/me/totalfreedom/event/EventBus.java b/Patchwork/src/main/java/fns/patchwork/event/EventBus.java similarity index 87% rename from Patchwork/src/main/java/me/totalfreedom/event/EventBus.java rename to Patchwork/src/main/java/fns/patchwork/event/EventBus.java index 67b8514..1a08182 100644 --- a/Patchwork/src/main/java/me/totalfreedom/event/EventBus.java +++ b/Patchwork/src/main/java/fns/patchwork/event/EventBus.java @@ -1,19 +1,18 @@ -package me.totalfreedom.event; - -import me.totalfreedom.api.Context; -import me.totalfreedom.base.CommonsBase; -import me.totalfreedom.service.Service; +package fns.patchwork.event; +import fns.patchwork.api.Context; +import fns.patchwork.base.Patchwork; +import fns.patchwork.service.Service; import java.util.HashSet; import java.util.Set; public class EventBus extends Service { - private final CommonsBase plugin; + private final Patchwork plugin; private final Set eventSet = new HashSet<>(); private final SubscriptionBox runningSubscriptions = new SubscriptionBox<>(); - public EventBus(final CommonsBase plugin) + public EventBus(final Patchwork plugin) { super("event_bus"); this.plugin = plugin; @@ -57,7 +56,7 @@ public class EventBus extends Service runningSubscriptions.removeSubscription(subscription); } - public CommonsBase getCommonsBase() + public Patchwork getCommonsBase() { return plugin; } diff --git a/Patchwork/src/main/java/me/totalfreedom/event/EventSubscription.java b/Patchwork/src/main/java/fns/patchwork/event/EventSubscription.java similarity index 88% rename from Patchwork/src/main/java/me/totalfreedom/event/EventSubscription.java rename to Patchwork/src/main/java/fns/patchwork/event/EventSubscription.java index ac7bad1..902c250 100644 --- a/Patchwork/src/main/java/me/totalfreedom/event/EventSubscription.java +++ b/Patchwork/src/main/java/fns/patchwork/event/EventSubscription.java @@ -1,4 +1,4 @@ -package me.totalfreedom.event; +package fns.patchwork.event; public record EventSubscription(T event, Callback callback) { diff --git a/Patchwork/src/main/java/me/totalfreedom/event/FEvent.java b/Patchwork/src/main/java/fns/patchwork/event/FEvent.java similarity index 95% rename from Patchwork/src/main/java/me/totalfreedom/event/FEvent.java rename to Patchwork/src/main/java/fns/patchwork/event/FEvent.java index 9aa68d7..5f74134 100644 --- a/Patchwork/src/main/java/me/totalfreedom/event/FEvent.java +++ b/Patchwork/src/main/java/fns/patchwork/event/FEvent.java @@ -1,4 +1,4 @@ -package me.totalfreedom.event; +package fns.patchwork.event; public abstract class FEvent { diff --git a/Patchwork/src/main/java/me/totalfreedom/event/SubscriptionBox.java b/Patchwork/src/main/java/fns/patchwork/event/SubscriptionBox.java similarity index 96% rename from Patchwork/src/main/java/me/totalfreedom/event/SubscriptionBox.java rename to Patchwork/src/main/java/fns/patchwork/event/SubscriptionBox.java index c93a230..d990273 100644 --- a/Patchwork/src/main/java/me/totalfreedom/event/SubscriptionBox.java +++ b/Patchwork/src/main/java/fns/patchwork/event/SubscriptionBox.java @@ -1,4 +1,4 @@ -package me.totalfreedom.event; +package fns.patchwork.event; import java.util.ArrayList; import java.util.List; diff --git a/Patchwork/src/main/java/me/totalfreedom/logging/BlockInteraction.java b/Patchwork/src/main/java/fns/patchwork/logging/BlockInteraction.java similarity index 97% rename from Patchwork/src/main/java/me/totalfreedom/logging/BlockInteraction.java rename to Patchwork/src/main/java/fns/patchwork/logging/BlockInteraction.java index ae64341..ef617ca 100644 --- a/Patchwork/src/main/java/me/totalfreedom/logging/BlockInteraction.java +++ b/Patchwork/src/main/java/fns/patchwork/logging/BlockInteraction.java @@ -1,13 +1,12 @@ -package me.totalfreedom.logging; +package fns.patchwork.logging; +import java.time.Instant; +import java.util.UUID; import org.bukkit.Location; import org.bukkit.block.data.BlockData; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import java.time.Instant; -import java.util.UUID; - public final class BlockInteraction implements Interaction { private final Location location; diff --git a/Patchwork/src/main/java/me/totalfreedom/logging/ContainerInteraction.java b/Patchwork/src/main/java/fns/patchwork/logging/ContainerInteraction.java similarity index 98% rename from Patchwork/src/main/java/me/totalfreedom/logging/ContainerInteraction.java rename to Patchwork/src/main/java/fns/patchwork/logging/ContainerInteraction.java index c09efee..a134f1b 100644 --- a/Patchwork/src/main/java/me/totalfreedom/logging/ContainerInteraction.java +++ b/Patchwork/src/main/java/fns/patchwork/logging/ContainerInteraction.java @@ -1,16 +1,15 @@ -package me.totalfreedom.logging; - -import org.bukkit.Location; -import org.bukkit.block.Container; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; +package fns.patchwork.logging; import java.time.Instant; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.UUID; +import org.bukkit.Location; +import org.bukkit.block.Container; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; public final class ContainerInteraction implements Interaction> { diff --git a/Patchwork/src/main/java/me/totalfreedom/logging/Interaction.java b/Patchwork/src/main/java/fns/patchwork/logging/Interaction.java similarity index 94% rename from Patchwork/src/main/java/me/totalfreedom/logging/Interaction.java rename to Patchwork/src/main/java/fns/patchwork/logging/Interaction.java index 75aeb63..bb0bed5 100644 --- a/Patchwork/src/main/java/me/totalfreedom/logging/Interaction.java +++ b/Patchwork/src/main/java/fns/patchwork/logging/Interaction.java @@ -1,11 +1,10 @@ -package me.totalfreedom.logging; +package fns.patchwork.logging; import com.google.errorprone.annotations.Immutable; -import org.bukkit.Location; -import org.jetbrains.annotations.NotNull; - import java.time.Instant; import java.util.UUID; +import org.bukkit.Location; +import org.jetbrains.annotations.NotNull; @Immutable public interface Interaction diff --git a/Patchwork/src/main/java/me/totalfreedom/logging/InteractionFormatter.java b/Patchwork/src/main/java/fns/patchwork/logging/InteractionFormatter.java similarity index 99% rename from Patchwork/src/main/java/me/totalfreedom/logging/InteractionFormatter.java rename to Patchwork/src/main/java/fns/patchwork/logging/InteractionFormatter.java index 19a5f01..ec660b3 100644 --- a/Patchwork/src/main/java/me/totalfreedom/logging/InteractionFormatter.java +++ b/Patchwork/src/main/java/fns/patchwork/logging/InteractionFormatter.java @@ -1,12 +1,11 @@ -package me.totalfreedom.logging; +package fns.patchwork.logging; +import java.time.Instant; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.inventory.ItemStack; -import java.time.Instant; - public final class InteractionFormatter { public String formatInteraction(final Interaction interaction) diff --git a/Patchwork/src/main/java/me/totalfreedom/particle/NoteColorUtil.java b/Patchwork/src/main/java/fns/patchwork/particle/NoteColorUtil.java similarity index 98% rename from Patchwork/src/main/java/me/totalfreedom/particle/NoteColorUtil.java rename to Patchwork/src/main/java/fns/patchwork/particle/NoteColorUtil.java index a415118..691eccb 100644 --- a/Patchwork/src/main/java/me/totalfreedom/particle/NoteColorUtil.java +++ b/Patchwork/src/main/java/fns/patchwork/particle/NoteColorUtil.java @@ -1,4 +1,4 @@ -package me.totalfreedom.particle; +package fns.patchwork.particle; import org.bukkit.Particle; import org.bukkit.World; diff --git a/Patchwork/src/main/java/me/totalfreedom/particle/Trail.java b/Patchwork/src/main/java/fns/patchwork/particle/Trail.java similarity index 96% rename from Patchwork/src/main/java/me/totalfreedom/particle/Trail.java rename to Patchwork/src/main/java/fns/patchwork/particle/Trail.java index b6ef17f..9ffb2c5 100644 --- a/Patchwork/src/main/java/me/totalfreedom/particle/Trail.java +++ b/Patchwork/src/main/java/fns/patchwork/particle/Trail.java @@ -1,16 +1,15 @@ -package me.totalfreedom.particle; +package fns.patchwork.particle; -import me.totalfreedom.api.Interpolator; -import me.totalfreedom.utils.InterpolationUtils; +import fns.patchwork.api.Interpolator; +import fns.patchwork.utils.InterpolationUtils; +import java.util.Set; +import java.util.UUID; import org.bukkit.Color; import org.bukkit.OfflinePlayer; import org.bukkit.Particle; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Set; -import java.util.UUID; - /** * Represents a Trail instance for a specific player. */ @@ -56,7 +55,7 @@ public interface Trail * * @return The color of the trail, or null if the trail is a gradient or non-colorable. * @see Particle - * @see #getColors(); + * @see #getColors() */ @Nullable Color getColor(); diff --git a/Patchwork/src/main/java/me/totalfreedom/particle/TrailType.java b/Patchwork/src/main/java/fns/patchwork/particle/TrailType.java similarity index 97% rename from Patchwork/src/main/java/me/totalfreedom/particle/TrailType.java rename to Patchwork/src/main/java/fns/patchwork/particle/TrailType.java index e7afbe2..f87269c 100644 --- a/Patchwork/src/main/java/me/totalfreedom/particle/TrailType.java +++ b/Patchwork/src/main/java/fns/patchwork/particle/TrailType.java @@ -1,4 +1,4 @@ -package me.totalfreedom.particle; +package fns.patchwork.particle; import org.bukkit.Particle; diff --git a/Patchwork/src/main/java/fns/patchwork/provider/ContextProvider.java b/Patchwork/src/main/java/fns/patchwork/provider/ContextProvider.java new file mode 100644 index 0000000..01f1807 --- /dev/null +++ b/Patchwork/src/main/java/fns/patchwork/provider/ContextProvider.java @@ -0,0 +1,204 @@ +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; +import java.util.stream.Stream; +import net.kyori.adventure.text.Component; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * This class is used to provide context to subcommand methods. This class is used by the BukkitDelegate to parse + * arguments for subcommands. The following types are supported: + *

+ * All of these types can be parsed from a String input. If the String cannot be parsed into any of + * these types, then null will be returned. + * + * @see #fromString(String, Class) + */ +public class ContextProvider +{ + public T fromString(final String string, final Class clazz) + { + return Stream.of(toBoolean(string, clazz), + toDouble(string, clazz), + toInt(string, clazz), + toLong(string, clazz), + toFloat(string, clazz), + toMaterial(string, clazz), + toPlayer(string, clazz), + toWorld(string, clazz), + toLocation(string, clazz), + toComponent(string, clazz)) + .filter(Objects::nonNull) + .findFirst() + .map(clazz::cast) + .orElse(null); + } + + private @Nullable Boolean toBoolean(final String string, final Class clazz) + { + if (clazz != Boolean.class) + return null; + + // Previously we used Boolean#parseBoolean, but that will always return a value and does not throw + // an exception. This means that if the string is not "true" or "false", it will return false. + if (string.equalsIgnoreCase("true")) + return true; + if (string.equalsIgnoreCase("false")) + return false; + + return null; + } + + private @Nullable Double toDouble(final String string, final Class clazz) + { + if (clazz != Double.class) + return null; + + try + { + return Double.parseDouble(string); + } + catch (NumberFormatException ignored) + { + return null; + } + } + + private @Nullable Integer toInt(final String string, final Class clazz) + { + if (clazz != Integer.class) + return null; + + try + { + return Integer.parseInt(string); + } + catch (NumberFormatException ignored) + { + return null; + } + } + + private @Nullable Long toLong(final String string, final Class clazz) + { + if (clazz != Long.class) + return null; + + try + { + return Long.parseLong(string); + } + catch (NumberFormatException ignored) + { + return null; + } + } + + private @Nullable Float toFloat(final String string, final Class clazz) + { + if (clazz != Float.class) + return null; + + try + { + return Float.parseFloat(string); + } + catch (NumberFormatException ignored) + { + return null; + } + } + + private @Nullable Material toMaterial(final String string, final Class clazz) + { + if (clazz != Material.class) + return null; + return Material.matchMaterial(string); + } + + private @Nullable Player toPlayer(final String string, final Class clazz) + { + if (clazz != Player.class) + return null; + return Bukkit.getPlayer(string); + } + + private @Nullable World toWorld(final String string, final Class clazz) + { + if (clazz != World.class) + return null; + return Bukkit.getWorld(string); + } + + /** + * When using this method, the next four arguments must be world, x, y, z. + * The world must be a valid world name, and x, y, and z must be valid doubles. + * If any of these are invalid, this will return null. + * + * @param string The string to parse + * @return A location object if xyz is valid + */ + private @Nullable Location toLocation(final String string, final Class clazz) + { + if (clazz != Location.class) + return null; + + final String[] split = string.split(" "); + + if (split.length != 4 || toWorld(split[0], World.class) == null) + return null; + + try + { + final double x = Double.parseDouble(split[1]); + final double y = Double.parseDouble(split[2]); + final double z = Double.parseDouble(split[3]); + + return new Location(toWorld(split[0], World.class), x, y, z); + } + catch (NumberFormatException ex) + { + return null; + } + } + + private @Nullable Component toComponent(final String string, final Class clazz) + { + if (clazz != Component.class) + return null; + return Component.text(string); + } + + public @NotNull List<@Nullable T> getList(final List resolvable, final Class clazz) + { + final List resolved = new ArrayList<>(); + for (final String entry : resolvable) + { + resolved.add(this.fromString(entry, clazz)); + } + return resolved; + } +} diff --git a/Patchwork/src/main/java/me/totalfreedom/provider/EventProvider.java b/Patchwork/src/main/java/fns/patchwork/provider/EventProvider.java similarity index 56% rename from Patchwork/src/main/java/me/totalfreedom/provider/EventProvider.java rename to Patchwork/src/main/java/fns/patchwork/provider/EventProvider.java index 242fc10..a48e0f7 100644 --- a/Patchwork/src/main/java/me/totalfreedom/provider/EventProvider.java +++ b/Patchwork/src/main/java/fns/patchwork/provider/EventProvider.java @@ -1,6 +1,6 @@ -package me.totalfreedom.provider; +package fns.patchwork.provider; -import me.totalfreedom.event.FEvent; +import fns.patchwork.event.FEvent; @FunctionalInterface public interface EventProvider diff --git a/Patchwork/src/main/java/me/totalfreedom/provider/ModuleProvider.java b/Patchwork/src/main/java/fns/patchwork/provider/ModuleProvider.java similarity index 80% rename from Patchwork/src/main/java/me/totalfreedom/provider/ModuleProvider.java rename to Patchwork/src/main/java/fns/patchwork/provider/ModuleProvider.java index 65c9bd1..2b46744 100644 --- a/Patchwork/src/main/java/me/totalfreedom/provider/ModuleProvider.java +++ b/Patchwork/src/main/java/fns/patchwork/provider/ModuleProvider.java @@ -1,4 +1,4 @@ -package me.totalfreedom.provider; +package fns.patchwork.provider; import org.bukkit.plugin.java.JavaPlugin; diff --git a/Patchwork/src/main/java/me/totalfreedom/provider/ServiceProvider.java b/Patchwork/src/main/java/fns/patchwork/provider/ServiceProvider.java similarity index 51% rename from Patchwork/src/main/java/me/totalfreedom/provider/ServiceProvider.java rename to Patchwork/src/main/java/fns/patchwork/provider/ServiceProvider.java index e9a3387..f58c4c9 100644 --- a/Patchwork/src/main/java/me/totalfreedom/provider/ServiceProvider.java +++ b/Patchwork/src/main/java/fns/patchwork/provider/ServiceProvider.java @@ -1,6 +1,6 @@ -package me.totalfreedom.provider; +package fns.patchwork.provider; -import me.totalfreedom.service.Service; +import fns.patchwork.service.Service; public interface ServiceProvider { diff --git a/Patchwork/src/main/java/me/totalfreedom/security/Group.java b/Patchwork/src/main/java/fns/patchwork/security/Group.java similarity index 96% rename from Patchwork/src/main/java/me/totalfreedom/security/Group.java rename to Patchwork/src/main/java/fns/patchwork/security/Group.java index 41b2825..284eb2e 100644 --- a/Patchwork/src/main/java/me/totalfreedom/security/Group.java +++ b/Patchwork/src/main/java/fns/patchwork/security/Group.java @@ -1,4 +1,4 @@ -package me.totalfreedom.security; +package fns.patchwork.security; import net.kyori.adventure.text.Component; diff --git a/Patchwork/src/main/java/fns/patchwork/security/Groups.java b/Patchwork/src/main/java/fns/patchwork/security/Groups.java new file mode 100644 index 0000000..e4ee003 --- /dev/null +++ b/Patchwork/src/main/java/fns/patchwork/security/Groups.java @@ -0,0 +1,55 @@ +package fns.patchwork.security; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public enum Groups +{ + NON_OP("patchwork.group.non-op", "Non-OP"), + OP("patchwork.group.op", "OP"), + SUPER_ADMIN("patchwork.group.super", "Super Admin"), + SENIOR_ADMIN("patchwork.group.senior", "Senior Admin"), + DEVELOPER("patchwork.group.dev", "Developer"), + EXECUTIVE("patchwork.group.exec", "Executive"), + OWNER("patchwork.group.owner", "Owner"); + + private final String permission; + private final String name; + + Groups(final String permission, final String name) + { + this.permission = permission; + this.name = name; + } + + public String getName() + { + return this.name; + } + + public String getPermission() + { + return this.permission; + } + + @Override + public String toString() + { + return this.permission; + } + + public static String fromPlayer(final Player player) { + for (final Groups group : values()) { + if (player.hasPermission(group.getPermission())) { + return group.getName(); + } + } + return Groups.NON_OP.getName(); + } + + public static String fromSender(final CommandSender sender) { + if (!(sender instanceof Player)) return "CONSOLE"; + + return fromPlayer((Player) sender); + } +} diff --git a/Patchwork/src/main/java/me/totalfreedom/security/Node.java b/Patchwork/src/main/java/fns/patchwork/security/Node.java similarity index 85% rename from Patchwork/src/main/java/me/totalfreedom/security/Node.java rename to Patchwork/src/main/java/fns/patchwork/security/Node.java index 8af9348..cc1b5b2 100644 --- a/Patchwork/src/main/java/me/totalfreedom/security/Node.java +++ b/Patchwork/src/main/java/fns/patchwork/security/Node.java @@ -1,16 +1,13 @@ -package me.totalfreedom.security; - -import org.bukkit.permissions.Permission; +package fns.patchwork.security; import javax.annotation.concurrent.Immutable; +import org.bukkit.permissions.Permission; @Immutable public interface Node { String key(); - boolean value(); - Permission bukkit(); NodeType type(); diff --git a/Patchwork/src/main/java/me/totalfreedom/security/NodeBuilder.java b/Patchwork/src/main/java/fns/patchwork/security/NodeBuilder.java similarity index 64% rename from Patchwork/src/main/java/me/totalfreedom/security/NodeBuilder.java rename to Patchwork/src/main/java/fns/patchwork/security/NodeBuilder.java index c0503ff..34ded3d 100644 --- a/Patchwork/src/main/java/me/totalfreedom/security/NodeBuilder.java +++ b/Patchwork/src/main/java/fns/patchwork/security/NodeBuilder.java @@ -1,18 +1,14 @@ -package me.totalfreedom.security; +package fns.patchwork.security; public interface NodeBuilder { NodeBuilder key(String key); - NodeBuilder value(boolean value); - NodeBuilder expiry(long expiry); NodeBuilder type(NodeType type); NodeBuilder wildcard(boolean wildcard); - NodeBuilder negated(boolean negated); - Node build(); } diff --git a/Patchwork/src/main/java/me/totalfreedom/security/NodeType.java b/Patchwork/src/main/java/fns/patchwork/security/NodeType.java similarity index 73% rename from Patchwork/src/main/java/me/totalfreedom/security/NodeType.java rename to Patchwork/src/main/java/fns/patchwork/security/NodeType.java index 11293a9..e9d5f41 100644 --- a/Patchwork/src/main/java/me/totalfreedom/security/NodeType.java +++ b/Patchwork/src/main/java/fns/patchwork/security/NodeType.java @@ -1,4 +1,4 @@ -package me.totalfreedom.security; +package fns.patchwork.security; public enum NodeType { diff --git a/Patchwork/src/main/java/me/totalfreedom/security/PermissionHolder.java b/Patchwork/src/main/java/fns/patchwork/security/PermissionHolder.java similarity index 88% rename from Patchwork/src/main/java/me/totalfreedom/security/PermissionHolder.java rename to Patchwork/src/main/java/fns/patchwork/security/PermissionHolder.java index 05f7e7c..9e6a96b 100644 --- a/Patchwork/src/main/java/me/totalfreedom/security/PermissionHolder.java +++ b/Patchwork/src/main/java/fns/patchwork/security/PermissionHolder.java @@ -1,9 +1,8 @@ -package me.totalfreedom.security; - -import org.bukkit.permissions.Permissible; +package fns.patchwork.security; import java.util.Set; import java.util.UUID; +import org.bukkit.permissions.Permissible; public interface PermissionHolder extends Permissible { diff --git a/Patchwork/src/main/java/me/totalfreedom/service/FreedomExecutor.java b/Patchwork/src/main/java/fns/patchwork/service/FreedomExecutor.java similarity index 95% rename from Patchwork/src/main/java/me/totalfreedom/service/FreedomExecutor.java rename to Patchwork/src/main/java/fns/patchwork/service/FreedomExecutor.java index f090314..c957279 100644 --- a/Patchwork/src/main/java/me/totalfreedom/service/FreedomExecutor.java +++ b/Patchwork/src/main/java/fns/patchwork/service/FreedomExecutor.java @@ -1,11 +1,10 @@ -package me.totalfreedom.service; - -import me.totalfreedom.base.CommonsBase; -import org.bukkit.Bukkit; -import org.bukkit.plugin.java.JavaPlugin; +package fns.patchwork.service; +import fns.patchwork.base.Patchwork; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; /** * This is a holder class for {@link Executor} objects that are used to delegate runnable tasks to the Bukkit Scheduler. @@ -26,12 +25,12 @@ public class FreedomExecutor /** * Creates a new {@link FreedomExecutor} instance. */ - public FreedomExecutor() + public FreedomExecutor(final Patchwork patchwork) { syncExecutor = r -> Bukkit.getScheduler() - .runTask(CommonsBase.getInstance(), r); + .runTask(patchwork, r); asyncExecutor = r -> Bukkit.getScheduler() - .runTaskAsynchronously(CommonsBase.getInstance(), r); + .runTaskAsynchronously(patchwork, r); } /** diff --git a/Patchwork/src/main/java/me/totalfreedom/service/Service.java b/Patchwork/src/main/java/fns/patchwork/service/Service.java similarity index 97% rename from Patchwork/src/main/java/me/totalfreedom/service/Service.java rename to Patchwork/src/main/java/fns/patchwork/service/Service.java index 927fb36..5da461a 100644 --- a/Patchwork/src/main/java/me/totalfreedom/service/Service.java +++ b/Patchwork/src/main/java/fns/patchwork/service/Service.java @@ -1,4 +1,4 @@ -package me.totalfreedom.service; +package fns.patchwork.service; /** * Represents a ticking service. Services may be asynchronous or synchronous, however there are some restrictions: diff --git a/Patchwork/src/main/java/me/totalfreedom/service/ServiceSubscription.java b/Patchwork/src/main/java/fns/patchwork/service/ServiceSubscription.java similarity index 99% rename from Patchwork/src/main/java/me/totalfreedom/service/ServiceSubscription.java rename to Patchwork/src/main/java/fns/patchwork/service/ServiceSubscription.java index dd8b543..af5faaf 100644 --- a/Patchwork/src/main/java/me/totalfreedom/service/ServiceSubscription.java +++ b/Patchwork/src/main/java/fns/patchwork/service/ServiceSubscription.java @@ -1,12 +1,11 @@ -package me.totalfreedom.service; +package fns.patchwork.service; +import java.util.concurrent.Executor; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; import org.jetbrains.annotations.NotNull; -import java.util.concurrent.Executor; - /** * Represents a subscription to a {@link Service}. *

diff --git a/Patchwork/src/main/java/me/totalfreedom/service/SubscriptionProvider.java b/Patchwork/src/main/java/fns/patchwork/service/SubscriptionProvider.java similarity index 99% rename from Patchwork/src/main/java/me/totalfreedom/service/SubscriptionProvider.java rename to Patchwork/src/main/java/fns/patchwork/service/SubscriptionProvider.java index 3a3c8ab..989a3cd 100644 --- a/Patchwork/src/main/java/me/totalfreedom/service/SubscriptionProvider.java +++ b/Patchwork/src/main/java/fns/patchwork/service/SubscriptionProvider.java @@ -1,4 +1,4 @@ -package me.totalfreedom.service; +package fns.patchwork.service; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.Contract; diff --git a/Patchwork/src/main/java/me/totalfreedom/service/Task.java b/Patchwork/src/main/java/fns/patchwork/service/Task.java similarity index 98% rename from Patchwork/src/main/java/me/totalfreedom/service/Task.java rename to Patchwork/src/main/java/fns/patchwork/service/Task.java index 3275705..a03773c 100644 --- a/Patchwork/src/main/java/me/totalfreedom/service/Task.java +++ b/Patchwork/src/main/java/fns/patchwork/service/Task.java @@ -1,9 +1,8 @@ -package me.totalfreedom.service; - -import me.totalfreedom.utils.DurationTools; -import org.bukkit.scheduler.BukkitRunnable; +package fns.patchwork.service; +import fns.patchwork.utils.DurationTools; import java.time.Duration; +import org.bukkit.scheduler.BukkitRunnable; /** * Represents a task that can be run asynchronously or synchronously. diff --git a/Patchwork/src/main/java/me/totalfreedom/service/TaskSubscription.java b/Patchwork/src/main/java/fns/patchwork/service/TaskSubscription.java similarity index 98% rename from Patchwork/src/main/java/me/totalfreedom/service/TaskSubscription.java rename to Patchwork/src/main/java/fns/patchwork/service/TaskSubscription.java index 9e5c3e1..f79c17b 100644 --- a/Patchwork/src/main/java/me/totalfreedom/service/TaskSubscription.java +++ b/Patchwork/src/main/java/fns/patchwork/service/TaskSubscription.java @@ -1,13 +1,12 @@ -package me.totalfreedom.service; +package fns.patchwork.service; -import me.totalfreedom.utils.container.Pair; +import fns.patchwork.utils.container.Pair; +import java.util.concurrent.Executor; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitTask; -import java.util.concurrent.Executor; - /** * Represents a subscription to a task. Task subscriptions offer a nice wrapper for managing tasks, which are inevitably * just bukkit runnables with a bit more lenience in terms of instantiation modification and execution. It also offers a diff --git a/Patchwork/src/main/java/me/totalfreedom/shop/Reactable.java b/Patchwork/src/main/java/fns/patchwork/shop/Reactable.java similarity index 82% rename from Patchwork/src/main/java/me/totalfreedom/shop/Reactable.java rename to Patchwork/src/main/java/fns/patchwork/shop/Reactable.java index 86ddec4..36b0d55 100644 --- a/Patchwork/src/main/java/me/totalfreedom/shop/Reactable.java +++ b/Patchwork/src/main/java/fns/patchwork/shop/Reactable.java @@ -1,11 +1,10 @@ -package me.totalfreedom.shop; +package fns.patchwork.shop; -import me.totalfreedom.economy.EconomicEntity; +import fns.patchwork.economy.EconomicEntity; +import java.time.Duration; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.text.Component; -import java.time.Duration; - public interface Reactable { Component getReactionMessage(); diff --git a/Patchwork/src/main/java/me/totalfreedom/shop/Reaction.java b/Patchwork/src/main/java/fns/patchwork/shop/Reaction.java similarity index 90% rename from Patchwork/src/main/java/me/totalfreedom/shop/Reaction.java rename to Patchwork/src/main/java/fns/patchwork/shop/Reaction.java index 0b96cc7..28f4a27 100644 --- a/Patchwork/src/main/java/me/totalfreedom/shop/Reaction.java +++ b/Patchwork/src/main/java/fns/patchwork/shop/Reaction.java @@ -1,9 +1,7 @@ -package me.totalfreedom.shop; - -import me.totalfreedom.display.BossBarDisplay; -import net.kyori.adventure.text.Component; +package fns.patchwork.shop; import java.time.Duration; +import net.kyori.adventure.text.Component; /** * Represents a chat reaction that can be performed by a player. @@ -59,10 +57,4 @@ public abstract class Reaction implements Reactable { return reactionType; } - - @Override - public BossBarDisplay getBossBarDisplay() - { - - } } diff --git a/Patchwork/src/main/java/me/totalfreedom/shop/ReactionTask.java b/Patchwork/src/main/java/fns/patchwork/shop/ReactionTask.java similarity index 67% rename from Patchwork/src/main/java/me/totalfreedom/shop/ReactionTask.java rename to Patchwork/src/main/java/fns/patchwork/shop/ReactionTask.java index cceb27e..360781b 100644 --- a/Patchwork/src/main/java/me/totalfreedom/shop/ReactionTask.java +++ b/Patchwork/src/main/java/fns/patchwork/shop/ReactionTask.java @@ -1,11 +1,13 @@ -package me.totalfreedom.shop; +package fns.patchwork.shop; +import fns.patchwork.base.Patchwork; +import fns.patchwork.base.Registration; +import fns.patchwork.base.Shortcuts; +import fns.patchwork.display.BossBarDisplay; +import fns.patchwork.display.BossBarTimer; +import fns.patchwork.economy.EconomicEntity; +import fns.patchwork.service.Task; import io.papermc.paper.event.player.AsyncChatEvent; -import me.totalfreedom.base.CommonsBase; -import me.totalfreedom.display.BossBarDisplay; -import me.totalfreedom.display.BossBarTimer; -import me.totalfreedom.economy.EconomicEntity; -import me.totalfreedom.service.Task; import net.kyori.adventure.bossbar.BossBar; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -36,7 +38,7 @@ public class ReactionTask extends Task implements Listener } final BossBarTimer timer = new BossBarTimer(bossBarDisplay, reaction.getReactionDuration()); - timer.runTaskTimer(CommonsBase.getInstance(), 0L, timer.getInterval()); + timer.runTaskTimer(Shortcuts.provideModule(Patchwork.class), 0L, timer.getInterval()); } @EventHandler @@ -45,10 +47,8 @@ public class ReactionTask extends Task implements Listener if (event.message() .equals(reaction.getReactionMessage())) { - final EconomicEntity entity = CommonsBase.getInstance() - .getRegistrations() - .getUserRegistry() - .getUser(event.getPlayer()); + final EconomicEntity entity = Registration.getUserRegistry() + .getUser(event.getPlayer()); reaction.onReact(entity); } diff --git a/Patchwork/src/main/java/me/totalfreedom/shop/ReactionType.java b/Patchwork/src/main/java/fns/patchwork/shop/ReactionType.java similarity index 67% rename from Patchwork/src/main/java/me/totalfreedom/shop/ReactionType.java rename to Patchwork/src/main/java/fns/patchwork/shop/ReactionType.java index e36a3da..905b1c9 100644 --- a/Patchwork/src/main/java/me/totalfreedom/shop/ReactionType.java +++ b/Patchwork/src/main/java/fns/patchwork/shop/ReactionType.java @@ -1,4 +1,4 @@ -package me.totalfreedom.shop; +package fns.patchwork.shop; public enum ReactionType { diff --git a/Patchwork/src/main/java/me/totalfreedom/sql/SQL.java b/Patchwork/src/main/java/fns/patchwork/sql/SQL.java similarity index 95% rename from Patchwork/src/main/java/me/totalfreedom/sql/SQL.java rename to Patchwork/src/main/java/fns/patchwork/sql/SQL.java index 4e9adc1..fb51021 100644 --- a/Patchwork/src/main/java/me/totalfreedom/sql/SQL.java +++ b/Patchwork/src/main/java/fns/patchwork/sql/SQL.java @@ -1,4 +1,4 @@ -package me.totalfreedom.sql; +package fns.patchwork.sql; import java.sql.PreparedStatement; import java.sql.ResultSet; diff --git a/Patchwork/src/main/java/me/totalfreedom/sql/SQLProperties.java b/Patchwork/src/main/java/fns/patchwork/sql/SQLProperties.java similarity index 97% rename from Patchwork/src/main/java/me/totalfreedom/sql/SQLProperties.java rename to Patchwork/src/main/java/fns/patchwork/sql/SQLProperties.java index 5a0566b..c1bc098 100644 --- a/Patchwork/src/main/java/me/totalfreedom/sql/SQLProperties.java +++ b/Patchwork/src/main/java/fns/patchwork/sql/SQLProperties.java @@ -1,4 +1,4 @@ -package me.totalfreedom.sql; +package fns.patchwork.sql; import java.io.File; import java.util.Properties; diff --git a/Patchwork/src/main/java/me/totalfreedom/user/User.java b/Patchwork/src/main/java/fns/patchwork/user/User.java similarity index 72% rename from Patchwork/src/main/java/me/totalfreedom/user/User.java rename to Patchwork/src/main/java/fns/patchwork/user/User.java index f925492..bf25338 100644 --- a/Patchwork/src/main/java/me/totalfreedom/user/User.java +++ b/Patchwork/src/main/java/fns/patchwork/user/User.java @@ -1,8 +1,8 @@ -package me.totalfreedom.user; +package fns.patchwork.user; -import me.totalfreedom.economy.EconomicEntity; -import me.totalfreedom.economy.EconomicEntityData; -import me.totalfreedom.security.PermissionHolder; +import fns.patchwork.economy.EconomicEntity; +import fns.patchwork.economy.EconomicEntityData; +import fns.patchwork.security.PermissionHolder; import net.kyori.adventure.text.Component; public interface User extends PermissionHolder, EconomicEntity diff --git a/Patchwork/src/main/java/me/totalfreedom/user/UserData.java b/Patchwork/src/main/java/fns/patchwork/user/UserData.java similarity index 63% rename from Patchwork/src/main/java/me/totalfreedom/user/UserData.java rename to Patchwork/src/main/java/fns/patchwork/user/UserData.java index 2cfb8d1..51afa7e 100644 --- a/Patchwork/src/main/java/me/totalfreedom/user/UserData.java +++ b/Patchwork/src/main/java/fns/patchwork/user/UserData.java @@ -1,12 +1,12 @@ -package me.totalfreedom.user; +package fns.patchwork.user; -import me.totalfreedom.economy.EconomicEntityData; -import me.totalfreedom.security.Group; +import fns.patchwork.display.adminchat.AdminChatFormat; +import fns.patchwork.economy.EconomicEntityData; +import fns.patchwork.security.Group; +import java.util.UUID; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.UUID; - public interface UserData extends EconomicEntityData { @NotNull UUID getUniqueId(); @@ -30,4 +30,10 @@ public interface UserData extends EconomicEntityData boolean canInteract(); void setInteractionState(boolean canInteract); + + boolean hasCustomACFormat(); + + void setCustomACFormat(final String customACFormat); + + AdminChatFormat getCustomACFormat(); } diff --git a/Patchwork/src/main/java/me/totalfreedom/utils/DurationTools.java b/Patchwork/src/main/java/fns/patchwork/utils/DurationTools.java similarity index 95% rename from Patchwork/src/main/java/me/totalfreedom/utils/DurationTools.java rename to Patchwork/src/main/java/fns/patchwork/utils/DurationTools.java index b629f09..84d1531 100644 --- a/Patchwork/src/main/java/me/totalfreedom/utils/DurationTools.java +++ b/Patchwork/src/main/java/fns/patchwork/utils/DurationTools.java @@ -1,4 +1,4 @@ -package me.totalfreedom.utils; +package fns.patchwork.utils; import java.time.Duration; diff --git a/Patchwork/src/main/java/me/totalfreedom/utils/InterpolationUtils.java b/Patchwork/src/main/java/fns/patchwork/utils/InterpolationUtils.java similarity index 98% rename from Patchwork/src/main/java/me/totalfreedom/utils/InterpolationUtils.java rename to Patchwork/src/main/java/fns/patchwork/utils/InterpolationUtils.java index 7be41c0..f8ca964 100644 --- a/Patchwork/src/main/java/me/totalfreedom/utils/InterpolationUtils.java +++ b/Patchwork/src/main/java/fns/patchwork/utils/InterpolationUtils.java @@ -1,13 +1,12 @@ -package me.totalfreedom.utils; +package fns.patchwork.utils; -import me.totalfreedom.api.Interpolator; +import fns.patchwork.api.Interpolator; +import java.util.LinkedHashSet; +import java.util.Set; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextColor; import org.bukkit.Color; -import java.util.LinkedHashSet; -import java.util.Set; - public final class InterpolationUtils { private InterpolationUtils() diff --git a/Patchwork/src/main/java/me/totalfreedom/utils/ShapeUtils.java b/Patchwork/src/main/java/fns/patchwork/utils/ShapeUtils.java similarity index 97% rename from Patchwork/src/main/java/me/totalfreedom/utils/ShapeUtils.java rename to Patchwork/src/main/java/fns/patchwork/utils/ShapeUtils.java index e4b533c..08f1f33 100644 --- a/Patchwork/src/main/java/me/totalfreedom/utils/ShapeUtils.java +++ b/Patchwork/src/main/java/fns/patchwork/utils/ShapeUtils.java @@ -1,11 +1,10 @@ -package me.totalfreedom.utils; - -import org.bukkit.Location; -import org.bukkit.World; +package fns.patchwork.utils; import java.util.LinkedList; import java.util.List; import java.util.function.DoubleUnaryOperator; +import org.bukkit.Location; +import org.bukkit.World; public class ShapeUtils { diff --git a/Patchwork/src/main/java/fns/patchwork/utils/Tagged.java b/Patchwork/src/main/java/fns/patchwork/utils/Tagged.java new file mode 100644 index 0000000..b2f0e08 --- /dev/null +++ b/Patchwork/src/main/java/fns/patchwork/utils/Tagged.java @@ -0,0 +1,100 @@ +package fns.patchwork.utils; + +import java.util.ArrayList; +import java.util.List; +import org.bukkit.entity.EntityType; +import org.jetbrains.annotations.NotNull; + +public final class Tagged +{ + public static final Tagged NON_WIPEABLE = new Tagged<>(EntityType.ITEM_FRAME, EntityType.BLOCK_DISPLAY, + EntityType.ITEM_DISPLAY, EntityType.LEASH_HITCH, + EntityType.CHEST_BOAT, EntityType.BOAT, + EntityType.TEXT_DISPLAY, + EntityType.GLOW_ITEM_FRAME, + EntityType.ARMOR_STAND, EntityType.PAINTING, + EntityType.PLAYER, EntityType.DROPPED_ITEM, + EntityType.MINECART, EntityType.MINECART_CHEST, + EntityType.MINECART_COMMAND, + EntityType.MINECART_FURNACE, + EntityType.MINECART_HOPPER, + EntityType.FISHING_HOOK, EntityType.DONKEY, + EntityType.HORSE, EntityType.IRON_GOLEM, + EntityType.RABBIT, EntityType.SNOWMAN, + EntityType.VILLAGER, EntityType.WOLF); + + public static final Tagged MINECARTS = new Tagged<>(EntityType.MINECART, EntityType.MINECART_CHEST, + EntityType.MINECART_COMMAND, + EntityType.MINECART_FURNACE, + EntityType.MINECART_HOPPER, + EntityType.MINECART_MOB_SPAWNER, + EntityType.MINECART_TNT); + + public static final Tagged BOATS = new Tagged<>(EntityType.BOAT, EntityType.CHEST_BOAT); + + public static final Tagged HOSTILE = new Tagged<>(EntityType.BLAZE, EntityType.CAVE_SPIDER, + EntityType.CREEPER, EntityType.DROWNED, + EntityType.ELDER_GUARDIAN, EntityType.ENDER_CRYSTAL, + EntityType.ENDER_DRAGON, EntityType.ENDERMAN, + EntityType.ENDERMITE, EntityType.EVOKER, + EntityType.EVOKER_FANGS, EntityType.GHAST, + EntityType.GIANT, EntityType.GUARDIAN, + EntityType.HOGLIN, EntityType.HUSK, + EntityType.ILLUSIONER, EntityType.MAGMA_CUBE, + EntityType.PHANTOM, EntityType.PIGLIN, + EntityType.PIGLIN_BRUTE, EntityType.PILLAGER, + EntityType.RAVAGER, EntityType.SHULKER, + EntityType.SILVERFISH, EntityType.SKELETON, + EntityType.SLIME, EntityType.SPIDER, EntityType.STRAY, + EntityType.VEX, EntityType.VINDICATOR, + EntityType.WARDEN, EntityType.WITCH, + EntityType.WITHER, EntityType.WITHER_SKELETON, + EntityType.ZOGLIN, EntityType.ZOMBIE, + EntityType.ZOMBIE_VILLAGER, + EntityType.ZOMBIFIED_PIGLIN); + + public static final Tagged PASSIVE = new Tagged<>(EntityType.BAT, EntityType.BEE, EntityType.CAT, + EntityType.CHICKEN, EntityType.COD, EntityType.COW, + EntityType.DOLPHIN, EntityType.DONKEY, EntityType.FOX, + EntityType.GOAT, EntityType.HORSE, + EntityType.IRON_GOLEM, EntityType.LLAMA, + EntityType.MULE, EntityType.MUSHROOM_COW, + EntityType.OCELOT, EntityType.PANDA, + EntityType.PARROT, EntityType.PIG, + EntityType.POLAR_BEAR, EntityType.PUFFERFISH, + EntityType.RABBIT, EntityType.SALMON, + EntityType.SHEEP, EntityType.SKELETON_HORSE, + EntityType.SNOWMAN, EntityType.SQUID, + EntityType.STRIDER, EntityType.TRADER_LLAMA, + EntityType.TROPICAL_FISH, EntityType.TURTLE, + EntityType.VILLAGER, EntityType.WANDERING_TRADER, + EntityType.WOLF); + + public static final Tagged PLAYER_RELATED = new Tagged<>(EntityType.PLAYER, EntityType.ARMOR_STAND, + EntityType.DROPPED_ITEM, EntityType.PAINTING, + EntityType.ITEM_FRAME, + EntityType.GLOW_ITEM_FRAME, + EntityType.LEASH_HITCH, + EntityType.FISHING_HOOK, + EntityType.TEXT_DISPLAY, + EntityType.BLOCK_DISPLAY, + EntityType.ITEM_DISPLAY); + + private final List taggable; + + private Tagged(final T... taggable) + { + this.taggable = new ArrayList<>(); + this.taggable.addAll(List.of(taggable)); + } + + public boolean isTagged(final @NotNull T object) + { + for (final T t : this.taggable) + { + if (object.equals(t)) + return true; + } + return false; + } +} diff --git a/Patchwork/src/main/java/me/totalfreedom/utils/container/Identity.java b/Patchwork/src/main/java/fns/patchwork/utils/container/Identity.java similarity index 89% rename from Patchwork/src/main/java/me/totalfreedom/utils/container/Identity.java rename to Patchwork/src/main/java/fns/patchwork/utils/container/Identity.java index 0770962..5a4415f 100644 --- a/Patchwork/src/main/java/me/totalfreedom/utils/container/Identity.java +++ b/Patchwork/src/main/java/fns/patchwork/utils/container/Identity.java @@ -1,4 +1,4 @@ -package me.totalfreedom.utils.container; +package fns.patchwork.utils.container; import java.util.UUID; diff --git a/Patchwork/src/main/java/me/totalfreedom/utils/container/Pair.java b/Patchwork/src/main/java/fns/patchwork/utils/container/Pair.java similarity index 52% rename from Patchwork/src/main/java/me/totalfreedom/utils/container/Pair.java rename to Patchwork/src/main/java/fns/patchwork/utils/container/Pair.java index 0cf4e76..1c6d3c7 100644 --- a/Patchwork/src/main/java/me/totalfreedom/utils/container/Pair.java +++ b/Patchwork/src/main/java/fns/patchwork/utils/container/Pair.java @@ -1,4 +1,4 @@ -package me.totalfreedom.utils.container; +package fns.patchwork.utils.container; public record Pair(K key, V value) { diff --git a/Patchwork/src/main/java/fns/patchwork/utils/container/Trio.java b/Patchwork/src/main/java/fns/patchwork/utils/container/Trio.java new file mode 100644 index 0000000..77c95e2 --- /dev/null +++ b/Patchwork/src/main/java/fns/patchwork/utils/container/Trio.java @@ -0,0 +1,5 @@ +package fns.patchwork.utils.container; + +public record Trio(A primary, B secondary, C tertiary) +{ +} diff --git a/Patchwork/src/main/java/fns/patchwork/utils/container/UnaryPair.java b/Patchwork/src/main/java/fns/patchwork/utils/container/UnaryPair.java new file mode 100644 index 0000000..6015249 --- /dev/null +++ b/Patchwork/src/main/java/fns/patchwork/utils/container/UnaryPair.java @@ -0,0 +1,5 @@ +package fns.patchwork.utils.container; + +public record UnaryPair(T first, T second) +{ +} diff --git a/Patchwork/src/main/java/fns/patchwork/utils/container/UnaryTrio.java b/Patchwork/src/main/java/fns/patchwork/utils/container/UnaryTrio.java new file mode 100644 index 0000000..de936f6 --- /dev/null +++ b/Patchwork/src/main/java/fns/patchwork/utils/container/UnaryTrio.java @@ -0,0 +1,5 @@ +package fns.patchwork.utils.container; + +public record UnaryTrio(T primary, T secondary, T tertiary) +{ +} diff --git a/Patchwork/src/main/java/me/totalfreedom/utils/kyori/FreedomAdventure.java b/Patchwork/src/main/java/fns/patchwork/utils/kyori/FreedomAdventure.java similarity index 97% rename from Patchwork/src/main/java/me/totalfreedom/utils/kyori/FreedomAdventure.java rename to Patchwork/src/main/java/fns/patchwork/utils/kyori/FreedomAdventure.java index 3dc548a..5599756 100644 --- a/Patchwork/src/main/java/me/totalfreedom/utils/kyori/FreedomAdventure.java +++ b/Patchwork/src/main/java/fns/patchwork/utils/kyori/FreedomAdventure.java @@ -1,9 +1,8 @@ -package me.totalfreedom.utils.kyori; - -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; +package fns.patchwork.utils.kyori; import java.util.function.Supplier; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; /** * This class contains the only reference to plain text component serializer, and allows access to it via wrapper diff --git a/Patchwork/src/main/java/me/totalfreedom/utils/kyori/FreedomMiniMessage.java b/Patchwork/src/main/java/fns/patchwork/utils/kyori/FreedomMiniMessage.java similarity index 90% rename from Patchwork/src/main/java/me/totalfreedom/utils/kyori/FreedomMiniMessage.java rename to Patchwork/src/main/java/fns/patchwork/utils/kyori/FreedomMiniMessage.java index 3db5cdc..1a3b28f 100644 --- a/Patchwork/src/main/java/me/totalfreedom/utils/kyori/FreedomMiniMessage.java +++ b/Patchwork/src/main/java/fns/patchwork/utils/kyori/FreedomMiniMessage.java @@ -19,7 +19,7 @@ * THE SOFTWARE. */ -package me.totalfreedom.utils.kyori; +package fns.patchwork.utils.kyori; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.TextDecoration; @@ -60,11 +60,11 @@ public class FreedomMiniMessage * @param placeholders Custom placeholders to use when processing the input * @return A processed Component */ - public static Component deserialize(boolean safe, String input, TagResolver... placeholders) + public static Component deserialize(final boolean safe, final String input, final TagResolver... placeholders) { return (safe - ? FreedomMiniMessage.safe - : unsafe).deserialize(input, placeholders); + ? FreedomMiniMessage.safe + : unsafe).deserialize(input, placeholders); } /** @@ -75,10 +75,10 @@ public class FreedomMiniMessage * @param input An already processed component * @return A processed Component */ - public static String serialize(boolean safe, Component input) + public static String serialize(final boolean safe, final Component input) { return (safe - ? FreedomMiniMessage.safe - : unsafe).serialize(input); + ? FreedomMiniMessage.safe + : unsafe).serialize(input); } } diff --git a/Patchwork/src/main/java/me/totalfreedom/utils/kyori/KyoriConstants.java b/Patchwork/src/main/java/fns/patchwork/utils/kyori/KyoriConstants.java similarity index 94% rename from Patchwork/src/main/java/me/totalfreedom/utils/kyori/KyoriConstants.java rename to Patchwork/src/main/java/fns/patchwork/utils/kyori/KyoriConstants.java index 0ffbe29..4820f35 100644 --- a/Patchwork/src/main/java/me/totalfreedom/utils/kyori/KyoriConstants.java +++ b/Patchwork/src/main/java/fns/patchwork/utils/kyori/KyoriConstants.java @@ -1,6 +1,6 @@ -package me.totalfreedom.utils.kyori; +package fns.patchwork.utils.kyori; -import me.totalfreedom.base.CommonsBase; +import fns.patchwork.base.Patchwork; import net.kyori.adventure.chat.ChatType; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -24,7 +24,7 @@ public final class KyoriConstants /** * A singleton {@link ChatType.Bound} for the Patchwork plugin. */ - public static final ChatType.Bound PATCHWORK = fromPlugin(CommonsBase.class); + public static final ChatType.Bound PATCHWORK = fromPlugin(Patchwork.class); private KyoriConstants() { diff --git a/Patchwork/src/main/java/me/totalfreedom/utils/logging/FreedomLogger.java b/Patchwork/src/main/java/fns/patchwork/utils/logging/FreedomLogger.java similarity index 98% rename from Patchwork/src/main/java/me/totalfreedom/utils/logging/FreedomLogger.java rename to Patchwork/src/main/java/fns/patchwork/utils/logging/FreedomLogger.java index 97cec23..8630f28 100644 --- a/Patchwork/src/main/java/me/totalfreedom/utils/logging/FreedomLogger.java +++ b/Patchwork/src/main/java/fns/patchwork/utils/logging/FreedomLogger.java @@ -1,6 +1,7 @@ -package me.totalfreedom.utils.logging; +package fns.patchwork.utils.logging; -import me.totalfreedom.utils.kyori.FreedomAdventure; +import fns.patchwork.utils.kyori.FreedomAdventure; +import java.util.function.Supplier; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.chat.ChatType; import net.kyori.adventure.chat.SignedMessage; @@ -10,8 +11,6 @@ import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.function.Supplier; - public class FreedomLogger implements Audience { private final Logger logger; diff --git a/Patchwork/src/main/java/me/totalfreedom/base/Registration.java b/Patchwork/src/main/java/me/totalfreedom/base/Registration.java deleted file mode 100644 index e697fe9..0000000 --- a/Patchwork/src/main/java/me/totalfreedom/base/Registration.java +++ /dev/null @@ -1,104 +0,0 @@ -package me.totalfreedom.base; - -import me.totalfreedom.data.ConfigRegistry; -import me.totalfreedom.data.EventRegistry; -import me.totalfreedom.data.GroupRegistry; -import me.totalfreedom.data.ModuleRegistry; -import me.totalfreedom.data.ServiceTaskRegistry; -import me.totalfreedom.data.UserRegistry; - -/** - * This class is a holder for each registry in the data package. - *
- * Registries such as {@link ModuleRegistry} and {@link ServiceTaskRegistry} can be found as final objects in this - * class. These registries should only ever be accessed through the single Registration object in CommonsBase using - * {@link CommonsBase#getRegistrations()} - */ -public class Registration -{ - /** - * The {@link EventRegistry} - */ - private final EventRegistry eventRegistry; - /** - * The {@link UserRegistry} - */ - private final UserRegistry userRegistry; - /** - * The {@link ServiceTaskRegistry} - */ - private final ServiceTaskRegistry serviceTaskRegistry; - /** - * The {@link ModuleRegistry} - */ - private final ModuleRegistry moduleRegistry; - /** - * The {@link GroupRegistry} - */ - private final GroupRegistry groupRegistry; - /** - * The {@link ConfigRegistry} - */ - private final ConfigRegistry configRegistry; - - /** - * Constructs a new Registration object and initializes all registries. - */ - Registration() - { - this.eventRegistry = new EventRegistry(); - this.userRegistry = new UserRegistry(); - this.serviceTaskRegistry = new ServiceTaskRegistry(); - this.moduleRegistry = new ModuleRegistry(); - this.groupRegistry = new GroupRegistry(); - this.configRegistry = new ConfigRegistry(); - } - - /** - * @return The {@link ModuleRegistry} - */ - public ModuleRegistry getModuleRegistry() - { - return moduleRegistry; - } - - /** - * @return The {@link EventRegistry} - */ - public EventRegistry getEventRegistry() - { - return eventRegistry; - } - - /** - * @return The {@link UserRegistry} - */ - public UserRegistry getUserRegistry() - { - return userRegistry; - } - - /** - * @return The {@link ServiceTaskRegistry} - */ - public ServiceTaskRegistry getServiceTaskRegistry() - { - return serviceTaskRegistry; - } - - /** - * @return The {@link GroupRegistry} - */ - public GroupRegistry getGroupRegistry() - { - return groupRegistry; - } - - /** - * @return The {@link ConfigRegistry} - */ - public ConfigRegistry getConfigRegistry() - { - return configRegistry; - } -} diff --git a/Patchwork/src/main/java/me/totalfreedom/provider/ContextProvider.java b/Patchwork/src/main/java/me/totalfreedom/provider/ContextProvider.java deleted file mode 100644 index 680219d..0000000 --- a/Patchwork/src/main/java/me/totalfreedom/provider/ContextProvider.java +++ /dev/null @@ -1,139 +0,0 @@ -package me.totalfreedom.provider; - -import net.kyori.adventure.text.Component; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Objects; -import java.util.stream.Stream; - -public class ContextProvider -{ - public T fromString(final String string, final Class clazz) - { - return Stream.of(toBoolean(string), - toDouble(string), - toInt(string), - toLong(string), - toFloat(string), - toMaterial(string), - toPlayer(string), - toWorld(string), - toLocation(string), - toCommandSender(string), - toComponent(string)) - .filter(Objects::nonNull) - .findFirst() - .map(clazz::cast) - .orElse(null); - } - - private @Nullable Boolean toBoolean(final String string) - { - // Previously we used Boolean#parseBoolean, but that will always return a value and does not throw - // an exception. This means that if the string is not "true" or "false", it will return false. - if (string.equalsIgnoreCase("true")) return true; - if (string.equalsIgnoreCase("false")) return false; - - return null; - } - - private @Nullable Double toDouble(final String string) - { - try - { - return Double.parseDouble(string); - } catch (NumberFormatException ignored) - { - return null; - } - } - - private @Nullable Integer toInt(final String string) - { - try - { - return Integer.parseInt(string); - } catch (NumberFormatException ignored) - { - return null; - } - } - - private @Nullable Long toLong(final String string) - { - try - { - return Long.parseLong(string); - } catch (NumberFormatException ignored) - { - return null; - } - } - - private @Nullable Float toFloat(final String string) - { - try - { - return Float.parseFloat(string); - } catch (NumberFormatException ignored) - { - return null; - } - } - - private @Nullable Material toMaterial(final String string) - { - return Material.matchMaterial(string); - } - - private @Nullable Player toPlayer(final String string) - { - return Bukkit.getPlayer(string); - } - - private @Nullable World toWorld(final String string) - { - return Bukkit.getWorld(string); - } - - /** - * When using this method, the input string must be formatted as - *
- * worldName,x,y,z - *
- * - * @param string The string to parse - * @return A location object if xyz is valid - */ - private @Nullable Location toLocation(final String string) - { - final String[] split = string.split(","); - - if (split.length != 4 || toWorld(split[0]) == null) return null; - - final double x = Double.parseDouble(split[1]); - final double y = Double.parseDouble(split[2]); - final double z = Double.parseDouble(split[3]); - - return new Location(toWorld(split[0]), x, y, z); - } - - private @Nullable CommandSender toCommandSender(final String string) - { - if (toPlayer(string) == null) return null; - - return toPlayer(string); - } - - private @NotNull Component toComponent(final String string) - { - return Component.text(string); - } -} diff --git a/Patchwork/src/main/java/me/totalfreedom/utils/container/Trio.java b/Patchwork/src/main/java/me/totalfreedom/utils/container/Trio.java deleted file mode 100644 index 90bf673..0000000 --- a/Patchwork/src/main/java/me/totalfreedom/utils/container/Trio.java +++ /dev/null @@ -1,30 +0,0 @@ -package me.totalfreedom.utils.container; - -public final class Trio -{ - private final A a; - private final B b; - private final C c; - - public Trio(final A a, final B b, final C c) - { - this.a = a; - this.b = b; - this.c = c; - } - - public A getPrimary() - { - return a; - } - - public B getSecondary() - { - return b; - } - - public C getTertiary() - { - return c; - } -} diff --git a/Patchwork/src/main/java/me/totalfreedom/utils/container/UnaryTrio.java b/Patchwork/src/main/java/me/totalfreedom/utils/container/UnaryTrio.java deleted file mode 100644 index cf2e27f..0000000 --- a/Patchwork/src/main/java/me/totalfreedom/utils/container/UnaryTrio.java +++ /dev/null @@ -1,30 +0,0 @@ -package me.totalfreedom.utils.container; - -public class UnaryTrio -{ - private final T primary; - private final T secondary; - private final T tertiary; - - public UnaryTrio(final T primary, final T secondary, final T tertiary) - { - this.primary = primary; - this.secondary = secondary; - this.tertiary = tertiary; - } - - public T getPrimary() - { - return primary; - } - - public T getSecondary() - { - return secondary; - } - - public T getTertiary() - { - return tertiary; - } -} diff --git a/Patchwork/src/main/resources/plugin.yml b/Patchwork/src/main/resources/plugin.yml index 5cbde93..c51a0e3 100644 --- a/Patchwork/src/main/resources/plugin.yml +++ b/Patchwork/src/main/resources/plugin.yml @@ -1,5 +1,6 @@ name: Patchwork -main: me.totalfreedom.base.CommonsBase +main: fns.patchwork.base.Patchwork +api-version: 1.20 version: 1.0.0 author: TotalFreedom description: The Core of Freedom Network Suite \ No newline at end of file diff --git a/README.md b/README.md index af20c7d..5bcfe6e 100644 --- a/README.md +++ b/README.md @@ -42,18 +42,25 @@ ![Libraries.io dependency status for GitHub repo](https://img.shields.io/librariesio/github/AtlasMediaGroup/Freedom-Network-Suite?style=for-the-badge) ![TFM Used](https://img.shields.io/static/v1?label=TFM%20Code%20Used&message=0%25&color=red&style=for-the-badge&logo=tensorflow) -# ![Header Image](https://simplexdev.app/images/fns-content/fnslogo.png) +# -This is a proof of concept for a new suite of modules supported by a common library. +

+ FNS Banner +

+ +# + +This project is a collection of plugins supported by a common library designed for creative-based freedom servers (servers which grant generous amounts of permission nodes to all players.) This is designed to encompass the ideologies of a Freedom server, while maintaining full customization through modules. -This is a ground up rewrite of [TotalFreedomMod]. +Most modules are designed to be either optional or interchangable, except Patchwork (API) and Datura (Data Manager). These two are required to run any of the other modules. +This is NOT a ground up rewrite of [TotalFreedomMod]. This is a completely new project designed to be entirely ambiguous.

Honorable mention:
[](https://github.com/plexusorg/Plex) -This proof-of-concept also uses the following libraries: +This plugin suite also uses the following libraries: - [Google GSON] for Json interpretation - [Jetbrains Annotations] for additional compiler annotations @@ -71,10 +78,12 @@ This proof-of-concept also uses the following libraries: [](https://github.com/VideoGameSmash12)
[](https://github.com/allinkdev) +
+[](https://github.com/FlorianMichael) # To Do List -Patchwork: +Patchwork (API): - [x] Logging System - [x] SQL API @@ -88,16 +97,16 @@ Patchwork: - [ ] Configuration API *(In Progress...)* - [ ] Event API *(In Progress...)* -Datura: +Datura (Data Manager): -- [ ] Permission Handling *(In Progress...)* -- [ ] Permission Registration & Assignment *(In Progress...)* +- [x] Permission Handling +- [x] Permission Registration & Assignment - [ ] SQL Data Handling *(In Progress...)* - [ ] Configuration Implementations - [ ] User Data Implementations *(In Progress...)* - [x] Punishment Systems (e.x. Locker, Halter, Cager) -Fossil: +Fossil (Entertainment): - [x] Economy Implementation - [ ] Particle Implementation / Trails *(In Progress...)* @@ -106,7 +115,7 @@ Fossil: - [ ] Chat reaction / game system - [ ] Jumppads -Corvo: +Corvo (Scheduling and Listening Service): - [ ] Service Implementation - [ ] Service Handling diff --git a/build.gradle b/build.gradle index f6090f2..5c91798 100644 --- a/build.gradle +++ b/build.gradle @@ -59,6 +59,12 @@ subprojects { weight = 0 } } + + javadoc { + options { + encoding = 'UTF-8' + } + } } tasks.register('buildChain') { diff --git a/codestyle.xml b/codestyle.xml new file mode 100644 index 0000000..a18269e --- /dev/null +++ b/codestyle.xml @@ -0,0 +1,73 @@ + + \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 249e583..033e24c 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 39d04d3..9f4197d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ -#Thu Apr 13 15:32:14 CDT 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c787..fcb6fca 100755 --- a/gradlew +++ b/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +80,10 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,22 +130,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,6 +197,10 @@ if "$cygwin" || "$msys" ; then done fi + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + # Collect all arguments for the java command; # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of # shell script including quotes and variable substitutions, so put them in @@ -205,6 +213,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index 107acd3..93e3f59 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal