mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2025-08-17 17:15:47 +00:00
fixed memory leak - players are loaded as they join/leave
This commit is contained in:
parent
1c61ac9d60
commit
bba7e70e8c
6
pom.xml
6
pom.xml
@ -291,5 +291,11 @@
|
|||||||
<artifactId>particle</artifactId>
|
<artifactId>particle</artifactId>
|
||||||
<version>1.5.1</version>
|
<version>1.5.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>RELEASE</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
@ -12,8 +12,10 @@ import me.SuperRonanCraft.BetterRTP.references.invs.RTPInventories;
|
|||||||
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 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;
|
||||||
@ -95,6 +97,9 @@ 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() {
|
||||||
|
@ -173,7 +173,7 @@ 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 (sendi != player || pl.getPerms().getBypassCooldown(player)) { //Bypassing/Forced?
|
||||||
return true;
|
return true;
|
||||||
} else if (cooldowns.enabled) { //Cooling down?
|
} else if (cooldowns.isEnabled()) { //Cooling down?
|
||||||
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)
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package me.SuperRonanCraft.BetterRTP.player.events;
|
package me.SuperRonanCraft.BetterRTP.player.events;
|
||||||
|
|
||||||
|
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||||
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP_TYPE;
|
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP_TYPE;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.Updater;
|
import me.SuperRonanCraft.BetterRTP.references.Updater;
|
||||||
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
|
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
|
||||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
@ -13,6 +13,7 @@ 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());
|
||||||
rtpOnFirstJoin(p);
|
rtpOnFirstJoin(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,9 +3,14 @@ package me.SuperRonanCraft.BetterRTP.player.events;
|
|||||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
class Leave {
|
class Leave {
|
||||||
|
|
||||||
void event(PlayerQuitEvent e) {
|
void event(PlayerQuitEvent e) {
|
||||||
BetterRTP.getInstance().getCmd().rtping.remove(e.getPlayer().getUniqueId());
|
BetterRTP pl = BetterRTP.getInstance();
|
||||||
|
UUID id = e.getPlayer().getUniqueId();
|
||||||
|
pl.getCmd().rtping.remove(id);
|
||||||
|
pl.getCmd().cooldowns.unloadPlayer(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package me.SuperRonanCraft.BetterRTP.player.rtp;
|
package me.SuperRonanCraft.BetterRTP.player.rtp;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
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.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
@ -14,12 +15,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> locked = null; //Players locked from rtp'ing ever again
|
private HashMap<UUID, Integer> locked = null; //Players locked from rtp'ing ever again
|
||||||
public 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() {
|
||||||
|
configfile = new File(BetterRTP.getInstance().getDataFolder(), "data/cooldowns.yml");
|
||||||
cooldowns.clear();
|
cooldowns.clear();
|
||||||
if (locked != null)
|
if (locked != null)
|
||||||
locked.clear();
|
locked.clear();
|
||||||
@ -30,7 +32,6 @@ public class RTPCooldown {
|
|||||||
lockedAfter = config.getInt("Settings.Cooldown.LockAfter");
|
lockedAfter = config.getInt("Settings.Cooldown.LockAfter");
|
||||||
if (lockedAfter > 0)
|
if (lockedAfter > 0)
|
||||||
locked = new HashMap<>();
|
locked = new HashMap<>();
|
||||||
loadFile();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +63,7 @@ public class RTPCooldown {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(UUID id) {
|
public void removeCooldown(UUID id) {
|
||||||
if (!enabled) return;
|
if (!enabled) return;
|
||||||
if (lockedAfter > 0) {
|
if (lockedAfter > 0) {
|
||||||
locked.put(id, locked.getOrDefault(id, 1) - 1);
|
locked.put(id, locked.getOrDefault(id, 1) - 1);
|
||||||
@ -80,7 +81,11 @@ public class RTPCooldown {
|
|||||||
|
|
||||||
private void savePlayer(UUID id, boolean adding, long time, int attempts) {
|
private void savePlayer(UUID id, boolean adding, long time, int attempts) {
|
||||||
YamlConfiguration config = getFile();
|
YamlConfiguration config = getFile();
|
||||||
if (config == null) return;
|
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
|
if (adding) { //Add player to file
|
||||||
config.set(id.toString() + ".Time", time);
|
config.set(id.toString() + ".Time", time);
|
||||||
if (attempts > 0)
|
if (attempts > 0)
|
||||||
@ -95,50 +100,49 @@ public class RTPCooldown {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private YamlConfiguration config;
|
|
||||||
private File configfile;
|
private File configfile;
|
||||||
|
|
||||||
private YamlConfiguration getFile() {
|
private YamlConfiguration getFile() {
|
||||||
if (config != null) {
|
if (!configfile.exists()) {
|
||||||
return config;
|
|
||||||
} else {
|
|
||||||
if (!configfile.exists()) {
|
|
||||||
try {
|
|
||||||
configfile.getParentFile().mkdir();
|
|
||||||
configfile.createNewFile();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
config = new YamlConfiguration();
|
configfile.getParentFile().mkdir();
|
||||||
config.load(configfile);
|
configfile.createNewFile();
|
||||||
return config;
|
} catch (IOException e) {
|
||||||
} catch (IOException | InvalidConfigurationException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
}
|
||||||
|
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()) {
|
||||||
|
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");
|
||||||
|
locked.put(uuid, attempts);
|
||||||
|
}
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
BetterRTP.getInstance().getLogger().info("UUID of `" + id + "` is invalid, please delete this!");
|
||||||
|
//Bad uuid
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadFile() {
|
public void unloadPlayer(UUID uuid) {
|
||||||
config = null;
|
cooldowns.remove(uuid);
|
||||||
configfile = new File(BetterRTP.getInstance().getDataFolder(), "data/cooldowns.yml");
|
if (locked != null)
|
||||||
YamlConfiguration config = getFile();
|
locked.remove(uuid);
|
||||||
if (config != null)
|
|
||||||
for (String id : config.getKeys(false)) {
|
|
||||||
try {
|
|
||||||
UUID uuid = UUID.fromString(id);
|
|
||||||
Long time = config.getLong(id + ".Time");
|
|
||||||
cooldowns.put(uuid, time);
|
|
||||||
if (lockedAfter > 0) {
|
|
||||||
int attempts = config.getInt(id + ".Attempts");
|
|
||||||
locked.put(uuid, attempts);
|
|
||||||
}
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
BetterRTP.getInstance().getLogger().info("UUID of `" + id + "` is invalid, please delete this!");
|
|
||||||
//Bad uuid
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ class RTPDelay implements Listener {
|
|||||||
|
|
||||||
private void delay(CommandSender sendi, int delay) {
|
private void delay(CommandSender sendi, int delay) {
|
||||||
getPl().getRTP().getTeleport().beforeTeleportDelay(rtp.getPlayer(), delay);
|
getPl().getRTP().getTeleport().beforeTeleportDelay(rtp.getPlayer(), delay);
|
||||||
run = Bukkit.getScheduler().scheduleSyncDelayedTask(BetterRTP.getInstance(), run(sendi, this), delay * 20);
|
run = Bukkit.getScheduler().scheduleSyncDelayedTask(BetterRTP.getInstance(), run(sendi, this), delay * 20L);
|
||||||
if (cancelOnMove || cancelOnDamage)
|
if (cancelOnMove || cancelOnDamage)
|
||||||
Bukkit.getPluginManager().registerEvents(this, BetterRTP.getInstance());
|
Bukkit.getPluginManager().registerEvents(this, BetterRTP.getInstance());
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ class RTPDelay implements Listener {
|
|||||||
HandlerList.unregisterAll(this);
|
HandlerList.unregisterAll(this);
|
||||||
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().getCmd().cooldowns.remove(rtp.getPlayer().getUniqueId());
|
getPl().getCmd().cooldowns.removeCooldown(rtp.getPlayer().getUniqueId());
|
||||||
getPl().getCmd().rtping.put(rtp.getPlayer().getUniqueId(), false);
|
getPl().getCmd().rtping.put(rtp.getPlayer().getUniqueId(), false);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new RTP_CancelledEvent(rtp.getPlayer()));
|
Bukkit.getServer().getPluginManager().callEvent(new RTP_CancelledEvent(rtp.getPlayer()));
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ 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.remove(p.getUniqueId());
|
getPl().getCmd().cooldowns.removeCooldown(p.getUniqueId());
|
||||||
//getPl().getEco().unCharge(p, pWorld);
|
//getPl().getEco().unCharge(p, pWorld);
|
||||||
getPl().getCmd().rtping.put(p.getUniqueId(), false);
|
getPl().getCmd().rtping.put(p.getUniqueId(), false);
|
||||||
}
|
}
|
||||||
|
@ -126,9 +126,9 @@ public class WorldPlayer implements RTPWorld {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Location generateLocation() {
|
public Location generateLocation() {
|
||||||
Location loc = null;
|
Location loc;
|
||||||
switch (shape) {
|
switch (shape) {
|
||||||
case CIRCLE: //DISABLED UNTIL NEXT PATCH
|
case CIRCLE:
|
||||||
loc = generateRound(getMaxRad(), getMinRad()); break;
|
loc = generateRound(getMaxRad(), getMinRad()); break;
|
||||||
default:
|
default:
|
||||||
loc = generateSquare(getMaxRad(), getMinRad()); break;
|
loc = generateSquare(getMaxRad(), getMinRad()); break;
|
||||||
@ -171,8 +171,8 @@ public class WorldPlayer implements RTPWorld {
|
|||||||
double area = Math.PI * (max - min) * (max + min); //of all the area in this donut
|
double area = Math.PI * (max - min) * (max + min); //of all the area in this donut
|
||||||
double subArea = area * new Random().nextDouble(); //pick a random subset of that area
|
double subArea = area * new Random().nextDouble(); //pick a random subset of that area
|
||||||
|
|
||||||
Double r = Math.sqrt(subArea/Math.PI + min*min); //convert area to radius
|
double r = Math.sqrt(subArea/Math.PI + min*min); //convert area to radius
|
||||||
double theta = (r - r.intValue()) * 2 * Math.PI; //use the remainder as an angle
|
double theta = (r - (int) r) * 2 * Math.PI; //use the remainder as an angle
|
||||||
|
|
||||||
// polar to cartesian
|
// polar to cartesian
|
||||||
x = (int) (r * Math.cos(theta));
|
x = (int) (r * Math.cos(theta));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user