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.List;
public class CmdQueue implements RTPCommand, RTPCommandHelpable {
public class CmdQueue implements RTPCommand {
public String getName() {
return "queue";
@ -36,11 +36,6 @@ public class CmdQueue implements RTPCommand, RTPCommandHelpable {
queueWorlds(sendi);
}
@Override
public String getHelp() {
return null;
}
//World
public static void sendInfo(CommandSender sendi, List<String> list) { //Send info
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<>();
for (World w : Bukkit.getWorlds())
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);
}
@ -61,7 +56,7 @@ public class CmdQueue implements RTPCommand, RTPCommandHelpable {
List<String> info = new ArrayList<>();
info.add("&eWorld: &6" + world.getName());
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();
str = str.replace("%x", String.valueOf(loc.getBlockX())).replace("%z", String.valueOf(loc.getBlockZ()));
info.add(str);

View File

@ -138,8 +138,9 @@ public class RTP {
else {
world_type = WORLD_TYPE.NORMAL;
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. " +
"Please add/fix this in the config.yml file! This world will be treated as an overworld!");
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! " +
"If this world is a nether world, configure it to NETHER (example: `- " + pWorld.getWorld().getName() + ": NETHER`", false);
}
return world_type;
}

View File

@ -31,8 +31,8 @@ public class RTPLoader {
exists.set(true);
});
if (exists.get()) {
BetterRTP.debug("- Custom World '" + world + "' registered:");
customWorlds.put(world, new WorldCustom(Bukkit.getWorld(world)));
BetterRTP.debug("- Custom World '" + world + "' successfully registered");
} else
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<>();
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();
Long lastTime = handler.lastWarning.getOrDefault(type, 0L);
if (lastTime <= System.currentTimeMillis()) {
BetterRTP.getInstance().getLogger().info(str);
lastTime += System.currentTimeMillis() + (1000 * 120);
}
handler.lastWarning.put(type, lastTime);
if (auto_ignore) { //Ignored automatically every 30 minutes
Long lastTime = handler.lastWarning.getOrDefault(type, 0L);
if (lastTime <= System.currentTimeMillis()) {
BetterRTP.getInstance().getLogger().info(str);
lastTime += System.currentTimeMillis() + (1000 * 1800);
}
handler.lastWarning.put(type, lastTime);
} else
BetterRTP.getInstance().getLogger().warning(str);
}
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 "
+ COLUMNS.UUID.name + " = ?";
List<Object> params = new ArrayList<Object>() {{
add(uuid.toString());
}};
return sqlUpdate(sql, params);
sqlUpdate(sql, params);
}
public CooldownData getCooldown(UUID uuid, World world) {
@ -66,7 +66,7 @@ public class DatabaseCooldownsWorlds extends SQLite {
if (rs.next()) {
Long time = rs.getLong(COLUMNS.COOLDOWN_DATE.name);
//int uses = rs.getInt(COLUMNS.USES.name);
return new CooldownData(uuid, time, world);
return new CooldownData(uuid, time);
}
} catch (SQLException ex) {
BetterRTP.getInstance().getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
@ -77,9 +77,9 @@ public class DatabaseCooldownsWorlds extends SQLite {
}
//Set a player Cooldown
public void setCooldown(CooldownData data) {
public void setCooldown(World world, CooldownData data) {
String pre = "INSERT OR REPLACE INTO ";
String sql = pre + data.getWorld().getName() + " ("
String sql = pre + world.getName() + " ("
+ COLUMNS.UUID.name + ", "
+ COLUMNS.COOLDOWN_DATE.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 @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.time = time;
this.world = world;
}
}

View File

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