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

View File

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

View File

@ -69,6 +69,8 @@ public abstract class DInstancePlayer extends DGlobalPlayer {
/* Actions */
/**
* Clear the player's inventory, potion effects etc.
* <p>
* Does NOT handle flight.
*/
public void clearPlayerData() {
player.getInventory().clear();
@ -85,7 +87,6 @@ public abstract class DInstancePlayer extends DGlobalPlayer {
player.setCollidable(true);
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")) {
breakBlocks = configFile.getBoolean("breakBlocks");
}