fix resizing claim not respecting owners claimblocks
This commit is contained in:
parent
9b1400b3d7
commit
23a4675135
@ -8,6 +8,7 @@ Flan 1.5.0
|
||||
Default global value is ALLFALSE so disabled.
|
||||
- Add NOHUNGER permission: Disables hunger in claims
|
||||
Default global value is ALLFALSE so disabled.
|
||||
- Fix resizing claims of other players not using their claim blocks
|
||||
|
||||
Flan 1.4.2
|
||||
======================
|
||||
|
@ -490,7 +490,7 @@ public class Claim implements IPermissionContainer {
|
||||
public void applyEffects(PlayerEntity player) {
|
||||
this.potions.forEach((effect, amp) -> {
|
||||
if (!player.hasStatusEffect(effect))
|
||||
player.applyStatusEffect(new StatusEffectInstance(effect, 200, amp-1, true, false));
|
||||
player.applyStatusEffect(new StatusEffectInstance(effect, 200, amp - 1, true, false));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -7,10 +7,12 @@ import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import io.github.flemmli97.flan.Flan;
|
||||
import io.github.flemmli97.flan.api.ClaimPermission;
|
||||
import io.github.flemmli97.flan.api.IPlayerData;
|
||||
import io.github.flemmli97.flan.api.PermissionRegistry;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.player.EnumDisplayType;
|
||||
import io.github.flemmli97.flan.player.EnumEditMode;
|
||||
import io.github.flemmli97.flan.player.OfflinePlayerData;
|
||||
import io.github.flemmli97.flan.player.PlayerClaimData;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectArrayMap;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
@ -158,9 +160,19 @@ public class ClaimStorage {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.conflictOther, Formatting.RED), false);
|
||||
return false;
|
||||
}
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
int diff = newClaim.getPlane() - claim.getPlane();
|
||||
if (data.canUseClaimBlocks(diff)) {
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
IPlayerData newData = null;
|
||||
boolean enoughBlocks = false;
|
||||
if (player.getUuid().equals(claim.getOwner()) || claim.isAdminClaim()) {
|
||||
enoughBlocks = claim.isAdminClaim() || data.canUseClaimBlocks(diff);
|
||||
newData = data;
|
||||
} else {
|
||||
ServerPlayerEntity other = player.getServer().getPlayerManager().getPlayer(claim.getOwner());
|
||||
newData = other != null ? PlayerClaimData.get(other) : new OfflinePlayerData(player.getServer(), claim.getOwner());
|
||||
enoughBlocks = newData.canUseClaimBlocks(diff);
|
||||
}
|
||||
if (enoughBlocks) {
|
||||
Flan.log("Resizing claim {}", claim);
|
||||
this.deleteClaim(claim, false, EnumEditMode.DEFAULT, player.getServerWorld());
|
||||
claim.copySizes(newClaim);
|
||||
@ -168,7 +180,7 @@ public class ClaimStorage {
|
||||
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.resizeSuccess, Formatting.GOLD), false);
|
||||
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBlocksFormat,
|
||||
data.getClaimBlocks(), data.getAdditionalClaims(), data.usedClaimBlocks()), Formatting.GOLD), false);
|
||||
newData.getClaimBlocks(), newData.getAdditionalClaims(), newData.usedClaimBlocks()), Formatting.GOLD), false);
|
||||
return true;
|
||||
}
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.notEnoughBlocks, Formatting.RED), false);
|
||||
|
@ -13,6 +13,7 @@ import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import io.github.flemmli97.flan.api.ClaimPermission;
|
||||
import io.github.flemmli97.flan.api.IPlayerData;
|
||||
import io.github.flemmli97.flan.api.PermissionRegistry;
|
||||
import io.github.flemmli97.flan.claim.Claim;
|
||||
import io.github.flemmli97.flan.claim.ClaimStorage;
|
||||
@ -160,13 +161,8 @@ public class CommandClaim {
|
||||
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() + claim.getPlane() < newData.claimBlocks + newData.additionalClaimBlocks;
|
||||
}
|
||||
IPlayerData newData = newOwner != null ? PlayerClaimData.get(newOwner) : new OfflinePlayerData(server, prof.getId());
|
||||
enoughBlocks = newData.canUseClaimBlocks(claim.getPlane());
|
||||
}
|
||||
if (!enoughBlocks) {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.ownerTransferNoBlocks, Formatting.RED), false);
|
||||
|
@ -103,6 +103,7 @@ public class LangConfig {
|
||||
public String screenMenuSub = "SubClaim-Menu";
|
||||
public String screenMenuGlobal = "Edit Global Permissions";
|
||||
public String screenMenuGroup = "Edit Permissiongroups";
|
||||
public String screenMenuPotion = "Edit Potioneffects";
|
||||
public String screenMenuDelete = "Delete Claim";
|
||||
public String screenConfirm = "Confirm";
|
||||
public String screenYes = "Yes";
|
||||
|
@ -63,7 +63,7 @@ public class ClaimMenuScreenHandler extends ServerOnlyScreenHandler {
|
||||
break;
|
||||
case 4:
|
||||
ItemStack potions = new ItemStack(Items.POTION);
|
||||
potions.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenMenuGroup, Formatting.GOLD));
|
||||
potions.setCustomName(ServerScreenHelper.coloredGuiText(ConfigHandler.lang.screenMenuPotion, Formatting.GOLD));
|
||||
inv.setStack(i, potions);
|
||||
break;
|
||||
case 8:
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.github.flemmli97.flan.player;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import io.github.flemmli97.flan.api.IPlayerData;
|
||||
import io.github.flemmli97.flan.claim.Claim;
|
||||
import io.github.flemmli97.flan.claim.ClaimStorage;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
@ -14,7 +15,7 @@ import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
|
||||
public class OfflinePlayerData {
|
||||
public class OfflinePlayerData implements IPlayerData {
|
||||
|
||||
public final int claimBlocks, additionalClaimBlocks;
|
||||
public final UUID owner;
|
||||
@ -53,4 +54,19 @@ public class OfflinePlayerData {
|
||||
}
|
||||
return usedClaimsBlocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getClaimBlocks() {
|
||||
return this.claimBlocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAdditionalClaims() {
|
||||
return this.additionalClaimBlocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int usedClaimBlocks() {
|
||||
return this.usedClaimBlocks();
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package io.github.flemmli97.flan.player;
|
||||
import com.google.gson.JsonObject;
|
||||
import io.github.flemmli97.flan.Flan;
|
||||
import io.github.flemmli97.flan.api.ClaimPermission;
|
||||
import io.github.flemmli97.flan.api.IPlayerData;
|
||||
import io.github.flemmli97.flan.api.PermissionRegistry;
|
||||
import io.github.flemmli97.flan.claim.Claim;
|
||||
import io.github.flemmli97.flan.claim.ClaimStorage;
|
||||
@ -35,7 +36,7 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class PlayerClaimData {
|
||||
public class PlayerClaimData implements IPlayerData {
|
||||
|
||||
private int claimBlocks, additionalClaimBlocks, confirmTick, actionCooldown;
|
||||
|
||||
@ -68,6 +69,7 @@ public class PlayerClaimData {
|
||||
return ((IPlayerClaimImpl) player).get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getClaimBlocks() {
|
||||
return this.claimBlocks;
|
||||
}
|
||||
@ -85,6 +87,7 @@ public class PlayerClaimData {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAdditionalClaims() {
|
||||
return this.additionalClaimBlocks;
|
||||
}
|
||||
@ -94,6 +97,7 @@ public class PlayerClaimData {
|
||||
this.dirty = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUseClaimBlocks(int amount) {
|
||||
if (ConfigHandler.config.maxClaimBlocks == -1)
|
||||
return true;
|
||||
@ -101,6 +105,7 @@ public class PlayerClaimData {
|
||||
return usedClaimsBlocks + amount <= this.claimBlocks + this.additionalClaimBlocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int usedClaimBlocks() {
|
||||
return this.calculateUsedClaimBlocks();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user