Fix CRLF on some files: convert all to unix format
This commit is contained in:
@@ -1,292 +1,292 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.TerritoryAccess;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.store.Entity;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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 BoardColl.get().get(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
|
||||
// -------------------------------------------- //
|
||||
|
||||
private ConcurrentSkipListMap<PS, TerritoryAccess> map;
|
||||
public Map<PS, TerritoryAccess> getMap() { return Collections.unmodifiableMap(this.map); }
|
||||
public Map<PS, TerritoryAccess> getMapRaw() { return this.map; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Board()
|
||||
{
|
||||
this.map = new ConcurrentSkipListMap<>();
|
||||
}
|
||||
|
||||
public Board(Map<PS, TerritoryAccess> map)
|
||||
{
|
||||
this.map = new ConcurrentSkipListMap<>(map);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: BOARD
|
||||
// -------------------------------------------- //
|
||||
|
||||
// GET
|
||||
|
||||
@Override
|
||||
public TerritoryAccess getTerritoryAccessAt(PS ps)
|
||||
{
|
||||
if (ps == null) throw new NullPointerException("ps");
|
||||
|
||||
ps = ps.getChunkCoords(true);
|
||||
TerritoryAccess ret = this.map.get(ps);
|
||||
if (ret == null || ret.getHostFaction() == null) ret = TerritoryAccess.valueOf(Factions.ID_NONE);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Faction getFactionAt(PS ps)
|
||||
{
|
||||
return this.getTerritoryAccessAt(ps).getHostFaction();
|
||||
}
|
||||
|
||||
// SET
|
||||
|
||||
@Override
|
||||
public void setTerritoryAccessAt(PS ps, TerritoryAccess territoryAccess)
|
||||
{
|
||||
ps = ps.getChunkCoords(true);
|
||||
|
||||
if (territoryAccess == null || (territoryAccess.getHostFactionId().equals(Factions.ID_NONE) && 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)
|
||||
{
|
||||
this.getChunks(faction).forEach(this::removeAt);
|
||||
}
|
||||
|
||||
// CHUNKS
|
||||
|
||||
@Override
|
||||
public Set<PS> getChunks(Faction faction)
|
||||
{
|
||||
return this.getChunks(faction.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PS> getChunks(String factionId)
|
||||
{
|
||||
return this.map.entrySet().stream()
|
||||
.filter(e -> e.getValue().getHostFactionId().equals(factionId))
|
||||
.map(Entry::getKey)
|
||||
.map(ps -> ps.withWorld(this.getId()))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Map<Faction, Set<PS>> getFactionToChunks()
|
||||
{
|
||||
return this.getFactionToChunks(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Faction, Set<PS>> getFactionToChunks(boolean withWorld)
|
||||
{
|
||||
Function<Entry<PS, TerritoryAccess>, PS> mapper = Entry::getKey;
|
||||
if (withWorld) mapper = mapper.andThen(ps -> ps.withWorld(this.getId()));
|
||||
|
||||
return map.entrySet().stream().collect(Collectors.groupingBy(
|
||||
entry -> entry.getValue().getHostFaction(), // This specifies how to get the key
|
||||
Collectors.mapping(mapper, Collectors.toSet()) // This maps the entries and puts them in the collection
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Map<Faction, Set<PS>>> getWorldToFactionToChunks(boolean withWorld)
|
||||
{
|
||||
return Collections.singletonMap(this.getId(), this.getFactionToChunks(withWorld));
|
||||
}
|
||||
|
||||
// COUNT
|
||||
|
||||
@Override
|
||||
public int getCount(Faction faction)
|
||||
{
|
||||
if (faction == null) throw new NullPointerException("faction");
|
||||
|
||||
return this.getCount(faction.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount(String factionId)
|
||||
{
|
||||
if (factionId == null) throw new NullPointerException("factionId");
|
||||
|
||||
return (int) this.map.values().stream()
|
||||
.map(TerritoryAccess::getHostFactionId)
|
||||
.filter(factionId::equals)
|
||||
.count();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Faction, Long> getFactionToCount()
|
||||
{
|
||||
return this.map.entrySet().stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
e -> e.getValue().getHostFaction(),
|
||||
Collectors.counting()
|
||||
));
|
||||
}
|
||||
|
||||
// CLAIMED
|
||||
|
||||
@Override
|
||||
public boolean hasClaimed(Faction faction)
|
||||
{
|
||||
return this.hasClaimed(faction.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasClaimed(String factionId)
|
||||
{
|
||||
return this.map.values().stream()
|
||||
.map(TerritoryAccess::getHostFactionId)
|
||||
.anyMatch(factionId::equals);
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnyBorderPs(Set<PS> pss)
|
||||
{
|
||||
return pss.stream().anyMatch(this::isBorderPs);
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnyConnectedPs(Set<PS> pss, Faction faction)
|
||||
{
|
||||
return pss.stream().anyMatch(ps -> this.isConnectedPs(ps, faction));
|
||||
}
|
||||
|
||||
}
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.TerritoryAccess;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.store.Entity;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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 BoardColl.get().get(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
|
||||
// -------------------------------------------- //
|
||||
|
||||
private ConcurrentSkipListMap<PS, TerritoryAccess> map;
|
||||
public Map<PS, TerritoryAccess> getMap() { return Collections.unmodifiableMap(this.map); }
|
||||
public Map<PS, TerritoryAccess> getMapRaw() { return this.map; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Board()
|
||||
{
|
||||
this.map = new ConcurrentSkipListMap<>();
|
||||
}
|
||||
|
||||
public Board(Map<PS, TerritoryAccess> map)
|
||||
{
|
||||
this.map = new ConcurrentSkipListMap<>(map);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: BOARD
|
||||
// -------------------------------------------- //
|
||||
|
||||
// GET
|
||||
|
||||
@Override
|
||||
public TerritoryAccess getTerritoryAccessAt(PS ps)
|
||||
{
|
||||
if (ps == null) throw new NullPointerException("ps");
|
||||
|
||||
ps = ps.getChunkCoords(true);
|
||||
TerritoryAccess ret = this.map.get(ps);
|
||||
if (ret == null || ret.getHostFaction() == null) ret = TerritoryAccess.valueOf(Factions.ID_NONE);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Faction getFactionAt(PS ps)
|
||||
{
|
||||
return this.getTerritoryAccessAt(ps).getHostFaction();
|
||||
}
|
||||
|
||||
// SET
|
||||
|
||||
@Override
|
||||
public void setTerritoryAccessAt(PS ps, TerritoryAccess territoryAccess)
|
||||
{
|
||||
ps = ps.getChunkCoords(true);
|
||||
|
||||
if (territoryAccess == null || (territoryAccess.getHostFactionId().equals(Factions.ID_NONE) && 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)
|
||||
{
|
||||
this.getChunks(faction).forEach(this::removeAt);
|
||||
}
|
||||
|
||||
// CHUNKS
|
||||
|
||||
@Override
|
||||
public Set<PS> getChunks(Faction faction)
|
||||
{
|
||||
return this.getChunks(faction.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PS> getChunks(String factionId)
|
||||
{
|
||||
return this.map.entrySet().stream()
|
||||
.filter(e -> e.getValue().getHostFactionId().equals(factionId))
|
||||
.map(Entry::getKey)
|
||||
.map(ps -> ps.withWorld(this.getId()))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Map<Faction, Set<PS>> getFactionToChunks()
|
||||
{
|
||||
return this.getFactionToChunks(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Faction, Set<PS>> getFactionToChunks(boolean withWorld)
|
||||
{
|
||||
Function<Entry<PS, TerritoryAccess>, PS> mapper = Entry::getKey;
|
||||
if (withWorld) mapper = mapper.andThen(ps -> ps.withWorld(this.getId()));
|
||||
|
||||
return map.entrySet().stream().collect(Collectors.groupingBy(
|
||||
entry -> entry.getValue().getHostFaction(), // This specifies how to get the key
|
||||
Collectors.mapping(mapper, Collectors.toSet()) // This maps the entries and puts them in the collection
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Map<Faction, Set<PS>>> getWorldToFactionToChunks(boolean withWorld)
|
||||
{
|
||||
return Collections.singletonMap(this.getId(), this.getFactionToChunks(withWorld));
|
||||
}
|
||||
|
||||
// COUNT
|
||||
|
||||
@Override
|
||||
public int getCount(Faction faction)
|
||||
{
|
||||
if (faction == null) throw new NullPointerException("faction");
|
||||
|
||||
return this.getCount(faction.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount(String factionId)
|
||||
{
|
||||
if (factionId == null) throw new NullPointerException("factionId");
|
||||
|
||||
return (int) this.map.values().stream()
|
||||
.map(TerritoryAccess::getHostFactionId)
|
||||
.filter(factionId::equals)
|
||||
.count();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Faction, Long> getFactionToCount()
|
||||
{
|
||||
return this.map.entrySet().stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
e -> e.getValue().getHostFaction(),
|
||||
Collectors.counting()
|
||||
));
|
||||
}
|
||||
|
||||
// CLAIMED
|
||||
|
||||
@Override
|
||||
public boolean hasClaimed(Faction faction)
|
||||
{
|
||||
return this.hasClaimed(faction.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasClaimed(String factionId)
|
||||
{
|
||||
return this.map.values().stream()
|
||||
.map(TerritoryAccess::getHostFactionId)
|
||||
.anyMatch(factionId::equals);
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnyBorderPs(Set<PS> pss)
|
||||
{
|
||||
return pss.stream().anyMatch(this::isBorderPs);
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnyConnectedPs(Set<PS> pss, Faction faction)
|
||||
{
|
||||
return pss.stream().anyMatch(ps -> this.isConnectedPs(ps, faction));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,436 +1,436 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import com.massivecraft.factions.TerritoryAccess;
|
||||
import com.massivecraft.massivecore.collections.MassiveList;
|
||||
import com.massivecraft.massivecore.collections.MassiveMap;
|
||||
import com.massivecraft.massivecore.collections.MassiveSet;
|
||||
import com.massivecraft.massivecore.entity.MassiveCoreMConf;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.store.Coll;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BoardColl extends Coll<Board> implements BoardInterface
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static BoardColl i = new BoardColl();
|
||||
public static BoardColl get() { return i; }
|
||||
private BoardColl()
|
||||
{
|
||||
this.setCreative(true);
|
||||
this.setLowercasing(true);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// STACK TRACEABILITY
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void onTick()
|
||||
{
|
||||
super.onTick();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// 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 ((Board)oid).getId();
|
||||
|
||||
boolean debug = MassiveCoreMConf.get().debugEnabled;
|
||||
String ret = MUtil.extract(String.class, "worldName", oid);
|
||||
if (ret != null && debug)
|
||||
{
|
||||
System.out.println("extracted world name from " + oid);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: BOARD
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public TerritoryAccess getTerritoryAccessAt(PS ps)
|
||||
{
|
||||
if (ps == null) throw new NullPointerException("ps");
|
||||
Board board = this.get(ps.getWorld());
|
||||
if (board == null) return null;
|
||||
return board.getTerritoryAccessAt(ps);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Faction getFactionAt(PS ps)
|
||||
{
|
||||
if (ps == null) throw new NullPointerException("ps");
|
||||
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) throw new NullPointerException("ps");
|
||||
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) throw new NullPointerException("ps");
|
||||
Board board = this.get(ps.getWorld());
|
||||
if (board == null) return;
|
||||
board.setFactionAt(ps, faction);
|
||||
}
|
||||
|
||||
// REMOVE
|
||||
|
||||
@Override
|
||||
public void removeAt(PS ps)
|
||||
{
|
||||
if (ps == null) throw new NullPointerException("ps");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// CHUNKS
|
||||
|
||||
@Override
|
||||
public Set<PS> getChunks(Faction faction)
|
||||
{
|
||||
return this.getAll().stream()
|
||||
.flatMap(board -> board.getChunks(faction).stream())
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PS> getChunks(String factionId)
|
||||
{
|
||||
return this.getAll().stream()
|
||||
.flatMap(board -> board.getChunks(factionId).stream())
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Map<Faction, Set<PS>> getFactionToChunks()
|
||||
{
|
||||
return this.getFactionToChunks(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Faction, Set<PS>> getFactionToChunks(boolean withWorld)
|
||||
{
|
||||
// Create
|
||||
Map<Faction, Set<PS>> ret = null;
|
||||
|
||||
// Fill
|
||||
for (Board board : this.getAll())
|
||||
{
|
||||
// Use the first board directly
|
||||
Map<Faction, Set<PS>> factionToChunks = board.getFactionToChunks(withWorld);
|
||||
if (ret == null)
|
||||
{
|
||||
ret = factionToChunks;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Merge the following boards
|
||||
for (Entry<Faction, Set<PS>> entry : factionToChunks.entrySet())
|
||||
{
|
||||
Faction faction = entry.getKey();
|
||||
Set<PS> chunks = ret.get(faction);
|
||||
if (chunks == null)
|
||||
{
|
||||
ret.put(faction, entry.getValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
chunks.addAll(entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Enforce create
|
||||
if (ret == null) ret = new MassiveMap<>();
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Map<Faction, Set<PS>>> getWorldToFactionToChunks(boolean withWorld)
|
||||
{
|
||||
return this.getAll().stream()
|
||||
.collect(Collectors.toMap(Board::getId, board -> board.getFactionToChunks(withWorld)));
|
||||
}
|
||||
|
||||
// COUNT
|
||||
|
||||
@Override
|
||||
public int getCount(Faction faction)
|
||||
{
|
||||
return this.getCount(faction.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount(String factionId)
|
||||
{
|
||||
return this.getAll().stream()
|
||||
.mapToInt(board -> board.getCount(factionId))
|
||||
.sum();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Faction, Long> getFactionToCount()
|
||||
{
|
||||
// Get them all and map them to sets of entries
|
||||
return this.getAll().stream()
|
||||
.map(Board::getFactionToCount)
|
||||
.map(Map::entrySet)
|
||||
.flatMap(Set::stream)
|
||||
// Collect the entries in a map of <Faction, Long> by summing the values
|
||||
.collect(Collectors.groupingBy(
|
||||
Entry::getKey,
|
||||
Collectors.summingLong(Entry::getValue)
|
||||
))
|
||||
;
|
||||
}
|
||||
|
||||
// COUNT
|
||||
|
||||
@Override
|
||||
public boolean hasClaimed(Faction faction)
|
||||
{
|
||||
return this.hasClaimed(faction.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasClaimed(String factionId)
|
||||
{
|
||||
return this.getAll().stream()
|
||||
.anyMatch(board -> board.hasClaimed(factionId));
|
||||
}
|
||||
|
||||
// NEARBY DETECTION
|
||||
|
||||
@Override
|
||||
public boolean isBorderPs(PS ps)
|
||||
{
|
||||
if (ps == null) throw new NullPointerException("ps");
|
||||
Board board = this.get(ps.getWorld());
|
||||
if (board == null) return false;
|
||||
return board.isBorderPs(ps);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnyBorderPs(Set<PS> pss)
|
||||
{
|
||||
return pss.stream().anyMatch(this::isBorderPs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnectedPs(PS ps, Faction faction)
|
||||
{
|
||||
if (ps == null) throw new NullPointerException("ps");
|
||||
Board board = this.get(ps.getWorld());
|
||||
if (board == null) return false;
|
||||
return board.isConnectedPs(ps, faction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnyConnectedPs(Set<PS> pss, Faction faction)
|
||||
{
|
||||
for (PS ps : pss)
|
||||
{
|
||||
if (this.isConnectedPs(ps, faction)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// WORLDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Set<String> getClaimedWorlds(Faction faction)
|
||||
{
|
||||
return getClaimedWorlds(faction.getId());
|
||||
}
|
||||
|
||||
public Set<String> getClaimedWorlds(String factionId)
|
||||
{
|
||||
if (factionId == null) throw new NullPointerException("factionId");
|
||||
return this.getAll().stream()
|
||||
.filter(board -> board.hasClaimed(factionId))
|
||||
.map(Board::getId)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UTIL
|
||||
// -------------------------------------------- //
|
||||
|
||||
// Distance -1 returns 0 chunks always.
|
||||
// Distance 0 returns 1 chunk only (the one supplied).
|
||||
// Distance 1 returns 3x3 = 9 chunks.
|
||||
public static Set<PS> getNearbyChunks(PS psChunk, int distance)
|
||||
{
|
||||
// Fix Args
|
||||
if (psChunk == null) throw new NullPointerException("psChunk");
|
||||
psChunk = psChunk.getChunk(true);
|
||||
|
||||
// Create
|
||||
Set<PS> ret = new MassiveSet<>();
|
||||
if (distance < 0) return ret;
|
||||
|
||||
// Fill
|
||||
int chunkX = psChunk.getChunkX();
|
||||
int xmin = chunkX - distance;
|
||||
int xmax = chunkX + distance;
|
||||
|
||||
int chunkZ = psChunk.getChunkZ();
|
||||
int zmin = chunkZ - distance;
|
||||
int zmax = chunkZ + distance;
|
||||
|
||||
for (int x = xmin; x <= xmax; x++)
|
||||
{
|
||||
PS psChunkX = psChunk.withChunkX(x);
|
||||
for (int z = zmin; z <= zmax; z++)
|
||||
{
|
||||
ret.add(psChunkX.withChunkZ(z));
|
||||
}
|
||||
}
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Set<PS> getNearbyChunks(Collection<PS> chunks, int distance)
|
||||
{
|
||||
// Fix Args
|
||||
if (chunks == null) throw new NullPointerException("chunks");
|
||||
|
||||
// Create
|
||||
Set<PS> ret = new MassiveSet<>();
|
||||
|
||||
if (distance < 0) return ret;
|
||||
|
||||
// Fill
|
||||
for (PS chunk : chunks)
|
||||
{
|
||||
ret.addAll(getNearbyChunks(chunk, distance));
|
||||
}
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Set<Faction> getDistinctFactions(Collection<PS> chunks)
|
||||
{
|
||||
// Fix Args
|
||||
if (chunks == null) throw new NullPointerException("chunks");
|
||||
|
||||
// Create
|
||||
Set<Faction> ret = new MassiveSet<>();
|
||||
|
||||
// Fill
|
||||
for (PS chunk : chunks)
|
||||
{
|
||||
Faction faction = get().getFactionAt(chunk);
|
||||
if (faction == null) continue;
|
||||
ret.add(faction);
|
||||
}
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Map<PS, Faction> getChunkFaction(Collection<PS> chunks)
|
||||
{
|
||||
// Create
|
||||
Map<PS, Faction> ret = new MassiveMap<>();
|
||||
|
||||
// Fill
|
||||
Faction none = FactionColl.get().getNone();
|
||||
for (PS chunk : chunks)
|
||||
{
|
||||
chunk = chunk.getChunk(true);
|
||||
Faction faction = get().getFactionAt(chunk);
|
||||
if (faction == null) faction = none;
|
||||
ret.put(chunk, faction);
|
||||
}
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static List<Collection<PS>> getForests(Collection<PS> pss)
|
||||
{
|
||||
List<Collection<PS>> forests = new MassiveList<>();
|
||||
List<PS> discovered = new MassiveList<>();
|
||||
|
||||
outer:
|
||||
for (PS ps : pss)
|
||||
{
|
||||
if (discovered.contains(ps)) continue outer;
|
||||
|
||||
List<PS> forest = new MassiveList<>();
|
||||
forests.add(forest);
|
||||
|
||||
Stack<PS> stack = new Stack<>();
|
||||
stack.push(ps);
|
||||
inner:
|
||||
while (!stack.empty())
|
||||
{
|
||||
PS elm = stack.pop();
|
||||
if (discovered.contains(elm)) continue inner;
|
||||
System.out.println(elm);
|
||||
discovered.add(elm);
|
||||
forest.add(elm);
|
||||
|
||||
addIfInSource(elm.withChunkX(elm.getChunkX() + 1), stack, pss);
|
||||
addIfInSource(elm.withChunkX(elm.getChunkX() - 1), stack, pss);
|
||||
addIfInSource(elm.withChunkZ(elm.getChunkZ() + 1), stack, pss);
|
||||
addIfInSource(elm.withChunkZ(elm.getChunkZ() - 1), stack, pss);
|
||||
}
|
||||
}
|
||||
|
||||
return forests;
|
||||
}
|
||||
|
||||
private static void addIfInSource(PS ps, Stack<PS> stack, Collection<PS> source)
|
||||
{
|
||||
if (source.contains(ps)) stack.push(ps);
|
||||
}
|
||||
|
||||
}
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import com.massivecraft.factions.TerritoryAccess;
|
||||
import com.massivecraft.massivecore.collections.MassiveList;
|
||||
import com.massivecraft.massivecore.collections.MassiveMap;
|
||||
import com.massivecraft.massivecore.collections.MassiveSet;
|
||||
import com.massivecraft.massivecore.entity.MassiveCoreMConf;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.store.Coll;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BoardColl extends Coll<Board> implements BoardInterface
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static BoardColl i = new BoardColl();
|
||||
public static BoardColl get() { return i; }
|
||||
private BoardColl()
|
||||
{
|
||||
this.setCreative(true);
|
||||
this.setLowercasing(true);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// STACK TRACEABILITY
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void onTick()
|
||||
{
|
||||
super.onTick();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// 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 ((Board)oid).getId();
|
||||
|
||||
boolean debug = MassiveCoreMConf.get().debugEnabled;
|
||||
String ret = MUtil.extract(String.class, "worldName", oid);
|
||||
if (ret != null && debug)
|
||||
{
|
||||
System.out.println("extracted world name from " + oid);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: BOARD
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public TerritoryAccess getTerritoryAccessAt(PS ps)
|
||||
{
|
||||
if (ps == null) throw new NullPointerException("ps");
|
||||
Board board = this.get(ps.getWorld());
|
||||
if (board == null) return null;
|
||||
return board.getTerritoryAccessAt(ps);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Faction getFactionAt(PS ps)
|
||||
{
|
||||
if (ps == null) throw new NullPointerException("ps");
|
||||
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) throw new NullPointerException("ps");
|
||||
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) throw new NullPointerException("ps");
|
||||
Board board = this.get(ps.getWorld());
|
||||
if (board == null) return;
|
||||
board.setFactionAt(ps, faction);
|
||||
}
|
||||
|
||||
// REMOVE
|
||||
|
||||
@Override
|
||||
public void removeAt(PS ps)
|
||||
{
|
||||
if (ps == null) throw new NullPointerException("ps");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// CHUNKS
|
||||
|
||||
@Override
|
||||
public Set<PS> getChunks(Faction faction)
|
||||
{
|
||||
return this.getAll().stream()
|
||||
.flatMap(board -> board.getChunks(faction).stream())
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PS> getChunks(String factionId)
|
||||
{
|
||||
return this.getAll().stream()
|
||||
.flatMap(board -> board.getChunks(factionId).stream())
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Map<Faction, Set<PS>> getFactionToChunks()
|
||||
{
|
||||
return this.getFactionToChunks(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Faction, Set<PS>> getFactionToChunks(boolean withWorld)
|
||||
{
|
||||
// Create
|
||||
Map<Faction, Set<PS>> ret = null;
|
||||
|
||||
// Fill
|
||||
for (Board board : this.getAll())
|
||||
{
|
||||
// Use the first board directly
|
||||
Map<Faction, Set<PS>> factionToChunks = board.getFactionToChunks(withWorld);
|
||||
if (ret == null)
|
||||
{
|
||||
ret = factionToChunks;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Merge the following boards
|
||||
for (Entry<Faction, Set<PS>> entry : factionToChunks.entrySet())
|
||||
{
|
||||
Faction faction = entry.getKey();
|
||||
Set<PS> chunks = ret.get(faction);
|
||||
if (chunks == null)
|
||||
{
|
||||
ret.put(faction, entry.getValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
chunks.addAll(entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Enforce create
|
||||
if (ret == null) ret = new MassiveMap<>();
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Map<Faction, Set<PS>>> getWorldToFactionToChunks(boolean withWorld)
|
||||
{
|
||||
return this.getAll().stream()
|
||||
.collect(Collectors.toMap(Board::getId, board -> board.getFactionToChunks(withWorld)));
|
||||
}
|
||||
|
||||
// COUNT
|
||||
|
||||
@Override
|
||||
public int getCount(Faction faction)
|
||||
{
|
||||
return this.getCount(faction.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount(String factionId)
|
||||
{
|
||||
return this.getAll().stream()
|
||||
.mapToInt(board -> board.getCount(factionId))
|
||||
.sum();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Faction, Long> getFactionToCount()
|
||||
{
|
||||
// Get them all and map them to sets of entries
|
||||
return this.getAll().stream()
|
||||
.map(Board::getFactionToCount)
|
||||
.map(Map::entrySet)
|
||||
.flatMap(Set::stream)
|
||||
// Collect the entries in a map of <Faction, Long> by summing the values
|
||||
.collect(Collectors.groupingBy(
|
||||
Entry::getKey,
|
||||
Collectors.summingLong(Entry::getValue)
|
||||
))
|
||||
;
|
||||
}
|
||||
|
||||
// COUNT
|
||||
|
||||
@Override
|
||||
public boolean hasClaimed(Faction faction)
|
||||
{
|
||||
return this.hasClaimed(faction.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasClaimed(String factionId)
|
||||
{
|
||||
return this.getAll().stream()
|
||||
.anyMatch(board -> board.hasClaimed(factionId));
|
||||
}
|
||||
|
||||
// NEARBY DETECTION
|
||||
|
||||
@Override
|
||||
public boolean isBorderPs(PS ps)
|
||||
{
|
||||
if (ps == null) throw new NullPointerException("ps");
|
||||
Board board = this.get(ps.getWorld());
|
||||
if (board == null) return false;
|
||||
return board.isBorderPs(ps);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnyBorderPs(Set<PS> pss)
|
||||
{
|
||||
return pss.stream().anyMatch(this::isBorderPs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnectedPs(PS ps, Faction faction)
|
||||
{
|
||||
if (ps == null) throw new NullPointerException("ps");
|
||||
Board board = this.get(ps.getWorld());
|
||||
if (board == null) return false;
|
||||
return board.isConnectedPs(ps, faction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnyConnectedPs(Set<PS> pss, Faction faction)
|
||||
{
|
||||
for (PS ps : pss)
|
||||
{
|
||||
if (this.isConnectedPs(ps, faction)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// WORLDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Set<String> getClaimedWorlds(Faction faction)
|
||||
{
|
||||
return getClaimedWorlds(faction.getId());
|
||||
}
|
||||
|
||||
public Set<String> getClaimedWorlds(String factionId)
|
||||
{
|
||||
if (factionId == null) throw new NullPointerException("factionId");
|
||||
return this.getAll().stream()
|
||||
.filter(board -> board.hasClaimed(factionId))
|
||||
.map(Board::getId)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UTIL
|
||||
// -------------------------------------------- //
|
||||
|
||||
// Distance -1 returns 0 chunks always.
|
||||
// Distance 0 returns 1 chunk only (the one supplied).
|
||||
// Distance 1 returns 3x3 = 9 chunks.
|
||||
public static Set<PS> getNearbyChunks(PS psChunk, int distance)
|
||||
{
|
||||
// Fix Args
|
||||
if (psChunk == null) throw new NullPointerException("psChunk");
|
||||
psChunk = psChunk.getChunk(true);
|
||||
|
||||
// Create
|
||||
Set<PS> ret = new MassiveSet<>();
|
||||
if (distance < 0) return ret;
|
||||
|
||||
// Fill
|
||||
int chunkX = psChunk.getChunkX();
|
||||
int xmin = chunkX - distance;
|
||||
int xmax = chunkX + distance;
|
||||
|
||||
int chunkZ = psChunk.getChunkZ();
|
||||
int zmin = chunkZ - distance;
|
||||
int zmax = chunkZ + distance;
|
||||
|
||||
for (int x = xmin; x <= xmax; x++)
|
||||
{
|
||||
PS psChunkX = psChunk.withChunkX(x);
|
||||
for (int z = zmin; z <= zmax; z++)
|
||||
{
|
||||
ret.add(psChunkX.withChunkZ(z));
|
||||
}
|
||||
}
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Set<PS> getNearbyChunks(Collection<PS> chunks, int distance)
|
||||
{
|
||||
// Fix Args
|
||||
if (chunks == null) throw new NullPointerException("chunks");
|
||||
|
||||
// Create
|
||||
Set<PS> ret = new MassiveSet<>();
|
||||
|
||||
if (distance < 0) return ret;
|
||||
|
||||
// Fill
|
||||
for (PS chunk : chunks)
|
||||
{
|
||||
ret.addAll(getNearbyChunks(chunk, distance));
|
||||
}
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Set<Faction> getDistinctFactions(Collection<PS> chunks)
|
||||
{
|
||||
// Fix Args
|
||||
if (chunks == null) throw new NullPointerException("chunks");
|
||||
|
||||
// Create
|
||||
Set<Faction> ret = new MassiveSet<>();
|
||||
|
||||
// Fill
|
||||
for (PS chunk : chunks)
|
||||
{
|
||||
Faction faction = get().getFactionAt(chunk);
|
||||
if (faction == null) continue;
|
||||
ret.add(faction);
|
||||
}
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Map<PS, Faction> getChunkFaction(Collection<PS> chunks)
|
||||
{
|
||||
// Create
|
||||
Map<PS, Faction> ret = new MassiveMap<>();
|
||||
|
||||
// Fill
|
||||
Faction none = FactionColl.get().getNone();
|
||||
for (PS chunk : chunks)
|
||||
{
|
||||
chunk = chunk.getChunk(true);
|
||||
Faction faction = get().getFactionAt(chunk);
|
||||
if (faction == null) faction = none;
|
||||
ret.put(chunk, faction);
|
||||
}
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static List<Collection<PS>> getForests(Collection<PS> pss)
|
||||
{
|
||||
List<Collection<PS>> forests = new MassiveList<>();
|
||||
List<PS> discovered = new MassiveList<>();
|
||||
|
||||
outer:
|
||||
for (PS ps : pss)
|
||||
{
|
||||
if (discovered.contains(ps)) continue outer;
|
||||
|
||||
List<PS> forest = new MassiveList<>();
|
||||
forests.add(forest);
|
||||
|
||||
Stack<PS> stack = new Stack<>();
|
||||
stack.push(ps);
|
||||
inner:
|
||||
while (!stack.empty())
|
||||
{
|
||||
PS elm = stack.pop();
|
||||
if (discovered.contains(elm)) continue inner;
|
||||
System.out.println(elm);
|
||||
discovered.add(elm);
|
||||
forest.add(elm);
|
||||
|
||||
addIfInSource(elm.withChunkX(elm.getChunkX() + 1), stack, pss);
|
||||
addIfInSource(elm.withChunkX(elm.getChunkX() - 1), stack, pss);
|
||||
addIfInSource(elm.withChunkZ(elm.getChunkZ() + 1), stack, pss);
|
||||
addIfInSource(elm.withChunkZ(elm.getChunkZ() - 1), stack, pss);
|
||||
}
|
||||
}
|
||||
|
||||
return forests;
|
||||
}
|
||||
|
||||
private static void addIfInSource(PS ps, Stack<PS> stack, Collection<PS> source)
|
||||
{
|
||||
if (source.contains(ps)) stack.push(ps);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,45 +1,45 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import com.massivecraft.factions.TerritoryAccess;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public interface BoardInterface
|
||||
{
|
||||
// GET
|
||||
TerritoryAccess getTerritoryAccessAt(PS ps);
|
||||
Faction getFactionAt(PS ps);
|
||||
|
||||
// SET
|
||||
void setTerritoryAccessAt(PS ps, TerritoryAccess territoryAccess);
|
||||
void setFactionAt(PS ps, Faction faction);
|
||||
|
||||
// REMOVE
|
||||
void removeAt(PS ps);
|
||||
void removeAll(Faction faction);
|
||||
|
||||
// CHUNKS
|
||||
Set<PS> getChunks(Faction faction);
|
||||
Set<PS> getChunks(String factionId);
|
||||
@Deprecated Map<Faction, Set<PS>> getFactionToChunks();
|
||||
Map<Faction, Set<PS>> getFactionToChunks(boolean withWorld);
|
||||
Map<String, Map<Faction, Set<PS>>> getWorldToFactionToChunks(boolean withWorld);
|
||||
|
||||
// COUNT
|
||||
int getCount(Faction faction);
|
||||
int getCount(String factionId);
|
||||
Map<Faction, Long> getFactionToCount();
|
||||
|
||||
// CLAIMED
|
||||
boolean hasClaimed(Faction faction);
|
||||
boolean hasClaimed(String factionId);
|
||||
|
||||
// NEARBY DETECTION
|
||||
boolean isBorderPs(PS ps);
|
||||
boolean isAnyBorderPs(Set<PS> pss);
|
||||
boolean isConnectedPs(PS ps, Faction faction);
|
||||
boolean isAnyConnectedPs(Set<PS> pss, Faction faction);
|
||||
|
||||
}
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import com.massivecraft.factions.TerritoryAccess;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public interface BoardInterface
|
||||
{
|
||||
// GET
|
||||
TerritoryAccess getTerritoryAccessAt(PS ps);
|
||||
Faction getFactionAt(PS ps);
|
||||
|
||||
// SET
|
||||
void setTerritoryAccessAt(PS ps, TerritoryAccess territoryAccess);
|
||||
void setFactionAt(PS ps, Faction faction);
|
||||
|
||||
// REMOVE
|
||||
void removeAt(PS ps);
|
||||
void removeAll(Faction faction);
|
||||
|
||||
// CHUNKS
|
||||
Set<PS> getChunks(Faction faction);
|
||||
Set<PS> getChunks(String factionId);
|
||||
@Deprecated Map<Faction, Set<PS>> getFactionToChunks();
|
||||
Map<Faction, Set<PS>> getFactionToChunks(boolean withWorld);
|
||||
Map<String, Map<Faction, Set<PS>>> getWorldToFactionToChunks(boolean withWorld);
|
||||
|
||||
// COUNT
|
||||
int getCount(Faction faction);
|
||||
int getCount(String factionId);
|
||||
Map<Faction, Long> getFactionToCount();
|
||||
|
||||
// CLAIMED
|
||||
boolean hasClaimed(Faction faction);
|
||||
boolean hasClaimed(String factionId);
|
||||
|
||||
// NEARBY DETECTION
|
||||
boolean isBorderPs(PS ps);
|
||||
boolean isAnyBorderPs(Set<PS> pss);
|
||||
boolean isConnectedPs(PS ps, Faction faction);
|
||||
boolean isAnyConnectedPs(Set<PS> pss, Faction faction);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,224 +1,224 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.util.MiscUtil;
|
||||
import com.massivecraft.massivecore.collections.MassiveMap;
|
||||
import com.massivecraft.massivecore.store.Coll;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class FactionColl extends Coll<Faction>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static FactionColl i = new FactionColl();
|
||||
public static FactionColl get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// STACK TRACEABILITY
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void onTick()
|
||||
{
|
||||
super.onTick();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: COLL
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void setActive(boolean active)
|
||||
{
|
||||
super.setActive(active);
|
||||
|
||||
if (!active) return;
|
||||
|
||||
this.createSpecialFactions();
|
||||
|
||||
Factions.get().log("Activated FactionColl");
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SPECIAL FACTIONS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void createSpecialFactions()
|
||||
{
|
||||
this.getNone();
|
||||
this.getSafezone();
|
||||
this.getWarzone();
|
||||
}
|
||||
|
||||
public Faction getNone()
|
||||
{
|
||||
String id = Factions.ID_NONE;
|
||||
Faction faction = this.get(id);
|
||||
if (faction != null) return faction;
|
||||
|
||||
faction = this.create(id);
|
||||
|
||||
faction.setName(Factions.NAME_NONE_DEFAULT);
|
||||
faction.setDescription("It's dangerous to go alone.");
|
||||
|
||||
faction.setFlag(MFlag.getFlagOpen(), false);
|
||||
faction.setFlag(MFlag.getFlagPermanent(), true);
|
||||
faction.setFlag(MFlag.getFlagPeaceful(), false);
|
||||
faction.setFlag(MFlag.getFlagInfpower(), true);
|
||||
faction.setFlag(MFlag.getFlagPowerloss(), true);
|
||||
faction.setFlag(MFlag.getFlagPvp(), true);
|
||||
faction.setFlag(MFlag.getFlagFriendlyire(), false);
|
||||
faction.setFlag(MFlag.getFlagMonsters(), true);
|
||||
faction.setFlag(MFlag.getFlagAnimals(), true);
|
||||
faction.setFlag(MFlag.getFlagExplosions(), true);
|
||||
faction.setFlag(MFlag.getFlagOfflineexplosions(), true);
|
||||
faction.setFlag(MFlag.getFlagFirespread(), true);
|
||||
faction.setFlag(MFlag.getFlagEndergrief(), true);
|
||||
faction.setFlag(MFlag.getFlagZombiegrief(), true);
|
||||
|
||||
faction.setPermittedRelations(MPerm.getPermBuild(), MPerm.getPermables(faction));
|
||||
faction.setPermittedRelations(MPerm.getPermDoor(), MPerm.getPermables(faction));
|
||||
faction.setPermittedRelations(MPerm.getPermContainer(), MPerm.getPermables(faction));
|
||||
faction.setPermittedRelations(MPerm.getPermButton(), MPerm.getPermables(faction));
|
||||
faction.setPermittedRelations(MPerm.getPermLever(), MPerm.getPermables(faction));
|
||||
faction.setPermittedRelations(MPerm.getPermDeposit(), Collections.singleton(faction.getLeaderRank())); // Wilderness deposit should be limited as an anti spam meassure.
|
||||
|
||||
return faction;
|
||||
}
|
||||
|
||||
public Faction getSafezone()
|
||||
{
|
||||
String id = Factions.ID_SAFEZONE;
|
||||
Faction faction = this.get(id);
|
||||
if (faction != null) return faction;
|
||||
|
||||
faction = this.create(id);
|
||||
|
||||
faction.setName(Factions.NAME_SAFEZONE_DEFAULT);
|
||||
faction.setDescription("Free from PVP and monsters");
|
||||
|
||||
faction.setFlag(MFlag.getFlagOpen(), false);
|
||||
faction.setFlag(MFlag.getFlagPermanent(), true);
|
||||
faction.setFlag(MFlag.getFlagPeaceful(), true);
|
||||
faction.setFlag(MFlag.getFlagInfpower(), true);
|
||||
faction.setFlag(MFlag.getFlagPowerloss(), false);
|
||||
faction.setFlag(MFlag.getFlagPvp(), false);
|
||||
faction.setFlag(MFlag.getFlagFriendlyire(), false);
|
||||
faction.setFlag(MFlag.getFlagMonsters(), false);
|
||||
faction.setFlag(MFlag.getFlagAnimals(), true);
|
||||
faction.setFlag(MFlag.getFlagExplosions(), false);
|
||||
faction.setFlag(MFlag.getFlagOfflineexplosions(), false);
|
||||
faction.setFlag(MFlag.getFlagFirespread(), false);
|
||||
faction.setFlag(MFlag.getFlagEndergrief(), false);
|
||||
faction.setFlag(MFlag.getFlagZombiegrief(), false);
|
||||
|
||||
faction.setPermittedRelations(MPerm.getPermDoor(), MPerm.getPermables(faction));
|
||||
faction.setPermittedRelations(MPerm.getPermContainer(), MPerm.getPermables(faction));
|
||||
faction.setPermittedRelations(MPerm.getPermButton(), MPerm.getPermables(faction));
|
||||
faction.setPermittedRelations(MPerm.getPermLever(), MPerm.getPermables(faction));
|
||||
|
||||
return faction;
|
||||
}
|
||||
|
||||
public Faction getWarzone()
|
||||
{
|
||||
String id = Factions.ID_WARZONE;
|
||||
Faction faction = this.get(id);
|
||||
if (faction != null) return faction;
|
||||
|
||||
faction = this.create(id);
|
||||
|
||||
faction.setName(Factions.NAME_WARZONE_DEFAULT);
|
||||
faction.setDescription("Not the safest place to be");
|
||||
|
||||
faction.setFlag(MFlag.getFlagOpen(), false);
|
||||
faction.setFlag(MFlag.getFlagPermanent(), true);
|
||||
faction.setFlag(MFlag.getFlagPeaceful(), true);
|
||||
faction.setFlag(MFlag.getFlagInfpower(), true);
|
||||
faction.setFlag(MFlag.getFlagPowerloss(), true);
|
||||
faction.setFlag(MFlag.getFlagPvp(), true);
|
||||
faction.setFlag(MFlag.getFlagFriendlyire(), true);
|
||||
faction.setFlag(MFlag.getFlagMonsters(), true);
|
||||
faction.setFlag(MFlag.getFlagAnimals(), true);
|
||||
faction.setFlag(MFlag.getFlagExplosions(), true);
|
||||
faction.setFlag(MFlag.getFlagOfflineexplosions(), true);
|
||||
faction.setFlag(MFlag.getFlagFirespread(), true);
|
||||
faction.setFlag(MFlag.getFlagEndergrief(), true);
|
||||
faction.setFlag(MFlag.getFlagZombiegrief(), true);
|
||||
|
||||
faction.setPermittedRelations(MPerm.getPermDoor(), MPerm.getPermables(faction));
|
||||
faction.setPermittedRelations(MPerm.getPermContainer(), MPerm.getPermables(faction));
|
||||
faction.setPermittedRelations(MPerm.getPermButton(), MPerm.getPermables(faction));
|
||||
faction.setPermittedRelations(MPerm.getPermLever(), MPerm.getPermables(faction));
|
||||
|
||||
return faction;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// NAME
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Faction getByName(String name)
|
||||
{
|
||||
String compStr = MiscUtil.getComparisonString(name);
|
||||
for (Faction faction : this.getAll())
|
||||
{
|
||||
if (faction.getComparisonName().equals(compStr))
|
||||
{
|
||||
return faction;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// PREDICATE LOGIC
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Map<Rel, List<String>> getRelationNames(Faction faction, Set<Rel> rels)
|
||||
{
|
||||
// Create
|
||||
Map<Rel, List<String>> ret = new MassiveMap<>();
|
||||
MFlag flagPeaceful = MFlag.getFlagPeaceful();
|
||||
boolean peaceful = faction.getFlag(flagPeaceful);
|
||||
for (Rel rel : rels)
|
||||
{
|
||||
ret.put(rel, new ArrayList<>());
|
||||
}
|
||||
|
||||
// Fill
|
||||
for (Faction fac : FactionColl.get().getAll())
|
||||
{
|
||||
if (fac.getFlag(flagPeaceful)) continue;
|
||||
|
||||
Rel rel = fac.getRelationTo(faction);
|
||||
List<String> names = ret.get(rel);
|
||||
if (names == null) continue;
|
||||
|
||||
String name = fac.describeTo(faction, true);
|
||||
names.add(name);
|
||||
}
|
||||
|
||||
// Replace TRUCE if peaceful
|
||||
if (!peaceful) return ret;
|
||||
|
||||
List<String> names = ret.get(Rel.TRUCE);
|
||||
if (names == null) return ret;
|
||||
|
||||
ret.put(Rel.TRUCE, Collections.singletonList(MConf.get().colorTruce.toString() + Txt.parse("<italic>*EVERYONE*")));
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.util.MiscUtil;
|
||||
import com.massivecraft.massivecore.collections.MassiveMap;
|
||||
import com.massivecraft.massivecore.store.Coll;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class FactionColl extends Coll<Faction>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static FactionColl i = new FactionColl();
|
||||
public static FactionColl get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// STACK TRACEABILITY
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void onTick()
|
||||
{
|
||||
super.onTick();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: COLL
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void setActive(boolean active)
|
||||
{
|
||||
super.setActive(active);
|
||||
|
||||
if (!active) return;
|
||||
|
||||
this.createSpecialFactions();
|
||||
|
||||
Factions.get().log("Activated FactionColl");
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SPECIAL FACTIONS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void createSpecialFactions()
|
||||
{
|
||||
this.getNone();
|
||||
this.getSafezone();
|
||||
this.getWarzone();
|
||||
}
|
||||
|
||||
public Faction getNone()
|
||||
{
|
||||
String id = Factions.ID_NONE;
|
||||
Faction faction = this.get(id);
|
||||
if (faction != null) return faction;
|
||||
|
||||
faction = this.create(id);
|
||||
|
||||
faction.setName(Factions.NAME_NONE_DEFAULT);
|
||||
faction.setDescription("It's dangerous to go alone.");
|
||||
|
||||
faction.setFlag(MFlag.getFlagOpen(), false);
|
||||
faction.setFlag(MFlag.getFlagPermanent(), true);
|
||||
faction.setFlag(MFlag.getFlagPeaceful(), false);
|
||||
faction.setFlag(MFlag.getFlagInfpower(), true);
|
||||
faction.setFlag(MFlag.getFlagPowerloss(), true);
|
||||
faction.setFlag(MFlag.getFlagPvp(), true);
|
||||
faction.setFlag(MFlag.getFlagFriendlyire(), false);
|
||||
faction.setFlag(MFlag.getFlagMonsters(), true);
|
||||
faction.setFlag(MFlag.getFlagAnimals(), true);
|
||||
faction.setFlag(MFlag.getFlagExplosions(), true);
|
||||
faction.setFlag(MFlag.getFlagOfflineexplosions(), true);
|
||||
faction.setFlag(MFlag.getFlagFirespread(), true);
|
||||
faction.setFlag(MFlag.getFlagEndergrief(), true);
|
||||
faction.setFlag(MFlag.getFlagZombiegrief(), true);
|
||||
|
||||
faction.setPermittedRelations(MPerm.getPermBuild(), MPerm.getPermables(faction));
|
||||
faction.setPermittedRelations(MPerm.getPermDoor(), MPerm.getPermables(faction));
|
||||
faction.setPermittedRelations(MPerm.getPermContainer(), MPerm.getPermables(faction));
|
||||
faction.setPermittedRelations(MPerm.getPermButton(), MPerm.getPermables(faction));
|
||||
faction.setPermittedRelations(MPerm.getPermLever(), MPerm.getPermables(faction));
|
||||
faction.setPermittedRelations(MPerm.getPermDeposit(), Collections.singleton(faction.getLeaderRank())); // Wilderness deposit should be limited as an anti spam meassure.
|
||||
|
||||
return faction;
|
||||
}
|
||||
|
||||
public Faction getSafezone()
|
||||
{
|
||||
String id = Factions.ID_SAFEZONE;
|
||||
Faction faction = this.get(id);
|
||||
if (faction != null) return faction;
|
||||
|
||||
faction = this.create(id);
|
||||
|
||||
faction.setName(Factions.NAME_SAFEZONE_DEFAULT);
|
||||
faction.setDescription("Free from PVP and monsters");
|
||||
|
||||
faction.setFlag(MFlag.getFlagOpen(), false);
|
||||
faction.setFlag(MFlag.getFlagPermanent(), true);
|
||||
faction.setFlag(MFlag.getFlagPeaceful(), true);
|
||||
faction.setFlag(MFlag.getFlagInfpower(), true);
|
||||
faction.setFlag(MFlag.getFlagPowerloss(), false);
|
||||
faction.setFlag(MFlag.getFlagPvp(), false);
|
||||
faction.setFlag(MFlag.getFlagFriendlyire(), false);
|
||||
faction.setFlag(MFlag.getFlagMonsters(), false);
|
||||
faction.setFlag(MFlag.getFlagAnimals(), true);
|
||||
faction.setFlag(MFlag.getFlagExplosions(), false);
|
||||
faction.setFlag(MFlag.getFlagOfflineexplosions(), false);
|
||||
faction.setFlag(MFlag.getFlagFirespread(), false);
|
||||
faction.setFlag(MFlag.getFlagEndergrief(), false);
|
||||
faction.setFlag(MFlag.getFlagZombiegrief(), false);
|
||||
|
||||
faction.setPermittedRelations(MPerm.getPermDoor(), MPerm.getPermables(faction));
|
||||
faction.setPermittedRelations(MPerm.getPermContainer(), MPerm.getPermables(faction));
|
||||
faction.setPermittedRelations(MPerm.getPermButton(), MPerm.getPermables(faction));
|
||||
faction.setPermittedRelations(MPerm.getPermLever(), MPerm.getPermables(faction));
|
||||
|
||||
return faction;
|
||||
}
|
||||
|
||||
public Faction getWarzone()
|
||||
{
|
||||
String id = Factions.ID_WARZONE;
|
||||
Faction faction = this.get(id);
|
||||
if (faction != null) return faction;
|
||||
|
||||
faction = this.create(id);
|
||||
|
||||
faction.setName(Factions.NAME_WARZONE_DEFAULT);
|
||||
faction.setDescription("Not the safest place to be");
|
||||
|
||||
faction.setFlag(MFlag.getFlagOpen(), false);
|
||||
faction.setFlag(MFlag.getFlagPermanent(), true);
|
||||
faction.setFlag(MFlag.getFlagPeaceful(), true);
|
||||
faction.setFlag(MFlag.getFlagInfpower(), true);
|
||||
faction.setFlag(MFlag.getFlagPowerloss(), true);
|
||||
faction.setFlag(MFlag.getFlagPvp(), true);
|
||||
faction.setFlag(MFlag.getFlagFriendlyire(), true);
|
||||
faction.setFlag(MFlag.getFlagMonsters(), true);
|
||||
faction.setFlag(MFlag.getFlagAnimals(), true);
|
||||
faction.setFlag(MFlag.getFlagExplosions(), true);
|
||||
faction.setFlag(MFlag.getFlagOfflineexplosions(), true);
|
||||
faction.setFlag(MFlag.getFlagFirespread(), true);
|
||||
faction.setFlag(MFlag.getFlagEndergrief(), true);
|
||||
faction.setFlag(MFlag.getFlagZombiegrief(), true);
|
||||
|
||||
faction.setPermittedRelations(MPerm.getPermDoor(), MPerm.getPermables(faction));
|
||||
faction.setPermittedRelations(MPerm.getPermContainer(), MPerm.getPermables(faction));
|
||||
faction.setPermittedRelations(MPerm.getPermButton(), MPerm.getPermables(faction));
|
||||
faction.setPermittedRelations(MPerm.getPermLever(), MPerm.getPermables(faction));
|
||||
|
||||
return faction;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// NAME
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Faction getByName(String name)
|
||||
{
|
||||
String compStr = MiscUtil.getComparisonString(name);
|
||||
for (Faction faction : this.getAll())
|
||||
{
|
||||
if (faction.getComparisonName().equals(compStr))
|
||||
{
|
||||
return faction;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// PREDICATE LOGIC
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Map<Rel, List<String>> getRelationNames(Faction faction, Set<Rel> rels)
|
||||
{
|
||||
// Create
|
||||
Map<Rel, List<String>> ret = new MassiveMap<>();
|
||||
MFlag flagPeaceful = MFlag.getFlagPeaceful();
|
||||
boolean peaceful = faction.getFlag(flagPeaceful);
|
||||
for (Rel rel : rels)
|
||||
{
|
||||
ret.put(rel, new ArrayList<>());
|
||||
}
|
||||
|
||||
// Fill
|
||||
for (Faction fac : FactionColl.get().getAll())
|
||||
{
|
||||
if (fac.getFlag(flagPeaceful)) continue;
|
||||
|
||||
Rel rel = fac.getRelationTo(faction);
|
||||
List<String> names = ret.get(rel);
|
||||
if (names == null) continue;
|
||||
|
||||
String name = fac.describeTo(faction, true);
|
||||
names.add(name);
|
||||
}
|
||||
|
||||
// Replace TRUCE if peaceful
|
||||
if (!peaceful) return ret;
|
||||
|
||||
List<String> names = ret.get(Rel.TRUCE);
|
||||
if (names == null) return ret;
|
||||
|
||||
ret.put(Rel.TRUCE, Collections.singletonList(MConf.get().colorTruce.toString() + Txt.parse("<italic>*EVERYONE*")));
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,37 +1,37 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import com.massivecraft.massivecore.MassiveCore;
|
||||
import com.massivecraft.massivecore.store.Coll;
|
||||
|
||||
public class MConfColl extends Coll<MConf>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static MConfColl i = new MConfColl();
|
||||
public static MConfColl get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// STACK TRACEABILITY
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void onTick()
|
||||
{
|
||||
super.onTick();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void setActive(boolean active)
|
||||
{
|
||||
super.setActive(active);
|
||||
if (!active) return;
|
||||
MConf.i = this.get(MassiveCore.INSTANCE, true);
|
||||
}
|
||||
|
||||
}
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import com.massivecraft.massivecore.MassiveCore;
|
||||
import com.massivecraft.massivecore.store.Coll;
|
||||
|
||||
public class MConfColl extends Coll<MConf>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static MConfColl i = new MConfColl();
|
||||
public static MConfColl get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// STACK TRACEABILITY
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void onTick()
|
||||
{
|
||||
super.onTick();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void setActive(boolean active)
|
||||
{
|
||||
super.setActive(active);
|
||||
if (!active) return;
|
||||
MConf.i = this.get(MassiveCore.INSTANCE, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,313 +1,313 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import com.massivecraft.factions.event.EventFactionsCreateFlags;
|
||||
import com.massivecraft.massivecore.Named;
|
||||
import com.massivecraft.massivecore.Prioritized;
|
||||
import com.massivecraft.massivecore.Registerable;
|
||||
import com.massivecraft.massivecore.collections.MassiveList;
|
||||
import com.massivecraft.massivecore.comparator.ComparatorSmart;
|
||||
import com.massivecraft.massivecore.predicate.PredicateIsRegistered;
|
||||
import com.massivecraft.massivecore.store.Entity;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MFlag extends Entity<MFlag> implements Prioritized, Registerable, Named
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTANTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public final static transient String ID_OPEN = "open";
|
||||
public final static transient String ID_MONSTERS = "monsters";
|
||||
public final static transient String ID_ANIMALS = "animals";
|
||||
public final static transient String ID_POWERLOSS = "powerloss";
|
||||
public final static transient String ID_POWERGAIN = "powergain";
|
||||
public final static transient String ID_PVP = "pvp";
|
||||
public final static transient String ID_FRIENDLYFIRE = "friendlyfire";
|
||||
public final static transient String ID_EXPLOSIONS = "explosions";
|
||||
public final static transient String ID_OFFLINEEXPLOSIONS = "offlineexplosions";
|
||||
public final static transient String ID_FIRESPREAD = "firespread";
|
||||
public final static transient String ID_ENDERGRIEF = "endergrief";
|
||||
public final static transient String ID_ZOMBIEGRIEF = "zombiegrief";
|
||||
public final static transient String ID_PERMANENT = "permanent";
|
||||
public final static transient String ID_PEACEFUL = "peaceful";
|
||||
public final static transient String ID_INFPOWER = "infpower";
|
||||
public final static transient String ID_FLY = "fly";
|
||||
public final static transient String ID_TAXKICK = "taxkick";
|
||||
public final static transient String ID_IMMORTAL = "immortal";
|
||||
|
||||
public final static transient int PRIORITY_OPEN = 1_000;
|
||||
public final static transient int PRIORITY_MONSTERS = 2_000;
|
||||
public final static transient int PRIORITY_ANIMALS = 3_000;
|
||||
public final static transient int PRIORITY_POWERLOSS = 4_000;
|
||||
public final static transient int PRIORITY_POWERGAIN = 5_000;
|
||||
public final static transient int PRIORITY_PVP = 6_000;
|
||||
public final static transient int PRIORITY_FRIENDLYFIRE = 7_000;
|
||||
public final static transient int PRIORITY_EXPLOSIONS = 8_000;
|
||||
public final static transient int PRIORITY_OFFLINEEXPLOSIONS = 9_000;
|
||||
public final static transient int PRIORITY_FIRESPREAD = 10_000;
|
||||
public final static transient int PRIORITY_ENDERGRIEF = 11_000;
|
||||
public final static transient int PRIORITY_ZOMBIEGRIEF = 12_000;
|
||||
public final static transient int PRIORITY_PERMANENT = 13_000;
|
||||
public final static transient int PRIORITY_PEACEFUL = 14_000;
|
||||
public final static transient int PRIORITY_INFPOWER = 15_000;
|
||||
public final static transient int PRIORITY_FLY = 16_000;
|
||||
public final static transient int PRIORITY_TAXKICK = 17_000;
|
||||
public final static transient int PRIORITY_IMMORTAL = 18_000;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// META: CORE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static MFlag get(Object oid)
|
||||
{
|
||||
return MFlagColl.get().get(oid);
|
||||
}
|
||||
|
||||
public static List<MFlag> getAll()
|
||||
{
|
||||
return getAll(Bukkit.isPrimaryThread());
|
||||
}
|
||||
|
||||
public static List<MFlag> getAll(boolean sync)
|
||||
{
|
||||
setupStandardFlags();
|
||||
new EventFactionsCreateFlags(!sync).run();
|
||||
return MFlagColl.get().getAll(PredicateIsRegistered.get(), ComparatorSmart.get());
|
||||
}
|
||||
|
||||
public static void setupStandardFlags()
|
||||
{
|
||||
getFlagOpen();
|
||||
getFlagMonsters();
|
||||
getFlagAnimals();
|
||||
getFlagPowerloss();
|
||||
getFlagPowergain();
|
||||
getFlagPvp();
|
||||
getFlagFriendlyire();
|
||||
getFlagExplosions();
|
||||
getFlagOfflineexplosions();
|
||||
getFlagFirespread();
|
||||
getFlagEndergrief();
|
||||
getFlagZombiegrief();
|
||||
getFlagPermanent();
|
||||
getFlagPeaceful();
|
||||
getFlagInfpower();
|
||||
getFlagFly();
|
||||
getFlagTaxKick();
|
||||
getFlagImmortal();
|
||||
}
|
||||
|
||||
public static MFlag getFlagOpen() { return getCreative(PRIORITY_OPEN, ID_OPEN, ID_OPEN, "Can the faction be joined without an invite?", "Anyone can join. No invite required.", "An invite is required to join.", false, true, true); }
|
||||
public static MFlag getFlagMonsters() { return getCreative(PRIORITY_MONSTERS, ID_MONSTERS, ID_MONSTERS, "Can monsters spawn in this territory?", "Monsters can spawn in this territory.", "Monsters can NOT spawn in this territory.", false, true, true); }
|
||||
public static MFlag getFlagAnimals() { return getCreative(PRIORITY_ANIMALS, ID_ANIMALS, ID_ANIMALS, "Can animals spawn in this territory?", "Animals can spawn in this territory.", "Animals can NOT spawn in this territory.", true, true, true); }
|
||||
public static MFlag getFlagPowerloss() { return getCreative(PRIORITY_POWERLOSS, ID_POWERLOSS, ID_POWERLOSS, "Is power lost on death in this territory?", "Power is lost on death in this territory.", "Power is NOT lost on death in this territory.", true, false, true); }
|
||||
public static MFlag getFlagPowergain() { return getCreative(PRIORITY_POWERGAIN, ID_POWERGAIN, ID_POWERGAIN, "Can power be gained in this territory?", "Power can be gained in this territory.", "Power is NOT gained in this territory.", true, false, true); }
|
||||
public static MFlag getFlagPvp() { return getCreative(PRIORITY_PVP, ID_PVP, ID_PVP, "Can you PVP in territory?", "You can PVP in this territory.", "You can NOT PVP in this territory.", true, false, true); }
|
||||
public static MFlag getFlagFriendlyire() { return getCreative(PRIORITY_FRIENDLYFIRE, ID_FRIENDLYFIRE, ID_FRIENDLYFIRE, "Can friends hurt eachother in this territory?", "Friendly fire is on here.", "Friendly fire is off here.", false, false, true); }
|
||||
public static MFlag getFlagExplosions() { return getCreative(PRIORITY_EXPLOSIONS, ID_EXPLOSIONS, ID_EXPLOSIONS, "Can explosions occur in this territory?", "Explosions can occur in this territory.", "Explosions can NOT occur in this territory.", true, false, true); }
|
||||
public static MFlag getFlagOfflineexplosions() { return getCreative(PRIORITY_OFFLINEEXPLOSIONS, ID_OFFLINEEXPLOSIONS, ID_OFFLINEEXPLOSIONS, "Can explosions occur if faction is offline?", "Explosions if faction is offline.", "No explosions if faction is offline.", false, false, true); }
|
||||
public static MFlag getFlagFirespread() { return getCreative(PRIORITY_FIRESPREAD, ID_FIRESPREAD, ID_FIRESPREAD, "Can fire spread in territory?", "Fire can spread in this territory.", "Fire can NOT spread in this territory.", true, false, true); }
|
||||
public static MFlag getFlagEndergrief() { return getCreative(PRIORITY_ENDERGRIEF, ID_ENDERGRIEF, ID_ENDERGRIEF, "Can endermen grief in this territory?", "Endermen can grief in this territory.", "Endermen can NOT grief in this territory.", false, false, true); }
|
||||
public static MFlag getFlagZombiegrief() { return getCreative(PRIORITY_ZOMBIEGRIEF, ID_ZOMBIEGRIEF, ID_ZOMBIEGRIEF, "Can zombies break doors in this territory?", "Zombies can break doors in this territory.", "Zombies can NOT break doors in this territory.", false, false, true); }
|
||||
public static MFlag getFlagPermanent() { return getCreative(PRIORITY_PERMANENT, ID_PERMANENT, ID_PERMANENT, "Is the faction immune to deletion?", "The faction can NOT be deleted.", "The faction can be deleted.", false, false, true); }
|
||||
public static MFlag getFlagPeaceful() { return getCreative(PRIORITY_PEACEFUL, ID_PEACEFUL, ID_PEACEFUL, "Is the faction in truce with everyone?", "The faction is in truce with everyone.", "The faction relations work as usual.", false, false, true); }
|
||||
public static MFlag getFlagInfpower() { return getCreative(PRIORITY_INFPOWER, ID_INFPOWER, ID_INFPOWER, "Does the faction have infinite power?", "The faction has infinite power.", "The faction power works as usual.", false, false, true); }
|
||||
public static MFlag getFlagFly() { return getCreative(PRIORITY_FLY, ID_FLY, ID_FLY, "Is flying allowed in faction territory?", "Players can fly in faction territory.", "Players can not fly in faction territory.", false, false, true); }
|
||||
public static MFlag getFlagTaxKick() { return getCreative(PRIORITY_TAXKICK, ID_TAXKICK, ID_TAXKICK, "Are players kicked for not paying taxes?", "Members are kicked for not paying taxes.", "Members are not kicked for not paying taxes.", false, true, true); }
|
||||
public static MFlag getFlagImmortal() { return getCreative(PRIORITY_IMMORTAL, ID_IMMORTAL, ID_IMMORTAL, "Are players immortal in this territory?", "Players are immortal in this territory.", "Players are NOT immortal in this territory.", false, false, true); }
|
||||
|
||||
public static MFlag getCreative(int priority, String id, String name, String desc, String descYes, String descNo, boolean standard, boolean editable, boolean visible)
|
||||
{
|
||||
MFlag ret = MFlagColl.get().get(id, false);
|
||||
if (ret != null)
|
||||
{
|
||||
ret.setRegistered(true);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = new MFlag(priority, name, desc, descYes, descNo, standard, editable, visible);
|
||||
MFlagColl.get().attach(ret, id);
|
||||
ret.setRegistered(true);
|
||||
ret.sync();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public MFlag load(MFlag that)
|
||||
{
|
||||
this.priority = that.priority;
|
||||
this.name = that.name;
|
||||
this.desc = that.desc;
|
||||
this.descYes = that.descYes;
|
||||
this.descNo = that.descNo;
|
||||
this.standard = that.standard;
|
||||
this.editable = that.editable;
|
||||
this.visible = that.visible;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// TRANSIENT FIELDS (Registered)
|
||||
// -------------------------------------------- //
|
||||
|
||||
private transient boolean registered = false;
|
||||
public boolean isRegistered() { return this.registered; }
|
||||
public void setRegistered(boolean registered) { this.registered = registered; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
// The sort priority. Low values appear first in sorted lists.
|
||||
// 1 is high up, 99999 is far down.
|
||||
// Standard Faction flags use "thousand values" like 1000, 2000, 3000 etc to allow adding new flags inbetween.
|
||||
// So 1000 might sound like a lot but it's actually the priority for the first flag.
|
||||
private int priority = 0;
|
||||
@Override public int getPriority() { return this.priority; }
|
||||
public MFlag setPriority(int priority) { this.priority = priority; this.changed(); return this; }
|
||||
|
||||
// The name of the flag. According to standard it should be fully lowercase just like the flag id.
|
||||
// In fact the name and the id of all standard flags are the same.
|
||||
// I just added the name in case anyone feel like renaming their flags for some reason.
|
||||
// Example: "monsters"
|
||||
private String name = "defaultName";
|
||||
@Override public String getName() { return this.name; }
|
||||
public MFlag setName(String name) { this.name = name; this.changed(); return this; }
|
||||
|
||||
// The flag function described as a question.
|
||||
// Example: "Can monsters spawn in this territory?"
|
||||
private String desc = "defaultDesc";
|
||||
public String getDesc() { return this.desc; }
|
||||
public MFlag setDesc(String desc) { this.desc = desc; this.changed(); return this; }
|
||||
|
||||
// The flag function described when true.
|
||||
// Example: "Monsters can spawn in this territory."
|
||||
private String descYes = "defaultDescYes";
|
||||
public String getDescYes() { return this.descYes; }
|
||||
public MFlag setDescYes(String descYes) { this.descYes = descYes; this.changed(); return this; }
|
||||
|
||||
// The flag function described when false.
|
||||
// Example: "Monsters can NOT spawn in this territory."
|
||||
private String descNo = "defaultDescNo";
|
||||
public String getDescNo() { return this.descNo; }
|
||||
public MFlag setDescNo(String descNo) { this.descNo = descNo; this.changed(); return this; }
|
||||
|
||||
// What is the standard (aka default) flag value?
|
||||
// This value will be set for factions from the beginning.
|
||||
// Example: false (per default monsters do not spawn in faction territory)
|
||||
private boolean standard = true;
|
||||
public boolean isStandard() { return this.standard; }
|
||||
public MFlag setStandard(boolean standard) { this.standard = standard; this.changed(); return this; }
|
||||
|
||||
// Is this flag editable by players?
|
||||
// With this we mean standard non administrator players.
|
||||
// All flags can be changed using /f override.
|
||||
// Example: true (if players want to turn mob spawning on I guess they should be able to)
|
||||
private boolean editable = false;
|
||||
public boolean isEditable() { return this.editable; }
|
||||
public MFlag setEditable(boolean editable) { this.editable = editable; this.changed(); return this; }
|
||||
|
||||
// Is this flag visible to players?
|
||||
// With this we mean standard non administrator players.
|
||||
// All flags can be seen using /f override.
|
||||
// Some flags can be rendered meaningless by settings in Factions or external plugins.
|
||||
// Say we set "editable" to false and "standard" to true for the "open" flag to force all factions being open.
|
||||
// In such case we might want to hide the open flag by setting "visible" false.
|
||||
// If it can't be changed, why bother showing it?
|
||||
// Example: true (yeah we need to see this flag)
|
||||
private boolean visible = true;
|
||||
public boolean isVisible() { return this.visible; }
|
||||
public MFlag setVisible(boolean visible) { this.visible = visible; this.changed(); return this; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public MFlag()
|
||||
{
|
||||
// No argument constructor for GSON
|
||||
}
|
||||
|
||||
public MFlag(int priority, String name, String desc, String descYes, String descNo, boolean standard, boolean editable, boolean visible)
|
||||
{
|
||||
this.priority = priority;
|
||||
this.name = name;
|
||||
this.desc = desc;
|
||||
this.descYes = descYes;
|
||||
this.descNo = descNo;
|
||||
this.standard = standard;
|
||||
this.editable = editable;
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// EXTRAS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean isInteresting(boolean value)
|
||||
{
|
||||
if ( ! this.isVisible()) return false;
|
||||
if (this.isEditable()) return true;
|
||||
return this.isStandard() != value;
|
||||
}
|
||||
|
||||
public String getStateDesc(boolean value, boolean withValue, boolean monospaceValue, boolean withName, boolean withDesc, boolean specificDesc)
|
||||
{
|
||||
// Create
|
||||
List<String> ret = new MassiveList<>();
|
||||
|
||||
// Fill
|
||||
if (withValue) ret.add(getStateValue(value, monospaceValue));
|
||||
if (withName) ret.add(this.getStateName());
|
||||
if (withDesc) ret.add(this.getStateDescription(value, specificDesc));
|
||||
|
||||
// Return
|
||||
return Txt.implode(ret, " ");
|
||||
}
|
||||
|
||||
private static String getStateValue(boolean value, boolean monoSpace)
|
||||
{
|
||||
String yes = "<g>YES";
|
||||
String no = monoSpace ? "<b>NOO" : "<b>NO";
|
||||
|
||||
return Txt.parse(value ? yes : no);
|
||||
}
|
||||
|
||||
private String getStateName()
|
||||
{
|
||||
return this.getStateColor().toString() + this.getName();
|
||||
}
|
||||
|
||||
private ChatColor getStateColor()
|
||||
{
|
||||
// Is special?
|
||||
if (!this.isVisible()) return ChatColor.GRAY;
|
||||
if (this.isEditable()) return ChatColor.LIGHT_PURPLE;
|
||||
|
||||
// Return normal
|
||||
return ChatColor.AQUA;
|
||||
}
|
||||
|
||||
private String getStateDescription(boolean value, boolean specific)
|
||||
{
|
||||
// Create
|
||||
String desc = this.getDesc();
|
||||
|
||||
// Is specific?
|
||||
if (specific) desc = value ? this.getDescYes() : this.getDescNo();
|
||||
|
||||
// Return
|
||||
return Txt.parse("<i>%s", desc);
|
||||
}
|
||||
|
||||
}
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import com.massivecraft.factions.event.EventFactionsCreateFlags;
|
||||
import com.massivecraft.massivecore.Named;
|
||||
import com.massivecraft.massivecore.Prioritized;
|
||||
import com.massivecraft.massivecore.Registerable;
|
||||
import com.massivecraft.massivecore.collections.MassiveList;
|
||||
import com.massivecraft.massivecore.comparator.ComparatorSmart;
|
||||
import com.massivecraft.massivecore.predicate.PredicateIsRegistered;
|
||||
import com.massivecraft.massivecore.store.Entity;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MFlag extends Entity<MFlag> implements Prioritized, Registerable, Named
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTANTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public final static transient String ID_OPEN = "open";
|
||||
public final static transient String ID_MONSTERS = "monsters";
|
||||
public final static transient String ID_ANIMALS = "animals";
|
||||
public final static transient String ID_POWERLOSS = "powerloss";
|
||||
public final static transient String ID_POWERGAIN = "powergain";
|
||||
public final static transient String ID_PVP = "pvp";
|
||||
public final static transient String ID_FRIENDLYFIRE = "friendlyfire";
|
||||
public final static transient String ID_EXPLOSIONS = "explosions";
|
||||
public final static transient String ID_OFFLINEEXPLOSIONS = "offlineexplosions";
|
||||
public final static transient String ID_FIRESPREAD = "firespread";
|
||||
public final static transient String ID_ENDERGRIEF = "endergrief";
|
||||
public final static transient String ID_ZOMBIEGRIEF = "zombiegrief";
|
||||
public final static transient String ID_PERMANENT = "permanent";
|
||||
public final static transient String ID_PEACEFUL = "peaceful";
|
||||
public final static transient String ID_INFPOWER = "infpower";
|
||||
public final static transient String ID_FLY = "fly";
|
||||
public final static transient String ID_TAXKICK = "taxkick";
|
||||
public final static transient String ID_IMMORTAL = "immortal";
|
||||
|
||||
public final static transient int PRIORITY_OPEN = 1_000;
|
||||
public final static transient int PRIORITY_MONSTERS = 2_000;
|
||||
public final static transient int PRIORITY_ANIMALS = 3_000;
|
||||
public final static transient int PRIORITY_POWERLOSS = 4_000;
|
||||
public final static transient int PRIORITY_POWERGAIN = 5_000;
|
||||
public final static transient int PRIORITY_PVP = 6_000;
|
||||
public final static transient int PRIORITY_FRIENDLYFIRE = 7_000;
|
||||
public final static transient int PRIORITY_EXPLOSIONS = 8_000;
|
||||
public final static transient int PRIORITY_OFFLINEEXPLOSIONS = 9_000;
|
||||
public final static transient int PRIORITY_FIRESPREAD = 10_000;
|
||||
public final static transient int PRIORITY_ENDERGRIEF = 11_000;
|
||||
public final static transient int PRIORITY_ZOMBIEGRIEF = 12_000;
|
||||
public final static transient int PRIORITY_PERMANENT = 13_000;
|
||||
public final static transient int PRIORITY_PEACEFUL = 14_000;
|
||||
public final static transient int PRIORITY_INFPOWER = 15_000;
|
||||
public final static transient int PRIORITY_FLY = 16_000;
|
||||
public final static transient int PRIORITY_TAXKICK = 17_000;
|
||||
public final static transient int PRIORITY_IMMORTAL = 18_000;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// META: CORE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static MFlag get(Object oid)
|
||||
{
|
||||
return MFlagColl.get().get(oid);
|
||||
}
|
||||
|
||||
public static List<MFlag> getAll()
|
||||
{
|
||||
return getAll(Bukkit.isPrimaryThread());
|
||||
}
|
||||
|
||||
public static List<MFlag> getAll(boolean sync)
|
||||
{
|
||||
setupStandardFlags();
|
||||
new EventFactionsCreateFlags(!sync).run();
|
||||
return MFlagColl.get().getAll(PredicateIsRegistered.get(), ComparatorSmart.get());
|
||||
}
|
||||
|
||||
public static void setupStandardFlags()
|
||||
{
|
||||
getFlagOpen();
|
||||
getFlagMonsters();
|
||||
getFlagAnimals();
|
||||
getFlagPowerloss();
|
||||
getFlagPowergain();
|
||||
getFlagPvp();
|
||||
getFlagFriendlyire();
|
||||
getFlagExplosions();
|
||||
getFlagOfflineexplosions();
|
||||
getFlagFirespread();
|
||||
getFlagEndergrief();
|
||||
getFlagZombiegrief();
|
||||
getFlagPermanent();
|
||||
getFlagPeaceful();
|
||||
getFlagInfpower();
|
||||
getFlagFly();
|
||||
getFlagTaxKick();
|
||||
getFlagImmortal();
|
||||
}
|
||||
|
||||
public static MFlag getFlagOpen() { return getCreative(PRIORITY_OPEN, ID_OPEN, ID_OPEN, "Can the faction be joined without an invite?", "Anyone can join. No invite required.", "An invite is required to join.", false, true, true); }
|
||||
public static MFlag getFlagMonsters() { return getCreative(PRIORITY_MONSTERS, ID_MONSTERS, ID_MONSTERS, "Can monsters spawn in this territory?", "Monsters can spawn in this territory.", "Monsters can NOT spawn in this territory.", false, true, true); }
|
||||
public static MFlag getFlagAnimals() { return getCreative(PRIORITY_ANIMALS, ID_ANIMALS, ID_ANIMALS, "Can animals spawn in this territory?", "Animals can spawn in this territory.", "Animals can NOT spawn in this territory.", true, true, true); }
|
||||
public static MFlag getFlagPowerloss() { return getCreative(PRIORITY_POWERLOSS, ID_POWERLOSS, ID_POWERLOSS, "Is power lost on death in this territory?", "Power is lost on death in this territory.", "Power is NOT lost on death in this territory.", true, false, true); }
|
||||
public static MFlag getFlagPowergain() { return getCreative(PRIORITY_POWERGAIN, ID_POWERGAIN, ID_POWERGAIN, "Can power be gained in this territory?", "Power can be gained in this territory.", "Power is NOT gained in this territory.", true, false, true); }
|
||||
public static MFlag getFlagPvp() { return getCreative(PRIORITY_PVP, ID_PVP, ID_PVP, "Can you PVP in territory?", "You can PVP in this territory.", "You can NOT PVP in this territory.", true, false, true); }
|
||||
public static MFlag getFlagFriendlyire() { return getCreative(PRIORITY_FRIENDLYFIRE, ID_FRIENDLYFIRE, ID_FRIENDLYFIRE, "Can friends hurt eachother in this territory?", "Friendly fire is on here.", "Friendly fire is off here.", false, false, true); }
|
||||
public static MFlag getFlagExplosions() { return getCreative(PRIORITY_EXPLOSIONS, ID_EXPLOSIONS, ID_EXPLOSIONS, "Can explosions occur in this territory?", "Explosions can occur in this territory.", "Explosions can NOT occur in this territory.", true, false, true); }
|
||||
public static MFlag getFlagOfflineexplosions() { return getCreative(PRIORITY_OFFLINEEXPLOSIONS, ID_OFFLINEEXPLOSIONS, ID_OFFLINEEXPLOSIONS, "Can explosions occur if faction is offline?", "Explosions if faction is offline.", "No explosions if faction is offline.", false, false, true); }
|
||||
public static MFlag getFlagFirespread() { return getCreative(PRIORITY_FIRESPREAD, ID_FIRESPREAD, ID_FIRESPREAD, "Can fire spread in territory?", "Fire can spread in this territory.", "Fire can NOT spread in this territory.", true, false, true); }
|
||||
public static MFlag getFlagEndergrief() { return getCreative(PRIORITY_ENDERGRIEF, ID_ENDERGRIEF, ID_ENDERGRIEF, "Can endermen grief in this territory?", "Endermen can grief in this territory.", "Endermen can NOT grief in this territory.", false, false, true); }
|
||||
public static MFlag getFlagZombiegrief() { return getCreative(PRIORITY_ZOMBIEGRIEF, ID_ZOMBIEGRIEF, ID_ZOMBIEGRIEF, "Can zombies break doors in this territory?", "Zombies can break doors in this territory.", "Zombies can NOT break doors in this territory.", false, false, true); }
|
||||
public static MFlag getFlagPermanent() { return getCreative(PRIORITY_PERMANENT, ID_PERMANENT, ID_PERMANENT, "Is the faction immune to deletion?", "The faction can NOT be deleted.", "The faction can be deleted.", false, false, true); }
|
||||
public static MFlag getFlagPeaceful() { return getCreative(PRIORITY_PEACEFUL, ID_PEACEFUL, ID_PEACEFUL, "Is the faction in truce with everyone?", "The faction is in truce with everyone.", "The faction relations work as usual.", false, false, true); }
|
||||
public static MFlag getFlagInfpower() { return getCreative(PRIORITY_INFPOWER, ID_INFPOWER, ID_INFPOWER, "Does the faction have infinite power?", "The faction has infinite power.", "The faction power works as usual.", false, false, true); }
|
||||
public static MFlag getFlagFly() { return getCreative(PRIORITY_FLY, ID_FLY, ID_FLY, "Is flying allowed in faction territory?", "Players can fly in faction territory.", "Players can not fly in faction territory.", false, false, true); }
|
||||
public static MFlag getFlagTaxKick() { return getCreative(PRIORITY_TAXKICK, ID_TAXKICK, ID_TAXKICK, "Are players kicked for not paying taxes?", "Members are kicked for not paying taxes.", "Members are not kicked for not paying taxes.", false, true, true); }
|
||||
public static MFlag getFlagImmortal() { return getCreative(PRIORITY_IMMORTAL, ID_IMMORTAL, ID_IMMORTAL, "Are players immortal in this territory?", "Players are immortal in this territory.", "Players are NOT immortal in this territory.", false, false, true); }
|
||||
|
||||
public static MFlag getCreative(int priority, String id, String name, String desc, String descYes, String descNo, boolean standard, boolean editable, boolean visible)
|
||||
{
|
||||
MFlag ret = MFlagColl.get().get(id, false);
|
||||
if (ret != null)
|
||||
{
|
||||
ret.setRegistered(true);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = new MFlag(priority, name, desc, descYes, descNo, standard, editable, visible);
|
||||
MFlagColl.get().attach(ret, id);
|
||||
ret.setRegistered(true);
|
||||
ret.sync();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public MFlag load(MFlag that)
|
||||
{
|
||||
this.priority = that.priority;
|
||||
this.name = that.name;
|
||||
this.desc = that.desc;
|
||||
this.descYes = that.descYes;
|
||||
this.descNo = that.descNo;
|
||||
this.standard = that.standard;
|
||||
this.editable = that.editable;
|
||||
this.visible = that.visible;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// TRANSIENT FIELDS (Registered)
|
||||
// -------------------------------------------- //
|
||||
|
||||
private transient boolean registered = false;
|
||||
public boolean isRegistered() { return this.registered; }
|
||||
public void setRegistered(boolean registered) { this.registered = registered; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
// The sort priority. Low values appear first in sorted lists.
|
||||
// 1 is high up, 99999 is far down.
|
||||
// Standard Faction flags use "thousand values" like 1000, 2000, 3000 etc to allow adding new flags inbetween.
|
||||
// So 1000 might sound like a lot but it's actually the priority for the first flag.
|
||||
private int priority = 0;
|
||||
@Override public int getPriority() { return this.priority; }
|
||||
public MFlag setPriority(int priority) { this.priority = priority; this.changed(); return this; }
|
||||
|
||||
// The name of the flag. According to standard it should be fully lowercase just like the flag id.
|
||||
// In fact the name and the id of all standard flags are the same.
|
||||
// I just added the name in case anyone feel like renaming their flags for some reason.
|
||||
// Example: "monsters"
|
||||
private String name = "defaultName";
|
||||
@Override public String getName() { return this.name; }
|
||||
public MFlag setName(String name) { this.name = name; this.changed(); return this; }
|
||||
|
||||
// The flag function described as a question.
|
||||
// Example: "Can monsters spawn in this territory?"
|
||||
private String desc = "defaultDesc";
|
||||
public String getDesc() { return this.desc; }
|
||||
public MFlag setDesc(String desc) { this.desc = desc; this.changed(); return this; }
|
||||
|
||||
// The flag function described when true.
|
||||
// Example: "Monsters can spawn in this territory."
|
||||
private String descYes = "defaultDescYes";
|
||||
public String getDescYes() { return this.descYes; }
|
||||
public MFlag setDescYes(String descYes) { this.descYes = descYes; this.changed(); return this; }
|
||||
|
||||
// The flag function described when false.
|
||||
// Example: "Monsters can NOT spawn in this territory."
|
||||
private String descNo = "defaultDescNo";
|
||||
public String getDescNo() { return this.descNo; }
|
||||
public MFlag setDescNo(String descNo) { this.descNo = descNo; this.changed(); return this; }
|
||||
|
||||
// What is the standard (aka default) flag value?
|
||||
// This value will be set for factions from the beginning.
|
||||
// Example: false (per default monsters do not spawn in faction territory)
|
||||
private boolean standard = true;
|
||||
public boolean isStandard() { return this.standard; }
|
||||
public MFlag setStandard(boolean standard) { this.standard = standard; this.changed(); return this; }
|
||||
|
||||
// Is this flag editable by players?
|
||||
// With this we mean standard non administrator players.
|
||||
// All flags can be changed using /f override.
|
||||
// Example: true (if players want to turn mob spawning on I guess they should be able to)
|
||||
private boolean editable = false;
|
||||
public boolean isEditable() { return this.editable; }
|
||||
public MFlag setEditable(boolean editable) { this.editable = editable; this.changed(); return this; }
|
||||
|
||||
// Is this flag visible to players?
|
||||
// With this we mean standard non administrator players.
|
||||
// All flags can be seen using /f override.
|
||||
// Some flags can be rendered meaningless by settings in Factions or external plugins.
|
||||
// Say we set "editable" to false and "standard" to true for the "open" flag to force all factions being open.
|
||||
// In such case we might want to hide the open flag by setting "visible" false.
|
||||
// If it can't be changed, why bother showing it?
|
||||
// Example: true (yeah we need to see this flag)
|
||||
private boolean visible = true;
|
||||
public boolean isVisible() { return this.visible; }
|
||||
public MFlag setVisible(boolean visible) { this.visible = visible; this.changed(); return this; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public MFlag()
|
||||
{
|
||||
// No argument constructor for GSON
|
||||
}
|
||||
|
||||
public MFlag(int priority, String name, String desc, String descYes, String descNo, boolean standard, boolean editable, boolean visible)
|
||||
{
|
||||
this.priority = priority;
|
||||
this.name = name;
|
||||
this.desc = desc;
|
||||
this.descYes = descYes;
|
||||
this.descNo = descNo;
|
||||
this.standard = standard;
|
||||
this.editable = editable;
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// EXTRAS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean isInteresting(boolean value)
|
||||
{
|
||||
if ( ! this.isVisible()) return false;
|
||||
if (this.isEditable()) return true;
|
||||
return this.isStandard() != value;
|
||||
}
|
||||
|
||||
public String getStateDesc(boolean value, boolean withValue, boolean monospaceValue, boolean withName, boolean withDesc, boolean specificDesc)
|
||||
{
|
||||
// Create
|
||||
List<String> ret = new MassiveList<>();
|
||||
|
||||
// Fill
|
||||
if (withValue) ret.add(getStateValue(value, monospaceValue));
|
||||
if (withName) ret.add(this.getStateName());
|
||||
if (withDesc) ret.add(this.getStateDescription(value, specificDesc));
|
||||
|
||||
// Return
|
||||
return Txt.implode(ret, " ");
|
||||
}
|
||||
|
||||
private static String getStateValue(boolean value, boolean monoSpace)
|
||||
{
|
||||
String yes = "<g>YES";
|
||||
String no = monoSpace ? "<b>NOO" : "<b>NO";
|
||||
|
||||
return Txt.parse(value ? yes : no);
|
||||
}
|
||||
|
||||
private String getStateName()
|
||||
{
|
||||
return this.getStateColor().toString() + this.getName();
|
||||
}
|
||||
|
||||
private ChatColor getStateColor()
|
||||
{
|
||||
// Is special?
|
||||
if (!this.isVisible()) return ChatColor.GRAY;
|
||||
if (this.isEditable()) return ChatColor.LIGHT_PURPLE;
|
||||
|
||||
// Return normal
|
||||
return ChatColor.AQUA;
|
||||
}
|
||||
|
||||
private String getStateDescription(boolean value, boolean specific)
|
||||
{
|
||||
// Create
|
||||
String desc = this.getDesc();
|
||||
|
||||
// Is specific?
|
||||
if (specific) desc = value ? this.getDescYes() : this.getDescNo();
|
||||
|
||||
// Return
|
||||
return Txt.parse("<i>%s", desc);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,63 +1,63 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import com.massivecraft.massivecore.store.Coll;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MFlagColl extends Coll<MFlag>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static MFlagColl i = new MFlagColl();
|
||||
public static MFlagColl get() { return i; }
|
||||
private MFlagColl()
|
||||
{
|
||||
this.setLowercasing(true);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// STACK TRACEABILITY
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void onTick()
|
||||
{
|
||||
super.onTick();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void setActive(boolean active)
|
||||
{
|
||||
super.setActive(active);
|
||||
if (!active) return;
|
||||
MFlag.setupStandardFlags();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// EXTRAS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public List<MFlag> getAll(boolean registered)
|
||||
{
|
||||
// Create
|
||||
List<MFlag> ret = new ArrayList<>();
|
||||
|
||||
// Fill
|
||||
for (MFlag mflag : this.getAll())
|
||||
{
|
||||
if (mflag.isRegistered() != registered) continue;
|
||||
ret.add(mflag);
|
||||
}
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import com.massivecraft.massivecore.store.Coll;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MFlagColl extends Coll<MFlag>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static MFlagColl i = new MFlagColl();
|
||||
public static MFlagColl get() { return i; }
|
||||
private MFlagColl()
|
||||
{
|
||||
this.setLowercasing(true);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// STACK TRACEABILITY
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void onTick()
|
||||
{
|
||||
super.onTick();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void setActive(boolean active)
|
||||
{
|
||||
super.setActive(active);
|
||||
if (!active) return;
|
||||
MFlag.setupStandardFlags();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// EXTRAS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public List<MFlag> getAll(boolean registered)
|
||||
{
|
||||
// Create
|
||||
List<MFlag> ret = new ArrayList<>();
|
||||
|
||||
// Fill
|
||||
for (MFlag mflag : this.getAll())
|
||||
{
|
||||
if (mflag.isRegistered() != registered) continue;
|
||||
ret.add(mflag);
|
||||
}
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,105 +1,105 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.massivecraft.massivecore.store.Coll;
|
||||
import com.massivecraft.massivecore.store.Modification;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class MPermColl extends Coll<MPerm>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static MPermColl i = new MPermColl();
|
||||
public static MPermColl get() { return i; }
|
||||
private MPermColl()
|
||||
{
|
||||
this.setLowercasing(true);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// STACK TRACEABILITY
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void onTick()
|
||||
{
|
||||
super.onTick();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void setActive(boolean active)
|
||||
{
|
||||
super.setActive(active);
|
||||
if (!active) return;
|
||||
MPerm.setupStandardPerms();
|
||||
}
|
||||
|
||||
private boolean initing = false;
|
||||
|
||||
// Change the ids
|
||||
@Override
|
||||
public synchronized void loadFromRemoteFixed(String id, Entry<JsonObject, Long> remoteEntry)
|
||||
{
|
||||
boolean renamed = false;
|
||||
if (initing)
|
||||
{
|
||||
if ("sethome".equalsIgnoreCase(id))
|
||||
{
|
||||
id = "setwarp";
|
||||
renamed = true;
|
||||
}
|
||||
if ("home".equalsIgnoreCase(id))
|
||||
{
|
||||
id = "home";
|
||||
renamed = true;
|
||||
}
|
||||
}
|
||||
|
||||
super.loadFromRemoteFixed(id, remoteEntry);
|
||||
if (renamed)
|
||||
{
|
||||
this.putIdentifiedModificationFixed(id, Modification.LOCAL_ATTACH);
|
||||
this.syncIdFixed(id);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initLoadAllFromRemote()
|
||||
{
|
||||
this.initing = true;
|
||||
super.initLoadAllFromRemote();
|
||||
this.removeAtRemoteFixed("sethome");
|
||||
this.removeAtRemoteFixed("home");
|
||||
this.initing = false;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// EXTRAS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public List<MPerm> getAll(boolean registered)
|
||||
{
|
||||
// Create
|
||||
List<MPerm> ret = new ArrayList<>();
|
||||
|
||||
// Fill
|
||||
for (MPerm mperm : this.getAll())
|
||||
{
|
||||
if (mperm.isRegistered() != registered) continue;
|
||||
ret.add(mperm);
|
||||
}
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.massivecraft.massivecore.store.Coll;
|
||||
import com.massivecraft.massivecore.store.Modification;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class MPermColl extends Coll<MPerm>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static MPermColl i = new MPermColl();
|
||||
public static MPermColl get() { return i; }
|
||||
private MPermColl()
|
||||
{
|
||||
this.setLowercasing(true);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// STACK TRACEABILITY
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void onTick()
|
||||
{
|
||||
super.onTick();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void setActive(boolean active)
|
||||
{
|
||||
super.setActive(active);
|
||||
if (!active) return;
|
||||
MPerm.setupStandardPerms();
|
||||
}
|
||||
|
||||
private boolean initing = false;
|
||||
|
||||
// Change the ids
|
||||
@Override
|
||||
public synchronized void loadFromRemoteFixed(String id, Entry<JsonObject, Long> remoteEntry)
|
||||
{
|
||||
boolean renamed = false;
|
||||
if (initing)
|
||||
{
|
||||
if ("sethome".equalsIgnoreCase(id))
|
||||
{
|
||||
id = "setwarp";
|
||||
renamed = true;
|
||||
}
|
||||
if ("home".equalsIgnoreCase(id))
|
||||
{
|
||||
id = "home";
|
||||
renamed = true;
|
||||
}
|
||||
}
|
||||
|
||||
super.loadFromRemoteFixed(id, remoteEntry);
|
||||
if (renamed)
|
||||
{
|
||||
this.putIdentifiedModificationFixed(id, Modification.LOCAL_ATTACH);
|
||||
this.syncIdFixed(id);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initLoadAllFromRemote()
|
||||
{
|
||||
this.initing = true;
|
||||
super.initLoadAllFromRemote();
|
||||
this.removeAtRemoteFixed("sethome");
|
||||
this.removeAtRemoteFixed("home");
|
||||
this.initing = false;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// EXTRAS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public List<MPerm> getAll(boolean registered)
|
||||
{
|
||||
// Create
|
||||
List<MPerm> ret = new ArrayList<>();
|
||||
|
||||
// Fill
|
||||
for (MPerm mperm : this.getAll())
|
||||
{
|
||||
if (mperm.isRegistered() != registered) continue;
|
||||
ret.add(mperm);
|
||||
}
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
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; }
|
||||
public MPlayerColl()
|
||||
{
|
||||
this.setCleanTaskEnabled(true);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// STACK TRACEABILITY
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void onTick()
|
||||
{
|
||||
super.onTick();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// EXTRAS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public long getCleanInactivityToleranceMillis()
|
||||
{
|
||||
return MConf.get().cleanInactivityToleranceMillis;
|
||||
}
|
||||
|
||||
}
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
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; }
|
||||
public MPlayerColl()
|
||||
{
|
||||
this.setCleanTaskEnabled(true);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// STACK TRACEABILITY
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void onTick()
|
||||
{
|
||||
super.onTick();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// EXTRAS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public long getCleanInactivityToleranceMillis()
|
||||
{
|
||||
return MConf.get().cleanInactivityToleranceMillis;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user