diff --git a/src/main/java/eu/m724/tweaks/redstone/RedstoneManager.java b/src/main/java/eu/m724/tweaks/redstone/RedstoneManager.java index d4491d5..437dfc1 100644 --- a/src/main/java/eu/m724/tweaks/redstone/RedstoneManager.java +++ b/src/main/java/eu/m724/tweaks/redstone/RedstoneManager.java @@ -29,7 +29,7 @@ public class RedstoneManager { } public void init(PluginCommand command) { - Store.init(plugin); + RedstoneStore.init(plugin); plugin.getServer().getPluginManager().registerEvents(new RedstoneListener(redstoneRepeaters), plugin); command.setExecutor(new RedstoneCommands(redstoneRepeaters)); diff --git a/src/main/java/eu/m724/tweaks/redstone/RedstoneRepeaters.java b/src/main/java/eu/m724/tweaks/redstone/RedstoneRepeaters.java index 77b1a77..c554379 100644 --- a/src/main/java/eu/m724/tweaks/redstone/RedstoneRepeaters.java +++ b/src/main/java/eu/m724/tweaks/redstone/RedstoneRepeaters.java @@ -8,6 +8,7 @@ package eu.m724.tweaks.redstone; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; +import eu.m724.tweaks.DebugLogger; import eu.m724.tweaks.Language; import org.bukkit.Location; import org.bukkit.Material; @@ -65,7 +66,7 @@ public class RedstoneRepeaters { repeatersById.put(repeaterId, block.getLocation()); block.setMetadata("rid", new FixedMetadataValue(plugin, repeaterId)); - Store.getInstance().saveRepeaterData(block.getLocation(), repeaterId, (byte) 0); + RedstoneStore.getInstance().saveRepeaterData(block.getLocation(), repeaterId, (byte) 0); return repeaterId; } @@ -79,7 +80,7 @@ public class RedstoneRepeaters { if (location == null) return; repeatersByPower.remove(repeaterId); - Store.getInstance().deleteSavedRepeaterData(location); + RedstoneStore.getInstance().deleteSavedRepeaterData(location); } /* Get functions */ @@ -89,7 +90,7 @@ public class RedstoneRepeaters { // if not, we're not loading because it's loaded as the block is var loc = repeatersById.get(repeaterId); if (loc == null) { - System.err.println("Delete because no loc"); + DebugLogger.fine("isValid: Delete because no loc"); delete(repeaterId); return false; } @@ -101,6 +102,7 @@ public class RedstoneRepeaters { // check if the block is correct type if (loc.getBlock().getType() != Material.DAYLIGHT_DETECTOR) { + DebugLogger.fine("isValid: Delete because not sensor"); delete(repeaterId); return false; } @@ -108,7 +110,7 @@ public class RedstoneRepeaters { // check if the block has the same ID bound var meta = loc.getBlock().getMetadata("rid"); if (meta.isEmpty() || meta.getFirst().asInt() != repeaterId) { - System.err.println("Delete because no meta"); + DebugLogger.fine("isValid: Delete because no meta"); delete(repeaterId); return false; } @@ -126,7 +128,7 @@ public class RedstoneRepeaters { if (id == null) { // not in memory, check if repeater - var d = Store.getInstance().getSavedRepeaterData(block.getLocation()); + var d = RedstoneStore.getInstance().getSavedRepeaterData(block.getLocation()); if (d == null) { block.setMetadata("rid", new FixedMetadataValue(plugin, Integer.MIN_VALUE)); @@ -153,12 +155,13 @@ public class RedstoneRepeaters { var storedId = location.getBlock().getMetadata("rid").getFirst().asInt(); if (storedId != repeaterId) { - System.out.println("retrieved but not exitt"); + DebugLogger.fine("attempted retrieve, but doesn't exist, deleting " + repeaterId); delete(repeaterId); return null; } - System.out.println("retrieved exist " + repeaterId); + DebugLogger.fine("retrieved " + repeaterId); + return location.getBlock(); } @@ -170,20 +173,21 @@ public class RedstoneRepeaters { block.getWorld().spawnParticle(Particle.LAVA, block.getLocation().add(0.5, 0.5, 0.5), 3); - System.out.println("Okay I got in power" + block.getBlockPower()); - return (byte) block.getBlockPower(); + var power = (byte) block.getBlockPower(); + DebugLogger.fine("Got " + repeaterId + " receives " + power); + return power; } byte getOutboundPower(int repeaterId) { var block = getBlock(repeaterId); if (block == null) return -1; - System.out.println("Okay I got out power" + repeatersByPower.get(repeaterId)); - return repeatersByPower.getOrDefault(repeaterId, (byte) 0); + var power = repeatersByPower.getOrDefault(repeaterId, (byte) 0); + DebugLogger.fine("Got " + repeaterId + " outputs " + power); + return power; } void setPower(int repeaterId, byte power) { - System.out.println(power); if (power < 0 || power > 15) throw new IllegalArgumentException("Power should be 0-15, but is " + power); @@ -197,6 +201,6 @@ public class RedstoneRepeaters { block.getWorld().spawnParticle(Particle.LAVA, block.getLocation().add(0.5, 0.5, 0.5), 3); - System.out.println("Okay I set power"); + DebugLogger.fine("Set power of " + repeaterId + " to " + power); } } \ No newline at end of file diff --git a/src/main/java/eu/m724/tweaks/redstone/Store.java b/src/main/java/eu/m724/tweaks/redstone/RedstoneStore.java similarity index 82% rename from src/main/java/eu/m724/tweaks/redstone/Store.java rename to src/main/java/eu/m724/tweaks/redstone/RedstoneStore.java index d9d8ff8..cd24665 100644 --- a/src/main/java/eu/m724/tweaks/redstone/Store.java +++ b/src/main/java/eu/m724/tweaks/redstone/RedstoneStore.java @@ -7,6 +7,7 @@ package eu.m724.tweaks.redstone; import com.google.common.primitives.Ints; +import eu.m724.tweaks.DebugLogger; import org.apache.commons.lang3.tuple.Pair; import org.bukkit.Location; import org.bukkit.plugin.Plugin; @@ -15,23 +16,23 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; -public class Store { - private static Store INSTANCE; +public class RedstoneStore { + private static RedstoneStore INSTANCE; private final Plugin plugin; private final File directory; - private Store(Plugin plugin) { + private RedstoneStore(Plugin plugin) { this.plugin = plugin; this.directory = new File(plugin.getDataFolder(), "storage/redstone"); directory.mkdirs(); } static void init(Plugin plugin) { - INSTANCE = new Store(plugin); + INSTANCE = new RedstoneStore(plugin); } - static Store getInstance() { + static RedstoneStore getInstance() { return INSTANCE; } @@ -51,12 +52,13 @@ public class Store { var repeaterId = Ints.fromByteArray(bytes) & ~0xF; var powerLevel = (byte) (bytes[3] & 0xF); + DebugLogger.fine("load " + location + " " + repeaterId + " " + powerLevel); + return Pair.of(repeaterId, powerLevel); } void saveRepeaterData(Location location, int repeaterId, byte powerLevel) { var file = getFile(location); - System.out.println(file); byte[] bytes = Ints.toByteArray((repeaterId & ~0xF) | (powerLevel & 0xF)); try { @@ -64,6 +66,8 @@ public class Store { } catch (IOException e) { throw new RuntimeException("Saving repeater data", e); } + + DebugLogger.fine("save " + location + " " + repeaterId + " " + powerLevel); } void deleteSavedRepeaterData(Location location) {