mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2025-08-17 17:15:47 +00:00
cooldowns convert + hClaims fix
This commit is contained in:
parent
86bf26535e
commit
141e857ed8
@ -97,9 +97,6 @@ public class BetterRTP extends JavaPlugin {
|
|||||||
invs.closeAll();
|
invs.closeAll();
|
||||||
loadAll();
|
loadAll();
|
||||||
text.getReload(sendi);
|
text.getReload(sendi);
|
||||||
//Reload all players cooldowns
|
|
||||||
for (Player p : Bukkit.getOnlinePlayers())
|
|
||||||
getCmd().cooldowns.loadPlayer(p.getUniqueId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public RTPInventories getInvs() {
|
public RTPInventories getInvs() {
|
||||||
|
@ -174,6 +174,8 @@ public class Commands {
|
|||||||
if (sendi != player || pl.getPerms().getBypassCooldown(player)) { //Bypassing/Forced?
|
if (sendi != player || pl.getPerms().getBypassCooldown(player)) { //Bypassing/Forced?
|
||||||
return true;
|
return true;
|
||||||
} else if (cooldowns.isEnabled()) { //Cooling down?
|
} else if (cooldowns.isEnabled()) { //Cooling down?
|
||||||
|
if (!cooldowns.database.isLoaded()) //Cooldowns have yet to download
|
||||||
|
return false;
|
||||||
UUID id = player.getUniqueId();
|
UUID id = player.getUniqueId();
|
||||||
if (cooldowns.exists(id)) {
|
if (cooldowns.exists(id)) {
|
||||||
if (cooldowns.locked(id)) { //Infinite cooldown (locked)
|
if (cooldowns.locked(id)) { //Infinite cooldown (locked)
|
||||||
|
@ -337,7 +337,7 @@ public class CmdEdit implements RTPCommand, RTPCommandHelpable { //Edit a worlds
|
|||||||
list.add(block.name());
|
list.add(block.name());
|
||||||
}
|
}
|
||||||
} else if (args[2].equalsIgnoreCase("remove")) {
|
} else if (args[2].equalsIgnoreCase("remove")) {
|
||||||
for (String block : BetterRTP.getInstance().getRTP().blockList) {
|
for (String block : BetterRTP.getInstance().getRTP().getBlockList()) {
|
||||||
if (block.startsWith(args[3]))
|
if (block.startsWith(args[3]))
|
||||||
list.add(block);
|
list.add(block);
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,14 @@ import lombok.Getter;
|
|||||||
import me.SuperRonanCraft.BetterRTP.references.database.DatabaseCooldowns;
|
import me.SuperRonanCraft.BetterRTP.references.database.DatabaseCooldowns;
|
||||||
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 org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -17,14 +20,13 @@ public class RTPCooldown {
|
|||||||
|
|
||||||
private final HashMap<UUID, Long> cooldowns = new HashMap<>(); //Cooldown timer for each player
|
private final HashMap<UUID, Long> cooldowns = new HashMap<>(); //Cooldown timer for each player
|
||||||
private HashMap<UUID, Integer> uses = null; //Players locked from rtp'ing ever again
|
private HashMap<UUID, Integer> uses = null; //Players locked from rtp'ing ever again
|
||||||
private final DatabaseCooldowns database = new DatabaseCooldowns();
|
public final DatabaseCooldowns database = new DatabaseCooldowns();
|
||||||
@Getter boolean enabled;
|
@Getter boolean enabled;
|
||||||
private int
|
private int
|
||||||
timer, //Cooldown timer
|
timer, //Cooldown timer
|
||||||
lockedAfter; //Rtp's before being locked
|
lockedAfter; //Rtp's before being locked
|
||||||
|
|
||||||
public void load() {
|
public void load() {
|
||||||
database.load();
|
|
||||||
//configfile = new File(BetterRTP.getInstance().getDataFolder(), "data/cooldowns.yml");
|
//configfile = new File(BetterRTP.getInstance().getDataFolder(), "data/cooldowns.yml");
|
||||||
cooldowns.clear();
|
cooldowns.clear();
|
||||||
if (uses != null)
|
if (uses != null)
|
||||||
@ -37,6 +39,13 @@ public class RTPCooldown {
|
|||||||
if (lockedAfter > 0)
|
if (lockedAfter > 0)
|
||||||
uses = new HashMap<>();
|
uses = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
|
||||||
|
database.load();
|
||||||
|
OldCooldownConverter.loadOldCooldowns(database);
|
||||||
|
//Load any online players cooldowns (mostly after a reload)
|
||||||
|
for (Player p : Bukkit.getOnlinePlayers())
|
||||||
|
loadPlayer(p.getUniqueId());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(UUID id) {
|
public void add(UUID id) {
|
||||||
@ -159,4 +168,68 @@ public class RTPCooldown {
|
|||||||
if (uses != null)
|
if (uses != null)
|
||||||
uses.remove(uuid);
|
uses.remove(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class OldCooldownConverter {
|
||||||
|
|
||||||
|
static void loadOldCooldowns(DatabaseCooldowns database) {
|
||||||
|
File file = new File(BetterRTP.getInstance().getDataFolder(), "data/cooldowns.yml");
|
||||||
|
YamlConfiguration config = getFile(file);
|
||||||
|
if (config == null) return;
|
||||||
|
if (config.getBoolean("Converted")) return;
|
||||||
|
List<CooldownData> cooldownData = new ArrayList<>();
|
||||||
|
for (String id : config.getConfigurationSection("").getKeys(false)) {
|
||||||
|
try {
|
||||||
|
Long time = config.getLong(id + ".Time");
|
||||||
|
UUID uuid = UUID.fromString(id);
|
||||||
|
int uses = config.getInt(id + ".Attempts");
|
||||||
|
cooldownData.add(new CooldownData(uuid, time, uses));
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
//Invalid UUID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
config.set("Converted", true);
|
||||||
|
try {
|
||||||
|
config.save(file);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
BetterRTP.getInstance().getLogger().info("Cooldowns converting to new database...");
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
|
||||||
|
database.setCooldown(cooldownData);
|
||||||
|
BetterRTP.getInstance().getLogger().info("Cooldowns have been converted to the new database!");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
config.load(configfile);
|
||||||
|
return config;
|
||||||
|
} catch (IOException | InvalidConfigurationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class CooldownData {
|
||||||
|
public UUID uuid;
|
||||||
|
public Long time;
|
||||||
|
public int uses;
|
||||||
|
|
||||||
|
CooldownData(UUID uuid, Long time, int uses) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
this.time = time;
|
||||||
|
this.uses = uses;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ public class RTPPluginValidation { //Safe locations depending on enabled depende
|
|||||||
boolean result = true;
|
boolean result = true;
|
||||||
if (getDepends().ishClaims())
|
if (getDepends().ishClaims())
|
||||||
try {
|
try {
|
||||||
result = ClaimAPI.isClaimed(loc);
|
result = ClaimAPI.getInstance().isClaimed(loc);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package me.SuperRonanCraft.BetterRTP.references.database;
|
package me.SuperRonanCraft.BetterRTP.references.database;
|
||||||
|
|
||||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||||
|
import me.SuperRonanCraft.BetterRTP.player.rtp.RTPCooldown;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@ -81,4 +82,22 @@ public class DatabaseCooldowns extends SQLite {
|
|||||||
}};
|
}};
|
||||||
sqlUpdate(sql, params);
|
sqlUpdate(sql, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Update multiple players cooldowns
|
||||||
|
public void setCooldown(List<RTPCooldown.CooldownData> cooldownData) {
|
||||||
|
String pre = "INSERT OR REPLACE INTO ";
|
||||||
|
String sql = pre + table + " ("
|
||||||
|
+ COLUMNS.UUID.name + ", "
|
||||||
|
+ COLUMNS.COOLDOWN_DATE.name + ", "
|
||||||
|
+ COLUMNS.USES.name + " "
|
||||||
|
+ ") VALUES(?, ?, ?)";
|
||||||
|
for (RTPCooldown.CooldownData data : cooldownData) {
|
||||||
|
List<Object> param = new ArrayList<>() {{
|
||||||
|
add(data.uuid.toString());
|
||||||
|
add(data.time);
|
||||||
|
add(data.uses);
|
||||||
|
}};
|
||||||
|
sqlUpdate(sql, param);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user