|
@@ -29,41 +29,67 @@ import xyz.spaceio.hooks.SkyblockAPIHook;
|
|
import xyz.spaceio.hooks.uSkyBlockHook;
|
|
import xyz.spaceio.hooks.uSkyBlockHook;
|
|
|
|
|
|
public class CustomOreGen extends JavaPlugin {
|
|
public class CustomOreGen extends JavaPlugin {
|
|
- public static List<GeneratorConfig> generatorConfigs = new ArrayList<GeneratorConfig>();
|
|
|
|
- public static List<String> disabledWorlds = new ArrayList<String>();
|
|
|
|
-
|
|
|
|
- public static ConsoleCommandSender clogger;
|
|
|
|
|
|
|
|
- private static HashMap<UUID, Integer> cachedOregenConfigs = new HashMap<UUID, Integer>();
|
|
|
|
- private static JSONConfig cachedOregenJsonConfig;
|
|
|
|
|
|
+ /*
|
|
|
|
+ * Configurations for all generators (defined in the config.yml)
|
|
|
|
+ */
|
|
|
|
+ private List<GeneratorConfig> generatorConfigs = new ArrayList<GeneratorConfig>();
|
|
|
|
|
|
- public static String activeInWorldName = "";
|
|
|
|
|
|
+ /*
|
|
|
|
+ * Disabled world blacklist
|
|
|
|
+ */
|
|
|
|
+ private List<String> disabledWorlds = new ArrayList<String>();
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ * Our logger
|
|
|
|
+ */
|
|
|
|
+ private ConsoleCommandSender clogger;
|
|
|
|
|
|
|
|
+ /*
|
|
|
|
+ * Cache for GeneratorConfig ID's for each player
|
|
|
|
+ */
|
|
|
|
+ private HashMap<UUID, Integer> cachedOregenConfigs = new HashMap<UUID, Integer>();
|
|
|
|
+ private JSONConfig cachedOregenJsonConfig;
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ * The skyblock world name
|
|
|
|
+ */
|
|
|
|
+ private String activeInWorldName = "";
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ * API Hook for the corresponding SkyBlock plugin
|
|
|
|
+ */
|
|
private SkyblockAPIHook skyblockAPI;
|
|
private SkyblockAPIHook skyblockAPI;
|
|
|
|
|
|
|
|
+ /*
|
|
|
|
+ * Prefix for the clogger
|
|
|
|
+ */
|
|
|
|
+ private final String PREFIX = "§6[CustomOreGen] ";
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void onEnable() {
|
|
public void onEnable() {
|
|
clogger = getServer().getConsoleSender();
|
|
clogger = getServer().getConsoleSender();
|
|
PluginManager pm = Bukkit.getPluginManager();
|
|
PluginManager pm = Bukkit.getPluginManager();
|
|
- pm.registerEvents(new Events(), this);
|
|
|
|
-
|
|
|
|
|
|
+ pm.registerEvents(new Events(this), this);
|
|
|
|
+
|
|
this.loadHook();
|
|
this.loadHook();
|
|
activeInWorldName = skyblockAPI.getSkyBlockWorldName();
|
|
activeInWorldName = skyblockAPI.getSkyBlockWorldName();
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
Bukkit.getPluginCommand("customoregen").setExecutor(new Cmd(this));
|
|
Bukkit.getPluginCommand("customoregen").setExecutor(new Cmd(this));
|
|
- try{
|
|
|
|
|
|
+
|
|
|
|
+ try {
|
|
loadConfig();
|
|
loadConfig();
|
|
- }catch(IOException e) {
|
|
|
|
|
|
+ } catch (IOException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
- cachedOregenJsonConfig = new JSONConfig(cachedOregenConfigs, new TypeToken<HashMap<UUID, Integer>>() { }.getType(), this);
|
|
|
|
|
|
+ cachedOregenJsonConfig = new JSONConfig(cachedOregenConfigs, new TypeToken<HashMap<UUID, Integer>>() {
|
|
|
|
+ }.getType(), this);
|
|
cachedOregenConfigs = (HashMap<UUID, Integer>) cachedOregenJsonConfig.get();
|
|
cachedOregenConfigs = (HashMap<UUID, Integer>) cachedOregenJsonConfig.get();
|
|
- if(cachedOregenConfigs == null){
|
|
|
|
|
|
+ if (cachedOregenConfigs == null) {
|
|
cachedOregenConfigs = new HashMap<UUID, Integer>();
|
|
cachedOregenConfigs = new HashMap<UUID, Integer>();
|
|
}
|
|
}
|
|
disabledWorlds = getConfig().getStringList("disabled-worlds");
|
|
disabledWorlds = getConfig().getStringList("disabled-worlds");
|
|
-
|
|
|
|
|
|
+
|
|
new Metrics(this);
|
|
new Metrics(this);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -71,34 +97,34 @@ public class CustomOreGen extends JavaPlugin {
|
|
* creates a new api hook instance for the used skyblock plugin
|
|
* creates a new api hook instance for the used skyblock plugin
|
|
*/
|
|
*/
|
|
private void loadHook() {
|
|
private void loadHook() {
|
|
- if(Bukkit.getServer().getPluginManager().isPluginEnabled("ASkyBlock")) {
|
|
|
|
|
|
+ if (Bukkit.getServer().getPluginManager().isPluginEnabled("ASkyBlock")) {
|
|
skyblockAPI = new ASkyBlockHook();
|
|
skyblockAPI = new ASkyBlockHook();
|
|
- clogger.sendMessage("§6[CustomOreGen] §aUsing ASkyBlock as SkyBlock-Plugin");
|
|
|
|
- }else if(Bukkit.getServer().getPluginManager().isPluginEnabled("AcidIsland")) {
|
|
|
|
|
|
+ sendConsole("&aUsing ASkyBlock as SkyBlock-Plugin");
|
|
|
|
+ } else if (Bukkit.getServer().getPluginManager().isPluginEnabled("AcidIsland")) {
|
|
skyblockAPI = new AcidIslandHook();
|
|
skyblockAPI = new AcidIslandHook();
|
|
- clogger.sendMessage("§6[CustomOreGen] §aUsing AcidIsland as SkyBlock-Plugin");
|
|
|
|
- }else if(Bukkit.getServer().getPluginManager().isPluginEnabled("uSkyBlock")) {
|
|
|
|
|
|
+ sendConsole("&aUsing AcidIsland as SkyBlock-Plugin");
|
|
|
|
+ } else if (Bukkit.getServer().getPluginManager().isPluginEnabled("uSkyBlock")) {
|
|
skyblockAPI = new uSkyBlockHook();
|
|
skyblockAPI = new uSkyBlockHook();
|
|
- clogger.sendMessage("§6[CustomOreGen] §aUsing uSkyBlock as SkyBlock-Plugin");
|
|
|
|
|
|
+ sendConsole("&aUsing uSkyBlock as SkyBlock-Plugin");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void onDisable() {
|
|
public void onDisable() {
|
|
cachedOregenJsonConfig.saveToDisk(cachedOregenConfigs);
|
|
cachedOregenJsonConfig.saveToDisk(cachedOregenConfigs);
|
|
}
|
|
}
|
|
-
|
|
|
|
- public static World getActiveWorld(){
|
|
|
|
|
|
+
|
|
|
|
+ public World getActiveWorld() {
|
|
return Bukkit.getWorld(activeInWorldName);
|
|
return Bukkit.getWorld(activeInWorldName);
|
|
}
|
|
}
|
|
|
|
|
|
public int getLevel(UUID uuid) {
|
|
public int getLevel(UUID uuid) {
|
|
return skyblockAPI.getIslandLevel(uuid);
|
|
return skyblockAPI.getIslandLevel(uuid);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public OfflinePlayer getOwner(Location loc) {
|
|
public OfflinePlayer getOwner(Location loc) {
|
|
UUID uuid = skyblockAPI.getIslandOwner(loc);
|
|
UUID uuid = skyblockAPI.getIslandOwner(loc);
|
|
- if(uuid == null){
|
|
|
|
|
|
+ if (uuid == null) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
OfflinePlayer p = Bukkit.getOfflinePlayer(uuid);
|
|
OfflinePlayer p = Bukkit.getOfflinePlayer(uuid);
|
|
@@ -110,118 +136,133 @@ public class CustomOreGen extends JavaPlugin {
|
|
reloadConfig();
|
|
reloadConfig();
|
|
loadConfig();
|
|
loadConfig();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * Just a method that sorts out stupid configuration mistakes made by kids who always give 1-star-reviews on Spigot.
|
|
|
|
- */
|
|
|
|
|
|
+ * Just a method that sorts out stupid configuration mistakes made by kids who
|
|
|
|
+ * always give 1-star-reviews on Spigot.
|
|
|
|
+ */
|
|
public void loadConfig() throws IOException {
|
|
public void loadConfig() throws IOException {
|
|
// Writing default config to data directory
|
|
// Writing default config to data directory
|
|
File cfg = new File("plugins/CustomOreGen/config.yml");
|
|
File cfg = new File("plugins/CustomOreGen/config.yml");
|
|
File dir = new File("plugins/CustomOreGen/");
|
|
File dir = new File("plugins/CustomOreGen/");
|
|
- if(!dir.exists()) dir.mkdirs();
|
|
|
|
- if(!cfg.exists()){
|
|
|
|
|
|
+ if (!dir.exists())
|
|
|
|
+ dir.mkdirs();
|
|
|
|
+ if (!cfg.exists()) {
|
|
FileOutputStream writer = new FileOutputStream(new File(getDataFolder() + "/config.yml"));
|
|
FileOutputStream writer = new FileOutputStream(new File(getDataFolder() + "/config.yml"));
|
|
InputStream out = this.getClassLoader().getResourceAsStream("config.yml");
|
|
InputStream out = this.getClassLoader().getResourceAsStream("config.yml");
|
|
byte[] linebuffer = new byte[4096];
|
|
byte[] linebuffer = new byte[4096];
|
|
int lineLength = 0;
|
|
int lineLength = 0;
|
|
- while((lineLength = out.read(linebuffer)) > 0)
|
|
|
|
- {
|
|
|
|
- writer.write(linebuffer, 0, lineLength);
|
|
|
|
|
|
+ while ((lineLength = out.read(linebuffer)) > 0) {
|
|
|
|
+ writer.write(linebuffer, 0, lineLength);
|
|
}
|
|
}
|
|
- writer.close();
|
|
|
|
|
|
+ writer.close();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
this.reloadConfig();
|
|
this.reloadConfig();
|
|
generatorConfigs = new ArrayList<GeneratorConfig>();
|
|
generatorConfigs = new ArrayList<GeneratorConfig>();
|
|
- for(String key : this.getConfig().getConfigurationSection("generators").getKeys(false)){
|
|
|
|
|
|
+ for (String key : this.getConfig().getConfigurationSection("generators").getKeys(false)) {
|
|
double totalChance = 0d;
|
|
double totalChance = 0d;
|
|
GeneratorConfig gc = new GeneratorConfig();
|
|
GeneratorConfig gc = new GeneratorConfig();
|
|
gc.permission = this.getConfig().getString("generators." + key + ".permission");
|
|
gc.permission = this.getConfig().getString("generators." + key + ".permission");
|
|
gc.unlock_islandLevel = this.getConfig().getInt("generators." + key + ".unlock_islandLevel");
|
|
gc.unlock_islandLevel = this.getConfig().getInt("generators." + key + ".unlock_islandLevel");
|
|
- if(gc.permission == null){
|
|
|
|
- System.out.println("[CustomOreGen] Config error: generator " + key + " does not have a valid permission entry");
|
|
|
|
|
|
+ if (gc.permission == null) {
|
|
|
|
+ sendConsole(String.format("&cConfig error: generator %s does not have a valid permission entry!", key));
|
|
}
|
|
}
|
|
- if(gc.unlock_islandLevel > 0 && gc.permission.length() > 1){
|
|
|
|
- System.out.println("[CustomOreGen] Config error: generator " + key + " has both a permission and level setup! Be sure to choose one of them!");
|
|
|
|
|
|
+ if (gc.unlock_islandLevel > 0 && gc.permission.length() > 1) {
|
|
|
|
+ sendConsole(String.format("&cConfig error: generator %s has both a permission and level setup! Be sure to choose one of them!", key));
|
|
}
|
|
}
|
|
-
|
|
|
|
- for(String raw : this.getConfig().getStringList("generators." + key + ".blocks")){
|
|
|
|
- try{
|
|
|
|
- if(!raw.contains("!")){
|
|
|
|
|
|
+
|
|
|
|
+ for (String raw : this.getConfig().getStringList("generators." + key + ".blocks")) {
|
|
|
|
+ try {
|
|
|
|
+ if (!raw.contains("!")) {
|
|
String material = raw.split(":")[0];
|
|
String material = raw.split(":")[0];
|
|
- if(Material.getMaterial(material.toUpperCase()) == null){
|
|
|
|
- System.out.println("[CustomOreGen] Config error: generator " + key + " has an unrecognized material: " + material);
|
|
|
|
|
|
+ if (Material.getMaterial(material.toUpperCase()) == null) {
|
|
|
|
+ sendConsole(String.format("&cConfig error: generator %s has an unrecognized material: %s", key, material));
|
|
}
|
|
}
|
|
double percent = Double.parseDouble(raw.split(":")[1]);
|
|
double percent = Double.parseDouble(raw.split(":")[1]);
|
|
totalChance += percent;
|
|
totalChance += percent;
|
|
gc.itemList.add(new GeneratorItem(material, (byte) 0, percent));
|
|
gc.itemList.add(new GeneratorItem(material, (byte) 0, percent));
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
String material = raw.split("!")[0];
|
|
String material = raw.split("!")[0];
|
|
- if(Material.getMaterial(material.toUpperCase()) == null){
|
|
|
|
- System.out.println("[CustomOreGen] Config error: generator " + key + " has an unrecognized material: " + material);
|
|
|
|
|
|
+ if (Material.getMaterial(material.toUpperCase()) == null) {
|
|
|
|
+ sendConsole(String.format("&cConfig error: generator %s has an unrecognized material: %s", key, material));
|
|
}
|
|
}
|
|
double percent = Double.parseDouble(raw.split(":")[1]);
|
|
double percent = Double.parseDouble(raw.split(":")[1]);
|
|
totalChance += percent;
|
|
totalChance += percent;
|
|
int damage = Integer.parseInt(raw.split("!")[1].split(":")[0]);
|
|
int damage = Integer.parseInt(raw.split("!")[1].split(":")[0]);
|
|
gc.itemList.add(new GeneratorItem(material, (byte) damage, percent));
|
|
gc.itemList.add(new GeneratorItem(material, (byte) damage, percent));
|
|
}
|
|
}
|
|
- }catch(Exception e){
|
|
|
|
- System.out.println("[CustomOreGen] Config error: general configuration error. Please check you config.yml");
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
|
+ sendConsole("&cConfig error: general configuration error. Please check you config.yml");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if(totalChance != 100.0){
|
|
|
|
- System.out.println("[CustomOreGen] Config error: generator " + key + " does not have a total chance of 100%! Chance: " + totalChance);
|
|
|
|
|
|
+ if (totalChance != 100.0) {
|
|
|
|
+ sendConsole(String.format("&cConfig error: generator %s does not have a total chance of 100%! Total chance is: %d", key, totalChance));
|
|
}
|
|
}
|
|
generatorConfigs.add(gc);
|
|
generatorConfigs.add(gc);
|
|
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
- //this.saveConfig();
|
|
|
|
- clogger.sendMessage("§6[CustomOreGen] §aLoaded §c" + generatorConfigs.size() + " §agenerators");
|
|
|
|
|
|
+
|
|
|
|
+ sendConsole(String.format("&aLoaded &c%d &agenerators!", generatorConfigs.size()));
|
|
}
|
|
}
|
|
- public static GeneratorConfig getGeneratorConfigForPlayer(OfflinePlayer p){
|
|
|
|
|
|
+
|
|
|
|
+ public GeneratorConfig getGeneratorConfigForPlayer(OfflinePlayer p) {
|
|
GeneratorConfig gc = null;
|
|
GeneratorConfig gc = null;
|
|
int id = 0;
|
|
int id = 0;
|
|
if (p == null) {
|
|
if (p == null) {
|
|
- gc = CustomOreGen.generatorConfigs.get(0);
|
|
|
|
|
|
+ gc = generatorConfigs.get(0);
|
|
cacheOreGen(p.getUniqueId(), id);
|
|
cacheOreGen(p.getUniqueId(), id);
|
|
} else {
|
|
} else {
|
|
-
|
|
|
|
- int islandLevel = CustomOreGen.getLevel(p.getUniqueId());
|
|
|
|
|
|
|
|
- if(p.isOnline()){
|
|
|
|
|
|
+ int islandLevel = getLevel(p.getUniqueId());
|
|
|
|
+
|
|
|
|
+ if (p.isOnline()) {
|
|
Player realP = p.getPlayer();
|
|
Player realP = p.getPlayer();
|
|
- if (activeInWorldName.equals(
|
|
|
|
- realP.getWorld().getName())) {
|
|
|
|
- for (GeneratorConfig gc2 : CustomOreGen.generatorConfigs) {
|
|
|
|
|
|
+ if (activeInWorldName.equals(realP.getWorld().getName())) {
|
|
|
|
+ for (GeneratorConfig gc2 : generatorConfigs) {
|
|
if (gc2 == null) {
|
|
if (gc2 == null) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
if ((realP.hasPermission(gc2.permission) || gc2.permission.length() == 0) && islandLevel >= gc2.unlock_islandLevel) {
|
|
if ((realP.hasPermission(gc2.permission) || gc2.permission.length() == 0) && islandLevel >= gc2.unlock_islandLevel) {
|
|
- // Weiter
|
|
|
|
|
|
+ // continue
|
|
gc = gc2;
|
|
gc = gc2;
|
|
id++;
|
|
id++;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
- }
|
|
|
|
- }else{
|
|
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
gc = getCachedGeneratorConfig(p.getUniqueId());
|
|
gc = getCachedGeneratorConfig(p.getUniqueId());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if(id > 0){
|
|
|
|
|
|
+ if (id > 0) {
|
|
cacheOreGen(p.getUniqueId(), id - 1);
|
|
cacheOreGen(p.getUniqueId(), id - 1);
|
|
}
|
|
}
|
|
return gc;
|
|
return gc;
|
|
}
|
|
}
|
|
- public static GeneratorConfig getCachedGeneratorConfig(UUID uuid){
|
|
|
|
- if(cachedOregenConfigs.containsKey(uuid)){
|
|
|
|
- return CustomOreGen.generatorConfigs.get(cachedOregenConfigs.get(uuid));
|
|
|
|
|
|
+
|
|
|
|
+ public List<String> getDisabledWorlds() {
|
|
|
|
+ return disabledWorlds;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setDisabledWorlds(List<String> disabledWorlds) {
|
|
|
|
+ this.disabledWorlds = disabledWorlds;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public GeneratorConfig getCachedGeneratorConfig(UUID uuid) {
|
|
|
|
+ if (cachedOregenConfigs.containsKey(uuid)) {
|
|
|
|
+ return generatorConfigs.get(cachedOregenConfigs.get(uuid));
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
- public static void cacheOreGen(UUID uuid, int configID){
|
|
|
|
|
|
+
|
|
|
|
+ public void cacheOreGen(UUID uuid, int configID) {
|
|
cachedOregenConfigs.put(uuid, configID);
|
|
cachedOregenConfigs.put(uuid, configID);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public void sendConsole(String msg) {
|
|
|
|
+ clogger.sendMessage(PREFIX + msg.replace("&", "§"));
|
|
|
|
+ }
|
|
}
|
|
}
|