From 62ff190aa54830394389c7eb8d8ec409ff116397 Mon Sep 17 00:00:00 2001 From: Mykyta Date: Sat, 4 Apr 2020 12:40:44 -0700 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Fix=20up=20cooldowns?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/maven.yml | 2 ++ .../nkomarn/Harbor/listener/BedListener.java | 22 +++++++++++++------ .../Harbor/task/AccelerateNightTask.java | 2 +- src/main/resources/plugin.yml | 6 ++--- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index f7f8944..53d37d7 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -12,6 +12,8 @@ jobs: uses: actions/setup-java@v1 with: java-version: 1.8 + - name: Build with Maven + run: mvn package --file pom.xml #- name: Build with Maven and Deploy # env: # GITHUB_USERNAME: x-access-token diff --git a/src/main/java/xyz/nkomarn/Harbor/listener/BedListener.java b/src/main/java/xyz/nkomarn/Harbor/listener/BedListener.java index 7a05aa9..477a96d 100644 --- a/src/main/java/xyz/nkomarn/Harbor/listener/BedListener.java +++ b/src/main/java/xyz/nkomarn/Harbor/listener/BedListener.java @@ -13,18 +13,20 @@ import xyz.nkomarn.Harbor.util.Messages; import java.util.HashMap; import java.util.Map; import java.util.UUID; +import java.util.concurrent.TimeUnit; public class BedListener implements Listener { - private Map cooldowns = new HashMap<>(); // TODO, totally fucked right now (lol) + private Map cooldowns = new HashMap<>(); @EventHandler(ignoreCancelled = true) public void onBedEnter(final PlayerBedEnterEvent event) { if (event.getBedEnterResult() != PlayerBedEnterEvent.BedEnterResult.OK) return; if (Checker.skippingWorlds.contains(event.getPlayer().getWorld())) return; + Bukkit.getScheduler().runTaskLater(Harbor.getHarbor(), () -> { - UUID playerUuid = event.getPlayer().getUniqueId(); - if (cooldowns.containsKey(playerUuid) && !(cooldowns.get(playerUuid) + - (Config.getInteger("messages.chat.message-cooldown") * 1000) >= System.currentTimeMillis())) return; + final UUID playerUuid = event.getPlayer().getUniqueId(); + if (!(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - getCooldown(playerUuid)) > + Config.getInteger("messages.chat.message-cooldown"))) return; Messages.sendWorldChatMessage(event.getBed().getWorld(), Config.getString("messages.chat.player-sleeping") @@ -37,10 +39,11 @@ public class BedListener implements Listener { @EventHandler(ignoreCancelled = true) public void onBedLeave(final PlayerBedLeaveEvent event) { if (Checker.skippingWorlds.contains(event.getPlayer().getWorld())) return; + Bukkit.getScheduler().runTaskLater(Harbor.getHarbor(), () -> { - UUID playerUuid = event.getPlayer().getUniqueId(); - if (cooldowns.containsKey(playerUuid) && !(cooldowns.get(playerUuid) + - (Config.getInteger("messages.chat.message-cooldown") * 1000) >= System.currentTimeMillis())) return; + final UUID playerUuid = event.getPlayer().getUniqueId(); + if (!(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - getCooldown(playerUuid)) > + Config.getInteger("messages.chat.message-cooldown"))) return; Messages.sendWorldChatMessage(event.getBed().getWorld(), Config.getString("messages.chat.player-left-bed") @@ -49,4 +52,9 @@ public class BedListener implements Listener { cooldowns.put(playerUuid, System.currentTimeMillis()); }, 1); } + + private long getCooldown(final UUID playerUuid) { + if (!cooldowns.containsKey(playerUuid)) return 0; + return cooldowns.get(playerUuid); + } } diff --git a/src/main/java/xyz/nkomarn/Harbor/task/AccelerateNightTask.java b/src/main/java/xyz/nkomarn/Harbor/task/AccelerateNightTask.java index 30c021f..4869753 100644 --- a/src/main/java/xyz/nkomarn/Harbor/task/AccelerateNightTask.java +++ b/src/main/java/xyz/nkomarn/Harbor/task/AccelerateNightTask.java @@ -19,7 +19,7 @@ public class AccelerateNightTask extends BukkitRunnable { @Override public void run() { final long time = world.getTime(); - final int dayTime = Config.getInteger("night-skip.daytime-ticks"); + final int dayTime = Math.max(150, Config.getInteger("night-skip.daytime-ticks")); final int sleeping = Checker.getSleeping(world).size(); double timeRate = Config.getInteger("night-skip.time-rate"); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 30cebb4..3b8f165 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,16 +4,16 @@ main: xyz.nkomarn.Harbor.Harbor version: 1.6.2-SNAPSHOT author: TechToolbox (@nkomarn) website: https://nkomarn.xyz -softdepend: [Essentials, PlaceholderAPI] +softdepend: [Essentials] api-version: 1.14 commands: harbor: description: "Base command for Harbor!" - usage: "/harbor {subcommand}" + usage: "/harbor [subcommand]" permissions: - harbor.bypass: + harbor.ignored: default: false harbor.admin: default: op \ No newline at end of file