Merge branch 'hotfix/1.0.1'

# Conflicts:
#	src/main/java/buttondevteam/chat/components/towny/TownyComponent.java
This commit is contained in:
Norbi Peti 2023-06-07 23:37:10 +02:00
commit 2242655c41
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
5 changed files with 27 additions and 66 deletions

17
pom.xml
View file

@ -66,21 +66,6 @@
</useSystemClassLoader> <!-- https://stackoverflow.com/a/53012553/2703239 --> </useSystemClassLoader> <!-- https://stackoverflow.com/a/53012553/2703239 -->
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-testCompile</id>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>
<groupId>buttondevteam</groupId> <groupId>buttondevteam</groupId>
@ -137,7 +122,7 @@
<groupId>com.github.TownyAdvanced</groupId> <groupId>com.github.TownyAdvanced</groupId>
<artifactId>Towny</artifactId> <artifactId>Towny</artifactId>
<!-- <version>8d3b6b6</version> ButtonCore repo --> <!-- <version>8d3b6b6</version> ButtonCore repo -->
<version>0.96.2.0</version> <version>0.98.6.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- <dependency> <groupId>au.com.mineauz</groupId> <artifactId>Minigames</artifactId> <!-- <dependency> <groupId>au.com.mineauz</groupId> <artifactId>Minigames</artifactId>

View file

@ -84,9 +84,9 @@ public class TownColorComponent extends Component<PluginMain> implements Listene
loadNC.accept(ncs); loadNC.accept(ncs);
} }
TownColors.keySet().removeIf(t -> !TownyComponent.dataSource.hasTown(t)); // Removes town colors for deleted/renamed towns TownColors.keySet().removeIf(t -> TownyComponent.dataSource.getTown(t) == null); // Removes town colors for deleted/renamed towns
if (usenc) if (usenc)
NationColor.keySet().removeIf(n -> !TownyComponent.dataSource.hasNation(n)); // Removes nation colors for deleted/renamed nations NationColor.keySet().removeIf(n -> TownyComponent.dataSource.getNation(n) == null); // Removes nation colors for deleted/renamed nations
initDynmap(); initDynmap();
@ -156,12 +156,7 @@ public class TownColorComponent extends Component<PluginMain> implements Listene
if (nickname.contains("~")) //StartsWith doesn't work because of color codes if (nickname.contains("~")) //StartsWith doesn't work because of color codes
nickname = nickname.replace("~", ""); //It gets stacked otherwise nickname = nickname.replace("~", ""); //It gets stacked otherwise
String name = ChatColor.stripColor(nickname); //Enforce "town colors" on non-members String name = ChatColor.stripColor(nickname); //Enforce "town colors" on non-members
Resident res; Resident res = TownyComponent.dataSource.getResident(player.getName());
try {
res = TownyComponent.dataSource.getResident(player.getName());
} catch (NotRegisteredException e) {
return name;
}
if (res == null || !res.hasTown()) if (res == null || !res.hasTown())
return name; return name;
try { try {

View file

@ -9,7 +9,6 @@ import buttondevteam.lib.chat.Color;
import buttondevteam.lib.chat.Command2; import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.CustomTabCompleteMethod; import buttondevteam.lib.chat.CustomTabCompleteMethod;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Nation; import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownyObject; import com.palmergames.bukkit.towny.object.TownyObject;
@ -24,13 +23,12 @@ import org.bukkit.command.CommandSender;
public class NationColorCommand extends AdminCommandBase { public class NationColorCommand extends AdminCommandBase {
@Command2.Subcommand @Command2.Subcommand
public boolean def(CommandSender sender, String nation, String color) { public boolean def(CommandSender sender, String nation, String color) {
try { final Nation n = TownyComponent.dataSource.getNation(nation);
final Nation n = TownyComponent.dataSource.getNation(nation); if (n == null) {
return SetNationColor(sender, n, color);
} catch (NotRegisteredException e) {
sender.sendMessage("§cThe nation '" + nation + "' cannot be found."); sender.sendMessage("§cThe nation '" + nation + "' cannot be found.");
return true; return true;
} }
return SetNationColor(sender, n, color);
} }
@CustomTabCompleteMethod(param = "color") @CustomTabCompleteMethod(param = "color")

View file

@ -8,7 +8,6 @@ import buttondevteam.lib.chat.Color;
import buttondevteam.lib.chat.Command2; import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.CustomTabCompleteMethod; import buttondevteam.lib.chat.CustomTabCompleteMethod;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownyObject; import com.palmergames.bukkit.towny.object.TownyObject;
import lombok.val; import lombok.val;
@ -29,17 +28,16 @@ import java.util.stream.Collectors;
public class TownColorCommand extends AdminCommandBase { public class TownColorCommand extends AdminCommandBase {
@Command2.Subcommand @Command2.Subcommand
public boolean def(CommandSender sender, String town, String... colornames) { public boolean def(CommandSender sender, String town, String... colornames) {
if (!TownyComponent.dataSource.hasTown(town)) { if (TownyComponent.dataSource.getTown(town) == null) {
sender.sendMessage("§cThe town '" + town + "' cannot be found."); sender.sendMessage("§cThe town '" + town + "' cannot be found.");
return true; return true;
} }
try { Town targetTown = TownyComponent.dataSource.getTown(town);
Town targetTown = TownyComponent.dataSource.getTown(town); if (targetTown == null) {
return SetTownColor(sender, targetTown, colornames);
} catch (NotRegisteredException e) {
sender.sendMessage("§cThe town '" + town + "' cannot be found."); sender.sendMessage("§cThe town '" + town + "' cannot be found.");
return true; return true;
} }
return SetTownColor(sender, targetTown, colornames);
} }
@CustomTabCompleteMethod(param = "colornames") @CustomTabCompleteMethod(param = "colornames")
@ -118,11 +116,11 @@ public class TownColorCommand extends AdminCommandBase {
} }
public static String getTownNameCased(String name) { public static String getTownNameCased(String name) {
try { val town = TownyComponent.dataSource.getTown(name);
return TownyComponent.dataSource.getTown(name).getName(); if (town == null) {
} catch (NotRegisteredException e) {
return null; return null;
} }
return town.getName();
} }
public static Iterable<String> tabcompleteColor() { public static Iterable<String> tabcompleteColor() {

View file

@ -8,7 +8,8 @@ import buttondevteam.core.component.channel.Channel;
import buttondevteam.lib.architecture.Component; import buttondevteam.lib.architecture.Component;
import buttondevteam.lib.chat.Color; import buttondevteam.lib.chat.Color;
import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.chat.TBMCChatAPI;
import com.palmergames.bukkit.towny.db.TownyDataSource; import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.TownyUniverse;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Nation; import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Resident; import com.palmergames.bukkit.towny.object.Resident;
@ -29,7 +30,7 @@ import java.util.stream.Collectors;
* You can disable /tc and /nc in Chroma-Core's config if you only want to use the TownColorComponent. * You can disable /tc and /nc in Chroma-Core's config if you only want to use the TownColorComponent.
*/ */
public class TownyComponent extends Component<PluginMain> { public class TownyComponent extends Component<PluginMain> {
public static TownyDataSource dataSource; public static TownyAPI dataSource;
private static ArrayList<String> Towns; private static ArrayList<String> Towns;
private static ArrayList<String> Nations; private static ArrayList<String> Nations;
@ -38,21 +39,9 @@ public class TownyComponent extends Component<PluginMain> {
@Override @Override
protected void enable() { protected void enable() {
try { dataSource = TownyAPI.getInstance();
try { Towns = TownyUniverse.getInstance().getTowns().stream().map(Town::getName).collect(Collectors.toCollection(ArrayList::new)); // Creates a snapshot of towns, new towns will be added when needed
var tucl = Class.forName("com.palmergames.bukkit.towny.TownyUniverse"); Nations = TownyUniverse.getInstance().getNations().stream().map(Nation::getName).collect(Collectors.toCollection(ArrayList::new)); // Same here but with nations
var tu = tucl.getMethod("getInstance").invoke(null);
dataSource = (TownyDataSource) tucl.getMethod("getDataSource")
.invoke(tu);
} catch (ClassNotFoundException e) {
dataSource = (TownyDataSource) Class.forName("com.palmergames.bukkit.towny.object.TownyUniverse").getMethod("getDataSource")
.invoke(null);
}
} catch (Exception e) {
throw new RuntimeException("Failed to find Towny's data source!", e);
}
Towns = dataSource.getTowns().stream().map(Town::getName).collect(Collectors.toCollection(ArrayList::new)); // Creates a snapshot of towns, new towns will be added when needed
Nations = dataSource.getNations().stream().map(Nation::getName).collect(Collectors.toCollection(ArrayList::new)); // Same here but with nations
TBMCChatAPI.registerChatChannel( TBMCChatAPI.registerChatChannel(
TownChat = new Channel("§3TC§f", Color.DarkAqua, "tc", s -> checkTownNationChat(s, false))); TownChat = new Channel("§3TC§f", Color.DarkAqua, "tc", s -> checkTownNationChat(s, false)));
TBMCChatAPI.registerChatChannel( TBMCChatAPI.registerChatChannel(
@ -77,12 +66,13 @@ public class TownyComponent extends Component<PluginMain> {
private void handleSpies(Channel channel, Player p, String jsonstr, CommandSender sender, String message) { private void handleSpies(Channel channel, Player p, String jsonstr, CommandSender sender, String message) {
if (channel.getIdentifier().equals(TownChat.getIdentifier()) || channel.getIdentifier().equals(NationChat.getIdentifier())) { if (channel.getIdentifier().equals(TownChat.getIdentifier()) || channel.getIdentifier().equals(NationChat.getIdentifier())) {
try { val res = dataSource.getResident(p.getName());
if (dataSource.getResident(p.getName()).hasMode("spy")) if (res == null) {
if (!VanillaUtils.tellRaw(p, jsonstr)) return;
ChatUtils.sendChatMessage(channel, sender, message, p);
} catch (NotRegisteredException ignored) {
} }
if (res.hasMode("spy"))
if (!VanillaUtils.tellRaw(p, jsonstr))
ChatUtils.sendChatMessage(channel, sender, message, p);
} }
} }
@ -92,12 +82,7 @@ public class TownyComponent extends Component<PluginMain> {
private static Channel.RecipientTestResult checkTownNationChat(CommandSender sender, boolean nationchat) { private static Channel.RecipientTestResult checkTownNationChat(CommandSender sender, boolean nationchat) {
if (!(sender instanceof Player)) if (!(sender instanceof Player))
return new Channel.RecipientTestResult("§cYou are not a player!"); return new Channel.RecipientTestResult("§cYou are not a player!");
Resident resident; Resident resident = dataSource.getResident(sender.getName());
try {
resident = dataSource.getResident(sender.getName());
} catch (NotRegisteredException e) {
resident = null;
}
Channel.RecipientTestResult result = checkTownNationChatInternal(nationchat, resident); Channel.RecipientTestResult result = checkTownNationChatInternal(nationchat, resident);
if (result.errormessage != null && resident != null && resident.getModes().contains("spy")) // Only use spy if they wouldn't see it if (result.errormessage != null && resident != null && resident.getModes().contains("spy")) // Only use spy if they wouldn't see it
result = new Channel.RecipientTestResult(1000, "allspies"); // There won't be more than a thousand towns/nations probably result = new Channel.RecipientTestResult(1000, "allspies"); // There won't be more than a thousand towns/nations probably