mirror of
https://github.com/YouHaveTrouble/YardWatch.git
synced 2026-05-12 06:26:59 +00:00
Adds towny and superiorskyblock support (#1)
* Stash changes * Add superiorskyblock2 support * Add as a soft depend * Fix skyblock support * Add palmers towny support * Turned off wildcard imports * Update readme * Update .gitignore * Add new line * Add new line
This commit is contained in:
@@ -3,6 +3,8 @@ package me.youhavetrouble.yardwatch;
|
||||
import me.youhavetrouble.yardwatch.hooks.FactionsUUIDProtection;
|
||||
import me.youhavetrouble.yardwatch.hooks.GriefPreventionProtection;
|
||||
import me.youhavetrouble.yardwatch.hooks.LWCXProtection;
|
||||
import me.youhavetrouble.yardwatch.hooks.SuperiorSkyBlockProtection;
|
||||
import me.youhavetrouble.yardwatch.hooks.TownyProtection;
|
||||
import me.youhavetrouble.yardwatch.hooks.WorldGuardProtection;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
@@ -15,7 +17,6 @@ public final class YardWatch extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
if (shouldRegisterService("WorldGuard")) {
|
||||
getServer().getServicesManager().register(
|
||||
Protection.class, new WorldGuardProtection(this), this, ServicePriority.Normal
|
||||
@@ -40,6 +41,18 @@ public final class YardWatch extends JavaPlugin {
|
||||
);
|
||||
}
|
||||
|
||||
if (shouldRegisterService("SuperiorSkyblock2")) {
|
||||
getServer().getServicesManager().register(
|
||||
Protection.class, new SuperiorSkyBlockProtection(this), this, ServicePriority.Normal
|
||||
);
|
||||
}
|
||||
|
||||
if (shouldRegisterService("Towny")) {
|
||||
getServer().getServicesManager().register(
|
||||
Protection.class, new TownyProtection(this), this, ServicePriority.Normal
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
package me.youhavetrouble.yardwatch.hooks;
|
||||
|
||||
import com.bgsoftware.superiorskyblock.api.SuperiorSkyblockAPI;
|
||||
import com.bgsoftware.superiorskyblock.api.island.BlockChangeResult;
|
||||
import com.bgsoftware.superiorskyblock.api.island.Island;
|
||||
import com.bgsoftware.superiorskyblock.api.island.IslandPrivilege;
|
||||
import com.bgsoftware.superiorskyblock.api.wrappers.SuperiorPlayer;
|
||||
import me.youhavetrouble.yardwatch.Protection;
|
||||
import me.youhavetrouble.yardwatch.YardWatch;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.banner.PatternType;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class SuperiorSkyBlockProtection implements Protection {
|
||||
|
||||
private final YardWatch plugin;
|
||||
|
||||
public SuperiorSkyBlockProtection(YardWatch plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return this.plugin.getServer().getPluginManager().isPluginEnabled("SuperiorSkyblock2");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProtected(Location location) {
|
||||
if (!isEnabled()) return false;
|
||||
|
||||
Island island = SuperiorSkyblockAPI.getIslandAt(location);
|
||||
|
||||
return island != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreakBlock(Player player, BlockState blockState) {
|
||||
if (!isEnabled()) return true;
|
||||
|
||||
Location location = blockState.getLocation();
|
||||
|
||||
Island island = SuperiorSkyblockAPI.getIslandAt(location);
|
||||
|
||||
return island == null || island.hasPermission(player, IslandPrivilege.getByName("BREAK"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceBlock(Player player, Location location) {
|
||||
if (!isEnabled()) return true;
|
||||
|
||||
Island island = SuperiorSkyblockAPI.getIslandAt(location);
|
||||
|
||||
return island == null || island.hasPermission(player, IslandPrivilege.getByName("INTERACT"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteract(Player player, BlockState blockState) {
|
||||
if (!isEnabled()) return true;
|
||||
|
||||
Location location = blockState.getLocation();
|
||||
|
||||
Island island = SuperiorSkyblockAPI.getIslandAt(location);
|
||||
|
||||
return island == null || island.hasPermission(player, IslandPrivilege.getByName("INTERACT"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteract(Player player, Entity target) {
|
||||
if (!isEnabled()) return true;
|
||||
|
||||
Location location = target.getLocation();
|
||||
|
||||
Island island = SuperiorSkyblockAPI.getIslandAt(location);
|
||||
|
||||
return island == null || island.hasPermission(player, IslandPrivilege.getByName("INTERACT")) || island.hasPermission(player, IslandPrivilege.getByName("USE"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDamage(Entity damager, Entity target) {
|
||||
if (!isEnabled()) return true;
|
||||
if (!(damager instanceof Player attacker)) return true;
|
||||
|
||||
Location location = target.getLocation();
|
||||
|
||||
Island island = SuperiorSkyblockAPI.getIslandAt(location);
|
||||
|
||||
return island == null || island.hasPermission(attacker, IslandPrivilege.getByName("INTERACT"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package me.youhavetrouble.yardwatch.hooks;
|
||||
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.TownBlock;
|
||||
import com.palmergames.bukkit.towny.object.TownyPermission;
|
||||
import com.palmergames.bukkit.towny.utils.CombatUtil;
|
||||
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 TownyProtection implements Protection {
|
||||
|
||||
private final YardWatch plugin;
|
||||
|
||||
private final TownyAPI api;
|
||||
|
||||
public TownyProtection(YardWatch plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
this.api = TownyAPI.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return this.plugin.getServer().getPluginManager().isPluginEnabled("Towny");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProtected(Location location) {
|
||||
if (!isEnabled()) return false;
|
||||
|
||||
TownBlock town = this.api.getTownBlock(location);
|
||||
|
||||
return town != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreakBlock(Player player, BlockState blockState) {
|
||||
return canInteract(player, blockState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceBlock(Player player, Location location) {
|
||||
return canInteract(player, location.getBlock().getState(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteract(Player player, BlockState blockState) {
|
||||
if (!isEnabled()) return true;
|
||||
|
||||
Location location = blockState.getLocation();
|
||||
|
||||
TownBlock town = this.api.getTownBlock(location);
|
||||
|
||||
Resident resident = this.api.getResident(player.getUniqueId());
|
||||
|
||||
return town == null || town.hasResident(resident) || town.hasTrustedResident(resident);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteract(Player player, Entity target) {
|
||||
return canInteract(player, target.getLocation().getBlock().getState(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDamage(Entity damager, Entity target) {
|
||||
if (!isEnabled()) return true;
|
||||
if (!(damager instanceof Player)) return true;
|
||||
|
||||
Location location = target.getLocation();
|
||||
|
||||
TownBlock town = this.api.getTownBlock(location);
|
||||
|
||||
return town == null || CombatUtil.preventPvP(town.getWorld(), town);
|
||||
}
|
||||
}
|
||||
@@ -12,3 +12,4 @@ softdepend:
|
||||
- "GriefPrevention"
|
||||
- "Towny"
|
||||
- "Factions"
|
||||
- "SuperiorSkyblock2"
|
||||
|
||||
Reference in New Issue
Block a user