Add existing commands

This commit is contained in:
KingRainbow44 2022-04-18 22:10:41 -04:00
parent 61c0ff36e7
commit b35ee455e5
5 changed files with 431 additions and 299 deletions

View File

@ -1,21 +1,17 @@
package emu.grasscutter.commands; package emu.grasscutter.commands;
import java.lang.reflect.Modifier; import emu.grasscutter.Grasscutter;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
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.data.def.MonsterData; import emu.grasscutter.data.def.MonsterData;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.World;
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 emu.grasscutter.game.entity.EntityItem; import emu.grasscutter.game.entity.EntityItem;
import emu.grasscutter.game.entity.EntityMonster; import emu.grasscutter.game.entity.EntityMonster;
import emu.grasscutter.game.entity.GenshinEntity;
import emu.grasscutter.game.inventory.GenshinItem; import emu.grasscutter.game.inventory.GenshinItem;
import emu.grasscutter.game.inventory.Inventory;
import emu.grasscutter.game.inventory.ItemType; import emu.grasscutter.game.inventory.ItemType;
import emu.grasscutter.game.props.ActionReason; import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.game.props.FightProperty; import emu.grasscutter.game.props.FightProperty;
@ -23,306 +19,302 @@ import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify;
import emu.grasscutter.server.packet.send.PacketItemAddHintNotify; import emu.grasscutter.server.packet.send.PacketItemAddHintNotify;
import emu.grasscutter.utils.Position; import emu.grasscutter.utils.Position;
public class PlayerCommands { import java.util.LinkedList;
private static HashMap<String, PlayerCommand> commandList = new HashMap<String, PlayerCommand>(); import java.util.List;
private static HashMap<String, PlayerCommand> commandAliasList = new HashMap<String, PlayerCommand>();
/**
static { * A container for player-related commands.
try { */
// Look for classes public final class PlayerCommands {
for (Class<?> cls : PlayerCommands.class.getDeclaredClasses()) { @Command(label = "give", aliases = {"g", "item", "giveitem"},
// Get non abstract classes usage = "Usage: give [player] <itemId|itemName> [amount]")
if (!Modifier.isAbstract(cls.getModifiers())) { public static class GiveCommand implements CommandHandler {
Command commandAnnotation = cls.getAnnotation(Command.class);
PlayerCommand command = (PlayerCommand) cls.newInstance();
if (commandAnnotation != null) {
command.setLevel(commandAnnotation.gmLevel());
command.setHelpText(commandAnnotation.helpText());
for (String alias : commandAnnotation.aliases()) {
if (alias.length() == 0) {
continue;
}
String commandName = alias; @Override
commandAliasList.put(commandName, command); public void execute(GenshinPlayer player, List<String> args) {
} int target, item, amount = 1;
}
String commandName = cls.getSimpleName().toLowerCase(); switch(args.size()) {
commandList.put(commandName, command); default:
} CommandHandler.sendMessage(player, "Usage: give <player> <itemId|itemName> [amount]");
return;
} case 1:
} catch (Exception e) { try {
item = Integer.parseInt(args.get(0));
} target = player.getId();
} } catch (NumberFormatException ignored) {
// TODO: Parse from item name using GM Handbook.
CommandHandler.sendMessage(player, "Invalid item id.");
return;
}
break;
case 2:
try {
target = Integer.parseInt(args.get(0));
if(Grasscutter.getGameServer().getPlayerById(target) == null) {
target = player.getId(); amount = Integer.parseInt(args.get(1));
item = Integer.parseInt(args.get(0));
} else {
item = Integer.parseInt(args.get(1));
}
} catch (NumberFormatException ignored) {
// TODO: Parse from item name using GM Handbook.
CommandHandler.sendMessage(player, "Invalid item or player ID.");
return;
}
break;
case 3:
try {
target = Integer.parseInt(args.get(0));
if(Grasscutter.getGameServer().getPlayerById(target) == null) {
CommandHandler.sendMessage(player, "Invalid player ID."); return;
}
public static void handle(GenshinPlayer player, String msg) { item = Integer.parseInt(args.get(1));
String[] split = msg.split(" "); amount = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) {
// End if invalid // TODO: Parse from item name using GM Handbook.
if (split.length == 0) { CommandHandler.sendMessage(player, "Invalid item or player ID.");
return; return;
} }
break;
}
String first = split[0].toLowerCase().substring(1); GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerById(target);
PlayerCommand c = PlayerCommands.commandList.get(first); if(targetPlayer == null) {
PlayerCommand a = PlayerCommands.commandAliasList.get(first); CommandHandler.sendMessage(player, "Player not found."); return;
}
if (c != null || a != null) {
PlayerCommand cmd = c != null ? c : a;
// Level check
if (player.getGmLevel() < cmd.getLevel()) {
return;
}
// Execute
int len = Math.min(split[0].length() + 1, msg.length());
cmd.execute(player, msg.substring(len));
}
}
public static abstract class PlayerCommand {
// GM level required to use this command
private int level;
private String helpText;
protected int getLevel() { return this.level; } ItemData itemData = GenshinData.getItemDataMap().get(item);
protected void setLevel(int minLevel) { this.level = minLevel; } if(itemData == null) {
CommandHandler.sendMessage(player, "Invalid item id."); return;
}
this.item(targetPlayer, itemData, amount);
}
protected String getHelpText() { return this.helpText; } /**
protected void setHelpText(String helpText) { this.helpText = helpText; } * give [player] [itemId|itemName] [amount]
*/
@Override public void execute(List<String> args) {
if(args.size() < 2) {
CommandHandler.sendMessage(null, "Usage: give <player> <itemId|itemName> [amount]");
return;
}
// Main try {
public abstract void execute(GenshinPlayer player, String raw); int target = Integer.parseInt(args.get(0));
} int item = Integer.parseInt(args.get(1));
int amount = 1; if(args.size() > 2) amount = Integer.parseInt(args.get(2));
// ================ Commands ================
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerById(target);
if(targetPlayer == null) {
CommandHandler.sendMessage(null, "Player not found."); return;
}
ItemData itemData = GenshinData.getItemDataMap().get(item);
if(itemData == null) {
CommandHandler.sendMessage(null, "Invalid item id."); return;
}
this.item(targetPlayer, itemData, amount);
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(null, "Invalid item or player ID.");
}
}
private void item(GenshinPlayer player, ItemData itemData, int amount) {
GenshinItem genshinItem = new GenshinItem(itemData);
if(itemData.isEquip()) {
List<GenshinItem> items = new LinkedList<>();
for(int i = 0; i < amount; i++) {
items.add(genshinItem);
} player.getInventory().addItems(items);
player.sendPacket(new PacketItemAddHintNotify(items, ActionReason.SubfieldDrop));
} else {
genshinItem.setCount(amount);
player.getInventory().addItem(genshinItem);
player.sendPacket(new PacketItemAddHintNotify(genshinItem, ActionReason.SubfieldDrop));
}
}
}
@Command(label = "drop", aliases = {"d", "dropitem"},
usage = "Usage: drop <itemId|itemName> [amount]",
execution = Command.Execution.PLAYER)
public static class DropCommand implements CommandHandler {
@Command(aliases = {"h"}, helpText = "Shows this command") @Override
public static class Help extends PlayerCommand { public void execute(GenshinPlayer player, List<String> args) {
if(args.size() < 1) {
CommandHandler.sendMessage(null, "Usage: drop <itemId|itemName> [amount]");
return;
}
@Override try {
public void execute(GenshinPlayer player, String raw) { int item = Integer.parseInt(args.get(0));
String helpMessage = "Grasscutter Commands: "; int amount = 1; if(args.size() > 1) amount = Integer.parseInt(args.get(1));
for (Map.Entry<String, PlayerCommand> cmd : commandList.entrySet()) {
helpMessage += "\n" + cmd.getKey() + " - " + cmd.getValue().helpText; ItemData itemData = GenshinData.getItemDataMap().get(item);
} if(itemData == null) {
CommandHandler.sendMessage(null, "Invalid item id."); return;
}
player.dropMessage(helpMessage); if (itemData.isEquip()) {
} float range = (5f + (.1f * amount));
} for (int i = 0; i < amount; i++) {
Position pos = player.getPos().clone().addX((float) (Math.random() * range) - (range / 2)).addY(3f).addZ((float) (Math.random() * range) - (range / 2));
@Command(aliases = {"g", "item", "additem"}, helpText = "/give [item id] [count] - Gives {count} amount of {item id}") EntityItem entity = new EntityItem(player.getWorld(), player, itemData, pos, 1);
public static class Give extends PlayerCommand { player.getWorld().addEntity(entity);
@Override }
public void execute(GenshinPlayer player, String raw) { } else {
String[] split = raw.split(" "); EntityItem entity = new EntityItem(player.getWorld(), player, itemData, player.getPos().clone().addY(3f), amount);
int itemId = 0, count = 1; player.getWorld().addEntity(entity);
}
try { } catch (NumberFormatException ignored) {
itemId = Integer.parseInt(split[0]); CommandHandler.sendMessage(null, "Invalid item or player ID.");
} catch (Exception e) { }
itemId = 0; }
} }
try { @Command(label = "spawn", execution = Command.Execution.PLAYER,
count = Math.max(Math.min(Integer.parseInt(split[1]), Integer.MAX_VALUE), 1); usage = "Usage: spawn <entityId|entityName> [level] [amount]")
} catch (Exception e) { public static class SpawnCommand implements CommandHandler {
count = 1;
} @Override
public void execute(GenshinPlayer player, List<String> args) {
// Give if(args.size() < 1) {
ItemData itemData = GenshinData.getItemDataMap().get(itemId); CommandHandler.sendMessage(null, "Usage: spawn <entityId|entityName> [amount]");
GenshinItem item; return;
}
if (itemData == null) {
player.dropMessage("Error: Item data not found"); try {
return; int entity = Integer.parseInt(args.get(0));
} int level = 1; if(args.size() > 1) level = Integer.parseInt(args.get(1));
int amount = 1; if(args.size() > 2) amount = Integer.parseInt(args.get(2));
if (itemData.isEquip()) {
List<GenshinItem> items = new LinkedList<>(); MonsterData entityData = GenshinData.getMonsterDataMap().get(entity);
for (int i = 0; i < count; i++) { if(entityData == null) {
item = new GenshinItem(itemData); CommandHandler.sendMessage(null, "Invalid entity id."); return;
items.add(item); }
}
player.getInventory().addItems(items); float range = (5f + (.1f * amount));
player.sendPacket(new PacketItemAddHintNotify(items, ActionReason.SubfieldDrop)); for (int i = 0; i < amount; i++) {
} else { Position pos = player.getPos().clone().addX((float) (Math.random() * range) - (range / 2)).addY(3f).addZ((float) (Math.random() * range) - (range / 2));
item = new GenshinItem(itemData, count); EntityMonster monster = new EntityMonster(player.getWorld(), entityData, pos, level);
player.getInventory().addItem(item); player.getWorld().addEntity(monster);
player.sendPacket(new PacketItemAddHintNotify(item, ActionReason.SubfieldDrop)); }
} } catch (NumberFormatException ignored) {
} CommandHandler.sendMessage(null, "Invalid item or player ID.");
} }
}
@Command(aliases = {"d"}, helpText = "/drop [item id] [count] - Drops {count} amount of {item id}") }
public static class Drop extends PlayerCommand {
@Override @Command(label = "killall",
public void execute(GenshinPlayer player, String raw) { usage = "Usage: killall [sceneId]")
String[] split = raw.split(" "); public static class KillAllCommand implements CommandHandler {
int itemId = 0, count = 1;
@Override
try { public void execute(GenshinPlayer player, List<String> args) {
itemId = Integer.parseInt(split[0]); World world = player.getWorld();
} catch (Exception e) { world.getEntities().values().stream()
itemId = 0; .filter(entity -> entity instanceof EntityMonster)
} .forEach(entity -> world.killEntity(entity, 0));
}
try {
count = Math.max(Math.min(Integer.parseInt(split[1]), Integer.MAX_VALUE), 1); @Override
} catch (Exception e) { public void execute(List<String> args) {
count = 1; if(args.size() < 1) {
} CommandHandler.sendMessage(null, "Usage: killall [sceneId]"); return;
}
// Give
ItemData itemData = GenshinData.getItemDataMap().get(itemId); try {
int sceneId = Integer.parseInt(args.get(0));
if (itemData == null) { CommandHandler.sendMessage(null, "Killing all monsters in scene " + sceneId);
player.dropMessage("Error: Item data not found"); // TODO: Implement getting worlds by scene ID.
return; } catch (NumberFormatException ignored) {
} CommandHandler.sendMessage(null, "Invalid scene id.");
}
if (itemData.isEquip()) { }
float range = (5f + (.1f * count)); }
for (int i = 0; i < count; i++) {
Position pos = player.getPos().clone().addX((float) (Math.random() * range) - (range / 2)).addY(3f).addZ((float) (Math.random() * range) - (range / 2)); @Command(label = "resetconst", aliases = {"resetconstellation"},
EntityItem entity = new EntityItem(player.getWorld(), player, itemData, pos, 1); usage = "Usage: resetconst [all]", execution = Command.Execution.PLAYER)
player.getWorld().addEntity(entity); public static class ResetConstellationCommand implements CommandHandler {
}
} else { @Override
EntityItem entity = new EntityItem(player.getWorld(), player, itemData, player.getPos().clone().addY(3f), count); public void execute(GenshinPlayer player, List<String> args) {
player.getWorld().addEntity(entity); if(args.size() > 0 && args.get(0).equalsIgnoreCase("all")) {
} player.getAvatars().forEach(this::resetConstellation);
} player.dropMessage("Reset all avatars' constellations.");
} } else {
EntityAvatar entity = player.getTeamManager().getCurrentAvatarEntity();
@Command(helpText = "/spawn [monster id] [count] - Creates {count} amount of {item id}") if(entity == null)
public static class Spawn extends PlayerCommand { return;
@Override
public void execute(GenshinPlayer player, String raw) { GenshinAvatar avatar = entity.getAvatar();
String[] split = raw.split(" "); this.resetConstellation(avatar);
int monsterId = 0, count = 1, level = 1;
player.dropMessage("Constellations for " + avatar.getAvatarData().getName() + " have been reset. Please relog to see changes.");
try { }
monsterId = Integer.parseInt(split[0]); }
} catch (Exception e) {
monsterId = 0; private void resetConstellation(GenshinAvatar avatar) {
} avatar.getTalentIdList().clear();
avatar.setCoreProudSkillLevel(0);
try { avatar.recalcStats();
level = Math.max(Math.min(Integer.parseInt(split[1]), 200), 1); avatar.save();
} catch (Exception e) { }
level = 1; }
}
@Command(label = "godmode",
try { usage = "Usage: godmode", execution = Command.Execution.PLAYER)
count = Math.max(Math.min(Integer.parseInt(split[2]), 1000), 1); public static class GodModeCommand implements CommandHandler {
} catch (Exception e) {
count = 1; @Override
} public void execute(GenshinPlayer player, List<String> args) {
player.setGodmode(!player.inGodmode());
// Give player.dropMessage("Godmode is now " + (player.inGodmode() ? "enabled" : "disabled") + ".");
MonsterData monsterData = GenshinData.getMonsterDataMap().get(monsterId); }
}
if (monsterData == null) {
player.dropMessage("Error: Monster data not found"); @Command(label = "sethealth", aliases = {"sethp"},
return; usage = "Usage: sethealth <hp>", execution = Command.Execution.PLAYER)
} public static class SetHealthCommand implements CommandHandler {
float range = (5f + (.1f * count)); @Override
for (int i = 0; i < count; i++) { public void execute(GenshinPlayer player, List<String> args) {
Position pos = player.getPos().clone().addX((float) (Math.random() * range) - (range / 2)).addY(3f).addZ((float) (Math.random() * range) - (range / 2)); if(args.size() < 1) {
EntityMonster entity = new EntityMonster(player.getWorld(), monsterData, pos, level); CommandHandler.sendMessage(null, "Usage: sethealth <hp>"); return;
player.getWorld().addEntity(entity); }
}
} try {
} int health = Integer.parseInt(args.get(0));
EntityAvatar entity = player.getTeamManager().getCurrentAvatarEntity();
@Command(helpText = "/killall") if(entity == null)
public static class KillAll extends PlayerCommand { return;
@Override
public void execute(GenshinPlayer player, String raw) { entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, health);
List<GenshinEntity> toRemove = new LinkedList<>(); entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_HP));
for (GenshinEntity entity : player.getWorld().getEntities().values()) { player.dropMessage("Health set to " + health + ".");
if (entity instanceof EntityMonster) { } catch (NumberFormatException ignored) {
toRemove.add(entity); CommandHandler.sendMessage(null, "Invalid health value.");
} }
} }
toRemove.forEach(e -> player.getWorld().killEntity(e, 0)); }
}
} @Command(label = "clearartifacts", aliases = {"clearart"},
usage = "Usage: clearartifacts", execution = Command.Execution.PLAYER)
@Command(helpText = "/resetconst - Resets all constellations for the currently active character") public static class ClearArtifactsCommand implements CommandHandler {
public static class ResetConst extends PlayerCommand {
@Override @Override
public void execute(GenshinPlayer player, String raw) { public void execute(GenshinPlayer player, List<String> args) {
EntityAvatar entity = player.getTeamManager().getCurrentAvatarEntity(); Inventory playerInventory = player.getInventory();
playerInventory.getItems().values().stream()
if (entity == null) { .filter(item -> item.getItemType() == ItemType.ITEM_RELIQUARY)
return; .filter(item -> item.getLevel() == 1 && item.getExp() == 0)
} .filter(item -> !item.isLocked() && !item.isEquipped())
.forEach(item -> playerInventory.removeItem(item, item.getCount()));
GenshinAvatar avatar = entity.getAvatar(); }
}
avatar.getTalentIdList().clear();
avatar.setCoreProudSkillLevel(0);
avatar.recalcStats();
avatar.save();
player.dropMessage("Constellations for " + entity.getAvatar().getAvatarData().getName() + " have been reset. Please relogin to see changes.");
}
}
@Command(helpText = "/godmode - Prevents you from taking damage")
public static class Godmode extends PlayerCommand {
@Override
public void execute(GenshinPlayer player, String raw) {
player.setGodmode(!player.hasGodmode());
player.dropMessage("Godmode is now " + (player.hasGodmode() ? "ON" : "OFF"));
}
}
@Command(helpText = "/sethp [hp]")
public static class Sethp extends PlayerCommand {
@Override
public void execute(GenshinPlayer player, String raw) {
String[] split = raw.split(" ");
int hp = 0;
try {
hp = Math.max(Integer.parseInt(split[0]), 1);
} catch (Exception e) {
hp = 1;
}
EntityAvatar entity = player.getTeamManager().getCurrentAvatarEntity();
if (entity == null) {
return;
}
entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, hp);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_HP));
}
}
@Command(aliases = {"clearart"}, helpText = "/clearartifacts")
public static class ClearArtifacts extends PlayerCommand {
@Override
public void execute(GenshinPlayer player, String raw) {
List<GenshinItem> toRemove = new LinkedList<>();
for (GenshinItem item : player.getInventory().getItems().values()) {
if (item.getItemType() == ItemType.ITEM_RELIQUARY && item.getLevel() == 1 && item.getExp() == 0 && !item.isLocked() && !item.isEquipped()) {
toRemove.add(item);
}
}
player.getInventory().removeItems(toRemove);
}
}
} }

View File

@ -0,0 +1,121 @@
package emu.grasscutter.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.Account;
import emu.grasscutter.game.GenshinPlayer;
import java.util.List;
/**
* A container for server-related commands.
*/
public final class ServerCommands {
@Command(label = "reload", usage = "Usage: reload")
public static class ReloadCommand implements CommandHandler {
@Override
public void execute(List<String> args) {
Grasscutter.getLogger().info("Reloading config.");
Grasscutter.loadConfig();
Grasscutter.getDispatchServer().loadQueries();
Grasscutter.getLogger().info("Reload complete.");
}
@Override
public void execute(GenshinPlayer player, List<String> args) {
this.execute(args);
}
}
@Command(label = "sendmessage", aliases = {"sendmsg", "msg"},
usage = "Usage: sendmessage <player> <message>")
public static class SendMessageCommand implements CommandHandler {
@Override
public void execute(List<String> args) {
if(args.size() < 2) {
CommandHandler.sendMessage(null, "Usage: sendmessage <player> <message>"); return;
}
try {
int target = Integer.parseInt(args.get(0));
String message = String.join(" ", args.subList(1, args.size()));
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerById(target);
if(targetPlayer == null) {
CommandHandler.sendMessage(null, "Player not found."); return;
}
targetPlayer.dropMessage(message);
CommandHandler.sendMessage(null, "Message sent.");
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(null, "Invalid player ID.");
}
}
@Override
public void execute(GenshinPlayer player, List<String> args) {
if(args.size() < 2) {
CommandHandler.sendMessage(null, "Usage: sendmessage <player> <message>"); return;
}
try {
int target = Integer.parseInt(args.get(0));
String message = String.join(" ", args.subList(1, args.size()));
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerById(target);
if(targetPlayer == null) {
CommandHandler.sendMessage(null, "Player not found."); return;
}
targetPlayer.sendMessage(player, message);
CommandHandler.sendMessage(null, "Message sent.");
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(null, "Invalid player ID.");
}
}
}
@Command(label = "account",
usage = "Usage: account <create|delete> <username> [uid]",
execution = Command.Execution.CONSOLE)
public static class AccountCommand implements CommandHandler {
@Override
public void execute(List<String> args) {
if(args.size() < 2) {
CommandHandler.sendMessage(null, "Usage: account <create|delete> <username> [uid]"); return;
}
String action = args.get(0);
String username = args.get(1);
switch(action) {
default:
CommandHandler.sendMessage(null, "Usage: account <create|delete> <username> [uid]");
return;
case "create":
int uid = 0;
if(args.size() > 2) {
try {
uid = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(null, "Invalid UID."); return;
}
}
Account account = DatabaseHelper.createAccountWithId(username, uid);
if(account == null) {
CommandHandler.sendMessage(null, "Account already exists."); return;
} else CommandHandler.sendMessage(null, "Account created with UID " + account.getId() + ".");
return;
case "delete":
if(DatabaseHelper.deleteAccount(username)) {
CommandHandler.sendMessage(null, "Account deleted."); return;
} else CommandHandler.sendMessage(null, "Account not found.");
return;
}
}
}
}

View File

@ -485,7 +485,7 @@ public class GenshinPlayer {
this.regionId = regionId; this.regionId = regionId;
} }
public boolean hasGodmode() { public boolean inGodmode() {
return godmode; return godmode;
} }
@ -558,6 +558,15 @@ public class GenshinPlayer {
public void dropMessage(Object message) { public void dropMessage(Object message) {
this.sendPacket(new PacketPrivateChatNotify(GenshinConstants.SERVER_CONSOLE_UID, getId(), message.toString())); this.sendPacket(new PacketPrivateChatNotify(GenshinConstants.SERVER_CONSOLE_UID, getId(), message.toString()));
} }
/**
* Sends a message to another player.
* @param sender The sender of the message.
* @param message The message to send.
*/
public void sendMessage(GenshinPlayer sender, Object message) {
this.sendPacket(new PacketPrivateChatNotify(sender.getId(), this.getId(), message.toString()));
}
public void interactWith(int gadgetEntityId) { public void interactWith(int gadgetEntityId) {
GenshinEntity entity = getWorld().getEntityById(gadgetEntityId); GenshinEntity entity = getWorld().getEntityById(gadgetEntityId);

View File

@ -344,7 +344,7 @@ public class World implements Iterable<GenshinPlayer> {
// Godmode check // Godmode check
if (target instanceof EntityAvatar) { if (target instanceof EntityAvatar) {
if (((EntityAvatar) target).getPlayer().hasGodmode()) { if (((EntityAvatar) target).getPlayer().inGodmode()) {
return; return;
} }
} }

View File

@ -118,6 +118,16 @@ public final class Utils {
} }
} }
/**
* Get object with null fallback.
* @param nonNull The object to return if not null.
* @param fallback The object to return if null.
* @return One of the two provided objects.
*/
public static <T> T requireNonNullElseGet(T nonNull, T fallback) {
return nonNull != null ? nonNull : fallback;
}
/** /**
* Checks for required files and folders before startup. * Checks for required files and folders before startup.
*/ */