@Command(
      aliases = {"gamemode", "gm"},
      usage =
          "[player] <0|1|2|survival|creative|adventure> (0 = SURVIVAL, 1 = CREATIVE, 2 = ADVENTURE)",
      desc = "Change a player's game mode",
      min = 1,
      max = 2)
  @CommandPermissions("vanilla.command.gamemode")
  public void gamemode(CommandContext args, CommandSource source) throws CommandException {
    int index = 0;
    Player player;
    if (args.length() == 2) {
      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) {
        throw new CommandException(args.getString(0) + " is not online.");
      }
    } else {
      if (!(source instanceof Player)) {
        throw new CommandException("You must be a player to toggle your game mode.");
      }

      player = (Player) source;
    }

    if (!player.has(Human.class)) {
      throw new CommandException("Invalid player!");
    }

    GameMode mode;

    try {
      if (args.isInteger(index)) {
        mode = GameMode.get(args.getInteger(index));
      } else {
        mode = GameMode.get(args.getString(index));
      }
    } catch (Exception e) {
      throw new CommandException(
          "A game mode must be either a number between 0 and 2, 'CREATIVE', 'SURVIVAL' or 'ADVENTURE'");
    }

    player.get(Human.class).setGamemode(mode);

    if (!player.equals(source)) {
      source.sendMessage(
          plugin.getPrefix(),
          ChatStyle.WHITE,
          player.getName(),
          "'s ",
          ChatStyle.BRIGHT_GREEN,
          "gamemode has been changed to ",
          ChatStyle.WHITE,
          mode.name(),
          ChatStyle.BRIGHT_GREEN,
          ".");
    }
  }
 @Command(aliases = "clear", usage = "[player]", desc = "Clears your inventory", min = 0, max = 1)
 @CommandPermissions("vanilla.command.clear")
 public void clear(CommandContext args, CommandSource source) throws CommandException {
   if (args.length() == 0) {
     if (!(source instanceof Player)) {
       throw new CommandException("You must be a player to clear your own inventory.");
     }
     PlayerInventory inv = ((Player) source).get(PlayerInventory.class);
     if (inv == null) {
       source.sendMessage(plugin.getPrefix(), ChatStyle.RED, "You have no inventory!");
       return;
     }
     inv.clear();
   }
   if (args.length() == 1) {
     Player player = args.getPlayer(0, false);
     if (player == null) {
       source.sendMessage(plugin.getPrefix(), ChatStyle.RED, "Player is not online!");
       return;
     }
     PlayerInventory inv = player.get(PlayerInventory.class);
     if (inv == null) {
       source.sendMessage(plugin.getPrefix(), ChatStyle.RED, "Player has no inventory!");
       return;
     }
     player.sendMessage(
         plugin.getPrefix(), ChatStyle.BRIGHT_GREEN, "Your inventory has been cleared.");
     if (source instanceof Player && source.equals(player)) {
       return;
     }
   }
   source.sendMessage(plugin.getPrefix(), ChatStyle.BRIGHT_GREEN, "Inventory cleared.");
 }
  @Override
  protected void worldChanged(World world) {
    GameMode gamemode = world.getComponentHolder().getData().get(VanillaData.GAMEMODE);
    // The world the player is entering has a different gamemode...
    if (gamemode != null) {
      if (gamemode != getPlayer().getData().get(VanillaData.GAMEMODE)) {
        PlayerGameModeChangedEvent event =
            Spout.getEngine()
                .getEventManager()
                .callEvent(new PlayerGameModeChangedEvent(player, gamemode));
        if (!event.isCancelled()) {
          gamemode = event.getMode();
        }
      }
    } else {
      // The world has no gamemode setting in its map so default to the Player's GameMode.
      gamemode = getPlayer().getData().get(VanillaData.GAMEMODE);
    }
    Difficulty difficulty = world.getComponentHolder().getData().get(VanillaData.DIFFICULTY);
    Dimension dimension = world.getComponentHolder().getData().get(VanillaData.DIMENSION);
    WorldType worldType = world.getComponentHolder().getData().get(VanillaData.WORLD_TYPE);

    // TODO Handle infinite height
    if (first) {
      first = false;
      int entityId = player.getId();
      Server server = (Server) session.getEngine();
      PlayerLoginRequestMessage idMsg =
          new PlayerLoginRequestMessage(
              entityId,
              worldType.toString(),
              gamemode.getId(),
              (byte) dimension.getId(),
              difficulty.getId(),
              (byte) server.getMaxPlayers());
      player.getSession().send(false, true, idMsg);
      player.getSession().setState(State.GAME);
      for (int slot = 0; slot < 4; slot++) {
        ItemStack slotItem = owner.get(Human.class).getInventory().getArmor().get(slot);
        player.getSession().send(false, new EntityEquipmentMessage(entityId, slot, slotItem));
      }
    } else {
      player
          .getSession()
          .send(
              false,
              new PlayerRespawnMessage(
                  dimension.getId(),
                  difficulty.getId(),
                  gamemode.getId(),
                  256,
                  worldType.toString()));
    }

    Point pos = world.getSpawnPoint().getPosition();
    PlayerSpawnPositionMessage SPMsg =
        new PlayerSpawnPositionMessage((int) pos.getX(), (int) pos.getY(), (int) pos.getZ());
    player.getSession().send(false, SPMsg);
  }
示例#4
0
 private void evaluateCriteria(String key, int value, boolean add, String... criteria) {
   for (Player player : ((Server) Spout.getEngine()).getOnlinePlayers()) {
     Scoreboard scoreboard = player.get(Scoreboard.class);
     if (scoreboard != null) {
       scoreboard.evaluateCriteria(key, value, add, criteria);
     }
   }
 }
  @Command(
      aliases = "xp",
      usage = "[player] <amount>",
      desc = "Give/take experience from a player",
      min = 1,
      max = 2)
  @CommandPermissions("vanilla.command.xp")
  public void xp(CommandContext args, CommandSource source) throws CommandException {
    // If source is player
    if (args.length() == 1) {
      if (source instanceof Player) {
        @SuppressWarnings("unused")
        Player sender = (Player) source;
        int amount = args.getInteger(0);
        source.sendMessage(
            plugin.getPrefix(),
            ChatStyle.BRIGHT_GREEN,
            "You have been given ",
            ChatStyle.WHITE,
            amount,
            ChatStyle.BRIGHT_GREEN,
            " xp.");
        // TODO: Give player 'amount' of xp.
      } else {
        throw new CommandException("You must be a player to give yourself xp.");
      }
    } else {
      if (Spout.getEngine() instanceof Client) {
        throw new CommandException("You cannot search for players unless you are in server mode.");
      }
      Player player = ((Server) Spout.getEngine()).getPlayer(args.getString(0), true);
      if (player != null) {
        short amount = (short) args.getInteger(1);
        LevelComponent level = player.get(LevelComponent.class);

        if (level == null) {
          return;
        }

        if (amount > 0) {
          level.addExperience(amount);
        } else {
          level.removeExperience(amount);
        }
        player.sendMessage(
            plugin.getPrefix(),
            ChatStyle.BRIGHT_GREEN,
            "Your experience has been set to ",
            ChatStyle.WHITE,
            amount,
            ChatStyle.BRIGHT_GREEN,
            ".");
      } else {
        throw new CommandException(args.getString(0) + " is not online.");
      }
    }
  }
示例#6
0
 private void updateProgressArrow(Player player) {
   float increment = 0;
   if (getBrewTime() >= 0) {
     increment = (BREW_TIME_INCREMENT - getBrewTime()) * 20;
   }
   player
       .get(WindowHolder.class)
       .getActiveWindow()
       .setProperty(BrewingStandProperty.PROGRESS_ARROW, (int) increment);
 }
示例#7
0
 @Override
 public BlockIterator getAlignedBlocks() {
   Player player = (Player) getOwner();
   Transform ptr = player.get(PlayerHead.class).getHeadTransform();
   Transform tr = new Transform();
   tr.setRotation(
       QuaternionMath.rotationTo(Vector3.FORWARD, ptr.getRotation().getDirection().multiply(-1)));
   tr.setPosition(ptr.getPosition());
   return new BlockIterator(player.getWorld(), tr, getRange());
 }
示例#8
0
 @Override
 public boolean open(Player player) {
   BrewingStandOpenEvent event =
       player.getEngine().getEventManager().callEvent(new BrewingStandOpenEvent(this, player));
   if (!event.isCancelled()) {
     player
         .get(WindowHolder.class)
         .openWindow(new BrewingStandWindow(player, this, getInventory()));
     return true;
   }
   return false;
 }
示例#9
0
  @EventHandler(order = Order.LATEST)
  public void entityHealth(EntityHealthChangeEvent event) {
    Entity entity = event.getEntity();
    Engine engine = Spout.getEngine();
    if (!(entity instanceof Player) || !(engine instanceof Server)) {
      return;
    }

    Player player = (Player) entity;
    evaluateCriteria(
        player.getName(),
        (int) (player.get(Health.class).getHealth() + event.getChange()),
        false,
        Objective.CRITERIA_HEALTH);
  }
 @Command(
     aliases = {"kill"},
     usage = "[player]",
     desc = "Kill yourself or another player",
     min = 0,
     max = 1)
 @CommandPermissions("vanilla.command.kill")
 public void kill(CommandContext args, CommandSource source) throws CommandException {
   if (args.length() == 0) {
     if (!(source instanceof Player)) {
       throw new CommandException("Don't be silly...you cannot kill yourself as the console.");
     }
     ((Player) source).get(HealthComponent.class).kill(HealthChangeCause.COMMAND);
   } else {
     if (Spout.getEngine() instanceof Client) {
       throw new CommandException("You cannot search for players unless you are in server mode.");
     }
     Player victim = ((Server) Spout.getEngine()).getPlayer(args.getString(0), true);
     if (victim != null) {
       victim.get(HealthComponent.class).kill(HealthChangeCause.COMMAND);
     }
   }
 }
  @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());
  }