That works, but DAFUQ?
This commit is contained in:
@@ -6,17 +6,22 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
|
||||
public class Chairs extends JavaPlugin {
|
||||
private static Chairs instance = null;
|
||||
public static ChairEffects chairEffects;
|
||||
@@ -32,7 +37,6 @@ public class Chairs extends JavaPlugin {
|
||||
public int sitEffectInterval;
|
||||
private File pluginFolder;
|
||||
private File configFile;
|
||||
public byte sitByte;
|
||||
public HashMap<String, Entity> sit = new HashMap<String, Entity>();
|
||||
public static final String PLUGIN_NAME = "Chairs";
|
||||
public static final String LOG_HEADER = "[" + PLUGIN_NAME + "]";
|
||||
@@ -40,6 +44,7 @@ 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() {
|
||||
@@ -59,16 +64,19 @@ public class Chairs extends JavaPlugin {
|
||||
logInfo("Enabling sitting effects.");
|
||||
chairEffects = new ChairEffects(this);
|
||||
}
|
||||
protocolManager = ProtocolLibrary.getProtocolManager();
|
||||
new PacketListener(protocolManager, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
protocolManager.removePacketListeners(this);
|
||||
protocolManager = null;
|
||||
for (String pName : sit.keySet()) {
|
||||
Player player = getServer().getPlayer(pName);
|
||||
Location loc = player.getLocation().clone();
|
||||
loc.setY(loc.getY() + 1);
|
||||
player.teleport(loc, PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||
|
||||
}
|
||||
if (ignoreList != null) {
|
||||
ignoreList.save();
|
||||
@@ -76,6 +84,8 @@ public class Chairs extends JavaPlugin {
|
||||
if (chairEffects != null) {
|
||||
chairEffects.cancel();
|
||||
}
|
||||
HandlerList.unregisterAll(this);
|
||||
instance = null;
|
||||
}
|
||||
|
||||
public void restartEffectsTask() {
|
||||
@@ -106,9 +116,7 @@ public class Chairs extends JavaPlugin {
|
||||
return (getServer().getPluginManager().getPlugin("ProtocolLib") != null);
|
||||
}
|
||||
|
||||
public void loadConfig() {
|
||||
sitByte = Byte.parseByte(getConfig().getString("packet"));
|
||||
logInfo("Sitting packet byte: " + sitByte);
|
||||
public void loadConfig() {
|
||||
autoRotate = getConfig().getBoolean("auto-rotate");
|
||||
sneaking = getConfig().getBoolean("sneaking");
|
||||
signCheck = getConfig().getBoolean("sign-check");
|
||||
|
@@ -4,6 +4,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftArrow;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -134,8 +135,6 @@ public class EventListener implements Listener {
|
||||
}
|
||||
|
||||
for (ChairBlock cb : plugin.allowedBlocks) {
|
||||
//plugin.logInfo("Comparing: (" + cb.getMat().name() + " ? " + block.getType().name() + ") ("
|
||||
// + cb.getDamage() + " ? " + block.getData() + ")");
|
||||
if (cb.getMat().toString().contains("STAIRS")) {
|
||||
if (cb.getMat().equals(block.getType())) {
|
||||
blockOkay = true;
|
||||
@@ -157,16 +156,12 @@ public class EventListener implements Listener {
|
||||
|
||||
if (block.getState().getData() instanceof Stairs) {
|
||||
stairs = (Stairs) block.getState().getData();
|
||||
//plugin.logInfo("STAIR");
|
||||
} else if (block.getState().getData() instanceof Step) {
|
||||
step = (Step) block.getState().getData();
|
||||
//plugin.logInfo("STEP");
|
||||
} else if (block.getState().getData() instanceof WoodenStep) {
|
||||
wStep = (WoodenStep) block.getState().getData();
|
||||
//plugin.logInfo("WOODEN_STEP");
|
||||
} else {
|
||||
sh += plugin.sittingHeightAdj;
|
||||
//plugin.logInfo("OTHER");
|
||||
}
|
||||
|
||||
int chairwidth = 1;
|
||||
@@ -202,7 +197,7 @@ public class EventListener implements Listener {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check for signs.
|
||||
if (plugin.signCheck == true && stairs != null) {
|
||||
boolean sign1 = false;
|
||||
@@ -235,9 +230,8 @@ public class EventListener implements Listener {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Sit-down process.
|
||||
if (!plugin.sneaking || (plugin.sneaking && event.getPlayer().isSneaking())) {
|
||||
if (plugin.seatOccupiedCheck) {
|
||||
if (!plugin.sit.isEmpty()) {
|
||||
for (String s : plugin.sit.keySet()) {
|
||||
@@ -268,6 +262,8 @@ public class EventListener implements Listener {
|
||||
break;
|
||||
case WEST:
|
||||
plocation.setYaw(90);
|
||||
default:
|
||||
;
|
||||
}
|
||||
player.teleport(plocation);
|
||||
} else {
|
||||
@@ -280,13 +276,11 @@ public class EventListener implements Listener {
|
||||
|
||||
player.getPlayer().teleport(plocation);
|
||||
Entity arrow = block.getWorld().spawnArrow(getBlockCentre(block).subtract(0, 0.5, 0), new Vector(0, 0, 0), 0, 0);
|
||||
|
||||
arrow.setPassenger(player);
|
||||
player.setSneaking(false);
|
||||
arrow.setTicksLived(1);
|
||||
plugin.sit.put(player.getName(), arrow);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
77
src/com/cnaude/chairs/PacketListener.java
Normal file
77
src/com/cnaude/chairs/PacketListener.java
Normal file
@@ -0,0 +1,77 @@
|
||||
package com.cnaude.chairs;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftArrow;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import com.comphenix.protocol.Packets;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
|
||||
public class PacketListener {
|
||||
|
||||
private ProtocolManager pm;
|
||||
private Chairs pluginInstance;
|
||||
public PacketListener(ProtocolManager pm, Chairs plugin)
|
||||
{
|
||||
this.pm = pm;
|
||||
this.pluginInstance = plugin;
|
||||
playerDismountListener();
|
||||
}
|
||||
|
||||
|
||||
private void playerDismountListener()
|
||||
{
|
||||
pm.getAsynchronousManager().registerAsyncHandler(
|
||||
new PacketAdapter(PacketAdapter
|
||||
.params(pluginInstance, Packets.Client.PLAYER_INPUT)
|
||||
.clientSide()
|
||||
.listenerPriority(ListenerPriority.HIGHEST)
|
||||
.optionIntercept()
|
||||
)
|
||||
{
|
||||
@Override
|
||||
public void onPacketReceiving(final PacketEvent e)
|
||||
{
|
||||
System.out.println("Checking packet");
|
||||
if (!e.isCancelled())
|
||||
{
|
||||
System.out.println(e.getPacket().getBooleans().getValues().get(1));
|
||||
final String playername = e.getPlayer().getName();
|
||||
if (e.getPacket().getBooleans().getValues().get(1))
|
||||
{
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(pluginInstance, new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
System.out.println("Doing magic");
|
||||
Entity arrow = pluginInstance.sit.get(playername);
|
||||
if (arrow != null)
|
||||
{
|
||||
net.minecraft.server.v1_6_R2.EntityArrow nmsarrow = ((CraftArrow) arrow).getHandle();
|
||||
nmsarrow.motX = 0;
|
||||
nmsarrow.motY = 0;
|
||||
nmsarrow.motZ = 0;
|
||||
nmsarrow.boundingBox.b = 0.1;
|
||||
}
|
||||
}
|
||||
});
|
||||
e.getAsyncMarker().incrementProcessingDelay();
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(pluginInstance, new Runnable()
|
||||
{
|
||||
public void run() {
|
||||
pm.getAsynchronousManager().signalPacketTransmission(e);
|
||||
}
|
||||
}, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user