-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
some basic packet/hologram classes #25
Open
tahmid-23
wants to merge
7
commits into
staging
Choose a base branch
from
packet
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
849eb7b
Packet classes
tahmid-23 041c5c8
some new hologram classes (doesn't compile)
tahmid-23 03816fd
compile error, still kind of iffy on polymorphism with different type…
tahmid-23 bc1fc50
forgot to implement a method
tahmid-23 145de1f
rename PacketBridge v1.16.3
tahmid-23 2f667a7
grab the latest ver of zap-party
tahmid-23 fa218c7
Merge branch 'staging' into packet
tahmid-23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
94 changes: 94 additions & 0 deletions
94
...ain/java/io/github/zap/arenaapi/nms/v1_16_R3/packet/ProtocolLibPacketBridge_v1_16_R3.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,94 @@ | ||
package io.github.zap.arenaapi.nms.v1_16_R3.packet; | ||
|
||
import com.comphenix.protocol.PacketType; | ||
import com.comphenix.protocol.ProtocolManager; | ||
import com.comphenix.protocol.events.PacketContainer; | ||
import com.comphenix.protocol.wrappers.AdventureComponentConverter; | ||
import com.comphenix.protocol.wrappers.WrappedDataWatcher; | ||
import io.github.zap.arenaapi.nms.common.packet.Packet; | ||
import io.github.zap.arenaapi.nms.common.packet.PacketBridge; | ||
import io.github.zap.arenaapi.nms.common.packet.ProtocolLibPacket; | ||
import net.kyori.adventure.text.Component; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
@SuppressWarnings("ClassCanBeRecord") | ||
public class ProtocolLibPacketBridge_v1_16_R3 implements PacketBridge { | ||
|
||
private final static byte INVISIBLE_BYTE_MASK = (byte) 0x20; | ||
|
||
private final static byte MARKER_ARMOR_STAND_MASK = (byte) 0x10; | ||
|
||
protected final ProtocolManager protocolManager; | ||
|
||
public ProtocolLibPacketBridge_v1_16_R3(@NotNull ProtocolManager protocolManager) { | ||
this.protocolManager = protocolManager; | ||
} | ||
|
||
@Override | ||
public @NotNull Packet createSpawnLivingEntityPacket(int entityId, int typeId, @NotNull UUID uuid, double x, | ||
double y, double z) { | ||
PacketContainer packetContainer = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY_LIVING); | ||
packetContainer.getIntegers() | ||
.write(0, entityId) | ||
.write(1,typeId); | ||
packetContainer.getUUIDs().write(0, uuid); | ||
packetContainer.getDoubles() | ||
.write(0, x) | ||
.write(1, y) | ||
.write(2, z); | ||
|
||
return createProtocolLibPacket(packetContainer); | ||
} | ||
|
||
@Override | ||
public @NotNull Packet createHologramLinePacket(int entityId, @NotNull Component line) { | ||
PacketContainer packetContainer = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA); | ||
packetContainer.getIntegers().write(0, entityId); | ||
|
||
WrappedDataWatcher wrappedDataWatcher = new WrappedDataWatcher(); | ||
|
||
WrappedDataWatcher.Serializer byteSerializer = WrappedDataWatcher.Registry.get(Byte.class); | ||
WrappedDataWatcher.Serializer optChatSerializer = WrappedDataWatcher.Registry | ||
.getChatComponentSerializer(true); | ||
WrappedDataWatcher.Serializer booleanSerializer = WrappedDataWatcher.Registry.get(Boolean.class); | ||
|
||
WrappedDataWatcher.WrappedDataWatcherObject invisible | ||
= new WrappedDataWatcher.WrappedDataWatcherObject(0, byteSerializer); | ||
WrappedDataWatcher.WrappedDataWatcherObject customName | ||
= new WrappedDataWatcher.WrappedDataWatcherObject(2, optChatSerializer); | ||
WrappedDataWatcher.WrappedDataWatcherObject customNameVisible | ||
= new WrappedDataWatcher.WrappedDataWatcherObject(3, booleanSerializer); | ||
WrappedDataWatcher.WrappedDataWatcherObject marker | ||
= new WrappedDataWatcher.WrappedDataWatcherObject(14, byteSerializer); | ||
|
||
wrappedDataWatcher.setObject(invisible, INVISIBLE_BYTE_MASK); | ||
wrappedDataWatcher.setObject(customName, Optional.of(AdventureComponentConverter.fromComponent(line))); | ||
wrappedDataWatcher.setObject(customNameVisible, true); | ||
wrappedDataWatcher.setObject(marker, MARKER_ARMOR_STAND_MASK); | ||
|
||
packetContainer.getWatchableCollectionModifier().write(0, wrappedDataWatcher.getWatchableObjects()); | ||
|
||
return createProtocolLibPacket(packetContainer); | ||
} | ||
|
||
@Override | ||
public @NotNull Packet createDestroyEntityPacket(int id) { | ||
return createDestroyEntitiesPacket(new int[] { id }); | ||
} | ||
|
||
@Override | ||
public @NotNull Packet createDestroyEntitiesPacket(int[] ids) { | ||
PacketContainer packetContainer = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY); | ||
packetContainer.getIntegerArrays().write(0, ids); | ||
|
||
return createProtocolLibPacket(packetContainer); | ||
} | ||
|
||
protected @NotNull Packet createProtocolLibPacket(@NotNull PacketContainer packetContainer) { | ||
return new ProtocolLibPacket(protocolManager, packetContainer); | ||
} | ||
|
||
} |
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
26 changes: 26 additions & 0 deletions
26
nms/nms-common/src/main/java/io/github/zap/arenaapi/nms/common/packet/MultiPacket.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,26 @@ | ||
package io.github.zap.arenaapi.nms.common.packet; | ||
|
||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.Plugin; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* A packet formed from many other packets | ||
*/ | ||
@SuppressWarnings("ClassCanBeRecord") | ||
public class MultiPacket implements Packet { | ||
|
||
private final Packet[] packets; | ||
|
||
public MultiPacket(@NotNull Packet... packets) { | ||
this.packets = packets; | ||
} | ||
|
||
@Override | ||
public void sendToPlayer(@NotNull Plugin plugin, @NotNull Player player) { | ||
for (Packet packet : packets) { | ||
packet.sendToPlayer(plugin, player); | ||
} | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
nms/nms-common/src/main/java/io/github/zap/arenaapi/nms/common/packet/Packet.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,19 @@ | ||
package io.github.zap.arenaapi.nms.common.packet; | ||
|
||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.Plugin; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* A minecraft packet used to circumvent limitations of the Bukkit API | ||
*/ | ||
public interface Packet { | ||
|
||
/** | ||
* Sends the packet to a {@link Player}. | ||
* @param plugin The {@link Plugin} from which the packet is being sent | ||
* @param player The {@link Player} to send the packet to | ||
*/ | ||
void sendToPlayer(@NotNull Plugin plugin, @NotNull Player player); | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
nms/nms-common/src/main/java/io/github/zap/arenaapi/nms/common/packet/PacketBridge.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,21 @@ | ||
package io.github.zap.arenaapi.nms.common.packet; | ||
|
||
import net.kyori.adventure.text.Component; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.UUID; | ||
|
||
/** | ||
* A bridge used for creating and interacting with packets | ||
*/ | ||
public interface PacketBridge { | ||
|
||
@NotNull Packet createSpawnLivingEntityPacket(int entityId, int typeId, @NotNull UUID uuid, double x, double y, | ||
double z); | ||
|
||
@NotNull Packet createHologramLinePacket(int entityId, @NotNull Component line); | ||
|
||
@NotNull Packet createDestroyEntityPacket(int id); | ||
|
||
@NotNull Packet createDestroyEntitiesPacket(int[] ids); | ||
} |
37 changes: 37 additions & 0 deletions
37
nms/nms-common/src/main/java/io/github/zap/arenaapi/nms/common/packet/ProtocolLibPacket.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,37 @@ | ||
package io.github.zap.arenaapi.nms.common.packet; | ||
|
||
import com.comphenix.protocol.ProtocolManager; | ||
import com.comphenix.protocol.events.PacketContainer; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.Plugin; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.logging.Level; | ||
|
||
/** | ||
* A packet using {@link PacketContainer}s | ||
*/ | ||
@SuppressWarnings("ClassCanBeRecord") | ||
public class ProtocolLibPacket implements Packet { | ||
|
||
private final ProtocolManager protocolManager; | ||
|
||
private final PacketContainer handle; | ||
|
||
public ProtocolLibPacket(@NotNull ProtocolManager protocolManager, @NotNull PacketContainer handle) { | ||
this.protocolManager = protocolManager; | ||
this.handle = handle; | ||
} | ||
|
||
@Override | ||
public void sendToPlayer(@NotNull Plugin plugin, @NotNull Player player) { | ||
try { | ||
protocolManager.sendServerPacket(player, handle); | ||
} catch (InvocationTargetException e) { | ||
plugin.getLogger().log(Level.WARNING, "Failed to send a packet to player with UUID " | ||
+ player.getUniqueId() + "!", e); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, disgusting NMS class naming schemes, how i have not missed needing to use you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
finalmente