feature test
This commit is contained in:
parent
0d36a0b88d
commit
775363aa57
7
resources/borders.yml
Normal file
7
resources/borders.yml
Normal file
@ -0,0 +1,7 @@
|
||||
# Here you can specify the world limits.
|
||||
# Borders will be calculated automatically from values in the 'points' list.
|
||||
# These coordinates WILL be inside your border, therefore you must specify at least two.
|
||||
#world:
|
||||
# points:
|
||||
# - 500, 500
|
||||
# - -500, -500
|
24
src/cz/marwland/mc/core/Feature.java
Normal file
24
src/cz/marwland/mc/core/Feature.java
Normal file
@ -0,0 +1,24 @@
|
||||
package cz.marwland.mc.core;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public abstract class Feature implements Listener {
|
||||
private final Plugin plugin;
|
||||
private String name = "";
|
||||
|
||||
public Feature(Plugin plugin, String name) {
|
||||
this.plugin = plugin;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
@ -1,19 +1,45 @@
|
||||
package cz.marwland.mc.core;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import cz.marwland.mc.core.cmd.First;
|
||||
import cz.marwland.mc.core.config.ConfigManager;
|
||||
import cz.marwland.mc.features.Heil;
|
||||
|
||||
public class MarwCore extends JavaPlugin {
|
||||
|
||||
private ConfigManager configManager;
|
||||
private HashMap<String, Feature> features = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getCommand("first").setExecutor(new First(this));
|
||||
getServer().getPluginManager().registerEvents(new EventListener(this), this);
|
||||
getLogger().info("Enabled!");
|
||||
configManager = new ConfigManager(this);
|
||||
configManager.registerConfig("borders.yml");
|
||||
configManager.load();
|
||||
|
||||
this.addFeature(new Heil(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
configManager.save();
|
||||
}
|
||||
|
||||
public ConfigManager getConfigManager() {
|
||||
return this.configManager;
|
||||
}
|
||||
|
||||
public void addFeature(Feature f) {
|
||||
f.getName();
|
||||
getServer().getPluginManager().registerEvents(f, this);
|
||||
}
|
||||
|
||||
public Feature getFeature(String name) {
|
||||
return this.features.get(name);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package cz.marwland.mc.core.cmd;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import cz.marwland.mc.core.MarwCore;
|
||||
|
||||
@ -17,6 +18,12 @@ public class First implements CommandExecutor {
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
plugin.getLogger().info("Hello?");
|
||||
sender.sendMessage("henlo");
|
||||
return false;
|
||||
if (!(sender instanceof Player))
|
||||
return true;
|
||||
|
||||
Player p = (Player) sender;
|
||||
p.getWorld().getWorldBorder();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
82
src/cz/marwland/mc/core/config/ConfigFile.java
Normal file
82
src/cz/marwland/mc/core/config/ConfigFile.java
Normal file
@ -0,0 +1,82 @@
|
||||
package cz.marwland.mc.core.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class ConfigFile {
|
||||
|
||||
private final Plugin plugin;
|
||||
private File file;
|
||||
private String path;
|
||||
private FileConfiguration cfg;
|
||||
|
||||
public ConfigFile(Plugin plugin, String template, String path) {
|
||||
this.plugin = plugin;
|
||||
this.path = template;
|
||||
this.file = new File(plugin.getDataFolder(), path);
|
||||
}
|
||||
|
||||
public ConfigFile(Plugin plugin, String path) {
|
||||
this(plugin, path, path);
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return this.file;
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig() {
|
||||
return this.cfg;
|
||||
}
|
||||
|
||||
public void load() {
|
||||
if (!file.exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
|
||||
InputStream in = plugin.getResource(path);
|
||||
if (in == null) {
|
||||
plugin.getLogger().config("The embedded resource '" + path + "' cannot be found!");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
OutputStream out = new FileOutputStream(file);
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
out.close();
|
||||
in.close();
|
||||
} catch (IOException ex) {
|
||||
plugin.getLogger().log(Level.CONFIG, "Could not save '" + path + "' to " + file, ex);
|
||||
}
|
||||
}
|
||||
|
||||
cfg = new YamlConfiguration();
|
||||
try {
|
||||
cfg.load(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidConfigurationException e) {
|
||||
plugin.getLogger().config("Invalid configuration " + path + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
try {
|
||||
cfg.save(file);
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().config("Cannot save " + path + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
41
src/cz/marwland/mc/core/config/ConfigManager.java
Normal file
41
src/cz/marwland/mc/core/config/ConfigManager.java
Normal file
@ -0,0 +1,41 @@
|
||||
package cz.marwland.mc.core.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class ConfigManager {
|
||||
private final Plugin plugin;
|
||||
|
||||
private HashMap<String, ConfigFile> configs = new HashMap<>();
|
||||
|
||||
public ConfigManager(Plugin pl) {
|
||||
this.plugin = pl;
|
||||
}
|
||||
|
||||
public void registerConfig(String path) {
|
||||
configs.put(path, new ConfigFile(plugin, path));
|
||||
}
|
||||
|
||||
public void registerConfig(String template, String path) {
|
||||
configs.put(path, new ConfigFile(plugin, template, path));
|
||||
}
|
||||
|
||||
public void load() {
|
||||
configs.forEach((k, v) -> v.load());
|
||||
}
|
||||
|
||||
public void save() {
|
||||
configs.forEach((k, v) -> v.save());
|
||||
}
|
||||
|
||||
public ConfigFile getConfigFile(String path) {
|
||||
return configs.get(path);
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig(String path) {
|
||||
return configs.get(path).getConfig();
|
||||
}
|
||||
|
||||
}
|
32
src/cz/marwland/mc/features/Heil.java
Normal file
32
src/cz/marwland/mc/features/Heil.java
Normal file
@ -0,0 +1,32 @@
|
||||
package cz.marwland.mc.features;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerChatEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import cz.marwland.mc.core.Feature;
|
||||
|
||||
public class Heil extends Feature {
|
||||
|
||||
public Heil(Plugin plugin) {
|
||||
super(plugin, "heil");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
||||
}
|
||||
@EventHandler
|
||||
public void onPlayerChat(PlayerChatEvent event) {
|
||||
if (event.getMessage().contains("sieg")) {
|
||||
event.setMessage("SIEG HEIL!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user