forked from alkarinv/ArenaSpleef
-
Notifications
You must be signed in to change notification settings - Fork 5
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
20 changed files
with
551 additions
and
120 deletions.
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
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
81 changes: 0 additions & 81 deletions
81
src/main/java/org/battleplugins/arena/spleef/SpleefArena.java
This file was deleted.
Oops, something went wrong.
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
99 changes: 99 additions & 0 deletions
99
src/main/java/org/battleplugins/arena/spleef/SpleefEventResolvers.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,99 @@ | ||
package org.battleplugins.arena.spleef; | ||
|
||
import com.destroystokyo.paper.event.entity.ThrownEggHatchEvent; | ||
import org.battleplugins.arena.ArenaPlayer; | ||
import org.battleplugins.arena.BattleArena; | ||
import org.battleplugins.arena.competition.Competition; | ||
import org.battleplugins.arena.competition.LiveCompetition; | ||
import org.battleplugins.arena.event.ArenaEventHandler; | ||
import org.battleplugins.arena.spleef.arena.SpleefArena; | ||
import org.battleplugins.arena.spleef.arena.SpleefCompetition; | ||
import org.battleplugins.arena.spleef.arena.SpleefGame; | ||
import org.bukkit.entity.Egg; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.block.TNTPrimeEvent; | ||
import org.bukkit.event.entity.ProjectileHitEvent; | ||
import org.bukkit.projectiles.ProjectileSource; | ||
|
||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* Contains custom event resolvers for Spleef events. | ||
* <p> | ||
* The events below would normally not be captured by the | ||
* {@link ArenaEventHandler} annotation since there is no default | ||
* logic for them to link back to a {@link Competition}. However, | ||
* these custom resolvers allow for these events to be listened | ||
* on, along with segmenting the logic to the appropriate arena | ||
* and spleef game mode. | ||
*/ | ||
public final class SpleefEventResolvers { | ||
|
||
public static final Function<ProjectileHitEvent, LiveCompetition<?>> PROJECTILE_HIT = event -> { | ||
if (!(event.getEntity() instanceof Egg egg)) { | ||
return null; | ||
} | ||
|
||
if (event.getHitBlock() == null) { | ||
return null; | ||
} | ||
|
||
if (!egg.hasMetadata("splegg")) { | ||
return null; | ||
} | ||
|
||
ProjectileSource shooter = egg.getShooter(); | ||
if (!(shooter instanceof Player player)) { | ||
return null; | ||
} | ||
|
||
ArenaPlayer arenaPlayer = ArenaPlayer.getArenaPlayer(player); | ||
if (arenaPlayer == null || !(arenaPlayer.getArena() instanceof SpleefArena)) { | ||
return null; | ||
} | ||
|
||
return arenaPlayer.getCompetition(); | ||
}; | ||
|
||
public static final Function<ThrownEggHatchEvent, LiveCompetition<?>> THROWN_EGG_HATCH = event -> { | ||
if (!event.getEgg().hasMetadata("splegg")) { | ||
return null; | ||
} | ||
|
||
ProjectileSource shooter = event.getEgg().getShooter(); | ||
if (!(shooter instanceof Player player)) { | ||
return null; | ||
} | ||
|
||
ArenaPlayer arenaPlayer = ArenaPlayer.getArenaPlayer(player); | ||
if (arenaPlayer == null || !(arenaPlayer.getArena() instanceof SpleefArena)) { | ||
return null; | ||
} | ||
|
||
return arenaPlayer.getCompetition(); | ||
}; | ||
|
||
public static final Function<SpleefArena, Function<TNTPrimeEvent, LiveCompetition<?>>> TNT_PRIME = arena -> event -> { | ||
if (arena.getGame() != SpleefGame.BOW_SPLEEF) { | ||
return null; | ||
} | ||
|
||
List<Competition<?>> competitions = BattleArena.getInstance().getCompetitions(arena); | ||
for (Competition<?> competition : competitions) { | ||
if (!(competition instanceof SpleefCompetition spleefCompetition)) { | ||
continue; | ||
} | ||
|
||
if (!spleefCompetition.getMap().getWorld().equals(event.getBlock().getWorld())) { | ||
continue; | ||
} | ||
|
||
if (spleefCompetition.getMap().getBounds() != null && spleefCompetition.getMap().getBounds().isInside(event.getBlock().getLocation())) { | ||
return spleefCompetition; | ||
} | ||
} | ||
|
||
return null; | ||
}; | ||
} |
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
40 changes: 40 additions & 0 deletions
40
src/main/java/org/battleplugins/arena/spleef/SpleefUtil.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,40 @@ | ||
package org.battleplugins.arena.spleef; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.util.NumberConversions; | ||
|
||
public final class SpleefUtil { | ||
|
||
public static Block getBlockUnderPlayer(int y, Location location) { | ||
Location loc = location.clone(); | ||
loc.setY(y); | ||
|
||
double boxWidth = 0.3; | ||
Block block1 = getBlock(loc, +boxWidth, -boxWidth); | ||
if (!block1.getType().isAir()) { | ||
return block1; | ||
} | ||
|
||
Block block2 = getBlock(loc, -boxWidth, +boxWidth); | ||
if (!block2.getType().isAir()) { | ||
return block2; | ||
} | ||
|
||
Block block3 = getBlock(loc, +boxWidth, +boxWidth); | ||
if (!block3.getType().isAir()) { | ||
return block3; | ||
} | ||
|
||
Block block4 = getBlock(loc, -boxWidth, -boxWidth); | ||
if (!block4.getType().isAir()) { | ||
return block4; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private static Block getBlock(Location loc, double x, double z) { | ||
return loc.getWorld().getBlockAt(NumberConversions.floor(loc.getX() + x), loc.getBlockY(), NumberConversions.floor(loc.getZ() + z)); | ||
} | ||
} |
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
3 changes: 2 additions & 1 deletion
3
...ugins/arena/spleef/PasteLayersAction.java → ...rena/spleef/action/PasteLayersAction.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
Oops, something went wrong.