diff --git a/plugin.yml b/plugin.yml index 64c7221..2f41718 100644 --- a/plugin.yml +++ b/plugin.yml @@ -341,3 +341,15 @@ permissions: griefprevention.eavesdropimmune: description: Players with this permission can't have their private messages eavesdropped. default: op + griefprevention.fasteraccrual: + description: Players with this permission accrue claim blocks at the faster rate specified in the config file. + default: false + griefprevention.fastestaccrual: + description: Players with this permission accrue claim blocks at the fastest rate specified in the config file. + default: false + griefprevention.moreaccrued: + description: Players with this permission can accrue more claim blocks (limit specified in the config file). + default: false + griefprevention.mostaccrued: + description: Players with this permission can accrue more claim blocks (limit specified in the config file). + default: false \ No newline at end of file diff --git a/src/me/ryanhamshire/GriefPrevention/DeliverClaimBlocksTask.java b/src/me/ryanhamshire/GriefPrevention/DeliverClaimBlocksTask.java index c015beb..d567090 100644 --- a/src/me/ryanhamshire/GriefPrevention/DeliverClaimBlocksTask.java +++ b/src/me/ryanhamshire/GriefPrevention/DeliverClaimBlocksTask.java @@ -38,8 +38,6 @@ class DeliverClaimBlocksTask implements Runnable @Override public void run() { - if(GriefPrevention.instance.config_claims_blocksAccruedPerHour <= 0) return; - //if no player specified, this task will create a player-specific task for each online player, scheduled one tick apart if(this.player == null) { @@ -57,6 +55,8 @@ class DeliverClaimBlocksTask implements Runnable //otherwise, deliver claim blocks to the specified player else { + if(!this.player.isOnline()) return; + DataStore dataStore = GriefPrevention.instance.dataStore; PlayerData playerData = dataStore.getPlayerData(player.getUniqueId()); @@ -69,21 +69,24 @@ class DeliverClaimBlocksTask implements Runnable (lastLocation == null || lastLocation.distanceSquared(player.getLocation()) >= 0) && !player.getLocation().getBlock().isLiquid()) { - //add blocks - int accruedBlocks = GriefPrevention.instance.config_claims_blocksAccruedPerHour / 6; - if(accruedBlocks < 0) accruedBlocks = 1; + //determine how fast blocks accrue for this player + int accrualRate = GriefPrevention.instance.config_claims_blocksAccruedPerHour_default; + if(player.hasPermission("griefprevention.fastestaccrual")) accrualRate = GriefPrevention.instance.config_claims_blocksAccruedPerHour_fastest; + else if(player.hasPermission("griefprevention.fasteraccrual")) accrualRate = GriefPrevention.instance.config_claims_blocksAccruedPerHour_faster; + //add blocks + int accruedBlocks = accrualRate / 6; + if(accruedBlocks < 0) accruedBlocks = 1; + playerData.accrueBlocks(accruedBlocks); GriefPrevention.AddLogEntry("Delivering " + accruedBlocks + " blocks to " + player.getName(), CustomLogEntryTypes.Debug, true); - playerData.accrueBlocks(accruedBlocks); - //intentionally NOT saving data here to reduce overall secondary storage access frequency - //many other operations will cause this players data to save, including his eventual logout + //many other operations will cause this player's data to save, including his eventual logout //dataStore.savePlayerData(player.getUniqueIdentifier(), playerData); } else { - GriefPrevention.AddLogEntry(player.getName() + " isn't active enough.", CustomLogEntryTypes.Debug, true); + GriefPrevention.AddLogEntry(player.getName() + " wasn't active enough to accrue claim blocks this round.", CustomLogEntryTypes.Debug, true); } } catch(IllegalArgumentException e) //can't measure distance when to/from are different worlds diff --git a/src/me/ryanhamshire/GriefPrevention/EntityEventHandler.java b/src/me/ryanhamshire/GriefPrevention/EntityEventHandler.java index 6fb7747..a4e98d3 100644 --- a/src/me/ryanhamshire/GriefPrevention/EntityEventHandler.java +++ b/src/me/ryanhamshire/GriefPrevention/EntityEventHandler.java @@ -795,6 +795,9 @@ public class EntityEventHandler implements Listener //allow for disabling villager protections in the config if(subEvent.getEntityType() == EntityType.VILLAGER && !GriefPrevention.instance.config_claims_protectCreatures) return; + //don't protect polar bears, they may be aggressive + if(subEvent.getEntityType() == EntityType.POLAR_BEAR) return; + //decide whether it's claimed Claim cachedClaim = null; PlayerData playerData = null; diff --git a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java index 43e226d..dcdcf1f 100644 --- a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java +++ b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java @@ -101,8 +101,12 @@ public class GriefPrevention extends JavaPlugin public int config_claims_initialBlocks; //the number of claim blocks a new player starts with public double config_claims_abandonReturnRatio; //the portion of claim blocks returned to a player when a claim is abandoned - public int config_claims_blocksAccruedPerHour; //how many additional blocks players get each hour of play (can be zero) - public int config_claims_maxAccruedBlocks; //the limit on accrued blocks (over time). doesn't limit purchased or admin-gifted blocks + public int config_claims_blocksAccruedPerHour_default; //how many additional blocks players get each hour of play (can be zero) without any special permissions + public int config_claims_blocksAccruedPerHour_faster; //how many additional blocks players get each hour of play when they have the griefprevention.fasteraccrual permission + public int config_claims_blocksAccruedPerHour_fastest; //how many additional blocks players get each hour of play when they have the griefprevention.fastestaccrual permission + public int config_claims_maxAccruedBlocks_default; //the limit on accrued blocks (over time) for players without any special permissions. doesn't limit purchased or admin-gifted blocks + public int config_claims_maxAccruedBlocks_more; //the limit on accrued blocks (over time) for players who have the griefprevention.moreaccrued permission + public int config_claims_maxAccruedBlocks_most; //the limit on accrued blocks (over time) for players who have the griefprevention.mostaccrued permission public int config_claims_maxDepth; //limit on how deep claims can go public int config_claims_expirationDays; //how many days of inactivity before a player loses his claims public int config_claims_expirationExemptionTotalBlocks; //total claim blocks amount which will exempt a player from claim expiration @@ -306,7 +310,7 @@ public class GriefPrevention extends JavaPlugin //unless claim block accrual is disabled, start the recurring per 10 minute event to give claim blocks to online players //20L ~ 1 second - if(this.config_claims_blocksAccruedPerHour > 0) + if(this.config_claims_blocksAccruedPerHour_default > 0 || this.config_claims_blocksAccruedPerHour_faster > 0 || this.config_claims_blocksAccruedPerHour_fastest > 0) { DeliverClaimBlocksTask task = new DeliverClaimBlocksTask(null); this.getServer().getScheduler().scheduleSyncRepeatingTask(this, task, 20L * 60 * 10, 20L * 60 * 10); @@ -527,8 +531,14 @@ public class GriefPrevention extends JavaPlugin this.config_claims_lockFenceGates = config.getBoolean("GriefPrevention.Claims.LockFenceGates", true); this.config_claims_enderPearlsRequireAccessTrust = config.getBoolean("GriefPrevention.Claims.EnderPearlsRequireAccessTrust", true); this.config_claims_initialBlocks = config.getInt("GriefPrevention.Claims.InitialBlocks", 100); - this.config_claims_blocksAccruedPerHour = config.getInt("GriefPrevention.Claims.BlocksAccruedPerHour", 100); - this.config_claims_maxAccruedBlocks = config.getInt("GriefPrevention.Claims.MaxAccruedBlocks", 80000); + this.config_claims_blocksAccruedPerHour_default = config.getInt("GriefPrevention.Claims.BlocksAccruedPerHour", 100); + this.config_claims_blocksAccruedPerHour_default = config.getInt("GriefPrevention.Claims.Claim Blocks Accrued Per Hour.Default", config_claims_blocksAccruedPerHour_default); + this.config_claims_blocksAccruedPerHour_faster = config.getInt("GriefPrevention.Claims.Claim Blocks Accrued Per Hour.With 'fasteraccrual' Permission", 110); + this.config_claims_blocksAccruedPerHour_fastest = config.getInt("GriefPrevention.Claims.Claim Blocks Accrued Per Hour.With 'fastestaccrual' Permission", 125); + this.config_claims_maxAccruedBlocks_default = config.getInt("GriefPrevention.Claims.MaxAccruedBlocks", 2000); + this.config_claims_maxAccruedBlocks_default = config.getInt("GriefPrevention.Claims.Max Accrued Claim Blocks.Default", this.config_claims_maxAccruedBlocks_default); + this.config_claims_maxAccruedBlocks_more= config.getInt("GriefPrevention.Claims.Max Accrued Claim Blocks.With 'moreaccrued' Permission", 5000); + this.config_claims_maxAccruedBlocks_most = config.getInt("GriefPrevention.Claims.Max Accrued Claim Blocks.With 'mostaccrued' Permission", 10000); this.config_claims_abandonReturnRatio = config.getDouble("GriefPrevention.Claims.AbandonReturnRatio", 1); this.config_claims_automaticClaimsForNewPlayersRadius = config.getInt("GriefPrevention.Claims.AutomaticNewPlayerClaimsRadius", 4); this.config_claims_claimsExtendIntoGroundDistance = Math.abs(config.getInt("GriefPrevention.Claims.ExtendIntoGroundDistance", 5)); @@ -762,8 +772,12 @@ public class GriefPrevention extends JavaPlugin outConfig.set("GriefPrevention.Claims.EnderPearlsRequireAccessTrust", this.config_claims_enderPearlsRequireAccessTrust); outConfig.set("GriefPrevention.Claims.ProtectHorses", this.config_claims_protectHorses); outConfig.set("GriefPrevention.Claims.InitialBlocks", this.config_claims_initialBlocks); - outConfig.set("GriefPrevention.Claims.BlocksAccruedPerHour", this.config_claims_blocksAccruedPerHour); - outConfig.set("GriefPrevention.Claims.MaxAccruedBlocks", this.config_claims_maxAccruedBlocks); + outConfig.set("GriefPrevention.Claims.Claim Blocks Accrued Per Hour.Default", this.config_claims_blocksAccruedPerHour_default); + outConfig.set("GriefPrevention.Claims.Claim Blocks Accrued Per Hour.With 'fasteraccrual' Permission", this.config_claims_blocksAccruedPerHour_faster); + outConfig.set("GriefPrevention.Claims.Claim Blocks Accrued Per Hour.With 'fastestaccrual' Permission", this.config_claims_blocksAccruedPerHour_fastest); + outConfig.set("GriefPrevention.Claims.Max Accrued Claim Blocks.Default", this.config_claims_maxAccruedBlocks_default); + outConfig.set("GriefPrevention.Claims.Max Accrued Claim Blocks.With 'moreaccrued' Permission", this.config_claims_maxAccruedBlocks_more); + outConfig.set("GriefPrevention.Claims.Max Accrued Claim Blocks.With 'mostaccrued' Permission", this.config_claims_maxAccruedBlocks_most); outConfig.set("GriefPrevention.Claims.AbandonReturnRatio", this.config_claims_abandonReturnRatio); outConfig.set("GriefPrevention.Claims.AutomaticNewPlayerClaimsRadius", this.config_claims_automaticClaimsForNewPlayersRadius); outConfig.set("GriefPrevention.Claims.ExtendIntoGroundDistance", this.config_claims_claimsExtendIntoGroundDistance); diff --git a/src/me/ryanhamshire/GriefPrevention/PlayerData.java b/src/me/ryanhamshire/GriefPrevention/PlayerData.java index 59551b4..cfaea8c 100644 --- a/src/me/ryanhamshire/GriefPrevention/PlayerData.java +++ b/src/me/ryanhamshire/GriefPrevention/PlayerData.java @@ -30,8 +30,10 @@ import me.ryanhamshire.GriefPrevention.ShovelMode; import me.ryanhamshire.GriefPrevention.SiegeData; import me.ryanhamshire.GriefPrevention.Visualization; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; //holds all of GriefPrevention's player-tied data public class PlayerData @@ -186,23 +188,25 @@ public class PlayerData { if(this.accruedClaimBlocks == null) this.loadDataFromSecondaryStorage(); - //if player is over accrued limit, accrued limit was probably reduced in config file AFTER he accrued - //in that case, leave his blocks where they are - int currentTotal = this.accruedClaimBlocks; - if(currentTotal >= GriefPrevention.instance.config_claims_maxAccruedBlocks) - { - this.newlyAccruedClaimBlocks = 0; - return currentTotal; - } + //update claim blocks with any he has accrued during his current play session + if(this.newlyAccruedClaimBlocks > 0) + { + int accruedLimit = this.getAccruedClaimBlocksLimit(); + + //if over the limit before adding blocks, leave it as-is, because the limit may have changed AFTER he accrued the blocks + if(this.accruedClaimBlocks < accruedLimit) + { + //move any in the holding area + int newTotal = this.accruedClaimBlocks + this.newlyAccruedClaimBlocks; + + //respect limits + this.accruedClaimBlocks = Math.min(newTotal, accruedLimit); + } + + this.newlyAccruedClaimBlocks = 0; + return this.accruedClaimBlocks; + } - //move any in the holding area - int newTotal = this.accruedClaimBlocks + this.newlyAccruedClaimBlocks; - this.newlyAccruedClaimBlocks = 0; - - //respect limits - if(newTotal > GriefPrevention.instance.config_claims_maxAccruedBlocks) newTotal = GriefPrevention.instance.config_claims_maxAccruedBlocks; - this.accruedClaimBlocks = newTotal; - return accruedClaimBlocks; } @@ -335,11 +339,8 @@ public class PlayerData //try to fix it by adding to accrued blocks this.accruedClaimBlocks = totalClaimsArea; - if(this.accruedClaimBlocks > GriefPrevention.instance.config_claims_maxAccruedBlocks) - { - //remember to respect the maximum on accrued blocks - this.accruedClaimBlocks = GriefPrevention.instance.config_claims_maxAccruedBlocks; - } + int accruedLimit = this.getAccruedClaimBlocksLimit(); + this.accruedClaimBlocks = Math.min(accruedLimit, this.accruedClaimBlocks); //if that didn't fix it, then make up the difference with bonus blocks totalBlocks = this.accruedClaimBlocks + this.getBonusClaimBlocks() + GriefPrevention.instance.dataStore.getGroupBonusBlocks(this.playerID); @@ -361,6 +362,19 @@ public class PlayerData return claims; } + //determine limits based on permissions + private int getAccruedClaimBlocksLimit() + { + Player player = Bukkit.getServer().getPlayer(this.playerID); + + //if the player isn't online, give him the benefit of any doubt + if(player == null) return Integer.MAX_VALUE; + + if(player.hasPermission("griefprevention.mostaccrued")) return GriefPrevention.instance.config_claims_maxAccruedBlocks_most; + if(player.hasPermission("griefprevention.moreaccrued")) return GriefPrevention.instance.config_claims_maxAccruedBlocks_more; + return GriefPrevention.instance.config_claims_maxAccruedBlocks_default; + } + public void accrueBlocks(int howMany) { this.newlyAccruedClaimBlocks += howMany;