Force unsit player on teleport. Workaround spigot bug. Other
improvements.
This commit is contained in:
parent
94825e44a8
commit
7cc0d12ed6
@ -1,174 +1,174 @@
|
|||||||
package com.cnaude.chairs.core;
|
package com.cnaude.chairs.core;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import com.cnaude.chairs.api.APIInit;
|
import com.cnaude.chairs.api.APIInit;
|
||||||
import com.cnaude.chairs.commands.ChairsCommand;
|
import com.cnaude.chairs.commands.ChairsCommand;
|
||||||
import com.cnaude.chairs.commands.ChairsIgnoreList;
|
import com.cnaude.chairs.commands.ChairsIgnoreList;
|
||||||
import com.cnaude.chairs.listeners.NANLoginListener;
|
import com.cnaude.chairs.listeners.NANLoginListener;
|
||||||
import com.cnaude.chairs.listeners.TrySitEventListener;
|
import com.cnaude.chairs.listeners.TrySitEventListener;
|
||||||
import com.cnaude.chairs.listeners.TryUnsitEventListener;
|
import com.cnaude.chairs.listeners.TryUnsitEventListener;
|
||||||
import com.cnaude.chairs.sitaddons.ChairEffects;
|
import com.cnaude.chairs.sitaddons.ChairEffects;
|
||||||
import com.cnaude.chairs.sitaddons.CommandRestrict;
|
import com.cnaude.chairs.sitaddons.CommandRestrict;
|
||||||
import com.cnaude.chairs.vehiclearrow.NMSAccess;
|
import com.cnaude.chairs.vehiclearrow.NMSAccess;
|
||||||
|
|
||||||
public class Chairs extends JavaPlugin {
|
public class Chairs extends JavaPlugin {
|
||||||
|
|
||||||
public ChairEffects chairEffects;
|
public ChairEffects chairEffects;
|
||||||
public List<ChairBlock> allowedBlocks;
|
public List<ChairBlock> allowedBlocks;
|
||||||
public List<Material> validSigns;
|
public List<Material> validSigns;
|
||||||
public boolean autoRotate, signCheck, notifyplayer;
|
public boolean autoRotate, signCheck, notifyplayer;
|
||||||
public boolean ignoreIfBlockInHand;
|
public boolean ignoreIfBlockInHand;
|
||||||
public double distance;
|
public double distance;
|
||||||
public HashSet<String> disabledRegions = new HashSet<String>();
|
public HashSet<String> disabledRegions = new HashSet<String>();
|
||||||
public int maxChairWidth;
|
public int maxChairWidth;
|
||||||
public boolean sitHealEnabled;
|
public boolean sitHealEnabled;
|
||||||
public int sitMaxHealth;
|
public int sitMaxHealth;
|
||||||
public int sitHealthPerInterval;
|
public int sitHealthPerInterval;
|
||||||
public int sitHealInterval;
|
public int sitHealInterval;
|
||||||
public boolean sitPickupEnabled;
|
public boolean sitPickupEnabled;
|
||||||
public boolean sitDisableAllCommands = false;
|
public boolean sitDisableAllCommands = false;
|
||||||
public HashSet<String> sitDisabledCommands = new HashSet<String>();
|
public HashSet<String> sitDisabledCommands = new HashSet<String>();
|
||||||
private Logger log;
|
private Logger log;
|
||||||
public ChairsIgnoreList ignoreList;
|
public ChairsIgnoreList ignoreList;
|
||||||
public String msgSitting, msgStanding, msgOccupied, msgNoPerm, msgReloaded, msgDisabled, msgEnabled, msgCommandRestricted;
|
public String msgSitting, msgStanding, msgOccupied, msgNoPerm, msgReloaded, msgDisabled, msgEnabled, msgCommandRestricted;
|
||||||
|
|
||||||
|
|
||||||
private PlayerSitData psitdata;
|
private PlayerSitData psitdata;
|
||||||
public PlayerSitData getPlayerSitData() {
|
public PlayerSitData getPlayerSitData() {
|
||||||
return psitdata;
|
return psitdata;
|
||||||
}
|
}
|
||||||
private NMSAccess nmsaccess = new NMSAccess();
|
private NMSAccess nmsaccess = new NMSAccess();
|
||||||
protected NMSAccess getNMSAccess() {
|
protected NMSAccess getNMSAccess() {
|
||||||
return nmsaccess;
|
return nmsaccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
log = this.getLogger();
|
log = this.getLogger();
|
||||||
try {
|
try {
|
||||||
nmsaccess.setupChairsArrow();
|
nmsaccess.setupChairsArrow();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
getServer().getPluginManager().disablePlugin(this);
|
getServer().getPluginManager().disablePlugin(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
chairEffects = new ChairEffects(this);
|
chairEffects = new ChairEffects(this);
|
||||||
ignoreList = new ChairsIgnoreList();
|
ignoreList = new ChairsIgnoreList();
|
||||||
psitdata = new PlayerSitData(this);
|
psitdata = new PlayerSitData(this);
|
||||||
getConfig().options().copyDefaults(true);
|
getConfig().options().copyDefaults(true);
|
||||||
saveConfig();
|
saveConfig();
|
||||||
loadConfig();
|
loadConfig();
|
||||||
if (sitHealEnabled) {
|
if (sitHealEnabled) {
|
||||||
chairEffects.startHealing();
|
chairEffects.startHealing();
|
||||||
}
|
}
|
||||||
if (sitPickupEnabled) {
|
if (sitPickupEnabled) {
|
||||||
chairEffects.startPickup();
|
chairEffects.startPickup();
|
||||||
}
|
}
|
||||||
getServer().getPluginManager().registerEvents(new NANLoginListener(), this);
|
getServer().getPluginManager().registerEvents(new NANLoginListener(), this);
|
||||||
getServer().getPluginManager().registerEvents(new TrySitEventListener(this, ignoreList), this);
|
getServer().getPluginManager().registerEvents(new TrySitEventListener(this, ignoreList), this);
|
||||||
getServer().getPluginManager().registerEvents(new TryUnsitEventListener(this), this);
|
getServer().getPluginManager().registerEvents(new TryUnsitEventListener(this), this);
|
||||||
getServer().getPluginManager().registerEvents(new CommandRestrict(this), this);
|
getServer().getPluginManager().registerEvents(new CommandRestrict(this), this);
|
||||||
getCommand("chairs").setExecutor(new ChairsCommand(this, ignoreList));
|
getCommand("chairs").setExecutor(new ChairsCommand(this, ignoreList));
|
||||||
new APIInit().initAPI(getPlayerSitData());
|
new APIInit().initAPI(getPlayerSitData());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
if (psitdata != null) {
|
if (psitdata != null) {
|
||||||
for (Player player : Utils.getOnlinePlayers()) {
|
for (Player player : Utils.getOnlinePlayers()) {
|
||||||
if (psitdata.isSitting(player)) {
|
if (psitdata.isSitting(player)) {
|
||||||
psitdata.unsitPlayerNow(player);
|
psitdata.unsitPlayerForce(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (chairEffects != null) {
|
if (chairEffects != null) {
|
||||||
chairEffects.cancelHealing();
|
chairEffects.cancelHealing();
|
||||||
chairEffects.cancelPickup();
|
chairEffects.cancelPickup();
|
||||||
chairEffects = null;
|
chairEffects = null;
|
||||||
}
|
}
|
||||||
log = null;
|
log = null;
|
||||||
nmsaccess = null;
|
nmsaccess = null;
|
||||||
psitdata = null;
|
psitdata = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadConfig() {
|
public void loadConfig() {
|
||||||
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(this.getDataFolder(),"config.yml"));
|
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(this.getDataFolder(),"config.yml"));
|
||||||
autoRotate = config.getBoolean("auto-rotate");
|
autoRotate = config.getBoolean("auto-rotate");
|
||||||
signCheck = config.getBoolean("sign-check");
|
signCheck = config.getBoolean("sign-check");
|
||||||
distance = config.getDouble("distance");
|
distance = config.getDouble("distance");
|
||||||
maxChairWidth = config.getInt("max-chair-width");
|
maxChairWidth = config.getInt("max-chair-width");
|
||||||
notifyplayer = config.getBoolean("notify-player");
|
notifyplayer = config.getBoolean("notify-player");
|
||||||
ignoreIfBlockInHand = config.getBoolean("ignore-if-item-in-hand");
|
ignoreIfBlockInHand = config.getBoolean("ignore-if-item-in-hand");
|
||||||
|
|
||||||
disabledRegions = new HashSet<String>(config.getStringList("disabledWGRegions"));
|
disabledRegions = new HashSet<String>(config.getStringList("disabledWGRegions"));
|
||||||
|
|
||||||
sitHealEnabled = config.getBoolean("sit-effects.healing.enabled", false);
|
sitHealEnabled = config.getBoolean("sit-effects.healing.enabled", false);
|
||||||
sitHealInterval = config.getInt("sit-effects.healing.interval",20);
|
sitHealInterval = config.getInt("sit-effects.healing.interval",20);
|
||||||
sitMaxHealth = config.getInt("sit-effects.healing.max-percent",100);
|
sitMaxHealth = config.getInt("sit-effects.healing.max-percent",100);
|
||||||
sitHealthPerInterval = config.getInt("sit-effects.healing.amount",1);
|
sitHealthPerInterval = config.getInt("sit-effects.healing.amount",1);
|
||||||
|
|
||||||
sitPickupEnabled = config.getBoolean("sit-effects.itempickup.enabled", false);
|
sitPickupEnabled = config.getBoolean("sit-effects.itempickup.enabled", false);
|
||||||
|
|
||||||
sitDisableAllCommands = config.getBoolean("sit-restrictions.commands.all");
|
sitDisableAllCommands = config.getBoolean("sit-restrictions.commands.all");
|
||||||
sitDisabledCommands = new HashSet<String>(config.getStringList("sit-restrictions.commands.list"));
|
sitDisabledCommands = new HashSet<String>(config.getStringList("sit-restrictions.commands.list"));
|
||||||
|
|
||||||
msgSitting = ChatColor.translateAlternateColorCodes('&',config.getString("messages.sitting"));
|
msgSitting = ChatColor.translateAlternateColorCodes('&',config.getString("messages.sitting"));
|
||||||
msgStanding = ChatColor.translateAlternateColorCodes('&',config.getString("messages.standing"));
|
msgStanding = ChatColor.translateAlternateColorCodes('&',config.getString("messages.standing"));
|
||||||
msgOccupied = ChatColor.translateAlternateColorCodes('&',config.getString("messages.occupied"));
|
msgOccupied = ChatColor.translateAlternateColorCodes('&',config.getString("messages.occupied"));
|
||||||
msgNoPerm = ChatColor.translateAlternateColorCodes('&',config.getString("messages.no-permission"));
|
msgNoPerm = ChatColor.translateAlternateColorCodes('&',config.getString("messages.no-permission"));
|
||||||
msgEnabled = ChatColor.translateAlternateColorCodes('&',config.getString("messages.enabled"));
|
msgEnabled = ChatColor.translateAlternateColorCodes('&',config.getString("messages.enabled"));
|
||||||
msgDisabled = ChatColor.translateAlternateColorCodes('&',config.getString("messages.disabled"));
|
msgDisabled = ChatColor.translateAlternateColorCodes('&',config.getString("messages.disabled"));
|
||||||
msgReloaded = ChatColor.translateAlternateColorCodes('&',config.getString("messages.reloaded"));
|
msgReloaded = ChatColor.translateAlternateColorCodes('&',config.getString("messages.reloaded"));
|
||||||
msgCommandRestricted = ChatColor.translateAlternateColorCodes('&',config.getString("messages.command-restricted"));
|
msgCommandRestricted = ChatColor.translateAlternateColorCodes('&',config.getString("messages.command-restricted"));
|
||||||
|
|
||||||
allowedBlocks = new ArrayList<ChairBlock>();
|
allowedBlocks = new ArrayList<ChairBlock>();
|
||||||
for (String s : config.getStringList("sit-blocks")) {
|
for (String s : config.getStringList("sit-blocks")) {
|
||||||
String type;
|
String type;
|
||||||
double sh = 0.7;
|
double sh = 0.7;
|
||||||
String tmp[] = s.split("[:]");
|
String tmp[] = s.split("[:]");
|
||||||
type = tmp[0];
|
type = tmp[0];
|
||||||
if (tmp.length == 2) {
|
if (tmp.length == 2) {
|
||||||
sh = Double.parseDouble(tmp[1]);
|
sh = Double.parseDouble(tmp[1]);
|
||||||
}
|
}
|
||||||
Material mat = Material.matchMaterial(type);
|
Material mat = Material.matchMaterial(type);
|
||||||
if (mat != null) {
|
if (mat != null) {
|
||||||
logInfo("Allowed block: " + mat.toString() + " => " + sh);
|
logInfo("Allowed block: " + mat.toString() + " => " + sh);
|
||||||
allowedBlocks.add(new ChairBlock(mat,sh));
|
allowedBlocks.add(new ChairBlock(mat,sh));
|
||||||
} else {
|
} else {
|
||||||
logError("Invalid block: " + type);
|
logError("Invalid block: " + type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
validSigns = new ArrayList<Material>();
|
validSigns = new ArrayList<Material>();
|
||||||
for (String type : config.getStringList("valid-signs")) {
|
for (String type : config.getStringList("valid-signs")) {
|
||||||
try {
|
try {
|
||||||
validSigns.add(Material.matchMaterial(type));
|
validSigns.add(Material.matchMaterial(type));
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
logError(e.getMessage());
|
logError(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void logInfo(String _message) {
|
public void logInfo(String _message) {
|
||||||
log.log(Level.INFO, _message);
|
log.log(Level.INFO, _message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void logError(String _message) {
|
public void logError(String _message) {
|
||||||
log.log(Level.SEVERE, _message);
|
log.log(Level.SEVERE, _message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,177 +1,128 @@
|
|||||||
package com.cnaude.chairs.core;
|
package com.cnaude.chairs.core;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.cnaude.chairs.api.PlayerChairSitEvent;
|
import com.cnaude.chairs.api.PlayerChairSitEvent;
|
||||||
import com.cnaude.chairs.api.PlayerChairUnsitEvent;
|
import com.cnaude.chairs.api.PlayerChairUnsitEvent;
|
||||||
|
|
||||||
public class PlayerSitData {
|
public class PlayerSitData {
|
||||||
|
|
||||||
private Chairs plugin;
|
private Chairs plugin;
|
||||||
public PlayerSitData(Chairs plugin) {
|
public PlayerSitData(Chairs plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
private HashMap<Player, SitData> sit = new HashMap<Player, SitData>();
|
private HashMap<Player, SitData> sit = new HashMap<Player, SitData>();
|
||||||
private HashMap<Block, Player> sitblock = new HashMap<Block, Player>();
|
private HashMap<Block, Player> sitblock = new HashMap<Block, Player>();
|
||||||
|
|
||||||
public boolean isSitting(Player player) {
|
public boolean isSitting(Player player) {
|
||||||
return sit.containsKey(player) && sit.get(player).sitting;
|
return sit.containsKey(player) && sit.get(player).sitting;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBlockOccupied(Block block) {
|
public boolean isBlockOccupied(Block block) {
|
||||||
return sitblock.containsKey(block);
|
return sitblock.containsKey(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player getPlayerOnChair(Block chair) {
|
public Player getPlayerOnChair(Block chair) {
|
||||||
return sitblock.get(chair);
|
return sitblock.get(chair);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean sitPlayer(final Player player, Block blocktooccupy, Location sitlocation) {
|
public boolean sitPlayer(final Player player, Block blocktooccupy, Location sitlocation) {
|
||||||
PlayerChairSitEvent playersitevent = new PlayerChairSitEvent(player, sitlocation.clone());
|
PlayerChairSitEvent playersitevent = new PlayerChairSitEvent(player, sitlocation.clone());
|
||||||
Bukkit.getPluginManager().callEvent(playersitevent);
|
Bukkit.getPluginManager().callEvent(playersitevent);
|
||||||
if (playersitevent.isCancelled()) {
|
if (playersitevent.isCancelled()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
sitlocation = playersitevent.getSitLocation().clone();
|
sitlocation = playersitevent.getSitLocation().clone();
|
||||||
if (plugin.notifyplayer) {
|
if (plugin.notifyplayer) {
|
||||||
player.sendMessage(plugin.msgSitting);
|
player.sendMessage(plugin.msgSitting);
|
||||||
}
|
}
|
||||||
SitData sitdata = new SitData();
|
SitData sitdata = new SitData();
|
||||||
Location arrowloc = sitlocation.getBlock().getLocation().add(0.5, 0 , 0.5);
|
Location arrowloc = sitlocation.getBlock().getLocation().add(0.5, 0 , 0.5);
|
||||||
Entity arrow = plugin.getNMSAccess().spawnArrow(arrowloc);
|
Entity arrow = plugin.getNMSAccess().spawnArrow(arrowloc);
|
||||||
sitdata.arrow = arrow;
|
sitdata.arrow = arrow;
|
||||||
sitdata.teleportloc = player.getLocation();
|
sitdata.teleportloc = player.getLocation();
|
||||||
int task = Bukkit.getScheduler().scheduleSyncRepeatingTask(
|
int task = Bukkit.getScheduler().scheduleSyncRepeatingTask(
|
||||||
plugin,
|
plugin,
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
reSitPlayer(player);
|
reSitPlayer(player);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
1000, 1000
|
1000, 1000
|
||||||
);
|
);
|
||||||
sitdata.resittask = task;
|
sitdata.resittask = task;
|
||||||
player.teleport(sitlocation);
|
player.teleport(sitlocation);
|
||||||
arrow.setPassenger(player);
|
arrow.setPassenger(player);
|
||||||
sitdata.sitting = true;
|
sitdata.sitting = true;
|
||||||
sit.put(player, sitdata);
|
sit.put(player, sitdata);
|
||||||
sitblock.put(blocktooccupy, player);
|
sitblock.put(blocktooccupy, player);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reSitPlayer(final Player player) {
|
public void reSitPlayer(final Player player) {
|
||||||
SitData sitdata = sit.get(player);
|
SitData sitdata = sit.get(player);
|
||||||
sitdata.sitting = false;
|
sitdata.sitting = false;
|
||||||
final Entity prevarrow = sit.get(player).arrow;
|
final Entity prevarrow = sit.get(player).arrow;
|
||||||
player.eject();
|
Entity arrow = plugin.getNMSAccess().spawnArrow(prevarrow.getLocation());
|
||||||
Entity arrow = plugin.getNMSAccess().spawnArrow(prevarrow.getLocation());
|
arrow.setPassenger(player);
|
||||||
arrow.setPassenger(player);
|
sitdata.arrow = arrow;
|
||||||
sitdata.arrow = arrow;
|
sitdata.sitting = true;
|
||||||
sitdata.sitting = true;
|
Bukkit.getScheduler().scheduleSyncDelayedTask(
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(
|
plugin,
|
||||||
plugin,
|
new Runnable() {
|
||||||
new Runnable() {
|
@Override
|
||||||
@Override
|
public void run() {
|
||||||
public void run() {
|
prevarrow.remove();
|
||||||
prevarrow.remove();
|
}
|
||||||
}
|
},
|
||||||
},
|
100
|
||||||
100
|
);
|
||||||
);
|
}
|
||||||
}
|
|
||||||
|
public boolean unsitPlayer(Player player) {
|
||||||
public boolean unsitPlayerNormal(Player player) {
|
return unsitPlayer(player, true);
|
||||||
UnsitParams params = new UnsitParams(false, true, false);
|
}
|
||||||
return unsitPlayer(player, true, params);
|
|
||||||
}
|
public void unsitPlayerForce(Player player) {
|
||||||
|
unsitPlayer(player, false);
|
||||||
public void unsitPlayerForce(Player player) {
|
}
|
||||||
UnsitParams params = new UnsitParams(true, true, false);
|
|
||||||
unsitPlayer(player, false, params);
|
private boolean unsitPlayer(final Player player, boolean canCancel) {
|
||||||
}
|
SitData sitdata = sit.get(player);
|
||||||
|
final PlayerChairUnsitEvent playerunsitevent = new PlayerChairUnsitEvent(player, sitdata.teleportloc.clone(), canCancel);
|
||||||
public void unsitPlayerNow(Player player) {
|
Bukkit.getPluginManager().callEvent(playerunsitevent);
|
||||||
UnsitParams params = new UnsitParams(true, false, true);
|
if (playerunsitevent.isCancelled() && playerunsitevent.canBeCancelled()) {
|
||||||
unsitPlayer(player, false, params);
|
return false;
|
||||||
}
|
}
|
||||||
|
sitdata.sitting = false;
|
||||||
private boolean unsitPlayer(final Player player, boolean canCancel, UnsitParams params) {
|
player.leaveVehicle();
|
||||||
SitData sitdata = sit.get(player);
|
sitdata.arrow.remove();
|
||||||
final PlayerChairUnsitEvent playerunsitevent = new PlayerChairUnsitEvent(player, sitdata.teleportloc.clone(), canCancel);
|
player.teleport(playerunsitevent.getTeleportLocation().clone());
|
||||||
Bukkit.getPluginManager().callEvent(playerunsitevent);
|
player.setSneaking(false);
|
||||||
if (playerunsitevent.isCancelled() && playerunsitevent.canBeCancelled()) {
|
sitblock.values().remove(player);
|
||||||
return false;
|
Bukkit.getScheduler().cancelTask(sitdata.resittask);
|
||||||
}
|
sit.remove(player);
|
||||||
sitdata.sitting = false;
|
if (plugin.notifyplayer) {
|
||||||
if (params.eject()) {
|
player.sendMessage(plugin.msgStanding);
|
||||||
player.eject();
|
}
|
||||||
}
|
return true;
|
||||||
sitdata.arrow.remove();
|
}
|
||||||
if (params.restorePostion()) {
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(
|
private class SitData {
|
||||||
plugin,
|
|
||||||
new Runnable() {
|
private boolean sitting;
|
||||||
@Override
|
private Entity arrow;
|
||||||
public void run() {
|
private Location teleportloc;
|
||||||
player.teleport(playerunsitevent.getTeleportLocation().clone());
|
private int resittask;
|
||||||
player.setSneaking(false);
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
1
|
}
|
||||||
);
|
|
||||||
} else if (params.correctLeavePosition()) {
|
|
||||||
player.teleport(playerunsitevent.getTeleportLocation());
|
|
||||||
}
|
|
||||||
sitblock.values().remove(player);
|
|
||||||
Bukkit.getScheduler().cancelTask(sitdata.resittask);
|
|
||||||
sit.remove(player);
|
|
||||||
if (plugin.notifyplayer) {
|
|
||||||
player.sendMessage(plugin.msgStanding);
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
private Entity arrow;
|
|
||||||
private Location teleportloc;
|
|
||||||
private int resittask;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -1,70 +1,69 @@
|
|||||||
package com.cnaude.chairs.listeners;
|
package com.cnaude.chairs.listeners;
|
||||||
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
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.player.PlayerTeleportEvent;
|
||||||
import org.bukkit.event.vehicle.VehicleExitEvent;
|
import org.bukkit.event.vehicle.VehicleExitEvent;
|
||||||
|
|
||||||
import com.cnaude.chairs.core.Chairs;
|
import com.cnaude.chairs.core.Chairs;
|
||||||
|
|
||||||
public class TryUnsitEventListener implements Listener {
|
public class TryUnsitEventListener implements Listener {
|
||||||
|
|
||||||
public Chairs plugin;
|
public Chairs plugin;
|
||||||
|
|
||||||
public TryUnsitEventListener(Chairs plugin) {
|
public TryUnsitEventListener(Chairs plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
//spigot...
|
@EventHandler(priority=EventPriority.LOWEST)
|
||||||
@EventHandler(priority=EventPriority.LOWEST)
|
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
final Player player = event.getPlayer();
|
||||||
final Player player = event.getPlayer();
|
if (plugin.getPlayerSitData().isSitting(player)) {
|
||||||
if (plugin.getPlayerSitData().isSitting(player)) {
|
plugin.getPlayerSitData().unsitPlayerForce(player);
|
||||||
event.setCancelled(true);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@EventHandler(priority=EventPriority.LOWEST)
|
||||||
@EventHandler(priority=EventPriority.LOWEST)
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
Player player = event.getPlayer();
|
||||||
Player player = event.getPlayer();
|
if (plugin.getPlayerSitData().isSitting(player)) {
|
||||||
if (plugin.getPlayerSitData().isSitting(player)) {
|
plugin.getPlayerSitData().unsitPlayerForce(player);
|
||||||
plugin.getPlayerSitData().unsitPlayerNow(player);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@EventHandler(priority=EventPriority.LOWEST)
|
||||||
@EventHandler(priority=EventPriority.LOWEST)
|
public void onPlayerDeath(PlayerDeathEvent event) {
|
||||||
public void onPlayerDeath(PlayerDeathEvent event) {
|
Player player = event.getEntity();
|
||||||
Player player = event.getEntity();
|
if (plugin.getPlayerSitData().isSitting(player)) {
|
||||||
if (plugin.getPlayerSitData().isSitting(player)) {
|
plugin.getPlayerSitData().unsitPlayerForce(player);
|
||||||
plugin.getPlayerSitData().unsitPlayerNow(player);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@EventHandler(priority=EventPriority.LOWEST)
|
||||||
@EventHandler(priority=EventPriority.LOWEST)
|
public void onExitVehicle(VehicleExitEvent e) {
|
||||||
public void onExitVehicle(VehicleExitEvent e) {
|
if (e.getVehicle().getPassenger() instanceof Player) {
|
||||||
if (e.getVehicle().getPassenger() instanceof Player) {
|
final Player player = (Player) e.getVehicle().getPassenger();
|
||||||
final Player player = (Player) e.getVehicle().getPassenger();
|
if (plugin.getPlayerSitData().isSitting(player)) {
|
||||||
if (plugin.getPlayerSitData().isSitting(player)) {
|
if (!plugin.getPlayerSitData().unsitPlayer(player)) {
|
||||||
if (!plugin.getPlayerSitData().unsitPlayerNormal(player)) {
|
e.setCancelled(true);
|
||||||
e.setCancelled(true);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true)
|
||||||
@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true)
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
Block b = event.getBlock();
|
||||||
Block b = event.getBlock();
|
if (plugin.getPlayerSitData().isBlockOccupied(b)) {
|
||||||
if (plugin.getPlayerSitData().isBlockOccupied(b)) {
|
Player player = plugin.getPlayerSitData().getPlayerOnChair(b);
|
||||||
Player player = plugin.getPlayerSitData().getPlayerOnChair(b);
|
plugin.getPlayerSitData().unsitPlayerForce(player);
|
||||||
plugin.getPlayerSitData().unsitPlayerForce(player);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user