Implement interface Powerboosted.

This commit is contained in:
ulumulu1510 2017-03-15 18:22:17 +01:00
parent 91fc5a2404
commit 9a2066efcc
10 changed files with 160 additions and 82 deletions

View File

@ -59,7 +59,10 @@ permissions:
factions.perm.set: {description: set perms, default: false}
factions.perm.show: {description: show perms, default: false}
factions.player: {description: show player information}
factions.powerboost: {description: set powerboost, default: false}
factions.powerboost: {description: manage powerboost, default: false}
factions.powerboost.faction: {description: show faction powerboost, default: false}
factions.powerboost.player: {description: show player powerboost, default: false}
factions.powerboost.set: {description: set powerboost, default: false}
factions.rank: {description: manage/show ranks, default: false}
factions.rank.show: {description: show rank, default: false}
factions.rank.action: {description: change rank, default: false}
@ -147,6 +150,9 @@ permissions:
factions.perm.show: true
factions.player: true
factions.powerboost: true
factions.powerboost.faction: true
factions.powerboost.player: true
factions.powerboost.set: true
factions.promote: true
factions.relation: true
factions.relation.list: true
@ -188,7 +194,7 @@ permissions:
default: false
children:
factions.kit.rank1: true
factions.powerboost: true
factions.powerboost.set: true
factions.join.others: true
factions.leader.any: true
factions.officer.any: true
@ -253,6 +259,9 @@ permissions:
factions.perm.show: true
factions.player: true
factions.promote: true
factions.powerboost: true
factions.powerboost.faction: true
factions.powerboost.player: true
factions.rank: true
factions.rank.show: true
factions.rank.action: true

View File

@ -0,0 +1,7 @@
package com.massivecraft.factions;
import com.massivecraft.massivecore.Named;
public interface FactionsParticipator extends Named, EconomyParticipator, PowerBoosted
{
}

View File

@ -61,6 +61,9 @@ public enum Perm implements Identified
PERM_SHOW,
PLAYER,
POWERBOOST,
POWERBOOST_PLAYER,
POWERBOOST_FACTION,
POWERBOOST_SET,
RANK,
RANK_SHOW,
RANK_ACTION,

View File

@ -0,0 +1,7 @@
package com.massivecraft.factions;
public interface PowerBoosted
{
public double getPowerBoost();
public void setPowerBoost(Double powerBoost);
}

View File

@ -1,23 +1,13 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.cmd.type.TypeFaction;
import com.massivecraft.factions.cmd.type.TypeMPlayer;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.Parameter;
import com.massivecraft.massivecore.command.type.primitive.TypeDouble;
import com.massivecraft.massivecore.command.type.primitive.TypeString;
public class CmdFactionsPowerBoost extends FactionsCommand
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private Parameter<MPlayer> parameterMplayer = new Parameter<MPlayer>(TypeMPlayer.get(), "name");
private Parameter<Faction> parameterFaction = new Parameter<Faction>(TypeFaction.get(), "name");
public CmdFactionsPowerBoostPlayer cmdFactionsPowerBoostPlayer = new CmdFactionsPowerBoostPlayer();
public CmdFactionsPowerBoostFaction cmdFactionsPowerBoostFaction = new CmdFactionsPowerBoostFaction();
// -------------------------------------------- //
// CONSTRUCT
@ -25,55 +15,9 @@ public class CmdFactionsPowerBoost extends FactionsCommand
public CmdFactionsPowerBoost()
{
// Parameters
this.addParameter(TypeString.get(), "p|f|player|faction");
this.addParameter(parameterMplayer);
this.addParameter(TypeDouble.get(), "#");
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform() throws MassiveException
{
String type = this.<String>readArg().toLowerCase();
boolean doPlayer = true;
if (type.equals("f") || type.equals("faction"))
{
doPlayer = false;
}
else if (!type.equals("p") && !type.equals("player"))
{
msg("<b>You must specify \"p\" or \"player\" to target a player or \"f\" or \"faction\" to target a faction.");
msg("<b>ex. /f powerboost p SomePlayer 0.5 -or- /f powerboost f SomeFaction -5");
return;
}
double targetPower = this.readArgAt(2);
String target;
if (doPlayer)
{
this.getParameters().set(1, parameterMplayer);
MPlayer targetPlayer = this.readArgAt(1);
targetPlayer.setPowerBoost(targetPower);
target = "Player \""+targetPlayer.getName()+"\"";
}
else
{
this.getParameters().set(1, parameterFaction);
Faction targetFaction = this.readArgAt(1);
targetFaction.setPowerBoost(targetPower);
target = "Faction \""+targetFaction.getName()+"\"";
}
msg("<i>"+target+" now has a power bonus/penalty of "+targetPower+" to min and max power levels.");
Factions.get().log(msender.getName()+" has set the power bonus/penalty for "+target+" to "+targetPower+".");
// Child
this.addChild(this.cmdFactionsPowerBoostPlayer);
this.addChild(this.cmdFactionsPowerBoostFaction);
}
}

View File

@ -0,0 +1,76 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.FactionsParticipator;
import com.massivecraft.factions.Perm;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.type.Type;
import com.massivecraft.massivecore.command.type.TypeNullable;
import com.massivecraft.massivecore.command.type.primitive.TypeDouble;
import com.massivecraft.massivecore.util.Txt;
public abstract class CmdFactionsPowerBoostAbstract extends FactionsCommand
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
protected CmdFactionsPowerBoostAbstract(Type<? extends FactionsParticipator> parameterType, String parameterName)
{
// Parameters
this.addParameter(parameterType, parameterName);
this.addParameter(TypeNullable.get(TypeDouble.get()), "amount", "show");
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform() throws MassiveException
{
// Parameters
FactionsParticipator factionsParticipator = this.readArg();
Double powerBoost = this.readArg(factionsParticipator.getPowerBoost());
// Try set the powerBoost
boolean updated = this.trySet(factionsParticipator, powerBoost);
// Inform
this.informPowerBoost(factionsParticipator, powerBoost, updated);
}
private boolean trySet(FactionsParticipator factionsParticipator, Double powerBoost) throws MassiveException
{
// Trying to set?
if (!this.argIsSet(1)) return false;
// Check set permissions
if (!Perm.POWERBOOST_SET.has(sender, true)) throw new MassiveException();
// Set
factionsParticipator.setPowerBoost(powerBoost);
// Return
return true;
}
private void informPowerBoost(FactionsParticipator factionsParticipator, Double powerBoost, boolean updated)
{
// Prepare
String participatorDescribe = factionsParticipator.describeTo(msender, true);
powerBoost = powerBoost == null ? factionsParticipator.getPowerBoost() : powerBoost;
String powerDescription = Txt.parse(Double.compare(powerBoost, 0D) >= 0 ? "<g>bonus" : "<b>penalty");
String when = updated ? "now " : "";
String verb = factionsParticipator.equals(msender) ? "have" : "has";
// Create message
String messagePlayer = Txt.parse("<i>%s<i> %s%s a power %s<i> of <h>%.2f<i> to min and max power levels.", participatorDescribe, when, verb, powerDescription, powerBoost);
String messageLog = Txt.parse("%s %s set the power %s<i> for %s<i> to <h>%.2f<i>.", msender.getName(), verb, powerDescription, factionsParticipator.getName(), powerBoost);
// Inform
msender.message(messagePlayer);
if (updated) Factions.get().log(messageLog);
}
}

View File

@ -0,0 +1,16 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.cmd.type.TypeFaction;
public class CmdFactionsPowerBoostFaction extends CmdFactionsPowerBoostAbstract
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsPowerBoostFaction()
{
super(TypeFaction.get(), "faction");
}
}

View File

@ -0,0 +1,16 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.cmd.type.TypeMPlayer;
public class CmdFactionsPowerBoostPlayer extends CmdFactionsPowerBoostAbstract
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsPowerBoostPlayer()
{
super(TypeMPlayer.get(), "player");
}
}

View File

@ -17,16 +17,15 @@ import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.massivecraft.factions.EconomyParticipator;
import com.massivecraft.factions.FactionEqualsPredicate;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.FactionsParticipator;
import com.massivecraft.factions.Lang;
import com.massivecraft.factions.PredicateRole;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.RelationParticipator;
import com.massivecraft.factions.util.MiscUtil;
import com.massivecraft.factions.util.RelationUtil;
import com.massivecraft.massivecore.Named;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.collections.MassiveMapDef;
import com.massivecraft.massivecore.collections.MassiveSet;
@ -44,7 +43,7 @@ import com.massivecraft.massivecore.util.IdUtil;
import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.Txt;
public class Faction extends Entity<Faction> implements EconomyParticipator, Named
public class Faction extends Entity<Faction> implements FactionsParticipator
{
// -------------------------------------------- //
// META
@ -401,7 +400,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator, Nam
// -------------------------------------------- //
// RAW
@Override
public double getPowerBoost()
{
Double ret = this.powerBoost;
@ -409,6 +408,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator, Nam
return ret;
}
@Override
public void setPowerBoost(Double powerBoost)
{
// Clean input
@ -942,12 +942,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator, Nam
ret += mplayer.getPower();
}
double factionPowerMax = MConf.get().factionPowerMax;
if (factionPowerMax > 0 && ret > factionPowerMax)
{
ret = factionPowerMax;
}
ret = this.limitWithPowerMax(ret);
ret += this.getPowerBoost();
return ret;
@ -963,17 +958,20 @@ public class Faction extends Entity<Faction> implements EconomyParticipator, Nam
ret += mplayer.getPowerMax();
}
double factionPowerMax = MConf.get().factionPowerMax;
if (factionPowerMax > 0 && ret > factionPowerMax)
{
ret = factionPowerMax;
}
ret = this.limitWithPowerMax(ret);
ret += this.getPowerBoost();
return ret;
}
private double limitWithPowerMax(double power)
{
// NOTE: 0.0 powerMax means there is no max power
double powerMax = MConf.get().factionPowerMax;
return powerMax <= 0 || power < powerMax ? power : powerMax;
}
public int getPowerRounded()
{
return (int) Math.round(this.getPower());

View File

@ -10,8 +10,8 @@ import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.massivecraft.factions.EconomyParticipator;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.FactionsParticipator;
import com.massivecraft.factions.Lang;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel;
@ -20,8 +20,8 @@ import com.massivecraft.factions.event.EventFactionsChunkChangeType;
import com.massivecraft.factions.event.EventFactionsChunksChange;
import com.massivecraft.factions.event.EventFactionsDisband;
import com.massivecraft.factions.event.EventFactionsMembershipChange;
import com.massivecraft.factions.event.EventFactionsRemovePlayerMillis;
import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason;
import com.massivecraft.factions.event.EventFactionsRemovePlayerMillis;
import com.massivecraft.factions.mixin.PowerMixin;
import com.massivecraft.factions.util.RelationUtil;
import com.massivecraft.massivecore.mixin.MixinSenderPs;
@ -34,7 +34,7 @@ import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.Txt;
import com.massivecraft.massivecore.xlib.gson.annotations.SerializedName;
public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipator
public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipator
{
// -------------------------------------------- //
// META
@ -393,6 +393,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
// FIELD: powerBoost
// -------------------------------------------- //
@Override
public double getPowerBoost()
{
Double ret = this.powerBoost;
@ -400,6 +401,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
return ret;
}
@Override
public void setPowerBoost(Double powerBoost)
{
// Clean input