#61: Use GameRules instead of WorldConfig

This commit is contained in:
Daniel Saukel 2016-05-08 01:51:29 +02:00
parent ffde4f6c8b
commit 231372956d
11 changed files with 76 additions and 70 deletions

View File

@ -35,6 +35,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
@ -348,7 +349,7 @@ public class Game {
}
}
int delay = world.getConfig().getTimeToNextWave();
int delay = rules.getTimeToNextWave();
sendMessage(plugin.getMessageConfig().getMessage(DMessages.GROUP_WAVE_FINISHED, String.valueOf(waveCount), String.valueOf(delay)));
new BukkitRunnable() {
@ -410,4 +411,13 @@ public class Game {
return null;
}
public static Game getByWorld(World world) {
GameWorld gameWorld = GameWorld.getByWorld(world);
if (gameWorld != null) {
return getByGameWorld(gameWorld);
} else {
return null;
}
}
}

View File

@ -20,6 +20,7 @@ import io.github.dre2n.commons.util.NumberUtil;
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.game.Game;
import io.github.dre2n.dungeonsxl.game.GamePlaceableBlock;
import io.github.dre2n.dungeonsxl.game.GameType;
import io.github.dre2n.dungeonsxl.game.GameTypeDefault;
@ -107,10 +108,11 @@ public class BlockListener implements Listener {
}
}
if (gameWorld.getGame() != null) {
GameType gameType = gameWorld.getGame().getType();
if (gameType == GameTypeDefault.DEFAULT && gameWorld.getConfig() != null) {
event.setCancelled(!gameWorld.getConfig().canBuild());
Game game = gameWorld.getGame();
if (game != null) {
GameType gameType = game.getType();
if (gameType == GameTypeDefault.DEFAULT) {
event.setCancelled(!game.getRules().canBuild());
} else if (!gameType.canBuild()) {
event.setCancelled(true);
@ -132,8 +134,11 @@ public class BlockListener implements Listener {
return;
}
if (gameWorld.getConfig().canBuild() || GamePlaceableBlock.canBuildHere(block, block.getFace(event.getBlockAgainst()), event.getItemInHand().getType(), gameWorld)) {
return;
Game game = gameWorld.getGame();
if (game != null) {
if (game.getRules().canBuild() || GamePlaceableBlock.canBuildHere(block, block.getFace(event.getBlockAgainst()), event.getItemInHand().getType(), gameWorld)) {
return;
}
}
// Workaround for a bug that would allow 3-Block-high jumping

View File

@ -17,10 +17,7 @@
package io.github.dre2n.dungeonsxl.listener;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.WorldConfig;
import io.github.dre2n.dungeonsxl.game.Game;
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.player.DGamePlayer;
import io.github.dre2n.dungeonsxl.player.DGroup;
@ -158,16 +155,8 @@ public class EntityListener implements Listener {
return;
}
WorldConfig config = gameWorld.getConfig();
GameType type = game.getType();
boolean pvp = config.isPlayerVersusPlayer();
boolean friendlyFire = config.isFriendlyFire();
if (type != GameTypeDefault.DEFAULT) {
pvp = type.isPlayerVersusPlayer();
friendlyFire = type.isFriendlyFire();
}
boolean pvp = game.getRules().isPlayerVersusPlayer();
boolean friendlyFire = game.getRules().isFriendlyFire();
Entity attackerEntity = event.getDamager();
Entity attackedEntity = event.getEntity();

View File

@ -19,10 +19,10 @@ package io.github.dre2n.dungeonsxl.listener;
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.WorldConfig;
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent;
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerDeathEvent;
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerKickEvent;
import io.github.dre2n.dungeonsxl.game.Game;
import io.github.dre2n.dungeonsxl.global.DPortal;
import io.github.dre2n.dungeonsxl.global.GameSign;
import io.github.dre2n.dungeonsxl.global.GlobalProtection;
@ -84,15 +84,18 @@ public class PlayerListener implements Listener {
@EventHandler(priority = EventPriority.HIGH)
public void onDeath(PlayerDeathEvent event) {
Player player = event.getEntity();
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
GameWorld gameWorld = GameWorld.getByWorld(player.getLocation().getWorld());
if (gameWorld == null) {
return;
}
WorldConfig dConfig = gameWorld.getConfig();
Game game = Game.getByGameWorld(gameWorld);
if (game == null) {
return;
}
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
if (dPlayer == null) {
return;
}
@ -117,14 +120,12 @@ public class PlayerListener implements Listener {
if (dPlayer.getLives() != -1) {
MessageUtil.sendMessage(player, DMessages.PLAYER_DEATH.getMessage(String.valueOf(dPlayer.getLives())));
if (dConfig != null) {
if (dConfig.getKeepInventoryOnDeath()) {
dPlayer.setRespawnInventory(event.getEntity().getInventory().getContents());
dPlayer.setRespawnArmor(event.getEntity().getInventory().getArmorContents());
// Delete all drops
for (ItemStack item : event.getDrops()) {
item.setType(Material.AIR);
}
if (game.getRules().getKeepInventoryOnDeath()) {
dPlayer.setRespawnInventory(event.getEntity().getInventory().getContents());
dPlayer.setRespawnArmor(event.getEntity().getInventory().getArmorContents());
// Delete all drops
for (ItemStack item : event.getDrops()) {
item.setType(Material.AIR);
}
}
}
@ -136,7 +137,7 @@ public class PlayerListener implements Listener {
if (!dPlayerKickEvent.isCancelled()) {
MessageUtil.broadcastMessage(DMessages.PLAYER_DEATH_KICK.getMessage(player.getName()));
dPlayer.leave();
if (gameWorld.getConfig().getKeepInventoryOnEscape()) {
if (game.getRules().getKeepInventoryOnEscape()) {
dPlayer.applyRespawnInventory();
}
}
@ -347,9 +348,9 @@ public class PlayerListener implements Listener {
return;
}
GameWorld gameWorld = GameWorld.getByWorld(gamePlayer.getWorld());
Game game = Game.getByWorld(gamePlayer.getWorld());
for (Material material : gameWorld.getConfig().getSecureObjects()) {
for (Material material : game.getRules().getSecureObjects()) {
if (material == event.getItemDrop().getItemStack().getType()) {
event.setCancelled(true);
MessageUtil.sendMessage(player, DMessages.ERROR_DROP.getMessage());
@ -471,9 +472,9 @@ public class PlayerListener implements Listener {
DGroup dGroup = DGroup.getByPlayer(player);
// Check GameWorld
GameWorld gameWorld = GameWorld.getByWorld(player.getWorld());
if (gameWorld != null) {
int timeUntilKickOfflinePlayer = gameWorld.getConfig().getTimeUntilKickOfflinePlayer();
Game game = Game.getByWorld(player.getWorld());
if (game != null) {
int timeUntilKickOfflinePlayer = game.getRules().getTimeUntilKickOfflinePlayer();
if (timeUntilKickOfflinePlayer == 0) {
dPlayer.leave();
@ -587,7 +588,7 @@ public class PlayerListener implements Listener {
String command = event.getMessage().toLowerCase();
ArrayList<String> commandWhitelist = new ArrayList<>();
GameWorld gameWorld = GameWorld.getByWorld(dPlayer.getWorld());
Game game = Game.getByWorld(dPlayer.getWorld());
if (dPlayer instanceof DEditPlayer) {
if (DPermissions.hasPermission(event.getPlayer(), DPermissions.CMD_EDIT)) {
@ -597,9 +598,9 @@ public class PlayerListener implements Listener {
commandWhitelist.addAll(plugin.getMainConfig().getEditCommandWhitelist());
}
} else if (gameWorld != null) {
if (gameWorld.getConfig() != null) {
commandWhitelist.addAll(gameWorld.getConfig().getGameCommandWhitelist());
} else if (game != null) {
if (game.getRules() != null) {
commandWhitelist.addAll(game.getRules().getGameCommandWhitelist());
}
}

View File

@ -21,7 +21,6 @@ import io.github.dre2n.commons.util.messageutil.MessageUtil;
import io.github.dre2n.commons.util.playerutil.PlayerUtil;
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.event.dgroup.DGroupFinishDungeonEvent;
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupFinishFloorEvent;
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupRewardEvent;
@ -29,6 +28,7 @@ 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.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;
@ -83,18 +83,18 @@ public class DGamePlayer extends DInstancePlayer {
public DGamePlayer(Player player, World world) {
super(player, world);
WorldConfig worldConfig = GameWorld.getByWorld(world).getConfig();
GameRules rules = Game.getByWorld(world).getRules();
player.setGameMode(GameMode.SURVIVAL);
if (!worldConfig.getKeepInventoryOnEnter()) {
if (!rules.getKeepInventoryOnEnter()) {
clearPlayerData();
}
if (worldConfig.isLobbyDisabled()) {
if (rules.isLobbyDisabled()) {
ready();
}
initialLives = worldConfig.getInitialLives();
initialLives = rules.getInitialLives();
lives = initialLives;
Location teleport = GameWorld.getByWorld(world).getLobbyLocation();
@ -183,12 +183,12 @@ public class DGamePlayer extends DInstancePlayer {
* the dClass to set
*/
public void setDClass(String className) {
GameWorld gameWorld = GameWorld.getByWorld(getPlayer().getWorld());
if (gameWorld == null) {
Game game = Game.getByWorld(getPlayer().getWorld());
if (game == null) {
return;
}
DClass dClass = gameWorld.getConfig().getClass(className);
DClass dClass = game.getRules().getClass(className);
if (dClass != null) {
if (this.dClass != dClass) {
this.dClass = dClass;
@ -359,11 +359,11 @@ public class DGamePlayer extends DInstancePlayer {
public void leave() {
delete();
WorldConfig dConfig = GameWorld.getByWorld(getWorld()).getConfig();
GameRules rules = Game.getByWorld(getWorld()).getRules();
if (finished) {
getSavePlayer().reset(dConfig.getKeepInventoryOnFinish());
getSavePlayer().reset(rules.getKeepInventoryOnFinish());
} else {
getSavePlayer().reset(dConfig.getKeepInventoryOnEscape());
getSavePlayer().reset(rules.getKeepInventoryOnEscape());
}
GameWorld gameWorld = GameWorld.getByWorld(getWorld());
@ -371,7 +371,7 @@ public class DGamePlayer extends DInstancePlayer {
// Permission bridge
if (plugin.getPermissionProvider() != null) {
for (String permission : gameWorld.getConfig().getGamePermissions()) {
for (String permission : rules.getGamePermissions()) {
plugin.getPermissionProvider().playerRemoveTransient(getWorld().getName(), player, permission);
}
}
@ -385,7 +385,7 @@ public class DGamePlayer extends DInstancePlayer {
if (game != null) {
if (finished) {
if (game.getType().hasRewards()) {
for (Reward reward : gameWorld.getConfig().getRewards()) {
for (Reward reward : rules.getRewards()) {
reward.giveTo(getPlayer());
}
@ -515,7 +515,7 @@ public class DGamePlayer extends DInstancePlayer {
}
// Respawn Items
if (GameWorld.getByWorld(getWorld()).getConfig().getKeepInventoryOnDeath()) {
if (Game.getByWorld(getWorld()).getRules().getKeepInventoryOnDeath()) {
applyRespawnInventory();
}
}

View File

@ -19,7 +19,6 @@ package io.github.dre2n.dungeonsxl.player;
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.WorldConfig;
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupDisbandEvent;
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupStartFloorEvent;
@ -27,6 +26,7 @@ import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerJoinDGroupEvent;
import io.github.dre2n.dungeonsxl.event.requirement.RequirementDemandEvent;
import io.github.dre2n.dungeonsxl.event.reward.RewardAdditionEvent;
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.global.GroupSign;
@ -521,9 +521,9 @@ public class DGroup {
}
}
WorldConfig config = gameWorld.getConfig();
if (config != null) {
for (Requirement requirement : config.getRequirements()) {
GameRules rules = gameWorld.getGame().getRules();
if (rules != null) {
for (Requirement requirement : rules.getRequirements()) {
RequirementDemandEvent requirementDemandEvent = new RequirementDemandEvent(requirement, player);
plugin.getServer().getPluginManager().callEvent(event);
@ -536,22 +536,22 @@ public class DGroup {
GameType gameType = game.getType();
if (gameType == GameTypeDefault.DEFAULT) {
player.setGameMode(config.getGameMode());
if (config.isTimeIsRunning()) {
timeIsRunningTask = new TimeIsRunningTask(this, config.getTimeToFinish()).runTaskTimer(plugin, 20, 20);
player.setGameMode(rules.getGameMode());
if (rules.isTimeIsRunning()) {
timeIsRunningTask = new TimeIsRunningTask(this, rules.getTimeToFinish()).runTaskTimer(plugin, 20, 20);
}
} else {
player.setGameMode(gameType.getGameMode());
if (gameType.getShowTime()) {
timeIsRunningTask = new TimeIsRunningTask(this, config.getTimeToFinish()).runTaskTimer(plugin, 20, 20);
timeIsRunningTask = new TimeIsRunningTask(this, rules.getTimeToFinish()).runTaskTimer(plugin, 20, 20);
}
}
}
// Permission bridge
if (plugin.getPermissionProvider() != null) {
for (String permission : gameWorld.getConfig().getGamePermissions()) {
for (String permission : rules.getGamePermissions()) {
plugin.getPermissionProvider().playerRemoveTransient(gameWorld.getWorld().getName(), player, permission);
}
}

View File

@ -42,7 +42,7 @@ public class ClassesSign extends DSign {
@Override
public void onInit() {
if (getGameWorld().getConfig().isLobbyDisabled()) {
if (getGame().getRules().isLobbyDisabled()) {
getSign().getBlock().setType(Material.AIR);
return;
}
@ -52,7 +52,7 @@ public class ClassesSign extends DSign {
int directionZ = direction[1];
int xx = 0, zz = 0;
for (DClass dclass : getGameWorld().getConfig().getClasses()) {
for (DClass dclass : getGame().getRules().getClasses()) {
// Check existing signs
boolean isContinued = true;

View File

@ -54,7 +54,7 @@ public class MessageSign extends DSign {
String lines[] = getSign().getLines();
if (!lines[1].isEmpty()) {
String msg = getGameWorld().getConfig().getMsg(NumberUtil.parseInt(lines[1]), true);
String msg = getGame().getRules().getMsg(NumberUtil.parseInt(lines[1]), true);
if (msg != null) {
this.msg = msg;
getSign().getBlock().setType(Material.AIR);

View File

@ -53,7 +53,7 @@ public class SoundMessageSign extends DSign {
String lines[] = getSign().getLines();
if (!lines[1].isEmpty()) {
String msg = getGameWorld().getConfig().getMsg(NumberUtil.parseInt(lines[1]), true);
String msg = getGame().getRules().getMsg(NumberUtil.parseInt(lines[1]), true);
if (msg != null) {
this.msg = msg;
getSign().getBlock().setType(Material.AIR);

View File

@ -71,7 +71,7 @@ public class MobSpawnTask extends BukkitRunnable {
}
// Check custom mobs
DMobType mobType = DMobType.getByName(sign.getMob(), gameWorld.getConfig().getMobTypes());
DMobType mobType = DMobType.getByName(sign.getMob(), gameWorld.getGame().getRules().getMobTypes());
if (mobType != null) {
mobType.spawn(GameWorld.getByWorld(world), spawnLoc);

View File

@ -21,6 +21,7 @@ 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.event.dplayer.DPlayerKickEvent;
import io.github.dre2n.dungeonsxl.game.Game;
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
import io.github.dre2n.dungeonsxl.player.DGroup;
import org.bukkit.Bukkit;
@ -72,7 +73,7 @@ public class TimeIsRunningTask extends BukkitRunnable {
if (!dPlayerKickEvent.isCancelled()) {
MessageUtil.broadcastMessage(DMessages.PLAYER_TIME_KICK.getMessage(player.getName()));
dPlayer.leave();
if (dGroup.getGameWorld().getConfig().getKeepInventoryOnEscape()) {
if (Game.getByDGroup(dGroup).getRules().getKeepInventoryOnEscape()) {
dPlayer.applyRespawnInventory();
}
}