本文整理汇总了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);
}
}
示例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));
}
}
示例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);
}
}
示例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());
}
}
}
}
示例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);
}
}
示例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);
}
}