3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 00:22:51 +01:00

Rename the Meta(List)1_9_1_10Type to Metadata(List)1_9Type and cleanup the listeners

Dieser Commit ist enthalten in:
Matsv 2016-07-11 20:27:44 +02:00
Ursprung b2680d76a6
Commit 693990644f
11 geänderte Dateien mit 156 neuen und 117 gelöschten Zeilen

Datei anzeigen

@ -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;
}
}

Datei anzeigen

@ -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.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.MetaList1_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.MetadataList1_9Type;
import java.util.List;
@ -11,10 +11,10 @@ public class Types1_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
*/
public static final Type<Metadata> METADATA = new Meta1_9_1_10Type();
public static final Type<Metadata> METADATA = new Metadata1_9Type();
}

Datei anzeigen

@ -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.packets.State;
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.MetaList1_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.MetadataList1_9Type;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public class Protocol1_10To1_9_3_4 extends Protocol {
@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
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) {
@Override

Datei anzeigen

@ -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.protocols.protocol1_9to1_8.metadata.NewType;
public class Meta1_9_1_10Type extends MetaTypeTemplate {
public class Metadata1_9Type extends MetaTypeTemplate {
@Override
public Metadata read(ByteBuf buffer) throws Exception {

Datei anzeigen

@ -8,7 +8,7 @@ import us.myles.ViaVersion.api.type.types.minecraft.Types1_9;
import java.util.ArrayList;
import java.util.List;
public class MetaList1_9_1_10Type extends MetaListTypeTemplate {
public class MetadataList1_9Type extends MetaListTypeTemplate {
@Override
public List<Metadata> read(ByteBuf buffer) throws Exception {

Datei anzeigen

@ -105,13 +105,15 @@ public class Protocol1_9TO1_8 extends Protocol {
@Override
protected void registerListeners() {
ViaVersionPlugin plugin = (ViaVersionPlugin) Bukkit.getPluginManager().getPlugin("ViaVersion");
Bukkit.getPluginManager().registerEvents(new ArmorListener(plugin), plugin);
Bukkit.getPluginManager().registerEvents(new CommandBlockListener(plugin), plugin);
Bukkit.getPluginManager().registerEvents(new DeathListener(plugin), plugin);
Bukkit.getPluginManager().registerEvents(new BlockListener(plugin), plugin);
new ArmorListener(plugin).register();
new CommandBlockListener(plugin).register();
new DeathListener(plugin).register();
new BlockListener(plugin).register();
if (Bukkit.getVersion().toLowerCase().contains("paper") || Bukkit.getVersion().toLowerCase().contains("taco")) {
plugin.getLogger().info("Enabling PaperSpigot/TacoSpigot patch: Fixes block placement.");
Bukkit.getPluginManager().registerEvents(new PaperPatch(), plugin);
new PaperPatch(plugin).register();
}
if (plugin.getConf().isStimulatePlayerTick())
new ViaIdleThread(plugin.getPortedPlayers()).runTaskTimer(plugin, 1L, 1L); // Updates player's idle status

Datei anzeigen

@ -1,12 +1,10 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners;
import lombok.RequiredArgsConstructor;
import org.bukkit.Bukkit;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
@ -16,30 +14,28 @@ import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.inventory.CraftingInventory;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.ViaListener;
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.Protocol1_9TO1_8;
import java.util.UUID;
@RequiredArgsConstructor
public class ArmorListener implements Listener {
public class ArmorListener extends ViaListener {
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
UserConnection userConnection = ((ViaVersionPlugin) ViaVersion.getInstance()).getConnection(player);
if (userConnection == null) return;
if (!userConnection.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) return;
if (!isOnPipe(player)) return;
int armor = ArmorType.calculateArmorPoints(player.getInventory().getArmorContents());
PacketWrapper wrapper = new PacketWrapper(0x4B, null, userConnection);
PacketWrapper wrapper = new PacketWrapper(0x4B, null, getUserConnection(player));
try {
wrapper.write(Type.VAR_INT, player.getEntityId()); // Player ID
wrapper.write(Type.INT, 1); // only 1 property
@ -61,7 +57,6 @@ public class ArmorListener implements Listener {
HumanEntity human = e.getWhoClicked();
if (human instanceof Player && e.getInventory() instanceof CraftingInventory) {
final Player player = (Player) human;
if (ViaVersion.getInstance().isPorted(player)) {
if (e.getCurrentItem() != null) {
if (ArmorType.isArmor(e.getCurrentItem().getType())) {
sendDelayedArmorUpdate(player);
@ -73,7 +68,6 @@ public class ArmorListener implements Listener {
}
}
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInteract(PlayerInteractEvent e) {
@ -81,13 +75,11 @@ public class ArmorListener implements Listener {
if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
final Player player = e.getPlayer();
// Due to odd bugs it's 3 ticks later
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), new Runnable() {
@Override
public void run() {
if (ViaVersion.getInstance().isPorted(player)) {
sendArmorUpdate(player);
}
}
}, 3L);
}
}
@ -100,24 +92,21 @@ public class ArmorListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onRespawn(PlayerRespawnEvent e) {
if (ViaVersion.getInstance().isPorted(e.getPlayer()))
sendDelayedArmorUpdate(e.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onWorldChange(PlayerChangedWorldEvent e) {
if (ViaVersion.getInstance().isPorted(e.getPlayer()))
sendArmorUpdate(e.getPlayer());
}
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
public void run() {
if (ViaVersion.getInstance().isPorted(player)) {
sendArmorUpdate(player);
}
}
});
}
}

Datei anzeigen

@ -1,30 +1,28 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners;
import lombok.RequiredArgsConstructor;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
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.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
@RequiredArgsConstructor
public class BlockListener implements Listener {
public class BlockListener extends ViaListener {
private final ViaVersionPlugin plugin;
public BlockListener(ViaVersionPlugin plugin) {
super(plugin, Protocol1_9TO1_8.class);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void placeBlock(BlockPlaceEvent e) {
if (plugin.isPorted(e.getPlayer())) {
UserConnection c = plugin.getConnection(e.getPlayer());
if (!c.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) return;
if (isOnPipe(e.getPlayer())) {
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()));
}
}
}

Datei anzeigen

@ -3,14 +3,12 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufOutputStream;
import io.netty.buffer.Unpooled;
import lombok.RequiredArgsConstructor;
import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.block.CommandBlock;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerChangedWorldEvent;
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 us.myles.ViaVersion.ViaVersionPlugin;
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.minecraft.Position;
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.util.ReflectionUtil;
@ -32,10 +29,11 @@ import java.io.DataOutput;
import java.io.DataOutputStream;
import java.lang.reflect.Method;
@RequiredArgsConstructor
public class CommandBlockListener implements Listener {
public class CommandBlockListener extends ViaListener {
private final ViaVersionPlugin plugin;
public CommandBlockListener(ViaVersionPlugin plugin) {
super(plugin, Protocol1_9TO1_8.class);
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onJoin(PlayerJoinEvent e) {
@ -44,7 +42,9 @@ public class CommandBlockListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void onRespawn(final PlayerRespawnEvent e) {
Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
if (!isOnPipe(e.getPlayer())) return;
Bukkit.getScheduler().runTaskLater(getPlugin(), new Runnable() {
@Override
public void run() {
sendOp(e.getPlayer());
@ -59,12 +59,7 @@ public class CommandBlockListener implements Listener {
@EventHandler(ignoreCancelled = true)
public void onInteract(PlayerInteractEvent e) {
if (e.getAction() == Action.RIGHT_CLICK_BLOCK && plugin.isPorted(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;
if (e.getAction() == Action.RIGHT_CLICK_BLOCK && isOnPipe(e.getPlayer()) && e.getPlayer().isOp()) {
try {
sendCommandBlockPacket(e.getClickedBlock(), e.getPlayer());
} catch (Exception ex) {
@ -74,16 +69,13 @@ public class CommandBlockListener implements Listener {
}
private void sendOp(Player p) {
if (p.isOp() && plugin.isPorted(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;
if (p.isOp() && isOnPipe(p)) {
try {
PacketWrapper wrapper = new PacketWrapper(0x1B, null, userConnection); // Entity status
wrapper.write(Type.INT, p.getEntityId());
PacketWrapper wrapper = new PacketWrapper(0x1B, null, getUserConnection(p)); // Entity status
wrapper.write(Type.INT, p.getEntityId()); // Entity ID
wrapper.write(Type.BYTE, (byte) 26); //Hardcoded op permission level
wrapper.send(Protocol1_9TO1_8.class);
} catch (Exception e) {
e.printStackTrace();
@ -99,9 +91,7 @@ public class CommandBlockListener implements Listener {
Object tileEntityCommand = ReflectionUtil.get(cmd, "commandBlock", ReflectionUtil.nms("TileEntityCommand"));
Object updatePacket = ReflectionUtil.invoke(tileEntityCommand, "getUpdatePacket");
UserConnection userConnection = ((ViaVersionPlugin) ViaVersion.getInstance()).getConnection(player);
PacketWrapper wrapper = generatePacket(updatePacket, userConnection);
PacketWrapper wrapper = generatePacket(updatePacket, getUserConnection(player));
wrapper.send(Protocol1_9TO1_8.class);
}

Datei anzeigen

@ -1,41 +1,29 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners;
import lombok.RequiredArgsConstructor;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.ViaListener;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.data.UserConnection;
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;
@RequiredArgsConstructor
public class DeathListener implements Listener {
private final ViaVersionPlugin plugin;
public class DeathListener extends ViaListener {
public DeathListener(ViaVersionPlugin plugin) {
super(plugin, Protocol1_9TO1_8.class);
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onDeath(PlayerDeathEvent e) {
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());
}
}
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) {
try {
@ -46,19 +34,19 @@ public class DeathListener implements Listener {
}
private void sendPacket(final Player p, final String msg) {
Bukkit.getScheduler().runTask(plugin, new Runnable() {
Bukkit.getScheduler().runTask(getPlugin(), new Runnable() {
@Override
public void run() {
PacketWrapper wrapper = new PacketWrapper(0x2C, null, getUserConnection(p));
try {
wrapper.write(Type.VAR_INT, 2);
wrapper.write(Type.VAR_INT, p.getEntityId());
wrapper.write(Type.INT, p.getEntityId());
Protocol1_9TO1_8.FIX_JSON.write(wrapper, msg);
wrapper.write(Type.VAR_INT, 2); // Event - Entity dead
wrapper.write(Type.VAR_INT, p.getEntityId()); // Player ID
wrapper.write(Type.INT, p.getEntityId()); // Entity ID
Protocol1_9TO1_8.FIX_JSON.write(wrapper, msg); // Message
wrapper.send(Protocol1_9TO1_8.class);
} catch (Exception e) {
e.printStackTrace();
wrapper.clearInputBuffer();
}
}
});

Datei anzeigen

@ -3,15 +3,16 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners;
import org.bukkit.Location;
import org.bukkit.block.BlockFace;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.api.ViaListener;
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.
@ -22,10 +23,7 @@ public class PaperPatch implements Listener {
@EventHandler(ignoreCancelled = true)
public void onPlace(BlockPlaceEvent e) {
if (ViaVersion.getInstance().isPorted(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;
if (isOnPipe(e.getPlayer())) {
Location diff = e.getPlayer().getLocation().subtract(e.getBlock().getLocation().add(0.5D, 0, 0.5D));
if (e.getPlayer().getLocation().getBlock().equals(e.getBlock())) {
e.setCancelled(true);