My command doesn't work

Started by ManosSef on

Topic category: Help with modding (Java Edition)

Last seen on 08:39, 21. Aug 2022
Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
My command doesn't work
Mon, 06/01/2020 - 05:57 (edited)

I am trying to make a command that kills the entity executing the command with a specific damage type, and I am trying to make the first (and only) parameter of the command be the damage type, but it doesn't work. I have attached the procedure and command.

https://file.io/8ZhsXXFu - The command

https://file.io/6DXLPHM0 - The start of the procedure

https://file.io/aZmbBs7E - The end of the procedure

I have skipped the middle of the procedure as it's only more "if" things for damage types.

Edited by ManosSef on Mon, 06/01/2020 - 05:57
Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I can't see the images so I…
Sun, 05/31/2020 - 19:28

I can't see the images so I can't help you (getting 404 error). Do you mind posting the images on Imgur along with the code?

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Or you could just post code…
Sun, 05/31/2020 - 19:29

Or you could just post code here

Last seen on 08:39, 21. Aug 2022
Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
OK, I fixed the links.
Mon, 06/01/2020 - 05:57

OK, I fixed the links.

Last seen on 08:39, 21. Aug 2022
Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Oh, maybe the links don't…
Mon, 06/01/2020 - 06:01

Oh, maybe the links don't work now either. I am posting the code here.

The procedure: 

package net.mcreator.killdamagetype.procedures;

import net.minecraft.world.World;
import net.minecraft.world.GameType;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.DamageSource;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.Entity;
import net.minecraft.client.network.play.NetworkPlayerInfo;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.Minecraft;

import net.mcreator.killdamagetype.KilldamagetypeModElements;

import java.util.HashMap;

@KilldamagetypeModElements.ModElement.Tag
public class KillProcedureProcedure extends KilldamagetypeModElements.ModElement {
	public KillProcedureProcedure(KilldamagetypeModElements instance) {
		super(instance, 1);
	}

	public static void executeProcedure(java.util.HashMap<String, Object> dependencies) {
		if (dependencies.get("entity") == null) {
			System.err.println("Failed to load dependency entity for procedure KillProcedure!");
			return;
		}
		if (dependencies.get("cmdparams") == null) {
			System.err.println("Failed to load dependency cmdparams for procedure KillProcedure!");
			return;
		}
		if (dependencies.get("world") == null) {
			System.err.println("Failed to load dependency world for procedure KillProcedure!");
			return;
		}
		Entity entity = (Entity) dependencies.get("entity");
		HashMap cmdparams = (HashMap) dependencies.get("cmdparams");
		World world = (World) dependencies.get("world");
		if ((entity.hasPermissionLevel((int) 4))) {
			if (((new Object() {
				public boolean checkGamemode(Entity _ent) {
					if (_ent instanceof ServerPlayerEntity) {
						return ((ServerPlayerEntity) _ent).interactionManager.getGameType() == GameType.SURVIVAL;
					} else if (_ent instanceof ClientPlayerEntity) {
						NetworkPlayerInfo _npi = Minecraft.getInstance().getConnection()
								.getPlayerInfo(((ClientPlayerEntity) _ent).getGameProfile().getId());
						return _npi != null && _npi.getGameType() == GameType.SURVIVAL;
					}
					return false;
				}
			}.checkGamemode(entity)) || (new Object() {
				public boolean checkGamemode(Entity _ent) {
					if (_ent instanceof ServerPlayerEntity) {
						return ((ServerPlayerEntity) _ent).interactionManager.getGameType() == GameType.ADVENTURE;
					} else if (_ent instanceof ClientPlayerEntity) {
						NetworkPlayerInfo _npi = Minecraft.getInstance().getConnection()
								.getPlayerInfo(((ClientPlayerEntity) _ent).getGameProfile().getId());
						return _npi != null && _npi.getGameType() == GameType.ADVENTURE;
					}
					return false;
				}
			}.checkGamemode(entity)))) {
				if ((((new Object() {
					public String getText() {
						String param = (String) cmdparams.get("0");
						if (param != null) {
							return param;
						}
						return "";
					}
				}.getText())).equals("generic"))) {
					entity.attackEntityFrom(DamageSource.GENERIC, (float) 2147483647);
				}
				if ((((new Object() {
					public String getText() {
						String param = (String) cmdparams.get("0");
						if (param != null) {
							return param;
						}
						return "";
					}
				}.getText())).equals("inFire"))) {
					entity.attackEntityFrom(DamageSource.IN_FIRE, (float) 2147483647);
				}
				if ((((new Object() {
					public String getText() {
						String param = (String) cmdparams.get("0");
						if (param != null) {
							return param;
						}
						return "";
					}
				}.getText())).equals("lightningBolt"))) {
					entity.attackEntityFrom(DamageSource.LIGHTNING_BOLT, (float) 2147483647);
				}
				if ((((new Object() {
					public String getText() {
						String param = (String) cmdparams.get("0");
						if (param != null) {
							return param;
						}
						return "";
					}
				}.getText())).equals("onFire"))) {
					entity.attackEntityFrom(DamageSource.ON_FIRE, (float) 2147483647);
				}
				if ((((new Object() {
					public String getText() {
						String param = (String) cmdparams.get("0");
						if (param != null) {
							return param;
						}
						return "";
					}
				}.getText())).equals("lava"))) {
					entity.attackEntityFrom(DamageSource.LAVA, (float) 2147483647);
				}
				if ((((new Object() {
					public String getText() {
						String param = (String) cmdparams.get("0");
						if (param != null) {
							return param;
						}
						return "";
					}
				}.getText())).equals("hotFloor"))) {
					entity.attackEntityFrom(DamageSource.HOT_FLOOR, (float) 2147483647);
				}
				if ((((new Object() {
					public String getText() {
						String param = (String) cmdparams.get("0");
						if (param != null) {
							return param;
						}
						return "";
					}
				}.getText())).equals("inWall"))) {
					entity.attackEntityFrom(DamageSource.IN_WALL, (float) 2147483647);
				}
				if ((((new Object() {
					public String getText() {
						String param = (String) cmdparams.get("0");
						if (param != null) {
							return param;
						}
						return "";
					}
				}.getText())).equals("cramming"))) {
					entity.attackEntityFrom(DamageSource.CRAMMING, (float) 2147483647);
				}
				if ((((new Object() {
					public String getText() {
						String param = (String) cmdparams.get("0");
						if (param != null) {
							return param;
						}
						return "";
					}
				}.getText())).equals("drown"))) {
					entity.attackEntityFrom(DamageSource.DROWN, (float) 2147483647);
				}
				if ((((new Object() {
					public String getText() {
						String param = (String) cmdparams.get("0");
						if (param != null) {
							return param;
						}
						return "";
					}
				}.getText())).equals("starve"))) {
					entity.attackEntityFrom(DamageSource.STARVE, (float) 2147483647);
				}
				if ((((new Object() {
					public String getText() {
						String param = (String) cmdparams.get("0");
						if (param != null) {
							return param;
						}
						return "";
					}
				}.getText())).equals("cactus"))) {
					entity.attackEntityFrom(DamageSource.CACTUS, (float) 2147483647);
				}
				if ((((new Object() {
					public String getText() {
						String param = (String) cmdparams.get("0");
						if (param != null) {
							return param;
						}
						return "";
					}
				}.getText())).equals("fall"))) {
					entity.attackEntityFrom(DamageSource.FALL, (float) 2147483647);
				}
				if ((((new Object() {
					public String getText() {
						String param = (String) cmdparams.get("0");
						if (param != null) {
							return param;
						}
						return "";
					}
				}.getText())).equals("flyIntoWall"))) {
					entity.attackEntityFrom(DamageSource.FLY_INTO_WALL, (float) 2147483647);
				}
				if ((((new Object() {
					public String getText() {
						String param = (String) cmdparams.get("0");
						if (param != null) {
							return param;
						}
						return "";
					}
				}.getText())).equals("outOfWorld"))) {
					entity.attackEntityFrom(DamageSource.OUT_OF_WORLD, (float) 2147483647);
				}
				if ((((new Object() {
					public String getText() {
						String param = (String) cmdparams.get("0");
						if (param != null) {
							return param;
						}
						return "";
					}
				}.getText())).equals("magic"))) {
					entity.attackEntityFrom(DamageSource.MAGIC, (float) 2147483647);
				}
				if ((((new Object() {
					public String getText() {
						String param = (String) cmdparams.get("0");
						if (param != null) {
							return param;
						}
						return "";
					}
				}.getText())).equals("wither"))) {
					entity.attackEntityFrom(DamageSource.WITHER, (float) 2147483647);
				}
				if ((((new Object() {
					public String getText() {
						String param = (String) cmdparams.get("0");
						if (param != null) {
							return param;
						}
						return "";
					}
				}.getText())).equals("anvil"))) {
					entity.attackEntityFrom(DamageSource.ANVIL, (float) 2147483647);
				}
				if ((((new Object() {
					public String getText() {
						String param = (String) cmdparams.get("0");
						if (param != null) {
							return param;
						}
						return "";
					}
				}.getText())).equals("fallingBlock"))) {
					entity.attackEntityFrom(DamageSource.FALLING_BLOCK, (float) 2147483647);
				}
				if ((((new Object() {
					public String getText() {
						String param = (String) cmdparams.get("0");
						if (param != null) {
							return param;
						}
						return "";
					}
				}.getText())).equals("dragonBreath"))) {
					entity.attackEntityFrom(DamageSource.DRAGON_BREATH, (float) 2147483647);
				}
				if ((((new Object() {
					public String getText() {
						String param = (String) cmdparams.get("0");
						if (param != null) {
							return param;
						}
						return "";
					}
				}.getText())).equals("fireworks"))) {
					entity.attackEntityFrom(DamageSource.FIREWORKS, (float) 2147483647);
				}
				if ((((new Object() {
					public String getText() {
						String param = (String) cmdparams.get("0");
						if (param != null) {
							return param;
						}
						return "";
					}
				}.getText())).equals("dryout"))) {
					entity.attackEntityFrom(DamageSource.DRYOUT, (float) 2147483647);
				}
				if ((((new Object() {
					public String getText() {
						String param = (String) cmdparams.get("0");
						if (param != null) {
							return param;
						}
						return "";
					}
				}.getText())).equals("sweetBerryBush"))) {
					entity.attackEntityFrom(DamageSource.SWEET_BERRY_BUSH, (float) 2147483647);
				}
			} else {
				if (entity instanceof PlayerEntity && !world.isRemote) {
					((PlayerEntity) entity).sendStatusMessage(new StringTextComponent("You are in a game mode where you cannot take damage"),
							(false));
				}
			}
		} else {
			if (entity instanceof PlayerEntity && !world.isRemote) {
				((PlayerEntity) entity).sendStatusMessage(new StringTextComponent("Insufficient permission!"), (false));
			}
		}
	}
}

The command: 


package net.mcreator.killdamagetype.command;

import net.minecraftforge.fml.event.server.FMLServerStartingEvent;

import net.minecraft.world.World;
import net.minecraft.entity.Entity;
import net.minecraft.command.Commands;
import net.minecraft.command.CommandSource;

import net.mcreator.killdamagetype.procedures.KillProcedureProcedure;
import net.mcreator.killdamagetype.KilldamagetypeModElements;

import java.util.HashMap;
import java.util.Arrays;

import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.arguments.StringArgumentType;

@KilldamagetypeModElements.ModElement.Tag
public class KillCommandCommand extends KilldamagetypeModElements.ModElement {
	public KillCommandCommand(KilldamagetypeModElements instance) {
		super(instance, 2);
	}

	@Override
	public void serverLoad(FMLServerStartingEvent event) {
		event.getCommandDispatcher().register(customCommand());
	}

	private LiteralArgumentBuilder<CommandSource> customCommand() {
		return LiteralArgumentBuilder.<CommandSource>literal("killtype")
				.then(Commands.argument("arguments", StringArgumentType.greedyString()).executes(this::execute)).executes(this::execute);
	}

	private int execute(CommandContext<CommandSource> ctx) {
		Entity entity = ctx.getSource().getEntity();
		if (entity != null) {
			int x = entity.getPosition().getX();
			int y = entity.getPosition().getY();
			int z = entity.getPosition().getZ();
			World world = entity.world;
			HashMap<String, String> cmdparams = new HashMap<>();
			int[] index = {-1};
			Arrays.stream(ctx.getInput().split("\\s+")).forEach(param -> {
				if (index[0] >= 0)
					cmdparams.put(Integer.toString(index[0]), param);
				index[0]++;
			});
			{
				java.util.HashMap<String, Object> $_dependencies = new java.util.HashMap<>();
				$_dependencies.put("entity", entity);
				$_dependencies.put("cmdparams", cmdparams);
				KillProcedureProcedure.executeProcedure($_dependencies);
			}
		}
		return 0;
	}
}

 

Last seen on 08:39, 21. Aug 2022
Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
It's been a week and I'm…
Mon, 06/08/2020 - 12:30

It's been a week and I'm still waiting.

Last seen on 22:41, 29. Dec 2021
Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Just post the pictures of…
Fri, 06/12/2020 - 20:43

Just post the pictures of your procedure on Imgur, file.io is not working. 

Please do the ENTIRE procedure, and your command element page.

Last seen on 08:39, 21. Aug 2022
Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
(No subject)
Sat, 06/13/2020 - 06:25

The procedure and command

Last seen on 21:58, 3. Jul 2022
Joined Jan 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
ManosSef you have to have…
Thu, 12/30/2021 - 00:30

ManosSef you have to have perms 4 try removing that a trying again... if it works then plan ahead from there!