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.block.Action;
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.Step;
import org.bukkit.material.WoodenStep;
@ -39,36 +37,6 @@ public class EventListener implements Listener {
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) {
if (player.isInsideVehicle()) {
@ -81,6 +49,14 @@ public class EventListener implements Listener {
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
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();

View File

@ -3,6 +3,7 @@ package com.cnaude.chairs;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftArrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import com.comphenix.protocol.Packets;
import com.comphenix.protocol.ProtocolManager;
@ -37,15 +38,10 @@ public class PacketListener {
{
if (!e.isCancelled())
{
final String playername = e.getPlayer().getName();
final Player player = e.getPlayer();
if (e.getPacket().getBooleans().getValues().get(1))
{
e.getAsyncMarker().incrementProcessingDelay();
Bukkit.getScheduler().scheduleSyncDelayedTask(pluginInstance, new Runnable()
{
public void run()
{
Entity arrow = pluginInstance.sit.get(playername);
final Entity arrow = pluginInstance.sit.get(player.getName());
if (arrow != null)
{
net.minecraft.server.v1_6_R2.EntityArrow nmsarrow = ((CraftArrow) arrow).getHandle();
@ -54,14 +50,30 @@ public class PacketListener {
nmsarrow.motZ = 0;
nmsarrow.boundingBox.b = -1;
}
pm.getAsynchronousManager().signalPacketTransmission(e);
Bukkit.getScheduler().scheduleSyncDelayedTask(pluginInstance, new Runnable()
{
public void run()
{
unSit(player);
}
});
},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.