forked from alkarinv/BattleArena
-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
Showing
4 changed files
with
85 additions
and
9 deletions.
There are no files selected for viewing
Empty file.
71 changes: 71 additions & 0 deletions
71
...one-in-the-chamber/src/main/java/org/battleplugins/arena/module/oitc/OneInTheChamber.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,71 @@ | ||
package org.battleplugins.arena.module.oitc; | ||
|
||
import org.battleplugins.arena.ArenaPlayer; | ||
import org.battleplugins.arena.event.ArenaEventHandler; | ||
import org.battleplugins.arena.event.ArenaListener; | ||
import org.battleplugins.arena.event.arena.ArenaInitializeEvent; | ||
import org.battleplugins.arena.event.player.ArenaKillEvent; | ||
import org.battleplugins.arena.module.ArenaModule; | ||
import org.battleplugins.arena.module.ArenaModuleInitializer; | ||
import org.bukkit.Material; | ||
import org.bukkit.entity.AbstractArrow; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.entity.EntityDamageByEntityEvent; | ||
import org.bukkit.event.entity.ProjectileHitEvent; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
/** | ||
* A module that adds one in the chamber to BattleArena. | ||
*/ | ||
@ArenaModule(id = OneInTheChamber.ID, name = "One in the Chamber", description = "Adds One in the Chamber to BattleArena.", authors = "BattlePlugins") | ||
public class OneInTheChamber implements ArenaModuleInitializer, ArenaListener { | ||
public static final String ID = "one-in-the-chamber"; | ||
|
||
@EventHandler | ||
public void onArenaInitialize(ArenaInitializeEvent event) { | ||
if (!event.getArena().isModuleEnabled(ID)) { | ||
return; | ||
} | ||
|
||
event.getArena().getEventManager().registerArenaResolver(ProjectileHitEvent.class, hitEvent -> { | ||
if (!(hitEvent.getEntity() instanceof AbstractArrow arrow && arrow.getShooter() instanceof Player player)) { | ||
return null; | ||
} | ||
|
||
return ArenaPlayer.arenaPlayer(player) | ||
.map(ArenaPlayer::getCompetition) | ||
.orElse(null); | ||
}); | ||
|
||
event.getArena().getEventManager().registerEvents(this); | ||
} | ||
|
||
@ArenaEventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { | ||
if (!(event.getDamager() instanceof AbstractArrow arrow && arrow.getShooter() instanceof Player shooter)) { | ||
return; | ||
} | ||
|
||
if (!(event.getEntity() instanceof Player victim)) { | ||
return; | ||
} | ||
|
||
event.setCancelled(true); | ||
|
||
victim.damage(10000, shooter); | ||
} | ||
|
||
@ArenaEventHandler | ||
public void onKill(ArenaKillEvent event) { | ||
event.getKiller().getPlayer().getInventory().addItem(new ItemStack(Material.ARROW)); | ||
} | ||
|
||
@ArenaEventHandler | ||
public void onProjectileHit(ProjectileHitEvent event) { | ||
if (event.getEntity() instanceof AbstractArrow arrow) { | ||
arrow.remove(); | ||
} | ||
} | ||
} |
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
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