Fix PVP rules; resolves #1009

This commit is contained in:
Daniel Saukel 2021-04-25 15:15:59 +02:00
parent 738d472b43
commit cb53d67293
6 changed files with 15 additions and 33 deletions

View File

@ -15,6 +15,7 @@
package de.erethon.dungeonsxl.api.world;
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
import de.erethon.dungeonsxl.api.dungeon.Game;
import de.erethon.dungeonsxl.api.dungeon.GameRuleContainer;
import java.io.File;
import org.bukkit.OfflinePlayer;
@ -120,22 +121,11 @@ public interface ResourceWorld {
* Returns a new game instance of this resource.
*
* @see de.erethon.dungeonsxl.api.dungeon.Game#ensureWorldIsLoaded(boolean)
* @param game the game the instance belongs to
* @param ignoreLimit if the instance limit set in the main config shall be ignored
* @return a new game instance of this resource
*/
default GameWorld instantiateGameWorld(boolean ignoreLimit) {
return instantiateGameWorld(getSingleFloorDungeon(), ignoreLimit);
}
/**
* Returns a new game instance of this resource.
*
* @see de.erethon.dungeonsxl.api.dungeon.Game#ensureWorldIsLoaded(boolean)
* @param dungeon the dungeon this game world will be part of
* @param ignoreLimit if the instance limit set in the main config shall be ignored
* @return a new game instance of this resource
*/
GameWorld instantiateGameWorld(Dungeon dungeon, boolean ignoreLimit);
GameWorld instantiateGameWorld(Game game, boolean ignoreLimit);
/**
* Returns the single floor dungeon of this resource.

View File

@ -291,7 +291,7 @@ public class DGame implements Game {
if (world != null) {
return world;
}
world = dungeon.getMap().instantiateGameWorld(dungeon, ignoreLimit);
world = dungeon.getMap().instantiateGameWorld(this, ignoreLimit);
return world;
}
@ -305,6 +305,7 @@ public class DGame implements Game {
continue;
}
if (!((DGroup) group).startGame(this, i++)) {
plugin.log("Could not start game for group " + group);
return false; // TODO: State of groups that are OK has already been changed
}
}

View File

@ -510,14 +510,7 @@ public class DGamePlayer extends DInstancePlayer implements GamePlayer {
}
ready = true;
boolean start = true;
if (!game.start()) {// TODO: Start for every player???
start = false;
} else {
respawn();
}
return start;
return ready;
}
@Override

View File

@ -515,7 +515,7 @@ public class DGroup implements PlayerGroup {
return;
}
GameWorld gameWorld = newFloor.instantiateGameWorld(true);
GameWorld gameWorld = newFloor.instantiateGameWorld(getGame(), true);
gameWorld.setType(type);
game.setWorld(gameWorld);
@ -561,7 +561,6 @@ public class DGroup implements PlayerGroup {
color = plugin.getMainConfig().getGroupColorPriority(index);
}
boolean ready = true;
for (Player player : getMembers().getOnlinePlayers()) {
GamePlayer gamePlayer = plugin.getPlayerCache().getGamePlayer(player);
if (gamePlayer == null) {
@ -569,14 +568,10 @@ public class DGroup implements PlayerGroup {
}
if (!gamePlayer.isReady()) {
ready = false;
return false;
}
}
if (!ready) {
return false;
}
GroupStartFloorEvent event = new GroupStartFloorEvent(this, getGameWorld());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {

View File

@ -170,8 +170,11 @@ public class ReadySign extends Button {
boolean wasReady = player.isReady();
if (!getGameWorld().areClassesEnabled() || player.getPlayerClass() != null) {
if (player.ready() && bar != null) {
bar.cancel();
if (player.ready()) {
getGame().start();
if (bar != null) {
bar.cancel();
}
}
}

View File

@ -233,14 +233,14 @@ public class DResourceWorld implements ResourceWorld {
}
@Override
public GameWorld instantiateGameWorld(Dungeon dungeon, boolean ignoreLimit) {
public GameWorld instantiateGameWorld(Game game, boolean ignoreLimit) {
if (plugin.isLoadingWorld()) {
return null;
}
if (!ignoreLimit && plugin.getMainConfig().getMaxInstances() <= plugin.getInstanceCache().size()) {
return null;
}
return (DGameWorld) instantiate(new DGame(plugin, dungeon));
return (DGameWorld) instantiate(game);
}
@Override