diff --git a/Datura/src/main/java/me/totalfreedom/datura/cmd/ClearDropsCommand.java b/Datura/src/main/java/me/totalfreedom/datura/cmd/ClearDropsCommand.java new file mode 100644 index 0000000..495d2ed --- /dev/null +++ b/Datura/src/main/java/me/totalfreedom/datura/cmd/ClearDropsCommand.java @@ -0,0 +1,94 @@ +package me.totalfreedom.datura.cmd; + + +import me.totalfreedom.base.Patchwork; +import me.totalfreedom.base.Shortcuts; +import me.totalfreedom.command.Commander; +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 me.totalfreedom.datura.Datura; +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"}) +@Permissive(perm = "datura.cleardrops") +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. + */ + protected 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; + Patchwork.getInstance() + .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}) + @Completion(index = 0, args = {"%world%"}) + public void clearDrops(final CommandSender sender, final World world) + { + Patchwork.getInstance() + .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/me/totalfreedom/datura/cmd/ClearEntitiesCommand.java b/Datura/src/main/java/me/totalfreedom/datura/cmd/ClearEntitiesCommand.java new file mode 100644 index 0000000..9868235 --- /dev/null +++ b/Datura/src/main/java/me/totalfreedom/datura/cmd/ClearEntitiesCommand.java @@ -0,0 +1,69 @@ +package me.totalfreedom.datura.cmd; + +import me.totalfreedom.command.Commander; +import me.totalfreedom.command.annotation.Base; +import me.totalfreedom.command.annotation.Completion; +import me.totalfreedom.command.annotation.Subcommand; +import me.totalfreedom.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; + +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. + */ + protected 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}) + @Completion(index = 0, args = {"%world%"}) + 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/Patchwork/src/main/java/me/totalfreedom/utils/Tagged.java b/Patchwork/src/main/java/me/totalfreedom/utils/Tagged.java new file mode 100644 index 0000000..568233e --- /dev/null +++ b/Patchwork/src/main/java/me/totalfreedom/utils/Tagged.java @@ -0,0 +1,99 @@ +package me.totalfreedom.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 tagged; + + private Tagged(final T... tagged) + { + this.tagged = new ArrayList<>(); + } + + public boolean isTagged(final @NotNull T object) + { + for (final T t : this.tagged) + { + if (object.equals(t)) + return true; + } + return false; + } +} diff --git a/Patchwork/src/main/java/me/totalfreedom/utils/container/Trio.java b/Patchwork/src/main/java/me/totalfreedom/utils/container/Trio.java index 90bf673..e3d61c2 100644 --- a/Patchwork/src/main/java/me/totalfreedom/utils/container/Trio.java +++ b/Patchwork/src/main/java/me/totalfreedom/utils/container/Trio.java @@ -1,30 +1,5 @@ package me.totalfreedom.utils.container; -public final class Trio +public record Trio(A primary, B secondary, C tertiary) { - 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/UnaryPair.java b/Patchwork/src/main/java/me/totalfreedom/utils/container/UnaryPair.java new file mode 100644 index 0000000..908cccf --- /dev/null +++ b/Patchwork/src/main/java/me/totalfreedom/utils/container/UnaryPair.java @@ -0,0 +1,5 @@ +package me.totalfreedom.utils.container; + +public record UnaryPair(T first, T second) +{ +} diff --git a/Patchwork/src/main/java/me/totalfreedom/utils/container/UnaryTrio.java b/Patchwork/src/main/java/me/totalfreedom/utils/container/UnaryTrio.java index cf2e27f..ac455cd 100644 --- a/Patchwork/src/main/java/me/totalfreedom/utils/container/UnaryTrio.java +++ b/Patchwork/src/main/java/me/totalfreedom/utils/container/UnaryTrio.java @@ -1,30 +1,5 @@ package me.totalfreedom.utils.container; -public class UnaryTrio +public record UnaryTrio(T primary, T secondary, T tertiary) { - 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/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