diff --git a/common/src/main/java/ru/beykerykt/lightapi/chunks/ChunkInfo.java b/common/src/main/java/ru/beykerykt/lightapi/chunks/ChunkInfo.java
index c5c33b74..ea2f911f 100644
--- a/common/src/main/java/ru/beykerykt/lightapi/chunks/ChunkInfo.java
+++ b/common/src/main/java/ru/beykerykt/lightapi/chunks/ChunkInfo.java
@@ -35,9 +35,6 @@ public class ChunkInfo {
private int x;
private int y;
private int z;
-
- @SuppressWarnings("DeprecatedIsStillUsed")
- @Deprecated // Bukkit.getOnlinePlayers() will be examined
private Collection extends Player> receivers;
@Deprecated
@@ -45,7 +42,6 @@ public ChunkInfo(World world, int chunkX, int chunkZ, Collection extends Playe
this(world, chunkX, 256, chunkZ, players);
}
- @SuppressWarnings("deprecation")
public ChunkInfo(World world, int chunkX, int chunk_y_height, int chunkZ, Collection extends Player> players) {
this.world = world;
this.x = chunkX;
@@ -70,16 +66,15 @@ public int getChunkYHeight() {
return y;
}
+ @SuppressWarnings("unused")
public void setChunkYHeight(int y) {
this.y = y;
}
- @Deprecated
public Collection extends Player> getReceivers() {
return receivers;
}
- @Deprecated
public void setReceivers(Collection extends Player> receivers) {
this.receivers = receivers;
}
diff --git a/plugin/pom.xml b/plugin/pom.xml
index d910d628..fc25e09f 100644
--- a/plugin/pom.xml
+++ b/plugin/pom.xml
@@ -6,7 +6,7 @@
ru.beykerykt
LightAPI-fork
- 3.3.1
+ 3.3.2
1.6
diff --git a/plugin/src/main/java/ru/beykerykt/lightapi/LightAPI.java b/plugin/src/main/java/ru/beykerykt/lightapi/LightAPI.java
index ecb7cd6d..b2e0a39a 100644
--- a/plugin/src/main/java/ru/beykerykt/lightapi/LightAPI.java
+++ b/plugin/src/main/java/ru/beykerykt/lightapi/LightAPI.java
@@ -354,11 +354,16 @@ public static boolean updateChunks(ChunkInfo info) {
@SuppressWarnings("WeakerAccess")
public static boolean updateChunk(ChunkInfo info) {
+ return updateChunk(info, null);
+ }
+
+ @SuppressWarnings("WeakerAccess")
+ public static boolean updateChunk(ChunkInfo info, Collection extends Player> players) {
if (getInstance().isEnabled()) {
UpdateChunkEvent event = new UpdateChunkEvent(info);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
- machine.addChunkToUpdate(info);
+ machine.addChunkToUpdate(info, players);
return true;
}
}
diff --git a/plugin/src/main/java/ru/beykerykt/lightapi/chunks/ChunkUpdateInfo.java b/plugin/src/main/java/ru/beykerykt/lightapi/chunks/ChunkUpdateInfo.java
new file mode 100644
index 00000000..4bd1dfa8
--- /dev/null
+++ b/plugin/src/main/java/ru/beykerykt/lightapi/chunks/ChunkUpdateInfo.java
@@ -0,0 +1,52 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2019 Qveshn
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package ru.beykerykt.lightapi.chunks;
+
+import org.bukkit.entity.Player;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+public class ChunkUpdateInfo {
+
+ private int sectionMask = 0;
+ private Collection players = new HashSet();
+
+ public void add(int sectionMask, Collection extends Player> players) {
+ this.sectionMask |= sectionMask;
+ add(players);
+ }
+
+ private void add(Collection extends Player> players) {
+ this.players.addAll(players);
+ }
+
+ public Collection getPlayers() {
+ return players;
+ }
+
+ public int getSectionMask() {
+ return sectionMask;
+ }
+}
diff --git a/plugin/src/main/java/ru/beykerykt/lightapi/request/RequestSteamMachine.java b/plugin/src/main/java/ru/beykerykt/lightapi/request/RequestSteamMachine.java
index dc689f40..61051319 100644
--- a/plugin/src/main/java/ru/beykerykt/lightapi/request/RequestSteamMachine.java
+++ b/plugin/src/main/java/ru/beykerykt/lightapi/request/RequestSteamMachine.java
@@ -2,6 +2,7 @@
* The MIT License (MIT)
*
* Copyright (c) 2016 Vladimir Mikhailov
+ * Copyright (c) 2019 Qveshn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -23,10 +24,10 @@
*/
package ru.beykerykt.lightapi.request;
-import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import ru.beykerykt.lightapi.chunks.ChunkInfo;
import ru.beykerykt.lightapi.chunks.ChunkLocation;
+import ru.beykerykt.lightapi.chunks.ChunkUpdateInfo;
import ru.beykerykt.lightapi.server.ServerModManager;
import ru.beykerykt.lightapi.server.nms.INMSHandler;
import ru.beykerykt.lightapi.utils.Debug;
@@ -39,6 +40,7 @@ public class RequestSteamMachine implements Runnable {
private boolean isStarted;
private Queue REQUEST_QUEUE = new ConcurrentLinkedQueue();
private int maxIterationsPerTick;
+ private Map chunksToUpdate = new HashMap();
// THREADS
private ScheduledFuture> sch;
@@ -75,19 +77,23 @@ public boolean addToQueue(Runnable request) {
return false;
}
- private Map chunksToUpdate = new HashMap();
-
- public void addChunkToUpdate(ChunkInfo info) {
+ public void addChunkToUpdate(final ChunkInfo info, Collection extends Player> receivers) {
int SectionY = info.getChunkYHeight() >> 4;
INMSHandler nmsHandler = ServerModManager.getNMSHandler();
if (nmsHandler.isValidSectionY(SectionY)) {
final ChunkLocation chunk = new ChunkLocation(info.getWorld(), info.getChunkX(), info.getChunkZ());
final int sectionYMask = nmsHandler.asSectionMask(SectionY);
+ final Collection players = new ArrayList(
+ receivers != null ? receivers : info.getReceivers()
+ );
addToQueue(new Runnable() {
@Override
public void run() {
- Integer sectionMask = chunksToUpdate.get(chunk);
- chunksToUpdate.put(chunk, (sectionMask == null ? 0 : sectionMask) | sectionYMask);
+ ChunkUpdateInfo chunkUpdateInfo = chunksToUpdate.get(chunk);
+ if (chunkUpdateInfo == null) {
+ chunksToUpdate.put(chunk, chunkUpdateInfo = new ChunkUpdateInfo());
+ }
+ chunkUpdateInfo.add(sectionYMask, players);
}
});
}
@@ -112,18 +118,18 @@ public void run() {
}
INMSHandler nmsHandler = ServerModManager.getNMSHandler();
- Collection extends Player> players = Bukkit.getOnlinePlayers();
- for (Map.Entry item : chunksToUpdate.entrySet()) {
+ for (Map.Entry item : chunksToUpdate.entrySet()) {
ChunkLocation chunk = item.getKey();
- int sectionMask = item.getValue();
- Collection extends Player> p =
- nmsHandler.filterVisiblePlayers(chunk.getWorld(), chunk.getX(), chunk.getZ(), players);
- nmsHandler.sendChunkSectionsUpdate(chunk.getWorld(), chunk.getX(), chunk.getZ(), sectionMask, p);
+ ChunkUpdateInfo chunkUpdateInfo = item.getValue();
+ int sectionMask = chunkUpdateInfo.getSectionMask();
+ Collection extends Player> players = nmsHandler.filterVisiblePlayers(
+ chunk.getWorld(), chunk.getX(), chunk.getZ(), chunkUpdateInfo.getPlayers());
+ nmsHandler.sendChunkSectionsUpdate(chunk.getWorld(), chunk.getX(), chunk.getZ(), sectionMask, players);
if (debug) {
- totalSends += p.size();
+ totalSends += players.size();
totalSections += Integer.bitCount(sectionMask);
- usedPlayers.addAll(p);
+ usedPlayers.addAll(players);
}
}