Merge remote-tracking branch 'origin/unstable' into unstable

This commit is contained in:
KingRainbow44 2023-05-22 03:15:18 -04:00
commit 4c0ce8e20e
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
8 changed files with 73 additions and 70 deletions

View File

@ -1,5 +1,8 @@
package emu.grasscutter; package emu.grasscutter;
import static emu.grasscutter.config.Configuration.SERVER;
import static emu.grasscutter.utils.lang.Language.translate;
import ch.qos.logback.classic.Level; import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.Logger;
import emu.grasscutter.auth.AuthenticationSystem; import emu.grasscutter.auth.AuthenticationSystem;
@ -30,6 +33,12 @@ import emu.grasscutter.utils.JsonUtils;
import emu.grasscutter.utils.StartupArguments; import emu.grasscutter.utils.StartupArguments;
import emu.grasscutter.utils.Utils; import emu.grasscutter.utils.Utils;
import emu.grasscutter.utils.lang.Language; import emu.grasscutter.utils.lang.Language;
import java.io.File;
import java.io.FileWriter;
import java.io.IOError;
import java.io.IOException;
import java.util.Calendar;
import javax.annotation.Nullable;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.jline.reader.EndOfFileException; import org.jline.reader.EndOfFileException;
@ -41,16 +50,6 @@ import org.jline.terminal.TerminalBuilder;
import org.reflections.Reflections; import org.reflections.Reflections;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import java.io.File;
import java.io.FileWriter;
import java.io.IOError;
import java.io.IOException;
import java.util.Calendar;
import static emu.grasscutter.config.Configuration.SERVER;
import static emu.grasscutter.utils.lang.Language.translate;
public final class Grasscutter { public final class Grasscutter {
public static final File configFile = new File("./config.json"); public static final File configFile = new File("./config.json");
public static final Reflections reflector = new Reflections("emu.grasscutter"); public static final Reflections reflector = new Reflections("emu.grasscutter");

View File

@ -116,8 +116,9 @@ public class AvatarStorage extends BasePlayerManager implements Iterable<Avatar>
// Update entity // Update entity
EntityAvatar entity = avatar.getAsEntity(); EntityAvatar entity = avatar.getAsEntity();
if (entity == null) { if (entity == null) {
entity = EntityCreationEvent.call(EntityAvatar.class, entity =
new Class<?>[] {Avatar.class}, new Object[] {avatar}); EntityCreationEvent.call(
EntityAvatar.class, new Class<?>[] {Avatar.class}, new Object[] {avatar});
getPlayer().sendPacket(new PacketAvatarChangeCostumeNotify(entity)); getPlayer().sendPacket(new PacketAvatarChangeCostumeNotify(entity));
} else { } else {
getPlayer().getScene().broadcastPacket(new PacketAvatarChangeCostumeNotify(entity)); getPlayer().getScene().broadcastPacket(new PacketAvatarChangeCostumeNotify(entity));

View File

@ -1,5 +1,8 @@
package emu.grasscutter.game.player; package emu.grasscutter.game.player;
import static emu.grasscutter.config.Configuration.GAME_OPTIONS;
import static emu.grasscutter.scripts.constants.EventType.EVENT_UNLOCK_TRANS_POINT;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
import emu.grasscutter.data.binout.ScenePointEntry; import emu.grasscutter.data.binout.ScenePointEntry;
import emu.grasscutter.data.excels.OpenStateData; import emu.grasscutter.data.excels.OpenStateData;
@ -12,13 +15,9 @@ import emu.grasscutter.game.quest.enums.QuestState;
import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode;
import emu.grasscutter.scripts.data.ScriptArgs; import emu.grasscutter.scripts.data.ScriptArgs;
import emu.grasscutter.server.packet.send.*; import emu.grasscutter.server.packet.send.*;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static emu.grasscutter.config.Configuration.GAME_OPTIONS;
import static emu.grasscutter.scripts.constants.EventType.EVENT_UNLOCK_TRANS_POINT;
// @Entity // @Entity
public final class PlayerProgressManager extends BasePlayerDataManager { public final class PlayerProgressManager extends BasePlayerDataManager {
/****************************************************************************************************************** /******************************************************************************************************************

View File

@ -1,5 +1,7 @@
package emu.grasscutter.game.player; package emu.grasscutter.game.player;
import static emu.grasscutter.config.Configuration.GAME_OPTIONS;
import dev.morphia.annotations.Entity; import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Transient; import dev.morphia.annotations.Transient;
import emu.grasscutter.GameConstants; import emu.grasscutter.GameConstants;
@ -31,15 +33,12 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet; import it.unimi.dsi.fastutil.ints.IntSet;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import java.util.*;
import java.util.stream.Stream;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.val; import lombok.val;
import java.util.*;
import java.util.stream.Stream;
import static emu.grasscutter.config.Configuration.GAME_OPTIONS;
@Entity @Entity
public final class TeamManager extends BasePlayerDataManager { public final class TeamManager extends BasePlayerDataManager {
@Transient private final List<EntityAvatar> avatars; @Transient private final List<EntityAvatar> avatars;
@ -356,10 +355,11 @@ public final class TeamManager extends BasePlayerDataManager {
} }
} else { } else {
var player = this.getPlayer(); var player = this.getPlayer();
entity = EntityCreationEvent.call(EntityAvatar.class, entity =
new Class<?>[] {Scene.class, Avatar.class}, new Object[] { EntityCreationEvent.call(
player.getScene(), player.getAvatars().getAvatarById(avatarId) EntityAvatar.class,
}); new Class<?>[] {Scene.class, Avatar.class},
new Object[] {player.getScene(), player.getAvatars().getAvatarById(avatarId)});
} }
this.getActiveTeam().add(entity); this.getActiveTeam().add(entity);
@ -498,10 +498,12 @@ public final class TeamManager extends BasePlayerDataManager {
this.getActiveTeam().removeIf(x -> x.getAvatar().getAvatarId() == trialAvatar.getAvatarId()); this.getActiveTeam().removeIf(x -> x.getAvatar().getAvatarId() == trialAvatar.getAvatarId());
this.getCurrentTeamInfo().getAvatars().removeIf(x -> x == trialAvatar.getAvatarId()); this.getCurrentTeamInfo().getAvatars().removeIf(x -> x == trialAvatar.getAvatarId());
// Add the avatar to the teams. // Add the avatar to the teams.
this.getActiveTeam().add(EntityCreationEvent.call(EntityAvatar.class, this.getActiveTeam()
new Class<?>[] {Scene.class, Avatar.class}, new Object[] { .add(
player.getScene(), trialAvatar EntityCreationEvent.call(
})); EntityAvatar.class,
new Class<?>[] {Scene.class, Avatar.class},
new Object[] {player.getScene(), trialAvatar}));
this.getCurrentTeamInfo().addAvatar(trialAvatar); this.getCurrentTeamInfo().addAvatar(trialAvatar);
this.getTrialAvatars().put(trialAvatar.getAvatarId(), trialAvatar); this.getTrialAvatars().put(trialAvatar.getAvatarId(), trialAvatar);
} }
@ -588,10 +590,11 @@ public final class TeamManager extends BasePlayerDataManager {
.forEach( .forEach(
avatarId -> avatarId ->
this.getActiveTeam() this.getActiveTeam()
.add(EntityCreationEvent.call(EntityAvatar.class, .add(
new Class<?>[] {Scene.class, Avatar.class}, new Object[] { EntityCreationEvent.call(
scene, player.getAvatars().getAvatarById(avatarId) EntityAvatar.class,
}))); new Class<?>[] {Scene.class, Avatar.class},
new Object[] {scene, player.getAvatars().getAvatarById(avatarId)})));
} else { } else {
// Restores all avatars from the player's avatar storage. // Restores all avatars from the player's avatar storage.
// If the avatar is already in the team, it will not be added. // If the avatar is already in the team, it will not be added.
@ -607,10 +610,13 @@ public final class TeamManager extends BasePlayerDataManager {
var avatarData = player.getAvatars().getAvatarById(avatar); var avatarData = player.getAvatars().getAvatarById(avatar);
if (avatarData == null) continue; if (avatarData == null) continue;
this.getActiveTeam().add(index, EntityCreationEvent.call(EntityAvatar.class, this.getActiveTeam()
new Class<?>[] {Scene.class, Avatar.class}, new Object[] { .add(
scene, avatarData index,
})); EntityCreationEvent.call(
EntityAvatar.class,
new Class<?>[] {Scene.class, Avatar.class},
new Object[] {scene, avatarData}));
} }
} }
@ -976,7 +982,9 @@ public final class TeamManager extends BasePlayerDataManager {
var avatar = avatars.getAvatarById(id); var avatar = avatars.getAvatarById(id);
if (avatar == null) continue; if (avatar == null) continue;
specifiedAvatarList.add(EntityCreationEvent.call(EntityAvatar.class, specifiedAvatarList.add(
EntityCreationEvent.call(
EntityAvatar.class,
new Class<?>[] {Scene.class, Avatar.class}, new Class<?>[] {Scene.class, Avatar.class},
new Object[] {scene, avatar})); new Object[] {scene, avatar}));
} }

View File

@ -24,13 +24,12 @@ import emu.grasscutter.server.packet.send.PacketFinishedParentQuestUpdateNotify;
import emu.grasscutter.server.packet.send.PacketQuestProgressUpdateNotify; import emu.grasscutter.server.packet.send.PacketQuestProgressUpdateNotify;
import emu.grasscutter.server.packet.send.PacketQuestUpdateQuestVarNotify; import emu.grasscutter.server.packet.send.PacketQuestUpdateQuestVarNotify;
import emu.grasscutter.utils.ConversionUtils; import emu.grasscutter.utils.ConversionUtils;
import java.util.*;
import java.util.stream.Collectors;
import lombok.Getter; import lombok.Getter;
import lombok.val; import lombok.val;
import org.bson.types.ObjectId; import org.bson.types.ObjectId;
import java.util.*;
import java.util.stream.Collectors;
@Entity(value = "quests", useDiscriminator = false) @Entity(value = "quests", useDiscriminator = false)
public class GameMainQuest { public class GameMainQuest {
@Id private ObjectId id; @Id private ObjectId id;

View File

@ -5,13 +5,12 @@ import com.google.gson.annotations.SerializedName;
import dev.morphia.annotations.Entity; import dev.morphia.annotations.Entity;
import emu.grasscutter.net.proto.VectorOuterClass.Vector; import emu.grasscutter.net.proto.VectorOuterClass.Vector;
import emu.grasscutter.utils.Utils; import emu.grasscutter.utils.Utils;
import java.io.Serializable;
import java.util.List;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.List;
@Entity @Entity
@Accessors(chain = true) @Accessors(chain = true)
public class Position implements Serializable { public class Position implements Serializable {

View File

@ -41,15 +41,14 @@ import emu.grasscutter.server.event.player.PlayerTeleportEvent;
import emu.grasscutter.server.packet.send.*; import emu.grasscutter.server.packet.send.*;
import emu.grasscutter.utils.objects.KahnsSort; import emu.grasscutter.utils.objects.KahnsSort;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import lombok.Getter;
import lombok.Setter;
import lombok.val;
import javax.annotation.Nullable;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.annotation.Nullable;
import lombok.Getter;
import lombok.Setter;
import lombok.val;
public final class Scene { public final class Scene {
@Getter private final World world; @Getter private final World world;
@ -248,11 +247,14 @@ public final class Scene {
} }
if (avatar == null) continue; if (avatar == null) continue;
} }
player.getTeamManager().getActiveTeam().add( player
EntityCreationEvent.call(EntityAvatar.class, .getTeamManager()
.getActiveTeam()
.add(
EntityCreationEvent.call(
EntityAvatar.class,
new Class<?>[] {Scene.class, Avatar.class}, new Class<?>[] {Scene.class, Avatar.class},
new Object[] {player.getScene(), avatar}) new Object[] {player.getScene(), avatar}));
);
} }
// Limit character index in case its out of bounds // Limit character index in case its out of bounds

View File

@ -2,28 +2,25 @@ package emu.grasscutter.server.event.entity;
import emu.grasscutter.game.entity.GameEntity; import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.server.event.Event; import emu.grasscutter.server.event.Event;
import javax.annotation.Nullable;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import javax.annotation.Nullable;
/** Invoked when an entity is created. */ /** Invoked when an entity is created. */
@AllArgsConstructor @AllArgsConstructor
public final class EntityCreationEvent extends Event { public final class EntityCreationEvent extends Event {
/** /**
* Helper method to call EntityCreationEvent. * Helper method to call EntityCreationEvent. Returns the result of the event call.
* Returns the result of the event call.
* *
* @param type The type of entity to create. * @param type The type of entity to create.
* @return The result of the event call. * @return The result of the event call.
* @param <T> The type of entity to create. * @param <T> The type of entity to create.
*/ */
public static <T extends GameEntity> T call( public static <T extends GameEntity> T call(Class<T> type, Class<?>[] argTypes, Object[] args) {
Class<T> type, Class<?>[] argTypes, Object[] args
) {
var event = new EntityCreationEvent(type, argTypes, args); var event = new EntityCreationEvent(type, argTypes, args);
event.call(); return type.cast(event.getEntity()); event.call();
return type.cast(event.getEntity());
} }
@Getter @Setter private Class<? extends GameEntity> entityType; @Getter @Setter private Class<? extends GameEntity> entityType;
@ -31,15 +28,14 @@ public final class EntityCreationEvent extends Event {
@Getter @Setter private Object[] constructorArgs; @Getter @Setter private Object[] constructorArgs;
/** /**
* Creates a new entity. * Creates a new entity. Returns null if the entity could not be created.
* Returns null if the entity could not be created.
* *
* @return The created entity. * @return The created entity.
*/ */
@Nullable @Nullable public GameEntity getEntity() {
public GameEntity getEntity() {
try { try {
return this.entityType.getConstructor(this.constructorArgTypes) return this.entityType
.getConstructor(this.constructorArgTypes)
.newInstance(this.constructorArgs); .newInstance(this.constructorArgs);
} catch (ReflectiveOperationException ignored) { } catch (ReflectiveOperationException ignored) {
return null; return null;