Skip to content

Commit

Permalink
Version 1.6 Release Candidate 7
Browse files Browse the repository at this point in the history
Adds config option for checkpoint system.
Makes data saving of player data async in most cases.

Only exception is when we create data for a new player or add new maps
to an existing player.

I will need to do quite a bit of redesign in order to make those async.
  • Loading branch information
JustBru00 committed Mar 19, 2022
1 parent 8021c6e commit 7dc962f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 23 deletions.
15 changes: 13 additions & 2 deletions src/com/gmail/justbru00/nethercube/parkour/data/PlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import java.util.Set;
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;

import com.gmail.justbru00.nethercube.parkour.main.NetherCubeParkour;
import com.gmail.justbru00.nethercube.parkour.map.Map;
import com.gmail.justbru00.nethercube.parkour.map.MapManager;

Expand Down Expand Up @@ -39,7 +41,7 @@ public static PlayerData getDataFor(OfflinePlayer p) {
dataFile.set(pathPre + map.getInternalName() + ".finishes", 0);
dataFile.set(pathPre + map.getInternalName() + ".besttime", (long) -1);
}
dataFile.save();
dataFile.save();
}

// Get all data from config.
Expand Down Expand Up @@ -103,7 +105,16 @@ public void save() {
dataFile.set(prePath + pmd.getInternalName() + ".finishes", pmd.getFinishes());
dataFile.set(prePath + pmd.getInternalName() + ".besttime", pmd.getBestTime());
}
dataFile.save();
//dataFile.save();
Bukkit.getScheduler().runTaskAsynchronously(NetherCubeParkour.getInstance(), PlayerData::saveToDisk);
}

/**
* This method is a syncronized method to make sure all data is saved and we don't lose anything.
* All changes are saved in order.
*/
private static synchronized void saveToDisk() {
dataFile.save();
}

public PlayerMapData getMapData(String internalName) {
Expand Down
15 changes: 11 additions & 4 deletions src/com/gmail/justbru00/nethercube/parkour/map/Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ public class Map {
private Location startPlateLocation;
private Location endingPlateLocation;
private Location spawnLocation;
private boolean requiresCheckpoint;

public Map(String internalName) {
this.internalName = internalName;
}

public Map(String internalName, ItemStack guiItem, MapDifficulty difficulty, MapLength length, String creatorName,
int rewardAmount, int purchaseCost, Location startPlateLocation, Location endingPlateLocation) {
int rewardAmount, int purchaseCost, Location startPlateLocation, Location endingPlateLocation, boolean requiresCheckpoint) {
super();
this.internalName = internalName;
this.guiItem = guiItem;
Expand All @@ -37,6 +38,7 @@ public Map(String internalName, ItemStack guiItem, MapDifficulty difficulty, Map
this.purchaseCost = purchaseCost;
this.startPlateLocation = startPlateLocation;
this.endingPlateLocation = endingPlateLocation;
this.requiresCheckpoint = requiresCheckpoint;
}
/**
* Gets the spawnpoint for this map
Expand Down Expand Up @@ -104,7 +106,12 @@ public Location getEndingPlateLocation() {
public void setEndingPlateLocation(Location endingPlateLocation) {
this.endingPlateLocation = endingPlateLocation;
}




public boolean doesRequiresCheckpoint() {
return requiresCheckpoint;
}

public void setRequiresCheckpoint(boolean requiresCheckpoint) {
this.requiresCheckpoint = requiresCheckpoint;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public static void init() {
m.setLength(MapLength.fromString(c.getString("maps." + mapKey +".length")));
m.setPurchaseCost(c.getInt(prePath + "purchasecost"));
m.setRewardAmount(c.getInt(prePath + "rewardamount"));
boolean checkpoint = c.getBoolean(prePath + "requirescheckpoint");
if (!checkpoint) {
Messager.msgConsole("&6[MapManager] Map '" + mapKey + "' doesn't have checkpoints enabled. If you want to change this please add 'requirescheckpoint: true` to the configuration section for this map.");
}
m.setRequiresCheckpoint(checkpoint);
Location start;
Location end;
Location spawnpoint;
Expand Down
32 changes: 16 additions & 16 deletions src/com/gmail/justbru00/nethercube/parkour/timer/PlayerTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public static void playerStartingMap(OfflinePlayer p, Map m) {
playersInMapsBoatUuids.put(p.getUniqueId(), boatUuid);
playersCheckpointScore.put(p.getUniqueId(), 0);

// Add one attempt to the stats
// Add one attempt to the stats
PlayerData pd = PlayerData.getDataFor(p);
PlayerMapData pmd = pd.getMapData(m.getInternalName());

Expand Down Expand Up @@ -169,7 +169,7 @@ public static void playerCheckpointMap(OfflinePlayer p, Map m) {
}

playersCheckpointScore.put(p.getUniqueId(), 1);
Messager.debug("Activated hidden checkpoint for " + p.getName());
Messager.debug("&6[PlayerTimer] Activated hidden checkpoint for " + p.getName());
return;
}

Expand Down Expand Up @@ -230,16 +230,18 @@ public static void playerEndedMap(Player p, Map m) {
return;
}

if (playersCheckpointScore.get(p.getUniqueId()) == null || playersCheckpointScore.get(p.getUniqueId()) != 1) {
Messager.msgPlayer("&cYou skipped some of the map. I can't accept your time because of this.", p);
Messager.msgConsole(String.format("&c%s attempted to exploit the timing system by finishing without passing the hidden checkpoint.", p.getName()));
// Remove player from the HashMaps
playersInMaps.remove(p.getUniqueId());
playerMapStartTime.remove(p.getUniqueId());
playersInMapsBoatUuids.remove(p.getUniqueId());
playersCheckpointScore.remove(p.getUniqueId());
return;
}
if (m.doesRequiresCheckpoint()) {
if (playersCheckpointScore.get(p.getUniqueId()) == null || playersCheckpointScore.get(p.getUniqueId()) != 1) {
Messager.msgPlayer("&cYou skipped some of the map. I can't accept your time because of this.", p);
Messager.msgConsole(String.format("&c%s attempted to exploit the timing system by finishing without passing the hidden checkpoint.", p.getName()));
// Remove player from the HashMaps
playersInMaps.remove(p.getUniqueId());
playerMapStartTime.remove(p.getUniqueId());
playersInMapsBoatUuids.remove(p.getUniqueId());
playersCheckpointScore.remove(p.getUniqueId());
return;
}
}

PlayerData pd = PlayerData.getDataFor(p);
PlayerMapData pmd = pd.getMapData(m.getInternalName());
Expand All @@ -250,14 +252,12 @@ public static void playerEndedMap(Player p, Map m) {
// The default value is still saved. This is the new best time.
Messager.msgPlayer("&6You finished the map in &a" + Messager.formatAsTime(mapTime) + "&6. That is your new personal best!", p);
// Save new best time
pmd.setBestTime(mapTime);
pd.save();
pmd.setBestTime(mapTime);
} else if (mapTime < pmd.getBestTime()) {
// This is the new best time
Messager.msgPlayer("&6You finished the map in &a" + Messager.formatAsTime(mapTime) + "&6. That is your new personal best! You beat your previous best time of &c"
+ Messager.formatAsTime(pmd.getBestTime()) + "&6.", p);
pmd.setBestTime(mapTime);
pd.save();
pmd.setBestTime(mapTime);
} else {
// Not the new best time
Messager.msgPlayer("&6You finished the map in &c" + Messager.formatAsTime(mapTime) + "&6. "
Expand Down
1 change: 1 addition & 0 deletions src/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ maps:
length: 'SHORT'
creatorname: 'ItsLlfe'
rewardamount: 50
requirescheckpoint: true
# Purchase cost. -1 for unlocked by default
purchasecost: 100
startlocation:
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: NetherCubeParkour
main: com.gmail.justbru00.nethercube.parkour.main.NetherCubeParkour
version: 1.6-RC6
version: 1.6-RC7
authors: [JustBru00,Justin Brubaker,SethTheLasersloth]
softdepend: [HolographicDisplays]
api-version: 1.16
Expand Down

0 comments on commit 7dc962f

Please sign in to comment.