cooldowns per world blueprint (compilation errors pending)

This commit is contained in:
RonanCraft 2022-03-28 17:48:03 -04:00
parent 158b89cb20
commit 098925d61a
11 changed files with 276 additions and 183 deletions

View File

@ -7,7 +7,6 @@ import me.SuperRonanCraft.BetterRTP.player.events.Listener;
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP; import me.SuperRonanCraft.BetterRTP.player.rtp.RTP;
import me.SuperRonanCraft.BetterRTP.references.Permissions; import me.SuperRonanCraft.BetterRTP.references.Permissions;
import me.SuperRonanCraft.BetterRTP.references.Updater; import me.SuperRonanCraft.BetterRTP.references.Updater;
import me.SuperRonanCraft.BetterRTP.references.database.DatabaseCooldowns;
import me.SuperRonanCraft.BetterRTP.references.depends.DepEconomy; import me.SuperRonanCraft.BetterRTP.references.depends.DepEconomy;
import me.SuperRonanCraft.BetterRTP.references.file.Files; import me.SuperRonanCraft.BetterRTP.references.file.Files;
import me.SuperRonanCraft.BetterRTP.references.file.Messages; import me.SuperRonanCraft.BetterRTP.references.file.Messages;
@ -35,7 +34,6 @@ public class BetterRTP extends JavaPlugin {
private final PlayerInfo pInfo = new PlayerInfo(); private final PlayerInfo pInfo = new PlayerInfo();
@Getter private final PlayerDataManager playerDataManager = new PlayerDataManager(); @Getter private final PlayerDataManager playerDataManager = new PlayerDataManager();
private final Settings settings = new Settings(); private final Settings settings = new Settings();
@Getter private final DatabaseCooldowns databaseCooldowns = new DatabaseCooldowns();
@Getter private final CooldownHandler cooldowns = new CooldownHandler(); @Getter private final CooldownHandler cooldowns = new CooldownHandler();
public void onEnable() { public void onEnable() {

View File

@ -2,20 +2,25 @@ package me.SuperRonanCraft.BetterRTP.references.database;
import me.SuperRonanCraft.BetterRTP.BetterRTP; import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.CooldownData; import me.SuperRonanCraft.BetterRTP.references.rtpinfo.CooldownData;
import org.bukkit.Bukkit;
import org.bukkit.World;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
public class DatabaseCooldowns extends SQLite { public class DatabaseCooldownsGlobal extends SQLite {
public DatabaseCooldowns() { public DatabaseCooldownsGlobal() {
super(DATABASE_TYPE.COOLDOWN); super(DATABASE_TYPE.COOLDOWN_GLOBAL);
}
@Override
public List<String> getTables() {
return Collections.singletonList("BetterRTP_Cooldown");
} }
public enum COLUMNS { public enum COLUMNS {
@ -25,8 +30,8 @@ public class DatabaseCooldowns extends SQLite {
USES("uses", "integer"), USES("uses", "integer"),
; ;
public String name; public final String name;
public String type; public final String type;
COLUMNS(String name, String type) { COLUMNS(String name, String type) {
this.name = name; this.name = name;
@ -35,7 +40,7 @@ public class DatabaseCooldowns extends SQLite {
} }
public boolean removePlayer(UUID uuid) { public boolean removePlayer(UUID uuid) {
String sql = "DELETE FROM " + table + " WHERE " String sql = "DELETE FROM " + tables.get(0) + " WHERE "
+ COLUMNS.UUID.name + " = ?"; + COLUMNS.UUID.name + " = ?";
List<Object> params = new ArrayList<Object>() {{ List<Object> params = new ArrayList<Object>() {{
add(uuid.toString()); add(uuid.toString());
@ -49,14 +54,14 @@ public class DatabaseCooldowns extends SQLite {
ResultSet rs = null; ResultSet rs = null;
try { try {
conn = getSQLConnection(); conn = getSQLConnection();
ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE " + COLUMNS.UUID.name + " = ?"); ps = conn.prepareStatement("SELECT * FROM " + tables.get(0) + " WHERE " + COLUMNS.UUID.name + " = ?");
ps.setString(1, uuid.toString()); ps.setString(1, uuid.toString());
rs = ps.executeQuery(); rs = ps.executeQuery();
if (rs.next()) { if (rs.next()) {
Long time = rs.getLong(COLUMNS.COOLDOWN_DATE.name); Long time = rs.getLong(COLUMNS.COOLDOWN_DATE.name);
int uses = rs.getInt(COLUMNS.USES.name); int uses = rs.getInt(COLUMNS.USES.name);
return new CooldownData(uuid, time, uses); return new CooldownData(uuid, time, uses, null);
} }
} catch (SQLException ex) { } catch (SQLException ex) {
BetterRTP.getInstance().getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex); BetterRTP.getInstance().getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
@ -69,7 +74,7 @@ public class DatabaseCooldowns extends SQLite {
//Set a player Cooldown //Set a player Cooldown
public void setCooldown(CooldownData data) { public void setCooldown(CooldownData data) {
String pre = "INSERT OR REPLACE INTO "; String pre = "INSERT OR REPLACE INTO ";
String sql = pre + table + " (" String sql = pre + tables.get(0) + " ("
+ COLUMNS.UUID.name + ", " + COLUMNS.UUID.name + ", "
+ COLUMNS.COOLDOWN_DATE.name + ", " + COLUMNS.COOLDOWN_DATE.name + ", "
+ COLUMNS.USES.name + " " + COLUMNS.USES.name + " "
@ -85,7 +90,7 @@ public class DatabaseCooldowns extends SQLite {
//Update multiple players cooldowns //Update multiple players cooldowns
public void setCooldown(List<CooldownData> cooldownData) { public void setCooldown(List<CooldownData> cooldownData) {
String pre = "INSERT OR REPLACE INTO "; String pre = "INSERT OR REPLACE INTO ";
String sql = pre + table + " (" String sql = pre + tables.get(0) + " ("
+ COLUMNS.UUID.name + ", " + COLUMNS.UUID.name + ", "
+ COLUMNS.COOLDOWN_DATE.name + ", " + COLUMNS.COOLDOWN_DATE.name + ", "
+ COLUMNS.USES.name + " " + COLUMNS.USES.name + " "

View File

@ -0,0 +1,112 @@
package me.SuperRonanCraft.BetterRTP.references.database;
import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.CooldownData;
import org.bukkit.Bukkit;
import org.bukkit.World;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.logging.Level;
public class DatabaseCooldownsWorlds extends SQLite {
public DatabaseCooldownsWorlds() {
super(DATABASE_TYPE.COOLDOWN);
}
@Override
public List<String> getTables() {
List<String> list = new ArrayList<>();
for (World world : Bukkit.getWorlds())
list.add(world.getName());
return list;
}
public enum COLUMNS {
UUID("uuid", "varchar(32) PRIMARY KEY"),
//COOLDOWN DATA
COOLDOWN_DATE("date", "long"),
USES("uses", "integer"),
;
public final String name;
public final String type;
COLUMNS(String name, String type) {
this.name = name;
this.type = type;
}
}
public boolean removePlayer(UUID uuid, World world) {
String sql = "DELETE FROM " + world.getName() + " WHERE "
+ COLUMNS.UUID.name + " = ?";
List<Object> params = new ArrayList<Object>() {{
add(uuid.toString());
}};
return sqlUpdate(sql, params);
}
public CooldownData getCooldown(UUID uuid, World world) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = getSQLConnection();
ps = conn.prepareStatement("SELECT * FROM " + world.getName() + " WHERE " + COLUMNS.UUID.name + " = ?");
ps.setString(1, uuid.toString());
rs = ps.executeQuery();
if (rs.next()) {
Long time = rs.getLong(COLUMNS.COOLDOWN_DATE.name);
int uses = rs.getInt(COLUMNS.USES.name);
return new CooldownData(uuid, time, uses, world);
}
} catch (SQLException ex) {
BetterRTP.getInstance().getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
} finally {
close(ps, rs, conn);
}
return null;
}
//Set a player Cooldown
public void setCooldown(CooldownData data) {
String pre = "INSERT OR REPLACE INTO ";
String sql = pre + data.getWorld().getName() + " ("
+ COLUMNS.UUID.name + ", "
+ COLUMNS.COOLDOWN_DATE.name + ", "
+ COLUMNS.USES.name + " "
+ ") VALUES(?, ?, ?)";
List<Object> params = new ArrayList<Object>() {{
add(data.getUuid().toString());
add(data.getTime());
add(data.getUses());
}};
sqlUpdate(sql, params);
}
//Update multiple players cooldowns
/*public void setCooldown(List<CooldownData> cooldownData) {
String pre = "INSERT OR REPLACE INTO ";
String sql = pre + table + " ("
+ COLUMNS.UUID.name + ", "
+ COLUMNS.COOLDOWN_DATE.name + ", "
+ COLUMNS.USES.name + " "
+ ") VALUES(?, ?, ?)";
for (CooldownData data : cooldownData) {
List<Object> param = new ArrayList<Object>() {{
add(data.getUuid().toString());
add(data.getTime());
add(data.getUses());
}};
sqlUpdate(sql, param);
}
}*/
}

View File

@ -2,7 +2,6 @@ package me.SuperRonanCraft.BetterRTP.references.database;
import lombok.NonNull; import lombok.NonNull;
import me.SuperRonanCraft.BetterRTP.BetterRTP; import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import java.io.File; import java.io.File;
@ -12,15 +11,13 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
public class SQLite { public abstract class SQLite {
private static final String db_file_name = "database"; private static final String db_file_name = "database";
//private final boolean sqlEnabled; List<String> tables;
String table; //private String host, database, username, password;
private String host, database, username, password; //private int port;
private int port; //boolean sqlEnabled;
boolean sqlEnabled;
//Connection connection;
private boolean loaded; private boolean loaded;
public String addMissingColumns = "ALTER TABLE %table% ADD COLUMN %column% %type%"; public String addMissingColumns = "ALTER TABLE %table% ADD COLUMN %column% %type%";
@ -31,9 +28,11 @@ public class SQLite {
this.type = type; this.type = type;
} }
public abstract List<String> getTables();
// SQL creation stuff // SQL creation stuff
public Connection getSQLConnection() { public Connection getSQLConnection() {
if (sqlEnabled) { /*if (sqlEnabled) {
try { try {
return getOnline(); return getOnline();
} catch (SQLException | ClassNotFoundException e) { } catch (SQLException | ClassNotFoundException e) {
@ -41,17 +40,17 @@ public class SQLite {
BetterRTP.getInstance().getLogger().info("MySQL setup is incorrect! Grabbing data from local database!"); BetterRTP.getInstance().getLogger().info("MySQL setup is incorrect! Grabbing data from local database!");
sqlEnabled = false; sqlEnabled = false;
} }
} }*/
return getLocal(); return getLocal();
} }
private Connection getOnline() throws SQLException, ClassNotFoundException { /*private Connection getOnline() throws SQLException, ClassNotFoundException {
synchronized (this) { synchronized (this) {
Class.forName("com.mysql.jdbc.Driver"); Class.forName("com.mysql.jdbc.Driver");
return DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database + return DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database +
"?autoReconnect=true&useSSL=false", this.username, this.password); "?autoReconnect=true&useSSL=false", this.username, this.password);
} }
} }*/
private Connection getLocal() { private Connection getLocal() {
File dataFolder = new File(BetterRTP.getInstance().getDataFolder().getPath() + File.separator + "data", db_file_name + ".db"); File dataFolder = new File(BetterRTP.getInstance().getDataFolder().getPath() + File.separator + "data", db_file_name + ".db");
@ -65,55 +64,53 @@ public class SQLite {
} }
} }
try { try {
//if (connection != null && !connection.isClosed()) {
// return connection;
//}
Class.forName("org.sqlite.JDBC"); Class.forName("org.sqlite.JDBC");
return DriverManager.getConnection("jdbc:sqlite:" + dataFolder); return DriverManager.getConnection("jdbc:sqlite:" + dataFolder);
//return connection;
} catch (SQLException ex) { } catch (SQLException ex) {
BetterRTP.getInstance().getLogger().log(Level.SEVERE, "SQLite exception on initialize", ex); BetterRTP.getInstance().getLogger().log(Level.SEVERE, "SQLite exception on initialize", ex);
} catch (ClassNotFoundException ex) { } catch (ClassNotFoundException ex) {
BetterRTP.getInstance().getLogger().log(Level.SEVERE, "You need the SQLite JBDC library. Google it. Put it in /lib folder."); BetterRTP.getInstance().getLogger().log(Level.SEVERE, "You need the SQLite JBDC library. Google it Ronan...");
} }
return null; return null;
} }
public void load() { public void load() {
loaded = false; loaded = false;
switch (type) { /*switch (type) {
case COOLDOWN: table = "BetterRTP_Cooldown"; break; case COOLDOWN: table = "BetterRTP_Cooldown"; break;
} }
if (table == null) { if (table == null) {
BetterRTP.getInstance().getLogger().severe("The table for `" + type.name() + "` is invalid. Disabling the plugin!"); BetterRTP.getInstance().getLogger().severe("The table for `" + type.name() + "` is invalid. Disabling the plugin!");
Bukkit.getPluginManager().disablePlugin(BetterRTP.getInstance()); Bukkit.getPluginManager().disablePlugin(BetterRTP.getInstance());
return; return;
} }*/
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> { Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
Connection connection = getSQLConnection(); Connection connection = getSQLConnection();
try { for (String table : tables) {
Statement s = connection.createStatement(); try {
s.executeUpdate(getCreateTable()); Statement s = connection.createStatement();
//s.executeUpdate(createTable_bank); s.executeUpdate(getCreateTable(table));
for (Enum<?> c : getColumns(type)) { //Add missing columns dynamically //s.executeUpdate(createTable_bank);
try { for (Enum<?> c : getColumns(type)) { //Add missing columns dynamically
String _name = getColumnName(type, c); try {
String _type = getColumnType(type, c); String _name = getColumnName(type, c);
//System.out.println("Adding " + _name); String _type = getColumnType(type, c);
s.executeUpdate(addMissingColumns.replace("%table%", table).replace("%column%", _name).replace("%type%", _type)); //System.out.println("Adding " + _name);
} catch (SQLException e) { s.executeUpdate(addMissingColumns.replace("%table%", table).replace("%column%", _name).replace("%type%", _type));
//e.printStackTrace(); } catch (SQLException e) {
//e.printStackTrace();
}
} }
} s.close();
s.close(); } catch (SQLException e) {
} catch (SQLException e) { e.printStackTrace();
e.printStackTrace(); } finally {
} finally { if (connection != null) {
if (connection != null) { try {
try { connection.close();
connection.close(); } catch (SQLException e) {
} catch (SQLException e) { e.printStackTrace();
e.printStackTrace(); }
} }
} }
} }
@ -123,7 +120,7 @@ public class SQLite {
}); });
} }
private String getCreateTable() { private String getCreateTable(String table) {
String str = "CREATE TABLE IF NOT EXISTS " + table + " ("; String str = "CREATE TABLE IF NOT EXISTS " + table + " (";
Enum<?>[] columns = getColumns(type); Enum<?>[] columns = getColumns(type);
for (Enum<?> c : columns) { for (Enum<?> c : columns) {
@ -141,19 +138,19 @@ public class SQLite {
private Enum<?>[] getColumns(DATABASE_TYPE type) { private Enum<?>[] getColumns(DATABASE_TYPE type) {
switch (type) { switch (type) {
default: return DatabaseCooldowns.COLUMNS.values(); default: return DatabaseCooldownsWorlds.COLUMNS.values();
} }
} }
private String getColumnName(DATABASE_TYPE type, Enum<?> column) { private String getColumnName(DATABASE_TYPE type, Enum<?> column) {
switch (type) { switch (type) {
default: return ((DatabaseCooldowns.COLUMNS) column).name; default: return ((DatabaseCooldownsWorlds.COLUMNS) column).name;
} }
} }
private String getColumnType(DATABASE_TYPE type, Enum<?> column) { private String getColumnType(DATABASE_TYPE type, Enum<?> column) {
switch (type) { switch (type) {
default: return ((DatabaseCooldowns.COLUMNS) column).type; default: return ((DatabaseCooldownsWorlds.COLUMNS) column).type;
} }
} }
@ -222,7 +219,7 @@ public class SQLite {
ResultSet rs = null; ResultSet rs = null;
try { try {
conn = getSQLConnection(); conn = getSQLConnection();
ps = conn.prepareStatement("SELECT * FROM " + table + " WHERE " + getColumnName(type, getColumns(type)[0]) + " = 0"); ps = conn.prepareStatement("SELECT * FROM " + tables.get(0) + " WHERE " + getColumnName(type, getColumns(type)[0]) + " = 0");
rs = ps.executeQuery(); rs = ps.executeQuery();
} catch (SQLException ex) { } catch (SQLException ex) {
@ -247,6 +244,7 @@ public class SQLite {
} }
public enum DATABASE_TYPE { public enum DATABASE_TYPE {
COOLDOWN COOLDOWN,
COOLDOWN_GLOBAL, //Table to know last time in general player has a cooldown for
} }
} }

View File

@ -67,7 +67,7 @@ public class HelperRTP {
return false; return false;
} }
//Cooldown Data //Cooldown Data
CooldownData cooldownData = getPl().getCooldowns().getPlayer(player); CooldownData cooldownData = getPl().getCooldowns().get(player);
if (cooldownData != null) { if (cooldownData != null) {
if (cooldownHandler.locked(cooldownData)) { //Infinite cooldown (locked) if (cooldownHandler.locked(cooldownData)) { //Infinite cooldown (locked)
getPl().getText().getNoPermission(sendi); getPl().getText().getNoPermission(sendi);

View File

@ -3,8 +3,13 @@ package me.SuperRonanCraft.BetterRTP.references.player.playerdata;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.CooldownData; import me.SuperRonanCraft.BetterRTP.references.rtpinfo.CooldownData;
import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class PlayerData { public class PlayerData {
public boolean loading; //Is this players data loading? public boolean loading; //Is this players data loading?
@ -12,7 +17,8 @@ public class PlayerData {
//Menus //Menus
@Getter final PlayerData_Menus menu = new PlayerData_Menus(); @Getter final PlayerData_Menus menu = new PlayerData_Menus();
//Player Data //Player Data
@Getter @Setter CooldownData cooldown; @Getter final HashMap<World, CooldownData> cooldowns = new HashMap<>();
@Getter @Setter CooldownData globalCooldown;
@Getter @Setter boolean rtping; @Getter @Setter boolean rtping;
PlayerData(Player player) { PlayerData(Player player) {

View File

@ -2,6 +2,7 @@ package me.SuperRonanCraft.BetterRTP.references.rtpinfo;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.bukkit.World;
import java.util.UUID; import java.util.UUID;
@ -9,10 +10,12 @@ public class CooldownData {
@Getter private final UUID uuid; @Getter private final UUID uuid;
@Getter @Setter private Long time; @Getter @Setter private Long time;
@Getter @Setter int uses; @Getter @Setter int uses;
@Getter private final World world;
public CooldownData(UUID uuid, Long time, int uses) { public CooldownData(UUID uuid, Long time, int uses, World world) {
this.uuid = uuid; this.uuid = uuid;
this.time = time; this.time = time;
this.uses = uses; this.uses = uses;
this.world = world;
} }
} }

View File

@ -1,22 +1,20 @@
package me.SuperRonanCraft.BetterRTP.references.rtpinfo; package me.SuperRonanCraft.BetterRTP.references.rtpinfo;
import lombok.Getter; import lombok.Getter;
import me.SuperRonanCraft.BetterRTP.references.database.DatabaseCooldowns; import me.SuperRonanCraft.BetterRTP.references.database.DatabaseCooldownsWorlds;
import me.SuperRonanCraft.BetterRTP.references.database.DatabaseCooldownsGlobal;
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics; import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
import me.SuperRonanCraft.BetterRTP.BetterRTP; import me.SuperRonanCraft.BetterRTP.BetterRTP;
import me.SuperRonanCraft.BetterRTP.references.player.HelperPlayer; import me.SuperRonanCraft.BetterRTP.references.player.HelperPlayer;
import me.SuperRonanCraft.BetterRTP.references.player.playerdata.PlayerData; import me.SuperRonanCraft.BetterRTP.references.player.playerdata.PlayerData;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.World;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean;
public class CooldownHandler { public class CooldownHandler {
@ -25,6 +23,8 @@ public class CooldownHandler {
timer, //Cooldown timer timer, //Cooldown timer
lockedAfter; //Rtp's before being locked lockedAfter; //Rtp's before being locked
private final List<Player> downloading = new ArrayList<>(); private final List<Player> downloading = new ArrayList<>();
private final DatabaseCooldownsWorlds cooldowns = new DatabaseCooldownsWorlds();
private final DatabaseCooldownsGlobal globalCooldown = new DatabaseCooldownsGlobal();
public void load() { public void load() {
//configfile = new File(BetterRTP.getInstance().getDataFolder(), "data/cooldowns.yml"); //configfile = new File(BetterRTP.getInstance().getDataFolder(), "data/cooldowns.yml");
@ -37,29 +37,34 @@ public class CooldownHandler {
lockedAfter = config.getInt("Settings.Cooldown.LockAfter"); lockedAfter = config.getInt("Settings.Cooldown.LockAfter");
} }
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> { Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
getDatabase().load(); globalCooldown.load();
cooldowns.load();
checkLater(); checkLater();
}); });
} }
private void checkLater() { private void checkLater() {
Bukkit.getScheduler().runTaskLaterAsynchronously(BetterRTP.getInstance(), () -> { Bukkit.getScheduler().runTaskLaterAsynchronously(BetterRTP.getInstance(), () -> {
if (getDatabase().isLoaded()) { AtomicBoolean loaded = new AtomicBoolean(true);
OldCooldownConverter.loadOldCooldowns(); if (!globalCooldown.isLoaded()) {
//Load any online players cooldowns (mostly after a reload)
for (Player p : Bukkit.getOnlinePlayers())
loadPlayer(p);
loaded = true;
} else
checkLater(); checkLater();
return;
} else if (!cooldowns.isLoaded()) {
checkLater();
return;
}
//OldCooldownConverter.loadOldCooldowns();
//Load any online players cooldowns (mostly after a reload)
for (Player p : Bukkit.getOnlinePlayers())
loadPlayer(p);
}, 10L); }, 10L);
} }
public void add(Player player) { public void add(Player player, World world) {
if (!enabled) return; if (!enabled) return;
CooldownData data = getData(player).getCooldown(); CooldownData data = getData(player).getCooldown();
if (data == null) if (data == null)
data = new CooldownData(player.getUniqueId(), 0L, 0); data = new CooldownData(player.getUniqueId(), 0L, 0, world);
if (lockedAfter > 0) if (lockedAfter > 0)
data.setUses(data.getUses() + 1); data.setUses(data.getUses() + 1);
data.setTime(System.currentTimeMillis()); data.setTime(System.currentTimeMillis());
@ -68,12 +73,22 @@ public class CooldownHandler {
} }
public boolean exists(Player p) { public boolean exists(Player p) {
return getData(p).getCooldown() != null; return getData(p).getCooldowns() != null;
} }
@Nullable @Nullable
public CooldownData getPlayer(Player p) { public CooldownData get(Player p, World world) {
return getData(p).getCooldown(); List<CooldownData> data = getData(p).getCooldowns();
if (data != null)
for (CooldownData cd : data)
if (cd.getWorld() == world)
return cd;
return null;
}
@Nullable
public CooldownData getGlobal(Player p) {
return globalCooldown.getCooldown(p.getUniqueId());
} }
public long timeLeft(CooldownData data) { public long timeLeft(CooldownData data) {
@ -106,19 +121,21 @@ public class CooldownHandler {
private void savePlayer(CooldownData data, boolean remove) { private void savePlayer(CooldownData data, boolean remove) {
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> { Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
if (!remove) { if (!remove) {
getDatabase().setCooldown(data); getDatabase(data.getWorld()).setCooldown(data);
} else { } else {
getDatabase().removePlayer(data.getUuid()); getDatabase(data.getWorld()).removePlayer(data.getUuid(), data.getWorld());
} }
}); });
} }
public void loadPlayer(Player player) { public void loadPlayer(Player player) {
if (!isEnabled()) return;
downloading.add(player); downloading.add(player);
if (isEnabled()) { List<CooldownData> cooldowns = new ArrayList<>();
CooldownData cooldown = getDatabase().getCooldown(player.getUniqueId()); for (World world : Bukkit.getWorlds()) {
CooldownData cooldown = getDatabaseWorlds().getCooldown(player.getUniqueId(), world);
if (cooldown != null) if (cooldown != null)
getData(player).setCooldown(cooldown); getData(player).getCooldowns().add(cooldown);
} }
downloading.remove(player); downloading.remove(player);
} }
@ -127,7 +144,17 @@ public class CooldownHandler {
return !downloading.contains(player); return !downloading.contains(player);
} }
@Deprecated private DatabaseCooldownsWorlds getDatabaseWorlds() {
return cooldowns;
}
private PlayerData getData(Player p) {
return HelperPlayer.getData(p);
}
}
//Old yaml file based system, no longer useful as of 3.3.1
/*@Deprecated
static class OldCooldownConverter { static class OldCooldownConverter {
static void loadOldCooldowns() { static void loadOldCooldowns() {
@ -162,12 +189,6 @@ public class CooldownHandler {
private static YamlConfiguration getFile(File configfile) { private static YamlConfiguration getFile(File configfile) {
if (!configfile.exists()) { if (!configfile.exists()) {
return null; return null;
/*try {
configfile.getParentFile().mkdir();
configfile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}*/
} }
try { try {
YamlConfiguration config = new YamlConfiguration(); YamlConfiguration config = new YamlConfiguration();
@ -178,13 +199,4 @@ public class CooldownHandler {
} }
return null; return null;
} }
} }*/
private DatabaseCooldowns getDatabase() {
return BetterRTP.getInstance().getDatabaseCooldowns();
}
private PlayerData getData(Player p) {
return HelperPlayer.getData(p);
}
}

View File

@ -2,23 +2,18 @@
Messages: Messages:
Prefix: '&7[&6BetterRTP&7] ' Prefix: '&7[&6BetterRTP&7] '
Success: # # Placeholders! %x% %y% and %z% are the x, y, and z coordinates that the player is being teleported to! # Success: # # Placeholders! %x% %y% and %z% are the x, y, and z coordinates that the player is being teleported to! #
Paid: '&aYou have been tp''d to&7 x=%x% y=%y% z=%z% for &c$%price%&7 in &f%attempts% Paid: '&aYou have been tp''d to&7 x=%x% y=%y% z=%z% for &c$%price%&7 in &f%attempts% &7attempts!'
&7attempts!'
Bypass: '&aYou have been tp''d to&7 x=%x% y=%y% z=%z% in &f%attempts% &7attempts' Bypass: '&aYou have been tp''d to&7 x=%x% y=%y% z=%z% in &f%attempts% &7attempts'
Loading: '&aSafe spot located! &7Loading chunks...' Loading: '&aSafe spot located! &7Loading chunks...'
Teleport: '&aTeleporting... &fplease wait while we find a safe location!' Teleport: '&aTeleporting... &fplease wait while we find a safe location!'
Failed: Failed:
Price: '&cCould not rtp because of insufficent funds! &7You must have atleast Price: '&cCould not rtp because of insufficent funds! &7You must have atleast $%price% &7to rtp!'
$%price% &7to rtp!' NotSafe: '&cCould not find safe spot within %attempts% attempts! &7You were not RTP''d!'
NotSafe: '&cCould not find safe spot within %attempts% attempts! &7You were not
RTP''d!'
Hunger: '&cCould not rtp because you are... &7too hungry&c, eat something fella!' Hunger: '&cCould not rtp because you are... &7too hungry&c, eat something fella!'
Other: Other:
Success: '&a%player% has been tp''d to&7 x=%x% y=%y% z=%z% in &f%attempts% &7attempts!' Success: '&a%player% has been tp''d to&7 x=%x% y=%y% z=%z% in &f%attempts% &7attempts!'
NotSafe: '&cCould not find safe spot within %attempts% attempts! &7%player% was NotSafe: '&cCould not find safe spot within %attempts% attempts! &7%player% was not rtp''d!'
not rtp''d!' Biome: '&cSeems like the biome&7 %biome%&c does not exist! &7Try using the tab list!'
Biome: '&cSeems like the biome&7 %biome%&c does not exist! &7Try using the tab
list!'
Reload: '&eConfig reloaded successfully!' Reload: '&eConfig reloaded successfully!'
NoPermission: NoPermission:
Basic: '&cSorry! &7You don''t have permission to use this command!' Basic: '&cSorry! &7You don''t have permission to use this command!'
@ -41,21 +36,16 @@ Messages:
Help: Help:
Prefix: '&e&m-----&6&l BetterRTP &8| Help &e&m-----' Prefix: '&e&m-----&6&l BetterRTP &8| Help &e&m-----'
Main: ' &7- &e/%command% &7- Randomly teleports you!' Main: ' &7- &e/%command% &7- Randomly teleports you!'
Biome: ' &7- &e/%command% biome <biome1, biome2...> &7- Randomly teleport withing Biome: ' &7- &e/%command% biome <biome1, biome2...> &7- Randomly teleport withing these biomes'
these biomes'
Edit: ' &7- &e/%command% edit <default/world> [args...] &7- Edit some plugin settings' Edit: ' &7- &e/%command% edit <default/world> [args...] &7- Edit some plugin settings'
Help: ' &7- &e/%command% help &7- Shows help list' Help: ' &7- &e/%command% help &7- Shows help list'
Info: ' &7- &e/%command% info [world/particles/shapes/potion_effects] &7- View specific Info: ' &7- &e/%command% info [world/particles/shapes/potion_effects] &7- View specific information about plugin parameters'
information about plugin parameters' Player: ' &7- &e/%command% player <player> [world] [biome1, biome2...] &7- Randomly teleport another player'
Player: ' &7- &e/%command% player <player> [world] [biome1, biome2...] &7- Randomly
teleport another player'
Reload: ' &7- &e/%command% reload &7- Reloads the plugin' Reload: ' &7- &e/%command% reload &7- Reloads the plugin'
Settings: ' &7- &e/%command% settings &7- Pull up a gui and edit some settings' Settings: ' &7- &e/%command% settings &7- Pull up a gui and edit some settings'
Test: ' &7- &e/%command% test &7- Test out plugin effects after a teleport without Test: ' &7- &e/%command% test &7- Test out plugin effects after a teleport without moving'
moving'
Version: ' &7- &e/%command% version &7- View currently running version' Version: ' &7- &e/%command% version &7- View currently running version'
World: ' &7- &e/%command% world <world> [biome1, biome2...] &7- Randomly teleport World: ' &7- &e/%command% world <world> [biome1, biome2...] &7- Randomly teleport in another world'
in another world'
Location: ' &7- &e/%command% location <location_name> &7- Rtp using a specific location' Location: ' &7- &e/%command% location <location_name> &7- Rtp using a specific location'
Usage: Usage:
@ -66,9 +56,7 @@ Usage:
Edit: Edit:
Base: '&cUsage&7: /%command% edit <default/world> [args...]' Base: '&cUsage&7: /%command% edit <default/world> [args...]'
Default: '&cUsage&7: /%command% edit default <max/min/useworldborder/center> <value>' Default: '&cUsage&7: /%command% edit default <max/min/useworldborder/center> <value>'
World: '&cUsage&7: /%command% edit world <world> <max/min/useworldborder/center> World: '&cUsage&7: /%command% edit world <world> <max/min/useworldborder/center> <value>'
<value>'
Worldtype: '&cUsage&7: /%command% edit world_type <world> <NETHER/NORMAL>' Worldtype: '&cUsage&7: /%command% edit world_type <world> <NETHER/NORMAL>'
Override: '&cUsage&7: /%command% edit override <world> <world_to>' Override: '&cUsage&7: /%command% edit override <world> <world_to>'
BlacklistedBlocks: '&cUsage&7: /%command% edit blacklistedblocks <add/remove> BlacklistedBlocks: '&cUsage&7: /%command% edit blacklistedblocks <add/remove> <block_id>'
<block_id>'

View File

@ -3,44 +3,31 @@
Messages: Messages:
Prefix: '&7[&6BetterRTP&7] ' Prefix: '&7[&6BetterRTP&7] '
Success: # # Placeholders! %x% %y% and %z% are the x, y, and z coordinates that the player is being teleported to! # Success: # # Placeholders! %x% %y% and %z% are the x, y, and z coordinates that the player is being teleported to! #
Paid: '&aVous avez été téléporté aux coordonnées &7x=%x% y=%y% z=%z% pour un prix Paid: '&aVous avez été téléporté aux coordonnées &7x=%x% y=%y% z=%z% pour un prix de &c$%price%&7 en &f%attempts% &7tentatives !'
de &c$%price%&7 en &f%attempts% &7tentatives !' Bypass: '&aVous avez été téléporté aux cooordonées &7x=%x% y=%y% z=%z% en &f%attempts% &7tentatives !'
Bypass: '&aVous avez été téléporté aux cooordonées &7x=%x% y=%y% z=%z% en &f%attempts%
&7tentatives !'
Loading: '&aUn endroit sûr a été trouvé ! &7Chargement des chunks...' Loading: '&aUn endroit sûr a été trouvé ! &7Chargement des chunks...'
Teleport: '&aTéléportation... &fMerci de patienter pendant la recherche d''un Teleport: '&aTéléportation... &fMerci de patienter pendant la recherche d''un endroit sûr !'
endroit sûr !'
Failed: Failed:
Price: '&cVous n''avez pas pu être téléporté; Manque de fonds ! &7Vous devez avoir Price: '&cVous n''avez pas pu être téléporté; Manque de fonds ! &7Vous devez avoir au moins $%price% &7pour vous téléporter !'
au moins $%price% &7pour vous téléporter !' NotSafe: '&cImpossible de trouver un endroit sûr en %attempts% tentatives ! &7Vous n''avez pas été téléporté !'
NotSafe: '&cImpossible de trouver un endroit sûr en %attempts% tentatives ! &7Vous Hunger: '&cImpossible de vous téléporter car vous avez trop faim, manger pour remplir votre barre de nourriture !'
n''avez pas été téléporté !'
Hunger: '&cImpossible de vous téléporter car vous avez trop faim, manger pour
remplir votre barre de nourriture !'
Other: Other:
Success: '&a%player% a été téléporté aux coordonées &7x=%x% y=%y% z=%z% em &f%attempts% Success: '&a%player% a été téléporté aux coordonées &7x=%x% y=%y% z=%z% em &f%attempts% &7tentatives !'
&7tentatives !' NotSafe: '&cImpossible de trouver un endroit sûr en %attempts% tentatives ! &7%player% n''a pas été téléporté !'
NotSafe: '&cImpossible de trouver un endroit sûr en %attempts% tentatives ! &7%player% Biome: '&cIl demblerais que le biome &7%biome% &cn''existe pas ! &7Utiliser l''autocomplétion de la Tab list !'
n''a pas été téléporté !'
Biome: '&cIl demblerais que le biome &7%biome% &cn''existe pas ! &7Utiliser l''autocomplétion
de la Tab list !'
Reload: '&eConfiguration rechargée avec succès !' Reload: '&eConfiguration rechargée avec succès !'
NoPermission: NoPermission:
Basic: '&cDésolé ! Vous n''avez pas la permission de faire cela !' Basic: '&cDésolé ! Vous n''avez pas la permission de faire cela !'
World: '&cDésolé ! Vous n''êtes pas autorisé à vous téléporter dans le monde %world% World: '&cDésolé ! Vous n''êtes pas autorisé à vous téléporter dans le monde %world%!'
!' DisabledWorld: '&cLe monde %world% est désactivé ! &7Impossible de se téléporter!'
DisabledWorld: '&cLe monde %world% est désactivé ! &7Impossible de se téléporter Cooldown: '&cDésolé ! Vous ne pouvez pas vous téléporter pendant encore &6%time% &csecondes !'
!'
Cooldown: '&cDésolé ! Vous ne pouvez pas vous téléporter pendant encore &6%time%
&csecondes !'
Locked: '&cSDésolé ! &7Vous avez utilisé tous vos RTP''s !' Locked: '&cSDésolé ! &7Vous avez utilisé tous vos RTP''s !'
Invalid: '&cArgument invalide. Essayer ''/%command% help''' Invalid: '&cArgument invalide. Essayer ''/%command% help'''
NotOnline: '&cLe joueur &7%player% &cn''est pas en ligne !' NotOnline: '&cLe joueur &7%player% &cn''est pas en ligne !'
Delay: '&aTéléportation dans &f%time% &asecondes ! Ne bougez pas !' Delay: '&aTéléportation dans &f%time% &asecondes ! Ne bougez pas !'
Moved: '&cVous avez bougé ! &7Téléportation annulée !' Moved: '&cVous avez bougé ! &7Téléportation annulée !'
NotExist: '&cLe monde &7%world% &cn''existe pas !' NotExist: '&cLe monde &7%world% &cn''existe pas !'
Already: '&cOups! &7Il semblerait que vous essaiyez déjà de vous téléporter... Patientez Already: '&cOups! &7Il semblerait que vous essaiyez déjà de vous téléporter... Patientez un peu !'
un peu !'
Sign: '&7Le panneau de commande a été créé ! &7La commande est... ''&f/rtp %command%&7''' Sign: '&7Le panneau de commande a été créé ! &7La commande est... ''&f/rtp %command%&7'''
Edit: Edit:
Error: '&cErreur ! &cEntrée invalide !' Error: '&cErreur ! &cEntrée invalide !'
@ -50,25 +37,17 @@ Messages:
Help: Help:
Prefix: '&e&m-----&6&l BetterRTP &8| Aide &e&m-----' Prefix: '&e&m-----&6&l BetterRTP &8| Aide &e&m-----'
Main: ' &7- &e/%command% &7- Téléportez vous aléatoirement' Main: ' &7- &e/%command% &7- Téléportez vous aléatoirement'
Biome: ' &7- &e/%command% biome <biome1, biome2...> &7- Téléportez vous aléatoirement Biome: ' &7- &e/%command% biome <biome1, biome2...> &7- Téléportez vous aléatoirement parmi ces biomes'
parmi ces biomes' Edit: ' &7- &e/%command% edit <default/world> [args...] &7- Modifiez quelques paramètres du plugin'
Edit: ' &7- &e/%command% edit <default/world> [args...] &7- Modifiez quelques paramètres
du plugin'
Help: ' &7- &e/%command% help &7- Affichez l''aide' Help: ' &7- &e/%command% help &7- Affichez l''aide'
Info: ' &7- &e/%command% info [world/particles/shapes/potion_effects] &7- Visualisez Info: ' &7- &e/%command% info [world/particles/shapes/potion_effects] &7- Visualisez les infos du plugin sur des paramètres spécifiques'
les infos du plugin sur des paramètres spécifiques' Player: ' &7- &e/%command% player <joueur> [monde] &7- Téléporter aléatoirement un autre joueur'
Player: ' &7- &e/%command% player <joueur> [monde] &7- Téléporter aléatoirement
un autre joueur'
Reload: ' &7- &e/%command% reload &7- Recharger le plugin !' Reload: ' &7- &e/%command% reload &7- Recharger le plugin !'
Settings: ' &7- &e/%command% settings &7- Afficher une interface pour modifier des Settings: ' &7- &e/%command% settings &7- Afficher une interface pour modifier des paramètres'
paramètres' Test: ' &7- &e/%command% test &7- Testez les effets du plugin après une téléportation sans bouger'
Test: ' &7- &e/%command% test &7- Testez les effets du plugin après une téléportation
sans bouger'
Version: ' &7- &e/%command% version &7- Voir la version en cours d''exécution' Version: ' &7- &e/%command% version &7- Voir la version en cours d''exécution'
World: ' &7- &e/%command% world <monde> &7- Téléportez vous aléatoirement dans un World: ' &7- &e/%command% world <monde> &7- Téléportez vous aléatoirement dans un autre monde'
autre monde' Location: ' &7- &e/%command% location <location_name> &7- Téléporté vous en utilisant une location spécidfique'
Location: ' &7- &e/%command% location <location_name> &7- Téléporté vous en utilisant
une location spécidfique'
Usage: Usage:
Player: '&cUtilisation &7: /%command% player <joueur> [monde]' Player: '&cUtilisation &7: /%command% player <joueur> [monde]'
@ -77,11 +56,8 @@ Usage:
Location: '&cUtilisation &7: /%command% location <location_name>' Location: '&cUtilisation &7: /%command% location <location_name>'
Edit: Edit:
Base: '&cUtilisation &7: /%command% edit <default/world> [args...]' Base: '&cUtilisation &7: /%command% edit <default/world> [args...]'
Default: '&cUtilisation &7: /%command% edit default <max/min/useworldborder/center> Default: '&cUtilisation &7: /%command% edit default <max/min/useworldborder/center> <value>'
<value>' World: '&cUtilisation &7: /%command% edit world <world> <max/min/useworldborder/center> <value>'
World: '&cUtilisation &7: /%command% edit world <world> <max/min/useworldborder/center>
<value>'
Worldtype: '&cUtilisation &7: /%command% edit world_type <world> <NETHER/NORMAL>' Worldtype: '&cUtilisation &7: /%command% edit world_type <world> <NETHER/NORMAL>'
Override: '&cUtilisation &7: /%command% edit override <world> <world_to>' Override: '&cUtilisation &7: /%command% edit override <world> <world_to>'
BlacklistedBlocks: '&cUtilisation &7: /%command% edit blacklistedblocks <add/remove> BlacklistedBlocks: '&cUtilisation &7: /%command% edit blacklistedblocks <add/remove> <block_id>'
<block_id>'

View File

@ -20,11 +20,6 @@ softdepend:
- Multiverse-Core #Forcing Multiverse to load BEFORE BetterRTP - Multiverse-Core #Forcing Multiverse to load BEFORE BetterRTP
api-version: '1.13' api-version: '1.13'
commands:
betterrtp:
aliases: [brtp, rtp, randomtp]
description: Randomly teleport to a location
commands: commands:
betterrtp: betterrtp:
aliases: [brtp, rtp, randomtp] aliases: [brtp, rtp, randomtp]