Fix for faction creation sometimes causing an NPE; hopefully a fix for the cause of the null value as well, from an ID clash in the entity collection of factions

Fix for disband command causing an NPE if run from the console
Additionally, disband command use is now logged
This commit is contained in:
Brettflan 2011-10-13 04:10:29 -05:00
parent cace4aa955
commit 4ec086e4fa
4 changed files with 18 additions and 5 deletions

View File

@ -58,6 +58,13 @@ public class CmdCreate extends FCommand
if ( ! payForCommand(Conf.econCostCreate, "to create a new faction", "for creating a new faction")) return;
Faction faction = Factions.i.create();
if (faction == null)
{
msg("<b>There was an internal error while trying to create your faction. Please try again.");
return;
}
faction.setTag(tag);
fme.setRole(Role.ADMIN);
fme.setFaction(faction);

View File

@ -44,7 +44,7 @@ public class CmdDisband extends FCommand
}
else
{
if ( ! Permission.DISBAND_ANY.has(me, true))
if ( ! Permission.DISBAND_ANY.has(sender, true))
{
return;
}
@ -69,6 +69,7 @@ public class CmdDisband extends FCommand
fplayer.msg("<h>%s<i> disbanded the faction %s.", who, faction.getTag(fplayer));
}
}
P.p.log("The faction "+faction.getTag()+" ("+faction.getId()+") was disbanded by "+(senderIsConsole ? "console command" : fme.getName())+".");
if (Econ.shouldBeUsed())
{

View File

@ -41,7 +41,7 @@ public class SpoutFeatures
{
listenersHooked = true;
mainListener = new SpoutMainListener();
P.p.getServer().getPluginManager().registerEvent(Event.Type.CUSTOM_EVENT, mainListener, Event.Priority.Normal, P.p);
P.p.registerEvent(Event.Type.CUSTOM_EVENT, mainListener, Event.Priority.Normal);
}
}
else

View File

@ -217,8 +217,13 @@ public abstract class EntityCollection<E extends Entity>
public String getNextId()
{
this.nextId += 1;
return "" + (nextId - 1);
String next = Integer.toString(this.nextId);
do
{
this.nextId += 1;
} while ( ! isIdFree(Integer.toString(this.nextId)) );
return next;
}
public boolean isIdFree(String id)