Skip to content

Commit

Permalink
feat: Use native method player.sendLinks() (#7)
Browse files Browse the repository at this point in the history
player no longer need to relog after custom server links config reload
  • Loading branch information
CptbeffHeart authored Aug 25, 2024
1 parent 6132f2d commit d59ec81
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.expectale.customserverlinks.command.ServerLinksReloadCommand;
import com.expectale.customserverlinks.serverlinks.ServerLinkManager;
import org.bukkit.ServerLinks;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

import java.util.logging.Logger;

Expand All @@ -27,4 +29,8 @@ public void onEnable() {
public void onDisable() {
LOGGER.info("Disabling CustomServerLinks");
}

public @NotNull ServerLinks getLinks() {
return this.getServer().getServerLinks();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.expectale.customserverlinks.command;

import com.expectale.customserverlinks.CustomServerLinks;
import com.expectale.customserverlinks.serverlinks.ServerLinkManager;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
Expand All @@ -15,7 +14,6 @@ public class ServerLinksReloadCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length == 0 || !args[0].equalsIgnoreCase("reload")) return false;
CustomServerLinks.INSTANCE.reloadConfig();
ServerLinkManager.reloadLinks();
sender.sendMessage("§a[!] CustomServerLinks config have been reloaded");
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.expectale.customserverlinks.serverlinks;

import com.expectale.customserverlinks.CustomServerLinks;
import org.bukkit.Bukkit;
import org.bukkit.ServerLinks;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
Expand All @@ -12,8 +13,9 @@
public class ServerLinkManager {

public static void reloadLinks() {
clearServerLinks();
CustomServerLinks instance = CustomServerLinks.INSTANCE;
clearServerLinks();
instance.reloadConfig();
FileConfiguration config = instance.getConfig();
for (String key : config.getKeys(false)) {

Expand Down Expand Up @@ -50,6 +52,8 @@ public static void reloadLinks() {

}

Bukkit.getOnlinePlayers().forEach(player -> player.sendLinks(instance.getLinks()));

}

public static boolean isValidType(String value) {
Expand Down

0 comments on commit d59ec81

Please sign in to comment.