Skip to content

Commit

Permalink
Address review by Camotoy - no need to tell client about new difficul…
Browse files Browse the repository at this point in the history
…ty/default game mode

Remove duplicate settings in SettingsUtils - otherwise, they clash with the new translator
Prevent client Gamemode switching when personal Gamemode is "default"
  • Loading branch information
onebeastchris committed Aug 30, 2023
1 parent e9f2824 commit 9d1d77f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
import org.cloudburstmc.protocol.bedrock.packet.SetDefaultGameTypePacket;
import org.cloudburstmc.protocol.bedrock.packet.SetPlayerGameTypePacket;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator;
Expand All @@ -42,9 +43,11 @@ public void translate(GeyserSession session, SetDefaultGameTypePacket packet) {
if (session.getOpPermissionLevel() >= 2 || session.hasPermission("geyser.settings.server")) {
session.getGeyser().getWorldManager().setDefaultGameMode(session, GameMode.byId(packet.getGamemode()));
}
// update the client
SetDefaultGameTypePacket defaultGameTypePacket = new SetDefaultGameTypePacket();
defaultGameTypePacket.setGamemode(packet.getGamemode());
session.sendUpstreamPacket(defaultGameTypePacket);
// Stop the client from updating their own Gamemode without telling the server
// Can occur when client Gamemode is set to "default", and default game mode is changed.
SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket();
int gamemode = session.getGameMode().ordinal() == 3 ? 6 : session.getGameMode().ordinal();
playerGameTypePacket.setGamemode(gamemode);
session.sendUpstreamPacket(playerGameTypePacket);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,5 @@ public void translate(GeyserSession session, SetDifficultyPacket packet) {
session.getGeyser().getWorldManager().setDifficulty(session, Difficulty.from(packet.getDifficulty()));
}
}
// inform the client
SetDifficultyPacket difficultyPacket = new SetDifficultyPacket();
difficultyPacket.setDifficulty(session.getWorldCache().getDifficulty().ordinal());
session.sendUpstreamPacket(difficultyPacket);
}
}
31 changes: 0 additions & 31 deletions core/src/main/java/org/geysermc/geyser/util/SettingsUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

package org.geysermc.geyser.util;

import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
import com.github.steveice10.mc.protocol.data.game.setting.Difficulty;
import org.geysermc.cumulus.component.DropdownComponent;
import org.geysermc.cumulus.form.CustomForm;
import org.geysermc.geyser.GeyserImpl;
Expand Down Expand Up @@ -77,23 +75,6 @@ public static CustomForm buildForm(GeyserSession session) {
}
}

boolean canModifyServer = session.getOpPermissionLevel() >= 2 || session.hasPermission("geyser.settings.server");
if (canModifyServer) {
builder.label("geyser.settings.title.server");

DropdownComponent.Builder gamemodeDropdown = DropdownComponent.builder("%createWorldScreen.gameMode.personal");
for (GameMode gamemode : GameMode.values()) {
gamemodeDropdown.option("selectWorld.gameMode." + gamemode.name().toLowerCase(), session.getGameMode() == gamemode);
}
builder.dropdown(gamemodeDropdown);

DropdownComponent.Builder difficultyDropdown = DropdownComponent.builder("%options.difficulty");
for (Difficulty difficulty : Difficulty.values()) {
difficultyDropdown.option("%options.difficulty." + difficulty.name().toLowerCase(), session.getWorldCache().getDifficulty() == difficulty);
}
builder.dropdown(difficultyDropdown);
}

boolean showGamerules = session.getOpPermissionLevel() >= 2 || session.hasPermission("geyser.settings.gamerules");
if (showGamerules) {
builder.label("geyser.settings.title.game_rules")
Expand Down Expand Up @@ -128,18 +109,6 @@ public static CustomForm buildForm(GeyserSession session) {
}
}

if (canModifyServer) {
GameMode gameMode = GameMode.values()[(int) response.next()];
if (gameMode != null && gameMode != session.getGameMode()) {
session.getGeyser().getWorldManager().setPlayerGameMode(session, gameMode);
}

Difficulty difficulty = Difficulty.values()[(int) response.next()];
if (difficulty != null && difficulty != session.getWorldCache().getDifficulty()) {
session.getGeyser().getWorldManager().setDifficulty(session, difficulty);
}
}

if (showGamerules) {
for (GameRule gamerule : GameRule.VALUES) {
if (Boolean.class.equals(gamerule.getType())) {
Expand Down

0 comments on commit 9d1d77f

Please sign in to comment.