Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-03 14:50:30 +01:00
Rename the Meta(List)1_9_1_10Type to Metadata(List)1_9Type and cleanup the listeners
Dieser Commit ist enthalten in:
Ursprung
b2680d76a6
Commit
693990644f
74
src/main/java/us/myles/ViaVersion/api/ViaListener.java
Normale Datei
74
src/main/java/us/myles/ViaVersion/api/ViaListener.java
Normale Datei
@ -0,0 +1,74 @@
|
|||||||
|
package us.myles.ViaVersion.api;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NonNull;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||||
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
|
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||||
|
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public abstract class ViaListener implements Listener {
|
||||||
|
private final ViaVersionPlugin plugin;
|
||||||
|
private final Class<? extends Protocol> requiredPipeline;
|
||||||
|
private boolean registered = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the UserConnection from a player
|
||||||
|
*
|
||||||
|
* @param player Player object
|
||||||
|
* @return The UserConnection
|
||||||
|
*/
|
||||||
|
public UserConnection getUserConnection(@NonNull Player player) {
|
||||||
|
return getUserConnection(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the UserConnection from an UUID
|
||||||
|
*
|
||||||
|
* @param uuid UUID object
|
||||||
|
* @return The UserConnection
|
||||||
|
*/
|
||||||
|
public UserConnection getUserConnection(@NonNull UUID uuid) {
|
||||||
|
if (!plugin.isPorted(uuid)) return null;
|
||||||
|
return plugin.getConnection(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the player is on the selected pipe
|
||||||
|
*
|
||||||
|
* @param player Player Object
|
||||||
|
* @return True if on pipe
|
||||||
|
*/
|
||||||
|
public boolean isOnPipe(Player player) {
|
||||||
|
return isOnPipe(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the UUID is on the selected pipe
|
||||||
|
*
|
||||||
|
* @param uuid UUID Object
|
||||||
|
* @return True if on pipe
|
||||||
|
*/
|
||||||
|
public boolean isOnPipe(UUID uuid) {
|
||||||
|
UserConnection userConnection = getUserConnection(uuid);
|
||||||
|
return userConnection != null &&
|
||||||
|
userConnection.get(ProtocolInfo.class).getPipeline().contains(requiredPipeline);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register as Bukkit event
|
||||||
|
*/
|
||||||
|
public void register() {
|
||||||
|
if (registered) return;
|
||||||
|
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||||
|
registered = true;
|
||||||
|
}
|
||||||
|
}
|
@ -2,8 +2,8 @@ package us.myles.ViaVersion.api.type.types.minecraft;
|
|||||||
|
|
||||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.types.Meta1_9_1_10Type;
|
import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.types.Metadata1_9Type;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.types.MetaList1_9_1_10Type;
|
import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.types.MetadataList1_9Type;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -11,10 +11,10 @@ public class Types1_9 {
|
|||||||
/**
|
/**
|
||||||
* Metadata list type for 1.9
|
* Metadata list type for 1.9
|
||||||
*/
|
*/
|
||||||
public static final Type<List<Metadata>> METADATA_LIST = new MetaList1_9_1_10Type();
|
public static final Type<List<Metadata>> METADATA_LIST = new MetadataList1_9Type();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Metadata type for 1.9
|
* Metadata type for 1.9
|
||||||
*/
|
*/
|
||||||
public static final Type<Metadata> METADATA = new Meta1_9_1_10Type();
|
public static final Type<Metadata> METADATA = new Metadata1_9Type();
|
||||||
}
|
}
|
||||||
|
@ -11,17 +11,17 @@ import us.myles.ViaVersion.api.type.Type;
|
|||||||
import us.myles.ViaVersion.api.type.types.minecraft.Types1_9;
|
import us.myles.ViaVersion.api.type.types.minecraft.Types1_9;
|
||||||
import us.myles.ViaVersion.packets.State;
|
import us.myles.ViaVersion.packets.State;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.storage.ResourcePackTracker;
|
import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.storage.ResourcePackTracker;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.types.Meta1_9_1_10Type;
|
import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.types.Metadata1_9Type;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.types.MetaList1_9_1_10Type;
|
import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.types.MetadataList1_9Type;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
public class Protocol1_10To1_9_3_4 extends Protocol {
|
public class Protocol1_10To1_9_3_4 extends Protocol {
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static final Type<List<Metadata>> METADATA_LIST = new MetaList1_9_1_10Type();
|
public static final Type<List<Metadata>> METADATA_LIST = new MetadataList1_9Type();
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static final Type<Metadata> METADATA = new Meta1_9_1_10Type();
|
public static final Type<Metadata> METADATA = new Metadata1_9Type();
|
||||||
|
|
||||||
public static ValueTransformer<Short, Float> toNewPitch = new ValueTransformer<Short, Float>(Type.FLOAT) {
|
public static ValueTransformer<Short, Float> toNewPitch = new ValueTransformer<Short, Float>(Type.FLOAT) {
|
||||||
@Override
|
@Override
|
||||||
|
@ -5,7 +5,7 @@ import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
|||||||
import us.myles.ViaVersion.api.type.types.minecraft.MetaTypeTemplate;
|
import us.myles.ViaVersion.api.type.types.minecraft.MetaTypeTemplate;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.NewType;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.NewType;
|
||||||
|
|
||||||
public class Meta1_9_1_10Type extends MetaTypeTemplate {
|
public class Metadata1_9Type extends MetaTypeTemplate {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Metadata read(ByteBuf buffer) throws Exception {
|
public Metadata read(ByteBuf buffer) throws Exception {
|
@ -8,7 +8,7 @@ import us.myles.ViaVersion.api.type.types.minecraft.Types1_9;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class MetaList1_9_1_10Type extends MetaListTypeTemplate {
|
public class MetadataList1_9Type extends MetaListTypeTemplate {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Metadata> read(ByteBuf buffer) throws Exception {
|
public List<Metadata> read(ByteBuf buffer) throws Exception {
|
@ -105,13 +105,15 @@ public class Protocol1_9TO1_8 extends Protocol {
|
|||||||
@Override
|
@Override
|
||||||
protected void registerListeners() {
|
protected void registerListeners() {
|
||||||
ViaVersionPlugin plugin = (ViaVersionPlugin) Bukkit.getPluginManager().getPlugin("ViaVersion");
|
ViaVersionPlugin plugin = (ViaVersionPlugin) Bukkit.getPluginManager().getPlugin("ViaVersion");
|
||||||
Bukkit.getPluginManager().registerEvents(new ArmorListener(plugin), plugin);
|
|
||||||
Bukkit.getPluginManager().registerEvents(new CommandBlockListener(plugin), plugin);
|
new ArmorListener(plugin).register();
|
||||||
Bukkit.getPluginManager().registerEvents(new DeathListener(plugin), plugin);
|
new CommandBlockListener(plugin).register();
|
||||||
Bukkit.getPluginManager().registerEvents(new BlockListener(plugin), plugin);
|
new DeathListener(plugin).register();
|
||||||
|
new BlockListener(plugin).register();
|
||||||
|
|
||||||
if (Bukkit.getVersion().toLowerCase().contains("paper") || Bukkit.getVersion().toLowerCase().contains("taco")) {
|
if (Bukkit.getVersion().toLowerCase().contains("paper") || Bukkit.getVersion().toLowerCase().contains("taco")) {
|
||||||
plugin.getLogger().info("Enabling PaperSpigot/TacoSpigot patch: Fixes block placement.");
|
plugin.getLogger().info("Enabling PaperSpigot/TacoSpigot patch: Fixes block placement.");
|
||||||
Bukkit.getPluginManager().registerEvents(new PaperPatch(), plugin);
|
new PaperPatch(plugin).register();
|
||||||
}
|
}
|
||||||
if (plugin.getConf().isStimulatePlayerTick())
|
if (plugin.getConf().isStimulatePlayerTick())
|
||||||
new ViaIdleThread(plugin.getPortedPlayers()).runTaskTimer(plugin, 1L, 1L); // Updates player's idle status
|
new ViaIdleThread(plugin.getPortedPlayers()).runTaskTimer(plugin, 1L, 1L); // Updates player's idle status
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners;
|
package us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||||
@ -16,30 +14,28 @@ import org.bukkit.event.player.PlayerRespawnEvent;
|
|||||||
import org.bukkit.inventory.CraftingInventory;
|
import org.bukkit.inventory.CraftingInventory;
|
||||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.ViaVersion;
|
import us.myles.ViaVersion.api.ViaListener;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ArmorType;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ArmorType;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
public class ArmorListener extends ViaListener {
|
||||||
public class ArmorListener implements Listener {
|
|
||||||
|
|
||||||
private static final UUID ARMOR_ATTRIBUTE = UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150");
|
private static final UUID ARMOR_ATTRIBUTE = UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150");
|
||||||
private final ViaVersionPlugin plugin;
|
|
||||||
|
|
||||||
public static void sendArmorUpdate(Player player) {
|
public ArmorListener(ViaVersionPlugin plugin) {
|
||||||
|
super(plugin, Protocol1_9TO1_8.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendArmorUpdate(Player player) {
|
||||||
// Ensure that the player is on our pipe
|
// Ensure that the player is on our pipe
|
||||||
UserConnection userConnection = ((ViaVersionPlugin) ViaVersion.getInstance()).getConnection(player);
|
if (!isOnPipe(player)) return;
|
||||||
if (userConnection == null) return;
|
|
||||||
if (!userConnection.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) return;
|
|
||||||
|
|
||||||
int armor = ArmorType.calculateArmorPoints(player.getInventory().getArmorContents());
|
int armor = ArmorType.calculateArmorPoints(player.getInventory().getArmorContents());
|
||||||
|
|
||||||
PacketWrapper wrapper = new PacketWrapper(0x4B, null, userConnection);
|
PacketWrapper wrapper = new PacketWrapper(0x4B, null, getUserConnection(player));
|
||||||
try {
|
try {
|
||||||
wrapper.write(Type.VAR_INT, player.getEntityId()); // Player ID
|
wrapper.write(Type.VAR_INT, player.getEntityId()); // Player ID
|
||||||
wrapper.write(Type.INT, 1); // only 1 property
|
wrapper.write(Type.INT, 1); // only 1 property
|
||||||
@ -61,17 +57,15 @@ public class ArmorListener implements Listener {
|
|||||||
HumanEntity human = e.getWhoClicked();
|
HumanEntity human = e.getWhoClicked();
|
||||||
if (human instanceof Player && e.getInventory() instanceof CraftingInventory) {
|
if (human instanceof Player && e.getInventory() instanceof CraftingInventory) {
|
||||||
final Player player = (Player) human;
|
final Player player = (Player) human;
|
||||||
if (ViaVersion.getInstance().isPorted(player)) {
|
if (e.getCurrentItem() != null) {
|
||||||
if (e.getCurrentItem() != null) {
|
if (ArmorType.isArmor(e.getCurrentItem().getType())) {
|
||||||
if (ArmorType.isArmor(e.getCurrentItem().getType())) {
|
|
||||||
sendDelayedArmorUpdate(player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (e.getRawSlot() >= 5 && e.getRawSlot() <= 8) {
|
|
||||||
sendDelayedArmorUpdate(player);
|
sendDelayedArmorUpdate(player);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (e.getRawSlot() >= 5 && e.getRawSlot() <= 8) {
|
||||||
|
sendDelayedArmorUpdate(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,12 +75,10 @@ public class ArmorListener implements Listener {
|
|||||||
if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||||
final Player player = e.getPlayer();
|
final Player player = e.getPlayer();
|
||||||
// Due to odd bugs it's 3 ticks later
|
// Due to odd bugs it's 3 ticks later
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (ViaVersion.getInstance().isPorted(player)) {
|
sendArmorUpdate(player);
|
||||||
sendArmorUpdate(player);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, 3L);
|
}, 3L);
|
||||||
}
|
}
|
||||||
@ -100,23 +92,20 @@ public class ArmorListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onRespawn(PlayerRespawnEvent e) {
|
public void onRespawn(PlayerRespawnEvent e) {
|
||||||
if (ViaVersion.getInstance().isPorted(e.getPlayer()))
|
sendDelayedArmorUpdate(e.getPlayer());
|
||||||
sendDelayedArmorUpdate(e.getPlayer());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onWorldChange(PlayerChangedWorldEvent e) {
|
public void onWorldChange(PlayerChangedWorldEvent e) {
|
||||||
if (ViaVersion.getInstance().isPorted(e.getPlayer()))
|
sendArmorUpdate(e.getPlayer());
|
||||||
sendArmorUpdate(e.getPlayer());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendDelayedArmorUpdate(final Player player) {
|
public void sendDelayedArmorUpdate(final Player player) {
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
if (!isOnPipe(player)) return; // Don't start a task if the player is not on the pipe
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (ViaVersion.getInstance().isPorted(player)) {
|
sendArmorUpdate(player);
|
||||||
sendArmorUpdate(player);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,28 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners;
|
package us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.ViaListener;
|
||||||
import us.myles.ViaVersion.api.minecraft.Position;
|
import us.myles.ViaVersion.api.minecraft.Position;
|
||||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
public class BlockListener extends ViaListener {
|
||||||
public class BlockListener implements Listener {
|
|
||||||
|
|
||||||
private final ViaVersionPlugin plugin;
|
public BlockListener(ViaVersionPlugin plugin) {
|
||||||
|
super(plugin, Protocol1_9TO1_8.class);
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void placeBlock(BlockPlaceEvent e) {
|
public void placeBlock(BlockPlaceEvent e) {
|
||||||
if (plugin.isPorted(e.getPlayer())) {
|
if (isOnPipe(e.getPlayer())) {
|
||||||
UserConnection c = plugin.getConnection(e.getPlayer());
|
|
||||||
if (!c.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) return;
|
|
||||||
Block b = e.getBlockPlaced();
|
Block b = e.getBlockPlaced();
|
||||||
plugin.getConnection(e.getPlayer()).get(EntityTracker.class).addBlockInteraction(new Position((long) b.getX(), (long) b.getY(), (long) b.getZ()));
|
getUserConnection(e.getPlayer())
|
||||||
|
.get(EntityTracker.class)
|
||||||
|
.addBlockInteraction(new Position((long) b.getX(), (long) b.getY(), (long) b.getZ()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,14 +3,12 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ByteBufOutputStream;
|
import io.netty.buffer.ByteBufOutputStream;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.CommandBlock;
|
import org.bukkit.block.CommandBlock;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
@ -20,11 +18,10 @@ import org.spacehq.opennbt.tag.builtin.ByteTag;
|
|||||||
import org.spacehq.opennbt.tag.builtin.CompoundTag;
|
import org.spacehq.opennbt.tag.builtin.CompoundTag;
|
||||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.ViaVersion;
|
import us.myles.ViaVersion.api.ViaListener;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.minecraft.Position;
|
import us.myles.ViaVersion.api.minecraft.Position;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
||||||
import us.myles.ViaVersion.util.ReflectionUtil;
|
import us.myles.ViaVersion.util.ReflectionUtil;
|
||||||
|
|
||||||
@ -32,10 +29,11 @@ import java.io.DataOutput;
|
|||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
public class CommandBlockListener extends ViaListener {
|
||||||
public class CommandBlockListener implements Listener {
|
|
||||||
|
|
||||||
private final ViaVersionPlugin plugin;
|
public CommandBlockListener(ViaVersionPlugin plugin) {
|
||||||
|
super(plugin, Protocol1_9TO1_8.class);
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||||
public void onJoin(PlayerJoinEvent e) {
|
public void onJoin(PlayerJoinEvent e) {
|
||||||
@ -44,7 +42,9 @@ public class CommandBlockListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onRespawn(final PlayerRespawnEvent e) {
|
public void onRespawn(final PlayerRespawnEvent e) {
|
||||||
Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
|
if (!isOnPipe(e.getPlayer())) return;
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTaskLater(getPlugin(), new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
sendOp(e.getPlayer());
|
sendOp(e.getPlayer());
|
||||||
@ -59,12 +59,7 @@ public class CommandBlockListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onInteract(PlayerInteractEvent e) {
|
public void onInteract(PlayerInteractEvent e) {
|
||||||
if (e.getAction() == Action.RIGHT_CLICK_BLOCK && plugin.isPorted(e.getPlayer()) && e.getPlayer().isOp()) {
|
if (e.getAction() == Action.RIGHT_CLICK_BLOCK && isOnPipe(e.getPlayer()) && e.getPlayer().isOp()) {
|
||||||
// Ensure that the player is on our pipe
|
|
||||||
UserConnection userConnection = ((ViaVersionPlugin) ViaVersion.getInstance()).getConnection(e.getPlayer());
|
|
||||||
if (userConnection == null) return;
|
|
||||||
if (!userConnection.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) return;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sendCommandBlockPacket(e.getClickedBlock(), e.getPlayer());
|
sendCommandBlockPacket(e.getClickedBlock(), e.getPlayer());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@ -74,16 +69,13 @@ public class CommandBlockListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendOp(Player p) {
|
private void sendOp(Player p) {
|
||||||
if (p.isOp() && plugin.isPorted(p)) {
|
if (p.isOp() && isOnPipe(p)) {
|
||||||
// Ensure that the player is on our pipe
|
|
||||||
UserConnection userConnection = ((ViaVersionPlugin) ViaVersion.getInstance()).getConnection(p);
|
|
||||||
if (userConnection == null) return;
|
|
||||||
if (!userConnection.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) return;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PacketWrapper wrapper = new PacketWrapper(0x1B, null, userConnection); // Entity status
|
PacketWrapper wrapper = new PacketWrapper(0x1B, null, getUserConnection(p)); // Entity status
|
||||||
wrapper.write(Type.INT, p.getEntityId());
|
|
||||||
|
wrapper.write(Type.INT, p.getEntityId()); // Entity ID
|
||||||
wrapper.write(Type.BYTE, (byte) 26); //Hardcoded op permission level
|
wrapper.write(Type.BYTE, (byte) 26); //Hardcoded op permission level
|
||||||
|
|
||||||
wrapper.send(Protocol1_9TO1_8.class);
|
wrapper.send(Protocol1_9TO1_8.class);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -99,9 +91,7 @@ public class CommandBlockListener implements Listener {
|
|||||||
Object tileEntityCommand = ReflectionUtil.get(cmd, "commandBlock", ReflectionUtil.nms("TileEntityCommand"));
|
Object tileEntityCommand = ReflectionUtil.get(cmd, "commandBlock", ReflectionUtil.nms("TileEntityCommand"));
|
||||||
Object updatePacket = ReflectionUtil.invoke(tileEntityCommand, "getUpdatePacket");
|
Object updatePacket = ReflectionUtil.invoke(tileEntityCommand, "getUpdatePacket");
|
||||||
|
|
||||||
UserConnection userConnection = ((ViaVersionPlugin) ViaVersion.getInstance()).getConnection(player);
|
PacketWrapper wrapper = generatePacket(updatePacket, getUserConnection(player));
|
||||||
|
|
||||||
PacketWrapper wrapper = generatePacket(updatePacket, userConnection);
|
|
||||||
wrapper.send(Protocol1_9TO1_8.class);
|
wrapper.send(Protocol1_9TO1_8.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,40 +1,28 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners;
|
package us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
|
import us.myles.ViaVersion.api.ViaListener;
|
||||||
import us.myles.ViaVersion.api.ViaVersion;
|
import us.myles.ViaVersion.api.ViaVersion;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
public class DeathListener extends ViaListener {
|
||||||
public class DeathListener implements Listener {
|
public DeathListener(ViaVersionPlugin plugin) {
|
||||||
private final ViaVersionPlugin plugin;
|
super(plugin, Protocol1_9TO1_8.class);
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||||
public void onDeath(PlayerDeathEvent e) {
|
public void onDeath(PlayerDeathEvent e) {
|
||||||
Player p = e.getEntity();
|
Player p = e.getEntity();
|
||||||
if (ViaVersion.getConfig().isShowNewDeathMessages() && checkGamerule(p.getWorld()) && e.getDeathMessage() != null && checkPipeline(p)) {
|
if (isOnPipe(p) && ViaVersion.getConfig().isShowNewDeathMessages() && checkGamerule(p.getWorld()) && e.getDeathMessage() != null)
|
||||||
sendPacket(p, e.getDeathMessage());
|
sendPacket(p, e.getDeathMessage());
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean checkPipeline(Player p) {
|
|
||||||
UserConnection userConnection = plugin.getConnection(p);
|
|
||||||
return userConnection != null && userConnection.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
private UserConnection getUserConnection(Player p) {
|
|
||||||
return plugin.getConnection(p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkGamerule(World w) {
|
public boolean checkGamerule(World w) {
|
||||||
@ -46,19 +34,19 @@ public class DeathListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendPacket(final Player p, final String msg) {
|
private void sendPacket(final Player p, final String msg) {
|
||||||
Bukkit.getScheduler().runTask(plugin, new Runnable() {
|
Bukkit.getScheduler().runTask(getPlugin(), new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PacketWrapper wrapper = new PacketWrapper(0x2C, null, getUserConnection(p));
|
PacketWrapper wrapper = new PacketWrapper(0x2C, null, getUserConnection(p));
|
||||||
try {
|
try {
|
||||||
wrapper.write(Type.VAR_INT, 2);
|
wrapper.write(Type.VAR_INT, 2); // Event - Entity dead
|
||||||
wrapper.write(Type.VAR_INT, p.getEntityId());
|
wrapper.write(Type.VAR_INT, p.getEntityId()); // Player ID
|
||||||
wrapper.write(Type.INT, p.getEntityId());
|
wrapper.write(Type.INT, p.getEntityId()); // Entity ID
|
||||||
Protocol1_9TO1_8.FIX_JSON.write(wrapper, msg);
|
Protocol1_9TO1_8.FIX_JSON.write(wrapper, msg); // Message
|
||||||
|
|
||||||
wrapper.send(Protocol1_9TO1_8.class);
|
wrapper.send(Protocol1_9TO1_8.class);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
wrapper.clearInputBuffer();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -3,15 +3,16 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||||
import us.myles.ViaVersion.api.ViaVersion;
|
import us.myles.ViaVersion.api.ViaListener;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
|
||||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
||||||
|
|
||||||
public class PaperPatch implements Listener {
|
public class PaperPatch extends ViaListener {
|
||||||
|
|
||||||
|
public PaperPatch(ViaVersionPlugin plugin) {
|
||||||
|
super(plugin, Protocol1_9TO1_8.class);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This patch is applied when Paper is detected.
|
This patch is applied when Paper is detected.
|
||||||
@ -22,10 +23,7 @@ public class PaperPatch implements Listener {
|
|||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onPlace(BlockPlaceEvent e) {
|
public void onPlace(BlockPlaceEvent e) {
|
||||||
if (ViaVersion.getInstance().isPorted(e.getPlayer())) {
|
if (isOnPipe(e.getPlayer())) {
|
||||||
UserConnection userConnection = ((ViaVersionPlugin) ViaVersion.getInstance()).getConnection(e.getPlayer());
|
|
||||||
if (userConnection == null) return;
|
|
||||||
if (!userConnection.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) return;
|
|
||||||
Location diff = e.getPlayer().getLocation().subtract(e.getBlock().getLocation().add(0.5D, 0, 0.5D));
|
Location diff = e.getPlayer().getLocation().subtract(e.getBlock().getLocation().add(0.5D, 0, 0.5D));
|
||||||
if (e.getPlayer().getLocation().getBlock().equals(e.getBlock())) {
|
if (e.getPlayer().getLocation().getBlock().equals(e.getBlock())) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren