From 394f22bbfb989d07196bd9245f511a8f47d03d22 Mon Sep 17 00:00:00 2001 From: ChomeNS Date: Mon, 20 Mar 2023 13:21:08 +0700 Subject: [PATCH] add random tp EASIEST COMMAND EVER TO MAKE !! actually its prob test but whatever lol --- .../commands/RandomTeleportCommand.java | 62 +++++++++++++++++++ .../plugins/CommandHandlerPlugin.java | 1 + .../chomensbot_mabe/util/NumberUtilities.java | 9 +++ .../chomensbot_mabe/util/UUIDUtilities.java | 8 --- 4 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 src/main/java/me/chayapak1/chomensbot_mabe/commands/RandomTeleportCommand.java create mode 100644 src/main/java/me/chayapak1/chomensbot_mabe/util/NumberUtilities.java diff --git a/src/main/java/me/chayapak1/chomensbot_mabe/commands/RandomTeleportCommand.java b/src/main/java/me/chayapak1/chomensbot_mabe/commands/RandomTeleportCommand.java new file mode 100644 index 0000000..96015be --- /dev/null +++ b/src/main/java/me/chayapak1/chomensbot_mabe/commands/RandomTeleportCommand.java @@ -0,0 +1,62 @@ +package me.chayapak1.chomensbot_mabe.commands; + +import me.chayapak1.chomensbot_mabe.Bot; +import me.chayapak1.chomensbot_mabe.command.Command; +import me.chayapak1.chomensbot_mabe.command.CommandContext; +import me.chayapak1.chomensbot_mabe.util.ComponentUtilities; +import me.chayapak1.chomensbot_mabe.util.NumberUtilities; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; + +import java.util.ArrayList; +import java.util.List; + +public class RandomTeleportCommand implements Command { + public String name() { return "rtp"; } + + public String description() { + return "Randomly teleports you"; + } + + public List usage() { + final List usages = new ArrayList<>(); + usages.add(""); + + return usages; + } + + public List alias() { + final List aliases = new ArrayList<>(); + aliases.add("randomteleport"); + + return aliases; + } + + public int trustLevel() { + return 0; + } + + public Component execute(CommandContext context, String[] args, String[] fullArgs) { + final Bot bot = context.bot(); + + final String stringDisplayName = ComponentUtilities.stringify(context.displayName()); + + final int positionX = NumberUtilities.between(1_000, 10_000); + final int positionZ = NumberUtilities.between(1_000, 10_000); + final String stringPosition = positionX + " 100 " + positionZ; // very 100 y + + context.sendOutput( + Component.empty() + .append(Component.text("Teleporting ")) + .append(context.displayName().color(NamedTextColor.AQUA)) + .append(Component.text(" to ").color(NamedTextColor.WHITE)) + .append(Component.text(stringPosition).color(NamedTextColor.GREEN)) + .append(Component.text("...").color(NamedTextColor.WHITE)) + ); + + // TODO: Use UUID instead of display name because it is a bad idea!!11 + bot.core().run("essentials:teleport " + stringDisplayName + " " + stringPosition); + + return Component.text("success"); + } +} diff --git a/src/main/java/me/chayapak1/chomensbot_mabe/plugins/CommandHandlerPlugin.java b/src/main/java/me/chayapak1/chomensbot_mabe/plugins/CommandHandlerPlugin.java index ae80574..edae546 100644 --- a/src/main/java/me/chayapak1/chomensbot_mabe/plugins/CommandHandlerPlugin.java +++ b/src/main/java/me/chayapak1/chomensbot_mabe/plugins/CommandHandlerPlugin.java @@ -28,6 +28,7 @@ public class CommandHandlerPlugin { registerCommand(new ThrowCommand()); registerCommand(new ValidateCommand()); registerCommand(new MusicCommand()); + registerCommand(new RandomTeleportCommand()); } public void registerCommand (Command command) { diff --git a/src/main/java/me/chayapak1/chomensbot_mabe/util/NumberUtilities.java b/src/main/java/me/chayapak1/chomensbot_mabe/util/NumberUtilities.java new file mode 100644 index 0000000..2a3500e --- /dev/null +++ b/src/main/java/me/chayapak1/chomensbot_mabe/util/NumberUtilities.java @@ -0,0 +1,9 @@ +package me.chayapak1.chomensbot_mabe.util; + +public class NumberUtilities { + public static int between (int min, int max) { + return (int) Math.floor( + Math.random() * (max - min) + min + ); + } +} diff --git a/src/main/java/me/chayapak1/chomensbot_mabe/util/UUIDUtilities.java b/src/main/java/me/chayapak1/chomensbot_mabe/util/UUIDUtilities.java index ef5c0b7..64fd98d 100644 --- a/src/main/java/me/chayapak1/chomensbot_mabe/util/UUIDUtilities.java +++ b/src/main/java/me/chayapak1/chomensbot_mabe/util/UUIDUtilities.java @@ -18,14 +18,6 @@ public class UUIDUtilities { return intArray; } - public static UUID byString (String string, int version) { - UUID uuid = UUID.nameUUIDFromBytes(string.getBytes()); - uuid = new UUID(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits() & ~(0xfL << 12)); - uuid = new UUID(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits() | ((long) version << 12)); - - return uuid; - } - public static IntArrayTag tag (UUID uuid) { return new IntArrayTag("", intArray(uuid)); }