Skip to content

Commit fd79ac6

Browse files
#858 Make it burn
1 parent 48fff25 commit fd79ac6

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

src/main/java/me/eccentric_nz/TARDIS/artron/ArtronPoweredRunnable.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,43 @@
44
import me.eccentric_nz.TARDIS.TARDIS;
55
import me.eccentric_nz.TARDIS.customblocks.ArtronFurnaceUtils;
66
import me.eccentric_nz.TARDIS.database.resultset.ResultSetPoweredFurnaces;
7+
import me.eccentric_nz.TARDIS.database.resultset.ResultSetTardisArtron;
78
import me.eccentric_nz.TARDIS.utility.TARDISStaticLocationGetters;
89
import org.bukkit.Location;
910
import org.bukkit.block.Furnace;
1011

1112
public class ArtronPoweredRunnable implements Runnable {
1213

1314
private final TARDIS plugin;
14-
private final int cookTime;
15+
private final Integer burnTime;
1516

1617
public ArtronPoweredRunnable(TARDIS plugin) {
1718
this.plugin = plugin;
18-
cookTime = 200 * this.plugin.getArtronConfig().getInt("artron_furnace.cook_time");
19+
burnTime = plugin.getArtronConfig().getInt("artron_furnace.power_cycle");
1920
}
2021

2122
@Override
2223
public void run() {
2324
// get all TARDIS powered furnaces
24-
// TODO there should probably be a limit per TARDIS
2525
ResultSetPoweredFurnaces rs = new ResultSetPoweredFurnaces(plugin);
2626
rs.fetchAsync((hasResult, resultSetBlocks) -> {
2727
if (hasResult) {
2828
for (Pair<String, Integer> loc : rs.getData()) {
2929
Location location = TARDISStaticLocationGetters.getLocationFromBukkitString(loc.getFirst());
30-
if (location != null && location.getBlock() instanceof Furnace furnace) {
30+
if (location != null && location.getBlock().getState() instanceof Furnace furnace) {
3131
if (plugin.getTardisHelper().isArtronFurnace(furnace.getBlock())) {
32-
// power the furnace
33-
furnace.setCookTimeTotal(cookTime);
34-
TARDISArtronFurnaceListener.setLit(furnace.getBlock(), true);
35-
// drain power from tardis
36-
ArtronFurnaceUtils.drain(loc.getSecond(), plugin);
32+
// does the TARDIS have enough power?
33+
ResultSetTardisArtron rsa = new ResultSetTardisArtron(plugin);
34+
if (rsa.fromID(loc.getSecond()) && rsa.getArtronLevel() > plugin.getArtronConfig().getInt("artron_furnace.power_drain")) {
35+
if (furnace.getInventory().getSmelting() != null) {
36+
// power the furnace
37+
furnace.setBurnTime(burnTime.shortValue());
38+
furnace.update(true);
39+
TARDISArtronFurnaceListener.setLit(furnace.getBlock(), true);
40+
// drain power from tardis
41+
ArtronFurnaceUtils.drain(loc.getSecond(), plugin);
42+
}
43+
}
3744
}
3845
}
3946
}

src/main/java/me/eccentric_nz/TARDIS/customblocks/ArtronFurnaceUtils.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package me.eccentric_nz.TARDIS.customblocks;
22

3-
import com.mojang.datafixers.util.Pair;
43
import me.eccentric_nz.TARDIS.TARDIS;
54
import me.eccentric_nz.TARDIS.database.data.Tardis;
65
import me.eccentric_nz.TARDIS.database.resultset.ResultSetArtronPowered;
@@ -10,7 +9,6 @@
109
import org.bukkit.Material;
1110
import org.bukkit.block.Block;
1211
import org.bukkit.block.BlockFace;
13-
import org.bukkit.block.Furnace;
1412
import org.bukkit.entity.ItemDisplay;
1513
import org.bukkit.entity.Player;
1614

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

31-
public static Pair<Boolean, Integer> isTARDISPowered(Furnace furnace, TARDIS plugin) {
32-
String location = furnace.getLocation().toString();
33-
ResultSetArtronPowered rs = new ResultSetArtronPowered(plugin);
34-
return rs.fromLocation(location);
35-
}
36-
37-
public static boolean isAlreadyTARDISPowered(String location, TARDIS plugin) {
29+
public static boolean isTARDISPowered(String location, TARDIS plugin) {
3830
ResultSetArtronPowered rs = new ResultSetArtronPowered(plugin);
3931
return rs.fromLocation(location).getFirst();
4032
}
@@ -74,7 +66,7 @@ public static void register(String location, Player player, TARDIS plugin) {
7466
return;
7567
}
7668
// check there is no capacitor associated with this furnace
77-
if (isAlreadyTARDISPowered(location, plugin)) {
69+
if (isTARDISPowered(location, plugin)) {
7870
plugin.getMessenger().send(player, TardisModule.TARDIS, "ENERGY_ALREADY_POWERED", "furnace");
7971
return;
8072
}
@@ -102,7 +94,7 @@ public static void removeFromCapacitor(Block block, Player player, TARDIS plugin
10294
// is there an Artron Furnace in the surrounding blocks?
10395
Block furnace = find(block, plugin);
10496
if (furnace != null) {
105-
remove(block.getLocation().toString(), player, plugin);
97+
remove(furnace.getLocation().toString(), player, plugin);
10698
}
10799
}
108100
}

src/main/java/me/eccentric_nz/TARDIS/database/resultset/ResultSetArtronPowered.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public Pair<Boolean, Integer> fromLocation(String location) {
3131
statement = connection.prepareStatement(query);
3232
statement.setString(1, location);
3333
rs = statement.executeQuery();
34-
3534
if (rs.isBeforeFirst()) {
3635
rs.next();
3736
return new Pair<>(true, rs.getInt("tardis_id"));

0 commit comments

Comments
 (0)