Exemplo n.º 1
0
	/**
	 * Used to cancel the land of falling blocks in bowspleef games
	 */
	@EventHandler
	public void onEntityChangeBlock(EntityChangeBlockEvent e) {
		if (!(e.getEntity() instanceof FallingBlock)) {
			return;
		}

		boolean bowspleefEntity = false;

		List<MetadataValue> metadatas = e.getEntity().getMetadata("bowspleef");
		for (MetadataValue metadata : metadatas) {
			if (metadata.getOwningPlugin() != HeavySpleef.getInstance())
				continue;

			if (metadata.asBoolean()) {
				bowspleefEntity = true;
				break;
			}
		}

		if (!bowspleefEntity) {
			return;
		}

		e.setCancelled(true);
		e.getEntity().remove();
	}
Exemplo n.º 2
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);
	}
Exemplo n.º 3
0
	@EventHandler
	public void onCommand(PlayerCommandPreprocessEvent e) {
		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getPlayer());

		if (player == null)
			return;
		if (!QueuesManager.hasQueue(player))
			return;
		if (HeavySpleef.getSystemConfig().getQueuesSection().isAllowCommands())
			return;

		if (e.getMessage().equalsIgnoreCase("/spleef leave") || e.getMessage().equalsIgnoreCase("/spl leave"))
			return;

		e.setCancelled(true);
		player.sendMessage(I18N._("noCommandsInQueue"));
	}
Exemplo n.º 4
0
	@EventHandler
	public void onItemDrop(PlayerDropItemEvent e) {
		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getPlayer());

		if (!player.isActive())
			return;

		e.setCancelled(true);
	}
Exemplo n.º 5
0
	@Override
	public void execute(CommandSender sender, String[] args) {
		Player player = (Player)sender;
		if (GameManager.hasGame(args[0].toLowerCase())) {
			player.sendMessage(_("arenaAlreadyExists"));
			return;
		}
		
		if (args[1].equalsIgnoreCase("cylinder") || args[1].equalsIgnoreCase("cyl")) {
			//Create a new cylinder game
			if (args.length < 4) {
				player.sendMessage(getUsage());
				return;
			}
			
			try {
				int radius = Integer.parseInt(args[2]);
				int height = Integer.parseInt(args[3]);
				
				Location center = player.getLocation();
				
				int minY = center.getBlockY();
				int maxY = center.getBlockY() + height;
				
				RegionCylinder region = new RegionCylinder(-1, center, radius, minY, maxY);
				Game game = new GameCylinder(args[0], region);
				GameManager.addGame(game);
			} catch (NumberFormatException e) {
				player.sendMessage(_("notANumber", args[2]));
				return;
			}
			
			player.sendMessage(_("gameCreated"));
		} else if (args[1].equalsIgnoreCase("cuboid") || args[1].equalsIgnoreCase("cub")) {
			//Create a new cuboid game
			Selection s = HeavySpleef.getInstance().getSelectionManager().getSelection(player);
			if (!s.hasSelection()) {
				player.sendMessage(_("needSelection"));
				return;
			}
			if (s.isTroughWorlds()) {
				player.sendMessage(_("selectionCantTroughWorlds"));
				return;
			}
			
			RegionCuboid region = new RegionCuboid(-1, s.getFirst(), s.getSecond());
			Game game = new GameCuboid(args[0], region);
			
			GameManager.addGame(game);
			player.sendMessage(_("gameCreated"));
		} else {
			player.sendMessage(_("unknownSpleefType"));
		}
	}
Exemplo n.º 6
0
	private void handleQuit(PlayerEvent e) {
		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getPlayer());

		if (player == null)
			return;
		if (!QueuesManager.hasQueue(player))
			return;

		// Remove the player from the queue if he quits
		QueuesManager.removeFromQueue(player);
	}
Exemplo n.º 7
0
	@EventHandler
	public void onEntityDamage(EntityDamageEvent e) {
		if (!(e.getEntity() instanceof Player))
			return;

		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getEntity());

		if (player.isActive()) {
			e.setCancelled(true);
		}
	}
Exemplo n.º 8
0
	public String getName() {
		String name = getRawName();
		
		if (bukkitPlayer.hasPermission(Permissions.VIP.getPerm())) {
			name = HeavySpleef.getSystemConfig().getGeneralSection().getVipPrefix() + name;
		} else if (getRawName().equalsIgnoreCase("matzefratze123")) {
			name = ChatColor.DARK_RED + name;
		}
		
		return name;
	}
Exemplo n.º 9
0
	@EventHandler
	public void onPlayerRespawn(PlayerRespawnEvent e) {
		final SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getPlayer());

		if (!dead.contains(player.getRawName()))
			return;

		// Player died while spleefing, restore his inventory
		Bukkit.getScheduler().scheduleSyncDelayedTask(HeavySpleef.getInstance(), new Runnable() {

			@Override
			public void run() {
				if (player.getBukkitPlayer().isOnline()) {
					player.restoreState();
				}
			}
		}, 10L);

		dead.remove(player.getRawName());
	}
Exemplo n.º 10
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);
	}
Exemplo n.º 11
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;
			}
		}
	}
Exemplo n.º 12
0
	@EventHandler
	public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getPlayer());

		if (!player.isActive() && !player.isSpectating())
			return;
		if (e.getPlayer().hasPermission(Permissions.COMMAND_WHITELISTED.getPerm()))
			return;

		String[] split = e.getMessage().split(" ");
		String cmd = split[0];
		if (cmd.equalsIgnoreCase("/spleef") || cmd.equalsIgnoreCase("/hs") || cmd.equalsIgnoreCase("/hspleef"))
			return;
		List<String> whitelist = HeavySpleef.getSystemConfig().getGeneralSection().getCommandWhitelist();
		for (String c : whitelist) {
			if (c.equalsIgnoreCase(cmd))
				return;
		}
		e.setCancelled(true);
		e.getPlayer().sendMessage(I18N._("cantUseCommands"));
	}
Exemplo n.º 13
0
	@EventHandler
	public void onFoodChange(FoodLevelChangeEvent e) {
		if (!(e.getEntity() instanceof Player)) {
			return;
		}

		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getEntity());

		if (player.isActive()) {
			e.setFoodLevel(20);
		}
	}
Exemplo n.º 14
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);
	}
Exemplo n.º 15
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);
		}
	}
Exemplo n.º 16
0
	@EventHandler(priority = EventPriority.HIGH)
	public void onGamemodeChange(PlayerGameModeChangeEvent e) {
		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(e.getPlayer());

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

		if (e.getNewGameMode() == GameMode.SURVIVAL) {
			return;
		}

		player.sendMessage(I18N._("cantChangeGamemode"));
		e.setCancelled(true);
	}
Exemplo n.º 17
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);
	}
Exemplo n.º 18
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"));
		}
	}
Exemplo n.º 19
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);
	}
Exemplo n.º 20
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);
		}
	}