me.ryanhamshire.GriefPrevention.Claim Java Examples

The following examples show how to use me.ryanhamshire.GriefPrevention.Claim. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GriefPreventionHandler.java    From Parties with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Result isManager(Player claimer) {
	if (active) {
		Claim claim = GriefPrevention.instance.dataStore.getClaimAt(claimer.getLocation(), false, null);
		if (claim == null) {
			return Result.NOEXIST;
		}
		if (!claim.getOwnerName().equalsIgnoreCase(claimer.getName())) {
			if (BukkitConfigMain.ADDONS_GRIEFPREVENTION_NEEDOWNER || !claim.managers.contains(claimer.getUniqueId().toString())) {
				return Result.NOMANAGER;
			}
		}
		return Result.SUCCESS;
	}
	return Result.NOEXIST;
}
 
Example #2
Source File: GriefPreventionHandler.java    From Parties with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void addPartyPermission(Player claimer, PartyImpl party, PermissionType perm) {
	if (active) {
		Claim claim = GriefPrevention.instance.dataStore.getClaimAt(claimer.getLocation(), false, null);
		for (UUID uuid : party.getMembers()) {
			if (claimer.getUniqueId().equals(uuid))
				continue;
			if (perm.isRemove())
				claim.dropPermission(uuid.toString());
			else
				claim.setPermission(uuid.toString(), perm.convertPermission());
		}
		GriefPrevention.instance.dataStore.saveClaim(claim);
	}
}
 
Example #3
Source File: GriefPreventionHook.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
Claim getClaim(final long id) {
	if (getClaim != null) {
		try {
			return (Claim) getClaim.invoke(plugin.dataStore, id);
		} catch (final IllegalAccessException e) {
			assert false : e;
		} catch (final IllegalArgumentException e) {
			assert false : e;
		} catch (final InvocationTargetException e) {
			throw new RuntimeException(e.getCause());
		}
	} else {
		assert claimsField != null;
		try {
			final List<?> claims = (List<?>) claimsField.get(plugin.dataStore);
			for (final Object claim : claims) {
				if (!(claim instanceof Claim))
					continue;
				if (((Claim) claim).getID() == id)
					return (Claim) claim;
			}
		} catch (final IllegalArgumentException e) {
			assert false : e;
		} catch (final IllegalAccessException e) {
			assert false : e;
		}
	}
	return null;
}
 
Example #4
Source File: GriefPreventionHook.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void deserialize(final Fields fields) throws StreamCorruptedException {
	final long id = fields.getPrimitive("id", long.class);
	final Claim c = getClaim(id);
	if (c == null)
		throw new StreamCorruptedException("Invalid claim " + id);
	claim = c;
}
 
Example #5
Source File: GriefPreventionHook.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("null")
@Override
public Collection<? extends Region> getRegionsAt_i(final Location l) {
	final Claim c = plugin.dataStore.getClaimAt(l, false, null);
	if (c != null)
		return Arrays.asList(new GriefPreventionRegion(c));
	return Collections.emptySet();
}
 
Example #6
Source File: GriefPreventionHook.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Region getRegion_i(final World world, final String name) {
	try {
		final Claim c = getClaim(Long.parseLong(name));
		if (c != null && world.equals(c.getLesserBoundaryCorner().getWorld()))
			return new GriefPreventionRegion(c);
		return null;
	} catch (final NumberFormatException e) {
		return null;
	}
}
 
Example #7
Source File: GriefPreventionFilter.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void calculateRegions() {
    for (Claim claim : claims) {
        org.bukkit.Location bot = claim.getGreaterBoundaryCorner();
        if (world.equals(bot.getWorld())) {
            org.bukkit.Location top = claim.getGreaterBoundaryCorner();
            BlockVector2D pos1 = new BlockVector2D(bot.getBlockX(), bot.getBlockZ());
            BlockVector2D pos2 = new BlockVector2D(top.getBlockX(), top.getBlockZ());
            add(pos1, pos2);
        }
    }
}
 
Example #8
Source File: RedProtectUtil.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public int convertFromGP() {
    int claimed = 0;
    Collection<Claim> claims = GriefPrevention.instance.dataStore.getClaims();
    for (Claim claim : claims) {
        if (Bukkit.getWorlds().contains(claim.getGreaterBoundaryCorner().getWorld())) {
            World w = claim.getGreaterBoundaryCorner().getWorld();
            String pname = claim.getOwnerName().replace(" ", "_").toLowerCase();
            if (claim.ownerID != null) {
                pname = claim.ownerID.toString();
            }
            Set<PlayerRegion> leaders = new HashSet<>();
            leaders.add(new PlayerRegion(claim.ownerID != null ? claim.ownerID.toString() : pname, pname));
            Location newmin = claim.getGreaterBoundaryCorner();
            Location newmax = claim.getLesserBoundaryCorner();
            newmin.setY(0);
            newmax.setY(w.getMaxHeight());

            Region r = new Region(nameGen(claim.getOwnerName().replace(" ", "_").toLowerCase(), w.getName()), new HashSet<>(), new HashSet<>(), leaders,
                    newmin, newmax, RedProtect.get().config.getDefFlagsValues(), "GriefPrevention region", 0, w.getName(), dateNow(), 0, null, true, true);

            Region other = RedProtect.get().rm.getTopRegion(w.getName(), r.getCenterX(), r.getCenterY(), r.getCenterZ());
            if (other == null || !r.getWelcome().equals(other.getWelcome())) {
                RedProtect.get().rm.add(r, w.getName());
                RedProtect.get().logger.debug(LogLevel.DEFAULT, "Region: " + r.getName());
                claimed++;
            }
        }
    }
    return claimed;
}
 
Example #9
Source File: GriefPreventionListener.java    From ShopChest with MIT License 5 votes vote down vote up
private boolean handleForLocation(Player player, Location loc, Cancellable e) {
    Claim claim = griefPrevention.dataStore.getClaimAt(loc, false, null);
    if (claim == null) 
        return false;

    if (claim.allowContainers(player) != null) {
        e.setCancelled(true);
        plugin.debug("Cancel Reason: GriefPrevention");
        return true;
    }

    return false;
}
 
Example #10
Source File: GriefPreventionHook.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
public GriefPreventionRegion(final Claim c) {
	claim = c;
}
 
Example #11
Source File: HookGriefPrevention.java    From CombatLogX with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isSafeZone(Location location) {
    GriefPrevention api = getAPI();
    Claim claim = api.dataStore.getClaimAt(location, false, null);

    return (claim != null);
}
 
Example #12
Source File: GriefPreventionFeature.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public boolean isAllowed(Player player, Claim claim, MaskType type) {
    return claim != null && (claim.getOwnerName().equalsIgnoreCase(player.getName()) || claim.getOwnerName().equals(player.getUniqueId()) || (type == MaskType.MEMBER && (claim.allowBuild(player, Material.AIR) == null)));
}