Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How would I determine if a command being executed is the product of the "/execute" command?

Featured Replies

Posted

Hey fellas!

So, to make it as short as possible here, I need to know how to determine if a command being executed is from "/execute" or not from the scope of the execute method in the command interface implementation. For example, if, let's say, popbob were to run the command "/summon tnt", and then if some other random player ran the command, "/execute popbob ~ ~ ~ summon tnt", from the scope accessible by the "execute" method of the summon command class, I need to be able to tell the difference between the one that was actually run by popbob and the one that was run by popbob as a result of another player making them use this command through the execute command.

Now, this isn't really pertinent information needed to answer the above question, so if you are not interested then please skip past this paragraph, but I'm always open to answer the question of "why on earth do you want this?" First, for context, I play Minecraft with my friends on my own Minecraft server. HOWEVER, they do not really trust me completely with hosting a Minecraft server because they believe me to be a "little troll" (which they're not wrong btw). So the agreement I have with them is that every single one of us gets to have operator, that way we are not only all as close to equal as possible, but also so that we can check on each other independently. To make sure that each of us stays operator, and also so that we each don't actually abuse operator against other players too much, I disabled commands like /stop, /ban, /kick, and /deop for players, making it so these commands can only be executed on the server. However, I would come to find out that they would also seem to be "little trolls", and they would constantly do things like spawning in Tsar Bombs, using the open inventory command to make sure I wouldn't be able to pull the item from them, and blasting the entire server to smithereens. Now, I still don't want to take away their operator status, but when they're using commands to kill me constantly as well as demolishing everything in sight with nuclear bombs, it's kind of hard to actually stop them. So, in response, I created an item that was so powerful, anybody who had it would be completely unstoppable by any immediate means what-so-ever. This includes things like complete immunity to all forms of harm, including every single potion effect, the /kill command, the void, HBM nuclear explosions, the Avaritia Sword of The Cosmos, etc., and on top of that, it would provide protection from other nuisances they would try to use, like opening another player's inventory, the teleport command, and the gamemode command. But that's not the only insane thing the item provides, as it also allows players to fly at infinite speeds, create nuclear explosions, annihilate entire biomes, and kill any player no matter what, even if they have the Avaritia infinity armor. So, with all that being said, it's pretty clear that should one of my friends get their hands on this item, I would probably be f****d. The only way to get rid of the item from their inventory would be to manually use an inventory editor after either kicking them off the server or stopping it entirely. In an effort to ensure that nobody but me is able to control who has this item, I overwrote a bunch of commands to do nothing if my code detects that they're trying to spawn in the god item. However, there is one major caveat, that being that they could just use the execute command to make me run the give command, thus my code would determine that I am running the give command and proceed with the operation. I DON'T WANT THIS AT ALL, but I also don't want to restrict their freedoms by disabling the execute command. Hence, that's why I need to know how to detect a command being run by "/execute" or not.

  • Author

UPDATE:

Okay, so I have a really good fix going on rn, but the problem still isn't exactly solved. Although the quick fix works well enough to be practical, it's not exactly perfect and can cause bugs. Basically, I just injected code at the start of the execute method of the execute command, as well as many others that search the argument list for the string "commands:onepunch" (the name of the super item that I don't want my friends to be able to have), and if it detects said string, it forces the function to return without doing anything.

This might sound like a foolproof method of preventing anyone from getting the super item, which it is, but the problem is that it's a bit too foolproof. Instead of the logic behind the practical obtainment of this item in reference to commands being something like, "You can't spawn in this item by any means unless you are the server owner", it turns it into something like, "You can't reference the item in ANY WAY in commands unless you are the server owner." This could cause some issues, like, for example, if I were popbob, and I were to run the command "/execute @e[type=sheep] ~ ~ ~ give popbob commands:onepunch", the code would run the execute command successfully, even though it detects that the super item is referenced because popbob, me, the server owner, is running the command. However, because it is still not able to differentiate between a /execute trigger for a command and a directly run command, even though I am the one who ran the execute command, it will fail once the /give part of it is passed to the sheep.

Although for all practical purposes I am happy with what I have so far, it still doesn't really work as intended, so I'll refrain from tagging this thread as solved in the hopes that somebody can come up with a solution to the specific problem at hand.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.