本文整理匯總了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
}
}
}
示例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);
}
}
};
}
示例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);
}
}
}
};
}
示例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);
}
}
}
}
}
示例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);
}
}
};
}
示例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();
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
}
}
示例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());
}
}
}
}
示例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);
}
}
}
示例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);
}
}
示例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();
}
}
示例14: onPacketReceiving
import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
@Override
public void onPacketReceiving(PacketEvent event) {
event.setCancelled(true);
return;
}
示例15: rejectTabComplete
import com.comphenix.protocol.events.PacketEvent; //導入方法依賴的package包/類
private void rejectTabComplete(PacketEvent event) {
this.plugin.sendTabErrorMessageIfEnabled(event.getPlayer());
event.setCancelled(true);
}