Skip to content

Commit

Permalink
player.setGamemode(int gamemode, AdventureSettings newSettings);
Browse files Browse the repository at this point in the history
  • Loading branch information
boybook committed Oct 9, 2016
1 parent 787e6eb commit 334e550
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions server/src/main/java/cn/nukkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -960,14 +960,20 @@ public int getGamemode() {
}

public boolean setGamemode(int gamemode) {
return this.setGamemode(gamemode, null);
}

public boolean setGamemode(int gamemode, AdventureSettings newSettings) {
if (gamemode < 0 || gamemode > 3 || this.gamemode == gamemode) {
return false;
}

AdventureSettings newSettings = this.getAdventureSettings().clone(this);
newSettings.setCanDestroyBlock((gamemode & 0x02) == 0);
newSettings.setCanFly((gamemode & 0x01) > 0);
newSettings.setNoclip(gamemode == 0x03);
if (newSettings == null) {
newSettings = this.getAdventureSettings().clone(this);
newSettings.setCanDestroyBlock((gamemode & 0x02) == 0);
newSettings.setCanFly((gamemode & 0x01) > 0);
newSettings.setNoclip(gamemode == 0x03);
}

PlayerGameModeChangeEvent ev;
this.server.getPluginManager().callEvent(ev = new PlayerGameModeChangeEvent(this, gamemode, newSettings));
Expand Down

0 comments on commit 334e550

Please sign in to comment.