Rewrite player data handling

This commit is contained in:
Daniel Saukel 2016-05-18 19:24:45 +02:00
parent 0a9149eb69
commit b3003ac3ed
17 changed files with 301 additions and 269 deletions

View File

@ -69,8 +69,6 @@ Instead of referencing the internals of the implementation directly, DungeonsXL
The shaded version of DXL (standard version) contains this library, while the original version needs it as an external plugin.
Have a look at the [installation instructions](../../wiki/getting-started#installation) for detailed information.
DungeonsXL currently uses BRCommons 0.6.3.
### Java
7 and higher

View File

@ -25,7 +25,7 @@ import io.github.dre2n.commons.util.FileUtil;
import io.github.dre2n.dungeonsxl.announcer.Announcers;
import io.github.dre2n.dungeonsxl.command.*;
import io.github.dre2n.dungeonsxl.config.DMessages;
import io.github.dre2n.dungeonsxl.config.DataConfig;
import io.github.dre2n.dungeonsxl.config.GlobalData;
import io.github.dre2n.dungeonsxl.config.MainConfig;
import io.github.dre2n.dungeonsxl.dungeon.Dungeons;
import io.github.dre2n.dungeonsxl.game.Game;
@ -70,13 +70,14 @@ public class DungeonsXL extends BRPlugin {
public static File DUNGEONS;
public static File LANGUAGES;
public static File MAPS;
public static File PLAYERS;
public static File SCRIPTS;
public static File ANNOUNCERS;
public static File CLASSES;
public static File MOBS;
public static File SIGNS;
private DataConfig dataConfig;
private GlobalData globalData;
private MainConfig mainConfig;
private MessageConfig messageConfig;
@ -135,7 +136,7 @@ public class DungeonsXL extends BRPlugin {
// Load Language
loadMessageConfig(new File(getDataFolder(), "languages/en.yml"));
// Load Config
loadDataConfig(new File(getDataFolder(), "data.yml"));
loadGlobalData(new File(getDataFolder(), "data.yml"));
loadMainConfig(new File(getDataFolder(), "config.yml"));
// Load Language 2
loadMessageConfig(new File(LANGUAGES, mainConfig.getLanguage() + ".yml"));
@ -227,6 +228,11 @@ public class DungeonsXL extends BRPlugin {
MAPS.mkdir();
}
PLAYERS = new File(getDataFolder(), "players");
if (!PLAYERS.exists()) {
PLAYERS.mkdir();
}
SCRIPTS = new File(getDataFolder(), "scripts");
if (!SCRIPTS.exists()) {
SCRIPTS.mkdir();
@ -299,17 +305,17 @@ public class DungeonsXL extends BRPlugin {
}
/**
* @return the loaded instance of DataConfig
* @return the loaded instance of GlobalData
*/
public DataConfig getDataConfig() {
return dataConfig;
public GlobalData getGlobalData() {
return globalData;
}
/**
* load / reload a new instance of MainConfig
* load / reload a new instance of GlobalData
*/
public void loadDataConfig(File file) {
dataConfig = new DataConfig(file);
public void loadGlobalData(File file) {
globalData = new GlobalData(file);
}
/**

View File

@ -21,7 +21,6 @@ import io.github.dre2n.commons.util.messageutil.MessageUtil;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.DMessages;
import io.github.dre2n.dungeonsxl.config.DungeonConfig;
import io.github.dre2n.dungeonsxl.config.WorldConfig;
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent;
import io.github.dre2n.dungeonsxl.game.Game;
@ -29,8 +28,6 @@ import io.github.dre2n.dungeonsxl.player.DGamePlayer;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPermissions;
import io.github.dre2n.dungeonsxl.world.EditWorld;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import java.io.File;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -92,24 +89,6 @@ public class PlayCommand extends BRCommand {
return;
}
if (!GameWorld.canPlayDungeon(identifier, player)) {
File file = new File(plugin.getDataFolder() + "/maps/" + identifier + "/config.yml");
if (file.exists()) {
WorldConfig confReader = new WorldConfig(file);
if (confReader != null) {
MessageUtil.sendMessage(player, DMessages.ERROR_COOLDOWN.getMessage(String.valueOf(confReader.getTimeToNextPlay())));
}
}
return;
}
if (!GameWorld.checkRequirements(mapName, player)) {
MessageUtil.sendMessage(player, DMessages.ERROR_REQUIREMENTS.getMessage());
return;
}
DGroup dGroup = DGroup.getByPlayer(player);
if (dGroup != null) {

View File

@ -71,7 +71,7 @@ public class ReloadCommand extends BRCommand {
// Load Language
plugin.loadMessageConfig(new File(plugin.getDataFolder(), "languages/en.yml"));
// Load Config
plugin.loadDataConfig(new File(plugin.getDataFolder(), "data.yml"));
plugin.loadGlobalData(new File(plugin.getDataFolder(), "data.yml"));
plugin.loadMainConfig(new File(plugin.getDataFolder(), "config.yml"));
// Load Language 2
plugin.loadMessageConfig(new File(plugin.getDataFolder(), "languages/" + plugin.getMainConfig().getLanguage() + ".yml"));

View File

@ -22,11 +22,11 @@ import java.io.File;
/**
* @author Daniel Saukel
*/
public class DataConfig extends BRConfig {
public class GlobalData extends BRConfig {
public static final int CONFIG_VERSION = 2;
public DataConfig(File file) {
public GlobalData(File file) {
super(file, CONFIG_VERSION);
if (initialize) {

View File

@ -0,0 +1,104 @@
/*
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.dre2n.dungeonsxl.config;
import io.github.dre2n.commons.config.BRConfig;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
/**
* @author Daniel Saukel
*/
public class PlayerData extends BRConfig {
DungeonsXL plugin = DungeonsXL.getInstance();
public static final int CONFIG_VERSION = 1;
private Map<String, Long> timeLastPlayed = new HashMap<>();
public PlayerData(File file) {
super(file, CONFIG_VERSION);
if (initialize) {
initialize();
}
load();
}
/**
* @return a map of the player's finished dungeons with dates.
*/
public Map<String, Long> getTimeLastPlayed() {
return timeLastPlayed;
}
/**
* @param dungeon
* the dungeon to check
* @return the time when the player finished the dungeon for the last time
*/
public long getTimeLastPlayed(String dungeon) {
Long time = timeLastPlayed.get(dungeon);
if (time == null) {
return -1;
} else {
return time;
}
}
/**
* @param dungeon
* the finished dungeon
* @param time
* the time when the dungeon was finished
*/
public void setTimeLastPlayed(String dungeon, long time) {
timeLastPlayed.put(dungeon, time);
save();
}
/**
* @param dungeon
* the finished dungeon
*/
public void logTimeLastPlayed(String dungeon) {
timeLastPlayed.put(dungeon, System.currentTimeMillis());
save();
}
@Override
public void initialize() {
if (!config.contains("timeLastPlayed")) {
config.createSection("timeLastPlayed");
}
save();
}
@Override
public void load() {
if (config.contains("timeLastPlayed")) {
for (String key : config.getConfigurationSection("timeLastPlayed").getKeys(false)) {
timeLastPlayed.put(key, config.getLong(key));
}
}
}
}

View File

@ -181,6 +181,10 @@ public class WorldConfig extends GameRules {
/* Dungeon Requirements */
if (configFile.contains("requirements")) {
if (requirements == null) {
requirements = new ArrayList<>();
}
for (String identifier : configFile.getConfigurationSection("requirements").getKeys(false)) {
Requirement requirement = Requirement.create(plugin.getRequirementTypes().getByIdentifier(identifier));
@ -225,13 +229,7 @@ public class WorldConfig extends GameRules {
}
if (configFile.contains("forcedGameType")) {
GameType gameType = plugin.getGameTypes().getByName(configFile.getString("forcedGameType"));
if (gameType != null) {
forcedGameType = gameType;
} else {
forcedGameType = null;
}
forcedGameType = plugin.getGameTypes().getByName(configFile.getString("forcedGameType"));
}
}

View File

@ -35,7 +35,11 @@ public class Dungeon {
public Dungeon(String name) {
this.name = name;
this.config = new DungeonConfig(new File(DungeonsXL.getInstance().getDataFolder() + "/dungeons", name + ".yml"));
File file = new File(DungeonsXL.getInstance().getDataFolder() + "/dungeons", name + ".yml");
if (file.exists()) {
this.config = new DungeonConfig(file);
}
}
/**
@ -52,4 +56,11 @@ public class Dungeon {
return config;
}
/**
* @return if this dungeon has multiple floors
*/
public boolean isMultiFloor() {
return config != null;
}
}

View File

@ -20,7 +20,6 @@ import io.github.dre2n.commons.util.messageutil.MessageUtil;
import io.github.dre2n.dungeonsxl.sign.DSign;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.block.Sign;
/**
* @author Daniel Saukel

View File

@ -19,12 +19,9 @@ package io.github.dre2n.dungeonsxl.global;
import io.github.dre2n.commons.util.BlockUtil;
import io.github.dre2n.commons.util.messageutil.MessageUtil;
import io.github.dre2n.dungeonsxl.config.DMessages;
import io.github.dre2n.dungeonsxl.config.WorldConfig;
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
import io.github.dre2n.dungeonsxl.game.Game;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import java.io.File;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
@ -489,23 +486,6 @@ public class GameSign extends GlobalProtection {
return true;
}
if (!GameWorld.canPlayDungeon(gameSign.mapName, dGroup)) {
File file = new File(plugin.getDataFolder() + "/maps/" + gameSign.mapName, "config.yml");
if (file != null) {
WorldConfig confReader = new WorldConfig(file);
if (confReader != null) {
dGroup.sendMessage(plugin.getMessageConfig().getMessage(DMessages.ERROR_COOLDOWN, String.valueOf(confReader.getTimeToNextPlay())));
}
}
return true;
}
if (!GameWorld.checkRequirements(gameSign.mapName, dGroup)) {
dGroup.sendMessage(plugin.getMessageConfig().getMessage(DMessages.ERROR_REQUIREMENTS));
return true;
}
int sx1 = gameSign.startSign.getX(), sy1 = gameSign.startSign.getY(), sz1 = gameSign.startSign.getZ();
Block topBlock = block.getRelative(0, sy1 - y, 0);

View File

@ -19,7 +19,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
public abstract class GlobalProtection {
static DungeonsXL plugin = DungeonsXL.getInstance();
static FileConfiguration config = plugin.getDataConfig().getConfig();
static FileConfiguration config = plugin.getGlobalData().getConfig();
static GlobalProtections protections = plugin.getGlobalProtections();
private World world;

View File

@ -86,7 +86,7 @@ public class GlobalProtections {
* Save all protections to the default file
*/
public void saveAll() {
saveAll(plugin.getDataConfig().getConfig());
saveAll(plugin.getGlobalData().getConfig());
}
/**
@ -107,7 +107,7 @@ public class GlobalProtections {
protection.save(config);
}
plugin.getDataConfig().save();
plugin.getGlobalData().save();
}
/**
@ -144,7 +144,7 @@ public class GlobalProtections {
/* SUBJECT TO CHANGE */
@Deprecated
public void loadAll() {
FileConfiguration data = plugin.getDataConfig().getConfig();
FileConfiguration data = plugin.getGlobalData().getConfig();
for (World world : plugin.getServer().getWorlds()) {
// GameSigns

View File

@ -19,11 +19,8 @@ package io.github.dre2n.dungeonsxl.global;
import io.github.dre2n.commons.util.BlockUtil;
import io.github.dre2n.commons.util.messageutil.MessageUtil;
import io.github.dre2n.dungeonsxl.config.DMessages;
import io.github.dre2n.dungeonsxl.config.WorldConfig;
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import java.io.File;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
@ -458,23 +455,6 @@ public class GroupSign extends GlobalProtection {
return true;
}
if (!GameWorld.canPlayDungeon(groupSign.mapName, player)) {
File file = new File(plugin.getDataFolder() + "/maps/" + groupSign.mapName, "config.yml");
if (file != null) {
WorldConfig confReader = new WorldConfig(file);
if (confReader != null) {
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(DMessages.ERROR_COOLDOWN, String.valueOf(confReader.getTimeToNextPlay())));
}
}
return true;
}
if (!GameWorld.checkRequirements(groupSign.mapName, player)) {
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(DMessages.ERROR_REQUIREMENTS));
return true;
}
int sx1 = groupSign.startSign.getX(), sy1 = groupSign.startSign.getY(), sz1 = groupSign.startSign.getZ();
Block topBlock = block.getRelative(0, sy1 - y, 0);

View File

@ -19,6 +19,7 @@ package io.github.dre2n.dungeonsxl.player;
import io.github.dre2n.commons.util.NumberUtil;
import io.github.dre2n.commons.util.messageutil.MessageUtil;
import io.github.dre2n.commons.util.playerutil.PlayerUtil;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.DMessages;
import io.github.dre2n.dungeonsxl.config.DungeonConfig;
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupFinishDungeonEvent;
@ -27,11 +28,13 @@ import io.github.dre2n.dungeonsxl.event.dgroup.DGroupRewardEvent;
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerFinishEvent;
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerKickEvent;
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerUpdateEvent;
import io.github.dre2n.dungeonsxl.event.requirement.RequirementCheckEvent;
import io.github.dre2n.dungeonsxl.game.Game;
import io.github.dre2n.dungeonsxl.game.GameRules;
import io.github.dre2n.dungeonsxl.game.GameType;
import io.github.dre2n.dungeonsxl.game.GameTypeDefault;
import io.github.dre2n.dungeonsxl.mob.DMob;
import io.github.dre2n.dungeonsxl.requirement.Requirement;
import io.github.dre2n.dungeonsxl.reward.DLootInventory;
import io.github.dre2n.dungeonsxl.reward.Reward;
import io.github.dre2n.dungeonsxl.trigger.DistanceTrigger;
@ -396,27 +399,7 @@ public class DGamePlayer extends DInstancePlayer {
addTreasure();
// Set Time
File file = new File(plugin.getDataFolder() + "/maps/" + gameWorld.getMapName(), "players.yml");
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
FileConfiguration playerConfig = YamlConfiguration.loadConfiguration(file);
playerConfig.set(getPlayer().getUniqueId().toString(), System.currentTimeMillis());
try {
playerConfig.save(file);
} catch (IOException exception) {
exception.printStackTrace();
}
getData().logTimeLastPlayed(dGroup.getDungeon().getName());
// Tutorial Permissions
if (gameWorld.isTutorial()) {
@ -464,6 +447,103 @@ public class DGamePlayer extends DInstancePlayer {
}
}
public boolean checkRequirements(Game game) {
if (DPermissions.hasPermission(player, DPermissions.IGNORE_REQUIREMENTS)) {
return true;
}
GameRules rules = Game.getByPlayer(player).getRules();
if (!checkTime(game)) {
MessageUtil.sendMessage(player, DMessages.ERROR_COOLDOWN.getMessage(String.valueOf(rules.getTimeToNextPlay())));
return false;
}
for (Requirement requirement : rules.getRequirements()) {
RequirementCheckEvent event = new RequirementCheckEvent(requirement, player);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
continue;
}
if (!requirement.check(player)) {
return false;
}
}
if (rules.getFinished() != null && rules.getFinishedAll() != null) {
if (!rules.getFinished().isEmpty()) {
long bestTime = 0;
int numOfNeeded = 0;
boolean doneTheOne = false;
if (rules.getFinished().size() == rules.getFinishedAll().size()) {
doneTheOne = true;
}
for (String played : rules.getFinished()) {
for (String dungeonName : DungeonsXL.MAPS.list()) {
if (new File(DungeonsXL.MAPS, dungeonName).isDirectory()) {
if (played.equalsIgnoreCase(dungeonName) || played.equalsIgnoreCase("any")) {
Long time = getData().getTimeLastPlayed(dungeonName);
if (time != -1) {
if (rules.getFinishedAll().contains(played)) {
numOfNeeded++;
} else {
doneTheOne = true;
}
if (bestTime < time) {
bestTime = time;
}
}
break;
}
}
}
}
if (bestTime == 0) {
return false;
} else if (rules.getTimeLastPlayed() != 0) {
if (System.currentTimeMillis() - bestTime > rules.getTimeLastPlayed() * (long) 3600000) {
return false;
}
}
if (numOfNeeded < rules.getFinishedAll().size() || !doneTheOne) {
return false;
}
}
}
return true;
}
public boolean checkTime(Game game) {
if (DPermissions.hasPermission(player, DPermissions.IGNORE_TIME_LIMIT)) {
return true;
}
GameRules rules = game.getRules();
if (rules.getTimeToNextPlay() != 0) {
// 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;
}
public void ready() {
ready(GameTypeDefault.DEFAULT);
}
@ -485,6 +565,11 @@ public class DGamePlayer extends DInstancePlayer {
game.setType(gameType);
}
if (!checkRequirements(game)) {
MessageUtil.sendMessage(player, DMessages.ERROR_REQUIREMENTS.getMessage());
return;
}
for (DGroup gameGroup : game.getDGroups()) {
if (!gameGroup.isPlaying()) {
gameGroup.startGame(game);

View File

@ -17,7 +17,9 @@
package io.github.dre2n.dungeonsxl.player;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.PlayerData;
import io.github.dre2n.dungeonsxl.global.DPortal;
import java.io.File;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -32,6 +34,8 @@ public class DGlobalPlayer {
protected Player player;
private PlayerData data;
private boolean breakMode;
private boolean chatSpyMode;
private DPortal creatingPortal;
@ -41,6 +45,7 @@ public class DGlobalPlayer {
public DGlobalPlayer(Player player) {
this.player = player;
loadPlayerData(new File(DungeonsXL.PLAYERS, player.getUniqueId().toString() + ".yml"));
plugin.getDPlayers().addPlayer(this);
}
@ -63,6 +68,20 @@ public class DGlobalPlayer {
return player;
}
/**
* @return the saved data
*/
public PlayerData getData() {
return data;
}
/**
* Load / reload a new instance of PlayerData
*/
public void loadPlayerData(File file) {
data = new PlayerData(file);
}
/**
* @return if the player is in break mode
*/

View File

@ -54,6 +54,7 @@ public class DGroup {
private Player captain;
private CopyOnWriteArrayList<Player> players = new CopyOnWriteArrayList<>();
private List<UUID> invitedPlayers = new ArrayList<>();
private Dungeon dungeon;
private String dungeonName;
private String mapName;
private List<String> unplayedFloors = new ArrayList<>();
@ -110,7 +111,9 @@ public class DGroup {
} else {
mapName = identifier;
dungeon = new Dungeon(identifier);
}
playing = false;
floorCount = 0;
}
@ -308,10 +311,10 @@ public class DGroup {
}
/**
* @return the dungeon (saved by name only)
* @return the dungeon
*/
public Dungeon getDungeon() {
return plugin.getDungeons().getDungeon(dungeonName);
return dungeon;
}
/**
@ -571,6 +574,34 @@ public class DGroup {
GroupSign.updatePerGroup(this);
}
public boolean checkTime(Game game) {
if (DPermissions.hasPermission(captain, DPermissions.IGNORE_TIME_LIMIT)) {
return true;
}
for (Player player : players) {
if (!DGamePlayer.getByPlayer(player).checkTime(game)) {
return false;
}
}
return true;
}
public boolean checkRequirements(Game game) {
if (DPermissions.hasPermission(captain, DPermissions.IGNORE_REQUIREMENTS)) {
return true;
}
for (Player player : players) {
if (!DGamePlayer.getByPlayer(player).checkRequirements(game)) {
return false;
}
}
return true;
}
/**
* Send a message to all players in the group
*/

View File

@ -25,14 +25,10 @@ import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldLoadEvent;
import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldStartGameEvent;
import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldUnloadEvent;
import io.github.dre2n.dungeonsxl.event.requirement.RequirementCheckEvent;
import io.github.dre2n.dungeonsxl.game.Game;
import io.github.dre2n.dungeonsxl.game.GamePlaceableBlock;
import io.github.dre2n.dungeonsxl.mob.DMob;
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPermissions;
import io.github.dre2n.dungeonsxl.requirement.Requirement;
import io.github.dre2n.dungeonsxl.reward.RewardChest;
import io.github.dre2n.dungeonsxl.sign.DSign;
import io.github.dre2n.dungeonsxl.sign.MobSign;
@ -53,12 +49,9 @@ import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Spider;
/**
@ -563,155 +556,4 @@ public class GameWorld {
}
}
public static boolean canPlayDungeon(String map, Player player) {
if (DPermissions.hasPermission(player, DPermissions.IGNORE_TIME_LIMIT)) {
return true;
}
if (new File(plugin.getDataFolder() + "/maps/" + map).isDirectory()) {
WorldConfig worldConfig = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + map, "config.yml"));
if (worldConfig.getTimeToNextPlay() != 0) {
// read PlayerConfig
long time = getPlayerTime(map, player);
if (time != -1) {
if (time + worldConfig.getTimeToNextPlay() * 1000 * 60 * 60 > System.currentTimeMillis()) {
return false;
}
}
}
} else {
return false;
}
return true;
}
public static boolean canPlayDungeon(String dungeon, DGroup dGroup) {
if (DPermissions.hasPermission(dGroup.getCaptain(), DPermissions.IGNORE_TIME_LIMIT)) {
return true;
}
for (Player player : dGroup.getPlayers()) {
if (!canPlayDungeon(dungeon, player)) {
return false;
}
}
return true;
}
public static long getPlayerTime(String dungeon, Player player) {
File file = new File(plugin.getDataFolder() + "/maps/" + dungeon, "players.yml");
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException exception) {
exception.printStackTrace();
}
}
FileConfiguration playerConfig = YamlConfiguration.loadConfiguration(file);
if (playerConfig.contains(player.getUniqueId().toString())) {
return playerConfig.getLong(player.getUniqueId().toString());
}
if (playerConfig.contains(player.getName())) {
return playerConfig.getLong(player.getName());
}
return -1;
}
public static boolean checkRequirements(String map, Player player) {
if (DPermissions.hasPermission(player, DPermissions.IGNORE_REQUIREMENTS)) {
return true;
}
if (new File(plugin.getDataFolder() + "/maps/" + map).isDirectory() == false) {
return false;
}
WorldConfig worldConfig = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + map, "config.yml"));
for (Requirement requirement : worldConfig.getRequirements()) {
RequirementCheckEvent event = new RequirementCheckEvent(requirement, player);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
continue;
}
if (!requirement.check(player)) {
return false;
}
}
if (worldConfig.getFinished() != null && worldConfig.getFinishedAll() != null) {
if (!worldConfig.getFinished().isEmpty()) {
long bestTime = 0;
int numOfNeeded = 0;
boolean doneTheOne = false;
if (worldConfig.getFinished().size() == worldConfig.getFinishedAll().size()) {
doneTheOne = true;
}
for (String played : worldConfig.getFinished()) {
for (String dungeonName : new File(plugin.getDataFolder() + "/maps").list()) {
if (new File(plugin.getDataFolder() + "/maps/" + dungeonName).isDirectory()) {
if (played.equalsIgnoreCase(dungeonName) || played.equalsIgnoreCase("any")) {
Long time = getPlayerTime(dungeonName, player);
if (time != -1) {
if (worldConfig.getFinishedAll().contains(played)) {
numOfNeeded++;
} else {
doneTheOne = true;
}
if (bestTime < time) {
bestTime = time;
}
}
break;
}
}
}
}
if (bestTime == 0) {
return false;
} else if (worldConfig.getTimeLastPlayed() != 0) {
if (System.currentTimeMillis() - bestTime > worldConfig.getTimeLastPlayed() * (long) 3600000) {
return false;
}
}
if (numOfNeeded < worldConfig.getFinishedAll().size() || !doneTheOne) {
return false;
}
}
}
return true;
}
public static boolean checkRequirements(String map, DGroup dGroup) {
if (DPermissions.hasPermission(dGroup.getCaptain(), DPermissions.IGNORE_REQUIREMENTS)) {
return true;
}
for (Player player : dGroup.getPlayers()) {
if (!checkRequirements(map, player)) {
return false;
}
}
return true;
}
}