当前位置: 首页>>代码示例>>Java>>正文


Java PlayerListEntry类代码示例

本文整理汇总了Java中org.spacehq.mc.protocol.data.game.PlayerListEntry的典型用法代码示例。如果您正苦于以下问题:Java PlayerListEntry类的具体用法?Java PlayerListEntry怎么用?Java PlayerListEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PlayerListEntry类属于org.spacehq.mc.protocol.data.game包,在下文中一共展示了PlayerListEntry类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onLogout

import org.spacehq.mc.protocol.data.game.PlayerListEntry; //导入依赖的package包/类
public void onLogout(ServerPlayer outPlayer) {
	MessageStyle logoutStyle = new MessageStyle().setColor(ChatColor.YELLOW);
	TextMessage logoutMessage = (TextMessage) new TextMessage(outPlayer.getName() + " has left the game")
			.setStyle(logoutStyle);

	MainMain.players.forEach((player) -> {
		player.sendMessage(logoutMessage);
	});
	MainMain.players.forEach((otherPlayer) -> {
		PlayerListEntry[] newPlayerListing = new PlayerListEntry[1];
		newPlayerListing[0] = new PlayerListEntry(outPlayer.getProfile(), GameMode.CREATIVE, 1,
				new TextMessage(otherPlayer.getName()));
		otherPlayer
				.sendPacket(new ServerPlayerListEntryPacket(PlayerListEntryAction.REMOVE_PLAYER, newPlayerListing));
	});
	outPlayer.setWorld(null);
	MainMain.players.remove(outPlayer.getSession());
}
 
开发者ID:MineGuard-dev,项目名称:TestServer_Java,代码行数:19,代码来源:LogoutHandler.java

示例2: onLogout

import org.spacehq.mc.protocol.data.game.PlayerListEntry; //导入依赖的package包/类
public void onLogout(NetherPlayer outPlayer) {
       // Send logout message to other players
       
       MessageStyle logoutStyle = new MessageStyle().setColor(ChatColor.YELLOW);
       TextMessage logoutMessage = (TextMessage) new TextMessage(outPlayer.getName() + " has left the game")
                                                                   .setStyle(logoutStyle);
       
       NetherServer.players.forEach((player) -> {
           player.sendMessage(logoutMessage);
       });
       
       // Remove the player from the other player's listing.
       NetherServer.players.forEach((otherPlayer) -> {
           PlayerListEntry[] newPlayerListing = new PlayerListEntry[1];
           
           newPlayerListing[0] = new PlayerListEntry(outPlayer.getProfile(), GameMode.CREATIVE, 1, new TextMessage(otherPlayer.getName()));
           
           otherPlayer.sendPacket(new ServerPlayerListEntryPacket(PlayerListEntryAction.REMOVE_PLAYER, newPlayerListing));
       });
       
       // Remove the player entity
       outPlayer.setWorld(null);
        NetherServer.players.remove(outPlayer.getSession());
}
 
开发者ID:netherrack,项目名称:netherrack,代码行数:25,代码来源:LogoutHandler.java

示例3: onLogin

import org.spacehq.mc.protocol.data.game.PlayerListEntry; //导入依赖的package包/类
public void onLogin(Session session) {
	ServerPlayer newPlayer = new ServerPlayer(session);
	MainMain.players.put(session, newPlayer);
	newPlayer.setWorld(MainMain.defaultWorld);
	session.send(new ServerJoinGamePacket((int) newPlayer.getUEID(), false, GameMode.CREATIVE,
			newPlayer.getWorld().getDimension().toInt(), Difficulty.PEACEFUL, 10, WorldType.DEFAULT, false));

	List<PlayerListEntry> playerList = new ArrayList<PlayerListEntry>();

	MainMain.players.forEach((otherPlayer) -> {
		playerList.add(new PlayerListEntry(otherPlayer.getProfile(), GameMode.CREATIVE, 1,
				new TextMessage(otherPlayer.getName())));
	});

	PlayerListEntry[] playerListPck = new PlayerListEntry[playerList.size()];
	playerList.toArray(playerListPck);

	session.send(new ServerPlayerListEntryPacket(PlayerListEntryAction.ADD_PLAYER, playerListPck));
	MainMain.players.forEach((otherPlayer) -> {
		if (otherPlayer == newPlayer)
			return;
		PlayerListEntry[] newPlayerListing = new PlayerListEntry[1];

		newPlayerListing[0] = new PlayerListEntry(newPlayer.getProfile(), GameMode.CREATIVE, 1,
				new TextMessage(newPlayer.getName()));

		otherPlayer.sendPacket(new ServerPlayerListEntryPacket(PlayerListEntryAction.ADD_PLAYER, newPlayerListing));
	});
	session.send(new ServerPlayerPositionRotationPacket(0, 120, 0, 0, 0, 0));
	MinecraftProtocol protocol = (MinecraftProtocol) session.getPacketProtocol();
	if (protocol.getSubProtocol() == SubProtocol.GAME) {
		GameProfile profile = session.getFlag(MinecraftConstants.PROFILE_KEY);
		logger.info(profile.getName() + " has joined the game");
		MainMain.server.getSessions()
				.forEach((sessions) -> sessions
						.send(new ServerChatPacket(new TextMessage(profile.getName() + " has joined the game")
								.setStyle(new MessageStyle().setColor(ChatColor.YELLOW)))));
	}
}
 
开发者ID:MineGuard-dev,项目名称:TestServer_Java,代码行数:40,代码来源:LoginHandler.java

示例4: onLogin

import org.spacehq.mc.protocol.data.game.PlayerListEntry; //导入依赖的package包/类
public void onLogin(Session session) {
	NetherPlayer newPlayer = new NetherPlayer(session);

	NetherServer.players.put(session, newPlayer);

	// spawn the player in the world
	newPlayer.setWorld(NetherServer.defaultWorld);

	// send the join game packet
	session.send(new ServerJoinGamePacket((int) newPlayer.getUEID(),
			false, // Hardcore
			GameMode.CREATIVE, // Player gamemode
			newPlayer.getWorld().getDimension().toInt(), // Dimension (-1, 0, 1)
			Difficulty.PEACEFUL, // Difficulty
			10, // Max players
			WorldType.DEFAULT, 
			false // Less debug info
	));
       
       // Send the logging in player the player list
       
       List<PlayerListEntry> playerList = new ArrayList<PlayerListEntry>();
       
       NetherServer.players.forEach((otherPlayer) -> {
           playerList.add(new PlayerListEntry(
                           otherPlayer.getProfile(),
                           GameMode.CREATIVE,        //TODO: game mode
                           1,                        //TODO: ping
                           new TextMessage(otherPlayer.getName())
           ));
       });
       
       PlayerListEntry[] playerListPck = new PlayerListEntry[playerList.size()];
       playerList.toArray(playerListPck);
       
       session.send(new ServerPlayerListEntryPacket(
           PlayerListEntryAction.ADD_PLAYER,
           playerListPck
       ));
       
       // Send the other players the new player listing.
       
       NetherServer.players.forEach((otherPlayer) -> {
           if(otherPlayer == newPlayer) return;
           
           PlayerListEntry[] newPlayerListing = new PlayerListEntry[1];
           
           newPlayerListing[0] = new PlayerListEntry(newPlayer.getProfile(), GameMode.CREATIVE, 1, new TextMessage(newPlayer.getName()));
           
           otherPlayer.sendPacket(new ServerPlayerListEntryPacket(PlayerListEntryAction.ADD_PLAYER, newPlayerListing));
       });

	// send the player position packet to get the player to spawn
	session.send(new ServerPlayerPositionRotationPacket(0, 81.62, 0, 0, 0, 0));

	// send a message to the console and to all players that a new person
	// has joined the game
	MinecraftProtocol protocol = (MinecraftProtocol) session.getPacketProtocol();
	if (protocol.getSubProtocol() == SubProtocol.GAME) {
		GameProfile profile = session.getFlag(MinecraftConstants.PROFILE_KEY);
		logger.info(profile.getName() + " has joined the game");
		NetherServer.server.getSessions()
				.forEach((sessions) -> sessions
						.send(new ServerChatPacket(new TextMessage(profile.getName() + " has joined the game")
								.setStyle(new MessageStyle().setColor(ChatColor.YELLOW)))));
	}
}
 
开发者ID:netherrack,项目名称:netherrack,代码行数:68,代码来源:LoginHandler.java


注:本文中的org.spacehq.mc.protocol.data.game.PlayerListEntry类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。