-
-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LoginInEncryptionBegin & LoginOutEncryptionBegin wrapper added,
LoginStart & LoginStatusPing wrapper added, Bug fixed with PostPlayerInjectEvent not being called, Custom GameProfile class coded, Main example class readded
- Loading branch information
purplexdev
committed
Jun 17, 2020
1 parent
ceb3581
commit 7f94b25
Showing
8 changed files
with
290 additions
and
6 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
17 changes: 17 additions & 0 deletions
17
src/main/java/io/github/retrooper/packetevents/example/MainExample.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,17 @@ | ||
package io.github.retrooper.packetevents.example; | ||
|
||
import io.github.retrooper.packetevents.PacketEvents; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
public class MainExample extends JavaPlugin { | ||
|
||
@Override | ||
public void onEnable() { | ||
PacketEvents.start(this); | ||
} | ||
|
||
@Override | ||
public void onDisable() { | ||
PacketEvents.stop(); | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
src/main/java/io/github/retrooper/packetevents/mojang/GameProfile.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,90 @@ | ||
package io.github.retrooper.packetevents.mojang; | ||
|
||
import com.mojang.authlib.properties.PropertyMap; | ||
import org.bukkit.craftbukkit.libs.org.apache.commons.lang3.StringUtils; | ||
import org.bukkit.craftbukkit.libs.org.apache.commons.lang3.builder.ToStringBuilder; | ||
|
||
import java.util.UUID; | ||
|
||
public class GameProfile { | ||
private final UUID id; | ||
private final String name; | ||
private final PropertyMap properties = new PropertyMap(); | ||
private boolean legacy; | ||
|
||
public GameProfile(UUID id, String name) { | ||
if (id == null && StringUtils.isBlank(name)) { | ||
throw new IllegalArgumentException("Name and ID cannot both be blank"); | ||
} else { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
} | ||
|
||
public UUID getId() { | ||
return this.id; | ||
} | ||
|
||
public String getName() { | ||
return this.name; | ||
} | ||
|
||
public PropertyMap getProperties() { | ||
return this.properties; | ||
} | ||
|
||
public boolean isComplete() { | ||
return this.id != null && StringUtils.isNotBlank(this.getName()); | ||
} | ||
|
||
public boolean equalsMojangGameProfile(com.mojang.authlib.GameProfile profile) { | ||
if (profile != null) { | ||
if (profile.getId() != null && getId() != null && profile.getId() == getId() | ||
&& profile.getName() != null && getName() != null && profile.getName().equals(getName())) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} else if (o != null && this.getClass() == o.getClass()) { | ||
GameProfile that = (GameProfile) o; | ||
if (this.id != null) { | ||
if (!this.id.equals(that.id)) { | ||
return false; | ||
} | ||
} else if (that.id != null) { | ||
return false; | ||
} | ||
|
||
if (this.name != null) { | ||
if (this.name.equals(that.name)) { | ||
return true; | ||
} | ||
} else if (that.name == null) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
public int hashCode() { | ||
int result = this.id != null ? this.id.hashCode() : 0; | ||
result = 31 * result + (this.name != null ? this.name.hashCode() : 0); | ||
return result; | ||
} | ||
|
||
public String toString() { | ||
return (new ToStringBuilder(this)).append("id", this.id).append("name", this.name).append("properties", this.properties).append("legacy", this.legacy).toString(); | ||
} | ||
|
||
public boolean isLegacy() { | ||
return this.legacy; | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
...thub/retrooper/packetevents/packetwrappers/login/WrappedPacketLoginInEncryptionBegin.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,41 @@ | ||
package io.github.retrooper.packetevents.packetwrappers.login; | ||
|
||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket; | ||
import io.github.retrooper.packetevents.tinyprotocol.Reflection; | ||
import io.github.retrooper.packetevents.utils.NMSUtils; | ||
|
||
public final class WrappedPacketLoginInEncryptionBegin extends WrappedPacket { | ||
private byte[] publicKey, verifyToken; | ||
public WrappedPacketLoginInEncryptionBegin(final Object packet) { | ||
super(packet); | ||
} | ||
|
||
@Override | ||
protected void setup() { | ||
this.publicKey = fields[0].get(packet); | ||
this.verifyToken = fields[1].get(packet); | ||
} | ||
|
||
public byte[] getPublicKey() { | ||
return publicKey; | ||
} | ||
|
||
public byte[] getVerifyToken() { | ||
return verifyToken; | ||
} | ||
|
||
private static Class<?> packetClass; | ||
|
||
private static final Reflection.FieldAccessor<byte[]>[] fields = new Reflection.FieldAccessor[2]; | ||
|
||
static { | ||
try { | ||
packetClass = NMSUtils.getNMSClass("PacketLoginInEncryptionBegin"); | ||
} catch (ClassNotFoundException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
fields[0] = Reflection.getField(packetClass, byte[].class, 0); | ||
fields[1] = Reflection.getField(packetClass, byte[].class, 1); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...hub/retrooper/packetevents/packetwrappers/login/WrappedPacketLoginOutEncryptionBegin.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,58 @@ | ||
package io.github.retrooper.packetevents.packetwrappers.login; | ||
|
||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket; | ||
import io.github.retrooper.packetevents.tinyprotocol.Reflection; | ||
import io.github.retrooper.packetevents.utils.NMSUtils; | ||
|
||
import java.security.PublicKey; | ||
|
||
|
||
public final class WrappedPacketLoginOutEncryptionBegin extends WrappedPacket { | ||
private String encodedString; | ||
private PublicKey encodedKey; | ||
private byte[] byteArray; | ||
|
||
public WrappedPacketLoginOutEncryptionBegin(final Object packet) { | ||
super(packet); | ||
} | ||
|
||
@Override | ||
protected void setup() { | ||
//string - a (encodedstring) | ||
//public key - b (encoded) | ||
//byte array - c(byte array) | ||
this.encodedString = fields[0].get(packet).toString(); | ||
this.encodedKey = (PublicKey) fields[1].get(packet); | ||
this.byteArray = (byte[]) fields[2].get(packet); | ||
} | ||
|
||
public String getEncodedString() { | ||
return encodedString; | ||
} | ||
|
||
public PublicKey getEncodedKey() { | ||
return encodedKey; | ||
} | ||
|
||
public byte[] getByteArray() { | ||
return byteArray; | ||
} | ||
|
||
private static Class<?> packetClass; | ||
|
||
private static final Reflection.FieldAccessor<?>[] fields = new Reflection.FieldAccessor[3]; | ||
|
||
static { | ||
try { | ||
packetClass = NMSUtils.getNMSClass("PacketLoginOutEncryptionBegin"); | ||
} catch (ClassNotFoundException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
fields[0] = Reflection.getField(packetClass, String.class, 0); | ||
fields[1] = Reflection.getField(packetClass, PublicKey.class, 1); | ||
fields[2] = Reflection.getField(packetClass, byte[].class, 2); | ||
} | ||
|
||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...n/java/io/github/retrooper/packetevents/packetwrappers/login/WrappedPacketLoginStart.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,36 @@ | ||
package io.github.retrooper.packetevents.packetwrappers.login; | ||
|
||
import io.github.retrooper.packetevents.mojang.GameProfile; | ||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket; | ||
import io.github.retrooper.packetevents.tinyprotocol.Reflection; | ||
import io.github.retrooper.packetevents.utils.NMSUtils; | ||
|
||
public final class WrappedPacketLoginStart extends WrappedPacket { | ||
private GameProfile gameProfile; | ||
public WrappedPacketLoginStart(final Object packet) { | ||
super(packet); | ||
} | ||
|
||
@Override | ||
protected void setup() { | ||
com.mojang.authlib.GameProfile gp = gameProfileAccessor.get(packet); | ||
this.gameProfile = new GameProfile(gp.getId(), gp.getName()); | ||
} | ||
|
||
public GameProfile getGameProfile() { | ||
return gameProfile; | ||
} | ||
|
||
private static Class<?> packetClass; | ||
|
||
private static final Reflection.FieldAccessor<com.mojang.authlib.GameProfile> gameProfileAccessor; | ||
|
||
static { | ||
try { | ||
packetClass = NMSUtils.getNMSClass("PacketLoginInStart"); | ||
} catch (ClassNotFoundException e) { | ||
e.printStackTrace(); | ||
} | ||
gameProfileAccessor = Reflection.getField(packetClass, com.mojang.authlib.GameProfile.class, 0); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...a/io/github/retrooper/packetevents/packetwrappers/login/WrappedPacketLoginStatusPing.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,36 @@ | ||
package io.github.retrooper.packetevents.packetwrappers.login; | ||
|
||
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket; | ||
import io.github.retrooper.packetevents.tinyprotocol.Reflection; | ||
import io.github.retrooper.packetevents.utils.NMSUtils; | ||
|
||
public final class WrappedPacketLoginStatusPing extends WrappedPacket { | ||
private long number; | ||
public WrappedPacketLoginStatusPing(final Object packet) { | ||
super(packet); | ||
} | ||
|
||
@Override | ||
protected void setup() { | ||
this.number = numberAccessor.get(packet); | ||
} | ||
|
||
public long getNumber() { | ||
return number; | ||
} | ||
|
||
private static Class<?> packetClass; | ||
|
||
private static final Reflection.FieldAccessor<Long> numberAccessor; | ||
|
||
static { | ||
try { | ||
packetClass = NMSUtils.getNMSClass("PacketStatusInPing"); | ||
} catch (ClassNotFoundException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
numberAccessor = Reflection.getField(packetClass, long.class, 0); | ||
} | ||
|
||
} |