2011-10-09 21:57:43 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2011-07-18 22:06:02 +02:00
|
|
|
import com.massivecraft.factions.Conf;
|
|
|
|
import com.massivecraft.factions.Faction;
|
2012-03-13 13:58:51 +01:00
|
|
|
import com.massivecraft.factions.event.FactionRelationEvent;
|
2014-10-22 18:54:00 +02:00
|
|
|
import com.massivecraft.factions.scoreboards.FTeamWrapper;
|
2011-10-09 18:35:39 +02:00
|
|
|
import com.massivecraft.factions.struct.Permission;
|
2011-07-18 22:06:02 +02:00
|
|
|
import com.massivecraft.factions.struct.Relation;
|
2014-12-08 00:12:52 +01:00
|
|
|
import com.massivecraft.factions.zcore.util.TL;
|
2014-04-04 20:55:21 +02:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
|
|
|
|
public abstract class FRelationCommand extends FCommand {
|
2014-08-05 17:17:27 +02:00
|
|
|
|
2014-04-04 20:55:21 +02:00
|
|
|
public Relation targetRelation;
|
|
|
|
|
|
|
|
public FRelationCommand() {
|
2014-07-01 22:10:18 +02:00
|
|
|
super();
|
|
|
|
this.requiredArgs.add("faction tag");
|
2014-04-04 20:55:21 +02:00
|
|
|
//this.optionalArgs.put("player name", "you");
|
|
|
|
|
2014-07-01 22:10:18 +02:00
|
|
|
this.permission = Permission.RELATION.node;
|
|
|
|
this.disableOnLock = true;
|
2014-04-04 20:55:21 +02:00
|
|
|
|
2014-07-01 22:10:18 +02:00
|
|
|
senderMustBePlayer = true;
|
|
|
|
senderMustBeMember = false;
|
|
|
|
senderMustBeModerator = true;
|
|
|
|
senderMustBeAdmin = false;
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void perform() {
|
2014-07-01 22:10:18 +02:00
|
|
|
Faction them = this.argAsFaction(0);
|
|
|
|
if (them == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-04-04 20:55:21 +02:00
|
|
|
|
|
|
|
if (!them.isNormal()) {
|
2014-12-08 00:12:52 +01:00
|
|
|
msg(TL.COMMAND_RELATIONS_ALLTHENOPE);
|
2014-07-01 22:10:18 +02:00
|
|
|
return;
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (them == myFaction) {
|
2014-12-08 00:12:52 +01:00
|
|
|
msg(TL.COMMAND_RELATIONS_MORENOPE);
|
2014-07-01 22:10:18 +02:00
|
|
|
return;
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (myFaction.getRelationWish(them) == targetRelation) {
|
2014-12-08 00:12:52 +01:00
|
|
|
msg(TL.COMMAND_RELATIONS_ALREADYINRELATIONSHIP, them.getTag());
|
2014-07-01 22:10:18 +02:00
|
|
|
return;
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
|
2014-12-11 17:05:04 +01:00
|
|
|
if (!payForCommand(targetRelation.getRelationCost(), TL.COMMAND_RELATIONS_TOMARRY, TL.COMMAND_RELATIONS_FORMARRY)) {
|
2014-04-04 20:55:21 +02:00
|
|
|
return;
|
2014-07-01 21:49:42 +02:00
|
|
|
}
|
2014-04-04 20:55:21 +02:00
|
|
|
|
|
|
|
// try to set the new relation
|
2014-07-01 22:10:18 +02:00
|
|
|
Relation oldRelation = myFaction.getRelationTo(them, true);
|
|
|
|
myFaction.setRelationWish(them, targetRelation);
|
2014-04-04 20:55:21 +02:00
|
|
|
Relation currentRelation = myFaction.getRelationTo(them, true);
|
|
|
|
ChatColor currentRelationColor = currentRelation.getColor();
|
|
|
|
|
|
|
|
// if the relation change was successful
|
|
|
|
if (targetRelation.value == currentRelation.value) {
|
|
|
|
// trigger the faction relation event
|
|
|
|
FactionRelationEvent relationEvent = new FactionRelationEvent(myFaction, them, oldRelation, currentRelation);
|
|
|
|
Bukkit.getServer().getPluginManager().callEvent(relationEvent);
|
|
|
|
|
2014-12-11 17:05:04 +01:00
|
|
|
them.msg(TL.COMMAND_RELATIONS_MUTUAL, currentRelationColor + targetRelation.getTranslation(), currentRelationColor + myFaction.getTag());
|
|
|
|
myFaction.msg(TL.COMMAND_RELATIONS_MUTUAL, currentRelationColor + targetRelation.getTranslation(), currentRelationColor + myFaction.getTag());
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
|
|
|
// inform the other faction of your request
|
|
|
|
else {
|
2014-12-11 17:05:04 +01:00
|
|
|
|
|
|
|
them.msg(TL.COMMAND_RELATIONS_PROPOSAL_1, currentRelationColor + myFaction.getTag(), targetRelation.getColor() + targetRelation.getTranslation());
|
|
|
|
them.msg(TL.COMMAND_RELATIONS_PROPOSAL_2, Conf.baseCommandAliases.get(0), targetRelation, myFaction.getTag());
|
|
|
|
myFaction.msg(TL.COMMAND_RELATIONS_PROPOSAL_SENT, currentRelationColor + them.getTag(), "" + targetRelation.getColor() + targetRelation);
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!targetRelation.isNeutral() && them.isPeaceful()) {
|
2014-12-08 00:12:52 +01:00
|
|
|
them.msg(TL.COMMAND_RELATIONS_PEACEFUL);
|
|
|
|
myFaction.msg(TL.COMMAND_RELATIONS_PEACEFULOTHER);
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!targetRelation.isNeutral() && myFaction.isPeaceful()) {
|
2014-12-08 00:12:52 +01:00
|
|
|
them.msg(TL.COMMAND_RELATIONS_PEACEFULOTHER);
|
|
|
|
myFaction.msg(TL.COMMAND_RELATIONS_PEACEFUL);
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2014-10-22 18:54:00 +02:00
|
|
|
FTeamWrapper.updatePrefixes(myFaction);
|
|
|
|
FTeamWrapper.updatePrefixes(them);
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
2011-03-22 15:45:41 +01:00
|
|
|
}
|