forked from BeYkeRYkt/LightAPI
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3.3.2] Allowed to redefine recievers when sending chunk changes to c…
…lients (updateChunk)
- Loading branch information
Showing
5 changed files
with
80 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
plugin/src/main/java/ru/beykerykt/lightapi/chunks/ChunkUpdateInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Player> players = new HashSet<Player>(); | ||
|
||
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<Player> getPlayers() { | ||
return players; | ||
} | ||
|
||
public int getSectionMask() { | ||
return sectionMask; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 Vladimir Mikhailov <[email protected]> | ||
* 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<Runnable> REQUEST_QUEUE = new ConcurrentLinkedQueue<Runnable>(); | ||
private int maxIterationsPerTick; | ||
private Map<ChunkLocation, ChunkUpdateInfo> chunksToUpdate = new HashMap<ChunkLocation, ChunkUpdateInfo>(); | ||
|
||
// THREADS | ||
private ScheduledFuture<?> sch; | ||
|
@@ -75,19 +77,23 @@ public boolean addToQueue(Runnable request) { | |
return false; | ||
} | ||
|
||
private Map<ChunkLocation, Integer> chunksToUpdate = new HashMap<ChunkLocation, Integer>(); | ||
|
||
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<Player> players = new ArrayList<Player>( | ||
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<ChunkLocation, Integer> item : chunksToUpdate.entrySet()) { | ||
for (Map.Entry<ChunkLocation, ChunkUpdateInfo> 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); | ||
} | ||
} | ||
|
||
|