當前位置: 首頁>>代碼示例>>Java>>正文


Java ProtocolManager.addPacketListener方法代碼示例

本文整理匯總了Java中com.comphenix.protocol.ProtocolManager.addPacketListener方法的典型用法代碼示例。如果您正苦於以下問題:Java ProtocolManager.addPacketListener方法的具體用法?Java ProtocolManager.addPacketListener怎麽用?Java ProtocolManager.addPacketListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.comphenix.protocol.ProtocolManager的用法示例。


在下文中一共展示了ProtocolManager.addPacketListener方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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);
}
 
開發者ID:games647,項目名稱:mcMMOAction,代碼行數:19,代碼來源:mcMMOAction.java

示例2: 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.");
  }
}
 
開發者ID:EasyMFnE,項目名稱:DeadHorses,代碼行數:22,代碼來源:DeadHorses.java

示例3: 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()));
						}
					}
				});
	}
}
 
開發者ID:davidm98,項目名稱:Crescent,代碼行數:16,代碼來源:BehaviourListeners.java

示例4: 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 });
				}
			});
}
 
開發者ID:lj2000lj,項目名稱:AuthMeGUI,代碼行數:29,代碼來源:SignLoginWindow.java

示例5: 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) {
            }
        }
    });
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:46,代碼來源:ProtocolLibHook.java

示例6: 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);
}
 
開發者ID:iso2013,項目名稱:MultiLineAPI,代碼行數:8,代碼來源:PacketListener.java

示例7: 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);
		}
	});
}
 
開發者ID:bobmandude9889,項目名稱:iZenith-PVP,代碼行數:13,代碼來源:ServerListHandler.java

示例8: onEnable

import com.comphenix.protocol.ProtocolManager; //導入方法依賴的package包/類
@Override
public void onEnable() {
    Config.loadConfig(this);
    this.updateConfig();
    language = new FileLanguage(this);

    if (!this.checkRequirements()) {
        this.getPluginLoader().disablePlugin(this);
        return;
    }

    // Hook Placeholder API
    if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
        new StringUtils.Placeholders().hook();
        pApiHooked = true;
        this.getLogger().info("Placeholder API hooked!");
    } else {
        pApiHooked = false;
    }

    // Load modules
    this.getLogger().info(CraftManager.init(this) ? "Craft extensions is enabled." : "Craft extensions isn't loaded.");
    this.getLogger().info(InventoryLocker.init(this) ? "Inventory lock system is enabled." : "Inventory lock system isn't loaded.");
    this.getLogger().info(ItemManager.init(this) ? "Item system is enabled." : "Item system isn't loaded.");
    this.getLogger().info(PetManager.init(this) ? "Pet system is enabled." : "Pet system isn't loaded.");
    this.getLogger().info(BackpackManager.init(this) ? "Backpack system is enabled." : "Backpack system isn't loaded.");

    // Hook MyPet
    if (Bukkit.getPluginManager().isPluginEnabled("MyPet") && MyPetManager.init(this)) {
        this.getLogger().info("MyPet hooked!");
    }

    // Registering other listeners
    PluginManager pm = this.getServer().getPluginManager();
    pm.registerEvents(new ArmorEquipListener(), this);
    pm.registerEvents(new HandSwapListener(), this);
    pm.registerEvents(new PlayerListener(), this);
    pm.registerEvents(new WorldListener(), this);

    if (SlotManager.instance().getElytraSlot() != null) {
        pm.registerEvents(new ElytraListener(), this);
    }

    ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
    // Workaround for 1.12+
    if (VersionHandler.isUpper1_12()) {
        protocolManager.addPacketListener(
                new PacketAdapter(this, PacketType.Play.Server.RECIPES) {
                    @Override
                    public void onPacketSending(PacketEvent event) {
                        event.setCancelled(true);
                    }
                });
        this.getLogger().info("Recipe book conflicts with RPGInventory and was disabled.");
    }

    protocolManager.addPacketListener(new PlayerLoader(this));

    this.loadPlayers();
    this.startMetrics();

    // Enable commands
    this.getCommand("rpginventory").setExecutor(new RPGInventoryCommandExecutor());

    this.checkUpdates(null);
}
 
開發者ID:EndlessCodeGroup,項目名稱:RPGInventory,代碼行數:67,代碼來源:RPGInventory.java

示例9: tabComplete

import com.comphenix.protocol.ProtocolManager; //導入方法依賴的package包/類
public static void tabComplete(ProtocolManager protocolManager, Plugin plugin){
	protocolManager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.NORMAL, new PacketType[]{ PacketType.Play.Client.TAB_COMPLETE }){
		@EventHandler(priority = EventPriority.HIGHEST)
		public void onPacketReceiving(PacketEvent e){
			if (e.getPacketType() == PacketType.Play.Client.TAB_COMPLETE){
				try{
					if (ConfigManager.getConfig().getBoolean("DisableTabComplete"))
						if (e.getPlayer().hasPermission("cb.bypasstab")){
							return;
						}
						PacketContainer packet = e.getPacket();
						String message = ((String) packet.getSpecificModifier(String.class).read(0)).toLowerCase();
						for (String cmd : ConfigManager.getDisabled().getConfigurationSection("DisabledCommands").getKeys(false)){
							String cmds = cmd.replace("%colon%", ":").toLowerCase();
							String permission = cmd.replace("%colon%", "").replace(" ", "");
							if (ConfigManager.getDisabled().getString("DisabledCommands." + cmd + ".Permission") == null){
								if (!(e.getPlayer().hasPermission(ConfigManager.getConfig().getString("Default.Permission").replace("%command%", permission)))){
									if (ConfigManager.getDisabled().getString("DisabledCommands." + cmd + ".NoTabComplete") == null){
										if (((message.startsWith("/" + cmds)) && (!message.contains("  "))) || ((message.startsWith("/") && (!message.contains(" "))))){
											e.setCancelled(true);
										}
									} else if (ConfigManager.getDisabled().getBoolean("DisabledCommands." + cmd + ".NoTabComplete")){
										if (((message.startsWith("/" + cmds)) && (!message.contains("  "))) || ((message.startsWith("/") && (!message.contains(" "))))){
											e.setCancelled(true);
										}
									}
								}
							} else {
								if (!(e.getPlayer().hasPermission(ConfigManager.getDisabled().getString("DisabledCommands." + cmd + ".Permission")))){
									if (ConfigManager.getDisabled().getString("DisabledCommands." + cmd + ".NoTabComplete") == null){
										if (((message.startsWith("/" + cmds)) && (!message.contains("  "))) || ((message.startsWith("/") && (!message.contains(" "))))){
											e.setCancelled(true);
										}
									} else if (ConfigManager.getDisabled().getBoolean("DisabledCommands." + cmd + ".NoTabComplete")){
										if (((message.startsWith("/" + cmds)) && (!message.contains("  "))) || ((message.startsWith("/") && (!message.contains(" "))))){
											e.setCancelled(true);
										}
									}
								}
							}
						}
				} catch (Exception e2) {
					e2.printStackTrace();
				}
			}
		}
	});
}
 
開發者ID:TreyRuffy,項目名稱:CommandBlocker,代碼行數:49,代碼來源:Packets.java

示例10: installInterceptors

import com.comphenix.protocol.ProtocolManager; //導入方法依賴的package包/類
private void installInterceptors() {
	GsonBuilder gsonBuilder = new GsonBuilder();
	gsonBuilder.registerTypeAdapter( ChatComponent.class, new ChatComponentDeserializer() );
	Gson gson = gsonBuilder.create();
	
	ProtocolManager  protocolManager = ProtocolLibrary.getProtocolManager();
	String           basePackage     = "com.blackypaw.mc.i18n.interceptor.";
	MinecraftVersion version         = protocolManager.getMinecraftVersion();
	
	if ( version.getMajor() == 1 ) {
		// Full Version:
		if ( version.getMinor() == 12 || version.getMinor() == 11 ) {
			basePackage += "v1_11";
		} else if ( version.getMinor() == 10 ) {
			basePackage += "v1_10";
		} else if ( version.getMinor() == 9 ) {
			if ( version.getBuild() > 2 ) {
				basePackage += "v1_10";
			} else {
				basePackage += "v1_9_2";
			}
		} else if ( version.getMinor() == 8 ) {
			basePackage += "v1_9_2";
		} else {
			basePackage = null;
		}
	} else {
		basePackage = null;
	}
	
	if ( basePackage == null ) {
		this.getLogger().log( Level.SEVERE, "Failed to instantiate interceptors: this build supports Minecraft versions 1.8 - 1.12; please consider upgrading to the latest version" );
		return;
	}
	
	try {
		protocolManager.addPacketListener( this.instantiatePacketListener( protocolManager, basePackage, "InterceptorChat", this, gson, this.i18n ) );
		protocolManager.addPacketListener( this.instantiatePacketListener( protocolManager, basePackage, "InterceptorScoreboard", this, gson, this.i18n ) );
		protocolManager.addPacketListener( this.instantiatePacketListener( protocolManager, basePackage, "InterceptorSettings", this, gson, this.i18n ) );
		protocolManager.addPacketListener( this.instantiatePacketListener( protocolManager, basePackage, "InterceptorSign", this, gson, this.i18n ) );
		protocolManager.addPacketListener( this.instantiatePacketListener( protocolManager, basePackage, "InterceptorSlot", this, gson, this.i18n ) );
		protocolManager.addPacketListener( this.instantiatePacketListener( protocolManager, basePackage, "InterceptorTitle", this, gson, this.i18n ) );
	} catch ( Exception e ) {
		this.getLogger().log( Level.SEVERE, "Failed to instantiate interceptors", e );
	}
}
 
開發者ID:BlackyPaw,項目名稱:I18N,代碼行數:47,代碼來源:I18NSpigotAdapter.java


注:本文中的com.comphenix.protocol.ProtocolManager.addPacketListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。