Remove debug printlns
All checks were successful
/ build (push) Successful in 1m2s

This commit is contained in:
Minecon724 2024-12-31 18:39:34 +01:00
parent 812b16e4be
commit 225adf0354
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
3 changed files with 28 additions and 20 deletions

View file

@ -29,7 +29,7 @@ public class RedstoneManager {
} }
public void init(PluginCommand command) { public void init(PluginCommand command) {
Store.init(plugin); RedstoneStore.init(plugin);
plugin.getServer().getPluginManager().registerEvents(new RedstoneListener(redstoneRepeaters), plugin); plugin.getServer().getPluginManager().registerEvents(new RedstoneListener(redstoneRepeaters), plugin);
command.setExecutor(new RedstoneCommands(redstoneRepeaters)); command.setExecutor(new RedstoneCommands(redstoneRepeaters));

View file

@ -8,6 +8,7 @@ package eu.m724.tweaks.redstone;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import eu.m724.tweaks.DebugLogger;
import eu.m724.tweaks.Language; import eu.m724.tweaks.Language;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -65,7 +66,7 @@ public class RedstoneRepeaters {
repeatersById.put(repeaterId, block.getLocation()); repeatersById.put(repeaterId, block.getLocation());
block.setMetadata("rid", new FixedMetadataValue(plugin, repeaterId)); 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; return repeaterId;
} }
@ -79,7 +80,7 @@ public class RedstoneRepeaters {
if (location == null) return; if (location == null) return;
repeatersByPower.remove(repeaterId); repeatersByPower.remove(repeaterId);
Store.getInstance().deleteSavedRepeaterData(location); RedstoneStore.getInstance().deleteSavedRepeaterData(location);
} }
/* Get functions */ /* Get functions */
@ -89,7 +90,7 @@ public class RedstoneRepeaters {
// if not, we're not loading because it's loaded as the block is // if not, we're not loading because it's loaded as the block is
var loc = repeatersById.get(repeaterId); var loc = repeatersById.get(repeaterId);
if (loc == null) { if (loc == null) {
System.err.println("Delete because no loc"); DebugLogger.fine("isValid: Delete because no loc");
delete(repeaterId); delete(repeaterId);
return false; return false;
} }
@ -101,6 +102,7 @@ public class RedstoneRepeaters {
// check if the block is correct type // check if the block is correct type
if (loc.getBlock().getType() != Material.DAYLIGHT_DETECTOR) { if (loc.getBlock().getType() != Material.DAYLIGHT_DETECTOR) {
DebugLogger.fine("isValid: Delete because not sensor");
delete(repeaterId); delete(repeaterId);
return false; return false;
} }
@ -108,7 +110,7 @@ public class RedstoneRepeaters {
// check if the block has the same ID bound // check if the block has the same ID bound
var meta = loc.getBlock().getMetadata("rid"); var meta = loc.getBlock().getMetadata("rid");
if (meta.isEmpty() || meta.getFirst().asInt() != repeaterId) { if (meta.isEmpty() || meta.getFirst().asInt() != repeaterId) {
System.err.println("Delete because no meta"); DebugLogger.fine("isValid: Delete because no meta");
delete(repeaterId); delete(repeaterId);
return false; return false;
} }
@ -126,7 +128,7 @@ public class RedstoneRepeaters {
if (id == null) { if (id == null) {
// not in memory, check if repeater // not in memory, check if repeater
var d = Store.getInstance().getSavedRepeaterData(block.getLocation()); var d = RedstoneStore.getInstance().getSavedRepeaterData(block.getLocation());
if (d == null) { if (d == null) {
block.setMetadata("rid", new FixedMetadataValue(plugin, Integer.MIN_VALUE)); block.setMetadata("rid", new FixedMetadataValue(plugin, Integer.MIN_VALUE));
@ -153,12 +155,13 @@ public class RedstoneRepeaters {
var storedId = location.getBlock().getMetadata("rid").getFirst().asInt(); var storedId = location.getBlock().getMetadata("rid").getFirst().asInt();
if (storedId != repeaterId) { if (storedId != repeaterId) {
System.out.println("retrieved but not exitt"); DebugLogger.fine("attempted retrieve, but doesn't exist, deleting " + repeaterId);
delete(repeaterId); delete(repeaterId);
return null; return null;
} }
System.out.println("retrieved exist " + repeaterId); DebugLogger.fine("retrieved " + repeaterId);
return location.getBlock(); 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); 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()); var power = (byte) block.getBlockPower();
return (byte) block.getBlockPower(); DebugLogger.fine("Got " + repeaterId + " receives " + power);
return power;
} }
byte getOutboundPower(int repeaterId) { byte getOutboundPower(int repeaterId) {
var block = getBlock(repeaterId); var block = getBlock(repeaterId);
if (block == null) return -1; if (block == null) return -1;
System.out.println("Okay I got out power" + repeatersByPower.get(repeaterId)); var power = repeatersByPower.getOrDefault(repeaterId, (byte) 0);
return repeatersByPower.getOrDefault(repeaterId, (byte) 0); DebugLogger.fine("Got " + repeaterId + " outputs " + power);
return power;
} }
void setPower(int repeaterId, byte power) { void setPower(int repeaterId, byte power) {
System.out.println(power);
if (power < 0 || power > 15) if (power < 0 || power > 15)
throw new IllegalArgumentException("Power should be 0-15, but is " + power); 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); 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);
} }
} }

View file

@ -7,6 +7,7 @@
package eu.m724.tweaks.redstone; package eu.m724.tweaks.redstone;
import com.google.common.primitives.Ints; import com.google.common.primitives.Ints;
import eu.m724.tweaks.DebugLogger;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -15,23 +16,23 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
public class Store { public class RedstoneStore {
private static Store INSTANCE; private static RedstoneStore INSTANCE;
private final Plugin plugin; private final Plugin plugin;
private final File directory; private final File directory;
private Store(Plugin plugin) { private RedstoneStore(Plugin plugin) {
this.plugin = plugin; this.plugin = plugin;
this.directory = new File(plugin.getDataFolder(), "storage/redstone"); this.directory = new File(plugin.getDataFolder(), "storage/redstone");
directory.mkdirs(); directory.mkdirs();
} }
static void init(Plugin plugin) { static void init(Plugin plugin) {
INSTANCE = new Store(plugin); INSTANCE = new RedstoneStore(plugin);
} }
static Store getInstance() { static RedstoneStore getInstance() {
return INSTANCE; return INSTANCE;
} }
@ -51,12 +52,13 @@ public class Store {
var repeaterId = Ints.fromByteArray(bytes) & ~0xF; var repeaterId = Ints.fromByteArray(bytes) & ~0xF;
var powerLevel = (byte) (bytes[3] & 0xF); var powerLevel = (byte) (bytes[3] & 0xF);
DebugLogger.fine("load " + location + " " + repeaterId + " " + powerLevel);
return Pair.of(repeaterId, powerLevel); return Pair.of(repeaterId, powerLevel);
} }
void saveRepeaterData(Location location, int repeaterId, byte powerLevel) { void saveRepeaterData(Location location, int repeaterId, byte powerLevel) {
var file = getFile(location); var file = getFile(location);
System.out.println(file);
byte[] bytes = Ints.toByteArray((repeaterId & ~0xF) | (powerLevel & 0xF)); byte[] bytes = Ints.toByteArray((repeaterId & ~0xF) | (powerLevel & 0xF));
try { try {
@ -64,6 +66,8 @@ public class Store {
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException("Saving repeater data", e); throw new RuntimeException("Saving repeater data", e);
} }
DebugLogger.fine("save " + location + " " + repeaterId + " " + powerLevel);
} }
void deleteSavedRepeaterData(Location location) { void deleteSavedRepeaterData(Location location) {