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


Java PacketEvent.setCancelled方法代碼示例

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


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

示例1: onSetCreativeSlotPacket

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
private static void onSetCreativeSlotPacket(PacketEvent e) {
	if (!e.getPlayer().isOp()) {
		try {
			StructureModifier<ItemStack> structureModifier = e.getPacket().getItemModifier();
			if (structureModifier != null) {
				ItemStack item = structureModifier.read(0);
				if (item != null) {
					Object craftItem = method_asNMSCopy.invoke(null, item);
					if (craftItem != null) {
						Object hasTag = method_hasTag.invoke(craftItem);
						if (hasTag != null && (Boolean) hasTag) {
							e.setCancelled(true);
						}
					}
				}
			}
		} catch (Exception ex) {
			// ignore
		}
	}
}
 
開發者ID:jiongjionger,項目名稱:NeverLag,代碼行數:22,代碼來源:AntiAUWMod.java

示例2: constructProtocol

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
/**
 * Construct the packet listener that will be used to intercept every entity-related packet.
 *
 * @param plugin - the parent plugin.
 *
 * @return The packet listener.
 */
private PacketAdapter constructProtocol(Plugin plugin)
{
    return new PacketAdapter(plugin, ENTITY_PACKETS)
    {
        @Override
        public void onPacketSending(PacketEvent event)
        {
            int entityID = event.getPacket().getIntegers().read(0);

            // See if this packet should be cancelled
            if (!isVisible(event.getPlayer(), entityID))
            {
                event.setCancelled(true);
            }
        }
    };
}
 
開發者ID:WoutDev,項目名稱:Mega-Walls,代碼行數:25,代碼來源:EntityHider.java

示例3: constructProtocol

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
/**
 * Construct the packet listener that will be used to intercept every
 * entity-related packet.
 * 
 * @param plugin
 *            - the parent plugin.
 * @return The packet listener.
 */
private PacketAdapter constructProtocol(Plugin plugin) {
    return new PacketAdapter(plugin, ENTITY_PACKETS) {

        @Override
        public void onPacketSending(PacketEvent event) {
            int index = event.getPacketType() == COMBAT_EVENT ? 1 : 0;

            Integer entityID = event.getPacket().getIntegers().readSafely(index);
            if (entityID != null) {
                if (!isVisible(event.getPlayer(), entityID)) {
                    event.setCancelled(true);
                }
            }
        }
    };
}
 
開發者ID:Co0sh,項目名稱:BetonQuest,代碼行數:25,代碼來源:EntityHider.java

示例4: onPacketSending

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
@Override
public void onPacketSending(PacketEvent event) {
    int distance = SoundMuffler.DISTANCE * SoundMuffler.DISTANCE;
    if (event.getPacketType() == PacketType.Play.Server.NAMED_SOUND_EFFECT) {
        int x = event.getPacket().getIntegers().read(0) >> 3;
        int y = event.getPacket().getIntegers().read(1) >> 3;
        int z = event.getPacket().getIntegers().read(2) >> 3;
        Location loc = new Location(event.getPlayer().getWorld(), x, y, z);
        for (SoundMuffler sm : mufflers) {
            if (loc.getWorld().equals(sm.getLocation().getWorld()) && loc.distanceSquared(sm.getLocation()) < distance) {
                if (sm.getVolume() == 0) {
                    event.setCancelled(true);
                } else {
                    event.getPacket().getFloat().write(0, (float) sm.getVolume() / 100.0f);
                }
            }
        }
    }
}
 
開發者ID:desht,項目名稱:sensibletoolbox,代碼行數:20,代碼來源:SoundMufflerListener.java

示例5: constructProtocol

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
/**
 * Construct the packet listener that will be used to intercept every entity-related packet.
 * @param plugin - the parent plugin.
 * @return The packet listener.
 */
private PacketAdapter constructProtocol(Plugin plugin) {
	return new PacketAdapter(plugin, ENTITY_PACKETS) {
		@Override
		public void onPacketSending(PacketEvent event) {
			int entityID = event.getPacket().getIntegers().read(0);

			// See if this packet should be cancelled
			if (!isVisible(event.getPlayer(), entityID)) {
				event.setCancelled(true);
			}
		}
	};
}
 
開發者ID:ijoeleoli,項目名稱:ZorahPractice,代碼行數:19,代碼來源:EntityHider.java

示例6: onPacketReceiving

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
@Override
public void onPacketReceiving(PacketEvent event) {
    StructureModifier<Integer> modifier = event.getPacket().getIntegers();

    try {
        int status = modifier.read(4);
        if (status == STARTED_DIGGING || status == FINISHED_DIGGING) {
            Player player = event.getPlayer();
            int x = modifier.read(0), y = modifier.read(1), z = modifier.read(2);
            Location location = new Location(player.getWorld(), x, y, z);
            
            Optional<FakeBlockSender> sender = FakeBlockSender.getFrom(player);
            if (!sender.isPresent()) {
                return;
            }
            
            FakeBlock visualBlock = sender.get().getBlockAt(location.toVector());
            if (visualBlock != null) {
                event.setCancelled(true);
                FakeBlock.Data data = visualBlock.getData();
                if (status == FINISHED_DIGGING || player.getGameMode() == GameMode.CREATIVE) {
                    player.sendBlockChange(location, data.getType(), data.getData());
                }
            }
        }
    } catch (FieldAccessException ex) {
        ex.printStackTrace();
    }
}
 
開發者ID:IPVP-MC,項目名稱:mirage,代碼行數:30,代碼來源:BlockDigAdapter.java

示例7: onPacketSending

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
@Override
public void onPacketSending(PacketEvent event) {
	if(event.getPacketType() == PacketType.Play.Server.PLAYER_INFO) {
		PacketContainer packet = event.getPacket();
		PlayerInfoAction action = packet.getPlayerInfoAction().read(0);
		Player player = Bukkit.getPlayer(packet.getPlayerInfoDataLists().read(0).get(0).getProfile().getUUID());
		boolean online = player != null && player.isOnline();
		if(online && action == PlayerInfoAction.REMOVE_PLAYER) event.setCancelled(true);
	}
}
 
開發者ID:TealNerd,項目名稱:RadarJammer,代碼行數:11,代碼來源:PlayerListManager.java

示例8: ignore

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
public void ignore(PacketEvent event) {
    PacketContainer packet = event.getPacket();
    Player player = event.getPlayer();
    if (packet.getID() == def(ignorePacketMap.remove(player.getName()), -1)) {
        event.setCancelled(true);
    }
}
 
開發者ID:EntryPointKR,項目名稱:K-Security,代碼行數:8,代碼來源:PacketIgnore.java

示例9: handleBlockEvent

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
private void handleBlockEvent(PacketEvent event, boolean relative, RunnableVal3<PacketEvent, HeightMapMCAGenerator, Vector> task) {
    HeightMapMCAGenerator gen = getGenerator(event);
    if (gen != null) {
        Vector pt = getRelPos(event, gen);
        if (pt != null) {
            if (relative) pt = getRelative(event, pt);
            if (gen.contain(pt)) {
                event.setCancelled(true);
                task.run(event, gen, pt);
            }
        }
    }
}
 
開發者ID:boy0001,項目名稱:FastAsyncWorldedit,代碼行數:14,代碼來源:CFIPacketListener.java

示例10: 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

示例11: onPacketReceiving

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
@Override
public void onPacketReceiving(PacketEvent event) {
    if (event.getPacketType() == PacketType.Play.Client.TAB_COMPLETE) {
        try {
            if (!playerCache.isAuthenticated(event.getPlayer().getName())) {
                event.setCancelled(true);
            }
        } catch (FieldAccessException e) {
            ConsoleLogger.logException("Couldn't access field:", e);
        }
    }
}
 
開發者ID:AuthMe,項目名稱:AuthMeReloaded,代碼行數:13,代碼來源:TabCompletePacketAdapter.java

示例12: onPacketSending

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
@Override
public void onPacketSending(PacketEvent packetEvent) {
    Player player = packetEvent.getPlayer();
    PacketContainer packet = packetEvent.getPacket();

    byte windowId = packet.getIntegers().read(0).byteValue();
    if (windowId == PLAYER_INVENTORY && !playerCache.isAuthenticated(player.getName())) {
        packetEvent.setCancelled(true);
    }
}
 
開發者ID:AuthMe,項目名稱:AuthMeReloaded,代碼行數:11,代碼來源:InventoryPacketAdapter.java

示例13: onPacketReceiving

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
@Override
public void onPacketReceiving(PacketEvent event) {
    StructureModifier<Integer> modifier = event.getPacket().getIntegers();
    Player player = event.getPlayer();

    try {
        int face = modifier.read(3);
        if (face == 255) {
            return;
        }

        int x = modifier.read(0);
        int y = modifier.read(1);
        int z = modifier.read(2);
        Location clickedBlock = new Location(player.getWorld(), x, y, z);
        clickedBlock = clickedBlock.getBlock().getLocation();

        Optional<FakeBlockSender> opt = FakeBlockSender.getFrom(player);
        if (!opt.isPresent()) {
            return;
        }

        FakeBlockSender sender = opt.get();
        FakeBlock block = sender.getBlockAt(clickedBlock.toVector());

        if (block == null) {
            return;
        }

        Location placedLocation = clickedBlock.clone();
        switch (face) {
            case 2:
                placedLocation.add(0, 0, -1);
                break;
            case 3:
                placedLocation.add(0, 0, 1);
                break;
            case 4:
                placedLocation.add(-1, 0, 0);
                break;
            case 5:
                placedLocation.add(1, 0, 0);
                break;
            default:
                return;
        }

        event.setCancelled(true);

        // Revert the block placing for the player
        if (sender.getBlockAt(placedLocation.toVector()) == null) {
            player.sendBlockChange(placedLocation, Material.AIR, (byte) 0);
            player.updateInventory();
        }
    } catch (FieldAccessException ex) {
        ex.printStackTrace();
    }
}
 
開發者ID:IPVP-MC,項目名稱:mirage,代碼行數:59,代碼來源:BlockPlaceAdapter.java

示例14: onPacketReceiving

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
@Override
public void onPacketReceiving(PacketEvent event) {
    event.setCancelled(true);
    return;
}
 
開發者ID:andylizi,項目名稱:AnimColorMOTD,代碼行數:6,代碼來源:MOTDPacketListener.java

示例15: rejectTabComplete

import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
private void rejectTabComplete(PacketEvent event) {
    this.plugin.sendTabErrorMessageIfEnabled(event.getPlayer());
    event.setCancelled(true);
}
 
開發者ID:xxyy,項目名稱:commandblockerultimate,代碼行數:5,代碼來源:TabCompletePacketListener.java


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