/** * Construct a new Bukkit unwrapper with ProtocolLib's default error reporter. */ public BukkitUnwrapper() { this(ProtocolLibrary.getErrorReporter()); }
/** * 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."); }
/** * 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; }
/** * 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); }
@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); } }
/** * 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)); } }
/** * 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()); } }); }
} catch (OutOfMemoryError e) { ProtocolLibrary.getErrorReporter().reportWarning( this, Report.newBuilder(REPORT_TOO_MANY_GENERATED_CLASSES).messageParam(compiledCache.size()) );
/** * 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; }
/** * 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()); } }
@Override public void run() { ProtocolLibrary.getErrorReporter().reportWarning(AsyncListenerHandler.this, Report. newBuilder(REPORT_HANDLER_NOT_STARTED). messageParam(listener.getPlugin(), AsyncListenerHandler.this). build() ); } }, 2 * TICKS_PER_SECOND);
ProtocolLibrary.getErrorReporter().reportDetailed(this, Report.newBuilder(REPORT_CANNOT_REVERT_CANCELLED_PACKET).error(e).callerParam(packet) );
public PacketProcessingQueue(PlayerSendingHandler sendingHandler, int initialSize, int maximumSize, int maximumConcurrency) { super(); try { this.processingQueue = Synchronization.queue(MinMaxPriorityQueue. expectedSize(initialSize). maximumSize(maximumSize). <PacketEventHolder>create(), null); } catch (IncompatibleClassChangeError e) { // Print in the console ProtocolLibrary.getErrorReporter().reportWarning( this, Report.newBuilder(REPORT_GUAVA_CORRUPT_MISSING).error(e)); // It's a Beta class after all this.processingQueue = Synchronization.queue( new PriorityQueue<PacketEventHolder>(), null); } this.maximumConcurrency = maximumConcurrency; this.concurrentProcessing = new Semaphore(maximumConcurrency); this.sendingHandler = sendingHandler; }
/** * Transmit a packet, if it hasn't already. * @param event - the packet to transmit. */ private void sendPacket(PacketEvent event) { AsyncMarker marker = event.getAsyncMarker(); try { // Don't send a packet twice if (marker != null && !marker.isTransmitted()) { marker.sendPacket(event); } } catch (PlayerLoggedOutException e) { ProtocolLibrary.getErrorReporter().reportDebug(this, Report.newBuilder(REPORT_DROPPED_PACKET). messageParam(marker.getOriginalSendingIndex(), event.getPacketType()). callerParam(event) ); } catch (IOException e) { // Just print the error e.printStackTrace(); } }
/** * Retrieve the current class source. * @return The class source. */ private static ClassSource getClassSource() { ErrorReporter reporter = ProtocolLibrary.getErrorReporter(); // Lazy pattern again if (classSource == null) { // Attempt to use MCPC try { return classSource = new RemappedClassSource().initialize(); } catch (RemapperUnavailableException e) { if (e.getReason() != Reason.MCPC_NOT_PRESENT) reporter.reportWarning(MinecraftReflection.class, Report.newBuilder(REPORT_CANNOT_FIND_MCPC_REMAPPER)); } catch (Exception e) { reporter.reportWarning(MinecraftReflection.class, Report.newBuilder(REPORT_CANNOT_LOAD_CPC_REMAPPER)); } // Just use the default class loader classSource = ClassSource.fromClassLoader(); } return classSource; }
@Override public void run() { try { if (BukkitUpdater.this.url != null) { // Obtain the results of the project's file feed if (BukkitUpdater.this.read()) { if (BukkitUpdater.this.versionCheck(BukkitUpdater.this.versionName)) { performUpdate(); } } } } catch (Exception e) { // Any generic error will be handled here ProtocolLibrary.getErrorReporter().reportDetailed( BukkitUpdater.this, Report.newBuilder(REPORT_CANNOT_UPDATE_PLUGIN).error(e).callerParam(this)); } finally { // Invoke the listeners on the main thread for (Runnable listener : listeners) { plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, listener); } } }
@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); } } } }