User:Captain S0L0/Command Signs

From the change of signs to support JSON text in 14w25a (1.8 snapshot) to release 1.8, the sign packet would not enforce the usage of only the text JSON component, allowing for modified clients to create signs that could run commands with the  tag. This can be extremely dangerous, as it allows for a non-op player to run any command, including opping themselves, as signs will always run their commands as a fully privileged level 4 operator.

Do note that due to various syntax changes over the versions, it would be wise to create command signs for both older and newer syntaxes. A common example is the  command. In older versions, numerical and single character abbreviations were allowed, such as. This was changed in 1.13 to require the full gamemode name to be specified, as.

Obtaining
This requires a modified client to create, but it will work on any vanilla server. The client must modify the sign GUI class to send a custom sign update packet containing the command(s) one wishes to place into the sign.

The below example was created with 1.8 Minecraft Coder Pack (MCP) mappings to create a sign to give creative to the nearest player upon right-clicking the sign:

import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.network.NetHandlerPlayClient; import net.minecraft.event.ClickEvent; import net.minecraft.network.play.client.C12PacketUpdateSign; import net.minecraft.tileentity.TileEntitySign; import net.minecraft.util.IChatComponent; import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChatStyle; import org.lwjgl.input.Keyboard;

public class GuiEditSign extends GuiScreen {   private TileEntitySign tileSign; // The client side sign object, contains the text entered in the GUI in the public array signText

public void onGuiClosed // Called when GUI closes {       Keyboard.enableRepeatEvents(false); NetHandlerPlayClient var1 = this.mc.getNetHandler;

if (var1 != null) {           //var1.addToSendQueue(new C12PacketUpdateSign(this.tileSign.getPos, this.tileSign.signText)); - This is the original packet creation line

/* Here we create a new array to hold each JSON component of the sign */ var1.addToSendQueue(new C12PacketUpdateSign(this.tileSign.getPos, new IChatComponent[]{

/* Here is where we create the ClickEvent with the command */ this.tileSign.signText[0].setChatStyle(new ChatStyle.setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND,"gamemode creative @p"))),

/* These just copy the existing text lines from the sign GUI */ this.tileSign.signText[1], this.tileSign.signText[2], this.tileSign.signText[3] }));       }

this.tileSign.setEditable(true); }

If one would like to be able to change the command to set in-game with ease, an easy method is to modify the  method as well to remove the character limit inside the GUI as follows: protected void keyTyped(char typedChar, int keyCode) throws IOException {       //...

//if (ChatAllowedCharacters.isAllowedCharacter(typedChar) && this.fontRendererObj.getStringWidth(var3 + typedChar) <= 90) - The original character width check if (ChatAllowedCharacters.isAllowedCharacter(typedChar)) // The new check with the width check removed {           var3 = var3 + typedChar; }

//...   }

And change the spoofed packet creation to

var1.addToSendQueue(new C12PacketUpdateSign(this.tileSign.getPos, new IChatComponent[]{

/* Set the ClickEvent's command from the text set in the first line of the sign, will set the visible text field as empty */ new ChatComponentText("").setChatStyle(new ChatStyle.setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND,this.tileSign.signText[0].getUnformattedTextForChat))),

/* These just copy the existing text lines from the sign GUI */ this.tileSign.signText[1], this.tileSign.signText[2], this.tileSign.signText[3] }));

to read the command as whatever is input into the first line of the sign. Do note that the full text line will not be rendered within the GUI if it extends beyond the GUI's edge.

Running the Command
To run the command(s) set in a command sign, simply right click the sign. You do not need cheats to be enabled, or to have operator privileges.

Uses
As one can imagine, allowing access to all commands has a plethora of uses, from creating custom items, blocks, entities, functions, and more. Listing everything possible with commands would be impossible, but here's a list of examples: • Give yourself Operator privileges

• Enchantments with higher than possible levels (up to 32,767).

• Java Edition:Any Enchantment on Any Item, including new enchantments and items.

• Custom potions with impossible effects or effect durations.

• Barriers

• The Farmland item

• The Dirt Path item

• The Chorus Plant item

• Command Blocks (with commands, too!)

• Command Signs

• Command Block Minecarts (also with commands!)

• Any infested stone type (if you didn't use bugged endermen or asynchronous word tearing), including new 1.17 deepslate variants.

• Player Heads (if you don't plan to use 20w14∞ or asynchronous word tearing), including custom player heads.

• Items with lore

• Custom written books with custom authors, colors and formatting, click event commands (will not work with cheats disabled / without operator privileges), hover tooltips, and more.

• Java Edition:Spawn Eggs (including those added after 11w49a)

• Containers with items inside (including impossible items due to them being added later, such as the Debug Stick, Recipe Book, Budding Amethyst, variants of command blocks (repeating, chain), Jigsaw Block, Structure Block and Structure Void, and more {full list needed})

• Creative Mode

• Adventure Mode

• Spectator Mode

• Super Creeper with Extreme Blast Radii

• Fireballs with Extreme Blast Radii

• Giants

• Mini Wither

• Giant Phantom

• Custom villager trades

• Any Mob with Armor

• NoAI/Silent/Persistent Mobs

• Infinite Resources

• Change Any Gamerule