Step 1 in many removing the universe system. Untested and lacking auto convert features.
This commit is contained in:
@@ -32,7 +32,7 @@ public class Board extends Entity<Board> implements BoardInterface
|
||||
|
||||
public static Board get(Object oid)
|
||||
{
|
||||
return BoardColls.get().get2(oid);
|
||||
return BoardColl.get().get(oid);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@@ -90,7 +90,7 @@ public class Board extends Entity<Board> implements BoardInterface
|
||||
if (ps == null) return null;
|
||||
ps = ps.getChunkCoords(true);
|
||||
TerritoryAccess ret = this.map.get(ps);
|
||||
if (ret == null) ret = TerritoryAccess.valueOf(UConf.get(this).factionIdNone);
|
||||
if (ret == null) ret = TerritoryAccess.valueOf(MConf.get().factionIdNone);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ public class Board extends Entity<Board> implements BoardInterface
|
||||
{
|
||||
ps = ps.getChunkCoords(true);
|
||||
|
||||
if (territoryAccess == null || (territoryAccess.getHostFactionId().equals(UConf.get(this).factionIdNone) && territoryAccess.isDefault()))
|
||||
if (territoryAccess == null || (territoryAccess.getHostFactionId().equals(MConf.get().factionIdNone) && territoryAccess.isDefault()))
|
||||
{
|
||||
this.map.remove(ps);
|
||||
}
|
||||
@@ -159,13 +159,12 @@ public class Board extends Entity<Board> implements BoardInterface
|
||||
@Override
|
||||
public void clean()
|
||||
{
|
||||
FactionColl factionColl = FactionColls.get().get(this);
|
||||
|
||||
for (Entry<PS, TerritoryAccess> entry : this.map.entrySet())
|
||||
{
|
||||
TerritoryAccess territoryAccess = entry.getValue();
|
||||
String factionId = territoryAccess.getHostFactionId();
|
||||
if (factionColl.containsId(factionId)) continue;
|
||||
|
||||
if (FactionColl.get().containsId(factionId)) continue;
|
||||
|
||||
PS ps = entry.getKey();
|
||||
this.removeAt(ps);
|
||||
|
@@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.massivecraft.factions.Const;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.RelationParticipator;
|
||||
import com.massivecraft.factions.TerritoryAccess;
|
||||
@@ -15,12 +16,14 @@ import com.massivecraft.massivecore.util.MUtil;
|
||||
public class BoardColl extends Coll<Board> implements BoardInterface
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public BoardColl(String name)
|
||||
private static BoardColl i = new BoardColl();
|
||||
public static BoardColl get() { return i; }
|
||||
private BoardColl()
|
||||
{
|
||||
super(name, Board.class, MStore.getDb(), Factions.get(), false, true, true);
|
||||
super(Const.COLLECTION_BOARD, Board.class, MStore.getDb(), Factions.get(), false, true, true);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@@ -165,4 +168,51 @@ public class BoardColl extends Coll<Board> implements BoardInterface
|
||||
return board.getMap(observer, centerPs, inDegrees);
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
super.init();
|
||||
|
||||
this.migrate();
|
||||
}
|
||||
|
||||
// This method is for the 1.8.X --> 2.0.0 migration
|
||||
public void migrate()
|
||||
{
|
||||
// Create file objects
|
||||
File oldFile = new File(Factions.get().getDataFolder(), "board.json");
|
||||
File newFile = new File(Factions.get().getDataFolder(), "board.json.migrated");
|
||||
|
||||
// Already migrated?
|
||||
if ( ! oldFile.exists()) return;
|
||||
|
||||
// Read the file content through GSON.
|
||||
Type type = new TypeToken<Map<String,Map<String,TerritoryAccess>>>(){}.getType();
|
||||
Map<String,Map<String,TerritoryAccess>> worldCoordIds = Factions.get().gson.fromJson(DiscUtil.readCatch(oldFile), type);
|
||||
|
||||
// Set the data
|
||||
for (Entry<String,Map<String,TerritoryAccess>> entry : worldCoordIds.entrySet())
|
||||
{
|
||||
String worldName = entry.getKey();
|
||||
BoardColl boardColl = this.getForWorld(worldName);
|
||||
Board board = boardColl.get(worldName);
|
||||
for (Entry<String,TerritoryAccess> entry2 : entry.getValue().entrySet())
|
||||
{
|
||||
String[] ChunkCoordParts = entry2.getKey().trim().split("[,\\s]+");
|
||||
int chunkX = Integer.parseInt(ChunkCoordParts[0]);
|
||||
int chunkZ = Integer.parseInt(ChunkCoordParts[1]);
|
||||
PS ps = new PSBuilder().chunkX(chunkX).chunkZ(chunkZ).build();
|
||||
|
||||
TerritoryAccess territoryAccess = entry2.getValue();
|
||||
|
||||
board.setTerritoryAccessAt(ps, territoryAccess);
|
||||
}
|
||||
}
|
||||
|
||||
// Mark as migrated
|
||||
oldFile.renameTo(newFile);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
@@ -1,215 +0,0 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.massivecraft.factions.Const;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.RelationParticipator;
|
||||
import com.massivecraft.factions.TerritoryAccess;
|
||||
import com.massivecraft.massivecore.Aspect;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.ps.PSBuilder;
|
||||
import com.massivecraft.massivecore.util.DiscUtil;
|
||||
import com.massivecraft.massivecore.xlib.gson.reflect.TypeToken;
|
||||
|
||||
public class BoardColls extends XColls<BoardColl, Board> implements BoardInterface
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static BoardColls i = new BoardColls();
|
||||
public static BoardColls get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: COLLS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public BoardColl createColl(String collName)
|
||||
{
|
||||
return new BoardColl(collName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Aspect getAspect()
|
||||
{
|
||||
return Factions.get().getAspect();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBasename()
|
||||
{
|
||||
return Const.COLLECTION_BOARD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
super.init();
|
||||
|
||||
this.migrate();
|
||||
}
|
||||
|
||||
// This method is for the 1.8.X --> 2.0.0 migration
|
||||
public void migrate()
|
||||
{
|
||||
// Create file objects
|
||||
File oldFile = new File(Factions.get().getDataFolder(), "board.json");
|
||||
File newFile = new File(Factions.get().getDataFolder(), "board.json.migrated");
|
||||
|
||||
// Already migrated?
|
||||
if ( ! oldFile.exists()) return;
|
||||
|
||||
// Read the file content through GSON.
|
||||
Type type = new TypeToken<Map<String,Map<String,TerritoryAccess>>>(){}.getType();
|
||||
Map<String,Map<String,TerritoryAccess>> worldCoordIds = Factions.get().gson.fromJson(DiscUtil.readCatch(oldFile), type);
|
||||
|
||||
// Set the data
|
||||
for (Entry<String,Map<String,TerritoryAccess>> entry : worldCoordIds.entrySet())
|
||||
{
|
||||
String worldName = entry.getKey();
|
||||
BoardColl boardColl = this.getForWorld(worldName);
|
||||
Board board = boardColl.get(worldName);
|
||||
for (Entry<String,TerritoryAccess> entry2 : entry.getValue().entrySet())
|
||||
{
|
||||
String[] ChunkCoordParts = entry2.getKey().trim().split("[,\\s]+");
|
||||
int chunkX = Integer.parseInt(ChunkCoordParts[0]);
|
||||
int chunkZ = Integer.parseInt(ChunkCoordParts[1]);
|
||||
PS ps = new PSBuilder().chunkX(chunkX).chunkZ(chunkZ).build();
|
||||
|
||||
TerritoryAccess territoryAccess = entry2.getValue();
|
||||
|
||||
board.setTerritoryAccessAt(ps, territoryAccess);
|
||||
}
|
||||
}
|
||||
|
||||
// Mark as migrated
|
||||
oldFile.renameTo(newFile);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: BOARD
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public TerritoryAccess getTerritoryAccessAt(PS ps)
|
||||
{
|
||||
BoardColl coll = this.getForWorld(ps.getWorld());
|
||||
if (coll == null) return null;
|
||||
return coll.getTerritoryAccessAt(ps);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Faction getFactionAt(PS ps)
|
||||
{
|
||||
BoardColl coll = this.getForWorld(ps.getWorld());
|
||||
if (coll == null) return null;
|
||||
return coll.getFactionAt(ps);
|
||||
}
|
||||
|
||||
// SET
|
||||
|
||||
@Override
|
||||
public void setTerritoryAccessAt(PS ps, TerritoryAccess territoryAccess)
|
||||
{
|
||||
BoardColl coll = this.getForWorld(ps.getWorld());
|
||||
if (coll == null) return;
|
||||
coll.setTerritoryAccessAt(ps, territoryAccess);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFactionAt(PS ps, Faction faction)
|
||||
{
|
||||
BoardColl coll = this.getForWorld(ps.getWorld());
|
||||
if (coll == null) return;
|
||||
coll.setFactionAt(ps, faction);
|
||||
}
|
||||
|
||||
// REMOVE
|
||||
|
||||
@Override
|
||||
public void removeAt(PS ps)
|
||||
{
|
||||
BoardColl coll = this.getForWorld(ps.getWorld());
|
||||
if (coll == null) return;
|
||||
coll.removeAt(ps);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAll(Faction faction)
|
||||
{
|
||||
for (BoardColl coll : this.getColls())
|
||||
{
|
||||
coll.removeAll(faction);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clean()
|
||||
{
|
||||
for (BoardColl coll : this.getColls())
|
||||
{
|
||||
coll.clean();
|
||||
}
|
||||
}
|
||||
|
||||
// CHUNKS
|
||||
@Override
|
||||
public Set<PS> getChunks(Faction faction)
|
||||
{
|
||||
Set<PS> ret = new HashSet<PS>();
|
||||
for (BoardColl coll : this.getColls())
|
||||
{
|
||||
ret.addAll(coll.getChunks(faction));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// COUNT
|
||||
@Override
|
||||
public int getCount(Faction faction)
|
||||
{
|
||||
int ret = 0;
|
||||
for (BoardColl coll : this.getColls())
|
||||
{
|
||||
ret += coll.getCount(faction);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// NEARBY DETECTION
|
||||
|
||||
@Override
|
||||
public boolean isBorderPs(PS ps)
|
||||
{
|
||||
BoardColl coll = this.getForWorld(ps.getWorld());
|
||||
if (coll == null) return false;
|
||||
return coll.isBorderPs(ps);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnectedPs(PS ps, Faction faction)
|
||||
{
|
||||
BoardColl coll = this.getForWorld(ps.getWorld());
|
||||
if (coll == null) return false;
|
||||
return coll.isConnectedPs(ps, faction);
|
||||
}
|
||||
|
||||
// MAP GENERATION
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getMap(RelationParticipator observer, PS centerPs, double inDegrees)
|
||||
{
|
||||
BoardColl coll = this.getForWorld(centerPs.getWorld());
|
||||
if (coll == null) return null;
|
||||
return coll.getMap(observer, centerPs, inDegrees);
|
||||
}
|
||||
|
||||
}
|
@@ -33,7 +33,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
|
||||
public static Faction get(Object oid)
|
||||
{
|
||||
return FactionColls.get().get2(oid);
|
||||
return FactionColl.get().get(oid);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@@ -62,13 +62,11 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
{
|
||||
Money.set(this, null, 0);
|
||||
|
||||
String universe = this.getUniverse();
|
||||
|
||||
// Clean the board
|
||||
BoardColls.get().getForUniverse(universe).clean();
|
||||
BoardColl.get().clean();
|
||||
|
||||
// Clean the uplayers
|
||||
UPlayerColls.get().getForUniverse(universe).clean();
|
||||
// Clean the mplayers
|
||||
MPlayerColl.get().clean();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@@ -132,7 +130,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
|
||||
public boolean isNone()
|
||||
{
|
||||
return this.getId().equals(UConf.get(this).factionIdNone);
|
||||
return this.getId().equals(MConf.get().factionIdNone);
|
||||
}
|
||||
|
||||
public boolean isNormal()
|
||||
@@ -150,8 +148,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
{
|
||||
String ret = this.name;
|
||||
|
||||
UConf uconf = UConf.get(this);
|
||||
if (uconf != null && UConf.get(this).factionNameForceUpperCase)
|
||||
if (MConf.get().factionNameForceUpperCase)
|
||||
{
|
||||
ret = ret.toUpperCase();
|
||||
}
|
||||
@@ -277,8 +274,8 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
public boolean isValidHome(PS ps)
|
||||
{
|
||||
if (ps == null) return true;
|
||||
if (!UConf.get(this).homesMustBeInClaimedTerritory) return true;
|
||||
if (BoardColls.get().getFactionAt(ps) == this) return true;
|
||||
if (!MConf.get().homesMustBeInClaimedTerritory) return true;
|
||||
if (BoardColl.get().getFactionAt(ps) == this) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -338,9 +335,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
|
||||
public boolean isDefaultOpen()
|
||||
{
|
||||
UConf uconf = UConf.get(this);
|
||||
if (uconf == null) return false;
|
||||
return uconf.defaultFactionOpen;
|
||||
return MConf.get().defaultFactionOpen;
|
||||
}
|
||||
|
||||
public boolean isOpen()
|
||||
@@ -412,7 +407,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
return this.getInvitedPlayerIds().contains(playerId);
|
||||
}
|
||||
|
||||
public boolean isInvited(UPlayer uplayer)
|
||||
public boolean isInvited(MPlayer uplayer)
|
||||
{
|
||||
return this.isInvited(uplayer.getId());
|
||||
}
|
||||
@@ -434,7 +429,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
|
||||
}
|
||||
|
||||
public void setInvited(UPlayer uplayer, boolean invited)
|
||||
public void setInvited(MPlayer uplayer, boolean invited)
|
||||
{
|
||||
this.setInvited(uplayer.getId(), invited);
|
||||
}
|
||||
@@ -523,7 +518,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
{
|
||||
ret.put(rel, new ArrayList<String>());
|
||||
}
|
||||
for (Faction faction : FactionColls.get().get(this).getAll())
|
||||
for (Faction faction : FactionColl.get().getAll())
|
||||
{
|
||||
Rel relation = faction.getRelationTo(this);
|
||||
if (onlyNonNeutral && relation == Rel.NEUTRAL) continue;
|
||||
@@ -544,7 +539,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
|
||||
for (FFlag fflag : FFlag.values())
|
||||
{
|
||||
ret.put(fflag, fflag.getDefault(this));
|
||||
ret.put(fflag, fflag.getDefault());
|
||||
}
|
||||
|
||||
if (this.flags != null)
|
||||
@@ -576,7 +571,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
while (iter.hasNext())
|
||||
{
|
||||
Entry<FFlag, Boolean> entry = iter.next();
|
||||
if (entry.getKey().getDefault(this) == entry.getValue())
|
||||
if (entry.getKey().getDefault() == entry.getValue())
|
||||
{
|
||||
iter.remove();
|
||||
}
|
||||
@@ -621,7 +616,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
|
||||
for (FPerm fperm : FPerm.values())
|
||||
{
|
||||
ret.put(fperm, fperm.getDefault(this));
|
||||
ret.put(fperm, fperm.getDefault());
|
||||
}
|
||||
|
||||
if (this.perms != null)
|
||||
@@ -667,7 +662,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
continue;
|
||||
}
|
||||
|
||||
Set<Rel> keyDefault = key.getDefault(this);
|
||||
Set<Rel> keyDefault = key.getDefault();
|
||||
Set<Rel> value = entry.getValue();
|
||||
|
||||
if (keyDefault.equals(value))
|
||||
@@ -779,12 +774,12 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
if (this.getFlag(FFlag.INFPOWER)) return 999999;
|
||||
|
||||
double ret = 0;
|
||||
for (UPlayer uplayer : this.getUPlayers())
|
||||
for (MPlayer uplayer : this.getUPlayers())
|
||||
{
|
||||
ret += uplayer.getPower();
|
||||
}
|
||||
|
||||
double factionPowerMax = UConf.get(this).factionPowerMax;
|
||||
double factionPowerMax = MConf.get().factionPowerMax;
|
||||
if (factionPowerMax > 0 && ret > factionPowerMax)
|
||||
{
|
||||
ret = factionPowerMax;
|
||||
@@ -800,12 +795,12 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
if (this.getFlag(FFlag.INFPOWER)) return 999999;
|
||||
|
||||
double ret = 0;
|
||||
for (UPlayer uplayer : this.getUPlayers())
|
||||
for (MPlayer uplayer : this.getUPlayers())
|
||||
{
|
||||
ret += uplayer.getPowerMax();
|
||||
}
|
||||
|
||||
double factionPowerMax = UConf.get(this).factionPowerMax;
|
||||
double factionPowerMax = MConf.get().factionPowerMax;
|
||||
if (factionPowerMax > 0 && ret > factionPowerMax)
|
||||
{
|
||||
ret = factionPowerMax;
|
||||
@@ -828,7 +823,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
|
||||
public int getLandCount()
|
||||
{
|
||||
return BoardColls.get().get(this).getCount(this);
|
||||
return BoardColl.get().getCount(this);
|
||||
}
|
||||
public int getLandCountInWorld(String worldName)
|
||||
{
|
||||
@@ -844,7 +839,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
// FOREIGN KEY: UPLAYER
|
||||
// -------------------------------------------- //
|
||||
|
||||
protected transient List<UPlayer> uplayers = new ArrayList<UPlayer>();
|
||||
protected transient List<MPlayer> uplayers = new ArrayList<MPlayer>();
|
||||
public void reindexUPlayers()
|
||||
{
|
||||
this.uplayers.clear();
|
||||
@@ -852,10 +847,10 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
String factionId = this.getId();
|
||||
if (factionId == null) return;
|
||||
|
||||
for (UPlayer uplayer : UPlayerColls.get().get(this).getAll())
|
||||
for (MPlayer mplayer : MPlayerColl.get().getAll())
|
||||
{
|
||||
if (!MUtil.equals(factionId, uplayer.getFactionId())) continue;
|
||||
this.uplayers.add(uplayer);
|
||||
if (!MUtil.equals(factionId, mplayer.getFactionId())) continue;
|
||||
this.uplayers.add(mplayer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -863,10 +858,10 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
// TODO: Find the bug causing non-attached UPlayers to be present in the index.
|
||||
private void checkUPlayerIndex()
|
||||
{
|
||||
Iterator<UPlayer> iter = this.uplayers.iterator();
|
||||
Iterator<MPlayer> iter = this.uplayers.iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
UPlayer uplayer = iter.next();
|
||||
MPlayer uplayer = iter.next();
|
||||
if (!uplayer.attached())
|
||||
{
|
||||
String msg = Txt.parse("<rose>WARN: <i>Faction <h>%s <i>aka <h>%s <i>had unattached uplayer in index:", this.getName(), this.getId());
|
||||
@@ -877,19 +872,19 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
}
|
||||
}
|
||||
|
||||
public List<UPlayer> getUPlayers()
|
||||
public List<MPlayer> getUPlayers()
|
||||
{
|
||||
this.checkUPlayerIndex();
|
||||
return new ArrayList<UPlayer>(this.uplayers);
|
||||
return new ArrayList<MPlayer>(this.uplayers);
|
||||
}
|
||||
|
||||
public List<UPlayer> getUPlayersWhereOnline(boolean online)
|
||||
public List<MPlayer> getUPlayersWhereOnline(boolean online)
|
||||
{
|
||||
List<UPlayer> ret = this.getUPlayers();
|
||||
Iterator<UPlayer> iter = ret.iterator();
|
||||
List<MPlayer> ret = this.getUPlayers();
|
||||
Iterator<MPlayer> iter = ret.iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
UPlayer uplayer = iter.next();
|
||||
MPlayer uplayer = iter.next();
|
||||
if (uplayer.isOnline() != online)
|
||||
{
|
||||
iter.remove();
|
||||
@@ -898,13 +893,13 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<UPlayer> getUPlayersWhereRole(Rel role)
|
||||
public List<MPlayer> getUPlayersWhereRole(Rel role)
|
||||
{
|
||||
List<UPlayer> ret = this.getUPlayers();
|
||||
Iterator<UPlayer> iter = ret.iterator();
|
||||
List<MPlayer> ret = this.getUPlayers();
|
||||
Iterator<MPlayer> iter = ret.iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
UPlayer uplayer = iter.next();
|
||||
MPlayer uplayer = iter.next();
|
||||
if (uplayer.getRole() != role)
|
||||
{
|
||||
iter.remove();
|
||||
@@ -913,13 +908,13 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
return ret;
|
||||
}
|
||||
|
||||
public UPlayer getLeader()
|
||||
public MPlayer getLeader()
|
||||
{
|
||||
List<UPlayer> ret = this.getUPlayers();
|
||||
Iterator<UPlayer> iter = ret.iterator();
|
||||
List<MPlayer> ret = this.getUPlayers();
|
||||
Iterator<MPlayer> iter = ret.iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
UPlayer uplayer = iter.next();
|
||||
MPlayer uplayer = iter.next();
|
||||
if (uplayer.getRole() == Rel.LEADER)
|
||||
{
|
||||
return uplayer;
|
||||
@@ -933,7 +928,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
List<CommandSender> ret = new ArrayList<CommandSender>();
|
||||
for (CommandSender player : IdUtil.getOnlineSenders())
|
||||
{
|
||||
UPlayer uplayer = UPlayer.get(player);
|
||||
MPlayer uplayer = MPlayer.get(player);
|
||||
if (!MUtil.equals(uplayer.getUniverse(), this.getUniverse())) continue;
|
||||
if (uplayer.getFaction() != this) continue;
|
||||
ret.add(player);
|
||||
@@ -946,7 +941,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
List<Player> ret = new ArrayList<Player>();
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
UPlayer uplayer = UPlayer.get(player);
|
||||
MPlayer uplayer = MPlayer.get(player);
|
||||
if (!MUtil.equals(uplayer.getUniverse(), this.getUniverse())) continue;
|
||||
if (uplayer.getFaction() != this) continue;
|
||||
ret.add(player);
|
||||
@@ -958,12 +953,12 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
public void promoteNewLeader()
|
||||
{
|
||||
if ( ! this.isNormal()) return;
|
||||
if (this.getFlag(FFlag.PERMANENT) && UConf.get(this).permanentFactionsDisableLeaderPromotion) return;
|
||||
if (this.getFlag(FFlag.PERMANENT) && MConf.get().permanentFactionsDisableLeaderPromotion) return;
|
||||
|
||||
UPlayer oldLeader = this.getLeader();
|
||||
MPlayer oldLeader = this.getLeader();
|
||||
|
||||
// get list of officers, or list of normal members if there are no officers
|
||||
List<UPlayer> replacements = this.getUPlayersWhereRole(Rel.OFFICER);
|
||||
List<MPlayer> replacements = this.getUPlayersWhereRole(Rel.OFFICER);
|
||||
if (replacements == null || replacements.isEmpty())
|
||||
{
|
||||
replacements = this.getUPlayersWhereRole(Rel.MEMBER);
|
||||
@@ -988,9 +983,9 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
|
||||
Factions.get().log("The faction "+this.getName()+" ("+this.getId()+") has been disbanded since it has no members left.");
|
||||
}
|
||||
|
||||
for (UPlayer uplayer : UPlayerColls.get().get(this).getAllOnline())
|
||||
for (MPlayer mplayer : MPlayerColl.get().getAllOnline())
|
||||
{
|
||||
uplayer.msg("<i>The faction %s<i> was disbanded.", this.getName(uplayer));
|
||||
mplayer.msg("<i>The faction %s<i> was disbanded.", this.getName(mplayer));
|
||||
}
|
||||
|
||||
this.detach();
|
||||
|
@@ -7,6 +7,7 @@ import org.bukkit.ChatColor;
|
||||
import com.massivecraft.massivecore.store.Coll;
|
||||
import com.massivecraft.massivecore.store.MStore;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
import com.massivecraft.factions.Const;
|
||||
import com.massivecraft.factions.FFlag;
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Factions;
|
||||
@@ -17,12 +18,14 @@ import com.massivecraft.factions.util.MiscUtil;
|
||||
public class FactionColl extends Coll<Faction>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public FactionColl(String name)
|
||||
private static FactionColl i = new FactionColl();
|
||||
public static FactionColl get() { return i; }
|
||||
private FactionColl()
|
||||
{
|
||||
super(name, Faction.class, MStore.getDb(), Factions.get());
|
||||
super(Const.COLLECTION_FACTION, Faction.class, MStore.getDb(), Factions.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@@ -50,8 +53,8 @@ public class FactionColl extends Coll<Faction>
|
||||
String message = Txt.parse("<b>Non existing factionId <h>%s <b>requested. <i>Cleaning all boards and uplayers.", this.fixId(oid));
|
||||
Factions.get().log(message);
|
||||
|
||||
BoardColls.get().clean();
|
||||
UPlayerColls.get().clean();
|
||||
BoardColl.get().clean();
|
||||
MPlayerColl.get().clean();
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -82,7 +85,7 @@ public class FactionColl extends Coll<Faction>
|
||||
|
||||
public Faction getNone()
|
||||
{
|
||||
String id = UConf.get(this).factionIdNone;
|
||||
String id = MConf.get().factionIdNone;
|
||||
Faction faction = this.get(id);
|
||||
if (faction != null) return faction;
|
||||
|
||||
@@ -115,7 +118,7 @@ public class FactionColl extends Coll<Faction>
|
||||
|
||||
public Faction getSafezone()
|
||||
{
|
||||
String id = UConf.get(this).factionIdSafezone;
|
||||
String id = MConf.get().factionIdSafezone;
|
||||
Faction faction = this.get(id);
|
||||
if (faction != null) return faction;
|
||||
|
||||
@@ -148,7 +151,7 @@ public class FactionColl extends Coll<Faction>
|
||||
|
||||
public Faction getWarzone()
|
||||
{
|
||||
String id = UConf.get(this).factionIdWarzone;
|
||||
String id = MConf.get().factionIdWarzone;
|
||||
Faction faction = this.get(id);
|
||||
if (faction != null) return faction;
|
||||
|
||||
@@ -185,9 +188,9 @@ public class FactionColl extends Coll<Faction>
|
||||
|
||||
public void econLandRewardRoutine()
|
||||
{
|
||||
if (!Econ.isEnabled(this.getUniverse())) return;
|
||||
if (!Econ.isEnabled()) return;
|
||||
|
||||
double econLandReward = UConf.get(this).econLandReward;
|
||||
double econLandReward = MConf.get().econLandReward;
|
||||
if (econLandReward == 0.0) return;
|
||||
|
||||
Factions.get().log("Running econLandRewardRoutine...");
|
||||
@@ -196,10 +199,10 @@ public class FactionColl extends Coll<Faction>
|
||||
int landCount = faction.getLandCount();
|
||||
if (!faction.getFlag(FFlag.PEACEFUL) && landCount > 0)
|
||||
{
|
||||
List<UPlayer> players = faction.getUPlayers();
|
||||
List<MPlayer> players = faction.getUPlayers();
|
||||
int playerCount = players.size();
|
||||
double reward = econLandReward * landCount / playerCount;
|
||||
for (UPlayer player : players)
|
||||
for (MPlayer player : players)
|
||||
{
|
||||
Econ.modifyMoney(player, reward, "own " + landCount + " faction land divided among " + playerCount + " members");
|
||||
}
|
||||
@@ -215,14 +218,14 @@ public class FactionColl extends Coll<Faction>
|
||||
{
|
||||
ArrayList<String> errors = new ArrayList<String>();
|
||||
|
||||
if (MiscUtil.getComparisonString(str).length() < UConf.get(this).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.", UConf.get(this).factionNameLengthMin));
|
||||
errors.add(Txt.parse("<i>The faction name can't be shorter than <h>%s<i> chars.", MConf.get().factionNameLengthMin));
|
||||
}
|
||||
|
||||
if (str.length() > UConf.get(this).factionNameLengthMax)
|
||||
if (str.length() > MConf.get().factionNameLengthMax)
|
||||
{
|
||||
errors.add(Txt.parse("<i>The faction name can't be longer than <h>%s<i> chars.", UConf.get(this).factionNameLengthMax));
|
||||
errors.add(Txt.parse("<i>The faction name can't be longer than <h>%s<i> chars.", MConf.get().factionNameLengthMax));
|
||||
}
|
||||
|
||||
for (char c : str.toCharArray())
|
||||
@@ -268,5 +271,62 @@ public class FactionColl extends Coll<Faction>
|
||||
{
|
||||
return this.getByName(str) != null;
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
super.init();
|
||||
|
||||
this.migrate();
|
||||
}
|
||||
|
||||
// This method is for the 1.8.X --> 2.0.0 migration
|
||||
public void migrate()
|
||||
{
|
||||
// Create file objects
|
||||
File oldFile = new File(Factions.get().getDataFolder(), "factions.json");
|
||||
File newFile = new File(Factions.get().getDataFolder(), "factions.json.migrated");
|
||||
|
||||
// Already migrated?
|
||||
if ( ! oldFile.exists()) return;
|
||||
|
||||
// Faction ids /delete
|
||||
// For simplicity we just drop the old special factions.
|
||||
// They will be replaced with new autogenerated ones per universe.
|
||||
Set<String> factionIdsToDelete = MUtil.set("0", "-1", "-2");
|
||||
|
||||
// Read the file content through GSON.
|
||||
Type type = new TypeToken<Map<String, Faction>>(){}.getType();
|
||||
Map<String, Faction> id2faction = Factions.get().gson.fromJson(DiscUtil.readCatch(oldFile), type);
|
||||
|
||||
// The Coll
|
||||
FactionColl coll = this.getForUniverse(MassiveCore.DEFAULT);
|
||||
|
||||
// Set the data
|
||||
for (Entry<String, Faction> entry : id2faction.entrySet())
|
||||
{
|
||||
String factionId = entry.getKey();
|
||||
if (factionIdsToDelete.contains(factionId)) continue;
|
||||
Faction faction = entry.getValue();
|
||||
coll.attach(faction, factionId);
|
||||
}
|
||||
|
||||
// Mark as migrated
|
||||
oldFile.renameTo(newFile);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INDEX
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void reindexUPlayers()
|
||||
{
|
||||
for (FactionColl coll : this.getColls())
|
||||
{
|
||||
coll.reindexUPlayers();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
@@ -1,103 +0,0 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import com.massivecraft.factions.Const;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.massivecore.Aspect;
|
||||
import com.massivecraft.massivecore.MassiveCore;
|
||||
import com.massivecraft.massivecore.util.DiscUtil;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import com.massivecraft.massivecore.xlib.gson.reflect.TypeToken;
|
||||
|
||||
public class FactionColls extends XColls<FactionColl, Faction>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static FactionColls i = new FactionColls();
|
||||
public static FactionColls get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: COLLS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public FactionColl createColl(String collName)
|
||||
{
|
||||
return new FactionColl(collName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Aspect getAspect()
|
||||
{
|
||||
return Factions.get().getAspect();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBasename()
|
||||
{
|
||||
return Const.COLLECTION_FACTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
super.init();
|
||||
|
||||
this.migrate();
|
||||
}
|
||||
|
||||
// This method is for the 1.8.X --> 2.0.0 migration
|
||||
public void migrate()
|
||||
{
|
||||
// Create file objects
|
||||
File oldFile = new File(Factions.get().getDataFolder(), "factions.json");
|
||||
File newFile = new File(Factions.get().getDataFolder(), "factions.json.migrated");
|
||||
|
||||
// Already migrated?
|
||||
if ( ! oldFile.exists()) return;
|
||||
|
||||
// Faction ids /delete
|
||||
// For simplicity we just drop the old special factions.
|
||||
// They will be replaced with new autogenerated ones per universe.
|
||||
Set<String> factionIdsToDelete = MUtil.set("0", "-1", "-2");
|
||||
|
||||
// Read the file content through GSON.
|
||||
Type type = new TypeToken<Map<String, Faction>>(){}.getType();
|
||||
Map<String, Faction> id2faction = Factions.get().gson.fromJson(DiscUtil.readCatch(oldFile), type);
|
||||
|
||||
// The Coll
|
||||
FactionColl coll = this.getForUniverse(MassiveCore.DEFAULT);
|
||||
|
||||
// Set the data
|
||||
for (Entry<String, Faction> entry : id2faction.entrySet())
|
||||
{
|
||||
String factionId = entry.getKey();
|
||||
if (factionIdsToDelete.contains(factionId)) continue;
|
||||
Faction faction = entry.getValue();
|
||||
coll.attach(faction, factionId);
|
||||
}
|
||||
|
||||
// Mark as migrated
|
||||
oldFile.renameTo(newFile);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INDEX
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void reindexUPlayers()
|
||||
{
|
||||
for (FactionColl coll : this.getColls())
|
||||
{
|
||||
coll.reindexUPlayers();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,18 +1,24 @@
|
||||
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 java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.EventPriority;
|
||||
|
||||
import com.massivecraft.factions.FFlag;
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.event.EventFactionsChunkChangeType;
|
||||
import com.massivecraft.factions.integration.dynmap.DynmapStyle;
|
||||
import com.massivecraft.factions.listeners.FactionsListenerChat;
|
||||
import com.massivecraft.massivecore.store.Entity;
|
||||
@@ -64,6 +70,54 @@ public class MConf extends Entity<MConf>
|
||||
public boolean removePlayerDataWhenBanned = true;
|
||||
public double removePlayerDataAfterInactiveDays = 20.0;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SPECIAL FACTION IDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String factionIdNone = UUID.randomUUID().toString();
|
||||
public String factionIdSafezone = UUID.randomUUID().toString();
|
||||
public String factionIdWarzone = UUID.randomUUID().toString();
|
||||
|
||||
// -------------------------------------------- //
|
||||
// DEFAULTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String defaultPlayerFactionId = this.factionIdNone;
|
||||
public Rel defaultPlayerRole = Rel.RECRUIT;
|
||||
public double defaultPlayerPower = 0.0;
|
||||
|
||||
public boolean defaultFactionOpen = false;
|
||||
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;
|
||||
|
||||
public boolean canLeaveWithNegativePower = true;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CORE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public int factionMemberLimit = 0;
|
||||
public double factionPowerMax = 0.0;
|
||||
|
||||
public int factionNameLengthMin = 3;
|
||||
public int factionNameLengthMax = 16;
|
||||
public boolean factionNameForceUpperCase = false;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// MESSAGES
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean broadcastNameChange = false;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CLAIM LIMITS
|
||||
// -------------------------------------------- //
|
||||
@@ -74,6 +128,110 @@ public class MConf extends Entity<MConf>
|
||||
// the maximum radius allowed when using the claim command.
|
||||
public int radiusClaimRadiusLimit = 5;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CLAIMS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean claimsMustBeConnected = true;
|
||||
public boolean claimingFromOthersAllowed = true;
|
||||
public boolean claimsCanBeUnconnectedIfOwnedByOtherFaction = false;
|
||||
public int claimsRequireMinFactionMembers = 1;
|
||||
public int claimedLandsMax = 0;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// HOMES
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean homesEnabled = true;
|
||||
public boolean homesMustBeInClaimedTerritory = true;
|
||||
public boolean homesTeleportCommandEnabled = true;
|
||||
public boolean homesTeleportAllowedFromEnemyTerritory = true;
|
||||
public boolean homesTeleportAllowedFromDifferentWorld = true;
|
||||
public double homesTeleportAllowedEnemyDistance = 32.0;
|
||||
public boolean homesTeleportIgnoreEnemiesIfInOwnTerritory = true;
|
||||
|
||||
public boolean homesTeleportToOnDeathActive = false;
|
||||
public EventPriority homesTeleportToOnDeathPriority = EventPriority.NORMAL;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ASSORTED
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean permanentFactionsDisableLeaderPromotion = false;
|
||||
public double actionDeniedPainAmount = 2.0D;
|
||||
public boolean disablePVPForFactionlessPlayers = false;
|
||||
public boolean enablePVPAgainstFactionlessInAttackersLand = false;
|
||||
public double territoryShieldFactor = 0.3D;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// DENY COMMANDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
// commands which will be prevented if the player is a member of a permanent faction
|
||||
public List<String> denyCommandsPermanentFactionMember = new ArrayList<String>();
|
||||
|
||||
// commands which will be prevented when in claimed territory of another faction
|
||||
public Map<Rel, List<String>> denyCommandsTerritoryRelation = MUtil.map(
|
||||
Rel.ENEMY, MUtil.list(
|
||||
// Essentials commands
|
||||
"home",
|
||||
"homes",
|
||||
"sethome",
|
||||
"createhome",
|
||||
"tpahere",
|
||||
"tpaccept",
|
||||
"tpyes",
|
||||
"tpa",
|
||||
"call",
|
||||
"tpask",
|
||||
"warp",
|
||||
"warps",
|
||||
"spawn",
|
||||
// Essentials e-alliases
|
||||
"ehome",
|
||||
"ehomes",
|
||||
"esethome",
|
||||
"ecreatehome",
|
||||
"etpahere",
|
||||
"etpaccept",
|
||||
"etpyes",
|
||||
"etpa",
|
||||
"ecall",
|
||||
"etpask",
|
||||
"ewarp",
|
||||
"ewarps",
|
||||
"espawn",
|
||||
// Essentials fallback alliases
|
||||
"essentials:home",
|
||||
"essentials:homes",
|
||||
"essentials:sethome",
|
||||
"essentials:createhome",
|
||||
"essentials:tpahere",
|
||||
"essentials:tpaccept",
|
||||
"essentials:tpyes",
|
||||
"essentials:tpa",
|
||||
"essentials:call",
|
||||
"essentials:tpask",
|
||||
"essentials:warp",
|
||||
"essentials:warps",
|
||||
"essentials:spawn",
|
||||
// Other plugins
|
||||
"wtp",
|
||||
"uspawn",
|
||||
"utp",
|
||||
"mspawn",
|
||||
"mtp",
|
||||
"fspawn",
|
||||
"ftp",
|
||||
"jspawn",
|
||||
"jtp"
|
||||
),
|
||||
Rel.NEUTRAL, new ArrayList<String>(),
|
||||
Rel.TRUCE, new ArrayList<String>(),
|
||||
Rel.ALLY, new ArrayList<String>(),
|
||||
Rel.MEMBER, new ArrayList<String>()
|
||||
);
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CHAT
|
||||
// -------------------------------------------- //
|
||||
@@ -87,28 +245,6 @@ public class MConf extends Entity<MConf>
|
||||
public boolean chatParseTags = true;
|
||||
public EventPriority chatParseTagsAt = EventPriority.LOW;
|
||||
|
||||
// HeroChat: The Faction Channel
|
||||
public String herochatFactionName = "Faction";
|
||||
public String herochatFactionNick = "F";
|
||||
public String herochatFactionFormat = "{color}[&l{nick}&r{color} &l{factions_roleprefix}&r{color}{factions_title|rp}{sender}{color}] &f{msg}";
|
||||
public ChatColor herochatFactionColor = ChatColor.GREEN;
|
||||
public int herochatFactionDistance = 0;
|
||||
public boolean herochatFactionIsShortcutAllowed = false;
|
||||
public boolean herochatFactionCrossWorld = true;
|
||||
public boolean herochatFactionMuted = false;
|
||||
public Set<String> herochatFactionWorlds = new HashSet<String>();
|
||||
|
||||
// HeroChat: The Allies Channel
|
||||
public String herochatAlliesName = "Allies";
|
||||
public String herochatAlliesNick = "A";
|
||||
public String herochatAlliesFormat = "{color}[&l{nick}&r&f {factions_relcolor}&l{factions_roleprefix}&r{factions_relcolor}{factions_name|rp}{sender}{color}] &f{msg}";
|
||||
public ChatColor herochatAlliesColor = ChatColor.DARK_PURPLE;
|
||||
public int herochatAlliesDistance = 0;
|
||||
public boolean herochatAlliesIsShortcutAllowed = false;
|
||||
public boolean herochatAlliesCrossWorld = true;
|
||||
public boolean herochatAlliesMuted = false;
|
||||
public Set<String> herochatAlliesWorlds = new HashSet<String>();
|
||||
|
||||
// -------------------------------------------- //
|
||||
// COLORS
|
||||
// -------------------------------------------- //
|
||||
@@ -250,7 +386,88 @@ public class MConf extends Entity<MConf>
|
||||
);
|
||||
|
||||
// -------------------------------------------- //
|
||||
// DYNMAP
|
||||
// INTEGRATION: HeroChat
|
||||
// -------------------------------------------- //
|
||||
|
||||
// HeroChat: The Faction Channel
|
||||
public String herochatFactionName = "Faction";
|
||||
public String herochatFactionNick = "F";
|
||||
public String herochatFactionFormat = "{color}[&l{nick}&r{color} &l{factions_roleprefix}&r{color}{factions_title|rp}{sender}{color}] &f{msg}";
|
||||
public ChatColor herochatFactionColor = ChatColor.GREEN;
|
||||
public int herochatFactionDistance = 0;
|
||||
public boolean herochatFactionIsShortcutAllowed = false;
|
||||
public boolean herochatFactionCrossWorld = true;
|
||||
public boolean herochatFactionMuted = false;
|
||||
public Set<String> herochatFactionWorlds = new HashSet<String>();
|
||||
|
||||
// HeroChat: The Allies Channel
|
||||
public String herochatAlliesName = "Allies";
|
||||
public String herochatAlliesNick = "A";
|
||||
public String herochatAlliesFormat = "{color}[&l{nick}&r&f {factions_relcolor}&l{factions_roleprefix}&r{factions_relcolor}{factions_name|rp}{sender}{color}] &f{msg}";
|
||||
public ChatColor herochatAlliesColor = ChatColor.DARK_PURPLE;
|
||||
public int herochatAlliesDistance = 0;
|
||||
public boolean herochatAlliesIsShortcutAllowed = false;
|
||||
public boolean herochatAlliesCrossWorld = true;
|
||||
public boolean herochatAlliesMuted = false;
|
||||
public Set<String> herochatAlliesWorlds = new HashSet<String>();
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INTEGRATION: LWC
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Map<EventFactionsChunkChangeType, Boolean> lwcRemoveOnChange = MUtil.map(
|
||||
EventFactionsChunkChangeType.BUY, false,
|
||||
EventFactionsChunkChangeType.SELL, false,
|
||||
EventFactionsChunkChangeType.CONQUER, false,
|
||||
EventFactionsChunkChangeType.PILLAGE, false
|
||||
);
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INTEGRATION: ECONOMY
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean econEnabled = false;
|
||||
|
||||
// TODO: Rename to include unit.
|
||||
public double econLandReward = 0.00;
|
||||
|
||||
public String econUniverseAccount = "";
|
||||
|
||||
public Map<EventFactionsChunkChangeType, Double> econChunkCost = MUtil.map(
|
||||
EventFactionsChunkChangeType.BUY, 30.0,
|
||||
EventFactionsChunkChangeType.SELL, -20.0,
|
||||
EventFactionsChunkChangeType.CONQUER, -10.0,
|
||||
EventFactionsChunkChangeType.PILLAGE, -10.0
|
||||
);
|
||||
|
||||
public double econCostCreate = 200.0;
|
||||
public double econCostSethome = 0.0;
|
||||
public double econCostJoin = 0.0;
|
||||
public double econCostLeave = 0.0;
|
||||
public double econCostKick = 0.0;
|
||||
public double econCostInvite = 0.0;
|
||||
public double econCostDeinvite = 0.0;
|
||||
public double econCostHome = 0.0;
|
||||
public double econCostName = 0.0;
|
||||
public double econCostDescription = 0.0;
|
||||
public double econCostTitle = 0.0;
|
||||
public double econCostOpen = 0.0;
|
||||
|
||||
public Map<Rel, Double> econRelCost = MUtil.map(
|
||||
Rel.ENEMY, 0.0,
|
||||
Rel.ALLY, 0.0,
|
||||
Rel.TRUCE, 0.0,
|
||||
Rel.NEUTRAL, 0.0
|
||||
);
|
||||
|
||||
//Faction banks, to pay for land claiming and other costs instead of individuals paying for them
|
||||
public boolean bankEnabled = true;
|
||||
//public static boolean bankMembersCanWithdraw = false; //Have to be at least moderator to withdraw or pay money to another faction
|
||||
public boolean bankFactionPaysCosts = true; //The faction pays for faction command costs, such as sethome
|
||||
public boolean bankFactionPaysLandCosts = true; //The faction pays for land claiming costs.
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INTEGRATION: DYNMAP
|
||||
// -------------------------------------------- //
|
||||
|
||||
// Should the dynmap intagration be used?
|
||||
|
@@ -27,7 +27,6 @@ public class MConfColl extends Coll<MConf>
|
||||
public void init()
|
||||
{
|
||||
super.init();
|
||||
|
||||
MConf.i = this.get(MassiveCore.INSTANCE, true);
|
||||
}
|
||||
|
||||
|
@@ -1,59 +1,828 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.massivecore.store.SenderEntity;
|
||||
|
||||
public class MPlayer extends SenderEntity<MPlayer>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// META
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static MPlayer get(Object oid)
|
||||
{
|
||||
return MPlayerColl.get().get(oid);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public MPlayer load(MPlayer that)
|
||||
{
|
||||
this.mapAutoUpdating = that.mapAutoUpdating;
|
||||
this.usingAdminMode = that.usingAdminMode;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDefault()
|
||||
{
|
||||
if (this.isMapAutoUpdating()) return false;
|
||||
if (this.isUsingAdminMode()) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private boolean mapAutoUpdating = false;
|
||||
public boolean isMapAutoUpdating() { return this.mapAutoUpdating; }
|
||||
public void setMapAutoUpdating(boolean mapAutoUpdating) { this.mapAutoUpdating = mapAutoUpdating; this.changed(); }
|
||||
|
||||
private boolean usingAdminMode = false;
|
||||
public boolean isUsingAdminMode()
|
||||
{
|
||||
if (this.usingAdminMode && this.getSender() != null && !Perm.ADMIN.has(this.getSender(), false))
|
||||
{
|
||||
// If we are using admin mode but don't have permissions for it we deactivate it.
|
||||
this.setUsingAdminMode(false);
|
||||
}
|
||||
return this.usingAdminMode;
|
||||
}
|
||||
public void setUsingAdminMode(boolean usingAdminMode) { this.usingAdminMode = usingAdminMode; this.changed(); }
|
||||
|
||||
}
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.massivecraft.factions.EconomyParticipator;
|
||||
import com.massivecraft.factions.FFlag;
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Lang;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.RelationParticipator;
|
||||
import com.massivecraft.factions.event.EventFactionsChunkChange;
|
||||
import com.massivecraft.factions.event.EventFactionsMembershipChange;
|
||||
import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason;
|
||||
import com.massivecraft.factions.util.RelationUtil;
|
||||
import com.massivecraft.massivecore.mixin.Mixin;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.ps.PSFormatHumanSpace;
|
||||
import com.massivecraft.massivecore.store.SenderEntity;
|
||||
import com.massivecraft.massivecore.util.IdUtil;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
|
||||
public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipator
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// META
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static MPlayer get(Object oid)
|
||||
{
|
||||
return MPlayerColl.get().get(oid);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: ENTITY
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public MPlayer load(MPlayer that)
|
||||
{
|
||||
this.setFactionId(that.factionId);
|
||||
this.setRole(that.role);
|
||||
this.setTitle(that.title);
|
||||
this.setPowerBoost(that.powerBoost);
|
||||
this.setPower(that.power);
|
||||
this.setMapAutoUpdating(that.mapAutoUpdating);
|
||||
this.setUsingAdminMode(that.usingAdminMode);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDefault()
|
||||
{
|
||||
if (this.hasFaction()) return false;
|
||||
// Role means nothing without a faction.
|
||||
// Title means nothing without a faction.
|
||||
if (this.getPowerRounded() != (int) Math.round(MConf.get().defaultPlayerPower)) return false;
|
||||
if (this.isMapAutoUpdating()) return false;
|
||||
if (this.isUsingAdminMode()) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postAttach(String id)
|
||||
{
|
||||
// If inited ...
|
||||
if (!Factions.get().isDatabaseInitialized()) return;
|
||||
|
||||
// ... update the index.
|
||||
Faction faction = this.getFaction();
|
||||
faction.uplayers.add(this);
|
||||
|
||||
//Factions.get().log(Txt.parse("<g>postAttach added <h>%s <i>aka <h>%s <i>to <h>%s <i>aka <h>%s<i>.", id, Mixin.getDisplayName(id), faction.getId(), faction.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preDetach(String id)
|
||||
{
|
||||
// If inited ...
|
||||
if (!Factions.get().isDatabaseInitialized()) return;
|
||||
|
||||
// ... update the index.
|
||||
Faction faction = this.getFaction();
|
||||
faction.uplayers.remove(this);
|
||||
|
||||
//Factions.get().log(Txt.parse("<b>preDetach removed <h>%s <i>aka <h>%s <i>to <h>%s <i>aka <h>%s<i>.", id, Mixin.getDisplayName(id), faction.getId(), faction.getName()));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS: RAW
|
||||
// -------------------------------------------- //
|
||||
// In this section of the source code we place the field declarations only.
|
||||
// Each field has it's own section further down since just the getter and setter logic takes up quite some place.
|
||||
|
||||
// This is a foreign key.
|
||||
// Each player belong to a faction.
|
||||
// Null means default for the universe.
|
||||
private String factionId = null;
|
||||
|
||||
// What role does the player have in the faction?
|
||||
// Null means default for the universe.
|
||||
private Rel role = null;
|
||||
|
||||
// What title does the player have in the faction?
|
||||
// The title is just for fun. It's not connected to any game mechanic.
|
||||
// The player title is similar to the faction description.
|
||||
//
|
||||
// Question: Can the title contain chat colors?
|
||||
// Answer: Yes but in such case the policy is that they already must be parsed using Txt.parse.
|
||||
// If the title contains raw markup, such as "<white>" instead of "§f" it will not be parsed and "<white>" will be displayed.
|
||||
//
|
||||
// Null means the player has no title.
|
||||
private String title = null;
|
||||
|
||||
// Player usually do not have a powerboost. It defaults to 0.
|
||||
// The powerBoost is a custom increase/decrease to default and maximum power.
|
||||
// Note that player powerBoost and faction powerBoost are very similar.
|
||||
private Double powerBoost = null;
|
||||
|
||||
// Each player has an individual power level.
|
||||
// The power level for online players is occasionally updated by a recurring task and the power should stay the same for offline players.
|
||||
// For that reason the value is to be considered correct when you pick it. Do not call the power update method.
|
||||
// Null means default for the universe.
|
||||
private Double power = null;
|
||||
|
||||
// Has this player requested an auto-updating ascii art map?
|
||||
// Null means false
|
||||
private Boolean mapAutoUpdating = null;
|
||||
|
||||
// Is this player using admin mode?
|
||||
// Null means false
|
||||
private Boolean usingAdminMode = null;
|
||||
|
||||
// The id for the faction this uplayer is currently autoclaiming for.
|
||||
// NOTE: This field will not be saved to the database ever.
|
||||
// Null means the player isn't auto claiming.
|
||||
private transient Faction autoClaimFaction = null;
|
||||
public Faction getAutoClaimFaction() { return this.autoClaimFaction; }
|
||||
public void setAutoClaimFaction(Faction autoClaimFaction) { this.autoClaimFaction = autoClaimFaction; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CORE UTILITIES
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void resetFactionData()
|
||||
{
|
||||
// The default neutral faction
|
||||
this.setFactionId(null);
|
||||
this.setRole(null);
|
||||
this.setTitle(null);
|
||||
this.setAutoClaimFaction(null);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELD: factionId
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String getDefaultFactionId()
|
||||
{
|
||||
return MConf.get().defaultPlayerFactionId;
|
||||
}
|
||||
|
||||
// This method never returns null
|
||||
public String getFactionId()
|
||||
{
|
||||
if (this.factionId == null) return this.getDefaultFactionId();
|
||||
return this.factionId;
|
||||
}
|
||||
|
||||
// This method never returns null
|
||||
public Faction getFaction()
|
||||
{
|
||||
Faction ret = Faction.get(this.getFactionId());
|
||||
if (ret == null) ret = Faction.get(MConf.get().defaultPlayerFactionId);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public boolean hasFaction()
|
||||
{
|
||||
return !this.getFactionId().equals(MConf.get().factionIdNone);
|
||||
}
|
||||
|
||||
// This setter is so long because it search for default/null case and takes care of updating the faction member index
|
||||
public void setFactionId(String factionId)
|
||||
{
|
||||
// Clean input
|
||||
String target = factionId;
|
||||
|
||||
// Detect Nochange
|
||||
if (MUtil.equals(this.factionId, target)) return;
|
||||
|
||||
// Get the raw old value
|
||||
String oldFactionId = this.factionId;
|
||||
|
||||
// Apply
|
||||
this.factionId = target;
|
||||
|
||||
// Must be attached and initialized
|
||||
if (!this.attached()) return;
|
||||
if (!Factions.get().isDatabaseInitialized()) return;
|
||||
|
||||
if (oldFactionId == null) oldFactionId = this.getDefaultFactionId();
|
||||
|
||||
// Update index
|
||||
Faction oldFaction = Faction.get(oldFactionId);
|
||||
Faction faction = this.getFaction();
|
||||
|
||||
if (oldFaction != null) oldFaction.uplayers.remove(this);
|
||||
if (faction != null) faction.uplayers.add(this);
|
||||
|
||||
String oldFactionIdDesc = "NULL";
|
||||
String oldFactionNameDesc = "NULL";
|
||||
if (oldFaction != null)
|
||||
{
|
||||
oldFactionIdDesc = oldFaction.getId();
|
||||
oldFactionNameDesc = oldFaction.getName();
|
||||
}
|
||||
String factionIdDesc = "NULL";
|
||||
String factionNameDesc = "NULL";
|
||||
if (faction != null)
|
||||
{
|
||||
factionIdDesc = faction.getId();
|
||||
factionNameDesc = faction.getName();
|
||||
}
|
||||
|
||||
Factions.get().log(Txt.parse("<i>setFactionId moved <h>%s <i>aka <h>%s <i>from <h>%s <i>aka <h>%s <i>to <h>%s <i>aka <h>%s<i>.", this.getId(), this.getDisplayName(IdUtil.getConsole()), oldFactionIdDesc, oldFactionNameDesc, factionIdDesc, factionNameDesc));
|
||||
|
||||
// Mark as changed
|
||||
this.changed();
|
||||
}
|
||||
|
||||
public void setFaction(Faction faction)
|
||||
{
|
||||
this.setFactionId(faction.getId());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELD: role
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Rel getDefaultRole()
|
||||
{
|
||||
return MConf.get().defaultPlayerRole;
|
||||
}
|
||||
|
||||
public Rel getRole()
|
||||
{
|
||||
if (this.role == null) return this.getDefaultRole();
|
||||
return this.role;
|
||||
}
|
||||
|
||||
public void setRole(Rel role)
|
||||
{
|
||||
// Clean input
|
||||
Rel target = role;
|
||||
|
||||
// Detect Nochange
|
||||
if (MUtil.equals(this.role, target)) return;
|
||||
|
||||
// Apply
|
||||
this.role = target;
|
||||
|
||||
// Mark as changed
|
||||
this.changed();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELD: title
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean hasTitle()
|
||||
{
|
||||
return this.title != null;
|
||||
}
|
||||
|
||||
public String getTitle()
|
||||
{
|
||||
if (this.hasTitle()) return this.title;
|
||||
return Lang.PLAYER_NOTITLE;
|
||||
}
|
||||
|
||||
public void setTitle(String title)
|
||||
{
|
||||
// Clean input
|
||||
String target = title;
|
||||
if (target != null)
|
||||
{
|
||||
target = target.trim();
|
||||
if (target.length() == 0)
|
||||
{
|
||||
target = null;
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: That we parse the title here is considered part of the 1.8 --> 2.0 migration.
|
||||
// This should be removed once the migration phase is considered to be over.
|
||||
if (target != null)
|
||||
{
|
||||
target = Txt.parse(target);
|
||||
}
|
||||
|
||||
// Detect Nochange
|
||||
if (MUtil.equals(this.title, target)) return;
|
||||
|
||||
// Apply
|
||||
this.title = target;
|
||||
|
||||
// Mark as changed
|
||||
this.changed();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELD: powerBoost
|
||||
// -------------------------------------------- //
|
||||
|
||||
public double getPowerBoost()
|
||||
{
|
||||
Double ret = this.powerBoost;
|
||||
if (ret == null) ret = 0D;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void setPowerBoost(Double powerBoost)
|
||||
{
|
||||
// Clean input
|
||||
Double target = powerBoost;
|
||||
if (target == null || target == 0) target = null;
|
||||
|
||||
// Detect Nochange
|
||||
if (MUtil.equals(this.powerBoost, target)) return;
|
||||
|
||||
// Apply
|
||||
this.powerBoost = target;
|
||||
|
||||
// Mark as changed
|
||||
this.changed();
|
||||
}
|
||||
|
||||
public boolean hasPowerBoost()
|
||||
{
|
||||
return this.getPowerBoost() != 0D;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// 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;
|
||||
}
|
||||
|
||||
public int getPowerMaxRounded()
|
||||
{
|
||||
return (int) Math.round(this.getPowerMax());
|
||||
}
|
||||
|
||||
public int getPowerMinRounded()
|
||||
{
|
||||
return (int) Math.round(this.getPowerMin());
|
||||
}
|
||||
|
||||
public int getPowerMaxUniversalRounded()
|
||||
{
|
||||
return (int) Math.round(this.getPowerMaxUniversal());
|
||||
}
|
||||
|
||||
// RAW
|
||||
|
||||
public double getDefaultPower()
|
||||
{
|
||||
return MConf.get().defaultPlayerPower;
|
||||
}
|
||||
|
||||
public double getPower()
|
||||
{
|
||||
Double ret = this.power;
|
||||
if (ret == null) ret = this.getDefaultPower();
|
||||
ret = this.getLimitedPower(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void setPower(Double power)
|
||||
{
|
||||
// Clean input
|
||||
Double target = power;
|
||||
|
||||
// Detect Nochange
|
||||
if (MUtil.equals(this.power, target)) return;
|
||||
|
||||
// Apply
|
||||
this.power = target;
|
||||
|
||||
// Mark as changed
|
||||
this.changed();
|
||||
}
|
||||
|
||||
// FINER
|
||||
|
||||
public int getPowerRounded()
|
||||
{
|
||||
return (int) Math.round(this.getPower());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELD: mapAutoUpdating
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean isMapAutoUpdating()
|
||||
{
|
||||
if (this.mapAutoUpdating == null) return false;
|
||||
if (this.mapAutoUpdating == false) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setMapAutoUpdating(Boolean mapAutoUpdating)
|
||||
{
|
||||
// Clean input
|
||||
Boolean target = mapAutoUpdating;
|
||||
if (target == false) target = null;
|
||||
|
||||
// Detect Nochange
|
||||
if (MUtil.equals(this.mapAutoUpdating, target)) return;
|
||||
|
||||
// Apply
|
||||
this.mapAutoUpdating = target;
|
||||
|
||||
// Mark as changed
|
||||
this.changed();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELD: usingAdminMode
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean isUsingAdminMode()
|
||||
{
|
||||
if (this.usingAdminMode == null) return false;
|
||||
if (this.usingAdminMode == false) return false;
|
||||
|
||||
// Deactivate admin mode if we don't have permissions for it.
|
||||
if (this.getSender() != null && !Perm.ADMIN.has(this.getSender(), false))
|
||||
{
|
||||
this.setUsingAdminMode(false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setUsingAdminMode(Boolean usingAdminMode)
|
||||
{
|
||||
// Clean input
|
||||
Boolean target = usingAdminMode;
|
||||
if (target == false) target = null;
|
||||
|
||||
// Detect Nochange
|
||||
if (MUtil.equals(this.usingAdminMode, target)) return;
|
||||
|
||||
// Apply
|
||||
this.usingAdminMode = target;
|
||||
|
||||
// Mark as changed
|
||||
this.changed();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// TITLE, NAME, FACTION NAME AND CHAT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String getFactionName()
|
||||
{
|
||||
Faction faction = this.getFaction();
|
||||
if (faction.isNone()) return "";
|
||||
return faction.getName();
|
||||
}
|
||||
|
||||
// Base concatenations:
|
||||
|
||||
public String getNameAndSomething(String color, String something)
|
||||
{
|
||||
String ret = "";
|
||||
ret += color;
|
||||
ret += this.getRole().getPrefix();
|
||||
if (something != null && something.length() > 0)
|
||||
{
|
||||
ret += something;
|
||||
ret += " ";
|
||||
ret += color;
|
||||
}
|
||||
ret += this.getName();
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String getNameAndFactionName()
|
||||
{
|
||||
return this.getNameAndSomething("", this.getFactionName());
|
||||
}
|
||||
|
||||
public String getNameAndTitle(String color)
|
||||
{
|
||||
if (this.hasTitle())
|
||||
{
|
||||
return this.getNameAndSomething(color, this.getTitle());
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.getNameAndSomething(color, null);
|
||||
}
|
||||
}
|
||||
|
||||
// Colored concatenations:
|
||||
// These are used in information messages
|
||||
|
||||
public String getNameAndTitle(Faction faction)
|
||||
{
|
||||
return this.getNameAndTitle(this.getColorTo(faction).toString());
|
||||
}
|
||||
public String getNameAndTitle(MPlayer uplayer)
|
||||
{
|
||||
return this.getNameAndTitle(this.getColorTo(uplayer).toString());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// RELATION AND RELATION COLORS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String describeTo(RelationParticipator observer, boolean ucfirst)
|
||||
{
|
||||
return RelationUtil.describeThatToMe(this, observer, ucfirst);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeTo(RelationParticipator observer)
|
||||
{
|
||||
return RelationUtil.describeThatToMe(this, observer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rel getRelationTo(RelationParticipator observer)
|
||||
{
|
||||
return RelationUtil.getRelationOfThatToMe(this, observer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rel getRelationTo(RelationParticipator observer, boolean ignorePeaceful)
|
||||
{
|
||||
return RelationUtil.getRelationOfThatToMe(this, observer, ignorePeaceful);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatColor getColorTo(RelationParticipator observer)
|
||||
{
|
||||
return RelationUtil.getColorOfThatToMe(this, observer);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// HEALTH
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void heal(int amnt)
|
||||
{
|
||||
Player player = this.getPlayer();
|
||||
if (player == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
player.setHealth(player.getHealth() + amnt);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// TERRITORY
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean isInOwnTerritory()
|
||||
{
|
||||
PS ps = Mixin.getSenderPs(this.getId());
|
||||
if (ps == null) return false;
|
||||
return BoardColl.get().getFactionAt(ps) == this.getFaction();
|
||||
}
|
||||
|
||||
public boolean isInEnemyTerritory()
|
||||
{
|
||||
PS ps = Mixin.getSenderPs(this.getId());
|
||||
if (ps == null) return false;
|
||||
return BoardColl.get().getFactionAt(ps).getRelationTo(this) == Rel.ENEMY;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ACTIONS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void leave()
|
||||
{
|
||||
Faction myFaction = this.getFaction();
|
||||
|
||||
boolean permanent = myFaction.getFlag(FFlag.PERMANENT);
|
||||
|
||||
if (myFaction.getUPlayers().size() > 1)
|
||||
{
|
||||
if (!permanent && this.getRole() == Rel.LEADER)
|
||||
{
|
||||
msg("<b>You must give the leader role to someone else first.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!MConf.get().canLeaveWithNegativePower && this.getPower() < 0)
|
||||
{
|
||||
msg("<b>You cannot leave until your power is positive.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Event
|
||||
EventFactionsMembershipChange membershipChangeEvent = new EventFactionsMembershipChange(this.getSender(), this, myFaction, MembershipChangeReason.LEAVE);
|
||||
membershipChangeEvent.run();
|
||||
if (membershipChangeEvent.isCancelled()) return;
|
||||
|
||||
if (myFaction.isNormal())
|
||||
{
|
||||
for (MPlayer uplayer : myFaction.getUPlayersWhereOnline(true))
|
||||
{
|
||||
uplayer.msg("%s<i> left %s<i>.", this.describeTo(uplayer, true), myFaction.describeTo(uplayer));
|
||||
}
|
||||
|
||||
if (MConf.get().logFactionLeave)
|
||||
{
|
||||
Factions.get().log(this.getName()+" left the faction: "+myFaction.getName());
|
||||
}
|
||||
}
|
||||
|
||||
this.resetFactionData();
|
||||
|
||||
if (myFaction.isNormal() && !permanent && myFaction.getUPlayers().isEmpty())
|
||||
{
|
||||
// Remove this faction
|
||||
for (MPlayer mplayer : MPlayerColl.get().getAllOnline())
|
||||
{
|
||||
mplayer.msg("<i>%s<i> was disbanded.", myFaction.describeTo(mplayer, true));
|
||||
}
|
||||
|
||||
if (MConf.get().logFactionDisband)
|
||||
{
|
||||
Factions.get().log("The faction "+myFaction.getName()+" ("+myFaction.getId()+") was disbanded due to the last player ("+this.getName()+") leaving.");
|
||||
}
|
||||
myFaction.detach();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean tryClaim(Faction newFaction, PS ps, boolean verbooseChange, boolean verbooseSame)
|
||||
{
|
||||
PS chunk = ps.getChunk(true);
|
||||
Faction oldFaction = BoardColl.get().getFactionAt(chunk);
|
||||
|
||||
MConf mconf = MConf.get();
|
||||
|
||||
// Validate
|
||||
if (newFaction == oldFaction)
|
||||
{
|
||||
msg("%s<i> already owns this land.", newFaction.describeTo(this, true));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!this.isUsingAdminMode())
|
||||
{
|
||||
if (newFaction.isNormal())
|
||||
{
|
||||
if (mconf.getWorldsNoClaiming().contains(ps.getWorld()))
|
||||
{
|
||||
msg("<b>Sorry, this world has land claiming disabled.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!FPerm.TERRITORY.has(this, newFaction, true))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newFaction.getUPlayers().size() < mconf.claimsRequireMinFactionMembers)
|
||||
{
|
||||
msg("Factions must have at least <h>%s<b> members to claim land.", mconf.claimsRequireMinFactionMembers);
|
||||
return false;
|
||||
}
|
||||
|
||||
int ownedLand = newFaction.getLandCount();
|
||||
|
||||
if (mconf.claimedLandsMax != 0 && ownedLand >= mconf.claimedLandsMax && ! newFaction.getFlag(FFlag.INFPOWER))
|
||||
{
|
||||
msg("<b>Limit reached. You can't claim more land.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ownedLand >= newFaction.getPowerRounded())
|
||||
{
|
||||
msg("<b>You can't claim more land. You need more power.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if
|
||||
(
|
||||
mconf.claimsMustBeConnected
|
||||
&&
|
||||
newFaction.getLandCountInWorld(ps.getWorld()) > 0
|
||||
&&
|
||||
!BoardColl.get().isConnectedPs(chunk, newFaction)
|
||||
&&
|
||||
(!mconf.claimsCanBeUnconnectedIfOwnedByOtherFaction || oldFaction.isNone())
|
||||
)
|
||||
{
|
||||
if (mconf.claimsCanBeUnconnectedIfOwnedByOtherFaction)
|
||||
{
|
||||
msg("<b>You can only claim additional land which is connected to your first claim or controlled by another faction!");
|
||||
}
|
||||
else
|
||||
{
|
||||
msg("<b>You can only claim additional land which is connected to your first claim!");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (oldFaction.isNormal())
|
||||
{
|
||||
if (!FPerm.TERRITORY.has(this, oldFaction, false))
|
||||
{
|
||||
if (!mconf.claimingFromOthersAllowed)
|
||||
{
|
||||
msg("<b>You may not claim land from others.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (oldFaction.getRelationTo(newFaction).isAtLeast(Rel.TRUCE))
|
||||
{
|
||||
msg("<b>You can't claim this land due to your relation with the current owner.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!oldFaction.hasLandInflation())
|
||||
{
|
||||
msg("%s<i> owns this land and is strong enough to keep it.", oldFaction.getName(this));
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! BoardColl.get().isBorderPs(chunk))
|
||||
{
|
||||
msg("<b>You must start claiming land at the border of the territory.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Event
|
||||
EventFactionsChunkChange event = new EventFactionsChunkChange(this.getSender(), chunk, newFaction);
|
||||
event.run();
|
||||
if (event.isCancelled()) return false;
|
||||
|
||||
// Apply
|
||||
BoardColl.get().setFactionAt(chunk, newFaction);
|
||||
|
||||
// Inform
|
||||
Set<MPlayer> informees = new HashSet<MPlayer>();
|
||||
informees.add(this);
|
||||
if (newFaction.isNormal())
|
||||
{
|
||||
informees.addAll(newFaction.getUPlayers());
|
||||
}
|
||||
if (oldFaction.isNormal())
|
||||
{
|
||||
informees.addAll(oldFaction.getUPlayers());
|
||||
}
|
||||
if (MConf.get().logLandClaims)
|
||||
{
|
||||
informees.add(MPlayer.get(IdUtil.getConsole()));
|
||||
}
|
||||
|
||||
String chunkString = chunk.toString(PSFormatHumanSpace.get());
|
||||
String typeString = event.getType().toString().toLowerCase();
|
||||
for (MPlayer informee : informees)
|
||||
{
|
||||
informee.msg("<h>%s<i> did %s %s <i>for <h>%s<i> from <h>%s<i>.", this.describeTo(informee, true), typeString, chunkString, newFaction.describeTo(informee), oldFaction.describeTo(informee));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -2,8 +2,13 @@ package com.massivecraft.factions.entity;
|
||||
|
||||
import com.massivecraft.factions.Const;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.massivecore.mixin.Mixin;
|
||||
import com.massivecraft.massivecore.store.MStore;
|
||||
import com.massivecraft.massivecore.store.SenderColl;
|
||||
import com.massivecraft.massivecore.util.IdUtil;
|
||||
import com.massivecraft.massivecore.util.TimeUnit;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class MPlayerColl extends SenderColl<MPlayer>
|
||||
{
|
||||
@@ -18,4 +23,101 @@ public class MPlayerColl extends SenderColl<MPlayer>
|
||||
super(Const.COLLECTION_MPLAYER, MPlayer.class, MStore.getDb(), Factions.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// EXTRAS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void clean()
|
||||
{
|
||||
String universe = this.getUniverse();
|
||||
for (MPlayer uplayer : this.getAll())
|
||||
{
|
||||
String factionId = uplayer.getFactionId();
|
||||
if (FactionColl.get().containsId(factionId)) continue;
|
||||
|
||||
uplayer.resetFactionData();
|
||||
|
||||
String message = Txt.parse("<i>Reset data for <h>%s <i>in <h>%s <i>universe. Unknown factionId <h>%s", uplayer.getDisplayName(IdUtil.getConsole()), universe, factionId);
|
||||
Factions.get().log(message);
|
||||
}
|
||||
}
|
||||
|
||||
public void removePlayerDataAfterInactiveDaysRoutine()
|
||||
{
|
||||
if (MConf.get().removePlayerDataAfterInactiveDays <= 0.0) return;
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
double toleranceMillis = MConf.get().removePlayerDataAfterInactiveDays * TimeUnit.MILLIS_PER_DAY;
|
||||
|
||||
for (MPlayer uplayer : this.getAll())
|
||||
{
|
||||
Long lastPlayed = Mixin.getLastPlayed(uplayer.getId());
|
||||
if (lastPlayed == null) continue;
|
||||
|
||||
if (uplayer.isOnline()) continue;
|
||||
if (now - lastPlayed <= toleranceMillis) continue;
|
||||
|
||||
if (MConf.get().logFactionLeave || MConf.get().logFactionKick)
|
||||
{
|
||||
Factions.get().log("Player "+uplayer.getName()+" was auto-removed due to inactivity.");
|
||||
}
|
||||
|
||||
// if player is faction leader, sort out the faction since he's going away
|
||||
if (uplayer.getRole() == Rel.LEADER)
|
||||
{
|
||||
Faction faction = uplayer.getFaction();
|
||||
if (faction != null)
|
||||
{
|
||||
uplayer.getFaction().promoteNewLeader();
|
||||
}
|
||||
}
|
||||
|
||||
uplayer.leave();
|
||||
uplayer.detach();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// This method is for the 1.8.X --> 2.0.0 migration
|
||||
public void migrate()
|
||||
{
|
||||
// Create file objects
|
||||
File oldFile = new File(Factions.get().getDataFolder(), "players.json");
|
||||
File newFile = new File(Factions.get().getDataFolder(), "players.json.migrated");
|
||||
|
||||
// Already migrated?
|
||||
if ( ! oldFile.exists()) return;
|
||||
|
||||
// Read the file content through GSON.
|
||||
Type type = new TypeToken<Map<String, UPlayer>>(){}.getType();
|
||||
Map<String, UPlayer> id2uplayer = Factions.get().gson.fromJson(DiscUtil.readCatch(oldFile), type);
|
||||
|
||||
// The Coll
|
||||
UPlayerColl coll = this.getForUniverse(MassiveCore.DEFAULT);
|
||||
|
||||
// Set the data
|
||||
for (Entry<String, UPlayer> entry : id2uplayer.entrySet())
|
||||
{
|
||||
String playerId = entry.getKey();
|
||||
UPlayer uplayer = entry.getValue();
|
||||
coll.attach(uplayer, playerId);
|
||||
}
|
||||
|
||||
// Mark as migrated
|
||||
oldFile.renameTo(newFile);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// EXTRAS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void clean()
|
||||
{
|
||||
for (UPlayerColl coll : this.getColls())
|
||||
{
|
||||
coll.clean();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
@@ -1,273 +0,0 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.EventPriority;
|
||||
|
||||
import com.massivecraft.factions.FFlag;
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.event.EventFactionsChunkChangeType;
|
||||
import com.massivecraft.massivecore.store.Entity;
|
||||
import com.massivecraft.massivecore.store.SenderEntity;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class UConf extends Entity<UConf>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// META
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static UConf get(Object oid)
|
||||
{
|
||||
return UConfColls.get().get2(oid);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UNIVERSE ENABLE SWITCH
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean enabled = true;
|
||||
|
||||
public static boolean isDisabled(Object universe)
|
||||
{
|
||||
return isDisabled(universe, null);
|
||||
}
|
||||
|
||||
public static String getDisabledMessage(Object universe)
|
||||
{
|
||||
UConf uconf = UConf.get(universe);
|
||||
return Txt.parse("<i>Factions are disabled in the <h>%s <i>universe.", uconf.getUniverse());
|
||||
}
|
||||
|
||||
public static boolean isDisabled(Object universe, Object inform)
|
||||
{
|
||||
UConf uconf = UConf.get(universe);
|
||||
if (uconf.enabled) return false;
|
||||
|
||||
if (inform instanceof CommandSender)
|
||||
{
|
||||
((CommandSender)inform).sendMessage(getDisabledMessage(universe));
|
||||
}
|
||||
else if (inform instanceof SenderEntity)
|
||||
{
|
||||
((SenderEntity<?>)inform).sendMessage(getDisabledMessage(universe));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SPECIAL FACTION IDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String factionIdNone = UUID.randomUUID().toString();
|
||||
public String factionIdSafezone = UUID.randomUUID().toString();
|
||||
public String factionIdWarzone = UUID.randomUUID().toString();
|
||||
|
||||
// -------------------------------------------- //
|
||||
// DEFAULTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String defaultPlayerFactionId = this.factionIdNone;
|
||||
public Rel defaultPlayerRole = Rel.RECRUIT;
|
||||
public double defaultPlayerPower = 0.0;
|
||||
|
||||
public boolean defaultFactionOpen = false;
|
||||
public Map<FFlag, Boolean> defaultFactionFlags = FFlag.getDefaultDefaults();
|
||||
public Map<FPerm, Set<Rel>> defaultFactionPerms = FPerm.getDefaultDefaults();
|
||||
|
||||
// -------------------------------------------- //
|
||||
// MESSAGES
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean broadcastNameChange = false;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// POWER
|
||||
// -------------------------------------------- //
|
||||
|
||||
public double powerMax = 10.0;
|
||||
public double powerMin = 0.0;
|
||||
public double powerPerHour = 2.0;
|
||||
public double powerPerDeath = -2.0;
|
||||
|
||||
public boolean canLeaveWithNegativePower = true;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CORE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public int factionMemberLimit = 0;
|
||||
public double factionPowerMax = 0.0;
|
||||
|
||||
public int factionNameLengthMin = 3;
|
||||
public int factionNameLengthMax = 16;
|
||||
public boolean factionNameForceUpperCase = false;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CLAIMS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean claimsMustBeConnected = true;
|
||||
public boolean claimingFromOthersAllowed = true;
|
||||
public boolean claimsCanBeUnconnectedIfOwnedByOtherFaction = false;
|
||||
public int claimsRequireMinFactionMembers = 1;
|
||||
public int claimedLandsMax = 0;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// HOMES
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean homesEnabled = true;
|
||||
public boolean homesMustBeInClaimedTerritory = true;
|
||||
public boolean homesTeleportCommandEnabled = true;
|
||||
public boolean homesTeleportAllowedFromEnemyTerritory = true;
|
||||
public boolean homesTeleportAllowedFromDifferentWorld = true;
|
||||
public double homesTeleportAllowedEnemyDistance = 32.0;
|
||||
public boolean homesTeleportIgnoreEnemiesIfInOwnTerritory = true;
|
||||
|
||||
public boolean homesTeleportToOnDeathActive = false;
|
||||
public EventPriority homesTeleportToOnDeathPriority = EventPriority.NORMAL;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ASSORTED
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean permanentFactionsDisableLeaderPromotion = false;
|
||||
public double actionDeniedPainAmount = 2.0D;
|
||||
public boolean disablePVPForFactionlessPlayers = false;
|
||||
public boolean enablePVPAgainstFactionlessInAttackersLand = false;
|
||||
public double territoryShieldFactor = 0.3D;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// DENY COMMANDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
// commands which will be prevented if the player is a member of a permanent faction
|
||||
public List<String> denyCommandsPermanentFactionMember = new ArrayList<String>();
|
||||
|
||||
// commands which will be prevented when in claimed territory of another faction
|
||||
public Map<Rel, List<String>> denyCommandsTerritoryRelation = MUtil.map(
|
||||
Rel.ENEMY, MUtil.list(
|
||||
// Essentials commands
|
||||
"home",
|
||||
"homes",
|
||||
"sethome",
|
||||
"createhome",
|
||||
"tpahere",
|
||||
"tpaccept",
|
||||
"tpyes",
|
||||
"tpa",
|
||||
"call",
|
||||
"tpask",
|
||||
"warp",
|
||||
"warps",
|
||||
"spawn",
|
||||
// Essentials e-alliases
|
||||
"ehome",
|
||||
"ehomes",
|
||||
"esethome",
|
||||
"ecreatehome",
|
||||
"etpahere",
|
||||
"etpaccept",
|
||||
"etpyes",
|
||||
"etpa",
|
||||
"ecall",
|
||||
"etpask",
|
||||
"ewarp",
|
||||
"ewarps",
|
||||
"espawn",
|
||||
// Essentials fallback alliases
|
||||
"essentials:home",
|
||||
"essentials:homes",
|
||||
"essentials:sethome",
|
||||
"essentials:createhome",
|
||||
"essentials:tpahere",
|
||||
"essentials:tpaccept",
|
||||
"essentials:tpyes",
|
||||
"essentials:tpa",
|
||||
"essentials:call",
|
||||
"essentials:tpask",
|
||||
"essentials:warp",
|
||||
"essentials:warps",
|
||||
"essentials:spawn",
|
||||
// Other plugins
|
||||
"wtp",
|
||||
"uspawn",
|
||||
"utp",
|
||||
"mspawn",
|
||||
"mtp",
|
||||
"fspawn",
|
||||
"ftp",
|
||||
"jspawn",
|
||||
"jtp"
|
||||
),
|
||||
Rel.NEUTRAL, new ArrayList<String>(),
|
||||
Rel.TRUCE, new ArrayList<String>(),
|
||||
Rel.ALLY, new ArrayList<String>(),
|
||||
Rel.MEMBER, new ArrayList<String>()
|
||||
);
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INTEGRATION: LWC
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Map<EventFactionsChunkChangeType, Boolean> lwcRemoveOnChange = MUtil.map(
|
||||
EventFactionsChunkChangeType.BUY, false,
|
||||
EventFactionsChunkChangeType.SELL, false,
|
||||
EventFactionsChunkChangeType.CONQUER, false,
|
||||
EventFactionsChunkChangeType.PILLAGE, false
|
||||
);
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INTEGRATION: ECONOMY
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean econEnabled = false;
|
||||
|
||||
// TODO: Rename to include unit.
|
||||
public double econLandReward = 0.00;
|
||||
|
||||
public String econUniverseAccount = "";
|
||||
|
||||
public Map<EventFactionsChunkChangeType, Double> econChunkCost = MUtil.map(
|
||||
EventFactionsChunkChangeType.BUY, 30.0,
|
||||
EventFactionsChunkChangeType.SELL, -20.0,
|
||||
EventFactionsChunkChangeType.CONQUER, -10.0,
|
||||
EventFactionsChunkChangeType.PILLAGE, -10.0
|
||||
);
|
||||
|
||||
public double econCostCreate = 200.0;
|
||||
public double econCostSethome = 0.0;
|
||||
public double econCostJoin = 0.0;
|
||||
public double econCostLeave = 0.0;
|
||||
public double econCostKick = 0.0;
|
||||
public double econCostInvite = 0.0;
|
||||
public double econCostDeinvite = 0.0;
|
||||
public double econCostHome = 0.0;
|
||||
public double econCostName = 0.0;
|
||||
public double econCostDescription = 0.0;
|
||||
public double econCostTitle = 0.0;
|
||||
public double econCostOpen = 0.0;
|
||||
|
||||
public Map<Rel, Double> econRelCost = MUtil.map(
|
||||
Rel.ENEMY, 0.0,
|
||||
Rel.ALLY, 0.0,
|
||||
Rel.TRUCE, 0.0,
|
||||
Rel.NEUTRAL, 0.0
|
||||
);
|
||||
|
||||
//Faction banks, to pay for land claiming and other costs instead of individuals paying for them
|
||||
public boolean bankEnabled = true;
|
||||
//public static boolean bankMembersCanWithdraw = false; //Have to be at least moderator to withdraw or pay money to another faction
|
||||
public boolean bankFactionPaysCosts = true; //The faction pays for faction command costs, such as sethome
|
||||
public boolean bankFactionPaysLandCosts = true; //The faction pays for land claiming costs.
|
||||
|
||||
}
|
@@ -1,30 +0,0 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.massivecore.MassiveCore;
|
||||
import com.massivecraft.massivecore.store.Coll;
|
||||
import com.massivecraft.massivecore.store.MStore;
|
||||
|
||||
public class UConfColl extends Coll<UConf>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public UConfColl(String name)
|
||||
{
|
||||
super(name, UConf.class, MStore.getDb(), Factions.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
super.init();
|
||||
this.get(MassiveCore.INSTANCE, true);
|
||||
}
|
||||
|
||||
}
|
@@ -1,48 +0,0 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import com.massivecraft.factions.Const;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.massivecore.Aspect;
|
||||
import com.massivecraft.massivecore.MassiveCore;
|
||||
|
||||
public class UConfColls extends XColls<UConfColl, UConf>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static UConfColls i = new UConfColls();
|
||||
public static UConfColls get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: COLLS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public UConfColl createColl(String collName)
|
||||
{
|
||||
return new UConfColl(collName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Aspect getAspect()
|
||||
{
|
||||
return Factions.get().getAspect();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBasename()
|
||||
{
|
||||
return Const.COLLECTION_UCONF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UConf get2(Object worldNameExtractable)
|
||||
{
|
||||
UConfColl coll = this.get(worldNameExtractable);
|
||||
if (coll == null) return null;
|
||||
return coll.get(MassiveCore.INSTANCE);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,796 +0,0 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.massivecraft.factions.EconomyParticipator;
|
||||
import com.massivecraft.factions.FFlag;
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Lang;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.RelationParticipator;
|
||||
import com.massivecraft.factions.event.EventFactionsChunkChange;
|
||||
import com.massivecraft.factions.event.EventFactionsMembershipChange;
|
||||
import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason;
|
||||
import com.massivecraft.factions.util.RelationUtil;
|
||||
import com.massivecraft.massivecore.mixin.Mixin;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.ps.PSFormatHumanSpace;
|
||||
import com.massivecraft.massivecore.store.SenderEntity;
|
||||
import com.massivecraft.massivecore.util.IdUtil;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
|
||||
public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipator
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// META
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static UPlayer get(Object oid)
|
||||
{
|
||||
return UPlayerColls.get().get2(oid);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: ENTITY
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public UPlayer load(UPlayer that)
|
||||
{
|
||||
this.setFactionId(that.factionId);
|
||||
this.setRole(that.role);
|
||||
this.setTitle(that.title);
|
||||
this.setPowerBoost(that.powerBoost);
|
||||
this.setPower(that.power);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDefault()
|
||||
{
|
||||
if (this.hasFaction()) return false;
|
||||
// Role means nothing without a faction.
|
||||
// Title means nothing without a faction.
|
||||
if (this.getPowerRounded() != (int) Math.round(UConf.get(this).defaultPlayerPower)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postAttach(String id)
|
||||
{
|
||||
// If inited ...
|
||||
if (!Factions.get().isDatabaseInitialized()) return;
|
||||
|
||||
// ... update the index.
|
||||
Faction faction = this.getFaction();
|
||||
faction.uplayers.add(this);
|
||||
|
||||
//Factions.get().log(Txt.parse("<g>postAttach added <h>%s <i>aka <h>%s <i>to <h>%s <i>aka <h>%s<i>.", id, Mixin.getDisplayName(id), faction.getId(), faction.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preDetach(String id)
|
||||
{
|
||||
// If inited ...
|
||||
if (!Factions.get().isDatabaseInitialized()) return;
|
||||
|
||||
// ... update the index.
|
||||
Faction faction = this.getFaction();
|
||||
faction.uplayers.remove(this);
|
||||
|
||||
//Factions.get().log(Txt.parse("<b>preDetach removed <h>%s <i>aka <h>%s <i>to <h>%s <i>aka <h>%s<i>.", id, Mixin.getDisplayName(id), faction.getId(), faction.getName()));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS: RAW
|
||||
// -------------------------------------------- //
|
||||
// In this section of the source code we place the field declarations only.
|
||||
// Each field has it's own section further down since just the getter and setter logic takes up quite some place.
|
||||
|
||||
// This is a foreign key.
|
||||
// Each player belong to a faction.
|
||||
// Null means default for the universe.
|
||||
private String factionId = null;
|
||||
|
||||
// What role does the player have in the faction?
|
||||
// Null means default for the universe.
|
||||
private Rel role = null;
|
||||
|
||||
// What title does the player have in the faction?
|
||||
// The title is just for fun. It's not connected to any game mechanic.
|
||||
// The player title is similar to the faction description.
|
||||
//
|
||||
// Question: Can the title contain chat colors?
|
||||
// Answer: Yes but in such case the policy is that they already must be parsed using Txt.parse.
|
||||
// If the title contains raw markup, such as "<white>" instead of "§f" it will not be parsed and "<white>" will be displayed.
|
||||
//
|
||||
// Null means the player has no title.
|
||||
private String title = null;
|
||||
|
||||
// Player usually do not have a powerboost. It defaults to 0.
|
||||
// The powerBoost is a custom increase/decrease to default and maximum power.
|
||||
// Note that player powerBoost and faction powerBoost are very similar.
|
||||
private Double powerBoost = null;
|
||||
|
||||
// Each player has an individual power level.
|
||||
// The power level for online players is occasionally updated by a recurring task and the power should stay the same for offline players.
|
||||
// For that reason the value is to be considered correct when you pick it. Do not call the power update method.
|
||||
// Null means default for the universe.
|
||||
private Double power = null;
|
||||
|
||||
// The id for the faction this uplayer is currently autoclaiming for.
|
||||
// NOTE: This field will not be saved to the database ever.
|
||||
// Null means the player isn't auto claiming.
|
||||
private transient Faction autoClaimFaction = null;
|
||||
public Faction getAutoClaimFaction() { return this.autoClaimFaction; }
|
||||
public void setAutoClaimFaction(Faction autoClaimFaction) { this.autoClaimFaction = autoClaimFaction; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS: MULTIVERSE PROXY
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean isMapAutoUpdating() { return MPlayer.get(this).isMapAutoUpdating(); }
|
||||
public void setMapAutoUpdating(boolean mapAutoUpdating) { MPlayer.get(this).setMapAutoUpdating(mapAutoUpdating); }
|
||||
|
||||
public boolean isUsingAdminMode() { return MPlayer.get(this).isUsingAdminMode(); }
|
||||
public void setUsingAdminMode(boolean usingAdminMode) { MPlayer.get(this).setUsingAdminMode(usingAdminMode); }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CORE UTILITIES
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void resetFactionData()
|
||||
{
|
||||
// The default neutral faction
|
||||
this.setFactionId(null);
|
||||
this.setRole(null);
|
||||
this.setTitle(null);
|
||||
this.setAutoClaimFaction(null);
|
||||
}
|
||||
|
||||
/*
|
||||
public boolean isPresent(boolean requireFetchable)
|
||||
{
|
||||
if (!this.isOnline()) return false;
|
||||
|
||||
if (requireFetchable)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PS ps = Mixin.getSenderPs(this.getId());
|
||||
if (ps == null) return false;
|
||||
|
||||
String psUniverse = Factions.get().getMultiverse().getUniverseForWorldName(ps.getWorld());
|
||||
if (!psUniverse.equals(this.getUniverse())) return false;
|
||||
|
||||
if (!requireFetchable) return true;
|
||||
|
||||
Player player = this.getPlayer();
|
||||
if (player == null) return false;
|
||||
|
||||
if (player.isDead()) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELD: factionId
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String getDefaultFactionId()
|
||||
{
|
||||
return UConf.get(this).defaultPlayerFactionId;
|
||||
}
|
||||
|
||||
// This method never returns null
|
||||
public String getFactionId()
|
||||
{
|
||||
if (this.factionId == null) return this.getDefaultFactionId();
|
||||
return this.factionId;
|
||||
}
|
||||
|
||||
// This method never returns null
|
||||
public Faction getFaction()
|
||||
{
|
||||
Faction ret = FactionColls.get().get(this).get(this.getFactionId());
|
||||
if (ret == null) ret = FactionColls.get().get(this).get(UConf.get(this).defaultPlayerFactionId);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public boolean hasFaction()
|
||||
{
|
||||
return !this.getFactionId().equals(UConf.get(this).factionIdNone);
|
||||
}
|
||||
|
||||
// This setter is so long because it search for default/null case and takes care of updating the faction member index
|
||||
public void setFactionId(String factionId)
|
||||
{
|
||||
// Clean input
|
||||
String target = factionId;
|
||||
|
||||
// Detect Nochange
|
||||
if (MUtil.equals(this.factionId, target)) return;
|
||||
|
||||
// Get the raw old value
|
||||
String oldFactionId = this.factionId;
|
||||
|
||||
// Apply
|
||||
this.factionId = target;
|
||||
|
||||
// Must be attached and initialized
|
||||
if (!this.attached()) return;
|
||||
if (!Factions.get().isDatabaseInitialized()) return;
|
||||
|
||||
if (oldFactionId == null) oldFactionId = this.getDefaultFactionId();
|
||||
|
||||
// Update index
|
||||
Faction oldFaction = FactionColls.get().get(this).get(oldFactionId);
|
||||
Faction faction = this.getFaction();
|
||||
|
||||
if (oldFaction != null) oldFaction.uplayers.remove(this);
|
||||
if (faction != null) faction.uplayers.add(this);
|
||||
|
||||
String oldFactionIdDesc = "NULL";
|
||||
String oldFactionNameDesc = "NULL";
|
||||
if (oldFaction != null)
|
||||
{
|
||||
oldFactionIdDesc = oldFaction.getId();
|
||||
oldFactionNameDesc = oldFaction.getName();
|
||||
}
|
||||
String factionIdDesc = "NULL";
|
||||
String factionNameDesc = "NULL";
|
||||
if (faction != null)
|
||||
{
|
||||
factionIdDesc = faction.getId();
|
||||
factionNameDesc = faction.getName();
|
||||
}
|
||||
|
||||
Factions.get().log(Txt.parse("<i>setFactionId moved <h>%s <i>aka <h>%s <i>from <h>%s <i>aka <h>%s <i>to <h>%s <i>aka <h>%s<i>.", this.getId(), this.getDisplayName(IdUtil.getConsole()), oldFactionIdDesc, oldFactionNameDesc, factionIdDesc, factionNameDesc));
|
||||
|
||||
// Mark as changed
|
||||
this.changed();
|
||||
}
|
||||
|
||||
public void setFaction(Faction faction)
|
||||
{
|
||||
this.setFactionId(faction.getId());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELD: role
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Rel getDefaultRole()
|
||||
{
|
||||
return UConf.get(this).defaultPlayerRole;
|
||||
}
|
||||
|
||||
public Rel getRole()
|
||||
{
|
||||
if (this.role == null) return this.getDefaultRole();
|
||||
return this.role;
|
||||
}
|
||||
|
||||
public void setRole(Rel role)
|
||||
{
|
||||
// Clean input
|
||||
Rel target = role;
|
||||
|
||||
// Detect Nochange
|
||||
if (MUtil.equals(this.role, target)) return;
|
||||
|
||||
// Apply
|
||||
this.role = target;
|
||||
|
||||
// Mark as changed
|
||||
this.changed();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELD: title
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean hasTitle()
|
||||
{
|
||||
return this.title != null;
|
||||
}
|
||||
|
||||
public String getTitle()
|
||||
{
|
||||
if (this.hasTitle()) return this.title;
|
||||
return Lang.PLAYER_NOTITLE;
|
||||
}
|
||||
|
||||
public void setTitle(String title)
|
||||
{
|
||||
// Clean input
|
||||
String target = title;
|
||||
if (target != null)
|
||||
{
|
||||
target = target.trim();
|
||||
if (target.length() == 0)
|
||||
{
|
||||
target = null;
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: That we parse the title here is considered part of the 1.8 --> 2.0 migration.
|
||||
// This should be removed once the migration phase is considered to be over.
|
||||
if (target != null)
|
||||
{
|
||||
target = Txt.parse(target);
|
||||
}
|
||||
|
||||
// Detect Nochange
|
||||
if (MUtil.equals(this.title, target)) return;
|
||||
|
||||
// Apply
|
||||
this.title = target;
|
||||
|
||||
// Mark as changed
|
||||
this.changed();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELD: powerBoost
|
||||
// -------------------------------------------- //
|
||||
|
||||
public double getPowerBoost()
|
||||
{
|
||||
Double ret = this.powerBoost;
|
||||
if (ret == null) ret = 0D;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void setPowerBoost(Double powerBoost)
|
||||
{
|
||||
// Clean input
|
||||
Double target = powerBoost;
|
||||
if (target == null || target == 0) target = null;
|
||||
|
||||
// Detect Nochange
|
||||
if (MUtil.equals(this.powerBoost, target)) return;
|
||||
|
||||
// Apply
|
||||
this.powerBoost = target;
|
||||
|
||||
// Mark as changed
|
||||
this.changed();
|
||||
}
|
||||
|
||||
public boolean hasPowerBoost()
|
||||
{
|
||||
return this.getPowerBoost() != 0D;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// 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;
|
||||
}
|
||||
|
||||
public int getPowerMaxRounded()
|
||||
{
|
||||
return (int) Math.round(this.getPowerMax());
|
||||
}
|
||||
|
||||
public int getPowerMinRounded()
|
||||
{
|
||||
return (int) Math.round(this.getPowerMin());
|
||||
}
|
||||
|
||||
public int getPowerMaxUniversalRounded()
|
||||
{
|
||||
return (int) Math.round(this.getPowerMaxUniversal());
|
||||
}
|
||||
|
||||
// RAW
|
||||
|
||||
public double getDefaultPower()
|
||||
{
|
||||
return UConf.get(this).defaultPlayerPower;
|
||||
}
|
||||
|
||||
public double getPower()
|
||||
{
|
||||
Double ret = this.power;
|
||||
if (ret == null) ret = this.getDefaultPower();
|
||||
ret = this.getLimitedPower(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void setPower(Double power)
|
||||
{
|
||||
// Clean input
|
||||
Double target = power;
|
||||
|
||||
// Detect Nochange
|
||||
if (MUtil.equals(this.power, target)) return;
|
||||
|
||||
// Apply
|
||||
this.power = target;
|
||||
|
||||
// Mark as changed
|
||||
this.changed();
|
||||
}
|
||||
|
||||
// FINER
|
||||
|
||||
public int getPowerRounded()
|
||||
{
|
||||
return (int) Math.round(this.getPower());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// TITLE, NAME, FACTION NAME AND CHAT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String getFactionName()
|
||||
{
|
||||
Faction faction = this.getFaction();
|
||||
if (faction.isNone()) return "";
|
||||
return faction.getName();
|
||||
}
|
||||
|
||||
// Base concatenations:
|
||||
|
||||
public String getNameAndSomething(String color, String something)
|
||||
{
|
||||
String ret = "";
|
||||
ret += color;
|
||||
ret += this.getRole().getPrefix();
|
||||
if (something != null && something.length() > 0)
|
||||
{
|
||||
ret += something;
|
||||
ret += " ";
|
||||
ret += color;
|
||||
}
|
||||
ret += this.getName();
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String getNameAndFactionName()
|
||||
{
|
||||
return this.getNameAndSomething("", this.getFactionName());
|
||||
}
|
||||
|
||||
public String getNameAndTitle(String color)
|
||||
{
|
||||
if (this.hasTitle())
|
||||
{
|
||||
return this.getNameAndSomething(color, this.getTitle());
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.getNameAndSomething(color, null);
|
||||
}
|
||||
}
|
||||
|
||||
// Colored concatenations:
|
||||
// These are used in information messages
|
||||
|
||||
public String getNameAndTitle(Faction faction)
|
||||
{
|
||||
return this.getNameAndTitle(this.getColorTo(faction).toString());
|
||||
}
|
||||
public String getNameAndTitle(UPlayer uplayer)
|
||||
{
|
||||
return this.getNameAndTitle(this.getColorTo(uplayer).toString());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// RELATION AND RELATION COLORS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String describeTo(RelationParticipator observer, boolean ucfirst)
|
||||
{
|
||||
return RelationUtil.describeThatToMe(this, observer, ucfirst);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeTo(RelationParticipator observer)
|
||||
{
|
||||
return RelationUtil.describeThatToMe(this, observer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rel getRelationTo(RelationParticipator observer)
|
||||
{
|
||||
return RelationUtil.getRelationOfThatToMe(this, observer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rel getRelationTo(RelationParticipator observer, boolean ignorePeaceful)
|
||||
{
|
||||
return RelationUtil.getRelationOfThatToMe(this, observer, ignorePeaceful);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatColor getColorTo(RelationParticipator observer)
|
||||
{
|
||||
return RelationUtil.getColorOfThatToMe(this, observer);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// HEALTH
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void heal(int amnt)
|
||||
{
|
||||
Player player = this.getPlayer();
|
||||
if (player == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
player.setHealth(player.getHealth() + amnt);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// TERRITORY
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean isInOwnTerritory()
|
||||
{
|
||||
PS ps = Mixin.getSenderPs(this.getId());
|
||||
if (ps == null) return false;
|
||||
return BoardColls.get().getFactionAt(ps) == this.getFaction();
|
||||
}
|
||||
|
||||
public boolean isInEnemyTerritory()
|
||||
{
|
||||
PS ps = Mixin.getSenderPs(this.getId());
|
||||
if (ps == null) return false;
|
||||
return BoardColls.get().getFactionAt(ps).getRelationTo(this) == Rel.ENEMY;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ACTIONS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void leave()
|
||||
{
|
||||
Faction myFaction = this.getFaction();
|
||||
|
||||
boolean permanent = myFaction.getFlag(FFlag.PERMANENT);
|
||||
|
||||
if (myFaction.getUPlayers().size() > 1)
|
||||
{
|
||||
if (!permanent && this.getRole() == Rel.LEADER)
|
||||
{
|
||||
msg("<b>You must give the leader role to someone else first.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!UConf.get(myFaction).canLeaveWithNegativePower && this.getPower() < 0)
|
||||
{
|
||||
msg("<b>You cannot leave until your power is positive.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Event
|
||||
EventFactionsMembershipChange membershipChangeEvent = new EventFactionsMembershipChange(this.getSender(), this, myFaction, MembershipChangeReason.LEAVE);
|
||||
membershipChangeEvent.run();
|
||||
if (membershipChangeEvent.isCancelled()) return;
|
||||
|
||||
if (myFaction.isNormal())
|
||||
{
|
||||
for (UPlayer uplayer : myFaction.getUPlayersWhereOnline(true))
|
||||
{
|
||||
uplayer.msg("%s<i> left %s<i>.", this.describeTo(uplayer, true), myFaction.describeTo(uplayer));
|
||||
}
|
||||
|
||||
if (MConf.get().logFactionLeave)
|
||||
{
|
||||
Factions.get().log(this.getName()+" left the faction: "+myFaction.getName());
|
||||
}
|
||||
}
|
||||
|
||||
this.resetFactionData();
|
||||
|
||||
if (myFaction.isNormal() && !permanent && myFaction.getUPlayers().isEmpty())
|
||||
{
|
||||
// Remove this faction
|
||||
for (UPlayer uplayer : UPlayerColls.get().get(this).getAllOnline())
|
||||
{
|
||||
uplayer.msg("<i>%s<i> was disbanded.", myFaction.describeTo(uplayer, true));
|
||||
}
|
||||
|
||||
if (MConf.get().logFactionDisband)
|
||||
{
|
||||
Factions.get().log("The faction "+myFaction.getName()+" ("+myFaction.getId()+") was disbanded due to the last player ("+this.getName()+") leaving.");
|
||||
}
|
||||
myFaction.detach();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean tryClaim(Faction newFaction, PS ps, boolean verbooseChange, boolean verbooseSame)
|
||||
{
|
||||
PS chunk = ps.getChunk(true);
|
||||
Faction oldFaction = BoardColls.get().getFactionAt(chunk);
|
||||
|
||||
UConf uconf = UConf.get(newFaction);
|
||||
MConf mconf = MConf.get();
|
||||
|
||||
// Validate
|
||||
if (newFaction == oldFaction)
|
||||
{
|
||||
msg("%s<i> already owns this land.", newFaction.describeTo(this, true));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!this.isUsingAdminMode())
|
||||
{
|
||||
if (newFaction.isNormal())
|
||||
{
|
||||
if (mconf.getWorldsNoClaiming().contains(ps.getWorld()))
|
||||
{
|
||||
msg("<b>Sorry, this world has land claiming disabled.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!FPerm.TERRITORY.has(this, newFaction, true))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newFaction.getUPlayers().size() < uconf.claimsRequireMinFactionMembers)
|
||||
{
|
||||
msg("Factions must have at least <h>%s<b> members to claim land.", uconf.claimsRequireMinFactionMembers);
|
||||
return false;
|
||||
}
|
||||
|
||||
int ownedLand = newFaction.getLandCount();
|
||||
|
||||
if (uconf.claimedLandsMax != 0 && ownedLand >= uconf.claimedLandsMax && ! newFaction.getFlag(FFlag.INFPOWER))
|
||||
{
|
||||
msg("<b>Limit reached. You can't claim more land.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ownedLand >= newFaction.getPowerRounded())
|
||||
{
|
||||
msg("<b>You can't claim more land. You need more power.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if
|
||||
(
|
||||
uconf.claimsMustBeConnected
|
||||
&&
|
||||
newFaction.getLandCountInWorld(ps.getWorld()) > 0
|
||||
&&
|
||||
!BoardColls.get().isConnectedPs(chunk, newFaction)
|
||||
&&
|
||||
(!uconf.claimsCanBeUnconnectedIfOwnedByOtherFaction || oldFaction.isNone())
|
||||
)
|
||||
{
|
||||
if (uconf.claimsCanBeUnconnectedIfOwnedByOtherFaction)
|
||||
{
|
||||
msg("<b>You can only claim additional land which is connected to your first claim or controlled by another faction!");
|
||||
}
|
||||
else
|
||||
{
|
||||
msg("<b>You can only claim additional land which is connected to your first claim!");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (oldFaction.isNormal())
|
||||
{
|
||||
if (!FPerm.TERRITORY.has(this, oldFaction, false))
|
||||
{
|
||||
if (!uconf.claimingFromOthersAllowed)
|
||||
{
|
||||
msg("<b>You may not claim land from others.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (oldFaction.getRelationTo(newFaction).isAtLeast(Rel.TRUCE))
|
||||
{
|
||||
msg("<b>You can't claim this land due to your relation with the current owner.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!oldFaction.hasLandInflation())
|
||||
{
|
||||
msg("%s<i> owns this land and is strong enough to keep it.", oldFaction.getName(this));
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! BoardColls.get().isBorderPs(chunk))
|
||||
{
|
||||
msg("<b>You must start claiming land at the border of the territory.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Event
|
||||
EventFactionsChunkChange event = new EventFactionsChunkChange(this.getSender(), chunk, newFaction);
|
||||
event.run();
|
||||
if (event.isCancelled()) return false;
|
||||
|
||||
// Apply
|
||||
BoardColls.get().setFactionAt(chunk, newFaction);
|
||||
|
||||
// Inform
|
||||
Set<UPlayer> informees = new HashSet<UPlayer>();
|
||||
informees.add(this);
|
||||
if (newFaction.isNormal())
|
||||
{
|
||||
informees.addAll(newFaction.getUPlayers());
|
||||
}
|
||||
if (oldFaction.isNormal())
|
||||
{
|
||||
informees.addAll(oldFaction.getUPlayers());
|
||||
}
|
||||
if (MConf.get().logLandClaims)
|
||||
{
|
||||
informees.add(UPlayer.get(IdUtil.getConsole()));
|
||||
}
|
||||
|
||||
String chunkString = chunk.toString(PSFormatHumanSpace.get());
|
||||
String typeString = event.getType().toString().toLowerCase();
|
||||
for (UPlayer informee : informees)
|
||||
{
|
||||
informee.msg("<h>%s<i> did %s %s <i>for <h>%s<i> from <h>%s<i>.", this.describeTo(informee, true), typeString, chunkString, newFaction.describeTo(informee), oldFaction.describeTo(informee));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@@ -1,77 +0,0 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.massivecore.mixin.Mixin;
|
||||
import com.massivecraft.massivecore.store.MStore;
|
||||
import com.massivecraft.massivecore.store.SenderColl;
|
||||
import com.massivecraft.massivecore.util.IdUtil;
|
||||
import com.massivecraft.massivecore.util.TimeUnit;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class UPlayerColl extends SenderColl<UPlayer>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public UPlayerColl(String name)
|
||||
{
|
||||
super(name, UPlayer.class, MStore.getDb(), Factions.get());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// EXTRAS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void clean()
|
||||
{
|
||||
FactionColl factionColl = FactionColls.get().get(this);
|
||||
String universe = this.getUniverse();
|
||||
for (UPlayer uplayer : this.getAll())
|
||||
{
|
||||
String factionId = uplayer.getFactionId();
|
||||
if (factionColl.containsId(factionId)) continue;
|
||||
|
||||
uplayer.resetFactionData();
|
||||
|
||||
String message = Txt.parse("<i>Reset data for <h>%s <i>in <h>%s <i>universe. Unknown factionId <h>%s", uplayer.getDisplayName(IdUtil.getConsole()), universe, factionId);
|
||||
Factions.get().log(message);
|
||||
}
|
||||
}
|
||||
|
||||
public void removePlayerDataAfterInactiveDaysRoutine()
|
||||
{
|
||||
if (MConf.get().removePlayerDataAfterInactiveDays <= 0.0) return;
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
double toleranceMillis = MConf.get().removePlayerDataAfterInactiveDays * TimeUnit.MILLIS_PER_DAY;
|
||||
|
||||
for (UPlayer uplayer : this.getAll())
|
||||
{
|
||||
Long lastPlayed = Mixin.getLastPlayed(uplayer.getId());
|
||||
if (lastPlayed == null) continue;
|
||||
|
||||
if (uplayer.isOnline()) continue;
|
||||
if (now - lastPlayed <= toleranceMillis) continue;
|
||||
|
||||
if (MConf.get().logFactionLeave || MConf.get().logFactionKick)
|
||||
{
|
||||
Factions.get().log("Player "+uplayer.getName()+" was auto-removed due to inactivity.");
|
||||
}
|
||||
|
||||
// if player is faction leader, sort out the faction since he's going away
|
||||
if (uplayer.getRole() == Rel.LEADER)
|
||||
{
|
||||
Faction faction = uplayer.getFaction();
|
||||
if (faction != null)
|
||||
{
|
||||
uplayer.getFaction().promoteNewLeader();
|
||||
}
|
||||
}
|
||||
|
||||
uplayer.leave();
|
||||
uplayer.detach();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,95 +0,0 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.massivecraft.factions.Const;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.massivecore.Aspect;
|
||||
import com.massivecraft.massivecore.MassiveCore;
|
||||
import com.massivecraft.massivecore.util.DiscUtil;
|
||||
import com.massivecraft.massivecore.xlib.gson.reflect.TypeToken;
|
||||
|
||||
public class UPlayerColls extends XColls<UPlayerColl, UPlayer>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static UPlayerColls i = new UPlayerColls();
|
||||
public static UPlayerColls get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: COLLS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public UPlayerColl createColl(String collName)
|
||||
{
|
||||
return new UPlayerColl(collName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Aspect getAspect()
|
||||
{
|
||||
return Factions.get().getAspect();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBasename()
|
||||
{
|
||||
return Const.COLLECTION_UPLAYER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
super.init();
|
||||
|
||||
this.migrate();
|
||||
}
|
||||
|
||||
// This method is for the 1.8.X --> 2.0.0 migration
|
||||
public void migrate()
|
||||
{
|
||||
// Create file objects
|
||||
File oldFile = new File(Factions.get().getDataFolder(), "players.json");
|
||||
File newFile = new File(Factions.get().getDataFolder(), "players.json.migrated");
|
||||
|
||||
// Already migrated?
|
||||
if ( ! oldFile.exists()) return;
|
||||
|
||||
// Read the file content through GSON.
|
||||
Type type = new TypeToken<Map<String, UPlayer>>(){}.getType();
|
||||
Map<String, UPlayer> id2uplayer = Factions.get().gson.fromJson(DiscUtil.readCatch(oldFile), type);
|
||||
|
||||
// The Coll
|
||||
UPlayerColl coll = this.getForUniverse(MassiveCore.DEFAULT);
|
||||
|
||||
// Set the data
|
||||
for (Entry<String, UPlayer> entry : id2uplayer.entrySet())
|
||||
{
|
||||
String playerId = entry.getKey();
|
||||
UPlayer uplayer = entry.getValue();
|
||||
coll.attach(uplayer, playerId);
|
||||
}
|
||||
|
||||
// Mark as migrated
|
||||
oldFile.renameTo(newFile);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// EXTRAS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void clean()
|
||||
{
|
||||
for (UPlayerColl coll : this.getColls())
|
||||
{
|
||||
coll.clean();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,42 +0,0 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.massivecraft.massivecore.store.Coll;
|
||||
import com.massivecraft.massivecore.store.Colls;
|
||||
import com.massivecraft.massivecore.store.Entity;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
|
||||
public abstract class XColls<C extends Coll<E>, E> extends Colls<C, E>
|
||||
{
|
||||
@Override
|
||||
public C get(Object o)
|
||||
{
|
||||
if (o == null) return null;
|
||||
|
||||
if (o instanceof Entity)
|
||||
{
|
||||
String universe = ((Entity<?>)o).getUniverse();
|
||||
if (universe == null) return null;
|
||||
return this.getForUniverse(universe);
|
||||
}
|
||||
|
||||
if (o instanceof Coll)
|
||||
{
|
||||
String universe = ((Coll<?>)o).getUniverse();
|
||||
if (universe == null) return null;
|
||||
return this.getForUniverse(universe);
|
||||
}
|
||||
|
||||
if ((o instanceof CommandSender) && !(o instanceof Player))
|
||||
{
|
||||
return this.getForWorld(Bukkit.getWorlds().get(0).getName());
|
||||
}
|
||||
|
||||
String worldName = MUtil.extract(String.class, "worldName", o);
|
||||
if (worldName == null) return null;
|
||||
return this.getForWorld(worldName);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user