-
-
Notifications
You must be signed in to change notification settings - Fork 5
Feature/only damage piloted #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package net.countercraft.movecraft.worldguard.listener; | ||
|
|
||
| import net.countercraft.movecraft.MovecraftLocation; | ||
| import net.countercraft.movecraft.craft.CraftManager; | ||
| import net.countercraft.movecraft.worldguard.CustomFlags; | ||
| import net.countercraft.movecraft.worldguard.MovecraftWorldGuard; | ||
| import net.countercraft.movecraft.worldguard.utils.WorldGuardUtils; | ||
| import org.bukkit.Location; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.Listener; | ||
| import org.bukkit.event.block.BlockBurnEvent; | ||
|
|
||
| public class BurnListener implements Listener { | ||
| @EventHandler | ||
| public void onBurn(BlockBurnEvent e) { | ||
| Location location = e.getBlock().getLocation(); | ||
|
|
||
| var wgUtils = MovecraftWorldGuard.getInstance().getWGUtils(); | ||
| WorldGuardUtils.State onlyDamagePilotedCrafts = wgUtils.getState(null, location, CustomFlags.ONLY_DAMAGE_PILOTED_CRAFTS); | ||
| if (onlyDamagePilotedCrafts != WorldGuardUtils.State.ALLOW) { | ||
| return; | ||
| } | ||
|
|
||
| MovecraftLocation movecraftLocation = new MovecraftLocation(location.getBlockX(), location.getBlockY(), location.getBlockZ()); | ||
| boolean burningCraft = CraftManager.getInstance().getCraftsInWorld(location.getWorld()).stream().anyMatch(it -> it.getHitBox().contains(movecraftLocation)); | ||
|
|
||
| e.setCancelled(!burningCraft); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,40 @@ | ||
| package net.countercraft.movecraft.worldguard.listener; | ||
|
|
||
| import com.sk89q.worldguard.protection.flags.Flags; | ||
| import net.countercraft.movecraft.MovecraftLocation; | ||
| import net.countercraft.movecraft.craft.CraftManager; | ||
| import net.countercraft.movecraft.events.ExplosionEvent; | ||
| import net.countercraft.movecraft.worldguard.CustomFlags; | ||
| import net.countercraft.movecraft.worldguard.MovecraftWorldGuard; | ||
| import net.countercraft.movecraft.worldguard.utils.WorldGuardUtils; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.Listener; | ||
| import org.bukkit.Location; | ||
|
|
||
| public class ExplosionListener implements Listener { | ||
| @EventHandler | ||
| public void onExplosion(ExplosionEvent e) { | ||
| switch (MovecraftWorldGuard.getInstance().getWGUtils().getState( | ||
| null, e.getExplosionLocation(), Flags.OTHER_EXPLOSION)) { | ||
| case ALLOW: | ||
| case NONE: | ||
| break; // Other-explosion is allowed | ||
| var wgUtils = MovecraftWorldGuard.getInstance().getWGUtils(); | ||
| Location explosionLocation = e.getExplosionLocation(); | ||
|
|
||
| switch (wgUtils.getState(null, explosionLocation, Flags.OTHER_EXPLOSION)) { | ||
| case DENY: | ||
| // Other-explosion is not allowed | ||
| e.setCancelled(true); | ||
| return; | ||
| default: | ||
| case ALLOW: // Other-explosion is allowed | ||
| case NONE: | ||
| break; | ||
| } | ||
|
|
||
| WorldGuardUtils.State onlyDamagePilotedCrafts = wgUtils.getState(null, explosionLocation, CustomFlags.ONLY_DAMAGE_PILOTED_CRAFTS); | ||
| if (onlyDamagePilotedCrafts != WorldGuardUtils.State.ALLOW) { | ||
| return; | ||
| } | ||
|
|
||
| MovecraftLocation movecraftLocation = new MovecraftLocation(explosionLocation.getBlockX(), explosionLocation.getBlockY(), explosionLocation.getBlockZ()); | ||
| boolean explodingOnCraft = CraftManager.getInstance().getCraftsInWorld(explosionLocation.getWorld()).stream().anyMatch(it -> it.getHitBox().contains(movecraftLocation)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an inefficient method to do a check like this, please use the utility functions in
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't find any good function there that might help me in my case, maybe there is something useful in MathUtils |
||
|
|
||
| e.setCancelled(!explodingOnCraft); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.