Force unsit player on teleport. Workaround spigot bug. Other

improvements.
This commit is contained in:
Shevchik 2015-01-15 12:51:13 +04:00
parent 94825e44a8
commit 7cc0d12ed6
3 changed files with 371 additions and 421 deletions

View File

@ -90,7 +90,7 @@ public class Chairs extends JavaPlugin {
if (psitdata != null) {
for (Player player : Utils.getOnlinePlayers()) {
if (psitdata.isSitting(player)) {
psitdata.unsitPlayerNow(player);
psitdata.unsitPlayerForce(player);
}
}
}

View File

@ -71,7 +71,6 @@ public class PlayerSitData {
SitData sitdata = sit.get(player);
sitdata.sitting = false;
final Entity prevarrow = sit.get(player).arrow;
player.eject();
Entity arrow = plugin.getNMSAccess().spawnArrow(prevarrow.getLocation());
arrow.setPassenger(player);
sitdata.arrow = arrow;
@ -88,22 +87,15 @@ public class PlayerSitData {
);
}
public boolean unsitPlayerNormal(Player player) {
UnsitParams params = new UnsitParams(false, true, false);
return unsitPlayer(player, true, params);
public boolean unsitPlayer(Player player) {
return unsitPlayer(player, true);
}
public void unsitPlayerForce(Player player) {
UnsitParams params = new UnsitParams(true, true, false);
unsitPlayer(player, false, params);
unsitPlayer(player, false);
}
public void unsitPlayerNow(Player player) {
UnsitParams params = new UnsitParams(true, false, true);
unsitPlayer(player, false, params);
}
private boolean unsitPlayer(final Player player, boolean canCancel, UnsitParams params) {
private boolean unsitPlayer(final Player player, boolean canCancel) {
SitData sitdata = sit.get(player);
final PlayerChairUnsitEvent playerunsitevent = new PlayerChairUnsitEvent(player, sitdata.teleportloc.clone(), canCancel);
Bukkit.getPluginManager().callEvent(playerunsitevent);
@ -111,25 +103,10 @@ public class PlayerSitData {
return false;
}
sitdata.sitting = false;
if (params.eject()) {
player.eject();
}
player.leaveVehicle();
sitdata.arrow.remove();
if (params.restorePostion()) {
Bukkit.getScheduler().scheduleSyncDelayedTask(
plugin,
new Runnable() {
@Override
public void run() {
player.teleport(playerunsitevent.getTeleportLocation().clone());
player.setSneaking(false);
}
},
1
);
} else if (params.correctLeavePosition()) {
player.teleport(playerunsitevent.getTeleportLocation());
}
player.teleport(playerunsitevent.getTeleportLocation().clone());
player.setSneaking(false);
sitblock.values().remove(player);
Bukkit.getScheduler().cancelTask(sitdata.resittask);
sit.remove(player);
@ -139,32 +116,6 @@ public class PlayerSitData {
return true;
}
private class UnsitParams {
private boolean eject;
private boolean restoreposition;
private boolean correctleaveposition;
public UnsitParams(boolean eject, boolean restoreposition, boolean correctleaveposition) {
this.eject = eject;
this.restoreposition = restoreposition;
this.correctleaveposition = correctleaveposition;
}
public boolean eject() {
return eject;
}
public boolean restorePostion() {
return restoreposition;
}
public boolean correctLeavePosition() {
return correctleaveposition;
}
}
private class SitData {
private boolean sitting;

View File

@ -21,12 +21,11 @@ public class TryUnsitEventListener implements Listener {
this.plugin = plugin;
}
//spigot...
@EventHandler(priority=EventPriority.LOWEST)
public void onPlayerTeleport(PlayerTeleportEvent event) {
final Player player = event.getPlayer();
if (plugin.getPlayerSitData().isSitting(player)) {
event.setCancelled(true);
plugin.getPlayerSitData().unsitPlayerForce(player);
}
}
@ -34,7 +33,7 @@ public class TryUnsitEventListener implements Listener {
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
if (plugin.getPlayerSitData().isSitting(player)) {
plugin.getPlayerSitData().unsitPlayerNow(player);
plugin.getPlayerSitData().unsitPlayerForce(player);
}
}
@ -42,7 +41,7 @@ public class TryUnsitEventListener implements Listener {
public void onPlayerDeath(PlayerDeathEvent event) {
Player player = event.getEntity();
if (plugin.getPlayerSitData().isSitting(player)) {
plugin.getPlayerSitData().unsitPlayerNow(player);
plugin.getPlayerSitData().unsitPlayerForce(player);
}
}
@ -51,7 +50,7 @@ public class TryUnsitEventListener implements Listener {
if (e.getVehicle().getPassenger() instanceof Player) {
final Player player = (Player) e.getVehicle().getPassenger();
if (plugin.getPlayerSitData().isSitting(player)) {
if (!plugin.getPlayerSitData().unsitPlayerNormal(player)) {
if (!plugin.getPlayerSitData().unsitPlayer(player)) {
e.setCancelled(true);
}
}