From 3fdf2aff92dffed0c632351018576f37bc50e6b6 Mon Sep 17 00:00:00 2001 From: stijnb1234 Date: Sat, 26 Sep 2020 14:30:32 +0200 Subject: [PATCH] Added timer command, bump to v2.1.2 --- pom.xml | 2 +- .../themeparkplus/commands/TPPCMD.java | 42 +++++++++++++++++++ src/main/resources/messages.yml | 4 +- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index e7d7b0e..76d28f7 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ nl.SBDeveloper ThemeParkPlus - 2.1.1 + 2.1.2 jar ThemeParkPlus diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/commands/TPPCMD.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/commands/TPPCMD.java index ac55e0e..e40c6a9 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/commands/TPPCMD.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/commands/TPPCMD.java @@ -9,8 +9,10 @@ import nl.sbdeveloper.themeparkplus.api.objects.Gate; import nl.sbdeveloper.themeparkplus.util.ConfigUtil; import nl.sbdeveloper.themeparkplus.util.Cuboid; import nl.sbdeveloper.themeparkplus.util.LGUtil; +import nl.sbdeveloper.themeparkplus.util.XMaterial; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.command.Command; @@ -21,6 +23,7 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import java.util.Collections; +import java.util.HashMap; public class TPPCMD implements CommandExecutor { @@ -146,10 +149,47 @@ public class TPPCMD implements CommandExecutor { return true; } return giveFPTicketCommand(sender, args); + } else if (args[0].equalsIgnoreCase("redstonetimer") && (args.length == 6 || args.length == 7)) { + if (!sender.hasPermission("tpp.redstonetimer")) { + sender.sendMessage(ConfigUtil.getMessage("General.NoPermission")); + return true; + } + return redstoneTimerCommand(sender, args); } return helpCommand(sender); } + private boolean redstoneTimerCommand(CommandSender sender, String[] args) { + World bworld = Bukkit.getWorld(args[1]); + double bx = Double.parseDouble(args[2]); + double by = Double.parseDouble(args[3]); + double bz = Double.parseDouble(args[4]); + Location loc = new Location(bworld, bx, by, bz); + + long onDelayTicks = Long.parseLong(args[5]) * 20L; + long offDelayTicks = args.length == 7 ? Long.parseLong(args[6]) * 20L : 20L; + + Block block = loc.getBlock(); + Material oldMaterial = block.getType(); + byte oldData = block.getData(); + Material redstoneMaterial = XMaterial.REDSTONE_BLOCK.parseMaterial(); + + if (redstoneMaterial == null) throw new IllegalArgumentException("Redstone Material not found."); + + Bukkit.getScheduler().scheduleSyncDelayedTask(ThemeParkPlus.getInstance(), () -> { + block.setType(redstoneMaterial); + if (!XMaterial.isNewVersion()) block.getState().setRawData(oldData); //LEGACY + Bukkit.getScheduler().scheduleSyncDelayedTask(ThemeParkPlus.getInstance(), () -> block.setType(oldMaterial), offDelayTicks); + }, onDelayTicks); + + HashMap replacements = new HashMap<>(); + replacements.put("%sec1%", args[5]); + replacements.put("%sec2%", args[6]); + + sender.sendMessage(ConfigUtil.getMessage("RedstoneTimer.Started", replacements)); + return true; + } + private boolean giveFPTicketCommand(CommandSender sender, String[] args) { if (args.length == 2 && !(sender instanceof Player)) { sender.sendMessage(ConfigUtil.getMessage("General.NoPlayer")); @@ -205,6 +245,8 @@ public class TPPCMD implements CommandExecutor { sender.sendMessage("§6/themeparkplus lampson [Seconds on]§f: Turn multiple lamps on."); sender.sendMessage("§6/themeparkplus lampsoff §f: Turn multiple lamps off."); sender.sendMessage(" "); + sender.sendMessage("§6/themeparkplus redstonetimer [Off Delay] §f: Create a Redstone delayer."); + sender.sendMessage(" "); sender.sendMessage("§6/themeparkplus givefpticket [Player]§f: Give yourself or someone else a Fastpass ticket (for free)."); return true; } diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 2fc85bc..402fde3 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -35,4 +35,6 @@ Lamps: TurnedOff: '&aLamps in region turned off!' WaitingRow: SignCreated: '&aYou''ve successfully created a waitingrow sign!' - WrongLocation: '&cA waitingrow sign (from the attraction %ridename%) couldn''t be found! It will be deleted.' \ No newline at end of file + WrongLocation: '&cA waitingrow sign (from the attraction %ridename%) couldn''t be found! It will be deleted.' +RedstoneTimer: + Started: '&aThe timer successfully started. It will go off in &f%sec1% &asecond(s), and will turn off in &f%sec2% &asecond(s) after that.' \ No newline at end of file