Clean up
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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<ChairBlock> allowedBlocks;
|
||||
public List<Material> validSigns;
|
||||
public boolean autoRotate, signCheck, notifyplayer;
|
||||
public boolean ignoreIfBlockInHand;
|
||||
public double distance;
|
||||
public HashSet<String> disabledRegions = new HashSet<String>();
|
||||
public int maxChairWidth;
|
||||
public boolean sitHealEnabled;
|
||||
public int sitMaxHealth;
|
||||
public int sitHealthPerInterval;
|
||||
public int sitHealInterval;
|
||||
public boolean sitPickupEnabled;
|
||||
public boolean sitDisableAllCommands = false;
|
||||
public HashSet<String> sitDisabledCommands = new HashSet<String>();
|
||||
private Logger log;
|
||||
public ChairsIgnoreList ignoreList;
|
||||
public String msgSitting, msgStanding, msgOccupied, msgNoPerm, msgReloaded, msgDisabled, msgEnabled, msgCommandRestricted;
|
||||
public ChairEffects chairEffects;
|
||||
public List<ChairBlock> allowedBlocks;
|
||||
public List<Material> validSigns;
|
||||
public boolean autoRotate, signCheck, notifyplayer;
|
||||
public boolean ignoreIfBlockInHand;
|
||||
public double distance;
|
||||
public HashSet<String> disabledRegions = new HashSet<String>();
|
||||
public int maxChairWidth;
|
||||
public boolean sitHealEnabled;
|
||||
public int sitMaxHealth;
|
||||
public int sitHealthPerInterval;
|
||||
public int sitHealInterval;
|
||||
public boolean sitPickupEnabled;
|
||||
public boolean sitDisableAllCommands = false;
|
||||
public HashSet<String> sitDisabledCommands = new HashSet<String>();
|
||||
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<String>(config.getStringList("disabledWGRegions"));
|
||||
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);
|
||||
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<String>(config.getStringList("sit-restrictions.commands.list"));
|
||||
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"));
|
||||
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<ChairBlock>();
|
||||
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<ChairBlock>();
|
||||
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<Material>();
|
||||
for (String type : config.getStringList("valid-signs")) {
|
||||
try {
|
||||
validSigns.add(Material.matchMaterial(type));
|
||||
}
|
||||
catch (Exception e) {
|
||||
logError(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
validSigns = new ArrayList<Material>();
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -14,5 +14,5 @@ public class ChairsAPI {
|
||||
public static boolean isSitting(Player player) {
|
||||
return pdata.isSitting(player);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user