diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml
index 78a3ce299..9621fa1d0 100644
--- a/.github/workflows/pullrequest.yml
+++ b/.github/workflows/pullrequest.yml
@@ -15,10 +15,10 @@ jobs:
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- - name: Set up JDK 1.8
+ - name: Set up JDK 16
uses: actions/setup-java@v1
with:
- java-version: 1.8
+ java-version: 16
- name: submodules-init
uses: snickerbockers/submodules-init@v4
- name: Build with Maven
diff --git a/ap/pom.xml b/ap/pom.xml
index f8cc2dd1b..912c6731b 100644
--- a/ap/pom.xml
+++ b/ap/pom.xml
@@ -6,9 +6,9 @@
org.geysermc
geyser-parent
- 1.4.2-SNAPSHOT
+ 1.4.3-SNAPSHOT
ap
- 1.4.2-SNAPSHOT
+ 1.4.3-SNAPSHOT
\ No newline at end of file
diff --git a/bootstrap/bungeecord/pom.xml b/bootstrap/bungeecord/pom.xml
index b01ac7984..bef37d453 100644
--- a/bootstrap/bungeecord/pom.xml
+++ b/bootstrap/bungeecord/pom.xml
@@ -6,7 +6,7 @@
org.geysermc
bootstrap-parent
- 1.4.2-SNAPSHOT
+ 1.4.3-SNAPSHOT
bootstrap-bungeecord
@@ -14,7 +14,7 @@
org.geysermc
connector
- 1.4.2-SNAPSHOT
+ 1.4.3-SNAPSHOT
compile
@@ -49,7 +49,7 @@
org.apache.maven.plugins
maven-shade-plugin
- 3.2.1
+ 3.3.0-SNAPSHOT
package
diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/command/BungeeCommandSender.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/command/BungeeCommandSender.java
index 807cf4786..1f3a875b2 100644
--- a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/command/BungeeCommandSender.java
+++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/command/BungeeCommandSender.java
@@ -57,8 +57,7 @@ public class BungeeCommandSender implements CommandSender {
@Override
public String getLocale() {
- if (handle instanceof ProxiedPlayer) {
- ProxiedPlayer player = (ProxiedPlayer) handle;
+ if (handle instanceof ProxiedPlayer player) {
String locale = player.getLocale().getLanguage() + "_" + player.getLocale().getCountry();
return LanguageUtils.formatLocale(locale);
}
diff --git a/bootstrap/pom.xml b/bootstrap/pom.xml
index c54d489fa..38489fa25 100644
--- a/bootstrap/pom.xml
+++ b/bootstrap/pom.xml
@@ -6,7 +6,7 @@
org.geysermc
geyser-parent
- 1.4.2-SNAPSHOT
+ 1.4.3-SNAPSHOT
bootstrap-parent
pom
@@ -34,7 +34,7 @@
org.geysermc
ap
- 1.4.2-SNAPSHOT
+ 1.4.3-SNAPSHOT
provided
diff --git a/bootstrap/spigot/pom.xml b/bootstrap/spigot/pom.xml
index cc2a73ffd..dd6b28473 100644
--- a/bootstrap/spigot/pom.xml
+++ b/bootstrap/spigot/pom.xml
@@ -6,7 +6,7 @@
org.geysermc
bootstrap-parent
- 1.4.2-SNAPSHOT
+ 1.4.3-SNAPSHOT
bootstrap-spigot
@@ -21,7 +21,7 @@
org.geysermc
connector
- 1.4.2-SNAPSHOT
+ 1.4.3-SNAPSHOT
compile
@@ -66,7 +66,7 @@
org.apache.maven.plugins
maven-shade-plugin
- 3.2.1
+ 3.3.0-SNAPSHOT
package
diff --git a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/command/SpigotCommandSender.java b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/command/SpigotCommandSender.java
index c1c2b2c72..16533623a 100644
--- a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/command/SpigotCommandSender.java
+++ b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/command/SpigotCommandSender.java
@@ -97,8 +97,7 @@ public class SpigotCommandSender implements CommandSender {
* @return the locale of the Spigot player
*/
private String getSpigotLocale() {
- if (handle instanceof Player) {
- Player player = (Player) handle;
+ if (handle instanceof Player player) {
if (USE_LEGACY_METHOD) {
try {
// sigh
diff --git a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/GeyserSpigot1_11CraftingListener.java b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/GeyserSpigot1_11CraftingListener.java
index 4f24af19c..f7a9d6df7 100644
--- a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/GeyserSpigot1_11CraftingListener.java
+++ b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/GeyserSpigot1_11CraftingListener.java
@@ -109,8 +109,7 @@ public class GeyserSpigot1_11CraftingListener implements Listener {
if (output == null || output.getId() == 0) continue; // If items make air we don't want that
boolean isNotAllAir = false; // Check for all-air recipes
- if (recipe instanceof ShapedRecipe) {
- ShapedRecipe shapedRecipe = (ShapedRecipe) recipe;
+ if (recipe instanceof ShapedRecipe shapedRecipe) {
int size = shapedRecipe.getShape().length * shapedRecipe.getShape()[0].length();
Ingredient[] ingredients = new Ingredient[size];
ItemData[] input = new ItemData[size];
@@ -134,8 +133,7 @@ public class GeyserSpigot1_11CraftingListener implements Listener {
craftingDataPacket.getCraftingData().add(CraftingData.fromShaped(uuid.toString(),
shapedRecipe.getShape()[0].length(), shapedRecipe.getShape().length, Arrays.asList(input),
Collections.singletonList(output), uuid, "crafting_table", 0, netId++));
- } else if (recipe instanceof ShapelessRecipe) {
- ShapelessRecipe shapelessRecipe = (ShapelessRecipe) recipe;
+ } else if (recipe instanceof ShapelessRecipe shapelessRecipe) {
Ingredient[] ingredients = new Ingredient[shapelessRecipe.getIngredientList().size()];
ItemData[] input = new ItemData[shapelessRecipe.getIngredientList().size()];
diff --git a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigotWorldManager.java b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigotWorldManager.java
index 516cf13dc..a0e97c51a 100644
--- a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigotWorldManager.java
+++ b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigotWorldManager.java
@@ -99,14 +99,13 @@ public class GeyserSpigotWorldManager extends GeyserWorldManager {
}
Block block = bukkitPlayer.getWorld().getBlockAt(x, y, z);
- if (!(block.getState() instanceof Lectern)) {
+ if (!(block.getState() instanceof Lectern lectern)) {
session.getConnector().getLogger().error("Lectern expected at: " + Vector3i.from(x, y, z).toString() + " but was not! " + block.toString());
return;
}
- Lectern lectern = (Lectern) block.getState();
ItemStack itemStack = lectern.getInventory().getItem(0);
- if (itemStack == null || !(itemStack.getItemMeta() instanceof BookMeta)) {
+ if (itemStack == null || !(itemStack.getItemMeta() instanceof BookMeta bookMeta)) {
if (!isChunkLoad) {
// We need to update the lectern since it's not going to be updated otherwise
BlockEntityUtils.updateBlockEntity(session, LecternInventoryTranslator.getBaseLecternTag(x, y, z, 0).build(), Vector3i.from(x, y, z));
@@ -115,7 +114,6 @@ public class GeyserSpigotWorldManager extends GeyserWorldManager {
return;
}
- BookMeta bookMeta = (BookMeta) itemStack.getItemMeta();
// On the count: allow the book to show/open even there are no pages. We know there is a book here, after all, and this matches Java behavior
boolean hasBookPages = bookMeta.getPageCount() > 0;
NbtMapBuilder lecternTag = LecternInventoryTranslator.getBaseLecternTag(x, y, z, hasBookPages ? bookMeta.getPageCount() : 1);
diff --git a/bootstrap/sponge/pom.xml b/bootstrap/sponge/pom.xml
index 4991e8aaf..a5582bbe0 100644
--- a/bootstrap/sponge/pom.xml
+++ b/bootstrap/sponge/pom.xml
@@ -6,7 +6,7 @@
org.geysermc
bootstrap-parent
- 1.4.2-SNAPSHOT
+ 1.4.3-SNAPSHOT
bootstrap-sponge
@@ -14,7 +14,7 @@
org.geysermc
connector
- 1.4.2-SNAPSHOT
+ 1.4.3-SNAPSHOT
compile
@@ -48,7 +48,7 @@
org.apache.maven.plugins
maven-shade-plugin
- 3.2.1
+ 3.3.0-SNAPSHOT
package
diff --git a/bootstrap/standalone/pom.xml b/bootstrap/standalone/pom.xml
index e39097b4a..64a6f6fee 100644
--- a/bootstrap/standalone/pom.xml
+++ b/bootstrap/standalone/pom.xml
@@ -6,7 +6,7 @@
org.geysermc
bootstrap-parent
- 1.4.2-SNAPSHOT
+ 1.4.3-SNAPSHOT
bootstrap-standalone
@@ -14,7 +14,7 @@
org.geysermc
connector
- 1.4.2-SNAPSHOT
+ 1.4.3-SNAPSHOT
compile
@@ -89,7 +89,7 @@
org.apache.maven.plugins
maven-shade-plugin
- 3.2.1
+ 3.3.0-SNAPSHOT
com.github.edwgiz
diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserStandaloneBootstrap.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserStandaloneBootstrap.java
index f875127cc..6a612f17d 100644
--- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserStandaloneBootstrap.java
+++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserStandaloneBootstrap.java
@@ -98,32 +98,26 @@ public class GeyserStandaloneBootstrap implements GeyserBootstrap {
// Allows gui and nogui without options, for backwards compatibility
String arg = args[i];
switch (arg) {
- case "--gui":
- case "gui":
- useGuiOpts = true;
- break;
- case "--nogui":
- case "nogui":
- useGuiOpts = false;
- break;
- case "--config":
- case "-c":
+ case "--gui", "gui" -> useGuiOpts = true;
+ case "--nogui", "nogui" -> useGuiOpts = false;
+ case "--config", "-c" -> {
if (i >= args.length - 1) {
System.err.println(MessageFormat.format(LanguageUtils.getLocaleStringLog("geyser.bootstrap.args.config_not_specified"), "-c"));
return;
}
- configFilenameOpt = args[i+1]; i++;
+ configFilenameOpt = args[i + 1];
+ i++;
System.out.println(MessageFormat.format(LanguageUtils.getLocaleStringLog("geyser.bootstrap.args.config_specified"), configFilenameOpt));
- break;
- case "--help":
- case "-h":
+ }
+ case "--help", "-h" -> {
System.out.println(MessageFormat.format(LanguageUtils.getLocaleStringLog("geyser.bootstrap.args.usage"), "[java -jar] Geyser.jar [opts]"));
System.out.println(" " + LanguageUtils.getLocaleStringLog("geyser.bootstrap.args.options"));
System.out.println(" -c, --config [file] " + LanguageUtils.getLocaleStringLog("geyser.bootstrap.args.config"));
System.out.println(" -h, --help " + LanguageUtils.getLocaleStringLog("geyser.bootstrap.args.help"));
System.out.println(" --gui, --nogui " + LanguageUtils.getLocaleStringLog("geyser.bootstrap.args.gui"));
return;
- default:
+ }
+ default -> {
// We have likely added a config option argument
if (arg.startsWith("--")) {
// Split the argument by an =
@@ -159,9 +153,9 @@ public class GeyserStandaloneBootstrap implements GeyserBootstrap {
}
}
}
-
System.err.println(LanguageUtils.getLocaleStringLog("geyser.bootstrap.args.unrecognised", arg));
return;
+ }
}
}
bootstrap.onEnable(useGuiOpts, configFilenameOpt);
diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/gui/GraphPanel.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/gui/GraphPanel.java
index 68adfde52..9cfa9399d 100644
--- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/gui/GraphPanel.java
+++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/gui/GraphPanel.java
@@ -68,11 +68,10 @@ public final class GraphPanel extends JPanel {
@Override
protected void paintComponent(Graphics graphics) {
super.paintComponent(graphics);
- if (!(graphics instanceof Graphics2D)) {
+ if (!(graphics instanceof final Graphics2D g)) {
graphics.drawString("Graphics is not Graphics2D, unable to render", 0, 0);
return;
}
- final Graphics2D g = (Graphics2D) graphics;
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
final int length = values.size();
diff --git a/bootstrap/velocity/pom.xml b/bootstrap/velocity/pom.xml
index 1e74bafbc..33df2be80 100644
--- a/bootstrap/velocity/pom.xml
+++ b/bootstrap/velocity/pom.xml
@@ -6,7 +6,7 @@
org.geysermc
bootstrap-parent
- 1.4.2-SNAPSHOT
+ 1.4.3-SNAPSHOT
bootstrap-velocity
@@ -14,7 +14,7 @@
org.geysermc
connector
- 1.4.2-SNAPSHOT
+ 1.4.3-SNAPSHOT
compile
@@ -48,7 +48,7 @@
org.apache.maven.plugins
maven-shade-plugin
- 3.2.1
+ 3.3.0-SNAPSHOT
package
diff --git a/common/pom.xml b/common/pom.xml
index edf31c2b8..a3e86ff9b 100644
--- a/common/pom.xml
+++ b/common/pom.xml
@@ -6,7 +6,7 @@
org.geysermc
geyser-parent
- 1.4.2-SNAPSHOT
+ 1.4.3-SNAPSHOT
common
diff --git a/connector/pom.xml b/connector/pom.xml
index e6bb897dd..0a15c759d 100644
--- a/connector/pom.xml
+++ b/connector/pom.xml
@@ -6,7 +6,7 @@
org.geysermc
geyser-parent
- 1.4.2-SNAPSHOT
+ 1.4.3-SNAPSHOT
connector
@@ -21,13 +21,13 @@
org.geysermc
ap
- 1.4.2-SNAPSHOT
+ 1.4.3-SNAPSHOT
provided
org.geysermc
common
- 1.4.2-SNAPSHOT
+ 1.4.3-SNAPSHOT
compile
diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java
index 0c9217147..7e22792fa 100644
--- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java
+++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java
@@ -384,40 +384,9 @@ public class GeyserConnector {
logger.warning(LanguageUtils.getLocaleStringLog("geyser.core.movement_warn"));
}
- checkForOutdatedJava();
-
newsHandler.handleNews(null, NewsItemAction.ON_SERVER_STARTED);
}
- private void checkForOutdatedJava() {
- final int supportedJavaVersion = 16;
- // Taken from Paper
- String javaVersion = System.getProperty("java.version");
- Matcher matcher = Pattern.compile("(?:1\\.)?(\\d+)").matcher(javaVersion);
- if (!matcher.find()) {
- getLogger().debug("Could not parse Java version string " + javaVersion);
- return;
- }
-
- String version = matcher.group(1);
- int majorVersion;
- try {
- majorVersion = Integer.parseInt(version);
- } catch (NumberFormatException e) {
- getLogger().debug("Could not format as an int: " + version);
- return;
- }
-
- if (majorVersion < supportedJavaVersion) {
- getLogger().warning("*********************************************");
- getLogger().warning("");
- getLogger().warning(LanguageUtils.getLocaleStringLog("geyser.bootstrap.unsupported_java.header"));
- getLogger().warning(LanguageUtils.getLocaleStringLog("geyser.bootstrap.unsupported_java.message", supportedJavaVersion, javaVersion));
- getLogger().warning("");
- getLogger().warning("*********************************************");
- }
- }
-
public void shutdown() {
bootstrap.getGeyserLogger().info(LanguageUtils.getLocaleStringLog("geyser.core.shutdown"));
shuttingDown = true;
diff --git a/connector/src/main/java/org/geysermc/connector/command/defaults/DumpCommand.java b/connector/src/main/java/org/geysermc/connector/command/defaults/DumpCommand.java
index 07a690298..0a1c81114 100644
--- a/connector/src/main/java/org/geysermc/connector/command/defaults/DumpCommand.java
+++ b/connector/src/main/java/org/geysermc/connector/command/defaults/DumpCommand.java
@@ -69,15 +69,9 @@ public class DumpCommand extends GeyserCommand {
if (args.length >= 1) {
for (String arg : args) {
switch (arg) {
- case "full":
- showSensitive = true;
- break;
- case "offline":
- offlineDump = true;
- break;
- case "logs":
- addLog = true;
- break;
+ case "full" -> showSensitive = true;
+ case "offline" -> offlineDump = true;
+ case "logs" -> addLog = true;
}
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/configuration/EmoteOffhandWorkaroundOption.java b/connector/src/main/java/org/geysermc/connector/configuration/EmoteOffhandWorkaroundOption.java
index 954e3d32a..c28048046 100644
--- a/connector/src/main/java/org/geysermc/connector/configuration/EmoteOffhandWorkaroundOption.java
+++ b/connector/src/main/java/org/geysermc/connector/configuration/EmoteOffhandWorkaroundOption.java
@@ -40,14 +40,11 @@ public enum EmoteOffhandWorkaroundOption {
@Override
public EmoteOffhandWorkaroundOption deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
String value = p.getValueAsString();
- switch (value) {
- case "no-emotes":
- return NO_EMOTES;
- case "emotes-and-offhand":
- return EMOTES_AND_OFFHAND;
- default:
- return DISABLED;
- }
+ return switch (value) {
+ case "no-emotes" -> NO_EMOTES;
+ case "emotes-and-offhand" -> EMOTES_AND_OFFHAND;
+ default -> DISABLED;
+ };
}
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/EnderCrystalEntity.java b/connector/src/main/java/org/geysermc/connector/entity/EnderCrystalEntity.java
index 596ccf089..e4b60980f 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/EnderCrystalEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/EnderCrystalEntity.java
@@ -48,8 +48,7 @@ public class EnderCrystalEntity extends Entity {
// Show beam
// Usually performed client-side on Bedrock except for Ender Dragon respawn event
if (entityMetadata.getId() == 8) {
- if (entityMetadata.getValue() instanceof Position) {
- Position pos = (Position) entityMetadata.getValue();
+ if (entityMetadata.getValue() instanceof Position pos) {
metadata.put(EntityData.BLOCK_TARGET, Vector3i.from(pos.getX(), pos.getY(), pos.getZ()));
} else {
metadata.put(EntityData.BLOCK_TARGET, Vector3i.ZERO);
diff --git a/connector/src/main/java/org/geysermc/connector/entity/Entity.java b/connector/src/main/java/org/geysermc/connector/entity/Entity.java
index eb9b8ec1c..f8bf9693d 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/Entity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/Entity.java
@@ -256,11 +256,9 @@ public class Entity {
setAir((int) entityMetadata.getValue());
break;
case 2: // custom name
- if (entityMetadata.getValue() instanceof Component) {
- Component message = (Component) entityMetadata.getValue();
- if (message != null)
- // Always translate even if it's a TextMessage since there could be translatable parameters
- metadata.put(EntityData.NAMETAG, MessageTranslator.convertMessage(message, session.getLocale()));
+ if (entityMetadata.getValue() instanceof Component message) {
+ // Always translate even if it's a TextMessage since there could be translatable parameters
+ metadata.put(EntityData.NAMETAG, MessageTranslator.convertMessage(message, session.getLocale()));
}
break;
case 3: // is custom name visible
diff --git a/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java b/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java
index 5ba66f71a..44a9859d5 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java
@@ -84,21 +84,21 @@ public class LivingEntity extends Entity {
@Override
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
switch (entityMetadata.getId()) {
- case 8: // blocking
+ case 8 -> { // blocking
byte xd = (byte) entityMetadata.getValue();
//blocking gets triggered when using a bow, but if we set USING_ITEM for all items, it may look like
//you're "mining" with ex. a shield.
ItemMapping shield = session.getItemMappings().getStoredItems().shield();
boolean isUsingShield = (getHand().getId() == shield.getBedrockId() ||
- getHand().equals(ItemData.AIR) && getOffHand().getId() == shield.getBedrockId());
+ getHand().equals(ItemData.AIR) && getOffHand().getId() == shield.getBedrockId());
metadata.getFlags().setFlag(EntityFlag.USING_ITEM, (xd & 0x01) == 0x01 && !isUsingShield);
metadata.getFlags().setFlag(EntityFlag.BLOCKING, (xd & 0x01) == 0x01);
// Riptide spin attack
metadata.getFlags().setFlag(EntityFlag.DAMAGE_NEARBY_MOBS, (xd & 0x04) == 0x04);
- break;
- case 9:
+ }
+ case 9 -> {
this.health = (float) entityMetadata.getValue();
AttributeData healthData = createHealthAttribute();
@@ -106,14 +106,10 @@ public class LivingEntity extends Entity {
attributesPacket.setRuntimeEntityId(geyserId);
attributesPacket.setAttributes(Collections.singletonList(healthData));
session.sendUpstreamPacket(attributesPacket);
- break;
- case 10:
- metadata.put(EntityData.EFFECT_COLOR, entityMetadata.getValue());
- break;
- case 11:
- metadata.put(EntityData.EFFECT_AMBIENT, (byte) ((boolean) entityMetadata.getValue() ? 1 : 0));
- break;
- case 14: // Bed Position
+ }
+ case 10 -> metadata.put(EntityData.EFFECT_COLOR, entityMetadata.getValue());
+ case 11 -> metadata.put(EntityData.EFFECT_AMBIENT, (byte) ((boolean) entityMetadata.getValue() ? 1 : 0));
+ case 14 -> { // Bed Position
Position bedPosition = (Position) entityMetadata.getValue();
if (bedPosition != null) {
metadata.put(EntityData.BED_POSITION, Vector3i.from(bedPosition.getX(), bedPosition.getY(), bedPosition.getZ()));
@@ -128,7 +124,7 @@ public class LivingEntity extends Entity {
// Player is no longer sleeping
metadata.put(EntityData.PLAYER_FLAGS, (byte) 0);
}
- break;
+ }
}
super.updateBedrockMetadata(entityMetadata, session);
@@ -249,28 +245,16 @@ public class LivingEntity extends Entity {
*/
protected void updateAttribute(Attribute javaAttribute, List newAttributes) {
switch (javaAttribute.getType()) {
- case GENERIC_MAX_HEALTH:
+ case GENERIC_MAX_HEALTH -> {
this.maxHealth = (float) AttributeUtils.calculateValue(javaAttribute);
newAttributes.add(createHealthAttribute());
- break;
- case GENERIC_ATTACK_DAMAGE:
- newAttributes.add(calculateAttribute(javaAttribute, GeyserAttributeType.ATTACK_DAMAGE));
- break;
- case GENERIC_FLYING_SPEED:
- newAttributes.add(calculateAttribute(javaAttribute, GeyserAttributeType.FLYING_SPEED));
- break;
- case GENERIC_MOVEMENT_SPEED:
- newAttributes.add(calculateAttribute(javaAttribute, GeyserAttributeType.MOVEMENT_SPEED));
- break;
- case GENERIC_FOLLOW_RANGE:
- newAttributes.add(calculateAttribute(javaAttribute, GeyserAttributeType.FOLLOW_RANGE));
- break;
- case GENERIC_KNOCKBACK_RESISTANCE:
- newAttributes.add(calculateAttribute(javaAttribute, GeyserAttributeType.KNOCKBACK_RESISTANCE));
- break;
- case HORSE_JUMP_STRENGTH:
- newAttributes.add(calculateAttribute(javaAttribute, GeyserAttributeType.HORSE_JUMP_STRENGTH));
- break;
+ }
+ case GENERIC_ATTACK_DAMAGE -> newAttributes.add(calculateAttribute(javaAttribute, GeyserAttributeType.ATTACK_DAMAGE));
+ case GENERIC_FLYING_SPEED -> newAttributes.add(calculateAttribute(javaAttribute, GeyserAttributeType.FLYING_SPEED));
+ case GENERIC_MOVEMENT_SPEED -> newAttributes.add(calculateAttribute(javaAttribute, GeyserAttributeType.MOVEMENT_SPEED));
+ case GENERIC_FOLLOW_RANGE -> newAttributes.add(calculateAttribute(javaAttribute, GeyserAttributeType.FOLLOW_RANGE));
+ case GENERIC_KNOCKBACK_RESISTANCE -> newAttributes.add(calculateAttribute(javaAttribute, GeyserAttributeType.KNOCKBACK_RESISTANCE));
+ case HORSE_JUMP_STRENGTH -> newAttributes.add(calculateAttribute(javaAttribute, GeyserAttributeType.HORSE_JUMP_STRENGTH));
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/PaintingEntity.java b/connector/src/main/java/org/geysermc/connector/entity/PaintingEntity.java
index 3e2ff7ead..b620e598b 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/PaintingEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/PaintingEntity.java
@@ -68,12 +68,12 @@ public class PaintingEntity extends Entity {
double widthOffset = paintingName.getWidth() > 1 ? 0.5 : 0;
double heightOffset = paintingName.getHeight() > 1 && paintingName.getHeight() != 3 ? 0.5 : 0;
- switch (direction) {
- case 0: return position.add(widthOffset, heightOffset, OFFSET);
- case 1: return position.add(-OFFSET, heightOffset, widthOffset);
- case 2: return position.add(-widthOffset, heightOffset, -OFFSET);
- case 3: return position.add(OFFSET, heightOffset, -widthOffset);
- }
- return position;
+ return switch (direction) {
+ case 0 -> position.add(widthOffset, heightOffset, OFFSET);
+ case 1 -> position.add(-OFFSET, heightOffset, widthOffset);
+ case 2 -> position.add(-widthOffset, heightOffset, -OFFSET);
+ case 3 -> position.add(OFFSET, heightOffset, -widthOffset);
+ default -> position;
+ };
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/ArmorStandEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/ArmorStandEntity.java
index d447f6379..6a87097a1 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/ArmorStandEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/ArmorStandEntity.java
@@ -161,42 +161,42 @@ public class ArmorStandEntity extends LivingEntity {
EntityFlag negativeYToggle = null;
EntityFlag negativeZToggle = null;
switch (entityMetadata.getId()) {
- case 16: // Head
+ case 16 -> { // Head
dataLeech = EntityData.MARK_VARIANT;
negativeXToggle = EntityFlag.INTERESTED;
negativeYToggle = EntityFlag.CHARGED;
negativeZToggle = EntityFlag.POWERED;
- break;
- case 17: // Body
+ }
+ case 17 -> { // Body
dataLeech = EntityData.VARIANT;
negativeXToggle = EntityFlag.IN_LOVE;
negativeYToggle = EntityFlag.CELEBRATING;
negativeZToggle = EntityFlag.CELEBRATING_SPECIAL;
- break;
- case 18: // Left arm
+ }
+ case 18 -> { // Left arm
dataLeech = EntityData.TRADE_TIER;
negativeXToggle = EntityFlag.CHARGING;
negativeYToggle = EntityFlag.CRITICAL;
negativeZToggle = EntityFlag.DANCING;
- break;
- case 19: // Right arm
+ }
+ case 19 -> { // Right arm
dataLeech = EntityData.MAX_TRADE_TIER;
negativeXToggle = EntityFlag.ELDER;
negativeYToggle = EntityFlag.EMOTING;
negativeZToggle = EntityFlag.IDLING;
- break;
- case 20: // Left leg
+ }
+ case 20 -> { // Left leg
dataLeech = EntityData.SKIN_ID;
negativeXToggle = EntityFlag.IS_ILLAGER_CAPTAIN;
negativeYToggle = EntityFlag.IS_IN_UI;
negativeZToggle = EntityFlag.LINGERING;
- break;
- case 21: // Right leg
+ }
+ case 21 -> { // Right leg
dataLeech = EntityData.HURT_DIRECTION;
negativeXToggle = EntityFlag.IS_PREGNANT;
negativeYToggle = EntityFlag.SHEARED;
negativeZToggle = EntityFlag.STALKING;
- break;
+ }
}
if (dataLeech != null) {
// Indicate that rotation should be checked
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/AxolotlEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/AxolotlEntity.java
index 3d2be0ce7..0968cecb0 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/AxolotlEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/AxolotlEntity.java
@@ -44,12 +44,8 @@ public class AxolotlEntity extends AnimalEntity {
if (entityMetadata.getId() == 17) {
int variant = (int) entityMetadata.getValue();
switch (variant) {
- case 1: // Java - "Wild" (brown)
- variant = 3;
- break;
- case 3: // Java - cyan
- variant = 1;
- break;
+ case 1 -> variant = 3; // Java - "Wild" (brown)
+ case 3 -> variant = 1; // Java - cyan
}
metadata.put(EntityData.VARIANT, variant);
}
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java
index 904f563f9..f22124409 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java
@@ -59,23 +59,14 @@ public class CatEntity extends TameableEntity {
}
if (entityMetadata.getId() == 19) {
// Different colors in Java and Bedrock for some reason
- int variantColor;
- switch ((int) entityMetadata.getValue()) {
- case 0:
- variantColor = 8;
- break;
- case 8:
- variantColor = 0;
- break;
- case 9:
- variantColor = 10;
- break;
- case 10:
- variantColor = 9;
- break;
- default:
- variantColor = (int) entityMetadata.getValue();
- }
+ int metadataValue = (int) entityMetadata.getValue();
+ int variantColor = switch (metadataValue) {
+ case 0 -> 8;
+ case 8 -> 0;
+ case 9 -> 10;
+ case 10 -> 9;
+ default -> metadataValue;
+ };
metadata.put(EntityData.VARIANT, variantColor);
}
if (entityMetadata.getId() == 20) {
diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/raid/SpellcasterIllagerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/raid/SpellcasterIllagerEntity.java
index 7e92a7569..693220dda 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/raid/SpellcasterIllagerEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/raid/SpellcasterIllagerEntity.java
@@ -49,19 +49,13 @@ public class SpellcasterIllagerEntity extends AbstractIllagerEntity {
int spellType = (int) (byte) entityMetadata.getValue();
// Summon vex, attack, or wololo
metadata.getFlags().setFlag(EntityFlag.CASTING, spellType == 1 || spellType == 2 || spellType == 3);
- int rgbData = 0;
- // Set the spell color based on Java values
- switch (spellType) {
- case 1:
- rgbData = SUMMON_VEX_PARTICLE_COLOR;
- break;
- case 2:
- rgbData = ATTACK_PARTICLE_COLOR;
- break;
- case 3:
- rgbData = WOLOLO_PARTICLE_COLOR;
- break;
- }
+ int rgbData = switch (spellType) {
+ // Set the spell color based on Java values
+ case 1 -> SUMMON_VEX_PARTICLE_COLOR;
+ case 2 -> ATTACK_PARTICLE_COLOR;
+ case 3 -> WOLOLO_PARTICLE_COLOR;
+ default -> 0;
+ };
metadata.put(EntityData.EVOKER_SPELL_COLOR, rgbData);
}
super.updateBedrockMetadata(entityMetadata, session);
diff --git a/connector/src/main/java/org/geysermc/connector/entity/player/PlayerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/player/PlayerEntity.java
index 6d4117a80..d5170d2fc 100644
--- a/connector/src/main/java/org/geysermc/connector/entity/player/PlayerEntity.java
+++ b/connector/src/main/java/org/geysermc/connector/entity/player/PlayerEntity.java
@@ -316,17 +316,12 @@ public class PlayerEntity extends LivingEntity {
protected void setDimensions(Pose pose) {
float height;
switch (pose) {
- case SNEAKING:
- height = 1.5f;
- break;
- case FALL_FLYING:
- case SPIN_ATTACK:
- case SWIMMING:
- height = 0.6f;
- break;
- default:
+ case SNEAKING -> height = 1.5f;
+ case FALL_FLYING, SPIN_ATTACK, SWIMMING -> height = 0.6f;
+ default -> {
super.setDimensions(pose);
return;
+ }
}
metadata.put(EntityData.BOUNDING_BOX_WIDTH, entityType.getWidth());
metadata.put(EntityData.BOUNDING_BOX_HEIGHT, height);
diff --git a/connector/src/main/java/org/geysermc/connector/network/BedrockProtocol.java b/connector/src/main/java/org/geysermc/connector/network/BedrockProtocol.java
index 660f1d039..3efb7a849 100644
--- a/connector/src/main/java/org/geysermc/connector/network/BedrockProtocol.java
+++ b/connector/src/main/java/org/geysermc/connector/network/BedrockProtocol.java
@@ -26,9 +26,7 @@
package org.geysermc.connector.network;
import com.nukkitx.protocol.bedrock.BedrockPacketCodec;
-import com.nukkitx.protocol.bedrock.v440.Bedrock_v440;
import com.nukkitx.protocol.bedrock.v448.Bedrock_v448;
-import org.geysermc.connector.GeyserConnector;
import java.util.ArrayList;
import java.util.List;
@@ -49,11 +47,6 @@ public class BedrockProtocol {
public static final List SUPPORTED_BEDROCK_CODECS = new ArrayList<>();
static {
- if (!GeyserConnector.getInstance().getConfig().isExtendedWorldHeight()) {
- SUPPORTED_BEDROCK_CODECS.add(Bedrock_v440.V440_CODEC.toBuilder()
- .minecraftVersion("1.17.0/1.17.1/1.17.2")
- .build());
- }
SUPPORTED_BEDROCK_CODECS.add(DEFAULT_BEDROCK_CODEC.toBuilder()
.minecraftVersion("1.17.10/1.17.11")
.build());
diff --git a/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java b/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java
index 94dd0b744..dcc3cb50b 100644
--- a/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java
+++ b/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java
@@ -129,10 +129,10 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler {
}
// Fallbacks to prevent errors and allow Bedrock to see the server
- if (pong.getMotd() == null || pong.getMotd().trim().isEmpty()) {
+ if (pong.getMotd() == null || pong.getMotd().isBlank()) {
pong.setMotd(GeyserConnector.NAME);
}
- if (pong.getSubMotd() == null || pong.getSubMotd().trim().isEmpty()) {
+ if (pong.getSubMotd() == null || pong.getSubMotd().isBlank()) {
// Sub-MOTD cannot be empty as of 1.16.210.59
pong.setSubMotd(GeyserConnector.NAME);
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityEffectCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityEffectCache.java
index 7cf296be2..e165ea545 100644
--- a/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityEffectCache.java
+++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityEffectCache.java
@@ -48,30 +48,18 @@ public class EntityEffectCache {
public void setEffect(Effect effect, int effectAmplifier) {
switch (effect) {
- case CONDUIT_POWER:
- conduitPower = effectAmplifier + 1;
- break;
- case FASTER_DIG:
- haste = effectAmplifier + 1;
- break;
- case SLOWER_DIG:
- miningFatigue = effectAmplifier + 1;
- break;
+ case CONDUIT_POWER -> conduitPower = effectAmplifier + 1;
+ case FASTER_DIG -> haste = effectAmplifier + 1;
+ case SLOWER_DIG -> miningFatigue = effectAmplifier + 1;
}
entityEffects.add(effect);
}
public void removeEffect(Effect effect) {
switch (effect) {
- case CONDUIT_POWER:
- conduitPower = 0;
- break;
- case FASTER_DIG:
- haste = 0;
- break;
- case SLOWER_DIG:
- miningFatigue = 0;
- break;
+ case CONDUIT_POWER -> conduitPower = 0;
+ case FASTER_DIG -> haste = 0;
+ case SLOWER_DIG -> miningFatigue = 0;
}
entityEffects.remove(effect);
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAnimateTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAnimateTranslator.java
index 53912bf4e..229cba6e7 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAnimateTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAnimateTranslator.java
@@ -46,26 +46,25 @@ public class BedrockAnimateTranslator extends PacketTranslator {
}
switch (packet.getAction()) {
- case SWING_ARM:
+ case SWING_ARM ->
// Delay so entity damage can be processed first
session.scheduleInEventLoop(() ->
session.sendDownstreamPacket(new ClientPlayerSwingArmPacket(Hand.MAIN_HAND)),
25,
TimeUnit.MILLISECONDS
);
- break;
// These two might need to be flipped, but my recommendation is getting moving working first
- case ROW_LEFT:
+ case ROW_LEFT -> {
// Packet value is a float of how long one has been rowing, so we convert that into a boolean
session.setSteeringLeft(packet.getRowingTime() > 0.0);
ClientSteerBoatPacket steerLeftPacket = new ClientSteerBoatPacket(session.isSteeringLeft(), session.isSteeringRight());
session.sendDownstreamPacket(steerLeftPacket);
- break;
- case ROW_RIGHT:
+ }
+ case ROW_RIGHT -> {
session.setSteeringRight(packet.getRowingTime() > 0.0);
ClientSteerBoatPacket steerRightPacket = new ClientSteerBoatPacket(session.isSteeringLeft(), session.isSteeringRight());
session.sendDownstreamPacket(steerRightPacket);
- break;
+ }
}
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandBlockUpdateTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandBlockUpdateTranslator.java
index f8f503387..4a87776b1 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandBlockUpdateTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandBlockUpdateTranslator.java
@@ -42,18 +42,14 @@ public class BedrockCommandBlockUpdateTranslator extends PacketTranslator // The green one
+ CommandBlockMode.SEQUENCE;
+ case REPEATING -> // The purple one
+ CommandBlockMode.AUTO;
+ default -> // NORMAL, the orange one
+ CommandBlockMode.REDSTONE;
+ };
boolean isConditional = packet.isConditional();
boolean automatic = !packet.isRedstoneMode(); // Automatic = Always Active option in Java
ClientUpdateCommandBlockPacket commandBlockPacket = new ClientUpdateCommandBlockPacket(
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockEntityPickRequestTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockEntityPickRequestTranslator.java
index c6677dbdc..c1febb795 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockEntityPickRequestTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockEntityPickRequestTranslator.java
@@ -50,59 +50,30 @@ public class BedrockEntityPickRequestTranslator extends PacketTranslator {
// Include type of boat in the name
int variant = entity.getMetadata().getInt(EntityData.VARIANT);
- String typeOfBoat;
- switch (variant) {
- case 1:
- typeOfBoat = "spruce";
- break;
- case 2:
- typeOfBoat = "birch";
- break;
- case 3:
- typeOfBoat = "jungle";
- break;
- case 4:
- typeOfBoat = "acacia";
- break;
- case 5:
- typeOfBoat = "dark_oak";
- break;
- default:
- typeOfBoat = "oak";
- break;
- }
+ String typeOfBoat = switch (variant) {
+ case 1 -> "spruce";
+ case 2 -> "birch";
+ case 3 -> "jungle";
+ case 4 -> "acacia";
+ case 5 -> "dark_oak";
+ default -> "oak";
+ };
itemName = typeOfBoat + "_boat";
- break;
- case LEASH_KNOT:
- itemName = "lead";
- break;
- case MINECART_CHEST:
- case MINECART_COMMAND_BLOCK:
- case MINECART_FURNACE:
- case MINECART_HOPPER:
- case MINECART_TNT:
- // Move MINECART to the end of the name
- itemName = entity.getEntityType().toString().toLowerCase().replace("minecart_", "") + "_minecart";
- break;
- case MINECART_SPAWNER:
- // Turns into a normal minecart
- itemName = "minecart";
- break;
- case ARMOR_STAND:
- case END_CRYSTAL:
- //case ITEM_FRAME: Not an entity in Bedrock Edition
- //case GLOW_ITEM_FRAME:
- case MINECART:
- case PAINTING:
- // No spawn egg, just an item
- itemName = entity.getEntityType().toString().toLowerCase();
- break;
- default:
- itemName = entity.getEntityType().toString().toLowerCase() + "_spawn_egg";
- break;
+ }
+ case LEASH_KNOT -> itemName = "lead";
+ case MINECART_CHEST, MINECART_COMMAND_BLOCK, MINECART_FURNACE, MINECART_HOPPER, MINECART_TNT ->
+ // Move MINECART to the end of the name
+ itemName = entity.getEntityType().toString().toLowerCase().replace("minecart_", "") + "_minecart";
+ case MINECART_SPAWNER -> itemName = "minecart"; // Turns into a normal minecart
+ //case ITEM_FRAME -> Not an entity in Bedrock Edition
+ //case GLOW_ITEM_FRAME ->
+ case ARMOR_STAND, END_CRYSTAL, MINECART, PAINTING ->
+ // No spawn egg, just an item
+ itemName = entity.getEntityType().toString().toLowerCase();
+ default -> itemName = entity.getEntityType().toString().toLowerCase() + "_spawn_egg";
}
String fullItemName = "minecraft:" + itemName;
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java
index 2de4e4cad..469b70ea0 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java
@@ -108,7 +108,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator {
// Check to make sure the client isn't spamming interaction
// Based on Nukkit 1.0, with changes to ensure holding down still works
boolean hasAlreadyClicked = System.currentTimeMillis() - session.getLastInteractionTime() < 110.0 &&
@@ -155,17 +155,14 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator
playerPosition = playerPosition.sub(0, (EntityType.PLAYER.getOffset() - 1.27f), 0);
- break;
- case SWIMMING:
- case FALL_FLYING: // Elytra
- case SPIN_ATTACK: // Trident spin attack
+ case SWIMMING,
+ FALL_FLYING, // Elytra
+ SPIN_ATTACK -> // Trident spin attack
playerPosition = playerPosition.sub(0, (EntityType.PLAYER.getOffset() - 0.4f), 0);
- break;
- case SLEEPING:
+ case SLEEPING ->
playerPosition = playerPosition.sub(0, (EntityType.PLAYER.getOffset() - 0.2f), 0);
- break;
} // else, we don't have to modify the position
float diffX = playerPosition.getX() - packet.getBlockPosition().getX();
@@ -248,15 +245,14 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator {
if (packet.getActions().size() == 1 && packet.getLegacySlots().size() > 0) {
InventoryActionData actionData = packet.getActions().get(0);
LegacySetItemSlotData slotData = packet.getLegacySlots().get(0);
@@ -286,8 +282,8 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator {
int blockState = session.getGameMode() == GameMode.CREATIVE ?
session.getConnector().getWorldManager().getBlockAt(session, packet.getBlockPosition()) : session.getBreakingBlock();
@@ -301,11 +297,11 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator MAXIMUM_BLOCK_DESTROYING_DISTANCE) {
restoreCorrectBlock(session, packet.getBlockPosition(), packet);
@@ -331,7 +327,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator {
// Resend the packet so we get the eating sounds
session.sendUpstreamPacket(packet);
return;
- case COMPLETE_TRADE:
+ }
+ case COMPLETE_TRADE -> {
ClientSelectTradePacket selectTradePacket = new ClientSelectTradePacket(packet.getData());
session.sendDownstreamPacket(selectTradePacket);
session.scheduleInEventLoop(() -> {
Entity villager = session.getPlayerEntity();
Inventory openInventory = session.getOpenInventory();
- if (openInventory instanceof MerchantContainer) {
- MerchantContainer merchantInventory = (MerchantContainer) openInventory;
+ if (openInventory instanceof MerchantContainer merchantInventory) {
VillagerTrade[] trades = merchantInventory.getVillagerTrades();
if (trades != null && packet.getData() >= 0 && packet.getData() < trades.length) {
VillagerTrade trade = merchantInventory.getVillagerTrades()[packet.getData()];
@@ -68,6 +68,7 @@ public class BedrockEntityEventTranslator extends PacketTranslator Math.abs((middleX + offset.getX()) - otherBox.getMiddleX()) * 2 < (sizeX + otherBox.getSizeX());
+ case Y -> Math.abs((middleY + offset.getY()) - otherBox.getMiddleY()) * 2 < (sizeY + otherBox.getSizeY());
+ case Z -> Math.abs((middleZ + offset.getZ()) - otherBox.getMiddleZ()) * 2 < (sizeZ + otherBox.getSizeZ());
+ };
}
/**
@@ -141,21 +137,14 @@ public class BoundingBox implements Cloneable {
* @return The distance to move in the direction of {@code side}
*/
public double getIntersectionSize(BoundingBox otherBoundingBox, Direction side) {
- switch (side) {
- case DOWN:
- return getMax().getY() - otherBoundingBox.getMin().getY();
- case UP:
- return otherBoundingBox.getMax().getY() - getMin().getY();
- case NORTH:
- return getMax().getZ() - otherBoundingBox.getMin().getZ();
- case SOUTH:
- return otherBoundingBox.getMax().getZ() - getMin().getZ();
- case WEST:
- return getMax().getX() - otherBoundingBox.getMin().getX();
- case EAST:
- return otherBoundingBox.getMax().getX() - getMin().getX();
- }
- return 0;
+ return switch (side) {
+ case DOWN -> getMax().getY() - otherBoundingBox.getMin().getY();
+ case UP -> otherBoundingBox.getMax().getY() - getMin().getY();
+ case NORTH -> getMax().getZ() - otherBoundingBox.getMin().getZ();
+ case SOUTH -> otherBoundingBox.getMax().getZ() - getMin().getZ();
+ case WEST -> getMax().getX() - otherBoundingBox.getMin().getX();
+ case EAST -> otherBoundingBox.getMax().getX() - getMin().getX();
+ };
}
@SneakyThrows(CloneNotSupportedException.class)
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/collision/CollisionManager.java b/connector/src/main/java/org/geysermc/connector/network/translators/collision/CollisionManager.java
index 8ec42d4a9..943682f5c 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/collision/CollisionManager.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/collision/CollisionManager.java
@@ -31,8 +31,8 @@ import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlags;
-import com.nukkitx.protocol.bedrock.packet.*;
-import com.nukkitx.protocol.bedrock.v448.Bedrock_v448;
+import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
+import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
import lombok.Getter;
import lombok.Setter;
import org.geysermc.connector.entity.player.PlayerEntity;
@@ -420,13 +420,8 @@ public class CollisionManager {
boolean flagsChanged;
boolean isSneakingWithScaffolding = (touchingScaffolding || onScaffolding) && session.isSneaking();
- if (session.getUpstream().getProtocolVersion() < Bedrock_v448.V448_CODEC.getProtocolVersion()) {
- // Now no longer sent with BDS as of 1.17.10
- flagsChanged = flags.setFlag(EntityFlag.FALL_THROUGH_SCAFFOLDING, isSneakingWithScaffolding);
- } else {
- flagsChanged = flags.setFlag(EntityFlag.OVER_DESCENDABLE_BLOCK, onScaffolding);
- flagsChanged |= flags.setFlag(EntityFlag.IN_ASCENDABLE_BLOCK, touchingScaffolding);
- }
+ flagsChanged = flags.setFlag(EntityFlag.OVER_DESCENDABLE_BLOCK, onScaffolding);
+ flagsChanged |= flags.setFlag(EntityFlag.IN_ASCENDABLE_BLOCK, touchingScaffolding);
flagsChanged |= flags.setFlag(EntityFlag.OVER_SCAFFOLDING, isSneakingWithScaffolding);
flagsChanged |= flags.setFlag(EntityFlag.IN_SCAFFOLDING, touchingScaffolding);
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/collision/translators/DoorCollision.java b/connector/src/main/java/org/geysermc/connector/network/translators/collision/translators/DoorCollision.java
index cdfeec8cf..8fb3e6981 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/collision/translators/DoorCollision.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/collision/translators/DoorCollision.java
@@ -75,18 +75,10 @@ public class DoorCollision extends BlockCollision {
int z = blockPos.getZ();
switch (facing) {
- case 1: // North
- playerCollision.setMiddleZ(z + 0.5125);
- break;
- case 2: // East
- playerCollision.setMiddleX(x + 0.5125);
- break;
- case 3: // South
- playerCollision.setMiddleZ(z + 0.4875);
- break;
- case 4: // West
- playerCollision.setMiddleX(x + 0.4875);
- break;
+ case 1 -> playerCollision.setMiddleZ(z + 0.5125); // North
+ case 2 -> playerCollision.setMiddleX(x + 0.5125); // East
+ case 3 -> playerCollision.setMiddleZ(z + 0.4875); // South
+ case 4 -> playerCollision.setMiddleX(x + 0.4875); // West
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/InventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/InventoryTranslator.java
index 5c7a08834..b6a00982a 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/InventoryTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/InventoryTranslator.java
@@ -159,21 +159,14 @@ public abstract class InventoryTranslator {
// Some special request that shouldn't be processed normally
response = translateSpecialRequest(session, inventory, request);
} else {
- switch (firstAction.getType()) {
- case CRAFT_RECIPE:
- response = translateCraftingRequest(session, inventory, request);
- break;
- case CRAFT_RECIPE_AUTO:
- response = translateAutoCraftingRequest(session, inventory, request);
- break;
- case CRAFT_CREATIVE:
- // This is also used for pulling items out of creative
- response = translateCreativeRequest(session, inventory, request);
- break;
- default:
- response = translateRequest(session, inventory, request);
- break;
- }
+ response = switch (firstAction.getType()) {
+ case CRAFT_RECIPE -> translateCraftingRequest(session, inventory, request);
+ case CRAFT_RECIPE_AUTO -> translateAutoCraftingRequest(session, inventory, request);
+ case CRAFT_CREATIVE ->
+ // This is also used for pulling items out of creative
+ translateCreativeRequest(session, inventory, request);
+ default -> translateRequest(session, inventory, request);
+ };
}
} else {
response = rejectRequest(request);
@@ -572,7 +565,7 @@ public abstract class InventoryTranslator {
}
switch (recipe.getType()) {
- case CRAFTING_SHAPED:
+ case CRAFTING_SHAPED -> {
ShapedRecipeData shapedData = (ShapedRecipeData) recipe.getData();
ingredients = shapedData.getIngredients();
recipeWidth = shapedData.getWidth();
@@ -580,8 +573,8 @@ public abstract class InventoryTranslator {
if (shapedData.getWidth() > gridDimensions || shapedData.getHeight() > gridDimensions) {
return rejectRequest(request);
}
- break;
- case CRAFTING_SHAPELESS:
+ }
+ case CRAFTING_SHAPELESS -> {
ShapelessRecipeData shapelessData = (ShapelessRecipeData) recipe.getData();
ingredients = shapelessData.getIngredients();
recipeWidth = gridDimensions;
@@ -589,7 +582,7 @@ public abstract class InventoryTranslator {
if (ingredients.length > gridSize) {
return rejectRequest(request);
}
- break;
+ }
}
break;
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/click/ClickPlan.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/click/ClickPlan.java
index 997193091..1aec8bff2 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/click/ClickPlan.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/click/ClickPlan.java
@@ -179,31 +179,30 @@ public class ClickPlan {
private void simulateAction(ClickAction action) {
GeyserItemStack cursor = simulating ? getCursor() : session.getPlayerInventory().getCursor();
switch (action.click) {
- case LEFT_OUTSIDE:
+ case LEFT_OUTSIDE -> {
setCursor(GeyserItemStack.EMPTY);
return;
- case RIGHT_OUTSIDE:
+ }
+ case RIGHT_OUTSIDE -> {
if (!cursor.isEmpty()) {
cursor.sub(1);
}
return;
+ }
}
GeyserItemStack clicked = simulating ? getItem(action.slot) : inventory.getItem(action.slot);
if (translator.getSlotType(action.slot) == SlotType.OUTPUT) {
switch (action.click) {
- case LEFT:
- case RIGHT:
+ case LEFT, RIGHT -> {
if (cursor.isEmpty() && !clicked.isEmpty()) {
setCursor(clicked.copy());
} else if (InventoryUtils.canStack(cursor, clicked)) {
cursor.add(clicked.getAmount());
}
reduceCraftingGrid(false);
- break;
- case LEFT_SHIFT:
- reduceCraftingGrid(true);
- break;
+ }
+ case LEFT_SHIFT -> reduceCraftingGrid(true);
}
} else {
switch (action.click) {
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/AnvilInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/AnvilInventoryTranslator.java
index 1f36eaabe..9aef64b36 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/AnvilInventoryTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/AnvilInventoryTranslator.java
@@ -43,42 +43,32 @@ public class AnvilInventoryTranslator extends AbstractBlockInventoryTranslator {
@Override
public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) {
- switch (slotInfoData.getContainer()) {
- case ANVIL_INPUT:
- return 0;
- case ANVIL_MATERIAL:
- return 1;
- case ANVIL_RESULT:
- case CREATIVE_OUTPUT:
- return 2;
- }
- return super.bedrockSlotToJava(slotInfoData);
+ return switch (slotInfoData.getContainer()) {
+ case ANVIL_INPUT -> 0;
+ case ANVIL_MATERIAL -> 1;
+ case ANVIL_RESULT, CREATIVE_OUTPUT -> 2;
+ default -> super.bedrockSlotToJava(slotInfoData);
+ };
}
@Override
public BedrockContainerSlot javaSlotToBedrockContainer(int slot) {
- switch (slot) {
- case 0:
- return new BedrockContainerSlot(ContainerSlotType.ANVIL_INPUT, 1);
- case 1:
- return new BedrockContainerSlot(ContainerSlotType.ANVIL_MATERIAL, 2);
- case 2:
- return new BedrockContainerSlot(ContainerSlotType.ANVIL_RESULT, 50);
- }
- return super.javaSlotToBedrockContainer(slot);
+ return switch (slot) {
+ case 0 -> new BedrockContainerSlot(ContainerSlotType.ANVIL_INPUT, 1);
+ case 1 -> new BedrockContainerSlot(ContainerSlotType.ANVIL_MATERIAL, 2);
+ case 2 -> new BedrockContainerSlot(ContainerSlotType.ANVIL_RESULT, 50);
+ default -> super.javaSlotToBedrockContainer(slot);
+ };
}
@Override
public int javaSlotToBedrock(int slot) {
- switch (slot) {
- case 0:
- return 1;
- case 1:
- return 2;
- case 2:
- return 50;
- }
- return super.javaSlotToBedrock(slot);
+ return switch (slot) {
+ case 0 -> 1;
+ case 1 -> 2;
+ case 2 -> 50;
+ default -> super.javaSlotToBedrock(slot);
+ };
}
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/BrewingInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/BrewingInventoryTranslator.java
index c54722849..17baff323 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/BrewingInventoryTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/BrewingInventoryTranslator.java
@@ -82,33 +82,23 @@ public class BrewingInventoryTranslator extends AbstractBlockInventoryTranslator
@Override
public int javaSlotToBedrock(int slot) {
- switch (slot) {
- case 0:
- return 1;
- case 1:
- return 2;
- case 2:
- return 3;
- case 3:
- return 0;
- case 4:
- return 4;
- }
- return super.javaSlotToBedrock(slot);
+ return switch (slot) {
+ case 0 -> 1;
+ case 1 -> 2;
+ case 2 -> 3;
+ case 3 -> 0;
+ case 4 -> 4;
+ default -> super.javaSlotToBedrock(slot);
+ };
}
@Override
public BedrockContainerSlot javaSlotToBedrockContainer(int slot) {
- switch (slot) {
- case 0:
- case 1:
- case 2:
- return new BedrockContainerSlot(ContainerSlotType.BREWING_RESULT, javaSlotToBedrock(slot));
- case 3:
- return new BedrockContainerSlot(ContainerSlotType.BREWING_INPUT, 0);
- case 4:
- return new BedrockContainerSlot(ContainerSlotType.BREWING_FUEL, 4);
- }
- return super.javaSlotToBedrockContainer(slot);
+ return switch (slot) {
+ case 0, 1, 2 -> new BedrockContainerSlot(ContainerSlotType.BREWING_RESULT, javaSlotToBedrock(slot));
+ case 3 -> new BedrockContainerSlot(ContainerSlotType.BREWING_INPUT, 0);
+ case 4 -> new BedrockContainerSlot(ContainerSlotType.BREWING_FUEL, 4);
+ default -> super.javaSlotToBedrockContainer(slot);
+ };
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/CartographyInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/CartographyInventoryTranslator.java
index 76bf21bd3..ef00f9343 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/CartographyInventoryTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/CartographyInventoryTranslator.java
@@ -59,42 +59,32 @@ public class CartographyInventoryTranslator extends AbstractBlockInventoryTransl
@Override
public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) {
- switch (slotInfoData.getContainer()) {
- case CARTOGRAPHY_INPUT:
- return 0;
- case CARTOGRAPHY_ADDITIONAL:
- return 1;
- case CARTOGRAPHY_RESULT:
- case CREATIVE_OUTPUT:
- return 2;
- }
- return super.bedrockSlotToJava(slotInfoData);
+ return switch (slotInfoData.getContainer()) {
+ case CARTOGRAPHY_INPUT -> 0;
+ case CARTOGRAPHY_ADDITIONAL -> 1;
+ case CARTOGRAPHY_RESULT, CREATIVE_OUTPUT -> 2;
+ default -> super.bedrockSlotToJava(slotInfoData);
+ };
}
@Override
public BedrockContainerSlot javaSlotToBedrockContainer(int slot) {
- switch (slot) {
- case 0:
- return new BedrockContainerSlot(ContainerSlotType.CARTOGRAPHY_INPUT, 12);
- case 1:
- return new BedrockContainerSlot(ContainerSlotType.CARTOGRAPHY_ADDITIONAL, 13);
- case 2:
- return new BedrockContainerSlot(ContainerSlotType.CARTOGRAPHY_RESULT, 50);
- }
- return super.javaSlotToBedrockContainer(slot);
+ return switch (slot) {
+ case 0 -> new BedrockContainerSlot(ContainerSlotType.CARTOGRAPHY_INPUT, 12);
+ case 1 -> new BedrockContainerSlot(ContainerSlotType.CARTOGRAPHY_ADDITIONAL, 13);
+ case 2 -> new BedrockContainerSlot(ContainerSlotType.CARTOGRAPHY_RESULT, 50);
+ default -> super.javaSlotToBedrockContainer(slot);
+ };
}
@Override
public int javaSlotToBedrock(int slot) {
- switch (slot) {
- case 0:
- return 12;
- case 1:
- return 13;
- case 2:
- return 50;
- }
- return super.javaSlotToBedrock(slot);
+ return switch (slot) {
+ case 0 -> 12;
+ case 1 -> 13;
+ case 2 -> 50;
+ default -> super.javaSlotToBedrock(slot);
+ };
}
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/GrindstoneInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/GrindstoneInventoryTranslator.java
index 65364e147..a71594153 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/GrindstoneInventoryTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/GrindstoneInventoryTranslator.java
@@ -38,41 +38,31 @@ public class GrindstoneInventoryTranslator extends AbstractBlockInventoryTransla
@Override
public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) {
- switch (slotInfoData.getContainer()) {
- case GRINDSTONE_INPUT:
- return 0;
- case GRINDSTONE_ADDITIONAL:
- return 1;
- case GRINDSTONE_RESULT:
- case CREATIVE_OUTPUT:
- return 2;
- }
- return super.bedrockSlotToJava(slotInfoData);
+ return switch (slotInfoData.getContainer()) {
+ case GRINDSTONE_INPUT -> 0;
+ case GRINDSTONE_ADDITIONAL -> 1;
+ case GRINDSTONE_RESULT, CREATIVE_OUTPUT -> 2;
+ default -> super.bedrockSlotToJava(slotInfoData);
+ };
}
@Override
public BedrockContainerSlot javaSlotToBedrockContainer(int slot) {
- switch (slot) {
- case 0:
- return new BedrockContainerSlot(ContainerSlotType.GRINDSTONE_INPUT, 16);
- case 1:
- return new BedrockContainerSlot(ContainerSlotType.GRINDSTONE_ADDITIONAL, 17);
- case 2:
- return new BedrockContainerSlot(ContainerSlotType.GRINDSTONE_RESULT, 50);
- }
- return super.javaSlotToBedrockContainer(slot);
+ return switch (slot) {
+ case 0 -> new BedrockContainerSlot(ContainerSlotType.GRINDSTONE_INPUT, 16);
+ case 1 -> new BedrockContainerSlot(ContainerSlotType.GRINDSTONE_ADDITIONAL, 17);
+ case 2 -> new BedrockContainerSlot(ContainerSlotType.GRINDSTONE_RESULT, 50);
+ default -> super.javaSlotToBedrockContainer(slot);
+ };
}
@Override
public int javaSlotToBedrock(int slot) {
- switch (slot) {
- case 0:
- return 16;
- case 1:
- return 17;
- case 2:
- return 50;
- }
- return super.javaSlotToBedrock(slot);
+ return switch (slot) {
+ case 0 -> 16;
+ case 1 -> 17;
+ case 2 -> 50;
+ default -> super.javaSlotToBedrock(slot);
+ };
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/LoomInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/LoomInventoryTranslator.java
index ec8f33f2e..c6909ec9f 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/LoomInventoryTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/LoomInventoryTranslator.java
@@ -125,10 +125,9 @@ public class LoomInventoryTranslator extends AbstractBlockInventoryTranslator {
public ItemStackResponsePacket.Response translateSpecialRequest(GeyserSession session, Inventory inventory, ItemStackRequest request) {
// TODO: I anticipate this will be changed in the future to use something non-deprecated. Keep an eye out.
StackRequestActionData data = request.getActions()[1];
- if (!(data instanceof CraftResultsDeprecatedStackRequestActionData)) {
+ if (!(data instanceof CraftResultsDeprecatedStackRequestActionData craftData)) {
return rejectRequest(request);
}
- CraftResultsDeprecatedStackRequestActionData craftData = (CraftResultsDeprecatedStackRequestActionData) data;
// Get the patterns compound tag
List newBlockEntityTag = craftData.getResultItems()[0].getTag().getList("Patterns", NbtType.COMPOUND);
@@ -177,48 +176,35 @@ public class LoomInventoryTranslator extends AbstractBlockInventoryTranslator {
@Override
public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) {
- switch (slotInfoData.getContainer()) {
- case LOOM_INPUT:
- return 0;
- case LOOM_DYE:
- return 1;
- case LOOM_MATERIAL:
- return 2;
- case LOOM_RESULT:
- case CREATIVE_OUTPUT:
- return 3;
- }
- return super.bedrockSlotToJava(slotInfoData);
+ return switch (slotInfoData.getContainer()) {
+ case LOOM_INPUT -> 0;
+ case LOOM_DYE -> 1;
+ case LOOM_MATERIAL -> 2;
+ case LOOM_RESULT, CREATIVE_OUTPUT -> 3;
+ default -> super.bedrockSlotToJava(slotInfoData);
+ };
}
@Override
public BedrockContainerSlot javaSlotToBedrockContainer(int slot) {
- switch (slot) {
- case 0:
- return new BedrockContainerSlot(ContainerSlotType.LOOM_INPUT, 9);
- case 1:
- return new BedrockContainerSlot(ContainerSlotType.LOOM_DYE, 10);
- case 2:
- return new BedrockContainerSlot(ContainerSlotType.LOOM_MATERIAL, 11);
- case 3:
- return new BedrockContainerSlot(ContainerSlotType.LOOM_RESULT, 50);
- }
- return super.javaSlotToBedrockContainer(slot);
+ return switch (slot) {
+ case 0 -> new BedrockContainerSlot(ContainerSlotType.LOOM_INPUT, 9);
+ case 1 -> new BedrockContainerSlot(ContainerSlotType.LOOM_DYE, 10);
+ case 2 -> new BedrockContainerSlot(ContainerSlotType.LOOM_MATERIAL, 11);
+ case 3 -> new BedrockContainerSlot(ContainerSlotType.LOOM_RESULT, 50);
+ default -> super.javaSlotToBedrockContainer(slot);
+ };
}
@Override
public int javaSlotToBedrock(int slot) {
- switch (slot) {
- case 0:
- return 9;
- case 1:
- return 10;
- case 2:
- return 11;
- case 3:
- return 50;
- }
- return super.javaSlotToBedrock(slot);
+ return switch (slot) {
+ case 0 -> 9;
+ case 1 -> 10;
+ case 2 -> 11;
+ case 3 -> 50;
+ default -> super.javaSlotToBedrock(slot);
+ };
}
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/MerchantInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/MerchantInventoryTranslator.java
index 736568868..63531ba8a 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/MerchantInventoryTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/MerchantInventoryTranslator.java
@@ -56,42 +56,32 @@ public class MerchantInventoryTranslator extends BaseInventoryTranslator {
@Override
public int javaSlotToBedrock(int slot) {
- switch (slot) {
- case 0:
- return 4;
- case 1:
- return 5;
- case 2:
- return 50;
- }
- return super.javaSlotToBedrock(slot);
+ return switch (slot) {
+ case 0 -> 4;
+ case 1 -> 5;
+ case 2 -> 50;
+ default -> super.javaSlotToBedrock(slot);
+ };
}
@Override
public BedrockContainerSlot javaSlotToBedrockContainer(int slot) {
- switch (slot) {
- case 0:
- return new BedrockContainerSlot(ContainerSlotType.TRADE2_INGREDIENT1, 4);
- case 1:
- return new BedrockContainerSlot(ContainerSlotType.TRADE2_INGREDIENT2, 5);
- case 2:
- return new BedrockContainerSlot(ContainerSlotType.TRADE2_RESULT, 50);
- }
- return super.javaSlotToBedrockContainer(slot);
+ return switch (slot) {
+ case 0 -> new BedrockContainerSlot(ContainerSlotType.TRADE2_INGREDIENT1, 4);
+ case 1 -> new BedrockContainerSlot(ContainerSlotType.TRADE2_INGREDIENT2, 5);
+ case 2 -> new BedrockContainerSlot(ContainerSlotType.TRADE2_RESULT, 50);
+ default -> super.javaSlotToBedrockContainer(slot);
+ };
}
@Override
public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) {
- switch (slotInfoData.getContainer()) {
- case TRADE2_INGREDIENT1:
- return 0;
- case TRADE2_INGREDIENT2:
- return 1;
- case TRADE2_RESULT:
- case CREATIVE_OUTPUT:
- return 2;
- }
- return super.bedrockSlotToJava(slotInfoData);
+ return switch (slotInfoData.getContainer()) {
+ case TRADE2_INGREDIENT1 -> 0;
+ case TRADE2_INGREDIENT2 -> 1;
+ case TRADE2_RESULT, CREATIVE_OUTPUT -> 2;
+ default -> super.bedrockSlotToJava(slotInfoData);
+ };
}
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/PlayerInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/PlayerInventoryTranslator.java
index adde2b26f..f52a3053d 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/PlayerInventoryTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/PlayerInventoryTranslator.java
@@ -218,8 +218,7 @@ public class PlayerInventoryTranslator extends InventoryTranslator {
IntSet affectedSlots = new IntOpenHashSet();
for (StackRequestActionData action : request.getActions()) {
switch (action.getType()) {
- case TAKE:
- case PLACE: {
+ case TAKE, PLACE -> {
TransferStackRequestActionData transferAction = (TransferStackRequestActionData) action;
if (!(checkNetId(session, inventory, transferAction.getSource()) && checkNetId(session, inventory, transferAction.getDestination()))) {
return rejectRequest(request);
@@ -265,9 +264,8 @@ public class PlayerInventoryTranslator extends InventoryTranslator {
affectedSlots.add(sourceSlot);
affectedSlots.add(destSlot);
}
- break;
}
- case SWAP: {
+ case SWAP -> {
SwapStackRequestActionData swapAction = (SwapStackRequestActionData) action;
if (!(checkNetId(session, inventory, swapAction.getSource()) && checkNetId(session, inventory, swapAction.getDestination()))) {
return rejectRequest(request);
@@ -306,9 +304,8 @@ public class PlayerInventoryTranslator extends InventoryTranslator {
affectedSlots.add(sourceSlot);
affectedSlots.add(destSlot);
}
- break;
}
- case DROP: {
+ case DROP -> {
DropStackRequestActionData dropAction = (DropStackRequestActionData) action;
if (!checkNetId(session, inventory, dropAction.getSource())) {
return rejectRequest(request);
@@ -334,9 +331,8 @@ public class PlayerInventoryTranslator extends InventoryTranslator {
session.sendDownstreamPacket(creativeDropPacket);
sourceItem.sub(dropAction.getCount());
- break;
}
- case DESTROY: {
+ case DESTROY -> {
// Only called when a creative client wants to destroy an item... I think - Camotoy
DestroyStackRequestActionData destroyAction = (DestroyStackRequestActionData) action;
if (!checkNetId(session, inventory, destroyAction.getSource())) {
@@ -356,11 +352,11 @@ public class PlayerInventoryTranslator extends InventoryTranslator {
// Just sync up the item on our end, since the server doesn't care what's in our cursor
playerInv.getCursor().sub(destroyAction.getCount());
}
- break;
}
- default:
+ default -> {
session.getConnector().getLogger().error("Unknown crafting state induced by " + session.getName());
return rejectRequest(request);
+ }
}
}
for (int slot : affectedSlots) {
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/SmithingInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/SmithingInventoryTranslator.java
index dbe04f68b..8b30be406 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/SmithingInventoryTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/SmithingInventoryTranslator.java
@@ -38,41 +38,31 @@ public class SmithingInventoryTranslator extends AbstractBlockInventoryTranslato
@Override
public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) {
- switch (slotInfoData.getContainer()) {
- case SMITHING_TABLE_INPUT:
- return 0;
- case SMITHING_TABLE_MATERIAL:
- return 1;
- case SMITHING_TABLE_RESULT:
- case CREATIVE_OUTPUT:
- return 2;
- }
- return super.bedrockSlotToJava(slotInfoData);
+ return switch (slotInfoData.getContainer()) {
+ case SMITHING_TABLE_INPUT -> 0;
+ case SMITHING_TABLE_MATERIAL -> 1;
+ case SMITHING_TABLE_RESULT, CREATIVE_OUTPUT -> 2;
+ default -> super.bedrockSlotToJava(slotInfoData);
+ };
}
@Override
public BedrockContainerSlot javaSlotToBedrockContainer(int slot) {
- switch (slot) {
- case 0:
- return new BedrockContainerSlot(ContainerSlotType.SMITHING_TABLE_INPUT, 51);
- case 1:
- return new BedrockContainerSlot(ContainerSlotType.SMITHING_TABLE_MATERIAL, 52);
- case 2:
- return new BedrockContainerSlot(ContainerSlotType.SMITHING_TABLE_RESULT, 50);
- }
- return super.javaSlotToBedrockContainer(slot);
+ return switch (slot) {
+ case 0 -> new BedrockContainerSlot(ContainerSlotType.SMITHING_TABLE_INPUT, 51);
+ case 1 -> new BedrockContainerSlot(ContainerSlotType.SMITHING_TABLE_MATERIAL, 52);
+ case 2 -> new BedrockContainerSlot(ContainerSlotType.SMITHING_TABLE_RESULT, 50);
+ default -> super.javaSlotToBedrockContainer(slot);
+ };
}
@Override
public int javaSlotToBedrock(int slot) {
- switch (slot) {
- case 0:
- return 51;
- case 1:
- return 52;
- case 2:
- return 50;
- }
- return super.javaSlotToBedrock(slot);
+ return switch (slot) {
+ case 0 -> 51;
+ case 1 -> 52;
+ case 2 -> 50;
+ default -> super.javaSlotToBedrock(slot);
+ };
}
}
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/StonecutterInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/StonecutterInventoryTranslator.java
index e4dea7265..d6bbe7d5d 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/StonecutterInventoryTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/StonecutterInventoryTranslator.java
@@ -61,10 +61,9 @@ public class StonecutterInventoryTranslator extends AbstractBlockInventoryTransl
public ItemStackResponsePacket.Response translateSpecialRequest(GeyserSession session, Inventory inventory, ItemStackRequest request) {
// TODO: Also surely to change in the future
StackRequestActionData data = request.getActions()[1];
- if (!(data instanceof CraftResultsDeprecatedStackRequestActionData)) {
+ if (!(data instanceof CraftResultsDeprecatedStackRequestActionData craftData)) {
return rejectRequest(request);
}
- CraftResultsDeprecatedStackRequestActionData craftData = (CraftResultsDeprecatedStackRequestActionData) data;
StonecutterContainer container = (StonecutterContainer) inventory;
// Get the ID of the item we are cutting
@@ -94,14 +93,11 @@ public class StonecutterInventoryTranslator extends AbstractBlockInventoryTransl
@Override
public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) {
- switch (slotInfoData.getContainer()) {
- case STONECUTTER_INPUT:
- return 0;
- case STONECUTTER_RESULT:
- case CREATIVE_OUTPUT:
- return 1;
- }
- return super.bedrockSlotToJava(slotInfoData);
+ return switch (slotInfoData.getContainer()) {
+ case STONECUTTER_INPUT -> 0;
+ case STONECUTTER_RESULT, CREATIVE_OUTPUT -> 1;
+ default -> super.bedrockSlotToJava(slotInfoData);
+ };
}
@Override
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java
index ec55bc48c..9fcf984cd 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java
@@ -299,8 +299,7 @@ public abstract class ItemTranslator {
return ((StringTag) tag).getValue();
}
- if (tag instanceof ListTag) {
- ListTag listTag = (ListTag) tag;
+ if (tag instanceof ListTag listTag) {
List