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

128 lines
4.6 KiB
Java
Raw Normal View History

2011-10-09 21:57:43 +02:00
package com.massivecraft.factions.cmd;
2015-09-08 19:18:45 +02:00
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.req.ReqHasFaction;
import com.massivecraft.factions.cmd.type.TypeFaction;
2013-04-22 09:37:53 +02:00
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MFlag;
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;
2015-11-06 02:10:29 +01:00
import com.massivecraft.massivecore.command.MassiveCommand;
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
2015-09-08 19:18:45 +02:00
import com.massivecraft.massivecore.mson.Mson;
import com.massivecraft.massivecore.util.Txt;
2014-09-18 13:41:20 +02:00
public abstract class CmdFactionsRelationAbstract extends FactionsCommand
2011-10-09 18:35:39 +02:00
{
public Rel targetRelation;
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
2013-04-10 13:12:22 +02:00
public CmdFactionsRelationAbstract()
2011-10-09 18:35:39 +02:00
{
2013-11-11 09:31:04 +01:00
// Aliases
this.addParameter(TypeFaction.get(), "faction");
2013-11-11 09:31:04 +01:00
// Requirements
2015-11-06 02:10:29 +01:00
this.addRequirements(RequirementHasPerm.get(Perm.RELATION.node));
this.addRequirements(ReqHasFaction.get());
}
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
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
{
// Args
2015-05-06 17:04:35 +02:00
Faction otherFaction = this.readArg();
Rel newRelation = targetRelation;
/*if ( ! them.isNormal())
2011-10-09 18:35:39 +02:00
{
2011-10-10 13:40:24 +02:00
msg("<b>Nope! You can't.");
return;
}*/
// MPerm
if ( ! MPerm.getPermRel().has(msender, msenderFaction, true)) return;
// Verify
2014-09-18 13:41:20 +02:00
if (otherFaction == msenderFaction)
2011-10-09 18:35:39 +02:00
{
2011-10-10 13:40:24 +02:00
msg("<b>Nope! You can't declare a relation to yourself :)");
return;
}
2014-09-18 13:41:20 +02:00
if (msenderFaction.getRelationWish(otherFaction) == newRelation)
{
msg("<b>You already have that relation wish set with %s.", otherFaction.getName());
return;
}
// Event
2014-09-18 13:41:20 +02:00
EventFactionsRelationChange event = new EventFactionsRelationChange(sender, msenderFaction, otherFaction, newRelation);
event.run();
if (event.isCancelled()) return;
newRelation = event.getNewRelation();
// try to set the new relation
2014-09-18 13:41:20 +02:00
msenderFaction.setRelationWish(otherFaction, newRelation);
Rel currentRelation = msenderFaction.getRelationTo(otherFaction, true);
// if the relation change was successful
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());
}
// inform the other faction of your request
2011-10-09 18:35:39 +02:00
else
{
2015-09-08 19:18:45 +02:00
MassiveCommand relationshipCommand = null;
if (newRelation.equals(Rel.NEUTRAL)) relationshipCommand = Factions.get().getOuterCmdFactions().cmdFactionsRelationNeutral;
else if (newRelation.equals(Rel.TRUCE)) relationshipCommand = Factions.get().getOuterCmdFactions().cmdFactionsRelationTruce;
else if (newRelation.equals(Rel.ALLY)) relationshipCommand = Factions.get().getOuterCmdFactions().cmdFactionsRelationAlly;
else if (newRelation.equals(Rel.ENEMY)) relationshipCommand = Factions.get().getOuterCmdFactions().cmdFactionsRelationEnemy;
String command = relationshipCommand.getCommandLine(msenderFaction.getName());
String tooltip = Txt.parse("<g>Click to <c>%s<i>.", command);
// Mson creation
Mson factionsRelationshipChange = mson(
Mson.parse("%s<i> wishes to be %s. ", msenderFaction.describeTo(otherFaction, true), newRelation.getColor()+newRelation.getDescFactionOne()),
mson(tooltip).tooltipParse(tooltip).command(command)
);
otherFaction.sendMessage(factionsRelationshipChange);
2014-09-18 13:41:20 +02:00
msenderFaction.msg("%s<i> were informed that you wish to be %s<i>.", otherFaction.describeTo(msenderFaction, true), newRelation.getColor()+newRelation.getDescFactionOne());
New "peaceful" status for factions which can only be set by server admins/moderators. Members of peaceful factions cannot deal or receive PvP damage (unless in a war zone which has friendly fire enabled), cannot claim land from another faction and likewise can't have their land claimed, and cannot be considered as ally or enemy of any other faction. Faction admins and moderators of peaceful factions can enable/disable all explosions inside their faction's territory at will. The main purpose of this is to provide a way for more peaceful players who don't want to take part in faction wars (or just want to take a break from them) to still have fun on the server. It is also meant to allow groups of players to make protected buildings, monuments, grand constructions, and so forth without having to worry about another faction destroying them. New conf.json settings: "peacefulTerritoryDisablePVP" (default true) prevents PvP damage for anyone inside a peaceful faction's territory "peacefulTerritoryDisableMonsters" (default false) provides protection against monsters spawning or attacking inside a peaceful faction's territory "peacefulMembersDisablePowerLoss" (default true) which keeps members of peaceful factions from suffering power loss when they die. New commands: /f peaceful [faction tag] - toggle the indicated faction's "peaceful" status /f noboom - enable/disable explosions inside your faction's territory; only available to faction admin and faction moderators for peaceful factions New permission nodes: factions.setPeaceful - ability to use the /f peaceful command (admins) factions.peacefulExplosionToggle - ability to use /f noboom (everyone)
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!!
// * this might have to be bumped up to make that happen, & allow ALLY,NEUTRAL only
if ( newRelation != Rel.TRUCE && otherFaction.getFlag(MFlag.getFlagPeaceful()))
2011-10-09 18:35: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
}
if ( newRelation != Rel.TRUCE && msenderFaction.getFlag(MFlag.getFlagPeaceful()))
2011-10-09 18:35: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.");
New "peaceful" status for factions which can only be set by server admins/moderators. Members of peaceful factions cannot deal or receive PvP damage (unless in a war zone which has friendly fire enabled), cannot claim land from another faction and likewise can't have their land claimed, and cannot be considered as ally or enemy of any other faction. Faction admins and moderators of peaceful factions can enable/disable all explosions inside their faction's territory at will. The main purpose of this is to provide a way for more peaceful players who don't want to take part in faction wars (or just want to take a break from them) to still have fun on the server. It is also meant to allow groups of players to make protected buildings, monuments, grand constructions, and so forth without having to worry about another faction destroying them. New conf.json settings: "peacefulTerritoryDisablePVP" (default true) prevents PvP damage for anyone inside a peaceful faction's territory "peacefulTerritoryDisableMonsters" (default false) provides protection against monsters spawning or attacking inside a peaceful faction's territory "peacefulMembersDisablePowerLoss" (default true) which keeps members of peaceful factions from suffering power loss when they die. New commands: /f peaceful [faction tag] - toggle the indicated faction's "peaceful" status /f noboom - enable/disable explosions inside your faction's territory; only available to faction admin and faction moderators for peaceful factions New permission nodes: factions.setPeaceful - ability to use the /f peaceful command (admins) factions.peacefulExplosionToggle - ability to use /f noboom (everyone)
2011-08-05 10:50:47 +02:00
}
2015-11-08 17:59:32 +01:00
// Mark as changed
msenderFaction.changed();
}
2013-11-11 09:31:04 +01:00
}