mirror of
https://github.com/YouHaveTrouble/YardWatch.git
synced 2026-05-11 22:16:58 +00:00
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>
This commit is contained in:
committed by
GitHub
parent
3833c5ce43
commit
afdb3a0e3e
@@ -2,9 +2,13 @@ package me.youhavetrouble.yardwatch.commands;
|
|||||||
|
|
||||||
import me.youhavetrouble.yardwatch.Protection;
|
import me.youhavetrouble.yardwatch.Protection;
|
||||||
import me.youhavetrouble.yardwatch.YardWatch;
|
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.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabExecutor;
|
import org.bukkit.command.TabExecutor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.bukkit.util.StringUtil;
|
import org.bukkit.util.StringUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -34,6 +38,9 @@ public class YardWatchCommand implements TabExecutor {
|
|||||||
if (args[0].equalsIgnoreCase("hooks")) {
|
if (args[0].equalsIgnoreCase("hooks")) {
|
||||||
sendHooks(sender);
|
sendHooks(sender);
|
||||||
return true;
|
return true;
|
||||||
|
} else if (args[0].equalsIgnoreCase("query")) {
|
||||||
|
queryProtection(sender);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -45,6 +52,7 @@ public class YardWatchCommand implements TabExecutor {
|
|||||||
|
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
completions.add("hooks");
|
completions.add("hooks");
|
||||||
|
completions.add("query");
|
||||||
return StringUtil.copyPartialMatches(args[0], completions, new ArrayList<>());
|
return StringUtil.copyPartialMatches(args[0], completions, new ArrayList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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.LocalPlayer;
|
||||||
import com.sk89q.worldguard.WorldGuard;
|
import com.sk89q.worldguard.WorldGuard;
|
||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
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.flags.Flags;
|
||||||
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
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);
|
com.sk89q.worldedit.util.Location wgLocation = BukkitAdapter.adapt(location);
|
||||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||||
RegionQuery query = container.createQuery();
|
RegionQuery query = container.createQuery();
|
||||||
return query.testBuild(wgLocation, null);
|
return query.testBuild(wgLocation, Associables.constant(Association.NON_MEMBER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user