mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-24 11:36:51 +01:00
Improve the names command.
This commit is contained in:
parent
f2e078ce6a
commit
da0d55fcea
@ -204,13 +204,17 @@ class CommandPacket implements CommandExecutor {
|
||||
sendMessageSilently(sender, ChatColor.BLUE + "Fully removed " + count + " listeners.");
|
||||
} else if (subCommand == SubCommand.NAMES) {
|
||||
|
||||
Set<Integer> named = getNamedPackets(side);
|
||||
|
||||
// Print the equivalent name of every given ID
|
||||
for (Range<Integer> range : ranges) {
|
||||
for (int id : range.asSet(DiscreteDomains.integers())) {
|
||||
if (named.contains(id)) {
|
||||
sendMessageSilently(sender, ChatColor.BLUE + "" + id + ": " + Packets.getDeclaredName(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
sendMessageSilently(sender, ChatColor.RED + "Cannot parse number: " + e.getMessage());
|
||||
@ -368,6 +372,30 @@ class CommandPacket implements CommandExecutor {
|
||||
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) {
|
||||
|
||||
Set<Integer> range = Ranges.closed(idStart, idStop).asSet(DiscreteDomains.integers());
|
||||
|
@ -12,8 +12,6 @@ import java.net.URLConnection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
@ -22,7 +20,6 @@ import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.events.XMLEvent;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
package com.comphenix.protocol.reflect;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
@ -100,6 +101,6 @@ public class IntEnum {
|
||||
* @return Enumeration of every value.
|
||||
*/
|
||||
public Set<Integer> values() {
|
||||
return members.keySet();
|
||||
return new HashSet<Integer>(members.keySet());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user