Skip to content

Commit

Permalink
refactor: Logic modification to use getServerLinks() (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
CptbeffHeart authored Aug 25, 2024
1 parent 8734c91 commit f34e88a
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.expectale.customserverlinks.command.ServerLinksReloadCommand;
import com.expectale.customserverlinks.serverlinks.ServerLinkManager;
import com.expectale.customserverlinks.listener.ServerLinkListener;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.logging.Logger;
Expand All @@ -18,7 +17,6 @@ public void onEnable() {
LOGGER = getLogger();

saveDefaultConfig();
getServer().getPluginManager().registerEvents(new ServerLinkListener(), this);
getCommand("customserverlinks").setExecutor(new ServerLinksReloadCommand());
ServerLinkManager.reloadLinks();

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,34 +1,20 @@
package com.expectale.customserverlinks.serverlinks;

import com.expectale.customserverlinks.CustomServerLinks;
import com.expectale.customserverlinks.serverlinks.link.AbstractServerLink;
import com.expectale.customserverlinks.serverlinks.link.NamedServerLink;
import com.expectale.customserverlinks.serverlinks.link.TypedServerLink;
import org.bukkit.ServerLinks;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ServerLinkManager {

private static final List<AbstractServerLink> LINKS = new ArrayList<>();

public static void addLink(AbstractServerLink link) {
LINKS.add(link);
}

public static List<AbstractServerLink> getLinks() {
return new ArrayList<>(LINKS);
}

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

ConfigurationSection section = config.getConfigurationSection(key);
Expand All @@ -53,10 +39,11 @@ public static void reloadLinks() {
continue;
}

ServerLinks serverLinks = instance.getServer().getServerLinks();
if (type != null && isValidType(type)) {
addLink(new TypedServerLink(ServerLinks.Type.valueOf(type.toUpperCase()), url));
serverLinks.addLink(ServerLinks.Type.valueOf(type.toUpperCase()), url);
} else if (name != null) {
addLink(new NamedServerLink(name.replace("&", "§"), url));
serverLinks.addLink(name.replace("&", "§"), url);
} else {
CustomServerLinks.LOGGER.warning("Could not load link for: " + key);
}
Expand All @@ -70,4 +57,9 @@ public static boolean isValidType(String value) {
.map(Enum::name)
.anyMatch(enumName -> enumName.equalsIgnoreCase(value.toUpperCase()));
}

public static void clearServerLinks() {
ServerLinks serverLinks = CustomServerLinks.INSTANCE.getServer().getServerLinks();
serverLinks.getLinks().forEach(serverLinks::removeLink);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit f34e88a

Please sign in to comment.