From 19de471de0f9dd44415024546f880d727817ead4 Mon Sep 17 00:00:00 2001 From: Magnus Ulf Date: Sat, 26 Jan 2019 15:04:47 +0100 Subject: [PATCH] Add Faction warps --- plugin.yml | 18 +++- src/com/massivecraft/factions/Factions.java | 4 + src/com/massivecraft/factions/Perm.java | 5 + .../factions/cmd/CmdFactions.java | 4 +- .../factions/cmd/CmdFactionsSethome.java | 69 -------------- .../factions/cmd/CmdFactionsWarp.java | 14 +++ .../factions/cmd/CmdFactionsWarpAdd.java | 85 +++++++++++++++++ ...ctionsHome.java => CmdFactionsWarpGo.java} | 69 +++++--------- .../factions/cmd/CmdFactionsWarpList.java | 48 ++++++++++ ...ethome.java => CmdFactionsWarpRemove.java} | 27 +++--- .../cmd/FactionsCommandDocumentation.java | 4 +- ...mandHome.java => FactionsCommandWarp.java} | 10 +- ...abled.java => ReqFactionWarpsEnabled.java} | 80 ++++++++-------- .../cmd/type/TypeEntityInternalFaction.java | 56 +++++++++++ .../factions/cmd/type/TypeRank.java | 30 +----- .../factions/cmd/type/TypeWarp.java | 37 ++++++++ .../factions/engine/EngineEcon.java | 27 ++++-- .../engine/EngineTeleportHomeOnDeath.java | 18 ++-- .../massivecraft/factions/entity/Faction.java | 69 ++++++-------- .../factions/entity/Invitation.java | 4 +- .../massivecraft/factions/entity/MConf.java | 49 +++++----- .../massivecraft/factions/entity/Warp.java | 93 +++++++++++++++++++ .../migrator/MigratorFaction003Warps.java | 51 ++++++++++ .../migrator/MigratorMConf005Warps.java | 28 ++++++ ...eChange.java => EventFactionsWarpAdd.java} | 80 ++++++++-------- .../event/EventFactionsWarpRemove.java | 40 ++++++++ ...rt.java => EventFactionsWarpTeleport.java} | 59 +++++++----- .../venturechat/EngineVentureChat.java | 2 - 28 files changed, 726 insertions(+), 354 deletions(-) delete mode 100644 src/com/massivecraft/factions/cmd/CmdFactionsSethome.java create mode 100644 src/com/massivecraft/factions/cmd/CmdFactionsWarp.java create mode 100644 src/com/massivecraft/factions/cmd/CmdFactionsWarpAdd.java rename src/com/massivecraft/factions/cmd/{CmdFactionsHome.java => CmdFactionsWarpGo.java} (61%) create mode 100644 src/com/massivecraft/factions/cmd/CmdFactionsWarpList.java rename src/com/massivecraft/factions/cmd/{CmdFactionsUnsethome.java => CmdFactionsWarpRemove.java} (53%) rename src/com/massivecraft/factions/cmd/{FactionsCommandHome.java => FactionsCommandWarp.java} (60%) rename src/com/massivecraft/factions/cmd/req/{ReqFactionHomesEnabled.java => ReqFactionWarpsEnabled.java} (74%) create mode 100644 src/com/massivecraft/factions/cmd/type/TypeEntityInternalFaction.java create mode 100644 src/com/massivecraft/factions/cmd/type/TypeWarp.java create mode 100644 src/com/massivecraft/factions/entity/Warp.java create mode 100644 src/com/massivecraft/factions/entity/migrator/MigratorFaction003Warps.java create mode 100644 src/com/massivecraft/factions/entity/migrator/MigratorMConf005Warps.java rename src/com/massivecraft/factions/event/{EventFactionsHomeChange.java => EventFactionsWarpAdd.java} (68%) create mode 100644 src/com/massivecraft/factions/event/EventFactionsWarpRemove.java rename src/com/massivecraft/factions/event/{EventFactionsHomeTeleport.java => EventFactionsWarpTeleport.java} (61%) diff --git a/plugin.yml b/plugin.yml index 965839cd..2b295930 100644 --- a/plugin.yml +++ b/plugin.yml @@ -38,7 +38,6 @@ permissions: factions.flag.list: {description: list flags, default: false} factions.flag.set: {description: set flags, default: false} factions.flag.show: {description: show flags, default: false} - factions.home: {description: teleport to faction home, default: false} factions.invite: {description: manage invites, default: false} factions.invite.list: {description: list invited players, default: false} factions.invite.list.other: {description: list invited players of another factions, default: false} @@ -87,7 +86,6 @@ permissions: factions.relation.wishes: {description: list the relation wishes, default: false} factions.seechunk: {description: see the chunk you stand in, default: false} factions.seechunkold: {description: see the chunk you stand in, default: false} - factions.sethome: {description: set the faction home, default: false} factions.setpower: {description: set power, default: false} factions.status: {description: show status, default: false} factions.name: {description: set faction name, default: false} @@ -101,7 +99,11 @@ permissions: factions.unclaim.square: {description: unclaim by square and radius, default: false} factions.unclaim.circle: {description: unclaim by circle and radius, default: false} factions.unclaim.all: {description: unclaim all faction land, default: false} - factions.unsethome: {description: unset faction home, default: false} + factions.warp: {description: use warps, default: false} + factions.warp.go: {description: go to a warp, default: false} + factions.warp.list: {description: list warps, default: false} + factions.warp.add: {description: add new warp, default: false} + factions.warp.remove: {description: remove warp, default: false} factions.unstuck: {description: teleport to nearest wilderness, default: false} factions.config: {description: edit the factions config, default: false} factions.clean: {description: clean the factions database, default: false} @@ -209,6 +211,11 @@ permissions: factions.unclaim.all: true factions.unsethome: true factions.unstuck: true + factions.warp: true + factions.warp.go: true + factions.warp.list: true + factions.warp.add: true + factions.warp.remove: true factions.config: true factions.clean: true factions.version: true @@ -335,6 +342,11 @@ permissions: factions.unclaim.all: true factions.unsethome: true factions.unstuck: true + factions.warp: true + factions.warp.go: true + factions.warp.list: true + factions.warp.add: true + factions.warp.remove: true factions.version: true factions.kit.default: default: true diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index 764c9ea1..71b4a68e 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -53,10 +53,12 @@ import com.massivecraft.factions.entity.MPermColl; import com.massivecraft.factions.entity.MPlayerColl; import com.massivecraft.factions.entity.migrator.MigratorFaction001Invitations; import com.massivecraft.factions.entity.migrator.MigratorFaction002Ranks; +import com.massivecraft.factions.entity.migrator.MigratorFaction003Warps; import com.massivecraft.factions.entity.migrator.MigratorMConf001EnumerationUtil; import com.massivecraft.factions.entity.migrator.MigratorMConf002CleanInactivity; import com.massivecraft.factions.entity.migrator.MigratorMConf003CleanInactivity; import com.massivecraft.factions.entity.migrator.MigratorMConf004Rank; +import com.massivecraft.factions.entity.migrator.MigratorMConf005Warps; import com.massivecraft.factions.entity.migrator.MigratorMPlayer001Ranks; import com.massivecraft.factions.event.EventFactionsChunkChangeType; import com.massivecraft.factions.integration.V18.IntegrationV18; @@ -139,10 +141,12 @@ public class Factions extends MassivePlugin return MUtil.list( MigratorFaction001Invitations.class, MigratorFaction002Ranks.class, + MigratorFaction003Warps.class, MigratorMConf001EnumerationUtil.class, MigratorMConf002CleanInactivity.class, MigratorMConf003CleanInactivity.class, MigratorMConf004Rank.class, + MigratorMConf005Warps.class, MigratorMPlayer001Ranks.class ); } diff --git a/src/com/massivecraft/factions/Perm.java b/src/com/massivecraft/factions/Perm.java index 8441aaee..adbf03ec 100644 --- a/src/com/massivecraft/factions/Perm.java +++ b/src/com/massivecraft/factions/Perm.java @@ -102,6 +102,11 @@ public enum Perm implements Identified UNCLAIM_ALL, UNSETHOME, UNSTUCK, + WARP, + WARP_GO, + WARP_LIST, + WARP_ADD, + WARP_REMOVE, CONFIG, CLEAN, VERSION, diff --git a/src/com/massivecraft/factions/cmd/CmdFactions.java b/src/com/massivecraft/factions/cmd/CmdFactions.java index 24a99775..b4031026 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactions.java +++ b/src/com/massivecraft/factions/cmd/CmdFactions.java @@ -29,14 +29,12 @@ public class CmdFactions extends FactionsCommand public CmdFactionsStatus cmdFactionsStatus = new CmdFactionsStatus(); public CmdFactionsJoin cmdFactionsJoin = new CmdFactionsJoin(); public CmdFactionsLeave cmdFactionsLeave = new CmdFactionsLeave(); - public CmdFactionsHome cmdFactionsHome = new CmdFactionsHome(); + public CmdFactionsWarp cmdFactionsWarp = new CmdFactionsWarp(); public CmdFactionsMap cmdFactionsMap = new CmdFactionsMap(); public CmdFactionsCreate cmdFactionsCreate = new CmdFactionsCreate(); public CmdFactionsName cmdFactionsName = new CmdFactionsName(); public CmdFactionsDescription cmdFactionsDescription = new CmdFactionsDescription(); public CmdFactionsMotd cmdFactionsMotd = new CmdFactionsMotd(); - public CmdFactionsSethome cmdFactionsSethome = new CmdFactionsSethome(); - public CmdFactionsUnsethome cmdFactionsUnsethome = new CmdFactionsUnsethome(); public CmdFactionsInvite cmdFactionsInvite = new CmdFactionsInvite(); public CmdFactionsKick cmdFactionsKick = new CmdFactionsKick(); public CmdFactionsTitle cmdFactionsTitle = new CmdFactionsTitle(); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java b/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java deleted file mode 100644 index b52671bf..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Perm; -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.event.EventFactionsHomeChange; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.requirement.RequirementHasPerm; -import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; -import com.massivecraft.massivecore.ps.PS; - -public class CmdFactionsSethome extends FactionsCommandHome -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsSethome() - { - // Parameters - this.addParameter(TypeFaction.get(), "faction", "you"); - - // Requirements - this.addRequirements(RequirementHasPerm.get(Perm.SETHOME)); - this.addRequirements(RequirementIsPlayer.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - Faction faction = this.readArg(msenderFaction); - - PS newHome = PS.valueOf(me.getLocation()); - - // MPerm - if ( ! MPerm.getPermSethome().has(msender, faction, true)) return; - - // Verify - if (!msender.isOverriding() && !faction.isValidHome(newHome)) - { - msender.msg("Sorry, your faction home can only be set inside your own claimed territory."); - return; - } - - // Event - EventFactionsHomeChange event = new EventFactionsHomeChange(sender, faction, newHome); - event.run(); - if (event.isCancelled()) return; - newHome = event.getNewHome(); - - // Apply - faction.setHome(newHome); - - // Inform - faction.msg("%s set the home for your faction. You can now use:", msender.describeTo(msenderFaction, true)); - faction.sendMessage(CmdFactions.get().cmdFactionsHome.getTemplate()); - if (faction != msenderFaction) - { - msender.msg("You have set the home for " + faction.getName(msender) + "."); - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsWarp.java b/src/com/massivecraft/factions/cmd/CmdFactionsWarp.java new file mode 100644 index 00000000..31a54195 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsWarp.java @@ -0,0 +1,14 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsWarp extends FactionsCommand +{ + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public CmdFactionsWarpGo cmdFactionsWarpGo = new CmdFactionsWarpGo(); + public CmdFactionsWarpList cmdFactionsWarpList = new CmdFactionsWarpList(); + public CmdFactionsWarpAdd cmdFactionWarpAdd = new CmdFactionsWarpAdd(); + public CmdFactionsWarpRemove cmdFactionWarpRemove = new CmdFactionsWarpRemove(); + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsWarpAdd.java b/src/com/massivecraft/factions/cmd/CmdFactionsWarpAdd.java new file mode 100644 index 00000000..97068272 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsWarpAdd.java @@ -0,0 +1,85 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.Warp; +import com.massivecraft.factions.event.EventFactionsWarpAdd; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; +import com.massivecraft.massivecore.command.type.primitive.TypeString; +import com.massivecraft.massivecore.ps.PS; + +public class CmdFactionsWarpAdd extends FactionsCommandWarp +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsWarpAdd() + { + // Parameters + this.addParameter(TypeString.get(), "name"); + this.addParameter(TypeFaction.get(), "faction", "you"); + + // Aliases + this.addAliases("create"); + + // Requirements + this.addRequirements(RequirementIsPlayer.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException + { + // Args + String name = this.readArg(); + Faction faction = this.readArg(msenderFaction); + + + PS ps = PS.valueOf(me.getLocation()); + Warp warp = new Warp(name, ps); + + // MPerm + if ( ! MPerm.getPermSethome().has(msender, faction, true)) return; + + if (faction.getWarps().getAll().stream().map(Warp::getName).anyMatch(s -> s.equalsIgnoreCase(name))) + { + throw new MassiveException().addMsg("There is already a warp called %s.", name); + } + + // Verify + if (!msender.isOverriding() && !warp.isValidFor(faction)) + { + throw new MassiveException().addMsg("Sorry, your faction warps can only be set inside your own claimed territory."); + } + + if (!msender.isOverriding() && faction.getWarps().size() >= MConf.get().warpsMax && MConf.get().warpsMax >= 0) + { + throw new MassiveException().addMsg("You can at most have %d warps at a time.", MConf.get().warpsMax); + } + + // Event + EventFactionsWarpAdd event = new EventFactionsWarpAdd(sender, faction, warp); + event.run(); + if (event.isCancelled()) return; + warp = event.getNewWarp(); + + // Apply + faction.getWarps().attach(warp); + + // Inform + faction.msg("%s added the warp %s to your faction. You can now use:", msender.describeTo(msenderFaction, true), warp.getName()); + faction.sendMessage(CmdFactions.get().cmdFactionsWarp.cmdFactionsWarpGo.getTemplateWithArgs(null, warp.getName())); + if (faction != msenderFaction) + { + msender.msg("You added the warp %s to %s.", warp.getName(), faction.describeTo(msender)); + } + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsHome.java b/src/com/massivecraft/factions/cmd/CmdFactionsWarpGo.java similarity index 61% rename from src/com/massivecraft/factions/cmd/CmdFactionsHome.java rename to src/com/massivecraft/factions/cmd/CmdFactionsWarpGo.java index fb42b9ef..fcde63ef 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsHome.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsWarpGo.java @@ -2,13 +2,15 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Rel; import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.cmd.type.TypeWarp; import com.massivecraft.factions.entity.BoardColl; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MFlag; import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.event.EventFactionsHomeTeleport; +import com.massivecraft.factions.entity.Warp; +import com.massivecraft.factions.event.EventFactionsWarpTeleport; import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; import com.massivecraft.massivecore.mixin.MixinMessage; @@ -18,19 +20,21 @@ import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.teleport.Destination; import com.massivecraft.massivecore.teleport.DestinationSimple; import com.massivecraft.massivecore.util.MUtil; +import com.massivecraft.massivecore.util.Txt; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; -public class CmdFactionsHome extends FactionsCommandHome +public class CmdFactionsWarpGo extends FactionsCommandWarp { // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // - public CmdFactionsHome() + public CmdFactionsWarpGo() { // Parameters + this.addParameter(TypeWarp.get(), "warp"); this.addParameter(TypeFaction.get(), "faction", "you"); // Requirements @@ -44,53 +48,31 @@ public class CmdFactionsHome extends FactionsCommandHome @Override public void perform() throws MassiveException { - if ( ! MConf.get().homesTeleportCommandEnabled) - { - msender.msg("Sorry, the ability to teleport to Faction homes is disabled on this server."); - return; - } - // Args - Faction faction = this.readArg(msenderFaction); - PS home = faction.getHome(); - String homeDesc = "home for " + faction.describeTo(msender, false); + Faction faction = this.readArgAt(1, msenderFaction); + Warp warp = TypeWarp.get(faction).read(this.argAt(0), sender); + String warpDesc = Txt.parse("%s in %s.", warp.getName(), faction.describeTo(msender, false)); // Any and MPerm if ( ! MPerm.getPermHome().has(msender, faction, true)) return; - if (home == null) + if ( ! MConf.get().warpsTeleportAllowedFromEnemyTerritory && msender.isInEnemyTerritory()) { - msender.msg("%s does not have a home.", faction.describeTo(msender, true)); - - if (MPerm.getPermSethome().has(msender, faction, false)) - { - msender.msg("You should:"); - msender.message(CmdFactions.get().cmdFactionsSethome.getTemplate()); - } - - return; + throw new MassiveException().addMsg("You cannot teleport to %s while in the territory of an enemy faction.", warp); } - if ( ! MConf.get().homesTeleportAllowedFromEnemyTerritory && msender.isInEnemyTerritory()) + if ( ! MConf.get().warpsTeleportAllowedFromDifferentWorld && !me.getWorld().getName().equalsIgnoreCase(warp.getWorld())) { - msender.msg("You cannot teleport to %s while in the territory of an enemy faction.", homeDesc); - return; + throw new MassiveException().addMsg("You cannot teleport to %s while in a different world.", warpDesc); } - - if ( ! MConf.get().homesTeleportAllowedFromDifferentWorld && !me.getWorld().getName().equalsIgnoreCase(home.getWorld())) - { - msender.msg("You cannot teleport to %s while in a different world.", homeDesc); - return; - } - - + Faction factionHere = BoardColl.get().getFactionAt(PS.valueOf(me.getLocation())); Location locationHere = me.getLocation().clone(); // if player is not in a safe zone or their own faction territory, only allow teleport if no enemies are nearby if ( - MConf.get().homesTeleportAllowedEnemyDistance > 0 + MConf.get().warpsTeleportAllowedEnemyDistance > 0 && factionHere.getFlag(MFlag.getFlagPvp()) && @@ -100,7 +82,7 @@ public class CmdFactionsHome extends FactionsCommandHome ( msender.isInOwnTerritory() && - ! MConf.get().homesTeleportIgnoreEnemiesIfInOwnTerritory + ! MConf.get().warpsTeleportIgnoreEnemiesIfInOwnTerritory ) ) ) @@ -110,41 +92,38 @@ public class CmdFactionsHome extends FactionsCommandHome double y = locationHere.getY(); double z = locationHere.getZ(); - for (Player p : me.getServer().getOnlinePlayers()) + for (Player p : w.getPlayers()) { if (MUtil.isntPlayer(p)) continue; - if (p == null || !p.isOnline() || p.isDead() || p == me || p.getWorld() != w) - continue; + if (p == null || !p.isOnline() || p.isDead() || p == me || p.getWorld() != w) continue; MPlayer fp = MPlayer.get(p); - if (msender.getRelationTo(fp) != Rel.ENEMY) - continue; + if (msender.getRelationTo(fp) != Rel.ENEMY) continue; Location l = p.getLocation(); double dx = Math.abs(x - l.getX()); double dy = Math.abs(y - l.getY()); double dz = Math.abs(z - l.getZ()); - double max = MConf.get().homesTeleportAllowedEnemyDistance; + double max = MConf.get().warpsTeleportAllowedEnemyDistance; // box-shaped distance check if (dx > max || dy > max || dz > max) continue; - msender.msg("You cannot teleport to %s while an enemy is within %f blocks of you.", homeDesc, MConf.get().homesTeleportAllowedEnemyDistance); - return; + throw new MassiveException().addMsg("You cannot teleport to %s while an enemy is within %f blocks of you.", warpDesc, max); } } // Event - EventFactionsHomeTeleport event = new EventFactionsHomeTeleport(sender); + EventFactionsWarpTeleport event = new EventFactionsWarpTeleport(sender, warp); event.run(); if (event.isCancelled()) return; // Apply try { - Destination destination = new DestinationSimple(home, homeDesc); + Destination destination = new DestinationSimple(warp.getLocation(), warpDesc); MixinTeleport.get().teleport(me, destination, sender); } catch (TeleporterException e) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsWarpList.java b/src/com/massivecraft/factions/cmd/CmdFactionsWarpList.java new file mode 100644 index 00000000..9d42f263 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsWarpList.java @@ -0,0 +1,48 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.Warp; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.Parameter; +import com.massivecraft.massivecore.pager.Pager; +import com.massivecraft.massivecore.pager.Stringifier; +import com.massivecraft.massivecore.ps.PSFormatDesc; +import com.massivecraft.massivecore.util.Txt; + +public class CmdFactionsWarpList extends FactionsCommandWarp +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsWarpList() + { + // Parameters + this.addParameter(TypeFaction.get(), "faction", "you"); + this.addParameter(Parameter.getPage()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException + { + // Args + Faction faction = this.readArg(msenderFaction); + int idx = this.readArg(); + + // Any and MPerm + if ( ! MPerm.getPermHome().has(msender, faction, true)) return; + + Pager pager = new Pager<>(this, "Warps for " + faction.getName(), idx, faction.getWarps().getAll()); + pager.setMsonifier((Stringifier) (warp, i) -> + Txt.parse("%s: %s", warp.getName(), warp.getLocation().getBlock(true).toString(PSFormatDesc.get()))); + + pager.message(); + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsUnsethome.java b/src/com/massivecraft/factions/cmd/CmdFactionsWarpRemove.java similarity index 53% rename from src/com/massivecraft/factions/cmd/CmdFactionsUnsethome.java rename to src/com/massivecraft/factions/cmd/CmdFactionsWarpRemove.java index 7d49cf55..2140b13e 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsUnsethome.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsWarpRemove.java @@ -1,20 +1,23 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.cmd.type.TypeWarp; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.event.EventFactionsHomeChange; +import com.massivecraft.factions.entity.Warp; +import com.massivecraft.factions.event.EventFactionsWarpRemove; import com.massivecraft.massivecore.MassiveException; -public class CmdFactionsUnsethome extends FactionsCommandHome +public class CmdFactionsWarpRemove extends FactionsCommandWarp { // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // - public CmdFactionsUnsethome() + public CmdFactionsWarpRemove() { // Parameters + this.addParameter(TypeWarp.get(), "warp"); this.addParameter(TypeFaction.get(), "faction", "you"); } @@ -26,31 +29,25 @@ public class CmdFactionsUnsethome extends FactionsCommandHome public void perform() throws MassiveException { // Args - Faction faction = this.readArg(msenderFaction); + Faction faction = this.readArgAt(1, msenderFaction); + Warp warp = TypeWarp.get(faction).read(this.argAt(0), sender); // Any and MPerm if ( ! MPerm.getPermSethome().has(msender, faction, true)) return; - // NoChange - if ( ! faction.hasHome()) - { - msender.msg("%s does already not have a home.", faction.describeTo(msender)); - return; - } - // Event - EventFactionsHomeChange event = new EventFactionsHomeChange(sender, faction, null); + EventFactionsWarpRemove event = new EventFactionsWarpRemove(sender, faction, warp); event.run(); if (event.isCancelled()) return; // Apply - faction.setHome(null); + warp.detach(); // Inform - faction.msg("%s unset the home for your faction.", msender.describeTo(msenderFaction, true)); + faction.msg("%s removed the warp %s for your faction.", msender.describeTo(msenderFaction, true), warp.getName()); if (faction != msenderFaction) { - msender.msg("You have unset the home for " + faction.getName(msender) + "."); + msender.msg("You have removed the warp %s for %s.", warp.getName(), faction.getName(msender)); } } diff --git a/src/com/massivecraft/factions/cmd/FactionsCommandDocumentation.java b/src/com/massivecraft/factions/cmd/FactionsCommandDocumentation.java index 8a0a9c17..e0a2e5cc 100644 --- a/src/com/massivecraft/factions/cmd/FactionsCommandDocumentation.java +++ b/src/com/massivecraft/factions/cmd/FactionsCommandDocumentation.java @@ -1,6 +1,6 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.cmd.req.ReqFactionHomesEnabled; +import com.massivecraft.factions.cmd.req.ReqFactionWarpsEnabled; import com.massivecraft.massivecore.mson.Mson; public class FactionsCommandDocumentation extends FactionsCommand @@ -11,7 +11,7 @@ public class FactionsCommandDocumentation extends FactionsCommand public FactionsCommandDocumentation() { - this.addRequirements(ReqFactionHomesEnabled.get()); + this.addRequirements(ReqFactionWarpsEnabled.get()); } // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/cmd/FactionsCommandHome.java b/src/com/massivecraft/factions/cmd/FactionsCommandWarp.java similarity index 60% rename from src/com/massivecraft/factions/cmd/FactionsCommandHome.java rename to src/com/massivecraft/factions/cmd/FactionsCommandWarp.java index 264d43cc..b9251d22 100644 --- a/src/com/massivecraft/factions/cmd/FactionsCommandHome.java +++ b/src/com/massivecraft/factions/cmd/FactionsCommandWarp.java @@ -1,18 +1,18 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.cmd.req.ReqFactionHomesEnabled; +import com.massivecraft.factions.cmd.req.ReqFactionWarpsEnabled; import com.massivecraft.factions.entity.MConf; import com.massivecraft.massivecore.command.Visibility; -public class FactionsCommandHome extends FactionsCommand +public class FactionsCommandWarp extends FactionsCommand { // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // - public FactionsCommandHome() + public FactionsCommandWarp() { - this.addRequirements(ReqFactionHomesEnabled.get()); + this.addRequirements(ReqFactionWarpsEnabled.get()); } // -------------------------------------------- // @@ -22,7 +22,7 @@ public class FactionsCommandHome extends FactionsCommand @Override public Visibility getVisibility() { - return MConf.get().homesEnabled ? super.getVisibility() : Visibility.INVISIBLE; + return MConf.get().warpsEnabled ? super.getVisibility() : Visibility.INVISIBLE; } } diff --git a/src/com/massivecraft/factions/cmd/req/ReqFactionHomesEnabled.java b/src/com/massivecraft/factions/cmd/req/ReqFactionWarpsEnabled.java similarity index 74% rename from src/com/massivecraft/factions/cmd/req/ReqFactionHomesEnabled.java rename to src/com/massivecraft/factions/cmd/req/ReqFactionWarpsEnabled.java index 43ba4ca7..4fb2547c 100644 --- a/src/com/massivecraft/factions/cmd/req/ReqFactionHomesEnabled.java +++ b/src/com/massivecraft/factions/cmd/req/ReqFactionWarpsEnabled.java @@ -1,40 +1,40 @@ -package com.massivecraft.factions.cmd.req; - -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.massivecore.command.MassiveCommand; -import com.massivecraft.massivecore.command.requirement.RequirementAbstract; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.command.CommandSender; - -public class ReqFactionHomesEnabled extends RequirementAbstract -{ - // -------------------------------------------- // - // SERIALIZABLE - // -------------------------------------------- // - - private static final long serialVersionUID = 1L; - - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static ReqFactionHomesEnabled i = new ReqFactionHomesEnabled(); - public static ReqFactionHomesEnabled get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public boolean apply(CommandSender sender, MassiveCommand command) - { - return MConf.get().homesEnabled; - } - - @Override - public String createErrorMessage(CommandSender sender, MassiveCommand command) - { - return Txt.parse("Homes must be enabled on the server to %s.", getDesc(command)); - } - -} +package com.massivecraft.factions.cmd.req; + +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.massivecore.command.MassiveCommand; +import com.massivecraft.massivecore.command.requirement.RequirementAbstract; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.command.CommandSender; + +public class ReqFactionWarpsEnabled extends RequirementAbstract +{ + // -------------------------------------------- // + // SERIALIZABLE + // -------------------------------------------- // + + private static final long serialVersionUID = 1L; + + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ReqFactionWarpsEnabled i = new ReqFactionWarpsEnabled(); + public static ReqFactionWarpsEnabled get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public boolean apply(CommandSender sender, MassiveCommand command) + { + return MConf.get().warpsEnabled; + } + + @Override + public String createErrorMessage(CommandSender sender, MassiveCommand command) + { + return Txt.parse("Warps must be enabled on the server to %s.", getDesc(command)); + } + +} diff --git a/src/com/massivecraft/factions/cmd/type/TypeEntityInternalFaction.java b/src/com/massivecraft/factions/cmd/type/TypeEntityInternalFaction.java new file mode 100644 index 00000000..5e8ee7d7 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/type/TypeEntityInternalFaction.java @@ -0,0 +1,56 @@ +package com.massivecraft.factions.cmd.type; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.massivecore.command.type.TypeAbstractChoice; +import com.massivecraft.massivecore.store.EntityInternal; +import org.bukkit.command.CommandSender; + +import java.util.Collection; +import java.util.Collections; + +public abstract class TypeEntityInternalFaction> extends TypeAbstractChoice +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + protected TypeEntityInternalFaction(Class clazz) + { + super(clazz); + + this.faction = null; + this.setAll(Collections.emptyList()); + } + + protected TypeEntityInternalFaction(Class clazz, Faction faction) + { + super(clazz); + if (faction == null) throw new NullPointerException("faction"); + + this.faction = faction; + + this.setAll(this.getAll(faction)); + } + + protected abstract Collection getAll(Faction faction); + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final Faction faction; + public Faction getFaction() { return this.faction; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public boolean isValid(String arg, CommandSender sender) + { + // In the generic case accept all + if (this.getAll().isEmpty()) return true; + else return super.isValid(arg, sender); + } + +} diff --git a/src/com/massivecraft/factions/cmd/type/TypeRank.java b/src/com/massivecraft/factions/cmd/type/TypeRank.java index 3b412406..1cf93e78 100644 --- a/src/com/massivecraft/factions/cmd/type/TypeRank.java +++ b/src/com/massivecraft/factions/cmd/type/TypeRank.java @@ -1,16 +1,13 @@ package com.massivecraft.factions.cmd.type; -import com.massivecraft.factions.Rel; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Rank; -import com.massivecraft.massivecore.command.type.TypeAbstractChoice; import com.massivecraft.massivecore.util.MUtil; -import org.bukkit.command.CommandSender; -import java.util.Collections; +import java.util.Collection; import java.util.Set; -public class TypeRank extends TypeAbstractChoice +public class TypeRank extends TypeEntityInternalFaction { // -------------------------------------------- // // INSTANCE & CONSTRUCT @@ -21,39 +18,22 @@ public class TypeRank extends TypeAbstractChoice private TypeRank() { super(Rank.class); - - this.faction = null; - this.setAll(Collections.emptyList()); } public static TypeRank get(Faction faction) { return new TypeRank(faction); } public TypeRank(Faction faction) { - super(Rel.class); - if (faction == null) throw new NullPointerException("faction"); - - this.faction = faction; - - this.setAll(faction.getRanks().getAll()); + super(Rank.class, faction); } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final Faction faction; - public Faction getFaction() { return this.faction; } // -------------------------------------------- // // OVERRIDE // -------------------------------------------- // @Override - public boolean isValid(String arg, CommandSender sender) + public Collection getAll(Faction faction) { - // In the generic case accept all - if (this.getAll().isEmpty()) return true; - else return super.isValid(arg, sender); + return faction.getRanks().getAll(); } @Override diff --git a/src/com/massivecraft/factions/cmd/type/TypeWarp.java b/src/com/massivecraft/factions/cmd/type/TypeWarp.java new file mode 100644 index 00000000..9cdba36a --- /dev/null +++ b/src/com/massivecraft/factions/cmd/type/TypeWarp.java @@ -0,0 +1,37 @@ +package com.massivecraft.factions.cmd.type; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.Warp; + +import java.util.Collection; + +public class TypeWarp extends TypeEntityInternalFaction +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static TypeWarp i = new TypeWarp(); + public static TypeWarp get() { return i; } + private TypeWarp() + { + super(Warp.class); + } + + public static TypeWarp get(Faction faction) { return new TypeWarp(faction); } + public TypeWarp(Faction faction) + { + super(Warp.class, faction); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Collection getAll(Faction faction) + { + return faction.getWarps().getAll(); + } + +} diff --git a/src/com/massivecraft/factions/engine/EngineEcon.java b/src/com/massivecraft/factions/engine/EngineEcon.java index 081a39fb..5f972e20 100644 --- a/src/com/massivecraft/factions/engine/EngineEcon.java +++ b/src/com/massivecraft/factions/engine/EngineEcon.java @@ -12,8 +12,9 @@ import com.massivecraft.factions.event.EventFactionsCreate; import com.massivecraft.factions.event.EventFactionsDescriptionChange; import com.massivecraft.factions.event.EventFactionsDisband; import com.massivecraft.factions.event.EventFactionsFlagChange; -import com.massivecraft.factions.event.EventFactionsHomeChange; -import com.massivecraft.factions.event.EventFactionsHomeTeleport; +import com.massivecraft.factions.event.EventFactionsWarpAdd; +import com.massivecraft.factions.event.EventFactionsWarpRemove; +import com.massivecraft.factions.event.EventFactionsWarpTeleport; import com.massivecraft.factions.event.EventFactionsInvitedChange; import com.massivecraft.factions.event.EventFactionsMembershipChange; import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; @@ -177,13 +178,22 @@ public class EngineEcon extends Engine } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(EventFactionsHomeChange event) + public void payForCommand(EventFactionsWarpAdd event) { - Double cost = MConf.get().econCostSethome; - String desc = CmdFactions.get().cmdFactionsSethome.getDesc(); + Double cost = MConf.get().econCostWarpAdd; + String desc = CmdFactions.get().cmdFactionsWarp.cmdFactionWarpAdd.getDesc(); payForAction(event, cost, desc); } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(EventFactionsWarpRemove event) + { + Double cost = MConf.get().econCostWarpRemove; + String desc = CmdFactions.get().cmdFactionsWarp.cmdFactionWarpRemove.getDesc(); + + payForAction(event, cost, desc); + } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void payForCommand(EventFactionsCreate event) @@ -240,13 +250,12 @@ public class EngineEcon extends Engine } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(EventFactionsHomeTeleport event) + public void payForCommand(EventFactionsWarpTeleport event) { - Double cost = MConf.get().econCostHome; - String desc = CmdFactions.get().cmdFactionsHome.getDesc(); + Double cost = MConf.get().econCostWarpGo; + String desc = CmdFactions.get().cmdFactionsWarp.cmdFactionsWarpGo.getDesc(); payForAction(event, cost, desc); } - } diff --git a/src/com/massivecraft/factions/engine/EngineTeleportHomeOnDeath.java b/src/com/massivecraft/factions/engine/EngineTeleportHomeOnDeath.java index d3c7d7bb..380e4fac 100644 --- a/src/com/massivecraft/factions/engine/EngineTeleportHomeOnDeath.java +++ b/src/com/massivecraft/factions/engine/EngineTeleportHomeOnDeath.java @@ -3,8 +3,8 @@ package com.massivecraft.factions.engine; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.entity.Warp; import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.util.MUtil; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -12,6 +12,8 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerRespawnEvent; +import java.util.List; + public class EngineTeleportHomeOnDeath extends Engine { // -------------------------------------------- // @@ -33,23 +35,25 @@ public class EngineTeleportHomeOnDeath extends Engine final MPlayer mplayer = MPlayer.get(player); // ... homes are enabled, active and at this priority ... - if (!MConf.get().homesEnabled) return; - if (!MConf.get().homesTeleportToOnDeathActive) return; - if (MConf.get().homesTeleportToOnDeathPriority != priority) return; + if (!MConf.get().warpsEnabled) return; + if (!MConf.get().warpsTeleportToOnDeathActive) return; + if (MConf.get().warpsTeleportToOnDeathPriority != priority) return; // ... and the player has a faction ... final Faction faction = mplayer.getFaction(); if (faction.isNone()) return; // ... and the faction has a home ... - PS home = faction.getHome(); - if (home == null) return; + List warps = faction.getWarps().getAll(warp -> warp.getName().equalsIgnoreCase(MConf.get().warpsTeleportToOnDeathName)); + if (warps.isEmpty()) return; + + Warp warp = warps.get(0); // ... and the home is translatable ... Location respawnLocation = null; try { - respawnLocation = home.asBukkitLocation(true); + respawnLocation = warp.getLocation().asBukkitLocation(true); } catch (Exception e) { diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index eb05e5a0..99bc8483 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -70,7 +70,7 @@ public class Faction extends Entity 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 implements FactionsParticipator, MP // VERSION // -------------------------------------------- // - public int version = 2; + public int version = 3; // -------------------------------------------- // // FIELDS: RAW @@ -125,11 +125,9 @@ public class Faction extends Entity 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 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 implements FactionsParticipator, MP } // -------------------------------------------- // - // FIELD: home + // FIELD: warp // -------------------------------------------- // - - public PS getHome() + + public EntityInternalMap 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("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); } // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/entity/Invitation.java b/src/com/massivecraft/factions/entity/Invitation.java index 1588214a..481dd444 100644 --- a/src/com/massivecraft/factions/entity/Invitation.java +++ b/src/com/massivecraft/factions/entity/Invitation.java @@ -23,11 +23,11 @@ public class Invitation extends EntityInternal 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 diff --git a/src/com/massivecraft/factions/entity/MConf.java b/src/com/massivecraft/factions/entity/MConf.java index 0f6a2909..3c6b1b3a 100644 --- a/src/com/massivecraft/factions/entity/MConf.java +++ b/src/com/massivecraft/factions/entity/MConf.java @@ -59,7 +59,7 @@ public class MConf extends Entity // VERSION // -------------------------------------------- // - public int version = 4; + public int version = 5; // -------------------------------------------- // // COMMAND ALIASES @@ -243,32 +243,34 @@ public class MConf extends Entity // 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 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; diff --git a/src/com/massivecraft/factions/entity/Warp.java b/src/com/massivecraft/factions/entity/Warp.java new file mode 100644 index 00000000..f70d9520 --- /dev/null +++ b/src/com/massivecraft/factions/entity/Warp.java @@ -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 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("%s:%s", this.getName(), this.getLocation().toString(PSFormatHumanSpace.get())); + } + + // -------------------------------------------- // + // VALID + // -------------------------------------------- // + + public boolean verifyIsValid() + { + if (this.isValid()) return true; + this.detach(); + this.getFaction().msg("Your faction warp %s 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()); + } +} diff --git a/src/com/massivecraft/factions/entity/migrator/MigratorFaction003Warps.java b/src/com/massivecraft/factions/entity/migrator/MigratorFaction003Warps.java new file mode 100644 index 00000000..d2417149 --- /dev/null +++ b/src/com/massivecraft/factions/entity/migrator/MigratorFaction003Warps.java @@ -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 warps = new MassiveMap<>(); + warps.put(MStore.createId(), warp); + + JsonElement jsonMap = MassiveCore.gson.toJsonTree(warps, (new TypeToken>(){}).getType()); + entity.add("warps", jsonMap); + } + +} diff --git a/src/com/massivecraft/factions/entity/migrator/MigratorMConf005Warps.java b/src/com/massivecraft/factions/entity/migrator/MigratorMConf005Warps.java new file mode 100644 index 00000000..5898dfb8 --- /dev/null +++ b/src/com/massivecraft/factions/entity/migrator/MigratorMConf005Warps.java @@ -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")); + } + +} diff --git a/src/com/massivecraft/factions/event/EventFactionsHomeChange.java b/src/com/massivecraft/factions/event/EventFactionsWarpAdd.java similarity index 68% rename from src/com/massivecraft/factions/event/EventFactionsHomeChange.java rename to src/com/massivecraft/factions/event/EventFactionsWarpAdd.java index a78ae6cf..e0d03a2e 100644 --- a/src/com/massivecraft/factions/event/EventFactionsHomeChange.java +++ b/src/com/massivecraft/factions/event/EventFactionsWarpAdd.java @@ -1,40 +1,40 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.massivecore.ps.PS; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -public class EventFactionsHomeChange extends EventFactionsAbstractSender -{ - // -------------------------------------------- // - // REQUIRED EVENT CODE - // -------------------------------------------- // - - private static final HandlerList handlers = new HandlerList(); - @Override public HandlerList getHandlers() { return handlers; } - public static HandlerList getHandlerList() { return handlers; } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final Faction faction; - public Faction getFaction() { return this.faction; } - - private PS newHome; - public PS getNewHome() { return this.newHome; } - public void setNewHome(PS newHome) { this.newHome = newHome; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsHomeChange(CommandSender sender, Faction faction, PS newHome) - { - super(sender); - this.faction = faction; - this.newHome = newHome; - } - -} +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.Warp; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +public class EventFactionsWarpAdd extends EventFactionsAbstractSender +{ + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + + private static final HandlerList handlers = new HandlerList(); + @Override public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final Faction faction; + public Faction getFaction() { return this.faction; } + + private Warp warp; + public Warp getNewWarp() { return this.warp; } + public void setNewWarp(Warp warp) { this.warp = warp; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsWarpAdd(CommandSender sender, Faction faction, Warp warp) + { + super(sender); + this.faction = faction; + this.warp = warp; + } + +} diff --git a/src/com/massivecraft/factions/event/EventFactionsWarpRemove.java b/src/com/massivecraft/factions/event/EventFactionsWarpRemove.java new file mode 100644 index 00000000..aa368832 --- /dev/null +++ b/src/com/massivecraft/factions/event/EventFactionsWarpRemove.java @@ -0,0 +1,40 @@ +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.Warp; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +public class EventFactionsWarpRemove extends EventFactionsAbstractSender +{ + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + + private static final HandlerList handlers = new HandlerList(); + @Override public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final Faction faction; + public Faction getFaction() { return this.faction; } + + private Warp warp; + public Warp getNewWarp() { return this.warp; } + public void setNewWarp(Warp warp) { this.warp = warp; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsWarpRemove(CommandSender sender, Faction faction, Warp warp) + { + super(sender); + this.faction = faction; + this.warp = warp; + } + +} diff --git a/src/com/massivecraft/factions/event/EventFactionsHomeTeleport.java b/src/com/massivecraft/factions/event/EventFactionsWarpTeleport.java similarity index 61% rename from src/com/massivecraft/factions/event/EventFactionsHomeTeleport.java rename to src/com/massivecraft/factions/event/EventFactionsWarpTeleport.java index e9264f2c..1672faef 100644 --- a/src/com/massivecraft/factions/event/EventFactionsHomeTeleport.java +++ b/src/com/massivecraft/factions/event/EventFactionsWarpTeleport.java @@ -1,25 +1,34 @@ -package com.massivecraft.factions.event; - -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -public class EventFactionsHomeTeleport extends EventFactionsAbstractSender -{ - // -------------------------------------------- // - // REQUIRED EVENT CODE - // -------------------------------------------- // - - private static final HandlerList handlers = new HandlerList(); - @Override public HandlerList getHandlers() { return handlers; } - public static HandlerList getHandlerList() { return handlers; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsHomeTeleport(CommandSender sender) - { - super(sender); - } - -} +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.Warp; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +public class EventFactionsWarpTeleport extends EventFactionsAbstractSender +{ + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + + private static final HandlerList handlers = new HandlerList(); + @Override public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final Warp warp; + public Warp getWarp() { return this.warp; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsWarpTeleport(CommandSender sender, Warp warp) + { + super(sender); + this.warp = warp; + } + +} diff --git a/src/com/massivecraft/factions/integration/venturechat/EngineVentureChat.java b/src/com/massivecraft/factions/integration/venturechat/EngineVentureChat.java index 1d3f139c..43bc47cb 100644 --- a/src/com/massivecraft/factions/integration/venturechat/EngineVentureChat.java +++ b/src/com/massivecraft/factions/integration/venturechat/EngineVentureChat.java @@ -5,7 +5,6 @@ import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.massivecore.Engine; -import kangarko.chatcontrol.ChatControl; import mineverse.Aust1n46.chat.api.MineverseChatAPI; import mineverse.Aust1n46.chat.api.MineverseChatPlayer; import mineverse.Aust1n46.chat.channel.ChatChannel; @@ -68,7 +67,6 @@ public class EngineVentureChat extends Engine Predicate predicate = isSpy.or(predicateChannel); EngineChat.filterToPredicate(event, predicate); - ChatControl } }