net.minecraft.command.ICommandSender Java Examples

The following examples show how to use net.minecraft.command.ICommandSender. 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: CommandGlDebug.java    From OpenModsLib with MIT License 6 votes vote down vote up
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
	if (args.length != 1) throw new CommandException("commands.generic.syntax");
	final String arg = args[0].toLowerCase(Locale.ROOT);
	if (arg.equals("disable")) {
		GL11.glDisable(KHRDebug.GL_DEBUG_OUTPUT);
	} else {
		final Set<Integer> allowedLevels = ALLOWED_LEVELS.get(arg);
		if (allowedLevels == null) throw new CommandException("commands.generic.syntax");

		GL11.glEnable(KHRDebug.GL_DEBUG_OUTPUT);
		for (int level : ALL_LEVELS) {
			final boolean isEnabled = allowedLevels.contains(level);
			KHRDebug.glDebugMessageControl(GL11.GL_DONT_CARE, GL11.GL_DONT_CARE, level, null, isEnabled);
		}
		KHRDebug.glDebugMessageCallback(new KHRDebugCallback());
	}

}
 
Example #2
Source File: CommandsAdmin.java    From MyTown2 with The Unlicense 6 votes vote down vote up
@Command(
        name = "member",
        permission = "mytown.adm.cmd.plot.add.member",
        parentName = "mytown.adm.cmd.plot.add",
        syntax = "/townadmin plot add member <town> <plot> <resident>",
        completionKeys = {"townCompletion", "plotCompletion", "residentCompletion"},
        console = true)
public static CommandResponse plotAddMemberCommand(ICommandSender sender, List<String> args) {
    if (args.size() < 3) {
        return CommandResponse.SEND_SYNTAX;
    }

    Resident target = getResidentFromName(args.get(2));
    Town town = getTownFromName(args.get(0));
    Plot plot = getPlotFromName(town, args.get(1));

    if(plot.membersContainer.contains(target) || plot.ownersContainer.contains(target)) {
        throw new MyTownCommandException("mytown.cmd.err.plot.add.alreadyInPlot");
    }

    getDatasource().linkResidentToPlot(target, plot, false);

    ChatManager.send(sender, "mytown.notification.plot.member.sender.added", target, plot);
    ChatManager.send(target.getPlayer(), "mytown.notification.plot.member.target.added", plot);
    return CommandResponse.DONE;
}
 
Example #3
Source File: GTCommandTeleport.java    From GT-Classic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void execute(@Nonnull MinecraftServer server, @Nonnull ICommandSender sender, @Nonnull String[] args)
		throws CommandException {
	if (!IC2.platform.isOp(sender.getCommandSenderEntity().getUniqueID())) {
		sender.sendMessage(new TextComponentString(TextFormatting.RED
				+ "You do not have permission to use this command"));
		return;
	}
	if (args.length < 1) {
		return;
	}
	String s = args[0];
	int dim;
	try {
		dim = Integer.parseInt(s);
	} catch (NumberFormatException e) {
		sender.sendMessage(new TextComponentString(TextFormatting.RED + "Error parsing dimension!"));
		return;
	}
	if (sender instanceof EntityPlayer) {
		GTCommandTeleporter.teleportToDimension((EntityPlayer) sender, dim, 0, 100, 0);
	}
}
 
Example #4
Source File: CommandsAssistant.java    From MyTown2 with The Unlicense 6 votes vote down vote up
@Command(
        name = "add",
        permission = "mytown.cmd.assistant.ranks.perm.add",
        parentName = "mytown.cmd.assistant.ranks.perm",
        syntax = "/town ranks perm add <rank> <perm>",
        completionKeys = {"rankCompletion"})
public static CommandResponse ranksPermAddCommand(ICommandSender sender, List<String> args) {
    if (args.size() < 2) {
        return CommandResponse.SEND_SYNTAX;
    }

    Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
    Town town = getTownFromResident(res);
    Rank rank = getRankFromTown(town, args.get(0));

    getDatasource().saveRankPermission(rank, args.get(1));
    ChatManager.send(sender, "mytown.notification.town.ranks.perm.add");

    return CommandResponse.DONE;
}
 
Example #5
Source File: CmdGetLangpack.java    From I18nUpdateMod with MIT License 6 votes vote down vote up
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) {
    // 参数为空,警告
    if (args.length == 0) {
        Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation("message.i18nmod.cmd_get_langpack.empty"));
        return;
    }

    // 参数存在,进行下一步判定
    if (Minecraft.getMinecraft().getResourceManager().getResourceDomains().contains(args[0])) {
        Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation("message.i18nmod.cmd_get_langpack.right_start", args[0]));

        // 同名资源包存在,直接返回
        if (!cerateTempLangpack(args[0])) {
            Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation("message.i18nmod.cmd_get_langpack.error_create_folder"));
            return;
        }

        // 主下载功能
        langFileDownloader(args[0]);
    }
    // 参数不存在,警告
    else {
        Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation("message.i18nmod.cmd_get_langpack.not_found", args[0]));
    }
}
 
Example #6
Source File: CommandsAdmin.java    From MyTown2 with The Unlicense 6 votes vote down vote up
@Command(
        name = "add",
        permission = "mytown.adm.cmd.blocks.extra.add",
        parentName = "mytown.adm.cmd.blocks.extra",
        syntax = "/townadmin blocks extra add <town> <amount>",
        completionKeys = {"townCompletion"},
        console = true)
public static CommandResponse townBlocksMaxAddCommand(ICommandSender sender, List<String> args) {
    if(args.size() < 2) {
        return CommandResponse.SEND_SYNTAX;
    }

    checkPositiveInteger(args.get(1));

    Town town = getTownFromName(args.get(0));
    int amount = Integer.parseInt(args.get(1));
    town.townBlocksContainer.setExtraBlocks(town.townBlocksContainer.getExtraBlocks() + amount);
    getDatasource().saveTown(town);
    ChatManager.send(sender, "mytown.notification.town.blocks.extra.set", town.townBlocksContainer.getExtraBlocks(), town);
    return CommandResponse.DONE;
}
 
Example #7
Source File: CommandsAdmin.java    From MyTown2 with The Unlicense 6 votes vote down vote up
@Command(
        name = "all",
        permission = "mytown.adm.cmd.claim.chunkload.all",
        parentName = "mytown.adm.cmd.claim.chunkload",
        syntax = "/townadmin claim chunkload all <town>",
        completionKeys = {"townCompletion"})
public static CommandResponse claimChunkloadAllCommand(ICommandSender sender, List<String> args) {
    if (args.size() < 1) {
        return CommandResponse.SEND_SYNTAX;
    }

    Town town = getTownFromName(args.get(0));
    int chunksToLoad = town.townBlocksContainer.size() - town.ticketMap.getChunkloadedAmount();

    town.ticketMap.chunkLoadAll();
    ChatManager.send(sender, "mytown.notification.claim.chunkload.all", chunksToLoad);

    return CommandResponse.DONE;
}
 
Example #8
Source File: CommandsAdmin.java    From MyTown2 with The Unlicense 6 votes vote down vote up
@Command(
        name = "rename",
        permission = "mytown.adm.cmd.plot.rename",
        parentName = "mytown.adm.cmd.plot",
        syntax = "/townadmin plot rename <town> <plot> <name>",
        completionKeys = {"townCompletion", "plotCompletion"},
        console = true)
public static CommandResponse plotRenameCommand(ICommandSender sender, List<String> args) {
    if (args.size() < 3)
        return CommandResponse.SEND_SYNTAX;

    Town town = getTownFromName(args.get(0));
    Plot plot = getPlotFromName(town, args.get(1));

    plot.setName(args.get(2));
    getDatasource().savePlot(plot);

    ChatManager.send(sender, "mytown.notification.plot.renamed");
    return CommandResponse.DONE;
}
 
Example #9
Source File: CommandsAdmin.java    From MyTown2 with The Unlicense 6 votes vote down vote up
@Command(
        name = "show",
        permission = "mytown.adm.cmd.plot.show",
        parentName = "mytown.adm.cmd.plot",
        syntax = "/townadmin plot show <town>",
        completionKeys = {"townCompletion"})
public static CommandResponse plotShowCommand(ICommandSender sender, List<String> args) {
    if (args.size() < 1)
        return CommandResponse.SEND_SYNTAX;

    Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
    Town town = getTownFromName(args.get(0));
    town.plotsContainer.show(res);
    ChatManager.send(sender, "mytown.notification.plot.showing");
    return CommandResponse.DONE;
}
 
Example #10
Source File: CommandsEveryone.java    From MyTown2 with The Unlicense 6 votes vote down vote up
@Command(
        name = "leave",
        permission = "mytown.cmd.everyone.leave",
        parentName = "mytown.cmd",
        syntax = "/town leave [delete]")
public static CommandResponse leaveCommand(ICommandSender sender, List<String> args) {
    Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
    Town town = getTownFromResident(res);

    if (town.residentsMap.get(res) != null && town.residentsMap.get(res).getType() == Rank.Type.MAYOR) {
        throw new MyTownCommandException("mytown.notification.town.left.asMayor");
    }

    getDatasource().unlinkResidentFromTown(res, town);

    ChatManager.send(sender, "mytown.notification.town.left.self", town);
    town.notifyEveryone(getLocal().getLocalization("mytown.notification.town.left", res, town));
    return CommandResponse.DONE;
}
 
Example #11
Source File: CommandConfig.java    From OpenModsLib with MIT License 6 votes vote down vote up
@Override
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos blockPos) {
	String command = args[0];
	if (args.length == 1) return filterPrefixes(command, SUBCOMMANDS);

	String modId = args[1];
	if (args.length == 2) return filterPrefixes(modId, ConfigProcessing.getConfigsIds());

	if (COMMAND_SAVE.equals(command)) return Collections.emptyList();

	final ModConfig config = ConfigProcessing.getConfig(modId);
	if (config == null) return Collections.emptyList();

	String category = args[2];
	if (args.length == 3) return filterPrefixes(category, config.getCategories());

	String name = args[3];
	if (args.length == 4) return filterPrefixes(name, config.getValues(category));

	return Collections.emptyList();
}
 
Example #12
Source File: ItemInHandInfoCommand.java    From NewHorizonsCoreMod with GNU General Public License v3.0 5 votes vote down vote up
private void SendHelpToPlayer(ICommandSender pCmdSender)
{
    if (!InGame(pCmdSender))
    {
        PlayerChatHelper.SendPlain(pCmdSender, "Command can only be executed ingame");            
    }
    else
    {
        PlayerChatHelper.SendInfo(pCmdSender, "/iih");            
    }
}
 
Example #13
Source File: CommandReloadGroups.java    From TickDynamic with MIT License 5 votes vote down vote up
@Override
public void processCommand(ICommandSender sender, String[] args) {
	sender.addChatMessage(new ChatComponentText("Reloading Groups configuration..."));
	sender.addChatMessage(new ChatComponentText("Note: Moving of (tile)entities to new groups might cause lag!!!"));
	mod.loadConfig(true);
	sender.addChatMessage(new ChatComponentText("Reload and moving complete!"));
}
 
Example #14
Source File: VSConfigCommandBase.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender,
    String[] args, @Nullable BlockPos targetPos) {

    args = VSCommandUtil.toProperArgs(args);

    ConfigCommandNode currentNode = root;

    if (args.length == 0) {
        return root.childrenNames();
    }

    for (int i = 0; i < args.length; i++) {
        System.out.println(args[i]);
        if (currentNode instanceof ConfigCommandParentNode) {
            ConfigCommandNode nextNode =
                ((ConfigCommandParentNode) currentNode).getChild(args[i]);

            if (nextNode == null) {
                return ((ConfigCommandParentNode) currentNode).getChildrenStartingWith(args[i])
                    .stream()
                    .map(ConfigCommandNode::getName)
                    .collect(Collectors.toList());
            } else if (i == args.length - 1 && nextNode instanceof ConfigCommandParentNode) {
                // We have reached the last argument, so the user must be looking for all the
                // values of this subcategory

                return ((ConfigCommandParentNode) nextNode).childrenNames();
            } else {
                currentNode = nextNode;
            }
        }
    }

    return Collections.emptyList();
}
 
Example #15
Source File: CommandsAdmin.java    From MyTown2 with The Unlicense 5 votes vote down vote up
@Command(
        name = "defaultFlags",
        permission = "mytown.adm.cmd.config.reset.defaultFlags",
        parentName = "mytown.adm.cmd.config.reset",
        syntax = "/townadmin config reset defaultFlags",
        console = true)
public static CommandResponse configResetFlagsCommand(ICommandSender sender, List<String> args) {
    MyTown.instance.getFlagsConfig().create(new ArrayList<FlagsConfig.Wrapper>());
    ChatManager.send(sender, "mytown.cmd.config.reset", MyTown.instance.getFlagsConfig().getName());
    return CommandResponse.DONE;
}
 
Example #16
Source File: CommandInventory.java    From burlapcraft with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void processCommand(ICommandSender sender, String[] args) {

	Map<String, Integer> items = HelperActions.checkInventory();
	for(Map.Entry<String, Integer> i : items.entrySet()){
		System.out.println("has " + i.getValue() + " " + i.getKey());
	}

}
 
Example #17
Source File: CommandFindBiome.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos) {
	if(args.length==1) {
		List<String> strings = new ArrayList<>();
		for (Biome b : ForgeRegistries.BIOMES.getValues()) {
			String s = b.getRegistryName().toString();
			if (s.toLowerCase().contains(args[0].toLowerCase()))
				strings.add(s);
		}

		return strings;
	}
	return Collections.emptyList();
}
 
Example #18
Source File: CoreCommand.java    From CodeChickenCore with MIT License 5 votes vote down vote up
@Override
public boolean canCommandSenderUseCommand(ICommandSender var1) {
    if (OPOnly()) {
        if (var1 instanceof EntityPlayer)
            return MinecraftServer.getServer().getConfigurationManager().canSendCommands(((EntityPlayer) var1).getGameProfile());

        return var1 instanceof MinecraftServer;
    }
    return true;
}
 
Example #19
Source File: CommandsEveryone.java    From MyTown2 with The Unlicense 5 votes vote down vote up
@Command(
        name = "select",
        permission = "mytown.cmd.everyone.plot.select",
        parentName = "mytown.cmd.everyone.plot",
        syntax = "/town plot select <command>")
public static CommandResponse plotSelectCommand(ICommandSender sender, List<String> args) {
    return CommandResponse.SEND_HELP_MESSAGE;
}
 
Example #20
Source File: CommandCalcFactory.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
public void execute(ICommandSender sender, IWhitespaceSplitter args) {
	final String name = args.getNextPart();
	final String expr = args.getTail();

	final Object result = state.compileAndSetGlobalSymbol(sender, name, expr);
	CommandUtils.respond(sender, "openmodslib.command.calc_set", name, String.valueOf(result));
}
 
Example #21
Source File: CommandEntity.java    From wailanbt with MIT License 5 votes vote down vote up
@Override
public void processCommand(ICommandSender sender, String[] array) {
    EntityPlayer player = (EntityPlayer) sender;
    Minecraft minecraft = Minecraft.getMinecraft();
    MovingObjectPosition objectMouseOver = minecraft.objectMouseOver;
    if (objectMouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.ENTITY){
        Class pointEntityClass  = objectMouseOver.entityHit.getClass();
        if (EntityList.classToStringMapping.containsKey(pointEntityClass)){
         player.addChatComponentMessage(new ChatComponentText(EntityList.getEntityString(objectMouseOver.entityHit)));
        }
    }else{
        player.addChatComponentMessage(new ChatComponentTranslation("wailanbt.info.NotPointing"));
    }
}
 
Example #22
Source File: NewSpawnPlatformCommand.java    From YUNoMakeGoodMap with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length != 2)
        throw new WrongUsageException(getUsage(sender));

    EntityPlayer player = getPlayer(server, sender, args[1]);

    if (player != null)
    {
        PlacementSettings settings = new PlacementSettings();
        WorldServer world = (WorldServer) sender.getEntityWorld();

        int platformNumber = SpawnPlatformSavedData.get(world).addAndGetPlatformNumber();
        BlockPos pos = getPositionOfPlatform(world, platformNumber);

        Template temp = StructureUtil.loadTemplate(new ResourceLocation(args[0]), world, true);
        BlockPos spawn = StructureUtil.findSpawn(temp, settings);
        spawn = spawn == null ? pos : spawn.add(pos);

        sender.sendMessage(new TextComponentString("Building \"" + args[0] + "\" 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!

        if (player instanceof EntityPlayerMP) {
            ((EntityPlayerMP) player).setPositionAndUpdate(spawn.getX() + 0.5, spawn.getY() + 1.6, spawn.getZ() + 0.5);
        }

        player.setSpawnChunk(spawn, true, world.provider.getDimension());
    }
    else
    {
        throw new WrongUsageException(getUsage(sender));
    }
}
 
Example #23
Source File: Commands.java    From MyTown2 with The Unlicense 5 votes vote down vote up
public static void makeBankPayment(ICommandSender sender, Town town, int amount) {
    if(amount == 0)
        return;

    if(town.bank.getAmount() < amount)
        throw new MyTownCommandException("mytown.cmd.err.town.payment", EconomyProxy.getCurrency(amount));

    town.bank.addAmount(-amount);
    getDatasource().saveTownBank(town.bank);
    ChatManager.send(sender, "mytown.notification.town.payment", EconomyProxy.getCurrency(amount));
}
 
Example #24
Source File: CommandNBTEdit.java    From NBTEdit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void processCommand(ICommandSender sender, String[] var2) {
	if (sender instanceof EntityPlayerMP) {
		EntityPlayerMP player = (EntityPlayerMP)sender;

		if (var2.length == 3) {
			int x = parseInt(sender,var2[0]);
			int y = parseInt(sender,var2[1]);
			int z = parseInt(sender,var2[2]);
			NBTEdit.log(Level.FINE, sender.getCommandSenderName() + " issued command \"/nbtedit " + x + " " + y + " " + z + "\"");
			new TileRequestPacket(x, y, z).handleServerSide(player);
		}
		else if (var2.length == 1) {
			int entityID = (var2[0].equalsIgnoreCase("me")) ? player.getEntityId() : parseIntWithMin(sender, var2[0], 0);
			NBTEdit.log(Level.FINE, sender.getCommandSenderName() + " issued command \"/nbtedit " + entityID +  "\"");
			new EntityRequestPacket(entityID).handleServerSide(player);
		}
		else if (var2.length == 0) {
			NBTEdit.log(Level.FINE, sender.getCommandSenderName() + " issued command \"/nbtedit\"");
			NBTEdit.DISPATCHER.sendTo(new MouseOverPacket(), player);
		}
		else  {
			String s = "";
			for (int i =0; i < var2.length; ++i) {
				s += var2[i];
				if (i != var2.length - 1)
					s += " ";
			}
			NBTEdit.log(Level.FINE, sender.getCommandSenderName() + " issued invalid command \"/nbtedit " + s + "\"");
			throw new WrongUsageException("Pass 0, 1, or 3 integers -- ex. /nbtedit", new Object[0]);
		}
	}
}
 
Example #25
Source File: CommandsAdmin.java    From MyTown2 with The Unlicense 5 votes vote down vote up
@Command(
        name = "town",
        permission = "mytown.adm.cmd.perm.town",
        parentName = "mytown.adm.cmd.perm",
        syntax = "/townadmin perm town <command>",
        console = true)
public static CommandResponse permTownCommand(ICommandSender sender, List<String> args) {
    return CommandResponse.SEND_HELP_MESSAGE;
}
 
Example #26
Source File: CommandCalcFactory.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
public void execute(ICommandSender sender, IWhitespaceSplitter args) {
	final String type = args.getNextPart().toUpperCase(Locale.ROOT);
	try {
		final CalculatorType newType = CalculatorType.valueOf(type);
		state.createCalculator(newType);
	} catch (IllegalArgumentException e) {
		throw new CommandSyntaxException("openmodslib.command.calc_invalid_type", Joiner.on(',').join(CalculatorType.values()));
	}
}
 
Example #27
Source File: CommandWrapper.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<String> getTabCompletions(MinecraftServer server, ICommandSender iCommandSender, String[] args, @Nullable BlockPos targetPos) {
    try {
        return this.command.tabComplete(sender, name, args);
    } catch (Exception e) {
        e.printStackTrace();
        return ImmutableList.of();
    }
}
 
Example #28
Source File: CommandsAssistant.java    From MyTown2 with The Unlicense 5 votes vote down vote up
@Command(
        name = "withdraw",
        permission = "mytown.cmd.assistant.bank.withdraw",
        parentName = "mytown.cmd.everyone.bank",
        syntax = "/town bank withdraw <amount>")
public static CommandResponse bankWithdrawCommand(ICommandSender sender, List<String> args) {
    if(args.size() < 1) {
        return CommandResponse.SEND_SYNTAX;
    }

    checkPositiveInteger(args.get(0));

    Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
    Town town = getTownFromResident(res);

    if(town instanceof AdminTown) {
        throw new MyTownCommandException("mytown.cmd.err.adminTown", town);
    }

    int amount = Integer.parseInt(args.get(0));
    if(town.bank.getAmount() < amount) {
        throw new MyTownCommandException("mytown.cmd.err.bank.withdraw", EconomyProxy.getCurrency(town.bank.getAmount()));
    }

    makeRefund(res.getPlayer(), amount);
    town.bank.addAmount(-amount);
    getDatasource().saveTownBank(town.bank);
    return CommandResponse.DONE;
}
 
Example #29
Source File: CommandsEveryone.java    From MyTown2 with The Unlicense 5 votes vote down vote up
@Command(
        name = "ranks",
        permission = "mytown.cmd.everyone.ranks",
        parentName = "mytown.cmd",
        syntax = "/town ranks <command>")
public static CommandResponse ranksCommand(ICommandSender sender, List<String> args) {
    return CommandResponse.SEND_HELP_MESSAGE;
}
 
Example #30
Source File: CommandsEveryone.java    From MyTown2 with The Unlicense 5 votes vote down vote up
@Command(
        name = "hide",
        permission = "mytown.cmd.everyone.borders.hide",
        parentName = "mytown.cmd.everyone.borders",
        syntax = "/town borders hide")
public static CommandResponse bordersHideCommand(ICommandSender sender, List<String> args) {
    Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
    Town town = getTownFromResident(res);

    town.townBlocksContainer.hide(res);
    ChatManager.send(sender, "mytown.notification.town.borders.hide");
    return CommandResponse.DONE;
}