Improve the names command.

This commit is contained in:
Kristian S. Stangeland 2012-11-03 07:16:20 +01:00
parent f2e078ce6a
commit da0d55fcea
3 changed files with 31 additions and 5 deletions

View File

@ -204,10 +204,14 @@ class CommandPacket implements CommandExecutor {
sendMessageSilently(sender, ChatColor.BLUE + "Fully removed " + count + " listeners."); sendMessageSilently(sender, ChatColor.BLUE + "Fully removed " + count + " listeners.");
} else if (subCommand == SubCommand.NAMES) { } else if (subCommand == SubCommand.NAMES) {
Set<Integer> named = getNamedPackets(side);
// Print the equivalent name of every given ID // Print the equivalent name of every given ID
for (Range<Integer> range : ranges) { for (Range<Integer> range : ranges) {
for (int id : range.asSet(DiscreteDomains.integers())) { for (int id : range.asSet(DiscreteDomains.integers())) {
sendMessageSilently(sender, ChatColor.BLUE + "" + id + ": " + Packets.getDeclaredName(id)); if (named.contains(id)) {
sendMessageSilently(sender, ChatColor.BLUE + "" + id + ": " + Packets.getDeclaredName(id));
}
} }
} }
} }
@ -368,6 +372,30 @@ class CommandPacket implements CommandExecutor {
throw new IllegalArgumentException("Illegal side: " + side); throw new IllegalArgumentException("Illegal side: " + side);
} }
private Set<Integer> getNamedPackets(ConnectionSide side) {
Set<Integer> valids = null;
Set<Integer> result = null;
try {
valids = getValidPackets(side);
} catch (FieldAccessException e) {
valids = Ranges.closed(0, 255).asSet(DiscreteDomains.integers());
}
// Check connection side
if (side.isForClient())
result = Packets.Client.getRegistry().values();
else if (side.isForServer())
result = Packets.Server.getRegistry().values();
else
throw new IllegalArgumentException("Illegal side: " + side);
// Remove invalid packets
result.retainAll(valids);
return result;
}
public DetailedPacketListener createPacketListener(final ConnectionSide side, int idStart, int idStop, final boolean detailed) { public DetailedPacketListener createPacketListener(final ConnectionSide side, int idStart, int idStop, final boolean detailed) {
Set<Integer> range = Ranges.closed(idStart, idStop).asSet(DiscreteDomains.integers()); Set<Integer> range = Ranges.closed(idStart, idStop).asSet(DiscreteDomains.integers());

View File

@ -12,8 +12,6 @@ import java.net.URLConnection;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
@ -22,7 +20,6 @@ import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.XMLEvent; import javax.xml.stream.events.XMLEvent;
import org.bukkit.Server;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;

View File

@ -18,6 +18,7 @@
package com.comphenix.protocol.reflect; package com.comphenix.protocol.reflect;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
@ -100,6 +101,6 @@ public class IntEnum {
* @return Enumeration of every value. * @return Enumeration of every value.
*/ */
public Set<Integer> values() { public Set<Integer> values() {
return members.keySet(); return new HashSet<Integer>(members.keySet());
} }
} }