Maven Attempt 1

This commit is contained in:
Olof Larsson
2014-09-13 00:50:33 +02:00
parent 3debf17f27
commit 13a4afdfb4
170 changed files with 151 additions and 49 deletions

View File

@ -1,345 +0,0 @@
package com.massivecraft.factions.entity;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentSkipListMap;
import org.bukkit.ChatColor;
import com.massivecraft.factions.Const;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.RelationParticipator;
import com.massivecraft.factions.TerritoryAccess;
import com.massivecraft.factions.util.AsciiCompass;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.store.Entity;
import com.massivecraft.massivecore.util.Txt;
import com.massivecraft.massivecore.xlib.gson.reflect.TypeToken;
public class Board extends Entity<Board> implements BoardInterface
{
public static final transient Type MAP_TYPE = new TypeToken<Map<PS, TerritoryAccess>>(){}.getType();
// -------------------------------------------- //
// META
// -------------------------------------------- //
public static Board get(Object oid)
{
return BoardColls.get().get2(oid);
}
// -------------------------------------------- //
// OVERRIDE: ENTITY
// -------------------------------------------- //
@Override
public Board load(Board that)
{
this.map = that.map;
return this;
}
@Override
public boolean isDefault()
{
if (this.map == null) return true;
if (this.map.isEmpty()) return true;
return false;
}
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
// TODO: Make TerritoryAccess immutable.
private ConcurrentSkipListMap<PS, TerritoryAccess> map;
public Map<PS, TerritoryAccess> getMap() { return Collections.unmodifiableMap(this.map); }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public Board()
{
this.map = new ConcurrentSkipListMap<PS, TerritoryAccess>();
}
public Board(Map<PS, TerritoryAccess> map)
{
this.map = new ConcurrentSkipListMap<PS, TerritoryAccess>(map);
}
// -------------------------------------------- //
// OVERRIDE: BOARD
// -------------------------------------------- //
// GET
@Override
public TerritoryAccess getTerritoryAccessAt(PS ps)
{
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);
return ret;
}
@Override
public Faction getFactionAt(PS ps)
{
if (ps == null) return null;
TerritoryAccess ta = this.getTerritoryAccessAt(ps);
return ta.getHostFaction(this);
}
// SET
@Override
public void setTerritoryAccessAt(PS ps, TerritoryAccess territoryAccess)
{
ps = ps.getChunkCoords(true);
if (territoryAccess == null || (territoryAccess.getHostFactionId().equals(UConf.get(this).factionIdNone) && territoryAccess.isDefault()))
{
this.map.remove(ps);
}
else
{
this.map.put(ps, territoryAccess);
}
this.changed();
}
@Override
public void setFactionAt(PS ps, Faction faction)
{
TerritoryAccess territoryAccess = null;
if (faction != null)
{
territoryAccess = TerritoryAccess.valueOf(faction.getId());
}
this.setTerritoryAccessAt(ps, territoryAccess);
}
// REMOVE
@Override
public void removeAt(PS ps)
{
this.setTerritoryAccessAt(ps, null);
}
@Override
public void removeAll(Faction faction)
{
String factionId = faction.getId();
for (Entry<PS, TerritoryAccess> entry : this.map.entrySet())
{
TerritoryAccess territoryAccess = entry.getValue();
if ( ! territoryAccess.getHostFactionId().equals(factionId)) continue;
PS ps = entry.getKey();
this.removeAt(ps);
}
}
// Removes orphaned foreign keys
@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;
PS ps = entry.getKey();
this.removeAt(ps);
Factions.get().log("Board cleaner removed "+factionId+" from "+ps);
}
}
// CHUNKS
@Override
public Set<PS> getChunks(Faction faction)
{
return this.getChunks(faction.getId());
}
public Set<PS> getChunks(String factionId)
{
Set<PS> ret = new HashSet<PS>();
for (Entry<PS, TerritoryAccess> entry : this.map.entrySet())
{
TerritoryAccess ta = entry.getValue();
if (!ta.getHostFactionId().equals(factionId)) continue;
PS ps = entry.getKey();
ps = ps.withWorld(this.getId());
ret.add(ps);
}
return ret;
}
// COUNT
@Override
public int getCount(Faction faction)
{
return this.getCount(faction.getId());
}
public int getCount(String factionId)
{
int ret = 0;
for (TerritoryAccess ta : this.map.values())
{
if (!ta.getHostFactionId().equals(factionId)) continue;
ret += 1;
}
return ret;
}
// NEARBY DETECTION
// Is this coord NOT completely surrounded by coords claimed by the same faction?
// Simpler: Is there any nearby coord with a faction other than the faction here?
@Override
public boolean isBorderPs(PS ps)
{
ps = ps.getChunk(true);
PS nearby = null;
Faction faction = this.getFactionAt(ps);
nearby = ps.withChunkX(ps.getChunkX() +1);
if (faction != this.getFactionAt(nearby)) return true;
nearby = ps.withChunkX(ps.getChunkX() -1);
if (faction != this.getFactionAt(nearby)) return true;
nearby = ps.withChunkZ(ps.getChunkZ() +1);
if (faction != this.getFactionAt(nearby)) return true;
nearby = ps.withChunkZ(ps.getChunkZ() -1);
if (faction != this.getFactionAt(nearby)) return true;
return false;
}
// Is this coord connected to any coord claimed by the specified faction?
@Override
public boolean isConnectedPs(PS ps, Faction faction)
{
ps = ps.getChunk(true);
PS nearby = null;
nearby = ps.withChunkX(ps.getChunkX() +1);
if (faction == this.getFactionAt(nearby)) return true;
nearby = ps.withChunkX(ps.getChunkX() -1);
if (faction == this.getFactionAt(nearby)) return true;
nearby = ps.withChunkZ(ps.getChunkZ() +1);
if (faction == this.getFactionAt(nearby)) return true;
nearby = ps.withChunkZ(ps.getChunkZ() -1);
if (faction == this.getFactionAt(nearby)) return true;
return false;
}
// MAP GENERATION
@Override
public ArrayList<String> getMap(RelationParticipator observer, PS centerPs, double inDegrees)
{
centerPs = centerPs.getChunkCoords(true);
ArrayList<String> ret = new ArrayList<String>();
Faction centerFaction = this.getFactionAt(centerPs);
ret.add(Txt.titleize("("+centerPs.getChunkX() + "," + centerPs.getChunkZ()+") "+centerFaction.getName(observer)));
int halfWidth = Const.MAP_WIDTH / 2;
int halfHeight = Const.MAP_HEIGHT / 2;
PS topLeftPs = centerPs.plusChunkCoords(-halfWidth, -halfHeight);
int width = halfWidth * 2 + 1;
int height = halfHeight * 2 + 1;
// Make room for the list of names
height--;
Map<Faction, Character> fList = new HashMap<Faction, Character>();
int chrIdx = 0;
// For each row
for (int dz = 0; dz < height; dz++)
{
// Draw and add that row
String row = "";
for (int dx = 0; dx < width; dx++)
{
if(dx == halfWidth && dz == halfHeight)
{
row += ChatColor.AQUA+"+";
continue;
}
PS herePs = topLeftPs.plusChunkCoords(dx, dz);
Faction hereFaction = this.getFactionAt(herePs);
if (hereFaction.isNone())
{
row += ChatColor.GRAY+"-";
}
else
{
if (!fList.containsKey(hereFaction))
fList.put(hereFaction, Const.MAP_KEY_CHARS[chrIdx++]);
char fchar = fList.get(hereFaction);
row += hereFaction.getColorTo(observer) + "" + fchar;
}
}
ret.add(row);
}
// Get the compass
ArrayList<String> asciiCompass = AsciiCompass.getAsciiCompass(inDegrees, ChatColor.RED, Txt.parse("<a>"));
// Add the compass
ret.set(1, asciiCompass.get(0)+ret.get(1).substring(3*3));
ret.set(2, asciiCompass.get(1)+ret.get(2).substring(3*3));
ret.set(3, asciiCompass.get(2)+ret.get(3).substring(3*3));
String fRow = "";
for (Faction keyfaction : fList.keySet())
{
fRow += ""+keyfaction.getColorTo(observer) + fList.get(keyfaction) + ": " + keyfaction.getName() + " ";
}
fRow = fRow.trim();
ret.add(fRow);
return ret;
}
}

View File

@ -1,168 +0,0 @@
package com.massivecraft.factions.entity;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.RelationParticipator;
import com.massivecraft.factions.TerritoryAccess;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.store.Coll;
import com.massivecraft.massivecore.store.MStore;
import com.massivecraft.massivecore.util.MUtil;
public class BoardColl extends Coll<Board> implements BoardInterface
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public BoardColl(String name)
{
super(name, Board.class, MStore.getDb(), Factions.get(), false, true, true);
}
// -------------------------------------------- //
// OVERRIDE: COLL
// -------------------------------------------- //
@Override
public String fixId(Object oid)
{
if (oid == null) return null;
if (oid instanceof String) return (String)oid;
if (oid instanceof Board) return this.getId(oid);
return MUtil.extract(String.class, "worldName", oid);
}
// -------------------------------------------- //
// OVERRIDE: BOARD
// -------------------------------------------- //
@Override
public TerritoryAccess getTerritoryAccessAt(PS ps)
{
if (ps == null) return null;
Board board = this.get(ps.getWorld());
if (board == null) return null;
return board.getTerritoryAccessAt(ps);
}
@Override
public Faction getFactionAt(PS ps)
{
if (ps == null) return null;
Board board = this.get(ps.getWorld());
if (board == null) return null;
return board.getFactionAt(ps);
}
// SET
@Override
public void setTerritoryAccessAt(PS ps, TerritoryAccess territoryAccess)
{
if (ps == null) return;
Board board = this.get(ps.getWorld());
if (board == null) return;
board.setTerritoryAccessAt(ps, territoryAccess);
}
@Override
public void setFactionAt(PS ps, Faction faction)
{
if (ps == null) return;
Board board = this.get(ps.getWorld());
if (board == null) return;
board.setFactionAt(ps, faction);
}
// REMOVE
@Override
public void removeAt(PS ps)
{
if (ps == null) return;
Board board = this.get(ps.getWorld());
if (board == null) return;
board.removeAt(ps);
}
@Override
public void removeAll(Faction faction)
{
for (Board board : this.getAll())
{
board.removeAll(faction);
}
}
@Override
public void clean()
{
for (Board board : this.getAll())
{
board.clean();
}
}
// CHUNKS
@Override
public Set<PS> getChunks(Faction faction)
{
Set<PS> ret = new HashSet<PS>();
for (Board board : this.getAll())
{
ret.addAll(board.getChunks(faction));
}
return ret;
}
// COUNT
@Override
public int getCount(Faction faction)
{
int ret = 0;
for (Board board : this.getAll())
{
ret += board.getCount(faction);
}
return ret;
}
// NEARBY DETECTION
@Override
public boolean isBorderPs(PS ps)
{
if (ps == null) return false;
Board board = this.get(ps.getWorld());
if (board == null) return false;
return board.isBorderPs(ps);
}
@Override
public boolean isConnectedPs(PS ps, Faction faction)
{
if (ps == null) return false;
Board board = this.get(ps.getWorld());
if (board == null) return false;
return board.isConnectedPs(ps, faction);
}
// MAP GENERATION
@Override
public ArrayList<String> getMap(RelationParticipator observer, PS centerPs, double inDegrees)
{
if (centerPs == null) return null;
Board board = this.get(centerPs.getWorld());
if (board == null) return null;
return board.getMap(observer, centerPs, inDegrees);
}
}

View File

@ -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);
}
}

View File

@ -1,39 +0,0 @@
package com.massivecraft.factions.entity;
import java.util.ArrayList;
import java.util.Set;
import com.massivecraft.factions.RelationParticipator;
import com.massivecraft.factions.TerritoryAccess;
import com.massivecraft.massivecore.ps.PS;
public interface BoardInterface
{
// GET
public TerritoryAccess getTerritoryAccessAt(PS ps);
public Faction getFactionAt(PS ps);
// SET
public void setTerritoryAccessAt(PS ps, TerritoryAccess territoryAccess);
public void setFactionAt(PS ps, Faction faction);
// REMOVE
public void removeAt(PS ps);
public void removeAll(Faction faction);
public void clean();
// CHUNKS
public Set<PS> getChunks(Faction faction);
// COUNT
public int getCount(Faction faction);
// NEARBY DETECTION
public boolean isBorderPs(PS ps);
public boolean isConnectedPs(PS ps, Faction faction);
// MAP
// TODO: Could the degrees be embedded in centerPs yaw instead?
public ArrayList<String> getMap(RelationParticipator observer, PS centerPs, double inDegrees);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,272 +0,0 @@
package com.massivecraft.factions.entity;
import java.util.*;
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.FFlag;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.util.MiscUtil;
public class FactionColl extends Coll<Faction>
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public FactionColl(String name)
{
super(name, Faction.class, MStore.getDb(), Factions.get());
}
// -------------------------------------------- //
// OVERRIDE: COLL
// -------------------------------------------- //
@Override
public void init()
{
super.init();
this.createSpecialFactions();
}
@Override
public Faction get(Object oid)
{
Faction ret = super.get(oid);
// We should only trigger automatic clean if the whole database system is initialized.
// A cleaning can only be successful if all data is available.
// Example Reason: When creating the special factions for the first time "createSpecialFactions" a clean would be triggered otherwise.
if (ret == null && Factions.get().isDatabaseInitialized())
{
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();
}
return ret;
}
// -------------------------------------------- //
// INDEX
// -------------------------------------------- //
public void reindexUPlayers()
{
for (Faction faction : this.getAll())
{
faction.reindexUPlayers();
}
}
// -------------------------------------------- //
// SPECIAL FACTIONS
// -------------------------------------------- //
public void createSpecialFactions()
{
this.getNone();
this.getSafezone();
this.getWarzone();
}
public Faction getNone()
{
String id = UConf.get(this).factionIdNone;
Faction faction = this.get(id);
if (faction != null) return faction;
faction = this.create(id);
faction.setName(ChatColor.DARK_GREEN+"Wilderness");
faction.setDescription(null);
faction.setOpen(false);
faction.setFlag(FFlag.PERMANENT, true);
faction.setFlag(FFlag.PEACEFUL, false);
faction.setFlag(FFlag.INFPOWER, true);
faction.setFlag(FFlag.POWERLOSS, true);
faction.setFlag(FFlag.PVP, true);
faction.setFlag(FFlag.FRIENDLYFIRE, false);
faction.setFlag(FFlag.MONSTERS, true);
faction.setFlag(FFlag.EXPLOSIONS, true);
faction.setFlag(FFlag.OFFLINE_EXPLOSIONS, true);
faction.setFlag(FFlag.FIRESPREAD, true);
faction.setFlag(FFlag.ENDERGRIEF, true);
faction.setPermittedRelations(FPerm.BUILD, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
faction.setPermittedRelations(FPerm.DOOR, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
faction.setPermittedRelations(FPerm.CONTAINER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
faction.setPermittedRelations(FPerm.BUTTON, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
faction.setPermittedRelations(FPerm.LEVER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
return faction;
}
public Faction getSafezone()
{
String id = UConf.get(this).factionIdSafezone;
Faction faction = this.get(id);
if (faction != null) return faction;
faction = this.create(id);
faction.setName("SafeZone");
faction.setDescription("Free from PVP and monsters");
faction.setOpen(false);
faction.setFlag(FFlag.PERMANENT, true);
faction.setFlag(FFlag.PEACEFUL, true);
faction.setFlag(FFlag.INFPOWER, true);
faction.setFlag(FFlag.POWERLOSS, false);
faction.setFlag(FFlag.PVP, false);
faction.setFlag(FFlag.FRIENDLYFIRE, false);
faction.setFlag(FFlag.MONSTERS, false);
faction.setFlag(FFlag.EXPLOSIONS, false);
faction.setFlag(FFlag.OFFLINE_EXPLOSIONS, false);
faction.setFlag(FFlag.FIRESPREAD, false);
faction.setFlag(FFlag.ENDERGRIEF, false);
faction.setPermittedRelations(FPerm.DOOR, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
faction.setPermittedRelations(FPerm.CONTAINER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
faction.setPermittedRelations(FPerm.BUTTON, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
faction.setPermittedRelations(FPerm.LEVER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
faction.setPermittedRelations(FPerm.TERRITORY, Rel.LEADER, Rel.OFFICER, Rel.MEMBER);
return faction;
}
public Faction getWarzone()
{
String id = UConf.get(this).factionIdWarzone;
Faction faction = this.get(id);
if (faction != null) return faction;
faction = this.create(id);
faction.setName("WarZone");
faction.setDescription("Not the safest place to be");
faction.setOpen(false);
faction.setFlag(FFlag.PERMANENT, true);
faction.setFlag(FFlag.PEACEFUL, true);
faction.setFlag(FFlag.INFPOWER, true);
faction.setFlag(FFlag.POWERLOSS, true);
faction.setFlag(FFlag.PVP, true);
faction.setFlag(FFlag.FRIENDLYFIRE, true);
faction.setFlag(FFlag.MONSTERS, true);
faction.setFlag(FFlag.EXPLOSIONS, true);
faction.setFlag(FFlag.OFFLINE_EXPLOSIONS, true);
faction.setFlag(FFlag.FIRESPREAD, true);
faction.setFlag(FFlag.ENDERGRIEF, true);
faction.setPermittedRelations(FPerm.DOOR, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
faction.setPermittedRelations(FPerm.CONTAINER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
faction.setPermittedRelations(FPerm.BUTTON, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
faction.setPermittedRelations(FPerm.LEVER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
faction.setPermittedRelations(FPerm.TERRITORY, Rel.LEADER, Rel.OFFICER, Rel.MEMBER);
return faction;
}
// -------------------------------------------- //
// LAND REWARD
// -------------------------------------------- //
public void econLandRewardRoutine()
{
if (!Econ.isEnabled(this.getUniverse())) return;
double econLandReward = UConf.get(this).econLandReward;
if (econLandReward == 0.0) return;
Factions.get().log("Running econLandRewardRoutine...");
for (Faction faction : this.getAll())
{
int landCount = faction.getLandCount();
if (!faction.getFlag(FFlag.PEACEFUL) && landCount > 0)
{
List<UPlayer> players = faction.getUPlayers();
int playerCount = players.size();
double reward = econLandReward * landCount / playerCount;
for (UPlayer player : players)
{
Econ.modifyMoney(player, reward, "own " + landCount + " faction land divided among " + playerCount + " members");
}
}
}
}
// -------------------------------------------- //
// FACTION NAME
// -------------------------------------------- //
public ArrayList<String> validateName(String str)
{
ArrayList<String> errors = new ArrayList<String>();
if (MiscUtil.getComparisonString(str).length() < UConf.get(this).factionNameLengthMin)
{
errors.add(Txt.parse("<i>The faction name can't be shorter than <h>%s<i> chars.", UConf.get(this).factionNameLengthMin));
}
if (str.length() > UConf.get(this).factionNameLengthMax)
{
errors.add(Txt.parse("<i>The faction name can't be longer than <h>%s<i> chars.", UConf.get(this).factionNameLengthMax));
}
for (char c : str.toCharArray())
{
if ( ! MiscUtil.substanceChars.contains(String.valueOf(c)))
{
errors.add(Txt.parse("<i>Faction name must be alphanumeric. \"<h>%s<i>\" is not allowed.", c));
}
}
return errors;
}
public Faction getByName(String str)
{
String compStr = MiscUtil.getComparisonString(str);
for (Faction faction : this.getAll())
{
if (faction.getComparisonName().equals(compStr))
{
return faction;
}
}
return null;
}
public Faction getBestNameMatch(String searchFor)
{
Map<String, Faction> name2faction = new HashMap<String, Faction>();
// TODO: Slow index building
for (Faction faction : this.getAll())
{
name2faction.put(ChatColor.stripColor(faction.getName()), faction);
}
String tag = Txt.getBestCIStart(name2faction.keySet(), searchFor);
if (tag == null) return null;
return name2faction.get(tag);
}
public boolean isNameTaken(String str)
{
return this.getByName(str) != null;
}
}

View File

@ -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();
}
}
}

View File

@ -1,338 +0,0 @@
package com.massivecraft.factions.entity;
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 org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventPriority;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.integration.dynmap.DynmapStyle;
import com.massivecraft.factions.listeners.FactionsListenerChat;
import com.massivecraft.massivecore.store.Entity;
import com.massivecraft.massivecore.util.MUtil;
public class MConf extends Entity<MConf>
{
// -------------------------------------------- //
// META
// -------------------------------------------- //
protected static transient MConf i;
public static MConf get() { return i; }
// -------------------------------------------- //
// OVERRIDE: ENTITY
// -------------------------------------------- //
@Override
public MConf load(MConf that)
{
super.load(that);
if (!Factions.get().isDatabaseInitialized()) return this;
FactionsListenerChat.get().setup();
return this;
}
// -------------------------------------------- //
// COMMAND ALIASES
// -------------------------------------------- //
public List<String> aliasesF = MUtil.list("f");
// -------------------------------------------- //
// TASKS
// -------------------------------------------- //
public double taskPlayerPowerUpdateMinutes = 1;
public double taskPlayerDataRemoveMinutes = 5;
public double taskEconLandRewardMinutes = 20;
// -------------------------------------------- //
// REMOVE DATA
// -------------------------------------------- //
public boolean removePlayerDataWhenBanned = true;
public double removePlayerDataAfterInactiveDays = 20.0;
// -------------------------------------------- //
// CLAIM LIMITS
// -------------------------------------------- //
// if someone is doing a radius claim and the process fails to claim land this many times in a row, it will exit
public int radiusClaimFailureLimit = 9;
// the maximum radius allowed when using the claim command.
public int radiusClaimRadiusLimit = 5;
// -------------------------------------------- //
// CHAT
// -------------------------------------------- //
// We offer a simple standard way to set the format
public boolean chatSetFormat = false;
public EventPriority chatSetFormatAt = EventPriority.LOWEST;
public String chatSetFormatTo = "<{factions_relcolor}§l{factions_roleprefix}§r{factions_relcolor}{factions_name|rp}§f%1$s> %2$s";
// We offer a simple standard way to parse the chat tags
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
// -------------------------------------------- //
public ChatColor colorMember = ChatColor.GREEN;
public ChatColor colorAlly = ChatColor.DARK_PURPLE;
public ChatColor colorTruce = ChatColor.LIGHT_PURPLE;
public ChatColor colorNeutral = ChatColor.WHITE;
public ChatColor colorEnemy = ChatColor.RED;
public ChatColor colorNoPVP = ChatColor.GOLD;
public ChatColor colorFriendlyFire = ChatColor.DARK_RED;
//public ChatColor colorWilderness = ChatColor.DARK_GREEN;
// -------------------------------------------- //
// PREFIXES
// -------------------------------------------- //
public String prefixLeader = "**";
public String prefixOfficer = "*";
public String prefixMember = "+";
public String prefixRecruit = "-";
// -------------------------------------------- //
// DERPY OVERRIDES
// -------------------------------------------- //
// TODO: Should worldsNoPowerLoss rather be a bukkit permission node?
// TODO: These are derpy because they possibly use an invalid design approach.
// After universe support is added. Would some of these be removed?
// Could it also be more customizeable using some sort of permission lookup map?
// mainly for other plugins/mods that use a fake player to take actions, which shouldn't be subject to our protections
public Set<String> playersWhoBypassAllProtection = new LinkedHashSet<String>();
public Set<String> worldsNoClaiming = new LinkedHashSet<String>();
public Set<String> getWorldsNoClaiming()
{
Set<String> ret = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
ret.addAll(this.worldsNoClaiming);
return ret;
}
public Set<String> worldsNoPowerLoss = new LinkedHashSet<String>();
public Set<String> getWorldsNoPowerLoss()
{
Set<String> ret = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
ret.addAll(this.worldsNoPowerLoss);
return ret;
}
public Set<String> worldsIgnorePvP = new LinkedHashSet<String>();
public Set<String> getWorldsIgnlorePvP()
{
Set<String> ret = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
ret.addAll(this.worldsIgnorePvP);
return ret;
}
// -------------------------------------------- //
// EXPLOITS
// -------------------------------------------- //
public boolean handleExploitObsidianGenerators = true;
public boolean handleExploitEnderPearlClipping = true;
public boolean handleExploitTNTWaterlog = false;
// -------------------------------------------- //
// LOGGING
// -------------------------------------------- //
public boolean logFactionCreate = true;
public boolean logFactionDisband = true;
public boolean logFactionJoin = true;
public boolean logFactionKick = true;
public boolean logFactionLeave = true;
public boolean logLandClaims = true;
public boolean logLandUnclaims = true;
public boolean logMoneyTransactions = true;
public boolean logPlayerCommands = true;
// -------------------------------------------- //
// ENUMERATIONS
// -------------------------------------------- //
public Set<Material> materialsEditOnInteract = MUtil.set(
Material.DIODE_BLOCK_OFF,
Material.DIODE_BLOCK_ON,
Material.NOTE_BLOCK,
Material.CAULDRON,
Material.SOIL
);
public Set<Material> materialsEditTools = MUtil.set(
Material.FIREBALL,
Material.FLINT_AND_STEEL,
Material.BUCKET,
Material.WATER_BUCKET,
Material.LAVA_BUCKET
);
public Set<Material> materialsDoor = MUtil.set(
Material.WOODEN_DOOR,
Material.TRAP_DOOR,
Material.FENCE_GATE
);
public Set<Material> materialsContainer = MUtil.set(
Material.DISPENSER,
Material.CHEST,
Material.FURNACE,
Material.BURNING_FURNACE,
Material.JUKEBOX,
Material.BREWING_STAND,
Material.ENCHANTMENT_TABLE,
Material.ANVIL,
Material.BEACON,
Material.TRAPPED_CHEST,
Material.HOPPER,
Material.DROPPER
);
public Set<EntityType> entityTypesMonsters = MUtil.set(
EntityType.BLAZE,
EntityType.CAVE_SPIDER,
EntityType.CREEPER,
EntityType.ENDERMAN,
EntityType.ENDER_DRAGON,
EntityType.GHAST,
EntityType.GIANT,
EntityType.MAGMA_CUBE,
EntityType.PIG_ZOMBIE,
EntityType.SILVERFISH,
EntityType.SKELETON,
EntityType.SLIME,
EntityType.SPIDER,
EntityType.WITCH,
EntityType.WITHER,
EntityType.ZOMBIE
);
// -------------------------------------------- //
// DYNMAP
// -------------------------------------------- //
// Should the dynmap intagration be used?
public boolean dynmapUse = true;
// Should the dynmap updates be logged to console output?
public boolean dynmapUpdateLog = false;
// Name of the Factions layer
public String dynmapLayerName = "Factions";
// Should the layer be visible per default
public boolean dynmapLayerVisible = true;
// Ordering priority in layer menu (low goes before high - default is 0)
public int dynmapLayerPriority = 2;
// (optional) set minimum zoom level before layer is visible (0 = defalt, always visible)
public int dynmapLayerMinimumZoom = 0;
// Format for popup - substitute values for macros
//public String dynmapInfowindowFormat = "<div class=\"infowindow\"><span style=\"font-size:120%;\">%regionname%</span><br />Flags<br /><span style=\"font-weight:bold;\">%flags%</span></div>";
public String dynmapDescription =
"<div class=\"infowindow\">\n" +
"<span style=\"font-weight: bold; font-size: 150%;\">%name%</span></br>\n" +
"<span style=\"font-style: italic; font-size: 110%;\">%description%</span></br>\n" +
"</br>\n" +
"<span style=\"font-weight: bold;\">Leader:</span> %players.leader%</br>\n" +
"<span style=\"font-weight: bold;\">Officers:</span> %players.officers.count%</br>\n" +
"<span style=\"font-weight: bold;\">Members:</span> %players.members.count%</br>\n" +
"<span style=\"font-weight: bold;\">Recruits:</span> %players.recruits.count%</br>\n" +
"<span style=\"font-weight: bold;\">TOTAL:</span> %players.count%</br>\n" +
"</br>\n" +
"<span style=\"font-weight: bold;\">Age:</span> %age%</br>\n" +
"<span style=\"font-weight: bold;\">Bank:</span> %money%</br>\n" +
"</br>\n" +
"<span style=\"font-weight: bold;\">Flags:</span></br>\n" +
"%open.color% | %permanent.color% | %peaceful.color% | %infpower.color% | %powerloss.color%</br>\n" +
"%pvp.color% | %friendlyfire.color% | %monsters.color% | %explosions.color%</br>\n" +
"%offlineexplosions.color% | %firespread.color% | %endergrief.color%\n" +
"</div>";
// Enable the %money% macro. Only do this if you know your economy manager is thread safe.
public boolean dynmapDescriptionMoney = false;
// Allow players in faction to see one another on Dynmap (only relevant if Dynmap has 'player-info-protected' enabled)
public boolean dynmapVisibilityByFaction = true;
// Optional setting to limit which regions to show.
// If empty all regions are shown.
// Specify Faction either by name or UUID.
// To show all regions on a given world, add 'world:<worldname>' to the list.
public Set<String> dynmapVisibleFactions = new LinkedHashSet<String>();
// Optional setting to hide specific Factions.
// Specify Faction either by name or UUID.
// To hide all regions on a given world, add 'world:<worldname>' to the list.
public Set<String> dynmapHiddenFactions = new LinkedHashSet<String>();
// Region Style
public final static transient String DYNMAP_STYLE_LINE_COLOR = "#00FF00";
public final static transient double DYNMAP_STYLE_LINE_OPACITY = 0.8D;
public final static transient int DYNMAP_STYLE_LINE_WEIGHT = 3;
public final static transient String DYNMAP_STYLE_FILL_COLOR = "#00FF00";
public final static transient double DYNMAP_STYLE_FILL_OPACITY = 0.35D;
public final static transient String DYNMAP_STYLE_HOME_MARKER = "greenflag";
public final static transient boolean DYNMAP_STYLE_BOOST = false;
public DynmapStyle dynmapDefaultStyle = new DynmapStyle()
.setStrokeColor(DYNMAP_STYLE_LINE_COLOR)
.setLineOpacity(DYNMAP_STYLE_LINE_OPACITY)
.setLineWeight(DYNMAP_STYLE_LINE_WEIGHT)
.setFillColor(DYNMAP_STYLE_FILL_COLOR)
.setFillOpacity(DYNMAP_STYLE_FILL_OPACITY)
.setHomeMarker(DYNMAP_STYLE_HOME_MARKER)
.setBoost(DYNMAP_STYLE_BOOST);
// Optional per Faction style overrides. Any defined replace those in dynmapDefaultStyle.
// Specify Faction either by name or UUID.
public Map<String, DynmapStyle> dynmapFactionStyles = MUtil.map(
"SafeZone", new DynmapStyle().setStrokeColor("#FF00FF").setFillColor("#FF00FF").setBoost(false),
"WarZone", new DynmapStyle().setStrokeColor("#FF0000").setFillColor("#FF0000").setBoost(false)
);
}

View File

@ -1,34 +0,0 @@
package com.massivecraft.factions.entity;
import com.massivecraft.factions.Const;
import com.massivecraft.factions.Factions;
import com.massivecraft.massivecore.MassiveCore;
import com.massivecraft.massivecore.store.Coll;
import com.massivecraft.massivecore.store.MStore;
public class MConfColl extends Coll<MConf>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static MConfColl i = new MConfColl();
public static MConfColl get() { return i; }
private MConfColl()
{
super(Const.COLLECTION_MCONF, MConf.class, MStore.getDb(), Factions.get());
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void init()
{
super.init();
MConf.i = this.get(MassiveCore.INSTANCE, true);
}
}

View File

@ -1,59 +0,0 @@
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(); }
}

View File

@ -1,21 +0,0 @@
package com.massivecraft.factions.entity;
import com.massivecraft.factions.Const;
import com.massivecraft.factions.Factions;
import com.massivecraft.massivecore.store.MStore;
import com.massivecraft.massivecore.store.SenderColl;
public class MPlayerColl extends SenderColl<MPlayer>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static MPlayerColl i = new MPlayerColl();
public static MPlayerColl get() { return i; }
private MPlayerColl()
{
super(Const.COLLECTION_MPLAYER, MPlayer.class, MStore.getDb(), Factions.get());
}
}

View File

@ -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.
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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();
}
}
}

View File

@ -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();
}
}
}

View File

@ -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);
}
}