Updates .jar to 1.18, fixes formatting and fixes some warnings
This commit is contained in:
@@ -33,53 +33,55 @@ import java.util.UUID;
|
||||
* @since 2.x.x
|
||||
*/
|
||||
public class JailIO {
|
||||
private final JailMain pl;
|
||||
|
||||
private final JailMain jailMain;
|
||||
private FileConfiguration flat, records;
|
||||
private Connection con;
|
||||
private Connection connection;
|
||||
private int storage = -1; //0 = flatfile, 1 = sqlite, 2 = mysql
|
||||
private String prefix;
|
||||
private boolean changed = false;
|
||||
|
||||
protected JailIO(JailMain plugin) {
|
||||
this.pl = plugin;
|
||||
this.jailMain = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the language file from disk, if there is none then we save the default one.
|
||||
*/
|
||||
protected void loadLanguage() {
|
||||
String language = pl.getConfig().getString(Settings.LANGUAGE.getPath());
|
||||
String language = jailMain.getConfig().getString(Settings.LANGUAGE.getPath());
|
||||
boolean save = false;
|
||||
File langFile = new File(pl.getDataFolder() + File.separator + "locales", language + ".yml");
|
||||
File langFile = new File(jailMain.getDataFolder() + File.separator + "locales", language + ".yml");
|
||||
|
||||
//File or folder already exists, let's check
|
||||
if (langFile.exists()) {
|
||||
if (langFile.isFile()) {
|
||||
Lang.setFile(YamlConfiguration.loadConfiguration(langFile));
|
||||
pl.getLogger().info("Loaded the language: " + language);
|
||||
jailMain.getLogger().info("Loaded the language: " + language);
|
||||
} else {
|
||||
pl.getLogger().severe("The language file can not be a folder.");
|
||||
pl.getLogger().severe("As a result, we are reverting back to English as the language.");
|
||||
Lang.setFile(YamlConfiguration.loadConfiguration(new InputStreamReader(pl.getResource("locales/en.yml"))));
|
||||
jailMain.getLogger().severe("The language file can not be a folder.");
|
||||
jailMain.getLogger().severe("As a result, we are reverting back to English as the language.");
|
||||
Lang.setFile(YamlConfiguration.loadConfiguration(new InputStreamReader(jailMain.getResource("locales/en.yml"))));
|
||||
save = true;
|
||||
}
|
||||
} else {
|
||||
pl.getLogger().warning("Loading the default language of: en");
|
||||
pl.getLogger().warning("If you wish to change this, please rename 'en.yml' to whatever you wish and set the config value to the name of the file.");
|
||||
Lang.setFile(YamlConfiguration.loadConfiguration(new InputStreamReader(pl.getResource("locales/en.yml"))));
|
||||
jailMain.getLogger().warning("Loading the default language of: en");
|
||||
jailMain.getLogger().warning("If you wish to change this, please rename 'en.yml' to whatever you wish and set the config value to the name of the file.");
|
||||
Lang.setFile(YamlConfiguration.loadConfiguration(new InputStreamReader(jailMain.getResource("locales/en.yml"))));
|
||||
save = true;
|
||||
}
|
||||
|
||||
//Make sure we have all the new language settings loaded
|
||||
if (!save)
|
||||
save = Lang.writeNewLanguage(YamlConfiguration.loadConfiguration(new InputStreamReader(pl.getResource("locales/en.yml"))));
|
||||
if (!save) {
|
||||
save = Lang.writeNewLanguage(YamlConfiguration.loadConfiguration(new InputStreamReader(jailMain.getResource("locales/en.yml"))));
|
||||
}
|
||||
|
||||
//If we have flagged to save the language file, let's save it as en.yml as this flag usually means they didn't have it loaded.
|
||||
if (save) {
|
||||
try {
|
||||
Lang.getFile().save(new File(pl.getDataFolder() + File.separator + "locales", "en.yml"));
|
||||
Lang.getFile().save(new File(jailMain.getDataFolder() + File.separator + "locales", "en.yml"));
|
||||
} catch (IOException e) {
|
||||
pl.getLogger().severe("Unable to save the language file: " + e.getMessage() + " (" + e.getClass().getSimpleName() + ")");
|
||||
jailMain.getLogger().severe("Unable to save the language file: " + e.getMessage() + " (" + e.getClass().getSimpleName() + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,13 +95,13 @@ public class JailIO {
|
||||
protected boolean prepareStorage(boolean doInitialCreations) {
|
||||
int inital = storage == -1 ? -1 : storage;
|
||||
|
||||
String st = pl.getConfig().getString("storage.type", "flatfile");
|
||||
String st = jailMain.getConfig().getString("storage.type", "flatfile");
|
||||
if (st.equalsIgnoreCase("sqlite")) {
|
||||
storage = 1;
|
||||
prefix = pl.getConfig().getString("storage.mysql.prefix");
|
||||
prefix = jailMain.getConfig().getString("storage.mysql.prefix");
|
||||
} else if (st.equalsIgnoreCase("mysql")) {
|
||||
storage = 2;
|
||||
prefix = pl.getConfig().getString("storage.mysql.prefix");
|
||||
prefix = jailMain.getConfig().getString("storage.mysql.prefix");
|
||||
} else {
|
||||
storage = 0;
|
||||
}
|
||||
@@ -108,33 +110,37 @@ public class JailIO {
|
||||
//this way we can know whether to save EVERYTHING
|
||||
//or not afterwards
|
||||
if (inital != -1 && inital != storage) {
|
||||
pl.debug("We changed storage types! We used to be " + inital + " and changed to " + storage + ".");
|
||||
jailMain.debug("We changed storage types! We used to be " + inital + " and changed to " + storage + ".");
|
||||
changed = true;
|
||||
}
|
||||
|
||||
pl.debug("The storage type " + st + " with the type being " + storage + ".");
|
||||
if (!pl.inDebug()) pl.getLogger().info("Storage type selected: " + st);
|
||||
jailMain.debug("The storage type " + st + " with the type being " + storage + ".");
|
||||
if (!jailMain.inDebug()) {
|
||||
jailMain.getLogger().info("Storage type selected: " + st);
|
||||
}
|
||||
|
||||
switch (storage) {
|
||||
case 1:
|
||||
try {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
pl.getLogger().info("Connecting to the sqlite database.");
|
||||
Connection sqliteConnection = DriverManager.getConnection("jdbc:sqlite:" + new File(pl.getDataFolder().getPath(), "jail3.sqlite").getPath());
|
||||
jailMain.getLogger().info("Connecting to the sqlite database.");
|
||||
Connection sqliteConnection = DriverManager.getConnection("jdbc:sqlite:" + new File(jailMain.getDataFolder().getPath(), "jail3.sqlite").getPath());
|
||||
sqliteConnection.setAutoCommit(true);
|
||||
this.con = sqliteConnection;
|
||||
pl.debug("Connection created for sqlite.");
|
||||
this.connection = sqliteConnection;
|
||||
jailMain.debug("Connection created for sqlite.");
|
||||
|
||||
if (doInitialCreations) createTables();
|
||||
if (doInitialCreations) {
|
||||
createTables();
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
pl.getLogger().severe("Sqlite driver not found, disabling the plugin.");
|
||||
jailMain.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
jailMain.getLogger().severe("Sqlite driver not found, disabling the plugin.");
|
||||
return false;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
pl.getLogger().severe("Unable to connect to the sqlite database, please update your config accordingly.");
|
||||
jailMain.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
jailMain.getLogger().severe("Unable to connect to the sqlite database, please update your config accordingly.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -142,31 +148,33 @@ public class JailIO {
|
||||
case 2:
|
||||
try {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
pl.getLogger().info("Connecting to the MySQL database.");
|
||||
Connection mysqlConnection = DriverManager.getConnection("jdbc:mysql://" + pl.getConfig().getString("storage.mysql.host") + ":"
|
||||
+ pl.getConfig().getString("storage.mysql.port") + "/"
|
||||
+ pl.getConfig().getString("storage.mysql.database"), pl.getConfig().getString("storage.mysql.username"), pl.getConfig().getString("storage.mysql.password"));
|
||||
jailMain.getLogger().info("Connecting to the MySQL database.");
|
||||
Connection mysqlConnection = DriverManager.getConnection("jdbc:mysql://" + jailMain.getConfig().getString("storage.mysql.host") + ":"
|
||||
+ jailMain.getConfig().getString("storage.mysql.port") + "/"
|
||||
+ jailMain.getConfig().getString("storage.mysql.database"), jailMain.getConfig().getString("storage.mysql.username"), jailMain.getConfig().getString("storage.mysql.password"));
|
||||
mysqlConnection.setAutoCommit(true);
|
||||
this.con = mysqlConnection;
|
||||
pl.debug("Connection created for MySQL.");
|
||||
this.connection = mysqlConnection;
|
||||
jailMain.debug("Connection created for MySQL.");
|
||||
|
||||
if (doInitialCreations) createTables();
|
||||
if (doInitialCreations) {
|
||||
createTables();
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
pl.getLogger().severe("MySQL driver not found, disabling the plugin.");
|
||||
jailMain.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
jailMain.getLogger().severe("MySQL driver not found, disabling the plugin.");
|
||||
return false;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
pl.getLogger().severe("Unable to connect to the MySQL database, please update your config accordingly.");
|
||||
jailMain.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
jailMain.getLogger().severe("Unable to connect to the MySQL database, please update your config accordingly.");
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
flat = YamlConfiguration.loadConfiguration(new File(pl.getDataFolder(), "data.yml"));
|
||||
records = YamlConfiguration.loadConfiguration(new File(pl.getDataFolder(), "records.yml"));
|
||||
flat = YamlConfiguration.loadConfiguration(new File(jailMain.getDataFolder(), "data.yml"));
|
||||
records = YamlConfiguration.loadConfiguration(new File(jailMain.getDataFolder(), "records.yml"));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -186,27 +194,35 @@ public class JailIO {
|
||||
private Connection getConnection() {
|
||||
switch (storage) {
|
||||
case 1:
|
||||
if (con == null) this.prepareStorage(false);
|
||||
if (connection == null) {
|
||||
this.prepareStorage(false);
|
||||
}
|
||||
try {
|
||||
if (con.isClosed()) this.prepareStorage(false);
|
||||
if (connection.isClosed()) {
|
||||
this.prepareStorage(false);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
pl.getLogger().severe("Unable to get a SQLite connection, please see the error above and fix the problem.");
|
||||
jailMain.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
jailMain.getLogger().severe("Unable to get a SQLite connection, please see the error above and fix the problem.");
|
||||
return null;
|
||||
}
|
||||
return con;
|
||||
return connection;
|
||||
case 2:
|
||||
if (con == null) this.prepareStorage(false);
|
||||
if (connection == null) {
|
||||
this.prepareStorage(false);
|
||||
}
|
||||
try {
|
||||
if (con.isClosed() || !con.isValid(10)) this.prepareStorage(false);
|
||||
if (connection.isClosed() || !connection.isValid(10)) {
|
||||
this.prepareStorage(false);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
pl.getLogger().severe("Unable to get a MySql connection, please see the error above and fix the problem.");
|
||||
jailMain.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
jailMain.getLogger().severe("Unable to get a MySql connection, please see the error above and fix the problem.");
|
||||
return null;
|
||||
}
|
||||
return con;
|
||||
return connection;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@@ -220,16 +236,16 @@ public class JailIO {
|
||||
case 1:
|
||||
case 2:
|
||||
try {
|
||||
if (con != null) {
|
||||
con.close();
|
||||
con = null;
|
||||
if (connection != null) {
|
||||
connection.close();
|
||||
connection = null;
|
||||
|
||||
pl.debug("Closed the SQL connection.");
|
||||
jailMain.debug("Closed the SQL connection.");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
pl.getLogger().severe("Unable to close the SQL connection.");
|
||||
jailMain.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
jailMain.getLogger().severe("Unable to close the SQL connection.");
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -240,7 +256,7 @@ public class JailIO {
|
||||
|
||||
private void createTables() {
|
||||
if (getConnection() == null) {
|
||||
pl.debug("The connection was null when we tried to create a table.");
|
||||
jailMain.debug("The connection was null when we tried to create a table.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -412,8 +428,8 @@ public class JailIO {
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
pl.getLogger().severe("Error while creating the tables, please check the error and fix what is wrong.");
|
||||
jailMain.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
jailMain.getLogger().severe("Error while creating the tables, please check the error and fix what is wrong.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -432,27 +448,27 @@ public class JailIO {
|
||||
ResultSet set = ps.executeQuery();
|
||||
|
||||
while (set.next()) {
|
||||
Jail j = new Jail(pl, set.getString("name"));
|
||||
Jail j = new Jail(jailMain, set.getString("name"));
|
||||
|
||||
j.setWorld(set.getString("world"));
|
||||
j.setMaxPoint(new int[]{set.getInt("top.x"), set.getInt("top.y"), set.getInt("top.z")});
|
||||
j.setMinPoint(new int[]{set.getInt("bottom.x"), set.getInt("bottom.y"), set.getInt("bottom.z")});
|
||||
j.setTeleportIn(new Location(pl.getServer().getWorld(j.getWorldName()), set.getDouble("tps.in.x"),
|
||||
j.setTeleportIn(new Location(jailMain.getServer().getWorld(j.getWorldName()), set.getDouble("tps.in.x"),
|
||||
set.getDouble("tps.in.y"), set.getDouble("tps.in.z"),
|
||||
set.getFloat("tps.in.yaw"), set.getFloat("tps.in.pitch")));
|
||||
j.setTeleportFree(new Location(pl.getServer().getWorld(j.getWorldName()), set.getDouble("tps.free.x"),
|
||||
j.setTeleportFree(new Location(jailMain.getServer().getWorld(j.getWorldName()), set.getDouble("tps.free.x"),
|
||||
set.getDouble("tps.free.y"), set.getDouble("tps.free.z"),
|
||||
set.getFloat("tps.free.yaw"), set.getFloat("tps.free.pitch")));
|
||||
j.setEnabled(j.getWorld() != null);
|
||||
pl.getJailManager().addJail(j, false);
|
||||
jailMain.getJailManager().addJail(j, false);
|
||||
}
|
||||
|
||||
set.close();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
pl.getLogger().severe("Error while loading the jails, please check the error and fix what is wrong.");
|
||||
jailMain.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
jailMain.getLogger().severe("Error while loading the jails, please check the error and fix what is wrong.");
|
||||
}
|
||||
|
||||
//This list contains an integer which refers to the cellid column in sql
|
||||
@@ -465,7 +481,7 @@ public class JailIO {
|
||||
ResultSet set = ps.executeQuery();
|
||||
|
||||
while (set.next()) {
|
||||
Jail j = pl.getJailManager().getJail(set.getString("jail"));
|
||||
Jail j = jailMain.getJailManager().getJail(set.getString("jail"));
|
||||
|
||||
if (j != null) {
|
||||
if (j.getWorld() != null) {
|
||||
@@ -494,46 +510,49 @@ public class JailIO {
|
||||
if (!j.addCell(c, false)) {
|
||||
int id = set.getInt("cellid");
|
||||
cellsToRemove.add(id);
|
||||
pl.debug("The cell, " + c.getName() + " (" + id + "), is already in jail " + j.getName() + " so we're removing it.");
|
||||
jailMain.debug("The cell, " + c.getName() + " (" + id + "), is already in jail " + j.getName() + " so we're removing it.");
|
||||
}
|
||||
} else {
|
||||
pl.getLogger().warning("The cell, " + set.getString("name") + ", in " + j.getName() + " is located in a world that is not loaded.");
|
||||
jailMain.getLogger().warning("The cell, " + set.getString("name") + ", in " + j.getName() + " is located in a world that is not loaded.");
|
||||
}
|
||||
} else {
|
||||
cellsToRemove.add(set.getInt("cellid"));
|
||||
}
|
||||
}
|
||||
|
||||
pl.debug("There are " + cellsToRemove.size() + " cells we need to remove due to being invalid.");
|
||||
jailMain.debug("There are " + cellsToRemove.size() + " cells we need to remove due to being invalid.");
|
||||
|
||||
set.close();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
pl.getLogger().severe("Error while loading all of the cells, please check the error and fix what is wrong.");
|
||||
jailMain.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
jailMain.getLogger().severe("Error while loading all of the cells, please check the error and fix what is wrong.");
|
||||
}
|
||||
|
||||
//Remove the invalid prisoners
|
||||
if (!cellsToRemove.isEmpty()) {
|
||||
StringBuilder ids = new StringBuilder();
|
||||
for (int c : cellsToRemove) {
|
||||
if (ids.length() == 0) ids.append("'").append(c).append("'");
|
||||
else ids.append("," + "'").append(c).append("'");
|
||||
if (ids.length() == 0) {
|
||||
ids.append("'").append(c).append("'");
|
||||
} else {
|
||||
ids.append("," + "'").append(c).append("'");
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
PreparedStatement cds = getConnection().prepareStatement("delete from " + prefix + "cells where cellid in (" + ids + ");");
|
||||
|
||||
pl.debug("Deleting old cells: `delete from " + prefix + "cells where cellid in (" + ids + ");`");
|
||||
jailMain.debug("Deleting old cells: `delete from " + prefix + "cells where cellid in (" + ids + ");`");
|
||||
|
||||
int count = cds.executeUpdate();
|
||||
pl.getLogger().info("Deleted " + count + " cells which were invalid, they either referenced a jail which are no longer valid or were duplicates.");
|
||||
jailMain.getLogger().info("Deleted " + count + " cells which were invalid, they either referenced a jail which are no longer valid or were duplicates.");
|
||||
cds.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
pl.getLogger().severe("Error while deleting the old cells which were invalid (they either referenced a jail which are no longer valid or were duplicates), please check the error and fix what is wrong.");
|
||||
jailMain.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
jailMain.getLogger().severe("Error while deleting the old cells which were invalid (they either referenced a jail which are no longer valid or were duplicates), please check the error and fix what is wrong.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -547,7 +566,7 @@ public class JailIO {
|
||||
ResultSet set = ps.executeQuery();
|
||||
|
||||
while (set.next()) {
|
||||
Jail j = pl.getJailManager().getJail(set.getString("jail"));
|
||||
Jail j = jailMain.getJailManager().getJail(set.getString("jail"));
|
||||
|
||||
if (j != null) {
|
||||
String cellname = set.getString("cell");
|
||||
@@ -580,37 +599,40 @@ public class JailIO {
|
||||
set.close();
|
||||
ps.close();
|
||||
|
||||
pl.debug("There are " + prisonersToRemove.size() + " prisoners we need to remove due to being invalid.");
|
||||
jailMain.debug("There are " + prisonersToRemove.size() + " prisoners we need to remove due to being invalid.");
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
pl.getLogger().severe("Error while loading all of the prisoners, please check the error and fix what is wrong.");
|
||||
jailMain.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
jailMain.getLogger().severe("Error while loading all of the prisoners, please check the error and fix what is wrong.");
|
||||
}
|
||||
|
||||
//Remove the invalid prisoners
|
||||
if (!prisonersToRemove.isEmpty()) {
|
||||
StringBuilder names = new StringBuilder();
|
||||
for (String s : prisonersToRemove) {
|
||||
if (names.length() == 0) names = new StringBuilder("'" + s + "'");
|
||||
else names.append("," + "'").append(s).append("'");
|
||||
if (names.length() == 0) {
|
||||
names = new StringBuilder("'" + s + "'");
|
||||
} else {
|
||||
names.append("," + "'").append(s).append("'");
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
PreparedStatement pds = getConnection().prepareStatement("delete from " + prefix + "prisoners where name in (" + names + ");");
|
||||
|
||||
pl.debug("Deleting old prisoners: 'delete from " + prefix + "prisoners where name in (" + names + ");'");
|
||||
jailMain.debug("Deleting old prisoners: 'delete from " + prefix + "prisoners where name in (" + names + ");'");
|
||||
|
||||
int count = pds.executeUpdate();
|
||||
pl.getLogger().info("Deleted " + count + " old prisoners which referenced a jail no longer valid: " + names);
|
||||
jailMain.getLogger().info("Deleted " + count + " old prisoners which referenced a jail no longer valid: " + names);
|
||||
pds.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
pl.getLogger().severe("Error while deleting the old prisoners which don't have a valid jail, please check the error and fix what is wrong.");
|
||||
jailMain.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
jailMain.getLogger().severe("Error while deleting the old prisoners which don't have a valid jail, please check the error and fix what is wrong.");
|
||||
}
|
||||
}
|
||||
|
||||
pl.debug("Took " + (System.currentTimeMillis() - st) + " millis to load the jails and all the data.");
|
||||
jailMain.debug("Took " + (System.currentTimeMillis() - st) + " millis to load the jails and all the data.");
|
||||
break;
|
||||
default:
|
||||
//load the jails from flatfile
|
||||
@@ -625,24 +647,24 @@ public class JailIO {
|
||||
break;
|
||||
}
|
||||
|
||||
int js = pl.getJailManager().getJails().size();
|
||||
pl.getLogger().info("Loaded " + js + (js == 1 ? " jail." : " jails."));
|
||||
int js = jailMain.getJailManager().getJails().size();
|
||||
jailMain.getLogger().info("Loaded " + js + (js == 1 ? " jail." : " jails."));
|
||||
|
||||
int cs = pl.getJailManager().getAllCells().size();
|
||||
pl.getLogger().info("Loaded " + cs + (cs == 1 ? " cell." : " cells."));
|
||||
int cs = jailMain.getJailManager().getAllCells().size();
|
||||
jailMain.getLogger().info("Loaded " + cs + (cs == 1 ? " cell." : " cells."));
|
||||
|
||||
int ps = pl.getJailManager().getAllPrisoners().size();
|
||||
pl.getLogger().info("Loaded " + ps + (ps == 1 ? " prisoner." : " prisoners."));
|
||||
int ps = jailMain.getJailManager().getAllPrisoners().size();
|
||||
jailMain.getLogger().info("Loaded " + ps + (ps == 1 ? " prisoner." : " prisoners."));
|
||||
}
|
||||
|
||||
private void loadJailFromFlatFile(String name) {
|
||||
String node = "jails." + name + ".";
|
||||
String cNode = node + "cells.";
|
||||
pl.debug("Loading the jail " + name + "; " + node + "; " + cNode);
|
||||
Jail j = new Jail(pl, name);
|
||||
jailMain.debug("Loading the jail " + name + "; " + node + "; " + cNode);
|
||||
Jail j = new Jail(jailMain, name);
|
||||
|
||||
if (flat.getString(node + "world") == null || flat.getString(node + "world").isEmpty()) {
|
||||
pl.getLogger().severe("Failed to load the jail, " + name + ", because the world is not set.");
|
||||
jailMain.getLogger().severe("Failed to load the jail, " + name + ", because the world is not set.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -651,14 +673,14 @@ public class JailIO {
|
||||
j.setMinPoint(new int[]{flat.getInt(node + "bottom.x"), flat.getInt(node + "bottom.y"), flat.getInt(node + "bottom.z")});
|
||||
|
||||
j.setTeleportIn(new Location(
|
||||
pl.getServer().getWorld(j.getWorldName()),
|
||||
jailMain.getServer().getWorld(j.getWorldName()),
|
||||
flat.getDouble(node + "tps.in.x"),
|
||||
flat.getDouble(node + "tps.in.y"),
|
||||
flat.getDouble(node + "tps.in.z"),
|
||||
(float) flat.getDouble(node + "tps.in.yaw"),
|
||||
(float) flat.getDouble(node + "tps.in.pitch")));
|
||||
j.setTeleportFree(new Location(
|
||||
pl.getServer().getWorld(flat.getString(node + "tps.free.world")),
|
||||
jailMain.getServer().getWorld(flat.getString(node + "tps.free.world")),
|
||||
flat.getDouble(node + "tps.free.x"),
|
||||
flat.getDouble(node + "tps.free.y"),
|
||||
flat.getDouble(node + "tps.free.z"),
|
||||
@@ -740,8 +762,8 @@ public class JailIO {
|
||||
}
|
||||
|
||||
j.setEnabled(j.getWorld() != null);
|
||||
pl.getJailManager().addJail(j, false);
|
||||
pl.getLogger().info("Loaded jail " + j.getName() + " with " + j.getAllPrisoners().size() + " prisoners and " + j.getCellCount() + " cells" + (j.isEnabled() ? "." : " but the jail is disabled as the world doesn't exist or isn't loaded."));
|
||||
jailMain.getJailManager().addJail(j, false);
|
||||
jailMain.getLogger().info("Loaded jail " + j.getName() + " with " + j.getAllPrisoners().size() + " prisoners and " + j.getCellCount() + " cells" + (j.isEnabled() ? "." : " but the jail is disabled as the world doesn't exist or isn't loaded."));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -750,7 +772,7 @@ public class JailIO {
|
||||
protected void saveEverything() {
|
||||
long st = System.currentTimeMillis();
|
||||
|
||||
for (Jail j : pl.getJailManager().getJails()) {
|
||||
for (Jail j : jailMain.getJailManager().getJails()) {
|
||||
saveJail(j);
|
||||
|
||||
//Only save the cells individually
|
||||
@@ -762,7 +784,7 @@ public class JailIO {
|
||||
}
|
||||
}
|
||||
|
||||
pl.debug("Saving everything took " + (System.currentTimeMillis() - st) + " millis.");
|
||||
jailMain.debug("Saving everything took " + (System.currentTimeMillis() - st) + " millis.");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -808,14 +830,15 @@ public class JailIO {
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
pl.getLogger().severe("Error while saving the Jail '" + j.getName() + "' (not updating the prisoners), please check the error and fix what is wrong.");
|
||||
jailMain.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
jailMain.getLogger().severe("Error while saving the Jail '" + j.getName() + "' (not updating the prisoners), please check the error and fix what is wrong.");
|
||||
}
|
||||
|
||||
try {
|
||||
for (Cell c : j.getCells()) {
|
||||
if (c.getDatabaseID() != -1)
|
||||
if (c.getDatabaseID() != -1) {
|
||||
saveCell(j, c, false);
|
||||
}
|
||||
|
||||
if (c.hasPrisoner() && c.getPrisoner().wasChanged()) {
|
||||
Prisoner p = c.getPrisoner();
|
||||
@@ -845,8 +868,8 @@ public class JailIO {
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
pl.getLogger().severe("Error while saving the cells of the Jail '" + j.getName() + "', please check the error and fix what is wrong.");
|
||||
jailMain.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
jailMain.getLogger().severe("Error while saving the cells of the Jail '" + j.getName() + "', please check the error and fix what is wrong.");
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -876,11 +899,11 @@ public class JailIO {
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
pl.getLogger().severe("Error while saving the prisoners of the Jail '" + j.getName() + "', please check the error and fix what is wrong.");
|
||||
jailMain.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
jailMain.getLogger().severe("Error while saving the prisoners of the Jail '" + j.getName() + "', please check the error and fix what is wrong.");
|
||||
}
|
||||
|
||||
pl.debug("Took " + (System.currentTimeMillis() - st) + " millis to save the jail " + j.getName() + ".");
|
||||
jailMain.debug("Took " + (System.currentTimeMillis() - st) + " millis to save the jail " + j.getName() + ".");
|
||||
break;
|
||||
default:
|
||||
if (flat != null) {
|
||||
@@ -950,10 +973,12 @@ public class JailIO {
|
||||
flat.set(cNode + "prisoner.reason", p.getReason());
|
||||
flat.set(cNode + "prisoner.inventory", p.getInventory());
|
||||
flat.set(cNode + "prisoner.armor", p.getArmor());
|
||||
if (p.getPreviousLocationString() != null)
|
||||
if (p.getPreviousLocationString() != null) {
|
||||
flat.set(cNode + "prisoner.previousLocation", p.getPreviousLocationString());
|
||||
if (p.getPreviousGameMode() != null)
|
||||
}
|
||||
if (p.getPreviousGameMode() != null) {
|
||||
flat.set(cNode + "prisoner.previousGameMode", p.getPreviousGameMode().toString());
|
||||
}
|
||||
}
|
||||
|
||||
c.setChanged(false);
|
||||
@@ -972,19 +997,21 @@ public class JailIO {
|
||||
flat.set(pNode + "reason", p.getReason());
|
||||
flat.set(pNode + "inventory", p.getInventory());
|
||||
flat.set(pNode + "armor", p.getArmor());
|
||||
if (p.getPreviousLocationString() != null)
|
||||
if (p.getPreviousLocationString() != null) {
|
||||
flat.set(pNode + "previousLocation", p.getPreviousLocationString());
|
||||
if (p.getPreviousGameMode() != null)
|
||||
}
|
||||
if (p.getPreviousGameMode() != null) {
|
||||
flat.set(pNode + "previousGameMode", p.getPreviousGameMode().toString());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
flat.save(new File(pl.getDataFolder(), "data.yml"));
|
||||
flat.save(new File(jailMain.getDataFolder(), "data.yml"));
|
||||
} catch (IOException e) {
|
||||
pl.getLogger().severe("Unable to save the Jail data: " + e.getMessage());
|
||||
jailMain.getLogger().severe("Unable to save the Jail data: " + e.getMessage());
|
||||
}
|
||||
} else {
|
||||
pl.getLogger().severe("Storage not enabled, could not save the jail " + j.getName());
|
||||
jailMain.getLogger().severe("Storage not enabled, could not save the jail " + j.getName());
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -994,7 +1021,9 @@ public class JailIO {
|
||||
public void saveCell(Jail j, Cell c, boolean force) {
|
||||
//if the cell hasn't changed, no need to save it again
|
||||
//unless they're forcing the save
|
||||
if (!c.hasChanged() && !force) return;
|
||||
if (!c.hasChanged() && !force) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (storage) {
|
||||
case 1:
|
||||
@@ -1005,7 +1034,7 @@ public class JailIO {
|
||||
break;
|
||||
}
|
||||
|
||||
pl.debug("Saving the cell " + c.getName());
|
||||
jailMain.debug("Saving the cell " + c.getName());
|
||||
boolean hasId = c.getDatabaseID() != -1;
|
||||
|
||||
PreparedStatement cPS = con.prepareStatement((hasId ? "REPLACE" : "INSERT")
|
||||
@@ -1061,8 +1090,8 @@ public class JailIO {
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
pl.getLogger().severe("Error while saving the cell '" + c.getName() + "' of the Jail '" + j.getName() + "', please check the error and fix what is wrong.");
|
||||
jailMain.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
jailMain.getLogger().severe("Error while saving the cell '" + c.getName() + "' of the Jail '" + j.getName() + "', please check the error and fix what is wrong.");
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -1104,26 +1133,27 @@ public class JailIO {
|
||||
PreparedStatement pp = con.prepareStatement("delete from `" + prefix + "prisoners` where uuid = ?");
|
||||
pp.setString(1, p.getUUID().toString());
|
||||
|
||||
pl.debug("Removing " + p.getLastKnownName() + " (" + p.getUUID().toString() + ") from " + (storage == 2 ? "MySQL" : "SQLite") + " database.");
|
||||
jailMain.debug("Removing " + p.getLastKnownName() + " (" + p.getUUID().toString() + ") from " + (storage == 2 ? "MySQL" : "SQLite") + " database.");
|
||||
|
||||
pp.executeUpdate();
|
||||
pp.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
pl.getLogger().severe("Error while removing the prisoner '" + p.getLastKnownName() + "' (" + p.getUUID().toString() + ") from the database, please check the error and fix what is wrong.");
|
||||
jailMain.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
jailMain.getLogger().severe("Error while removing the prisoner '" + p.getLastKnownName() + "' (" + p.getUUID().toString() + ") from the database, please check the error and fix what is wrong.");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (c == null)
|
||||
if (c == null) {
|
||||
flat.set("jails." + j.getName() + ".prisoners." + p.getUUID().toString(), null);
|
||||
else
|
||||
} else {
|
||||
flat.set("jails." + j.getName() + ".cells." + c.getName() + ".prisoner", null);
|
||||
}
|
||||
|
||||
try {
|
||||
flat.save(new File(pl.getDataFolder(), "data.yml"));
|
||||
flat.save(new File(jailMain.getDataFolder(), "data.yml"));
|
||||
} catch (IOException e) {
|
||||
pl.getLogger().severe("Unable to save the Jail data: " + e.getMessage());
|
||||
jailMain.getLogger().severe("Unable to save the Jail data: " + e.getMessage());
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1137,11 +1167,13 @@ public class JailIO {
|
||||
*/
|
||||
public void removeCell(Jail j, Cell c) {
|
||||
//Clear the inventory before we delete it
|
||||
if (c.hasChest()) c.getChest().getInventory().clear();
|
||||
if (c.hasChest()) {
|
||||
c.getChest().getInventory().clear();
|
||||
}
|
||||
|
||||
//transfer the prisoner if it has one
|
||||
if (c.hasPrisoner()) {
|
||||
pl.getLogger().warning("Removing of cell '" + c.getName() + "' from the jail '" + j.getName() + "' failed as it has a prisoner.");
|
||||
jailMain.getLogger().warning("Removing of cell '" + c.getName() + "' from the jail '" + j.getName() + "' failed as it has a prisoner.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1161,8 +1193,8 @@ public class JailIO {
|
||||
p.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
pl.getLogger().severe("Error while removing the cell '" + c.getName() + "' from the Jail '" + j.getName() + "', please check the error and fix what is wrong.");
|
||||
jailMain.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
jailMain.getLogger().severe("Error while removing the cell '" + c.getName() + "' from the Jail '" + j.getName() + "', please check the error and fix what is wrong.");
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
@@ -1180,8 +1212,8 @@ public class JailIO {
|
||||
p.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
pl.getLogger().severe("Error while removing the cell '" + c.getName() + "' from the Jail '" + j.getName() + "', please check the error and fix what is wrong.");
|
||||
jailMain.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
jailMain.getLogger().severe("Error while removing the cell '" + c.getName() + "' from the Jail '" + j.getName() + "', please check the error and fix what is wrong.");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -1189,11 +1221,11 @@ public class JailIO {
|
||||
flat.set("jails." + j.getName() + ".cells." + c.getName(), null);
|
||||
|
||||
try {
|
||||
flat.save(new File(pl.getDataFolder(), "data.yml"));
|
||||
flat.save(new File(jailMain.getDataFolder(), "data.yml"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
pl.getLogger().severe("Removing of the cell '" + c.getName() + "' from the jail '" + j.getName() + "' errored out while on saving.");
|
||||
jailMain.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
jailMain.getLogger().severe("Removing of the cell '" + c.getName() + "' from the jail '" + j.getName() + "' errored out while on saving.");
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1228,19 +1260,19 @@ public class JailIO {
|
||||
p.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
pl.getLogger().severe("Error while removing the Jail '" + j.getName() + "', please check the error and fix what is wrong.");
|
||||
jailMain.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
jailMain.getLogger().severe("Error while removing the Jail '" + j.getName() + "', please check the error and fix what is wrong.");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
flat.set("jails." + name, null);
|
||||
|
||||
try {
|
||||
flat.save(new File(pl.getDataFolder(), "data.yml"));
|
||||
flat.save(new File(jailMain.getDataFolder(), "data.yml"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
pl.getLogger().severe("Removing of the jail '" + j.getName() + "' errored out while on saving.");
|
||||
jailMain.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
jailMain.getLogger().severe("Removing of the jail '" + j.getName() + "' errored out while on saving.");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1279,13 +1311,14 @@ public class JailIO {
|
||||
p.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
pl.getLogger().severe("Error while adding a record entry for '" + username + "', please check the error and fix what is wrong.");
|
||||
jailMain.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
jailMain.getLogger().severe("Error while adding a record entry for '" + username + "', please check the error and fix what is wrong.");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (records == null)
|
||||
records = YamlConfiguration.loadConfiguration(new File(pl.getDataFolder(), "records.yml"));
|
||||
if (records == null) {
|
||||
records = YamlConfiguration.loadConfiguration(new File(jailMain.getDataFolder(), "records.yml"));
|
||||
}
|
||||
|
||||
List<String> previous = records.getStringList(uuid);
|
||||
previous.add(Lang.RECORDENTRY.get(date, username, jailer, String.valueOf(time), reason, uuid));
|
||||
@@ -1293,11 +1326,11 @@ public class JailIO {
|
||||
records.set(uuid, previous);
|
||||
|
||||
try {
|
||||
records.save(new File(pl.getDataFolder(), "records.yml"));
|
||||
records.save(new File(jailMain.getDataFolder(), "records.yml"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
pl.getLogger().severe("Saving the records.yml file failed while putting an entry in for '" + username + "'.");
|
||||
jailMain.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
jailMain.getLogger().severe("Saving the records.yml file failed while putting an entry in for '" + username + "'.");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1311,7 +1344,7 @@ public class JailIO {
|
||||
* @deprecated This calls getOfflinePlayer which is a blocking call from Bukkit
|
||||
*/
|
||||
public List<String> getRecordEntries(String username) {
|
||||
UUID uuid = pl.getServer().getOfflinePlayer(username).getUniqueId();
|
||||
UUID uuid = jailMain.getServer().getOfflinePlayer(username).getUniqueId();
|
||||
List<String> entries = new ArrayList<>();
|
||||
|
||||
switch (storage) {
|
||||
@@ -1336,13 +1369,14 @@ public class JailIO {
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
pl.getLogger().severe("Error while getting all the record entries for '" + uuid + "', please check the error and fix what is wrong.");
|
||||
jailMain.getLogger().severe("---------- Jail Error!!! ----------");
|
||||
jailMain.getLogger().severe("Error while getting all the record entries for '" + uuid + "', please check the error and fix what is wrong.");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (records == null)
|
||||
records = YamlConfiguration.loadConfiguration(new File(pl.getDataFolder(), "records.yml"));
|
||||
if (records == null) {
|
||||
records = YamlConfiguration.loadConfiguration(new File(jailMain.getDataFolder(), "records.yml"));
|
||||
}
|
||||
|
||||
entries = records.getStringList(uuid.toString());
|
||||
break;
|
||||
|
@@ -20,10 +20,13 @@ import com.graywolf336.jail.listeners.ProtectionListener;
|
||||
import com.graywolf336.jail.listeners.WorldListener;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -40,13 +43,13 @@ public class JailMain extends JavaPlugin {
|
||||
private HandCuffManager hcm;
|
||||
private JailHandler jh;
|
||||
private JailIO io;
|
||||
private JailManager jm;
|
||||
private JailManager jailManager;
|
||||
private IJailPayManager jpm;
|
||||
private IJailStickManager jsm;
|
||||
private IJailStickManager jailStickManager;
|
||||
private JailTimer jt;
|
||||
private JailVoteManager jvm;
|
||||
private PrisonerManager pm;
|
||||
private ScoreBoardManager sbm;
|
||||
private ScoreBoardManager scoreBoardManager;
|
||||
private MoveProtectionListener mpl;
|
||||
private Update update;
|
||||
private boolean debug = false;
|
||||
@@ -57,10 +60,12 @@ public class JailMain extends JavaPlugin {
|
||||
loadConfig();
|
||||
|
||||
debug = getConfig().getBoolean(Settings.DEBUG.getPath());
|
||||
if (debug) getLogger().info("Debugging enabled.");
|
||||
if (debug) {
|
||||
getLogger().info("Debugging enabled.");
|
||||
}
|
||||
|
||||
hcm = new HandCuffManager();
|
||||
jm = new JailManager(this);
|
||||
jailManager = new JailManager(this);
|
||||
io = new JailIO(this);
|
||||
io.loadLanguage();
|
||||
|
||||
@@ -84,15 +89,15 @@ public class JailMain extends JavaPlugin {
|
||||
getLogger().severe("Failed to load the Jail Vote system, please see the stacktrace above (you probably misconfigured the time).");
|
||||
}
|
||||
|
||||
PluginManager plm = this.getServer().getPluginManager();
|
||||
plm.registerEvents(new CacheListener(this), this);
|
||||
plm.registerEvents(new CellSignListener(this), this);
|
||||
plm.registerEvents(new EntityListener(this), this);
|
||||
plm.registerEvents(new HandCuffListener(this), this);
|
||||
plm.registerEvents(new JailingListener(this), this);
|
||||
plm.registerEvents(new PlayerListener(this), this);
|
||||
plm.registerEvents(new ProtectionListener(this), this);
|
||||
plm.registerEvents(new WorldListener(this), this);
|
||||
PluginManager pluginManager = this.getServer().getPluginManager();
|
||||
pluginManager.registerEvents(new CacheListener(this), this);
|
||||
pluginManager.registerEvents(new CellSignListener(this), this);
|
||||
pluginManager.registerEvents(new EntityListener(this), this);
|
||||
pluginManager.registerEvents(new HandCuffListener(this), this);
|
||||
pluginManager.registerEvents(new JailingListener(this), this);
|
||||
pluginManager.registerEvents(new PlayerListener(this), this);
|
||||
pluginManager.registerEvents(new ProtectionListener(this), this);
|
||||
pluginManager.registerEvents(new WorldListener(this), this);
|
||||
|
||||
//Only register the move protection listener if this is enabled in the
|
||||
//config when we first start the plugin. The reason for this change is
|
||||
@@ -103,39 +108,43 @@ public class JailMain extends JavaPlugin {
|
||||
this.reloadMoveProtection();
|
||||
|
||||
jt = new JailTimer(this);
|
||||
sbm = new ScoreBoardManager(this);
|
||||
scoreBoardManager = new ScoreBoardManager(this);
|
||||
reloadJailPayManager();
|
||||
reloadJailSticks();
|
||||
reloadUpdateCheck();
|
||||
|
||||
new JailsAPI(this);
|
||||
JailsAPI.initialize(this);
|
||||
debug("Took " + (System.currentTimeMillis() - st) + " to enable the plugin.");
|
||||
getLogger().info("Completed enablement.");
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
if (jm != null)
|
||||
for (Jail j : jm.getJails())
|
||||
if (jailManager != null) {
|
||||
for (Jail j : jailManager.getJails())
|
||||
io.saveJail(j);
|
||||
}
|
||||
|
||||
if (jt != null)
|
||||
if (jt.getTimer() != null)
|
||||
if (jt != null) {
|
||||
if (jt.getTimer() != null) {
|
||||
jt.getTimer().stop();
|
||||
}
|
||||
}
|
||||
|
||||
if (io != null)
|
||||
if (io != null) {
|
||||
io.closeConnection();
|
||||
}
|
||||
|
||||
getServer().getScheduler().cancelTasks(this);
|
||||
|
||||
update = null;
|
||||
jvm = null;
|
||||
jt = null;
|
||||
sbm = null;
|
||||
scoreBoardManager = null;
|
||||
jpm = null;
|
||||
cmdHand = null;
|
||||
pm = null;
|
||||
jm = null;
|
||||
jsm = null;
|
||||
jailManager = null;
|
||||
jailStickManager = null;
|
||||
io = null;
|
||||
hcm = null;
|
||||
}
|
||||
@@ -148,17 +157,19 @@ public class JailMain extends JavaPlugin {
|
||||
getConfig().options().copyDefaults(true);
|
||||
|
||||
// Set the header and save
|
||||
getConfig().options().header(getHeader());
|
||||
getConfig().options().setHeader(getHeader());
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
private String getHeader() {
|
||||
private List<String> getHeader() {
|
||||
String sep = System.getProperty("line.separator");
|
||||
|
||||
return "###################" + sep
|
||||
List<String> header = new ArrayList<>();
|
||||
header.add("###################" + sep
|
||||
+ "Jail v" + this.getDescription().getVersion() + " config file" + sep
|
||||
+ "Note: You -must- use spaces instead of tabs!" + sep +
|
||||
"###################";
|
||||
"###################");
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
/* Majority of the new command system was heavily influenced by the MobArena.
|
||||
@@ -166,22 +177,24 @@ public class JailMain extends JavaPlugin {
|
||||
*
|
||||
* Send the command off to the CommandHandler class, that way this main class doesn't get clogged up.
|
||||
*/
|
||||
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String commandLabel,
|
||||
@NotNull String[] args) {
|
||||
if (jh == null || cmdHand == null) {
|
||||
sender.sendMessage(Lang.PLUGINNOTLOADED.get());
|
||||
getServer().getConsoleSender().sendMessage(Lang.PLUGINNOTLOADED.get());
|
||||
} else {
|
||||
if (commandLabel.equalsIgnoreCase("jail") || commandLabel.equalsIgnoreCase("j")) {
|
||||
jh.parseCommand(jm, sender, args);
|
||||
jh.parseCommand(jailManager, sender, args);
|
||||
} else {
|
||||
cmdHand.handleCommand(jm, sender, command.getName().toLowerCase(), args);
|
||||
cmdHand.handleCommand(jailManager, sender, command.getName().toLowerCase(), args);
|
||||
}
|
||||
}
|
||||
|
||||
return true;//Always return true here, that way we can handle the help and command usage ourself.
|
||||
}
|
||||
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String commandLabel, String[] args) {
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
|
||||
@NotNull String commandLabel, @NotNull String[] args) {
|
||||
if (jh == null || cmdHand == null) {
|
||||
sender.sendMessage(Lang.PLUGINNOTLOADED.get());
|
||||
getServer().getConsoleSender().sendMessage(Lang.PLUGINNOTLOADED.get());
|
||||
@@ -189,13 +202,14 @@ public class JailMain extends JavaPlugin {
|
||||
debug("Tab Complete Args (" + args.length + ") for '" + commandLabel + "': " + Util.getStringFromArray(", ", args));
|
||||
try {
|
||||
if (commandLabel.equalsIgnoreCase("jail") || commandLabel.equalsIgnoreCase("j")) {
|
||||
return jh.parseTabComplete(jm, sender, args);
|
||||
return jh.parseTabComplete(jailManager, sender, args);
|
||||
} else {
|
||||
return cmdHand.parseTabComplete(jm, sender, command.getName().toLowerCase(), args);
|
||||
return cmdHand.parseTabComplete(jailManager, sender, command.getName().toLowerCase(), args);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (this.debug)
|
||||
if (this.debug) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
debug(e.getClass().getSimpleName() + " occured while providing tab complete: " + e.getMessage());
|
||||
return Collections.emptyList();
|
||||
@@ -256,15 +270,19 @@ public class JailMain extends JavaPlugin {
|
||||
* Reloads the scoreboard manager class, useful when something is changed in the config about it.
|
||||
*/
|
||||
private void reloadScoreBoardManager() {
|
||||
this.sbm.removeAllScoreboards();
|
||||
this.sbm = null;
|
||||
this.sbm = new ScoreBoardManager(this);
|
||||
this.scoreBoardManager.removeAllScoreboards();
|
||||
this.scoreBoardManager = null;
|
||||
this.scoreBoardManager = new ScoreBoardManager(this);
|
||||
|
||||
if (getConfig().getBoolean(Settings.SCOREBOARDENABLED.getPath())) {
|
||||
for (Jail j : jm.getJails()) {
|
||||
for (Prisoner p : j.getAllPrisoners().values()) {
|
||||
if (getServer().getPlayer(p.getUUID()) != null) {
|
||||
this.sbm.addScoreBoard(getServer().getPlayer(p.getUUID()), p);
|
||||
for (Jail jail : jailManager.getJails()) {
|
||||
for (Prisoner prisoner : jail.getAllPrisoners().values()) {
|
||||
if (getServer().getPlayer(prisoner.getUUID()) != null) {
|
||||
Player uuid = getServer().getPlayer(prisoner.getUUID());
|
||||
if (uuid == null) {
|
||||
continue;
|
||||
}
|
||||
this.scoreBoardManager.addScoreBoard(uuid, prisoner);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -276,12 +294,12 @@ public class JailMain extends JavaPlugin {
|
||||
*/
|
||||
private void reloadJailSticks() {
|
||||
if (getConfig().getBoolean(Settings.JAILSTICKENABLED.getPath())) {
|
||||
if (this.jsm != null) {
|
||||
this.jsm.removeAllStickUsers();
|
||||
this.jsm = null;
|
||||
if (this.jailStickManager != null) {
|
||||
this.jailStickManager.removeAllStickUsers();
|
||||
this.jailStickManager = null;
|
||||
}
|
||||
|
||||
this.jsm = new JailStickManager(this);
|
||||
this.jailStickManager = new JailStickManager(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -358,7 +376,7 @@ public class JailMain extends JavaPlugin {
|
||||
* @return {@link JailManager} instance
|
||||
*/
|
||||
public JailManager getJailManager() {
|
||||
return this.jm;
|
||||
return this.jailManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -385,7 +403,7 @@ public class JailMain extends JavaPlugin {
|
||||
* @return {@link JailStickManager}
|
||||
*/
|
||||
public IJailStickManager getJailStickManager() {
|
||||
return this.jsm;
|
||||
return this.jailStickManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -394,7 +412,7 @@ public class JailMain extends JavaPlugin {
|
||||
* @return {@link ScoreBoardManager} instance
|
||||
*/
|
||||
public ScoreBoardManager getScoreBoardManager() {
|
||||
return this.sbm;
|
||||
return this.scoreBoardManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -446,7 +464,9 @@ public class JailMain extends JavaPlugin {
|
||||
* @param message the item to log as debugging
|
||||
*/
|
||||
public void debug(String message) {
|
||||
if (inDebug()) getLogger().info("[Debug]: " + message);
|
||||
if (inDebug()) {
|
||||
getLogger().info("[Debug]: " + message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -79,23 +79,6 @@ public class JailManager {
|
||||
return new HashSet<>(jails.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of all the names of the jails.
|
||||
*
|
||||
* @return Array of the jail names
|
||||
*/
|
||||
public String[] getJailNames() {
|
||||
String[] toReturn = new String[jails.size()];
|
||||
|
||||
int count = 0;
|
||||
for (Jail j : this.jails.values()) {
|
||||
toReturn[count] = j.getName();
|
||||
count++;
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of Jail names that start with the provided prefix.
|
||||
*
|
||||
@@ -110,8 +93,9 @@ public class JailManager {
|
||||
List<String> results = new ArrayList<>();
|
||||
|
||||
for (Jail j : this.jails.values())
|
||||
if (prefix.isEmpty() || StringUtil.startsWithIgnoreCase(j.getName(), prefix))
|
||||
if (prefix.isEmpty() || StringUtil.startsWithIgnoreCase(j.getName(), prefix)) {
|
||||
results.add(j.getName());
|
||||
}
|
||||
|
||||
Collections.sort(results);
|
||||
|
||||
@@ -126,7 +110,9 @@ public class JailManager {
|
||||
*/
|
||||
public void addJail(Jail jail, boolean n) {
|
||||
this.jails.put(jail.getName().toLowerCase(), jail);
|
||||
if (n) plugin.getJailIO().saveJail(jail);
|
||||
if (n) {
|
||||
plugin.getJailIO().saveJail(jail);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,10 +132,11 @@ public class JailManager {
|
||||
* @return The {@link Jail} with the given name, if no jail found this <strong>will</strong> return null.
|
||||
*/
|
||||
public Jail getJail(String name) {
|
||||
if (name.isEmpty() && jails.isEmpty())
|
||||
if (name.isEmpty() && jails.isEmpty()) {
|
||||
return null;
|
||||
else
|
||||
} else {
|
||||
return name.isEmpty() ? this.jails.values().iterator().next() : this.jails.get(name.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,24 +146,26 @@ public class JailManager {
|
||||
* @return The nearest {@link Jail} to the sender if it is a player or else the first jail defined.
|
||||
*/
|
||||
public Jail getNearestJail(CommandSender sender) {
|
||||
if (jails.isEmpty()) return null;
|
||||
if (jails.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (sender instanceof Player) {
|
||||
Location loc = ((Player) sender).getLocation();
|
||||
Location playerLocation = ((Player) sender).getLocation();
|
||||
|
||||
Jail j = null;
|
||||
double len = -1;
|
||||
Jail nearestJail = null;
|
||||
double nearestJailDistance = -1;
|
||||
|
||||
for (Jail jail : jails.values()) {
|
||||
double clen = jail.getDistance(loc);
|
||||
double distance = jail.getDistance(playerLocation);
|
||||
|
||||
if (clen < len || len == -1) {
|
||||
len = clen;
|
||||
j = jail;
|
||||
if (distance < nearestJailDistance || nearestJailDistance == -1) {
|
||||
nearestJailDistance = distance;
|
||||
nearestJail = jail;
|
||||
}
|
||||
}
|
||||
|
||||
return (j == null ? jails.values().iterator().next() : j);
|
||||
return nearestJail;
|
||||
} else {
|
||||
return jails.values().iterator().next();
|
||||
}
|
||||
@@ -232,8 +221,8 @@ public class JailManager {
|
||||
public HashSet<Cell> getAllCells() {
|
||||
HashSet<Cell> cells = new HashSet<>();
|
||||
|
||||
for (Jail j : jails.values())
|
||||
cells.addAll(j.getCells());
|
||||
for (Jail jail : jails.values())
|
||||
cells.addAll(jail.getCells());
|
||||
|
||||
return cells;
|
||||
}
|
||||
@@ -242,12 +231,11 @@ public class JailManager {
|
||||
* Adds a prisoner to the cache.
|
||||
*
|
||||
* @param cache object to store
|
||||
* @return The same object given
|
||||
*/
|
||||
public CachePrisoner addCacheObject(CachePrisoner cache) {
|
||||
plugin.debug("Adding " + cache.getPrisoner().getUUID().toString() + " to the cache.");
|
||||
this.cache.put(cache.getPrisoner().getUUID(), cache);
|
||||
return this.cache.get(cache.getPrisoner().getUUID());
|
||||
public void addCacheObject(CachePrisoner cache) {
|
||||
UUID uuid = cache.getPrisoner().getUUID();
|
||||
plugin.debug("Adding " + uuid.toString() + " to the cache.");
|
||||
this.cache.put(uuid, cache);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -301,8 +289,11 @@ public class JailManager {
|
||||
* @return The jail the player is in, <strong>CAN BE NULL</strong>.
|
||||
*/
|
||||
public Jail getJailPrisonerIsIn(Prisoner prisoner) {
|
||||
if (prisoner == null) return null;
|
||||
else return getJailPlayerIsIn(prisoner.getUUID());
|
||||
if (prisoner == null) {
|
||||
return null;
|
||||
} else {
|
||||
return getJailPlayerIsIn(prisoner.getUUID());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -322,8 +313,9 @@ public class JailManager {
|
||||
}
|
||||
|
||||
for (Jail j : jails.values())
|
||||
if (j.isPlayerJailed(uuid))
|
||||
if (j.isPlayerJailed(uuid)) {
|
||||
return j;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -359,8 +351,9 @@ public class JailManager {
|
||||
public Jail getJailPlayerIsInByLastKnownName(String username) {
|
||||
for (Jail j : jails.values())
|
||||
for (Prisoner p : j.getAllPrisoners().values())
|
||||
if (p.getLastKnownName().equalsIgnoreCase(username))
|
||||
if (p.getLastKnownName().equalsIgnoreCase(username)) {
|
||||
return j;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -373,8 +366,9 @@ public class JailManager {
|
||||
*/
|
||||
public Prisoner getPrisonerByLastKnownName(String username) {
|
||||
for (Prisoner p : this.getAllPrisoners().values())
|
||||
if (p.getLastKnownName().equalsIgnoreCase(username))
|
||||
if (p.getLastKnownName().equalsIgnoreCase(username)) {
|
||||
return p;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -586,38 +580,24 @@ public class JailManager {
|
||||
String message = "";
|
||||
|
||||
if (isCreatingACell(player)) {//Check whether it is a jail cell
|
||||
CreationPlayer cp = this.getCellCreationPlayer(player);
|
||||
message = "You're already creating a Cell with the name '" + cp.getCellName() + "' and you still need to ";
|
||||
CreationPlayer creationPlayer = this.getCellCreationPlayer(player);
|
||||
message = "You're already creating a Cell with the name '" + creationPlayer.getCellName() + "' and you still need to ";
|
||||
|
||||
switch (cp.getStep()) {
|
||||
case 1:
|
||||
message += "set the teleport in location.";
|
||||
break;
|
||||
case 2:
|
||||
message += "select all the signs.";
|
||||
break;
|
||||
case 3:
|
||||
message += "set the double chest location.";
|
||||
break;
|
||||
switch (creationPlayer.getStep()) {
|
||||
case 1 -> message += "set the teleport in location.";
|
||||
case 2 -> message += "select all the signs.";
|
||||
case 3 -> message += "set the double chest location.";
|
||||
}
|
||||
|
||||
} else if (isCreatingAJail(player)) {//If not a cell, then check if a jail.
|
||||
CreationPlayer cp = this.getJailCreationPlayer(player);
|
||||
message = "You're already creating a Jail with the name '" + cp.getJailName() + "' and you still need to ";
|
||||
CreationPlayer creationPlayer = this.getJailCreationPlayer(player);
|
||||
message = "You're already creating a Jail with the name '" + creationPlayer.getJailName() + "' and you still need to ";
|
||||
|
||||
switch (cp.getStep()) {
|
||||
case 1:
|
||||
message += "select the first point.";
|
||||
break;
|
||||
case 2:
|
||||
message += "select the second point.";
|
||||
break;
|
||||
case 3:
|
||||
message += "set the teleport in location.";
|
||||
break;
|
||||
case 4:
|
||||
message += "set the release location.";
|
||||
break;
|
||||
switch (creationPlayer.getStep()) {
|
||||
case 1 -> message += "select the first point.";
|
||||
case 2 -> message += "select the second point.";
|
||||
case 3 -> message += "set the teleport in location.";
|
||||
case 4 -> message += "set the release location.";
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -81,7 +81,9 @@ public class JailPayManager implements IJailPayManager {
|
||||
ItemStack it = p.getInventory().getItem(i);
|
||||
|
||||
//The item is either air or we doesn't match out needs
|
||||
if (it == null || it.getType() != this.item) continue;
|
||||
if (it == null || it.getType() != this.item) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//If the itemstack has more than or equal to the amount
|
||||
//that we need, remove it and subject from the amt needed
|
||||
@@ -95,7 +97,9 @@ public class JailPayManager implements IJailPayManager {
|
||||
amtNeeded = 0;
|
||||
}
|
||||
|
||||
if (amtNeeded == 0) break;
|
||||
if (amtNeeded == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.economy.withdrawPlayer(p, amt);
|
||||
@@ -133,7 +137,9 @@ public class JailPayManager implements IJailPayManager {
|
||||
}
|
||||
|
||||
private boolean setupEconomy(JailMain plugin) {
|
||||
if (economy != null) return true;
|
||||
if (economy != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
RegisteredServiceProvider<Economy> economyProvider = plugin.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
if (economyProvider != null) {
|
||||
|
@@ -85,7 +85,9 @@ public class JailTimer {
|
||||
if (!event.isCancelled()) {
|
||||
after = event.getTimeAfterChange();
|
||||
p.setRemainingTime(after);
|
||||
if (p.getRemainingTime() == 0) pl.getPrisonerManager().schedulePrisonerRelease(p);
|
||||
if (p.getRemainingTime() == 0) {
|
||||
pl.getPrisonerManager().schedulePrisonerRelease(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -111,7 +113,9 @@ public class JailTimer {
|
||||
if (!event.isCancelled()) {
|
||||
after = event.getTimeAfterChange();
|
||||
p.setRemainingTime(after);
|
||||
if (p.getRemainingTime() == 0) pl.getPrisonerManager().schedulePrisonerRelease(p);
|
||||
if (p.getRemainingTime() == 0) {
|
||||
pl.getPrisonerManager().schedulePrisonerRelease(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -15,10 +15,15 @@ import com.graywolf336.jail.interfaces.IJailStickManager;
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public class JailsAPI {
|
||||
private static JailMain pl;
|
||||
|
||||
protected JailsAPI(JailMain plugin) {
|
||||
pl = plugin;
|
||||
private static JailMain jailMain;
|
||||
|
||||
private JailsAPI() {
|
||||
|
||||
}
|
||||
|
||||
protected static void initialize(JailMain plugin) {
|
||||
jailMain = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,7 +32,7 @@ public class JailsAPI {
|
||||
* @return the build number of jail or -1 if an error occurred.
|
||||
*/
|
||||
public static int getBuildNumber() {
|
||||
String v = pl.getDescription().getVersion();
|
||||
String v = jailMain.getDescription().getVersion();
|
||||
String[] split = v.split("-");
|
||||
|
||||
try {
|
||||
@@ -44,7 +49,7 @@ public class JailsAPI {
|
||||
* @see JailManager
|
||||
*/
|
||||
public static JailManager getJailManager() {
|
||||
return pl.getJailManager();
|
||||
return jailMain.getJailManager();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,7 +59,7 @@ public class JailsAPI {
|
||||
* @see PrisonerManager
|
||||
*/
|
||||
public static PrisonerManager getPrisonerManager() {
|
||||
return pl.getPrisonerManager();
|
||||
return jailMain.getPrisonerManager();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,7 +69,7 @@ public class JailsAPI {
|
||||
* @see IJailStickManager
|
||||
*/
|
||||
public static IJailStickManager getJailStickManager() {
|
||||
return pl.getJailStickManager();
|
||||
return jailMain.getJailStickManager();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +79,7 @@ public class JailsAPI {
|
||||
* @see HandCuffManager
|
||||
*/
|
||||
public static HandCuffManager getHandCuffManager() {
|
||||
return pl.getHandCuffManager();
|
||||
return jailMain.getHandCuffManager();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,7 +89,7 @@ public class JailsAPI {
|
||||
* @see JailVoteManager
|
||||
*/
|
||||
public static JailVoteManager getJailVoteManager() {
|
||||
return pl.getJailVoteManager();
|
||||
return jailMain.getJailVoteManager();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -86,17 +86,21 @@ public class PrisonerManager {
|
||||
*/
|
||||
public void prepareJail(final Jail jail, ICell cell, final Player player, final Prisoner prisoner) throws JailRequiredException, PrisonerAlreadyJailedException, PrisonerRequiredException {
|
||||
//Do some checks of whether the passed params are null.
|
||||
if (jail == null)
|
||||
if (jail == null) {
|
||||
throw new JailRequiredException("jailing a prisoner");
|
||||
}
|
||||
|
||||
if (cell == null)
|
||||
if (cell == null) {
|
||||
cell = new NoCell();
|
||||
}
|
||||
|
||||
if (prisoner == null)
|
||||
if (prisoner == null) {
|
||||
throw new PrisonerRequiredException("jailing a prisoner");
|
||||
}
|
||||
|
||||
if (this.pl.getJailManager().isPlayerJailed(prisoner.getUUID()))
|
||||
if (this.pl.getJailManager().isPlayerJailed(prisoner.getUUID())) {
|
||||
throw new PrisonerAlreadyJailedException(prisoner.getLastKnownName(), prisoner.getUUID().toString());
|
||||
}
|
||||
|
||||
//Set whether the prisoner is offline or not.
|
||||
prisoner.setOfflinePending(player == null);
|
||||
@@ -108,10 +112,11 @@ public class PrisonerManager {
|
||||
} else if (cell instanceof AnyCell) {
|
||||
cell = jail.getFirstEmptyCell();
|
||||
|
||||
if (cell == null)
|
||||
if (cell == null) {
|
||||
jail.addPrisoner(prisoner);
|
||||
else
|
||||
} else {
|
||||
cell.setPrisoner(prisoner);
|
||||
}
|
||||
} else {
|
||||
cell.setPrisoner(prisoner);
|
||||
}
|
||||
@@ -127,10 +132,11 @@ public class PrisonerManager {
|
||||
//Get a message ready for broadcasting or logging.
|
||||
String msg;
|
||||
|
||||
if (prisoner.getRemainingTime() < 0L)
|
||||
if (prisoner.getRemainingTime() < 0L) {
|
||||
msg = Lang.BROADCASTMESSAGEFOREVER.get(prisoner.getLastKnownName(), prisoner.getReason(), jail.getName(), cell == null ? "" : cell.getName());
|
||||
else
|
||||
} else {
|
||||
msg = Lang.BROADCASTMESSAGEFORMINUTES.get(prisoner.getLastKnownName(), String.valueOf(prisoner.getRemainingTimeInMinutes()), prisoner.getReason(), jail.getName(), cell == null ? "" : cell.getName());
|
||||
}
|
||||
|
||||
boolean broadcasted = false;
|
||||
//Broadcast the message, if it is enabled
|
||||
@@ -164,10 +170,11 @@ public class PrisonerManager {
|
||||
* @param prisoner data containing everything pertaining to them
|
||||
*/
|
||||
protected void jailPrisoner(final Jail jail, ICell cell, final Player player, final Prisoner prisoner) {
|
||||
if (cell instanceof NoCell)
|
||||
if (cell instanceof NoCell) {
|
||||
cell = null;
|
||||
else if (cell instanceof AnyCell)
|
||||
} else if (cell instanceof AnyCell) {
|
||||
cell = null;
|
||||
}
|
||||
|
||||
//If they have handcuffs on them, then let's remove them before we continue
|
||||
//this way the handcuff listeners and this aren't battleing each other
|
||||
@@ -208,8 +215,9 @@ public class PrisonerManager {
|
||||
} catch (Exception e) {
|
||||
StringBuilder gamemodes = new StringBuilder();
|
||||
for (GameMode m : GameMode.values()) {
|
||||
if (gamemodes.length() != 0)
|
||||
if (gamemodes.length() != 0) {
|
||||
gamemodes.append(", ");
|
||||
}
|
||||
|
||||
gamemodes.append(m.toString().toLowerCase());
|
||||
}
|
||||
@@ -279,14 +287,18 @@ public class PrisonerManager {
|
||||
player.getInventory().clear();
|
||||
} else {
|
||||
for (ItemStack item : player.getInventory().getContents())
|
||||
if (item != null)
|
||||
if (Util.isStringInsideList(item.getType().toString(), blacklist))
|
||||
if (item != null) {
|
||||
if (Util.isStringInsideList(item.getType().toString(), blacklist)) {
|
||||
player.getInventory().remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
for (ItemStack item : player.getInventory().getArmorContents())
|
||||
if (item != null)
|
||||
if (Util.isStringInsideList(item.getType().toString(), blacklist))
|
||||
if (item != null) {
|
||||
if (Util.isStringInsideList(item.getType().toString(), blacklist)) {
|
||||
player.getInventory().remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
prisoner.setInventory(Util.toBase64(player.getInventory()));
|
||||
|
||||
@@ -307,14 +319,18 @@ public class PrisonerManager {
|
||||
List<String> blacklist = pl.getConfig().getStringList(Settings.JAILEDINVENTORYBLACKLIST.getPath());
|
||||
|
||||
for (ItemStack item : player.getInventory().getContents())
|
||||
if (item != null)
|
||||
if (Util.isStringInsideList(item.getType().toString(), blacklist))
|
||||
if (item != null) {
|
||||
if (Util.isStringInsideList(item.getType().toString(), blacklist)) {
|
||||
player.getInventory().remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
for (ItemStack item : player.getInventory().getArmorContents())
|
||||
if (item != null)
|
||||
if (Util.isStringInsideList(item.getType().toString(), blacklist))
|
||||
if (item != null) {
|
||||
if (Util.isStringInsideList(item.getType().toString(), blacklist)) {
|
||||
player.getInventory().remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
prisoner.setInventory(Util.toBase64(player.getInventory()));
|
||||
|
||||
@@ -415,19 +431,24 @@ public class PrisonerManager {
|
||||
* @throws PrisonerRequiredException when the provided prisoner data is null.
|
||||
*/
|
||||
public void unJail(final Jail jail, ICell cell, final Player player, final Prisoner prisoner, final CommandSender sender) throws AsyncUnJailingNotSupportedException, JailRequiredException, PrisonerRequiredException {
|
||||
if (!pl.getServer().isPrimaryThread()) throw new AsyncUnJailingNotSupportedException();
|
||||
if (!pl.getServer().isPrimaryThread()) {
|
||||
throw new AsyncUnJailingNotSupportedException();
|
||||
}
|
||||
|
||||
//Do some checks of whether the passed params are null.
|
||||
if (jail == null)
|
||||
if (jail == null) {
|
||||
throw new JailRequiredException("unjailing a prisoner");
|
||||
}
|
||||
|
||||
if (cell instanceof NoCell)
|
||||
if (cell instanceof NoCell) {
|
||||
cell = null;
|
||||
else if (cell instanceof AnyCell)
|
||||
} else if (cell instanceof AnyCell) {
|
||||
cell = null;
|
||||
}
|
||||
|
||||
if (prisoner == null)
|
||||
if (prisoner == null) {
|
||||
throw new PrisonerRequiredException("unjailing a prisoner");
|
||||
}
|
||||
|
||||
//Throw the custom event which is called before we start releasing them
|
||||
PrePrisonerReleasedEvent preEvent = new PrePrisonerReleasedEvent(jail, cell, prisoner, player);
|
||||
@@ -461,7 +482,9 @@ public class PrisonerManager {
|
||||
Inventory chest = cell.getChest().getInventory();
|
||||
|
||||
for (ItemStack item : chest.getContents()) {
|
||||
if (item == null || item.getType() == Material.AIR) continue;
|
||||
if (item == null || item.getType() == Material.AIR) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item.getType().toString().toLowerCase().contains("helmet") && (player.getInventory().getHelmet() == null || player.getInventory().getHelmet().getType() == Material.AIR)) {
|
||||
player.getInventory().setHelmet(item);
|
||||
@@ -485,13 +508,17 @@ public class PrisonerManager {
|
||||
} else {
|
||||
//Clear out the cell's chest just in case
|
||||
//they decided to store something there
|
||||
if (cell.hasChest()) cell.getChest().getInventory().clear();
|
||||
if (cell.hasChest()) {
|
||||
cell.getChest().getInventory().clear();
|
||||
}
|
||||
}
|
||||
|
||||
pl.getJailIO().removePrisoner(jail, (Cell) cell, prisoner);
|
||||
cell.removePrisoner();
|
||||
} else {
|
||||
if (store) Util.restoreInventory(player, prisoner);
|
||||
if (store) {
|
||||
Util.restoreInventory(player, prisoner);
|
||||
}
|
||||
|
||||
pl.getJailIO().removePrisoner(jail, prisoner);
|
||||
jail.removePrisoner(prisoner);
|
||||
@@ -506,8 +533,9 @@ public class PrisonerManager {
|
||||
//previous position then let's do that
|
||||
boolean tpd = false;
|
||||
if (pl.getConfig().getBoolean(Settings.RELEASETOPREVIOUSPOSITION.getPath(), false)) {
|
||||
if (prisoner.getPreviousLocation() != null)
|
||||
if (prisoner.getPreviousLocation() != null) {
|
||||
tpd = player.teleport(prisoner.getPreviousLocation());
|
||||
}
|
||||
}
|
||||
|
||||
//If they haven't already been teleported and the config has us to teleport on release,
|
||||
@@ -543,7 +571,9 @@ public class PrisonerManager {
|
||||
pl.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
player.sendMessage(Lang.UNJAILED.get());
|
||||
if (sender != null) sender.sendMessage(Lang.UNJAILSUCCESS.get(player.getName()));
|
||||
if (sender != null) {
|
||||
sender.sendMessage(Lang.UNJAILSUCCESS.get(player.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -600,11 +630,13 @@ public class PrisonerManager {
|
||||
* @throws PrisonerRequiredException when the provided prisoner data is null.
|
||||
*/
|
||||
public void forceUnJail(Jail jail, Cell cell, Player player, Prisoner prisoner, CommandSender sender) throws JailRequiredException, PrisonerRequiredException {
|
||||
if (jail == null)
|
||||
if (jail == null) {
|
||||
throw new JailRequiredException("jailing a prisoner");
|
||||
}
|
||||
|
||||
if (prisoner == null)
|
||||
if (prisoner == null) {
|
||||
throw new PrisonerRequiredException("jailing a prisoner");
|
||||
}
|
||||
|
||||
if (player == null) {
|
||||
//Player is offline, we just forcefully remove them from the database
|
||||
@@ -620,7 +652,9 @@ public class PrisonerManager {
|
||||
PrisonerReleasedEvent event = new PrisonerReleasedEvent(jail, cell, prisoner, player);
|
||||
pl.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (sender != null) sender.sendMessage(Lang.FORCEUNJAILED.get(prisoner.getLastKnownName()));
|
||||
if (sender != null) {
|
||||
sender.sendMessage(Lang.FORCEUNJAILED.get(prisoner.getLastKnownName()));
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
unJail(jail, cell, player, prisoner, sender);
|
||||
@@ -718,8 +752,9 @@ public class PrisonerManager {
|
||||
if (targetCell.hasChest()) {
|
||||
//Loop through the origin's chest inventory and add it to the target cell's chest
|
||||
for (ItemStack i : originCell.getChest().getInventory().getContents())
|
||||
if (i != null)
|
||||
if (i != null) {
|
||||
targetCell.getChest().getInventory().addItem(i);
|
||||
}
|
||||
|
||||
//Clear the origin cell's chest as it is clear now
|
||||
originCell.getChest().getInventory().clear();
|
||||
@@ -736,10 +771,12 @@ public class PrisonerManager {
|
||||
}
|
||||
|
||||
//Update the signs of both cells
|
||||
if (originCell != null)
|
||||
if (originCell != null) {
|
||||
originCell.updateSigns();
|
||||
if (targetCell != null)
|
||||
}
|
||||
if (targetCell != null) {
|
||||
targetCell.updateSigns();
|
||||
}
|
||||
|
||||
//Throw our custom event PrisonerTransferredEvent to say it was successful
|
||||
PrisonerTransferredEvent event = new PrisonerTransferredEvent(originJail, originCell, targetJail, targetCell, prisoner, player);
|
||||
|
@@ -129,7 +129,7 @@ public class Update {
|
||||
* @return The result is a negative integer if str1 is _numerically_ less than str2.
|
||||
* The result is a positive integer if str1 is _numerically_ greater than str2.
|
||||
* The result is zero if the strings are _numerically_ equal.
|
||||
* @note It does not work if "1.10" is supposed to be equal to "1.10.0".
|
||||
* Note: It does not work if "1.10" is supposed to be equal to "1.10.0".
|
||||
*/
|
||||
private Integer versionCompare(String str1, String str2) {
|
||||
String[] vals1 = str1.split("\\.");
|
||||
|
@@ -88,8 +88,9 @@ public class Util {
|
||||
*/
|
||||
public static boolean isStringInsideArray(String value, String... array) {
|
||||
for (String s : array)
|
||||
if (s.equalsIgnoreCase(value))
|
||||
if (s.equalsIgnoreCase(value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -105,8 +106,9 @@ public class Util {
|
||||
*/
|
||||
public static boolean isStringInsideList(String value, List<String> list) {
|
||||
for (String s : list)
|
||||
if (s.equalsIgnoreCase(value))
|
||||
if (s.equalsIgnoreCase(value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -122,7 +124,9 @@ public class Util {
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
for (String s : array) {
|
||||
if (result.length() != 0) result.append(separator);
|
||||
if (result.length() != 0) {
|
||||
result.append(separator);
|
||||
}
|
||||
result.append(s);
|
||||
}
|
||||
|
||||
@@ -140,7 +144,9 @@ public class Util {
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
for (String s : list) {
|
||||
if (result.length() != 0) result.append(separator);
|
||||
if (result.length() != 0) {
|
||||
result.append(separator);
|
||||
}
|
||||
result.append(s);
|
||||
}
|
||||
|
||||
@@ -236,22 +242,24 @@ public class Util {
|
||||
* @throws Exception if there are no matches
|
||||
*/
|
||||
public static Long getTime(String time) throws Exception {
|
||||
if (time.equalsIgnoreCase("-1")) return -1L;
|
||||
if (time.equalsIgnoreCase("-1")) {
|
||||
return -1L;
|
||||
}
|
||||
|
||||
long t;
|
||||
Matcher match = DURATION_PATTERN.matcher(time);
|
||||
|
||||
if (match.matches()) {
|
||||
String units = match.group(2);
|
||||
if ("seconds".equals(units) || "second".equals(units) || "s".equals(units))
|
||||
if ("seconds".equals(units) || "second".equals(units) || "s".equals(units)) {
|
||||
t = TimeUnit.MILLISECONDS.convert(Long.parseLong(match.group(1)), TimeUnit.SECONDS);
|
||||
else if ("minutes".equals(units) || "minute".equals(units) || "mins".equals(units) || "min".equals(units) || "m".equals(units))
|
||||
} else if ("minutes".equals(units) || "minute".equals(units) || "mins".equals(units) || "min".equals(units) || "m".equals(units)) {
|
||||
t = TimeUnit.MILLISECONDS.convert(Long.parseLong(match.group(1)), TimeUnit.MINUTES);
|
||||
else if ("hours".equals(units) || "hour".equals(units) || "h".equals(units))
|
||||
} else if ("hours".equals(units) || "hour".equals(units) || "h".equals(units)) {
|
||||
t = TimeUnit.MILLISECONDS.convert(Long.parseLong(match.group(1)), TimeUnit.HOURS);
|
||||
else if ("days".equals(units) || "day".equals(units) || "d".equals(units))
|
||||
} else if ("days".equals(units) || "day".equals(units) || "d".equals(units)) {
|
||||
t = TimeUnit.MILLISECONDS.convert(Long.parseLong(match.group(1)), TimeUnit.DAYS);
|
||||
else {
|
||||
} else {
|
||||
try {
|
||||
t = TimeUnit.MILLISECONDS.convert(Long.parseLong(time), TimeUnit.MINUTES);
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -313,7 +321,9 @@ public class Util {
|
||||
* @throws Exception Throws an exception if there aren't exactly four lines.
|
||||
*/
|
||||
public static void updateSignLinesCache(String[] lines) throws Exception {
|
||||
if (lines.length != 4) throw new Exception("Exactly four lines are required for the signs.");
|
||||
if (lines.length != 4) {
|
||||
throw new Exception("Exactly four lines are required for the signs.");
|
||||
}
|
||||
signLines = lines;
|
||||
}
|
||||
|
||||
@@ -329,14 +339,19 @@ public class Util {
|
||||
public static List<String> getUnusedItems(List<String> items, String[] args, boolean useP) {
|
||||
List<String> used = new ArrayList<>();
|
||||
for (String s : args)
|
||||
if (s.contains("-"))
|
||||
if (s.contains("-")) {
|
||||
used.add(s.replace("-", ""));
|
||||
}
|
||||
|
||||
List<String> unused = new ArrayList<>();
|
||||
for (String t : items)
|
||||
if (!used.contains(t)) //don't add it if it is already used
|
||||
{
|
||||
if (!t.equalsIgnoreCase("p") || (useP && t.equalsIgnoreCase("p")))//don't add -p unless otherwise stated
|
||||
{
|
||||
unused.add("-" + t);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(unused);
|
||||
|
||||
@@ -423,7 +438,9 @@ public class Util {
|
||||
* @throws IOException if we were unable to parse the base64 string
|
||||
*/
|
||||
public static Inventory fromBase64(String data) throws IOException {
|
||||
if (data.isEmpty()) return Bukkit.getServer().createInventory(null, 0);
|
||||
if (data.isEmpty()) {
|
||||
return Bukkit.getServer().createInventory(null, 0);
|
||||
}
|
||||
|
||||
try {
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
|
||||
@@ -456,7 +473,9 @@ public class Util {
|
||||
* @throws IOException if we was unable to parse the base64 string
|
||||
*/
|
||||
public static ItemStack[] itemStackArrayFromBase64(String data) throws IOException {
|
||||
if (data.isEmpty()) return new ItemStack[]{};
|
||||
if (data.isEmpty()) {
|
||||
return new ItemStack[]{};
|
||||
}
|
||||
|
||||
try {
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
|
||||
@@ -482,28 +501,32 @@ public class Util {
|
||||
|
||||
for (ItemStack item : armor) {
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
else if (item.getType().toString().toLowerCase().contains("helmet"))
|
||||
if (item.getType().toString().toLowerCase().contains("helmet")) {
|
||||
player.getInventory().setHelmet(item);
|
||||
else if (item.getType().toString().toLowerCase().contains("chestplate"))
|
||||
} else if (item.getType().toString().toLowerCase().contains("chestplate")) {
|
||||
player.getInventory().setChestplate(item);
|
||||
else if (item.getType().toString().toLowerCase().contains("leg"))
|
||||
} else if (item.getType().toString().toLowerCase().contains("leg")) {
|
||||
player.getInventory().setLeggings(item);
|
||||
else if (item.getType().toString().toLowerCase().contains("boots"))
|
||||
} else if (item.getType().toString().toLowerCase().contains("boots")) {
|
||||
player.getInventory().setBoots(item);
|
||||
else if (player.getInventory().firstEmpty() == -1)
|
||||
} else if (player.getInventory().firstEmpty() == -1) {
|
||||
player.getWorld().dropItem(player.getLocation(), item);
|
||||
else
|
||||
} else {
|
||||
player.getInventory().addItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
for (ItemStack item : content.getContents()) {
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
else if (player.getInventory().firstEmpty() == -1)
|
||||
if (player.getInventory().firstEmpty() == -1) {
|
||||
player.getWorld().dropItem(player.getLocation(), item);
|
||||
else
|
||||
} else {
|
||||
player.getInventory().addItem(item);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
@@ -23,7 +23,8 @@ import java.util.List;
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public class Cell implements ICell {
|
||||
private final int databaseid;
|
||||
|
||||
private final int databaseId;
|
||||
private final String name;
|
||||
private Prisoner p;
|
||||
private final HashSet<SimpleLocation> signs;
|
||||
@@ -36,7 +37,7 @@ public class Cell implements ICell {
|
||||
* @param name The name of the cell.
|
||||
*/
|
||||
public Cell(String name) {
|
||||
this.databaseid = -1;
|
||||
this.databaseId = -1;
|
||||
this.name = name;
|
||||
this.signs = new HashSet<>();
|
||||
this.changed = false;
|
||||
@@ -49,14 +50,14 @@ public class Cell implements ICell {
|
||||
* @param name The name of the cell.
|
||||
*/
|
||||
public Cell(int id, String name) {
|
||||
this.databaseid = id;
|
||||
this.databaseId = id;
|
||||
this.name = name;
|
||||
this.signs = new HashSet<>();
|
||||
this.changed = false;
|
||||
}
|
||||
|
||||
public int getDatabaseID() {
|
||||
return this.databaseid;
|
||||
return this.databaseId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -117,10 +118,9 @@ public class Cell implements ICell {
|
||||
List<String> invalid = new ArrayList<>();
|
||||
|
||||
for (SimpleLocation s : new HashSet<>(signs))
|
||||
if (s.getLocation().getBlock().getState() instanceof Sign) {
|
||||
}
|
||||
else
|
||||
if (!(s.getLocation().getBlock().getState() instanceof Sign)) {
|
||||
invalid.add(s.toString());
|
||||
}
|
||||
|
||||
return invalid;
|
||||
}
|
||||
@@ -129,8 +129,7 @@ public class Cell implements ICell {
|
||||
List<String> cleaned = new ArrayList<>();
|
||||
|
||||
for (SimpleLocation s : new HashSet<>(signs)) {
|
||||
if (s.getLocation().getBlock().getState() instanceof Sign) {
|
||||
} else {
|
||||
if (!(s.getLocation().getBlock().getState() instanceof Sign)) {
|
||||
changed = true;
|
||||
signs.remove(s);
|
||||
cleaned.add(s.toString());
|
||||
@@ -147,8 +146,7 @@ public class Cell implements ICell {
|
||||
for (SimpleLocation s : new HashSet<>(signs)) {
|
||||
BlockState bs = s.getLocation().getBlock().getState();
|
||||
|
||||
if (bs instanceof Sign) {
|
||||
Sign sign = (Sign) bs;
|
||||
if (bs instanceof Sign sign) {
|
||||
|
||||
if (hasPrisoner()) {
|
||||
String[] lines = Util.replaceAllVariables(p, Util.getSignLines());
|
||||
@@ -157,14 +155,13 @@ public class Cell implements ICell {
|
||||
sign.setLine(1, lines[1]);
|
||||
sign.setLine(2, lines[2]);
|
||||
sign.setLine(3, lines[3]);
|
||||
sign.update(true, false);
|
||||
} else {
|
||||
sign.setLine(0, "");
|
||||
sign.setLine(1, Lang.CELLEMPTYSIGN.get());
|
||||
sign.setLine(2, "");
|
||||
sign.setLine(3, "");
|
||||
sign.update(true, false);
|
||||
}
|
||||
sign.update(true, false);
|
||||
|
||||
updated.add(s.toString());
|
||||
} else {
|
||||
@@ -200,10 +197,14 @@ public class Cell implements ICell {
|
||||
}
|
||||
|
||||
public Chest getChest() {
|
||||
if (this.chest == null) return null;
|
||||
if (this.chest.getLocation().getBlock() == null
|
||||
|| (this.chest.getLocation().getBlock().getType() != Material.CHEST
|
||||
&& this.chest.getLocation().getBlock().getType() != Material.TRAPPED_CHEST)) return null;
|
||||
if (this.chest == null) {
|
||||
return null;
|
||||
}
|
||||
this.chest.getLocation().getBlock();
|
||||
if (this.chest.getLocation().getBlock().getType() != Material.CHEST &&
|
||||
this.chest.getLocation().getBlock().getType() != Material.TRAPPED_CHEST) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (Chest) this.chest.getLocation().getBlock().getState();
|
||||
}
|
||||
@@ -211,14 +212,15 @@ public class Cell implements ICell {
|
||||
public boolean hasChest() {
|
||||
Chest c = getChest();
|
||||
if (c != null) {
|
||||
if (c.getInventory().getSize() >= 40)
|
||||
if (c.getInventory().getSize() >= 40) {
|
||||
return true;
|
||||
else {
|
||||
} else {
|
||||
Bukkit.getLogger().severe("The cell " + this.name + " has chest that isn't a double chest, please fix.");
|
||||
return false;
|
||||
}
|
||||
} else
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean useChest() {
|
||||
|
@@ -4,6 +4,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Represents an instance of a player creating something, whether it be a jail or cell.
|
||||
@@ -184,7 +185,7 @@ public class CreationPlayer {
|
||||
* @param location the in location
|
||||
*/
|
||||
public void setTeleportIn(Location location) {
|
||||
this.inWorld = location.getWorld().getName();
|
||||
this.inWorld = Objects.requireNonNull(location.getWorld()).getName();
|
||||
this.inX = location.getX();
|
||||
this.inY = location.getY();
|
||||
this.inZ = location.getZ();
|
||||
@@ -235,7 +236,7 @@ public class CreationPlayer {
|
||||
* @param location Sets the teleport free {@link Location}
|
||||
*/
|
||||
public void setTeleportFree(Location location) {
|
||||
this.freeWorld = location.getWorld().getName();
|
||||
this.freeWorld = Objects.requireNonNull(location.getWorld()).getName();
|
||||
this.freeX = location.getX();
|
||||
this.freeY = location.getY();
|
||||
this.freeZ = location.getZ();
|
||||
|
@@ -87,7 +87,9 @@ public class Jail {
|
||||
* @param location the {@link Location} of the lowest point
|
||||
*/
|
||||
public void setMinPoint(Location location) {
|
||||
if (this.world.isEmpty()) this.world = location.getWorld().getName();
|
||||
if (this.world.isEmpty()) {
|
||||
this.world = location.getWorld().getName();
|
||||
}
|
||||
|
||||
this.minX = location.getBlockX();
|
||||
this.minY = location.getBlockY();
|
||||
@@ -100,7 +102,9 @@ public class Jail {
|
||||
* @param coords the coordinates of the minimum point
|
||||
*/
|
||||
public void setMinPoint(int[] coords) {
|
||||
if (coords.length != 3) return;
|
||||
if (coords.length != 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.minX = coords[0];
|
||||
this.minY = coords[1];
|
||||
@@ -122,7 +126,9 @@ public class Jail {
|
||||
* @param location the {@link Location} of the maximum point
|
||||
*/
|
||||
public void setMaxPoint(Location location) {
|
||||
if (this.world.isEmpty()) this.world = location.getWorld().getName();
|
||||
if (this.world.isEmpty()) {
|
||||
this.world = location.getWorld().getName();
|
||||
}
|
||||
|
||||
this.maxX = location.getBlockX();
|
||||
this.maxY = location.getBlockY();
|
||||
@@ -142,7 +148,9 @@ public class Jail {
|
||||
* Accepts an array of ints as the coord, where <strong>0 = x</strong>, <strong>1 = y</strong>, <strong>2 = z</strong>.
|
||||
*/
|
||||
public void setMaxPoint(int[] coords) {
|
||||
if (coords.length != 3) return;
|
||||
if (coords.length != 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.maxX = coords[0];
|
||||
this.maxY = coords[1];
|
||||
@@ -174,7 +182,9 @@ public class Jail {
|
||||
* Sets the {@link Location location} of the teleport <strong>in</strong>.
|
||||
*/
|
||||
public void setTeleportIn(Location location) {
|
||||
if (this.world.isEmpty()) this.world = location.getWorld().getName();
|
||||
if (this.world.isEmpty()) {
|
||||
this.world = location.getWorld().getName();
|
||||
}
|
||||
|
||||
this.in = location;
|
||||
}
|
||||
@@ -225,11 +235,16 @@ public class Jail {
|
||||
* Adds a cell to the Jail.
|
||||
*/
|
||||
public boolean addCell(Cell cell, boolean save) {
|
||||
if (save) plugin.getJailIO().saveCell(this, cell, false);
|
||||
if (save) {
|
||||
plugin.getJailIO().saveCell(this, cell, false);
|
||||
}
|
||||
|
||||
//Check if it already exists or not
|
||||
if (this.cells.containsKey(cell.getName())) return false;
|
||||
else this.cells.put(cell.getName(), cell);
|
||||
if (this.cells.containsKey(cell.getName())) {
|
||||
return false;
|
||||
} else {
|
||||
this.cells.put(cell.getName(), cell);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -278,9 +293,11 @@ public class Jail {
|
||||
*/
|
||||
public Cell getCellPrisonerIsIn(UUID uuid) {
|
||||
for (Cell c : cells.values())
|
||||
if (c.hasPrisoner())
|
||||
if (c.getPrisoner().getUUID().equals(uuid))
|
||||
if (c.hasPrisoner()) {
|
||||
if (c.getPrisoner().getUUID().equals(uuid)) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -289,11 +306,10 @@ public class Jail {
|
||||
* Returns the first empty cell, returns null if there aren't any cells or any free cells.
|
||||
*/
|
||||
public Cell getFirstEmptyCell() {
|
||||
for (Cell c : getCells())
|
||||
if (c.hasPrisoner()) {
|
||||
for (Cell cell : getCells())
|
||||
if (!cell.hasPrisoner()) {
|
||||
return cell;
|
||||
}
|
||||
else
|
||||
return c;
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -303,8 +319,9 @@ public class Jail {
|
||||
*/
|
||||
public boolean hasEmptyCell() {
|
||||
for (Cell c : getCells())
|
||||
if (!c.hasPrisoner())
|
||||
if (!c.hasPrisoner()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -369,8 +386,9 @@ public class Jail {
|
||||
HashMap<UUID, Prisoner> all = new HashMap<>(nocellPrisoners); //initalize the temp one to return with the prisoners not in any cells
|
||||
|
||||
for (Cell c : cells.values())
|
||||
if (c.hasPrisoner())
|
||||
if (c.hasPrisoner()) {
|
||||
all.put(c.getPrisoner().getUUID(), c.getPrisoner());
|
||||
}
|
||||
|
||||
return all;
|
||||
}
|
||||
@@ -382,8 +400,9 @@ public class Jail {
|
||||
HashSet<Prisoner> all = new HashSet<>();
|
||||
|
||||
for (Cell c : getCells())
|
||||
if (c.hasPrisoner())
|
||||
if (c.hasPrisoner()) {
|
||||
all.add(c.getPrisoner());
|
||||
}
|
||||
|
||||
return all;
|
||||
}
|
||||
@@ -432,12 +451,16 @@ public class Jail {
|
||||
* @return true if is jailed in a cell, false if not.
|
||||
*/
|
||||
public boolean isJailedInACell(UUID uuid) {
|
||||
if (this.nocellPrisoners.containsKey(uuid)) return false;
|
||||
if (this.nocellPrisoners.containsKey(uuid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Cell c : cells.values())
|
||||
if (c.getPrisoner() != null)
|
||||
if (c.getPrisoner().getUUID().equals(uuid))
|
||||
if (c.getPrisoner() != null) {
|
||||
if (c.getPrisoner().getUUID().equals(uuid)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -450,8 +473,9 @@ public class Jail {
|
||||
*/
|
||||
public Prisoner getPrisonerByLastKnownName(String name) {
|
||||
for (Prisoner p : this.getAllPrisoners().values())
|
||||
if (p.getLastKnownName().equalsIgnoreCase(name))
|
||||
if (p.getLastKnownName().equalsIgnoreCase(name)) {
|
||||
return p;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -463,12 +487,16 @@ public class Jail {
|
||||
* @return the prisoner instance, can be null
|
||||
*/
|
||||
public Prisoner getPrisoner(UUID uuid) {
|
||||
if (this.nocellPrisoners.containsKey(uuid)) return this.nocellPrisoners.get(uuid);
|
||||
if (this.nocellPrisoners.containsKey(uuid)) {
|
||||
return this.nocellPrisoners.get(uuid);
|
||||
}
|
||||
|
||||
for (Cell c : cells.values())
|
||||
if (c.hasPrisoner())
|
||||
if (c.getPrisoner().getUUID().equals(uuid))
|
||||
if (c.hasPrisoner()) {
|
||||
if (c.getPrisoner().getUUID().equals(uuid)) {
|
||||
return c.getPrisoner();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -482,8 +510,11 @@ public class Jail {
|
||||
* @return Distance between the location provided and the teleport in location.
|
||||
*/
|
||||
public double getDistance(Location loc) {
|
||||
if (!loc.getWorld().getName().equalsIgnoreCase(getTeleportIn().getWorld().getName())) return Integer.MAX_VALUE;
|
||||
else return loc.distance(getTeleportIn());
|
||||
if (!loc.getWorld().getName().equalsIgnoreCase(getTeleportIn().getWorld().getName())) {
|
||||
return Integer.MAX_VALUE;
|
||||
} else {
|
||||
return loc.distance(getTeleportIn());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -164,16 +164,21 @@ public class Prisoner {
|
||||
* Finishes the setup of the prisoner data, set to defaults.
|
||||
*/
|
||||
private void finishSetup() {
|
||||
if (jailer == null)
|
||||
if (jailer == null) {
|
||||
jailer = Lang.DEFAULTJAILER.get();
|
||||
if (reason == null)
|
||||
}
|
||||
if (reason == null) {
|
||||
Lang.DEFAULTJAILEDREASON.get();
|
||||
if (inventory == null)
|
||||
}
|
||||
if (inventory == null) {
|
||||
inventory = "";
|
||||
if (armor == null)
|
||||
}
|
||||
if (armor == null) {
|
||||
armor = "";
|
||||
if (previousGameMode == null)
|
||||
}
|
||||
if (previousGameMode == null) {
|
||||
previousGameMode = GameMode.SURVIVAL;
|
||||
}
|
||||
previousPosition = null;
|
||||
}
|
||||
|
||||
@@ -372,14 +377,18 @@ public class Prisoner {
|
||||
* Gets the previous location of this player, separated by a comma.
|
||||
*/
|
||||
public String getPreviousLocationString() {
|
||||
if (previousPosition == null) return "";
|
||||
else if (previousPosition.getWorld() == null) return "";
|
||||
else return previousPosition.getWorld().getName() + "," +
|
||||
if (previousPosition == null) {
|
||||
return "";
|
||||
} else if (previousPosition.getWorld() == null) {
|
||||
return "";
|
||||
} else {
|
||||
return previousPosition.getWorld().getName() + "," +
|
||||
previousPosition.getX() + "," +
|
||||
previousPosition.getY() + "," +
|
||||
previousPosition.getZ() + "," +
|
||||
previousPosition.getYaw() + "," +
|
||||
previousPosition.getPitch();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -393,8 +402,12 @@ public class Prisoner {
|
||||
* Sets the previous location of this player from a comma separated string.
|
||||
*/
|
||||
public void setPreviousPosition(String location) {
|
||||
if (location == null) return;
|
||||
if (location.isEmpty()) return;
|
||||
if (location == null) {
|
||||
return;
|
||||
}
|
||||
if (location.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.changed = true;
|
||||
String[] s = location.split(",");
|
||||
@@ -425,9 +438,13 @@ public class Prisoner {
|
||||
* Sets the previous gamemode of this player based upon the provided string.
|
||||
*/
|
||||
public void setPreviousGameMode(String previous) {
|
||||
if (previous == null) return;
|
||||
else if (previous.isEmpty()) return;
|
||||
else this.previousGameMode = GameMode.valueOf(previous);
|
||||
if (previous == null) {
|
||||
return;
|
||||
} else if (previous.isEmpty()) {
|
||||
return;
|
||||
} else {
|
||||
this.previousGameMode = GameMode.valueOf(previous);
|
||||
}
|
||||
this.changed = true;
|
||||
}
|
||||
|
||||
|
@@ -38,19 +38,26 @@ public class CommandHandler {
|
||||
public List<String> parseTabComplete(JailManager jm, CommandSender sender, String commandLine, String[] args) {
|
||||
List<Command> matches = getMatches(commandLine);
|
||||
|
||||
if (matches.size() != 1) return Collections.emptyList();
|
||||
else {
|
||||
if (matches.size() != 1) {
|
||||
return Collections.emptyList();
|
||||
} else {
|
||||
CommandInfo i = matches.get(0).getClass().getAnnotation(CommandInfo.class);
|
||||
|
||||
//Sender provided too many arguments which means there
|
||||
//is nothing to tab complete
|
||||
if (i.maxArgs() != -1 && i.maxArgs() < args.length) return Collections.emptyList();
|
||||
if (i.maxArgs() != -1 && i.maxArgs() < args.length) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
//Don't return anything if a player is required and they're not a player
|
||||
if (i.needsPlayer() && !(sender instanceof Player)) return Collections.emptyList();
|
||||
if (i.needsPlayer() && !(sender instanceof Player)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
//Don't return anything if they don't have permission
|
||||
if (!sender.hasPermission(i.permission())) return Collections.emptyList();
|
||||
if (!sender.hasPermission(i.permission())) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
//Let the command handle the rest of it
|
||||
return matches.get(0).provideTabCompletions(jm, sender, args);
|
||||
@@ -73,12 +80,12 @@ public class CommandHandler {
|
||||
* <li>Then executes, upon failed execution it sends the usage command.</li>
|
||||
* </ol>
|
||||
*
|
||||
* @param jailmanager The instance of {@link JailManager}.
|
||||
* @param jailManager The instance of {@link JailManager}.
|
||||
* @param sender The sender of the command.
|
||||
* @param commandLine The name of the command.
|
||||
* @param args The arguments passed to the command.
|
||||
*/
|
||||
public void handleCommand(JailManager jailmanager, CommandSender sender, String commandLine, String[] args) {
|
||||
public void handleCommand(JailManager jailManager, CommandSender sender, String commandLine, String[] args) {
|
||||
List<Command> matches = getMatches(commandLine);
|
||||
|
||||
//If no matches were found, send them the unknown command message.
|
||||
@@ -90,8 +97,9 @@ public class CommandHandler {
|
||||
ArrayList<String> args2 = new ArrayList<>(Arrays.asList(args));
|
||||
args2.add(a0);
|
||||
|
||||
if (jailmanager.getPlugin().onCommand(sender, null, j, args2.toArray(new String[0])))
|
||||
if (jailManager.getPlugin().onCommand(sender, null, j, args2.toArray(new String[0]))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
sender.sendMessage(Lang.UNKNOWNCOMMAND.get(commandLine));
|
||||
@@ -135,12 +143,12 @@ public class CommandHandler {
|
||||
// Since everything has been checked and we're all clear, let's execute it.
|
||||
// But if get back false, let's show the usage message.
|
||||
try {
|
||||
if (!c.execute(jailmanager, sender, args)) {
|
||||
if (!c.execute(jailManager, sender, args)) {
|
||||
showUsage(sender, c);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
jailmanager.getPlugin().getLogger().severe("An error occured while handling the command: " + i.usage());
|
||||
jailManager.getPlugin().getLogger().severe("An error occured while handling the command: " + i.usage());
|
||||
showUsage(sender, c);
|
||||
}
|
||||
}
|
||||
@@ -165,7 +173,9 @@ public class CommandHandler {
|
||||
*/
|
||||
private void showUsage(CommandSender sender, Command command) {
|
||||
CommandInfo info = command.getClass().getAnnotation(CommandInfo.class);
|
||||
if (!sender.hasPermission(info.permission())) return;
|
||||
if (!sender.hasPermission(info.permission())) {
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(info.usage());
|
||||
}
|
||||
@@ -183,7 +193,9 @@ public class CommandHandler {
|
||||
|
||||
private void load(Class<? extends Command> c) {
|
||||
CommandInfo info = c.getAnnotation(CommandInfo.class);
|
||||
if (info == null) return;
|
||||
if (info == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
commands.put(info.pattern(), c.newInstance());
|
||||
|
@@ -71,7 +71,9 @@ public class JailHandler {
|
||||
}
|
||||
|
||||
//Skip if the command requires a player and the sender isn't a player
|
||||
if (i.needsPlayer() && !(sender instanceof Player)) continue;
|
||||
if (i.needsPlayer() && !(sender instanceof Player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//If the sender has permission to the command
|
||||
//and the first argument (sub command) is empty OR
|
||||
@@ -86,10 +88,11 @@ public class JailHandler {
|
||||
|
||||
//If the results doesn't contain anything and they have permission to jail someone
|
||||
//then send let the jail command provide the tab completion
|
||||
if (results.isEmpty() && hasJailPermission)
|
||||
if (results.isEmpty() && hasJailPermission) {
|
||||
return getMatches("jail").get(0).provideTabCompletions(jm, sender, args);
|
||||
else
|
||||
} else {
|
||||
return results;
|
||||
}
|
||||
} else {
|
||||
String arg0 = args[0].toLowerCase();
|
||||
boolean hasJailPermission = false;
|
||||
@@ -105,17 +108,25 @@ public class JailHandler {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!arg0.toLowerCase().matches(i.pattern())) continue;
|
||||
if (!arg0.toLowerCase().matches(i.pattern())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//Sender provided too many arguments which means there
|
||||
//is nothing to tab complete
|
||||
if (i.maxArgs() != -1 && i.maxArgs() < args.length - 1) continue;
|
||||
if (i.maxArgs() != -1 && i.maxArgs() < args.length - 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//Skip if the command requires a player and the sender isn't a player
|
||||
if (i.needsPlayer() && !(sender instanceof Player)) continue;
|
||||
if (i.needsPlayer() && !(sender instanceof Player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//If the sender doesn't have permission, we won't send them further
|
||||
if (!sender.hasPermission(i.permission())) continue;
|
||||
if (!sender.hasPermission(i.permission())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return c.provideTabCompletions(jm, sender, args);
|
||||
}
|
||||
@@ -123,8 +134,9 @@ public class JailHandler {
|
||||
//By the time it has reached here no other command matched
|
||||
//which means they are probably jailing someone, or trying to
|
||||
//so let's check permission first and go from there.
|
||||
if (hasJailPermission)
|
||||
if (hasJailPermission) {
|
||||
return getMatches("jail").get(0).provideTabCompletions(jm, sender, args);
|
||||
}
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
@@ -149,12 +161,12 @@ public class JailHandler {
|
||||
* @param args The arguments passed to the command.
|
||||
*/
|
||||
public boolean parseCommand(JailManager jailmanager, CommandSender sender, String[] args) {
|
||||
Command c;
|
||||
Command command;
|
||||
|
||||
//If they didn't provide any arguments (aka just: /jail) then we will need to send them some help
|
||||
if (args.length == 0) {
|
||||
//TODO: Create the help page(s)
|
||||
c = getMatches("jail").get(0);
|
||||
command = getMatches("jail").get(0);
|
||||
|
||||
} else {
|
||||
//Get the matches from the first argument passed
|
||||
@@ -162,7 +174,7 @@ public class JailHandler {
|
||||
|
||||
if (matches.isEmpty()) {
|
||||
//No matches found, thus it is more likely than not they are trying to jail someone
|
||||
c = getMatches("jail").get(0);
|
||||
command = getMatches("jail").get(0);
|
||||
|
||||
} else if (matches.size() > 1) {
|
||||
//If there was found more than one match
|
||||
@@ -173,21 +185,21 @@ public class JailHandler {
|
||||
|
||||
} else {
|
||||
//Only one match was found, so let's continue
|
||||
c = matches.get(0);
|
||||
command = matches.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
CommandInfo i = c.getClass().getAnnotation(CommandInfo.class);
|
||||
CommandInfo commandInfo = command.getClass().getAnnotation(CommandInfo.class);
|
||||
|
||||
// First, let's check if the sender has permission for the command.
|
||||
if (!i.permission().isEmpty() && !sender.hasPermission(i.permission())) {
|
||||
jailmanager.getPlugin().debug("Sender has no permission: " + i.permission());
|
||||
sender.sendMessage(Lang.NOPERMISSION.get() + (jailmanager.getPlugin().inDebug() ? " (" + i.permission() + ")" : ""));
|
||||
if (!commandInfo.permission().isEmpty() && !sender.hasPermission(commandInfo.permission())) {
|
||||
jailmanager.getPlugin().debug("Sender has no permission: " + commandInfo.permission());
|
||||
sender.sendMessage(Lang.NOPERMISSION.get() + (jailmanager.getPlugin().inDebug() ? " (" + commandInfo.permission() + ")" : ""));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Next, let's check if we need a player and then if the sender is actually a player
|
||||
if (i.needsPlayer() && !(sender instanceof Player)) {
|
||||
if (commandInfo.needsPlayer() && !(sender instanceof Player)) {
|
||||
jailmanager.getPlugin().debug("Sender is not a player.");
|
||||
sender.sendMessage(Lang.PLAYERCONTEXTREQUIRED.get());
|
||||
return true;
|
||||
@@ -195,36 +207,34 @@ public class JailHandler {
|
||||
|
||||
// Now, let's check the size of the arguments passed. If it is shorter than the minimum required args, let's show the usage.
|
||||
// The reason we are subtracting one is because the command is now `/jail <subcommand>` and the subcommand is viewed as an argument
|
||||
if (args.length - 1 < i.minimumArgs()) {
|
||||
if (args.length - 1 < commandInfo.minimumArgs()) {
|
||||
jailmanager.getPlugin().debug("Sender didn't provide enough arguments.");
|
||||
showUsage(sender, c);
|
||||
showUsage(sender, command);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Then, if the maximumArgs doesn't equal -1, we need to check if the size of the arguments passed is greater than the maximum args.
|
||||
// The reason we are subtracting one is because the command is now `/jail <subcommand>` and the subcommand is viewed as an argument
|
||||
if (i.maxArgs() != -1 && i.maxArgs() < args.length - 1) {
|
||||
if (commandInfo.maxArgs() != -1 && commandInfo.maxArgs() < args.length - 1) {
|
||||
jailmanager.getPlugin().debug("Sender provided too many arguments.");
|
||||
showUsage(sender, c);
|
||||
showUsage(sender, command);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Since everything has been checked and we're all clear, let's execute it.
|
||||
// But if get back false, let's show the usage message.
|
||||
try {
|
||||
if (!c.execute(jailmanager, sender, args)) {
|
||||
showUsage(sender, c);
|
||||
return true;
|
||||
} else {
|
||||
return true;
|
||||
if (!command.execute(jailmanager, sender, args)) {
|
||||
showUsage(sender, command);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
if (jailmanager.getPlugin().inDebug()) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
jailmanager.getPlugin().getLogger().severe("An error occured while handling the command: " + i.usage());
|
||||
showUsage(sender, c);
|
||||
jailmanager.getPlugin().getLogger().severe("An error occured while handling the command: " + commandInfo.usage());
|
||||
showUsage(sender, command);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -249,7 +259,9 @@ public class JailHandler {
|
||||
*/
|
||||
private void showUsage(CommandSender sender, Command command) {
|
||||
CommandInfo info = command.getClass().getAnnotation(CommandInfo.class);
|
||||
if (!sender.hasPermission(info.permission())) return;
|
||||
if (!sender.hasPermission(info.permission())) {
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(info.usage());
|
||||
}
|
||||
@@ -286,7 +298,9 @@ public class JailHandler {
|
||||
|
||||
private void load(Class<? extends Command> command) {
|
||||
CommandInfo info = command.getAnnotation(CommandInfo.class);
|
||||
if (info == null) return;
|
||||
if (info == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
commands.put(info.pattern(), command.newInstance());
|
||||
|
@@ -48,9 +48,14 @@ public class HandCuffCommand implements Command {
|
||||
|
||||
for (Player p : jm.getPlugin().getServer().getOnlinePlayers())
|
||||
if (!jm.getPlugin().getHandCuffManager().isHandCuffed(p.getUniqueId())) //don't send someone who is already handcuffed
|
||||
{
|
||||
if (!p.hasPermission("jail.cantbehandcuffed")) //don't send someone who can't be handcuffed
|
||||
if (args[0].isEmpty() || StringUtil.startsWithIgnoreCase(p.getName(), args[0]))
|
||||
{
|
||||
if (args[0].isEmpty() || StringUtil.startsWithIgnoreCase(p.getName(), args[0])) {
|
||||
results.add(p.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(results);
|
||||
|
||||
|
@@ -42,8 +42,11 @@ public class UnHandCuffCommand implements Command {
|
||||
|
||||
for (Player p : jm.getPlugin().getServer().getOnlinePlayers())
|
||||
if (jm.getPlugin().getHandCuffManager().isHandCuffed(p.getUniqueId())) //don't send someone who isn't already handcuffed
|
||||
if (args[0].isEmpty() || StringUtil.startsWithIgnoreCase(p.getName(), args[0]))
|
||||
{
|
||||
if (args[0].isEmpty() || StringUtil.startsWithIgnoreCase(p.getName(), args[0])) {
|
||||
results.add(p.getName());
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(results);
|
||||
|
||||
|
@@ -71,8 +71,9 @@ public class UnJailCommand implements Command {
|
||||
List<String> results = new ArrayList<>();
|
||||
|
||||
for (Prisoner p : jm.getAllPrisoners().values())
|
||||
if (args[0].isEmpty() || StringUtil.startsWithIgnoreCase(p.getLastKnownName(), args[0]))
|
||||
if (args[0].isEmpty() || StringUtil.startsWithIgnoreCase(p.getLastKnownName(), args[0])) {
|
||||
results.add(p.getLastKnownName());
|
||||
}
|
||||
|
||||
Collections.sort(results);
|
||||
|
||||
|
@@ -46,8 +46,9 @@ public class UnJailForceCommand implements Command {
|
||||
List<String> results = new ArrayList<>();
|
||||
|
||||
for (Prisoner p : jm.getAllPrisoners().values())
|
||||
if (args[0].isEmpty() || StringUtil.startsWithIgnoreCase(p.getLastKnownName(), args[0]))
|
||||
if (args[0].isEmpty() || StringUtil.startsWithIgnoreCase(p.getLastKnownName(), args[0])) {
|
||||
results.add(p.getLastKnownName());
|
||||
}
|
||||
|
||||
Collections.sort(results);
|
||||
|
||||
|
@@ -54,11 +54,14 @@ public class JailCheckCommand implements Command {
|
||||
|
||||
Collections.sort(results);
|
||||
|
||||
if (args.length == 2)
|
||||
if (args.length == 2) {
|
||||
for (Player p : jm.getPlugin().getServer().getOnlinePlayers())
|
||||
if (args[1].isEmpty() || StringUtil.startsWithIgnoreCase(p.getName(), args[1]))
|
||||
if (!results.contains(p.getName()))
|
||||
if (args[1].isEmpty() || StringUtil.startsWithIgnoreCase(p.getName(), args[1])) {
|
||||
if (!results.contains(p.getName())) {
|
||||
results.add(p.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
@@ -61,7 +61,9 @@ public class JailCommand implements Command {
|
||||
List<String> arguments = new LinkedList<>(Arrays.asList(args));
|
||||
//Only add the "-p" if it doesn't already contain it, this way people can do `/jail -p check` in the event someone
|
||||
//has a name which is one of our subcommands
|
||||
if (!arguments.contains("-p")) arguments.add(0, "-p");
|
||||
if (!arguments.contains("-p")) {
|
||||
arguments.add(0, "-p");
|
||||
}
|
||||
|
||||
Jailing params;
|
||||
|
||||
@@ -233,10 +235,11 @@ public class JailCommand implements Command {
|
||||
|
||||
//check if the event is cancelled
|
||||
if (event.isCancelled()) {
|
||||
if (event.getCancelledMessage().isEmpty())
|
||||
if (event.getCancelledMessage().isEmpty()) {
|
||||
sender.sendMessage(Lang.CANCELLEDBYANOTHERPLUGIN.get(params.getPlayer()));
|
||||
else
|
||||
} else {
|
||||
sender.sendMessage(event.getCancelledMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -278,20 +281,26 @@ public class JailCommand implements Command {
|
||||
String previous = args[args.length - 2];
|
||||
jm.getPlugin().debug("args[args.length - 2]: " + previous);
|
||||
|
||||
if (previous.equalsIgnoreCase("-p")) return getPlayers(jm, last);
|
||||
else if (previous.equalsIgnoreCase("-j")) return jm.getJailsByPrefix(last);
|
||||
else if (previous.equalsIgnoreCase("-c")) {
|
||||
if (previous.equalsIgnoreCase("-p")) {
|
||||
return getPlayers(jm, last);
|
||||
} else if (previous.equalsIgnoreCase("-j")) {
|
||||
return jm.getJailsByPrefix(last);
|
||||
} else if (previous.equalsIgnoreCase("-c")) {
|
||||
//Since we need to give them a list of the cells in a jail
|
||||
//we need to get the jail they're giving
|
||||
int jailIndex = ArrayUtils.indexOf(args, "-j");
|
||||
if (jailIndex != -1) {
|
||||
String jail = args[jailIndex + 1];
|
||||
jm.getPlugin().debug("The jail is: " + jail);
|
||||
if (jm.isValidJail(jail)) return getCells(jm, jail, last);
|
||||
if (jm.isValidJail(jail)) {
|
||||
return getCells(jm, jail, last);
|
||||
}
|
||||
}
|
||||
} else if (previous.endsWith("r")) return Collections.emptyList();
|
||||
else if (!commands.contains(args[args.length - 2].replace("-", "")))
|
||||
} else if (previous.endsWith("r")) {
|
||||
return Collections.emptyList();
|
||||
} else if (!commands.contains(args[args.length - 2].replace("-", ""))) {
|
||||
return Util.getUnusedItems(commands, args, false);
|
||||
}
|
||||
} else {
|
||||
return getPlayers(jm, last);
|
||||
}
|
||||
@@ -312,9 +321,12 @@ public class JailCommand implements Command {
|
||||
List<String> results = new ArrayList<>();
|
||||
|
||||
for (Player p : jm.getPlugin().getServer().getOnlinePlayers())
|
||||
if (first.isEmpty() || StringUtil.startsWithIgnoreCase(p.getName(), first))
|
||||
if (first.isEmpty() || StringUtil.startsWithIgnoreCase(p.getName(), first)) {
|
||||
if (!jm.isPlayerJailed(p.getUniqueId()) && !p.hasPermission(noJailPermission)) //don't send back them if they're already jailed or can't be jailed
|
||||
{
|
||||
results.add(p.getName());
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(results);
|
||||
jm.getPlugin().debug("The list we're returning is: " + Util.getStringFromList(", ", results));
|
||||
@@ -326,8 +338,9 @@ public class JailCommand implements Command {
|
||||
List<String> results = new ArrayList<>();
|
||||
|
||||
for (Cell c : jm.getJail(jail).getCells())
|
||||
if (!c.hasPrisoner() && (cell.isEmpty() || StringUtil.startsWithIgnoreCase(c.getName(), cell)))
|
||||
if (!c.hasPrisoner() && (cell.isEmpty() || StringUtil.startsWithIgnoreCase(c.getName(), cell))) {
|
||||
results.add(c.getName());
|
||||
}
|
||||
|
||||
Collections.sort(results);
|
||||
|
||||
|
@@ -46,7 +46,9 @@ public class JailCreateCellCommand implements Command {
|
||||
Jail j = jm.getJail(jail);
|
||||
|
||||
//If they didn't provide a cell name, let's provide one ourself.
|
||||
if (cell.isEmpty()) cell = "cell_n" + (j.getCellCount() + 1);
|
||||
if (cell.isEmpty()) {
|
||||
cell = "cell_n" + (j.getCellCount() + 1);
|
||||
}
|
||||
|
||||
if (j.getCell(cell) == null) {
|
||||
if (jm.addCreatingCell(name, jail, cell)) {
|
||||
@@ -67,7 +69,9 @@ public class JailCreateCellCommand implements Command {
|
||||
|
||||
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) {
|
||||
//We shouldn't provide when they want a cell name
|
||||
if (args.length >= 3) return Collections.emptyList();
|
||||
if (args.length >= 3) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return jm.getJailsByPrefix(args.length == 2 ? args[1] : "");
|
||||
}
|
||||
|
@@ -50,8 +50,9 @@ public class JailDeleteCellCommand implements Command {
|
||||
Jail j = jm.getJail(args[1]);
|
||||
|
||||
for (Cell c : j.getCells())
|
||||
if (args[2].isEmpty() || StringUtil.startsWithIgnoreCase(c.getName(), args[2]))
|
||||
if (args[2].isEmpty() || StringUtil.startsWithIgnoreCase(c.getName(), args[2])) {
|
||||
results.add(c.getName());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@@ -32,10 +32,11 @@ public class JailListCommand implements Command {
|
||||
if (args.length == 1) {
|
||||
//No jail provided, so give them a list of the jails
|
||||
for (Jail j : jm.getJails()) {
|
||||
if (j.isEnabled())
|
||||
if (j.isEnabled()) {
|
||||
sender.sendMessage(ChatColor.BLUE + " " + j.getName() + " (" + j.getAllPrisoners().size() + ")");
|
||||
else
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + " " + j.getName() + " (" + j.getAllPrisoners().size() + ") - WORLD UNLOADED");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Jail j = jm.getJail(args[1]);
|
||||
|
@@ -29,10 +29,11 @@ public class JailMuteCommand implements Command {
|
||||
jm.getPrisonerByLastKnownName(args[1]).setMuted(muted);
|
||||
|
||||
//Send the message to the sender based upon whether they are muted or unmuted
|
||||
if (muted)
|
||||
if (muted) {
|
||||
sender.sendMessage(Lang.NOWMUTED.get(args[1]));
|
||||
else
|
||||
} else {
|
||||
sender.sendMessage(Lang.NOWUNMUTED.get(args[1]));
|
||||
}
|
||||
} else {
|
||||
//The player provided is not jailed, so let's tell the sender that
|
||||
sender.sendMessage(Lang.NOTJAILED.get(args[1]));
|
||||
@@ -45,8 +46,9 @@ public class JailMuteCommand implements Command {
|
||||
if (args.length == 2) {
|
||||
List<String> results = new ArrayList<>();
|
||||
for (Player p : jm.getPlugin().getServer().getOnlinePlayers())
|
||||
if (StringUtil.startsWithIgnoreCase(p.getName(), args[1].toLowerCase()))
|
||||
if (StringUtil.startsWithIgnoreCase(p.getName(), args[1].toLowerCase())) {
|
||||
results.add(p.getName());
|
||||
}
|
||||
|
||||
Collections.sort(results);
|
||||
return results;
|
||||
|
@@ -216,9 +216,14 @@ public class JailPayCommand implements Command {
|
||||
List<String> results = new ArrayList<>();
|
||||
for (Prisoner p : jm.getAllPrisoners().values())
|
||||
if (!p.isOfflinePending()) //Don't list if they're offline pending
|
||||
{
|
||||
if (p.getRemainingTime() != -1) //Don't list if they're jailed forever
|
||||
if (StringUtil.startsWithIgnoreCase(p.getLastKnownName(), args[2]))
|
||||
{
|
||||
if (StringUtil.startsWithIgnoreCase(p.getLastKnownName(), args[2])) {
|
||||
results.add(p.getLastKnownName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(results);
|
||||
|
||||
|
@@ -108,8 +108,9 @@ public class JailSignsCommand implements Command {
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) {
|
||||
@@ -118,17 +119,20 @@ public class JailSignsCommand implements Command {
|
||||
switch (args.length) {
|
||||
case 2:
|
||||
for (String s : options)
|
||||
if (args[1].isEmpty() || StringUtil.startsWithIgnoreCase(s, args[1]))
|
||||
if (args[1].isEmpty() || StringUtil.startsWithIgnoreCase(s, args[1])) {
|
||||
results.add(s);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
results.addAll(jm.getJailsByPrefix(args[2]));
|
||||
break;
|
||||
default:
|
||||
if (jm.isValidJail(args[2]))
|
||||
if (jm.isValidJail(args[2])) {
|
||||
for (Cell c : jm.getJail(args[2]).getCells())
|
||||
if (!Util.isStringInsideArray(c.getName(), args))
|
||||
if (!Util.isStringInsideArray(c.getName(), args)) {
|
||||
results.add(c.getName());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@@ -64,8 +64,9 @@ public class JailTeleInCommand implements Command {
|
||||
List<String> results = new ArrayList<>();
|
||||
|
||||
for (Player p : jm.getPlugin().getServer().getOnlinePlayers())
|
||||
if (args[2].isEmpty() || StringUtil.startsWithIgnoreCase(p.getName(), args[2]))
|
||||
if (args[2].isEmpty() || StringUtil.startsWithIgnoreCase(p.getName(), args[2])) {
|
||||
results.add(p.getName());
|
||||
}
|
||||
|
||||
Collections.sort(results);
|
||||
|
||||
|
@@ -64,8 +64,9 @@ public class JailTeleOutCommand implements Command {
|
||||
List<String> results = new ArrayList<>();
|
||||
|
||||
for (Player p : jm.getPlugin().getServer().getOnlinePlayers())
|
||||
if (args[2].isEmpty() || StringUtil.startsWithIgnoreCase(p.getName(), args[2]))
|
||||
if (args[2].isEmpty() || StringUtil.startsWithIgnoreCase(p.getName(), args[2])) {
|
||||
results.add(p.getName());
|
||||
}
|
||||
|
||||
Collections.sort(results);
|
||||
|
||||
|
@@ -65,13 +65,15 @@ public class JailTimeCommand implements Command {
|
||||
switch (args.length) {
|
||||
case 2:
|
||||
for (String s : options)
|
||||
if (args[1].isEmpty() || StringUtil.startsWithIgnoreCase(s, args[1]))
|
||||
if (args[1].isEmpty() || StringUtil.startsWithIgnoreCase(s, args[1])) {
|
||||
results.add(s);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
for (Prisoner p : jm.getAllPrisoners().values())
|
||||
if (StringUtil.startsWithIgnoreCase(p.getLastKnownName(), args[2]))
|
||||
if (StringUtil.startsWithIgnoreCase(p.getLastKnownName(), args[2])) {
|
||||
results.add(p.getLastKnownName());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@@ -65,8 +65,9 @@ public class JailTransferAllCommand implements Command {
|
||||
List<String> results = new ArrayList<>();
|
||||
|
||||
for (Jail j : jm.getJails())
|
||||
if (!j.getName().equalsIgnoreCase(args[1]) && (args[2].isEmpty() || StringUtil.startsWithIgnoreCase(j.getName(), args[2])))
|
||||
if (!j.getName().equalsIgnoreCase(args[1]) && (args[2].isEmpty() || StringUtil.startsWithIgnoreCase(j.getName(), args[2]))) {
|
||||
results.add(j.getName());
|
||||
}
|
||||
|
||||
Collections.sort(results);
|
||||
|
||||
|
@@ -153,19 +153,24 @@ public class JailTransferCommand implements Command {
|
||||
String previous = args[args.length - 2];
|
||||
jm.getPlugin().debug("args[args.length - 2]: " + previous);
|
||||
|
||||
if (previous.equalsIgnoreCase("-p")) return getPlayers(jm, last);
|
||||
else if (previous.equalsIgnoreCase("-j")) return jm.getJailsByPrefix(last);
|
||||
else if (previous.equalsIgnoreCase("-c")) {
|
||||
if (previous.equalsIgnoreCase("-p")) {
|
||||
return getPlayers(jm, last);
|
||||
} else if (previous.equalsIgnoreCase("-j")) {
|
||||
return jm.getJailsByPrefix(last);
|
||||
} else if (previous.equalsIgnoreCase("-c")) {
|
||||
//Since we need to give them a list of the cells in a jail
|
||||
//we need to get the jail they're giving
|
||||
int jailIndex = ArrayUtils.indexOf(args, "-j");
|
||||
if (jailIndex != -1) {
|
||||
String jail = args[jailIndex + 1];
|
||||
jm.getPlugin().debug("The jail is: " + jail);
|
||||
if (jm.isValidJail(jail)) return getCells(jm, jail, last);
|
||||
if (jm.isValidJail(jail)) {
|
||||
return getCells(jm, jail, last);
|
||||
}
|
||||
}
|
||||
} else if (!commands.contains(args[args.length - 2].replace("-", "")))
|
||||
} else if (!commands.contains(args[args.length - 2].replace("-", ""))) {
|
||||
return Util.getUnusedItems(commands, args, true);
|
||||
}
|
||||
}
|
||||
} else if (last.equalsIgnoreCase("-")) {
|
||||
//add some smart checking so that it only returns a list of what isn't already
|
||||
@@ -182,8 +187,9 @@ public class JailTransferCommand implements Command {
|
||||
List<String> results = new ArrayList<>();
|
||||
|
||||
for (Player p : jm.getPlugin().getServer().getOnlinePlayers())
|
||||
if (first.isEmpty() || StringUtil.startsWithIgnoreCase(p.getName(), first))
|
||||
if (first.isEmpty() || StringUtil.startsWithIgnoreCase(p.getName(), first)) {
|
||||
results.add(p.getName());
|
||||
}
|
||||
|
||||
Collections.sort(results);
|
||||
|
||||
@@ -194,8 +200,9 @@ public class JailTransferCommand implements Command {
|
||||
List<String> results = new ArrayList<>();
|
||||
|
||||
for (Cell c : jm.getJail(jail).getCells())
|
||||
if (!c.hasPrisoner() && (cell.isEmpty() || StringUtil.startsWithIgnoreCase(c.getName(), cell)))
|
||||
if (!c.hasPrisoner() && (cell.isEmpty() || StringUtil.startsWithIgnoreCase(c.getName(), cell))) {
|
||||
results.add(c.getName());
|
||||
}
|
||||
|
||||
Collections.sort(results);
|
||||
|
||||
|
@@ -111,13 +111,15 @@ public class JailVoteCommand implements Command {
|
||||
switch (args.length) {
|
||||
case 2:
|
||||
for (Player p : jm.getPlugin().getServer().getOnlinePlayers())
|
||||
if (args[1].isEmpty() || StringUtil.startsWithIgnoreCase(p.getName(), args[1]))
|
||||
if (args[1].isEmpty() || StringUtil.startsWithIgnoreCase(p.getName(), args[1])) {
|
||||
results.add(p.getName());
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
for (String s : options)
|
||||
if (args[2].isEmpty() || StringUtil.startsWithIgnoreCase(s, args[2]))
|
||||
if (args[2].isEmpty() || StringUtil.startsWithIgnoreCase(s, args[2])) {
|
||||
results.add(s);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@@ -583,7 +583,9 @@ public enum Lang {
|
||||
public String get(String... variables) {
|
||||
String message = lang.getString(path);
|
||||
|
||||
if (message == null) return "";
|
||||
if (message == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
for (int i = 0; i < variables.length; i++) {
|
||||
message = message.replaceAll("%" + i + "%", variables[i]);
|
||||
|
@@ -3,6 +3,7 @@ package com.graywolf336.jail.events;
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Event thrown after the plugin is reloaded, internal usage only.
|
||||
@@ -33,7 +34,7 @@ public class JailPluginReloadedEvent extends Event {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.interfaces.ICell;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Event thrown when a prisoner is offline put will be put into jail next time they come online.
|
||||
@@ -84,7 +85,7 @@ public class OfflinePrisonerJailedEvent extends Event {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Event thrown before we a player is jailed by someone hitting them with a {@link Stick jail stick}.
|
||||
@@ -148,7 +149,7 @@ public class PrePrisonerJailedByJailStickEvent extends Event implements Cancella
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Event thrown before we are jailing a player, both offline and online players.
|
||||
@@ -163,7 +164,7 @@ public class PrePrisonerJailedEvent extends Event implements Cancellable {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import com.graywolf336.jail.interfaces.ICell;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Event thrown after a prisoner is released.
|
||||
@@ -81,7 +82,7 @@ public class PrePrisonerReleasedEvent extends Event {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Event thrown before we transfer a prisoner, both offline and online prisoner.
|
||||
@@ -95,8 +96,11 @@ public class PrePrisonerTransferredEvent extends Event implements Cancellable {
|
||||
* Will return null if the cell is not in the targetJail.
|
||||
*/
|
||||
public Cell getTargetCell() {
|
||||
if (this.targetJail.isValidCell(this.targetCell.getName())) return this.targetCell;
|
||||
else return null;
|
||||
if (this.targetJail.isValidCell(this.targetCell.getName())) {
|
||||
return this.targetCell;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,7 +196,7 @@ public class PrePrisonerTransferredEvent extends Event implements Cancellable {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Event thrown when a prisoner dies.
|
||||
@@ -86,7 +87,7 @@ public class PrisonerDeathEvent extends Event {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import com.graywolf336.jail.beans.Prisoner;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Event thrown after a prisoner is put into jail.
|
||||
@@ -95,7 +96,7 @@ public class PrisonerJailedEvent extends Event {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import com.graywolf336.jail.beans.Prisoner;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Event thrown after a prisoner is released.
|
||||
@@ -81,7 +82,7 @@ public class PrisonerReleasedEvent extends Event {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Event thrown when a prisoner's time changes.
|
||||
@@ -133,7 +134,7 @@ public class PrisonerTimeChangeEvent extends Event implements Cancellable {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import com.graywolf336.jail.beans.Prisoner;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Event thrown after we transfer a prisoner, both an offline and an online prisoner.
|
||||
@@ -80,8 +81,11 @@ public class PrisonerTransferredEvent extends Event {
|
||||
* Will return null if the cell is not in the targetJail.
|
||||
*/
|
||||
public Cell getTargetCell() {
|
||||
if (this.targetJail.isValidCell(this.targetCell.getName())) return this.targetCell;
|
||||
else return null;
|
||||
if (this.targetJail.isValidCell(this.targetCell.getName())) {
|
||||
return this.targetCell;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,7 +120,7 @@ public class PrisonerTransferredEvent extends Event {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package com.graywolf336.jail.exceptions;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* The exception thrown trying to unjail via a thread that is NOT the primary thread.
|
||||
*
|
||||
@@ -8,6 +10,7 @@ package com.graywolf336.jail.exceptions;
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public class AsyncUnJailingNotSupportedException extends Exception {
|
||||
@Serial
|
||||
private static final long serialVersionUID = -1540695375715404835L;
|
||||
|
||||
/**
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package com.graywolf336.jail.exceptions;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* The exception thrown when a cell is required but wasn't provided.
|
||||
*
|
||||
@@ -8,6 +10,7 @@ package com.graywolf336.jail.exceptions;
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public class CellRequiredException extends Exception {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 6496748770371151376L;
|
||||
|
||||
/**
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package com.graywolf336.jail.exceptions;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* The exception thrown when a jail is required but wasn't provided.
|
||||
*
|
||||
@@ -8,6 +10,7 @@ package com.graywolf336.jail.exceptions;
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public class JailRequiredException extends Exception {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1046287197309037470L;
|
||||
|
||||
/**
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package com.graywolf336.jail.exceptions;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* The exception thrown when a prisoner is already jailed.
|
||||
*
|
||||
@@ -8,6 +10,7 @@ package com.graywolf336.jail.exceptions;
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public class PrisonerAlreadyJailedException extends Exception {
|
||||
@Serial
|
||||
private static final long serialVersionUID = -5830449694077279409L;
|
||||
|
||||
/**
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package com.graywolf336.jail.exceptions;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* The exception thrown when a prisoner's data is required but wasn't provided.
|
||||
*
|
||||
@@ -8,6 +10,7 @@ package com.graywolf336.jail.exceptions;
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public class PrisonerRequiredException extends Exception {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 5289068334047189357L;
|
||||
|
||||
/**
|
||||
|
@@ -23,10 +23,18 @@ public class CellSignListener implements Listener {
|
||||
pl = plugin;
|
||||
List<String> lines = pl.getConfig().getStringList(Settings.CELLSIGNLINES.getPath());
|
||||
|
||||
if (lines.size() >= 1) lineOne = lines.get(0);
|
||||
if (lines.size() >= 2) lineTwo = lines.get(1);
|
||||
if (lines.size() >= 3) lineThree = lines.get(2);
|
||||
if (lines.size() >= 4) lineFour = lines.get(3);
|
||||
if (lines.size() >= 1) {
|
||||
lineOne = lines.get(0);
|
||||
}
|
||||
if (lines.size() >= 2) {
|
||||
lineTwo = lines.get(1);
|
||||
}
|
||||
if (lines.size() >= 3) {
|
||||
lineThree = lines.get(2);
|
||||
}
|
||||
if (lines.size() >= 4) {
|
||||
lineFour = lines.get(3);
|
||||
}
|
||||
|
||||
try {
|
||||
Util.updateSignLinesCache(new String[]{lineOne, lineTwo, lineThree, lineFour});
|
||||
@@ -87,10 +95,18 @@ public class CellSignListener implements Listener {
|
||||
lineThree = "";
|
||||
lineFour = "";
|
||||
|
||||
if (lines.size() >= 1) lineOne = lines.get(0);
|
||||
if (lines.size() >= 2) lineTwo = lines.get(1);
|
||||
if (lines.size() >= 3) lineThree = lines.get(2);
|
||||
if (lines.size() >= 4) lineFour = lines.get(3);
|
||||
if (lines.size() >= 1) {
|
||||
lineOne = lines.get(0);
|
||||
}
|
||||
if (lines.size() >= 2) {
|
||||
lineTwo = lines.get(1);
|
||||
}
|
||||
if (lines.size() >= 3) {
|
||||
lineThree = lines.get(2);
|
||||
}
|
||||
if (lines.size() >= 4) {
|
||||
lineFour = lines.get(3);
|
||||
}
|
||||
|
||||
Util.updateSignLinesCache(new String[]{lineOne, lineTwo, lineThree, lineFour});
|
||||
}
|
||||
|
@@ -15,57 +15,64 @@ import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class HandCuffListener implements Listener {
|
||||
private final JailMain pl;
|
||||
|
||||
private final JailMain jailMain;
|
||||
private final HashMap<String, Location> tos;
|
||||
|
||||
public HandCuffListener(JailMain plugin) {
|
||||
this.pl = plugin;
|
||||
this.jailMain = plugin;
|
||||
this.tos = new HashMap<>();
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
if (false) return;
|
||||
if (false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) {
|
||||
Location to = pl.getHandCuffManager().getLocation(event.getPlayer().getUniqueId());
|
||||
if (jailMain.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) {
|
||||
Location to = jailMain.getHandCuffManager().getLocation(event.getPlayer().getUniqueId());
|
||||
to.setPitch(event.getTo().getPitch());
|
||||
to.setYaw(event.getTo().getYaw());
|
||||
|
||||
tos.put(event.getPlayer().getName(), to);
|
||||
event.getPlayer().teleport(to);
|
||||
|
||||
if (System.currentTimeMillis() >= pl.getHandCuffManager().getNextMessageTime(event.getPlayer().getUniqueId())) {
|
||||
if (System.currentTimeMillis() >= jailMain.getHandCuffManager().getNextMessageTime(event.getPlayer().getUniqueId())) {
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and cant move!");
|
||||
pl.getHandCuffManager().updateNextTime(event.getPlayer().getUniqueId());
|
||||
jailMain.getHandCuffManager().updateNextTime(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
if (false) return;
|
||||
if (false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId()) && event.getTo() != tos.get(event.getPlayer().getName())) {
|
||||
Location to = pl.getHandCuffManager().getLocation(event.getPlayer().getUniqueId());
|
||||
if (jailMain.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId()) && event.getTo() != tos.get(event.getPlayer().getName())) {
|
||||
Location to = jailMain.getHandCuffManager().getLocation(event.getPlayer().getUniqueId());
|
||||
to.setPitch(event.getTo().getPitch());
|
||||
to.setYaw(event.getTo().getYaw());
|
||||
|
||||
tos.put(event.getPlayer().getName(), to);
|
||||
event.getPlayer().teleport(to);
|
||||
|
||||
if (System.currentTimeMillis() >= pl.getHandCuffManager().getNextMessageTime(event.getPlayer().getUniqueId())) {
|
||||
if (System.currentTimeMillis() >= jailMain.getHandCuffManager().getNextMessageTime(event.getPlayer().getUniqueId())) {
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and cant move!");
|
||||
pl.getHandCuffManager().updateNextTime(event.getPlayer().getUniqueId());
|
||||
jailMain.getHandCuffManager().updateNextTime(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void playerChat(AsyncPlayerChatEvent event) {
|
||||
if (false) return;
|
||||
if (false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId()) && !event.getPlayer().hasPermission("jail.command.handcuff")) {
|
||||
if (jailMain.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId()) && !event.getPlayer().hasPermission("jail.command.handcuff")) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and aren't allowed to talk!");
|
||||
}
|
||||
@@ -73,9 +80,11 @@ public class HandCuffListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void blockBreak(BlockBreakEvent event) {
|
||||
if (false) return;
|
||||
if (false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) {
|
||||
if (jailMain.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and aren't allowed to break blocks!");
|
||||
}
|
||||
@@ -83,9 +92,11 @@ public class HandCuffListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void blockPlace(BlockPlaceEvent event) {
|
||||
if (false) return;
|
||||
if (false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) {
|
||||
if (jailMain.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and aren't allowed to place blocks!");
|
||||
}
|
||||
@@ -93,9 +104,11 @@ public class HandCuffListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void preCommands(PlayerCommandPreprocessEvent event) {
|
||||
if (false) return;
|
||||
if (false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId()) && !event.getPlayer().hasPermission("jail.command.handcuff") && (!event.getMessage().startsWith("/r") || !event.getMessage().startsWith("/reply"))) {
|
||||
if (jailMain.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId()) && !event.getPlayer().hasPermission("jail.command.handcuff") && (!event.getMessage().startsWith("/r") || !event.getMessage().startsWith("/reply"))) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and aren't allowed to use commands!");
|
||||
}
|
||||
|
@@ -90,8 +90,9 @@ public class PlayerListener implements Listener {
|
||||
//If the config has receive messages set to false, let's remove all the prisoners
|
||||
//from getting the chat messages.
|
||||
if (!pl.getConfig().getBoolean(Settings.RECIEVEMESSAGES.getPath())) {
|
||||
if (pl.inDebug())
|
||||
if (pl.inDebug()) {
|
||||
pl.getLogger().info("Debug - There are " + event.getRecipients().size() + " players getting the message before.");
|
||||
}
|
||||
Set<Player> rec = new HashSet<>(event.getRecipients());
|
||||
|
||||
for (Jail j : pl.getJailManager().getJails())
|
||||
@@ -100,8 +101,9 @@ public class PlayerListener implements Listener {
|
||||
|
||||
event.getRecipients().clear();
|
||||
event.getRecipients().addAll(rec);
|
||||
if (pl.inDebug())
|
||||
if (pl.inDebug()) {
|
||||
pl.getLogger().info("Debug - There are now " + event.getRecipients().size() + " players getting the message.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,20 +238,27 @@ public class PlayerListener implements Listener {
|
||||
if (pl.getConfig().getBoolean(Settings.JAILSTICKENABLED.getPath())) {
|
||||
//If the damager and the entity getting damage is not a player,
|
||||
//we don't want to handle it in this method
|
||||
if (!(event.getDamager() instanceof Player) || !(event.getEntity() instanceof Player)) return;
|
||||
if (!(event.getDamager() instanceof Player) || !(event.getEntity() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player attacker = (Player) event.getDamager();
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
//They aren't using the jail stick, they need to toggle themselves
|
||||
if (!pl.getJailStickManager().isUsingJailStick(attacker.getUniqueId())) return;
|
||||
if (!pl.getJailStickManager().isUsingJailStick(attacker.getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
//They don't have a valid jail stick type
|
||||
if (!pl.getJailStickManager().isValidStick(attacker.getInventory().getItemInMainHand().getType())) return;
|
||||
if (!pl.getJailStickManager().isValidStick(attacker.getInventory().getItemInMainHand().getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
//They don't have permission for that type of jail stick
|
||||
if (!attacker.hasPermission("jail.usejailstick." + attacker.getInventory().getItemInMainHand().getType().toString().toLowerCase()))
|
||||
if (!attacker.hasPermission("jail.usejailstick." + attacker.getInventory().getItemInMainHand().getType().toString().toLowerCase())) {
|
||||
return;
|
||||
}
|
||||
|
||||
//The player they hit is already jailed.
|
||||
if (pl.getJailManager().isPlayerJailed(player.getUniqueId())) {
|
||||
@@ -285,10 +294,11 @@ public class PlayerListener implements Listener {
|
||||
pl.getServer().getPluginManager().callEvent(jEvent);
|
||||
|
||||
if (jEvent.isCancelled()) {
|
||||
if (jEvent.getCancelledMessage().isEmpty())
|
||||
if (jEvent.getCancelledMessage().isEmpty()) {
|
||||
attacker.sendMessage(Lang.CANCELLEDBYANOTHERPLUGIN.get(player.getName()));
|
||||
else
|
||||
} else {
|
||||
attacker.sendMessage(jEvent.getCancelledMessage());
|
||||
}
|
||||
} else {
|
||||
//recall data from the event
|
||||
Jail j = jEvent.getJail();
|
||||
|
@@ -63,7 +63,9 @@ public class ProtectionListener implements Listener {
|
||||
} else {
|
||||
//The player is not jailed but they're trying to break blocks inside of the Jail
|
||||
//If there is no jail let's skedaddle
|
||||
if (pl.getJailManager().getJailFromLocation(event.getBlock().getLocation()) == null) return;
|
||||
if (pl.getJailManager().getJailFromLocation(event.getBlock().getLocation()) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
//If the player doesn't have permission to modify the jail,
|
||||
//then we stop it here. We won't be doing any of the additions to
|
||||
@@ -115,7 +117,9 @@ public class ProtectionListener implements Listener {
|
||||
} else {
|
||||
//The player is not jailed but they're trying to place blocks inside of the Jail
|
||||
//If there is no jail let's skedaddle
|
||||
if (pl.getJailManager().getJailFromLocation(event.getBlock().getLocation()) == null) return;
|
||||
if (pl.getJailManager().getJailFromLocation(event.getBlock().getLocation()) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
//If the player doesn't have permission to modify the jail,
|
||||
//then we stop it here. We won't be doing any of the additions to
|
||||
@@ -138,8 +142,9 @@ public class ProtectionListener implements Listener {
|
||||
boolean match = false;
|
||||
|
||||
for (String whited : pl.getConfig().getStringList(Settings.COMMANDWHITELIST.getPath()))
|
||||
if (event.getMessage().toLowerCase().startsWith(whited.toLowerCase()))
|
||||
if (event.getMessage().toLowerCase().startsWith(whited.toLowerCase())) {
|
||||
match = true;
|
||||
}
|
||||
|
||||
//If no match found in the whitelist, then let's block this command.
|
||||
if (!match) {
|
||||
@@ -195,8 +200,9 @@ public class ProtectionListener implements Listener {
|
||||
|
||||
if (pos1 || pos2 || pos3 || pos4) {
|
||||
//it is a double chest, so they're free to go!
|
||||
if (pl.inDebug())
|
||||
if (pl.inDebug()) {
|
||||
event.getPlayer().sendMessage("[Jail Debug]: You're opening up a double chest.");
|
||||
}
|
||||
} else {
|
||||
//it is not a double chest, so we won't be allowing it.
|
||||
event.setCancelled(true);
|
||||
|
@@ -18,12 +18,16 @@ public class WorldListener implements Listener {
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
|
||||
public void worldLoaded(WorldLoadEvent event) {
|
||||
for (Jail j : pl.getJailManager().getJails())
|
||||
if (j.getWorldName().equalsIgnoreCase(event.getWorld().getName())) j.setEnabled(true);
|
||||
if (j.getWorldName().equalsIgnoreCase(event.getWorld().getName())) {
|
||||
j.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
|
||||
public void worldUnload(WorldUnloadEvent event) {
|
||||
for (Jail j : pl.getJailManager().getJails())
|
||||
if (j.getWorldName().equalsIgnoreCase(event.getWorld().getName())) j.setEnabled(false);
|
||||
if (j.getWorldName().equalsIgnoreCase(event.getWorld().getName())) {
|
||||
j.setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -151,8 +151,9 @@ public class CellCreationSteps {
|
||||
c.addAllSigns(cp.getSigns());
|
||||
c.setTeleport(cp.getTeleportInSL());
|
||||
|
||||
if (cp.getChestLocation() != null)
|
||||
if (cp.getChestLocation() != null) {
|
||||
c.setChestLocation(cp.getChestLocation());
|
||||
}
|
||||
|
||||
j.addCell(c, true);
|
||||
|
||||
|
Reference in New Issue
Block a user