Beispiel #1
0
 @Override
 public DataContainer toContainer() {
   DataContainer container = new MemoryDataContainer();
   container.set(DataQuery.of("myInt"), this.testInt);
   container.set(DataQuery.of("myDouble"), this.testDouble);
   container.set(DataQuery.of("myString"), this.testString);
   container.set(DataQuery.of("myStringList"), Arrays.asList(this.testList));
   return container;
 }
  public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException {
    if (src instanceof Player) {
      Player player = (Player) src;

      if (player.getItemInHand().isPresent()) {
        ItemStack itemInHand = player.getItemInHand().get();
        player.sendMessage(
            Text.of(
                TextColors.GOLD,
                "The ID of the item in your hand is: ",
                TextColors.GRAY,
                itemInHand.getItem().getName()));
        player.sendMessage(
            Text.of(
                TextColors.GOLD,
                "The meta of the item in your hand is: ",
                TextColors.GRAY,
                itemInHand.toContainer().get(DataQuery.of("UnsafeDamage")).get().toString()));
      } else {
        player.sendMessage(
            Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must hold an item."));
      }
    } else {
      src.sendMessage(
          Text.of(
              TextColors.DARK_RED,
              "Error! ",
              TextColors.RED,
              "You must be an in-game player to use this command."));
    }

    return CommandResult.success();
  }
Beispiel #3
0
@Plugin(
    id = "io.github.hsyyid.commandsigns",
    name = "CommandSigns",
    version = "1.3",
    description =
        "This plugins enables server admins to create signs that run a list of commands, targeting the player who clicks them.")
public class CommandSigns {
  public static List<CommandSignModifier> commandSignModifiers = Lists.newArrayList();
  public static Set<UUID> listCommands = Sets.newHashSet();

  // Keys
  public static final Key<Value<Boolean>> IS_COMMAND_SIGN =
      KeyFactory.makeSingleKey(Boolean.class, Value.class, DataQuery.of("IsCommandSign"));
  public static final Key<Value<Boolean>> IS_ONE_TIME =
      KeyFactory.makeSingleKey(Boolean.class, Value.class, DataQuery.of("IsOneTime"));
  public static final Key<Value<String>> USERS =
      KeyFactory.makeSingleKey(String.class, Value.class, DataQuery.of("Users"));
  public static final Key<ListValue<String>> COMMANDS =
      KeyFactory.makeListKey(String.class, DataQuery.of("Commands"));

  @Inject private Logger logger;

  public Logger getLogger() {
    return logger;
  }

  @Inject
  @DefaultConfig(sharedRoot = true)
  private File dConfig;

  @Inject
  @DefaultConfig(sharedRoot = true)
  private ConfigurationLoader<CommentedConfigurationNode> confManager;

  @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!");
  }
}