Skip to content

Commit

Permalink
Don't allow worthiness modification if contract is not signed
Browse files Browse the repository at this point in the history
  • Loading branch information
SamB440 committed Apr 6, 2024
1 parent 6876d07 commit 248f1f0
Showing 1 changed file with 14 additions and 13 deletions.
Expand Up @@ -23,19 +23,8 @@ public class GuildPlayer {
PlayerKingdom.CODEC.optionalFieldOf("kingdom").forGetter(guildPlayer -> Optional.ofNullable(guildPlayer.getKingdom())),
Uuids.CODEC.listOf().fieldOf("hunters").forGetter(GuildPlayer::getHunters),
Codec.BOOL.fieldOf("has_rebuilt_guild").forGetter(GuildPlayer::hasRebuiltGuild)
).apply(instance, (signedContract, coins, bankerCoins, worthiness, farmerLastBread, kingdom, hunters, hasRebuiltGuild) -> {
final GuildPlayer guildPlayer = new GuildPlayer();
guildPlayer.setSignedContract(signedContract);
guildPlayer.setCoins(coins);
guildPlayer.setBankerCoins(bankerCoins);
guildPlayer.setWorthiness(worthiness);
guildPlayer.setFarmerLastBread(farmerLastBread);
guildPlayer.setKingdom(kingdom.orElse(null));
guildPlayer.getHunters().addAll(hunters);
guildPlayer.setHasRebuiltGuild(hasRebuiltGuild);
return guildPlayer;
}
));
).apply(instance, GuildPlayer::new)
);

private boolean signedContract;
private int coins;
Expand All @@ -51,6 +40,17 @@ public GuildPlayer() {
this.farmerLastBread = -1;
}

private GuildPlayer(boolean signedContract, int coins, int bankerCoins, int worthiness, long farmerLastBread, Optional<PlayerKingdom> kingdom, List<UUID> hunters, boolean hasRebuiltGuild) {
this.signedContract = signedContract;
this.coins = coins;
this.bankerCoins = bankerCoins;
this.worthiness = worthiness;
this.farmerLastBread = farmerLastBread;
this.kingdom = kingdom.orElse(null);
this.hunters = hunters;
this.hasRebuiltGuild = hasRebuiltGuild;
}

public boolean hasSignedContract() {
return signedContract;
}
Expand Down Expand Up @@ -80,6 +80,7 @@ public int getWorthiness() {
}

public void setWorthiness(int worthiness) {
if (!hasSignedContract()) return;
this.worthiness = worthiness;
}

Expand Down

0 comments on commit 248f1f0

Please sign in to comment.