@Override public boolean execute(Player p, String[] args) { if (args.length < 1) { server.sendLocalizedMessage(p, HSPMessages.ERROR_ID_NUMBER_REQUIRED, "input", "null"); return true; } int id = -1; try { id = Integer.parseInt(args[0]); } catch (NumberFormatException e) { server.sendLocalizedMessage(p, HSPMessages.ERROR_ID_NUMBER_REQUIRED, "input", args[0]); return true; } com.andune.minecraft.hsp.entity.HomeInvite hi = storage.getHomeInviteDAO().findHomeInviteById(id); // make sure we found an object and that the home is owned by the player if (hi != null && p.getName().equals(hi.getHome().getPlayerName())) { try { Home h = hi.getHome(); String invitee = hi.getInvitedPlayer(); storage.getHomeInviteDAO().deleteHomeInvite(hi); server.sendLocalizedMessage( p, HSPMessages.HOMEINVITE_DELETED, "id", id, "home", h.getName(), "invitee", invitee); } catch (StorageException e) { server.sendLocalizedMessage(p, HSPMessages.GENERIC_ERROR); log.warn("Caught exception in /" + getCommandName(), e); } } else { server.sendLocalizedMessage(p, HSPMessages.HOMEINVITE_ID_NOT_FOUND, "id", args[0]); } return true; }
@Override public Set<HomeInvite> findInvitesByHome(Home home) { String q = "find homeInvite where home = :home"; Query<HomeInvite> query = ebean.createQuery(HomeInvite.class, q); query.setParameter("home", home.getId()); return query.findSet(); }
@Override public HomeInvite findInviteByHomeAndInvitee(Home home, String invitee) { String q; if (configCore.useEbeanSearchLower()) q = "find homeInvite where home = :home and lower(invitedPlayer) = lower(:invitee)"; else q = "find homeInvite where home = :home and invitedPlayer = :invitee"; Query<HomeInvite> query = ebean.createQuery(HomeInvite.class, q); query.setParameter("home", home.getId()); query.setParameter("invitee", invitee); return query.findUnique(); }
@Override public StrategyResult evaluate(StrategyContext context) { Home home = null; // take the name from the argument, if given String name = context.getArg(); // otherwise use the name given at instantiation if (name == null) name = homeName; log.debug("HomeNamedHome: name={}", name); if (name != null) { home = homeDAO.findHomeByNameAndPlayer(name, context.getPlayer().getName()); log.debug( "HomeNamedHome: home pre-modes={}, current modes={}", home, context.getCurrentModes()); if (context.isModeEnabled(StrategyMode.MODE_HOME_DEFAULT_ONLY) && !home.isDefaultHome()) home = null; if (context.isModeEnabled(StrategyMode.MODE_HOME_BED_ONLY) && !home.isBedHome()) home = null; if (context.isModeEnabled(StrategyMode.MODE_HOME_NO_BED) && home.isBedHome()) home = null; if (context.isModeEnabled(StrategyMode.MODE_HOME_REQUIRES_BED) && !isBedNearby(home)) { logVerbose( "Home ", home, " skipped because MODE_HOME_REQUIRES_BED is true and no bed is nearby the home location"); home = null; } } else log.warn( "Strategy " + getStrategyConfigName() + " was not given a homeName argument, nothing to do"); return new StrategyResultImpl(home); }