コード例 #1
0
ファイル: MyChunks.java プロジェクト: GameModsBR/MyChunks
  @Listener
  public void onServerStarting(GameStartingServerEvent event) {
    GlobalCommands globalCommands = new GlobalCommands(this);
    CommandSpec map =
        CommandSpec.builder()
            .description(Text.of("All commands related to the chunk protection"))
            .executor(globalCommands::map)
            .build();

    CommandSpec claim =
        CommandSpec.builder()
            .description(Text.of("Claims the chunk that you are standing"))
            .executor(globalCommands::claim)
            .build();

    CommandSpec chunk =
        CommandSpec.builder()
            .description(Text.of("Commands related to chunk protection"))
            .child(map, "map")
            .child(claim, "claim")
            .build();

    CommandSpec mychunk =
        CommandSpec.builder()
            .description(Text.of("All mychunk commands"))
            .child(chunk, "chunk", "c")
            .build();

    Sponge.getCommandManager().register(this, chunk, "chunk");
    Sponge.getCommandManager().register(this, mychunk, "mychunk");
  }
コード例 #2
0
ファイル: CommandSigns.java プロジェクト: hsyyid/CommandSigns
  @Listener
  public void onServerInit(GameInitializationEvent event) {
    getLogger().info("CommandSigns loading...");

    HashMap<List<String>, CommandSpec> subcommands = new HashMap<List<String>, CommandSpec>();

    subcommands.put(
        Arrays.asList("setcommandsign"),
        CommandSpec.builder()
            .description(Text.of("Creates CommandSigns"))
            .permission("commandsigns.setcommandsign")
            .arguments(
                GenericArguments.seq(
                    GenericArguments.onlyOne(GenericArguments.bool(Text.of("one time"))),
                    GenericArguments.onlyOne(
                        GenericArguments.remainingJoinedStrings(Text.of("command")))))
            .executor(new SetCommandSignExecutor())
            .build());

    subcommands.put(
        Arrays.asList("addcommand"),
        CommandSpec.builder()
            .description(Text.of("Adds Command to CommandSign"))
            .permission("commandsigns.addcommand")
            .arguments(
                GenericArguments.onlyOne(
                    GenericArguments.remainingJoinedStrings(Text.of("command"))))
            .executor(new AddCommandExecutor())
            .build());

    subcommands.put(
        Arrays.asList("removecommand"),
        CommandSpec.builder()
            .description(Text.of("Removes Command on CommandSign"))
            .permission("commandsigns.removecommand")
            .arguments(
                GenericArguments.onlyOne(GenericArguments.integer(Text.of("command number"))))
            .executor(new RemoveCommandExecutor())
            .build());

    subcommands.put(
        Arrays.asList("listcommands"),
        CommandSpec.builder()
            .description(Text.of("List Commands on CommandSign"))
            .permission("commandsigns.listcommands")
            .executor(new ListCommandsExecutor())
            .build());

    CommandSpec commandSignsCommandSpec =
        CommandSpec.builder()
            .description(Text.of("CommandSigns Command"))
            .permission("commandsigns.command")
            .executor(new CommandSignsExecutor())
            .children(subcommands)
            .build();

    Sponge.getCommandManager()
        .register(this, commandSignsCommandSpec, "cs", "commandsign", "commandsigns");

    // One-Time
    Sponge.getDataManager()
        .register(IsOneTimeData.class, ImmutableIsOneTimeData.class, new IsOneTimeDataBuilder());
    Sponge.getDataManager()
        .register(
            SpongeIsOneTimeData.class,
            ImmutableSpongeIsOneTimeData.class,
            new IsOneTimeDataBuilder());

    // IsCommandSign
    Sponge.getDataManager()
        .register(
            IsCommandSignData.class,
            ImmutableIsCommandSignData.class,
            new IsCommandSignDataBuilder());
    Sponge.getDataManager()
        .register(
            SpongeIsCommandSignData.class,
            ImmutableSpongeIsCommandSignData.class,
            new IsCommandSignDataBuilder());

    // Commands
    Sponge.getDataManager()
        .register(CommandsData.class, ImmutableCommandsData.class, new CommandsDataBuilder());
    Sponge.getDataManager()
        .register(
            SpongeCommandsData.class, ImmutableSpongeCommandsData.class, new CommandsDataBuilder());

    // Users
    Sponge.getDataManager()
        .register(UsersData.class, ImmutableUsersData.class, new UsersDataBuilder());
    Sponge.getDataManager()
        .register(SpongeUsersData.class, ImmutableSpongeUsersData.class, new UsersDataBuilder());

    Sponge.getEventManager().registerListeners(this, new HitBlockListener());
    Sponge.getEventManager().registerListeners(this, new InteractBlockListener());

    getLogger().info("-----------------------------");
    getLogger().info("CommandSigns was made by HassanS6000!");
    getLogger().info("Please post all errors on the Sponge Thread or on GitHub!");
    getLogger().info("Have fun, and enjoy! :D");
    getLogger().info("-----------------------------");
    getLogger().info("CommandSigns loaded!");
  }