示例#1
0
  @EventHandler(order = Order.LATEST)
  public void entityDeath(EntityDeathEvent event) {
    Entity entity = event.getEntity();
    Engine engine = Spout.getEngine();

    // kill count criteria
    Object lastDamager = event.getLastDamager();
    if (lastDamager instanceof Player) {
      Player killer = (Player) lastDamager;
      String killerName = killer.getName();
      String[] criteria = {
        Objective.CRITERIA_TOTAL_KILL_COUNT, Objective.CRITERIA_PLAYER_KILL_COUNT
      };
      if (entity instanceof Player) {
        // killed a player? update total and player kill count
        evaluateCriteria(killerName, 1, true, criteria);
      } else {
        // just an entity? only update total kill count
        evaluateCriteria(killerName, 1, true, criteria[0]);
      }
    }

    if (!(entity instanceof Player) || !(engine instanceof Server)) {
      return;
    }

    // player death criteria
    Player player = (Player) entity;
    evaluateCriteria(player.getName(), 1, true, Objective.CRITERIA_DEATH_COUNT);
  }
  @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,
          ".");
    }
  }
示例#3
0
 // TODO Make method faster and better. [quick fix]
 @SuppressWarnings("static-access")
 @EventHandler
 public void onChat(PlayerChatEvent e) {
   Player p = e.getPlayer();
   String Nickname = plugin.PDC().getNode(p.getName() + ".GeneralData.prefix").getString();
   e.NAME.equals(Nickname);
   e.setFormat(
       new ChatArguments(
           "[",
           plugin.PharseStringColors(
               plugin.PDC().getNode(p.getName() + ".GeneralData.prefix").getString()),
           ChatStyle.BRIGHT_GREEN,
           e.NAME,
           ChatStyle.WHITE,
           "]",
           ChatStyle.YELLOW,
           ": ",
           ChatStyle.WHITE,
           e.MESSAGE));
 }
 @Override
 public void onInteract(final EntityInteractEvent<?> event) {
   if (event instanceof PlayerInteractEntityEvent) {
     final PlayerInteractEntityEvent pie = (PlayerInteractEntityEvent) event;
     final Player player = (Player) pie.getEntity();
     switch (pie.getAction()) {
       case RIGHT_CLICK:
         // TODO: Make player enter Minecart here
         System.out.println("MINECART ENTER: " + player.getName());
     }
   }
 }
示例#5
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 = {"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());
  }