diff --git a/README.md b/README.md
index 6315dfa..936544b 100644
--- a/README.md
+++ b/README.md
@@ -23,7 +23,7 @@
com.github.Be4rJP
Parallel
- v1.0.9
+ v1.1.0
provided
```
diff --git a/pom.xml b/pom.xml
index be5c385..757c4da 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
be4rjp
Parallel
- 1.0.9
+ 1.1.0
jar
Parallel
diff --git a/src/main/java/be4rjp/parallel/Config.java b/src/main/java/be4rjp/parallel/Config.java
index 5ba665e..396bb72 100644
--- a/src/main/java/be4rjp/parallel/Config.java
+++ b/src/main/java/be4rjp/parallel/Config.java
@@ -10,10 +10,14 @@ public class Config {
private static boolean performanceMode = false;
+ private static boolean rewriteLightPacket = true;
+
public static WorkType getWorkType() {return workType;}
public static boolean isPerformanceMode() {return performanceMode;}
+ public static boolean isRewriteLightPacket() {return rewriteLightPacket;}
+
public static void load(){
File file = new File("plugins/Parallel", "config.yml");
file.getParentFile().mkdirs();
@@ -27,6 +31,7 @@ public static void load(){
if(yml.contains("work-type")) workType = WorkType.valueOf(yml.getString("work-type"));
if(yml.contains("performance-mode")) performanceMode = yml.getBoolean("performance-mode");
+ if(yml.contains("rewrite-light-packet")) rewriteLightPacket = yml.getBoolean("rewrite-light-packet");
}
public enum WorkType{
diff --git a/src/main/java/be4rjp/parallel/ParallelWorld.java b/src/main/java/be4rjp/parallel/ParallelWorld.java
index 1e2988a..304965b 100644
--- a/src/main/java/be4rjp/parallel/ParallelWorld.java
+++ b/src/main/java/be4rjp/parallel/ParallelWorld.java
@@ -18,13 +18,13 @@
*/
public class ParallelWorld {
- private static Map worldMap;
+ private static Map worldMap;
private static final ParallelWorld onlyOneWorld;
static {
initialize();
- onlyOneWorld = new ParallelWorld("");
+ onlyOneWorld = new ParallelWorld(UUID.randomUUID());
}
public static void initialize(){
@@ -32,10 +32,14 @@ public static void initialize(){
}
public static synchronized ParallelWorld getParallelWorld(Player player){
- return getParallelWorld(player.getUniqueId().toString());
+ return getParallelWorld(player.getUniqueId());
}
- public static synchronized ParallelWorld getParallelWorld(String uuid){
+ public static synchronized ParallelWorld getParallelWorld(String uuidString){
+ return getParallelWorld(UUID.fromString(uuidString));
+ }
+
+ public static synchronized ParallelWorld getParallelWorld(UUID uuid){
if(Config.getWorkType() == Config.WorkType.NORMAL) {
if (worldMap.containsKey(uuid)) return worldMap.get(uuid);
return new ParallelWorld(uuid);
@@ -45,18 +49,22 @@ public static synchronized ParallelWorld getParallelWorld(String uuid){
}
public static synchronized void removeParallelWorld(String uuid){
+ worldMap.remove(UUID.fromString(uuid));
+ }
+
+ public static synchronized void removeParallelWorld(UUID uuid){
worldMap.remove(uuid);
}
- private final String uuid;
+ private final UUID uuid;
private final Map> chunkBlockMap;
private final Map editedPacketForChunkMap;
private final Map editedPacketForLightMap;
- private ParallelWorld(String uuid){
+ private ParallelWorld(UUID uuid){
this.uuid = uuid;
this.chunkBlockMap = new ConcurrentHashMap<>();
this.editedPacketForChunkMap = new ConcurrentHashMap<>();
@@ -107,12 +115,8 @@ public void setBlock(Block block, BlockData blockData, boolean blockUpdate){
pBlockData.setBlockData(blockData);
if(block.getChunk().isLoaded() && blockUpdate) {
- for(Player player : Bukkit.getServer().getOnlinePlayers()) {
- if (player.getUniqueId().toString().equals(uuid)) {
- player.sendBlockChange(block.getLocation(), blockData);
- break;
- }
- }
+ Player player = Bukkit.getPlayer(uuid);
+ if(player != null) player.sendBlockChange(block.getLocation(), blockData);
}
}
@@ -171,7 +175,7 @@ public void setBlocks(Map blockDataMap, @Nullable UpdatePacket
if(Config.getWorkType() == Config.WorkType.NORMAL) {
- Player player = Bukkit.getPlayer(UUID.fromString(uuid));
+ Player player = Bukkit.getPlayer(uuid);
if (player == null) return;
this.sendUpdatePacket(player, type, updateMap);
}else{
@@ -310,7 +314,7 @@ public void setBlocks(Map blockDataMap, boolean chunkUpdate){
if(!chunkUpdate) return;
- Player player = Bukkit.getPlayer(UUID.fromString(uuid));
+ Player player = Bukkit.getPlayer(uuid);
if(player == null) return;
for(Chunk chunk : chunkSet) {
@@ -358,7 +362,7 @@ public void setLightLevels(Map lightLevelMap){
/**
* 指定されたブロックに設定されているデータを削除します
- * @param block
+ * @param block データを削除するブロック
*/
public void removeBlock(Block block){
BlockLocation location = BlockLocation.createBlockLocation(block);
@@ -371,6 +375,55 @@ public void removeBlock(Block block){
}
+ /**
+ * 指定されたブロックに設定されているデータを削除します
+ * @param block データを削除するブロック
+ * @param update ブロックの変更をプレイヤーに通知するかどうか
+ */
+ public void removeBlock(Block block, boolean update){
+ removeBlock(block);
+ Player player = Bukkit.getPlayer(uuid);
+ if(player != null) player.sendBlockChange(block.getLocation(), block.getBlockData());
+ }
+
+ /**
+ * 一気に大量のブロックのデータを削除します。
+ * @param blocks データを削除するブロック
+ * @param type ブロックの変更をクライアントに適用させるためのパケットの種類。 MULTI_BLOCK_CHANGE推奨
+ */
+ public void removeBlocks(Set blocks, @Nullable UpdatePacketType type){
+ if(type == null) type = UpdatePacketType.NO_UPDATE;
+
+ Map> updateMap = new HashMap<>();
+
+ for(Block block : blocks){
+ Location location = block.getLocation();
+ ChunkPosition chunkPosition = new ChunkPosition(location.getBlockX(), location.getBlockZ());
+ this.addEditedChunk(chunkPosition, block.getWorld());
+
+ Map blockMap = chunkBlockMap.get(chunkPosition);
+ if(blockMap != null){
+ blockMap.remove(BlockLocation.createBlockLocation(block));
+ }
+
+ Set updateBlocks = updateMap.computeIfAbsent(block.getChunk(), k -> new HashSet<>());
+ updateBlocks.add(block);
+ }
+
+
+ if(Config.getWorkType() == Config.WorkType.NORMAL) {
+ Player player = Bukkit.getPlayer(uuid);
+ if (player == null) return;
+ this.sendUpdatePacket(player, type, updateMap);
+ }else{
+ Set players = new HashSet<>(Bukkit.getOnlinePlayers());
+ for(Player player : players){
+ this.sendUpdatePacket(player, type, updateMap);
+ }
+ }
+ }
+
+
/**
* ブロックデータを取得します
* @param block 取得したいブロック
diff --git a/src/main/java/be4rjp/parallel/nms/PacketHandler.java b/src/main/java/be4rjp/parallel/nms/PacketHandler.java
index bef267b..6c5c139 100644
--- a/src/main/java/be4rjp/parallel/nms/PacketHandler.java
+++ b/src/main/java/be4rjp/parallel/nms/PacketHandler.java
@@ -1,4 +1,5 @@
package be4rjp.parallel.nms;
+import be4rjp.parallel.Config;
import be4rjp.parallel.Parallel;
import be4rjp.parallel.nms.manager.*;
import io.netty.channel.*;
@@ -35,7 +36,7 @@ public void write(ChannelHandlerContext channelHandlerContext, Object packet, Ch
return;
}
- if(packet.getClass().getSimpleName().equalsIgnoreCase("PacketPlayOutLightUpdate")){
+ if(packet.getClass().getSimpleName().equalsIgnoreCase("PacketPlayOutLightUpdate") && Config.isRewriteLightPacket()){
LightUpdatePacketManager manager = new LightUpdatePacketManager(channelHandlerContext, packet, channelPromise, this, player);
manager.runTaskAsynchronously(Parallel.getPlugin());
return;
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 6e40ff1..88c296d 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -2,11 +2,13 @@
# 動作モードの設定
# NORMAL or ONLY_ONE
# ONLY_ONEに設定した場合は全てのプレイヤーに対して同じParallelWorldが使われるようになります
-
work-type: NORMAL
# パフォーマンスモードを使用するかどうかの設定
# このプラグイン以外でブロックの設置が行われる可能性のある場合は false 推奨
+performance-mode: false
+
-performance-mode: false
\ No newline at end of file
+## ライトパケットへの介入を行うかどうかの設定
+rewrite-light-packet: true
\ No newline at end of file