4 Commits

Author SHA1 Message Date
YouHaveTrouble 5c942e72c3 bump version 2024-07-19 18:56:14 +02:00
YouHaveTrouble 27bb0e49e7 display api version in /yw command feedback 2024-07-19 18:55:24 +02:00
YouHaveTrouble 8aba8ea79d update wg depend and dump YardWatch API version into a resource file 2024-07-19 18:55:06 +02:00
Hüseyin Serhat Han afdb3a0e3e Query command & Worldguard null parameter exception fix (#4)
* query command + fix wg exception

* remove empty statement and unused imports

* added feedback for case when there are no protections in queried location

---------

Co-authored-by: YouHaveTrouble <youhavetrouble@youhavetrouble.me>
2024-07-19 17:49:25 +02:00
5 changed files with 61 additions and 5 deletions
+4 -3
View File
@@ -6,7 +6,7 @@
<groupId>me.youhavetrouble</groupId>
<artifactId>YardWatch</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>
<packaging>jar</packaging>
<name>YardWatch</name>
@@ -15,6 +15,7 @@
<properties>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<yardwatch.api.version>2.0.0</yardwatch.api.version>
</properties>
<url>https://youhavetrouble.me</url>
@@ -105,7 +106,7 @@
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>
<version>7.0.4-SNAPSHOT</version>
<version>7.0.9-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.bstats</groupId>
@@ -117,7 +118,7 @@
<dependency>
<groupId>com.github.YouHaveTrouble</groupId>
<artifactId>YardWatchAPI</artifactId>
<version>2.0.0</version>
<version>${yardwatch.api.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
@@ -1,5 +1,6 @@
package me.youhavetrouble.yardwatch;
import com.google.common.io.Resources;
import me.youhavetrouble.yardwatch.commands.YardWatchCommand;
import me.youhavetrouble.yardwatch.hooks.FactionsUUIDProtection;
import me.youhavetrouble.yardwatch.hooks.GriefPreventionProtection;
@@ -13,13 +14,25 @@ import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.ServicePriority;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
import java.net.URL;
import java.util.List;
@SuppressWarnings("UnstableApiUsage")
public final class YardWatch extends JavaPlugin {
private static String yardWatchApiVersion = "Unknown";
@Override
public void onEnable() {
try {
URL url = Resources.getResource("apiversion.txt");
yardWatchApiVersion = Resources.toString(url, com.google.common.base.Charsets.UTF_8);
} catch (IOException e) {
getLogger().warning("Failed to read YardWatch API version.");
}
PluginCommand command = getCommand("yardwatch");
if (command != null) {
command.setExecutor(new YardWatchCommand(this));
@@ -96,4 +109,8 @@ public final class YardWatch extends JavaPlugin {
public void onDisable() {
getServer().getServicesManager().unregisterAll(this);
}
public static String getYardWatchApiVersion() {
return yardWatchApiVersion;
}
}
@@ -2,9 +2,13 @@ package me.youhavetrouble.yardwatch.commands;
import me.youhavetrouble.yardwatch.Protection;
import me.youhavetrouble.yardwatch.YardWatch;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.HoverEvent;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
@@ -34,6 +38,9 @@ public class YardWatchCommand implements TabExecutor {
if (args[0].equalsIgnoreCase("hooks")) {
sendHooks(sender);
return true;
} else if (args[0].equalsIgnoreCase("query")) {
queryProtection(sender);
return true;
}
return false;
@@ -45,6 +52,7 @@ public class YardWatchCommand implements TabExecutor {
if (args.length == 1) {
completions.add("hooks");
completions.add("query");
return StringUtil.copyPartialMatches(args[0], completions, new ArrayList<>());
}
@@ -52,7 +60,7 @@ public class YardWatchCommand implements TabExecutor {
}
private void sendDefault(CommandSender sender) {
sender.sendMessage("YardWatch " + version);
sender.sendMessage(String.format("YardWatch %s (Implementing YardWatch API %s)", version, YardWatch.getYardWatchApiVersion()));
}
private void sendHooks(CommandSender sender) {
@@ -72,4 +80,31 @@ public class YardWatchCommand implements TabExecutor {
}
}
private void queryProtection(CommandSender sender) {
if (!(sender instanceof Player player)) {
sender.sendMessage(("You must be a player to use this command!"));
return;
}
Location location = player.getLocation();
sender.sendMessage("Protections at " + location.getBlockX() + ", " + location.getBlockY() + ", " + location.getBlockZ());
Collection<RegisteredServiceProvider<Protection>> protections = plugin.getServer().getServicesManager().getRegistrations(Protection.class);
if (protections.isEmpty()) {
sender.sendMessage("No protections registered at " + location.getBlockX() + ", " + location.getBlockY() + ", " + location.getBlockZ());
return;
}
for (RegisteredServiceProvider<Protection> protection : protections) {
Component component = Component.text(protection.getPlugin().getName()).append(Component.text(" isProtected " + protection.getProvider().isProtected(location)))
.hoverEvent(HoverEvent.showText(
Component.text(protection.getProvider().toString())
.append(Component.newline())
.append(Component.text("canPlaceBlock " + protection.getProvider().canPlaceBlock(player, location))
.append(Component.newline())
.append(Component.text("canBreakBlock " + protection.getProvider().canBreakBlock(player, location.getBlock().getState())))
.append(Component.newline())
.append(Component.text("canInteract " + protection.getProvider().canInteract(player, location.getBlock().getState())))
)));
sender.sendMessage(component);
}
}
}
@@ -4,6 +4,8 @@ import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.domains.Association;
import com.sk89q.worldguard.protection.association.Associables;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import com.sk89q.worldguard.protection.regions.RegionQuery;
@@ -34,7 +36,7 @@ public class WorldGuardProtection implements Protection {
com.sk89q.worldedit.util.Location wgLocation = BukkitAdapter.adapt(location);
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
RegionQuery query = container.createQuery();
return query.testBuild(wgLocation, null);
return query.testBuild(wgLocation, Associables.constant(Association.NON_MEMBER));
}
@Override
+1
View File
@@ -0,0 +1 @@
${yardwatch.api.version}