Beispiel #1
0
  @Override
  public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    if (!args.hasAny("old")) {
      src.sendMessage(invalidArg());
      return CommandResult.empty();
    }

    String oldWorldName = args.<String>getOne("old").get();

    if (oldWorldName.equalsIgnoreCase("@w")) {
      if (src instanceof Player) {
        oldWorldName = ((Player) src).getWorld().getName();
      }
    }

    if (!args.hasAny("new")) {
      src.sendMessage(invalidArg());
      return CommandResult.empty();
    }

    String newWorldName = args.<String>getOne("new").get();

    for (WorldProperties world : Main.getGame().getServer().getAllWorldProperties()) {
      if (!world.getWorldName().equalsIgnoreCase(newWorldName)) {
        continue;
      }

      src.sendMessage(Text.of(TextColors.DARK_RED, newWorldName, " already exists"));
      return CommandResult.empty();
    }

    if (!Main.getGame().getServer().getWorld(oldWorldName).isPresent()) {
      src.sendMessage(Text.of(TextColors.DARK_RED, "World ", oldWorldName, " does not exists"));
      return CommandResult.empty();
    }

    Optional<WorldProperties> copy = null;
    try {
      copy =
          Main.getGame()
              .getServer()
              .copyWorld(
                  Main.getGame().getServer().getWorld(oldWorldName).get().getProperties(),
                  newWorldName)
              .get();
    } catch (InterruptedException | ExecutionException e) {
      e.printStackTrace();
    }

    if (!copy.isPresent()) {
      src.sendMessage(Text.of(TextColors.DARK_RED, "Could not copy ", oldWorldName));
      return CommandResult.empty();
    }

    src.sendMessage(Text.of(TextColors.DARK_GREEN, oldWorldName, " copied to ", newWorldName));

    return CommandResult.success();
  }
Beispiel #2
0
 @Override
 public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException {
   int expLevel = ctx.<Integer>getOne("exp").get();
   Player player = ctx.<Player>getOne("target").get();
   player.offer(Keys.TOTAL_EXPERIENCE, player.get(Keys.TOTAL_EXPERIENCE).get() - expLevel);
   src.sendMessage(
       Text.of(
           TextColors.GREEN,
           "Success! ",
           TextColors.YELLOW,
           "Took " + expLevel + " experience from " + player.getName() + "."));
   return CommandResult.success();
 }
  @Override
  public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {

    if (src instanceof Player) {
      Player player = (Player) src;
      Optional<String> optionalKitName = args.getOne("kitName");
      Optional<String> optionalArgs = args.getOne("args");
      if (optionalKitName.isPresent()) {
        String kitName = optionalKitName.get().toUpperCase();
        CommandKitManager kitManager = plugin.getKitManager();
        if (kitManager.isKit(kitName)) {
          CommandKit kit = kitManager.getKit(kitName);
          if (kit.hasPermission(player)) {
            if (kit.hasRequirements(player)) {
              if (kitManager.checkInterval(player, kitName) == 0) {
                String[] argArray = new String[0];
                if (optionalArgs.isPresent()) {
                  argArray = optionalArgs.get().split(" ");
                }
                kit.execute(player, argArray);
                kitManager.markInterval(player, kitName);
              } else {
                src.sendMessage(
                    Text.of(
                        TextColors.RED,
                        Strings.getInstance().getStrings().get("intervalDenial")
                            + kitManager.checkInterval(player, kitName)));
              }
            } else {
              src.sendMessage(
                  Text.of(
                      TextColors.RED, Strings.getInstance().getStrings().get("requirementDenial")));
            }
          } else {
            src.sendMessage(
                Text.of(
                    TextColors.RED, Strings.getInstance().getStrings().get("permissionDenial")));
          }
        } else {
          src.sendMessage(
              Text.of(TextColors.RED, Strings.getInstance().getStrings().get("unknownKit")));
        }
        return CommandResult.success();
      }
      src.sendMessage(
          Text.of(TextColors.RED, Strings.getInstance().getStrings().get("unknownKit")));
    }
    return CommandResult.empty();
  }
Beispiel #4
0
  @Override
  public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {

    String name = args.<String>getOne("name").get();
    if (src instanceof Player && EzpzPvpKit.getInstance().isQueueExisting(name)) {
      Player player = (Player) src;
      PvPPlayer pvpPlayer = EzpzPvpKit.getInstance().getPlayer(player.getIdentifier());
      Team team = EzpzPvpKit.getInstance().getTeam(pvpPlayer.getTeam());
      DuelQueue queue = EzpzPvpKit.getInstance().getQueue(name);
      // Size ?
      if (team.getSize() != queue.getSize())
        Utils.sendKitMessage(
            player, Text.of(TextColors.RED, "Party size doesn't match queue size"));
      // Is in duel ?
      else if (team.getInMatch())
        Utils.sendKitMessage(player, Text.of(TextColors.RED, "Cannot join queue in duel"));
      else {
        // is in other queue ?
        if (team.getQueue() != null) EzpzPvpKit.getInstance().getQueue(team.getQueue()).leave(team);
        queue.join(team);
        for (String it : team.getPlayers())
          Utils.sendKitMessage(
              EzpzPvpKit.getInstance().getPlayer(it).getPlayer(),
              Text.of("You joined queue : " + name));
      }

    } else if (src instanceof Player && !EzpzPvpKit.getInstance().isQueueExisting(name))
      Utils.sendKitMessage((Player) src, Text.of(TextColors.RED, "this queue doesn't exist"));
    else if (src instanceof ConsoleSource) Utils.sendMessageC(src);
    else if (src instanceof CommandBlockSource) Utils.sendMessageCB(src);

    return CommandResult.success();
  }
Beispiel #5
0
  @Override
  public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    Optional<Player> opl = this.getUser(Player.class, src, player, args);
    if (!opl.isPresent()) {
      return CommandResult.empty();
    }

    Player pl = opl.get();

    InternalQuickStartUser uc = plugin.getUserLoader().getUser(pl);
    boolean fly = args.<Boolean>getOne(toggle).orElse(!uc.isFlying());

    if (!uc.setFlying(fly)) {
      src.sendMessages(Text.of(TextColors.RED, Util.getMessageWithFormat("command.fly.error")));
      return CommandResult.empty();
    }

    if (pl != src) {
      src.sendMessages(
          Text.of(
              TextColors.GREEN,
              MessageFormat.format(
                  Util.getMessageWithFormat(
                      fly ? "command.fly.player.on" : "command.fly.player.off"),
                  pl.getName())));
    }

    pl.sendMessage(
        Text.of(
            TextColors.GREEN,
            Util.getMessageWithFormat(fly ? "command.fly.on" : "command.fly.off")));
    return CommandResult.success();
  }
Beispiel #6
0
  @Override
  public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
    // Get the home.
    Optional<WarpLocation> owl = args.<WarpLocation>getOne(home);
    if (!owl.isPresent()) {
      owl = plugin.getUserLoader().getUser(src).getHome("home");

      if (!owl.isPresent()) {
        src.sendMessage(
            Text.of(TextColors.RED, Util.getMessageWithFormat("args.home.nohome", "home")));
        return CommandResult.empty();
      }
    }

    WarpLocation wl = owl.get();

    // Warp to it safely.
    if (src.setLocationAndRotationSafely(wl.getLocation(), wl.getRotation())) {
      src.sendMessage(
          Text.of(
              TextColors.GREEN, Util.getMessageWithFormat("command.home.success", wl.getName())));
      return CommandResult.success();
    } else {
      src.sendMessage(
          Text.of(TextColors.RED, Util.getMessageWithFormat("command.home.fail", wl.getName())));
      return CommandResult.empty();
    }
  }
  public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException {
    if (src instanceof Player) {
      Player player = (Player) src;
      Player target = ctx.<Player>getOne("target").get();

      player.sendMessage(Text.of(TextColors.DARK_AQUA, "You have slapped ", target.getName()));
      target.sendMessage(
          Text.of(TextColors.DARK_AQUA, "You have been slapped by ", player.getName()));
    }
    return CommandResult.success();
  }
Beispiel #8
0
  public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException {
    setLocalVariables();
    Optional<Player> player = ctx.<Player>getOne("player");
    // if reason is not there use default reason
    Optional<String> oReason = ctx.<String>getOne("reason");

    if (oReason.isPresent()) {
      String reason = oReason.get();
      if (player.isPresent()) {
        Player players = player.get();
        players
            .getPlayer()
            .get()
            .kick(
                Text.builder()
                    .append(
                        Text.of(
                            TextColors.DARK_RED,
                            "You have been tempbanned!\n",
                            TextColors.RED,
                            "Reason: "))
                    .append(TextSerializers.formattingCode('&').deserialize(reason), Text.of("\n"))
                    .build());
        return CommandResult.success();
      }
      src.sendMessage(
          Text.of(
              TextColors.RED, "Need to specify a player. Correct useage: /kick <player> <reason>"));
      return CommandResult.empty();
    } else {
      src.sendMessage(
          Text.of(
              TextColors.RED, "Need to specify a Reason. Correct useage: /kick <player> <reason>"));
      return CommandResult.empty();
    }
  }
  public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException {
    EntityType entityType = ctx.<EntityType>getOne("mob").get();

    if (src instanceof Player) {
      Player player = (Player) src;

      ItemStack mobSpawnerStack =
          ItemStack.builder().itemType(ItemTypes.MOB_SPAWNER).quantity(1).build();
      Optional<MobSpawnerData> mobSpawnerData = mobSpawnerStack.getOrCreate(MobSpawnerData.class);

      if (mobSpawnerData.isPresent()) {
        MobSpawnerData data = mobSpawnerData.get();
        data.nextEntityToSpawn().set(entityType, null);

        if (mobSpawnerStack.offer(data).isSuccessful()) {
          player.setItemInHand(mobSpawnerStack);
          player.sendMessage(
              Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Created mob spawner."));
        } else {
          player.sendMessage(
              Text.of(
                  TextColors.DARK_RED,
                  "Error! ",
                  TextColors.RED,
                  "Failed to set mob spawner entity."));
        }
      } else {
        player.sendMessage(
            Text.of(
                TextColors.DARK_RED, "Error! ", TextColors.RED, "Failed to create mob spawner."));
      }
    } else {
      src.sendMessage(
          Text.of(
              TextColors.DARK_RED,
              "Error! ",
              TextColors.RED,
              "Must be an in-game player to use /mobspawner!"));
    }

    return CommandResult.success();
  }
  @Override
  public CommandResult execute(CommandSource source, CommandContext args) throws CommandException {
    int index = args.<Integer>getOne("index").get();

    List<String> messages = plugin.getConfigManager().getConfiguration().getMessages();
    if (index > messages.size()) {
      source.sendMessage(
          Text.of(
              TextColors.DARK_RED,
              index + '/' + messages.size() + " Number is higher than the available messages"));
    } else {
      Text removedMessage = plugin.translateColorCodes(messages.remove(index - 1));
      plugin.getConfigManager().save();

      source.sendMessage(Text.of(TextColors.DARK_GREEN, "Removed the following message"));
      source.sendMessage(removedMessage);
      return CommandResult.builder().successCount(1).build();
    }

    return CommandResult.success();
  }
Beispiel #11
0
  @Override
  public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    if (!args.hasAny("name")) {
      src.sendMessage(invalidArg());
      return CommandResult.empty();
    }
    String worldName = args.<String>getOne("name").get();

    if (worldName.equalsIgnoreCase("@w") && src instanceof Player) {
      worldName = ((Player) src).getWorld().getName();
    }

    Collection<WorldProperties> worlds = new ArrayList<>();

    if (worldName.equalsIgnoreCase("@a")) {
      worlds = Main.getGame().getServer().getAllWorldProperties();
    } else {
      if (!Main.getGame().getServer().getWorldProperties(worldName).isPresent()) {
        src.sendMessage(Text.of(TextColors.DARK_RED, worldName, " does not exist"));
        return CommandResult.empty();
      }
      worlds.add(Main.getGame().getServer().getWorldProperties(worldName).get());
    }

    String value = null;

    if (args.hasAny("value")) {
      value = args.<String>getOne("value").get();

      if ((!value.equalsIgnoreCase("true")) && (!value.equalsIgnoreCase("false"))) {
        src.sendMessage(invalidArg());
        return CommandResult.empty();
      }
    }

    List<Text> list = new ArrayList<>();

    for (WorldProperties properties : worlds) {
      if (value == null) {
        list.add(
            Text.of(
                TextColors.GREEN,
                properties.getWorldName(),
                ": ",
                TextColors.WHITE,
                Boolean.toString(properties.isHardcore()).toUpperCase()));
        continue;
      }

      properties.setHardcore(Boolean.getBoolean(value));

      src.sendMessage(
          Text.of(
              TextColors.DARK_GREEN,
              "Set hardcore of ",
              worldName,
              " to ",
              TextColors.YELLOW,
              value.toUpperCase()));
    }

    if (!list.isEmpty()) {
      if (src instanceof Player) {
        PaginationList.Builder pages =
            Main.getGame().getServiceManager().provide(PaginationService.class).get().builder();

        pages.title(
            Text.builder()
                .color(TextColors.DARK_GREEN)
                .append(Text.of(TextColors.GREEN, "Hardcore"))
                .build());

        pages.contents(list);

        pages.sendTo(src);
      } else {
        for (Text text : list) {
          src.sendMessage(text);
        }
      }
    }

    return CommandResult.success();
  }
  public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException {
    Optional<Player> optionalTarget = ctx.<Player>getOne("player");

    if (!optionalTarget.isPresent()) {
      if (src instanceof Player) {
        Player player = (Player) src;
        BlockRay<World> playerBlockRay = BlockRay.from(player).blockLimit(350).build();

        Location<World> spawnLocation = null;
        int i = 0;

        while (playerBlockRay.hasNext()) {
          // TODO: Come up with a better way of making sure it doesn't hit the player.
          i++;

          BlockRayHit<World> currentHitRay = playerBlockRay.next();

          if (i > 5) {
            // We can set the spawn location, so break here.
            spawnLocation = currentHitRay.getLocation();
            break;
          }
        }

        Vector3d velocity = player.getTransform().getRotationAsQuaternion().getDirection();
        spawnEntity(spawnLocation, velocity, player);
        player.sendMessage(
            Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Created Fireball!"));
      } else if (src instanceof ConsoleSource) {
        src.sendMessage(
            Text.of(
                TextColors.DARK_RED,
                "Error! ",
                TextColors.RED,
                "Must be an in-game player to use /fireball!"));
      } else if (src instanceof CommandBlockSource) {
        src.sendMessage(
            Text.of(
                TextColors.DARK_RED,
                "Error! ",
                TextColors.RED,
                "Must be an in-game player to use /fireball!"));
      }
    } else {
      Player player = optionalTarget.get();
      Location<World> playerLocation = player.getLocation();

      Vector3d velocity = player.getTransform().getRotationAsQuaternion().getDirection();
      spawnEntity(playerLocation, velocity, src);
      player.sendMessage(
          Text.of(
              TextColors.GRAY, src.getName(), TextColors.GOLD, " has struck you with a fireball."));
      src.sendMessage(
          Text.of(
              TextColors.GREEN,
              "Success! ",
              TextColors.YELLOW,
              "Struck " + player.getName() + " with fireball."));
    }

    return CommandResult.success();
  }