165 lines
4.7 KiB
Java
165 lines
4.7 KiB
Java
package com.me.tft_02.soulbound;
|
|
|
|
import java.io.File;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
|
|
import org.bukkit.configuration.InvalidConfigurationException;
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
import org.bukkit.plugin.PluginManager;
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
import com.me.tft_02.soulbound.commands.BindCommand;
|
|
import com.me.tft_02.soulbound.commands.BindOnEquipCommand;
|
|
import com.me.tft_02.soulbound.commands.BindOnPickupCommand;
|
|
import com.me.tft_02.soulbound.commands.BindOnUseCommand;
|
|
import com.me.tft_02.soulbound.commands.SoulboundCommand;
|
|
import com.me.tft_02.soulbound.commands.UnbindCommand;
|
|
import com.me.tft_02.soulbound.config.Config;
|
|
import com.me.tft_02.soulbound.config.ItemsConfig;
|
|
import com.me.tft_02.soulbound.hooks.EpicBossRecodedListener;
|
|
import com.me.tft_02.soulbound.listeners.BlockListener;
|
|
import com.me.tft_02.soulbound.listeners.EntityListener;
|
|
import com.me.tft_02.soulbound.listeners.InventoryListener;
|
|
import com.me.tft_02.soulbound.listeners.PlayerListener;
|
|
import com.me.tft_02.soulbound.util.LogFilter;
|
|
|
|
public class Soulbound extends JavaPlugin {
|
|
/* File Paths */
|
|
private static String mainDirectory;
|
|
|
|
public static Soulbound p;
|
|
|
|
// Jar Stuff
|
|
public static File soulbound;
|
|
|
|
// Checks for hooking into other plugins
|
|
public static boolean epicBossRecodedEnabled = false;
|
|
public static boolean loreLocksEnabled = false;
|
|
|
|
// Update Check
|
|
private boolean updateAvailable;
|
|
|
|
public File msgfile;
|
|
public FileConfiguration msgConfig;
|
|
|
|
public void onLoad() {
|
|
saveDefaultConfig();
|
|
this.saveResource("message.yml", false);
|
|
msgfile = new File(this.getDataFolder(), "message.yml");
|
|
msgConfig = Loadcfg(msgfile);
|
|
}
|
|
|
|
|
|
/**
|
|
* Run things on enable.
|
|
*/
|
|
@Override
|
|
public void onEnable() {
|
|
p = this;
|
|
getLogger().setFilter(new LogFilter(this));
|
|
|
|
setupFilePaths();
|
|
|
|
loadConfigFiles();
|
|
|
|
setupEpicBossRecoded();
|
|
|
|
registerEvents();
|
|
|
|
getCommand("soulbound").setExecutor(new SoulboundCommand());
|
|
getCommand("bind").setExecutor(new BindCommand());
|
|
getCommand("bindonpickup").setExecutor(new BindOnPickupCommand());
|
|
getCommand("bindonuse").setExecutor(new BindOnUseCommand());
|
|
getCommand("bindonequip").setExecutor(new BindOnEquipCommand());
|
|
getCommand("unbind").setExecutor(new UnbindCommand());
|
|
}
|
|
|
|
private void registerEvents() {
|
|
PluginManager pm = getServer().getPluginManager();
|
|
pm.registerEvents(new PlayerListener(), this);
|
|
pm.registerEvents(new InventoryListener(), this);
|
|
pm.registerEvents(new EntityListener(), this);
|
|
pm.registerEvents(new BlockListener(), this);
|
|
}
|
|
|
|
private void setupEpicBossRecoded() {
|
|
if (getServer().getPluginManager().isPluginEnabled("EpicBossRecoded")) {
|
|
epicBossRecodedEnabled = true;
|
|
debug("EpicBossRecoded found!");
|
|
getServer().getPluginManager().registerEvents(new EpicBossRecodedListener(), this);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Run things on disable.
|
|
*/
|
|
@Override
|
|
public void onDisable() {}
|
|
|
|
public static String getMainDirectory() {
|
|
return mainDirectory;
|
|
}
|
|
|
|
public boolean isUpdateAvailable() {
|
|
return updateAvailable;
|
|
}
|
|
|
|
public void debug(String message) {
|
|
getLogger().info("[Debug] " + message);
|
|
}
|
|
|
|
/**
|
|
* Setup the various storage file paths
|
|
*/
|
|
private void setupFilePaths() {
|
|
soulbound = getFile();
|
|
mainDirectory = getDataFolder().getPath() + File.separator;
|
|
}
|
|
|
|
private void loadConfigFiles() {
|
|
Config.getInstance();
|
|
ItemsConfig.getInstance();
|
|
}
|
|
|
|
public FileConfiguration Loadcfg(File cfgfile) {
|
|
if (!cfgfile.exists()) {
|
|
saveResource(cfgfile.getName(), false);
|
|
return YamlConfiguration.loadConfiguration(cfgfile);
|
|
} else {
|
|
return YamlConfiguration.loadConfiguration(cfgfile);
|
|
}
|
|
}
|
|
|
|
public void LoadConfig(FileConfiguration cfg, File cfgfile)
|
|
throws FileNotFoundException, IOException,
|
|
InvalidConfigurationException {
|
|
if (!cfgfile.exists()) {
|
|
saveResource(cfgfile.getName(), false);
|
|
cfg.load(cfgfile);
|
|
} else {
|
|
cfg.load(cfgfile);
|
|
}
|
|
}
|
|
|
|
public void Savecfg(FileConfiguration cfg, File cfgfile) {
|
|
try {
|
|
// cfg.saveToString();
|
|
cfg.save(cfgfile);
|
|
} catch (IOException e) {
|
|
getLogger().info("配置文件" + cfgfile.getName() + "已保存!");
|
|
}
|
|
}
|
|
|
|
public String getmessage(String path) {
|
|
String message = this.msgConfig.getString(path).replaceAll("&", "§");
|
|
return message;
|
|
}
|
|
|
|
public String getlang(String type) {
|
|
return this.getmessage("Message." + type);
|
|
}
|
|
|
|
}
|