mirror of
https://github.com/nkomarn/harbor.git
synced 2025-01-07 00:08:19 +01:00
⚡ Fix up cooldowns
This commit is contained in:
parent
7644a7faad
commit
62ff190aa5
2
.github/workflows/maven.yml
vendored
2
.github/workflows/maven.yml
vendored
@ -12,6 +12,8 @@ jobs:
|
|||||||
uses: actions/setup-java@v1
|
uses: actions/setup-java@v1
|
||||||
with:
|
with:
|
||||||
java-version: 1.8
|
java-version: 1.8
|
||||||
|
- name: Build with Maven
|
||||||
|
run: mvn package --file pom.xml
|
||||||
#- name: Build with Maven and Deploy
|
#- name: Build with Maven and Deploy
|
||||||
# env:
|
# env:
|
||||||
# GITHUB_USERNAME: x-access-token
|
# GITHUB_USERNAME: x-access-token
|
||||||
|
@ -13,18 +13,20 @@ import xyz.nkomarn.Harbor.util.Messages;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class BedListener implements Listener {
|
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)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onBedEnter(final PlayerBedEnterEvent event) {
|
public void onBedEnter(final PlayerBedEnterEvent event) {
|
||||||
if (event.getBedEnterResult() != PlayerBedEnterEvent.BedEnterResult.OK) return;
|
if (event.getBedEnterResult() != PlayerBedEnterEvent.BedEnterResult.OK) return;
|
||||||
if (Checker.skippingWorlds.contains(event.getPlayer().getWorld())) return;
|
if (Checker.skippingWorlds.contains(event.getPlayer().getWorld())) return;
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(Harbor.getHarbor(), () -> {
|
Bukkit.getScheduler().runTaskLater(Harbor.getHarbor(), () -> {
|
||||||
UUID playerUuid = event.getPlayer().getUniqueId();
|
final UUID playerUuid = event.getPlayer().getUniqueId();
|
||||||
if (cooldowns.containsKey(playerUuid) && !(cooldowns.get(playerUuid) +
|
if (!(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - getCooldown(playerUuid)) >
|
||||||
(Config.getInteger("messages.chat.message-cooldown") * 1000) >= System.currentTimeMillis())) return;
|
Config.getInteger("messages.chat.message-cooldown"))) return;
|
||||||
|
|
||||||
Messages.sendWorldChatMessage(event.getBed().getWorld(),
|
Messages.sendWorldChatMessage(event.getBed().getWorld(),
|
||||||
Config.getString("messages.chat.player-sleeping")
|
Config.getString("messages.chat.player-sleeping")
|
||||||
@ -37,10 +39,11 @@ public class BedListener implements Listener {
|
|||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onBedLeave(final PlayerBedLeaveEvent event) {
|
public void onBedLeave(final PlayerBedLeaveEvent event) {
|
||||||
if (Checker.skippingWorlds.contains(event.getPlayer().getWorld())) return;
|
if (Checker.skippingWorlds.contains(event.getPlayer().getWorld())) return;
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(Harbor.getHarbor(), () -> {
|
Bukkit.getScheduler().runTaskLater(Harbor.getHarbor(), () -> {
|
||||||
UUID playerUuid = event.getPlayer().getUniqueId();
|
final UUID playerUuid = event.getPlayer().getUniqueId();
|
||||||
if (cooldowns.containsKey(playerUuid) && !(cooldowns.get(playerUuid) +
|
if (!(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - getCooldown(playerUuid)) >
|
||||||
(Config.getInteger("messages.chat.message-cooldown") * 1000) >= System.currentTimeMillis())) return;
|
Config.getInteger("messages.chat.message-cooldown"))) return;
|
||||||
|
|
||||||
Messages.sendWorldChatMessage(event.getBed().getWorld(),
|
Messages.sendWorldChatMessage(event.getBed().getWorld(),
|
||||||
Config.getString("messages.chat.player-left-bed")
|
Config.getString("messages.chat.player-left-bed")
|
||||||
@ -49,4 +52,9 @@ public class BedListener implements Listener {
|
|||||||
cooldowns.put(playerUuid, System.currentTimeMillis());
|
cooldowns.put(playerUuid, System.currentTimeMillis());
|
||||||
}, 1);
|
}, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long getCooldown(final UUID playerUuid) {
|
||||||
|
if (!cooldowns.containsKey(playerUuid)) return 0;
|
||||||
|
return cooldowns.get(playerUuid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ public class AccelerateNightTask extends BukkitRunnable {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final long time = world.getTime();
|
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();
|
final int sleeping = Checker.getSleeping(world).size();
|
||||||
double timeRate = Config.getInteger("night-skip.time-rate");
|
double timeRate = Config.getInteger("night-skip.time-rate");
|
||||||
|
|
||||||
|
@ -4,16 +4,16 @@ main: xyz.nkomarn.Harbor.Harbor
|
|||||||
version: 1.6.2-SNAPSHOT
|
version: 1.6.2-SNAPSHOT
|
||||||
author: TechToolbox (@nkomarn)
|
author: TechToolbox (@nkomarn)
|
||||||
website: https://nkomarn.xyz
|
website: https://nkomarn.xyz
|
||||||
softdepend: [Essentials, PlaceholderAPI]
|
softdepend: [Essentials]
|
||||||
api-version: 1.14
|
api-version: 1.14
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
harbor:
|
harbor:
|
||||||
description: "Base command for Harbor!"
|
description: "Base command for Harbor!"
|
||||||
usage: "/harbor {subcommand}"
|
usage: "/harbor [subcommand]"
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
harbor.bypass:
|
harbor.ignored:
|
||||||
default: false
|
default: false
|
||||||
harbor.admin:
|
harbor.admin:
|
||||||
default: op
|
default: op
|
Loading…
Reference in New Issue
Block a user