Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into Nukkit-PM1E
Browse files Browse the repository at this point in the history
# Conflicts:
#	pom.xml
  • Loading branch information
lt-name committed May 7, 2024
2 parents 339e9ef + 59725aa commit f3754be
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>cn.lanink</groupId>
<artifactId>MemoriesOfTime-GameCore</artifactId>
<version>1.6.13-PM1E<!-- -SNAPSHOT--></version>
<version>1.6.14-PM1E-SNAPSHOT</version>

<name>MemoriesOfTime-GameCore</name>
<description>MemoriesOfTime-GameCore -- A dependency</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,9 @@ public EntityPlayerCorpse(FullChunk chunk, CompoundTag nbt) {
public void saveNBT() {
//不保存数据
}

// 不保存实体 (兼容nkx leveldb分支)
public boolean canSaveToStorage() {
return false;
}
}
12 changes: 9 additions & 3 deletions src/main/java/cn/lanink/gamecore/entity/ITextFakeEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
public interface ITextFakeEntity {

void setPosition(Position position);
void setPosition(@NotNull Position position);

Position getPosition();

Expand All @@ -33,10 +33,16 @@ default boolean needAsyncTick() {

void onAsyncTick(int i);

void spawnTo(Player player);
void spawnTo(@NotNull Player player);

void despawnFrom(Player player);
void despawnFrom(@NotNull Player player);

void close();

boolean canSee(@NotNull Player player);

void hideToPlayer(@NotNull Player player);

void showToPlayer(@NotNull Player player);

}
5 changes: 5 additions & 0 deletions src/main/java/cn/lanink/gamecore/entity/RobotEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ public RobotEntity(FullChunk chunk, CompoundTag nbt) {
public void saveNBT() {
//不保存数据
}

// 不保存实体 (兼容nkx leveldb分支)
public boolean canSaveToStorage() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class TextFakeTextFakeEntity extends Position implements ITextFakeEntity
@Getter
private int maxCanSeeDistance = 16 * Server.getInstance().getViewDistance();

protected final Set<Player> hiddenPlayers = Collections.newSetFromMap(new ConcurrentHashMap<>());

public TextFakeTextFakeEntity() {
this.id = Entity.entityCount++;
}
Expand All @@ -69,6 +71,7 @@ public TextFakeTextFakeEntity(long id) {
this.id = id;
}

@Override
public void setPosition(@NotNull Position position) {
this.x = position.getX();
this.y = position.getY();
Expand All @@ -88,6 +91,7 @@ public void setPosition(@NotNull Position position) {
}
}

@Override
public Position getPosition() {
return this;
}
Expand All @@ -96,21 +100,25 @@ public void setShowText(@NotNull String showText) {
this.defaultShowText = showText;
}

@Override
public void setShowText(@NotNull Player player, @NotNull String showText) {
this.showTextMap.put(player, showText);
}

@Override
public void setMaxCanSeeDistance(int maxCanSeeDistance) {
if (maxCanSeeDistance < 1) {
maxCanSeeDistance = 1;
}
this.maxCanSeeDistance = maxCanSeeDistance;
}

@Override
public boolean needTick() {
return false;
}

@Override
public void onTick(int i) {
try {
throw new RuntimeException();
Expand All @@ -119,10 +127,12 @@ public void onTick(int i) {
}
}

@Override
public boolean needAsyncTick() {
return true;
}

@Override
public void onAsyncTick(int i) {
if (this.isClosed() || i%20 != 0) {
return;
Expand All @@ -148,7 +158,7 @@ public void onAsyncTick(int i) {
for (Map.Entry<Player, String> entry : this.getShowTextMap().entrySet()) {
if (entry.getKey().getLevel() == this.getLevel() &&
this.distance(entry.getKey()) <= this.getMaxCanSeeDistance()) {
if (!this.hasSpawned.contains(entry.getKey()) || i%2400 == 0) {
if (!this.hasSpawned.contains(entry.getKey()) || i % 2400 == 0) {
this.spawnTo(entry.getKey());
}
this.sendText(entry.getKey(), entry.getValue());
Expand All @@ -168,7 +178,11 @@ public boolean hasDefaultShowText() {
return this.defaultShowText != null && !this.defaultShowText.isEmpty();
}

@Override
public void spawnTo(@NotNull Player player) {
if (!this.canSee(player)) {
return;
}
if (this.hasSpawned.contains(player)) {
this.despawnFrom(player);
}
Expand All @@ -190,6 +204,7 @@ public void spawnTo(@NotNull Player player) {
player.dataPacket(pk);
}

@Override
public void despawnFrom(@NotNull Player player) {
if (this.hasSpawned.contains(player)) {
RemoveEntityPacket pk = new RemoveEntityPacket();
Expand All @@ -199,6 +214,7 @@ public void despawnFrom(@NotNull Player player) {
}
}

@Override
public void close() {
this.closed = true;
this.getShowTextMap().clear();
Expand All @@ -224,4 +240,19 @@ private void sendData(@NotNull Player[] players, @NotNull EntityMetadata data) {
}
}

public boolean canSee(@NotNull Player player) {
return !this.hiddenPlayers.contains(player);
}

public void hideToPlayer(@NotNull Player player) {
this.hiddenPlayers.add( player);
this.despawnFrom(player);
}

public void showToPlayer(@NotNull Player player) {
this.hiddenPlayers.remove(player);
if (player.isOnline()) {
this.spawnTo(player);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,23 @@ public class FloatingTextUtils {
private static final HashMap<Long, TextFakeTextFakeEntity> ENTITY_MAP = new HashMap<>();

/**
* 临时显示一个浮空字
* 生成一个浮空字实体
*
* @param position 显示位置
* @param showText 显示的文字
* @return 浮空字实体
*/
public static TextFakeTextFakeEntity showTextTemporary(@NotNull Position position, @NotNull String showText) {
return showTextTemporary(position, showText, -1);
}

/**
* 生成一个浮空字实体,并在指定时间后自动关闭
*
* @param position 显示位置
* @param showText 显示的文字
* @param showTick 显示时间(tick)
* @return 浮空字实体
*/
public static TextFakeTextFakeEntity showTextTemporary(@NotNull Position position, @NotNull String showText, int showTick) {
TextFakeTextFakeEntity textFakeEntity = new TextFakeTextFakeEntity(getIdleID());
Expand All @@ -45,6 +61,8 @@ public static long getIdleID() {

public static class TickTask extends PluginTask<GameCore> {

private int tick = 0;

public TickTask(GameCore owner) {
super(owner);
}
Expand All @@ -54,17 +72,20 @@ public void onRun(int i) {
for (TextFakeTextFakeEntity textFakeEntity : ENTITY_MAP.values()) {
try {
if (textFakeEntity.needTick()) {
textFakeEntity.onTick(i);
textFakeEntity.onTick(this.tick);
}
}catch (Exception e) {
} catch (Exception e) {
GameCore.getInstance().getLogger().error("FloatingTextUtils-TickTask", e);
}
}
this.tick++;
}
}

public static class AsyncTickTask extends PluginTask<GameCore> {

private int tick = 0;

public AsyncTickTask(GameCore owner) {
super(owner);
}
Expand All @@ -74,12 +95,13 @@ public void onRun(int i) {
for (TextFakeTextFakeEntity textFakeEntity : ENTITY_MAP.values()) {
try {
if (textFakeEntity.needAsyncTick()) {
textFakeEntity.onAsyncTick(i);
textFakeEntity.onAsyncTick(this.tick);
}
}catch (Exception e) {
GameCore.getInstance().getLogger().error("FloatingTextUtils-AsyncTickTask", e);
}
}
this.tick++;
}

@Override
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/cn/lanink/gamecore/ranking/RankingFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.util.TreeMap;

/**
* 排行榜格式配置
*
* @author lt_name
*/
@Setter
Expand Down Expand Up @@ -53,12 +55,25 @@ public RankingFormat(String top, String line, String lineSelf, String bottom, So
this.showLine.putAll(showLine);
}


/**
* 排序方式
*/
public enum SortOrder {
/**
* 升序
*/
ASCENDING,
/**
* 降序
*/
DESCENDING
}

/**
* 获取默认格式
*
* @return 默认格式
*/
public static RankingFormat getDefaultFormat() {
return defaultFormat.clone();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public void removeRanking(@NotNull Ranking ranking) {
public void onRun(int i) {
for (Ranking ranking : this.updateRankings) {
try {
ranking.onAsyncTick(tick);
ranking.onAsyncTick(this.tick);
}catch (Exception e) {
GameCore.getInstance().getLogger().error("Ranking " + ranking.getClass().getName() + " onAsyncTick error: ", e);
}
}
tick++;
this.tick++;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
public class UpdateTask extends PluginTask<GameCore> implements IRankingAPITask {

private int tick = 0;

private final Set<Ranking> updateRankings = Collections.newSetFromMap(new ConcurrentHashMap<>());

public UpdateTask(GameCore owner) {
Expand All @@ -40,11 +42,12 @@ public void removeRanking(@NotNull Ranking ranking) {
public void onRun(int i) {
for (Ranking ranking : this.updateRankings) {
try {
ranking.onTick(i);
ranking.onTick(this.tick);
}catch (Exception e) {
GameCore.getInstance().getLogger().error("Ranking " + ranking.getClass().getName() + " onTick error: ", e);
}
}
this.tick++;
}

@Override
Expand Down

0 comments on commit f3754be

Please sign in to comment.