Introducing a power Mixin since Bukkit does not allow permissions for offline players and we want to know for offline players. Servers wanting individual power rules can implement and inject this mixin.
This commit is contained in:
@ -1,20 +1,14 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import com.massivecraft.factions.listeners.FactionsListenerChat;
|
||||
import com.massivecraft.mcore.store.Entity;
|
||||
import com.massivecraft.mcore.util.MUtil;
|
||||
import com.massivecraft.mcore.util.PermUtil;
|
||||
import com.massivecraft.mcore.util.TimeUnit;
|
||||
|
||||
public class MConf extends Entity<MConf>
|
||||
@ -35,7 +29,6 @@ public class MConf extends Entity<MConf>
|
||||
{
|
||||
super.load(that);
|
||||
|
||||
this.upsertPowerPerms();
|
||||
FactionsListenerChat.get().setup();
|
||||
|
||||
return this;
|
||||
@ -47,55 +40,6 @@ public class MConf extends Entity<MConf>
|
||||
|
||||
public long powerTaskMillis = TimeUnit.MILLIS_PER_MINUTE;
|
||||
|
||||
public Map<String, Double> permToPowerMax = MUtil.map(
|
||||
"factions.power.max.50", 50.0,
|
||||
"factions.power.max.40", 40.0,
|
||||
"factions.power.max.30", 30.0,
|
||||
"factions.power.max.20", 20.0,
|
||||
"factions.power.max.10", 10.0,
|
||||
"factions.power.max.default", 10.0
|
||||
);
|
||||
|
||||
public Map<String, Double> permToPowerMin = MUtil.map(
|
||||
"factions.power.min.50", 50.0,
|
||||
"factions.power.min.40", 40.0,
|
||||
"factions.power.min.30", 30.0,
|
||||
"factions.power.min.20", 20.0,
|
||||
"factions.power.min.10", 10.0,
|
||||
"factions.power.min.default", 10.0
|
||||
);
|
||||
|
||||
public Map<String, Double> permToPowerHour = MUtil.map(
|
||||
"factions.power.hour.50", 50.0,
|
||||
"factions.power.hour.40", 40.0,
|
||||
"factions.power.hour.30", 30.0,
|
||||
"factions.power.hour.20", 20.0,
|
||||
"factions.power.hour.10", 10.0,
|
||||
"factions.power.hour.4", 4.0,
|
||||
"factions.power.hour.2", 2.0,
|
||||
"factions.power.hour.default", 2.0
|
||||
);
|
||||
|
||||
public Map<String, Double> permToPowerDeath = MUtil.map(
|
||||
"factions.power.death.0", 0.0,
|
||||
"factions.power.death.-2", -2.0,
|
||||
"factions.power.death.default", -2.0
|
||||
);
|
||||
|
||||
public void upsertPowerPerms()
|
||||
{
|
||||
List<String> names = new ArrayList<String>();
|
||||
names.addAll(this.permToPowerMax.keySet());
|
||||
names.addAll(this.permToPowerMin.keySet());
|
||||
names.addAll(this.permToPowerHour.keySet());
|
||||
names.addAll(this.permToPowerDeath.keySet());
|
||||
|
||||
for (String name : names)
|
||||
{
|
||||
PermUtil.get(true, true, name, name, PermissionDefault.FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CHAT
|
||||
// -------------------------------------------- //
|
||||
|
@ -51,6 +51,15 @@ public class UConf extends Entity<UConf>
|
||||
public Map<FFlag, Boolean> defaultFactionFlags = FFlag.getDefaultDefaults();
|
||||
public Map<FPerm, Set<Rel>> defaultFactionPerms = FPerm.getDefaultDefaults();
|
||||
|
||||
// -------------------------------------------- //
|
||||
// POWER
|
||||
// -------------------------------------------- //
|
||||
|
||||
public double powerMax = 10.0;
|
||||
public double powerMin = 0.0;
|
||||
public double powerPerHour = 2.0;
|
||||
public double powerPerDeath = -2.0;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// DENY COMMANDS
|
||||
// -------------------------------------------- //
|
||||
|
@ -289,6 +289,42 @@ public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipato
|
||||
// FIELD: power
|
||||
// -------------------------------------------- //
|
||||
|
||||
// MIXIN: RAW
|
||||
|
||||
public double getPowerMaxUniversal()
|
||||
{
|
||||
return Factions.get().getPowerMixin().getMaxUniversal(this);
|
||||
}
|
||||
|
||||
public double getPowerMax()
|
||||
{
|
||||
return Factions.get().getPowerMixin().getMax(this);
|
||||
}
|
||||
|
||||
public double getPowerMin()
|
||||
{
|
||||
return Factions.get().getPowerMixin().getMin(this);
|
||||
}
|
||||
|
||||
public double getPowerPerHour()
|
||||
{
|
||||
return Factions.get().getPowerMixin().getPerHour(this);
|
||||
}
|
||||
|
||||
public double getPowerPerDeath()
|
||||
{
|
||||
return Factions.get().getPowerMixin().getPerDeath(this);
|
||||
}
|
||||
|
||||
// MIXIN: FINER
|
||||
|
||||
public double getLimitedPower(double power)
|
||||
{
|
||||
power = Math.max(power, this.getPowerMin());
|
||||
power = Math.min(power, this.getPowerMax());
|
||||
return power;
|
||||
}
|
||||
|
||||
// RAW
|
||||
|
||||
public double getDefaultPower()
|
||||
@ -300,12 +336,14 @@ public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipato
|
||||
{
|
||||
Double ret = this.power;
|
||||
if (ret == null) ret = this.getDefaultPower();
|
||||
ret = this.getLimitedPower(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void setPower(Double power)
|
||||
{
|
||||
if (power == null || MUtil.equals(power, this.getDefaultPower())) power = null;
|
||||
power = this.getLimitedPower(power);
|
||||
this.power = power;
|
||||
this.changed();
|
||||
}
|
||||
|
Reference in New Issue
Block a user