From 1f29b363a2756698088aa79e9a4034dd264db300 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Thu, 28 Nov 2024 21:55:44 +0100 Subject: [PATCH] Mixins clean up --- .../fabric/mixin/command/TextMixin.java | 20 ---------- .../1.12.2/src/main/resources/fabric.mod.json | 4 +- ...y-fabric-sponge-command-api-v2.mixins.json | 14 ------- .../mixin/command/MinecraftServerMixin.java | 36 ------------------ .../fabric/mixin/command/TextMixin.java | 13 ------- .../1.7.10/src/main/resources/fabric.mod.json | 4 +- ...y-fabric-sponge-command-api-v2.mixins.json | 12 ------ .../mixin/command/MinecraftServerMixin.java | 36 ------------------ .../fabric/mixin/command/TextMixin.java | 20 ---------- .../1.8.9/src/main/resources/fabric.mod.json | 4 +- ...y-fabric-sponge-command-api-v2.mixins.json | 12 ------ .../v2/lib/sponge/args/CommandElement.java | 4 +- .../impl/command/CrossCompatibleText.java | 5 --- .../fabric/impl/command/GuavaUtils.java | 38 ++++++++++--------- .../common/src/main/resources/fabric.mod.json | 4 +- .../permission}/MinecraftServerMixin.java | 6 +-- ...bric-permissions-api-v1-common.mixins.json | 1 + 17 files changed, 28 insertions(+), 205 deletions(-) delete mode 100644 legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/command/TextMixin.java delete mode 100644 legacy-fabric-command-api-v2/1.12.2/src/main/resources/legacy-fabric-sponge-command-api-v2.mixins.json delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/command/MinecraftServerMixin.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/command/TextMixin.java delete mode 100644 legacy-fabric-command-api-v2/1.7.10/src/main/resources/legacy-fabric-sponge-command-api-v2.mixins.json delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/command/MinecraftServerMixin.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/command/TextMixin.java delete mode 100644 legacy-fabric-command-api-v2/1.8.9/src/main/resources/legacy-fabric-sponge-command-api-v2.mixins.json delete mode 100644 legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/CrossCompatibleText.java rename {legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/command => legacy-fabric-permissions-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/permission}/MinecraftServerMixin.java (87%) diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/command/TextMixin.java b/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/command/TextMixin.java deleted file mode 100644 index 36ba5f4a2..000000000 --- a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/command/TextMixin.java +++ /dev/null @@ -1,20 +0,0 @@ -package net.legacyfabric.fabric.mixin.command; - -import net.legacyfabric.fabric.impl.command.CrossCompatibleText; - -import net.minecraft.text.Text; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(Text.class) -public abstract class TextMixin implements CrossCompatibleText { - - @Shadow - public abstract String asUnformattedString(); - - @Override - public String asSanitizedString() { - return this.asUnformattedString(); - } -} diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/resources/fabric.mod.json b/legacy-fabric-command-api-v2/1.12.2/src/main/resources/fabric.mod.json index 5ff821a2a..83dca385f 100644 --- a/legacy-fabric-command-api-v2/1.12.2/src/main/resources/fabric.mod.json +++ b/legacy-fabric-command-api-v2/1.12.2/src/main/resources/fabric.mod.json @@ -28,9 +28,7 @@ ] }, "description": "Powerful Command API that uses SpongeAPI's command api", - "mixins": [ - "legacy-fabric-sponge-command-api-v2.mixins.json" - ], + "mixins": [], "custom": { "modmenu": { "badges": [ "library" ], diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/resources/legacy-fabric-sponge-command-api-v2.mixins.json b/legacy-fabric-command-api-v2/1.12.2/src/main/resources/legacy-fabric-sponge-command-api-v2.mixins.json deleted file mode 100644 index 80912f82f..000000000 --- a/legacy-fabric-command-api-v2/1.12.2/src/main/resources/legacy-fabric-sponge-command-api-v2.mixins.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "required": true, - "package": "net.legacyfabric.fabric.mixin.command", - "compatibilityLevel": "JAVA_8", - "mixins": [ - "MinecraftServerMixin", - "TextMixin" - ], - "client": [ - ], - "injectors": { - "defaultRequire": 1 - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/command/MinecraftServerMixin.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/command/MinecraftServerMixin.java deleted file mode 100644 index 397b46b4c..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/command/MinecraftServerMixin.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * 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 net.legacyfabric.fabric.mixin.command; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -import net.minecraft.server.MinecraftServer; - -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -@Mixin(MinecraftServer.class) -public abstract class MinecraftServerMixin implements PermissibleCommandSource { - @Shadow - public abstract boolean isDedicated(); - - @Override - public boolean hasPermission(String perm) { - return true; - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/command/TextMixin.java b/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/command/TextMixin.java deleted file mode 100644 index 56e7e3c16..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/java/net/legacyfabric/fabric/mixin/command/TextMixin.java +++ /dev/null @@ -1,13 +0,0 @@ -package net.legacyfabric.fabric.mixin.command; - -import net.legacyfabric.fabric.impl.command.CrossCompatibleText; -import net.minecraft.text.Text; -import org.spongepowered.asm.mixin.Mixin; - -@Mixin(Text.class) -public abstract class TextMixin implements CrossCompatibleText { - @Override - public String asSanitizedString() { - return this.toString(); - } -} diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/resources/fabric.mod.json b/legacy-fabric-command-api-v2/1.7.10/src/main/resources/fabric.mod.json index 5ff821a2a..83dca385f 100644 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/resources/fabric.mod.json +++ b/legacy-fabric-command-api-v2/1.7.10/src/main/resources/fabric.mod.json @@ -28,9 +28,7 @@ ] }, "description": "Powerful Command API that uses SpongeAPI's command api", - "mixins": [ - "legacy-fabric-sponge-command-api-v2.mixins.json" - ], + "mixins": [], "custom": { "modmenu": { "badges": [ "library" ], diff --git a/legacy-fabric-command-api-v2/1.7.10/src/main/resources/legacy-fabric-sponge-command-api-v2.mixins.json b/legacy-fabric-command-api-v2/1.7.10/src/main/resources/legacy-fabric-sponge-command-api-v2.mixins.json deleted file mode 100644 index 2ffb653db..000000000 --- a/legacy-fabric-command-api-v2/1.7.10/src/main/resources/legacy-fabric-sponge-command-api-v2.mixins.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "required": true, - "package": "net.legacyfabric.fabric.mixin.command", - "compatibilityLevel": "JAVA_8", - "mixins": [ - "MinecraftServerMixin", - "TextMixin" - ], - "injectors": { - "defaultRequire": 1 - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/command/MinecraftServerMixin.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/command/MinecraftServerMixin.java deleted file mode 100644 index 397b46b4c..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/command/MinecraftServerMixin.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2020 - 2024 Legacy Fabric - * Copyright (c) 2016 - 2022 FabricMC - * - * 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 net.legacyfabric.fabric.mixin.command; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -import net.minecraft.server.MinecraftServer; - -import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; - -@Mixin(MinecraftServer.class) -public abstract class MinecraftServerMixin implements PermissibleCommandSource { - @Shadow - public abstract boolean isDedicated(); - - @Override - public boolean hasPermission(String perm) { - return true; - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/command/TextMixin.java b/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/command/TextMixin.java deleted file mode 100644 index 36ba5f4a2..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/command/TextMixin.java +++ /dev/null @@ -1,20 +0,0 @@ -package net.legacyfabric.fabric.mixin.command; - -import net.legacyfabric.fabric.impl.command.CrossCompatibleText; - -import net.minecraft.text.Text; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(Text.class) -public abstract class TextMixin implements CrossCompatibleText { - - @Shadow - public abstract String asUnformattedString(); - - @Override - public String asSanitizedString() { - return this.asUnformattedString(); - } -} diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/resources/fabric.mod.json b/legacy-fabric-command-api-v2/1.8.9/src/main/resources/fabric.mod.json index 5ff821a2a..83dca385f 100644 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/resources/fabric.mod.json +++ b/legacy-fabric-command-api-v2/1.8.9/src/main/resources/fabric.mod.json @@ -28,9 +28,7 @@ ] }, "description": "Powerful Command API that uses SpongeAPI's command api", - "mixins": [ - "legacy-fabric-sponge-command-api-v2.mixins.json" - ], + "mixins": [], "custom": { "modmenu": { "badges": [ "library" ], diff --git a/legacy-fabric-command-api-v2/1.8.9/src/main/resources/legacy-fabric-sponge-command-api-v2.mixins.json b/legacy-fabric-command-api-v2/1.8.9/src/main/resources/legacy-fabric-sponge-command-api-v2.mixins.json deleted file mode 100644 index 2ffb653db..000000000 --- a/legacy-fabric-command-api-v2/1.8.9/src/main/resources/legacy-fabric-sponge-command-api-v2.mixins.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "required": true, - "package": "net.legacyfabric.fabric.mixin.command", - "compatibilityLevel": "JAVA_8", - "mixins": [ - "MinecraftServerMixin", - "TextMixin" - ], - "injectors": { - "defaultRequire": 1 - } -} diff --git a/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandElement.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandElement.java index 8e27eac7a..d582ace40 100644 --- a/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandElement.java +++ b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/api/command/v2/lib/sponge/args/CommandElement.java @@ -27,8 +27,6 @@ import java.util.List; -import net.legacyfabric.fabric.impl.command.CrossCompatibleText; - import org.jetbrains.annotations.Nullable; import net.minecraft.server.MinecraftServer; @@ -134,7 +132,7 @@ public void parse(PermissibleCommandSource source, CommandArgs args, CommandCont * @return The formatted usage */ public Text getUsage(PermissibleCommandSource src) { - return this.getKey() == null ? new LiteralText("") : new LiteralText("<" + ((CrossCompatibleText) this.getKey()).asSanitizedString() + ">"); + return this.getKey() == null ? new LiteralText("") : new LiteralText("<" + this.getKey().asUnformattedString() + ">"); } public MinecraftServer getServer() { diff --git a/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/CrossCompatibleText.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/CrossCompatibleText.java deleted file mode 100644 index 29c945cb4..000000000 --- a/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/CrossCompatibleText.java +++ /dev/null @@ -1,5 +0,0 @@ -package net.legacyfabric.fabric.impl.command; - -public interface CrossCompatibleText { - String asSanitizedString(); -} diff --git a/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/GuavaUtils.java b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/GuavaUtils.java index 926d50ea8..da5fd2b6a 100644 --- a/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/GuavaUtils.java +++ b/legacy-fabric-command-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/command/GuavaUtils.java @@ -1,10 +1,27 @@ +/* + * Copyright (c) 2020 - 2024 Legacy Fabric + * Copyright (c) 2016 - 2022 FabricMC + * + * 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 net.legacyfabric.fabric.impl.command; +import java.util.Arrays; + import com.google.common.base.Preconditions; import org.jetbrains.annotations.Nullable; -import java.util.Arrays; - /** * Guava's ToStringHelper class which isn't located at the same place depending on guava versions. * This ensures it is available in all targeted versions. @@ -35,78 +52,63 @@ private ToStringHelper(String className) { this.className = (String) Preconditions.checkNotNull(className); } - public ToStringHelper omitNullValues() { this.omitNullValues = true; return this; } - public ToStringHelper add(String name, @Nullable Object value) { return this.addHolder(name, value); } - public ToStringHelper add(String name, boolean value) { return this.addHolder(name, String.valueOf(value)); } - public ToStringHelper add(String name, char value) { return this.addHolder(name, String.valueOf(value)); } - public ToStringHelper add(String name, double value) { return this.addHolder(name, String.valueOf(value)); } - public ToStringHelper add(String name, float value) { return this.addHolder(name, String.valueOf(value)); } - public ToStringHelper add(String name, int value) { return this.addHolder(name, String.valueOf(value)); } - public ToStringHelper add(String name, long value) { return this.addHolder(name, String.valueOf(value)); } - public ToStringHelper addValue(@Nullable Object value) { return this.addHolder(value); } - public ToStringHelper addValue(boolean value) { return this.addHolder(String.valueOf(value)); } - public ToStringHelper addValue(char value) { return this.addHolder(String.valueOf(value)); } - public ToStringHelper addValue(double value) { return this.addHolder(String.valueOf(value)); } - public ToStringHelper addValue(float value) { return this.addHolder(String.valueOf(value)); } - public ToStringHelper addValue(int value) { return this.addHolder(String.valueOf(value)); } - public ToStringHelper addValue(long value) { return this.addHolder(String.valueOf(value)); } @@ -118,9 +120,11 @@ public String toString() { for (ValueHolder valueHolder = this.holderHead.next; valueHolder != null; valueHolder = valueHolder.next) { Object value = valueHolder.value; + if (!omitNullValuesSnapshot || value != null) { builder.append(nextSeparator); nextSeparator = ", "; + if (valueHolder.name != null) { builder.append(valueHolder.name).append('='); } diff --git a/legacy-fabric-command-api-v2/common/src/main/resources/fabric.mod.json b/legacy-fabric-command-api-v2/common/src/main/resources/fabric.mod.json index f2da6f186..c0620c084 100644 --- a/legacy-fabric-command-api-v2/common/src/main/resources/fabric.mod.json +++ b/legacy-fabric-command-api-v2/common/src/main/resources/fabric.mod.json @@ -22,9 +22,7 @@ "entrypoints": { }, "description": "Powerful Command API that uses SpongeAPI's command api", - "mixins": [ - "legacy-fabric-sponge-command-api-v2-common.mixins.json" - ], + "mixins": [], "custom": { "modmenu": { "badges": [ "library" ], diff --git a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/command/MinecraftServerMixin.java b/legacy-fabric-permissions-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/permission/MinecraftServerMixin.java similarity index 87% rename from legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/command/MinecraftServerMixin.java rename to legacy-fabric-permissions-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/permission/MinecraftServerMixin.java index 397b46b4c..f277a46b7 100644 --- a/legacy-fabric-command-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/command/MinecraftServerMixin.java +++ b/legacy-fabric-permissions-api-v1/common/src/main/java/net/legacyfabric/fabric/mixin/permission/MinecraftServerMixin.java @@ -15,10 +15,9 @@ * limitations under the License. */ -package net.legacyfabric.fabric.mixin.command; +package net.legacyfabric.fabric.mixin.permission; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import net.minecraft.server.MinecraftServer; @@ -26,9 +25,6 @@ @Mixin(MinecraftServer.class) public abstract class MinecraftServerMixin implements PermissibleCommandSource { - @Shadow - public abstract boolean isDedicated(); - @Override public boolean hasPermission(String perm) { return true; diff --git a/legacy-fabric-permissions-api-v1/common/src/main/resources/legacy-fabric-permissions-api-v1-common.mixins.json b/legacy-fabric-permissions-api-v1/common/src/main/resources/legacy-fabric-permissions-api-v1-common.mixins.json index a982b0f48..fd8c4ce74 100644 --- a/legacy-fabric-permissions-api-v1/common/src/main/resources/legacy-fabric-permissions-api-v1-common.mixins.json +++ b/legacy-fabric-permissions-api-v1/common/src/main/resources/legacy-fabric-permissions-api-v1-common.mixins.json @@ -5,6 +5,7 @@ "mixins": [ "ConsoleMixin", "EntityMixin", + "MinecraftServerMixin", "ServerPlayerEntityMixin" ], "injectors": {