@@ -3,15 +3,18 @@
import java .io .InputStream ;
import java .io .Reader ;
import java .io .Writer ;
import java .util .ArrayList ;
import java .util .HashMap ;
import java .util .List ;
import java .util .Map ;
import org .bukkit .permissions .Permission ;
import org .bukkit .permissions .PermissionDefault ;
import org .yaml .snakeyaml .Yaml ;
import org .yaml .snakeyaml .constructor .SafeConstructor ;
import com .google .common .collect .ImmutableList ;
import com .google .common .collect .ImmutableMap ;
/**
* Provides access to a Plugins description file, plugin.yaml
*/
@@ -20,21 +23,20 @@ public final class PluginDescriptionFile {
private String name = null ;
private String main = null ;
private String classLoaderOf = null ;
private ArrayList <String > depend = null ;
private ArrayList <String > softDepend = null ;
private List <String > depend = null ;
private List <String > softDepend = null ;
private String version = null ;
private Object commands = null ;
private Map < String , Map < String , Object >> commands = null ;
private String description = null ;
private ArrayList <String > authors = new ArrayList < String >() ;
private List <String > authors = null ;
private String website = null ;
private boolean database = false ;
private PluginLoadOrder order = PluginLoadOrder .POSTWORLD ;
private List <Permission > permissions = new ArrayList < Permission >() ;
private List <Permission > permissions = null ;
private PermissionDefault defaultPerm = PermissionDefault .OP ;
@ SuppressWarnings ("unchecked" )
public PluginDescriptionFile (final InputStream stream ) throws InvalidDescriptionException {
loadMap ((Map <String , Object >) yaml .load (stream ));
loadMap ((Map <?, ? >) yaml .load (stream ));
}
/**
@@ -43,9 +45,8 @@ public PluginDescriptionFile(final InputStream stream) throws InvalidDescription
* @param reader The reader
* @throws InvalidDescriptionException If the PluginDescriptionFile is invalid
*/
@ SuppressWarnings ("unchecked" )
public PluginDescriptionFile (final Reader reader ) throws InvalidDescriptionException {
loadMap ((Map <String , Object >) yaml .load (reader ));
loadMap ((Map <?, ? >) yaml .load (reader ));
}
/**
@@ -106,15 +107,15 @@ public String getMain() {
return main ;
}
public Object getCommands () {
public Map < String , Map < String , Object >> getCommands () {
return commands ;
}
public Object getDepend () {
public List < String > getDepend () {
return depend ;
}
public Object getSoftDepend () {
public List < String > getSoftDepend () {
return softDepend ;
}
@@ -131,7 +132,7 @@ public String getDescription() {
return description ;
}
public ArrayList <String > getAuthors () {
public List <String > getAuthors () {
return authors ;
}
@@ -159,8 +160,7 @@ public String getClassLoaderOf() {
return classLoaderOf ;
}
@ SuppressWarnings ("unchecked" )
private void loadMap (Map <String , Object > map ) throws InvalidDescriptionException {
private void loadMap (Map <?, ?> map ) throws InvalidDescriptionException {
try {
name = map .get ("name" ).toString ();
@@ -193,31 +193,56 @@ private void loadMap(Map<String, Object> map) throws InvalidDescriptionException
}
if (map .containsKey ("commands" )) {
ImmutableMap .Builder <String , Map <String , Object >> commandsBuilder = ImmutableMap .<String , Map <String , Object >>builder ();
try {
commands = map .get ("commands" );
for (Map .Entry <?, ?> command : ((Map <?, ?>) map .get ("commands" )).entrySet ()) {
ImmutableMap .Builder <String , Object > commandBuilder = ImmutableMap .<String , Object >builder ();
for (Map .Entry <?, ?> commandEntry : ((Map <?, ?>) command .getValue ()).entrySet ()) {
if (commandEntry .getValue () instanceof Iterable ) {
// This prevents internal alias list changes
ImmutableList .Builder <Object > commandSubList = ImmutableList .<Object >builder ();
for (Object commandSubListItem : (Iterable <?>) commandEntry .getValue ()) {
commandSubList .add (commandSubListItem );
}
commandBuilder .put (commandEntry .getKey ().toString (), commandSubList .build ());
} else {
commandBuilder .put (commandEntry .getKey ().toString (), commandEntry .getValue ());
}
}
commandsBuilder .put (command .getKey ().toString (), commandBuilder .build ());
}
} catch (ClassCastException ex ) {
throw new InvalidDescriptionException (ex , "commands are of wrong type" );
}
commands = commandsBuilder .build ();
}
if (map .containsKey ("class-loader-of" )) {
classLoaderOf = map .get ("class-loader-of" ).toString ();
}
if (map .containsKey ("depend" )) {
ImmutableList .Builder <String > dependBuilder = ImmutableList .<String >builder ();
try {
depend = (ArrayList <String >) map .get ("depend" );
for (Object dependency : (Iterable <?>) map .get ("depend" )) {
dependBuilder .add (dependency .toString ());
}
} catch (ClassCastException ex ) {
throw new InvalidDescriptionException (ex , "depend is of wrong type" );
}
depend = dependBuilder .build ();
}
if (map .containsKey ("softdepend" )) {
ImmutableList .Builder <String > softDependBuilder = ImmutableList .<String >builder ();
try {
softDepend = (ArrayList <String >) map .get ("softdepend" );
for (Object dependency : (Iterable <?>) map .get ("softdepend" )) {
softDependBuilder .add (dependency .toString ());
}
} catch (ClassCastException ex ) {
throw new InvalidDescriptionException (ex , "softdepend is of wrong type" );
}
softDepend = softDependBuilder .build ();
}
if (map .containsKey ("database" )) {
@@ -229,19 +254,11 @@ private void loadMap(Map<String, Object> map) throws InvalidDescriptionException
}
if (map .containsKey ("website" )) {
try {
website = (String ) map .get ("website" );
} catch (ClassCastException ex ) {
throw new InvalidDescriptionException (ex , "website is of wrong type" );
}
website = map .get ("website" ).toString ();
}
if (map .containsKey ("description" )) {
try {
description = (String ) map .get ("description" );
} catch (ClassCastException ex ) {
throw new InvalidDescriptionException (ex , "description is of wrong type" );
}
description = map .get ("description" ).toString ();
}
if (map .containsKey ("load" )) {
@@ -254,29 +271,28 @@ private void loadMap(Map<String, Object> map) throws InvalidDescriptionException
}
}
if (map .containsKey ("author" )) {
try {
String extra = (String ) map .get ("author" );
authors .add (extra );
} catch (ClassCastException ex ) {
throw new InvalidDescriptionException (ex , "author is of wrong type" );
}
}
if (map .containsKey ("authors" )) {
ImmutableList .Builder <String > authorsBuilder = ImmutableList .<String >builder ();
if (map .containsKey ("author" )) {
authorsBuilder .add (map .get ("author" ).toString ());
}
try {
ArrayList < String > extra = ( ArrayList < String >) map .get ("authors" );
authors . addAll ( extra );
for ( Object o : ( Iterable <? >) map .get ("authors" )) {
authorsBuilder . add ( o . toString ());
}
} catch (ClassCastException ex ) {
throw new InvalidDescriptionException (ex , "authors are of wrong type" );
}
authors = authorsBuilder .build ();
} else if (map .containsKey ("author" )) {
authors = ImmutableList .of (map .get ("author" ).toString ());
} else {
authors = ImmutableList .<String >of ();
}
if (map .containsKey ("default-permission" )) {
try {
defaultPerm = PermissionDefault .getByName (( String ) map .get ("default-permission" ));
defaultPerm = PermissionDefault .getByName (map .get ("default-permission" ). toString ( ));
} catch (ClassCastException ex ) {
throw new InvalidDescriptionException (ex , "default-permission is of wrong type" );
} catch (IllegalArgumentException ex ) {
@@ -286,12 +302,14 @@ private void loadMap(Map<String, Object> map) throws InvalidDescriptionException
if (map .containsKey ("permissions" )) {
try {
Map <String , Map < String , Object >> perms = (Map <String , Map < String , Object > >) map .get ("permissions" );
Map <?, ?> perms = (Map <?, ? >) map .get ("permissions" );
permissions = Permission .loadPermissions (perms , "Permission node '%s' in plugin description file for " + getFullName () + " is invalid" , defaultPerm );
permissions = ImmutableList . copyOf ( Permission .loadPermissions (perms , "Permission node '%s' in plugin description file for " + getFullName () + " is invalid" , defaultPerm ) );
} catch (ClassCastException ex ) {
throw new InvalidDescriptionException (ex , "permissions are of wrong type" );
}
} else {
permissions = ImmutableList .<Permission >of ();
}
}
don't know why yet but this breaks the plugin dwarfforge which I'm keeping alive.. https://github.com/dredhorse/DwarfForge/issues/12
will look into it, just letting you know.