本文整理汇总了Java中com.comphenix.protocol.ProtocolManager类的典型用法代码示例。如果您正苦于以下问题:Java ProtocolManager类的具体用法?Java ProtocolManager怎么用?Java ProtocolManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProtocolManager类属于com.comphenix.protocol包,在下文中一共展示了ProtocolManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import com.comphenix.protocol.ProtocolManager; //导入依赖的package包/类
public static void init(ProtocolManager manager, Logger errorLogger, boolean itemSupport) {
PacketUtil.manager = manager;
PacketUtil.errorLogger = errorLogger;
String version = Bukkit.getServer().getClass().getPackage().getName();
version = version.substring(version.lastIndexOf('.') + 1);
try {
entityID = Class.forName("net.minecraft.server." + version + ".Entity").getDeclaredField("entityCount");
if (!entityID.isAccessible()) entityID.setAccessible(true);
if (!itemSupport) return;
getISNMSCopy = Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack")
.getDeclaredMethod("asNMSCopy", ItemStack.class);
} catch (NoSuchMethodException | ClassNotFoundException | NoSuchFieldException e) {
entityID = null;
getISNMSCopy = null;
}
}
示例2: MOTDPacketListener
import com.comphenix.protocol.ProtocolManager; //导入依赖的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);
}
示例3: instantiatePacketListener
import com.comphenix.protocol.ProtocolManager; //导入依赖的package包/类
private PacketListener instantiatePacketListener( ProtocolManager protocolManager, String basePackage, String name, Object... args ) throws Exception {
String fullyQualifiedName = basePackage + "." + name;
try {
Class<?> clazz = Class.forName( fullyQualifiedName, true, this.getClassLoader() );
if ( !InterceptorBase.class.isAssignableFrom( clazz ) ) {
throw new AssertionError( "Interceptor is not derived from InterceptorBase" );
}
Class<? extends InterceptorBase> checkedClass = (Class<? extends InterceptorBase>) clazz;
Constructor<? extends InterceptorBase> constructor = checkedClass.getConstructor( Plugin.class, Gson.class, I18NSpigotImpl.class );
constructor.setAccessible( true );
return constructor.newInstance( args );
} catch ( Throwable e ) {
MinecraftVersion minecraftVersion = protocolManager.getMinecraftVersion();
throw new Exception( "Could not instantiate interceptor '" + name + "' for Minecraft version " + minecraftVersion.getMajor() + "." + minecraftVersion.getMinor(), e );
}
}
示例4: sendNbt
import com.comphenix.protocol.ProtocolManager; //导入依赖的package包/类
private void sendNbt(Vector pos, NbtCompound compound) {
Player player = this.<Player>getPlayer().parent;
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
PacketContainer blockNbt = new PacketContainer(PacketType.Play.Server.TILE_ENTITY_DATA);
blockNbt.getBlockPositionModifier().write(0, new BlockPosition(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()));
blockNbt.getIntegers().write(0, 7);
blockNbt.getNbtModifier().write(0, compound);
try {
manager.sendServerPacket(player, blockNbt);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
示例5: onEnable
import com.comphenix.protocol.ProtocolManager; //导入依赖的package包/类
@Override
public void onEnable() {
configuration = new Configuration(this);
configuration.saveDefault();
configuration.load();
getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
getCommand("mmoaction").setExecutor(new ToggleCommand(this));
//the event could and should be executed async, but if we try to use it with other sync listeners
//the sending order gets mixed up
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
protocolManager.addPacketListener(new MessageListener(this, configuration.getMessages()));
//load disabled lists
actionBarDisabled = loadDisabled(ACTIONBAR_FILE_NAME);
progressBarDisabled = loadDisabled(PROGRESS_FILE_NAME);
}
示例6: setupPacketModification
import com.comphenix.protocol.ProtocolManager; //导入依赖的package包/类
/**
* Set up packet listening for ENTITY_METADATA packets so they can be modified to actually contain
* the dead horses' equipped armor.
*/
private void setupPacketModification() {
if (getServer().getPluginManager().getPlugin(PROTOCOL_LIB) instanceof ProtocolLibrary) {
fancyLog("ProtocolLib detected, creating hook for entity metadata packets.");
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
manager.addPacketListener(new PacketAdapter(new PacketAdapter.AdapterParameteters()
.plugin(this).serverSide().types(PacketType.Play.Server.ENTITY_METADATA)) {
@Override
public void onPacketSending(PacketEvent event) {
if (config.isPacketModificationEnabled()) {
handleMetadataPacket(event);
}
}
});
hookedProtocolLib = true;
fancyLog("Entity metadata packet hooked.");
}
}
示例7: updatePlayer
import com.comphenix.protocol.ProtocolManager; //导入依赖的package包/类
/**
* Update the given player.
*
* @param manager - reference to ProtocolLib
* @param player - player to refresh.
* @throws InvocationTargetException If we are unable to send a packet.
*/
public void updatePlayer(ProtocolManager manager, Player player) throws InvocationTargetException {
if (player.isDead()) {
return;
}
Byte flag = flagByte.get(player);
// It doesn't matter much
if (flag == null) {
flag = 0;
}
// Create the packet we will transmit
WrapperPlayServerEntityMetadata packet = new WrapperPlayServerEntityMetadata();
WrappedDataWatcher watcher = new WrappedDataWatcher();
watcher.setObject(0, flag);
packet.setEntityId(player.getEntityId());
packet.setEntityMetadata(watcher.getWatchableObjects());
// Broadcast the packet
for (Player observer : manager.getEntityTrackers(player)) {
manager.sendServerPacket(observer, packet.getHandle());
}
}
示例8: sendBlankInventoryPacket
import com.comphenix.protocol.ProtocolManager; //导入依赖的package包/类
public void sendBlankInventoryPacket(Player player) {
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
PacketContainer inventoryPacket = protocolManager.createPacket(PacketType.Play.Server.WINDOW_ITEMS);
inventoryPacket.getIntegers().write(0, PLAYER_INVENTORY);
int inventorySize = CRAFTING_SIZE + ARMOR_SIZE + MAIN_SIZE + HOTBAR_SIZE;
ItemStack[] blankInventory = new ItemStack[inventorySize];
Arrays.fill(blankInventory, new ItemStack(Material.AIR));
//old minecraft versions
StructureModifier<ItemStack[]> itemArrayModifier = inventoryPacket.getItemArrayModifier();
if (itemArrayModifier.size() > 0) {
itemArrayModifier.write(0, blankInventory);
} else {
//minecraft versions above 1.11
StructureModifier<List<ItemStack>> itemListModifier = inventoryPacket.getItemListModifier();
itemListModifier.write(0, Arrays.asList(blankInventory));
}
try {
protocolManager.sendServerPacket(player, inventoryPacket, false);
} catch (InvocationTargetException invocationExc) {
ConsoleLogger.logException("Error during sending blank inventory", invocationExc);
}
}
示例9: registerPacketListeners
import com.comphenix.protocol.ProtocolManager; //导入依赖的package包/类
public void registerPacketListeners() {
final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
for (PacketType packetType : new PacketType[] { PacketType.Play.Client.POSITION }) {
protocolManager
.addPacketListener(new PacketAdapter(Crescent.getInstance(), ListenerPriority.NORMAL, packetType) {
@Override
public void onPacketReceiving(PacketEvent event) {
if (event.getPacketType() == packetType) {
Bukkit.getPluginManager()
.callEvent(new PlayerPacketEvent(event.getPlayer(), event.getPacket()));
}
}
});
}
}
示例10: SignLoginWindow
import com.comphenix.protocol.ProtocolManager; //导入依赖的package包/类
public SignLoginWindow(ProtocolManager protocolManager, Plugin plugin) {
super(protocolManager, plugin);
protocolManager.addPacketListener(
new PacketAdapter(plugin, ListenerPriority.NORMAL, PacketType.Play.Client.UPDATE_SIGN) {
@Override
public void onPacketReceiving(PacketEvent event) {
if (event.getPacketType() != PacketType.Play.Client.UPDATE_SIGN) {
return;
}
if (AuthMeApi.getInstance().isAuthenticated(event.getPlayer())) {
return;
}
PacketContainer packet = event.getPacket();
String[] strings = packet.getStringArrays().read(0);
if (strings[Variables.signLoginLine - 1].isEmpty()) {
return;
}
boolean registered = AuthMeApi.getInstance().isRegistered(event.getPlayer().getName());
String password = strings[Variables.signLoginLine - 1].substring(SignLoginWindow.this
.getInfoFor(event.getPlayer(), Variables.signInfo.get(Variables.signLoginLine - 1))
.length());
if (!registered & !password.isEmpty()) {
AuthMeApi.getInstance().registerPlayer(event.getPlayer().getName(), password);
}
Bukkit.getPluginCommand("login").execute(event.getPlayer(), "login", new String[] { password });
}
});
}
示例11: hook
import com.comphenix.protocol.ProtocolManager; //导入依赖的package包/类
/**
* Hooks ProtocolLibrary into a {@link JavaPlugin}.
*
* @param kairos
* the plugin to hook into
*/
public static void hook(HCF kairos) {
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
protocolManager.addPacketListener(new PacketAdapter(kairos, ListenerPriority.NORMAL, PacketType.Play.Client.BLOCK_DIG) {
@Override
public void onPacketReceiving(PacketEvent event) {
PacketContainer packet = event.getPacket();
StructureModifier<Integer> modifier = packet.getIntegers();
Player player = event.getPlayer();
try {
int status = modifier.read(4);
// int face = modifier.read(3);
if (status == STARTED_DIGGING || status == FINISHED_DIGGING) {
int x, y, z;
Location location = new Location(player.getWorld(), x = modifier.read(0), y = modifier.read(1), z = modifier.read(2));
// Validation
VisualBlock visualBlock = kairos.getVisualiseHandler().getVisualBlockAt(player, location);
if (visualBlock == null)
return;
event.setCancelled(true);
VisualBlockData data = visualBlock.getBlockData();
if (status == FINISHED_DIGGING) {
player.sendBlockChange(location, data.getBlockType(), data.getData());
} else if (status == STARTED_DIGGING) { // we check this because Blocks that broke pretty much straight away do not send a FINISHED for some weird reason.
EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
if (player.getGameMode() == GameMode.CREATIVE
|| net.minecraft.server.v1_7_R4.Block.getById(data.getItemTypeId()).getDamage(entityPlayer, entityPlayer.world, x, y, z) > 1.0F) {
player.sendBlockChange(location, data.getBlockType(), data.getData());
}
}
}
} catch (FieldAccessException ignored) {
}
}
});
}
示例12: PacketListener
import com.comphenix.protocol.ProtocolManager; //导入依赖的package包/类
public PacketListener(MultiLineAPI plugin) {
this.plugin = plugin;
this.tagMap = Maps.newHashMap();
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
manager.addPacketListener(this);
PacketUtil.init(manager, plugin.getLogger(), false);
}
示例13: execute
import com.comphenix.protocol.ProtocolManager; //导入依赖的package包/类
@Override
protected void execute(Event event) {
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
try {
for (PacketContainer packet : packetContainerExpression.getArray(event)) {
for (Player player : playerExpression.getArray(event)) {
protocolManager.recieveClientPacket(player, packet);
}
}
} catch (IllegalAccessException | InvocationTargetException e) {
Logging.reportException(this, e);
}
}
示例14: handleHF
import com.comphenix.protocol.ProtocolManager; //导入依赖的package包/类
public static void handleHF() {
if (!active
&& !(Variables.tablist_header_inparty.isEmpty() && Variables.tablist_header_outparty.isEmpty()
&& Variables.tablist_footer_inparty.isEmpty() && Variables.tablist_footer_outparty.isEmpty())) {
Parties plugin = Parties.getInstance();
ProtocolManager proto = ProtocolLibrary.getProtocolManager();
PacketContainer pc = proto.createPacket(PacketType.Play.Server.PLAYER_LIST_HEADER_FOOTER);
for (Player pl : plugin.getServer().getOnlinePlayers()) {
String header = "", footer = "";
ThePlayer tp = plugin.getPlayerHandler().getPlayer(pl.getUniqueId());
Party party = plugin.getPartyHandler().getParty(tp.getPartyName());
if (party != null) {
header = party.convertText(Variables.tablist_header_inparty, pl);
footer = party.convertText(Variables.tablist_footer_inparty, pl);
} else {
header = plugin.getPlayerHandler().setTabText(Variables.tablist_header_outparty, pl);
footer = plugin.getPlayerHandler().setTabText(Variables.tablist_footer_outparty, pl);
}
if (!header.isEmpty())
pc.getChatComponents().write(0, WrappedChatComponent.fromText(ChatColor.translateAlternateColorCodes('&', header)));
if (!footer.isEmpty())
pc.getChatComponents().write(1, WrappedChatComponent.fromText(ChatColor.translateAlternateColorCodes('&', footer)));
try {
proto.sendServerPacket(pl, pc);
} catch (InvocationTargetException ex) {
LogHandler.printError("ProtocolHandler error at handleHF(): " + ex.getMessage());
}
}
}
}
示例15: ServerListHandler
import com.comphenix.protocol.ProtocolManager; //导入依赖的package包/类
public ServerListHandler() {
ProtocolManager pManager = ProtocolLibrary.getProtocolManager();
pManager.removePacketListeners(Util.getMain());
pManager.addPacketListener(new PacketAdapter(Vars.main, Arrays.asList(PacketType.Status.Server.OUT_SERVER_INFO)) {
@Override
public void onPacketSending(PacketEvent event) {
StructureModifier<WrappedServerPing> pings = event.getPacket().getServerPings();
WrappedServerPing ping = pings.read(0);
handlePing(ping);
}
});
}