Remove CraftBukkit dependency.
Add ProtocolLib dependency.
This commit is contained in:
parent
7b8dba06e8
commit
7c9668f862
@ -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<WatchableObject> b() {
|
|
||||||
ArrayList<WatchableObject> list = new ArrayList<WatchableObject>();
|
|
||||||
WatchableObject wo = new WatchableObject(0, 0, Byte.valueOf(this.metadata));
|
|
||||||
list.add(wo);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,20 +1,23 @@
|
|||||||
package net.spoothie.chairs;
|
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.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import net.minecraft.server.v1_5_R2.Packet40EntityMetadata;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.permissions.Permission;
|
import org.bukkit.permissions.Permission;
|
||||||
import org.bukkit.permissions.PermissionDefault;
|
import org.bukkit.permissions.PermissionDefault;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
@ -41,9 +44,15 @@ public class Chairs extends JavaPlugin {
|
|||||||
public PluginManager pm;
|
public PluginManager pm;
|
||||||
public static ChairsIgnoreList ignoreList;
|
public static ChairsIgnoreList ignoreList;
|
||||||
public String msgSitting, msgStanding, msgOccupied, msgNoPerm, msgReloaded, msgDisabled, msgEnabled;
|
public String msgSitting, msgStanding, msgOccupied, msgNoPerm, msgReloaded, msgDisabled, msgEnabled;
|
||||||
|
private ProtocolManager protocolManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
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;
|
instance = this;
|
||||||
ignoreList = new ChairsIgnoreList();
|
ignoreList = new ChairsIgnoreList();
|
||||||
ignoreList.load();
|
ignoreList.load();
|
||||||
@ -60,6 +69,7 @@ public class Chairs extends JavaPlugin {
|
|||||||
logInfo("Enabling sitting effects.");
|
logInfo("Enabling sitting effects.");
|
||||||
chairEffects = new ChairEffects(this);
|
chairEffects = new ChairEffects(this);
|
||||||
}
|
}
|
||||||
|
protocolManager = ProtocolLibrary.getProtocolManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -190,10 +200,18 @@ public class Chairs extends JavaPlugin {
|
|||||||
|
|
||||||
// Send sit packet to all online players
|
// Send sit packet to all online players
|
||||||
public void sendSit(Player p) {
|
public void sendSit(Player p) {
|
||||||
Packet40EntityMetadata packet = new Packet40EntityMetadata(p.getPlayer().getEntityId(), new ChairWatcher((byte) 4), false);
|
PacketContainer fakeSit = protocolManager.createPacket(40);
|
||||||
for (Player play : Bukkit.getOnlinePlayers()) {
|
fakeSit.getSpecificModifier(int.class).write(0, p.getEntityId());
|
||||||
((CraftPlayer) play).getHandle().playerConnection.sendPacket(packet);
|
WrappedDataWatcher watcher = new WrappedDataWatcher();
|
||||||
//((CraftPlayer) play).getHandle().netServerHandler.sendPacket(packet);
|
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());
|
sit.remove(p.getName());
|
||||||
}
|
}
|
||||||
Packet40EntityMetadata packet = new Packet40EntityMetadata(p.getPlayer().getEntityId(), new ChairWatcher((byte) 0), false);
|
|
||||||
for (Player play : Bukkit.getOnlinePlayers()) {
|
PacketContainer fakeSit = protocolManager.createPacket(40);
|
||||||
((CraftPlayer) play).getHandle().playerConnection.sendPacket(packet);
|
fakeSit.getSpecificModifier(int.class).write(0, p.getEntityId());
|
||||||
//((CraftPlayer) play).getHandle().netServerHandler.sendPacket(packet);
|
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;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean checkForProtocolLib() {
|
||||||
|
Plugin plugin = getServer().getPluginManager().getPlugin("ProtocolLib");
|
||||||
|
if (plugin == null) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name: Chairs
|
name: Chairs
|
||||||
version: 1.22.0
|
version: 2.0.0
|
||||||
description: Let players sit on blocks.
|
description: Let players sit on blocks.
|
||||||
authors:
|
authors:
|
||||||
- spoothie
|
- spoothie
|
||||||
|
Loading…
Reference in New Issue
Block a user