From 786d6be217a913a87df1b384615962483b57cf1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?SvenjaRei=C3=9Faus?= Date: Tue, 19 Mar 2019 09:56:49 -0500 Subject: [PATCH] Added some translation for more frecuent messages. Fixes #124 --- .../massivecraft/factions/cmd/FCommand.java | 20 +++++++++---------- .../listeners/FactionsBlockListener.java | 14 ++++++------- .../listeners/FactionsPlayerListener.java | 14 +++++++------ .../massivecraft/factions/zcore/util/TL.java | 11 +++++++++- src/main/resources/lang/en_US.yml | 8 ++++++++ 5 files changed, 43 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/cmd/FCommand.java b/src/main/java/com/massivecraft/factions/cmd/FCommand.java index 03aab442..722fa40c 100644 --- a/src/main/java/com/massivecraft/factions/cmd/FCommand.java +++ b/src/main/java/com/massivecraft/factions/cmd/FCommand.java @@ -99,7 +99,7 @@ public abstract class FCommand extends MCommand { if (!fme.hasFaction()) { if (informSenderIfNot) { - sender.sendMessage(p.txt.parse("You are not member of any faction.")); + sender.sendMessage(p.txt.parse(TL.ACTIONS_NOFACTION.toString())); } return false; } @@ -107,21 +107,21 @@ public abstract class FCommand extends MCommand { if (this.senderMustBeModerator && !fme.getRole().isAtLeast(Role.MODERATOR)) { if (informSenderIfNot) { - sender.sendMessage(p.txt.parse("Only faction moderators can %s.", this.getHelpShort())); + sender.sendMessage(p.txt.parse(TL.ACTIONS_MUSTBE.toString().replace("{role}", "moderator").replace("{action}", this.getHelpShort()))); } return false; } if (this.senderMustBeColeader && !fme.getRole().isAtLeast(Role.COLEADER)) { if (informSenderIfNot) { - sender.sendMessage(p.txt.parse("Only faction coleaders can %s.", this.getHelpShort())); + sender.sendMessage(p.txt.parse(TL.ACTIONS_MUSTBE.toString().replace("{role}", "coleader").replace("{action}", this.getHelpShort()))); } return false; } if (this.senderMustBeAdmin && !fme.getRole().isAtLeast(Role.LEADER)) { if (informSenderIfNot) { - sender.sendMessage(p.txt.parse("Only faction admins can %s.", this.getHelpShort())); + sender.sendMessage(p.txt.parse(TL.ACTIONS_MUSTBE.toString().replace("{role}", "admin").replace("{action}", this.getHelpShort()))); } return false; } @@ -140,7 +140,7 @@ public abstract class FCommand extends MCommand { } if (!fme.hasFaction()) { - sendMessage("You are not member of any faction."); + msg(TL.ACTIONS_NOFACTION); return false; } return true; @@ -152,7 +152,7 @@ public abstract class FCommand extends MCommand { } if (fme.getRole().value < role.value) { - msg("You must be " + role + " to " + this.getHelpShort() + "."); + msg(TL.ACTIONS_MUSTBE.toString().replace("{role}", role.nicename).replace("{action}", this.getHelpShort())); return false; } return true; @@ -282,23 +282,23 @@ public abstract class FCommand extends MCommand { } if (you.getRole().equals(Role.LEADER)) { - i.sendMessage(p.txt.parse("Only the faction admin can do that.")); + i.sendMessage(p.txt.parse(TL.ACTIONS_MUSTBE.toString().replace("{role}", "leader").replace("{action}", "do that"))); } else if ((you.getRole().equals(Role.COLEADER))) { if (i == you) { return true; } else { - i.sendMessage(p.txt.parse("Coleaders can't control each other...")); + i.sendMessage(p.txt.parse(TL.ACTIONS_NOSAMEROLE.toString().replace("{role}", i.getRole().nicename))); } } else if (i.getRole().equals(Role.MODERATOR)) { if (i == you) { return true; //Moderators can control themselves } else { - i.sendMessage(p.txt.parse("Moderators can't control each other...")); + i.sendMessage(p.txt.parse(TL.ACTIONS_NOSAMEROLE.toString().replace("{role}", i.getRole().nicename))); } } else { - i.sendMessage(p.txt.parse("You must be a faction moderator to do that.")); + i.sendMessage(p.txt.parse(TL.ACTIONS_MUSTBE.toString().replace("{role}", "moderator").replace("{action}", "do that"))); } return false; diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java index 884b3c8e..0ad77dc0 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java @@ -487,31 +487,31 @@ public class FactionsBlockListener implements Listener { boolean landOwned = (myFaction.doesLocationHaveOwnersSet(loc) && !myFaction.getOwnerList(loc).isEmpty()); if ((landOwned && myFaction.getOwnerListString(loc).contains(player.getName())) || (me.getRole() == Role.LEADER && me.getFactionId().equals(myFaction.getId()))) return true; else if (landOwned && !myFaction.getOwnerListString(loc).contains(player.getName())) { - me.msg("You can't " + action + " in this territory, it is owned by: " + myFaction.getOwnerListString(loc)); + me.msg(TL.ACTIONS_OWNEDTERRITORYDENY.toString().replace("{owners}", myFaction.getOwnerListString(loc))); if (shouldHurt) { player.damage(Conf.actionDeniedPainAmount); - me.msg("It is painful to try to " + action + " in the territory of " + Board.getInstance().getFactionAt(loc).getTag(myFaction)); + me.msg(TL.ACTIONS_NOPERMISSIONPAIN.toString().replace("{action}", action.toString()).replace("{faction}", Board.getInstance().getFactionAt(loc).getTag(myFaction))); } return false; } else if (!landOwned && access == Access.DENY) { // If land is not owned but access is set to DENY anyway if (shouldHurt) { player.damage(Conf.actionDeniedPainAmount); - me.msg("It is painful to try to " + action + " in the territory of " + Board.getInstance().getFactionAt(loc).getTag(myFaction)); + me.msg(TL.ACTIONS_NOPERMISSIONPAIN.toString().replace("{action}", action.toString()).replace("{faction}", Board.getInstance().getFactionAt(loc).getTag(myFaction))); } - me.msg("You cannot " + action + " in the territory of " + myFaction.getTag(me.getFaction())); + me.msg(TL.ACTIONS_NOPERMISSION.toString().replace("{faction}", myFaction.getTag(me.getFaction())).replace("{action}", action.toString())); return false; } else if (access == Access.ALLOW) return true; - me.msg("You cannot " + action + " in the territory of " + myFaction.getTag(me.getFaction())); + me.msg(TL.ACTIONS_NOPERMISSION.toString().replace("{faction}", myFaction.getTag(me.getFaction())).replace("{action}", action.toString())); return false; } private static boolean CheckActionState(Faction target, FLocation location, FPlayer me, PermissableAction action, boolean pain) { if (Conf.ownedAreasEnabled && target.doesLocationHaveOwnersSet(location) && !target.playerHasOwnershipRights(me, location)) { // If pain should be applied - if (pain && Conf.ownedAreaPainBuild) me.msg("It is painful to try to " + action + " in this territory, it is owned by: " + target.getOwnerListString(location)); + if (pain && Conf.ownedAreaPainBuild) me.msg(TL.ACTIONS_OWNEDTERRITORYPAINDENY.toString().replace("{action}", action.toString()).replace("{faction}", target.getOwnerListString(location))); if (Conf.ownedAreaDenyBuild && pain) return false; else if (Conf.ownedAreaDenyBuild) { - me.msg("You cannot " + action + " in the territory of " + target.getTag(me.getFaction())); + me.msg(TL.ACTIONS_NOPERMISSION.toString().replace("{faction}", target.getTag(me.getFaction())).replace("{action}", action.toString())); return false; } } diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java index df6b2f33..916f99af 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -40,7 +40,6 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryDragEvent; import org.bukkit.event.player.*; -import org.bukkit.util.NumberConversions; import java.util.*; import java.util.logging.Level; @@ -88,7 +87,7 @@ public class FactionsPlayerListener implements Listener { // Also cancel if player doesn't have ownership rights for this claim if (Conf.ownedAreasEnabled && myFaction == otherFaction && !myFaction.playerHasOwnershipRights(me, loc)) { if (!justCheck) { - me.msg("You can't use that in this territory, it is owned by: " + otherFaction.getOwnerListString(loc)); + me.msg(TL.ACTIONS_OWNEDTERRITORYDENY.toString().replace("{owners}", myFaction.getOwnerListString(loc))); } return false; } @@ -773,7 +772,7 @@ public class FactionsPlayerListener implements Listener { Faction otherFaction = Board.getInstance().getFactionAt(new FLocation(block.getLocation())); Faction myFaction = me.getFaction(); - me.msg("You can't use bone meal in the territory of " + otherFaction.getTag(myFaction)); + me.msg(TL.ACTIONS_NOPERMISSION.toString().replace("{faction}", myFaction.getTag(me.getFaction())).replace("{action}", "use bone meal")); event.setCancelled(true); } } @@ -898,18 +897,18 @@ public class FactionsPlayerListener implements Listener { boolean landOwned = (myFaction.doesLocationHaveOwnersSet(loc) && !myFaction.getOwnerList(loc).isEmpty()); if ((landOwned && myFaction.getOwnerListString(loc).contains(player.getName())) || (me.getRole() == Role.LEADER && me.getFactionId().equals(myFaction.getId()))) return true; else if (landOwned && !myFaction.getOwnerListString(loc).contains(player.getName())) { - me.msg("You can't do that in this territory, it is owned by: " + myFaction.getOwnerListString(loc)); + me.msg(TL.ACTIONS_OWNEDTERRITORYDENY.toString().replace("{owners}", myFaction.getOwnerListString(loc))); if (doPain) { player.damage(Conf.actionDeniedPainAmount); } return false; } else if (!landOwned && access == Access.ALLOW) return true; else { - me.msg("You cannot " + action + " in the territory of " + myFaction.getTag(me.getFaction())); + me.msg(TL.ACTIONS_NOPERMISSION.toString().replace("{faction}", myFaction.getTag(me.getFaction())).replace("{action}", action.toString())); return false; } } - me.msg("You cannot " + action + " in the territory of " + myFaction.getTag(me.getFaction())); + me.msg(TL.ACTIONS_NOPERMISSION.toString().replace("{faction}", myFaction.getTag(me.getFaction())).replace("{action}", action.toString())); return false; } /// @@ -918,6 +917,9 @@ public class FactionsPlayerListener implements Listener { private static PermissableAction GetPermissionFromUsableBlock(Block block) { return GetPermissionFromUsableBlock(block.getType()); } + /// + /// This will try to resolve a permission action based on the item material, if it's not usable, will return null + /// private static PermissableAction GetPermissionFromUsableBlock(Material material) { // Check for doors that might have diff material name in old version. if (material.name().contains("DOOR")) diff --git a/src/main/java/com/massivecraft/factions/zcore/util/TL.java b/src/main/java/com/massivecraft/factions/zcore/util/TL.java index 202c3e83..969a606a 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TL.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TL.java @@ -46,7 +46,16 @@ public enum TL { _LOCAL_LANGUAGE("English"), _LOCAL_REGION("US"), _LOCAL_STATE("complete"), //And this is the English version. It's not ever going to be not complete. - + /** + * Actions translations + */ + ACTIONS_NOPERMISSION("{faction} does not allow you to {action}"), + ACTIONS_NOPERMISSIONPAIN("It is painful to try to {action} in the territory of {faction}"), + ACTIONS_OWNEDTERRITORYDENY("You cant do that in this territory, it is owned by {owners}"), + ACTIONS_OWNEDTERRITORYPAINDENY("It is painful to try to {action} in this territory, it is owned by {owners}"), + ACTIONS_MUSTBE("You must be {role} to {action}."), + ACTIONS_NOSAMEROLE("{role} can't control each other..."), + ACTIONS_NOFACTION("You are not member of any faction."), /** * Command translations */ diff --git a/src/main/resources/lang/en_US.yml b/src/main/resources/lang/en_US.yml index dbdc5ed2..453534ce 100644 --- a/src/main/resources/lang/en_US.yml +++ b/src/main/resources/lang/en_US.yml @@ -476,6 +476,14 @@ COMPASS: EAST: E SOUTH: S WEST: W +ACTIONS: + NOPERMISSION: '{faction} does not allow you to {action}' + NOPERMISSIONPAINFUL: 'It is painful to try to {action} in the territory of {faction}' + OWNEDTERRITORYDENY: You cant do that in this territory, it is owned by {owners} + OWNEDTERRITORYPAINDENY: It is painful to try to {action} in this territory, it is owned by {owners} + MUSTBE: 'You must be {role} to {action}.' + NOSAMEROLE: {role} can't control each other... + NOFACTION: 'You are not member of any faction.' CHAT: FACTION: faction chat ALLIANCE: alliance chat