mirror of
https://gitlab.com/SamB440/rpgregions-2.git
synced 2025-12-28 19:29:16 +00:00
Add JavaPlugin
This commit is contained in:
101
src/main/java/net/islandearth/rpgregions/RPGRegions.java
Normal file
101
src/main/java/net/islandearth/rpgregions/RPGRegions.java
Normal file
@@ -0,0 +1,101 @@
|
||||
package net.islandearth.rpgregions;
|
||||
|
||||
import net.islandearth.languagy.language.Language;
|
||||
import net.islandearth.languagy.language.LanguagyImplementation;
|
||||
import net.islandearth.languagy.language.LanguagyPluginHook;
|
||||
import net.islandearth.languagy.language.Translator;
|
||||
import net.islandearth.rpgregions.api.RPGRegionsAPI;
|
||||
import net.islandearth.rpgregions.managers.RPGRegionsManagers;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class RPGRegions extends JavaPlugin implements RPGRegionsAPI, LanguagyPluginHook {
|
||||
|
||||
private RPGRegionsManagers managers;
|
||||
private static RPGRegions plugin;
|
||||
|
||||
public Translator getTranslator() {
|
||||
return translator;
|
||||
}
|
||||
|
||||
@LanguagyImplementation(fallbackFile = "plugins/RPGRegions/lang/en_gb.yml")
|
||||
private Translator translator;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
this.createConfig();
|
||||
this.generateLang();
|
||||
this.managers = new RPGRegionsManagers(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
}
|
||||
|
||||
@Override
|
||||
public RPGRegionsManagers getManagers() {
|
||||
return managers;
|
||||
}
|
||||
|
||||
private void generateLang() {
|
||||
File lang = new File(this.getDataFolder() + "/lang/");
|
||||
if (!lang.exists()) lang.mkdirs();
|
||||
|
||||
for (Language language : Language.values()) {
|
||||
File file = new File(getDataFolder() + "/lang/" + language.getCode() + ".yml");
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
config.options().copyDefaults(true);
|
||||
config.addDefault("toggled", "&aYour map has been toggled.");
|
||||
config.addDefault("invalid_cursor", "&cInvalid cursor type.");
|
||||
config.addDefault("location_saved", "&aMap location saved.");
|
||||
config.addDefault("cursor_removed", "&aThe cursor has been removed.");
|
||||
config.addDefault("location_not_saved", "&cYour current location is not saved as a cursor.");
|
||||
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void createConfig() {
|
||||
FileConfiguration config = this.getConfig();
|
||||
String header;
|
||||
String eol = System.getProperty("line.separator");
|
||||
header = "This is the config for RPGRegions." + eol;
|
||||
config.options().header(header);
|
||||
config.addDefault("storage", "file");
|
||||
config.addDefault("sql.host", "localhost");
|
||||
config.addDefault("sql.port", 3306);
|
||||
config.addDefault("sql.db", "RPGMap");
|
||||
config.addDefault("sql.user", "user");
|
||||
config.addDefault("sql.pass", "pass");
|
||||
config.options().copyDefaults(true);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
public static RPGRegionsAPI getAPI() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLanguagyHook() {
|
||||
translator.setDisplay(Material.MAP);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user