Skip to content

Commit

Permalink
Merge pull request #1383 from Dans-Plugins/locale-utility
Browse files Browse the repository at this point in the history
Locale Utility - Simplified Referencing Method
  • Loading branch information
dmccoystephenson authored Mar 7, 2022
2 parents b96f76c + badc059 commit 6bb2d0e
Show file tree
Hide file tree
Showing 21 changed files with 165 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import dansplugins.factionsystem.events.FactionWarEndEvent;
import dansplugins.factionsystem.objects.domain.Faction;
import dansplugins.factionsystem.objects.domain.PowerRecord;
import dansplugins.factionsystem.services.LocalLocaleService;
import dansplugins.factionsystem.utils.Locale;
import dansplugins.factionsystem.utils.Logger;
import dansplugins.fiefs.utils.UUIDChecker;
import preponderous.ponder.misc.ArgumentParser;
Expand Down Expand Up @@ -116,7 +116,7 @@ private void forceLoad(CommandSender sender) {
if (!(checkPermissions(sender, "mf.force.load", "mf.force.*", "mf.admin"))) {
return;
}
sender.sendMessage(translate("&a" + LocalLocaleService.getInstance().getText("AlertForcedLoad")));
sender.sendMessage(translate("&a" + Locale.get("AlertForcedLoad")));
PersistentData.getInstance().getLocalStorageService().load();
MedievalFactions.getInstance().reloadConfig();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import dansplugins.factionsystem.MedievalFactions;
import dansplugins.factionsystem.commands.abs.SubCommand;
import dansplugins.factionsystem.services.LocalLocaleService;
import dansplugins.factionsystem.utils.Locale;
import preponderous.ponder.minecraft.bukkit.tools.UUIDChecker;

/**
Expand Down Expand Up @@ -71,7 +71,7 @@ public void execute(Player player, String[] args, String key) {
return;
}
faction.invite(playerUUID);
player.sendMessage(ChatColor.GREEN + LocalLocaleService.getInstance().getText("InvitationSent"));
player.sendMessage(ChatColor.GREEN + Locale.get("InvitationSent"));
if (target.isOnline() && target.getPlayer() != null) {
target.getPlayer().sendMessage(translate(
"&a" + getText("AlertBeenInvited", faction.getName(), faction.getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import dansplugins.factionsystem.commands.abs.SubCommand;
import dansplugins.factionsystem.data.PersistentData;
import dansplugins.factionsystem.objects.domain.Faction;
import dansplugins.factionsystem.services.LocalLocaleService;
import dansplugins.factionsystem.utils.Locale;

/**
* @author Callum Johnson
Expand Down Expand Up @@ -55,7 +55,7 @@ public void execute(CommandSender sender, String[] args, String key) {
}
sender.sendMessage(translate("&b&l" + getText("FactionsTitle")));
List<PersistentData.SortableFaction> sortedFactionList = PersistentData.getInstance().getSortedListOfFactions();
sender.sendMessage(ChatColor.AQUA + LocalLocaleService.getInstance().getText("ListLegend"));
sender.sendMessage(ChatColor.AQUA + Locale.get("ListLegend"));
sender.sendMessage(ChatColor.AQUA + "-----");
for (PersistentData.SortableFaction sortableFaction : sortedFactionList) {
final Faction temp = sortableFaction.getFaction();
Expand Down
43 changes: 24 additions & 19 deletions src/main/java/dansplugins/factionsystem/data/PersistentData.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import dansplugins.factionsystem.services.LocalConfigService;
import dansplugins.factionsystem.services.LocalLocaleService;
import dansplugins.factionsystem.utils.InteractionAccessChecker;
import dansplugins.factionsystem.utils.Locale;
import dansplugins.factionsystem.utils.Logger;
import dansplugins.factionsystem.utils.extended.BlockChecker;
import dansplugins.factionsystem.utils.extended.Messenger;
Expand Down Expand Up @@ -436,7 +437,7 @@ public boolean isBlockInGate(Block block, Player player) {
for (Faction faction : factions) {
for (Gate gate : faction.getGates()) {
if (gate.hasBlock(block)) {
player.sendMessage(ChatColor.RED + String.format(LocalLocaleService.getInstance().getText("BlockIsPartOfGateMustRemoveGate"), gate.getName()));
player.sendMessage(ChatColor.RED + String.format(Locale.get("BlockIsPartOfGateMustRemoveGate"), gate.getName()));
return true;
}
}
Expand Down Expand Up @@ -466,7 +467,7 @@ public void initiatePowerIncreaseForAllPlayers() {
private void initiatePowerIncrease(PowerRecord powerRecord) {
if (powerRecord.getPower() < powerRecord.maxPower() && Objects.requireNonNull(getServer().getPlayer(powerRecord.getPlayerUUID())).isOnline()) {
powerRecord.increasePower();
Objects.requireNonNull(getServer().getPlayer(powerRecord.getPlayerUUID())).sendMessage(ChatColor.GREEN + String.format(LocalLocaleService.getInstance().getText("AlertPowerLevelIncreasedBy"), MedievalFactions.getInstance().getConfig().getInt("powerIncreaseAmount")));
Objects.requireNonNull(getServer().getPlayer(powerRecord.getPlayerUUID())).sendMessage(ChatColor.GREEN + String.format(Locale.get("AlertPowerLevelIncreasedBy"), MedievalFactions.getInstance().getConfig().getInt("powerIncreaseAmount")));
}
}

Expand All @@ -479,9 +480,9 @@ public void disbandAllZeroPowerFactions() {
}

for (String factionName : factionsToDisband) {
Messenger.getInstance().sendAllPlayersInFactionMessage(PersistentData.getInstance().getFaction(factionName), ChatColor.RED + LocalLocaleService.getInstance().getText("AlertDisbandmentDueToZeroPower"));
Messenger.getInstance().sendAllPlayersInFactionMessage(PersistentData.getInstance().getFaction(factionName), ChatColor.RED + Locale.get("AlertDisbandmentDueToZeroPower"));
removeFaction(factionName);
System.out.printf((LocalLocaleService.getInstance().getText("DisbandmentDueToZeroPower")) + "%n", factionName);
System.out.printf((Locale.get("DisbandmentDueToZeroPower")) + "%n", factionName);
}
}

Expand Down Expand Up @@ -630,7 +631,7 @@ public void radiusClaimAtLocation(int depth, Player claimant, Location location,

// check if depth is valid
if (depth < 0 || depth > maxClaimRadius) {
claimant.sendMessage(ChatColor.RED + String.format(LocalLocaleService.getInstance().getText("RadiusRequirement"), maxClaimRadius));
claimant.sendMessage(ChatColor.RED + String.format(Locale.get("RadiusRequirement"), maxClaimRadius));
return;
}

Expand Down Expand Up @@ -702,10 +703,10 @@ public void removeChunkAtPlayerLocation(Player player, Faction playersFaction) {
ClaimedChunk chunk = isChunkClaimed(playerCoords[0], playerCoords[1], Objects.requireNonNull(player.getLocation().getWorld()).getName());
if (chunk != null) {
removeChunk(chunk, player, PersistentData.getInstance().getFaction(chunk.getHolder()));
player.sendMessage(ChatColor.GREEN + LocalLocaleService.getInstance().getText("LandClaimedUsingAdminBypass"));
player.sendMessage(ChatColor.GREEN + Locale.get("LandClaimedUsingAdminBypass"));
return;
}
player.sendMessage(ChatColor.RED + LocalLocaleService.getInstance().getText("LandNotCurrentlyClaimed"));
player.sendMessage(ChatColor.RED + Locale.get("LandNotCurrentlyClaimed"));
return;
}

Expand All @@ -718,13 +719,13 @@ public void removeChunkAtPlayerLocation(Player player, Faction playersFaction) {

// ensure that the chunk is claimed by the player's faction.
if (!chunk.getHolder().equalsIgnoreCase(playersFaction.getName())) {
player.sendMessage(ChatColor.RED + String.format(LocalLocaleService.getInstance().getText("LandClaimedBy"), chunk.getHolder()));
player.sendMessage(ChatColor.RED + String.format(Locale.get("LandClaimedBy"), chunk.getHolder()));
return;
}

// initiate removal
removeChunk(chunk, player, playersFaction);
player.sendMessage(ChatColor.GREEN + LocalLocaleService.getInstance().getText("LandUnclaimed"));
player.sendMessage(ChatColor.GREEN + Locale.get("LandUnclaimed"));
}

/**
Expand Down Expand Up @@ -801,7 +802,7 @@ public void removeAllClaimedChunks(String factionName) {
try {
itr.remove();
} catch (Exception e) {
System.out.println(LocalLocaleService.getInstance().getText("ErrorClaimedChunkRemoval"));
System.out.println(Locale.get("ErrorClaimedChunkRemoval"));
}
}
}
Expand All @@ -826,7 +827,7 @@ public void informPlayerIfTheirLandIsInDanger(Player player) {
Faction faction = PersistentData.getInstance().getPlayersFaction(player.getUniqueId());
if (faction != null) {
if (isFactionExceedingTheirDemesneLimit(faction)) {
player.sendMessage(ChatColor.RED + LocalLocaleService.getInstance().getText("AlertMoreClaimedChunksThanPower"));
player.sendMessage(ChatColor.RED + Locale.get("AlertMoreClaimedChunksThanPower"));
}
}
}
Expand Down Expand Up @@ -944,7 +945,7 @@ private void claimChunkAtLocation(Player claimant, double[] chunkCoords, World w
if (LocalConfigService.getInstance().getBoolean("limitLand")) {
// if at demesne limit
if (!(getChunksClaimedByFaction(claimantsFaction.getName()) < claimantsFaction.getCumulativePowerLevel())) {
claimant.sendMessage(ChatColor.RED + LocalLocaleService.getInstance().getText("AlertReachedDemesne"));
claimant.sendMessage(ChatColor.RED + Locale.get("AlertReachedDemesne"));
return;
}
}
Expand All @@ -957,7 +958,7 @@ private void claimChunkAtLocation(Player claimant, double[] chunkCoords, World w

// if holder is player's faction
if (targetFaction.getName().equalsIgnoreCase(claimantsFaction.getName()) && !claimantsFaction.getAutoClaimStatus()) {
claimant.sendMessage(ChatColor.RED + LocalLocaleService.getInstance().getText("LandAlreadyClaimedByYourFaction"));
claimant.sendMessage(ChatColor.RED + Locale.get("LandAlreadyClaimedByYourFaction"));
return;
}

Expand All @@ -970,7 +971,7 @@ private void claimChunkAtLocation(Player claimant, double[] chunkCoords, World w
// surrounded chunk protection check
if (MedievalFactions.getInstance().getConfig().getBoolean("surroundedChunksProtected")) {
if (isClaimedChunkSurroundedByChunksClaimedBySameFaction(chunk)) {
claimant.sendMessage(ChatColor.RED + LocalLocaleService.getInstance().getText("SurroundedChunkProtected"));
claimant.sendMessage(ChatColor.RED + Locale.get("SurroundedChunkProtected"));
return;
}
}
Expand All @@ -980,7 +981,7 @@ private void claimChunkAtLocation(Player claimant, double[] chunkCoords, World w

// if target faction does not have more land than their demesne limit
if (!(targetFactionsCumulativePowerLevel < chunksClaimedByTargetFaction)) {
claimant.sendMessage(ChatColor.RED + LocalLocaleService.getInstance().getText("TargetFactionNotOverClaiming"));
claimant.sendMessage(ChatColor.RED + Locale.get("TargetFactionNotOverClaiming"));
return;
}

Expand All @@ -997,9 +998,9 @@ private void claimChunkAtLocation(Player claimant, double[] chunkCoords, World w

Chunk toClaim = world.getChunkAt((int) chunkCoords[0], (int) chunkCoords[1]);
addClaimedChunk(toClaim, claimantsFaction, claimant.getWorld());
claimant.sendMessage(ChatColor.GREEN + String.format(LocalLocaleService.getInstance().getText("AlertLandConqueredFromAnotherFaction"), targetFaction.getName(), getChunksClaimedByFaction(claimantsFaction.getName()), claimantsFaction.getCumulativePowerLevel()));
claimant.sendMessage(ChatColor.GREEN + String.format(Locale.get("AlertLandConqueredFromAnotherFaction"), targetFaction.getName(), getChunksClaimedByFaction(claimantsFaction.getName()), claimantsFaction.getCumulativePowerLevel()));

Messenger.getInstance().sendAllPlayersInFactionMessage(targetFaction, ChatColor.RED + String.format(LocalLocaleService.getInstance().getText("AlertLandConqueredFromYourFaction"), claimantsFaction.getName()));
Messenger.getInstance().sendAllPlayersInFactionMessage(targetFaction, ChatColor.RED + String.format(Locale.get("AlertLandConqueredFromYourFaction"), claimantsFaction.getName()));
}
} else {
Chunk toClaim = world.getChunkAt((int) chunkCoords[0], (int) chunkCoords[1]);
Expand All @@ -1008,7 +1009,7 @@ private void claimChunkAtLocation(Player claimant, double[] chunkCoords, World w
if (!claimEvent.isCancelled()) {
// chunk not already claimed
addClaimedChunk(toClaim, claimantsFaction, claimant.getWorld());
claimant.sendMessage(ChatColor.GREEN + String.format(LocalLocaleService.getInstance().getText("AlertLandClaimed"), getChunksClaimedByFaction(claimantsFaction.getName()), claimantsFaction.getCumulativePowerLevel()));
claimant.sendMessage(ChatColor.GREEN + String.format(Locale.get("AlertLandClaimed"), getChunksClaimedByFaction(claimantsFaction.getName()), claimantsFaction.getCumulativePowerLevel()));
}
}
}
Expand Down Expand Up @@ -1102,7 +1103,7 @@ private void removeChunk(ClaimedChunk chunkToRemove, Player unclaimingPlayer, Fa
&& chunkToRemove.getWorldName().equalsIgnoreCase(Objects.requireNonNull(unclaimingPlayer.getLocation().getWorld()).getName())) {
// remove faction home
holdingFaction.setFactionHome(null);
Messenger.getInstance().sendAllPlayersInFactionMessage(holdingFaction, ChatColor.RED + LocalLocaleService.getInstance().getText("AlertFactionHomeRemoved"));
Messenger.getInstance().sendAllPlayersInFactionMessage(holdingFaction, ChatColor.RED + Locale.get("AlertFactionHomeRemoved"));

}
}
Expand Down Expand Up @@ -1232,6 +1233,8 @@ private boolean canBlockBeInteractedWith(PlayerInteractEvent event) {
case STONE_BUTTON:
case LECTERN:
return false;
default:
break;
}
}
return true;
Expand Down Expand Up @@ -1278,6 +1281,8 @@ private boolean materialAllowed(Material material) {
case CHORUS_FRUIT:
case DRIED_KELP:
case BAKED_POTATO:
default:
break;
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import dansplugins.factionsystem.objects.domain.ClaimedChunk;
import dansplugins.factionsystem.objects.domain.Duel;
import dansplugins.factionsystem.objects.domain.Faction;
import dansplugins.factionsystem.services.LocalLocaleService;
import dansplugins.factionsystem.utils.Locale;
import dansplugins.factionsystem.utils.Logger;

/**
Expand Down Expand Up @@ -194,14 +194,14 @@ private void handleFriendlyFire(EntityDamageByEntityEvent event, Player attacker
boolean friendlyFireAllowed = (boolean) faction.getFlags().getFlag("allowFriendlyFire");
if (!friendlyFireAllowed) {
event.setCancelled(true);
attacker.sendMessage(ChatColor.RED + LocalLocaleService.getInstance().getText("CannotAttackFactionMember"));
attacker.sendMessage(ChatColor.RED + Locale.get("CannotAttackFactionMember"));
}
}

private void handleNonEnemyFire(EntityDamageByEntityEvent event, Player attacker, Player victim) {
if (MedievalFactions.getInstance().getConfig().getBoolean("warsRequiredForPVP")) {
event.setCancelled(true);
attacker.sendMessage(ChatColor.RED + LocalLocaleService.getInstance().getText("CannotAttackNonWarringPlayer"));
attacker.sendMessage(ChatColor.RED + Locale.get("CannotAttackNonWarringPlayer"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import dansplugins.factionsystem.data.PersistentData;
import dansplugins.factionsystem.objects.domain.PowerRecord;
import dansplugins.factionsystem.services.LocalConfigService;
import dansplugins.factionsystem.services.LocalLocaleService;
import dansplugins.factionsystem.utils.Locale;

public class DeathHandler implements Listener {

Expand All @@ -32,7 +32,7 @@ public void handle(PlayerDeathEvent event) {
return;
}
record.grantPowerDueToKill();
killer.sendMessage(ChatColor.GREEN + LocalLocaleService.getInstance().getText("PowerLevelHasIncreased"));
killer.sendMessage(ChatColor.GREEN + Locale.get("PowerLevelHasIncreased"));
}

private boolean wasPlayersCauseOfDeathAnotherPlayerKillingThem(Player player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
import dansplugins.factionsystem.objects.domain.ClaimedChunk;
import dansplugins.factionsystem.objects.domain.LockedBlock;
import dansplugins.factionsystem.services.LocalGateService;
import dansplugins.factionsystem.services.LocalLocaleService;
import dansplugins.factionsystem.services.LocalLockService;
import dansplugins.factionsystem.utils.InteractionAccessChecker;
import dansplugins.factionsystem.utils.Locale;
import dansplugins.factionsystem.utils.extended.BlockChecker;
import preponderous.ponder.minecraft.bukkit.tools.UUIDChecker;

Expand Down Expand Up @@ -69,7 +69,7 @@ public void handle(BlockBreakEvent event) {
boolean isOwner = PersistentData.getInstance().getLockedBlock(block).getOwner().equals(player.getUniqueId());
if (!isOwner) {
event.setCancelled(true);
player.sendMessage(ChatColor.RED + LocalLocaleService.getInstance().getText("AlertNonOwnership"));
player.sendMessage(ChatColor.RED + Locale.get("AlertNonOwnership"));
return;
}

Expand Down Expand Up @@ -111,7 +111,7 @@ public void handle(BlockPlaceEvent event) {
if (BlockChecker.getInstance().isChest(event.getBlock())) {
boolean isNextToNonOwnedLockedChest = BlockChecker.getInstance().isNextToNonOwnedLockedChest(event.getPlayer(), event.getBlock());
if (isNextToNonOwnedLockedChest) {
player.sendMessage(ChatColor.RED + LocalLocaleService.getInstance().getText("CannotPlaceChestsNextToUnownedLockedChests"));
player.sendMessage(ChatColor.RED + Locale.get("CannotPlaceChestsNextToUnownedLockedChests"));
event.setCancelled(true);
return;
}
Expand Down Expand Up @@ -154,7 +154,7 @@ public void handle(BlockPlaceEvent event) {
boolean isUnderOrAboveNonOwnedLockedChest = BlockChecker.getInstance().isUnderOrAboveNonOwnedLockedChest(event.getPlayer(), event.getBlock());
if (isNextToNonOwnedLockedChest || isUnderOrAboveNonOwnedLockedChest) {
event.setCancelled(true);
player.sendMessage(ChatColor.RED + LocalLocaleService.getInstance().getText("CannotPlaceHoppersNextToUnownedLockedChests"));
player.sendMessage(ChatColor.RED + Locale.get("CannotPlaceHoppersNextToUnownedLockedChests"));
}
}
}
Expand Down Expand Up @@ -183,7 +183,7 @@ public void handle(PlayerInteractEvent event) {
if (!playerHasAccess && !isPlayerBypassing) {
UUIDChecker uuidChecker = new UUIDChecker();
String owner = uuidChecker.findPlayerNameBasedOnUUID(lockedBlock.getOwner());
player.sendMessage(ChatColor.RED + String.format(LocalLocaleService.getInstance().getText("LockedBy"), owner));
player.sendMessage(ChatColor.RED + String.format(Locale.get("LockedBy"), owner));
event.setCancelled(true);
return;
}
Expand Down Expand Up @@ -211,7 +211,7 @@ public void handle(PlayerInteractEvent event) {

} else {
if (isPlayerUsingAnAccessCommand(player)) {
player.sendMessage(ChatColor.RED + LocalLocaleService.getInstance().getText("BlockIsNotLocked"));
player.sendMessage(ChatColor.RED + Locale.get("BlockIsNotLocked"));
}
}

Expand Down
Loading

0 comments on commit 6bb2d0e

Please sign in to comment.