diff --git a/build.gradle b/build.gradle index 691b1d3..ad895d5 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,9 @@ buildscript { dependencies { classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT' classpath 'org.spongepowered:spongegradle:0.8.2-SNAPSHOT' - classpath 'org.spongepowered:event-impl-gen:5.2.0-SNAPSHOT' + classpath 'org.spongepowered:event-impl-gen:5.1.0-SNAPSHOT' + //classpath 'gradle.plugin.org.spongepowered:event-impl-gen:5.0.2' + //classpath 'gradle.plugin.org.spongepowered:event-impl-gen:5.1.0-SNAPSHOT' classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3' } } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index fbae4b4..d8ea031 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 95a46c8..0cd056e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -#Sun May 27 00:37:29 PDT 2018 +#Wed May 30 12:43:00 PDT 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/FoxGuardMain.java b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/FoxGuardMain.java index 54171d7..847b126 100644 --- a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/FoxGuardMain.java +++ b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/FoxGuardMain.java @@ -50,6 +50,7 @@ import net.foxdenstudio.sponge.foxguard.plugin.state.factory.ControllersStateFieldFactory; import net.foxdenstudio.sponge.foxguard.plugin.state.factory.HandlersStateFieldFactory; import net.foxdenstudio.sponge.foxguard.plugin.state.factory.RegionsStateFieldFactory; +import net.foxdenstudio.sponge.foxguard.plugin.util.DebugManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spongepowered.api.Game; @@ -64,7 +65,6 @@ import org.spongepowered.api.event.cause.EventContext; import org.spongepowered.api.event.entity.DamageEntityEvent; import org.spongepowered.api.event.entity.InteractEntityEvent; -import org.spongepowered.api.event.entity.MoveEntityEvent; import org.spongepowered.api.event.entity.SpawnEntityEvent; import org.spongepowered.api.event.game.state.*; import org.spongepowered.api.event.world.ExplosionEvent; @@ -242,9 +242,14 @@ public void registerCommands(GameInitializationEvent event) { fgDispatcher.register(new CommandPriority(), "priority", "prio", "level", "rank"); - fgDispatcher.register(new CommandTest(), "test"); fgDispatcher.register(new CommandLink2(true), "link2", "connect2", "attach2"); fgDispatcher.register(new CommandLink2(false), "unlink2", "disconnect2", "detach2"); + + // DEBUG USE + //fgDispatcher.register(new CommandTest(), "test"); + //fgDispatcher.register(DebugManager.INSTANCE, "debug"); + + registerCoreCommands(fgDispatcher); game.getCommandManager().register(this, fgDispatcher, "foxguard", "foxg", "fguard", "fg"); diff --git a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/command/CommandHere.java b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/command/CommandHere.java index 87b53b2..3e229eb 100644 --- a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/command/CommandHere.java +++ b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/command/CommandHere.java @@ -35,7 +35,7 @@ import net.foxdenstudio.sponge.foxguard.plugin.FGManager; import net.foxdenstudio.sponge.foxguard.plugin.controller.IController; import net.foxdenstudio.sponge.foxguard.plugin.handler.IHandler; -import net.foxdenstudio.sponge.foxguard.plugin.listener.PlayerMoveListenerNew; +import net.foxdenstudio.sponge.foxguard.plugin.listener.PlayerMoveListener; import net.foxdenstudio.sponge.foxguard.plugin.region.IRegion; import net.foxdenstudio.sponge.foxguard.plugin.util.FGUtil; import org.spongepowered.api.Sponge; @@ -85,7 +85,7 @@ public CommandResult process(CommandSource source, String arguments) throws Comm } AdvCmdParser.ParseResult parse = AdvCmdParser.builder().arguments(arguments).flagMapper(MAPPER).parse(); boolean hud = false; - PlayerMoveListenerNew.HUDConfig hudConfig = new PlayerMoveListenerNew.HUDConfig(false, false, false); + PlayerMoveListener.HUDConfig hudConfig = new PlayerMoveListener.HUDConfig(false, false, false); String worldName = parse.flags.get("world"); World world = null; @@ -239,7 +239,7 @@ public CommandResult process(CommandSource source, String arguments) throws Comm if (hud) { Player player = (Player) source; if (CommandHUD.instance().getIsHUDEnabled().get(player)) { - PlayerMoveListenerNew instance = PlayerMoveListenerNew.getInstance(); + PlayerMoveListener instance = PlayerMoveListener.getInstance(); instance.getHudConfigMap().put(player, hudConfig); instance.renderHUD(player, regionList, handlerList, hudConfig); instance.showScoreboard(player); diff --git a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/config/ListenerModule.java b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/config/ListenerModule.java index 0f8d2c2..fe0bf35 100644 --- a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/config/ListenerModule.java +++ b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/config/ListenerModule.java @@ -1,7 +1,7 @@ package net.foxdenstudio.sponge.foxguard.plugin.config; import net.foxdenstudio.sponge.foxguard.plugin.FoxGuardMain; -import net.foxdenstudio.sponge.foxguard.plugin.listener.PlayerMoveListenerNew; +import net.foxdenstudio.sponge.foxguard.plugin.listener.PlayerMoveListener; import org.spongepowered.api.event.entity.MoveEntityEvent; import javax.annotation.Nonnull; @@ -25,7 +25,7 @@ public String setup(String setting) { setting = getDefaultValue(); full = true; } - PlayerMoveListenerNew pml = new PlayerMoveListenerNew(true); + PlayerMoveListener pml = new PlayerMoveListener(true); plugin.registerListener(MoveEntityEvent.class, pml); //plugin.registerListeners(pml.new Listeners()); return setting; diff --git a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/BlockChangeListener.java b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/BlockChangeListener.java index 28701ad..ae7647e 100644 --- a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/BlockChangeListener.java +++ b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/BlockChangeListener.java @@ -31,6 +31,7 @@ import net.foxdenstudio.sponge.foxguard.plugin.flag.FlagSet; import net.foxdenstudio.sponge.foxguard.plugin.handler.IHandler; import net.foxdenstudio.sponge.foxguard.plugin.object.IFGObject; +import net.foxdenstudio.sponge.foxguard.plugin.util.DebugManager; import net.foxdenstudio.sponge.foxguard.plugin.util.ExtraContext; import net.foxdenstudio.sponge.foxguard.plugin.util.FGUtil; import org.spongepowered.api.block.BlockSnapshot; @@ -67,6 +68,9 @@ public void handle(ChangeBlockEvent event) throws Exception { || tr.getOriginal().getState().getType().equals(BlockTypes.GRASS) && tr.getFinal().getState().getType().equals(BlockTypes.DIRT)) return; } + + DebugManager.INSTANCE.printEvent(event); + //DebugHelper.printBlockEvent(event); /*FlagOld typeFlag; if (event instanceof ChangeBlockEvent.Modify) typeFlag = FlagOld.BLOCK_MODIFY; @@ -105,6 +109,7 @@ public void handle(ChangeBlockEvent event) throws Exception { } if(handlerSet.size() == 0) return; + User user; if (event.getCause().containsType(Player.class)) { user = event.getCause().first(Player.class).get(); @@ -114,6 +119,8 @@ public void handle(ChangeBlockEvent event) throws Exception { user = null; } + + boolean[] flags = BASE_FLAG_SET.clone(); if (event instanceof ChangeBlockEvent.Modify) flags[MODIFY.id] = true; diff --git a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/InteractEntityListener.java b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/InteractEntityListener.java index 0e70da3..be2d6d5 100644 --- a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/InteractEntityListener.java +++ b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/InteractEntityListener.java @@ -26,10 +26,12 @@ package net.foxdenstudio.sponge.foxguard.plugin.listener; import com.flowpowered.math.vector.Vector3d; +import com.google.common.collect.ImmutableList; import net.foxdenstudio.sponge.foxguard.plugin.FGManager; import net.foxdenstudio.sponge.foxguard.plugin.FoxGuardMain; import net.foxdenstudio.sponge.foxguard.plugin.flag.FlagSet; import net.foxdenstudio.sponge.foxguard.plugin.handler.IHandler; +import net.foxdenstudio.sponge.foxguard.plugin.listener.util.EntityFlagCalculator; import net.foxdenstudio.sponge.foxguard.plugin.listener.util.FGListenerUtil; import net.foxdenstudio.sponge.foxguard.plugin.object.IFGObject; import net.foxdenstudio.sponge.foxguard.plugin.util.ExtraContext; @@ -51,6 +53,7 @@ public class InteractEntityListener implements EventListener { + private static final EntityFlagCalculator ENTITY_FLAG_CALCULATOR = EntityFlagCalculator.getInstance(); private static final boolean[] BASE_FLAG_SET = FlagSet.arrayFromFlags(ROOT, DEBUFF, INTERACT, ENTITY); @Override @@ -91,8 +94,7 @@ public void handle(InteractEntityEvent event) throws Exception { if (event instanceof InteractEntityEvent.Secondary.MainHand) flags[MAIN.id] = true; else if (event instanceof InteractEntityEvent.Secondary.OffHand) flags[OFF.id] = true; } - Entity entity = event.getTargetEntity(); - FGListenerUtil.applyEntityFlags(entity, flags); + ENTITY_FLAG_CALCULATOR.applyEntityFlags(ImmutableList.of(event.getTargetEntity()), flags); FlagSet flagSet = new FlagSet(flags); List handlerList = new ArrayList<>(handlerSet); diff --git a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/PlayerMoveListenerNew.java b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/PlayerMoveListener.java similarity index 98% rename from src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/PlayerMoveListenerNew.java rename to src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/PlayerMoveListener.java index d7eb237..c126671 100644 --- a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/PlayerMoveListenerNew.java +++ b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/PlayerMoveListener.java @@ -61,11 +61,11 @@ * Created by Fox on 1/4/2016. * Project: SpongeForge */ -public class PlayerMoveListenerNew implements EventListener { +public class PlayerMoveListener implements EventListener { private static final boolean[] BASE_FLAG_SET = FlagSet.arrayFromFlags(ROOT, DEBUFF, MOVE); - private static PlayerMoveListenerNew instance; + private static PlayerMoveListener instance; public final boolean full; @@ -84,7 +84,7 @@ public class PlayerMoveListenerNew implements EventListener { }); private final Map hudConfigMap = new WeakCacheMap<>((k, m) -> new HUDConfig()); - public PlayerMoveListenerNew(boolean full) { + public PlayerMoveListener(boolean full) { this.full = full; if (instance == null) instance = this; } @@ -360,7 +360,7 @@ public void showScoreboard(Player player) { player.setScoreboard(this.scoreboardMap.get(player)); } - public static PlayerMoveListenerNew getInstance() { + public static PlayerMoveListener getInstance() { return instance; } diff --git a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/SpawnEntityListener.java b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/SpawnEntityListener.java index 6d68854..bb52149 100644 --- a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/SpawnEntityListener.java +++ b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/SpawnEntityListener.java @@ -30,6 +30,7 @@ import net.foxdenstudio.sponge.foxguard.plugin.flag.Flag; import net.foxdenstudio.sponge.foxguard.plugin.flag.FlagSet; import net.foxdenstudio.sponge.foxguard.plugin.handler.IHandler; +import net.foxdenstudio.sponge.foxguard.plugin.listener.util.EntityFlagCalculator; import net.foxdenstudio.sponge.foxguard.plugin.object.IFGObject; import net.foxdenstudio.sponge.foxguard.plugin.util.ExtraContext; import org.spongepowered.api.entity.Entity; @@ -54,25 +55,20 @@ public class SpawnEntityListener implements EventListener { + private static final EntityFlagCalculator ENTITY_FLAG_CALCULATOR = EntityFlagCalculator.getInstance(); private static final boolean[] BASE_FLAG_SET = FlagSet.arrayFromFlags(ROOT, DEBUFF, SPAWN, ENTITY); @Override public void handle(SpawnEntityEvent event) throws Exception { if (event.isCancelled()) return; - if (event.getEntities().isEmpty()) return; - for (Entity entity : event.getEntities()) { + List entities = event.getEntities(); + if (entities.isEmpty()) return; + + for (Entity entity : entities) { if (entity instanceof Player) return; } - User user; - if (event.getCause().containsType(Player.class)) { - user = event.getCause().first(Player.class).get(); - } else if (event.getCause().containsType(User.class)) { - user = event.getCause().first(User.class).get(); - } else { - user = null; - } - Entity oneEntity = event.getEntities().get(0); + //Entity oneEntity = event.getEntities().get(0); /*if (oneEntity instanceof Arrow) { Optional creator = oneEntity.getCreator(), notifier = oneEntity.getNotifier(); @@ -89,29 +85,10 @@ public void handle(SpawnEntityEvent event) throws Exception { } }*/ - boolean[] flags = BASE_FLAG_SET.clone(); - - if (oneEntity instanceof Living) { - flags[LIVING.id] = true; - if (oneEntity instanceof Agent) { - flags[AGENT.id] = true; - if (oneEntity instanceof Hostile) { - flags[HOSTILE.id] = true; - } else if (oneEntity instanceof Human) { - flags[HUMAN.id] = true; - } else { - flags[PASSIVE.id] = true; - } - } - } else if (oneEntity instanceof Hanging) { - flags[HANGING.id] = true; - } - - FlagSet flagSet = new FlagSet(flags); Set handlerSet = new HashSet<>(); - for (Entity entity : event.getEntities()) { + for (Entity entity : entities) { Location loc = entity.getLocation(); Vector3d pos = loc.getPosition(); World world = loc.getExtent(); @@ -122,10 +99,24 @@ public void handle(SpawnEntityEvent event) throws Exception { .forEach(handlerSet::add)); } - - //TODO maybe throw a warning if(handlerSet.size() == 0) return; + + User user; + if (event.getCause().containsType(Player.class)) { + user = event.getCause().first(Player.class).get(); + } else if (event.getCause().containsType(User.class)) { + user = event.getCause().first(User.class).get(); + } else { + user = null; + } + + boolean[] flags = BASE_FLAG_SET.clone(); + + ENTITY_FLAG_CALCULATOR.applyEntityFlags(entities, flags); + + FlagSet flagSet = new FlagSet(flags); + ArrayList handlerList = new ArrayList<>(handlerSet); Collections.sort(handlerList); int currPriority = handlerList.get(0).getPriority(); diff --git a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/util/EntityFlagCalculator.java b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/util/EntityFlagCalculator.java index e82828b..9857e8c 100644 --- a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/util/EntityFlagCalculator.java +++ b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/util/EntityFlagCalculator.java @@ -51,7 +51,6 @@ public void applyEntityFlags(Collection entities, boolean[] flags) { mini.apply(flags); } - @SuppressWarnings("Duplicates") private MiniFlagSet getMiniFlag(Map, Entity> types) { MiniFlagSet mini = new MiniFlagSet(); Set totalFlags = new HashSet<>(); @@ -210,7 +209,7 @@ public void apply(boolean[] flagset) { } } - public static void main(String[] args) { + /*public static void main(String[] args) { EntityFlagCalculator calculator = EntityFlagCalculator.getInstance(); FlagRegistry registry = FlagRegistry.getInstance(); Entity entity = (Entity) Proxy.newProxyInstance(EntityFlagCalculator.class.getClassLoader(), @@ -220,5 +219,5 @@ public static void main(String[] args) { for (Flag flag : flags) { System.out.println(flag.name); } - } + }*/ } diff --git a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/util/DebugHelper.java b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/util/DebugHelper.java deleted file mode 100644 index dede305..0000000 --- a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/util/DebugHelper.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * This file is part of FoxGuard, licensed under the MIT License (MIT). - * - * Copyright (c) gravityfox - https://gravityfox.net/ - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package net.foxdenstudio.sponge.foxguard.plugin.util; - -import net.foxdenstudio.sponge.foxguard.plugin.FoxGuardMain; -import org.spongepowered.api.data.Transaction; -import org.spongepowered.api.event.Event; -import org.spongepowered.api.event.block.ChangeBlockEvent; - -public class DebugHelper { - - public static void printEvent(Event event) { - StringBuilder sb = new StringBuilder().append("-----------------------------------\n"); - sb.append(event.getClass()).append("\n\n"); - for (Object o : event.getCause().all()) { - sb.append(o).append("\n"); - } - FoxGuardMain.instance().getLogger().info(sb.toString()); - } - - public static void printBlockEvent(ChangeBlockEvent event) { - StringBuilder sb = new StringBuilder().append("-----------------------------------\n"); - sb.append(event.getClass()).append("\n"); - for (Transaction t : event.getTransactions()) { - sb.append(t).append("\n"); - } - sb.append("\n"); - for (Object o : event.getCause().all()) { - sb.append(o).append("\n"); - } - sb.append("\n"); - event.getContext().asMap().forEach((k, v) -> sb.append(k).append("::").append(v).append("\n")); - FoxGuardMain.instance().getLogger().info(sb.toString()); - } -} diff --git a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/util/DebugManager.java b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/util/DebugManager.java new file mode 100644 index 0000000..ce6f8f5 --- /dev/null +++ b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/util/DebugManager.java @@ -0,0 +1,127 @@ +/* + * This file is part of FoxGuard, licensed under the MIT License (MIT). + * + * Copyright (c) gravityfox - https://gravityfox.net/ + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package net.foxdenstudio.sponge.foxguard.plugin.util; + +import net.foxdenstudio.sponge.foxcore.plugin.command.FCCommandBase; +import net.foxdenstudio.sponge.foxguard.plugin.FoxGuardMain; +import org.spongepowered.api.command.CommandException; +import org.spongepowered.api.command.CommandResult; +import org.spongepowered.api.command.CommandSource; +import org.spongepowered.api.data.Transaction; +import org.spongepowered.api.event.Event; +import org.spongepowered.api.event.block.ChangeBlockEvent; +import org.spongepowered.api.event.cause.EventContextKey; +import org.spongepowered.api.text.Text; + +import java.util.Map; + +public class DebugManager extends FCCommandBase { + + public static final DebugManager INSTANCE = new DebugManager(); + + private boolean enabled = false; + private int armCount = 0; + + @Override + public CommandResult process(CommandSource source, String arguments) throws CommandException { + String[] parts = arguments.split(" +"); + if (parts.length == 0) return CommandResult.empty(); + + switch (parts[0]) { + case "on": + enabled = true; + armCount = 0; + source.sendMessage(Text.of("Enabled printing")); + break; + case "off": + enabled = false; + armCount = 0; + source.sendMessage(Text.of("Disabled printing")); + case "arm": + enabled = true; + int count = 1; + if (parts.length > 1) { + try { + count = Integer.parseInt(parts[1]); + } catch (NumberFormatException ignored) { + } + } + armCount = count; + source.sendMessage(Text.of("Armed for " + count + " prints")); + default: + return CommandResult.empty(); + } + return CommandResult.empty(); + } + + @Override + public boolean testPermission(CommandSource source) { + return source.hasPermission("foxguard.command.debug"); + } + + private boolean print() { + boolean ret = enabled; + if (armCount > 0) { + if (--armCount == 0) enabled = false; + } + return ret; + } + + public void printEvent(Event event) { + if (print()) { + StringBuilder sb = new StringBuilder().append("-----------------------------------\n"); + sb.append(event.getClass()).append("\n\n"); + + for (Object o : event.getCause().all()) { + sb.append(o).append("\n"); + } + + sb.append("\n"); + + for (Map.Entry, Object> entry : event.getContext().asMap().entrySet()) { + sb.append(entry).append("\n"); + } + FoxGuardMain.instance().getLogger().info(sb.toString()); + } + } + + public void printBlockEvent(ChangeBlockEvent event) { + if (print()) { + StringBuilder sb = new StringBuilder().append("-----------------------------------\n"); + sb.append(event.getClass()).append("\n"); + for (Transaction t : event.getTransactions()) { + sb.append(t).append("\n"); + } + sb.append("\n"); + for (Object o : event.getCause().all()) { + sb.append(o).append("\n"); + } + sb.append("\n"); + event.getContext().asMap().forEach((k, v) -> sb.append(k).append("::").append(v).append("\n")); + FoxGuardMain.instance().getLogger().info(sb.toString()); + } + } +}