mirror of
https://github.com/Phoenix616/RandomTeleport.git
synced 2024-11-22 10:36:00 +01:00
Check if player can build as we don't care about actual protection info
This commit is contained in:
parent
514e2bb684
commit
ff4106253b
@ -20,6 +20,7 @@ package de.themoep.randomteleport.hook;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
@ -126,45 +127,23 @@ public class HookManager implements Listener, ProtectionHook, WorldborderHook {
|
||||
// Convenience methods to check all registered hooks
|
||||
|
||||
@Override
|
||||
public boolean isProtected(Location location) {
|
||||
public boolean canBuild(Player player, Location location) {
|
||||
for (ProtectionHook hook : getHooks(ProtectionHook.class)) {
|
||||
if (hook.isProtected(location)) {
|
||||
return true;
|
||||
if (!hook.canBuild(player, location)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOwner(Location location) {
|
||||
public boolean canBuild(Player player, World world, int chunkX, int chunkZ) {
|
||||
for (ProtectionHook hook : getHooks(ProtectionHook.class)) {
|
||||
String owner = hook.getOwner(location);
|
||||
if (owner != null) {
|
||||
return owner;
|
||||
if (!hook.canBuild(player, world, chunkX, chunkZ)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProtected(World world, int chunkX, int chunkZ) {
|
||||
for (ProtectionHook hook : getHooks(ProtectionHook.class)) {
|
||||
if (hook.isProtected(world, chunkX, chunkZ)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOwner(World world, int chunkX, int chunkZ) {
|
||||
for (ProtectionHook hook : getHooks(ProtectionHook.class)) {
|
||||
String owner = hook.getOwner(world, chunkX, chunkZ);
|
||||
if (owner != null) {
|
||||
return owner;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,6 +23,7 @@ import io.papermc.lib.features.blockstatesnapshot.BlockStateSnapshotResult;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Lockable;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class MinecraftHook implements ProtectionHook, WorldborderHook {
|
||||
@ -43,31 +44,17 @@ public class MinecraftHook implements ProtectionHook, WorldborderHook {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProtected(Location location) {
|
||||
public boolean canBuild(Player player, Location location) {
|
||||
BlockStateSnapshotResult state = PaperLib.getBlockState(location.getBlock(), true);
|
||||
if (state.getState() instanceof Lockable) {
|
||||
return ((Lockable) state.getState()).getLock() != null;
|
||||
return ((Lockable) state.getState()).getLock() == null;
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOwner(Location location) {
|
||||
BlockStateSnapshotResult state = PaperLib.getBlockState(location.getBlock(), true);
|
||||
if (state.getState() instanceof Lockable) {
|
||||
return ((Lockable) state.getState()).getLock();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProtected(World world, int chunkX, int chunkZ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOwner(World world, int chunkX, int chunkZ) {
|
||||
return null;
|
||||
public boolean canBuild(Player player, World world, int chunkX, int chunkZ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,57 +21,37 @@ package de.themoep.randomteleport.hook;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface ProtectionHook extends PluginHook {
|
||||
|
||||
/**
|
||||
* Check if a certain location is protected
|
||||
* Check if a player can build at a location
|
||||
*
|
||||
* @param player The player to check
|
||||
* @param location The location to check
|
||||
* @return Whether or not it is protected
|
||||
* @return Whether or not the player can build
|
||||
*/
|
||||
boolean isProtected(Location location);
|
||||
boolean canBuild(Player player, Location location);
|
||||
|
||||
/**
|
||||
* Get the owner of a protection at a certain location, null if no owner
|
||||
* @param location The location to check
|
||||
* @return The name of the owner of the location, null if no owner
|
||||
*/
|
||||
String getOwner(Location location);
|
||||
|
||||
/**
|
||||
* Check if a certain chunk is protected
|
||||
* Check if a player can build in a chunk
|
||||
* @param player The player to check
|
||||
* @param chunk The chunk to check
|
||||
* @return Whether or not it is protected
|
||||
* @return Whether or not the player can build
|
||||
*/
|
||||
default boolean isProtected(Chunk chunk) {
|
||||
return isProtected(chunk.getWorld(), chunk.getX(), chunk.getZ());
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if a certain chunk is protected
|
||||
* @param world The chunk's world
|
||||
* @param chunkX The chunk's X coordinate
|
||||
* @param chunkZ The chunk's Z coordinate
|
||||
* @return Whether or not it is protected
|
||||
*/
|
||||
boolean isProtected(World world, int chunkX, int chunkZ);
|
||||
|
||||
/**
|
||||
* Get the owner of a protection at a certain chunk, null if no owner
|
||||
* @param chunk The chunk to check
|
||||
* @return The name of the owner of the location, null if no owner
|
||||
*/
|
||||
default String getOwner(Chunk chunk) {
|
||||
return getOwner(chunk.getWorld(), chunk.getX(), chunk.getZ());
|
||||
default boolean canBuild(Player player, Chunk chunk) {
|
||||
return canBuild(player, chunk.getWorld(), chunk.getX(), chunk.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the owner of a protection at a certain chunk, null if no owner
|
||||
* Check if a player can build in a chunk
|
||||
* @param player The player to check
|
||||
* @param world The chunk's world
|
||||
* @param chunkX The chunk's X coordinate
|
||||
* @param chunkZ The chunk's Z coordinate
|
||||
* @return The name of the owner of the location, null if no owner
|
||||
* @return Whether or not the player can build
|
||||
*/
|
||||
String getOwner(World world, int chunkX, int chunkZ);
|
||||
boolean canBuild(Player player, World world, int chunkX, int chunkZ);
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user