Step 1 in many removing the universe system. Untested and lacking auto convert features.
This commit is contained in:
@@ -5,8 +5,8 @@ import java.util.Set;
|
||||
|
||||
import com.massivecraft.factions.EconomyParticipator;
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.entity.UConf;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.util.RelationUtil;
|
||||
import com.massivecraft.massivecore.money.Money;
|
||||
@@ -17,27 +17,25 @@ public class Econ
|
||||
// STATE
|
||||
// -------------------------------------------- //
|
||||
|
||||
// TODO: Do we really need that config option?
|
||||
// TODO: Could we not have it enabled as long as Money.enabled is true?
|
||||
public static boolean isEnabled(Object universe)
|
||||
public static boolean isEnabled()
|
||||
{
|
||||
return UConf.get(universe).econEnabled && Money.enabled();
|
||||
return MConf.get().econEnabled && Money.enabled();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UTIL
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static boolean payForAction(double cost, UPlayer usender, String actionDescription)
|
||||
public static boolean payForAction(double cost, MPlayer usender, String actionDescription)
|
||||
{
|
||||
if (!isEnabled(usender)) return true;
|
||||
if (!isEnabled()) return true;
|
||||
if (cost == 0D) return true;
|
||||
|
||||
if (usender.isUsingAdminMode()) return true;
|
||||
UConf uconf = UConf.get(usender);
|
||||
|
||||
Faction usenderFaction = usender.getFaction();
|
||||
|
||||
if (uconf.bankEnabled && uconf.bankFactionPaysCosts && usenderFaction.isNormal())
|
||||
if (MConf.get().bankEnabled && MConf.get().bankFactionPaysCosts && usenderFaction.isNormal())
|
||||
{
|
||||
return modifyMoney(usenderFaction, -cost, actionDescription);
|
||||
}
|
||||
@@ -53,18 +51,17 @@ public class Econ
|
||||
|
||||
public static void modifyUniverseMoney(Object universe, double delta)
|
||||
{
|
||||
if (!isEnabled(universe)) return;
|
||||
UConf uconf = UConf.get(universe);
|
||||
if (!isEnabled()) return;
|
||||
|
||||
if (uconf.econUniverseAccount == null) return;
|
||||
if (uconf.econUniverseAccount.length() == 0) return;
|
||||
if (MConf.get().econUniverseAccount == null) return;
|
||||
if (MConf.get().econUniverseAccount.length() == 0) return;
|
||||
|
||||
if (!Money.exists(uconf.econUniverseAccount)) return;
|
||||
if (!Money.exists(MConf.get().econUniverseAccount)) return;
|
||||
|
||||
Money.spawn(uconf.econUniverseAccount, null, delta);
|
||||
Money.spawn(MConf.get().econUniverseAccount, null, delta);
|
||||
}
|
||||
|
||||
public static void sendBalanceInfo(UPlayer to, EconomyParticipator about)
|
||||
public static void sendBalanceInfo(MPlayer to, EconomyParticipator about)
|
||||
{
|
||||
to.msg("<a>%s's<i> balance is <h>%s<i>.", about.describeTo(to, true), Money.format(Money.get(about)));
|
||||
}
|
||||
@@ -78,7 +75,7 @@ public class Econ
|
||||
if (fI == null) return true;
|
||||
|
||||
// Bypassing players can do any kind of transaction
|
||||
if (i instanceof UPlayer && ((UPlayer)i).isUsingAdminMode()) return true;
|
||||
if (i instanceof MPlayer && ((MPlayer)i).isUsingAdminMode()) return true;
|
||||
|
||||
// You can deposit to anywhere you feel like. It's your loss if you can't withdraw it again.
|
||||
if (i == you) return true;
|
||||
@@ -92,7 +89,7 @@ public class Econ
|
||||
if (you instanceof Faction)
|
||||
{
|
||||
if (i instanceof Faction && FPerm.WITHDRAW.has((Faction)i, fYou)) return true;
|
||||
if (i instanceof UPlayer && FPerm.WITHDRAW.has((UPlayer)i, fYou, false)) return true;
|
||||
if (i instanceof MPlayer && FPerm.WITHDRAW.has((MPlayer)i, fYou, false)) return true;
|
||||
}
|
||||
|
||||
// Otherwise you may not! ;,,;
|
||||
@@ -105,7 +102,7 @@ public class Econ
|
||||
}
|
||||
public static boolean transferMoney(EconomyParticipator from, EconomyParticipator to, EconomyParticipator by, double amount, boolean notify)
|
||||
{
|
||||
if (!isEnabled(from)) return false;
|
||||
if (!isEnabled()) return false;
|
||||
|
||||
// The amount must be positive.
|
||||
// If the amount is negative we must flip and multiply amount with -1.
|
||||
@@ -155,17 +152,17 @@ public class Econ
|
||||
}
|
||||
}
|
||||
|
||||
public static Set<UPlayer> getUPlayers(EconomyParticipator ep)
|
||||
public static Set<MPlayer> getUPlayers(EconomyParticipator ep)
|
||||
{
|
||||
Set<UPlayer> uplayers = new HashSet<UPlayer>();
|
||||
Set<MPlayer> uplayers = new HashSet<MPlayer>();
|
||||
|
||||
if (ep == null)
|
||||
{
|
||||
// Add nothing
|
||||
}
|
||||
else if (ep instanceof UPlayer)
|
||||
else if (ep instanceof MPlayer)
|
||||
{
|
||||
uplayers.add((UPlayer)ep);
|
||||
uplayers.add((MPlayer)ep);
|
||||
}
|
||||
else if (ep instanceof Faction)
|
||||
{
|
||||
@@ -177,35 +174,35 @@ public class Econ
|
||||
|
||||
public static void sendTransferInfo(EconomyParticipator invoker, EconomyParticipator from, EconomyParticipator to, double amount)
|
||||
{
|
||||
Set<UPlayer> recipients = new HashSet<UPlayer>();
|
||||
Set<MPlayer> recipients = new HashSet<MPlayer>();
|
||||
recipients.addAll(getUPlayers(invoker));
|
||||
recipients.addAll(getUPlayers(from));
|
||||
recipients.addAll(getUPlayers(to));
|
||||
|
||||
if (invoker == null)
|
||||
{
|
||||
for (UPlayer recipient : recipients)
|
||||
for (MPlayer recipient : recipients)
|
||||
{
|
||||
recipient.msg("<h>%s<i> was transfered from <h>%s<i> to <h>%s<i>.", Money.format(amount), from.describeTo(recipient), to.describeTo(recipient));
|
||||
}
|
||||
}
|
||||
else if (invoker == from)
|
||||
{
|
||||
for (UPlayer recipient : recipients)
|
||||
for (MPlayer recipient : recipients)
|
||||
{
|
||||
recipient.msg("<h>%s<i> <h>gave %s<i> to <h>%s<i>.", from.describeTo(recipient, true), Money.format(amount), to.describeTo(recipient));
|
||||
}
|
||||
}
|
||||
else if (invoker == to)
|
||||
{
|
||||
for (UPlayer recipient : recipients)
|
||||
for (MPlayer recipient : recipients)
|
||||
{
|
||||
recipient.msg("<h>%s<i> <h>took %s<i> from <h>%s<i>.", to.describeTo(recipient, true), Money.format(amount), from.describeTo(recipient));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (UPlayer recipient : recipients)
|
||||
for (MPlayer recipient : recipients)
|
||||
{
|
||||
recipient.msg("<h>%s<i> transfered <h>%s<i> from <h>%s<i> to <h>%s<i>.", invoker.describeTo(recipient, true), Money.format(amount), from.describeTo(recipient), to.describeTo(recipient));
|
||||
}
|
||||
@@ -214,7 +211,7 @@ public class Econ
|
||||
|
||||
public static boolean hasAtLeast(EconomyParticipator ep, double delta, String toDoThis)
|
||||
{
|
||||
if (!isEnabled(ep)) return true;
|
||||
if (!isEnabled()) return true;
|
||||
|
||||
if (Money.get(ep) < delta)
|
||||
{
|
||||
@@ -229,7 +226,7 @@ public class Econ
|
||||
|
||||
public static boolean modifyMoney(EconomyParticipator ep, double delta, String actionDescription)
|
||||
{
|
||||
if (!isEnabled(ep)) return false;
|
||||
if (!isEnabled()) return false;
|
||||
if (delta == 0) return true;
|
||||
|
||||
String You = ep.describeTo(ep, true);
|
||||
|
@@ -28,13 +28,10 @@ import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.TerritoryAccess;
|
||||
import com.massivecraft.factions.entity.Board;
|
||||
import com.massivecraft.factions.entity.BoardColl;
|
||||
import com.massivecraft.factions.entity.BoardColls;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.FactionColl;
|
||||
import com.massivecraft.factions.entity.FactionColls;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.entity.UConf;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.EngineAbstract;
|
||||
import com.massivecraft.massivecore.money.Money;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
@@ -241,28 +238,25 @@ public class EngineDynmap extends EngineAbstract
|
||||
Map<String, TempMarker> ret = new HashMap<String, TempMarker>();
|
||||
|
||||
// Loop current factions
|
||||
for (FactionColl coll : FactionColls.get().getColls())
|
||||
for (Faction faction : FactionColl.get().getAll())
|
||||
{
|
||||
for (Faction faction : coll.getAll())
|
||||
{
|
||||
PS ps = faction.getHome();
|
||||
if (ps == null) continue;
|
||||
|
||||
DynmapStyle style = getStyle(faction);
|
||||
|
||||
String markerId = FACTIONS_HOME_ + faction.getId();
|
||||
|
||||
TempMarker temp = new TempMarker();
|
||||
temp.label = ChatColor.stripColor(faction.getName());
|
||||
temp.world = ps.getWorld();
|
||||
temp.x = ps.getLocationX();
|
||||
temp.y = ps.getLocationY();
|
||||
temp.z = ps.getLocationZ();
|
||||
temp.iconName = style.getHomeMarker();
|
||||
temp.description = getDescription(faction);
|
||||
|
||||
ret.put(markerId, temp);
|
||||
}
|
||||
PS ps = faction.getHome();
|
||||
if (ps == null) continue;
|
||||
|
||||
DynmapStyle style = getStyle(faction);
|
||||
|
||||
String markerId = FACTIONS_HOME_ + faction.getId();
|
||||
|
||||
TempMarker temp = new TempMarker();
|
||||
temp.label = ChatColor.stripColor(faction.getName());
|
||||
temp.world = ps.getWorld();
|
||||
temp.x = ps.getLocationX();
|
||||
temp.y = ps.getLocationY();
|
||||
temp.z = ps.getLocationZ();
|
||||
temp.iconName = style.getHomeMarker();
|
||||
temp.description = getDescription(faction);
|
||||
|
||||
ret.put(markerId, temp);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -327,42 +321,41 @@ public class EngineDynmap extends EngineAbstract
|
||||
{
|
||||
// Create map "world name --> faction --> set of chunk coords"
|
||||
Map<String, Map<Faction, Set<PS>>> worldFactionChunks = new HashMap<String, Map<Faction, Set<PS>>>();
|
||||
for (BoardColl coll : BoardColls.get().getColls())
|
||||
|
||||
// Note: The board is the world. The board id is the world name.
|
||||
for (Board board : BoardColl.get().getAll())
|
||||
{
|
||||
// Note: The board is the world. The board id is the world name.
|
||||
for (Board board : coll.getAll())
|
||||
String world = board.getId();
|
||||
|
||||
// Get the factionChunks creatively.
|
||||
Map<Faction, Set<PS>> factionChunks = worldFactionChunks.get(world);
|
||||
if (factionChunks == null)
|
||||
{
|
||||
String world = board.getId();
|
||||
factionChunks = new HashMap<Faction, Set<PS>>();
|
||||
worldFactionChunks.put(world, factionChunks);
|
||||
}
|
||||
|
||||
// Populate the factionChunks
|
||||
for (Entry<PS, TerritoryAccess> entry : board.getMap().entrySet())
|
||||
{
|
||||
PS chunk = entry.getKey();
|
||||
TerritoryAccess territoryAccess = entry.getValue();
|
||||
String factionId = territoryAccess.getHostFactionId();
|
||||
Faction faction = Faction.get(factionId);
|
||||
if (faction == null) continue;
|
||||
|
||||
// Get the factionChunks creatively.
|
||||
Map<Faction, Set<PS>> factionChunks = worldFactionChunks.get(world);
|
||||
if (factionChunks == null)
|
||||
// Get the chunks creatively.
|
||||
Set<PS> chunks = factionChunks.get(faction);
|
||||
if (chunks == null)
|
||||
{
|
||||
factionChunks = new HashMap<Faction, Set<PS>>();
|
||||
worldFactionChunks.put(world, factionChunks);
|
||||
}
|
||||
|
||||
// Populate the factionChunks
|
||||
for (Entry<PS, TerritoryAccess> entry : board.getMap().entrySet())
|
||||
{
|
||||
PS chunk = entry.getKey();
|
||||
TerritoryAccess territoryAccess = entry.getValue();
|
||||
String factionId = territoryAccess.getHostFactionId();
|
||||
Faction faction = FactionColls.get().getForWorld(world).get(factionId);
|
||||
if (faction == null) continue;
|
||||
|
||||
// Get the chunks creatively.
|
||||
Set<PS> chunks = factionChunks.get(faction);
|
||||
if (chunks == null)
|
||||
{
|
||||
chunks = new HashSet<PS>();
|
||||
factionChunks.put(faction, chunks);
|
||||
}
|
||||
|
||||
chunks.add(chunk);
|
||||
chunks = new HashSet<PS>();
|
||||
factionChunks.put(faction, chunks);
|
||||
}
|
||||
|
||||
chunks.add(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
return worldFactionChunks;
|
||||
}
|
||||
|
||||
@@ -659,7 +652,7 @@ public class EngineDynmap extends EngineAbstract
|
||||
|
||||
Set<String> ret = new HashSet<String>();
|
||||
|
||||
for (UPlayer uplayer : faction.getUPlayers())
|
||||
for (MPlayer uplayer : faction.getUPlayers())
|
||||
{
|
||||
// NOTE: We add both UUID and name. This might be a good idea for future proofing.
|
||||
ret.add(uplayer.getId());
|
||||
@@ -675,17 +668,14 @@ public class EngineDynmap extends EngineAbstract
|
||||
if (!MConf.get().dynmapVisibilityByFaction) return null;
|
||||
|
||||
Map<String, Set<String>> ret = new HashMap<String, Set<String>>();
|
||||
|
||||
for (FactionColl coll : FactionColls.get().getColls())
|
||||
|
||||
for (Faction faction : FactionColl.get().getAll())
|
||||
{
|
||||
for (Faction faction : coll.getAll())
|
||||
{
|
||||
String playersetId = createPlayersetId(faction);
|
||||
if (playersetId == null) continue;
|
||||
Set<String> playerIds = createPlayerset(faction);
|
||||
if (playerIds == null) continue;
|
||||
ret.put(playersetId, playerIds);
|
||||
}
|
||||
String playersetId = createPlayersetId(faction);
|
||||
if (playersetId == null) continue;
|
||||
Set<String> playerIds = createPlayerset(faction);
|
||||
if (playerIds == null) continue;
|
||||
ret.put(playersetId, playerIds);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -761,7 +751,7 @@ public class EngineDynmap extends EngineAbstract
|
||||
|
||||
// Money
|
||||
String money = "unavailable";
|
||||
if (UConf.get(faction).bankEnabled && MConf.get().dynmapDescriptionMoney)
|
||||
if (MConf.get().bankEnabled && MConf.get().dynmapDescriptionMoney)
|
||||
{
|
||||
money = Money.format(Money.get(faction));
|
||||
}
|
||||
@@ -789,22 +779,22 @@ public class EngineDynmap extends EngineAbstract
|
||||
}
|
||||
|
||||
// Players
|
||||
List<UPlayer> playersList = faction.getUPlayers();
|
||||
List<MPlayer> playersList = faction.getUPlayers();
|
||||
String playersCount = String.valueOf(playersList.size());
|
||||
String players = getPlayerString(playersList);
|
||||
|
||||
UPlayer playersLeaderObject = faction.getLeader();
|
||||
MPlayer playersLeaderObject = faction.getLeader();
|
||||
String playersLeader = getPlayerName(playersLeaderObject);
|
||||
|
||||
List<UPlayer> playersOfficersList = faction.getUPlayersWhereRole(Rel.OFFICER);
|
||||
List<MPlayer> playersOfficersList = faction.getUPlayersWhereRole(Rel.OFFICER);
|
||||
String playersOfficersCount = String.valueOf(playersOfficersList.size());
|
||||
String playersOfficers = getPlayerString(playersOfficersList);
|
||||
|
||||
List<UPlayer> playersMembersList = faction.getUPlayersWhereRole(Rel.MEMBER);
|
||||
List<MPlayer> playersMembersList = faction.getUPlayersWhereRole(Rel.MEMBER);
|
||||
String playersMembersCount = String.valueOf(playersMembersList.size());
|
||||
String playersMembers = getPlayerString(playersMembersList);
|
||||
|
||||
List<UPlayer> playersRecruitsList = faction.getUPlayersWhereRole(Rel.RECRUIT);
|
||||
List<MPlayer> playersRecruitsList = faction.getUPlayersWhereRole(Rel.RECRUIT);
|
||||
String playersRecruitsCount = String.valueOf(playersRecruitsList.size());
|
||||
String playersRecruits = getPlayerString(playersRecruitsList);
|
||||
|
||||
@@ -822,10 +812,10 @@ public class EngineDynmap extends EngineAbstract
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static String getPlayerString(List<UPlayer> uplayers)
|
||||
public static String getPlayerString(List<MPlayer> uplayers)
|
||||
{
|
||||
String ret = "";
|
||||
for (UPlayer uplayer : uplayers)
|
||||
for (MPlayer uplayer : uplayers)
|
||||
{
|
||||
if (ret.length() > 0) ret += ", ";
|
||||
ret += getPlayerName(uplayer);
|
||||
@@ -833,7 +823,7 @@ public class EngineDynmap extends EngineAbstract
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static String getPlayerName(UPlayer uplayer)
|
||||
public static String getPlayerName(MPlayer uplayer)
|
||||
{
|
||||
if (uplayer == null) return "none";
|
||||
return escapeHtml(uplayer.getName());
|
||||
|
@@ -23,7 +23,7 @@ import com.dthielke.herochat.Herochat;
|
||||
import com.dthielke.herochat.MessageFormatSupplier;
|
||||
import com.dthielke.herochat.MessageNotFoundException;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
|
||||
public abstract class ChannelFactionsAbstract implements Channel
|
||||
@@ -228,13 +228,13 @@ public abstract class ChannelFactionsAbstract implements Channel
|
||||
{
|
||||
Set<Player> ret = new HashSet<Player>();
|
||||
|
||||
UPlayer fpsender = UPlayer.get(sender);
|
||||
MPlayer fpsender = MPlayer.get(sender);
|
||||
Faction faction = fpsender.getFaction();
|
||||
String universe = fpsender.getUniverse();
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
UPlayer frecipient = UPlayer.get(player);
|
||||
MPlayer frecipient = MPlayer.get(player);
|
||||
if (!frecipient.getUniverse().equals(universe)) continue;
|
||||
if (!this.getTargetRelations().contains(faction.getRelationTo(frecipient))) continue;
|
||||
ret.add(player);
|
||||
|
@@ -17,8 +17,8 @@ import com.griefcraft.lwc.LWC;
|
||||
import com.griefcraft.model.Protection;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.UConf;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.factions.event.EventFactionsChunkChange;
|
||||
import com.massivecraft.factions.event.EventFactionsChunkChangeType;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
@@ -57,9 +57,8 @@ public class EngineLwc implements Listener
|
||||
{
|
||||
// If we are supposed to clear at this chunk change type ...
|
||||
Faction newFaction = event.getNewFaction();
|
||||
UConf uconf = UConf.get(newFaction);
|
||||
EventFactionsChunkChangeType type = event.getType();
|
||||
Boolean remove = uconf.lwcRemoveOnChange.get(type);
|
||||
Boolean remove = MConf.get().lwcRemoveOnChange.get(type);
|
||||
if (remove == null) return;
|
||||
if (remove == false) return;
|
||||
|
||||
@@ -73,10 +72,10 @@ public class EngineLwc implements Listener
|
||||
|
||||
public static void removeAlienProtections(PS chunkPs, Faction faction)
|
||||
{
|
||||
List<UPlayer> nonAliens = faction.getUPlayers();
|
||||
List<MPlayer> nonAliens = faction.getUPlayers();
|
||||
for (Protection protection : getProtectionsInChunk(chunkPs))
|
||||
{
|
||||
UPlayer owner = UPlayer.get(protection.getOwner());
|
||||
MPlayer owner = MPlayer.get(protection.getOwner());
|
||||
if (nonAliens.contains(owner)) continue;
|
||||
protection.remove();
|
||||
}
|
||||
|
Reference in New Issue
Block a user