forked from ChomeNS/chomens-bot-java
finally fix WorldPlugin
This commit is contained in:
parent
85d30b0b14
commit
78d671030d
1 changed files with 21 additions and 23 deletions
|
@ -1,8 +1,10 @@
|
||||||
package me.chayapak1.chomens_bot.plugins;
|
package me.chayapak1.chomens_bot.plugins;
|
||||||
|
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
|
import org.cloudburstmc.nbt.NbtMap;
|
||||||
import org.geysermc.mcprotocollib.network.Session;
|
import org.geysermc.mcprotocollib.network.Session;
|
||||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||||
|
import org.geysermc.mcprotocollib.protocol.data.game.RegistryEntry;
|
||||||
import org.geysermc.mcprotocollib.protocol.packet.configuration.clientbound.ClientboundRegistryDataPacket;
|
import org.geysermc.mcprotocollib.protocol.packet.configuration.clientbound.ClientboundRegistryDataPacket;
|
||||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
|
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
|
||||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundRespawnPacket;
|
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundRespawnPacket;
|
||||||
|
@ -18,7 +20,7 @@ public class WorldPlugin extends Bot.Listener {
|
||||||
public int minY = 0;
|
public int minY = 0;
|
||||||
public int maxY = 256;
|
public int maxY = 256;
|
||||||
|
|
||||||
public Key registry = null;
|
public List<RegistryEntry> registry = null;
|
||||||
|
|
||||||
private final List<Listener> listeners = new ArrayList<>();
|
private final List<Listener> listeners = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -35,37 +37,33 @@ public class WorldPlugin extends Bot.Listener {
|
||||||
else if (packet instanceof ClientboundRegistryDataPacket) packetReceived((ClientboundRegistryDataPacket) packet);
|
else if (packet instanceof ClientboundRegistryDataPacket) packetReceived((ClientboundRegistryDataPacket) packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @SuppressWarnings("unchecked")
|
private void worldChanged (String dimension) {
|
||||||
private void worldChanged (int dimension) {
|
final RegistryEntry currentDimension = registry.stream()
|
||||||
// FIXME
|
.filter(eachDimension -> eachDimension.getId().asString().equals(dimension))
|
||||||
bot.logger.info(registry.value());
|
.toArray(RegistryEntry[]::new)[0];
|
||||||
bot.logger.info(registry.toString());
|
|
||||||
// final Key dimensionType = ((LinkedHashMap<String, Key>) registry.get("minecraft:dimension_type").asString()).get("value");
|
final NbtMap data = currentDimension.getData();
|
||||||
//
|
|
||||||
// final ArrayList<Key> dimensions = (ArrayList<Key>) dimensionType.asString();
|
if (data == null) return;
|
||||||
//
|
|
||||||
// final Key currentDimension = dimensions.stream()
|
minY = data.getInt("min_y");
|
||||||
// .filter((eachDimension) -> eachDimension.get("name").getValue().equals(dimension))
|
maxY = data.getInt("height");
|
||||||
// .toArray(Key[]::new)[0];
|
|
||||||
//
|
for (Listener listener : listeners) listener.worldChanged(dimension);
|
||||||
// final Key element = currentDimension.get("element");
|
|
||||||
//
|
|
||||||
// minY = (int) element.get("min_y").getValue();
|
|
||||||
// maxY = (int) element.get("height").getValue();
|
|
||||||
//
|
|
||||||
// for (Listener listener : listeners) listener.worldChanged(dimension);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void packetReceived (ClientboundRegistryDataPacket packet) {
|
public void packetReceived (ClientboundRegistryDataPacket packet) {
|
||||||
registry = packet.getRegistry();
|
if (!packet.getRegistry().value().equals("dimension_type")) return;
|
||||||
|
|
||||||
|
registry = packet.getEntries();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void packetReceived (ClientboundLoginPacket packet) {
|
public void packetReceived (ClientboundLoginPacket packet) {
|
||||||
worldChanged(packet.getCommonPlayerSpawnInfo().getDimension());
|
worldChanged(packet.getCommonPlayerSpawnInfo().getWorldName().asString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void packetReceived (ClientboundRespawnPacket packet) {
|
public void packetReceived (ClientboundRespawnPacket packet) {
|
||||||
worldChanged(packet.getCommonPlayerSpawnInfo().getDimension());
|
worldChanged(packet.getCommonPlayerSpawnInfo().getWorldName().asString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Listener {
|
public static class Listener {
|
||||||
|
|
Loading…
Reference in a new issue