Implement interface Powerboosted.
This commit is contained in:
parent
91fc5a2404
commit
9a2066efcc
13
plugin.yml
13
plugin.yml
@ -59,7 +59,10 @@ permissions:
|
|||||||
factions.perm.set: {description: set perms, default: false}
|
factions.perm.set: {description: set perms, default: false}
|
||||||
factions.perm.show: {description: show perms, default: false}
|
factions.perm.show: {description: show perms, default: false}
|
||||||
factions.player: {description: show player information}
|
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: {description: manage/show ranks, default: false}
|
||||||
factions.rank.show: {description: show rank, default: false}
|
factions.rank.show: {description: show rank, default: false}
|
||||||
factions.rank.action: {description: change rank, default: false}
|
factions.rank.action: {description: change rank, default: false}
|
||||||
@ -147,6 +150,9 @@ permissions:
|
|||||||
factions.perm.show: true
|
factions.perm.show: true
|
||||||
factions.player: true
|
factions.player: true
|
||||||
factions.powerboost: true
|
factions.powerboost: true
|
||||||
|
factions.powerboost.faction: true
|
||||||
|
factions.powerboost.player: true
|
||||||
|
factions.powerboost.set: true
|
||||||
factions.promote: true
|
factions.promote: true
|
||||||
factions.relation: true
|
factions.relation: true
|
||||||
factions.relation.list: true
|
factions.relation.list: true
|
||||||
@ -188,7 +194,7 @@ permissions:
|
|||||||
default: false
|
default: false
|
||||||
children:
|
children:
|
||||||
factions.kit.rank1: true
|
factions.kit.rank1: true
|
||||||
factions.powerboost: true
|
factions.powerboost.set: true
|
||||||
factions.join.others: true
|
factions.join.others: true
|
||||||
factions.leader.any: true
|
factions.leader.any: true
|
||||||
factions.officer.any: true
|
factions.officer.any: true
|
||||||
@ -253,6 +259,9 @@ permissions:
|
|||||||
factions.perm.show: true
|
factions.perm.show: true
|
||||||
factions.player: true
|
factions.player: true
|
||||||
factions.promote: true
|
factions.promote: true
|
||||||
|
factions.powerboost: true
|
||||||
|
factions.powerboost.faction: true
|
||||||
|
factions.powerboost.player: true
|
||||||
factions.rank: true
|
factions.rank: true
|
||||||
factions.rank.show: true
|
factions.rank.show: true
|
||||||
factions.rank.action: true
|
factions.rank.action: true
|
||||||
|
7
src/com/massivecraft/factions/FactionsParticipator.java
Normal file
7
src/com/massivecraft/factions/FactionsParticipator.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package com.massivecraft.factions;
|
||||||
|
|
||||||
|
import com.massivecraft.massivecore.Named;
|
||||||
|
|
||||||
|
public interface FactionsParticipator extends Named, EconomyParticipator, PowerBoosted
|
||||||
|
{
|
||||||
|
}
|
@ -61,6 +61,9 @@ public enum Perm implements Identified
|
|||||||
PERM_SHOW,
|
PERM_SHOW,
|
||||||
PLAYER,
|
PLAYER,
|
||||||
POWERBOOST,
|
POWERBOOST,
|
||||||
|
POWERBOOST_PLAYER,
|
||||||
|
POWERBOOST_FACTION,
|
||||||
|
POWERBOOST_SET,
|
||||||
RANK,
|
RANK,
|
||||||
RANK_SHOW,
|
RANK_SHOW,
|
||||||
RANK_ACTION,
|
RANK_ACTION,
|
||||||
|
7
src/com/massivecraft/factions/PowerBoosted.java
Normal file
7
src/com/massivecraft/factions/PowerBoosted.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package com.massivecraft.factions;
|
||||||
|
|
||||||
|
public interface PowerBoosted
|
||||||
|
{
|
||||||
|
public double getPowerBoost();
|
||||||
|
public void setPowerBoost(Double powerBoost);
|
||||||
|
}
|
@ -1,23 +1,13 @@
|
|||||||
package com.massivecraft.factions.cmd;
|
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
|
public class CmdFactionsPowerBoost extends FactionsCommand
|
||||||
{
|
{
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// FIELDS
|
// FIELDS
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
private Parameter<MPlayer> parameterMplayer = new Parameter<MPlayer>(TypeMPlayer.get(), "name");
|
public CmdFactionsPowerBoostPlayer cmdFactionsPowerBoostPlayer = new CmdFactionsPowerBoostPlayer();
|
||||||
private Parameter<Faction> parameterFaction = new Parameter<Faction>(TypeFaction.get(), "name");
|
public CmdFactionsPowerBoostFaction cmdFactionsPowerBoostFaction = new CmdFactionsPowerBoostFaction();
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// CONSTRUCT
|
// CONSTRUCT
|
||||||
@ -25,55 +15,9 @@ public class CmdFactionsPowerBoost extends FactionsCommand
|
|||||||
|
|
||||||
public CmdFactionsPowerBoost()
|
public CmdFactionsPowerBoost()
|
||||||
{
|
{
|
||||||
// Parameters
|
// Child
|
||||||
this.addParameter(TypeString.get(), "p|f|player|faction");
|
this.addChild(this.cmdFactionsPowerBoostPlayer);
|
||||||
this.addParameter(parameterMplayer);
|
this.addChild(this.cmdFactionsPowerBoostFaction);
|
||||||
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+".");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -17,16 +17,15 @@ import org.bukkit.ChatColor;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.massivecraft.factions.EconomyParticipator;
|
|
||||||
import com.massivecraft.factions.FactionEqualsPredicate;
|
import com.massivecraft.factions.FactionEqualsPredicate;
|
||||||
import com.massivecraft.factions.Factions;
|
import com.massivecraft.factions.Factions;
|
||||||
|
import com.massivecraft.factions.FactionsParticipator;
|
||||||
import com.massivecraft.factions.Lang;
|
import com.massivecraft.factions.Lang;
|
||||||
import com.massivecraft.factions.PredicateRole;
|
import com.massivecraft.factions.PredicateRole;
|
||||||
import com.massivecraft.factions.Rel;
|
import com.massivecraft.factions.Rel;
|
||||||
import com.massivecraft.factions.RelationParticipator;
|
import com.massivecraft.factions.RelationParticipator;
|
||||||
import com.massivecraft.factions.util.MiscUtil;
|
import com.massivecraft.factions.util.MiscUtil;
|
||||||
import com.massivecraft.factions.util.RelationUtil;
|
import com.massivecraft.factions.util.RelationUtil;
|
||||||
import com.massivecraft.massivecore.Named;
|
|
||||||
import com.massivecraft.massivecore.collections.MassiveList;
|
import com.massivecraft.massivecore.collections.MassiveList;
|
||||||
import com.massivecraft.massivecore.collections.MassiveMapDef;
|
import com.massivecraft.massivecore.collections.MassiveMapDef;
|
||||||
import com.massivecraft.massivecore.collections.MassiveSet;
|
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.MUtil;
|
||||||
import com.massivecraft.massivecore.util.Txt;
|
import com.massivecraft.massivecore.util.Txt;
|
||||||
|
|
||||||
public class Faction extends Entity<Faction> implements EconomyParticipator, Named
|
public class Faction extends Entity<Faction> implements FactionsParticipator
|
||||||
{
|
{
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// META
|
// META
|
||||||
@ -401,7 +400,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator, Nam
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
// RAW
|
// RAW
|
||||||
|
@Override
|
||||||
public double getPowerBoost()
|
public double getPowerBoost()
|
||||||
{
|
{
|
||||||
Double ret = this.powerBoost;
|
Double ret = this.powerBoost;
|
||||||
@ -409,6 +408,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator, Nam
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setPowerBoost(Double powerBoost)
|
public void setPowerBoost(Double powerBoost)
|
||||||
{
|
{
|
||||||
// Clean input
|
// Clean input
|
||||||
@ -942,12 +942,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator, Nam
|
|||||||
ret += mplayer.getPower();
|
ret += mplayer.getPower();
|
||||||
}
|
}
|
||||||
|
|
||||||
double factionPowerMax = MConf.get().factionPowerMax;
|
ret = this.limitWithPowerMax(ret);
|
||||||
if (factionPowerMax > 0 && ret > factionPowerMax)
|
|
||||||
{
|
|
||||||
ret = factionPowerMax;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret += this.getPowerBoost();
|
ret += this.getPowerBoost();
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -963,17 +958,20 @@ public class Faction extends Entity<Faction> implements EconomyParticipator, Nam
|
|||||||
ret += mplayer.getPowerMax();
|
ret += mplayer.getPowerMax();
|
||||||
}
|
}
|
||||||
|
|
||||||
double factionPowerMax = MConf.get().factionPowerMax;
|
ret = this.limitWithPowerMax(ret);
|
||||||
if (factionPowerMax > 0 && ret > factionPowerMax)
|
|
||||||
{
|
|
||||||
ret = factionPowerMax;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret += this.getPowerBoost();
|
ret += this.getPowerBoost();
|
||||||
|
|
||||||
return ret;
|
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()
|
public int getPowerRounded()
|
||||||
{
|
{
|
||||||
return (int) Math.round(this.getPower());
|
return (int) Math.round(this.getPower());
|
||||||
|
@ -10,8 +10,8 @@ import org.bukkit.ChatColor;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.massivecraft.factions.EconomyParticipator;
|
|
||||||
import com.massivecraft.factions.Factions;
|
import com.massivecraft.factions.Factions;
|
||||||
|
import com.massivecraft.factions.FactionsParticipator;
|
||||||
import com.massivecraft.factions.Lang;
|
import com.massivecraft.factions.Lang;
|
||||||
import com.massivecraft.factions.Perm;
|
import com.massivecraft.factions.Perm;
|
||||||
import com.massivecraft.factions.Rel;
|
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.EventFactionsChunksChange;
|
||||||
import com.massivecraft.factions.event.EventFactionsDisband;
|
import com.massivecraft.factions.event.EventFactionsDisband;
|
||||||
import com.massivecraft.factions.event.EventFactionsMembershipChange;
|
import com.massivecraft.factions.event.EventFactionsMembershipChange;
|
||||||
import com.massivecraft.factions.event.EventFactionsRemovePlayerMillis;
|
|
||||||
import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason;
|
import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason;
|
||||||
|
import com.massivecraft.factions.event.EventFactionsRemovePlayerMillis;
|
||||||
import com.massivecraft.factions.mixin.PowerMixin;
|
import com.massivecraft.factions.mixin.PowerMixin;
|
||||||
import com.massivecraft.factions.util.RelationUtil;
|
import com.massivecraft.factions.util.RelationUtil;
|
||||||
import com.massivecraft.massivecore.mixin.MixinSenderPs;
|
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.util.Txt;
|
||||||
import com.massivecraft.massivecore.xlib.gson.annotations.SerializedName;
|
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
|
// META
|
||||||
@ -393,6 +393,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
|
|||||||
// FIELD: powerBoost
|
// FIELD: powerBoost
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
public double getPowerBoost()
|
public double getPowerBoost()
|
||||||
{
|
{
|
||||||
Double ret = this.powerBoost;
|
Double ret = this.powerBoost;
|
||||||
@ -400,6 +401,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setPowerBoost(Double powerBoost)
|
public void setPowerBoost(Double powerBoost)
|
||||||
{
|
{
|
||||||
// Clean input
|
// Clean input
|
||||||
|
Loading…
Reference in New Issue
Block a user