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


Java PacketType类代码示例

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


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

示例1: listenPackets

import com.comphenix.protocol.PacketType; //导入依赖的package包/类
public static void listenPackets() {
    ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(DynamicAC.instance, ListenerPriority.NORMAL, PacketType.Play.Client.POSITION, PacketType.Play.Client.POSITION_LOOK) {
        @Override
        public void onPacketReceiving(PacketEvent e) {
            Player p = e.getPlayer();
            Location cur = e.getPlayer().getLocation();
            if(!MOVE_COUNT.containsKey(p)) {
                MOVE_COUNT.put(p, 1);
            } else {
                MOVE_COUNT.put(p, MOVE_COUNT.get(p) + 1);
                if(MOVE_COUNT.get(p) > MagicNumbers.BLINK_PACKET)  {
                    for(Player player : DynamicAC.instance.onlinestaff) {
                        player.sendMessage(DynamicAC.prefix + p.getName() + " failed Blink test, sent too many " +
                                "packets in one place!");
                    }
                    MOVE_COUNT.remove(p);
                    e.setCancelled(true);
                    e.getPlayer().teleport(cur);
                }
            }
        }
    });
}
 
开发者ID:Notoh,项目名称:DynamicAC,代码行数:24,代码来源:MovementListener.java

示例2: newObjectivePacket

import com.comphenix.protocol.PacketType; //导入依赖的package包/类
private PacketContainer newObjectivePacket(UpdateType mode) {
    // http://wiki.vg/Protocol#Scoreboard_Objective
    PacketContainer packet = new PacketContainer(PacketType.Play.Server.SCOREBOARD_OBJECTIVE);

    // set name - limited to String(16)
    packet.getStrings().write(0, getId());

    // set mode - 0 to create the scoreboard. 1 to remove the scoreboard. 2 to update the display text.
    packet.getIntegers().write(0, mode.getCode());

    // set display name - limited to String(16) - Only if mode is 0 or 2. The text to be displayed for the score
    packet.getStrings().write(1, getDisplayName());

    // set type - either "integer" or "hearts"
    packet.getEnumModifier(HealthDisplay.class, 2).write(0, HealthDisplay.INTEGER);

    return packet;
}
 
开发者ID:lucko,项目名称:helper,代码行数:19,代码来源:PacketScoreboardObjective.java

示例3: newScorePacket

import com.comphenix.protocol.PacketType; //导入依赖的package包/类
private PacketContainer newScorePacket(String name, int value, ScoreboardAction action) {
    // http://wiki.vg/Protocol#Update_Score
    PacketContainer packet = new PacketContainer(PacketType.Play.Server.SCOREBOARD_SCORE);

    // set "Entity name" - aka the name of the score - limited to 40.
    packet.getStrings().write(0, name);

    // set the action - 0 to create/update an item. 1 to remove an item.
    packet.getScoreboardActions().write(0, action);

    // set objective name - The name of the objective the score belongs to
    packet.getStrings().write(1, getId());

    // set value of the score- The score to be displayed next to the entry. Only sent when Action does not equal 1.
    packet.getIntegers().write(0, value);

    return packet;
}
 
开发者ID:lucko,项目名称:helper,代码行数:19,代码来源:PacketScoreboardObjective.java

示例4: newTeamMemberUpdatePacket

import com.comphenix.protocol.PacketType; //导入依赖的package包/类
private PacketContainer newTeamMemberUpdatePacket(String player, MemberAction action) {
    // http://wiki.vg/Protocol#Teams
    PacketContainer packet = new PacketContainer(PacketType.Play.Server.SCOREBOARD_TEAM);

    // set team name - 	String (16)
    packet.getStrings().write(0, getId());

    // set mode
    switch (action) {
        case ADD:
            packet.getIntegers().write(1, UpdateType.ADD_PLAYERS.getCode());
            break;
        case REMOVE:
            packet.getIntegers().write(1, UpdateType.REMOVE_PLAYERS.getCode());
            break;
        default:
            throw new RuntimeException();
    }

    // set players - Array of String (40)
    packet.getSpecificModifier(Collection.class).write(0, Collections.singletonList(player));
    
    return packet;
}
 
开发者ID:lucko,项目名称:helper,代码行数:25,代码来源:PacketScoreboardTeam.java

示例5: sendTabListAddPacket

import com.comphenix.protocol.PacketType; //导入依赖的package包/类
@Override
public void sendTabListAddPacket(Player playerToAdd, GameProfileWrapper newProfile, Player seer) {
    PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO);
    int ping = (int) ReflectUtil.getFieldValue(ReflectUtil.invokeMethod(playerToAdd, GET_HANDLE).getOrThrow(), PING).getOrThrow();
    packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.ADD_PLAYER);
    PlayerInfoData playerInfoData = new PlayerInfoData(getProtocolLibProfileWrapper(newProfile), ping, EnumWrappers.NativeGameMode.fromBukkit(playerToAdd.getGameMode()), WrappedChatComponent.fromText(playerToAdd.getPlayerListName()));
    packet.getPlayerInfoDataLists().write(0, Collections.singletonList(playerInfoData));
    try {
        ProtocolLibrary.getProtocolManager().sendServerPacket(seer, packet);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
}
 
开发者ID:Alvin-LB,项目名称:NameTagChanger,代码行数:14,代码来源:ProtocolLibPacketHandler.java

示例6: sendNamedEntitySpawnPacket

import com.comphenix.protocol.PacketType; //导入依赖的package包/类
@Override
public void sendNamedEntitySpawnPacket(Player playerToSpawn, Player seer) {
    PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.NAMED_ENTITY_SPAWN);
    packet.getIntegers().write(0, playerToSpawn.getEntityId());
    packet.getUUIDs().write(0, playerToSpawn.getUniqueId());
    if (ReflectUtil.isVersionHigherThan(1, 8, 8)) {
        packet.getDoubles().write(0, playerToSpawn.getLocation().getX());
        packet.getDoubles().write(1, playerToSpawn.getLocation().getY());
        packet.getDoubles().write(2, playerToSpawn.getLocation().getZ());
    } else {
        packet.getIntegers().write(0, (int) Math.floor(playerToSpawn.getLocation().getX() * 32D));
        packet.getIntegers().write(1, (int) Math.floor(playerToSpawn.getLocation().getY() * 32D));
        packet.getIntegers().write(2, (int) Math.floor(playerToSpawn.getLocation().getZ() * 32D));
    }
    packet.getBytes().write(0, (byte) (playerToSpawn.getLocation().getYaw() * 256F / 360F));
    packet.getBytes().write(1, (byte) (playerToSpawn.getLocation().getPitch() * 256F / 360F));
    try {
        ProtocolLibrary.getProtocolManager().sendServerPacket(seer, packet);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
}
 
开发者ID:Alvin-LB,项目名称:NameTagChanger,代码行数:23,代码来源:ProtocolLibPacketHandler.java

示例7: openFor

import com.comphenix.protocol.PacketType; //导入依赖的package包/类
@Override
public void openFor(Player player) throws InvocationTargetException {
	if (AuthMeApi.getInstance().isAuthenticated(player)) {
		return;
	}
	PacketContainer fakeBlockChange = new PacketContainer(PacketType.Play.Server.BLOCK_CHANGE);
	PacketContainer updateEntity = new PacketContainer(PacketType.Play.Server.TILE_ENTITY_DATA);
	PacketContainer sign = new PacketContainer(PacketType.Play.Server.OPEN_SIGN_EDITOR);
	Location block = player.getLocation().getBlock().getLocation();
	BlockPosition position = new BlockPosition(block.getBlockX(), block.getBlockY() + 1, block.getBlockZ());
	fakeBlockChange.getBlockPositionModifier().write(0, position);
	fakeBlockChange.getBlockData().write(0, WrappedBlockData.createData(Material.SIGN_POST));
	protocolManager.sendServerPacket(player, fakeBlockChange);
	updateEntity.getBlockPositionModifier().write(0, position);
	updateEntity.getIntegers().write(0, 9);
	NbtCompound signNbt = (NbtCompound) updateEntity.getNbtModifier().read(0);
	signNbt = signNbt == null ? NbtFactory.ofCompound("") : signNbt;
	List<String> lines = this.getInfoFor(player);
	for (int i = 0; i < lines.size() || i < 4; i++) {
		signNbt.put("Text" + (i + 1), "{\"text\":\"" + lines.get(i) + "\"}");
	}
	updateEntity.getNbtModifier().write(0, signNbt);
	protocolManager.sendServerPacket(player, updateEntity);
	sign.getBlockPositionModifier().write(0, position);
	protocolManager.sendServerPacket(player, sign);
}
 
开发者ID:lj2000lj,项目名称:AuthMeGUI,代码行数:27,代码来源:SignLoginWindow.java

示例8: fromMapPacket

import com.comphenix.protocol.PacketType; //导入依赖的package包/类
/**
 * Construct a chunk packet processor from a givne MAP_CHUNK packet.
 * @param packet - the map chunk packet.
 * @return The chunk packet processor.
 */
public static ChunkPacketProcessor fromMapPacket(PacketContainer packet, World world) {
	if (!packet.getType().equals(PacketType.Play.Server.MAP_CHUNK))
		throw new IllegalArgumentException(packet + " must be a MAP_CHUNK packet.");
	
	StructureModifier<Integer> ints = packet.getIntegers();
	StructureModifier<byte[]> byteArray = packet.getByteArrays();
    
    // Create an info objects
	ChunkPacketProcessor processor = new ChunkPacketProcessor();
	processor.world = world;
    processor.chunkX = ints.read(0); 	 // packet.a;
    processor.chunkZ = ints.read(1); 	 // packet.b;
    processor.chunkMask = ints.read(2);  // packet.c;
    processor.extraMask = ints.read(3);  // packet.d;
    processor.data = byteArray.read(1);  // packet.inflatedBuffer;
    processor.startIndex = 0;

    if (packet.getBooleans().size() > 0) {
    	processor.hasContinous = packet.getBooleans().read(0);
    }
    return processor;
}
 
开发者ID:Vrekt,项目名称:Arc-v2,代码行数:28,代码来源:ChunkPacketProcessor.java

示例9: sendKeepAlive

import com.comphenix.protocol.PacketType; //导入依赖的package包/类
public static void sendKeepAlive(List<Player> player) {
	for (Player p : player) {
		try {
			PacketContainer packet = get().createPacket(PacketType.Play.Client.KEEP_ALIVE);
			packet.getIntegers().write(0, random.nextInt());
			get().sendServerPacket(p, packet);
		} catch (InvocationTargetException ex) {
			ex.printStackTrace();
		}
	}
}
 
开发者ID:jiongjionger,项目名称:NeverLag,代码行数:12,代码来源:ProtocolUtils.java

示例10: onPacketReceiving

import com.comphenix.protocol.PacketType; //导入依赖的package包/类
@Override
public void onPacketReceiving(PacketEvent packetEvent) {
    Player p = packetEvent.getPlayer();
    PacketContainer packet = packetEvent.getPacket();
    if (packet.getType().equals(PacketType.Play.Client.USE_ENTITY)) {
        UUID u = tagMap.get(packet.getIntegers().read(0));
        if (u == null) return;
        Entity e = p.getNearbyEntities(8, 8, 8).stream().filter(entity -> entity.getUniqueId().equals(u)).findAny
                ().orElse(null);
        if (e == null) return;
        if (!HitboxUtil.isLookingAt(p, e)) return;
        packet.getIntegers().write(0, e.getEntityId());
        if (e.getType() == EntityType.ARMOR_STAND)
            packet.getEntityUseActions().write(0, EnumWrappers.EntityUseAction.ATTACK);
    }
}
 
开发者ID:iso2013,项目名称:MultiLineAPI,代码行数:17,代码来源:PacketListener.java

示例11: addListener

import com.comphenix.protocol.PacketType; //导入依赖的package包/类
public static void addListener(PacketType[] packettypes) {
    List<PacketType> packetTypesToStartListeningFor = new ArrayList<PacketType>();
    for (int i = 0; i < packettypes.length; i++) {
        if (!packetTypesListenedFor.contains(packettypes[i])) {
            packetTypesListenedFor.add(packettypes[i]);
            packetTypesToStartListeningFor.add(packettypes[i]);
        }
    }
    if (!packetTypesToStartListeningFor.isEmpty()) {
        PacketType[] packetTypes = packetTypesToStartListeningFor.toArray(new PacketType[0]);
        PacketManager.onPacketEvent(packetTypes, packetEvent -> {
            MundoPacketEvent evt = new MundoPacketEvent(packetEvent);
            Bukkit.getServer().getPluginManager().callEvent(evt);
        });
    }
}
 
开发者ID:MundoSK,项目名称:MundoSK,代码行数:17,代码来源:MundoPacketEvent.java

示例12: enableScores

import com.comphenix.protocol.PacketType; //导入依赖的package包/类
public void enableScores() {
    if (!areScoresEnabled()) {
        scoresEnabled = true;

        PacketContainer createPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SCOREBOARD_OBJECTIVE); //Used to get some defaults
        createPacket.getStrings().writeSafely(0, OBJECTIVE_NAME);
        createPacket.getStrings().writeSafely(1, OBJECTIVE_NAME);
        createPacket.getIntegers().writeSafely(0, 0);
        PacketManager.sendPacket(createPacket, this, target);

        PacketContainer displayPacket = new PacketContainer(PacketType.Play.Server.SCOREBOARD_DISPLAY_OBJECTIVE);
        displayPacket.getIntegers().writeSafely(0, 0);
        displayPacket.getStrings().writeSafely(0, OBJECTIVE_NAME);
        PacketManager.sendPacket(displayPacket, this, target);
    }
}
 
开发者ID:MundoSK,项目名称:MundoSK,代码行数:17,代码来源:Tablist.java

示例13: onEnable

import com.comphenix.protocol.PacketType; //导入依赖的package包/类
/**
 * @see org.bukkit.plugin.java.JavaPlugin#onEnable()
 */
@Override
public void onEnable() {
    saveDefaultConfig();
    CONFIG = new Configuration(this);
    CONFIG.reload();

    _protocolManager = ProtocolLibrary.getProtocolManager();
    _protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.UPDATE_TIME) {
        @Override
        public void onPacketSending(PacketEvent event) {
            if (event.getPacketType() == PacketType.Play.Server.UPDATE_TIME &&
                _ignoringTime.contains(event.getPlayer()) &&
                event.getPacket().getLongs().read(1) >= 0) {
                event.setCancelled(true);
            }
        }
    });
}
 
开发者ID:NerdNu,项目名称:NerdMoods,代码行数:22,代码来源:NerdMoods.java

示例14: MOTDPacketListener

import com.comphenix.protocol.PacketType; //导入依赖的package包/类
public MOTDPacketListener(Main plugin, ProtocolManager pm) throws Throwable {
    this.plugin = plugin;
    this.pm = pm;

    this.sendingWhitelist = ListeningWhitelist.newBuilder()
            .priority(ListenerPriority.NORMAL)
            .types(PacketType.Status.Server.OUT_SERVER_INFO) //监听PacketStatusOutServerInfo包
            .gamePhase(GamePhase.LOGIN)
            .options(new ListenerOptions[]{ListenerOptions.ASYNC})
            .build();
    this.receivingWhitelist = ListeningWhitelist.newBuilder()
            .priority(ListenerPriority.NORMAL)
            .types(PacketType.Status.Client.IN_PING) //监听PacketStatusInPing包
            .gamePhase(GamePhase.LOGIN)
            .options(new ListenerOptions[]{ListenerOptions.ASYNC})
            .build();
    new Timer("ColorMOTDAnimThread", true).scheduleAtFixedRate(this, 0, config.globalFrameRate);
}
 
开发者ID:andylizi,项目名称:AnimColorMOTD,代码行数:19,代码来源:MOTDPacketListener.java

示例15: send

import com.comphenix.protocol.PacketType; //导入依赖的package包/类
public static void send(UUID u) {
	if (active && listPlayers != null) {
		try {
			PacketContainer packet = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
			
			List<PlayerInfoData> list = new ArrayList<PlayerInfoData>();
			for (Entry<UUID, PlayerInfoData> e : listPlayers.entrySet()) {
				list.add(e.getValue());
			}
			packet.getPlayerInfoDataLists().write(0, list);
			packet.getPlayerInfoAction().write(0, PlayerInfoAction.ADD_PLAYER);
			
			ProtocolLibrary.getProtocolManager().sendServerPacket(Bukkit.getPlayer(u), packet);
		} catch (InvocationTargetException ex) {
			LogHandler.printError("ProtocolHandler error at send(): " + ex.getMessage());
		}
	}
}
 
开发者ID:AlessioDP,项目名称:Parties,代码行数:19,代码来源:ProtocolHandler.java


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