diff --git a/src/net/spoothie/chairs/ChairWatcher.java b/src/net/spoothie/chairs/ChairWatcher.java deleted file mode 100644 index 0ca1799..0000000 --- a/src/net/spoothie/chairs/ChairWatcher.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package net.spoothie.chairs; - -import java.util.ArrayList; -import net.minecraft.server.v1_5_R2.DataWatcher; -import net.minecraft.server.v1_5_R2.WatchableObject; - - -/** - * - * @author cnaude - */ -public class ChairWatcher extends DataWatcher { - - private byte metadata; - - public ChairWatcher(byte i) { - this.metadata = i; - } - - @Override - public ArrayList b() { - ArrayList list = new ArrayList(); - WatchableObject wo = new WatchableObject(0, 0, Byte.valueOf(this.metadata)); - list.add(wo); - return list; - } -} diff --git a/src/net/spoothie/chairs/Chairs.java b/src/net/spoothie/chairs/Chairs.java index 3cc0ee9..8f5a860 100644 --- a/src/net/spoothie/chairs/Chairs.java +++ b/src/net/spoothie/chairs/Chairs.java @@ -1,20 +1,23 @@ package net.spoothie.chairs; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.ProtocolManager; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.wrappers.WrappedDataWatcher; import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; -import net.minecraft.server.v1_5_R2.Packet40EntityMetadata; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionDefault; +import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -41,9 +44,15 @@ public class Chairs extends JavaPlugin { public PluginManager pm; public static ChairsIgnoreList ignoreList; public String msgSitting, msgStanding, msgOccupied, msgNoPerm, msgReloaded, msgDisabled, msgEnabled; + private ProtocolManager protocolManager; @Override public void onEnable() { + if (!checkForProtocolLib()) { + logError("This plugin requires ProtocolLib. Please download the latest: http://dev.bukkit.org/server-mods/protocollib/"); + Bukkit.getServer().getPluginManager().disablePlugin(this); + return; + } instance = this; ignoreList = new ChairsIgnoreList(); ignoreList.load(); @@ -60,6 +69,7 @@ public class Chairs extends JavaPlugin { logInfo("Enabling sitting effects."); chairEffects = new ChairEffects(this); } + protocolManager = ProtocolLibrary.getProtocolManager(); } @Override @@ -189,11 +199,19 @@ public class Chairs extends JavaPlugin { } // Send sit packet to all online players - public void sendSit(Player p) { - Packet40EntityMetadata packet = new Packet40EntityMetadata(p.getPlayer().getEntityId(), new ChairWatcher((byte) 4), false); - for (Player play : Bukkit.getOnlinePlayers()) { - ((CraftPlayer) play).getHandle().playerConnection.sendPacket(packet); - //((CraftPlayer) play).getHandle().netServerHandler.sendPacket(packet); + public void sendSit(Player p) { + PacketContainer fakeSit = protocolManager.createPacket(40); + fakeSit.getSpecificModifier(int.class).write(0, p.getEntityId()); + WrappedDataWatcher watcher = new WrappedDataWatcher(); + watcher.setObject(0, (byte)4); + fakeSit.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects()); + + for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { + try { + protocolManager.sendServerPacket(onlinePlayer, fakeSit); + } catch (Exception ex) { + // Nothing here + } } } @@ -214,10 +232,20 @@ public class Chairs extends JavaPlugin { } sit.remove(p.getName()); } - Packet40EntityMetadata packet = new Packet40EntityMetadata(p.getPlayer().getEntityId(), new ChairWatcher((byte) 0), false); - for (Player play : Bukkit.getOnlinePlayers()) { - ((CraftPlayer) play).getHandle().playerConnection.sendPacket(packet); - //((CraftPlayer) play).getHandle().netServerHandler.sendPacket(packet); + + PacketContainer fakeSit = protocolManager.createPacket(40); + fakeSit.getSpecificModifier(int.class).write(0, p.getEntityId()); + WrappedDataWatcher watcher = new WrappedDataWatcher(); + watcher.setObject(0, (byte)0); + fakeSit.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects()); + + + for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { + try { + protocolManager.sendServerPacket(onlinePlayer, fakeSit); + } catch (Exception ex) { + // Nothing here + } } } @@ -233,4 +261,13 @@ public class Chairs extends JavaPlugin { return instance; } + public boolean checkForProtocolLib() { + Plugin plugin = getServer().getPluginManager().getPlugin("ProtocolLib"); + if (plugin == null) { + return false; + } else { + return true; + } + } + } diff --git a/src/plugin.yml b/src/plugin.yml index cd23a86..237f6c0 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,5 +1,5 @@ name: Chairs -version: 1.22.0 +version: 2.0.0 description: Let players sit on blocks. authors: - spoothie