Handling the case where someone is writing a NULL element to
a equivalent converter.
Dieser Commit ist enthalten in:
Ursprung
8bd7f75a6d
Commit
57add8e26f
@ -143,7 +143,8 @@ public class PacketContainer implements Serializable {
|
|||||||
*/
|
*/
|
||||||
public StructureModifier<ItemStack> getItemModifier() {
|
public StructureModifier<ItemStack> getItemModifier() {
|
||||||
// Convert from and to the Bukkit wrapper
|
// Convert from and to the Bukkit wrapper
|
||||||
return structureModifier.<ItemStack>withType(net.minecraft.server.ItemStack.class, new EquivalentConverter<ItemStack>() {
|
return structureModifier.<ItemStack>withType(net.minecraft.server.ItemStack.class,
|
||||||
|
getIgnoreNull(new EquivalentConverter<ItemStack>() {
|
||||||
public Object getGeneric(ItemStack specific) {
|
public Object getGeneric(ItemStack specific) {
|
||||||
return toStackNMS(specific);
|
return toStackNMS(specific);
|
||||||
}
|
}
|
||||||
@ -157,7 +158,7 @@ public class PacketContainer implements Serializable {
|
|||||||
public Class<ItemStack> getSpecificType() {
|
public Class<ItemStack> getSpecificType() {
|
||||||
return ItemStack.class;
|
return ItemStack.class;
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -169,7 +170,10 @@ public class PacketContainer implements Serializable {
|
|||||||
*/
|
*/
|
||||||
public StructureModifier<ItemStack[]> getItemArrayModifier() {
|
public StructureModifier<ItemStack[]> getItemArrayModifier() {
|
||||||
// Convert to and from the Bukkit wrapper
|
// Convert to and from the Bukkit wrapper
|
||||||
return structureModifier.<ItemStack[]>withType(net.minecraft.server.ItemStack[].class, new EquivalentConverter<ItemStack[]>() {
|
return structureModifier.<ItemStack[]>withType(
|
||||||
|
net.minecraft.server.ItemStack[].class,
|
||||||
|
getIgnoreNull(new EquivalentConverter<ItemStack[]>() {
|
||||||
|
|
||||||
public Object getGeneric(ItemStack[] specific) {
|
public Object getGeneric(ItemStack[] specific) {
|
||||||
net.minecraft.server.ItemStack[] result = new net.minecraft.server.ItemStack[specific.length];
|
net.minecraft.server.ItemStack[] result = new net.minecraft.server.ItemStack[specific.length];
|
||||||
|
|
||||||
@ -196,7 +200,7 @@ public class PacketContainer implements Serializable {
|
|||||||
public Class<ItemStack[]> getSpecificType() {
|
public Class<ItemStack[]> getSpecificType() {
|
||||||
return ItemStack[].class;
|
return ItemStack[].class;
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -228,7 +232,10 @@ public class PacketContainer implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Convert to and from the Bukkit wrapper
|
// Convert to and from the Bukkit wrapper
|
||||||
return structureModifier.<WorldType>withType(net.minecraft.server.WorldType.class, new EquivalentConverter<WorldType>() {
|
return structureModifier.<WorldType>withType(
|
||||||
|
net.minecraft.server.WorldType.class,
|
||||||
|
getIgnoreNull(new EquivalentConverter<WorldType>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getGeneric(WorldType specific) {
|
public Object getGeneric(WorldType specific) {
|
||||||
return net.minecraft.server.WorldType.getType(specific.getName());
|
return net.minecraft.server.WorldType.getType(specific.getName());
|
||||||
@ -244,7 +251,7 @@ public class PacketContainer implements Serializable {
|
|||||||
public Class<WorldType> getSpecificType() {
|
public Class<WorldType> getSpecificType() {
|
||||||
return WorldType.class;
|
return WorldType.class;
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -268,7 +275,10 @@ public class PacketContainer implements Serializable {
|
|||||||
"getEntity", nmsEntityClass, new Class[] { int.class });
|
"getEntity", nmsEntityClass, new Class[] { int.class });
|
||||||
|
|
||||||
// Convert to and from the Bukkit wrapper
|
// Convert to and from the Bukkit wrapper
|
||||||
return structureModifier.<Entity>withType(int.class, new EquivalentConverter<Entity>() {
|
return structureModifier.<Entity>withType(
|
||||||
|
int.class,
|
||||||
|
getIgnoreNull(new EquivalentConverter<Entity>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getGeneric(Entity specific) {
|
public Object getGeneric(Entity specific) {
|
||||||
// Simple enough
|
// Simple enough
|
||||||
@ -310,7 +320,32 @@ public class PacketContainer implements Serializable {
|
|||||||
public Class<Entity> getSpecificType() {
|
public Class<Entity> getSpecificType() {
|
||||||
return Entity.class;
|
return Entity.class;
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
private <TType> EquivalentConverter<TType> getIgnoreNull(final EquivalentConverter<TType> delegate) {
|
||||||
|
// Automatically wrap all parameters to the delegate with a NULL check
|
||||||
|
return new EquivalentConverter<TType>() {
|
||||||
|
public Object getGeneric(TType specific) {
|
||||||
|
if (specific != null)
|
||||||
|
return delegate.getGeneric(specific);
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TType getSpecific(Object generic) {
|
||||||
|
if (generic != null)
|
||||||
|
return delegate.getSpecific(generic);
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<TType> getSpecificType() {
|
||||||
|
return delegate.getSpecificType();
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren