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;
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.Logger;
import emu.grasscutter.auth.AuthenticationSystem;
@ -30,6 +33,12 @@ import emu.grasscutter.utils.JsonUtils;
import emu.grasscutter.utils.StartupArguments;
import emu.grasscutter.utils.Utils;
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.Setter;
import org.jline.reader.EndOfFileException;
@ -41,16 +50,6 @@ import org.jline.terminal.TerminalBuilder;
import org.reflections.Reflections;
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 static final File configFile = new File("./config.json");
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
EntityAvatar entity = avatar.getAsEntity();
if (entity == null) {
entity = EntityCreationEvent.call(EntityAvatar.class,
new Class<?>[] {Avatar.class}, new Object[] {avatar});
entity =
EntityCreationEvent.call(
EntityAvatar.class, new Class<?>[] {Avatar.class}, new Object[] {avatar});
getPlayer().sendPacket(new PacketAvatarChangeCostumeNotify(entity));
} else {
getPlayer().getScene().broadcastPacket(new PacketAvatarChangeCostumeNotify(entity));

View File

@ -1,5 +1,8 @@
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.binout.ScenePointEntry;
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.scripts.data.ScriptArgs;
import emu.grasscutter.server.packet.send.*;
import java.util.Set;
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
public final class PlayerProgressManager extends BasePlayerDataManager {
/******************************************************************************************************************

View File

@ -1,5 +1,7 @@
package emu.grasscutter.game.player;
import static emu.grasscutter.config.Configuration.GAME_OPTIONS;
import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Transient;
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.IntSet;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import java.util.*;
import java.util.stream.Stream;
import lombok.Getter;
import lombok.Setter;
import lombok.val;
import java.util.*;
import java.util.stream.Stream;
import static emu.grasscutter.config.Configuration.GAME_OPTIONS;
@Entity
public final class TeamManager extends BasePlayerDataManager {
@Transient private final List<EntityAvatar> avatars;
@ -356,10 +355,11 @@ public final class TeamManager extends BasePlayerDataManager {
}
} else {
var player = this.getPlayer();
entity = EntityCreationEvent.call(EntityAvatar.class,
new Class<?>[] {Scene.class, Avatar.class}, new Object[] {
player.getScene(), player.getAvatars().getAvatarById(avatarId)
});
entity =
EntityCreationEvent.call(
EntityAvatar.class,
new Class<?>[] {Scene.class, Avatar.class},
new Object[] {player.getScene(), player.getAvatars().getAvatarById(avatarId)});
}
this.getActiveTeam().add(entity);
@ -498,10 +498,12 @@ public final class TeamManager extends BasePlayerDataManager {
this.getActiveTeam().removeIf(x -> x.getAvatar().getAvatarId() == trialAvatar.getAvatarId());
this.getCurrentTeamInfo().getAvatars().removeIf(x -> x == trialAvatar.getAvatarId());
// Add the avatar to the teams.
this.getActiveTeam().add(EntityCreationEvent.call(EntityAvatar.class,
new Class<?>[] {Scene.class, Avatar.class}, new Object[] {
player.getScene(), trialAvatar
}));
this.getActiveTeam()
.add(
EntityCreationEvent.call(
EntityAvatar.class,
new Class<?>[] {Scene.class, Avatar.class},
new Object[] {player.getScene(), trialAvatar}));
this.getCurrentTeamInfo().addAvatar(trialAvatar);
this.getTrialAvatars().put(trialAvatar.getAvatarId(), trialAvatar);
}
@ -588,10 +590,11 @@ public final class TeamManager extends BasePlayerDataManager {
.forEach(
avatarId ->
this.getActiveTeam()
.add(EntityCreationEvent.call(EntityAvatar.class,
new Class<?>[] {Scene.class, Avatar.class}, new Object[] {
scene, player.getAvatars().getAvatarById(avatarId)
})));
.add(
EntityCreationEvent.call(
EntityAvatar.class,
new Class<?>[] {Scene.class, Avatar.class},
new Object[] {scene, player.getAvatars().getAvatarById(avatarId)})));
} else {
// Restores all avatars from the player's avatar storage.
// 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);
if (avatarData == null) continue;
this.getActiveTeam().add(index, EntityCreationEvent.call(EntityAvatar.class,
new Class<?>[] {Scene.class, Avatar.class}, new Object[] {
scene, avatarData
}));
this.getActiveTeam()
.add(
index,
EntityCreationEvent.call(
EntityAvatar.class,
new Class<?>[] {Scene.class, Avatar.class},
new Object[] {scene, avatarData}));
}
}
@ -976,9 +982,11 @@ public final class TeamManager extends BasePlayerDataManager {
var avatar = avatars.getAvatarById(id);
if (avatar == null) continue;
specifiedAvatarList.add(EntityCreationEvent.call(EntityAvatar.class,
new Class<?>[] {Scene.class, Avatar.class},
new Object[] {scene, avatar}));
specifiedAvatarList.add(
EntityCreationEvent.call(
EntityAvatar.class,
new Class<?>[] {Scene.class, Avatar.class},
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.PacketQuestUpdateQuestVarNotify;
import emu.grasscutter.utils.ConversionUtils;
import java.util.*;
import java.util.stream.Collectors;
import lombok.Getter;
import lombok.val;
import org.bson.types.ObjectId;
import java.util.*;
import java.util.stream.Collectors;
@Entity(value = "quests", useDiscriminator = false)
public class GameMainQuest {
@Id private ObjectId id;

View File

@ -5,13 +5,12 @@ import com.google.gson.annotations.SerializedName;
import dev.morphia.annotations.Entity;
import emu.grasscutter.net.proto.VectorOuterClass.Vector;
import emu.grasscutter.utils.Utils;
import java.io.Serializable;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.List;
@Entity
@Accessors(chain = true)
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.utils.objects.KahnsSort;
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.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import lombok.Getter;
import lombok.Setter;
import lombok.val;
public final class Scene {
@Getter private final World world;
@ -248,11 +247,14 @@ public final class Scene {
}
if (avatar == null) continue;
}
player.getTeamManager().getActiveTeam().add(
EntityCreationEvent.call(EntityAvatar.class,
new Class<?>[] {Scene.class, Avatar.class},
new Object[] {player.getScene(), avatar})
);
player
.getTeamManager()
.getActiveTeam()
.add(
EntityCreationEvent.call(
EntityAvatar.class,
new Class<?>[] {Scene.class, Avatar.class},
new Object[] {player.getScene(), avatar}));
}
// 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.server.event.Event;
import javax.annotation.Nullable;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import javax.annotation.Nullable;
/** Invoked when an entity is created. */
@AllArgsConstructor
public final class EntityCreationEvent extends Event {
/**
* Helper method to call EntityCreationEvent.
* Returns the result of the event call.
* Helper method to call EntityCreationEvent. Returns the result of the event call.
*
* @param type The type of entity to create.
* @return The result of the event call.
* @param <T> The type of entity to create.
*/
public static <T extends GameEntity> T call(
Class<T> type, Class<?>[] argTypes, Object[] args
) {
public static <T extends GameEntity> T call(Class<T> type, Class<?>[] argTypes, Object[] 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;
@ -31,16 +28,15 @@ public final class EntityCreationEvent extends Event {
@Getter @Setter private Object[] constructorArgs;
/**
* Creates a new entity.
* Returns null if the entity could not be created.
* Creates a new entity. Returns null if the entity could not be created.
*
* @return The created entity.
*/
@Nullable
public GameEntity getEntity() {
@Nullable public GameEntity getEntity() {
try {
return this.entityType.getConstructor(this.constructorArgTypes)
.newInstance(this.constructorArgs);
return this.entityType
.getConstructor(this.constructorArgTypes)
.newInstance(this.constructorArgs);
} catch (ReflectiveOperationException ignored) {
return null;
}