Make ProtocolLib optional.
This commit is contained in:
parent
a874053dee
commit
525e5e58b4
30
src/net/spoothie/chairs/ChairWatcher.java
Normal file
30
src/net/spoothie/chairs/ChairWatcher.java
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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_R3.DataWatcher;
|
||||
import net.minecraft.server.v1_5_R3.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;
|
||||
}
|
||||
}
|
@ -10,15 +10,16 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import net.minecraft.server.v1_5_R3.Packet40EntityMetadata;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
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;
|
||||
|
||||
@ -49,11 +50,6 @@ public class Chairs extends JavaPlugin {
|
||||
|
||||
@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();
|
||||
@ -70,7 +66,12 @@ public class Chairs extends JavaPlugin {
|
||||
logInfo("Enabling sitting effects.");
|
||||
chairEffects = new ChairEffects(this);
|
||||
}
|
||||
if (isProtocolLibLoaded()) {
|
||||
logInfo("ProtocolLib detected.");
|
||||
protocolManager = ProtocolLibrary.getProtocolManager();
|
||||
} else {
|
||||
logInfo("ProtocolLib not detected. Using NMS code methods instead.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -114,6 +115,10 @@ public class Chairs extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isProtocolLibLoaded() {
|
||||
return (getServer().getPluginManager().getPlugin("ProtocolLib") != null);
|
||||
}
|
||||
|
||||
public void loadConfig() {
|
||||
autoRotate = getConfig().getBoolean("auto-rotate");
|
||||
sneaking = getConfig().getBoolean("sneaking");
|
||||
@ -228,7 +233,12 @@ public class Chairs extends JavaPlugin {
|
||||
|
||||
// Send sit packet to all online players that are on same world and can see player
|
||||
public void sendSit(Player p) {
|
||||
if (protocolManager != null) {
|
||||
sendPacketToPlayers(getSitPacket(p),p);
|
||||
} else {
|
||||
Packet40EntityMetadata packet = new Packet40EntityMetadata(p.getPlayer().getEntityId(), new ChairWatcher((byte) 4), false);
|
||||
sendPacketToPlayers(packet,p);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendPacketToPlayers(PacketContainer pc, Player p) {
|
||||
@ -245,6 +255,20 @@ public class Chairs extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
private void sendPacketToPlayers(Packet40EntityMetadata packet, Player p) {
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (onlinePlayer.canSee(p)) {
|
||||
if (onlinePlayer.getWorld().equals(p.getWorld())) {
|
||||
try {
|
||||
((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
|
||||
} catch (Exception ex) {
|
||||
// Nothing here
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void sendSit() {
|
||||
for (String s : sit.keySet()) {
|
||||
Player p = Bukkit.getPlayer(s);
|
||||
@ -262,7 +286,12 @@ public class Chairs extends JavaPlugin {
|
||||
}
|
||||
sit.remove(p.getName());
|
||||
}
|
||||
if (protocolManager != null) {
|
||||
sendPacketToPlayers(getStandPacket(p),p);
|
||||
} else {
|
||||
Packet40EntityMetadata packet = new Packet40EntityMetadata(p.getPlayer().getEntityId(), new ChairWatcher((byte) 0), false);
|
||||
sendPacketToPlayers(packet,p);
|
||||
}
|
||||
}
|
||||
|
||||
public void logInfo(String _message) {
|
||||
@ -277,13 +306,4 @@ public class Chairs extends JavaPlugin {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public boolean checkForProtocolLib() {
|
||||
Plugin plugin = getServer().getPluginManager().getPlugin("ProtocolLib");
|
||||
if (plugin == null) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
name: Chairs
|
||||
version: 2.0.3
|
||||
version: 2.1.3
|
||||
description: Let players sit on blocks.
|
||||
authors:
|
||||
- spoothie
|
||||
- cnaude
|
||||
main: net.spoothie.chairs.Chairs
|
||||
softdepend:
|
||||
- ProtocolLib
|
||||
commands:
|
||||
chairs:
|
||||
description: Various commands for Chairs.
|
||||
|
Loading…
Reference in New Issue
Block a user