Parcourir la source

second release

Linus il y a 7 ans
commit
261529b8ba

+ 30 - 0
config.yml

@@ -0,0 +1,30 @@
+# You can create generators as much as you want.
+# Important: All generators should be named "generator1", "generator2", etc. 
+# You can define the spawnrates of any block in the blocks-section.
+# The spawnrates are in percent, for example 57.3 are 57,3%.
+# All values together should be 100%. If all values together are higher or lower as 100, the plugin would'nt work correctly.
+# The permissions are custom, so you can make a generator for VIPS, and give them the permission "oregen.vip".
+# Are you finish with configuring? Just type /customoregen to reload the plugin!
+
+# Note: If the Island's owner is offline, the cobblestone generator would be choose the first Generator-Config.
+
+generators:
+  generator1:
+    # default generator
+    blocks:
+    # Please use Bukkit-Blocknames. List: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html
+    - STONE:50.0
+    - SANDSTONE:40.0
+    - IRON_ORE:10.0
+    permission: ''
+    # You can also define from what level the generator should be activated. Example: Leave all permissions empty and
+    # only work with the island Level. The plugin would only consider the islandLevel then.
+    unlock_islandLevel: 0
+  generator2:
+    # vip generator, VIPS need generators.vip permission
+    blocks:
+    - IRON_ORE:90.0
+    - STONE:5.0
+    - SANDSTONE:5.0
+    permission: 'oregen.vip'
+    unlock_islandLevel: 0

+ 32 - 0
de/Linus122/customoregen/Cmd.java

@@ -0,0 +1,32 @@
+package de.Linus122.customoregen;
+
+import java.io.IOException;
+
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+
+public class Cmd implements CommandExecutor {
+
+	Main main;
+	public Cmd(Main main) {
+		this.main = main;
+	}
+
+	public boolean onCommand(CommandSender cs, Command arg1, String arg2,
+			String[] arg3) {
+		if(!cs.hasPermission("customoregen.admin")){
+			cs.sendMessage("You dont have permissions.");
+		}else{
+			try {
+				main.reload();
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			cs.sendMessage("§aConfig reloaded!");
+		}
+		return true;
+	}
+
+}

+ 85 - 0
de/Linus122/customoregen/Events.java

@@ -0,0 +1,85 @@
+package de.Linus122.customoregen;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Random;
+import java.util.Set;
+import java.util.UUID;
+
+import org.bukkit.Bukkit;
+import org.bukkit.EntityEffect;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.block.Block;
+import org.bukkit.block.BlockFace;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.block.BlockFromToEvent;
+
+
+public class Events implements Listener {
+	@SuppressWarnings({ "deprecation", "unused" })
+	@EventHandler
+	public void onFromTo(BlockFromToEvent event){
+	    int id = event.getBlock().getTypeId();
+	    if ((id >= 8) && (id <= 11)){
+	    	Block b = event.getToBlock();
+	    	int toid = b.getTypeId();
+	    	if ((toid == 0) && (generatesCobble(id, b))){
+	    		GeneratorConfig gc = null;
+
+				Player p = Main.getOwner(b.getLocation());
+				if(p == null){
+					gc = Main.generatorConfigs.get(0);	
+				}else{
+					int islandLevel = Main.getLevel(p);
+
+					if(Main.activeInWorld.getName().equals(b.getWorld().getName())){
+							for(GeneratorConfig gc2 : Main.generatorConfigs){
+								if(gc2 == null){
+									continue;
+								}
+								
+									if(p.hasPermission(gc2.permission) &&
+											islandLevel >= 
+											gc2.unlock_islandLevel ){
+										//Weiter
+										gc = gc2;
+									}	
+							
+							}	
+					}
+				}
+				if(gc == null) return;
+				if(getObject(gc) == null) return;
+				GeneratorItem winning = getObject(gc);
+				if(Material.getMaterial(winning.name) == null) return;
+				//b.setType(Material.getMaterial(winning));	
+				b.setTypeIdAndData(Material.getMaterial(winning.name).getId() , winning.damage, true);
+	    	}
+		}
+	}
+	public GeneratorItem getObject(GeneratorConfig gc){
+		
+		Random random = new Random();
+		double d = random.nextDouble() * 100;
+		for(GeneratorItem key : gc.itemList){
+			if ((d -= key.chance) < 0) return key;
+		}
+		return new GeneratorItem("COBBLESTONE", (byte) 0, 0); //DEFAULT
+	}
+	private final BlockFace[] faces = { BlockFace.SELF, BlockFace.UP, BlockFace.DOWN, BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST };
+    
+	public boolean generatesCobble(int id, Block b){
+	    int mirrorID1 = (id == 8) || (id == 9) ? 10 : 8;
+	    int mirrorID2 = (id == 8) || (id == 9) ? 11 : 9;
+	    for(BlockFace face : this.faces){
+	        Block r = b.getRelative(face, 1);
+	        if ((r.getTypeId() == mirrorID1) || (r.getTypeId() == mirrorID2)) {
+	            return true;
+	       }
+	    }
+	    return false;
+	 }
+}

+ 11 - 0
de/Linus122/customoregen/GeneratorConfig.java

@@ -0,0 +1,11 @@
+package de.Linus122.customoregen;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class GeneratorConfig {
+	public List<GeneratorItem> itemList = new ArrayList<GeneratorItem>();
+	public String permission = ";";
+	public int unlock_islandLevel = 0;
+}

+ 13 - 0
de/Linus122/customoregen/GeneratorItem.java

@@ -0,0 +1,13 @@
+package de.Linus122.customoregen;
+
+public class GeneratorItem {
+
+	String name;
+	Byte damage = 0;
+	double chance = 0d;
+	GeneratorItem(String name, byte damage, double chance){
+		this.name = name;
+		this.damage = damage;
+		this.chance = chance;
+	}
+}

+ 149 - 0
de/Linus122/customoregen/Main.java

@@ -0,0 +1,149 @@
+package de.Linus122.customoregen;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.PluginManager;
+import org.bukkit.plugin.java.JavaPlugin;
+
+
+public class Main extends JavaPlugin{
+	public static List<GeneratorConfig> generatorConfigs = new ArrayList<GeneratorConfig>();
+	
+	public static World activeInWorld;
+	@Override
+	public void onEnable(){
+		PluginManager pm = Bukkit.getPluginManager();
+		pm.registerEvents(new Events(), this);
+		Bukkit.getPluginCommand("customoregen").setExecutor(new Cmd(this));
+		
+		try {
+			loadConfig();
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		if(Bukkit.getServer().getPluginManager().isPluginEnabled("ASkyBlock")){
+			activeInWorld = com.wasteofplastic.askyblock.ASkyBlock.getIslandWorld();
+		}else
+		if(Bukkit.getServer().getPluginManager().isPluginEnabled("AcidIsland")){
+			activeInWorld = com.wasteofplastic.acidisland.ASkyBlock.getIslandWorld();	
+		}else
+		if(Bukkit.getServer().getPluginManager().isPluginEnabled("uSkyBlock")){
+			activeInWorld = us.talabrek.ultimateskyblock.uSkyBlock.getSkyBlockWorld();
+		}
+	}
+	@Override
+	public void onDisable(){
+		
+	}
+	public static int getLevel(Player p){
+		if(Bukkit.getServer().getPluginManager().isPluginEnabled("ASkyBlock")){
+			return com.wasteofplastic.askyblock.ASkyBlockAPI.getInstance().getIslandLevel(p.getUniqueId());
+		}else
+		if(Bukkit.getServer().getPluginManager().isPluginEnabled("AcidIsland")){
+			return com.wasteofplastic.acidisland.ASkyBlockAPI.getInstance().getIslandLevel(p.getUniqueId());
+		}else 
+		if(Bukkit.getServer().getPluginManager().isPluginEnabled("uSkyBlock")){
+			return (int) Math.floor(us.talabrek.ultimateskyblock.uSkyBlock.getAPI().getIslandLevel(p));
+		}
+		return 0;
+	}
+	static HashMap<UUID, Player> map = new HashMap<UUID, Player>();
+	public static Player getOwner(Location loc){
+		Set<Location> set = new HashSet<Location>();
+		set.add(loc);
+		
+		UUID uuid = null;
+		if(Bukkit.getServer().getPluginManager().isPluginEnabled("ASkyBlock")){
+			uuid = com.wasteofplastic.askyblock.ASkyBlockAPI.getInstance().getOwner(com.wasteofplastic.askyblock.ASkyBlockAPI.getInstance().locationIsOnIsland(set, loc));
+		}else
+		if(Bukkit.getServer().getPluginManager().isPluginEnabled("AcidIsland")){
+			uuid = com.wasteofplastic.acidisland.ASkyBlockAPI.getInstance().getOwner(com.wasteofplastic.acidisland.ASkyBlockAPI.getInstance().locationIsOnIsland(set, loc));
+		}else 
+		if(Bukkit.getServer().getPluginManager().isPluginEnabled("uSkyBlock")){
+			String player = us.talabrek.ultimateskyblock.uSkyBlock.getInstance().getIslandInfo(loc).getLeader();
+			if(Bukkit.getPlayer(player) != null){
+				if(Bukkit.getPlayer(player).getUniqueId() != null){
+					uuid = Bukkit.getPlayer(player).getUniqueId();
+				}
+			}
+		}
+		Player p = Bukkit.getPlayer(uuid);
+		//Offline buffering
+		if(p != null){
+			map.put(uuid, p);
+		}else{
+			if(map.containsKey(uuid)){
+				p = map.get(uuid);
+			}
+		}
+		return p;
+	}
+	public void reload() throws IOException{
+		this.reloadConfig();
+		loadConfig();
+	}
+	public void loadConfig() throws IOException{
+		File cfg = new File("plugins/CustomOreGen/config.yml");
+		File dir = new File("plugins/CustomOreGen/");
+		if(!dir.exists()) dir.mkdirs();
+		if(!cfg.exists()){
+			FileOutputStream writer = new FileOutputStream(new File(getDataFolder() + "/config.yml"));
+			InputStream out = this.getClassLoader().getResourceAsStream("config.yml");
+			byte[] linebuffer = new byte[4096];
+			int lineLength = 0;
+			while((lineLength = out.read(linebuffer)) > 0)
+			{
+			   writer.write(linebuffer, 0, lineLength);
+			}
+			writer.close();	
+		}
+		 
+		
+		generatorConfigs = new ArrayList<GeneratorConfig>();
+		int i = 0;
+		while(true){
+			i++;
+			if(this.getConfig().contains("generators.generator" + i)){
+				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){
+					}
+				}
+				generatorConfigs.add(gc);
+			}else{
+				break;
+			}
+			
+		}
+		//this.saveConfig();
+	}
+}

+ 10 - 0
plugin.yml

@@ -0,0 +1,10 @@
+name: CustomOreGen
+version: 1.0
+description: Controls the Ore-Generator
+author: Linus122
+soft-depends: [ASkyBlock, AcidIsland, uSkyBlock]
+main: de.Linus122.customoregen.Main
+commands:
+   customoregen:
+     description: reloads the plugin
+     usage: /CustomOreGen