master
parent
d31738b773
commit
141d5ef24a
20 changed files with 241 additions and 58 deletions
@ -0,0 +1,46 @@ |
|||||||
|
package xyz.soukup.informator.handlers; |
||||||
|
|
||||||
|
import org.bukkit.ChatColor; |
||||||
|
import org.bukkit.entity.Player; |
||||||
|
|
||||||
|
import java.util.regex.Matcher; |
||||||
|
import java.util.regex.Pattern; |
||||||
|
|
||||||
|
public class PlaceholderHandler { |
||||||
|
public static String substituteAll(String text, Player player){ |
||||||
|
String result = substitudeAnimation(text); |
||||||
|
result = substitudeColor(result); |
||||||
|
return result; |
||||||
|
} |
||||||
|
public static String substitudeAnimation(String text){ |
||||||
|
// Define the regular expression pattern for placeholders
|
||||||
|
Pattern pattern = Pattern.compile("%%animation:(.*?)%%"); |
||||||
|
|
||||||
|
// Create a matcher with the input string
|
||||||
|
Matcher matcher = pattern.matcher(text); |
||||||
|
|
||||||
|
// StringBuffer to hold the result
|
||||||
|
StringBuffer result = new StringBuffer(); |
||||||
|
|
||||||
|
// Find and replace placeholders
|
||||||
|
while (matcher.find()) { |
||||||
|
// Get the animation name
|
||||||
|
String animationName = matcher.group(1); |
||||||
|
|
||||||
|
// Look up the corresponding value from the map
|
||||||
|
String replacement = AnimationHandler.getCurrentFrame(animationName); |
||||||
|
|
||||||
|
// Append the replacement to the result
|
||||||
|
matcher.appendReplacement(result, replacement); |
||||||
|
} |
||||||
|
|
||||||
|
// Append the remainder of the input string after the last match
|
||||||
|
matcher.appendTail(result); |
||||||
|
|
||||||
|
// Convert the result to a String
|
||||||
|
return result.toString(); |
||||||
|
} |
||||||
|
public static String substitudeColor(String text){ |
||||||
|
return ChatColor.translateAlternateColorCodes('&', text); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,78 @@ |
|||||||
|
package xyz.soukup.informator.handlers; |
||||||
|
|
||||||
|
import org.bukkit.Bukkit; |
||||||
|
import org.bukkit.configuration.ConfigurationSection; |
||||||
|
import org.bukkit.configuration.file.YamlConfiguration; |
||||||
|
import org.bukkit.entity.Player; |
||||||
|
|
||||||
|
import java.util.*; |
||||||
|
import java.util.stream.Collectors; |
||||||
|
|
||||||
|
public class TabHandler { |
||||||
|
private static HashMap<String, List<Object>> tabData = new HashMap<>(); |
||||||
|
public static HashMap<Player, String> playerTab = new HashMap<>(); |
||||||
|
private static final YamlConfiguration tabConfig = ConfigHandler.tabConfig; |
||||||
|
|
||||||
|
public static void loadTabs(){ |
||||||
|
List<String> tabSources = new ArrayList<>(); |
||||||
|
tabSources.add("tabs.required"); |
||||||
|
tabSources.add("tabs.world.worlds"); |
||||||
|
tabSources.add("tabs.group.groups"); |
||||||
|
tabSources.add("tabs.player.players"); |
||||||
|
for(String targetKey: tabSources){ |
||||||
|
ConfigurationSection targetSection = tabConfig.getConfigurationSection(targetKey); |
||||||
|
|
||||||
|
if (targetSection != null) { |
||||||
|
Set<String> keys = targetSection.getKeys(false); |
||||||
|
for (String key : keys) { |
||||||
|
List<Object> tabDataList = new ArrayList<>(); |
||||||
|
tabDataList.add(tabConfig.getInt(targetKey + "." + key + ".priority")); |
||||||
|
List<String> header = tabConfig.getStringList(targetKey + "." + key + ".header"); |
||||||
|
List<String> footer = tabConfig.getStringList(targetKey + "." + key + ".footer"); |
||||||
|
String headerString = String.join("\n&r", header); |
||||||
|
String footerString = String.join("\n&r", footer); |
||||||
|
tabDataList.add(headerString); |
||||||
|
tabDataList.add(footerString); |
||||||
|
tabData.put(targetKey + "." + key, tabDataList); |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
public static void chooseTab(Player player){ |
||||||
|
String choosenTab = "tabs.required.default"; |
||||||
|
int choosenPriority = tabConfig.getInt("tabs.required.default.priority"); |
||||||
|
if (tabData.containsKey("tabs.player.players." + player.getDisplayName())){ |
||||||
|
player.sendMessage("ss"+choosenPriority); |
||||||
|
|
||||||
|
if ((int)tabData.get("tabs.player.players." + player.getDisplayName()).get(0) > choosenPriority){ |
||||||
|
player.sendMessage("SSSSSSSS"); |
||||||
|
choosenTab = "tabs.player.players." + player.getDisplayName(); |
||||||
|
choosenPriority = (int)tabData.get("tabs.player.players." + player.getDisplayName()).get(0); |
||||||
|
} |
||||||
|
} |
||||||
|
if (tabData.containsKey("tabs.world.worlds." + player.getWorld().getName())){ |
||||||
|
if ((int)tabData.get("tabs.world.worlds." + player.getWorld().getName()).get(0) > choosenPriority){ |
||||||
|
choosenTab = "tab.world.worlds." + player.getWorld().getName(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
playerTab.put(player, choosenTab); |
||||||
|
|
||||||
|
} |
||||||
|
public static void refreshTabs(){ |
||||||
|
for (Player player : Bukkit.getOnlinePlayers()){ |
||||||
|
if (!playerTab.containsKey(player)){ |
||||||
|
chooseTab(player); |
||||||
|
} |
||||||
|
player.setPlayerListHeader(PlaceholderHandler.substituteAll((String) tabData.get(playerTab.get(player)).get(1), player)); |
||||||
|
player.setPlayerListFooter(PlaceholderHandler.substituteAll((String) tabData.get(playerTab.get(player)).get(2), player)); |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -1,5 +0,0 @@ |
|||||||
package xyz.soukup.informator.handlers; |
|
||||||
|
|
||||||
public class tabHandler { |
|
||||||
|
|
||||||
} |
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue