mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-11-25 19:56:23 +01:00
Max world claim count
This commit is contained in:
parent
7fc22db45a
commit
32db800fe1
@ -15,6 +15,7 @@ import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -93,9 +94,11 @@ import com.massivecraft.factions.integration.spigot.IntegrationSpigot;
|
||||
import com.massivecraft.factions.util.VisualizeUtil;
|
||||
import com.massivecraft.massivecore.Engine;
|
||||
import com.massivecraft.massivecore.PriorityLines;
|
||||
import com.massivecraft.massivecore.collections.MassiveList;
|
||||
import com.massivecraft.massivecore.collections.MassiveSet;
|
||||
import com.massivecraft.massivecore.event.EventMassiveCorePlayerLeave;
|
||||
import com.massivecraft.massivecore.mixin.Mixin;
|
||||
import com.massivecraft.massivecore.mixin.MixinWorld;
|
||||
import com.massivecraft.massivecore.money.Money;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
@ -520,17 +523,51 @@ public class EngineMain extends Engine
|
||||
return;
|
||||
}
|
||||
|
||||
// ... ensure the claim would not bypass the global max limit ...
|
||||
int ownedLand = newFaction.getLandCount();
|
||||
if (MConf.get().claimedLandsMax != 0 && ownedLand + chunks.size() > MConf.get().claimedLandsMax && ! newFaction.getFlag(MFlag.getFlagInfpower()))
|
||||
int claimedLandCount = newFaction.getLandCount();
|
||||
if ( ! newFaction.getFlag(MFlag.getFlagInfpower()))
|
||||
{
|
||||
mplayer.msg("<b>Limit reached. You can't claim more land.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
// ... ensure the claim would not bypass the global max limit ...
|
||||
if (MConf.get().claimedLandsMax != 0 && claimedLandCount + chunks.size() > MConf.get().claimedLandsMax)
|
||||
{
|
||||
mplayer.msg("<b>Limit reached. You can't claim more land.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// ... ensure the claim would not bypass the global max limit ...
|
||||
if (MConf.get().claimedWorldsMax >= 0)
|
||||
{
|
||||
Set<String> oldWorlds = newFaction.getClaimedWorlds();
|
||||
Set<String> newWorlds = PS.getDistinctWorlds(chunks);
|
||||
|
||||
Set<String> worlds = new MassiveSet<>();
|
||||
worlds.addAll(oldWorlds);
|
||||
worlds.addAll(newWorlds);
|
||||
|
||||
if (worlds.size() > MConf.get().claimedWorldsMax)
|
||||
{
|
||||
List<String> worldNames = new MassiveList<>();
|
||||
for (String world : oldWorlds)
|
||||
{
|
||||
worldNames.add(MixinWorld.get().getWorldDisplayName(world));
|
||||
}
|
||||
|
||||
String worldsMax = MConf.get().claimedWorldsMax == 1 ? "world" : "worlds";
|
||||
String worldsAlready = oldWorlds.size() == 1 ? "world" : "worlds";
|
||||
mplayer.msg("<b>A faction may only be present on <h>%d<b> different %s.", MConf.get().claimedWorldsMax, worldsMax);
|
||||
mplayer.msg("%s<i> is already present on <h>%d<i> %s:", newFaction.describeTo(mplayer), oldWorlds.size(), worldsAlready);
|
||||
mplayer.message(Txt.implodeCommaAndDot(worldNames, ChatColor.YELLOW.toString()));
|
||||
mplayer.msg("<i>Please unclaim bases on other worlds to claim here.");
|
||||
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ... ensure the claim would not bypass the faction power ...
|
||||
if (ownedLand + chunks.size() > newFaction.getPowerRounded())
|
||||
if (claimedLandCount + chunks.size() > newFaction.getPowerRounded())
|
||||
{
|
||||
mplayer.msg("<b>You don't have enough power to claim that land.");
|
||||
event.setCancelled(true);
|
||||
|
@ -276,6 +276,25 @@ public class Board extends Entity<Board> implements BoardInterface
|
||||
return ret;
|
||||
}
|
||||
|
||||
// CLAIMED
|
||||
|
||||
@Override
|
||||
public boolean hasClaimed(Faction faction)
|
||||
{
|
||||
return this.hasClaimed(faction.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasClaimed(String factionId)
|
||||
{
|
||||
for (TerritoryAccess ta : this.map.values())
|
||||
{
|
||||
if ( ! ta.getHostFactionId().equals(factionId)) continue;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// NEARBY DETECTION
|
||||
|
||||
// Is this coord NOT completely surrounded by coords claimed by the same faction?
|
||||
|
@ -14,6 +14,7 @@ import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.RelationParticipator;
|
||||
import com.massivecraft.factions.TerritoryAccess;
|
||||
import com.massivecraft.massivecore.collections.MassiveMap;
|
||||
import com.massivecraft.massivecore.collections.MassiveSet;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.store.Coll;
|
||||
import com.massivecraft.massivecore.store.MStore;
|
||||
@ -240,6 +241,25 @@ public class BoardColl extends Coll<Board> implements BoardInterface
|
||||
return ret;
|
||||
}
|
||||
|
||||
// COUNT
|
||||
|
||||
@Override
|
||||
public boolean hasClaimed(Faction faction)
|
||||
{
|
||||
return this.hasClaimed(faction.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasClaimed(String factionId)
|
||||
{
|
||||
for (Board board : this.getAll())
|
||||
{
|
||||
if ( ! board.hasClaimed(factionId)) continue;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// NEARBY DETECTION
|
||||
|
||||
@Override
|
||||
@ -291,6 +311,28 @@ public class BoardColl extends Coll<Board> implements BoardInterface
|
||||
return board.getMap(observer, centerPs, inDegrees, width, height);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// WORLDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Set<String> getClaimedWorlds(Faction faction)
|
||||
{
|
||||
return getClaimedWorlds(faction.getId());
|
||||
}
|
||||
|
||||
public Set<String> getClaimedWorlds(String factionId)
|
||||
{
|
||||
Set<String> ret = new MassiveSet<>();
|
||||
|
||||
for (Board board : this.getAll())
|
||||
{
|
||||
if ( ! board.hasClaimed(factionId)) continue;
|
||||
ret.add(board.getId());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UTIL
|
||||
// -------------------------------------------- //
|
||||
|
@ -33,6 +33,10 @@ public interface BoardInterface
|
||||
public int getCount(String factionId);
|
||||
public Map<Faction, Integer> getFactionToCount();
|
||||
|
||||
// CLAIMED
|
||||
public boolean hasClaimed(Faction faction);
|
||||
public boolean hasClaimed(String factionId);
|
||||
|
||||
// NEARBY DETECTION
|
||||
public boolean isBorderPs(PS ps);
|
||||
public boolean isAnyBorderPs(Set<PS> pss);
|
||||
|
@ -995,6 +995,15 @@ public class Faction extends Entity<Faction> implements EconomyParticipator, Nam
|
||||
return this.getLandCount() > this.getPowerRounded();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// WORLDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Set<String> getClaimedWorlds()
|
||||
{
|
||||
return BoardColl.get().getClaimedWorlds(this);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FOREIGN KEY: MPLAYER
|
||||
// -------------------------------------------- //
|
||||
|
@ -235,6 +235,9 @@ public class MConf extends Entity<MConf>
|
||||
// 0 means there isn't.
|
||||
public int claimedLandsMax = 0;
|
||||
|
||||
// The max amount of worlds in which a player can have claims in.
|
||||
public int claimedWorldsMax = -1;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// PROTECTION
|
||||
// -------------------------------------------- //
|
||||
|
Loading…
Reference in New Issue
Block a user