Clean up and reformat source
This commit is contained in:
parent
ff38ead562
commit
9d231ca8b8
@ -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;
|
||||||
|
@ -25,34 +25,26 @@ public class PlayerSitData {
|
|||||||
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,13 +60,11 @@ 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);
|
||||||
@ -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,8 +128,7 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
@ -30,8 +31,7 @@ public class TrySitEventListener implements Listener {
|
|||||||
this.ignoreList = ignoreList;
|
this.ignoreList = ignoreList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
@EventHandler
|
|
||||||
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,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
|
// Check for permissions
|
||||||
if (!player.hasPermission("chairs.sit")) {
|
if (!player.hasPermission("chairs.sit")) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -25,52 +25,41 @@ public class TryUnsitEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@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);
|
||||||
}
|
}
|
||||||
@ -81,15 +70,12 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -70,8 +70,9 @@ public class ChairEffects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +83,8 @@ public class ChairEffects {
|
|||||||
|
|
||||||
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)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user