check if new owner has enough blocks. fix #41

This commit is contained in:
Flemmli97 2021-04-04 12:33:10 +02:00
parent e5e1fc921a
commit 5c9403cf7c
5 changed files with 33 additions and 5 deletions

View File

@ -1,3 +1,10 @@
Flan 1.2.4
======================
- Fix crash in void worlds #39
- Fix permission autocomplete #43
- Fix mod icon #42
- Check if the new owner has enough claim blocks when using transferClaim. Bypassed with admin mode
Flan 1.2.3
======================
- Fabric Permission API support for commands and claim creation. See wiki for permission nodes

View File

@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx2G
loader_version=0.9.1+build.205
# Mod Properties
mod_version = 1.2.3
mod_version = 1.2.4
maven_group = com.flemmli97.flan
archives_base_name = flan

View File

@ -36,8 +36,8 @@ import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.util.Collection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@ -128,6 +128,25 @@ public class CommandClaim {
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false);
return 0;
}
PlayerClaimData data = PlayerClaimData.get(player);
boolean enoughBlocks = true;
if (!data.isAdminIgnoreClaim()) {
MinecraftServer server = context.getSource().getMinecraftServer();
ServerPlayerEntity newOwner = server.getPlayerManager().getPlayer(prof.getId());
if (newOwner != null) {
PlayerClaimData newData = PlayerClaimData.get(newOwner);
enoughBlocks = newData.canUseClaimBlocks(claim.getPlane());
} else {
OfflinePlayerData newData = new OfflinePlayerData(server, prof.getId());
enoughBlocks = ConfigHandler.config.maxClaimBlocks == -1 || newData.getUsedClaimBlocks(server) + claim.getPlane() < newData.claimBlocks + newData.additionalClaimBlocks;
}
}
if (!enoughBlocks) {
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.ownerTransferNoBlocks, Formatting.RED), false);
if (CommandPermission.perm(context.getSource(), CommandPermission.cmdAdminMode, true))
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.ownerTransferNoBlocksAdmin, Formatting.RED), false);
return 0;
}
if (!storage.transferOwner(claim, player, prof.getId())) {
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.ownerTransferFail, Formatting.RED), false);
return 0;

View File

@ -28,6 +28,8 @@ public class LangConfig {
public String onlyOnePlayer = "Only one player can be used as argument";
public String ownerTransferSuccess = "New Claimowner now: %s";
public String ownerTransferFail = "Only the owner may transfer claims";
public String ownerTransferNoBlocks = "The new owner doesnt have enough claimblocks";
public String ownerTransferNoBlocksAdmin = "You can ignore this by switching to admin mode";
public String noPermission = "You don't have the required permissions to do that here!";
public String noPermissionSimple = "Sorry you can't do that here!";

View File

@ -136,14 +136,14 @@ public class EntityInteractEvents {
}
Entity hit = ((EntityHitResult) res).getEntity();
boolean fail = attackSimple(player, hit, true) != ActionResult.PASS;
if(fail && proj instanceof PersistentProjectileEntity && ((PersistentProjectileEntity) proj).getPierceLevel() > 0) {
if (fail && proj instanceof PersistentProjectileEntity && ((PersistentProjectileEntity) proj).getPierceLevel() > 0) {
PersistentProjectileEntity pers = (PersistentProjectileEntity) proj;
IntOpenHashSet pierced = ((IPersistentProjectileVars) pers).getPiercedEntities();
if(pierced == null)
if (pierced == null)
pierced = new IntOpenHashSet(5);
pierced.add(hit.getEntityId());
((IPersistentProjectileVars) pers).setPiercedEntities(pierced);
pers.setPierceLevel((byte) (pers.getPierceLevel() +1));
pers.setPierceLevel((byte) (pers.getPierceLevel() + 1));
}
return fail;
}