Clean up and reformat source

This commit is contained in:
Shevchik 2014-03-05 23:38:52 +04:00
parent ff38ead562
commit 9d231ca8b8
13 changed files with 142 additions and 165 deletions

View File

@ -29,7 +29,7 @@ public class ChairsCommand implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length == 0) { if (args.length == 0) {
return false; return false;
} }
if (args[0].equalsIgnoreCase("reload")) { if (args[0].equalsIgnoreCase("reload")) {
if (sender.hasPermission("chairs.reload") || !(sender instanceof Player)) { if (sender.hasPermission("chairs.reload") || !(sender instanceof Player)) {
plugin.loadConfig(); plugin.loadConfig();
@ -81,5 +81,5 @@ public class ChairsCommand implements CommandExecutor {
} }
return true; return true;
} }
} }

View File

@ -4,7 +4,12 @@
*/ */
package com.cnaude.chairs.commands; package com.cnaude.chairs.commands;
import java.io.*; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import com.cnaude.chairs.core.Chairs; import com.cnaude.chairs.core.Chairs;
@ -17,35 +22,35 @@ import com.cnaude.chairs.core.Chairs;
public class ChairsIgnoreList implements Serializable{ public class ChairsIgnoreList implements Serializable{
private static ArrayList<String> ignoreList = new ArrayList<String>(); private static ArrayList<String> ignoreList = new ArrayList<String>();
private static final String IGNORE_FILE = "plugins/Chairs/ignores.ser"; private static final String IGNORE_FILE = "plugins/Chairs/ignores.ser";
private Chairs plugin; private Chairs plugin;
public ChairsIgnoreList(Chairs plugin) public ChairsIgnoreList(Chairs plugin)
{ {
this.plugin = plugin; this.plugin = plugin;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void load() { public void load() {
File file = new File(IGNORE_FILE); File file = new File(IGNORE_FILE);
if (!file.exists()) { if (!file.exists()) {
plugin.logInfo("Ignore file '"+file.getAbsolutePath()+"' does not exist."); plugin.logInfo("Ignore file '"+file.getAbsolutePath()+"' does not exist.");
return; return;
} }
try { try {
FileInputStream f_in = new FileInputStream(file); FileInputStream f_in = new FileInputStream(file);
ObjectInputStream obj_in = new ObjectInputStream (f_in); ObjectInputStream obj_in = new ObjectInputStream (f_in);
ignoreList = (ArrayList<String>) obj_in.readObject(); ignoreList = (ArrayList<String>) obj_in.readObject();
obj_in.close(); obj_in.close();
plugin.logInfo("Loaded ignore list. (Count = "+ignoreList.size()+")"); plugin.logInfo("Loaded ignore list. (Count = "+ignoreList.size()+")");
} }
catch(Exception e) { catch(Exception e) {
plugin.logError(e.getMessage()); plugin.logError(e.getMessage());
} }
} }
public void save() { public void save() {
try { try {
File file = new File(IGNORE_FILE); File file = new File(IGNORE_FILE);
FileOutputStream f_out = new FileOutputStream (file); FileOutputStream f_out = new FileOutputStream (file);
ObjectOutputStream obj_out = new ObjectOutputStream (f_out); ObjectOutputStream obj_out = new ObjectOutputStream (f_out);
obj_out.writeObject (ignoreList); obj_out.writeObject (ignoreList);
@ -56,7 +61,7 @@ public class ChairsIgnoreList implements Serializable{
plugin.logError(e.getMessage()); plugin.logError(e.getMessage());
} }
} }
public void addPlayer(String s) { public void addPlayer(String s) {
if (ignoreList.contains(s)) { if (ignoreList.contains(s)) {
return; return;
@ -64,12 +69,12 @@ public class ChairsIgnoreList implements Serializable{
//Chairs.get().logInfo("Adding " + s + " to ignore list."); //Chairs.get().logInfo("Adding " + s + " to ignore list.");
ignoreList.add(s); ignoreList.add(s);
} }
public void removePlayer(String s) { public void removePlayer(String s) {
//Chairs.get().logInfo("Removing " + s + " from ignore list."); //Chairs.get().logInfo("Removing " + s + " from ignore list.");
ignoreList.remove(s); ignoreList.remove(s);
} }
public boolean isIgnored(String s) { public boolean isIgnored(String s) {
if (ignoreList.contains(s)) { if (ignoreList.contains(s)) {
return true; return true;

View File

@ -13,16 +13,16 @@ import org.bukkit.Material;
public class ChairBlock { public class ChairBlock {
private Material mat; private Material mat;
private double sitHeight; private double sitHeight;
public ChairBlock(Material m, double s) { public ChairBlock(Material m, double s) {
mat = m; mat = m;
sitHeight = s; sitHeight = s;
} }
public Material getMat() { public Material getMat() {
return mat; return mat;
} }
public double getSitHeight() { public double getSitHeight() {
return sitHeight; return sitHeight;
} }

View File

@ -44,16 +44,16 @@ public class Chairs extends JavaPlugin {
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 Class<?> vehiclearrowclass; private Class<?> vehiclearrowclass;
protected Class<?> getVehicleArrowClass() protected Class<?> getVehicleArrowClass()
{ {
@ -61,10 +61,10 @@ public class Chairs extends JavaPlugin {
} }
GetVehicleArrowClass genvehiclearrow = new GetVehicleArrowClass(); GetVehicleArrowClass genvehiclearrow = new GetVehicleArrowClass();
@Override @Override
public void onEnable() { public void onEnable() {
log = this.getLogger(); log = this.getLogger();
//load vehiclearrowclass //load vehiclearrowclass
try { try {
World world = getServer().getWorlds().get(0); World world = getServer().getWorlds().get(0);
@ -104,7 +104,7 @@ public class Chairs extends JavaPlugin {
@Override @Override
public void onDisable() { public void onDisable() {
for (Player player : getServer().getOnlinePlayers()) { for (Player player : getServer().getOnlinePlayers()) {
if (psitdata.isSitting(player)) { if (psitdata.isSitting(player)) {
psitdata.unSitPlayer(player, false, true); psitdata.unSitPlayer(player, false, true);
} }
@ -120,7 +120,7 @@ public class Chairs extends JavaPlugin {
vehiclearrowclass = null; vehiclearrowclass = 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");
@ -129,19 +129,19 @@ public class Chairs extends JavaPlugin {
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"));
@ -156,21 +156,21 @@ public class Chairs extends JavaPlugin {
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));
} }
@ -178,8 +178,8 @@ public class Chairs extends JavaPlugin {
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);
} }
@ -187,5 +187,5 @@ public class Chairs extends JavaPlugin {
public void logError(String _message) { public void logError(String _message) {
log.log(Level.SEVERE, _message); log.log(Level.SEVERE, _message);
} }
} }

View File

@ -19,40 +19,32 @@ public class PlayerSitData {
public PlayerSitData(Chairs plugin) { public PlayerSitData(Chairs plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
private HashMap<String, Entity> sit = new HashMap<String, Entity>(); private HashMap<String, Entity> sit = new HashMap<String, Entity>();
private HashMap<Block, String> sitblock = new HashMap<Block, String>(); private HashMap<Block, String> sitblock = new HashMap<Block, String>();
private HashMap<String, Block> sitblockbr = new HashMap<String, Block>(); private HashMap<String, Block> sitblockbr = new HashMap<String, Block>();
private HashMap<String, Location> sitstopteleportloc = new HashMap<String, Location>(); private HashMap<String, Location> sitstopteleportloc = new HashMap<String, Location>();
private HashMap<String, Integer> sittask = new HashMap<String, Integer>(); private HashMap<String, Integer> sittask = new HashMap<String, Integer>();
public boolean isSitting(Player player) public boolean isSitting(Player player) {
{
return sit.containsKey(player.getName()); return sit.containsKey(player.getName());
} }
public boolean isAroowOccupied(Entity entity) public boolean isAroowOccupied(Entity entity) {
{ for (Entity usedentity : sit.values()) {
for (Entity usedentity : sit.values()) if (usedentity.getEntityId() == entity.getEntityId()) {
{
if (usedentity.getEntityId() == entity.getEntityId())
{
return true; return true;
} }
} }
return false; return false;
} }
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 Bukkit.getPlayerExact(sitblock.get(chair)); return Bukkit.getPlayerExact(sitblock.get(chair));
} }
public void sitPlayer(Player player, Location sitlocation) public void sitPlayer(Player player, Location sitlocation) {
{
try { try {
if (plugin.notifyplayer) if (plugin.notifyplayer) {
{
player.sendMessage(plugin.msgSitting); player.sendMessage(plugin.msgSitting);
} }
Block block = sitlocation.getBlock(); Block block = sitlocation.getBlock();
@ -68,15 +60,13 @@ public class PlayerSitData {
e.printStackTrace(); e.printStackTrace();
} }
} }
public void startReSitTask(final Player player) public void startReSitTask(final Player player) {
{ int task =
int task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() @Override
{ public void run() {
public void run()
{
reSitPlayer(player); reSitPlayer(player);
} }
},1000,1000); },1000,1000);
sittask.put(player.getName(), task); sittask.put(player.getName(), task);
} }
@ -90,10 +80,9 @@ public class PlayerSitData {
Location arrowloc = block.getLocation().add(0.5, 0 , 0.5); Location arrowloc = block.getLocation().add(0.5, 0 , 0.5);
Entity arrow = sitPlayerOnArrow(player, arrowloc); Entity arrow = sitPlayerOnArrow(player, arrowloc);
sit.put(player.getName(), arrow); sit.put(player.getName(), arrow);
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
{ @Override
public void run() public void run() {
{
prevarrow.remove(); prevarrow.remove();
} }
},100); },100);
@ -101,8 +90,7 @@ public class PlayerSitData {
e.printStackTrace(); e.printStackTrace();
} }
} }
private Entity sitPlayerOnArrow(Player player, Location arrowloc) throws NoSuchMethodException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, InstantiationException, InvocationTargetException private Entity sitPlayerOnArrow(Player player, Location arrowloc) throws NoSuchMethodException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, InstantiationException, InvocationTargetException {
{
Entity arrow = player.getWorld().spawnArrow(arrowloc, new Vector(0, 0 ,0), 0, 0); Entity arrow = player.getWorld().spawnArrow(arrowloc, new Vector(0, 0 ,0), 0, 0);
Method getHandleMethod = arrow.getClass().getDeclaredMethod("getHandle"); Method getHandleMethod = arrow.getClass().getDeclaredMethod("getHandle");
getHandleMethod.setAccessible(true); getHandleMethod.setAccessible(true);
@ -116,25 +104,23 @@ public class PlayerSitData {
arrow.setPassenger(player); arrow.setPassenger(player);
return arrow; return arrow;
} }
public void unSitPlayer(final Player player, boolean restoreposition, boolean correctleaveposition) public void unSitPlayer(final Player player, boolean restoreposition, boolean correctleaveposition) {
{
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 (restoreposition) if (restoreposition) {
{ Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable()
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable()
{ {
public void run() @Override
public void run()
{ {
player.teleport(tploc); player.teleport(tploc);
player.setSneaking(false); player.setSneaking(false);
} }
},1); },1);
} else if (correctleaveposition) } else if (correctleaveposition) {
{
player.teleport(tploc); player.teleport(tploc);
} }
sitblock.remove(sitblockbr.get(player.getName())); sitblock.remove(sitblockbr.get(player.getName()));
@ -142,10 +128,9 @@ public class PlayerSitData {
sitstopteleportloc.remove(player.getName()); sitstopteleportloc.remove(player.getName());
Bukkit.getScheduler().cancelTask(sittask.get(player.getName())); Bukkit.getScheduler().cancelTask(sittask.get(player.getName()));
sittask.remove(player.getName()); sittask.remove(player.getName());
if (plugin.notifyplayer) if (plugin.notifyplayer) {
{
player.sendMessage(plugin.msgStanding); player.sendMessage(plugin.msgStanding);
} }
} }
} }

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemFrame; import org.bukkit.entity.ItemFrame;
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.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
@ -29,9 +30,8 @@ public class TrySitEventListener implements Listener {
this.plugin = plugin; this.plugin = plugin;
this.ignoreList = ignoreList; this.ignoreList = ignoreList;
} }
@EventHandler @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
@ -44,51 +44,50 @@ public class TrySitEventListener implements Listener {
} }
} }
private boolean sitAllowed(Player player, Block block) private boolean sitAllowed(Player player, Block block) {
{
// Check for permissions // Check for permissions
if (!player.hasPermission("chairs.sit")) { if (!player.hasPermission("chairs.sit")) {
return false; return false;
} }
// Check for already sitting // Check for already sitting
if (isSitting(player)) { if (isSitting(player)) {
return false; return false;
} }
// Check for item in hand // Check for item in hand
if (plugin.ignoreIfBlockInHand && player.getItemInHand().getType() != Material.AIR) { if (plugin.ignoreIfBlockInHand && player.getItemInHand().getType() != Material.AIR) {
return false; return false;
} }
// Check for sneaking // Check for sneaking
if (player.isSneaking()) { if (player.isSneaking()) {
return false; return false;
} }
// Check for /chairs off // Check for /chairs off
if (ignoreList.isIgnored(player.getName())) { if (ignoreList.isIgnored(player.getName())) {
return false; return false;
} }
// Sit occupied check // Sit occupied check
if (plugin.getPlayerSitData().isBlockOccupied(block)) { if (plugin.getPlayerSitData().isBlockOccupied(block)) {
player.sendMessage(plugin.msgOccupied.replace("%PLAYER%", plugin.getPlayerSitData().getPlayerOnChair(block).getName())); player.sendMessage(plugin.msgOccupied.replace("%PLAYER%", plugin.getPlayerSitData().getPlayerOnChair(block).getName()));
return false; return false;
} }
// Region allowance check // Region allowance check
if (!WGHook.isAllowedInRegion(plugin.disabledRegions, block.getLocation())) { if (!WGHook.isAllowedInRegion(plugin.disabledRegions, block.getLocation())) {
return false; return false;
} }
Stairs stairs = null; Stairs stairs = null;
Step step = null; Step step = null;
WoodenStep wStep = null; WoodenStep wStep = null;
// Check for block is chair // Check for block is chair
if ( if (
isValidChair(block) || isValidChair(block) ||
( (
!player.hasPermission("chairs.sit.antiopcheck") && !player.hasPermission("chairs.sit.antiopcheck") &&
player.hasPermission("chairs.sit." + block.getType().toString()) player.hasPermission("chairs.sit." + block.getType().toString())
@ -131,7 +130,7 @@ public class TrySitEventListener implements Listener {
if (wStep != null && wStep.isInverted()) { if (wStep != null && wStep.isInverted()) {
return false; return false;
} }
// Check for signs (only for stairs) // Check for signs (only for stairs)
if (plugin.signCheck && stairs != null) { if (plugin.signCheck && stairs != null) {
boolean sign1 = false; boolean sign1 = false;
@ -167,26 +166,26 @@ public class TrySitEventListener implements Listener {
return true; return true;
} }
return false; return false;
} }
private Location getSitLocation(Block block, Float playerYaw) private Location getSitLocation(Block block, Float playerYaw)
{ {
double sh = 0.7; double sh = 0.7;
for (ChairBlock cb : plugin.allowedBlocks) { for (ChairBlock cb : plugin.allowedBlocks) {
if (cb.getMat().equals(block.getType())) { if (cb.getMat().equals(block.getType())) {
sh = cb.getSitHeight(); sh = cb.getSitHeight();
break; break;
} }
} }
Stairs stairs = null; Stairs stairs = null;
if (block.getState().getData() instanceof Stairs) { if (block.getState().getData() instanceof Stairs) {
stairs = (Stairs) block.getState().getData(); stairs = (Stairs) block.getState().getData();
} }
Location plocation = block.getLocation().clone(); Location plocation = block.getLocation().clone();
plocation.add(0.5D, (sh - 0.5D), 0.5D); plocation.add(0.5D, (sh - 0.5D), 0.5D);
@ -212,9 +211,9 @@ public class TrySitEventListener implements Listener {
} }
return plocation; return plocation;
} }
private boolean isValidChair(Block block) { private boolean isValidChair(Block block) {
for (ChairBlock cb : plugin.allowedBlocks) { for (ChairBlock cb : plugin.allowedBlocks) {
if (cb.getMat().equals(block.getType())) { if (cb.getMat().equals(block.getType())) {

View File

@ -17,60 +17,49 @@ 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;
} }
@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().unSitPlayer(player, false, true); plugin.getPlayerSitData().unSitPlayer(player, false, true);
} }
} }
@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)) {
{
event.setCancelled(true); event.setCancelled(true);
} }
} }
@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().unSitPlayer(player, false, false); plugin.getPlayerSitData().unSitPlayer(player, false, false);
} }
} }
private HashSet<String> queueUnsit = new HashSet<String>(); private HashSet<String> queueUnsit = new HashSet<String>();
@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)) {
{
e.setCancelled(true); e.setCancelled(true);
if (!queueUnsit.contains(player.getName())) if (!queueUnsit.contains(player.getName())) {
{
queueUnsit.add(player.getName()); queueUnsit.add(player.getName());
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
{ @Override
public void run() public void run() {
{
queueUnsit.remove(player.getName()); queueUnsit.remove(player.getName());
plugin.getPlayerSitData().unSitPlayer(player, true, false); plugin.getPlayerSitData().unSitPlayer(player, true, false);
} }
@ -79,17 +68,14 @@ public class TryUnsitEventListener implements Listener {
} }
} }
} }
@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().unSitPlayer(player, true, false); plugin.getPlayerSitData().unSitPlayer(player, true, false);
} }
} }
} }

View File

@ -10,19 +10,19 @@ import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldguard.bukkit.WGBukkit; import com.sk89q.worldguard.bukkit.WGBukkit;
public class WGHook { public class WGHook {
public static boolean isAllowedInRegion(HashSet<String> disabledRegions, Location location) { public static boolean isAllowedInRegion(HashSet<String> disabledRegions, Location location) {
if (Bukkit.getPluginManager().getPlugin("WorldGuard") == null) if (Bukkit.getPluginManager().getPlugin("WorldGuard") == null)
{ {
return true; return true;
} }
if (disabledRegions.isEmpty()) if (disabledRegions.isEmpty())
{ {
return true; return true;
} }
List<String> aregions = WGBukkit.getRegionManager(location.getWorld()).getApplicableRegionsIDs(BukkitUtil.toVector(location)); List<String> aregions = WGBukkit.getRegionManager(location.getWorld()).getApplicableRegionsIDs(BukkitUtil.toVector(location));
for (String region : aregions) for (String region : aregions)
{ {
if (disabledRegions.contains(region)) if (disabledRegions.contains(region))
{ {
@ -31,5 +31,5 @@ public class WGHook {
} }
return true; return true;
} }
} }

View File

@ -21,12 +21,12 @@ public class ChairEffects {
private Chairs plugin; private Chairs plugin;
private int healTaskID = -1; private int healTaskID = -1;
private int pickupTaskID = -1; private int pickupTaskID = -1;
public ChairEffects(Chairs plugin) { public ChairEffects(Chairs plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
public void startHealing() { public void startHealing() {
healEffectsTask(); healEffectsTask();
} }
@ -37,7 +37,7 @@ public class ChairEffects {
healTaskID = -1; healTaskID = -1;
} }
} }
public void restartHealing() { public void restartHealing() {
cancelHealing(); cancelHealing();
startHealing(); startHealing();
@ -64,25 +64,27 @@ public class ChairEffects {
} }
}, plugin.sitHealInterval, plugin.sitHealInterval); }, plugin.sitHealInterval, plugin.sitHealInterval);
} }
public void startPickup() { public void startPickup() {
pickupEffectsTask(); pickupEffectsTask();
} }
public void cancelPickup() { public void cancelPickup() {
if (pickupTaskID != -1) if (pickupTaskID != -1) {
plugin.getServer().getScheduler().cancelTask(pickupTaskID); plugin.getServer().getScheduler().cancelTask(pickupTaskID);
}
pickupTaskID = -1; pickupTaskID = -1;
} }
public void restartPickup() { public void restartPickup() {
cancelPickup(); cancelPickup();
startPickup(); startPickup();
} }
private void pickupEffectsTask() { private void pickupEffectsTask() {
pickupTaskID = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { pickupTaskID = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
public void run() { @Override
public void run() {
for (Player p : Bukkit.getOnlinePlayers()) { for (Player p : Bukkit.getOnlinePlayers()) {
if (plugin.getPlayerSitData().isSitting(p)) { if (plugin.getPlayerSitData().isSitting(p)) {
for (Entity entity : p.getNearbyEntities(1, 2, 1)) { for (Entity entity : p.getNearbyEntities(1, 2, 1)) {
@ -105,5 +107,5 @@ public class ChairEffects {
} }
},0,1); },0,1);
} }
} }

View File

@ -9,12 +9,12 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import com.cnaude.chairs.core.Chairs; import com.cnaude.chairs.core.Chairs;
public class CommandRestrict implements Listener { public class CommandRestrict implements Listener {
private Chairs plugin; private Chairs plugin;
public CommandRestrict(Chairs plugin) { public CommandRestrict(Chairs plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
@EventHandler(priority=EventPriority.LOWEST) @EventHandler(priority=EventPriority.LOWEST)
public void onPlayerCommand(PlayerCommandPreprocessEvent event) public void onPlayerCommand(PlayerCommandPreprocessEvent event)
{ {

View File

@ -13,7 +13,7 @@ public class GetVehicleArrowClass {
if (nmspackageversion.equals("v1_7_R1")) if (nmspackageversion.equals("v1_7_R1"))
{ {
return Class.forName(pkgname+"."+"nms172"+"."+vehiclearrowclassname); return Class.forName(pkgname+"."+"nms172"+"."+vehiclearrowclassname);
} else } else
if (nmspackageversion.equals("v1_6_R3")) if (nmspackageversion.equals("v1_6_R3"))
{ {
return Class.forName(pkgname+"."+"nms164"+"."+vehiclearrowclassname); return Class.forName(pkgname+"."+"nms164"+"."+vehiclearrowclassname);
@ -22,5 +22,5 @@ public class GetVehicleArrowClass {
} }
} }

View File

@ -8,15 +8,15 @@ import org.bukkit.entity.Vehicle;
public class VehicleArrow extends CraftArrow implements Vehicle { public class VehicleArrow extends CraftArrow implements Vehicle {
public VehicleArrow(CraftServer server, EntityArrow entity) public VehicleArrow(CraftServer server, EntityArrow entity)
{ {
super(server, entity); super(server, entity);
} }
@Override @Override
public void remove() public void remove()
{ {
if (this.getPassenger() == null) if (this.getPassenger() == null)
{ {
super.remove(); super.remove();
} }

View File

@ -8,15 +8,15 @@ import org.bukkit.entity.Vehicle;
public class VehicleArrow extends CraftArrow implements Vehicle { public class VehicleArrow extends CraftArrow implements Vehicle {
public VehicleArrow(CraftServer server, EntityArrow entity) public VehicleArrow(CraftServer server, EntityArrow entity)
{ {
super(server, entity); super(server, entity);
} }
@Override @Override
public void remove() public void remove()
{ {
if (this.getPassenger() == null) if (this.getPassenger() == null)
{ {
super.remove(); super.remove();
} }