New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong fall damage when switching gamemodes #820

Merged
merged 4 commits into from Jan 21, 2018

Conversation

Projects
None yet
4 participants
@XuZhen86
Contributor

XuZhen86 commented Jan 21, 2018

This is my first ever pull request, please have mercy if I did something wrong馃槃

This pull request tries to fix bug that when switching to game mode 0 from game mode 1, the player receives incorrect fall damage.

Steps to recreate:

  1. In game mode 0, land on floor
  2. Switch to game mode 1 and fly to a certain height
  3. Lower the height to barely touching the floor (not actually standing on the floor)
  4. Switch back to game mode 0 and the player receives fall damage. The damage can sometimes kill the player.

Observed behavior:
The player receives fall damage calculated from the maximum height during game mode 1

Expected behavior:
The player receives fall damage calculated from the location where the player's game mode changes. For example, the player should not receive damage when he/she's only 2 blocks above the floor when the game mode switches.

Solution:
I have added an extra statement to reset the player's fall distance when switching game mode. At line 75 of file GameModeCommand.java

@CLAassistant

This comment has been minimized.

CLAassistant commented Jan 21, 2018

CLA assistant check
All committers have signed the CLA.

@@ -73,22 +72,20 @@ public boolean execute(CommandSender sender, String label, String[] args) {
private void updateGameMode(CommandSender sender, Player who, GameMode gameMode) {
String gameModeName = GameModeUtils.prettyPrint(gameMode);
who.setGameMode(gameMode);
who.setFallDistance(0);

This comment has been minimized.

@momothereal

momothereal Jan 21, 2018

Member

Maybe add this statement to the GlowPlayer#setGameMode method instead? That way, this fix would also apply to plugins changing a player's game mode.

@mastercoms

This comment has been minimized.

Member

mastercoms commented Jan 21, 2018

Hi, thank you for your PR to Glowstone! We love to see new contributors!

Since this is your first time here, you may want to check out our code style.

@@ -22,8 +22,7 @@
* Creates the instance for this command.
*/
public GameModeCommand() {
super("gamemode", "Change the game mode of a player.", "/gamemode <mode> [player]",
Collections.emptyList());
super("gamemode", "Change the game mode of a player.", "/gamemode <mode> [player]", Collections.emptyList());

This comment has been minimized.

@momothereal

momothereal Jan 21, 2018

Member

As per our code style, the line length should not exceed 100. Can you revert this change?

@@ -74,21 +73,18 @@ private void updateGameMode(CommandSender sender, Player who, GameMode gameMode)
String gameModeName = GameModeUtils.prettyPrint(gameMode);
who.setGameMode(gameMode);
if (!sender.equals(who)) {
sender.sendMessage(
who.getDisplayName() + "'s game mode has been updated to " + ChatColor.GRAY + ""
sender.sendMessage(who.getDisplayName() + "'s game mode has been updated to " + ChatColor.GRAY + ""

This comment has been minimized.

@momothereal

momothereal Jan 21, 2018

Member

Revert this change as well

who.sendMessage(
"Your game mode has been updated to " + ChatColor.GRAY + "" + ChatColor.ITALIC
+ gameModeName + " Mode" + ChatColor.RESET);
who.sendMessage("Your game mode has been updated to " + ChatColor.GRAY + "" + ChatColor.ITALIC + gameModeName

This comment has been minimized.

@momothereal

momothereal Jan 21, 2018

Member

Revert this change as well

}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args)
throws IllegalArgumentException {
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {

This comment has been minimized.

@momothereal

momothereal Jan 21, 2018

Member

Revert this change as well

@mastercoms mastercoms merged commit 962ca82 into GlowstoneMC:dev Jan 21, 2018

2 checks passed

ci/circleci: build Your tests passed on CircleCI!
Details
license/cla Contributor License Agreement is signed.
Details
@mastercoms

This comment has been minimized.

Member

mastercoms commented Jan 21, 2018

Nice work! Thank you for your contribution to Glowstone.

@XuZhen86 XuZhen86 deleted the Glowminers:FixWrongFallDamageWhenSwitchingGamemodes branch Jan 22, 2018

@XuZhen86 XuZhen86 restored the Glowminers:FixWrongFallDamageWhenSwitchingGamemodes branch Jan 23, 2018

@XuZhen86 XuZhen86 deleted the Glowminers:FixWrongFallDamageWhenSwitchingGamemodes branch Jan 23, 2018

@XuZhen86 XuZhen86 restored the Glowminers:FixWrongFallDamageWhenSwitchingGamemodes branch Jan 23, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment