فهرست منبع

fixed broken uSkyblock level gathering

mastercake10 7 سال پیش
والد
کامیت
5c4b0d9e9f
3فایلهای تغییر یافته به همراه88 افزوده شده و 25 حذف شده
  1. 63 0
      src/de/Linus122/customoregen/JSONConfig.java
  2. 24 24
      src/de/Linus122/customoregen/Main.java
  3. 1 1
      src/plugin.yml

+ 63 - 0
src/de/Linus122/customoregen/JSONConfig.java

@@ -0,0 +1,63 @@
+package de.Linus122.customoregen;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.lang.reflect.Type;
+
+import org.bukkit.plugin.Plugin;
+
+import com.google.gson.Gson;
+
+
+public class JSONConfig {
+	File data;
+	Type type;
+	Object obj;
+	
+	public JSONConfig(Object obj, Type type, Plugin pl){
+		this.data = new File(pl.getDataFolder().getPath() + "/" + "data.json");
+		this.type = type;
+	}
+	public String getJson(Object obj){
+		Gson gson = new Gson();
+		return gson.toJson(obj, type);
+	}
+	public long saveToDisk(Object obj){
+		Gson gson = new Gson();
+		try {
+			FileOutputStream fout= new FileOutputStream (data);
+			ObjectOutputStream oos = new ObjectOutputStream(fout);
+			
+			oos.writeObject(gson.toJson(obj, type));
+			fout.close();
+			oos.close();
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		return data.length();
+	}
+	public Object get(){
+		Object  c = null;
+		if(data.exists()){
+			try {
+				FileInputStream fin = new FileInputStream(data);
+				ObjectInputStream ois = new ObjectInputStream(fin);
+				Gson gson = new Gson();
+				c = gson.fromJson((String) ois.readObject(), type);
+				ois.close();
+				fin.close();
+			} catch (Exception e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			return c;
+		}else{
+			return null;
+		}
+	}
+}

+ 24 - 24
src/de/Linus122/customoregen/Main.java

@@ -77,6 +77,11 @@ public class Main extends JavaPlugin {
 			return com.wasteofplastic.acidisland.ASkyBlockAPI.getInstance().getIslandLevel(uuid);
 		}
 		if(Bukkit.getServer().getPluginManager().isPluginEnabled("uSkyBlock")) {
+			if(Bukkit.getPlayer(uuid) != null){
+				Player p = Bukkit.getPlayer(uuid);
+				return (int) Math.floor(us.talabrek.ultimateskyblock.uSkyBlock.getInstance().getIslandLevel(p));
+			}
+			// Note: The API for getIslandInfo seems to be broken
 			return (int) Math.floor(us.talabrek.ultimateskyblock.uSkyBlock.getInstance().getIslandInfo(us.talabrek.ultimateskyblock.uSkyBlock.getInstance().getPlayerInfo(uuid)).getLevel());
 		}
 		return 0;
@@ -129,33 +134,28 @@ public class Main extends JavaPlugin {
 		 
 		this.reloadConfig();
 		generatorConfigs = new ArrayList<GeneratorConfig>();
-		int i = 0;
-		while(true){
-			i++;
-			if(this.getConfig().contains("generators.generator" + i, true)){
-				GeneratorConfig gc = new GeneratorConfig();
-				gc.permission = this.getConfig().getString("generators.generator" + i + ".permission");
-				gc.unlock_islandLevel = this.getConfig().getInt("generators.generator" + i + ".unlock_islandLevel");
-				for(String raw : this.getConfig().getStringList("generators.generator" + i + ".blocks")){
-					try{
-						if(!raw.contains("!")){
-							String material = raw.split(":")[0];
-							double percent = Double.parseDouble(raw.split(":")[1]);
-							gc.itemList.add(new GeneratorItem(material, (byte) 0, percent));
-						}else{
-							String material = raw.split("!")[0];
-							double percent = Double.parseDouble(raw.split(":")[1]);
-							int damage = Integer.parseInt(raw.split("!")[1].split(":")[0]);
-							gc.itemList.add(new GeneratorItem(material, (byte) damage, percent));
-						}
-					}catch(Exception e){
-						e.printStackTrace();
+		for(String key : this.getConfig().getConfigurationSection("generators").getKeys(false)){
+			GeneratorConfig gc = new GeneratorConfig();
+			gc.permission = this.getConfig().getString("generators." + key + ".permission");
+			gc.unlock_islandLevel = this.getConfig().getInt("generators." + key + ".unlock_islandLevel");
+			for(String raw : this.getConfig().getStringList("generators." + key + ".blocks")){
+				try{
+					if(!raw.contains("!")){
+						String material = raw.split(":")[0];
+						double percent = Double.parseDouble(raw.split(":")[1]);
+						gc.itemList.add(new GeneratorItem(material, (byte) 0, percent));
+					}else{
+						String material = raw.split("!")[0];
+						double percent = Double.parseDouble(raw.split(":")[1]);
+						int damage = Integer.parseInt(raw.split("!")[1].split(":")[0]);
+						gc.itemList.add(new GeneratorItem(material, (byte) damage, percent));
 					}
+				}catch(Exception e){
+					e.printStackTrace();
 				}
-				generatorConfigs.add(gc);
-			}else{
-				break;
 			}
+			generatorConfigs.add(gc);
+
 			
 		}
 		//this.saveConfig();

+ 1 - 1
src/plugin.yml

@@ -1,5 +1,5 @@
 name: CustomOreGen
-version: 1.2.33
+version: 1.2.35
 description: Controls the Ore-Generator
 author: Linus122
 soft-depends: [ASkyBlock, AcidIsland, uSkyBlock]