Java Code Examples for net.minecraft.command.ICommandSender#getCommandSenderEntity()

The following examples show how to use net.minecraft.command.ICommandSender#getCommandSenderEntity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommandGenPearl.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void execute(@NotNull MinecraftServer server, @NotNull ICommandSender sender, @NotNull String[] args) {
	Entity entity = sender.getCommandSenderEntity();
	if (entity instanceof EntityPlayerMP) {
		ItemStack item = new ItemStack(ModItems.PEARL_NACRE);


		List<ItemStack> recipe = new ArrayList<>();
		recipe.add(ModuleRegistry.INSTANCE.getModules(ModuleType.SHAPE).get(RandUtil.nextInt(ModuleRegistry.INSTANCE.getModules(ModuleType.SHAPE).size() - 1)).getItemStack());
		recipe.add(ModuleRegistry.INSTANCE.getModules(ModuleType.EFFECT).get(RandUtil.nextInt(ModuleRegistry.INSTANCE.getModules(ModuleType.EFFECT).size() - 1)).getItemStack());
		recipe.add(new ItemStack(ModItems.DEVIL_DUST));

		SpellBuilder builder = new SpellBuilder(recipe, 1);

		NBTTagList list = new NBTTagList();
		for (SpellRing spellRing : builder.getSpell())
			list.appendTag(spellRing.serializeNBT());
		NBTHelper.setList(item, NBTConstants.NBT.SPELL, list);
		NBTHelper.setBoolean(item, "infused", true);

		((EntityPlayerMP) entity).addItemStackToInventory(item);
		((EntityPlayerMP) entity).openContainer.detectAndSendChanges();
	} else notifyCommandListener(sender, this, "wizardry.command.notplayer");
}
 
Example 2
Source File: CommandGenStaff.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void execute(@NotNull MinecraftServer server, @NotNull ICommandSender sender, @NotNull String[] args) {
	Entity entity = sender.getCommandSenderEntity();
	if (entity instanceof EntityPlayerMP) {
		ItemStack item = new ItemStack(ModItems.STAFF);
		item.setItemDamage(1);

		List<ItemStack> recipe = new ArrayList<>();
		recipe.add(ModuleRegistry.INSTANCE.getModules(ModuleType.SHAPE).get(RandUtil.nextInt(ModuleRegistry.INSTANCE.getModules(ModuleType.SHAPE).size() - 1)).getItemStack());
		recipe.add(ModuleRegistry.INSTANCE.getModules(ModuleType.EFFECT).get(RandUtil.nextInt(ModuleRegistry.INSTANCE.getModules(ModuleType.EFFECT).size() - 1)).getItemStack());
		recipe.add(new ItemStack(ModItems.DEVIL_DUST));

		SpellBuilder builder = new SpellBuilder(recipe, 1);

		NBTTagList list = new NBTTagList();
		for (SpellRing spellRing : builder.getSpell())
			list.appendTag(spellRing.serializeNBT());
		NBTHelper.setList(item, NBTConstants.NBT.SPELL, list);
		NBTHelper.setBoolean(item, "infused", true);

		((EntityPlayerMP) entity).addItemStackToInventory(item);
		((EntityPlayerMP) entity).openContainer.detectAndSendChanges();
	} else notifyCommandListener(sender, this, "wizardry.command.notplayer");
}
 
Example 3
Source File: CommandTeleportUnderworld.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void execute(@NotNull MinecraftServer server, @NotNull ICommandSender sender, @NotNull String[] args) {
	Entity entity = sender.getCommandSenderEntity();
	if (entity instanceof EntityPlayerMP) {
		EntityPlayer player = ((EntityPlayer) entity);
		fallResetter.add(player.getUniqueID());
		TeleportUtil.teleportToDimension(player, Wizardry.underWorld.getId(), 0, 300, 0);
		player.addPotionEffect(new PotionEffect(ModPotions.NULLIFY_GRAVITY, 100, 0, true, false));
	} else notifyCommandListener(sender, this, "wizardry.command.notplayer");
}
 
Example 4
Source File: CommandTeleportTorikki.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
	public void execute(@NotNull MinecraftServer server, @NotNull ICommandSender sender, @NotNull String[] args) {
		Entity entity = sender.getCommandSenderEntity();
		if (entity instanceof EntityPlayerMP) {
			EntityPlayer player = ((EntityPlayer) entity);
			fallResetter.add(player.getUniqueID());
//			TeleportUtil.teleportToDimension(player, Wizardry.torikki.getId(), 0, 65, 0);
		} else notifyCommandListener(sender, this, "wizardry.command.notplayer");
	}
 
Example 5
Source File: AirshipMapCommand.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args)
    throws CommandException {
    String term = args[0];

    if (term.equals("tpto")) {
        StringBuilder shipName = new StringBuilder(args.length < 2 ? "" : args[1]);
        if (args.length > 2) {
            for (int i = 2; i < args.length; i++) {
                shipName.append(" ").append(args[i]);
            }
        }

        Entity player = sender.getCommandSenderEntity();
        if (!(player instanceof EntityPlayer)) {
            return;
        }

        Optional<ShipData> shipDataOptional = ValkyrienUtils.getQueryableData(player.world)
            .getShipFromName(shipName.toString());

        if (shipDataOptional.isPresent()) {
            ShipPositionData positionData = shipDataOptional.get().getPositionData();
            double posX = positionData.getPosX();
            double posY = positionData.getPosY();
            double posZ = positionData.getPosZ();

            // Time to teleport!
            if (player instanceof EntityPlayerMP) {
                EntityPlayerMP playerMP = (EntityPlayerMP) player;

                ((EntityPlayerMP) player).connection.setPlayerLocation(posX, posY, posZ, 0, 0);
            }
        } else {
            sender.sendMessage(new TextComponentString("That's not a valid ship!"));
        }
    }

    if (term.equals("help")) {
        sender.sendMessage(new TextComponentString("tpto"));
    }
}
 
Example 6
Source File: PlatformCommand.java    From YUNoMakeGoodMap with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 1)
        throw new WrongUsageException(getUsage(sender));

    String cmd = args[0].toLowerCase(Locale.ENGLISH);
    if ("list".equals(cmd))
    {
        sender.sendMessage(new TextComponentString("Known Platforms:"));
        for (ResourceLocation rl : getPlatforms())
        {
            sender.sendMessage(new TextComponentString("  " + rl.toString()));
        }
    }
    else if ("spawn".equals(cmd) || "preview".equals(cmd))
    {
        if (args.length < 2)
            throw new WrongUsageException(getUsage(sender));

        Entity ent = sender.getCommandSenderEntity();
        PlacementSettings settings = new PlacementSettings();
        WorldServer world = (WorldServer)sender.getEntityWorld();

        if (args.length >= 3)
        {
            //TODO: Preview doesnt quite work correctly with rotations....
            String rot = args[2].toLowerCase(Locale.ENGLISH);
            if ("0".equals(rot) || "none".equals(rot))
                settings.setRotation(Rotation.NONE);
            else if ("90".equals(rot))
                settings.setRotation(Rotation.CLOCKWISE_90);
            else if ("180".equals(rot))
                settings.setRotation(Rotation.CLOCKWISE_180);
            else if ("270".equals(rot))
                settings.setRotation(Rotation.COUNTERCLOCKWISE_90);
            else
                throw new WrongUsageException("Only rotations none, 0, 90, 180, and 270 allowed.");
        }

        BlockPos pos;
        if (args.length >= 6)
            pos = CommandBase.parseBlockPos(sender, args, 3, false);
        else if (ent != null)
            pos = ent.getPosition();
        else
            throw new WrongUsageException("Must specify a position if the command sender is not an entity");

        Template temp = StructureUtil.loadTemplate(new ResourceLocation(args[1]), world, true);

        BlockPos spawn = StructureUtil.findSpawn(temp, settings);
        if (spawn != null)
            pos = pos.subtract(spawn);

        if ("spawn".equals(cmd))
        {
            sender.sendMessage(new TextComponentString("Building \"" + args[1] +"\" at " + pos.toString()));
            temp.addBlocksToWorld(world, pos, settings, 2); //Push to world, with no neighbor notifications!
            world.getPendingBlockUpdates(new StructureBoundingBox(pos, pos.add(temp.getSize())), true); //Remove block updates, so that sand doesn't fall!
        }
        else
        {
            BlockPos tpos = pos.down();
            if (spawn != null)
                tpos = tpos.add(spawn);
            sender.sendMessage(new TextComponentString("Previewing \"" + args[1] +"\" at " + pos.toString()));
            world.setBlockState(tpos, Blocks.STRUCTURE_BLOCK.getDefaultState().withProperty(BlockStructure.MODE, TileEntityStructure.Mode.LOAD));
            TileEntityStructure te = (TileEntityStructure)world.getTileEntity(tpos);
            if (spawn != null)
                te.setPosition(te.getPosition().subtract(spawn));
            te.setSize(temp.getSize());
            te.setMode(Mode.LOAD);
            te.markDirty();
        }
    }
    else
        throw new WrongUsageException(getUsage(sender));
}