Formatting changes

This commit is contained in:
KingRainbow44 2022-04-28 22:21:30 -04:00
parent b811300742
commit 2e119efb86
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
11 changed files with 36 additions and 60 deletions

View File

@ -8,13 +8,14 @@ import java.util.List;
@Command(label = "coop", usage = "coop", @Command(label = "coop", usage = "coop",
description = "Forces someone to join the world of others", permission = "server.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 @Override
public void execute(Player sender, List<String> args) { public void execute(Player sender, List<String> args) {
if (args.size() < 2) { if (args.size() < 2) {
CommandHandler.sendMessage(sender, "Usage: coop <playerId> <target playerId>"); CommandHandler.sendMessage(sender, "Usage: coop <playerId> <target playerId>");
return; return;
} }
try { try {
int tid = Integer.parseInt(args.get(0)); int tid = Integer.parseInt(args.get(0));
int hostId = Integer.parseInt(args.get(1)); int hostId = Integer.parseInt(args.get(1));

View File

@ -15,7 +15,7 @@ import java.util.*;
@Command(label = "giveall", usage = "giveall [player] [amount]", @Command(label = "giveall", usage = "giveall [player] [amount]",
description = "Gives all items", aliases = {"givea"}, permission = "player.giveall", threading = true) description = "Gives all items", aliases = {"givea"}, permission = "player.giveall", threading = true)
public class GiveAllCommand implements CommandHandler { public final class GiveAllCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, List<String> args) { public void execute(Player sender, List<String> args) {
@ -142,16 +142,11 @@ public class GiveAllCommand implements CommandHandler {
} }
} }
if (testItemsList.contains(itemId)) { return testItemsList.contains(itemId);
return true;
}
return false;
} }
static class Range { static class Range {
private int min; private final int min, max;
private int max;
public Range(int min, int max) { public Range(int min, int max) {
if(min > max){ if(min > max){
@ -159,6 +154,7 @@ public class GiveAllCommand implements CommandHandler {
max ^= min; max ^= min;
min ^= max; min ^= max;
} }
this.min = min; this.min = min;
this.max = max; this.max = max;
} }

View File

@ -6,24 +6,20 @@ import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.mail.Mail; import emu.grasscutter.game.mail.Mail;
import emu.grasscutter.game.player.Player; 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.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale;
@Command(label = "sendmail", usage = "sendmail <userId|all|help> [templateId]", @Command(label = "sendmail", usage = "sendmail <userId|all|help> [templateId]",
description = "Sends mail to the specified user. The usage of this command changes based on it's composition state.", permission = "server.sendmail") 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 // 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 // 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 // the command system (again). For now this will do
// Key = User that is constructing the mail. // Key = User that is constructing the mail.
private static HashMap<Integer, MailBuilder> mailBeingConstructed = new HashMap<Integer, MailBuilder>(); private static final HashMap<Integer, MailBuilder> mailBeingConstructed = new HashMap<Integer, MailBuilder>();
// Yes this is awful and I hate it. // Yes this is awful and I hate it.
@Override @Override
@ -48,7 +44,6 @@ public class SendMailCommand implements CommandHandler {
default -> { default -> {
if (DatabaseHelper.getPlayerById(Integer.parseInt(args.get(0))) != null) { if (DatabaseHelper.getPlayerById(Integer.parseInt(args.get(0))) != null) {
mailBuilder = new MailBuilder(Integer.parseInt(args.get(0)), new Mail()); mailBuilder = new MailBuilder(Integer.parseInt(args.get(0)), new Mail());
break;
} else { } else {
CommandHandler.sendMessage(sender, "The user with an id of '" + args.get(0) + "' does not exist"); CommandHandler.sendMessage(sender, "The user with an id of '" + args.get(0) + "' does not exist");
return; return;
@ -73,7 +68,7 @@ public class SendMailCommand implements CommandHandler {
} }
case "finish" -> { case "finish" -> {
if (mailBuilder.constructionStage == 3) { if (mailBuilder.constructionStage == 3) {
if (mailBuilder.sendToAll == false) { if (!mailBuilder.sendToAll) {
Grasscutter.getGameServer().getPlayerByUid(mailBuilder.recipient, true).sendMail(mailBuilder.mail); Grasscutter.getGameServer().getPlayerByUid(mailBuilder.recipient, true).sendMail(mailBuilder.mail);
CommandHandler.sendMessage(sender, "Message sent to user " + mailBuilder.recipient + "!"); CommandHandler.sendMessage(sender, "Message sent to user " + mailBuilder.recipient + "!");
} else { } else {

View File

@ -9,23 +9,25 @@ import java.util.List;
@Command(label = "tpall", usage = "tpall", @Command(label = "tpall", usage = "tpall",
description = "Teleports all players in your world to your position", permission = "player.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 @Override
public void execute(Player sender, List<String> args) { public void execute(Player sender, List<String> args) {
if (sender == null) { if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game."); CommandHandler.sendMessage(null, "Run this command in-game.");
return; return;
} }
if (!sender.getWorld().isMultiplayer()) { if (!sender.getWorld().isMultiplayer()) {
CommandHandler.sendMessage(sender, "You only can use this command in MP mode."); CommandHandler.sendMessage(sender, "You only can use this command in MP mode.");
return; return;
} }
for (Player gp : sender.getWorld().getPlayers()) {
if (gp.equals(sender)) for (Player player : sender.getWorld().getPlayers()) {
if (player.equals(sender))
continue; continue;
Position pos = sender.getPos(); Position pos = sender.getPos();
gp.getWorld().transferPlayerToScene(gp, sender.getSceneId(), pos); player.getWorld().transferPlayerToScene(player, sender.getSceneId(), pos);
} }
} }
} }

View File

@ -30,6 +30,7 @@ import java.net.BindException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.URI; import java.net.URI;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.security.KeyStore; import java.security.KeyStore;
import java.util.*; import java.util.*;
@ -243,10 +244,9 @@ public final class DispatchServer {
try { try {
kmf = createKeyManagerFactory(keystoreFile, "123456"); kmf = createKeyManagerFactory(keystoreFile, "123456");
Grasscutter.getLogger().warn( 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) { } catch (Exception e2) {
Grasscutter.getLogger().warn("[Dispatch] Error while loading keystore!"); Grasscutter.getLogger().warn("[Dispatch] Error while loading keystore!", e2);
e2.printStackTrace();
} }
} }
} }
@ -339,10 +339,6 @@ public final class DispatchServer {
// added. // added.
account = DatabaseHelper.createAccountWithId(requestData.account, 0); account = DatabaseHelper.createAccountWithId(requestData.account, 0);
for (String permission : Grasscutter.getConfig().getDispatchOptions().defaultPermissions) {
account.addPermission(permission);
}
if (account != null) { if (account != null) {
responseData.message = "OK"; responseData.message = "OK";
responseData.data.account.uid = account.getId(); responseData.data.account.uid = account.getId();
@ -352,6 +348,9 @@ public final class DispatchServer {
Grasscutter.getLogger() Grasscutter.getLogger()
.info(String.format("[Dispatch] Client %s failed to log in: Account %s created", .info(String.format("[Dispatch] Client %s failed to log in: Account %s created",
t.getRemoteAddress(), responseData.data.account.uid)); t.getRemoteAddress(), responseData.data.account.uid));
for (String permission : Grasscutter.getConfig().getDispatchOptions().defaultPermissions) {
account.addPermission(permission);
}
} else { } else {
responseData.retcode = -201; responseData.retcode = -201;
responseData.message = "Username not found, create failed."; responseData.message = "Username not found, create failed.";
@ -575,15 +574,11 @@ public final class DispatchServer {
if (next > last) { if (next > last) {
int eqPos = qs.indexOf('=', last); int eqPos = qs.indexOf('=', last);
try {
if (eqPos < 0 || eqPos > next) { if (eqPos < 0 || eqPos > next) {
result.put(URLDecoder.decode(qs.substring(last, next), "utf-8"), ""); result.put(URLDecoder.decode(qs.substring(last, next), StandardCharsets.UTF_8), "");
} else { } else {
result.put(URLDecoder.decode(qs.substring(last, eqPos), "utf-8"), result.put(URLDecoder.decode(qs.substring(last, eqPos), StandardCharsets.UTF_8),
URLDecoder.decode(qs.substring(eqPos + 1, next), "utf-8")); URLDecoder.decode(qs.substring(eqPos + 1, next), StandardCharsets.UTF_8));
}
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e); // will never happen, utf-8 support is mandatory for java
} }
} }
last = next + 1; last = next + 1;

View File

@ -1,6 +1,6 @@
package emu.grasscutter.server.event.dispatch; 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 { public final class QueryAllRegionsEvent extends ServerEvent {
private String regionList; private String regionList;

View File

@ -1,6 +1,6 @@
package emu.grasscutter.server.event.dispatch; 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 { public final class QueryCurrentRegionEvent extends ServerEvent {
private String regionInfo; private String regionInfo;

View File

@ -1,7 +1,7 @@
package emu.grasscutter.server.event.game; package emu.grasscutter.server.event.game;
import emu.grasscutter.server.event.Cancellable; 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; import emu.grasscutter.server.game.GameSession;
public final class ReceivePacketEvent extends ServerEvent implements Cancellable { public final class ReceivePacketEvent extends ServerEvent implements Cancellable {

View File

@ -17,7 +17,7 @@ import emu.grasscutter.game.world.World;
import emu.grasscutter.net.packet.PacketHandler; import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail; import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail;
import emu.grasscutter.netty.KcpServer; 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.game.ServerTickEvent;
import emu.grasscutter.server.event.internal.ServerStartEvent; import emu.grasscutter.server.event.internal.ServerStartEvent;
import emu.grasscutter.server.event.internal.ServerStopEvent; import emu.grasscutter.server.event.internal.ServerStopEvent;

View File

@ -3,24 +3,12 @@ package emu.grasscutter.task;
import org.quartz.*; import org.quartz.*;
@PersistJobDataAfterExecution @PersistJobDataAfterExecution
public class TaskHandler implements Job { public abstract class TaskHandler implements Job {
public void restartExecute() throws JobExecutionException { public void restartExecute() throws JobExecutionException {
execute(null); execute(null);
} }
public void onEnable() { public abstract void onEnable();
}
public void onDisable() {
}
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
// TODO Auto-generated method stub
}
public abstract void onDisable();
} }

View File

@ -4,22 +4,21 @@ import emu.grasscutter.Grasscutter;
import emu.grasscutter.task.Task; import emu.grasscutter.task.Task;
import emu.grasscutter.task.TaskHandler; import emu.grasscutter.task.TaskHandler;
import org.quartz.JobExecutionContext; import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException; import org.quartz.JobExecutionException;
@Task(taskName = "MoonCard", taskCronExpression = "0 0 0 * * ?", triggerName = "MoonCardTrigger") @Task(taskName = "MoonCard", taskCronExpression = "0 0 0 * * ?", triggerName = "MoonCardTrigger")
// taskCronExpression: Fixed time period: 0:0:0 every day (twenty-four hour system) // 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 @Override
public void onEnable() { public void onEnable() {
Grasscutter.getLogger().info("[Task] MoonCard task enabled."); Grasscutter.getLogger().debug("[Task] MoonCard task enabled.");
} }
@Override @Override
public void onDisable() { public void onDisable() {
Grasscutter.getLogger().info("[Task] MoonCard task disabled."); Grasscutter.getLogger().debug("[Task] MoonCard task disabled.");
} }
@Override @Override