Add flight game rule

This commit is contained in:
Daniel Saukel 2019-02-23 01:10:45 +01:00
parent d7736831f9
commit 6845fa7711
4 changed files with 17 additions and 1 deletions

View File

@ -50,6 +50,7 @@ public class GameRuleProvider {
/* World */ /* World */
DEFAULT_VALUES.gameMode = GameMode.SURVIVAL; DEFAULT_VALUES.gameMode = GameMode.SURVIVAL;
DEFAULT_VALUES.fly = false;
DEFAULT_VALUES.breakBlocks = false; DEFAULT_VALUES.breakBlocks = false;
DEFAULT_VALUES.breakPlacedBlocks = false; DEFAULT_VALUES.breakPlacedBlocks = false;
DEFAULT_VALUES.breakWhitelist = null; DEFAULT_VALUES.breakWhitelist = null;
@ -115,6 +116,7 @@ public class GameRuleProvider {
/* World */ /* World */
protected GameMode gameMode; protected GameMode gameMode;
protected Boolean fly;
protected Boolean breakBlocks; protected Boolean breakBlocks;
protected Boolean breakPlacedBlocks; protected Boolean breakPlacedBlocks;
protected Map<ExItem, HashSet<ExItem>> breakWhitelist; protected Map<ExItem, HashSet<ExItem>> breakWhitelist;
@ -212,6 +214,10 @@ public class GameRuleProvider {
return gameMode; return gameMode;
} }
public boolean canFly() {
return fly;
}
/** /**
* @return if all blocks may be destroyed * @return if all blocks may be destroyed
*/ */
@ -684,6 +690,10 @@ public class GameRuleProvider {
gameMode = defaultValues.gameMode; gameMode = defaultValues.gameMode;
} }
if (fly == null) {
fly = defaultValues.fly;
}
if (breakBlocks == null) { if (breakBlocks == null) {
breakBlocks = defaultValues.breakBlocks; breakBlocks = defaultValues.breakBlocks;
} }

View File

@ -96,6 +96,7 @@ public class DGamePlayer extends DInstancePlayer {
if (!rules.getKeepInventoryOnEnter()) { if (!rules.getKeepInventoryOnEnter()) {
clearPlayerData(); clearPlayerData();
} }
player.setAllowFlight(rules.canFly());
if (rules.isLobbyDisabled()) { if (rules.isLobbyDisabled()) {
ready(); ready();

View File

@ -69,6 +69,8 @@ public abstract class DInstancePlayer extends DGlobalPlayer {
/* Actions */ /* Actions */
/** /**
* Clear the player's inventory, potion effects etc. * Clear the player's inventory, potion effects etc.
* <p>
* Does NOT handle flight.
*/ */
public void clearPlayerData() { public void clearPlayerData() {
player.getInventory().clear(); player.getInventory().clear();
@ -85,7 +87,6 @@ public abstract class DInstancePlayer extends DGlobalPlayer {
player.setCollidable(true); player.setCollidable(true);
player.setInvulnerable(false); player.setInvulnerable(false);
} }
player.setAllowFlight(false);
} }
/** /**

View File

@ -143,6 +143,10 @@ public class WorldConfig extends GameRuleProvider {
} }
} }
if (configFile.contains("fly")) {
fly = configFile.getBoolean("fly");
}
if (configFile.contains("breakBlocks")) { if (configFile.contains("breakBlocks")) {
breakBlocks = configFile.getBoolean("breakBlocks"); breakBlocks = configFile.getBoolean("breakBlocks");
} }