diff --git a/src/com/cnaude/chairs/commands/ChairsCommand.java b/src/com/cnaude/chairs/commands/ChairsCommand.java index edd227f..66f355b 100644 --- a/src/com/cnaude/chairs/commands/ChairsCommand.java +++ b/src/com/cnaude/chairs/commands/ChairsCommand.java @@ -17,69 +17,69 @@ import com.cnaude.chairs.core.Chairs; */ public class ChairsCommand implements CommandExecutor { - private final Chairs plugin; - public ChairsIgnoreList ignoreList; + private final Chairs plugin; + public ChairsIgnoreList ignoreList; - public ChairsCommand(Chairs instance, ChairsIgnoreList ignoreList) { - this.plugin = instance; - this.ignoreList = ignoreList; - } + public ChairsCommand(Chairs instance, ChairsIgnoreList ignoreList) { + this.plugin = instance; + this.ignoreList = ignoreList; + } - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (args.length == 0) { - return false; - } - if (args[0].equalsIgnoreCase("reload")) { - if (sender.hasPermission("chairs.reload") || !(sender instanceof Player)) { - plugin.loadConfig(); - if (plugin.sitHealEnabled) { - plugin.chairEffects.restartHealing(); - } else { - plugin.chairEffects.cancelHealing(); - } - if (plugin.sitPickupEnabled) { - plugin.chairEffects.restartPickup(); - } else { - plugin.chairEffects.cancelPickup(); - } - if (!plugin.msgReloaded.isEmpty()) { - sender.sendMessage(plugin.msgReloaded); - } - } else { - if (!plugin.msgNoPerm.isEmpty()) { - sender.sendMessage(plugin.msgNoPerm); - } - } - } - if (sender instanceof Player) { - Player p = (Player) sender; - if (args[0].equalsIgnoreCase("on")) { - if (p.hasPermission("chairs.self")) { - ignoreList.removePlayer(p.getName()); - if (!plugin.msgEnabled.isEmpty()) { - p.sendMessage(plugin.msgEnabled); - } - } else { - if (!plugin.msgNoPerm.isEmpty()) { - p.sendMessage(plugin.msgNoPerm); - } - } - } - if (args[0].equalsIgnoreCase("off")) { - if (p.hasPermission("chairs.self")) { - ignoreList.addPlayer(p.getName()); - if (!plugin.msgDisabled.isEmpty()) { - p.sendMessage(plugin.msgDisabled); - } - } else { - if (!plugin.msgNoPerm.isEmpty()) { - p.sendMessage(plugin.msgNoPerm); - } - } - } - } - return true; - } + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args.length == 0) { + return false; + } + if (args[0].equalsIgnoreCase("reload")) { + if (sender.hasPermission("chairs.reload") || !(sender instanceof Player)) { + plugin.loadConfig(); + if (plugin.sitHealEnabled) { + plugin.chairEffects.restartHealing(); + } else { + plugin.chairEffects.cancelHealing(); + } + if (plugin.sitPickupEnabled) { + plugin.chairEffects.restartPickup(); + } else { + plugin.chairEffects.cancelPickup(); + } + if (!plugin.msgReloaded.isEmpty()) { + sender.sendMessage(plugin.msgReloaded); + } + } else { + if (!plugin.msgNoPerm.isEmpty()) { + sender.sendMessage(plugin.msgNoPerm); + } + } + } + if (sender instanceof Player) { + Player p = (Player) sender; + if (args[0].equalsIgnoreCase("on")) { + if (p.hasPermission("chairs.self")) { + ignoreList.removePlayer(p.getName()); + if (!plugin.msgEnabled.isEmpty()) { + p.sendMessage(plugin.msgEnabled); + } + } else { + if (!plugin.msgNoPerm.isEmpty()) { + p.sendMessage(plugin.msgNoPerm); + } + } + } + if (args[0].equalsIgnoreCase("off")) { + if (p.hasPermission("chairs.self")) { + ignoreList.addPlayer(p.getName()); + if (!plugin.msgDisabled.isEmpty()) { + p.sendMessage(plugin.msgDisabled); + } + } else { + if (!plugin.msgNoPerm.isEmpty()) { + p.sendMessage(plugin.msgNoPerm); + } + } + } + } + return true; + } } diff --git a/src/com/cnaude/chairs/commands/ChairsIgnoreList.java b/src/com/cnaude/chairs/commands/ChairsIgnoreList.java index 7253bbb..a0c2123 100644 --- a/src/com/cnaude/chairs/commands/ChairsIgnoreList.java +++ b/src/com/cnaude/chairs/commands/ChairsIgnoreList.java @@ -20,67 +20,67 @@ import com.cnaude.chairs.core.Chairs; */ @SuppressWarnings("serial") public class ChairsIgnoreList implements Serializable{ - private static ArrayList ignoreList = new ArrayList(); - private static final String IGNORE_FILE = "plugins/Chairs/ignores.ser"; + private static ArrayList ignoreList = new ArrayList(); + private static final String IGNORE_FILE = "plugins/Chairs/ignores.ser"; - private Chairs plugin; - public ChairsIgnoreList(Chairs plugin) - { - this.plugin = plugin; - } + private Chairs plugin; + public ChairsIgnoreList(Chairs plugin) + { + this.plugin = plugin; + } - @SuppressWarnings("unchecked") - public void load() { - File file = new File(IGNORE_FILE); - if (!file.exists()) { - plugin.logInfo("Ignore file '"+file.getAbsolutePath()+"' does not exist."); - return; - } - try { - FileInputStream f_in = new FileInputStream(file); - ObjectInputStream obj_in = new ObjectInputStream (f_in); - ignoreList = (ArrayList) obj_in.readObject(); - obj_in.close(); - plugin.logInfo("Loaded ignore list. (Count = "+ignoreList.size()+")"); - } - catch(Exception e) { - plugin.logError(e.getMessage()); - } - } + @SuppressWarnings("unchecked") + public void load() { + File file = new File(IGNORE_FILE); + if (!file.exists()) { + plugin.logInfo("Ignore file '"+file.getAbsolutePath()+"' does not exist."); + return; + } + try { + FileInputStream f_in = new FileInputStream(file); + ObjectInputStream obj_in = new ObjectInputStream (f_in); + ignoreList = (ArrayList) obj_in.readObject(); + obj_in.close(); + plugin.logInfo("Loaded ignore list. (Count = "+ignoreList.size()+")"); + } + catch(Exception e) { + plugin.logError(e.getMessage()); + } + } - public void save() { - try { - File file = new File(IGNORE_FILE); - FileOutputStream f_out = new FileOutputStream (file); - ObjectOutputStream obj_out = new ObjectOutputStream (f_out); - obj_out.writeObject (ignoreList); - obj_out.close(); - plugin.logInfo("Saved ignore list. (Count = "+ignoreList.size()+")"); - } - catch(Exception e) { - plugin.logError(e.getMessage()); - } - } + public void save() { + try { + File file = new File(IGNORE_FILE); + FileOutputStream f_out = new FileOutputStream (file); + ObjectOutputStream obj_out = new ObjectOutputStream (f_out); + obj_out.writeObject (ignoreList); + obj_out.close(); + plugin.logInfo("Saved ignore list. (Count = "+ignoreList.size()+")"); + } + catch(Exception e) { + plugin.logError(e.getMessage()); + } + } - public void addPlayer(String s) { - if (ignoreList.contains(s)) { - return; - } - //Chairs.get().logInfo("Adding " + s + " to ignore list."); - ignoreList.add(s); - } + public void addPlayer(String s) { + if (ignoreList.contains(s)) { + return; + } + //Chairs.get().logInfo("Adding " + s + " to ignore list."); + ignoreList.add(s); + } - public void removePlayer(String s) { - //Chairs.get().logInfo("Removing " + s + " from ignore list."); - ignoreList.remove(s); - } + public void removePlayer(String s) { + //Chairs.get().logInfo("Removing " + s + " from ignore list."); + ignoreList.remove(s); + } - public boolean isIgnored(String s) { - if (ignoreList.contains(s)) { - return true; - } - else { - return false; - } - } + public boolean isIgnored(String s) { + if (ignoreList.contains(s)) { + return true; + } + else { + return false; + } + } } \ No newline at end of file diff --git a/src/com/cnaude/chairs/core/ChairBlock.java b/src/com/cnaude/chairs/core/ChairBlock.java index 8ed2c6c..4d514d5 100644 --- a/src/com/cnaude/chairs/core/ChairBlock.java +++ b/src/com/cnaude/chairs/core/ChairBlock.java @@ -11,20 +11,20 @@ import org.bukkit.Material; * @author cnaude */ public class ChairBlock { - private Material mat; - private double sitHeight; + private Material mat; + private double sitHeight; - public ChairBlock(Material m, double s) { - mat = m; - sitHeight = s; - } + public ChairBlock(Material m, double s) { + mat = m; + sitHeight = s; + } - public Material getMat() { - return mat; - } + public Material getMat() { + return mat; + } - public double getSitHeight() { - return sitHeight; - } + public double getSitHeight() { + return sitHeight; + } } diff --git a/src/com/cnaude/chairs/core/Chairs.java b/src/com/cnaude/chairs/core/Chairs.java index 9787ed3..ec2b9f4 100644 --- a/src/com/cnaude/chairs/core/Chairs.java +++ b/src/com/cnaude/chairs/core/Chairs.java @@ -25,153 +25,153 @@ import com.cnaude.chairs.sitaddons.CommandRestrict; import com.cnaude.chairs.vehiclearrow.NMSAccess; public class Chairs extends JavaPlugin { - public ChairEffects chairEffects; - public List allowedBlocks; - public List validSigns; - public boolean autoRotate, signCheck, notifyplayer; - public boolean ignoreIfBlockInHand; - public double distance; - public HashSet disabledRegions = new HashSet(); - public int maxChairWidth; - public boolean sitHealEnabled; - public int sitMaxHealth; - public int sitHealthPerInterval; - public int sitHealInterval; - public boolean sitPickupEnabled; - public boolean sitDisableAllCommands = false; - public HashSet sitDisabledCommands = new HashSet(); - private Logger log; - public ChairsIgnoreList ignoreList; - public String msgSitting, msgStanding, msgOccupied, msgNoPerm, msgReloaded, msgDisabled, msgEnabled, msgCommandRestricted; + public ChairEffects chairEffects; + public List allowedBlocks; + public List validSigns; + public boolean autoRotate, signCheck, notifyplayer; + public boolean ignoreIfBlockInHand; + public double distance; + public HashSet disabledRegions = new HashSet(); + public int maxChairWidth; + public boolean sitHealEnabled; + public int sitMaxHealth; + public int sitHealthPerInterval; + public int sitHealInterval; + public boolean sitPickupEnabled; + public boolean sitDisableAllCommands = false; + public HashSet sitDisabledCommands = new HashSet(); + private Logger log; + public ChairsIgnoreList ignoreList; + public String msgSitting, msgStanding, msgOccupied, msgNoPerm, msgReloaded, msgDisabled, msgEnabled, msgCommandRestricted; - private PlayerSitData psitdata; - public PlayerSitData getPlayerSitData() { - return psitdata; - } - private NMSAccess nmsaccess = new NMSAccess(); - protected NMSAccess getNMSAccess() { - return nmsaccess; - } + private PlayerSitData psitdata; + public PlayerSitData getPlayerSitData() { + return psitdata; + } + private NMSAccess nmsaccess = new NMSAccess(); + protected NMSAccess getNMSAccess() { + return nmsaccess; + } - @Override - public void onEnable() { - log = this.getLogger(); + @Override + public void onEnable() { + log = this.getLogger(); try { - nmsaccess.setupVehicleArrow(); + nmsaccess.setupVehicleArrow(); } catch (Exception e) { e.printStackTrace(); log.severe("Failed to generate VehicleArrow class, exiting"); getServer().getPluginManager().disablePlugin(this); return; } - chairEffects = new ChairEffects(this); - ignoreList = new ChairsIgnoreList(this); - ignoreList.load(); - psitdata = new PlayerSitData(this); - getConfig().options().copyDefaults(true); - saveConfig(); - loadConfig(); - if (sitHealEnabled) { - chairEffects.startHealing(); - } - if (sitPickupEnabled) { - chairEffects.startPickup(); - } - getServer().getPluginManager().registerEvents(new NANLoginListener(), this); - getServer().getPluginManager().registerEvents(new TrySitEventListener(this, ignoreList), this); - getServer().getPluginManager().registerEvents(new TryUnsitEventListener(this), this); - getServer().getPluginManager().registerEvents(new CommandRestrict(this), this); - getCommand("chairs").setExecutor(new ChairsCommand(this, ignoreList)); - new ChairsAPI(getPlayerSitData()); - } + chairEffects = new ChairEffects(this); + ignoreList = new ChairsIgnoreList(this); + ignoreList.load(); + psitdata = new PlayerSitData(this); + getConfig().options().copyDefaults(true); + saveConfig(); + loadConfig(); + if (sitHealEnabled) { + chairEffects.startHealing(); + } + if (sitPickupEnabled) { + chairEffects.startPickup(); + } + getServer().getPluginManager().registerEvents(new NANLoginListener(), this); + getServer().getPluginManager().registerEvents(new TrySitEventListener(this, ignoreList), this); + getServer().getPluginManager().registerEvents(new TryUnsitEventListener(this), this); + getServer().getPluginManager().registerEvents(new CommandRestrict(this), this); + getCommand("chairs").setExecutor(new ChairsCommand(this, ignoreList)); + new ChairsAPI(getPlayerSitData()); + } - @Override - public void onDisable() { - for (Player player : getServer().getOnlinePlayers()) { - if (psitdata.isSitting(player)) { - psitdata.unsitPlayerNow(player); - } - } - if (ignoreList != null) { - ignoreList.save(); - } - if (chairEffects != null) { - chairEffects.cancelHealing(); - chairEffects.cancelPickup(); - chairEffects = null; - } - log = null; - nmsaccess = null; - psitdata = null; - } + @Override + public void onDisable() { + for (Player player : getServer().getOnlinePlayers()) { + if (psitdata.isSitting(player)) { + psitdata.unsitPlayerNow(player); + } + } + if (ignoreList != null) { + ignoreList.save(); + } + if (chairEffects != null) { + chairEffects.cancelHealing(); + chairEffects.cancelPickup(); + chairEffects = null; + } + log = null; + nmsaccess = null; + psitdata = null; + } - public void loadConfig() { - FileConfiguration config = YamlConfiguration.loadConfiguration(new File(this.getDataFolder(),"config.yml")); - autoRotate = config.getBoolean("auto-rotate"); - signCheck = config.getBoolean("sign-check"); - distance = config.getDouble("distance"); - maxChairWidth = config.getInt("max-chair-width"); - notifyplayer = config.getBoolean("notify-player"); - ignoreIfBlockInHand = config.getBoolean("ignore-if-item-in-hand"); + public void loadConfig() { + FileConfiguration config = YamlConfiguration.loadConfiguration(new File(this.getDataFolder(),"config.yml")); + autoRotate = config.getBoolean("auto-rotate"); + signCheck = config.getBoolean("sign-check"); + distance = config.getDouble("distance"); + maxChairWidth = config.getInt("max-chair-width"); + notifyplayer = config.getBoolean("notify-player"); + ignoreIfBlockInHand = config.getBoolean("ignore-if-item-in-hand"); - disabledRegions = new HashSet(config.getStringList("disabledWGRegions")); + disabledRegions = new HashSet(config.getStringList("disabledWGRegions")); - sitHealEnabled = config.getBoolean("sit-effects.healing.enabled", false); - sitHealInterval = config.getInt("sit-effects.healing.interval",20); - sitMaxHealth = config.getInt("sit-effects.healing.max-percent",100); - sitHealthPerInterval = config.getInt("sit-effects.healing.amount",1); + sitHealEnabled = config.getBoolean("sit-effects.healing.enabled", false); + sitHealInterval = config.getInt("sit-effects.healing.interval",20); + sitMaxHealth = config.getInt("sit-effects.healing.max-percent",100); + 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"); - sitDisabledCommands = new HashSet(config.getStringList("sit-restrictions.commands.list")); + sitDisableAllCommands = config.getBoolean("sit-restrictions.commands.all"); + sitDisabledCommands = new HashSet(config.getStringList("sit-restrictions.commands.list")); - msgSitting = ChatColor.translateAlternateColorCodes('&',config.getString("messages.sitting")); - msgStanding = ChatColor.translateAlternateColorCodes('&',config.getString("messages.standing")); - msgOccupied = ChatColor.translateAlternateColorCodes('&',config.getString("messages.occupied")); - msgNoPerm = ChatColor.translateAlternateColorCodes('&',config.getString("messages.no-permission")); - msgEnabled = ChatColor.translateAlternateColorCodes('&',config.getString("messages.enabled")); - msgDisabled = ChatColor.translateAlternateColorCodes('&',config.getString("messages.disabled")); - msgReloaded = ChatColor.translateAlternateColorCodes('&',config.getString("messages.reloaded")); - msgCommandRestricted = ChatColor.translateAlternateColorCodes('&',config.getString("messages.command-restricted")); + msgSitting = ChatColor.translateAlternateColorCodes('&',config.getString("messages.sitting")); + msgStanding = ChatColor.translateAlternateColorCodes('&',config.getString("messages.standing")); + msgOccupied = ChatColor.translateAlternateColorCodes('&',config.getString("messages.occupied")); + msgNoPerm = ChatColor.translateAlternateColorCodes('&',config.getString("messages.no-permission")); + msgEnabled = ChatColor.translateAlternateColorCodes('&',config.getString("messages.enabled")); + msgDisabled = ChatColor.translateAlternateColorCodes('&',config.getString("messages.disabled")); + msgReloaded = ChatColor.translateAlternateColorCodes('&',config.getString("messages.reloaded")); + msgCommandRestricted = ChatColor.translateAlternateColorCodes('&',config.getString("messages.command-restricted")); - allowedBlocks = new ArrayList(); - for (String s : config.getStringList("sit-blocks")) { - String type; - double sh = 0.7; - String tmp[] = s.split("[:]"); - type = tmp[0]; - if (tmp.length == 2) { - sh = Double.parseDouble(tmp[1]); - } - Material mat = Material.matchMaterial(type); - if (mat != null) { - logInfo("Allowed block: " + mat.toString() + " => " + sh); - allowedBlocks.add(new ChairBlock(mat,sh)); - } else { - logError("Invalid block: " + type); - } - } + allowedBlocks = new ArrayList(); + for (String s : config.getStringList("sit-blocks")) { + String type; + double sh = 0.7; + String tmp[] = s.split("[:]"); + type = tmp[0]; + if (tmp.length == 2) { + sh = Double.parseDouble(tmp[1]); + } + Material mat = Material.matchMaterial(type); + if (mat != null) { + logInfo("Allowed block: " + mat.toString() + " => " + sh); + allowedBlocks.add(new ChairBlock(mat,sh)); + } else { + logError("Invalid block: " + type); + } + } - validSigns = new ArrayList(); - for (String type : config.getStringList("valid-signs")) { - try { - validSigns.add(Material.matchMaterial(type)); - } - catch (Exception e) { - logError(e.getMessage()); - } - } - } + validSigns = new ArrayList(); + for (String type : config.getStringList("valid-signs")) { + try { + validSigns.add(Material.matchMaterial(type)); + } + catch (Exception e) { + logError(e.getMessage()); + } + } + } - public void logInfo(String _message) { - log.log(Level.INFO, _message); - } + public void logInfo(String _message) { + log.log(Level.INFO, _message); + } - public void logError(String _message) { - log.log(Level.SEVERE, _message); - } + public void logError(String _message) { + log.log(Level.SEVERE, _message); + } } diff --git a/src/com/cnaude/chairs/core/PlayerSitData.java b/src/com/cnaude/chairs/core/PlayerSitData.java index 4f7d083..edaef58 100644 --- a/src/com/cnaude/chairs/core/PlayerSitData.java +++ b/src/com/cnaude/chairs/core/PlayerSitData.java @@ -30,39 +30,39 @@ public class PlayerSitData { public Player getPlayerOnChair(Block chair) { return Bukkit.getPlayerExact(sitblock.get(chair)); } - public void sitPlayer(Player player, Location sitlocation) { - try { - if (plugin.notifyplayer) { - player.sendMessage(plugin.msgSitting); - } - Block block = sitlocation.getBlock(); - sitstopteleportloc.put(player.getName(), player.getLocation()); - player.teleport(sitlocation); - Location arrowloc = block.getLocation().add(0.5, 0 , 0.5); + public void sitPlayer(Player player, Location sitlocation) { + try { + if (plugin.notifyplayer) { + player.sendMessage(plugin.msgSitting); + } + Block block = sitlocation.getBlock(); + sitstopteleportloc.put(player.getName(), player.getLocation()); + player.teleport(sitlocation); + Location arrowloc = block.getLocation().add(0.5, 0 , 0.5); Entity arrow = sitPlayerOnArrow(player, arrowloc); - sit.put(player.getName(), arrow); - sitblock.put(block, player.getName()); - sitblockbr.put(player.getName(), block); - startReSitTask(player); - } catch (Exception e) { - e.printStackTrace(); - } - } - public void startReSitTask(final Player player) { - int task = - Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { - @Override - public void run() { - reSitPlayer(player); - } - },1000,1000); - sittask.put(player.getName(), task); - } - public void reSitPlayer(final Player player) { - try { - final Entity prevarrow = sit.get(player.getName()); - sit.remove(player.getName()); - player.eject(); + sit.put(player.getName(), arrow); + sitblock.put(block, player.getName()); + sitblockbr.put(player.getName(), block); + startReSitTask(player); + } catch (Exception e) { + e.printStackTrace(); + } + } + public void startReSitTask(final Player player) { + int task = + Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { + @Override + public void run() { + reSitPlayer(player); + } + },1000,1000); + sittask.put(player.getName(), task); + } + public void reSitPlayer(final Player player) { + try { + final Entity prevarrow = sit.get(player.getName()); + sit.remove(player.getName()); + player.eject(); Block block = sitblockbr.get(player.getName()); Location arrowloc = block.getLocation().add(0.5, 0 , 0.5); Entity arrow = sitPlayerOnArrow(player, arrowloc); @@ -73,51 +73,51 @@ public class PlayerSitData { prevarrow.remove(); } },100); - } catch (Exception e) { - e.printStackTrace(); - } - } - private Entity sitPlayerOnArrow(Player player, Location arrowloc) throws NoSuchMethodException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, InstantiationException, InvocationTargetException { - Entity arrow = plugin.getNMSAccess().spawnArrow(arrowloc); - arrow.setPassenger(player); + } catch (Exception e) { + e.printStackTrace(); + } + } + private Entity sitPlayerOnArrow(Player player, Location arrowloc) throws NoSuchMethodException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, InstantiationException, InvocationTargetException { + Entity arrow = plugin.getNMSAccess().spawnArrow(arrowloc); + arrow.setPassenger(player); return arrow; - } - public void unsitPlayerNormal(Player player) { - unsitPlayer(player, false, true, false); - } - public void unsitPlayerForce(Player player) { - unsitPlayer(player, true, true, false); - } - public void unsitPlayerNow(Player player) { - unsitPlayer(player, true, false, true); - } - private void unsitPlayer(final Player player, boolean eject, boolean restoreposition, boolean correctleaveposition) { - final Entity arrow = sit.get(player.getName()); + } + public void unsitPlayerNormal(Player player) { + unsitPlayer(player, false, true, false); + } + public void unsitPlayerForce(Player player) { + unsitPlayer(player, true, true, false); + } + public void unsitPlayerNow(Player player) { + unsitPlayer(player, true, false, true); + } + private void unsitPlayer(final Player player, boolean eject, boolean restoreposition, boolean correctleaveposition) { + final Entity arrow = sit.get(player.getName()); sit.remove(player.getName()); if (eject) { player.eject(); } - arrow.remove(); - final Location tploc = sitstopteleportloc.get(player.getName()); - if (restoreposition) { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - @Override + arrow.remove(); + final Location tploc = sitstopteleportloc.get(player.getName()); + if (restoreposition) { + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override public void run() { - player.teleport(tploc); - player.setSneaking(false); - } - },1); - } else if (correctleaveposition) { - player.teleport(tploc); - } + player.teleport(tploc); + player.setSneaking(false); + } + },1); + } else if (correctleaveposition) { + player.teleport(tploc); + } sitblock.remove(sitblockbr.get(player.getName())); sitblockbr.remove(player.getName()); sitstopteleportloc.remove(player.getName()); Bukkit.getScheduler().cancelTask(sittask.get(player.getName())); sittask.remove(player.getName()); if (plugin.notifyplayer) { - player.sendMessage(plugin.msgStanding); - } - } + player.sendMessage(plugin.msgStanding); + } + } } diff --git a/src/com/cnaude/chairs/core/api/ChairsAPI.java b/src/com/cnaude/chairs/core/api/ChairsAPI.java index 7a9bf89..4ad4fe0 100644 --- a/src/com/cnaude/chairs/core/api/ChairsAPI.java +++ b/src/com/cnaude/chairs/core/api/ChairsAPI.java @@ -14,5 +14,5 @@ public class ChairsAPI { public static boolean isSitting(Player player) { return pdata.isSitting(player); } - + } diff --git a/src/com/cnaude/chairs/listeners/TrySitEventListener.java b/src/com/cnaude/chairs/listeners/TrySitEventListener.java index d350c91..f0714a3 100644 --- a/src/com/cnaude/chairs/listeners/TrySitEventListener.java +++ b/src/com/cnaude/chairs/listeners/TrySitEventListener.java @@ -23,282 +23,282 @@ import com.cnaude.chairs.pluginhooks.WGHook; public class TrySitEventListener implements Listener { - public Chairs plugin; - public ChairsIgnoreList ignoreList; + public Chairs plugin; + public ChairsIgnoreList ignoreList; - public TrySitEventListener(Chairs plugin, ChairsIgnoreList ignoreList) { - this.plugin = plugin; - this.ignoreList = ignoreList; - } + public TrySitEventListener(Chairs plugin, ChairsIgnoreList ignoreList) { + this.plugin = plugin; + this.ignoreList = ignoreList; + } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onPlayerInteract(PlayerInteractEvent event) { - Player player = event.getPlayer(); - if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { - Block block = event.getClickedBlock(); - if (sitAllowed(player, block)) { - event.setCancelled(true); - Location sitLocation = getSitLocation(block, player.getLocation().getYaw()); - plugin.getPlayerSitData().sitPlayer(player, sitLocation); - } - } - } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onPlayerInteract(PlayerInteractEvent event) { + Player player = event.getPlayer(); + if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { + Block block = event.getClickedBlock(); + if (sitAllowed(player, block)) { + event.setCancelled(true); + Location sitLocation = getSitLocation(block, player.getLocation().getYaw()); + plugin.getPlayerSitData().sitPlayer(player, sitLocation); + } + } + } - private boolean sitAllowed(Player player, Block block) { - // Check for permissions - if (!player.hasPermission("chairs.sit")) { - return false; - } + private boolean sitAllowed(Player player, Block block) { + // Check for permissions + if (!player.hasPermission("chairs.sit")) { + return false; + } - // Check for already sitting - if (isSitting(player)) { - return false; - } + // Check for already sitting + if (isSitting(player)) { + return false; + } - // Check for item in hand - if (plugin.ignoreIfBlockInHand && player.getItemInHand().getType() != Material.AIR) { - return false; - } + // Check for item in hand + if (plugin.ignoreIfBlockInHand && player.getItemInHand().getType() != Material.AIR) { + return false; + } - // Check for sneaking - if (player.isSneaking()) { - return false; - } + // Check for sneaking + if (player.isSneaking()) { + return false; + } - // Check for /chairs off - if (ignoreList.isIgnored(player.getName())) { - return false; - } + // Check for /chairs off + if (ignoreList.isIgnored(player.getName())) { + return false; + } - // Sit occupied check - if (plugin.getPlayerSitData().isBlockOccupied(block)) { - player.sendMessage(plugin.msgOccupied.replace("%PLAYER%", plugin.getPlayerSitData().getPlayerOnChair(block).getName())); - return false; - } + // Sit occupied check + if (plugin.getPlayerSitData().isBlockOccupied(block)) { + player.sendMessage(plugin.msgOccupied.replace("%PLAYER%", plugin.getPlayerSitData().getPlayerOnChair(block).getName())); + return false; + } - // Region allowance check - if (!WGHook.isAllowedInRegion(plugin.disabledRegions, block.getLocation())) { - return false; - } + // Region allowance check + if (!WGHook.isAllowedInRegion(plugin.disabledRegions, block.getLocation())) { + return false; + } - Stairs stairs = null; - Step step = null; - WoodenStep wStep = null; + Stairs stairs = null; + Step step = null; + WoodenStep wStep = null; - // Check for block is chair - if ( - isValidChair(block) || - ( - !player.hasPermission("chairs.sit.antiopcheck") && - player.hasPermission("chairs.sit." + block.getType().toString()) - ) - ) - { - if (block.getState().getData() instanceof Stairs) { - stairs = (Stairs) block.getState().getData(); - } else if (block.getState().getData() instanceof Step) { - step = (Step) block.getState().getData(); - } else if (block.getState().getData() instanceof WoodenStep) { - wStep = (WoodenStep) block.getState().getData(); - } + // Check for block is chair + if ( + isValidChair(block) || + ( + !player.hasPermission("chairs.sit.antiopcheck") && + player.hasPermission("chairs.sit." + block.getType().toString()) + ) + ) + { + if (block.getState().getData() instanceof Stairs) { + stairs = (Stairs) block.getState().getData(); + } else if (block.getState().getData() instanceof Step) { + step = (Step) block.getState().getData(); + } else if (block.getState().getData() instanceof WoodenStep) { + wStep = (WoodenStep) block.getState().getData(); + } - int chairwidth = 1; + int chairwidth = 1; - // Check if block beneath chair is solid. - if (block.getRelative(BlockFace.DOWN).isLiquid()) { - return false; - } - if (block.getRelative(BlockFace.DOWN).isEmpty()) { - return false; - } - if (!block.getRelative(BlockFace.DOWN).getType().isSolid()) { - return false; - } + // Check if block beneath chair is solid. + if (block.getRelative(BlockFace.DOWN).isLiquid()) { + return false; + } + if (block.getRelative(BlockFace.DOWN).isEmpty()) { + return false; + } + if (!block.getRelative(BlockFace.DOWN).getType().isSolid()) { + return false; + } - // Check for distance distance between player and chair. - if (plugin.distance > 0 && player.getLocation().distance(block.getLocation().add(0.5, 0, 0.5)) > plugin.distance) { - return false; - } + // Check for distance distance between player and chair. + if (plugin.distance > 0 && player.getLocation().distance(block.getLocation().add(0.5, 0, 0.5)) > plugin.distance) { + return false; + } - // Check if block is inverted - if (stairs != null && stairs.isInverted()) { - return false; - } - if (step != null && step.isInverted()) { - return false; - } - if (wStep != null && wStep.isInverted()) { - return false; - } + // Check if block is inverted + if (stairs != null && stairs.isInverted()) { + return false; + } + if (step != null && step.isInverted()) { + return false; + } + if (wStep != null && wStep.isInverted()) { + return false; + } - // Check for signs (only for stairs) - if (plugin.signCheck && stairs != null) { - boolean sign1 = false; - boolean sign2 = false; + // Check for signs (only for stairs) + if (plugin.signCheck && stairs != null) { + boolean sign1 = false; + boolean sign2 = false; - if (stairs.getDescendingDirection() == BlockFace.NORTH || stairs.getDescendingDirection() == BlockFace.SOUTH) { - sign1 = checkSign(block, BlockFace.EAST) || checkFrame(block, BlockFace.EAST, player); - sign2 = checkSign(block, BlockFace.WEST) || checkFrame(block, BlockFace.WEST, player); - } else if (stairs.getDescendingDirection() == BlockFace.EAST || stairs.getDescendingDirection() == BlockFace.WEST) { - sign1 = checkSign(block, BlockFace.NORTH) || checkFrame(block, BlockFace.NORTH, player); - sign2 = checkSign(block, BlockFace.SOUTH) || checkFrame(block, BlockFace.SOUTH, player); - } + if (stairs.getDescendingDirection() == BlockFace.NORTH || stairs.getDescendingDirection() == BlockFace.SOUTH) { + sign1 = checkSign(block, BlockFace.EAST) || checkFrame(block, BlockFace.EAST, player); + sign2 = checkSign(block, BlockFace.WEST) || checkFrame(block, BlockFace.WEST, player); + } else if (stairs.getDescendingDirection() == BlockFace.EAST || stairs.getDescendingDirection() == BlockFace.WEST) { + sign1 = checkSign(block, BlockFace.NORTH) || checkFrame(block, BlockFace.NORTH, player); + sign2 = checkSign(block, BlockFace.SOUTH) || checkFrame(block, BlockFace.SOUTH, player); + } - if (!(sign1 && sign2)) { - return false; - } - } + if (!(sign1 && sign2)) { + return false; + } + } - // Check for maximal chair width (only for stairs) - if (plugin.maxChairWidth > 0 && stairs != null) { - if (stairs.getDescendingDirection() == BlockFace.NORTH || stairs.getDescendingDirection() == BlockFace.SOUTH) { - chairwidth += getChairWidth(block, BlockFace.EAST); - chairwidth += getChairWidth(block, BlockFace.WEST); - } else if (stairs.getDescendingDirection() == BlockFace.EAST || stairs.getDescendingDirection() == BlockFace.WEST) { - chairwidth += getChairWidth(block, BlockFace.NORTH); - chairwidth += getChairWidth(block, BlockFace.SOUTH); - } + // Check for maximal chair width (only for stairs) + if (plugin.maxChairWidth > 0 && stairs != null) { + if (stairs.getDescendingDirection() == BlockFace.NORTH || stairs.getDescendingDirection() == BlockFace.SOUTH) { + chairwidth += getChairWidth(block, BlockFace.EAST); + chairwidth += getChairWidth(block, BlockFace.WEST); + } else if (stairs.getDescendingDirection() == BlockFace.EAST || stairs.getDescendingDirection() == BlockFace.WEST) { + chairwidth += getChairWidth(block, BlockFace.NORTH); + chairwidth += getChairWidth(block, BlockFace.SOUTH); + } - if (chairwidth > plugin.maxChairWidth) { - return false; - } - } + if (chairwidth > plugin.maxChairWidth) { + return false; + } + } - return true; - } + return true; + } - return false; - } + return false; + } - private Location getSitLocation(Block block, Float playerYaw) - { - double sh = 0.7; + private Location getSitLocation(Block block, Float playerYaw) + { + double sh = 0.7; - for (ChairBlock cb : plugin.allowedBlocks) { - if (cb.getMat().equals(block.getType())) { - sh = cb.getSitHeight(); - break; - } - } + for (ChairBlock cb : plugin.allowedBlocks) { + if (cb.getMat().equals(block.getType())) { + sh = cb.getSitHeight(); + break; + } + } - Stairs stairs = null; - if (block.getState().getData() instanceof Stairs) { - stairs = (Stairs) block.getState().getData(); - } + Stairs stairs = null; + if (block.getState().getData() instanceof Stairs) { + stairs = (Stairs) block.getState().getData(); + } - Location plocation = block.getLocation().clone(); - plocation.add(0.5D, (sh - 0.5D), 0.5D); + Location plocation = block.getLocation().clone(); + plocation.add(0.5D, (sh - 0.5D), 0.5D); - // Rotate the player's view to the descending side of the block. - if (plugin.autoRotate && stairs != null) { - switch (stairs.getDescendingDirection()) { - case NORTH: - plocation.setYaw(180); - break; - case EAST: - plocation.setYaw(-90); - break; - case SOUTH: - plocation.setYaw(0); - break; - case WEST: - plocation.setYaw(90); + // Rotate the player's view to the descending side of the block. + if (plugin.autoRotate && stairs != null) { + switch (stairs.getDescendingDirection()) { + case NORTH: + plocation.setYaw(180); + break; + case EAST: + plocation.setYaw(-90); + break; + case SOUTH: + plocation.setYaw(0); + break; + case WEST: + plocation.setYaw(90); default: ; - } - } else { - plocation.setYaw(playerYaw); - } + } + } else { + plocation.setYaw(playerYaw); + } return plocation; - } + } - private boolean isValidChair(Block block) { - for (ChairBlock cb : plugin.allowedBlocks) { - if (cb.getMat().equals(block.getType())) { - return true; - } - } - return false; - } + private boolean isValidChair(Block block) { + for (ChairBlock cb : plugin.allowedBlocks) { + if (cb.getMat().equals(block.getType())) { + return true; + } + } + return false; + } - private boolean isSitting(Player player) { - return plugin.getPlayerSitData().isSitting(player); - } + private boolean isSitting(Player player) { + return plugin.getPlayerSitData().isSitting(player); + } - private int getChairWidth(Block block, BlockFace face) { - int width = 0; + private int getChairWidth(Block block, BlockFace face) { + int width = 0; - // Go through the blocks next to the clicked block and check if there are any further stairs. - for (int i = 1; i <= plugin.maxChairWidth; i++) { - Block relative = block.getRelative(face, i); - if (relative.getState().getData() instanceof Stairs) { - if (isValidChair(relative) && ((Stairs) relative.getState().getData()).getDescendingDirection() == ((Stairs) block.getState().getData()).getDescendingDirection()) { - width++; - } else { - break; - } - } - } + // Go through the blocks next to the clicked block and check if there are any further stairs. + for (int i = 1; i <= plugin.maxChairWidth; i++) { + Block relative = block.getRelative(face, i); + if (relative.getState().getData() instanceof Stairs) { + if (isValidChair(relative) && ((Stairs) relative.getState().getData()).getDescendingDirection() == ((Stairs) block.getState().getData()).getDescendingDirection()) { + width++; + } else { + break; + } + } + } - return width; - } + return width; + } - private boolean checkSign(Block block, BlockFace face) { - // Go through the blocks next to the clicked block and check if are signs on the end. - for (int i = 1; i <= 100; i++) { - Block relative = block.getRelative(face, i); - if (checkDirection(block, relative)) { - continue; - } - if (plugin.validSigns.contains(relative.getType())) { - return true; - } else { - return false; - } - } - return false; - } + private boolean checkSign(Block block, BlockFace face) { + // Go through the blocks next to the clicked block and check if are signs on the end. + for (int i = 1; i <= 100; i++) { + Block relative = block.getRelative(face, i); + if (checkDirection(block, relative)) { + continue; + } + if (plugin.validSigns.contains(relative.getType())) { + return true; + } else { + return false; + } + } + return false; + } - private boolean checkDirection(Block block1, Block block2) { - if (block1.getState().getData() instanceof Stairs - && block2.getState().getData() instanceof Stairs) { - if (((Stairs) block1.getState().getData()).getDescendingDirection() - .equals(((Stairs) block2.getState().getData()).getDescendingDirection())) { - return true; - } - } - return false; - } + private boolean checkDirection(Block block1, Block block2) { + if (block1.getState().getData() instanceof Stairs + && block2.getState().getData() instanceof Stairs) { + if (((Stairs) block1.getState().getData()).getDescendingDirection() + .equals(((Stairs) block2.getState().getData()).getDescendingDirection())) { + return true; + } + } + return false; + } - private boolean checkFrame(Block block, BlockFace face, Player player) { - // Go through the blocks next to the clicked block and check if are signs on the end. + private boolean checkFrame(Block block, BlockFace face, Player player) { + // Go through the blocks next to the clicked block and check if are signs on the end. - for (int i = 1; i <= 100; i++) { - Block relative = block.getRelative(face, i); - if (checkDirection(block, relative)) { - continue; - } - if (relative.getType().equals(Material.AIR)) { - int x = relative.getLocation().getBlockX(); - int y = relative.getLocation().getBlockY(); - int z = relative.getLocation().getBlockZ(); - for (Entity e : player.getNearbyEntities(plugin.distance, plugin.distance, plugin.distance)) { - if (e instanceof ItemFrame && plugin.validSigns.contains(Material.ITEM_FRAME)) { - int x2 = e.getLocation().getBlockX(); - int y2 = e.getLocation().getBlockY(); - int z2 = e.getLocation().getBlockZ(); - if (x == x2 && y == y2 && z == z2) { - return true; - } - } - } - return false; - } else { - return false; - } - } - return false; - } + for (int i = 1; i <= 100; i++) { + Block relative = block.getRelative(face, i); + if (checkDirection(block, relative)) { + continue; + } + if (relative.getType().equals(Material.AIR)) { + int x = relative.getLocation().getBlockX(); + int y = relative.getLocation().getBlockY(); + int z = relative.getLocation().getBlockZ(); + for (Entity e : player.getNearbyEntities(plugin.distance, plugin.distance, plugin.distance)) { + if (e instanceof ItemFrame && plugin.validSigns.contains(Material.ITEM_FRAME)) { + int x2 = e.getLocation().getBlockX(); + int y2 = e.getLocation().getBlockY(); + int z2 = e.getLocation().getBlockZ(); + if (x == x2 && y == y2 && z == z2) { + return true; + } + } + } + return false; + } else { + return false; + } + } + return false; + } } \ No newline at end of file diff --git a/src/com/cnaude/chairs/listeners/TryUnsitEventListener.java b/src/com/cnaude/chairs/listeners/TryUnsitEventListener.java index 17e913e..fb9f3b3 100644 --- a/src/com/cnaude/chairs/listeners/TryUnsitEventListener.java +++ b/src/com/cnaude/chairs/listeners/TryUnsitEventListener.java @@ -15,53 +15,53 @@ import com.cnaude.chairs.core.Chairs; public class TryUnsitEventListener implements Listener { - public Chairs plugin; + public Chairs plugin; - public TryUnsitEventListener(Chairs plugin) { - this.plugin = plugin; - } + public TryUnsitEventListener(Chairs plugin) { + this.plugin = plugin; + } - @EventHandler(priority=EventPriority.LOWEST) - public void onPlayerQuit(PlayerQuitEvent event) { - Player player = event.getPlayer(); - if (plugin.getPlayerSitData().isSitting(player)) { - plugin.getPlayerSitData().unsitPlayerNow(player); - } - } + @EventHandler(priority=EventPriority.LOWEST) + public void onPlayerQuit(PlayerQuitEvent event) { + Player player = event.getPlayer(); + if (plugin.getPlayerSitData().isSitting(player)) { + plugin.getPlayerSitData().unsitPlayerNow(player); + } + } - @EventHandler(priority=EventPriority.LOWEST) - public void onPlayerTeleport(PlayerTeleportEvent event) { - final Player player = event.getPlayer(); - if (plugin.getPlayerSitData().isSitting(player)) { - event.setCancelled(true); - } - } + @EventHandler(priority=EventPriority.LOWEST) + public void onPlayerTeleport(PlayerTeleportEvent event) { + final Player player = event.getPlayer(); + if (plugin.getPlayerSitData().isSitting(player)) { + event.setCancelled(true); + } + } - @EventHandler(priority=EventPriority.LOWEST) - public void onPlayerDeath(PlayerDeathEvent event) { - Player player = event.getEntity(); - if (plugin.getPlayerSitData().isSitting(player)) { - plugin.getPlayerSitData().unsitPlayerNow(player); - } - } + @EventHandler(priority=EventPriority.LOWEST) + public void onPlayerDeath(PlayerDeathEvent event) { + Player player = event.getEntity(); + if (plugin.getPlayerSitData().isSitting(player)) { + plugin.getPlayerSitData().unsitPlayerNow(player); + } + } - @EventHandler(priority=EventPriority.LOWEST) - public void onExitVehicle(VehicleExitEvent e) { - if (e.getVehicle().getPassenger() instanceof Player) { - final Player player = (Player) e.getVehicle().getPassenger(); - if (plugin.getPlayerSitData().isSitting(player)) { - plugin.getPlayerSitData().unsitPlayerNormal(player); - } - } - } + @EventHandler(priority=EventPriority.LOWEST) + public void onExitVehicle(VehicleExitEvent e) { + if (e.getVehicle().getPassenger() instanceof Player) { + final Player player = (Player) e.getVehicle().getPassenger(); + if (plugin.getPlayerSitData().isSitting(player)) { + plugin.getPlayerSitData().unsitPlayerNormal(player); + } + } + } - @EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true) - public void onBlockBreak(BlockBreakEvent event) { - Block b = event.getBlock(); - if (plugin.getPlayerSitData().isBlockOccupied(b)) { - Player player = plugin.getPlayerSitData().getPlayerOnChair(b); - plugin.getPlayerSitData().unsitPlayerForce(player); - } - } + @EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true) + public void onBlockBreak(BlockBreakEvent event) { + Block b = event.getBlock(); + if (plugin.getPlayerSitData().isBlockOccupied(b)) { + Player player = plugin.getPlayerSitData().getPlayerOnChair(b); + plugin.getPlayerSitData().unsitPlayerForce(player); + } + } } diff --git a/src/com/cnaude/chairs/sitaddons/ChairEffects.java b/src/com/cnaude/chairs/sitaddons/ChairEffects.java index 123ae79..7b12132 100644 --- a/src/com/cnaude/chairs/sitaddons/ChairEffects.java +++ b/src/com/cnaude/chairs/sitaddons/ChairEffects.java @@ -21,119 +21,119 @@ import com.cnaude.chairs.core.Chairs; */ public class ChairEffects { - private Chairs plugin; - private int healTaskID = -1; - private int pickupTaskID = -1; + private Chairs plugin; + private int healTaskID = -1; + private int pickupTaskID = -1; - public ChairEffects(Chairs plugin) { - this.plugin = plugin; - } + public ChairEffects(Chairs plugin) { + this.plugin = plugin; + } - public void startHealing() { - healEffectsTask(); - } + public void startHealing() { + healEffectsTask(); + } - public void cancelHealing() { - if (healTaskID != -1) { - plugin.getServer().getScheduler().cancelTask(healTaskID); - healTaskID = -1; - } - } + public void cancelHealing() { + if (healTaskID != -1) { + plugin.getServer().getScheduler().cancelTask(healTaskID); + healTaskID = -1; + } + } - public void restartHealing() { - cancelHealing(); - startHealing(); - } + public void restartHealing() { + cancelHealing(); + startHealing(); + } - private void healEffectsTask() { - healTaskID = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { - @Override - public void run() { - for (Player p : Bukkit.getOnlinePlayers()) { - if (plugin.getPlayerSitData().isSitting(p)) { - if (p.hasPermission("chairs.sit.health")) { - double pHealthPcnt = (p.getHealth()) / p.getMaxHealth() * 100d; - if ((pHealthPcnt < plugin.sitMaxHealth) && (p.getHealth() < p.getMaxHealth())) { - double newHealth = plugin.sitHealthPerInterval + p.getHealth(); - if (newHealth > p.getMaxHealth()) { - newHealth = p.getMaxHealth(); - } - p.setHealth(newHealth); - } - } - } - } - } - }, plugin.sitHealInterval, plugin.sitHealInterval); - } + private void healEffectsTask() { + healTaskID = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { + @Override + public void run() { + for (Player p : Bukkit.getOnlinePlayers()) { + if (plugin.getPlayerSitData().isSitting(p)) { + if (p.hasPermission("chairs.sit.health")) { + double pHealthPcnt = (p.getHealth()) / p.getMaxHealth() * 100d; + if ((pHealthPcnt < plugin.sitMaxHealth) && (p.getHealth() < p.getMaxHealth())) { + double newHealth = plugin.sitHealthPerInterval + p.getHealth(); + if (newHealth > p.getMaxHealth()) { + newHealth = p.getMaxHealth(); + } + p.setHealth(newHealth); + } + } + } + } + } + }, plugin.sitHealInterval, plugin.sitHealInterval); + } - public void startPickup() { - pickupEffectsTask(); - } + public void startPickup() { + pickupEffectsTask(); + } - public void cancelPickup() { - if (pickupTaskID != -1) { + public void cancelPickup() { + if (pickupTaskID != -1) { plugin.getServer().getScheduler().cancelTask(pickupTaskID); } - pickupTaskID = -1; - } + pickupTaskID = -1; + } - public void restartPickup() { - cancelPickup(); - startPickup(); - } + public void restartPickup() { + cancelPickup(); + startPickup(); + } - private void pickupEffectsTask() { - pickupTaskID = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { - @Override + private void pickupEffectsTask() { + pickupTaskID = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { + @Override public void run() { - for (Player p : Bukkit.getOnlinePlayers()) { - if (plugin.getPlayerSitData().isSitting(p)) { - for (Entity entity : p.getNearbyEntities(1, 2, 1)) { - if (entity instanceof Item) { - Item item = (Item) entity; - if (item.getPickupDelay() == 0) { - if (p.getInventory().firstEmpty() != -1) { - PlayerPickupItemEvent pickupevent = new PlayerPickupItemEvent(p, item, 0); - Bukkit.getPluginManager().callEvent(pickupevent); - if (!pickupevent.isCancelled()) { - p.getInventory().addItem(item.getItemStack()); - entity.remove(); - } - } - } - } else if (entity instanceof ExperienceOrb) { - ExperienceOrb eorb = (ExperienceOrb) entity; - int exptoadd = eorb.getExperience(); - while (exptoadd > 0) { - int localexptoadd = 0; - if (p.getExpToLevel() < exptoadd) { - localexptoadd = p.getExpToLevel(); - PlayerExpChangeEvent expchangeevent = new PlayerExpChangeEvent(p, localexptoadd); - Bukkit.getPluginManager().callEvent(expchangeevent); - p.giveExp(expchangeevent.getAmount()); - if (p.getExpToLevel() <= 0) { - PlayerLevelChangeEvent levelchangeevent = new PlayerLevelChangeEvent(p, p.getLevel(), p.getLevel()+1); - Bukkit.getPluginManager().callEvent(levelchangeevent); - p.setExp(0); - p.giveExpLevels(1); - } - } else { - localexptoadd = exptoadd; - PlayerExpChangeEvent expchangeevent = new PlayerExpChangeEvent(p, localexptoadd); - Bukkit.getPluginManager().callEvent(expchangeevent); - p.giveExp(expchangeevent.getAmount()); - } - exptoadd -= localexptoadd; - } - entity.remove(); - } - } - } - } - } - },0,1); - } + for (Player p : Bukkit.getOnlinePlayers()) { + if (plugin.getPlayerSitData().isSitting(p)) { + for (Entity entity : p.getNearbyEntities(1, 2, 1)) { + if (entity instanceof Item) { + Item item = (Item) entity; + if (item.getPickupDelay() == 0) { + if (p.getInventory().firstEmpty() != -1) { + PlayerPickupItemEvent pickupevent = new PlayerPickupItemEvent(p, item, 0); + Bukkit.getPluginManager().callEvent(pickupevent); + if (!pickupevent.isCancelled()) { + p.getInventory().addItem(item.getItemStack()); + entity.remove(); + } + } + } + } else if (entity instanceof ExperienceOrb) { + ExperienceOrb eorb = (ExperienceOrb) entity; + int exptoadd = eorb.getExperience(); + while (exptoadd > 0) { + int localexptoadd = 0; + if (p.getExpToLevel() < exptoadd) { + localexptoadd = p.getExpToLevel(); + PlayerExpChangeEvent expchangeevent = new PlayerExpChangeEvent(p, localexptoadd); + Bukkit.getPluginManager().callEvent(expchangeevent); + p.giveExp(expchangeevent.getAmount()); + if (p.getExpToLevel() <= 0) { + PlayerLevelChangeEvent levelchangeevent = new PlayerLevelChangeEvent(p, p.getLevel(), p.getLevel()+1); + Bukkit.getPluginManager().callEvent(levelchangeevent); + p.setExp(0); + p.giveExpLevels(1); + } + } else { + localexptoadd = exptoadd; + PlayerExpChangeEvent expchangeevent = new PlayerExpChangeEvent(p, localexptoadd); + Bukkit.getPluginManager().callEvent(expchangeevent); + p.giveExp(expchangeevent.getAmount()); + } + exptoadd -= localexptoadd; + } + entity.remove(); + } + } + } + } + } + },0,1); + } } diff --git a/src/com/cnaude/chairs/sitaddons/CommandRestrict.java b/src/com/cnaude/chairs/sitaddons/CommandRestrict.java index b04c817..53ebea4 100644 --- a/src/com/cnaude/chairs/sitaddons/CommandRestrict.java +++ b/src/com/cnaude/chairs/sitaddons/CommandRestrict.java @@ -15,33 +15,33 @@ public class CommandRestrict implements Listener { this.plugin = plugin; } - @EventHandler(priority=EventPriority.LOWEST) - public void onPlayerCommand(PlayerCommandPreprocessEvent event) - { - Player player = event.getPlayer(); - String playercommand = event.getMessage().toLowerCase(); - if (plugin.getPlayerSitData().isSitting(player)) - { + @EventHandler(priority=EventPriority.LOWEST) + public void onPlayerCommand(PlayerCommandPreprocessEvent event) + { + Player player = event.getPlayer(); + String playercommand = event.getMessage().toLowerCase(); + if (plugin.getPlayerSitData().isSitting(player)) + { if (plugin.sitDisableAllCommands) { event.setCancelled(true); player.sendMessage(plugin.msgCommandRestricted); return; } - for (String disabledCommand : plugin.sitDisabledCommands) - { - if (disabledCommand.startsWith(playercommand)) - { - String therest = playercommand.replace(disabledCommand, ""); - if (therest.isEmpty() || therest.startsWith(" ")) - { - event.setCancelled(true); - player.sendMessage(plugin.msgCommandRestricted); - return; - } - } - } - } - } + for (String disabledCommand : plugin.sitDisabledCommands) + { + if (disabledCommand.startsWith(playercommand)) + { + String therest = playercommand.replace(disabledCommand, ""); + if (therest.isEmpty() || therest.startsWith(" ")) + { + event.setCancelled(true); + player.sendMessage(plugin.msgCommandRestricted); + return; + } + } + } + } + } } diff --git a/src/com/cnaude/chairs/vehiclearrow/NMSAccess.java b/src/com/cnaude/chairs/vehiclearrow/NMSAccess.java index 099d158..e800037 100644 --- a/src/com/cnaude/chairs/vehiclearrow/NMSAccess.java +++ b/src/com/cnaude/chairs/vehiclearrow/NMSAccess.java @@ -12,24 +12,24 @@ import org.bukkit.entity.Arrow; public class NMSAccess { private Class nmsArrowClass; - + public void setupVehicleArrow() throws Exception { - String pkgname = getClass().getPackage().getName(); - String packageName = Bukkit.getServer().getClass().getPackage().getName(); - String nmspackageversion = packageName.substring(packageName.lastIndexOf('.') + 1); - switch (nmspackageversion) { - case "v1_7_R1": { - nmsArrowClass = Class.forName(pkgname+"."+"nms172"+".NMSChairsArrow"); - return; - } - case "v1_6_R3": { - nmsArrowClass = Class.forName(pkgname+"."+"nms164"+".NMSChairsArrow"); - return; - } - } - throw new Exception("ChairsReloaded is not compatible with your server version"); + String pkgname = getClass().getPackage().getName(); + String packageName = Bukkit.getServer().getClass().getPackage().getName(); + String nmspackageversion = packageName.substring(packageName.lastIndexOf('.') + 1); + switch (nmspackageversion) { + case "v1_7_R1": { + nmsArrowClass = Class.forName(pkgname+"."+"nms172"+".NMSChairsArrow"); + return; + } + case "v1_6_R3": { + nmsArrowClass = Class.forName(pkgname+"."+"nms164"+".NMSChairsArrow"); + return; + } + } + throw new Exception("ChairsReloaded is not compatible with your server version"); } - + public Arrow spawnArrow(Location location) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException { World world = location.getWorld(); Method getHandle = world.getClass().getDeclaredMethod("getHandle"); diff --git a/src/com/cnaude/chairs/vehiclearrow/NMSChairsArrowInterface.java b/src/com/cnaude/chairs/vehiclearrow/NMSChairsArrowInterface.java index 2c5aac8..1f9d308 100644 --- a/src/com/cnaude/chairs/vehiclearrow/NMSChairsArrowInterface.java +++ b/src/com/cnaude/chairs/vehiclearrow/NMSChairsArrowInterface.java @@ -7,11 +7,11 @@ import org.bukkit.entity.Arrow; public interface NMSChairsArrowInterface { public void setBukkitEntity(Server server); - + public Arrow getBukkitArrow(); - + public void setArrowLocation(Location location); - + public void addToWorld(); } diff --git a/src/com/cnaude/chairs/vehiclearrow/nms172/NMSChairsArrow.java b/src/com/cnaude/chairs/vehiclearrow/nms172/NMSChairsArrow.java index ceb9592..3409c69 100644 --- a/src/com/cnaude/chairs/vehiclearrow/nms172/NMSChairsArrow.java +++ b/src/com/cnaude/chairs/vehiclearrow/nms172/NMSChairsArrow.java @@ -1,5 +1,8 @@ package com.cnaude.chairs.vehiclearrow.nms172; +import net.minecraft.server.v1_7_R1.EntityArrow; +import net.minecraft.server.v1_7_R1.World; + import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.craftbukkit.v1_7_R1.CraftServer; @@ -7,19 +10,17 @@ import org.bukkit.entity.Arrow; import com.cnaude.chairs.vehiclearrow.NMSChairsArrowInterface; -import net.minecraft.server.v1_7_R1.EntityArrow; -import net.minecraft.server.v1_7_R1.World; - public class NMSChairsArrow extends EntityArrow implements NMSChairsArrowInterface { - + public NMSChairsArrow(World world) { super(world); } - + @Override public void h() { } + @Override public void setBukkitEntity(Server server) { bukkitEntity = new CraftChairsArrow((CraftServer) server, this); }