Overhaul requirements

This commit is contained in:
Daniel Saukel 2020-04-11 02:02:42 +02:00
parent 79ba04add4
commit 15a2b86667
20 changed files with 367 additions and 157 deletions

View File

@ -14,6 +14,7 @@
*/
package de.erethon.dungeonsxl.api;
import net.md_5.bungee.api.chat.BaseComponent;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
@ -39,6 +40,14 @@ public interface Requirement {
*/
boolean check(Player player);
/**
* Returns the message that informs the player if they fulfill the requirement.
*
* @param player the player who will receive the message
* @return the error message that is sent to the player when they do not fulfill the requirement
*/
BaseComponent[] getCheckMessage(Player player);
/**
* This is fired after the {@link #check(Player)} has been accepted. It demands the requirement from the given player. This may be empty for a "key" or may
* take something away for a "fee" requirement.

View File

@ -26,7 +26,7 @@ import org.bukkit.entity.Wolf;
*
* @author Daniel Saukel
*/
// Implementation-specific methods: isInTestMode, setReady, [wolf, group tag, requirement, loot check methods], finishFloor
// Implementation-specific methods: isInTestMode, setReady, [wolf, group tag methods], finishFloor
public interface GamePlayer extends InstancePlayer {
/**

View File

@ -16,6 +16,7 @@ package de.erethon.dungeonsxl.api.player;
import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.player.PlayerWrapper;
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;
@ -137,4 +138,14 @@ public interface GlobalPlayer extends PlayerWrapper {
*/
void reset(Location tpLoc, boolean keepInventory);
/**
* Performs a requirement check for the given dungeon.
* <p>
* This method might send messages to the player to inform him that he does not fulfill them.
*
* @param dungeon the dungeon to check
* @return if the player fulfills the requirements or may bypass them
*/
boolean checkRequirements(Dungeon dungeon);
}

View File

@ -82,6 +82,10 @@ public class PlayCommand extends DCommand {
}
group.setDungeon(dungeon);
if (!dPlayer.checkRequirements(dungeon)) {
return;
}
GameWorld gameWorld = dungeon.getMap().instantiateGameWorld(false);
if (gameWorld == null) {
MessageUtil.sendMessage(player, DMessage.ERROR_TOO_MANY_INSTANCES.getMessage());

View File

@ -199,6 +199,12 @@ public enum DMessage implements Message {
PLAYER_UNLIMITED_LIVES("player.unlimitedLives"),
PLAYER_WAIT_FOR_OTHER_PLAYERS("player.waitForOtherPlayers"),
REQUIREMENT_FEE("requirement.fee"),
REQUIREMENT_FEE_LEVEL("requirement.feeLevel"),
REQUIREMENT_FEE_MONEY("requirement.feeMoney"),
REQUIREMENT_FORBIDDEN_ITEMS("requirement.forbiddenItems"),
REQUIREMENT_GROUP_SIZE("requirement.groupSize"),
REQUIREMENT_KEY_ITEMS("requirement.keyItems"),
REQUIREMENT_PERMISSION("requirement.permission"),
REWARD_GENERAL("reward.general"),
SIGN_END("sign.end"),
SIGN_FLOOR_1("sign.floor.1"),

View File

@ -21,6 +21,7 @@ import de.erethon.caliburn.item.VanillaItem;
import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.misc.BlockUtil;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
import de.erethon.dungeonsxl.api.dungeon.Game;
import de.erethon.dungeonsxl.api.player.PlayerGroup;
import de.erethon.dungeonsxl.api.world.GameWorld;
@ -246,15 +247,22 @@ public class DPortal extends GlobalProtection {
return;
}
Dungeon dungeon = group.getDungeon();
if (dungeon == null) {
MessageUtil.sendMessage(player, DMessage.ERROR_NO_SUCH_DUNGEON.getMessage());
return;
}
if (!plugin.getPlayerCache().get(player).checkRequirements()) {
return;
}
GameWorld target = group.getGameWorld();
Game game = group.getGame();
if (target == null && game != null) {
target = game.getWorld();
}
if (target == null) {
if (game != null) {
if (target == null) {
for (PlayerGroup otherTeam : game.getGroups()) {
if (otherTeam.getGameWorld() != null) {
target = otherTeam.getGameWorld();
@ -264,8 +272,8 @@ public class DPortal extends GlobalProtection {
}
}
if (target == null && group.getDungeon() != null) {
ResourceWorld resource = group.getDungeon().getMap();
if (target == null) {
ResourceWorld resource = dungeon.getMap();
if (resource != null) {
target = resource.instantiateGameWorld(false);
if (target == null) {

View File

@ -21,9 +21,6 @@ import de.erethon.caliburn.mob.VanillaMob;
import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.player.PlayerUtil;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.api.Requirement;
import de.erethon.dungeonsxl.api.Reward;
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
import de.erethon.dungeonsxl.api.dungeon.Game;
import de.erethon.dungeonsxl.api.dungeon.GameGoal;
import de.erethon.dungeonsxl.api.dungeon.GameRule;
@ -40,14 +37,10 @@ import de.erethon.dungeonsxl.event.dplayer.DPlayerKickEvent;
import de.erethon.dungeonsxl.event.dplayer.instance.DInstancePlayerUpdateEvent;
import de.erethon.dungeonsxl.event.dplayer.instance.game.DGamePlayerFinishEvent;
import de.erethon.dungeonsxl.event.dplayer.instance.game.DGamePlayerRewardEvent;
import de.erethon.dungeonsxl.event.requirement.RequirementCheckEvent;
import de.erethon.dungeonsxl.trigger.DistanceTrigger;
import de.erethon.dungeonsxl.world.DGameWorld;
import de.erethon.dungeonsxl.world.DResourceWorld;
import de.erethon.dungeonsxl.world.block.TeamFlag;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
@ -400,7 +393,7 @@ public class DGamePlayer extends DInstancePlayer implements GamePlayer {
DGamePlayerRewardEvent dGroupRewardEvent = new DGamePlayerRewardEvent(this);
Bukkit.getPluginManager().callEvent(dGroupRewardEvent);
if (!dGroupRewardEvent.isCancelled()) {
giveLoot(rules, rules.getState(GameRule.REWARDS), dGroup.getRewards());
giveLoot(getGroup().getDungeon(), rules.getState(GameRule.REWARDS), dGroup.getRewards());
}
getData().logTimeLastFinished(getGroup().getDungeonName());
@ -482,134 +475,6 @@ public class DGamePlayer extends DInstancePlayer implements GamePlayer {
}
}
public boolean checkRequirements(Dungeon dungeon) {
if (DPermission.hasPermission(player, DPermission.IGNORE_REQUIREMENTS)) {
return true;
}
GameRuleContainer rules = dungeon.getRules();
if (!checkTimeAfterStart(dungeon) && !checkTimeAfterFinish(dungeon)) {
int longestTime = rules.getState(GameRule.TIME_TO_NEXT_PLAY_AFTER_START) >= rules.getState(GameRule.TIME_TO_NEXT_PLAY_AFTER_FINISH)
? rules.getState(GameRule.TIME_TO_NEXT_PLAY_AFTER_START) : rules.getState(GameRule.TIME_TO_NEXT_PLAY_AFTER_FINISH);
MessageUtil.sendMessage(player, DMessage.ERROR_COOLDOWN.getMessage(String.valueOf(longestTime)));
return false;
} else if (!checkTimeAfterStart(dungeon)) {
MessageUtil.sendMessage(player, DMessage.ERROR_COOLDOWN.getMessage(String.valueOf(rules.getState(GameRule.TIME_TO_NEXT_PLAY_AFTER_START))));
return false;
} else if (!checkTimeAfterFinish(dungeon)) {
MessageUtil.sendMessage(player, DMessage.ERROR_COOLDOWN.getMessage(String.valueOf(rules.getState(GameRule.TIME_TO_NEXT_PLAY_AFTER_FINISH))));
return false;
}
for (Requirement requirement : rules.getState(GameRule.REQUIREMENTS)) {
RequirementCheckEvent event = new RequirementCheckEvent(requirement, player);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
continue;
}
if (!requirement.check(player)) {
return false;
}
}
if (rules.getState(GameRule.MUST_FINISH_ALL) != null) {
List<String> finished = new ArrayList<>(rules.getState(GameRule.MUST_FINISH_ALL));
if (rules.getState(GameRule.MUST_FINISH_ONE) != null) {
finished.addAll(rules.getState(GameRule.MUST_FINISH_ONE));
}
if (!finished.isEmpty()) {
long bestTime = 0;
int numOfNeeded = 0;
boolean doneTheOne = false;
if (finished.size() == rules.getState(GameRule.MUST_FINISH_ALL).size()) {
doneTheOne = true;
}
for (String played : finished) {
for (String dungeonName : DungeonsXL.MAPS.list()) {
if (new File(DungeonsXL.MAPS, dungeonName).isDirectory()) {
if (played.equalsIgnoreCase(dungeonName) || played.equalsIgnoreCase("any")) {
Long time = getData().getTimeLastFinished(dungeonName);
if (time != -1) {
if (rules.getState(GameRule.MUST_FINISH_ALL).contains(played)) {
numOfNeeded++;
} else {
doneTheOne = true;
}
if (bestTime < time) {
bestTime = time;
}
}
break;
}
}
}
}
if (bestTime == 0) {
return false;
} else if (rules.getState(GameRule.TIME_LAST_PLAYED_REQUIRED_DUNGEONS) != 0) {
if (System.currentTimeMillis() - bestTime > rules.getState(GameRule.TIME_LAST_PLAYED_REQUIRED_DUNGEONS) * (long) 3600000) {
return false;
}
}
if (numOfNeeded < rules.getState(GameRule.MUST_FINISH_ALL).size() || !doneTheOne) {
return false;
}
}
}
return true;
}
public boolean checkTimeAfterStart(Dungeon dungeon) {
return checkTime(dungeon, dungeon.getRules().getState(GameRule.TIME_TO_NEXT_PLAY_AFTER_START),
getData().getTimeLastStarted(dungeon.getName()));
}
public boolean checkTimeAfterFinish(Dungeon dungeon) {
return checkTime(dungeon, dungeon.getRules().getState(GameRule.TIME_TO_NEXT_PLAY_AFTER_FINISH),
getData().getTimeLastFinished(dungeon.getName()));
}
public boolean checkTime(Dungeon dungeon, int requirement, long dataTime) {
if (DPermission.hasPermission(player, DPermission.IGNORE_TIME_LIMIT)) {
return true;
}
return dataTime == -1 || dataTime + requirement * 1000 * 60 * 60 <= System.currentTimeMillis();
}
public void giveLoot(GameRuleContainer rules, List<Reward> ruleRewards, List<Reward> groupRewards) {
if (!canLoot(rules)) {
return;
}
ruleRewards.forEach(r -> r.giveTo(player.getPlayer()));
groupRewards.forEach(r -> r.giveTo(player.getPlayer()));
getData().logTimeLastLoot(dGroup.getDungeon().getName());
}
public boolean canLoot(GameRuleContainer rules) {
return getTimeNextLoot(rules) <= getData().getTimeLastStarted(getGroup().getDungeonName());
}
public long getTimeNextLoot(GameRuleContainer rules) {
return rules.getState(GameRule.TIME_TO_NEXT_LOOT) * 60 * 60 * 1000 + getData().getTimeLastLoot(getGroup().getDungeonName());
}
@Override
public boolean ready() {
return ready(true);
@ -626,8 +491,7 @@ public class DGamePlayer extends DInstancePlayer implements GamePlayer {
}
game.setRewards(rewards);
if (!checkRequirements(game.getDungeon())) {
MessageUtil.sendMessage(player, DMessage.ERROR_REQUIREMENTS.getMessage());
if (rewards && !checkRequirements(game.getDungeon())) {
return false;
}

View File

@ -20,16 +20,22 @@ import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.compatibility.Internals;
import de.erethon.commons.player.PlayerUtil;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.api.Requirement;
import de.erethon.dungeonsxl.api.Reward;
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
import de.erethon.dungeonsxl.api.dungeon.GameRule;
import de.erethon.dungeonsxl.api.dungeon.GameRuleContainer;
import de.erethon.dungeonsxl.api.player.GlobalPlayer;
import de.erethon.dungeonsxl.api.player.PlayerGroup;
import de.erethon.dungeonsxl.api.world.GameWorld;
import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.dungeon.DGame;
import de.erethon.dungeonsxl.event.dgroup.DGroupCreateEvent;
import de.erethon.dungeonsxl.event.requirement.RequirementCheckEvent;
import de.erethon.dungeonsxl.global.DPortal;
import de.erethon.dungeonsxl.util.NBTUtil;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
@ -253,6 +259,138 @@ public class DGlobalPlayer implements GlobalPlayer {
return DPermission.hasPermission(player, permission);
}
public boolean checkRequirements(Dungeon dungeon) {
boolean fulfilled = true;
GameRuleContainer rules = dungeon.getRules();
if (!checkTimeAfterStart(dungeon) && !checkTimeAfterFinish(dungeon)) {
int longestTime = rules.getState(GameRule.TIME_TO_NEXT_PLAY_AFTER_START) >= rules.getState(GameRule.TIME_TO_NEXT_PLAY_AFTER_FINISH)
? rules.getState(GameRule.TIME_TO_NEXT_PLAY_AFTER_START) : rules.getState(GameRule.TIME_TO_NEXT_PLAY_AFTER_FINISH);
MessageUtil.sendMessage(player, DMessage.ERROR_COOLDOWN.getMessage(String.valueOf(longestTime)));
fulfilled = false;
} else if (!checkTimeAfterStart(dungeon)) {
MessageUtil.sendMessage(player, DMessage.ERROR_COOLDOWN.getMessage(String.valueOf(rules.getState(GameRule.TIME_TO_NEXT_PLAY_AFTER_START))));
fulfilled = false;
} else if (!checkTimeAfterFinish(dungeon)) {
MessageUtil.sendMessage(player, DMessage.ERROR_COOLDOWN.getMessage(String.valueOf(rules.getState(GameRule.TIME_TO_NEXT_PLAY_AFTER_FINISH))));
fulfilled = false;
}
boolean genericReqs = true;
for (Requirement requirement : rules.getState(GameRule.REQUIREMENTS)) {
RequirementCheckEvent event = new RequirementCheckEvent(requirement, player);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
continue;
}
if (!requirement.check(player)) {
fulfilled = false;
genericReqs = false;
}
}
if (!genericReqs) {
MessageUtil.sendMessage(player, DMessage.ERROR_REQUIREMENTS.getMessage());
rules.getState(GameRule.REQUIREMENTS).forEach(r -> MessageUtil.sendMessage(player, r.getCheckMessage(player)));
}
if (rules.getState(GameRule.MUST_FINISH_ALL) != null) {
List<String> finished = new ArrayList<>(rules.getState(GameRule.MUST_FINISH_ALL));
if (rules.getState(GameRule.MUST_FINISH_ONE) != null) {
finished.addAll(rules.getState(GameRule.MUST_FINISH_ONE));
}
if (!finished.isEmpty()) {
long bestTime = 0;
int numOfNeeded = 0;
boolean doneTheOne = false;
if (finished.size() == rules.getState(GameRule.MUST_FINISH_ALL).size()) {
doneTheOne = true;
}
for (String played : finished) {
for (String dungeonName : DungeonsXL.MAPS.list()) {
if (new File(DungeonsXL.MAPS, dungeonName).isDirectory()) {
if (played.equalsIgnoreCase(dungeonName) || played.equalsIgnoreCase("any")) {
Long time = getData().getTimeLastFinished(dungeonName);
if (time != -1) {
if (rules.getState(GameRule.MUST_FINISH_ALL).contains(played)) {
numOfNeeded++;
} else {
doneTheOne = true;
}
if (bestTime < time) {
bestTime = time;
}
}
break;
}
}
}
}
if (bestTime == 0) {
fulfilled = false;
} else if (rules.getState(GameRule.TIME_LAST_PLAYED_REQUIRED_DUNGEONS) != 0) {
if (System.currentTimeMillis() - bestTime > rules.getState(GameRule.TIME_LAST_PLAYED_REQUIRED_DUNGEONS) * (long) 3600000) {
fulfilled = false;
}
}
if (numOfNeeded < rules.getState(GameRule.MUST_FINISH_ALL).size() || !doneTheOne) {
fulfilled = false;
}
}
}
return fulfilled || DPermission.hasPermission(player, DPermission.IGNORE_REQUIREMENTS);
}
public boolean checkTimeAfterStart(Dungeon dungeon) {
return checkTime(dungeon, dungeon.getRules().getState(GameRule.TIME_TO_NEXT_PLAY_AFTER_START),
getData().getTimeLastStarted(dungeon.getName()));
}
public boolean checkTimeAfterFinish(Dungeon dungeon) {
return checkTime(dungeon, dungeon.getRules().getState(GameRule.TIME_TO_NEXT_PLAY_AFTER_FINISH),
getData().getTimeLastFinished(dungeon.getName()));
}
public boolean checkTime(Dungeon dungeon, int requirement, long dataTime) {
if (DPermission.hasPermission(player, DPermission.IGNORE_TIME_LIMIT)) {
return true;
}
return dataTime == -1 || dataTime + requirement * 1000 * 60 * 60 <= System.currentTimeMillis();
}
public void giveLoot(Dungeon dungeon, List<Reward> ruleRewards, List<Reward> groupRewards) {
if (!canLoot(dungeon)) {
return;
}
ruleRewards.forEach(r -> r.giveTo(player.getPlayer()));
groupRewards.forEach(r -> r.giveTo(player.getPlayer()));
if (getGroup() != null && getGroup().getDungeon() != null) {
getData().logTimeLastLoot(getGroup().getDungeon().getName());
}
}
public boolean canLoot(Dungeon dungeon) {
return getTimeNextLoot(dungeon) <= getData().getTimeLastStarted(dungeon.getName());
}
public long getTimeNextLoot(Dungeon dungeon) {
return dungeon.getRules().getState(GameRule.TIME_TO_NEXT_LOOT) * 60 * 60 * 1000 + getData().getTimeLastLoot(dungeon.getName());
}
/* Actions */
@Override
public void sendMessage(String message) {

View File

@ -761,7 +761,6 @@ public class DGroup implements PlayerGroup {
for (Requirement requirement : rules.getState(GameRule.REQUIREMENTS)) {
RequirementDemandEvent requirementDemandEvent = new RequirementDemandEvent(requirement, player);
Bukkit.getPluginManager().callEvent(event);
if (requirementDemandEvent.isCancelled()) {
continue;
}
@ -800,6 +799,7 @@ public class DGroup implements PlayerGroup {
}
}
// This is not used.
public boolean checkTime() {
if (DPermission.hasPermission(getLeader(), DPermission.IGNORE_TIME_LIMIT)) {
return true;
@ -814,6 +814,7 @@ public class DGroup implements PlayerGroup {
return true;
}
// This is not used.
public boolean checkRequirements() {
if (DPermission.hasPermission(getLeader(), DPermission.IGNORE_REQUIREMENTS)) {
return true;

View File

@ -24,7 +24,11 @@ import de.erethon.dungeonsxl.api.dungeon.GameRule;
import de.erethon.dungeonsxl.api.dungeon.GameRuleContainer;
import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.player.DGamePlayer;
import de.erethon.dungeonsxl.player.DGlobalPlayer;
import de.erethon.dungeonsxl.player.DPlayerData;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
@ -65,12 +69,26 @@ public class FeeLevelRequirement implements Requirement {
@Override
public boolean check(Player player) {
return getRelevantLevel(player) >= fee;
}
@Override
public BaseComponent[] getCheckMessage(Player player) {
int level = getRelevantLevel(player);
ChatColor color = level >= fee ? ChatColor.GREEN : ChatColor.DARK_RED;
return new ComponentBuilder(DMessage.REQUIREMENT_FEE_LEVEL.getMessage() + ": ").color(ChatColor.GOLD)
.append(String.valueOf(level)).color(color)
.append("/" + fee).color(ChatColor.WHITE)
.create();
}
private int getRelevantLevel(Player player) {
if (isKeepInventory(player)) {
return player.getLevel() >= fee;
return player.getLevel();
}
DGamePlayer dPlayer = (DGamePlayer) api.getPlayerCache().getGamePlayer(player);
return dPlayer != null ? dPlayer.getData().getOldLevel() >= fee : true;
DGlobalPlayer dPlayer = (DGlobalPlayer) api.getPlayerCache().get(player);
return dPlayer.getData().getOldLevel();
}
@Override
@ -109,4 +127,9 @@ public class FeeLevelRequirement implements Requirement {
return keepInventory;
}
@Override
public String toString() {
return "FeeLevelRequirement{fee=" + fee + "}";
}
}

View File

@ -21,6 +21,9 @@ import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.api.DungeonsAPI;
import de.erethon.dungeonsxl.api.Requirement;
import de.erethon.dungeonsxl.config.DMessage;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
@ -68,6 +71,16 @@ public class FeeMoneyRequirement implements Requirement {
return econ.getBalance(player) >= fee;
}
@Override
public BaseComponent[] getCheckMessage(Player player) {
double money = econ.getBalance(player);
ChatColor color = money >= fee ? ChatColor.GREEN : ChatColor.DARK_RED;
return new ComponentBuilder(DMessage.REQUIREMENT_FEE_MONEY.getMessage() + ": ").color(ChatColor.GOLD)
.append(String.valueOf(money)).color(color)
.append("/" + fee).color(ChatColor.WHITE)
.create();
}
@Override
public void demand(Player player) {
if (econ == null) {
@ -78,4 +91,9 @@ public class FeeMoneyRequirement implements Requirement {
MessageUtil.sendMessage(player, DMessage.REQUIREMENT_FEE.getMessage(econ.format(fee)));
}
@Override
public String toString() {
return "FeeMoneyRequirement{fee=" + fee + "}";
}
}

View File

@ -20,7 +20,13 @@ import de.erethon.caliburn.CaliburnAPI;
import de.erethon.caliburn.item.ExItem;
import de.erethon.dungeonsxl.api.DungeonsAPI;
import de.erethon.dungeonsxl.api.Requirement;
import de.erethon.dungeonsxl.config.DMessage;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -66,8 +72,38 @@ public class ForbiddenItemsRequirement implements Requirement {
return true;
}
@Override
public BaseComponent[] getCheckMessage(Player player) {
ComponentBuilder builder = new ComponentBuilder(DMessage.REQUIREMENT_FORBIDDEN_ITEMS.getMessage() + ": ").color(ChatColor.GOLD);
Set<ExItem> exInventory = new HashSet<>();
for (ItemStack item : player.getInventory().getContents()) {
if (item != null) {
exInventory.add(caliburn.getExItem(item));
}
}
boolean first = true;
for (ExItem forbiddenItem : forbiddenItems) {
ChatColor color = exInventory.contains(forbiddenItem) ? ChatColor.DARK_RED : ChatColor.GREEN;
if (!first) {
builder.append(", ").color(ChatColor.WHITE);
} else {
first = false;
}
builder.append(forbiddenItem.getName()).color(color);
}
return builder.create();
}
@Override
public void demand(Player player) {
}
@Override
public String toString() {
return "ForbiddenItemsRequirement{items=" + forbiddenItems + "}";
}
}

View File

@ -19,6 +19,10 @@ package de.erethon.dungeonsxl.requirement;
import de.erethon.dungeonsxl.api.DungeonsAPI;
import de.erethon.dungeonsxl.api.Requirement;
import de.erethon.dungeonsxl.api.player.PlayerGroup;
import de.erethon.dungeonsxl.config.DMessage;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
@ -78,8 +82,23 @@ public class GroupSizeRequirement implements Requirement {
return size >= minimum && size <= maximum;
}
@Override
public BaseComponent[] getCheckMessage(Player player) {
int size = api.getPlayerGroup(player).getMembers().size();
ChatColor color = size >= minimum && size <= maximum ? ChatColor.GREEN : ChatColor.DARK_RED;
return new ComponentBuilder(DMessage.REQUIREMENT_GROUP_SIZE.getMessage() + ": ").color(ChatColor.GOLD)
.append(String.valueOf(size)).color(color)
.append("/" + minimum + "-" + maximum).color(ChatColor.WHITE)
.create();
}
@Override
public void demand(Player player) {
}
@Override
public String toString() {
return "GroupSizeRequirement{minimum=" + minimum + "; maximum=" + maximum + "}";
}
}

View File

@ -20,8 +20,14 @@ import de.erethon.caliburn.CaliburnAPI;
import de.erethon.caliburn.item.ExItem;
import de.erethon.dungeonsxl.api.DungeonsAPI;
import de.erethon.dungeonsxl.api.Requirement;
import de.erethon.dungeonsxl.config.DMessage;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -65,8 +71,38 @@ public class KeyItemsRequirement implements Requirement {
return keyItems.isEmpty();
}
@Override
public BaseComponent[] getCheckMessage(Player player) {
ComponentBuilder builder = new ComponentBuilder(DMessage.REQUIREMENT_KEY_ITEMS.getMessage() + ": ").color(ChatColor.GOLD);
Set<ExItem> exInventory = new HashSet<>();
for (ItemStack item : player.getInventory().getContents()) {
if (item != null) {
exInventory.add(caliburn.getExItem(item));
}
}
boolean first = true;
for (ExItem key : keyItems) {
ChatColor color = exInventory.contains(key) ? ChatColor.GREEN : ChatColor.DARK_RED;
if (!first) {
builder.append(", ").color(ChatColor.WHITE);
} else {
first = false;
}
builder.append(key.getName()).color(color);
}
return builder.create();
}
@Override
public void demand(Player player) {
}
@Override
public String toString() {
return "KeyItemsRequirement{items=" + keyItems + "}";
}
}

View File

@ -17,9 +17,13 @@
package de.erethon.dungeonsxl.requirement;
import de.erethon.dungeonsxl.api.Requirement;
import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.player.DPermission;
import java.util.ArrayList;
import java.util.List;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
@ -48,7 +52,7 @@ public class PermissionRequirement implements Requirement {
/* Actions */
@Override
public void setup(ConfigurationSection config) {
permissions = config.getStringList("permission");
permissions = config.getStringList("permissions");
}
@Override
@ -62,8 +66,28 @@ public class PermissionRequirement implements Requirement {
return true;
}
@Override
public BaseComponent[] getCheckMessage(Player player) {
ComponentBuilder builder = new ComponentBuilder(DMessage.REQUIREMENT_PERMISSION.getMessage() + ": ").color(ChatColor.GOLD);
boolean first = true;
for (String node : permissions) {
if (!first) {
builder.append(", ").color(ChatColor.WHITE);
} else {
first = false;
}
builder.append(node).color(player.hasPermission(node) ? ChatColor.GREEN : ChatColor.DARK_RED);
}
return builder.create();
}
@Override
public void demand(Player player) {
}
@Override
public String toString() {
return "PermissionRequirement{permissions=" + permissions + "}";
}
}

View File

@ -135,9 +135,4 @@ public class WorldConfig extends GameRuleContainer {
this.worldEnvironment = worldEnvironment;
}
@Override
public String toString() {
return getClass().getSimpleName() + "{file=" + file.getPath() + "}";
}
}

View File

@ -168,8 +168,8 @@ public class RewardChest extends GameBlock {
for (Player player : group.getMembers().getOnlinePlayers()) {
DGamePlayer dPlayer = (DGamePlayer) api.getPlayerCache().getGamePlayer(player);
if (dPlayer == null || !dPlayer.canLoot(game.getRules())) {
MessageUtil.sendMessage(player, DMessage.ERROR_NO_REWARDS_TIME.getMessage(SimpleDateUtil.ddMMyyyyhhmm(dPlayer.getTimeNextLoot(game.getRules()))));
if (dPlayer == null || !dPlayer.canLoot(game.getDungeon())) {
MessageUtil.sendMessage(player, DMessage.ERROR_NO_REWARDS_TIME.getMessage(SimpleDateUtil.ddMMyyyyhhmm(dPlayer.getTimeNextLoot(game.getDungeon()))));
continue;
}

View File

@ -213,6 +213,12 @@ player:
waitForOtherPlayers: "&6Waiting for team members..."
requirement:
fee: "&6You have been charged &4&v1 &6for entering the dungeon."
feeLevel: "Levels"
feeMoney: "Money"
forbiddenItems: "Forbidden items"
groupSize: "Group size"
keyItems: "Keys"
permission: "Permissions"
reward:
general: "&6You received &4&v1 &6for finishing the dungeon."
sign:

View File

@ -213,6 +213,12 @@ player:
waitForOtherPlayers: "&6En attente des membres de l'équipe..."
requirement:
fee: "&6Vous avez été débité de &4&v1 &6pour entrer dans le donjon."
feeLevel: "Niveaux"
feeMoney: "Argent"
forbiddenItems: "Objets défendus"
groupSize: "Quantité des joueurs"
keyItems: "Clés"
permission: "Permissions"
reward:
general: "&6Vous avez reçu &4&v1 &6pour avoir fini le donjon."
sign:

View File

@ -213,6 +213,12 @@ player:
waitForOtherPlayers: "&6Warte auf andere Gruppenmitglieder..."
requirement:
fee: "&6Du hast &4&v1 &6bezahlt, um den Dungeon zu betreten."
feeLevel: "Level"
feeMoney: "Geld"
forbiddenItems: "Verbotene Items"
groupSize: "Gruppengröße"
keyItems: "Schlüssel"
permission: "Permissions"
reward:
general: "&6Du hast &4&v1 &6für das Beenden des Dungeons erhalten."
sign: