-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d4a890
commit 57a2bf2
Showing
2 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...gin-bukkit/src/main/java/com/izanagicraft/guard/events/listener/BlockPhysicsListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.izanagicraft.guard.events.listener; | ||
|
||
import com.izanagicraft.guard.IzanagiWorldGuardPlugin; | ||
import com.izanagicraft.guard.events.GuardListener; | ||
import com.izanagicraft.guard.flags.GuardFlag; | ||
import org.bukkit.Location; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.configuration.file.YamlConfiguration; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.block.BlockPhysicsEvent; | ||
|
||
/** | ||
* IzanagiWorldGuard; com.izanagicraft.guard.events.listener:BlockPhysicsListener | ||
* | ||
* Handles the BlockPhysicsEvent to enforce block_physics-related flags within protected regions. | ||
* | ||
* @author <a href="https://github.com/sanguine6660">@sanguine6660</a> | ||
* @since 18.12.2023 | ||
*/ | ||
public class BlockPhysicsListener extends GuardListener { | ||
/** | ||
* Constructs a new GuardListener with the specified IzanagiWorldGuardPlugin. | ||
* | ||
* @param plugin The IzanagiWorldGuardPlugin instance. | ||
*/ | ||
public BlockPhysicsListener(IzanagiWorldGuardPlugin plugin) { | ||
super(plugin); | ||
} | ||
|
||
/** | ||
* Handles the BlockPhysicsEvent to enforce block_physics-related flags within protected regions. | ||
* | ||
* @param event The BlockPhysicsEvent. | ||
*/ | ||
@EventHandler | ||
public void onBlockPhysicsUpdate(BlockPhysicsEvent event) { | ||
Block block = event.getBlock(); | ||
|
||
if (block == null) { | ||
event.setCancelled(true); | ||
return; | ||
} | ||
|
||
Location target = block.getLocation(); | ||
|
||
YamlConfiguration worldConfig = getPlugin().getWorldConfigs().get(target.getWorld().getName()); | ||
if (worldConfig == null) return; | ||
|
||
boolean allowPhysics = true; | ||
|
||
String allow = worldConfig.getString("flags." + GuardFlag.BLOCK_PHYSICS.getFlagName(), "false"); | ||
|
||
if (allow.isEmpty() || allow.equalsIgnoreCase("empty") | ||
|| allow.equalsIgnoreCase("false") || allow.equalsIgnoreCase("deny")) { | ||
allowPhysics = false; | ||
} | ||
|
||
// TODO: region based checks. | ||
|
||
if (!allowPhysics) event.setCancelled(true); | ||
|
||
} | ||
} |