Commit 222e6109 authored by Ethan's avatar Ethan 💬
Browse files

i hate options

parent 78b8aff8
package com.ehhthan.mmoactionbar;
import com.ehhthan.mmoactionbar.command.MMOActionBarCommand;
import com.ehhthan.mmoactionbar.manager.ConfigManager;
import com.ehhthan.mmoactionbar.manager.LanguageManager;
import com.ehhthan.mmoactionbar.manager.type.ConfigManager;
import com.ehhthan.mmoactionbar.manager.type.LanguageManager;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
......
package com.ehhthan.mmoactionbar.api.element;
public class ActionBarElement {
private final String id;
public ActionBarElement(String id) {
this.id = id.toLowerCase().replace("_", "-").replace(" ", "-");;
}
public String getId() {
return id;
}
}
package com.ehhthan.mmoactionbar.api.element;
public interface ConfigOption {
boolean hasOption(String option);
String getOption(String option);
void reloadOptions();
}
package com.ehhthan.mmoactionbar.api.reroute;
import com.ehhthan.mmoactionbar.api.element.ActionBarElement;
import com.ehhthan.mmoactionbar.file.ConfigFile;
import net.kyori.adventure.text.Component;
public abstract class RoutedMessage extends ActionBarElement {
public RoutedMessage(String id) {
super(id);
}
public abstract void sendMessage(Component message);
}
package com.ehhthan.mmoactionbar.api.reroute;
import com.ehhthan.mmoactionbar.api.reroute.type.RoutedActionBar;
import com.ehhthan.mmoactionbar.api.reroute.type.RoutedBossBar;
import com.ehhthan.mmoactionbar.api.reroute.type.RoutedChat;
import com.ehhthan.mmoactionbar.api.reroute.type.RoutedSubtitle;
import com.ehhthan.mmoactionbar.api.reroute.type.RoutedTitle;
public class RoutedMessages {
public static final RoutedMessage
ACTION_BAR = new RoutedActionBar(),
BOSS_BAR = new RoutedBossBar(),
CHAT = new RoutedChat(),
SUBTITLE = new RoutedSubtitle(),
TITLE = new RoutedTitle();
}
package com.ehhthan.mmoactionbar.api.reroute.type;
import com.ehhthan.mmoactionbar.api.reroute.RoutedMessage;
import net.kyori.adventure.text.Component;
public class RoutedActionBar extends RoutedMessage {
public RoutedActionBar() {
super("action-bar");
}
@Override
public void sendMessage(Component message) {
}
}
package com.ehhthan.mmoactionbar.api.reroute.type;
import com.ehhthan.mmoactionbar.MMOActionBar;
import com.ehhthan.mmoactionbar.api.element.ConfigOption;
import com.ehhthan.mmoactionbar.api.reroute.RoutedMessage;
import net.kyori.adventure.text.Component;
import org.apache.commons.lang.Validate;
import java.util.HashMap;
import java.util.Map;
public class RoutedBossBar extends RoutedMessage {
public RoutedBossBar() {
super("boss-bar");
}
@Override
public void sendMessage(Component message) {
}
}
package com.ehhthan.mmoactionbar.api.reroute.type;
import com.ehhthan.mmoactionbar.api.reroute.RoutedMessage;
import net.kyori.adventure.text.Component;
public class RoutedChat extends RoutedMessage {
public RoutedChat() {
super("chat");
}
@Override
public void sendMessage(Component message) {
}
}
package com.ehhthan.mmoactionbar.api.reroute.type;
import com.ehhthan.mmoactionbar.api.reroute.RoutedMessage;
import net.kyori.adventure.text.Component;
public class RoutedSubtitle extends RoutedMessage {
public RoutedSubtitle() {
super("subtitle");
}
@Override
public void sendMessage(Component message) {
}
}
package com.ehhthan.mmoactionbar.api.reroute.type;
import com.ehhthan.mmoactionbar.api.reroute.RoutedMessage;
import net.kyori.adventure.text.Component;
public class RoutedTitle extends RoutedMessage {
public RoutedTitle() {
super("title");
}
@Override
public void sendMessage(Component message) {
}
}
......@@ -59,7 +59,7 @@ public class PacketListener {
}
private void rerouteComponent(Component component, PacketEvent event) {
if (component.insertion() == null || !component.insertion().equalsIgnoreCase("MMOBARS")) {
if (component.insertion() == null || !component.insertion().equalsIgnoreCase("MMOACTIONBAR")) {
event.setCancelled(true);
}
}
......
package com.ehhthan.mmoactionbar.manager;
import com.ehhthan.mmoactionbar.MMOActionBar;
import com.ehhthan.mmoactionbar.api.element.ActionBarElement;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
/**
* This is a manager than can be registered through the config
* or have default parameters in the code.
* @param <T> Class of managed item.
*/
public abstract class Manager<T> {
private final Map<String, T> managed = new HashMap<>();
private final String name;
public Manager(String name) {
this.name = name;
}
public abstract void reload();
public boolean has(String id) {
return managed.containsKey(id);
}
public T get(String id) {
if (!has(id))
throw new IllegalArgumentException(name + " '" + id + "' does not exist.");
return managed.get(id);
}
public Collection<T> getValues() {
return managed.values();
}
public void register(T object) {
if (object instanceof ActionBarElement)
managed.put(((ActionBarElement) object).getId(), object);
}
public void registerAll(Map<String, T> objects) {
managed.putAll(objects);
}
public void clear() {
managed.clear();
}
public int size() {
return managed.size();
}
public String getName() {
return name;
}
public void error(String key, Exception e) {
MMOActionBar.getInstance().getLogger().log(Level.WARNING, "Could not load " + name + " '" + key + "': " + e.getMessage());
}
}
package com.ehhthan.mmoactionbar.manager;
import com.ehhthan.mmoactionbar.api.element.ActionBarElement;
import java.util.HashMap;
import java.util.Map;
/**
* This is a manager than can be registered through the config
* as well as have default parameters in the code.
* @param <T> Class of managed item.
*/
public abstract class ProvidedManager<T> extends Manager<T> {
private final Map<String, T> provided = new HashMap<>();
public ProvidedManager(String name) {
super(name);
}
public void registerProvided(T object) {
if (object instanceof ActionBarElement)
provided.put(((ActionBarElement) object).getId(), object);
}
public Map<String, T> getProvided() {
return provided;
}
}
package com.ehhthan.mmoactionbar.manager;
package com.ehhthan.mmoactionbar.manager.type;
import com.ehhthan.mmoactionbar.MMOActionBar;
......@@ -28,7 +28,6 @@ public class ConfigManager {
* get copied into the plugin folder when the plugin enables
*/
public enum DefaultFile {
LANGUAGE("language/language.yml", "language", "language.yml");
private final String folderPath, fileName, resourceName;
......
package com.ehhthan.mmoactionbar.manager;
package com.ehhthan.mmoactionbar.manager.type;
import com.ehhthan.mmoactionbar.MMOActionBar;
import com.ehhthan.mmoactionbar.file.ConfigFile;
......
package com.ehhthan.mmoactionbar.manager.type;
import com.ehhthan.mmoactionbar.api.element.ConfigOption;
import com.ehhthan.mmoactionbar.api.reroute.RoutedMessage;
import com.ehhthan.mmoactionbar.api.reroute.RoutedMessages;
import com.ehhthan.mmoactionbar.manager.ProvidedManager;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
public class RouteManager extends ProvidedManager<RoutedMessage> {
public RouteManager() {
super(RoutedMessage.class.getSimpleName());
for (Field field : RoutedMessages.class.getFields())
try {
if (Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers()) && field.get(null) instanceof RoutedMessage)
registerProvided((RoutedMessage) field.get(null));
} catch (IllegalArgumentException | IllegalAccessException exception) {
error(field.getName(), exception);
}
}
@Override
public void reload() {
clear();
registerAll(getProvided());
for (RoutedMessage message : getValues()) {
if (message instanceof ConfigOption)
((ConfigOption) message).reloadOptions();
}
}
}
# Do not touch this.
config-version: 1
\ No newline at end of file
config-version: 1
reroute-options:
# Options that all messages follow.
general:
# How long the message should last for in ticks.
# Does not work with chat messages.
last-for: 60
# Text to appear before the routed message.
prefix: ''
# Text to appear after the routed message.
suffix: ''
# Options for boss bars.
boss-bar:
# What color should the bar display?
# Colors: pink, blue, red, green, yellow, purple, and white.
color: white
# Which overlay should the bar display?
# Overlay: progress, notched_6, notched_10, notched_12, and notched_20.
overlay: progress
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment