Correctly unSit the player

This commit is contained in:
Shevchik 2013-09-01 14:39:11 +04:00
parent 0df6cf8eb4
commit 05b19edd5c
3 changed files with 34 additions and 46 deletions

View File

@ -11,8 +11,6 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.vehicle.VehicleExitEvent;
import org.bukkit.material.Stairs; import org.bukkit.material.Stairs;
import org.bukkit.material.Step; import org.bukkit.material.Step;
import org.bukkit.material.WoodenStep; import org.bukkit.material.WoodenStep;
@ -39,36 +37,6 @@ public class EventListener implements Listener {
return false; return false;
} }
@EventHandler
public void onVehicleExitEvent(VehicleExitEvent event) {
Entity e = event.getVehicle().getPassenger();
if (e instanceof Player) {
Player player = (Player) e;
if (plugin.sit.containsKey(player.getName())) {
unSit(player);
}
}
}
@EventHandler
public void onPlayerMoveEvent(PlayerMoveEvent event) {
if (event.getFrom().distance(event.getTo()) > 0) {
Player player = event.getPlayer();
if (plugin.sit.containsKey(player.getName())) {
if (plugin.sit.get(player.getName()).getLocation().distance(player.getLocation()) > 0.5) {
unSit(player);
}
}
}
}
private void unSit(Player player) {
plugin.sit.get(player.getName()).remove();
plugin.sit.remove(player.getName());
if (plugin.notifyplayer && !plugin.msgStanding.isEmpty()) {
player.sendMessage(plugin.msgStanding);
}
}
private boolean isSitting(Player player) { private boolean isSitting(Player player) {
if (player.isInsideVehicle()) { if (player.isInsideVehicle()) {
@ -80,6 +48,14 @@ public class EventListener implements Listener {
} }
return false; return false;
} }
private void unSit(Player player) {
plugin.sit.get(player.getName()).remove();
plugin.sit.remove(player.getName());
if (plugin.notifyplayer && !plugin.msgStanding.isEmpty()) {
player.sendMessage(plugin.msgStanding);
}
}
@EventHandler @EventHandler
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {

View File

@ -3,6 +3,7 @@ package com.cnaude.chairs;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftArrow; import org.bukkit.craftbukkit.v1_6_R2.entity.CraftArrow;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import com.comphenix.protocol.Packets; import com.comphenix.protocol.Packets;
import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.ProtocolManager;
@ -37,31 +38,42 @@ public class PacketListener {
{ {
if (!e.isCancelled()) if (!e.isCancelled())
{ {
final String playername = e.getPlayer().getName(); final Player player = e.getPlayer();
if (e.getPacket().getBooleans().getValues().get(1)) if (e.getPacket().getBooleans().getValues().get(1))
{ {
e.getAsyncMarker().incrementProcessingDelay(); final Entity arrow = pluginInstance.sit.get(player.getName());
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 = -1;
}
Bukkit.getScheduler().scheduleSyncDelayedTask(pluginInstance, new Runnable() Bukkit.getScheduler().scheduleSyncDelayedTask(pluginInstance, new Runnable()
{ {
public void run() public void run()
{ {
Entity arrow = pluginInstance.sit.get(playername); unSit(player);
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 = -1;
}
pm.getAsynchronousManager().signalPacketTransmission(e);
} }
}); },1);
} }
} }
} }
}).start(); }).syncStart();
} }
private void unSit(Player player) {
if (pluginInstance.sit.containsKey(player.getName()))
{
pluginInstance.sit.get(player.getName()).remove();
pluginInstance.sit.remove(player.getName());
if (pluginInstance.notifyplayer && !pluginInstance.msgStanding.isEmpty()) {
player.sendMessage(pluginInstance.msgStanding);
}
}
}
} }

Binary file not shown.