Archiviert
13
0

Fix empty chat messages

Also improved incompatible plugin checking
Dieser Commit ist enthalten in:
Dan Mulloy 2015-07-06 02:20:32 -04:00
Ursprung 7b9e0cdb65
Commit 7861a57d37
2 geänderte Dateien mit 46 neuen und 24 gelöschten Zeilen

Datei anzeigen

@ -19,6 +19,8 @@ package com.comphenix.protocol;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.Arrays;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.logging.Handler; import java.util.logging.Handler;
import java.util.logging.Level; import java.util.logging.Level;
@ -428,23 +430,22 @@ public class ProtocolLibrary extends JavaPlugin {
} }
} }
private void checkForIncompatibility(PluginManager manager) {
// Plugin authors: Notify me to remove these // Plugin authors: Notify me to remove these
String[] incompatible = { }; public static List<String> INCOMPATIBLE = Arrays.asList("TagAPI");
for (String plugin : incompatible) { private void checkForIncompatibility(PluginManager manager) {
for (String plugin : INCOMPATIBLE) {
if (manager.getPlugin(plugin) != null) { if (manager.getPlugin(plugin) != null) {
// Check for versions, etc.
logger.severe("Detected incompatible plugin: " + plugin);
}
}
// Special case for TagAPI and iTag // Special case for TagAPI and iTag
if (manager.getPlugin("TagAPI") != null) { if (plugin.equals("TagAPI")) {
Plugin iTag = manager.getPlugin("iTag"); Plugin iTag = manager.getPlugin("iTag");
if (iTag == null || iTag.getDescription().getVersion().startsWith("1.0")) { if (iTag == null || iTag.getDescription().getVersion().startsWith("1.0")) {
logger.severe("Detected incompatible plugin: TagAPI"); logger.severe("Detected incompatible plugin: TagAPI");
} }
} else {
logger.severe("Detected incompatible plugin: " + plugin);
}
}
} }
} }

Datei anzeigen

@ -33,7 +33,6 @@ import com.comphenix.protocol.reflect.instances.BannedGenerator;
import com.comphenix.protocol.reflect.instances.DefaultInstances; import com.comphenix.protocol.reflect.instances.DefaultInstances;
import com.comphenix.protocol.reflect.instances.InstanceProvider; import com.comphenix.protocol.reflect.instances.InstanceProvider;
import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.utility.MinecraftReflection;
import com.comphenix.protocol.utility.Util;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
@ -183,21 +182,23 @@ public class StructureModifier<TField> {
this.useStructureCompiler = useStructureCompiler; this.useStructureCompiler = useStructureCompiler;
} }
private static final List<String> BROKEN_PLUGINS = Util.asList("TagAPI");
/** /**
* Reads the value of a field given its index. * Reads the value of a field given its index.
* <p>
* Note: This method is prone to exceptions (there are currently 5 total throw statements). It is recommended that you
* use {@link #readSafely(int)}, which returns {@code null} if the field doesn't exist, instead of throwing an exception.
*
* @param fieldIndex - index of the field. * @param fieldIndex - index of the field.
* @return Value of the field. * @return Value of the field.
* @throws FieldAccessException The field doesn't exist, or it cannot be accessed under the current security contraints. * @throws FieldAccessException if the field doesn't exist, or it cannot be accessed under the current security contraints.
*/ */
public TField read(int fieldIndex) throws FieldAccessException { public TField read(int fieldIndex) throws FieldAccessException {
try { try {
return readInternal(fieldIndex); return readInternal(fieldIndex);
} catch (FieldAccessException ex) { } catch (FieldAccessException ex) {
String plugin = PluginContext.getPluginCaller(ex); String plugin = PluginContext.getPluginCaller(ex);
if (BROKEN_PLUGINS.contains(plugin)) { if (ProtocolLibrary.INCOMPATIBLE.contains(plugin)) {
ProtocolLibrary.log(Level.WARNING, "Encountered an exception caused by broken plugin {0}.", plugin); ProtocolLibrary.log(Level.WARNING, "Encountered an exception caused by incompatible plugin {0}.", plugin);
ProtocolLibrary.log(Level.WARNING, "It is advised that you remove it."); ProtocolLibrary.log(Level.WARNING, "It is advised that you remove it.");
} }
@ -235,10 +236,24 @@ public class StructureModifier<TField> {
} }
/** /**
* Reads the value of a field if and ONLY IF it exists. * Reads the value of a field only if it exists. If the field does not exist, {@code null} is returned.
* <p>
* As its name implies, this method is a much safer alternative to {@link #read(int)}.
* In addition to throwing less exceptions and thereby causing less console spam, this
* method makes providing backwards compatiblity signficiantly easier, as shown below:
*
* <pre><code>
* BlockPosition position = packet.getBlockPositionModifier().readSafely(0);
* if (position != null) {
* // Handle 1.8+
* } else {
* // Handle 1.7-
* }
* </code></pre>
*
* @param fieldIndex - index of the field. * @param fieldIndex - index of the field.
* @return Value of the field, or NULL if it doesn't exist. * @return Value of the field, or NULL if it doesn't exist.
* @throws FieldAccessException The field cannot be accessed under the current security contraints. * @throws FieldAccessException if the field cannot be accessed under the current security constraints.
*/ */
public TField readSafely(int fieldIndex) throws FieldAccessException { public TField readSafely(int fieldIndex) throws FieldAccessException {
if (fieldIndex >= 0 && fieldIndex < data.size()) { if (fieldIndex >= 0 && fieldIndex < data.size()) {
@ -312,8 +327,8 @@ public class StructureModifier<TField> {
return writeInternal(fieldIndex, value); return writeInternal(fieldIndex, value);
} catch (FieldAccessException ex) { } catch (FieldAccessException ex) {
String plugin = PluginContext.getPluginCaller(ex); String plugin = PluginContext.getPluginCaller(ex);
if (BROKEN_PLUGINS.contains(plugin)) { if (ProtocolLibrary.INCOMPATIBLE.contains(plugin)) {
ProtocolLibrary.log(Level.WARNING, "Encountered an exception caused by broken plugin {0}.", plugin); ProtocolLibrary.log(Level.WARNING, "Encountered an exception caused by incompatible plugin {0}.", plugin);
ProtocolLibrary.log(Level.WARNING, "It is advised that you remove it."); ProtocolLibrary.log(Level.WARNING, "It is advised that you remove it.");
} }
@ -412,6 +427,12 @@ public class StructureModifier<TField> {
// Write a default instance to every field // Write a default instance to every field
for (Field field : defaultFields.keySet()) { for (Field field : defaultFields.keySet()) {
if (field.getType().getCanonicalName().equals("net.md_5.bungee.api.chat.BaseComponent[]")) {
// Special case for Spigot's custom chat components
// Generating this will cause messages to be blank
continue;
}
try { try {
FieldUtils.writeField(field, target, FieldUtils.writeField(field, target,
generator.getDefault(field.getType()), true); generator.getDefault(field.getType()), true);