- Update min. Towny to 0.97.0.0 and remove NotRegisteredException

catches.
This commit is contained in:
Llm Dl committed 2021-05-10 16:40:32 -05:00
1 parent cb2f8da9c3
commit ce03d1dd5c
5 files changed
+76 -97

No files matched your search

+2 -2
View File
@@ -7,7 +7,7 @@
<groupId>com.palmergames.bukkit</groupId>
<artifactId>TownyChat</artifactId>
<packaging>jar</packaging>
<version>0.88</version>
<version>0.89</version>
<licenses>
<license>
@@ -74,7 +74,7 @@
<dependency>
<groupId>com.github.TownyAdvanced</groupId>
<artifactId>Towny</artifactId>
<version>0.96.7.0</version>
<version>0.97.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
+3 -1
View File
@@ -374,4 +374,6 @@ v0.87:
v0.88:
- Fix players who've just recently joined a town/nation/alliance not being included in the town/nation/alliance chats.
- Fix spam_time settings not working.
- Fix hex color codes not being parsed in TownyChat spy messages.
- Fix hex color codes not being parsed in TownyChat spy messages.
v0.89:
- Update min. Towny to 0.97.0.0 and remove NotRegisteredException catches.
@@ -45,7 +45,7 @@ public class Chat extends JavaPlugin {
private Towny towny = null;
private DynmapAPI dynMap = null;
private static Version requiredTownyVersion = Version.fromString("0.96.5.5");
private static Version requiredTownyVersion = Version.fromString("0.97.0.0");
public static boolean usingPlaceholderAPI = false;
boolean chatConfigError = false;
boolean channelsConfigError = false;
@@ -4,8 +4,8 @@ import com.palmergames.bukkit.TownyChat.config.ChatSettings;
import com.palmergames.bukkit.TownyChat.listener.LocalTownyChatEvent;
import com.palmergames.bukkit.TownyChat.util.StringReplaceManager;
import com.palmergames.bukkit.towny.Towny;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.TownySettings;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Government;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Resident;
@@ -237,89 +237,82 @@ public class TownyChatFormatter {
* @return string containing the correctly formatted nation/town data
*/
public static String formatTownyTag(Resident resident, Boolean override, Boolean full) {
try {
if (resident.hasTown()) {
Town town = resident.getTown();
String townTag = getTag(town);
Nation nation = null;
String nationTag = null;
if (resident.hasNation()) {
nation = town.getNation();
nationTag = getTag(nation);
}
String nTag = "", tTag = "";
//Force use of full names only
if (full) {
nationTag = "";
townTag = "";
}
// Load town tags/names
if (townTag != null && !townTag.isEmpty())
tTag = townTag;
else if (override || full)
tTag = getName(town);
// Load the nation tags/names
if ((nationTag != null) && !nationTag.isEmpty())
nTag = nationTag;
else if (resident.hasNation() && (override || full))
nTag = getName(nation);
// Output depending on what tags are present
if ((!tTag.isEmpty()) && (!nTag.isEmpty())) {
if (ChatSettings.getBothTags().contains("%t") || ChatSettings.getBothTags().contains("%n")) {
// Then it contains %s & %s
// Small suttle change so that an issue is solved, it is documented in the config.
// But only after addition of this. (v0.50)
return ChatSettings.getBothTags().replace("%t", tTag).replace("%n", nTag);
} else {
return String.format(ChatSettings.getBothTags(), nTag, tTag);
}
}
if (!nTag.isEmpty()) {
return String.format(ChatSettings.getNationTag(), nTag);
}
if (!tTag.isEmpty()) {
return String.format(ChatSettings.getTownTag(), tTag);
}
if (resident.hasTown()) {
Town town = TownyAPI.getInstance().getResidentTownOrNull(resident);
String townTag = getTag(town);
Nation nation = null;
String nationTag = null;
if (resident.hasNation()) {
nation = TownyAPI.getInstance().getResidentNationOrNull(resident);
nationTag = getTag(nation);
}
} catch (NotRegisteredException e) {
// no town or nation
String nTag = "", tTag = "";
//Force use of full names only
if (full) {
nationTag = "";
townTag = "";
}
// Load town tags/names
if (townTag != null && !townTag.isEmpty())
tTag = townTag;
else if (override || full)
tTag = getName(town);
// Load the nation tags/names
if ((nationTag != null) && !nationTag.isEmpty())
nTag = nationTag;
else if (resident.hasNation() && (override || full))
nTag = getName(nation);
// Output depending on what tags are present
if ((!tTag.isEmpty()) && (!nTag.isEmpty())) {
if (ChatSettings.getBothTags().contains("%t") || ChatSettings.getBothTags().contains("%n")) {
// Then it contains %s & %s
// Small suttle change so that an issue is solved, it is documented in the config.
// But only after addition of this. (v0.50)
return ChatSettings.getBothTags().replace("%t", tTag).replace("%n", nTag);
} else {
return String.format(ChatSettings.getBothTags(), nTag, tTag);
}
}
if (!nTag.isEmpty()) {
return String.format(ChatSettings.getNationTag(), nTag);
}
if (!tTag.isEmpty()) {
return String.format(ChatSettings.getTownTag(), tTag);
}
}
return "";
}
public static String formatTownTag(Resident resident, Boolean override, Boolean full) {
try {
if (resident.hasTown())
if (full)
return hexIfCompatible(String.format(ChatSettings.getTownTag(), getName(resident.getTown())));
else if (resident.getTown().hasTag())
return hexIfCompatible(String.format(ChatSettings.getTownTag(), getTag(resident.getTown())));
else if (override)
return hexIfCompatible(String.format(ChatSettings.getTownTag(), getName(resident.getTown())));
if (resident.hasTown()) {
Town town = TownyAPI.getInstance().getResidentTownOrNull(resident);
if (full)
return hexIfCompatible(String.format(ChatSettings.getTownTag(), getName(town)));
else if (town.hasTag())
return hexIfCompatible(String.format(ChatSettings.getTownTag(), getTag(town)));
else if (override)
return hexIfCompatible(String.format(ChatSettings.getTownTag(), getName(town)));
} catch (NotRegisteredException e) {
}
return "";
}
public static String formatNationTag(Resident resident, Boolean override, Boolean full) {
try {
if (resident.hasNation())
if (full)
return hexIfCompatible(String.format(ChatSettings.getNationTag(), getName(resident.getTown().getNation())));
else if (resident.getTown().getNation().hasTag())
return hexIfCompatible(String.format(ChatSettings.getNationTag(), getTag(resident.getTown().getNation())));
else if (override)
return hexIfCompatible(String.format(ChatSettings.getNationTag(), getName(resident.getTown().getNation())));
} catch (NotRegisteredException e) {
if (resident.hasNation()) {
Nation nation = TownyAPI.getInstance().getResidentNationOrNull(resident);
if (full)
return hexIfCompatible(String.format(ChatSettings.getNationTag(), getName(nation)));
else if (nation.hasTag())
return hexIfCompatible(String.format(ChatSettings.getNationTag(), getTag(nation)));
else if (override)
return hexIfCompatible(String.format(ChatSettings.getNationTag(), getName(nation)));
}
return "";
}
@@ -11,7 +11,6 @@ import com.palmergames.bukkit.TownyChat.listener.LocalTownyChatEvent;
import com.palmergames.bukkit.towny.Towny;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.TownyMessaging;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.exceptions.TownyException;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Resident;
@@ -54,18 +53,8 @@ public class StandardChannel extends Channel {
Resident resident = TownyUniverse.getInstance().getResident(player.getUniqueId());
if (resident == null)
return;
// TODO: When 0.97.0.0 is released, replace 61-68 with:
// Town town = TownyAPI.getInstance().getResidentTownOrNull(resident);
// Nation nation = TownyAPI.getInstance().getResidentNationOrNull(resident);
Town town = null;
Nation nation = null;
try {
town = resident.getTown();
nation = resident.getTown().getNation();
} catch (NotRegisteredException e1) {
// Not in a town/nation (doesn't matter which)
}
Town town = TownyAPI.getInstance().getResidentTownOrNull(resident);
Nation nation = TownyAPI.getInstance().getResidentNationOrNull(resident);
// If player sends a message to a channel it had left
// tell the channel to add the player back
@@ -345,14 +334,9 @@ public class StandardChannel extends Channel {
Resident resident = TownyUniverse.getInstance().getResident(player.getUniqueId());
if (resident == null)
return null;
Town town = null;
Nation nation = null;
try {
town = resident.getTown();
nation = resident.getTown().getNation();
} catch (NotRegisteredException e1) {
// Not in a town/nation (doesn't matter which)
}
Town town = TownyAPI.getInstance().getResidentTownOrNull(resident);
Nation nation = TownyAPI.getInstance().getResidentNationOrNull(resident);
String format = ChatColor.translateAlternateColorCodes('&', getChannelTag());
if (Towny.is116Plus())
format = HexFormatter.translateHexColors(format);