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


Java PacketEvent.isCancelled方法代碼示例

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


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

示例1: onPacketSending

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
@Override
public void onPacketSending(PacketEvent event) {
    Player player = event.getPlayer();
    //noinspection ConstantConditions
    if (event.isCancelled() || !InventoryManager.playerIsLoaded(player)
            || isNotNeededHere(player)) {
        return;
    }

    WrapperPlayServerWindowItems packet = new WrapperPlayServerWindowItems(event.getPacket());
    if (player.getOpenInventory().getType() == InventoryType.WORKBENCH) {
        List<ItemStack> contents = packet.getSlotData();

        List<CraftExtension> extensions = CraftManager.getExtensions(player);
        for (CraftExtension extension : extensions) {
            for (int slot : extension.getSlots()) {
                contents.set(slot, extension.getCapItem());
            }
        }

        packet.setSlotData(contents);
    }
}
 
開發者ID:EndlessCodeGroup,項目名稱:RPGInventory,代碼行數:24,代碼來源:CraftListener.java

示例2: onPacketSending

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
@Override
public void onPacketSending(PacketEvent packetEvent) {
    Player player = packetEvent.getPlayer();
    if (packetEvent.isCancelled() || player instanceof Factory) {
        return;
    }

    PacketContainer packet = packetEvent.getPacket();
    if (packet.hasMetadata("ScoreboardStats")) {
        //it's our own packet
        return;
    }

    UUID playerUUID = player.getUniqueId();

    //handle async packets by other plugins
    if (Bukkit.isPrimaryThread()) {
        ensureMainThread(playerUUID, packet);
    } else {
        PacketContainer clone = packet.deepClone();
        Bukkit.getScheduler().runTask(plugin, () -> ensureMainThread(playerUUID, clone));
    }
}
 
開發者ID:games647,項目名稱:ScoreboardStats,代碼行數:24,代碼來源:PacketListener.java

示例3: onPacketSending

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
@Override
public void onPacketSending(PacketEvent packetEvent) {
    PacketContainer packet = packetEvent.getPacket();
    if (packetEvent.isCancelled() || packet.hasMetadata(plugin.getName())) {
        return;
    }

    Player player = packetEvent.getPlayer();
    WrappedChatComponent message = packet.getChatComponents().read(0);
    ChatType chatType = readChatPosition(packet);
    if (message == null || chatType != ChatType.SYSTEM) {
        return;
    }

    String json = message.getJson();
    if (shouldRemoveHover) {
        json = gson.toJson(cleanJsonFromHover(json));
    }

    BaseComponent chatComponent = ComponentSerializer.parse(json)[0];
    if (chatComponent != null && isMcMMOMessage(chatComponent.toPlainText()) && plugin.isActionBarEnabled(player)) {
        writeChatPosition(packet);

        //action bar doesn't support the new chat features
        String legacyText = pluginTagPattern.matcher(chatComponent.toLegacyText()).replaceFirst("");
        packet.getChatComponents().write(0, WrappedChatComponent.fromText(legacyText));
        plugin.playNotificationSound(player);
    }
}
 
開發者ID:games647,項目名稱:mcMMOAction,代碼行數:30,代碼來源:MessageListener.java

示例4: onPacketSending

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public void onPacketSending(final PacketEvent event) {
	if (event.getPacketType() != PacketType.Play.Server.CHAT) {
		return;
	}
	if (event.isCancelled()) {
		return;
	}
	final PacketContainer packet = event.getPacket();
	final List<WrappedChatComponent> chatComponentValues = packet.getChatComponents().getValues();

	// igonre system messages if set in config
	if (!main.getConfig().getBoolean("ignoreSystemMessages") || packet.getBytes().size() <= 0 || packet.getBytes().read(0) != 1) {
		// Parse Json, translate messages only
		event.setCancelled(true);
		final String lang = User.get(event.getPlayer()).getLanguage();
		for (final WrappedChatComponent chatComponent : chatComponentValues) {
			final Object parsed = JSONValue.parse(chatComponent.getJson());
			if (parsed == null) {
				if (chatComponent.getJson().isEmpty()) {
					continue;
				} else {
					// TODO print error
				}
			} else if (parsed instanceof String) {
				chatComponent.setJson(translator.getTranslationOf(((String) parsed), "auto", lang));
			} else if (parsed instanceof JSONArray) {
				chatComponent.setJson(parseAndTranslate((JSONArray) parsed, lang).toJSONString());
			} else if (parsed instanceof JSONObject) {
				chatComponent.setJson(parseAndTranslate((JSONObject) parsed, lang).toJSONString());
			}
		}
	}
}
 
開發者ID:davewolax,項目名稱:ChatTranslator,代碼行數:36,代碼來源:ChatMessageSendingListener.java

示例5: onPacketReceiving

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
@Override
public void onPacketReceiving(PacketEvent event) {
    //Packet: {Chat message} http://wiki.vg/Protocol#Tab-Complete_2
    //We need to check the incoming chat message, since tab completions themselves don't
    //include the command they're for by default
    if (event.isCancelled()) {
        return;
    }
    StructureModifier<String> textModifier = event.getPacket().getSpecificModifier(String.class);
    String message = textModifier.read(TEXT_INDEX);
    if(isBlockedCommand(message) && !hasBypassPermission(event)) {
        rejectTabComplete(event);
    }
}
 
開發者ID:xxyy,項目名稱:commandblockerultimate,代碼行數:15,代碼來源:TabCompletePacketListener.java

示例6: onPacketSending

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
@Override
public void onPacketSending(PacketEvent event) {
    //Packet: {(VarInt)Count, Matched command} http://wiki.vg/Protocol#Tab-Complete
    List<String> suggestions = getSuggestionsFrom(event.getPacket());
    if (event.isCancelled() || suggestions.isEmpty() || hasBypassPermission(event)) {
        return;
    }
    Collection<String> blockedSuggestions = findBlockedSuggestionsIn(suggestions);
    suggestions.removeAll(blockedSuggestions);
    if(suggestions.isEmpty() || restrictiveModeApplies(blockedSuggestions)) {
        rejectTabComplete(event);
    } else if(!blockedSuggestions.isEmpty()) {
        writeSuggestionsTo(event.getPacket(), suggestions);
    }
}
 
開發者ID:xxyy,項目名稱:commandblockerultimate,代碼行數:16,代碼來源:TabCompletePacketListener.java


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