mirror of
https://github.com/TotalFreedomMC/TF-ProjectKorra.git
synced 2025-02-11 11:40:40 +00:00
Simplification of the code
Instead of 3 if statements containing almost the same code, one switch statement and one small helper method.
This commit is contained in:
parent
65e0f0bd97
commit
1e45ff4fac
1 changed files with 17 additions and 44 deletions
|
@ -35,55 +35,28 @@ public class Extraction {
|
||||||
}
|
}
|
||||||
if (!Methods.isRegionProtectedFromBuild(player, "Extraction", block.getLocation())) {
|
if (!Methods.isRegionProtectedFromBuild(player, "Extraction", block.getLocation())) {
|
||||||
if (Methods.canMetalbend(player) && Methods.canBend(player.getName(), "Extraction")) {
|
if (Methods.canMetalbend(player) && Methods.canBend(player.getName(), "Extraction")) {
|
||||||
|
switch(block.getType()) {
|
||||||
|
case IRON_ORE:
|
||||||
|
block.setType(Material.STONE);
|
||||||
|
player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.IRON_INGOT, getAmount());
|
||||||
|
break;
|
||||||
|
case GOLD_ORE:
|
||||||
|
block.setType(Material.STONE);
|
||||||
|
player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.GOLD_INGOT, getAmount());
|
||||||
|
break;
|
||||||
|
case QUARTZ_ORE:
|
||||||
|
block.setType(Material.NETHERRACK);
|
||||||
|
player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.QUARTZ, getAmount());
|
||||||
|
break;
|
||||||
|
case default:
|
||||||
|
break;//shouldn't happen
|
||||||
|
}
|
||||||
|
cooldowns.put(player.getName(), System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getAmount() {
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
if (rand.nextInt(99) + 1 <= triplechance) {
|
return rand.nextInt(99) + 1 <= triplechance ? 3 : rand.nextInt(99) + 1 <= doublechance ? 2: 0;
|
||||||
if (block.getType() == Material.IRON_ORE) {
|
|
||||||
block.setType(Material.STONE);
|
|
||||||
player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.IRON_INGOT, 3));
|
|
||||||
}
|
|
||||||
if (block.getType() == Material.GOLD_ORE){
|
|
||||||
block.setType(Material.STONE);
|
|
||||||
player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.GOLD_INGOT, 3));
|
|
||||||
}
|
|
||||||
if (block.getType() == Material.QUARTZ_ORE) {
|
|
||||||
block.setType(Material.NETHERRACK);
|
|
||||||
player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.QUARTZ, 3));
|
|
||||||
}
|
|
||||||
cooldowns.put(player.getName(), System.currentTimeMillis());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (rand.nextInt(99) + 1 <= doublechance) {
|
|
||||||
if (block.getType() == Material.IRON_ORE) {
|
|
||||||
block.setType(Material.STONE);
|
|
||||||
player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.IRON_INGOT, 2));
|
|
||||||
}
|
|
||||||
if (block.getType() == Material.GOLD_ORE){
|
|
||||||
block.setType(Material.STONE);
|
|
||||||
player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.GOLD_INGOT, 2));
|
|
||||||
}
|
|
||||||
if (block.getType() == Material.QUARTZ_ORE) {
|
|
||||||
block.setType(Material.NETHERRACK);
|
|
||||||
player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.QUARTZ, 2));
|
|
||||||
}
|
|
||||||
cooldowns.put(player.getName(), System.currentTimeMillis());
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
if (block.getType() == Material.IRON_ORE) {
|
|
||||||
block.setType(Material.STONE);
|
|
||||||
player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.IRON_INGOT));
|
|
||||||
}
|
|
||||||
if (block.getType() == Material.GOLD_ORE){
|
|
||||||
block.setType(Material.STONE);
|
|
||||||
player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.GOLD_INGOT));
|
|
||||||
}
|
|
||||||
if (block.getType() == Material.QUARTZ_ORE) {
|
|
||||||
block.setType(Material.NETHERRACK);
|
|
||||||
player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.QUARTZ));
|
|
||||||
}
|
|
||||||
cooldowns.put(player.getName(), System.currentTimeMillis());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue