Skip to content

Commit

Permalink
Redirect spammy debug message
Browse files Browse the repository at this point in the history
  • Loading branch information
LXGaming committed Aug 12, 2018
1 parent 92e7c6c commit b74508e
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 3 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ targetCompatibility = 1.8

group = "io.github.lxgaming"
archivesBaseName = "Sledgehammer"
version = "1.2.4-1.12.2"
version = "1.2.5-1.12.2"

minecraft {
version = "1.12.2-14.23.4.2705"
Expand Down Expand Up @@ -78,7 +78,7 @@ jar {
attributes(
"FMLCorePluginContainsFMLMod": true,
"ForceLoadAsMod": true,
"MixinConfigs": "mixins.sledgehammer.core.json,mixins.sledgehammer.forge.json",
"MixinConfigs": "mixins.sledgehammer.core.json,mixins.sledgehammer.forge.json,mixins.sledgehammer.sponge.json",
"TweakClass": "org.spongepowered.asm.launch.MixinTweaker",
"TweakOrder": 0
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ private void registerMappings() {
getMixinMappings().put("io.github.lxgaming.sledgehammer.mixin.forge.common.MixinForgeHooks_Harvest", MixinCategory::isHarvestBlock);
getMixinMappings().put("io.github.lxgaming.sledgehammer.mixin.forge.entity.passive.MixinEntityVillager", MixinCategory::isTravelingMerchant);
getMixinMappings().put("io.github.lxgaming.sledgehammer.mixin.forge.world.storage.MixinWorldInfo", MixinCategory::isCeremonyRain);

// Mixin Sponge
getMixinMappings().put("io.github.lxgaming.sledgehammer.mixin.sponge.common.event.MixinSpongeCommonEventFactory", MixinCategory::isMessageSpam);
}

public void debugMessage(String format, Object... arguments) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2018 Alex Thomson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.github.lxgaming.sledgehammer.commands;

import io.github.lxgaming.sledgehammer.Sledgehammer;
import io.github.lxgaming.sledgehammer.configuration.Config;
import io.github.lxgaming.sledgehammer.util.Toolbox;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;

import java.util.List;

public class DebugCommand extends AbstractCommand {

public DebugCommand() {
addAlias("debug");
setPermission("sledgehammer.debug");
}

@Override
public CommandResult execute(CommandSource commandSource, List<String> arguments) {
Config config = Sledgehammer.getInstance().getConfig().orElse(null);
if (config == null) {
commandSource.sendMessage(Text.of(Toolbox.getTextPrefix(), TextColors.RED, "Configuration error"));
return CommandResult.empty();
}

if (config.isDebug()) {
config.setDebug(false);
commandSource.sendMessage(Text.of(Toolbox.getTextPrefix(), TextColors.RED, "Debugging disabled"));
} else {
config.setDebug(true);
commandSource.sendMessage(Text.of(Toolbox.getTextPrefix(), TextColors.GREEN, "Debugging enabled"));
}

return CommandResult.success();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class SledgehammerCommand extends AbstractCommand {
public SledgehammerCommand() {
addAlias("sledgehammer");
addAlias("sh");
addChild(DebugCommand.class);
addChild(HelpCommand.class);
addChild(InfoCommand.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public boolean isDebug() {
return debug;
}

public void setDebug(boolean debug) {
this.debug = debug;
}

public IntegrationCategory getIntegrationCategory() {
return integrationCategory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class MixinCategory {
@Setting(value = "interact-events", comment = "Fixes https://github.com/SpongePowered/SpongeCommon/issues/2013")
private boolean interactEvents = false;

@Setting(value = "message-spam", comment = "Redirects spammy messages to Sledgehammer debug")
private boolean messageSpam = false;

@Setting(value = "network-system", comment = "Fixes potential deadlock on shutdown")
private boolean networkSystem = false;

Expand Down Expand Up @@ -91,6 +94,10 @@ public boolean isInteractEvents() {
return interactEvents;
}

public boolean isMessageSpam() {
return messageSpam;
}

public boolean isNetworkSystem() {
return networkSystem;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2018 Alex Thomson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.github.lxgaming.sledgehammer.mixin.plugin;

import org.spongepowered.asm.lib.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

import java.util.List;
import java.util.Set;

public class SpongePlugin extends AbstractPlugin {

@Override
public void onLoad(String mixinPackage) {
super.onLoad(mixinPackage);
}

@Override
public String getRefMapperConfig() {
return null;
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
return super.shouldApplyMixin(targetClassName, mixinClassName);
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
}

@Override
public List<String> getMixins() {
return null;
}

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2018 Alex Thomson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.github.lxgaming.sledgehammer.mixin.sponge.common.event;

import io.github.lxgaming.sledgehammer.Sledgehammer;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.common.event.SpongeCommonEventFactory;

@Mixin(value = SpongeCommonEventFactory.class, priority = 1337, remap = false)
public abstract class MixinSpongeCommonEventFactory {

@Redirect(method = "captureTransaction(Lorg/spongepowered/common/interfaces/IMixinInventory;Lorg/spongepowered/api/item/inventory/Inventory;ILnet/minecraft/item/ItemStack;)V",
at = @At(value = "INVOKE",
target = "Lorg/apache/logging/log4j/Logger;warn(Ljava/lang/String;)V"
)
)
private static void onCaptureTransaction(Logger logger, String message) {
Sledgehammer.getInstance().debugMessage(message);
}

@Redirect(method = "captureTransaction(Lorg/spongepowered/common/interfaces/IMixinInventory;Lorg/spongepowered/api/item/inventory/Inventory;ILjava/util/function/Supplier;)Lnet/minecraft/item/ItemStack;",
at = @At(value = "INVOKE",
target = "Lorg/apache/logging/log4j/Logger;warn(Ljava/lang/String;)V"
)
)
private static void onCaptureTransactions(Logger logger, String message) {
Sledgehammer.getInstance().debugMessage(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Reference {

public static final String PLUGIN_ID = "sledgehammer";
public static final String PLUGIN_NAME = "Sledgehammer";
public static final String PLUGIN_VERSION = "1.2.4-1.12.2";
public static final String PLUGIN_VERSION = "1.2.5-1.12.2";
public static final String DESCRIPTION = "Smashes the stupid out of the server.";
public static final String AUTHORS = "LX_Gaming";
public static final String SOURCE = "https://github.com/LXGaming/Sledgehammer/";
Expand Down
15 changes: 15 additions & 0 deletions src/main/resources/mixins.sledgehammer.sponge.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"required": true,
"minVersion": "0.7.4",
"package": "io.github.lxgaming.sledgehammer.mixin.sponge",
"refmap": "mixins.sledgehammer.refmap.json",
"plugin": "io.github.lxgaming.sledgehammer.mixin.plugin.SpongePlugin",
"target": "@env(DEFAULT)",
"compatibilityLevel": "JAVA_8",
"mixins": [
"common.event.MixinSpongeCommonEventFactory"
],
"injectors": {
"defaultRequire": 1
}
}

0 comments on commit b74508e

Please sign in to comment.