Improved OFFLINE_REDSTONE handling (and added javadoc)

This commit is contained in:
Florian CUNY 2019-03-04 08:22:18 +01:00
parent c004c8e4a4
commit 2ae36e737f
2 changed files with 21 additions and 11 deletions

View File

@ -10,12 +10,19 @@ import org.bukkit.event.block.BlockRedstoneEvent;
import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.lists.Flags;
/**
* Handles {@link Flags#OFFLINE_REDSTONE} flag.
* @author tastybento
*/
public class OfflineRedstoneListener extends FlagListener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBlockRedstone(BlockRedstoneEvent e) {
// If offline redstone is allowed then return
if (!Flags.OFFLINE_REDSTONE.isSetForWorld(e.getBlock().getWorld())) {
if (!getIWM().inWorld(e.getBlock().getWorld()) || Flags.OFFLINE_REDSTONE.isSetForWorld(e.getBlock().getWorld())) {
// Do not do anything if it is not in the right world or if it is disabled.
return;
}
// Check if island exists and members are online
getIslands().getProtectedIslandAt(e.getBlock().getLocation()).ifPresent(i -> {
for (UUID uuid : i.getMemberSet()) {
@ -27,4 +34,3 @@ public class OfflineRedstoneListener extends FlagListener {
});
}
}
}

View File

@ -315,6 +315,10 @@ public final class Flags {
public static final Flag ISLAND_RESPAWN = new Flag.Builder("ISLAND_RESPAWN", Material.TORCH).type(Type.WORLD_SETTING)
.listener(new IslandRespawnListener()).defaultSetting(true).build();
/**
* If disabled, prevents redstone from operating on islands whose members are offline.
* @see OfflineRedstoneListener
*/
public static final Flag OFFLINE_REDSTONE = new Flag.Builder("OFFLINE_REDSTONE", Material.COMPARATOR).type(Type.WORLD_SETTING)
.listener(new OfflineRedstoneListener()).defaultSetting(true).build();