mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-10-02 09:37:48 +02:00
parent
f92a004fcb
commit
11ac5d5071
@ -67,7 +67,8 @@ public class GameRuleProvider {
|
|||||||
|
|
||||||
/* Timer */
|
/* Timer */
|
||||||
DEFAULT_VALUES.timeLastPlayed = 0;
|
DEFAULT_VALUES.timeLastPlayed = 0;
|
||||||
DEFAULT_VALUES.timeToNextPlay = 0;
|
DEFAULT_VALUES.timeToNextPlayAfterStart = 0;
|
||||||
|
DEFAULT_VALUES.timeToNextPlayAfterFinish = 0;
|
||||||
DEFAULT_VALUES.timeToNextLoot = 0;
|
DEFAULT_VALUES.timeToNextLoot = 0;
|
||||||
DEFAULT_VALUES.timeToNextWave = 10;
|
DEFAULT_VALUES.timeToNextWave = 10;
|
||||||
DEFAULT_VALUES.timeToFinish = -1;
|
DEFAULT_VALUES.timeToFinish = -1;
|
||||||
@ -122,7 +123,8 @@ public class GameRuleProvider {
|
|||||||
|
|
||||||
/* Timer */
|
/* Timer */
|
||||||
protected Integer timeLastPlayed;
|
protected Integer timeLastPlayed;
|
||||||
protected Integer timeToNextPlay;
|
protected Integer timeToNextPlayAfterStart;
|
||||||
|
protected Integer timeToNextPlayAfterFinish;
|
||||||
protected Integer timeToNextLoot;
|
protected Integer timeToNextLoot;
|
||||||
protected Integer timeToNextWave;
|
protected Integer timeToNextWave;
|
||||||
protected Integer timeToFinish;
|
protected Integer timeToFinish;
|
||||||
@ -334,10 +336,17 @@ public class GameRuleProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the time until a player can play again
|
* @return the time until a player can play again after he started the dungeon the last time
|
||||||
*/
|
*/
|
||||||
public int getTimeToNextPlay() {
|
public int getTimeToNextPlayAfterStart() {
|
||||||
return timeToNextPlay;
|
return timeToNextPlayAfterStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the time until a player can play again after he finished the dungeon the last time
|
||||||
|
*/
|
||||||
|
public int getTimeToNextPlayAfterFinish() {
|
||||||
|
return timeToNextPlayAfterFinish;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -732,8 +741,12 @@ public class GameRuleProvider {
|
|||||||
timeLastPlayed = defaultValues.timeLastPlayed;
|
timeLastPlayed = defaultValues.timeLastPlayed;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeToNextPlay == null) {
|
if (timeToNextPlayAfterStart == null) {
|
||||||
timeToNextPlay = defaultValues.timeToNextPlay;
|
timeToNextPlayAfterStart = defaultValues.timeToNextPlayAfterStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timeToNextPlayAfterFinish == null) {
|
||||||
|
timeToNextPlayAfterFinish = defaultValues.timeToNextPlayAfterFinish;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeToNextLoot == null) {
|
if (timeToNextLoot == null) {
|
||||||
|
@ -20,6 +20,7 @@ import de.erethon.commons.chat.MessageUtil;
|
|||||||
import de.erethon.commons.player.PlayerUtil;
|
import de.erethon.commons.player.PlayerUtil;
|
||||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||||
import io.github.dre2n.dungeonsxl.config.DMessage;
|
import io.github.dre2n.dungeonsxl.config.DMessage;
|
||||||
|
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
|
||||||
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerKickEvent;
|
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerKickEvent;
|
||||||
import io.github.dre2n.dungeonsxl.event.dplayer.instance.DInstancePlayerUpdateEvent;
|
import io.github.dre2n.dungeonsxl.event.dplayer.instance.DInstancePlayerUpdateEvent;
|
||||||
import io.github.dre2n.dungeonsxl.event.dplayer.instance.game.DGamePlayerDeathEvent;
|
import io.github.dre2n.dungeonsxl.event.dplayer.instance.game.DGamePlayerDeathEvent;
|
||||||
@ -510,7 +511,7 @@ public class DGamePlayer extends DInstancePlayer {
|
|||||||
reward.giveTo(getPlayer());
|
reward.giveTo(getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
getData().logTimeLastPlayed(getDGroup().getDungeon().getName());
|
getData().logTimeLastFinished(getDGroup().getDungeonName());
|
||||||
|
|
||||||
// Tutorial Permissions
|
// Tutorial Permissions
|
||||||
if (game.isTutorial() && plugin.getPermissionProvider().hasGroupSupport()) {
|
if (game.isTutorial() && plugin.getPermissionProvider().hasGroupSupport()) {
|
||||||
@ -598,8 +599,13 @@ public class DGamePlayer extends DInstancePlayer {
|
|||||||
|
|
||||||
GameRuleProvider rules = game.getRules();
|
GameRuleProvider rules = game.getRules();
|
||||||
|
|
||||||
if (!checkTime(game)) {
|
if (!checkTimeAfterStart(game)) {
|
||||||
MessageUtil.sendMessage(player, DMessage.ERROR_COOLDOWN.getMessage(String.valueOf(rules.getTimeToNextPlay())));
|
MessageUtil.sendMessage(player, DMessage.ERROR_COOLDOWN.getMessage(String.valueOf(rules.getTimeToNextPlayAfterStart())));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!checkTimeAfterFinish(game)) {
|
||||||
|
MessageUtil.sendMessage(player, DMessage.ERROR_COOLDOWN.getMessage(String.valueOf(rules.getTimeToNextPlayAfterStart())));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -632,7 +638,7 @@ public class DGamePlayer extends DInstancePlayer {
|
|||||||
if (new File(DungeonsXL.MAPS, dungeonName).isDirectory()) {
|
if (new File(DungeonsXL.MAPS, dungeonName).isDirectory()) {
|
||||||
if (played.equalsIgnoreCase(dungeonName) || played.equalsIgnoreCase("any")) {
|
if (played.equalsIgnoreCase(dungeonName) || played.equalsIgnoreCase("any")) {
|
||||||
|
|
||||||
Long time = getData().getTimeLastPlayed(dungeonName);
|
Long time = getData().getTimeLastFinished(dungeonName);
|
||||||
if (time != -1) {
|
if (time != -1) {
|
||||||
if (rules.getFinishedAll().contains(played)) {
|
if (rules.getFinishedAll().contains(played)) {
|
||||||
numOfNeeded++;
|
numOfNeeded++;
|
||||||
@ -669,20 +675,22 @@ public class DGamePlayer extends DInstancePlayer {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkTime(Game game) {
|
public boolean checkTimeAfterStart(Game game) {
|
||||||
|
return checkTime(game.getDungeon(), game.getRules().getTimeToNextPlayAfterStart(), getData().getTimeLastStarted(game.getDungeon().getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkTimeAfterFinish(Game game) {
|
||||||
|
return checkTime(game.getDungeon(), game.getRules().getTimeToNextPlayAfterFinish(), getData().getTimeLastFinished(game.getDungeon().getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkTime(Dungeon dungeon, int requirement, long dataTime) {
|
||||||
if (DPermission.hasPermission(player, DPermission.IGNORE_TIME_LIMIT)) {
|
if (DPermission.hasPermission(player, DPermission.IGNORE_TIME_LIMIT)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameRuleProvider rules = game.getRules();
|
if (requirement != -1) {
|
||||||
|
if (requirement + dataTime * 1000 * 60 * 60 > System.currentTimeMillis()) {
|
||||||
if (rules.getTimeToNextPlay() != 0) {
|
return false;
|
||||||
// read PlayerConfig
|
|
||||||
long time = getData().getTimeLastPlayed(game.getDungeon().getName());
|
|
||||||
if (time != -1) {
|
|
||||||
if (time + rules.getTimeToNextPlay() * 1000 * 60 * 60 > System.currentTimeMillis()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -817,6 +817,7 @@ public class DGroup {
|
|||||||
if (dPlayer == null) {
|
if (dPlayer == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
dPlayer.getData().logTimeLastStarted(getDungeonName());
|
||||||
|
|
||||||
dPlayer.respawn();
|
dPlayer.respawn();
|
||||||
|
|
||||||
@ -890,7 +891,7 @@ public class DGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (DGamePlayer dPlayer : getDGamePlayers()) {
|
for (DGamePlayer dPlayer : getDGamePlayers()) {
|
||||||
if (!dPlayer.checkTime(game)) {
|
if (!dPlayer.checkTimeAfterStart(game) || !dPlayer.checkTimeAfterFinish(game)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ public class DPlayerData extends DREConfig {
|
|||||||
|
|
||||||
boolean is1_9 = Internals.andHigher(Internals.v1_9_R1).contains(CompatibilityHandler.getInstance().getInternals());
|
boolean is1_9 = Internals.andHigher(Internals.v1_9_R1).contains(CompatibilityHandler.getInstance().getInternals());
|
||||||
|
|
||||||
public static final int CONFIG_VERSION = 2;
|
public static final int CONFIG_VERSION = 3;
|
||||||
|
|
||||||
public static final String PREFIX_STATE_PERSISTENCE = "savePlayer.";
|
public static final String PREFIX_STATE_PERSISTENCE = "savePlayer.";
|
||||||
public static final String PREFIX_STATS = "stats.";
|
public static final String PREFIX_STATS = "stats.";
|
||||||
@ -67,7 +67,8 @@ public class DPlayerData extends DREConfig {
|
|||||||
private Collection<PotionEffect> oldPotionEffects;
|
private Collection<PotionEffect> oldPotionEffects;
|
||||||
|
|
||||||
// Stats
|
// Stats
|
||||||
private Map<String, Long> timeLastPlayed = new HashMap<>();
|
private Map<String, Long> timeLastStarted = new HashMap<>();
|
||||||
|
private Map<String, Long> timeLastFinished = new HashMap<>();
|
||||||
|
|
||||||
public DPlayerData(File file) {
|
public DPlayerData(File file) {
|
||||||
super(file, CONFIG_VERSION);
|
super(file, CONFIG_VERSION);
|
||||||
@ -266,11 +267,43 @@ public class DPlayerData extends DREConfig {
|
|||||||
oldPotionEffects = potionEffects;
|
oldPotionEffects = potionEffects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a map of the player's started dungeons with dates.
|
||||||
|
*/
|
||||||
|
public Map<String, Long> getTimeLastStarted() {
|
||||||
|
return timeLastStarted;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param dungeon
|
||||||
|
* the dungeon to check
|
||||||
|
* @return the time when the player started the dungeon for the last time
|
||||||
|
*/
|
||||||
|
public long getTimeLastStarted(String dungeon) {
|
||||||
|
Long time = timeLastStarted.get(dungeon.toLowerCase());
|
||||||
|
if (time == null) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param dungeon
|
||||||
|
* the started dungeon
|
||||||
|
* @param time
|
||||||
|
* the time when the dungeon was started
|
||||||
|
*/
|
||||||
|
public void setTimeLastStarted(String dungeon, long time) {
|
||||||
|
timeLastStarted.put(dungeon.toLowerCase(), time);
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a map of the player's finished dungeons with dates.
|
* @return a map of the player's finished dungeons with dates.
|
||||||
*/
|
*/
|
||||||
public Map<String, Long> getTimeLastPlayed() {
|
public Map<String, Long> getTimeLastFinished() {
|
||||||
return timeLastPlayed;
|
return timeLastFinished;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -278,8 +311,8 @@ public class DPlayerData extends DREConfig {
|
|||||||
* the dungeon to check
|
* the dungeon to check
|
||||||
* @return the time when the player finished the dungeon for the last time
|
* @return the time when the player finished the dungeon for the last time
|
||||||
*/
|
*/
|
||||||
public long getTimeLastPlayed(String dungeon) {
|
public long getTimeLastFinished(String dungeon) {
|
||||||
Long time = timeLastPlayed.get(dungeon.toLowerCase());
|
Long time = timeLastFinished.get(dungeon.toLowerCase());
|
||||||
if (time == null) {
|
if (time == null) {
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
@ -293,25 +326,38 @@ public class DPlayerData extends DREConfig {
|
|||||||
* @param time
|
* @param time
|
||||||
* the time when the dungeon was finished
|
* the time when the dungeon was finished
|
||||||
*/
|
*/
|
||||||
public void setTimeLastPlayed(String dungeon, long time) {
|
public void setTimeLastFinished(String dungeon, long time) {
|
||||||
timeLastPlayed.put(dungeon.toLowerCase(), time);
|
timeLastFinished.put(dungeon.toLowerCase(), time);
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Actions */
|
/* Actions */
|
||||||
|
/**
|
||||||
|
* @param dungeon
|
||||||
|
* the started dungeon
|
||||||
|
*/
|
||||||
|
public void logTimeLastStarted(String dungeon) {
|
||||||
|
timeLastStarted.put(dungeon.toLowerCase(), System.currentTimeMillis());
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param dungeon
|
* @param dungeon
|
||||||
* the finished dungeon
|
* the finished dungeon
|
||||||
*/
|
*/
|
||||||
public void logTimeLastPlayed(String dungeon) {
|
public void logTimeLastFinished(String dungeon) {
|
||||||
timeLastPlayed.put(dungeon.toLowerCase(), System.currentTimeMillis());
|
timeLastFinished.put(dungeon.toLowerCase(), System.currentTimeMillis());
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
if (!config.contains(PREFIX_STATS + "timeLastPlayed")) {
|
if (!config.contains(PREFIX_STATS + "timeLastStarted")) {
|
||||||
config.createSection(PREFIX_STATS + "timeLastPlayed");
|
config.createSection(PREFIX_STATS + "timeLastStarted");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!config.contains(PREFIX_STATS + "timeLastFinished")) {
|
||||||
|
config.createSection(PREFIX_STATS + "timeLastFinished");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
@ -327,9 +373,15 @@ public class DPlayerData extends DREConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load() {
|
public void load() {
|
||||||
if (config.isConfigurationSection(PREFIX_STATS + "timeLastPlayed")) {
|
if (config.isConfigurationSection(PREFIX_STATS + "timeLastStarted")) {
|
||||||
for (String key : config.getConfigurationSection(PREFIX_STATS + "timeLastPlayed").getKeys(false)) {
|
for (String key : config.getConfigurationSection(PREFIX_STATS + "timeLastStarted").getKeys(false)) {
|
||||||
timeLastPlayed.put(key, config.getLong(PREFIX_STATS + "timeLastPlayed." + key));
|
timeLastStarted.put(key, config.getLong(PREFIX_STATS + "timeLastStarted." + key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.isConfigurationSection(PREFIX_STATS + "timeLastFinished")) {
|
||||||
|
for (String key : config.getConfigurationSection(PREFIX_STATS + "timeLastFinished").getKeys(false)) {
|
||||||
|
timeLastFinished.put(key, config.getLong(PREFIX_STATS + "timeLastFinished." + key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,7 +415,8 @@ public class DPlayerData extends DREConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save() {
|
public void save() {
|
||||||
config.set(PREFIX_STATS + "timeLastPlayed", timeLastPlayed);
|
config.set(PREFIX_STATS + "timeLastStarted", timeLastStarted);
|
||||||
|
config.set(PREFIX_STATS + "timeLastFinished", timeLastFinished);
|
||||||
super.save();
|
super.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,6 +106,7 @@ public class WorldConfig extends GameRuleProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Keep Inventory */
|
/* Keep Inventory */
|
||||||
|
// DEPRECATED
|
||||||
if (configFile.contains("keepInventory")) {
|
if (configFile.contains("keepInventory")) {
|
||||||
if (!configFile.contains("keepInventoryOnEnter")) {
|
if (!configFile.contains("keepInventoryOnEnter")) {
|
||||||
keepInventoryOnEnter = configFile.getBoolean("keepInventory");
|
keepInventoryOnEnter = configFile.getBoolean("keepInventory");
|
||||||
@ -221,8 +222,17 @@ public class WorldConfig extends GameRuleProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Times */
|
/* Times */
|
||||||
|
if (configFile.contains("timeToNextPlayAfterStart")) {
|
||||||
|
timeToNextPlayAfterStart = configFile.getInt("timeToNextPlayAfterStart");
|
||||||
|
}
|
||||||
|
|
||||||
|
// DEPRECATED
|
||||||
if (configFile.contains("timeToNextPlay")) {
|
if (configFile.contains("timeToNextPlay")) {
|
||||||
timeToNextPlay = configFile.getInt("timeToNextPlay");
|
timeToNextPlayAfterFinish = configFile.getInt("timeToNextPlay");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (configFile.contains("timeToNextPlayAfterFinish")) {
|
||||||
|
timeToNextPlayAfterFinish = configFile.getInt("timeToNextPlayAfterFinish");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configFile.contains("timeToNextLoot")) {
|
if (configFile.contains("timeToNextLoot")) {
|
||||||
|
Loading…
Reference in New Issue
Block a user