Skip to content

Commit

Permalink
Added a limit of up to 64 chars on the version string, and added an e…
Browse files Browse the repository at this point in the history
…vent to remove players when quit to prevent ram leaks
  • Loading branch information
brunoxkk0 committed Aug 17, 2023
1 parent 5afdc20 commit efbacf2
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package io.github.cruciblemc.vitatempus.necrotempus;

import de.tr7zw.changeme.nbtapi.NBTContainer;
import io.github.cruciblemc.vitatempus.VitaTempus;
import lombok.SneakyThrows;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.messaging.PluginMessageListener;

Expand All @@ -13,15 +17,17 @@
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

public class NecroTempus implements PluginMessageListener {
public class NecroTempus implements PluginMessageListener, Listener {

private static NecroTempus instance;

public static NecroTempus getInstance(){
return instance != null ? instance : (instance = new NecroTempus());
}

private NecroTempus(){}
private NecroTempus(){
Bukkit.getPluginManager().registerEvents(this, VitaTempus.getInstance());
}

private static final ConcurrentHashMap<UUID, String> versions = new ConcurrentHashMap<>();

Expand All @@ -46,7 +52,7 @@ public void onPluginMessageReceived(String channel, Player player, byte[] messag

if(nbtContainer.hasTag("version")){
String version = nbtContainer.getString("version");
versions.put(player.getUniqueId(), version);
versions.put(player.getUniqueId(), version.substring(0, Math.min(64, version.length() - 1)));
}

}
Expand All @@ -59,4 +65,9 @@ public void onDisable(Plugin plugin, String channel){
Bukkit.getServer().getMessenger().unregisterIncomingPluginChannel(plugin, channel, this);
}

@EventHandler
public void onPlayerQuit(PlayerQuitEvent event){
versions.remove(event.getPlayer().getUniqueId());
}

}

0 comments on commit efbacf2

Please sign in to comment.