mirror of
https://github.com/songoda/EpicFurnaces.git
synced 2025-03-14 07:29:11 +01:00
Reorganized furnace level logic & General Cleanup.
This commit is contained in:
parent
c4391af34c
commit
6caafe5892
@ -25,7 +25,7 @@ import com.craftaro.epicfurnaces.database.migrations._1_InitialMigration;
|
||||
import com.craftaro.epicfurnaces.furnace.Furnace;
|
||||
import com.craftaro.epicfurnaces.furnace.FurnaceBuilder;
|
||||
import com.craftaro.epicfurnaces.furnace.FurnaceManager;
|
||||
import com.craftaro.epicfurnaces.furnace.levels.LevelManager;
|
||||
import com.craftaro.epicfurnaces.level.LevelManager;
|
||||
import com.craftaro.epicfurnaces.handlers.BlacklistHandler;
|
||||
import com.craftaro.epicfurnaces.listeners.BlockListeners;
|
||||
import com.craftaro.epicfurnaces.listeners.EntityListeners;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.craftaro.epicfurnaces.commands;
|
||||
|
||||
import com.craftaro.core.commands.AbstractCommand;
|
||||
import com.craftaro.epicfurnaces.furnace.levels.Level;
|
||||
import com.craftaro.epicfurnaces.level.Level;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
|
@ -11,7 +11,7 @@ import com.craftaro.core.math.MathUtils;
|
||||
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.third_party.com.cryptomorin.xseries.XSound;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
import com.craftaro.epicfurnaces.furnace.levels.Level;
|
||||
import com.craftaro.epicfurnaces.level.Level;
|
||||
import com.craftaro.epicfurnaces.settings.Settings;
|
||||
import com.craftaro.epicfurnaces.boost.BoostData;
|
||||
import com.craftaro.epicfurnaces.gui.GUIOverview;
|
||||
@ -116,25 +116,10 @@ public class Furnace implements Data {
|
||||
}
|
||||
|
||||
|
||||
if (this.level.getReward() == null) {
|
||||
if (this.level.getReward() == null)
|
||||
return;
|
||||
}
|
||||
|
||||
String reward = this.level.getReward();
|
||||
int min = 1;
|
||||
int max = 1;
|
||||
if (reward.contains(":")) {
|
||||
String[] rewardSplit = reward.split(":");
|
||||
reward = rewardSplit[0].substring(0, rewardSplit[0].length() - 1);
|
||||
if (rewardSplit[1].contains("-")) {
|
||||
String[] split = rewardSplit[1].split("-");
|
||||
min = Integer.parseInt(split[0]);
|
||||
max = Integer.parseInt(split[1]);
|
||||
} else {
|
||||
min = Integer.parseInt(rewardSplit[1]);
|
||||
max = min;
|
||||
}
|
||||
}
|
||||
|
||||
if (Settings.UPGRADE_BY_SMELTING.getBoolean() &&
|
||||
needed == 0 &&
|
||||
@ -162,7 +147,7 @@ public class Furnace implements Data {
|
||||
return;
|
||||
}
|
||||
|
||||
int randomAmount = min == max ? min : (int) (Math.random() * ((max - min) + 1)) + min;
|
||||
int randomAmount = level.getRandomReward();
|
||||
|
||||
BoostData boostData = this.plugin.getBoostManager().getBoost(this.placedBy);
|
||||
randomAmount = randomAmount * (boostData == null ? 1 : boostData.getMultiplier());
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.craftaro.epicfurnaces.furnace;
|
||||
|
||||
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.epicfurnaces.furnace.levels.Level;
|
||||
import com.craftaro.epicfurnaces.level.Level;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -11,7 +11,7 @@ import com.craftaro.core.utils.TimeUtils;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
import com.craftaro.epicfurnaces.boost.BoostData;
|
||||
import com.craftaro.epicfurnaces.furnace.Furnace;
|
||||
import com.craftaro.epicfurnaces.furnace.levels.Level;
|
||||
import com.craftaro.epicfurnaces.level.Level;
|
||||
import com.craftaro.epicfurnaces.settings.Settings;
|
||||
import com.craftaro.epicfurnaces.utils.CostType;
|
||||
import com.craftaro.epicfurnaces.utils.Methods;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.craftaro.epicfurnaces.furnace.levels;
|
||||
package com.craftaro.epicfurnaces.level;
|
||||
|
||||
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
@ -9,6 +9,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Level {
|
||||
|
||||
private final int level;
|
||||
private final int costExperience;
|
||||
private final int costEconomy;
|
||||
@ -19,7 +20,8 @@ public class Level {
|
||||
|
||||
private Map<XMaterial, Integer> materials;
|
||||
|
||||
private final String reward;
|
||||
private final String rewardRaw;
|
||||
private final int rewardMin, rewardMax;
|
||||
|
||||
private final List<String> description = new ArrayList<>();
|
||||
|
||||
@ -28,7 +30,6 @@ public class Level {
|
||||
this.costExperience = costExperience;
|
||||
this.costEconomy = costEconomy;
|
||||
this.performance = performance;
|
||||
this.reward = reward;
|
||||
this.fuelDuration = fuelDuration;
|
||||
this.overheat = overheat;
|
||||
this.fuelShare = fuelShare;
|
||||
@ -70,6 +71,22 @@ public class Level {
|
||||
.processPlaceholder("amount", overheat)
|
||||
.getMessage());
|
||||
}
|
||||
|
||||
rewardRaw = reward;
|
||||
if (reward.contains(":")) { // Optionally this can be multiple values.
|
||||
String[] rewardSplit = reward.split(":");
|
||||
reward = rewardSplit[0].substring(0, rewardSplit[0].length() - 1);
|
||||
if (rewardSplit[1].contains("-")) {
|
||||
String[] split = rewardSplit[1].split("-");
|
||||
rewardMin = Integer.parseInt(split[0]);
|
||||
rewardMax = Integer.parseInt(split[1]);
|
||||
} else {
|
||||
rewardMin = Integer.parseInt(rewardSplit[1]);
|
||||
rewardMax = rewardMin;
|
||||
}
|
||||
} else {
|
||||
rewardMin =
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -120,4 +137,8 @@ public class Level {
|
||||
public Map<XMaterial, Integer> getMaterials() {
|
||||
return Collections.unmodifiableMap(this.materials);
|
||||
}
|
||||
|
||||
public int getRandomReward() {
|
||||
return rewardMin == rewardMax ? rewardMin : (int) (Math.random() * ((rewardMax - rewardMin) + 1)) + rewardMin;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.craftaro.epicfurnaces.furnace.levels;
|
||||
package com.craftaro.epicfurnaces.level;
|
||||
|
||||
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
|
@ -2,7 +2,8 @@ package com.craftaro.epicfurnaces.listeners;
|
||||
|
||||
import com.craftaro.epicfurnaces.EpicFurnaces;
|
||||
import com.craftaro.epicfurnaces.furnace.Furnace;
|
||||
import com.craftaro.epicfurnaces.furnace.levels.Level;
|
||||
import com.craftaro.epicfurnaces.level.Level;
|
||||
import com.craftaro.epicfurnaces.settings.Settings;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -19,15 +20,15 @@ public class FurnaceListeners implements Listener {
|
||||
@EventHandler
|
||||
public void onCook(FurnaceSmeltEvent event) {
|
||||
Block block = event.getBlock();
|
||||
if ((event.getBlock().isBlockPowered() && this.plugin.getConfig().getBoolean("Main.Redstone Deactivates Furnaces")) || event.getResult() == null) {
|
||||
if (event.getBlock().isBlockPowered() && Settings.REDSTONE_DEACTIVATES.getBoolean()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Furnace furnace = this.plugin.getFurnaceManager().getFurnace(block.getLocation());
|
||||
|
||||
if (furnace != null) {
|
||||
if (furnace != null)
|
||||
furnace.plus(event);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -18,20 +18,18 @@ public class FurnaceTask extends BukkitRunnable {
|
||||
private static FurnaceTask instance;
|
||||
|
||||
private final EpicFurnaces plugin;
|
||||
final HashSet<Location> toRemove = new HashSet<>();
|
||||
boolean doParticles;
|
||||
private final HashSet<Location> toRemove = new HashSet<>();
|
||||
private boolean doParticles;
|
||||
|
||||
private FurnaceTask(EpicFurnaces plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public static FurnaceTask startTask(EpicFurnaces plugin) {
|
||||
public static void startTask(EpicFurnaces plugin) {
|
||||
if (instance == null) {
|
||||
instance = new FurnaceTask(plugin);
|
||||
instance.runTaskTimer(plugin, 0, Settings.TICK_SPEED.getInt());
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -50,7 +48,7 @@ public class FurnaceTask extends BukkitRunnable {
|
||||
overheat(furnace);
|
||||
}
|
||||
if (furnace.getLevel().getFuelShare() != 0) {
|
||||
fuelshare(furnace);
|
||||
fuelShare(furnace);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -68,14 +66,12 @@ public class FurnaceTask extends BukkitRunnable {
|
||||
|
||||
for (Location location : furnace.getRadius(true)) {
|
||||
int random = ThreadLocalRandom.current().nextInt(0, 10);
|
||||
if (random != 1) {
|
||||
if (random != 1)
|
||||
continue;
|
||||
}
|
||||
|
||||
Block block = location.getBlock();
|
||||
if (block.getType() == Material.AIR || block.getRelative(BlockFace.UP).getType() != Material.AIR) {
|
||||
if (block.getType() == Material.AIR || block.getRelative(BlockFace.UP).getType() != Material.AIR)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (block.getType() == Material.SNOW) {
|
||||
block.setType(Material.AIR);
|
||||
@ -94,7 +90,7 @@ public class FurnaceTask extends BukkitRunnable {
|
||||
}
|
||||
}
|
||||
|
||||
private void fuelshare(Furnace furnace) {
|
||||
private void fuelShare(Furnace furnace) {
|
||||
if (furnace.getRadius(false) == null || furnace.getRadiusLast(false) != furnace.getLevel().getOverheat()) {
|
||||
furnace.setRadiusLast(furnace.getLevel().getOverheat(), false);
|
||||
cache(furnace, false);
|
||||
@ -103,19 +99,17 @@ public class FurnaceTask extends BukkitRunnable {
|
||||
for (Location location : furnace.getRadius(false)) {
|
||||
int random = ThreadLocalRandom.current().nextInt(0, 10);
|
||||
|
||||
if (random != 1) {
|
||||
if (random != 1)
|
||||
continue;
|
||||
}
|
||||
|
||||
Block block = location.getBlock();
|
||||
|
||||
if (!block.getType().name().contains("FURNACE") && !block.getType().name().contains("SMOKER")) {
|
||||
if (!block.getType().name().contains("FURNACE") && !block.getType().name().contains("SMOKER"))
|
||||
continue;
|
||||
}
|
||||
Furnace furnace1 = this.plugin.getFurnaceManager().getFurnace(block);
|
||||
if (furnace == furnace1) {
|
||||
if (furnace == furnace1)
|
||||
continue;
|
||||
}
|
||||
|
||||
org.bukkit.block.Furnace furnaceBlock = ((org.bukkit.block.Furnace) block.getState());
|
||||
if (furnaceBlock.getBurnTime() == 0) {
|
||||
furnaceBlock.setBurnTime((short) 100);
|
||||
@ -140,15 +134,12 @@ public class FurnaceTask extends BukkitRunnable {
|
||||
int by = block.getY();
|
||||
int bz = block.getZ();
|
||||
|
||||
for (int fx = -radius; fx <= radius; fx++) {
|
||||
for (int fy = -2; fy <= 1; fy++) {
|
||||
for (int fz = -radius; fz <= radius; fz++) {
|
||||
for (int fx = -radius; fx <= radius; fx++)
|
||||
for (int fy = -2; fy <= 1; fy++)
|
||||
for (int fz = -radius; fz <= radius; fz++)
|
||||
if ((fx * fx) + (fz * fz) <= rSquared) {
|
||||
Location location = new Location(block.getWorld(), bx + fx, by + fy, bz + fz);
|
||||
furnace.addToRadius(location, overheat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user