Skip to content

Commit

Permalink
All is working,
Browse files Browse the repository at this point in the history
1.3.9 releasing soon ane about to post on spigotmc
  • Loading branch information
OPtimal committed Jul 3, 2020
1 parent e2cfdda commit b2654e1
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 101 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<version>1.7.10</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.github.spigot</groupId>
<artifactId>1.8.8</artifactId>
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/io/github/retrooper/packetevents/PacketEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.github.retrooper.packetevents.event.impl.PacketReceiveEvent;
import io.github.retrooper.packetevents.event.impl.PlayerInjectEvent;
import io.github.retrooper.packetevents.event.impl.ServerTickEvent;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -20,13 +21,24 @@ public final class PacketEvents implements PacketListener, Listener {
private static boolean hasRegistered;
private static int currentTick;
private static Plugin plugin;
private static boolean hasLoaded;
/**
* Call this before start(), this is also very heavy
*/
public static void load() {
PacketTypeClasses.Client.load();
hasLoaded = true;
}

/**
* Starts the server tick task and initiates the TinyProtocolHandler
*
* @param plugin
*/
public static void start(final Plugin plugin) {
if(!hasLoaded) {
load();
}
if (!hasRegistered) {
//Register Bukkit and PacketListener
getAPI().getEventManager().registerListener(getInstance());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,29 @@
import io.github.retrooper.packetevents.event.PacketListener;
import io.github.retrooper.packetevents.event.impl.PacketReceiveEvent;
import io.github.retrooper.packetevents.packet.PacketType;
import io.github.retrooper.packetevents.packetwrappers.in.useentity.WrappedPacketInUseEntity;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

import static io.github.retrooper.packetevents.PacketEvents.getAPI;

public class MainExample extends JavaPlugin implements PacketListener {
public class MainExample extends JavaPlugin {

@Override
public void onLoad() {
PacketEvents.load();
}

@Override
public void onEnable() {
PacketEvents.start(this);


getAPI().getServerTickTask().cancel();

getAPI().getEventManager().registerListener(this);
}

@Override
public void onDisable() {
PacketEvents.stop();
}

@PacketHandler
public void onReceive(PacketReceiveEvent e) {
if(e.getPacketId() == PacketType.Client.ARM_ANIMATION) {
e.getPlayer().sendMessage("you swung your arm");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@

public class NettyPacketHandler {
public static final String handlerName = "packet_handler";
private static final ServerVersion version = PacketEvents.getAPI().getServerUtilities().getServerVersion();
private static boolean v1_7_nettyMode = false;

static {
try {
Class.forName("io.netty.channel.Channel");
} catch (ClassNotFoundException e) {
v1_7_nettyMode = true;
}
}

public static void injectPlayer(final Player player) {
final PlayerInjectEvent injectEvent = new PlayerInjectEvent(player);
PacketEvents.getAPI().getEventManager().callEvent(injectEvent);
if (!injectEvent.isCancelled()) {
if (version.isLowerThan(ServerVersion.v_1_8)) {
if (v1_7_nettyMode) {
NettyPacketHandler_7.injectPlayer(player);
} else {
NettyPacketHandler_8.injectPlayer(player);
Expand All @@ -30,7 +38,7 @@ public static Future<?> uninjectPlayer(final Player player) {
final PlayerUninjectEvent uninjectEvent = new PlayerUninjectEvent(player);
PacketEvents.getAPI().getEventManager().callEvent(uninjectEvent);
if (!uninjectEvent.isCancelled()) {
if (version.isLowerThan(ServerVersion.v_1_8)) {
if (v1_7_nettyMode) {
return NettyPacketHandler_7.uninjectPlayer(player);
} else {
return NettyPacketHandler_8.uninjectPlayer(player);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ public class PacketType {


public static class Client {
public static class Util {
public static boolean isInstanceOfFlying(final int packetId) {
return packetId == FLYING
|| packetId == POSITION || packetId == POSITION_LOOK || packetId == LOOK;
}
}
public static final Map<Class<?>, Integer> packetIds = new HashMap<Class<?>, Integer>();

public static final int TELEPORT_ACCEPT = 0,
Expand Down Expand Up @@ -69,7 +75,6 @@ public static void init(){
packetIds.put(PacketTypeClasses.Client.SPECTATE, SPECTATE);
packetIds.put(PacketTypeClasses.Client.USE_ITEM, USE_ITEM);
packetIds.put(PacketTypeClasses.Client.BLOCK_PLACE, BLOCK_PLACE);

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ public static class Client {
@Nullable
public static final Class<?> FLYING = NMSUtils.getNMSClassWithoutException(c + "Flying");

static {
try {POSITION = NMSUtils.getNMSClass(c + "Position");
public static void load() {
try {
POSITION = NMSUtils.getNMSClass(c + "Position");
POSITION_LOOK = NMSUtils.getNMSClass(c + "PositionLook");
LOOK = NMSUtils.getNMSClass(c + "Look");
} catch (ClassNotFoundException e) {
Expand Down

0 comments on commit b2654e1

Please sign in to comment.