Added support for decimals in the generator.

This commit is contained in:
Brianna O'Keefe 2019-01-24 20:26:08 -05:00
parent 4bebce5016
commit 6a6e9aeff1
4 changed files with 186 additions and 193 deletions

View File

@ -1,13 +1,10 @@
package me.goodandevil.skyblock.generator;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import me.goodandevil.skyblock.SkyBlock;
import me.goodandevil.skyblock.config.FileManager.Config;
import me.goodandevil.skyblock.utils.version.Materials;
import me.goodandevil.skyblock.utils.version.NMSUtil;
import me.goodandevil.skyblock.utils.version.Sounds;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
@ -17,11 +14,9 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import me.goodandevil.skyblock.SkyBlock;
import me.goodandevil.skyblock.config.FileManager.Config;
import me.goodandevil.skyblock.utils.version.Materials;
import me.goodandevil.skyblock.utils.version.NMSUtil;
import me.goodandevil.skyblock.utils.version.Sounds;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
public class GeneratorManager {
@ -37,13 +32,14 @@ public class GeneratorManager {
Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "generators.yml"));
FileConfiguration configLoad = config.getFileConfiguration();
if (configLoad.getString("Generators") != null) {
Materials[] oreMaterials = new Materials[] { Materials.COAL, Materials.CHARCOAL, Materials.DIAMOND,
Materials.IRON_INGOT, Materials.GOLD_INGOT, Materials.EMERALD };
if (configLoad.getString("Generators") == null) return;
Materials[] oreMaterials = new Materials[]{Materials.COAL, Materials.CHARCOAL, Materials.DIAMOND,
Materials.IRON_INGOT, Materials.GOLD_INGOT, Materials.EMERALD};
Random rnd = new Random();
for (String generatorList : configLoad.getConfigurationSection("Generators").getKeys(false)) {
if (configLoad.getString("Generators." + generatorList + ".Name") != null) {
if (configLoad.getString("Generators." + generatorList + ".Name") == null) continue;
List<GeneratorMaterial> generatorMaterials = new ArrayList<>();
if (configLoad.getString("Generators." + generatorList + ".Materials") != null) {
@ -63,42 +59,40 @@ public class GeneratorManager {
configLoad.getBoolean("Generators." + generatorList + ".Permission")));
}
}
}
}
public void unregisterGenerators() {
generatorStorage.clear();
}
private boolean isFlowingTowardsBlock(Block from){
if(!from.isLiquid())
private boolean isFlowingTowardsBlock(Block from) {
if (!from.isLiquid())
return false;
if(isWater(from) && isFlowingBlock(from))
if (isWater(from) && isFlowingBlock(from))
return true;
return false;
}
private boolean isLava(Block block){
private boolean isLava(Block block) {
return block.getType().equals(Materials.LAVA.parseMaterial()) || block.getType().equals(Materials.LEGACY_STATIONARY_LAVA.parseMaterial());
}
private boolean isWater(Block block){
private boolean isWater(Block block) {
return block.getType().equals(Materials.WATER.parseMaterial()) || block.getType().equals(Materials.LEGACY_STATIONARY_WATER.parseMaterial());
}
public boolean isGenerator(Block block) {
BlockFace[] blockFaces = new BlockFace[]{BlockFace.UP, BlockFace.DOWN, BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST};
for(BlockFace blockFace1 : blockFaces){
for(BlockFace blockFace2 : blockFaces){
if(blockFace1.equals(blockFace2))
for (BlockFace blockFace1 : blockFaces) {
for (BlockFace blockFace2 : blockFaces) {
if (blockFace1.equals(blockFace2))
continue;
Block from1 = block.getRelative(blockFace1);
Block from2 = block.getRelative(blockFace2);
if(isLava(from1) && isWater(from2) && isFlowingTowardsBlock(from2))
if (isLava(from1) && isWater(from2) && isFlowingTowardsBlock(from2))
return true;
}
}
@ -223,12 +217,11 @@ public class GeneratorManager {
}
@SuppressWarnings("deprecation")
private int getLiquidLevel(Block block){
private int getLiquidLevel(Block block) {
if (NMSUtil.getVersionNumber() > 12 && block.getState().getBlockData() instanceof Levelled) {
Levelled levelled = (Levelled) block.getState().getBlockData();
return levelled.getLevel();
}
else {
} else {
return block.getData();
}
}
@ -319,8 +312,8 @@ public class GeneratorManager {
}
public void addGenerator(String name, List<GeneratorMaterial> generatorMaterials, boolean permission) {
Materials[] oreMaterials = new Materials[] { Materials.COAL, Materials.CHARCOAL, Materials.DIAMOND,
Materials.IRON_INGOT, Materials.GOLD_INGOT, Materials.EMERALD };
Materials[] oreMaterials = new Materials[]{Materials.COAL, Materials.CHARCOAL, Materials.DIAMOND,
Materials.IRON_INGOT, Materials.GOLD_INGOT, Materials.EMERALD};
generatorStorage.add(new Generator(name, oreMaterials[new Random().nextInt(oreMaterials.length)],
generatorMaterials, permission));
}

View File

@ -5,7 +5,7 @@ import me.goodandevil.skyblock.utils.version.Materials;
public class GeneratorMaterial {
private Materials materials;
private int chance;
private double chance;
public GeneratorMaterial(Materials materials, int chance) {
this.materials = materials;
@ -16,11 +16,11 @@ public class GeneratorMaterial {
return materials;
}
public int getChance() {
public double getChance() {
return chance;
}
public void setChance(int chance) {
public void setChance(double chance) {
this.chance = chance;
}
}

View File

@ -502,7 +502,7 @@ public class Generator implements Listener {
1.0F, 1.0F);
} else {
int materialChance = Integer.valueOf(event1.getName());
int totalMaterialChance = materialChance;
double totalMaterialChance = materialChance;
for (GeneratorMaterial generatorMaterialList1 : generator
.getGeneratorMaterials()) {

View File

@ -6,12 +6,12 @@ Generators:
COBBLESTONE:
Chance: 60
COAL_ORE:
Chance: 15
Chance: 14.5
IRON_ORE:
Chance: 10
Chance: 9.5
GOLD_ORE:
Chance: 8
EMERALD_ORE:
Chance: 5
Chance: 5.5
DIAMOND_ORE:
Chance: 2
Chance: 2.5