Archiviert
13
0

Fix a ton of JavaDoc errors

Dieser Commit ist enthalten in:
Dan Mulloy 2015-06-17 14:25:39 -04:00
Ursprung 241003b56a
Commit bba1054f97
64 geänderte Dateien mit 529 neuen und 466 gelöschten Zeilen

Datei anzeigen

@ -295,7 +295,7 @@ public class CommandFilter extends CommandBase {
@Override @Override
public boolean handle(PacketEvent event, Filter filter, Exception ex) { public boolean handle(PacketEvent event, Filter filter, Exception ex) {
reporter.reportMinimal(plugin, "filterEvent(PacketEvent)", ex, event); reporter.reportMinimal(plugin, "filterEvent(PacketEvent)", ex, event);
reporter.reportWarning(this, reporter.reportWarning(this,
Report.newBuilder(REPORT_FILTER_REMOVED_FOR_ERROR).messageParam(filter.getName(), ex.getClass().getSimpleName()) Report.newBuilder(REPORT_FILTER_REMOVED_FOR_ERROR).messageParam(filter.getName(), ex.getClass().getSimpleName())
); );
return false; return false;
@ -321,7 +321,7 @@ public class CommandFilter extends CommandBase {
* @param event - the event. * @param event - the event.
* @param handler - failure handler. * @param handler - failure handler.
* @return TRUE if we should, FALSE otherwise. * @return TRUE if we should, FALSE otherwise.
* @throws FilterFailedException If one of the filters failed. * @throws ScriptException If one of the filters failed.
*/ */
public boolean filterEvent(PacketEvent event, FilterFailedHandler handler) { public boolean filterEvent(PacketEvent event, FilterFailedHandler handler) {
for (Iterator<Filter> it = filters.iterator(); it.hasNext(); ) { for (Iterator<Filter> it = filters.iterator(); it.hasNext(); ) {
@ -389,7 +389,7 @@ public class CommandFilter extends CommandBase {
// Make sure we can use the conversable interface // Make sure we can use the conversable interface
if (sender instanceof Conversable) { if (sender instanceof Conversable) {
final MultipleLinesPrompt prompt = final MultipleLinesPrompt prompt =
new MultipleLinesPrompt(new CompilationSuccessCanceller(), "function(event, packet) {"); new MultipleLinesPrompt(new CompilationSuccessCanceller(), "function(event, packet) {");
new ConversationFactory(plugin). new ConversationFactory(plugin).
@ -424,7 +424,7 @@ public class CommandFilter extends CommandBase {
whom.sendRawMessage(ChatColor.RED + "Cancelled filter."); whom.sendRawMessage(ChatColor.RED + "Cancelled filter.");
} }
} catch (Exception e) { } catch (Exception e) {
reporter.reportDetailed(this, reporter.reportDetailed(this,
Report.newBuilder(REPORT_CANNOT_HANDLE_CONVERSATION).error(e).callerParam(event) Report.newBuilder(REPORT_CANNOT_HANDLE_CONVERSATION).error(e).callerParam(event)
); );
} }

Datei anzeigen

@ -823,6 +823,7 @@ public class PacketType implements Serializable, Comparable<PacketType> {
* Construct a legacy packet type. * Construct a legacy packet type.
* @param sender - client or server. * @param sender - client or server.
* @param legacyId - the legacy packet ID. * @param legacyId - the legacy packet ID.
* @return Legacy packet type
*/ */
public static PacketType newLegacy(Sender sender, int legacyId) { public static PacketType newLegacy(Sender sender, int legacyId) {
return new PacketType(Protocol.LEGACY, sender, PacketType.UNKNOWN_PACKET, legacyId, MinecraftVersion.WORLD_UPDATE); return new PacketType(Protocol.LEGACY, sender, PacketType.UNKNOWN_PACKET, legacyId, MinecraftVersion.WORLD_UPDATE);

Datei anzeigen

@ -423,7 +423,7 @@ public class ProtocolConfig {
/** /**
* Set the starting injection method to use. * Set the starting injection method to use.
* @return Injection method. * @param hook Injection method
*/ */
public void setInjectionMethod(PlayerInjectHooks hook) { public void setInjectionMethod(PlayerInjectHooks hook) {
setConfig(global, INJECTION_METHOD, hook.name()); setConfig(global, INJECTION_METHOD, hook.name());

Datei anzeigen

@ -2,16 +2,16 @@
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland * Copyright (C) 2012 Kristian S. Stangeland
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the * This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 2 of * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * See the GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License along with this program; * You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA * 02111-1307 USA
*/ */
@ -53,7 +53,7 @@ public interface ProtocolManager extends PacketStream {
/** /**
* Send a packet to the given player. * Send a packet to the given player.
* <p> * <p>
* Re-sending a previously cancelled packet is discouraged. Use {@link AsyncMarker#incrementProcessingDelay()} * Re-sending a previously cancelled packet is discouraged. Use {@link AsyncMarker#incrementProcessingDelay()}
* to delay a packet until a certain condition has been met. * to delay a packet until a certain condition has been met.
* *
* @param receiver - the receiver. * @param receiver - the receiver.
@ -62,13 +62,13 @@ public interface ProtocolManager extends PacketStream {
* @throws InvocationTargetException - if an error occurred when sending the packet. * @throws InvocationTargetException - if an error occurred when sending the packet.
*/ */
@Override @Override
public void sendServerPacket(Player receiver, PacketContainer packet, boolean filters) public void sendServerPacket(Player receiver, PacketContainer packet, boolean filters)
throws InvocationTargetException; throws InvocationTargetException;
/** /**
* Simulate receiving a certain packet from a given player. * Simulate receiving a certain packet from a given player.
* <p> * <p>
* Receiving a previously cancelled packet is discouraged. Use {@link AsyncMarker#incrementProcessingDelay()} * Receiving a previously cancelled packet is discouraged. Use {@link AsyncMarker#incrementProcessingDelay()}
* to delay a packet until a certain condition has been met. * to delay a packet until a certain condition has been met.
* *
* @param sender - the sender. * @param sender - the sender.
@ -78,7 +78,7 @@ public interface ProtocolManager extends PacketStream {
* @throws IllegalAccessException If the underlying method caused an error. * @throws IllegalAccessException If the underlying method caused an error.
*/ */
@Override @Override
public void recieveClientPacket(Player sender, PacketContainer packet, boolean filters) public void recieveClientPacket(Player sender, PacketContainer packet, boolean filters)
throws IllegalAccessException, InvocationTargetException; throws IllegalAccessException, InvocationTargetException;
/** /**
@ -89,9 +89,9 @@ public interface ProtocolManager extends PacketStream {
public void broadcastServerPacket(PacketContainer packet); public void broadcastServerPacket(PacketContainer packet);
/** /**
* Broadcast a packet to every player that is receiving information about a given entity. * Broadcast a packet to every player that is receiving information about a given entity.
* <p> * <p>
* This is usually every player in the same world within an observable distance. If the entity is a * This is usually every player in the same world within an observable distance. If the entity is a
* player, it will only be included if <i>includeTracker</i> is TRUE. * player, it will only be included if <i>includeTracker</i> is TRUE.
* @param packet - the packet to broadcast. * @param packet - the packet to broadcast.
* @param entity - the entity whose trackers we will inform. * @param entity - the entity whose trackers we will inform.
@ -115,17 +115,17 @@ public interface ProtocolManager extends PacketStream {
public ImmutableSet<PacketListener> getPacketListeners(); public ImmutableSet<PacketListener> getPacketListeners();
/** /**
* Adds a packet listener. * Adds a packet listener.
* <p> * <p>
* Adding an already registered listener has no effect. If you need to change the packets * Adding an already registered listener has no effect. If you need to change the packets
* the current listener is observing, you must first remove the packet listener before you * the current listener is observing, you must first remove the packet listener before you
* can register it again. * can register it again.
* @param listener - new packet listener. * @param listener - new packet listener.
*/ */
public void addPacketListener(PacketListener listener); public void addPacketListener(PacketListener listener);
/** /**
* Removes a given packet listener. * Removes a given packet listener.
* <p> * <p>
* Attempting to remove a listener that doesn't exist has no effect. * Attempting to remove a listener that doesn't exist has no effect.
* @param listener - the packet listener to remove. * @param listener - the packet listener to remove.
@ -158,7 +158,7 @@ public interface ProtocolManager extends PacketStream {
/** /**
* Constructs a new encapsulated Minecraft packet with the given ID. * Constructs a new encapsulated Minecraft packet with the given ID.
* <p> * <p>
* If set to true, the <i>forceDefaults</i> option will force the system to automatically * If set to true, the <i>forceDefaults</i> option will force the system to automatically
* give non-primitive fields in the packet sensible default values. For instance, certain * give non-primitive fields in the packet sensible default values. For instance, certain
* packets - like Packet60Explosion - require a List or Set to be non-null. If the * packets - like Packet60Explosion - require a List or Set to be non-null. If the
* forceDefaults option is true, the List or Set will be automatically created. * forceDefaults option is true, the List or Set will be automatically created.
@ -175,7 +175,7 @@ public interface ProtocolManager extends PacketStream {
/** /**
* Constructs a new encapsulated Minecraft packet with the given ID. * Constructs a new encapsulated Minecraft packet with the given ID.
* <p> * <p>
* If set to true, the <i>forceDefaults</i> option will force the system to automatically * If set to true, the <i>forceDefaults</i> option will force the system to automatically
* give non-primitive fields in the packet sensible default values. For instance, certain * give non-primitive fields in the packet sensible default values. For instance, certain
* packets - like Packet60Explosion - require a List or Set to be non-null. If the * packets - like Packet60Explosion - require a List or Set to be non-null. If the
* forceDefaults option is true, the List or Set will be automatically created. * forceDefaults option is true, the List or Set will be automatically created.
@ -199,7 +199,7 @@ public interface ProtocolManager extends PacketStream {
/** /**
* Construct a packet using the special builtin Minecraft constructors. * Construct a packet using the special builtin Minecraft constructors.
* @param id - the packet type. * @param type - the packet type.
* @param arguments - arguments that will be passed to the constructor. * @param arguments - arguments that will be passed to the constructor.
* @return The packet constructor. * @return The packet constructor.
*/ */
@ -208,7 +208,7 @@ public interface ProtocolManager extends PacketStream {
/** /**
* Completely resend an entity to a list of clients. * Completely resend an entity to a list of clients.
* <p> * <p>
* Note that this method is NOT thread safe. If you call this method from anything * Note that this method is NOT thread safe. If you call this method from anything
* but the main thread, it will throw an exception. * but the main thread, it will throw an exception.
* @param entity - entity to refresh. * @param entity - entity to refresh.
* @param observers - the clients to update. * @param observers - the clients to update.
@ -269,7 +269,7 @@ public interface ProtocolManager extends PacketStream {
public MinecraftVersion getMinecraftVersion(); public MinecraftVersion getMinecraftVersion();
/** /**
* Determines whether or not this protocol manager has been disabled. * Determines whether or not this protocol manager has been disabled.
* @return TRUE if it has, FALSE otherwise. * @return TRUE if it has, FALSE otherwise.
*/ */
public boolean isClosed(); public boolean isClosed();

Datei anzeigen

@ -373,7 +373,6 @@ public class AsyncFilterManager implements AsynchronousManager {
/** /**
* Construct an async marker with the given sending priority delta and timeout delta. * Construct an async marker with the given sending priority delta and timeout delta.
* @param sendingDelta - how many packets we're willing to wait.
* @param timeoutDelta - how long (in ms) until the packet expire. * @param timeoutDelta - how long (in ms) until the packet expire.
* @return An async marker. * @return An async marker.
*/ */
@ -473,6 +472,8 @@ public class AsyncFilterManager implements AsynchronousManager {
/** /**
* Send any due packets, or clean up packets that have expired. * Send any due packets, or clean up packets that have expired.
* @param tickCounter Tick counter
* @param onMainThread Whether or not to execute on the main thread
*/ */
public void sendProcessedPackets(int tickCounter, boolean onMainThread) { public void sendProcessedPackets(int tickCounter, boolean onMainThread) {
// The server queue is unlikely to need checking that often // The server queue is unlikely to need checking that often

Datei anzeigen

@ -402,6 +402,7 @@ public class AsyncMarker implements Serializable, Comparable<AsyncMarker> {
/** /**
* Determine if Minecraft allows asynchronous processing of this packet. * Determine if Minecraft allows asynchronous processing of this packet.
* @return TRUE if it does, FALSE otherwise. * @return TRUE if it does, FALSE otherwise.
* @throws FieldAccessException If determining fails for some reasaon
*/ */
public boolean isMinecraftAsync(PacketEvent event) throws FieldAccessException { public boolean isMinecraftAsync(PacketEvent event) throws FieldAccessException {
if (isMinecraftAsync == null && !alwaysSync) { if (isMinecraftAsync == null && !alwaysSync) {

Datei anzeigen

@ -2,16 +2,16 @@
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland * Copyright (C) 2012 Kristian S. Stangeland
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the * This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 2 of * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * See the GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License along with this program; * You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA * 02111-1307 USA
*/ */
@ -35,6 +35,7 @@ public interface AsyncRunnable extends Runnable {
* <p> * <p>
* This may not occur right away. * This may not occur right away.
* @return TRUE if the thread was stopped, FALSE if it was already stopped. * @return TRUE if the thread was stopped, FALSE if it was already stopped.
* @throws InterruptedException if it is interrupted
*/ */
public boolean stop() throws InterruptedException; public boolean stop() throws InterruptedException;

Datei anzeigen

@ -18,6 +18,7 @@ public class IntegerMap<T> {
/** /**
* Construct a new integer map. * Construct a new integer map.
* @param <T> Parameter type
* @return A new integer map. * @return A new integer map.
*/ */
public static <T> IntegerMap<T> newMap() { public static <T> IntegerMap<T> newMap() {
@ -51,7 +52,7 @@ public class IntegerMap<T> {
public T put(int key, T value) { public T put(int key, T value) {
ensureCapacity(key); ensureCapacity(key);
T old = array[key]; T old = array[key];
array[key] = Preconditions.checkNotNull(value, "value cannot be NULL"); array[key] = Preconditions.checkNotNull(value, "value cannot be NULL");
if (old == null) if (old == null)

Datei anzeigen

@ -149,6 +149,7 @@ public abstract class AbstractIntervalTree<TKey extends Comparable<TKey>, TValue
* @param lowerBound - lowest value to remove. * @param lowerBound - lowest value to remove.
* @param upperBound - highest value to remove. * @param upperBound - highest value to remove.
* @param preserveDifference - whether or not to preserve the intervals that are partially outside. * @param preserveDifference - whether or not to preserve the intervals that are partially outside.
* @return Intervals that were removed
*/ */
public Set<Entry> remove(TKey lowerBound, TKey upperBound, boolean preserveDifference) { public Set<Entry> remove(TKey lowerBound, TKey upperBound, boolean preserveDifference) {
checkBounds(lowerBound, upperBound); checkBounds(lowerBound, upperBound);

Datei anzeigen

@ -2,16 +2,16 @@
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland * Copyright (C) 2012 Kristian S. Stangeland
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the * This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 2 of * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * See the GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License along with this program; * You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA * 02111-1307 USA
*/ */
@ -48,6 +48,8 @@ public class BlockingHashMap<TKey, TValue> {
/** /**
* Retrieve a cache loader that will always throw an exception. * Retrieve a cache loader that will always throw an exception.
* @param <TKey> Type of the key
* @param <TValue> Type of the value
* @return An invalid cache loader. * @return An invalid cache loader.
*/ */
public static <TKey, TValue> CacheLoader<TKey, TValue> newInvalidCacheLoader() { public static <TKey, TValue> CacheLoader<TKey, TValue> newInvalidCacheLoader() {
@ -83,6 +85,8 @@ public class BlockingHashMap<TKey, TValue> {
/** /**
* Initialize a new map. * Initialize a new map.
* @param <TKey> Type of the key
* @param <TValue> Type of the value
* @return The created map. * @return The created map.
*/ */
public static <TKey, TValue> BlockingHashMap<TKey, TValue> create() { public static <TKey, TValue> BlockingHashMap<TKey, TValue> create() {
@ -91,7 +95,7 @@ public class BlockingHashMap<TKey, TValue> {
/** /**
* Waits until a value has been associated with the given key, and then retrieves that value. * Waits until a value has been associated with the given key, and then retrieves that value.
* @param key - the key whose associated value is to be returned * @param key - the key whose associated value is to be returned
* @return The value to which the specified key is mapped. * @return The value to which the specified key is mapped.
* @throws InterruptedException If the current thread got interrupted while waiting. * @throws InterruptedException If the current thread got interrupted while waiting.
*/ */
@ -118,7 +122,7 @@ public class BlockingHashMap<TKey, TValue> {
/** /**
* Waits until a value has been associated with the given key, and then retrieves that value. * Waits until a value has been associated with the given key, and then retrieves that value.
* @param key - the key whose associated value is to be returned * @param key - the key whose associated value is to be returned
* @param timeout - the amount of time to wait until an association has been made. * @param timeout - the amount of time to wait until an association has been made.
* @param unit - unit of timeout. * @param unit - unit of timeout.
* @return The value to which the specified key is mapped, or NULL if the timeout elapsed. * @return The value to which the specified key is mapped, or NULL if the timeout elapsed.
@ -133,7 +137,7 @@ public class BlockingHashMap<TKey, TValue> {
* <p> * <p>
* If timeout is zero, this method will return immediately if it can't find an socket injector. * If timeout is zero, this method will return immediately if it can't find an socket injector.
* *
* @param key - the key whose associated value is to be returned * @param key - the key whose associated value is to be returned
* @param timeout - the amount of time to wait until an association has been made. * @param timeout - the amount of time to wait until an association has been made.
* @param unit - unit of timeout. * @param unit - unit of timeout.
* @param ignoreInterrupted - TRUE if we should ignore the thread being interrupted, FALSE otherwise. * @param ignoreInterrupted - TRUE if we should ignore the thread being interrupted, FALSE otherwise.

Datei anzeigen

@ -6,7 +6,6 @@ import java.util.Iterator;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -70,6 +69,7 @@ public class ConcurrentPlayerMap<TValue> extends AbstractMap<Player, TValue> imp
/** /**
* Construct a new concurrent player map that uses each player's address as key. * Construct a new concurrent player map that uses each player's address as key.
* @param <T> Parameter type
* @return Concurrent player map. * @return Concurrent player map.
*/ */
public static <T> ConcurrentPlayerMap<T> usingAddress() { public static <T> ConcurrentPlayerMap<T> usingAddress() {
@ -78,6 +78,7 @@ public class ConcurrentPlayerMap<TValue> extends AbstractMap<Player, TValue> imp
/** /**
* Construct a new concurrent player map that uses each player's name as key. * Construct a new concurrent player map that uses each player's name as key.
* @param <T> Parameter type
* @return Concurrent player map. * @return Concurrent player map.
*/ */
public static <T> ConcurrentPlayerMap<T> usingName() { public static <T> ConcurrentPlayerMap<T> usingName() {
@ -177,7 +178,6 @@ public class ConcurrentPlayerMap<TValue> extends AbstractMap<Player, TValue> imp
* Lookup a player by key in the cache, optionally searching every online player. * Lookup a player by key in the cache, optionally searching every online player.
* @param key - the key of the player we are locating. * @param key - the key of the player we are locating.
* @return The player, or NULL if not found. * @return The player, or NULL if not found.
* @throws ExecutionException
*/ */
protected Player lookupPlayer(Object key) { protected Player lookupPlayer(Object key) {
try { try {
@ -293,7 +293,7 @@ public class ConcurrentPlayerMap<TValue> extends AbstractMap<Player, TValue> imp
private Iterator<Entry<Player, TValue>> entryIterator() { private Iterator<Entry<Player, TValue>> entryIterator() {
// Skip entries with stale data // Skip entries with stale data
final Iterator<Entry<Object, TValue>> source = valueLookup.entrySet().iterator(); final Iterator<Entry<Object, TValue>> source = valueLookup.entrySet().iterator();
final AbstractIterator<Entry<Player,TValue>> filtered = final AbstractIterator<Entry<Player,TValue>> filtered =
new AbstractIterator<Entry<Player,TValue>>() { new AbstractIterator<Entry<Player,TValue>>() {
@Override @Override
protected Entry<Player, TValue> computeNext() { protected Entry<Player, TValue> computeNext() {
@ -315,12 +315,15 @@ public class ConcurrentPlayerMap<TValue> extends AbstractMap<Player, TValue> imp
// We can't return AbstractIterator directly, as it doesn't permitt the remove() method // We can't return AbstractIterator directly, as it doesn't permitt the remove() method
return new Iterator<Entry<Player, TValue>>() { return new Iterator<Entry<Player, TValue>>() {
@Override
public boolean hasNext() { public boolean hasNext() {
return filtered.hasNext(); return filtered.hasNext();
} }
@Override
public Entry<Player, TValue> next() { public Entry<Player, TValue> next() {
return filtered.next(); return filtered.next();
} }
@Override
public void remove() { public void remove() {
source.remove(); source.remove();
} }

Datei anzeigen

@ -2,16 +2,16 @@
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland * Copyright (C) 2012 Kristian S. Stangeland
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the * This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 2 of * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * See the GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License along with this program; * You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA * 02111-1307 USA
*/ */
@ -25,7 +25,7 @@ import java.util.Set;
/** /**
* Represents a very quick integer set that uses a lookup table to store membership. * Represents a very quick integer set that uses a lookup table to store membership.
* <p> * <p>
* This class is intentionally missing a size method. * This class is intentionally missing a size method.
* @author Kristian * @author Kristian
*/ */
public class IntegerSet { public class IntegerSet {
@ -67,7 +67,7 @@ public class IntegerSet {
/** /**
* Add the given element to the set, or do nothing if it already exists. * Add the given element to the set, or do nothing if it already exists.
* @param element - element to add. * @param element - element to add.
* @throws OutOfBoundsException If the given element is not in the range [0, count). * @throws ArrayIndexOutOfBoundsException If the given element is not in the range [0, count).
*/ */
public void add(int element) { public void add(int element) {
array[element] = true; array[element] = true;

Datei anzeigen

@ -65,7 +65,7 @@ public class PacketTypeSet {
/** /**
* Remove the given types from the set. * Remove the given types from the set.
* @param type - the types to remove. * @param types Types to remove
*/ */
public synchronized void removeAll(Iterable<? extends PacketType> types) { public synchronized void removeAll(Iterable<? extends PacketType> types) {
for (PacketType type : types) { for (PacketType type : types) {
@ -101,7 +101,7 @@ public class PacketTypeSet {
} }
/** /**
* Determine if the type of a packet is in the current set. * Determine if the type of a packet is in the current set.
* @param packet - the packet. * @param packet - the packet.
* @return TRUE if it is, FALSE otherwise. * @return TRUE if it is, FALSE otherwise.
*/ */

Datei anzeigen

@ -93,6 +93,7 @@ public class DetailedErrorReporter implements ErrorReporter {
/** /**
* Create a default error reporting system. * Create a default error reporting system.
* @param plugin - the plugin owner.
*/ */
public DetailedErrorReporter(Plugin plugin) { public DetailedErrorReporter(Plugin plugin) {
this(plugin, DEFAULT_PREFIX, DEFAULT_SUPPORT_URL); this(plugin, DEFAULT_PREFIX, DEFAULT_SUPPORT_URL);

Datei anzeigen

@ -2,16 +2,16 @@
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland * Copyright (C) 2012 Kristian S. Stangeland
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the * This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 2 of * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * See the GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License along with this program; * You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA * 02111-1307 USA
*/ */
@ -56,20 +56,20 @@ public interface ErrorReporter {
/** /**
* Prints a debug message from the current sender. * Prints a debug message from the current sender.
* @param sender - the sender. * @param sender - the sender.
* @param report - the report builder. * @param builder - the report builder.
*/ */
public abstract void reportDebug(Object sender, ReportBuilder builder); public abstract void reportDebug(Object sender, ReportBuilder builder);
/** /**
* Prints a warning message from the current plugin. * Prints a warning message from the current plugin.
* @param sender - the object containing the caller method. * @param sender - the object containing the caller method.
* @param report - an error report to include. * @param report - an error report to include.
*/ */
public abstract void reportWarning(Object sender, Report report); public abstract void reportWarning(Object sender, Report report);
/** /**
* Prints a warning message from the current plugin. * Prints a warning message from the current plugin.
* @param sender - the object containing the caller method. * @param sender - the object containing the caller method.
* @param reportBuilder - an error report builder that will be used to get the report. * @param reportBuilder - an error report builder that will be used to get the report.
*/ */
public abstract void reportWarning(Object sender, ReportBuilder reportBuilder); public abstract void reportWarning(Object sender, ReportBuilder reportBuilder);

Datei anzeigen

@ -10,7 +10,7 @@ import javax.annotation.Nullable;
* *
* @author Kristian * @author Kristian
*/ */
public class Report { public class Report {
private final ReportType type; private final ReportType type;
private final Throwable exception; private final Throwable exception;
private final Object[] messageParameters; private final Object[] messageParameters;
@ -76,7 +76,7 @@ public class Report {
} }
/** /**
* Set the minimum number of nanoseconds to wait until a report of equal type and parameters * Set the minimum number of nanoseconds to wait until a report of equal type and parameters
* is allowed to be printed again. * is allowed to be printed again.
* @param rateLimit - number of nanoseconds, or 0 to disable. Cannot be negative. * @param rateLimit - number of nanoseconds, or 0 to disable. Cannot be negative.
* @return This builder, for chaining. * @return This builder, for chaining.
@ -122,8 +122,8 @@ public class Report {
* @param type - the report type that will be used to construct the message. * @param type - the report type that will be used to construct the message.
* @param messageParameters - parameters used to construct the report message. * @param messageParameters - parameters used to construct the report message.
* @param callerParameters - parameters from the caller method. * @param callerParameters - parameters from the caller method.
*/ */
protected Report(ReportType type, @Nullable Throwable exception, protected Report(ReportType type, @Nullable Throwable exception,
@Nullable Object[] messageParameters, @Nullable Object[] callerParameters) { @Nullable Object[] messageParameters, @Nullable Object[] callerParameters) {
this(type, exception, messageParameters, callerParameters, 0); this(type, exception, messageParameters, callerParameters, 0);
} }
@ -135,8 +135,8 @@ public class Report {
* @param messageParameters - parameters used to construct the report message. * @param messageParameters - parameters used to construct the report message.
* @param callerParameters - parameters from the caller method. * @param callerParameters - parameters from the caller method.
* @param rateLimit - minimum number of nanoseconds to wait until a report of equal type and parameters is allowed to be printed again. * @param rateLimit - minimum number of nanoseconds to wait until a report of equal type and parameters is allowed to be printed again.
*/ */
protected Report(ReportType type, @Nullable Throwable exception, protected Report(ReportType type, @Nullable Throwable exception,
@Nullable Object[] messageParameters, @Nullable Object[] callerParameters, long rateLimit) { @Nullable Object[] messageParameters, @Nullable Object[] callerParameters, long rateLimit) {
if (type == null) if (type == null)
throw new IllegalArgumentException("type cannot be NULL."); throw new IllegalArgumentException("type cannot be NULL.");
@ -157,7 +157,7 @@ public class Report {
/** /**
* Retrieve the message parameters that will be used to construc the report message. * Retrieve the message parameters that will be used to construc the report message.
* <p< * <p>
* This should not be confused with the method parameters of the caller method. * This should not be confused with the method parameters of the caller method.
* @return Message parameters. * @return Message parameters.
*/ */
@ -231,8 +231,8 @@ public class Report {
return true; return true;
if (obj instanceof Report) { if (obj instanceof Report) {
Report other = (Report) obj; Report other = (Report) obj;
return type == other.type && return type == other.type &&
Arrays.equals(callerParameters, other.callerParameters) && Arrays.equals(callerParameters, other.callerParameters) &&
Arrays.equals(messageParameters, other.messageParameters); Arrays.equals(messageParameters, other.messageParameters);
} }
return false; return false;

Datei anzeigen

@ -2,16 +2,16 @@
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland * Copyright (C) 2012 Kristian S. Stangeland
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the * This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 2 of * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * See the GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License along with this program; * You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA * 02111-1307 USA
*/ */
@ -47,7 +47,7 @@ public enum ListenerPriority {
HIGHEST(4), HIGHEST(4),
/** /**
* Event is listened to purely for monitoring the outcome of an event. * Event is listened to purely for monitoring the outcome of an event.
* <p/> * <p>
* No modifications to the event should be made under this priority. * No modifications to the event should be made under this priority.
*/ */
MONITOR(5); MONITOR(5);

Datei anzeigen

@ -2,16 +2,16 @@
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland * Copyright (C) 2012 Kristian S. Stangeland
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the * This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 2 of * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * See the GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License along with this program; * You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA * 02111-1307 USA
*/ */
@ -32,7 +32,7 @@ import com.google.common.collect.Sets;
/** /**
* Determines which packets will be observed by a listener, and with what priority. * Determines which packets will be observed by a listener, and with what priority.
* @author Kristian * @author Kristian
*/ */
public class ListeningWhitelist { public class ListeningWhitelist {
/** /**
@ -60,7 +60,7 @@ public class ListeningWhitelist {
* <p> * <p>
* Deprecated: Use {@link #newBuilder()} instead. * Deprecated: Use {@link #newBuilder()} instead.
* @param priority - the listener priority. * @param priority - the listener priority.
* @param whitelist - set of IDs to observe/enable. * @param whitelist - set of IDs to observe/enable.
*/ */
@Deprecated @Deprecated
public ListeningWhitelist(ListenerPriority priority, Set<Integer> whitelist) { public ListeningWhitelist(ListenerPriority priority, Set<Integer> whitelist) {
@ -192,7 +192,7 @@ public class ListeningWhitelist {
/** /**
* Determine if any of the given IDs can be found in the whitelist. * Determine if any of the given IDs can be found in the whitelist.
* @param whitelist - whitelist to test. * @param whitelist - whitelist to test.
* @param idList - list of packet IDs to find. * @param idList - list of packet IDs to find.
* @return TRUE if any of the packets in the list can be found in the whitelist, FALSE otherwise. * @return TRUE if any of the packets in the list can be found in the whitelist, FALSE otherwise.
*/ */
public static boolean containsAny(ListeningWhitelist whitelist, int... idList) { public static boolean containsAny(ListeningWhitelist whitelist, int... idList) {
@ -442,7 +442,7 @@ public class ListeningWhitelist {
/** /**
* Set the options to copy when constructing new whitelists. * Set the options to copy when constructing new whitelists.
* @param options - the options array. * @param serverOptions - the options array.
* @return This builder, for chaining. * @return This builder, for chaining.
*/ */
public Builder options(ListenerOptions[] serverOptions) { public Builder options(ListenerOptions[] serverOptions) {
@ -452,7 +452,7 @@ public class ListeningWhitelist {
/** /**
* Options to merge into the current set of options. * Options to merge into the current set of options.
* @param options - the options array. * @param serverOptions - the options array.
* @return This builder, for chaining. * @return This builder, for chaining.
*/ */
public Builder mergeOptions(ListenerOptions... serverOptions) { public Builder mergeOptions(ListenerOptions... serverOptions) {
@ -461,7 +461,7 @@ public class ListeningWhitelist {
/** /**
* Options to merge into the current set of options. * Options to merge into the current set of options.
* @param options - the options array. * @param serverOptions - the options array.
* @return This builder, for chaining. * @return This builder, for chaining.
*/ */
public Builder mergeOptions(Collection<ListenerOptions> serverOptions) { public Builder mergeOptions(Collection<ListenerOptions> serverOptions) {

Datei anzeigen

@ -24,12 +24,12 @@ import com.google.common.collect.Lists;
import com.google.common.primitives.Ints; import com.google.common.primitives.Ints;
/** /**
* Marker containing the serialized packet data seen from the network, * Marker containing the serialized packet data seen from the network,
* or output handlers that will serialize the current packet. * or output handlers that will serialize the current packet.
* *
* @author Kristian * @author Kristian
*/ */
public abstract class NetworkMarker { public abstract class NetworkMarker {
public static class EmptyBufferMarker extends NetworkMarker { public static class EmptyBufferMarker extends NetworkMarker {
public EmptyBufferMarker(@Nonnull ConnectionSide side) { public EmptyBufferMarker(@Nonnull ConnectionSide side) {
super(side, (byte[]) null, null); super(side, (byte[]) null, null);
@ -48,7 +48,7 @@ public abstract class NetworkMarker {
@Override @Override
protected DataInputStream addHeader(DataInputStream input, PacketType type) { protected DataInputStream addHeader(DataInputStream input, PacketType type) {
throw new IllegalStateException("Buffer is empty."); throw new IllegalStateException("Buffer is empty.");
} }
} }
// Custom network handler // Custom network handler
@ -68,8 +68,9 @@ public abstract class NetworkMarker {
/** /**
* Construct a new network marker. * Construct a new network marker.
* @param side - whether or not this marker belongs to a client or server packet. * @param side - which side this marker belongs to.
* @param inputBuffer - the read serialized packet data. * @param inputBuffer - the read serialized packet data.
* @param type - packet type
*/ */
public NetworkMarker(@Nonnull ConnectionSide side, ByteBuffer inputBuffer, PacketType type) { public NetworkMarker(@Nonnull ConnectionSide side, ByteBuffer inputBuffer, PacketType type) {
this.side = Preconditions.checkNotNull(side, "side cannot be NULL."); this.side = Preconditions.checkNotNull(side, "side cannot be NULL.");
@ -81,9 +82,9 @@ public abstract class NetworkMarker {
* Construct a new network marker. * Construct a new network marker.
* <p> * <p>
* The input buffer is only non-null for client-side packets. * The input buffer is only non-null for client-side packets.
* @param side - whether or not this marker belongs to a client or server packet. * @param side - which side this marker belongs to.
* @param inputBuffer - the read serialized packet data. * @param inputBuffer - the read serialized packet data.
* @param handler - handle skipping headers. * @param type - packet type
*/ */
public NetworkMarker(@Nonnull ConnectionSide side, byte[] inputBuffer, PacketType type) { public NetworkMarker(@Nonnull ConnectionSide side, byte[] inputBuffer, PacketType type) {
this.side = Preconditions.checkNotNull(side, "side cannot be NULL."); this.side = Preconditions.checkNotNull(side, "side cannot be NULL.");
@ -115,7 +116,7 @@ public abstract class NetworkMarker {
/** /**
* Retrieve the serialized packet data (excluding the header by default) from the network input stream. * Retrieve the serialized packet data (excluding the header by default) from the network input stream.
* <p> * <p>
* The returned buffer is read-only. If the parent event is a server side packet this * The returned buffer is read-only. If the parent event is a server side packet this
* method throws {@link IllegalStateException}. * method throws {@link IllegalStateException}.
* <p> * <p>
* It returns NULL if the packet was transmitted by a plugin locally. * It returns NULL if the packet was transmitted by a plugin locally.
@ -128,7 +129,7 @@ public abstract class NetworkMarker {
/** /**
* Retrieve the serialized packet data from the network input stream. * Retrieve the serialized packet data from the network input stream.
* <p> * <p>
* The returned buffer is read-only. If the parent event is a server side packet this * The returned buffer is read-only. If the parent event is a server side packet this
* method throws {@link IllegalStateException}. * method throws {@link IllegalStateException}.
* <p> * <p>
* It returns NULL if the packet was transmitted by a plugin locally. * It returns NULL if the packet was transmitted by a plugin locally.
@ -143,7 +144,7 @@ public abstract class NetworkMarker {
ByteBuffer result = inputBuffer.asReadOnlyBuffer(); ByteBuffer result = inputBuffer.asReadOnlyBuffer();
try { try {
if (excludeHeader) if (excludeHeader)
result = skipHeader(result); result = skipHeader(result);
else else
result = addHeader(result, type); result = addHeader(result, type);
@ -158,7 +159,7 @@ public abstract class NetworkMarker {
/** /**
* Retrieve the serialized packet data (excluding the header by default) as an input stream. * Retrieve the serialized packet data (excluding the header by default) as an input stream.
* <p> * <p>
* The data is exactly the same as in {@link #getInputBuffer()}. * The data is exactly the same as in {@link #getInputBuffer()}.
* @see #getInputBuffer() * @see #getInputBuffer()
* @return The incoming serialized packet data as a stream, or NULL if the packet was transmitted locally. * @return The incoming serialized packet data as a stream, or NULL if the packet was transmitted locally.
*/ */
@ -169,7 +170,7 @@ public abstract class NetworkMarker {
/** /**
* Retrieve the serialized packet data as an input stream. * Retrieve the serialized packet data as an input stream.
* <p> * <p>
* The data is exactly the same as in {@link #getInputBuffer()}. * The data is exactly the same as in {@link #getInputBuffer()}.
* @see #getInputBuffer() * @see #getInputBuffer()
* @param excludeHeader - whether or not to exclude the packet ID header. * @param excludeHeader - whether or not to exclude the packet ID header.
* @return The incoming serialized packet data as a stream, or NULL if the packet was transmitted locally. * @return The incoming serialized packet data as a stream, or NULL if the packet was transmitted locally.
@ -186,7 +187,7 @@ public abstract class NetworkMarker {
); );
try { try {
if (excludeHeader) if (excludeHeader)
input = skipHeader(input); input = skipHeader(input);
else else
input = addHeader(input, type); input = addHeader(input, type);
@ -207,7 +208,7 @@ public abstract class NetworkMarker {
/** /**
* Enqueue the given output handler for managing how the current packet will be written to the network stream. * Enqueue the given output handler for managing how the current packet will be written to the network stream.
* <p> * <p>
* Note that output handlers are not serialized, as most consumers will probably implement them using anonymous classes. * Note that output handlers are not serialized, as most consumers will probably implement them using anonymous classes.
* It is not safe to serialize anonymous classes, as their name depend on the order in which they are declared in the parent class. * It is not safe to serialize anonymous classes, as their name depend on the order in which they are declared in the parent class.
* <p> * <p>
* This can only be invoked on server side packet events. * This can only be invoked on server side packet events.
@ -261,10 +262,10 @@ public abstract class NetworkMarker {
} }
/** /**
* Add a listener that is invoked after a packet has been successfully sent to the client, or received * Add a listener that is invoked after a packet has been successfully sent to the client, or received
* by the server. * by the server.
* <p> * <p>
* Received packets are not guarenteed to have been fully processed, but packets passed * Received packets are not guarenteed to have been fully processed, but packets passed
* to {@link ProtocolManager#recieveClientPacket(Player, PacketContainer)} will be processed after the * to {@link ProtocolManager#recieveClientPacket(Player, PacketContainer)} will be processed after the
* current packet event. * current packet event.
* <p> * <p>
@ -324,7 +325,9 @@ public abstract class NetworkMarker {
* Return a byte buffer without the header in the current packet. * Return a byte buffer without the header in the current packet.
* <p> * <p>
* It's safe to modify the position of the buffer. * It's safe to modify the position of the buffer.
* @param buffer - a read-only byte source. * @param buffer - a read-only byte source.
* @return A byte buffer without the header in the current packet.
* @throws IOException If integer reading fails
*/ */
protected ByteBuffer skipHeader(ByteBuffer buffer) throws IOException { protected ByteBuffer skipHeader(ByteBuffer buffer) throws IOException {
skipHeader(new DataInputStream(new ByteBufferInputStream(buffer))); skipHeader(new DataInputStream(new ByteBufferInputStream(buffer)));
@ -335,13 +338,14 @@ public abstract class NetworkMarker {
* Return an input stream without the header in the current packet. * Return an input stream without the header in the current packet.
* <p> * <p>
* It's safe to modify the input stream. * It's safe to modify the input stream.
* @throws IOException If integer reading fails
*/ */
protected abstract DataInputStream skipHeader(DataInputStream input) throws IOException; protected abstract DataInputStream skipHeader(DataInputStream input) throws IOException;
/** /**
* Return the byte buffer prepended with the packet header. * Return the byte buffer prepended with the packet header.
* @param buffer - the read-only byte buffer. * @param buffer - the read-only byte buffer.
* @param type - the current packet. * @param type - the current packet.
* @return The byte buffer. * @return The byte buffer.
*/ */
protected abstract ByteBuffer addHeader(ByteBuffer buffer, PacketType type); protected abstract ByteBuffer addHeader(ByteBuffer buffer, PacketType type);
@ -349,7 +353,7 @@ public abstract class NetworkMarker {
/** /**
* Return the input stream prepended with the packet header. * Return the input stream prepended with the packet header.
* @param input - the input stream. * @param input - the input stream.
* @param type - the current packet. * @param type - the current packet.
* @return The byte buffer. * @return The byte buffer.
*/ */
protected abstract DataInputStream addHeader(DataInputStream input, PacketType type); protected abstract DataInputStream addHeader(DataInputStream input, PacketType type);

Datei anzeigen

@ -2,16 +2,16 @@
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland * Copyright (C) 2012 Kristian S. Stangeland
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the * This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 2 of * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * See the GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License along with this program; * You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA * 02111-1307 USA
*/ */
@ -50,7 +50,7 @@ public abstract class PacketAdapter implements PacketListener {
*/ */
public PacketAdapter(@Nonnull AdapterParameteters params) { public PacketAdapter(@Nonnull AdapterParameteters params) {
this( this(
checkValidity(params).plugin, params.connectionSide, params.listenerPriority, checkValidity(params).plugin, params.connectionSide, params.listenerPriority,
params.gamePhase, params.options, params.packets params.gamePhase, params.options, params.packets
); );
} }
@ -58,7 +58,6 @@ public abstract class PacketAdapter implements PacketListener {
/** /**
* Initialize a packet listener with the given parameters. * Initialize a packet listener with the given parameters.
* @param plugin - the plugin. * @param plugin - the plugin.
* @param listenerPriority - the priority.
* @param types - the packet types. * @param types - the packet types.
*/ */
public PacketAdapter(Plugin plugin, PacketType... types) { public PacketAdapter(Plugin plugin, PacketType... types) {
@ -241,7 +240,7 @@ public abstract class PacketAdapter implements PacketListener {
*/ */
@Deprecated @Deprecated
public PacketAdapter( public PacketAdapter(
Plugin plugin, ConnectionSide connectionSide, ListenerPriority listenerPriority, Plugin plugin, ConnectionSide connectionSide, ListenerPriority listenerPriority,
GamePhase gamePhase, ListenerOptions[] options, Integer... packets) { GamePhase gamePhase, ListenerOptions[] options, Integer... packets) {
this(plugin, connectionSide, listenerPriority, gamePhase, options, this(plugin, connectionSide, listenerPriority, gamePhase, options,
@ -251,7 +250,7 @@ public abstract class PacketAdapter implements PacketListener {
// For internal use only // For internal use only
private PacketAdapter( private PacketAdapter(
Plugin plugin, ConnectionSide connectionSide, ListenerPriority listenerPriority, Plugin plugin, ConnectionSide connectionSide, ListenerPriority listenerPriority,
GamePhase gamePhase, ListenerOptions[] options, PacketType... packets) { GamePhase gamePhase, ListenerOptions[] options, PacketType... packets) {
if (plugin == null) if (plugin == null)
@ -272,7 +271,7 @@ public abstract class PacketAdapter implements PacketListener {
// Special case that allows us to specify optionIntercept(). // Special case that allows us to specify optionIntercept().
if (connectionSide == ConnectionSide.BOTH) { if (connectionSide == ConnectionSide.BOTH) {
serverOptions = except(serverOptions, new ListenerOptions[0], serverOptions = except(serverOptions, new ListenerOptions[0],
ListenerOptions.INTERCEPT_INPUT_BUFFER); ListenerOptions.INTERCEPT_INPUT_BUFFER);
} }
@ -360,10 +359,10 @@ public abstract class PacketAdapter implements PacketListener {
} }
@Override @Override
public String toString() { public String toString() {
// This is used by the error reporter // This is used by the error reporter
return String.format("PacketAdapter[plugin=%s, sending=%s, receiving=%s]", return String.format("PacketAdapter[plugin=%s, sending=%s, receiving=%s]",
getPluginName(this), getPluginName(this),
sendingWhitelist, sendingWhitelist,
receivingWhitelist); receivingWhitelist);
} }
@ -441,7 +440,7 @@ public abstract class PacketAdapter implements PacketListener {
} }
/** /**
* Set this adapter to also look for client-side packets. * Set this adapter to also look for client-side packets.
* @return This builder, for chaining. * @return This builder, for chaining.
*/ */
public AdapterParameteters clientSide() { public AdapterParameteters clientSide() {
@ -449,7 +448,7 @@ public abstract class PacketAdapter implements PacketListener {
} }
/** /**
* Set this adapter to also look for server-side packets. * Set this adapter to also look for server-side packets.
* @return This builder, for chaining. * @return This builder, for chaining.
*/ */
public AdapterParameteters serverSide() { public AdapterParameteters serverSide() {
@ -457,7 +456,7 @@ public abstract class PacketAdapter implements PacketListener {
} }
/** /**
* Set the the event priority, where the execution is in ascending order from lowest to highest. * Set the the event priority, where the execution is in ascending order from lowest to highest.
* <p> * <p>
* Default is {@link ListenerPriority#NORMAL}. * Default is {@link ListenerPriority#NORMAL}.
* @param listenerPriority - the new event priority. * @param listenerPriority - the new event priority.

Datei anzeigen

@ -164,10 +164,9 @@ public class PacketContainer implements Serializable {
/** /**
* Creates a packet container for an existing packet. * Creates a packet container for an existing packet.
* <p>
* Deprecated: Use {@link #PacketContainer(PacketType, Object))} instead.
* @param id - ID of the given packet. * @param id - ID of the given packet.
* @param handle - contained packet. * @param handle - contained packet.
* @deprecated Use {@link #PacketContainer(PacketType, Object)} instead
*/ */
@Deprecated @Deprecated
public PacketContainer(int id, Object handle) { public PacketContainer(int id, Object handle) {
@ -176,11 +175,10 @@ public class PacketContainer implements Serializable {
/** /**
* Creates a packet container for an existing packet. * Creates a packet container for an existing packet.
* <p>
* Deprecated: Use {@link #PacketContainer(PacketType, Object, StructureModifier))} instead.
* @param id - ID of the given packet. * @param id - ID of the given packet.
* @param handle - contained packet. * @param handle - contained packet.
* @param structure - structure modifier. * @param structure - structure modifier.
* @deprecated Use {@link #PacketContainer(PacketType, Object, StructureModifier)} instead
*/ */
@Deprecated @Deprecated
public PacketContainer(int id, Object handle, StructureModifier<Object> structure) { public PacketContainer(int id, Object handle, StructureModifier<Object> structure) {
@ -197,7 +195,7 @@ public class PacketContainer implements Serializable {
/** /**
* Creates a packet container for an existing packet. * Creates a packet container for an existing packet.
* @param id - ID of the given packet. * @param type - Type of the given packet.
* @param handle - contained packet. * @param handle - contained packet.
*/ */
public PacketContainer(PacketType type, Object handle) { public PacketContainer(PacketType type, Object handle) {
@ -206,7 +204,7 @@ public class PacketContainer implements Serializable {
/** /**
* Creates a packet container for an existing packet. * Creates a packet container for an existing packet.
* @param id - ID of the given packet. * @param type - Type of the given packet.
* @param handle - contained packet. * @param handle - contained packet.
* @param structure - structure modifier. * @param structure - structure modifier.
*/ */
@ -255,6 +253,7 @@ public class PacketContainer implements Serializable {
/** /**
* Retrieves a read/write structure for every field with the given type. * Retrieves a read/write structure for every field with the given type.
* @param <T> Type
* @param primitiveType - the type to find. * @param primitiveType - the type to find.
* @return A modifier for this specific type. * @return A modifier for this specific type.
*/ */
@ -681,7 +680,7 @@ public class PacketContainer implements Serializable {
/** /**
* Retrieve a read/write structure for the PlayerInfoData list fields in the following packet: <br> * Retrieve a read/write structure for the PlayerInfoData list fields in the following packet: <br>
* <ul> * <ul>
* <li>{@link PacketType.Play.Server.PLAYER_INFO}</li> * <li>{@link PacketType.Play.Server#PLAYER_INFO}
* </ul> * </ul>
* @return A modifier for PlayerInfoData list fields. * @return A modifier for PlayerInfoData list fields.
*/ */

Datei anzeigen

@ -2,16 +2,16 @@
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland * Copyright (C) 2012 Kristian S. Stangeland
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the * This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 2 of * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * See the GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License along with this program; * You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA * 02111-1307 USA
*/ */
@ -34,7 +34,7 @@ public interface PacketListener {
* <p> * <p>
* This method is executed on the main thread in 1.6.4 and earlier, and thus the Bukkit API is safe to use. * This method is executed on the main thread in 1.6.4 and earlier, and thus the Bukkit API is safe to use.
* <p> * <p>
* In Minecraft 1.7.2 and later, this method MAY be executed asynchronously, but only if {@link ListenerOptions#ASYNC} * In Minecraft 1.7.2 and later, this method MAY be executed asynchronously, but only if {@link ListenerOptions#ASYNC}
* have been specified in the listener. This is off by default. * have been specified in the listener. This is off by default.
* @param event - the packet that should be sent. * @param event - the packet that should be sent.
*/ */
@ -43,9 +43,9 @@ public interface PacketListener {
/** /**
* Invoked right before a received packet from a client is being processed. * Invoked right before a received packet from a client is being processed.
* <p> * <p>
* <b>WARNING</b>: </br> * <b>WARNING</b>: <br>
* This method will be called <i>asynchronously</i>! You should synchronize with the main * This method will be called <i>asynchronously</i>! You should synchronize with the main
* thread using {@link org.bukkit.scheduler.BukkitScheduler#scheduleSyncDelayedTask(Plugin, Runnable, long) scheduleSyncDelayedTask} * thread using {@link org.bukkit.scheduler.BukkitScheduler#scheduleSyncDelayedTask(Plugin, Runnable, long) scheduleSyncDelayedTask}
* if you need to call the Bukkit API. * if you need to call the Bukkit API.
* @param event - the packet that has been received. * @param event - the packet that has been received.
*/ */

Datei anzeigen

@ -2,16 +2,16 @@
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland * Copyright (C) 2012 Kristian S. Stangeland
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the * This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 2 of * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * See the GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License along with this program; * You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA * 02111-1307 USA
*/ */
@ -38,8 +38,8 @@ import com.google.common.primitives.Primitives;
* <p> * <p>
* Typical conversions include: * Typical conversions include:
* <ul> * <ul>
* <li>org.bukkit.entity.Player -> net.minecraft.server.EntityPlayer</li> * <li>org.bukkit.entity.Player to net.minecraft.server.EntityPlayer</li>
* <li>org.bukkit.World -> net.minecraft.server.WorldServer</li> * <li>org.bukkit.World to net.minecraft.server.WorldServer</li>
* </ul> * </ul>
* *
* @author Kristian * @author Kristian
@ -91,7 +91,7 @@ public class BukkitUnwrapper implements Unwrapper {
@Override @Override
public Object unwrapItem(Object wrappedObject) { public Object unwrapItem(Object wrappedObject) {
// Special case // Special case
if (wrappedObject == null) if (wrappedObject == null)
return null; return null;
Class<?> currentClass = PacketConstructor.getClass(wrappedObject); Class<?> currentClass = PacketConstructor.getClass(wrappedObject);
@ -149,7 +149,7 @@ public class BukkitUnwrapper implements Unwrapper {
try { try {
final Method find = type.getMethod("getHandle"); final Method find = type.getMethod("getHandle");
// It's thread safe, as getMethod should return the same handle // It's thread safe, as getMethod should return the same handle
Unwrapper methodUnwrapper = new Unwrapper() { Unwrapper methodUnwrapper = new Unwrapper() {
@Override @Override
public Object unwrapItem(Object wrappedObject) { public Object unwrapItem(Object wrappedObject) {
@ -159,7 +159,7 @@ public class BukkitUnwrapper implements Unwrapper {
return find.invoke(wrappedObject); return find.invoke(wrappedObject);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
reporter.reportDetailed(this, reporter.reportDetailed(this,
Report.newBuilder(REPORT_ILLEGAL_ARGUMENT).error(e).callerParam(wrappedObject, find) Report.newBuilder(REPORT_ILLEGAL_ARGUMENT).error(e).callerParam(wrappedObject, find)
); );
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
@ -178,7 +178,7 @@ public class BukkitUnwrapper implements Unwrapper {
return methodUnwrapper; return methodUnwrapper;
} catch (SecurityException e) { } catch (SecurityException e) {
reporter.reportDetailed(this, reporter.reportDetailed(this,
Report.newBuilder(REPORT_SECURITY_LIMITATION).error(e).callerParam(type) Report.newBuilder(REPORT_SECURITY_LIMITATION).error(e).callerParam(type)
); );
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
@ -188,7 +188,7 @@ public class BukkitUnwrapper implements Unwrapper {
if (fieldUnwrapper != null) if (fieldUnwrapper != null)
return fieldUnwrapper; return fieldUnwrapper;
else else
reporter.reportDetailed(this, reporter.reportDetailed(this,
Report.newBuilder(REPORT_CANNOT_FIND_UNWRAP_METHOD).error(e).callerParam(type)); Report.newBuilder(REPORT_CANNOT_FIND_UNWRAP_METHOD).error(e).callerParam(type));
} }
@ -214,7 +214,7 @@ public class BukkitUnwrapper implements Unwrapper {
return checkClass((Class<?>) wrappedObject, type, find.getType()); return checkClass((Class<?>) wrappedObject, type, find.getType());
return FieldUtils.readField(find, wrappedObject, true); return FieldUtils.readField(find, wrappedObject, true);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
reporter.reportDetailed(this, reporter.reportDetailed(this,
Report.newBuilder(REPORT_CANNOT_READ_FIELD_HANDLE).error(e).callerParam(wrappedObject, find) Report.newBuilder(REPORT_CANNOT_READ_FIELD_HANDLE).error(e).callerParam(wrappedObject, find)
); );
return null; return null;
@ -227,7 +227,7 @@ public class BukkitUnwrapper implements Unwrapper {
} else { } else {
// Inform about this too // Inform about this too
reporter.reportDetailed(this, reporter.reportDetailed(this,
Report.newBuilder(REPORT_CANNOT_READ_FIELD_HANDLE).callerParam(find) Report.newBuilder(REPORT_CANNOT_READ_FIELD_HANDLE).callerParam(find)
); );
return null; return null;

Datei anzeigen

@ -36,7 +36,7 @@ public class NetworkProcessor {
*/ */
public byte[] processOutput(PacketEvent event, NetworkMarker marker, final byte[] input) { public byte[] processOutput(PacketEvent event, NetworkMarker marker, final byte[] input) {
// Bit of a hack - but we need the performance // Bit of a hack - but we need the performance
PriorityQueue<PacketOutputHandler> handlers = (PriorityQueue<PacketOutputHandler>) PriorityQueue<PacketOutputHandler> handlers = (PriorityQueue<PacketOutputHandler>)
marker.getOutputHandlers(); marker.getOutputHandlers();
byte[] output = input; byte[] output = input;
@ -66,6 +66,7 @@ public class NetworkProcessor {
/** /**
* Invoke the post listeners and packet transmission, if any. * Invoke the post listeners and packet transmission, if any.
* @param event - PacketEvent
* @param marker - the network marker, or NULL. * @param marker - the network marker, or NULL.
*/ */
public void invokePostEvent(PacketEvent event, NetworkMarker marker) { public void invokePostEvent(PacketEvent event, NetworkMarker marker) {

Datei anzeigen

@ -2,16 +2,16 @@
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland * Copyright (C) 2012 Kristian S. Stangeland
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the * This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 2 of * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * See the GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License along with this program; * You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA * 02111-1307 USA
*/ */
@ -38,7 +38,7 @@ import com.google.common.primitives.Primitives;
*/ */
public class PacketConstructor { public class PacketConstructor {
/** /**
* A packet constructor that automatically converts Bukkit types to their NMS conterpart. * A packet constructor that automatically converts Bukkit types to their NMS conterpart.
* <p> * <p>
* Remember to call withPacket(). * Remember to call withPacket().
*/ */
@ -59,7 +59,7 @@ public class PacketConstructor {
private PacketConstructor(Constructor<?> constructorMethod) { private PacketConstructor(Constructor<?> constructorMethod) {
this.constructorMethod = constructorMethod; this.constructorMethod = constructorMethod;
this.unwrappers = Lists.newArrayList((Unwrapper) new BukkitUnwrapper(new RethrowErrorReporter() )); this.unwrappers = Lists.newArrayList((Unwrapper) new BukkitUnwrapper(new RethrowErrorReporter() ));
this.unwrappers.addAll(BukkitConverters.getUnwrappers()); this.unwrappers.addAll(BukkitConverters.getUnwrappers());
} }
private PacketConstructor(PacketType type, Constructor<?> constructorMethod, List<Unwrapper> unwrappers, Unwrapper[] paramUnwrapper) { private PacketConstructor(PacketType type, Constructor<?> constructorMethod, List<Unwrapper> unwrappers, Unwrapper[] paramUnwrapper) {
@ -104,7 +104,7 @@ public class PacketConstructor {
/** /**
* Create a packet constructor that creates packets using the given ID. * Create a packet constructor that creates packets using the given ID.
* <p> * <p>
* Note that if you pass a Class<?> as a value, it will use its type directly. * Note that if you pass a Class as a value, it will use its type directly.
* <p> * <p>
* Deprecated: Use {@link #withPacket(PacketType, Object[])} instead. * Deprecated: Use {@link #withPacket(PacketType, Object[])} instead.
* @param id - legacy (1.6.4) packet ID. * @param id - legacy (1.6.4) packet ID.
@ -120,7 +120,7 @@ public class PacketConstructor {
/** /**
* Create a packet constructor that creates packets using the given types. * Create a packet constructor that creates packets using the given types.
* <p> * <p>
* Note that if you pass a Class<?> as a value, it will use its type directly. * Note that if you pass a Class as a value, it will use its type directly.
* @param type - the type of the packet to create. * @param type - the type of the packet to create.
* @param values - the values that will match each parameter in the desired constructor. * @param values - the values that will match each parameter in the desired constructor.
* @return A packet constructor with these types. * @return A packet constructor with these types.
@ -129,7 +129,7 @@ public class PacketConstructor {
public PacketConstructor withPacket(PacketType type, Object[] values) { public PacketConstructor withPacket(PacketType type, Object[] values) {
Class<?>[] types = new Class<?>[values.length]; Class<?>[] types = new Class<?>[values.length];
Throwable lastException = null; Throwable lastException = null;
Unwrapper[] paramUnwrapper = new Unwrapper[values.length]; Unwrapper[] paramUnwrapper = new Unwrapper[values.length];
for (int i = 0; i < types.length; i++) { for (int i = 0; i < types.length; i++) {
// Default type // Default type
@ -258,7 +258,7 @@ public class PacketConstructor {
/** /**
* Convert the given wrapped object to the equivalent net.minecraft.server object. * Convert the given wrapped object to the equivalent net.minecraft.server object.
* <p> * <p>
* Note that we may pass in a class instead of object - in that case, the unwrapper should * Note that we may pass in a class instead of object - in that case, the unwrapper should
* return the equivalent NMS class. * return the equivalent NMS class.
* @param wrappedObject - wrapped object or class. * @param wrappedObject - wrapped object or class.
* @return The equivalent net.minecraft.server object or class. * @return The equivalent net.minecraft.server object or class.

Datei anzeigen

@ -223,7 +223,8 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
private boolean debug; private boolean debug;
/** /**
* Only create instances of this class if protocol lib is disabled. * Only create instances of this class if ProtocolLib is disabled.
* @param builder - PacketFilterBuilder
*/ */
public PacketFilterManager(PacketFilterBuilder builder) { public PacketFilterManager(PacketFilterBuilder builder) {
// Used to determine if injection is needed // Used to determine if injection is needed

Datei anzeigen

@ -201,7 +201,7 @@ public class NettyProtocolInjector implements ChannelListener {
/** /**
* Inject our packet handling into a specific player. * Inject our packet handling into a specific player.
* @param player * @param player Player to inject into
*/ */
public void injectPlayer(Player player) { public void injectPlayer(Player player) {
injectionFactory.fromPlayer(player, this).inject(); injectionFactory.fromPlayer(player, this).inject();

Datei anzeigen

@ -116,7 +116,10 @@ public class InterceptWritePacket {
/** /**
* Construct a new instance of the proxy object. * Construct a new instance of the proxy object.
* @return New instance of proxy, or NULL if we failed. * @param proxyObject - Object to construct proxy of
* @param event - Packet event
* @param marker - Network marker
* @return New instance of the proxy, or null if we failed.
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public Object constructProxy(Object proxyObject, PacketEvent event, NetworkMarker marker) { public Object constructProxy(Object proxyObject, PacketEvent event, NetworkMarker marker) {

Datei anzeigen

@ -2,16 +2,16 @@
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland * Copyright (C) 2012 Kristian S. Stangeland
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the * This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 2 of * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * See the GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License along with this program; * You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA * 02111-1307 USA
*/ */
@ -96,7 +96,7 @@ public class PacketRegistry {
return NETTY.getPacketTypeLookup().containsKey(type); return NETTY.getPacketTypeLookup().containsKey(type);
// Look up the correct type // Look up the correct type
return type.isClient() ? return type.isClient() ?
LEGACY.getClientPackets().contains(type.getLegacyId()) : LEGACY.getClientPackets().contains(type.getLegacyId()) :
LEGACY.getServerPackets().contains(type.getLegacyId()); LEGACY.getServerPackets().contains(type.getLegacyId());
} }
@ -120,7 +120,7 @@ public class PacketRegistry {
); );
} }
} catch (CannotFindTroveNoEntryValue e) { } catch (CannotFindTroveNoEntryValue e) {
ProtocolLibrary.getErrorReporter().reportWarning(PacketRegistry.class, ProtocolLibrary.getErrorReporter().reportWarning(PacketRegistry.class,
Report.newBuilder(REPORT_CANNOT_CORRECT_TROVE_MAP).error(e.getCause())); Report.newBuilder(REPORT_CANNOT_CORRECT_TROVE_MAP).error(e.getCause()));
} }
} }
@ -139,6 +139,7 @@ public class PacketRegistry {
if (NETTY != null) { if (NETTY != null) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<Class, Integer> result = (Map)Maps.transformValues(NETTY.getPacketClassLookup(), new Function<PacketType, Integer>() { Map<Class, Integer> result = (Map)Maps.transformValues(NETTY.getPacketClassLookup(), new Function<PacketType, Integer>() {
@Override
public Integer apply(PacketType type) { public Integer apply(PacketType type) {
return type.getLegacyId(); return type.getLegacyId();
}; };
@ -161,6 +162,7 @@ public class PacketRegistry {
return result; return result;
} }
return Maps.transformValues(LEGACY.getPacketToID(), new Function<Integer, PacketType>() { return Maps.transformValues(LEGACY.getPacketToID(), new Function<Integer, PacketType>() {
@Override
public PacketType apply(Integer packetId) { public PacketType apply(Integer packetId) {
return PacketType.findLegacy(packetId); return PacketType.findLegacy(packetId);
}; };
@ -288,7 +290,7 @@ public class PacketRegistry {
* @param types - packet type. * @param types - packet type.
* @return Set of integers. * @return Set of integers.
*/ */
public static Set<Integer> toLegacy(Set<PacketType> types) { public static Set<Integer> toLegacy(Set<PacketType> types) {
Set<Integer> result = Sets.newHashSet(); Set<Integer> result = Sets.newHashSet();
for (PacketType type : types) for (PacketType type : types)
@ -298,20 +300,20 @@ public class PacketRegistry {
/** /**
* Convert a set of legacy packet IDs to packet types. * Convert a set of legacy packet IDs to packet types.
* @param types - legacy packet IDs. * @param ids - legacy packet IDs.
* @return Set of packet types. * @return Set of packet types.
*/ */
public static Set<PacketType> toPacketTypes(Set<Integer> ids) { public static Set<PacketType> toPacketTypes(Set<Integer> ids) {
return toPacketTypes(ids, null); return toPacketTypes(ids, null);
} }
/** /**
* Convert a set of legacy packet IDs to packet types. * Convert a set of legacy packet IDs to packet types.
* @param types - legacy packet IDs. * @param ids - legacy packet IDs.
* @param preference - the sender preference, if any. * @param preference - the sender preference, if any.
* @return Set of packet types. * @return Set of packet types.
*/ */
public static Set<PacketType> toPacketTypes(Set<Integer> ids, Sender preference) { public static Set<PacketType> toPacketTypes(Set<Integer> ids, Sender preference) {
Set<PacketType> result = Sets.newHashSet(); Set<PacketType> result = Sets.newHashSet();
for (int id : ids) for (int id : ids)
@ -417,7 +419,7 @@ public class PacketRegistry {
} else { } else {
final int id = LEGACY.getPacketID(packet); final int id = LEGACY.getPacketID(packet);
return PacketType.hasLegacy(id) ? return PacketType.hasLegacy(id) ?
PacketType.fromLegacy(id, sender) : null; PacketType.fromLegacy(id, sender) : null;
} }
} }

Datei anzeigen

@ -129,7 +129,7 @@ public interface PlayerInjectionHandler {
* Send the given packet to the given receiver. * Send the given packet to the given receiver.
* @param receiver - the player receiver. * @param receiver - the player receiver.
* @param packet - the packet to send. * @param packet - the packet to send.
* @param marker * @param marker - network marker.
* @param filters - whether or not to invoke the packet filters. * @param filters - whether or not to invoke the packet filters.
* @throws InvocationTargetException If an error occurred during sending. * @throws InvocationTargetException If an error occurred during sending.
*/ */

Datei anzeigen

@ -156,6 +156,7 @@ public abstract class PlayerInjector implements SocketInjector {
/** /**
* Initialize all fields for this player injector, if it hasn't already. * Initialize all fields for this player injector, if it hasn't already.
* @param injectionSource - Injection source
* @throws IllegalAccessException An error has occured. * @throws IllegalAccessException An error has occured.
*/ */
public void initialize(Object injectionSource) throws IllegalAccessException { public void initialize(Object injectionSource) throws IllegalAccessException {
@ -442,6 +443,7 @@ public abstract class PlayerInjector implements SocketInjector {
/** /**
* Retrieves the current net handler for this player. * Retrieves the current net handler for this player.
* @boolean refresh - Whether or not to refresh
* @return Current net handler. * @return Current net handler.
* @throws IllegalAccessException Unable to find or retrieve net handler. * @throws IllegalAccessException Unable to find or retrieve net handler.
*/ */
@ -562,6 +564,7 @@ public abstract class PlayerInjector implements SocketInjector {
/** /**
* Determine if this inject method can even be attempted. * Determine if this inject method can even be attempted.
* @param GamePhase - Game phase
* @return TRUE if can be attempted, though possibly with failure, FALSE otherwise. * @return TRUE if can be attempted, though possibly with failure, FALSE otherwise.
*/ */
public abstract boolean canInject(GamePhase state); public abstract boolean canInject(GamePhase state);

Datei anzeigen

@ -42,11 +42,12 @@ public interface SocketInjector {
* @param filtered - whether or not the packet will be filtered by our listeners. * @param filtered - whether or not the packet will be filtered by our listeners.
* @throws InvocationTargetException If an error occured when sending the packet. * @throws InvocationTargetException If an error occured when sending the packet.
*/ */
public abstract void sendServerPacket(Object packet, NetworkMarker marker, boolean filtered) public abstract void sendServerPacket(Object packet, NetworkMarker marker, boolean filtered)
throws InvocationTargetException; throws InvocationTargetException;
/** /**
* Retrieve the hooked player. * Retrieve the hooked player.
* @return The hooked player.
*/ */
public abstract Player getPlayer(); public abstract Player getPlayer();
@ -57,7 +58,7 @@ public interface SocketInjector {
public abstract Player getUpdatedPlayer(); public abstract Player getUpdatedPlayer();
/** /**
* Invoked when a delegated socket injector transfers the state of one injector to the next. * Invoked when a delegated socket injector transfers the state of one injector to the next.
* @param delegate - the new injector. * @param delegate - the new injector.
*/ */
public abstract void transferState(SocketInjector delegate); public abstract void transferState(SocketInjector delegate);

Datei anzeigen

@ -268,7 +268,7 @@ public class Metrics {
/** /**
* Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task. * Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
* *
* @throws java.io.IOException * @throws IOException If configuration saving fails
*/ */
public void enable() throws IOException { public void enable() throws IOException {
// This has to be synchronized or it can collide with the check in the task. // This has to be synchronized or it can collide with the check in the task.
@ -289,7 +289,7 @@ public class Metrics {
/** /**
* Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task. * Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task.
* *
* @throws java.io.IOException * @throws IOException If configuration saving fails
*/ */
public void disable() throws IOException { public void disable() throws IOException {
// This has to be synchronized or it can collide with the check in the task. // This has to be synchronized or it can collide with the check in the task.
@ -327,6 +327,8 @@ public class Metrics {
/** /**
* Generic method that posts a plugin to the metrics website * Generic method that posts a plugin to the metrics website
*
* @throws IOException If posting fails
*/ */
private void postPlugin(final boolean isPing) throws IOException { private void postPlugin(final boolean isPing) throws IOException {
// Server software specific section // Server software specific section
@ -496,8 +498,8 @@ public class Metrics {
/** /**
* GZip compress a string of bytes * GZip compress a string of bytes
* *
* @param input * @param input Input to compress
* @return * @return Compressed string
*/ */
public static byte[] gzip(String input) { public static byte[] gzip(String input) {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
@ -532,14 +534,7 @@ public class Metrics {
} }
} }
/** // Appends a json encoded key/value pair to the given string builder.
* Appends a json encoded key/value pair to the given string builder.
*
* @param json
* @param key
* @param value
* @throws UnsupportedEncodingException
*/
private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException { private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException {
boolean isValueNumeric = false; boolean isValueNumeric = false;
@ -566,12 +561,7 @@ public class Metrics {
} }
} }
/** // Escape a string to create a valid JSON string
* Escape a string to create a valid JSON string
*
* @param text
* @return
*/
private static String escapeJSON(String text) { private static String escapeJSON(String text) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
@ -612,12 +602,7 @@ public class Metrics {
return builder.toString(); return builder.toString();
} }
/** // Encode text as UTF-8
* Encode text as UTF-8
*
* @param text the text to encode
* @return the encoded text, as UTF-8
*/
private static String urlEncode(final String text) throws UnsupportedEncodingException { private static String urlEncode(final String text) throws UnsupportedEncodingException {
return URLEncoder.encode(text, "UTF-8"); return URLEncoder.encode(text, "UTF-8");
} }

Datei anzeigen

@ -14,7 +14,7 @@ import com.comphenix.protocol.reflect.compiler.EmptyClassVisitor;
import com.comphenix.protocol.reflect.compiler.EmptyMethodVisitor; import com.comphenix.protocol.reflect.compiler.EmptyMethodVisitor;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
public class ClassAnalyser { public class ClassAnalyser {
/** /**
* Represents a method in ASM. * Represents a method in ASM.
* <p> * <p>
@ -68,7 +68,7 @@ public class ClassAnalyser {
/** /**
* Retrieve the associated owner class. * Retrieve the associated owner class.
* @return The owner class. * @return The owner class.
* @throws ClassNotFoundException * @throws ClassNotFoundException If the class was not found
*/ */
public Class<?> getOwnerClass() throws ClassNotFoundException { public Class<?> getOwnerClass() throws ClassNotFoundException {
return AsmMethod.class.getClassLoader().loadClass(getOwnerName().replace('/', '.')); return AsmMethod.class.getClassLoader().loadClass(getOwnerName().replace('/', '.'));

Datei anzeigen

@ -2,16 +2,16 @@
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland * Copyright (C) 2012 Kristian S. Stangeland
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the * This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 2 of * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * See the GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License along with this program; * You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA * 02111-1307 USA
*/ */
@ -93,6 +93,7 @@ public class FuzzyReflection {
/** /**
* Retrieve the value of the first field of the given type. * Retrieve the value of the first field of the given type.
* @param <T> Type
* @param instance - the instance to retrieve from. * @param instance - the instance to retrieve from.
* @param fieldClass - type of the field to retrieve. * @param fieldClass - type of the field to retrieve.
* @param forceAccess - whether or not to look for private and protected fields. * @param forceAccess - whether or not to look for private and protected fields.
@ -107,6 +108,7 @@ public class FuzzyReflection {
/** /**
* Retrieves the underlying class. * Retrieves the underlying class.
* @return The underlying class.
*/ */
public Class<?> getSource() { public Class<?> getSource() {
return source; return source;
@ -117,7 +119,7 @@ public class FuzzyReflection {
* @return The singleton instance. * @return The singleton instance.
* @throws IllegalStateException If the class has no singleton. * @throws IllegalStateException If the class has no singleton.
*/ */
public Object getSingleton() { public Object getSingleton() {
Method method = null; Method method = null;
Field field = null; Field field = null;
@ -203,12 +205,12 @@ public class FuzzyReflection {
for (Method method : getMethods()) { for (Method method : getMethods()) {
if (match.matcher(method.getName()).matches()) { if (match.matcher(method.getName()).matches()) {
// Right - this is probably it. // Right - this is probably it.
return method; return method;
} }
} }
throw new IllegalArgumentException("Unable to find a method with the pattern " + throw new IllegalArgumentException("Unable to find a method with the pattern " +
nameRegex + " in " + source.getName()); nameRegex + " in " + source.getName());
} }
@ -341,13 +343,13 @@ public class FuzzyReflection {
for (Field field : getFields()) { for (Field field : getFields()) {
if (match.matcher(field.getName()).matches()) { if (match.matcher(field.getName()).matches()) {
// Right - this is probably it. // Right - this is probably it.
return field; return field;
} }
} }
// Looks like we're outdated. Too bad. // Looks like we're outdated. Too bad.
throw new IllegalArgumentException("Unable to find a field with the pattern " + throw new IllegalArgumentException("Unable to find a field with the pattern " +
nameRegex + " in " + source.getName()); nameRegex + " in " + source.getName());
} }
@ -428,7 +430,7 @@ public class FuzzyReflection {
/** /**
* Retrieves a field by type. * Retrieves a field by type.
* <p> * <p>
* Note that the type is matched using the full canonical representation, i.e.: * Note that the type is matched using the full canonical representation, i.e.:
* <ul> * <ul>
* <li>java.util.List</li> * <li>java.util.List</li>
* <li>net.comphenix.xp.ExperienceMod</li> * <li>net.comphenix.xp.ExperienceMod</li>
@ -451,14 +453,14 @@ public class FuzzyReflection {
} }
// Looks like we're outdated. Too bad. // Looks like we're outdated. Too bad.
throw new IllegalArgumentException("Unable to find a field with the type " + throw new IllegalArgumentException("Unable to find a field with the type " +
typeRegex + " in " + source.getName()); typeRegex + " in " + source.getName());
} }
/** /**
* Retrieves a field by type. * Retrieves a field by type.
* <p> * <p>
* Note that the type is matched using the full canonical representation, i.e.: * Note that the type is matched using the full canonical representation, i.e.:
* <ul> * <ul>
* <li>java.util.List</li> * <li>java.util.List</li>
* <li>net.comphenix.xp.ExperienceMod</li> * <li>net.comphenix.xp.ExperienceMod</li>
@ -483,7 +485,7 @@ public class FuzzyReflection {
} }
// Looks like we're outdated. Too bad. // Looks like we're outdated. Too bad.
throw new IllegalArgumentException("Unable to find a field with the type " + throw new IllegalArgumentException("Unable to find a field with the type " +
typeRegex + " in " + source.getName()); typeRegex + " in " + source.getName());
} }
@ -505,7 +507,7 @@ public class FuzzyReflection {
} }
/** /**
* Retrieve every method as a map over names. * Retrieve every method as a map over names.
* <p> * <p>
* Note that overloaded methods will only occur once in the resulting map. * Note that overloaded methods will only occur once in the resulting map.
* @param methods - every method. * @param methods - every method.

Datei anzeigen

@ -38,10 +38,10 @@ import org.bukkit.Bukkit;
* Reflection locates these methods fine and correctly assigns them as public. * Reflection locates these methods fine and correctly assigns them as public.
* However, an <code>IllegalAccessException</code> is thrown if the method is invoked.</p> * However, an <code>IllegalAccessException</code> is thrown if the method is invoked.</p>
* *
* <p><code>MethodUtils</code> contains a workaround for this situation. * <p><code>MethodUtils</code> contains a workaround for this situation.
* It will attempt to call <code>setAccessible</code> on this method. * It will attempt to call <code>setAccessible</code> on this method.
* If this call succeeds, then the method can be invoked as normal. * If this call succeeds, then the method can be invoked as normal.
* This call will only succeed when the application has sufficient security privilages. * This call will only succeed when the application has sufficient security privilages.
* If this call fails then a warning will be logged and the method may fail.</p> * If this call fails then a warning will be logged and the method may fail.</p>
* *
* @author Craig R. McClanahan * @author Craig R. McClanahan
@ -58,7 +58,7 @@ public class MethodUtils {
// --------------------------------------------------------- Private Methods // --------------------------------------------------------- Private Methods
/** /**
* Only log warning about accessibility work around once. * Only log warning about accessibility work around once.
* <p> * <p>
* Note that this is broken when this class is deployed via a shared * Note that this is broken when this class is deployed via a shared
@ -71,7 +71,7 @@ public class MethodUtils {
*/ */
private static boolean loggedAccessibleWarning = false; private static boolean loggedAccessibleWarning = false;
/** /**
* Indicates whether methods should be cached for improved performance. * Indicates whether methods should be cached for improved performance.
* <p> * <p>
* Note that when this class is deployed via a shared classloader in * Note that when this class is deployed via a shared classloader in
@ -91,9 +91,9 @@ public class MethodUtils {
* <p> * <p>
* The keys into this map only ever exist as temporary variables within * The keys into this map only ever exist as temporary variables within
* methods of this class, and are never exposed to users of this class. * methods of this class, and are never exposed to users of this class.
* This means that the WeakHashMap is used only as a mechanism for * This means that the WeakHashMap is used only as a mechanism for
* limiting the size of the cache, ie a way to tell the garbage collector * limiting the size of the cache, ie a way to tell the garbage collector
* that the contents of the cache can be completely garbage-collected * that the contents of the cache can be completely garbage-collected
* whenever it needs the memory. Whether this is a good approach to * whenever it needs the memory. Whether this is a good approach to
* this problem is doubtful; something like the commons-collections * this problem is doubtful; something like the commons-collections
* LRUMap may be more appropriate (though of course selecting an * LRUMap may be more appropriate (though of course selecting an
@ -140,12 +140,12 @@ public class MethodUtils {
/** /**
* <p>Invoke a named method whose parameter type matches the object type.</p> * <p>Invoke a named method whose parameter type matches the object type.</p>
* *
* <p>The behaviour of this method is less deterministic * <p>The behaviour of this method is less deterministic
* than <code>invokeExactMethod()</code>. * than <code>invokeExactMethod()</code>.
* It loops through all methods with names that match * It loops through all methods with names that match
* and then executes the first it finds with compatable parameters.</p> * and then executes the first it finds with compatable parameters.</p>
* *
* <p>This method supports calls to methods taking primitive parameters * <p>This method supports calls to methods taking primitive parameters
* via passing in wrapping classes. So, for example, a <code>Boolean</code> class * via passing in wrapping classes. So, for example, a <code>Boolean</code> class
* would match a <code>boolean</code> primitive.</p> * would match a <code>boolean</code> primitive.</p>
* *
@ -182,12 +182,12 @@ public class MethodUtils {
/** /**
* <p>Invoke a named method whose parameter type matches the object type.</p> * <p>Invoke a named method whose parameter type matches the object type.</p>
* *
* <p>The behaviour of this method is less deterministic * <p>The behaviour of this method is less deterministic
* than {@link #invokeExactMethod(Object object,String methodName,Object [] args)}. * than {@link #invokeExactMethod(Object object,String methodName,Object [] args)}.
* It loops through all methods with names that match * It loops through all methods with names that match
* and then executes the first it finds with compatable parameters.</p> * and then executes the first it finds with compatable parameters.</p>
* *
* <p>This method supports calls to methods taking primitive parameters * <p>This method supports calls to methods taking primitive parameters
* via passing in wrapping classes. So, for example, a <code>Boolean</code> class * via passing in wrapping classes. So, for example, a <code>Boolean</code> class
* would match a <code>boolean</code> primitive.</p> * would match a <code>boolean</code> primitive.</p>
* *
@ -217,7 +217,7 @@ public class MethodUtils {
if (args == null) { if (args == null) {
args = EMPTY_OBJECT_ARRAY; args = EMPTY_OBJECT_ARRAY;
} }
int arguments = args.length; int arguments = args.length;
Class[] parameterTypes = new Class[arguments]; Class[] parameterTypes = new Class[arguments];
for (int i = 0; i < arguments; i++) { for (int i = 0; i < arguments; i++) {
@ -231,13 +231,13 @@ public class MethodUtils {
/** /**
* <p>Invoke a named method whose parameter type matches the object type.</p> * <p>Invoke a named method whose parameter type matches the object type.</p>
* *
* <p>The behaviour of this method is less deterministic * <p>The behaviour of this method is less deterministic
* than {@link * than {@link
* #invokeExactMethod(Object object,String methodName,Object [] args,Class[] parameterTypes)}. * #invokeExactMethod(Object object,String methodName,Object [] args,Class[] parameterTypes)}.
* It loops through all methods with names that match * It loops through all methods with names that match
* and then executes the first it finds with compatable parameters.</p> * and then executes the first it finds with compatable parameters.</p>
* *
* <p>This method supports calls to methods taking primitive parameters * <p>This method supports calls to methods taking primitive parameters
* via passing in wrapping classes. So, for example, a <code>Boolean</code> class * via passing in wrapping classes. So, for example, a <code>Boolean</code> class
* would match a <code>boolean</code> primitive.</p> * would match a <code>boolean</code> primitive.</p>
* *
@ -266,10 +266,10 @@ public class MethodUtils {
if (parameterTypes == null) { if (parameterTypes == null) {
parameterTypes = EMPTY_CLASS_PARAMETERS; parameterTypes = EMPTY_CLASS_PARAMETERS;
} }
if (args == null) { if (args == null) {
args = EMPTY_OBJECT_ARRAY; args = EMPTY_OBJECT_ARRAY;
} }
Method method = getMatchingAccessibleMethod( Method method = getMatchingAccessibleMethod(
object.getClass(), object.getClass(),
@ -345,7 +345,7 @@ public class MethodUtils {
InvocationTargetException { InvocationTargetException {
if (args == null) { if (args == null) {
args = EMPTY_OBJECT_ARRAY; args = EMPTY_OBJECT_ARRAY;
} }
int arguments = args.length; int arguments = args.length;
Class[] parameterTypes = new Class[arguments]; Class[] parameterTypes = new Class[arguments];
for (int i = 0; i < arguments; i++) { for (int i = 0; i < arguments; i++) {
@ -387,7 +387,7 @@ public class MethodUtils {
if (args == null) { if (args == null) {
args = EMPTY_OBJECT_ARRAY; args = EMPTY_OBJECT_ARRAY;
} }
if (parameterTypes == null) { if (parameterTypes == null) {
parameterTypes = EMPTY_CLASS_PARAMETERS; parameterTypes = EMPTY_CLASS_PARAMETERS;
@ -437,7 +437,7 @@ public class MethodUtils {
if (args == null) { if (args == null) {
args = EMPTY_OBJECT_ARRAY; args = EMPTY_OBJECT_ARRAY;
} }
if (parameterTypes == null) { if (parameterTypes == null) {
parameterTypes = EMPTY_CLASS_PARAMETERS; parameterTypes = EMPTY_CLASS_PARAMETERS;
@ -458,12 +458,12 @@ public class MethodUtils {
/** /**
* <p>Invoke a named static method whose parameter type matches the object type.</p> * <p>Invoke a named static method whose parameter type matches the object type.</p>
* *
* <p>The behaviour of this method is less deterministic * <p>The behaviour of this method is less deterministic
* than {@link #invokeExactMethod(Object, String, Object[], Class[])}. * than {@link #invokeExactMethod(Object, String, Object[], Class[])}.
* It loops through all methods with names that match * It loops through all methods with names that match
* and then executes the first it finds with compatable parameters.</p> * and then executes the first it finds with compatable parameters.</p>
* *
* <p>This method supports calls to methods taking primitive parameters * <p>This method supports calls to methods taking primitive parameters
* via passing in wrapping classes. So, for example, a <code>Boolean</code> class * via passing in wrapping classes. So, for example, a <code>Boolean</code> class
* would match a <code>boolean</code> primitive.</p> * would match a <code>boolean</code> primitive.</p>
* *
@ -501,12 +501,12 @@ public class MethodUtils {
/** /**
* <p>Invoke a named static method whose parameter type matches the object type.</p> * <p>Invoke a named static method whose parameter type matches the object type.</p>
* *
* <p>The behaviour of this method is less deterministic * <p>The behaviour of this method is less deterministic
* than {@link #invokeExactMethod(Object object,String methodName,Object [] args)}. * than {@link #invokeExactMethod(Object object,String methodName,Object [] args)}.
* It loops through all methods with names that match * It loops through all methods with names that match
* and then executes the first it finds with compatable parameters.</p> * and then executes the first it finds with compatable parameters.</p>
* *
* <p>This method supports calls to methods taking primitive parameters * <p>This method supports calls to methods taking primitive parameters
* via passing in wrapping classes. So, for example, a <code>Boolean</code> class * via passing in wrapping classes. So, for example, a <code>Boolean</code> class
* would match a <code>boolean</code> primitive.</p> * would match a <code>boolean</code> primitive.</p>
* *
@ -537,7 +537,7 @@ public class MethodUtils {
if (args == null) { if (args == null) {
args = EMPTY_OBJECT_ARRAY; args = EMPTY_OBJECT_ARRAY;
} }
int arguments = args.length; int arguments = args.length;
Class[] parameterTypes = new Class[arguments]; Class[] parameterTypes = new Class[arguments];
for (int i = 0; i < arguments; i++) { for (int i = 0; i < arguments; i++) {
@ -551,13 +551,13 @@ public class MethodUtils {
/** /**
* <p>Invoke a named static method whose parameter type matches the object type.</p> * <p>Invoke a named static method whose parameter type matches the object type.</p>
* *
* <p>The behaviour of this method is less deterministic * <p>The behaviour of this method is less deterministic
* than {@link * than {@link
* #invokeExactStaticMethod(Class objectClass,String methodName,Object [] args,Class[] parameterTypes)}. * #invokeExactStaticMethod(Class objectClass,String methodName,Object [] args,Class[] parameterTypes)}.
* It loops through all methods with names that match * It loops through all methods with names that match
* and then executes the first it finds with compatable parameters.</p> * and then executes the first it finds with compatable parameters.</p>
* *
* <p>This method supports calls to methods taking primitive parameters * <p>This method supports calls to methods taking primitive parameters
* via passing in wrapping classes. So, for example, a <code>Boolean</code> class * via passing in wrapping classes. So, for example, a <code>Boolean</code> class
* would match a <code>boolean</code> primitive.</p> * would match a <code>boolean</code> primitive.</p>
* *
@ -587,10 +587,10 @@ public class MethodUtils {
if (parameterTypes == null) { if (parameterTypes == null) {
parameterTypes = EMPTY_CLASS_PARAMETERS; parameterTypes = EMPTY_CLASS_PARAMETERS;
} }
if (args == null) { if (args == null) {
args = EMPTY_OBJECT_ARRAY; args = EMPTY_OBJECT_ARRAY;
} }
Method method = getMatchingAccessibleMethod( Method method = getMatchingAccessibleMethod(
objectClass, objectClass,
@ -668,7 +668,7 @@ public class MethodUtils {
InvocationTargetException { InvocationTargetException {
if (args == null) { if (args == null) {
args = EMPTY_OBJECT_ARRAY; args = EMPTY_OBJECT_ARRAY;
} }
int arguments = args.length; int arguments = args.length;
Class[] parameterTypes = new Class[arguments]; Class[] parameterTypes = new Class[arguments];
for (int i = 0; i < arguments; i++) { for (int i = 0; i < arguments; i++) {
@ -890,16 +890,16 @@ public class MethodUtils {
/** /**
* <p>Find an accessible method that matches the given name and has compatible parameters. * <p>Find an accessible method that matches the given name and has compatible parameters.
* Compatible parameters mean that every method parameter is assignable from * Compatible parameters mean that every method parameter is assignable from
* the given parameters. * the given parameters.
* In other words, it finds a method with the given name * In other words, it finds a method with the given name
* that will take the parameters given.<p> * that will take the parameters given.</p>
* *
* <p>This method is slightly undeterminstic since it loops * <p>This method is slightly undeterminstic since it loops
* through methods names and return the first matching method.</p> * through methods names and return the first matching method.</p>
* *
* <p>This method is used by * <p>This method is used by
* {@link * {@link
* #invokeMethod(Object object,String methodName,Object [] args,Class[] parameterTypes)}. * #invokeMethod(Object object,String methodName,Object [] args,Class[] parameterTypes)}.
* *
* <p>This method can match primitive parameter by passing in wrapper classes. * <p>This method can match primitive parameter by passing in wrapper classes.
@ -908,7 +908,7 @@ public class MethodUtils {
* *
* @param clazz find method in this class * @param clazz find method in this class
* @param methodName find method with this name * @param methodName find method with this name
* @param parameterTypes find method with compatible parameters * @param parameterTypes find method with compatible parameters
* @return The accessible method * @return The accessible method
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -938,19 +938,19 @@ public class MethodUtils {
} catch (NoSuchMethodException e) { /* SWALLOW */ } } catch (NoSuchMethodException e) { /* SWALLOW */ }
// search through all methods // search through all methods
int paramSize = parameterTypes.length; int paramSize = parameterTypes.length;
Method bestMatch = null; Method bestMatch = null;
Method[] methods = clazz.getMethods(); Method[] methods = clazz.getMethods();
float bestMatchCost = Float.MAX_VALUE; float bestMatchCost = Float.MAX_VALUE;
float myCost = Float.MAX_VALUE; float myCost = Float.MAX_VALUE;
for (int i = 0, size = methods.length; i < size ; i++) { for (int i = 0, size = methods.length; i < size ; i++) {
if (methods[i].getName().equals(methodName)) { if (methods[i].getName().equals(methodName)) {
// compare parameters // compare parameters
Class[] methodsParams = methods[i].getParameterTypes(); Class[] methodsParams = methods[i].getParameterTypes();
int methodParamSize = methodsParams.length; int methodParamSize = methodsParams.length;
if (methodParamSize == paramSize) { if (methodParamSize == paramSize) {
boolean match = true; boolean match = true;
for (int n = 0 ; n < methodParamSize; n++) { for (int n = 0 ; n < methodParamSize; n++) {
if (!isAssignmentCompatible(methodsParams[n], parameterTypes[n])) { if (!isAssignmentCompatible(methodsParams[n], parameterTypes[n])) {
@ -986,7 +986,7 @@ public class MethodUtils {
} }
} }
return bestMatch; return bestMatch;
} }
/** /**
@ -1018,7 +1018,7 @@ public class MethodUtils {
// modifer is public. // modifer is public.
// //
// The following workaround solves the problem but will only // The following workaround solves the problem but will only
// work from sufficiently privilages code. // work from sufficiently privilages code.
// //
// Better workarounds would be greatfully accepted. // Better workarounds would be greatfully accepted.
// //
@ -1032,7 +1032,7 @@ public class MethodUtils {
boolean vulnerableJVM = false; boolean vulnerableJVM = false;
try { try {
String specVersion = System.getProperty("java.specification.version"); String specVersion = System.getProperty("java.specification.version");
if (specVersion.charAt(0) == '1' && if (specVersion.charAt(0) == '1' &&
(specVersion.charAt(2) == '0' || (specVersion.charAt(2) == '0' ||
specVersion.charAt(2) == '1' || specVersion.charAt(2) == '1' ||
specVersion.charAt(2) == '2' || specVersion.charAt(2) == '2' ||
@ -1074,8 +1074,8 @@ public class MethodUtils {
} }
/** /**
* Gets the number of steps required needed to turn the source class into the * Gets the number of steps required needed to turn the source class into the
* destination class. This represents the number of steps in the object hierarchy * destination class. This represents the number of steps in the object hierarchy
* graph. * graph.
* @param srcClass The source class * @param srcClass The source class
* @param destClass The destination class * @param destClass The destination class
@ -1085,9 +1085,9 @@ public class MethodUtils {
float cost = 0.0f; float cost = 0.0f;
while (destClass != null && !destClass.equals(srcClass)) { while (destClass != null && !destClass.equals(srcClass)) {
if (destClass.isInterface() && isAssignmentCompatible(destClass,srcClass)) { if (destClass.isInterface() && isAssignmentCompatible(destClass,srcClass)) {
// slight penalty for interface match. // slight penalty for interface match.
// we still want an exact match to override an interface match, but // we still want an exact match to override an interface match, but
// an interface match should override anything where we have to get a // an interface match should override anything where we have to get a
// superclass. // superclass.
cost += 0.25f; cost += 0.25f;
break; break;
@ -1097,7 +1097,7 @@ public class MethodUtils {
} }
/* /*
* If the destination class is null, we've travelled all the way up to * If the destination class is null, we've travelled all the way up to
* an Object match. We'll penalize this by adding 1.5 to the cost. * an Object match. We'll penalize this by adding 1.5 to the cost.
*/ */
if (destClass == null) { if (destClass == null) {
@ -1121,7 +1121,7 @@ public class MethodUtils {
* For example, a <code>Long</code> will not match a <code>int</code>. * For example, a <code>Long</code> will not match a <code>int</code>.
* *
* @param parameterType the type of parameter accepted by the method * @param parameterType the type of parameter accepted by the method
* @param parameterization the type of parameter being tested * @param parameterization the type of parameter being tested
* *
* @return true if the assignement is compatible. * @return true if the assignement is compatible.
*/ */
@ -1148,7 +1148,7 @@ public class MethodUtils {
* Gets the wrapper object class for the given primitive type class. * Gets the wrapper object class for the given primitive type class.
* For example, passing <code>boolean.class</code> returns <code>Boolean.class</code> * For example, passing <code>boolean.class</code> returns <code>Boolean.class</code>
* @param primitiveType the primitive type class for which a match is to be found * @param primitiveType the primitive type class for which a match is to be found
* @return the wrapper type associated with the given primitive * @return the wrapper type associated with the given primitive
* or null if no match is found * or null if no match is found
*/ */
public static Class getPrimitiveWrapper(Class primitiveType) { public static Class getPrimitiveWrapper(Class primitiveType) {
@ -1177,8 +1177,8 @@ public class MethodUtils {
/** /**
* Gets the class for the primitive type corresponding to the primitive wrapper class given. * Gets the class for the primitive type corresponding to the primitive wrapper class given.
* For example, an instance of <code>Boolean.class</code> returns a <code>boolean.class</code>. * For example, an instance of <code>Boolean.class</code> returns a <code>boolean.class</code>.
* @param wrapperType the * @param wrapperType the
* @return the primitive type class corresponding to the given wrapper class, * @return the primitive type class corresponding to the given wrapper class,
* null if no match is found * null if no match is found
*/ */
@ -1214,7 +1214,7 @@ public class MethodUtils {
public static Class toNonPrimitiveClass(Class clazz) { public static Class toNonPrimitiveClass(Class clazz) {
if (clazz.isPrimitive()) { if (clazz.isPrimitive()) {
Class primitiveClazz = MethodUtils.getPrimitiveWrapper(clazz); Class primitiveClazz = MethodUtils.getPrimitiveWrapper(clazz);
// the above method returns // the above method returns
if (primitiveClazz != null) { if (primitiveClazz != null) {
return primitiveClazz; return primitiveClazz;
} else { } else {
@ -1298,7 +1298,8 @@ public class MethodUtils {
* @param obj object to be tested for equality * @param obj object to be tested for equality
* @return true, if the object describes the same Method. * @return true, if the object describes the same Method.
*/ */
public boolean equals(Object obj) { @Override
public boolean equals(Object obj) {
if (!(obj instanceof MethodDescriptor)) { if (!(obj instanceof MethodDescriptor)) {
return false; return false;
} }
@ -1318,7 +1319,8 @@ public class MethodUtils {
* determine equality. * determine equality.
* @return the string length of method name. * @return the string length of method name.
*/ */
public int hashCode() { @Override
public int hashCode() {
return hashCode; return hashCode;
} }
} }

Datei anzeigen

@ -2,16 +2,16 @@
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland * Copyright (C) 2012 Kristian S. Stangeland
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the * This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 2 of * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * See the GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License along with this program; * You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA * 02111-1307 USA
*/ */
@ -36,16 +36,18 @@ import com.google.common.collect.HashBiMap;
public class ObjectEnum<T> implements Iterable<T> { public class ObjectEnum<T> implements Iterable<T> {
// Used to convert between IDs and names // Used to convert between IDs and names
protected BiMap<T, String> members = HashBiMap.create(); protected BiMap<T, String> members = HashBiMap.create();
/** /**
* Registers every declared integer field. * Registers every declared integer field.
* @param fieldType Field type
*/ */
public ObjectEnum(Class<T> fieldType) { public ObjectEnum(Class<T> fieldType) {
registerAll(fieldType); registerAll(fieldType);
} }
/** /**
* Registers every public assignable static field as a member. * Registers every public assignable static field as a member.
* @param fieldType Field type
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected void registerAll(Class<T> fieldType) { protected void registerAll(Class<T> fieldType) {
@ -56,7 +58,7 @@ public class ObjectEnum<T> implements Iterable<T> {
T value = (T) entry.get(null); T value = (T) entry.get(null);
if (value == null) if (value == null)
throw new IllegalArgumentException("Field " + entry + " was NULL. Remember to " + throw new IllegalArgumentException("Field " + entry + " was NULL. Remember to " +
"construct the object after the field has been declared."); "construct the object after the field has been declared.");
registerMember(value, entry.getName()); registerMember(value, entry.getName());
} }
@ -77,7 +79,7 @@ public class ObjectEnum<T> implements Iterable<T> {
*/ */
public boolean registerMember(T instance, String name) { public boolean registerMember(T instance, String name) {
if (!members.containsKey(instance)) { if (!members.containsKey(instance)) {
members.put(instance, name); members.put(instance, name);
return true; return true;
} }
return false; return false;

Datei anzeigen

@ -62,10 +62,10 @@ public class PrettyPrinter {
public final static int RECURSE_DEPTH = 3; public final static int RECURSE_DEPTH = 3;
/** /**
* Print the content of an object. * Print the contents of an object.
* @param object - the object to serialize. * @param object - the object to serialize.
* @return String representation of the class. * @return String representation of the class.
* @throws IllegalAccessException * @throws IllegalAccessException If the object is null
*/ */
public static String printObject(Object object) throws IllegalAccessException { public static String printObject(Object object) throws IllegalAccessException {
if (object == null) if (object == null)
@ -75,11 +75,12 @@ public class PrettyPrinter {
} }
/** /**
* Print the content of an object. * Print the contents of an object.
* @param object - the object to serialize. * @param object - the object to serialize.
* @param start - class to start at.
* @param stop - superclass that will stop the process. * @param stop - superclass that will stop the process.
* @return String representation of the class. * @return String representation of the class
* @throws IllegalAccessException * @throws IllegalAccessException If the object is null
*/ */
public static String printObject(Object object, Class<?> start, Class<?> stop) throws IllegalAccessException { public static String printObject(Object object, Class<?> start, Class<?> stop) throws IllegalAccessException {
if (object == null) if (object == null)
@ -89,24 +90,27 @@ public class PrettyPrinter {
} }
/** /**
* Print the content of an object. * Print the contents of an object.
* @param object - the object to serialize. * @param object - the object to serialize.
* @param start - class to start at.
* @param stop - superclass that will stop the process. * @param stop - superclass that will stop the process.
* @param hierachyDepth - maximum recursion level.
* @return String representation of the class. * @return String representation of the class.
* @throws IllegalAccessException * @throws IllegalAccessException If the object is null
*/ */
public static String printObject(Object object, Class<?> start, Class<?> stop, int hierachyDepth) throws IllegalAccessException { public static String printObject(Object object, Class<?> start, Class<?> stop, int hierachyDepth) throws IllegalAccessException {
return printObject(object, start, stop, hierachyDepth, ObjectPrinter.DEFAULT); return printObject(object, start, stop, hierachyDepth, ObjectPrinter.DEFAULT);
} }
/** /**
* Print the content of an object. * Print the contents of an object.
* @param object - the object to serialize. * @param object - the object to serialize.
* @param start - class to start at.
* @param stop - superclass that will stop the process. * @param stop - superclass that will stop the process.
* @param hierachyDepth - maximum recursion level. * @param hierachyDepth - maximum recursion level.
* @param printer - a generic object printer. * @param printer - a generic object printer.
* @return String representation of the class. * @return String representation of the class.
* @throws IllegalAccessException * @throws IllegalAccessException If the object is null
*/ */
public static String printObject(Object object, Class<?> start, Class<?> stop, int hierachyDepth, ObjectPrinter printer) throws IllegalAccessException { public static String printObject(Object object, Class<?> start, Class<?> stop, int hierachyDepth, ObjectPrinter printer) throws IllegalAccessException {
if (object == null) if (object == null)

Datei anzeigen

@ -393,6 +393,7 @@ public class StructureModifier<TField> {
/** /**
* Retrieves a structure modifier that only reads and writes fields of a given type. * Retrieves a structure modifier that only reads and writes fields of a given type.
* @param <T> Type
* @param fieldType - the type, or supertype, of every field to modify. * @param fieldType - the type, or supertype, of every field to modify.
* @return A structure modifier for fields of this type. * @return A structure modifier for fields of this type.
*/ */
@ -424,6 +425,7 @@ public class StructureModifier<TField> {
/** /**
* Retrieves a structure modifier that only reads and writes fields of a given type. * Retrieves a structure modifier that only reads and writes fields of a given type.
* @param <T> Type
* @param fieldType - the type, or supertype, of every field to modify. * @param fieldType - the type, or supertype, of every field to modify.
* @param converter - converts objects into the given type. * @param converter - converts objects into the given type.
* @return A structure modifier for fields of this type. * @return A structure modifier for fields of this type.
@ -507,10 +509,10 @@ public class StructureModifier<TField> {
/** /**
* Create a new structure modifier for the new field type. * Create a new structure modifier for the new field type.
* @param <T> Type
* @param fieldType - common type of each field. * @param fieldType - common type of each field.
* @param filtered - list of fields after filtering the original modifier. * @param filtered - list of fields after filtering the original modifier.
* @param defaults - list of default values after filtering the original. * @param defaults - list of default values after filtering the original.
* @param converter - the new converter
* @return A new structure modifier. * @return A new structure modifier.
*/ */
protected <T> StructureModifier<T> withFieldType( protected <T> StructureModifier<T> withFieldType(
@ -520,6 +522,7 @@ public class StructureModifier<TField> {
/** /**
* Create a new structure modifier for the new field type. * Create a new structure modifier for the new field type.
* @param <T> Type
* @param fieldType - common type of each field. * @param fieldType - common type of each field.
* @param filtered - list of fields after filtering the original modifier. * @param filtered - list of fields after filtering the original modifier.
* @param defaults - list of default values after filtering the original. * @param defaults - list of default values after filtering the original.

Datei anzeigen

@ -200,6 +200,7 @@ public class VolatileField {
/** /**
* Determine whether or not we'll need to revert the value. * Determine whether or not we'll need to revert the value.
* @return True if it is set, false if not.
*/ */
public boolean isCurrentSet() { public boolean isCurrentSet() {
return currentSet; return currentSet;

Datei anzeigen

@ -78,7 +78,7 @@ public final class Accessors {
/** /**
* Retrieve an accessor for the first field of the given type. * Retrieve an accessor for the first field of the given type.
* @param instanceClass - the type of the instance to retrieve. * @param instanceClass - the type of the instance to retrieve.
* @param fieldClass - type of the field to retrieve. * @param fieldName - name of the field to retrieve.
* @param forceAccess - whether or not to look for private and protected fields. * @param forceAccess - whether or not to look for private and protected fields.
* @return The value of that field. * @return The value of that field.
* @throws IllegalArgumentException If the field cannot be found. * @throws IllegalArgumentException If the field cannot be found.

Datei anzeigen

@ -26,6 +26,7 @@ public class SerializableCloner implements Cloner {
/** /**
* Clone the given object using serialization. * Clone the given object using serialization.
* @param <T> Type
* @param obj - the object to clone. * @param obj - the object to clone.
* @return The cloned object. * @return The cloned object.
* @throws RuntimeException If we were unable to clone the object. * @throws RuntimeException If we were unable to clone the object.

Datei anzeigen

@ -2,16 +2,16 @@
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland * Copyright (C) 2012 Kristian S. Stangeland
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the * This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 2 of * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * See the GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License along with this program; * You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA * 02111-1307 USA
*/ */
@ -158,6 +158,7 @@ public class BackgroundCompiler {
/** /**
* Ensure that the given structure modifier is eventually compiled. * Ensure that the given structure modifier is eventually compiled.
* @param <TKey> Type
* @param uncompiled - structure modifier to compile. * @param uncompiled - structure modifier to compile.
* @param listener - listener responsible for responding to the compilation. * @param listener - listener responsible for responding to the compilation.
*/ */
@ -181,7 +182,7 @@ public class BackgroundCompiler {
List list = listeners.get(key); List list = listeners.get(key);
if (!listeners.containsKey(key)) { if (!listeners.containsKey(key)) {
listeners.put(key, (List) Lists.newArrayList(listener)); listeners.put(key, (List) Lists.newArrayList(listener));
} else { } else {
// We're currently compiling // We're currently compiling
list.add(listener); list.add(listener);
@ -261,8 +262,8 @@ public class BackgroundCompiler {
} }
} catch (RejectedExecutionException e) { } catch (RejectedExecutionException e) {
// Occures when the underlying queue is overflowing. Since the compilation // Occures when the underlying queue is overflowing. Since the compilation
// is only an optmization and not really essential we'll just log this failure // is only an optmization and not really essential we'll just log this failure
// and move on. // and move on.
reporter.reportWarning(this, Report.newBuilder(REPORT_CANNOT_SCHEDULE_COMPILATION).error(e)); reporter.reportWarning(this, Report.newBuilder(REPORT_CANNOT_SCHEDULE_COMPILATION).error(e));
} }
@ -271,6 +272,7 @@ public class BackgroundCompiler {
/** /**
* Add a compile listener if we are still waiting for the structure modifier to be compiled. * Add a compile listener if we are still waiting for the structure modifier to be compiled.
* @param <TKey> Type
* @param uncompiled - the structure modifier that may get compiled. * @param uncompiled - the structure modifier that may get compiled.
* @param listener - the listener to invoke in that case. * @param listener - the listener to invoke in that case.
*/ */
@ -280,7 +282,7 @@ public class BackgroundCompiler {
StructureKey key = new StructureKey(uncompiled); StructureKey key = new StructureKey(uncompiled);
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
List list = listeners.get(key); List list = listeners.get(key);
if (list != null) { if (list != null) {
list.add(listener); list.add(listener);

Datei anzeigen

@ -2,16 +2,16 @@
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland * Copyright (C) 2012 Kristian S. Stangeland
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the * This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 2 of * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * See the GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License along with this program; * You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA * 02111-1307 USA
*/ */
@ -40,9 +40,9 @@ import com.google.common.base.Objects;
import com.google.common.primitives.Primitives; import com.google.common.primitives.Primitives;
// public class CompiledStructureModifierPacket20<TField> extends CompiledStructureModifier<TField> { // public class CompiledStructureModifierPacket20<TField> extends CompiledStructureModifier<TField> {
// //
// private Packet20NamedEntitySpawn typedTarget; // private Packet20NamedEntitySpawn typedTarget;
// //
// public CompiledStructureModifierPacket20(StructureModifier<TField> other, StructureCompiler compiler) { // public CompiledStructureModifierPacket20(StructureModifier<TField> other, StructureCompiler compiler) {
// super(); // super();
// initialize(other); // initialize(other);
@ -50,12 +50,12 @@ import com.google.common.primitives.Primitives;
// this.typedTarget = (Packet20NamedEntitySpawn) target; // this.typedTarget = (Packet20NamedEntitySpawn) target;
// this.compiler = compiler; // this.compiler = compiler;
// } // }
// //
// @Override // @Override
// protected Object readGenerated(int fieldIndex) throws FieldAccessException { // protected Object readGenerated(int fieldIndex) throws FieldAccessException {
// //
// Packet20NamedEntitySpawn target = typedTarget; // Packet20NamedEntitySpawn target = typedTarget;
// //
// switch (fieldIndex) { // switch (fieldIndex) {
// case 0: return (Object) target.a; // case 0: return (Object) target.a;
// case 1: return (Object) target.b; // case 1: return (Object) target.b;
@ -69,12 +69,12 @@ import com.google.common.primitives.Primitives;
// throw new FieldAccessException("Invalid index " + fieldIndex); // throw new FieldAccessException("Invalid index " + fieldIndex);
// } // }
// } // }
// //
// @Override // @Override
// protected StructureModifier<TField> writeGenerated(int index, Object value) throws FieldAccessException { // protected StructureModifier<TField> writeGenerated(int index, Object value) throws FieldAccessException {
// //
// Packet20NamedEntitySpawn target = typedTarget; // Packet20NamedEntitySpawn target = typedTarget;
// //
// switch (index) { // switch (index) {
// case 0: target.a = (Integer) value; break; // case 0: target.a = (Integer) value; break;
// case 1: target.b = (String) value; break; // case 1: target.b = (String) value; break;
@ -87,7 +87,7 @@ import com.google.common.primitives.Primitives;
// default: // default:
// throw new FieldAccessException("Invalid index " + index); // throw new FieldAccessException("Invalid index " + index);
// } // }
// //
// // Chaining // // Chaining
// return this; // return this;
// } // }
@ -157,6 +157,7 @@ public final class StructureCompiler {
/** /**
* Lookup the current class loader for any previously generated classes before we attempt to generate something. * Lookup the current class loader for any previously generated classes before we attempt to generate something.
* @param <TKey> Type
* @param source - the structure modifier to look up. * @param source - the structure modifier to look up.
* @return TRUE if we successfully found a previously generated class, FALSE otherwise. * @return TRUE if we successfully found a previously generated class, FALSE otherwise.
*/ */
@ -179,7 +180,7 @@ public final class StructureCompiler {
return true; return true;
} }
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
// That's ok. // That's ok.
} }
// We need to compile the class // We need to compile the class
@ -189,7 +190,7 @@ public final class StructureCompiler {
/** /**
* Compiles the given structure modifier. * Compiles the given structure modifier.
* <p> * <p>
* WARNING: Do NOT call this method in the main thread. Compiling may easily take 10 ms, which is already * WARNING: Do NOT call this method in the main thread. Compiling may easily take 10 ms, which is already
* over 1/4 of a tick (50 ms). Let the background thread automatically compile the structure modifiers instead. * over 1/4 of a tick (50 ms). Let the background thread automatically compile the structure modifiers instead.
* @param source - structure modifier to compile. * @param source - structure modifier to compile.
* @return A compiled structure modifier. * @return A compiled structure modifier.
@ -233,7 +234,7 @@ public final class StructureCompiler {
throw new RuntimeException("Error occured while instancing generated class.", e); throw new RuntimeException("Error occured while instancing generated class.", e);
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
throw new IllegalStateException("Cannot happen.", e); throw new IllegalStateException("Cannot happen.", e);
} }
} }
/** /**
@ -254,8 +255,8 @@ public final class StructureCompiler {
Class<?> targetType = source.getTargetType(); Class<?> targetType = source.getTargetType();
// Concat class and field type // Concat class and field type
return "CompiledStructure$" + return "CompiledStructure$" +
getSafeTypeName(targetType) + "$" + getSafeTypeName(targetType) + "$" +
getSafeTypeName(source.getFieldType()); getSafeTypeName(source.getFieldType());
} }
@ -274,7 +275,7 @@ public final class StructureCompiler {
String targetName = targetType.getName().replace('.', '/'); String targetName = targetType.getName().replace('.', '/');
// Define class // Define class
cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, PACKAGE_NAME + "/" + className, cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, PACKAGE_NAME + "/" + className,
null, COMPILED_CLASS, null); null, COMPILED_CLASS, null);
createFields(cw, targetSignature); createFields(cw, targetSignature);
@ -288,7 +289,7 @@ public final class StructureCompiler {
// Call the define method // Call the define method
try { try {
if (defineMethod == null) { if (defineMethod == null) {
Method defined = ClassLoader.class.getDeclaredMethod("defineClass", Method defined = ClassLoader.class.getDeclaredMethod("defineClass",
new Class<?>[] { String.class, byte[].class, int.class, int.class }); new Class<?>[] { String.class, byte[].class, int.class, int.class });
// Awesome. Now, create and return it. // Awesome. Now, create and return it.
@ -351,7 +352,7 @@ public final class StructureCompiler {
String methodDescriptor = "(ILjava/lang/Object;)L" + SUPER_CLASS + ";"; String methodDescriptor = "(ILjava/lang/Object;)L" + SUPER_CLASS + ";";
String methodSignature = "(ILjava/lang/Object;)L" + SUPER_CLASS + "<Ljava/lang/Object;>;"; String methodSignature = "(ILjava/lang/Object;)L" + SUPER_CLASS + "<Ljava/lang/Object;>;";
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PROTECTED, "writeGenerated", methodDescriptor, methodSignature, MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PROTECTED, "writeGenerated", methodDescriptor, methodSignature,
new String[] { FIELD_EXCEPTION_CLASS }); new String[] { FIELD_EXCEPTION_CLASS });
BoxingHelper boxingHelper = new BoxingHelper(mv); BoxingHelper boxingHelper = new BoxingHelper(mv);
@ -437,7 +438,7 @@ public final class StructureCompiler {
} }
private void createReadMethod(ClassWriter cw, String className, List<Field> fields, String targetSignature, String targetName) { private void createReadMethod(ClassWriter cw, String className, List<Field> fields, String targetSignature, String targetName) {
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PROTECTED, "readGenerated", "(I)Ljava/lang/Object;", null, MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PROTECTED, "readGenerated", "(I)Ljava/lang/Object;", null,
new String[] { "com/comphenix/protocol/reflect/FieldAccessException" }); new String[] { "com/comphenix/protocol/reflect/FieldAccessException" });
BoxingHelper boxingHelper = new BoxingHelper(mv); BoxingHelper boxingHelper = new BoxingHelper(mv);
@ -508,8 +509,8 @@ public final class StructureCompiler {
} }
private void createConstructor(ClassWriter cw, String className, String targetSignature, String targetName) { private void createConstructor(ClassWriter cw, String className, String targetSignature, String targetName) {
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>",
"(L" + SUPER_CLASS + ";L" + PACKAGE_NAME + "/StructureCompiler;)V", "(L" + SUPER_CLASS + ";L" + PACKAGE_NAME + "/StructureCompiler;)V",
"(L" + SUPER_CLASS + "<Ljava/lang/Object;>;L" + PACKAGE_NAME + "/StructureCompiler;)V", null); "(L" + SUPER_CLASS + "<Ljava/lang/Object;>;L" + PACKAGE_NAME + "/StructureCompiler;)V", null);
String fullClassName = PACKAGE_NAME + "/" + className; String fullClassName = PACKAGE_NAME + "/" + className;

Datei anzeigen

@ -87,7 +87,7 @@ public abstract class AbstractFuzzyMember<T extends Member> extends AbstractFuzz
/** /**
* Set the exact name of the member we are matching. * Set the exact name of the member we are matching.
* <p< * <p>
* This will overwrite the regular expression rule. * This will overwrite the regular expression rule.
* @param name - exact name. * @param name - exact name.
* @return This builder, for chaining. * @return This builder, for chaining.
@ -137,7 +137,7 @@ public abstract class AbstractFuzzyMember<T extends Member> extends AbstractFuzz
} }
/** /**
* Construct a new instance of the current type. * Construct a new instance of the current type.
* @return New instance. * @return New instance.
*/ */
@Nonnull @Nonnull
@ -232,7 +232,7 @@ public abstract class AbstractFuzzyMember<T extends Member> extends AbstractFuzz
@Override @Override
protected int calculateRoundNumber() { protected int calculateRoundNumber() {
// Sanity check // Sanity check
if (!sealed) if (!sealed)
throw new IllegalStateException("Cannot calculate round number during construction."); throw new IllegalStateException("Cannot calculate round number during construction.");
// NULL is zero // NULL is zero
@ -255,7 +255,7 @@ public abstract class AbstractFuzzyMember<T extends Member> extends AbstractFuzz
// Build our representation // Build our representation
if (modifiersRequired != Integer.MAX_VALUE || modifiersBanned != 0) { if (modifiersRequired != Integer.MAX_VALUE || modifiersBanned != 0) {
map.put("modifiers", String.format("[required: %s, banned: %s]", map.put("modifiers", String.format("[required: %s, banned: %s]",
getBitView(modifiersRequired, 16), getBitView(modifiersRequired, 16),
getBitView(modifiersBanned, 16)) getBitView(modifiersBanned, 16))
); );
@ -298,7 +298,7 @@ public abstract class AbstractFuzzyMember<T extends Member> extends AbstractFuzz
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hashCode(modifiersBanned, modifiersRequired, return Objects.hashCode(modifiersBanned, modifiersRequired,
nameRegex != null ? nameRegex.pattern() : null, declaringMatcher); nameRegex != null ? nameRegex.pattern() : null, declaringMatcher);
} }
} }

Datei anzeigen

@ -26,7 +26,7 @@ public class FuzzyMethodContract extends AbstractFuzzyMember<MethodInfo> {
private final Integer indexMatch; private final Integer indexMatch;
/** /**
* Construct a new parameter class matcher. * Construct a new parameter class matcher.
* @param typeMatcher - class type matcher. * @param typeMatcher - class type matcher.
*/ */
public ParameterClassMatcher(@Nonnull AbstractFuzzyMatcher<Class<?>> typeMatcher) { public ParameterClassMatcher(@Nonnull AbstractFuzzyMatcher<Class<?>> typeMatcher) {
@ -34,7 +34,7 @@ public class FuzzyMethodContract extends AbstractFuzzyMember<MethodInfo> {
} }
/** /**
* Construct a new parameter class matcher. * Construct a new parameter class matcher.
* @param typeMatcher - class type matcher. * @param typeMatcher - class type matcher.
* @param indexMatch - parameter index to match, or NULL for anything. * @param indexMatch - parameter index to match, or NULL for anything.
*/ */
@ -49,7 +49,7 @@ public class FuzzyMethodContract extends AbstractFuzzyMember<MethodInfo> {
/** /**
* See if there's a match for this matcher. * See if there's a match for this matcher.
* @param used - parameters that have been matched before. * @param used - parameters that have been matched before.
* @param parent - the container (member) that holds a reference to this parameter. * @param parent - the container (member) that holds a reference to this parameter.
* @param params - the type of each parameter. * @param params - the type of each parameter.
* @return TRUE if this matcher matches any of the given parameters, FALSE otherwise. * @return TRUE if this matcher matches any of the given parameters, FALSE otherwise.
*/ */
@ -93,8 +93,9 @@ public class FuzzyMethodContract extends AbstractFuzzyMember<MethodInfo> {
* @author Kristian * @author Kristian
*/ */
public static class Builder extends AbstractFuzzyMember.Builder<FuzzyMethodContract> { public static class Builder extends AbstractFuzzyMember.Builder<FuzzyMethodContract> {
@Override
public Builder requireModifier(int modifier) { public Builder requireModifier(int modifier) {
super.requireModifier(modifier); super.requireModifier(modifier);
return this; return this;
} }
@ -106,49 +107,49 @@ public class FuzzyMethodContract extends AbstractFuzzyMember<MethodInfo> {
@Override @Override
public Builder banModifier(int modifier) { public Builder banModifier(int modifier) {
super.banModifier(modifier); super.banModifier(modifier);
return this; return this;
} }
@Override @Override
public Builder nameRegex(String regex) { public Builder nameRegex(String regex) {
super.nameRegex(regex); super.nameRegex(regex);
return this; return this;
} }
@Override @Override
public Builder nameRegex(Pattern pattern) { public Builder nameRegex(Pattern pattern) {
super.nameRegex(pattern); super.nameRegex(pattern);
return this; return this;
} }
@Override @Override
public Builder nameExact(String name) { public Builder nameExact(String name) {
super.nameExact(name); super.nameExact(name);
return this; return this;
} }
@Override @Override
public Builder declaringClassExactType(Class<?> declaringClass) { public Builder declaringClassExactType(Class<?> declaringClass) {
super.declaringClassExactType(declaringClass); super.declaringClassExactType(declaringClass);
return this; return this;
} }
@Override @Override
public Builder declaringClassSuperOf(Class<?> declaringClass) { public Builder declaringClassSuperOf(Class<?> declaringClass) {
super.declaringClassSuperOf(declaringClass); super.declaringClassSuperOf(declaringClass);
return this; return this;
} }
@Override @Override
public Builder declaringClassDerivedOf(Class<?> declaringClass) { public Builder declaringClassDerivedOf(Class<?> declaringClass) {
super.declaringClassDerivedOf(declaringClass); super.declaringClassDerivedOf(declaringClass);
return this; return this;
} }
@Override @Override
public Builder declaringClassMatching(AbstractFuzzyMatcher<Class<?>> classMatcher) { public Builder declaringClassMatching(AbstractFuzzyMatcher<Class<?>> classMatcher) {
super.declaringClassMatching(classMatcher); super.declaringClassMatching(classMatcher);
return this; return this;
} }
@ -209,7 +210,7 @@ public class FuzzyMethodContract extends AbstractFuzzyMember<MethodInfo> {
/** /**
* Add a new required parameters by type and order for any matching method. * Add a new required parameters by type and order for any matching method.
* @param type - the types of every parameters in order. * @param types - the types of every parameters in order.
* @return This builder, for chaining. * @return This builder, for chaining.
*/ */
public Builder parameterExactArray(Class<?>... types) { public Builder parameterExactArray(Class<?>... types) {
@ -270,7 +271,7 @@ public class FuzzyMethodContract extends AbstractFuzzyMember<MethodInfo> {
/** /**
* Require a void method. * Require a void method.
* @return This builder, for chaining. * @return This builder, for chaining.
*/ */
public Builder returnTypeVoid() { public Builder returnTypeVoid() {
return returnTypeExact(Void.TYPE); return returnTypeExact(Void.TYPE);
@ -287,7 +288,7 @@ public class FuzzyMethodContract extends AbstractFuzzyMember<MethodInfo> {
} }
/** /**
* Set the expected super class of the return type for every matching method. * Set the expected super class of the return type for every matching method.
* @param type - the return type, or a super class of it. * @param type - the return type, or a super class of it.
* @return This builder, for chaining. * @return This builder, for chaining.
*/ */
@ -429,7 +430,7 @@ public class FuzzyMethodContract extends AbstractFuzzyMember<MethodInfo> {
/** /**
* Retrieve an immutable list of every parameter matcher for this method. * Retrieve an immutable list of every parameter matcher for this method.
* @return Immutable list of every parameter matcher. * @return Immutable list of every parameter matcher.
*/ */
public ImmutableList<ParameterClassMatcher> getParamMatchers() { public ImmutableList<ParameterClassMatcher> getParamMatchers() {
if (paramMatchers instanceof ImmutableList) if (paramMatchers instanceof ImmutableList)
@ -440,7 +441,7 @@ public class FuzzyMethodContract extends AbstractFuzzyMember<MethodInfo> {
/** /**
* Retrieve an immutable list of every exception matcher for this method. * Retrieve an immutable list of every exception matcher for this method.
* @return Immutable list of every exception matcher. * @return Immutable list of every exception matcher.
*/ */
public List<ParameterClassMatcher> getExceptionMatchers() { public List<ParameterClassMatcher> getExceptionMatchers() {
if (exceptionMatchers instanceof ImmutableList) if (exceptionMatchers instanceof ImmutableList)
@ -478,7 +479,7 @@ public class FuzzyMethodContract extends AbstractFuzzyMember<MethodInfo> {
return false; return false;
// Finally, check parameters and exceptions // Finally, check parameters and exceptions
return matchParameters(params, value, paramMatchers) && return matchParameters(params, value, paramMatchers) &&
matchParameters(exceptions, value, exceptionMatchers); matchParameters(exceptions, value, exceptionMatchers);
} }
// No match // No match
@ -572,7 +573,7 @@ public class FuzzyMethodContract extends AbstractFuzzyMember<MethodInfo> {
} else if (obj instanceof FuzzyMethodContract && super.equals(obj)) { } else if (obj instanceof FuzzyMethodContract && super.equals(obj)) {
FuzzyMethodContract other = (FuzzyMethodContract) obj; FuzzyMethodContract other = (FuzzyMethodContract) obj;
return Objects.equal(paramCount, other.paramCount) && return Objects.equal(paramCount, other.paramCount) &&
Objects.equal(returnMatcher, other.returnMatcher) && Objects.equal(returnMatcher, other.returnMatcher) &&
Objects.equal(paramMatchers, other.paramMatchers) && Objects.equal(paramMatchers, other.paramMatchers) &&
Objects.equal(exceptionMatchers, other.exceptionMatchers); Objects.equal(exceptionMatchers, other.exceptionMatchers);

Datei anzeigen

@ -156,8 +156,8 @@ public class DefaultInstances implements InstanceProvider {
* <li>Enums. Returns the first declared element.</li> * <li>Enums. Returns the first declared element.</li>
* <li>Collection interfaces, such as List and Set. Returns the most appropriate empty container.</li> * <li>Collection interfaces, such as List and Set. Returns the most appropriate empty container.</li>
* <li>Any type with a public constructor that has parameters with defaults.</li> * <li>Any type with a public constructor that has parameters with defaults.</li>
* </ul>
* </ul> * </ul>
* @param <T> Type
* @param type - the type to construct a default value. * @param type - the type to construct a default value.
* @return A default value/instance, or NULL if not possible. * @return A default value/instance, or NULL if not possible.
*/ */
@ -167,6 +167,7 @@ public class DefaultInstances implements InstanceProvider {
/** /**
* Retrieve the constructor with the fewest number of parameters. * Retrieve the constructor with the fewest number of parameters.
* @param <T> Type
* @param type - type to construct. * @param type - type to construct.
* @return A constructor with the fewest number of parameters, or NULL if the type has no constructors. * @return A constructor with the fewest number of parameters, or NULL if the type has no constructors.
*/ */
@ -239,8 +240,8 @@ public class DefaultInstances implements InstanceProvider {
* <li>Enums. Returns the first declared element.</li> * <li>Enums. Returns the first declared element.</li>
* <li>Collection interfaces, such as List and Set. Returns the most appropriate empty container.</li> * <li>Collection interfaces, such as List and Set. Returns the most appropriate empty container.</li>
* <li>Any type with a public constructor that has parameters with defaults.</li> * <li>Any type with a public constructor that has parameters with defaults.</li>
* </ul>
* </ul> * </ul>
* @param <T> Type
* @param type - the type to construct a default value. * @param type - the type to construct a default value.
* @param providers - instance providers used during the construction. * @param providers - instance providers used during the construction.
* @return A default value/instance, or NULL if not possible. * @return A default value/instance, or NULL if not possible.
@ -319,6 +320,7 @@ public class DefaultInstances implements InstanceProvider {
/** /**
* Used by the default instance provider to create a class from a given constructor. * Used by the default instance provider to create a class from a given constructor.
* The default method uses reflection. * The default method uses reflection.
* @param <T> Type
* @param type - the type to create. * @param type - the type to create.
* @param constructor - the constructor to use. * @param constructor - the constructor to use.
* @param types - type of each parameter in order. * @param types - type of each parameter in order.

Datei anzeigen

@ -1,7 +1,7 @@
package com.comphenix.protocol.reflect.instances; package com.comphenix.protocol.reflect.instances;
/** /**
* Invoked when a instance provider indicates that a given type cannot or should not be * Invoked when a instance provider indicates that a given type cannot or should not be
* constructed under any circumstances. * constructed under any circumstances.
* *
* @author Kristian * @author Kristian
@ -21,6 +21,7 @@ public class NotConstructableException extends IllegalArgumentException {
/** /**
* Construct a new not constructable exception with a custom message. * Construct a new not constructable exception with a custom message.
* @param message - detail message
*/ */
public NotConstructableException(String message) { public NotConstructableException(String message) {
super(message); super(message);
@ -28,6 +29,8 @@ public class NotConstructableException extends IllegalArgumentException {
/** /**
* Construct a new not constructable exception with a custom message and cause. * Construct a new not constructable exception with a custom message and cause.
* @param message - detail message
* @param cause - cause
*/ */
public NotConstructableException(String message, Throwable cause) { public NotConstructableException(String message, Throwable cause) {
super(message, cause); super(message, cause);
@ -35,6 +38,7 @@ public class NotConstructableException extends IllegalArgumentException {
/** /**
* Construct a new not constructable exception with a custom cause. * Construct a new not constructable exception with a custom cause.
* @param cause - cause
*/ */
public NotConstructableException(Throwable cause) { public NotConstructableException(Throwable cause) {
super( cause); super( cause);

Datei anzeigen

@ -6,7 +6,7 @@ package com.comphenix.protocol.timing;
*/ */
public class StatisticsStream extends OnlineComputation { public class StatisticsStream extends OnlineComputation {
// This algorithm is due to Donald Knuth, as described in: // This algorithm is due to Donald Knuth, as described in:
// Donald E. Knuth (1998). The Art of Computer Programming, volume 2: // Donald E. Knuth (1998). The Art of Computer Programming, volume 2:
// Seminumerical Algorithms, 3rd edn., p. 232. Boston: Addison-Wesley. // Seminumerical Algorithms, 3rd edn., p. 232. Boston: Addison-Wesley.
private int count = 0; private int count = 0;
@ -51,7 +51,7 @@ public class StatisticsStream extends OnlineComputation {
// As per Knuth // As per Knuth
count++; count++;
mean += delta / count; mean += delta / count;
m2 += delta * (value - mean); m2 += delta * (value - mean);
// Update extremes // Update extremes
if (value < minimum) if (value < minimum)
@ -107,6 +107,7 @@ public class StatisticsStream extends OnlineComputation {
/** /**
* Combine the two statistics. * Combine the two statistics.
* @param other - the other statistics. * @param other - the other statistics.
* @return Combined statistics
*/ */
public StatisticsStream add(StatisticsStream other) { public StatisticsStream add(StatisticsStream other) {
// Special cases // Special cases
@ -147,8 +148,8 @@ public class StatisticsStream extends OnlineComputation {
if (count == 0) if (count == 0)
return "StatisticsStream [Nothing recorded]"; return "StatisticsStream [Nothing recorded]";
return String.format("StatisticsStream [Average: %.3f, SD: %.3f, Min: %.3f, Max: %.3f, Count: %s]", return String.format("StatisticsStream [Average: %.3f, SD: %.3f, Min: %.3f, Max: %.3f, Count: %s]",
getMean(), getStandardDeviation(), getMean(), getStandardDeviation(),
getMinimum(), getMaximum(), getCount()); getMinimum(), getMaximum(), getCount());
} }
} }

Datei anzeigen

@ -10,7 +10,7 @@ import com.google.common.collect.Maps;
* Tracks the invocation time for a particular plugin against a list of packets. * Tracks the invocation time for a particular plugin against a list of packets.
* @author Kristian * @author Kristian
*/ */
public class TimedTracker { public class TimedTracker {
// Table of packets and invocations // Table of packets and invocations
private Map<PacketType, StatisticsStream> packets = Maps.newHashMap(); private Map<PacketType, StatisticsStream> packets = Maps.newHashMap();
private int observations; private int observations;
@ -26,7 +26,7 @@ public class TimedTracker {
/** /**
* Stop and record the execution time since the creation of the given tracking token. * Stop and record the execution time since the creation of the given tracking token.
* @param trackingToken - the tracking token. * @param trackingToken - the tracking token.
* @param packetId - the packet ID. * @param type - the packet type.
*/ */
public synchronized void endTracking(long trackingToken, PacketType type) { public synchronized void endTracking(long trackingToken, PacketType type) {
StatisticsStream stream = packets.get(type); StatisticsStream stream = packets.get(type);
@ -57,7 +57,7 @@ public class TimedTracker {
for (Entry<PacketType, StatisticsStream> entry : packets.entrySet()) { for (Entry<PacketType, StatisticsStream> entry : packets.entrySet()) {
clone.put( clone.put(
entry.getKey(), entry.getKey(),
new StatisticsStream(entry.getValue()) new StatisticsStream(entry.getValue())
); );
} }

Datei anzeigen

@ -2,16 +2,16 @@
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland * Copyright (C) 2012 Kristian S. Stangeland
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the * This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 2 of * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * See the GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License along with this program; * You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA * 02111-1307 USA
*/ */
@ -66,7 +66,7 @@ public class ChatExtensions {
* @param message - the message to send. * @param message - the message to send.
* @throws InvocationTargetException If we were unable to send the message. * @throws InvocationTargetException If we were unable to send the message.
*/ */
public void sendMessageSilently(CommandSender receiver, String message) throws InvocationTargetException { public void sendMessageSilently(CommandSender receiver, String message) throws InvocationTargetException {
if (receiver == null) if (receiver == null)
throw new IllegalArgumentException("receiver cannot be NULL."); throw new IllegalArgumentException("receiver cannot be NULL.");
if (message == null) if (message == null)
@ -172,6 +172,7 @@ public class ChatExtensions {
* @param marginChar - the character to use as margin. * @param marginChar - the character to use as margin.
* @param marginWidth - the width (in characters) of the left and right margin. * @param marginWidth - the width (in characters) of the left and right margin.
* @param marginHeight - the height (in characters) of the top and buttom margin. * @param marginHeight - the height (in characters) of the top and buttom margin.
* @return Flowerboxed message
*/ */
public static String[] toFlowerBox(String[] message, String marginChar, int marginWidth, int marginHeight) { public static String[] toFlowerBox(String[] message, String marginChar, int marginWidth, int marginHeight) {
String[] output = new String[message.length + marginHeight * 2]; String[] output = new String[message.length + marginHeight * 2];

Datei anzeigen

@ -23,6 +23,7 @@ public class HexDumper {
/** /**
* Retrieve a hex dumper tuned for lines of 80 characters: * Retrieve a hex dumper tuned for lines of 80 characters:
* <table border="1"> * <table border="1">
* <caption>Values</caption>
* <tr> * <tr>
* <th>Property</th> * <th>Property</th>
* <th>Value</th> * <th>Value</th>
@ -118,7 +119,7 @@ public class HexDumper {
* Set the number of groups in each line. This is limited by the supply of bytes in the byte array. * Set the number of groups in each line. This is limited by the supply of bytes in the byte array.
* <p> * <p>
* Use {@link Integer#MAX_VALUE} to effectively disable lines. * Use {@link Integer#MAX_VALUE} to effectively disable lines.
* @param groupLength - the length of each group. * @param groupCount - the count of groups.
* @return This instance, for chaining. * @return This instance, for chaining.
*/ */
public HexDumper groupCount(int groupCount) { public HexDumper groupCount(int groupCount) {
@ -132,7 +133,6 @@ public class HexDumper {
* Append the hex dump of the given data to the string builder, using the current formatting settings. * Append the hex dump of the given data to the string builder, using the current formatting settings.
* @param appendable - appendable source. * @param appendable - appendable source.
* @param data - the data to dump. * @param data - the data to dump.
* @param start - the starting index of the data.
* @param length - the number of bytes to dump. * @param length - the number of bytes to dump.
* @throws IOException Any underlying IO exception. * @throws IOException Any underlying IO exception.
*/ */
@ -158,8 +158,6 @@ public class HexDumper {
* Append the hex dump of the given data to the string builder, using the current formatting settings. * Append the hex dump of the given data to the string builder, using the current formatting settings.
* @param builder - the builder. * @param builder - the builder.
* @param data - the data to dump. * @param data - the data to dump.
* @param start - the starting index of the data.
* @param length - the number of bytes to dump.
*/ */
public void appendTo(StringBuilder builder, byte[] data) { public void appendTo(StringBuilder builder, byte[] data) {
appendTo(builder, data, 0, data.length); appendTo(builder, data, 0, data.length);

Datei anzeigen

@ -1752,12 +1752,14 @@ public class MinecraftReflection {
} }
private static MethodAccessor asCraftMirror; private static MethodAccessor asCraftMirror;
private static MethodAccessor asCraftCopy;
private static MethodAccessor asNMSCopy; private static MethodAccessor asNMSCopy;
/** /**
* Retrieve a CraftItemStack from a given ItemStack. * Retrieve a CraftItemStack from a given NMS ItemStack.
* @param bukkitItemStack - the Bukkit ItemStack to convert. *
* @return A CraftItemStack as an ItemStack. * @param nmsItem - the NMS ItemStack to convert.
* @return A CraftItemStack as a NMS ItemStack.
*/ */
public static ItemStack getBukkitItemStack(Object nmsItem) { public static ItemStack getBukkitItemStack(Object nmsItem) {
if (asCraftMirror == null) { if (asCraftMirror == null) {
@ -1768,9 +1770,24 @@ public class MinecraftReflection {
} }
/** /**
* Retrieve the Bukkit ItemStack from a given net.minecraft.server ItemStack. * Retrieve a CraftItemStack from a given ItemStack.
* @param minecraftItemStack - the NMS ItemStack to wrap. *
* @return The wrapped ItemStack. * @param stack - the Bukkit ItemStack to convert.
* @return A CraftItemStack as an ItemStack.
*/
public static ItemStack getCraftItemStack(ItemStack stack) {
if (asCraftCopy == null) {
asCraftCopy = Accessors.getMethodAccessor(getCraftItemStackClass(), "asCraftCopy", ItemStack.class);
}
return (ItemStack) asCraftCopy.invoke(null, stack);
}
/**
* Retrieve the NMS ItemStack from a given ItemStack.
*
* @param stack - the ItemStack to convert.
* @return The NMS ItemStack.
*/ */
public static Object getMinecraftItemStack(ItemStack stack) { public static Object getMinecraftItemStack(ItemStack stack) {
if (asNMSCopy == null) { if (asNMSCopy == null) {

Datei anzeigen

@ -28,6 +28,8 @@ public class SafeCacheBuilder<K, V> {
/** /**
* Construct a new safe cache builder. * Construct a new safe cache builder.
* @param <K> Key type
* @param <V> Value type
* *
* @return A new cache builder. * @return A new cache builder.
*/ */
@ -54,9 +56,12 @@ public class SafeCacheBuilder<K, V> {
* <b>Note:</b>The default may change in the future. If you care about this * <b>Note:</b>The default may change in the future. If you care about this
* value, you should always choose it explicitly. * value, you should always choose it explicitly.
* *
* @param concurrencyLevel New concurrency level
* @return This for chaining
*
* @throws IllegalArgumentException if {@code concurrencyLevel} is * @throws IllegalArgumentException if {@code concurrencyLevel} is
* nonpositive * nonpositive
* @throws IllegalStateException if a concurrency level was already set * @throws IllegalStateExeption if a concurrency level was already set
*/ */
public SafeCacheBuilder<K, V> concurrencyLevel(int concurrencyLevel) { public SafeCacheBuilder<K, V> concurrencyLevel(int concurrencyLevel) {
builder.concurrencyLevel(concurrencyLevel); builder.concurrencyLevel(concurrencyLevel);
@ -66,8 +71,7 @@ public class SafeCacheBuilder<K, V> {
/** /**
* Specifies that each entry should be automatically removed from the cache * Specifies that each entry should be automatically removed from the cache
* once a fixed duration has elapsed after the entry's creation, or last * once a fixed duration has elapsed after the entry's creation, or last
* access. Access time is reset by {@link com.google.common.cache.Cache#get Cache.get()} and * access. Access time is reset by {@link com.google.common.cache.Cache#get Cache.get()},
* {@link com.google.common.cache.Cache#getUnchecked Cache.getUnchecked()},
* but not by operations on the view returned by * but not by operations on the view returned by
* {@link com.google.common.cache.Cache#asMap() Cache.asMap()}. * {@link com.google.common.cache.Cache#asMap() Cache.asMap()}.
* *
@ -86,6 +90,8 @@ public class SafeCacheBuilder<K, V> {
* @param duration the length of time after an entry is last accessed that * @param duration the length of time after an entry is last accessed that
* it should be automatically removed * it should be automatically removed
* @param unit the unit that {@code duration} is expressed in * @param unit the unit that {@code duration} is expressed in
* @return This for chaining
*
* @throws IllegalArgumentException if {@code duration} is negative * @throws IllegalArgumentException if {@code duration} is negative
* @throws IllegalStateException if the time to idle or time to live was * @throws IllegalStateException if the time to idle or time to live was
* already set * already set
@ -280,7 +286,7 @@ public class SafeCacheBuilder<K, V> {
/** /**
* Returns the cache wrapped as a ConcurrentMap. * Returns the cache wrapped as a ConcurrentMap.
* <> * <p>
* We can't return the direct Cache instance as it changed in Guava 13. * We can't return the direct Cache instance as it changed in Guava 13.
* @return The cache as a map. * @return The cache as a map.
*/ */

Datei anzeigen

@ -12,7 +12,7 @@ public abstract class AbstractWrapper {
/** /**
* Construct a new NMS wrapper. * Construct a new NMS wrapper.
* @param handle - the wrapped NMS object. * @param handleType - the NMS handle type.
*/ */
public AbstractWrapper(Class<?> handleType) { public AbstractWrapper(Class<?> handleType) {
this.handleType = Preconditions.checkNotNull(handleType, "handleType cannot be NULL"); this.handleType = Preconditions.checkNotNull(handleType, "handleType cannot be NULL");

Datei anzeigen

@ -210,8 +210,8 @@ public class BukkitConverters {
/** /**
* Retrieve an equivalent converter for a map of generic keys and primitive values. * Retrieve an equivalent converter for a map of generic keys and primitive values.
* @param genericItemType - the generic item type. * @param genericKeyType - the generic key type.
* @param itemConverter - an equivalent converter for the generic type. * @param keyConverter - an equivalent converter for the generic type.
* @return An equivalent converter. * @return An equivalent converter.
*/ */
public static <T, U> EquivalentConverter<Map<T, U>> getMapConverter( public static <T, U> EquivalentConverter<Map<T, U>> getMapConverter(
@ -1006,7 +1006,7 @@ public class BukkitConverters {
} }
/** /**
* Retrieve every NMS <-> Bukkit converter as unwrappers. * Retrieve every NMS to/from Bukkit converter as unwrappers.
* @return Every unwrapper. * @return Every unwrapper.
*/ */
public static List<Unwrapper> getUnwrappers() { public static List<Unwrapper> getUnwrappers() {

Datei anzeigen

@ -147,7 +147,7 @@ public class WrappedGameProfile extends AbstractWrapper {
/** /**
* Construct a wrapper around an existing game profile. * Construct a wrapper around an existing game profile.
* *
* @param profile - the underlying profile, or NULL. * @param handle - the underlying profile, or NULL.
*/ */
public static WrappedGameProfile fromHandle(Object handle) { public static WrappedGameProfile fromHandle(Object handle) {
if (handle == null) if (handle == null)

Datei anzeigen

@ -175,7 +175,7 @@ public class WrappedServerPing extends AbstractWrapper {
/** /**
* Set the message of the day. * Set the message of the day.
* @param description - the message. * @param message - the message.
*/ */
public void setMotD(String message) { public void setMotD(String message) {
setMotD(WrappedChatComponent.fromText(message)); setMotD(WrappedChatComponent.fromText(message));
@ -200,9 +200,9 @@ public class WrappedServerPing extends AbstractWrapper {
/** /**
* Retrieve the displayed number of online players. * Retrieve the displayed number of online players.
* @see {@link #setPlayersOnline(int)} for more information.
* @return The displayed number. * @return The displayed number.
* @throws IllegalStateException If the player count has been hidden via {@link #setPlayersVisible(boolean)}. * @throws IllegalStateException If the player count has been hidden via {@link #setPlayersVisible(boolean)}.
* @see #setPlayersOnline(int)
*/ */
public int getPlayersOnline() { public int getPlayersOnline() {
if (players == null) if (players == null)
@ -225,9 +225,9 @@ public class WrappedServerPing extends AbstractWrapper {
/** /**
* Retrieve the displayed maximum number of players. * Retrieve the displayed maximum number of players.
* @see {@link #setPlayersMaximum(int)} for more information.
* @return The maximum number. * @return The maximum number.
* @throws IllegalStateException If the player maximum has been hidden via {@link #setPlayersVisible(boolean)}. * @throws IllegalStateException If the player maximum has been hidden via {@link #setPlayersVisible(boolean)}.
* @see #setPlayersMaximum(int)
*/ */
public int getPlayersMaximum() { public int getPlayersMaximum() {
if (players == null) if (players == null)

Datei anzeigen

@ -15,7 +15,6 @@ public class WrappedSignedProperty extends AbstractWrapper {
* @param name - the name of the property. * @param name - the name of the property.
* @param value - the value of the property. * @param value - the value of the property.
* @param signature - the BASE64-encoded signature of the value. * @param signature - the BASE64-encoded signature of the value.
* @return The signed property.
*/ */
public WrappedSignedProperty(String name, String value, String signature) { public WrappedSignedProperty(String name, String value, String signature) {
this(new Property(name, value, signature)); this(new Property(name, value, signature));

Datei anzeigen

@ -36,7 +36,7 @@ public class WrappedStatistic extends AbstractWrapper {
} }
/** /**
* Construct a new wrapper from a given underlying statistics. * Construct a new wrapper from a given underlying statistics.
* @param handle - the statistics. * @param handle - the statistics.
* @return The wrapped statistics. * @return The wrapped statistics.
*/ */
@ -46,7 +46,7 @@ public class WrappedStatistic extends AbstractWrapper {
/** /**
* Construct a wrapper around an existing game profile. * Construct a wrapper around an existing game profile.
* @param profile - the underlying profile. * @param name - statistic name.
* @return The wrapped statistics, or NULL if not found. * @return The wrapped statistics, or NULL if not found.
*/ */
public static WrappedStatistic fromName(String name) { public static WrappedStatistic fromName(String name) {
@ -60,9 +60,10 @@ public class WrappedStatistic extends AbstractWrapper {
*/ */
public static Iterable<WrappedStatistic> values() { public static Iterable<WrappedStatistic> values() {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<Object, Object> map = (Map<Object, Object>) MAP_ACCESSOR.get(null); Map<Object, Object> map = (Map<Object, Object>) MAP_ACCESSOR.get(null);
return Iterables.transform(map.values(), new Function<Object, WrappedStatistic>() { return Iterables.transform(map.values(), new Function<Object, WrappedStatistic>() {
@Override
public WrappedStatistic apply(Object handle) { public WrappedStatistic apply(Object handle) {
return fromHandle(handle); return fromHandle(handle);
}; };

Datei anzeigen

@ -186,6 +186,7 @@ public class WrappedWatchableObject extends AbstractWrapper {
* Retrieve the type ID of a watchable object. * Retrieve the type ID of a watchable object.
* <p> * <p>
* <table border=1> * <table border=1>
* <caption>Type to Value</caption>
* <tbody> * <tbody>
* <tr> * <tr>
* <th>Type ID</th> * <th>Type ID</th>
@ -230,9 +231,9 @@ public class WrappedWatchableObject extends AbstractWrapper {
/** /**
* Set the type ID of a watchable object. * Set the type ID of a watchable object.
* @see {@link #getTypeID()} for more information.
* @param id - the new ID. * @param id - the new ID.
* @throws FieldAccessException Reflection failed. * @throws FieldAccessException Reflection failed.
* @see #getTypeID()
*/ */
public void setTypeID(int id) throws FieldAccessException { public void setTypeID(int id) throws FieldAccessException {
modifier.<Integer>withType(int.class).write(0, id); modifier.<Integer>withType(int.class).write(0, id);

Datei anzeigen

@ -19,18 +19,18 @@ import javax.annotation.Nonnull;
*/ */
public interface NbtCompound extends NbtBase<Map<String, NbtBase<?>>>, Iterable<NbtBase<?>> { public interface NbtCompound extends NbtBase<Map<String, NbtBase<?>>>, Iterable<NbtBase<?>> {
@Override @Override
@Deprecated() @Deprecated
public Map<String, NbtBase<?>> getValue(); public Map<String, NbtBase<?>> getValue();
/** /**
* Determine if an entry with the given key exists or not. * Determine if an entry with the given key exists or not.
* @param key - the key to lookup. * @param key - the key to lookup.
* @return TRUE if an entry with the given key exists, FALSE otherwise. * @return TRUE if an entry with the given key exists, FALSE otherwise.
*/ */
public abstract boolean containsKey(String key); public abstract boolean containsKey(String key);
/** /**
* Retrieve a Set view of the keys of each entry in this compound. * Retrieve a Set view of the keys of each entry in this compound.
* @return The keys of each entry. * @return The keys of each entry.
*/ */
public abstract Set<String> getKeys(); public abstract Set<String> getKeys();
@ -260,7 +260,7 @@ public interface NbtCompound extends NbtBase<Map<String, NbtBase<?>>>, Iterable<
public abstract NbtCompound put(String key, int[] value); public abstract NbtCompound put(String key, int[] value);
/** /**
* Associates a given Java primitive value, list, map or NbtBase<?> with a certain key. * Associates a given Java primitive value, list, map or NbtBase with a certain key.
* <p> * <p>
* If the value is NULL, the corresponding key is removed. Any Map or List will be converted * If the value is NULL, the corresponding key is removed. Any Map or List will be converted
* to a corresponding NbtCompound or NbtList. * to a corresponding NbtCompound or NbtList.
@ -341,5 +341,6 @@ public interface NbtCompound extends NbtBase<Map<String, NbtBase<?>>>, Iterable<
* Retrieve an iterator view of the NBT tags stored in this compound. * Retrieve an iterator view of the NBT tags stored in this compound.
* @return The tags stored in this compound. * @return The tags stored in this compound.
*/ */
@Override
public abstract Iterator<NbtBase<?>> iterator(); public abstract Iterator<NbtBase<?>> iterator();
} }

Datei anzeigen

@ -2,16 +2,16 @@
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland * Copyright (C) 2012 Kristian S. Stangeland
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the * This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 2 of * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * See the GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License along with this program; * You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA * 02111-1307 USA
*/ */
@ -130,8 +130,8 @@ public class NbtFactory {
/** /**
* Set the NBT compound tag of a given item stack. * Set the NBT compound tag of a given item stack.
* <p> * <p>
* The item stack must be a wrapper for a CraftItemStack. Use * The item stack must be a wrapper for a CraftItemStack. Use
* {@link MinecraftReflection#getBukkitItemStack(ItemStack)} if not. * {@link MinecraftReflection#getCraftItemStack(ItemStack)} if not.
* @param stack - the item stack, cannot be air. * @param stack - the item stack, cannot be air.
* @param compound - the new NBT compound, or NULL to remove it. * @param compound - the new NBT compound, or NULL to remove it.
* @throws IllegalArgumentException If the stack is not a CraftItemStack, or it represents air. * @throws IllegalArgumentException If the stack is not a CraftItemStack, or it represents air.
@ -148,8 +148,8 @@ public class NbtFactory {
* auxillary data such as enchanting, name and lore is stored. It doesn't include the items * auxillary data such as enchanting, name and lore is stored. It doesn't include the items
* material, damage value or count. * material, damage value or count.
* <p> * <p>
* The item stack must be a wrapper for a CraftItemStack. Use * The item stack must be a wrapper for a CraftItemStack. Use
* {@link MinecraftReflection#getBukkitItemStack(ItemStack)} if not. * {@link MinecraftReflection#getCraftItemStack(ItemStack)} if not.
* @param stack - the item stack. * @param stack - the item stack.
* @return A wrapper for its NBT tag. * @return A wrapper for its NBT tag.
*/ */
@ -189,7 +189,7 @@ public class NbtFactory {
// Would be nice to avoid this, but alas - we have to use Java 6 // Would be nice to avoid this, but alas - we have to use Java 6
if (input != null) Closeables.close(input, swallow); if (input != null) Closeables.close(input, swallow);
else if (stream != null) Closeables.close(stream, swallow); else if (stream != null) Closeables.close(stream, swallow);
} }
} }
/** /**
@ -214,12 +214,12 @@ public class NbtFactory {
// Note the order // Note the order
if (output != null) Closeables.close(output, swallow); if (output != null) Closeables.close(output, swallow);
else if (stream != null) Closeables.close(stream, swallow); else if (stream != null) Closeables.close(stream, swallow);
} }
} }
/** /**
* Retrieve the NBT tile entity that represents the given block. * Retrieve the NBT tile entity that represents the given block.
* @param state - the block state. * @param block - the block.
* @return The NBT compound, or NULL if the state doesn't have a tile entity. * @return The NBT compound, or NULL if the state doesn't have a tile entity.
*/ */
public static NbtCompound readBlockState(Block block) { public static NbtCompound readBlockState(Block block) {
@ -274,7 +274,7 @@ public class NbtFactory {
// Use the first and best NBT tag // Use the first and best NBT tag
return itemStackModifier. return itemStackModifier.
withTarget(nmsStack). withTarget(nmsStack).
withType(MinecraftReflection.getNBTBaseClass(), withType(MinecraftReflection.getNBTBaseClass(),
BukkitConverters.getNbtConverter()); BukkitConverters.getNbtConverter());
} }
@ -332,7 +332,7 @@ public class NbtFactory {
/** /**
* Constructs a NBT tag of type string. * Constructs a NBT tag of type string.
* @param name - name of the tag. * @param name - name of the tag.
* @param value - value of the tag. * @param value - value of the tag.
* @return The constructed NBT tag. * @return The constructed NBT tag.
*/ */
public static NbtBase<String> of(String name, String value) { public static NbtBase<String> of(String name, String value) {
@ -342,7 +342,7 @@ public class NbtFactory {
/** /**
* Constructs a NBT tag of type byte. * Constructs a NBT tag of type byte.
* @param name - name of the tag. * @param name - name of the tag.
* @param value - value of the tag. * @param value - value of the tag.
* @return The constructed NBT tag. * @return The constructed NBT tag.
*/ */
public static NbtBase<Byte> of(String name, byte value) { public static NbtBase<Byte> of(String name, byte value) {
@ -352,7 +352,7 @@ public class NbtFactory {
/** /**
* Constructs a NBT tag of type short. * Constructs a NBT tag of type short.
* @param name - name of the tag. * @param name - name of the tag.
* @param value - value of the tag. * @param value - value of the tag.
* @return The constructed NBT tag. * @return The constructed NBT tag.
*/ */
public static NbtBase<Short> of(String name, short value) { public static NbtBase<Short> of(String name, short value) {
@ -362,7 +362,7 @@ public class NbtFactory {
/** /**
* Constructs a NBT tag of type int. * Constructs a NBT tag of type int.
* @param name - name of the tag. * @param name - name of the tag.
* @param value - value of the tag. * @param value - value of the tag.
* @return The constructed NBT tag. * @return The constructed NBT tag.
*/ */
public static NbtBase<Integer> of(String name, int value) { public static NbtBase<Integer> of(String name, int value) {
@ -372,7 +372,7 @@ public class NbtFactory {
/** /**
* Constructs a NBT tag of type long. * Constructs a NBT tag of type long.
* @param name - name of the tag. * @param name - name of the tag.
* @param value - value of the tag. * @param value - value of the tag.
* @return The constructed NBT tag. * @return The constructed NBT tag.
*/ */
public static NbtBase<Long> of(String name, long value) { public static NbtBase<Long> of(String name, long value) {
@ -382,7 +382,7 @@ public class NbtFactory {
/** /**
* Constructs a NBT tag of type float. * Constructs a NBT tag of type float.
* @param name - name of the tag. * @param name - name of the tag.
* @param value - value of the tag. * @param value - value of the tag.
* @return The constructed NBT tag. * @return The constructed NBT tag.
*/ */
public static NbtBase<Float> of(String name, float value) { public static NbtBase<Float> of(String name, float value) {
@ -392,7 +392,7 @@ public class NbtFactory {
/** /**
* Constructs a NBT tag of type double. * Constructs a NBT tag of type double.
* @param name - name of the tag. * @param name - name of the tag.
* @param value - value of the tag. * @param value - value of the tag.
* @return The constructed NBT tag. * @return The constructed NBT tag.
*/ */
public static NbtBase<Double> of(String name, double value) { public static NbtBase<Double> of(String name, double value) {
@ -402,7 +402,7 @@ public class NbtFactory {
/** /**
* Constructs a NBT tag of type byte array. * Constructs a NBT tag of type byte array.
* @param name - name of the tag. * @param name - name of the tag.
* @param value - value of the tag. * @param value - value of the tag.
* @return The constructed NBT tag. * @return The constructed NBT tag.
*/ */
public static NbtBase<byte[]> of(String name, byte[] value) { public static NbtBase<byte[]> of(String name, byte[] value) {
@ -412,7 +412,7 @@ public class NbtFactory {
/** /**
* Constructs a NBT tag of type int array. * Constructs a NBT tag of type int array.
* @param name - name of the tag. * @param name - name of the tag.
* @param value - value of the tag. * @param value - value of the tag.
* @return The constructed NBT tag. * @return The constructed NBT tag.
*/ */
public static NbtBase<int[]> of(String name, int[] value) { public static NbtBase<int[]> of(String name, int[] value) {
@ -421,7 +421,7 @@ public class NbtFactory {
/** /**
* Construct a new NBT compound initialized with a given list of NBT values. * Construct a new NBT compound initialized with a given list of NBT values.
* @param name - the name of the compound wrapper. * @param name - the name of the compound wrapper.
* @param list - the list of elements to add. * @param list - the list of elements to add.
* @return The new wrapped NBT compound. * @return The new wrapped NBT compound.
*/ */
@ -431,7 +431,7 @@ public class NbtFactory {
/** /**
* Construct a new NBT compound wrapper. * Construct a new NBT compound wrapper.
* @param name - the name of the compound wrapper. * @param name - the name of the compound wrapper.
* @return The new wrapped NBT compound. * @return The new wrapped NBT compound.
*/ */
public static NbtCompound ofCompound(String name) { public static NbtCompound ofCompound(String name) {
@ -519,7 +519,7 @@ public class NbtFactory {
if (type == NbtType.TAG_COMPOUND) if (type == NbtType.TAG_COMPOUND)
return (NbtWrapper<T>) new WrappedCompound(handle); return (NbtWrapper<T>) new WrappedCompound(handle);
else if (type == NbtType.TAG_LIST) else if (type == NbtType.TAG_LIST)
return (NbtWrapper<T>) new WrappedList(handle); return new WrappedList(handle);
else else
return new WrappedElement<T>(handle); return new WrappedElement<T>(handle);
} }
@ -532,7 +532,7 @@ public class NbtFactory {
if (type == NbtType.TAG_COMPOUND) if (type == NbtType.TAG_COMPOUND)
return (NbtWrapper<T>) new WrappedCompound(handle, name); return (NbtWrapper<T>) new WrappedCompound(handle, name);
else if (type == NbtType.TAG_LIST) else if (type == NbtType.TAG_LIST)
return (NbtWrapper<T>) new WrappedList(handle, name); return new WrappedList(handle, name);
else else
return new WrappedElement<T>(handle, name); return new WrappedElement<T>(handle, name);
} }

Datei anzeigen

@ -23,7 +23,7 @@ public interface NbtList<TType> extends NbtBase<List<NbtBase<TType>>>, Iterable<
public static String EMPTY_NAME = ""; public static String EMPTY_NAME = "";
/** /**
* Get the type of each element. * Get the type of each element.
* <p> * <p>
* This will be {@link NbtType#TAG_END TAG_END} if the NBT list has just been created. * This will be {@link NbtType#TAG_END TAG_END} if the NBT list has just been created.
* @return Element type. * @return Element type.
@ -51,56 +51,56 @@ public interface NbtList<TType> extends NbtBase<List<NbtBase<TType>>>, Iterable<
public abstract void add(NbtBase<TType> element); public abstract void add(NbtBase<TType> element);
/** /**
* Add a new string element to the list. * Add a new string element to the list.
* @param value - the string element to add. * @param value - the string element to add.
* @throws IllegalArgumentException If this is not a list of strings. * @throws IllegalArgumentException If this is not a list of strings.
*/ */
public abstract void add(String value); public abstract void add(String value);
/** /**
* Add a new byte element to the list. * Add a new byte element to the list.
* @param value - the byte element to add. * @param value - the byte element to add.
* @throws IllegalArgumentException If this is not a list of bytes. * @throws IllegalArgumentException If this is not a list of bytes.
*/ */
public abstract void add(byte value); public abstract void add(byte value);
/** /**
* Add a new short element to the list. * Add a new short element to the list.
* @param value - the short element to add. * @param value - the short element to add.
* @throws IllegalArgumentException If this is not a list of shorts. * @throws IllegalArgumentException If this is not a list of shorts.
*/ */
public abstract void add(short value); public abstract void add(short value);
/** /**
* Add a new integer element to the list. * Add a new integer element to the list.
* @param value - the string element to add. * @param value - the string element to add.
* @throws IllegalArgumentException If this is not a list of integers. * @throws IllegalArgumentException If this is not a list of integers.
*/ */
public abstract void add(int value); public abstract void add(int value);
/** /**
* Add a new long element to the list. * Add a new long element to the list.
* @param value - the string element to add. * @param value - the string element to add.
* @throws IllegalArgumentException If this is not a list of longs. * @throws IllegalArgumentException If this is not a list of longs.
*/ */
public abstract void add(long value); public abstract void add(long value);
/** /**
* Add a new double element to the list. * Add a new double element to the list.
* @param value - the double element to add. * @param value - the double element to add.
* @throws IllegalArgumentException If this is not a list of doubles. * @throws IllegalArgumentException If this is not a list of doubles.
*/ */
public abstract void add(double value); public abstract void add(double value);
/** /**
* Add a new byte array element to the list. * Add a new byte array element to the list.
* @param value - the byte array element to add. * @param value - the byte array element to add.
* @throws IllegalArgumentException If this is not a list of byte arrays. * @throws IllegalArgumentException If this is not a list of byte arrays.
*/ */
public abstract void add(byte[] value); public abstract void add(byte[] value);
/** /**
* Add a new int array element to the list. * Add a new int array element to the list.
* @param value - the int array element to add. * @param value - the int array element to add.
* @throws IllegalArgumentException If this is not a list of int arrays. * @throws IllegalArgumentException If this is not a list of int arrays.
*/ */
@ -116,7 +116,7 @@ public interface NbtList<TType> extends NbtBase<List<NbtBase<TType>>>, Iterable<
* Retrieve an element by index. * Retrieve an element by index.
* @param index - index of the element to retrieve. * @param index - index of the element to retrieve.
* @return The element to retrieve. * @return The element to retrieve.
* @throws IndexOutOfBoundsException If the index is out of range (index < 0 || index >= size()) * @throws IndexOutOfBoundsException If the index is out of range
*/ */
public abstract TType getValue(int index); public abstract TType getValue(int index);
@ -135,5 +135,6 @@ public interface NbtList<TType> extends NbtBase<List<NbtBase<TType>>>, Iterable<
/** /**
* Iterate over all the elements in this list. * Iterate over all the elements in this list.
*/ */
@Override
public abstract Iterator<TType> iterator(); public abstract Iterator<TType> iterator();
} }