Clean up the Coll's
This commit is contained in:
parent
0ba52eae14
commit
b13c77b6c5
@ -131,29 +131,42 @@ public class BoardColl extends Coll<Board> implements BoardInterface
|
|||||||
@Override
|
@Override
|
||||||
public Set<PS> getChunks(Faction faction)
|
public Set<PS> getChunks(Faction faction)
|
||||||
{
|
{
|
||||||
|
// Create
|
||||||
Set<PS> ret = new HashSet<PS>();
|
Set<PS> ret = new HashSet<PS>();
|
||||||
|
|
||||||
|
// Fill
|
||||||
for (Board board : this.getAll())
|
for (Board board : this.getAll())
|
||||||
{
|
{
|
||||||
ret.addAll(board.getChunks(faction));
|
ret.addAll(board.getChunks(faction));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<PS> getChunks(String factionId)
|
public Set<PS> getChunks(String factionId)
|
||||||
{
|
{
|
||||||
|
// Create
|
||||||
Set<PS> ret = new HashSet<PS>();
|
Set<PS> ret = new HashSet<PS>();
|
||||||
|
|
||||||
|
// Fill
|
||||||
for (Board board : this.getAll())
|
for (Board board : this.getAll())
|
||||||
{
|
{
|
||||||
ret.addAll(board.getChunks(factionId));
|
ret.addAll(board.getChunks(factionId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<Faction, Set<PS>> getFactionToChunks()
|
public Map<Faction, Set<PS>> getFactionToChunks()
|
||||||
{
|
{
|
||||||
|
// Create
|
||||||
Map<Faction, Set<PS>> ret = null;
|
Map<Faction, Set<PS>> ret = null;
|
||||||
|
|
||||||
|
// Fill
|
||||||
for (Board board : this.getAll())
|
for (Board board : this.getAll())
|
||||||
{
|
{
|
||||||
// Use the first board directly
|
// Use the first board directly
|
||||||
@ -180,7 +193,10 @@ public class BoardColl extends Coll<Board> implements BoardInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enforce create
|
||||||
if (ret == null) ret = new MassiveMap<Faction, Set<PS>>();
|
if (ret == null) ret = new MassiveMap<Faction, Set<PS>>();
|
||||||
|
|
||||||
|
// Return
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,8 +266,7 @@ public class BoardColl extends Coll<Board> implements BoardInterface
|
|||||||
{
|
{
|
||||||
for (Board board : this.getAll())
|
for (Board board : this.getAll())
|
||||||
{
|
{
|
||||||
if ( ! board.hasClaimed(factionId)) continue;
|
if (board.hasClaimed(factionId)) return true;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -318,14 +333,16 @@ public class BoardColl extends Coll<Board> implements BoardInterface
|
|||||||
|
|
||||||
public Set<String> getClaimedWorlds(String factionId)
|
public Set<String> getClaimedWorlds(String factionId)
|
||||||
{
|
{
|
||||||
|
// Create
|
||||||
Set<String> ret = new MassiveSet<>();
|
Set<String> ret = new MassiveSet<>();
|
||||||
|
|
||||||
|
// Fill
|
||||||
for (Board board : this.getAll())
|
for (Board board : this.getAll())
|
||||||
{
|
{
|
||||||
if ( ! board.hasClaimed(factionId)) continue;
|
if (board.hasClaimed(factionId)) ret.add(board.getId());
|
||||||
ret.add(board.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,33 +353,35 @@ public class BoardColl extends Coll<Board> implements BoardInterface
|
|||||||
// Distance -1 returns 0 chunks always.
|
// Distance -1 returns 0 chunks always.
|
||||||
// Distance 0 returns 1 chunk only (the one supplied).
|
// Distance 0 returns 1 chunk only (the one supplied).
|
||||||
// Distance 1 returns 3x3 = 9 chunks.
|
// Distance 1 returns 3x3 = 9 chunks.
|
||||||
public static Set<PS> getNearbyChunks(PS chunk, int distance)
|
public static Set<PS> getNearbyChunks(PS psChunk, int distance)
|
||||||
{
|
{
|
||||||
// Fix Args
|
// Fix Args
|
||||||
if (chunk == null) throw new NullPointerException("chunk");
|
if (psChunk == null) throw new NullPointerException("psChunk");
|
||||||
chunk = chunk.getChunk(true);
|
psChunk = psChunk.getChunk(true);
|
||||||
|
|
||||||
// Create Ret
|
// Create
|
||||||
Set<PS> ret = new LinkedHashSet<PS>();
|
Set<PS> ret = new LinkedHashSet<PS>();
|
||||||
|
|
||||||
if (distance < 0) return ret;
|
if (distance < 0) return ret;
|
||||||
|
|
||||||
// Main
|
// Fill
|
||||||
int xmin = chunk.getChunkX() - distance;
|
int chunkX = psChunk.getChunkX();
|
||||||
int xmax = chunk.getChunkX() + distance;
|
int xmin = chunkX - distance;
|
||||||
|
int xmax = chunkX + distance;
|
||||||
|
|
||||||
int zmin = chunk.getChunkZ() - distance;
|
int chunkZ = psChunk.getChunkZ();
|
||||||
int zmax = chunk.getChunkZ() + distance;
|
int zmin = chunkZ - distance;
|
||||||
|
int zmax = chunkZ + distance;
|
||||||
|
|
||||||
for (int x = xmin; x <= xmax; x++)
|
for (int x = xmin; x <= xmax; x++)
|
||||||
{
|
{
|
||||||
|
PS psChunkX = psChunk.withChunkX(x);
|
||||||
for (int z = zmin; z <= zmax; z++)
|
for (int z = zmin; z <= zmax; z++)
|
||||||
{
|
{
|
||||||
ret.add(chunk.withChunkX(x).withChunkZ(z));
|
ret.add(psChunkX.withChunkZ(z));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return Ret
|
// Return
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,18 +390,18 @@ public class BoardColl extends Coll<Board> implements BoardInterface
|
|||||||
// Fix Args
|
// Fix Args
|
||||||
if (chunks == null) throw new NullPointerException("chunks");
|
if (chunks == null) throw new NullPointerException("chunks");
|
||||||
|
|
||||||
// Create Ret
|
// Create
|
||||||
Set<PS> ret = new LinkedHashSet<PS>();
|
Set<PS> ret = new LinkedHashSet<PS>();
|
||||||
|
|
||||||
if (distance < 0) return ret;
|
if (distance < 0) return ret;
|
||||||
|
|
||||||
// Main
|
// Fill
|
||||||
for (PS chunk : chunks)
|
for (PS chunk : chunks)
|
||||||
{
|
{
|
||||||
ret.addAll(getNearbyChunks(chunk, distance));
|
ret.addAll(getNearbyChunks(chunk, distance));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return Ret
|
// Return
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -391,33 +410,37 @@ public class BoardColl extends Coll<Board> implements BoardInterface
|
|||||||
// Fix Args
|
// Fix Args
|
||||||
if (chunks == null) throw new NullPointerException("chunks");
|
if (chunks == null) throw new NullPointerException("chunks");
|
||||||
|
|
||||||
// Create Ret
|
// Create
|
||||||
Set<Faction> ret = new LinkedHashSet<Faction>();
|
Set<Faction> ret = new LinkedHashSet<Faction>();
|
||||||
|
|
||||||
// Main
|
// Fill
|
||||||
for (PS chunk : chunks)
|
for (PS chunk : chunks)
|
||||||
{
|
{
|
||||||
Faction faction = BoardColl.get().getFactionAt(chunk);
|
Faction faction = get().getFactionAt(chunk);
|
||||||
if (faction == null) continue;
|
if (faction == null) continue;
|
||||||
ret.add(faction);
|
ret.add(faction);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return Ret
|
// Return
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<PS, Faction> getChunkFaction(Collection<PS> chunks)
|
public static Map<PS, Faction> getChunkFaction(Collection<PS> chunks)
|
||||||
{
|
{
|
||||||
|
// Create
|
||||||
Map<PS, Faction> ret = new LinkedHashMap<PS, Faction>();
|
Map<PS, Faction> ret = new LinkedHashMap<PS, Faction>();
|
||||||
|
|
||||||
|
// Fill
|
||||||
|
Faction none = FactionColl.get().getNone();
|
||||||
for (PS chunk : chunks)
|
for (PS chunk : chunks)
|
||||||
{
|
{
|
||||||
chunk = chunk.getChunk(true);
|
chunk = chunk.getChunk(true);
|
||||||
Faction faction = get().getFactionAt(chunk);
|
Faction faction = get().getFactionAt(chunk);
|
||||||
if (faction == null) faction = FactionColl.get().getNone();
|
if (faction == null) faction = none;
|
||||||
ret.put(chunk, faction);
|
ret.put(chunk, faction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,18 @@
|
|||||||
package com.massivecraft.factions.entity;
|
package com.massivecraft.factions.entity;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import com.massivecraft.massivecore.store.Coll;
|
|
||||||
import com.massivecraft.massivecore.util.Txt;
|
|
||||||
import com.massivecraft.factions.Factions;
|
import com.massivecraft.factions.Factions;
|
||||||
import com.massivecraft.factions.Rel;
|
import com.massivecraft.factions.Rel;
|
||||||
import com.massivecraft.factions.integration.Econ;
|
import com.massivecraft.factions.integration.Econ;
|
||||||
import com.massivecraft.factions.util.MiscUtil;
|
import com.massivecraft.factions.util.MiscUtil;
|
||||||
|
import com.massivecraft.massivecore.store.Coll;
|
||||||
|
import com.massivecraft.massivecore.util.Txt;
|
||||||
|
|
||||||
public class FactionColl extends Coll<Faction>
|
public class FactionColl extends Coll<Faction>
|
||||||
{
|
{
|
||||||
@ -37,7 +42,7 @@ public class FactionColl extends Coll<Faction>
|
|||||||
{
|
{
|
||||||
super.setActive(active);
|
super.setActive(active);
|
||||||
|
|
||||||
if ( ! active) return;
|
if (!active) return;
|
||||||
|
|
||||||
this.createSpecialFactions();
|
this.createSpecialFactions();
|
||||||
}
|
}
|
||||||
@ -197,25 +202,40 @@ public class FactionColl extends Coll<Faction>
|
|||||||
|
|
||||||
public void econLandRewardRoutine()
|
public void econLandRewardRoutine()
|
||||||
{
|
{
|
||||||
|
// If econ is enabled ...
|
||||||
if (!Econ.isEnabled()) return;
|
if (!Econ.isEnabled()) return;
|
||||||
|
|
||||||
|
// ... and the land reward is non zero ...
|
||||||
double econLandReward = MConf.get().econLandReward;
|
double econLandReward = MConf.get().econLandReward;
|
||||||
if (econLandReward == 0.0) return;
|
if (econLandReward == 0.0) return;
|
||||||
|
|
||||||
|
// ... log initiation ...
|
||||||
Factions.get().log("Running econLandRewardRoutine...");
|
Factions.get().log("Running econLandRewardRoutine...");
|
||||||
|
MFlag flagPeaceful = MFlag.getFlagPeaceful();
|
||||||
|
|
||||||
|
// ... and for each faction ...
|
||||||
for (Faction faction : this.getAll())
|
for (Faction faction : this.getAll())
|
||||||
{
|
{
|
||||||
|
// ... get the land count ...
|
||||||
int landCount = faction.getLandCount();
|
int landCount = faction.getLandCount();
|
||||||
if (!faction.getFlag(MFlag.getFlagPeaceful()) && landCount > 0)
|
|
||||||
{
|
// ... and if the faction isn't peaceful and has land ...
|
||||||
|
if (faction.getFlag(flagPeaceful) || landCount > 0) continue;
|
||||||
|
|
||||||
|
// ... get the faction's members ...
|
||||||
List<MPlayer> players = faction.getMPlayers();
|
List<MPlayer> players = faction.getMPlayers();
|
||||||
|
|
||||||
|
// ... calculate the reward ...
|
||||||
int playerCount = players.size();
|
int playerCount = players.size();
|
||||||
double reward = econLandReward * landCount / playerCount;
|
double reward = econLandReward * landCount / playerCount;
|
||||||
|
|
||||||
|
// ... and grant the reward.
|
||||||
|
String description = String.format("own %s faction land divided among %s members", landCount, playerCount);
|
||||||
for (MPlayer player : players)
|
for (MPlayer player : players)
|
||||||
{
|
{
|
||||||
Econ.modifyMoney(player, reward, "own " + landCount + " faction land divided among " + playerCount + " members");
|
Econ.modifyMoney(player, reward, description);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,26 +245,32 @@ public class FactionColl extends Coll<Faction>
|
|||||||
|
|
||||||
public ArrayList<String> validateName(String str)
|
public ArrayList<String> validateName(String str)
|
||||||
{
|
{
|
||||||
|
// Create
|
||||||
ArrayList<String> errors = new ArrayList<String>();
|
ArrayList<String> errors = new ArrayList<String>();
|
||||||
|
|
||||||
|
// Fill
|
||||||
|
// Check minimum length
|
||||||
if (MiscUtil.getComparisonString(str).length() < MConf.get().factionNameLengthMin)
|
if (MiscUtil.getComparisonString(str).length() < MConf.get().factionNameLengthMin)
|
||||||
{
|
{
|
||||||
errors.add(Txt.parse("<i>The faction name can't be shorter than <h>%s<i> chars.", MConf.get().factionNameLengthMin));
|
errors.add(Txt.parse("<i>The faction name can't be shorter than <h>%s<i> chars.", MConf.get().factionNameLengthMin));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check maximum length
|
||||||
if (str.length() > MConf.get().factionNameLengthMax)
|
if (str.length() > MConf.get().factionNameLengthMax)
|
||||||
{
|
{
|
||||||
errors.add(Txt.parse("<i>The faction name can't be longer than <h>%s<i> chars.", MConf.get().factionNameLengthMax));
|
errors.add(Txt.parse("<i>The faction name can't be longer than <h>%s<i> chars.", MConf.get().factionNameLengthMax));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check characters used
|
||||||
for (char c : str.toCharArray())
|
for (char c : str.toCharArray())
|
||||||
{
|
{
|
||||||
if ( ! MiscUtil.substanceChars.contains(String.valueOf(c)))
|
if (!MiscUtil.substanceChars.contains(String.valueOf(c)))
|
||||||
{
|
{
|
||||||
errors.add(Txt.parse("<i>Faction name must be alphanumeric. \"<h>%s<i>\" is not allowed.", c));
|
errors.add(Txt.parse("<i>Faction name must be alphanumeric. \"<h>%s<i>\" is not allowed.", c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return
|
||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,7 +296,8 @@ public class FactionColl extends Coll<Faction>
|
|||||||
{
|
{
|
||||||
// Create
|
// Create
|
||||||
Map<Rel, List<String>> ret = new LinkedHashMap<Rel, List<String>>();
|
Map<Rel, List<String>> ret = new LinkedHashMap<Rel, List<String>>();
|
||||||
boolean peaceful = faction.getFlag(MFlag.getFlagPeaceful());
|
MFlag flagPeaceful = MFlag.getFlagPeaceful();
|
||||||
|
boolean peaceful = faction.getFlag(flagPeaceful);
|
||||||
for (Rel rel : rels)
|
for (Rel rel : rels)
|
||||||
{
|
{
|
||||||
ret.put(rel, new ArrayList<String>());
|
ret.put(rel, new ArrayList<String>());
|
||||||
@ -279,7 +306,7 @@ public class FactionColl extends Coll<Faction>
|
|||||||
// Fill
|
// Fill
|
||||||
for (Faction fac : FactionColl.get().getAll())
|
for (Faction fac : FactionColl.get().getAll())
|
||||||
{
|
{
|
||||||
if (fac.getFlag(MFlag.getFlagPeaceful())) continue;
|
if (fac.getFlag(flagPeaceful)) continue;
|
||||||
|
|
||||||
Rel rel = fac.getRelationTo(faction);
|
Rel rel = fac.getRelationTo(faction);
|
||||||
List<String> names = ret.get(rel);
|
List<String> names = ret.get(rel);
|
||||||
@ -289,8 +316,8 @@ public class FactionColl extends Coll<Faction>
|
|||||||
names.add(name);
|
names.add(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace TRUCE if peasceful
|
// Replace TRUCE if peaceful
|
||||||
if ( ! peaceful) return ret;
|
if (!peaceful) return ret;
|
||||||
|
|
||||||
List<String> names = ret.get(Rel.TRUCE);
|
List<String> names = ret.get(Rel.TRUCE);
|
||||||
if (names == null) return ret;
|
if (names == null) return ret;
|
||||||
|
@ -30,7 +30,7 @@ public class MConfColl extends Coll<MConf>
|
|||||||
public void setActive(boolean active)
|
public void setActive(boolean active)
|
||||||
{
|
{
|
||||||
super.setActive(active);
|
super.setActive(active);
|
||||||
if ( ! active) return;
|
if (!active) return;
|
||||||
MConf.i = this.get(MassiveCore.INSTANCE, true);
|
MConf.i = this.get(MassiveCore.INSTANCE, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ public class MFlagColl extends Coll<MFlag>
|
|||||||
public void setActive(boolean active)
|
public void setActive(boolean active)
|
||||||
{
|
{
|
||||||
super.setActive(active);
|
super.setActive(active);
|
||||||
if ( ! active) return;
|
if (!active) return;
|
||||||
MFlag.setupStandardFlags();
|
MFlag.setupStandardFlags();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,12 +46,17 @@ public class MFlagColl extends Coll<MFlag>
|
|||||||
|
|
||||||
public List<MFlag> getAll(boolean registered)
|
public List<MFlag> getAll(boolean registered)
|
||||||
{
|
{
|
||||||
|
// Create
|
||||||
List<MFlag> ret = new ArrayList<MFlag>();
|
List<MFlag> ret = new ArrayList<MFlag>();
|
||||||
|
|
||||||
|
// Fill
|
||||||
for (MFlag mflag : this.getAll())
|
for (MFlag mflag : this.getAll())
|
||||||
{
|
{
|
||||||
if (mflag.isRegistered() != registered) continue;
|
if (mflag.isRegistered() != registered) continue;
|
||||||
ret.add(mflag);
|
ret.add(mflag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ public class MPermColl extends Coll<MPerm>
|
|||||||
public void setActive(boolean active)
|
public void setActive(boolean active)
|
||||||
{
|
{
|
||||||
super.setActive(active);
|
super.setActive(active);
|
||||||
if ( ! active) return;
|
if (!active) return;
|
||||||
MPerm.setupStandardPerms();
|
MPerm.setupStandardPerms();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,12 +46,17 @@ public class MPermColl extends Coll<MPerm>
|
|||||||
|
|
||||||
public List<MPerm> getAll(boolean registered)
|
public List<MPerm> getAll(boolean registered)
|
||||||
{
|
{
|
||||||
|
// Create
|
||||||
List<MPerm> ret = new ArrayList<MPerm>();
|
List<MPerm> ret = new ArrayList<MPerm>();
|
||||||
|
|
||||||
|
// Fill
|
||||||
for (MPerm mperm : this.getAll())
|
for (MPerm mperm : this.getAll())
|
||||||
{
|
{
|
||||||
if (mperm.isRegistered() != registered) continue;
|
if (mperm.isRegistered() != registered) continue;
|
||||||
ret.add(mperm);
|
ret.add(mperm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,13 +85,17 @@ public class MPlayerColl extends SenderColl<MPlayer>
|
|||||||
|
|
||||||
public void clean()
|
public void clean()
|
||||||
{
|
{
|
||||||
|
// For each player ...
|
||||||
for (MPlayer mplayer : this.getAll())
|
for (MPlayer mplayer : this.getAll())
|
||||||
{
|
{
|
||||||
|
// ... who doesn't have a valid faction ...
|
||||||
String factionId = mplayer.getFactionId();
|
String factionId = mplayer.getFactionId();
|
||||||
if (FactionColl.get().containsId(factionId)) continue;
|
if (FactionColl.get().containsId(factionId)) continue;
|
||||||
|
|
||||||
|
// ... reset their faction data ...
|
||||||
mplayer.resetFactionData();
|
mplayer.resetFactionData();
|
||||||
|
|
||||||
|
// ... and log.
|
||||||
String message = Txt.parse("<i>Reset data for <h>%s <i>. Unknown factionId <h>%s", mplayer.getDisplayName(IdUtil.getConsole()), factionId);
|
String message = Txt.parse("<i>Reset data for <h>%s <i>. Unknown factionId <h>%s", mplayer.getDisplayName(IdUtil.getConsole()), factionId);
|
||||||
Factions.get().log(message);
|
Factions.get().log(message);
|
||||||
}
|
}
|
||||||
@ -112,8 +116,10 @@ public class MPlayerColl extends SenderColl<MPlayer>
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
|
// For each offline player ...
|
||||||
for (MPlayer mplayer : mplayersOffline)
|
for (MPlayer mplayer : mplayersOffline)
|
||||||
{
|
{
|
||||||
|
// ... see if they should be removed.
|
||||||
mplayer.considerRemovePlayerMillis(true);
|
mplayer.considerRemovePlayerMillis(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user