mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2025-08-17 17:15:47 +00:00
Cooldowns database async saving/loading + cooldowns updated to new system
This commit is contained in:
parent
7f388e6c6b
commit
d3bb025068
2
pom.xml
2
pom.xml
@ -7,7 +7,7 @@
|
|||||||
<groupId>me.SuperRonanCraft</groupId>
|
<groupId>me.SuperRonanCraft</groupId>
|
||||||
<artifactId>BetterRTP</artifactId>
|
<artifactId>BetterRTP</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>3.1.1</version>
|
<version>3.2.0</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
@ -6,6 +6,7 @@ import me.SuperRonanCraft.BetterRTP.player.commands.Commands;
|
|||||||
import me.SuperRonanCraft.BetterRTP.player.events.Listener;
|
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.database.DatabaseCooldowns;
|
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;
|
||||||
@ -14,11 +15,8 @@ import me.SuperRonanCraft.BetterRTP.references.invs.RTPInventories;
|
|||||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.CooldownHandler;
|
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.CooldownHandler;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.settings.Settings;
|
import me.SuperRonanCraft.BetterRTP.references.settings.Settings;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.web.Metrics;
|
import me.SuperRonanCraft.BetterRTP.references.web.Metrics;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.Updater;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -35,7 +33,7 @@ public class BetterRTP extends JavaPlugin {
|
|||||||
private final RTPInventories invs = new RTPInventories();
|
private final RTPInventories invs = new RTPInventories();
|
||||||
private final PlayerInfo pInfo = new PlayerInfo();
|
private final PlayerInfo pInfo = new PlayerInfo();
|
||||||
private final Settings settings = new Settings();
|
private final Settings settings = new Settings();
|
||||||
@Getter private final DatabaseCooldowns database = new DatabaseCooldowns();
|
@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() {
|
||||||
@ -114,6 +112,7 @@ public class BetterRTP extends JavaPlugin {
|
|||||||
|
|
||||||
//(Re)Load all plugin systems/files/cache
|
//(Re)Load all plugin systems/files/cache
|
||||||
private void loadAll() {
|
private void loadAll() {
|
||||||
|
pInfo.unloadAll();
|
||||||
files.loadAll();
|
files.loadAll();
|
||||||
settings.load();
|
settings.load();
|
||||||
invs.load();
|
invs.load();
|
||||||
|
@ -9,6 +9,7 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class PlayerInfo {
|
public class PlayerInfo {
|
||||||
|
|
||||||
@ -17,6 +18,7 @@ public class PlayerInfo {
|
|||||||
@Getter private final HashMap<Player, World> invWorld = new HashMap<>();
|
@Getter private final HashMap<Player, World> invWorld = new HashMap<>();
|
||||||
@Getter private final HashMap<Player, RTP_INV_SETTINGS> invNextInv = new HashMap<>();
|
@Getter private final HashMap<Player, RTP_INV_SETTINGS> invNextInv = new HashMap<>();
|
||||||
@Getter private final HashMap<Player, CooldownData> cooldown = new HashMap<>();
|
@Getter private final HashMap<Player, CooldownData> cooldown = new HashMap<>();
|
||||||
|
@Getter private final HashMap<Player, Boolean> rtping = new HashMap<>();
|
||||||
//private final HashMap<Player, RTP_TYPE> rtpType = new HashMap<>();
|
//private final HashMap<Player, RTP_TYPE> rtpType = new HashMap<>();
|
||||||
|
|
||||||
public void setInv(Player p, Inventory inv) {
|
public void setInv(Player p, Inventory inv) {
|
||||||
@ -41,18 +43,25 @@ public class PlayerInfo {
|
|||||||
return invs.containsKey(p);
|
return invs.containsKey(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void unloadAll() {
|
||||||
invs.clear();
|
invs.clear();
|
||||||
invType.clear();
|
invType.clear();
|
||||||
invWorld.clear();
|
invWorld.clear();
|
||||||
invNextInv.clear();
|
invNextInv.clear();
|
||||||
|
cooldown.clear();
|
||||||
|
rtping.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear(Player p) {
|
public void unload(Player p) {
|
||||||
|
clearInvs(p);
|
||||||
|
cooldown.remove(p);
|
||||||
|
rtping.remove(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearInvs(Player p) {
|
||||||
invs.remove(p);
|
invs.remove(p);
|
||||||
invType.remove(p);
|
invType.remove(p);
|
||||||
invWorld.remove(p);
|
invWorld.remove(p);
|
||||||
invNextInv.remove(p);
|
invNextInv.remove(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package me.SuperRonanCraft.BetterRTP.player.commands;
|
package me.SuperRonanCraft.BetterRTP.player.commands;
|
||||||
|
|
||||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||||
|
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.CooldownData;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.CooldownHandler;
|
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.CooldownHandler;
|
||||||
import me.SuperRonanCraft.BetterRTP.player.rtp.RTPSetupInformation;
|
import me.SuperRonanCraft.BetterRTP.player.rtp.RTPSetupInformation;
|
||||||
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP_TYPE;
|
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP_TYPE;
|
||||||
@ -13,14 +14,11 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class Commands {
|
public class Commands {
|
||||||
|
|
||||||
private final BetterRTP pl;
|
private final BetterRTP pl;
|
||||||
public HashMap<UUID, Boolean> rtping = new HashMap<>();
|
|
||||||
private int delayTimer;
|
private int delayTimer;
|
||||||
public List<RTPCommand> commands = new ArrayList<>();
|
public List<RTPCommand> commands = new ArrayList<>();
|
||||||
|
|
||||||
@ -31,7 +29,6 @@ public class Commands {
|
|||||||
public void load() {
|
public void load() {
|
||||||
FileBasics.FILETYPE config = FileBasics.FILETYPE.CONFIG;
|
FileBasics.FILETYPE config = FileBasics.FILETYPE.CONFIG;
|
||||||
delayTimer = config.getInt("Settings.Delay.Time");
|
delayTimer = config.getInt("Settings.Delay.Time");
|
||||||
rtping.clear();
|
|
||||||
commands.clear();
|
commands.clear();
|
||||||
for (RTPCommandType cmd : RTPCommandType.values())
|
for (RTPCommandType cmd : RTPCommandType.values())
|
||||||
registerCommand(cmd.getCmd(), false);
|
registerCommand(cmd.getCmd(), false);
|
||||||
@ -154,14 +151,16 @@ public class Commands {
|
|||||||
if (pl.getSettings().delayEnabled && delayTimer > 0) //Delay enabled?
|
if (pl.getSettings().delayEnabled && delayTimer > 0) //Delay enabled?
|
||||||
if (!pl.getPerms().getBypassDelay(player)) //Can bypass?
|
if (!pl.getPerms().getBypassDelay(player)) //Can bypass?
|
||||||
delay = true;
|
delay = true;
|
||||||
RTPSetupInformation setup_info = new RTPSetupInformation(world, sendi, player, true, biomes, delay, rtpType, locations);
|
//player.sendMessage("Cooldown applies: " + cooldownApplies(sendi, player));
|
||||||
|
RTPSetupInformation setup_info = new RTPSetupInformation(world, sendi, player, true,
|
||||||
|
biomes, delay, rtpType, locations, !ignoreCooldown && cooldownApplies(sendi, player)); //ignore cooldown or else
|
||||||
pl.getRTP().start(setup_info);
|
pl.getRTP().start(setup_info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkRTPing(Player player, CommandSender sendi) {
|
private boolean checkRTPing(Player player, CommandSender sendi) {
|
||||||
if (rtping.containsKey(player.getUniqueId()) && rtping.get(player.getUniqueId())) {
|
if (getPl().getpInfo().getRtping().containsKey(player) && getPl().getpInfo().getRtping().get(player)) {
|
||||||
pl.getText().getAlready(sendi);
|
pl.getText().getAlready(sendi);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -169,18 +168,20 @@ public class Commands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkCooldown(CommandSender sendi, Player player) {
|
private boolean checkCooldown(CommandSender sendi, Player player) {
|
||||||
if (sendi != player || pl.getPerms().getBypassCooldown(player)) { //Bypassing/Forced?
|
if (cooldownApplies(sendi, player)) { //Bypassing/Forced?
|
||||||
return true;
|
CooldownHandler cooldownHandler = getPl().getCooldowns();
|
||||||
} else if (getPl().getCo.isEnabled()) { //Cooling down?
|
if (!cooldownHandler.isLoaded() || !cooldownHandler.loadedPlayer(player)) { //Cooldowns have yet to download
|
||||||
if (!.database.isLoaded()) //Cooldowns have yet to download
|
pl.getText().getCooldown(sendi, String.valueOf(-1L));
|
||||||
return false;
|
return false;
|
||||||
UUID id = player.getUniqueId();
|
}
|
||||||
if (cooldowns.exists(id)) {
|
//Cooldown Data
|
||||||
if (cooldowns.locked(id)) { //Infinite cooldown (locked)
|
CooldownData cooldownData = getPl().getCooldowns().getPlayer(player);
|
||||||
|
if (cooldownData != null) {
|
||||||
|
if (cooldownHandler.locked(cooldownData)) { //Infinite cooldown (locked)
|
||||||
pl.getText().getNoPermission(sendi);
|
pl.getText().getNoPermission(sendi);
|
||||||
return false;
|
return false;
|
||||||
} else { //Normal cooldown
|
} else { //Normal cooldown
|
||||||
long Left = cooldowns.timeLeft(id);
|
long Left = cooldownHandler.timeLeft(cooldownData);
|
||||||
if (pl.getSettings().delayEnabled && !pl.getPerms().getBypassDelay(sendi))
|
if (pl.getSettings().delayEnabled && !pl.getPerms().getBypassDelay(sendi))
|
||||||
Left = Left + delayTimer;
|
Left = Left + delayTimer;
|
||||||
if (Left > 0) {
|
if (Left > 0) {
|
||||||
@ -199,6 +200,18 @@ public class Commands {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean cooldownOverride(CommandSender sendi, Player player) {
|
||||||
|
return sendi != player || pl.getPerms().getBypassCooldown(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean cooldownEnabled() {
|
||||||
|
return getPl().getCooldowns().isEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean cooldownApplies(CommandSender sendi, Player player) {
|
||||||
|
return cooldownEnabled() && !cooldownOverride(sendi, player);
|
||||||
|
}
|
||||||
|
|
||||||
private BetterRTP getPl() {
|
private BetterRTP getPl() {
|
||||||
return BetterRTP.getInstance();
|
return BetterRTP.getInstance();
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ public class Click {
|
|||||||
PlayerInfo pInfo = BetterRTP.getInstance().getpInfo();
|
PlayerInfo pInfo = BetterRTP.getInstance().getpInfo();
|
||||||
Player p = (Player) e.getWhoClicked();
|
Player p = (Player) e.getWhoClicked();
|
||||||
RTPInventories menu = BetterRTP.getInstance().getInvs();
|
RTPInventories menu = BetterRTP.getInstance().getInvs();
|
||||||
menu.getInv(pInfo.getInvType(p)).clickEvent(e);
|
menu.getInv(pInfo.getInvType().get(p)).clickEvent(e);
|
||||||
} catch (NullPointerException ex) {
|
} catch (NullPointerException ex) {
|
||||||
//ex.printStackTrace();
|
//ex.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -36,10 +36,10 @@ public class Click {
|
|||||||
return false;
|
return false;
|
||||||
else if (e.getWhoClicked() instanceof Player) {
|
else if (e.getWhoClicked() instanceof Player) {
|
||||||
// Clicks the inventory
|
// Clicks the inventory
|
||||||
if (!e.getInventory().equals(BetterRTP.getInstance().getpInfo().getInv((Player) e.getWhoClicked())))
|
if (!e.getInventory().equals(BetterRTP.getInstance().getpInfo().getInvs().get((Player) e.getWhoClicked())))
|
||||||
return false;
|
return false;
|
||||||
// Clicks their own inventory
|
// Clicks their own inventory
|
||||||
else if (!e.getClickedInventory().equals(BetterRTP.getInstance().getpInfo().getInv((Player) e
|
else if (!e.getClickedInventory().equals(BetterRTP.getInstance().getpInfo().getInvs().get((Player) e
|
||||||
.getWhoClicked()))) {
|
.getWhoClicked()))) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
return false;
|
return false;
|
||||||
|
@ -13,7 +13,9 @@ public class Join {
|
|||||||
void event(PlayerJoinEvent e) {
|
void event(PlayerJoinEvent e) {
|
||||||
Player p = e.getPlayer();
|
Player p = e.getPlayer();
|
||||||
updater(p);
|
updater(p);
|
||||||
getPl().getCmd().cooldowns.loadPlayer(p.getUniqueId());
|
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
|
||||||
|
getPl().getCooldowns().loadPlayer(p);
|
||||||
|
});
|
||||||
rtpOnFirstJoin(p);
|
rtpOnFirstJoin(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package me.SuperRonanCraft.BetterRTP.player.events;
|
package me.SuperRonanCraft.BetterRTP.player.events;
|
||||||
|
|
||||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -9,8 +10,8 @@ class Leave {
|
|||||||
|
|
||||||
void event(PlayerQuitEvent e) {
|
void event(PlayerQuitEvent e) {
|
||||||
BetterRTP pl = BetterRTP.getInstance();
|
BetterRTP pl = BetterRTP.getInstance();
|
||||||
UUID id = e.getPlayer().getUniqueId();
|
Player p = e.getPlayer();
|
||||||
pl.getCmd().rtping.remove(id);
|
pl.getpInfo().getRtping().remove(p);
|
||||||
pl.getCmd().cooldowns.unloadPlayer(id);
|
pl.getpInfo().unload(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
package me.SuperRonanCraft.BetterRTP.player.rtp;
|
package me.SuperRonanCraft.BetterRTP.player.rtp;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
|
|
||||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||||
|
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.*;
|
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.*;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.worlds.*;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -156,14 +155,16 @@ public class RTP {
|
|||||||
// Economy
|
// Economy
|
||||||
if (!getPl().getEco().hasBalance(sendi, pWorld))
|
if (!getPl().getEco().hasBalance(sendi, pWorld))
|
||||||
return;
|
return;
|
||||||
rtp(sendi, pWorld, setup_info.delay, setup_info.rtp_type);
|
rtp(sendi, pWorld, setup_info.delay, setup_info.rtp_type, setup_info.cooldown);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void rtp(CommandSender sendi, WorldPlayer pWorld, boolean delay, RTP_TYPE type) {
|
private void rtp(CommandSender sendi, WorldPlayer pWorld, boolean delay, RTP_TYPE type, boolean cooldown) {
|
||||||
//Cooldown
|
//Cooldown
|
||||||
Player p = pWorld.getPlayer();
|
Player p = pWorld.getPlayer();
|
||||||
getPl().getCmd().cooldowns.add(p.getUniqueId());
|
//p.sendMessage("Cooling down: " + cooldown);
|
||||||
getPl().getCmd().rtping.put(p.getUniqueId(), true); //Cache player so they cant run '/rtp' again while rtp'ing
|
if (cooldown)
|
||||||
|
getPl().getCooldowns().add(p);
|
||||||
|
getPl().getpInfo().getRtping().put(p, true); //Cache player so they cant run '/rtp' again while rtp'ing
|
||||||
//Setup player rtp methods
|
//Setup player rtp methods
|
||||||
RTPPlayer rtpPlayer = new RTPPlayer(p, this, pWorld, type);
|
RTPPlayer rtpPlayer = new RTPPlayer(p, this, pWorld, type);
|
||||||
// Delaying? Else, just go
|
// Delaying? Else, just go
|
||||||
|
@ -61,7 +61,7 @@ class RTPDelay implements Listener {
|
|||||||
getPl().getRTP().getTeleport().cancelledTeleport(rtp.getPlayer());
|
getPl().getRTP().getTeleport().cancelledTeleport(rtp.getPlayer());
|
||||||
//getPl().getEco().unCharge(rtp.getPlayer(), rtp.pWorld);
|
//getPl().getEco().unCharge(rtp.getPlayer(), rtp.pWorld);
|
||||||
getPl().getCooldowns().removeCooldown(rtp.getPlayer());
|
getPl().getCooldowns().removeCooldown(rtp.getPlayer());
|
||||||
getPl().getCmd().rtping.put(rtp.getPlayer().getUniqueId(), false);
|
getPl().getpInfo().getRtping().put(rtp.getPlayer(), false);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new RTP_CancelledEvent(rtp.getPlayer()));
|
Bukkit.getServer().getPluginManager().callEvent(new RTP_CancelledEvent(rtp.getPlayer()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ class RTPDelay implements Listener {
|
|||||||
private Runnable run(final CommandSender sendi, final RTPDelay cls) {
|
private Runnable run(final CommandSender sendi, final RTPDelay cls) {
|
||||||
return () -> {
|
return () -> {
|
||||||
HandlerList.unregisterAll(cls);
|
HandlerList.unregisterAll(cls);
|
||||||
if (getPl().getCmd().rtping.containsKey(rtp.getPlayer().getUniqueId()))
|
if (getPl().getpInfo().getRtping().containsKey(rtp.getPlayer()))
|
||||||
rtp.randomlyTeleport(sendi);
|
rtp.randomlyTeleport(sendi);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package me.SuperRonanCraft.BetterRTP.player.rtp;
|
|||||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
|
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.*;
|
import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.*;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.worlds.*;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -68,7 +67,7 @@ public class RTPLoader {
|
|||||||
valids.append(type.name()).append(", ");
|
valids.append(type.name()).append(", ");
|
||||||
valids.replace(valids.length() - 2, valids.length(), "");
|
valids.replace(valids.length() - 2, valids.length(), "");
|
||||||
getPl().getLogger().severe("World Type for '" + entry.getKey() + "' is INVALID '" + entry.getValue() +
|
getPl().getLogger().severe("World Type for '" + entry.getKey() + "' is INVALID '" + entry.getValue() +
|
||||||
"'. Valid ID's are: " + valids.toString());
|
"'. Valid ID's are: " + valids);
|
||||||
//Wrong rtp world type
|
//Wrong rtp world type
|
||||||
}
|
}
|
||||||
}/* else {
|
}/* else {
|
||||||
|
@ -79,9 +79,9 @@ public class RTPPlayer {
|
|||||||
getPl().getText().getFailedNotSafe(sendi, settings.maxAttempts);
|
getPl().getText().getFailedNotSafe(sendi, settings.maxAttempts);
|
||||||
else
|
else
|
||||||
getPl().getText().getOtherNotSafe(sendi, settings.maxAttempts, p.getName());*/
|
getPl().getText().getOtherNotSafe(sendi, settings.maxAttempts, p.getName());*/
|
||||||
getPl().getCmd().cooldowns.removeCooldown(p.getUniqueId());
|
getPl().getCooldowns().removeCooldown(p);
|
||||||
//getPl().getEco().unCharge(p, pWorld);
|
//getPl().getEco().unCharge(p, pWorld);
|
||||||
getPl().getCmd().rtping.put(p.getUniqueId(), false);
|
getPl().getpInfo().getRtping().put(p, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Location getLocAtNormal(int x, int z, World world, Float yaw, Float pitch, WorldPlayer pWorld) {
|
private Location getLocAtNormal(int x, int z, World world, Float yaw, Float pitch, WorldPlayer pWorld) {
|
||||||
|
@ -11,7 +11,7 @@ public class RTPSetupInformation {
|
|||||||
public String world;
|
public String world;
|
||||||
public CommandSender sender;
|
public CommandSender sender;
|
||||||
public Player player;
|
public Player player;
|
||||||
public boolean personalized;
|
public boolean personalized, cooldown;
|
||||||
public List<String> biomes;
|
public List<String> biomes;
|
||||||
public WorldLocations location;
|
public WorldLocations location;
|
||||||
public boolean delay;
|
public boolean delay;
|
||||||
@ -22,7 +22,12 @@ public class RTPSetupInformation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public RTPSetupInformation(String world, CommandSender sender, Player player, boolean personalized, List<String> biomes,
|
public RTPSetupInformation(String world, CommandSender sender, Player player, boolean personalized, List<String> biomes,
|
||||||
boolean delay, RTP_TYPE rtp_type, WorldLocations location) {
|
boolean delay, RTP_TYPE rtp_type, WorldLocations location) {
|
||||||
|
this(world, sender, player, personalized, biomes, delay, rtp_type, location, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RTPSetupInformation(String world, CommandSender sender, Player player, boolean personalized, List<String> biomes,
|
||||||
|
boolean delay, RTP_TYPE rtp_type, WorldLocations location, boolean cooldown) {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
@ -37,5 +42,6 @@ public class RTPSetupInformation {
|
|||||||
else if (this.location != null)
|
else if (this.location != null)
|
||||||
this.world = this.location.getWorld().getName();
|
this.world = this.location.getWorld().getName();
|
||||||
}
|
}
|
||||||
|
this.cooldown = cooldown;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ public class RTPTeleport {
|
|||||||
afterTeleport(p, loc, price, attempts, oldLoc, type);
|
afterTeleport(p, loc, price, attempts, oldLoc, type);
|
||||||
if (sendi != p) //Tell player who requested that the player rtp'd
|
if (sendi != p) //Tell player who requested that the player rtp'd
|
||||||
sendSuccessMsg(sendi, p.getName(), loc, price, false, attempts);
|
sendSuccessMsg(sendi, p.getName(), loc, price, false, attempts);
|
||||||
getPl().getCmd().rtping.remove(p.getUniqueId()); //No longer rtp'ing
|
getPl().getpInfo().getRtping().remove(p); //No longer rtp'ing
|
||||||
//Save respawn location if first join
|
//Save respawn location if first join
|
||||||
if (type == RTP_TYPE.JOIN) //RTP Type was Join
|
if (type == RTP_TYPE.JOIN) //RTP Type was Join
|
||||||
if (BetterRTP.getInstance().getSettings().rtpOnFirstJoin_SetAsRespawn) //Save as respawn is enabled
|
if (BetterRTP.getInstance().getSettings().rtpOnFirstJoin_SetAsRespawn) //Save as respawn is enabled
|
||||||
@ -70,7 +70,7 @@ public class RTPTeleport {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
getPl().getCmd().rtping.remove(p.getUniqueId()); //No longer rtp'ing (errored)
|
getPl().getpInfo().getRtping().remove(p); //No longer rtp'ing (errored)
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ public class DatabaseCooldowns extends SQLite {
|
|||||||
return sqlUpdate(sql, params);
|
return sqlUpdate(sql, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Object> getCooldown(UUID uuid) {
|
public CooldownData getCooldown(UUID uuid) {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
@ -54,10 +54,9 @@ public class DatabaseCooldowns extends SQLite {
|
|||||||
|
|
||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
List<Object> data = new ArrayList<>();
|
Long time = rs.getLong(COLUMNS.COOLDOWN_DATE.name);
|
||||||
data.add(rs.getLong(COLUMNS.COOLDOWN_DATE.name));
|
int uses = rs.getInt(COLUMNS.USES.name);
|
||||||
data.add(rs.getInt(COLUMNS.USES.name));
|
return new CooldownData(uuid, time, uses);
|
||||||
return data;
|
|
||||||
}
|
}
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
BetterRTP.getInstance().getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
|
BetterRTP.getInstance().getLogger().log(Level.SEVERE, Errors.sqlConnectionExecute(), ex);
|
||||||
@ -93,9 +92,9 @@ public class DatabaseCooldowns extends SQLite {
|
|||||||
+ ") VALUES(?, ?, ?)";
|
+ ") VALUES(?, ?, ?)";
|
||||||
for (CooldownData data : cooldownData) {
|
for (CooldownData data : cooldownData) {
|
||||||
List<Object> param = new ArrayList<>() {{
|
List<Object> param = new ArrayList<>() {{
|
||||||
add(data.uuid.toString());
|
add(data.getUuid().toString());
|
||||||
add(data.time);
|
add(data.getTime());
|
||||||
add(data.uses);
|
add(data.getUses());
|
||||||
}};
|
}};
|
||||||
sqlUpdate(sql, param);
|
sqlUpdate(sql, param);
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ public class RTPInventories {
|
|||||||
for (Player p : Bukkit.getOnlinePlayers())
|
for (Player p : Bukkit.getOnlinePlayers())
|
||||||
if (main.getpInfo().playerExists(p)) {
|
if (main.getpInfo().playerExists(p)) {
|
||||||
//main.getText().getReloadMenu(p);
|
//main.getText().getReloadMenu(p);
|
||||||
main.getpInfo().clear(p);
|
main.getpInfo().clearInvs(p);
|
||||||
p.closeInventory();
|
p.closeInventory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ import java.util.ArrayList;
|
|||||||
public class RTPInvCoordinates extends RTPInventory {
|
public class RTPInvCoordinates extends RTPInventory {
|
||||||
|
|
||||||
public void show(Player p) {
|
public void show(Player p) {
|
||||||
if (BetterRTP.getInstance().getpInfo().getInvWorld(p) == null) {
|
if (BetterRTP.getInstance().getpInfo().getInvWorld().get(p) == null) {
|
||||||
BetterRTP.getInstance().getpInfo().setNextInv(p, this.type);
|
BetterRTP.getInstance().getpInfo().setNextInv(p, this.type);
|
||||||
BetterRTP.getInstance().getInvs().getInv(RTP_INV_SETTINGS.WORLDS).show(p);
|
BetterRTP.getInstance().getInvs().getInv(RTP_INV_SETTINGS.WORLDS).show(p);
|
||||||
return;
|
return;
|
||||||
|
@ -53,7 +53,7 @@ public class RTPInvWorlds extends RTPInventory {
|
|||||||
for (World world : Bukkit.getWorlds()) {
|
for (World world : Bukkit.getWorlds()) {
|
||||||
if (_index == slot) {
|
if (_index == slot) {
|
||||||
BetterRTP.getInstance().getpInfo().setInvWorld(p, world);
|
BetterRTP.getInstance().getpInfo().setInvWorld(p, world);
|
||||||
BetterRTP.getInstance().getInvs().getInv(BetterRTP.getInstance().getpInfo().getNextInv(p)).show(p);
|
BetterRTP.getInstance().getInvs().getInv(BetterRTP.getInstance().getpInfo().getInvNextInv().get(p)).show(p);
|
||||||
}
|
}
|
||||||
_index ++;
|
_index ++;
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,12 @@ import me.SuperRonanCraft.BetterRTP.player.PlayerInfo;
|
|||||||
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 me.SuperRonanCraft.BetterRTP.references.rtpinfo.CooldownData;
|
|
||||||
import org.bukkit.Bukkit;
|
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 org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -20,55 +20,60 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class CooldownHandler {
|
public class CooldownHandler {
|
||||||
|
|
||||||
//private final HashMap<UUID, Long> cooldowns = new HashMap<>(); //Cooldown timer for each player
|
@Getter boolean enabled, loaded;
|
||||||
//private HashMap<UUID, Integer> uses = null; //Players locked from rtp'ing ever again
|
|
||||||
@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
|
||||||
|
private final List<Player> downloading = new ArrayList<>();
|
||||||
|
|
||||||
public void load() {
|
public void load() {
|
||||||
//configfile = new File(BetterRTP.getInstance().getDataFolder(), "data/cooldowns.yml");
|
//configfile = new File(BetterRTP.getInstance().getDataFolder(), "data/cooldowns.yml");
|
||||||
getPInfo().getCooldown().clear();
|
getPInfo().getCooldown().clear();
|
||||||
FileBasics.FILETYPE config = FileBasics.FILETYPE.CONFIG;
|
FileBasics.FILETYPE config = FileBasics.FILETYPE.CONFIG;
|
||||||
enabled = config.getBoolean("Settings.Cooldown.Enabled");
|
enabled = config.getBoolean("Settings.Cooldown.Enabled");
|
||||||
|
downloading.clear();
|
||||||
|
loaded = false;
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
timer = config.getInt("Settings.Cooldown.Time");
|
timer = config.getInt("Settings.Cooldown.Time");
|
||||||
lockedAfter = config.getInt("Settings.Cooldown.LockAfter");
|
lockedAfter = config.getInt("Settings.Cooldown.LockAfter");
|
||||||
//if (lockedAfter > 0)
|
|
||||||
// uses = new HashMap<>();
|
|
||||||
}
|
}
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
|
||||||
getDatabase().load();
|
getDatabase().load();
|
||||||
OldCooldownConverter.loadOldCooldowns();
|
OldCooldownConverter.loadOldCooldowns();
|
||||||
//Load any online players cooldowns (mostly after a reload)
|
//Load any online players cooldowns (mostly after a reload)
|
||||||
for (Player p : Bukkit.getOnlinePlayers())
|
for (Player p : Bukkit.getOnlinePlayers())
|
||||||
loadPlayer(p.getUniqueId());
|
loadPlayer(p);
|
||||||
|
loaded = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Player player) {
|
public void add(Player player) {
|
||||||
if (!enabled) return;
|
if (!enabled) return;
|
||||||
CooldownData data = getPInfo().getCooldown().getOrDefault(player,
|
CooldownData data = getPInfo().getCooldown().getOrDefault(player,
|
||||||
new CooldownData(player.getUniqueId(), System.currentTimeMillis(), 0));
|
new CooldownData(player.getUniqueId(), 0L, 0));
|
||||||
if (lockedAfter > 0)
|
if (lockedAfter > 0)
|
||||||
data.setUses(data.getUses() + 1);
|
data.setUses(data.getUses() + 1);
|
||||||
savePlayer(data);
|
data.setTime(System.currentTimeMillis());
|
||||||
|
getPInfo().getCooldown().put(player, data);
|
||||||
|
savePlayer(data, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean exists(UUID id) {
|
public boolean exists(Player p) {
|
||||||
return cooldowns.containsKey(id);
|
return getPInfo().getCooldown().containsKey(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long timeLeft(UUID id) {
|
@Nullable
|
||||||
long cooldown = cooldowns.getOrDefault(id, 0L);
|
public CooldownData getPlayer(Player p) {
|
||||||
|
return getPInfo().getCooldown().getOrDefault(p, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long timeLeft(CooldownData data) {
|
||||||
|
long cooldown = data.getTime();
|
||||||
return ((cooldown / 1000) + timer) - (System.currentTimeMillis() / 1000);
|
return ((cooldown / 1000) + timer) - (System.currentTimeMillis() / 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean locked(UUID id) {
|
public boolean locked(CooldownData data) {
|
||||||
if (uses != null && uses.containsKey(id))
|
return lockedAfter > 0 && data.uses >= lockedAfter;
|
||||||
return uses.get(id) >= lockedAfter;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeCooldown(Player player) {
|
public void removeCooldown(Player player) {
|
||||||
@ -90,82 +95,30 @@ public class CooldownHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void savePlayer(CooldownData data, boolean remove) {
|
private void savePlayer(CooldownData data, boolean remove) {
|
||||||
if (!remove) {
|
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
|
||||||
getDatabase().setCooldown(data);
|
if (!remove) {
|
||||||
} else {
|
getDatabase().setCooldown(data);
|
||||||
getDatabase().removePlayer(data.getUuid());
|
} else {
|
||||||
}
|
getDatabase().removePlayer(data.getUuid());
|
||||||
/*YamlConfiguration config = getFile();
|
}
|
||||||
if (config == null) {
|
});
|
||||||
BetterRTP.getInstance().getLogger().severe("Unabled to save cooldown for the players UUID " + id
|
|
||||||
+ ". Cooldown file might have been compromised!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (adding) { //Add player to file
|
|
||||||
config.set(id.toString() + ".Time", time);
|
|
||||||
if (attempts > 0)
|
|
||||||
config.set(id.toString() + ".Attempts", attempts);
|
|
||||||
} else { //Remove player from the file
|
|
||||||
config.set(id.toString(), null);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
config.save(configfile);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*private File configfile;
|
public void loadPlayer(Player player) {
|
||||||
|
downloading.add(player);
|
||||||
/*private YamlConfiguration getFile() {
|
|
||||||
if (!configfile.exists()) {
|
|
||||||
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 void loadPlayer(UUID uuid) {
|
|
||||||
if (isEnabled()) {
|
if (isEnabled()) {
|
||||||
List<Object> data = getDatabase().getCooldown(uuid);
|
CooldownData data = getDatabase().getCooldown(player.getUniqueId());
|
||||||
if (data != null) {
|
if (data != null)
|
||||||
cooldowns.put(uuid, (Long) data.get(0));
|
getPInfo().getCooldown().put(player, data);
|
||||||
uses.put(uuid, (int) data.get(1));
|
|
||||||
}
|
|
||||||
/*String id = uuid.toString();
|
|
||||||
YamlConfiguration config = getFile();
|
|
||||||
if (config != null && config.isConfigurationSection(id))
|
|
||||||
try {
|
|
||||||
Long time = config.getLong(id + ".Time");
|
|
||||||
cooldowns.put(uuid, time);
|
|
||||||
if (lockedAfter > 0) {
|
|
||||||
int attempts = config.getInt(id + ".Attempts");
|
|
||||||
uses.put(uuid, attempts);
|
|
||||||
}
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
BetterRTP.getInstance().getLogger().info("UUID of `" + id + "` is invalid, please delete this!");
|
|
||||||
//Bad uuid
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
downloading.remove(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unloadPlayer(UUID uuid) {
|
public boolean loadedPlayer(Player player) {
|
||||||
cooldowns.remove(uuid);
|
return !downloading.contains(player);
|
||||||
if (uses != null)
|
|
||||||
uses.remove(uuid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
static class OldCooldownConverter {
|
static class OldCooldownConverter {
|
||||||
|
|
||||||
static void loadOldCooldowns() {
|
static void loadOldCooldowns() {
|
||||||
@ -192,7 +145,7 @@ public class CooldownHandler {
|
|||||||
}
|
}
|
||||||
BetterRTP.getInstance().getLogger().info("Cooldowns converting to new database...");
|
BetterRTP.getInstance().getLogger().info("Cooldowns converting to new database...");
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(BetterRTP.getInstance(), () -> {
|
||||||
BetterRTP.getInstance().getDatabase().setCooldown(cooldownData);
|
BetterRTP.getInstance().getDatabaseCooldowns().setCooldown(cooldownData);
|
||||||
BetterRTP.getInstance().getLogger().info("Cooldowns have been converted to the new database!");
|
BetterRTP.getInstance().getLogger().info("Cooldowns have been converted to the new database!");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -219,7 +172,7 @@ public class CooldownHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private DatabaseCooldowns getDatabase() {
|
private DatabaseCooldowns getDatabase() {
|
||||||
return BetterRTP.getInstance().getDatabase();
|
return BetterRTP.getInstance().getDatabaseCooldowns();
|
||||||
}
|
}
|
||||||
|
|
||||||
private PlayerInfo getPInfo() {
|
private PlayerInfo getPInfo() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user