当前位置: 首页>>代码示例>>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;未经允许,请勿转载。