Requirement / reward systems now work flawlessly :)

This commit is contained in:
Daniel Saukel 2016-01-12 21:34:05 +01:00
parent e6ebee2d27
commit 418e2cb075
6 changed files with 26 additions and 8 deletions

View File

@ -3,6 +3,7 @@ package io.github.dre2n.dungeonsxl.dungeon;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.mob.DMobType;
import io.github.dre2n.dungeonsxl.player.DClass;
import io.github.dre2n.dungeonsxl.requirement.FeeRequirement;
import io.github.dre2n.dungeonsxl.requirement.Requirement;
import io.github.dre2n.dungeonsxl.reward.Reward;
import io.github.dre2n.dungeonsxl.util.NumberUtil;
@ -239,7 +240,14 @@ public class WorldConfig {
/* Dungeon Requirements */
if (configFile.contains("requirements")) {
for (String identifier : configFile.getConfigurationSection("requirements").getKeys(false)) {
requirements.add(Requirement.create(plugin.getRequirements().getByIdentifier(identifier)));
Requirement requirement = Requirement.create(plugin.getRequirements().getByIdentifier(identifier));
// Check for built-in requirements
if (requirement instanceof FeeRequirement) {
((FeeRequirement) requirement).setFee(configFile.getDouble("requirements.fee"));
}
requirements.add(requirement);
}
} else {
requirements = plugin.getDefaultConfig().requirements;

View File

@ -67,6 +67,7 @@ public class GameChest {
if ( !hasMoneyReward) {
Reward reward = Reward.create(RewardTypeDefault.MONEY);
((MoneyReward) reward).addMoney(moneyReward);
dGroup.addReward(reward);
}
String msg = "";
@ -102,7 +103,7 @@ public class GameChest {
MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.PLAYER_LOOT_ADDED, msg));
if (moneyReward != 0) {
MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.PLAYER_LOOT_ADDED, String.valueOf(moneyReward)));
MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.PLAYER_LOOT_ADDED, plugin.getEconomyProvider().format(moneyReward)));
}
}
}

View File

@ -381,7 +381,6 @@ public class GameWorld {
}
public static boolean canPlayDungeon(String dungeon, Player player) {
if (player.hasPermission("dxl.ignoretimelimit")) {
return true;
}
@ -391,13 +390,14 @@ public class GameWorld {
if (worldConfig.getTimeToNextPlay() != 0) {
// read PlayerConfig
Long time = getPlayerTime(dungeon, player);
long time = getPlayerTime(dungeon, player);
if (time != -1) {
if (time + worldConfig.getTimeToNextPlay() * 1000 * 60 * 60 > System.currentTimeMillis()) {
return false;
}
}
}
} else {
return false;
}

View File

@ -109,6 +109,8 @@ public class DMessages {
HELP_CMD_TEST("Help_Cmd_Test", "/dxl test ([dungeon|map]) [name] - Tests a dungeon"),
HELP_CMD_UNINVITE("Help_Cmd_Uninvite", "/dxl uninvite <player> <dungeon> - Uninvite a player to edit a dungeon"),
REQUIREMENT_FEE("Requirement_Fee", "&6You have been charged &4&v1 &6for entering the dungeon."),
REWARD_MONEY("Reward_Money", "&6You received &4&v1 &6for finishing the dungeon.");
private String identifier;

View File

@ -1,5 +1,8 @@
package io.github.dre2n.dungeonsxl.requirement;
import io.github.dre2n.dungeonsxl.file.DMessages.Messages;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import org.bukkit.entity.Player;
public class FeeRequirement extends Requirement {
@ -39,9 +42,12 @@ public class FeeRequirement extends Requirement {
@Override
public void demand(Player player) {
if (plugin.getEconomyProvider() != null) {
plugin.getEconomyProvider().withdrawPlayer(player, fee);
if (plugin.getEconomyProvider() == null) {
return;
}
plugin.getEconomyProvider().withdrawPlayer(player, fee);
MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.REQUIREMENT_FEE, plugin.getEconomyProvider().format(fee)));
}
@Override

View File

@ -36,10 +36,11 @@ public class MoneyReward extends Reward {
@Override
public void giveTo(Player player) {
if (plugin.getEconomyProvider() != null) {
plugin.getEconomyProvider().depositPlayer(player, money);
if (plugin.getEconomyProvider() == null) {
return;
}
plugin.getEconomyProvider().depositPlayer(player, money);
MessageUtil.sendMessage(player, plugin.getDMessages().getMessage(Messages.REWARD_MONEY, plugin.getEconomyProvider().format(money)));
}