Code Cleanup/Added Configurable option to deny and remove homes in ANY factions land.

More Soon..
This commit is contained in:
Driftay
2019-02-10 23:57:45 -05:00
parent 3559a9f090
commit 5a37320397
125 changed files with 3676 additions and 3410 deletions

View File

@@ -141,7 +141,7 @@ public class Econ {
// The amount must be positive.
// If the amount is negative we must flip and multiply amount with -1.
if (amount < 0) {
amount *= - 1;
amount *= -1;
EconomyParticipator temp = from;
from = to;
to = temp;
@@ -308,7 +308,7 @@ public class Econ {
// The account might not have enough space
EconomyResponse er = econ.depositPlayer(acc, delta);
if (er.transactionSuccess()) {
modifyUniverseMoney(- delta);
modifyUniverseMoney(-delta);
if (forDoingThis != null && !forDoingThis.isEmpty()) {
ep.msg("<h>%s<i> gained <h>%s<i> %s.", You, moneyString(delta), forDoingThis);
}
@@ -324,17 +324,17 @@ public class Econ {
// The player should loose money
// The player might not have enough.
if (econ.has(acc, - delta) && econ.withdrawPlayer(acc, - delta).transactionSuccess()) {
if (econ.has(acc, -delta) && econ.withdrawPlayer(acc, -delta).transactionSuccess()) {
// There is enough money to pay
modifyUniverseMoney(- delta);
modifyUniverseMoney(-delta);
if (forDoingThis != null && !forDoingThis.isEmpty()) {
ep.msg("<h>%s<i> lost <h>%s<i> %s.", You, moneyString(- delta), forDoingThis);
ep.msg("<h>%s<i> lost <h>%s<i> %s.", You, moneyString(-delta), forDoingThis);
}
return true;
} else {
// There was not enough money to pay
if (toDoThis != null && !toDoThis.isEmpty()) {
ep.msg("<h>%s<i> can't afford <h>%s<i> %s.", You, moneyString(- delta), toDoThis);
ep.msg("<h>%s<i> can't afford <h>%s<i> %s.", You, moneyString(-delta), toDoThis);
}
return false;
}
@@ -410,7 +410,7 @@ public class Econ {
public static boolean modifyBalance(String account, double amount) {
if (amount < 0) {
return econ.withdrawPlayer(account, - amount).transactionSuccess();
return econ.withdrawPlayer(account, -amount).transactionSuccess();
} else {
return econ.depositPlayer(account, amount).transactionSuccess();
}

View File

@@ -3,11 +3,7 @@ package com.massivecraft.factions.integration;
import com.earth2me.essentials.Teleport;
import com.earth2me.essentials.Trade;
import com.massivecraft.factions.Conf;
import net.ess3.api.IEssentials;
import java.math.BigDecimal;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
@@ -15,6 +11,8 @@ import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.plugin.Plugin;
import java.math.BigDecimal;
public class Essentials {
private static IEssentials essentials;

View File

@@ -1,139 +1,139 @@
package com.massivecraft.factions.integration;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.SavageFactions;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
/*
* Worldguard Region Checking
* Author: Spathizilla
*/
public class Worldguard {
private static WorldGuardPlugin wg;
private static boolean enabled = false;
public static void init(Plugin plugin) {
Plugin wgplug = plugin.getServer().getPluginManager().getPlugin("WorldGuard");
if (wgplug == null || !(wgplug instanceof WorldGuardPlugin)) {
enabled = false;
wg = null;
SavageFactions.plugin.log("Could not hook to WorldGuard. WorldGuard checks are disabled.");
} else {
wg = (WorldGuardPlugin) wgplug;
enabled = true;
SavageFactions.plugin.log("Successfully hooked to WorldGuard.");
}
}
public static boolean isEnabled() {
return enabled;
}
// PVP Flag check
// Returns:
// True: PVP is allowed
// False: PVP is disallowed
@SuppressWarnings("deprecation")
public static boolean isPVP(Player player) {
if (!enabled) {
// No WG hooks so we'll always bypass this check.
return true;
}
Location loc = player.getLocation();
World world = loc.getWorld();
Vector pt = toVector(loc);
RegionManager regionManager = wg.getRegionManager(world);
ApplicableRegionSet set = regionManager.getApplicableRegions(pt);
return set.allows(DefaultFlag.PVP);
}
// Check if player can build at location by worldguards rules.
// Returns:
// True: Player can build in the region.
// False: Player can not build in the region.
public static boolean playerCanBuild(Player player, Location loc) {
if (!enabled) {
// No WG hooks so we'll always bypass this check.
return false;
}
World world = loc.getWorld();
Vector pt = toVector(loc);
return wg.getRegionManager(world).getApplicableRegions(pt).size() > 0 && wg.canBuild(player, loc);
}
// Check for Regions in chunk the chunk
// Returns:
// True: Regions found within chunk
// False: No regions found within chunk
public static boolean checkForRegionsInChunk(FLocation floc) {
Chunk chunk = floc.getWorld().getChunkAt((int) floc.getX(), (int) floc.getZ());
return checkForRegionsInChunk(chunk);
}
public static boolean checkForRegionsInChunk(Location loc) {
Chunk chunk = loc.getWorld().getChunkAt(loc);
return checkForRegionsInChunk(chunk);
}
public static boolean checkForRegionsInChunk(Chunk chunk) {
if (!enabled) {
// No WG hooks so we'll always bypass this check.
return false;
}
World world = chunk.getWorld();
int minChunkX = chunk.getX() << 4;
int minChunkZ = chunk.getZ() << 4;
int maxChunkX = minChunkX + 15;
int maxChunkZ = minChunkZ + 15;
int worldHeight = world.getMaxHeight(); // Allow for heights other than default
BlockVector minChunk = new BlockVector(minChunkX, 0, minChunkZ);
BlockVector maxChunk = new BlockVector(maxChunkX, worldHeight, maxChunkZ);
RegionManager regionManager = wg.getRegionManager(world);
ProtectedCuboidRegion region = new ProtectedCuboidRegion("wgfactionoverlapcheck", minChunk, maxChunk);
Map<String, ProtectedRegion> allregions = regionManager.getRegions();
Collection<ProtectedRegion> allregionslist = new ArrayList<>(allregions.values());
List<ProtectedRegion> overlaps;
boolean foundregions = false;
try {
overlaps = region.getIntersectingRegions(allregionslist);
foundregions = overlaps != null && !overlaps.isEmpty();
} catch (Exception e) {
e.printStackTrace();
}
return foundregions;
}
package com.massivecraft.factions.integration;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.SavageFactions;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
/*
* Worldguard Region Checking
* Author: Spathizilla
*/
public class Worldguard {
private static WorldGuardPlugin wg;
private static boolean enabled = false;
public static void init(Plugin plugin) {
Plugin wgplug = plugin.getServer().getPluginManager().getPlugin("WorldGuard");
if (wgplug == null || !(wgplug instanceof WorldGuardPlugin)) {
enabled = false;
wg = null;
SavageFactions.plugin.log("Could not hook to WorldGuard. WorldGuard checks are disabled.");
} else {
wg = (WorldGuardPlugin) wgplug;
enabled = true;
SavageFactions.plugin.log("Successfully hooked to WorldGuard.");
}
}
public static boolean isEnabled() {
return enabled;
}
// PVP Flag check
// Returns:
// True: PVP is allowed
// False: PVP is disallowed
@SuppressWarnings("deprecation")
public static boolean isPVP(Player player) {
if (!enabled) {
// No WG hooks so we'll always bypass this check.
return true;
}
Location loc = player.getLocation();
World world = loc.getWorld();
Vector pt = toVector(loc);
RegionManager regionManager = wg.getRegionManager(world);
ApplicableRegionSet set = regionManager.getApplicableRegions(pt);
return set.allows(DefaultFlag.PVP);
}
// Check if player can build at location by worldguards rules.
// Returns:
// True: Player can build in the region.
// False: Player can not build in the region.
public static boolean playerCanBuild(Player player, Location loc) {
if (!enabled) {
// No WG hooks so we'll always bypass this check.
return false;
}
World world = loc.getWorld();
Vector pt = toVector(loc);
return wg.getRegionManager(world).getApplicableRegions(pt).size() > 0 && wg.canBuild(player, loc);
}
// Check for Regions in chunk the chunk
// Returns:
// True: Regions found within chunk
// False: No regions found within chunk
public static boolean checkForRegionsInChunk(FLocation floc) {
Chunk chunk = floc.getWorld().getChunkAt((int) floc.getX(), (int) floc.getZ());
return checkForRegionsInChunk(chunk);
}
public static boolean checkForRegionsInChunk(Location loc) {
Chunk chunk = loc.getWorld().getChunkAt(loc);
return checkForRegionsInChunk(chunk);
}
public static boolean checkForRegionsInChunk(Chunk chunk) {
if (!enabled) {
// No WG hooks so we'll always bypass this check.
return false;
}
World world = chunk.getWorld();
int minChunkX = chunk.getX() << 4;
int minChunkZ = chunk.getZ() << 4;
int maxChunkX = minChunkX + 15;
int maxChunkZ = minChunkZ + 15;
int worldHeight = world.getMaxHeight(); // Allow for heights other than default
BlockVector minChunk = new BlockVector(minChunkX, 0, minChunkZ);
BlockVector maxChunk = new BlockVector(maxChunkX, worldHeight, maxChunkZ);
RegionManager regionManager = wg.getRegionManager(world);
ProtectedCuboidRegion region = new ProtectedCuboidRegion("wgfactionoverlapcheck", minChunk, maxChunk);
Map<String, ProtectedRegion> allregions = regionManager.getRegions();
Collection<ProtectedRegion> allregionslist = new ArrayList<>(allregions.values());
List<ProtectedRegion> overlaps;
boolean foundregions = false;
try {
overlaps = region.getIntersectingRegions(allregionslist);
foundregions = overlaps != null && !overlaps.isEmpty();
} catch (Exception e) {
e.printStackTrace();
}
return foundregions;
}
}

View File

@@ -45,7 +45,8 @@ public class EngineDynmap {
public MarkerAPI markerApi;
public MarkerSet markerset;
private EngineDynmap() {}
private EngineDynmap() {
}
public static EngineDynmap getInstance() {
return i;
@@ -63,7 +64,7 @@ public class EngineDynmap {
}
public static String getHtmlPlayerName(FPlayer fplayer) {
return fplayer != null ? escapeHtml(fplayer.getName()):"none";
return fplayer != null ? escapeHtml(fplayer.getName()) : "none";
}
public static String escapeHtml(String string) {
@@ -72,8 +73,8 @@ public class EngineDynmap {
char c = string.charAt(i);
if (c > 127 || c == '"' || c == '<' || c == '>' || c == '&') {
out.append("&#")
.append((int) c)
.append(';');
.append((int) c)
.append(';');
} else {
out.append(c);
}

View File

@@ -10,8 +10,8 @@ public class TempAreaMarker {
public String label;
public String world;
public double x[];
public double z[];
public double[] x;
public double[] z;
public String description;
public int lineColor;
@@ -27,7 +27,7 @@ public class TempAreaMarker {
// CREATE
// -------------------------------------------- //
public static boolean equals(AreaMarker marker, double x[], double z[]) {
public static boolean equals(AreaMarker marker, double[] x, double[] z) {
int length = marker.getCornerCount();
if (x.length != length) {