Actually use game goals

This commit is contained in:
Daniel Saukel 2020-11-02 17:01:39 +01:00
parent 1482bb5902
commit 000250e95b
3 changed files with 20 additions and 1 deletions

View File

@ -337,7 +337,8 @@ public class DGamePlayer extends DInstancePlayer implements GamePlayer {
GameRuleContainer rules = game.getRules();
getGroup().setScore(getGroup().getScore() + 1);
if (rules.getState(GameRule.SCORE_GOAL) == getGroup().getScore()) {
GameGoal goal = rules.getState(GameRule.GAME_GOAL);
if ((goal == GameGoal.REACH_SCORE || goal == GameGoal.TIME_SCORE) && rules.getState(GameRule.SCORE_GOAL) == getGroup().getScore()) {
getGroup().winGame();
}

View File

@ -18,6 +18,8 @@ package de.erethon.dungeonsxl.player;
import de.erethon.commons.chat.MessageUtil;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.api.dungeon.GameGoal;
import de.erethon.dungeonsxl.api.dungeon.GameRule;
import de.erethon.dungeonsxl.api.event.group.GroupPlayerKickEvent;
import de.erethon.dungeonsxl.api.player.GamePlayer;
import de.erethon.dungeonsxl.api.player.PlayerGroup;
@ -37,12 +39,14 @@ public class TimeIsRunningTask extends BukkitRunnable {
private PlayerGroup group;
private int time;
private int timeLeft;
private GameGoal goal;
public TimeIsRunningTask(DungeonsXL plugin, PlayerGroup group, int time) {
this.plugin = plugin;
this.group = group;
this.time = time;
this.timeLeft = time;
goal = group.getDungeon().getRules().getState(GameRule.GAME_GOAL);
}
@Override
@ -66,6 +70,10 @@ public class TimeIsRunningTask extends BukkitRunnable {
continue;
}
// Fire trigger
if (goal != GameGoal.TIME_SCORE && goal != GameGoal.TIME_SURVIVAL) {
return;
}
GroupPlayerKickEvent groupPlayerKickEvent = new GroupPlayerKickEvent(group, dPlayer, GroupPlayerKickEvent.Cause.TIME_EXPIRED);
Bukkit.getServer().getPluginManager().callEvent(groupPlayerKickEvent);

View File

@ -16,8 +16,11 @@
*/
package de.erethon.dungeonsxl.sign.button;
import de.erethon.commons.chat.MessageUtil;
import de.erethon.dungeonsxl.api.DungeonsAPI;
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
import de.erethon.dungeonsxl.api.dungeon.GameGoal;
import de.erethon.dungeonsxl.api.dungeon.GameRule;
import de.erethon.dungeonsxl.api.sign.Button;
import de.erethon.dungeonsxl.api.world.InstanceWorld;
import de.erethon.dungeonsxl.api.world.ResourceWorld;
@ -82,6 +85,13 @@ public class EndSign extends Button {
@Override
public void initialize() {
GameGoal goal = getGame().getRules().getState(GameRule.GAME_GOAL);
if (goal != GameGoal.END) {
setToAir();
MessageUtil.log(api, "&4An end sign in the dungeon " + getGame().getDungeon().getName() + " is ignored because the game goal is " + goal.toString());
return;
}
if (!getLine(1).isEmpty()) {
floor = api.getMapRegistry().get(getLine(1));
}