1
0
mirror of https://github.com/nkomarn/harbor.git synced 2025-01-05 07:07:34 +01:00

Fix up cooldowns

This commit is contained in:
Mykyta 2020-04-04 12:40:44 -07:00
parent 7644a7faad
commit 62ff190aa5
No known key found for this signature in database
GPG Key ID: C147E30C19EA3570
4 changed files with 21 additions and 11 deletions

View File

@ -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

View File

@ -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<UUID, Long> cooldowns = new HashMap<>(); // TODO, totally fucked right now (lol)
private Map<UUID, Long> 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);
}
}

View File

@ -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");

View File

@ -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