Cooldown world null fix

This commit is contained in:
RonanCraft 2022-04-12 14:06:25 -04:00
parent db0d64e404
commit 201f645c43
8 changed files with 37 additions and 42 deletions

View File

@ -23,7 +23,7 @@ import java.sql.Time;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class CmdQueue implements RTPCommand, RTPCommandHelpable { public class CmdQueue implements RTPCommand {
public String getName() { public String getName() {
return "queue"; return "queue";
@ -36,11 +36,6 @@ public class CmdQueue implements RTPCommand, RTPCommandHelpable {
queueWorlds(sendi); queueWorlds(sendi);
} }
@Override
public String getHelp() {
return null;
}
//World //World
public static void sendInfo(CommandSender sendi, List<String> list) { //Send info public static void sendInfo(CommandSender sendi, List<String> list) { //Send info
list.add(0, "&e&m-----&6 BetterRTP &8| Queue &e&m-----"); list.add(0, "&e&m-----&6 BetterRTP &8| Queue &e&m-----");
@ -53,7 +48,7 @@ public class CmdQueue implements RTPCommand, RTPCommandHelpable {
List<String> info = new ArrayList<>(); List<String> info = new ArrayList<>();
for (World w : Bukkit.getWorlds()) for (World w : Bukkit.getWorlds())
info.addAll(queueGetWorld(w)); info.addAll(queueGetWorld(w));
info.add("&eTotal of &a%amount% generated locations".replace("%amount%", String.valueOf(QueueHandler.getCount()))); info.add("&eTotal of &a%amount% &egenerated locations".replace("%amount%", String.valueOf(QueueHandler.getCount())));
sendInfo(sendi, info); sendInfo(sendi, info);
} }
@ -61,7 +56,7 @@ public class CmdQueue implements RTPCommand, RTPCommandHelpable {
List<String> info = new ArrayList<>(); List<String> info = new ArrayList<>();
info.add("&eWorld: &6" + world.getName()); info.add("&eWorld: &6" + world.getName());
for (QueueData queue : QueueHandler.getApplicable(world)) { for (QueueData queue : QueueHandler.getApplicable(world)) {
String str = "&7x= &b%x, &7z= &b%z"; String str = "&8- &7x= &b%x, &7z= &b%z";
Location loc = queue.getLocation(); Location loc = queue.getLocation();
str = str.replace("%x", String.valueOf(loc.getBlockX())).replace("%z", String.valueOf(loc.getBlockZ())); str = str.replace("%x", String.valueOf(loc.getBlockX())).replace("%z", String.valueOf(loc.getBlockZ()));
info.add(str); info.add(str);

View File

@ -138,8 +138,9 @@ public class RTP {
else { else {
world_type = WORLD_TYPE.NORMAL; world_type = WORLD_TYPE.NORMAL;
rtp.world_type.put(pWorld.getWorld().getName(), world_type); //Defaults this so the error message isn't spammed rtp.world_type.put(pWorld.getWorld().getName(), world_type); //Defaults this so the error message isn't spammed
WarningHandler.warn(WarningHandler.WARNING.NO_WORLD_TYPE_DECLARED, "Seems like the world `" + pWorld.getWorld() + "` does not have a `WorldType` declared. " + WarningHandler.warn(WarningHandler.WARNING.NO_WORLD_TYPE_DECLARED, "Seems like the world `" + pWorld.getWorld().getName() + "` does not have a `WorldType` declared. " +
"Please add/fix this in the config.yml file! This world will be treated as an overworld!"); "Please add/fix this in the config.yml file! This world will be treated as an overworld! " +
"If this world is a nether world, configure it to NETHER (example: `- " + pWorld.getWorld().getName() + ": NETHER`", false);
} }
return world_type; return world_type;
} }

View File

@ -31,8 +31,8 @@ public class RTPLoader {
exists.set(true); exists.set(true);
}); });
if (exists.get()) { if (exists.get()) {
BetterRTP.debug("- Custom World '" + world + "' registered:");
customWorlds.put(world, new WorldCustom(Bukkit.getWorld(world))); customWorlds.put(world, new WorldCustom(Bukkit.getWorld(world)));
BetterRTP.debug("- Custom World '" + world + "' successfully registered");
} else } else
BetterRTP.debug("[WARN] - Custom World '" + world + "' was not registered because world does NOT exist"); BetterRTP.debug("[WARN] - Custom World '" + world + "' was not registered because world does NOT exist");
} }

View File

@ -9,13 +9,20 @@ public class WarningHandler {
HashMap<WARNING, Long> lastWarning = new HashMap<>(); HashMap<WARNING, Long> lastWarning = new HashMap<>();
public static void warn(WARNING type, String str) { public static void warn(WARNING type, String str) {
warn(type, str, true);
}
public static void warn(WARNING type, String str, boolean auto_ignore) {
WarningHandler handler = BetterRTP.getInstance().getWarningHandler(); WarningHandler handler = BetterRTP.getInstance().getWarningHandler();
if (auto_ignore) { //Ignored automatically every 30 minutes
Long lastTime = handler.lastWarning.getOrDefault(type, 0L); Long lastTime = handler.lastWarning.getOrDefault(type, 0L);
if (lastTime <= System.currentTimeMillis()) { if (lastTime <= System.currentTimeMillis()) {
BetterRTP.getInstance().getLogger().info(str); BetterRTP.getInstance().getLogger().info(str);
lastTime += System.currentTimeMillis() + (1000 * 120); lastTime += System.currentTimeMillis() + (1000 * 1800);
} }
handler.lastWarning.put(type, lastTime); handler.lastWarning.put(type, lastTime);
} else
BetterRTP.getInstance().getLogger().warning(str);
} }
public enum WARNING { public enum WARNING {

View File

@ -44,13 +44,13 @@ public class DatabaseCooldownsWorlds extends SQLite {
} }
} }
public boolean removePlayer(UUID uuid, World world) { public void removePlayer(UUID uuid, World world) {
String sql = "DELETE FROM " + world.getName() + " WHERE " String sql = "DELETE FROM " + world.getName() + " 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());
}}; }};
return sqlUpdate(sql, params); sqlUpdate(sql, params);
} }
public CooldownData getCooldown(UUID uuid, World world) { public CooldownData getCooldown(UUID uuid, World world) {
@ -66,7 +66,7 @@ public class DatabaseCooldownsWorlds extends SQLite {
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, world); return new CooldownData(uuid, time);
} }
} catch (SQLException ex) { } catch (SQLException ex) {
BetterRTP.getInstance().getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex); BetterRTP.getInstance().getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
@ -77,9 +77,9 @@ public class DatabaseCooldownsWorlds extends SQLite {
} }
//Set a player Cooldown //Set a player Cooldown
public void setCooldown(CooldownData data) { public void setCooldown(World world, CooldownData data) {
String pre = "INSERT OR REPLACE INTO "; String pre = "INSERT OR REPLACE INTO ";
String sql = pre + data.getWorld().getName() + " (" String sql = pre + world.getName() + " ("
+ COLUMNS.UUID.name + ", " + COLUMNS.UUID.name + ", "
+ COLUMNS.COOLDOWN_DATE.name + " " + COLUMNS.COOLDOWN_DATE.name + " "
//+ COLUMNS.USES.name + " " //+ COLUMNS.USES.name + " "

View File

@ -1,6 +0,0 @@
package me.SuperRonanCraft.BetterRTP.references.helpers;
public class HelperRTP_EditConfig {
}

View File

@ -11,11 +11,9 @@ public class CooldownData {
@Getter private final UUID uuid; @Getter private final UUID uuid;
@Getter @Setter private Long time; @Getter @Setter private Long time;
@Getter private final @Nullable World world;
public CooldownData(UUID uuid, Long time, @Nullable World world) { public CooldownData(UUID uuid, Long time) {
this.uuid = uuid; this.uuid = uuid;
this.time = time; this.time = time;
this.world = world;
} }
} }

View File

@ -64,12 +64,12 @@ public class CooldownHandler {
PlayerData playerData = getData(player); PlayerData playerData = getData(player);
if (cooldownByWorld) { if (cooldownByWorld) {
HashMap<World, CooldownData> cooldowns = playerData.getCooldowns(); HashMap<World, CooldownData> cooldowns = playerData.getCooldowns();
CooldownData data = cooldowns.getOrDefault(world, new CooldownData(player.getUniqueId(), 0L, world)); CooldownData data = cooldowns.getOrDefault(world, new CooldownData(player.getUniqueId(), 0L));
playerData.setRtpCount(playerData.getRtpCount() + 1); playerData.setRtpCount(playerData.getRtpCount() + 1);
data.setTime(System.currentTimeMillis()); data.setTime(System.currentTimeMillis());
playerData.setGlobalCooldown(data.getTime()); playerData.setGlobalCooldown(data.getTime());
cooldowns.put(world, data); cooldowns.put(world, data);
savePlayer(player, data, false); savePlayer(player, world, data, false);
} else } else
add(player); add(player);
} }
@ -79,7 +79,7 @@ public class CooldownHandler {
PlayerData playerData = getData(player); PlayerData playerData = getData(player);
playerData.setRtpCount(playerData.getRtpCount() + 1); playerData.setRtpCount(playerData.getRtpCount() + 1);
playerData.setGlobalCooldown(System.currentTimeMillis()); playerData.setGlobalCooldown(System.currentTimeMillis());
savePlayer(player, null, false); savePlayer(player, null, null, false);
} }
@Nullable @Nullable
@ -90,7 +90,7 @@ public class CooldownHandler {
if (data != null) if (data != null)
return cooldownData.getOrDefault(world, null); return cooldownData.getOrDefault(world, null);
} else if (data.getGlobalCooldown() > 0) { } else if (data.getGlobalCooldown() > 0) {
return new CooldownData(p.getUniqueId(), data.getGlobalCooldown(), null); return new CooldownData(p.getUniqueId(), data.getGlobalCooldown());
} }
return null; return null;
} }
@ -115,24 +115,24 @@ public class CooldownHandler {
if (lockedAfter > 0) { if (lockedAfter > 0) {
//uses.put(id, uses.getOrDefault(id, 1) - 1); //uses.put(id, uses.getOrDefault(id, 1) - 1);
if (playerData.getRtpCount() <= 0) { //Remove from file as well if (playerData.getRtpCount() <= 0) { //Remove from file as well
savePlayer(player, cooldownData, true); savePlayer(player, world, cooldownData, true);
getData(player).getCooldowns().put(world, null); getData(player).getCooldowns().put(world, null);
} else { //Keep the player cached } else { //Keep the player cached
savePlayer(player, cooldownData, false); savePlayer(player, world, cooldownData, false);
} }
} else { //Remove completely } else { //Remove completely
getData(player).getCooldowns().remove(world); getData(player).getCooldowns().remove(world);
savePlayer(player, cooldownData, true); savePlayer(player, world, cooldownData, true);
} }
} }
private void savePlayer(Player player, @Nullable CooldownData data, boolean remove) { private void savePlayer(Player player, @Nullable World world, @Nullable CooldownData data, boolean remove) {
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> { Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
if (data != null && getDatabaseWorlds() != null) { //Per World enabled? if (world != null && data != null && getDatabaseWorlds() != null) { //Per World enabled?
if (!remove) if (!remove)
getDatabaseWorlds().setCooldown(data); getDatabaseWorlds().setCooldown(world, data);
else else
getDatabaseWorlds().removePlayer(data.getUuid(), data.getWorld()); getDatabaseWorlds().removePlayer(data.getUuid(), world);
} }
DatabaseHandler.getPlayers().setData(getData(player)); DatabaseHandler.getPlayers().setData(getData(player));
}); });