configs for features
This commit is contained in:
parent
15645a58f5
commit
5aded1e458
@ -6,7 +6,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import cz.marwland.mc.core.config.ConfigManager;
|
||||
import cz.marwland.mc.core.features.Feature;
|
||||
import cz.marwland.mc.essentials.features.Heil;
|
||||
import cz.marwland.mc.essentials.features.Borders;
|
||||
|
||||
public class MarwCore extends JavaPlugin {
|
||||
|
||||
@ -19,9 +19,9 @@ public class MarwCore extends JavaPlugin {
|
||||
|
||||
configManager = new ConfigManager(this);
|
||||
configManager.registerConfig("borders.yml");
|
||||
configManager.load();
|
||||
this.addFeature(new Borders(this));
|
||||
|
||||
this.addFeature(new Heil(this));
|
||||
configManager.load();
|
||||
this.features.forEach((k, v) -> v.onEnable());
|
||||
}
|
||||
|
||||
|
@ -3,19 +3,23 @@ package cz.marwland.mc.core.features;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.defaults.BukkitCommand;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import cz.marwland.mc.core.MarwCore;
|
||||
|
||||
public abstract class Feature implements Listener {
|
||||
private final Plugin plugin;
|
||||
private final MarwCore plugin;
|
||||
private String name = "";
|
||||
private ArrayList<BukkitCommand> commands = new ArrayList<>();
|
||||
private HashMap<String, String> configs = new HashMap<>();
|
||||
private static CommandMap cmap;
|
||||
|
||||
public Feature(Plugin plugin, String name) {
|
||||
public Feature(MarwCore plugin, String name) {
|
||||
this.plugin = plugin;
|
||||
this.name = name;
|
||||
Method commandMap;
|
||||
@ -35,6 +39,8 @@ public abstract class Feature implements Listener {
|
||||
}
|
||||
}
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
|
||||
configs.forEach((k, v) -> plugin.getConfigManager().registerConfig(k, v));
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
@ -48,8 +54,20 @@ public abstract class Feature implements Listener {
|
||||
return this.commands;
|
||||
}
|
||||
|
||||
public void addCommand(BukkitCommand cmd) {
|
||||
protected void addCommand(BukkitCommand cmd) {
|
||||
this.commands.add(cmd);
|
||||
}
|
||||
|
||||
protected void registerConfig(String path) {
|
||||
registerConfig(path, path);
|
||||
}
|
||||
|
||||
protected void registerConfig(String template, String path) {
|
||||
this.configs.put(template, path);
|
||||
}
|
||||
|
||||
protected FileConfiguration getConfig(String path) {
|
||||
return plugin.getConfigManager().getConfig(path);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,15 +4,13 @@ import java.util.Arrays;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.defaults.BukkitCommand;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerChatEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import cz.marwland.mc.core.MarwCore;
|
||||
import cz.marwland.mc.core.features.Feature;
|
||||
|
||||
public class Heil extends Feature {
|
||||
public class Borders extends Feature {
|
||||
|
||||
public Heil(Plugin plugin) {
|
||||
public Borders(MarwCore plugin) {
|
||||
super(plugin, "heil");
|
||||
// String name, String description, String usageMessage, List<String> aliases)
|
||||
this.addCommand(new BukkitCommand("sieg", "Heil the Führer!", "/sieg", Arrays.asList()) {
|
||||
@ -22,14 +20,13 @@ public class Heil extends Feature {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
this.registerConfig("borders.yml");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(PlayerChatEvent event) {
|
||||
if (event.getMessage().contains("sieg")) {
|
||||
event.setMessage("SIEG HEIL!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
super.onEnable();
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user