Skip to content

Commit

Permalink
1.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
NCT-skyouo committed Oct 21, 2022
1 parent 835d101 commit 5be46c8
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 31 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<name>NatureRevive</name>

<properties>
<java.version>1.8</java.version>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@ public void onEnable() {
};
}, 20L, 2L);

getServer().getScheduler().runTaskTimer(this, () -> {
for (int i = 0; i < NatureRevive.readonlyConfig.blockExplosionProcessingAmountPerProcessing && blockExplosionQueue.hasNext(); i++) {
getServer().getScheduler().runTaskTimerAsynchronously(this, () -> {
for (int i = 0; i < NatureRevive.readonlyConfig.blockProcessingAmountPerProcessing && blockExplosionQueue.hasNext(); i++) {
ChunkRelatedEventListener.flagChunk(blockExplosionQueue.pop());
}
}, 20L, NatureRevive.readonlyConfig.blockExplosionProcessingTick);
}, 20L, NatureRevive.readonlyConfig.blockProcessingTick);

getServer().getScheduler().runTaskTimer(this, () -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ReadonlyConfig {

private YamlConfiguration configuration;

public final int CONFIG_VERSION = 10;
public final int CONFIG_VERSION = 11;

public boolean debug;

Expand Down Expand Up @@ -49,9 +49,9 @@ public class ReadonlyConfig {

public int maxPlayersCountForRegeneration;

public int blockExplosionProcessingTick;
public int blockProcessingTick;

public int blockExplosionProcessingAmountPerProcessing;
public int blockProcessingAmountPerProcessing;

public String coreProtectUserName;

Expand Down Expand Up @@ -225,15 +225,15 @@ public ReadonlyConfig() {
"When passive is chosen, the plugin will only regenrate chunk on player visited, this method will reduce performance cost but not all the expired chunks will be regenerated."
));

configuration.set("block-explosion-queue-process-per-n-tick", 10);
configuration.setComments("block-explosion-queue-process-per-n-tick",
Arrays.asList("每 n 個 tick 處理一次爆炸影響之區塊計算 (1 tick = 50ms)",
"Proceeding the block/entity explosions affected chunks calculation function every n tick(s).")
configuration.set("block-queue-process-per-n-tick", 10);
configuration.setComments("block-queue-process-per-n-tick",
Arrays.asList("每 n 個 tick 處理一次事件影響之區塊計算 (1 tick = 50ms)",
"Proceeding the chunks flagging function every n tick(s).")
);

configuration.set("block-explosion-queue-process-per-time", 200);
configuration.setComments("block-explosion-queue-process-per-time", Arrays.asList("每次可以處理幾個被爆炸範圍影響的方塊.",
"How many block(s) to calculate per explosion process period.")
configuration.set("block-queue-process-per-time", 200);
configuration.setComments("block-queue-process-per-time", Arrays.asList("每次可以處理幾個被事件影響的方塊.",
"How many block(s) to calculate per chunk flagging process period.")
);

configuration.set("storage.method", "yaml");
Expand Down Expand Up @@ -432,6 +432,12 @@ private void updateConfigurations(int version) {
configuration.setComments("block-explosion-queue-process-per-time", Arrays.asList("每次可以處理幾個被爆炸範圍影響的方塊.",
"How many block(s) to calculate per explosion process period.")
);
case 10:
configuration.set("block-queue-process-per-n-tick", configuration.getInt("block-explosion-queue-process-per-n-tick"));
configuration.set("block-queue-process-per-time", configuration.getInt("block-explosion-queue-process-per-time"));

configuration.set("block-explosion-queue-process-per-n-tick", null);
configuration.set("block-explosion-queue-process-per-time", null);
default:
configuration.set("config-version", CONFIG_VERSION);
try {
Expand Down Expand Up @@ -461,8 +467,8 @@ public void reloadConfig() {
minTPSCountForRegeneration = configuration.getDouble("min-tps-for-regenerate-chunk", 16.0);
maxPlayersCountForRegeneration = configuration.getInt("max-players-for-regenerate-chunk", 40);
regenerationStrategy = configuration.getString("regeneration-strategy", "aggressive");
blockExplosionProcessingTick = configuration.getInt("block-explosion-queue-process-per-n-tick", 10);
blockExplosionProcessingAmountPerProcessing = configuration.getInt("block-explosion-queue-process-per-time", 200);
blockProcessingTick = configuration.getInt("block-queue-process-per-n-tick", 10);
blockProcessingAmountPerProcessing = configuration.getInt("block-queue-process-per-time", 200);

ttlDuration = parseDuration(configuration.getString("ttl-duration", "7d"));
coreProtectUserName = configuration.getString("coreprotect-log-username", "#資源再生");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public PositionInfo get(Location location) {
if (cache.containsKey(location))
return cache.get(location);

/*
try (Connection connection = hikari.getConnection(); Statement statement = connection.createStatement()) {
ResultSet resultSet = statement
.executeQuery("SELECT * FROM " + NatureRevive.readonlyConfig.databaseTableName + " WHERE X = " + chunkPos.chunkX + " AND Z = " + chunkPos.chunkZ + " AND WORLDNAME = '" + location.getWorld().getName() + "';");
Expand All @@ -114,6 +116,10 @@ public PositionInfo get(Location location) {
e.printStackTrace();
return null;
}
*/ // NCT skyouo - do not perform further lookup

return null;
}

public PositionInfo getNoCache(PositionInfo positionInfo) {
Expand Down Expand Up @@ -148,6 +154,8 @@ public PositionInfo get(PositionInfo positionInfo) {
if (cache.containsKey(positionInfo.getLocation()))
return cache.get(positionInfo.getLocation());

/*
try (Connection connection = hikari.getConnection(); Statement statement = connection.createStatement()) {
ResultSet resultSet = statement
.executeQuery("SELECT * FROM " + NatureRevive.readonlyConfig.databaseTableName + " WHERE X = " + chunkPos.chunkX + " AND Z = " + chunkPos.chunkZ + " AND WORLDNAME = '" + positionInfo.getLocation().getWorld().getName() + "';");
Expand All @@ -169,14 +177,18 @@ public PositionInfo get(PositionInfo positionInfo) {
e.printStackTrace();
return null;
}
*/ // NCT skyouo - do not perform further lookup

return null;
}


public List<PositionInfo> values() {
ArrayList<PositionInfo> positionInfos = new ArrayList<>();

if (!cache.isEmpty())
return new ArrayList<>(cache.values());
return List.copyOf(cache.values());

try (Connection connection = hikari.getConnection(); Statement statement = connection.createStatement()) {
ResultSet resultSet = statement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public PositionInfo get(Location location) {
if (cache.containsKey(location))
return cache.get(location);

/*
try {
ResultSet resultSet = connection.createStatement()
.executeQuery("SELECT * FROM locations WHERE X = " + chunkPos.chunkX + " AND Z = " + chunkPos.chunkZ + " AND WORLDNAME = '" + location.getWorld().getName() + "';");
Expand All @@ -100,6 +102,10 @@ public PositionInfo get(Location location) {
e.printStackTrace();
return null;
}
*/ // NCT skyouo - do not perform further lookup

return null;
}

public PositionInfo get(PositionInfo positionInfo) {
Expand All @@ -108,6 +114,8 @@ public PositionInfo get(PositionInfo positionInfo) {
if (cache.containsKey(positionInfo.getLocation()))
return cache.get(positionInfo.getLocation());

/*
try {
ResultSet resultSet = connection.createStatement()
.executeQuery("SELECT * FROM locations WHERE X = " + chunkPos.chunkX + " AND Z = " + chunkPos.chunkZ + " AND WORLDNAME = '" + positionInfo.getLocation().getWorld().getName() + "';");
Expand All @@ -126,6 +134,10 @@ public PositionInfo get(PositionInfo positionInfo) {
e.printStackTrace();
return null;
}
*/ // NCT skyouo - do not perform further lookup.

return null;
}

public List<PositionInfo> values() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,15 @@ public void onBlockBreakEvent(BlockBreakEvent event) {
return;


log(event, event.getBlock().getLocation());
flagChunk(event.getBlock().getLocation());
NatureRevive.blockExplosionQueue.add(event.getBlock().getLocation());
}

@EventHandler(priority = EventPriority.MONITOR)
public void onBlockPlaceEvent(BlockPlaceEvent event) {
if (event.isCancelled())
return;

log(event, event.getBlock().getLocation());
flagChunk(event.getBlock().getLocation());
NatureRevive.blockExplosionQueue.add(event.getBlock().getLocation());
}

/*
Expand All @@ -57,8 +55,7 @@ public void onBlockCookEvent(BlockCookEvent event) {
if (event.isCancelled())
return;

log(event, event.getBlock().getLocation());
flagChunk(event.getBlock().getLocation());
NatureRevive.blockExplosionQueue.add(event.getBlock().getLocation());
}


Expand All @@ -70,8 +67,7 @@ public void onEntityDeathEvent(EntityDeathEvent event) {
if (event.getEntity().getKiller() == null)
return;

log(event, event.getEntity().getLocation());
flagChunk(event.getEntity().getLocation());
NatureRevive.blockExplosionQueue.add(event.getEntity().getLocation());
}

@EventHandler(priority = EventPriority.MONITOR)
Expand Down Expand Up @@ -108,14 +104,12 @@ public void onEntityExplodeEvent(EntityExplodeEvent event) {

@EventHandler(priority = EventPriority.MONITOR)
public void onBrewEvent(BrewEvent event) {
log(event, event.getBlock().getLocation());
flagChunk(event.getBlock().getLocation());
NatureRevive.blockExplosionQueue.add(event.getBlock().getLocation());
}

@EventHandler(priority = EventPriority.MONITOR)
public void onFurnaceBurnEvent(FurnaceBurnEvent event) {
log(event, event.getBlock().getLocation());
flagChunk(event.getBlock().getLocation());
NatureRevive.blockExplosionQueue.add(event.getBlock().getLocation());
}

@EventHandler(priority = EventPriority.MONITOR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ public static void randomizeChunkOre(Chunk chunk) {
Lists.reverse(pairList);

for (int i = 0; i < oreList.size(); i++) {
if ((i + 1) > pairList.size()) {
if (NatureRevive.readonlyConfig.debug)
System.out.println("[DEBUG] Cannot fully obfuscate ores at chunk[x=" + chunk.getX() + ", z=" + chunk.getZ() + ", world=" + chunk.getWorld().getName() + "] (ores count: " + oreList.size() + ", replaced count: " + pairList.size() + ")!");
break;
}

Location loc = pairList.get(i).first();

Block ore = oreList.get(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ private void savingMovableStructure(Chunk chunk, ChunkSnapshot oldChunkSnapshot)
for (int z = 0; z < 16; z++) {
Material blockType = oldChunkSnapshot.getBlockType(x, y, z);
Location originLocation = new Location(chunk.getWorld(), (chunk.getX() << 4) + x, y, (chunk.getZ() << 4) + z);

if ((blockType.equals(Material.END_PORTAL) || blockType.equals(Material.END_GATEWAY)) && !perversedBlocks.containsKey(originLocation)) {

for (int i = -2; i <= 2; i++)
Expand Down Expand Up @@ -367,10 +368,15 @@ private void savingMovableStructure(Chunk chunk, ChunkSnapshot oldChunkSnapshot)
if (perversedBlocks.containsKey(neighborLocation)) {
perversedBlocks.put(originLocation, oldChunkSnapshot.getBlockData(x, y, z));
}
} else if (blockType.equals(Material.TORCH)) {
} else if (blockType.equals(Material.WALL_TORCH)) {
if (!chunk.getWorld().getEnvironment().equals(World.Environment.THE_END))
continue;

if (isInSpecialChunks(chunk)) {
perversedBlocks.put(originLocation, oldChunkSnapshot.getBlockData(x, y, z));
continue;
}

for (int i = -1; i <= 1; i++)
for (int k = -1; k <= 1; k++) {
Location neighborLocation = originLocation.clone().add(i, 0, k);
Expand Down Expand Up @@ -509,7 +515,7 @@ private static boolean isNotInTheChunk(Chunk chunk, Location location) {

// The method is hardcoded to detect the end gateway.
private static boolean isInSpecialChunks(Chunk chunk) {
return (chunk.getX() == 0 || chunk.getX() == -1) && (chunk.getZ() == 0 || chunk.getZ() == 1);
return (chunk.getX() == 0 || chunk.getX() == -1) && (chunk.getZ() == 0 || chunk.getZ() == -1);
}

private static int[] convertLocationToInChunkXYZ(Location location) {
Expand Down

0 comments on commit 5be46c8

Please sign in to comment.