-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Completely redesigned the plugin's network concept and added support …
…for 1.21.4.
- Loading branch information
Showing
11 changed files
with
835 additions
and
133 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Mon Aug 14 11:23:44 BRT 2023 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
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
76 changes: 76 additions & 0 deletions
76
src/main/java/io/github/cruciblemc/vitatempus/VitaTempusInterceptor.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,76 @@ | ||
package io.github.cruciblemc.vitatempus; | ||
|
||
import de.tr7zw.changeme.nbtapi.NBT; | ||
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT; | ||
import io.github.cruciblemc.vitatempus.ext.com.fren_gor.lightInjector.LightInjector; | ||
import io.github.cruciblemc.vitatempus.necrotempus.NecroTempus; | ||
import io.netty.channel.Channel; | ||
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; | ||
import net.minecraft.network.protocol.common.custom.DiscardedPayload; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.Plugin; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.nio.ByteBuffer; | ||
import java.util.Arrays; | ||
|
||
public class VitaTempusInterceptor extends LightInjector { | ||
|
||
/** | ||
* Initializes the injector and starts to listen to packets. | ||
* <p> | ||
* Note that, while it is possible to create more than one instance per plugin, | ||
* it is more efficient and recommended to just have only one. | ||
* | ||
* @param plugin The {@link Plugin} which is instantiating this injector. | ||
* @throws NullPointerException If the provided {@code plugin} is {@code null}. | ||
* @throws IllegalStateException When <b>not</b> called from the main thread. | ||
* @throws IllegalArgumentException If the provided {@code plugin} is not enabled. | ||
*/ | ||
public VitaTempusInterceptor(@NotNull Plugin plugin) { | ||
super(plugin); | ||
} | ||
|
||
@Override | ||
protected @NotNull Object onPacketReceiveAsync(@Nullable Player sender, @NotNull Channel channel, @NotNull Object packet) { | ||
|
||
if (packet instanceof ServerboundCustomPayloadPacket( | ||
net.minecraft.network.protocol.common.custom.CustomPacketPayload payload | ||
) && sender != null) { | ||
|
||
DiscardedPayload discardedPayload = (DiscardedPayload) payload; | ||
|
||
String id = discardedPayload.id().toString(); | ||
|
||
if (!id.equals(VitaTempus.NecroTempusChannel)) | ||
return packet; | ||
|
||
var buffer = discardedPayload.data(); | ||
byte[] message; | ||
|
||
message = new byte[buffer.readableBytes()]; | ||
buffer.duplicate().readBytes(message); | ||
|
||
ByteBuffer byteBuffer = ByteBuffer.wrap(message); | ||
|
||
short size = byteBuffer.getShort(1); | ||
byte[] data = Arrays.copyOfRange(message, 3, size); | ||
|
||
ReadWriteNBT nbtContainer = NBT.readNBT(new ByteArrayInputStream(data)); | ||
|
||
if (nbtContainer.hasTag("version")) | ||
NecroTempus.getInstance().setVersion(sender, nbtContainer.getString("version")); | ||
|
||
} | ||
|
||
return packet; | ||
} | ||
|
||
@Override | ||
protected @NotNull Object onPacketSendAsync(@Nullable Player receiver, @NotNull Channel channel, @NotNull Object packet) { | ||
return packet; | ||
} | ||
|
||
} |
54 changes: 13 additions & 41 deletions
54
src/main/java/io/github/cruciblemc/vitatempus/core/BukkitPacketDeliver.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 |
---|---|---|
@@ -1,60 +1,32 @@ | ||
package io.github.cruciblemc.vitatempus.core; | ||
|
||
import io.github.cruciblemc.vitatempus.VitaTempus; | ||
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.Plugin; | ||
|
||
public class BukkitPacketDeliver { | ||
|
||
private final Plugin plugin; | ||
private final VitaTempus plugin; | ||
private final String channel; | ||
|
||
private BukkitPacketDeliver(Plugin plugin, String channel){ | ||
public BukkitPacketDeliver(VitaTempus plugin, String channel) { | ||
this.plugin = plugin; | ||
this.channel = channel; | ||
onInit(); | ||
} | ||
|
||
public static BukkitPacketDeliver register(Plugin plugin, String channel){ | ||
return new BukkitPacketDeliver(plugin, channel); | ||
public void deliverTo(Player player, MessagePacket messagePacket) { | ||
Bukkit.getScheduler().runTask(plugin, () -> plugin.getInterceptor().sendPacket( | ||
player, | ||
new ClientboundCustomPayloadPacket( | ||
MessagePacketEncoder.asDiscardedPayload(channel, messagePacket)) | ||
)); | ||
} | ||
|
||
public void deliverTo(Player player, EncodedMessage encodedMessage){ | ||
Bukkit.getScheduler().runTask(plugin, () -> { | ||
player.sendPluginMessage(plugin, channel, encodedMessage.getTransformedData()); | ||
}); | ||
} | ||
|
||
public void broadcast(EncodedMessage encodedMessage){ | ||
for(Player player : Bukkit.getOnlinePlayers()){ | ||
deliverTo(player, encodedMessage); | ||
public void broadcast(MessagePacket messagePacket) { | ||
for (Player player : Bukkit.getOnlinePlayers()) { | ||
deliverTo(player, messagePacket); | ||
} | ||
} | ||
|
||
public void deliverTo(Player player, MessagePacket messagePacket){ | ||
EncodedMessage encodedMessage = MessagePacketEncoder.encode(messagePacket); | ||
|
||
Bukkit.getScheduler().runTask(plugin, () -> { | ||
player.sendPluginMessage(plugin, channel, encodedMessage.getTransformedData()); | ||
}); | ||
} | ||
|
||
public void broadcast(MessagePacket messagePacket){ | ||
|
||
EncodedMessage encodedMessage = MessagePacketEncoder.encode(messagePacket); | ||
|
||
for(Player player : Bukkit.getOnlinePlayers()){ | ||
deliverTo(player, encodedMessage); | ||
} | ||
} | ||
|
||
public void onInit(){ | ||
Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(plugin, channel); | ||
} | ||
|
||
public void onDisable(){ | ||
Bukkit.getServer().getMessenger().unregisterOutgoingPluginChannel(plugin, channel); | ||
} | ||
|
||
|
||
} |
12 changes: 0 additions & 12 deletions
12
src/main/java/io/github/cruciblemc/vitatempus/core/EncodedMessage.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.