use of com.leomelonseeds.missilewars.arenas.Arena in project MissileWars by Leomelonseeds.
the class CustomItemListener method getPlayerArena.
/**
* Get the Arena the current player is in.
*
* @param player the player
* @return the Arena the player is in
*/
private Arena getPlayerArena(Player player) {
ArenaManager manager = MissileWarsPlugin.getPlugin().getArenaManager();
Arena arena = manager.getArena(player.getUniqueId());
return arena;
}
use of com.leomelonseeds.missilewars.arenas.Arena in project MissileWars by Leomelonseeds.
the class CustomItemListener method architectLeaves.
// Check for architect leaves to despawn them after a while
@EventHandler
public void architectLeaves(BlockPlaceEvent event) {
Player player = event.getPlayer();
Arena playerArena = getPlayerArena(player);
if ((playerArena == null) || !event.getItemInHand().getType().toString().contains("LEAVES")) {
return;
}
playerArena.addLeaf(event.getBlockPlaced().getLocation(), player);
}
use of com.leomelonseeds.missilewars.arenas.Arena in project MissileWars by Leomelonseeds.
the class CustomItemListener method handleUtilityCollisions.
/**
* Utility should go through players
*/
@EventHandler
public void handleUtilityCollisions(ProjectileHitEvent event) {
// Ensure we are tracking a utility thrown by a player
if (!(event.getEntity().getType() == EntityType.SNOWBALL || event.getEntity().getType() == EntityType.EGG || event.getEntity().getType() == EntityType.ENDER_PEARL)) {
return;
}
Projectile thrown = event.getEntity();
// If it has a custom name, it definitely is a missile wars item
if (!(thrown.getShooter() instanceof Player) || (thrown.getCustomName() == null)) {
return;
}
// Make sure it's in an arena
Player thrower = (Player) thrown.getShooter();
Arena playerArena = getPlayerArena(thrower);
if (playerArena == null) {
return;
}
// Make them go through entities
if (event.getHitEntity() != null) {
event.setCancelled(true);
return;
}
}
use of com.leomelonseeds.missilewars.arenas.Arena in project MissileWars by Leomelonseeds.
the class CustomItemListener method useStructureItem.
/**
* Handle missile and other structure item spawning.
*/
@EventHandler
public void useStructureItem(PlayerInteractEvent event) {
// Check if player is trying to place a structure item
MissileWarsPlugin plugin = MissileWarsPlugin.getPlugin();
Player player = event.getPlayer();
Arena playerArena = getPlayerArena(player);
if (playerArena == null) {
return;
}
ItemStack hand = getItemUsed(player);
Block clicked = event.getClickedBlock();
String structureName = getStructureFromItem(hand);
if (structureName == null) {
return;
}
// Switch to throwing logic if using a throwable
if (structureName.contains("shield_") || structureName.contains("platform_") || structureName.contains("torpedo_") || structureName.contains("obsidian_")) {
return;
}
// Stop if not left-click on block
if (!event.getAction().toString().contains("RIGHT") || clicked == null) {
return;
}
event.setCancelled(true);
List<String> cancel = plugin.getConfig().getStringList("cancel-schematic");
for (String s : cancel) {
if (clicked.getType() == Material.getMaterial(s)) {
ConfigUtils.sendConfigMessage("messages.cannot-place-structure", player, null, null);
return;
}
}
// Place structure
String mapName = "default-map";
if (playerArena.getMapName() != null) {
mapName = playerArena.getMapName();
}
if (SchematicManager.spawnNBTStructure(structureName, clicked.getLocation(), isRedTeam(player), mapName)) {
hand.setAmount(hand.getAmount() - 1);
playerArena.getPlayerInArena(player.getUniqueId()).incrementMissiles();
} else {
ConfigUtils.sendConfigMessage("messages.cannot-place-structure", player, null, null);
}
}
use of com.leomelonseeds.missilewars.arenas.Arena in project MissileWars by Leomelonseeds.
the class JoinLeaveListener method onWorldChange.
/**
* Remove player from Arena if they leave the world.
*/
@EventHandler
public void onWorldChange(PlayerChangedWorldEvent event) {
Player player = event.getPlayer();
if (event.getFrom().getName().contains("mwarena")) {
ArenaManager manager = MissileWarsPlugin.getPlugin().getArenaManager();
Arena playerArena = manager.getArena(player.getUniqueId());
if (playerArena == null || player.getWorld().equals(playerArena.getWorld())) {
return;
}
// Check 1 tick later to make 100% sure
Bukkit.getScheduler().runTaskLater(MissileWarsPlugin.getPlugin(), () -> {
if (player.getWorld().getName().equals("world")) {
playerArena.removePlayer(player.getUniqueId());
}
}, 1);
}
}
Aggregations