Commit d32f706c authored by KingRainbow44's avatar KingRainbow44
Browse files

Merge branch 'development' into api

# Conflicts:
#	src/main/java/emu/grasscutter/plugin/api/ServerHook.java
parents 47d8fd3c f0d728b4
...@@ -3,10 +3,10 @@ package emu.grasscutter.command.commands; ...@@ -3,10 +3,10 @@ package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.data.GenshinData; import emu.grasscutter.data.GameData;
import emu.grasscutter.data.def.ItemData; import emu.grasscutter.data.def.ItemData;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.game.inventory.GenshinItem; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.ActionReason; import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.server.packet.send.PacketItemAddHintNotify; import emu.grasscutter.server.packet.send.PacketItemAddHintNotify;
...@@ -18,7 +18,7 @@ import java.util.List; ...@@ -18,7 +18,7 @@ import java.util.List;
public final class GiveCommand implements CommandHandler { public final class GiveCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(Player sender, List<String> args) {
int target, item, lvl, amount = 1; int target, item, lvl, amount = 1;
if (sender == null && args.size() < 2) { if (sender == null && args.size() < 2) {
CommandHandler.sendMessage(null, "Usage: give <player> <itemId|itemName> [amount] [level]"); CommandHandler.sendMessage(null, "Usage: give <player> <itemId|itemName> [amount] [level]");
...@@ -99,14 +99,14 @@ public final class GiveCommand implements CommandHandler { ...@@ -99,14 +99,14 @@ public final class GiveCommand implements CommandHandler {
break; break;
} }
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found."); CommandHandler.sendMessage(sender, "Player not found.");
return; return;
} }
ItemData itemData = GenshinData.getItemDataMap().get(item); ItemData itemData = GameData.getItemDataMap().get(item);
if (itemData == null) { if (itemData == null) {
CommandHandler.sendMessage(sender, "Invalid item id."); CommandHandler.sendMessage(sender, "Invalid item id.");
return; return;
...@@ -121,11 +121,11 @@ public final class GiveCommand implements CommandHandler { ...@@ -121,11 +121,11 @@ public final class GiveCommand implements CommandHandler {
String.format("Given %s with level %s %s times to %s", item, lvl, amount, target)); String.format("Given %s with level %s %s times to %s", item, lvl, amount, target));
} }
private void item(GenshinPlayer player, ItemData itemData, int amount, int lvl) { private void item(Player player, ItemData itemData, int amount, int lvl) {
if (itemData.isEquip()) { if (itemData.isEquip()) {
List<GenshinItem> items = new LinkedList<>(); List<GameItem> items = new LinkedList<>();
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
GenshinItem item = new GenshinItem(itemData); GameItem item = new GameItem(itemData);
item.setCount(amount); item.setCount(amount);
item.setLevel(lvl); item.setLevel(lvl);
item.setPromoteLevel(0); item.setPromoteLevel(0);
...@@ -144,13 +144,11 @@ public final class GiveCommand implements CommandHandler { ...@@ -144,13 +144,11 @@ public final class GiveCommand implements CommandHandler {
} }
items.add(item); items.add(item);
} }
player.getInventory().addItems(items); player.getInventory().addItems(items, ActionReason.SubfieldDrop);
player.sendPacket(new PacketItemAddHintNotify(items, ActionReason.SubfieldDrop));
} else { } else {
GenshinItem genshinItem = new GenshinItem(itemData); GameItem item = new GameItem(itemData);
genshinItem.setCount(amount); item.setCount(amount);
player.getInventory().addItem(genshinItem); player.getInventory().addItem(item, ActionReason.SubfieldDrop);
player.sendPacket(new PacketItemAddHintNotify(genshinItem, ActionReason.SubfieldDrop));
} }
} }
} }
...@@ -3,7 +3,7 @@ package emu.grasscutter.command.commands; ...@@ -3,7 +3,7 @@ package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
...@@ -12,7 +12,7 @@ import java.util.List; ...@@ -12,7 +12,7 @@ import java.util.List;
public final class GodModeCommand implements CommandHandler { public final class GodModeCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer 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; // TODO: toggle player's godmode statue from console or other players return; // TODO: toggle player's godmode statue from console or other players
...@@ -32,7 +32,7 @@ public final class GodModeCommand implements CommandHandler { ...@@ -32,7 +32,7 @@ public final class GodModeCommand implements CommandHandler {
} else { } else {
target = sender.getUid(); target = sender.getUid();
} }
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found."); CommandHandler.sendMessage(sender, "Player not found.");
return; return;
......
...@@ -2,7 +2,7 @@ package emu.grasscutter.command.commands; ...@@ -2,7 +2,7 @@ package emu.grasscutter.command.commands;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.FightProperty; import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.server.packet.send.PacketAvatarFightPropUpdateNotify; import emu.grasscutter.server.packet.send.PacketAvatarFightPropUpdateNotify;
import emu.grasscutter.server.packet.send.PacketAvatarLifeStateChangeNotify; import emu.grasscutter.server.packet.send.PacketAvatarLifeStateChangeNotify;
...@@ -13,7 +13,7 @@ import java.util.List; ...@@ -13,7 +13,7 @@ import java.util.List;
description = "Heal all characters in your current team.", permission = "player.heal") description = "Heal all characters in your current team.", permission = "player.heal")
public final class HealCommand implements CommandHandler { public final class HealCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer 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;
......
...@@ -3,7 +3,7 @@ package emu.grasscutter.command.commands; ...@@ -3,7 +3,7 @@ package emu.grasscutter.command.commands;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.command.CommandMap; import emu.grasscutter.command.CommandMap;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.player.Player;
import java.util.*; import java.util.*;
...@@ -12,7 +12,7 @@ import java.util.*; ...@@ -12,7 +12,7 @@ import java.util.*;
public final class HelpCommand implements CommandHandler { public final class HelpCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer player, List<String> args) { public void execute(Player player, List<String> args) {
if (args.size() < 1) { if (args.size() < 1) {
HashMap<String, CommandHandler> handlers = CommandMap.getInstance().getHandlers(); HashMap<String, CommandHandler> handlers = CommandMap.getInstance().getHandlers();
List<Command> annotations = new ArrayList<>(); List<Command> annotations = new ArrayList<>();
...@@ -53,7 +53,7 @@ public final class HelpCommand implements CommandHandler { ...@@ -53,7 +53,7 @@ public final class HelpCommand implements CommandHandler {
} }
} }
void SendAllHelpMessage(GenshinPlayer player, List<Command> annotations) { void SendAllHelpMessage(Player player, List<Command> annotations) {
if (player == null) { if (player == null) {
StringBuilder builder = new StringBuilder("\nAvailable commands:\n"); StringBuilder builder = new StringBuilder("\nAvailable commands:\n");
annotations.forEach(annotation -> { annotations.forEach(annotation -> {
......
...@@ -3,7 +3,7 @@ package emu.grasscutter.command.commands; ...@@ -3,7 +3,7 @@ package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
...@@ -12,10 +12,10 @@ import java.util.List; ...@@ -12,10 +12,10 @@ import java.util.List;
public final class KickCommand implements CommandHandler { public final class KickCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(Player sender, List<String> args) {
int target = Integer.parseInt(args.get(0)); int target = Integer.parseInt(args.get(0));
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found."); CommandHandler.sendMessage(sender, "Player not found.");
return; return;
......
...@@ -3,9 +3,9 @@ package emu.grasscutter.command.commands; ...@@ -3,9 +3,9 @@ package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.GenshinScene;
import emu.grasscutter.game.entity.EntityMonster; import emu.grasscutter.game.entity.EntityMonster;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.world.Scene;
import java.util.List; import java.util.List;
...@@ -14,9 +14,9 @@ import java.util.List; ...@@ -14,9 +14,9 @@ import java.util.List;
public final class KillAllCommand implements CommandHandler { public final class KillAllCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(Player sender, List<String> args) {
GenshinScene scene; Scene mainScene;
GenshinPlayer genshinPlayer; Player targetPlayer;
try { try {
switch (args.size()) { switch (args.size()) {
...@@ -25,38 +25,38 @@ public final class KillAllCommand implements CommandHandler { ...@@ -25,38 +25,38 @@ public final class KillAllCommand implements CommandHandler {
CommandHandler.sendMessage(null, "Usage: killall [playerUid] [sceneId]"); CommandHandler.sendMessage(null, "Usage: killall [playerUid] [sceneId]");
return; return;
} }
scene = sender.getScene(); mainScene = sender.getScene();
break; break;
case 1: // [playerUid] case 1: // [playerUid]
genshinPlayer = Grasscutter.getGameServer().getPlayerByUid(Integer.parseInt(args.get(0))); targetPlayer = Grasscutter.getGameServer().getPlayerByUid(Integer.parseInt(args.get(0)));
if (genshinPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found or offline."); CommandHandler.sendMessage(sender, "Player not found or offline.");
return; return;
} }
scene = genshinPlayer.getScene(); mainScene = targetPlayer.getScene();
break; break;
case 2: // [playerUid] [sceneId] case 2: // [playerUid] [sceneId]
genshinPlayer = Grasscutter.getGameServer().getPlayerByUid(Integer.parseInt(args.get(0))); targetPlayer = Grasscutter.getGameServer().getPlayerByUid(Integer.parseInt(args.get(0)));
if (genshinPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found or offline."); CommandHandler.sendMessage(sender, "Player not found or offline.");
return; return;
} }
GenshinScene genshinScene = sender.getWorld().getSceneById(Integer.parseInt(args.get(1))); Scene scene = sender.getWorld().getSceneById(Integer.parseInt(args.get(1)));
if (genshinScene == null) { if (scene == null) {
CommandHandler.sendMessage(sender, "Scene not found in player world"); CommandHandler.sendMessage(sender, "Scene not found in player world");
return; return;
} }
scene = genshinScene; mainScene = scene;
break; break;
default: default:
CommandHandler.sendMessage(sender, "Usage: killall [playerUid] [sceneId]"); CommandHandler.sendMessage(sender, "Usage: killall [playerUid] [sceneId]");
return; return;
} }
scene.getEntities().values().stream() mainScene.getEntities().values().stream()
.filter(entity -> entity instanceof EntityMonster) .filter(entity -> entity instanceof EntityMonster)
.forEach(entity -> scene.killEntity(entity, 0)); .forEach(entity -> mainScene.killEntity(entity, 0));
CommandHandler.sendMessage(sender, "Killing all monsters in scene " + scene.getId()); CommandHandler.sendMessage(sender, "Killing all monsters in scene " + mainScene.getId());
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid arguments."); CommandHandler.sendMessage(sender, "Invalid arguments.");
} }
......
...@@ -3,8 +3,8 @@ package emu.grasscutter.command.commands; ...@@ -3,8 +3,8 @@ package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.entity.EntityAvatar; import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.FightProperty; import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.game.props.LifeState; import emu.grasscutter.game.props.LifeState;
import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify; import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify;
...@@ -17,7 +17,7 @@ import java.util.List; ...@@ -17,7 +17,7 @@ import java.util.List;
public final class KillCharacterCommand implements CommandHandler { public final class KillCharacterCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(Player sender, List<String> args) {
int target; int target;
if (sender == null) { if (sender == null) {
// from console // from console
...@@ -48,7 +48,7 @@ public final class KillCharacterCommand implements CommandHandler { ...@@ -48,7 +48,7 @@ public final class KillCharacterCommand implements CommandHandler {
} }
} }
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found or offline."); CommandHandler.sendMessage(sender, "Player not found or offline.");
return; return;
......
...@@ -3,7 +3,7 @@ package emu.grasscutter.command.commands; ...@@ -3,7 +3,7 @@ package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -12,8 +12,8 @@ import java.util.Map; ...@@ -12,8 +12,8 @@ import java.util.Map;
public final class ListCommand implements CommandHandler { public final class ListCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(Player sender, List<String> args) {
Map<Integer, GenshinPlayer> playersMap = Grasscutter.getGameServer().getPlayers(); Map<Integer, Player> playersMap = Grasscutter.getGameServer().getPlayers();
CommandHandler.sendMessage(sender, String.format("There are %s player(s) online:", playersMap.size())); CommandHandler.sendMessage(sender, String.format("There are %s player(s) online:", playersMap.size()));
......
...@@ -4,7 +4,7 @@ import emu.grasscutter.Grasscutter; ...@@ -4,7 +4,7 @@ import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.Account; import emu.grasscutter.game.Account;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
...@@ -13,7 +13,7 @@ import java.util.List; ...@@ -13,7 +13,7 @@ import java.util.List;
public final class PermissionCommand implements CommandHandler { public final class PermissionCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(Player sender, List<String> args) {
if (args.size() < 3) { if (args.size() < 3) {
CommandHandler.sendMessage(sender, "Usage: permission <add|remove> <username> <permission>"); CommandHandler.sendMessage(sender, "Usage: permission <add|remove> <username> <permission>");
return; return;
......
...@@ -2,7 +2,7 @@ package emu.grasscutter.command.commands; ...@@ -2,7 +2,7 @@ package emu.grasscutter.command.commands;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
...@@ -11,7 +11,7 @@ import java.util.List; ...@@ -11,7 +11,7 @@ import java.util.List;
public final class PositionCommand implements CommandHandler { public final class PositionCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer 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;
......
...@@ -3,7 +3,7 @@ package emu.grasscutter.command.commands; ...@@ -3,7 +3,7 @@ package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
...@@ -12,10 +12,12 @@ import java.util.List; ...@@ -12,10 +12,12 @@ import java.util.List;
public final class ReloadCommand implements CommandHandler { public final class ReloadCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(Player sender, List<String> args) {
CommandHandler.sendMessage(sender, "Reloading config."); CommandHandler.sendMessage(sender, "Reloading config.");
Grasscutter.loadConfig(); Grasscutter.loadConfig();
Grasscutter.getGameServer().getGachaManager().load(); Grasscutter.getGameServer().getGachaManager().load();
Grasscutter.getGameServer().getDropManager().load();
Grasscutter.getGameServer().getShopManager().load();
Grasscutter.getDispatchServer().loadQueries(); Grasscutter.getDispatchServer().loadQueries();
CommandHandler.sendMessage(sender, "Reload complete."); CommandHandler.sendMessage(sender, "Reload complete.");
} }
......
...@@ -2,9 +2,9 @@ package emu.grasscutter.command.commands; ...@@ -2,9 +2,9 @@ package emu.grasscutter.command.commands;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.avatar.GenshinAvatar;
import emu.grasscutter.game.entity.EntityAvatar; import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
...@@ -14,7 +14,7 @@ import java.util.List; ...@@ -14,7 +14,7 @@ import java.util.List;
public final class ResetConstCommand implements CommandHandler { public final class ResetConstCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer 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;
...@@ -29,14 +29,14 @@ public final class ResetConstCommand implements CommandHandler { ...@@ -29,14 +29,14 @@ public final class ResetConstCommand implements CommandHandler {
return; return;
} }
GenshinAvatar avatar = entity.getAvatar(); Avatar avatar = entity.getAvatar();
this.resetConstellation(avatar); this.resetConstellation(avatar);
sender.dropMessage("Constellations for " + avatar.getAvatarData().getName() + " have been reset. Please relog to see changes."); sender.dropMessage("Constellations for " + avatar.getAvatarData().getName() + " have been reset. Please relog to see changes.");
} }
} }
private void resetConstellation(GenshinAvatar avatar) { private void resetConstellation(Avatar avatar) {
avatar.getTalentIdList().clear(); avatar.getTalentIdList().clear();
avatar.setCoreProudSkillLevel(0); avatar.setCoreProudSkillLevel(0);
avatar.recalcStats(); avatar.recalcStats();
......
...@@ -2,7 +2,7 @@ package emu.grasscutter.command.commands; ...@@ -2,7 +2,7 @@ package emu.grasscutter.command.commands;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
...@@ -10,7 +10,7 @@ import java.util.List; ...@@ -10,7 +10,7 @@ import java.util.List;
public final class RestartCommand implements CommandHandler { public final class RestartCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(Player sender, List<String> args) {
sender.getSession().close(); sender.getSession().close();
} }
} }
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
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 <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")
public 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<Integer, MailBuilder> mailBeingConstructed = new HashMap<Integer, MailBuilder>();
// Yes this is awful and I hate it.
@Override
public void execute(Player sender, List<String> args) {
int senderId;
if(sender != null) {
senderId = sender.getUid();
} else {
senderId = -1;
}
if (!mailBeingConstructed.containsKey(senderId)) {
switch (args.size()) {
case 1 -> {
MailBuilder mailBuilder;
switch (args.get(0).toLowerCase()) {
case "help" -> {
CommandHandler.sendMessage(sender, this.getClass().getAnnotation(Command.class).description() + "\nUsage: " + this.getClass().getAnnotation(Command.class).usage());
return;
}
case "all" -> mailBuilder = new MailBuilder(true, new Mail());
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;
}
}
}
mailBeingConstructed.put(senderId, mailBuilder);
CommandHandler.sendMessage(sender, "Starting composition of message.\nPlease use `/sendmail <title>` to continue.\nYou can use `/sendmail stop` at any time");
}
case 2 -> CommandHandler.sendMessage(sender, "Mail templates coming soon implemented...");
default -> CommandHandler.sendMessage(sender, "Invalid arguments.\nUsage `/sendmail <userId|all|help> [templateId]`");
}
} else {
MailBuilder mailBuilder = mailBeingConstructed.get(senderId);
if (args.size() >= 1) {
switch (args.get(0).toLowerCase()) {
case "stop" -> {
mailBeingConstructed.remove(senderId);
CommandHandler.sendMessage(sender, "Message sending cancelled");
return;
}
case "finish" -> {
if (mailBuilder.constructionStage == 3) {
if (mailBuilder.sendToAll == false) {
Grasscutter.getGameServer().getPlayerByUid(mailBuilder.recipient, true).sendMail(mailBuilder.mail);
CommandHandler.sendMessage(sender, "Message sent to user " + mailBuilder.recipient + "!");
} else {
for (Player player : DatabaseHelper.getAllPlayers()) {
Grasscutter.getGameServer().getPlayerByUid(player.getUid(), true).sendMail(mailBuilder.mail);
}
CommandHandler.sendMessage(sender, "Message sent to all users!");
}
mailBeingConstructed.remove(senderId);
} else {
CommandHandler.sendMessage(sender, "Message composition not at final stage.\nPlease use `/sendmail " + getConstructionArgs(mailBuilder.constructionStage) + "` or `/sendmail stop` to cancel");
}
return;
}
case "help" -> {
CommandHandler.sendMessage(sender, "Please use `/sendmail " + getConstructionArgs(mailBuilder.constructionStage) + "`");
return;
}
default -> {
switch (mailBuilder.constructionStage) {
case 0 -> {
String title = String.join(" ", args.subList(0, args.size()));
mailBuilder.mail.mailContent.title = title;
CommandHandler.sendMessage(sender, "Message title set as '" + title + "'.\nUse '/sendmail <content>' to continue.");
mailBuilder.constructionStage++;
}
case 1 -> {
String contents = String.join(" ", args.subList(0, args.size()));
mailBuilder.mail.mailContent.content = contents;
CommandHandler.sendMessage(sender, "Message contents set as '" + contents + "'.\nUse '/sendmail <sender>' to continue.");
mailBuilder.constructionStage++;
}
case 2 -> {
String msgSender = String.join(" ", args.subList(0, args.size()));
mailBuilder.mail.mailContent.sender = msgSender;
CommandHandler.sendMessage(sender, "Message sender set as '" + msgSender + "'.\nUse '/sendmail <itemId|itemName|finish> [amount] [level]' to continue.");
mailBuilder.constructionStage++;
}
case 3 -> {
// Literally just copy-pasted from the give command lol.
int item, lvl, amount = 1;
switch (args.size()) {
default -> { // *No args*
CommandHandler.sendMessage(sender, "Usage: give [player] <itemId|itemName> [amount]");
return;
}
case 1 -> { // <itemId|itemName>
try {
item = Integer.parseInt(args.get(0));
lvl = 1;
} catch (NumberFormatException ignored) {
// TODO: Parse from item name using GM Handbook.
CommandHandler.sendMessage(sender, "Invalid item id.");
return;
}
}
case 2 -> { // <itemId|itemName> [amount]
lvl = 1;
item = Integer.parseInt(args.get(0));
amount = Integer.parseInt(args.get(1));
}
case 3 -> { // <itemId|itemName> [amount] [level]
try {
item = Integer.parseInt(args.get(0));
amount = Integer.parseInt(args.get(1));
lvl = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) {
// TODO: Parse from item name using GM Handbook.
CommandHandler.sendMessage(sender, "Invalid item or player ID.");
return;
}
}
}
mailBuilder.mail.itemList.add(new Mail.MailItem(item, amount, lvl));
CommandHandler.sendMessage(sender, String.format("Attached %s of %s (level %s) to the message.\nContinue adding more items or use `/sendmail finish` to send the message.", amount, item, lvl));
}
}
}
}
} else {
CommandHandler.sendMessage(sender, "Invalid arguments \n Please use `/sendmail " + getConstructionArgs(mailBuilder.constructionStage));
}
}
}
private String getConstructionArgs(int stage) {
switch (stage) {
case 0 -> {
return "<title>";
}
case 1 -> {
return "<message>";
}
case 2 -> {
return "<sender>";
}
case 3 -> {
return "<itemId|itemName|finish> [amount] [level]";
}
default -> {
Thread.dumpStack();
return "ERROR: invalid construction stage " + stage + ". Check console for stacktrace.";
}
}
}
public static class MailBuilder {
public int recipient;
public boolean sendToAll;
public int constructionStage;
public Mail mail;
public MailBuilder(int recipient, Mail mail) {
this.recipient = recipient;
this.sendToAll = false;
this.constructionStage = 0;
this.mail = mail;
}
public MailBuilder(boolean sendToAll, Mail mail) {
if (sendToAll) {
this.recipient = 0;
this.sendToAll = true;
this.constructionStage = 0;
this.mail = mail;
} else {
Grasscutter.getLogger().error("Please use MailBuilder(int, mail) when not sending to all");
Thread.dumpStack();
}
}
}
}
...@@ -3,7 +3,7 @@ package emu.grasscutter.command.commands; ...@@ -3,7 +3,7 @@ package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
...@@ -12,7 +12,7 @@ import java.util.List; ...@@ -12,7 +12,7 @@ import java.util.List;
public final class SendMessageCommand implements CommandHandler { public final class SendMessageCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(Player sender, List<String> args) {
if (args.size() < 2) { if (args.size() < 2) {
CommandHandler.sendMessage(null, "Usage: sendmessage <player> <message>"); CommandHandler.sendMessage(null, "Usage: sendmessage <player> <message>");
return; return;
...@@ -22,7 +22,7 @@ public final class SendMessageCommand implements CommandHandler { ...@@ -22,7 +22,7 @@ public final class SendMessageCommand implements CommandHandler {
int target = Integer.parseInt(args.get(0)); int target = Integer.parseInt(args.get(0));
String message = String.join(" ", args.subList(1, args.size())); String message = String.join(" ", args.subList(1, args.size()));
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found."); CommandHandler.sendMessage(sender, "Player not found.");
return; return;
......
...@@ -4,9 +4,9 @@ import java.util.List; ...@@ -4,9 +4,9 @@ import java.util.List;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.data.GenshinData; import emu.grasscutter.data.GameData;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.avatar.GenshinAvatar; import emu.grasscutter.game.player.Player;
import emu.grasscutter.server.packet.send.PacketAvatarFetterDataNotify; import emu.grasscutter.server.packet.send.PacketAvatarFetterDataNotify;
@Command(label = "setfetterlevel", usage = "setfetterlevel <level>", @Command(label = "setfetterlevel", usage = "setfetterlevel <level>",
...@@ -15,7 +15,7 @@ import emu.grasscutter.server.packet.send.PacketAvatarFetterDataNotify; ...@@ -15,7 +15,7 @@ import emu.grasscutter.server.packet.send.PacketAvatarFetterDataNotify;
public final class SetFetterLevelCommand implements CommandHandler { public final class SetFetterLevelCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer 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;
...@@ -32,11 +32,11 @@ public final class SetFetterLevelCommand implements CommandHandler { ...@@ -32,11 +32,11 @@ public final class SetFetterLevelCommand implements CommandHandler {
CommandHandler.sendMessage(sender, "Fetter level must be between 0 and 10."); CommandHandler.sendMessage(sender, "Fetter level must be between 0 and 10.");
return; return;
} }
GenshinAvatar avatar = sender.getTeamManager().getCurrentAvatarEntity().getAvatar(); Avatar avatar = sender.getTeamManager().getCurrentAvatarEntity().getAvatar();
avatar.setFetterLevel(fetterLevel); avatar.setFetterLevel(fetterLevel);
if (fetterLevel != 10) { if (fetterLevel != 10) {
avatar.setFetterExp(GenshinData.getAvatarFetterLevelDataMap().get(fetterLevel).getExp()); avatar.setFetterExp(GameData.getAvatarFetterLevelDataMap().get(fetterLevel).getExp());
} }
avatar.save(); avatar.save();
......
...@@ -2,8 +2,8 @@ package emu.grasscutter.command.commands; ...@@ -2,8 +2,8 @@ package emu.grasscutter.command.commands;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.entity.EntityAvatar; import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.FightProperty; import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify; import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify;
...@@ -14,7 +14,7 @@ import java.util.List; ...@@ -14,7 +14,7 @@ import java.util.List;
public final class SetStatsCommand implements CommandHandler { public final class SetStatsCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer 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;
......
...@@ -2,7 +2,7 @@ package emu.grasscutter.command.commands; ...@@ -2,7 +2,7 @@ package emu.grasscutter.command.commands;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.PlayerProperty; import emu.grasscutter.game.props.PlayerProperty;
import java.util.List; import java.util.List;
...@@ -13,7 +13,7 @@ import java.util.List; ...@@ -13,7 +13,7 @@ import java.util.List;
public final class SetWorldLevelCommand implements CommandHandler { public final class SetWorldLevelCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer 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; // TODO: set player's world level from console or other players return; // TODO: set player's world level from console or other players
...@@ -29,7 +29,7 @@ public final class SetWorldLevelCommand implements CommandHandler { ...@@ -29,7 +29,7 @@ public final class SetWorldLevelCommand implements CommandHandler {
// Set in both world and player props // Set in both world and player props
sender.getWorld().setWorldLevel(level); sender.getWorld().setWorldLevel(level);
sender.setProperty(PlayerProperty.PROP_PLAYER_WORLD_LEVEL, level); sender.setWorldLevel(level);
sender.dropMessage("World level set to " + level + "."); sender.dropMessage("World level set to " + level + ".");
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
......
...@@ -2,10 +2,10 @@ package emu.grasscutter.command.commands; ...@@ -2,10 +2,10 @@ package emu.grasscutter.command.commands;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.data.GenshinData; import emu.grasscutter.data.GameData;
import emu.grasscutter.data.def.MonsterData; import emu.grasscutter.data.def.MonsterData;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.entity.EntityMonster; import emu.grasscutter.game.entity.EntityMonster;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.utils.Position; import emu.grasscutter.utils.Position;
import java.util.List; import java.util.List;
...@@ -15,7 +15,7 @@ import java.util.List; ...@@ -15,7 +15,7 @@ import java.util.List;
public final class SpawnCommand implements CommandHandler { public final class SpawnCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer 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;
...@@ -31,7 +31,7 @@ public final class SpawnCommand implements CommandHandler { ...@@ -31,7 +31,7 @@ public final class SpawnCommand implements CommandHandler {
int level = args.size() > 1 ? Integer.parseInt(args.get(1)) : 1; int level = args.size() > 1 ? Integer.parseInt(args.get(1)) : 1;
int amount = args.size() > 2 ? Integer.parseInt(args.get(2)) : 1; int amount = args.size() > 2 ? Integer.parseInt(args.get(2)) : 1;
MonsterData entityData = GenshinData.getMonsterDataMap().get(entity); MonsterData entityData = GameData.getMonsterDataMap().get(entity);
if (entityData == null) { if (entityData == null) {
CommandHandler.sendMessage(sender, "Invalid entity id."); CommandHandler.sendMessage(sender, "Invalid entity id.");
return; return;
......
...@@ -3,7 +3,7 @@ package emu.grasscutter.command.commands; ...@@ -3,7 +3,7 @@ package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
...@@ -12,9 +12,9 @@ import java.util.List; ...@@ -12,9 +12,9 @@ import java.util.List;
public final class StopCommand implements CommandHandler { public final class StopCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(Player sender, List<String> args) {
CommandHandler.sendMessage(null, "Server shutting down..."); CommandHandler.sendMessage(null, "Server shutting down...");
for (GenshinPlayer p : Grasscutter.getGameServer().getPlayers().values()) { for (Player p : Grasscutter.getGameServer().getPlayers().values()) {
CommandHandler.sendMessage(p, "Server shutting down..."); CommandHandler.sendMessage(p, "Server shutting down...");
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment