GriefDefender/sponge/src/main/java/com/griefdefender/task/ClaimBlockTask.java

92 lines
4.8 KiB
Java
Raw Normal View History

2019-11-24 23:01:05 +01:00
/*
* This file is part of GriefDefender, licensed under the MIT License (MIT).
*
* Copyright (c) bloodmc
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.griefdefender.task;
import com.google.common.reflect.TypeToken;
import com.griefdefender.GDPlayerData;
import com.griefdefender.GriefDefenderPlugin;
import com.griefdefender.api.permission.option.Options;
import com.griefdefender.claim.GDClaim;
import com.griefdefender.permission.GDPermissionManager;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.data.manipulator.mutable.entity.VehicleData;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.service.economy.Currency;
import org.spongepowered.api.service.economy.account.Account;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;
import java.math.BigDecimal;
import java.util.Optional;
public class ClaimBlockTask implements Runnable {
public ClaimBlockTask() {
}
@Override
public void run() {
for (World world : Sponge.getServer().getWorlds()) {
final int blockMoveThreshold = GriefDefenderPlugin.getActiveConfig(world.getProperties()).getConfig().claim.claimBlockTaskMoveThreshold;
for (Player player : world.getPlayers()) {
final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
final GDClaim claim = GriefDefenderPlugin.getInstance().dataStore.getClaimAtPlayer(playerData, player.getLocation());
final int accrualPerHour = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Integer.class), player, Options.BLOCKS_ACCRUED_PER_HOUR, claim);
if (accrualPerHour > 0) {
final Location<World> lastLocation = playerData.lastAfkCheckLocation;
if (!player.get(VehicleData.class).isPresent() &&
Update for 1.5.9 release. * Fix playerdata getting wrong accrued claim block value if world context existed while in global mode. * Fix Citizen NPC's being denied entry to claim when flag 'enter-claim' is false. * Fix some zh_HK translations. * Fix NPE during potion splash. * Fix enderman-grief flag definition. * Fix villager-trade flag definition. * Fix villager-farm flag definition. * Fix timing NPE in EntityEventHandler. * Fix owner name showing for enter/exit prefix in wilderness/admin claims. * Fix untamed animals being denied when attacking eachother. * Add 'claim-block-task' setting in global.conf to control whether block accrue task runs. * Add animal-block-modify flag definition. * Add ravager-block-break flag definition. * Add silverfish-block-infest flag definition. * Add new visual config setting 'cuboid-level-visuals-2d' under visual category to control whether cuboid visuals should be show during inspection of 2d claims with owner min/max level between 0-255. * Add ru_RU translations for new flag definitions. * Remove 'ForSale' click function in '/claiminfo' as it is no longer needed. * Rewrite EntityChangeBlockEvent handling. Handler will now use the proper block flag when handling source/target block changes. * (Sponge) Fix 'flowing_water' spam in gddebug. * (Sponge) Add ice form/melt detection. * (Sponge) Fix NPE in Nucleus listener. * (Sponge) Fix rent sign interval. * (Sponge) Fix compatibility with LittleTiles mod. * (Sponge) Fix inability to disable modification/investigation tool in config. * (Sponge) Fix some more debug spam during block pre event.
2021-01-08 19:59:00 +01:00
(lastLocation == null || lastLocation.getPosition().distanceSquared(player.getLocation().getPosition()) >= (blockMoveThreshold * blockMoveThreshold))) {
int accruedBlocks = playerData.getBlocksAccruedPerHour() / 12;
if (accruedBlocks < 0) {
accruedBlocks = 1;
}
2019-11-24 23:01:05 +01:00
if (GriefDefenderPlugin.getInstance().isEconomyModeEnabled()) {
final Account playerAccount = GriefDefenderPlugin.getInstance().economyService.get().getOrCreateAccount(player.getUniqueId()).orElse(null);
if (playerAccount == null) {
Update for 1.5.10 release. * Fix ClaimBlockTask prematurely exiting if a player had max claim blocks. * Fix TaxApplyTask not pulling funds from claim bank first. * Fix ClaimContextCalculator overwriting option claim contexts. * Fix player option commands running during a command causing a loop. * Fix player-command-enter running command from subclaim. * Fix player-command-exit running command to subclaim. * Fix player contexts not being added in all cases where a player is involved. * Fix flag definitions not accepting any context. * Fix elytra enter-claim bypass. * Add 'claim-create-radius-limit' to global config. * Add Simplified Chinese language support (zh_CN). * Add enter-claim flag permission check on player login. * Add enter/exit-claim support for player respawns. If denied, GD will respawn player back in source claim in a safe location. * Add TE NBT id support for mods such as gregtech. * (Hybrid) Fix mohist EntityType mod registration. * (Hybrid/Sponge) Add TE NBT id support for mods such as gregtech. See new setting 'tile-id-nbt-map' under mod category in global.conf * (Sponge) Add 'interact-item-force-list' to global config. Used to force interact-item flag checks when a player left/right-clicks with an item in hand. * (Sponge) Add check to prevent re-registration of worlds. * (Sponge) Add workaround during collisions when user is wrapped in ProjectileSource. * (Sponge) Add EntityThrowable support for getEntityOwner. * (Sponge) Add method to get internal DamageSource type name. * (Sponge) Fix NPE when cancelling claim with '/claimrent cancel' * (Sponge) Fix wrong block being checked during bucket interactions such as lava and water. * (Sponge) Fix block-pre not handing certain mod permission checks such as AE2 cables. * (Sponge) Fix 'block-id-convert-list' feature not using correct id during player interactions. * (Sponge) Fix item-pickup flag not checking trust.
2021-02-06 00:06:14 +01:00
continue;
}
2019-11-24 23:01:05 +01:00
final Currency defaultCurrency = GriefDefenderPlugin.getInstance().economyService.get().getDefaultCurrency();
playerAccount.deposit(defaultCurrency, BigDecimal.valueOf(accruedBlocks), Sponge.getCauseStackManager().getCurrentCause());
} else {
int currentTotal = playerData.getAccruedClaimBlocks();
if ((currentTotal + accruedBlocks) > playerData.getMaxAccruedClaimBlocks()) {
playerData.setAccruedClaimBlocks(playerData.getMaxAccruedClaimBlocks());
playerData.lastAfkCheckLocation = player.getLocation();
Update for 1.5.10 release. * Fix ClaimBlockTask prematurely exiting if a player had max claim blocks. * Fix TaxApplyTask not pulling funds from claim bank first. * Fix ClaimContextCalculator overwriting option claim contexts. * Fix player option commands running during a command causing a loop. * Fix player-command-enter running command from subclaim. * Fix player-command-exit running command to subclaim. * Fix player contexts not being added in all cases where a player is involved. * Fix flag definitions not accepting any context. * Fix elytra enter-claim bypass. * Add 'claim-create-radius-limit' to global config. * Add Simplified Chinese language support (zh_CN). * Add enter-claim flag permission check on player login. * Add enter/exit-claim support for player respawns. If denied, GD will respawn player back in source claim in a safe location. * Add TE NBT id support for mods such as gregtech. * (Hybrid) Fix mohist EntityType mod registration. * (Hybrid/Sponge) Add TE NBT id support for mods such as gregtech. See new setting 'tile-id-nbt-map' under mod category in global.conf * (Sponge) Add 'interact-item-force-list' to global config. Used to force interact-item flag checks when a player left/right-clicks with an item in hand. * (Sponge) Add check to prevent re-registration of worlds. * (Sponge) Add workaround during collisions when user is wrapped in ProjectileSource. * (Sponge) Add EntityThrowable support for getEntityOwner. * (Sponge) Add method to get internal DamageSource type name. * (Sponge) Fix NPE when cancelling claim with '/claimrent cancel' * (Sponge) Fix wrong block being checked during bucket interactions such as lava and water. * (Sponge) Fix block-pre not handing certain mod permission checks such as AE2 cables. * (Sponge) Fix 'block-id-convert-list' feature not using correct id during player interactions. * (Sponge) Fix item-pickup flag not checking trust.
2021-02-06 00:06:14 +01:00
continue;
}
2019-11-24 23:01:05 +01:00
playerData.setAccruedClaimBlocks(playerData.getAccruedClaimBlocks() + accruedBlocks);
}
}
2019-11-24 23:01:05 +01:00
playerData.lastAfkCheckLocation = player.getLocation();
2019-11-24 23:01:05 +01:00
}
}
}
}
}