mirror of
https://github.com/nkomarn/harbor.git
synced 2025-01-05 07:07:34 +01:00
🌠 Use a HashSet instead of ArrayList
Harbor runs .contains() a lot, which is a lot more performant in Sets.
This commit is contained in:
parent
b5eaeeb7f1
commit
7b4c55e9a3
@ -37,11 +37,11 @@ public class HarborCommand implements TabExecutor {
|
||||
Player player = (Player) sender;
|
||||
World world = player.getWorld();
|
||||
|
||||
if (Checker.skippingWorlds.contains(world)) {
|
||||
if (Checker.SKIPPING_WORLDS.contains(world)) {
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', prefix
|
||||
+ "This world's time is already being accelerated."));
|
||||
} else {
|
||||
Checker.skippingWorlds.add(world);
|
||||
Checker.SKIPPING_WORLDS.add(world);
|
||||
new AccelerateNightTask(world).runTaskTimer(Harbor.getHarbor(), 0L, 1);
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', prefix
|
||||
+ "Forcing night skip in your world."));
|
||||
|
@ -21,7 +21,7 @@ public class BedListener implements Listener {
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBedEnter(final PlayerBedEnterEvent event) {
|
||||
if (event.getBedEnterResult() != PlayerBedEnterEvent.BedEnterResult.OK) return;
|
||||
if (Checker.skippingWorlds.contains(event.getPlayer().getWorld())) return;
|
||||
if (Checker.SKIPPING_WORLDS.contains(event.getPlayer().getWorld())) return;
|
||||
if (Checker.isVanished(event.getPlayer())) return;
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(Harbor.getHarbor(), () -> {
|
||||
@ -39,7 +39,7 @@ public class BedListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBedLeave(final PlayerBedLeaveEvent event) {
|
||||
if (Checker.skippingWorlds.contains(event.getPlayer().getWorld())) return;
|
||||
if (Checker.SKIPPING_WORLDS.contains(event.getPlayer().getWorld())) return;
|
||||
if (Checker.isVanished(event.getPlayer())) return;
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(Harbor.getHarbor(), () -> {
|
||||
|
@ -43,7 +43,7 @@ public class AccelerateNightTask extends BukkitRunnable {
|
||||
world.getPlayers().forEach(player -> player.setStatistic(Statistic.TIME_SINCE_REST, 0));
|
||||
}
|
||||
|
||||
Checker.skippingWorlds.remove(world);
|
||||
Checker.SKIPPING_WORLDS.remove(world);
|
||||
Messages.sendRandomChatMessage(world, "messages.chat.night-skipped");
|
||||
this.cancel();
|
||||
} else {
|
||||
|
@ -3,7 +3,6 @@ package xyz.nkomarn.Harbor.task;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
@ -12,13 +11,14 @@ import xyz.nkomarn.Harbor.util.Afk;
|
||||
import xyz.nkomarn.Harbor.util.Config;
|
||||
import xyz.nkomarn.Harbor.util.Messages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
public class Checker implements Runnable {
|
||||
public static final List<World> skippingWorlds = new ArrayList<>();
|
||||
public static final Set<World> SKIPPING_WORLDS = new HashSet<>();
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@ -48,7 +48,7 @@ public class Checker implements Runnable {
|
||||
world.setTime(Config.getInteger("night-skip.daytime-ticks")));
|
||||
Messages.sendRandomChatMessage(world, "messages.chat.night-skipped");
|
||||
} else {
|
||||
skippingWorlds.add(world);
|
||||
SKIPPING_WORLDS.add(world);
|
||||
new AccelerateNightTask(world).runTaskTimer(Harbor.getHarbor(), 1, 1);
|
||||
}
|
||||
}
|
||||
@ -56,7 +56,7 @@ public class Checker implements Runnable {
|
||||
|
||||
private boolean validateWorld(final World world) {
|
||||
return !isBlacklisted(world)
|
||||
&& !skippingWorlds.contains(world)
|
||||
&& !SKIPPING_WORLDS.contains(world)
|
||||
&& isNight(world);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user