package com.massivecraft.factions.cmd; import com.massivecraft.factions.cmd.type.TypeFaction; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.entity.Warp; import com.massivecraft.factions.event.EventFactionsWarpAdd; import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; import com.massivecraft.massivecore.command.type.primitive.TypeString; import com.massivecraft.massivecore.ps.PS; public class CmdFactionsWarpAdd extends FactionsCommandWarp { // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // public CmdFactionsWarpAdd() { // Parameters this.addParameter(TypeString.get(), "name"); this.addParameter(TypeFaction.get(), "faction", "you"); // Aliases this.addAliases("create"); // Requirements this.addRequirements(RequirementIsPlayer.get()); } // -------------------------------------------- // // OVERRIDE // -------------------------------------------- // @Override public void perform() throws MassiveException { // Args String name = this.readArg(); Faction faction = this.readArg(msenderFaction); PS ps = PS.valueOf(me.getLocation()); Warp warp = new Warp(name, ps); // MPerm if ( ! MPerm.getPermSethome().has(msender, faction, true)) return; if (faction.getWarps().getAll().stream().map(Warp::getName).anyMatch(s -> s.equalsIgnoreCase(name))) { throw new MassiveException().addMsg("There is already a warp called %s.", name); } // Verify if (!msender.isOverriding() && !warp.isValidFor(faction)) { throw new MassiveException().addMsg("Sorry, your faction warps can only be set inside your own claimed territory."); } if (!msender.isOverriding() && faction.getWarps().size() >= MConf.get().warpsMax && MConf.get().warpsMax >= 0) { throw new MassiveException().addMsg("You can at most have %d warps at a time.", MConf.get().warpsMax); } // Event EventFactionsWarpAdd event = new EventFactionsWarpAdd(sender, faction, warp); event.run(); if (event.isCancelled()) return; warp = event.getNewWarp(); // Apply faction.getWarps().attach(warp); // Inform faction.msg("%s added the warp %s to your faction. You can now use:", msender.describeTo(msenderFaction, true), warp.getName()); faction.sendMessage(CmdFactions.get().cmdFactionsWarp.cmdFactionsWarpGo.getTemplateWithArgs(null, warp.getName())); if (faction != msenderFaction) { msender.msg("You added the warp %s to %s.", warp.getName(), faction.describeTo(msender)); } } }