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


Java MinecraftConstants类代码示例

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


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

示例1: onPacket

import org.spacehq.mc.protocol.MinecraftConstants; //导入依赖的package包/类
public void onPacket(PacketReceivedEvent event) {
	// if the packet is a chat packet, handle it!
	if (event.getPacket() instanceof ClientChatPacket) {
		ClientChatPacket packet = event.getPacket();
		String message = packet.getMessage();

		GameProfile profile = event.getSession().getFlag(MinecraftConstants.PROFILE_KEY);
		System.out.println("<" + profile.getName() + "> " + packet.getMessage());

		// Check if it was a command or a chat message
		if (message.substring(0, 1).equals("/")) {
			NetherPlayer player = NetherServer.players.get(event.getSession());
			NetherServer.commandHandler.runCommand(player, message);
		} else {
			// let every other user on the server know that someone has just
			// chatted
			NetherServer.server.getSessions().forEach((session) -> session
					.send(new ServerChatPacket("<" + profile.getName() + "> " + packet.getMessage())));
		}
	}
}
 
开发者ID:netherrack,项目名称:netherrack,代码行数:22,代码来源:ChatHandler.java

示例2: onStatusRequest

import org.spacehq.mc.protocol.MinecraftConstants; //导入依赖的package包/类
@PacketHandler
public void onStatusRequest(PCSession session, StatusQueryPacket packet) {
    final List<Session> sessions = SpongeGame.instance.getServer().getNetwork().getSessions();
    final List<GameProfile> profiles = new ArrayList<>();

    sessions.stream().filter(activeSession -> activeSession.isConnected() && activeSession instanceof PCSession
            && ((PCSession) activeSession).getPacketProtocol()
            .getProtocolPhase() == ProtocolPhase.INGAME).forEach(activeSession -> profiles.add(activeSession.getFlag(MinecraftConstants.
            PROFILE_KEY)));

    final VersionInfo versionInfo = new VersionInfo("1.9.x", MinecraftConstants.PROTOCOL_VERSION);
    final PlayerInfo playerInfo = new PlayerInfo(SpongeGame.instance.getServer().getMaxPlayers(), profiles.size(), profiles.toArray(new
            GameProfile[profiles.size()]));
    final ServerStatusInfo info = new ServerStatusInfo(versionInfo, playerInfo,  new TextMessage(SpongeGame.instance.getConfiguration().getMotd
            ()), null);
    session.send(new StatusResponsePacket(info));
}
 
开发者ID:InspireNXE,项目名称:Pulse,代码行数:18,代码来源:StatusHandlers.java

示例3: onServerChat

import org.spacehq.mc.protocol.MinecraftConstants; //导入依赖的package包/类
@PacketHandler
public void onServerChat(PCSession session, ClientChatPacket packet) {
    final String mesaage = packet.getMessage();
    final GameProfile profile = session.getFlag(MinecraftConstants.PROFILE_KEY);
    boolean command = mesaage.startsWith("/");
    final String outgoing = "<" + profile.getName() + "> " + mesaage;
    if (!command) {
        for (Session activeSession : SpongeGame.instance.getServer().getNetwork().getSessions()) {
            activeSession.send(new ServerChatPacket(outgoing, MessageType.CHAT));
        }
    } else {
        session.send(new ServerChatPacket(outgoing, MessageType.CHAT));
    }

    if (command) {
        SpongeGame.logger.info("{} issued command: {}", profile.getName(), mesaage);
    } else {
        SpongeGame.logger.info(outgoing);
    }
}
 
开发者ID:InspireNXE,项目名称:Pulse,代码行数:21,代码来源:IngameHandlers.java

示例4: buildInfo

import org.spacehq.mc.protocol.MinecraftConstants; //导入依赖的package包/类
@Override
public ServerStatusInfo buildInfo(Session session) {
	return new ServerStatusInfo(
			new VersionInfo(MinecraftConstants.GAME_VERSION, MinecraftConstants.PROTOCOL_VERSION),
			new PlayerInfo(Integer.valueOf(MainMain.config.getProperty("max-players")), Integer.valueOf(MainMain.server.getSessions().size()), new GameProfile[0]), new TextMessage(MainMain.config.getProperty("motd"))
					.setStyle(new MessageStyle().setColor(ChatColor.RESET)),
			null);
}
 
开发者ID:MineGuard-dev,项目名称:TestServer_Java,代码行数:9,代码来源:PingHandler.java

示例5: onPacket

import org.spacehq.mc.protocol.MinecraftConstants; //导入依赖的package包/类
public void onPacket(PacketReceivedEvent event) {
	if (event.getPacket() instanceof ClientChatPacket) {
		ClientChatPacket packet = event.getPacket();
		GameProfile profile = event.getSession().getFlag(MinecraftConstants.PROFILE_KEY);
		System.out.println("<" + profile.getName() + "> " + packet.getMessage());
		MainMain.server.getSessions().forEach((session) -> session
				.send(new ServerChatPacket("<" + profile.getName() + "> " + packet.getMessage())));

	}
}
 
开发者ID:MineGuard-dev,项目名称:TestServer_Java,代码行数:11,代码来源:ChatHandler.java

示例6: onLogin

import org.spacehq.mc.protocol.MinecraftConstants; //导入依赖的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

示例7: buildInfo

import org.spacehq.mc.protocol.MinecraftConstants; //导入依赖的package包/类
@Override
public ServerStatusInfo buildInfo(Session session) {
	// a server status builder to respond to pings, TODO! make this
	// configureable
	return new ServerStatusInfo(
			new VersionInfo(MinecraftConstants.GAME_VERSION, MinecraftConstants.PROTOCOL_VERSION),
			new PlayerInfo(20, 0, new GameProfile[0]),
			new TextMessage(NetherServer.config.getProperty("motd")).setStyle(new MessageStyle().setColor(ChatColor.RESET)), null);
}
 
开发者ID:netherrack,项目名称:netherrack,代码行数:10,代码来源:PingHandler.java

示例8: Network

import org.spacehq.mc.protocol.MinecraftConstants; //导入依赖的package包/类
public Network(SpongeServer server) {
    super(SpongeGame.logger, "network", server.getGame().getConfiguration().getTickRate());
    this.server = server;

    this.listener = new Server(server.getGame().getConfiguration().getAddress(), server.getGame().getConfiguration().getPort(), PCProtocol.class,
            new PCSessionFactory());
    this.listener.setGlobalFlag(MinecraftConstants.AUTH_PROXY_KEY, AUTH_PROXY);
    this.listener.setGlobalFlag(MinecraftConstants.VERIFY_USERS_KEY, server.getGame().getConfiguration().isAuthenticateSessions());
    this.listener.setGlobalFlag(MinecraftConstants.SERVER_COMPRESSION_THRESHOLD, 100);
}
 
开发者ID:InspireNXE,项目名称:Pulse,代码行数:11,代码来源:Network.java

示例9: disconnected

import org.spacehq.mc.protocol.MinecraftConstants; //导入依赖的package包/类
@Override
public void disconnected(DisconnectedEvent event) {
    if (((PCSession) event.getSession()).getPacketProtocol().getProtocolPhase() == ProtocolPhase.INGAME) {
        final GameProfile profile = event.getSession().getFlag(MinecraftConstants.PROFILE_KEY);
        final String message = profile.getName() + " has left the game.";

        SpongeGame.logger.info(message);

        this.listener.getSessions().stream().filter(Session::isConnected).forEach(session -> {
            session.send(new ServerChatPacket(message, MessageType.SYSTEM));
        });
    }
}
 
开发者ID:InspireNXE,项目名称:Pulse,代码行数:14,代码来源:Network.java

示例10: run

import org.spacehq.mc.protocol.MinecraftConstants; //导入依赖的package包/类
@Override
public void run() {
    final String username = this.session.getFlag(SessionFlags.USERNAME);
    Proxy authProxy = this.session.getFlag(MinecraftConstants.AUTH_PROXY_KEY);
    if (authProxy == null) {
        authProxy = Proxy.NO_PROXY;
    }

    GameProfile profile;
    try {
        profile = (new SessionService(authProxy)).getProfileByServer(username, (new BigInteger(
                CryptUtil.getServerIdHash(this.serverId, this.keyPair.getPublic(), this.secretKey))).toString(16));
    } catch (RequestException ex) {
        this.session.disconnect("Failed to make session service request.", ex);
        return;
    }

    if (profile == null) {
        this.session.disconnect("Failed to verify username.");
        return;
    }

    if (this.session.hasFlag(MinecraftConstants.SERVER_COMPRESSION_THRESHOLD)) {
        final int compressionThreshold = this.session.getFlag(MinecraftConstants.SERVER_COMPRESSION_THRESHOLD);
        this.session.send(new LoginSetCompressionPacket(compressionThreshold));
        this.session.setCompressionThreshold(compressionThreshold);
    } else {
        this.session.setCompressionThreshold(-1);
    }
    this.session.send(new LoginSuccessPacket(profile));
    this.session.setFlag(MinecraftConstants.PROFILE_KEY, profile);
    ((PCProtocol)this.session.getPacketProtocol()).setProtocolPhase(ProtocolPhase.INGAME);
}
 
开发者ID:InspireNXE,项目名称:Pulse,代码行数:34,代码来源:SessionAuthenticatorThread.java

示例11: getProfile

import org.spacehq.mc.protocol.MinecraftConstants; //导入依赖的package包/类
public GameProfile getProfile() {
	return session.getFlag(MinecraftConstants.PROFILE_KEY);
}
 
开发者ID:MineGuard-dev,项目名称:TestServer_Java,代码行数:4,代码来源:ServerPlayer.java

示例12: getKey

import org.spacehq.mc.protocol.MinecraftConstants; //导入依赖的package包/类
private String getKey(Session session) {
	GameProfile profile = session.getFlag(MinecraftConstants.PROFILE_KEY);

	return profile.getName();
}
 
开发者ID:MineGuard-dev,项目名称:TestServer_Java,代码行数:6,代码来源:SessionMapping.java

示例13: onLogin

import org.spacehq.mc.protocol.MinecraftConstants; //导入依赖的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

示例14: getKey

import org.spacehq.mc.protocol.MinecraftConstants; //导入依赖的package包/类
private String getKey(Session session){
    GameProfile profile = session.getFlag(MinecraftConstants.PROFILE_KEY);
    
    return profile.getName();
}
 
开发者ID:netherrack,项目名称:netherrack,代码行数:6,代码来源:SessionMapping.java

示例15: onKeepAlive

import org.spacehq.mc.protocol.MinecraftConstants; //导入依赖的package包/类
@PacketHandler
public void onKeepAlive(PCSession session, ClientKeepAlivePacket packet) {
    if (packet.getPingId() == session.getLastPingId()) {
        session.setFlag(MinecraftConstants.PING_KEY, System.currentTimeMillis() - session.getLastPingTime());
    }
}
 
开发者ID:InspireNXE,项目名称:Pulse,代码行数:7,代码来源:IngameHandlers.java


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