mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-26 18:11:43 +01:00
Improved OFFLINE_REDSTONE handling (and added javadoc)
This commit is contained in:
parent
c004c8e4a4
commit
2ae36e737f
@ -10,21 +10,27 @@ 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())) {
|
||||
// Check if island exists and members are online
|
||||
getIslands().getProtectedIslandAt(e.getBlock().getLocation()).ifPresent(i -> {
|
||||
for (UUID uuid : i.getMemberSet()) {
|
||||
if (Bukkit.getPlayer(uuid) != null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
e.setNewCurrent(0);
|
||||
});
|
||||
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()) {
|
||||
if (Bukkit.getPlayer(uuid) != null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
e.setNewCurrent(0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user