Update Towny dependency and replace methods that were removed (#128)

This commit is contained in:
Norbi Peti 2023-03-13 00:47:40 +01:00
parent 6c1378f370
commit 10bf0e98df
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 -->
</configuration>
</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>
</build>
<groupId>buttondevteam</groupId>
@ -137,7 +122,7 @@
<groupId>com.github.TownyAdvanced</groupId>
<artifactId>Towny</artifactId>
<!-- <version>8d3b6b6</version> ButtonCore repo -->
<version>0.96.2.0</version>
<version>0.98.6.0</version>
<scope>provided</scope>
</dependency>
<!-- <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);
}
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)
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();
@ -156,12 +156,7 @@ public class TownColorComponent extends Component<PluginMain> implements Listene
if (nickname.contains("~")) //StartsWith doesn't work because of color codes
nickname = nickname.replace("~", ""); //It gets stacked otherwise
String name = ChatColor.stripColor(nickname); //Enforce "town colors" on non-members
Resident res;
try {
res = TownyComponent.dataSource.getResident(player.getName());
} catch (NotRegisteredException e) {
return name;
}
Resident res = TownyComponent.dataSource.getResident(player.getName());
if (res == null || !res.hasTown())
return name;
try {

View file

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

View file

@ -8,7 +8,6 @@ import buttondevteam.lib.chat.Color;
import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.chat.CommandClass;
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.TownyObject;
import lombok.val;
@ -29,17 +28,16 @@ import java.util.stream.Collectors;
public class TownColorCommand extends AdminCommandBase {
@Command2.Subcommand
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.");
return true;
}
try {
Town targetTown = TownyComponent.dataSource.getTown(town);
return SetTownColor(sender, targetTown, colornames);
} catch (NotRegisteredException e) {
Town targetTown = TownyComponent.dataSource.getTown(town);
if (targetTown == null) {
sender.sendMessage("§cThe town '" + town + "' cannot be found.");
return true;
}
return SetTownColor(sender, targetTown, colornames);
}
@CustomTabCompleteMethod(param = "colornames")
@ -118,11 +116,11 @@ public class TownColorCommand extends AdminCommandBase {
}
public static String getTownNameCased(String name) {
try {
return TownyComponent.dataSource.getTown(name).getName();
} catch (NotRegisteredException e) {
val town = TownyComponent.dataSource.getTown(name);
if (town == null) {
return null;
}
return town.getName();
}
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.chat.Color;
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.object.Nation;
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.
*/
public class TownyComponent extends Component<PluginMain> {
public static TownyDataSource dataSource;
public static TownyAPI dataSource;
private static ArrayList<String> Towns;
private static ArrayList<String> Nations;
@ -38,21 +39,9 @@ public class TownyComponent extends Component<PluginMain> {
@Override
protected void enable() {
try {
try {
var tucl = Class.forName("com.palmergames.bukkit.towny.TownyUniverse");
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
dataSource = TownyAPI.getInstance();
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
Nations = TownyUniverse.getInstance().getNations().stream().map(Nation::getName).collect(Collectors.toCollection(ArrayList::new)); // Same here but with nations
TBMCChatAPI.RegisterChatChannel(
TownChat = new Channel("§3TC§f", Color.DarkAqua, "tc", s -> checkTownNationChat(s, false)));
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) {
if (channel.ID.equals(TownChat.ID) || channel.ID.equals(NationChat.ID)) {
try {
if (dataSource.getResident(p.getName()).hasMode("spy"))
if (!VanillaUtils.tellRaw(p, jsonstr))
ChatUtils.sendChatMessage(channel, sender, message, p);
} catch (NotRegisteredException ignored) {
val res = dataSource.getResident(p.getName());
if (res == null) {
return;
}
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) {
if (!(sender instanceof Player))
return new Channel.RecipientTestResult("§cYou are not a player!");
Resident resident;
try {
resident = dataSource.getResident(sender.getName());
} catch (NotRegisteredException e) {
resident = null;
}
Resident resident = dataSource.getResident(sender.getName());
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
result = new Channel.RecipientTestResult(1000, "allspies"); // There won't be more than a thousand towns/nations probably