From e8ea32d4f198e1e1b4698551fceebfb281ceae13 Mon Sep 17 00:00:00 2001 From: PMFRTT <37709302+PMFRTT@users.noreply.github.com> Date: Thu, 1 Apr 2021 16:09:50 +0200 Subject: [PATCH] bump version to 16.5.30 --- ...igotmc_spigot_api_1_16_5_R0_1_SNAPSHOT.xml | 6 +- pom.xml | 2 +- src/main/java/bingo/BingoPlugin.java | 29 +++++---- src/main/java/bingo/BingoSettings.java | 64 ++++++++++++++++--- src/main/java/bingo/Utils.java | 31 +++++---- .../commandExecutor/BingoCommandExecutor.java | 14 +++- .../java/bingo/teleporter/Teleporter.java | 59 +++++++++++++++++ .../bingo/teleporter/TeleporterTimer.java | 5 +- 8 files changed, 166 insertions(+), 44 deletions(-) diff --git a/.idea/libraries/Maven__org_spigotmc_spigot_api_1_16_5_R0_1_SNAPSHOT.xml b/.idea/libraries/Maven__org_spigotmc_spigot_api_1_16_5_R0_1_SNAPSHOT.xml index ad9ecf3..5e13f7e 100644 --- a/.idea/libraries/Maven__org_spigotmc_spigot_api_1_16_5_R0_1_SNAPSHOT.xml +++ b/.idea/libraries/Maven__org_spigotmc_spigot_api_1_16_5_R0_1_SNAPSHOT.xml @@ -1,13 +1,13 @@ - + - + - + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 2c5fe2c..0985fca 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ Bingo Bingo - 16.5.30-dev + 16.5.30 jar Bingo diff --git a/src/main/java/bingo/BingoPlugin.java b/src/main/java/bingo/BingoPlugin.java index dbc9241..081c770 100644 --- a/src/main/java/bingo/BingoPlugin.java +++ b/src/main/java/bingo/BingoPlugin.java @@ -5,6 +5,7 @@ import bingo.commandExecutor.TopCommandExecutor; import bingo.eventhandler.BingoEventhandler; import bingo.eventhandler.CheckInventory; +import bingo.teleporter.Teleporter; import core.core.CoreMain; import core.Utils; import core.timer.Timer; @@ -20,19 +21,21 @@ public final class BingoPlugin extends JavaPlugin { - private final BingoEventhandler bingoEventhandler = new BingoEventhandler(this); private static BingoSettings bingoSettings; - private int difficulty = 0; + private static int difficulty = 0; + private static Timer timer; + public static int items = 0; public static SideList sideList; - private static Timer timer; public static boolean scatter; + public static boolean tpEnabled = false; @Override public void onEnable() { CoreMain.setPlugin(this); timer = new Timer(this, TimerType.INCREASING, "Das Bingo läuft seit: &b", "&cDas Bingo ist pausiert", false); + BingoEventhandler bingoEventhandler = new BingoEventhandler(this); bingoEventhandler.initialize(); bingoSettings = new BingoSettings(this); BingoCommandExecutor bingoCommandExecutor = new BingoCommandExecutor(this); @@ -72,17 +75,15 @@ public void startBingo() { SettingCycle items = (SettingCycle) bingoSettings.getSettingbyName("Items"); SettingSwitch keepInventory = (SettingSwitch) bingoSettings.getSettingbyName("Keep Inventory"); SettingSwitch singlePlayer = (SettingSwitch) bingoSettings.getSettingbyName("Singleplayer"); - SettingSwitch advancements = (SettingSwitch) bingoSettings.getSettingbyName("Announce Advancements"); SettingSwitch scatter = (SettingSwitch) bingoSettings.getSettingbyName("Scatter Players"); SettingCycle singlePlayerStartTime = (SettingCycle) bingoSettings.singlePlayerSubSettings.getSettingbyName("Start-Zeit"); SettingCycle scatterPlayerSize = (SettingCycle) bingoSettings.scatterPlayerSubSettings.getSettingbyName("Scatter-Größe"); + SettingCycle teleportTime = (SettingCycle) bingoSettings.teleporterSubSettings.getSettingbyName("Countdown-Zeit"); + SettingCycle teleportRange = (SettingCycle) bingoSettings.teleporterSubSettings.getSettingbyName("Teleporter-Radius"); + SettingSwitch enabletp = (SettingSwitch) bingoSettings.getSettingbyName("Teleporter"); this.difficulty = difficulty.getValue(); - this.scatter = scatter.getSettingValue(); - if (advancements.getSettingValue()) { - Utils.changeGamerule(GameRule.ANNOUNCE_ADVANCEMENTS, true); - } else { - Utils.changeGamerule(GameRule.ANNOUNCE_ADVANCEMENTS, false); - } + tpEnabled = enabletp.getSettingValue(); + BingoPlugin.scatter = scatter.getSettingValue(); boolean singleplayer = singlePlayer.getSettingValue(); if (keepInventory.getSettingValue()) { Utils.changeGamerule(GameRule.KEEP_INVENTORY, true); @@ -92,10 +93,16 @@ public void startBingo() { timer.setSeconds(singlePlayerStartTime.getValue()); timer.setSingle(true); } - this.items = items.getValue(); + BingoPlugin.items = items.getValue(); + int teleporterRadius = teleportRange.getValue(); + int teleporterTime = teleportTime.getValue(); BingoList.populatePlayerBingoList(difficulty.getValue(), items.getValue()); bingo.Utils.preparePlayers(scatterPlayerSize.getValue()); sideList.init(); + if (enabletp.getSettingValue()) { + Teleporter teleporter = new Teleporter(this, true, teleporterTime, teleporterRadius); + teleporter.init(); + } timer.resume(); } diff --git a/src/main/java/bingo/BingoSettings.java b/src/main/java/bingo/BingoSettings.java index 97a2207..a768501 100644 --- a/src/main/java/bingo/BingoSettings.java +++ b/src/main/java/bingo/BingoSettings.java @@ -64,11 +64,11 @@ private void addSettings() { add(Utils.colorize("&7ihre Items &cverlieren &7oder &abehalten")); }}, Material.ENDER_EYE, false); - this.addSetting("Announce Advancements", new ArrayList() {{ + /*this.addSetting("Announce Advancements", new ArrayList() {{ add(Utils.colorize("&7Legt fest, ob Gegenspieler im")); add(Utils.colorize("&7Chat erfahren, dass ein")); add(Utils.colorize("&6Advancement erreicht &7wurde")); - }}, Material.NOTE_BLOCK, false); + }}, Material.NOTE_BLOCK, false);*/ this.addSetting("Scatter Players", new ArrayList() {{ add(Utils.colorize("&7Legt fest, ob Spieler")); @@ -80,7 +80,7 @@ private void addSettings() { scatterPlayerSubSettings.addSetting("Scatter-Größe", new ArrayList() {{ add(Utils.colorize("&7Hier kannst du einstellen,")); - add(Utils.colorize("&7wie &6groß der Radius&7 des ")); + add(Utils.colorize("&7wie groß der &6Radius&7 des ")); add(Utils.colorize("&7Scatterns sein soll")); }}, Material.CARTOGRAPHY_TABLE, new ArrayList() {{ add(100); @@ -112,13 +112,6 @@ private void addSettings() { add(Utils.colorize("&8Shift + Rechtsclick -> Einstellungen")); }}, Material.TOTEM_OF_UNDYING, false, singlePlayerSubSettings); - this.addSetting("Teleporter", new ArrayList() {{ - add(Utils.colorize("&7Ermöglicht dem Spieler sich")); - add(Utils.colorize("&7entweder einmalig oder mit einem")); - add(Utils.colorize("&7Countdown zu &ateleportieren!")); - add(Utils.colorize("&8Shift + Rechtsclick -> Einstellungen")); - }}, Material.ENDERMAN_SPAWN_EGG, false, teleporterSubSettings); - singlePlayerSubSettings.addSetting("Start-Zeit", new ArrayList() {{ add(core.Utils.colorize("&7Hier kannst du einstellen, mit wie")); add(core.Utils.colorize("&7viel &6Zeit &7du in dem")); @@ -147,6 +140,57 @@ private void addSettings() { add(Utils.colorize("&a10 Minuten")); }}); + this.addSetting("Teleporter", new ArrayList() {{ + add(Utils.colorize("&7Ermöglicht dem Spieler sich")); + add(Utils.colorize("&7entweder einmalig oder mit einem")); + add(Utils.colorize("&7Countdown zu &ateleportieren!")); + add(Utils.colorize("&8Shift + Rechtsclick -> Einstellungen")); + }}, Material.ENDERMAN_SPAWN_EGG, false, teleporterSubSettings); + + teleporterSubSettings.addSetting("Countdown", new ArrayList(){{ + add(Utils.colorize("&7Wenn diese Einstellung aktiv ist,")); + add(Utils.colorize("&7kann der Teleporter &6wiederholt nach")); + add(Utils.colorize("&6einer bestimmten Zeit &7genutzt werden!")); + }}, Material.CLOCK, true); + + teleporterSubSettings.addSetting("Countdown-Zeit", new ArrayList(){{ + add(Utils.colorize("&7Hier legst du fest, &6wie lange&7 ein")); + add(Utils.colorize("&7Spieler &6warten &7muss, bis er sich")); + add(Utils.colorize("&7wieder teleportieren kann!")); + }}, Material.NAUTILUS_SHELL, new ArrayList(){{ + add(120); + add(300); + add(600); + }}, new ArrayList(){{ + add(Utils.colorize("&b2 Minuten")); + add(Utils.colorize("&b5 Minuten")); + add(Utils.colorize("&b10 Minuten")); + }}); + + teleporterSubSettings.addSetting("Teleporter-Radius", new ArrayList() {{ + add(Utils.colorize("&7Hier kannst du einstellen,")); + add(Utils.colorize("&7wie groß der &6Radius&7 des ")); + add(Utils.colorize("&7Telportierens sein soll")); + }}, Material.CARTOGRAPHY_TABLE, new ArrayList() {{ + add(100); + add(250); + add(500); + add(750); + add(1000); + add(1500); + add(2000); + }}, new ArrayList() {{ + add(Utils.colorize("&b100 &fBlöcke")); + add(Utils.colorize("&b250 &fBlöcke")); + add(Utils.colorize("&b500 &fBlöcke")); + add(Utils.colorize("&b750 &fBlöcke")); + add(Utils.colorize("&b1000 &fBlöcke")); + add(Utils.colorize("&b1500 &fBlöcke")); + add(Utils.colorize("&b2000 &fBlöcke")); + }}); + + + //this.addSetting(); } } diff --git a/src/main/java/bingo/Utils.java b/src/main/java/bingo/Utils.java index e93e339..6c1d310 100644 --- a/src/main/java/bingo/Utils.java +++ b/src/main/java/bingo/Utils.java @@ -12,30 +12,29 @@ public class Utils { - private static void scatterPlayers(int scatterSize) { + public static void scatterPlayer(Player player, int scatterSize) { Random random = new Random(); World world = Bukkit.getWorld("world"); - for (Player player : Bukkit.getOnlinePlayers()) { - Location location = player.getLocation(); - do { - double x = (random.nextFloat() - 0.5f) * scatterSize; - double z = (random.nextFloat() - 0.5f) * scatterSize; - location.setX(x); - location.setZ(z); - assert world != null; - location.setY(world.getHighestBlockYAt((int) x, (int) z)); - } while (location.getBlock().isLiquid()); - location.add(0, 2, 0); - player.setBedSpawnLocation(location, true); - player.teleport(location); - } + Location location = player.getLocation(); + do { + double x = (random.nextFloat() - 0.5f) * scatterSize; + double z = (random.nextFloat() - 0.5f) * scatterSize; + location.setX(x); + location.setZ(z); + assert world != null; + location.setY(world.getHighestBlockYAt((int) x, (int) z)); + } while (location.getBlock().isLiquid()); + location.add(0, 2, 0); + player.setBedSpawnLocation(location, true); + player.teleport(location); } public static void preparePlayers(int scatterSize) { clearPlayers(); CheckInventory.createLock(); if (BingoPlugin.scatter) { - scatterPlayers(scatterSize); + for(Player player : Bukkit.getOnlinePlayers()) + scatterPlayer(player, scatterSize); } } diff --git a/src/main/java/bingo/commandExecutor/BingoCommandExecutor.java b/src/main/java/bingo/commandExecutor/BingoCommandExecutor.java index 185ce3e..678717b 100644 --- a/src/main/java/bingo/commandExecutor/BingoCommandExecutor.java +++ b/src/main/java/bingo/commandExecutor/BingoCommandExecutor.java @@ -3,6 +3,8 @@ import bingo.BingoInventory; import bingo.BingoList; import bingo.BingoPlugin; +import bingo.teleporter.Teleporter; +import bingo.teleporter.TeleporterTimer; import org.bukkit.*; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -54,7 +56,17 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } } } else if (command.getLabel().equalsIgnoreCase("rtp")) { - + assert player != null; + if (BingoPlugin.tpEnabled) { + if (Teleporter.canTP(player)) { + Teleporter.teleport(player); + player.sendMessage(Utils.getPrefix("Teleporter") + Utils.colorize("Du wurdest &ateleportiert&f!")); + } else { + player.sendMessage(Utils.getPrefix("Teleporter") + Utils.colorize("Du musst noch &b" + Utils.formatTimerTimeText(Teleporter.getTimer(player).getSeconds()) + "&f warten!")); + } + } else { + player.sendMessage(Utils.getPrefix("Teleporter") + Utils.colorize("Das Teleport-Feature ist &cdeaktiviert&f!")); + } return false; } diff --git a/src/main/java/bingo/teleporter/Teleporter.java b/src/main/java/bingo/teleporter/Teleporter.java index 253292e..99dd12c 100644 --- a/src/main/java/bingo/teleporter/Teleporter.java +++ b/src/main/java/bingo/teleporter/Teleporter.java @@ -1,4 +1,63 @@ package bingo.teleporter; +import bingo.BingoPlugin; +import core.Utils; +import core.timer.TimerType; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.util.HashMap; + public class Teleporter { + + private static boolean enabled; + private static int time; + private static int radius; + private static BingoPlugin bingoPlugin; + + + private static HashMap playerCountdown = new HashMap(); + + public Teleporter(BingoPlugin bingoPlugin, boolean enabled, int time, int radius) { + Teleporter.enabled = enabled; + Teleporter.time = time; + Teleporter.radius = radius; + Teleporter.bingoPlugin = bingoPlugin; + } + + public void init() { + if (enabled) { + for (Player player : Bukkit.getOnlinePlayers()) { + TeleporterTimer teleporterTimer = new TeleporterTimer(bingoPlugin, TimerType.DECREASING, "", "", true, Utils.colorize("Du kannst dich wieder &bteleportieren&f!"), player); + teleporterTimer.setSeconds(time); + teleporterTimer.resume(); + playerCountdown.put(player.getDisplayName(), teleporterTimer); + } + } + } + + public void enable() { + enabled = true; + } + + public void disable() { + enabled = false; + } + + public static boolean canTP(Player player){ + return playerCountdown.get(player.getDisplayName()).getTicks() == 0; + } + + public static void teleport(Player player){ + TeleporterTimer teleporterTimer = playerCountdown.get(player.getDisplayName()); + teleporterTimer.setSeconds(time); + teleporterTimer.resume(); + Utils.sendDebugMessage("&cPlayer has been teleported"); + playerCountdown.put(player.getDisplayName(), teleporterTimer); + bingo.Utils.scatterPlayer(player, radius); + } + + public static TeleporterTimer getTimer(Player player){ + return playerCountdown.get(player.getDisplayName()); + } } diff --git a/src/main/java/bingo/teleporter/TeleporterTimer.java b/src/main/java/bingo/teleporter/TeleporterTimer.java index 08fea03..911f832 100644 --- a/src/main/java/bingo/teleporter/TeleporterTimer.java +++ b/src/main/java/bingo/teleporter/TeleporterTimer.java @@ -2,10 +2,11 @@ import core.timer.Timer; import core.timer.TimerType; +import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; public class TeleporterTimer extends Timer { - public TeleporterTimer(Plugin plugin, TimerType timerType, String runningString, String pausedString, boolean hidden) { - super(plugin, timerType, runningString, pausedString, hidden); + public TeleporterTimer(Plugin plugin, TimerType timerType, String runningString, String pausedString, boolean hidden, String timerReady, Player player) { + super(plugin, timerType, runningString, pausedString, hidden, timerReady, player); } }