Search in sources :

Example 1 with CommandBase

use of net.minecraft.command.CommandBase in project SpongeCommon by SpongePowered.

the class MixinCommandTeleport method execute.

/**
 * @author Aaron1011 - August 15, 2016
 * @reason Prevent 'notifyCommandListener' from being called the event is cancelled
 */
@Overwrite
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (args.length < 4) {
        throw new WrongUsageException("commands.teleport.usage", new Object[0]);
    } else {
        Entity entity = getEntity(server, sender, args[0]);
        if (entity.world != null) {
            // int i = 4096;
            Vec3d vec3d = sender.getPositionVector();
            int j = 1;
            CommandBase.CoordinateArg commandbase$coordinatearg = parseCoordinate(vec3d.x, args[j++], true);
            CommandBase.CoordinateArg commandbase$coordinatearg1 = parseCoordinate(vec3d.y, args[j++], -4096, 4096, false);
            CommandBase.CoordinateArg commandbase$coordinatearg2 = parseCoordinate(vec3d.z, args[j++], true);
            Entity entity1 = sender.getCommandSenderEntity() == null ? entity : sender.getCommandSenderEntity();
            CommandBase.CoordinateArg commandbase$coordinatearg3 = parseCoordinate(args.length > j ? (double) entity1.rotationYaw : (double) entity.rotationYaw, args.length > j ? args[j] : "~", false);
            ++j;
            CommandBase.CoordinateArg commandbase$coordinatearg4 = parseCoordinate(args.length > j ? (double) entity1.rotationPitch : (double) entity.rotationPitch, args.length > j ? args[j] : "~", false);
            // Sponge start - check shouldNotifyCommandListener before calling 'notifyCommandListener'
            // Guard against any possible re-entrance
            boolean shouldNotify = shouldNotifyCommandListener;
            doTeleport(entity, commandbase$coordinatearg, commandbase$coordinatearg1, commandbase$coordinatearg2, commandbase$coordinatearg3, commandbase$coordinatearg4);
            if (shouldNotifyCommandListener) {
                notifyCommandListener(sender, this, "commands.tp.success.coordinates", new Object[] { entity.getName(), Double.valueOf(commandbase$coordinatearg.getResult()), Double.valueOf(commandbase$coordinatearg1.getResult()), Double.valueOf(commandbase$coordinatearg2.getResult()) });
            }
            shouldNotifyCommandListener = shouldNotify;
        // Sponge end
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) WrongUsageException(net.minecraft.command.WrongUsageException) CommandBase(net.minecraft.command.CommandBase) Vec3d(net.minecraft.util.math.Vec3d) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

CommandBase (net.minecraft.command.CommandBase)1 WrongUsageException (net.minecraft.command.WrongUsageException)1 Entity (net.minecraft.entity.Entity)1 Vec3d (net.minecraft.util.math.Vec3d)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1