removed useless config elements and added a way to choose if you want to keep an history or not of all the backs and homes set
This commit is contained in:
parent
42bbfb5f0d
commit
993279974b
@ -27,11 +27,13 @@ import java.util.stream.Collectors;
|
|||||||
*/
|
*/
|
||||||
public class BackHome extends JavaPlugin implements Listener, TabCompleter {
|
public class BackHome extends JavaPlugin implements Listener, TabCompleter {
|
||||||
|
|
||||||
private static final String DB_NAME_KEY = "database.name";
|
private static final String DB_NAME_KEY = "data.name";
|
||||||
private static final String HOME_TABLE_KEY = "database.tables.home.base";
|
private static final String HOME_TABLE = "Home";
|
||||||
private static final String BACK_TABLE_KEY = "database.tables.back.base";
|
private static final String BACK_TABLE = "Back";
|
||||||
private static final String HOME_HISTORY_TABLE_KEY = "database.tables.home.history";
|
private static final String HOME_HISTORY_TABLE = "HomeHistory";
|
||||||
private static final String BACK_HISTORY_TABLE_KEY = "database.tables.back.history";
|
private static final String BACK_HISTORY_TABLE = "BackHistory";
|
||||||
|
private static final String HOME_KEEP_HISTORY_KEY = "data.home.keep-history";
|
||||||
|
private static final String BACK_KEEP_HISTORY_KEY = "data.back.keep-history";
|
||||||
|
|
||||||
private Connection connexion;
|
private Connection connexion;
|
||||||
|
|
||||||
@ -63,9 +65,9 @@ public class BackHome extends JavaPlugin implements Listener, TabCompleter {
|
|||||||
private void createTable() throws SQLException {
|
private void createTable() throws SQLException {
|
||||||
this.connexion = getConnection();
|
this.connexion = getConnection();
|
||||||
createHomeTable();
|
createHomeTable();
|
||||||
createHomeHistoryTable();
|
|
||||||
createBackTable();
|
createBackTable();
|
||||||
createBackHistoryTable();
|
if (getConfig().getBoolean(HOME_KEEP_HISTORY_KEY)) createHomeHistoryTable();
|
||||||
|
if (getConfig().getBoolean(BACK_KEEP_HISTORY_KEY)) createBackHistoryTable();
|
||||||
this.connexion.close();
|
this.connexion.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,7 +172,7 @@ public class BackHome extends JavaPlugin implements Listener, TabCompleter {
|
|||||||
try {
|
try {
|
||||||
this.connexion = getConnection();
|
this.connexion = getConnection();
|
||||||
try (PreparedStatement recherche = this.connexion.prepareStatement(
|
try (PreparedStatement recherche = this.connexion.prepareStatement(
|
||||||
"SELECT x, y, z, yaw, pitch, world FROM " + getConfig().getString(BACK_TABLE_KEY) + " WHERE uuid = ?;")) {
|
"SELECT x, y, z, yaw, pitch, world FROM " + BACK_TABLE + " WHERE uuid = ?;")) {
|
||||||
recherche.setString(1, ((Player) sender).getUniqueId().toString());
|
recherche.setString(1, ((Player) sender).getUniqueId().toString());
|
||||||
teleportPlayerFromPreparedStatement(sender, recherche);
|
teleportPlayerFromPreparedStatement(sender, recherche);
|
||||||
removeBack(((Player) sender));
|
removeBack(((Player) sender));
|
||||||
@ -202,7 +204,7 @@ public class BackHome extends JavaPlugin implements Listener, TabCompleter {
|
|||||||
if (getHomeList(((Player) sender).getUniqueId()).contains(name)) {
|
if (getHomeList(((Player) sender).getUniqueId()).contains(name)) {
|
||||||
this.connexion = getConnection();
|
this.connexion = getConnection();
|
||||||
try (PreparedStatement recherche = this.connexion.prepareStatement(
|
try (PreparedStatement recherche = this.connexion.prepareStatement(
|
||||||
"SELECT x, y, z, yaw, pitch, world FROM " + getConfig().getString(HOME_TABLE_KEY) + " WHERE uuid = ? AND name = ?;")) {
|
"SELECT x, y, z, yaw, pitch, world FROM " + HOME_TABLE + " WHERE uuid = ? AND name = ?;")) {
|
||||||
recherche.setString(1, ((Player) sender).getUniqueId().toString());
|
recherche.setString(1, ((Player) sender).getUniqueId().toString());
|
||||||
recherche.setString(2, name);
|
recherche.setString(2, name);
|
||||||
removeBack(((Player) sender));
|
removeBack(((Player) sender));
|
||||||
@ -242,7 +244,7 @@ public class BackHome extends JavaPlugin implements Listener, TabCompleter {
|
|||||||
float pitch = res.getFloat("pitch");
|
float pitch = res.getFloat("pitch");
|
||||||
String world = res.getString("world");
|
String world = res.getString("world");
|
||||||
((Player) sender).teleport(new Location(Bukkit.getWorld(world), x, y, z, yaw, pitch));
|
((Player) sender).teleport(new Location(Bukkit.getWorld(world), x, y, z, yaw, pitch));
|
||||||
sender.sendMessage(ChatColor.GREEN + "Teleported you back successfully.");
|
sender.sendMessage(ChatColor.GREEN + "Teleported you successfully.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -284,9 +286,7 @@ public class BackHome extends JavaPlugin implements Listener, TabCompleter {
|
|||||||
private String getArgsAsString(String[] args) {
|
private String getArgsAsString(String[] args) {
|
||||||
StringBuilder name = new StringBuilder();
|
StringBuilder name = new StringBuilder();
|
||||||
for (String arg : args) {
|
for (String arg : args) {
|
||||||
if (name.length() != 0) {
|
if (name.length() != 0) name.append(" ");
|
||||||
name.append(" ");
|
|
||||||
}
|
|
||||||
name.append(arg);
|
name.append(arg);
|
||||||
}
|
}
|
||||||
return name.toString();
|
return name.toString();
|
||||||
@ -325,7 +325,7 @@ public class BackHome extends JavaPlugin implements Listener, TabCompleter {
|
|||||||
if (backedPlayer != null) {
|
if (backedPlayer != null) {
|
||||||
this.connexion = getConnection();
|
this.connexion = getConnection();
|
||||||
try (PreparedStatement stmt = this.connexion.prepareStatement(""
|
try (PreparedStatement stmt = this.connexion.prepareStatement(""
|
||||||
+ "DELETE FROM " + getConfig().getString(BACK_TABLE_KEY)
|
+ "DELETE FROM " + BACK_TABLE
|
||||||
+ " WHERE uuid = ?;"
|
+ " WHERE uuid = ?;"
|
||||||
)) {
|
)) {
|
||||||
stmt.setString(1, backedPlayer.getUniqueId().toString());
|
stmt.setString(1, backedPlayer.getUniqueId().toString());
|
||||||
@ -348,10 +348,11 @@ public class BackHome extends JavaPlugin implements Listener, TabCompleter {
|
|||||||
List<PreparedStatement> stmts = new ArrayList<>();
|
List<PreparedStatement> stmts = new ArrayList<>();
|
||||||
stmts.add(this.connexion.prepareStatement(
|
stmts.add(this.connexion.prepareStatement(
|
||||||
"INSERT INTO "
|
"INSERT INTO "
|
||||||
+ getConfig().getString(HOME_TABLE_KEY) + "(uuid, name, date, x, y, z, yaw, pitch, world) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);"));
|
+ HOME_TABLE + "(uuid, name, date, x, y, z, yaw, pitch, world) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);"));
|
||||||
stmts.add(this.connexion.prepareStatement(
|
if (getConfig().getBoolean(HOME_KEEP_HISTORY_KEY))
|
||||||
"INSERT INTO " + getConfig().getString(HOME_HISTORY_TABLE_KEY)
|
stmts.add(this.connexion.prepareStatement(
|
||||||
+ "(uuid, name, date, x, y, z, yaw, pitch, world) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);"));
|
"INSERT INTO " + HOME_HISTORY_TABLE
|
||||||
|
+ "(uuid, name, date, x, y, z, yaw, pitch, world) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);"));
|
||||||
for (PreparedStatement stmt : stmts) {
|
for (PreparedStatement stmt : stmts) {
|
||||||
stmt.setString(1, player.getUniqueId().toString());
|
stmt.setString(1, player.getUniqueId().toString());
|
||||||
stmt.setString(2, name);
|
stmt.setString(2, name);
|
||||||
@ -379,10 +380,11 @@ public class BackHome extends JavaPlugin implements Listener, TabCompleter {
|
|||||||
this.connexion = getConnection();
|
this.connexion = getConnection();
|
||||||
List<PreparedStatement> stmts = new ArrayList<>();
|
List<PreparedStatement> stmts = new ArrayList<>();
|
||||||
stmts.add(this.connexion.prepareStatement(
|
stmts.add(this.connexion.prepareStatement(
|
||||||
"INSERT INTO " + getConfig().getString(BACK_TABLE_KEY) + "(uuid, date, x, y, z, yaw, pitch, world) VALUES (?, ?, ?, ?, ?, ?, ?, ?);"));
|
"INSERT INTO " + BACK_TABLE + "(uuid, date, x, y, z, yaw, pitch, world) VALUES (?, ?, ?, ?, ?, ?, ?, ?);"));
|
||||||
stmts.add(this.connexion.prepareStatement(
|
if (getConfig().getBoolean(BACK_KEEP_HISTORY_KEY))
|
||||||
"INSERT INTO " + getConfig().getString(BACK_HISTORY_TABLE_KEY)
|
stmts.add(this.connexion.prepareStatement(
|
||||||
+ "(uuid, date, x, y, z, yaw, pitch, world) VALUES (?, ?, ?, ?, ?, ?, ?, ?);"));
|
"INSERT INTO " + BACK_HISTORY_TABLE
|
||||||
|
+ "(uuid, date, x, y, z, yaw, pitch, world) VALUES (?, ?, ?, ?, ?, ?, ?, ?);"));
|
||||||
for (PreparedStatement stmt : stmts) {
|
for (PreparedStatement stmt : stmts) {
|
||||||
stmt.setString(1, player.getUniqueId().toString());
|
stmt.setString(1, player.getUniqueId().toString());
|
||||||
stmt.setString(2, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
stmt.setString(2, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
||||||
@ -408,7 +410,7 @@ public class BackHome extends JavaPlugin implements Listener, TabCompleter {
|
|||||||
private void removeHome(UUID backedPlayer, String homeName) throws SQLException {
|
private void removeHome(UUID backedPlayer, String homeName) throws SQLException {
|
||||||
this.connexion = getConnection();
|
this.connexion = getConnection();
|
||||||
try (PreparedStatement stmt = this.connexion.prepareStatement(""
|
try (PreparedStatement stmt = this.connexion.prepareStatement(""
|
||||||
+ "DELETE FROM " + getConfig().getString(HOME_TABLE_KEY) + " WHERE uuid = ? AND name = ?;"
|
+ "DELETE FROM " + HOME_TABLE + " WHERE uuid = ? AND name = ?;"
|
||||||
)) {
|
)) {
|
||||||
stmt.setString(1, backedPlayer.toString());
|
stmt.setString(1, backedPlayer.toString());
|
||||||
stmt.setString(2, homeName);
|
stmt.setString(2, homeName);
|
||||||
@ -428,12 +430,10 @@ public class BackHome extends JavaPlugin implements Listener, TabCompleter {
|
|||||||
this.connexion = getConnection();
|
this.connexion = getConnection();
|
||||||
List<String> homeNames = new ArrayList<>();
|
List<String> homeNames = new ArrayList<>();
|
||||||
try (PreparedStatement recherche = this.connexion.prepareStatement(
|
try (PreparedStatement recherche = this.connexion.prepareStatement(
|
||||||
"SELECT name FROM " + getConfig().getString(HOME_TABLE_KEY) + " WHERE uuid = ?;")) {
|
"SELECT name FROM " + HOME_TABLE + " WHERE uuid = ?;")) {
|
||||||
recherche.setString(1, player.toString());
|
recherche.setString(1, player.toString());
|
||||||
try (ResultSet res = recherche.executeQuery()) {
|
try (ResultSet res = recherche.executeQuery()) {
|
||||||
while (res.next()) {
|
while (res.next()) homeNames.add(res.getString("name"));
|
||||||
homeNames.add(res.getString("name"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.connexion.close();
|
this.connexion.close();
|
||||||
@ -447,7 +447,7 @@ public class BackHome extends JavaPlugin implements Listener, TabCompleter {
|
|||||||
*/
|
*/
|
||||||
private void createBackHistoryTable() throws SQLException {
|
private void createBackHistoryTable() throws SQLException {
|
||||||
try (PreparedStatement stmt = connexion.prepareStatement(""
|
try (PreparedStatement stmt = connexion.prepareStatement(""
|
||||||
+ "CREATE TABLE IF NOT EXISTS " + getConfig().getString(BACK_HISTORY_TABLE_KEY)
|
+ "CREATE TABLE IF NOT EXISTS " + BACK_HISTORY_TABLE
|
||||||
+ "("
|
+ "("
|
||||||
+ "id INTEGER PRIMARY KEY AUTOINCREMENT, "
|
+ "id INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||||
+ "uuid TEXT, "
|
+ "uuid TEXT, "
|
||||||
@ -471,7 +471,7 @@ public class BackHome extends JavaPlugin implements Listener, TabCompleter {
|
|||||||
*/
|
*/
|
||||||
private void createBackTable() throws SQLException {
|
private void createBackTable() throws SQLException {
|
||||||
try (PreparedStatement stmt = connexion.prepareStatement(""
|
try (PreparedStatement stmt = connexion.prepareStatement(""
|
||||||
+ "CREATE TABLE IF NOT EXISTS " + getConfig().getString(BACK_TABLE_KEY)
|
+ "CREATE TABLE IF NOT EXISTS " + BACK_TABLE
|
||||||
+ "("
|
+ "("
|
||||||
+ "id INTEGER PRIMARY KEY AUTOINCREMENT, "
|
+ "id INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||||
+ "uuid TEXT UNIQUE, "
|
+ "uuid TEXT UNIQUE, "
|
||||||
@ -495,7 +495,7 @@ public class BackHome extends JavaPlugin implements Listener, TabCompleter {
|
|||||||
*/
|
*/
|
||||||
private void createHomeHistoryTable() throws SQLException {
|
private void createHomeHistoryTable() throws SQLException {
|
||||||
try (PreparedStatement stmt = connexion.prepareStatement(""
|
try (PreparedStatement stmt = connexion.prepareStatement(""
|
||||||
+ "CREATE TABLE IF NOT EXISTS " + getConfig().getString(HOME_HISTORY_TABLE_KEY)
|
+ "CREATE TABLE IF NOT EXISTS " + HOME_HISTORY_TABLE
|
||||||
+ "("
|
+ "("
|
||||||
+ "id INTEGER UNIQUE PRIMARY KEY AUTOINCREMENT, "
|
+ "id INTEGER UNIQUE PRIMARY KEY AUTOINCREMENT, "
|
||||||
+ "uuid TEXT, "
|
+ "uuid TEXT, "
|
||||||
@ -520,7 +520,7 @@ public class BackHome extends JavaPlugin implements Listener, TabCompleter {
|
|||||||
*/
|
*/
|
||||||
private void createHomeTable() throws SQLException {
|
private void createHomeTable() throws SQLException {
|
||||||
try (PreparedStatement stmt = connexion.prepareStatement(""
|
try (PreparedStatement stmt = connexion.prepareStatement(""
|
||||||
+ "CREATE TABLE IF NOT EXISTS " + getConfig().getString(HOME_TABLE_KEY)
|
+ "CREATE TABLE IF NOT EXISTS " + HOME_TABLE
|
||||||
+ "("
|
+ "("
|
||||||
+ "id INTEGER UNIQUE PRIMARY KEY AUTOINCREMENT, "
|
+ "id INTEGER UNIQUE PRIMARY KEY AUTOINCREMENT, "
|
||||||
+ "uuid TEXT, "
|
+ "uuid TEXT, "
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
database:
|
data:
|
||||||
name: "BackHome.data"
|
name: "BackHome.data"
|
||||||
tables:
|
home:
|
||||||
home:
|
keep-history: true
|
||||||
base: "Home"
|
back:
|
||||||
history: "HomeHistory"
|
keep-history: true
|
||||||
back:
|
|
||||||
base: "Back"
|
|
||||||
history: "BackHistory"
|
|
||||||
|
Loading…
Reference in New Issue
Block a user