コード例 #1
0
    @EventHandler
    public void onCustomEvent(PlayerInRegionEvent event) {
      RegionManager rm = plugin.getRegionManager();
      Player player = event.getPlayer();

      Location l = event.getLocation();
      ArrayList<String> effects = rm.getRegionType(rm.getRegion(l).getType()).getEffects();

      // Check if the region has the shoot arrow effect and return arrow velocity
      int explode = effect.regionHasEffect(effects, "landmine");
      if (explode == 0) return;

      // Check if the player owns or is a member of the region
      if (effect.isOwnerOfRegion(player, l) || effect.isMemberOfRegion(player, l)) {
        return;
      }

      // Check to see if the HeroStronghold has enough reagents
      if (!effect.hasReagents(l)) return;

      // Run upkeep but don't need to know if upkeep occured
      effect.forceUpkeep(event);

      // Check to see if exploding regions are enabled
      if (HeroStronghold.getConfigManager().getExplode()) {
        rm.destroyRegion(l);
      } else {
        rm.destroyRegion(l);
        l.getBlock().setTypeId(0);
        TNTPrimed tnt = l.getWorld().spawn(l, TNTPrimed.class);
        tnt.setFuseTicks(1);
      }

      // Set the event to destroy the region
      ArrayList<Location> tempArray = new ArrayList<Location>();
      tempArray.add(l);
      event.setRegionsToDestroy(tempArray);
    }
コード例 #2
0
    @EventHandler
    public void onCustomEvent(PlayerInRegionEvent event) {
      if (!event
          .getLocation()
          .getBlock()
          .getRelative(BlockFace.UP)
          .equals(event.getPlayer().getLocation().getBlock())) {
        return;
      }
      Location l = event.getLocation();
      RegionManager rm = getPlugin().getRegionManager();
      Region r = rm.getRegion(l);
      RegionType rt = rm.getRegionType(r.getType());

      // Check if the region is a teleporter
      if (effect.regionHasEffect(rt.getEffects(), "teleport") == 0) {
        return;
      }

      Block block = l.getBlock().getRelative(BlockFace.UP);
      if (!(block.getState() instanceof Sign)) {
        return;
      }

      Sign sign = (Sign) block.getState();
      if (!sign.getLine(0).equalsIgnoreCase("[Teleport]")) {
        return;
      }
      Region currentRegion = null;
      try {
        currentRegion = rm.getRegionByID(Integer.parseInt(sign.getLine(1)));
      } catch (Exception e) {
        return;
      }
      if (currentRegion == null) {
        return;
      }

      if (r.getOwners().isEmpty() || currentRegion.getOwners().isEmpty()) {
        return;
      }
      // TODO add more error messages
      boolean ownerCheck = false;
      for (String s : r.getOwners()) {
        if (currentRegion.isOwner(s)) {
          ownerCheck = true;
          break;
        }
      }
      if (!ownerCheck) {
        return;
      }

      if (effect.regionHasEffect(rm.getRegionType(currentRegion.getType()).getEffects(), "teleport")
          == 0) {
        return;
      }

      Location targetLoc = currentRegion.getLocation();

      // Check to see if the HeroStronghold has enough reagents
      if (!effect.hasReagents(l)) {
        return;
      }

      // Run upkeep but don't need to know if upkeep occured
      effect.forceUpkeep(event);
      event
          .getPlayer()
          .teleport(
              targetLoc
                  .getBlock()
                  .getRelative(BlockFace.NORTH, 2)
                  .getRelative(BlockFace.UP)
                  .getLocation());
      event.getPlayer().sendMessage(ChatColor.GOLD + "[HeroStronghold] You have been teleported!");
    }