diff --git a/.idea/artifacts/Informator_jar.xml b/.idea/artifacts/Informator_jar.xml index 0eb4301..8faa225 100644 --- a/.idea/artifacts/Informator_jar.xml +++ b/.idea/artifacts/Informator_jar.xml @@ -1,6 +1,6 @@ - $USER_HOME$/Plocha/betaserver/plugins/ + $USER_HOME$/Plocha/beta server/plugins diff --git a/.idea/misc.xml b/.idea/misc.xml index 28403f3..2454f64 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -12,8 +12,9 @@ + - + \ No newline at end of file diff --git a/src/main/java/xyz/soukup/informator/Informator.java b/src/main/java/xyz/soukup/informator/Informator.java index 0f62e78..6987593 100644 --- a/src/main/java/xyz/soukup/informator/Informator.java +++ b/src/main/java/xyz/soukup/informator/Informator.java @@ -4,6 +4,7 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; import xyz.soukup.informator.handlers.AnimationHandler; import xyz.soukup.informator.handlers.ConfigHandler; +import xyz.soukup.informator.handlers.TabHandler; import xyz.soukup.informator.handlers.clockHandler; import java.io.IOException; @@ -46,13 +47,17 @@ public final class Informator extends JavaPlugin { throw new RuntimeException(e); } AnimationHandler.loadAnimations(); - clockHandler.centralClock + if (ConfigHandler.config.getBoolean("modules-enabled.tab")){ + TabHandler.loadTabs(); + } + clockHandler clockHandler = new clockHandler(); logger.info(""); logger.info("\u001B[33m==========================================================="); logger.info(""); logger.info("\u001B[34m Informator loaded!"); logger.info(""); logger.info("\u001B[33m==========================================================="); + TabHandler.loadTabs(); } public static Informator getPlugin(){ return instance; diff --git a/src/main/java/xyz/soukup/informator/handlers/AnimationHandler.java b/src/main/java/xyz/soukup/informator/handlers/AnimationHandler.java index bc490eb..79ab64c 100644 --- a/src/main/java/xyz/soukup/informator/handlers/AnimationHandler.java +++ b/src/main/java/xyz/soukup/informator/handlers/AnimationHandler.java @@ -19,7 +19,6 @@ public class AnimationHandler { private static final HashMap tpsCounter = new HashMap(); private static final HashMap animationSpeed = new HashMap(); private static final HashMap currentFrame = new HashMap(); - private static Integer cycles = 0; public static void loadAnimations(){ animations.addAll(aconfig.getKeys(false)); @@ -47,15 +46,14 @@ public class AnimationHandler { } - cycles++; } public static String getCurrentFrame(String name){ if (animations.contains(name)) - return animationFrames.get(name).get(currentFrame.get(name))+ " " + currentFrame.get(name); + return animationFrames.get(name).get(currentFrame.get(name)); else - return null; + return "&cinvalid animation"; } } diff --git a/src/main/java/xyz/soukup/informator/handlers/ConfigHandler.java b/src/main/java/xyz/soukup/informator/handlers/ConfigHandler.java index 1db3d1d..0449276 100644 --- a/src/main/java/xyz/soukup/informator/handlers/ConfigHandler.java +++ b/src/main/java/xyz/soukup/informator/handlers/ConfigHandler.java @@ -16,6 +16,9 @@ public class ConfigHandler { static Informator plugin = Informator.getPlugin(); static Logger logger = plugin.getLogger(); public static YamlConfiguration animationConfig = new YamlConfiguration(); + public static YamlConfiguration config = new YamlConfiguration(); + + public static YamlConfiguration tabConfig = new YamlConfiguration(); public static void loadConfigs() throws IOException, InvalidConfigurationException { List configsToLoad = new ArrayList<>(); configsToLoad.add("config.yml"); @@ -29,6 +32,10 @@ public class ConfigHandler { } animationConfig.load(new File(plugin.getDataFolder(), "animations.yml")); + tabConfig.load(new File(plugin.getDataFolder(), "modules/tab.yml")); + config.load(new File(plugin.getDataFolder(), "config.yml")); + + } diff --git a/src/main/java/xyz/soukup/informator/handlers/PlaceholderHandler.java b/src/main/java/xyz/soukup/informator/handlers/PlaceholderHandler.java new file mode 100644 index 0000000..3e958fa --- /dev/null +++ b/src/main/java/xyz/soukup/informator/handlers/PlaceholderHandler.java @@ -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); + } +} diff --git a/src/main/java/xyz/soukup/informator/handlers/TabHandler.java b/src/main/java/xyz/soukup/informator/handlers/TabHandler.java new file mode 100644 index 0000000..d794c7d --- /dev/null +++ b/src/main/java/xyz/soukup/informator/handlers/TabHandler.java @@ -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> tabData = new HashMap<>(); + public static HashMap playerTab = new HashMap<>(); + private static final YamlConfiguration tabConfig = ConfigHandler.tabConfig; + + public static void loadTabs(){ + List 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 keys = targetSection.getKeys(false); + for (String key : keys) { + List tabDataList = new ArrayList<>(); + tabDataList.add(tabConfig.getInt(targetKey + "." + key + ".priority")); + List header = tabConfig.getStringList(targetKey + "." + key + ".header"); + List 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)); + + + } + } + +} diff --git a/src/main/java/xyz/soukup/informator/handlers/clockHandler.java b/src/main/java/xyz/soukup/informator/handlers/clockHandler.java index 423fe64..edf4478 100644 --- a/src/main/java/xyz/soukup/informator/handlers/clockHandler.java +++ b/src/main/java/xyz/soukup/informator/handlers/clockHandler.java @@ -11,16 +11,16 @@ import java.util.Objects; public class clockHandler { public static Informator plugin = Informator.getPlugin(); - static int cycles = 0; public static BukkitTask centralClock = new BukkitRunnable() { @Override public void run() { - cycles++; AnimationHandler.refreshAnimations(); - for (Player player: Bukkit.getOnlinePlayers()) { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(AnimationHandler.getCurrentFrame("exampleTitle")))); + + if (ConfigHandler.config.getBoolean("modules-enabled.tab")){ + TabHandler.refreshTabs(); } + } }.runTaskTimer(plugin, 0, 1L); diff --git a/src/main/java/xyz/soukup/informator/handlers/tabHandler.java b/src/main/java/xyz/soukup/informator/handlers/tabHandler.java deleted file mode 100644 index 415cf4b..0000000 --- a/src/main/java/xyz/soukup/informator/handlers/tabHandler.java +++ /dev/null @@ -1,5 +0,0 @@ -package xyz.soukup.informator.handlers; - -public class tabHandler { - -} diff --git a/src/main/resources/animations.yml b/src/main/resources/animations.yml index a3f54a3..ff6d034 100644 --- a/src/main/resources/animations.yml +++ b/src/main/resources/animations.yml @@ -6,7 +6,7 @@ exampleTitle: #Speed is in minecraft ticks #20 ticks = 1 second so speed 20 = 1 frame per second - speed: 2 + speed: 4 #Also hate making animations manually? #You can use animation creation tool (ACT) built in web configurator! # https://informator.soukup.xyz/configurator/act @@ -21,5 +21,5 @@ exampleTitle: - "&b&fINFORMA&b&3T&b&fOR" - "&b&fINFORMAT&b&3O&b&fR" - "&b&fINFORMATO&b&3R" - - "&cKONEC" + diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index ccadb33..204c4f6 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -9,6 +9,7 @@ modules-enabled: bossbar: true #Configuration for plugin's web interface + web-interface: #online configurator enabled. We recommend to disable it after setting up the plugin enabled: true diff --git a/src/main/resources/modules/tab.yml b/src/main/resources/modules/tab.yml index a99dda0..df8e228 100644 --- a/src/main/resources/modules/tab.yml +++ b/src/main/resources/modules/tab.yml @@ -5,23 +5,24 @@ #/___/_/ /_/_/ \____/_/ /_/ /_/ /_/\__,_/\__/\____/_/ # -settings: +enabled: true tabs: - default: - priority: 0 - header: - - "" - - "{animation.exampleTitle}" - - "" - - "{animation.exampleLine}" - - "" - footer: - - "" - - "{animation.exampleLine}" - - "" - - "Change this in modules/tab.yml" - - "" + required: + default: + priority: 0 + header: + - "" + - "%%animation:exampleTitle%%" + - "" + - "%%animation:exampleLine%%" + - "" + footer: + - "" + - "%%animation:exampleLine%%" + - "" + - "Change this in modules/tab.yml" + - "" world: enabled: false priority: 1 @@ -30,34 +31,50 @@ tabs: enabled: true header: - "World specified tab" - - "{animation.exampleTitle}" + - "%%animation:exampleTitle%%" - "" - - "{animation.exampleLine}" + - "%%animation:exampleLine%%" - "" footer: - "" - - "{animation.exampleLine}" + - "%%animation:exampleLine%%" - "" - "Change this in modules/tab.yml" - "" #tab that will show only to players with certain group group: - - player: enabled: false priority: 3 - players: - examplePlayer: + groups: + exampleGroup: enabled: true header: - "World specified tab" - - "{animation.exampleTitle}" + - "%%animation:exampleTitle%%" + - "" + - "%%animation:exampleLine%%" + - "" + footer: + - "" + - "%%animation:exampleLine%%" + - "" + - "Change this in modules/tab.yml" + - "" + player: + enabled: false + players: + Kuba1428: + priority: 3 + enabled: true + header: + - "Player specified tab" + - "%%animation:exampleTitle%%" - "" - - "{animation.exampleLine}" + - "%%animation:exampleLine%%" - "" footer: - "" - - "{animation.exampleLine}" + - "%%animation:exampleLine%%" - "" - "Change this in modules/tab.yml" - "" diff --git a/target/classes/modules/tab.yml b/target/classes/modules/tab.yml index 80a9543..df8e228 100644 --- a/target/classes/modules/tab.yml +++ b/target/classes/modules/tab.yml @@ -5,15 +5,24 @@ #/___/_/ /_/_/ \____/_/ /_/ /_/ /_/\__,_/\__/\____/_/ # -settings: +enabled: true tabs: - default: - priority: 0 - header: - - "INFORMATOR" - footer: + required: + default: + priority: 0 + header: + - "" + - "%%animation:exampleTitle%%" + - "" + - "%%animation:exampleLine%%" + - "" + footer: + - "" + - "%%animation:exampleLine%%" + - "" - "Change this in modules/tab.yml" + - "" world: enabled: false priority: 1 @@ -21,27 +30,53 @@ tabs: exampleWorld: enabled: true header: - - "INFORMATOR" + - "World specified tab" + - "%%animation:exampleTitle%%" + - "" + - "%%animation:exampleLine%%" - "" - - "This tab will show up to players" - - "in world exampleWorld" footer: + - "" + - "%%animation:exampleLine%%" + - "" - "Change this in modules/tab.yml" + - "" #tab that will show only to players with certain group group: - - player: enabled: false priority: 3 + groups: + exampleGroup: + enabled: true + header: + - "World specified tab" + - "%%animation:exampleTitle%%" + - "" + - "%%animation:exampleLine%%" + - "" + footer: + - "" + - "%%animation:exampleLine%%" + - "" + - "Change this in modules/tab.yml" + - "" + player: + enabled: false players: - examplePlayer: + Kuba1428: + priority: 3 enabled: true header: - - "INFORMATOR" + - "Player specified tab" + - "%%animation:exampleTitle%%" + - "" + - "%%animation:exampleLine%%" - "" - - "This tab will show up to user" - - "with nickname examplePlayer" footer: + - "" + - "%%animation:exampleLine%%" + - "" - "Change this in modules/tab.yml" + - "" diff --git a/target/classes/xyz/soukup/informator/Informator.class b/target/classes/xyz/soukup/informator/Informator.class index cee02b9..89d6e20 100644 Binary files a/target/classes/xyz/soukup/informator/Informator.class and b/target/classes/xyz/soukup/informator/Informator.class differ diff --git a/target/classes/xyz/soukup/informator/handlers/AnimationHandler.class b/target/classes/xyz/soukup/informator/handlers/AnimationHandler.class index 48f9e33..1c18fdf 100644 Binary files a/target/classes/xyz/soukup/informator/handlers/AnimationHandler.class and b/target/classes/xyz/soukup/informator/handlers/AnimationHandler.class differ diff --git a/target/classes/xyz/soukup/informator/handlers/ConfigHandler.class b/target/classes/xyz/soukup/informator/handlers/ConfigHandler.class index 01a404e..2bbdd42 100644 Binary files a/target/classes/xyz/soukup/informator/handlers/ConfigHandler.class and b/target/classes/xyz/soukup/informator/handlers/ConfigHandler.class differ diff --git a/target/classes/xyz/soukup/informator/handlers/PlaceholderHandler.class b/target/classes/xyz/soukup/informator/handlers/PlaceholderHandler.class new file mode 100644 index 0000000..b8e941a Binary files /dev/null and b/target/classes/xyz/soukup/informator/handlers/PlaceholderHandler.class differ diff --git a/target/classes/xyz/soukup/informator/handlers/TabHandler.class b/target/classes/xyz/soukup/informator/handlers/TabHandler.class new file mode 100644 index 0000000..2d1a3b7 Binary files /dev/null and b/target/classes/xyz/soukup/informator/handlers/TabHandler.class differ diff --git a/target/classes/xyz/soukup/informator/handlers/clockHandler$1.class b/target/classes/xyz/soukup/informator/handlers/clockHandler$1.class index 0b85198..5bcde2d 100644 Binary files a/target/classes/xyz/soukup/informator/handlers/clockHandler$1.class and b/target/classes/xyz/soukup/informator/handlers/clockHandler$1.class differ diff --git a/target/classes/xyz/soukup/informator/handlers/clockHandler.class b/target/classes/xyz/soukup/informator/handlers/clockHandler.class index e36e5d9..c90babe 100644 Binary files a/target/classes/xyz/soukup/informator/handlers/clockHandler.class and b/target/classes/xyz/soukup/informator/handlers/clockHandler.class differ