Correctly unSit the player
This commit is contained in:
parent
0df6cf8eb4
commit
05b19edd5c
@ -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();
|
||||
|
@ -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,31 +38,42 @@ 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();
|
||||
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()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
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 = -1;
|
||||
}
|
||||
pm.getAsynchronousManager().signalPacketTransmission(e);
|
||||
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.
Loading…
Reference in New Issue
Block a user