コード例 #1
1
  @Override
  public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
    Player player = event.getPlayer();

    String[] split = event.getMessage().split(" ");
    int numParams = split.length - 1;
    if (!(plugin.optionsMap.containsKey("oncommand|" + split[0])
        || plugin.optionsMap.containsKey("oncommand|" + split[0] + "|" + numParams)
        || plugin.optionsMap.containsKey("oncommand|" + split[0] + "|override")
        || plugin.optionsMap.containsKey("oncommand|" + split[0] + "|override|" + numParams)))
      return;

    List<String> replaceThese = new LinkedList<String>();
    List<String> withThese = new LinkedList<String>();
    /* Build parameter list */
    StringBuilder params = new StringBuilder();
    StringBuilder reverseParams = new StringBuilder();
    String prefix = "";
    int max = split.length;
    for (int i = 1; i < max; i++) {
      params.append(prefix + split[i]);
      reverseParams.insert(0, split[max - i] + prefix);
      prefix = " ";

      replaceThese.add("<<param" + Integer.toString(i) + ">>");
      withThese.add(split[i]);

      replaceThese.add("<<param" + Integer.toString(i) + "->>");
      withThese.add(params.toString());

      replaceThese.add("<<param" + Integer.toString(max - i) + "\\+>>");
      withThese.add(reverseParams.toString());
    }
    replaceThese.add("<<params>>");
    withThese.add(params.toString());
    String[] replaceTheseArray = replaceThese.toArray(new String[replaceThese.size()]);
    String[] withTheseArray = withThese.toArray(new String[withThese.size()]);

    plugin.triggerMessages(player, "oncommand|" + split[0], replaceTheseArray, withTheseArray);

    if (split[0].equalsIgnoreCase("/rTriggers")) {
      plugin.triggerMessages(player, "onrTriggers", replaceTheseArray, withTheseArray);
      event.setCancelled(true);
    }

    if (plugin.triggerMessages(
            player, "oncommand|" + split[0] + "|override", replaceTheseArray, withTheseArray)
        || plugin.triggerMessages(
            player,
            "oncommand|" + split[0] + "|override|" + numParams,
            replaceTheseArray,
            withTheseArray)) {
      event.setCancelled(true);
    }

    return;
  }
コード例 #2
0
 @EventHandler
 public void HeMan(PlayerChatEvent e) {
   if (e.isCancelled()) return;
   if (!e.getMessage().matches("(?i)by the power of gr[a|e]yskull!?")) return;
   Player p = e.getPlayer();
   if (!plugin.isAuthorized(p, "rcmds.heman")) return;
   ItemStack is = p.getItemInHand();
   if (is.getType() != Material.DIAMOND_SWORD) return;
   if (is.getEnchantments().isEmpty()) return;
   e.setCancelled(true);
   p.getWorld().strikeLightningEffect(p.getLocation());
   Matcher m = Pattern.compile("(?i)by the power of gr[a|e]yskull!?").matcher(e.getMessage());
   StringBuilder sb = new StringBuilder();
   int last = 0;
   while (m.find()) {
     sb.append(e.getMessage().substring(last, m.start()));
     sb.append(m.group(0).toUpperCase());
     last = m.end();
   }
   sb.append(e.getMessage().substring(last));
   plugin
       .getServer()
       .broadcastMessage(
           e.getFormat().replaceAll("(?i)by the power of gr[a|e]yskull!?", sb.toString()));
   e.setFormat("");
   List<PotionEffect> effects = new ArrayList<PotionEffect>();
   effects.add(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 1200, 2));
   effects.add(new PotionEffect(PotionEffectType.REGENERATION, 1200, 2));
   effects.add(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 1200, 2));
   effects.add(new PotionEffect(PotionEffectType.SPEED, 1200, 2));
   p.addPotionEffects(effects);
 }
コード例 #3
0
  public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.isCancelled()) {
      return;
    }
    Action action = event.getAction();
    if (action == Action.RIGHT_CLICK_BLOCK || action == Action.RIGHT_CLICK_AIR) {
      Block block = event.getClickedBlock();
      Material type = block.getType();
      Player player = event.getPlayer();

      GlobalConfiguration cfg = plugin.getGlobalConfiguration();
      WorldConfiguration wcfg = cfg.getWorldConfig(event.getClickedBlock().getWorld().getName());

      if (wcfg.useRegions && player.getItemInHand().getTypeId() == wcfg.regionWand) {
        Vector pt = toVector(block);

        RegionManager mgr =
            plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
        ApplicableRegionSet app = mgr.getApplicableRegions(pt);
        List<String> regions = mgr.getApplicableRegionsIDs(pt);

        if (regions.size() > 0) {
          player.sendMessage(
              ChatColor.YELLOW
                  + "Can you build? "
                  + (app.canBuild(BukkitPlayer.wrapPlayer(plugin, player)) ? "Yes" : "No"));

          StringBuilder str = new StringBuilder();
          for (Iterator<String> it = regions.iterator(); it.hasNext(); ) {
            str.append(it.next());
            if (it.hasNext()) {
              str.append(", ");
            }
          }

          player.sendMessage(ChatColor.YELLOW + "Applicable regions: " + str.toString());
        } else {
          player.sendMessage(ChatColor.YELLOW + "WorldGuard: No defined regions here!");
        }
      }

      if (block.getType() == Material.CHEST
          || block.getType() == Material.DISPENSER
          || block.getType() == Material.FURNACE
          || block.getType() == Material.BURNING_FURNACE
          || block.getType() == Material.NOTE_BLOCK) {
        if (wcfg.useRegions) {
          Vector pt = toVector(block);
          LocalPlayer localPlayer = BukkitPlayer.wrapPlayer(plugin, player);
          RegionManager mgr =
              plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());

          if (!plugin.hasPermission(player, "region.bypass")) {
            ApplicableRegionSet set = mgr.getApplicableRegions(pt);
            if (!set.isStateFlagAllowed(Flags.CHEST_ACCESS) && !set.canBuild(localPlayer)) {
              player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
              event.setCancelled(true);
              return;
            }
          }
        }
      }

      if (wcfg.useRegions && (type == Material.LEVER || type == Material.STONE_BUTTON)) {
        Vector pt = toVector(block);
        RegionManager mgr =
            cfg.getWorldGuardPlugin()
                .getGlobalRegionManager()
                .getRegionManager(player.getWorld().getName());
        ApplicableRegionSet applicableRegions = mgr.getApplicableRegions(pt);
        LocalPlayer localPlayer = BukkitPlayer.wrapPlayer(plugin, player);

        if (!applicableRegions.isStateFlagAllowed(Flags.LEVER_AND_BUTTON, localPlayer)) {
          player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
          event.setCancelled(true);
          return;
        }
      }

      if (wcfg.useRegions && type == Material.CAKE_BLOCK) {

        Vector pt = toVector(block);

        if (!cfg.canBuild(player, pt)) {
          player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");

          byte newData = (byte) (block.getData() - 1);
          newData = newData < 0 ? 0 : newData;

          block.setData(newData);
          player.setHealth(player.getHealth() - 3);

          return;
        }
      }

      if (wcfg.useRegions
          && wcfg.useiConomy
          && cfg.getiConomy() != null
          && (type == Material.SIGN_POST || type == Material.SIGN || type == Material.WALL_SIGN)) {
        BlockState blockstate = block.getState();

        if (((Sign) blockstate).getLine(0).equalsIgnoreCase("[WorldGuard]")
            && ((Sign) blockstate).getLine(1).equalsIgnoreCase("For sale")) {
          String regionId = ((Sign) blockstate).getLine(2);
          // String regionComment = ((Sign)block).getLine(3);

          if (regionId != null && regionId != "") {
            RegionManager mgr =
                cfg.getWorldGuardPlugin()
                    .getGlobalRegionManager()
                    .getRegionManager(player.getWorld().getName());
            ProtectedRegion region = mgr.getRegion(regionId);

            if (region != null) {
              RegionFlagContainer flags = region.getFlags();

              if (flags.getBooleanFlag(Flags.BUYABLE).getValue(false)) {
                if (iConomy.getBank().hasAccount(player.getName())) {
                  Account account = iConomy.getBank().getAccount(player.getName());
                  double balance = account.getBalance();
                  double regionPrice = flags.getDoubleFlag(Flags.PRICE).getValue();

                  if (balance >= regionPrice) {
                    account.subtract(regionPrice);
                    player.sendMessage(
                        ChatColor.YELLOW
                            + "You have bought the region "
                            + regionId
                            + " for "
                            + iConomy.getBank().format(regionPrice));
                    DefaultDomain owners = region.getOwners();
                    owners.addPlayer(player.getName());
                    region.setOwners(owners);
                    flags.getBooleanFlag(Flags.BUYABLE).setValue(false);
                    account.save();
                  } else {
                    player.sendMessage(ChatColor.YELLOW + "You have not enough money.");
                  }
                } else {
                  player.sendMessage(ChatColor.YELLOW + "You have not enough money.");
                }
              } else {
                player.sendMessage(ChatColor.RED + "Region: " + regionId + " is not buyable");
              }
            } else {
              player.sendMessage(
                  ChatColor.DARK_RED + "The region " + regionId + " does not exist.");
            }
          } else {
            player.sendMessage(ChatColor.DARK_RED + "No region specified.");
          }
        }
      }

      if (wcfg.getBlacklist() != null) {

        if (!wcfg.getBlacklist()
            .check(
                new BlockInteractBlacklistEvent(
                    BukkitPlayer.wrapPlayer(plugin, player), toVector(block), block.getTypeId()),
                false,
                false)) {
          event.setCancelled(true);
          return;
        }
      }
    }
  }