mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-28 13:36:33 +01:00
Fix time requirement check
This commit is contained in:
parent
e74b1bbb2e
commit
4695c024ab
@ -129,6 +129,7 @@ public enum DMessages implements Messages {
|
||||
LOG_ERROR_NO_CONSOLE_COMMAND("Log_Error_NoConsoleCommand", "&6/dxl &v1&4 can not be executed as Console!"),
|
||||
LOG_GENERATE_NEW_WORLD("Log_GenerateNewWorld", "&6Generate new world..."),
|
||||
LOG_NEW_DUNGEON("Log_NewDungeon", "&6New Dungeon"),
|
||||
LOG_NEW_PLAYER_DATA("Log_NewPlayerData", "&6A new player data file has been created and saved as &v1."),
|
||||
LOG_WORLD_GENERATION_FINISHED("Log_WorldGenerationFinished", "&6World generation finished!"),
|
||||
PLAYER_BLOCK_INFO("Player_BlockInfo", "&6Block-ID: &2&v1"),
|
||||
PLAYER_CHECKPOINT_REACHED("Player_CheckpointReached", "&6Checkpoint reached!"),
|
||||
|
@ -17,10 +17,14 @@
|
||||
package io.github.dre2n.dungeonsxl.config;
|
||||
|
||||
import io.github.dre2n.commons.config.BRConfig;
|
||||
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
@ -55,7 +59,7 @@ public class PlayerData extends BRConfig {
|
||||
* @return the time when the player finished the dungeon for the last time
|
||||
*/
|
||||
public long getTimeLastPlayed(String dungeon) {
|
||||
Long time = timeLastPlayed.get(dungeon);
|
||||
Long time = timeLastPlayed.get(dungeon.toLowerCase());
|
||||
if (time == null) {
|
||||
return -1;
|
||||
} else {
|
||||
@ -70,7 +74,7 @@ public class PlayerData extends BRConfig {
|
||||
* the time when the dungeon was finished
|
||||
*/
|
||||
public void setTimeLastPlayed(String dungeon, long time) {
|
||||
timeLastPlayed.put(dungeon, time);
|
||||
timeLastPlayed.put(dungeon.toLowerCase(), time);
|
||||
save();
|
||||
}
|
||||
|
||||
@ -79,7 +83,7 @@ public class PlayerData extends BRConfig {
|
||||
* the finished dungeon
|
||||
*/
|
||||
public void logTimeLastPlayed(String dungeon) {
|
||||
timeLastPlayed.put(dungeon, System.currentTimeMillis());
|
||||
timeLastPlayed.put(dungeon.toLowerCase(), System.currentTimeMillis());
|
||||
save();
|
||||
}
|
||||
|
||||
@ -89,16 +93,30 @@ public class PlayerData extends BRConfig {
|
||||
config.createSection("timeLastPlayed");
|
||||
}
|
||||
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
MessageUtil.log(plugin, DMessages.LOG_NEW_PLAYER_DATA.getMessage(file.getName()));
|
||||
} catch (IOException exception) {
|
||||
}
|
||||
}
|
||||
|
||||
save();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
if (config.contains("timeLastPlayed")) {
|
||||
if (config.isConfigurationSection("timeLastPlayed")) {
|
||||
for (String key : config.getConfigurationSection("timeLastPlayed").getKeys(false)) {
|
||||
timeLastPlayed.put(key, config.getLong(key));
|
||||
timeLastPlayed.put(key, config.getLong("timeLastPlayed." + key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
config.set("timeLastPlayed", timeLastPlayed);
|
||||
super.save();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -79,8 +79,8 @@ public class Game {
|
||||
started = false;
|
||||
world = new GameWorld();
|
||||
dGroup.setGameWorld(world);
|
||||
fetchRules();
|
||||
world.load(worldName);
|
||||
fetchRules();
|
||||
}
|
||||
|
||||
public Game(DGroup dGroup, GameType type, GameWorld world) {
|
||||
|
@ -196,12 +196,12 @@ public class DPortal extends GlobalProtection {
|
||||
}
|
||||
|
||||
if (game == null) {
|
||||
game = new Game(dGroup);
|
||||
game = new Game(dGroup, target);
|
||||
} else {
|
||||
game.setWorld(target);
|
||||
dGroup.setGameWorld(target);
|
||||
}
|
||||
|
||||
game.setWorld(target);
|
||||
dGroup.setGameWorld(target);
|
||||
|
||||
new DGamePlayer(player, target);
|
||||
}
|
||||
|
||||
|
@ -40,15 +40,12 @@ import io.github.dre2n.dungeonsxl.reward.Reward;
|
||||
import io.github.dre2n.dungeonsxl.trigger.DistanceTrigger;
|
||||
import io.github.dre2n.dungeonsxl.world.GameWorld;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Damageable;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -452,7 +449,7 @@ public class DGamePlayer extends DInstancePlayer {
|
||||
return true;
|
||||
}
|
||||
|
||||
GameRules rules = Game.getByPlayer(player).getRules();
|
||||
GameRules rules = game.getRules();
|
||||
|
||||
if (!checkTime(game)) {
|
||||
MessageUtil.sendMessage(player, DMessages.ERROR_COOLDOWN.getMessage(String.valueOf(rules.getTimeToNextPlay())));
|
||||
@ -521,6 +518,7 @@ public class DGamePlayer extends DInstancePlayer {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -540,7 +538,6 @@ public class DGamePlayer extends DInstancePlayer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -549,8 +546,6 @@ public class DGamePlayer extends DInstancePlayer {
|
||||
}
|
||||
|
||||
public void ready(GameType gameType) {
|
||||
ready = true;
|
||||
|
||||
DGroup dGroup = DGroup.getByPlayer(getPlayer());
|
||||
|
||||
if (dGroup == null) {
|
||||
@ -564,12 +559,15 @@ public class DGamePlayer extends DInstancePlayer {
|
||||
} else {
|
||||
game.setType(gameType);
|
||||
}
|
||||
game.fetchRules();
|
||||
|
||||
if (!checkRequirements(game)) {
|
||||
MessageUtil.sendMessage(player, DMessages.ERROR_REQUIREMENTS.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
ready = true;
|
||||
|
||||
for (DGroup gameGroup : game.getDGroups()) {
|
||||
if (!gameGroup.isPlaying()) {
|
||||
gameGroup.startGame(game);
|
||||
@ -633,11 +631,7 @@ public class DGamePlayer extends DInstancePlayer {
|
||||
}
|
||||
}
|
||||
|
||||
boolean invalid = false;
|
||||
|
||||
if (dGroup.getDungeon() == null) {
|
||||
invalid = true;
|
||||
}
|
||||
boolean invalid = !dGroup.getDungeon().isMultiFloor();
|
||||
|
||||
for (Player player : dGroup.getPlayers()) {
|
||||
DGamePlayer dPlayer = getByPlayer(player);
|
||||
|
@ -103,9 +103,9 @@ public class DGroup {
|
||||
addPlayer(player);
|
||||
}
|
||||
|
||||
Dungeon dungeon = plugin.getDungeons().getDungeon(identifier);
|
||||
dungeon = plugin.getDungeons().getDungeon(identifier);
|
||||
if (multiFloor && dungeon != null) {
|
||||
dungeonName = identifier;
|
||||
dungeonName = dungeon.getName();
|
||||
mapName = dungeon.getConfig().getStartFloor();
|
||||
unplayedFloors = dungeon.getConfig().getFloors();
|
||||
|
||||
@ -295,6 +295,21 @@ public class DGroup {
|
||||
this.gameWorld = gameWorld;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dungeon
|
||||
*/
|
||||
public Dungeon getDungeon() {
|
||||
return dungeon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dungeon
|
||||
* the dungeon to set
|
||||
*/
|
||||
public void setDungeon(Dungeon dungeon) {
|
||||
this.dungeon = dungeon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dungeonName
|
||||
*/
|
||||
@ -310,21 +325,6 @@ public class DGroup {
|
||||
this.dungeonName = dungeonName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dungeon
|
||||
*/
|
||||
public Dungeon getDungeon() {
|
||||
return dungeon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dungeon
|
||||
* the dungeon to set (saved by name only)
|
||||
*/
|
||||
public void setDungeon(Dungeon dungeon) {
|
||||
dungeonName = dungeon.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the group is playing
|
||||
*/
|
||||
|
@ -117,10 +117,10 @@ public class ReadySign extends DSign {
|
||||
if (getGameWorld().getSignClass().isEmpty() || dPlayer.getDClass() != null) {
|
||||
GameType forced = getGameWorld().getConfig().getForcedGameType();
|
||||
dPlayer.ready(forced == null ? gameType : forced);
|
||||
MessageUtil.sendMessage(dPlayer.getPlayer(), plugin.getMessageConfig().getMessage(DMessages.PLAYER_READY));
|
||||
}
|
||||
|
||||
} else {
|
||||
MessageUtil.sendMessage(dPlayer.getPlayer(), plugin.getMessageConfig().getMessage(DMessages.ERROR_READY));
|
||||
if (dPlayer.isReady()) {
|
||||
MessageUtil.sendMessage(dPlayer.getPlayer(), plugin.getMessageConfig().getMessage(dPlayer.isReady() ? DMessages.PLAYER_READY : DMessages.ERROR_READY));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user