2015-01-09 22:36:12 +01:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
|
|
|
import com.massivecraft.factions.Rel;
|
2017-04-06 22:32:52 +02:00
|
|
|
import com.massivecraft.factions.Selector;
|
|
|
|
import com.massivecraft.factions.cmd.req.RequirementHasMPerm;
|
2015-10-21 19:35:41 +02:00
|
|
|
import com.massivecraft.factions.cmd.type.TypeMPerm;
|
2017-04-06 22:32:52 +02:00
|
|
|
import com.massivecraft.factions.cmd.type.TypeSelector;
|
2015-01-09 22:36:12 +01:00
|
|
|
import com.massivecraft.factions.entity.Faction;
|
|
|
|
import com.massivecraft.factions.entity.MPerm;
|
2015-11-23 03:12:13 +01:00
|
|
|
import com.massivecraft.factions.event.EventFactionsPermChange;
|
2017-04-06 22:32:52 +02:00
|
|
|
import com.massivecraft.massivecore.Button;
|
2015-02-12 12:00:55 +01:00
|
|
|
import com.massivecraft.massivecore.MassiveException;
|
2017-04-06 22:32:52 +02:00
|
|
|
import com.massivecraft.massivecore.mson.Mson;
|
|
|
|
import org.bukkit.ChatColor;
|
2015-01-09 22:36:12 +01:00
|
|
|
|
2017-04-06 22:32:52 +02:00
|
|
|
public abstract class CmdFactionsPermSet extends FactionsCommand
|
2015-01-09 22:36:12 +01:00
|
|
|
{
|
2017-04-06 22:32:52 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// FIELDS
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
|
|
|
private boolean add;
|
|
|
|
public boolean isAdd() { return this.add; }
|
|
|
|
|
2015-01-09 22:36:12 +01:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// CONSTRUCT
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2017-04-06 22:32:52 +02:00
|
|
|
public CmdFactionsPermSet(boolean add)
|
2015-01-09 22:36:12 +01:00
|
|
|
{
|
2017-04-06 22:32:52 +02:00
|
|
|
// Add/Remove
|
|
|
|
this.add = add;
|
|
|
|
|
2015-10-21 19:35:41 +02:00
|
|
|
// Parameters
|
2017-04-06 22:32:52 +02:00
|
|
|
this.addParameter(TypeMPerm.get(), "permission");
|
|
|
|
this.addParameter(TypeSelector.get(), "selector");
|
|
|
|
|
|
|
|
// Requirements
|
|
|
|
this.addRequirements(RequirementHasMPerm.get(MPerm.getPermPerms()));
|
2015-01-09 22:36:12 +01:00
|
|
|
}
|
2017-04-06 22:32:52 +02:00
|
|
|
|
2015-01-09 22:36:12 +01:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// OVERRIDE
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
|
|
|
@Override
|
2015-02-12 12:00:55 +01:00
|
|
|
public void perform() throws MassiveException
|
2015-01-09 22:36:12 +01:00
|
|
|
{
|
2017-04-06 22:32:52 +02:00
|
|
|
// Parameter
|
2015-05-06 17:04:35 +02:00
|
|
|
MPerm perm = this.readArg();
|
2017-04-06 22:32:52 +02:00
|
|
|
Selector selector = this.readArg();
|
|
|
|
Faction faction = msender.getUsedFaction();
|
|
|
|
boolean adding = this.isAdd();
|
2015-01-09 22:36:12 +01:00
|
|
|
|
|
|
|
// Is this perm editable?
|
2017-04-06 22:32:52 +02:00
|
|
|
if (!msender.isOverriding() && !perm.isEditable())
|
2015-01-09 22:36:12 +01:00
|
|
|
{
|
|
|
|
msg("<b>The perm <h>%s <b>is not editable.", perm.getName());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-06 22:32:52 +02:00
|
|
|
// Visuals
|
|
|
|
String visualSelector = TypeSelector.get().getVisual(selector);
|
|
|
|
String visualFaction = faction.describeTo(msender);
|
|
|
|
String visualPerm = perm.getDesc(true, false);
|
2015-11-23 03:12:13 +01:00
|
|
|
|
2015-01-09 22:36:12 +01:00
|
|
|
// No change
|
2017-04-06 22:32:52 +02:00
|
|
|
if (faction.isPermitted(perm, selector) == adding)
|
2015-01-09 22:36:12 +01:00
|
|
|
{
|
2017-04-06 22:32:52 +02:00
|
|
|
String already = "already";
|
|
|
|
if (!adding) already += " not";
|
|
|
|
msg("%s <i>is %s permitted for faction %s<i> and perm %s<i>.", visualSelector, already, visualFaction, visualPerm);
|
2015-01-09 22:36:12 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-06 22:32:52 +02:00
|
|
|
// Event
|
|
|
|
EventFactionsPermChange event = new EventFactionsPermChange(sender, faction, perm, selector, adding);
|
|
|
|
event.run();
|
|
|
|
if (event.isCancelled()) return;
|
|
|
|
adding = event.getNewValue();
|
2015-01-09 22:36:12 +01:00
|
|
|
|
|
|
|
// The following is to make sure the leader always has the right to change perms if that is our goal.
|
2017-04-06 22:32:52 +02:00
|
|
|
if (perm == MPerm.getPermPerms() && MPerm.getPermPerms().getStandard().contains(Rel.LEADER) && !adding)
|
2015-01-09 22:36:12 +01:00
|
|
|
{
|
2017-04-06 22:32:52 +02:00
|
|
|
throw new MassiveException().setMsg("<b>You are not allowed to remove the leader from the perm <h>perms<b>.");
|
2015-01-09 22:36:12 +01:00
|
|
|
}
|
|
|
|
|
2017-04-06 22:32:52 +02:00
|
|
|
// Apply
|
|
|
|
faction.setPermitted(perm, selector, adding);
|
2015-01-09 22:36:12 +01:00
|
|
|
|
2017-04-06 22:32:52 +02:00
|
|
|
// Inform
|
|
|
|
String addRemove = adding ? "added" : "removed";
|
|
|
|
Mson button = new Button()
|
|
|
|
.setName("Show")
|
|
|
|
.setCommand(CmdFactions.get().cmdFactionsPerm.cmdFactionsPermShow)
|
|
|
|
.setArgs(perm.getId())
|
|
|
|
.render();
|
|
|
|
faction.sendMessage(mson(visualSelector, " was ", addRemove, " to the perm ", visualPerm, ". ", button).color(ChatColor.YELLOW));
|
2015-01-09 22:36:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|