Clean up and reformat source
This commit is contained in:
parent
ff38ead562
commit
9d231ca8b8
@ -4,7 +4,12 @@
|
||||
*/
|
||||
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 com.cnaude.chairs.core.Chairs;
|
||||
|
@ -25,34 +25,26 @@ public class PlayerSitData {
|
||||
private HashMap<String, Block> sitblockbr = new HashMap<String, Block>();
|
||||
private HashMap<String, Location> sitstopteleportloc = new HashMap<String, Location>();
|
||||
private HashMap<String, Integer> sittask = new HashMap<String, Integer>();
|
||||
public boolean isSitting(Player player)
|
||||
{
|
||||
public boolean isSitting(Player player) {
|
||||
return sit.containsKey(player.getName());
|
||||
}
|
||||
public boolean isAroowOccupied(Entity entity)
|
||||
{
|
||||
for (Entity usedentity : sit.values())
|
||||
{
|
||||
if (usedentity.getEntityId() == entity.getEntityId())
|
||||
{
|
||||
public boolean isAroowOccupied(Entity entity) {
|
||||
for (Entity usedentity : sit.values()) {
|
||||
if (usedentity.getEntityId() == entity.getEntityId()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public boolean isBlockOccupied(Block block)
|
||||
{
|
||||
public boolean isBlockOccupied(Block block) {
|
||||
return sitblock.containsKey(block);
|
||||
}
|
||||
public Player getPlayerOnChair(Block chair)
|
||||
{
|
||||
public Player getPlayerOnChair(Block chair) {
|
||||
return Bukkit.getPlayerExact(sitblock.get(chair));
|
||||
}
|
||||
public void sitPlayer(Player player, Location sitlocation)
|
||||
{
|
||||
public void sitPlayer(Player player, Location sitlocation) {
|
||||
try {
|
||||
if (plugin.notifyplayer)
|
||||
{
|
||||
if (plugin.notifyplayer) {
|
||||
player.sendMessage(plugin.msgSitting);
|
||||
}
|
||||
Block block = sitlocation.getBlock();
|
||||
@ -68,13 +60,11 @@ public class PlayerSitData {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public void startReSitTask(final Player player)
|
||||
{
|
||||
public void startReSitTask(final Player player) {
|
||||
int task =
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
reSitPlayer(player);
|
||||
}
|
||||
},1000,1000);
|
||||
@ -90,10 +80,9 @@ public class PlayerSitData {
|
||||
Location arrowloc = block.getLocation().add(0.5, 0 , 0.5);
|
||||
Entity arrow = sitPlayerOnArrow(player, arrowloc);
|
||||
sit.put(player.getName(), arrow);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
prevarrow.remove();
|
||||
}
|
||||
},100);
|
||||
@ -101,8 +90,7 @@ public class PlayerSitData {
|
||||
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);
|
||||
Method getHandleMethod = arrow.getClass().getDeclaredMethod("getHandle");
|
||||
getHandleMethod.setAccessible(true);
|
||||
@ -116,25 +104,23 @@ public class PlayerSitData {
|
||||
arrow.setPassenger(player);
|
||||
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());
|
||||
sit.remove(player.getName());
|
||||
player.eject();
|
||||
arrow.remove();
|
||||
final Location tploc = sitstopteleportloc.get(player.getName());
|
||||
if (restoreposition)
|
||||
{
|
||||
if (restoreposition) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable()
|
||||
{
|
||||
public void run()
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
player.teleport(tploc);
|
||||
player.setSneaking(false);
|
||||
}
|
||||
},1);
|
||||
} else if (correctleaveposition)
|
||||
{
|
||||
} else if (correctleaveposition) {
|
||||
player.teleport(tploc);
|
||||
}
|
||||
sitblock.remove(sitblockbr.get(player.getName()));
|
||||
@ -142,8 +128,7 @@ public class PlayerSitData {
|
||||
sitstopteleportloc.remove(player.getName());
|
||||
Bukkit.getScheduler().cancelTask(sittask.get(player.getName()));
|
||||
sittask.remove(player.getName());
|
||||
if (plugin.notifyplayer)
|
||||
{
|
||||
if (plugin.notifyplayer) {
|
||||
player.sendMessage(plugin.msgStanding);
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
@ -30,8 +31,7 @@ public class TrySitEventListener implements Listener {
|
||||
this.ignoreList = ignoreList;
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
@ -44,8 +44,7 @@ public class TrySitEventListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean sitAllowed(Player player, Block block)
|
||||
{
|
||||
private boolean sitAllowed(Player player, Block block) {
|
||||
// Check for permissions
|
||||
if (!player.hasPermission("chairs.sit")) {
|
||||
return false;
|
||||
|
@ -25,52 +25,41 @@ public class TryUnsitEventListener implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler(priority=EventPriority.LOWEST)
|
||||
public void onPlayerQuit(PlayerQuitEvent event)
|
||||
{
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (plugin.getPlayerSitData().isSitting(player))
|
||||
{
|
||||
if (plugin.getPlayerSitData().isSitting(player)) {
|
||||
plugin.getPlayerSitData().unSitPlayer(player, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority=EventPriority.LOWEST)
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event)
|
||||
{
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
if (plugin.getPlayerSitData().isSitting(player))
|
||||
{
|
||||
if (plugin.getPlayerSitData().isSitting(player)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority=EventPriority.LOWEST)
|
||||
public void onPlayerDeath(PlayerDeathEvent event)
|
||||
{
|
||||
public void onPlayerDeath(PlayerDeathEvent event) {
|
||||
Player player = event.getEntity();
|
||||
if (plugin.getPlayerSitData().isSitting(player))
|
||||
{
|
||||
if (plugin.getPlayerSitData().isSitting(player)) {
|
||||
plugin.getPlayerSitData().unSitPlayer(player, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
private HashSet<String> queueUnsit = new HashSet<String>();
|
||||
@EventHandler(priority=EventPriority.LOWEST)
|
||||
public void onExitVehicle(VehicleExitEvent e)
|
||||
{
|
||||
if (e.getVehicle().getPassenger() instanceof Player)
|
||||
{
|
||||
public void onExitVehicle(VehicleExitEvent e) {
|
||||
if (e.getVehicle().getPassenger() instanceof Player) {
|
||||
final Player player = (Player) e.getVehicle().getPassenger();
|
||||
if (plugin.getPlayerSitData().isSitting(player))
|
||||
{
|
||||
if (plugin.getPlayerSitData().isSitting(player)) {
|
||||
e.setCancelled(true);
|
||||
if (!queueUnsit.contains(player.getName()))
|
||||
{
|
||||
if (!queueUnsit.contains(player.getName())) {
|
||||
queueUnsit.add(player.getName());
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
queueUnsit.remove(player.getName());
|
||||
plugin.getPlayerSitData().unSitPlayer(player, true, false);
|
||||
}
|
||||
@ -81,15 +70,12 @@ public class TryUnsitEventListener implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true)
|
||||
public void onBlockBreak(BlockBreakEvent event)
|
||||
{
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
Block b = event.getBlock();
|
||||
if (plugin.getPlayerSitData().isBlockOccupied(b))
|
||||
{
|
||||
if (plugin.getPlayerSitData().isBlockOccupied(b)) {
|
||||
Player player = plugin.getPlayerSitData().getPlayerOnChair(b);
|
||||
plugin.getPlayerSitData().unSitPlayer(player, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -70,8 +70,9 @@ public class ChairEffects {
|
||||
}
|
||||
|
||||
public void cancelPickup() {
|
||||
if (pickupTaskID != -1)
|
||||
plugin.getServer().getScheduler().cancelTask(pickupTaskID);
|
||||
if (pickupTaskID != -1) {
|
||||
plugin.getServer().getScheduler().cancelTask(pickupTaskID);
|
||||
}
|
||||
pickupTaskID = -1;
|
||||
}
|
||||
|
||||
@ -82,7 +83,8 @@ public class ChairEffects {
|
||||
|
||||
private void pickupEffectsTask() {
|
||||
pickupTaskID = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (plugin.getPlayerSitData().isSitting(p)) {
|
||||
for (Entity entity : p.getNearbyEntities(1, 2, 1)) {
|
||||
|
Loading…
Reference in New Issue
Block a user