use of io.github.nucleuspowered.nucleus.modules.home.events.CreateHomeEvent in project Nucleus by NucleusPowered.
the class HomeHandler method createHomeInternal.
public void createHomeInternal(Cause cause, User user, String name, Location<World> location, Vector3d rotation) throws NucleusException {
if (!NucleusHomeService.HOME_NAME_PATTERN.matcher(name).matches()) {
throw new NucleusException(Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("command.sethome.name"), NucleusException.ExceptionType.DISALLOWED_NAME);
}
int max = getMaximumHomes(user);
if (getHomes(user.getUniqueId()).size() >= max) {
throw new NucleusException(Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("command.sethome.limit", String.valueOf(max)), NucleusException.ExceptionType.LIMIT_REACHED);
}
CreateHomeEvent event = new CreateHomeEvent(name, user, cause, location);
postEvent(event);
// Just in case.
if (!Nucleus.getNucleus().getUserDataManager().get(user).get().get(HomeUserDataModule.class).setHome(name, location, rotation, false)) {
throw new NucleusException(Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("command.sethome.seterror", name), NucleusException.ExceptionType.UNKNOWN_ERROR);
}
}
Aggregations