From 2e119efb86aeb26e8af988eb64665f04830d77da Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Thu, 28 Apr 2022 22:21:30 -0400 Subject: [PATCH] Formatting changes --- .../command/commands/CoopCommand.java | 3 ++- .../command/commands/GiveAllCommand.java | 12 +++------ .../command/commands/SendMailCommand.java | 11 +++----- ...llCommand.java => TeleportAllCommand.java} | 10 ++++--- .../server/dispatch/DispatchServer.java | 27 ++++++++----------- .../event/dispatch/QueryAllRegionsEvent.java | 2 +- .../dispatch/QueryCurrentRegionEvent.java | 2 +- .../server/event/game/ReceivePacketEvent.java | 2 +- .../grasscutter/server/game/GameServer.java | 2 +- .../emu/grasscutter/task/TaskHandler.java | 18 +++---------- .../emu/grasscutter/task/tasks/MoonCard.java | 7 +++-- 11 files changed, 36 insertions(+), 60 deletions(-) rename src/main/java/emu/grasscutter/command/commands/{TpallCommand.java => TeleportAllCommand.java} (75%) diff --git a/src/main/java/emu/grasscutter/command/commands/CoopCommand.java b/src/main/java/emu/grasscutter/command/commands/CoopCommand.java index 0dec6839e..633c2c8c1 100644 --- a/src/main/java/emu/grasscutter/command/commands/CoopCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/CoopCommand.java @@ -8,13 +8,14 @@ import java.util.List; @Command(label = "coop", usage = "coop", description = "Forces someone to join the world of others", permission = "server.coop") -public class CoopCommand implements CommandHandler { +public final class CoopCommand implements CommandHandler { @Override public void execute(Player sender, List args) { if (args.size() < 2) { CommandHandler.sendMessage(sender, "Usage: coop "); return; } + try { int tid = Integer.parseInt(args.get(0)); int hostId = Integer.parseInt(args.get(1)); diff --git a/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java b/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java index 648828643..804f13919 100644 --- a/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java @@ -15,7 +15,7 @@ import java.util.*; @Command(label = "giveall", usage = "giveall [player] [amount]", description = "Gives all items", aliases = {"givea"}, permission = "player.giveall", threading = true) -public class GiveAllCommand implements CommandHandler { +public final class GiveAllCommand implements CommandHandler { @Override public void execute(Player sender, List args) { @@ -142,16 +142,11 @@ public class GiveAllCommand implements CommandHandler { } } - if (testItemsList.contains(itemId)) { - return true; - } - - return false; + return testItemsList.contains(itemId); } static class Range { - private int min; - private int max; + private final int min, max; public Range(int min, int max) { if(min > max){ @@ -159,6 +154,7 @@ public class GiveAllCommand implements CommandHandler { max ^= min; min ^= max; } + this.min = min; this.max = max; } diff --git a/src/main/java/emu/grasscutter/command/commands/SendMailCommand.java b/src/main/java/emu/grasscutter/command/commands/SendMailCommand.java index 35cedab9a..031358d45 100644 --- a/src/main/java/emu/grasscutter/command/commands/SendMailCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/SendMailCommand.java @@ -6,24 +6,20 @@ import emu.grasscutter.command.CommandHandler; import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.game.mail.Mail; import emu.grasscutter.game.player.Player; -import emu.grasscutter.server.packet.send.PacketMailChangeNotify; -import java.time.Instant; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.Locale; @Command(label = "sendmail", usage = "sendmail [templateId]", description = "Sends mail to the specified user. The usage of this command changes based on it's composition state.", permission = "server.sendmail") -public class SendMailCommand implements CommandHandler { +public final class SendMailCommand implements CommandHandler { // TODO: You should be able to do /sendmail and then just send subsequent messages until you finish // However, due to the current nature of the command system, I don't think this is possible without rewriting // the command system (again). For now this will do // Key = User that is constructing the mail. - private static HashMap mailBeingConstructed = new HashMap(); + private static final HashMap mailBeingConstructed = new HashMap(); // Yes this is awful and I hate it. @Override @@ -48,7 +44,6 @@ public class SendMailCommand implements CommandHandler { default -> { if (DatabaseHelper.getPlayerById(Integer.parseInt(args.get(0))) != null) { mailBuilder = new MailBuilder(Integer.parseInt(args.get(0)), new Mail()); - break; } else { CommandHandler.sendMessage(sender, "The user with an id of '" + args.get(0) + "' does not exist"); return; @@ -73,7 +68,7 @@ public class SendMailCommand implements CommandHandler { } case "finish" -> { if (mailBuilder.constructionStage == 3) { - if (mailBuilder.sendToAll == false) { + if (!mailBuilder.sendToAll) { Grasscutter.getGameServer().getPlayerByUid(mailBuilder.recipient, true).sendMail(mailBuilder.mail); CommandHandler.sendMessage(sender, "Message sent to user " + mailBuilder.recipient + "!"); } else { diff --git a/src/main/java/emu/grasscutter/command/commands/TpallCommand.java b/src/main/java/emu/grasscutter/command/commands/TeleportAllCommand.java similarity index 75% rename from src/main/java/emu/grasscutter/command/commands/TpallCommand.java rename to src/main/java/emu/grasscutter/command/commands/TeleportAllCommand.java index 20236c729..bd4a8a06e 100644 --- a/src/main/java/emu/grasscutter/command/commands/TpallCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/TeleportAllCommand.java @@ -9,23 +9,25 @@ import java.util.List; @Command(label = "tpall", usage = "tpall", description = "Teleports all players in your world to your position", permission = "player.tpall") -public class TpallCommand implements CommandHandler { +public final class TeleportAllCommand implements CommandHandler { @Override public void execute(Player sender, List args) { if (sender == null) { CommandHandler.sendMessage(null, "Run this command in-game."); return; } + if (!sender.getWorld().isMultiplayer()) { CommandHandler.sendMessage(sender, "You only can use this command in MP mode."); return; } - for (Player gp : sender.getWorld().getPlayers()) { - if (gp.equals(sender)) + + for (Player player : sender.getWorld().getPlayers()) { + if (player.equals(sender)) continue; Position pos = sender.getPos(); - gp.getWorld().transferPlayerToScene(gp, sender.getSceneId(), pos); + player.getWorld().transferPlayerToScene(player, sender.getSceneId(), pos); } } } diff --git a/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java b/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java index e8fd5a4ea..f2443dfea 100644 --- a/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java +++ b/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java @@ -30,6 +30,7 @@ import java.net.BindException; import java.net.InetSocketAddress; import java.net.URI; import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.security.KeyStore; import java.util.*; @@ -243,10 +244,9 @@ public final class DispatchServer { try { kmf = createKeyManagerFactory(keystoreFile, "123456"); Grasscutter.getLogger().warn( - "[Dispatch] The default keystore password was loaded successfully. Please consider setting the password to 123456 in config.json."); + "[Dispatch] The default keystore password was loaded successfully. Please consider setting the password to '123456' in config.json."); } catch (Exception e2) { - Grasscutter.getLogger().warn("[Dispatch] Error while loading keystore!"); - e2.printStackTrace(); + Grasscutter.getLogger().warn("[Dispatch] Error while loading keystore!", e2); } } } @@ -339,10 +339,6 @@ public final class DispatchServer { // added. account = DatabaseHelper.createAccountWithId(requestData.account, 0); - for (String permission : Grasscutter.getConfig().getDispatchOptions().defaultPermissions) { - account.addPermission(permission); - } - if (account != null) { responseData.message = "OK"; responseData.data.account.uid = account.getId(); @@ -352,6 +348,9 @@ public final class DispatchServer { Grasscutter.getLogger() .info(String.format("[Dispatch] Client %s failed to log in: Account %s created", t.getRemoteAddress(), responseData.data.account.uid)); + for (String permission : Grasscutter.getConfig().getDispatchOptions().defaultPermissions) { + account.addPermission(permission); + } } else { responseData.retcode = -201; responseData.message = "Username not found, create failed."; @@ -575,15 +574,11 @@ public final class DispatchServer { if (next > last) { int eqPos = qs.indexOf('=', last); - try { - if (eqPos < 0 || eqPos > next) { - result.put(URLDecoder.decode(qs.substring(last, next), "utf-8"), ""); - } else { - result.put(URLDecoder.decode(qs.substring(last, eqPos), "utf-8"), - URLDecoder.decode(qs.substring(eqPos + 1, next), "utf-8")); - } - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); // will never happen, utf-8 support is mandatory for java + if (eqPos < 0 || eqPos > next) { + result.put(URLDecoder.decode(qs.substring(last, next), StandardCharsets.UTF_8), ""); + } else { + result.put(URLDecoder.decode(qs.substring(last, eqPos), StandardCharsets.UTF_8), + URLDecoder.decode(qs.substring(eqPos + 1, next), StandardCharsets.UTF_8)); } } last = next + 1; diff --git a/src/main/java/emu/grasscutter/server/event/dispatch/QueryAllRegionsEvent.java b/src/main/java/emu/grasscutter/server/event/dispatch/QueryAllRegionsEvent.java index 8595f6221..bb4864692 100644 --- a/src/main/java/emu/grasscutter/server/event/dispatch/QueryAllRegionsEvent.java +++ b/src/main/java/emu/grasscutter/server/event/dispatch/QueryAllRegionsEvent.java @@ -1,6 +1,6 @@ package emu.grasscutter.server.event.dispatch; -import emu.grasscutter.server.event.ServerEvent; +import emu.grasscutter.server.event.types.ServerEvent; public final class QueryAllRegionsEvent extends ServerEvent { private String regionList; diff --git a/src/main/java/emu/grasscutter/server/event/dispatch/QueryCurrentRegionEvent.java b/src/main/java/emu/grasscutter/server/event/dispatch/QueryCurrentRegionEvent.java index d6a20b2df..d963d74a7 100644 --- a/src/main/java/emu/grasscutter/server/event/dispatch/QueryCurrentRegionEvent.java +++ b/src/main/java/emu/grasscutter/server/event/dispatch/QueryCurrentRegionEvent.java @@ -1,6 +1,6 @@ package emu.grasscutter.server.event.dispatch; -import emu.grasscutter.server.event.ServerEvent; +import emu.grasscutter.server.event.types.ServerEvent; public final class QueryCurrentRegionEvent extends ServerEvent { private String regionInfo; diff --git a/src/main/java/emu/grasscutter/server/event/game/ReceivePacketEvent.java b/src/main/java/emu/grasscutter/server/event/game/ReceivePacketEvent.java index 51109c720..e64a6305d 100644 --- a/src/main/java/emu/grasscutter/server/event/game/ReceivePacketEvent.java +++ b/src/main/java/emu/grasscutter/server/event/game/ReceivePacketEvent.java @@ -1,7 +1,7 @@ package emu.grasscutter.server.event.game; import emu.grasscutter.server.event.Cancellable; -import emu.grasscutter.server.event.ServerEvent; +import emu.grasscutter.server.event.types.ServerEvent; import emu.grasscutter.server.game.GameSession; public final class ReceivePacketEvent extends ServerEvent implements Cancellable { diff --git a/src/main/java/emu/grasscutter/server/game/GameServer.java b/src/main/java/emu/grasscutter/server/game/GameServer.java index 9452b3993..c66a22e53 100644 --- a/src/main/java/emu/grasscutter/server/game/GameServer.java +++ b/src/main/java/emu/grasscutter/server/game/GameServer.java @@ -17,7 +17,7 @@ import emu.grasscutter.game.world.World; import emu.grasscutter.net.packet.PacketHandler; import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail; import emu.grasscutter.netty.KcpServer; -import emu.grasscutter.server.event.ServerEvent; +import emu.grasscutter.server.event.types.ServerEvent; import emu.grasscutter.server.event.game.ServerTickEvent; import emu.grasscutter.server.event.internal.ServerStartEvent; import emu.grasscutter.server.event.internal.ServerStopEvent; diff --git a/src/main/java/emu/grasscutter/task/TaskHandler.java b/src/main/java/emu/grasscutter/task/TaskHandler.java index ea6fe22cd..bf2b9850a 100644 --- a/src/main/java/emu/grasscutter/task/TaskHandler.java +++ b/src/main/java/emu/grasscutter/task/TaskHandler.java @@ -3,24 +3,12 @@ package emu.grasscutter.task; import org.quartz.*; @PersistJobDataAfterExecution -public class TaskHandler implements Job { - +public abstract class TaskHandler implements Job { public void restartExecute() throws JobExecutionException { execute(null); } - public void onEnable() { - - } - - public void onDisable() { - - } - - @Override - public void execute(JobExecutionContext context) throws JobExecutionException { - // TODO Auto-generated method stub - - } + public abstract void onEnable(); + public abstract void onDisable(); } diff --git a/src/main/java/emu/grasscutter/task/tasks/MoonCard.java b/src/main/java/emu/grasscutter/task/tasks/MoonCard.java index 51088f46d..2d51151c1 100644 --- a/src/main/java/emu/grasscutter/task/tasks/MoonCard.java +++ b/src/main/java/emu/grasscutter/task/tasks/MoonCard.java @@ -4,22 +4,21 @@ import emu.grasscutter.Grasscutter; import emu.grasscutter.task.Task; import emu.grasscutter.task.TaskHandler; - import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; @Task(taskName = "MoonCard", taskCronExpression = "0 0 0 * * ?", triggerName = "MoonCardTrigger") // taskCronExpression: Fixed time period: 0:0:0 every day (twenty-four hour system) -public class MoonCard extends TaskHandler { +public final class MoonCard extends TaskHandler { @Override public void onEnable() { - Grasscutter.getLogger().info("[Task] MoonCard task enabled."); + Grasscutter.getLogger().debug("[Task] MoonCard task enabled."); } @Override public void onDisable() { - Grasscutter.getLogger().info("[Task] MoonCard task disabled."); + Grasscutter.getLogger().debug("[Task] MoonCard task disabled."); } @Override