mirror of
https://gitlab.com/SamB440/rpgregions-2.git
synced 2025-12-19 14:59:19 +00:00
fix: %rpgregions_region_timed% showing incorrect percentage, fix: time incrementing standing still
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package net.islandearth.rpgregions.managers.data.account;
|
||||
|
||||
import net.islandearth.rpgregions.managers.data.region.Discovery;
|
||||
import net.islandearth.rpgregions.utils.TimeEntry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -14,7 +15,7 @@ public class RPGRegionsAccount {
|
||||
private final UUID uuid;
|
||||
private final Map<String, Discovery> discoveredRegions;
|
||||
private final List<AccountCooldown> cooldowns;
|
||||
private final Map<String, Long> secondsInRegion;
|
||||
private final Map<String, TimeEntry> secondsInRegion;
|
||||
|
||||
public RPGRegionsAccount(UUID uuid, Map<String, Discovery> discoveredRegions) {
|
||||
this.uuid = uuid;
|
||||
@@ -39,12 +40,12 @@ public class RPGRegionsAccount {
|
||||
return cooldowns;
|
||||
}
|
||||
|
||||
public Optional<Long> getStartTimeInRegion(String region) {
|
||||
public Optional<TimeEntry> getTimeEntryInRegion(String region) {
|
||||
return Optional.ofNullable(secondsInRegion.getOrDefault(region, null));
|
||||
}
|
||||
|
||||
public void addStartTimeInRegion(String region, long time) {
|
||||
secondsInRegion.put(region, time);
|
||||
public void addTimeEntryInRegion(String region, long time) {
|
||||
secondsInRegion.put(region, new TimeEntry(time));
|
||||
}
|
||||
|
||||
public void removeStartTimeInRegion(String region) {
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package net.islandearth.rpgregions.utils;
|
||||
|
||||
public class TimeEntry {
|
||||
|
||||
private long start, latestEntry;
|
||||
|
||||
public TimeEntry(long start) {
|
||||
this.start = start;
|
||||
this.latestEntry = start;
|
||||
}
|
||||
|
||||
public long getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public long getLatestEntry() {
|
||||
return latestEntry;
|
||||
}
|
||||
|
||||
public void setStart(long start) {
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
public void setLatestEntry(long latestEntry) {
|
||||
this.latestEntry = latestEntry;
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import net.islandearth.rpgregions.managers.data.account.RPGRegionsAccount;
|
||||
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
|
||||
import net.islandearth.rpgregions.thread.Blocking;
|
||||
import net.islandearth.rpgregions.translation.Translations;
|
||||
import net.islandearth.rpgregions.utils.TimeEntry;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Optional;
|
||||
@@ -103,11 +104,11 @@ public class PlaceholderRegionHook extends PlaceholderExpansion implements Block
|
||||
return region.get().getCustomName();
|
||||
}
|
||||
|
||||
final Optional<Long> startTimeInRegion = account.getStartTimeInRegion(region.get().getId());
|
||||
if (startTimeInRegion.isEmpty()) return region.get().getCustomName();
|
||||
final Optional<TimeEntry> timeEntry = account.getTimeEntryInRegion(region.get().getId());
|
||||
if (timeEntry.isEmpty()) return region.get().getCustomName();
|
||||
|
||||
final double entry = startTimeInRegion.get();
|
||||
final double time = TimeUnit.MILLISECONDS.toSeconds((long) (System.currentTimeMillis() - entry));
|
||||
final double entry = timeEntry.get().getStart();
|
||||
final double time = TimeUnit.MILLISECONDS.toSeconds((long) (timeEntry.get().getLatestEntry() - entry));
|
||||
final double secondsInsideToDiscover = configuredRegion.getSecondsInsideToDiscover();
|
||||
final double percent = (time / secondsInsideToDiscover) * 100;
|
||||
return Translations.DISCOVERING_AREA_PLACEHOLDER.get(player, (int) percent, region.get().getId()).get(0);
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.islandearth.rpgregions.managers.data.region.Discovery;
|
||||
import net.islandearth.rpgregions.managers.data.region.WorldDiscovery;
|
||||
import net.islandearth.rpgregions.translation.Translations;
|
||||
import net.islandearth.rpgregions.utils.RegenUtils;
|
||||
import net.islandearth.rpgregions.utils.TimeEntry;
|
||||
import net.islandearth.rpgregions.utils.TitleAnimator;
|
||||
import net.islandearth.rpgregions.utils.XSound;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
@@ -72,12 +73,14 @@ public class RegionListener implements Listener {
|
||||
if (!has && configuredRegion.isDiscoverable() && prioritised) {
|
||||
if (configuredRegion.isTimedRegion()) {
|
||||
final long currentTimeMillis = System.currentTimeMillis();
|
||||
if (account.getStartTimeInRegion(region).isEmpty()) {
|
||||
account.addStartTimeInRegion(region, currentTimeMillis);
|
||||
if (account.getTimeEntryInRegion(region).isEmpty()) {
|
||||
account.addTimeEntryInRegion(region, currentTimeMillis);
|
||||
}
|
||||
|
||||
final long entry = account.getStartTimeInRegion(region).get();
|
||||
long time = TimeUnit.MILLISECONDS.toSeconds(currentTimeMillis - entry);
|
||||
final TimeEntry entry = account.getTimeEntryInRegion(region).get();
|
||||
long time = TimeUnit.MILLISECONDS.toSeconds(currentTimeMillis - entry.getStart());
|
||||
entry.setLatestEntry(currentTimeMillis);
|
||||
|
||||
final int secondsInsideToDiscover = configuredRegion.getSecondsInsideToDiscover();
|
||||
if (time < secondsInsideToDiscover) {
|
||||
plugin.debug(String.format("Unable to discover region for %s because they have not reached the time requirement (c: %d, e: %d, t: %d).", player.getName(), secondsInsideToDiscover, entry, time));
|
||||
|
||||
Reference in New Issue
Block a user