Permissions for claim block accrual.
Added nodes for higher limits on accrued blocks and faster accrual.
This commit is contained in:
parent
ee857f3a83
commit
c7327d4982
12
plugin.yml
12
plugin.yml
|
|
@ -341,3 +341,15 @@ permissions:
|
||||||
griefprevention.eavesdropimmune:
|
griefprevention.eavesdropimmune:
|
||||||
description: Players with this permission can't have their private messages eavesdropped.
|
description: Players with this permission can't have their private messages eavesdropped.
|
||||||
default: op
|
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
|
||||||
|
|
@ -38,8 +38,6 @@ class DeliverClaimBlocksTask implements Runnable
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
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 no player specified, this task will create a player-specific task for each online player, scheduled one tick apart
|
||||||
if(this.player == null)
|
if(this.player == null)
|
||||||
{
|
{
|
||||||
|
|
@ -57,6 +55,8 @@ class DeliverClaimBlocksTask implements Runnable
|
||||||
//otherwise, deliver claim blocks to the specified player
|
//otherwise, deliver claim blocks to the specified player
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if(!this.player.isOnline()) return;
|
||||||
|
|
||||||
DataStore dataStore = GriefPrevention.instance.dataStore;
|
DataStore dataStore = GriefPrevention.instance.dataStore;
|
||||||
PlayerData playerData = dataStore.getPlayerData(player.getUniqueId());
|
PlayerData playerData = dataStore.getPlayerData(player.getUniqueId());
|
||||||
|
|
||||||
|
|
@ -69,21 +69,24 @@ class DeliverClaimBlocksTask implements Runnable
|
||||||
(lastLocation == null || lastLocation.distanceSquared(player.getLocation()) >= 0) &&
|
(lastLocation == null || lastLocation.distanceSquared(player.getLocation()) >= 0) &&
|
||||||
!player.getLocation().getBlock().isLiquid())
|
!player.getLocation().getBlock().isLiquid())
|
||||||
{
|
{
|
||||||
//add blocks
|
//determine how fast blocks accrue for this player
|
||||||
int accruedBlocks = GriefPrevention.instance.config_claims_blocksAccruedPerHour / 6;
|
int accrualRate = GriefPrevention.instance.config_claims_blocksAccruedPerHour_default;
|
||||||
if(accruedBlocks < 0) accruedBlocks = 1;
|
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);
|
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
|
//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);
|
//dataStore.savePlayerData(player.getUniqueIdentifier(), playerData);
|
||||||
}
|
}
|
||||||
else
|
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
|
catch(IllegalArgumentException e) //can't measure distance when to/from are different worlds
|
||||||
|
|
|
||||||
|
|
@ -795,6 +795,9 @@ public class EntityEventHandler implements Listener
|
||||||
//allow for disabling villager protections in the config
|
//allow for disabling villager protections in the config
|
||||||
if(subEvent.getEntityType() == EntityType.VILLAGER && !GriefPrevention.instance.config_claims_protectCreatures) return;
|
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
|
//decide whether it's claimed
|
||||||
Claim cachedClaim = null;
|
Claim cachedClaim = null;
|
||||||
PlayerData playerData = null;
|
PlayerData playerData = null;
|
||||||
|
|
|
||||||
|
|
@ -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 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 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_blocksAccruedPerHour_default; //how many additional blocks players get each hour of play (can be zero) without any special permissions
|
||||||
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_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_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_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
|
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
|
//unless claim block accrual is disabled, start the recurring per 10 minute event to give claim blocks to online players
|
||||||
//20L ~ 1 second
|
//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);
|
DeliverClaimBlocksTask task = new DeliverClaimBlocksTask(null);
|
||||||
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, task, 20L * 60 * 10, 20L * 60 * 10);
|
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_lockFenceGates = config.getBoolean("GriefPrevention.Claims.LockFenceGates", true);
|
||||||
this.config_claims_enderPearlsRequireAccessTrust = config.getBoolean("GriefPrevention.Claims.EnderPearlsRequireAccessTrust", true);
|
this.config_claims_enderPearlsRequireAccessTrust = config.getBoolean("GriefPrevention.Claims.EnderPearlsRequireAccessTrust", true);
|
||||||
this.config_claims_initialBlocks = config.getInt("GriefPrevention.Claims.InitialBlocks", 100);
|
this.config_claims_initialBlocks = config.getInt("GriefPrevention.Claims.InitialBlocks", 100);
|
||||||
this.config_claims_blocksAccruedPerHour = config.getInt("GriefPrevention.Claims.BlocksAccruedPerHour", 100);
|
this.config_claims_blocksAccruedPerHour_default = 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.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_abandonReturnRatio = config.getDouble("GriefPrevention.Claims.AbandonReturnRatio", 1);
|
||||||
this.config_claims_automaticClaimsForNewPlayersRadius = config.getInt("GriefPrevention.Claims.AutomaticNewPlayerClaimsRadius", 4);
|
this.config_claims_automaticClaimsForNewPlayersRadius = config.getInt("GriefPrevention.Claims.AutomaticNewPlayerClaimsRadius", 4);
|
||||||
this.config_claims_claimsExtendIntoGroundDistance = Math.abs(config.getInt("GriefPrevention.Claims.ExtendIntoGroundDistance", 5));
|
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.EnderPearlsRequireAccessTrust", this.config_claims_enderPearlsRequireAccessTrust);
|
||||||
outConfig.set("GriefPrevention.Claims.ProtectHorses", this.config_claims_protectHorses);
|
outConfig.set("GriefPrevention.Claims.ProtectHorses", this.config_claims_protectHorses);
|
||||||
outConfig.set("GriefPrevention.Claims.InitialBlocks", this.config_claims_initialBlocks);
|
outConfig.set("GriefPrevention.Claims.InitialBlocks", this.config_claims_initialBlocks);
|
||||||
outConfig.set("GriefPrevention.Claims.BlocksAccruedPerHour", this.config_claims_blocksAccruedPerHour);
|
outConfig.set("GriefPrevention.Claims.Claim Blocks Accrued Per Hour.Default", this.config_claims_blocksAccruedPerHour_default);
|
||||||
outConfig.set("GriefPrevention.Claims.MaxAccruedBlocks", this.config_claims_maxAccruedBlocks);
|
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.AbandonReturnRatio", this.config_claims_abandonReturnRatio);
|
||||||
outConfig.set("GriefPrevention.Claims.AutomaticNewPlayerClaimsRadius", this.config_claims_automaticClaimsForNewPlayersRadius);
|
outConfig.set("GriefPrevention.Claims.AutomaticNewPlayerClaimsRadius", this.config_claims_automaticClaimsForNewPlayersRadius);
|
||||||
outConfig.set("GriefPrevention.Claims.ExtendIntoGroundDistance", this.config_claims_claimsExtendIntoGroundDistance);
|
outConfig.set("GriefPrevention.Claims.ExtendIntoGroundDistance", this.config_claims_claimsExtendIntoGroundDistance);
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,10 @@ import me.ryanhamshire.GriefPrevention.ShovelMode;
|
||||||
import me.ryanhamshire.GriefPrevention.SiegeData;
|
import me.ryanhamshire.GriefPrevention.SiegeData;
|
||||||
import me.ryanhamshire.GriefPrevention.Visualization;
|
import me.ryanhamshire.GriefPrevention.Visualization;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
//holds all of GriefPrevention's player-tied data
|
//holds all of GriefPrevention's player-tied data
|
||||||
public class PlayerData
|
public class PlayerData
|
||||||
|
|
@ -186,22 +188,24 @@ public class PlayerData
|
||||||
{
|
{
|
||||||
if(this.accruedClaimBlocks == null) this.loadDataFromSecondaryStorage();
|
if(this.accruedClaimBlocks == null) this.loadDataFromSecondaryStorage();
|
||||||
|
|
||||||
//if player is over accrued limit, accrued limit was probably reduced in config file AFTER he accrued
|
//update claim blocks with any he has accrued during his current play session
|
||||||
//in that case, leave his blocks where they are
|
if(this.newlyAccruedClaimBlocks > 0)
|
||||||
int currentTotal = this.accruedClaimBlocks;
|
|
||||||
if(currentTotal >= GriefPrevention.instance.config_claims_maxAccruedBlocks)
|
|
||||||
{
|
{
|
||||||
this.newlyAccruedClaimBlocks = 0;
|
int accruedLimit = this.getAccruedClaimBlocksLimit();
|
||||||
return currentTotal;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
//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
|
//move any in the holding area
|
||||||
int newTotal = this.accruedClaimBlocks + this.newlyAccruedClaimBlocks;
|
int newTotal = this.accruedClaimBlocks + this.newlyAccruedClaimBlocks;
|
||||||
this.newlyAccruedClaimBlocks = 0;
|
|
||||||
|
|
||||||
//respect limits
|
//respect limits
|
||||||
if(newTotal > GriefPrevention.instance.config_claims_maxAccruedBlocks) newTotal = GriefPrevention.instance.config_claims_maxAccruedBlocks;
|
this.accruedClaimBlocks = Math.min(newTotal, accruedLimit);
|
||||||
this.accruedClaimBlocks = newTotal;
|
}
|
||||||
|
|
||||||
|
this.newlyAccruedClaimBlocks = 0;
|
||||||
|
return this.accruedClaimBlocks;
|
||||||
|
}
|
||||||
|
|
||||||
return accruedClaimBlocks;
|
return accruedClaimBlocks;
|
||||||
}
|
}
|
||||||
|
|
@ -335,11 +339,8 @@ public class PlayerData
|
||||||
|
|
||||||
//try to fix it by adding to accrued blocks
|
//try to fix it by adding to accrued blocks
|
||||||
this.accruedClaimBlocks = totalClaimsArea;
|
this.accruedClaimBlocks = totalClaimsArea;
|
||||||
if(this.accruedClaimBlocks > GriefPrevention.instance.config_claims_maxAccruedBlocks)
|
int accruedLimit = this.getAccruedClaimBlocksLimit();
|
||||||
{
|
this.accruedClaimBlocks = Math.min(accruedLimit, this.accruedClaimBlocks);
|
||||||
//remember to respect the maximum on accrued blocks
|
|
||||||
this.accruedClaimBlocks = GriefPrevention.instance.config_claims_maxAccruedBlocks;
|
|
||||||
}
|
|
||||||
|
|
||||||
//if that didn't fix it, then make up the difference with bonus blocks
|
//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);
|
totalBlocks = this.accruedClaimBlocks + this.getBonusClaimBlocks() + GriefPrevention.instance.dataStore.getGroupBonusBlocks(this.playerID);
|
||||||
|
|
@ -361,6 +362,19 @@ public class PlayerData
|
||||||
return claims;
|
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)
|
public void accrueBlocks(int howMany)
|
||||||
{
|
{
|
||||||
this.newlyAccruedClaimBlocks += howMany;
|
this.newlyAccruedClaimBlocks += howMany;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user