Format code [skip actions]

This commit is contained in:
github-actions
2023-05-11 02:23:43 +00:00
parent f51fd55cb5
commit f9906c4492
730 changed files with 29212 additions and 29159 deletions

View File

@@ -1,23 +1,23 @@
package emu.grasscutter.game.player;
import lombok.NonNull;
public abstract class BasePlayerDataManager {
protected transient Player player;
public BasePlayerDataManager() {}
public BasePlayerDataManager(@NonNull Player player) {
this.player = player;
}
public Player getPlayer() {
return this.player;
}
public void setPlayer(Player player) {
if (this.player == null) {
this.player = player;
}
}
}
package emu.grasscutter.game.player;
import lombok.NonNull;
public abstract class BasePlayerDataManager {
protected transient Player player;
public BasePlayerDataManager() {}
public BasePlayerDataManager(@NonNull Player player) {
this.player = player;
}
public Player getPlayer() {
return this.player;
}
public void setPlayer(Player player) {
if (this.player == null) {
this.player = player;
}
}
}

View File

@@ -1,20 +1,20 @@
package emu.grasscutter.game.player;
import lombok.NonNull;
public abstract class BasePlayerManager {
protected final transient Player player;
public BasePlayerManager(@NonNull Player player) {
this.player = player;
}
public Player getPlayer() {
return this.player;
}
/** Saves the player to the database */
public void save() {
getPlayer().save();
}
}
package emu.grasscutter.game.player;
import lombok.NonNull;
public abstract class BasePlayerManager {
protected final transient Player player;
public BasePlayerManager(@NonNull Player player) {
this.player = player;
}
public Player getPlayer() {
return this.player;
}
/** Saves the player to the database */
public void save() {
getPlayer().save();
}
}

View File

@@ -1,64 +1,64 @@
package emu.grasscutter.game.player;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.proto.ForwardTypeOuterClass.ForwardType;
import java.util.ArrayList;
import java.util.List;
public class InvokeHandler<T> {
private final List<T> entryListForwardAll;
private final List<T> entryListForwardAllExceptCur;
private final List<T> entryListForwardHost;
private final Class<? extends BasePacket> packetClass;
public InvokeHandler(Class<? extends BasePacket> packetClass) {
this.entryListForwardAll = new ArrayList<>();
this.entryListForwardAllExceptCur = new ArrayList<>();
this.entryListForwardHost = new ArrayList<>();
this.packetClass = packetClass;
}
public synchronized void addEntry(ForwardType forward, T entry) {
switch (forward) {
case FORWARD_TYPE_TO_ALL -> entryListForwardAll.add(entry);
case FORWARD_TYPE_TO_ALL_EXCEPT_CUR,
FORWARD_TYPE_TO_ALL_EXIST_EXCEPT_CUR -> entryListForwardAllExceptCur.add(entry);
case FORWARD_TYPE_TO_HOST -> entryListForwardHost.add(entry);
default -> {}
}
}
public synchronized void update(Player player) {
if (player.getWorld() == null || player.getScene() == null) {
this.entryListForwardAll.clear();
this.entryListForwardAllExceptCur.clear();
this.entryListForwardHost.clear();
return;
}
try {
if (entryListForwardAll.size() > 0) {
BasePacket packet =
packetClass.getDeclaredConstructor(List.class).newInstance(this.entryListForwardAll);
player.getScene().broadcastPacket(packet);
this.entryListForwardAll.clear();
}
if (entryListForwardAllExceptCur.size() > 0) {
BasePacket packet =
packetClass
.getDeclaredConstructor(List.class)
.newInstance(this.entryListForwardAllExceptCur);
player.getScene().broadcastPacketToOthers(player, packet);
this.entryListForwardAllExceptCur.clear();
}
if (entryListForwardHost.size() > 0) {
BasePacket packet =
packetClass.getDeclaredConstructor(List.class).newInstance(this.entryListForwardHost);
player.getWorld().getHost().sendPacket(packet);
this.entryListForwardHost.clear();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
package emu.grasscutter.game.player;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.proto.ForwardTypeOuterClass.ForwardType;
import java.util.ArrayList;
import java.util.List;
public class InvokeHandler<T> {
private final List<T> entryListForwardAll;
private final List<T> entryListForwardAllExceptCur;
private final List<T> entryListForwardHost;
private final Class<? extends BasePacket> packetClass;
public InvokeHandler(Class<? extends BasePacket> packetClass) {
this.entryListForwardAll = new ArrayList<>();
this.entryListForwardAllExceptCur = new ArrayList<>();
this.entryListForwardHost = new ArrayList<>();
this.packetClass = packetClass;
}
public synchronized void addEntry(ForwardType forward, T entry) {
switch (forward) {
case FORWARD_TYPE_TO_ALL -> entryListForwardAll.add(entry);
case FORWARD_TYPE_TO_ALL_EXCEPT_CUR,
FORWARD_TYPE_TO_ALL_EXIST_EXCEPT_CUR -> entryListForwardAllExceptCur.add(entry);
case FORWARD_TYPE_TO_HOST -> entryListForwardHost.add(entry);
default -> {}
}
}
public synchronized void update(Player player) {
if (player.getWorld() == null || player.getScene() == null) {
this.entryListForwardAll.clear();
this.entryListForwardAllExceptCur.clear();
this.entryListForwardHost.clear();
return;
}
try {
if (entryListForwardAll.size() > 0) {
BasePacket packet =
packetClass.getDeclaredConstructor(List.class).newInstance(this.entryListForwardAll);
player.getScene().broadcastPacket(packet);
this.entryListForwardAll.clear();
}
if (entryListForwardAllExceptCur.size() > 0) {
BasePacket packet =
packetClass
.getDeclaredConstructor(List.class)
.newInstance(this.entryListForwardAllExceptCur);
player.getScene().broadcastPacketToOthers(player, packet);
this.entryListForwardAllExceptCur.clear();
}
if (entryListForwardHost.size() > 0) {
BasePacket packet =
packetClass.getDeclaredConstructor(List.class).newInstance(this.entryListForwardHost);
player.getWorld().getHost().sendPacket(packet);
this.entryListForwardHost.clear();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -1,64 +1,64 @@
package emu.grasscutter.game.player;
import dev.morphia.annotations.Entity;
import emu.grasscutter.net.proto.BirthdayOuterClass.Birthday;
@Entity
public class PlayerBirthday {
private int day;
private int month;
public PlayerBirthday() {
this.day = 0;
this.month = 0;
}
public PlayerBirthday(int day, int month) {
this.day = day;
this.month = month;
}
public PlayerBirthday set(PlayerBirthday birth) {
this.day = birth.day;
this.month = birth.month;
return this;
}
public PlayerBirthday set(int d, int m) {
this.day = d;
this.month = m;
return this;
}
public int getDay() {
return this.day;
}
public PlayerBirthday setDay(int value) {
this.day = value;
return this;
}
public int getMonth() {
return this.month;
}
public PlayerBirthday setMonth(int value) {
this.month = value;
return this;
}
public Birthday toProto() {
return Birthday.newBuilder().setDay(this.getDay()).setMonth(this.getMonth()).build();
}
public Birthday.Builder getFilledProtoWhenNotEmpty() {
if (this.getDay() > 0) {
return Birthday.newBuilder().setDay(this.getDay()).setMonth(this.getMonth());
}
return Birthday.newBuilder();
}
}
package emu.grasscutter.game.player;
import dev.morphia.annotations.Entity;
import emu.grasscutter.net.proto.BirthdayOuterClass.Birthday;
@Entity
public class PlayerBirthday {
private int day;
private int month;
public PlayerBirthday() {
this.day = 0;
this.month = 0;
}
public PlayerBirthday(int day, int month) {
this.day = day;
this.month = month;
}
public PlayerBirthday set(PlayerBirthday birth) {
this.day = birth.day;
this.month = birth.month;
return this;
}
public PlayerBirthday set(int d, int m) {
this.day = d;
this.month = m;
return this;
}
public int getDay() {
return this.day;
}
public PlayerBirthday setDay(int value) {
this.day = value;
return this;
}
public int getMonth() {
return this.month;
}
public PlayerBirthday setMonth(int value) {
this.month = value;
return this;
}
public Birthday toProto() {
return Birthday.newBuilder().setDay(this.getDay()).setMonth(this.getMonth()).build();
}
public Birthday.Builder getFilledProtoWhenNotEmpty() {
if (this.getDay() > 0) {
return Birthday.newBuilder().setDay(this.getDay()).setMonth(this.getMonth());
}
return Birthday.newBuilder();
}
}

View File

@@ -1,68 +1,68 @@
package emu.grasscutter.game.player;
import dev.morphia.annotations.Entity;
import java.util.HashMap;
import java.util.Map;
@Entity(useDiscriminator = false)
public class PlayerCollectionRecords {
private Map<Integer, CollectionRecord> records;
private Map<Integer, CollectionRecord> getRecords() {
if (records == null) {
records = new HashMap<>();
}
return records;
}
public void addRecord(int configId, long expiredMillisecond) {
Map<Integer, CollectionRecord> records;
synchronized (records = getRecords()) {
records.put(
configId,
new CollectionRecord(configId, expiredMillisecond + System.currentTimeMillis()));
}
}
public boolean findRecord(int configId) {
Map<Integer, CollectionRecord> records;
synchronized (records = getRecords()) {
CollectionRecord record = records.get(configId);
if (record == null) {
return false;
}
boolean expired = record.getExpiredTime() < System.currentTimeMillis();
if (expired) {
records.remove(configId);
return false;
}
return true;
}
}
@Entity
public static class CollectionRecord {
private int configId;
private long expiredTime;
@Deprecated // Morphia
public CollectionRecord() {}
public CollectionRecord(int configId, long expiredTime) {
this.configId = configId;
this.expiredTime = expiredTime;
}
public int getConfigId() {
return configId;
}
public long getExpiredTime() {
return expiredTime;
}
}
}
package emu.grasscutter.game.player;
import dev.morphia.annotations.Entity;
import java.util.HashMap;
import java.util.Map;
@Entity(useDiscriminator = false)
public class PlayerCollectionRecords {
private Map<Integer, CollectionRecord> records;
private Map<Integer, CollectionRecord> getRecords() {
if (records == null) {
records = new HashMap<>();
}
return records;
}
public void addRecord(int configId, long expiredMillisecond) {
Map<Integer, CollectionRecord> records;
synchronized (records = getRecords()) {
records.put(
configId,
new CollectionRecord(configId, expiredMillisecond + System.currentTimeMillis()));
}
}
public boolean findRecord(int configId) {
Map<Integer, CollectionRecord> records;
synchronized (records = getRecords()) {
CollectionRecord record = records.get(configId);
if (record == null) {
return false;
}
boolean expired = record.getExpiredTime() < System.currentTimeMillis();
if (expired) {
records.remove(configId);
return false;
}
return true;
}
}
@Entity
public static class CollectionRecord {
private int configId;
private long expiredTime;
@Deprecated // Morphia
public CollectionRecord() {}
public CollectionRecord(int configId, long expiredTime) {
this.configId = configId;
this.expiredTime = expiredTime;
}
public int getConfigId() {
return configId;
}
public long getExpiredTime() {
return expiredTime;
}
}
}