public static ProtocolManager get() { if (plm == null) { plm = ProtocolLibrary.getProtocolManager(); } return plm; }
/** * Called before an object is created with this builder. */ private void initializeDefaults() { ProtocolManager manager = ProtocolLibrary.getProtocolManager(); // Initialize with default values if we can if (reporter == null) reporter = ProtocolLibrary.getErrorReporter(); if (invoker == null) invoker = (PacketFilterManager) manager; if (playerInjection == null) throw new IllegalStateException("Player injection parameter must be initialized."); }
/** * Construct a new Bukkit unwrapper with ProtocolLib's default error reporter. */ public BukkitUnwrapper() { this(ProtocolLibrary.getErrorReporter()); }
@Override public void run() { try { String version = getSpigotVersion(); remoteVersion = version; if (versionCheck(version)) { result = UpdateResult.SPIGOT_UPDATE_AVAILABLE; } else { result = UpdateResult.NO_UPDATE; } } catch (Throwable ex) { if (ProtocolLibrary.getConfig().isDebug()) { ProtocolLibrary.getErrorReporter().reportDetailed( SpigotUpdater.this, Report.newBuilder(REPORT_CANNOT_UPDATE_PLUGIN).error(ex).callerParam(this)); } else { // People don't care // plugin.getLogger().log(Level.WARNING, "Failed to check for updates: " + ex); } ProtocolLibrary.disableUpdates(); } finally { // Invoke the listeners on the main thread for (Runnable listener : listeners) { plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, listener); } } } }
/** * Retrieve the default instance of the Bukkit unwrapper. * @return The default instance. */ public static BukkitUnwrapper getInstance() { ErrorReporter currentReporter = ProtocolLibrary.getErrorReporter(); // Also recreate the unwrapper if the error reporter has changed if (DEFAULT == null || DEFAULT.reporter != currentReporter) { DEFAULT = new BukkitUnwrapper(currentReporter); } return DEFAULT; }
/** * Gets the protocol manager. * * @return the protocol manager. */ @Nonnull public static ProtocolManager manager() { return ProtocolLibrary.getProtocolManager(); }
/** * Called before an object is created with this builder. */ private void initializeDefaults() { ProtocolManager manager = ProtocolLibrary.getProtocolManager(); // Initialize with default values if we can if (reporter == null) reporter = ProtocolLibrary.getErrorReporter(); if (invoker == null) invoker = (PacketFilterManager) manager; if (server == null) server = Bukkit.getServer(); if (injectionFilter == null) throw new IllegalStateException("injectionFilter must be initialized."); if (packetListeners == null) throw new IllegalStateException("packetListeners must be initialized."); }
/** * Construct a new channel injector. * @param player - the current player, or temporary player. * @param networkManager - its network manager. * @param channel - its channel. * @param channelListener - a listener. * @param factory - the factory that created this injector */ ChannelInjector(Player player, Object networkManager, Channel channel, ChannelListener channelListener, InjectionFactory factory) { this.player = Preconditions.checkNotNull(player, "player cannot be NULL"); this.networkManager = Preconditions.checkNotNull(networkManager, "networkMananger cannot be NULL"); this.originalChannel = Preconditions.checkNotNull(channel, "channel cannot be NULL"); this.channelListener = Preconditions.checkNotNull(channelListener, "channelListener cannot be NULL"); this.factory = Preconditions.checkNotNull(factory, "factory cannot be NULL"); this.processor = new NetworkProcessor(ProtocolLibrary.getErrorReporter()); // Get the channel field this.channelField = new VolatileField(FuzzyReflection .fromObject(networkManager, true) .getFieldByType("channel", Channel.class), networkManager, true); }
/** * Gets the protocol manager. * * @return the protocol manager. */ @Nonnull public static ProtocolManager manager() { return ProtocolLibrary.getProtocolManager(); }
@Override public void recieveClientPacket(final Object packet) { // TODO: Ensure the packet listeners are executed in the channel thread. // Execute this in the channel thread Runnable action = () -> { try { MinecraftMethods.getNetworkManagerReadPacketMethod().invoke(networkManager, null, packet); } catch (Exception e) { // Inform the user ProtocolLibrary.getErrorReporter().reportMinimal(factory.getPlugin(), "recieveClientPacket", e); } }; // Execute in the worker thread if (originalChannel.eventLoop().inEventLoop()) { action.run(); } else { originalChannel.eventLoop().execute(action); } }
/** * Schedule the packet transmission or reception. */ public void schedule() { schedule(ProtocolLibrary.getProtocolManager()); }
/** * Parse an UUID using very lax rules, as specified in {@link #WrappedGameProfile(UUID, String)}. * * @param id - text. * @return The corresponding UUID. * @throws IllegalArgumentException If we cannot parse the text. */ private static UUID parseUUID(String id) { if (id == null) return null; try { return UUID.fromString(id); } catch (IllegalArgumentException e) { // Warn once every hour (per plugin) ProtocolLibrary.getErrorReporter() .reportWarning(WrappedGameProfile.class, Report.newBuilder(REPORT_INVALID_UUID) .rateLimit(1, TimeUnit.HOURS) .messageParam(PluginContext.getPluginCaller(new Exception()), id)); return UUID.nameUUIDFromBytes(id.getBytes(Charsets.UTF_8)); } }
@Override public void removePacketListener(PacketListener listener) { Iterator<CommonPacketListener> iter = listeners.iterator(); while (iter.hasNext()) { CommonPacketListener cpl = iter.next(); if (cpl.listener == listener) { ProtocolLibrary.getProtocolManager().removePacketListener(cpl); iter.remove(); } } }
/** * Execute a specific command in the channel thread. * <p> * Exceptions are printed through the standard error reporter mechanism. * @param command - the command to execute. */ private void executeInChannelThread(final Runnable command) { originalChannel.eventLoop().execute(() -> { try { command.run(); } catch (Exception e) { ProtocolLibrary.getErrorReporter().reportDetailed(ChannelInjector.this, Report.newBuilder(REPORT_CANNOT_EXECUTE_IN_CHANNEL_THREAD).error(e).build()); } }); }
public static void setHearDisguisesListener(boolean enabled) { if (soundsListenerEnabled != enabled) { soundsListenerEnabled = enabled; if (soundsListenerEnabled) { ProtocolLibrary.getProtocolManager().addPacketListener(soundsListener); } else { ProtocolLibrary.getProtocolManager().removePacketListener(soundsListener); } } }
} catch (OutOfMemoryError e) { ProtocolLibrary.getErrorReporter().reportWarning( this, Report.newBuilder(REPORT_TOO_MANY_GENERATED_CLASSES).messageParam(compiledCache.size()) );
@Override public void removePacketListeners(Plugin plugin) { ProtocolLibrary.getProtocolManager().removePacketListeners(plugin); }
/** * Replace the packet that will be sent to the player. * @param packet - the packet that will be sent instead. */ public void setPacket(PacketContainer packet) { if (readOnly) throw new IllegalStateException("The packet event is read-only."); if (packet == null) throw new IllegalArgumentException("Cannot set packet to NULL. Use setCancelled() instead."); // Change warnings final PacketType oldType = this.packet.getType(); final PacketType newType = packet.getType(); if (this.packet != null && !Objects.equal(oldType, newType)) { // Only report this once if (CHANGE_WARNINGS.put(oldType, newType)) { ProtocolLibrary.getErrorReporter().reportWarning(this, Report.newBuilder(REPORT_CHANGING_PACKET_TYPE_IS_CONFUSING). messageParam(PluginContext.getPluginCaller(new Exception()), oldType, newType). build()); } } this.packet = packet; }
final WeakReference<ProtocolManager> managerRef = new WeakReference<>(ProtocolLibrary.getProtocolManager());
/** * Invoke the sendPacket method in Minecraft. * @param packet - the packet to send. */ private void invokeSendPacket(Object packet) { Validate.isTrue(!closed, "cannot send packets to a closed channel"); // Attempt to send the packet with NetworkMarker.handle(), or the PlayerConnection if its active try { if (player instanceof Factory) { MinecraftMethods.getNetworkManagerHandleMethod().invoke(networkManager, packet); } else { MinecraftMethods.getSendPacketMethod().invoke(getPlayerConnection(), packet); } } catch (Throwable ex) { ProtocolLibrary.getErrorReporter().reportWarning(this, Report.newBuilder(REPORT_CANNOT_SEND_PACKET).messageParam(packet, playerName).error(ex).build()); } }