Skip to content

Commit

Permalink
Merge branch 'GriefPrevention:master' into update
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBedrock authored Oct 12, 2024
2 parents ac6dd29 + b6512aa commit d589d08
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ class DeliverClaimBlocksTask implements Runnable
{
private final Player player;
private final GriefPrevention instance;
private final int idleThresholdSquared;

public DeliverClaimBlocksTask(Player player, GriefPrevention instance)
{
this.player = player;
this.instance = instance;
this.idleThresholdSquared = instance.config_claims_accruedIdleThreshold * instance.config_claims_accruedIdleThreshold;
}

@Override
Expand Down Expand Up @@ -67,45 +65,28 @@ public void run()
DataStore dataStore = instance.dataStore;
PlayerData playerData = dataStore.getPlayerData(player.getUniqueId());

// check if player is idle. considered idle if
// in vehicle or is in water (pushed by water)
// or has not moved at least defined blocks since last check
// check if player is idle (considered idle if player's facing direction has not changed)
boolean isIdle = false;
try
{
isIdle = player.isInsideVehicle() || player.getLocation().getBlock().isLiquid() ||
!(playerData.lastAfkCheckLocation == null || playerData.lastAfkCheckLocation.distanceSquared(player.getLocation()) > idleThresholdSquared);
}
catch (IllegalArgumentException ignore) //can't measure distance when to/from are different worlds
{
}
isIdle = !(playerData.lastAfkCheckLocation == null || playerData.lastAfkCheckLocation.getDirection().equals(player.getLocation().getDirection()));

//remember current location for next time
playerData.lastAfkCheckLocation = player.getLocation();

try
{
//determine how fast blocks accrue for this player //RoboMWM: addons determine this instead
//determine how fast blocks accrue for this player; can be modified by addons
int accrualRate = instance.config_claims_blocksAccruedPerHour_default;

//determine idle accrual rate when idle
if (isIdle)
{
if (instance.config_claims_accruedIdlePercent <= 0)
{
GriefPrevention.AddLogEntry(player.getName() + " wasn't active enough to accrue claim blocks this round.", CustomLogEntryTypes.Debug, true);
return; //idle accrual percentage is disabled
}

accrualRate = (int) (accrualRate * (instance.config_claims_accruedIdlePercent / 100.0D));
}

//fire event for addons
AccrueClaimBlocksEvent event = new AccrueClaimBlocksEvent(player, accrualRate, isIdle);
instance.getServer().getPluginManager().callEvent(event);
if (event.isCancelled())
{
GriefPrevention.AddLogEntry(player.getName() + " claim block delivery was canceled by another plugin.", CustomLogEntryTypes.Debug, true);
//event is initialized as canceled if player is idle
if (event.isIdle())
GriefPrevention.AddLogEntry(player.getName() + " wasn't active enough to accrue claim blocks this round.", CustomLogEntryTypes.Debug, true);
else
GriefPrevention.AddLogEntry(player.getName() + " claim block delivery was canceled by another plugin.", CustomLogEntryTypes.Debug, true);
return; //event was cancelled
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ public class GriefPrevention extends JavaPlugin
public double config_claims_abandonReturnRatio; //the portion of claim blocks returned to a player when a claim is abandoned
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_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_accruedIdleThreshold; //how far (in blocks) a player must move in order to not be considered afk/idle when determining accrued claim blocks
public int config_claims_accruedIdlePercent; //how much percentage of claim block accruals should idle players get
public int config_claims_maxDepth; //limit on how deep claims can go
public boolean config_claims_expirationEnabled; //whether automatic claim expiration is enabled (default true)
public int config_claims_expirationDays; //how many days of inactivity before a player loses his claims
Expand Down Expand Up @@ -548,9 +546,6 @@ else if (world.getEnvironment() == Environment.NORMAL)
this.config_claims_blocksAccruedPerHour_default = config.getInt("GriefPrevention.Claims.Claim Blocks Accrued Per Hour.Default", config_claims_blocksAccruedPerHour_default);
this.config_claims_maxAccruedBlocks_default = config.getInt("GriefPrevention.Claims.MaxAccruedBlocks", 80000);
this.config_claims_maxAccruedBlocks_default = config.getInt("GriefPrevention.Claims.Max Accrued Claim Blocks.Default", this.config_claims_maxAccruedBlocks_default);
this.config_claims_accruedIdleThreshold = config.getInt("GriefPrevention.Claims.AccruedIdleThreshold", 0);
this.config_claims_accruedIdleThreshold = config.getInt("GriefPrevention.Claims.Accrued Idle Threshold", this.config_claims_accruedIdleThreshold);
this.config_claims_accruedIdlePercent = config.getInt("GriefPrevention.Claims.AccruedIdlePercent", 0);
this.config_claims_abandonReturnRatio = config.getDouble("GriefPrevention.Claims.AbandonReturnRatio", 1.0D);
this.config_claims_automaticClaimsForNewPlayersRadius = config.getInt("GriefPrevention.Claims.AutomaticNewPlayerClaimsRadius", 4);
this.config_claims_automaticClaimsForNewPlayersRadiusMin = Math.max(0, Math.min(this.config_claims_automaticClaimsForNewPlayersRadius,
Expand Down Expand Up @@ -715,8 +710,6 @@ else if (world.getEnvironment() == Environment.NORMAL)
outConfig.set("GriefPrevention.Claims.InitialBlocks", this.config_claims_initialBlocks);
outConfig.set("GriefPrevention.Claims.Claim Blocks Accrued Per Hour.Default", this.config_claims_blocksAccruedPerHour_default);
outConfig.set("GriefPrevention.Claims.Max Accrued Claim Blocks.Default", this.config_claims_maxAccruedBlocks_default);
outConfig.set("GriefPrevention.Claims.Accrued Idle Threshold", this.config_claims_accruedIdleThreshold);
outConfig.set("GriefPrevention.Claims.AccruedIdlePercent", this.config_claims_accruedIdlePercent);
outConfig.set("GriefPrevention.Claims.AbandonReturnRatio", this.config_claims_abandonReturnRatio);
outConfig.set("GriefPrevention.Claims.AutomaticNewPlayerClaimsRadius", this.config_claims_automaticClaimsForNewPlayersRadius);
outConfig.set("GriefPrevention.Claims.AutomaticNewPlayerClaimsRadiusMinimum", this.config_claims_automaticClaimsForNewPlayersRadiusMin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public AccrueClaimBlocksEvent(@NotNull Player player, int blocksToAccruePerHour)
* 6 times per hour.
* <br>To achieve a specific number of blocks to accrue, either multiply in advance or set
* using {@link #setBlocksToAccrue(int)} after construction.
* <br>This event is initialized as canceled if @param isIdle is set to true.
*
* @param player the {@link Player} receiving accruals
* @param blocksToAccruePerHour the number of claim blocks to accrue multiplied by 6
Expand All @@ -57,6 +58,8 @@ public AccrueClaimBlocksEvent(@NotNull Player player, int blocksToAccruePerHour,
super(player);
this.blocksToAccrue = blocksToAccruePerHour / 6;
this.isIdle = isIdle;
if (isIdle)
this.setCancelled(true);
}

/**
Expand Down

0 comments on commit d589d08

Please sign in to comment.