2011-04-08 15:51:07 +02:00
package org.mcteam.factions.commands ;
2011-03-22 15:45:41 +01:00
import java.util.ArrayList ;
2011-04-08 15:51:07 +02:00
import org.mcteam.factions.Conf ;
import org.mcteam.factions.Faction ;
import org.mcteam.factions.struct.Role ;
import org.mcteam.factions.util.TextUtil ;
2011-03-22 15:45:41 +01:00
public class FCommandTag extends FBaseCommand {
public FCommandTag ( ) {
2011-03-22 18:48:09 +01:00
aliases . add ( " tag " ) ;
2011-03-22 15:45:41 +01:00
requiredParameters . add ( " faction tag " ) ;
helpDescription = " Change the faction tag " ;
}
public void perform ( ) {
if ( ! assertHasFaction ( ) ) {
return ;
}
2011-05-08 17:16:43 +02:00
if ( isLocked ( ) ) {
sendLockMessage ( ) ;
return ;
}
2011-03-22 15:45:41 +01:00
if ( ! assertMinRole ( Role . MODERATOR ) ) {
return ;
}
String tag = parameters . get ( 0 ) ;
// TODO does not first test cover selfcase?
if ( Faction . isTagTaken ( tag ) & & ! TextUtil . getComparisonString ( tag ) . equals ( me . getFaction ( ) . getComparisonTag ( ) ) ) {
sendMessage ( " That tag is already taken " ) ;
return ;
}
ArrayList < String > errors = new ArrayList < String > ( ) ;
errors . addAll ( Faction . validateTag ( tag ) ) ;
if ( errors . size ( ) > 0 ) {
sendMessage ( errors ) ;
return ;
}
Faction myFaction = me . getFaction ( ) ;
String oldtag = myFaction . getTag ( ) ;
myFaction . setTag ( tag ) ;
// Inform
myFaction . sendMessage ( me . getNameAndRelevant ( myFaction ) + Conf . colorSystem + " changed your faction tag to " + Conf . colorMember + myFaction . getTag ( ) ) ;
for ( Faction faction : Faction . getAll ( ) ) {
2011-03-22 17:20:21 +01:00
if ( faction = = me . getFaction ( ) ) {
2011-03-22 15:45:41 +01:00
continue ;
}
2011-05-30 00:19:46 +02:00
faction . sendMessage ( Conf . colorSystem + " The faction " + me . getRelationColor ( faction ) + oldtag + Conf . colorSystem + " changed their name to " + myFaction . getTag ( faction ) ) ;
2011-03-22 15:45:41 +01:00
}
}
}