feat: add remaining claim blocks

This commit is contained in:
Jarva 2022-07-12 04:13:22 +01:00
parent b3907b00ae
commit 8f97e6780f
5 changed files with 13 additions and 6 deletions

View File

@ -10,6 +10,8 @@ public interface IPlayerData {
int usedClaimBlocks(); int usedClaimBlocks();
int remainingClaimBlocks();
void setAdditionalClaims(int amount); void setAdditionalClaims(int amount);
default boolean canUseClaimBlocks(int amount) { default boolean canUseClaimBlocks(int amount) {

View File

@ -107,7 +107,7 @@ public class ClaimStorage implements IPermissionStorage {
data.updateScoreboard(); data.updateScoreboard();
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.langManager.get("claimCreateSuccess"), ChatFormatting.GOLD), false); player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.langManager.get("claimCreateSuccess"), ChatFormatting.GOLD), false);
player.displayClientMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("claimBlocksFormat"), player.displayClientMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("claimBlocksFormat"),
data.getClaimBlocks(), data.getAdditionalClaims(), data.usedClaimBlocks()), ChatFormatting.GOLD), false); data.getClaimBlocks(), data.getAdditionalClaims(), data.usedClaimBlocks(), data.remainingClaimBlocks()), ChatFormatting.GOLD), false);
return true; return true;
} }
PlayerClaimData data = PlayerClaimData.get(player); PlayerClaimData data = PlayerClaimData.get(player);
@ -202,7 +202,7 @@ public class ClaimStorage implements IPermissionStorage {
((PlayerClaimData) newData).updateScoreboard(); ((PlayerClaimData) newData).updateScoreboard();
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.langManager.get("resizeSuccess"), ChatFormatting.GOLD), false); player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.langManager.get("resizeSuccess"), ChatFormatting.GOLD), false);
player.displayClientMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("claimBlocksFormat"), player.displayClientMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("claimBlocksFormat"),
newData.getClaimBlocks(), newData.getAdditionalClaims(), newData.usedClaimBlocks()), ChatFormatting.GOLD), false); newData.getClaimBlocks(), newData.getAdditionalClaims(), newData.usedClaimBlocks(), data.remainingClaimBlocks()), ChatFormatting.GOLD), false);
return true; return true;
} }
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.langManager.get("notEnoughBlocks"), ChatFormatting.RED), false); player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.langManager.get("notEnoughBlocks"), ChatFormatting.RED), false);

View File

@ -444,11 +444,11 @@ public class CommandClaim {
if (player != null) { if (player != null) {
PlayerClaimData data = PlayerClaimData.get(player); PlayerClaimData data = PlayerClaimData.get(player);
context.getSource().sendSuccess(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("claimBlocksFormat"), context.getSource().sendSuccess(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("claimBlocksFormat"),
data.getClaimBlocks(), data.getAdditionalClaims(), data.usedClaimBlocks()), ChatFormatting.GOLD), false); data.getClaimBlocks(), data.getAdditionalClaims(), data.usedClaimBlocks(), data.remainingClaimBlocks()), ChatFormatting.GOLD), false);
} else { } else {
OfflinePlayerData data = new OfflinePlayerData(server, of); OfflinePlayerData data = new OfflinePlayerData(server, of);
context.getSource().sendSuccess(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("claimBlocksFormat"), context.getSource().sendSuccess(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("claimBlocksFormat"),
data.claimBlocks, data.getAdditionalClaims(), data.usedClaimBlocks()), ChatFormatting.GOLD), false); data.claimBlocks, data.getAdditionalClaims(), data.usedClaimBlocks(), data.remainingClaimBlocks()), ChatFormatting.GOLD), false);
} }
} }
context.getSource().sendSuccess(PermHelper.simpleColoredText(ConfigHandler.langManager.get("listClaims"), ChatFormatting.GOLD), false); context.getSource().sendSuccess(PermHelper.simpleColoredText(ConfigHandler.langManager.get("listClaims"), ChatFormatting.GOLD), false);

View File

@ -39,7 +39,7 @@ public class LangManager {
this.defaultTranslation.put("noClaim", "There is no claim here."); this.defaultTranslation.put("noClaim", "There is no claim here.");
this.defaultTranslation.put("inspectBlockOwner", "This is %1$s's claim"); this.defaultTranslation.put("inspectBlockOwner", "This is %1$s's claim");
this.defaultTranslation.put("inspectNoClaim", "Nobody owns this block"); this.defaultTranslation.put("inspectNoClaim", "Nobody owns this block");
this.defaultTranslation.put("claimBlocksFormat", "Claim Blocks: %1$d + (Bonus) %2$d); Used: %3$d"); this.defaultTranslation.put("claimBlocksFormat", "Claim Blocks: %1$d + (Bonus) %2$d); Used: %3$d; Remaining %4$d");
this.defaultTranslation.put("listClaims", "Listing all claims:"); this.defaultTranslation.put("listClaims", "Listing all claims:");
this.defaultTranslation.put("listAdminClaims", "Listing all admin-claims in %1$s:"); this.defaultTranslation.put("listAdminClaims", "Listing all admin-claims in %1$s:");
this.defaultTranslation.put("onlyOnePlayer", "Only one player can be used as argument"); this.defaultTranslation.put("onlyOnePlayer", "Only one player can be used as argument");

View File

@ -134,6 +134,11 @@ public class PlayerClaimData implements IPlayerData {
return this.calculateUsedClaimBlocks(); return this.calculateUsedClaimBlocks();
} }
@Override
public int remainingClaimBlocks() {
return this.getClaimBlocks() + this.getAdditionalClaims() - this.usedClaimBlocks();
}
/** /**
* To prevent double processing. most notably when right clicking on a block and the block doesnt do anything -> * To prevent double processing. most notably when right clicking on a block and the block doesnt do anything ->
* block onUse -> item use. Might be a better way but for now this. But also handles having * block onUse -> item use. Might be a better way but for now this. But also handles having
@ -286,7 +291,7 @@ public class PlayerClaimData implements IPlayerData {
} else if (!this.claimBlockMessage) { } else if (!this.claimBlockMessage) {
this.claimBlockMessage = true; this.claimBlockMessage = true;
this.player.displayClientMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("claimBlocksFormat"), this.player.displayClientMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("claimBlocksFormat"),
this.getClaimBlocks(), this.getAdditionalClaims(), this.usedClaimBlocks()), ChatFormatting.GOLD), false); this.getClaimBlocks(), this.getAdditionalClaims(), this.usedClaimBlocks(), this.remainingClaimBlocks()), ChatFormatting.GOLD), false);
} }
this.actionCooldown--; this.actionCooldown--;
if (--this.trappedTick >= 0) { if (--this.trappedTick >= 0) {