Factions/src/com/massivecraft/factions/cmd/CmdFactionsTitle.java

70 lines
2.0 KiB
Java
Raw Normal View History

2011-10-09 21:57:43 +02:00
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.type.TypeMPlayer;
import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.entity.MPlayer;
2014-06-04 16:47:01 +02:00
import com.massivecraft.factions.event.EventFactionsTitleChange;
2015-02-12 12:00:55 +01:00
import com.massivecraft.massivecore.MassiveException;
2015-11-06 02:10:29 +01:00
import com.massivecraft.massivecore.command.type.primitive.TypeString;
2014-06-04 14:02:23 +02:00
import com.massivecraft.massivecore.util.Txt;
2017-03-24 13:05:58 +01:00
import org.bukkit.ChatColor;
2014-09-18 13:41:20 +02:00
public class CmdFactionsTitle extends FactionsCommand
2011-10-09 18:35:39 +02:00
{
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
2013-04-10 13:12:22 +02:00
public CmdFactionsTitle()
2011-10-09 18:35:39 +02:00
{
// Parameters
this.addParameter(TypeMPlayer.get(), "player");
2019-01-02 00:43:39 +01:00
this.addParameter(TypeString.get(), "title", "none", true);
}
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
2015-02-12 12:00:55 +01:00
public void perform() throws MassiveException
2011-10-09 18:35:39 +02:00
{
// Args
2015-05-06 17:04:35 +02:00
MPlayer you = this.readArg();
String newTitle = this.readArg("");
2013-04-25 16:54:55 +02:00
newTitle = Txt.parse(newTitle);
if (!Perm.TITLE_COLOR.has(sender, false))
{
newTitle = ChatColor.stripColor(newTitle);
}
// MPerm
if ( ! MPerm.getPermTitle().has(msender, you.getFaction(), true)) return;
2015-08-26 08:23:08 +02:00
// Rank Check
if (!msender.isOverriding() && you.getRank().isMoreThan(msender.getRank()))
2015-08-26 08:23:08 +02:00
{
2019-01-02 00:43:39 +01:00
throw new MassiveException().addMsg("<b>You can not edit titles for higher ranks.");
}
if (!msender.isOverriding() && you.getRank() == msender.getRank())
{
throw new MassiveException().addMsg("<b>You can't edit titles of people with the same rank as yourself.");
2015-08-26 08:23:08 +02:00
}
// Event
2014-06-04 16:47:01 +02:00
EventFactionsTitleChange event = new EventFactionsTitleChange(sender, you, newTitle);
event.run();
if (event.isCancelled()) return;
newTitle = event.getNewTitle();
// Apply
you.setTitle(newTitle);
// Inform
2014-09-18 13:41:20 +02:00
msenderFaction.msg("%s<i> changed a title: %s", msender.describeTo(msenderFaction, true), you.describeTo(msenderFaction, true));
}
}