mirror of
https://gitlab.com/distant-horizons-team/distant-horizons-server-plugin.git
synced 2026-11-06 01:12:33 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2fb530de2b | ||
|
|
dbc97a9366 | ||
|
|
e2c0e3f88a | ||
|
|
bbc26ef9d7 | ||
|
|
fbb07e329d | ||
|
|
e0299eb798 | ||
|
|
5fcd6b8b52 | ||
|
|
32567079f0 |
No files matched your search
@@ -3,7 +3,7 @@
|
||||
|
||||
<groupId>no.jckf</groupId>
|
||||
<name>dh-support</name>
|
||||
<version>0.2.0-SNAPSHOT</version>
|
||||
<version>0.2.2</version>
|
||||
<artifactId>DHSupport</artifactId>
|
||||
|
||||
<properties>
|
||||
|
||||
@@ -19,18 +19,24 @@
|
||||
package no.jckf.dhsupport.core.handler;
|
||||
|
||||
import no.jckf.dhsupport.core.DhSupport;
|
||||
import no.jckf.dhsupport.core.message.plugin.FullDataChunkMessage;
|
||||
import no.jckf.dhsupport.core.message.plugin.FullDataSourceRequestMessage;
|
||||
import no.jckf.dhsupport.core.message.plugin.FullDataSourceResponseMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
public class LodHandler
|
||||
{
|
||||
protected static int CHUNK_SIZE = 1024 * 16; // TODO: Configurable?
|
||||
|
||||
protected DhSupport dhSupport;
|
||||
|
||||
protected PluginMessageHandler pluginMessageHandler;
|
||||
|
||||
protected int bufferId = 0; // TODO: Should be tracked per player instead of globally, and reset when a player disconnects.
|
||||
|
||||
public LodHandler(DhSupport dhSupport, PluginMessageHandler pluginMessageHandler)
|
||||
{
|
||||
this.dhSupport = dhSupport;
|
||||
@@ -42,18 +48,35 @@ public class LodHandler
|
||||
this.pluginMessageHandler.getEventBus().registerHandler(FullDataSourceRequestMessage.class, (requestMessage) -> {
|
||||
//this.dhSupport.info("LOD request for " + requestMessage.getPosition().getX() + " x " + requestMessage.getPosition().getZ());
|
||||
|
||||
int myBufferId = this.bufferId++;
|
||||
|
||||
// TODO: Some sort of Player wrapper or interface object. Bukkit classes should not be imported here.
|
||||
UUID worldUuid = Bukkit.getPlayer(requestMessage.getSender()).getWorld().getUID();
|
||||
|
||||
this.dhSupport.getLodData(worldUuid, requestMessage.getPosition())
|
||||
.thenAccept((lod) -> {
|
||||
FullDataSourceResponseMessage response = new FullDataSourceResponseMessage();
|
||||
response.isResponseTo(requestMessage);
|
||||
response.setData(lod);
|
||||
int chunkCount = (int) Math.ceil((double) lod.length / CHUNK_SIZE);
|
||||
|
||||
this.pluginMessageHandler.sendPluginMessage(requestMessage.getSender(), response);
|
||||
for (int chunkNo = 0; chunkNo < chunkCount; chunkNo++) {
|
||||
FullDataChunkMessage chunkResponse = new FullDataChunkMessage();
|
||||
chunkResponse.setBufferId(myBufferId);
|
||||
chunkResponse.setIsFirst(chunkNo == 0);
|
||||
chunkResponse.setData(Arrays.copyOfRange(
|
||||
lod,
|
||||
CHUNK_SIZE * chunkNo,
|
||||
Math.min(CHUNK_SIZE * chunkNo + CHUNK_SIZE, lod.length)
|
||||
));
|
||||
|
||||
//this.dhSupport.info("LOD sent for " + requestMessage.getPosition().getX() + " x " + requestMessage.getPosition().getZ());
|
||||
this.pluginMessageHandler.sendPluginMessage(requestMessage.getSender(), chunkResponse);
|
||||
}
|
||||
|
||||
FullDataSourceResponseMessage responseMessage = new FullDataSourceResponseMessage();
|
||||
responseMessage.isResponseTo(requestMessage);
|
||||
responseMessage.setBufferId(myBufferId);
|
||||
|
||||
this.pluginMessageHandler.sendPluginMessage(requestMessage.getSender(), responseMessage);
|
||||
|
||||
//this.dhSupport.info("LOD in " + chunkCount + " parts sent for " + requestMessage.getPosition().getX() + " x " + requestMessage.getPosition().getZ());
|
||||
})
|
||||
.exceptionally((exception) -> {
|
||||
this.dhSupport.warning(exception.getMessage());
|
||||
|
||||
@@ -38,7 +38,7 @@ public class PluginMessageHandler
|
||||
|
||||
public final String pluginChannel = "distant_horizons:message";
|
||||
|
||||
public final int protocolVersion = 2;
|
||||
public final int protocolVersion = 3;
|
||||
|
||||
private EventBus<PluginMessage> eventBus;
|
||||
|
||||
@@ -58,7 +58,8 @@ public class PluginMessageHandler
|
||||
this.messageTypeRegistry.registerMessageType(5, ExceptionMessage.class);
|
||||
this.messageTypeRegistry.registerMessageType(6, FullDataSourceRequestMessage.class);
|
||||
this.messageTypeRegistry.registerMessageType(7, FullDataSourceResponseMessage.class);
|
||||
//this.messageTypeRegistry.registerMessageType(8, FullDataPartialUpdateMessage.class);
|
||||
this.messageTypeRegistry.registerMessageType(8, /*FullDataPartialUpdateMessage.class*/ null);
|
||||
this.messageTypeRegistry.registerMessageType(9, FullDataChunkMessage.class);
|
||||
}
|
||||
|
||||
public void onEnable()
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* DH Support, server-side support for Distant Horizons.
|
||||
* Copyright (C) 2024 Jim C K Flaten
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package no.jckf.dhsupport.core.message.plugin;
|
||||
|
||||
import no.jckf.dhsupport.core.bytestream.Encoder;
|
||||
|
||||
public class FullDataChunkMessage extends PluginMessage
|
||||
{
|
||||
protected int bufferId;
|
||||
|
||||
protected byte[] data;
|
||||
|
||||
protected boolean isFirst = true;
|
||||
|
||||
public void setBufferId(int bufferId)
|
||||
{
|
||||
this.bufferId = bufferId;
|
||||
}
|
||||
|
||||
public int getBufferId()
|
||||
{
|
||||
return bufferId;
|
||||
}
|
||||
|
||||
public void setData(byte[] data)
|
||||
{
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setIsFirst(boolean isFirst)
|
||||
{
|
||||
this.isFirst = isFirst;
|
||||
}
|
||||
|
||||
public boolean getIsFirst()
|
||||
{
|
||||
return this.isFirst;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(Encoder encoder)
|
||||
{
|
||||
encoder.writeInt(this.bufferId);
|
||||
encoder.writeInt(this.data.length);
|
||||
encoder.write(this.data);
|
||||
encoder.writeBoolean(this.isFirst);
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -22,22 +22,22 @@ import no.jckf.dhsupport.core.bytestream.Encoder;
|
||||
|
||||
public class FullDataSourceResponseMessage extends TrackablePluginMessage
|
||||
{
|
||||
protected byte[] data;
|
||||
protected int bufferId;
|
||||
|
||||
public void setData(byte[] data)
|
||||
public void setBufferId(int bufferId)
|
||||
{
|
||||
this.data = data;
|
||||
this.bufferId = bufferId;
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
public int getBufferId()
|
||||
{
|
||||
return data;
|
||||
return bufferId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(Encoder encoder)
|
||||
{
|
||||
encoder.writeBoolean(true);
|
||||
encoder.write(this.data);
|
||||
encoder.writeInt(this.bufferId);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
name: DHSupport
|
||||
version: 0.2.0-SNAPSHOT
|
||||
version: 0.2.2
|
||||
main: no.jckf.dhsupport.bukkit.DhSupportBukkitPlugin
|
||||
api-version: 1.21
|
||||
Reference in new issue
Block a user