mirror of
https://github.com/YouHaveTrouble/YardWatch.git
synced 2026-05-11 22:16:58 +00:00
Integrate LWCXProtection in YardWatch
A new protection hook, LWCXProtection, has been introduced to the YardWatch system, and the respective hook has been registered. Changes have been made to the service manager to facilitate this. Additionally, a relevant repository and corresponding dependency have been added to the pom.xml file for this purpose.
This commit is contained in:
@@ -68,6 +68,10 @@
|
||||
<id>sk89q-repo</id>
|
||||
<url>https://maven.enginehub.org/repo/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>codemc-repo</id>
|
||||
<url>https://repo.codemc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
@@ -101,5 +105,11 @@
|
||||
<version>16.18.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.griefcraft</groupId>
|
||||
<artifactId>lwc</artifactId>
|
||||
<version>2.2.9-dev</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package me.youhavetrouble.yardwatch;
|
||||
|
||||
import me.youhavetrouble.yardwatch.hooks.GriefPreventionProtection;
|
||||
import me.youhavetrouble.yardwatch.hooks.LWCXProtection;
|
||||
import me.youhavetrouble.yardwatch.hooks.WorldGuardProtection;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
@@ -26,6 +27,12 @@ public final class YardWatch extends JavaPlugin {
|
||||
);
|
||||
}
|
||||
|
||||
if (shouldRegisterService("LWC")) {
|
||||
getServer().getServicesManager().register(
|
||||
Protection.class, new LWCXProtection(this), this, ServicePriority.Normal
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
package me.youhavetrouble.yardwatch.hooks;
|
||||
|
||||
import com.griefcraft.lwc.LWC;
|
||||
import com.griefcraft.lwc.LWCPlugin;
|
||||
import me.youhavetrouble.yardwatch.Protection;
|
||||
import me.youhavetrouble.yardwatch.YardWatch;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class LWCXProtection implements Protection {
|
||||
|
||||
private final YardWatch plugin;
|
||||
|
||||
public LWCXProtection(YardWatch plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return plugin.getServer().getPluginManager().isPluginEnabled("LWC");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProtected(Location location) {
|
||||
if (!isEnabled()) return false;
|
||||
return LWCPlugin.getPlugin(LWCPlugin.class).getLWC().findProtection(location) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreakBlock(Player player, BlockState blockState) {
|
||||
if (!isEnabled()) return true;
|
||||
return LWCPlugin.getPlugin(LWCPlugin.class)
|
||||
.getLWC()
|
||||
.canAccessProtection(
|
||||
player,
|
||||
blockState.getX(),
|
||||
blockState.getY(),
|
||||
blockState.getZ()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceBlock(Player player, Location location) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteract(Player player, BlockState blockState) {
|
||||
if (!isEnabled()) return true;
|
||||
return LWCPlugin.getPlugin(LWCPlugin.class)
|
||||
.getLWC()
|
||||
.canAccessProtection(
|
||||
player,
|
||||
blockState.getX(),
|
||||
blockState.getY(),
|
||||
blockState.getZ()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteract(Player player, Entity target) {
|
||||
if (!isEnabled()) return true;
|
||||
LWC lwc = LWCPlugin.getPlugin(LWCPlugin.class).getLWC();
|
||||
if (!lwc.isProtectable(target.getType())) return true;
|
||||
// the following is extraction of lwcx internal logic. I have no clue what's happening here.
|
||||
int a = 50000 + target.getUniqueId().hashCode();
|
||||
com.griefcraft.model.Protection protection = lwc.getPhysicalDatabase()
|
||||
.loadProtection(target.getWorld().getName(), a, a, a);
|
||||
if (protection == null) return true;
|
||||
return lwc.canAccessProtection(player, protection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDamage(Entity damager, Entity target) {
|
||||
if (!isEnabled()) return true;
|
||||
LWC lwc = LWCPlugin.getPlugin(LWCPlugin.class).getLWC();
|
||||
if (!lwc.isProtectable(target.getType())) return true;
|
||||
// the following is extraction of lwcx internal logic. I have no clue what's happening here.
|
||||
int a = 50000 + target.getUniqueId().hashCode();
|
||||
com.griefcraft.model.Protection protection = lwc.getPhysicalDatabase()
|
||||
.loadProtection(target.getWorld().getName(), a, a, a);
|
||||
if (protection == null) return true;
|
||||
if (damager instanceof Player player) {
|
||||
return lwc.canAccessProtection(player, protection);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user