Magix sanity.

This commit is contained in:
KingRainbow44 2022-04-20 18:48:24 -04:00
parent f35f76f372
commit 652a2154ce
22 changed files with 1086 additions and 1086 deletions

View File

@ -1,62 +1,62 @@
package emu.grasscutter.command.commands; 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.database.DatabaseHelper; import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.GenshinPlayer;
import java.util.List; import java.util.List;
@Command(label = "account", usage = "account <create|delete> <username> [uid]", @Command(label = "account", usage = "account <create|delete> <username> [uid]",
description = "Modify user accounts") description = "Modify user accounts")
public class Account implements CommandHandler { public final class AccountCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(GenshinPlayer sender, List<String> args) {
if (sender != null) { if (sender != null) {
CommandHandler.sendMessage(sender, "This command can only be run from the console."); CommandHandler.sendMessage(sender, "This command can only be run from the console.");
return; return;
} }
if (args.size() < 2) { if (args.size() < 2) {
CommandHandler.sendMessage(null, "Usage: account <create|delete> <username> [uid]"); CommandHandler.sendMessage(null, "Usage: account <create|delete> <username> [uid]");
return; return;
} }
String action = args.get(0); String action = args.get(0);
String username = args.get(1); String username = args.get(1);
switch (action) { switch (action) {
default: default:
CommandHandler.sendMessage(null, "Usage: account <create|delete> <username> [uid]"); CommandHandler.sendMessage(null, "Usage: account <create|delete> <username> [uid]");
return; return;
case "create": case "create":
int uid = 0; int uid = 0;
if (args.size() > 2) { if (args.size() > 2) {
try { try {
uid = Integer.parseInt(args.get(2)); uid = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(null, "Invalid UID."); CommandHandler.sendMessage(null, "Invalid UID.");
return; return;
} }
} }
emu.grasscutter.game.Account account = DatabaseHelper.createAccountWithId(username, uid); emu.grasscutter.game.Account account = DatabaseHelper.createAccountWithId(username, uid);
if (account == null) { if (account == null) {
CommandHandler.sendMessage(null, "Account already exists."); CommandHandler.sendMessage(null, "Account already exists.");
return; return;
} else { } else {
CommandHandler.sendMessage(null, "Account created with UID " + account.getPlayerId() + "."); CommandHandler.sendMessage(null, "Account created with UID " + account.getPlayerId() + ".");
account.addPermission("*"); // Grant the player superuser permissions. account.addPermission("*"); // Grant the player superuser permissions.
account.save(); // Save account to database. account.save(); // Save account to database.
} }
return; return;
case "delete": case "delete":
if (DatabaseHelper.deleteAccount(username)) { if (DatabaseHelper.deleteAccount(username)) {
CommandHandler.sendMessage(null, "Account deleted."); CommandHandler.sendMessage(null, "Account deleted.");
} else { } else {
CommandHandler.sendMessage(null, "Account not found."); CommandHandler.sendMessage(null, "Account not found.");
} }
} }
} }
} }

View File

@ -1,29 +1,29 @@
package emu.grasscutter.command.commands; 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.GenshinPlayer;
import java.util.List; import java.util.List;
@Command(label = "broadcast", usage = "broadcast <message>", @Command(label = "broadcast", usage = "broadcast <message>",
description = "Sends a message to all the players", aliases = {"b"}, permission = "server.broadcast") description = "Sends a message to all the players", aliases = {"b"}, permission = "server.broadcast")
public class Broadcast implements CommandHandler { public final class BroadcastCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(GenshinPlayer sender, List<String> args) {
if (args.size() < 1) { if (args.size() < 1) {
CommandHandler.sendMessage(sender, "Usage: broadcast <message>"); CommandHandler.sendMessage(sender, "Usage: broadcast <message>");
return; return;
} }
String message = String.join(" ", args.subList(0, args.size())); String message = String.join(" ", args.subList(0, args.size()));
for (GenshinPlayer p : Grasscutter.getGameServer().getPlayers().values()) { for (GenshinPlayer p : Grasscutter.getGameServer().getPlayers().values()) {
CommandHandler.sendMessage(p, message); CommandHandler.sendMessage(p, message);
} }
CommandHandler.sendMessage(sender, "Message sent."); CommandHandler.sendMessage(sender, "Message sent.");
} }
} }

View File

@ -1,36 +1,36 @@
package emu.grasscutter.command.commands; 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.GenshinPlayer;
import java.util.List; import java.util.List;
@Command(label = "changescene", usage = "changescene <scene id>", @Command(label = "changescene", usage = "changescene <scene id>",
description = "Changes your scene", aliases = {"scene"}, permission = "player.changescene") description = "Changes your scene", aliases = {"scene"}, permission = "player.changescene")
public class ChangeScene implements CommandHandler { public final class ChangeSceneCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(GenshinPlayer 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 (args.size() < 1) { if (args.size() < 1) {
CommandHandler.sendMessage(sender, "Usage: changescene <scene id>"); CommandHandler.sendMessage(sender, "Usage: changescene <scene id>");
return; return;
} }
try { try {
int sceneId = Integer.parseInt(args.get(0)); int sceneId = Integer.parseInt(args.get(0));
boolean result = sender.getWorld().transferPlayerToScene(sender, sceneId, sender.getPos()); boolean result = sender.getWorld().transferPlayerToScene(sender, sceneId, sender.getPos());
CommandHandler.sendMessage(sender, "Changed to scene " + sceneId); CommandHandler.sendMessage(sender, "Changed to scene " + sceneId);
if (!result) { if (!result) {
CommandHandler.sendMessage(sender, "Scene does not exist or you are already in it"); CommandHandler.sendMessage(sender, "Scene does not exist or you are already in it");
} }
} catch (Exception e) { } catch (Exception e) {
CommandHandler.sendMessage(sender, "Usage: changescene <scene id>"); CommandHandler.sendMessage(sender, "Usage: changescene <scene id>");
} }
} }
} }

View File

@ -1,30 +1,30 @@
package emu.grasscutter.command.commands; 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.GenshinPlayer;
import emu.grasscutter.game.inventory.Inventory; import emu.grasscutter.game.inventory.Inventory;
import emu.grasscutter.game.inventory.ItemType; import emu.grasscutter.game.inventory.ItemType;
import java.util.List; import java.util.List;
@Command(label = "clearartifacts", usage = "clearartifacts", @Command(label = "clearartifacts", usage = "clearartifacts",
description = "Deletes all unequipped and unlocked level 0 artifacts, including yellow rarity ones from your inventory", description = "Deletes all unequipped and unlocked level 0 artifacts, including yellow rarity ones from your inventory",
aliases = {"clearart"}, permission = "player.clearartifacts") aliases = {"clearart"}, permission = "player.clearartifacts")
public class ClearArtifacts implements CommandHandler { public final class ClearArtifactsCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(GenshinPlayer 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: clear player's artifacts from console or other players return; // TODO: clear player's artifacts from console or other players
} }
Inventory playerInventory = sender.getInventory(); Inventory playerInventory = sender.getInventory();
playerInventory.getItems().values().stream() playerInventory.getItems().values().stream()
.filter(item -> item.getItemType() == ItemType.ITEM_RELIQUARY) .filter(item -> item.getItemType() == ItemType.ITEM_RELIQUARY)
.filter(item -> item.getLevel() == 1 && item.getExp() == 0) .filter(item -> item.getLevel() == 1 && item.getExp() == 0)
.filter(item -> !item.isLocked() && !item.isEquipped()) .filter(item -> !item.isLocked() && !item.isEquipped())
.forEach(item -> playerInventory.removeItem(item, item.getCount())); .forEach(item -> playerInventory.removeItem(item, item.getCount()));
} }
} }

View File

@ -1,56 +1,56 @@
package emu.grasscutter.command.commands; 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.GenshinData;
import emu.grasscutter.data.def.ItemData; import emu.grasscutter.data.def.ItemData;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.entity.EntityItem; import emu.grasscutter.game.entity.EntityItem;
import emu.grasscutter.utils.Position; import emu.grasscutter.utils.Position;
import java.util.List; import java.util.List;
@Command(label = "drop", usage = "drop <itemId|itemName> [amount]", @Command(label = "drop", usage = "drop <itemId|itemName> [amount]",
description = "Drops an item near you", aliases = {"d", "dropitem"}, permission = "server.drop") description = "Drops an item near you", aliases = {"d", "dropitem"}, permission = "server.drop")
public class Drop implements CommandHandler { public final class DropCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(GenshinPlayer 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 (args.size() < 1) { if (args.size() < 1) {
CommandHandler.sendMessage(sender, "Usage: drop <itemId|itemName> [amount]"); CommandHandler.sendMessage(sender, "Usage: drop <itemId|itemName> [amount]");
return; return;
} }
try { try {
int item = Integer.parseInt(args.get(0)); int item = Integer.parseInt(args.get(0));
int amount = 1; int amount = 1;
if (args.size() > 1) amount = Integer.parseInt(args.get(1)); if (args.size() > 1) amount = Integer.parseInt(args.get(1));
ItemData itemData = GenshinData.getItemDataMap().get(item); ItemData itemData = GenshinData.getItemDataMap().get(item);
if (itemData == null) { if (itemData == null) {
CommandHandler.sendMessage(sender, "Invalid item id."); CommandHandler.sendMessage(sender, "Invalid item id.");
return; return;
} }
if (itemData.isEquip()) { if (itemData.isEquip()) {
float range = (5f + (.1f * amount)); float range = (5f + (.1f * amount));
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
Position pos = sender.getPos().clone().addX((float) (Math.random() * range) - (range / 2)).addY(3f).addZ((float) (Math.random() * range) - (range / 2)); Position pos = sender.getPos().clone().addX((float) (Math.random() * range) - (range / 2)).addY(3f).addZ((float) (Math.random() * range) - (range / 2));
EntityItem entity = new EntityItem(sender.getScene(), sender, itemData, pos, 1); EntityItem entity = new EntityItem(sender.getScene(), sender, itemData, pos, 1);
sender.getScene().addEntity(entity); sender.getScene().addEntity(entity);
} }
} else { } else {
EntityItem entity = new EntityItem(sender.getScene(), sender, itemData, sender.getPos().clone().addY(3f), amount); EntityItem entity = new EntityItem(sender.getScene(), sender, itemData, sender.getPos().clone().addY(3f), amount);
sender.getScene().addEntity(entity); sender.getScene().addEntity(entity);
} }
CommandHandler.sendMessage(sender, String.format("Dropped %s of %s.", amount, item)); CommandHandler.sendMessage(sender, String.format("Dropped %s of %s.", amount, item));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid item or player ID."); CommandHandler.sendMessage(sender, "Invalid item or player ID.");
} }
} }
} }

View File

@ -1,93 +1,93 @@
package emu.grasscutter.command.commands; 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.GenshinData;
import emu.grasscutter.data.def.AvatarData; import emu.grasscutter.data.def.AvatarData;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.avatar.GenshinAvatar; import emu.grasscutter.game.avatar.GenshinAvatar;
import java.util.List; import java.util.List;
@Command(label = "givechar", usage = "givechar <playerId> <avatarId> [level]", @Command(label = "givechar", usage = "givechar <playerId> <avatarId> [level]",
description = "Gives the player a specified character", aliases = {"givec"}, permission = "player.givechar") description = "Gives the player a specified character", aliases = {"givec"}, permission = "player.givechar")
public class GiveChar implements CommandHandler { public final class GiveCharCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(GenshinPlayer sender, List<String> args) {
int target, avatarId, level = 1, ascension; int target, avatarId, level = 1, ascension;
if (sender == null && args.size() < 2) { if (sender == null && args.size() < 2) {
CommandHandler.sendMessage(null, "Usage: givechar <player> <itemId|itemName> [amount]"); CommandHandler.sendMessage(null, "Usage: givechar <player> <itemId|itemName> [amount]");
return; return;
} }
switch (args.size()) { switch (args.size()) {
default: default:
CommandHandler.sendMessage(sender, "Usage: givechar <player> <avatarId> [level]"); CommandHandler.sendMessage(sender, "Usage: givechar <player> <avatarId> [level]");
return; return;
case 2: case 2:
try { try {
target = Integer.parseInt(args.get(0)); target = Integer.parseInt(args.get(0));
if (Grasscutter.getGameServer().getPlayerByUid(target) == null && sender != null) { if (Grasscutter.getGameServer().getPlayerByUid(target) == null && sender != null) {
target = sender.getUid(); target = sender.getUid();
level = Integer.parseInt(args.get(1)); level = Integer.parseInt(args.get(1));
avatarId = Integer.parseInt(args.get(0)); avatarId = Integer.parseInt(args.get(0));
} else { } else {
avatarId = Integer.parseInt(args.get(1)); avatarId = Integer.parseInt(args.get(1));
} }
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
// TODO: Parse from avatar name using GM Handbook. // TODO: Parse from avatar name using GM Handbook.
CommandHandler.sendMessage(sender, "Invalid avatar or player ID."); CommandHandler.sendMessage(sender, "Invalid avatar or player ID.");
return; return;
} }
break; break;
case 3: case 3:
try { try {
target = Integer.parseInt(args.get(0)); target = Integer.parseInt(args.get(0));
if (Grasscutter.getGameServer().getPlayerByUid(target) == null) { if (Grasscutter.getGameServer().getPlayerByUid(target) == null) {
CommandHandler.sendMessage(sender, "Invalid player ID."); CommandHandler.sendMessage(sender, "Invalid player ID.");
return; return;
} }
avatarId = Integer.parseInt(args.get(1)); avatarId = Integer.parseInt(args.get(1));
level = Integer.parseInt(args.get(2)); level = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
// TODO: Parse from avatar name using GM Handbook. // TODO: Parse from avatar name using GM Handbook.
CommandHandler.sendMessage(sender, "Invalid avatar or player ID."); CommandHandler.sendMessage(sender, "Invalid avatar or player ID.");
return; return;
} }
break; break;
} }
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); GenshinPlayer 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;
} }
AvatarData avatarData = GenshinData.getAvatarDataMap().get(avatarId); AvatarData avatarData = GenshinData.getAvatarDataMap().get(avatarId);
if (avatarData == null) { if (avatarData == null) {
CommandHandler.sendMessage(sender, "Invalid avatar id."); CommandHandler.sendMessage(sender, "Invalid avatar id.");
return; return;
} }
// Calculate ascension level. // Calculate ascension level.
if (level <= 40) { if (level <= 40) {
ascension = (int) Math.ceil(level / 20f); ascension = (int) Math.ceil(level / 20f);
} else { } else {
ascension = (int) Math.ceil(level / 10f) - 3; ascension = (int) Math.ceil(level / 10f) - 3;
} }
GenshinAvatar avatar = new GenshinAvatar(avatarId); GenshinAvatar avatar = new GenshinAvatar(avatarId);
avatar.setLevel(level); avatar.setLevel(level);
avatar.setPromoteLevel(ascension); avatar.setPromoteLevel(ascension);
// This will handle stats and talents // This will handle stats and talents
avatar.recalcStats(); avatar.recalcStats();
targetPlayer.addAvatar(avatar); targetPlayer.addAvatar(avatar);
CommandHandler.sendMessage(sender, String.format("Given %s to %s.", avatarId, target)); CommandHandler.sendMessage(sender, String.format("Given %s to %s.", avatarId, target));
} }
} }

View File

@ -1,112 +1,112 @@
package emu.grasscutter.command.commands; 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.GenshinData;
import emu.grasscutter.data.def.ItemData; import emu.grasscutter.data.def.ItemData;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.inventory.GenshinItem; import emu.grasscutter.game.inventory.GenshinItem;
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;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@Command(label = "give", usage = "give [player] <itemId|itemName> [amount]", @Command(label = "give", usage = "give [player] <itemId|itemName> [amount]",
description = "Gives an item to you or the specified player", aliases = {"g", "item", "giveitem"}, permission = "player.give") description = "Gives an item to you or the specified player", aliases = {"g", "item", "giveitem"}, permission = "player.give")
public class Give implements CommandHandler { public final class GiveCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(GenshinPlayer sender, List<String> args) {
int target, item, amount = 1; int target, item, amount = 1;
if (sender == null && args.size() < 2) { if (sender == null && args.size() < 2) {
CommandHandler.sendMessage(null, "Usage: give <player> <itemId|itemName> [amount]"); CommandHandler.sendMessage(null, "Usage: give <player> <itemId|itemName> [amount]");
return; return;
} }
switch (args.size()) { switch (args.size()) {
default: // *No args* default: // *No args*
CommandHandler.sendMessage(sender, "Usage: give [player] <itemId|itemName> [amount]"); CommandHandler.sendMessage(sender, "Usage: give [player] <itemId|itemName> [amount]");
return; return;
case 1: // <itemId|itemName> case 1: // <itemId|itemName>
try { try {
item = Integer.parseInt(args.get(0)); item = Integer.parseInt(args.get(0));
target = sender.getUid(); target = sender.getUid();
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
// TODO: Parse from item name using GM Handbook. // TODO: Parse from item name using GM Handbook.
CommandHandler.sendMessage(sender, "Invalid item id."); CommandHandler.sendMessage(sender, "Invalid item id.");
return; return;
} }
break; break;
case 2: // <itemId|itemName> [amount] | [player] <itemId|itemName> case 2: // <itemId|itemName> [amount] | [player] <itemId|itemName>
try { try {
target = Integer.parseInt(args.get(0)); target = Integer.parseInt(args.get(0));
if (Grasscutter.getGameServer().getPlayerByUid(target) == null && sender != null) { if (Grasscutter.getGameServer().getPlayerByUid(target) == null && sender != null) {
target = sender.getUid(); target = sender.getUid();
item = Integer.parseInt(args.get(0)); item = Integer.parseInt(args.get(0));
amount = Integer.parseInt(args.get(1)); amount = Integer.parseInt(args.get(1));
} else { } else {
item = Integer.parseInt(args.get(1)); item = Integer.parseInt(args.get(1));
} }
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
// TODO: Parse from item name using GM Handbook. // TODO: Parse from item name using GM Handbook.
CommandHandler.sendMessage(sender, "Invalid item or player ID."); CommandHandler.sendMessage(sender, "Invalid item or player ID.");
return; return;
} }
break; break;
case 3: // [player] <itemId|itemName> [amount] case 3: // [player] <itemId|itemName> [amount]
try { try {
target = Integer.parseInt(args.get(0)); target = Integer.parseInt(args.get(0));
if (Grasscutter.getGameServer().getPlayerByUid(target) == null) { if (Grasscutter.getGameServer().getPlayerByUid(target) == null) {
CommandHandler.sendMessage(sender, "Invalid player ID."); CommandHandler.sendMessage(sender, "Invalid player ID.");
return; return;
} }
item = Integer.parseInt(args.get(1)); item = Integer.parseInt(args.get(1));
amount = Integer.parseInt(args.get(2)); amount = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
// TODO: Parse from item name using GM Handbook. // TODO: Parse from item name using GM Handbook.
CommandHandler.sendMessage(sender, "Invalid item or player ID."); CommandHandler.sendMessage(sender, "Invalid item or player ID.");
return; return;
} }
break; break;
} }
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); GenshinPlayer 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 = GenshinData.getItemDataMap().get(item);
if (itemData == null) { if (itemData == null) {
CommandHandler.sendMessage(sender, "Invalid item id."); CommandHandler.sendMessage(sender, "Invalid item id.");
return; return;
} }
this.item(targetPlayer, itemData, amount); this.item(targetPlayer, itemData, amount);
CommandHandler.sendMessage(sender, String.format("Given %s of %s to %s.", amount, item, target)); CommandHandler.sendMessage(sender, String.format("Given %s of %s to %s.", amount, item, target));
} }
private void item(GenshinPlayer player, ItemData itemData, int amount) { private void item(GenshinPlayer player, ItemData itemData, int amount) {
GenshinItem genshinItem = new GenshinItem(itemData); GenshinItem genshinItem = new GenshinItem(itemData);
if (itemData.isEquip()) { if (itemData.isEquip()) {
List<GenshinItem> items = new LinkedList<>(); List<GenshinItem> items = new LinkedList<>();
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
items.add(genshinItem); items.add(genshinItem);
} }
player.getInventory().addItems(items); player.getInventory().addItems(items);
player.sendPacket(new PacketItemAddHintNotify(items, ActionReason.SubfieldDrop)); player.sendPacket(new PacketItemAddHintNotify(items, ActionReason.SubfieldDrop));
} else { } else {
genshinItem.setCount(amount); genshinItem.setCount(amount);
player.getInventory().addItem(genshinItem); player.getInventory().addItem(genshinItem);
player.sendPacket(new PacketItemAddHintNotify(genshinItem, ActionReason.SubfieldDrop)); player.sendPacket(new PacketItemAddHintNotify(genshinItem, ActionReason.SubfieldDrop));
} }
} }
} }

View File

@ -1,22 +1,22 @@
package emu.grasscutter.command.commands; 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.GenshinPlayer;
import java.util.List; import java.util.List;
@Command(label = "godmode", usage = "godmode [playerId]", @Command(label = "godmode", usage = "godmode [playerId]",
description = "Prevents you from taking damage", permission = "player.godmode") description = "Prevents you from taking damage", permission = "player.godmode")
public class GodMode implements CommandHandler { public final class GodModeCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(GenshinPlayer 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
} }
sender.setGodmode(!sender.inGodmode()); sender.setGodmode(!sender.inGodmode());
sender.dropMessage("Godmode is now " + (sender.inGodmode() ? "enabled" : "disabled") + "."); sender.dropMessage("Godmode is now " + (sender.inGodmode() ? "enabled" : "disabled") + ".");
} }
} }

View File

@ -1,91 +1,91 @@
package emu.grasscutter.command.commands; 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.GenshinPlayer;
import java.util.*; import java.util.*;
@Command(label = "help", usage = "help [command]", @Command(label = "help", usage = "help [command]",
description = "Sends the help message or shows information about a specified command") description = "Sends the help message or shows information about a specified command")
public class Help implements CommandHandler { public final class HelpCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer player, List<String> args) { public void execute(GenshinPlayer 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<>();
for (String key : handlers.keySet()) { for (String key : handlers.keySet()) {
Command annotation = handlers.get(key).getClass().getAnnotation(Command.class); Command annotation = handlers.get(key).getClass().getAnnotation(Command.class);
if (!Arrays.asList(annotation.aliases()).contains(key)) { if (!Arrays.asList(annotation.aliases()).contains(key)) {
if (player != null && !Objects.equals(annotation.permission(), "") && !player.getAccount().hasPermission(annotation.permission())) if (player != null && !Objects.equals(annotation.permission(), "") && !player.getAccount().hasPermission(annotation.permission()))
continue; continue;
annotations.add(annotation); annotations.add(annotation);
} }
} }
SendAllHelpMessage(player, annotations); SendAllHelpMessage(player, annotations);
} else { } else {
String command = args.get(0); String command = args.get(0);
CommandHandler handler = CommandMap.getInstance().getHandler(command); CommandHandler handler = CommandMap.getInstance().getHandler(command);
StringBuilder builder = new StringBuilder(player == null ? "\nHelp - " : "Help - ").append(command).append(": \n"); StringBuilder builder = new StringBuilder(player == null ? "\nHelp - " : "Help - ").append(command).append(": \n");
if (handler == null) { if (handler == null) {
builder.append("No command found."); builder.append("No command found.");
} else { } else {
Command annotation = handler.getClass().getAnnotation(Command.class); Command annotation = handler.getClass().getAnnotation(Command.class);
builder.append(" ").append(annotation.description()).append("\n"); builder.append(" ").append(annotation.description()).append("\n");
builder.append(" Usage: ").append(annotation.usage()); builder.append(" Usage: ").append(annotation.usage());
if (annotation.aliases().length >= 1) { if (annotation.aliases().length >= 1) {
builder.append("\n").append(" Aliases: "); builder.append("\n").append(" Aliases: ");
for (String alias : annotation.aliases()) { for (String alias : annotation.aliases()) {
builder.append(alias).append(" "); builder.append(alias).append(" ");
} }
} }
if (player != null && !Objects.equals(annotation.permission(), "") && !player.getAccount().hasPermission(annotation.permission())) { if (player != null && !Objects.equals(annotation.permission(), "") && !player.getAccount().hasPermission(annotation.permission())) {
builder.append("\n Warning: You do not have permission to run this command."); builder.append("\n Warning: You do not have permission to run this command.");
} }
} }
CommandHandler.sendMessage(player, builder.toString()); CommandHandler.sendMessage(player, builder.toString());
} }
} }
void SendAllHelpMessage(GenshinPlayer player, List<Command> annotations) { void SendAllHelpMessage(GenshinPlayer 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 -> {
builder.append(annotation.label()).append("\n"); builder.append(annotation.label()).append("\n");
builder.append(" ").append(annotation.description()).append("\n"); builder.append(" ").append(annotation.description()).append("\n");
builder.append(" Usage: ").append(annotation.usage()); builder.append(" Usage: ").append(annotation.usage());
if (annotation.aliases().length >= 1) { if (annotation.aliases().length >= 1) {
builder.append("\n").append(" Aliases: "); builder.append("\n").append(" Aliases: ");
for (String alias : annotation.aliases()) { for (String alias : annotation.aliases()) {
builder.append(alias).append(" "); builder.append(alias).append(" ");
} }
} }
builder.append("\n"); builder.append("\n");
}); });
CommandHandler.sendMessage(null, builder.toString()); CommandHandler.sendMessage(null, builder.toString());
} else { } else {
CommandHandler.sendMessage(player, "Available commands:"); CommandHandler.sendMessage(player, "Available commands:");
annotations.forEach(annotation -> { annotations.forEach(annotation -> {
StringBuilder builder = new StringBuilder(annotation.label()).append("\n"); StringBuilder builder = new StringBuilder(annotation.label()).append("\n");
builder.append(" ").append(annotation.description()).append("\n"); builder.append(" ").append(annotation.description()).append("\n");
builder.append(" Usage: ").append(annotation.usage()); builder.append(" Usage: ").append(annotation.usage());
if (annotation.aliases().length >= 1) { if (annotation.aliases().length >= 1) {
builder.append("\n").append(" Aliases: "); builder.append("\n").append(" Aliases: ");
for (String alias : annotation.aliases()) { for (String alias : annotation.aliases()) {
builder.append(alias).append(" "); builder.append(alias).append(" ");
} }
} }
CommandHandler.sendMessage(player, builder.toString()); CommandHandler.sendMessage(player, builder.toString());
}); });
} }
} }
} }

View File

@ -1,31 +1,31 @@
package emu.grasscutter.command.commands; 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.GenshinPlayer;
import java.util.List; import java.util.List;
@Command(label = "kick", usage = "kick <player>", @Command(label = "kick", usage = "kick <player>",
description = "Kicks the specified player from the server (WIP)", permission = "server.kick") description = "Kicks the specified player from the server (WIP)", permission = "server.kick")
public class Kick implements CommandHandler { public final class KickCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(GenshinPlayer sender, List<String> args) {
int target = Integer.parseInt(args.get(0)); int target = Integer.parseInt(args.get(0));
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); GenshinPlayer 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;
} }
if (sender != null) { if (sender != null) {
CommandHandler.sendMessage(sender, String.format("Player [%s:%s] has kicked player [%s:%s]", sender.getAccount().getPlayerId(), sender.getAccount().getUsername(), target, targetPlayer.getAccount().getUsername())); CommandHandler.sendMessage(sender, String.format("Player [%s:%s] has kicked player [%s:%s]", sender.getAccount().getPlayerId(), sender.getAccount().getUsername(), target, targetPlayer.getAccount().getUsername()));
} }
CommandHandler.sendMessage(sender, String.format("Kicking player [%s:%s]", target, targetPlayer.getAccount().getUsername())); CommandHandler.sendMessage(sender, String.format("Kicking player [%s:%s]", target, targetPlayer.getAccount().getUsername()));
targetPlayer.getSession().close(); targetPlayer.getSession().close();
} }
} }

View File

@ -1,64 +1,64 @@
package emu.grasscutter.command.commands; 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.GenshinPlayer;
import emu.grasscutter.game.GenshinScene; import emu.grasscutter.game.GenshinScene;
import emu.grasscutter.game.entity.EntityMonster; import emu.grasscutter.game.entity.EntityMonster;
import java.util.List; import java.util.List;
@Command(label = "killall", usage = "killall [playerUid] [sceneId]", @Command(label = "killall", usage = "killall [playerUid] [sceneId]",
description = "Kill all entities", permission = "server.killall") description = "Kill all entities", permission = "server.killall")
public class KillAll implements CommandHandler { public final class KillAllCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(GenshinPlayer sender, List<String> args) {
GenshinScene scene; GenshinScene scene;
GenshinPlayer genshinPlayer; GenshinPlayer genshinPlayer;
try { try {
switch (args.size()) { switch (args.size()) {
case 0: // *No args* case 0: // *No args*
if (sender == null) { if (sender == null) {
CommandHandler.sendMessage(null, "Usage: killall [playerUid] [sceneId]"); CommandHandler.sendMessage(null, "Usage: killall [playerUid] [sceneId]");
return; return;
} }
scene = sender.getScene(); scene = sender.getScene();
break; break;
case 1: // [playerUid] case 1: // [playerUid]
genshinPlayer = Grasscutter.getGameServer().getPlayerByUid(Integer.parseInt(args.get(0))); genshinPlayer = Grasscutter.getGameServer().getPlayerByUid(Integer.parseInt(args.get(0)));
if (genshinPlayer == null) { if (genshinPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found or offline."); CommandHandler.sendMessage(sender, "Player not found or offline.");
return; return;
} }
scene = genshinPlayer.getScene(); scene = genshinPlayer.getScene();
break; break;
case 2: // [playerUid] [sceneId] case 2: // [playerUid] [sceneId]
genshinPlayer = Grasscutter.getGameServer().getPlayerByUid(Integer.parseInt(args.get(0))); genshinPlayer = Grasscutter.getGameServer().getPlayerByUid(Integer.parseInt(args.get(0)));
if (genshinPlayer == null) { if (genshinPlayer == 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))); GenshinScene genshinScene = sender.getWorld().getSceneById(Integer.parseInt(args.get(1)));
if (genshinScene == null) { if (genshinScene == null) {
CommandHandler.sendMessage(sender, "Scene not found in player world"); CommandHandler.sendMessage(sender, "Scene not found in player world");
return; return;
} }
scene = genshinScene; scene = genshinScene;
break; break;
default: default:
CommandHandler.sendMessage(sender, "Usage: killall [playerUid] [sceneId]"); CommandHandler.sendMessage(sender, "Usage: killall [playerUid] [sceneId]");
return; return;
} }
scene.getEntities().values().stream() scene.getEntities().values().stream()
.filter(entity -> entity instanceof EntityMonster) .filter(entity -> entity instanceof EntityMonster)
.forEach(entity -> scene.killEntity(entity, 0)); .forEach(entity -> scene.killEntity(entity, 0));
CommandHandler.sendMessage(sender, "Killing all monsters in scene " + scene.getId()); CommandHandler.sendMessage(sender, "Killing all monsters in scene " + scene.getId());
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid arguments."); CommandHandler.sendMessage(sender, "Invalid arguments.");
} }
} }
} }

View File

@ -1,50 +1,50 @@
package emu.grasscutter.command.commands; 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.Account; import emu.grasscutter.game.Account;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.GenshinPlayer;
import java.util.List; import java.util.List;
@Command(label = "permission", usage = "permission <add|remove> <username> <permission>", @Command(label = "permission", usage = "permission <add|remove> <username> <permission>",
description = "Grants or removes a permission for a user", permission = "*") description = "Grants or removes a permission for a user", permission = "*")
public class Permission implements CommandHandler { public final class PermissionCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(GenshinPlayer 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;
} }
String action = args.get(0); String action = args.get(0);
String username = args.get(1); String username = args.get(1);
String permission = args.get(2); String permission = args.get(2);
Account account = Grasscutter.getGameServer().getAccountByName(username); Account account = Grasscutter.getGameServer().getAccountByName(username);
if (account == null) { if (account == null) {
CommandHandler.sendMessage(sender, "Account not found."); CommandHandler.sendMessage(sender, "Account not found.");
return; return;
} }
switch (action) { switch (action) {
default: default:
CommandHandler.sendMessage(sender, "Usage: permission <add|remove> <username> <permission>"); CommandHandler.sendMessage(sender, "Usage: permission <add|remove> <username> <permission>");
break; break;
case "add": case "add":
if (account.addPermission(permission)) { if (account.addPermission(permission)) {
CommandHandler.sendMessage(sender, "Permission added."); CommandHandler.sendMessage(sender, "Permission added.");
} else CommandHandler.sendMessage(sender, "They already have this permission!"); } else CommandHandler.sendMessage(sender, "They already have this permission!");
break; break;
case "remove": case "remove":
if (account.removePermission(permission)) { if (account.removePermission(permission)) {
CommandHandler.sendMessage(sender, "Permission removed."); CommandHandler.sendMessage(sender, "Permission removed.");
} else CommandHandler.sendMessage(sender, "They don't have this permission!"); } else CommandHandler.sendMessage(sender, "They don't have this permission!");
break; break;
} }
account.save(); account.save();
} }
} }

View File

@ -1,22 +1,22 @@
package emu.grasscutter.command.commands; 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.GenshinPlayer;
import java.util.List; import java.util.List;
@Command(label = "pos", usage = "pos", @Command(label = "position", usage = "position", aliases = {"pos"},
description = "Get coordinates.") description = "Get coordinates.")
public class Pos implements CommandHandler { public final class PositionCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(GenshinPlayer 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;
} }
sender.dropMessage(String.format("Coord: %.3f, %.3f, %.3f", sender.getPos().getX(), sender.getPos().getY(), sender.getPos().getZ())); sender.dropMessage(String.format("Coord: %.3f, %.3f, %.3f", sender.getPos().getX(), sender.getPos().getY(), sender.getPos().getZ()));
} }
} }

View File

@ -1,22 +1,22 @@
package emu.grasscutter.command.commands; 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.GenshinPlayer;
import java.util.List; import java.util.List;
@Command(label = "reload", usage = "reload", @Command(label = "reload", usage = "reload",
description = "Reload server config", permission = "server.reload") description = "Reload server config", permission = "server.reload")
public class Reload implements CommandHandler { public final class ReloadCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(GenshinPlayer 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.getDispatchServer().loadQueries(); Grasscutter.getDispatchServer().loadQueries();
CommandHandler.sendMessage(sender, "Reload complete."); CommandHandler.sendMessage(sender, "Reload complete.");
} }
} }

View File

@ -1,45 +1,45 @@
package emu.grasscutter.command.commands; 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.GenshinPlayer;
import emu.grasscutter.game.avatar.GenshinAvatar; import emu.grasscutter.game.avatar.GenshinAvatar;
import emu.grasscutter.game.entity.EntityAvatar; import emu.grasscutter.game.entity.EntityAvatar;
import java.util.List; import java.util.List;
@Command(label = "resetconst", usage = "resetconst [all]", @Command(label = "resetconst", usage = "resetconst [all]",
description = "Resets the constellation level on your current active character, will need to relog after using the command to see any changes.", description = "Resets the constellation level on your current active character, will need to relog after using the command to see any changes.",
aliases = {"resetconstellation"}, permission = "player.resetconstellation") aliases = {"resetconstellation"}, permission = "player.resetconstellation")
public class ResetConst implements CommandHandler { public final class ResetConstCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(GenshinPlayer 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 (args.size() > 0 && args.get(0).equalsIgnoreCase("all")) { if (args.size() > 0 && args.get(0).equalsIgnoreCase("all")) {
sender.getAvatars().forEach(this::resetConstellation); sender.getAvatars().forEach(this::resetConstellation);
sender.dropMessage("Reset all avatars' constellations."); sender.dropMessage("Reset all avatars' constellations.");
} else { } else {
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
if (entity == null) { if (entity == null) {
return; return;
} }
GenshinAvatar avatar = entity.getAvatar(); GenshinAvatar 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(GenshinAvatar avatar) {
avatar.getTalentIdList().clear(); avatar.getTalentIdList().clear();
avatar.setCoreProudSkillLevel(0); avatar.setCoreProudSkillLevel(0);
avatar.recalcStats(); avatar.recalcStats();
avatar.save(); avatar.save();
} }
} }

View File

@ -1,16 +1,16 @@
package emu.grasscutter.command.commands; 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.GenshinPlayer;
import java.util.List; import java.util.List;
@Command(label = "restart", usage = "restart - Restarts the current session") @Command(label = "restart", usage = "restart - Restarts the current session")
public class Restart implements CommandHandler { public final class RestartCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(GenshinPlayer sender, List<String> args) {
sender.getSession().close(); sender.getSession().close();
} }
} }

View File

@ -1,37 +1,37 @@
package emu.grasscutter.command.commands; 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.GenshinPlayer;
import java.util.List; import java.util.List;
@Command(label = "say", usage = "say <player> <message>", description = "Sends a message to a player as the server", @Command(label = "say", usage = "say <player> <message>", description = "Sends a message to a player as the server",
aliases = {"sendservmsg", "sendservermessage", "sendmessage"}, permission = "server.sendmessage") aliases = {"sendservmsg", "sendservermessage", "sendmessage"}, permission = "server.sendmessage")
public class SendMessage implements CommandHandler { public final class SendMessageCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(GenshinPlayer 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;
} }
try { try {
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); GenshinPlayer 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;
} }
CommandHandler.sendMessage(targetPlayer, message); CommandHandler.sendMessage(targetPlayer, message);
CommandHandler.sendMessage(sender, "Message sent."); CommandHandler.sendMessage(sender, "Message sent.");
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid player ID."); CommandHandler.sendMessage(sender, "Invalid player ID.");
} }
} }
} }

View File

@ -1,120 +1,120 @@
package emu.grasscutter.command.commands; 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.GenshinPlayer;
import emu.grasscutter.game.entity.EntityAvatar; import emu.grasscutter.game.entity.EntityAvatar;
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;
import java.util.List; import java.util.List;
@Command(label = "setstats", usage = "setstats <hp|def|atk|em|er|crate|cdmg> <value>", @Command(label = "setstats", usage = "setstats <hp|def|atk|em|er|crate|cdmg> <value>",
aliases = {"stats"}) aliases = {"stats"})
public class SetStats implements CommandHandler { public final class SetStatsCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(GenshinPlayer 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;
} }
String stat = args.get(0); String stat = args.get(0);
switch (stat) { switch (stat) {
default: default:
CommandHandler.sendMessage(sender, "Usage: setstats|stats <hp|def|atk|em|er|crate|cdmg> <value>"); CommandHandler.sendMessage(sender, "Usage: setstats|stats <hp|def|atk|em|er|crate|cdmg> <value>");
return; return;
case "hp": case "hp":
try { try {
int health = Integer.parseInt(args.get(1)); int health = Integer.parseInt(args.get(1));
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, health); entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, health);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_HP)); entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_HP));
CommandHandler.sendMessage(sender, "HP set to " + health + "."); CommandHandler.sendMessage(sender, "HP set to " + health + ".");
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid HP value."); CommandHandler.sendMessage(sender, "Invalid HP value.");
return; return;
} }
break; break;
case "def": case "def":
try { try {
int def = Integer.parseInt(args.get(1)); int def = Integer.parseInt(args.get(1));
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_DEFENSE, def); entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_DEFENSE, def);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_DEFENSE)); entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_DEFENSE));
CommandHandler.sendMessage(sender, "DEF set to " + def + "."); CommandHandler.sendMessage(sender, "DEF set to " + def + ".");
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid DEF value."); CommandHandler.sendMessage(sender, "Invalid DEF value.");
return; return;
} }
break; break;
case "atk": case "atk":
try { try {
int atk = Integer.parseInt(args.get(1)); int atk = Integer.parseInt(args.get(1));
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_ATTACK, atk); entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_ATTACK, atk);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_ATTACK)); entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_ATTACK));
CommandHandler.sendMessage(sender, "ATK set to " + atk + "."); CommandHandler.sendMessage(sender, "ATK set to " + atk + ".");
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid ATK value."); CommandHandler.sendMessage(sender, "Invalid ATK value.");
return; return;
} }
break; break;
case "em": case "em":
try { try {
int em = Integer.parseInt(args.get(1)); int em = Integer.parseInt(args.get(1));
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
entity.setFightProperty(FightProperty.FIGHT_PROP_ELEMENT_MASTERY, em); entity.setFightProperty(FightProperty.FIGHT_PROP_ELEMENT_MASTERY, em);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_ELEMENT_MASTERY)); entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_ELEMENT_MASTERY));
CommandHandler.sendMessage(sender, "Elemental Mastery set to " + em + "."); CommandHandler.sendMessage(sender, "Elemental Mastery set to " + em + ".");
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid EM value."); CommandHandler.sendMessage(sender, "Invalid EM value.");
return; return;
} }
break; break;
case "er": case "er":
try { try {
float er = Integer.parseInt(args.get(1)); float er = Integer.parseInt(args.get(1));
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
float erecharge = er / 10000; float erecharge = er / 10000;
entity.setFightProperty(FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY, erecharge); entity.setFightProperty(FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY, erecharge);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY)); entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY));
float iger = erecharge * 100; float iger = erecharge * 100;
CommandHandler.sendMessage(sender, "Energy recharge set to " + iger + "%."); CommandHandler.sendMessage(sender, "Energy recharge set to " + iger + "%.");
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid ER value."); CommandHandler.sendMessage(sender, "Invalid ER value.");
return; return;
} }
break; break;
case "crate": case "crate":
try { try {
float cr = Integer.parseInt(args.get(1)); float cr = Integer.parseInt(args.get(1));
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
float crate = cr / 10000; float crate = cr / 10000;
entity.setFightProperty(FightProperty.FIGHT_PROP_CRITICAL, crate); entity.setFightProperty(FightProperty.FIGHT_PROP_CRITICAL, crate);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CRITICAL)); entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CRITICAL));
float igcrate = crate * 100; float igcrate = crate * 100;
CommandHandler.sendMessage(sender, "Crit Rate set to " + igcrate + "%."); CommandHandler.sendMessage(sender, "Crit Rate set to " + igcrate + "%.");
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid Crit Rate value."); CommandHandler.sendMessage(sender, "Invalid Crit Rate value.");
return; return;
} }
break; break;
case "cdmg": case "cdmg":
try { try {
float cdmg = Integer.parseInt(args.get(1)); float cdmg = Integer.parseInt(args.get(1));
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
float cdamage = cdmg / 10000; float cdamage = cdmg / 10000;
entity.setFightProperty(FightProperty.FIGHT_PROP_CRITICAL_HURT, cdamage); entity.setFightProperty(FightProperty.FIGHT_PROP_CRITICAL_HURT, cdamage);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CRITICAL_HURT)); entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CRITICAL_HURT));
float igcdmg = cdamage * 100; float igcdmg = cdamage * 100;
CommandHandler.sendMessage(sender, "Crit DMG set to " + igcdmg + "%"); CommandHandler.sendMessage(sender, "Crit DMG set to " + igcdmg + "%");
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid Crit DMG value."); CommandHandler.sendMessage(sender, "Invalid Crit DMG value.");
return; return;
} }
break; break;
} }
} }
} }

View File

@ -1,39 +1,39 @@
package emu.grasscutter.command.commands; 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.GenshinPlayer;
import emu.grasscutter.game.props.PlayerProperty; import emu.grasscutter.game.props.PlayerProperty;
import java.util.List; import java.util.List;
@Command(label = "setworldlevel", usage = "setworldlevel <level>", @Command(label = "setworldlevel", usage = "setworldlevel <level>",
description = "Sets your world level (Relog to see proper effects)", description = "Sets your world level (Relog to see proper effects)",
aliases = {"setworldlvl"}, permission = "player.setworldlevel") aliases = {"setworldlvl"}, permission = "player.setworldlevel")
public class SetWorldLevel implements CommandHandler { public final class SetWorldLevelCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(GenshinPlayer 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
} }
if (args.size() < 1) { if (args.size() < 1) {
CommandHandler.sendMessage(sender, "Usage: setworldlevel <level>"); CommandHandler.sendMessage(sender, "Usage: setworldlevel <level>");
return; return;
} }
try { try {
int level = Integer.parseInt(args.get(0)); int level = Integer.parseInt(args.get(0));
// 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.setProperty(PlayerProperty.PROP_PLAYER_WORLD_LEVEL, level);
sender.dropMessage("World level set to " + level + "."); sender.dropMessage("World level set to " + level + ".");
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(null, "Invalid world level."); CommandHandler.sendMessage(null, "Invalid world level.");
} }
} }
} }

View File

@ -1,51 +1,51 @@
package emu.grasscutter.command.commands; 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.GenshinData;
import emu.grasscutter.data.def.MonsterData; import emu.grasscutter.data.def.MonsterData;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.entity.EntityMonster; import emu.grasscutter.game.entity.EntityMonster;
import emu.grasscutter.utils.Position; import emu.grasscutter.utils.Position;
import java.util.List; import java.util.List;
@Command(label = "spawn", usage = "spawn <entityId|entityName> [level] [amount]", @Command(label = "spawn", usage = "spawn <entityId|entityName> [level] [amount]",
description = "Spawns an entity near you", permission = "server.spawn") description = "Spawns an entity near you", permission = "server.spawn")
public class Spawn implements CommandHandler { public final class SpawnCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(GenshinPlayer 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 (args.size() < 1) { if (args.size() < 1) {
CommandHandler.sendMessage(sender, "Usage: spawn <entityId|entityName> [amount]"); CommandHandler.sendMessage(sender, "Usage: spawn <entityId|entityName> [amount]");
return; return;
} }
try { try {
int entity = Integer.parseInt(args.get(0)); int entity = Integer.parseInt(args.get(0));
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 = GenshinData.getMonsterDataMap().get(entity);
if (entityData == null) { if (entityData == null) {
CommandHandler.sendMessage(sender, "Invalid entity id."); CommandHandler.sendMessage(sender, "Invalid entity id.");
return; return;
} }
float range = (5f + (.1f * amount)); float range = (5f + (.1f * amount));
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
Position pos = sender.getPos().clone().addX((float) (Math.random() * range) - (range / 2)).addY(3f).addZ((float) (Math.random() * range) - (range / 2)); Position pos = sender.getPos().clone().addX((float) (Math.random() * range) - (range / 2)).addY(3f).addZ((float) (Math.random() * range) - (range / 2));
EntityMonster monster = new EntityMonster(sender.getScene(), entityData, pos, level); EntityMonster monster = new EntityMonster(sender.getScene(), entityData, pos, level);
sender.getScene().addEntity(monster); sender.getScene().addEntity(monster);
} }
CommandHandler.sendMessage(sender, String.format("Spawned %s of %s.", amount, entity)); CommandHandler.sendMessage(sender, String.format("Spawned %s of %s.", amount, entity));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid item or player ID."); CommandHandler.sendMessage(sender, "Invalid item or player ID.");
} }
} }
} }

View File

@ -1,23 +1,23 @@
package emu.grasscutter.command.commands; 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.GenshinPlayer;
import java.util.List; import java.util.List;
@Command(label = "stop", usage = "stop", @Command(label = "stop", usage = "stop",
description = "Stops the server", permission = "server.stop") description = "Stops the server", permission = "server.stop")
public class Stop implements CommandHandler { public final class StopCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(GenshinPlayer sender, List<String> args) {
CommandHandler.sendMessage(null, "Server shutting down..."); CommandHandler.sendMessage(null, "Server shutting down...");
for (GenshinPlayer p : Grasscutter.getGameServer().getPlayers().values()) { for (GenshinPlayer p : Grasscutter.getGameServer().getPlayers().values()) {
CommandHandler.sendMessage(p, "Server shutting down..."); CommandHandler.sendMessage(p, "Server shutting down...");
} }
System.exit(1); System.exit(1);
} }
} }

View File

@ -1,39 +1,39 @@
package emu.grasscutter.command.commands; 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.GenshinPlayer;
import emu.grasscutter.game.props.ClimateType; import emu.grasscutter.game.props.ClimateType;
import emu.grasscutter.server.packet.send.PacketSceneAreaWeatherNotify; import emu.grasscutter.server.packet.send.PacketSceneAreaWeatherNotify;
import java.util.List; import java.util.List;
@Command(label = "weather", usage = "weather <weatherId>", @Command(label = "weather", usage = "weather <weatherId>",
description = "Changes the weather.", aliases = {"w"}, permission = "player.weather") description = "Changes the weather.", aliases = {"w"}, permission = "player.weather")
public class Weather implements CommandHandler { public final class WeatherCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer sender, List<String> args) { public void execute(GenshinPlayer 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 (args.size() < 1) { if (args.size() < 1) {
CommandHandler.sendMessage(sender, "Usage: weather <weatherId>"); CommandHandler.sendMessage(sender, "Usage: weather <weatherId>");
return; return;
} }
try { try {
int weatherId = Integer.parseInt(args.get(0)); int weatherId = Integer.parseInt(args.get(0));
ClimateType climate = ClimateType.getTypeByValue(weatherId); ClimateType climate = ClimateType.getTypeByValue(weatherId);
sender.getScene().setClimate(climate); sender.getScene().setClimate(climate);
sender.getScene().broadcastPacket(new PacketSceneAreaWeatherNotify(sender)); sender.getScene().broadcastPacket(new PacketSceneAreaWeatherNotify(sender));
CommandHandler.sendMessage(sender, "Changed weather to " + weatherId); CommandHandler.sendMessage(sender, "Changed weather to " + weatherId);
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid weather ID."); CommandHandler.sendMessage(sender, "Invalid weather ID.");
} }
} }
} }