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>
|
||||
<version>1.5.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>RELEASE</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -12,8 +12,10 @@ import me.SuperRonanCraft.BetterRTP.references.invs.RTPInventories;
|
||||
import me.SuperRonanCraft.BetterRTP.references.settings.Settings;
|
||||
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.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.List;
|
||||
@ -95,6 +97,9 @@ public class BetterRTP extends JavaPlugin {
|
||||
invs.closeAll();
|
||||
loadAll();
|
||||
text.getReload(sendi);
|
||||
//Reload all players cooldowns
|
||||
for (Player p : Bukkit.getOnlinePlayers())
|
||||
getCmd().cooldowns.loadPlayer(p.getUniqueId());
|
||||
}
|
||||
|
||||
public RTPInventories getInvs() {
|
||||
|
@ -173,7 +173,7 @@ public class Commands {
|
||||
private boolean checkCooldown(CommandSender sendi, Player player) {
|
||||
if (sendi != player || pl.getPerms().getBypassCooldown(player)) { //Bypassing/Forced?
|
||||
return true;
|
||||
} else if (cooldowns.enabled) { //Cooling down?
|
||||
} else if (cooldowns.isEnabled()) { //Cooling down?
|
||||
UUID id = player.getUniqueId();
|
||||
if (cooldowns.exists(id)) {
|
||||
if (cooldowns.locked(id)) { //Infinite cooldown (locked)
|
||||
|
@ -1,9 +1,9 @@
|
||||
package me.SuperRonanCraft.BetterRTP.player.events;
|
||||
|
||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||
import me.SuperRonanCraft.BetterRTP.player.rtp.RTP_TYPE;
|
||||
import me.SuperRonanCraft.BetterRTP.references.Updater;
|
||||
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
|
||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
@ -13,6 +13,7 @@ public class Join {
|
||||
void event(PlayerJoinEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
updater(p);
|
||||
getPl().getCmd().cooldowns.loadPlayer(p.getUniqueId());
|
||||
rtpOnFirstJoin(p);
|
||||
}
|
||||
|
||||
|
@ -3,9 +3,14 @@ package me.SuperRonanCraft.BetterRTP.player.events;
|
||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
class Leave {
|
||||
|
||||
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;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.SuperRonanCraft.BetterRTP.references.file.FileBasics;
|
||||
import me.SuperRonanCraft.BetterRTP.BetterRTP;
|
||||
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 HashMap<UUID, Integer> locked = null; //Players locked from rtp'ing ever again
|
||||
public boolean enabled;
|
||||
@Getter boolean enabled;
|
||||
private int
|
||||
timer, //Cooldown timer
|
||||
lockedAfter; //Rtp's before being locked
|
||||
|
||||
public void load() {
|
||||
configfile = new File(BetterRTP.getInstance().getDataFolder(), "data/cooldowns.yml");
|
||||
cooldowns.clear();
|
||||
if (locked != null)
|
||||
locked.clear();
|
||||
@ -30,7 +32,6 @@ public class RTPCooldown {
|
||||
lockedAfter = config.getInt("Settings.Cooldown.LockAfter");
|
||||
if (lockedAfter > 0)
|
||||
locked = new HashMap<>();
|
||||
loadFile();
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,7 +63,7 @@ public class RTPCooldown {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void remove(UUID id) {
|
||||
public void removeCooldown(UUID id) {
|
||||
if (!enabled) return;
|
||||
if (lockedAfter > 0) {
|
||||
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) {
|
||||
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
|
||||
config.set(id.toString() + ".Time", time);
|
||||
if (attempts > 0)
|
||||
@ -95,13 +100,9 @@ public class RTPCooldown {
|
||||
}
|
||||
}
|
||||
|
||||
private YamlConfiguration config;
|
||||
private File configfile;
|
||||
|
||||
private YamlConfiguration getFile() {
|
||||
if (config != null) {
|
||||
return config;
|
||||
} else {
|
||||
if (!configfile.exists()) {
|
||||
try {
|
||||
configfile.getParentFile().mkdir();
|
||||
@ -111,7 +112,7 @@ public class RTPCooldown {
|
||||
}
|
||||
}
|
||||
try {
|
||||
config = new YamlConfiguration();
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
config.load(configfile);
|
||||
return config;
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
@ -119,16 +120,13 @@ public class RTPCooldown {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void loadFile() {
|
||||
config = null;
|
||||
configfile = new File(BetterRTP.getInstance().getDataFolder(), "data/cooldowns.yml");
|
||||
public void loadPlayer(UUID uuid) {
|
||||
if (isEnabled()) {
|
||||
String id = uuid.toString();
|
||||
YamlConfiguration config = getFile();
|
||||
if (config != null)
|
||||
for (String id : config.getKeys(false)) {
|
||||
if (config != null && config.isConfigurationSection(id))
|
||||
try {
|
||||
UUID uuid = UUID.fromString(id);
|
||||
Long time = config.getLong(id + ".Time");
|
||||
cooldowns.put(uuid, time);
|
||||
if (lockedAfter > 0) {
|
||||
@ -141,4 +139,10 @@ public class RTPCooldown {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void unloadPlayer(UUID uuid) {
|
||||
cooldowns.remove(uuid);
|
||||
if (locked != null)
|
||||
locked.remove(uuid);
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ class RTPDelay implements Listener {
|
||||
|
||||
private void delay(CommandSender sendi, int 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)
|
||||
Bukkit.getPluginManager().registerEvents(this, BetterRTP.getInstance());
|
||||
}
|
||||
@ -60,7 +60,7 @@ class RTPDelay implements Listener {
|
||||
HandlerList.unregisterAll(this);
|
||||
getPl().getRTP().getTeleport().cancelledTeleport(rtp.getPlayer());
|
||||
//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);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new RTP_CancelledEvent(rtp.getPlayer()));
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ public class RTPPlayer {
|
||||
getPl().getText().getFailedNotSafe(sendi, settings.maxAttempts);
|
||||
else
|
||||
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().getCmd().rtping.put(p.getUniqueId(), false);
|
||||
}
|
||||
|
@ -126,9 +126,9 @@ public class WorldPlayer implements RTPWorld {
|
||||
}
|
||||
|
||||
public Location generateLocation() {
|
||||
Location loc = null;
|
||||
Location loc;
|
||||
switch (shape) {
|
||||
case CIRCLE: //DISABLED UNTIL NEXT PATCH
|
||||
case CIRCLE:
|
||||
loc = generateRound(getMaxRad(), getMinRad()); break;
|
||||
default:
|
||||
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 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 theta = (r - r.intValue()) * 2 * Math.PI; //use the remainder as an angle
|
||||
double r = Math.sqrt(subArea/Math.PI + min*min); //convert area to radius
|
||||
double theta = (r - (int) r) * 2 * Math.PI; //use the remainder as an angle
|
||||
|
||||
// polar to cartesian
|
||||
x = (int) (r * Math.cos(theta));
|
||||
|
Loading…
x
Reference in New Issue
Block a user