mirror of
https://gitlab.com/SamB440/rpgregions-2.git
synced 2025-12-29 11:49:08 +00:00
Persist player time entries in timed discovery regions, fix SQL delete queries, add account to discover event and award method in rewards
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package net.islandearth.rpgregions.api.events;
|
||||
|
||||
import net.islandearth.rpgregions.managers.data.account.RPGRegionsAccount;
|
||||
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
|
||||
import net.islandearth.rpgregions.managers.data.region.Discovery;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -10,11 +11,13 @@ public class RegionDiscoverEvent extends Event {
|
||||
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
private final Player player;
|
||||
private final RPGRegionsAccount account;
|
||||
private final ConfiguredRegion region;
|
||||
private final Discovery discovery;
|
||||
|
||||
public RegionDiscoverEvent(Player player, ConfiguredRegion region, Discovery discovery) {
|
||||
public RegionDiscoverEvent(Player player, RPGRegionsAccount account, ConfiguredRegion region, Discovery discovery) {
|
||||
this.player = player;
|
||||
this.account = account;
|
||||
this.region = region;
|
||||
this.discovery = discovery;
|
||||
}
|
||||
@@ -27,6 +30,14 @@ public class RegionDiscoverEvent extends Event {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the account of the player involved in this event.
|
||||
* @return the account of the player involved
|
||||
*/
|
||||
public RPGRegionsAccount getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the region that has been discovered.
|
||||
* @return {@link ConfiguredRegion} that was discovered
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.islandearth.rpgregions.managers.data.account;
|
||||
|
||||
import net.islandearth.rpgregions.managers.data.region.Discovery;
|
||||
import net.islandearth.rpgregions.rewards.DiscoveryReward;
|
||||
import net.islandearth.rpgregions.utils.TimeEntry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -16,6 +17,7 @@ public class RPGRegionsAccount {
|
||||
private final Map<String, Discovery> discoveries;
|
||||
private final List<AccountCooldown> cooldowns;
|
||||
private final Map<String, TimeEntry> secondsInRegion;
|
||||
private final Map<DiscoveryReward, Long> lastAwards = new HashMap<>();
|
||||
|
||||
public RPGRegionsAccount(UUID uuid, Map<String, Discovery> discoveries) {
|
||||
this.uuid = uuid;
|
||||
@@ -44,18 +46,33 @@ public class RPGRegionsAccount {
|
||||
return cooldowns;
|
||||
}
|
||||
|
||||
public Map<String, TimeEntry> getTimedEntries() {
|
||||
return Map.copyOf(secondsInRegion);
|
||||
}
|
||||
|
||||
public Optional<TimeEntry> getTimeEntryInRegion(String region) {
|
||||
return Optional.ofNullable(secondsInRegion.getOrDefault(region, null));
|
||||
}
|
||||
|
||||
public void addTimeEntryInRegion(String region, long time) {
|
||||
secondsInRegion.put(region, new TimeEntry(time));
|
||||
public TimeEntry addTimeEntryInRegion(String region, long time) {
|
||||
System.out.println("added time entry: " + region + ", " + time);
|
||||
final TimeEntry timeEntry = new TimeEntry(time);
|
||||
secondsInRegion.put(region, timeEntry);
|
||||
return timeEntry;
|
||||
}
|
||||
|
||||
public void removeStartTimeInRegion(String region) {
|
||||
secondsInRegion.remove(region);
|
||||
}
|
||||
|
||||
public void updateAwardTime(DiscoveryReward reward) {
|
||||
this.lastAwards.put(reward, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public Optional<Long> getLastAwardTime(DiscoveryReward reward) {
|
||||
return Optional.ofNullable(this.lastAwards.get(reward));
|
||||
}
|
||||
|
||||
public enum AccountCooldown {
|
||||
ICON_COMMAND,
|
||||
TELEPORT
|
||||
|
||||
@@ -371,7 +371,7 @@ public class ConfiguredRegion {
|
||||
this.teleportCooldown = teleportCooldown;
|
||||
}
|
||||
|
||||
public void setTeleportCost(int teleportCost) { this.teleportCost = teleportCost; }
|
||||
public void setTeleportCost(int teleportCost) { this.teleportCost = teleportCost; }
|
||||
|
||||
public boolean showActionbar() {
|
||||
return showActionbar;
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.islandearth.rpgregions.rewards;
|
||||
import net.islandearth.rpgregions.api.IRPGRegionsAPI;
|
||||
import net.islandearth.rpgregions.gui.GuiEditable;
|
||||
import net.islandearth.rpgregions.gui.IGuiEditable;
|
||||
import net.islandearth.rpgregions.managers.data.account.RPGRegionsAccount;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class DiscoveryReward implements IGuiEditable {
|
||||
@@ -15,8 +16,6 @@ public abstract class DiscoveryReward implements IGuiEditable {
|
||||
@GuiEditable("Time Between Reward (s)")
|
||||
private int timeBetweenReward;
|
||||
|
||||
private long lastReward;
|
||||
|
||||
public DiscoveryReward(IRPGRegionsAPI api) {
|
||||
this.api = api;
|
||||
}
|
||||
@@ -29,10 +28,10 @@ public abstract class DiscoveryReward implements IGuiEditable {
|
||||
* Awards this reward to the specified player
|
||||
* @param player player to award to
|
||||
*/
|
||||
public abstract void award(Player player);
|
||||
public abstract void award(Player player, RPGRegionsAccount account);
|
||||
|
||||
protected void updateAwardTime() {
|
||||
this.lastReward = System.currentTimeMillis();
|
||||
protected void updateAwardTime(RPGRegionsAccount account) {
|
||||
account.updateAwardTime(this);
|
||||
}
|
||||
|
||||
public boolean isAlwaysAward() {
|
||||
@@ -51,8 +50,8 @@ public abstract class DiscoveryReward implements IGuiEditable {
|
||||
this.timeBetweenReward = timeBetweenReward;
|
||||
}
|
||||
|
||||
public boolean canAward() {
|
||||
return (System.currentTimeMillis() - lastReward) >= (timeBetweenReward * 1000L);
|
||||
public boolean canAward(RPGRegionsAccount account) {
|
||||
return (System.currentTimeMillis() - account.getLastAwardTime(this).orElse(0L)) >= (timeBetweenReward * 1000L);
|
||||
}
|
||||
|
||||
public String getPluginRequirement() {
|
||||
|
||||
Reference in New Issue
Block a user