Esempio n. 1
0
  public Boolean addPlayer(String name) {
    Player p = Bukkit.getServer().getPlayer(name);
    if (p == null) {
      return false;
    }
    if (p.getName().equals(leader)) {
      return false;
    }
    members.add(name);

    /* Dodanie gracza do cuboidu i configu */
    RegionManager regionManager = getRegionManager(world);
    String prefix = Config.getPrefix();
    DefaultDomain dd = regionManager.getRegion(prefix + akronim).getMembers();
    dd.addPlayer(name);
    regionManager.getRegion(prefix + akronim).setMembers(dd);
    try {
      regionManager.save();
    } catch (ProtectionDatabaseException ex) {
      Logger.getLogger(Wioska.class.getName()).log(Level.SEVERE, null, ex);
    }

    saveWioska();
    return true;
  }
 /** @return <code>true</code> if this region is not transient and changes have been made. */
 @Override
 public boolean isDirty() {
   if (isTransient()) {
     return false;
   }
   return dirty || owners.isDirty() || members.isDirty();
 }
Esempio n. 3
0
  public static void giveStall(Player player, String zone, String number) {
    WorldGuardPlugin worldGuard = getWorldGuard();
    World world = player.getWorld();

    RegionManager regionManager = worldGuard.getRegionManager(world);
    ProtectedRegion region = regionManager.getRegion("stall_" + zone.toLowerCase() + number);
    DefaultDomain owners = region.getOwners();
    owners.addPlayer(player.getName());
    region.setOwners(owners);
    editPlotSign(player, zone, number, region);
  }
Esempio n. 4
0
 private String uuidSetToString(DefaultDomain domain) {
   UUIDControl uuidControl = SlapPlayers.getUUIDController();
   Set<UUID> set = domain.getUniqueIds();
   if (set.isEmpty()) {
     return ChatColor.RED + "(none)";
   } else {
     HashSet<String> names = new HashSet<>();
     for (UUID owner : domain.getUniqueIds()) {
       names.add(uuidControl.getProfile(owner).getCurrentName());
     }
     return ChatColor.YELLOW + Util.buildString(names, ", ");
   }
 }
Esempio n. 5
0
  private void createCuboid() throws Exception {
    RegionManager regionManager = getRegionManager(world);

    String prefix = Config.getPrefix();
    ProtectedCuboidRegion pr = new ProtectedCuboidRegion(prefix + akronim, getPos1(), getPos2());
    DefaultDomain dd = new DefaultDomain();
    dd.addPlayer(leader);
    for (String s : members) {
      dd.addPlayer(s);
    }
    pr.setMembers(dd);

    pr.setFlag(DefaultFlag.USE, State.DENY);
    regionManager.addRegion(pr);
  }
  /**
   * Checks whether a player is a member OR OWNER of the region or any of its parents.
   *
   * @param player player to check
   * @return whether an owner or member
   */
  public boolean isMember(LocalPlayer player) {
    if (owners.contains(player) || members.contains(player)) {
      return true;
    }

    ProtectedRegion curParent = getParent();
    while (curParent != null) {
      if (curParent.getOwners().contains(player) || curParent.getMembers().contains(player)) {
        return true;
      }

      curParent = curParent.getParent();
    }

    return false;
  }
Esempio n. 7
0
  void setUpExitRegion() throws Exception {
    DefaultDomain domain = new DefaultDomain();
    domain.addGroup(BUILDER_GROUP);

    ProtectedRegion region =
        new ProtectedCuboidRegion(
            EXIT_ID, new BlockVector(-1, 0, -1), new BlockVector(-10, 255, -10));

    region.setOwners(domain);
    manager.addRegion(region);

    entryRegion = region;
    // same as above
    entryRegion.setFlag(DefaultFlag.EXIT, StateFlag.State.DENY);
    entryRegion.setFlag(DefaultFlag.EXIT.getRegionGroupFlag(), RegionGroup.NON_OWNERS);
  }
Esempio n. 8
0
  void setUpEntryRegion() {
    DefaultDomain domain = new DefaultDomain();
    domain.addGroup(VIP_GROUP);

    ProtectedRegion region =
        new ProtectedCuboidRegion(ENTRY_ID, new BlockVector(1, 0, 1), new BlockVector(10, 255, 10));

    region.setMembers(domain);
    manager.addRegion(region);

    entryRegion = region;
    // this is the way it's supposed to work
    // whatever the group flag is set to is the group that the flag APPLIES to
    // in this case, non members (esskay) should be DENIED entry
    entryRegion.setFlag(DefaultFlag.ENTRY, StateFlag.State.DENY);
    entryRegion.setFlag(DefaultFlag.ENTRY.getRegionGroupFlag(), RegionGroup.NON_MEMBERS);
  }
 public OfflinePlayer[] getOwners() {
   OfflinePlayer[] list;
   Set<String> playerSet = owners.getPlayers();
   list = new OfflinePlayer[playerSet.size()];
   int index = 0;
   for (String playerName : playerSet) {
     list[index] = Bukkit.getOfflinePlayer(playerName);
     ++index;
   }
   return list;
 }
Esempio n. 10
0
  public Boolean removePlayer(String name) {
    if (!members.contains(name)) {
      return false;
    }
    members.remove(name);

    /* Usunięcie gracza z cuboidu i configu */
    RegionManager regionManager = getRegionManager(world);
    String prefix = Config.getPrefix();
    DefaultDomain dd = regionManager.getRegion(prefix + akronim).getMembers();
    dd.removePlayer(name);
    regionManager.getRegion(prefix + akronim).setMembers(dd);
    try {
      regionManager.save();
    } catch (ProtectionDatabaseException ex) {
      Logger.getLogger(Wioska.class.getName()).log(Level.SEVERE, null, ex);
    }

    saveWioska();
    return true;
  }
  /**
   * Checks whether a player is a member of the region or any of its parents.
   *
   * @param player player to check
   * @return whether an member
   */
  public boolean isMemberOnly(LocalPlayer player) {
    checkNotNull(player);

    if (members.contains(player)) {
      return true;
    }

    ProtectedRegion curParent = getParent();
    while (curParent != null) {
      if (curParent.getMembers().contains(player)) {
        return true;
      }

      curParent = curParent.getParent();
    }

    return false;
  }
  /**
   * Checks whether a player is an owner of region or any of its parents.
   *
   * @param playerName player name to check
   * @return whether an owner
   * @deprecated Names are deprecated
   */
  @Deprecated
  public boolean isOwner(String playerName) {
    checkNotNull(playerName);

    if (owners.contains(playerName)) {
      return true;
    }

    ProtectedRegion curParent = getParent();
    while (curParent != null) {
      if (curParent.getOwners().contains(playerName)) {
        return true;
      }

      curParent = curParent.getParent();
    }

    return false;
  }
 public boolean isPlayerMember(LocalPlayer localPlayer) {
   return members.contains(localPlayer);
 }
 public void removeAllOwners() {
   owners.removeAll();
 }
 public void removeAllMembers() {
   members.removeAll();
 }
 public void removeOwnerGroup(String group) {
   owners.removeGroup(group);
 }
 public void removeOwner(LocalPlayer localPlayer) {
   owners.removePlayer(localPlayer);
 }
  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;
        }
      }
    }
  }
 public void addOwnerGroup(String group) {
   owners.addGroup(group);
 }
 public void addOwner(LocalPlayer localPlayer) {
   owners.addPlayer(localPlayer);
 }
 public void addMember(LocalPlayer localPlayer) {
   members.addPlayer(localPlayer);
 }
Esempio n. 22
0
 /**
  * Checks whether a region has members or owners.
  *
  * @return whether there are members or owners
  */
 public boolean hasMembersOrOwners() {
   return owners.size() > 0 || members.size() > 0;
 }
 public boolean isPlayerOwner(LocalPlayer localPlayer) {
   return owners.contains(localPlayer);
 }
 public void removeMember(LocalPlayer localPlayer) {
   members.removePlayer(localPlayer);
 }
 public void removeMemberGroup(String group) {
   members.removeGroup(group);
 }
 public void addMemberGroup(String group) {
   members.addGroup(group);
 }
 @Override
 public void setDirty(boolean dirty) {
   this.dirty = dirty;
   owners.setDirty(dirty);
   members.setDirty(dirty);
 }