mostly claimnearby stuff?
This commit is contained in:
parent
67b9c2c8ba
commit
0f8b6b5a0d
|
|
@ -733,4 +733,23 @@ public class Claim
|
||||||
{
|
{
|
||||||
return DataStore.getChunkHashes(this);
|
return DataStore.getChunkHashes(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean canCleaimNear(Player player, int howNear) {
|
||||||
|
Location location = player.getLocation();
|
||||||
|
Claim claim = new Claim
|
||||||
|
(new Location(this.lesserBoundaryCorner.getWorld(), this.lesserBoundaryCorner.getBlockX() - howNear, this.lesserBoundaryCorner.getBlockY(), this.lesserBoundaryCorner.getBlockZ() - howNear),
|
||||||
|
new Location(this.greaterBoundaryCorner.getWorld(), this.greaterBoundaryCorner.getBlockX() + howNear, this.greaterBoundaryCorner.getBlockY(), this.greaterBoundaryCorner.getBlockZ() + howNear),
|
||||||
|
null, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), null);
|
||||||
|
|
||||||
|
if(!claim.contains(location, false, true)) return true;
|
||||||
|
Set<Claim> claims = GriefPrevention.instance.dataStore.getNearbyClaims(location);
|
||||||
|
for (Claim claim2 : claims) {
|
||||||
|
if(!claim2.overlaps(claim)) continue;
|
||||||
|
|
||||||
|
Supplier<String> canClaimTrust = claim2.checkPermission(player, ClaimPermission.Claim, null);
|
||||||
|
if (canClaimTrust == null) continue;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,9 @@ public enum ClaimPermission
|
||||||
* ClaimPermission that allows users to grant ClaimPermissions. Uses a separate track from normal
|
* ClaimPermission that allows users to grant ClaimPermissions. Uses a separate track from normal
|
||||||
* permissions and does not grant any other permissions.
|
* permissions and does not grant any other permissions.
|
||||||
*/
|
*/
|
||||||
Manage(Messages.NoPermissionTrust);
|
Manage(Messages.NoPermissionTrust),
|
||||||
|
|
||||||
|
Claim(Messages.NoClaimTrust);
|
||||||
|
|
||||||
private final Messages denialMessage;
|
private final Messages denialMessage;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -964,6 +964,12 @@ public abstract class DataStore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (creatingPlayer != null && !newClaim.canCleaimNear(creatingPlayer, 100)) {
|
||||||
|
result.succeeded = false;
|
||||||
|
result.claim = null;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
//if worldguard is installed, also prevent claims from overlapping any worldguard regions
|
//if worldguard is installed, also prevent claims from overlapping any worldguard regions
|
||||||
if (GriefPrevention.instance.config_claims_respectWorldGuard && this.worldGuard != null && creatingPlayer != null)
|
if (GriefPrevention.instance.config_claims_respectWorldGuard && this.worldGuard != null && creatingPlayer != null)
|
||||||
{
|
{
|
||||||
|
|
@ -974,6 +980,7 @@ public abstract class DataStore
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dryRun)
|
if (dryRun)
|
||||||
{
|
{
|
||||||
// since this is a dry run, just return the unsaved claim as is.
|
// since this is a dry run, just return the unsaved claim as is.
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,10 @@ package me.ryanhamshire.GriefPrevention;
|
||||||
|
|
||||||
import me.ryanhamshire.GriefPrevention.DataStore.NoTransferException;
|
import me.ryanhamshire.GriefPrevention.DataStore.NoTransferException;
|
||||||
import me.ryanhamshire.GriefPrevention.alttd.config.Config;
|
import me.ryanhamshire.GriefPrevention.alttd.config.Config;
|
||||||
|
import me.ryanhamshire.GriefPrevention.alttd.database.DatabaseConnection;
|
||||||
import me.ryanhamshire.GriefPrevention.alttd.hook.Pl3xMapHook;
|
import me.ryanhamshire.GriefPrevention.alttd.hook.Pl3xMapHook;
|
||||||
import me.ryanhamshire.GriefPrevention.alttd.listeners.AltitudeListener;
|
import me.ryanhamshire.GriefPrevention.alttd.listeners.AltitudeListener;
|
||||||
import me.ryanhamshire.GriefPrevention.alttd.tasks.ClaimExpireTask;
|
import me.ryanhamshire.GriefPrevention.alttd.tasks.AdminClaimExpireTask;
|
||||||
import me.ryanhamshire.GriefPrevention.alttd.tasks.IgnoreClaimWarningTask;
|
import me.ryanhamshire.GriefPrevention.alttd.tasks.IgnoreClaimWarningTask;
|
||||||
import me.ryanhamshire.GriefPrevention.events.PreventBlockBreakEvent;
|
import me.ryanhamshire.GriefPrevention.events.PreventBlockBreakEvent;
|
||||||
import me.ryanhamshire.GriefPrevention.events.SaveTrappedPlayerEvent;
|
import me.ryanhamshire.GriefPrevention.events.SaveTrappedPlayerEvent;
|
||||||
|
|
@ -65,11 +66,8 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
@ -77,7 +75,6 @@ import java.util.function.Supplier;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class GriefPrevention extends JavaPlugin
|
public class GriefPrevention extends JavaPlugin
|
||||||
{
|
{
|
||||||
|
|
@ -239,6 +236,7 @@ public class GriefPrevention extends JavaPlugin
|
||||||
private String databasePassword;
|
private String databasePassword;
|
||||||
|
|
||||||
private Pl3xMapHook pl3xmapHook;
|
private Pl3xMapHook pl3xmapHook;
|
||||||
|
private DatabaseConnection databaseConnection;
|
||||||
|
|
||||||
private HashMap<UUID, IgnoreClaimWarningTask> ignoreClaimWarningTasks;
|
private HashMap<UUID, IgnoreClaimWarningTask> ignoreClaimWarningTasks;
|
||||||
|
|
||||||
|
|
@ -349,7 +347,7 @@ public class GriefPrevention extends JavaPlugin
|
||||||
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, task2, 20L * 60, 20L * config_advanced_claim_expiration_check_rate);
|
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, task2, 20L * 60, 20L * config_advanced_claim_expiration_check_rate);
|
||||||
|
|
||||||
// start task to clean up temporary admin claims
|
// start task to clean up temporary admin claims
|
||||||
ClaimExpireTask claimExpireTask = new ClaimExpireTask(this);
|
AdminClaimExpireTask claimExpireTask = new AdminClaimExpireTask(this);
|
||||||
claimExpireTask.init();
|
claimExpireTask.init();
|
||||||
|
|
||||||
//register for events
|
//register for events
|
||||||
|
|
@ -375,6 +373,7 @@ public class GriefPrevention extends JavaPlugin
|
||||||
if (getServer().getPluginManager().isPluginEnabled("Pl3xMap")) {
|
if (getServer().getPluginManager().isPluginEnabled("Pl3xMap")) {
|
||||||
pl3xmapHook = new Pl3xMapHook(this);
|
pl3xmapHook = new Pl3xMapHook(this);
|
||||||
}
|
}
|
||||||
|
// databaseConnection = new DatabaseConnection(); // TODO Set up database to pull data from proxyplaytime
|
||||||
ignoreClaimWarningTasks = new HashMap<>();
|
ignoreClaimWarningTasks = new HashMap<>();
|
||||||
AddLogEntry("Boot finished.");
|
AddLogEntry("Boot finished.");
|
||||||
|
|
||||||
|
|
@ -1603,6 +1602,16 @@ public class GriefPrevention extends JavaPlugin
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (cmd.getName().equalsIgnoreCase("claimnearbytrust") && player != null)
|
||||||
|
{
|
||||||
|
//requires exactly one parameter, the other player's name
|
||||||
|
if (args.length != 1) return false;
|
||||||
|
|
||||||
|
this.handleTrustCommand(player, ClaimPermission.Claim, args[0]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//permissiontrust <player>
|
//permissiontrust <player>
|
||||||
else if (cmd.getName().equalsIgnoreCase("permissiontrust") && player != null)
|
else if (cmd.getName().equalsIgnoreCase("permissiontrust") && player != null)
|
||||||
{
|
{
|
||||||
|
|
@ -3243,4 +3252,7 @@ public class GriefPrevention extends JavaPlugin
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DatabaseConnection getDataBase() {
|
||||||
|
return databaseConnection;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -254,5 +254,6 @@ public enum Messages
|
||||||
StandInSubclaim,
|
StandInSubclaim,
|
||||||
SubclaimRestricted,
|
SubclaimRestricted,
|
||||||
SubclaimUnrestricted,
|
SubclaimUnrestricted,
|
||||||
NetherPortalTrapDetectionMessage
|
NetherPortalTrapDetectionMessage,
|
||||||
|
NoClaimTrust
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,14 +29,16 @@ public class Config extends AbstractConfig {
|
||||||
public static boolean DEBUG_MODE = false;
|
public static boolean DEBUG_MODE = false;
|
||||||
public static boolean alternativeClaimExpiring = false;
|
public static boolean alternativeClaimExpiring = false;
|
||||||
public static int alternativeClaimExpireDays = 1;
|
public static int alternativeClaimExpireDays = 1;
|
||||||
public static int expireCheckRate = 1200;
|
public static int adminClaimExpireCheckRate = 1200;
|
||||||
|
public static int playerClaimExpireCheckRate = 1200;
|
||||||
public static HashMap<Long, Long> expiringClaims = new HashMap<>();
|
public static HashMap<Long, Long> expiringClaims = new HashMap<>();
|
||||||
private static void settings() {
|
private static void settings() {
|
||||||
String node = "alternative-claim-expiring";
|
String node = "alternative-claim-expiring";
|
||||||
DEBUG_MODE = config.getBoolean("debug-mode", DEBUG_MODE);
|
DEBUG_MODE = config.getBoolean("debug-mode", DEBUG_MODE);
|
||||||
alternativeClaimExpiring = config.getBoolean(node + ".enabled", alternativeClaimExpiring);
|
alternativeClaimExpiring = config.getBoolean(node + ".enabled", alternativeClaimExpiring);
|
||||||
alternativeClaimExpireDays = config.getInt(node + ".days", alternativeClaimExpireDays);
|
alternativeClaimExpireDays = config.getInt(node + ".days", alternativeClaimExpireDays);
|
||||||
expireCheckRate = config.getInt(node + ".expire-check-rate", expireCheckRate);
|
adminClaimExpireCheckRate = config.getInt(node + ".admin-claim-expire-check-rate", adminClaimExpireCheckRate);
|
||||||
|
playerClaimExpireCheckRate = config.getInt(node + ".player-claim-expire-check-rate", playerClaimExpireCheckRate);
|
||||||
// todo create an alternative way of loading these in
|
// todo create an alternative way of loading these in
|
||||||
expiringClaims.clear();
|
expiringClaims.clear();
|
||||||
config.getMap(node + ".claims", new HashMap<String, Long>())
|
config.getMap(node + ".claims", new HashMap<String, Long>())
|
||||||
|
|
@ -159,4 +161,18 @@ public class Config extends AbstractConfig {
|
||||||
} catch (NumberFormatException ignored) {}
|
} catch (NumberFormatException ignored) {}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String IP = "0.0.0.0";
|
||||||
|
public static String PORT = "3306";
|
||||||
|
public static String DATABASE = "database";
|
||||||
|
public static String USERNAME = "root";
|
||||||
|
public static String PASSWORD = "root";
|
||||||
|
private static void database() {
|
||||||
|
IP = config.getString("database.ip", IP);
|
||||||
|
PORT = config.getString("database.port", PORT);
|
||||||
|
DATABASE = config.getString("database.name", DATABASE);
|
||||||
|
USERNAME = config.getString("database.username", USERNAME);
|
||||||
|
PASSWORD = config.getString("database.password", PASSWORD);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,75 @@
|
||||||
|
package me.ryanhamshire.GriefPrevention.alttd.database;
|
||||||
|
|
||||||
|
import me.ryanhamshire.GriefPrevention.alttd.config.Config;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class DatabaseConnection {
|
||||||
|
|
||||||
|
private static DatabaseConnection instance;
|
||||||
|
private static Connection connection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets information for the database and opens the connection.
|
||||||
|
*/
|
||||||
|
public DatabaseConnection() {
|
||||||
|
instance = this;
|
||||||
|
|
||||||
|
try {
|
||||||
|
instance.openConnection();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens the connection if it's not already open.
|
||||||
|
* @throws SQLException If it can't create the connection.
|
||||||
|
*/
|
||||||
|
public void openConnection() throws SQLException {
|
||||||
|
if (connection != null && !connection.isClosed()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized (this) {
|
||||||
|
if (connection != null && !connection.isClosed()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
connection = DriverManager.getConnection(
|
||||||
|
"jdbc:mysql://" + Config.IP + ":" + Config.PORT + "/" + Config.DATABASE + "?autoReconnect=true"+
|
||||||
|
"&useSSL=false",
|
||||||
|
Config.USERNAME, Config.PASSWORD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the connection for the database
|
||||||
|
* @return Returns the connection.
|
||||||
|
*/
|
||||||
|
public static Connection getConnection() {
|
||||||
|
try {
|
||||||
|
instance.openConnection();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the connection for this instance
|
||||||
|
*/
|
||||||
|
public static boolean initialize() {
|
||||||
|
instance = new DatabaseConnection();
|
||||||
|
return connection != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
package me.ryanhamshire.GriefPrevention.alttd.database;
|
||||||
|
|
||||||
|
public class Queries {}
|
||||||
|
|
@ -7,18 +7,18 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class ClaimExpireTask extends BukkitRunnable
|
public class AdminClaimExpireTask extends BukkitRunnable
|
||||||
{
|
{
|
||||||
private GriefPrevention plugin;
|
private GriefPrevention plugin;
|
||||||
|
|
||||||
public ClaimExpireTask(GriefPrevention plugin)
|
public AdminClaimExpireTask(GriefPrevention plugin)
|
||||||
{
|
{
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init()
|
public void init()
|
||||||
{
|
{
|
||||||
runTaskTimer(plugin, 0, Config.expireCheckRate);
|
runTaskTimer(plugin, 0, Config.adminClaimExpireCheckRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
package me.ryanhamshire.GriefPrevention.alttd.tasks;
|
||||||
|
|
||||||
|
import me.ryanhamshire.GriefPrevention.GriefPrevention;
|
||||||
|
import me.ryanhamshire.GriefPrevention.alttd.config.Config;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class PlayerClaimExpireTask extends BukkitRunnable
|
||||||
|
{
|
||||||
|
private GriefPrevention plugin;
|
||||||
|
|
||||||
|
public PlayerClaimExpireTask(GriefPrevention plugin)
|
||||||
|
{
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init()
|
||||||
|
{
|
||||||
|
runTaskTimer(plugin, 0, Config.playerClaimExpireCheckRate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -48,6 +48,10 @@ commands:
|
||||||
usage: /PermissionTrust <player>. Permits a player to share his permission level with others.
|
usage: /PermissionTrust <player>. Permits a player to share his permission level with others.
|
||||||
aliases: pt
|
aliases: pt
|
||||||
permission: griefprevention.claims
|
permission: griefprevention.claims
|
||||||
|
claimnearbytrust:
|
||||||
|
description: Grants a player permission to claim within x blocks of your claim.
|
||||||
|
usage: /claimnearbytrust <player>.
|
||||||
|
permission: griefprevention.claimsnearby
|
||||||
subdivideclaims:
|
subdivideclaims:
|
||||||
description: Switches the shovel tool to subdivision mode, used to subdivide your claims.
|
description: Switches the shovel tool to subdivision mode, used to subdivide your claims.
|
||||||
usage: /SubdivideClaims
|
usage: /SubdivideClaims
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user