Add Faction warps

This commit is contained in:
Magnus Ulf
2019-01-26 15:04:47 +01:00
parent b13d2665da
commit 19de471de0
28 changed files with 726 additions and 354 deletions

View File

@ -70,7 +70,7 @@ public class Faction extends Entity<Faction> implements FactionsParticipator, MP
this.setDescription(that.description);
this.setMotd(that.motd);
this.setCreatedAtMillis(that.createdAtMillis);
this.setHome(that.home);
this.warps.load(that.warps);
this.setPowerBoost(that.powerBoost);
this.invitations.load(that.invitations);
this.ranks.load(that.ranks);
@ -99,7 +99,7 @@ public class Faction extends Entity<Faction> implements FactionsParticipator, MP
// VERSION
// -------------------------------------------- //
public int version = 2;
public int version = 3;
// -------------------------------------------- //
// FIELDS: RAW
@ -125,11 +125,9 @@ public class Faction extends Entity<Faction> implements FactionsParticipator, MP
// We store the creation date for the faction.
// It can be displayed on info pages etc.
private long createdAtMillis = System.currentTimeMillis();
// Factions can optionally set a home location.
// If they do their members can teleport there using /f home
// Null means the faction has no home.
private PS home = null;
// Factions can set a few significant locations (warps)
private EntityInternalMap<Warp> warps = new EntityInternalMap<>(this, Warp.class);
// Factions usually do not have a powerboost. It defaults to 0.
// The powerBoost is a custom increase/decrease to default and maximum power.
@ -362,46 +360,37 @@ public class Faction extends Entity<Faction> implements FactionsParticipator, MP
}
// -------------------------------------------- //
// FIELD: home
// FIELD: warp
// -------------------------------------------- //
public PS getHome()
public EntityInternalMap<Warp> getWarps() { return this.warps; }
public Warp getWarp(Object oid)
{
this.verifyHomeIsValid();
return this.home;
if (oid == null) throw new NullPointerException("oid");
Warp warp = this.getWarps().get(oid);
if (warp == null) return null;
if (!warp.verifyIsValid()) return null;
return warp;
}
public PS getWarpPS(Object oid)
{
if (oid == null) throw new NullPointerException("oid");
Warp warp = this.getWarp(oid);
if (warp == null) return null;
return warp.getLocation();
}
public void verifyHomeIsValid()
public String addWarp(Warp warp)
{
if (this.isValidHome(this.home)) return;
this.home = null;
this.changed();
msg("<b>Your faction home has been un-set since it is no longer in your territory.");
return this.getWarps().attach(warp);
}
public boolean isValidHome(PS ps)
public Warp removeWarp(Warp warp)
{
if (ps == null) return true;
if (!MConf.get().homesMustBeInClaimedTerritory) return true;
if (BoardColl.get().getFactionAt(ps) == this) return true;
return false;
}
public boolean hasHome()
{
return this.getHome() != null;
}
public void setHome(PS home)
{
// Detect Nochange
if (MUtil.equals(this.home, home)) return;
// Apply
this.home = home;
// Mark as changed
this.changed();
return this.getWarps().detachEntity(warp);
}
// -------------------------------------------- //

View File

@ -23,11 +23,11 @@ public class Invitation extends EntityInternal<Invitation>
private String inviterId;
public String getInviterId() { return inviterId; }
public void setInviterId(String inviterId) { this.inviterId = inviterId; }
public void setInviterId(String inviterId) { this.inviterId = inviterId; this.changed(); }
private Long creationMillis;
public Long getCreationMillis() { return creationMillis; }
public void setCreationMillis(Long creationMillis) { this.creationMillis = creationMillis; }
public void setCreationMillis(Long creationMillis) { this.creationMillis = creationMillis; this.changed(); }
// -------------------------------------------- //
// CONSTRUCT

View File

@ -59,7 +59,7 @@ public class MConf extends Entity<MConf>
// VERSION
// -------------------------------------------- //
public int version = 4;
public int version = 5;
// -------------------------------------------- //
// COMMAND ALIASES
@ -243,32 +243,34 @@ public class MConf extends Entity<MConf>
// HOMES
// -------------------------------------------- //
// Is the home feature enabled?
// If you set this to false players can't set homes or teleport home.
public boolean homesEnabled = true;
// Must homes be located inside the faction's territory?
// Is the warps feature enabled?
// If you set this to false players can't set warps or teleport to a warp.
public boolean warpsEnabled = true;
// How many warps can they have?
public int warpsMax = 1;
// Must warps be located inside the faction's territory?
// It's usually a wise idea keeping this true.
// Otherwise players can set their homes inside enemy territory.
public boolean homesMustBeInClaimedTerritory = true;
// Otherwise players can set their warps inside enemy territory.
public boolean warpsMustBeInClaimedTerritory = true;
// Is the home teleport command available?
// One reason you might set this to false is if you only want players going home on respawn after death.
public boolean homesTeleportCommandEnabled = true;
// These options can be used to limit rights to warp under different circumstances.
public boolean warpsTeleportAllowedFromEnemyTerritory = true;
public boolean warpsTeleportAllowedFromDifferentWorld = true;
public double warpsTeleportAllowedEnemyDistance = 32.0;
public boolean warpsTeleportIgnoreEnemiesIfInOwnTerritory = true;
// These options can be used to limit rights to tp home under different circumstances.
public boolean homesTeleportAllowedFromEnemyTerritory = true;
public boolean homesTeleportAllowedFromDifferentWorld = true;
public double homesTeleportAllowedEnemyDistance = 32.0;
public boolean homesTeleportIgnoreEnemiesIfInOwnTerritory = true;
// Should players teleport to faction home on death?
// Should players teleport to faction warp on death?
// Set this to true to override the default respawn location.
public boolean homesTeleportToOnDeathActive = false;
public boolean warpsTeleportToOnDeathActive = false;
// And waht faction warp should it be? It must have a specific name.
public String warpsTeleportToOnDeathName = "home";
// This value can be used to tweak compatibility with other plugins altering the respawn location.
// Choose between: LOWEST, LOW, NORMAL, HIGH, HIGHEST and MONITOR.
public EventPriority homesTeleportToOnDeathPriority = EventPriority.NORMAL;
public EventPriority warpsTeleportToOnDeathPriority = EventPriority.NORMAL;
// -------------------------------------------- //
// TERRITORY INFO
@ -590,13 +592,16 @@ public class MConf extends Entity<MConf>
public double econCostCreate = 100.0;
// And so on and so forth ... you get the idea.
public double econCostSethome = 0.0;
@Deprecated public double econCostSethome = 0.0;
public double econCostWarpAdd = 0.0;
public double econCostWarpRemove = 0.0;
public double econCostJoin = 0.0;
public double econCostLeave = 0.0;
public double econCostKick = 0.0;
public double econCostInvite = 0.0;
public double econCostDeinvite = 0.0;
public double econCostHome = 0.0;
@Deprecated public double econCostHome = 0.0;
public double econCostWarpGo = 0.0;
public double econCostName = 0.0;
public double econCostDescription = 0.0;
public double econCostTitle = 0.0;

View File

@ -0,0 +1,93 @@
package com.massivecraft.factions.entity;
import com.massivecraft.massivecore.Named;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.ps.PSFormatHumanSpace;
import com.massivecraft.massivecore.store.EntityInternal;
import com.massivecraft.massivecore.store.EntityInternalMap;
import com.massivecraft.massivecore.util.Txt;
public class Warp extends EntityInternal<Warp> implements Named
{
// -------------------------------------------- //
// OVERRIDE: ENTITY
// -------------------------------------------- //
@Override
public Warp load(Warp that)
{
this.name = that.name;
this.location = that.location;
return this;
}
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private String name;
public String getName() { return name; }
public void setName(String name) { this.name = name; this.changed(); }
private PS location;
public PS getLocation() { return location; }
public void setLocation(PS location) { this.location = location; this.changed(); }
public String getWorld() { return this.getLocation().getWorld(); }
public Faction getFaction()
{
EntityInternalMap<?> internalMap = (EntityInternalMap<?>) this.getContainer();
Faction faction = (Faction) internalMap.getEntity();
return faction;
}
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public Warp()
{
this(null, null);
}
public Warp(String name, PS location)
{
this.name = name;
this.location = location;
}
// -------------------------------------------- //
// VISUAL
// -------------------------------------------- //
public String getVisual(Object senderObject)
{
return Txt.parse("<h>%s<reset>:%s", this.getName(), this.getLocation().toString(PSFormatHumanSpace.get()));
}
// -------------------------------------------- //
// VALID
// -------------------------------------------- //
public boolean verifyIsValid()
{
if (this.isValid()) return true;
this.detach();
this.getFaction().msg("<b>Your faction warp <h>%s <b>has been un-set since it is no longer in your territory.", this.getName());
return false;
}
public boolean isValidFor(Faction faction)
{
if (!MConf.get().warpsMustBeInClaimedTerritory) return true;
if (BoardColl.get().getFactionAt(this.getLocation()) == faction) return true;
return false;
}
public boolean isValid()
{
return this.isValidFor(this.getFaction());
}
}

View File

@ -0,0 +1,51 @@
package com.massivecraft.factions.entity.migrator;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.Warp;
import com.massivecraft.massivecore.MassiveCore;
import com.massivecraft.massivecore.collections.MassiveMap;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.store.MStore;
import com.massivecraft.massivecore.store.migrator.MigratorRoot;
import java.util.Map;
public class MigratorFaction003Warps extends MigratorRoot
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static MigratorFaction003Warps i = new MigratorFaction003Warps();
public static MigratorFaction003Warps get() { return i; }
private MigratorFaction003Warps()
{
super(Faction.class);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void migrateInner(JsonObject entity)
{
JsonElement jsonHome = entity.remove("home");
if (jsonHome == null ||jsonHome.isJsonNull()) return;
if (!jsonHome.isJsonObject()) throw new RuntimeException("not JsonObject " + jsonHome);
PS psHome = MassiveCore.gson.fromJson(jsonHome, PS.class);
Warp warp = new Warp("home", psHome);
Map<String, Warp> warps = new MassiveMap<>();
warps.put(MStore.createId(), warp);
JsonElement jsonMap = MassiveCore.gson.toJsonTree(warps, (new TypeToken<Map<String,Warp>>(){}).getType());
entity.add("warps", jsonMap);
}
}

View File

@ -0,0 +1,28 @@
package com.massivecraft.factions.entity.migrator;
import com.massivecraft.factions.entity.MConf;
import com.massivecraft.massivecore.store.migrator.MigratorFieldRename;
import com.massivecraft.massivecore.store.migrator.MigratorRoot;
public class MigratorMConf005Warps extends MigratorRoot
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static MigratorMConf005Warps i = new MigratorMConf005Warps();
public static MigratorMConf005Warps get() { return i; }
private MigratorMConf005Warps()
{
super(MConf.class);
this.addInnerMigrator(MigratorFieldRename.get("homesEnabled", "warpsEnabled"));
this.addInnerMigrator(MigratorFieldRename.get("homesMustBeInClaimedTerritory", "warpsMustBeInClaimedTerritory"));
this.addInnerMigrator(MigratorFieldRename.get("homesTeleportAllowedFromEnemyTerritory", "warpsTeleportAllowedFromEnemyTerritory"));
this.addInnerMigrator(MigratorFieldRename.get("homesTeleportAllowedFromDifferentWorld", "warpsTeleportAllowedFromDifferentWorld"));
this.addInnerMigrator(MigratorFieldRename.get("homesTeleportAllowedEnemyDistance", "warpsTeleportAllowedEnemyDistance"));
this.addInnerMigrator(MigratorFieldRename.get("homesTeleportIgnoreEnemiesIfInOwnTerritory", "warpsTeleportIgnoreEnemiesIfInOwnTerritory"));
this.addInnerMigrator(MigratorFieldRename.get("homesTeleportToOnDeathActive", "warpsTeleportToOnDeathActive"));
this.addInnerMigrator(MigratorFieldRename.get("homesTeleportToOnDeathPriority", "warpsTeleportToOnDeathPriority"));
}
}