예제 #1
0
	@EventHandler(priority = EventPriority.HIGHEST)
	public void onPlayerInteract(PlayerInteractEvent e) {
		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getPlayer());
		Block block = e.getClickedBlock();

		if (player == null)
			return;
		if (block == null)
			return;
		if (!player.isActive())
			return;
		if (e.getAction() != Action.LEFT_CLICK_BLOCK)
			return;

		Game game = player.getGame();
		if (!game.canSpleef(player, block.getLocation()))
			return;

		if (game.getFlag(FlagType.BOWSPLEEF) || game.getFlag(FlagType.SPLEGG))
			return;

		if (game.getFlag(FlagType.BLOCKBREAKEFFECT)) {
			block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType());
		}

		block.setType(Material.AIR);
		player.addBrokenBlock(block);
	}
예제 #2
0
	@EventHandler
	public void onEntitySpawn(CreatureSpawnEvent e) {
		for (Game game : GameManager.getGames()) {
			if (game.contains(e.getLocation())) {
				e.setCancelled(true);
				return;
			}
		}
	}
예제 #3
0
	@EventHandler
	public void onEntityExplode(EntityExplodeEvent e) {
		if (!HeavySpleef.getSystemConfig().getGeneralSection().isProtectArenas())
			return;

		for (Game game : GameManager.getGames()) {
			if (game.contains(e.getLocation())) {
				e.blockList().clear();
				return;
			}
		}
	}
예제 #4
0
	private void handleQuit(PlayerEvent e) {
		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getPlayer());

		QueuesManager.removeFromQueue(player);

		if (!player.isActive()) {
			return;
		}

		Game game = player.getGame();
		game.leave(player, LoseCause.QUIT);
	}
예제 #5
0
	// This event shouldn't be fired because player is in god mode
	// But we don't know if someone types /kill player while he's playing
	// spleef...
	@EventHandler
	public void onPlayerDeath(PlayerDeathEvent e) {
		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getEntity());

		if (player.isActive()) {

			Game game = player.getGame();
			game.leave(player, LoseCause.UNKNOWN);

			dead.add(player.getRawName());
		} else if (player.isSpectating()) {
			player.getGame().leaveSpectate(player);
		}
	}
	@Command(value = "removelose", minArgs = 2, onlyIngame = true)
	@CommandPermissions(value = { Permissions.REMOVE_LOSEZONE })
	@CommandHelp(usage = "/spleef removelose <game> <ID>", description = "Removes a losezone from a game")
	public void execute(Player player, Game game, Integer id) {
		if (game == null) {
			player.sendMessage(_("arenaDoesntExists"));
			return;
		}

		if (!game.getComponents().hasLoseZone(id)) {
			player.sendMessage(_("loseZoneWithIDDoesntExists"));
			return;
		}

		game.getComponents().removeLoseZone(id);
		player.sendMessage(_("loseZoneRemoved", String.valueOf(id)));
	}
예제 #7
0
	@Command(value = "spectate", minArgs = 1, onlyIngame = true)
	@CommandPermissions(value = { Permissions.SPECTATE })
	@CommandHelp(usage = "/spleef spectate <game>", description = "Spectates a game")
	public void execute(Player bukkitPlayer, Game game) {
		if (game == null) {
			bukkitPlayer.sendMessage(_("arenaDoesntExists"));
			return;
		}

		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(bukkitPlayer);

		if (game.getFlag(FlagType.SPECTATE) == null) {
			player.sendMessage(_("noSpectatePoint"));
			return;
		}

		game.spectate(player);
	}
예제 #8
0
	@EventHandler
	public void onBlockPlace(BlockPlaceEvent e) {
		for (Game game : GameManager.getGames()) {
			if (!game.contains(e.getBlock().getLocation())) {
				continue;
			}

			if (e.getPlayer().hasPermission(Permissions.BUILD_BYPASS.getPerm())) {
				return;
			}

			if (!HeavySpleef.getSystemConfig().getGeneralSection().isProtectArenas()) {
				return;
			}

			e.setCancelled(true);
			e.getPlayer().sendMessage(I18N._("notAllowedToBuild"));
		}
	}
예제 #9
0
	private String getFriendlyFlagInfo(Game game) {
		Map<Flag<?>, Object> flags = game.getFlags();
		String[] info = new String[flags.size()];
		
		int i = 0;
		for (Flag<?> flag : flags.keySet()) {
			info[i] = flag.toInfo(flags.get(flag));
			i++;
		}
		
		return Util.toFriendlyString(info, ", ");
	}
예제 #10
0
	@Command(value = "regenerate", minArgs = 1)
	@CommandPermissions(value = { Permissions.RESTORE_FLOORS })
	@CommandHelp(usage = "/spleef regenerate <game>", description = "Restores all floors of a game.")
	public void execute(CommandSender sender, Game game) {
		if (game == null) {
			sender.sendMessage(_("arenaDoesntExists"));
			return;
		}

		game.getComponents().regenerateFloors();
		sender.sendMessage(_("floorsRegenerated"));
	}
예제 #11
0
	@EventHandler
	public void onSpleggGunClick(PlayerInteractEvent e) {
		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getPlayer());

		if (player == null)
			return;
		if (e.getAction() != Action.RIGHT_CLICK_AIR && e.getAction() != Action.RIGHT_CLICK_BLOCK)
			return;
		if (!player.isActive())
			return;

		Game game = player.getGame();
		if (game.getGameState() != GameState.INGAME)
			return;
		if (!game.getFlag(FlagType.SPLEGG))
			return;
		if (player.getBukkitPlayer().getItemInHand().getType() != Material.DIAMOND_SPADE)
			return;

		// Launch egg
		player.getBukkitPlayer().launchProjectile(Egg.class);
		player.getBukkitPlayer().playSound(e.getPlayer().getLocation(), Sound.GHAST_FIREBALL, 0.4F, 2F);
	}
예제 #12
0
	@Command(value = "info", minArgs = 1)
	@CommandPermissions(value = {Permissions.INFO})
	@CommandHelp(usage = "/spleef info <game>", description = "Prints out information about this game")
	public void execute(CommandSender sender, Game game) {
		if (game == null) {
			sender.sendMessage(_("arenaDoesntExists"));
			return;
		}
		
		sender.sendMessage(ChatColor.YELLOW + "Name: " + game.getName() + ChatColor.GRAY + ", type: " + game.getType().name());
		if (game.getFlags().size() > 0) {
			sender.sendMessage(ChatColor.BLUE + "" + ChatColor.BOLD + "Flags: " + ChatColor.BLUE + getFriendlyFlagInfo(game));
		}
		
		sender.sendMessage(ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "Floors:");
		for (IFloor floor : game.getComponents().getFloors()) {
			sender.sendMessage(ChatColor.LIGHT_PURPLE + "# " + floor.asPlayerInfo());
		}
		
		sender.sendMessage(ChatColor.YELLOW + "" + ChatColor.BOLD + "Losezones:");
		for (LoseZone zone : game.getComponents().getLoseZones()) {
			sender.sendMessage(ChatColor.YELLOW + "# " + zone.asInfo());
		}
	}
예제 #13
0
	@EventHandler
	public void onBlockBreak(BlockBreakEvent e) {
		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getPlayer());
		Block block = e.getBlock();

		if (!player.isActive()) {
			for (Game game : GameManager.getGames()) {
				if (game.contains(block.getLocation())) {
					if (player.getBukkitPlayer().hasPermission(Permissions.BUILD_BYPASS.getPerm()))
						return;
					if (!HeavySpleef.getSystemConfig().getGeneralSection().isProtectArenas())
						return;

					e.setCancelled(true);
					fixBlockGlitch(player.getBukkitPlayer(), block);
					player.sendMessage(I18N._("notAllowedToBuild"));
					return;
				}
			}
			return;
		}

		Game game = player.getGame();

		if (!game.canSpleef(player, block.getLocation())) {
			e.setCancelled(true);
			fixBlockGlitch(player.getBukkitPlayer(), block);
			player.sendMessage(I18N._("notAllowedToBuild"));
			return;
		}

		if (game.getFlag(FlagType.BOWSPLEEF) || game.getFlag(FlagType.SPLEGG)) {
			e.setCancelled(true);
			return;
		}

		player.addBrokenBlock(block);
	}
예제 #14
0
	public boolean isSpectating() {
		return game != null && game.isSpectating(this);
	}
예제 #15
0
	public boolean isActive() {
		return game != null && game.hasPlayer(this);
	}
예제 #16
0
	public boolean isIngame() {
		return game != null && game.hasPlayer(this) && game.getGameState() == GameState.INGAME;
	}
예제 #17
0
	@EventHandler
	public void onProjectileHit(ProjectileHitEvent e) {
		if (!(e.getEntity() instanceof Arrow) && !(e.getEntity() instanceof Egg))
			return;

		Projectile projectile = e.getEntity();

		if (!(projectile.getShooter() instanceof Player))
			return;

		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(projectile.getShooter());

		if (!player.isActive())
			return;

		Game game = player.getGame();

		if (projectile instanceof Arrow) {
			Arrow arrow = (Arrow) projectile;

			if (!game.getFlag(FlagType.BOWSPLEEF))
				return;

			// Use BlockIterator to detect the hit block
			BlockIterator iterator = new BlockIterator(arrow.getWorld(), arrow.getLocation().toVector(), arrow.getVelocity().normalize(), 0, 4);
			Block hitBlock = null;

			while (iterator.hasNext()) {
				hitBlock = iterator.next();

				if (hitBlock.getType() != Material.AIR)
					break;
			}

			if (!game.canSpleef(player, hitBlock.getLocation()))
				return;

			World world = arrow.getWorld();

			if (hitBlock.getType() == Material.TNT) {
				return;
			}

			arrow.remove();

			player.addBrokenBlock(hitBlock);
			FallingBlock block = world.spawnFallingBlock(hitBlock.getLocation(), hitBlock.getType(), hitBlock.getData());
			block.setMetadata("bowspleef", new FixedMetadataValue(HeavySpleef.getInstance(), true));

			if (game.getFlag(FlagType.BLOCKBREAKEFFECT)) {
				world.playEffect(hitBlock.getLocation(), Effect.STEP_SOUND, hitBlock.getType());
			}
			hitBlock.setType(Material.AIR);
		} else if (projectile instanceof Egg) {
			Egg egg = (Egg) projectile;

			if (!game.getFlag(FlagType.SPLEGG))
				return;

			// Use BlockIterator to detect the hit block
			World world = egg.getWorld();
			BlockIterator iterator = new BlockIterator(egg.getWorld(), egg.getLocation().toVector(), egg.getVelocity().normalize(), 0, 4);

			egg.remove();
			Block hitBlock = null;

			while (iterator.hasNext()) {
				hitBlock = iterator.next();

				if (hitBlock.getType() != Material.AIR)
					break;
			}

			if (!game.canSpleef(player, hitBlock.getLocation()))
				return;

			player.addBrokenBlock(hitBlock);
			world.playSound(hitBlock.getLocation(), Sound.CHICKEN_EGG_POP, 0.7F, 1.0F);
			FuzzyReflection.playMobSpellEffect(hitBlock.getLocation().clone().add(0.5, 0.8, 0.5), 100, 0);
			hitBlock.setType(Material.AIR);
		}
	}