Skip to content

Commit

Permalink
Added new bukkit plugin name resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
SBPrime committed Jul 10, 2016
1 parent 8f70f78 commit 0fed6f1
Showing 1 changed file with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,38 +50,40 @@
* @author SBPrime
*/
public class BukkitBaseEntity extends BaseEntity {

protected BukkitBaseEntity(JavaPlugin plugin) {
this(plugin, null);
}

protected BukkitBaseEntity(JavaPlugin plugin, String name) {
this(getName(plugin, name), plugin != null);
}

private BukkitBaseEntity(String name, boolean isEnabled) {
super(name != null ? name : "?", isEnabled && name != null);
}



private static String getName(JavaPlugin plugin, String name) {
if (plugin == null) {
return name;
}

PluginDescriptionFile pd = plugin.getDescription();
if (pd == null) {
return name;
}

String pName = pd.getName();
if (pName != null) {
return pName;
if (pd != null) {
String pName = pd.getName();
String version = pd.getVersion();
if (pName != null && version != null) {
return String.format("%1$s %2$s", pName, version);
}
else if (pName != null) {
return pName;
}
}

if (name == null) {
return plugin.getClass().getCanonicalName();
}

return name;
}
}

0 comments on commit 0fed6f1

Please sign in to comment.