2011-10-09 21:57:43 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2013-04-09 13:24:55 +02:00
|
|
|
import com.massivecraft.factions.Rel;
|
2015-10-21 19:35:41 +02:00
|
|
|
import com.massivecraft.factions.cmd.type.TypeFaction;
|
2016-02-25 09:48:02 +01:00
|
|
|
import com.massivecraft.factions.cmd.type.TypeRelation;
|
2013-04-22 09:37:53 +02:00
|
|
|
import com.massivecraft.factions.entity.Faction;
|
2014-10-02 11:45:06 +02:00
|
|
|
import com.massivecraft.factions.entity.MFlag;
|
2014-10-03 09:01:36 +02:00
|
|
|
import com.massivecraft.factions.entity.MPerm;
|
2014-06-04 16:47:01 +02:00
|
|
|
import com.massivecraft.factions.event.EventFactionsRelationChange;
|
2015-02-12 12:00:55 +01:00
|
|
|
import com.massivecraft.massivecore.MassiveException;
|
2016-02-26 15:37:41 +01:00
|
|
|
import com.massivecraft.massivecore.command.MassiveCommand;
|
2015-09-08 19:18:45 +02:00
|
|
|
import com.massivecraft.massivecore.mson.Mson;
|
2017-03-24 13:05:58 +01:00
|
|
|
import org.bukkit.ChatColor;
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2016-02-25 09:48:02 +01:00
|
|
|
public class CmdFactionsRelationSet extends FactionsCommand
|
2011-10-09 18:35:39 +02:00
|
|
|
{
|
2013-11-11 09:31:04 +01:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// CONSTRUCT
|
|
|
|
// -------------------------------------------- //
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2016-02-25 09:48:02 +01:00
|
|
|
public CmdFactionsRelationSet()
|
2011-10-09 18:35:39 +02:00
|
|
|
{
|
2016-02-25 09:48:02 +01:00
|
|
|
// Parameter
|
2015-10-21 19:35:41 +02:00
|
|
|
this.addParameter(TypeFaction.get(), "faction");
|
2016-02-25 09:48:02 +01:00
|
|
|
this.addParameter(TypeRelation.get(), "relation");
|
2011-03-22 15:45:41 +01:00
|
|
|
}
|
2013-11-11 09:31:04 +01:00
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// OVERRIDE
|
|
|
|
// -------------------------------------------- //
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2011-10-09 18:35:39 +02:00
|
|
|
@Override
|
2015-02-12 12:00:55 +01:00
|
|
|
public void perform() throws MassiveException
|
2011-10-09 18:35:39 +02:00
|
|
|
{
|
2013-04-19 12:27:39 +02:00
|
|
|
// Args
|
2015-05-06 17:04:35 +02:00
|
|
|
Faction otherFaction = this.readArg();
|
2016-02-25 09:48:02 +01:00
|
|
|
Rel newRelation = this.readArg();
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2014-10-03 09:01:36 +02:00
|
|
|
// MPerm
|
|
|
|
if ( ! MPerm.getPermRel().has(msender, msenderFaction, true)) return;
|
|
|
|
|
2013-04-19 12:27:39 +02:00
|
|
|
// Verify
|
2014-09-18 13:41:20 +02:00
|
|
|
if (otherFaction == msenderFaction)
|
2011-10-09 18:35:39 +02:00
|
|
|
{
|
2016-02-25 09:48:02 +01:00
|
|
|
throw new MassiveException().setMsg("<b>Nope! You can't declare a relation to yourself :)");
|
2011-03-22 15:45:41 +01:00
|
|
|
}
|
2014-09-18 13:41:20 +02:00
|
|
|
if (msenderFaction.getRelationWish(otherFaction) == newRelation)
|
2012-04-06 20:27:23 +02:00
|
|
|
{
|
2016-02-25 09:48:02 +01:00
|
|
|
throw new MassiveException().setMsg("<b>You already have that relation wish set with %s.", otherFaction.getName());
|
2012-04-06 20:27:23 +02:00
|
|
|
}
|
2013-04-19 12:27:39 +02:00
|
|
|
|
|
|
|
// Event
|
2014-09-18 13:41:20 +02:00
|
|
|
EventFactionsRelationChange event = new EventFactionsRelationChange(sender, msenderFaction, otherFaction, newRelation);
|
2013-04-19 12:27:39 +02:00
|
|
|
event.run();
|
|
|
|
if (event.isCancelled()) return;
|
|
|
|
newRelation = event.getNewRelation();
|
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
|
|
|
|
2012-03-09 23:09:33 +01:00
|
|
|
// try to set the new relation
|
2014-09-18 13:41:20 +02:00
|
|
|
msenderFaction.setRelationWish(otherFaction, newRelation);
|
|
|
|
Rel currentRelation = msenderFaction.getRelationTo(otherFaction, true);
|
2012-03-09 23:09:33 +01:00
|
|
|
|
|
|
|
// if the relation change was successful
|
2013-04-19 12:27:39 +02:00
|
|
|
if (newRelation == currentRelation)
|
2011-10-09 18:35:39 +02:00
|
|
|
{
|
2014-09-18 13:41:20 +02:00
|
|
|
otherFaction.msg("%s<i> is now %s.", msenderFaction.describeTo(otherFaction, true), newRelation.getDescFactionOne());
|
|
|
|
msenderFaction.msg("%s<i> is now %s.", otherFaction.describeTo(msenderFaction, true), newRelation.getDescFactionOne());
|
2011-03-22 15:45:41 +01:00
|
|
|
}
|
2012-03-09 23:09:33 +01:00
|
|
|
// inform the other faction of your request
|
2011-10-09 18:35:39 +02:00
|
|
|
else
|
|
|
|
{
|
2016-02-25 09:48:02 +01:00
|
|
|
MassiveCommand command = CmdFactions.get().cmdFactionsRelation.cmdFactionsRelationSet;
|
|
|
|
String colorOne = newRelation.getColor() + newRelation.getDescFactionOne();
|
|
|
|
|
2015-09-08 19:18:45 +02:00
|
|
|
// Mson creation
|
|
|
|
Mson factionsRelationshipChange = mson(
|
2016-02-25 09:48:02 +01:00
|
|
|
Mson.parse("%s<i> wishes to be %s.", msenderFaction.describeTo(otherFaction, true), colorOne),
|
|
|
|
Mson.SPACE,
|
|
|
|
mson("[Accept]").color(ChatColor.AQUA).command(command, msenderFaction.getName(), newRelation.name())
|
2015-09-08 19:18:45 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
otherFaction.sendMessage(factionsRelationshipChange);
|
2016-02-25 09:48:02 +01:00
|
|
|
msenderFaction.msg("%s<i> were informed that you wish to be %s<i>.", otherFaction.describeTo(msenderFaction, true), colorOne);
|
2011-08-05 10:50:47 +02:00
|
|
|
}
|
2011-10-09 18:35:39 +02:00
|
|
|
|
2011-10-24 11:07:06 +02:00
|
|
|
// TODO: The ally case should work!!
|
2012-03-09 23:09:33 +01:00
|
|
|
// * this might have to be bumped up to make that happen, & allow ALLY,NEUTRAL only
|
2016-02-25 09:48:02 +01:00
|
|
|
if (newRelation != Rel.TRUCE && otherFaction.getFlag(MFlag.getFlagPeaceful()))
|
2011-10-09 18:35:39 +02:00
|
|
|
{
|
2013-04-19 12:27:39 +02:00
|
|
|
otherFaction.msg("<i>This will have no effect while your faction is peaceful.");
|
2014-09-18 13:41:20 +02:00
|
|
|
msenderFaction.msg("<i>This will have no effect while their faction is peaceful.");
|
2011-10-09 18:35:39 +02:00
|
|
|
}
|
|
|
|
|
2016-02-25 09:48:02 +01:00
|
|
|
if (newRelation != Rel.TRUCE && msenderFaction.getFlag(MFlag.getFlagPeaceful()))
|
2011-10-09 18:35:39 +02:00
|
|
|
{
|
2013-04-19 12:27:39 +02:00
|
|
|
otherFaction.msg("<i>This will have no effect while their faction is peaceful.");
|
2014-09-18 13:41:20 +02:00
|
|
|
msenderFaction.msg("<i>This will have no effect while your faction is peaceful.");
|
2011-08-05 10:50:47 +02:00
|
|
|
}
|
2015-11-08 17:59:32 +01:00
|
|
|
|
|
|
|
// Mark as changed
|
|
|
|
msenderFaction.changed();
|
2011-03-22 15:45:41 +01:00
|
|
|
}
|
2013-11-11 09:31:04 +01:00
|
|
|
|
2011-03-22 15:45:41 +01:00
|
|
|
}
|