From 3c296a598fab8f19d7d92b811e97664e16ba0a9d Mon Sep 17 00:00:00 2001 From: Tim203 Date: Wed, 2 Oct 2024 00:05:06 +0200 Subject: [PATCH] Removed var usage for primitives and String, removed star imports --- .../geysermc/geyser/entity/type/Entity.java | 19 +++++++++++---- .../entity/type/player/PlayerEntity.java | 16 ++++++------- .../geysermc/geyser/scoreboard/Objective.java | 4 ++-- .../geyser/scoreboard/ScoreReference.java | 2 +- .../geyser/scoreboard/Scoreboard.java | 23 ++++++++++++------- .../org/geysermc/geyser/scoreboard/Team.java | 14 +++++------ .../display/score/SidebarDisplayScore.java | 4 ++-- .../geyser/session/cache/EntityCache.java | 11 +++++---- 8 files changed, 55 insertions(+), 38 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index dc76e9925..983455da8 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -25,6 +25,12 @@ package org.geysermc.geyser.entity.type; +import java.util.Collections; +import java.util.EnumSet; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.UUID; import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; @@ -35,7 +41,12 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityEventType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.cloudburstmc.protocol.bedrock.packet.*; +import org.cloudburstmc.protocol.bedrock.packet.AddEntityPacket; +import org.cloudburstmc.protocol.bedrock.packet.EntityEventPacket; +import org.cloudburstmc.protocol.bedrock.packet.MoveEntityAbsolutePacket; +import org.cloudburstmc.protocol.bedrock.packet.MoveEntityDeltaPacket; +import org.cloudburstmc.protocol.bedrock.packet.RemoveEntityPacket; +import org.cloudburstmc.protocol.bedrock.packet.SetEntityDataPacket; import org.geysermc.geyser.api.entity.type.GeyserEntity; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.GeyserDirtyMetadata; @@ -56,8 +67,6 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEnt import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType; -import java.util.*; - @Getter @Setter public class Entity implements GeyserEntity { @@ -427,7 +436,7 @@ public class Entity implements GeyserEntity { // Displayname is ignored for players, and is always their username. Optional name = entityMetadata.getValue(); if (name.isPresent()) { - var displayName = MessageTranslator.convertMessage(name.get(), session.locale()); + String displayName = MessageTranslator.convertMessage(name.get(), session.locale()); this.displayName = displayName; setNametag(displayName, true); return; @@ -456,7 +465,7 @@ public class Entity implements GeyserEntity { if (nametag == null) { nametag = ""; } - var changed = !Objects.equals(this.nametag, nametag); + boolean changed = !Objects.equals(this.nametag, nametag); this.nametag = nametag; // we only update metadata if the value has changed if (!changed) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java index e3214879a..85905d716 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java @@ -25,7 +25,12 @@ package org.geysermc.geyser.entity.type.player; +import java.util.Collections; +import java.util.List; import java.util.Objects; +import java.util.Optional; +import java.util.UUID; +import java.util.concurrent.TimeUnit; import lombok.Getter; import lombok.Setter; import net.kyori.adventure.text.Component; @@ -45,7 +50,6 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityLinkData; import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData; import org.cloudburstmc.protocol.bedrock.packet.AddPlayerPacket; import org.cloudburstmc.protocol.bedrock.packet.MovePlayerPacket; -import org.cloudburstmc.protocol.bedrock.packet.SetEntityDataPacket; import org.cloudburstmc.protocol.bedrock.packet.SetEntityLinkPacket; import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket; import org.geysermc.geyser.api.entity.type.player.GeyserPlayerEntity; @@ -62,12 +66,6 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.Pose; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.FloatEntityMetadata; - -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.UUID; -import java.util.concurrent.TimeUnit; import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType; @Getter @Setter @@ -430,7 +428,7 @@ public class PlayerEntity extends LivingEntity implements GeyserPlayerEntity { text = ""; } - var changed = !Objects.equals(cachedScore, text); + boolean changed = !Objects.equals(cachedScore, text); cachedScore = text; if (isScoreVisible() && changed) { dirtyMetadata.put(EntityDataTypes.SCORE, text); @@ -439,7 +437,7 @@ public class PlayerEntity extends LivingEntity implements GeyserPlayerEntity { @Override protected void scoreVisibility(boolean show) { - var visibilityChanged = scoreVisible != show; + boolean visibilityChanged = scoreVisible != show; scoreVisible = show; if (!visibilityChanged) { return; diff --git a/core/src/main/java/org/geysermc/geyser/scoreboard/Objective.java b/core/src/main/java/org/geysermc/geyser/scoreboard/Objective.java index c15c1944d..f3b7f20d2 100644 --- a/core/src/main/java/org/geysermc/geyser/scoreboard/Objective.java +++ b/core/src/main/java/org/geysermc/geyser/scoreboard/Objective.java @@ -83,8 +83,8 @@ public final class Objective { } public void updateProperties(Component displayNameComponent, ScoreType type, NumberFormat format) { - var displayName = MessageTranslator.convertMessageRaw(displayNameComponent, scoreboard.session().locale()); - var changed = !Objects.equals(this.displayName, displayName) || this.type != type; + String displayName = MessageTranslator.convertMessageRaw(displayNameComponent, scoreboard.session().locale()); + boolean changed = !Objects.equals(this.displayName, displayName) || this.type != type; this.displayName = displayName; this.type = type; diff --git a/core/src/main/java/org/geysermc/geyser/scoreboard/ScoreReference.java b/core/src/main/java/org/geysermc/geyser/scoreboard/ScoreReference.java index e56420da4..c26a59899 100644 --- a/core/src/main/java/org/geysermc/geyser/scoreboard/ScoreReference.java +++ b/core/src/main/java/org/geysermc/geyser/scoreboard/ScoreReference.java @@ -86,7 +86,7 @@ public final class ScoreReference { } private void score(int score) { - var changed = this.score != score; + boolean changed = this.score != score; this.score = score; if (changed) { markChanged(); diff --git a/core/src/main/java/org/geysermc/geyser/scoreboard/Scoreboard.java b/core/src/main/java/org/geysermc/geyser/scoreboard/Scoreboard.java index 02e2f3a82..6e0867ddc 100644 --- a/core/src/main/java/org/geysermc/geyser/scoreboard/Scoreboard.java +++ b/core/src/main/java/org/geysermc/geyser/scoreboard/Scoreboard.java @@ -25,8 +25,23 @@ package org.geysermc.geyser.scoreboard; +import static org.geysermc.geyser.scoreboard.UpdateType.REMOVE; + import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import java.util.ArrayList; +import java.util.Collections; +import java.util.EnumMap; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicLong; +import java.util.function.Function; +import java.util.stream.Collectors; import lombok.Getter; import net.kyori.adventure.text.Component; import org.checkerframework.checker.nullness.qual.Nullable; @@ -48,14 +63,6 @@ import org.geysermc.mcprotocollib.protocol.data.game.scoreboard.ScoreboardPositi import org.geysermc.mcprotocollib.protocol.data.game.scoreboard.TeamColor; import org.jetbrains.annotations.Contract; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicLong; -import java.util.function.Function; -import java.util.stream.Collectors; - -import static org.geysermc.geyser.scoreboard.UpdateType.*; - /** * Here follows some information about how scoreboards work in Java Edition, that is related to the workings of this * class: diff --git a/core/src/main/java/org/geysermc/geyser/scoreboard/Team.java b/core/src/main/java/org/geysermc/geyser/scoreboard/Team.java index 28efb02cb..d7c06ac4f 100644 --- a/core/src/main/java/org/geysermc/geyser/scoreboard/Team.java +++ b/core/src/main/java/org/geysermc/geyser/scoreboard/Team.java @@ -120,7 +120,7 @@ public final class Team { } public String displayName(String score) { - var chatColor = ChatColor.chatColorFor(color); + String chatColor = ChatColor.chatColorFor(color); // most sidebar plugins will use the reset color, because they don't want color // skip the unneeded double reset color in that case if (ChatColor.RESET.equals(chatColor)) { @@ -149,10 +149,10 @@ public final class Team { return; } - var oldName = this.name; - var oldPrefix = this.prefix; - var oldSuffix = this.suffix; - var oldVisible = isVisibleFor(playerName()); + String oldName = this.name; + String oldPrefix = this.prefix; + String oldSuffix = this.suffix; + boolean oldVisible = isVisibleFor(playerName()); var oldColor = this.color; this.name = MessageTranslator.convertMessageRaw(name, session().locale()); @@ -245,7 +245,7 @@ public final class Team { if (names.isEmpty()) { return; } - var containsSelf = names.contains(playerName()); + boolean containsSelf = names.contains(playerName()); for (Entity entity : session().getEntityCache().getEntities().values()) { if (names.contains(entity.teamIdentifier())) { @@ -263,7 +263,7 @@ public final class Team { } private void removeRemovedEntities(Set names) { - var containsSelf = names.contains(playerName()); + boolean containsSelf = names.contains(playerName()); var iterator = managedEntities.iterator(); while (iterator.hasNext()) { diff --git a/core/src/main/java/org/geysermc/geyser/scoreboard/display/score/SidebarDisplayScore.java b/core/src/main/java/org/geysermc/geyser/scoreboard/display/score/SidebarDisplayScore.java index 57bebd22f..42c0dbbf7 100644 --- a/core/src/main/java/org/geysermc/geyser/scoreboard/display/score/SidebarDisplayScore.java +++ b/core/src/main/java/org/geysermc/geyser/scoreboard/display/score/SidebarDisplayScore.java @@ -60,8 +60,8 @@ public final class SidebarDisplayScore extends DisplayScore { public void update(Objective objective) { markUpdated(); - var finalName = reference.name(); - var displayName = reference.displayName(); + String finalName = reference.name(); + String displayName = reference.displayName(); if (displayName != null) { finalName = displayName; diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/EntityCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/EntityCache.java index 24f2eb50c..a80ed3e3a 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/EntityCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/EntityCache.java @@ -31,15 +31,18 @@ import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicLong; import lombok.Getter; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.Tickable; import org.geysermc.geyser.entity.type.player.PlayerEntity; import org.geysermc.geyser.session.GeyserSession; -import java.util.*; -import java.util.concurrent.atomic.AtomicLong; - /** * Each session has its own EntityCache in the occasion that an entity packet is sent specifically * for that player (e.g. seeing vanished players from /vanish) @@ -133,7 +136,7 @@ public class EntityCache { public void addPlayerEntity(PlayerEntity entity) { // putIfAbsent matches the behavior of playerInfoMap in Java as of 1.19.3 - var exists = playerEntities.putIfAbsent(entity.getUuid(), entity) != null; + boolean exists = playerEntities.putIfAbsent(entity.getUuid(), entity) != null; if (exists) { return; }