forked from Upstream/CommandPanels
3.19.1.1
This commit is contained in:
parent
81f1f611dd
commit
ac721b0770
@ -1,4 +1,4 @@
|
||||
version: 3.19.1.0
|
||||
version: 3.19.1.1
|
||||
main: me.rockyhawk.commandpanels.CommandPanels
|
||||
name: CommandPanels
|
||||
author: RockyHawk
|
||||
|
@ -31,8 +31,7 @@ public class GetCustomHeads {
|
||||
this.plugin = pl;
|
||||
}
|
||||
|
||||
//contains cached player name and then base64 value (clears on /cpr reload)
|
||||
//also will clear if the map reaches a length of 1000 which is roughly 135 KB RAM usage
|
||||
//will not go above 2000 elements in the list which is roughly 270 KB RAM usage
|
||||
public HashMap<String, String> playerHeadTextures = new HashMap<>();
|
||||
|
||||
public String getHeadBase64(ItemStack head) {
|
||||
|
@ -8,8 +8,11 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -51,8 +54,8 @@ public class Commandpanelsreload implements CommandExecutor {
|
||||
registerCommands();
|
||||
}
|
||||
|
||||
//clear cached head textures
|
||||
plugin.customHeads.playerHeadTextures.clear();
|
||||
//pre-cache any player head textures from panels
|
||||
reloadCachedHeads(sender);
|
||||
|
||||
sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.reload")));
|
||||
}else{
|
||||
@ -110,4 +113,48 @@ public class Commandpanelsreload implements CommandExecutor {
|
||||
Bukkit.getConsoleSender().sendMessage("[CommandPanels]" + ChatColor.RED + " WARNING: Could not register custom commands!");
|
||||
}
|
||||
}
|
||||
|
||||
//reload player heads
|
||||
public void reloadCachedHeads(CommandSender sender){
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
for (Panel temp : plugin.panelList) {
|
||||
ConfigurationSection yaml = temp.getConfig();
|
||||
//look through yaml for player heads
|
||||
if(sender instanceof Player) {
|
||||
Player player = ((Player) sender).getPlayer();
|
||||
checkKeysRecursive(temp, player, yaml);
|
||||
}else{
|
||||
checkKeysRecursive(temp, null, yaml);
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(this.plugin);
|
||||
}
|
||||
|
||||
//this will recursively check through all the keys in a panel for cps= values and find ones with Player names
|
||||
private void checkKeysRecursive(Panel panel, Player player, ConfigurationSection section) {
|
||||
for (String key : section.getKeys(false)) {
|
||||
if (key.equals("material")) {
|
||||
String value = section.getString(key);
|
||||
//if value is a custom head
|
||||
if (value.startsWith("cps=")) {
|
||||
String[] words = value.split("\\s");
|
||||
//if value is the length of a players name
|
||||
if (!words[1].equalsIgnoreCase("self") && words[1].length() <= 16) {
|
||||
try {
|
||||
String tempName = plugin.tex.placeholdersNoColour(panel, PanelPosition.Top, player, words[1]);
|
||||
plugin.customHeads.getPlayerHead(tempName); //get the head cached
|
||||
}catch (Exception ignore){} //ignore heads that cannot be cached without the panel being open
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (section.isConfigurationSection(key)) {
|
||||
// Recursive call to check nested sections
|
||||
checkKeysRecursive(panel, player, section.getConfigurationSection(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -14,7 +14,10 @@ import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
|
||||
public class UtilsPanelsLoader implements Listener {
|
||||
CommandPanels plugin;
|
||||
@ -75,9 +78,10 @@ public class UtilsPanelsLoader implements Listener {
|
||||
//close panels and run commands for Top panel
|
||||
plugin.openPanels.closePanelForLoader(e.getPlayer().getName(),PanelPosition.Top);
|
||||
|
||||
//clear cached textures list on length limit
|
||||
if(plugin.customHeads.playerHeadTextures.size() > 1000) {
|
||||
plugin.customHeads.playerHeadTextures.clear();
|
||||
//clear cached textures list until length limit is reached
|
||||
while (plugin.customHeads.playerHeadTextures.size() > 2000) {
|
||||
List<String> keys = new ArrayList<>(plugin.customHeads.playerHeadTextures.keySet());
|
||||
plugin.customHeads.playerHeadTextures.remove(keys.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user