示例#1
0
	@SuppressWarnings("deprecation")
	public void restoreState() {
		if (state == null) {
			return;
		}
		
		bukkitPlayer.getInventory().setContents(state.getContents());
		bukkitPlayer.getInventory().setHelmet(state.getHelmet());
		bukkitPlayer.getInventory().setChestplate(state.getChestplate());
		bukkitPlayer.getInventory().setLeggings(state.getLeggings());
		bukkitPlayer.getInventory().setBoots(state.getBoots());
		
		bukkitPlayer.setExhaustion(state.getExhaustion());
		bukkitPlayer.setSaturation(state.getSaturation());
		
		bukkitPlayer.setFoodLevel(state.getFoodLevel());
		bukkitPlayer.setHealth(state.getHealth());
		
		bukkitPlayer.addPotionEffects(state.getPotioneffects());
		
		bukkitPlayer.setLevel(state.getLevel());
		bukkitPlayer.setExp(state.getExp());
		bukkitPlayer.setAllowFlight(state.isFly());
		
		sendMessage(I18N._("stateRestored"));
		bukkitPlayer.updateInventory();
		state = null;
	}
示例#2
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);
	}
示例#3
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);
	}
	@Override
	public void onPlace(SignChangeEvent e) {
		e.getPlayer().sendMessage(I18N._("spleefSignCreated"));
		
		StringBuilder builder = new StringBuilder();
		if (e.getLine(1).startsWith("[")) {
			builder.append(ChatColor.DARK_GRAY + "[");
		}
		
		builder.append(ChatColor.DARK_RED).append(ChatColor.BOLD).append("Leave");
		
		if (e.getLine(1).endsWith("]")) {
			builder.append(ChatColor.DARK_GRAY + "]");
		}
		
		e.setLine(1, builder.toString());
	}
示例#5
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"));
	}
示例#6
0
	@SuppressWarnings("deprecation")
	public void saveState() {
		bukkitPlayer.setGameMode(GameMode.SURVIVAL);//Set to survival
		
		//Define player states variables
		ItemStack[] contents = bukkitPlayer.getInventory().getContents();
		
		ItemStack helmet = bukkitPlayer.getInventory().getHelmet();
		ItemStack chestplate = bukkitPlayer.getInventory().getChestplate();
		ItemStack leggings = bukkitPlayer.getInventory().getLeggings();
		ItemStack boots = bukkitPlayer.getInventory().getBoots();
		
		float exhaustion = bukkitPlayer.getExhaustion();
		float saturation = bukkitPlayer.getSaturation();
		
		int foodLevel = bukkitPlayer.getFoodLevel();
		double health = bukkitPlayer.getHealth();
		
		GameMode gm = bukkitPlayer.getGameMode();
		Collection<PotionEffect> potionEffects = bukkitPlayer.getActivePotionEffects();
		
		float exp = bukkitPlayer.getExp();
		int level = bukkitPlayer.getLevel();
		
		boolean fly = bukkitPlayer.getAllowFlight();
		
		//Save state
		state = new PlayerState(contents, helmet, chestplate, leggings, boots, exhaustion, saturation, foodLevel, health, gm, potionEffects, exp, level, fly);
		
		//Set to default state
		bukkitPlayer.setFoodLevel(20);
		bukkitPlayer.setHealth(20.0);
		bukkitPlayer.setAllowFlight(false);//Disable fly mode (Essentials etc.)
		bukkitPlayer.setFireTicks(0);
		bukkitPlayer.getInventory().clear();
		bukkitPlayer.getInventory().setArmorContents(new ItemStack[4]);
		bukkitPlayer.setLevel(0);
		bukkitPlayer.setExp(0);
		
		for (PotionEffect effect : bukkitPlayer.getActivePotionEffects()) {
			bukkitPlayer.removePotionEffect(effect.getType());
		}
		
		bukkitPlayer.sendMessage(I18N._("stateSaved"));
		bukkitPlayer.updateInventory();
	}
示例#7
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"));
		}
	}
示例#8
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"));
	}