Clean up and reformat source
This commit is contained in:
@@ -13,16 +13,16 @@ import org.bukkit.Material;
|
||||
public class ChairBlock {
|
||||
private Material mat;
|
||||
private double sitHeight;
|
||||
|
||||
|
||||
public ChairBlock(Material m, double s) {
|
||||
mat = m;
|
||||
sitHeight = s;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Material getMat() {
|
||||
return mat;
|
||||
}
|
||||
|
||||
|
||||
public double getSitHeight() {
|
||||
return sitHeight;
|
||||
}
|
||||
|
@@ -44,16 +44,16 @@ public class Chairs extends JavaPlugin {
|
||||
public boolean sitDisableAllCommands = false;
|
||||
public HashSet<String> sitDisabledCommands = new HashSet<String>();
|
||||
private Logger log;
|
||||
public ChairsIgnoreList ignoreList;
|
||||
public ChairsIgnoreList ignoreList;
|
||||
public String msgSitting, msgStanding, msgOccupied, msgNoPerm, msgReloaded, msgDisabled, msgEnabled, msgCommandRestricted;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private PlayerSitData psitdata;
|
||||
public PlayerSitData getPlayerSitData()
|
||||
{
|
||||
return psitdata;
|
||||
}
|
||||
}
|
||||
private Class<?> vehiclearrowclass;
|
||||
protected Class<?> getVehicleArrowClass()
|
||||
{
|
||||
@@ -61,10 +61,10 @@ public class Chairs extends JavaPlugin {
|
||||
}
|
||||
|
||||
GetVehicleArrowClass genvehiclearrow = new GetVehicleArrowClass();
|
||||
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
log = this.getLogger();
|
||||
log = this.getLogger();
|
||||
//load vehiclearrowclass
|
||||
try {
|
||||
World world = getServer().getWorlds().get(0);
|
||||
@@ -104,7 +104,7 @@ public class Chairs extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
if (psitdata.isSitting(player)) {
|
||||
psitdata.unSitPlayer(player, false, true);
|
||||
}
|
||||
@@ -120,7 +120,7 @@ public class Chairs extends JavaPlugin {
|
||||
vehiclearrowclass = null;
|
||||
psitdata = null;
|
||||
}
|
||||
|
||||
|
||||
public void loadConfig() {
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(this.getDataFolder(),"config.yml"));
|
||||
autoRotate = config.getBoolean("auto-rotate");
|
||||
@@ -129,19 +129,19 @@ public class Chairs extends JavaPlugin {
|
||||
maxChairWidth = config.getInt("max-chair-width");
|
||||
notifyplayer = config.getBoolean("notify-player");
|
||||
ignoreIfBlockInHand = config.getBoolean("ignore-if-item-in-hand");
|
||||
|
||||
|
||||
disabledRegions = new HashSet<String>(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);
|
||||
|
||||
|
||||
sitPickupEnabled = config.getBoolean("sit-effects.itempickup.enabled", false);
|
||||
|
||||
|
||||
sitDisableAllCommands = config.getBoolean("sit-restrictions.commands.all");
|
||||
sitDisabledCommands = new HashSet<String>(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"));
|
||||
@@ -156,21 +156,21 @@ public class Chairs extends JavaPlugin {
|
||||
String type;
|
||||
double sh = 0.7;
|
||||
String tmp[] = s.split("[:]");
|
||||
type = tmp[0];
|
||||
type = tmp[0];
|
||||
if (tmp.length == 2) {
|
||||
sh = Double.parseDouble(tmp[1]);
|
||||
}
|
||||
}
|
||||
Material mat = Material.matchMaterial(type);
|
||||
if (mat != null) {
|
||||
if (mat != null) {
|
||||
logInfo("Allowed block: " + mat.toString() + " => " + sh);
|
||||
allowedBlocks.add(new ChairBlock(mat,sh));
|
||||
} else {
|
||||
logError("Invalid block: " + type);
|
||||
}
|
||||
}
|
||||
|
||||
validSigns = new ArrayList<Material>();
|
||||
for (String type : config.getStringList("valid-signs")) {
|
||||
|
||||
validSigns = new ArrayList<Material>();
|
||||
for (String type : config.getStringList("valid-signs")) {
|
||||
try {
|
||||
validSigns.add(Material.matchMaterial(type));
|
||||
}
|
||||
@@ -178,8 +178,8 @@ public class Chairs extends JavaPlugin {
|
||||
logError(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void logInfo(String _message) {
|
||||
log.log(Level.INFO, _message);
|
||||
}
|
||||
@@ -187,5 +187,5 @@ public class Chairs extends JavaPlugin {
|
||||
public void logError(String _message) {
|
||||
log.log(Level.SEVERE, _message);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -19,40 +19,32 @@ public class PlayerSitData {
|
||||
public PlayerSitData(Chairs plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
private HashMap<String, Entity> sit = new HashMap<String, Entity>();
|
||||
private HashMap<Block, String> sitblock = new HashMap<Block, String>();
|
||||
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,15 +60,13 @@ public class PlayerSitData {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public void startReSitTask(final Player player)
|
||||
{
|
||||
int task =
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
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);
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable()
|
||||
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,10 +128,9 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user