use of com.solinia.solinia.Exceptions.SoliniaSpawnGroupCreationException in project solinia3-core by mixxit.
the class SoliniaSpawnGroupFactory method Create.
public static void Create(String spawngroupname, int npcid, Location location, boolean operatorCreated) throws CoreStateInitException, SoliniaSpawnGroupCreationException {
if (StateManager.getInstance().getConfigurationManager().getSpawnGroup(spawngroupname.toUpperCase()) != null)
throw new SoliniaSpawnGroupCreationException("Spawngroup already exists");
if (StateManager.getInstance().getConfigurationManager().getNPC(npcid) == null)
throw new SoliniaSpawnGroupCreationException("NPC does not exist");
SoliniaSpawnGroup sg = new SoliniaSpawnGroup();
sg.setId(StateManager.getInstance().getConfigurationManager().getNextSpawnGroupId());
sg.setName(spawngroupname.toUpperCase());
sg.setNpcid(npcid);
sg.setLocation(location);
sg.setRespawntime(900);
sg.setOperatorCreated(operatorCreated);
StateManager.getInstance().getConfigurationManager().addSpawnGroup(sg);
}
use of com.solinia.solinia.Exceptions.SoliniaSpawnGroupCreationException in project solinia3-core by mixxit.
the class CommandCreateSpawnGroup method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player))
return false;
Player player = (Player) sender;
if (!player.isOp() && !player.hasPermission("solinia.createspawngroup")) {
player.sendMessage("You do not have permission to access this command");
return false;
}
if (args.length < 2) {
sender.sendMessage("Insufficient arguments: npcid, spawngroupname");
return false;
}
// args
// defaultnpcid
// spawngroupname
int npcid = Integer.parseInt(args[0]);
if (npcid < 1) {
sender.sendMessage("NPCID is invalid");
return false;
}
ISoliniaNPC npc;
try {
npc = StateManager.getInstance().getConfigurationManager().getNPC(npcid);
} catch (CoreStateInitException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
sender.sendMessage(e1.getMessage());
return true;
}
if (npc == null) {
sender.sendMessage("The ID number you provided for the NPC is invalid");
return false;
}
String spawngroupname = "";
int count = 0;
for (String entry : args) {
if (count == 0) {
count++;
continue;
}
spawngroupname += entry;
count++;
}
if (spawngroupname.equals("")) {
sender.sendMessage("Blank name not allowed when creating spawngroup");
return false;
}
spawngroupname.replace(" ", "_");
try {
SoliniaSpawnGroupFactory.Create(spawngroupname, npcid, player.getLocation(), sender.isOp());
sender.sendMessage("SpawnGroup created at your location");
} catch (CoreStateInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
sender.sendMessage(e.getMessage());
return true;
} catch (SoliniaSpawnGroupCreationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
sender.sendMessage(e.getMessage());
return true;
}
return true;
}
Aggregations