use of com.leomelonseeds.missilewars.arenas.Arena in project MissileWars by Leomelonseeds.
the class CustomItemListener method useUtility.
/**
* Handle utilities utilization.
*/
@EventHandler
public void useUtility(PlayerInteractEvent event) {
// Check if player is trying to place a utility item
Player player = event.getPlayer();
Arena playerArena = getPlayerArena(player);
if (playerArena == null) {
return;
}
ItemStack hand = getItemUsed(player);
// Handle splash potion through other methods
if (hand.getType() == Material.SPLASH_POTION) {
return;
}
String utility = getUtilityFromItem(hand);
if (utility == null) {
return;
}
// Make sure we allow gear items to be used
if (utility.contains("bow") || utility.contains("sword") || utility.contains("pickaxe")) {
return;
}
// Stop if not left-click
if (!event.getAction().toString().contains("RIGHT_CLICK")) {
return;
}
if (event.getAction().toString().contains("RIGHT_CLICK_BLOCK")) {
List<String> cancel = MissileWarsPlugin.getPlugin().getConfig().getStringList("cancel-schematic");
for (String s : cancel) {
if (event.getClickedBlock().getType() == Material.getMaterial(s)) {
event.setCancelled(true);
ConfigUtils.sendConfigMessage("messages.cannot-place-structure", player, null, null);
return;
}
}
if (utility.contains("creeper")) {
Location spawnLoc = event.getClickedBlock().getRelative(event.getBlockFace()).getLocation();
Creeper creeper = (Creeper) spawnLoc.getWorld().spawnEntity(spawnLoc.toCenterLocation().add(0, -0.5, 0), EntityType.CREEPER);
if (utility.contains("charged")) {
creeper.setPowered(true);
}
hand.setAmount(hand.getAmount() - 1);
event.setCancelled(true);
return;
}
}
// Do proper action based on utility type
if (utility.equalsIgnoreCase("fireball")) {
event.setCancelled(true);
Fireball fireball = (Fireball) player.getWorld().spawnEntity(player.getEyeLocation().clone().add(player.getEyeLocation().getDirection()), EntityType.FIREBALL);
fireball.setYield(2);
fireball.setIsIncendiary(true);
fireball.setDirection(player.getEyeLocation().getDirection());
fireball.setShooter(player);
hand.setAmount(hand.getAmount() - 1);
for (Player players : player.getWorld().getPlayers()) {
ConfigUtils.sendConfigSound("spawn-fireball", players, player.getLocation());
}
playerArena.getPlayerInArena(player.getUniqueId()).incrementUtility();
} else if (utility.equalsIgnoreCase("canopy")) {
event.setCancelled(true);
if (canopy_cooldown.contains(player.getUniqueId())) {
return;
}
if (!player.isOnGround()) {
ConfigUtils.sendConfigMessage("messages.canopy-fail", player, null, null);
return;
}
ConfigUtils.sendConfigMessage("messages.canopy-activate", player, null, null);
canopy_cooldown.add(player.getUniqueId());
spawnCanopy(player, playerArena);
}
}
use of com.leomelonseeds.missilewars.arenas.Arena in project MissileWars by Leomelonseeds.
the class JoinLeaveListener method onQuit.
/**
* Remove player from Arena if they DC.
*/
@EventHandler
public void onQuit(PlayerQuitEvent event) {
// Save player deck configuration
Player player = event.getPlayer();
MissileWarsPlugin.getPlugin().getJSON().savePlayer(player.getUniqueId());
// Get Arena player is in and remove them
ArenaManager manager = MissileWarsPlugin.getPlugin().getArenaManager();
Arena playerArena = manager.getArena(player.getUniqueId());
if (playerArena == null) {
InventoryUtils.saveInventory(player, true);
return;
}
playerArena.removePlayer(player.getUniqueId());
}
use of com.leomelonseeds.missilewars.arenas.Arena in project MissileWars by Leomelonseeds.
the class Deck method givePoolItem.
/**
* Give a random item from the pool to a given player if they have space.
*
* @param player the player to give the pool item too
*/
public void givePoolItem(Player player) {
// Ensure Deck has pool items
if (pool.isEmpty()) {
return;
}
double chance = 0.375;
List<ItemStack> toUse = rand.nextDouble() < chance ? utility : missiles;
ItemStack poolItem;
// Don't give players the same item twice
do {
poolItem = toUse.get(rand.nextInt(toUse.size()));
} while (lastTwo.contains(poolItem));
// Add item to the list
lastTwo.addFirst(poolItem);
if (lastTwo.size() > 2) {
lastTwo.removeLast();
}
Arena arena = MissileWarsPlugin.getPlugin().getArenaManager().getArena(player.getUniqueId());
double toohigh = ConfigUtils.getMapNumber(arena.getMapType(), arena.getMapName(), "too-high");
double toofar = ConfigUtils.getMapNumber(arena.getMapType(), arena.getMapName(), "too-far");
Location loc = player.getLocation();
// Don't give item if they are out of bounds
if (loc.getBlockY() > toohigh || loc.getBlockX() < toofar) {
refuseItem(player, poolItem, "messages.out-of-bounds");
return;
}
// Don't give item if their inventory space is full
if (!hasInventorySpace(player)) {
refuseItem(player, poolItem, "messages.inventory-limit");
return;
}
player.getInventory().addItem(poolItem);
}
use of com.leomelonseeds.missilewars.arenas.Arena in project MissileWars by Leomelonseeds.
the class ArenaGameruleListener method onPearl.
/**
* Make sure players can't teleport with ender pearls
*/
@EventHandler
public void onPearl(PlayerTeleportEvent event) {
// Ensure it's an ender pearl
if (event.getCause() != TeleportCause.ENDER_PEARL) {
return;
}
// Ensure it was in an arena world
String possibleArenaName = event.getPlayer().getWorld().getName().replace("mwarena_", "");
Arena possibleArena = MissileWarsPlugin.getPlugin().getArenaManager().getArena(possibleArenaName);
if (possibleArena == null) {
return;
}
event.setCancelled(true);
}
use of com.leomelonseeds.missilewars.arenas.Arena in project MissileWars by Leomelonseeds.
the class ArenaGameruleListener method onRespawn.
/**
* Just in case a player somehow respawns in the lobby
*/
@EventHandler
public void onRespawn(PlayerPostRespawnEvent event) {
Player player = event.getPlayer();
ArenaManager manager = MissileWarsPlugin.getPlugin().getArenaManager();
Arena playerArena = manager.getArena(player.getUniqueId());
if (playerArena != null && event.getRespawnedLocation().getWorld().getName().equals("world")) {
ConfigUtils.sendConfigMessage("messages.spawn-obstructed", player, null, null);
player.teleport(playerArena.getPlayerSpawn(player));
}
}
Aggregations