From d03cb64c0297cccab453734917ada02150ccd561 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Wed, 8 Apr 2020 20:33:10 +0200 Subject: [PATCH] Removed /sf elevator --- .../core/commands/subcommands/Commands.java | 1 - .../commands/subcommands/ElevatorCommand.java | 66 ------------------- .../items/gps/ElevatorPlate.java | 21 ++++-- 3 files changed, 17 insertions(+), 71 deletions(-) delete mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ElevatorCommand.java diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/Commands.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/Commands.java index dc25b37d5..9e7c5894b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/Commands.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/Commands.java @@ -25,6 +25,5 @@ public final class Commands { commands.add(new OpenGuideCommand(plugin, cmd)); commands.add(new SearchCommand(plugin, cmd)); commands.add(new DebugFishCommand(plugin, cmd)); - commands.add(new ElevatorCommand(plugin, cmd)); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ElevatorCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ElevatorCommand.java deleted file mode 100644 index 38f3f32c4..000000000 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/ElevatorCommand.java +++ /dev/null @@ -1,66 +0,0 @@ -package io.github.thebusybiscuit.slimefun4.core.commands.subcommands; - -import java.util.Map; - -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import io.github.thebusybiscuit.cscorelib2.chat.ChatColors; -import io.github.thebusybiscuit.slimefun4.core.commands.SlimefunCommand; -import io.github.thebusybiscuit.slimefun4.core.commands.SubCommand; -import io.github.thebusybiscuit.slimefun4.implementation.items.gps.ElevatorPlate; -import me.mrCookieSlime.Slimefun.SlimefunPlugin; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.api.BlockStorage; - -class ElevatorCommand extends SubCommand { - - private final ElevatorPlate elevatorPlate; - - ElevatorCommand(SlimefunPlugin plugin, SlimefunCommand cmd) { - super(plugin, cmd); - - elevatorPlate = ((ElevatorPlate) SlimefunItem.getByID("ELEVATOR_PLATE")); - } - - @Override - public void recordUsage(Map commandUsage) { - // This command is only for internal purposes, we do not wanna record the - // usage of this one. - } - - @Override - public String getName() { - return "elevator"; - } - - @Override - public boolean isHidden() { - return true; - } - - @Override - public void onExecute(CommandSender sender, String[] args) { - if (sender instanceof Player && args.length == 4) { - Player p = (Player) sender; - - int x = Integer.parseInt(args[1]); - int y = Integer.parseInt(args[2]); - int z = Integer.parseInt(args[3]); - - if (BlockStorage.getLocationInfo(p.getWorld().getBlockAt(x, y, z).getLocation(), "floor") != null) { - elevatorPlate.getUsers().add(p.getUniqueId()); - float yaw = p.getEyeLocation().getYaw() + 180; - if (yaw > 180) yaw = -180 + (yaw - 180); - - p.teleport(new Location(p.getWorld(), x + 0.5, y + 0.4, z + 0.5, yaw, p.getEyeLocation().getPitch())); - - String floor = BlockStorage.getLocationInfo(p.getWorld().getBlockAt(x, y, z).getLocation(), "floor"); - p.sendTitle(ChatColor.RESET + ChatColors.color(floor), " ", 20, 60, 20); - } - } - } - -} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/ElevatorPlate.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/ElevatorPlate.java index 01bce2dff..ee9840d7e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/ElevatorPlate.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/ElevatorPlate.java @@ -7,7 +7,9 @@ import java.util.Set; import java.util.UUID; import org.bukkit.ChatColor; +import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -15,7 +17,6 @@ import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.chat.ChatColors; import io.github.thebusybiscuit.cscorelib2.chat.json.ChatComponent; import io.github.thebusybiscuit.cscorelib2.chat.json.ClickEvent; -import io.github.thebusybiscuit.cscorelib2.chat.json.ClickEventAction; import io.github.thebusybiscuit.cscorelib2.chat.json.CustomBookInterface; import io.github.thebusybiscuit.cscorelib2.chat.json.HoverEvent; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; @@ -35,6 +36,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; public class ElevatorPlate extends SimpleSlimefunItem { private final Set users = new HashSet<>(); + private final NamespacedKey elevatorKey = new NamespacedKey(SlimefunPlugin.instance, "elevator"); public ElevatorPlate(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) { super(category, item, recipeType, recipe, recipeOutput); @@ -115,12 +117,23 @@ public class ElevatorPlate extends SimpleSlimefunItem { if (block.getY() == b.getY()) { line = new ChatComponent("\n" + ChatColor.GRAY + "> " + (floors.size() - i) + ". " + ChatColor.RESET + floor); - line.setHoverEvent(new HoverEvent(ChatColors.color(SlimefunPlugin.getLocal().getMessage(p, "machines.ELEVATOR.current-floor")), ChatColor.RESET + floor, "")); + line.setHoverEvent(new HoverEvent(ChatColor.RESET + floor, "", ChatColors.color(SlimefunPlugin.getLocal().getMessage(p, "machines.ELEVATOR.current-floor")), ChatColor.RESET + floor, "")); } else { line = new ChatComponent("\n" + ChatColor.GRAY.toString() + (floors.size() - i) + ". " + ChatColor.RESET + floor); - line.setHoverEvent(new HoverEvent(ChatColors.color(SlimefunPlugin.getLocal().getMessage(p, "machines.ELEVATOR.click-to-teleport")), ChatColor.RESET + floor, "")); - line.setClickEvent(new ClickEvent(ClickEventAction.RUN_COMMAND, "/sf elevator " + block.getX() + ' ' + block.getY() + ' ' + block.getZ() + " ")); + line.setHoverEvent(new HoverEvent(ChatColor.RESET + floor, "", ChatColors.color(SlimefunPlugin.getLocal().getMessage(p, "machines.ELEVATOR.click-to-teleport")), ChatColor.RESET + floor, "")); + line.setClickEvent(new ClickEvent(elevatorKey, player -> { + users.add(player.getUniqueId()); + + float yaw = player.getEyeLocation().getYaw() + 180; + + if (yaw > 180) { + yaw = -180 + (yaw - 180); + } + + player.teleport(new Location(player.getWorld(), block.getX() + 0.5, block.getY() + 0.4, block.getZ() + 0.5, yaw, player.getEyeLocation().getPitch())); + player.sendTitle(ChatColor.RESET + ChatColors.color(floor), " ", 20, 60, 20); + })); } page.append(line);