mirror of
https://github.com/YouHaveTrouble/YardWatch.git
synced 2026-05-12 14:36:58 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5c942e72c3 | |||
| 27bb0e49e7 | |||
| 8aba8ea79d | |||
| afdb3a0e3e | |||
| 3833c5ce43 | |||
| fec112511c | |||
| c65e68dcfc | |||
| b7587970c0 | |||
| 48f5c337d7 | |||
| 6017feccec | |||
| 31fa7b02b9 | |||
| eb9ebb1fb3 |
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>me.youhavetrouble</groupId>
|
<groupId>me.youhavetrouble</groupId>
|
||||||
<artifactId>YardWatch</artifactId>
|
<artifactId>YardWatch</artifactId>
|
||||||
<version>1.1.0</version>
|
<version>1.3.0</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>YardWatch</name>
|
<name>YardWatch</name>
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<java.version>17</java.version>
|
<java.version>17</java.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<yardwatch.api.version>2.0.0</yardwatch.api.version>
|
||||||
</properties>
|
</properties>
|
||||||
<url>https://youhavetrouble.me</url>
|
<url>https://youhavetrouble.me</url>
|
||||||
|
|
||||||
@@ -39,6 +40,15 @@
|
|||||||
<goals>
|
<goals>
|
||||||
<goal>shade</goal>
|
<goal>shade</goal>
|
||||||
</goals>
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<transformers>
|
||||||
|
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
|
<manifestEntries>
|
||||||
|
<paperweight-mappings-namespace>mojang</paperweight-mappings-namespace>
|
||||||
|
</manifestEntries>
|
||||||
|
</transformer>
|
||||||
|
</transformers>
|
||||||
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
@@ -96,7 +106,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sk89q.worldguard</groupId>
|
<groupId>com.sk89q.worldguard</groupId>
|
||||||
<artifactId>worldguard-bukkit</artifactId>
|
<artifactId>worldguard-bukkit</artifactId>
|
||||||
<version>7.0.4-SNAPSHOT</version>
|
<version>7.0.9-SNAPSHOT</version>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<groupId>org.bstats</groupId>
|
<groupId>org.bstats</groupId>
|
||||||
@@ -108,7 +118,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.YouHaveTrouble</groupId>
|
<groupId>com.github.YouHaveTrouble</groupId>
|
||||||
<artifactId>YardWatchAPI</artifactId>
|
<artifactId>YardWatchAPI</artifactId>
|
||||||
<version>2.0.0</version>
|
<version>${yardwatch.api.version}</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ Implementation of [YardWatchAPI](https://github.com/YouHaveTrouble/YardWatchAPI)
|
|||||||
of supported plugins implements the API itself, then this plugin will stop providing its implementation to allow the
|
of supported plugins implements the API itself, then this plugin will stop providing its implementation to allow the
|
||||||
plugin to take over.
|
plugin to take over.
|
||||||
|
|
||||||
|
|
||||||
If you're a developer looking for information how to implement YardWatchAPI in your plugin, see
|
If you're a developer looking for information how to implement YardWatchAPI in your plugin, see
|
||||||
[YardWatchAPI](https://github.com/YouHaveTrouble/YardWatchAPI)
|
[YardWatchAPI](https://github.com/YouHaveTrouble/YardWatchAPI)
|
||||||
|
|
||||||
|
## Downloads
|
||||||
|
You can download YardWatch plugin on [Modrinth](https://modrinth.com/plugin/yardwatch).
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
- Java 17
|
- Java 17
|
||||||
- Minecraft 1.16+
|
- Minecraft 1.16+
|
||||||
@@ -14,7 +16,7 @@ If you're a developer looking for information how to implement YardWatchAPI in y
|
|||||||
## Implementations for:
|
## Implementations for:
|
||||||
- [GriefPrevention (v16+)](https://www.spigotmc.org/resources/griefprevention.1884/)
|
- [GriefPrevention (v16+)](https://www.spigotmc.org/resources/griefprevention.1884/)
|
||||||
- [WorldGuard (7.0.0+)](https://enginehub.org/worldguard#downloads)
|
- [WorldGuard (7.0.0+)](https://enginehub.org/worldguard#downloads)
|
||||||
- LWCX
|
- [LWCX](https://www.spigotmc.org/resources/lwc-extended.69551/)
|
||||||
- [FactionsUUID](https://www.spigotmc.org/resources/factionsuuid.1035/)
|
- [FactionsUUID](https://www.spigotmc.org/resources/factionsuuid.1035/)
|
||||||
- [SuperiorSkyBlock](https://bg-software.com/superiorskyblock/)
|
- [SuperiorSkyBlock](https://bg-software.com/superiorskyblock/)
|
||||||
- [Towny](https://github.com/TownyAdvanced/Towny)
|
- [Towny](https://github.com/TownyAdvanced/Towny)
|
||||||
|
|||||||
@@ -1,58 +1,91 @@
|
|||||||
package me.youhavetrouble.yardwatch;
|
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.FactionsUUIDProtection;
|
||||||
import me.youhavetrouble.yardwatch.hooks.GriefPreventionProtection;
|
import me.youhavetrouble.yardwatch.hooks.GriefPreventionProtection;
|
||||||
import me.youhavetrouble.yardwatch.hooks.LWCXProtection;
|
import me.youhavetrouble.yardwatch.hooks.LWCXProtection;
|
||||||
import me.youhavetrouble.yardwatch.hooks.SuperiorSkyBlockProtection;
|
import me.youhavetrouble.yardwatch.hooks.SuperiorSkyBlockProtection;
|
||||||
import me.youhavetrouble.yardwatch.hooks.TownyProtection;
|
import me.youhavetrouble.yardwatch.hooks.TownyProtection;
|
||||||
import me.youhavetrouble.yardwatch.hooks.WorldGuardProtection;
|
import me.youhavetrouble.yardwatch.hooks.WorldGuardProtection;
|
||||||
|
import org.bukkit.command.PluginCommand;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.bukkit.plugin.ServicePriority;
|
import org.bukkit.plugin.ServicePriority;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
public final class YardWatch extends JavaPlugin {
|
public final class YardWatch extends JavaPlugin {
|
||||||
|
|
||||||
|
private static String yardWatchApiVersion = "Unknown";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
if (shouldRegisterService("WorldGuard")) {
|
if (shouldRegisterService("WorldGuard")) {
|
||||||
|
getLogger().info("Registering WorldGuard service.");
|
||||||
getServer().getServicesManager().register(
|
getServer().getServicesManager().register(
|
||||||
Protection.class, new WorldGuardProtection(this), this, ServicePriority.Normal
|
Protection.class, new WorldGuardProtection(this), this, ServicePriority.Normal
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldRegisterService("GriefPrevention")) {
|
if (shouldRegisterService("GriefPrevention")) {
|
||||||
|
getLogger().info("Registering GriefPrevention service.");
|
||||||
getServer().getServicesManager().register(
|
getServer().getServicesManager().register(
|
||||||
Protection.class, new GriefPreventionProtection(this), this, ServicePriority.Normal
|
Protection.class, new GriefPreventionProtection(this), this, ServicePriority.Normal
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldRegisterService("LWC")) {
|
if (shouldRegisterService("LWC")) {
|
||||||
|
getLogger().info("Registering LWC service.");
|
||||||
getServer().getServicesManager().register(
|
getServer().getServicesManager().register(
|
||||||
Protection.class, new LWCXProtection(this), this, ServicePriority.Normal
|
Protection.class, new LWCXProtection(this), this, ServicePriority.Normal
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldRegisterService("Factions")) {
|
if (shouldRegisterService("Factions")) {
|
||||||
|
getLogger().info("Registering Factions service.");
|
||||||
getServer().getServicesManager().register(
|
getServer().getServicesManager().register(
|
||||||
Protection.class, new FactionsUUIDProtection(this), this, ServicePriority.Normal
|
Protection.class, new FactionsUUIDProtection(this), this, ServicePriority.Normal
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldRegisterService("SuperiorSkyblock2")) {
|
if (shouldRegisterService("SuperiorSkyblock2")) {
|
||||||
|
getLogger().info("Registering SuperiorSkyblock2 service.");
|
||||||
getServer().getServicesManager().register(
|
getServer().getServicesManager().register(
|
||||||
Protection.class, new SuperiorSkyBlockProtection(this), this, ServicePriority.Normal
|
Protection.class, new SuperiorSkyBlockProtection(this), this, ServicePriority.Normal
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldRegisterService("Towny")) {
|
if (shouldRegisterService("Towny")) {
|
||||||
|
getLogger().info("Registering Towny service.");
|
||||||
getServer().getServicesManager().register(
|
getServer().getServicesManager().register(
|
||||||
Protection.class, new TownyProtection(this), this, ServicePriority.Normal
|
Protection.class, new TownyProtection(this), this, ServicePriority.Normal
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<RegisteredServiceProvider<?>> registrations = getServer().getServicesManager().getRegistrations(this);
|
||||||
|
if (registrations.isEmpty()) {
|
||||||
|
getLogger().info("Registered 0 services. This plugin can be safely removed.");
|
||||||
|
} else {
|
||||||
|
getLogger().info("Successfully registered " + registrations.size() + " services.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -76,4 +109,8 @@ public final class YardWatch extends JavaPlugin {
|
|||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
getServer().getServicesManager().unregisterAll(this);
|
getServer().getServicesManager().unregisterAll(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getYardWatchApiVersion() {
|
||||||
|
return yardWatchApiVersion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
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;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class YardWatchCommand implements TabExecutor {
|
||||||
|
|
||||||
|
private final YardWatch plugin;
|
||||||
|
|
||||||
|
private final String version;
|
||||||
|
|
||||||
|
public YardWatchCommand(YardWatch plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.version = plugin.getDescription().getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
|
|
||||||
|
if (args.length == 0) {
|
||||||
|
sendDefault(sender);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args[0].equalsIgnoreCase("hooks")) {
|
||||||
|
sendHooks(sender);
|
||||||
|
return true;
|
||||||
|
} else if (args[0].equalsIgnoreCase("query")) {
|
||||||
|
queryProtection(sender);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
||||||
|
List<String> completions = new ArrayList<>();
|
||||||
|
|
||||||
|
if (args.length == 1) {
|
||||||
|
completions.add("hooks");
|
||||||
|
completions.add("query");
|
||||||
|
return StringUtil.copyPartialMatches(args[0], completions, new ArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
return completions;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendDefault(CommandSender sender) {
|
||||||
|
sender.sendMessage(String.format("YardWatch %s (Implementing YardWatch API %s)", version, YardWatch.getYardWatchApiVersion()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendHooks(CommandSender sender) {
|
||||||
|
Map<String, Integer> hooks = new HashMap<>();
|
||||||
|
Collection<RegisteredServiceProvider<Protection>> protections = plugin.getServer().getServicesManager().getRegistrations(Protection.class);
|
||||||
|
for (RegisteredServiceProvider<Protection> protection : protections) {
|
||||||
|
hooks.merge(protection.getPlugin().getName(), 1, Integer::sum);
|
||||||
|
}
|
||||||
|
if (hooks.isEmpty()) {
|
||||||
|
sender.sendMessage("No hooks registered.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sender.sendMessage("Hooks:");
|
||||||
|
for (Map.Entry<String, Integer> entry : hooks.entrySet()) {
|
||||||
|
String hook = entry.getValue() == 1 ? "hook" : "hooks";
|
||||||
|
sender.sendMessage(String.format("%s -> %s %s registered", entry.getKey(), entry.getValue(), hook));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
${yardwatch.api.version}
|
||||||
@@ -13,3 +13,11 @@ softdepend:
|
|||||||
- "Towny"
|
- "Towny"
|
||||||
- "Factions"
|
- "Factions"
|
||||||
- "SuperiorSkyblock2"
|
- "SuperiorSkyblock2"
|
||||||
|
- "LWC"
|
||||||
|
commands:
|
||||||
|
yardwatch:
|
||||||
|
description: "YardWatch command"
|
||||||
|
usage: "/yardwatch <arg>"
|
||||||
|
permission: "yardwatch.command"
|
||||||
|
aliases:
|
||||||
|
- "yw"
|
||||||
Reference in New Issue
Block a user