Also unsit player on teleport event
This commit is contained in:
parent
03c683af03
commit
ef9f272a57
@ -83,7 +83,7 @@ public class Chairs extends JavaPlugin {
|
|||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
for (Player player : getServer().getOnlinePlayers()) {
|
for (Player player : getServer().getOnlinePlayers()) {
|
||||||
if (sit.containsKey(player.getName())) {
|
if (sit.containsKey(player.getName())) {
|
||||||
unSitPlayer(player, true);
|
unSitPlayer(player, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ignoreList != null) {
|
if (ignoreList != null) {
|
||||||
@ -175,14 +175,14 @@ public class Chairs extends JavaPlugin {
|
|||||||
arrow.setPassenger(player);
|
arrow.setPassenger(player);
|
||||||
return arrow;
|
return arrow;
|
||||||
}
|
}
|
||||||
protected void unSitPlayer(final Player player, boolean playerleft)
|
protected void unSitPlayer(final Player player, boolean restoreposition, boolean correctnmspostion)
|
||||||
{
|
{
|
||||||
final Entity arrow = sit.get(player.getName());
|
final Entity arrow = sit.get(player.getName());
|
||||||
sit.remove(player.getName());
|
sit.remove(player.getName());
|
||||||
player.eject();
|
player.eject();
|
||||||
arrow.remove();
|
arrow.remove();
|
||||||
final Location tploc = sitstopteleportloc.get(player.getName());
|
final Location tploc = sitstopteleportloc.get(player.getName());
|
||||||
if (!playerleft)
|
if (restoreposition)
|
||||||
{
|
{
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable()
|
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable()
|
||||||
{
|
{
|
||||||
@ -194,22 +194,25 @@ public class Chairs extends JavaPlugin {
|
|||||||
},1);
|
},1);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
try {
|
if (correctnmspostion)
|
||||||
Method getHandleMethod = player.getClass().getDeclaredMethod("getHandle");
|
{
|
||||||
getHandleMethod.setAccessible(true);
|
try {
|
||||||
Object nmsPlayer = getHandleMethod.invoke(player);
|
Method getHandleMethod = player.getClass().getDeclaredMethod("getHandle");
|
||||||
Class<?> entityClass = nmsPlayer.getClass().getSuperclass().getSuperclass().getSuperclass();
|
getHandleMethod.setAccessible(true);
|
||||||
Field locXField = entityClass.getDeclaredField("locX");
|
Object nmsPlayer = getHandleMethod.invoke(player);
|
||||||
locXField.setAccessible(true);
|
Class<?> entityClass = nmsPlayer.getClass().getSuperclass().getSuperclass().getSuperclass();
|
||||||
locXField.set(nmsPlayer, tploc.getX());
|
Field locXField = entityClass.getDeclaredField("locX");
|
||||||
Field locYField = entityClass.getDeclaredField("locY");
|
locXField.setAccessible(true);
|
||||||
locYField.setAccessible(true);
|
locXField.set(nmsPlayer, tploc.getX());
|
||||||
locYField.set(nmsPlayer, tploc.getY());
|
Field locYField = entityClass.getDeclaredField("locY");
|
||||||
Field locZField = entityClass.getDeclaredField("locZ");
|
locYField.setAccessible(true);
|
||||||
locZField.setAccessible(true);
|
locYField.set(nmsPlayer, tploc.getY());
|
||||||
locZField.set(nmsPlayer, tploc.getZ());
|
Field locZField = entityClass.getDeclaredField("locZ");
|
||||||
} catch (Exception e) {
|
locZField.setAccessible(true);
|
||||||
e.printStackTrace();
|
locZField.set(nmsPlayer, tploc.getZ());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sitblock.remove(sitblockbr.get(player.getName()));
|
sitblock.remove(sitblockbr.get(player.getName()));
|
||||||
|
@ -11,6 +11,7 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
import org.bukkit.event.vehicle.VehicleExitEvent;
|
import org.bukkit.event.vehicle.VehicleExitEvent;
|
||||||
|
|
||||||
public class TryUnsitEventListener implements Listener {
|
public class TryUnsitEventListener implements Listener {
|
||||||
@ -27,7 +28,17 @@ public class TryUnsitEventListener implements Listener {
|
|||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (plugin.sit.containsKey(player.getName()))
|
if (plugin.sit.containsKey(player.getName()))
|
||||||
{
|
{
|
||||||
plugin.unSitPlayer(player,true);
|
plugin.unSitPlayer(player, false, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority=EventPriority.LOWEST)
|
||||||
|
public void onPlayerTeleport(PlayerTeleportEvent event)
|
||||||
|
{
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (plugin.sit.containsKey(player.getName()))
|
||||||
|
{
|
||||||
|
plugin.unSitPlayer(player, false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +48,7 @@ public class TryUnsitEventListener implements Listener {
|
|||||||
Player player = event.getEntity();
|
Player player = event.getEntity();
|
||||||
if (plugin.sit.containsKey(player.getName()))
|
if (plugin.sit.containsKey(player.getName()))
|
||||||
{
|
{
|
||||||
plugin.unSitPlayer(player,true);
|
plugin.unSitPlayer(player, false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +70,7 @@ public class TryUnsitEventListener implements Listener {
|
|||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
queueUnsit.remove(player.getName());
|
queueUnsit.remove(player.getName());
|
||||||
plugin.unSitPlayer(player, false);
|
plugin.unSitPlayer(player, true, false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -74,7 +85,7 @@ public class TryUnsitEventListener implements Listener {
|
|||||||
if (plugin.sitblock.containsKey(b))
|
if (plugin.sitblock.containsKey(b))
|
||||||
{
|
{
|
||||||
Player player = Bukkit.getPlayerExact(plugin.sitblock.get(b));
|
Player player = Bukkit.getPlayerExact(plugin.sitblock.get(b));
|
||||||
plugin.unSitPlayer(player,false);
|
plugin.unSitPlayer(player, true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user