From c8e582ec61872aa2ab602f97f38b1786eb2f5305 Mon Sep 17 00:00:00 2001 From: BenceX100 Date: Tue, 8 Oct 2024 20:15:29 +0200 Subject: [PATCH] 1.14.3 --- pom.xml | 4 +-- .../axgraves/commands/Commands.java | 14 +++------- .../commands/subcommands/SubCommandList.java | 3 ++- .../subcommands/SubCommandReload.java | 4 +-- .../subcommands/SubCommandTeleport.java | 27 +++++++++++++++++++ .../artillexstudios/axgraves/utils/Utils.java | 7 ++--- 6 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 src/main/java/com/artillexstudios/axgraves/commands/subcommands/SubCommandTeleport.java diff --git a/pom.xml b/pom.xml index 416696d..3bc3d7d 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.artillexstudios AxGraves - 1.14.2 + 1.14.3 jar AxGraves @@ -106,7 +106,7 @@ com.artillexstudios.axapi axapi - 1.4.332 + 1.4.380 compile all diff --git a/src/main/java/com/artillexstudios/axgraves/commands/Commands.java b/src/main/java/com/artillexstudios/axgraves/commands/Commands.java index c150fcc..37f0a0b 100644 --- a/src/main/java/com/artillexstudios/axgraves/commands/Commands.java +++ b/src/main/java/com/artillexstudios/axgraves/commands/Commands.java @@ -1,11 +1,9 @@ package com.artillexstudios.axgraves.commands; -import com.artillexstudios.axapi.utils.PaperUtils; import com.artillexstudios.axapi.utils.StringUtils; import com.artillexstudios.axgraves.commands.subcommands.SubCommandList; import com.artillexstudios.axgraves.commands.subcommands.SubCommandReload; -import com.artillexstudios.axgraves.grave.SpawnedGraves; -import org.bukkit.Location; +import com.artillexstudios.axgraves.commands.subcommands.SubCommandTeleport; import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -31,22 +29,18 @@ public void help(@NotNull CommandSender sender) { @Subcommand("reload") @CommandPermission("axgraves.reload") public void reload(@NotNull CommandSender sender) { - new SubCommandReload().subCommand(sender); + SubCommandReload.INSTANCE.subCommand(sender); } @Subcommand("list") @CommandPermission("axgraves.list") public void list(@NotNull CommandSender sender) { - new SubCommandList().subCommand(sender); + SubCommandList.INSTANCE.subCommand(sender); } @Subcommand("tp") @CommandPermission("axgraves.tp") public void tp(@NotNull Player sender, World world, double x, double y, double z) { - final Location location = new Location(world, x, y, z); - if (!sender.hasPermission("axgraves.tp.bypass") && SpawnedGraves.getGraves().stream().filter(grave -> grave.getPlayer().getUniqueId().equals(sender.getUniqueId())).filter(grave -> grave.getLocation().equals(location)).findAny().isEmpty()) { - return; - } - PaperUtils.teleportAsync(sender, location); + SubCommandTeleport.INSTANCE.subCommand(sender, world, x, y, z); } } diff --git a/src/main/java/com/artillexstudios/axgraves/commands/subcommands/SubCommandList.java b/src/main/java/com/artillexstudios/axgraves/commands/subcommands/SubCommandList.java index 986d6b1..75ab561 100644 --- a/src/main/java/com/artillexstudios/axgraves/commands/subcommands/SubCommandList.java +++ b/src/main/java/com/artillexstudios/axgraves/commands/subcommands/SubCommandList.java @@ -18,7 +18,8 @@ import static com.artillexstudios.axgraves.AxGraves.MESSAGES; import static com.artillexstudios.axgraves.AxGraves.MESSAGEUTILS; -public class SubCommandList { +public enum SubCommandList { + INSTANCE; public void subCommand(@NotNull CommandSender sender) { if (SpawnedGraves.getGraves().isEmpty()) { diff --git a/src/main/java/com/artillexstudios/axgraves/commands/subcommands/SubCommandReload.java b/src/main/java/com/artillexstudios/axgraves/commands/subcommands/SubCommandReload.java index 3a15876..81a5734 100644 --- a/src/main/java/com/artillexstudios/axgraves/commands/subcommands/SubCommandReload.java +++ b/src/main/java/com/artillexstudios/axgraves/commands/subcommands/SubCommandReload.java @@ -13,10 +13,10 @@ import static com.artillexstudios.axgraves.AxGraves.MESSAGES; import static com.artillexstudios.axgraves.AxGraves.MESSAGEUTILS; -public class SubCommandReload { +public enum SubCommandReload { + INSTANCE; public void subCommand(@NotNull CommandSender sender) { - final String errorMsg = CONFIG.getString("prefix") + MESSAGES.getString("reload.failed"); if (!CONFIG.reload()) { diff --git a/src/main/java/com/artillexstudios/axgraves/commands/subcommands/SubCommandTeleport.java b/src/main/java/com/artillexstudios/axgraves/commands/subcommands/SubCommandTeleport.java new file mode 100644 index 0000000..ccdc612 --- /dev/null +++ b/src/main/java/com/artillexstudios/axgraves/commands/subcommands/SubCommandTeleport.java @@ -0,0 +1,27 @@ +package com.artillexstudios.axgraves.commands.subcommands; + +import com.artillexstudios.axapi.utils.PaperUtils; +import com.artillexstudios.axgraves.grave.Grave; +import com.artillexstudios.axgraves.grave.SpawnedGraves; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.Optional; + +public enum SubCommandTeleport { + INSTANCE; + + public void subCommand(@NotNull Player sender, World world, double x, double y, double z) { + final Location location = new Location(world, x, y, z); + + Optional foundGrave = SpawnedGraves.getGraves().stream() + .filter(grave -> grave.getPlayer().getUniqueId().equals(sender.getUniqueId())) + .filter(grave -> grave.getLocation().distanceSquared(location) < 1) + .findAny(); + + if (!sender.hasPermission("axgraves.tp.bypass") && foundGrave.isEmpty()) return; + PaperUtils.teleportAsync(sender, foundGrave.isEmpty() ? location : foundGrave.get().getLocation()); + } +} diff --git a/src/main/java/com/artillexstudios/axgraves/utils/Utils.java b/src/main/java/com/artillexstudios/axgraves/utils/Utils.java index cbd72d6..b5ad2b4 100644 --- a/src/main/java/com/artillexstudios/axgraves/utils/Utils.java +++ b/src/main/java/com/artillexstudios/axgraves/utils/Utils.java @@ -11,9 +11,10 @@ public class Utils { @NotNull public static ItemStack getPlayerHead(@NotNull OfflinePlayer player) { final ItemStack it = new ItemStack(Material.PLAYER_HEAD); - final SkullMeta skullMeta = (SkullMeta) it.getItemMeta(); - skullMeta.setOwningPlayer(player); - it.setItemMeta(skullMeta); + if (it.getItemMeta() instanceof SkullMeta skullMeta) { + skullMeta.setOwningPlayer(player); + it.setItemMeta(skullMeta); + } return it; }