From 9af4cc244667fdbfbdc5056082dd0783bae4acdb Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Tue, 26 Apr 2022 00:04:03 -0400 Subject: [PATCH] Refactor classes --- .../grasscutter/command/commands/HealCommand.java | 11 +++++------ .../grasscutter/command/commands/ListCommand.java | 12 ++++-------- .../grasscutter/command/commands/TalentCommand.java | 2 +- .../{TelePortCommand.java => TeleportCommand.java} | 2 +- .../grasscutter/server/dispatch/DispatchServer.java | 4 ++-- 5 files changed, 13 insertions(+), 18 deletions(-) rename src/main/java/emu/grasscutter/command/commands/{TelePortCommand.java => TeleportCommand.java} (97%) diff --git a/src/main/java/emu/grasscutter/command/commands/HealCommand.java b/src/main/java/emu/grasscutter/command/commands/HealCommand.java index 511e52812..27511e527 100644 --- a/src/main/java/emu/grasscutter/command/commands/HealCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/HealCommand.java @@ -6,20 +6,19 @@ import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.props.FightProperty; import emu.grasscutter.server.packet.send.PacketAvatarFightPropUpdateNotify; import emu.grasscutter.server.packet.send.PacketAvatarLifeStateChangeNotify; -import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify; -import emu.grasscutter.server.packet.send.PacketLifeStateChangeNotify; import java.util.List; -@Command(label = "heal", usage = "heal|h", - description = "Heal all characters in your current team.", aliases = {"h"}, permission = "player.heal") -public class HealCommand implements CommandHandler { +@Command(label = "heal", usage = "heal|h", aliases = {"h"}, + description = "Heal all characters in your current team.", permission = "player.heal") +public final class HealCommand implements CommandHandler { @Override public void execute(GenshinPlayer sender, List args) { if (sender == null) { CommandHandler.sendMessage(null, "Run this command in-game."); return; } + sender.getTeamManager().getActiveTeam().forEach(entity -> { boolean isAlive = entity.isAlive(); entity.setFightProperty( @@ -31,6 +30,6 @@ public class HealCommand implements CommandHandler { entity.getWorld().broadcastPacket(new PacketAvatarLifeStateChangeNotify(entity.getAvatar())); } }); - CommandHandler.sendMessage(sender, "All characters are healed."); + CommandHandler.sendMessage(sender, "All characters have been healed."); } } diff --git a/src/main/java/emu/grasscutter/command/commands/ListCommand.java b/src/main/java/emu/grasscutter/command/commands/ListCommand.java index 6afca4a6d..1fb7f0eed 100644 --- a/src/main/java/emu/grasscutter/command/commands/ListCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/ListCommand.java @@ -9,7 +9,7 @@ import java.util.List; import java.util.Map; @Command(label = "list", description = "List online players") -public class ListCommand implements CommandHandler { +public final class ListCommand implements CommandHandler { @Override public void execute(GenshinPlayer sender, List args) { @@ -19,14 +19,10 @@ public class ListCommand implements CommandHandler { if (playersMap.size() != 0) { StringBuilder playerSet = new StringBuilder(); - - for (Map.Entry entry : playersMap.entrySet()) { - playerSet.append(entry.getValue().getNickname()); - playerSet.append(", "); - } - + playersMap.values().forEach(player -> + playerSet.append(player.getNickname()).append(", ")); + String players = playerSet.toString(); - CommandHandler.sendMessage(sender, players.substring(0, players.length() - 2)); } } diff --git a/src/main/java/emu/grasscutter/command/commands/TalentCommand.java b/src/main/java/emu/grasscutter/command/commands/TalentCommand.java index 21cf66249..59fc83226 100644 --- a/src/main/java/emu/grasscutter/command/commands/TalentCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/TalentCommand.java @@ -13,7 +13,7 @@ import java.util.List; @Command(label = "talent", usage = "talent ", description = "Set talent level for your current active character", permission = "player.settalent") -public class TalentCommand implements CommandHandler { +public final class TalentCommand implements CommandHandler { @Override public void execute(GenshinPlayer sender, List args) { diff --git a/src/main/java/emu/grasscutter/command/commands/TelePortCommand.java b/src/main/java/emu/grasscutter/command/commands/TeleportCommand.java similarity index 97% rename from src/main/java/emu/grasscutter/command/commands/TelePortCommand.java rename to src/main/java/emu/grasscutter/command/commands/TeleportCommand.java index 84848afa5..6b08fb333 100644 --- a/src/main/java/emu/grasscutter/command/commands/TelePortCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/TeleportCommand.java @@ -9,7 +9,7 @@ import java.util.List; @Command(label = "teleport", usage = "teleport ", aliases = {"tp"}, description = "Change the player's position.", permission = "player.teleport") -public class TelePortCommand implements CommandHandler { +public final class TeleportCommand implements CommandHandler { @Override public void execute(GenshinPlayer sender, List args) { diff --git a/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java b/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java index 5cb06d5e1..fe8e79abc 100644 --- a/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java +++ b/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java @@ -98,8 +98,8 @@ public final class DispatchServer { byte[] decoded2 = Base64.getDecoder().decode(query_cur_region); QueryCurrRegionHttpRsp regionQuery = QueryCurrRegionHttpRsp.parseFrom(decoded2); - List servers = new ArrayList(); - List usedNames = new ArrayList(); // List to check for potential naming conflicts + List servers = new ArrayList<>(); + List usedNames = new ArrayList<>(); // List to check for potential naming conflicts if (Grasscutter.getConfig().RunMode.equalsIgnoreCase("HYBRID")) { // Automatically add the game server if in // hybrid mode RegionSimpleInfo server = RegionSimpleInfo.newBuilder()