refactor: use correct EventHandler implementation
This commit is contained in:
parent
91ba9794ac
commit
b97d83333b
8 changed files with 87 additions and 8 deletions
|
@ -9,7 +9,7 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
|||
|
||||
public class BannedItemListener implements Listener {
|
||||
|
||||
@EventHandler()
|
||||
@EventHandler
|
||||
public void onEntityPickupItem(EntityPickupItemEvent e) {
|
||||
if (e.getEntity() instanceof Player) {
|
||||
Material mat = e.getItem().getItemStack().getType();
|
||||
|
@ -21,7 +21,7 @@ public class BannedItemListener implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
@EventHandler()
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent e) {
|
||||
if (e.getCurrentItem() == null)
|
||||
return;
|
||||
|
|
|
@ -9,7 +9,7 @@ import de.cliffbreak.varo.uitls.MessageUtils;
|
|||
|
||||
public class ChatListener implements Listener {
|
||||
|
||||
@EventHandler()
|
||||
@EventHandler
|
||||
public void onChat(AsyncPlayerChatEvent e) {
|
||||
e.setCancelled(true);
|
||||
Bukkit.broadcast(MessageUtils.getRichTextComponent(e.getPlayer().getName(), e.getMessage()));
|
||||
|
|
|
@ -16,7 +16,7 @@ public class CreatureSpawnListener implements Listener {
|
|||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler()
|
||||
@EventHandler
|
||||
public void onCreatureSpawn(CreatureSpawnEvent e) {
|
||||
LivingEntity livingEntity = e.getEntity();
|
||||
if (livingEntity.getType().equals(EntityType.WANDERING_TRADER)
|
||||
|
|
|
@ -7,7 +7,7 @@ import org.bukkit.event.entity.EntityRegainHealthEvent;
|
|||
|
||||
public class EntityRegainHealthListener implements Listener {
|
||||
|
||||
@EventHandler()
|
||||
@EventHandler
|
||||
public void onEntityRegainHealth(EntityRegainHealthEvent e) {
|
||||
if (e.getEntity() instanceof Player) {
|
||||
if (e.isFastRegen()) {
|
||||
|
|
|
@ -16,7 +16,7 @@ public class PlayerClientOptionsChangeListener implements Listener {
|
|||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler()
|
||||
@EventHandler
|
||||
public void onPlayerClientOptionsChange(PlayerClientOptionsChangeEvent e) {
|
||||
String uuid = e.getPlayer().getUniqueId().toString().replace("-", "");
|
||||
plugin.playerCache.setPlayerCache(uuid, PlayerCacheType.SKINPARTS, e.getSkinParts().getRaw());
|
||||
|
|
|
@ -18,7 +18,7 @@ public class PlayerDeathListener implements Listener {
|
|||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler()
|
||||
@EventHandler
|
||||
public void onPlayerDeath(final PlayerDeathEvent e) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
|
|
|
@ -17,7 +17,7 @@ public class PlayerPreLoginListener implements Listener {
|
|||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler()
|
||||
@EventHandler
|
||||
public void onPlayerPreLogin(final AsyncPlayerPreLoginEvent e) {
|
||||
@SuppressWarnings("unchecked")
|
||||
final ArrayList<String> bans = (ArrayList<String>) this.plugin.config.get("Varo.Bans");
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
package de.cliffbreak.varo.uitls;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||
import net.minecraft.server.v1_15_R1.Packet;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PacketReader {
|
||||
|
||||
Player player;
|
||||
Channel channel;
|
||||
|
||||
public PacketReader(final Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public void inject() {
|
||||
final CraftPlayer cPlayer = (CraftPlayer) this.player;
|
||||
channel = cPlayer.getHandle().playerConnection.networkManager.channel;
|
||||
channel.pipeline().addAfter("decoder", "PacketInjector", new MessageToMessageDecoder<Packet<?>>() {
|
||||
@Override
|
||||
protected void decode(final ChannelHandlerContext arg0, final Packet<?> packet, final List<Object> arg2)
|
||||
throws Exception {
|
||||
arg2.add(packet);
|
||||
readPacket(packet);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void uninject() {
|
||||
if (channel.pipeline().get("PacketInjector") != null) {
|
||||
channel.pipeline().remove("PacketInjector");
|
||||
}
|
||||
}
|
||||
|
||||
public void readPacket(final Packet<?> packet) {
|
||||
if (packet.getClass().getSimpleName().equalsIgnoreCase("PacketPlayInUseEntity")) {
|
||||
final int id = (Integer) getValue(packet, "a");
|
||||
|
||||
System.out.println(getValue(packet, "action").toString());
|
||||
System.out.println(getValue(packet, "a").toString());
|
||||
|
||||
// if (Main.npc.getEntityID() == id) {
|
||||
// if (getValue(packet, "action").toString().equalsIgnoreCase("ATTACK")) {
|
||||
// Main.npc.animation(1);
|
||||
// } else if (getValue(packet, "action").toString().equalsIgnoreCase("INTERACT")) {
|
||||
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
public void setValue(final Object obj, final String name, final Object value) {
|
||||
try {
|
||||
final Field field = obj.getClass().getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
field.set(obj, value);
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public Object getValue(final Object obj, final String name) {
|
||||
try {
|
||||
final Field field = obj.getClass().getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
return field.get(obj);
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue