mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2025-08-17 09:05:47 +00:00
cooldowns per world blueprint (compilation errors pending)
This commit is contained in:
parent
158b89cb20
commit
098925d61a
@ -7,7 +7,6 @@ import me.SuperRonanCraft.BetterRTP.player.events.Listener;
|
||||
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP;
|
||||
import me.SuperRonanCraft.BetterRTP.references.Permissions;
|
||||
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.file.Files;
|
||||
import me.SuperRonanCraft.BetterRTP.references.file.Messages;
|
||||
@ -35,7 +34,6 @@ public class BetterRTP extends JavaPlugin {
|
||||
private final PlayerInfo pInfo = new PlayerInfo();
|
||||
@Getter private final PlayerDataManager playerDataManager = new PlayerDataManager();
|
||||
private final Settings settings = new Settings();
|
||||
@Getter private final DatabaseCooldowns databaseCooldowns = new DatabaseCooldowns();
|
||||
@Getter private final CooldownHandler cooldowns = new CooldownHandler();
|
||||
|
||||
public void onEnable() {
|
||||
|
@ -2,20 +2,25 @@ 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.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class DatabaseCooldowns extends SQLite {
|
||||
public class DatabaseCooldownsGlobal extends SQLite {
|
||||
|
||||
public DatabaseCooldowns() {
|
||||
super(DATABASE_TYPE.COOLDOWN);
|
||||
public DatabaseCooldownsGlobal() {
|
||||
super(DATABASE_TYPE.COOLDOWN_GLOBAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTables() {
|
||||
return Collections.singletonList("BetterRTP_Cooldown");
|
||||
}
|
||||
|
||||
public enum COLUMNS {
|
||||
@ -25,8 +30,8 @@ public class DatabaseCooldowns extends SQLite {
|
||||
USES("uses", "integer"),
|
||||
;
|
||||
|
||||
public String name;
|
||||
public String type;
|
||||
public final String name;
|
||||
public final String type;
|
||||
|
||||
COLUMNS(String name, String type) {
|
||||
this.name = name;
|
||||
@ -35,7 +40,7 @@ public class DatabaseCooldowns extends SQLite {
|
||||
}
|
||||
|
||||
public boolean removePlayer(UUID uuid) {
|
||||
String sql = "DELETE FROM " + table + " WHERE "
|
||||
String sql = "DELETE FROM " + tables.get(0) + " WHERE "
|
||||
+ COLUMNS.UUID.name + " = ?";
|
||||
List<Object> params = new ArrayList<Object>() {{
|
||||
add(uuid.toString());
|
||||
@ -49,14 +54,14 @@ public class DatabaseCooldowns extends SQLite {
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
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());
|
||||
|
||||
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);
|
||||
return new CooldownData(uuid, time, uses, null);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
BetterRTP.getInstance().getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
|
||||
@ -69,7 +74,7 @@ public class DatabaseCooldowns extends SQLite {
|
||||
//Set a player Cooldown
|
||||
public void setCooldown(CooldownData data) {
|
||||
String pre = "INSERT OR REPLACE INTO ";
|
||||
String sql = pre + table + " ("
|
||||
String sql = pre + tables.get(0) + " ("
|
||||
+ COLUMNS.UUID.name + ", "
|
||||
+ COLUMNS.COOLDOWN_DATE.name + ", "
|
||||
+ COLUMNS.USES.name + " "
|
||||
@ -85,7 +90,7 @@ public class DatabaseCooldowns extends SQLite {
|
||||
//Update multiple players cooldowns
|
||||
public void setCooldown(List<CooldownData> cooldownData) {
|
||||
String pre = "INSERT OR REPLACE INTO ";
|
||||
String sql = pre + table + " ("
|
||||
String sql = pre + tables.get(0) + " ("
|
||||
+ COLUMNS.UUID.name + ", "
|
||||
+ COLUMNS.COOLDOWN_DATE.name + ", "
|
||||
+ COLUMNS.USES.name + " "
|
@ -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);
|
||||
}
|
||||
}*/
|
||||
}
|
@ -2,7 +2,6 @@ package me.SuperRonanCraft.BetterRTP.references.database;
|
||||
|
||||
import lombok.NonNull;
|
||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.io.File;
|
||||
@ -12,15 +11,13 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class SQLite {
|
||||
public abstract class SQLite {
|
||||
|
||||
private static final String db_file_name = "database";
|
||||
//private final boolean sqlEnabled;
|
||||
String table;
|
||||
private String host, database, username, password;
|
||||
private int port;
|
||||
boolean sqlEnabled;
|
||||
//Connection connection;
|
||||
List<String> tables;
|
||||
//private String host, database, username, password;
|
||||
//private int port;
|
||||
//boolean sqlEnabled;
|
||||
private boolean loaded;
|
||||
|
||||
public String addMissingColumns = "ALTER TABLE %table% ADD COLUMN %column% %type%";
|
||||
@ -31,9 +28,11 @@ public class SQLite {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public abstract List<String> getTables();
|
||||
|
||||
// SQL creation stuff
|
||||
public Connection getSQLConnection() {
|
||||
if (sqlEnabled) {
|
||||
/*if (sqlEnabled) {
|
||||
try {
|
||||
return getOnline();
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
@ -41,17 +40,17 @@ public class SQLite {
|
||||
BetterRTP.getInstance().getLogger().info("MySQL setup is incorrect! Grabbing data from local database!");
|
||||
sqlEnabled = false;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
return getLocal();
|
||||
}
|
||||
|
||||
private Connection getOnline() throws SQLException, ClassNotFoundException {
|
||||
/*private Connection getOnline() throws SQLException, ClassNotFoundException {
|
||||
synchronized (this) {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
return DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database +
|
||||
"?autoReconnect=true&useSSL=false", this.username, this.password);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
private Connection getLocal() {
|
||||
File dataFolder = new File(BetterRTP.getInstance().getDataFolder().getPath() + File.separator + "data", db_file_name + ".db");
|
||||
@ -65,55 +64,53 @@ public class SQLite {
|
||||
}
|
||||
}
|
||||
try {
|
||||
//if (connection != null && !connection.isClosed()) {
|
||||
// return connection;
|
||||
//}
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
return DriverManager.getConnection("jdbc:sqlite:" + dataFolder);
|
||||
//return connection;
|
||||
} catch (SQLException ex) {
|
||||
BetterRTP.getInstance().getLogger().log(Level.SEVERE, "SQLite exception on initialize", 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;
|
||||
}
|
||||
|
||||
public void load() {
|
||||
loaded = false;
|
||||
switch (type) {
|
||||
/*switch (type) {
|
||||
case COOLDOWN: table = "BetterRTP_Cooldown"; break;
|
||||
}
|
||||
if (table == null) {
|
||||
BetterRTP.getInstance().getLogger().severe("The table for `" + type.name() + "` is invalid. Disabling the plugin!");
|
||||
Bukkit.getPluginManager().disablePlugin(BetterRTP.getInstance());
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
|
||||
Connection connection = getSQLConnection();
|
||||
try {
|
||||
Statement s = connection.createStatement();
|
||||
s.executeUpdate(getCreateTable());
|
||||
//s.executeUpdate(createTable_bank);
|
||||
for (Enum<?> c : getColumns(type)) { //Add missing columns dynamically
|
||||
try {
|
||||
String _name = getColumnName(type, c);
|
||||
String _type = getColumnType(type, c);
|
||||
//System.out.println("Adding " + _name);
|
||||
s.executeUpdate(addMissingColumns.replace("%table%", table).replace("%column%", _name).replace("%type%", _type));
|
||||
} catch (SQLException e) {
|
||||
//e.printStackTrace();
|
||||
for (String table : tables) {
|
||||
try {
|
||||
Statement s = connection.createStatement();
|
||||
s.executeUpdate(getCreateTable(table));
|
||||
//s.executeUpdate(createTable_bank);
|
||||
for (Enum<?> c : getColumns(type)) { //Add missing columns dynamically
|
||||
try {
|
||||
String _name = getColumnName(type, c);
|
||||
String _type = getColumnType(type, c);
|
||||
//System.out.println("Adding " + _name);
|
||||
s.executeUpdate(addMissingColumns.replace("%table%", table).replace("%column%", _name).replace("%type%", _type));
|
||||
} catch (SQLException e) {
|
||||
//e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
s.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (connection != null) {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
s.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (connection != null) {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
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 + " (";
|
||||
Enum<?>[] columns = getColumns(type);
|
||||
for (Enum<?> c : columns) {
|
||||
@ -141,19 +138,19 @@ public class SQLite {
|
||||
|
||||
private Enum<?>[] getColumns(DATABASE_TYPE type) {
|
||||
switch (type) {
|
||||
default: return DatabaseCooldowns.COLUMNS.values();
|
||||
default: return DatabaseCooldownsWorlds.COLUMNS.values();
|
||||
}
|
||||
}
|
||||
|
||||
private String getColumnName(DATABASE_TYPE type, Enum<?> column) {
|
||||
switch (type) {
|
||||
default: return ((DatabaseCooldowns.COLUMNS) column).name;
|
||||
default: return ((DatabaseCooldownsWorlds.COLUMNS) column).name;
|
||||
}
|
||||
}
|
||||
|
||||
private String getColumnType(DATABASE_TYPE type, Enum<?> column) {
|
||||
switch (type) {
|
||||
default: return ((DatabaseCooldowns.COLUMNS) column).type;
|
||||
default: return ((DatabaseCooldownsWorlds.COLUMNS) column).type;
|
||||
}
|
||||
}
|
||||
|
||||
@ -222,7 +219,7 @@ public class SQLite {
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
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();
|
||||
} catch (SQLException ex) {
|
||||
@ -247,6 +244,7 @@ public class SQLite {
|
||||
}
|
||||
|
||||
public enum DATABASE_TYPE {
|
||||
COOLDOWN
|
||||
COOLDOWN,
|
||||
COOLDOWN_GLOBAL, //Table to know last time in general player has a cooldown for
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ public class HelperRTP {
|
||||
return false;
|
||||
}
|
||||
//Cooldown Data
|
||||
CooldownData cooldownData = getPl().getCooldowns().getPlayer(player);
|
||||
CooldownData cooldownData = getPl().getCooldowns().get(player);
|
||||
if (cooldownData != null) {
|
||||
if (cooldownHandler.locked(cooldownData)) { //Infinite cooldown (locked)
|
||||
getPl().getText().getNoPermission(sendi);
|
||||
|
@ -3,8 +3,13 @@ package me.SuperRonanCraft.BetterRTP.references.player.playerdata;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.CooldownData;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class PlayerData {
|
||||
|
||||
public boolean loading; //Is this players data loading?
|
||||
@ -12,7 +17,8 @@ public class PlayerData {
|
||||
//Menus
|
||||
@Getter final PlayerData_Menus menu = new PlayerData_Menus();
|
||||
//Player Data
|
||||
@Getter @Setter CooldownData cooldown;
|
||||
@Getter final HashMap<World, CooldownData> cooldowns = new HashMap<>();
|
||||
@Getter @Setter CooldownData globalCooldown;
|
||||
@Getter @Setter boolean rtping;
|
||||
|
||||
PlayerData(Player player) {
|
||||
|
@ -2,6 +2,7 @@ package me.SuperRonanCraft.BetterRTP.references.rtpinfo;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@ -9,10 +10,12 @@ public class CooldownData {
|
||||
@Getter private final UUID uuid;
|
||||
@Getter @Setter private Long time;
|
||||
@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.time = time;
|
||||
this.uses = uses;
|
||||
this.world = world;
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,20 @@
|
||||
package me.SuperRonanCraft.BetterRTP.references.rtpinfo;
|
||||
|
||||
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.BetterRTP;
|
||||
import me.SuperRonanCraft.BetterRTP.references.player.HelperPlayer;
|
||||
import me.SuperRonanCraft.BetterRTP.references.player.playerdata.PlayerData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class CooldownHandler {
|
||||
|
||||
@ -25,6 +23,8 @@ public class CooldownHandler {
|
||||
timer, //Cooldown timer
|
||||
lockedAfter; //Rtp's before being locked
|
||||
private final List<Player> downloading = new ArrayList<>();
|
||||
private final DatabaseCooldownsWorlds cooldowns = new DatabaseCooldownsWorlds();
|
||||
private final DatabaseCooldownsGlobal globalCooldown = new DatabaseCooldownsGlobal();
|
||||
|
||||
public void load() {
|
||||
//configfile = new File(BetterRTP.getInstance().getDataFolder(), "data/cooldowns.yml");
|
||||
@ -37,29 +37,34 @@ public class CooldownHandler {
|
||||
lockedAfter = config.getInt("Settings.Cooldown.LockAfter");
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
|
||||
getDatabase().load();
|
||||
globalCooldown.load();
|
||||
cooldowns.load();
|
||||
checkLater();
|
||||
});
|
||||
}
|
||||
|
||||
private void checkLater() {
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(BetterRTP.getInstance(), () -> {
|
||||
if (getDatabase().isLoaded()) {
|
||||
OldCooldownConverter.loadOldCooldowns();
|
||||
//Load any online players cooldowns (mostly after a reload)
|
||||
for (Player p : Bukkit.getOnlinePlayers())
|
||||
loadPlayer(p);
|
||||
loaded = true;
|
||||
} else
|
||||
AtomicBoolean loaded = new AtomicBoolean(true);
|
||||
if (!globalCooldown.isLoaded()) {
|
||||
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);
|
||||
}
|
||||
|
||||
public void add(Player player) {
|
||||
public void add(Player player, World world) {
|
||||
if (!enabled) return;
|
||||
CooldownData data = getData(player).getCooldown();
|
||||
if (data == null)
|
||||
data = new CooldownData(player.getUniqueId(), 0L, 0);
|
||||
data = new CooldownData(player.getUniqueId(), 0L, 0, world);
|
||||
if (lockedAfter > 0)
|
||||
data.setUses(data.getUses() + 1);
|
||||
data.setTime(System.currentTimeMillis());
|
||||
@ -68,12 +73,22 @@ public class CooldownHandler {
|
||||
}
|
||||
|
||||
public boolean exists(Player p) {
|
||||
return getData(p).getCooldown() != null;
|
||||
return getData(p).getCooldowns() != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public CooldownData getPlayer(Player p) {
|
||||
return getData(p).getCooldown();
|
||||
public CooldownData get(Player p, World world) {
|
||||
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) {
|
||||
@ -106,19 +121,21 @@ public class CooldownHandler {
|
||||
private void savePlayer(CooldownData data, boolean remove) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
|
||||
if (!remove) {
|
||||
getDatabase().setCooldown(data);
|
||||
getDatabase(data.getWorld()).setCooldown(data);
|
||||
} else {
|
||||
getDatabase().removePlayer(data.getUuid());
|
||||
getDatabase(data.getWorld()).removePlayer(data.getUuid(), data.getWorld());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void loadPlayer(Player player) {
|
||||
if (!isEnabled()) return;
|
||||
downloading.add(player);
|
||||
if (isEnabled()) {
|
||||
CooldownData cooldown = getDatabase().getCooldown(player.getUniqueId());
|
||||
List<CooldownData> cooldowns = new ArrayList<>();
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
CooldownData cooldown = getDatabaseWorlds().getCooldown(player.getUniqueId(), world);
|
||||
if (cooldown != null)
|
||||
getData(player).setCooldown(cooldown);
|
||||
getData(player).getCooldowns().add(cooldown);
|
||||
}
|
||||
downloading.remove(player);
|
||||
}
|
||||
@ -127,7 +144,17 @@ public class CooldownHandler {
|
||||
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 void loadOldCooldowns() {
|
||||
@ -162,12 +189,6 @@ public class CooldownHandler {
|
||||
private static YamlConfiguration getFile(File configfile) {
|
||||
if (!configfile.exists()) {
|
||||
return null;
|
||||
/*try {
|
||||
configfile.getParentFile().mkdir();
|
||||
configfile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
}
|
||||
try {
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
@ -178,13 +199,4 @@ public class CooldownHandler {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private DatabaseCooldowns getDatabase() {
|
||||
return BetterRTP.getInstance().getDatabaseCooldowns();
|
||||
}
|
||||
|
||||
private PlayerData getData(Player p) {
|
||||
return HelperPlayer.getData(p);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
@ -2,23 +2,18 @@
|
||||
Messages:
|
||||
Prefix: '&7[&6BetterRTP&7] '
|
||||
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%
|
||||
&7attempts!'
|
||||
Paid: '&aYou have been tp''d to&7 x=%x% y=%y% z=%z% for &c$%price%&7 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...'
|
||||
Teleport: '&aTeleporting... &fplease wait while we find a safe location!'
|
||||
Failed:
|
||||
Price: '&cCould not rtp because of insufficent funds! &7You must have atleast
|
||||
$%price% &7to rtp!'
|
||||
NotSafe: '&cCould not find safe spot within %attempts% attempts! &7You were not
|
||||
RTP''d!'
|
||||
Price: '&cCould not rtp because of insufficent funds! &7You must have atleast $%price% &7to rtp!'
|
||||
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!'
|
||||
Other:
|
||||
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
|
||||
not rtp''d!'
|
||||
Biome: '&cSeems like the biome&7 %biome%&c does not exist! &7Try using the tab
|
||||
list!'
|
||||
NotSafe: '&cCould not find safe spot within %attempts% attempts! &7%player% was not rtp''d!'
|
||||
Biome: '&cSeems like the biome&7 %biome%&c does not exist! &7Try using the tab list!'
|
||||
Reload: '&eConfig reloaded successfully!'
|
||||
NoPermission:
|
||||
Basic: '&cSorry! &7You don''t have permission to use this command!'
|
||||
@ -41,21 +36,16 @@ Messages:
|
||||
Help:
|
||||
Prefix: '&e&m-----&6&l BetterRTP &8| Help &e&m-----'
|
||||
Main: ' &7- &e/%command% &7- Randomly teleports you!'
|
||||
Biome: ' &7- &e/%command% biome <biome1, biome2...> &7- Randomly teleport withing
|
||||
these biomes'
|
||||
Biome: ' &7- &e/%command% biome <biome1, biome2...> &7- Randomly teleport withing these biomes'
|
||||
Edit: ' &7- &e/%command% edit <default/world> [args...] &7- Edit some plugin settings'
|
||||
Help: ' &7- &e/%command% help &7- Shows help list'
|
||||
Info: ' &7- &e/%command% info [world/particles/shapes/potion_effects] &7- View specific
|
||||
information about plugin parameters'
|
||||
Player: ' &7- &e/%command% player <player> [world] [biome1, biome2...] &7- Randomly
|
||||
teleport another player'
|
||||
Info: ' &7- &e/%command% info [world/particles/shapes/potion_effects] &7- View specific information about plugin parameters'
|
||||
Player: ' &7- &e/%command% player <player> [world] [biome1, biome2...] &7- Randomly teleport another player'
|
||||
Reload: ' &7- &e/%command% reload &7- Reloads the plugin'
|
||||
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
|
||||
moving'
|
||||
Test: ' &7- &e/%command% test &7- Test out plugin effects after a teleport without moving'
|
||||
Version: ' &7- &e/%command% version &7- View currently running version'
|
||||
World: ' &7- &e/%command% world <world> [biome1, biome2...] &7- Randomly teleport
|
||||
in another world'
|
||||
World: ' &7- &e/%command% world <world> [biome1, biome2...] &7- Randomly teleport in another world'
|
||||
Location: ' &7- &e/%command% location <location_name> &7- Rtp using a specific location'
|
||||
|
||||
Usage:
|
||||
@ -66,9 +56,7 @@ Usage:
|
||||
Edit:
|
||||
Base: '&cUsage&7: /%command% edit <default/world> [args...]'
|
||||
Default: '&cUsage&7: /%command% edit default <max/min/useworldborder/center> <value>'
|
||||
World: '&cUsage&7: /%command% edit world <world> <max/min/useworldborder/center>
|
||||
<value>'
|
||||
World: '&cUsage&7: /%command% edit world <world> <max/min/useworldborder/center> <value>'
|
||||
Worldtype: '&cUsage&7: /%command% edit world_type <world> <NETHER/NORMAL>'
|
||||
Override: '&cUsage&7: /%command% edit override <world> <world_to>'
|
||||
BlacklistedBlocks: '&cUsage&7: /%command% edit blacklistedblocks <add/remove>
|
||||
<block_id>'
|
||||
BlacklistedBlocks: '&cUsage&7: /%command% edit blacklistedblocks <add/remove> <block_id>'
|
||||
|
@ -3,44 +3,31 @@
|
||||
Messages:
|
||||
Prefix: '&7[&6BetterRTP&7] '
|
||||
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
|
||||
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 !'
|
||||
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 !'
|
||||
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...'
|
||||
Teleport: '&aTéléportation... &fMerci de patienter pendant la recherche d''un
|
||||
endroit sûr !'
|
||||
Teleport: '&aTéléportation... &fMerci de patienter pendant la recherche d''un endroit sûr !'
|
||||
Failed:
|
||||
Price: '&cVous n''avez pas pu être téléporté; Manque de fonds ! &7Vous devez avoir
|
||||
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é !'
|
||||
Hunger: '&cImpossible de vous téléporter car vous avez trop faim, manger pour
|
||||
remplir votre barre de nourriture !'
|
||||
Price: '&cVous n''avez pas pu être téléporté; Manque de fonds ! &7Vous devez avoir 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é !'
|
||||
Hunger: '&cImpossible de vous téléporter car vous avez trop faim, manger pour remplir votre barre de nourriture !'
|
||||
Other:
|
||||
Success: '&a%player% a été téléporté aux coordonées &7x=%x% y=%y% z=%z% em &f%attempts%
|
||||
&7tentatives !'
|
||||
NotSafe: '&cImpossible de trouver un endroit sûr en %attempts% tentatives ! &7%player%
|
||||
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 !'
|
||||
Success: '&a%player% a été téléporté aux coordonées &7x=%x% y=%y% z=%z% em &f%attempts% &7tentatives !'
|
||||
NotSafe: '&cImpossible de trouver un endroit sûr en %attempts% tentatives ! &7%player% 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 !'
|
||||
NoPermission:
|
||||
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%
|
||||
!'
|
||||
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 !'
|
||||
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!'
|
||||
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 !'
|
||||
Invalid: '&cArgument invalide. Essayer ''/%command% help'''
|
||||
NotOnline: '&cLe joueur &7%player% &cn''est pas en ligne !'
|
||||
Delay: '&aTéléportation dans &f%time% &asecondes ! Ne bougez pas !'
|
||||
Moved: '&cVous avez bougé ! &7Téléportation annulée !'
|
||||
NotExist: '&cLe monde &7%world% &cn''existe pas !'
|
||||
Already: '&cOups! &7Il semblerait que vous essaiyez déjà de vous téléporter... Patientez
|
||||
un peu !'
|
||||
Already: '&cOups! &7Il semblerait que vous essaiyez déjà de vous téléporter... Patientez un peu !'
|
||||
Sign: '&7Le panneau de commande a été créé ! &7La commande est... ''&f/rtp %command%&7'''
|
||||
Edit:
|
||||
Error: '&cErreur ! &cEntrée invalide !'
|
||||
@ -50,25 +37,17 @@ Messages:
|
||||
Help:
|
||||
Prefix: '&e&m-----&6&l BetterRTP &8| Aide &e&m-----'
|
||||
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
|
||||
parmi ces biomes'
|
||||
Edit: ' &7- &e/%command% edit <default/world> [args...] &7- Modifiez quelques paramètres
|
||||
du plugin'
|
||||
Biome: ' &7- &e/%command% biome <biome1, biome2...> &7- Téléportez vous aléatoirement parmi ces biomes'
|
||||
Edit: ' &7- &e/%command% edit <default/world> [args...] &7- Modifiez quelques paramètres du plugin'
|
||||
Help: ' &7- &e/%command% help &7- Affichez l''aide'
|
||||
Info: ' &7- &e/%command% info [world/particles/shapes/potion_effects] &7- Visualisez
|
||||
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'
|
||||
Info: ' &7- &e/%command% info [world/particles/shapes/potion_effects] &7- Visualisez 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'
|
||||
Reload: ' &7- &e/%command% reload &7- Recharger le plugin !'
|
||||
Settings: ' &7- &e/%command% settings &7- Afficher une interface pour modifier des
|
||||
paramètres'
|
||||
Test: ' &7- &e/%command% test &7- Testez les effets du plugin après une téléportation
|
||||
sans bouger'
|
||||
Settings: ' &7- &e/%command% settings &7- Afficher une interface pour modifier des paramètres'
|
||||
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'
|
||||
World: ' &7- &e/%command% world <monde> &7- Téléportez vous aléatoirement dans un
|
||||
autre monde'
|
||||
Location: ' &7- &e/%command% location <location_name> &7- Téléporté vous en utilisant
|
||||
une location spécidfique'
|
||||
World: ' &7- &e/%command% world <monde> &7- Téléportez vous aléatoirement dans un autre monde'
|
||||
Location: ' &7- &e/%command% location <location_name> &7- Téléporté vous en utilisant une location spécidfique'
|
||||
|
||||
Usage:
|
||||
Player: '&cUtilisation &7: /%command% player <joueur> [monde]'
|
||||
@ -77,11 +56,8 @@ Usage:
|
||||
Location: '&cUtilisation &7: /%command% location <location_name>'
|
||||
Edit:
|
||||
Base: '&cUtilisation &7: /%command% edit <default/world> [args...]'
|
||||
Default: '&cUtilisation &7: /%command% edit default <max/min/useworldborder/center>
|
||||
<value>'
|
||||
World: '&cUtilisation &7: /%command% edit world <world> <max/min/useworldborder/center>
|
||||
<value>'
|
||||
Default: '&cUtilisation &7: /%command% edit default <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>'
|
||||
Override: '&cUtilisation &7: /%command% edit override <world> <world_to>'
|
||||
BlacklistedBlocks: '&cUtilisation &7: /%command% edit blacklistedblocks <add/remove>
|
||||
<block_id>'
|
||||
BlacklistedBlocks: '&cUtilisation &7: /%command% edit blacklistedblocks <add/remove> <block_id>'
|
||||
|
@ -20,11 +20,6 @@ softdepend:
|
||||
- Multiverse-Core #Forcing Multiverse to load BEFORE BetterRTP
|
||||
api-version: '1.13'
|
||||
|
||||
commands:
|
||||
betterrtp:
|
||||
aliases: [brtp, rtp, randomtp]
|
||||
description: Randomly teleport to a location
|
||||
|
||||
commands:
|
||||
betterrtp:
|
||||
aliases: [brtp, rtp, randomtp]
|
||||
|
Loading…
x
Reference in New Issue
Block a user