Skip to content

Commit

Permalink
#858 Make it burn
Browse files Browse the repository at this point in the history
  • Loading branch information
eccentricdevotion committed Jul 9, 2024
1 parent 48fff25 commit fd79ac6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,43 @@
import me.eccentric_nz.TARDIS.TARDIS;
import me.eccentric_nz.TARDIS.customblocks.ArtronFurnaceUtils;
import me.eccentric_nz.TARDIS.database.resultset.ResultSetPoweredFurnaces;
import me.eccentric_nz.TARDIS.database.resultset.ResultSetTardisArtron;
import me.eccentric_nz.TARDIS.utility.TARDISStaticLocationGetters;
import org.bukkit.Location;
import org.bukkit.block.Furnace;

public class ArtronPoweredRunnable implements Runnable {

private final TARDIS plugin;
private final int cookTime;
private final Integer burnTime;

public ArtronPoweredRunnable(TARDIS plugin) {
this.plugin = plugin;
cookTime = 200 * this.plugin.getArtronConfig().getInt("artron_furnace.cook_time");
burnTime = plugin.getArtronConfig().getInt("artron_furnace.power_cycle");
}

@Override
public void run() {
// get all TARDIS powered furnaces
// TODO there should probably be a limit per TARDIS
ResultSetPoweredFurnaces rs = new ResultSetPoweredFurnaces(plugin);
rs.fetchAsync((hasResult, resultSetBlocks) -> {
if (hasResult) {
for (Pair<String, Integer> loc : rs.getData()) {
Location location = TARDISStaticLocationGetters.getLocationFromBukkitString(loc.getFirst());
if (location != null && location.getBlock() instanceof Furnace furnace) {
if (location != null && location.getBlock().getState() instanceof Furnace furnace) {
if (plugin.getTardisHelper().isArtronFurnace(furnace.getBlock())) {
// power the furnace
furnace.setCookTimeTotal(cookTime);
TARDISArtronFurnaceListener.setLit(furnace.getBlock(), true);
// drain power from tardis
ArtronFurnaceUtils.drain(loc.getSecond(), plugin);
// does the TARDIS have enough power?
ResultSetTardisArtron rsa = new ResultSetTardisArtron(plugin);
if (rsa.fromID(loc.getSecond()) && rsa.getArtronLevel() > plugin.getArtronConfig().getInt("artron_furnace.power_drain")) {
if (furnace.getInventory().getSmelting() != null) {
// power the furnace
furnace.setBurnTime(burnTime.shortValue());
furnace.update(true);
TARDISArtronFurnaceListener.setLit(furnace.getBlock(), true);
// drain power from tardis
ArtronFurnaceUtils.drain(loc.getSecond(), plugin);
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.eccentric_nz.TARDIS.customblocks;

import com.mojang.datafixers.util.Pair;
import me.eccentric_nz.TARDIS.TARDIS;
import me.eccentric_nz.TARDIS.database.data.Tardis;
import me.eccentric_nz.TARDIS.database.resultset.ResultSetArtronPowered;
Expand All @@ -10,7 +9,6 @@
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Furnace;
import org.bukkit.entity.ItemDisplay;
import org.bukkit.entity.Player;

Expand All @@ -28,13 +26,7 @@ public static Block find(Block block, TARDIS plugin) {
return null;
}

public static Pair<Boolean, Integer> isTARDISPowered(Furnace furnace, TARDIS plugin) {
String location = furnace.getLocation().toString();
ResultSetArtronPowered rs = new ResultSetArtronPowered(plugin);
return rs.fromLocation(location);
}

public static boolean isAlreadyTARDISPowered(String location, TARDIS plugin) {
public static boolean isTARDISPowered(String location, TARDIS plugin) {
ResultSetArtronPowered rs = new ResultSetArtronPowered(plugin);
return rs.fromLocation(location).getFirst();
}
Expand Down Expand Up @@ -74,7 +66,7 @@ public static void register(String location, Player player, TARDIS plugin) {
return;
}
// check there is no capacitor associated with this furnace
if (isAlreadyTARDISPowered(location, plugin)) {
if (isTARDISPowered(location, plugin)) {
plugin.getMessenger().send(player, TardisModule.TARDIS, "ENERGY_ALREADY_POWERED", "furnace");
return;
}
Expand Down Expand Up @@ -102,7 +94,7 @@ public static void removeFromCapacitor(Block block, Player player, TARDIS plugin
// is there an Artron Furnace in the surrounding blocks?
Block furnace = find(block, plugin);
if (furnace != null) {
remove(block.getLocation().toString(), player, plugin);
remove(furnace.getLocation().toString(), player, plugin);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public Pair<Boolean, Integer> fromLocation(String location) {
statement = connection.prepareStatement(query);
statement.setString(1, location);
rs = statement.executeQuery();

if (rs.isBeforeFirst()) {
rs.next();
return new Pair<>(true, rs.getInt("tardis_id"));
Expand Down

0 comments on commit fd79ac6

Please sign in to comment.