Ejemplo n.º 1
0
 @EventHandler
 public Message onBlockAction(BlockActionEvent event) {
   int id = VanillaMaterials.getMinecraftId(event.getMaterial());
   if (id == -1) {
     return null;
   } else {
     return new BlockActionMessage(
         event.getBlock(), (short) id, event.getData1(), event.getData2(), getRepositionManager());
   }
 }
Ejemplo n.º 2
0
  @Command(
      aliases = {"give"},
      usage = "[player] <block> [amount] ",
      desc = "Lets a player spawn items",
      min = 1,
      max = 3)
  @CommandPermissions("vanilla.command.give")
  public void give(CommandContext args, CommandSource source) throws CommandException {
    int index = 0;
    Player player = null;

    if (args.length() != 1) {
      if (Spout.getEngine() instanceof Client) {
        throw new CommandException("You cannot search for players unless you are in server mode.");
      }
      player = Spout.getEngine().getPlayer(args.getString(index++), true);
    }

    if (player == null) {
      switch (args.length()) {
        case 3:
          throw new CommandException(args.getString(0) + " is not online.");
        case 2:
          index--;
        case 1:
          if (!(source instanceof Player)) {
            throw new CommandException("You must be a player to give yourself materials!");
          }

          player = (Player) source;
          break;
      }
    }

    Material material;
    if (args.isInteger(index)) {
      material = VanillaMaterials.getMaterial((short) args.getInteger(index));
    } else {
      String name = args.getString(index);

      if (name.contains(":")) {
        String[] parts = args.getString(index).split(":");
        material =
            VanillaMaterials.getMaterial(Short.parseShort(parts[0]), Short.parseShort(parts[1]));
      } else {
        material = Material.get(args.getString(index));
      }
    }

    if (material == null) {
      throw new CommandException(args.getString(index) + " is not a block!");
    }

    int count = args.getInteger(++index, 1);
    player.get(PlayerInventory.class).add(new ItemStack(material, count));
    source.sendMessage(
        plugin.getPrefix(),
        ChatStyle.BRIGHT_GREEN,
        "Gave ",
        ChatStyle.WHITE,
        player.getName() + " ",
        count,
        ChatStyle.BRIGHT_GREEN,
        " of ",
        ChatStyle.WHITE,
        material.getDisplayName());
  }