diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index b41aefd4..a3eec8cf 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -1,28 +1,36 @@ ## Affected Plugin + + - **Affected Plugin Name:** Factions - **Affected Plugin Version:** ??? ## Describe your Environment + + - **Server Version:** ??? ## Steps to Reproduce this Bug + + 1. First I did this. 2. Next I did that. 3. Finally this happened. ## Observed Results + ## Expected Results + diff --git a/plugin.yml b/plugin.yml deleted file mode 100644 index 93553fb1..00000000 --- a/plugin.yml +++ /dev/null @@ -1,461 +0,0 @@ -main: ${project.groupId}.${project.name} -name: ${project.name} -version: ${project.version} -website: ${project.url} -description: ${project.description} -authors: [Madus, Cayorion, Ulumulu1510, MarkehMe, Brettflan] -depend: [MassiveCore] -softdepend: [PermissionsEx, Permissions, Essentials, EssentialsChat, HeroChat, LocalAreaChat, LWC, ChatManager, AuthMe, Vault, WorldEdit, WorldGuard] -api-version: 1.13 -permissions: - # -------------------------------------------- # - # THE REAL NODES - # -------------------------------------------- # - factions.access: {description: manage access, with the proper fperm, default: false} - factions.access.deny: {description: deny faction access, default: false} - factions.access.deny.one: {description: deny access in a single chunk, default: false} - factions.access.deny.fill: {description: deny access by filling, default: false} - factions.access.deny.square: {description: deny access by square and radius, default: false} - factions.access.deny.circle: {description: deny access by circle and radius, default: false} - factions.access.grant: {description: grant faction access, default: false} - factions.access.grant.one: {description: grant access in a single chunk, default: false} - factions.access.grant.fill: {description: grant access by filling, default: false} - factions.access.grant.square: {description: grant access by square and radius, default: false} - factions.access.grant.circle: {description: grant access by circle and radius, default: false} - factions.access.inspect: {description: inspect where someone has access, default: false} - factions.access.view: {description: view access, default: false} - factions.override: {description: enable override mode, default: false} - factions.basecommand: {description: use factions base command, default: false} - factions.chunkname: {description: set chunk name, default: false} - factions.claim: {description: claim faction territory, default: false} - factions.claim.one: {description: claim a single chunk, default: false} - factions.claim.auto: {description: claim as you walk around, default: false} - factions.claim.fill: {description: claim by filling, default: false} - factions.claim.square: {description: claim by square and radius, default: false} - factions.claim.circle: {description: claim by circle and radius, default: false} - factions.claim.all: {description: claim all faction land, default: false} - factions.create: {description: create new faction, default: false} - factions.description: {description: change faction description, default: false} - factions.disband: {description: disband faction, default: false} - factions.documentation: {description: show documentation, default: false} - factions.documentation.flags: {description: show flag documentation, default: false} - factions.documentation.power: {description: show power documentation, default: false} - factions.documentation.perms: {description: show perms documentation, default: false} - factions.documentation.ranks: {description: show rank documentation, default: false} - factions.documentation.tax: {description: show tax documentation, default: false} - factions.documentation.warps: {description: show warp documentation, default: false} - factions.expansions: {description: list expansions, default: false} - factions.faction: {description: show faction information, default: false} - factions.flag: {description: manage faction flags, default: false} - 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.fly: {description: faction fly, default: false} - factions.fly.other: {description: set faction fly for others, 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} - factions.invite.add: {description: invite player, default: false} - factions.invite.remove: {description: revoke an invite, default: false} - factions.join: {description: join faction, default: false} - factions.join.others: {description: have another player join faction, default: false} - factions.kick: {description: kick player from faction, default: false} - factions.leave: {description: leave your faction, default: false} - factions.list: {description: list all factions, default: false} - factions.map: {description: show territory map, default: false} - factions.money: {description: manage faction money, default: false} - factions.money.balance: {description: show faction money, default: false} - factions.money.balance.any: {description: show another factions money, default: false} - factions.money.deposit: {description: deposit to faction, default: false} - factions.money.f2f: {description: transfer f --> f, default: false} - factions.money.f2p: {description: transfer f --> p, default: false} - factions.money.p2f: {description: transfer p --> f, default: false} - factions.money.withdraw: {description: withdraw from faction, default: false} - factions.moneyconvert: {description: convert to the new money system, default: false} - factions.motd: {description: faction motd, default: false} - factions.open: {description: set if invitation is required to join, default: false} - factions.perm: {description: change faction permissions, default: false} - factions.perm.list: {description: list perms, default: false} - factions.perm.set: {description: set perms, default: false} - factions.perm.show: {description: show who has perm, default: false} - factions.perm.view: {description: view perms given to, default: false} - factions.perm.viewall: {description: view all perms held by, default: false} - factions.player: {description: show player information} - factions.powerboost: {description: manage powerboost, default: false} - factions.powerboost.faction: {description: manage faction powerboost, default: false} - factions.powerboost.faction.add: {description: add to faction powerboost, default: false} - factions.powerboost.faction.multiply: {description: multiply faction powerboost, default: false} - factions.powerboost.faction.set: {description: set faction powerboost, default: false} - factions.powerboost.faction.show: {description: show faction powerboost, default: false} - factions.powerboost.faction.take: {description: take faction powerboost, default: false} - factions.powerboost.player: {description: manage player powerboost, default: false} - factions.powerboost.player.add: {description: add to player powerboost, default: false} - factions.powerboost.player.multiply: {description: multiply player powerboost, default: false} - factions.powerboost.player.set: {description: set player powerboost, default: false} - factions.powerboost.player.show: {description: show player powerboost, default: false} - factions.powerboost.player.take: {description: take player powerboost, default: false} - factions.rank: {description: manage/show ranks, default: false} - factions.rank.show: {description: show rank, default: false} - factions.rank.set: {description: set rank, default: false} - factions.rank.list: {description: list ranks, default: false} - factions.rank.edit: {description: edit ranks, default: false} - factions.rank.edit.create: {description: create rank, default: false} - factions.rank.edit.name: {description: set rank name, default: false} - factions.rank.edit.prefix: {description: set rank prefix, default: false} - factions.rank.edit.priority: {description: set rank priority, default: false} - factions.rank.edit.delete: {description: delete rank, default: false} - factions.relation: {description: manage faction relations, default: false} - factions.relation.list: {description: list all factions with certain relation, default: false} - factions.relation.set: {description: set relation wish to another faction, default: false} - 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.setpower: {description: set power, default: false} - factions.status: {description: show status, default: false} - factions.tax: {description: manage taxes, default: false} - factions.tax.faction: {description: show faction tax, default: false} - factions.tax.player: {description: show player tax, default: false} - factions.tax.run: {description: run a tax collection, default: false} - factions.tax.set: {description: set taxes, default: false} - factions.name: {description: set faction name, default: false} - factions.title: {description: set player title, default: false} - factions.title.color: {description: set player title with color, default: false} - factions.territorytitles: {description: toggle territory titles, default: false} - factions.top: {description: show faction top, default: false} - factions.unclaim: {description: unclaim faction territory, default: false} - factions.unclaim.one: {description: unclaim a single chunk, default: false} - factions.unclaim.auto: {description: unclaim as you walk around, default: false} - factions.unclaim.fill: {description: unclaim by filling, default: false} - 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.vote: {description: vote in faction votes, default: false} - factions.vote.do: {description: do vote, default: false} - factions.vote.list: {description: list votes, default: false} - factions.vote.show: {description: show vote result, default: false} - factions.vote.create: {description: create a vote, default: false} - factions.vote.remove: {description: remove a vote, 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} - factions.version: {description: see plugin version, default: false} -# -------------------------------------------- # -# STAR NOTATION -# -------------------------------------------- # - factions.*: - children: - factions.access: true - factions.access.deny: true - factions.access.deny.one: true - factions.access.deny.fill: true - factions.access.deny.square: true - factions.access.deny.circle: true - factions.access.grant: true - factions.access.grant.one: true - factions.access.grant.fill: true - factions.access.grant.square: true - factions.access.grant.circle: true - factions.access.inspect: true - factions.access.view: true - factions.override: true - factions.basecommand: true - factions.chunkname: true - factions.claim: true - factions.claim.one: true - factions.claim.auto: true - factions.claim.fill: true - factions.claim.square: true - factions.claim.circle: true - factions.claim.all: true - factions.create: true - factions.demote: true - factions.description: true - factions.disband: true - factions.documentation: true - factions.documentation.flags: true - factions.documentation.perms: true - factions.documentation.power: true - factions.documentation.ranks: true - factions.documentation.tax: true - factions.documentation.warps: true - factions.expansions: true - factions.faction: true - factions.flag: true - factions.flag.list: true - factions.flag.set: true - factions.flag.show: true - factions.fly: true - factions.fly.other: true - factions.home: true - factions.invite: true - factions.invite.list: true - factions.invite.list.other: true - factions.invite.add: true - factions.invite.remove: true - factions.join: true - factions.join.others: true - factions.kick: true - factions.leader: true - factions.leader.any: true - factions.leave: true - factions.list: true - factions.map: true - factions.money: true - factions.money.balance: true - factions.money.balance.any: true - factions.money.deposit: true - factions.money.f2f: true - factions.money.f2p: true - factions.money.p2f: true - factions.money.withdraw: true - factions.moneyconvert: true - factions.motd: true - factions.officer: true - factions.officer.any: true - factions.open: true - factions.perm: true - factions.perm.list: true - factions.perm.set: true - factions.perm.show: true - factions.perm.view: true - factions.perm.viewall: true - factions.player: true - factions.powerboost: true - factions.powerboost.faction: true - factions.powerboost.faction.add: true - factions.powerboost.faction.multiply: true - factions.powerboost.faction.set: true - factions.powerboost.faction.show: true - factions.powerboost.faction.take: true - factions.powerboost.player: true - factions.powerboost.player.add: true - factions.powerboost.player.multiply: true - factions.powerboost.player.set: true - factions.powerboost.player.show: true - factions.powerboost.player.take: true - factions.rank: true - factions.rank.show: true - factions.rank.set: true - factions.rank.list: true - factions.rank.edit: true - factions.rank.edit.create: true - factions.rank.edit.name: true - factions.rank.edit.prefix: true - factions.rank.edit.priority: true - factions.rank.edit.delete: true - factions.promote: true - factions.relation: true - factions.relation.list: true - factions.relation.set: true - factions.relation.wishes: true - factions.seechunk: true - factions.seechunkold: true - factions.sethome: true - factions.setpower: true - factions.status: true - factions.tax: true - factions.tax.faction: true - factions.tax.player: true - factions.tax.run: true - factions.tax.set: true - factions.name: true - factions.title: true - factions.title.color: true - factions.territorytitles: true - factions.top: true - factions.unclaim: true - factions.unclaim.one: true - factions.unclaim.auto: true - factions.unclaim.fill: true - factions.unclaim.square: true - factions.unclaim.circle: true - factions.unclaim.all: true - factions.unsethome: true - factions.unstuck: true - factions.vote: true - factions.vote.do: true - factions.vote.list: true - factions.vote.show: true - factions.vote.create: true - factions.vote.remove: 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 -# -------------------------------------------- # -# KITS -# -------------------------------------------- # - factions.kit.op: - default: op - children: - factions.*: true - factions.kit.rank3: - default: false - children: - factions.kit.rank2: true - factions.moneyconvert: true - factions.config: true - factions.clean: true - factions.kit.rank2: - default: false - children: - factions.kit.rank1: true - factions.powerboost.faction.add: true - factions.powerboost.faction.multiply: true - factions.powerboost.faction.set: true - factions.powerboost.faction.take: true - factions.powerboost.player.add: true - factions.powerboost.player.multiply: true - factions.powerboost.player.set: true - factions.powerboost.player.take: true - factions.join.others: true - factions.leader.any: true - factions.officer.any: true - factions.access.any: true - factions.fly.other: true - factions.setpower: true - factions.kit.rank1: - default: false - children: - factions.kit.rank0: true - factions.override: true - factions.invite.list.other: true - factions.kit.rank0: - default: false - children: - factions.access: true - factions.access.deny: true - factions.access.deny.one: true - factions.access.deny.fill: true - factions.access.deny.square: true - factions.access.deny.circle: true - factions.access.grant: true - factions.access.grant.one: true - factions.access.grant.fill: true - factions.access.grant.square: true - factions.access.grant.circle: true - factions.access.inspect: true - factions.access.view: true - factions.basecommand: true - factions.chunkname: true - factions.claim: true - factions.claim.one: true - factions.claim.auto: true - factions.claim.fill: true - factions.claim.square: true - factions.claim.circle: true - factions.claim.all: true - factions.create: true - factions.demote: true - factions.description: true - factions.disband: true - factions.documentation: true - factions.documentation.flags: true - factions.documentation.perms: true - factions.documentation.power: true - factions.documentation.ranks: true - factions.documentation.warps: true - factions.expansions: true - factions.faction: true - factions.flag: true - factions.flag.list: true - factions.flag.set: true - factions.flag.show: true - factions.fly: true - factions.home: true - factions.invite: true - factions.invite.list: true - factions.invite.add: true - factions.invite.remove: true - factions.join: true - factions.kick: true - factions.leader: true - factions.leave: true - factions.list: true - factions.map: true - factions.money: true - factions.money.balance: true - factions.money.balance.any: true - factions.money.deposit: true - factions.money.f2f: true - factions.money.f2p: true - factions.money.p2f: true - factions.money.withdraw: true - factions.motd: true - factions.officer: true - factions.open: true - factions.perm: true - factions.perm.list: true - factions.perm.set: true - factions.perm.show: true - factions.perm.view: true - factions.perm.viewall: true - factions.player: true - factions.promote: true - factions.powerboost: true - factions.powerboost.faction: true - factions.powerboost.faction.show: true - factions.powerboost.player: true - factions.powerboost.player.show: true - factions.rank: true - factions.rank.show: true - factions.rank.set: true - factions.rank.list: true - factions.rank.edit: true - factions.rank.edit.create: true - factions.rank.edit.name: true - factions.rank.edit.prefix: true - factions.rank.edit.priority: true - factions.rank.edit.delete: true - factions.relation: true - factions.relation.list: true - factions.relation.set: true - factions.relation.wishes: true - factions.seechunk: true - factions.seechunkold: true - factions.sethome: true - factions.status: true - factions.tax: true - factions.tax.faction: true - factions.tax.player: true - factions.tax.run: true - factions.tax.set: true - factions.name: true - factions.title: true - factions.title.color: true - factions.territorytitles: true - factions.top: true - factions.unclaim: true - factions.unclaim.one: true - factions.unclaim.auto: true - factions.unclaim.fill: true - factions.unclaim.square: true - factions.unclaim.circle: true - factions.unclaim.all: true - factions.unsethome: true - factions.unstuck: true - factions.vote: true - factions.vote.do: true - factions.vote.list: true - factions.vote.show: true - factions.vote.create: true - factions.vote.remove: 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 - children: - factions.kit.rank0: true diff --git a/pom.xml b/pom.xml index e8dcfe6e..53c38a3b 100644 --- a/pom.xml +++ b/pom.xml @@ -1,23 +1,57 @@ - + 4.0.0 - + - com.massivecraft.factions + net.knarcraft Factions jar + https://git.knarcraft.net ${project.artifactId} - ${massiveColorInfo}${project.name} allows the players to team up and claim land as their own and start wars with other factions. This way we hope to inspire politics, intrigue, and team spirit. ${massiveDescriptionSuffix} - ${massiveBaseUrl}/factions + ${project.name} allows the players to team up and claim land as their own and start wars with other + factions. This way we hope to inspire politics, intrigue, and team spirit. + + + 3.3.3 + + + UTF-8 + 17 + 17 + + + + + spigotmc-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + vault-repo + http://nexus.hc.to/content/repositories/pub_releases + + + engine-hub-repo + https://maven.enginehub.org/repo/ + + + dynmap + https://repo.mikeprimm.com/ + + + placeholderapi + https://repo.extendedclip.com/content/repositories/placeholderapi/ + + @@ -25,75 +59,98 @@ org.spigotmc spigot-api + 1.19.1-R0.1-SNAPSHOT com.massivecraft.massivecore MassiveCore + RELEASE + system + lib\MassiveCore.jar com.sk89q.worldedit worldedit-core + 7.2.7 com.sk89q.worldedit worldedit-bukkit + 7.2.7 com.sk89q.worldguard worldguard-core + RELEASE com.sk89q.worldguard worldguard-bukkit + RELEASE net.milkbowl.vault - Vault + VaultAPI + 1.7 com.griefcraft lwc + RELEASE + system + lib\LWC.jar - me.clip - placeholderapi + me.clip + placeholderapi + 2.11.2 + provided - mineverse.Aust1n46.chat - MineverseChat + mineverse.Aust1n46.chat + VentureChat + RELEASE + system + lib\VentureChat.jar - us.dynmap - dynmap + us.dynmap + dynmap-api + 3.1-beta-2 - + clean package install - - ${project.basedir} true + ${basedir}/src/main/resources *.yml - - - ${project.build.sourceDirectory} - false - + + + org.apache.maven.plugins + maven-compiler-plugin + 3.7.0 + + 17 + 17 + + + diff --git a/src/com/massivecraft/factions/AccessStatus.java b/src/com/massivecraft/factions/AccessStatus.java deleted file mode 100644 index 1870dece..00000000 --- a/src/com/massivecraft/factions/AccessStatus.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.massivecraft.factions; - - -import com.massivecraft.massivecore.Colorized; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.ChatColor; - -public enum AccessStatus implements Colorized -{ - // -------------------------------------------- // - // ENUM - // -------------------------------------------- // - - STANDARD(ChatColor.YELLOW, null), - ELEVATED(ChatColor.GREEN, true), - DECREASED(ChatColor.RED, false), - - // END OF LIST - ; - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final ChatColor color; - @Override public ChatColor getColor() { return this.color; } - - private final Boolean access; - public Boolean hasAccess() { return access; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - AccessStatus(ChatColor color, Boolean access) - { - this.color = color; - this.access = access; - } - - // -------------------------------------------- // - // MESSAGE - // -------------------------------------------- // - - public String getStatusMessage() - { - ChatColor color = this.getColor(); - String status = Txt.getNicedEnum(this).toLowerCase(); - return Txt.parse("%sYou have %s access to this area.", color.toString(), status); - } - -} diff --git a/src/com/massivecraft/factions/ExtractorFactionAccountId.java b/src/com/massivecraft/factions/ExtractorFactionAccountId.java deleted file mode 100644 index a9cbaac1..00000000 --- a/src/com/massivecraft/factions/ExtractorFactionAccountId.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.massivecraft.factions; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.massivecore.util.extractor.Extractor; - -public class ExtractorFactionAccountId implements Extractor -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static ExtractorFactionAccountId i = new ExtractorFactionAccountId(); - public static ExtractorFactionAccountId get() { return i; } - - // -------------------------------------------- // - // OVERRIDE: EXTRACTOR - // -------------------------------------------- // - - @Override - public Object extract(Object o) - { - if (o instanceof Faction) - { - String factionId = ((Faction)o).getId(); - if (factionId == null) return null; - return Factions.FACTION_MONEY_ACCOUNT_ID_PREFIX + factionId; - } - - return null; - } - -} diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java deleted file mode 100644 index 2d8b965b..00000000 --- a/src/com/massivecraft/factions/Factions.java +++ /dev/null @@ -1,291 +0,0 @@ -package com.massivecraft.factions; - -import com.google.gson.GsonBuilder; -import com.massivecraft.factions.adapter.BoardAdapter; -import com.massivecraft.factions.adapter.BoardMapAdapter; -import com.massivecraft.factions.adapter.TerritoryAccessAdapter; -import com.massivecraft.factions.chat.modifier.ChatModifierLc; -import com.massivecraft.factions.chat.modifier.ChatModifierLp; -import com.massivecraft.factions.chat.modifier.ChatModifierParse; -import com.massivecraft.factions.chat.modifier.ChatModifierRp; -import com.massivecraft.factions.chat.modifier.ChatModifierUc; -import com.massivecraft.factions.chat.modifier.ChatModifierUcf; -import com.massivecraft.factions.chat.tag.ChatTagName; -import com.massivecraft.factions.chat.tag.ChatTagNameforce; -import com.massivecraft.factions.chat.tag.ChatTagRelcolor; -import com.massivecraft.factions.chat.tag.ChatTagRole; -import com.massivecraft.factions.chat.tag.ChatTagRoleprefix; -import com.massivecraft.factions.chat.tag.ChatTagRoleprefixforce; -import com.massivecraft.factions.chat.tag.ChatTagTitle; -import com.massivecraft.factions.cmd.CmdFactions; -import com.massivecraft.factions.cmd.type.TypeFactionChunkChangeType; -import com.massivecraft.factions.cmd.type.TypeRel; -import com.massivecraft.factions.engine.EngineCanCombatHappen; -import com.massivecraft.factions.engine.EngineChat; -import com.massivecraft.factions.engine.EngineChunkChange; -import com.massivecraft.factions.engine.EngineCleanInactivity; -import com.massivecraft.factions.engine.EngineDenyCommands; -import com.massivecraft.factions.engine.EngineDenyTeleport; -import com.massivecraft.factions.engine.EngineEcon; -import com.massivecraft.factions.engine.EngineExploit; -import com.massivecraft.factions.engine.EngineFlagEndergrief; -import com.massivecraft.factions.engine.EngineFlagExplosion; -import com.massivecraft.factions.engine.EngineFlagFireSpread; -import com.massivecraft.factions.engine.EngineFlagSpawn; -import com.massivecraft.factions.engine.EngineFlagZombiegrief; -import com.massivecraft.factions.engine.EngineFly; -import com.massivecraft.factions.engine.EngineLastActivity; -import com.massivecraft.factions.engine.EngineMotd; -import com.massivecraft.factions.engine.EngineMoveChunk; -import com.massivecraft.factions.engine.EnginePermBuild; -import com.massivecraft.factions.engine.EnginePlayerData; -import com.massivecraft.factions.engine.EnginePower; -import com.massivecraft.factions.engine.EngineSeeChunk; -import com.massivecraft.factions.engine.EngineShow; -import com.massivecraft.factions.engine.EngineTeleportHomeOnDeath; -import com.massivecraft.factions.engine.EngineTerritoryShield; -import com.massivecraft.factions.engine.EngineVisualizations; -import com.massivecraft.factions.entity.Board; -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.FactionColl; -import com.massivecraft.factions.entity.MConfColl; -import com.massivecraft.factions.entity.MFlagColl; -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.MigratorFaction004WarpsPerms; -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.MigratorMPerm001Warps; -import com.massivecraft.factions.entity.migrator.MigratorMPerm002MoveStandard; -import com.massivecraft.factions.entity.migrator.MigratorMPlayer001Ranks; -import com.massivecraft.factions.entity.migrator.MigratorMPlayer002UsingAdminMode; -import com.massivecraft.factions.entity.migrator.MigratorTerritoryAccess001Restructure; -import com.massivecraft.factions.event.EventFactionsChunkChangeType; -import com.massivecraft.factions.integration.dynmap.IntegrationDynmap; -import com.massivecraft.factions.integration.lwc.IntegrationLwc; -import com.massivecraft.factions.integration.placeholderapi.IntegrationPlaceholderAPI; -import com.massivecraft.factions.integration.venturechat.IntegrationVentureChat; -import com.massivecraft.factions.integration.worldguard.IntegrationWorldGuard; -import com.massivecraft.factions.mixin.PowerMixin; -import com.massivecraft.factions.task.TaskFlagPermCreate; -import com.massivecraft.factions.task.TaskPlayerPowerUpdate; -import com.massivecraft.factions.task.TaskTax; -import com.massivecraft.massivecore.MassivePlugin; -import com.massivecraft.massivecore.command.type.RegistryType; -import com.massivecraft.massivecore.store.migrator.MigratorUtil; -import com.massivecraft.massivecore.util.MUtil; -import org.bukkit.ChatColor; - -import java.util.List; - -public class Factions extends MassivePlugin -{ - // -------------------------------------------- // - // CONSTANTS - // -------------------------------------------- // - - public final static String FACTION_MONEY_ACCOUNT_ID_PREFIX = "faction-"; - - public final static String ID_NONE = "none"; - public final static String ID_SAFEZONE = "safezone"; - public final static String ID_WARZONE = "warzone"; - - public final static String NAME_NONE_DEFAULT = ChatColor.DARK_GREEN.toString() + "Wilderness"; - public final static String NAME_SAFEZONE_DEFAULT = "SafeZone"; - public final static String NAME_WARZONE_DEFAULT = "WarZone"; - - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static Factions i; - public static Factions get() { return i; } - public Factions() { Factions.i = this; } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - // Mixins - @Deprecated public PowerMixin getPowerMixin() { return PowerMixin.get(); } - @Deprecated public void setPowerMixin(PowerMixin powerMixin) { PowerMixin.get().setInstance(powerMixin); } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void onEnableInner() - { - // Register types - RegistryType.register(Rel.class, TypeRel.get()); - RegistryType.register(EventFactionsChunkChangeType.class, TypeFactionChunkChangeType.get()); - - // Register Faction accountId Extractor - // TODO: Perhaps this should be placed in the econ integration somewhere? - MUtil.registerExtractor(String.class, "accountId", ExtractorFactionAccountId.get()); - - MigratorUtil.addJsonRepresentation(Board.class, Board.MAP_TYPE); - MigratorUtil.setTargetVersion(TerritoryAccess.class, 1); - - // Activate - this.activateAuto(); - this.activate(getClassesActiveChat()); - - } - - // These are overriden because the reflection trick was buggy and didn't work on all systems - @Override - public List> getClassesActiveMigrators() - { - return MUtil.list( - MigratorFaction001Invitations.class, - MigratorFaction002Ranks.class, - MigratorFaction003Warps.class, - MigratorFaction004WarpsPerms.class, - MigratorMConf001EnumerationUtil.class, - MigratorMConf002CleanInactivity.class, - MigratorMConf003CleanInactivity.class, - MigratorMConf004Rank.class, - MigratorMConf005Warps.class, - MigratorMPerm001Warps.class, - MigratorMPerm002MoveStandard.class, - MigratorMPlayer001Ranks.class, - MigratorMPlayer002UsingAdminMode.class, - MigratorTerritoryAccess001Restructure.class - ); - } - - @Override - public List> getClassesActiveColls() - { - // MConf should always be activated first for all plugins. It's simply a standard. The config should have no dependencies. - // MFlag and MPerm are both dependency free. - // Next we activate Faction, MPlayer and Board. The order is carefully chosen based on foreign keys and indexing direction. - // MPlayer --> Faction - // We actually only have an index that we maintain for the MPlayer --> Faction one. - // The Board could currently be activated in any order but the current placement is an educated guess. - // In the future we might want to find all chunks from the faction or something similar. - // We also have the /f access system where the player can be granted specific access, possibly supporting the idea of such a reverse index. - return MUtil.list( - MConfColl.class, - MFlagColl.class, - MPermColl.class, - FactionColl.class, - MPlayerColl.class, - BoardColl.class - ); - } - - @Override - public List> getClassesActiveCommands() - { - return MUtil.list( - CmdFactions.class - ); - } - - @Override - public List> getClassesActiveIntegrations() - { - return MUtil.list( - IntegrationPlaceholderAPI.class, - IntegrationVentureChat.class, - IntegrationLwc.class, - IntegrationWorldGuard.class, - IntegrationDynmap.class - ); - } - - @Override - public List> getClassesActiveTasks() - { - return MUtil.list( - TaskTax.class, - TaskFlagPermCreate.class, - TaskPlayerPowerUpdate.class - ); - } - - @Override - public List> getClassesActiveEngines() - { - return MUtil.list( - EngineCanCombatHappen.class, - EngineChat.class, - EngineChunkChange.class, - EngineCleanInactivity.class, - EngineDenyCommands.class, - EngineDenyTeleport.class, - EngineExploit.class, - EngineFlagEndergrief.class, - EngineFlagExplosion.class, - EngineFlagFireSpread.class, - EngineFlagSpawn.class, - EngineFlagZombiegrief.class, - EngineFly.class, - EngineLastActivity.class, - EngineMotd.class, - EngineMoveChunk.class, - EnginePermBuild.class, - EnginePlayerData.class, - EnginePower.class, - EngineSeeChunk.class, - EngineShow.class, - EngineTeleportHomeOnDeath.class, - EngineTerritoryShield.class, - EngineVisualizations.class, - EngineEcon.class - ); - } - - @Override - public List> getClassesActiveMixins() - { - return MUtil.list( - PowerMixin.class - ); - } - - @Override - public List> getClassesActiveTests() - { - return MUtil.list(); - } - - public List> getClassesActiveChat() - { - return MUtil.list( - ChatModifierLc.class, - ChatModifierLp.class, - ChatModifierParse.class, - ChatModifierRp.class, - ChatModifierUc.class, - ChatModifierUcf.class, - ChatTagName.class, - ChatTagNameforce.class, - ChatTagRelcolor.class, - ChatTagRole.class, - ChatTagRoleprefix.class, - ChatTagRoleprefixforce.class, - ChatTagTitle.class - ); - } - - @Override - public GsonBuilder getGsonBuilder() - { - return super.getGsonBuilder() - .registerTypeAdapter(TerritoryAccess.class, TerritoryAccessAdapter.get()) - .registerTypeAdapter(Board.class, BoardAdapter.get()) - .registerTypeAdapter(Board.MAP_TYPE, BoardMapAdapter.get()) - ; - } - -} diff --git a/src/com/massivecraft/factions/FactionsIndex.java b/src/com/massivecraft/factions/FactionsIndex.java deleted file mode 100644 index 0b98cd18..00000000 --- a/src/com/massivecraft/factions/FactionsIndex.java +++ /dev/null @@ -1,168 +0,0 @@ -package com.massivecraft.factions; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.FactionColl; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.entity.MPlayerColl; -import com.massivecraft.massivecore.collections.MassiveSet; - -import java.util.Collections; -import java.util.Map; -import java.util.Set; -import java.util.WeakHashMap; - -/** - * This Index class contains the MPlayer <--> Faction index. - * - * In the background it's powered by WeakHashMaps and all public methods are synchronized. - * That should increase thread safety but no thread safety is actually guarranteed. - * That is because the mplayer.getFaction() method is not threadsafe. - * TODO: Something to fix in the future perhaps? - */ -public class FactionsIndex -{ - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static FactionsIndex i = new FactionsIndex(); - public static FactionsIndex get() { return i; } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final Map mplayer2faction; - private final Map> faction2mplayers; - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - private FactionsIndex() - { - this.mplayer2faction = new WeakHashMap<>(); - this.faction2mplayers = new WeakHashMapCreativeImpl(); - } - - // -------------------------------------------- // - // IS CONNECTED - // -------------------------------------------- // - - private boolean isConnected(MPlayer mplayer, Faction faction) - { - if (mplayer == null) throw new NullPointerException("mplayer"); - if (faction == null) throw new NullPointerException("faction"); - - return mplayer.getFaction() == faction; - } - - // -------------------------------------------- // - // GET - // -------------------------------------------- // - - public synchronized Faction getFaction(MPlayer mplayer) - { - return this.mplayer2faction.get(mplayer); - } - - public synchronized Set getMPlayers(Faction faction) - { - return new MassiveSet<>(this.faction2mplayers.get(faction)); - } - - // -------------------------------------------- // - // UPDATE - // -------------------------------------------- // - - public synchronized void updateAll() - { - if (!MPlayerColl.get().isActive()) throw new IllegalStateException("The MPlayerColl is not yet fully activated."); - - MPlayerColl.get().getAll().forEach(this::update); - } - - public synchronized void update(MPlayer mplayer) - { - if (mplayer == null) throw new NullPointerException("mplayer"); - if (!FactionColl.get().isActive()) throw new IllegalStateException("The FactionColl is not yet fully activated."); - - // TODO: This is not optimal but here we remove a player from the index when - // the mplayer object is deattached. Optimally it should be removed - // automatically because it is stored as a weak reference. - // But sometimes that doesn't happen so we do this instead. - // Is there a memory leak somewhere? - if (!mplayer.attached()) - { - Faction factionIndexed = this.mplayer2faction.remove(mplayer); - if (factionIndexed != null) - { - faction2mplayers.get(factionIndexed).remove(mplayer); - } - return; - } - - Faction factionActual = mplayer.getFaction(); - Faction factionIndexed = this.getFaction(mplayer); - - Set factions = new MassiveSet<>(); - if (factionActual != null) factions.add(factionActual); - if (factionIndexed != null) factions.add(factionIndexed); - - for (Faction faction : factions) - { - boolean connected = this.isConnected(mplayer, faction); - if (connected) - { - this.faction2mplayers.get(faction).add(mplayer); - } - else - { - this.faction2mplayers.get(faction).remove(mplayer); - } - } - - this.mplayer2faction.put(mplayer, factionActual); - } - - public synchronized void update(Faction faction) - { - if (faction == null) throw new NullPointerException("faction"); - - this.getMPlayers(faction).forEach(this::update); - } - - // -------------------------------------------- // - // MAP - // -------------------------------------------- // - - private static abstract class WeakHashMapCreative extends java.util.WeakHashMap - { - @SuppressWarnings("unchecked") - @Override - public V get(Object key) - { - V ret = super.get(key); - - if (ret == null) - { - ret = this.createValue(); - this.put((K)key, ret); - } - - return ret; - } - - public abstract V createValue(); - } - - private static class WeakHashMapCreativeImpl extends WeakHashMapCreative> - { - @Override - public Set createValue() - { - return Collections.newSetFromMap(new WeakHashMap<>()); - } - } - -} diff --git a/src/com/massivecraft/factions/Perm.java b/src/com/massivecraft/factions/Perm.java deleted file mode 100644 index 73b1c44a..00000000 --- a/src/com/massivecraft/factions/Perm.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.massivecraft.factions; - -import com.massivecraft.massivecore.Identified; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.util.PermissionUtil; -import org.bukkit.permissions.Permissible; - -public enum Perm implements Identified -{ - // -------------------------------------------- // - // ENUM - // -------------------------------------------- // - - // All of these are referenced in the code - ACCESS_GRANT_ONE, - ACCESS_GRANT_FILL, - ACCESS_GRANT_SQUARE, - ACCESS_GRANT_CIRCLE, - ACCESS_DENY_ONE, - ACCESS_DENY_FILL, - ACCESS_DENY_SQUARE, - ACCESS_DENY_CIRCLE, - CLAIM_ONE, - CLAIM_AUTO, - CLAIM_FILL, - CLAIM_SQUARE, - CLAIM_CIRCLE, - CLAIM_ALL, - UNCLAIM_ONE, - UNCLAIM_AUTO, - UNCLAIM_FILL, - UNCLAIM_SQUARE, - UNCLAIM_CIRCLE, - UNCLAIM_ALL, - OVERRIDE, - FLY, - JOIN_OTHERS, - INVITE_LIST_OTHER, - TITLE_COLOR, - POWERBOOST_SET, - MONEY_BALANCE_ANY, - SETPOWER, - CONFIG, - VERSION, - - // These are just here to tell the system that it is seechunk rather than see.chunk - SEECHUNK, - SEECHUNKOLD, - - // END OF LIST - ; - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final String id; - @Override public String getId() { return this.id; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - Perm() - { - this.id = PermissionUtil.createPermissionId(Factions.get(), this); - } - - // -------------------------------------------- // - // HAS - // -------------------------------------------- // - - public boolean has(Permissible permissible, boolean verboose) - { - return PermissionUtil.hasPermission(permissible, this, verboose); - } - - public boolean has(Permissible permissible) - { - return PermissionUtil.hasPermission(permissible, this); - } - - public void hasOrThrow(Permissible permissible) throws MassiveException - { - PermissionUtil.hasPermissionOrThrow(permissible, this); - } - -} diff --git a/src/com/massivecraft/factions/PowerBoosted.java b/src/com/massivecraft/factions/PowerBoosted.java deleted file mode 100644 index 84ccebfe..00000000 --- a/src/com/massivecraft/factions/PowerBoosted.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.massivecraft.factions; - -public interface PowerBoosted -{ - double getPowerBoost(); - void setPowerBoost(Double powerBoost); -} diff --git a/src/com/massivecraft/factions/Rel.java b/src/com/massivecraft/factions/Rel.java deleted file mode 100644 index 0b87e9ea..00000000 --- a/src/com/massivecraft/factions/Rel.java +++ /dev/null @@ -1,140 +0,0 @@ -package com.massivecraft.factions; - -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.massivecore.Colorized; -import com.massivecraft.massivecore.Named; -import com.massivecraft.massivecore.collections.MassiveSet; -import org.bukkit.ChatColor; - -import java.util.Collections; -import java.util.Set; - -public enum Rel implements Colorized, Named, MPerm.MPermable -{ - // -------------------------------------------- // - // ENUM - // -------------------------------------------- // - - ENEMY( - "an enemy", "enemies", "an enemy faction", "enemy factions", - "Enemy" - ) { @Override public ChatColor getColor() { return MConf.get().colorEnemy; } }, - - NEUTRAL( - "someone neutral to you", "those neutral to you", "a neutral faction", "neutral factions", - "Neutral" - ) { @Override public ChatColor getColor() { return MConf.get().colorNeutral; } }, - - TRUCE( - "someone in truce with you", "those in truce with you", "a faction in truce", "factions in truce", - "Truce" - ) { @Override public ChatColor getColor() { return MConf.get().colorTruce; } }, - - ALLY( - "an ally", "allies", "an allied faction", "allied factions", - "Ally" - ) { @Override public ChatColor getColor() { return MConf.get().colorAlly; } }, - - FACTION( - "your faction", "your faction", "your faction", "your faction", - "Faction" - ) { @Override public ChatColor getColor() { return MConf.get().colorMember; } }, - - // END OF LIST - ; - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public int getValue() { return this.ordinal(); } - - private final String descPlayerOne; - public String getDescPlayerOne() { return this.descPlayerOne; } - - private final String descPlayerMany; - public String getDescPlayerMany() { return this.descPlayerMany; } - - private final String descFactionOne; - public String getDescFactionOne() { return this.descFactionOne; } - - private final String descFactionMany; - public String getDescFactionMany() { return this.descFactionMany; } - - private final Set names; - public Set getNames() { return this.names; } - @Override public String getName() { return this.getNames().iterator().next(); } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - Rel(String descPlayerOne, String descPlayerMany, String descFactionOne, String descFactionMany, String... names) - { - this.descPlayerOne = descPlayerOne; - this.descPlayerMany = descPlayerMany; - this.descFactionOne = descFactionOne; - this.descFactionMany = descFactionMany; - this.names = Collections.unmodifiableSet(new MassiveSet<>(names)); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public ChatColor getColor() - { - return MConf.get().colorMember; - } - - @Override - public String getId() - { - return name(); - } - - @Override - public String getDisplayName(Object senderObject) - { - return this.getColor() + this.getName(); - } - - // -------------------------------------------- // - // UTIL - // -------------------------------------------- // - - public boolean isAtLeast(Rel rel) - { - return this.getValue() >= rel.getValue(); - } - - public boolean isAtMost(Rel rel) - { - return this.getValue() <= rel.getValue(); - } - - public boolean isLessThan(Rel rel) - { - return this.getValue() < rel.getValue(); - } - - public boolean isMoreThan(Rel rel) - { - return this.getValue() > rel.getValue(); - } - - // Used for friendly fire. - public boolean isFriend() - { - return this.isAtLeast(TRUCE); - } - - @Deprecated - public String getPrefix() - { - return ""; - } - -} diff --git a/src/com/massivecraft/factions/RelationParticipator.java b/src/com/massivecraft/factions/RelationParticipator.java deleted file mode 100644 index 9a495431..00000000 --- a/src/com/massivecraft/factions/RelationParticipator.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.massivecraft.factions; - -import org.bukkit.ChatColor; - - -public interface RelationParticipator -{ - String describeTo(RelationParticipator observer); - String describeTo(RelationParticipator observer, boolean ucfirst); - - Rel getRelationTo(RelationParticipator observer); - Rel getRelationTo(RelationParticipator observer, boolean ignorePeaceful); - - ChatColor getColorTo(RelationParticipator observer); -} diff --git a/src/com/massivecraft/factions/TerritoryAccess.java b/src/com/massivecraft/factions/TerritoryAccess.java deleted file mode 100644 index 8fc7857f..00000000 --- a/src/com/massivecraft/factions/TerritoryAccess.java +++ /dev/null @@ -1,184 +0,0 @@ -package com.massivecraft.factions; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.MPerm.MPermable; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.util.RelationUtil; -import com.massivecraft.massivecore.collections.MassiveSet; - -import java.util.Collection; -import java.util.Collections; -import java.util.Set; - -public class TerritoryAccess -{ - // -------------------------------------------- // - // FIELDS: RAW - // -------------------------------------------- // - - // no default value, can't be null - private final String hostFactionId; - public String getHostFactionId() { return this.hostFactionId; } - - // default is true - private final boolean hostFactionAllowed; - public boolean isHostFactionAllowed() { return this.hostFactionAllowed; } - - // default is empty - private final Set grantedIds; - public Set getGrantedIds() { return this.grantedIds; } - - // default is null - private final String chunkName; - public String getChunkName() { return this.chunkName; } - - // -------------------------------------------- // - // FIELDS: VERSION - // -------------------------------------------- // - - public int version = 1; - - // -------------------------------------------- // - // FIELDS: DELTA - // -------------------------------------------- // - - // The simple ones - public TerritoryAccess withHostFactionId(String hostFactionId) { return valueOf(hostFactionId, hostFactionAllowed, grantedIds, chunkName); } - public TerritoryAccess withHostFactionAllowed(Boolean hostFactionAllowed) { return valueOf(hostFactionId, hostFactionAllowed, grantedIds, chunkName); } - public TerritoryAccess withGrantedIds(Collection grantedIds) { return valueOf(hostFactionId, hostFactionAllowed, grantedIds, chunkName); } - public TerritoryAccess withChunkName(String chunkName) { return valueOf(hostFactionId, hostFactionAllowed, grantedIds, chunkName); } - - // The intermediate ones - public TerritoryAccess withGranted(MPermable mpermable, boolean with) - { - return withGrantedId(mpermable.getId(), with); - } - - public TerritoryAccess withGrantedId(String grantedId, boolean with) - { - if (this.getHostFactionId().equals(grantedId)) - { - return valueOf(hostFactionId, with, grantedIds, chunkName); - } - - Set grantedIds = new MassiveSet<>(this.getGrantedIds()); - if (with) - { - grantedIds.add(grantedId); - } - else - { - grantedIds.remove(grantedId); - } - return valueOf(hostFactionId, hostFactionAllowed, grantedIds, chunkName); - } - - // -------------------------------------------- // - // FIELDS: DIRECT - // -------------------------------------------- // - - // This method intentionally returns null if the Faction no longer exists. - // In Board we don't even return this TerritoryAccess if that is the case. - public Faction getHostFaction() - { - return Faction.get(this.getHostFactionId()); - } - - public Set getGranteds() - { - return MPerm.idsToMPermables(this.getGrantedIds()); - } - - // -------------------------------------------- // - // PRIVATE CONSTRUCTOR - // -------------------------------------------- // - - // Strictly for GSON only - private TerritoryAccess() - { - this.hostFactionId = null; - this.hostFactionAllowed = true; - this.grantedIds = null; - this.chunkName = null; - } - - private TerritoryAccess(String hostFactionId, Boolean hostFactionAllowed, Collection grantedIds, String chunkName) - { - if (hostFactionId == null) throw new NullPointerException("hostFactionId"); - if (grantedIds == null) throw new NullPointerException("grantedIds"); - this.hostFactionId = hostFactionId; - - Set grantedIdsInner = new MassiveSet<>(); - grantedIdsInner.addAll(grantedIds); - if (grantedIdsInner.remove(hostFactionId)) - { - hostFactionAllowed = true; - } - this.grantedIds = Collections.unmodifiableSet(grantedIdsInner); - - this.hostFactionAllowed = (hostFactionAllowed == null || hostFactionAllowed); - - this.chunkName = chunkName; - } - - // -------------------------------------------- // - // FACTORY: VALUE OF - // -------------------------------------------- // - - public static TerritoryAccess valueOf(String hostFactionId, Boolean hostFactionAllowed, Collection grantedIds, String chunkName) - { - if (hostFactionId == null) throw new NullPointerException("hostFactionId"); - if (grantedIds == null) throw new NullPointerException("grantedIds"); - return new TerritoryAccess(hostFactionId, hostFactionAllowed, grantedIds, chunkName); - } - - public static TerritoryAccess valueOf(String hostFactionId) - { - if (hostFactionId == null) throw new NullPointerException("hostFactionId"); - return valueOf(hostFactionId, null, Collections.emptySet(), null); - } - - // -------------------------------------------- // - // INSTANCE METHODS - // -------------------------------------------- // - - public boolean isGranted(MPermable permable) - { - return isGranted(permable.getId()); - } - - public boolean isGranted(String permableId) - { - if (permableId.equals(this.hostFactionId)) return this.isHostFactionAllowed(); - return this.getGrantedIds().contains(permableId); - } - - // A "default" TerritoryAccess could be serialized as a simple string only. - // The host faction is still allowed (default) and no faction or player has been granted explicit access (default). - public boolean isDefault() - { - return this.isHostFactionAllowed() && this.getGrantedIds().isEmpty() && this.getChunkName() == null; - } - - // -------------------------------------------- // - // ACCESS STATUS - // -------------------------------------------- // - - public AccessStatus getTerritoryAccess(MPlayer mplayer) - { - if (isGranted(mplayer.getId())) return AccessStatus.ELEVATED; - if (isGranted(mplayer.getRank().getId())) return AccessStatus.ELEVATED; - - if (this.getHostFactionId().equals(mplayer.getFaction().getId())) - { - if (this.isHostFactionAllowed()) return AccessStatus.STANDARD; - else return AccessStatus.DECREASED; - } - if (isGranted(mplayer.getFaction().getId())) return AccessStatus.ELEVATED; - if (isGranted(RelationUtil.getRelationOfThatToMe(mplayer, this.getHostFaction()).toString())) return AccessStatus.ELEVATED; - - return AccessStatus.STANDARD; - } - -} diff --git a/src/com/massivecraft/factions/adapter/BoardAdapter.java b/src/com/massivecraft/factions/adapter/BoardAdapter.java deleted file mode 100644 index 0965719a..00000000 --- a/src/com/massivecraft/factions/adapter/BoardAdapter.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.massivecraft.factions.adapter; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonParseException; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; -import com.massivecraft.factions.entity.Board; - -import java.lang.reflect.Type; - -public class BoardAdapter implements JsonDeserializer, JsonSerializer -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static BoardAdapter i = new BoardAdapter(); - public static BoardAdapter get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @SuppressWarnings("unchecked") - @Override - public Board deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException - { - return new Board(context.deserialize(json, Board.MAP_TYPE)); - } - - @Override - public JsonElement serialize(Board src, Type typeOfSrc, JsonSerializationContext context) - { - return context.serialize(src.getMap(), Board.MAP_TYPE); - } - -} diff --git a/src/com/massivecraft/factions/adapter/BoardMapAdapter.java b/src/com/massivecraft/factions/adapter/BoardMapAdapter.java deleted file mode 100644 index 1556edfb..00000000 --- a/src/com/massivecraft/factions/adapter/BoardMapAdapter.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.massivecraft.factions.adapter; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; -import com.massivecraft.factions.TerritoryAccess; -import com.massivecraft.massivecore.ps.PS; - -import java.lang.reflect.Type; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.ConcurrentSkipListMap; - -public class BoardMapAdapter implements JsonDeserializer>, JsonSerializer> -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static BoardMapAdapter i = new BoardMapAdapter(); - public static BoardMapAdapter get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public Map deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException - { - Map ret = new ConcurrentSkipListMap<>(); - - JsonObject jsonObject = json.getAsJsonObject(); - - for (Entry entry : jsonObject.entrySet()) - { - String[] ChunkCoordParts = entry.getKey().split("[,\\s]+"); - int chunkX = Integer.parseInt(ChunkCoordParts[0]); - int chunkZ = Integer.parseInt(ChunkCoordParts[1]); - PS chunk = PS.valueOf(chunkX, chunkZ); - - TerritoryAccess territoryAccess = context.deserialize(entry.getValue(), TerritoryAccess.class); - - ret.put(chunk, territoryAccess); - } - - return ret; - } - - @Override - public JsonElement serialize(Map src, Type typeOfSrc, JsonSerializationContext context) - { - JsonObject ret = new JsonObject(); - - for (Entry entry : src.entrySet()) - { - PS ps = entry.getKey(); - TerritoryAccess territoryAccess = entry.getValue(); - - ret.add(ps.getChunkX().toString() + "," + ps.getChunkZ().toString(), context.serialize(territoryAccess, TerritoryAccess.class)); - } - - return ret; - } - -} diff --git a/src/com/massivecraft/factions/adapter/TerritoryAccessAdapter.java b/src/com/massivecraft/factions/adapter/TerritoryAccessAdapter.java deleted file mode 100644 index 8e0e8378..00000000 --- a/src/com/massivecraft/factions/adapter/TerritoryAccessAdapter.java +++ /dev/null @@ -1,117 +0,0 @@ -package com.massivecraft.factions.adapter; - - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; -import com.google.gson.reflect.TypeToken; -import com.massivecraft.factions.TerritoryAccess; -import com.massivecraft.massivecore.store.migrator.MigratorUtil; - -import java.lang.reflect.Type; -import java.util.Collections; -import java.util.Set; - -public class TerritoryAccessAdapter implements JsonDeserializer, JsonSerializer -{ - // -------------------------------------------- // - // CONSTANTS - // -------------------------------------------- // - - public static final String HOST_FACTION_ID = "hostFactionId"; - public static final String HOST_FACTION_ALLOWED = "hostFactionAllowed"; - public static final String GRANTED_IDS = "grantedIds"; - public static final String CHUNK_NAME = "chunkName"; - - public static final Type SET_OF_STRING_TYPE = new TypeToken>(){}.getType(); - - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static TerritoryAccessAdapter i = new TerritoryAccessAdapter(); - public static TerritoryAccessAdapter get() { return i; } - - //----------------------------------------------// - // OVERRIDE - //----------------------------------------------// - - @Override - public TerritoryAccess deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException - { - // isDefault <=> simple hostFactionId string - if (json.isJsonPrimitive()) - { - String hostFactionId = json.getAsString(); - return TerritoryAccess.valueOf(hostFactionId); - } - - // Otherwise object - JsonObject obj = json.getAsJsonObject(); - - // Prepare variables - String hostFactionId = null; - Boolean hostFactionAllowed = null; - Set grantedIds = Collections.emptySet(); - String chunkName = null; - - // Read variables (test old values first) - JsonElement element = null; - - element = obj.get(HOST_FACTION_ID); - hostFactionId = element.getAsString(); - - element = obj.get(HOST_FACTION_ALLOWED); - if (element != null) hostFactionAllowed = element.getAsBoolean(); - - element = obj.get(GRANTED_IDS); - if (element != null) grantedIds = context.deserialize(element, SET_OF_STRING_TYPE); - - element = obj.get(CHUNK_NAME); - if (element != null) chunkName = element.getAsString(); - - return TerritoryAccess.valueOf(hostFactionId, hostFactionAllowed, grantedIds, chunkName); - } - - @Override - public JsonElement serialize(TerritoryAccess src, Type typeOfSrc, JsonSerializationContext context) - { - if (src == null) return null; - - // isDefault <=> simple hostFactionId string - if (src.isDefault()) - { - return new JsonPrimitive(src.getHostFactionId()); - } - - // Otherwise object - JsonObject obj = new JsonObject(); - - obj.addProperty(HOST_FACTION_ID, src.getHostFactionId()); - - if (!src.isHostFactionAllowed()) - { - obj.addProperty(HOST_FACTION_ALLOWED, src.isHostFactionAllowed()); - } - - if (!src.getGrantedIds().isEmpty()) - { - obj.add(GRANTED_IDS, context.serialize(src.getGrantedIds(), SET_OF_STRING_TYPE)); - } - - if (src.getChunkName() != null) - { - obj.addProperty(CHUNK_NAME, src.getChunkName()); - } - - obj.add(MigratorUtil.VERSION_FIELD_NAME, new JsonPrimitive(src.version)); - - return obj; - } - -} diff --git a/src/com/massivecraft/factions/chat/ChatActive.java b/src/com/massivecraft/factions/chat/ChatActive.java deleted file mode 100644 index 2928df95..00000000 --- a/src/com/massivecraft/factions/chat/ChatActive.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.massivecraft.factions.chat; - -import com.massivecraft.massivecore.Active; -import com.massivecraft.massivecore.Identified; -import com.massivecraft.massivecore.MassivePlugin; - -public abstract class ChatActive implements Active, Identified -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private MassivePlugin activePlugin; - - private final String id; - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public ChatActive(final String id) - { - this.id = id.toLowerCase(); - } - - // -------------------------------------------- // - // OVERRIDE > IDENTIFIED - // -------------------------------------------- // - - @Override - public String getId() - { - return this.id; - } - - // -------------------------------------------- // - // OVERRIDE > ACTIVE - // -------------------------------------------- // - - @Override - public MassivePlugin setActivePlugin(MassivePlugin plugin) - { - this.activePlugin = plugin; - return plugin; - } - - @Override - public MassivePlugin getActivePlugin() - { - return this.activePlugin; - } - - @Override - public void setActive(MassivePlugin plugin) - { - this.setActive(plugin != null); - this.setActivePlugin(plugin); - } - -} diff --git a/src/com/massivecraft/factions/chat/ChatFormatter.java b/src/com/massivecraft/factions/chat/ChatFormatter.java deleted file mode 100644 index 083e1524..00000000 --- a/src/com/massivecraft/factions/chat/ChatFormatter.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.massivecraft.factions.chat; - -import org.bukkit.command.CommandSender; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * The ChatFormater is a system offered by factions for tag parsing. - * - * Note that every tag and modifier id must be lowercase. - * A tag with id "derp" is allowed but not with id "Derp". For that reason the tag {sender} will work but {Sender} wont. - */ -public class ChatFormatter -{ - // -------------------------------------------- // - // CONSTANTS - // -------------------------------------------- // - - public final static String START = "{"; - public final static String END = "}"; - public final static String SEPARATOR = "|"; - - public final static String ESC_START = "\\"+START; - public final static String ESC_END = "\\"+END; - public final static String ESC_SEPARATOR = "\\"+SEPARATOR; - - public final static Pattern pattern = Pattern.compile(ESC_START+"([^"+ESC_START+ESC_END+"]+)"+ESC_END); - - // -------------------------------------------- // - // FORMAT - // -------------------------------------------- // - - public static String format(String msg, CommandSender sender, CommandSender recipient) - { - // We build the return value in this string buffer - StringBuffer ret = new StringBuffer(); - - // A matcher to match all the tags in the msg - Matcher matcher = pattern.matcher(msg); - - // For each tag we find - while (matcher.find()) - { - // The fullmatch is something like "{sender|lp|rp}" - String fullmatch = matcher.group(0); - - // The submatch is something like "sender|lp|rp" - String submatch = matcher.group(1); - - // The parts are something like ["sender", "lp", "rp"] - String[] parts = submatch.split(ESC_SEPARATOR); - - // The modifier ids are something like ["lp", "rp"] and tagId something like "sender" - List modifierIds = new ArrayList<>(Arrays.asList(parts)); - String tagId = modifierIds.remove(0); - - // Fetch tag for the id - ChatTag tag = ChatTag.getTag(tagId); - - String replacement; - if (tag == null) - { - // No change if tag wasn't found - replacement = fullmatch; - } - else - { - replacement = compute(tag, modifierIds, sender, recipient); - if (replacement == null) - { - // If a tag or modifier returns null it's the same as opting out. - replacement = fullmatch; - } - } - - matcher.appendReplacement(ret, replacement); - } - - // Append the rest - matcher.appendTail(ret); - - // And finally we return the string value of the buffer we built - return ret.toString(); - } - - // -------------------------------------------- // - // TAG COMPUTE - // -------------------------------------------- // - - public static String compute(ChatTag tag, List modifierIds, CommandSender sender, CommandSender recipient) - { - String ret = tag.getReplacement(sender, recipient); - if (ret == null) return null; - - for (String modifierId : modifierIds) - { - // Find the modifier or skip - ChatModifier modifier = ChatModifier.getModifier(modifierId); - if (modifier == null) continue; - - // Modify and ignore change if null. - // Modifier can't get or return null. - String modified = modifier.getModified(ret, sender, recipient); - if (modified == null) continue; - - ret = modified; - } - - return ret; - } - -} diff --git a/src/com/massivecraft/factions/chat/ChatModifier.java b/src/com/massivecraft/factions/chat/ChatModifier.java deleted file mode 100644 index 56eabd0e..00000000 --- a/src/com/massivecraft/factions/chat/ChatModifier.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.massivecraft.factions.chat; - -import com.massivecraft.massivecore.collections.MassiveMap; -import org.bukkit.command.CommandSender; - -import java.util.Map; - -public abstract class ChatModifier extends ChatActive -{ - // -------------------------------------------- // - // MODIFIER REGISTER - // -------------------------------------------- // - - private final static Map idToModifier = new MassiveMap<>(); - public static ChatModifier getModifier(String modifierId) { return idToModifier.get(modifierId); } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public ChatModifier(final String id) - { - super(id); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public boolean isActive() - { - return idToModifier.containsKey(this.getId()); - } - - @Override - public void setActive(boolean active) - { - if (active) - { - idToModifier.put(this.getId(), this); - } - else - { - idToModifier.remove(this.getId()); - } - } - - // -------------------------------------------- // - // ABSTRACT - // -------------------------------------------- // - - public abstract String getModified(String subject, CommandSender sender, CommandSender recipient); -} diff --git a/src/com/massivecraft/factions/chat/ChatTag.java b/src/com/massivecraft/factions/chat/ChatTag.java deleted file mode 100644 index 861e0b6f..00000000 --- a/src/com/massivecraft/factions/chat/ChatTag.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.massivecraft.factions.chat; - -import com.massivecraft.massivecore.collections.MassiveMap; -import org.bukkit.command.CommandSender; - -import java.util.Map; - -public abstract class ChatTag extends ChatActive -{ - // -------------------------------------------- // - // TAG REGISTER - // -------------------------------------------- // - - private final static Map idToTag = new MassiveMap<>(); - public static ChatTag getTag(String tagId) { return idToTag.get(tagId); } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public ChatTag(final String id) - { - super(id); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public boolean isActive() - { - return idToTag.containsKey(this.getId()); - } - - @Override - public void setActive(boolean active) - { - if (active) - { - idToTag.put(this.getId(), this); - } - else - { - idToTag.remove(this.getId()); - } - } - - // -------------------------------------------- // - // ABSTRACT - // -------------------------------------------- // - - public abstract String getReplacement(CommandSender sender, CommandSender recipient); - -} diff --git a/src/com/massivecraft/factions/chat/modifier/ChatModifierLc.java b/src/com/massivecraft/factions/chat/modifier/ChatModifierLc.java deleted file mode 100644 index 20585fc4..00000000 --- a/src/com/massivecraft/factions/chat/modifier/ChatModifierLc.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.massivecraft.factions.chat.modifier; - -import com.massivecraft.factions.chat.ChatModifier; -import org.bukkit.command.CommandSender; - -public class ChatModifierLc extends ChatModifier -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private ChatModifierLc() { super("lc"); } - private static ChatModifierLc i = new ChatModifierLc(); - public static ChatModifierLc get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getModified(String subject, CommandSender sender, CommandSender recipient) - { - return subject.toLowerCase(); - } - -} diff --git a/src/com/massivecraft/factions/chat/modifier/ChatModifierLp.java b/src/com/massivecraft/factions/chat/modifier/ChatModifierLp.java deleted file mode 100644 index f02924a4..00000000 --- a/src/com/massivecraft/factions/chat/modifier/ChatModifierLp.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.massivecraft.factions.chat.modifier; - -import com.massivecraft.factions.chat.ChatModifier; -import org.bukkit.command.CommandSender; - - -public class ChatModifierLp extends ChatModifier -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private ChatModifierLp() { super("lp"); } - private static ChatModifierLp i = new ChatModifierLp(); - public static ChatModifierLp get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getModified(String subject, CommandSender sender, CommandSender recipient) - { - if (subject.equals("")) return subject; - return " "+subject; - } - -} diff --git a/src/com/massivecraft/factions/chat/modifier/ChatModifierParse.java b/src/com/massivecraft/factions/chat/modifier/ChatModifierParse.java deleted file mode 100644 index b2e3e6c8..00000000 --- a/src/com/massivecraft/factions/chat/modifier/ChatModifierParse.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.massivecraft.factions.chat.modifier; - -import com.massivecraft.factions.chat.ChatModifier; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.command.CommandSender; - -public class ChatModifierParse extends ChatModifier -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private ChatModifierParse() { super("parse"); } - private static ChatModifierParse i = new ChatModifierParse(); - public static ChatModifierParse get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getModified(String subject, CommandSender sender, CommandSender recipient) - { - return Txt.parse(subject); - } - -} diff --git a/src/com/massivecraft/factions/chat/modifier/ChatModifierRp.java b/src/com/massivecraft/factions/chat/modifier/ChatModifierRp.java deleted file mode 100644 index 8f7c0893..00000000 --- a/src/com/massivecraft/factions/chat/modifier/ChatModifierRp.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.massivecraft.factions.chat.modifier; - -import com.massivecraft.factions.chat.ChatModifier; -import org.bukkit.command.CommandSender; - -public class ChatModifierRp extends ChatModifier -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private ChatModifierRp() { super("rp"); } - private static ChatModifierRp i = new ChatModifierRp(); - public static ChatModifierRp get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getModified(String subject, CommandSender sender, CommandSender recipient) - { - if (subject.equals("")) return subject; - return subject+" "; - } - -} diff --git a/src/com/massivecraft/factions/chat/modifier/ChatModifierUc.java b/src/com/massivecraft/factions/chat/modifier/ChatModifierUc.java deleted file mode 100644 index 03271c7d..00000000 --- a/src/com/massivecraft/factions/chat/modifier/ChatModifierUc.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.massivecraft.factions.chat.modifier; - -import com.massivecraft.factions.chat.ChatModifier; -import org.bukkit.command.CommandSender; - -public class ChatModifierUc extends ChatModifier -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private ChatModifierUc() { super("uc"); } - private static ChatModifierUc i = new ChatModifierUc(); - public static ChatModifierUc get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getModified(String subject, CommandSender sender, CommandSender recipient) - { - return subject.toUpperCase(); - } - -} diff --git a/src/com/massivecraft/factions/chat/modifier/ChatModifierUcf.java b/src/com/massivecraft/factions/chat/modifier/ChatModifierUcf.java deleted file mode 100644 index fb8b73d3..00000000 --- a/src/com/massivecraft/factions/chat/modifier/ChatModifierUcf.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.massivecraft.factions.chat.modifier; - -import com.massivecraft.factions.chat.ChatModifier; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.command.CommandSender; - -public class ChatModifierUcf extends ChatModifier -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private ChatModifierUcf() { super("ucf"); } - private static ChatModifierUcf i = new ChatModifierUcf(); - public static ChatModifierUcf get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getModified(String subject, CommandSender sender, CommandSender recipient) - { - return Txt.upperCaseFirst(subject); - } - -} diff --git a/src/com/massivecraft/factions/chat/tag/ChatTagName.java b/src/com/massivecraft/factions/chat/tag/ChatTagName.java deleted file mode 100644 index 2ee6fc2e..00000000 --- a/src/com/massivecraft/factions/chat/tag/ChatTagName.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.massivecraft.factions.chat.tag; - -import com.massivecraft.factions.chat.ChatTag; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPlayer; -import org.bukkit.command.CommandSender; - -public class ChatTagName extends ChatTag -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private ChatTagName() { super("factions_name"); } - private static ChatTagName i = new ChatTagName(); - public static ChatTagName get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getReplacement(CommandSender sender, CommandSender recipient) - { - // Get entities - MPlayer usender = MPlayer.get(sender); - - // No "force" - Faction faction = usender.getFaction(); - if (faction.isNone()) return ""; - - return faction.getName(); - } - -} diff --git a/src/com/massivecraft/factions/chat/tag/ChatTagNameforce.java b/src/com/massivecraft/factions/chat/tag/ChatTagNameforce.java deleted file mode 100644 index 7dc264f5..00000000 --- a/src/com/massivecraft/factions/chat/tag/ChatTagNameforce.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.massivecraft.factions.chat.tag; - -import com.massivecraft.factions.chat.ChatTag; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPlayer; -import org.bukkit.command.CommandSender; - -public class ChatTagNameforce extends ChatTag -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private ChatTagNameforce() { super("factions_nameforce"); } - private static ChatTagNameforce i = new ChatTagNameforce(); - public static ChatTagNameforce get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getReplacement(CommandSender sender, CommandSender recipient) - { - // Get entities - MPlayer usender = MPlayer.get(sender); - - Faction faction = usender.getFaction(); - return faction.getName(); - } - -} diff --git a/src/com/massivecraft/factions/chat/tag/ChatTagRelcolor.java b/src/com/massivecraft/factions/chat/tag/ChatTagRelcolor.java deleted file mode 100644 index eb17367f..00000000 --- a/src/com/massivecraft/factions/chat/tag/ChatTagRelcolor.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.massivecraft.factions.chat.tag; - -import com.massivecraft.factions.chat.ChatTag; -import com.massivecraft.factions.entity.MPlayer; -import org.bukkit.command.CommandSender; - -public class ChatTagRelcolor extends ChatTag -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private ChatTagRelcolor() { super("factions_relcolor"); } - private static ChatTagRelcolor i = new ChatTagRelcolor(); - public static ChatTagRelcolor get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getReplacement(CommandSender sender, CommandSender recipient) - { - // Opt out if no recipient - if (recipient == null) return null; - - // Get entities - MPlayer usender = MPlayer.get(sender); - MPlayer urecipient = MPlayer.get(recipient); - - return urecipient.getRelationTo(usender).getColor().toString(); - } - -} diff --git a/src/com/massivecraft/factions/chat/tag/ChatTagRole.java b/src/com/massivecraft/factions/chat/tag/ChatTagRole.java deleted file mode 100644 index ec9868e1..00000000 --- a/src/com/massivecraft/factions/chat/tag/ChatTagRole.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.massivecraft.factions.chat.tag; - -import com.massivecraft.factions.chat.ChatTag; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.command.CommandSender; - -public class ChatTagRole extends ChatTag -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private ChatTagRole() { super("factions_role"); } - private static ChatTagRole i = new ChatTagRole(); - public static ChatTagRole get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getReplacement(CommandSender sender, CommandSender recipient) - { - // Get entities - MPlayer usender = MPlayer.get(sender); - - return Txt.upperCaseFirst(usender.getRank().getName().toLowerCase()); - } - -} diff --git a/src/com/massivecraft/factions/chat/tag/ChatTagRoleprefix.java b/src/com/massivecraft/factions/chat/tag/ChatTagRoleprefix.java deleted file mode 100644 index ac61fca0..00000000 --- a/src/com/massivecraft/factions/chat/tag/ChatTagRoleprefix.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.massivecraft.factions.chat.tag; - -import com.massivecraft.factions.chat.ChatTag; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPlayer; -import org.bukkit.command.CommandSender; - -public class ChatTagRoleprefix extends ChatTag -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private ChatTagRoleprefix() { super("factions_roleprefix"); } - private static ChatTagRoleprefix i = new ChatTagRoleprefix(); - public static ChatTagRoleprefix get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getReplacement(CommandSender sender, CommandSender recipient) - { - // Get entities - MPlayer usender = MPlayer.get(sender); - - // No "force" - Faction faction = usender.getFaction(); - if (faction.isNone()) return ""; - - return usender.getRank().getPrefix(); - } - -} diff --git a/src/com/massivecraft/factions/chat/tag/ChatTagRoleprefixforce.java b/src/com/massivecraft/factions/chat/tag/ChatTagRoleprefixforce.java deleted file mode 100644 index 80122fcb..00000000 --- a/src/com/massivecraft/factions/chat/tag/ChatTagRoleprefixforce.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.massivecraft.factions.chat.tag; - -import com.massivecraft.factions.chat.ChatTag; -import com.massivecraft.factions.entity.MPlayer; -import org.bukkit.command.CommandSender; - -public class ChatTagRoleprefixforce extends ChatTag -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private ChatTagRoleprefixforce() { super("factions_roleprefixforce"); } - private static ChatTagRoleprefixforce i = new ChatTagRoleprefixforce(); - public static ChatTagRoleprefixforce get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getReplacement(CommandSender sender, CommandSender recipient) - { - // Get entities - MPlayer usender = MPlayer.get(sender); - - return usender.getRank().getPrefix(); - } - -} diff --git a/src/com/massivecraft/factions/chat/tag/ChatTagTitle.java b/src/com/massivecraft/factions/chat/tag/ChatTagTitle.java deleted file mode 100644 index 32f8e15f..00000000 --- a/src/com/massivecraft/factions/chat/tag/ChatTagTitle.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.massivecraft.factions.chat.tag; - -import com.massivecraft.factions.chat.ChatTag; -import com.massivecraft.factions.entity.MPlayer; -import org.bukkit.command.CommandSender; - -public class ChatTagTitle extends ChatTag -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private ChatTagTitle() { super("factions_title"); } - private static ChatTagTitle i = new ChatTagTitle(); - public static ChatTagTitle get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getReplacement(CommandSender sender, CommandSender recipient) - { - // Get entities - MPlayer usender = MPlayer.get(sender); - - if (!usender.hasTitle()) return ""; - return usender.getTitle(); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactions.java b/src/com/massivecraft/factions/cmd/CmdFactions.java deleted file mode 100644 index d77c8b09..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactions.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.massivecore.command.MassiveCommandDeprecated; -import com.massivecraft.massivecore.command.MassiveCommandVersion; - -import java.util.List; - -public class CmdFactions extends FactionsCommand -{ - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static CmdFactions i = new CmdFactions(); - public static CmdFactions get() { return i; } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public CmdFactionsDocumentation cmdFactionsDocumentation = new CmdFactionsDocumentation(); - public CmdFactionsList cmdFactionsList = new CmdFactionsList(); - public CmdFactionsFaction cmdFactionsFaction = new CmdFactionsFaction(); - public CmdFactionsPlayer cmdFactionsPlayer = new CmdFactionsPlayer(); - public CmdFactionsStatus cmdFactionsStatus = new CmdFactionsStatus(); - public CmdFactionsJoin cmdFactionsJoin = new CmdFactionsJoin(); - public CmdFactionsLeave cmdFactionsLeave = new CmdFactionsLeave(); - public CmdFactionsWarp cmdFactionsWarp = new CmdFactionsWarp(); - public CmdFactionsHome cmdFactionsHome = new CmdFactionsHome(); - public CmdFactionsSethome cmdFactionsSethome = new CmdFactionsSethome(); - public CmdFactionsUnsethome cmdFactionsUnsethome = new CmdFactionsUnsethome(); - public CmdFactionsVote cmdFactionsVote = new CmdFactionsVote(); - 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 CmdFactionsInvite cmdFactionsInvite = new CmdFactionsInvite(); - public CmdFactionsKick cmdFactionsKick = new CmdFactionsKick(); - public CmdFactionsTitle cmdFactionsTitle = new CmdFactionsTitle(); - public CmdFactionsRank cmdFactionsRank = new CmdFactionsRank(); - public CmdFactionsMoney cmdFactionsMoney = new CmdFactionsMoney(); - public CmdFactionsTop cmdFactionsTop = new CmdFactionsTop(); - public CmdFactionsSeeChunk cmdFactionsSeeChunk = new CmdFactionsSeeChunk(); - public CmdFactionsSeeChunkOld cmdFactionsSeeChunkOld = new CmdFactionsSeeChunkOld(); - public CmdFactionsTerritorytitles cmdFactionsTerritorytitles = new CmdFactionsTerritorytitles(); - public CmdFactionsClaim cmdFactionsClaim = new CmdFactionsClaim(); - public CmdFactionsUnclaim cmdFactionsUnclaim = new CmdFactionsUnclaim(); - public CmdFactionsAccess cmdFactionsAccess = new CmdFactionsAccess(); - public CmdFactionsChunkname cmdFactionsChunkname = new CmdFactionsChunkname(); - public CmdFactionsRelation cmdFactionsRelation = new CmdFactionsRelation(); - public CmdFactionsRelationOld cmdFactionsRelationOldAlly = new CmdFactionsRelationOld("ally"); - public CmdFactionsRelationOld cmdFactionsRelationOldTruce = new CmdFactionsRelationOld("truce"); - public CmdFactionsRelationOld cmdFactionsRelationOldNeutral = new CmdFactionsRelationOld("neutral"); - public CmdFactionsRelationOld cmdFactionsRelationOldEnemy = new CmdFactionsRelationOld("enemy"); - public CmdFactionsTax cmdFactionsTax = new CmdFactionsTax(); - public CmdFactionsPerm cmdFactionsPerm = new CmdFactionsPerm(); - public CmdFactionsFlag cmdFactionsFlag = new CmdFactionsFlag(); - public CmdFactionsFly cmdFactionsFly = new CmdFactionsFly(); - public CmdFactionsUnstuck cmdFactionsUnstuck = new CmdFactionsUnstuck(); - public CmdFactionsOverride cmdFactionsOverride = new CmdFactionsOverride(); - public CmdFactionsDisband cmdFactionsDisband = new CmdFactionsDisband(); - public CmdFactionsPowerboost cmdFactionsPowerBoost = new CmdFactionsPowerboost(); - public CmdFactionsSetpower cmdFactionsSetpower = new CmdFactionsSetpower(); - public CmdFactionsMoneyconvert cmdFactionsMoneyconvert = new CmdFactionsMoneyconvert(); - public CmdFactionsConfig cmdFactionsConfig = new CmdFactionsConfig(); - public CmdFactionsClean cmdFactionsClean = new CmdFactionsClean(); - public MassiveCommandVersion cmdFactionsVersion = new MassiveCommandVersion(Factions.get()); - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactions() - { - // Old rank stuff - this.addChild(new CmdFactionsRankOld("demote")); - this.addChild(new CmdFactionsRankOld("promote")); - - // Deprecated Commands - this.addChild(new MassiveCommandDeprecated(this.cmdFactionsRank, "leader", "owner", "officer", "moderator", "coleader")); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public List getAliases() - { - return MConf.get().aliasesF; - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAccess.java b/src/com/massivecraft/factions/cmd/CmdFactionsAccess.java deleted file mode 100644 index 2823f637..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAccess.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; - -public class CmdFactionsAccess extends FactionsCommand -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public CmdFactionsAccessView cmdFactionsAccessView = new CmdFactionsAccessView(); - public CmdFactionsAccessGrant cmdFactionsAccessGrant = new CmdFactionsAccessGrant(); - public CmdFactionsAccessDeny cmdFactionsAccessDeny = new CmdFactionsAccessDeny(); - public CmdFactionsAccessInspect cmdFactionsAccessInspect = new CmdFactionsAccessInspect(); - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsAccess() - { - // Requirements - this.addRequirements(RequirementIsPlayer.get()); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAccessAbstract.java b/src/com/massivecraft/factions/cmd/CmdFactionsAccessAbstract.java deleted file mode 100644 index b116bb58..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAccessAbstract.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.TerritoryAccess; -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.MPerm.MPermable; -import com.massivecraft.factions.util.AsciiMap; -import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.Txt; - -import java.util.Collection; - - -public abstract class CmdFactionsAccessAbstract extends FactionsCommand -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public PS chunk; - public TerritoryAccess ta; - public Faction hostFaction; - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsAccessAbstract() - { - // Requirements - this.addRequirements(RequirementIsPlayer.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void senderFields(boolean set) - { - super.senderFields(set); - - if (set) - { - chunk = PS.valueOf(me.getLocation()).getChunk(true); - ta = BoardColl.get().getTerritoryAccessAt(chunk); - hostFaction = ta.getHostFaction(); - } - else - { - chunk = null; - ta = null; - hostFaction = null; - } - } - - public void sendAccessInfo() - { - String chunkDesc = AsciiMap.getChunkDescWithName(chunk, ta); - Object title = "Access" + chunkDesc; - title = Txt.titleize(title); - message(title); - - msg("Host Faction: %s", hostFaction.describeTo(msender, true)); - msg("Host Faction Allowed: %s", ta.isHostFactionAllowed() ? Txt.parse("TRUE") : Txt.parse("FALSE")); - msg("Granted to: %s", CmdFactionsPermShow.permablesToDisplayString(ta.getGranteds(), msender)); - } - - public void setAccess(Collection chunks, MPermable mpermable, boolean granted) - { - chunks.forEach(chunk -> setAccess(chunk, mpermable, granted)); - } - - public void setAccess(PS chunk, MPermable mpermable, boolean granted) - { - TerritoryAccess ta = BoardColl.get().getTerritoryAccessAt(chunk); - Faction faction = ta.getHostFaction(); - - - String chunkDesc = AsciiMap.getChunkDescWithName(chunk, ta); - String grantedDenied = granted ? "granted" : "denied"; - String mpermableDesc = mpermable.getDisplayName(msender); - - if ( ! MPerm.getPermAccess().has(msender, faction, false)) - { - msg("You do not have permission to edit access%s.", chunkDesc); - return; - } - - if (ta.isGranted(mpermable) == granted) - { - msg("Access%s is already %s to %s.", chunkDesc, grantedDenied, mpermableDesc); - return; - } - - ta = ta.withGranted(mpermable, granted); - BoardColl.get().setTerritoryAccessAt(chunk, ta); - - msg("Access%s is now %s to %s.", chunkDesc, grantedDenied, mpermableDesc); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAccessDeny.java b/src/com/massivecraft/factions/cmd/CmdFactionsAccessDeny.java deleted file mode 100644 index 8a4b49fa..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAccessDeny.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; - -public class CmdFactionsAccessDeny extends CmdFactionsAccessAbstract -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public CmdFactionsAccessSetOne cmdFactionsAccessDenyOne = new CmdFactionsAccessSetOne(false); - public CmdFactionsAccessSetSquare cmdFactionsAccessDenySquare = new CmdFactionsAccessSetSquare(false); - public CmdFactionsAccessSetCircle cmdFactionsAccessDenyCircle = new CmdFactionsAccessSetCircle(false); - public CmdFactionsAccessSetFill cmdFactionsAccessDenyFill = new CmdFactionsAccessSetFill(false); - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsAccessDeny() - { - // Requirements - this.addRequirements(RequirementIsPlayer.get()); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAccessGrant.java b/src/com/massivecraft/factions/cmd/CmdFactionsAccessGrant.java deleted file mode 100644 index 979ba253..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAccessGrant.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; - -public class CmdFactionsAccessGrant extends CmdFactionsAccessAbstract -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public CmdFactionsAccessSetOne cmdFactionsAccessGrantOne = new CmdFactionsAccessSetOne(true); - public CmdFactionsAccessSetSquare cmdFactionsAccessGrantSquare = new CmdFactionsAccessSetSquare(true); - public CmdFactionsAccessSetCircle cmdFactionsAccessGrantCircle = new CmdFactionsAccessSetCircle(true); - public CmdFactionsAccessSetFill cmdFactionsAccessGrantFill = new CmdFactionsAccessSetFill(true); - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsAccessGrant() - { - // Requirements - this.addRequirements(RequirementIsPlayer.get()); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAccessInspect.java b/src/com/massivecraft/factions/cmd/CmdFactionsAccessInspect.java deleted file mode 100644 index 716c6606..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAccessInspect.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.cmd.type.TypeMPermable; -import com.massivecraft.factions.entity.Board; -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.MPerm.MPermable; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.collections.MassiveMap; -import com.massivecraft.massivecore.mixin.MixinWorld; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.ps.PSFormatHumanSpace; -import com.massivecraft.massivecore.util.Txt; - -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.stream.Collectors; - -public class CmdFactionsAccessInspect extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsAccessInspect() - { - // Parameters - this.addParameter(TypeMPermable.get(), "rank/rel/player/faction"); - this.addParameter(TypeFaction.get(), "faction", "your"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Parameter - Faction faction = this.readArgAt(1, msenderFaction); - MPermable mpermable = TypeMPermable.get(faction).read(this.argAt(0), sender); - - String factionId = faction.getId(); - - // Check if they have access perms, unless they are checking for their own access - if (mpermable != msender && mpermable != msenderFaction && mpermable != msender.getRank()) - { - if ( ! MPerm.getPermAccess().has(msender, faction, true)) return; - } - - // Turn into id->chunks - // And filter the ones that are empty - Map> world2Chunks = new MassiveMap<>(); - for (Board board : BoardColl.get().getAll()) - { - String worldId = board.getId(); - Set chunks = board.getMap().entrySet().stream() - .filter(e -> e.getValue().getHostFactionId().equals(factionId)) - .filter(e -> e.getValue().isGranted(mpermable)) - .map(Entry::getKey) - .collect(Collectors.toSet()); - if ( ! chunks.isEmpty()) world2Chunks.put(worldId, chunks); - } - - if (world2Chunks.isEmpty()) - { - msg("%s has no special access in %s.", mpermable.getDisplayName(msender), faction.describeTo(msender)); - return; - } - - msg("%s has special access in %s in the following chunks:", mpermable.getDisplayName(msender), faction.describeTo(msender)); - - for (Entry> entry : world2Chunks.entrySet()) - { - String worldId = entry.getKey(); - Set chunks = entry.getValue(); - - String worldName = MixinWorld.get().getWorldDisplayName(worldId); - - // Remove world from chunks - List chunkNames = chunks.stream() - .map(PS::getChunkCoords) - .map(PSFormatHumanSpace.get()::format) - .collect(Collectors.toList()); - - String chunkDesc = Txt.implodeCommaAnd(chunkNames, Txt.parse("")); - - msg("%s (%d): %s", worldName, chunks.size(), chunkDesc); - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetCircle.java b/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetCircle.java deleted file mode 100644 index 339d4a16..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetCircle.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Perm; -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; -import com.massivecraft.massivecore.util.ChunkUtil; - -import java.util.Set; - - -public class CmdFactionsAccessSetCircle extends CmdFactionsAccessSetXRadius -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsAccessSetCircle(boolean grant) - { - // Super - super(grant); - - // Aliases - this.addAliases("circle"); - - // Requirements - this.addRequirements(RequirementIsPlayer.get()); - Perm perm = grant ? Perm.ACCESS_GRANT_CIRCLE : Perm.ACCESS_DENY_CIRCLE; - this.addRequirements(RequirementHasPerm.get(perm)); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public Set getChunks() throws MassiveException - { - // Common Startup - final PS chunk = PS.valueOf(me.getLocation()).getChunk(true); - return ChunkUtil.getChunksCircle(chunk, this.getRadius()); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetFill.java b/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetFill.java deleted file mode 100644 index 678f8334..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetFill.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Perm; -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; -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; -import com.massivecraft.massivecore.util.ChunkUtil; - -import java.util.Set; -import java.util.function.Predicate; - -public class CmdFactionsAccessSetFill extends CmdFactionsAccessSetXSimple -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsAccessSetFill(boolean claim) - { - // Super - super(claim); - - // Aliases - this.addAliases("fill"); - - // Requirements - this.addRequirements(RequirementIsPlayer.get()); - Perm perm = claim ? Perm.ACCESS_GRANT_FILL : Perm.ACCESS_DENY_FILL; - this.addRequirements(RequirementHasPerm.get(perm)); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public Set getChunks() throws MassiveException - { - // Common Startup - final PS chunk = PS.valueOf(me.getLocation()).getChunk(true); - - // What faction (aka color) resides there? - // NOTE: Wilderness/None is valid. - final Faction color = BoardColl.get().getFactionAt(chunk); - - // Calculate - int max = MConf.get().setFillMax; - Predicate matcher = ps -> BoardColl.get().getFactionAt(ps) == color; - return ChunkUtil.getChunkArea(chunk, matcher, max); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetOne.java b/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetOne.java deleted file mode 100644 index db48973c..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetOne.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Perm; -import com.massivecraft.massivecore.command.requirement.RequirementHasPerm; -import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; -import com.massivecraft.massivecore.ps.PS; - -import java.util.Collections; -import java.util.Set; - - -public class CmdFactionsAccessSetOne extends CmdFactionsAccessSetXSimple -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsAccessSetOne(boolean claim) - { - // Super - super(claim); - - // Aliases - this.addAliases("one"); - - // Requirements - this.addRequirements(RequirementIsPlayer.get()); - Perm perm = claim ? Perm.ACCESS_GRANT_ONE : Perm.ACCESS_DENY_ONE; - this.addRequirements(RequirementHasPerm.get(perm)); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public Set getChunks() - { - final PS chunk = PS.valueOf(me.getLocation()).getChunk(true); - return Collections.singleton(chunk); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetSquare.java b/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetSquare.java deleted file mode 100644 index 078c5bca..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetSquare.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Perm; -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; -import com.massivecraft.massivecore.util.ChunkUtil; - -import java.util.Set; - - -public class CmdFactionsAccessSetSquare extends CmdFactionsAccessSetXRadius -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsAccessSetSquare(boolean grant) - { - // Super - super(grant); - - // Aliases - this.addAliases("square"); - - // Requirements - this.addRequirements(RequirementIsPlayer.get()); - Perm perm = grant ? Perm.ACCESS_GRANT_SQUARE : Perm.ACCESS_DENY_SQUARE; - this.addRequirements(RequirementHasPerm.get(perm)); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public Set getChunks() throws MassiveException - { - // Common Startup - final PS chunk = PS.valueOf(me.getLocation()).getChunk(true); - return ChunkUtil.getChunksSquare(chunk, this.getRadius()); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetX.java b/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetX.java deleted file mode 100644 index 048b6424..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetX.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeMPermable; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPerm.MPermable; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.ps.PS; - -import java.util.Set; - -public abstract class CmdFactionsAccessSetX extends CmdFactionsAccessAbstract -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private boolean grant = true; - public boolean isGranting() { return this.grant; } - public void setGranting(boolean grant) { this.grant = grant; } - - private int mpermableArgIndex = 0; - public int getMPermableArgIndex() { return this.mpermableArgIndex; } - public void setMPermableArgIndex(int mpermableArgIndex) { this.mpermableArgIndex = mpermableArgIndex; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsAccessSetX(boolean grant) - { - this.setGranting(grant); - this.setSetupEnabled(false); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - final MPermable mpermable = this.getMPermable(hostFaction); - - final Set chunks = this.getChunks(); - if (chunks == null) throw new NullPointerException("chunks"); - - // Apply / Inform - setAccess(chunks, mpermable, this.isGranting()); - } - - // -------------------------------------------- // - // ABSTRACT - // -------------------------------------------- // - - public abstract Set getChunks() throws MassiveException; - - // -------------------------------------------- // - // EXTRAS - // -------------------------------------------- // - - public MPermable getMPermable(Faction faction) throws MassiveException - { - String arg = this.argAt(this.getMPermableArgIndex()); - return TypeMPermable.get(faction).read(arg, sender); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetXRadius.java b/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetXRadius.java deleted file mode 100644 index 1f21d83e..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetXRadius.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeMPermable; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.primitive.TypeInteger; - - -public abstract class CmdFactionsAccessSetXRadius extends CmdFactionsAccessSetX -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsAccessSetXRadius(boolean claim) - { - // Super - super(claim); - - // Parameters - this.addParameter(TypeInteger.get(), "radius"); - - this.addParameter(TypeMPermable.get(), "rank/rel/faction/player"); - this.setMPermableArgIndex(1); - - } - - // -------------------------------------------- // - // EXTRAS - // -------------------------------------------- // - - public Integer getRadius() throws MassiveException - { - int radius = this.readArgAt(0); - - // Radius Claim Min - if (radius < 1) - { - throw new MassiveException().setMsg("If you specify a radius, it must be at least 1."); - } - - // Radius Claim Max - if (radius > MConf.get().setRadiusMax && ! msender.isOverriding()) - { - throw new MassiveException().setMsg("The maximum radius allowed is %s.", MConf.get().setRadiusMax); - } - - return radius; - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetXSimple.java b/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetXSimple.java deleted file mode 100644 index 5195ca76..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAccessSetXSimple.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeMPermable; - -public abstract class CmdFactionsAccessSetXSimple extends CmdFactionsAccessSetX -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsAccessSetXSimple(boolean claim) - { - // Super - super(claim); - - // Parameters - this.addParameter(TypeMPermable.get(), "rank/rel/player/faction"); - this.setMPermableArgIndex(0); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAccessView.java b/src/com/massivecraft/factions/cmd/CmdFactionsAccessView.java deleted file mode 100644 index 82fc8016..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAccessView.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.massivecraft.factions.cmd; - -public class CmdFactionsAccessView extends CmdFactionsAccessAbstract -{ - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() - { - this.sendAccessInfo(); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsChunkname.java b/src/com/massivecraft/factions/cmd/CmdFactionsChunkname.java deleted file mode 100644 index ccb3465a..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsChunkname.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.TerritoryAccess; -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.util.AsciiMap; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; -import com.massivecraft.massivecore.command.type.TypeNullable; -import com.massivecraft.massivecore.command.type.primitive.TypeString; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.MUtil; -import com.massivecraft.massivecore.util.Txt; - -public class CmdFactionsChunkname extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsChunkname() - { - // Parameters - this.addParameter(TypeNullable.get(TypeString.get()), "name", "read"); - - this.addRequirements(RequirementIsPlayer.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - PS chunk = PS.valueOf(me.getLocation()).getChunk(true); - TerritoryAccess ta = BoardColl.get().getTerritoryAccessAt(chunk); - - if (!this.argIsSet(0)) - { - String name = ta.getChunkName(); - if (name == null) - { - msg("This chunk has no name."); - } - else - { - msg("This chunk is called %s.", name); - } - return; - } - - // MPerm - if (!MPerm.getPermTerritory().has(msender, msenderFaction, true)) return; - - // Args - String target = this.readArg(); - if (target != null) - { - target = target.trim(); - target = Txt.parse(target); - } - - String old = ta.getChunkName(); - - // NoChange - if (MUtil.equals(old, target)) - { - if (old == null) - { - throw new MassiveException().addMsg("This chunk already has no name."); - } - throw new MassiveException().addMsg("The name for this chunk is already %s.", old); - } - - ta = ta.withChunkName(target); - BoardColl.get().setTerritoryAccessAt(chunk, ta); - - String chunkDesc = AsciiMap.getChunkDesc(chunk); - msg("The chunk name%s is now %s.", chunkDesc, target); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java b/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java deleted file mode 100644 index 1963c676..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.massivecraft.factions.cmd; - -public class CmdFactionsClaim extends FactionsCommand -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public CmdFactionsSetOne cmdFactionsClaimOne = new CmdFactionsSetOne(true); - public CmdFactionsSetAuto cmdFactionsClaimAuto = new CmdFactionsSetAuto(true); - public CmdFactionsSetFill cmdFactionsClaimFill = new CmdFactionsSetFill(true); - public CmdFactionsSetSquare cmdFactionsClaimSquare = new CmdFactionsSetSquare(true); - public CmdFactionsSetCircle cmdFactionsClaimCircle = new CmdFactionsSetCircle(true); - public CmdFactionsSetAll cmdFactionsClaimAll = new CmdFactionsSetAll(true); - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsClean.java b/src/com/massivecraft/factions/cmd/CmdFactionsClean.java deleted file mode 100644 index 480dbb0e..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsClean.java +++ /dev/null @@ -1,167 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Rel; -import com.massivecraft.factions.TerritoryAccess; -import com.massivecraft.factions.entity.Board; -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.FactionColl; -import com.massivecraft.factions.entity.Invitation; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.entity.MPlayerColl; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.collections.MassiveSet; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.store.EntityInternalMap; -import com.massivecraft.massivecore.util.Txt; - -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.Set; - -public class CmdFactionsClean extends FactionsCommand -{ - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - Object message; - int count; - - // Title - message = Txt.titleize("Factions Cleaner Results"); - message(message); - - // Yada - cleanMessage(this.cleanPlayer(), "player"); - cleanMessage(this.cleanFactionInvites(), "faction invites"); - cleanMessage(this.cleanFactionRelationWhishes(), "faction relation whishes"); - cleanMessage(this.cleanBoardHost(), "chunk whole"); - cleanMessage(this.cleanBoardGrant(), "chunk access"); - } - - // -------------------------------------------- // - // CLEAN - // -------------------------------------------- // - - private void cleanMessage(int count, String name) - { - msg("%d %s", count, name); - } - - private int cleanPlayer() - { - int ret = 0; - - for (MPlayer mplayer : MPlayerColl.get().getAll()) - { - if (!mplayer.isFactionOrphan()) continue; - - mplayer.resetFactionData(); - ret += 1; - } - - return ret; - } - - private int cleanFactionInvites() - { - int ret = 0; - - for (Faction faction : FactionColl.get().getAll()) - { - EntityInternalMap invitations = faction.getInvitations(); - if (invitations.isEmpty()) continue; - - ret += invitations.size(); - Set invitationIds = new MassiveSet<>(invitations.keySet()); - for (String inviteId : invitationIds) - { - invitations.detachIdFixed(inviteId); - } - - faction.changed(); - } - - return ret; - } - - private int cleanFactionRelationWhishes() - { - int ret = 0; - - for (Faction faction : FactionColl.get().getAll()) - { - for (Iterator> iterator = faction.getRelationWishes().entrySet().iterator(); iterator.hasNext();) - { - Entry entry = iterator.next(); - String factionId = entry.getKey(); - if (FactionColl.get().containsId(factionId)) continue; - - iterator.remove(); - ret += 1; - faction.changed(); - } - } - - return ret; - } - - private int cleanBoardHost() - { - int ret = 0; - - for (Board board : BoardColl.get().getAll()) - { - for (Entry entry : board.getMap().entrySet()) - { - PS ps = entry.getKey(); - TerritoryAccess territoryAccess = entry.getValue(); - String factionId = territoryAccess.getHostFactionId(); - - if (FactionColl.get().containsId(factionId)) continue; - - board.removeAt(ps); - ret += 1; - } - } - - return ret; - } - - private int cleanBoardGrant() - { - int ret = 0; - - for (Board board : BoardColl.get().getAll()) - { - for (Entry entry : board.getMap().entrySet()) - { - PS ps = entry.getKey(); - TerritoryAccess territoryAccess = entry.getValue(); - boolean changed = false; - - for (String grantedIds : territoryAccess.getGrantedIds()) - { - if (MPerm.idToMPermableOptional(grantedIds).isPresent()) continue; - - territoryAccess = territoryAccess.withGrantedId(grantedIds, false); - ret += 1; - changed = true; - } - - if (changed) - { - board.setTerritoryAccessAt(ps, territoryAccess); - } - } - } - - return ret; - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java b/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java deleted file mode 100644 index d500cbce..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.cmd.req.ReqHasntFaction; -import com.massivecraft.factions.cmd.type.TypeFactionNameStrict; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.FactionColl; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.event.EventFactionsCreate; -import com.massivecraft.factions.event.EventFactionsMembershipChange; -import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.mson.Mson; -import com.massivecraft.massivecore.store.MStore; -import org.bukkit.ChatColor; - -public class CmdFactionsCreate extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsCreate() - { - // Aliases - this.addAliases("new"); - - // Parameters - this.addParameter(TypeFactionNameStrict.get(), "name").setDesc("the name of your new faction"); - - // Requirements - this.addRequirements(ReqHasntFaction.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - String newName = this.readArg(); - - // Pre-Generate Id - String factionId = MStore.createId(); - - // Event - EventFactionsCreate createEvent = new EventFactionsCreate(sender, factionId, newName); - createEvent.run(); - if (createEvent.isCancelled()) return; - - // Apply - Faction faction = FactionColl.get().create(factionId); - faction.setName(newName); - - msender.setRank(faction.getLeaderRank()); - msender.setFaction(faction); - - EventFactionsMembershipChange joinEvent = new EventFactionsMembershipChange(sender, msender, faction, MembershipChangeReason.CREATE); - joinEvent.run(); - // NOTE: join event cannot be cancelled or you'll have an empty faction - - // Inform - msg("You created the faction %s", faction.getName(msender)); - message(Mson.mson(mson("You should now: ").color(ChatColor.YELLOW), CmdFactions.get().cmdFactionsDescription.getTemplate())); - - // Log - if (MConf.get().logFactionCreate) - { - Factions.get().log(msender.getName() + " created a new faction: " + newName); - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java b/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java deleted file mode 100644 index 5e1ae9ea..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.req.ReqHasFaction; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.event.EventFactionsDescriptionChange; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.primitive.TypeString; -import com.massivecraft.massivecore.mixin.MixinDisplayName; - -public class CmdFactionsDescription extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsDescription() - { - // Parameters - this.addParameter(TypeString.get(), "desc", true).setDesc("the new faction desciption"); - - // Requirements - this.addRequirements(ReqHasFaction.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - String newDescription = this.readArg(); - - // MPerm - if ( ! MPerm.getPermDesc().has(msender, msenderFaction, true)) return; - - // Event - EventFactionsDescriptionChange event = new EventFactionsDescriptionChange(sender, msenderFaction, newDescription); - event.run(); - if (event.isCancelled()) return; - newDescription = event.getNewDescription(); - - // Apply - msenderFaction.setDescription(newDescription); - - // Inform - for (MPlayer follower : msenderFaction.getMPlayers()) - { - follower.msg("%s set your faction description to:\n%s", MixinDisplayName.get().getDisplayName(sender, follower), msenderFaction.getDescriptionDesc()); - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java b/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java deleted file mode 100644 index 3799d753..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.FactionColl; -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.EventFactionsDisband; -import com.massivecraft.factions.event.EventFactionsMembershipChange; -import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.primitive.TypeStringConfirmation; -import com.massivecraft.massivecore.util.ConfirmationUtil; -import com.massivecraft.massivecore.util.IdUtil; -import com.massivecraft.massivecore.util.Txt; - -public class CmdFactionsDisband extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsDisband() - { - // Parameters - this.addParameter(TypeFaction.get(), "faction"); - this.addParameter(TypeStringConfirmation.get(), "confirmation", ""); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - Faction faction = this.readArg(); - String confirmationString = this.readArg(null); - - if (MConf.get().requireConfirmationForFactionDisbanding) ConfirmationUtil.tryConfirm(this); - - // MPerm - if ( ! MPerm.getPermDisband().has(msender, faction, true)) return; - - // Verify - if (faction.getFlag(MFlag.getFlagPermanent())) - { - throw new MassiveException().addMsg("This faction is designated as permanent, so you cannot disband it."); - } - - // Event - EventFactionsDisband event = new EventFactionsDisband(me, faction); - event.run(); - if (event.isCancelled()) return; - - // Merged Apply and Inform - - // Run event for each player in the faction - for (MPlayer mplayer : faction.getMPlayers()) - { - EventFactionsMembershipChange membershipChangeEvent = new EventFactionsMembershipChange(sender, mplayer, FactionColl.get().getNone(), MembershipChangeReason.DISBAND); - membershipChangeEvent.run(); - } - - // Inform - for (MPlayer mplayer : faction.getMPlayersWhereOnline(true)) - { - mplayer.msg("%s disbanded your faction.", msender.describeTo(mplayer)); - } - - if (msenderFaction != faction) - { - msender.msg("You disbanded %s." , faction.describeTo(msender)); - } - - // Log - if (MConf.get().logFactionDisband) - { - Factions.get().log(Txt.parse("The faction %s (%s) was disbanded by %s.", faction.getName(), faction.getId(), msender.getDisplayName(IdUtil.getConsole()))); - } - - // Apply - faction.detach(); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDocumentation.java b/src/com/massivecraft/factions/cmd/CmdFactionsDocumentation.java deleted file mode 100644 index e61abef5..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDocumentation.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Factions; -import org.bukkit.ChatColor; - -public class CmdFactionsDocumentation extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsDocumentation() - { - String web = Factions.get().getDescription().getWebsite(); - this.setHelp(mson("More help can be found at ", mson(web).link(web).color(ChatColor.AQUA))); - } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public CmdFactionsDocumentationPower cmdFactionsDocumentationPower = new CmdFactionsDocumentationPower(); - public CmdFactionsDocumentationRanks cmdFactionsDocumentationRanks = new CmdFactionsDocumentationRanks(); - public CmdFactionsDocumentationWarps cmdFactionsDocumentationWarps = new CmdFactionsDocumentationWarps(); - public CmdFactionsDocumentationFlags cmdFactionsDocumentationFlags = new CmdFactionsDocumentationFlags(); - public CmdFactionsDocumentationPerms cmdFactionsDocumentationPerms = new CmdFactionsDocumentationPerms(); - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationFlags.java b/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationFlags.java deleted file mode 100644 index e855a6ef..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationFlags.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.entity.MFlag; -import com.massivecraft.factions.entity.MFlagColl; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.util.Txt; - -import java.util.List; -import java.util.stream.Collectors; - -public class CmdFactionsDocumentationFlags extends FactionsCommandDocumentation -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsDocumentationFlags() - { - - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - msgDoc("Flags are a way to give certain factions certain attributes " + - " such as disabling pvp or enabling friendly fire."); - msgDoc("To see all the flags type:"); - message(CmdFactions.get().cmdFactionsFlag.cmdFactionsFlagList.getTemplate(false, true, sender)); - - List flags = MFlagColl.get().getAll(MFlag::isEditable).stream().map(flag -> Txt.parse("%s", flag.getName())).collect(Collectors.toList()); - String str = Txt.implodeCommaAndDot(flags, Txt.parse("")); - msgDoc("The flags you can edit for your faction are: %s", str); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationPerms.java b/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationPerms.java deleted file mode 100644 index fa316f5a..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationPerms.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.massivecore.MassiveException; - -public class CmdFactionsDocumentationPerms extends FactionsCommandDocumentation -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsDocumentationPerms() - { - - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - msgDoc("Permissions decide who can do what in your faction. " + - "Permissions can be given to a rank, a player, a relation, " + - "everyone in another faction or everyone with a specific rank in another faction."); - msgDoc("Because perms can be given to all of these groups individually, it allows for extreme degrees of fine tuning."); - - msgDoc("To list all permissions type:"); - message(CmdFactions.get().cmdFactionsPerm.cmdFactionsPermList.getTemplate(false, true, sender)); - - msgDoc("To see who has a specific perm type:"); - message(CmdFactions.get().cmdFactionsPerm.cmdFactionsPermShow.getTemplate(false, true, sender)); - - msgDoc("Per default permissions are only granted to ranks within your faction " + - "and a few perms are given to allies, but if you have changed it that will be displayed by the command above."); - msgDoc("When you create a new rank, you will have to set up their perms from scratch."); - - msgDoc("If you want to know what permissions are specifically given to someone do:"); - message(CmdFactions.get().cmdFactionsPerm.cmdFactionsPermView.getTemplate(false, true, sender)); - - msgDoc("To set perms do: "); - message(CmdFactions.get().cmdFactionsPerm.cmdFactionsPermSet.getTemplate(false, true, sender)); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationPower.java b/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationPower.java deleted file mode 100644 index ec9a990b..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationPower.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.massivecore.MassiveException; - -public class CmdFactionsDocumentationPower extends FactionsCommandDocumentation -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsDocumentationPower() - { - - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - msgDoc("All players have an amount of power ranging from %.2f to %.2f.", MConf.get().powerMin, MConf.get().powerMax); - msgDoc("The power of a faction is equal to the combined power of all it's members."); - msgDoc("Your power is %.2f", msender.getPower()); - msgDoc("Your faction's power is %.2f", msenderFaction.getPower()); - msgDoc("The amount of chunks a faction can claim is the amount power it has."); - msgDoc("For every hour you are online you gain %.2f power.", MConf.get().powerPerHour); - msgDoc("Every time you die you power is decreased by %.2f .", MConf.get().powerPerDeath*-1); - if (!MConf.get().canLeaveWithNegativePower && MConf.get().powerMin < 0) - { - msgDoc("You can't leave a faction if your power is negative."); - } - - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationRanks.java b/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationRanks.java deleted file mode 100644 index 14ab32d6..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationRanks.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.entity.Rank; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.mson.Mson; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.ChatColor; - -import java.util.Comparator; -import java.util.List; -import java.util.stream.Collectors; - -public class CmdFactionsDocumentationRanks extends FactionsCommandDocumentation -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsDocumentationRanks() - { - - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - msgDoc("Ranks divide the faction into groups."); - - List ranks = msenderFaction.getRanks().getAll(Comparator.comparingInt(Rank::getPriority).reversed()); - List rankDesc = ranks.stream().map(r -> r.getDisplayName(msender)).collect(Collectors.toList()); - msgDoc("Your faction has: %s", Txt.implodeCommaAndDot(rankDesc, Txt.parse(""))); - - msgDoc("Ranks can have a prefix that will be prepended before any player name. Prefixes can be coloured."); - msgDoc("All ranks have a priority showed in parentheses after the name."); - - Mson msonLeader = mson("The rank with the highest priority is deemed the “leader rank”" + - "(can be renamed) and only one person can have that rank") - .tooltip("For yor faction the leader rank is" + rankDesc.get(0)) - .color(ChatColor.YELLOW); - messageDoc(msonLeader); - msgDoc("Whenever a new person joins the faction they will be assigned the rank with the lowest priority."); - msgDoc("Priorities are important because they determine who can do what." + - "For example: you can’t kick someone with the same or higher rank than yourself." + - "So if you have both Officers, and Co-leaders, do not fear officers kicking co-leaders or the co-leaders kicking each other." + - "They can’t. The same goes for changing ranks, titles and other similar things."); - - msgDoc("To show, set or edit ranks do:"); - message(CmdFactions.get().cmdFactionsRank.getTemplate(false, true, sender)); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationTax.java b/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationTax.java deleted file mode 100644 index 746b40a3..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationTax.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.req.ReqTaxEnabled; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.money.Money; -import com.massivecraft.massivecore.util.TimeDiffUtil; -import com.massivecraft.massivecore.util.TimeUnit; -import com.massivecraft.massivecore.util.Txt; - -import java.util.LinkedHashMap; - -public class CmdFactionsDocumentationTax extends FactionsCommandDocumentation -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsDocumentationTax() - { - this.addRequirements(ReqTaxEnabled.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - LinkedHashMap timeUnitcounts = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(MConf.get().taxTaskPeriodMillis, TimeUnit.getAll()), 3); - String periodString = TimeDiffUtil.formatedVerboose(timeUnitcounts); - - msgDoc("Taxation Period: every %s.", periodString); - - long nextTaxationTime = MConf.get().taxTaskPeriodMillis + MConf.get().taxTaskPeriodMillis; - - msgDoc("Next Taxation: %s", Txt.getTimeDeltaDescriptionRelNow(nextTaxationTime)); - - String minTax = Money.format(MConf.get().taxPlayerMinimum); - String maxTax = Money.format(MConf.get().taxPlayerMaximum); - msgDoc("Taxes for players can be set between %s and %s.", minTax, maxTax); - - double tax = msenderFaction.getTaxForPlayer(msender); - if (tax > 0) - { - msgDoc("You pay %s in taxes.", Money.format(tax)); - } - else if (tax < 0) - { - msgDoc("Instead of taxes you faction pays you %s .", Money.format(tax * -1)); - } - else - { - msgDoc("You don't pay taxes."); - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationWarps.java b/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationWarps.java deleted file mode 100644 index 0b36a392..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationWarps.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.req.ReqFactionWarpsEnabled; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.MPerm.MPermable; -import com.massivecraft.massivecore.MassiveException; - -import java.util.Set; - -public class CmdFactionsDocumentationWarps extends FactionsCommandDocumentation -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsDocumentationWarps() - { - this.addRequirements(ReqFactionWarpsEnabled.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - msgDoc("A faction can have warps which allows it's members to easily go to important places within the faction."); - - if (MConf.get().warpsMax < 0) - { - msgDoc("There is no limit to how many warps a faction can have."); - } - else - { - msgDoc("A faction can only have %d warps.", MConf.get().warpsMax); - } - - if (MConf.get().warpsMustBeInClaimedTerritory) - { - msgDoc("Warps must be within claimed territory."); - } - - if (MConf.get().warpsTeleportToOnDeathActive) - { - msgDoc("If your faction has a warp with the name %s you will teleport there after death.", MConf.get().warpsTeleportToOnDeathName); - } - - if (!MConf.get().warpsTeleportAllowedFromEnemyTerritory) - { - msgDoc("You can't use faction warps while in enemy territory."); - } - - if (!MConf.get().warpsTeleportAllowedFromDifferentWorld) - { - msgDoc("You can't teleporty to a warp from another world."); - } - - if (MConf.get().warpsTeleportAllowedEnemyDistance > 0) - { - String str = String.format("You can't teleport home if there is an enemy within %.1f blocks of you", MConf.get().warpsTeleportAllowedEnemyDistance); - if (MConf.get().warpsTeleportIgnoreEnemiesIfInOwnTerritory) str += " unless you are in your own territory."; - else str += "."; - msgDoc(str); - } - - if (msenderFaction.isNormal()) - { - Set set = msenderFaction.getPermittedPermables(MPerm.getPermWarp()); - String permables = CmdFactionsPermShow.permablesToDisplayString(set, msender); - msgDoc("In your faction warps can be used by: %s.", permables); - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsFaction.java b/src/com/massivecraft/factions/cmd/CmdFactionsFaction.java deleted file mode 100644 index cee7de79..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsFaction.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.event.EventFactionsFactionShowAsync; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.PriorityLines; -import com.massivecraft.massivecore.mixin.MixinMessage; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; - -import java.util.TreeSet; - -public class CmdFactionsFaction extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsFaction() - { - // Aliases - this.addAliases("f", "show", "who").setDesc("the faction to show info about"); - - // Parameters - this.addParameter(TypeFaction.get(), "faction", "you"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - final Faction faction = this.readArg(msenderFaction); - final CommandSender sender = this.sender; - - Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> { - // Event - EventFactionsFactionShowAsync event = new EventFactionsFactionShowAsync(sender, faction); - event.run(); - if (event.isCancelled()) return; - - // Title - MixinMessage.get().messageOne(sender, Txt.titleize("Faction " + faction.getName(msender))); - - // Lines - TreeSet priorityLiness = new TreeSet<>(event.getIdPriorityLiness().values()); - for (PriorityLines priorityLines : priorityLiness) - { - MixinMessage.get().messageOne(sender, priorityLines.getLines()); - } - }); - - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsFlag.java b/src/com/massivecraft/factions/cmd/CmdFactionsFlag.java deleted file mode 100644 index 1fd88599..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsFlag.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.massivecraft.factions.cmd; - -public class CmdFactionsFlag extends FactionsCommand -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public CmdFactionsFlagList cmdFactionsFlagList = new CmdFactionsFlagList(); - public CmdFactionsFlagShow cmdFactionsFlagShow = new CmdFactionsFlagShow(); - public CmdFactionsFlagSet cmdFactionsFlagSet = new CmdFactionsFlagSet(); - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsFlagList.java b/src/com/massivecraft/factions/cmd/CmdFactionsFlagList.java deleted file mode 100644 index c4bb34d0..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsFlagList.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.entity.MFlag; -import com.massivecraft.factions.entity.MFlagColl; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.Parameter; -import com.massivecraft.massivecore.pager.Pager; -import com.massivecraft.massivecore.pager.Stringifier; -import org.bukkit.Bukkit; - -import java.util.List; - -public class CmdFactionsFlagList extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsFlagList() - { - // Parameters - this.addParameter(Parameter.getPage()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Parameter - final int page = this.readArg(); - final MPlayer mplayer = msender; - - // Pager create - String title = "Flag List for " + msenderFaction.describeTo(mplayer); - final Pager pager = new Pager<>(this, title, page, (Stringifier) (mflag, index) -> mflag.getStateDesc(false, false, true, true, true, false)); - - Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> { - // Get items - List items = MFlagColl.get().getAll(mplayer.isOverriding() ? null : MFlag::isVisible); - - // Pager items - pager.setItems(items); - - // Pager message - pager.message(); - }); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsFlagSet.java b/src/com/massivecraft/factions/cmd/CmdFactionsFlagSet.java deleted file mode 100644 index 2845009a..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsFlagSet.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.cmd.type.TypeMFlag; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MFlag; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.event.EventFactionsFlagChange; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.primitive.TypeBooleanYes; - -public class CmdFactionsFlagSet extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsFlagSet() - { - // Parameters - this.addParameter(TypeMFlag.get(), "flag").setDesc("the faction flag to set a value for"); - this.addParameter(TypeBooleanYes.get(), "yes/no").setDesc("should the flag be on or off?"); - this.addParameter(TypeFaction.get(), "faction", "you").setDesc("the faction to set the flag for (per default your own)"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - MFlag flag = this.readArg(); - boolean value = this.readArg(); - Faction faction = this.readArg(msenderFaction); - - // Do the sender have the right to change flags for this faction? - if ( ! MPerm.getPermFlags().has(msender, faction, true)) return; - - // Is this flag editable? - if (!msender.isOverriding() && ! flag.isEditable()) - { - throw new MassiveException().addMsg("The flag %s is not editable.", flag.getName()); - } - - // Event - EventFactionsFlagChange event = new EventFactionsFlagChange(sender, faction, flag, value); - event.run(); - if (event.isCancelled()) return; - value = event.isNewValue(); - - // No change - if (faction.getFlag(flag) == value) - { - throw new MassiveException().addMsg("%s already has %s set to %s.", faction.describeTo(msender), flag.getStateDesc(value, false, true, true, false, true), flag.getStateDesc(value, true, true, false, false, false)); - } - - // Apply - faction.setFlag(flag, value); - - // Inform - String stateInfo = flag.getStateDesc(faction.getFlag(flag), true, false, true, true, true); - if (msender.getFaction() != faction) - { - // Send message to sender - msg("%s set a flag for %s.", msender.describeTo(msender, true), faction.describeTo(msender, true)); - message(stateInfo); - } - faction.msg("%s set a flag for %s.", msender.describeTo(faction, true), faction.describeTo(faction, true)); - faction.sendMessage(stateInfo); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsFlagShow.java b/src/com/massivecraft/factions/cmd/CmdFactionsFlagShow.java deleted file mode 100644 index 249e24a7..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsFlagShow.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MFlag; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.collections.MassiveList; -import com.massivecraft.massivecore.command.Parameter; -import com.massivecraft.massivecore.pager.Pager; -import com.massivecraft.massivecore.pager.Stringifier; - -import java.util.List; - -public class CmdFactionsFlagShow extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsFlagShow() - { - // Parameters - this.addParameter(TypeFaction.get(), "faction", "you").setDesc("the faction to show flags for"); - this.addParameter(Parameter.getPage()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Parameters - final Faction faction = this.readArg(msenderFaction); - int page = this.readArg(); - - // Pager create - String title = "Flags for " + faction.describeTo(msender); - Pager pager = new Pager<>(this, title, page, MFlag.getAll(), (Stringifier) (mflag, index) -> mflag.getStateDesc(faction.getFlag(mflag), true, true, true, true, true)); - - // Pager args - List pagerArgs = new MassiveList<>( - faction.getId(), - String.valueOf(page) - ); - pager.setArgs(pagerArgs); - - // Pager message - pager.messageAsync(); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsFly.java b/src/com/massivecraft/factions/cmd/CmdFactionsFly.java deleted file mode 100644 index ec5334a9..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsFly.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.engine.EngineFly; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.MassiveCommandToggle; -import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; -import com.massivecraft.massivecore.engine.EngineMassiveCorePlayerUpdate; -import com.massivecraft.massivecore.ps.PS; -import org.bukkit.entity.Player; - -public class CmdFactionsFly extends MassiveCommandToggle -{ - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static CmdFactionsFly i = new CmdFactionsFly(); - public static CmdFactionsFly get() { return i; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsFly() - { - this.addRequirements(RequirementIsPlayer.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getName() - { - return "faction flying"; - } - - @Override - public boolean getValue() throws MassiveException - { - return MPlayer.get(sender).isFlying(); - } - - public void setValue(boolean value) throws MassiveException - { - MPlayer mplayer = MPlayer.get(sender); - Player player = me; - if (player == null) throw new MassiveException().addMsg("Could not find player."); - - PS ps = PS.valueOf(player); - if (value) EngineFly.canFlyInTerritoryOrThrow(mplayer, ps); - - mplayer.setFlying(value); - EngineMassiveCorePlayerUpdate.update(player, false); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsHome.java b/src/com/massivecraft/factions/cmd/CmdFactionsHome.java deleted file mode 100644 index 22617606..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsHome.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.Visibility; -import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; -import com.massivecraft.massivecore.util.MUtil; - -import java.util.List; - -public class CmdFactionsHome extends FactionsCommandWarp -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsHome() - { - // Requirements - this.addRequirements(RequirementIsPlayer.get()); - - // Parameters - this.addParameter(TypeFaction.get(), "faction", "you"); - - - // Visibility - this.setVisibility(Visibility.INVISIBLE); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - List args = MUtil.list(MConf.get().warpsHomeName, this.argAt(0)); - CmdFactions.get().cmdFactionsWarp.cmdFactionsWarpGo.execute(me, args); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java b/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java deleted file mode 100644 index 680804a3..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.massivecraft.factions.cmd; - -public class CmdFactionsInvite extends FactionsCommand -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public CmdFactionsInviteList cmdFactionsInviteList = new CmdFactionsInviteList(); - public CmdFactionsInviteAdd cmdFactionsInviteAdd = new CmdFactionsInviteAdd(); - public CmdFactionsInviteRemove cmdFactionsInviteRemove = new CmdFactionsInviteRemove(); - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsInviteAdd.java b/src/com/massivecraft/factions/cmd/CmdFactionsInviteAdd.java deleted file mode 100644 index 86701c5b..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsInviteAdd.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeMPlayer; -import com.massivecraft.factions.entity.Invitation; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.event.EventFactionsInvitedChange; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.container.TypeSet; -import com.massivecraft.massivecore.mson.Mson; -import com.massivecraft.massivecore.util.IdUtil; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.ChatColor; - -import java.util.Collection; - -public class CmdFactionsInviteAdd extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsInviteAdd() - { - // Parameters - this.addParameter(TypeSet.get(TypeMPlayer.get()), "players", true).setDesc("the player to invite"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - Collection mplayers = this.readArg(); - - String senderId = IdUtil.getId(sender); - long creationMillis = System.currentTimeMillis(); - - // MPerm - if ( ! MPerm.getPermInvite().has(msender, msenderFaction, true)) return; - - for (MPlayer mplayer : mplayers) - { - // Already member? - if (mplayer.getFaction() == msenderFaction) - { - msg("%s is already a member of %s.", mplayer.getName(), msenderFaction.getName(msender)); - continue; - } - - // Already invited? - boolean isInvited = msenderFaction.isInvited(mplayer); - - if ( ! isInvited) - { - // Event - EventFactionsInvitedChange event = new EventFactionsInvitedChange(sender, mplayer, msenderFaction, isInvited); - event.run(); - if (event.isCancelled()) continue; - isInvited = event.isNewInvited(); - - // Inform - mplayer.msg("%s invited you to %s.", msender.describeTo(mplayer, true), msenderFaction.describeTo(mplayer)); - msenderFaction.msg("%s invited %s to your faction.", msender.describeTo(msenderFaction, true), mplayer.describeTo(msenderFaction)); - - // Apply - Invitation invitation = new Invitation(senderId, creationMillis); - msenderFaction.invite(mplayer.getId(), invitation); - msenderFaction.changed(); - } - else - { - // Mson - String command = CmdFactions.get().cmdFactionsInvite.cmdFactionsInviteRemove.getCommandLine(mplayer.getName()); - String tooltip = Txt.parse("Click to %s.", command); - - Mson remove = Mson.mson( - mson("You might want to remove him. ").color(ChatColor.YELLOW), - mson("Click to " + command).color(ChatColor.RED).tooltip(tooltip).suggest(command) - ); - - // Inform - msg("%s is already invited to %s.", mplayer.getName(), msenderFaction.getName(msender)); - message(remove); - } - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsInviteList.java b/src/com/massivecraft/factions/cmd/CmdFactionsInviteList.java deleted file mode 100644 index f577a7b7..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsInviteList.java +++ /dev/null @@ -1,83 +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.Invitation; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.collections.MassiveList; -import com.massivecraft.massivecore.command.Parameter; -import com.massivecraft.massivecore.comparator.ComparatorSmart; -import com.massivecraft.massivecore.mixin.MixinDisplayName; -import com.massivecraft.massivecore.pager.Pager; -import com.massivecraft.massivecore.pager.Stringifier; -import com.massivecraft.massivecore.util.TimeDiffUtil; -import com.massivecraft.massivecore.util.TimeUnit; -import com.massivecraft.massivecore.util.Txt; - -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map.Entry; - -public class CmdFactionsInviteList extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsInviteList() - { - // Parameters - this.addParameter(Parameter.getPage()); - this.addParameter(TypeFaction.get(), "faction", "you").setDesc("the faction to list invites for"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - int page = this.readArg(); - - Faction faction = this.readArg(msenderFaction); - - if ( faction != msenderFaction && ! Perm.INVITE_LIST_OTHER.has(sender, true)) return; - - // MPerm - if ( ! MPerm.getPermInvite().has(msender, msenderFaction, true)) return; - - // Pager Create - final List> invitations = new MassiveList<>(faction.getInvitations().entrySet()); - - invitations.sort((i1, i2) -> ComparatorSmart.get().compare(i2.getValue().getCreationMillis(), i1.getValue().getCreationMillis())); - - final long now = System.currentTimeMillis(); - - final Pager> pager = new Pager<>(this, "Invited Players List", page, invitations, (Stringifier>) (entry, index) -> { - String inviteeId = entry.getKey(); - String inviterId = entry.getValue().getInviterId(); - - String inviteeDisplayName = MixinDisplayName.get().getDisplayName(inviteeId, sender); - String inviterDisplayName = inviterId != null ? MixinDisplayName.get().getDisplayName(inviterId, sender) : Txt.parse("unknown"); - - String ageDesc = ""; - if (entry.getValue().getCreationMillis() != null) - { - long millis = now - entry.getValue().getCreationMillis(); - LinkedHashMap ageUnitcounts = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(millis, TimeUnit.getAllButMillis()), 2); - ageDesc = TimeDiffUtil.formatedMinimal(ageUnitcounts, ""); - ageDesc = " " + ageDesc + Txt.parse(" ago"); - } - - return Txt.parse("%s was invited by %s%s.", inviteeDisplayName, inviterDisplayName, ageDesc); - }); - - // Pager Message - pager.message(); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsInviteRemove.java b/src/com/massivecraft/factions/cmd/CmdFactionsInviteRemove.java deleted file mode 100644 index 0ab92db9..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsInviteRemove.java +++ /dev/null @@ -1,146 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeMPlayer; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.event.EventFactionsInvitedChange; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.container.TypeSet; -import com.massivecraft.massivecore.mson.Mson; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.ChatColor; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class CmdFactionsInviteRemove extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - public CmdFactionsInviteRemove() - { - // Parameters - this.addParameter(TypeSet.get(TypeMPlayer.get()), "players/all", true).setDesc("the player to deinvite"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - Set mplayers = new HashSet<>(); - boolean all = false; - - // Args - if ("all".equalsIgnoreCase(this.argAt(0))) - { - Set ids = msenderFaction.getInvitations().keySet(); - // Doesn't show up if list is empty. Test at home if it worked. - if (ids == null || ids.isEmpty()) - { - throw new MassiveException().addMsg("No one is invited to your faction."); - } - all = true; - - for (String id : ids) - { - mplayers.add(MPlayer.get(id)); - } - } - else - { - mplayers = this.readArgAt(0); - } - - // MPerm - if ( ! MPerm.getPermInvite().has(msender, msenderFaction, true)) return; - - for (MPlayer mplayer : mplayers) - { - // Already member? - if (mplayer.getFaction() == msenderFaction) - { - // Mson - String command = CmdFactions.get().cmdFactionsKick.getCommandLine(mplayer.getName()); - String tooltip = Txt.parse("Click to %s.", command); - - Mson kick = Mson.mson( - mson("You might want to kick him. ").color(ChatColor.YELLOW), - mson(ChatColor.RED.toString() + tooltip).tooltip(ChatColor.YELLOW.toString() + tooltip).suggest(command) - ); - - // Inform - msg("%s is already a member of %s.", mplayer.getName(), msenderFaction.getName(msender)); - message(kick); - continue; - } - - // Already invited? - boolean isInvited = msenderFaction.isInvited(mplayer); - - if (isInvited) - { - // Event - EventFactionsInvitedChange event = new EventFactionsInvitedChange(sender, mplayer, msenderFaction, isInvited); - event.run(); - if (event.isCancelled()) continue; - isInvited = event.isNewInvited(); - - // Inform Player - mplayer.msg("%s revoked your invitation to %s.", msender.describeTo(mplayer, true), msenderFaction.describeTo(mplayer)); - - // Inform Faction - if ( ! all) - { - msenderFaction.msg("%s revoked %s's invitation.", msender.describeTo(msenderFaction), mplayer.describeTo(msenderFaction)); - } - - // Apply - msenderFaction.uninvite(mplayer); - - // If all, we do this at last. So we only do it once. - if (! all) msenderFaction.changed(); - } - else - { - // Mson - String command = CmdFactions.get().cmdFactionsInvite.cmdFactionsInviteAdd.getCommandLine(mplayer.getName()); - String tooltip = Txt.parse("Click to %s.", command); - - Mson invite = Mson.mson( - mson("You might want to invite him. ").color(ChatColor.YELLOW), - mson(ChatColor.GREEN.toString() + tooltip).tooltip(ChatColor.YELLOW.toString() + tooltip).suggest(command) - ); - - // Inform - msg("%s is not invited to %s.", mplayer.describeTo(msender, true), msenderFaction.describeTo(mplayer)); - message(invite); - } - } - - // Inform Faction if all - if (all) - { - List names = new ArrayList<>(); - for (MPlayer mplayer : mplayers) - { - names.add(mplayer.describeTo(msender, true)); - } - - Mson factionsRevokeAll = mson( - Mson.parse("%s revoked ", msender.describeTo(msenderFaction)), - Mson.parse("all %s pending invitations", mplayers.size()).tooltip(names), - mson(" from your faction.").color(ChatColor.YELLOW) - ); - - msenderFaction.sendMessage(factionsRevokeAll); - msenderFaction.changed(); - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java b/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java deleted file mode 100644 index 15828c09..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java +++ /dev/null @@ -1,137 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.Perm; -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.cmd.type.TypeMPlayer; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MFlag; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.event.EventFactionsMembershipChange; -import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.mson.Mson; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.ChatColor; - -public class CmdFactionsJoin extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsJoin() - { - // Parameters - this.addParameter(TypeFaction.get(), "faction").setDesc("the faction to join"); - this.addParameter(TypeMPlayer.get(), "player", "you").setDesc("the player that should join tje faction (for admins only)"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - Faction faction = this.readArg(); - - MPlayer mplayer = this.readArg(msender); - Faction mplayerFaction = mplayer.getFaction(); - - boolean samePlayer = mplayer == msender; - - // Validate - if (!samePlayer && ! Perm.JOIN_OTHERS.has(sender, false)) - { - msg("You do not have permission to move other players into a faction."); - return; - } - - if (faction == mplayerFaction) - { - String command = CmdFactions.get().cmdFactionsKick.getCommandLine(mplayer.getName()); - - // Mson creation - Mson alreadyMember = Mson.mson( - Mson.parse(mplayer.describeTo(msender, true)), - mson((samePlayer ? " are" : " is") + " already a member of " + faction.getName(msender) + ".").color(ChatColor.YELLOW) - ); - - message(alreadyMember.suggest(command).tooltip(Txt.parse("Click to %s.", command))); - return; - } - - if (MConf.get().factionMemberLimit > 0 && faction.getMPlayers().size() >= MConf.get().factionMemberLimit) - { - msg(" ! The faction %s is at the limit of %d members, so %s cannot currently join.", faction.getName(msender), MConf.get().factionMemberLimit, mplayer.describeTo(msender, false)); - return; - } - - if (mplayerFaction.isNormal()) - { - String command = CmdFactions.get().cmdFactionsLeave.getCommandLine(mplayer.getName()); - - // Mson creation - Mson leaveFirst = Mson.mson( - Mson.parse(mplayer.describeTo(msender, true)), - mson(" must leave " + (samePlayer ? "your" : "their") + " current faction first.").color(ChatColor.RED) - ); - - message(leaveFirst.suggest(command).tooltip(Txt.parse("Click to %s.", command))); - return; - } - - if (!MConf.get().canLeaveWithNegativePower && mplayer.getPower() < 0) - { - msg("%s cannot join a faction with a negative power level.", mplayer.describeTo(msender, true)); - return; - } - - if( ! (faction.getFlag(MFlag.getFlagOpen()) || faction.isInvited(mplayer) || msender.isOverriding())) - { - msg("This faction requires invitation."); - if (samePlayer) - { - faction.msg("%s tried to join your faction.", mplayer.describeTo(faction, true)); - } - return; - } - - // Event - EventFactionsMembershipChange membershipChangeEvent = new EventFactionsMembershipChange(sender, msender, faction, MembershipChangeReason.JOIN); - membershipChangeEvent.run(); - if (membershipChangeEvent.isCancelled()) return; - - // Inform - if (!samePlayer) - { - mplayer.msg("%s moved you into the faction %s.", msender.describeTo(mplayer, true), faction.getName(mplayer)); - } - faction.msg("%s joined your faction.", mplayer.describeTo(faction, true)); - msender.msg("%s successfully joined %s.", mplayer.describeTo(msender, true), faction.getName(msender)); - - // Apply - mplayer.resetFactionData(); - mplayer.setFaction(faction); - mplayer.setRank(faction.getLowestRank()); - - faction.uninvite(mplayer); - - // Derplog - if (MConf.get().logFactionJoin) - { - if (samePlayer) - { - Factions.get().log(Txt.parse("%s joined the faction %s.", mplayer.getName(), faction.getName())); - } - else - { - Factions.get().log(Txt.parse("%s moved the player %s into the faction %s.", msender.getName(), mplayer.getName(), faction.getName())); - } - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsKick.java b/src/com/massivecraft/factions/cmd/CmdFactionsKick.java deleted file mode 100644 index 3d2e7379..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsKick.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.cmd.type.TypeMPlayer; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.FactionColl; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.event.EventFactionsMembershipChange; -import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.util.IdUtil; -import org.bukkit.ChatColor; - -public class CmdFactionsKick extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsKick() - { - // Parameters - this.addParameter(TypeMPlayer.get(), "player").setDesc("the player to kick"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Arg - MPlayer mplayer = this.readArg(); - - // Validate - if (msender == mplayer) - { - msg("You can't kick yourself."); - message(mson(mson("You might want to: ").color(ChatColor.YELLOW), CmdFactions.get().cmdFactionsLeave.getTemplate(false))); - return; - } - - if ( !msender.isOverriding() && mplayer.getRank().isLeader()) - { - throw new MassiveException().addMsg("The leader cannot be kicked."); - } - - if (! msender.isOverriding() && mplayer.getFaction() == msenderFaction && mplayer.getRank().isMoreThan(msender.getRank()) ) - { - throw new MassiveException().addMsg("You can't kick people of higher rank than yourself."); - } - - if (! msender.isOverriding() && mplayer.getRank() == msender.getRank()) - { - throw new MassiveException().addMsg("You can't kick people of the same rank as yourself."); - } - - if ( ! msender.isOverriding() && ! MConf.get().canLeaveWithNegativePower && mplayer.getPower() < 0) - { - msg("You can't kick that person until their power is positive."); - return; - } - - // MPerm - Faction mplayerFaction = mplayer.getFaction(); - if ( ! MPerm.getPermKick().has(msender, mplayerFaction, true)) return; - - // Event - EventFactionsMembershipChange event = new EventFactionsMembershipChange(sender, mplayer, FactionColl.get().getNone(), MembershipChangeReason.KICK); - event.run(); - if (event.isCancelled()) return; - - // Inform - mplayerFaction.msg("%s kicked %s from the faction! :O", msender.describeTo(mplayerFaction, true), mplayer.describeTo(mplayerFaction, true)); - mplayer.msg("%s kicked you from %s! :O", msender.describeTo(mplayer, true), mplayerFaction.describeTo(mplayer)); - if (mplayerFaction != msenderFaction) - { - msender.msg("You kicked %s from the faction %s!", mplayer.describeTo(msender), mplayerFaction.describeTo(msender)); - } - - if (MConf.get().logFactionKick) - { - Factions.get().log(msender.getDisplayName(IdUtil.getConsole()) + " kicked " + mplayer.getName() + " from the faction " + mplayerFaction.getName()); - } - - // Apply - if (mplayer.getRank().isLeader()) - { - mplayerFaction.promoteNewLeader(); - } - mplayerFaction.uninvite(mplayer); - mplayer.resetFactionData(); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsLeave.java b/src/com/massivecraft/factions/cmd/CmdFactionsLeave.java deleted file mode 100644 index 4daa3afc..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsLeave.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.req.ReqHasFaction; - -public class CmdFactionsLeave extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsLeave() - { - // Requirements - this.addRequirements(ReqHasFaction.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() - { - msender.leave(); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsList.java b/src/com/massivecraft/factions/cmd/CmdFactionsList.java deleted file mode 100644 index 03913c11..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsList.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.comparator.ComparatorFactionList; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.FactionColl; -import com.massivecraft.factions.entity.MPlayer; -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.util.Txt; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; - -import java.util.List; - -public class CmdFactionsList extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsList() - { - // Parameters - this.addParameter(Parameter.getPage()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - int page = this.readArg(); - final CommandSender sender = this.sender; - final MPlayer msender = this.msender; - - // NOTE: The faction list is quite slow and mostly thread safe. - // We run it asynchronously to spare the primary server thread. - - // Pager Create - final Pager pager = new Pager<>(this, "Faction List", page, (Stringifier) (faction, index) -> { - if (faction.isNone()) - { - return Txt.parse("Factionless %d online", FactionColl.get().getNone().getMPlayersWhereOnlineTo(sender).size()); - } - else - { - return Txt.parse("%s %d/%d online, %d/%d/%d", - faction.getName(msender), - faction.getMPlayersWhereOnlineTo(sender).size(), - faction.getMPlayers().size(), - faction.getLandCount(), - faction.getPowerRounded(), - faction.getPowerMaxRounded() - ); - } - }); - - Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> { - // Pager Items - final List factions = FactionColl.get().getAll(ComparatorFactionList.get(sender)); - pager.setItems(factions); - - // Pager Message - pager.message(); - }); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMap.java b/src/com/massivecraft/factions/cmd/CmdFactionsMap.java deleted file mode 100644 index 10d5b00f..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMap.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.util.AsciiMap; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; -import com.massivecraft.massivecore.command.type.primitive.TypeBooleanYes; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.Txt; - -public class CmdFactionsMap extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsMap() - { - // Parameters - this.addParameter(TypeBooleanYes.get(), "on/off", "once").setDesc("set to yes to get an auto updating map\nset to no to disable"); - - // Requirements - this.addRequirements(RequirementIsPlayer.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // NOTE: Map show is performed when auto == true || once - boolean argSet = this.argIsSet(); - boolean showMap = true; - - // Auto update - if (argSet) showMap = this.adjustAutoUpdating(); - if (!showMap) return; - - // Show Map - AsciiMap map = new AsciiMap(msender, PS.valueOf(me), !argSet); - message(map.render()); - } - - private boolean adjustAutoUpdating() throws MassiveException - { - // Get - boolean autoUpdating = this.readArg(!msender.isMapAutoUpdating()); - - // Set - msender.setMapAutoUpdating(autoUpdating); - - // Inform - msg("Map auto update %s.", Txt.parse(autoUpdating ? "ENABLED" : "DISABLED")); - return autoUpdating; - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMoney.java b/src/com/massivecraft/factions/cmd/CmdFactionsMoney.java deleted file mode 100644 index aeb48fa4..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMoney.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled; - -public class CmdFactionsMoney extends FactionsCommand -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public CmdFactionsMoneyBalance cmdMoneyBalance = new CmdFactionsMoneyBalance(); - public CmdFactionsMoneyDeposit cmdMoneyDeposit = new CmdFactionsMoneyDeposit(); - public CmdFactionsMoneyWithdraw cmdMoneyWithdraw = new CmdFactionsMoneyWithdraw(); - public CmdFactionsMoneyTransferF2f cmdMoneyTransferFf = new CmdFactionsMoneyTransferF2f(); - public CmdFactionsMoneyTransferF2p cmdMoneyTransferFp = new CmdFactionsMoneyTransferF2p(); - public CmdFactionsMoneyTransferP2f cmdMoneyTransferPf = new CmdFactionsMoneyTransferP2f(); - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsMoney() - { - // Requirements - this.addRequirements(ReqBankCommandsEnabled.get()); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyBalance.java b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyBalance.java deleted file mode 100644 index 15cac3b4..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyBalance.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Perm; -import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled; -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.integration.Econ; -import com.massivecraft.massivecore.MassiveException; - -public class CmdFactionsMoneyBalance extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsMoneyBalance() - { - // Parameters - this.addParameter(TypeFaction.get(), "faction", "you").setDesc("the faction whose balance to check"); - - // Requirements - this.addRequirements(ReqBankCommandsEnabled.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - Faction faction = this.readArg(msenderFaction); - - if (faction != msenderFaction && ! Perm.MONEY_BALANCE_ANY.has(sender, true)) return; - - Econ.sendBalanceInfo(msender, faction); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyDeposit.java b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyDeposit.java deleted file mode 100644 index ccb4abcf..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyDeposit.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled; -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.integration.Econ; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.primitive.TypeDouble; -import com.massivecraft.massivecore.money.Money; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.ChatColor; - -public class CmdFactionsMoneyDeposit extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsMoneyDeposit() - { - // Parameters - this.addParameter(TypeDouble.get(), "amount").setDesc("the amount of money to deposit"); - this.addParameter(TypeFaction.get(), "faction", "you").setDesc("the faction to deposit money to"); - - // Requirements - this.addRequirements(ReqBankCommandsEnabled.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - double amount = this.readArg(); - - Faction faction = this.readArg(msenderFaction); - - boolean success = Econ.transferMoney(msender, msender, faction, amount); - - if (success && MConf.get().logMoneyTransactions) - { - Factions.get().log(ChatColor.stripColor(Txt.parse("%s deposited %s in the faction bank: %s", msender.getName(), Money.format(amount), faction.describeTo(null)))); - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferF2f.java b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferF2f.java deleted file mode 100644 index f890f9d0..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferF2f.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled; -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.integration.Econ; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.primitive.TypeDouble; -import com.massivecraft.massivecore.money.Money; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.ChatColor; - -public class CmdFactionsMoneyTransferF2f extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsMoneyTransferF2f() - { - // Fields - this.setSetupEnabled(false); - - // Aliases - this.addAliases("ff"); - - // Parameters - this.addParameter(TypeDouble.get(), "amount").setDesc("the amount of money to transfer"); - this.addParameter(TypeFaction.get(), "faction").setDesc("the faction to transfer money from"); - this.addParameter(TypeFaction.get(), "faction").setDesc("the faction to transfer money to"); - - // Requirements - this.addRequirements(ReqBankCommandsEnabled.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - double amount = this.readArg(); - Faction from = this.readArg(); - Faction to = this.readArg(); - - boolean success = Econ.transferMoney(msender, from, to, amount); - - if (success && MConf.get().logMoneyTransactions) - { - Factions.get().log(ChatColor.stripColor(Txt.parse("%s transferred %s from the faction \"%s\" to the faction \"%s\"", msender.getName(), Money.format(amount), from.describeTo(null), to.describeTo(null)))); - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferF2p.java b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferF2p.java deleted file mode 100644 index 85484617..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferF2p.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled; -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.cmd.type.TypeMPlayer; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.integration.Econ; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.primitive.TypeDouble; -import com.massivecraft.massivecore.money.Money; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.ChatColor; - -public class CmdFactionsMoneyTransferF2p extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsMoneyTransferF2p() - { - // Fields - this.setSetupEnabled(false); - - // Aliases - this.addAliases("fp"); - - // Parameters - this.addParameter(TypeDouble.get(), "amount").setDesc("the amount of money to transfer"); - this.addParameter(TypeFaction.get(), "faction").setDesc("the faction to transfer money from"); - this.addParameter(TypeMPlayer.get(), "player").setDesc("the player to transfer money to"); - - // Requirements - this.addRequirements(ReqBankCommandsEnabled.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - double amount = this.readArg(); - Faction from = this.readArg(); - MPlayer to = this.readArg(); - - boolean success = Econ.transferMoney(msender, from, to, amount); - - if (success && MConf.get().logMoneyTransactions) - { - Factions.get().log(ChatColor.stripColor(Txt.parse("%s transferred %s from the faction \"%s\" to the player \"%s\"", msender.getName(), Money.format(amount), from.describeTo(null), to.describeTo(null)))); - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferP2f.java b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferP2f.java deleted file mode 100644 index 383cc8d1..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferP2f.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled; -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.cmd.type.TypeMPlayer; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.integration.Econ; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.primitive.TypeDouble; -import com.massivecraft.massivecore.money.Money; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.ChatColor; - -public class CmdFactionsMoneyTransferP2f extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsMoneyTransferP2f() - { - // Fields - this.setSetupEnabled(false); - - // Aliases - this.addAliases("pf"); - - // Parameters - this.addParameter(TypeDouble.get(), "amount").setDesc("the amount of money to transfer"); - this.addParameter(TypeMPlayer.get(), "player").setDesc("the player to transfer money from"); - this.addParameter(TypeFaction.get(), "faction").setDesc("the faction to transfer money to"); - - // Requirements - this.addRequirements(ReqBankCommandsEnabled.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - double amount = this.readArg(); - MPlayer from = this.readArg(); - Faction to = this.readArg(); - - boolean success = Econ.transferMoney(msender, from, to, amount); - - if (success && MConf.get().logMoneyTransactions) - { - Factions.get().log(ChatColor.stripColor(Txt.parse("%s transferred %s from the player \"%s\" to the faction \"%s\"", msender.getName(), Money.format(amount), from.describeTo(null), to.describeTo(null)))); - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyWithdraw.java b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyWithdraw.java deleted file mode 100644 index 03f98e1e..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyWithdraw.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled; -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.integration.Econ; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.primitive.TypeDouble; -import com.massivecraft.massivecore.money.Money; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.ChatColor; - -public class CmdFactionsMoneyWithdraw extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsMoneyWithdraw() - { - // Parameters - this.addParameter(TypeDouble.get(), "amount").setDesc("the amount of money to withdraw"); - this.addParameter(TypeFaction.get(), "faction", "you").setDesc("the faction to transfer money to"); - - // Requirements - this.addRequirements(ReqBankCommandsEnabled.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - Double amount = this.readArg(); - Faction from = this.readArg(msenderFaction); - - MPlayer to = msender; - - boolean success = Econ.transferMoney(msender, from, to, amount); - - if (success && MConf.get().logMoneyTransactions) - { - Factions.get().log(ChatColor.stripColor(Txt.parse("%s withdrew %s from the faction bank: %s", msender.getName(), Money.format(amount), from.describeTo(null)))); - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyconvert.java b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyconvert.java deleted file mode 100644 index 0abdc5fd..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyconvert.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.FactionColl; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.Visibility; -import com.massivecraft.massivecore.command.type.primitive.TypeStringConfirmation; -import com.massivecraft.massivecore.money.Money; -import com.massivecraft.massivecore.util.ConfirmationUtil; - -public class CmdFactionsMoneyconvert extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsMoneyconvert() - { - // Parameters - this.addParameter(TypeStringConfirmation.get(), "confirmation", ""); - - // Low priority - this.setPriority(-100); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public Visibility getVisibility() - { - //return Visibility.INVISIBLE; - return MConf.get().useNewMoneySystem ? Visibility.INVISIBLE : Visibility.SECRET; - } - - @Override - public void perform() throws MassiveException - { - if (MConf.get().useNewMoneySystem) - { - throw new MassiveException().addMsg("The economy system is already converted."); - } - - // Args - if (!this.argIsSet(0)) - { - msg("Money in Factions used to be stored within the applicable economy plugin." + - " This is problematic because not all economy plugins support that." + - " This command allows to convert to the new system where the money of a Faction" + - " is stored within the Factions plugin. Then all economy plugins can be used with Factions."); - } - - ConfirmationUtil.tryConfirm(this); - - MConf.get().useNewMoneySystem = true; - - for (Faction f : FactionColl.get().getAll()) - { - if (!Money.exists(f)) - { - msg("%s does not have any money.", f.getName()); - continue; - } - - double money = Money.get(f); - f.setMoney(money); - - Money.set(f, null, 0); - - msg("%s has %s and has been converted.", f.getName(), Money.format(money)); - } - msg("Converted all factions. Hooray!"); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMotd.java b/src/com/massivecraft/factions/cmd/CmdFactionsMotd.java deleted file mode 100644 index 2d30f543..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMotd.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.event.EventFactionsMotdChange; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.TypeNullable; -import com.massivecraft.massivecore.command.type.primitive.TypeString; -import com.massivecraft.massivecore.mixin.MixinDisplayName; -import com.massivecraft.massivecore.util.MUtil; -import com.massivecraft.massivecore.util.Txt; - -public class CmdFactionsMotd extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsMotd() - { - // Parameters - this.addParameter(TypeNullable.get(TypeString.get()), "new", "read", true).setDesc("the new motd\nif not specified you will just see the current one"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Read - if (!this.argIsSet(0)) - { - message(msenderFaction.getMotdMessages()); - return; - } - - // MPerm - if (!MPerm.getPermMotd().has(msender, msenderFaction, true)) return; - - // Args - String target = this.readArg(); - - if (target != null) - { - target = target.trim(); - target = Txt.parse(target); - } - - // Get Old - String old = msenderFaction.getMotd(); - - // NoChange - if (MUtil.equals(old, target)) - { - msg("The motd for %s is already: %s", msenderFaction.describeTo(msender, true), msenderFaction.getMotdDesc()); - return; - } - - // Event - EventFactionsMotdChange event = new EventFactionsMotdChange(sender, msenderFaction, target); - event.run(); - if (event.isCancelled()) return; - target = event.getNewMotd(); - - // Apply - msenderFaction.setMotd(target); - - // Inform - for (MPlayer follower : msenderFaction.getMPlayers()) - { - follower.msg("%s changed your faction motd.", MixinDisplayName.get().getDisplayName(sender, follower)); - follower.message(msenderFaction.getMotdMessages()); - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsName.java b/src/com/massivecraft/factions/cmd/CmdFactionsName.java deleted file mode 100644 index 7542d1c3..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsName.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.cmd.type.TypeFactionNameLenient; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.event.EventFactionsNameChange; -import com.massivecraft.massivecore.MassiveException; - -public class CmdFactionsName extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsName() - { - // Parameters - this.addParameter(TypeFactionNameLenient.get(), "new name").setDesc("the new name of the faction"); - this.addParameter(TypeFaction.get(), "faction", "you").setDesc("the faction whose name to change"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - String newName = this.readArg(); - Faction faction = this.readArg(msenderFaction); - - // MPerm - if ( ! MPerm.getPermName().has(msender, faction, true)) return; - - // Event - EventFactionsNameChange event = new EventFactionsNameChange(sender, faction, newName); - event.run(); - if (event.isCancelled()) return; - newName = event.getNewName(); - - // Apply - faction.setName(newName); - - // Inform - faction.msg("%s changed your faction name to %s", msender.describeTo(faction, true), faction.getName(faction)); - if (msenderFaction != faction) - { - msg("You changed the faction name to %s", faction.getName(msender)); - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsOverride.java b/src/com/massivecraft/factions/cmd/CmdFactionsOverride.java deleted file mode 100644 index a2326e4f..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsOverride.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Factions; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.primitive.TypeBooleanYes; -import com.massivecraft.massivecore.util.IdUtil; -import com.massivecraft.massivecore.util.Txt; - -public class CmdFactionsOverride extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsOverride() - { - // Aliases - this.addAliases("admin"); - - // Parameters - this.addParameter(TypeBooleanYes.get(), "on/off", "flip"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - boolean target = this.readArg( ! msender.isOverriding()); - - // Apply - msender.setOverriding(target); - - // Inform - String desc = Txt.parse(msender.isOverriding() ? "ENABLED" : "DISABLED"); - - String messageYou = Txt.parse("%s %s override mode.", msender.getDisplayName(msender), desc); - String messageLog = Txt.parse("%s %s override mode.", msender.getDisplayName(IdUtil.getConsole()), desc); - - msender.message(messageYou); - Factions.get().log(messageLog); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java b/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java deleted file mode 100644 index 5650810b..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.massivecraft.factions.cmd; - -public class CmdFactionsPerm extends FactionsCommand -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - CmdFactionsPermList cmdFactionsPermList = new CmdFactionsPermList(); - CmdFactionsPermShow cmdFactionsPermShow = new CmdFactionsPermShow(); - CmdFactionsPermView cmdFactionsPermView = new CmdFactionsPermView(); - CmdFactionsPermViewall cmdFactionsPermViewall = new CmdFactionsPermViewall(); - CmdFactionsPermSet cmdFactionsPermSet = new CmdFactionsPermSet(); - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPermList.java b/src/com/massivecraft/factions/cmd/CmdFactionsPermList.java deleted file mode 100644 index f6ea0f3f..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPermList.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.MPermColl; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.Parameter; -import com.massivecraft.massivecore.pager.Pager; -import com.massivecraft.massivecore.pager.Stringifier; -import org.bukkit.Bukkit; - -import java.util.List; -import java.util.function.Predicate; - -public class CmdFactionsPermList extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsPermList() - { - // Parameters - this.addParameter(Parameter.getPage()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Parameter - int page = this.readArg(); - - // Pager create - String title = String.format("Perms for %s", msenderFaction.describeTo(msender)); - final Pager pager = new Pager<>(this, title, page, (Stringifier) (mp, i) -> mp.getDesc(true, true)); - final Predicate predicate = msender.isOverriding() ? null : MPerm::isVisible; - - Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> { - // Get items - List items = MPermColl.get().getAll(predicate); - - // Pager items - pager.setItems(items); - - // Pager message - pager.message(); - }); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPermSet.java b/src/com/massivecraft/factions/cmd/CmdFactionsPermSet.java deleted file mode 100644 index c2bc270d..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPermSet.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.cmd.type.TypeMPerm; -import com.massivecraft.factions.cmd.type.TypeMPermable; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.event.EventFactionsPermChange; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.primitive.TypeBooleanYes; -import com.massivecraft.massivecore.util.Txt; - -public class CmdFactionsPermSet extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsPermSet() - { - // Parameters - this.addParameter(TypeMPerm.get(), "perm"); - this.addParameter(TypeMPermable.get(), "rank/rel/player/faction"); - this.addParameter(TypeBooleanYes.get(), "yes/no"); - this.addParameter(TypeFaction.get(), "faction", "you"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - MPerm perm = this.readArgAt(0); - Boolean value = this.readArgAt(2); - Faction faction = this.readArgAt(3, msenderFaction); - - MPerm.MPermable permable = TypeMPermable.get(faction).read(this.argAt(1), sender); - - // Do the sender have the right to change perms for this faction? - if ( ! MPerm.getPermPerms().has(msender, faction, true)) return; - - // Is this perm editable? - if ( ! msender.isOverriding() && ! perm.isEditable()) - { - throw new MassiveException().addMsg("The perm %s is not editable.", perm.getName()); - } - - if (permable == faction) - { - throw new MassiveException().addMsg("A faction can't have perms for itself. Perhaps try ranks."); - } - - // Event - EventFactionsPermChange event = new EventFactionsPermChange(sender, faction, perm, permable, value); - event.run(); - if (event.isCancelled()) return; - value = event.getNewValue(); - - // Apply - boolean change = faction.setPermitted(permable, perm, value); - - // No change - if (!change) - { - throw new MassiveException().addMsg("%s already has %s set to %s for %s.", faction.describeTo(msender), perm.getDesc(true, false), Txt.parse(value ? "YES" : "NOO"), permable.getDisplayName(msender)); - } - - // The following is to make sure the leader always has the right to change perms if that is our goal. - if (perm == MPerm.getPermPerms() && MConf.get().perm2default.get(MPerm.ID_PERMS).contains("LEADER")) - { - faction.setPermitted( faction.getLeaderRank(), MPerm.getPermPerms(), true); - } - - // Inform sender - String yesNo = Txt.parse(value ? "YES" : "NOO"); - msg("Set perm %s to %s for %s in %s.", perm.getName(), yesNo, permable.getDisplayName(msender), faction.describeTo(msender)); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPermShow.java b/src/com/massivecraft/factions/cmd/CmdFactionsPermShow.java deleted file mode 100644 index d919ed08..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPermShow.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.cmd.type.TypeMPerm; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.MPerm.MPermable; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.collections.MassiveList; -import com.massivecraft.massivecore.util.Txt; - -import java.util.Collection; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -public class CmdFactionsPermShow extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsPermShow() - { - // Parameters - this.addParameter(TypeMPerm.get(), "perm"); - this.addParameter(TypeFaction.get(), "faction", "you"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Arg: Faction - MPerm mperm = this.readArg(); - Faction faction = this.readArg(msenderFaction); - - Set permittedIds = faction.getPerms().get(mperm.getId()); - List permables = new MassiveList<>(); - - for (String permitted : permittedIds) - { - permables.add(MPerm.idToMPermable(permitted)); - } - - String removeString = Txt.parse(" of ") + faction.getDisplayName(msender); - List permableList = permables.stream() - .map(permable -> permable.getDisplayName(msender)) - .map(s -> s.replace(removeString, "")) - .collect(Collectors.toList()); - String permableNames = Txt.implodeCommaAnd(permableList, Txt.parse("")); - - // Create messages - msg("In %s permission %s is granted to %s.", faction.describeTo(msender), mperm.getDesc(true, false), permableNames); - } - - @Deprecated - public static MPerm.MPermable idToMPermable(String id) - { - return MPerm.idToMPermable(id); - } - - public static String permablesToDisplayString(Collection permables, Object watcherObject) - { - MPlayer mplayer = MPlayer.get(watcherObject); - Faction faction = mplayer.getFaction(); - - String removeString; - if (faction.isNone()) removeString = ""; - else removeString = Txt.parse(" of ") + faction.getDisplayName(mplayer); - - List permableList = permables.stream() - .map(permable -> permable.getDisplayName(mplayer)) - .map(s -> s.replace(removeString, "")) - .collect(Collectors.toList()); - - return Txt.implodeCommaAnd(permableList, Txt.parse("")); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPermView.java b/src/com/massivecraft/factions/cmd/CmdFactionsPermView.java deleted file mode 100644 index 10af058a..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPermView.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.cmd.type.TypeMPermable; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.entity.Rank; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.collections.MassiveList; -import com.massivecraft.massivecore.mson.Mson; -import com.massivecraft.massivecore.util.MUtil; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.ChatColor; - -import java.util.List; -import java.util.stream.Collectors; - -public class CmdFactionsPermView extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsPermView() - { - // Parameters - this.addParameter(TypeMPermable.get(), "rank/rel/player/faction"); - this.addParameter(TypeFaction.get(), "faction", "you"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Arg: Faction - Faction faction = this.readArgAt(1, msenderFaction); - TypeMPermable permableType = TypeMPermable.get(faction); - MPerm.MPermable permable = permableType.read(this.argAt(0), sender); - - if (permable == faction) - { - throw new MassiveException().addMsg("A faction can't have perms for itself."); - } - - List perms = new MassiveList<>(); - - for (MPerm mperm : MPerm.getAll()) - { - if (faction.isPermitted(permable.getId(), mperm.getId())) perms.add(mperm); - } - - if (perms.isEmpty()) - { - msg("In %s %s specifically has no permissions.", faction.describeTo(msender), permable.getDisplayName(sender)); - } - else - { - List permNames = perms.stream().map(perm -> Txt.parse("") + perm.getName()).collect(Collectors.toList()); - String names = Txt.implodeCommaAnd(permNames, Txt.parse("")); - - // Create messages - String permissionSingularPlural = permNames.size() == 1 ? "permission" : "permissions"; - msg("In %s %s specifically has the %s: %s.", faction.describeTo(msender), permable.getDisplayName(sender), permissionSingularPlural, names); - } - if (permable instanceof MPlayer) - { - MPlayer mplayer = (MPlayer) permable; - msg("They may have other permissions through their faction membership, rank or relation to %s.", faction.describeTo(msender)); - - List msons = new MassiveList<>(); - - if (mplayer.getFaction() != faction) msons.add(Mson.parse("[faction]").command(this, mplayer.getFaction().getName(), faction.getName())); - msons.add(Mson.parse("[rank]").command(this, mplayer.getFaction().getName() + "-" + mplayer.getRank().getName(), faction.getName())); - if (mplayer.getFaction() != faction) msons.add(Mson.parse("[relation]").command(this, faction.getRelationTo(mplayer).toString(), faction.getName())); - Mson msons2 = Mson.implode(msons, Mson.SPACE); - message(mson(mson("Commands: ").color(ChatColor.YELLOW), msons2)); - } - if (permable instanceof Faction) - { - Faction faction1 = (Faction) permable; - msg("They may have other permissions through their relation to %s.", faction.describeTo(msender)); - Mson msonRelation = Mson.parse("[relation]").command(this, faction.getRelationTo(faction1).toString(), faction.getName()); - Mson msons = Mson.implode(MUtil.list(msonRelation), Mson.SPACE); - message(mson(mson("Commands: ").color(ChatColor.YELLOW), msons)); - } - if (permable instanceof Rank && !faction.hasRank((Rank) permable)) - { - Rank rank = (Rank) permable; - msg("They may have other permissions thorugh their faction membership or relation to %s.", faction.describeTo(msender)); - Mson msonFaction = Mson.parse("[faction]").command(this, rank.getFaction().getName(), faction.getName()); - Mson msonRelation = Mson.parse("[relation]").command(this, faction.getRelationTo(rank.getFaction()).toString(), faction.getName()); - Mson msons = Mson.implode(MUtil.list(msonFaction, msonRelation), Mson.SPACE); - message(mson(mson("Commands: ").color(ChatColor.YELLOW), msons)); - } - msg("To view all perms held by %s type:", permable.getDisplayName(sender)); - message(CmdFactions.get().cmdFactionsPerm.cmdFactionsPermViewall.getTemplateWithArgs(sender, MUtil.list(permable.getName(), faction.getName()))); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPermViewall.java b/src/com/massivecraft/factions/cmd/CmdFactionsPermViewall.java deleted file mode 100644 index cf801a15..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPermViewall.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.cmd.type.TypeMPermable; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.MPerm.MPermable; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.entity.Rank; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.collections.MassiveList; -import com.massivecraft.massivecore.util.Txt; - -import java.util.List; -import java.util.stream.Collectors; - -public class CmdFactionsPermViewall extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsPermViewall() - { - // Parameters - this.addParameter(TypeMPermable.get(), "rank/rel/player/faction"); - this.addParameter(TypeFaction.get(), "faction", "you"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Arg: Faction - Faction faction = this.readArgAt(1, msenderFaction); - TypeMPermable permableType = TypeMPermable.get(faction); - MPerm.MPermable permable = permableType.read(this.argAt(0), sender); - - // Self check - if (permable == faction) - { - throw new MassiveException().addMsg("A faction can't have perms for itself."); - } - - // Create list of all applicable permables - List permables = new MassiveList<>(); - permables.add(permable); - - if (permable instanceof MPlayer) - { - MPlayer mplayer = (MPlayer) permable; - permables.add(mplayer.getFaction()); - permables.add(mplayer.getRank()); - permables.add(faction.getRelationTo(mplayer)); - } - if (permable instanceof Faction) - { - Faction faction1 = (Faction) permable; - permables.add(faction.getRelationTo(faction1)); - } - if (permable instanceof Rank && !faction.hasRank((Rank) permable)) - { - Rank rank = (Rank) permable; - Faction faction1 = rank.getFaction(); - permables.add(faction1); - permables.add(faction.getRelationTo(faction1)); - } - - // Find the perms they have - List perms = new MassiveList<>(); - - perm: - for (MPerm mperm : MPerm.getAll()) - { - String mpermId = mperm.getId(); - permable: - for (MPermable mpa : permables) - { - if (!faction.isPermitted(mpa.getId(), mperm.getId())) continue permable; - perms.add(mperm); - continue perm; - } - - } - - if (perms.isEmpty()) - { - msg("In %s %s has no permissions.", faction.describeTo(msender), permable.getDisplayName(sender)); - } - else - { - List permNames = perms.stream().map(perm -> Txt.parse("") + perm.getName()).collect(Collectors.toList()); - String names = Txt.implodeCommaAnd(permNames, Txt.parse("")); - - // Create messages - String permissionSingularPlural = permNames.size() == 1 ? "permission" : "permissions"; - msg("In %s %s has the %s: %s either specifically granted to them or through rank, relation or faction membership.", faction.describeTo(msender), permable.getDisplayName(sender), permissionSingularPlural, names); - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPlayer.java b/src/com/massivecraft/factions/cmd/CmdFactionsPlayer.java deleted file mode 100644 index 61f08e05..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPlayer.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeMPlayer; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.Progressbar; -import com.massivecraft.massivecore.event.EventMassiveCorePlayerCleanInactivityToleranceMillis; -import com.massivecraft.massivecore.util.TimeDiffUtil; -import com.massivecraft.massivecore.util.TimeUnit; -import com.massivecraft.massivecore.util.Txt; - -import java.util.LinkedHashMap; -import java.util.Map.Entry; - -public class CmdFactionsPlayer extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsPlayer() - { - // Parameters - this.addParameter(TypeMPlayer.get(), "player", "you"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - MPlayer mplayer = this.readArg(msender); - - // INFO: Title - message(Txt.titleize("Player " + mplayer.describeTo(msender))); - - // INFO: Rank - msg("Rank: %s", mplayer.getRank().getDisplayName(sender)); - - // INFO: Power (as progress bar) - double progressbarQuota = 0; - double playerPowerMax = mplayer.getPowerMax(); - if (playerPowerMax != 0) - { - progressbarQuota = mplayer.getPower() / playerPowerMax; - } - - int progressbarWidth = (int) Math.round(mplayer.getPowerMax() / mplayer.getPowerMaxUniversal() * 100); - msg("Power: %s", Progressbar.HEALTHBAR_CLASSIC.withQuota(progressbarQuota).withWidth(progressbarWidth).render()); - - // INFO: Power (as digits) - msg("Power: %.2f / %.2f", mplayer.getPower(), mplayer.getPowerMax()); - - // INFO: Power Boost - if (mplayer.hasPowerBoost()) - { - double powerBoost = mplayer.getPowerBoost(); - String powerBoostType = (powerBoost > 0 ? "bonus" : "penalty"); - msg("Power Boost: %f (a manually granted %s)", powerBoost, powerBoostType); - } - - // INFO: Power per Hour - // If the player is not at maximum we wan't to display how much time left. - - String stringTillMax = ""; - double powerTillMax = mplayer.getPowerMax() - mplayer.getPower(); - if (powerTillMax > 0) - { - long millisTillMax = (long) (powerTillMax * TimeUnit.MILLIS_PER_HOUR / mplayer.getPowerPerHour()); - LinkedHashMap unitcountsTillMax = TimeDiffUtil.unitcounts(millisTillMax, TimeUnit.getAllButMillis()); - unitcountsTillMax = TimeDiffUtil.limit(unitcountsTillMax, 2); - String unitcountsTillMaxFormated = TimeDiffUtil.formatedVerboose(unitcountsTillMax, ""); - stringTillMax = Txt.parse(" (%s left till max)", unitcountsTillMaxFormated); - } - - msg("Power per Hour: %.2f%s", mplayer.getPowerPerHour(), stringTillMax); - - // INFO: Power per Death - msg("Power per Death: %.2f", mplayer.getPowerPerDeath()); - - // Display automatic kick / remove info if the system is in use - if (MConf.get().cleanInactivityToleranceMillis <= 0) return; - - EventMassiveCorePlayerCleanInactivityToleranceMillis event = new EventMassiveCorePlayerCleanInactivityToleranceMillis(mplayer.getLastActivityMillis(), mplayer); - event.run(); - msg("Automatic removal after %s of inactivity:", format(event.getToleranceMillis())); - for (Entry causeMillis : event.getToleranceCauseMillis().entrySet()) - { - String cause = causeMillis.getKey(); - long millis = causeMillis.getValue(); - msg("%s: %s", cause, format(millis)); - } - } - - // -------------------------------------------- // - // TIME FORMAT - // -------------------------------------------- // - - public static String format(long millis) - { - LinkedHashMap unitcounts = TimeDiffUtil.unitcounts(millis, TimeUnit.getAllBut(TimeUnit.MILLISECOND, TimeUnit.WEEK, TimeUnit.MONTH)); - return TimeDiffUtil.formatedVerboose(unitcounts); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboost.java b/src/com/massivecraft/factions/cmd/CmdFactionsPowerboost.java deleted file mode 100644 index cd4a3d38..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboost.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.massivecraft.factions.cmd; - -public class CmdFactionsPowerboost extends FactionsCommand -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public CmdFactionsPowerboostPlayer cmdFactionsPowerBoostPlayer = new CmdFactionsPowerboostPlayer(); - public CmdFactionsPowerboostFaction cmdFactionsPowerBoostFaction = new CmdFactionsPowerboostFaction(); - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsPowerboost() - { - // Child - this.addChild(this.cmdFactionsPowerBoostPlayer); - this.addChild(this.cmdFactionsPowerBoostFaction); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostAbstract.java b/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostAbstract.java deleted file mode 100644 index 4317d07f..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostAbstract.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.FactionsParticipator; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.Type; -import com.massivecraft.massivecore.command.type.primitive.TypeDouble; -import com.massivecraft.massivecore.util.Txt; - -public abstract class CmdFactionsPowerboostAbstract extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - protected CmdFactionsPowerboostAbstract(Type parameterType, String parameterName) - { - // Parameters - this.addParameter(parameterType, parameterName); - if (!this.getClass().getSimpleName().contains("Show")) - { - this.addParameter(TypeDouble.get(), "amount"); - } - } - - // -------------------------------------------- // - // ABSTRACT - // -------------------------------------------- // - - public abstract double calcNewPowerboost(double current, double d); - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Parameters - FactionsParticipator factionsParticipator = this.readArg(); - - boolean updated = false; - // Try set the powerBoost - if (this.argIsSet(1)) - { - // Yes updated - updated = true; - - // Calc powerboost - double current = factionsParticipator.getPowerBoost(); - double number = this.readArg(); - double powerBoost = this.calcNewPowerboost(current, number); - - // Set - factionsParticipator.setPowerBoost(powerBoost); - } - - // Inform - this.informPowerBoost(factionsParticipator, updated); - } - - private void informPowerBoost(FactionsParticipator factionsParticipator, boolean updated) - { - // Prepare - Double powerBoost = factionsParticipator.getPowerBoost(); - String participatorDescribe = factionsParticipator.describeTo(msender, true); - String powerDescription = Txt.parse(Double.compare(powerBoost, 0D) >= 0 ? "bonus" : "penalty"); - String when = updated ? "now " : ""; - String verb = factionsParticipator.equals(msender) ? "have" : "has"; - - // Create message - String messagePlayer = Txt.parse("%s %s%s a power %s of %.2f to min and max power levels.", participatorDescribe, when, verb, powerDescription, powerBoost); - String messageLog = Txt.parse("%s %s set the power %s for %s to %.2f.", msender.getName(), verb, powerDescription, factionsParticipator.getName(), powerBoost); - - // Inform - msender.message(messagePlayer); - if (updated) Factions.get().log(messageLog); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostFaction.java b/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostFaction.java deleted file mode 100644 index b489b900..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostFaction.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.massivecraft.factions.cmd; - -public class CmdFactionsPowerboostFaction extends FactionsCommand -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public CmdFactionsPowerboostFactionShow cmdFactionsPowerBoostFactionShow = new CmdFactionsPowerboostFactionShow(); - public CmdFactionsPowerboostFactionSet cmdFactionsPowerBoostFactionSet = new CmdFactionsPowerboostFactionSet(); - public CmdFactionsPowerboostFactionAdd cmdFactionsPowerBoostFactionAdd = new CmdFactionsPowerboostFactionAdd(); - public CmdFactionsPowerboostFactionTake cmdFactionsPowerBoostFactionTake = new CmdFactionsPowerboostFactionTake(); - public CmdFactionsPowerboostFactionMultiply cmdFactionsPowerBoostFactionMultiply = new CmdFactionsPowerboostFactionMultiply(); - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionAbstract.java b/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionAbstract.java deleted file mode 100644 index 0f42212d..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionAbstract.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeFaction; - -public abstract class CmdFactionsPowerboostFactionAbstract extends CmdFactionsPowerboostAbstract -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsPowerboostFactionAbstract() - { - super(TypeFaction.get(), "faction"); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionAdd.java b/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionAdd.java deleted file mode 100644 index 2b6ec876..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionAdd.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.massivecraft.factions.cmd; - -public class CmdFactionsPowerboostFactionAdd extends CmdFactionsPowerboostFactionAbstract -{ - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public double calcNewPowerboost(double current, double d) - { - return current + d; - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionMultiply.java b/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionMultiply.java deleted file mode 100644 index a30de437..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionMultiply.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.massivecraft.factions.cmd; - -public class CmdFactionsPowerboostFactionMultiply extends CmdFactionsPowerboostFactionAbstract -{ - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public double calcNewPowerboost(double current, double d) - { - return current * d; - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionSet.java b/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionSet.java deleted file mode 100644 index 772c8b51..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionSet.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.massivecraft.factions.cmd; - -public class CmdFactionsPowerboostFactionSet extends CmdFactionsPowerboostFactionAbstract -{ - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public double calcNewPowerboost(double current, double d) - { - return d; - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionShow.java b/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionShow.java deleted file mode 100644 index b29f2682..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionShow.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.massivecraft.factions.cmd; - -public class CmdFactionsPowerboostFactionShow extends CmdFactionsPowerboostFactionAbstract -{ - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public double calcNewPowerboost(double current, double d) - { - throw new UnsupportedOperationException(); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionTake.java b/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionTake.java deleted file mode 100644 index 8b4262e5..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionTake.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.massivecraft.factions.cmd; - -public class CmdFactionsPowerboostFactionTake extends CmdFactionsPowerboostFactionAbstract -{ - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public double calcNewPowerboost(double current, double d) - { - return current - d; - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayer.java b/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayer.java deleted file mode 100644 index 45276eeb..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayer.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.massivecraft.factions.cmd; - -public class CmdFactionsPowerboostPlayer extends FactionsCommand -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public CmdFactionsPowerboostPlayerShow cmdFactionsPowerBoostPlayerShow = new CmdFactionsPowerboostPlayerShow(); - public CmdFactionsPowerboostPlayerSet cmdFactionsPowerBoostPlayerSet = new CmdFactionsPowerboostPlayerSet(); - public CmdFactionsPowerboostPlayerAdd cmdFactionsPowerBoostPlayerAdd = new CmdFactionsPowerboostPlayerAdd(); - public CmdFactionsPowerboostPlayerTake cmdFactionsPowerBoostPlayerTake = new CmdFactionsPowerboostPlayerTake(); - public CmdFactionsPowerboostPlayerMultiply cmdFactionsPowerBoostPlayerMultiply = new CmdFactionsPowerboostPlayerMultiply(); - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerAbstract.java b/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerAbstract.java deleted file mode 100644 index 9f952576..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerAbstract.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeMPlayer; - -public abstract class CmdFactionsPowerboostPlayerAbstract extends CmdFactionsPowerboostAbstract -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsPowerboostPlayerAbstract() - { - super(TypeMPlayer.get(), "player"); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerAdd.java b/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerAdd.java deleted file mode 100644 index 558efb7a..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerAdd.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.massivecraft.factions.cmd; - -public class CmdFactionsPowerboostPlayerAdd extends CmdFactionsPowerboostPlayerAbstract -{ - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public double calcNewPowerboost(double current, double d) - { - return current + d; - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerMultiply.java b/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerMultiply.java deleted file mode 100644 index 466e4692..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerMultiply.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.massivecraft.factions.cmd; - -public class CmdFactionsPowerboostPlayerMultiply extends CmdFactionsPowerboostPlayerAbstract -{ - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public double calcNewPowerboost(double current, double d) - { - return current * d; - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerSet.java b/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerSet.java deleted file mode 100644 index c04fb51e..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerSet.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.massivecraft.factions.cmd; - -public class CmdFactionsPowerboostPlayerSet extends CmdFactionsPowerboostPlayerAbstract -{ - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public double calcNewPowerboost(double current, double d) - { - return d; - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerShow.java b/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerShow.java deleted file mode 100644 index 6a52ca02..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerShow.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.massivecraft.factions.cmd; - -public class CmdFactionsPowerboostPlayerShow extends CmdFactionsPowerboostPlayerAbstract -{ - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public double calcNewPowerboost(double current, double d) - { - throw new UnsupportedOperationException(); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerTake.java b/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerTake.java deleted file mode 100644 index 2f58e222..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerTake.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.massivecraft.factions.cmd; - -public class CmdFactionsPowerboostPlayerTake extends CmdFactionsPowerboostPlayerAbstract -{ - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public double calcNewPowerboost(double current, double d) - { - return current - d; - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRank.java b/src/com/massivecraft/factions/cmd/CmdFactionsRank.java deleted file mode 100644 index 9d466b3c..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRank.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.massivecraft.factions.cmd; - -public class CmdFactionsRank extends FactionsCommand -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public CmdFactionsRankSet cmdFactionsRankSet = new CmdFactionsRankSet(); - public CmdFactionsRankShow cmdFactionsRankShow = new CmdFactionsRankShow(); - public CmdFactionsRankList cmdFactionsRankList = new CmdFactionsRankList(); - public CmdFactionsRankEdit cmdFactionsRankEdit = new CmdFactionsRankEdit(); - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRankEdit.java b/src/com/massivecraft/factions/cmd/CmdFactionsRankEdit.java deleted file mode 100644 index 35a74c50..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRankEdit.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.MassiveException; - -public class CmdFactionsRankEdit extends FactionsCommand -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public CmdFactionsRankEditCreate cmdFactionsRankEditCreate = new CmdFactionsRankEditCreate(); - public CmdFactionsRankEditDelete cmdFactionsRankEditDelete = new CmdFactionsRankEditDelete(); - public CmdFactionsRankEditName cmdFactionsRankEditName = new CmdFactionsRankEditName(); - public CmdFactionsRankEditPrefix cmdFactionsRankEditPrefix = new CmdFactionsRankEditPrefix(); - public CmdFactionsRankEditPriority cmdFactionsRankEditPriority = new CmdFactionsRankEditPriority(); - - static void ensureAllowed(MPlayer msender, Faction faction, String action) throws MassiveException - { - if (msender.isOverriding()) return; - - if (faction != msender.getFaction()) - { - throw new MassiveException().addMsg("You can't manage ranks outside your own faction."); - } - - if (!msender.getRank().isLeader()) - { - throw new MassiveException().addMsg("Only the leader can %s ranks.", action); - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRankEditCreate.java b/src/com/massivecraft/factions/cmd/CmdFactionsRankEditCreate.java deleted file mode 100644 index e9a0a908..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRankEditCreate.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.Rank; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.primitive.TypeInteger; -import com.massivecraft.massivecore.command.type.primitive.TypeString; -import com.massivecraft.massivecore.command.type.primitive.TypeStringParsed; - -import java.util.Collection; - -public class CmdFactionsRankEditCreate extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsRankEditCreate() - { - // Parameters - this.addParameter(TypeString.get(), "name"); - this.addParameter(TypeInteger.get(), "priority"); - this.addParameter("", TypeStringParsed.get(), "prefix", "none"); - this.addParameter(TypeFaction.get(), "faction", "you"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - String name = this.readArg(); - Integer priority = this.readArg(); - String prefix = this.readArg(); - Faction faction = this.readArg(msenderFaction); - - CmdFactionsRankEdit.ensureAllowed(msender, faction, "create"); - - Collection ranks = faction.getRanks().getAll(); - - if (ranks.stream().map(Rank::getName).anyMatch(s -> s.equalsIgnoreCase(name))) - { - throw new MassiveException().addMsg("There is already a rank called %s.", name); - } - if (ranks.stream().map(Rank::getPriority).anyMatch(i -> i.equals(priority))) - { - throw new MassiveException().addMsg("There is already a rank with priority %s.", priority); - } - if (priority > faction.getLeaderRank().getPriority()) - { - throw new MassiveException().addMsg("You can't create a rank of higher priority than the leader rank."); - } - - Rank rank = new Rank(name, priority, prefix); - - faction.getRanks().attach(rank); - - // Inform - msg("You created the rank %s.", rank.getVisual()); - msg("You might want to change its permissions:"); - CmdFactions.get().cmdFactionsPerm.getTemplate(false, true, sender).messageOne(msender); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRankEditDelete.java b/src/com/massivecraft/factions/cmd/CmdFactionsRankEditDelete.java deleted file mode 100644 index f0a43faf..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRankEditDelete.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.cmd.type.TypeRank; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.entity.Rank; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.primitive.TypeString; -import com.massivecraft.massivecore.util.Txt; - -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; - -public class CmdFactionsRankEditDelete extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsRankEditDelete() - { - // Parameters - this.addParameter(TypeString.get(), "rank"); - this.addParameter(TypeFaction.get(), "faction", "you"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - Faction faction = this.readArgAt(1, msenderFaction); - - // Rank if any passed. - TypeRank typeRank = new TypeRank(faction); - Rank rank = typeRank.read(this.argAt(0), sender); - - CmdFactionsRankEdit.ensureAllowed(msender, faction, "delete"); - - Collection ranks = faction.getRanks().getAll(); - if (ranks.size() <= 2) - { - throw new MassiveException().addMsg("A faction must have at least two ranks."); - } - - List mplayers = faction.getMPlayersWhereRank(rank); - if (!mplayers.isEmpty()) - { - int count = mplayers.size(); - List names = mplayers.stream().map(m -> m.getDisplayName(sender)).collect(Collectors.toList()); - String namesDesc = Txt.implodeCommaAnd(names, Txt.parse("")); - String rankRanks = count == 1 ? "rank" : "ranks"; - throw new MassiveException().addMsg("This rank is held by %s change their %s first.", namesDesc, rankRanks); - } - - String visual = rank.getVisual(); - faction.getRanks().detachEntity(rank); - - // Inform - msg("You deleted the rank %s.", visual); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRankEditName.java b/src/com/massivecraft/factions/cmd/CmdFactionsRankEditName.java deleted file mode 100644 index a9327fd3..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRankEditName.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.cmd.type.TypeRank; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.Rank; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.primitive.TypeString; - -import java.util.Collection; - -public class CmdFactionsRankEditName extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsRankEditName() - { - // Parameters - this.addParameter(TypeRank.get(), "rank"); - this.addParameter(TypeString.get(), "new name"); - this.addParameter(TypeFaction.get(), "faction", "you"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - String name = this.readArgAt(1); - Faction faction = this.readArgAt(2, msenderFaction); - - // Rank if any passed. - TypeRank typeRank = new TypeRank(faction); - Rank rank = typeRank.read(this.argAt(0), sender); - - // Args - - CmdFactionsRankEdit.ensureAllowed(msender, faction, "rename"); - - Collection ranks = faction.getRanks().getAll(); - - if (ranks.stream().map(Rank::getName).anyMatch(s -> s.equalsIgnoreCase(name))) - { - throw new MassiveException().addMsg("There is already a rank called %s.", name); - } - - String priorVisual = rank.getVisual(); - rank.setName(name); - - // Visual - msg("You renamed the rank from %s to %s.", priorVisual, rank.getVisual()); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRankEditPrefix.java b/src/com/massivecraft/factions/cmd/CmdFactionsRankEditPrefix.java deleted file mode 100644 index 7470b1da..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRankEditPrefix.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.cmd.type.TypeRank; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.Rank; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.primitive.TypeString; - -public class CmdFactionsRankEditPrefix extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsRankEditPrefix() - { - // Parameters - this.addParameter(TypeRank.get(), "rank"); - this.addParameter(TypeString.get(), "new prefix"); - this.addParameter(TypeFaction.get(), "faction", "you"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - String prefix = this.readArgAt(1); - Faction faction = this.readArgAt(2, msenderFaction); - - // Rank if any passed. - TypeRank typeRank = new TypeRank(faction); - Rank rank = typeRank.read(this.argAt(0), sender); - - // Args - - CmdFactionsRankEdit.ensureAllowed(msender, faction, "edit"); - - String priorPrefix = rank.getPrefix(); - rank.setPrefix(prefix); - - // Visual - msg("You changed the prefix of %s from %s to %s.", rank.getVisual(), priorPrefix, prefix); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRankEditPriority.java b/src/com/massivecraft/factions/cmd/CmdFactionsRankEditPriority.java deleted file mode 100644 index f9823f25..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRankEditPriority.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.cmd.type.TypeRank; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.Rank; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.primitive.TypeInteger; - -import java.util.Collection; - -public class CmdFactionsRankEditPriority extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsRankEditPriority() - { - // Parameters - this.addParameter(TypeRank.get(), "rank"); - this.addParameter(TypeInteger.get(), "new priority"); - this.addParameter(TypeFaction.get(), "faction", "you"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - Integer priority = this.readArgAt(1); - Faction faction = this.readArgAt(2, msenderFaction); - - // Rank if any passed. - TypeRank typeRank = new TypeRank(faction); - Rank rank = typeRank.read(this.argAt(0), sender); - - CmdFactionsRankEdit.ensureAllowed(msender, faction, "edit"); - - Collection ranks = faction.getRanks().getAll(); - - if (ranks.stream().map(Rank::getPriority).anyMatch(s -> s.equals(priority))) - { - throw new MassiveException().addMsg("There is already a rank with the priority %s.", priority); - } - - if (rank.isLeader()) - { - Rank below = rank.getRankBelow(); - if (below.getPriority() > priority) - { - throw new MassiveException().addMsg("The leader rank must have the highest priority."); - } - } - else - { - if (priority >= faction.getLeaderRank().getPriority()) - { - throw new MassiveException().addMsg("No rank can have higher priority than the leader rank."); - } - } - - int priorPriority = rank.getPriority(); - rank.setPriority(priority); - - // Visual - msg("You changed the priority of %s from %s to %s.", rank.getVisual(), priorPriority, priority); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRankList.java b/src/com/massivecraft/factions/cmd/CmdFactionsRankList.java deleted file mode 100644 index 0ccdabec..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRankList.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.Rank; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.Parameter; -import com.massivecraft.massivecore.pager.Pager; -import com.massivecraft.massivecore.pager.Stringifier; - -import java.util.Comparator; -import java.util.List; - -public class CmdFactionsRankList extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsRankList() - { - // Parameters - this.addParameter(Parameter.getPage()); - this.addParameter(TypeFaction.get(), "faction", "you"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - final int page = this.readArg(); - Faction faction = this.readArg(msenderFaction); - - List ranks = faction.getRanks().getAll(Comparator.comparingInt(Rank::getPriority).reversed()); - - String title = "Rank list for " + faction.describeTo(msender); - Pager pager = new Pager<>(this, title, page, ranks, (Stringifier) (r, i) -> r.getVisual()); - pager.message(); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRankOld.java b/src/com/massivecraft/factions/cmd/CmdFactionsRankOld.java deleted file mode 100644 index 6ebc9a88..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRankOld.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeMPlayer; -import com.massivecraft.massivecore.command.Visibility; -import com.massivecraft.massivecore.util.MUtil; - -public class CmdFactionsRankOld extends FactionsCommand -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public final String rankName; - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsRankOld(String rank) - { - // Fields - this.rankName = rank.toLowerCase(); - this.setSetupEnabled(false); - - // Aliases - this.addAliases(rankName); - - // Parameters - this.addParameter(TypeMPlayer.get(), "player"); - - // Visibility - this.setVisibility(Visibility.INVISIBLE); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() - { - CmdFactions.get().cmdFactionsRank.cmdFactionsRankSet.execute(sender, MUtil.list( - this.argAt(0), - this.rankName - )); - } - -} \ No newline at end of file diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRankSet.java b/src/com/massivecraft/factions/cmd/CmdFactionsRankSet.java deleted file mode 100644 index 7bbfe374..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRankSet.java +++ /dev/null @@ -1,341 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.cmd.type.TypeMPlayer; -import com.massivecraft.factions.cmd.type.TypeRank; -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.entity.MPlayerColl; -import com.massivecraft.factions.entity.Rank; -import com.massivecraft.factions.event.EventFactionsMembershipChange; -import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; -import com.massivecraft.factions.event.EventFactionsRankChange; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.collections.MassiveSet; -import com.massivecraft.massivecore.util.Txt; - -import java.util.HashSet; -import java.util.Set; - -public class CmdFactionsRankSet extends FactionsCommand -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - // These fields are set upon perform() and unset afterwards. - - // Target - private Faction targetFaction = null; - private MPlayer target = null; - - // End faction (the faction they are changed to) - private Faction endFaction = null; - private boolean factionChange = false; - - // Ranks - private Rank senderRank = null; - private Rank targetRank = null; - private Rank rank = null; - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsRankSet() - { - // Parameters - this.addParameter(TypeMPlayer.get(), "player"); - this.addParameter(TypeRank.get(), "rank"); - this.addParameter(TypeFaction.get(), "faction", "their"); - - // Too complicated for that - this.setSwapping(false); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // This sets target and much other. - this.registerFields(); - - // Is the player allowed or not. Method can be found later down. - this.ensureAllowed(); - - if (factionChange) - { - this.changeFaction(); - } - - // Does the change make sense. - this.ensureMakesSense(); - - // Event - EventFactionsRankChange event = new EventFactionsRankChange(sender, target, rank); - event.run(); - if (event.isCancelled()) return; - rank = event.getNewRank(); - - // Change the rank. - this.changeRank(); - } - - // This is always run after performing a MassiveCommand. - @Override - public void senderFields(boolean set) - { - super.senderFields(set); - - if ( ! set) - { - this.unregisterFields(); - } - } - - // -------------------------------------------- // - // PRIVATE: REGISTER & UNREGISTER - // -------------------------------------------- // - - private void registerFields() throws MassiveException - { - // Getting the target and faction. - target = this.readArg(); - targetFaction = target.getFaction(); - - - // Ranks - senderRank = msender.getRank(); - targetRank = target.getRank(); - - endFaction = this.readArgAt(2, targetFaction); - factionChange = (endFaction != targetFaction); - - // Rank if any passed. - TypeRank typeRank = new TypeRank(endFaction, target.getRank()); - rank = typeRank.read(this.argAt(1), sender); - - } - - private void unregisterFields() - { - targetFaction = null; - target = null; - - endFaction = null; - factionChange = false; - - senderRank = null; - targetRank = null; - rank = null; - } - - // -------------------------------------------- // - // PRIVATE: ENSURE - // -------------------------------------------- // - - private void ensureAllowed() throws MassiveException - { - // People with permission don't follow the normal rules. - if (msender.isOverriding()) return; - - // If somone gets the leadership of wilderness (Which has happened before). - // We can at least try to limit their powers. - if (endFaction.isNone()) - { - throw new MassiveException().addMsg("%s doesn't use ranks sorry :(", endFaction.getName()); - } - - if (target == msender) - { - // Don't change your own rank. - throw new MassiveException().addMsg("The target player mustn't be yourself."); - } - - if (factionChange) - { - // Don't change peoples faction - throw new MassiveException().addMsg("You can't change %s's faction.", target.describeTo(msender)); - } - - if (!MPerm.getPermRank().has(msender, targetFaction, false)) - { - throw new MassiveException().addMessage(MPerm.getPermRank().createDeniedMessage(msender, targetFaction)); - } - - // The following two if statements could be merged. - // But isn't for the sake of nicer error messages. - if (senderRank == targetRank) - { - // You can't change someones rank if it is equal to yours. - throw new MassiveException().addMsg("%s can't manage eachother.", senderRank.getName()+"s"); - } - - if (senderRank.isLessThan(targetRank)) - { - // You can't change someones rank if it is higher than yours. - throw new MassiveException().addMsg("You can't manage people of higher rank."); - } - - // The following two if statements could be merged. - // But isn't for the sake of nicer error messages. - if (senderRank == rank && !senderRank.isLeader()) - { - // You can't set ranks equal to your own. Unless you are the leader. - throw new MassiveException().addMsg("You can't set ranks equal to your own."); - } - - if (senderRank.isLessThan(rank)) - { - // You can't set ranks higher than your own. - throw new MassiveException().addMsg("You can't set ranks higher than your own."); - } - } - - private void ensureMakesSense() throws MassiveException - { - // Don't change their rank to something they already are. - if (target.getRank() == rank) - { - throw new MassiveException().addMsg("%s is already %s %s.", target.describeTo(msender), Txt.aan(rank.getName()), rank.getName()); - } - } - - // -------------------------------------------- // - // PRIVATE: CHANGE FACTION - // -------------------------------------------- // - - private void changeFaction() throws MassiveException - { - // Don't change a leader to a new faction. - if (targetRank.isLeader()) - { - throw new MassiveException().addMsg("You cannot remove the present leader. Demote them first."); - } - - // Event - EventFactionsMembershipChange membershipChangeEvent = new EventFactionsMembershipChange(sender, msender, endFaction, MembershipChangeReason.RANK); - membershipChangeEvent.run(); - if (membershipChangeEvent.isCancelled()) throw new MassiveException(); - - // Apply - target.resetFactionData(); - target.setFaction(endFaction); - - // No longer invited. - endFaction.uninvite(target); - - // Create recipients - Set recipients = new HashSet<>(); - recipients.addAll(targetFaction.getMPlayersWhereOnline(true)); - recipients.addAll(endFaction.getMPlayersWhereOnline(true)); - recipients.add(msender); - - // Send message - for (MPlayer recipient : recipients) - { - recipient.msg("%s was moved from %s to %s.", target.describeTo(recipient), targetFaction.describeTo(recipient), endFaction.describeTo(recipient)); - } - - // Derplog - if (MConf.get().logFactionJoin) - { - Factions.get().log(Txt.parse("%s moved %s from %s to %s.", msender.getName(), target.getName(), targetFaction.getName(), endFaction.getName())); - } - - // Now we don't need the old values. - targetFaction = target.getFaction(); - targetRank = target.getRank(); - senderRank = msender.getRank(); // In case they changed their own rank - - } - - // -------------------------------------------- // - // PRIVATE: CHANGE RANK - // -------------------------------------------- // - - private void changeRank() throws MassiveException - { - // In case of leadership change, we do special things not done in other rank changes. - if (rank.isLeader()) - { - this.changeRankLeader(); - } - else - { - this.changeRankOther(); - } - } - - private void changeRankLeader() - { - // If there is a current leader. Demote & inform them. - MPlayer targetFactionCurrentLeader = targetFaction.getLeader(); - if (targetFactionCurrentLeader != null) - { - // Inform & demote the old leader. - targetFactionCurrentLeader.setRank(rank.getRankBelow()); - if (targetFactionCurrentLeader != msender) - { - // They kinda know if they fired the command themself. - targetFactionCurrentLeader.msg("You have been demoted from the position of faction leader by %s.", msender.describeTo(targetFactionCurrentLeader, true)); - } - } - - // Promote the new leader. - target.setRank(rank); - - // Inform everyone, this includes sender and target. - for (MPlayer recipient : MPlayerColl.get().getAllOnline()) - { - String changerName = senderIsConsole ? "A server admin" : msender.describeTo(recipient); - recipient.msg("%s gave %s the leadership of %s.", changerName, target.describeTo(recipient), targetFaction.describeTo(recipient)); - } - } - - private void changeRankOther() throws MassiveException - { - // If the target is currently the leader and faction isn't permanent a new leader should be promoted. - // Sometimes a bug occurs and multiple leaders exist. Then we should be able to demote without promoting new leader - if (targetRank.isLeader() && ( ! MConf.get().permanentFactionsDisableLeaderPromotion || ! targetFaction.getFlag(MFlag.ID_PERMANENT)) && targetFaction.getMPlayersWhereRank(targetFaction.getLeaderRank()).size() == 1) - // This if statement is very long. Should I nest it for readability? - { - targetFaction.promoteNewLeader(); // This might disband the faction. - - // So if the faction disbanded... - if (targetFaction.detached()) - { - // ... we inform the sender. - target.resetFactionData(); - throw new MassiveException().addMsg("The target was a leader and got demoted. The faction disbanded and no rank was set."); - } - } - - // Create recipients - Set recipients = new MassiveSet<>(targetFaction.getMPlayers()); - recipients.add(msender); - - // Were they demoted or promoted? - String change = (rank.isLessThan(targetRank) ? "demoted" : "promoted"); - - // The rank will be set before the msg, so they have the appropriate prefix. - target.setRank(rank); - String oldRankName = targetRank.getName().toLowerCase(); - String rankName = rank.getName().toLowerCase(); - - // Send message - for(MPlayer recipient : recipients) - { - String targetName = target.describeTo(recipient, true); - String wasWere = (recipient == target) ? "were" : "was"; - recipient.msg("%s %s %s from %s to %s in %s.", targetName, wasWere, change, oldRankName, rankName, targetFaction.describeTo(msender)); - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRankShow.java b/src/com/massivecraft/factions/cmd/CmdFactionsRankShow.java deleted file mode 100644 index 14c38af6..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRankShow.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeMPlayer; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.entity.Rank; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.util.Txt; - -public class CmdFactionsRankShow extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsRankShow() - { - // Parameters - this.addParameter(TypeMPlayer.get(), "player"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - MPlayer target = this.readArg(); - Rank rank = target.getRank(); - - // Damn you grammar, causing all these checks. - String targetName = target.describeTo(msender, true); - String isAre = (target == msender) ? "are" : "is"; // "you are" or "he is" - - String theAan = (rank.isLeader()) ? "the" : Txt.aan(rank.getName()); // "a member", "an officer" or "the leader" - String rankName = rank.getName().toLowerCase(); - String ofIn = (rank.isLeader()) ? "of" : "in"; // "member in" or "leader of" - String factionName = target.getFaction().describeTo(msender, true); - if (target.getFaction() == msenderFaction) - { - // Having the "Y" in "Your faction" being uppercase in the middle of a sentence makes no sense. - factionName = factionName.toLowerCase(); - } - if (target.getFaction().isNone()) - { - // Wilderness aka none doesn't use ranks - msg("%s %s factionless", targetName, isAre); - } - else - { - // Derp is a member in Faction - msg("%s %s %s %s %s %s.", targetName, isAre, theAan, rankName, ofIn, factionName); - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRelation.java b/src/com/massivecraft/factions/cmd/CmdFactionsRelation.java deleted file mode 100644 index 6c60d4ad..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRelation.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.massivecraft.factions.cmd; - -public class CmdFactionsRelation extends FactionsCommand -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public CmdFactionsRelationSet cmdFactionsRelationSet = new CmdFactionsRelationSet(); - public CmdFactionsRelationList cmdFactionsRelationList = new CmdFactionsRelationList(); - public CmdFactionsRelationWishes cmdFactionsRelationWishes = new CmdFactionsRelationWishes(); - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRelationList.java b/src/com/massivecraft/factions/cmd/CmdFactionsRelationList.java deleted file mode 100644 index 4068e431..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRelationList.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.Rel; -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.cmd.type.TypeRelation; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.FactionColl; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.collections.MassiveList; -import com.massivecraft.massivecore.collections.MassiveSet; -import com.massivecraft.massivecore.command.Parameter; -import com.massivecraft.massivecore.command.type.container.TypeSet; -import com.massivecraft.massivecore.pager.Pager; -import com.massivecraft.massivecore.pager.Stringifier; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.Bukkit; - -import java.util.List; -import java.util.Map.Entry; -import java.util.Set; - -public class CmdFactionsRelationList extends FactionsCommand -{ - // -------------------------------------------- // - // COSTANTS - // -------------------------------------------- // - - public static final Set RELEVANT_RELATIONS = new MassiveSet<>(Rel.ENEMY, Rel.TRUCE, Rel.ALLY); - public static final String SEPERATOR = Txt.parse(": "); - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsRelationList() - { - // Parameter - this.addParameter(Parameter.getPage()); - this.addParameter(TypeFaction.get(), "faction", "you"); - this.addParameter(TypeSet.get(TypeRelation.get()), "relations", "all"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - int page = this.readArg(); - final Faction faction = this.readArg(msenderFaction); - final Set relations = this.readArg(RELEVANT_RELATIONS); - - // Pager Create - final Pager pager = new Pager<>(this, "", page, (Stringifier) (item, index) -> item); - - Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> { - // Prepare Items - List relNames = new MassiveList<>(); - for (Entry> entry : FactionColl.get().getRelationNames(faction, relations).entrySet()) - { - Rel relation = entry.getKey(); - String coloredName = relation.getColor().toString() + relation.getName(); - - for (String name : entry.getValue()) - { - relNames.add(coloredName + SEPERATOR + name); - } - } - - // Pager Title - pager.setTitle(Txt.parse("%s's Relations (%d)", faction.getName(), relNames.size())); - - // Pager Items - pager.setItems(relNames); - - // Pager Message - pager.message(); - }); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRelationOld.java b/src/com/massivecraft/factions/cmd/CmdFactionsRelationOld.java deleted file mode 100644 index 3a537400..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRelationOld.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.Visibility; -import com.massivecraft.massivecore.util.MUtil; - -public class CmdFactionsRelationOld extends FactionsCommand -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public final String relName; - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsRelationOld(String rel) - { - // Fields - this.relName = rel.toLowerCase(); - this.setSetupEnabled(false); - - // Aliases - this.addAliases(relName); - - // Parameters - this.addParameter(TypeFaction.get(), "faction", true); - - // Visibility - this.setVisibility(Visibility.INVISIBLE); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Arguments - Faction faction = this.readArg(); - - // Apply - CmdFactions.get().cmdFactionsRelation.cmdFactionsRelationSet.execute(sender, MUtil.list( - faction.getId(), - this.relName - )); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRelationSet.java b/src/com/massivecraft/factions/cmd/CmdFactionsRelationSet.java deleted file mode 100644 index 2a02d6f8..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRelationSet.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Rel; -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.cmd.type.TypeRelation; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MFlag; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.event.EventFactionsRelationChange; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.MassiveCommand; -import com.massivecraft.massivecore.mson.Mson; -import org.bukkit.ChatColor; - -public class CmdFactionsRelationSet extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsRelationSet() - { - // Parameter - this.addParameter(TypeFaction.get(), "faction"); - this.addParameter(TypeRelation.get(), "relation"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - Faction otherFaction = this.readArg(); - Rel newRelation = this.readArg(); - - // MPerm - if ( ! MPerm.getPermRel().has(msender, msenderFaction, true)) return; - - // Verify - if (otherFaction == msenderFaction) - { - throw new MassiveException().setMsg("Nope! You can't declare a relation to yourself :)"); - } - if (msenderFaction.getRelationWish(otherFaction) == newRelation) - { - throw new MassiveException().setMsg("You already have that relation wish set with %s.", otherFaction.getName()); - } - - // Event - EventFactionsRelationChange event = new EventFactionsRelationChange(sender, msenderFaction, otherFaction, newRelation); - event.run(); - if (event.isCancelled()) return; - newRelation = event.getNewRelation(); - - // try to set the new relation - msenderFaction.setRelationWish(otherFaction, newRelation); - Rel currentRelation = msenderFaction.getRelationTo(otherFaction, true); - - // if the relation change was successful - if (newRelation == currentRelation) - { - otherFaction.msg("%s is now %s.", msenderFaction.describeTo(otherFaction, true), newRelation.getDescFactionOne()); - msenderFaction.msg("%s is now %s.", otherFaction.describeTo(msenderFaction, true), newRelation.getDescFactionOne()); - } - // inform the other faction of your request - else - { - MassiveCommand command = CmdFactions.get().cmdFactionsRelation.cmdFactionsRelationSet; - String colorOne = newRelation.getColor() + newRelation.getDescFactionOne(); - - // Mson creation - Mson factionsRelationshipChange = mson( - Mson.parse("%s wishes to be %s.", msenderFaction.describeTo(otherFaction, true), colorOne), - Mson.SPACE, - mson("[Accept]").color(ChatColor.AQUA).command(command, msenderFaction.getName(), newRelation.name()) - ); - - otherFaction.sendMessage(factionsRelationshipChange); - msenderFaction.msg("%s were informed that you wish to be %s.", otherFaction.describeTo(msenderFaction, true), colorOne); - } - - // TODO: The ally case should work!! - // this might have to be bumped up to make that happen, & allow ALLY,NEUTRAL only - if (newRelation != Rel.TRUCE && otherFaction.getFlag(MFlag.getFlagPeaceful())) - { - otherFaction.msg("This will have no effect while your faction is peaceful."); - msenderFaction.msg("This will have no effect while their faction is peaceful."); - } - - if (newRelation != Rel.TRUCE && msenderFaction.getFlag(MFlag.getFlagPeaceful())) - { - otherFaction.msg("This will have no effect while their faction is peaceful."); - msenderFaction.msg("This will have no effect while your faction is peaceful."); - } - - // Mark as changed - msenderFaction.changed(); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRelationWishes.java b/src/com/massivecraft/factions/cmd/CmdFactionsRelationWishes.java deleted file mode 100644 index 7fb551f4..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRelationWishes.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.Rel; -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.FactionColl; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.collections.MassiveMap; -import com.massivecraft.massivecore.command.Parameter; -import com.massivecraft.massivecore.pager.Pager; -import com.massivecraft.massivecore.pager.Stringifier; -import com.massivecraft.massivecore.util.MUtil; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.Bukkit; - -import java.util.Map; -import java.util.Map.Entry; - -public class CmdFactionsRelationWishes extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsRelationWishes() - { - // Parameter - this.addParameter(Parameter.getPage()); - this.addParameter(TypeFaction.get(), "faction", "you"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - int page = this.readArg(); - final Faction faction = this.readArg(msenderFaction); - - // Pager Create - final Pager> pager = new Pager<>(this, "", page, (Stringifier>) (item, index) -> { - Rel rel = item.getValue(); - Faction fac = item.getKey(); - return rel.getColor().toString() + rel.getName() + CmdFactionsRelationList.SEPERATOR + fac.describeTo(faction, true); - }); - - Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> { - Map realWishes = new MassiveMap<>(); - - for (Entry entry : faction.getRelationWishes().entrySet()) - { - Rel rel = entry.getValue(); - Faction fac = FactionColl.get().getFixed(entry.getKey()); - if (fac == null) continue; - - // A wish is not a wish anymore if both factions have atleast equal "wishes" - if (fac.getRelationTo(faction).isAtLeast(rel)) continue; - realWishes.put(fac, rel); - } - - // Pager Title - pager.setTitle(Txt.parse("%s's Relation wishes (%d)", faction.getName(), realWishes.size())); - - // Pager Items - pager.setItems(MUtil.entriesSortedByValues(realWishes)); - - // Pager Message - pager.message(); - }); - } -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsSeeChunk.java b/src/com/massivecraft/factions/cmd/CmdFactionsSeeChunk.java deleted file mode 100644 index 8c0ff847..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsSeeChunk.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; -import com.massivecraft.massivecore.command.type.primitive.TypeBooleanOn; -import com.massivecraft.massivecore.util.Txt; - -public class CmdFactionsSeeChunk extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsSeeChunk() - { - // Aliases - this.addAliases("sc"); - - // Parameters - this.addParameter(TypeBooleanOn.get(), "active", "toggle"); - - // Requirements - this.addRequirements(RequirementIsPlayer.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - boolean old = msender.isSeeingChunk(); - boolean targetDefault = !old; - boolean target = this.readArg(targetDefault); - String targetDesc = Txt.parse(target ? "ON": "OFF"); - - // NoChange - if (target == old) - { - msg("See Chunk is already %s.", targetDesc); - return; - } - - // Apply - msender.setSeeingChunk(target); - - // Inform - msg("See Chunk is now %s.", targetDesc); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsSeeChunkOld.java b/src/com/massivecraft/factions/cmd/CmdFactionsSeeChunkOld.java deleted file mode 100644 index fc0c3f71..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsSeeChunkOld.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.util.AsciiMap; -import com.massivecraft.factions.util.VisualizeUtil; -import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.ps.PSFormatHumanSpace; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.entity.Player; - -public class CmdFactionsSeeChunkOld extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsSeeChunkOld() - { - // Aliases - this.addAliases("sco"); - - // Requirements - this.addRequirements(RequirementIsPlayer.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() - { - // Args - World world = me.getWorld(); - PS chunk = PS.valueOf(me.getLocation()).getChunk(true); - int chunkX = chunk.getChunkX(); - int chunkZ = chunk.getChunkZ(); - - // Apply - int blockX; - int blockZ; - - blockX = chunkX*16; - blockZ = chunkZ*16; - showPillar(me, world, blockX, blockZ); - - blockX = chunkX*16 + 15; - blockZ = chunkZ*16; - showPillar(me, world, blockX, blockZ); - - blockX = chunkX*16; - blockZ = chunkZ*16 + 15; - showPillar(me, world, blockX, blockZ); - - blockX = chunkX*16 + 15; - blockZ = chunkZ*16 + 15; - showPillar(me, world, blockX, blockZ); - - // Inform - boolean showCoords = AsciiMap.showChunkCoords(chunk); - String chunkDesc = showCoords ? chunk.toString(PSFormatHumanSpace.get()) : "chunk"; - msg("Visualized %s", chunkDesc); - } - - public static void showPillar(Player player, World world, int blockX, int blockZ) - { - for (int blockY = 0; blockY < world.getMaxHeight(); blockY++) - { - Location loc = new Location(world, blockX, blockY, blockZ); - if (loc.getBlock().getType() != Material.AIR) continue; - Material type = blockY % 5 == 0 ? Material.GLOWSTONE : Material.GLASS; - VisualizeUtil.addLocation(player, loc, type); - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsSetAll.java b/src/com/massivecraft/factions/cmd/CmdFactionsSetAll.java deleted file mode 100644 index 90062c3d..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsSetAll.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Perm; -import com.massivecraft.factions.entity.Board; -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.requirement.RequirementHasPerm; -import com.massivecraft.massivecore.mixin.MixinWorld; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.MUtil; - -import java.util.Collections; -import java.util.List; -import java.util.Set; - - -public class CmdFactionsSetAll extends CmdFactionsSetXAll -{ - // -------------------------------------------- // - // CONSTANTS - // -------------------------------------------- // - - public static final List LIST_ALL = Collections.unmodifiableList(MUtil.list("a", "al", "all")); - public static final List LIST_MAP = Collections.singletonList("map"); - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsSetAll(boolean claim) - { - // Super - super(claim); - - // Aliases - this.addAliases("all"); - - // Requirements - Perm perm = claim ? Perm.CLAIM_ALL : Perm.UNCLAIM_ALL; - this.addRequirements(RequirementHasPerm.get(perm)); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public Set getChunks() throws MassiveException - { - // World - String word = (this.isClaim() ? "claim" : "unclaim"); - - // Create Ret - Set chunks = null; - - // Args - Faction oldFaction = this.getOldFaction(); - - if (LIST_ALL.contains(this.argAt(0).toLowerCase())) - { - chunks = BoardColl.get().getChunks(oldFaction); - this.setFormatOne("%s %s %d chunk using " + word + " all."); - this.setFormatMany("%s %s %d chunks using " + word + " all."); - } - else - { - String worldId = null; - if (LIST_MAP.contains(this.argAt(0).toLowerCase())) - { - if (me != null) - { - worldId = me.getWorld().getName(); - } - else - { - throw new MassiveException().addMsg("You must specify which map from console."); - } - } - else - { - worldId = this.argAt(0); - if (worldId == null) return null; - } - Board board = BoardColl.get().get(worldId); - chunks = board.getChunks(oldFaction); - String worldDisplayName = MixinWorld.get().getWorldDisplayName(worldId); - this.setFormatOne("%s %s %d chunk using " + word + " " + worldDisplayName + "."); - this.setFormatMany("%s %s %d chunks using " + word + " " + worldDisplayName + "."); - } - - // Return Ret - return chunks; - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsSetAuto.java b/src/com/massivecraft/factions/cmd/CmdFactionsSetAuto.java deleted file mode 100644 index 286f5d48..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsSetAuto.java +++ /dev/null @@ -1,92 +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.FactionColl; -import com.massivecraft.factions.entity.MPerm; -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; - -import java.util.Collections; -import java.util.Set; - - -public class CmdFactionsSetAuto extends FactionsCommand -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private boolean claim = true; - public boolean isClaim() { return this.claim; } - public void setClaim(boolean claim) { this.claim = claim; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsSetAuto(boolean claim) - { - // Fields - this.setClaim(claim); - this.setSetupEnabled(false); - - // Aliases - this.addAliases("auto"); - - // Parameters - if (claim) - { - this.addParameter(TypeFaction.get(), "faction", "you"); - } - - // Requirements - this.addRequirements(RequirementIsPlayer.get()); - Perm perm = claim ? Perm.CLAIM_AUTO : Perm.UNCLAIM_AUTO; - this.addRequirements(RequirementHasPerm.get(perm)); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - final Faction newFaction; - if (claim) - { - newFaction = this.readArg(msenderFaction); - } - else - { - newFaction = FactionColl.get().getNone(); - } - - // Disable? - if (newFaction == null || newFaction == msender.getAutoClaimFaction()) - { - msender.setAutoClaimFaction(null); - throw new MassiveException().addMsg("Disabled auto-setting as you walk around."); - } - - // MPerm Preemptive Check - if (newFaction.isNormal() && ! MPerm.getPermTerritory().has(msender, newFaction, true)) return; - - // Apply / Inform - msender.setAutoClaimFaction(newFaction); - msg("Now auto-setting %s land.", newFaction.describeTo(msender)); - - // Chunks - final PS chunk = PS.valueOf(me.getLocation()).getChunk(true); - Set chunks = Collections.singleton(chunk); - - // Apply / Inform - msender.tryClaim(newFaction, chunks); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsSetCircle.java b/src/com/massivecraft/factions/cmd/CmdFactionsSetCircle.java deleted file mode 100644 index d8830cc1..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsSetCircle.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Perm; -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; -import com.massivecraft.massivecore.util.ChunkUtil; - -import java.util.Set; - - -public class CmdFactionsSetCircle extends CmdFactionsSetXRadius -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsSetCircle(boolean claim) - { - // Super - super(claim); - - // Aliases - this.addAliases("circle"); - - // Format - this.setFormatOne("%s %s %d chunk %s using circle."); - this.setFormatMany("%s %s %d chunks near %s using circle."); - - // Requirements - this.addRequirements(RequirementIsPlayer.get()); - Perm perm = claim ? Perm.CLAIM_CIRCLE : Perm.UNCLAIM_CIRCLE; - this.addRequirements(RequirementHasPerm.get(perm)); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public Set getChunks() throws MassiveException - { - // Common Startup - final PS chunk = PS.valueOf(me.getLocation()).getChunk(true); - return ChunkUtil.getChunksCircle(chunk, this.getRadius()); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsSetFill.java b/src/com/massivecraft/factions/cmd/CmdFactionsSetFill.java deleted file mode 100644 index 45590206..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsSetFill.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Perm; -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; -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; -import com.massivecraft.massivecore.util.ChunkUtil; - -import java.util.Set; -import java.util.function.Predicate; - - -public class CmdFactionsSetFill extends CmdFactionsSetXSimple -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsSetFill(boolean claim) - { - // Super - super(claim); - - // Aliases - this.addAliases("fill"); - - // Format - this.setFormatOne("%s %s %d chunk %s using fill."); - this.setFormatMany("%s %s %d chunks near %s using fill."); - - // Requirements - this.addRequirements(RequirementIsPlayer.get()); - Perm perm = claim ? Perm.CLAIM_FILL : Perm.UNCLAIM_FILL; - this.addRequirements(RequirementHasPerm.get(perm)); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public Set getChunks() throws MassiveException - { - // Common Startup - final PS chunk = PS.valueOf(me.getLocation()).getChunk(true); - - // What faction (aka color) resides there? - // NOTE: Wilderness/None is valid. - final Faction color = BoardColl.get().getFactionAt(chunk); - - // Calculate - int max = MConf.get().setFillMax; - Predicate matcher = ps -> BoardColl.get().getFactionAt(ps) == color; - return ChunkUtil.getChunkArea(chunk, matcher, max); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsSetOne.java b/src/com/massivecraft/factions/cmd/CmdFactionsSetOne.java deleted file mode 100644 index 102b5ed9..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsSetOne.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Perm; -import com.massivecraft.massivecore.command.requirement.RequirementHasPerm; -import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; -import com.massivecraft.massivecore.ps.PS; - -import java.util.Collections; -import java.util.Set; - - -public class CmdFactionsSetOne extends CmdFactionsSetXSimple -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsSetOne(boolean claim) - { - // Super - super(claim); - - // Aliases - this.addAliases("one"); - - // Requirements - this.addRequirements(RequirementIsPlayer.get()); - Perm perm = claim ? Perm.CLAIM_ONE : Perm.UNCLAIM_ONE; - this.addRequirements(RequirementHasPerm.get(perm)); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public Set getChunks() - { - final PS chunk = PS.valueOf(me.getLocation()).getChunk(true); - return Collections.singleton(chunk); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsSetSquare.java b/src/com/massivecraft/factions/cmd/CmdFactionsSetSquare.java deleted file mode 100644 index 8239463f..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsSetSquare.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Perm; -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; -import com.massivecraft.massivecore.util.ChunkUtil; - -import java.util.Set; - - -public class CmdFactionsSetSquare extends CmdFactionsSetXRadius -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsSetSquare(boolean claim) - { - // Super - super(claim); - - // Aliases - this.addAliases("square"); - - // Format - this.setFormatOne("%s %s %d chunk %s using square."); - this.setFormatMany("%s %s %d chunks near %s using square."); - - // Requirements - this.addRequirements(RequirementIsPlayer.get()); - Perm perm = claim ? Perm.CLAIM_SQUARE : Perm.UNCLAIM_SQUARE; - this.addRequirements(RequirementHasPerm.get(perm)); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public Set getChunks() throws MassiveException - { - // Common Startup - final PS chunk = PS.valueOf(me.getLocation()).getChunk(true); - return ChunkUtil.getChunksSquare(chunk, this.getRadius()); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsSetX.java b/src/com/massivecraft/factions/cmd/CmdFactionsSetX.java deleted file mode 100644 index 4c0162a9..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsSetX.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.FactionColl; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.ps.PS; - -import java.util.Set; - -public abstract class CmdFactionsSetX extends FactionsCommand -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private String formatOne = null; - public String getFormatOne() { return this.formatOne; } - public void setFormatOne(String formatOne) { this.formatOne = formatOne; } - - private String formatMany = null; - public String getFormatMany() { return this.formatMany; } - public void setFormatMany(String formatMany) { this.formatMany = formatMany; } - - private boolean claim = true; - public boolean isClaim() { return this.claim; } - public void setClaim(boolean claim) { this.claim = claim; } - - private int factionArgIndex = 0; - public int getFactionArgIndex() { return this.factionArgIndex; } - public void setFactionArgIndex(int factionArgIndex) { this.factionArgIndex = factionArgIndex; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsSetX(boolean claim) - { - this.setClaim(claim); - this.setSetupEnabled(false); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - final Faction newFaction = this.getNewFaction(); - final Set chunks = this.getChunks(); - if (chunks == null) throw new NullPointerException("chunks"); - - // Apply / Inform - msender.tryClaim(newFaction, chunks, this.getFormatOne(), this.getFormatMany()); - } - - // -------------------------------------------- // - // ABSTRACT - // -------------------------------------------- // - - public abstract Set getChunks() throws MassiveException; - - // -------------------------------------------- // - // EXTRAS - // -------------------------------------------- // - - public Faction getNewFaction() throws MassiveException - { - if (this.isClaim()) - { - return this.readArgAt(this.getFactionArgIndex(), msenderFaction); - } - else - { - return FactionColl.get().getNone(); - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsSetXAll.java b/src/com/massivecraft/factions/cmd/CmdFactionsSetXAll.java deleted file mode 100644 index d9b042e8..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsSetXAll.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.primitive.TypeString; - -public abstract class CmdFactionsSetXAll extends CmdFactionsSetX -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsSetXAll(boolean claim) - { - // Super - super(claim); - - // Parameters - this.addParameter(TypeString.get(), "all|map"); - this.addParameter(TypeFaction.get(), "faction"); - if (claim) - { - this.addParameter(TypeFaction.get(), "newfaction"); - this.setFactionArgIndex(2); - } - } - - // -------------------------------------------- // - // EXTRAS - // -------------------------------------------- // - - public Faction getOldFaction() throws MassiveException - { - return this.readArgAt(1); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsSetXRadius.java b/src/com/massivecraft/factions/cmd/CmdFactionsSetXRadius.java deleted file mode 100644 index c20c6f23..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsSetXRadius.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.primitive.TypeInteger; - - -public abstract class CmdFactionsSetXRadius extends CmdFactionsSetX -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsSetXRadius(boolean claim) - { - // Super - super(claim); - - // Parameters - this.addParameter(1, TypeInteger.get(), "radius"); - if (claim) - { - this.addParameter(TypeFaction.get(), "faction", "you"); - this.setFactionArgIndex(1); - } - } - - // -------------------------------------------- // - // EXTRAS - // -------------------------------------------- // - - public Integer getRadius() throws MassiveException - { - int radius = this.readArgAt(0); - - // Radius Claim Min - if (radius < 1) - { - throw new MassiveException().setMsg("If you specify a radius, it must be at least 1."); - } - - // Radius Claim Max - if (radius > MConf.get().setRadiusMax && ! msender.isOverriding()) - { - throw new MassiveException().setMsg("The maximum radius allowed is %s.", MConf.get().setRadiusMax); - } - - return radius; - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsSetXSimple.java b/src/com/massivecraft/factions/cmd/CmdFactionsSetXSimple.java deleted file mode 100644 index dd703a94..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsSetXSimple.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeFaction; - -public abstract class CmdFactionsSetXSimple extends CmdFactionsSetX -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsSetXSimple(boolean claim) - { - // Super - super(claim); - - // Parameters - if (claim) - { - this.addParameter(TypeFaction.get(), "faction", "you"); - this.setFactionArgIndex(0); - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java b/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java deleted file mode 100644 index feca44bb..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.Visibility; -import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; -import com.massivecraft.massivecore.util.MUtil; - -import java.util.List; - -public class CmdFactionsSethome extends FactionsCommandWarp -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsSethome() - { - // Requirements - this.addRequirements(RequirementIsPlayer.get()); - - // Parameters - this.addParameter(TypeFaction.get(), "faction", "you"); - - // Visibility - this.setVisibility(Visibility.INVISIBLE); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - List args = MUtil.list(MConf.get().warpsHomeName, this.argAt(0)); - CmdFactions.get().cmdFactionsWarp.cmdFactionWarpAdd.execute(me, args); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsSetpower.java b/src/com/massivecraft/factions/cmd/CmdFactionsSetpower.java deleted file mode 100644 index b7fb3e78..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsSetpower.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Perm; -import com.massivecraft.factions.cmd.type.TypeMPlayer; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.event.EventFactionsPowerChange; -import com.massivecraft.factions.event.EventFactionsPowerChange.PowerChangeReason; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.requirement.RequirementHasPerm; -import com.massivecraft.massivecore.command.type.primitive.TypeDouble; - -public class CmdFactionsSetpower extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsSetpower() - { - // Aliases - this.addAliases("sp"); - - // Parameters - this.addParameter(TypeMPlayer.get(), "player"); - this.addParameter(TypeDouble.get(), "power"); - - // Requirements - this.addRequirements(RequirementHasPerm.get(Perm.SETPOWER)); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - MPlayer mplayer = this.readArg(); - double power = this.readArg(); - - // Power - double oldPower = mplayer.getPower(); - double newPower = mplayer.getLimitedPower(power); - - // Detect "no change" - double difference = Math.abs(newPower - oldPower); - double maxDifference = 0.1d; - if (difference < maxDifference) - { - throw new MassiveException().addMsg("%s's power is already %.2f.", mplayer.getDisplayName(msender), newPower); - } - - // Event - EventFactionsPowerChange event = new EventFactionsPowerChange(sender, mplayer, PowerChangeReason.COMMAND, newPower); - event.run(); - if (event.isCancelled()) return; - - // Inform - msg("You changed %s's power from %.2f to %.2f.", mplayer.getDisplayName(msender), oldPower, newPower); - if (msender != mplayer) - { - mplayer.msg("%s changed your power from %.2f to %.2f.", msender.getDisplayName(mplayer), oldPower, newPower); - } - - // Apply - mplayer.setPower(newPower); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsStatus.java b/src/com/massivecraft/factions/cmd/CmdFactionsStatus.java deleted file mode 100644 index f1dcb1f9..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsStatus.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.cmd.type.TypeSortMPlayer; -import com.massivecraft.factions.comparator.ComparatorMPlayerInactivity; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPlayer; -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.util.TimeDiffUtil; -import com.massivecraft.massivecore.util.TimeUnit; -import com.massivecraft.massivecore.util.Txt; - -import java.util.Comparator; -import java.util.LinkedHashMap; -import java.util.List; - -public class CmdFactionsStatus extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsStatus() - { - // Parameters - this.addParameter(Parameter.getPage()); - this.addParameter(TypeFaction.get(), "faction", "you").setDesc("the faction whose status to see"); - this.addParameter(TypeSortMPlayer.get(), "sort", "time").setDesc("sort mplayers by rank, power or last active time?"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - int page = this.readArg(); - Faction faction = this.readArg(msenderFaction); - Comparator sortedBy = this.readArg(ComparatorMPlayerInactivity.get()); - - // Sort list - final List mplayers = faction.getMPlayers(); - mplayers.sort(sortedBy); - - // Pager Create - String title = Txt.parse("Status of %s.", faction.describeTo(msender, true)); - final Pager pager = new Pager<>(this, title, page, mplayers, (Stringifier) (mplayer, index) -> { - // Name - String displayName = mplayer.getNameAndSomething(msender.getColorTo(mplayer).toString(), ""); - int length = 15 - displayName.length(); - length = length <= 0 ? 1 : length; - String whiteSpace = Txt.repeat(" ", length); - - // Power - double currentPower = mplayer.getPower(); - double maxPower = mplayer.getPowerMax(); - String color; - double percent = currentPower / maxPower; - - if (percent > 0.75) - { - color = ""; - } - else if (percent > 0.5) - { - color = ""; - } - else if (percent > 0.25) - { - color = ""; - } - else - { - color = ""; - } - - String power = Txt.parse("Power: %s%.0f/%.0f", Txt.parse(color), currentPower, maxPower); - - // Time - long lastActiveMillis = mplayer.getLastActivityMillis() - System.currentTimeMillis(); - LinkedHashMap activeTimes = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(lastActiveMillis, TimeUnit.getAllButMillis()), 3); - String lastActive = mplayer.isOnline(msender) ? Txt.parse("Online right now.") : Txt.parse("Last active: " + TimeDiffUtil.formatedMinimal(activeTimes, "")); - - return Txt.parse("%s%s %s %s", displayName, whiteSpace, power, lastActive); - }); - - - // Pager Message - pager.message(); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsTax.java b/src/com/massivecraft/factions/cmd/CmdFactionsTax.java deleted file mode 100644 index 0e906199..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsTax.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.massivecraft.factions.cmd; - -public class CmdFactionsTax extends FactionsCommand -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public CmdFactionsTaxPlayer cmdFactionsTaxPlayer = new CmdFactionsTaxPlayer(); - public CmdFactionsTaxFaction cmdFactionsTaxFaction = new CmdFactionsTaxFaction(); - public CmdFactionsTaxSet cmdFactionsTaxSet = new CmdFactionsTaxSet(); - public CmdFactionsTaxRun cmdFactionsTaxRun = new CmdFactionsTaxRun(); - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsTaxFaction.java b/src/com/massivecraft/factions/cmd/CmdFactionsTaxFaction.java deleted file mode 100644 index 448bcfc7..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsTaxFaction.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.req.ReqTaxEnabled; -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MFlag; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.entity.Rank; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.mson.Mson; -import com.massivecraft.massivecore.util.Txt; - -import java.util.Map.Entry; - -public class CmdFactionsTaxFaction extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsTaxFaction() - { - this.addParameter(TypeFaction.get(), "faction", "your"); - - this.addRequirements(ReqTaxEnabled.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - Faction faction = this.readArg(msenderFaction); - - if (faction.isNone()) - { - throw new MassiveException().addMsg("Taxes are not in place for %s.", faction.describeTo(msender)); - } - - Mson title = Txt.titleize("Tax for " + faction.getDisplayName(msender)); - message(title); - - MFlag flag = MFlag.getFlagTaxKick(); - String flagDesc = flag.getStateDesc(faction.getFlag(flag), true, false, false, true, true); - msg("Player Kick: %s", flagDesc); - - boolean anyTax = false; - for (Entry entry : faction.getTax().entrySet()) - { - String id = entry.getKey(); - Double tax = entry.getValue(); - - Rank rank = faction.getRank(id); - MPlayer mplayer = MPlayer.get(id); - - String name; - if (Faction.IDENTIFIER_TAX_BASE.equals(id)) name = "Default"; - else if (rank != null) name = rank.getName(); - else if (mplayer != null) name = mplayer.getDisplayName(msender); - else continue; - anyTax = true; - msg("%s: %.2f", name, tax); - } - if (!anyTax) msg("No players in this faction pays taxes."); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsTaxPlayer.java b/src/com/massivecraft/factions/cmd/CmdFactionsTaxPlayer.java deleted file mode 100644 index 56f7109d..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsTaxPlayer.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.req.ReqTaxEnabled; -import com.massivecraft.factions.cmd.type.TypeMPlayer; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.money.Money; -import com.massivecraft.massivecore.mson.Mson; -import com.massivecraft.massivecore.util.Txt; - -public class CmdFactionsTaxPlayer extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsTaxPlayer() - { - this.addParameter(TypeMPlayer.get(), "player", "you"); - - this.addRequirements(ReqTaxEnabled.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - MPlayer mplayer = this.readArg(msender); - - Mson title = Txt.titleize("Tax for " + mplayer.getDisplayName(msender)); - message(title); - - String factionName = mplayer.getFaction().describeTo(msender); - msg("Faction: %s", factionName); - - double tax = mplayer.getFaction().getTaxForPlayer(mplayer); - String taxDesc = Money.format(tax); - msg("Tax: %s", taxDesc); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsTaxRun.java b/src/com/massivecraft/factions/cmd/CmdFactionsTaxRun.java deleted file mode 100644 index 5a76ba1e..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsTaxRun.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.req.ReqTaxEnabled; -import com.massivecraft.factions.task.TaskTax; -import com.massivecraft.massivecore.MassiveException; - -public class CmdFactionsTaxRun extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsTaxRun() - { - this.addRequirements(ReqTaxEnabled.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - TaskTax.get().invoke(System.currentTimeMillis()); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsTaxSet.java b/src/com/massivecraft/factions/cmd/CmdFactionsTaxSet.java deleted file mode 100644 index 74f79b4e..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsTaxSet.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.req.ReqTaxEnabled; -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.cmd.type.TypeTaxable; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.entity.MPlayerColl; -import com.massivecraft.factions.entity.Rank; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.primitive.TypeDouble; -import com.massivecraft.massivecore.money.Money; -import com.massivecraft.massivecore.util.MUtil; - -public class CmdFactionsTaxSet extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsTaxSet() - { - this.addParameter(TypeDouble.get(), "tax"); - this.addParameter(TypeTaxable.get(), "default|rank|player|all", "default"); - this.addParameter(TypeFaction.get(), "faction", "your"); - - this.addRequirements(ReqTaxEnabled.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - Double tax = this.readArg(); - - if (MConf.get().taxPlayerMaximum < tax && tax != 0) - { - throw new MassiveException().addMsg("Taxes can't be above %s.", Money.format(MConf.get().taxPlayerMaximum)); - } - if (MConf.get().taxPlayerMinimum > tax && tax != 0) - { - throw new MassiveException().addMsg("Taxes can't be below %s.", Money.format(MConf.get().taxPlayerMinimum)); - } - - Faction faction = this.readArgAt(2, msenderFaction); - TypeTaxable typeTaxable = TypeTaxable.get(faction); - String taxable = this.argIsSet(1) ? typeTaxable.read(this.argAt(1), sender) : Faction.IDENTIFIER_TAX_BASE; - - if ( ! MPerm.getPermTax().has(msender, faction, true)) return; - - Rank rank = faction.getRank(taxable); - MPlayer mplayer = MPlayerColl.get().get(taxable, false); - - String name; - if (Faction.IDENTIFIER_TAX_BASE.equalsIgnoreCase(taxable)) name = "Default"; - else if (rank != null) name = rank.getDisplayName(msender); - else if (mplayer != null) name = mplayer.getDisplayName(msender); - else throw new RuntimeException(taxable); - - String taxDesc = Money.format(tax); - - Double previous = faction.setTaxFor(taxable, tax); - - if (MUtil.equalsishNumber(tax, previous)) - { - throw new MassiveException().addMsg("The tax for %s is already %s.", name, taxDesc); - } - - msg("The taxes for %s is now set to %s.", name, taxDesc); - if (tax < 0) - { - msg("NOTE: A negative tax works like a salary."); - } - - if (msender != mplayer && mplayer != null) - { - mplayer.msg("%s set your tax to %s.", msender.getDisplayName(mplayer), taxDesc); - } - if (rank != null) - { - String msg = "Taxes for %s set to %s by %s."; - faction.getMPlayersWhereRank(rank).forEach(mp -> mp.msg(msg, name, taxDesc, msender.getDisplayName(mp))); - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsTerritorytitles.java b/src/com/massivecraft/factions/cmd/CmdFactionsTerritorytitles.java deleted file mode 100644 index 078b79ba..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsTerritorytitles.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.Visibility; -import com.massivecraft.massivecore.command.requirement.RequirementTitlesAvailable; -import com.massivecraft.massivecore.command.type.primitive.TypeBooleanOn; -import com.massivecraft.massivecore.mixin.MixinTitle; -import com.massivecraft.massivecore.util.Txt; - -public class CmdFactionsTerritorytitles extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsTerritorytitles() - { - // Aliases - this.addAliases("tt"); - - // Parameters - this.addParameter(TypeBooleanOn.get(), "on|off", "toggle"); - - // Requirements - this.addRequirements(RequirementTitlesAvailable.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public Visibility getVisibility() - { - // We hide the command if titles aren't available. - if ( ! MixinTitle.get().isAvailable()) return Visibility.INVISIBLE; - return super.getVisibility(); - } - - @Override - public void perform() throws MassiveException - { - // Args - boolean before = msender.isTerritoryInfoTitles(); - boolean after = this.readArg(!before); - String desc = Txt.parse(after ? "ON" : "OFF"); - - // NoChange - if (after == before) - { - msg("Territory titles is already %s.", desc); - return; - } - - // Apply - msender.setTerritoryInfoTitles(after); - - // Inform - msg("Territory titles is now %s.", desc); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsTitle.java b/src/com/massivecraft/factions/cmd/CmdFactionsTitle.java deleted file mode 100644 index 8d7356e0..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsTitle.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Perm; -import com.massivecraft.factions.cmd.type.TypeMPlayer; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.event.EventFactionsTitleChange; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.primitive.TypeString; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.ChatColor; - -public class CmdFactionsTitle extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsTitle() - { - // Parameters - this.addParameter(TypeMPlayer.get(), "player"); - this.addParameter(TypeString.get(), "title", "none", true); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - MPlayer you = this.readArg(); - String newTitle = this.readArg(""); - - newTitle = Txt.parse(newTitle); - if (!Perm.TITLE_COLOR.has(sender, false)) - { - newTitle = ChatColor.stripColor(newTitle); - } - - // MPerm - if ( ! MPerm.getPermTitle().has(msender, you.getFaction(), true)) return; - - // Rank Check - if (!msender.isOverriding() && you.getRank().isMoreThan(msender.getRank())) - { - throw new MassiveException().addMsg("You can not edit titles for higher ranks."); - } - if (!msender.isOverriding() && you.getRank() == msender.getRank() && msender != you) - { - throw new MassiveException().addMsg("You can't edit titles of people with the same rank as yourself."); - } - - // Event - EventFactionsTitleChange event = new EventFactionsTitleChange(sender, you, newTitle); - event.run(); - if (event.isCancelled()) return; - newTitle = event.getNewTitle(); - - // Apply - you.setTitle(newTitle); - - // Inform - msenderFaction.msg("%s changed a title: %s", msender.describeTo(msenderFaction, true), you.describeTo(msenderFaction, true)); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsTop.java b/src/com/massivecraft/factions/cmd/CmdFactionsTop.java deleted file mode 100644 index df7426de..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsTop.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.FactionColl; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.integration.Econ; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.Parameter; -import com.massivecraft.massivecore.command.type.enumeration.TypeEnum; -import com.massivecraft.massivecore.money.Money; -import com.massivecraft.massivecore.pager.Pager; -import com.massivecraft.massivecore.pager.Stringifier; -import com.massivecraft.massivecore.util.TimeDiffUtil; -import com.massivecraft.massivecore.util.TimeUnit; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; - -import java.util.LinkedHashMap; -import java.util.List; - -public class CmdFactionsTop extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsTop() - { - // Parameters - this.addParameter(new TypeEnum<>(TopCategory.class)); - this.addParameter(Parameter.getPage()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - TopCategory category = this.readArg(); - int page = this.readArg(); - final CommandSender sender = this.sender; - final MPlayer msender = this.msender; - - if (category == TopCategory.MONEY && !Econ.isEnabled()) - { - throw new MassiveException().addMsg("Economy is not enabled."); - } - - Pager pager = new Pager<>(this, "Faction top", page); - pager.setMsonifier((Stringifier) (f, i) -> getValue(category, f, msender)); - - // NOTE: The faction list is quite slow and mostly thread safe. - // We run it asynchronously to spare the primary server thread. - - Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> { - // Pager Items - List factions = FactionColl.get().getAll((f1, f2) -> (int) (getNumber(category, f2) - getNumber(category, f1))); - pager.setItems(factions); - - // Pager Message - pager.message(); - }); - } - - private static double getNumber(TopCategory category, Faction faction) - { - switch(category) - { - case MONEY: return Econ.getMoney(faction); - case MEMBERS: return faction.getMPlayers().size(); - case TERRITORY: return faction.getLandCount(); - case AGE: return faction.getAge(); - } - throw new RuntimeException(); - } - - private static String getValue(TopCategory category, Faction faction, MPlayer mplayer) - { - String ret = Txt.parse("%s: ", faction.getName(mplayer)); - switch(category) - { - case MONEY: ret += Money.format(Econ.getMoney(faction), true); break; - case MEMBERS: ret += faction.getMPlayers().size() + " members"; break; - case TERRITORY: ret += faction.getLandCount() + " chunks"; break; - case AGE: - long ageMillis = faction.getAge(); - LinkedHashMap ageUnitcounts = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(ageMillis, TimeUnit.getAllButMillis()), 3); - ret += TimeDiffUtil.formatedVerboose(ageUnitcounts); - break; - } - return ret; - } - - public enum TopCategory - { - MONEY, - MEMBERS, - TERRITORY, - AGE, - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java deleted file mode 100644 index 91d5c67a..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.massivecraft.factions.cmd; - -public class CmdFactionsUnclaim extends FactionsCommand -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public CmdFactionsSetOne cmdFactionsUnclaimOne = new CmdFactionsSetOne(false); - public CmdFactionsSetAuto cmdFactionsUnclaimAuto = new CmdFactionsSetAuto(false); - public CmdFactionsSetFill cmdFactionsUnclaimFill = new CmdFactionsSetFill(false); - public CmdFactionsSetSquare cmdFactionsUnclaimSquare = new CmdFactionsSetSquare(false); - public CmdFactionsSetCircle cmdFactionsUnclaimCircle = new CmdFactionsSetCircle(false); - public CmdFactionsSetAll cmdFactionsUnclaimAll = new CmdFactionsSetAll(false); - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsUnsethome.java b/src/com/massivecraft/factions/cmd/CmdFactionsUnsethome.java deleted file mode 100644 index 54907a47..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsUnsethome.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.Visibility; -import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; -import com.massivecraft.massivecore.util.MUtil; - -import java.util.List; - -public class CmdFactionsUnsethome extends FactionsCommandWarp -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsUnsethome() - { - // Requirements - this.addRequirements(RequirementIsPlayer.get()); - - // Parameters - this.addParameter(TypeFaction.get(), "faction", "you"); - - // Visibility - this.setVisibility(Visibility.INVISIBLE); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - List args = MUtil.list(MConf.get().warpsHomeName, this.argAt(0)); - CmdFactions.get().cmdFactionsWarp.cmdFactionWarpRemove.execute(me, args); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsUnstuck.java b/src/com/massivecraft/factions/cmd/CmdFactionsUnstuck.java deleted file mode 100644 index 106f3678..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsUnstuck.java +++ /dev/null @@ -1,156 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.FactionColl; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; -import com.massivecraft.massivecore.mixin.MixinTeleport; -import com.massivecraft.massivecore.mixin.TeleporterException; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.teleport.Destination; -import com.massivecraft.massivecore.teleport.DestinationSimple; -import org.bukkit.Location; -import org.bukkit.World; - -import java.util.ArrayList; -import java.util.List; - -public class CmdFactionsUnstuck extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsUnstuck() - { - // Requirements - this.addRequirements(RequirementIsPlayer.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // If the player is in a chunk ... - final PS center = PS.valueOf(me.getLocation().getChunk()); - - // ... that isn't free ... - if (isFree(msender, center)) - { - msg("You don't seem to be stuck."); - return; - } - - // ... get the nearest free top location ... - Location location = getNearestFreeTopLocation(msender, center); - if (location == null) - { - msg("No nearby chunk with %s or build rights found.", FactionColl.get().getNone().describeTo(msender)); - return; - } - - // ... and schedule a teleport. - Destination destination = new DestinationSimple(PS.valueOf(location)); - try - { - MixinTeleport.get().teleport(me, destination, MConf.get().unstuckSeconds); - } - catch (TeleporterException e) - { - msg("%s", e.getMessage()); - } - } - - // Get the first free top location in the spiral. - public static Location getNearestFreeTopLocation(MPlayer mplayer, PS ps) - { - List chunks = getChunkSpiral(ps); - for (PS chunk : chunks) - { - if (!isFree(mplayer, chunk)) continue; - Location ret = getTopLocation(chunk); - if (ret == null) continue; - return ret; - } - return null; - } - - // Return the ground level top location for this ps. - public static Location getTopLocation(PS ps) - { - Location ret = null; - try - { - World world = ps.asBukkitWorld(); - - int blockX = ps.getBlockX(true); - int blockZ = ps.getBlockZ(true); - int blockY = world.getHighestBlockYAt(blockX, blockZ); - - // We must have something to stand on. - if (blockY <= 1) return null; - - double locationX = blockX + 0.5D; - double locationY = blockY + 0.5D; - double locationZ = blockZ + 0.5D; - - ret = new Location(world, locationX, locationY, locationZ); - } - catch (Exception e) - { - e.printStackTrace(); - } - return ret; - } - - // With a "free" chunk we mean wilderness or that the player has build rights. - public static boolean isFree(MPlayer mplayer, PS ps) - { - Faction faction = BoardColl.get().getFactionAt(ps); - if (faction.isNone()) return true; - return MPerm.getPermBuild().has(mplayer, ps, false); - } - - // Not exactly a spiral. But it will do. - public static List getChunkSpiral(PS center) - { - // Create Ret - List ret = new ArrayList<>(); - - // Fill Ret - center = center.getChunk(true); - final int centerX = center.getChunkX(); - final int centerZ = center.getChunkZ(); - - for (int delta = 1; delta <= MConf.get().unstuckChunkRadius; delta++) - { - int minX = centerX - delta; - int maxX = centerX + delta; - int minZ = centerZ - delta; - int maxZ = centerZ + delta; - - for (int x = minX; x <= maxX; x++) - { - ret.add(center.withChunkX(x).withChunkZ(minZ)); - ret.add(center.withChunkX(x).withChunkZ(maxZ)); - } - - for (int z = minZ + 1; z <= maxZ - 1; z++) - { - ret.add(center.withChunkX(minX).withChunkZ(z)); - ret.add(center.withChunkX(maxX).withChunkZ(z)); - } - } - - // Return Ret - return ret; - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsVote.java b/src/com/massivecraft/factions/cmd/CmdFactionsVote.java deleted file mode 100644 index 48384a08..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsVote.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.massivecraft.factions.cmd; - -public class CmdFactionsVote extends FactionsCommand -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public CmdFactionsVoteShow cmdFactionsVoteShow = new CmdFactionsVoteShow(); - public CmdFactionsVoteList cmdFactionsVoteList = new CmdFactionsVoteList(); - public CmdFactionsVoteDo cmdFactionsVoteDo = new CmdFactionsVoteDo(); - public CmdFactionsVoteCreate cmdFactionsVoteCreate = new CmdFactionsVoteCreate(); - public CmdFactionsVoteRemove cmdFactionsVoteRemove = new CmdFactionsVoteRemove(); - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsVoteCreate.java b/src/com/massivecraft/factions/cmd/CmdFactionsVoteCreate.java deleted file mode 100644 index fbfe87ce..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsVoteCreate.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.Vote; -import com.massivecraft.factions.event.EventFactionsVoteAdd; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.collections.MassiveList; -import com.massivecraft.massivecore.command.type.container.TypeList; -import com.massivecraft.massivecore.command.type.primitive.TypeString; -import com.massivecraft.massivecore.util.IdUtil; - -import java.util.List; - -public class CmdFactionsVoteCreate extends FactionsCommandWarp -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsVoteCreate() - { - // Parameters - this.addParameter(TypeString.get(), "name"); - this.addParameter(TypeList.get(TypeString.get()), "options", true); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - String name = this.readArg(); - List options = this.readArg(); - - // MPerm - if ( ! MPerm.getPermCreateVote().has(msender, msenderFaction, true)) return; - - if (msenderFaction.getVoteByName(name).isPresent()) - { - throw new MassiveException().addMsg("There is already a vote called %s.", name); - } - - // Make sure there are no duplicated - List options2 = new MassiveList<>(); - for (String str : options) - { - if (options2.stream().anyMatch(str::equalsIgnoreCase)) continue; - options2.add(str); - } - - - Vote vote = new Vote(IdUtil.getId(sender), name, options2); - - // Event - EventFactionsVoteAdd event = new EventFactionsVoteAdd(sender, msenderFaction, vote); - event.run(); - if (event.isCancelled()) return; - vote = event.getVote(); - - // Apply - msenderFaction.addVote(vote); - - // Inform - msenderFaction.msg("%s added the vote %s to your faction. You can now use:", msender.describeTo(msenderFaction, true), vote.getName()); - msenderFaction.sendMessage(CmdFactions.get().cmdFactionsVote.cmdFactionsVoteDo.getTemplateWithArgs(null, vote.getName())); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsVoteDo.java b/src/com/massivecraft/factions/cmd/CmdFactionsVoteDo.java deleted file mode 100644 index 61b5405d..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsVoteDo.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeVote; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.Vote; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.primitive.TypeString; - -public class CmdFactionsVoteDo extends FactionsCommandWarp -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsVoteDo() - { - // Parameters - this.addParameter(TypeVote.get()); - this.addParameter(TypeString.get(), "option"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - Vote vote = TypeVote.get(msenderFaction).read(this.arg(), sender); - String option = this.readArg(); - - // Any and MPerm - if ( ! MPerm.getPermVote().has(msender, msenderFaction, true)) return; - - if (vote.getOptions().stream().noneMatch(option::equalsIgnoreCase)) - { - throw new MassiveException().addMsg("No option in %s matches %s.", vote.getName(), option); - } - - vote.setVote(msender, option); - - msg("Succesfully voted for %s in %s.", option, vote.getName()); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsVoteList.java b/src/com/massivecraft/factions/cmd/CmdFactionsVoteList.java deleted file mode 100644 index 319b98d8..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsVoteList.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.entity.Vote; -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.util.Txt; - -public class CmdFactionsVoteList extends FactionsCommandWarp -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsVoteList() - { - // Parameters - this.addParameter(Parameter.getPage()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - int idx = this.readArg(); - - Pager pager = new Pager<>(this, "Faction Votes", idx, msenderFaction.getVotes().getAll()); - pager.setMsonifier((Stringifier) (vote, i) -> - { - String options = Txt.implodeCommaAndDot(vote.getOptions(), Txt.parse("%s"), Txt.parse(", "), Txt.parse(" and "), ""); - return Txt.parse("%s: %s", vote.getName(), options); - }); - - pager.message(); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsVoteRemove.java b/src/com/massivecraft/factions/cmd/CmdFactionsVoteRemove.java deleted file mode 100644 index 040a5496..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsVoteRemove.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeVote; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.Vote; -import com.massivecraft.factions.event.EventFactionsVoteRemove; -import com.massivecraft.massivecore.MassiveException; - -public class CmdFactionsVoteRemove extends FactionsCommandWarp -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsVoteRemove() - { - // Parameters - this.addParameter(TypeVote.get(), "vote"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - Vote vote = TypeVote.get(msenderFaction).read(this.arg(), sender); - - // Any and MPerm - if ( ! MPerm.getPermCreateVote().has(msender, msenderFaction, true)) return; - - // Event - EventFactionsVoteRemove event = new EventFactionsVoteRemove(sender, msenderFaction, vote); - event.run(); - if (event.isCancelled()) return; - vote = event.getVote(); - - // Apply - vote.detach(); - - // Inform - msender.msg("%s removed the vote %s from your faction.", msender.describeTo(msenderFaction, true), vote.getName()); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsVoteShow.java b/src/com/massivecraft/factions/cmd/CmdFactionsVoteShow.java deleted file mode 100644 index ec8a4080..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsVoteShow.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeVote; -import com.massivecraft.factions.entity.Vote; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.util.Txt; - -public class CmdFactionsVoteShow extends FactionsCommandWarp -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsVoteShow() - { - // Parameters - this.addParameter(TypeVote.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - Vote vote = TypeVote.get(msenderFaction).read(this.arg(), sender); - - // Clean the vote - vote.clean(); - - // Message - message(Txt.titleize("Votes for " + vote.getName())); - - int numberOfVotes = vote.getId2Vote().size(); - for (String option : vote.getOptions()) - { - long num = vote.getId2Vote().values().stream() - .filter(option::equalsIgnoreCase).count(); - - double percent = ((double) num / (double) numberOfVotes) * 100; - if (Double.isInfinite(percent)) percent = 0D; - String str = Txt.parse("%s: %d/%d (%.2f%%)", option, num, numberOfVotes, percent); - message(str); - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsWarp.java b/src/com/massivecraft/factions/cmd/CmdFactionsWarp.java deleted file mode 100644 index 31a54195..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsWarp.java +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index ba25f69e..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsWarpAdd.java +++ /dev/null @@ -1,85 +0,0 @@ -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.getPermSetwarp().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/CmdFactionsWarpGo.java b/src/com/massivecraft/factions/cmd/CmdFactionsWarpGo.java deleted file mode 100644 index 8d6cded8..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsWarpGo.java +++ /dev/null @@ -1,139 +0,0 @@ -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.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; -import com.massivecraft.massivecore.mixin.MixinTeleport; -import com.massivecraft.massivecore.mixin.TeleporterException; -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 CmdFactionsWarpGo extends FactionsCommandWarp -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsWarpGo() - { - // Parameters - this.addParameter(TypeWarp.get(), "warp"); - this.addParameter(TypeFaction.get(), "faction", "you"); - - // Requirements - this.addRequirements(RequirementIsPlayer.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - 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)); - - // Must be valid - if (!warp.verifyIsValid()) return; - - // Any and MPerm - if ( ! MPerm.getPermWarp().has(msender, faction, true)) return; - - if ( ! MConf.get().warpsTeleportAllowedFromEnemyTerritory && msender.isInEnemyTerritory()) - { - throw new MassiveException().addMsg("You cannot teleport to %s while in the territory of an enemy faction.", warp); - } - - if ( ! MConf.get().warpsTeleportAllowedFromDifferentWorld && !me.getWorld().getName().equalsIgnoreCase(warp.getWorld())) - { - throw new MassiveException().addMsg("You cannot teleport to %s while in a different world.", warpDesc); - } - - 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().warpsTeleportAllowedEnemyDistance > 0 - && - factionHere.getFlag(MFlag.getFlagPvp()) - && - ( - ! msender.isInOwnTerritory() - || - ( - msender.isInOwnTerritory() - && - ! MConf.get().warpsTeleportIgnoreEnemiesIfInOwnTerritory - ) - ) - ) - { - World w = locationHere.getWorld(); - double x = locationHere.getX(); - double y = locationHere.getY(); - double z = locationHere.getZ(); - - for (Player p : w.getPlayers()) - { - if (MUtil.isntPlayer(p)) continue; - - if (!p.isOnline() || p.isDead() || p == me || p.getWorld() != w) continue; - - MPlayer fp = MPlayer.get(p); - 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().warpsTeleportAllowedEnemyDistance; - - // box-shaped distance check - if (dx > max || dy > max || dz > max) - continue; - - throw new MassiveException().addMsg("You cannot teleport to %s while an enemy is within %f blocks of you.", warpDesc, max); - } - } - - // Event - EventFactionsWarpTeleport event = new EventFactionsWarpTeleport(sender, warp); - event.run(); - if (event.isCancelled()) return; - - // Apply - try - { - Destination destination = new DestinationSimple(warp.getLocation(), warpDesc); - MixinTeleport.get().teleport(me, destination, sender); - } - catch (TeleporterException e) - { - String message = e.getMessage(); - MixinMessage.get().messageOne(me, message); - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsWarpList.java b/src/com/massivecraft/factions/cmd/CmdFactionsWarpList.java deleted file mode 100644 index 28801e56..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsWarpList.java +++ /dev/null @@ -1,48 +0,0 @@ -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.getPermWarp().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/CmdFactionsWarpRemove.java b/src/com/massivecraft/factions/cmd/CmdFactionsWarpRemove.java deleted file mode 100644 index 1fcceb01..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsWarpRemove.java +++ /dev/null @@ -1,55 +0,0 @@ -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.entity.Warp; -import com.massivecraft.factions.event.EventFactionsWarpRemove; -import com.massivecraft.massivecore.MassiveException; - -public class CmdFactionsWarpRemove extends FactionsCommandWarp -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsWarpRemove() - { - // Parameters - this.addParameter(TypeWarp.get(), "warp"); - this.addParameter(TypeFaction.get(), "faction", "you"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - Faction faction = this.readArgAt(1, msenderFaction); - Warp warp = TypeWarp.get(faction).read(this.argAt(0), sender); - - // Any and MPerm - if ( ! MPerm.getPermSetwarp().has(msender, faction, true)) return; - - // Event - EventFactionsWarpRemove event = new EventFactionsWarpRemove(sender, faction, warp); - event.run(); - if (event.isCancelled()) return; - warp = event.getWarp(); - - // Apply - warp.detach(); - - // Inform - faction.msg("%s removed the warp %s for your faction.", msender.describeTo(msenderFaction, true), warp.getName()); - if (faction != msenderFaction) - { - msender.msg("You have removed the warp %s for %s.", warp.getName(), faction.getName(msender)); - } - } - -} diff --git a/src/com/massivecraft/factions/cmd/FactionsCommand.java b/src/com/massivecraft/factions/cmd/FactionsCommand.java deleted file mode 100644 index a3530d07..00000000 --- a/src/com/massivecraft/factions/cmd/FactionsCommand.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.command.MassiveCommand; - -public class FactionsCommand extends MassiveCommand -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public MPlayer msender; - public Faction msenderFaction; - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public FactionsCommand() - { - - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void senderFields(boolean set) - { - this.msender = set ? MPlayer.get(sender) : null; - this.msenderFaction = set ? this.msender.getFaction() : null; - } - -} diff --git a/src/com/massivecraft/factions/cmd/FactionsCommandDocumentation.java b/src/com/massivecraft/factions/cmd/FactionsCommandDocumentation.java deleted file mode 100644 index e0a2e5cc..00000000 --- a/src/com/massivecraft/factions/cmd/FactionsCommandDocumentation.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.req.ReqFactionWarpsEnabled; -import com.massivecraft.massivecore.mson.Mson; - -public class FactionsCommandDocumentation extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public FactionsCommandDocumentation() - { - this.addRequirements(ReqFactionWarpsEnabled.get()); - } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public int num = 1; - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void senderFields(boolean set) - { - super.senderFields(set); - - num = 1; - } - - // -------------------------------------------- // - // MESSAGE - // -------------------------------------------- // - - public void msgDoc(String msg, Object... args) - { - msg = "" + this.num++ + ") " + msg; - msg(msg, args); - } - - public void messageDoc(Mson message) - { - Mson mson = mson(Mson.parse("" + this.num++ + ") "), message); - message(mson); - } - -} diff --git a/src/com/massivecraft/factions/cmd/FactionsCommandWarp.java b/src/com/massivecraft/factions/cmd/FactionsCommandWarp.java deleted file mode 100644 index b9251d22..00000000 --- a/src/com/massivecraft/factions/cmd/FactionsCommandWarp.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.req.ReqFactionWarpsEnabled; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.massivecore.command.Visibility; - -public class FactionsCommandWarp extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public FactionsCommandWarp() - { - this.addRequirements(ReqFactionWarpsEnabled.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public Visibility getVisibility() - { - return MConf.get().warpsEnabled ? super.getVisibility() : Visibility.INVISIBLE; - } - -} diff --git a/src/com/massivecraft/factions/cmd/req/ReqBankCommandsEnabled.java b/src/com/massivecraft/factions/cmd/req/ReqBankCommandsEnabled.java deleted file mode 100644 index 34a8b53e..00000000 --- a/src/com/massivecraft/factions/cmd/req/ReqBankCommandsEnabled.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.massivecraft.factions.cmd.req; - -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.integration.Econ; -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 ReqBankCommandsEnabled extends RequirementAbstract -{ - // -------------------------------------------- // - // SERIALIZABLE - // -------------------------------------------- // - - private static final long serialVersionUID = 1L; - - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static ReqBankCommandsEnabled i = new ReqBankCommandsEnabled(); - public static ReqBankCommandsEnabled get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public boolean apply(CommandSender sender, MassiveCommand command) - { - return MConf.get().bankEnabled && Econ.isEnabled(); - } - - @Override - public String createErrorMessage(CommandSender sender, MassiveCommand command) - { - String what = !MConf.get().bankEnabled ? "banks" : "economy features"; - return Txt.parse("Faction %s are disabled.", what); - } - -} diff --git a/src/com/massivecraft/factions/cmd/req/ReqFactionWarpsEnabled.java b/src/com/massivecraft/factions/cmd/req/ReqFactionWarpsEnabled.java deleted file mode 100644 index 4fb2547c..00000000 --- a/src/com/massivecraft/factions/cmd/req/ReqFactionWarpsEnabled.java +++ /dev/null @@ -1,40 +0,0 @@ -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/req/ReqHasFaction.java b/src/com/massivecraft/factions/cmd/req/ReqHasFaction.java deleted file mode 100644 index 5fe0e528..00000000 --- a/src/com/massivecraft/factions/cmd/req/ReqHasFaction.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.massivecraft.factions.cmd.req; - -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.command.MassiveCommand; -import com.massivecraft.massivecore.command.requirement.RequirementAbstract; -import com.massivecraft.massivecore.util.MUtil; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.command.CommandSender; - -public class ReqHasFaction extends RequirementAbstract -{ - // -------------------------------------------- // - // SERIALIZABLE - // -------------------------------------------- // - - private static final long serialVersionUID = 1L; - - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static ReqHasFaction i = new ReqHasFaction(); - public static ReqHasFaction get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public boolean apply(CommandSender sender, MassiveCommand command) - { - if (MUtil.isntSender(sender)) return false; - - MPlayer mplayer = MPlayer.get(sender); - return mplayer.hasFaction(); - } - - @Override - public String createErrorMessage(CommandSender sender, MassiveCommand command) - { - return Txt.parse("You must belong to a faction to %s.", getDesc(command)); - } - -} diff --git a/src/com/massivecraft/factions/cmd/req/ReqHasntFaction.java b/src/com/massivecraft/factions/cmd/req/ReqHasntFaction.java deleted file mode 100644 index a00d7980..00000000 --- a/src/com/massivecraft/factions/cmd/req/ReqHasntFaction.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.massivecraft.factions.cmd.req; - -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.command.MassiveCommand; -import com.massivecraft.massivecore.command.requirement.RequirementAbstract; -import com.massivecraft.massivecore.util.MUtil; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.command.CommandSender; - -public class ReqHasntFaction extends RequirementAbstract -{ - // -------------------------------------------- // - // SERIALIZABLE - // -------------------------------------------- // - - private static final long serialVersionUID = 1L; - - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static ReqHasntFaction i = new ReqHasntFaction(); - public static ReqHasntFaction get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public boolean apply(CommandSender sender, MassiveCommand command) - { - if (MUtil.isntSender(sender)) return true; - - MPlayer mplayer = MPlayer.get(sender); - return !mplayer.hasFaction(); - } - - @Override - public String createErrorMessage(CommandSender sender, MassiveCommand command) - { - return Txt.parse("You must leave your current faction before you %s.", getDesc(command)); - } - -} diff --git a/src/com/massivecraft/factions/cmd/req/ReqRankIsAtLeast.java b/src/com/massivecraft/factions/cmd/req/ReqRankIsAtLeast.java deleted file mode 100644 index c19aed0a..00000000 --- a/src/com/massivecraft/factions/cmd/req/ReqRankIsAtLeast.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.massivecraft.factions.cmd.req; - -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.entity.Rank; -import com.massivecraft.massivecore.command.MassiveCommand; -import com.massivecraft.massivecore.command.requirement.RequirementAbstract; -import com.massivecraft.massivecore.util.MUtil; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.command.CommandSender; - -public class ReqRankIsAtLeast extends RequirementAbstract -{ - // -------------------------------------------- // - // SERIALIZABLE - // -------------------------------------------- // - - private static final long serialVersionUID = 1L; - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final Rank rank; - public Rank getRank() { return this.rank; } - - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - public static ReqRankIsAtLeast get(Rank rank) { return new ReqRankIsAtLeast(rank); } - private ReqRankIsAtLeast(Rank rank) { this.rank = rank; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public boolean apply(CommandSender sender, MassiveCommand command) - { - if (MUtil.isntSender(sender)) return false; - - MPlayer mplayer = MPlayer.get(sender); - return mplayer.getRank().isAtLeast(this.getRank()); - } - - @Override - public String createErrorMessage(CommandSender sender, MassiveCommand command) - { - return Txt.parse("You must be %s or higher to %s.", rank.getName(), getDesc(command)); - } - -} diff --git a/src/com/massivecraft/factions/cmd/req/ReqTaxEnabled.java b/src/com/massivecraft/factions/cmd/req/ReqTaxEnabled.java deleted file mode 100644 index d0ce5da8..00000000 --- a/src/com/massivecraft/factions/cmd/req/ReqTaxEnabled.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.massivecraft.factions.cmd.req; - -import com.massivecraft.factions.task.TaskTax; -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 ReqTaxEnabled extends RequirementAbstract -{ - // -------------------------------------------- // - // SERIALIZABLE - // -------------------------------------------- // - - private static final long serialVersionUID = 1L; - - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static ReqTaxEnabled i = new ReqTaxEnabled(); - public static ReqTaxEnabled get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public boolean apply(CommandSender sender, MassiveCommand command) - { - return TaskTax.get().areConditionsMet(); - } - - @Override - public String createErrorMessage(CommandSender sender, MassiveCommand command) - { - return Txt.parse("Tax is not enabled on this server."); - } - -} diff --git a/src/com/massivecraft/factions/cmd/type/TypeEntityInternalFaction.java b/src/com/massivecraft/factions/cmd/type/TypeEntityInternalFaction.java deleted file mode 100644 index 91224c38..00000000 --- a/src/com/massivecraft/factions/cmd/type/TypeEntityInternalFaction.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.massivecraft.factions.cmd.type; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.collections.MassiveSet; -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; -import java.util.Set; - - -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); - } - - @Override - public Collection getTabList(CommandSender sender, String arg) - { - if (this.getFaction() != null) return super.getTabList(sender, arg); - - // Default to tab list for the sender - Faction faction = MPlayer.get(sender).getFaction(); - - // Create - Set ret = new MassiveSet<>(); - - // Fill - for (E value : this.getAll(faction)) - { - ret.addAll(this.createTabs(value)); - } - - // Return - return ret; - } - -} diff --git a/src/com/massivecraft/factions/cmd/type/TypeFaction.java b/src/com/massivecraft/factions/cmd/type/TypeFaction.java deleted file mode 100644 index e6c33bf6..00000000 --- a/src/com/massivecraft/factions/cmd/type/TypeFaction.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.massivecraft.factions.cmd.type; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.FactionColl; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.entity.MPlayerColl; -import com.massivecraft.massivecore.MassiveCore; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.TypeAbstract; -import com.massivecraft.massivecore.comparator.ComparatorCaseInsensitive; -import com.massivecraft.massivecore.util.IdUtil; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; - -import java.util.Collection; -import java.util.Set; -import java.util.TreeSet; - -public class TypeFaction extends TypeAbstract -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static TypeFaction i = new TypeFaction(); - public static TypeFaction get() { return i; } - public TypeFaction() { super(Faction.class); } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getVisualInner(Faction value, CommandSender sender) - { - return value.describeTo(MPlayer.get(sender)); - } - - @Override - public String getNameInner(Faction value) - { - return ChatColor.stripColor(value.getName()); - } - - @Override - public Faction read(String str, CommandSender sender) throws MassiveException - { - Faction ret; - - // Nothing/Remove targets Wilderness - if (MassiveCore.NOTHING_REMOVE.contains(str)) - { - return FactionColl.get().getNone(); - } - - // Faction Id Exact - if (FactionColl.get().containsId(str)) - { - ret = FactionColl.get().get(str); - if (ret != null) return ret; - } - - // Faction Name Exact - ret = FactionColl.get().getByName(str); - if (ret != null) return ret; - - // MPlayer Name Exact - String id = IdUtil.getId(str); - if (id != null) - { - MPlayer mplayer = MPlayerColl.get().get(id, false); - if (mplayer != null) - { - return mplayer.getFaction(); - } - } - - throw new MassiveException().addMsg("No faction or player matching \"

%s\".", str); - } - - @Override - public Collection getTabList(CommandSender sender, String arg) - { - // Create - Set ret = new TreeSet<>(ComparatorCaseInsensitive.get()); - - // Fill - for (Faction faction : FactionColl.get().getAll()) - { - ret.add(ChatColor.stripColor(faction.getName())); - } - - // Return - return ret; - } - -} diff --git a/src/com/massivecraft/factions/cmd/type/TypeFactionChunkChangeType.java b/src/com/massivecraft/factions/cmd/type/TypeFactionChunkChangeType.java deleted file mode 100644 index ddcecda4..00000000 --- a/src/com/massivecraft/factions/cmd/type/TypeFactionChunkChangeType.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.massivecraft.factions.cmd.type; - -import com.massivecraft.factions.event.EventFactionsChunkChangeType; -import com.massivecraft.massivecore.command.type.enumeration.TypeEnum; - -public class TypeFactionChunkChangeType extends TypeEnum -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static TypeFactionChunkChangeType i = new TypeFactionChunkChangeType(); - public static TypeFactionChunkChangeType get() { return i; } - public TypeFactionChunkChangeType() - { - super(EventFactionsChunkChangeType.class); - } - -} diff --git a/src/com/massivecraft/factions/cmd/type/TypeFactionNameAbstract.java b/src/com/massivecraft/factions/cmd/type/TypeFactionNameAbstract.java deleted file mode 100644 index 8c08321d..00000000 --- a/src/com/massivecraft/factions/cmd/type/TypeFactionNameAbstract.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.massivecraft.factions.cmd.type; - -import com.massivecraft.factions.entity.FactionColl; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.util.MiscUtil; -import com.massivecraft.massivecore.Named; -import com.massivecraft.massivecore.command.type.TypeNameAbstract; -import org.bukkit.command.CommandSender; - -public class TypeFactionNameAbstract extends TypeNameAbstract -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public TypeFactionNameAbstract(boolean strict) - { - super(strict); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public Named getCurrent(CommandSender sender) - { - MPlayer mplayer = MPlayer.get(sender); - return mplayer.getFaction(); - } - - @Override - public boolean isNameTaken(String name) - { - return FactionColl.get().isNameTaken(name); - } - - @Override - public boolean isCharacterAllowed(char character) - { - return MiscUtil.substanceChars.contains(String.valueOf(character)); - } - - @Override - public Integer getLengthMin() - { - return MConf.get().factionNameLengthMin; - } - - @Override - public Integer getLengthMax() - { - return MConf.get().factionNameLengthMax; - } - -} diff --git a/src/com/massivecraft/factions/cmd/type/TypeFactionNameLenient.java b/src/com/massivecraft/factions/cmd/type/TypeFactionNameLenient.java deleted file mode 100644 index 42cd0e93..00000000 --- a/src/com/massivecraft/factions/cmd/type/TypeFactionNameLenient.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.massivecraft.factions.cmd.type; - -public class TypeFactionNameLenient extends TypeFactionNameAbstract -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static TypeFactionNameLenient i = new TypeFactionNameLenient(); - public static TypeFactionNameLenient get() { return i; } - public TypeFactionNameLenient() - { - super(false); - } - -} diff --git a/src/com/massivecraft/factions/cmd/type/TypeFactionNameStrict.java b/src/com/massivecraft/factions/cmd/type/TypeFactionNameStrict.java deleted file mode 100644 index 476a4c82..00000000 --- a/src/com/massivecraft/factions/cmd/type/TypeFactionNameStrict.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.massivecraft.factions.cmd.type; - -public class TypeFactionNameStrict extends TypeFactionNameAbstract -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static TypeFactionNameStrict i = new TypeFactionNameStrict(); - public static TypeFactionNameStrict get() {return i; } - public TypeFactionNameStrict() - { - super(true); - } - -} diff --git a/src/com/massivecraft/factions/cmd/type/TypeMFlag.java b/src/com/massivecraft/factions/cmd/type/TypeMFlag.java deleted file mode 100644 index aa0793d3..00000000 --- a/src/com/massivecraft/factions/cmd/type/TypeMFlag.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.massivecraft.factions.cmd.type; - -import com.massivecraft.factions.entity.MFlag; -import com.massivecraft.factions.entity.MFlagColl; -import com.massivecraft.massivecore.command.type.store.TypeEntity; - -import java.util.Collection; - -public class TypeMFlag extends TypeEntity -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static TypeMFlag i = new TypeMFlag(); - public static TypeMFlag get() { return i; } - public TypeMFlag() - { - super(MFlagColl.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getName() - { - return "faction flag"; - } - - @Override - public Collection getAll() - { - return MFlag.getAll(); - } - -} diff --git a/src/com/massivecraft/factions/cmd/type/TypeMPerm.java b/src/com/massivecraft/factions/cmd/type/TypeMPerm.java deleted file mode 100644 index f7c4f333..00000000 --- a/src/com/massivecraft/factions/cmd/type/TypeMPerm.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.massivecraft.factions.cmd.type; - -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.MPermColl; -import com.massivecraft.massivecore.command.type.store.TypeEntity; - -import java.util.Collection; - -public class TypeMPerm extends TypeEntity -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static TypeMPerm i = new TypeMPerm(); - public static TypeMPerm get() { return i; } - public TypeMPerm() - { - super(MPermColl.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getName() - { - return "faction permission"; - } - - @Override - public Collection getAll() - { - return MPerm.getAll(); - } - - -} diff --git a/src/com/massivecraft/factions/cmd/type/TypeMPermable.java b/src/com/massivecraft/factions/cmd/type/TypeMPermable.java deleted file mode 100644 index c158a4c9..00000000 --- a/src/com/massivecraft/factions/cmd/type/TypeMPermable.java +++ /dev/null @@ -1,203 +0,0 @@ -package com.massivecraft.factions.cmd.type; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.FactionColl; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.entity.Rank; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.collections.MassiveList; -import com.massivecraft.massivecore.command.type.TypeAbstract; -import com.massivecraft.massivecore.util.MUtil; -import org.bukkit.command.CommandSender; - -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; - -public class TypeMPermable extends TypeAbstract -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static TypeMPermable i = new TypeMPermable(); - public static TypeMPermable get() { return i; } - private TypeMPermable() - { - super(Rank.class); - - this.faction = null; - } - - public static TypeMPermable get(Faction faction) { return new TypeMPermable(faction); } - public TypeMPermable(Faction faction) - { - super(MPerm.MPermable.class); - if (faction == null) throw new NullPointerException("faction"); - - this.faction = faction; - } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final Faction faction; - public Faction getFaction() { return this.faction; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public MPerm.MPermable read(String arg, CommandSender sender) throws MassiveException - { - if (arg.toLowerCase().startsWith("rank-")) - { - String subArg = arg.substring("rank-".length()); - return new TypeRank(this.getFaction()).read(subArg, sender); - } - - if (arg.toLowerCase().startsWith("relation-")) - { - String subArg = arg.substring("relation-".length()); - return TypeRelation.get().read(subArg, sender); - } - - if (arg.toLowerCase().startsWith("player-")) - { - String subArg = arg.substring("player-".length()); - return TypeMPlayer.get().read(subArg, sender); - } - - if (arg.toLowerCase().startsWith("faction-")) - { - String subArg = arg.substring("faction-".length()); - return TypeFaction.get().read(subArg, sender); - } - - TypeRank typeRank = new TypeRank(this.getFaction()); - try - { - return typeRank.read(arg, sender); - } - catch (MassiveException ex) - { - // Do nothing - } - - try - { - return TypeRelation.get().read(arg, sender); - } - catch (MassiveException ex) - { - // Do nothing - } - - try - { - return TypeMPlayer.get().read(arg, sender); - } - catch (MassiveException ex) - { - // Do nothing - } - - try - { - return TypeFaction.get().read(arg, sender); - } - catch (MassiveException ex) - { - // Do nothing - } - - if (arg.contains("-")) - { - int idx = arg.indexOf('-'); - String factionName = arg.substring(0, idx); - String rankName = arg.substring(idx+1); - - Faction faction = TypeFaction.get().read(factionName, sender); - return TypeRank.get(faction).read(rankName, sender); - } - - throw new MassiveException().addMsg("No rank, relation, player or faction matches: %s.", arg); - } - - public Collection getTabList(CommandSender sender, String arg) - { - List ret = new MassiveList<>(); - Faction faction = this.getFaction(); - if (faction == null) faction = MPlayer.get(sender).getFaction(); - - // Always add ranks, relations, other factions and other players - ret.addAll(faction.getRanks().getAll().stream().map(Rank::getName).collect(Collectors.toList())); - ret.addAll(TypeRelation.get().getTabList(sender, arg)); - ret.addAll(TypeFaction.get().getTabList(sender, arg)); - ret.addAll(TypeMPlayer.get().getTabList(sender, arg)); - - // If something has been specified, then suggest factin specific ranks - if (arg.length() >= 2) - { - for (Faction f : FactionColl.get().getAll()) - { - String name = f.getName(); - if (arg.length() <= name.length() && !name.toLowerCase().startsWith(arg.toLowerCase())) continue; - if (arg.length() > name.length() && !arg.toLowerCase().startsWith(name.toLowerCase())) continue; - - ret.addAll(f.getRanks().getAll().stream().map(r -> name + "-" + r.getName()).collect(Collectors.toList())); - } - } - - // Also add the cases for when type is specified - if (arg.length() >= 2) - { - String compArg = arg.toLowerCase(); - if (compArg.startsWith("rank-") || "rank-".startsWith(compArg)) - { - ret.addAll(faction.getRanks().getAll().stream() - .map(Rank::getName) - .map(n -> "rank-" + n) - .collect(Collectors.toList())); - } - if (compArg.startsWith("relation-") || "relation-".startsWith(compArg)) - { - ret.addAll(TypeRelation.get().getTabList(sender, arg).stream() - .map(s -> "relation-" + s) - .collect(Collectors.toList())); - } - if (compArg.startsWith("faction-") || "faction-".startsWith(compArg)) - { - ret.addAll(TypeFaction.get().getTabList(sender, arg).stream() - .map(s -> "faction-" + s) - .collect(Collectors.toList())); - } - if (compArg.startsWith("player-") || "player-".startsWith(compArg)) - { - ret.addAll(TypeMPlayer.get().getTabList(sender, arg).stream() - .map(s -> "player-" + s) - .collect(Collectors.toList())); - } - } - else - { - // Or at least add the beginning - ret.addAll(MUtil.list("rank-", "relation-", "faction-", "player-")); - } - - return ret; - } - - - @Override - public boolean isValid(String arg, CommandSender sender) - { - // In the generic case accept all - if (this.getFaction() == null) return true; - else return super.isValid(arg, sender); - } - -} diff --git a/src/com/massivecraft/factions/cmd/type/TypeMPlayer.java b/src/com/massivecraft/factions/cmd/type/TypeMPlayer.java deleted file mode 100644 index 66bffd20..00000000 --- a/src/com/massivecraft/factions/cmd/type/TypeMPlayer.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.massivecraft.factions.cmd.type; - -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.entity.MPlayerColl; -import com.massivecraft.massivecore.command.type.Type; - -public class TypeMPlayer -{ - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - public static Type get() - { - return MPlayerColl.get().getTypeEntity(); - } - -} diff --git a/src/com/massivecraft/factions/cmd/type/TypeRank.java b/src/com/massivecraft/factions/cmd/type/TypeRank.java deleted file mode 100644 index f4bc3b1d..00000000 --- a/src/com/massivecraft/factions/cmd/type/TypeRank.java +++ /dev/null @@ -1,113 +0,0 @@ -package com.massivecraft.factions.cmd.type; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.Rank; -import com.massivecraft.massivecore.collections.MassiveList; -import com.massivecraft.massivecore.collections.MassiveSet; -import org.bukkit.command.CommandSender; - -import java.util.Collection; -import java.util.List; - -import java.util.Set; - -public class TypeRank extends TypeEntityInternalFaction -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static TypeRank i = new TypeRank(); - public static TypeRank get() { return i; } - private TypeRank() - { - super(Rank.class); - this.currentRank = null; - } - - @Deprecated public static TypeRank get(Faction faction) { return new TypeRank(faction, null); } - @Deprecated public TypeRank(Faction faction) - { - this(faction, null); - } - - public static TypeRank get(Faction faction, Rank rank) { return new TypeRank(faction, rank); } - public TypeRank(Faction faction, Rank rank) - { - super(Rank.class, faction); - this.currentRank = rank; - - // When setAll is done in the super constructor some optimisations are done - // which don't take the promote/demote thing into account. - this.setAll(this.getAll(faction)); - } - - private final Rank currentRank; - - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public Collection getAll(Faction faction) - { - return faction.getRanks().getAll(); - } - - @Override - public Collection getTabList(CommandSender sender, String arg) - { - List ret = new MassiveList<>(super.getTabList(sender, arg)); - ret.add("promote"); - ret.add("demote"); - return ret; - } - - @Override - public Set getNamesInner(Rank value) - { - Set names = new MassiveSet<>(); - names.add(value.getName()); - - if (this.currentRank != null) - { - // You can't use "promote" to make someone leader. - Rank promote = getPromote(currentRank); - if (value == promote && !promote.isLeader()) names.add("promote"); - - if (value == getDemote(currentRank)) names.add("demote"); - } - - return names; - } - - private static Rank getPromote(Rank rank) - { - Rank ret = null; - for (Rank r : rank.getFaction().getRanks().getAll()) - { - if (rank == r) continue; - if (rank.isMoreThan(r)) continue; - if (ret != null && ret.isLessThan(r)) continue; - - ret = r; - } - return ret; - } - - private static Rank getDemote(Rank rank) - { - Rank ret = null; - for (Rank r : rank.getFaction().getRanks().getAll()) - { - if (rank == r) continue; - if (rank.isLessThan(r)) continue; - if (ret != null && ret.isMoreThan(r)) continue; - - ret = r; - } - return ret; - } - -} diff --git a/src/com/massivecraft/factions/cmd/type/TypeRel.java b/src/com/massivecraft/factions/cmd/type/TypeRel.java deleted file mode 100644 index 7ad6c3bd..00000000 --- a/src/com/massivecraft/factions/cmd/type/TypeRel.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.massivecraft.factions.cmd.type; - -import com.massivecraft.factions.Rel; -import com.massivecraft.massivecore.command.type.enumeration.TypeEnum; - -import java.util.Set; - -public class TypeRel extends TypeEnum -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static TypeRel i = new TypeRel(); - public static TypeRel get() { return i; } - public TypeRel() { super(Rel.class); } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getName() - { - return "relation"; - } - - @Override - public String getNameInner(Rel value) - { - return value.getName(); - } - - @Override - public Set getNamesInner(Rel value) - { - return value.getNames(); - } - -} diff --git a/src/com/massivecraft/factions/cmd/type/TypeRelation.java b/src/com/massivecraft/factions/cmd/type/TypeRelation.java deleted file mode 100644 index 88a77a7d..00000000 --- a/src/com/massivecraft/factions/cmd/type/TypeRelation.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.massivecraft.factions.cmd.type; - -import com.massivecraft.factions.Rel; - -public class TypeRelation extends TypeRel -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static TypeRelation i = new TypeRelation(); - public static TypeRelation get() { return i; } - public TypeRelation() { this.setAll(Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.ENEMY); } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getName() - { - return "relation"; - } - -} diff --git a/src/com/massivecraft/factions/cmd/type/TypeSortMPlayer.java b/src/com/massivecraft/factions/cmd/type/TypeSortMPlayer.java deleted file mode 100644 index 404e2e2c..00000000 --- a/src/com/massivecraft/factions/cmd/type/TypeSortMPlayer.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.massivecraft.factions.cmd.type; - -import com.massivecraft.factions.comparator.ComparatorMPlayerInactivity; -import com.massivecraft.factions.comparator.ComparatorMPlayerPower; -import com.massivecraft.factions.comparator.ComparatorMPlayerRole; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.command.type.TypeAbstractChoice; - -import java.util.Comparator; - -public class TypeSortMPlayer extends TypeAbstractChoice> -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static TypeSortMPlayer i = new TypeSortMPlayer(); - public static TypeSortMPlayer get() { return i; } - public TypeSortMPlayer() - { - super(Comparator.class); - this.setAll( - ComparatorMPlayerRole.get(), - ComparatorMPlayerPower.get(), - ComparatorMPlayerInactivity.get() - ); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getName() - { - return "player sorter"; - } - -} diff --git a/src/com/massivecraft/factions/cmd/type/TypeTaxable.java b/src/com/massivecraft/factions/cmd/type/TypeTaxable.java deleted file mode 100644 index a9fe89a4..00000000 --- a/src/com/massivecraft/factions/cmd/type/TypeTaxable.java +++ /dev/null @@ -1,136 +0,0 @@ -package com.massivecraft.factions.cmd.type; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.entity.Rank; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.collections.MassiveList; -import com.massivecraft.massivecore.command.type.TypeAbstract; -import com.massivecraft.massivecore.util.MUtil; -import org.bukkit.command.CommandSender; - -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; - -// TODO: This whole thing is a copy/paste of TypeMPermable. Duplicate code. -public class TypeTaxable extends TypeAbstract -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static TypeTaxable i = new TypeTaxable(); - public static TypeTaxable get() { return i; } - private TypeTaxable() - { - super(String.class); - - this.faction = null; - } - - public static TypeTaxable get(Faction faction) { return new TypeTaxable(faction); } - public TypeTaxable(Faction faction) - { - super(String.class); - if (faction == null) throw new NullPointerException("faction"); - - this.faction = faction; - } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final Faction faction; - public Faction getFaction() { return this.faction; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String read(String arg, CommandSender sender) throws MassiveException - { - if (arg.toLowerCase().startsWith("rank-")) - { - String subArg = arg.substring("rank-".length()); - return new TypeRank(this.getFaction()).read(subArg, sender).getId(); - } - - if (arg.toLowerCase().startsWith("player-")) - { - String subArg = arg.substring("player-".length()); - return TypeMPlayer.get().read(subArg, sender).getId(); - } - - - TypeRank typeRank = new TypeRank(this.getFaction()); - try - { - return typeRank.read(arg, sender).getId(); - } - catch (MassiveException ex) - { - // Do nothing - } - - try - { - return TypeMPlayer.get().read(arg, sender).getId(); - } - catch (MassiveException ex) - { - // Do nothing - } - - throw new MassiveException().addMsg("No rank or player matches: %s.", arg); - } - - public Collection getTabList(CommandSender sender, String arg) - { - List ret = new MassiveList<>(); - Faction faction = this.getFaction(); - if (faction == null) faction = MPlayer.get(sender).getFaction(); - - // Always add ranks, relations, other factions and other players - ret.addAll(faction.getRanks().getAll().stream().map(Rank::getName).collect(Collectors.toList())); - ret.addAll(TypeMPlayer.get().getTabList(sender, arg)); - - // Also add the cases for when type is specified - if (arg.length() >= 2) - { - String compArg = arg.toLowerCase(); - if (compArg.startsWith("rank-") || "rank-".startsWith(compArg)) - { - ret.addAll(faction.getRanks().getAll().stream() - .map(Rank::getName) - .map(n -> "rank-" + n) - .collect(Collectors.toList())); - } - if (compArg.startsWith("player-") || "player-".startsWith(compArg)) - { - ret.addAll(TypeMPlayer.get().getTabList(sender, arg).stream() - .map(s -> "player-" + s) - .collect(Collectors.toList())); - } - } - else - { - // Or at least add the beginning - ret.addAll(MUtil.list("rank-", "player-")); - } - - return ret; - } - - - @Override - public boolean isValid(String arg, CommandSender sender) - { - // In the generic case accept all - if (this.getFaction() == null) return true; - else return super.isValid(arg, sender); - } - -} diff --git a/src/com/massivecraft/factions/cmd/type/TypeVote.java b/src/com/massivecraft/factions/cmd/type/TypeVote.java deleted file mode 100644 index 7ea3447d..00000000 --- a/src/com/massivecraft/factions/cmd/type/TypeVote.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.massivecraft.factions.cmd.type; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.Vote; - -import java.util.Collection; - -public class TypeVote extends TypeEntityInternalFaction -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static TypeVote i = new TypeVote(); - public static TypeVote get() { return i; } - private TypeVote() - { - super(Vote.class); - } - - public static TypeVote get(Faction faction) { return new TypeVote(faction); } - public TypeVote(Faction faction) - { - super(Vote.class, faction); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public Collection getAll(Faction faction) - { - return faction.getVotes().getAll(); - } - -} diff --git a/src/com/massivecraft/factions/cmd/type/TypeWarp.java b/src/com/massivecraft/factions/cmd/type/TypeWarp.java deleted file mode 100644 index 9cdba36a..00000000 --- a/src/com/massivecraft/factions/cmd/type/TypeWarp.java +++ /dev/null @@ -1,37 +0,0 @@ -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/comparator/ComparatorFactionList.java b/src/com/massivecraft/factions/comparator/ComparatorFactionList.java deleted file mode 100644 index 74de992f..00000000 --- a/src/com/massivecraft/factions/comparator/ComparatorFactionList.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.massivecraft.factions.comparator; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.massivecore.comparator.ComparatorAbstract; -import com.massivecraft.massivecore.comparator.ComparatorComparable; -import com.massivecraft.massivecore.util.IdUtil; -import org.bukkit.command.CommandSender; - -import java.lang.ref.WeakReference; - -public class ComparatorFactionList extends ComparatorAbstract -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final WeakReference watcher; - public CommandSender getWatcher() { return this.watcher.get(); } - - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - public static ComparatorFactionList get(Object watcherObject) { return new ComparatorFactionList(watcherObject); } - public ComparatorFactionList(Object watcherObject) - { - this.watcher = new WeakReference<>(IdUtil.getSender(watcherObject)); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public int compareInner(Faction f1, Faction f2) - { - // None a.k.a. Wilderness - if (f1.isNone() && f2.isNone()) return 0; - if (f1.isNone()) return -1; - if (f2.isNone()) return 1; - - // Players Online - int ret = f2.getMPlayersWhereOnlineTo(this.getWatcher()).size() - f1.getMPlayersWhereOnlineTo(this.getWatcher()).size(); - if (ret != 0) return ret; - - // Players Total - ret = f2.getMPlayers().size() - f1.getMPlayers().size(); - if (ret != 0) return ret; - - // Tie by Id - return ComparatorComparable.get().compare(f1.getId(), f2.getId()); - } - -} diff --git a/src/com/massivecraft/factions/comparator/ComparatorMPlayerInactivity.java b/src/com/massivecraft/factions/comparator/ComparatorMPlayerInactivity.java deleted file mode 100644 index 967874ca..00000000 --- a/src/com/massivecraft/factions/comparator/ComparatorMPlayerInactivity.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.massivecraft.factions.comparator; - -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.Named; -import com.massivecraft.massivecore.comparator.ComparatorAbstract; - -public class ComparatorMPlayerInactivity extends ComparatorAbstract implements Named -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static ComparatorMPlayerInactivity i = new ComparatorMPlayerInactivity(); - public static ComparatorMPlayerInactivity get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getName() - { - return "Time"; - } - - @Override - public int compareInner(MPlayer m1, MPlayer m2) - { - // Online - boolean o1 = m1.isOnline(); - boolean o2 = m2.isOnline(); - - if (o1 && o2) return 0; - else if (o1) return -1; - else if (o2) return +1; - - // Inactivity Time - long r1 = m1.getLastActivityMillis(); - long r2 = m2.getLastActivityMillis(); - - return (int) (r1 - r2); - } - -} diff --git a/src/com/massivecraft/factions/comparator/ComparatorMPlayerPower.java b/src/com/massivecraft/factions/comparator/ComparatorMPlayerPower.java deleted file mode 100644 index 5fd01fdc..00000000 --- a/src/com/massivecraft/factions/comparator/ComparatorMPlayerPower.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.massivecraft.factions.comparator; - -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.Named; -import com.massivecraft.massivecore.comparator.ComparatorAbstract; - -public class ComparatorMPlayerPower extends ComparatorAbstract implements Named -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static ComparatorMPlayerPower i = new ComparatorMPlayerPower(); - public static ComparatorMPlayerPower get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getName() - { - return "Power"; - } - - @Override - public int compareInner(MPlayer m1, MPlayer m2) - { - // Power - int ret = m1.getPowerRounded() - m2.getPowerRounded(); - if (ret != 0) return ret; - - // MaxPower - return m1.getPowerMaxRounded() - m2.getPowerMaxRounded(); - } - -} diff --git a/src/com/massivecraft/factions/comparator/ComparatorMPlayerRole.java b/src/com/massivecraft/factions/comparator/ComparatorMPlayerRole.java deleted file mode 100644 index fabcbf80..00000000 --- a/src/com/massivecraft/factions/comparator/ComparatorMPlayerRole.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.massivecraft.factions.comparator; - -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.entity.Rank; -import com.massivecraft.massivecore.Named; -import com.massivecraft.massivecore.comparator.ComparatorAbstract; - -public class ComparatorMPlayerRole extends ComparatorAbstract implements Named -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static ComparatorMPlayerRole i = new ComparatorMPlayerRole(); - public static ComparatorMPlayerRole get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getName() - { - return "Rank"; - } - - @Override - public int compareInner(MPlayer m1, MPlayer m2) - { - // Rank - if (m1.getFaction() != m2.getFaction()) throw new IllegalArgumentException("Noncomparable players"); - Rank r1 = m1.getRank(); - Rank r2 = m2.getRank(); - return r2.getPriority() - r1.getPriority() ; - } - -} diff --git a/src/com/massivecraft/factions/engine/DisallowCause.java b/src/com/massivecraft/factions/engine/DisallowCause.java deleted file mode 100644 index c585547e..00000000 --- a/src/com/massivecraft/factions/engine/DisallowCause.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.massivecraft.factions.engine; - -public enum DisallowCause -{ - // -------------------------------------------- // - // ENUM - // -------------------------------------------- // - - PEACEFUL_LAND, - FACTIONLESS, - FRIENDLYFIRE, - OWN_TERRITORY - - // END OF LIST - -} diff --git a/src/com/massivecraft/factions/engine/EngineCanCombatHappen.java b/src/com/massivecraft/factions/engine/EngineCanCombatHappen.java deleted file mode 100644 index 02a18b84..00000000 --- a/src/com/massivecraft/factions/engine/EngineCanCombatHappen.java +++ /dev/null @@ -1,257 +0,0 @@ -package com.massivecraft.factions.engine; - -import com.massivecraft.factions.Rel; -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.MPlayer; -import com.massivecraft.factions.event.EventFactionsPvpDisallowed; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.MUtil; -import org.bukkit.entity.Arrow; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.entity.Trident; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.entity.AreaEffectCloudApplyEvent; -import org.bukkit.event.entity.EntityCombustByEntityEvent; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.PotionSplashEvent; -import org.bukkit.projectiles.ProjectileSource; - -import java.util.ArrayList; -import java.util.List; - -public class EngineCanCombatHappen extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineCanCombatHappen i = new EngineCanCombatHappen(); - public static EngineCanCombatHappen get() { return i; } - - // -------------------------------------------- // - // CAN COMBAT DAMAGE HAPPEN - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void canCombatDamageHappen(EntityDamageByEntityEvent event) - { - if (this.canCombatDamageHappen(event, true)) return; - event.setCancelled(true); - - Entity damager = event.getDamager(); - if (damager instanceof Arrow && !(damager instanceof Trident) ) - { - damager.remove(); - } - - - } - - // mainly for flaming arrows; don't want allies or people in safe zones to be ignited even after damage event is cancelled - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void canCombatDamageHappen(EntityCombustByEntityEvent event) - { - EntityDamageByEntityEvent sub = new EntityDamageByEntityEvent(event.getCombuster(), event.getEntity(), EntityDamageEvent.DamageCause.FIRE, 0D); - if (this.canCombatDamageHappen(sub, false)) return; - event.setCancelled(true); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void canCombatDamageHappen(PotionSplashEvent event) - { - // If a harmful potion is splashing ... - if (!MUtil.isHarmfulPotion(event.getPotion())) return; - - ProjectileSource projectileSource = event.getPotion().getShooter(); - if (! (projectileSource instanceof Entity)) return; - - Entity thrower = (Entity)projectileSource; - - // ... scan through affected entities to make sure they're all valid targets. - for (LivingEntity affectedEntity : event.getAffectedEntities()) - { - EntityDamageByEntityEvent sub = new EntityDamageByEntityEvent(thrower, affectedEntity, EntityDamageEvent.DamageCause.CUSTOM, 0D); - if (this.canCombatDamageHappen(sub, true)) continue; - - // affected entity list doesn't accept modification (iter.remove() is a no-go), but this works - event.setIntensity(affectedEntity, 0.0); - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void canCombatDamageHappen(AreaEffectCloudApplyEvent event) - { - // If a harmful potion effect cloud is present ... - if ( ! MUtil.isHarmfulPotion(event.getEntity().getBasePotionData().getType().getEffectType())) return; - - ProjectileSource projectileSource = event.getEntity().getSource(); - if ( ! (projectileSource instanceof Entity)) return; - - Entity thrower = (Entity)projectileSource; - - // ... create a dummy list to avoid ConcurrentModificationException ... - List affectedList = new ArrayList<>(); - - // ... then scan through affected entities to make sure they're all valid targets ... - for (LivingEntity affectedEntity : event.getAffectedEntities()) - { - EntityDamageByEntityEvent sub = new EntityDamageByEntityEvent(thrower, affectedEntity, EntityDamageEvent.DamageCause.CUSTOM, 0D); - // Notification disabled due to the iterating nature of effect clouds. - if (EngineCanCombatHappen.get().canCombatDamageHappen(sub, false)) continue; - - affectedList.add(affectedEntity); - } - - // finally, remove valid targets from the affected list. (Unlike splash potions, area effect cloud's affected entities list is mutable.) - event.getAffectedEntities().removeAll(affectedList); - } - - // Utility method used in "canCombatDamageHappen" below. - public static boolean falseUnlessDisallowedPvpEventCancelled(Player attacker, Player defender, DisallowCause reason, EntityDamageByEntityEvent event) - { - EventFactionsPvpDisallowed dpe = new EventFactionsPvpDisallowed(attacker, defender, reason, event); - dpe.run(); - return dpe.isCancelled(); - } - - public boolean canCombatDamageHappen(EntityDamageByEntityEvent event, boolean notify) - { - boolean ret = true; - - // If the defender is a player ... - Entity edefender = event.getEntity(); - if (MUtil.isntPlayer(edefender)) return true; - Player defender = (Player)edefender; - MPlayer mdefender = MPlayer.get(edefender); - - // ... and the attacker is someone else ... - Entity eattacker = MUtil.getLiableDamager(event); - - // (we check null here since there may not be an attacker) - // (lack of attacker situations can be caused by other bukkit plugins) - if (eattacker != null && eattacker.equals(edefender)) return true; - - // ... gather defender PS and faction information ... - PS defenderPs = PS.valueOf(defender.getLocation()); - Faction defenderPsFaction = BoardColl.get().getFactionAt(defenderPs); - - // ... fast evaluate if the attacker is overriding ... - if (MUtil.isPlayer(eattacker)) - { - - MPlayer mplayer = MPlayer.get(eattacker); - if (mplayer != null && mplayer.isOverriding()) return true; - } - - // ... PVP flag may cause a damage block ... - if (defenderPsFaction.getFlag(MFlag.getFlagPvp()) == false) - { - if (eattacker == null) - { - // No attacker? - // Let's behave as if it were a player - return falseUnlessDisallowedPvpEventCancelled(null, defender, DisallowCause.PEACEFUL_LAND, event); - } - if (MUtil.isPlayer(eattacker)) - { - ret = falseUnlessDisallowedPvpEventCancelled((Player)eattacker, defender, DisallowCause.PEACEFUL_LAND, event); - if (!ret && notify) - { - MPlayer attacker = MPlayer.get(eattacker); - attacker.msg("PVP is disabled in %s.", defenderPsFaction.describeTo(attacker)); - } - return ret; - } - return defenderPsFaction.getFlag(MFlag.getFlagMonsters()); - } - - // ... and if the attacker is a player ... - if (MUtil.isntPlayer(eattacker)) return true; - Player attacker = (Player)eattacker; - MPlayer uattacker = MPlayer.get(attacker); - - // ... does this player bypass all protection? ... - if (MConf.get().playersWhoBypassAllProtection.contains(attacker.getName())) return true; - - // ... gather attacker PS and faction information ... - PS attackerPs = PS.valueOf(attacker.getLocation()); - Faction attackerPsFaction = BoardColl.get().getFactionAt(attackerPs); - - // ... PVP flag may cause a damage block ... - // (just checking the defender as above isn't enough. What about the attacker? It could be in a no-pvp area) - // NOTE: This check is probably not that important but we could keep it anyways. - if (attackerPsFaction.getFlag(MFlag.getFlagPvp()) == false) - { - ret = falseUnlessDisallowedPvpEventCancelled(attacker, defender, DisallowCause.PEACEFUL_LAND, event); - if (!ret && notify) uattacker.msg("PVP is disabled in %s.", attackerPsFaction.describeTo(uattacker)); - return ret; - } - - // ... are PVP rules completely ignored in this world? ... - if (!MConf.get().worldsPvpRulesEnabled.contains(defenderPs.getWorld())) return true; - - Faction defendFaction = mdefender.getFaction(); - Faction attackFaction = uattacker.getFaction(); - - if (attackFaction.isNone() && MConf.get().disablePVPForFactionlessPlayers) - { - ret = falseUnlessDisallowedPvpEventCancelled(attacker, defender, DisallowCause.FACTIONLESS, event); - if (!ret && notify) uattacker.msg("You can't hurt other players until you join a faction."); - return ret; - } - else if (defendFaction.isNone()) - { - if (defenderPsFaction == attackFaction && MConf.get().enablePVPAgainstFactionlessInAttackersLand) - { - // Allow PVP vs. Factionless in attacker's faction territory - return true; - } - else if (MConf.get().disablePVPForFactionlessPlayers) - { - ret = falseUnlessDisallowedPvpEventCancelled(attacker, defender, DisallowCause.FACTIONLESS, event); - if (!ret && notify) uattacker.msg("You can't hurt players who are not currently in a faction."); - return ret; - } - else if (attackFaction.isNone() && MConf.get().enablePVPBetweenFactionlessPlayers) - { - // Allow factionless vs factionless - return true; - } - } - - Rel relation = defendFaction.getRelationTo(attackFaction); - - // Check the relation - if (relation.isFriend() && defenderPsFaction.getFlag(MFlag.getFlagFriendlyire()) == false) - { - ret = falseUnlessDisallowedPvpEventCancelled(attacker, defender, DisallowCause.FRIENDLYFIRE, event); - if (!ret && notify) uattacker.msg("You can't hurt %s.", relation.getDescPlayerMany()); - return ret; - } - - // You can not hurt neutrals in their own territory. - boolean ownTerritory = mdefender.isInOwnTerritory(); - - if (mdefender.hasFaction() && ownTerritory && relation == Rel.NEUTRAL) - { - ret = falseUnlessDisallowedPvpEventCancelled(attacker, defender, DisallowCause.OWN_TERRITORY, event); - if (!ret && notify) - { - uattacker.msg("You can't hurt %s in their own territory unless you declare them as an enemy.", mdefender.describeTo(uattacker)); - mdefender.msg("%s tried to hurt you.", uattacker.describeTo(mdefender, true)); - } - return ret; - } - - return true; - } - -} diff --git a/src/com/massivecraft/factions/engine/EngineChat.java b/src/com/massivecraft/factions/engine/EngineChat.java deleted file mode 100644 index dce78aac..00000000 --- a/src/com/massivecraft/factions/engine/EngineChat.java +++ /dev/null @@ -1,178 +0,0 @@ -package com.massivecraft.factions.engine; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.Rel; -import com.massivecraft.factions.RelationParticipator; -import com.massivecraft.factions.chat.ChatFormatter; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.event.EventMassiveCorePlayerToRecipientChat; -import com.massivecraft.massivecore.util.MUtil; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.EventException; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.plugin.EventExecutor; - -import java.util.Iterator; -import java.util.function.Predicate; - -public class EngineChat extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineChat i = new EngineChat(); - public static EngineChat get() { return i; } - public EngineChat() - { - this.setPlugin(Factions.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void setActiveInner(boolean active) - { - if ( ! active) return; - - if (MConf.get().chatSetFormat) - { - Bukkit.getPluginManager().registerEvent(AsyncPlayerChatEvent.class, this, MConf.get().chatSetFormatAt, new SetFormatEventExecutor(), Factions.get(), true); - } - - if (MConf.get().chatParseTags) - { - Bukkit.getPluginManager().registerEvent(AsyncPlayerChatEvent.class, this, MConf.get().chatParseTagsAt, new ParseTagsEventExecutor(), Factions.get(), true); - } - - if (MConf.get().chatParseTags) - { - Bukkit.getPluginManager().registerEvent(EventMassiveCorePlayerToRecipientChat.class, this, EventPriority.NORMAL, new ParseRelcolorEventExecutor(), Factions.get(), true); - } - } - - // -------------------------------------------- // - // SET FORMAT - // -------------------------------------------- // - - private class SetFormatEventExecutor implements EventExecutor - { - @Override - public void execute(Listener listener, Event event) throws EventException - { - try - { - if (!(event instanceof AsyncPlayerChatEvent)) return; - setFormat((AsyncPlayerChatEvent)event); - } - catch (Throwable t) - { - throw new EventException(t); - } - } - } - - public static void setFormat(AsyncPlayerChatEvent event) - { - event.setFormat(MConf.get().chatSetFormatTo); - } - - // -------------------------------------------- // - // PARSE TAGS - // -------------------------------------------- // - - private class ParseTagsEventExecutor implements EventExecutor - { - @Override - public void execute(Listener listener, Event event) throws EventException - { - try - { - if (!(event instanceof AsyncPlayerChatEvent)) return; - parseTags((AsyncPlayerChatEvent)event); - } - catch (Throwable t) - { - throw new EventException(t); - } - } - } - - public static void parseTags(AsyncPlayerChatEvent event) - { - Player player = event.getPlayer(); - if (MUtil.isntPlayer(player)) return; - - String format = event.getFormat(); - format = ChatFormatter.format(format, player, null); - event.setFormat(format); - } - - // -------------------------------------------- // - // PARSE RELCOLOR - // -------------------------------------------- // - - private class ParseRelcolorEventExecutor implements EventExecutor - { - @Override - public void execute(Listener listener, Event event) throws EventException - { - try - { - if (!(event instanceof EventMassiveCorePlayerToRecipientChat)) return; - parseRelcolor((EventMassiveCorePlayerToRecipientChat)event); - } - catch (Throwable t) - { - throw new EventException(t); - } - } - } - - public static void parseRelcolor(EventMassiveCorePlayerToRecipientChat event) - { - String format = event.getFormat(); - format = ChatFormatter.format(format, event.getSender(), event.getRecipient()); - event.setFormat(format); - } - - // -------------------------------------------- // - // FILTER CHAT CHANNEL - // -------------------------------------------- // - - public static Predicate getPredicateIsInFaction(RelationParticipator participator) - { - return player -> MPlayer.get(player).getRelationTo(participator).isAtLeast(Rel.FACTION); - } - - public static Predicate getPredicateIsAlly(RelationParticipator participator) - { - return player -> MPlayer.get(player).getFaction().getRelationTo(participator).isAtLeast(Rel.ALLY); - } - - public static void filterToPredicate(AsyncPlayerChatEvent event, Predicate predicate) - { - Player player = event.getPlayer(); - MPlayer mplayer = MPlayer.get(player); - Faction faction = mplayer.getFaction(); - - // Get and filter recipients - for (Iterator it = event.getRecipients().iterator(); it.hasNext();) - { - Player recipient = it.next(); - if (predicate.test(recipient)) continue; - - it.remove(); - } - } - -} diff --git a/src/com/massivecraft/factions/engine/EngineChunkChange.java b/src/com/massivecraft/factions/engine/EngineChunkChange.java deleted file mode 100644 index e9c2309a..00000000 --- a/src/com/massivecraft/factions/engine/EngineChunkChange.java +++ /dev/null @@ -1,292 +0,0 @@ -package com.massivecraft.factions.engine; - -import com.massivecraft.factions.Rel; -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.FactionColl; -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.EventFactionsChunksChange; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.collections.MassiveList; -import com.massivecraft.massivecore.collections.MassiveSet; -import com.massivecraft.massivecore.mixin.MixinWorld; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.ChatColor; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; - -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -public class EngineChunkChange extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineChunkChange i = new EngineChunkChange(); - public static EngineChunkChange get() { return i; } - - // -------------------------------------------- // - // CHUNK CHANGE: ALLOWED - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) - public void onChunksChange(EventFactionsChunksChange event) - { - // For security reasons we block the chunk change on any error since an error might block security checks from happening. - try - { - onChunksChangeInner(event); - } - catch (Throwable throwable) - { - event.setCancelled(true); - throwable.printStackTrace(); - } - } - - public void onChunksChangeInner(EventFactionsChunksChange event) - { - // Args - final MPlayer mplayer = event.getMPlayer(); - final Faction newFaction = event.getNewFaction(); - final Map> currentFactionChunks = event.getOldFactionChunks(); - final Set currentFactions = currentFactionChunks.keySet(); - final Set chunks = event.getChunks(); - - // Override Mode? Sure! - if (mplayer.isOverriding()) return; - - // CALC: Is there at least one normal faction among the current ones? - boolean currentFactionsContainsAtLeastOneNormal = false; - for (Faction currentFaction : currentFactions) - { - if (currentFaction.isNormal()) - { - currentFactionsContainsAtLeastOneNormal = true; - break; - } - } - - // If the new faction is normal (not wilderness/none), meaning if we are claiming for a faction ... - if (newFaction.isNormal()) - { - // ... ensure claiming is enabled for the worlds of all chunks ... - for (PS chunk : chunks) - { - String worldId = chunk.getWorld(); - if ( ! MConf.get().worldsClaimingEnabled.contains(worldId)) - { - String worldName = MixinWorld.get().getWorldDisplayName(worldId); - mplayer.msg("Land claiming is disabled in %s.", worldName); - event.setCancelled(true); - return; - } - } - - // ... ensure we have permission to alter the territory of the new faction ... - if ( ! MPerm.getPermTerritory().has(mplayer, newFaction, true)) - { - // NOTE: No need to send a message. We send message from the permission check itself. - event.setCancelled(true); - return; - } - - // ... ensure the new faction has enough players to claim ... - if (newFaction.getMPlayers().size() < MConf.get().claimsRequireMinFactionMembers) - { - mplayer.msg("Factions must have at least %s members to claim land.", MConf.get().claimsRequireMinFactionMembers); - event.setCancelled(true); - return; - } - - int claimedLandCount = newFaction.getLandCount(); - if ( ! newFaction.getFlag(MFlag.getFlagInfpower())) - { - // ... ensure the claim would not bypass the global max limit ... - if (MConf.get().claimedLandsMax != 0 && claimedLandCount + chunks.size() > MConf.get().claimedLandsMax) - { - mplayer.msg("Limit reached. You can't claim more land."); - event.setCancelled(true); - return; - } - - // ... ensure the claim would not bypass the global world limit ... - if (MConf.get().claimedWorldsMax >= 0) - { - Set oldWorlds = newFaction.getClaimedWorlds(); - Set newWorlds = PS.getDistinctWorlds(chunks); - - Set worlds = new MassiveSet<>(); - worlds.addAll(oldWorlds); - worlds.addAll(newWorlds); - - if (!oldWorlds.containsAll(newWorlds) && worlds.size() > MConf.get().claimedWorldsMax) - { - List 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("A faction may only be present on %d different %s.", MConf.get().claimedWorldsMax, worldsMax); - mplayer.msg("%s is already present on %d %s:", newFaction.describeTo(mplayer), oldWorlds.size(), worldsAlready); - mplayer.message(Txt.implodeCommaAndDot(worldNames, ChatColor.YELLOW.toString())); - mplayer.msg("Please unclaim bases on other worlds to claim here."); - - event.setCancelled(true); - return; - } - } - - } - - // ... ensure the claim would not bypass the faction power ... - if (claimedLandCount + chunks.size() > newFaction.getPowerRounded()) - { - mplayer.msg("You don't have enough power to claim that land."); - event.setCancelled(true); - return; - } - - // ... ensure the claim would not violate distance to neighbors ... - // HOW: Calculate the factions nearby, excluding the chunks themselves, the faction itself and the wilderness faction. - // HOW: The chunks themselves will be handled in the "if (oldFaction.isNormal())" section below. - Set nearbyChunks = BoardColl.getNearbyChunks(chunks, MConf.get().claimMinimumChunksDistanceToOthers); - nearbyChunks.removeAll(chunks); - Set nearbyFactions = BoardColl.getDistinctFactions(nearbyChunks); - nearbyFactions.remove(FactionColl.get().getNone()); - nearbyFactions.remove(newFaction); - // HOW: Next we check if the new faction has permission to claim nearby the nearby factions. - MPerm claimnear = MPerm.getPermClaimnear(); - for (Faction nearbyFaction : nearbyFactions) - { - if (claimnear.has(mplayer, nearbyFaction, true)) continue; - event.setCancelled(true); - return; - } - - // ... ensure claims are properly connected ... - if - ( - // If claims must be connected ... - MConf.get().claimsMustBeConnected - // ... and this faction already has claimed something on this map (meaning it's not their first claim) ... - && - newFaction.getLandCountInWorld(chunks.iterator().next().getWorld()) > 0 - // ... and none of the chunks are connected to an already claimed chunk for the faction ... - && - ! BoardColl.get().isAnyConnectedPs(chunks, newFaction) - // ... and either claims must always be connected or there is at least one normal faction among the old factions ... - && - ( ! MConf.get().claimsCanBeUnconnectedIfOwnedByOtherFaction || currentFactionsContainsAtLeastOneNormal) - ) - { - if (MConf.get().claimsCanBeUnconnectedIfOwnedByOtherFaction) - { - mplayer.msg("You can only claim additional land which is connected to your first claim or controlled by another faction!"); - } - else - { - mplayer.msg("You can only claim additional land which is connected to your first claim!"); - } - event.setCancelled(true); - return; - } - } - - // Ensure claims are properly connected when unclaiming - if (newFaction.isNone() && MConf.get().claimsMustBeConnected && MConf.get().claimsMustBeConnectedStrict) - { - for (Entry> entry : currentFactionChunks.entrySet()) - { - Faction faction = entry.getKey(); - Set factionRemovedChunks = entry.getValue(); - - Set pssBefore = BoardColl.get().getChunks(faction); - - // Get how many "forests" of claims there are right now - List> forestsBefore = BoardColl.getForests(pssBefore); - - Set pssAfter = new MassiveSet<>(pssBefore); - pssAfter.removeAll(factionRemovedChunks); - - List> forestsAfter = BoardColl.getForests(pssAfter); - if (forestsAfter.size() > forestsBefore.size()) - { - mplayer.msg("Claims must be connected. You can't make them disconnected by unclaiming."); - event.setCancelled(true); - return; - } - } - } - - // For each of the old factions ... - for (Entry> entry : currentFactionChunks.entrySet()) - { - Faction oldFaction = entry.getKey(); - Set oldChunks = entry.getValue(); - - // ... that is an actual faction ... - if (oldFaction.isNone()) continue; - - // ... for which the mplayer lacks permission ... - if (MPerm.getPermTerritory().has(mplayer, oldFaction, false)) continue; - - // ... consider all reasons to forbid "overclaiming/warclaiming" ... - - // ... claiming from others may be forbidden ... - if ( ! MConf.get().claimingFromOthersAllowed) - { - mplayer.msg("You may not claim land from others."); - event.setCancelled(true); - return; - } - - // ... and they must actually be claiming ... - if (newFaction.isNone()) - { - mplayer.msg("You can't unclaim land belonging to others."); - event.setCancelled(true); - return; - } - - // ... the relation may forbid ... - if (oldFaction.getRelationTo(newFaction).isAtLeast(Rel.TRUCE)) - { - mplayer.msg("You can't claim this land due to your relation with the current owner."); - event.setCancelled(true); - return; - } - - // ... the old faction might not be inflated enough ... - if (oldFaction.getPowerRounded() > oldFaction.getLandCount() - oldChunks.size() && MConf.get().claimingFromOthersMustBeInflated) - { - mplayer.msg("%s owns this land and is strong enough to keep it.", oldFaction.getName(mplayer)); - event.setCancelled(true); - return; - } - - // ... and you might be trying to claim without starting at the border ... - if ( ! BoardColl.get().isAnyBorderPs(chunks)) - { - mplayer.msg("You must start claiming land at the border of the territory."); - event.setCancelled(true); - return; - } - - // ... otherwise you may claim from this old faction even though you lack explicit permission from them. - } - } - -} diff --git a/src/com/massivecraft/factions/engine/EngineCleanInactivity.java b/src/com/massivecraft/factions/engine/EngineCleanInactivity.java deleted file mode 100644 index 8107c508..00000000 --- a/src/com/massivecraft/factions/engine/EngineCleanInactivity.java +++ /dev/null @@ -1,97 +0,0 @@ -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.MPlayerColl; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.event.EventMassiveCorePlayerCleanInactivityToleranceMillis; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; - -import java.util.Map; -import java.util.Map.Entry; - -public class EngineCleanInactivity extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineCleanInactivity i = new EngineCleanInactivity(); - public static EngineCleanInactivity get() { return i; } - - // -------------------------------------------- // - // REMOVE PLAYER MILLIS - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void ageBonus(EventMassiveCorePlayerCleanInactivityToleranceMillis event) - { - if (event.getColl() != MPlayerColl.get()) return; - - applyPlayerAgeBonus(event); - applyFactionAgeBonus(event); - } - - public void applyPlayerAgeBonus(EventMassiveCorePlayerCleanInactivityToleranceMillis event) - { - // Calculate First Played - Long firstPlayed = event.getEntity().getFirstPlayed(); - Long age = 0L; - if (firstPlayed != null) - { - age = System.currentTimeMillis() - firstPlayed; - } - - // Calculate the Bonus! - Long bonus = calculateBonus(age, MConf.get().cleanInactivityToleranceMillisPlayerAgeToBonus); - if (bonus == null) return; - - // Apply - event.getToleranceCauseMillis().put("Player Age Bonus", bonus); - } - - public void applyFactionAgeBonus(EventMassiveCorePlayerCleanInactivityToleranceMillis event) - { - // Calculate Faction Age - Faction faction = ((MPlayer)event.getEntity()).getFaction(); - long age = 0L; - if ( ! faction.isNone()) - { - age = faction.getAge(); - } - - // Calculate the Bonus! - Long bonus = calculateBonus(age, MConf.get().cleanInactivityToleranceMillisFactionAgeToBonus); - if (bonus == null) return; - - // Apply - event.getToleranceCauseMillis().put("Faction Age Bonus", bonus); - } - - private Long calculateBonus(long age, Map ageToBonus) - { - if (ageToBonus.isEmpty()) return null; - - Long bonus = 0L; - for (Entry entry : ageToBonus.entrySet()) - { - Long key = entry.getKey(); - if (key == null) continue; - - Long value = entry.getValue(); - if (value == null) continue; - - if (age >= key) - { - bonus = value; - break; - } - } - - return bonus; - } - - -} diff --git a/src/com/massivecraft/factions/engine/EngineDenyCommands.java b/src/com/massivecraft/factions/engine/EngineDenyCommands.java deleted file mode 100644 index 3bb770ca..00000000 --- a/src/com/massivecraft/factions/engine/EngineDenyCommands.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.massivecraft.factions.engine; - -import com.massivecraft.factions.Rel; -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.MPlayer; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.MUtil; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; - -import java.util.List; - -public class EngineDenyCommands extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineDenyCommands i = new EngineDenyCommands(); - public static EngineDenyCommands get() { return i; } - - // -------------------------------------------- // - // DENY COMMANDS - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) - public void denyCommands(PlayerCommandPreprocessEvent event) - { - // If a player is trying to run a command ... - Player player = event.getPlayer(); - if (MUtil.isntPlayer(player)) return; - MPlayer mplayer = MPlayer.get(player); - - // ... and the player is not overriding ... - if (mplayer.isOverriding()) return; - - // ... clean up the command ... - String command = event.getMessage(); - command = Txt.removeLeadingCommandDust(command); - command = command.toLowerCase(); - command = command.trim(); - - // ... the command may be denied for members of permanent factions ... - if (mplayer.hasFaction() && mplayer.getFaction().getFlag(MFlag.getFlagPermanent()) && MUtil.containsCommand(command, MConf.get().denyCommandsPermanentFactionMember)) - { - mplayer.msg("You can't use \"/%s\" as member of a permanent faction.", command); - event.setCancelled(true); - return; - } - - // ... if there is a faction at the players location we fetch the relation now ... - PS ps = PS.valueOf(player.getLocation()).getChunk(true); - Faction factionAtPs = BoardColl.get().getFactionAt(ps); - Rel factionAtRel = null; - - if (factionAtPs != null && ! factionAtPs.isNone()) - { - factionAtRel = factionAtPs.getRelationTo(mplayer); - } - - // ... there maybe be a player in the distance that denies the command ... - if (MConf.get().denyCommandsDistance > -1 && ! MConf.get().denyCommandsDistanceBypassIn.contains(factionAtRel)) - { - for (Player otherplayer : player.getWorld().getPlayers()) - { - MPlayer othermplayer = MPlayer.get(otherplayer); - if (othermplayer == mplayer) continue; - - double distance = player.getLocation().distance(otherplayer.getLocation()); - if (MConf.get().denyCommandsDistance > distance) continue; - - Rel playerRel = mplayer.getRelationTo(othermplayer); - if ( ! MConf.get().denyCommandsDistanceRelation.containsKey(playerRel)) continue; - - String desc = playerRel.getDescPlayerOne(); - - mplayer.msg("You can't use \"/%s\" as there is %s nearby.", command, desc); - event.setCancelled(true); - return; - } - } - - // ... if there is no relation here then there are no further checks ... - if (factionAtRel == null) return; - - List deniedCommands = MConf.get().denyCommandsTerritoryRelation.get(factionAtRel); - if (deniedCommands == null) return; - if ( ! MUtil.containsCommand(command, deniedCommands)) return; - - mplayer.msg("You can't use \"/%s\" in %s territory.", command, Txt.getNicedEnum(factionAtRel)); - event.setCancelled(true); - } - -} diff --git a/src/com/massivecraft/factions/engine/EngineDenyTeleport.java b/src/com/massivecraft/factions/engine/EngineDenyTeleport.java deleted file mode 100644 index 5488e178..00000000 --- a/src/com/massivecraft/factions/engine/EngineDenyTeleport.java +++ /dev/null @@ -1,130 +0,0 @@ -package com.massivecraft.factions.engine; - -import com.massivecraft.factions.Rel; -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.Couple; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.mixin.MixinMessage; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.MUtil; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; - -import java.util.List; -import java.util.Map.Entry; - -public class EngineDenyTeleport extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineDenyTeleport i = new EngineDenyTeleport(); - public static EngineDenyTeleport get() { return i; } - - // -------------------------------------------- // - // CAN COMBAT DAMAGE HAPPEN - // -------------------------------------------- // - - private enum TerritoryType - { - ENEMY, - WILDERNESS, - OWN, - OTHER - } - - @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) - public void canTeleportHappen(PlayerTeleportEvent event) - { - Entry entry = shouldBeCancelled(event); - if (entry == null) return; - - event.setCancelled(true); - - TeleportCause cause = entry.getKey(); - TerritoryType deny = entry.getValue(); - - String teleportDesc = Txt.getNicedEnum(cause); - String denyDesc = ""; - if (deny == TerritoryType.ENEMY) denyDesc = "enemy"; - if (deny == TerritoryType.WILDERNESS) denyDesc = "wilderness"; - if (deny == TerritoryType.OWN) denyDesc = "your own"; - if (deny == TerritoryType.OTHER) denyDesc = "other faction's"; - - Player player = event.getPlayer(); - MixinMessage.get().msgOne(player, "Teleportation with %s is not allowed in %s territory.", teleportDesc, denyDesc); - } - - private Entry shouldBeCancelled(PlayerTeleportEvent event) - { - Player player = event.getPlayer(); - if (MUtil.isntPlayer(player)) return null; - - MPlayer mplayer = MPlayer.get(player); - - PS from = PS.valueOf(event.getFrom()); - PS to = PS.valueOf(event.getTo()); - - TerritoryType typeFrom = getTerritoryType(mplayer, from); - TerritoryType typeTo = getTerritoryType(mplayer, to); - List types = MUtil.list(typeFrom, typeTo); - - TeleportCause cause = event.getCause(); - MConf mconf = MConf.get(); - - if (cause == TeleportCause.CHORUS_FRUIT) - { - if (!mconf.allowChorusFruitInEnemyTerritory && types.contains(TerritoryType.ENEMY)) - return Couple.valueOf(cause, TerritoryType.ENEMY); - - if (!mconf.allowChorusFruitInWildernessTerritory && types.contains(TerritoryType.WILDERNESS)) - return Couple.valueOf(cause, TerritoryType.WILDERNESS); - - if (!mconf.allowChorusFruitInOwnTerritory && types.contains(TerritoryType.OWN)) - return Couple.valueOf(cause, TerritoryType.OWN); - - if (!mconf.allowChorusFruitInOtherTerritory && types.contains(TerritoryType.OTHER)) - return Couple.valueOf(cause, TerritoryType.OTHER); - } - else if (cause == TeleportCause.ENDER_PEARL) - { - if (!mconf.allowEnderPearlInEnemyTerritory && types.contains(TerritoryType.ENEMY)) - return Couple.valueOf(cause, TerritoryType.ENEMY); - - if (!mconf.allowEnderPearlInWildernessTerritory && types.contains(TerritoryType.WILDERNESS)) - return Couple.valueOf(cause, TerritoryType.WILDERNESS); - - if (!mconf.allowEnderPearlInOwnTerritory && types.contains(TerritoryType.OWN)) - return Couple.valueOf(cause, TerritoryType.OWN); - - if (!mconf.allowEnderPearlInOtherTerritory && types.contains(TerritoryType.OTHER)) - return Couple.valueOf(cause, TerritoryType.OTHER); - } - else - { - // Don't cancel other kinds of teleports - } - - return null; - } - - private TerritoryType getTerritoryType(MPlayer mplayer, PS territory) - { - Faction territoryFaction = BoardColl.get().getFactionAt(territory); - Rel relation = territoryFaction.getRelationTo(mplayer); - - if (territoryFaction.isNone()) return TerritoryType.WILDERNESS; - if (relation == Rel.ENEMY) return TerritoryType.ENEMY; - if (relation == Rel.FACTION) return TerritoryType.OWN; - return TerritoryType.OTHER; - } - -} diff --git a/src/com/massivecraft/factions/engine/EngineEcon.java b/src/com/massivecraft/factions/engine/EngineEcon.java deleted file mode 100644 index 89292cad..00000000 --- a/src/com/massivecraft/factions/engine/EngineEcon.java +++ /dev/null @@ -1,263 +0,0 @@ -package com.massivecraft.factions.engine; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.cmd.CmdFactions; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.event.EventFactionsAbstractSender; -import com.massivecraft.factions.event.EventFactionsChunkChangeType; -import com.massivecraft.factions.event.EventFactionsChunksChange; -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.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; -import com.massivecraft.factions.event.EventFactionsNameChange; -import com.massivecraft.factions.event.EventFactionsRelationChange; -import com.massivecraft.factions.event.EventFactionsTitleChange; -import com.massivecraft.factions.integration.Econ; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.money.Money; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map.Entry; -import java.util.Set; - -public class EngineEcon extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineEcon i = new EngineEcon(); - public static EngineEcon get() { return i; } - - // -------------------------------------------- // - // TAKE ON LEAVE - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void takeOnLeave(EventFactionsMembershipChange event) - { - if (!Econ.isEnabled()) return; - - // If a player is leaving the faction ... - if (event.getReason() != MembershipChangeReason.LEAVE) return; - - // ... and that player was the last one in the faction ... - MPlayer mplayer = event.getMPlayer(); - Faction oldFaction = mplayer.getFaction(); - if (oldFaction.getMPlayers().size() > 1) return; - - // ... then transfer all money to the player. - double money = Econ.getMoney(oldFaction); - if (money == 0) return; - Econ.transferMoney(mplayer, oldFaction, mplayer, money); - } - - // -------------------------------------------- // - // TAKE ON DISBAND - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void takeOnDisband(EventFactionsDisband event) - { - // If there is a mplayer ... - MPlayer mplayer = event.getMPlayer(); - if (mplayer == null) return; - - // ... and economy is enabled ... - if (!Econ.isEnabled()) return; - - // ... then transfer all the faction money to the sender. - Faction faction = event.getFaction(); - - double amount = Econ.getMoney(faction); - - // Check that there is an amount - if (amount == 0) return; - - String amountString = Money.format(amount); - - Econ.transferMoney(faction, mplayer, mplayer, amount, true); - - mplayer.msg("You have been given the disbanded faction's bank, totaling %s.", amountString); - Factions.get().log(mplayer.getName() + " has been given bank holdings of "+amountString+" from disbanding "+faction.getName()+"."); - } - - // -------------------------------------------- // - // PAY FOR ACTION - // -------------------------------------------- // - - public static void payForAction(EventFactionsAbstractSender event, Double cost, String desc) - { - // If there is an mplayer ... - MPlayer mplayer = event.getMPlayer(); - if (mplayer == null) return; - - // ... and there is a cost ... - if (cost == null) return; - if (cost == 0) return; - - // ... that the sender can't afford ... - if (Econ.payForAction(cost, mplayer, desc)) return; - - // ... then cancel. - event.setCancelled(true); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForAction(EventFactionsChunksChange event) - { - double cost = 0; - List typeNames = new ArrayList<>(); - - for (Entry> typeChunks : event.getTypeChunks().entrySet()) - { - final EventFactionsChunkChangeType type = typeChunks.getKey(); - final Set chunks = typeChunks.getValue(); - - Double typeCost = MConf.get().econChunkCost.get(type); - if (typeCost == null) continue; - if (typeCost == 0) continue; - - typeCost *= chunks.size(); - cost += typeCost; - - typeNames.add(type.now); - } - - String desc = Txt.implodeCommaAnd(typeNames) + " this land"; - payForAction(event, cost, desc); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForAction(EventFactionsMembershipChange event) - { - Double cost = null; - String desc = null; - - if (event.getReason() == MembershipChangeReason.JOIN) - { - cost = MConf.get().econCostJoin; - desc = "join a faction"; - } - else if (event.getReason() == MembershipChangeReason.LEAVE) - { - cost = MConf.get().econCostLeave; - desc = "leave a faction"; - } - else if (event.getReason() == MembershipChangeReason.KICK) - { - cost = MConf.get().econCostKick; - desc = "kick someone from a faction"; - } - else - { - return; - } - - payForAction(event, cost, desc); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(EventFactionsRelationChange event) - { - Double cost = MConf.get().econRelCost.get(event.getNewRelation()); - String desc = CmdFactions.get().cmdFactionsRelation.cmdFactionsRelationSet.getDesc(); - payForAction(event, cost, desc); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(EventFactionsWarpAdd event) - { - 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) - { - Double cost = MConf.get().econCostCreate; - String desc = CmdFactions.get().cmdFactionsCreate.getDesc(); - - payForAction(event, cost, desc); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(EventFactionsDescriptionChange event) - { - Double cost = MConf.get().econCostDescription; - String desc = CmdFactions.get().cmdFactionsDescription.getDesc(); - - payForAction(event, cost, desc); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(EventFactionsNameChange event) - { - Double cost = MConf.get().econCostName; - String desc = CmdFactions.get().cmdFactionsName.getDesc(); - - payForAction(event, cost, desc); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(EventFactionsTitleChange event) - { - Double cost = MConf.get().econCostTitle; - String desc = CmdFactions.get().cmdFactionsTitle.getDesc(); - - payForAction(event, cost, desc); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(EventFactionsFlagChange event) - { - Double cost = MConf.get().econCostFlag; - String desc = CmdFactions.get().cmdFactionsFlag.getDesc(); - - payForAction(event, cost, desc); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(EventFactionsInvitedChange event) - { - Double cost = event.isNewInvited() ? MConf.get().econCostInvite : MConf.get().econCostDeinvite; - String desc = CmdFactions.get().cmdFactionsInvite.getDesc(); - - payForAction(event, cost, desc); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(EventFactionsWarpTeleport event) - { - Double cost = MConf.get().econCostWarpGo; - String desc = CmdFactions.get().cmdFactionsWarp.cmdFactionsWarpGo.getDesc(); - - payForAction(event, cost, desc); - } - -} diff --git a/src/com/massivecraft/factions/engine/EngineExploit.java b/src/com/massivecraft/factions/engine/EngineExploit.java deleted file mode 100644 index ed6086f1..00000000 --- a/src/com/massivecraft/factions/engine/EngineExploit.java +++ /dev/null @@ -1,212 +0,0 @@ -package com.massivecraft.factions.engine; - -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.collections.MassiveList; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.MUtil; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.block.BlockFromToEvent; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; - -import java.util.HashMap; -import java.util.List; -import java.util.UUID; - -public class EngineExploit extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineExploit i = new EngineExploit(); - public static EngineExploit get() { return i; } - - // -------------------------------------------- // - // OBSIDIAN GENERATORS - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void obsidianGenerators(BlockFromToEvent event) - { - if (!MConf.get().handleExploitObsidianGenerators) return; - - // thanks to ObGenBlocker and WorldGuard for this method - Block block = event.getToBlock(); - Material source = event.getBlock().getType(); - Material target = block.getType(); - if ((target == Material.REDSTONE_WIRE || target == Material.TRIPWIRE) && (source == Material.AIR || source == Material.LAVA)) - { - block.setType(Material.AIR); - } - } - - // -------------------------------------------- // - // ENDER PEARL CLIPPING - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void enderPearlClipping(PlayerTeleportEvent event) - { - if (!MConf.get().handleExploitEnderPearlClipping) return; - if (event.getCause() != PlayerTeleportEvent.TeleportCause.ENDER_PEARL) return; - - // this exploit works when the target location is within 0.31 blocks or so of a door or glass block or similar... - Location target = event.getTo(); - Location from = event.getFrom(); - - // blocks who occupy less than 1 block width or length wise need to be handled differently - Material mat = event.getTo().getBlock().getType(); - if ( - ((mat == Material.GLASS_PANE || mat == Material.IRON_BARS) && clippingThrough(target, from, 0.65)) - || ((MUtil.list(Material.ACACIA_FENCE, Material.BIRCH_FENCE, Material.DARK_OAK_FENCE, Material.JUNGLE_FENCE, Material.NETHER_BRICK_FENCE, Material.OAK_FENCE, Material.SPRUCE_FENCE).contains(mat)) && clippingThrough(target, from, 0.45)) - ) - { - event.setTo(from); - return; - } - - // simple fix otherwise: ender pearl target locations are standardized to be in the center (X/Z) of the target block, not at the edges - target.setX(target.getBlockX() + 0.5); - target.setZ(target.getBlockZ() + 0.5); - event.setTo(target); - - } - - public static boolean clippingThrough(Location target, Location from, double thickness) - { - return - ( - (from.getX() > target.getX() && (from.getX() - target.getX() < thickness)) - || (target.getX() > from.getX() && (target.getX() - from.getX() < thickness)) - || (from.getZ() > target.getZ() && (from.getZ() - target.getZ() < thickness)) - || (target.getZ() > from.getZ() && (target.getZ() - from.getZ() < thickness)) - ); - } - - // -------------------------------------------- // - // NETHER PORTAL TRAP - // -------------------------------------------- // - // A nether portal trap can be created by the destination portal being enclosed (trapped) - resulting in the player not being able to run commands. - // This fix removes the portal blocks (client side) from the destination until they are away from the portal. - - private static final int NETHER_TRAP_RADIUS_CHECK = 5; - private static final int NETHER_TRAP_RESET_RADIUS_SQUARED = 9; - - private HashMap> portalTraps = new HashMap<>(); - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void portalTrapRemoveAnimation(PlayerTeleportEvent event) - { - // If there is a teleport caused by a nether portal ... - if ( ! MConf.get().handleNetherPortalTrap || event.getCause() != TeleportCause.NETHER_PORTAL) return; - - Player player = event.getPlayer(); - Block from = event.getTo().getBlock(); - - // ... and the player can't build at the destination ... - if (EnginePermBuild.canPlayerBuildAt(player, PS.valueOf(from), false)) return; - - // ... reset the old portal blocks stored ... - this.portalReset(player); - - // ... get all the portal blocks belonging to the new portal at the destination ... - List portalTrap = getPortal(from); - if (portalTrap.isEmpty()) return; - - // ... and then store those blocks and send an update as if they were air. - this.portalTraps.put(player.getUniqueId(), portalTrap); - portalUpdateAir(player, portalTrap); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void portalUpdate(PlayerMoveEvent event) - { - // If a player moves ... - if ( ! MConf.get().handleNetherPortalTrap || MUtil.isSameBlock(event)) return; - - Player player = event.getPlayer(); - UUID uuid = player.getUniqueId(); - - // ... and he recently used a portal ... - List portalTrap = this.portalTraps.get(uuid); - if (portalTrap == null) return; - - Location locationTo = event.getTo(); - Location locationFrom = portalTrap.get(0).getLocation(); - - World worldTo = locationTo.getWorld(); - World worldFrom = locationFrom.getWorld(); - - // ... update reset the portal near them, if they have moved away too far ... - if ( ! worldTo.equals(worldFrom) || locationTo.distanceSquared(locationFrom) > NETHER_TRAP_RESET_RADIUS_SQUARED) - { - portalUpdateReset(player, portalTrap); - return; - } - - // ... or send an update as if the portal blocks were air. - portalUpdateAir(player, portalTrap); - } - - public void portalReset(Player player) - { - UUID uuid = player.getUniqueId(); - - // If a player has already a portal registered to him ... - List portalTrap = this.portalTraps.get(uuid); - if (portalTrap == null) return; - - // ... remove them from the registry ... - this.portalTraps.remove(uuid); - - // ... and send updates if the player and portal are in the same world. - if ( ! player.getWorld().equals(portalTrap.get(0).getWorld())) return; - portalUpdateReset(player, portalTrap); - } - - public static void portalUpdateReset(Player player, List portal) { portalUpdate(player, portal, null, null); } - public static void portalUpdateAir(Player player, List portal) { portalUpdate(player, portal, Material.AIR, (byte) 0); } - - @SuppressWarnings("deprecation") - private static void portalUpdate(Player player, List portal, Material material, Byte data) - { - boolean usingDefault = material == null && data == null; - for (Block block : portal) - { - Material updateMaterial = usingDefault ? block.getType() : material; - byte updateData = usingDefault ? block.getData() : data; - player.sendBlockChange(block.getLocation(), updateMaterial, updateData); - } - } - - public static List getPortal(Block from) - { - // Create - List ret = new MassiveList<>(); - - // Fill - Check in a radius of the block to find the portal blocks - for (int x = -(NETHER_TRAP_RADIUS_CHECK); x <= NETHER_TRAP_RADIUS_CHECK; x ++) - { - for (int y = -(NETHER_TRAP_RADIUS_CHECK); y <= NETHER_TRAP_RADIUS_CHECK; y ++) - { - for (int z = -(NETHER_TRAP_RADIUS_CHECK); z <= NETHER_TRAP_RADIUS_CHECK; z ++) - { - if (from.getRelative(x, y, z).getType() == Material.NETHER_PORTAL) ret.add(from.getRelative(x, y, z)); - } - } - } - - // Return - return ret; - } - -} diff --git a/src/com/massivecraft/factions/engine/EngineFlagEndergrief.java b/src/com/massivecraft/factions/engine/EngineFlagEndergrief.java deleted file mode 100644 index 7230531f..00000000 --- a/src/com/massivecraft/factions/engine/EngineFlagEndergrief.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.massivecraft.factions.engine; - -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MFlag; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.ps.PS; -import org.bukkit.entity.Enderman; -import org.bukkit.entity.Entity; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.entity.EntityChangeBlockEvent; - -public class EngineFlagEndergrief extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineFlagEndergrief i = new EngineFlagEndergrief(); - public static EngineFlagEndergrief get() { return i; } - - // -------------------------------------------- // - // FLAG: ENDERGRIEF - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void blockEndergrief(EntityChangeBlockEvent event) - { - // If an enderman is changing a block ... - Entity entity = event.getEntity(); - if (!(entity instanceof Enderman)) return; - - // ... and the faction there has endergrief disabled ... - PS ps = PS.valueOf(event.getBlock()); - Faction faction = BoardColl.get().getFactionAt(ps); - if (faction.getFlag(MFlag.getFlagEndergrief())) return; - - // ... stop the block alteration. - event.setCancelled(true); - } - -} diff --git a/src/com/massivecraft/factions/engine/EngineFlagExplosion.java b/src/com/massivecraft/factions/engine/EngineFlagExplosion.java deleted file mode 100644 index 0693e3c4..00000000 --- a/src/com/massivecraft/factions/engine/EngineFlagExplosion.java +++ /dev/null @@ -1,146 +0,0 @@ -package com.massivecraft.factions.engine; - -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.util.EnumerationUtil; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.ps.PS; -import org.bukkit.Location; -import org.bukkit.block.Block; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Wither; -import org.bukkit.event.Cancellable; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.block.BlockExplodeEvent; -import org.bukkit.event.entity.EntityChangeBlockEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityDamageEvent.DamageCause; -import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.hanging.HangingBreakEvent; -import org.bukkit.event.hanging.HangingBreakEvent.RemoveCause; - -import java.util.Collection; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -public class EngineFlagExplosion extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineFlagExplosion i = new EngineFlagExplosion(); - public static EngineFlagExplosion get() { return i; } - - // -------------------------------------------- // - // FLAG: EXPLOSIONS - // -------------------------------------------- // - - protected Set DAMAGE_CAUSE_EXPLOSIONS = EnumSet.of(DamageCause.BLOCK_EXPLOSION, DamageCause.ENTITY_EXPLOSION); - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void blockExplosion(HangingBreakEvent event) - { - // If a hanging entity was broken by an explosion ... - if (event.getCause() != RemoveCause.EXPLOSION) return; - Entity entity = event.getEntity(); - - // ... and the faction there has explosions disabled ... - Faction faction = BoardColl.get().getFactionAt(PS.valueOf(entity.getLocation())); - if (faction.isExplosionsAllowed()) return; - - // ... then cancel. - event.setCancelled(true); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void blockExplosion(EntityDamageEvent event) - { - // If an explosion damages ... - if ( ! DAMAGE_CAUSE_EXPLOSIONS.contains(event.getCause())) return; - - // ... an entity that is modified on damage ... - if ( ! EnumerationUtil.isEntityTypeEditOnDamage(event.getEntityType())) return; - - // ... and the faction has explosions disabled ... - if (BoardColl.get().getFactionAt(PS.valueOf(event.getEntity())).isExplosionsAllowed()) return; - - // ... then cancel! - event.setCancelled(true); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void blockExplosion(EntityExplodeEvent event) - { - Location location = event.getLocation(); - Cancellable cancellable = event; - Collection blocks = event.blockList(); - - blockExplosion(location, cancellable, blocks); - } - - // Note that this method is used by EngineV18 for the BlockExplodeEvent - public void blockExplosion(Location location, Cancellable cancellable, Collection blocks) - { - // Caching to speed things up. - Map faction2allowed = new HashMap<>(); - - // Check the entity. Are explosions disabled there? - Faction faction = BoardColl.get().getFactionAt(PS.valueOf(location)); - Boolean allowed = faction.isExplosionsAllowed(); - if (!allowed) - { - cancellable.setCancelled(true); - return; - } - faction2allowed.put(faction, allowed); - - // Individually check the flag state for each block - Iterator iterator = blocks.iterator(); - while (iterator.hasNext()) - { - Block block = iterator.next(); - faction = BoardColl.get().getFactionAt(PS.valueOf(block)); - allowed = faction2allowed.get(faction); - if (allowed == null) - { - allowed = faction.isExplosionsAllowed(); - faction2allowed.put(faction, allowed); - } - - if (!allowed) iterator.remove(); - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void blockExplosion(EntityChangeBlockEvent event) - { - // If a wither is changing a block ... - Entity entity = event.getEntity(); - if (!(entity instanceof Wither)) return; - - // ... and the faction there has explosions disabled ... - PS ps = PS.valueOf(event.getBlock()); - Faction faction = BoardColl.get().getFactionAt(ps); - - if (faction.isExplosionsAllowed()) return; - - // ... stop the block alteration. - event.setCancelled(true); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void blockExplosion(BlockExplodeEvent event) - { - Location location = event.getBlock().getLocation(); - Cancellable cancellable = event; - Collection blocks = event.blockList(); - - EngineFlagExplosion.get().blockExplosion(location, cancellable, blocks); - } - -} diff --git a/src/com/massivecraft/factions/engine/EngineFlagFireSpread.java b/src/com/massivecraft/factions/engine/EngineFlagFireSpread.java deleted file mode 100644 index 59474918..00000000 --- a/src/com/massivecraft/factions/engine/EngineFlagFireSpread.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.massivecraft.factions.engine; - -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MFlag; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.ps.PS; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.event.Cancellable; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.block.BlockBurnEvent; -import org.bukkit.event.block.BlockIgniteEvent; -import org.bukkit.event.block.BlockIgniteEvent.IgniteCause; -import org.bukkit.event.block.BlockSpreadEvent; - -public class EngineFlagFireSpread extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineFlagFireSpread i = new EngineFlagFireSpread(); - public static EngineFlagFireSpread get() { return i; } - - // -------------------------------------------- // - // FLAG: FIRE SPREAD - // -------------------------------------------- // - - public void blockFireSpread(Block block, Cancellable cancellable) - { - // If the faction at the block has firespread disabled ... - PS ps = PS.valueOf(block); - Faction faction = BoardColl.get().getFactionAt(ps); - - if (faction.getFlag(MFlag.getFlagFirespread())) return; - - // then cancel the event. - cancellable.setCancelled(true); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void blockFireSpread(BlockIgniteEvent event) - { - // If fire is spreading ... - if (event.getCause() != IgniteCause.SPREAD && event.getCause() != IgniteCause.LAVA) return; - - // ... consider blocking it. - blockFireSpread(event.getBlock(), event); - } - - // TODO: Is use of this event deprecated? - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void blockFireSpread(BlockSpreadEvent event) - { - // If fire is spreading ... - if (event.getNewState().getType() != Material.FIRE) return; - - // ... consider blocking it. - blockFireSpread(event.getBlock(), event); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void blockFireSpread(BlockBurnEvent event) - { - // If a block is burning ... - - // ... consider blocking it. - blockFireSpread(event.getBlock(), event); - } - -} diff --git a/src/com/massivecraft/factions/engine/EngineFlagSpawn.java b/src/com/massivecraft/factions/engine/EngineFlagSpawn.java deleted file mode 100644 index a2def31d..00000000 --- a/src/com/massivecraft/factions/engine/EngineFlagSpawn.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.massivecraft.factions.engine; - -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MFlag; -import com.massivecraft.factions.util.EnumerationUtil; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.collections.BackstringSet; -import com.massivecraft.massivecore.ps.PS; -import org.bukkit.Location; -import org.bukkit.entity.EntityType; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; - -import java.util.Set; - -public class EngineFlagSpawn extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineFlagSpawn i = new EngineFlagSpawn(); - public static EngineFlagSpawn get() { return i; } - - // -------------------------------------------- // - // CONSTANTS - // -------------------------------------------- // - - public static final Set NATURAL_SPAWN_REASONS = new BackstringSet<>(SpawnReason.class, - "NATURAL", - "JOCKEY", - "CHUNK_GEN", - "OCELOT_BABY", - "NETHER_PORTAL", - "MOUNT", - "REINFORCEMENTS", - "VILLAGE_DEFENSE", - "VILLAGE_INVASION", - "RAID", - "PATROL" - ); - - // -------------------------------------------- // - // FLAG: MONSTERS & ANIMALS - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void blockMonstersAndAnimals(CreatureSpawnEvent event) - { - // If this is a natural spawn .. - if ( ! NATURAL_SPAWN_REASONS.contains(event.getSpawnReason())) return; - - // ... get the spawn location ... - Location location = event.getLocation(); - PS ps = PS.valueOf(location); - - // ... get the faction there ... - Faction faction = BoardColl.get().getFactionAt(ps); - if (faction == null) return; - - // ... get the entity type ... - EntityType type = event.getEntityType(); - - // ... and if this type can't spawn in the faction ... - if (canSpawn(faction, type)) return; - - // ... then cancel. - event.setCancelled(true); - } - - public static boolean canSpawn(Faction faction, EntityType type) - { - if (EnumerationUtil.isEntityTypeMonster(type)) - { - // Monster - return faction.getFlag(MFlag.getFlagMonsters()); - } - else if (EnumerationUtil.isEntityTypeAnimal(type)) - { - // Animal - return faction.getFlag(MFlag.getFlagAnimals()); - } - else - { - // Other - return true; - } - } - -} diff --git a/src/com/massivecraft/factions/engine/EngineFlagZombiegrief.java b/src/com/massivecraft/factions/engine/EngineFlagZombiegrief.java deleted file mode 100644 index 327260d9..00000000 --- a/src/com/massivecraft/factions/engine/EngineFlagZombiegrief.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.massivecraft.factions.engine; - -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MFlag; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.ps.PS; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Zombie; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.entity.EntityBreakDoorEvent; - -public class EngineFlagZombiegrief extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineFlagZombiegrief i = new EngineFlagZombiegrief(); - public static EngineFlagZombiegrief get() { return i; } - - // -------------------------------------------- // - // FLAG: ZOMBIEGRIEF - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void denyZombieGrief(EntityBreakDoorEvent event) - { - // If a zombie is breaking a door ... - Entity entity = event.getEntity(); - if (!(entity instanceof Zombie)) return; - - // ... and the faction there has zombiegrief disabled ... - PS ps = PS.valueOf(event.getBlock()); - Faction faction = BoardColl.get().getFactionAt(ps); - if (faction.getFlag(MFlag.getFlagZombiegrief())) return; - - // ... stop the door breakage. - event.setCancelled(true); - } - -} diff --git a/src/com/massivecraft/factions/engine/EngineFly.java b/src/com/massivecraft/factions/engine/EngineFly.java deleted file mode 100644 index 03a86449..00000000 --- a/src/com/massivecraft/factions/engine/EngineFly.java +++ /dev/null @@ -1,230 +0,0 @@ -package com.massivecraft.factions.engine; - -import com.massivecraft.factions.Perm; -import com.massivecraft.factions.cmd.CmdFactions; -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.MFlagColl; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.event.EventFactionsFlagChange; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.event.EventMassiveCorePlayerUpdate; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.store.DriverFlatfile; -import com.massivecraft.massivecore.util.MUtil; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.player.PlayerMoveEvent; - -import java.io.File; - -public class EngineFly extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineFly i = new EngineFly(); - public static EngineFly get() { return i; } - - // -------------------------------------------- // - // LISTENER - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void onMassiveCorePlayerUpdate(EventMassiveCorePlayerUpdate event) - { - // If we are updating a player ... - Player player = event.getPlayer(); - if (MUtil.isntPlayer(player)) return; - - // ... and that player isn't in creative or spectator mode ... - if (EventMassiveCorePlayerUpdate.isFlyAllowed(player, false)) return; - - // ... and the player is alive ... - if (player.isDead()) return; - - MPlayer mplayer = MPlayer.get(player); - - // ... and the player enables flying ... - if (!mplayer.isFlying()) return; - - // ... and the player can fly here... - if (!canFlyInTerritory(mplayer, PS.valueOf(player))) return; - - // ... set allowed ... - event.setAllowed(true); - - // ... set speed ... - event.setFlySpeed(MConf.get().flySpeed); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void moveChunkDetect(PlayerMoveEvent event) - { - // If the player is moving from one chunk to another ... - if (MUtil.isSameChunk(event)) return; - Player player = event.getPlayer(); - if (MUtil.isntPlayer(player)) return; - - // ... gather info on the player and the move ... - MPlayer mplayer = MPlayer.get(player); - PS chunkTo = PS.valueOf(event.getTo()).getChunk(true); - - // ... and they are currently flying ... - if (!mplayer.isFlying()) return; - - // ... but can't fly at the new place ... - if (canFlyInTerritory(mplayer, chunkTo)) return; - - // ... then perhaps they should not be - mplayer.setFlying(false); - deactivateForPlayer(player); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void flagUpdate(EventFactionsFlagChange event) - { - if (event.getFlag() != MFlag.getFlagFly()) return; - if (event.isNewValue() == true) return; - - // Disable for all players when disabled - event.getFaction().getOnlinePlayers().forEach(EngineFly::deactivateForPlayer); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void territoryShield(EntityDamageByEntityEvent event) - { - // If flying is diabled on PVP ... - if (!MConf.get().flyDisableOnPvp) return; - - // ... and the defender is a player ... - Entity entity = event.getEntity(); - if (MUtil.isntPlayer(entity)) return; - Player defender = (Player)entity; - MPlayer mdefender = MPlayer.get(defender); - - // ... and the attacker is a player ... - Entity eattacker = MUtil.getLiableDamager(event); - if (! (eattacker instanceof Player)) return; - Player attacker = (Player) eattacker; - MPlayer mattacker = MPlayer.get(attacker); - - // ... disable flying for both - if (mdefender.isFlying()) - { - mdefender.setFlying(false); - deactivateForPlayer(defender); - mdefender.msg("Flying is disabled in combat."); - } - - if (mattacker.isFlying()) - { - mattacker.setFlying(false); - deactivateForPlayer(attacker); - mattacker.msg("Flying is disabled in combat."); - } - } - - public static boolean canFlyInTerritory(MPlayer mplayer, PS ps) - { - try - { - canFlyInTerritoryOrThrow(mplayer, ps); - return true; - } - catch (MassiveException ex) - { - return false; - } - } - - public static void canFlyInTerritoryOrThrow(MPlayer mplayer, PS ps) throws MassiveException - { - if (!mplayer.isPlayer()) - { - throw new MassiveException().addMsg("Only players can fly."); - } - - Faction faction = mplayer.getFaction(); - Faction locationFaction = BoardColl.get().getFactionAt(ps.getChunk(true)); - - if (faction != locationFaction) - { - throw new MassiveException().addMsg("You can only fly within your own faction."); - } - - // If the faction does not have the flag ... - if (!faction.getFlag(MFlag.getFlagFly())) - { - MFlag flag = MFlag.getFlagFly(); - MassiveException ex = new MassiveException() - .addMsg("Flying requires that the %s flag is enabled for your faction.", flag.getName()); - - // ... but they can change ... - if (flag.isEditable()) { - boolean canEdit = MPerm.getPermFlags().has(mplayer, faction, false); - // ... and the player can edit it themselves ... - if (canEdit) { - // ... tell them to edit. - ex.addMsg("You can edit the flag with: "); - ex.addMessage(CmdFactions.get().cmdFactionsFlag.cmdFactionsFlagSet.getTemplate(false, true, mplayer.getSender())); - } - // ... otherwise ... - else { - // .. tell them to have someone else edit it ... - ex.addMsg("You can ask a faction admin to change the flag."); - } - } - // ... or only server admins can change it ... - else - { - boolean isAdmin = Perm.OVERRIDE.has(mplayer.getSender()); - boolean isDefault = flag.isDefault(); - if (isAdmin) - { - boolean overriding = mplayer.isOverriding(); - ex.addMsg("You can change the flag if you are overriding."); - if (overriding) ex.addMsg("You are already overriding."); - else - { - ex.addMsg("You can enable override with:"); - ex.addMessage(CmdFactions.get().cmdFactionsOverride.getTemplate(false, true, mplayer.getSender())); - } - - if (!isDefault) - { - ex.addMsg("You can also ask someone with access to the configuration files to make flying enabled by default."); - if (MFlagColl.get().getDb().getDriver() instanceof DriverFlatfile) - { - File file = DriverFlatfile.getDirectory(MFlagColl.get()); - ex.addMsg("Configuring the flags can be done by editing the files in %s.", file.getAbsoluteFile()); - } - } - } - else - { - ex.addMsg("Only server admins can change the flag. Per default flying is %s.", isDefault ? "enabled" : "disabled"); - } - } - throw ex; - } - } - - public static void deactivateForPlayer(Player player) - { - EventMassiveCorePlayerUpdate.resetFlyAllowed(player); - EventMassiveCorePlayerUpdate.resetFlyActive(player); - EventMassiveCorePlayerUpdate.resetFlySpeed(player); - - EventMassiveCorePlayerUpdate.run(player); - } - -} diff --git a/src/com/massivecraft/factions/engine/EngineLastActivity.java b/src/com/massivecraft/factions/engine/EngineLastActivity.java deleted file mode 100644 index 3e802893..00000000 --- a/src/com/massivecraft/factions/engine/EngineLastActivity.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.massivecraft.factions.engine; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.event.EventMassiveCorePlayerLeave; -import com.massivecraft.massivecore.util.MUtil; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerJoinEvent; - -public class EngineLastActivity extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineLastActivity i = new EngineLastActivity(); - public static EngineLastActivity get() { return i; } - - // -------------------------------------------- // - // UPDATE LAST ACTIVITY - // -------------------------------------------- // - - public static void updateLastActivity(CommandSender sender) - { - if (sender == null) throw new RuntimeException("sender"); - if (MUtil.isntSender(sender)) return; - - MPlayer mplayer = MPlayer.get(sender); - mplayer.setLastActivityMillis(); - } - - public static void updateLastActivitySoon(final CommandSender sender) - { - if (sender == null) throw new RuntimeException("sender"); - Bukkit.getScheduler().scheduleSyncDelayedTask(Factions.get(), () -> updateLastActivity(sender)); - } - - // Can't be cancelled - @EventHandler(priority = EventPriority.LOWEST) - public void updateLastActivity(PlayerJoinEvent event) - { - // During the join event itself we want to be able to reach the old data. - // That is also the way the underlying fallback Mixin system does it and we do it that way for the sake of symmetry. - // For that reason we wait till the next tick with updating the value. - updateLastActivitySoon(event.getPlayer()); - } - - // Can't be cancelled - @EventHandler(priority = EventPriority.LOWEST) - public void updateLastActivity(EventMassiveCorePlayerLeave event) - { - // Here we do however update immediately. - // The player data should be fully updated before leaving the server. - updateLastActivity(event.getPlayer()); - } - -} diff --git a/src/com/massivecraft/factions/engine/EngineMotd.java b/src/com/massivecraft/factions/engine/EngineMotd.java deleted file mode 100644 index 38fa2711..00000000 --- a/src/com/massivecraft/factions/engine/EngineMotd.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.massivecraft.factions.engine; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.mixin.MixinActual; -import com.massivecraft.massivecore.mixin.MixinMessage; -import com.massivecraft.massivecore.util.MUtil; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerJoinEvent; - -import java.util.List; - -public class EngineMotd extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineMotd i = new EngineMotd(); - public static EngineMotd get() { return i; } - - // -------------------------------------------- // - // MOTD - // -------------------------------------------- // - - public static void motd(PlayerJoinEvent event, EventPriority currentPriority) - { - // Gather info ... - final Player player = event.getPlayer(); - if (MUtil.isntPlayer(player)) return; - final MPlayer mplayer = MPlayer.get(player); - final Faction faction = mplayer.getFaction(); - - // ... if there is a motd ... - if ( ! faction.hasMotd()) return; - - // ... and this is the priority we are supposed to act on ... - if (currentPriority != MConf.get().motdPriority) return; - - // ... and this is an actual join ... - if ( ! MixinActual.get().isActualJoin(event)) return; - - // ... then prepare the messages ... - final List messages = faction.getMotdMessages(); - - // ... and send to the player. - if (MConf.get().motdDelayTicks < 0) - { - MixinMessage.get().messageOne(player, messages); - } - else - { - Bukkit.getScheduler().scheduleSyncDelayedTask(Factions.get(), () -> MixinMessage.get().messageOne(player, messages), MConf.get().motdDelayTicks); - } - } - - // Can't be cancelled - @EventHandler(priority = EventPriority.LOWEST) - public void motdLowest(PlayerJoinEvent event) - { - motd(event, EventPriority.LOWEST); - } - - // Can't be cancelled - @EventHandler(priority = EventPriority.LOW) - public void motdLow(PlayerJoinEvent event) - { - motd(event, EventPriority.LOW); - } - - // Can't be cancelled - @EventHandler(priority = EventPriority.NORMAL) - public void motdNormal(PlayerJoinEvent event) - { - motd(event, EventPriority.NORMAL); - } - - // Can't be cancelled - @EventHandler(priority = EventPriority.HIGH) - public void motdHigh(PlayerJoinEvent event) - { - motd(event, EventPriority.HIGH); - } - - // Can't be cancelled - @EventHandler(priority = EventPriority.HIGHEST) - public void motdHighest(PlayerJoinEvent event) - { - motd(event, EventPriority.HIGHEST); - } - - // Can't be cancelled - @EventHandler(priority = EventPriority.MONITOR) - public void motdMonitor(PlayerJoinEvent event) - { - motd(event, EventPriority.MONITOR); - } - -} diff --git a/src/com/massivecraft/factions/engine/EngineMoveChunk.java b/src/com/massivecraft/factions/engine/EngineMoveChunk.java deleted file mode 100644 index 1be2d854..00000000 --- a/src/com/massivecraft/factions/engine/EngineMoveChunk.java +++ /dev/null @@ -1,139 +0,0 @@ -package com.massivecraft.factions.engine; - -import com.massivecraft.factions.AccessStatus; -import com.massivecraft.factions.TerritoryAccess; -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.util.AsciiMap; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.mixin.MixinTitle; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.MUtil; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerMoveEvent; - -import java.util.Collections; - -public class EngineMoveChunk extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineMoveChunk i = new EngineMoveChunk(); - public static EngineMoveChunk get() { return i; } - - // -------------------------------------------- // - // MOVE CHUNK: DETECT - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void moveChunkDetect(PlayerMoveEvent event) - { - // If the player is moving from one chunk to another ... - if (MUtil.isSameChunk(event)) return; - Player player = event.getPlayer(); - if (MUtil.isntPlayer(player)) return; - - // ... gather info on the player and the move ... - MPlayer mplayer = MPlayer.get(player); - - PS psFrom = PS.valueOf(event.getFrom()); - PS psTo = PS.valueOf(event.getTo()); - - // ... send info onwards and try auto-claiming. - sendChunkInfo(mplayer, player, psFrom, psTo); - tryAutoClaim(mplayer, psTo); - } - - // -------------------------------------------- // - // MOVE CHUNK: SEND CHUNK INFO - // -------------------------------------------- // - - private static void sendChunkInfo(MPlayer mplayer, Player player, PS psFrom, PS psTo) - { - sendAutoMapUpdate(mplayer, psTo); - sendFactionTerritoryInfo(mplayer, player, psFrom, psTo); - sendTerritoryAccessMessage(mplayer, psFrom, psTo); - } - - private static void sendAutoMapUpdate(MPlayer mplayer, PS ps) - { - if (!mplayer.isMapAutoUpdating()) return; - AsciiMap map = new AsciiMap(mplayer, ps, false); - mplayer.message(map.render()); - } - - private static void sendFactionTerritoryInfo(MPlayer mplayer, Player player, PS psFrom, PS psTo) - { - Faction factionFrom = BoardColl.get().getFactionAt(psFrom); - Faction factionTo = BoardColl.get().getFactionAt(psTo); - - if (factionFrom == factionTo) return; - - if (mplayer.isTerritoryInfoTitles()) - { - String titleMain = parseTerritoryInfo(MConf.get().territoryInfoTitlesMain, mplayer, factionTo); - String titleSub = parseTerritoryInfo(MConf.get().territoryInfoTitlesSub, mplayer, factionTo); - int ticksIn = MConf.get().territoryInfoTitlesTicksIn; - int ticksStay = MConf.get().territoryInfoTitlesTicksStay; - int ticksOut = MConf.get().territoryInfoTitleTicksOut; - MixinTitle.get().sendTitleMessage(player, ticksIn, ticksStay, ticksOut, titleMain, titleSub); - } - else - { - String message = parseTerritoryInfo(MConf.get().territoryInfoChat, mplayer, factionTo); - player.sendMessage(message); - } - } - - private static String parseTerritoryInfo(String string, MPlayer mplayer, Faction faction) - { - if (string == null) throw new NullPointerException("string"); - if (faction == null) throw new NullPointerException("faction"); - - string = Txt.parse(string); - string = string.replace("{name}", faction.getName()); - string = string.replace("{relcolor}", faction.getColorTo(mplayer).toString()); - string = string.replace("{desc}", faction.getDescriptionDesc()); - - return string; - } - - private static void sendTerritoryAccessMessage(MPlayer mplayer, PS psFrom, PS psTo) - { - if (!MConf.get().territoryAccessShowMessage) return; - - // Get TerritoryAccess for from & to chunks - TerritoryAccess accessFrom = BoardColl.get().getTerritoryAccessAt(psFrom); - TerritoryAccess accessTo = BoardColl.get().getTerritoryAccessAt(psTo); - - // See if the status has changed - AccessStatus statusFrom = accessFrom.getTerritoryAccess(mplayer); - AccessStatus statusTo = accessTo.getTerritoryAccess(mplayer); - if (statusFrom == statusTo) return; - - // Inform - mplayer.message(statusTo.getStatusMessage()); - } - - // -------------------------------------------- // - // MOVE CHUNK: TRY AUTO CLAIM - // -------------------------------------------- // - - private static void tryAutoClaim(MPlayer mplayer, PS chunkTo) - { - // If the player is auto claiming ... - Faction autoClaimFaction = mplayer.getAutoClaimFaction(); - if (autoClaimFaction == null) return; - - // ... try claim. - mplayer.tryClaim(autoClaimFaction, Collections.singletonList(chunkTo)); - } - -} diff --git a/src/com/massivecraft/factions/engine/EnginePermBuild.java b/src/com/massivecraft/factions/engine/EnginePermBuild.java deleted file mode 100644 index 76e79f13..00000000 --- a/src/com/massivecraft/factions/engine/EnginePermBuild.java +++ /dev/null @@ -1,419 +0,0 @@ -package com.massivecraft.factions.engine; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.TerritoryAccess; -import com.massivecraft.factions.entity.Board; -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.FactionColl; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.util.EnumerationUtil; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.MUtil; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.entity.Projectile; -import org.bukkit.event.Cancellable; -import org.bukkit.event.Event; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.block.Action; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockFromToEvent; -import org.bukkit.event.block.BlockPistonExtendEvent; -import org.bukkit.event.block.BlockPistonRetractEvent; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.block.SignChangeEvent; -import org.bukkit.event.entity.EntityChangeBlockEvent; -import org.bukkit.event.entity.EntityCombustByEntityEvent; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.hanging.HangingBreakByEntityEvent; -import org.bukkit.event.hanging.HangingPlaceEvent; -import org.bukkit.event.player.PlayerBucketEmptyEvent; -import org.bukkit.event.player.PlayerBucketFillEvent; -import org.bukkit.event.player.PlayerInteractAtEntityEvent; -import org.bukkit.event.player.PlayerInteractEntityEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.projectiles.ProjectileSource; - -import java.util.List; -import java.util.Map; - -public class EnginePermBuild extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EnginePermBuild i = new EnginePermBuild(); - public static EnginePermBuild get() { return i; } - - // -------------------------------------------- // - // LOGIC > PROTECT - // -------------------------------------------- // - - public static Boolean isProtected(ProtectCase protectCase, boolean verboose, MPlayer mplayer, PS ps, Object object) - { - if (mplayer == null) return null; - if (protectCase == null) return null; - String name = mplayer.getName(); - if (MConf.get().playersWhoBypassAllProtection.contains(name)) return false; - if (mplayer.isOverriding()) return false; - - MPerm perm = protectCase.getPerm(object); - if (perm == null) return null; - if (protectCase != ProtectCase.BUILD) return !perm.has(mplayer, ps, verboose); - - if (!perm.has(mplayer, ps, false) && MPerm.getPermPainbuild().has(mplayer, ps, false)) - { - if (!verboose) return false; - - Faction hostFaction = BoardColl.get().getFactionAt(ps); - mplayer.msg("It is painful to build in the territory of %s.", hostFaction.describeTo(mplayer)); - Player player = mplayer.getPlayer(); - if (player != null) player.damage(MConf.get().actionDeniedPainAmount); - } - - return !perm.has(mplayer, ps, verboose); - } - - public static Boolean protect(ProtectCase protectCase, boolean verboose, Player player, PS ps, Object object, Cancellable cancellable) - { - Boolean ret = isProtected(protectCase, verboose, MPlayer.get(player), ps, object); - if (Boolean.TRUE.equals(ret) && cancellable != null) cancellable.setCancelled(true); - - return ret; - } - - public static Boolean build(Entity entity, Block block, Event event) - { - if (!(event instanceof Cancellable)) return true; - if (MUtil.isntPlayer(entity)) return false; - Player player = (Player) entity; - boolean verboose = !isFake(event); - return protect(ProtectCase.BUILD, verboose, player, PS.valueOf(block), block, (Cancellable) event); - } - - public static Boolean useItem(Player player, Block block, Material material, Cancellable cancellable) - { - return protect(ProtectCase.USE_ITEM, true, player, PS.valueOf(block), material, cancellable); - } - - public static Boolean useEntity(Player player, Entity entity, boolean verboose, Cancellable cancellable) - { - return protect(ProtectCase.USE_ENTITY, verboose, player, PS.valueOf(entity), entity, cancellable); - } - - public static Boolean useBlock(Player player, Block block, boolean verboose, Cancellable cancellable) - { - return protect(ProtectCase.USE_BLOCK, verboose, player, PS.valueOf(block), block.getType(), cancellable); - } - - // -------------------------------------------- // - // LOGIC > PROTECT > BUILD - // -------------------------------------------- // - - public static boolean canPlayerBuildAt(Object senderObject, PS ps, boolean verboose) - { - MPlayer mplayer = MPlayer.get(senderObject); - if (mplayer == null) return false; - - Boolean ret = isProtected(ProtectCase.BUILD, verboose, mplayer, ps, null); - return !Boolean.TRUE.equals(ret); - } - - // -------------------------------------------- // - // BUILD > BLOCK - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.NORMAL) - public void build(BlockPlaceEvent event) { build(event.getPlayer(), event.getBlock(), event); } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void build(BlockBreakEvent event) { build(event.getPlayer(), event.getBlock(), event); } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void build(SignChangeEvent event) { build(event.getPlayer(), event.getBlock(), event); } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void build(HangingPlaceEvent event) { build(event.getPlayer(), event.getBlock(), event); } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void build(HangingBreakByEntityEvent event) { build(event.getRemover(), event.getEntity().getLocation().getBlock(), event); } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void build(EntityChangeBlockEvent event) - { - // Handling lilypads being broken by boats - Entity entity = event.getEntity(); - if (entity.getType() != EntityType.BOAT || entity.getPassengers().size() <= 0) return; - Entity player = entity.getPassengers().stream().filter(MUtil::isPlayer).findAny().orElse(entity); - - build(player, event.getBlock(), event); - } - - - // -------------------------------------------- // - // USE > ITEM - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void useBlockItem(PlayerInteractEvent event) - { - // If the player right clicks (or is physical with) a block ... - if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) return; - - Block block = event.getClickedBlock(); - Player player = event.getPlayer(); - if (block == null) return; - - // ... and we are either allowed to use this block ... - Boolean ret = useBlock(player, block, true, event); - if (Boolean.TRUE.equals(ret)) return; - - // ... or are allowed to right click with the item, this event is safe to perform. - if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; - useItem(player, block, event.getMaterial(), event); - } - - // For some reason onPlayerInteract() sometimes misses bucket events depending on distance - // (something like 2-3 blocks away isn't detected), but these separate bucket events below always fire without fail - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void useItem(PlayerBucketEmptyEvent event) { useItem(event.getPlayer(), event.getBlockClicked().getRelative(event.getBlockFace()), event.getBucket(), event); } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void useItem(PlayerBucketFillEvent event) { useItem(event.getPlayer(), event.getBlockClicked(), event.getBucket(), event); } - - // -------------------------------------------- // - // USE > ENTITY - // -------------------------------------------- // - - // This event will not fire for Minecraft 1.8 armor stands. - // Armor stands are handled in EngineSpigot instead. - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void useEntity(PlayerInteractEntityEvent event) - { - // Ignore Off Hand - if (isOffHand(event)) return; - useEntity(event.getPlayer(), event.getRightClicked(), true, event); - } - - // This is a special Spigot event that fires for Minecraft 1.8 armor stands. - // It also fires for other entity types but for those the event is buggy. - // It seems we can only cancel interaction with armor stands from here. - // Thus we only handle armor stands from here and handle everything else in EngineMain. - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void handleArmorStand(PlayerInteractAtEntityEvent event) - { - // Ignore Off Hand - if (isOffHand(event)) return; - - // Gather Info - final Player player = event.getPlayer(); - if (MUtil.isntPlayer(player)) return; - final Entity entity = event.getRightClicked(); - final boolean verboose = true; - - // Only care for armor stands. - if (entity.getType() != EntityType.ARMOR_STAND) return; - - // If we can't use, block it - EnginePermBuild.useEntity(player, entity, verboose, event); - } - - // -------------------------------------------- // - // BUILD > ENTITY - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void buildEntity(EntityDamageByEntityEvent event) - { - // If a player ... - Entity damager = MUtil.getLiableDamager(event); - if (MUtil.isntPlayer(damager)) return; - Player player = (Player)damager; - - // ... damages an entity which is edited on damage ... - Entity entity = event.getEntity(); - if (entity == null || !EnumerationUtil.isEntityTypeEditOnDamage(entity.getType())) return; - - // ... and the player can't build there, cancel the event - build(player, entity.getLocation().getBlock(), event); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void combustEntity(EntityCombustByEntityEvent event) { - - // If a burning projectile ... - if (!(event.getCombuster() instanceof Projectile)) return; - Projectile entityProjectile = (Projectile)event.getCombuster(); - - // ... fired by a player ... - ProjectileSource projectileSource = entityProjectile.getShooter(); - if (MUtil.isntPlayer(projectileSource)) return; - Player player = (Player) projectileSource; - - // ... and hits an entity which is edited on damage (and thus likely to burn) ... - Entity entityTarget = event.getEntity(); - if (entityTarget == null || !EnumerationUtil.isEntityTypeEditOnDamage(entityTarget.getType())) return; - - // ... and the player can't build there, cancel the event - Block block = entityTarget.getLocation().getBlock(); - protect(ProtectCase.BUILD, false, player, PS.valueOf(block), block, event); - } - - // -------------------------------------------- // - // BUILD > PISTON - // -------------------------------------------- // - - /* - * Note: With 1.8 and the slime blocks, retracting and extending pistons - * became more of a problem. Blocks located on the border of a chunk - * could have easily been stolen. That is the reason why every block - * needs to be checked now, whether he moved into a territory which - * he actually may not move into. - */ - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void blockBuild(BlockPistonExtendEvent event) - { - // Is checking deactivated by MConf? - if ( ! MConf.get().handlePistonProtectionThroughDenyBuild) return; - - Faction pistonFaction = BoardColl.get().getFactionAt(PS.valueOf(event.getBlock())); - - List blocks = event.getBlocks(); - - // Check for all extended blocks - for (Block block : blocks) - { - // Block which is being pushed into - Block targetBlock = block.getRelative(event.getDirection()); - - // Members of a faction might not have build rights in their own territory, but pistons should still work regardless - Faction targetFaction = BoardColl.get().getFactionAt(PS.valueOf(targetBlock)); - if (targetFaction == pistonFaction) continue; - - // Perm check - if (MPerm.getPermBuild().has(pistonFaction, targetFaction)) continue; - - event.setCancelled(true); - return; - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void blockBuild(BlockPistonRetractEvent event) - { - // Is checking deactivated by MConf? - if ( ! MConf.get().handlePistonProtectionThroughDenyBuild) return; - - Faction pistonFaction = BoardColl.get().getFactionAt(PS.valueOf(event.getBlock())); - - List blocks = event.getBlocks(); - - // Check for all retracted blocks - for (Block block : blocks) - { - // Is the retracted block air/water/lava? Don't worry about it - if (block.isEmpty() || block.isLiquid()) return; - - // Members of a faction might not have build rights in their own territory, but pistons should still work regardless - Faction targetFaction = BoardColl.get().getFactionAt(PS.valueOf(block)); - if (targetFaction == pistonFaction) continue; - - // Perm check - if (MPerm.getPermBuild().has(pistonFaction, targetFaction)) continue; - - event.setCancelled(true); - return; - } - } - - // -------------------------------------------- // - // BUILD > FIRE - // -------------------------------------------- // - - @SuppressWarnings("deprecation") - @EventHandler(priority = EventPriority.NORMAL) - public void buildFire(PlayerInteractEvent event) - { - // If it is a left click on block and the clicked block is not null... - if (event.getAction() != Action.LEFT_CLICK_BLOCK || event.getClickedBlock() == null) return; - - // ... and the potential block is not null either ... - Block potentialBlock = event.getClickedBlock().getRelative(BlockFace.UP, 1); - if (potentialBlock == null) return; - - Material blockType = potentialBlock.getType(); - - // ... and we're only going to check for fire ... (checking everything else would be bad performance wise) - if (blockType != Material.FIRE) return; - - // ... check if they can't build, cancel the event ... - if (!Boolean.FALSE.equals(build(event.getPlayer(), potentialBlock, event))) return; - - // ... and compensate for client side prediction - event.getPlayer().sendBlockChange(potentialBlock.getLocation(), blockType, potentialBlock.getState().getRawData()); - } - - // -------------------------------------------- // - // BUILD > MOVE - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void buildMove(BlockFromToEvent event) - { - if ( ! MConf.get().protectionLiquidFlowEnabled) return; - - // Prepare fields - Block fromBlock = event.getBlock(); - int chunkFromX = fromBlock.getX() >> 4; - int chunkFromZ = fromBlock.getZ() >> 4; - BlockFace face = event.getFace(); - int chunkToX = (fromBlock.getX() + face.getModX()) >> 4; - int chunkToZ = (fromBlock.getZ() + face.getModZ()) >> 4; - - // If a liquid (or dragon egg) moves from one chunk to another ... - if (chunkToX == chunkFromX && chunkToZ == chunkFromZ) return; - - // ... get the correct board for this block ... - Board board = BoardColl.get().getFixed(fromBlock.getWorld().getName().toLowerCase(), false); - if (board == null) return; - - // ... get the access map ... - Map map = board.getMapRaw(); - if (map.isEmpty()) return; - - // ... get the faction ids from and to ... - PS fromPs = PS.valueOf(chunkFromX, chunkFromZ); - PS toPs = PS.valueOf(chunkToX, chunkToZ); - TerritoryAccess fromTa = map.get(fromPs); - TerritoryAccess toTa = map.get(toPs); - - // Null checks are needed here since automatic board cleaning can be undesired sometimes - String fromId = fromTa != null ? fromTa.getHostFactionId() : Factions.ID_NONE; - String toId = toTa != null ? toTa.getHostFactionId() : Factions.ID_NONE; - - // ... and the chunks belong to different factions ... - if (toId.equals(fromId)) return; - - // ... and the faction "from" can not build at "to" ... - Faction fromFac = FactionColl.get().getFixed(fromId); - if (fromFac == null) fromFac = FactionColl.get().getNone(); - Faction toFac = FactionColl.get().getFixed(toId); - if (toFac == null) toFac = FactionColl.get().getNone(); - if (MPerm.getPermBuild().has(fromFac, toFac)) return; - - // ... cancel the event! - event.setCancelled(true); - } - -} diff --git a/src/com/massivecraft/factions/engine/EnginePlayerData.java b/src/com/massivecraft/factions/engine/EnginePlayerData.java deleted file mode 100644 index fee52a6e..00000000 --- a/src/com/massivecraft/factions/engine/EnginePlayerData.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.massivecraft.factions.engine; - -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.entity.MPlayerColl; -import com.massivecraft.massivecore.Engine; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerKickEvent; - -public class EnginePlayerData extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EnginePlayerData i = new EnginePlayerData(); - public static EnginePlayerData get() { return i; } - - // -------------------------------------------- // - // REMOVE PLAYER DATA WHEN BANNED - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onPlayerKick(PlayerKickEvent event) - { - // If a player was kicked from the server ... - Player player = event.getPlayer(); - - // ... and if the if player was banned (not just kicked) ... - //if (!event.getReason().equals("Banned by admin.")) return; - if (!player.isBanned()) return; - - // ... and we remove player data when banned ... - if (!MConf.get().removePlayerWhenBanned) return; - - // ... get rid of their stored info. - MPlayer mplayer = MPlayerColl.get().get(player, false); - if (mplayer == null) return; - - if (mplayer.getRank().isLeader()) - { - mplayer.getFaction().promoteNewLeader(); - } - - mplayer.leave(); - mplayer.detach(); - } - -} diff --git a/src/com/massivecraft/factions/engine/EnginePower.java b/src/com/massivecraft/factions/engine/EnginePower.java deleted file mode 100644 index 2d884fc5..00000000 --- a/src/com/massivecraft/factions/engine/EnginePower.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.massivecraft.factions.engine; - -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.MPlayer; -import com.massivecraft.factions.event.EventFactionsPowerChange; -import com.massivecraft.factions.event.EventFactionsPowerChange.PowerChangeReason; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.MUtil; -import com.massivecraft.massivecore.util.PlayerUtil; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.entity.PlayerDeathEvent; - -public class EnginePower extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EnginePower i = new EnginePower(); - public static EnginePower get() { return i; } - - // -------------------------------------------- // - // POWER LOSS ON DEATH - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.NORMAL) - public void powerLossOnDeath(PlayerDeathEvent event) - { - // If a player dies ... - Player player = event.getEntity(); - if (MUtil.isntPlayer(player)) return; - - // ... and this is the first death event this tick ... - // (yeah other plugins can case death event to fire twice the same tick) - if (PlayerUtil.isDuplicateDeathEvent(event)) return; - - MPlayer mplayer = MPlayer.get(player); - - // ... and powerloss can happen here ... - Faction faction = BoardColl.get().getFactionAt(PS.valueOf(player.getLocation())); - - if (!faction.getFlag(MFlag.getFlagPowerloss())) - { - mplayer.msg("You didn't lose any power since the territory you died in works that way."); - return; - } - - if (!MConf.get().worldsPowerLossEnabled.contains(player.getWorld())) - { - mplayer.msg("You didn't lose any power due to the world you died in."); - return; - } - - // ... alter the power ... - double newPower = mplayer.getPower() + mplayer.getPowerPerDeath(); - - EventFactionsPowerChange powerChangeEvent = new EventFactionsPowerChange(null, mplayer, PowerChangeReason.DEATH, newPower); - powerChangeEvent.run(); - if (powerChangeEvent.isCancelled()) return; - newPower = powerChangeEvent.getNewPower(); - - mplayer.setPower(newPower); - - // ... and inform the player. - // TODO: A progress bar here would be epic :) - mplayer.msg("Your power is now %.2f / %.2f", newPower, mplayer.getPowerMax()); - } - -} diff --git a/src/com/massivecraft/factions/engine/EngineSeeChunk.java b/src/com/massivecraft/factions/engine/EngineSeeChunk.java deleted file mode 100644 index 670e33af..00000000 --- a/src/com/massivecraft/factions/engine/EngineSeeChunk.java +++ /dev/null @@ -1,173 +0,0 @@ -package com.massivecraft.factions.engine; - -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.event.EventMassiveCorePlayerLeave; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.MUtil; -import com.massivecraft.massivecore.util.PeriodUtil; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Particle; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerChangedWorldEvent; - -import java.security.InvalidParameterException; -import java.util.ArrayList; -import java.util.List; - -public class EngineSeeChunk extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineSeeChunk i = new EngineSeeChunk(); - public static EngineSeeChunk get() { return i; } - public EngineSeeChunk() - { - this.setPeriod(1L); - } - - // -------------------------------------------- // - // LEAVE AND WORLD CHANGE REMOVAL - // -------------------------------------------- // - - public static void leaveAndWorldChangeRemoval(Player player) - { - if (MUtil.isntPlayer(player)) return; - - final MPlayer mplayer = MPlayer.get(player); - mplayer.setSeeingChunk(false); - } - - // Can't be cancelled - @EventHandler(priority = EventPriority.NORMAL) - public void leaveAndWorldChangeRemoval(EventMassiveCorePlayerLeave event) - { - leaveAndWorldChangeRemoval(event.getPlayer()); - } - - // Can't be cancelled - @EventHandler(priority = EventPriority.NORMAL) - public void leaveAndWorldChangeRemoval(PlayerChangedWorldEvent event) - { - leaveAndWorldChangeRemoval(event.getPlayer()); - } - - // -------------------------------------------- // - // MODULO REPEAT TASK - // -------------------------------------------- // - - @Override - public void run() - { - // Do we have a new period? - final long now = System.currentTimeMillis(); - final long length = 500; - if ( ! PeriodUtil.isNewPeriod(this, length, now)) return; - - // Get the period number - final long period = PeriodUtil.getPeriod(length, now); - - // Calculate the "step" from the period number - final int steps = 1; // Example: 4 - final int step = (int) (period % steps); // Example: 0, 1, 2, 3 - - // Load other related config options - final float offsetX = 0.0f; - final float offsetY = 2; - final float offsetZ = 0.0f; - final float speed = 0; - final int amount = 30; - - // For each player - for (Player player : Bukkit.getOnlinePlayers()) - { - // Hide for dead players since the death screen looks better without. - if (player.isDead()) continue; - - // The player must obviously have the feature activated. - MPlayer mplayer = MPlayer.get(player); - if ( ! mplayer.isSeeingChunk()) continue; - - // Calculate locations and play the effect there. - List locations = getLocations(player, steps, step); - for (Location location : locations) - { - location.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, location, amount, offsetX, offsetY, offsetZ, speed); - //ParticleEffect.EXPLOSION_NORMAL.display(location, offsetX, offsetY, offsetZ, speed, amount, player); - } - } - } - - public static List getLocations(Player player, int steps, int step) - { - // Clean Args - if (player == null) throw new NullPointerException("player"); - if (steps < 1) throw new InvalidParameterException("steps must be larger than 0"); - if (step < 0) throw new InvalidParameterException("step must at least be 0"); - if (step >= steps) throw new InvalidParameterException("step must be less than steps"); - - // Create Ret - List ret = new ArrayList<>(); - - final Location location = player.getLocation(); - final World world = location.getWorld(); - PS chunk = PS.valueOf(location).getChunk(true); - - final int xmin = chunk.getChunkX() * 16; - final int xmax = xmin + 15; - final double y = location.getBlockY() + 2; - final int zmin = chunk.getChunkZ() * 16; - final int zmax = zmin + 15; - - int keepEvery = 5; - if (keepEvery <= 0) keepEvery = Integer.MAX_VALUE; - - int skipEvery = 0; - if (skipEvery <= 0) skipEvery = Integer.MAX_VALUE; - - int x = xmin; - int z = zmin; - int i = 0; - - // Add #1 - while (x + 1 <= xmax) - { - x++; - i++; - if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5)); - } - - // Add #2 - while (z + 1 <= zmax) - { - z++; - i++; - if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5)); - } - - // Add #3 - while (x - 1 >= xmin) - { - x--; - i++; - if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5)); - } - - // Add #4 - while (z - 1 >= zmin) - { - z--; - i++; - if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5)); - } - - // Return Ret - return ret; - } -} diff --git a/src/com/massivecraft/factions/engine/EngineShow.java b/src/com/massivecraft/factions/engine/EngineShow.java deleted file mode 100644 index 1dad84ff..00000000 --- a/src/com/massivecraft/factions/engine/EngineShow.java +++ /dev/null @@ -1,254 +0,0 @@ -package com.massivecraft.factions.engine; - -import com.massivecraft.factions.comparator.ComparatorMPlayerRole; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MFlag; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.event.EventFactionsChunkChangeType; -import com.massivecraft.factions.event.EventFactionsFactionShowAsync; -import com.massivecraft.factions.integration.Econ; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.PriorityLines; -import com.massivecraft.massivecore.money.Money; -import com.massivecraft.massivecore.util.TimeDiffUtil; -import com.massivecraft.massivecore.util.TimeUnit; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.command.CommandSender; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -public class EngineShow extends Engine -{ - // -------------------------------------------- // - // CONSTANTS - // -------------------------------------------- // - - public static final String BASENAME = "factions"; - public static final String BASENAME_ = BASENAME+"_"; - - public static final String SHOW_ID_FACTION_ID = BASENAME_ + "id"; - public static final String SHOW_ID_FACTION_DESCRIPTION = BASENAME_ + "description"; - public static final String SHOW_ID_FACTION_AGE = BASENAME_ + "age"; - public static final String SHOW_ID_FACTION_FLAGS = BASENAME_ + "flags"; - public static final String SHOW_ID_FACTION_POWER = BASENAME_ + "power"; - public static final String SHOW_ID_FACTION_LANDVALUES = BASENAME_ + "landvalue"; - public static final String SHOW_ID_FACTION_BANK = BASENAME_ + "bank"; - public static final String SHOW_ID_FACTION_FOLLOWERS = BASENAME_ + "followers"; - - public static final int SHOW_PRIORITY_FACTION_ID = 1000; - public static final int SHOW_PRIORITY_FACTION_DESCRIPTION = 2000; - public static final int SHOW_PRIORITY_FACTION_AGE = 3000; - public static final int SHOW_PRIORITY_FACTION_FLAGS = 4000; - public static final int SHOW_PRIORITY_FACTION_POWER = 5000; - public static final int SHOW_PRIORITY_FACTION_LANDVALUES = 6000; - public static final int SHOW_PRIORITY_FACTION_BANK = 7000; - public static final int SHOW_PRIORITY_FACTION_FOLLOWERS = 9000; - - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineShow i = new EngineShow(); - public static EngineShow get() { return i; } - - // -------------------------------------------- // - // FACTION SHOW - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) - public void onFactionShow(EventFactionsFactionShowAsync event) - { - final int tableCols = 4; - final CommandSender sender = event.getSender(); - final MPlayer mplayer = event.getMPlayer(); - final Faction faction = event.getFaction(); - final boolean normal = faction.isNormal(); - final Map idPriorityLiness = event.getIdPriorityLiness(); - String none = Txt.parse("none"); - - // ID - if (mplayer.isOverriding()) - { - show(idPriorityLiness, SHOW_ID_FACTION_ID, SHOW_PRIORITY_FACTION_ID, "ID", faction.getId()); - } - - // DESCRIPTION - show(idPriorityLiness, SHOW_ID_FACTION_DESCRIPTION, SHOW_PRIORITY_FACTION_DESCRIPTION, "Description", faction.getDescriptionDesc()); - - // SECTION: NORMAL - if (normal) - { - // AGE - long ageMillis = faction.getCreatedAtMillis() - System.currentTimeMillis(); - LinkedHashMap ageUnitcounts = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(ageMillis, TimeUnit.getAllButMillis()), 3); - String ageDesc = TimeDiffUtil.formatedVerboose(ageUnitcounts, ""); - show(idPriorityLiness, SHOW_ID_FACTION_AGE, SHOW_PRIORITY_FACTION_AGE, "Age", ageDesc); - - // FLAGS - // We display all editable and non default ones. The rest we skip. - List flagDescs = new LinkedList<>(); - for (Entry entry : faction.getFlags().entrySet()) - { - final MFlag mflag = entry.getKey(); - if (mflag == null) continue; - - final Boolean value = entry.getValue(); - if (value == null) continue; - - if ( ! mflag.isInteresting(value)) continue; - - String flagDesc = Txt.parse(value ? "" : "") + mflag.getName(); - flagDescs.add(flagDesc); - } - String flagsDesc = Txt.parse("default"); - if ( ! flagDescs.isEmpty()) - { - flagsDesc = Txt.implode(flagDescs, Txt.parse(" | ")); - } - show(idPriorityLiness, SHOW_ID_FACTION_FLAGS, SHOW_PRIORITY_FACTION_FLAGS, "Flags", flagsDesc); - - // POWER - double powerBoost = faction.getPowerBoost(); - String boost = (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? " (bonus: " : " (penalty: ") + powerBoost + ")"; - String powerDesc = Txt.parse("%d/%d/%d%s", faction.getLandCount(), faction.getPowerRounded(), faction.getPowerMaxRounded(), boost); - show(idPriorityLiness, SHOW_ID_FACTION_POWER, SHOW_PRIORITY_FACTION_POWER, "Land / Power / Maxpower", powerDesc); - - // SECTION: ECON - if (Econ.isEnabled()) - { - // LANDVALUES - List landvalueLines = new LinkedList<>(); - long landCount = faction.getLandCount(); - for (EventFactionsChunkChangeType type : EventFactionsChunkChangeType.values()) - { - Double money = MConf.get().econChunkCost.get(type); - if (money == null) continue; - if (money == 0) continue; - money *= landCount; - - String word = "Cost"; - if (money <= 0) - { - word = "Reward"; - money *= -1; - } - - String key = Txt.parse("Total Land %s %s", type.toString().toLowerCase(), word); - String value = Txt.parse("%s", Money.format(money)); - String line = show(key, value); - landvalueLines.add(line); - } - idPriorityLiness.put(SHOW_ID_FACTION_LANDVALUES, new PriorityLines(SHOW_PRIORITY_FACTION_LANDVALUES, landvalueLines)); - - // BANK - if (MConf.get().bankEnabled) - { - double bank = Econ.getMoney(faction); - String bankDesc = Txt.parse("%s", Money.format(bank, true)); - show(idPriorityLiness, SHOW_ID_FACTION_BANK, SHOW_PRIORITY_FACTION_BANK, "Bank", bankDesc); - } - } - } - - // FOLLOWERS - List followerLines = new ArrayList<>(); - - List followerNamesOnline = new ArrayList<>(); - List followerNamesOffline = new ArrayList<>(); - - List followers = faction.getMPlayers(); - followers.sort(ComparatorMPlayerRole.get()); - for (MPlayer follower : followers) - { - if (follower.isOnline(sender)) - { - followerNamesOnline.add(follower.getNameAndTitle(mplayer)); - } - else if (normal) - { - // For the non-faction we skip the offline members since they are far to many (infinite almost) - followerNamesOffline.add(follower.getNameAndTitle(mplayer)); - } - } - - String headerOnline = Txt.parse("Followers Online (%s):", followerNamesOnline.size()); - followerLines.add(headerOnline); - if (followerNamesOnline.isEmpty()) - { - followerLines.add(none); - } - else - { - followerLines.addAll(table(followerNamesOnline, tableCols)); - } - - if (normal) - { - String headerOffline = Txt.parse("Followers Offline (%s):", followerNamesOffline.size()); - followerLines.add(headerOffline); - if (followerNamesOffline.isEmpty()) - { - followerLines.add(none); - } - else - { - followerLines.addAll(table(followerNamesOffline, tableCols)); - } - } - idPriorityLiness.put(SHOW_ID_FACTION_FOLLOWERS, new PriorityLines(SHOW_PRIORITY_FACTION_FOLLOWERS, followerLines)); - } - - public static String show(String key, String value) - { - return Txt.parse("%s: %s", key, value); - } - - public static PriorityLines show(int priority, String key, String value) - { - return new PriorityLines(priority, show(key, value)); - } - - public static void show(Map idPriorityLiness, String id, int priority, String key, String value) - { - idPriorityLiness.put(id, show(priority, key, value)); - } - - public static List table(List strings, int cols) - { - List ret = new ArrayList<>(); - - StringBuilder row = new StringBuilder(); - int count = 0; - - Iterator iter = strings.iterator(); - while (iter.hasNext()) - { - String string = iter.next(); - row.append(string); - count++; - - if (iter.hasNext() && count != cols) - { - row.append(Txt.parse(" | ")); - } - else - { - ret.add(row.toString()); - row = new StringBuilder(); - count = 0; - } - } - - return ret; - } - -} diff --git a/src/com/massivecraft/factions/engine/EngineTeleportHomeOnDeath.java b/src/com/massivecraft/factions/engine/EngineTeleportHomeOnDeath.java deleted file mode 100644 index 02b99064..00000000 --- a/src/com/massivecraft/factions/engine/EngineTeleportHomeOnDeath.java +++ /dev/null @@ -1,104 +0,0 @@ -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.util.MUtil; -import org.bukkit.Location; -import org.bukkit.entity.Player; -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 -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineTeleportHomeOnDeath i = new EngineTeleportHomeOnDeath(); - public static EngineTeleportHomeOnDeath get() { return i; } - - // -------------------------------------------- // - // TELEPORT TO HOME ON DEATH - // -------------------------------------------- // - - public void teleportToHomeOnDeath(PlayerRespawnEvent event, EventPriority priority) - { - // If a player is respawning ... - final Player player = event.getPlayer(); - if (MUtil.isntPlayer(player)) return; - final MPlayer mplayer = MPlayer.get(player); - - // ... homes are enabled, active and at this priority ... - 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 ... - List warps = faction.getWarps().getAll((java.util.function.Predicate) (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 = warp.getLocation().asBukkitLocation(true); - } - catch (Exception e) - { - // The home location map may have been deleted - return; - } - - // ... then use it for the respawn location. - event.setRespawnLocation(respawnLocation); - } - - @EventHandler(priority = EventPriority.LOWEST) - public void teleportToHomeOnDeathLowest(PlayerRespawnEvent event) - { - this.teleportToHomeOnDeath(event, EventPriority.LOWEST); - } - - @EventHandler(priority = EventPriority.LOW) - public void teleportToHomeOnDeathLow(PlayerRespawnEvent event) - { - this.teleportToHomeOnDeath(event, EventPriority.LOW); - } - - @EventHandler(priority = EventPriority.NORMAL) - public void teleportToHomeOnDeathNormal(PlayerRespawnEvent event) - { - this.teleportToHomeOnDeath(event, EventPriority.NORMAL); - } - - @EventHandler(priority = EventPriority.HIGH) - public void teleportToHomeOnDeathHigh(PlayerRespawnEvent event) - { - this.teleportToHomeOnDeath(event, EventPriority.HIGH); - } - - @EventHandler(priority = EventPriority.HIGHEST) - public void teleportToHomeOnDeathHighest(PlayerRespawnEvent event) - { - this.teleportToHomeOnDeath(event, EventPriority.HIGHEST); - } - - @EventHandler(priority = EventPriority.MONITOR) - public void teleportToHomeOnDeathMonitor(PlayerRespawnEvent event) - { - this.teleportToHomeOnDeath(event, EventPriority.MONITOR); - } - -} diff --git a/src/com/massivecraft/factions/engine/EngineTerritoryShield.java b/src/com/massivecraft/factions/engine/EngineTerritoryShield.java deleted file mode 100644 index 35603e04..00000000 --- a/src/com/massivecraft/factions/engine/EngineTerritoryShield.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.massivecraft.factions.engine; - -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.util.MUtil; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.entity.EntityDamageByEntityEvent; - -import java.text.MessageFormat; - -public class EngineTerritoryShield extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineTerritoryShield i = new EngineTerritoryShield(); - public static EngineTerritoryShield get() { return i; } - - // -------------------------------------------- // - // TERRITORY SHIELD - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void territoryShield(EntityDamageByEntityEvent event) - { - // If the entity is a player ... - Entity entity = event.getEntity(); - if (MUtil.isntPlayer(entity)) return; - Player player = (Player)entity; - MPlayer mplayer = MPlayer.get(player); - - // ... and the attacker is a player ... - Entity attacker = MUtil.getLiableDamager(event); - if (! (attacker instanceof Player)) return; - - // ... and that player has a faction ... - if ( ! mplayer.hasFaction()) return; - - // ... and that player is in their own territory ... - if ( ! mplayer.isInOwnTerritory()) return; - - // ... and a territoryShieldFactor is configured ... - if (MConf.get().territoryShieldFactor <= 0) return; - - // ... then scale the damage ... - double factor = 1D - MConf.get().territoryShieldFactor; - MUtil.scaleDamage(event, factor); - - // ... and inform. - String perc = MessageFormat.format("{0,number,#%}", (MConf.get().territoryShieldFactor)); - mplayer.msg("Enemy damage reduced by %s.", perc); - } - -} diff --git a/src/com/massivecraft/factions/engine/EngineVisualizations.java b/src/com/massivecraft/factions/engine/EngineVisualizations.java deleted file mode 100644 index aacab13a..00000000 --- a/src/com/massivecraft/factions/engine/EngineVisualizations.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.massivecraft.factions.engine; - -import com.massivecraft.factions.util.VisualizeUtil; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.util.MUtil; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerMoveEvent; - -public class EngineVisualizations extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineVisualizations i = new EngineVisualizations(); - public static EngineVisualizations get() { return i; } - - // -------------------------------------------- // - // VISUALIZE UTIL - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onPlayerMoveClearVisualizations(PlayerMoveEvent event) - { - if (MUtil.isSameBlock(event)) return; - - VisualizeUtil.clear(event.getPlayer()); - } - -} diff --git a/src/com/massivecraft/factions/engine/ProtectCase.java b/src/com/massivecraft/factions/engine/ProtectCase.java deleted file mode 100644 index 5196e03f..00000000 --- a/src/com/massivecraft/factions/engine/ProtectCase.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.massivecraft.factions.engine; - -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.util.EnumerationUtil; -import org.bukkit.Material; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; - -public enum ProtectCase -{ - // -------------------------------------------- // - // ENUM - // -------------------------------------------- // - - BUILD, - USE_BLOCK, - USE_ITEM, - USE_ENTITY, - - // END OF LIST - ; - - // -------------------------------------------- // - // PERM - // -------------------------------------------- // - - public MPerm getPerm(Object object) - { - switch (this) - { - case BUILD: - return MPerm.getPermBuild(); - - case USE_ITEM: - if (!(object instanceof Material)) return null; - if (!EnumerationUtil.isMaterialEditTool((Material) object)) return null; - return MPerm.getPermBuild(); - - case USE_ENTITY: - if (!(object instanceof Entity)) return null; - Entity entity = (Entity) object; - EntityType type = entity.getType(); - if (EnumerationUtil.isEntityTypeContainer(type)) return MPerm.getPermContainer(); - if (EnumerationUtil.isEntityTypeEditOnInteract(type)) return MPerm.getPermBuild(); - - case USE_BLOCK: - if (!(object instanceof Material)) return null; - Material material = (Material) object; - if (EnumerationUtil.isMaterialEditOnInteract(material)) return MPerm.getPermBuild(); - if (EnumerationUtil.isMaterialContainer(material)) return MPerm.getPermContainer(); - if (EnumerationUtil.isMaterialDoor(material)) return MPerm.getPermDoor(); - if (material == Material.STONE_BUTTON) return MPerm.getPermButton(); - if (material == Material.LEVER) return MPerm.getPermLever(); - - default: - return null; - } - } - -} diff --git a/src/com/massivecraft/factions/entity/Board.java b/src/com/massivecraft/factions/entity/Board.java deleted file mode 100644 index 8ac59350..00000000 --- a/src/com/massivecraft/factions/entity/Board.java +++ /dev/null @@ -1,292 +0,0 @@ -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 implements BoardInterface -{ - public static final transient Type MAP_TYPE = new TypeToken>(){}.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 map; - public Map getMap() { return Collections.unmodifiableMap(this.map); } - public Map getMapRaw() { return this.map; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public Board() - { - this.map = new ConcurrentSkipListMap<>(); - } - - public Board(Map 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 getChunks(Faction faction) - { - return this.getChunks(faction.getId()); - } - - @Override - public Set 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> getFactionToChunks() - { - return this.getFactionToChunks(true); - } - - @Override - public Map> getFactionToChunks(boolean withWorld) - { - Function, 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>> 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 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 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 pss, Faction faction) - { - return pss.stream().anyMatch(ps -> this.isConnectedPs(ps, faction)); - } - -} diff --git a/src/com/massivecraft/factions/entity/BoardColl.java b/src/com/massivecraft/factions/entity/BoardColl.java deleted file mode 100644 index 014a06ca..00000000 --- a/src/com/massivecraft/factions/entity/BoardColl.java +++ /dev/null @@ -1,436 +0,0 @@ -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 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 getChunks(Faction faction) - { - return this.getAll().stream() - .flatMap(board -> board.getChunks(faction).stream()) - .collect(Collectors.toSet()); - } - - @Override - public Set getChunks(String factionId) - { - return this.getAll().stream() - .flatMap(board -> board.getChunks(factionId).stream()) - .collect(Collectors.toSet()); - } - - @Override - @Deprecated - public Map> getFactionToChunks() - { - return this.getFactionToChunks(false); - } - - @Override - public Map> getFactionToChunks(boolean withWorld) - { - // Create - Map> ret = null; - - // Fill - for (Board board : this.getAll()) - { - // Use the first board directly - Map> factionToChunks = board.getFactionToChunks(withWorld); - if (ret == null) - { - ret = factionToChunks; - continue; - } - - // Merge the following boards - for (Entry> entry : factionToChunks.entrySet()) - { - Faction faction = entry.getKey(); - Set 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>> 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 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 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 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 pss, Faction faction) - { - for (PS ps : pss) - { - if (this.isConnectedPs(ps, faction)) return true; - } - return false; - } - - // -------------------------------------------- // - // WORLDS - // -------------------------------------------- // - - public Set getClaimedWorlds(Faction faction) - { - return getClaimedWorlds(faction.getId()); - } - - public Set 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 getNearbyChunks(PS psChunk, int distance) - { - // Fix Args - if (psChunk == null) throw new NullPointerException("psChunk"); - psChunk = psChunk.getChunk(true); - - // Create - Set 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 getNearbyChunks(Collection chunks, int distance) - { - // Fix Args - if (chunks == null) throw new NullPointerException("chunks"); - - // Create - Set ret = new MassiveSet<>(); - - if (distance < 0) return ret; - - // Fill - for (PS chunk : chunks) - { - ret.addAll(getNearbyChunks(chunk, distance)); - } - - // Return - return ret; - } - - public static Set getDistinctFactions(Collection chunks) - { - // Fix Args - if (chunks == null) throw new NullPointerException("chunks"); - - // Create - Set 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 getChunkFaction(Collection chunks) - { - // Create - Map 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> getForests(Collection pss) - { - List> forests = new MassiveList<>(); - List discovered = new MassiveList<>(); - - outer: - for (PS ps : pss) - { - if (discovered.contains(ps)) continue outer; - - List forest = new MassiveList<>(); - forests.add(forest); - - Stack 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 stack, Collection source) - { - if (source.contains(ps)) stack.push(ps); - } - -} diff --git a/src/com/massivecraft/factions/entity/BoardInterface.java b/src/com/massivecraft/factions/entity/BoardInterface.java deleted file mode 100644 index 4c54de68..00000000 --- a/src/com/massivecraft/factions/entity/BoardInterface.java +++ /dev/null @@ -1,45 +0,0 @@ -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 getChunks(Faction faction); - Set getChunks(String factionId); - @Deprecated Map> getFactionToChunks(); - Map> getFactionToChunks(boolean withWorld); - Map>> getWorldToFactionToChunks(boolean withWorld); - - // COUNT - int getCount(Faction faction); - int getCount(String factionId); - Map getFactionToCount(); - - // CLAIMED - boolean hasClaimed(Faction faction); - boolean hasClaimed(String factionId); - - // NEARBY DETECTION - boolean isBorderPs(PS ps); - boolean isAnyBorderPs(Set pss); - boolean isConnectedPs(PS ps, Faction faction); - boolean isAnyConnectedPs(Set pss, Faction faction); - -} diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java deleted file mode 100644 index f9f4b3f3..00000000 --- a/src/com/massivecraft/factions/entity/Faction.java +++ /dev/null @@ -1,1354 +0,0 @@ -package com.massivecraft.factions.entity; - - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.FactionsIndex; -import com.massivecraft.factions.FactionsParticipator; -import com.massivecraft.factions.Rel; -import com.massivecraft.factions.RelationParticipator; -import com.massivecraft.factions.entity.MPerm.MPermable; -import com.massivecraft.factions.predicate.PredicateCommandSenderFaction; -import com.massivecraft.factions.predicate.PredicateMPlayerRank; -import com.massivecraft.factions.util.MiscUtil; -import com.massivecraft.factions.util.RelationUtil; -import com.massivecraft.massivecore.Couple; -import com.massivecraft.massivecore.Identified; -import com.massivecraft.massivecore.collections.MassiveList; -import com.massivecraft.massivecore.collections.MassiveMap; -import com.massivecraft.massivecore.collections.MassiveMapDef; -import com.massivecraft.massivecore.collections.MassiveSet; -import com.massivecraft.massivecore.mixin.MixinMessage; -import com.massivecraft.massivecore.money.Money; -import com.massivecraft.massivecore.predicate.PredicateAnd; -import com.massivecraft.massivecore.predicate.PredicateVisibleTo; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.store.Entity; -import com.massivecraft.massivecore.store.EntityInternalMap; -import com.massivecraft.massivecore.store.SenderColl; -import com.massivecraft.massivecore.util.IdUtil; -import com.massivecraft.massivecore.util.MUtil; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -public class Faction extends Entity implements FactionsParticipator, MPerm.MPermable -{ - // -------------------------------------------- // - // CONSTANTS - // -------------------------------------------- // - - public static final transient String NODESCRIPTION = Txt.parse("no description set"); - public static final transient String NOMOTD = Txt.parse("no message of the day set"); - - // -------------------------------------------- // - // META - // -------------------------------------------- // - - public static Faction get(Object oid) - { - return FactionColl.get().get(oid); - } - - // -------------------------------------------- // - // OVERRIDE: ENTITY - // -------------------------------------------- // - - @Override - public Faction load(Faction that) - { - this.setName(that.name); - this.setDescription(that.description); - this.setMotd(that.motd); - this.setCreatedAtMillis(that.createdAtMillis); - this.warps.load(that.warps); - this.setPowerBoost(that.powerBoost); - this.money = that.money; - this.invitations.load(that.invitations); - this.ranks.load(that.ranks); - this.votes.load(that.votes); - this.setRelationWishes(that.relationWishes); - this.setFlagIds(that.flags); - this.perms = that.perms; - this.tax = that.tax; - - return this; - } - - @Override - public void preDetach(String id) - { - if (!this.isLive()) return; - - // NOTE: Existence check is required for compatibility with some plugins. - // If they have money ... - if (Money.exists(this)) - { - // ... remove it. - Money.set(this, null, 0, "Factions"); - } - } - - // -------------------------------------------- // - // VERSION - // -------------------------------------------- // - - public int version = 4; - - // -------------------------------------------- // - // FIELDS: RAW - // -------------------------------------------- // - // In this section of the source code we place the field declarations only. - // Each field has it's own section further down since just the getter and setter logic takes up quite some place. - - // The actual faction id looks something like "54947df8-0e9e-4471-a2f9-9af509fb5889" and that is not too easy to remember for humans. - // Thus we make use of a name. Since the id is used in all foreign key situations changing the name is fine. - // Null should never happen. The name must not be null. - private String name = null; - - // Factions can optionally set a description for themselves. - // This description can for example be seen in territorial alerts. - // Null means the faction has no description. - private String description = null; - - // Factions can optionally set a message of the day. - // This message will be shown when logging on to the server. - // Null means the faction has no motd - private String motd = null; - - // We store the creation date for the faction. - // It can be displayed on info pages etc. - private long createdAtMillis = System.currentTimeMillis(); - - // 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. - // Null means the faction has powerBoost (0). - private Double powerBoost = null; - - // The money a Faction has - // null means 0.0 - private Double money = null; - - // This is the ids of the invited players. - // They are actually "senderIds" since you can invite "@console" to your faction. - private EntityInternalMap invitations = new EntityInternalMap<>(this, Invitation.class); - - // This is where all the ranks are, they are faction specific - private EntityInternalMap ranks = this.createRankMap(); - - // This is the votes currently open in the faction - private EntityInternalMap votes = new EntityInternalMap<>(this, Vote.class); - - // The keys in this map are factionIds. - // Null means no special relation whishes. - private MassiveMapDef relationWishes = new MassiveMapDef<>(); - - // The flag overrides are modifications to the default values. - // Null means default. - private MassiveMapDef flags = new MassiveMapDef<>(); - - private Map> perms = this.createNewPermMap(); - - // What is the base tax on members of the faction? - // Specific taxes on ranks or players. - public static transient String IDENTIFIER_TAX_BASE = "base"; - - private Map tax = new MassiveMap<>(); - - // -------------------------------------------- // - // FIELD: id - // -------------------------------------------- // - - // FINER - - public boolean isNone() - { - return this.getId().equals(Factions.ID_NONE); - } - - public boolean isNormal() - { - return ! this.isNone(); - } - - // -------------------------------------------- // - // FIELD: name - // -------------------------------------------- // - - // RAW - - @Override - public String getName() - { - return this.name; - } - - public void setName(String name) - { - // Clean input - String target = name; - - // Detect Nochange - if (MUtil.equals(this.name, target)) return; - - // Apply - this.name = target; - - // Mark as changed - this.changed(); - } - - // FINER - - public String getComparisonName() - { - return MiscUtil.getComparisonString(this.getName()); - } - - public String getName(String prefix) - { - return prefix + this.getName(); - } - - public String getName(RelationParticipator observer) - { - if (observer == null) return getName(); - return this.getName(this.getColorTo(observer).toString()); - } - - // -------------------------------------------- // - // FIELD: description - // -------------------------------------------- // - - // RAW - - public boolean hasDescription() - { - return this.description != null; - } - - public String getDescription() - { - return this.description; - } - - public void setDescription(String description) - { - // Clean input - String target = clean(description); - - // Detect Nochange - if (MUtil.equals(this.description, target)) return; - - // Apply - this.description = target; - - // Mark as changed - this.changed(); - } - - // FINER - - public String getDescriptionDesc() - { - String motd = this.getDescription(); - if (motd == null) motd = NODESCRIPTION; - return motd; - } - - // -------------------------------------------- // - // FIELD: motd - // -------------------------------------------- // - - // RAW - - public boolean hasMotd() - { - return this.motd != null; - } - - public String getMotd() - { - return this.motd; - } - - public void setMotd(String motd) - { - // Clean input - String target = clean(motd); - - // Detect Nochange - if (MUtil.equals(this.motd, target)) return; - - // Apply - this.motd = target; - - // Mark as changed - this.changed(); - } - - // FINER - - public String getMotdDesc() - { - return getMotdDesc(this.getMotd()); - } - - private static String getMotdDesc(String motd) - { - if (motd == null) motd = NOMOTD; - return motd; - } - - public List getMotdMessages() - { - // Create - List ret = new MassiveList<>(); - - // Fill - Object title = this.getName() + " - Message of the Day"; - title = Txt.titleize(title); - ret.add(title); - - String motd = this.getMotdDesc(); - List motds = Arrays.asList(motd.split("\\\\n")); - motds = motds.stream().map(s -> Txt.parse("") + s).collect(Collectors.toList()); - ret.addAll(motds); - - ret.add(""); - - // Return - return ret; - } - - // -------------------------------------------- // - // FIELD: createdAtMillis - // -------------------------------------------- // - - public long getCreatedAtMillis() - { - return this.createdAtMillis; - } - - public void setCreatedAtMillis(long createdAtMillis) - { - // Detect Nochange - if (MUtil.equals(this.createdAtMillis, createdAtMillis)) return; - - // Apply - this.createdAtMillis = createdAtMillis; - - // Mark as changed - this.changed(); - } - - public long getAge() - { - return this.getAge(System.currentTimeMillis()); - } - - public long getAge(long now) - { - return now - this.getCreatedAtMillis(); - } - - // -------------------------------------------- // - // FIELD: warp - // -------------------------------------------- // - - public EntityInternalMap getWarps() { return this.warps; } - - public Warp getWarp(Object oid) - { - 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 String addWarp(Warp warp) - { - return this.getWarps().attach(warp); - } - - public Warp removeWarp(Warp warp) - { - return this.getWarps().detachEntity(warp); - } - - // -------------------------------------------- // - // FIELD: powerBoost - // -------------------------------------------- // - - // RAW - @Override - public double getPowerBoost() - { - Double ret = this.powerBoost; - if (ret == null) ret = 0D; - return ret; - } - - @Override - public void setPowerBoost(Double powerBoost) - { - // Clean input - Double target = powerBoost; - - if (target == null || target == 0) target = null; - - // Detect Nochange - if (MUtil.equals(this.powerBoost, target)) return; - - // Apply - this.powerBoost = target; - - // Mark as changed - this.changed(); - } - - // -------------------------------------------- // - // FIELD: money - // -------------------------------------------- // - - public double getMoney() - { - if (!MConf.get().econEnabled) throw new UnsupportedOperationException("econ not enabled"); - if (!MConf.get().bankEnabled) throw new UnsupportedOperationException("bank not enabled"); - if (!MConf.get().useNewMoneySystem) throw new UnsupportedOperationException("this server does not use the new econ system"); - - return this.convertGet(this.money, 0D); - } - - public void setMoney(Double money) - { - if (!MConf.get().econEnabled) throw new UnsupportedOperationException("econ not enabled"); - if (!MConf.get().bankEnabled) throw new UnsupportedOperationException("bank not enabled"); - if (!MConf.get().useNewMoneySystem) throw new UnsupportedOperationException("this server does not use the new econ system"); - - this.money = this.convertSet(money, this.money, 0D); - } - - // -------------------------------------------- // - // FIELD: invitations - // -------------------------------------------- // - - // RAW - - public EntityInternalMap getInvitations() { return this.invitations; } - - // FINER - - public boolean isInvited(String playerId) - { - return this.getInvitations().containsKey(playerId); - } - - public boolean isInvited(MPlayer mplayer) - { - return this.isInvited(mplayer.getId()); - } - - public boolean uninvite(String playerId) - { - return this.getInvitations().detachId(playerId) != null; - } - - public boolean uninvite(MPlayer mplayer) - { - return uninvite(mplayer.getId()); - } - - public void invite(String playerId, Invitation invitation) - { - uninvite(playerId); - this.invitations.attach(invitation, playerId); - } - - // -------------------------------------------- // - // FIELD: ranks - // -------------------------------------------- // - - // RAW - - public EntityInternalMap getRanks() { return this.ranks; } - - // FINER - - public boolean hasRank(Rank rank) - { - return this.getRanks().containsKey(rank.getId()); - } - - public Rank getRank(String rankId) - { - if (rankId == null) throw new NullPointerException("rankId"); - return this.getRanks().getFixed(rankId); - } - - private EntityInternalMap createRankMap() - { - EntityInternalMap ret = new EntityInternalMap<>(this, Rank.class); - - MConf.get().defaultRanks.stream() - .map(Rank::copy) - .forEach(ret::attach); - - return ret; - } - - public Rank getLeaderRank() - { - Rank ret = null; - for (Rank rank : this.getRanks().getAll()) - { - if (ret != null && ret.isMoreThan(rank)) continue; - - ret = rank; - } - return ret; - } - - public Rank getLowestRank() - { - Rank ret = null; - for (Rank rank : this.getRanks().getAll()) - { - if (ret != null && ret.isLessThan(rank)) continue; - - ret = rank; - } - return ret; - } - - // -------------------------------------------- // - // FIELD: votes - // -------------------------------------------- // - - // RAW - - public EntityInternalMap getVotes() { return this.votes; } - - public void addVote(Vote vote) - { - if (vote == null) throw new NullPointerException("vote"); - this.getVotes().attach(vote); - } - - public Optional getVoteByName(String name) - { - if (name == null) throw new NullPointerException("name"); - return this.getVotes().getAll().stream().filter(vote -> vote.getName().equalsIgnoreCase(name)).findFirst(); - } - - // -------------------------------------------- // - // FIELD: relationWish - // -------------------------------------------- // - - // RAW - - public Map getRelationWishes() - { - return this.relationWishes; - } - - public void setRelationWishes(Map relationWishes) - { - // Clean input - MassiveMapDef target = new MassiveMapDef<>(relationWishes); - - // Detect Nochange - if (MUtil.equals(this.relationWishes, target)) return; - - // Apply - this.relationWishes = target; - - // Mark as changed - this.changed(); - } - - // FINER - - public Rel getRelationWish(String factionId) - { - Rel ret = this.getRelationWishes().get(factionId); - if (ret == null) ret = Rel.NEUTRAL; - return ret; - } - - public Rel getRelationWish(Faction faction) - { - return this.getRelationWish(faction.getId()); - } - - public void setRelationWish(String factionId, Rel rel) - { - Map relationWishes = this.getRelationWishes(); - if (rel == null || rel == Rel.NEUTRAL) - { - relationWishes.remove(factionId); - } - else - { - relationWishes.put(factionId, rel); - } - this.setRelationWishes(relationWishes); - } - - public void setRelationWish(Faction faction, Rel rel) - { - this.setRelationWish(faction.getId(), rel); - } - - // -------------------------------------------- // - // FIELD: flagOverrides - // -------------------------------------------- // - - // RAW - - public Map getFlags() - { - // We start with default values ... - Map ret = new MassiveMap<>(); - for (MFlag mflag : MFlag.getAll()) - { - ret.put(mflag, mflag.isStandard()); - } - - // ... and if anything is explicitly set we use that info ... - Iterator> iter = this.flags.entrySet().iterator(); - while (iter.hasNext()) - { - // ... for each entry ... - Map.Entry entry = iter.next(); - - // ... extract id and remove null values ... - String id = entry.getKey(); - if (id == null) - { - iter.remove(); - this.changed(); - continue; - } - - // ... resolve object and skip unknowns ... - MFlag mflag = MFlag.get(id); - if (mflag == null) continue; - - ret.put(mflag, entry.getValue()); - } - - return ret; - } - - public void setFlags(Map flags) - { - Map flagIds = new MassiveMap<>(); - for (Map.Entry entry : flags.entrySet()) - { - flagIds.put(entry.getKey().getId(), entry.getValue()); - } - setFlagIds(flagIds); - } - - public void setFlagIds(Map flagIds) - { - // Clean input - MassiveMapDef target = new MassiveMapDef<>(); - for (Map.Entry entry : flagIds.entrySet()) - { - String key = entry.getKey(); - if (key == null) continue; - key = key.toLowerCase(); // Lowercased Keys Version 2.6.0 --> 2.7.0 - - Boolean value = entry.getValue(); - if (value == null) continue; - - target.put(key, value); - } - - // Detect Nochange - if (MUtil.equals(this.flags, target)) return; - - // Apply - this.flags = new MassiveMapDef<>(target); - - // Mark as changed - this.changed(); - } - - // FINER - - public boolean getFlag(String flagId) - { - if (flagId == null) throw new NullPointerException("flagId"); - - Boolean ret = this.flags.get(flagId); - if (ret != null) return ret; - - MFlag flag = MFlag.get(flagId); - if (flag == null) throw new NullPointerException("flag"); - - return flag.isStandard(); - } - - public boolean getFlag(MFlag flag) - { - if (flag == null) throw new NullPointerException("flag"); - - String flagId = flag.getId(); - if (flagId == null) throw new NullPointerException("flagId"); - - Boolean ret = this.flags.get(flagId); - if (ret != null) return ret; - - return flag.isStandard(); - } - - public Boolean setFlag(String flagId, boolean value) - { - if (flagId == null) throw new NullPointerException("flagId"); - - Boolean ret = this.flags.put(flagId, value); - if (ret == null || ret != value) this.changed(); - return ret; - } - - public Boolean setFlag(MFlag flag, boolean value) - { - if (flag == null) throw new NullPointerException("flag"); - - String flagId = flag.getId(); - if (flagId == null) throw new NullPointerException("flagId"); - - Boolean ret = this.flags.put(flagId, value); - if (ret == null || ret != value) this.changed(); - return ret; - } - - // -------------------------------------------- // - // FIELD: perms - // -------------------------------------------- // - - public Map> getPerms() - { - return this.perms; - } - - public Map> createNewPermMap() - { - Map> ret = new MassiveMap<>(); - for (MPerm mperm : MPerm.getAll()) - { - Set granteds = mperm2granteds(mperm); - - ret.put(mperm.getId(), granteds); - } - return ret; - } - - private Set mperm2granteds(MPerm mperm) - { - String permId = mperm.getId(); - Set value = new MassiveSet<>(MConf.get().perm2default.get(permId)); - Set additions = new MassiveSet<>(); - outer: - for (Iterator it = value.iterator(); it.hasNext();) - { - String granted = it.next(); - for (Rank rank : this.getRanks().getAll()) - { - if (granted.equalsIgnoreCase(rank.getName())) - { - it.remove(); - additions.add(rank.getId()); - continue outer; - } - } - } - value.addAll(additions); - return value; - } - - // IS PERMITTED - - public boolean isPlayerPermitted(MPlayer mplayer, String permId) - { - if (isPermitted(mplayer.getId(), permId)) return true; - if (isPermitted(mplayer.getFaction().getId(), permId)) return true; - if (isPermitted(mplayer.getRank().getId(), permId)) return true; - if (isPermitted(RelationUtil.getRelationOfThatToMe(mplayer, this).toString(), permId)) return true; - - return false; - } - - public boolean isPlayerPermitted(MPlayer mplayer, MPerm mperm) - { - return isPlayerPermitted(mplayer, mperm.getId()); - } - - public boolean isFactionPermitted(Faction faction, String permId) - { - if (isPermitted(faction.getId(), permId)) return true; - if (isPermitted(RelationUtil.getRelationOfThatToMe(faction, this).toString(), permId)) return true; - - return false; - } - - public boolean isFactionPermitted(Faction faction, MPerm mperm) - { - return isFactionPermitted(faction, mperm.getId()); - } - - public Set getPermitted(String permId) - { - if (permId == null) throw new NullPointerException("permId"); - Set permables = this.perms.get(permId); - - if (permables == null) - { - // No perms was found, but likely this is just a new MPerm. - // So if this does not exist in the database, throw an error. - if (!doesPermExist(permId)) throw new NullPointerException(permId + " caused null"); - - permables = new MassiveSet<>(); - this.perms.put(permId, permables); - } - - return permables; - } - - public Set getPermitted(MPerm mperm) - { - return getPermitted(mperm.getId()); - } - - public Set getPermittedPermables(String permId) - { - return MPerm.idsToMPermables(getPermitted(permId)); - } - - public Set getPermittedPermables(MPerm mperm) - { - return getPermittedPermables(mperm.getId()); - } - - public boolean isPermitted(String permableId, String permId) - { - if (permableId == null) throw new NullPointerException("permableId"); - if (permId == null) throw new NullPointerException("permId"); - - // TODO: Isn't this section redundant and just a copy of that from getPermitted? - Set permables = this.perms.get(permId); - if (permables == null) - { - // No perms was found, but likely this is just a new MPerm. - // So if this does not exist in the database, throw an error. - if (!doesPermExist(permId)) throw new NullPointerException(permId + " caused null"); - - // Otherwise handle it - return false; - } - - return getPermitted(permId).contains(permableId); - } - - // SET PERMITTED - - public boolean setPermitted(MPerm.MPermable mpermable, String permId, boolean permitted) - { - boolean changed = false; - - Set perms = this.perms.get(permId); - if (perms == null) - { - // No perms was found, but likely this is just a new MPerm. - // So if this does not exist in the database, throw an error. - if (!doesPermExist(permId)) throw new NullPointerException(permId + " caused null"); - - // Otherwise handle it - Set permables = new MassiveSet<>(); - this.perms.put(permId, permables); - changed = true; - } - - if (permitted) - { - changed = this.getPerms().get(permId).add(mpermable.getId()) | changed; - } - else - { - changed = this.getPerms().get(permId).remove(mpermable.getId()) | changed; - } - if (changed) this.changed(); - return changed; - } - - public boolean setPermitted(MPerm.MPermable mpermable, MPerm mperm, boolean permitted) - { - return setPermitted(mpermable, mperm.getId(), permitted); - } - - public void setPermittedRelations(String permId, Collection permables) - { - Set ids = permables.stream().map(MPerm.MPermable::getId).collect(Collectors.toSet()); - this.getPerms().put(permId, ids); - } - - public void setPermittedRelations(MPerm perm, Collection permables) - { - setPermittedRelations(perm.getId(), permables); - } - - - private boolean doesPermExist(String permId) - { - return MPermColl.get().getFixed(permId) != null; - } - - // -------------------------------------------- // - // FIELD: tax - // -------------------------------------------- // - - // RAW - public Map getTax() { return this.tax; } - - // FINER GET - public Double getTaxFor(String id) - { - if (id == null) throw new NullPointerException("id"); - return this.tax.get(id); - } - - public Double getTaxFor(Identified identified) - { - if (identified == null) throw new NullPointerException("identified"); - return this.getTaxFor(identified.getId()); - } - - public double getTaxForPlayer(MPlayer mplayer) - { - return getTaxAndReasonForPlayer(mplayer).map(Entry::getValue).orElse(0D); - } - - public Optional> getTaxAndReasonForPlayer(MPlayer mplayer) - { - if (mplayer == null) throw new NullPointerException("mplayer"); - - if (mplayer.getFaction() != this) throw new IllegalArgumentException("Player " + mplayer.getId() + " not in " + this.getId()); - - Double ret = null; - - ret = this.getTaxFor(mplayer); - if (ret != null) return Optional.of(new Couple<>(mplayer.getId(), ret)); - - ret = this.getTaxFor(mplayer.getRank()); - if (ret != null) return Optional.of(new Couple<>(mplayer.getRank().getId(), ret)); - - ret = this.getTaxFor(IDENTIFIER_TAX_BASE); - if (ret != null) return Optional.of(new Couple<>(IDENTIFIER_TAX_BASE, ret)); - - return Optional.empty(); - } - - // FINER SET - public Double setTaxFor(String id, Double value) - { - this.changed(); - return this.tax.put(id, value); - } - - public Double setTaxFor(Identified identified, Double value) - { - return this.setTaxFor(identified.getId(), value); - } - - // -------------------------------------------- // - // OVERRIDE: RelationParticipator - // -------------------------------------------- // - - @Override - public String describeTo(RelationParticipator observer, boolean ucfirst) - { - return RelationUtil.describeThatToMe(this, observer, ucfirst); - } - - @Override - public String describeTo(RelationParticipator observer) - { - return RelationUtil.describeThatToMe(this, observer); - } - - @Override - public Rel getRelationTo(RelationParticipator observer) - { - return RelationUtil.getRelationOfThatToMe(this, observer); - } - - @Override - public Rel getRelationTo(RelationParticipator observer, boolean ignorePeaceful) - { - return RelationUtil.getRelationOfThatToMe(this, observer, ignorePeaceful); - } - - @Override - public ChatColor getColorTo(RelationParticipator observer) - { - return RelationUtil.getColorOfThatToMe(this, observer); - } - - // -------------------------------------------- // - // OVERRIDE: permable - // -------------------------------------------- // - - @Override - public String getDisplayName(Object senderObject) - { - MPlayer mplayer = MPlayer.get(senderObject); - if (mplayer == null) return this.getName(); - - return this.describeTo(mplayer); - } - - // -------------------------------------------- // - // POWER - // -------------------------------------------- // - // TODO: Implement a has enough feature. - - public double getPower() - { - if (this.getFlag(MFlag.getFlagInfpower())) return 999999; - - double ret = 0; - for (MPlayer mplayer : this.getMPlayers()) - { - ret += mplayer.getPower(); - } - - ret = this.limitWithPowerMax(ret); - ret += this.getPowerBoost(); - - return ret; - } - - public double getPowerMax() - { - if (this.getFlag(MFlag.getFlagInfpower())) return 999999; - - double ret = 0; - for (MPlayer mplayer : this.getMPlayers()) - { - ret += mplayer.getPowerMax(); - } - - ret = this.limitWithPowerMax(ret); - ret += this.getPowerBoost(); - - return ret; - } - - private double limitWithPowerMax(double power) - { - // NOTE: 0.0 powerMax means there is no max power - double powerMax = MConf.get().factionPowerMax; - - return powerMax <= 0 || power < powerMax ? power : powerMax; - } - - public int getPowerRounded() - { - return (int) Math.round(this.getPower()); - } - - public int getPowerMaxRounded() - { - return (int) Math.round(this.getPowerMax()); - } - - public int getLandCount() - { - return BoardColl.get().getCount(this); - } - public int getLandCountInWorld(String worldName) - { - return Board.get(worldName).getCount(this); - } - - public boolean hasLandInflation() - { - return this.getLandCount() > this.getPowerRounded(); - } - - // -------------------------------------------- // - // WORLDS - // -------------------------------------------- // - - public Set getClaimedWorlds() - { - return BoardColl.get().getClaimedWorlds(this); - } - - // -------------------------------------------- // - // FOREIGN KEY: MPLAYER - // -------------------------------------------- // - - public List getMPlayers() - { - return new MassiveList<>(FactionsIndex.get().getMPlayers(this)); - } - - public List getMPlayers(java.util.function.Predicate where, Comparator orderby, Integer limit, Integer offset) - { - return MUtil.transform(this.getMPlayers(), where, orderby, limit, offset); - } - - public List getMPlayersWhere(java.util.function.Predicate predicate) - { - return this.getMPlayers(predicate, null, null, null); - } - - public List getMPlayersWhereOnline(boolean online) - { - return this.getMPlayersWhere(online ? SenderColl.PREDICATE_ONLINE : SenderColl.PREDICATE_OFFLINE); - } - - public List getMPlayersWhereOnlineTo(Object senderObject) - { - return this.getMPlayersWhere(PredicateAnd.get(SenderColl.PREDICATE_ONLINE, PredicateVisibleTo.get(senderObject))); - } - - public List getMPlayersWhereRank(Rank rank) - { - return this.getMPlayersWhere(PredicateMPlayerRank.get(rank)); - } - - public MPlayer getLeader() - { - List ret = this.getMPlayersWhereRank(this.getLeaderRank()); - if (ret.size() == 0) return null; - return ret.get(0); - } - - public Set getMPlayerIds() - { - return this.getMPlayers().stream().map(MPlayer::getId).collect(Collectors.toSet()); - } - - public List getOnlineCommandSenders() - { - // Create Ret - List ret = new MassiveList<>(); - - // Fill Ret - for (CommandSender sender : IdUtil.getLocalSenders()) - { - if (MUtil.isntSender(sender)) continue; - - MPlayer mplayer = MPlayer.get(sender); - if (mplayer.getFaction() != this) continue; - - ret.add(sender); - } - - // Return Ret - return ret; - } - - public List getOnlinePlayers() - { - // Create Ret - List ret = new MassiveList<>(); - - // Fill Ret - for (Player player : Bukkit.getOnlinePlayers()) - { - if (MUtil.isntPlayer(player)) continue; - - MPlayer mplayer = MPlayer.get(player); - if (mplayer.getFaction() != this) continue; - - ret.add(player); - } - - // Return Ret - return ret; - } - - // used when current leader is about to be removed from the faction; promotes new leader, or disbands faction if no other members left - public void promoteNewLeader() - { - if ( ! this.isNormal()) return; - if (this.getFlag(MFlag.getFlagPermanent()) && MConf.get().permanentFactionsDisableLeaderPromotion) return; - - MPlayer oldLeader = this.getLeader(); - Rank leaderRank = oldLeader.getRank(); - - List replacements = Collections.emptyList(); - for (Rank rank = leaderRank; rank != null; rank = rank.getRankBelow()) - { - //Skip first - if (rank == leaderRank) continue; - - replacements = this.getMPlayersWhereRank(rank); - if (!replacements.isEmpty()) break; - } - - // if we found a replacement - if (replacements == null || replacements.isEmpty()) - { - // faction leader is the only member; one-man faction - if (this.getFlag(MFlag.getFlagPermanent())) - { - if (oldLeader != null) - { - oldLeader.setRank(this.getLeaderRank().getRankBelow()); - } - return; - } - - // no members left and faction isn't permanent, so disband it - if (MConf.get().logFactionDisband) - { - Factions.get().log("The faction "+this.getName()+" ("+this.getId()+") has been disbanded since it has no members left."); - } - - for (MPlayer mplayer : MPlayerColl.get().getAllOnline()) - { - mplayer.msg("The faction %s was disbanded.", this.getName(mplayer)); - } - - this.detach(); - } - else - { - // promote new faction leader - if (oldLeader != null) - { - oldLeader.setRank(this.getLeaderRank().getRankBelow()); - } - - replacements.get(0).setRank(this.getLeaderRank()); - this.msg("Faction leader %s has been removed. %s has been promoted as the new faction leader.", oldLeader == null ? "" : oldLeader.getName(), replacements.get(0).getName()); - Factions.get().log("Faction "+this.getName()+" ("+this.getId()+") leader was removed. Replacement leader: "+replacements.get(0).getName()); - } - } - - // -------------------------------------------- // - // FACTION ONLINE STATE - // -------------------------------------------- // - - public boolean isAllMPlayersOffline() - { - return this.getMPlayersWhereOnline(true).size() == 0; - } - - public boolean isAnyMPlayersOnline() - { - return !this.isAllMPlayersOffline(); - } - - public boolean isFactionConsideredOffline() - { - return this.isAllMPlayersOffline(); - } - - public boolean isFactionConsideredOnline() - { - return !this.isFactionConsideredOffline(); - } - - public boolean isExplosionsAllowed() - { - boolean explosions = this.getFlag(MFlag.getFlagExplosions()); - boolean offlineexplosions = this.getFlag(MFlag.getFlagOfflineexplosions()); - - if (explosions && offlineexplosions) return true; - if ( ! explosions && ! offlineexplosions) return false; - - boolean online = this.isFactionConsideredOnline(); - - return (online && explosions) || (!online && offlineexplosions); - } - - // -------------------------------------------- // - // MESSAGES - // -------------------------------------------- // - // These methods are simply proxied in from the Mixin. - - // CONVENIENCE SEND MESSAGE - - public boolean sendMessage(Object message) - { - return MixinMessage.get().messagePredicate(new PredicateCommandSenderFaction(this), message); - } - - public boolean sendMessage(Object... messages) - { - return MixinMessage.get().messagePredicate(new PredicateCommandSenderFaction(this), messages); - } - - public boolean sendMessage(Collection messages) - { - return MixinMessage.get().messagePredicate(new PredicateCommandSenderFaction(this), messages); - } - - // CONVENIENCE MSG - - public boolean msg(String msg) - { - return MixinMessage.get().msgPredicate(new PredicateCommandSenderFaction(this), msg); - } - - public boolean msg(String msg, Object... args) - { - return MixinMessage.get().msgPredicate(new PredicateCommandSenderFaction(this), msg, args); - } - - public boolean msg(Collection msgs) - { - return MixinMessage.get().msgPredicate(new PredicateCommandSenderFaction(this), msgs); - } - - // -------------------------------------------- // - // UTIL - // -------------------------------------------- // - - // FIXME this probably needs to be moved elsewhere - public static String clean(String message) - { - String target = message; - if (target == null) return null; - - target = target.trim(); - if (target.isEmpty()) target = null; - - return target; - } - -} diff --git a/src/com/massivecraft/factions/entity/FactionColl.java b/src/com/massivecraft/factions/entity/FactionColl.java deleted file mode 100644 index cced62aa..00000000 --- a/src/com/massivecraft/factions/entity/FactionColl.java +++ /dev/null @@ -1,224 +0,0 @@ -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 -{ - // -------------------------------------------- // - // 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> getRelationNames(Faction faction, Set rels) - { - // Create - Map> 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 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 names = ret.get(Rel.TRUCE); - if (names == null) return ret; - - ret.put(Rel.TRUCE, Collections.singletonList(MConf.get().colorTruce.toString() + Txt.parse("*EVERYONE*"))); - - // Return - return ret; - } - -} diff --git a/src/com/massivecraft/factions/entity/Invitation.java b/src/com/massivecraft/factions/entity/Invitation.java deleted file mode 100644 index 481dd444..00000000 --- a/src/com/massivecraft/factions/entity/Invitation.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.massivecraft.factions.entity; - -import com.massivecraft.massivecore.store.EntityInternal; - -public class Invitation extends EntityInternal -{ - // -------------------------------------------- // - // OVERRIDE: ENTITY - // -------------------------------------------- // - - @Override - public Invitation load(Invitation that) - { - this.inviterId = that.inviterId; - this.creationMillis = that.creationMillis; - - return this; - } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private String inviterId; - public String getInviterId() { return 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; this.changed(); } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public Invitation() - { - this(null, null); - } - - public Invitation(String inviterId, Long creationMillis) - { - this.inviterId = inviterId; - this.creationMillis = creationMillis; - } - -} diff --git a/src/com/massivecraft/factions/entity/MConf.java b/src/com/massivecraft/factions/entity/MConf.java deleted file mode 100644 index 5388ddfd..00000000 --- a/src/com/massivecraft/factions/entity/MConf.java +++ /dev/null @@ -1,800 +0,0 @@ -package com.massivecraft.factions.entity; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.Rel; -import com.massivecraft.factions.engine.EngineChat; -import com.massivecraft.factions.event.EventFactionsChunkChangeType; -import com.massivecraft.factions.integration.dynmap.DynmapStyle; -import com.massivecraft.factions.integration.dynmap.IntegrationDynmap; -import com.massivecraft.massivecore.collections.BackstringSet; -import com.massivecraft.massivecore.collections.MassiveSet; -import com.massivecraft.massivecore.collections.WorldExceptionSet; -import com.massivecraft.massivecore.command.editor.annotation.EditorName; -import com.massivecraft.massivecore.command.editor.annotation.EditorType; -import com.massivecraft.massivecore.command.editor.annotation.EditorTypeInner; -import com.massivecraft.massivecore.command.editor.annotation.EditorVisible; -import com.massivecraft.massivecore.command.type.TypeMillisDiff; -import com.massivecraft.massivecore.store.Entity; -import com.massivecraft.massivecore.util.MUtil; -import com.massivecraft.massivecore.util.TimeUnit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.EntityType; -import org.bukkit.event.EventPriority; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -@EditorName("config") -public class MConf extends Entity -{ - // -------------------------------------------- // - // META - // -------------------------------------------- // - - protected static transient MConf i; - public static MConf get() { return i; } - - // -------------------------------------------- // - // OVERRIDE: ENTITY - // -------------------------------------------- // - - @Override - public MConf load(MConf that) - { - super.load(that); - - // Reactivate EngineChat if currently active. - // This way some event listeners are registered with the correct priority based on the config. - EngineChat engine = EngineChat.get(); - if (engine.isActive()) - { - engine.setActive(false); - engine.setActive(true); - } - - return this; - } - - // -------------------------------------------- // - // VERSION - // -------------------------------------------- // - - public int version = 5; - - // -------------------------------------------- // - // COMMAND ALIASES - // -------------------------------------------- // - - // Don't you want "f" as the base command alias? Simply change it here. - public List aliasesF = MUtil.list("f"); - - // -------------------------------------------- // - // WORLDS FEATURE ENABLED - // -------------------------------------------- // - - // Use this blacklist/whitelist system to toggle features on a per world basis. - // Do you only want claiming enabled on the one map called "Hurr"? - // In such case set standard to false and add "Hurr" as an exeption to worldsClaimingEnabled. - public WorldExceptionSet worldsClaimingEnabled = new WorldExceptionSet(); - public WorldExceptionSet worldsPowerLossEnabled = new WorldExceptionSet(); - public WorldExceptionSet worldsPowerGainEnabled = new WorldExceptionSet(); - - public WorldExceptionSet worldsPvpRulesEnabled = new WorldExceptionSet(); - - // -------------------------------------------- // - // DERPY OVERRIDES - // -------------------------------------------- // - - // Add player names here who should bypass all protections. - // Should /not/ be used for admins. There is "/f adminmode" for that. - // This is for other plugins/mods that use a fake player to take actions, which shouldn't be subject to our protections. - public Set playersWhoBypassAllProtection = new MassiveSet<>(); - - // -------------------------------------------- // - // REMOVE DATA - // -------------------------------------------- // - - // Should players be kicked from their faction and their data erased when banned? - public boolean removePlayerWhenBanned = true; - - // After how many milliseconds should players be automatically kicked from their faction? - - // The Default - @EditorType(TypeMillisDiff.class) - public long cleanInactivityToleranceMillis = 10 * TimeUnit.MILLIS_PER_DAY; // 10 days - - // Player Age Bonus - @EditorTypeInner({TypeMillisDiff.class, TypeMillisDiff.class}) - public Map cleanInactivityToleranceMillisPlayerAgeToBonus = MUtil.map( - 2 * TimeUnit.MILLIS_PER_WEEK, 10 * TimeUnit.MILLIS_PER_DAY // +10 days after 2 weeks - ); - - // Faction Age Bonus - @EditorTypeInner({TypeMillisDiff.class, TypeMillisDiff.class}) - public Map cleanInactivityToleranceMillisFactionAgeToBonus = MUtil.map( - 4 * TimeUnit.MILLIS_PER_WEEK, 10 * TimeUnit.MILLIS_PER_DAY, // +10 days after 4 weeks - 2 * TimeUnit.MILLIS_PER_WEEK, 5 * TimeUnit.MILLIS_PER_DAY // +5 days after 2 weeks - ); - - // -------------------------------------------- // - // DEFAULTS - // -------------------------------------------- // - - // Which faction should new players be followers of? - // "none" means Wilderness. Remember to specify the id, like "3defeec7-b3b1-48d9-82bb-2a8903df24e3" and not the name. - public String defaultPlayerFactionId = Factions.ID_NONE; - - // What power should the player start with? - public double defaultPlayerPower = 0.0; - - // -------------------------------------------- // - // MOTD - // -------------------------------------------- // - - // During which event priority should the faction message of the day be displayed? - // Choose between: LOWEST, LOW, NORMAL, HIGH, HIGHEST and MONITOR. - // This setting only matters if "motdDelayTicks" is set to -1 - public EventPriority motdPriority = EventPriority.NORMAL; - - // How many ticks should we delay the faction message of the day with? - // -1 means we don't delay at all. We display it at once. - // 0 means it's deferred to the upcoming server tick. - // 5 means we delay it yet another 5 ticks. - public int motdDelayTicks = -1; - - // -------------------------------------------- // - // POWER - // -------------------------------------------- // - - // What is the maximum player power? - public double powerMax = 10.0; - - // What is the minimum player power? - // NOTE: Negative minimum values is possible. - public double powerMin = 0.0; - - // How much power should be regained per hour online on the server? - public double powerPerHour = 2.0; - - // How much power should be lost on death? - public double powerPerDeath = -2.0; - - // Can players with negative power leave their faction? - // NOTE: This only makes sense to set to false if your "powerMin" setting is negative. - public boolean canLeaveWithNegativePower = true; - - // -------------------------------------------- // - // CORE - // -------------------------------------------- // - - // Is there a maximum amount of members per faction? - // 0 means there is not. If you set it to 100 then there can at most be 100 members per faction. - public int factionMemberLimit = 0; - - // Is there a maximum faction power cap? - // 0 means there is not. Set it to a positive value in case you wan't to use this feature. - public double factionPowerMax = 0.0; - - // Limit the length of faction names here. - public int factionNameLengthMin = 3; - public int factionNameLengthMax = 16; - - // -------------------------------------------- // - // SET LIMITS - // -------------------------------------------- // - - // When using radius setting of faction territory, what is the maximum radius allowed? - public int setRadiusMax = 30; - - // When using fill setting of faction territory, what is the maximum chunk count allowed? - public int setFillMax = 1000; - - // -------------------------------------------- // - // CLAIMS - // -------------------------------------------- // - - // Must claims be connected to each other? - // If you set this to false you will allow factions to claim more than one base per world map. - // That would makes outposts possible but also potentially ugly weird claims messing up your Dynmap and ingame experiance. - public boolean claimsMustBeConnected = true; - - // Must claims be connected to each other enforced strictly? - // If this is enabled there is also done a check on - // unclaim which makes sure you can't make two different bases by unclaiming land. - public boolean claimsMustBeConnectedStrict = false; - - // Would you like to allow unconnected claims when conquering land from another faction? - // Setting this to true would allow taking over someone elses base even if claims normally have to be connected. - // Note that even without this you can pillage/unclaim another factions territory in war. - // You just won't be able to take the land as your own. - public boolean claimsCanBeUnconnectedIfOwnedByOtherFaction = false; - - // Is claiming from other factions even allowed? - // Set this to false to disable territorial warfare altogether. - public boolean claimingFromOthersAllowed = true; - - // Is it required for factions to have an inflated land/power ratio in order to have their land conquered by another faction? - // Set this to false to allow factions to invade each other without requiring them to have an inflated land/power ratio.. - public boolean claimingFromOthersMustBeInflated = true; - - // Is a minimum distance (measured in chunks) to other factions required? - // 0 means the feature is disabled. - // Set the feature to 10 and there must be 10 chunks of wilderness between factions. - // Factions may optionally allow their allies to bypass this limit by configuring their faction permissions ingame themselves. - public int claimMinimumChunksDistanceToOthers = 0; - - // Do you need a minimum amount of faction members to claim land? - // 1 means just the faction leader alone is enough. - public int claimsRequireMinFactionMembers = 1; - - // Is there a maximum limit to chunks claimed? - // 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 - // -------------------------------------------- // - - public boolean protectionLiquidFlowEnabled = true; - - // Protects the faction land from piston extending/retracting - // through the denying of MPerm build - public boolean handlePistonProtectionThroughDenyBuild = true; - - // -------------------------------------------- // - // WARPS - // -------------------------------------------- // - - // 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 warps inside enemy territory. - public boolean warpsMustBeInClaimedTerritory = true; - - // And what faction warp should be used when a player types /f home - public String warpsHomeName = "home"; - - // 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; - - // Should players teleport to faction warp on death? - // Set this to true to override the default respawn location. - public boolean warpsTeleportToOnDeathActive = false; - - // And what 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 warpsTeleportToOnDeathPriority = EventPriority.NORMAL; - - // -------------------------------------------- // - // TERRITORY INFO - // -------------------------------------------- // - - public boolean territoryInfoTitlesDefault = true; - - public String territoryInfoTitlesMain = "{relcolor}{name}"; - public String territoryInfoTitlesSub = "{desc}"; - public int territoryInfoTitlesTicksIn = 5; - public int territoryInfoTitlesTicksStay = 60; - public int territoryInfoTitleTicksOut = 5; - - public String territoryInfoChat = " ~ {relcolor}{name} {desc}"; - - public boolean territoryAccessShowMessage = true; - - // -------------------------------------------- // - // ASSORTED - // -------------------------------------------- // - - // Set this to true if want to block the promotion of new leaders for permanent factions. - // I don't really understand the user case for this option. - public boolean permanentFactionsDisableLeaderPromotion = false; - - // How much health damage should a player take upon placing or breaking a block in a "pain build" territory? - // 2.0 means one heart. - public double actionDeniedPainAmount = 2.0D; - - // If you set this option to true then factionless players cant partake in PVP. - // It works in both directions. Meaning you must join a faction to hurt players and get hurt by players. - public boolean disablePVPForFactionlessPlayers = false; - - // If you set this option to true then factionless players cant damage each other. - // So two factionless can't PvP, but they can PvP with others if that is allowed. - public boolean enablePVPBetweenFactionlessPlayers = true; - - // Set this option to true to create an exception to the rule above. - // Players inside their own faction territory can then hurt facitonless players. - // This way you may "evict" factionless trolls messing around in your home base. - public boolean enablePVPAgainstFactionlessInAttackersLand = false; - - // Inside your own faction territory you take less damage. - // 0.1 means that you take 10% less damage at home. - public double territoryShieldFactor = 0.1D; - - // Make faction disbanding a confirmation thing - public boolean requireConfirmationForFactionDisbanding = true; - - // At what speed can players fly with /f fly? - public float flySpeed = 0.1f; - - // Will flying be disabled on pvp - public boolean flyDisableOnPvp = false; - - // -------------------------------------------- // - // DENY COMMANDS - // -------------------------------------------- // - - // A list of commands to block for members of permanent factions. - // I don't really understand the user case for this option. - public List denyCommandsPermanentFactionMember = new ArrayList<>(); - - // Lists of commands to deny depending on your relation to the current faction territory. - // You may for example not type /home (might be the plugin Essentials) in the territory of your enemies. - public Map> denyCommandsTerritoryRelation = MUtil.map( - Rel.ENEMY, MUtil.list( - // Essentials commands - "home", - "homes", - "sethome", - "createhome", - "tpahere", - "tpaccept", - "tpyes", - "tpa", - "call", - "tpask", - "warp", - "warps", - "spawn", - // Essentials e-alliases - "ehome", - "ehomes", - "esethome", - "ecreatehome", - "etpahere", - "etpaccept", - "etpyes", - "etpa", - "ecall", - "etpask", - "ewarp", - "ewarps", - "espawn", - // Essentials fallback alliases - "essentials:home", - "essentials:homes", - "essentials:sethome", - "essentials:createhome", - "essentials:tpahere", - "essentials:tpaccept", - "essentials:tpyes", - "essentials:tpa", - "essentials:call", - "essentials:tpask", - "essentials:warp", - "essentials:warps", - "essentials:spawn", - // Other plugins - "wtp", - "uspawn", - "utp", - "mspawn", - "mtp", - "fspawn", - "ftp", - "jspawn", - "jtp" - ), - Rel.NEUTRAL, new ArrayList(), - Rel.TRUCE, new ArrayList(), - Rel.ALLY, new ArrayList(), - Rel.FACTION, new ArrayList() - ); - - // The distance for denying the following commands. Set to -1 to disable. - public double denyCommandsDistance = -1; - - // Lists of commands to deny depending on your relation to a nearby enemy in the above distance. - public Map> denyCommandsDistanceRelation = MUtil.map( - Rel.ENEMY, MUtil.list( - "home" - ), - Rel.NEUTRAL, new ArrayList(), - Rel.TRUCE, new ArrayList(), - Rel.ALLY, new ArrayList(), - Rel.FACTION, new ArrayList() - ); - - // Allow bypassing the above setting when in these territories. - public List denyCommandsDistanceBypassIn = MUtil.list( - Rel.FACTION, - Rel.ALLY - ); - - // -------------------------------------------- // - // CHAT - // -------------------------------------------- // - - // Should Factions set the chat format? - // This should be kept at false if you use an external chat format plugin. - // If you are planning on running a more lightweight server you can set this to true. - public boolean chatSetFormat = true; - - // At which event priority should the chat format be set in such case? - // Choose between: LOWEST, LOW, NORMAL, HIGH and HIGHEST. - public EventPriority chatSetFormatAt = EventPriority.LOWEST; - - // What format should be set? - public String chatSetFormatTo = "<{factions_relcolor}§l{factions_roleprefix}§r{factions_relcolor}{factions_name|rp}§f%1$s> %2$s"; - - // Should the chat tags such as {factions_name} be parsed? - // NOTE: You can set this to true even with chatSetFormat = false. - // But in such case you must set the chat format using an external chat format plugin. - public boolean chatParseTags = true; - - // At which event priority should the faction chat tags be parsed in such case? - // Choose between: LOWEST, LOW, NORMAL, HIGH, HIGHEST. - public EventPriority chatParseTagsAt = EventPriority.LOW; - - // -------------------------------------------- // - // COLORS - // -------------------------------------------- // - - // Here you can alter the colors tied to certain faction relations and settings. - // You probably don't want to edit these to much. - // Doing so might confuse players that are used to Factions. - public ChatColor colorMember = ChatColor.GREEN; - public ChatColor colorAlly = ChatColor.DARK_PURPLE; - public ChatColor colorTruce = ChatColor.LIGHT_PURPLE; - public ChatColor colorNeutral = ChatColor.WHITE; - public ChatColor colorEnemy = ChatColor.RED; - - // This one is for example applied to SafeZone since that faction has the pvp flag set to false. - public ChatColor colorNoPVP = ChatColor.GOLD; - - // This one is for example applied to WarZone since that faction has the friendly fire flag set to true. - public ChatColor colorFriendlyFire = ChatColor.DARK_RED; - - // -------------------------------------------- // - // EXPLOITS - // -------------------------------------------- // - - public boolean handleExploitObsidianGenerators = true; - public boolean handleExploitEnderPearlClipping = true; - public boolean handleNetherPortalTrap = true; - - // -------------------------------------------- // - // UNSTUCK - // -------------------------------------------- // - - public int unstuckSeconds = 30; - public int unstuckChunkRadius = 10; - - // -------------------------------------------- // - // ENDER PEARL AND CHORUS FRUIT - // -------------------------------------------- // - - public boolean allowEnderPearlInEnemyTerritory = true; - public boolean allowEnderPearlInWildernessTerritory = true; - public boolean allowEnderPearlInOwnTerritory = true; - public boolean allowEnderPearlInOtherTerritory = true; - - public boolean allowChorusFruitInEnemyTerritory = true; - public boolean allowChorusFruitInWildernessTerritory = true; - public boolean allowChorusFruitInOwnTerritory = true; - public boolean allowChorusFruitInOtherTerritory = true; - - // -------------------------------------------- // - // LOGGING - // -------------------------------------------- // - - // Here you can disable logging of certain events to the server console. - - public boolean logFactionCreate = true; - public boolean logFactionDisband = true; - public boolean logFactionJoin = true; - public boolean logFactionKick = true; - public boolean logFactionLeave = true; - public boolean logLandClaims = true; - public boolean logMoneyTransactions = true; - - // -------------------------------------------- // - // TAX - // -------------------------------------------- // - - // Should the tax system be enabled? - public boolean taxEnabled = false; - - // How much can you tax a player? - public double taxPlayerMinimum = -10; - public double taxPlayerMaximum = 10; - - // How much should Factions be taxed? - //public double taxUpkeepBase = 0; - //public double taxUpkeepPerChunk = 1; - - // When is a player inactive? - public int taxInactiveDays = 3; - - // When the last run time was (in unix time) - // 0 means never - public long taxTaskLastMillis = 0; - - // Tax run when? - // 0 means at midnight UTC it can be offset by a certain millis - public long taxTaskInvocationOffsetMillis = 0; - - // How often should the task be run? - public long taxTaskPeriodMillis = TimeUnit.MILLIS_PER_DAY; - - // -------------------------------------------- // - // RANKS - // -------------------------------------------- // - - @EditorVisible(false) - public List defaultRanks = MUtil.list( - new Rank("Leader", 400, "**"), - new Rank("Officer", 300, "*"), - new Rank("Member", 200, "+"), - new Rank("Recruit", 100, "-") - ); - - // -------------------------------------------- // - // PERMISSIONS - // -------------------------------------------- // - - public Map> perm2default = MUtil.map( - MPerm.ID_BUILD, MUtil.set("LEADER", "OFFICER", "MEMBER"), - MPerm.ID_PAINBUILD, MUtil.set(), - MPerm.ID_DOOR, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), - MPerm.ID_BUTTON, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), - MPerm.ID_LEVER, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), - MPerm.ID_CONTAINER, MUtil.set("LEADER", "OFFICER", "MEMBER"), - - MPerm.ID_NAME, MUtil.set("LEADER"), - MPerm.ID_DESC, MUtil.set("LEADER", "OFFICER"), - MPerm.ID_MOTD, MUtil.set("LEADER", "OFFICER"), - MPerm.ID_INVITE, MUtil.set("LEADER", "OFFICER"), - MPerm.ID_KICK, MUtil.set("LEADER", "OFFICER"), - MPerm.ID_RANK, MUtil.set("LEADER", "OFFICER"), - MPerm.ID_TITLE, MUtil.set("LEADER", "OFFICER"), - MPerm.ID_WARP, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), - MPerm.ID_SETWARP, MUtil.set("LEADER", "OFFICER"), - MPerm.ID_DEPOSIT, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY", "TRUCE", "NEUTRAL", "ENEMY"), - MPerm.ID_WITHDRAW, MUtil.set("LEADER"), - MPerm.ID_TERRITORY, MUtil.set("LEADER", "OFFICER"), - MPerm.ID_ACCESS, MUtil.set("LEADER", "OFFICER"), - MPerm.ID_VOTE, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT"), - MPerm.ID_CREATEVOTE, MUtil.set("LEADER", "OFFICER"), - MPerm.ID_CLAIMNEAR, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), - MPerm.ID_TAX, MUtil.set("LEADER"), - MPerm.ID_REL, MUtil.set("LEADER", "OFFICER"), - MPerm.ID_DISBAND, MUtil.set("LEADER"), - MPerm.ID_FLAGS, MUtil.set("LEADER"), - MPerm.ID_PERMS, MUtil.set("LEADER") - ); - - // -------------------------------------------- // - // ENUMERATIONS - // -------------------------------------------- // - // In this configuration section you can add support for Forge mods that add new Materials and EntityTypes. - // This way they can be protected in Faction territory. - // Use the "UPPER_CASE_NAME" for the Material or EntityType in question. - // If you are running a regular Spigot server you don't have to edit this section. - // In fact all of these sets can be empty on regular Spigot servers without any risk. - - // Interacting with these materials when they are already placed in the terrain results in an edit. - public BackstringSet materialsEditOnInteract = new BackstringSet<>(Material.class); - - // Interacting with the the terrain holding this item in hand results in an edit. - // There's no need to add all block materials here. Only special items other than blocks. - public BackstringSet materialsEditTools = new BackstringSet<>(Material.class); - - // Interacting with these materials placed in the terrain results in door toggling. - public BackstringSet materialsDoor = new BackstringSet<>(Material.class); - - // Interacting with these materials placed in the terrain results in opening a container. - public BackstringSet materialsContainer = new BackstringSet<>(Material.class); - - // Interacting with these entities results in an edit. - public BackstringSet entityTypesEditOnInteract = new BackstringSet<>(EntityType.class); - - // Damaging these entities results in an edit. - public BackstringSet entityTypesEditOnDamage = new BackstringSet<>(EntityType.class); - - // Interacting with these entities results in opening a container. - public BackstringSet entityTypesContainer = new BackstringSet<>(EntityType.class); - - // The complete list of entities considered to be monsters. - public BackstringSet entityTypesMonsters = new BackstringSet<>(EntityType.class); - - // List of entities considered to be animals. - public BackstringSet entityTypesAnimals = new BackstringSet<>(EntityType.class); - - // -------------------------------------------- // - // INTEGRATION: LWC - // -------------------------------------------- // - - // Do you need faction build rights in the territory to create an LWC protection there? - public boolean lwcMustHaveBuildRightsToCreate = true; - - // The config option above does not handle situations where a player creates an LWC protection in Faction territory and then leaves the faction. - // The player would then have an LWC protection in a territory where they can not build. - // Set this config option to true to enable an automatic removal feature. - // LWC protections that couldn't be created will be removed on an attempt to open them by any player. - public boolean lwcRemoveIfNoBuildRights = false; - - // WARN: Experimental and semi buggy. - // If you change this to true: alien LWC protections will be removed upon using /f set. - public Map lwcRemoveOnChange = MUtil.map( - EventFactionsChunkChangeType.BUY, false, // when claiming from wilderness - EventFactionsChunkChangeType.SELL, false, // when selling back to wilderness - EventFactionsChunkChangeType.CONQUER, false, // when claiming from another player faction - EventFactionsChunkChangeType.PILLAGE, false // when unclaiming (to wilderness) from another player faction - ); - - // -------------------------------------------- // - // INTEGRATION: WorldGuard - // -------------------------------------------- // - - // Global WorldGuard Integration Switch - public boolean worldguardCheckEnabled = false; - - // Enable the WorldGuard check per-world - // Specify which worlds the WorldGuard Check can be used in - public WorldExceptionSet worldguardCheckWorldsEnabled = new WorldExceptionSet(); - - // -------------------------------------------- // - // INTEGRATION: VentureChat - // -------------------------------------------- // - - public String ventureChatFactionChannelName = "faction"; - public String ventureChatAllyChannelName = "ally"; - public boolean ventureChatAllowFactionchatBetweenFactionless = false; - - // -------------------------------------------- // - // INTEGRATION: ECONOMY - // -------------------------------------------- // - - // Should economy features be enabled? - // This requires that you have the external plugin called "Vault" installed. - public boolean econEnabled = true; - - // When paying a cost you may specify an account that should receive the money here. - // Per default "" the money is just destroyed. - public String econUniverseAccount = ""; - - // What is the price per chunk when using /f set? - public Map econChunkCost = MUtil.map( - EventFactionsChunkChangeType.BUY, 1.0, // when claiming from wilderness - EventFactionsChunkChangeType.SELL, 0.0, // when selling back to wilderness - EventFactionsChunkChangeType.CONQUER, 0.0, // when claiming from another player faction - EventFactionsChunkChangeType.PILLAGE, 0.0 // when unclaiming (to wilderness) from another player faction - ); - - // What is the price to create a faction? - public double econCostCreate = 100.0; - - // And so on and so forth ... you get the idea. - 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 econCostWarpGo = 0.0; - public double econCostName = 0.0; - public double econCostDescription = 0.0; - public double econCostTitle = 0.0; - public double econCostFlag = 0.0; - - public Map econRelCost = MUtil.map( - Rel.ENEMY, 0.0, - Rel.ALLY, 0.0, - Rel.TRUCE, 0.0, - Rel.NEUTRAL, 0.0 - ); - - // Should the faction bank system be enabled? - // This enables the command /f money. - public boolean bankEnabled = true; - - // That costs should the faciton bank take care of? - // If you set this to false the player executing the command will pay instead. - public boolean bankFactionPaysCosts = true; - - public boolean useNewMoneySystem = false; - - // -------------------------------------------- // - // INTEGRATION: DYNMAP - // -------------------------------------------- // - - // Should the dynmap intagration be used? - public boolean dynmapEnabled = true; - - // Should the dynmap updates be logged to console output? - public boolean dynmapLogTimeSpent = false; - - // Name of the Factions layer - public String dynmapLayerName = "Factions"; - - // Should the layer be visible per default - public boolean dynmapLayerHiddenByDefault = false; - - // Ordering priority in layer menu (low goes before high - default is 0) - public int dynmapLayerPriority = 2; - - // (optional) set minimum zoom level before layer is visible (0 = defalt, always visible) - public int dynmapLayerMinimumZoom = 0; - - // Format for popup - substitute values for macros - //public String dynmapInfowindowFormat = "
%regionname%
Flags
%flags%
"; - public String dynmapFactionDescription = - "
\n" + - "%name%
\n" + - "%description%
\n" + - "
\n" + - "Leader: %players.leader%
\n" + - "Members: %players%
\n" + - "
\n" + - "Age: %age%
\n" + - "Bank: %money%
\n" + - "
\n" + - "Flags:
\n" + - "%flags.table3%\n" + - "
"; - - // Enable the %money% macro. Only do this if you know your economy manager is thread safe. - public boolean dynmapShowMoneyInDescription = false; - - // Allow players in faction to see one another on Dynmap (only relevant if Dynmap has 'player-info-protected' enabled) - //public boolean dynmapVisibilityByFaction = true; - - // Optional setting to limit which regions to show. - // If empty all regions are shown. - // Specify Faction either by name or UUID. - // To show all regions on a given world, add 'world:' to the list. - public Set dynmapVisibleFactions = new MassiveSet<>(); - - // Optional setting to hide specific Factions. - // Specify Faction either by name or UUID. - // To hide all regions on a given world, add 'world:' to the list. - public Set dynmapHiddenFactions = new MassiveSet<>(); - - @EditorVisible(false) - public DynmapStyle dynmapDefaultStyle = new DynmapStyle( - IntegrationDynmap.DYNMAP_STYLE_LINE_COLOR, - IntegrationDynmap.DYNMAP_STYLE_LINE_OPACITY, - IntegrationDynmap.DYNMAP_STYLE_LINE_WEIGHT, - IntegrationDynmap.DYNMAP_STYLE_FILL_COLOR, - IntegrationDynmap.DYNMAP_STYLE_FILL_OPACITY, - IntegrationDynmap.DYNMAP_STYLE_HOME_MARKER, - IntegrationDynmap.DYNMAP_STYLE_BOOST - ); - - // Optional per Faction style overrides. Any defined replace those in dynmapDefaultStyle. - // Specify Faction either by name or UUID. - @EditorVisible(false) - public Map dynmapFactionStyles = MUtil.map( - "SafeZone", new DynmapStyle().withLineColor("#FF00FF").withFillColor("#FF00FF").withBoost(false), - "WarZone", new DynmapStyle().withLineColor("#FF0000").withFillColor("#FF0000").withBoost(false) - ); -} diff --git a/src/com/massivecraft/factions/entity/MConfColl.java b/src/com/massivecraft/factions/entity/MConfColl.java deleted file mode 100644 index 3ae6ce9d..00000000 --- a/src/com/massivecraft/factions/entity/MConfColl.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.massivecraft.factions.entity; - -import com.massivecraft.massivecore.MassiveCore; -import com.massivecraft.massivecore.store.Coll; - -public class MConfColl extends Coll -{ - // -------------------------------------------- // - // 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); - } - -} diff --git a/src/com/massivecraft/factions/entity/MFlag.java b/src/com/massivecraft/factions/entity/MFlag.java deleted file mode 100644 index 4e631c88..00000000 --- a/src/com/massivecraft/factions/entity/MFlag.java +++ /dev/null @@ -1,309 +0,0 @@ -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 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 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; - - // -------------------------------------------- // - // META: CORE - // -------------------------------------------- // - - public static MFlag get(Object oid) - { - return MFlagColl.get().get(oid); - } - - public static List getAll() - { - return getAll(Bukkit.isPrimaryThread()); - } - - public static List 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(); - } - - 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 for members in faction territory?", "Members can fly in faction territory.", "Members 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 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 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 = "YES"; - String no = monoSpace ? "NOO" : "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("%s", desc); - } - -} diff --git a/src/com/massivecraft/factions/entity/MFlagColl.java b/src/com/massivecraft/factions/entity/MFlagColl.java deleted file mode 100644 index 075454c5..00000000 --- a/src/com/massivecraft/factions/entity/MFlagColl.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.massivecraft.factions.entity; - -import com.massivecraft.massivecore.store.Coll; - -import java.util.ArrayList; -import java.util.List; - -public class MFlagColl extends Coll -{ - // -------------------------------------------- // - // 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 getAll(boolean registered) - { - // Create - List ret = new ArrayList<>(); - - // Fill - for (MFlag mflag : this.getAll()) - { - if (mflag.isRegistered() != registered) continue; - ret.add(mflag); - } - - // Return - return ret; - } - -} diff --git a/src/com/massivecraft/factions/entity/MPerm.java b/src/com/massivecraft/factions/entity/MPerm.java deleted file mode 100644 index d6dd1976..00000000 --- a/src/com/massivecraft/factions/entity/MPerm.java +++ /dev/null @@ -1,496 +0,0 @@ -package com.massivecraft.factions.entity; - -import com.massivecraft.factions.AccessStatus; -import com.massivecraft.factions.Perm; -import com.massivecraft.factions.Rel; -import com.massivecraft.factions.TerritoryAccess; -import com.massivecraft.factions.cmd.CmdFactions; -import com.massivecraft.factions.event.EventFactionsCreatePerms; -import com.massivecraft.massivecore.Identified; -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.ps.PS; -import com.massivecraft.massivecore.store.Entity; -import com.massivecraft.massivecore.util.IdUtil; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Comparator; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -public class MPerm extends Entity implements Prioritized, Registerable, Named -{ - // -------------------------------------------- // - // CONSTANTS - // -------------------------------------------- // - - public final static transient String ID_BUILD = "build"; - public final static transient String ID_PAINBUILD = "painbuild"; - public final static transient String ID_DOOR = "door"; - public final static transient String ID_BUTTON = "button"; - public final static transient String ID_LEVER = "lever"; - public final static transient String ID_CONTAINER = "container"; - - public final static transient String ID_NAME = "name"; - public final static transient String ID_DESC = "desc"; - public final static transient String ID_MOTD = "motd"; - public final static transient String ID_INVITE = "invite"; - public final static transient String ID_KICK = "kick"; - public final static transient String ID_RANK = "rank"; - public final static transient String ID_TITLE = "title"; - public final static transient String ID_WARP = "warp"; - public final static transient String ID_SETWARP = "setwarp"; - public final static transient String ID_DEPOSIT = "deposit"; - public final static transient String ID_WITHDRAW = "withdraw"; - public final static transient String ID_TERRITORY = "territory"; - public final static transient String ID_ACCESS = "access"; - public final static transient String ID_VOTE = "VOTE"; // Why is this capitalised? Can that be easily changed? - public final static transient String ID_CREATEVOTE = "createvote"; - public final static transient String ID_CLAIMNEAR = "claimnear"; - public final static transient String ID_TAX = "tax"; - public final static transient String ID_REL = "rel"; - public final static transient String ID_DISBAND = "disband"; - public final static transient String ID_FLAGS = "flags"; - public final static transient String ID_PERMS = "perms"; - - public final static transient int PRIORITY_BUILD = 1000; - public final static transient int PRIORITY_PAINBUILD = 2000; - public final static transient int PRIORITY_DOOR = 3000; - public final static transient int PRIORITY_BUTTON = 4000; - public final static transient int PRIORITY_LEVER = 5000; - public final static transient int PRIORITY_CONTAINER = 6000; - - public final static transient int PRIORITY_NAME = 7000; - public final static transient int PRIORITY_DESC = 8000; - public final static transient int PRIORITY_MOTD = 9000; - public final static transient int PRIORITY_INVITE = 10000; - public final static transient int PRIORITY_KICK = 11000; - public final static transient int PRIORITY_RANK = 11500; - public final static transient int PRIORITY_TITLE = 12000; - public final static transient int PRIORITY_WARP = 13000; - public final static transient int PRIORITY_SETWARP = 14000; - public final static transient int PRIORITY_DEPOSIT = 15000; - public final static transient int PRIORITY_WITHDRAW = 16000; - public final static transient int PRIORITY_TERRITORY = 17000; - public final static transient int PRIORITY_ACCESS = 18000; - public final static transient int PRIORITY_VOTE = 18200; - public final static transient int PRIORITY_CREATEVOTE = 18600; - public final static transient int PRIORITY_CLAIMNEAR = 19000; - public final static transient int PRIORITY_TAX = 19500; - public final static transient int PRIORITY_REL = 20000; - public final static transient int PRIORITY_DISBAND = 21000; - public final static transient int PRIORITY_FLAGS = 22000; - public final static transient int PRIORITY_PERMS = 23000; - - // -------------------------------------------- // - // META: CORE - // -------------------------------------------- // - - public static MPerm get(Object oid) - { - return MPermColl.get().get(oid); - } - - public static List getAll() - { - return getAll(false); - } - - public static List getAll(boolean isAsync) - { - setupStandardPerms(); - new EventFactionsCreatePerms().run(); - - return MPermColl.get().getAll(PredicateIsRegistered.get(), ComparatorSmart.get()); - } - - public static void setupStandardPerms() - { - getPermBuild(); - getPermPainbuild(); - getPermDoor(); - getPermButton(); - getPermLever(); - getPermContainer(); - - getPermName(); - getPermDesc(); - getPermMotd(); - getPermInvite(); - getPermKick(); - getPermRank(); - getPermTitle(); - getPermWarp(); - getPermSetwarp(); - getPermDeposit(); - getPermWithdraw(); - getPermTerritory(); - getPermAccess(); - getPermVote(); - getPermCreateVote(); - getPermClaimnear(); - getPermTax(); - getPermRel(); - getPermDisband(); - getPermFlags(); - getPermPerms(); - } - - public static MPerm getPermBuild() { return getCreative(PRIORITY_BUILD, ID_BUILD, ID_BUILD, "edit the terrain", true, true, true); } - public static MPerm getPermPainbuild() { return getCreative(PRIORITY_PAINBUILD, ID_PAINBUILD, ID_PAINBUILD, "edit, take damage", true, true, true); } - public static MPerm getPermDoor() { return getCreative(PRIORITY_DOOR, ID_DOOR, ID_DOOR, "use doors", true, true, true); } - public static MPerm getPermButton() { return getCreative(PRIORITY_BUTTON, ID_BUTTON, ID_BUTTON, "use stone buttons", true, true, true); } - public static MPerm getPermLever() { return getCreative(PRIORITY_LEVER, ID_LEVER, ID_LEVER, "use levers", true, true, true); } - public static MPerm getPermContainer() { return getCreative(PRIORITY_CONTAINER, ID_CONTAINER, ID_CONTAINER, "use containers", true, true, true); } - - public static MPerm getPermName() { return getCreative(PRIORITY_NAME, ID_NAME, ID_NAME, "set name", false, true, true); } - public static MPerm getPermDesc() { return getCreative(PRIORITY_DESC, ID_DESC, ID_DESC, "set description", false, true, true); } - public static MPerm getPermMotd() { return getCreative(PRIORITY_MOTD, ID_MOTD, ID_MOTD, "set motd", false, true, true); } - public static MPerm getPermInvite() { return getCreative(PRIORITY_INVITE, ID_INVITE, ID_INVITE, "invite players", false, true, true); } - public static MPerm getPermKick() { return getCreative(PRIORITY_KICK, ID_KICK, ID_KICK, "kick members", false, true, true); } - public static MPerm getPermRank() { return getCreative(PRIORITY_RANK, ID_RANK, ID_RANK, "change ranks", false, true, true); } - public static MPerm getPermTitle() { return getCreative(PRIORITY_TITLE, ID_TITLE, ID_TITLE, "set titles", false, true, true); } - public static MPerm getPermWarp() { return getCreative(PRIORITY_WARP, ID_WARP, ID_WARP, "teleport to warp", false, true, true); } - public static MPerm getPermSetwarp() { return getCreative(PRIORITY_SETWARP, ID_SETWARP, ID_SETWARP, "set warps", false, true, true); } - public static MPerm getPermDeposit() { return getCreative(PRIORITY_DEPOSIT, ID_DEPOSIT, ID_DEPOSIT, "deposit money", false, false, false); } // non editable, non visible. - public static MPerm getPermWithdraw() { return getCreative(PRIORITY_WITHDRAW, ID_WITHDRAW, ID_WITHDRAW, "withdraw money", false, true, true); } - public static MPerm getPermTerritory() { return getCreative(PRIORITY_TERRITORY, ID_TERRITORY, ID_TERRITORY, "claim or unclaim", false, true, true); } - public static MPerm getPermAccess() { return getCreative(PRIORITY_ACCESS, ID_ACCESS, ID_ACCESS, "grant territory", false, true, true); } - public static MPerm getPermVote() { return getCreative(PRIORITY_VOTE, ID_VOTE, ID_VOTE, "vote", false, true, true); } - public static MPerm getPermCreateVote() { return getCreative(PRIORITY_CREATEVOTE, ID_CREATEVOTE, ID_CREATEVOTE, "manage votes", false, true, true); } - public static MPerm getPermClaimnear() { return getCreative(PRIORITY_CLAIMNEAR, ID_CLAIMNEAR, ID_CLAIMNEAR, "claim nearby", false, false, false); } // non editable, non visible. - public static MPerm getPermTax() { return getCreative(PRIORITY_TAX, ID_TAX, ID_TAX, "set taxes", false, true, true); } - public static MPerm getPermRel() { return getCreative(PRIORITY_REL, ID_REL, ID_REL, "change relations", false, true, true); } - public static MPerm getPermDisband() { return getCreative(PRIORITY_DISBAND, ID_DISBAND, ID_DISBAND, "disband the faction", false, true, true); } - public static MPerm getPermFlags() { return getCreative(PRIORITY_FLAGS, ID_FLAGS, ID_FLAGS, "manage flags", false, true, true); } - public static MPerm getPermPerms() { return getCreative(PRIORITY_PERMS, ID_PERMS, ID_PERMS, "manage permissions", false, true, true); } - - public static MPerm getCreative(int priority, String id, String name, String desc, boolean territory, boolean editable, boolean visible) - { - MPerm ret = MPermColl.get().get(id, false); - if (ret != null) - { - ret.setRegistered(true); - return ret; - } - - ret = new MPerm(priority, name, desc, territory, editable, visible); - MPermColl.get().attach(ret, id); - ret.setRegistered(true); - ret.sync(); - - return ret; - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public MPerm load(MPerm that) - { - //System.out.println("Loading MPerm"); - this.priority = that.priority; - this.name = that.name; - this.desc = that.desc; - this.territory = that.territory; - 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; } - - // -------------------------------------------- // - // VERSION - // -------------------------------------------- // - - public int version = 2; - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - // The sort priority. Low values appear first in sorted lists. - // 1 is high up, 99999 is far down. - // Standard Faction perms use "thousand values" like 1000, 2000, 3000 etc to allow adding new perms inbetween. - // So 1000 might sound like a lot but it's actually the priority for the first perm. - private int priority = 0; - @Override public int getPriority() { return this.priority; } - public MPerm setPriority(int priority) { this.priority = priority; this.changed(); return this; } - - // The name of the perm. According to standard it should be fully lowercase just like the perm id. - // In fact the name and the id of all standard perms are the same. - // I just added the name in case anyone feel like renaming their perms for some reason. - // Example: "build" - private String name = "defaultName"; - @Override public String getName() { return this.name; } - public MPerm setName(String name) { this.name = name; this.changed(); return this; } - - // The perm function described as an "order". - // The desc should match the format: - // "You are not allowed to X." - // "You are not allowed to edit the terrain." - // Example: "edit the terrain" - private String desc = "defaultDesc"; - public String getDesc() { return this.desc; } - public MPerm setDesc(String desc) { this.desc = desc; this.changed(); return this; } - - // What is the standard (aka default) perm value? - // This value will be set for factions from the beginning. - // Example: ... set of relations ... - //@Deprecated - //private Set standard = null; - //@Deprecated public Set getStandard() { return this.standard; } - //@Deprecated public MPerm setStandard(Set standard) { this.standard = standard; this.changed(); return this; } - - // Is this a territory perm meaning it has to do with territory construction, modification or interaction? - // True Examples: build, container, door, lever etc. - // False Examples: name, invite, home, sethome, deposit, withdraw etc. - private boolean territory = false; - public boolean isTerritory() { return this.territory; } - public MPerm setTerritory(boolean territory) { this.territory = territory; this.changed(); return this; } - - // Is this perm editable by players? - // With this we mean standard non administrator players. - // All perms can be changed using /f override. - // Example: true (all perms are editable by default) - private boolean editable = false; - public boolean isEditable() { return this.editable; } - public MPerm setEditable(boolean editable) { this.editable = editable; this.changed(); return this; } - - // Is this perm visible to players? - // With this we mean standard non administrator players. - // All perms can be seen using /f override. - // Some perms can be rendered meaningless by settings in Factions or external plugins. - // Say we set "editable" to false. - // In such case we might want to hide the perm by setting "visible" false. - // If it can't be changed, why bother showing it? - // Example: true (yeah we need to see this permission) - private boolean visible = true; - public boolean isVisible() { return this.visible; } - public MPerm setVisible(boolean visible) { this.visible = visible; this.changed(); return this; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public MPerm() - { - // No argument constructor for GSON - } - - public MPerm(int priority, String name, String desc, boolean territory, boolean editable, boolean visible) - { - this.priority = priority; - this.name = name; - this.desc = desc; - this.territory = territory; - this.editable = editable; - this.visible = visible; - } - - // -------------------------------------------- // - // EXTRAS - // -------------------------------------------- // - - public String createDeniedMessage(MPlayer mplayer, Faction hostFaction) - { - // Null Check - if (mplayer == null) throw new NullPointerException("mplayer"); - if (hostFaction == null) throw new NullPointerException("hostFaction"); - - String ret = Txt.parse("%s does not allow you to %s.", hostFaction.describeTo(mplayer, true), this.getDesc()); - - Player player = mplayer.getPlayer(); - if (player != null && Perm.OVERRIDE.has(player)) - { - ret += Txt.parse("\nYou can bypass by using " + CmdFactions.get().cmdFactionsOverride.getTemplate(false).toPlain(true)); - } - - return ret; - } - - public String getDesc(boolean withName, boolean withDesc) - { - List parts = new ArrayList<>(); - - if (withName) - { - String nameFormat; - if ( ! this.isVisible()) - { - nameFormat = "%s"; - } - else if (this.isEditable()) - { - nameFormat = "%s"; - } - else - { - nameFormat = "%s"; - } - String name = this.getName(); - String nameDesc = Txt.parse(nameFormat, name); - parts.add(nameDesc); - } - - if (withDesc) - { - String desc = this.getDesc(); - - String descDesc = Txt.parse("%s", desc); - parts.add(descDesc); - } - - return Txt.implode(parts, " "); - } - - public boolean has(Faction faction, Faction hostFaction) - { - // Null Check - if (faction == null) throw new NullPointerException("faction"); - if (hostFaction == null) throw new NullPointerException("hostFaction"); - - return hostFaction.isFactionPermitted(faction, this); - } - - public boolean has(MPlayer mplayer, Faction hostFaction, boolean verboose) - { - // Null Check - if (mplayer == null) throw new NullPointerException("mplayer"); - if (hostFaction == null) throw new NullPointerException("hostFaction"); - - if (mplayer.isOverriding()) return true; - - Rel rel = mplayer.getRelationTo(hostFaction); - MPermable permable = rel == Rel.FACTION ? mplayer.getRank() : rel; - if (hostFaction.isPlayerPermitted(mplayer, this)) return true; - - if (verboose) mplayer.message(this.createDeniedMessage(mplayer, hostFaction)); - - return false; - } - - public boolean has(MPlayer mplayer, PS ps, boolean verboose) - { - // Null Check - if (mplayer == null) throw new NullPointerException("mplayer"); - if (ps == null) throw new NullPointerException("ps"); - - if (mplayer.isOverriding()) return true; - - TerritoryAccess ta = BoardColl.get().getTerritoryAccessAt(ps); - Faction hostFaction = ta.getHostFaction(); - - if (this.isTerritory()) - { - AccessStatus accessStatus = ta.getTerritoryAccess(mplayer); - if (accessStatus != AccessStatus.STANDARD) - { - if (verboose && accessStatus == AccessStatus.DECREASED) - { - mplayer.message(this.createDeniedMessage(mplayer, hostFaction)); - } - - return accessStatus.hasAccess(); - } - } - - return this.has(mplayer, hostFaction, verboose); - } - - // -------------------------------------------- // - // PERMABLES - // -------------------------------------------- // - - public static List getPermables(Faction faction) - { - if (faction == null) throw new NullPointerException("faction"); - - List list = new MassiveList<>(); - - list.addAll(Arrays.asList(Rel.values())); - list.remove(Rel.FACTION); - - list.addAll(faction.getRanks().getAll(Comparator.comparingInt(Rank::getPriority))); - - return list; - } - - public interface MPermable extends Named, Identified - { - default boolean isRelation() - { - return this instanceof Rel; - } - - default boolean isRank() - { - return this instanceof Rank; - } - - default String getShortName() - { - return this.getName().substring(0, 3).toUpperCase(); - } - - String getDisplayName(Object senderObject); - } - - public static Set idsToMPermables(Collection ids) - { - return ids.stream() - .map(MPerm::idToMPermable) - .collect(Collectors.toSet()); - } - - public static MPermable idToMPermable(String id) - { - return idToMPermableOptional(id).orElseThrow(() -> new RuntimeException(id)); - } - - public static Optional idToMPermableOptional(String id) - { - MPlayer mplayer = MPlayerColl.get().get(id, false); - if (mplayer != null) return Optional.of(mplayer); - - // Workaround for registered senders - // Players ussually have a power, which makes sure they are in the coll - if (IdUtil.getRegistryIdToSender().containsKey(id)) return Optional.of(MPlayerColl.get().get(id, true)); - - Faction faction = Faction.get(id); - if (faction != null) return Optional.of(faction); - - for (Faction f : FactionColl.get().getAll()) - { - Rank rank = f.getRank(id); - if (rank != null) return Optional.of(rank); - } - - if (Rel.ALLY.name().equalsIgnoreCase(id)) return Optional.of(Rel.ALLY); - if (Rel.TRUCE.name().equalsIgnoreCase(id)) return Optional.of(Rel.TRUCE); - if (Rel.NEUTRAL.name().equalsIgnoreCase(id)) return Optional.of(Rel.NEUTRAL); - if (Rel.ENEMY.name().equalsIgnoreCase(id)) return Optional.of(Rel.ENEMY); - - return Optional.empty(); - } - -} diff --git a/src/com/massivecraft/factions/entity/MPermColl.java b/src/com/massivecraft/factions/entity/MPermColl.java deleted file mode 100644 index e0537408..00000000 --- a/src/com/massivecraft/factions/entity/MPermColl.java +++ /dev/null @@ -1,105 +0,0 @@ -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 -{ - // -------------------------------------------- // - // 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 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 getAll(boolean registered) - { - // Create - List ret = new ArrayList<>(); - - // Fill - for (MPerm mperm : this.getAll()) - { - if (mperm.isRegistered() != registered) continue; - ret.add(mperm); - } - - // Return - return ret; - } - -} diff --git a/src/com/massivecraft/factions/entity/MPlayer.java b/src/com/massivecraft/factions/entity/MPlayer.java deleted file mode 100644 index f01bf190..00000000 --- a/src/com/massivecraft/factions/entity/MPlayer.java +++ /dev/null @@ -1,901 +0,0 @@ -package com.massivecraft.factions.entity; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.FactionsIndex; -import com.massivecraft.factions.FactionsParticipator; -import com.massivecraft.factions.Perm; -import com.massivecraft.factions.Rel; -import com.massivecraft.factions.RelationParticipator; -import com.massivecraft.factions.event.EventFactionsChunkChangeType; -import com.massivecraft.factions.event.EventFactionsChunksChange; -import com.massivecraft.factions.event.EventFactionsDisband; -import com.massivecraft.factions.event.EventFactionsMembershipChange; -import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; -import com.massivecraft.factions.mixin.PowerMixin; -import com.massivecraft.factions.util.AsciiMap; -import com.massivecraft.factions.util.RelationUtil; -import com.massivecraft.massivecore.mixin.MixinSenderPs; -import com.massivecraft.massivecore.mixin.MixinTitle; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.ps.PSFormatHumanSpace; -import com.massivecraft.massivecore.store.SenderEntity; -import com.massivecraft.massivecore.util.IdUtil; -import com.massivecraft.massivecore.util.MUtil; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.lang.ref.WeakReference; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.Set; - -public class MPlayer extends SenderEntity implements FactionsParticipator, MPerm.MPermable -{ - // -------------------------------------------- // - // META - // -------------------------------------------- // - - public static final transient String NOTITLE = Txt.parse("no title set"); - - // -------------------------------------------- // - // META - // -------------------------------------------- // - - public static MPlayer get(Object oid) - { - return MPlayerColl.get().get(oid); - } - - // -------------------------------------------- // - // VERSION - // -------------------------------------------- // - - public int version = 2; - - // -------------------------------------------- // - // LOAD - // -------------------------------------------- // - - @Override - public MPlayer load(MPlayer that) - { - this.setLastActivityMillis(that.lastActivityMillis); - this.setFactionId(that.factionId); - this.rankId = that.rankId; - this.setTitle(that.title); - this.setPowerBoost(that.powerBoost); - this.setPower(that.power); - this.setMapAutoUpdating(that.mapAutoUpdating); - this.setOverriding(that.overriding); - this.setTerritoryInfoTitles(that.territoryInfoTitles); - - return this; - } - - // -------------------------------------------- // - // IS DEFAULT - // -------------------------------------------- // - - @Override - public boolean isDefault() - { - // Last activity millis is data we use for clearing out cleanable players. So it does not in itself make the player data worth keeping. - if (this.hasFaction()) return false; - // Role means nothing without a faction. - // Title means nothing without a faction. - if (this.hasPowerBoost()) return false; - if (this.getPowerRounded() != (int) Math.round(MConf.get().defaultPlayerPower)) return false; - // if (this.isMapAutoUpdating()) return false; // Just having an auto updating map is not in itself reason enough for database storage. - if (this.isOverriding()) return false; - if (this.isTerritoryInfoTitles() != MConf.get().territoryInfoTitlesDefault) return false; - - return true; - } - - // -------------------------------------------- // - // UPDATE FACTION INDEXES - // -------------------------------------------- // - - @Override - public void postAttach(String id) - { - FactionsIndex.get().update(this); - } - - @Override - public void postDetach(String id) - { - //System.out.println("Detaching: " + id + " : " + this.getFactionId()); - FactionsIndex.get().update(this); - } - - @Override - public void preClean() - { - if (this.getRank().isLeader()) - { - this.getFaction().promoteNewLeader(); - } - - this.leave(); - } - - // -------------------------------------------- // - // FIELDS: RAW - // -------------------------------------------- // - // In this section of the source code we place the field declarations only. - // Each field has it's own section further down since just the getter and setter logic takes up quite some place. - - // The last known time of explicit player activity, such as login or logout. - // This value is most importantly used for removing cleanable players. - // For that reason it defaults to the current time. - // Really cleanable players will be considered newly active when upgrading Factions from 2.6 --> 2.7. - // There is actually more than one reason we store this data ourselves and don't use the OfflinePlayer#getLastPlayed. - // 1. I don't trust that method. It's been very buggy or even completely broken in previous Bukkit versions. - // 2. The method depends on the player.dat files being present. - // Server owners clear those files at times, or move their database data around between different servers. - private long lastActivityMillis = System.currentTimeMillis(); - - // This is a foreign key. - // Each player belong to a faction. - // Null means default. - private String factionId = null; - - // What role does the player have in the faction? - // Null means default. - private String rankId = null; - - // What title does the player have in the faction? - // The title is just for fun. It's not connected to any game mechanic. - // The player title is similar to the faction description. - // - // Question: Can the title contain chat colors? - // Answer: Yes but in such case the policy is that they already must be parsed using Txt.parse. - // If the title contains raw markup, such as "" instead of "§f" it will not be parsed and "" will be displayed. - // - // Null means the player has no title. - private String title = null; - - // Player usually do not have a powerboost. It defaults to 0. - // The powerBoost is a custom increase/decrease to default and maximum power. - // Note that player powerBoost and faction powerBoost are very similar. - private Double powerBoost = null; - - // Each player has an individual power level. - // The power level for online players is occasionally updated by a recurring task and the power should stay the same for offline players. - // For that reason the value is to be considered correct when you pick it. Do not call the power update method. - // Null means default. - private Double power = null; - - // Has this player requested an auto-updating ascii art map? - // Null means false - private Boolean mapAutoUpdating = null; - - // Is this player overriding? - // Null means false - private Boolean overriding = null; - - // Does this player use titles for territory info? - // Null means default specified in MConf. - private Boolean territoryInfoTitles = null; - - // Is the player doing faction flying? - private Boolean flying = null; - - // The Faction this player is currently autoclaiming for. - // Null means the player isn't auto claiming. - // NOTE: This field will not be saved to the database ever. - private transient WeakReference autoClaimFaction = new WeakReference<>(null); - - public Faction getAutoClaimFaction() - { - if (this.isFactionOrphan()) return null; - Faction ret = this.autoClaimFaction.get(); - if (ret == null) return null; - if (ret.detached()) return null; - return ret; - } - public void setAutoClaimFaction(Faction autoClaimFaction) { this.autoClaimFaction = new WeakReference<>(autoClaimFaction); } - - // Does the player have /f seechunk activated? - // NOTE: This field will not be saved to the database ever. - private transient boolean seeingChunk = false; - public boolean isSeeingChunk() { return this.seeingChunk; } - public void setSeeingChunk(boolean seeingChunk) { this.seeingChunk = seeingChunk; } - - // -------------------------------------------- // - // CORE UTILITIES - // -------------------------------------------- // - - public void resetFactionData() - { - // The default neutral faction - this.setFactionId(null); - this.setRank(null); - this.setTitle(null); - this.setAutoClaimFaction(null); - } - - // -------------------------------------------- // - // FIELD: lastActivityMillis - // -------------------------------------------- // - - public long getLastActivityMillis() - { - return this.lastActivityMillis; - } - - public void setLastActivityMillis(long lastActivityMillis) - { - this.lastActivityMillis = convertSet(lastActivityMillis, this.lastActivityMillis, null); - } - - public void setLastActivityMillis() - { - this.setLastActivityMillis(System.currentTimeMillis()); - } - - @Override - public boolean shouldBeCleaned(long now) - { - return this.shouldBeCleaned(now, this.lastActivityMillis); - } - - // -------------------------------------------- // - // FIELD: factionId - // -------------------------------------------- // - - private Faction getFactionInternal() - { - String effectiveFactionId = this.convertGet(this.factionId, MConf.get().defaultPlayerFactionId); - return Faction.get(effectiveFactionId); - } - - public boolean isFactionOrphan() - { - return this.getFactionInternal() == null; - } - - @Deprecated - public String getFactionId() - { - return this.getFaction().getId(); - } - - // This method never returns null - public Faction getFaction() - { - Faction ret; - - ret = this.getFactionInternal(); - - // Adopt orphans - if (ret == null) - { - ret = FactionColl.get().getNone(); - } - - return ret; - } - - public boolean hasFaction() - { - return !this.getFaction().isNone(); - } - - // This setter is so long because it search for default/null case and takes - // care of updating the faction member index - public void setFactionId(String factionId) - { - // Before - String beforeId = this.factionId; - - // After - String afterId = factionId; - - // NoChange - if (MUtil.equals(beforeId, afterId)) return; - - // Apply - this.factionId = afterId; - - // Index - FactionsIndex.get().update(this); - - // Mark as changed - this.changed(); - } - - public void setFaction(Faction faction) - { - this.setFactionId(faction.getId()); - } - - // -------------------------------------------- // - // FIELD: role - // -------------------------------------------- // - - public Rank getRank() - { - if (this.isFactionOrphan()) return FactionColl.get().getNone().getLowestRank(); - - if (this.rankId == null) return this.getFaction().getLowestRank(); - return this.getFaction().getRank(this.rankId); - } - - public void setRank(Rank rank) - { - // Clean input - String rankId = rank == null ? null : rank.getId(); - - // Detect Nochange - if (MUtil.equals(this.rankId, rankId)) return; - - // Apply - this.rankId = rankId; - - // Mark as changed - this.changed(); - } - - // -------------------------------------------- // - // FIELD: title - // -------------------------------------------- // - // TODO: Improve upon the has and get stuff. - // TODO: Has should depend on get. Visualisation should be done elsewhere. - - public boolean hasTitle() - { - return !this.isFactionOrphan() && this.title != null; - } - - public String getTitle() - { - if (this.isFactionOrphan()) return NOTITLE; - - if (this.hasTitle()) return this.title; - - return NOTITLE; - } - - public void setTitle(String title) - { - // Clean input - String target = Faction.clean(title); - - // Detect Nochange - if (MUtil.equals(this.title, target)) return; - - // Apply - this.title = target; - - // Mark as changed - this.changed(); - } - - // -------------------------------------------- // - // FIELD: powerBoost - // -------------------------------------------- // - - @Override - public double getPowerBoost() - { - Double ret = this.powerBoost; - if (ret == null) ret = 0D; - return ret; - } - - @Override - public void setPowerBoost(Double powerBoost) - { - // Clean input - Double target = powerBoost; - if (target == null || target == 0) target = null; - - // Detect Nochange - if (MUtil.equals(this.powerBoost, target)) return; - - // Apply - this.powerBoost = target; - - // Mark as changed - this.changed(); - } - - public boolean hasPowerBoost() - { - return this.getPowerBoost() != 0D; - } - - // -------------------------------------------- // - // FIELD: power - // -------------------------------------------- // - - // MIXIN: RAW - - public double getPowerMaxUniversal() - { - return PowerMixin.get().getMaxUniversal(this); - } - - public double getPowerMax() - { - return PowerMixin.get().getMax(this); - } - - public double getPowerMin() - { - return PowerMixin.get().getMin(this); - } - - public double getPowerPerHour() - { - return PowerMixin.get().getPerHour(this); - } - - public double getPowerPerDeath() - { - return PowerMixin.get().getPerDeath(this); - } - - // MIXIN: FINER - - public double getLimitedPower(double power) - { - power = Math.max(power, this.getPowerMin()); - power = Math.min(power, this.getPowerMax()); - - return power; - } - - public int getPowerMaxRounded() - { - return (int) Math.round(this.getPowerMax()); - } - - public int getPowerMinRounded() - { - return (int) Math.round(this.getPowerMin()); - } - - public int getPowerMaxUniversalRounded() - { - return (int) Math.round(this.getPowerMaxUniversal()); - } - - // RAW - - @Deprecated - public double getDefaultPower() - { - return MConf.get().defaultPlayerPower; - } - - public double getPower() - { - Double ret = this.power; - if (ret == null) ret = MConf.get().defaultPlayerPower; - ret = this.getLimitedPower(ret); - return ret; - } - - public void setPower(Double power) - { - // Clean input - Double target = power; - - // Detect Nochange - if (MUtil.equals(this.power, target)) return; - - // Apply - this.power = target; - - // Mark as changed - this.changed(); - } - - // FINER - - public int getPowerRounded() - { - return (int) Math.round(this.getPower()); - } - - // -------------------------------------------- // - // FIELD: mapAutoUpdating - // -------------------------------------------- // - - public boolean isMapAutoUpdating() - { - if (this.mapAutoUpdating == null) return false; - if (this.mapAutoUpdating == false) return false; - return true; - } - - public void setMapAutoUpdating(Boolean mapAutoUpdating) - { - // Clean input - Boolean target = mapAutoUpdating; - if (MUtil.equals(target, false)) target = null; - - // Detect Nochange - if (MUtil.equals(this.mapAutoUpdating, target)) return; - - // Apply - this.mapAutoUpdating = target; - - // Mark as changed - this.changed(); - } - - // -------------------------------------------- // - // FIELD: overriding - // -------------------------------------------- // - - public boolean isOverriding() - { - if (this.overriding == null) return false; - if (this.overriding == false) return false; - - if (!this.hasPermission(Perm.OVERRIDE, true)) - { - this.setOverriding(false); - return false; - } - - return true; - } - - public void setOverriding(Boolean overriding) - { - // Clean input - Boolean target = overriding; - if (MUtil.equals(target, false)) target = null; - - // Detect Nochange - if (MUtil.equals(this.overriding, target)) return; - - // Apply - this.overriding = target; - - // Mark as changed - this.changed(); - } - - // -------------------------------------------- // - // FIELD: territoryInfoTitles - // -------------------------------------------- // - - public boolean isTerritoryInfoTitles() - { - if (!MixinTitle.get().isAvailable()) return false; - if (this.territoryInfoTitles == null) return MConf.get().territoryInfoTitlesDefault; - return this.territoryInfoTitles; - } - - public void setTerritoryInfoTitles(Boolean territoryInfoTitles) - { - // Clean input - Boolean target = territoryInfoTitles; - if (MUtil.equals(target, MConf.get().territoryInfoTitlesDefault)) target = null; - - // Detect Nochange - if (MUtil.equals(this.territoryInfoTitles, target)) return; - - // Apply - this.territoryInfoTitles = target; - - // Mark as changed - this.changed(); - } - - // -------------------------------------------- // - // FIELD: fly - // -------------------------------------------- // - - public boolean isFlying() - { - return this.convertGet(this.flying, false, Perm.FLY); - } - - public void setFlying(Boolean flying) - { - this.flying = this.convertSet(flying, this.flying, false); - } - - // -------------------------------------------- // - // TITLE, NAME, FACTION NAME AND CHAT - // -------------------------------------------- // - - public String getFactionName() - { - Faction faction = this.getFaction(); - if (faction.isNone()) return ""; - return faction.getName(); - } - - // Base concatenations: - - public String getNameAndSomething(String color, String something) - { - String ret = ""; - ret += color; - ret += this.getRank().getPrefix(); - if (something != null && something.length() > 0) - { - ret += something; - ret += " "; - ret += color; - } - ret += this.getName(); - return ret; - } - - public String getNameAndFactionName() - { - return this.getNameAndSomething("", this.getFactionName()); - } - - public String getNameAndTitle(String color) - { - if (this.hasTitle()) - { - return this.getNameAndSomething(color, this.getTitle()); - } - else - { - return this.getNameAndSomething(color, null); - } - } - - // Colored concatenations: - // These are used in information messages - - public String getNameAndTitle(Faction faction) - { - return this.getNameAndTitle(this.getColorTo(faction).toString()); - } - - public String getNameAndTitle(MPlayer mplayer) - { - return this.getNameAndTitle(this.getColorTo(mplayer).toString()); - } - - // -------------------------------------------- // - // RELATION AND RELATION COLORS - // -------------------------------------------- // - - @Override - public String describeTo(RelationParticipator observer, boolean ucfirst) - { - return RelationUtil.describeThatToMe(this, observer, ucfirst); - } - - @Override - public String describeTo(RelationParticipator observer) - { - return RelationUtil.describeThatToMe(this, observer); - } - - @Override - public Rel getRelationTo(RelationParticipator observer) - { - return RelationUtil.getRelationOfThatToMe(this, observer); - } - - @Override - public Rel getRelationTo(RelationParticipator observer, boolean ignorePeaceful) - { - return RelationUtil.getRelationOfThatToMe(this, observer, ignorePeaceful); - } - - @Override - public ChatColor getColorTo(RelationParticipator observer) - { - return RelationUtil.getColorOfThatToMe(this, observer); - } - - // -------------------------------------------- // - // HEALTH - // -------------------------------------------- // - - public void heal(int amnt) - { - Player player = this.getPlayer(); - if (player == null) - { - return; - } - player.setHealth(player.getHealth() + amnt); - } - - // -------------------------------------------- // - // TERRITORY - // -------------------------------------------- // - - public boolean isInOwnTerritory() - { - PS ps = MixinSenderPs.get().getSenderPs(this.getId()); - if (ps == null) return false; - return BoardColl.get().getFactionAt(ps) == this.getFaction(); - } - - public boolean isInEnemyTerritory() - { - PS ps = MixinSenderPs.get().getSenderPs(this.getId()); - if (ps == null) return false; - return BoardColl.get().getFactionAt(ps).getRelationTo(this) == Rel.ENEMY; - } - - // -------------------------------------------- // - // ACTIONS - // -------------------------------------------- // - - public void leave() - { - Faction myFaction = this.getFaction(); - - boolean permanent = myFaction.getFlag(MFlag.getFlagPermanent()); - - if (myFaction.getMPlayers().size() > 1) - { - if (!permanent && this.getRank().isLeader()) - { - msg("You must give the leader role to someone else first."); - return; - } - - if (!MConf.get().canLeaveWithNegativePower && this.getPower() < 0) - { - msg("You cannot leave until your power is positive."); - return; - } - } - - // Event - EventFactionsMembershipChange membershipChangeEvent = new EventFactionsMembershipChange(this.getSender(), this, myFaction, MembershipChangeReason.LEAVE); - membershipChangeEvent.run(); - if (membershipChangeEvent.isCancelled()) return; - - if (myFaction.isNormal()) - { - for (MPlayer mplayer : myFaction.getMPlayersWhereOnline(true)) - { - mplayer.msg("%s left %s.", this.describeTo(mplayer, true), myFaction.describeTo(mplayer)); - } - - if (MConf.get().logFactionLeave) - { - Factions.get().log(this.getName() + " left the faction: " + myFaction.getName()); - } - } - - this.resetFactionData(); - - if (myFaction.isNormal() && !permanent && myFaction.getMPlayers().isEmpty()) - { - EventFactionsDisband eventFactionsDisband = new EventFactionsDisband(this.getSender(), myFaction); - eventFactionsDisband.run(); - if (!eventFactionsDisband.isCancelled()) - { - // Remove this faction - this.msg("%s was disbanded since you were the last player.", myFaction.describeTo(this, true)); - if (MConf.get().logFactionDisband) - { - Factions.get().log("The faction " + myFaction.getName() + " (" + myFaction.getId() + ") was disbanded due to the last player (" + this.getName() + ") leaving."); - } - myFaction.detach(); - } - } - } - - // NEW - public boolean tryClaim(Faction newFaction, Collection pss) - { - return this.tryClaim(newFaction, pss, null, null); - } - - public boolean tryClaim(Faction newFaction, Collection pss, String formatOne, String formatMany) - { - // Args - if (formatOne == null) formatOne = "%s %s %d chunk %s."; - if (formatMany == null) formatMany = "%s %s %d chunks near %s."; - - if (newFaction == null) throw new NullPointerException("newFaction"); - - if (pss == null) throw new NullPointerException("pss"); - final Set chunks = PS.getDistinctChunks(pss); - - // NoChange - // We clean the chunks further by removing what does not change. - // This is also very suggested cleaning of EventFactionsChunksChange input. - Iterator iter = chunks.iterator(); - chunks.removeIf(chunk -> BoardColl.get().getFactionAt(chunk) == newFaction); - if (chunks.isEmpty()) - { - msg("%s already owns this land.", newFaction.describeTo(this, true)); - return true; - } - - // Event - // NOTE: We listen to this event ourselves at LOW. - // NOTE: That is where we apply the standard checks. - CommandSender sender = this.getSender(); - if (sender == null) - { - msg("ERROR: Your \"CommandSender Link\" has been severed."); - msg("It's likely that you are using Cauldron."); - msg("We do currently not support Cauldron."); - msg("We would love to but lack time to develop support ourselves."); - msg("Do you know how to code? Please send us a pull request <3, sorry."); - return false; - } - EventFactionsChunksChange event = new EventFactionsChunksChange(sender, chunks, newFaction); - event.run(); - if (event.isCancelled()) return false; - - // Apply - for (PS chunk : chunks) - { - BoardColl.get().setFactionAt(chunk, newFaction); - } - - // Inform - for (Entry> entry : event.getOldFactionChunks().entrySet()) - { - final Faction oldFaction = entry.getKey(); - final Set oldChunks = entry.getValue(); - final PS oldChunk = oldChunks.iterator().next(); - final Set informees = getClaimInformees(this, oldFaction, newFaction); - final EventFactionsChunkChangeType type = EventFactionsChunkChangeType.get(oldFaction, newFaction, this.getFaction()); - - String chunkString = oldChunk.toString(PSFormatHumanSpace.get()); - String typeString = type.past; - - if (!AsciiMap.showChunkCoords(oldChunk)) - { - chunkString = ""; - formatMany = formatMany.replace(" near ", ""); - } - - for (MPlayer informee : informees) - { - informee.msg((oldChunks.size() == 1 ? formatOne : formatMany), this.describeTo(informee, true), typeString, oldChunks.size(), chunkString); - informee.msg(" %s --> %s", oldFaction.describeTo(informee, true), newFaction.describeTo(informee, true)); - } - } - - // Success - return true; - } - - // -------------------------------------------- // - // UTIL - // -------------------------------------------- // - - public static Set getClaimInformees(MPlayer msender, Faction... factions) - { - Set ret = new HashSet<>(); - - if (msender != null) ret.add(msender); - - for (Faction faction : factions) - { - if (faction == null) continue; - if (faction.isNone()) continue; - ret.addAll(faction.getMPlayers()); - } - - if (MConf.get().logLandClaims) - { - ret.add(MPlayer.get(IdUtil.getConsole())); - } - - return ret; - } - -} diff --git a/src/com/massivecraft/factions/entity/MPlayerColl.java b/src/com/massivecraft/factions/entity/MPlayerColl.java deleted file mode 100644 index 83926b0b..00000000 --- a/src/com/massivecraft/factions/entity/MPlayerColl.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.massivecraft.factions.entity; - -import com.massivecraft.massivecore.store.SenderColl; - -public class MPlayerColl extends SenderColl -{ - // -------------------------------------------- // - // 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; - } - -} diff --git a/src/com/massivecraft/factions/entity/Rank.java b/src/com/massivecraft/factions/entity/Rank.java deleted file mode 100644 index 68a589b4..00000000 --- a/src/com/massivecraft/factions/entity/Rank.java +++ /dev/null @@ -1,176 +0,0 @@ -package com.massivecraft.factions.entity; - -import com.massivecraft.massivecore.store.EntityInternal; -import com.massivecraft.massivecore.store.EntityInternalMap; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.ChatColor; - -import java.util.Map.Entry; -import java.util.Set; - -public class Rank extends EntityInternal implements MPerm.MPermable -{ - // -------------------------------------------- // - // OVERRIDE: ENTITY - // -------------------------------------------- // - - @Override - public Rank load(Rank that) - { - this.name = that.name; - - return this; - } - - @Override - public void preDetach(String id) - { - for (Faction f : FactionColl.get().getAll()) - { - for (Entry> entry : f.getPerms().entrySet()) - { - Set value = entry.getValue(); - if (value == null) throw new NullPointerException(entry.getKey()); - value.remove(id); - } - } - } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private String name; - public String getName() { return this.name; } - public void setName(String name) { this.name = name; this.changed(); } - - private int priority; - public int getPriority() { return this.priority; } - public void setPriority(int priority) { this.priority = priority; this.changed(); } - - private String prefix; - public String getPrefix() { return this.prefix; } - public void setPrefix(String prefix) { this.prefix = prefix; this.changed(); } - - public Faction getFaction() - { - EntityInternalMap internalMap = (EntityInternalMap) this.getContainer(); - return (Faction) internalMap.getEntity(); - } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - // For GSON - private Rank() - { - this(null,0, ""); - } - - public Rank(String name, int priority, String prefix) - { - this.name = name; - this.priority = priority; - this.prefix = prefix; - } - - public Rank copy() - { - return new Rank(this.name, this.priority, this.prefix); - } - - // -------------------------------------------- // - // VISUAL - // -------------------------------------------- // - - @Override - public String getDisplayName(Object senderObject) - { - String ret = this.getVisual(); - ret += Txt.parse(" of ") + this.getFaction().getDisplayName(senderObject); - return ret; - } - - public String getVisual() - { - String ret = ""; - ret += ChatColor.GREEN.toString(); - ret += this.getPrefix(); - ret += this.getName(); - ret += " (" + this.getPriority() + ")"; - return ret; - } - - // -------------------------------------------- // - // RANK PRIORITY - // -------------------------------------------- // - - public boolean isLessThan(Rank otherRank) - { - if (this.getContainer() != otherRank.getContainer()) throw new IllegalArgumentException(this.getId() + " : " + otherRank.getId()); - - return this.getPriority() < otherRank.getPriority(); - } - - public boolean isMoreThan(Rank otherRank) - { - if (this.getContainer() != otherRank.getContainer()) throw new IllegalArgumentException(this.getId() + " : " + otherRank.getId()); - - return this.getPriority() > otherRank.getPriority(); - } - - public boolean isAtLeast(Rank otherRank) - { - if (this.getContainer() != otherRank.getContainer()) throw new IllegalArgumentException(this.getId() + " : " + otherRank.getId()); - - return this.getPriority() >= otherRank.getPriority(); - } - - public boolean isAtMost(Rank otherRank) - { - if (this.getContainer() != otherRank.getContainer()) throw new IllegalArgumentException(this.getId() + " : " + otherRank.getId()); - - return this.getPriority() <= otherRank.getPriority(); - } - - public boolean isLeader() - { - for (Rank otherRank : this.getContainer().getAll()) - { - if (otherRank == this) continue; - - if (otherRank.isMoreThan(this)) return false; - } - return true; - } - - public Rank getRankAbove() - { - Rank ret = null; - for (Rank otherRank : this.getContainer().getAll()) - { - if (otherRank == this) continue; - if (otherRank.isLessThan(this)) continue; - if (ret != null && ret.isLessThan(otherRank)) continue; - - ret = otherRank; - } - return ret; - } - - public Rank getRankBelow() - { - Rank ret = null; - for (Rank otherRank : this.getContainer().getAll()) - { - if (otherRank == this) continue; - if (otherRank.isMoreThan(this)) continue; - if (ret != null && ret.isMoreThan(otherRank)) continue; - - ret = otherRank; - } - return ret; - } - -} diff --git a/src/com/massivecraft/factions/entity/Vote.java b/src/com/massivecraft/factions/entity/Vote.java deleted file mode 100644 index caa54667..00000000 --- a/src/com/massivecraft/factions/entity/Vote.java +++ /dev/null @@ -1,126 +0,0 @@ -package com.massivecraft.factions.entity; - -import com.massivecraft.massivecore.Named; -import com.massivecraft.massivecore.collections.MassiveMap; -import com.massivecraft.massivecore.store.EntityInternal; -import com.massivecraft.massivecore.store.EntityInternalMap; - -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -public class Vote extends EntityInternal implements Named -{ - // -------------------------------------------- // - // OVERRIDE: ENTITY - // -------------------------------------------- // - - @Override - public Vote load(Vote that) - { - this.creatorId = that.creatorId; - this.creationMillis = that.creationMillis; - this.options = that.options; - this.id2Vote = that.id2Vote; - - return this; - } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private String creatorId; - public String getCreatorId() { return this.creatorId; } - - private long creationMillis; - public long getCreationMillis() { return this.creationMillis; } - - private String name; - @Override public String getName() { return this.name; } - - private List options; - public List getOptions() { return this.options; } - - private Map id2Vote; - public Map getId2Vote() { return id2Vote; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - // For GSON - private Vote() - { - this(null, 0, null, null); - } - - public Vote(String creatorId, String name, List options) - { - this(creatorId, System.currentTimeMillis(), name, options); - } - - public Vote(String creatorId, long creationMillis, String name, List options) - { - this.creatorId = creatorId; - this.creationMillis = creationMillis; - this.name = name; - this.options = options; - this.id2Vote = new MassiveMap<>(); - } - - // -------------------------------------------- // - // OTHER - // -------------------------------------------- // - - public void setVote(MPlayer mplayer, String choice) - { - if (mplayer == null) throw new NullPointerException("mplayer"); - if (choice == null) throw new NullPointerException("choice"); - - if (!this.getOptions().contains(choice)) throw new IllegalArgumentException(choice + " is not in " + this.getOptions()); - - id2Vote.put(mplayer.getId(), choice); - this.changed(); - } - - public String getVote(MPlayer mplayer) - { - if (mplayer == null) throw new NullPointerException("mplayer"); - - return this.getId2Vote().get(mplayer.getId()); - } - - public Faction getFaction() - { - EntityInternalMap internalMap = (EntityInternalMap) this.getContainer(); - return (Faction) internalMap.getEntity(); - } - - public void clean() - { - Faction faction = this.getFaction(); - for (Iterator> it = this.id2Vote.entrySet().iterator(); it.hasNext();) - { - Entry entry = it.next(); - String id = entry.getKey(); - - // MPlayer must be a member - if ( ! faction.getMPlayerIds().contains(id)) - { - it.remove(); - break; - } - - // And they must have the perm - MPlayer mplayer = MPlayer.get(id); - if (! MPerm.getPermVote().has(mplayer, faction, false)) - { - it.remove(); - break; - } - } - } - -} diff --git a/src/com/massivecraft/factions/entity/Warp.java b/src/com/massivecraft/factions/entity/Warp.java deleted file mode 100644 index 3db27f90..00000000 --- a/src/com/massivecraft/factions/entity/Warp.java +++ /dev/null @@ -1,93 +0,0 @@ -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(); - return (Faction) internalMap.getEntity(); - } - - // -------------------------------------------- // - // 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; - Faction fac = this.getFaction(); - this.detach(); - fac.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/MigratorFaction001Invitations.java b/src/com/massivecraft/factions/entity/migrator/MigratorFaction001Invitations.java deleted file mode 100644 index 27af7f40..00000000 --- a/src/com/massivecraft/factions/entity/migrator/MigratorFaction001Invitations.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.massivecraft.factions.entity.migrator; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.massivecore.store.migrator.MigratorFieldConvert; -import com.massivecraft.massivecore.store.migrator.MigratorFieldRename; -import com.massivecraft.massivecore.store.migrator.MigratorRoot; - -public class MigratorFaction001Invitations extends MigratorRoot -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static com.massivecraft.factions.entity.migrator.MigratorFaction001Invitations i = new com.massivecraft.factions.entity.migrator.MigratorFaction001Invitations(); - public static com.massivecraft.factions.entity.migrator.MigratorFaction001Invitations get() { return i; } - private MigratorFaction001Invitations() - { - super(Faction.class); - this.addInnerMigrator(MigratorFieldRename.get("invitedPlayerIds", "invitations")); - this.addInnerMigrator(new MigratorFaction001InvitationsField()); - } - - public class MigratorFaction001InvitationsField extends MigratorFieldConvert - { - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - private MigratorFaction001InvitationsField() - { - super("invitations"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - public Object migrateInner(JsonElement idList) - { - JsonObject ret = new JsonObject(); - //EntityInternalMap ret = new EntityInternalMap<>(null, Invitation.class); - - // If non-null - if (!idList.isJsonNull()) - { - // ... and proper type ... - if (!idList.isJsonArray()) throw new IllegalArgumentException(idList.toString()); - - // ... fill! - for (JsonElement playerId : idList.getAsJsonArray()) - { - String id = playerId.getAsString(); - - // Create invitation - JsonObject invitation = new JsonObject(); - - // Attach - ret.add(id, invitation); - } - } - - return ret; - } - - } - -} diff --git a/src/com/massivecraft/factions/entity/migrator/MigratorFaction002Ranks.java b/src/com/massivecraft/factions/entity/migrator/MigratorFaction002Ranks.java deleted file mode 100644 index e6876410..00000000 --- a/src/com/massivecraft/factions/entity/migrator/MigratorFaction002Ranks.java +++ /dev/null @@ -1,113 +0,0 @@ -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.MConf; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.Rank; -import com.massivecraft.massivecore.MassiveCore; -import com.massivecraft.massivecore.collections.MassiveMap; -import com.massivecraft.massivecore.collections.MassiveSet; -import com.massivecraft.massivecore.store.MStore; -import com.massivecraft.massivecore.store.migrator.MigratorRoot; - -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -public class MigratorFaction002Ranks extends MigratorRoot -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static MigratorFaction002Ranks i = new MigratorFaction002Ranks(); - public static MigratorFaction002Ranks get() { return i; } - private MigratorFaction002Ranks() - { - super(Faction.class); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void migrateInner(JsonObject entity) - { - String idLeader = MStore.createId(); - String idOfficer = MStore.createId(); - String idMember = MStore.createId(); - String idRecruit = MStore.createId(); - - Rank leader = new Rank("Leader", 400, "**"); - Rank officer = new Rank("Officer", 300, "*"); - Rank member = new Rank("Member", 200, "+"); - Rank recruit = new Rank("Recruit", 100, "-"); - - Map map = new MassiveMap<>(); - map.put(idLeader, leader); - map.put(idOfficer, officer); - map.put(idMember, member); - map.put(idRecruit, recruit); - - JsonElement jsonMap = MassiveCore.gson.toJsonTree(map, (new TypeToken>(){}).getType()); - entity.add("ranks", jsonMap); - - JsonElement priorPerms = entity.get("perms"); - Map> newPerms = getPerms(priorPerms, idLeader, idOfficer, idMember, idRecruit); - - JsonElement jsonPerms = MassiveCore.gson.toJsonTree(newPerms, (new TypeToken>>(){}).getType()); - entity.add("perms", jsonPerms); - } - - private Map> getPerms(JsonElement priorPerms, String leaderId, String officerId, String memberId, String recruitId) - { - // We start with default values ... - Map> ret = new MassiveMap<>(); - for (MPerm mperm : MPerm.getAll()) - { - // This should work since MConf and MPerm is loaded /before/ Factions - //Set value = new MassiveSet<>(mperm.getStandard()); - Set value = new MassiveSet<>(MConf.get().perm2default.get(mperm.getId())); - - if (value.remove("LEADER")) value.add(leaderId); - if (value.remove("OFFICER")) value.add(officerId); - if (value.remove("MEMBER")) value.add(memberId); - if (value.remove("RECRUIT")) value.add(recruitId); - ret.put(mperm.getId(), value); - } - - if (priorPerms != null) - { - Map> permMap = MassiveCore.gson.fromJson(priorPerms, (new TypeToken>>(){}).getType()); - // ... and if anything is explicitly set we use that info ... - Iterator>> iter = permMap.entrySet().iterator(); - while (iter.hasNext()) - { - // ... for each entry ... - Map.Entry> entry = iter.next(); - - // ... extract id and remove null values ... - String id = entry.getKey(); - if (id == null) - { - iter.remove(); - continue; - } - - Set value = entry.getValue(); - if (value.remove("LEADER")) value.add(leaderId); - if (value.remove("OFFICER")) value.add(officerId); - if (value.remove("MEMBER")) value.add(memberId); - if (value.remove("RECRUIT")) value.add(recruitId); - ret.put(id, value); - } - } - - return ret; - } - -} diff --git a/src/com/massivecraft/factions/entity/migrator/MigratorFaction003Warps.java b/src/com/massivecraft/factions/entity/migrator/MigratorFaction003Warps.java deleted file mode 100644 index d2417149..00000000 --- a/src/com/massivecraft/factions/entity/migrator/MigratorFaction003Warps.java +++ /dev/null @@ -1,51 +0,0 @@ -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/MigratorFaction004WarpsPerms.java b/src/com/massivecraft/factions/entity/migrator/MigratorFaction004WarpsPerms.java deleted file mode 100644 index 22c28b98..00000000 --- a/src/com/massivecraft/factions/entity/migrator/MigratorFaction004WarpsPerms.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.massivecraft.factions.entity.migrator; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.massivecore.store.migrator.MigratorRoot; - -public class MigratorFaction004WarpsPerms extends MigratorRoot -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static MigratorFaction004WarpsPerms i = new MigratorFaction004WarpsPerms(); - public static MigratorFaction004WarpsPerms get() { return i; } - private MigratorFaction004WarpsPerms() - { - super(Faction.class); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void migrateInner(JsonObject entity) - { - JsonElement perms = entity.get("perms"); - if (perms == null || perms.isJsonNull() || !perms.isJsonObject()) return; - - JsonObject permsO = perms.getAsJsonObject(); - - JsonElement home = permsO.remove("home"); - if (home != null) permsO.add("warp", home); - - JsonElement sethome = permsO.remove("sethome"); - if (home != null) permsO.add("setwarp", home); - } - -} diff --git a/src/com/massivecraft/factions/entity/migrator/MigratorMConf001EnumerationUtil.java b/src/com/massivecraft/factions/entity/migrator/MigratorMConf001EnumerationUtil.java deleted file mode 100644 index 0a007de0..00000000 --- a/src/com/massivecraft/factions/entity/migrator/MigratorMConf001EnumerationUtil.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.massivecraft.factions.entity.migrator; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.util.EnumerationUtil; -import com.massivecraft.massivecore.store.migrator.MigratorRoot; - -import java.util.Collection; -import java.util.Iterator; - -public class MigratorMConf001EnumerationUtil extends MigratorRoot -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static MigratorMConf001EnumerationUtil i = new MigratorMConf001EnumerationUtil(); - public static MigratorMConf001EnumerationUtil get() { return i; } - private MigratorMConf001EnumerationUtil() - { - super(MConf.class); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void migrateInner(JsonObject entity) - { - removeFromStringsField(entity, "materialsEditOnInteract", EnumerationUtil.MATERIALS_EDIT_ON_INTERACT.getStringSet()); - removeFromStringsField(entity, "materialsEditTools", EnumerationUtil.MATERIALS_EDIT_TOOL.getStringSet()); - removeFromStringsField(entity, "materialsDoor", EnumerationUtil.MATERIALS_DOOR.getStringSet()); - removeFromStringsField(entity, "materialsContainer", EnumerationUtil.MATERIALS_CONTAINER.getStringSet()); - removeFromStringsField(entity, "entityTypesEditOnInteract", EnumerationUtil.ENTITY_TYPES_EDIT_ON_INTERACT.getStringSet()); - removeFromStringsField(entity, "entityTypesEditOnDamage", EnumerationUtil.ENTITY_TYPES_EDIT_ON_DAMAGE.getStringSet()); - removeFromStringsField(entity, "entityTypesContainer", EnumerationUtil.ENTITY_TYPES_CONTAINER.getStringSet()); - removeFromStringsField(entity, "entityTypesMonsters", EnumerationUtil.ENTITY_TYPES_MONSTER.getStringSet()); - removeFromStringsField(entity, "entityTypesAnimals", EnumerationUtil.ENTITY_TYPES_ANIMAL.getStringSet()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - private void removeFromStringsField(JsonObject entity, String fieldName, Collection removals) - { - JsonElement stringsElement = entity.get(fieldName); - if (!(stringsElement instanceof JsonArray)) return; - JsonArray strings = (JsonArray)stringsElement; - - for (Iterator iterator = strings.iterator(); iterator.hasNext();) - { - JsonElement stringElement = iterator.next(); - if (!(stringElement instanceof JsonPrimitive)) continue; - JsonPrimitive string = (JsonPrimitive)stringElement; - - if (!removals.contains(string.getAsString())) continue; - - iterator.remove(); - } - } - -} diff --git a/src/com/massivecraft/factions/entity/migrator/MigratorMConf002CleanInactivity.java b/src/com/massivecraft/factions/entity/migrator/MigratorMConf002CleanInactivity.java deleted file mode 100644 index 4abae91d..00000000 --- a/src/com/massivecraft/factions/entity/migrator/MigratorMConf002CleanInactivity.java +++ /dev/null @@ -1,23 +0,0 @@ -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 MigratorMConf002CleanInactivity extends MigratorRoot -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static MigratorMConf002CleanInactivity i = new MigratorMConf002CleanInactivity(); - public static MigratorMConf002CleanInactivity get() { return i; } - private MigratorMConf002CleanInactivity() - { - super(MConf.class); - this.addInnerMigrator(MigratorFieldRename.get("removePlayerMillisDefault", "playercleanToleranceMillis")); - this.addInnerMigrator(MigratorFieldRename.get("removePlayerMillisPlayerAgeToBonus", "playercleanToleranceMillisPlayerAgeToBonus")); - this.addInnerMigrator(MigratorFieldRename.get("removePlayerMillisFactionAgeToBonus", "playercleanToleranceMillisFactionAgeToBonus")); - } - -} diff --git a/src/com/massivecraft/factions/entity/migrator/MigratorMConf003CleanInactivity.java b/src/com/massivecraft/factions/entity/migrator/MigratorMConf003CleanInactivity.java deleted file mode 100644 index a0b8a740..00000000 --- a/src/com/massivecraft/factions/entity/migrator/MigratorMConf003CleanInactivity.java +++ /dev/null @@ -1,23 +0,0 @@ -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 MigratorMConf003CleanInactivity extends MigratorRoot -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static MigratorMConf003CleanInactivity i = new MigratorMConf003CleanInactivity(); - public static MigratorMConf003CleanInactivity get() { return i; } - private MigratorMConf003CleanInactivity() - { - super(MConf.class); - this.addInnerMigrator(MigratorFieldRename.get("playercleanToleranceMillis", "cleanInactivityToleranceMillis")); - this.addInnerMigrator(MigratorFieldRename.get("playercleanToleranceMillisPlayerAgeToBonus", "cleanInactivityToleranceMillisPlayerAgeToBonus")); - this.addInnerMigrator(MigratorFieldRename.get("playercleanToleranceMillisFactionAgeToBonus", "cleanInactivityToleranceMillisFactionAgeToBonus")); - } - -} diff --git a/src/com/massivecraft/factions/entity/migrator/MigratorMConf004Rank.java b/src/com/massivecraft/factions/entity/migrator/MigratorMConf004Rank.java deleted file mode 100644 index 1625d7d3..00000000 --- a/src/com/massivecraft/factions/entity/migrator/MigratorMConf004Rank.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.massivecraft.factions.entity.migrator; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.massivecore.store.migrator.MigratorRoot; - -import java.util.Iterator; - -public class MigratorMConf004Rank extends MigratorRoot -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static MigratorMConf004Rank i = new MigratorMConf004Rank(); - public static MigratorMConf004Rank get() { return i; } - private MigratorMConf004Rank() { super(MConf.class); } - - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void migrateInner(JsonObject entity) - { - migrateRename(entity, "denyCommandsTerritoryRelation"); - migrateRename(entity, "denyCommandsDistanceRelation"); - migrateRename(entity, "denyCommandsDistanceBypassIn"); - - entity.remove("defaultPlayerRole"); - entity.remove("herochatFactionName"); - entity.remove("herochatFactionNick"); - entity.remove("herochatFactionFormat"); - entity.remove("herochatFactionColor"); - entity.remove("herochatFactionDistance"); - entity.remove("herochatFactionIsShortcutAllowed"); - entity.remove("herochatFactionCrossWorld"); - entity.remove("herochatFactionMuted"); - entity.remove("herochatFactionWorlds"); - entity.remove("herochatAlliesName"); - entity.remove("herochatAlliesNick"); - entity.remove("herochatAlliesFormat"); - entity.remove("herochatAlliesColor"); - entity.remove("herochatAlliesDistance"); - entity.remove("herochatAlliesIsShortcutAllowed"); - entity.remove("herochatAlliesCrossWorld"); - entity.remove("herochatAlliesMuted"); - entity.remove("herochatAlliesWorlds"); - } - - private void migrateRename(JsonObject entity, String name) - { - JsonElement element = entity.get(name); - if (element.isJsonObject()) - { - JsonObject map = element.getAsJsonObject(); - if (map.has("MEMBER")) - { - JsonElement e = map.remove("MEMBER"); - map.add("FACTION", e); - } - } - if (element.isJsonArray()) - { - JsonArray array = element.getAsJsonArray(); - boolean success = false; - for (Iterator it = array.iterator(); it.hasNext(); ) - { - JsonElement e = it.next(); - if (!e.getAsString().equals("MEMBER")) continue; - it.remove(); - success = true; - } - if (success) - { - array.add("FACTION"); - } - } - } - -} diff --git a/src/com/massivecraft/factions/entity/migrator/MigratorMConf005Warps.java b/src/com/massivecraft/factions/entity/migrator/MigratorMConf005Warps.java deleted file mode 100644 index 5898dfb8..00000000 --- a/src/com/massivecraft/factions/entity/migrator/MigratorMConf005Warps.java +++ /dev/null @@ -1,28 +0,0 @@ -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/entity/migrator/MigratorMPerm001Warps.java b/src/com/massivecraft/factions/entity/migrator/MigratorMPerm001Warps.java deleted file mode 100644 index 4f709908..00000000 --- a/src/com/massivecraft/factions/entity/migrator/MigratorMPerm001Warps.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.massivecraft.factions.entity.migrator; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.massivecore.store.migrator.MigratorRoot; - -public class MigratorMPerm001Warps extends MigratorRoot -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static MigratorMPerm001Warps i = new MigratorMPerm001Warps(); - public static MigratorMPerm001Warps get() { return i; } - private MigratorMPerm001Warps() - { - super(MPerm.class); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void migrateInner(JsonObject entity) - { - JsonElement jsonName = entity.get("name"); - String name = jsonName.getAsString(); - if (name.equalsIgnoreCase("home")) name = "warp"; - if (name.equalsIgnoreCase("sethome")) name = "setwarp"; - - entity.addProperty("name", name); - - JsonElement jsonDesc = entity.get("desc"); - String desc = jsonDesc.getAsString(); - if (desc.equalsIgnoreCase("teleport home")) desc = "teleport to warp"; - if (desc.equalsIgnoreCase("set the home")) desc = "set warps"; - - entity.addProperty("desc", desc); - } - -} diff --git a/src/com/massivecraft/factions/entity/migrator/MigratorMPerm002MoveStandard.java b/src/com/massivecraft/factions/entity/migrator/MigratorMPerm002MoveStandard.java deleted file mode 100644 index ec62b777..00000000 --- a/src/com/massivecraft/factions/entity/migrator/MigratorMPerm002MoveStandard.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.massivecraft.factions.entity.migrator; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.massivecore.collections.MassiveSet; -import com.massivecraft.massivecore.store.migrator.MigratorRoot; - -import java.util.Set; - -public class MigratorMPerm002MoveStandard extends MigratorRoot -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static MigratorMPerm002MoveStandard i = new MigratorMPerm002MoveStandard(); - public static MigratorMPerm002MoveStandard get() { return i; } - private MigratorMPerm002MoveStandard() - { - super(MPerm.class); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void migrateInner(JsonObject entity) - { - JsonElement jsonStandard = entity.remove("standard"); - if (jsonStandard == null || !jsonStandard.isJsonArray()) return; - - JsonArray jsonArray = jsonStandard.getAsJsonArray(); - Set result = new MassiveSet<>(); - jsonArray.forEach(e -> result.add(e.getAsString())); - - String id = entity.get("name").getAsString(); - - // This is hacky but we utilise that names and ids are the same - MConf.get().perm2default.put(id, result); - MConf.get().changed(); - } - -} diff --git a/src/com/massivecraft/factions/entity/migrator/MigratorMPlayer001Ranks.java b/src/com/massivecraft/factions/entity/migrator/MigratorMPlayer001Ranks.java deleted file mode 100644 index 9c134b76..00000000 --- a/src/com/massivecraft/factions/entity/migrator/MigratorMPlayer001Ranks.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.massivecraft.factions.entity.migrator; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.FactionColl; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.entity.Rank; -import com.massivecraft.massivecore.store.migrator.MigratorRoot; - -import java.util.Collection; - -public class MigratorMPlayer001Ranks extends MigratorRoot -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static MigratorMPlayer001Ranks i = new MigratorMPlayer001Ranks(); - public static MigratorMPlayer001Ranks get() { return i; } - private MigratorMPlayer001Ranks() - { - super(MPlayer.class); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void migrateInner(JsonObject entity) - { - // Get role - JsonElement jsonRole = entity.remove("role"); - String role; - if (jsonRole == null) - { - // The role can be null. - // Then they are probably recruit in the default faction (Wilderness). - role = null; - } - else - { - role = jsonRole.getAsString(); - } - - // Get faction - JsonElement jsonFaction = entity.get("factionId"); - - String factionId; - if (jsonFaction == null) factionId = MConf.get().defaultPlayerFactionId; - else factionId = jsonFaction.getAsString(); - - Faction faction = FactionColl.get().get(factionId); - if (faction == null) faction = FactionColl.get().getNone(); - - // Get rank - Rank rank = null; - if (role != null) - { - Collection ranks = faction.getRanks().getAll(); - for (Rank r : ranks) - { - if (!r.getName().equalsIgnoreCase(role)) continue; - rank = r; - break; - } - } - if (rank == null) rank = faction.getLowestRank(); - - entity.add("rankId", new JsonPrimitive(rank.getId())); - } - -} diff --git a/src/com/massivecraft/factions/entity/migrator/MigratorMPlayer002UsingAdminMode.java b/src/com/massivecraft/factions/entity/migrator/MigratorMPlayer002UsingAdminMode.java deleted file mode 100644 index 90a68b8f..00000000 --- a/src/com/massivecraft/factions/entity/migrator/MigratorMPlayer002UsingAdminMode.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.massivecraft.factions.entity.migrator; - -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.store.migrator.MigratorFieldRename; -import com.massivecraft.massivecore.store.migrator.MigratorRoot; - -public class MigratorMPlayer002UsingAdminMode extends MigratorRoot -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static MigratorMPlayer002UsingAdminMode i = new MigratorMPlayer002UsingAdminMode(); - public static MigratorMPlayer002UsingAdminMode get() { return i; } - private MigratorMPlayer002UsingAdminMode() - { - super(MPlayer.class); - this.addInnerMigrator(MigratorFieldRename.get("usingAdminMode", "overriding")); - } - -} diff --git a/src/com/massivecraft/factions/entity/migrator/MigratorTerritoryAccess001Restructure.java b/src/com/massivecraft/factions/entity/migrator/MigratorTerritoryAccess001Restructure.java deleted file mode 100644 index 01f0836d..00000000 --- a/src/com/massivecraft/factions/entity/migrator/MigratorTerritoryAccess001Restructure.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.massivecraft.factions.entity.migrator; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.massivecraft.factions.TerritoryAccess; -import com.massivecraft.factions.adapter.TerritoryAccessAdapter; -import com.massivecraft.massivecore.store.migrator.MigratorRoot; - -public class MigratorTerritoryAccess001Restructure extends MigratorRoot -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static MigratorTerritoryAccess001Restructure i = new MigratorTerritoryAccess001Restructure(); - public static MigratorTerritoryAccess001Restructure get() { return i; } - private MigratorTerritoryAccess001Restructure() - { - super(TerritoryAccess.class); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void migrateInner(JsonObject entity) - { - JsonElement factionIds = entity.remove("factionIds"); - JsonElement playerIds = entity.remove("playerIds"); - - JsonArray grantedIds = new JsonArray(); - - if (factionIds != null && factionIds.isJsonArray()) - { - JsonArray factionIdsArr = factionIds.getAsJsonArray(); - grantedIds.addAll(factionIdsArr); - } - - if (playerIds != null && playerIds.isJsonArray()) - { - JsonArray playerIdsArr = playerIds.getAsJsonArray(); - grantedIds.addAll(playerIdsArr); - } - - if (grantedIds.size() > 0) entity.add(TerritoryAccessAdapter.GRANTED_IDS, grantedIds); - } - -} diff --git a/src/com/massivecraft/factions/event/EventFactionsAbstract.java b/src/com/massivecraft/factions/event/EventFactionsAbstract.java deleted file mode 100644 index 5e20b0f9..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsAbstract.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.massivecore.event.EventMassiveCore; - -public abstract class EventFactionsAbstract extends EventMassiveCore -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsAbstract() - { - - } - - public EventFactionsAbstract(boolean isAsync) - { - super(isAsync); - } - -} diff --git a/src/com/massivecraft/factions/event/EventFactionsAbstractSender.java b/src/com/massivecraft/factions/event/EventFactionsAbstractSender.java deleted file mode 100644 index 3d74cf12..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsAbstractSender.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.event.EventMassiveCore; -import org.bukkit.command.CommandSender; - -public abstract class EventFactionsAbstractSender extends EventMassiveCore -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final CommandSender sender; - public CommandSender getSender() { return this.sender; } - public MPlayer getMPlayer() { return this.sender == null ? null : MPlayer.get(this.sender); } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsAbstractSender(CommandSender sender) - { - this.sender = sender; - } - - public EventFactionsAbstractSender(boolean async, CommandSender sender) - { - super(async); - this.sender = sender; - } - -} diff --git a/src/com/massivecraft/factions/event/EventFactionsChunkChangeType.java b/src/com/massivecraft/factions/event/EventFactionsChunkChangeType.java deleted file mode 100644 index 0797ec92..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsChunkChangeType.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.massivecore.Colorized; -import org.bukkit.ChatColor; - -public enum EventFactionsChunkChangeType implements Colorized -{ - // -------------------------------------------- // - // ENUM - // -------------------------------------------- // - - NONE("none", "none", ChatColor.WHITE), - BUY("buy", "bought", ChatColor.GREEN), - SELL("sell", "sold", ChatColor.GREEN), - CONQUER("conquer", "conquered", ChatColor.DARK_GREEN), - PILLAGE("pillage", "pillaged", ChatColor.RED), - - // END OF LIST - ; - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public final String now; - public final String past; - - public final ChatColor color; - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - EventFactionsChunkChangeType(String now, String past, ChatColor color) - { - this.now = now; - this.past = past; - this.color = color; - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public ChatColor getColor() - { - return this.color; - } - - // -------------------------------------------- // - // UTIL - // -------------------------------------------- // - - public static EventFactionsChunkChangeType get(Faction oldFaction, Faction newFaction, Faction self) - { - if (newFaction == oldFaction) return NONE; - if (oldFaction.isNone()) return BUY; - if (newFaction.isNormal()) return CONQUER; - if (oldFaction == self) return SELL; - return PILLAGE; - } - -} diff --git a/src/com/massivecraft/factions/event/EventFactionsChunksChange.java b/src/com/massivecraft/factions/event/EventFactionsChunksChange.java deleted file mode 100644 index e4540e0e..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsChunksChange.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.collections.MassiveMap; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.MUtil; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -import java.util.Collections; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -public class EventFactionsChunksChange 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 Set chunks; - public Set getChunks() { return this.chunks; } - - private final Faction newFaction; - public Faction getNewFaction() { return this.newFaction; } - - private final Map oldChunkFaction; - public Map getOldChunkFaction() { return this.oldChunkFaction; } - - private final Map> oldFactionChunks; - public Map> getOldFactionChunks() { return this.oldFactionChunks; } - - private final Map chunkType; - public Map getChunkType() { return this.chunkType; } - - private final Map> typeChunks; - public Map> getTypeChunks() { return this.typeChunks; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsChunksChange(CommandSender sender, Set chunks, Faction newFaction) - { - super(sender); - chunks = PS.getDistinctChunks(chunks); - this.chunks = Collections.unmodifiableSet(chunks); - this.newFaction = newFaction; - this.oldChunkFaction = Collections.unmodifiableMap(BoardColl.getChunkFaction(chunks)); - this.oldFactionChunks = Collections.unmodifiableMap(MUtil.reverseIndex(this.oldChunkFaction)); - - MPlayer msender = this.getMPlayer(); - Faction self = null; - if (msender != null) self = msender.getFaction(); - Map currentChunkType = new MassiveMap<>(); - for (Entry entry : this.oldChunkFaction.entrySet()) - { - PS chunk = entry.getKey(); - Faction from = entry.getValue(); - currentChunkType.put(chunk, EventFactionsChunkChangeType.get(from, newFaction, self)); - } - - this.chunkType = Collections.unmodifiableMap(currentChunkType); - this.typeChunks = Collections.unmodifiableMap(MUtil.reverseIndex(this.chunkType)); - } - -} diff --git a/src/com/massivecraft/factions/event/EventFactionsCreate.java b/src/com/massivecraft/factions/event/EventFactionsCreate.java deleted file mode 100644 index 66e80797..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsCreate.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.massivecraft.factions.event; - -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -public class EventFactionsCreate 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 String factionId; - public final String getFactionId() { return this.factionId; } - - private final String factionName; - public final String getFactionName() { return this.factionName; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsCreate(CommandSender sender, String factionId, String factionName) - { - super(sender); - this.factionId = factionId; - this.factionName = factionName; - } - -} diff --git a/src/com/massivecraft/factions/event/EventFactionsCreateFlags.java b/src/com/massivecraft/factions/event/EventFactionsCreateFlags.java deleted file mode 100644 index b1ded42a..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsCreateFlags.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.massivecraft.factions.event; - -import org.bukkit.event.HandlerList; - -/** - * External plugins that add Faction flags should make sure they exist when this event is called. - */ -public class EventFactionsCreateFlags extends EventFactionsAbstract -{ - // -------------------------------------------- // - // REQUIRED EVENT CODE - // -------------------------------------------- // - - private static final HandlerList handlers = new HandlerList(); - @Override public HandlerList getHandlers() { return handlers; } - public static HandlerList getHandlerList() { return handlers; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsCreateFlags() - { - - } - - public EventFactionsCreateFlags(boolean isAsync) - { - super(isAsync); - } - -} diff --git a/src/com/massivecraft/factions/event/EventFactionsCreatePerms.java b/src/com/massivecraft/factions/event/EventFactionsCreatePerms.java deleted file mode 100644 index 16034785..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsCreatePerms.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.massivecraft.factions.event; - -import org.bukkit.event.HandlerList; - -/** - * External plugins that add Faction perms should make sure they exist when this event is called. - */ -public class EventFactionsCreatePerms extends EventFactionsAbstract -{ - // -------------------------------------------- // - // REQUIRED EVENT CODE - // -------------------------------------------- // - - private static final HandlerList handlers = new HandlerList(); - @Override public HandlerList getHandlers() { return handlers; } - public static HandlerList getHandlerList() { return handlers; } - -} diff --git a/src/com/massivecraft/factions/event/EventFactionsDescriptionChange.java b/src/com/massivecraft/factions/event/EventFactionsDescriptionChange.java deleted file mode 100644 index dc49700c..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsDescriptionChange.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.Faction; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -public class EventFactionsDescriptionChange 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 String newDescription; - public String getNewDescription() { return this.newDescription; } - public void setNewDescription(String newDescription) { this.newDescription = newDescription; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsDescriptionChange(CommandSender sender, Faction faction, String newDescription) - { - super(sender); - this.faction = faction; - this.newDescription = newDescription; - } - -} diff --git a/src/com/massivecraft/factions/event/EventFactionsDisband.java b/src/com/massivecraft/factions/event/EventFactionsDisband.java deleted file mode 100644 index ca49b347..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsDisband.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.Faction; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -public class EventFactionsDisband 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 final String factionId; - public String getFactionId() { return this.factionId; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsDisband(CommandSender sender, Faction faction) - { - super(sender); - this.faction = faction; - this.factionId = faction.getId(); - } - -} diff --git a/src/com/massivecraft/factions/event/EventFactionsExpansions.java b/src/com/massivecraft/factions/event/EventFactionsExpansions.java deleted file mode 100644 index 33e28600..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsExpansions.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.massivecore.collections.MassiveTreeMap; -import com.massivecraft.massivecore.comparator.ComparatorCaseInsensitive; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -import java.util.Map; - -public class EventFactionsExpansions 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 MassiveTreeMap expansions = new MassiveTreeMap<>(ComparatorCaseInsensitive.get()); - public Map getExpansions() { return this.expansions; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsExpansions(CommandSender sender) - { - super(sender); - this.getExpansions().put("FactionsTax", false); - this.getExpansions().put("FactionsDynmap", false); - } - -} diff --git a/src/com/massivecraft/factions/event/EventFactionsFactionShowAsync.java b/src/com/massivecraft/factions/event/EventFactionsFactionShowAsync.java deleted file mode 100644 index 07859baa..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsFactionShowAsync.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.massivecore.PriorityLines; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -import java.util.HashMap; -import java.util.Map; - -public class EventFactionsFactionShowAsync 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 final Map idPriorityLiness; - public Map getIdPriorityLiness() { return this.idPriorityLiness; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsFactionShowAsync(CommandSender sender, Faction faction) - { - super(true, sender); - this.faction = faction; - this.idPriorityLiness = new HashMap<>(); - } - -} diff --git a/src/com/massivecraft/factions/event/EventFactionsFlagChange.java b/src/com/massivecraft/factions/event/EventFactionsFlagChange.java deleted file mode 100644 index f9627dd6..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsFlagChange.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MFlag; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -public class EventFactionsFlagChange 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 final MFlag flag; - public MFlag getFlag() { return this.flag; } - - private boolean newValue; - public boolean isNewValue() { return this.newValue; } - public void setNewValue(boolean newValue) { this.newValue = newValue; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsFlagChange(CommandSender sender, Faction faction, MFlag flag, boolean newValue) - { - super(sender); - this.faction = faction; - this.flag = flag; - this.newValue = newValue; - } - -} diff --git a/src/com/massivecraft/factions/event/EventFactionsInvitedChange.java b/src/com/massivecraft/factions/event/EventFactionsInvitedChange.java deleted file mode 100644 index 422b236b..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsInvitedChange.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPlayer; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -public class EventFactionsInvitedChange 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 MPlayer mplayer; - public MPlayer getMPlayer() { return this.mplayer; } - - private final Faction faction; - public Faction getFaction() { return this.faction; } - - private boolean newInvited; - public boolean isNewInvited() { return this.newInvited; } - public void setNewInvited(boolean newInvited) { this.newInvited = newInvited; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsInvitedChange(CommandSender sender, MPlayer mplayer, Faction faction, boolean newInvited) - { - super(sender); - this.mplayer = mplayer; - this.faction = faction; - this.newInvited = newInvited; - } - -} diff --git a/src/com/massivecraft/factions/event/EventFactionsMembershipChange.java b/src/com/massivecraft/factions/event/EventFactionsMembershipChange.java deleted file mode 100644 index 6b4b9d28..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsMembershipChange.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPlayer; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -public class EventFactionsMembershipChange 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 - // -------------------------------------------- // - - @Override - public void setCancelled(boolean cancelled) - { - if (!this.reason.isCancellable()) cancelled = false; - super.setCancelled(cancelled); - } - - private final MPlayer mplayer; - public MPlayer getMPlayer() { return this.mplayer; } - - private final Faction newFaction; - public Faction getNewFaction() { return this.newFaction; } - - private final MembershipChangeReason reason; - public MembershipChangeReason getReason() { return this.reason; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsMembershipChange(CommandSender sender, MPlayer mplayer, Faction newFaction, MembershipChangeReason reason) - { - super(sender); - this.mplayer = mplayer; - this.newFaction = newFaction; - this.reason = reason; - } - - // -------------------------------------------- // - // REASON ENUM - // -------------------------------------------- // - - public enum MembershipChangeReason - { - // Join - JOIN (true), - CREATE (false), - // Leader is not used, but temporarily kept to avoid other plugins crashing - @Deprecated - LEADER (true), - RANK (true), - - // Leave - LEAVE (true), - //JOINOTHER (true), - KICK (true), - DISBAND (false), - //RESET (false), - ; - - private final boolean cancellable; - public boolean isCancellable() { return this.cancellable; } - - MembershipChangeReason(boolean cancellable) - { - this.cancellable = cancellable; - } - } - -} diff --git a/src/com/massivecraft/factions/event/EventFactionsMotdChange.java b/src/com/massivecraft/factions/event/EventFactionsMotdChange.java deleted file mode 100644 index a85be9da..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsMotdChange.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.Faction; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -public class EventFactionsMotdChange 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 String newMotd; - public String getNewMotd() { return this.newMotd; } - public void setNewMotd(String newMotd) { this.newMotd = newMotd; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsMotdChange(CommandSender sender, Faction faction, String newMotd) - { - super(sender); - this.faction = faction; - this.newMotd = newMotd; - } - -} diff --git a/src/com/massivecraft/factions/event/EventFactionsNameChange.java b/src/com/massivecraft/factions/event/EventFactionsNameChange.java deleted file mode 100644 index 20edb6eb..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsNameChange.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.Faction; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -public class EventFactionsNameChange 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 String newName; - public String getNewName() { return this.newName; } - public void setNewName(String newName) { this.newName = newName; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsNameChange(CommandSender sender, Faction faction, String newName) - { - super(sender); - this.faction = faction; - this.newName = newName; - } - -} diff --git a/src/com/massivecraft/factions/event/EventFactionsPermChange.java b/src/com/massivecraft/factions/event/EventFactionsPermChange.java deleted file mode 100644 index 59b35605..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsPermChange.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPerm; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -public class EventFactionsPermChange 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 final MPerm perm; - public MPerm getPerm() { return this.perm; } - - private final MPerm.MPermable permable; - public MPerm.MPermable getRel() { return this.permable; } - - private boolean newValue; - public boolean getNewValue() { return this.newValue; } - public void setNewValue(boolean newValue) { this.newValue = newValue; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsPermChange(CommandSender sender, Faction faction, MPerm perm, MPerm.MPermable permable, boolean newValue) - { - super(sender); - this.faction = faction; - this.perm = perm; - this.permable = permable; - this.newValue = newValue; - } - -} diff --git a/src/com/massivecraft/factions/event/EventFactionsPowerChange.java b/src/com/massivecraft/factions/event/EventFactionsPowerChange.java deleted file mode 100644 index 77a09514..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsPowerChange.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.MPlayer; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -public class EventFactionsPowerChange 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 MPlayer mplayer; - public MPlayer getMPlayer() { return this.mplayer; } - - private final PowerChangeReason reason; - public PowerChangeReason getReason() { return this.reason; } - - private double newPower; - public double getNewPower() { return this.newPower; } - public void setNewPower(double newPower) { this.newPower = newPower; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsPowerChange(CommandSender sender, MPlayer mplayer, PowerChangeReason reason, double newPower) - { - super(sender); - this.mplayer = mplayer; - this.reason = reason; - this.newPower = mplayer.getLimitedPower(newPower); - } - - // -------------------------------------------- // - // REASON ENUM - // -------------------------------------------- // - - public enum PowerChangeReason - { - TIME, - DEATH, - COMMAND, - UNDEFINED, - ; - } - -} diff --git a/src/com/massivecraft/factions/event/EventFactionsPvpDisallowed.java b/src/com/massivecraft/factions/event/EventFactionsPvpDisallowed.java deleted file mode 100644 index 62864bae..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsPvpDisallowed.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.engine.DisallowCause; -import com.massivecraft.factions.entity.MPlayer; -import org.bukkit.entity.Player; -import org.bukkit.event.HandlerList; -import org.bukkit.event.entity.EntityDamageByEntityEvent; - -/** - * This event is fired when PVP is disallowed between players due to any rules in Factions. - * Canceling this event allows the PVP in spite of this and stops text messages from being sent. - * - * Note that the defender field always is set but the attacker can be null. - * Some other plugins seem to fire EntityDamageByEntityEvent without an attacker. - */ -public class EventFactionsPvpDisallowed extends EventFactionsAbstract -{ - // -------------------------------------------- // - // 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 Player attacker; - public Player getAttacker() { return this.attacker; } - public MPlayer getMAttacker() { return this.attacker == null ? null : MPlayer.get(this.attacker); } - - private final Player defender; - public Player getDefender() { return this.defender; } - public MPlayer getMDefender() { return this.defender == null ? null : MPlayer.get(this.defender); } - - private final DisallowCause cause; - public DisallowCause getCause() { return this.cause; } - - private final EntityDamageByEntityEvent event; - public EntityDamageByEntityEvent getEvent() { return this.event; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsPvpDisallowed(Player attacker, Player defender, DisallowCause cause, EntityDamageByEntityEvent event) - { - this.attacker = attacker; - this.defender = defender; - this.cause = cause; - this.event = event; - } - -} diff --git a/src/com/massivecraft/factions/event/EventFactionsRankChange.java b/src/com/massivecraft/factions/event/EventFactionsRankChange.java deleted file mode 100644 index f9396505..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsRankChange.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.entity.Rank; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -public class EventFactionsRankChange 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 MPlayer mplayer; - public MPlayer getMPlayer() { return this.mplayer; } - - private Rank newRank; - public Rank getNewRank() { return this.newRank; } - public void setNewRank(Rank newRole) { this.newRank = newRole; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsRankChange(CommandSender sender, MPlayer mplayer, Rank newRank) - { - super(sender); - this.mplayer = mplayer; - this.newRank = newRank; - } -} diff --git a/src/com/massivecraft/factions/event/EventFactionsRelationChange.java b/src/com/massivecraft/factions/event/EventFactionsRelationChange.java deleted file mode 100644 index 9610ed2c..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsRelationChange.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.Rel; -import com.massivecraft.factions.entity.Faction; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - - -public class EventFactionsRelationChange 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 final Faction otherFaction; - public Faction getOtherFaction() { return this.otherFaction; } - - private Rel newRelation; - public Rel getNewRelation() { return this.newRelation; } - public void setNewRelation(Rel newRelation) { this.newRelation = newRelation; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsRelationChange(CommandSender sender, Faction faction, Faction otherFaction, Rel newRelation) - { - super(sender); - this.faction = faction; - this.otherFaction = otherFaction; - this.newRelation = newRelation; - } - -} diff --git a/src/com/massivecraft/factions/event/EventFactionsTitleChange.java b/src/com/massivecraft/factions/event/EventFactionsTitleChange.java deleted file mode 100644 index 7c6227e1..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsTitleChange.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.MPlayer; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -public class EventFactionsTitleChange 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 MPlayer mplayer; - public MPlayer getMPlayer() { return this.mplayer; } - - private String newTitle; - public String getNewTitle() { return this.newTitle; } - public void setNewTitle(String newTitle) { this.newTitle = newTitle; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsTitleChange(CommandSender sender, MPlayer mplayer, String newTitle) - { - super(sender); - this.mplayer = mplayer; - this.newTitle = newTitle; - } - -} diff --git a/src/com/massivecraft/factions/event/EventFactionsVoteAdd.java b/src/com/massivecraft/factions/event/EventFactionsVoteAdd.java deleted file mode 100644 index f3ed680c..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsVoteAdd.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.Vote; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -public class EventFactionsVoteAdd 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 Vote vote; - public Vote getVote() { return this.vote; } - public void setVote(Vote vote) { this.vote = vote; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsVoteAdd(CommandSender sender, Faction faction, Vote vote) - { - super(sender); - this.faction = faction; - this.vote = vote; - } - -} diff --git a/src/com/massivecraft/factions/event/EventFactionsVoteRemove.java b/src/com/massivecraft/factions/event/EventFactionsVoteRemove.java deleted file mode 100644 index f7b3c03e..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsVoteRemove.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.Vote; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -public class EventFactionsVoteRemove 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 Vote vote; - public Vote getVote() { return this.vote; } - public void setVote(Vote vote) { this.vote = vote; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsVoteRemove(CommandSender sender, Faction faction, Vote vote) - { - super(sender); - this.faction = faction; - this.vote = vote; - } - -} diff --git a/src/com/massivecraft/factions/event/EventFactionsWarpAdd.java b/src/com/massivecraft/factions/event/EventFactionsWarpAdd.java deleted file mode 100644 index e0d03a2e..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsWarpAdd.java +++ /dev/null @@ -1,40 +0,0 @@ -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 deleted file mode 100644 index 7ac52b03..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsWarpRemove.java +++ /dev/null @@ -1,40 +0,0 @@ -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 getWarp() { return this.warp; } - public void setWarp(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/EventFactionsWarpTeleport.java b/src/com/massivecraft/factions/event/EventFactionsWarpTeleport.java deleted file mode 100644 index 1672faef..00000000 --- a/src/com/massivecraft/factions/event/EventFactionsWarpTeleport.java +++ /dev/null @@ -1,34 +0,0 @@ -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/Econ.java b/src/com/massivecraft/factions/integration/Econ.java deleted file mode 100644 index b8b4cd6e..00000000 --- a/src/com/massivecraft/factions/integration/Econ.java +++ /dev/null @@ -1,345 +0,0 @@ -package com.massivecraft.factions.integration; - -import com.massivecraft.factions.EconomyParticipator; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.util.RelationUtil; -import com.massivecraft.massivecore.money.Money; - -import java.util.HashSet; -import java.util.Set; - -public class Econ -{ - // -------------------------------------------- // - // STATE - // -------------------------------------------- // - - public static boolean isEnabled() - { - return MConf.get().econEnabled && Money.enabled(); - } - - // -------------------------------------------- // - // UTIL - // -------------------------------------------- // - - public static boolean payForAction(double cost, MPlayer usender, String actionDescription) - { - if (!isEnabled()) return true; - if (cost == 0D) return true; - - if (usender.isOverriding()) return true; - - Faction usenderFaction = usender.getFaction(); - - if (MConf.get().bankEnabled && MConf.get().bankFactionPaysCosts && usenderFaction.isNormal()) - { - return modifyMoney(usenderFaction, -cost, actionDescription); - } - else - { - return modifyMoney(usender, -cost, actionDescription); - } - } - - // -------------------------------------------- // - // ASSORTED - // -------------------------------------------- // - - public static void modifyUniverseMoney(Object universe, double delta) - { - if ( ! isEnabled()) return; - - if (MConf.get().econUniverseAccount == null) return; - if (MConf.get().econUniverseAccount.length() == 0) return; - - if ( ! Money.exists(MConf.get().econUniverseAccount)) return; - - Money.spawn(MConf.get().econUniverseAccount, null, delta); - } - - public static void sendBalanceInfo(MPlayer to, EconomyParticipator about) - { - to.msg("%s's balance is %s.", about.describeTo(to, true), Money.format(getMoney(about))); - } - - public static boolean isMePermittedYou(EconomyParticipator me, EconomyParticipator you, MPerm mperm) - { - // Null means special system invocation and is always to be accepted. - if (me == null) return true; - - // Always accept when in admin mode. - if (me instanceof MPlayer && ((MPlayer)me).isOverriding()) return true; - - // Always accept control of self - if (me == you) return true; - - Faction fMe = RelationUtil.getFaction(me); - Faction fYou = RelationUtil.getFaction(you); - - // A faction can always transfer away the money of it's members and its own money... - // This will however probably never happen as a faction does not have free will. - // Ohh by the way... Yes it could. For daily rent to the faction. - if (me == fMe && fMe == fYou) return true; - - // Factions can be controlled by those that have permissions - if (you instanceof Faction) - { - if (me instanceof Faction && mperm.has((Faction)me, fYou)) return true; - if (me instanceof MPlayer && mperm.has((MPlayer)me, fYou, false)) return true; - } - - // Otherwise you may not! ;,,; - return false; - } - - public static boolean transferMoney(EconomyParticipator invoker, EconomyParticipator from, EconomyParticipator to, double amount) - { - return transferMoney(from, to, invoker, amount, true); - } - public static boolean transferMoney(EconomyParticipator from, EconomyParticipator to, EconomyParticipator by, double amount, boolean notify) - { - if ( ! isEnabled()) return false; - - // The amount must be positive. - // If the amount is negative we must flip and multiply amount with -1. - if (amount < 0) - { - amount *= -1; - EconomyParticipator temp = from; - from = to; - to = temp; - } - - // Check Permissions - if ( ! isMePermittedYou(by, from, MPerm.getPermWithdraw())) - { - by.msg("%s lack permission to withdraw money from %s.", by.describeTo(by, true), from.describeTo(by)); - return false; - } - - if ( ! isMePermittedYou(by, to, MPerm.getPermDeposit())) - { - by.msg("%s lack permission to deposit money to %s.", by.describeTo(by, true), to.describeTo(by)); - return false; - } - - // Is there enough money for the transaction to happen? - if (getMoney(from) < amount) - { - // There was not enough money to pay - if (by != null && notify) - { - by.msg("%s can't afford to transfer %s to %s.", from.describeTo(by, true), Money.format(amount), to.describeTo(by)); - } - return false; - } - - // Transfer money - if (moveMoney(from, to, by, amount)) - { - if (notify) - { - sendTransferInfo(by, from, to, amount); - } - return true; - } - else - { - // if we get here something with the transaction failed - if (by != null && notify) - { - by.msg("Unable to transfer %s to %s from %s.", Money.format(amount), to.describeTo(by), from.describeTo(by, true)); - } - return false; - } - } - - public static Set getMPlayers(EconomyParticipator ep) - { - Set mplayers = new HashSet<>(); - - if (ep == null) - { - // Add nothing - } - else if (ep instanceof MPlayer) - { - mplayers.add((MPlayer)ep); - } - else if (ep instanceof Faction) - { - mplayers.addAll(((Faction)ep).getMPlayers()); - } - - return mplayers; - } - - public static void sendTransferInfo(EconomyParticipator invoker, EconomyParticipator from, EconomyParticipator to, double amount) - { - Set recipients = new HashSet<>(); - recipients.addAll(getMPlayers(invoker)); - recipients.addAll(getMPlayers(from)); - recipients.addAll(getMPlayers(to)); - - if (invoker == null) - { - for (MPlayer recipient : recipients) - { - recipient.msg("%s was transfered from %s to %s.", Money.format(amount), from.describeTo(recipient), to.describeTo(recipient)); - } - } - else if (invoker == from) - { - for (MPlayer recipient : recipients) - { - recipient.msg("%s gave %s to %s.", from.describeTo(recipient, true), Money.format(amount), to.describeTo(recipient)); - } - } - else if (invoker == to) - { - for (MPlayer recipient : recipients) - { - recipient.msg("%s took %s from %s.", to.describeTo(recipient, true), Money.format(amount), from.describeTo(recipient)); - } - } - else - { - for (MPlayer recipient : recipients) - { - recipient.msg("%s transfered %s from %s to %s.", invoker.describeTo(recipient, true), Money.format(amount), from.describeTo(recipient), to.describeTo(recipient)); - } - } - } - - public static boolean hasAtLeast(EconomyParticipator ep, double delta) - { - return hasAtLeast(ep, delta, null); - } - - public static boolean hasAtLeast(EconomyParticipator ep, double delta, String toDoThis) - { - if ( ! isEnabled()) return true; - - if (getMoney(ep) < delta) - { - if (toDoThis != null && !toDoThis.isEmpty()) - { - ep.msg("%s can't afford %s %s.", ep.describeTo(ep, true), Money.format(delta), toDoThis); - } - return false; - } - return true; - } - - public static boolean modifyMoney(EconomyParticipator ep, double delta, String actionDescription) - { - if ( ! isEnabled()) return false; - if (delta == 0) return true; - - String You = ep.describeTo(ep, true); - String you = ep.describeTo(ep, false); - - boolean hasActionDesctription = (actionDescription != null && !actionDescription.isEmpty()); - - if (moveMoney(null, ep, null, delta)) - { - modifyUniverseMoney(ep, -delta); - - if (hasActionDesctription) - { - if (delta > 0) - { - ep.msg("%s gained %s since %s did %s.", You, Money.format(delta), you, actionDescription); - } - else - { - ep.msg("%s lost %s since %s did %s.", You, Money.format(-delta), you, actionDescription); - } - } - return true; - } - else - { - if (hasActionDesctription) - { - if (delta > 0) - { - ep.msg("%s would have gained %s since %s did %s, but the deposit failed.", You, Money.format(delta), you, actionDescription); - } - else - { - ep.msg("%s can't afford %s to %s.", You, Money.format(-delta), actionDescription); - } - } - return false; - } - } - - public static double getMoney(EconomyParticipator ep) - { - if (ep instanceof Faction && MConf.get().useNewMoneySystem) - { - return ((Faction) ep).getMoney(); - } - else - { - return Money.get(ep); - } - } - - public static boolean moveMoney(EconomyParticipator from, EconomyParticipator to, EconomyParticipator by, double amount) - { - return moveMoney(from, to, by, amount, "Factions"); - } - - public static boolean moveMoney(EconomyParticipator from, EconomyParticipator to, EconomyParticipator by, double amount, String category) - { - final boolean fromFaction = from instanceof Faction; - final boolean toFaction = to instanceof Faction; - - // If the old money system is used just do that - if (!MConf.get().useNewMoneySystem) - { - return Money.move(from, to, by, amount, category); - } - - // Or if neither to or from is a faction - if (!fromFaction && !toFaction) - { - return Money.move(from, to, by, amount, category); - } - - // Handle from - if (fromFaction) - { - Faction faction = (Faction) from; - double money = faction.getMoney(); - if (amount > money) return false; - faction.setMoney(money - amount); - } - else if (from != null) - { - boolean temp = Money.despawn(from, by, amount); - if (temp == false) return temp; - } - - // Handle to - if (toFaction) - { - Faction faction = (Faction) to; - double money = faction.getMoney(); - faction.setMoney(money + amount); - } - else if (to != null) - { - Money.spawn(to, by, amount); - } - - return true; - } - -} diff --git a/src/com/massivecraft/factions/integration/dynmap/AreaMarkerValues.java b/src/com/massivecraft/factions/integration/dynmap/AreaMarkerValues.java deleted file mode 100644 index c2a38e80..00000000 --- a/src/com/massivecraft/factions/integration/dynmap/AreaMarkerValues.java +++ /dev/null @@ -1,222 +0,0 @@ -package com.massivecraft.factions.integration.dynmap; - -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.MUtil; -import org.dynmap.markers.AreaMarker; -import org.dynmap.markers.MarkerAPI; -import org.dynmap.markers.MarkerSet; - -public class AreaMarkerValues -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final String label; - public String getLabel() { return label; } - public AreaMarkerValues withLabel(String label) { return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } - - private final String world; - public String getWorld() { return world; } - public AreaMarkerValues withWorld(String world) { return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } - - private final PS[] corners; - public PS[] getCorners() { return this.corners; } - public AreaMarkerValues withCorners() { return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } - - private final String description; - public String getDescription() { return description; } - public AreaMarkerValues withDescription(String description) { return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } - - private final int lineColor; - public int getLineColor() { return lineColor; } - public AreaMarkerValues withLineColor(int lineColor) { return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } - - private final double lineOpacity; - public double getLineOpacity() { return lineOpacity; } - public AreaMarkerValues withLineOpacity(double lineOpacity) { return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } - - private final int lineWeight; - public int getLineWeight() { return lineWeight; } - public AreaMarkerValues withLineWright(int lineWeight) { return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } - - private final int fillColor; - public int getFillColor() { return fillColor; } - public AreaMarkerValues withFillColor(int fillColor) { return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } - - private final double fillOpacity; - public double getFillOpacity() { return fillOpacity; } - public AreaMarkerValues withFillOpacity(double fillOpacity) { return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } - - private final boolean boost; - public boolean isBoost() { return boost; } - public AreaMarkerValues withBoost(boolean boost) { return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } - - public AreaMarkerValues withStyle(DynmapStyle style) - { - return new AreaMarkerValues(label, world, corners, description, style); - } - - // Caches - private final double[] x; - private final double[] z; - - // -------------------------------------------- // - // CONSTRUCTOR - // -------------------------------------------- // - - public AreaMarkerValues(String label, String world, PS[] corners, String description, DynmapStyle style) - { - this(label, world, corners, description, style.getLineColor(), style.getLineOpacity(), style.getLineWeight(), style.getFillColor(), style.getFillOpacity(), style.getBoost()); - } - - public AreaMarkerValues(String label, String world, PS[] corners, String description, int lineColor, double lineOpacity, int lineWeight, int fillColor, double fillOpacity, boolean boost) - { - this.label = label; - this.world = world; - this.corners = corners; - this.description = description; - this.lineColor = lineColor; - this.lineOpacity = lineOpacity; - this.lineWeight = lineWeight; - this.fillColor = fillColor; - this.fillOpacity = fillOpacity; - this.boost = boost; - - int sz = corners.length; - x = new double[sz]; - z = new double[sz]; - - for (int i = 0; i < sz; i++) - { - PS ps = corners[i]; - x[i] = ps.getLocationX(true); - z[i] = ps.getLocationZ(true); - } - } - - // -------------------------------------------- // - // MASTER - // -------------------------------------------- // - - public AreaMarker ensureExistsAndUpdated(AreaMarker areaMarker, MarkerAPI markerApi, MarkerSet markerset, String markerId) - { - // NOTE: I remove from the map created just in the beginning of this method. - // NOTE: That way what is left at the end will be outdated markers to remove. - if (areaMarker == null) - { - areaMarker = create(markerApi, markerset, markerId); - } - else - { - update(markerApi, markerset, areaMarker); - } - - if (areaMarker == null) - { - EngineDynmap.logSevere("Could not get/create the area marker " + markerId); - } - - return areaMarker; - } - - // -------------------------------------------- // - // CREATE - // -------------------------------------------- // - - public AreaMarker create(MarkerAPI markerApi, MarkerSet markerset, String markerId) - { - AreaMarker ret = markerset.createAreaMarker( - markerId, - this.getLabel(), - false, - this.getWorld(), - this.x, - this.z, - false // not persistent - ); - - if (ret == null) return null; - - // Description - ret.setDescription(this.getDescription()); - - // Line Style - ret.setLineStyle(this.getLineWeight(), this.getLineOpacity(), this.getLineColor()); - - // Fill Style - ret.setFillStyle(this.getFillOpacity(), this.getFillColor()); - - // Boost Flag - ret.setBoostFlag(this.isBoost()); - - return ret; - } - - // -------------------------------------------- // - // UPDATE - // -------------------------------------------- // - - public void update(MarkerAPI markerApi, MarkerSet markerset, AreaMarker marker) - { - // Corner Locations - if (!equals(marker, this.x, this.z)) - { - marker.setCornerLocations(this.x, this.z); - } - - // Label - MUtil.setIfDifferent(this.getLabel(), marker::getLabel, marker::setLabel); - - // Description - MUtil.setIfDifferent(this.getDescription(), marker::getDescription, marker::setDescription); - - // Line Style - if - ( - !MUtil.equals(marker.getLineWeight(), this.lineWeight) - || - !MUtil.equals(marker.getLineOpacity(), this.lineOpacity) - || - !MUtil.equals(marker.getLineColor(), this.lineColor) - ) - { - marker.setLineStyle(this.lineWeight, this.lineOpacity, this.lineColor); - } - - // Fill Style - if - ( - !MUtil.equals(marker.getFillOpacity(), this.fillOpacity) - || - !MUtil.equals(marker.getFillColor(), this.fillColor) - ) - { - marker.setFillStyle(this.fillOpacity, this.fillColor); - } - - // Boost Flag - MUtil.setIfDifferent(this.isBoost(), marker::getBoostFlag, marker::setBoostFlag); - } - - // -------------------------------------------- // - // UTIL - // -------------------------------------------- // - - public static boolean equals(AreaMarker marker, double[] x, double[] z) - { - int length = marker.getCornerCount(); - - if (x.length != length) return false; - if (z.length != length) return false; - - for (int i = 0; i < length; i++) - { - if (marker.getCornerX(i) != x[i]) return false; - if (marker.getCornerZ(i) != z[i]) return false; - } - - return true; - } - -} \ No newline at end of file diff --git a/src/com/massivecraft/factions/integration/dynmap/DynmapStyle.java b/src/com/massivecraft/factions/integration/dynmap/DynmapStyle.java deleted file mode 100644 index 743224c0..00000000 --- a/src/com/massivecraft/factions/integration/dynmap/DynmapStyle.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.massivecraft.factions.integration.dynmap; - -import com.massivecraft.factions.entity.MConf; - -public class DynmapStyle -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public final String lineColor; - public int getLineColor() { return getColor(coalesce(this.lineColor, MConf.get().dynmapDefaultStyle.lineColor, IntegrationDynmap.DYNMAP_STYLE_LINE_COLOR)); } - public DynmapStyle withLineColor(String lineColor) { return new DynmapStyle(lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, homeMarker, boost); } - - public final Double lineOpacity; - public double getLineOpacity() { return coalesce(this.lineOpacity, MConf.get().dynmapDefaultStyle.lineOpacity, IntegrationDynmap.DYNMAP_STYLE_LINE_OPACITY); } - public DynmapStyle withLineOpacity(Double lineOpacity) { return new DynmapStyle(lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, homeMarker, boost); } - - public final Integer lineWeight; - public int getLineWeight() { return coalesce(this.lineWeight, MConf.get().dynmapDefaultStyle.lineWeight, IntegrationDynmap.DYNMAP_STYLE_LINE_WEIGHT); } - public DynmapStyle withLineWeight(Integer lineWeight) { return new DynmapStyle(lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, homeMarker, boost); } - - public final String fillColor; - public int getFillColor() { return getColor(coalesce(this.fillColor, MConf.get().dynmapDefaultStyle.fillColor, IntegrationDynmap.DYNMAP_STYLE_FILL_COLOR)); } - public DynmapStyle withFillColor(String fillColor) { return new DynmapStyle(lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, homeMarker, boost); } - - public final Double fillOpacity; - public double getFillOpacity() { return coalesce(this.fillOpacity, MConf.get().dynmapDefaultStyle.fillOpacity, IntegrationDynmap.DYNMAP_STYLE_FILL_OPACITY); } - public DynmapStyle withFillOpacity(Double fillOpacity) { return new DynmapStyle(lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, homeMarker, boost); } - - // NOTE: We just return the string here. We do not return the resolved Dynmap MarkerIcon object. - // The reason is we use this class in the MConf. For serialization to work Dynmap would have to be loaded and we can't require that. - // Using dynmap is optional. - public final String homeMarker; - public String getHomeMarker() { return coalesce(this.homeMarker, MConf.get().dynmapDefaultStyle.homeMarker, IntegrationDynmap.DYNMAP_STYLE_HOME_MARKER); } - public DynmapStyle withHomeMarker(String homeMarker) { return new DynmapStyle(lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, homeMarker, boost); } - - public final Boolean boost; - public boolean getBoost() { return coalesce(this.boost, MConf.get().dynmapDefaultStyle.boost, IntegrationDynmap.DYNMAP_STYLE_BOOST); } - public DynmapStyle withBoost(Boolean boost) { return new DynmapStyle(lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, homeMarker, boost); } - - // -------------------------------------------- // - // CONSTRUCTOR - // -------------------------------------------- // - - public DynmapStyle() - { - this(null, null, null, null, null, null, null); - } - - public DynmapStyle(String lineColor, Double lineOpacity, Integer lineWeight, String fillColor, Double fillOpacity, String homeMarker, Boolean boost) - { - this.lineColor = lineColor; - this.lineOpacity = lineOpacity; - this.lineWeight = lineWeight; - this.fillColor = fillColor; - this.fillOpacity = fillOpacity; - this.homeMarker = homeMarker; - this.boost = boost; - } - - // -------------------------------------------- // - // UTIL - // -------------------------------------------- // - - @SafeVarargs - public static T coalesce(T... items) - { - for (T item : items) - { - if (item != null) return item; - } - return null; - } - - public static int getColor(String string) - { - int ret = 0x00FF00; - try - { - ret = Integer.parseInt(string.substring(1), 16); - } - catch (NumberFormatException nfx) - { - - } - return ret; - } - -} \ No newline at end of file diff --git a/src/com/massivecraft/factions/integration/dynmap/EngineDynmap.java b/src/com/massivecraft/factions/integration/dynmap/EngineDynmap.java deleted file mode 100644 index 40c75a0f..00000000 --- a/src/com/massivecraft/factions/integration/dynmap/EngineDynmap.java +++ /dev/null @@ -1,760 +0,0 @@ -package com.massivecraft.factions.integration.dynmap; - -import com.massivecraft.factions.Factions; -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.MPlayer; -import com.massivecraft.factions.integration.Econ; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.collections.MassiveList; -import com.massivecraft.massivecore.collections.MassiveMap; -import com.massivecraft.massivecore.collections.MassiveSet; -import com.massivecraft.massivecore.money.Money; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.MUtil; -import com.massivecraft.massivecore.util.TimeDiffUtil; -import com.massivecraft.massivecore.util.TimeUnit; -import com.massivecraft.massivecore.util.Txt; -import org.apache.commons.lang.StringEscapeUtils; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.dynmap.DynmapAPI; -import org.dynmap.markers.AreaMarker; -import org.dynmap.markers.MarkerAPI; -import org.dynmap.markers.MarkerSet; - -import java.util.ArrayDeque; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class EngineDynmap extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineDynmap i = new EngineDynmap(); - public static EngineDynmap get() { return i; } - private EngineDynmap() - { - // Async - this.setSync(false); - - // Every 15 seconds - this.setPeriod(15 * 20L); - } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private DynmapAPI dynmapApi; - private MarkerAPI markerApi; - private MarkerSet markerset; - - // -------------------------------------------- // - // RUN: UPDATE - // -------------------------------------------- // - - // Thread Safe / Asynchronous: Yes - @Override - public void run() - { - // Is Dynmap enabled? - if (MConf.get().dynmapEnabled) - { - this.perform(); - } - else - { - this.disable(); - } - } - - public void perform() - { - long before = System.currentTimeMillis(); - - // We do what we can here. - // You /can/ run this method from the main server thread but it's not recommended at all. - // This method is supposed to be run async to avoid locking the main server thread. - //final Map homes = createHomes(); - final Map areas = createAreas(); - - logTimeSpent("Async", before); - - // Shedule non thread safe sync at the end! - Bukkit.getScheduler().scheduleSyncDelayedTask(Factions.get(), () -> this.updateFactionsDynmap(areas)); - } - - public void updateFactionsDynmap(Map areas) - { - long before = System.currentTimeMillis(); - - if (!Bukkit.isPrimaryThread()) throw new IllegalStateException("async"); - - if (!fetchDynmapAPI()) return; - - // createLayer() is thread safe but it makes use of fields set in fetchDynmapAPI() so we must have it after. - if (!updateLayer(createLayer())) return; - - updateAreas(areas); - - logTimeSpent("Sync", before); - } - - public void disable() - { - if (this.markerset != null) - { - this.markerset.deleteMarkerSet(); - this.markerset = null; - } - } - - // Thread Safe / Asynchronous: Yes - public static void logTimeSpent(String name, long start) - { - if (!MConf.get().dynmapLogTimeSpent) return; - long end = System.currentTimeMillis(); - long duration = end-start; - - String message = Txt.parse("Dynmap %s took %dms.", name, duration); - Factions.get().log(message); - } - - // -------------------------------------------- // - // API - // -------------------------------------------- // - - // Thread Safe / Asynchronous: No - public boolean fetchDynmapAPI() - { - // Get DynmapAPI - this.dynmapApi = (DynmapAPI) Bukkit.getPluginManager().getPlugin("dynmap"); - if (this.dynmapApi == null) - { - logSevere("Could not access the DynmapAPI."); - return false; - } - - // Get MarkerAPI - this.markerApi = this.dynmapApi.getMarkerAPI(); - if (this.markerApi == null) - { - logSevere("Could not access the MarkerAPI."); - return false; - } - - return true; - } - - // -------------------------------------------- // - // UPDATE: Layer - // -------------------------------------------- // - - // Thread Safe / Asynchronous: Yes - public LayerValues createLayer() - { - return new LayerValues( - MConf.get().dynmapLayerName, - MConf.get().dynmapLayerMinimumZoom, - MConf.get().dynmapLayerPriority, - MConf.get().dynmapLayerHiddenByDefault - ); - } - - // Thread Safe / Asynchronous: No - public boolean updateLayer(LayerValues temp) - { - this.markerset = temp.ensureExistsAndUpdated(this.markerApi, IntegrationDynmap.FACTIONS_MARKERSET); - return this.markerset != null; - } - - // -------------------------------------------- // - // UPDATE: AREAS - // -------------------------------------------- // - - // Thread Safe: YES - public Map createAreas() - { - Map>> worldFactionChunks = BoardColl.get().getWorldToFactionToChunks(false); - return createAreas(worldFactionChunks); - - } - - // Thread Safe: YES - public Map createAreas(Map>> worldFactionChunks) - { - // For each world create the areas - return worldFactionChunks.entrySet().stream() - .map(this::createAreas) - // And combine all of those into a single map: - .map(Map::entrySet) - .flatMap(Set::stream) - .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); - } - - public Map createAreas(Entry>> superEntry) - { - return createAreas(superEntry.getKey(), superEntry.getValue()); - } - - public Map createAreas(String world, Map> map) - { - // For each entry convert it into the appropriate map (with method below) - return map.entrySet().stream() - .map(e -> createAreas(world, e)) - // And combine all of those into a single map: - .map(Map::entrySet) - .flatMap(Set::stream) - .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); - } - - public Map createAreas(String world, Entry> entry) - { - return createAreas(world, entry.getKey(), entry.getValue()); - } - - public Map createAreas(String world, Faction faction, Set chunks) - { - // If the faction is visible ... - if (!isVisible(faction, world)) return Collections.emptyMap(); - - // ... and has any chunks ... - if (chunks.isEmpty()) return Collections.emptyMap(); - - Map ret = new MassiveMap<>(); - - // Get info - String description = getDescription(faction); - DynmapStyle style = this.getStyle(faction); - - // Here we start of with all chunks - // This field is slowly cleared when the chunks are grouped into polygons - Set allChunksSource = new MassiveSet<>(chunks); - - while (!allChunksSource.isEmpty()) - { - Iterator it = allChunksSource.iterator(); - PS somePs = it.next(); - - List linelist = new MassiveList<>(); - // Create the polygon - Set polygonChunks = new MassiveSet<>(); - floodFillTarget(allChunksSource, polygonChunks, somePs); - - List polygonCorners = new MassiveList<>(); - for (PS chunk : polygonChunks) - { - for (Direction d : Direction.values()) - { - polygonCorners.add(d.getCorner(chunk)); - } - } - - Set points = new MassiveSet<>(); - for (PS corner : polygonCorners) - { - if (points.contains(corner)) - points.remove(corner); - else - points.add(corner); - } - - Map edges_h = new MassiveMap<>(); - Map edges_v = new MassiveMap<>(); - - List sorted_x = new MassiveList<>(points); - Collections.sort(sorted_x, this::xThenZ); - List sorted_z = new MassiveList<>(points); - Collections.sort(sorted_z, this::zThenX); - - // Create horizontal edges - for (int i = 0; i < points.size();) - { - int curr_z = sorted_z.get(i).getChunkZ(); - while (i < points.size() && curr_z == sorted_z.get(i+1).getChunkZ()) - { - edges_h.put(sorted_z.get(i), sorted_z.get(i+1)); - edges_h.put(sorted_z.get(i+1), sorted_z.get(i)); - i += 2; - } - } - - // Create vertical edges - for (int i = 0; i < points.size();) - { - int curr_x = sorted_x.get(i).getChunkX(); - while (i < points.size() && curr_x == sorted_x.get(i+1).getChunkX()) - { - edges_v.put(sorted_x.get(i), sorted_x.get(i+1)); - edges_v.put(sorted_x.get(i+1), sorted_x.get(i)); - i += 2; - } - } - - //List linelist = getLineList(polygonChunks); - - - linelist = new MassiveList<>(new LinkedHashSet<>(linelist)); - - for (Direction d : Direction.values()) - { - linelist.add(d.getCorner(somePs)); - } - - // Build information for specific area - String markerId = calcMarkerId(world, faction); - AreaMarkerValues values = new AreaMarkerValues(faction.getName(), world, linelist.toArray(new PS[]{}), description, style); - ret.put(markerId, values); - } - - return ret; - } - - private int zThenX(PS a, PS b) - { - if (a.getChunkZ() < b.getChunkZ() || (a.getChunkZ().equals(b.getChunkZ()) && a.getChunkX() < b.getChunkX())) - return -1; - else if (a.equals(b)) - return 0; - else - return 1; - } - - private int xThenZ(PS a, PS b) - { - if (a.getChunkX() < b.getChunkX() || (a.getChunkX().equals(b.getChunkX()) && a.getChunkZ() < b.getChunkZ())) - return -1; - else if (a.equals(b)) - return 0; - else - return 1; - } - - private static PS getMinimum(Collection pss) - { - int minimumX = Integer.MAX_VALUE; - int minimumZ = Integer.MAX_VALUE; - - for (PS chunk : pss) - { - int chunkX = chunk.getChunkX(); - int chunkZ = chunk.getChunkZ(); - - if (chunkX < minimumX) - { - minimumX = chunkX; - minimumZ = chunkZ; - } - else if (chunkX == minimumX && chunkZ < minimumZ) - { - minimumZ = chunkZ; - } - } - return PS.valueOf(minimumX, minimumZ); - } - - // XPLUS, ZPLUS, XMINUS, ZMINUS - private static List getLineList(Set polygonChunks) - { - PS minimumChunk = getMinimum(polygonChunks); - - //final int initialX = minimumChunk.getChunkX(); - //final int initialZ = minimumChunk.getChunkZ(); - //int currentX = initialX; - //int currentZ = initialZ; - - PS currentChunk = minimumChunk; - - Direction direction = Direction.XPLUS; - List linelist = new MassiveList<>(); - - linelist.add(minimumChunk); // Add start point - while ((!currentChunk.equals(minimumChunk)) || (direction != Direction.ZMINUS)) - { - PS adjacent = direction.adjacent(currentChunk); - PS corner = direction.getCorner(currentChunk); - // If the adjacent chunk is not present - - if (!polygonChunks.contains(adjacent)) - { // Right turn? - linelist.add(corner); // Finish line - direction = direction.turnRight(); // Change direction - } - - // If the chunk left of the adjacent is not present - else if (!polygonChunks.contains(direction.turnLeft().adjacent(adjacent))) - { // Straight? - currentChunk = adjacent; - } - - else - { // Left turn - linelist.add(corner); // Finish line - direction = direction.turnLeft(); - - // Left turn of adjacent - currentChunk = direction.adjacent(adjacent); - } - } - - return linelist; - } - - // IS CLAIMED - - private static boolean isSoutheastClaimed(PS ps, Collection polygon) - { - return polygon.contains(PS.valueOf(ps.getChunkX() - 1, ps.getChunkZ() + 1)); - } - - private static boolean isNortheastClaimed(PS ps, Collection polygon) - { - return polygon.contains(PS.valueOf(ps.getChunkX() + 1, ps.getChunkZ() + 1)); - } - - private static boolean isSouthwestClaimed(PS ps, Collection polygon) - { - return polygon.contains(PS.valueOf(ps.getChunkX() - 1, ps.getChunkZ() - 1)); - } - - private static boolean isNorthwestClaimed(PS ps, Collection polygon) - { - return polygon.contains(PS.valueOf(ps.getChunkX() + 1, ps.getChunkZ() - 1)); - } - - // GET CHUNKS - - private static PS getNortheastPS(PS ps) - { - return PS.valueOf(ps.getChunkX() + 1, ps.getChunkZ() + 1); - } - - private static PS getSoutheastPS(PS ps) - { - return PS.valueOf(ps.getChunkX(), ps.getChunkZ() + 1); - } - - private static PS getSouthwestPS(PS ps) - { - return PS.valueOf(ps.getChunkX(), ps.getChunkZ()); - } - - private static PS getNorthwestPS(PS ps) - { - return PS.valueOf(ps.getChunkX() + 1, ps.getChunkZ()); - } - - // This markerIndex, is if a faction has several claims in a single world - private int markerIdx = 0; - private String lastPartialMarkerId = ""; - public String calcMarkerId(String world, Faction faction) - { - // Calc current partial - String partial = IntegrationDynmap.FACTIONS_AREA_ + world + "__" + faction.getId() + "__"; - - // If different than last time, then reset the counter - if (!partial.equals(lastPartialMarkerId)) markerIdx = 0; - - this.lastPartialMarkerId = partial; - - return partial + markerIdx++; - } - - // Thread Safe: NO - public void updateAreas(Map values) - { - // Cleanup old markers - this.markerset.getAreaMarkers().stream() // Get current markers - .filter(am -> !values.containsKey(am.getMarkerID())) // That are not in the new map - .forEach(AreaMarker::deleteMarker); // and delete them - - - // Map Current - Map markers = getMarkerMap(this.markerset); - - // Loop New - values.forEach((markerId, value) -> - value.ensureExistsAndUpdated(markers.get(markerId), this.markerApi, this.markerset, markerId)); - - } - - private static Map getMarkerMap(MarkerSet markerSet) - { - return markerSet.getAreaMarkers().stream().collect(Collectors.toMap(AreaMarker::getMarkerID, m->m)); - } - - // -------------------------------------------- // - // UTIL & SHARED - // -------------------------------------------- // - - // Thread Safe / Asynchronous: Yes - private String getDescription(Faction faction) - { - String ret = "
" + MConf.get().dynmapFactionDescription + "
"; - - // Name - String name = faction.getName(); - ret = addToHtml(ret, "name", name); - - // Description - String description = faction.getDescriptionDesc(); - ret = addToHtml(ret, "description", description); - - // MOTD (probably shouldn't be shown but if the server owner specifies it, I don't care) - String motd = faction.getMotd(); - if (motd != null) ret = addToHtml(ret, "motd", motd); - - // Age - long ageMillis = faction.getAge(); - LinkedHashMap ageUnitcounts = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(ageMillis, TimeUnit.getAllButMillisSecondsAndMinutes()), 3); - String age = TimeDiffUtil.formatedVerboose(ageUnitcounts, ""); - ret = addToHtml(ret, "age", age); - - // Money - String money = "unavailable"; - if (Econ.isEnabled() && MConf.get().dynmapShowMoneyInDescription) - { - money = Money.format(Econ.getMoney(faction)); - } - ret = addToHtml(ret, "money", money); - - // Flags - Map flags = MFlag.getAll().stream() - .filter(MFlag::isVisible) - .collect(Collectors.toMap(m -> m, faction::getFlag)); - - List flagMapParts = new MassiveList<>(); - List flagTableParts = new MassiveList<>(); - - for (Entry entry : flags.entrySet()) - { - String flagName = entry.getKey().getName(); - boolean value = entry.getValue(); - - String bool = String.valueOf(value); - String color = calcBoolcolor(flagName, value); - String boolcolor = calcBoolcolor(String.valueOf(value), value); - - ret = ret.replace("%" + flagName + ".bool%", bool); // true - ret = ret.replace("%" + flagName + ".color%", color); // monsters (red or green) - ret = ret.replace("%" + flagName + ".boolcolor%", boolcolor); // true (red or green) - - flagMapParts.add(flagName + ": " + boolcolor); - flagTableParts.add(color); - } - - String flagMap = Txt.implode(flagMapParts, "
\n"); - ret = ret.replace("%flags.map%", flagMap); - - // The server can specify the wished number of columns - // So we loop over the possibilities - for (int cols = 1; cols <= 10; cols++) - { - String flagTable = getHtmlAsciTable(flagTableParts, cols); - ret = ret.replace("%flags.table" + cols + "%", flagTable); - } - - // Players - List playersList = faction.getMPlayers(); - String playersCount = String.valueOf(playersList.size()); - String players = getHtmlPlayerString(playersList); - - MPlayer playersLeaderObject = faction.getLeader(); - String playersLeader = getHtmlPlayerName(playersLeaderObject); - - ret = ret.replace("%players%", players); - ret = ret.replace("%players.count%", playersCount); - ret = ret.replace("%players.leader%", playersLeader); - - return ret; - } - - public static String getHtmlAsciTable(Collection strings, final int cols) - { - StringBuilder ret = new StringBuilder(); - - int count = 0; - for (Iterator iter = strings.iterator(); iter.hasNext();) - { - String string = iter.next(); - count++; - - ret.append(string); - - if (iter.hasNext()) - { - boolean lineBreak = count % cols == 0; - ret.append(lineBreak ? "
" : " | "); - } - } - - return ret.toString(); - } - - public static String getHtmlPlayerString(List mplayers) - { - List names = mplayers.stream().map(EngineDynmap::getHtmlPlayerName).collect(Collectors.toList()); - return Txt.implodeCommaAndDot(names); - } - - public static String getHtmlPlayerName(MPlayer mplayer) - { - if (mplayer == null) return "none"; - return StringEscapeUtils.escapeHtml(mplayer.getName()); - } - - public static String calcBoolcolor(String string, boolean bool) - { - return "" + string + ""; - } - - public static String addToHtml(String ret, String target, String replace) - { - if (ret == null) throw new NullPointerException("ret"); - if (target == null) throw new NullPointerException("target"); - if (replace == null) throw new NullPointerException("replace"); - - target = "%" + target + "%"; - replace = ChatColor.stripColor(replace); - replace = StringEscapeUtils.escapeHtml(replace); - return ret.replace(target, replace); - } - - // Thread Safe / Asynchronous: Yes - private boolean isVisible(Faction faction, String world) - { - if (faction == null) throw new NullPointerException("faction"); - if (world == null) throw new NullPointerException("world"); - - final String factionId = faction.getId(); - final String factionName = faction.getName(); - final String worldId = "world:" + world; - - Set ids = MUtil.set(factionId, factionName, worldId); - - if (factionId == null) throw new NullPointerException("faction id"); - if (factionName == null) throw new NullPointerException("faction name"); - - Set visible = MConf.get().dynmapVisibleFactions; - Set hidden = MConf.get().dynmapHiddenFactions; - - - if (!visible.isEmpty() && visible.stream().noneMatch(ids::contains)) - { - return false; - } - - if (!hidden.isEmpty() && hidden.stream().anyMatch(ids::contains)) - { - return false; - } - - - return true; - } - - // Thread Safe / Asynchronous: Yes - public DynmapStyle getStyle(Faction faction) - { - Map styles = MConf.get().dynmapFactionStyles; - - return DynmapStyle.coalesce( - styles.get(faction.getId()), - styles.get(faction.getName()), - MConf.get().dynmapDefaultStyle - ); - } - - public static void logSevere(String msg) - { - String message = ChatColor.RED.toString() + msg; - Factions.get().log(message); - } - - enum Direction - { - XPLUS, ZPLUS, XMINUS, ZMINUS - - ; - - public PS adjacent(PS ps) - { - switch (this) - { - case XPLUS: return PS.valueOf(ps.getChunkX() + 1, ps.getChunkZ()); - case ZPLUS: return PS.valueOf(ps.getChunkX(), ps.getChunkZ() + 1); - case XMINUS: return PS.valueOf(ps.getChunkX() - 1, ps.getChunkZ()); - case ZMINUS: return PS.valueOf(ps.getChunkX(), ps.getChunkZ() - 1); - } - throw new RuntimeException("say what"); - } - - public PS getCorner(PS ps) - { - switch (this) - { - case XPLUS: return PS.valueOf(ps.getChunkX() + 1, ps.getChunkZ()); - case ZPLUS: return PS.valueOf(ps.getChunkX() + 1, ps.getChunkZ() + 1); - case XMINUS: return PS.valueOf(ps.getChunkX(), ps.getChunkZ() + 1); - case ZMINUS: return PS.valueOf(ps.getChunkX(), ps.getChunkZ()); - } - throw new RuntimeException("say what"); - } - - public Direction turnRight() - { - return values()[(this.ordinal() + 1) % values().length]; - } - - public Direction turnAround() - { - return this.turnRight().turnRight(); - } - - public Direction turnLeft() - { - return this.turnRight().turnRight().turnRight(); - } - } - - private void floodFillTarget(Collection source, Collection destination, PS startChunk) - { - // Create the deque - ArrayDeque stack = new ArrayDeque<>(); - stack.push(startChunk); - - // And for each item in the queue - while (!stack.isEmpty()) - { - PS next = stack.pop(); - - // If it is in the source - // Remove it from there to avoid double-counting (and endless recursion) - if (!source.remove(next)) continue; - - // Add to destination - destination.add(next); - - // And look in adjacent chunks that are within the source - Stream.of(Direction.values()) - .map(d -> d.adjacent(next)) - .filter(source::contains) - .forEach(stack::push); - } - } - -} diff --git a/src/com/massivecraft/factions/integration/dynmap/IntegrationDynmap.java b/src/com/massivecraft/factions/integration/dynmap/IntegrationDynmap.java deleted file mode 100644 index 68f7b126..00000000 --- a/src/com/massivecraft/factions/integration/dynmap/IntegrationDynmap.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.massivecraft.factions.integration.dynmap; - -import com.massivecraft.factions.integration.worldguard.EngineWorldGuard; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.Integration; - -public class IntegrationDynmap extends Integration -{ - // -------------------------------------------- // - // CONSTANTS - // -------------------------------------------- // - - // Constants must be here rather than in EngineDynmap. - // MConf relies on DynmapStyle which relies on these constants - // and we must be able to load MConf without EngineDynmap. - public final static int BLOCKS_PER_CHUNK = 16; - - public final static String FACTIONS = "factions"; - public final static String FACTIONS_ = FACTIONS + "_"; - - public final static String FACTIONS_MARKERSET = FACTIONS_ + "markerset"; - - public final static String FACTIONS_AREA = FACTIONS_ + "area"; - public final static String FACTIONS_AREA_ = FACTIONS_AREA + "_"; - - public final static transient String DYNMAP_STYLE_LINE_COLOR = "#00FF00"; - public final static transient double DYNMAP_STYLE_LINE_OPACITY = 0.8D; - public final static transient int DYNMAP_STYLE_LINE_WEIGHT = 3; - public final static transient String DYNMAP_STYLE_FILL_COLOR = "#00FF00"; - public final static transient double DYNMAP_STYLE_FILL_OPACITY = 0.35D; - public final static transient String DYNMAP_STYLE_HOME_MARKER = "greenflag"; - public final static transient boolean DYNMAP_STYLE_BOOST = false; - - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static IntegrationDynmap i = new IntegrationDynmap(); - public static IntegrationDynmap get() { return i; } - private IntegrationDynmap() - { - this.setPluginName("dynmap"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public Engine getEngine() - { - return EngineDynmap.get(); - } - -} diff --git a/src/com/massivecraft/factions/integration/dynmap/LayerValues.java b/src/com/massivecraft/factions/integration/dynmap/LayerValues.java deleted file mode 100644 index 5392c224..00000000 --- a/src/com/massivecraft/factions/integration/dynmap/LayerValues.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.massivecraft.factions.integration.dynmap; - -import com.massivecraft.massivecore.util.MUtil; -import org.dynmap.markers.MarkerAPI; -import org.dynmap.markers.MarkerSet; - -public class LayerValues -{ - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final String label; - public String getLabel() { return label; } - public LayerValues withLabel(String label) { return new LayerValues(label, minimumZoom, priority, hiddenByDefault); } - - private final int minimumZoom; - public int getMinimumZoom() { return minimumZoom; } - public LayerValues withMinimumZoom(int minimumZoom) { return new LayerValues(label, minimumZoom, priority, hiddenByDefault); } - - private final int priority; - public int getPriority() { return priority; } - public LayerValues withPriority(int priority) { return new LayerValues(label, minimumZoom, priority, hiddenByDefault); } - - private final boolean hiddenByDefault; - public boolean isHiddenByDefault() { return hiddenByDefault; } - public LayerValues withHidenByDefault(boolean hideByDefault) { return new LayerValues(label, minimumZoom, priority, hideByDefault); } - - // -------------------------------------------- // - // CONSTRUCTOR - // -------------------------------------------- // - - public LayerValues(String label, int minimumZoom, int priority, boolean hideByDefault) - { - this.label = label; - this.minimumZoom = minimumZoom; - this.priority = priority; - this.hiddenByDefault = hideByDefault; - } - - // -------------------------------------------- // - // MASTER - // -------------------------------------------- // - - public MarkerSet ensureExistsAndUpdated(MarkerAPI api, String id) - { - MarkerSet set = api.getMarkerSet(id); - if (set == null) - { - set = this.create(api, id); - } - else - { - this.update(set); - } - - if (set == null) - { - EngineDynmap.logSevere("Could not create the Faction Markerset/Layer"); - } - - return set; - } - - // -------------------------------------------- // - // CREATE - // -------------------------------------------- // - - public MarkerSet create(MarkerAPI markerApi, String id) - { - MarkerSet ret = markerApi.createMarkerSet(id, this.label, null, false); // ("null, false" at the end means "all icons allowed, not perisistent") - if (ret == null) return null; - - // Minimum Zoom - if (this.minimumZoom > 0) - { - ret.setMinZoom(this.getMinimumZoom()); - } - - // Priority - ret.setLayerPriority(this.getPriority()); - - // Hide by Default - ret.setHideByDefault(this.isHiddenByDefault()); - return ret; - } - - // -------------------------------------------- // - // UPDATE - // -------------------------------------------- // - - public void update(MarkerSet markerset) - { - // Minimum Zoom - if (this.minimumZoom > 0) - { - MUtil.setIfDifferent(this.getMinimumZoom(), markerset::getMinZoom, markerset::setMinZoom); - } - - // Set other values - MUtil.setIfDifferent(this.getLabel(), markerset::getMarkerSetLabel, markerset::setMarkerSetLabel); - MUtil.setIfDifferent(this.getPriority(), markerset::getLayerPriority, markerset::setLayerPriority); - MUtil.setIfDifferent(this.isHiddenByDefault(), markerset::getHideByDefault, markerset::setHideByDefault); - } - -} diff --git a/src/com/massivecraft/factions/integration/dynmap/MarkerValues.java b/src/com/massivecraft/factions/integration/dynmap/MarkerValues.java deleted file mode 100644 index 50c747f6..00000000 --- a/src/com/massivecraft/factions/integration/dynmap/MarkerValues.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.massivecraft.factions.integration.dynmap; - -import com.massivecraft.massivecore.util.MUtil; -import org.dynmap.markers.Marker; -import org.dynmap.markers.MarkerAPI; -import org.dynmap.markers.MarkerIcon; -import org.dynmap.markers.MarkerSet; - -public class MarkerValues -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final String label; - public String getLabel() { return label; } - public MarkerValues withLabel(String label) { return new MarkerValues(label, world, x, y, z, iconName, description); } - - private final String world; - public String getWorld() { return world; } - public MarkerValues withWorld(String world) { return new MarkerValues(label, world, x, y, z, iconName, description); } - - private final double x; - public double getX() { return x; } - public MarkerValues withX(double x) { return new MarkerValues(label, world, x, y, z, iconName, description); } - - private final double y; - public double getY() { return y; } - public MarkerValues withY(double y) { return new MarkerValues(label, world, x, y, z, iconName, description); } - - private final double z; - public double getZ() { return z; } - public MarkerValues withZ(double z) { return new MarkerValues(label, world, x, y, z, iconName, description); } - - private final String iconName; - public String getIconName() { return iconName; } - public MarkerValues withIconName(String iconName) { return new MarkerValues(label, world, x, y, z, iconName, description); } - - private final String description; - public String getDescription() { return description; } - public MarkerValues withDescription(String description) { return new MarkerValues(label, world, x, y, z, iconName, description); } - - // -------------------------------------------- // - // CONSTRUCTOR - // -------------------------------------------- // - - public MarkerValues(String label, String world, double x, double y, double z, String iconName, String description) - { - this.label = label; - this.world = world; - this.x = x; - this.y = y; - this.z = z; - this.iconName = iconName; - this.description = description; - } - - // -------------------------------------------- // - // MAKE SURE EXISTS - // -------------------------------------------- // - - public Marker ensureExistsAndUpdated(MarkerAPI markerApi, MarkerSet markerset, String id) - { - throw new UnsupportedOperationException("todo"); - } - - // -------------------------------------------- // - // CREATE - // -------------------------------------------- // - - public Marker create(MarkerAPI markerApi, MarkerSet markerset, String markerId) - { - Marker ret = markerset.createMarker( - markerId, - this.getLabel(), - this.getWorld(), - this.getX(), - this.getY(), - this.getZ(), - getMarkerIcon(markerApi, this.getIconName()), - false // not persistent - ); - - if (ret == null) return null; - - ret.setDescription(this.getDescription()); - - return ret; - } - - // -------------------------------------------- // - // UPDATE - // -------------------------------------------- // - - public void update(MarkerAPI markerApi, MarkerSet markerset, Marker marker) - { - if - ( - !MUtil.equals(marker.getWorld(), this.getWorld()) - || - marker.getX() != this.getX() - || - marker.getY() != this.getY() - || - marker.getZ() != this.getZ() - ) - { - marker.setLocation( - this.getWorld(), - this.getX(), - this.getY(), - this.getZ() - ); - } - - MUtil.setIfDifferent(this.getLabel(), marker::getLabel, marker::setLabel); - - MarkerIcon icon = getMarkerIcon(markerApi, this.iconName); - MUtil.setIfDifferent(icon, marker::getMarkerIcon, marker::setMarkerIcon); - - MUtil.setIfDifferent(this.getDescription(), marker::getDescription, marker::setDescription); - } - - // -------------------------------------------- // - // UTIL - // -------------------------------------------- // - - public static MarkerIcon getMarkerIcon(MarkerAPI markerApi, String name) - { - MarkerIcon ret = markerApi.getMarkerIcon(name); - if (ret == null) ret = markerApi.getMarkerIcon(IntegrationDynmap.DYNMAP_STYLE_HOME_MARKER); - return ret; - } - -} \ No newline at end of file diff --git a/src/com/massivecraft/factions/integration/lwc/EngineLwc.java b/src/com/massivecraft/factions/integration/lwc/EngineLwc.java deleted file mode 100644 index 67f2a3bb..00000000 --- a/src/com/massivecraft/factions/integration/lwc/EngineLwc.java +++ /dev/null @@ -1,137 +0,0 @@ -package com.massivecraft.factions.integration.lwc; - -import com.griefcraft.lwc.LWC; -import com.griefcraft.model.Protection; -import com.griefcraft.sql.PhysDB; -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.event.EventFactionsChunkChangeType; -import com.massivecraft.factions.event.EventFactionsChunksChange; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.IdUtil; -import org.bukkit.Bukkit; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; - -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - - -public class EngineLwc extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineLwc i = new EngineLwc(); - public static EngineLwc get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void setActiveInner(boolean active) - { - if (active) - { - LWC.getInstance().getModuleLoader().registerModule(Factions.get(), new FactionsLwcModule(Factions.get())); - } - else - { - if (LWC.getInstance() != null) - { - LWC.getInstance().getModuleLoader().removeModules(Factions.get()); - } - } - } - - // -------------------------------------------- // - // LISTENER - // -------------------------------------------- // - - public void removeProtectionsOnChunkChange(Faction newFaction, EventFactionsChunkChangeType type, Set chunks) - { - // If we are supposed to clear at this chunk change type ... - Boolean remove = MConf.get().lwcRemoveOnChange.get(type); - if (remove == null) return; - if (remove == false) return; - - // ... then remove for all other factions than the new one. - // First we wait one tick to make sure the chunk ownership changes have been applied. - // Then we remove the protections but we do it asynchronously to not lock the main thread. - for (PS chunk : chunks) - { - removeAlienProtectionsAsyncNextTick(chunk, newFaction); - } - } - - public void removeProtectionsOnChunkChange(Faction newFaction, Map> typeChunks) - { - for (Entry> typeChunk : typeChunks.entrySet()) - { - final EventFactionsChunkChangeType type = typeChunk.getKey(); - final Set chunks = typeChunk.getValue(); - removeProtectionsOnChunkChange(newFaction, type, chunks); - } - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void removeProtectionsOnChunkChange(EventFactionsChunksChange event) - { - removeProtectionsOnChunkChange(event.getNewFaction(), event.getTypeChunks()); - } - - // -------------------------------------------- // - // UTIL - // -------------------------------------------- // - - // This method causes LWC to run an SQL query which can take a few milliseconds. - // For that reason this method should not be executed in the main server thread. - // After looking through the source code of LWC I am also hopeful this is thread safe. - public static List getProtectionsInChunk(PS chunkPs) - { - final int xmin = chunkPs.getChunkX() * 16; - final int xmax = xmin + 15; - - final int ymin = 0; - final int ymax = 255; - - final int zmin = chunkPs.getChunkZ() * 16; - final int zmax = zmin + 15; - - PhysDB db = LWC.getInstance().getPhysicalDatabase(); - return db.loadProtections(chunkPs.getWorld(), xmin, xmax, ymin, ymax, zmin, zmax); - } - - // As with the method above: Thread safe and slow. Do run asynchronously. - public static void removeAlienProtectionsRaw(PS chunkPs, Faction faction) - { - List nonAliens = faction.getMPlayers(); - for (Protection protection : getProtectionsInChunk(chunkPs)) - { - // NOTE: The LWC protection owner is still the name and not the UUID. For that reason we must convert it. - String ownerName = protection.getOwner(); - String ownerId = IdUtil.getId(ownerName); - MPlayer owner = MPlayer.get(ownerId); - if (nonAliens.contains(owner)) continue; - protection.remove(); - } - } - - public static void removeAlienProtectionsAsync(final PS chunkPs, final Faction faction) - { - Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> removeAlienProtectionsRaw(chunkPs, faction)); - } - - public static void removeAlienProtectionsAsyncNextTick(final PS chunkPs, final Faction faction) - { - Bukkit.getScheduler().runTaskLater(Factions.get(), () -> removeAlienProtectionsAsync(chunkPs, faction), 0); - } - -} diff --git a/src/com/massivecraft/factions/integration/lwc/FactionsLwcModule.java b/src/com/massivecraft/factions/integration/lwc/FactionsLwcModule.java deleted file mode 100644 index f014c796..00000000 --- a/src/com/massivecraft/factions/integration/lwc/FactionsLwcModule.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.massivecraft.factions.integration.lwc; - -import com.griefcraft.lwc.LWC; -import com.griefcraft.model.Protection; -import com.griefcraft.scripting.JavaModule; -import com.griefcraft.scripting.event.LWCProtectionInteractEvent; -import com.griefcraft.scripting.event.LWCProtectionRegisterEvent; -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.engine.EnginePermBuild; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.SoundEffect; -import com.massivecraft.massivecore.mixin.MixinMessage; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.IdUtil; -import com.massivecraft.massivecore.util.SmokeUtil; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.Location; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; - -@SuppressWarnings("unused") -public class FactionsLwcModule extends JavaModule -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - // These plugin variables must be present. - // They are set by LWC using reflection somehow. - private Factions plugin; - private LWC lwc; - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public FactionsLwcModule(Factions plugin) - { - this.plugin = plugin; - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - // - - @Override - public void onRegisterProtection(LWCProtectionRegisterEvent event) - { - // If this feature is enabled ... - if ( ! MConf.get().lwcMustHaveBuildRightsToCreate) return; - - // ... and the player don't have build rights here ... - // NOTE: We verbosely check the build rights so that a proper info message is sent - if (EnginePermBuild.canPlayerBuildAt(event.getPlayer(), PS.valueOf(event.getBlock()), true)) return; - - // ... then cancel the event. - event.setCancelled(true); - } - - @Override - public void onProtectionInteract(LWCProtectionInteractEvent event) - { - // If this feature is enabled ... - if ( ! MConf.get().lwcRemoveIfNoBuildRights) return; - - // ... gather data ... - final Protection protection = event.getProtection(); - final Block block = protection.getBlock(); - final PS ps = PS.valueOf(block); - // NOTE: The LWC protection owner is still the name and not the UUID. For that reason we must convert it. - final String ownerName = protection.getOwner(); - final String ownerId = IdUtil.getId(ownerName); - final MPlayer mowner = MPlayer.get(ownerId); - if (mowner == null) return; - - // ... and if the protection owner no longer has build rights for the area ... - // NOTE: We silently check the build rights for the protection owner. - // NOTE: The protection owner may even be offline at the moment. - if (EnginePermBuild.canPlayerBuildAt(mowner, ps, false)) return; - - // ... remove the protection ... - protection.remove(); - - // ... cancel the event ... - // NOTE: The first time you click nothing but the unlock should happen. - // NOTE: This way it's more obvious the auto unlock system kicked in. - // NOTE: No inventory will get opened. - event.setResult(Result.CANCEL); - - // ... play FX ... - Location location = block.getLocation(); - SmokeUtil.spawnCloudSimple(location); - - SoundEffect.valueOf("DOOR_OPEN", 1, 1).run(location); - - // ... and inform. - Player player = event.getPlayer(); - String message = Txt.parse("Factions removed %s's LWC. They lacked build rights.", mowner.getDisplayName(player)); - MixinMessage.get().messageOne(player, message); - } - -} diff --git a/src/com/massivecraft/factions/integration/lwc/IntegrationLwc.java b/src/com/massivecraft/factions/integration/lwc/IntegrationLwc.java deleted file mode 100644 index 6dbe4e8b..00000000 --- a/src/com/massivecraft/factions/integration/lwc/IntegrationLwc.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.massivecraft.factions.integration.lwc; - -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.Integration; - -public class IntegrationLwc extends Integration -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static IntegrationLwc i = new IntegrationLwc(); - public static IntegrationLwc get() { return i; } - private IntegrationLwc() - { - this.setPluginName("LWC"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public Engine getEngine() - { - return EngineLwc.get(); - } - -} diff --git a/src/com/massivecraft/factions/integration/placeholderapi/IntegrationPlaceholderAPI.java b/src/com/massivecraft/factions/integration/placeholderapi/IntegrationPlaceholderAPI.java deleted file mode 100644 index 2699129f..00000000 --- a/src/com/massivecraft/factions/integration/placeholderapi/IntegrationPlaceholderAPI.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.massivecraft.factions.integration.placeholderapi; - -import com.massivecraft.massivecore.Integration; -import org.bukkit.Bukkit; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; - -public class IntegrationPlaceholderAPI extends Integration -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static IntegrationPlaceholderAPI i = new IntegrationPlaceholderAPI(); - public static IntegrationPlaceholderAPI get() { return i; } - private IntegrationPlaceholderAPI() - { - this.setPluginName("PlaceholderAPI"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void setIntegrationActiveInner(boolean active) - { - if (active) PlaceholderFactions.get().register(); - } - - public static void ensureRegistered() - { - if (PlaceholderFactions.get().isRegistered()) return; - PlaceholderFactions.get().register(); - } - - // If the PlaceholderAPI command is run to reload the config - // then we should reregister. - @EventHandler(priority = EventPriority.MONITOR) - public void lookForCommand(PlayerCommandPreprocessEvent event) - { - String str = event.getMessage(); - if (str.startsWith("/")) str = str.substring(1); - - if (!str.startsWith("papi")) return; - Bukkit.getScheduler().runTaskLater(this.getPlugin(), IntegrationPlaceholderAPI::ensureRegistered, 10L); - } - - -} diff --git a/src/com/massivecraft/factions/integration/placeholderapi/PlaceholderFactions.java b/src/com/massivecraft/factions/integration/placeholderapi/PlaceholderFactions.java deleted file mode 100644 index 7483e499..00000000 --- a/src/com/massivecraft/factions/integration/placeholderapi/PlaceholderFactions.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.massivecraft.factions.integration.placeholderapi; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.MPlayer; -import me.clip.placeholderapi.expansion.PlaceholderExpansion; -import org.bukkit.entity.Player; - -import java.text.DecimalFormat; - -public class PlaceholderFactions extends PlaceholderExpansion -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static PlaceholderFactions i = new PlaceholderFactions(); - public static PlaceholderFactions get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getIdentifier() - { - return "factions"; - } - - @Override - public String getAuthor() - { - return "Madus"; - } - - @Override - public String getVersion() - { - return Factions.get().getDescription().getVersion(); - } - - @Override - public String onPlaceholderRequest(Player player, String params) - { - if (player == null) return null; - - MPlayer mplayer = MPlayer.get(player); - if ("role".equals(params)) params = "rank"; - DecimalFormat df = new DecimalFormat("#.##"); - - switch (params) - { - case "faction": return mplayer.getFaction().getName(); - case "power": return df.format(mplayer.getPower()); - case "powermax": return df.format(mplayer.getPowerMax()); - case "factionpower": return df.format(mplayer.getFaction().getPower()); - case "factionpowermax": return df.format(mplayer.getFaction().getPowerMax()); - case "title": return mplayer.getTitle(); - case "rank": return mplayer.getRank().getName(); - case "claims": return Long.toString(BoardColl.get().getAll().stream().mapToInt(board -> board.getCount(mplayer.getFaction())).sum()); - case "onlinemembers": return Integer.toString(mplayer.getFaction().getMPlayersWhereOnlineTo(mplayer).size()); - case "allmembers": return Integer.toString(mplayer.getFaction().getMPlayers().size()); - } - return null; - } - -} diff --git a/src/com/massivecraft/factions/integration/venturechat/EngineVentureChat.java b/src/com/massivecraft/factions/integration/venturechat/EngineVentureChat.java deleted file mode 100644 index 43bc47cb..00000000 --- a/src/com/massivecraft/factions/integration/venturechat/EngineVentureChat.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.massivecraft.factions.integration.venturechat; - -import com.massivecraft.factions.engine.EngineChat; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.Engine; -import mineverse.Aust1n46.chat.api.MineverseChatAPI; -import mineverse.Aust1n46.chat.api.MineverseChatPlayer; -import mineverse.Aust1n46.chat.channel.ChatChannel; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.AsyncPlayerChatEvent; - -import java.util.function.Predicate; - -public class EngineVentureChat extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineVentureChat i = new EngineVentureChat(); - public static EngineVentureChat get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void setActiveInner(boolean active) - { - - } - - // -------------------------------------------- // - // LISTENER - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) - public void filterFaction(AsyncPlayerChatEvent event) - { - // Get player - Player player = event.getPlayer(); - MineverseChatPlayer chatPlayer = MineverseChatAPI.getMineverseChatPlayer(player); - ChatChannel channel = chatPlayer.getCurrentChannel(); - String channelName = channel.getName(); - - // If the channel is the Factions channel - boolean factionChat = channelName.equalsIgnoreCase(MConf.get().ventureChatFactionChannelName); - boolean allyChat = channelName.equalsIgnoreCase(MConf.get().ventureChatAllyChannelName); - if (!(factionChat || allyChat)) return; - - MPlayer mplayer = MPlayer.get(player); - Faction faction = mplayer.getFaction(); - - // Wilderness check - if ( ! MConf.get().ventureChatAllowFactionchatBetweenFactionless && faction.isNone()) - { - mplayer.msg("Factionless can't use faction chat."); - event.setCancelled(true); - } - - Predicate predicateChannel = factionChat ? EngineChat.getPredicateIsInFaction(faction) : EngineChat.getPredicateIsAlly(faction); - Predicate isSpy = recipient -> MineverseChatAPI.getMineverseChatPlayer(recipient).isSpy(); - Predicate predicate = isSpy.or(predicateChannel); - - EngineChat.filterToPredicate(event, predicate); - } - -} diff --git a/src/com/massivecraft/factions/integration/venturechat/IntegrationVentureChat.java b/src/com/massivecraft/factions/integration/venturechat/IntegrationVentureChat.java deleted file mode 100644 index b3da2c2f..00000000 --- a/src/com/massivecraft/factions/integration/venturechat/IntegrationVentureChat.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.massivecraft.factions.integration.venturechat; - -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.Integration; - -public class IntegrationVentureChat extends Integration -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static IntegrationVentureChat i = new IntegrationVentureChat(); - public static IntegrationVentureChat get() { return i; } - private IntegrationVentureChat() - { - this.setPluginName("VentureChat"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public Engine getEngine() - { - return EngineVentureChat.get(); - } - -} diff --git a/src/com/massivecraft/factions/integration/worldguard/EngineWorldGuard.java b/src/com/massivecraft/factions/integration/worldguard/EngineWorldGuard.java deleted file mode 100644 index fd8f7198..00000000 --- a/src/com/massivecraft/factions/integration/worldguard/EngineWorldGuard.java +++ /dev/null @@ -1,127 +0,0 @@ -package com.massivecraft.factions.integration.worldguard; - -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MFlag; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.event.EventFactionsChunksChange; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.ps.PS; -import com.sk89q.worldedit.bukkit.BukkitWorld; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldguard.LocalPlayer; -import com.sk89q.worldguard.WorldGuard; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.protection.managers.RegionManager; -import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion; -import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public class EngineWorldGuard extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineWorldGuard i = new EngineWorldGuard(); - public static EngineWorldGuard get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void setActiveInner(boolean active) - { - - } - - // -------------------------------------------- // - // LISTENER - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void checkForRegion(EventFactionsChunksChange event) - { - // Skip checks if the configuration has worldguardCheckEnabled disabled - if ( ! MConf.get().worldguardCheckEnabled) return; - - // Permanent Factions should not apply this rule - if (event.getNewFaction().getFlag(MFlag.ID_PERMANENT)) return; - - MPlayer mplayer = event.getMPlayer(); - Player player = mplayer.getPlayer(); - - // Only do this for players - if (player == null) return; - - LocalPlayer wrapperPlayer = WorldGuardPlugin.inst() .wrapPlayer(player); - - if ( ! MConf.get().worldguardCheckWorldsEnabled.contains(player)) return; - - // For overriders don't bother checking - if (mplayer.isOverriding()) return; - - for (PS chunk : event.getChunks()) - { - // Grab any regions in the chunk - final List regions = this.getProtectedRegionsFor(chunk); - - // Ensure there are actually regions to go over - if (regions == null || regions.isEmpty()) continue; - - for (ProtectedRegion region : regions) - { - // Ensure it's not the global region, and check if they're a member - if (region instanceof GlobalProtectedRegion || region.isMember(wrapperPlayer)) continue; - - // Check for a permission - can't use Perm enum for this - if (player.hasPermission("factions.allowregionclaim." + region.getId())) continue; - - // No permission, notify player and stop claiming - mplayer.msg("You cannot claim the chunk at %s, %s as there is a region in the way.", chunk.getChunkX(), chunk.getChunkZ()); - - event.setCancelled(true); - return; - } - } - } - - // -------------------------------------------- // - // UTIL - // -------------------------------------------- // - - public List getProtectedRegionsFor(PS ps) - { - // Find overlaps in the chunk - int minChunkX = ps.getChunkX() << 4; - int minChunkZ = ps.getChunkZ() << 4; - int maxChunkX = minChunkX + 15; - int maxChunkZ = minChunkZ + 15; - - int worldHeight = ps.asBukkitWorld().getMaxHeight(); - - BlockVector3 minChunk = BlockVector3.at(minChunkX, 0, minChunkZ); - BlockVector3 maxChunk = BlockVector3.at(maxChunkX, worldHeight, maxChunkZ); - - RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(new BukkitWorld(ps.asBukkitWorld())); - - String regionName = "factions_temp"; - ProtectedCuboidRegion region = new ProtectedCuboidRegion(regionName, minChunk, maxChunk); - - Map regionMap = regionManager.getRegions(); - List regionList = new ArrayList<>(regionMap.values()); - - // Let's find what we've overlapped - List overlapRegions = region.getIntersectingRegions(regionList); - - return overlapRegions; - } - -} diff --git a/src/com/massivecraft/factions/integration/worldguard/IntegrationWorldGuard.java b/src/com/massivecraft/factions/integration/worldguard/IntegrationWorldGuard.java deleted file mode 100644 index e2b42d8f..00000000 --- a/src/com/massivecraft/factions/integration/worldguard/IntegrationWorldGuard.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.massivecraft.factions.integration.worldguard; - -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.Integration; - -public class IntegrationWorldGuard extends Integration -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static IntegrationWorldGuard i = new IntegrationWorldGuard(); - public static IntegrationWorldGuard get() { return i; } - private IntegrationWorldGuard() - { - this.setPluginName("WorldGuard"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public Engine getEngine() - { - return EngineWorldGuard.get(); - } - -} diff --git a/src/com/massivecraft/factions/mixin/PowerMixin.java b/src/com/massivecraft/factions/mixin/PowerMixin.java deleted file mode 100644 index 8157e249..00000000 --- a/src/com/massivecraft/factions/mixin/PowerMixin.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.massivecraft.factions.mixin; - -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.mixin.Mixin; - -public class PowerMixin extends Mixin -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static PowerMixin d = new PowerMixin(); - private static PowerMixin i = d; - public static PowerMixin get() { return i; } - - // -------------------------------------------- // - // METHODS - // -------------------------------------------- // - - public double getMaxUniversal(MPlayer mplayer) - { - return this.getMax(mplayer); - } - - public double getMax(MPlayer mplayer) - { - return MConf.get().powerMax + mplayer.getPowerBoost(); - } - - public double getMin(MPlayer mplayer) - { - return MConf.get().powerMin; - } - - public double getPerHour(MPlayer mplayer) - { - return MConf.get().powerPerHour; - } - - public double getPerDeath(MPlayer mplayer) - { - return MConf.get().powerPerDeath; - } - -} diff --git a/src/com/massivecraft/factions/predicate/PredicateCommandSenderFaction.java b/src/com/massivecraft/factions/predicate/PredicateCommandSenderFaction.java deleted file mode 100644 index 59464a75..00000000 --- a/src/com/massivecraft/factions/predicate/PredicateCommandSenderFaction.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.massivecraft.factions.predicate; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.util.MUtil; -import org.bukkit.command.CommandSender; - -import java.io.Serializable; -import java.util.function.Predicate; - -public class PredicateCommandSenderFaction implements Predicate, Serializable -{ - private static final long serialVersionUID = 1L; - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final String factionId; - public String getFactionId() { return this.factionId; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public PredicateCommandSenderFaction(Faction faction) - { - this.factionId = faction.getId(); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public boolean test(CommandSender sender) - { - if (MUtil.isntSender(sender)) return false; - - MPlayer mplayer = MPlayer.get(sender); - return this.factionId.equals(mplayer.getFaction().getId()); - } - -} diff --git a/src/com/massivecraft/factions/predicate/PredicateMPlayerRank.java b/src/com/massivecraft/factions/predicate/PredicateMPlayerRank.java deleted file mode 100644 index 504570fd..00000000 --- a/src/com/massivecraft/factions/predicate/PredicateMPlayerRank.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.massivecraft.factions.predicate; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.entity.Rank; - -import java.util.function.Predicate; - -public class PredicateMPlayerRank implements Predicate -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final Rank rank; - public Rank getRank() { return this.rank; } - - // -------------------------------------------- // - // INSTANCE AND CONTRUCT - // -------------------------------------------- // - - public static PredicateMPlayerRank get(Rank rank) { return new PredicateMPlayerRank(rank); } - public PredicateMPlayerRank(Rank rank) - { - this.rank = rank; - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public boolean test(MPlayer mplayer) - { - if (mplayer == null) return false; - Faction faction = mplayer.getFaction(); - if (!faction.hasRank(this.getRank())) throw new IllegalStateException("rank: " + rank.getId() + " player:" + mplayer.getId()); - return mplayer.getRank() == this.rank; - } -} diff --git a/src/com/massivecraft/factions/task/TaskFlagPermCreate.java b/src/com/massivecraft/factions/task/TaskFlagPermCreate.java deleted file mode 100644 index 3bc4486b..00000000 --- a/src/com/massivecraft/factions/task/TaskFlagPermCreate.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.massivecraft.factions.task; - -import com.massivecraft.factions.entity.MFlag; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.massivecore.ModuloRepeatTask; -import com.massivecraft.massivecore.util.TimeUnit; - -public class TaskFlagPermCreate extends ModuloRepeatTask -{ - // -------------------------------------------- // - // CONSTANTS - // -------------------------------------------- // - - private static final long MILLIS_INTERVAL = TimeUnit.MILLIS_PER_SECOND * 3; - - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static TaskFlagPermCreate i = new TaskFlagPermCreate(); - public static TaskFlagPermCreate get() { return i; } - - public TaskFlagPermCreate() - { - super(MILLIS_INTERVAL); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void setDelayMillis(long delayMillis) - { - // No operation - } - - @Override - public void invoke(long now) - { - MPerm.getAll(); - MFlag.getAll(); - } - -} diff --git a/src/com/massivecraft/factions/task/TaskPlayerPowerUpdate.java b/src/com/massivecraft/factions/task/TaskPlayerPowerUpdate.java deleted file mode 100644 index 379cad88..00000000 --- a/src/com/massivecraft/factions/task/TaskPlayerPowerUpdate.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.massivecraft.factions.task; - -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.MPlayer; -import com.massivecraft.factions.event.EventFactionsPowerChange; -import com.massivecraft.factions.event.EventFactionsPowerChange.PowerChangeReason; -import com.massivecraft.massivecore.ModuloRepeatTask; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.MUtil; -import com.massivecraft.massivecore.util.TimeUnit; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -public class TaskPlayerPowerUpdate extends ModuloRepeatTask -{ - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static TaskPlayerPowerUpdate i = new TaskPlayerPowerUpdate(); - public static TaskPlayerPowerUpdate get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public long getDelayMillis() - { - // The interval is determined by the MConf rather than being set with setDelayMillis. - return TimeUnit.MILLIS_PER_MINUTE; - } - - @Override - public void invoke(long now) - { - long millis = this.getDelayMillis(); - MFlag flagPowerGain = MFlag.getFlagPowergain(); - - // For each player ... - for (Player player : Bukkit.getOnlinePlayers()) - { - // ... that is a living player ... - if (MUtil.isntPlayer(player)) continue; - if (player.isDead()) continue; - - // ... in a faction territory that permits power gain ... - Faction faction = BoardColl.get().getFactionAt(PS.valueOf(player)); - if (!faction.getFlag(flagPowerGain)) return; - - // ... in a world that permits power gain ... - if (!MConf.get().worldsPowerGainEnabled.contains(player)) return; - - MPlayer mplayer = MPlayer.get(player); - - // ... calculate new power ... - double newPower = mplayer.getPower() + mplayer.getPowerPerHour() * millis / TimeUnit.MILLIS_PER_HOUR; - - // ... and if other plugins don't object ... - EventFactionsPowerChange event = new EventFactionsPowerChange(null, mplayer, PowerChangeReason.TIME, newPower); - event.run(); - if (event.isCancelled()) continue; - - // ... set the new power for the player. - newPower = event.getNewPower(); - mplayer.setPower(newPower); - } - } - -} diff --git a/src/com/massivecraft/factions/task/TaskTax.java b/src/com/massivecraft/factions/task/TaskTax.java deleted file mode 100644 index ef23f300..00000000 --- a/src/com/massivecraft/factions/task/TaskTax.java +++ /dev/null @@ -1,225 +0,0 @@ -package com.massivecraft.factions.task; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.FactionColl; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MFlag; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.entity.MPlayerColl; -import com.massivecraft.factions.event.EventFactionsMembershipChange; -import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; -import com.massivecraft.factions.integration.Econ; -import com.massivecraft.massivecore.Couple; -import com.massivecraft.massivecore.Task; -import com.massivecraft.massivecore.collections.MassiveMap; -import com.massivecraft.massivecore.mixin.MixinMessage; -import com.massivecraft.massivecore.money.Money; -import com.massivecraft.massivecore.util.IdUtil; -import com.massivecraft.massivecore.util.TimeUnit; - -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -public class TaskTax extends Task -{ - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static TaskTax i = new TaskTax(); - public static TaskTax get() { return i; } - public TaskTax() - { - // Just check once a minute - this.setPeriod(60L * 20L); - - this.setMustBeTaskServer(true); - this.setLoggingTimeSpent(true); - - this.addCondition(Econ::isEnabled); - this.addCondition(() -> MConf.get().taxEnabled); - } - - // -------------------------------------------- // - // OVERRIDE: TASK - // -------------------------------------------- // - - @Override - public long getPreviousMillis() - { - return MConf.get().taxTaskLastMillis; - } - @Override - public void setPreviousMillis(long millis) - { - MConf.get().taxTaskLastMillis = millis; - MConf.get().changed(); - } - - @Override - public long getPeriodMillis() - { - return MConf.get().taxTaskPeriodMillis; - } - @Override - public long getOffsetMillis() - { - return MConf.get().taxTaskInvocationOffsetMillis; - } - - // -------------------------------------------- // - // OVERRIDE: RUNNABLE - // -------------------------------------------- // - - @Override - public void invoke(long now) - { - taxPlayers(now); - taxFactions(now); - } - - public void taxPlayers(long now) - { - MixinMessage.get().msgAll("Taxation of players starting."); - long start = System.nanoTime(); - - // Tax players and track how many players are taxed and how much - Map> faction2tax = new MassiveMap<>(); - - List> taxes = MPlayerColl.get().getAll().stream() - .filter(mp -> shouldBeTaxed(now, mp)) - .map(mp -> new Couple<>(mp, getTax(mp))) - .filter(e -> e.getValue() != 0D) - .collect(Collectors.toList()); - - /*String debug = taxes.stream() - .map(c -> c.getFirst().getName() + ": " + c.getSecond()) - .reduce((s1, s2) -> s1 + "\n" + s2).orElse("No players pay tax."); - MixinMessage.get().messageAll(debug);*/ - - // Pay the highest taxes first. - // That way taxes are collected before wages are given. - Comparator> comparator = Comparator.comparingDouble(Couple::getSecond); - comparator = comparator.reversed(); - taxes.sort(comparator); - - for (Couple couple : taxes) - { - double tax = doTaxPlayer(couple); - if (tax == 0D) continue; - - // Log data - Faction faction = couple.getFirst().getFaction(); - Couple newCouple = new Couple<>(1, tax); - faction2tax.merge(faction, newCouple, - (c1, c2) -> new Couple<>(c1.getFirst() + c2.getFirst(), c1.getSecond() + c2.getSecond())); - } - - // Inform factions - faction2tax.forEach(this::informFactionOfPlayerTax); - - // Inform of taxation complete - int count = faction2tax.values().stream().mapToInt(Couple::getFirst).sum(); - MixinMessage.get().msgAll("Taxation of players complete. %d players were taxed.", count); - - long end = System.nanoTime(); - double elapsedSeconds = (end - start) / 1000_000_000D; - MixinMessage.get().msgAll("Took %.2f seconds.", elapsedSeconds); - } - - private double getTax(MPlayer mplayer) - { - return mplayer.getFaction().getTaxForPlayer(mplayer); - } - - private double doTaxPlayer(Couple couple) - { - return doTaxPlayer(couple.getFirst(), couple.getSecond()); - } - - private double doTaxPlayer(MPlayer mplayer, double tax) - { - Faction faction = mplayer.getFaction(); - boolean success = Econ.moveMoney(mplayer, faction, null, tax, "Factions Tax"); - if (success) - { - // Inform player - if (mplayer.isOnline()) - { - if (tax > 0) mplayer.msg("You were just taxed %s by your faction.", Money.format(tax)); // Tax - else mplayer.msg("You were just paid %s by your faction.", Money.format(-tax)); // Salary - } - - return tax; - } - else if (tax > 0) // If a tax - { - faction.msg("%s couldn't afford tax!", mplayer.describeTo(faction)); - boolean kicked = tryKickPlayer(mplayer); - if (!kicked) faction.msg("%s could not afford tax.", mplayer.describeTo(faction)); - return 0D; - } - else // If a salary - { - faction.msg("Your faction couldn't afford to pay %s to %s.", Money.format(-tax), mplayer.describeTo(faction)); - return 0D; - } - } - - private boolean shouldBeTaxed(long now, MPlayer mplayer) - { - // Must have faction - if ( ! mplayer.hasFaction()) return false; - - // Must have been online recently - long offlinePeriod; - if (mplayer.isOnline()) offlinePeriod = 0; - else offlinePeriod = now - mplayer.getLastActivityMillis(); - - int inactiveDays = MConf.get().taxInactiveDays; - if (inactiveDays > 0 && offlinePeriod > inactiveDays * TimeUnit.MILLIS_PER_DAY) return false; - - return true; - } - - private boolean tryKickPlayer(MPlayer mplayer) - { - Faction faction = mplayer.getFaction(); - if (mplayer.getRank().isLeader()) return false; - if ( ! faction.getFlag(MFlag.getFlagTaxKick())) return false; - - EventFactionsMembershipChange event = new EventFactionsMembershipChange(null, mplayer, FactionColl.get().getNone(), MembershipChangeReason.KICK); - event.run(); - if (event.isCancelled()) return false; - - faction.msg("%s could not afford tax and was kicked from your faction.", mplayer.describeTo(faction)); - - if (MConf.get().logFactionKick) - { - MPlayer console = MPlayer.get(IdUtil.CONSOLE_ID); - Factions.get().log("%s could not afford tax and was kicked from %s.", mplayer.describeTo(console), faction.describeTo(console)); - } - - // Apply - faction.uninvite(mplayer); - mplayer.resetFactionData(); - - return true; - } - - private void informFactionOfPlayerTax(Faction faction, Couple couple) - { - faction.msg("A total of %d players in your faction were taxed for a total of %s.", couple.getFirst(), Money.format(couple.getSecond())); - } - - public void taxFactions(long now) - { - // TODO - String msg = "For the time being factions themselves cannot be taxed. This feature will be added at a later date."; - MixinMessage.get().msgOne(IdUtil.CONSOLE_ID, msg); - } - -} diff --git a/src/com/massivecraft/factions/util/AsciiCompass.java b/src/com/massivecraft/factions/util/AsciiCompass.java deleted file mode 100644 index 58e5d128..00000000 --- a/src/com/massivecraft/factions/util/AsciiCompass.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.massivecraft.factions.util; - -import com.massivecraft.massivecore.collections.MassiveList; - -import java.util.List; - -import static com.massivecraft.factions.util.AsciiCompassDirection.E; -import static com.massivecraft.factions.util.AsciiCompassDirection.N; -import static com.massivecraft.factions.util.AsciiCompassDirection.NE; -import static com.massivecraft.factions.util.AsciiCompassDirection.NONE; -import static com.massivecraft.factions.util.AsciiCompassDirection.NW; -import static com.massivecraft.factions.util.AsciiCompassDirection.S; -import static com.massivecraft.factions.util.AsciiCompassDirection.SE; -import static com.massivecraft.factions.util.AsciiCompassDirection.SW; -import static com.massivecraft.factions.util.AsciiCompassDirection.W; - -public class AsciiCompass -{ - // -------------------------------------------- // - // COMPASS - // -------------------------------------------- // - - public static List getAsciiCompass(double degrees) - { - return getAsciiCompass(AsciiCompassDirection.getByDegrees(degrees)); - } - - private static List getAsciiCompass(AsciiCompassDirection directionFacing) - { - // Create - List ret = new MassiveList<>(); - - // Fill - ret.add(visualizeRow(directionFacing, NW, N, NE)); - ret.add(visualizeRow(directionFacing, W, NONE, E)); - ret.add(visualizeRow(directionFacing, SW, S, SE)); - - // Return - return ret; - } - - // -------------------------------------------- // - // VISUALIZE ROW - // -------------------------------------------- // - - private static String visualizeRow(AsciiCompassDirection directionFacing, AsciiCompassDirection... cardinals) - { - // Catch - if (cardinals == null) throw new NullPointerException("cardinals"); - - // Create - StringBuilder ret = new StringBuilder(cardinals.length); - - // Fill - for (AsciiCompassDirection asciiCardinal : cardinals) - { - ret.append(asciiCardinal.visualize(directionFacing)); - } - - // Return - return ret.toString(); - } - -} diff --git a/src/com/massivecraft/factions/util/AsciiCompassDirection.java b/src/com/massivecraft/factions/util/AsciiCompassDirection.java deleted file mode 100644 index bc5df38b..00000000 --- a/src/com/massivecraft/factions/util/AsciiCompassDirection.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.massivecraft.factions.util; - -import org.bukkit.ChatColor; - -public enum AsciiCompassDirection -{ - // -------------------------------------------- // - // ENUM - // -------------------------------------------- // - - N('N'), - NE('/'), - E('E'), - SE('\\'), - S('S'), - SW('/'), - W('W'), - NW('\\'), - NONE('+'), - - // END OF LIST - ; - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final char asciiChar; - public char getAsciiChar() { return this.asciiChar; } - - // -------------------------------------------- // - // CONSTANTS - // -------------------------------------------- // - - public static final ChatColor ACTIVE = ChatColor.RED; - public static final ChatColor INACTIVE = ChatColor.YELLOW; - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - AsciiCompassDirection(final char asciiChar) - { - this.asciiChar = asciiChar; - } - - // -------------------------------------------- // - // VISUALIZE - // -------------------------------------------- // - - public String visualize(AsciiCompassDirection directionFacing) - { - boolean isFacing = this.isFacing(directionFacing); - ChatColor color = this.getColor(isFacing); - - return color.toString() + this.getAsciiChar(); - } - - private boolean isFacing(AsciiCompassDirection directionFacing) - { - return this == directionFacing; - } - - private ChatColor getColor(boolean active) - { - return active ? ACTIVE : INACTIVE; - } - - // -------------------------------------------- // - // GET BY DEGREES - // -------------------------------------------- // - - public static AsciiCompassDirection getByDegrees(double degrees) - { - // Prepare - // The conversion from bukkit to usable degrees is (degrees - 180) % 360 - // But we reduced the 180 to 157 (-23) because it makes the math easier that follows. - degrees = (degrees - 157) % 360; - if (degrees < 0) degrees += 360; - - // Get ordinal - int ordinal = (int) Math.floor(degrees / 45); - - // Return - return AsciiCompassDirection.values()[ordinal]; - } - -} diff --git a/src/com/massivecraft/factions/util/AsciiMap.java b/src/com/massivecraft/factions/util/AsciiMap.java deleted file mode 100644 index f98f9011..00000000 --- a/src/com/massivecraft/factions/util/AsciiMap.java +++ /dev/null @@ -1,271 +0,0 @@ -package com.massivecraft.factions.util; - -import com.massivecraft.factions.RelationParticipator; -import com.massivecraft.factions.TerritoryAccess; -import com.massivecraft.factions.entity.Board; -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.massivecore.collections.MassiveList; -import com.massivecraft.massivecore.mson.Mson; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.ps.PSFormatHumanSpace; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.ChatColor; -import org.bukkit.GameRule; -import org.bukkit.World; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import static com.massivecraft.massivecore.mson.Mson.*; - -public class AsciiMap -{ - // -------------------------------------------- // - // CONSTANTS - // -------------------------------------------- // - - private static final char[] FACTION_KEY_CHARS = "\\/#?笣$%=&^ABCDEFGHJKLMNOPQRSTUVWXYZÄÖÜÆØÅ1234567890abcdeghjmnopqrsuvwxyÿzäöüæøåâêîûô".toCharArray(); - private static final int KEY_SIZE = FACTION_KEY_CHARS.length; - - // Map Heights & Widths - private static final int WIDTH = 49; - private static final int WIDTH_HALF = WIDTH / 2; - private static final int HEIGHT = 8; - private static final int HEIGHT_HALF = HEIGHT / 2; - private static final int HEIGHT_EXTRA = 17; - private static final int HEIGHT_EXTRA_HALF = HEIGHT_EXTRA / 2; - - private static final String TITLE_FORMAT = "(%d,%d) %s"; - private static final String TITLE_FORMAT_NO_COORDS = "%s"; - private static final Mson KEY_MIDDLE = mson("+").color(ChatColor.AQUA); - private static final Mson KEY_WILDERNESS = mson("-").color(ChatColor.GRAY).tooltip(); - private static final Mson KEY_OVERFLOW = mson("-").style(ChatColor.MAGIC).add(mson("").style(ChatColor.RESET)); - private static final Mson OVERFLOW_MESSAGE = Mson.format("%s: Too Many Factions (>%d) on this Map.", KEY_OVERFLOW.toPlain(true), FACTION_KEY_CHARS.length); - private static final Mson LEGEND_SEPARATOR = mson(": "); - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final RelationParticipator relationParticipator; - public RelationParticipator getRelationParticipator() { return this.relationParticipator; } - - private final double angle; - public double getAngle() { return this.angle; } - - private final PS center; - public PS getCenter() { return this.center; } - - private final PS topLeft; - public PS getTopLeft() { return this.topLeft; } - - private final Board board; - public Board getBoard() { return this.board; } - - private final Map factionChars = new HashMap<>(); - public Map getFactionChars() { return this.factionChars; } - - private final int height; - private int getHeight() { return this.height; } - - private final int heightHalf; - private int getHeightHalf() { return this.heightHalf; } - - private boolean overflown = false; - public boolean isOverflown() { return this.overflown; } - public void setOverflown(boolean overflown) { this.overflown = overflown; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - @Deprecated - public AsciiMap(RelationParticipator relationParticipator, Player player, boolean extraHeight) - { - this(relationParticipator, PS.valueOf(player), extraHeight); - } - - public AsciiMap(RelationParticipator relationParticipator, PS ps, boolean extraHeight) - { - this.relationParticipator = relationParticipator; - this.angle = ps.getYaw(); - this.center = ps.getChunk(true); - this.height = extraHeight ? HEIGHT_EXTRA : HEIGHT; - this.heightHalf = extraHeight ? HEIGHT_EXTRA_HALF : HEIGHT_HALF; - this.topLeft = this.center.plusChunkCoords(-WIDTH_HALF, -this.heightHalf); - this.board = BoardColl.get().get(this.center.getWorld()); - } - - // -------------------------------------------- // - // RENDER - // -------------------------------------------- // - - public List render() - { - // Create - List ret = new ArrayList<>(); - - // Fill - ret.add(this.getTitle()); - ret.addAll(this.getLines()); - ret.add(this.getFactionLegend()); - - // Return - return ret; - } - - private Mson getTitle() - { - // Prepare - PS chunk = this.getCenter(); - Faction faction = this.getBoard().getFactionAt(chunk); - int chunkX = chunk.getChunkX(); - int chunkZ = chunk.getChunkZ(); - String factionName = faction.getName(this.getRelationParticipator()); - - boolean showCoords = showChunkCoords(chunk); - - String title; - if (showCoords) title = String.format(TITLE_FORMAT, chunkX, chunkZ, factionName); - else title = String.format(TITLE_FORMAT_NO_COORDS, factionName); - - // Titleize - return Txt.titleize(title); - } - - private List getLines() - { - // Create - List ret = new MassiveList<>(); - List asciiCompass = AsciiCompass.getAsciiCompass(this.getAngle()); - - // Fill - for (int deltaZ = 0; deltaZ < this.getHeight(); deltaZ++) - { - ret.add(this.getLine(deltaZ, asciiCompass)); - } - - // Return - return ret; - } - - private Mson getLine(int deltaZ, List asciiCompass) - { - // Create - boolean isCompassLine = deltaZ < asciiCompass.size(); - int startX = isCompassLine ? 3 : 0; - Mson ret = isCompassLine ? mson(asciiCompass.get(deltaZ)) : EMPTY; - Mson factionChar; - - // Fill - for (int deltaX = startX; deltaX < WIDTH; deltaX++) - { - boolean isMiddle = deltaX == WIDTH_HALF && deltaZ == this.getHeightHalf(); - factionChar = isMiddle ? KEY_MIDDLE : this.getCharChunk(deltaZ, deltaX); - ret = ret.add(factionChar); - } - - // Return - return ret; - } - - private Mson getCharChunk(int deltaZ, int deltaX) - { - PS herePs = this.getTopLeft().plusChunkCoords(deltaX, deltaZ); - Faction hereFaction = this.getBoard().getFactionAt(herePs); - - String chunkName = this.getBoard().getTerritoryAccessAt(herePs).getChunkName(); - Mson charFaction = getCharFaction(hereFaction); - String tooltip = charFaction.getTooltip(); - if (chunkName != null) tooltip += "\n" + ChatColor.WHITE + chunkName; - Mson charChunk = charFaction.tooltip(tooltip); - return charChunk; - } - - private Mson getCharFaction(Faction faction) - { - // Calculate overflow - int index = this.getFactionChars().size(); - if (!this.isOverflown() && index >= KEY_SIZE) this.setOverflown(true); - - Mson factionChar = this.getFactionChars().get(faction); - - // Is Wilderness or known? - if (faction.isNone()) return KEY_WILDERNESS; - if (factionChar != null) return factionChar; - - // Create descriptions - ChatColor color = faction.getColorTo(this.getRelationParticipator()); - String name = faction.getName(this.getRelationParticipator()); - String tooltip = color.toString() + name; - - // Is overflown? - if (this.isOverflown()) return KEY_OVERFLOW.tooltip(tooltip); - - // Create new one - factionChar = mson(String.valueOf(FACTION_KEY_CHARS[index])).color(color); - factionChar = factionChar.tooltip(tooltip); - - // Store for later use - this.getFactionChars().put(faction, factionChar); - - // Return - return factionChar; - } - - private Mson getFactionLegend() - { - // Create - List ret = new MassiveList<>(); - - // Fill - for (Entry entry : this.getFactionChars().entrySet()) - { - Faction here = entry.getKey(); - Mson factionChar = entry.getValue(); - ChatColor color = here.getColorTo(this.getRelationParticipator()); - - ret.add(mson(factionChar, LEGEND_SEPARATOR, here.getName()).color(color)); - } - - // Add overflown message if needed - if (this.isOverflown()) ret.add(OVERFLOW_MESSAGE); - - // Return - return Mson.implode(ret, SPACE); - } - - public static boolean showChunkCoords(PS chunk) - { - return showChunkCoords(chunk.asBukkitWorld(true)); - } - - public static boolean showChunkCoords(World w) - { - return ! w.getGameRuleValue(GameRule.REDUCED_DEBUG_INFO); - } - - public static String getChunkDesc(PS chunk) - { - return showChunkCoords(chunk) ? " at " + chunk.toString(PSFormatHumanSpace.get()) : ""; - } - - public static String getChunkDescWithName(PS chunk, TerritoryAccess ta) - { - String name = ta.getChunkName(); - if (name == null) return getChunkDesc(chunk); - - String ret = Txt.parse(" at %s", name); - if (showChunkCoords(chunk)) - { - ret += Txt.parse(" (%s)", chunk.toString(PSFormatHumanSpace.get())); - } - return ret; - } - -} diff --git a/src/com/massivecraft/factions/util/EnumerationUtil.java b/src/com/massivecraft/factions/util/EnumerationUtil.java deleted file mode 100644 index 3abbe52e..00000000 --- a/src/com/massivecraft/factions/util/EnumerationUtil.java +++ /dev/null @@ -1,321 +0,0 @@ -package com.massivecraft.factions.util; - -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.massivecore.collections.BackstringSet; -import org.bukkit.Material; -import org.bukkit.entity.EntityType; - -public class EnumerationUtil -{ - // -------------------------------------------- // - // MATERIAL EDIT ON INTERACT - // -------------------------------------------- // - - public static final BackstringSet MATERIALS_EDIT_ON_INTERACT = new BackstringSet<>(Material.class, - "REPEATER", // Minecraft 1.? - "NOTE_BLOCK", // Minecraft 1.? - "CAULDRON", // Minecraft 1.? - "FARMLAND", // Minecraft 1.? - "DAYLIGHT_DETECTOR", // Minecraft 1.5 - "COMPARATOR", // Minecraft 1.? - "COMPOSTER", // Minecraft 1.14 - "LECTERN", // Minecraft 1.14 - "BEEHIVE", // Minecraft 1.15 - "BEE_NEST", // Minecraft 1.5 - "FLOWER_POT", // Minecraft 1.? - - // The various flower pots, they had to make each one a different material -.- - "POTTED_ACACIA_SAPLING", // Minecraft 1.13 - "POTTED_ALLIUM", // Minecraft 1.13 - "POTTED_AZURE_BLUET", // Minecraft 1.13 - "POTTED_BAMBOO", // Minecraft 1.13 - "POTTED_BIRCH_SAPLING", // Minecraft 1.13 - "POTTED_BLUE_ORCHID", // Minecraft 1.13 - "POTTED_BROWN_MUSHROOM", // Minecraft 1.13 - "POTTED_CACTUS", // Minecraft 1.13 - "POTTED_CACTUS", // Minecraft 1.13 - "POTTED_CORNFLOWER", // Minecraft 1.13 - "POTTED_DANDELION", // Minecraft 1.13 - "POTTED_DARK_OAK_SAPLING", // Minecraft 1.13 - "POTTED_DEAD_BUSH", // Minecraft 1.13 - "POTTED_FERN", // Minecraft 1.13 - "POTTED_JUNGLE_SAPLING", // Minecraft 1.13 - "POTTED_LILY_OF_THE_VALLEY", // Minecraft 1.13 - "POTTED_OAK_SAPLING", // Minecraft 1.13 - "POTTED_ORANGE_TULIP", // Minecraft 1.13 - "POTTED_OXEYE_DAISY", // Minecraft 1.13 - "POTTED_PINK_TULIP", // Minecraft 1.13 - "POTTED_POPPY", // Minecraft 1.13 - "POTTED_RED_MUSHROOM", // Minecraft 1.13 - "POTTED_RED_TULIP", // Minecraft 1.13 - "POTTED_SPRUCE_SAPLING", // Minecraft 1.13 - "POTTED_WHITE_TULIP", // Minecraft 1.13 - "POTTED_WITHER_ROSE", // Minecraft 1.13 - "POTTED_CRIMSON_FUNGUS", // Minecraft 1.16 - "POTTED_CRIMSON_ROOTS", // Minecraft 1.16 - "POTTED_WARPED_FUNGUS", // Minecraft 1.16 - "POTTED_WARPED_ROOTS" // Minecraft 1.16 - ); - - public static boolean isMaterialEditOnInteract(Material material) - { - return MATERIALS_EDIT_ON_INTERACT.contains(material) || MConf.get().materialsEditOnInteract.contains(material); - } - - // -------------------------------------------- // - // MATERIAL EDIT TOOLS - // -------------------------------------------- // - - public static final BackstringSet MATERIALS_EDIT_TOOL = new BackstringSet<>(Material.class, - "FIRE_CHARGE", // Minecraft 1.? - "FLINT_AND_STEEL", // Minecraft 1.? - "BUCKET", - "WATER_BUCKET", // Minecraft 1.? - "LAVA_BUCKET",// Minecraft 1.? - "COD_BUCKET",// Minecraft 1.13 - "PUFFERFISH_BUCKET", // Minecraft 1.13 - "SALMON_BUCKET", // Minecraft 1.13 - "TROPICAL_FISH_BUCKET", // Minecraft 1.13 - "ARMOR_STAND", // Minecraft 1.8 - "END_CRYSTAL", // Minecraft 1.10 - - // The duplication bug found in Spigot 1.8 protocol patch - // https://github.com/MassiveCraft/Factions/issues/693 - "CHEST", // Minecraft 1.? // TODO why chest? - "SIGN_POST", // Minecraft 1.? - "TRAPPED_CHEST", // Minecraft 1.? - "SIGN", // Minecraft 1.? - "WOOD_DOOR", // Minecraft 1.? - "IRON_DOOR", // Minecraft 1.? - "BONE_MEAL" // Minecraft 1.? - ); - - public static boolean isMaterialEditTool(Material material) - { - return MATERIALS_EDIT_TOOL.contains(material) || MConf.get().materialsEditTools.contains(material); - } - - // -------------------------------------------- // - // MATERIAL DOOR - // -------------------------------------------- // - - // Interacting with these materials placed in the terrain results in door toggling. - public static final BackstringSet MATERIALS_DOOR = new BackstringSet<>(Material.class, - "OAK_DOOR", - "OAK_TRAPDOOR", - "OAK_FENCE_GATE", - "ACACIA_DOOR", - "ACACIA_TRAPDOOR", - "ACACIA_FENCE_GATE", - "BIRCH_DOOR", - "BIRCH_TRAPDOOR", - "BIRCH_FENCE_GATE", - "DARK_OAK_DOOR", - "DARK_OAK_TRAPDOOR", - "DARK_OAK_FENCE_GATE", - "JUNGLE_DOOR", - "JUNGLE_TRAPDOOR", - "JUNGLE_FENCE_GATE", - "SPRUCE_DOOR", - "SPRUCE_TRAPDOOR", - "SPRUCE_FENCE_GATE", - - // Minecraft 1.16 - "CRIMSON_DOOR", - "CRIMSON_TRAPDOOR", - "CRIMSON_FENCE_GATE", - "WARPED_DOOR", - "WARPED_TRAPDOOR", - "WARPED_FENCE_GATE" - ); - - public static boolean isMaterialDoor(Material material) - { - return MATERIALS_DOOR.contains(material) || MConf.get().materialsDoor.contains(material); - } - - // -------------------------------------------- // - // MATERIAL CONTAINER - // -------------------------------------------- // - - public static final BackstringSet MATERIALS_CONTAINER = new BackstringSet<>(Material.class, - "DISPENSER", - "CHEST", - "TRAPPED_CHEST", - "FURNACE", - "JUKEBOX", - "BREWING_STAND", - "ENCHANTING_TABLE", - "ANVIL", - "CHIPPED_ANVIL", - "DAMAGED_ANVIL", - "BEACON", - "HOPPER", - "DROPPER", - "BARREL", // Minecraft 1.14 - "BLAST_FURNACE", // Minecraft 1.14 - "SMOKER", // 1.14 - "RESPAWN_ANCHOR", // 1.16 - - // The various shulker boxes, they had to make each one a different material -.- - "SHULKER_BOX", - "BLACK_SHULKER_BOX", - "BLUE_SHULKER_BOX", - "BROWN_SHULKER_BOX", - "CYAN_SHULKER_BOX", - "GRAY_SHULKER_BOX", - "GREEN_SHULKER_BOX", - "LIGHT_BLUE_SHULKER_BOX", - "LIGHT_GRAY_SHULKER_BOX", - "LIME_SHULKER_BOX", - "MAGENTA_SHULKER_BOX", - "ORANGE_SHULKER_BOX", - "PINK_SHULKER_BOX", - "PURPLE_SHULKER_BOX", - "RED_SHULKER_BOX", - "SILVER_SHULKER_BOX", // Changed name to light gray, I think. Kept for backwards compatibility - "WHITE_SHULKER_BOX", - "YELLOW_SHULKER_BOX" - ); - - public static boolean isMaterialContainer(Material material) - { - return MATERIALS_CONTAINER.contains(material) || MConf.get().materialsContainer.contains(material); - } - - // -------------------------------------------- // - // ENTITY TYPE EDIT ON INTERACT - // -------------------------------------------- // - - // Interacting with these entities results in an edit. - public static final BackstringSet ENTITY_TYPES_EDIT_ON_INTERACT = new BackstringSet<>(EntityType.class, - "ITEM_FRAME", // Minecraft 1.? - "ARMOR_STAND" // Minecraft 1.8 - ); - - public static boolean isEntityTypeEditOnInteract(EntityType entityType) - { - return ENTITY_TYPES_EDIT_ON_INTERACT.contains(entityType) || MConf.get().entityTypesEditOnInteract.contains(entityType); - } - - // -------------------------------------------- // - // ENTITY TYPE EDIT ON DAMAGE - // -------------------------------------------- // - - // Damaging these entities results in an edit. - public static final BackstringSet ENTITY_TYPES_EDIT_ON_DAMAGE = new BackstringSet<>(EntityType.class, - "ITEM_FRAME", // Minecraft 1.? - "ARMOR_STAND", // Minecraft 1.8 - "ENDER_CRYSTAL" // Minecraft 1.10 - ); - - public static boolean isEntityTypeEditOnDamage(EntityType entityType) - { - return ENTITY_TYPES_EDIT_ON_DAMAGE.contains(entityType) || MConf.get().entityTypesEditOnDamage.contains(entityType); - } - - // -------------------------------------------- // - // ENTITY TYPE CONTAINER - // -------------------------------------------- // - - public static final BackstringSet ENTITY_TYPES_CONTAINER = new BackstringSet<>(EntityType.class, - "MINECART_CHEST", // Minecraft 1.? - "MINECART_HOPPER" // Minecraft 1.? - ); - - public static boolean isEntityTypeContainer(EntityType entityType) - { - return ENTITY_TYPES_CONTAINER.contains(entityType) || MConf.get().entityTypesContainer.contains(entityType); - } - - // -------------------------------------------- // - // ENTITY TYPE MONSTER - // -------------------------------------------- // - - public static final BackstringSet ENTITY_TYPES_MONSTER = new BackstringSet<>(EntityType.class, - "BLAZE", // Minecraft 1.? - "CAVE_SPIDER", // Minecraft 1.? - "CREEPER", // Minecraft 1.? - "ELDER_GUARDIAN", - "ENDERMAN", // Minecraft 1.? - "ENDERMITE", // Minecraft 1.8 - "ENDER_DRAGON", // Minecraft 1.? - "EVOKER", - "GUARDIAN", // Minecraft 1.8 - "GHAST", // Minecraft 1.? - "GIANT", // Minecraft 1.? - "HUSK", - "MAGMA_CUBE", // Minecraft 1.? - "PIG_ZOMBIE", // Minecraft 1.? - "POLAR_BEAR", // Minecraft 1.10 - "SILVERFISH", // Minecraft 1.? - "SHULKER", // Minecraft 1.10 - "SKELETON", // Minecraft 1.? - "SLIME", // Minecraft 1.? - "SPIDER", // Minecraft 1.? - "STRAY", - "VINDICATOR", - "VEX", - "WITCH", // Minecraft 1.? - "WITHER", // Minecraft 1.? - "WITHER_SKELETON", - "STRAY", // Minecraft 1.? - "ZOMBIE", // Minecraft 1.? - "ZOMBIE_VILLAGER", - "ILLUSIONER", // Minecraft 1.12 - "PHANTOM", // Minecraft 1.13 - "DOLPHIN", // Minecraft 1.13 - "DROWNED", // Minecraft 1.13 - "PILLAGER", // Minecraft 1.14 - "RAVAGER", // Minercraft 1.14 - "ZOMBIFIED_PIGLIN", // Minecraft 1.16 (rename of PIG_ZOMBIE) - "HOGLIN", // Minecraft 1.16 - "ZOGLIN" // 1.16 - ); - - public static boolean isEntityTypeMonster(EntityType entityType) - { - return ENTITY_TYPES_MONSTER.contains(entityType) || MConf.get().entityTypesMonsters.contains(entityType); - } - - // -------------------------------------------- // - // ENTITY TYPE ANIMAL - // -------------------------------------------- // - - public static final BackstringSet ENTITY_TYPES_ANIMAL = new BackstringSet<>(EntityType.class, - "BAT", // Minecraft 1.? - "CHICKEN", // Minecraft 1.? - "COW", // Minecraft 1.? - "DONKEY", - "HORSE", // Minecraft 1.? - "LLAMA", - "MULE", - "MUSHROOM_COW", // Minecraft 1.? - "OCELOT", // Minecraft 1.? - "PIG", // Minecraft 1.? - "RABBIT", // Minecraft 1.? - "SHEEP", // Minecraft 1.? - "SKELETON_HORSE", - "SQUID", // Minecraft 1.? - "WOLF", // Minecraft 1.? - "ZOMBIE_HORSE", - "PARROT", // Minecraft 1.12 - "COD", // Minecraft 1.13 - "SALMON", // Minecraft 1.13 - "PUFFERFISH", // Minecraft 1.13 - "TROPICAL_FISH", // Minecraft 1.13 - "TURTLE", // Minecraft 1.13 - "CAT", // Minecraft 1.14 - "FOX", // Minecraft 1.14 - "PANDA", // Minecraft 1.14 - "LLAMA", // Minecraft 1.14 - "LLAMA_SPIT", // Minecraft 1.14 - "STRIDER" // Minecraft 1.16 - ); - - public static boolean isEntityTypeAnimal(EntityType entityType) - { - return ENTITY_TYPES_ANIMAL.contains(entityType) || MConf.get().entityTypesAnimals.contains(entityType); - } - -} diff --git a/src/com/massivecraft/factions/util/MiscUtil.java b/src/com/massivecraft/factions/util/MiscUtil.java deleted file mode 100644 index 608c4374..00000000 --- a/src/com/massivecraft/factions/util/MiscUtil.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.massivecraft.factions.util; - -import org.bukkit.ChatColor; - -import java.util.Arrays; -import java.util.HashSet; - -public class MiscUtil -{ - // Inclusive range - public static long[] range(long start, long end) { - long[] values = new long[(int) Math.abs(end - start) + 1]; - - if (end < start) { - long oldstart = start; - start = end; - end = oldstart; - } - - for (long i = start; i <= end; i++) { - values[(int) (i - start)] = i; - } - - return values; - } - - public static HashSet substanceChars = new HashSet<>(Arrays.asList("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", - "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", - "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", - "s", "t", "u", "v", "w", "x", "y", "z")); - - public static String getComparisonString(String str) - { - StringBuilder ret = new StringBuilder(); - - str = ChatColor.stripColor(str); - str = str.toLowerCase(); - - for (char c : str.toCharArray()) - { - if (substanceChars.contains(String.valueOf(c))) - { - ret.append(c); - } - } - return ret.toString().toLowerCase(); - } - -} diff --git a/src/com/massivecraft/factions/util/RelationUtil.java b/src/com/massivecraft/factions/util/RelationUtil.java deleted file mode 100644 index d665b3c6..00000000 --- a/src/com/massivecraft/factions/util/RelationUtil.java +++ /dev/null @@ -1,144 +0,0 @@ -package com.massivecraft.factions.util; - -import com.massivecraft.factions.Rel; -import com.massivecraft.factions.RelationParticipator; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MFlag; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.ChatColor; - -public class RelationUtil -{ - // -------------------------------------------- // - // CONSTANTS - // -------------------------------------------- // - - private static final String UNKNOWN_RELATION_OTHER = "A server admin"; - private static final String UNDEFINED_FACTION_OTHER = "ERROR"; - private static final String OWN_FACTION = "your faction"; - private static final String SELF = "you"; - - // -------------------------------------------- // - // DESCRIBE - // -------------------------------------------- // - - public static String describeThatToMe(RelationParticipator that, RelationParticipator me, boolean ucfirst) - { - String ret = ""; - - if (that == null) return UNKNOWN_RELATION_OTHER; - - Faction thatFaction = getFaction(that); - if (thatFaction == null) return UNDEFINED_FACTION_OTHER; // ERROR - - Faction myFaction = getFaction(me); - - boolean isSameFaction = thatFaction == myFaction; - - if (that instanceof Faction) - { - String thatFactionName = thatFaction.getName(); - if (thatFaction.isNone()) - { - ret = thatFactionName; - } - else if (me instanceof MPlayer && isSameFaction) - { - ret = OWN_FACTION; - } - else - { - ret = thatFactionName; - } - } - else if (that instanceof MPlayer) - { - MPlayer mplayerthat = (MPlayer) that; - if (that == me) - { - ret = SELF; - } - else if (isSameFaction) - { - ret = mplayerthat.getNameAndTitle(myFaction); - } - else - { - ret = mplayerthat.getNameAndFactionName(); - } - } - - if (ucfirst) ret = Txt.upperCaseFirst(ret); - - return getColorOfThatToMe(that, me).toString() + ret; - } - - public static String describeThatToMe(RelationParticipator that, RelationParticipator me) - { - return describeThatToMe(that, me, false); - } - - // -------------------------------------------- // - // RELATION - // -------------------------------------------- // - - public static Rel getRelationOfThatToMe(RelationParticipator that, RelationParticipator me) - { - return getRelationOfThatToMe(that, me, false); - } - - public static Rel getRelationOfThatToMe(RelationParticipator that, RelationParticipator me, boolean ignorePeaceful) - { - Faction myFaction = getFaction(me); - if (myFaction == null) return Rel.NEUTRAL; // ERROR - - Faction thatFaction = getFaction(that); - if (thatFaction == null) return Rel.NEUTRAL; // ERROR - - if (myFaction.equals(thatFaction)) - { - return Rel.FACTION; - } - - MFlag flagPeaceful = MFlag.getFlagPeaceful(); - if (!ignorePeaceful && (thatFaction.getFlag(flagPeaceful) || myFaction.getFlag(flagPeaceful))) return Rel.TRUCE; - - // The faction with the lowest wish "wins" - Rel theirWish = thatFaction.getRelationWish(myFaction); - Rel myWish = myFaction.getRelationWish(thatFaction); - return theirWish.isLessThan(myWish) ? theirWish : myWish; - } - - // -------------------------------------------- // - // FACTION - // -------------------------------------------- // - - public static Faction getFaction(RelationParticipator rp) - { - if (rp instanceof Faction) return (Faction) rp; - - if (rp instanceof MPlayer) return ((MPlayer) rp).getFaction(); - - // ERROR - return null; - } - - // -------------------------------------------- // - // COLOR - // -------------------------------------------- // - - public static ChatColor getColorOfThatToMe(RelationParticipator that, RelationParticipator me) - { - Faction thatFaction = getFaction(that); - if (thatFaction != null && thatFaction != getFaction(me)) - { - if (thatFaction.getFlag(MFlag.getFlagFriendlyire())) return MConf.get().colorFriendlyFire; - - if (!thatFaction.getFlag(MFlag.getFlagPvp())) return MConf.get().colorNoPVP; - } - return getRelationOfThatToMe(that, me).getColor(); - } - -} diff --git a/src/com/massivecraft/factions/util/VisualizeUtil.java b/src/com/massivecraft/factions/util/VisualizeUtil.java deleted file mode 100644 index 9fd30dbd..00000000 --- a/src/com/massivecraft/factions/util/VisualizeUtil.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.massivecraft.factions.util; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; - -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.UUID; - -// TODO: Only send blocks in visual range -// TODO: Only send blocks that where changed when clearing? -// TODO: Create packed queue to avoid freezes. - -public class VisualizeUtil -{ - protected static Map> playerLocations = new HashMap<>(); - public static Set getPlayerLocations(Player player) - { - return getPlayerLocations(player.getUniqueId()); - } - public static Set getPlayerLocations(UUID uuid) - { - return playerLocations.computeIfAbsent(uuid, k -> new HashSet<>()); - } - - // -------------------------------------------- // - // SINGLE - // -------------------------------------------- // - - @SuppressWarnings("deprecation") - public static void addLocation(Player player, Location location, Material material, byte data) - { - getPlayerLocations(player).add(location); - player.sendBlockChange(location, material, data); - } - - @SuppressWarnings("deprecation") - public static void addLocation(Player player, Location location, Material material) - { - getPlayerLocations(player).add(location); - player.sendBlockChange(location, material, (byte) 0); - } - - // -------------------------------------------- // - // MANY - // -------------------------------------------- // - - @SuppressWarnings("deprecation") - public static void addLocations(Player player, Map locationMaterialIds) - { - Set ploc = getPlayerLocations(player); - for (Entry entry : locationMaterialIds.entrySet()) - { - ploc.add(entry.getKey()); - player.sendBlockChange(entry.getKey(), entry.getValue(), (byte) 0); - } - } - - @SuppressWarnings("deprecation") - public static void addLocations(Player player, Collection locations, Material material) - { - Set ploc = getPlayerLocations(player); - for (Location location : locations) - { - ploc.add(location); - player.sendBlockChange(location, material, (byte) 0); - } - } - - @SuppressWarnings("deprecation") - public static void addBlocks(Player player, Collection blocks, Material material) - { - Set ploc = getPlayerLocations(player); - for (Block block : blocks) - { - Location location = block.getLocation(); - ploc.add(location); - player.sendBlockChange(location, material, (byte) 0); - } - } - - // -------------------------------------------- // - // CLEAR - // -------------------------------------------- // - - @SuppressWarnings("deprecation") - public static void clear(Player player) - { - Set locations = getPlayerLocations(player); - if (locations == null) return; - for (Location location : locations) - { - Block block = location.getWorld().getBlockAt(location); - player.sendBlockChange(location, block.getType(), block.getData()); - } - locations.clear(); - } - -} diff --git a/src/main/java/com/massivecraft/factions/AccessStatus.java b/src/main/java/com/massivecraft/factions/AccessStatus.java new file mode 100644 index 00000000..2bde40b5 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/AccessStatus.java @@ -0,0 +1,56 @@ +package com.massivecraft.factions; + + +import com.massivecraft.massivecore.Colorized; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.ChatColor; + +public enum AccessStatus implements Colorized { + // -------------------------------------------- // + // ENUM + // -------------------------------------------- // + + STANDARD(ChatColor.YELLOW, null), + ELEVATED(ChatColor.GREEN, true), + DECREASED(ChatColor.RED, false), + + // END OF LIST + ; + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final ChatColor color; + + @Override + public ChatColor getColor() { + return this.color; + } + + private final Boolean access; + + public Boolean hasAccess() { + return access; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + AccessStatus(ChatColor color, Boolean access) { + this.color = color; + this.access = access; + } + + // -------------------------------------------- // + // MESSAGE + // -------------------------------------------- // + + public String getStatusMessage() { + ChatColor color = this.getColor(); + String status = Txt.getNicedEnum(this).toLowerCase(); + return Txt.parse("%sYou have %s access to this area.", color.toString(), status); + } + +} diff --git a/src/com/massivecraft/factions/EconomyParticipator.java b/src/main/java/com/massivecraft/factions/EconomyParticipator.java similarity index 66% rename from src/com/massivecraft/factions/EconomyParticipator.java rename to src/main/java/com/massivecraft/factions/EconomyParticipator.java index 94c14b79..4de52cc5 100644 --- a/src/com/massivecraft/factions/EconomyParticipator.java +++ b/src/main/java/com/massivecraft/factions/EconomyParticipator.java @@ -1,6 +1,5 @@ -package com.massivecraft.factions; - -public interface EconomyParticipator extends RelationParticipator -{ - boolean msg(String msg, Object... args); -} +package com.massivecraft.factions; + +public interface EconomyParticipator extends RelationParticipator { + boolean msg(String msg, Object... args); +} diff --git a/src/main/java/com/massivecraft/factions/ExtractorFactionAccountId.java b/src/main/java/com/massivecraft/factions/ExtractorFactionAccountId.java new file mode 100644 index 00000000..eea6977c --- /dev/null +++ b/src/main/java/com/massivecraft/factions/ExtractorFactionAccountId.java @@ -0,0 +1,34 @@ +package com.massivecraft.factions; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.massivecore.util.extractor.Extractor; + +public class ExtractorFactionAccountId implements Extractor { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ExtractorFactionAccountId i = new ExtractorFactionAccountId(); + + public static ExtractorFactionAccountId get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE: EXTRACTOR + // -------------------------------------------- // + + @Override + public Object extract(Object o) { + if (o instanceof Faction) { + String factionId = ((Faction) o).getId(); + if (factionId == null) { + return null; + } + return Factions.FACTION_MONEY_ACCOUNT_ID_PREFIX + factionId; + } + + return null; + } + +} diff --git a/src/main/java/com/massivecraft/factions/Factions.java b/src/main/java/com/massivecraft/factions/Factions.java new file mode 100644 index 00000000..43fc36e1 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/Factions.java @@ -0,0 +1,292 @@ +package com.massivecraft.factions; + +import com.google.gson.GsonBuilder; +import com.massivecraft.factions.adapter.BoardAdapter; +import com.massivecraft.factions.adapter.BoardMapAdapter; +import com.massivecraft.factions.adapter.TerritoryAccessAdapter; +import com.massivecraft.factions.chat.modifier.ChatModifierLc; +import com.massivecraft.factions.chat.modifier.ChatModifierLp; +import com.massivecraft.factions.chat.modifier.ChatModifierParse; +import com.massivecraft.factions.chat.modifier.ChatModifierRp; +import com.massivecraft.factions.chat.modifier.ChatModifierUc; +import com.massivecraft.factions.chat.modifier.ChatModifierUcf; +import com.massivecraft.factions.chat.tag.ChatTagName; +import com.massivecraft.factions.chat.tag.ChatTagNameforce; +import com.massivecraft.factions.chat.tag.ChatTagRelcolor; +import com.massivecraft.factions.chat.tag.ChatTagRole; +import com.massivecraft.factions.chat.tag.ChatTagRoleprefix; +import com.massivecraft.factions.chat.tag.ChatTagRoleprefixforce; +import com.massivecraft.factions.chat.tag.ChatTagTitle; +import com.massivecraft.factions.cmd.CmdFactions; +import com.massivecraft.factions.cmd.type.TypeFactionChunkChangeType; +import com.massivecraft.factions.cmd.type.TypeRel; +import com.massivecraft.factions.engine.EngineCanCombatHappen; +import com.massivecraft.factions.engine.EngineChat; +import com.massivecraft.factions.engine.EngineChunkChange; +import com.massivecraft.factions.engine.EngineCleanInactivity; +import com.massivecraft.factions.engine.EngineDenyCommands; +import com.massivecraft.factions.engine.EngineDenyTeleport; +import com.massivecraft.factions.engine.EngineEcon; +import com.massivecraft.factions.engine.EngineExploit; +import com.massivecraft.factions.engine.EngineFlagEndergrief; +import com.massivecraft.factions.engine.EngineFlagExplosion; +import com.massivecraft.factions.engine.EngineFlagFireSpread; +import com.massivecraft.factions.engine.EngineFlagSpawn; +import com.massivecraft.factions.engine.EngineFlagZombiegrief; +import com.massivecraft.factions.engine.EngineFly; +import com.massivecraft.factions.engine.EngineLastActivity; +import com.massivecraft.factions.engine.EngineMotd; +import com.massivecraft.factions.engine.EngineMoveChunk; +import com.massivecraft.factions.engine.EnginePermBuild; +import com.massivecraft.factions.engine.EnginePlayerData; +import com.massivecraft.factions.engine.EnginePower; +import com.massivecraft.factions.engine.EngineSeeChunk; +import com.massivecraft.factions.engine.EngineShow; +import com.massivecraft.factions.engine.EngineTeleportHomeOnDeath; +import com.massivecraft.factions.engine.EngineTerritoryShield; +import com.massivecraft.factions.engine.EngineVisualizations; +import com.massivecraft.factions.entity.Board; +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.factions.entity.MConfColl; +import com.massivecraft.factions.entity.MFlagColl; +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.MigratorFaction004WarpsPerms; +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.MigratorMPerm001Warps; +import com.massivecraft.factions.entity.migrator.MigratorMPerm002MoveStandard; +import com.massivecraft.factions.entity.migrator.MigratorMPlayer001Ranks; +import com.massivecraft.factions.entity.migrator.MigratorMPlayer002UsingAdminMode; +import com.massivecraft.factions.entity.migrator.MigratorTerritoryAccess001Restructure; +import com.massivecraft.factions.event.EventFactionsChunkChangeType; +import com.massivecraft.factions.integration.dynmap.IntegrationDynmap; +import com.massivecraft.factions.integration.lwc.IntegrationLwc; +import com.massivecraft.factions.integration.placeholderapi.IntegrationPlaceholderAPI; +import com.massivecraft.factions.integration.venturechat.IntegrationVentureChat; +import com.massivecraft.factions.integration.worldguard.IntegrationWorldGuard; +import com.massivecraft.factions.mixin.PowerMixin; +import com.massivecraft.factions.task.TaskFlagPermCreate; +import com.massivecraft.factions.task.TaskPlayerPowerUpdate; +import com.massivecraft.factions.task.TaskTax; +import com.massivecraft.massivecore.MassivePlugin; +import com.massivecraft.massivecore.command.type.RegistryType; +import com.massivecraft.massivecore.store.migrator.MigratorUtil; +import com.massivecraft.massivecore.util.MUtil; +import org.bukkit.ChatColor; + +import java.util.List; + +public class Factions extends MassivePlugin { + // -------------------------------------------- // + // CONSTANTS + // -------------------------------------------- // + + public final static String FACTION_MONEY_ACCOUNT_ID_PREFIX = "faction-"; + + public final static String ID_NONE = "none"; + public final static String ID_SAFEZONE = "safezone"; + public final static String ID_WARZONE = "warzone"; + + public final static String NAME_NONE_DEFAULT = ChatColor.DARK_GREEN.toString() + "Wilderness"; + public final static String NAME_SAFEZONE_DEFAULT = "SafeZone"; + public final static String NAME_WARZONE_DEFAULT = "WarZone"; + + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static Factions i; + + public static Factions get() { + return i; + } + + public Factions() { + Factions.i = this; + } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + // Mixins + @Deprecated + public PowerMixin getPowerMixin() { + return PowerMixin.get(); + } + + @Deprecated + public void setPowerMixin(PowerMixin powerMixin) { + PowerMixin.get().setInstance(powerMixin); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void onEnableInner() { + // Register types + RegistryType.register(Rel.class, TypeRel.get()); + RegistryType.register(EventFactionsChunkChangeType.class, TypeFactionChunkChangeType.get()); + + // Register Faction accountId Extractor + // TODO: Perhaps this should be placed in the econ integration somewhere? + MUtil.registerExtractor(String.class, "accountId", ExtractorFactionAccountId.get()); + + MigratorUtil.addJsonRepresentation(Board.class, Board.MAP_TYPE); + MigratorUtil.setTargetVersion(TerritoryAccess.class, 1); + + // Activate + this.activateAuto(); + this.activate(getClassesActiveChat()); + + } + + // These are overriden because the reflection trick was buggy and didn't work on all systems + @Override + public List> getClassesActiveMigrators() { + return MUtil.list( + MigratorFaction001Invitations.class, + MigratorFaction002Ranks.class, + MigratorFaction003Warps.class, + MigratorFaction004WarpsPerms.class, + MigratorMConf001EnumerationUtil.class, + MigratorMConf002CleanInactivity.class, + MigratorMConf003CleanInactivity.class, + MigratorMConf004Rank.class, + MigratorMConf005Warps.class, + MigratorMPerm001Warps.class, + MigratorMPerm002MoveStandard.class, + MigratorMPlayer001Ranks.class, + MigratorMPlayer002UsingAdminMode.class, + MigratorTerritoryAccess001Restructure.class + ); + } + + @Override + public List> getClassesActiveColls() { + // MConf should always be activated first for all plugins. It's simply a standard. The config should have no dependencies. + // MFlag and MPerm are both dependency free. + // Next we activate Faction, MPlayer and Board. The order is carefully chosen based on foreign keys and indexing direction. + // MPlayer --> Faction + // We actually only have an index that we maintain for the MPlayer --> Faction one. + // The Board could currently be activated in any order but the current placement is an educated guess. + // In the future we might want to find all chunks from the faction or something similar. + // We also have the /f access system where the player can be granted specific access, possibly supporting the idea of such a reverse index. + return MUtil.list( + MConfColl.class, + MFlagColl.class, + MPermColl.class, + FactionColl.class, + MPlayerColl.class, + BoardColl.class + ); + } + + @Override + public List> getClassesActiveCommands() { + return MUtil.list( + CmdFactions.class + ); + } + + @Override + public List> getClassesActiveIntegrations() { + return MUtil.list( + IntegrationPlaceholderAPI.class, + IntegrationVentureChat.class, + IntegrationLwc.class, + IntegrationWorldGuard.class, + IntegrationDynmap.class + ); + } + + @Override + public List> getClassesActiveTasks() { + return MUtil.list( + TaskTax.class, + TaskFlagPermCreate.class, + TaskPlayerPowerUpdate.class + ); + } + + @Override + public List> getClassesActiveEngines() { + return MUtil.list( + EngineCanCombatHappen.class, + EngineChat.class, + EngineChunkChange.class, + EngineCleanInactivity.class, + EngineDenyCommands.class, + EngineDenyTeleport.class, + EngineExploit.class, + EngineFlagEndergrief.class, + EngineFlagExplosion.class, + EngineFlagFireSpread.class, + EngineFlagSpawn.class, + EngineFlagZombiegrief.class, + EngineFly.class, + EngineLastActivity.class, + EngineMotd.class, + EngineMoveChunk.class, + EnginePermBuild.class, + EnginePlayerData.class, + EnginePower.class, + EngineSeeChunk.class, + EngineShow.class, + EngineTeleportHomeOnDeath.class, + EngineTerritoryShield.class, + EngineVisualizations.class, + EngineEcon.class + ); + } + + @Override + public List> getClassesActiveMixins() { + return MUtil.list( + PowerMixin.class + ); + } + + @Override + public List> getClassesActiveTests() { + return MUtil.list(); + } + + public List> getClassesActiveChat() { + return MUtil.list( + ChatModifierLc.class, + ChatModifierLp.class, + ChatModifierParse.class, + ChatModifierRp.class, + ChatModifierUc.class, + ChatModifierUcf.class, + ChatTagName.class, + ChatTagNameforce.class, + ChatTagRelcolor.class, + ChatTagRole.class, + ChatTagRoleprefix.class, + ChatTagRoleprefixforce.class, + ChatTagTitle.class + ); + } + + @Override + public GsonBuilder getGsonBuilder() { + return super.getGsonBuilder() + .registerTypeAdapter(TerritoryAccess.class, TerritoryAccessAdapter.get()) + .registerTypeAdapter(Board.class, BoardAdapter.get()) + .registerTypeAdapter(Board.MAP_TYPE, BoardMapAdapter.get()) + ; + } + +} diff --git a/src/main/java/com/massivecraft/factions/FactionsIndex.java b/src/main/java/com/massivecraft/factions/FactionsIndex.java new file mode 100644 index 00000000..d98c5c0c --- /dev/null +++ b/src/main/java/com/massivecraft/factions/FactionsIndex.java @@ -0,0 +1,168 @@ +package com.massivecraft.factions; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.entity.MPlayerColl; +import com.massivecraft.massivecore.collections.MassiveSet; + +import java.util.Collections; +import java.util.Map; +import java.util.Set; +import java.util.WeakHashMap; + +/** + * This Index class contains the MPlayer <--> Faction index. + *

+ * In the background it's powered by WeakHashMaps and all public methods are synchronized. + * That should increase thread safety but no thread safety is actually guarranteed. + * That is because the mplayer.getFaction() method is not threadsafe. + * TODO: Something to fix in the future perhaps? + */ +public class FactionsIndex { + // -------------------------------------------- // + // INSTANCE + // -------------------------------------------- // + + private static FactionsIndex i = new FactionsIndex(); + + public static FactionsIndex get() { + return i; + } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final Map mplayer2faction; + private final Map> faction2mplayers; + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + private FactionsIndex() { + this.mplayer2faction = new WeakHashMap<>(); + this.faction2mplayers = new WeakHashMapCreativeImpl(); + } + + // -------------------------------------------- // + // IS CONNECTED + // -------------------------------------------- // + + private boolean isConnected(MPlayer mplayer, Faction faction) { + if (mplayer == null) { + throw new NullPointerException("mplayer"); + } + if (faction == null) { + throw new NullPointerException("faction"); + } + + return mplayer.getFaction() == faction; + } + + // -------------------------------------------- // + // GET + // -------------------------------------------- // + + public synchronized Faction getFaction(MPlayer mplayer) { + return this.mplayer2faction.get(mplayer); + } + + public synchronized Set getMPlayers(Faction faction) { + return new MassiveSet<>(this.faction2mplayers.get(faction)); + } + + // -------------------------------------------- // + // UPDATE + // -------------------------------------------- // + + public synchronized void updateAll() { + if (!MPlayerColl.get().isActive()) { + throw new IllegalStateException("The MPlayerColl is not yet fully activated."); + } + + MPlayerColl.get().getAll().forEach(this::update); + } + + public synchronized void update(MPlayer mplayer) { + if (mplayer == null) { + throw new NullPointerException("mplayer"); + } + if (!FactionColl.get().isActive()) { + throw new IllegalStateException("The FactionColl is not yet fully activated."); + } + + // TODO: This is not optimal but here we remove a player from the index when + // the mplayer object is deattached. Optimally it should be removed + // automatically because it is stored as a weak reference. + // But sometimes that doesn't happen so we do this instead. + // Is there a memory leak somewhere? + if (!mplayer.attached()) { + Faction factionIndexed = this.mplayer2faction.remove(mplayer); + if (factionIndexed != null) { + faction2mplayers.get(factionIndexed).remove(mplayer); + } + return; + } + + Faction factionActual = mplayer.getFaction(); + Faction factionIndexed = this.getFaction(mplayer); + + Set factions = new MassiveSet<>(); + if (factionActual != null) { + factions.add(factionActual); + } + if (factionIndexed != null) { + factions.add(factionIndexed); + } + + for (Faction faction : factions) { + boolean connected = this.isConnected(mplayer, faction); + if (connected) { + this.faction2mplayers.get(faction).add(mplayer); + } else { + this.faction2mplayers.get(faction).remove(mplayer); + } + } + + this.mplayer2faction.put(mplayer, factionActual); + } + + public synchronized void update(Faction faction) { + if (faction == null) { + throw new NullPointerException("faction"); + } + + this.getMPlayers(faction).forEach(this::update); + } + + // -------------------------------------------- // + // MAP + // -------------------------------------------- // + + private static abstract class WeakHashMapCreative extends java.util.WeakHashMap { + @SuppressWarnings("unchecked") + @Override + public V get(Object key) { + V ret = super.get(key); + + if (ret == null) { + ret = this.createValue(); + this.put((K) key, ret); + } + + return ret; + } + + public abstract V createValue(); + } + + private static class WeakHashMapCreativeImpl extends WeakHashMapCreative> { + @Override + public Set createValue() { + return Collections.newSetFromMap(new WeakHashMap<>()); + } + } + +} diff --git a/src/com/massivecraft/factions/FactionsParticipator.java b/src/main/java/com/massivecraft/factions/FactionsParticipator.java similarity index 85% rename from src/com/massivecraft/factions/FactionsParticipator.java rename to src/main/java/com/massivecraft/factions/FactionsParticipator.java index 90998e51..6474d22e 100644 --- a/src/com/massivecraft/factions/FactionsParticipator.java +++ b/src/main/java/com/massivecraft/factions/FactionsParticipator.java @@ -2,6 +2,5 @@ package com.massivecraft.factions; import com.massivecraft.massivecore.Named; -public interface FactionsParticipator extends Named, EconomyParticipator, PowerBoosted -{ +public interface FactionsParticipator extends Named, EconomyParticipator, PowerBoosted { } diff --git a/src/main/java/com/massivecraft/factions/Perm.java b/src/main/java/com/massivecraft/factions/Perm.java new file mode 100644 index 00000000..09b68b71 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/Perm.java @@ -0,0 +1,87 @@ +package com.massivecraft.factions; + +import com.massivecraft.massivecore.Identified; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.util.PermissionUtil; +import org.bukkit.permissions.Permissible; + +public enum Perm implements Identified { + // -------------------------------------------- // + // ENUM + // -------------------------------------------- // + + // All of these are referenced in the code + ACCESS_GRANT_ONE, + ACCESS_GRANT_FILL, + ACCESS_GRANT_SQUARE, + ACCESS_GRANT_CIRCLE, + ACCESS_DENY_ONE, + ACCESS_DENY_FILL, + ACCESS_DENY_SQUARE, + ACCESS_DENY_CIRCLE, + CLAIM_ONE, + CLAIM_AUTO, + CLAIM_FILL, + CLAIM_SQUARE, + CLAIM_CIRCLE, + CLAIM_ALL, + UNCLAIM_ONE, + UNCLAIM_AUTO, + UNCLAIM_FILL, + UNCLAIM_SQUARE, + UNCLAIM_CIRCLE, + UNCLAIM_ALL, + OVERRIDE, + FLY, + JOIN_OTHERS, + INVITE_LIST_OTHER, + TITLE_COLOR, + POWERBOOST_SET, + MONEY_BALANCE_ANY, + SETPOWER, + CONFIG, + VERSION, + + // These are just here to tell the system that it is seechunk rather than see.chunk + SEECHUNK, + SEECHUNKOLD, + + // END OF LIST + ; + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final String id; + + @Override + public String getId() { + return this.id; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + Perm() { + this.id = PermissionUtil.createPermissionId(Factions.get(), this); + } + + // -------------------------------------------- // + // HAS + // -------------------------------------------- // + + public boolean has(Permissible permissible, boolean verboose) { + return PermissionUtil.hasPermission(permissible, this, verboose); + } + + public boolean has(Permissible permissible) { + return PermissionUtil.hasPermission(permissible, this); + } + + public void hasOrThrow(Permissible permissible) throws MassiveException { + PermissionUtil.hasPermissionOrThrow(permissible, this); + } + +} diff --git a/src/main/java/com/massivecraft/factions/PowerBoosted.java b/src/main/java/com/massivecraft/factions/PowerBoosted.java new file mode 100644 index 00000000..27353cd0 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/PowerBoosted.java @@ -0,0 +1,7 @@ +package com.massivecraft.factions; + +public interface PowerBoosted { + double getPowerBoost(); + + void setPowerBoost(Double powerBoost); +} diff --git a/src/main/java/com/massivecraft/factions/Rel.java b/src/main/java/com/massivecraft/factions/Rel.java new file mode 100644 index 00000000..9a79c0b1 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/Rel.java @@ -0,0 +1,175 @@ +package com.massivecraft.factions; + +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.massivecore.Colorized; +import com.massivecraft.massivecore.Named; +import com.massivecraft.massivecore.collections.MassiveSet; +import org.bukkit.ChatColor; + +import java.util.Collections; +import java.util.Set; + +public enum Rel implements Colorized, Named, MPerm.MPermable { + // -------------------------------------------- // + // ENUM + // -------------------------------------------- // + + ENEMY( + "an enemy", "enemies", "an enemy faction", "enemy factions", + "Enemy" + ) { + @Override + public ChatColor getColor() { + return MConf.get().colorEnemy; + } + }, + + NEUTRAL( + "someone neutral to you", "those neutral to you", "a neutral faction", "neutral factions", + "Neutral" + ) { + @Override + public ChatColor getColor() { + return MConf.get().colorNeutral; + } + }, + + TRUCE( + "someone in truce with you", "those in truce with you", "a faction in truce", "factions in truce", + "Truce" + ) { + @Override + public ChatColor getColor() { + return MConf.get().colorTruce; + } + }, + + ALLY( + "an ally", "allies", "an allied faction", "allied factions", + "Ally" + ) { + @Override + public ChatColor getColor() { + return MConf.get().colorAlly; + } + }, + + FACTION( + "your faction", "your faction", "your faction", "your faction", + "Faction" + ) { + @Override + public ChatColor getColor() { + return MConf.get().colorMember; + } + }, + + // END OF LIST + ; + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public int getValue() { + return this.ordinal(); + } + + private final String descPlayerOne; + + public String getDescPlayerOne() { + return this.descPlayerOne; + } + + private final String descPlayerMany; + + public String getDescPlayerMany() { + return this.descPlayerMany; + } + + private final String descFactionOne; + + public String getDescFactionOne() { + return this.descFactionOne; + } + + private final String descFactionMany; + + public String getDescFactionMany() { + return this.descFactionMany; + } + + private final Set names; + + public Set getNames() { + return this.names; + } + + @Override + public String getName() { + return this.getNames().iterator().next(); + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + Rel(String descPlayerOne, String descPlayerMany, String descFactionOne, String descFactionMany, String... names) { + this.descPlayerOne = descPlayerOne; + this.descPlayerMany = descPlayerMany; + this.descFactionOne = descFactionOne; + this.descFactionMany = descFactionMany; + this.names = Collections.unmodifiableSet(new MassiveSet<>(names)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public ChatColor getColor() { + return MConf.get().colorMember; + } + + @Override + public String getId() { + return name(); + } + + @Override + public String getDisplayName(Object senderObject) { + return this.getColor() + this.getName(); + } + + // -------------------------------------------- // + // UTIL + // -------------------------------------------- // + + public boolean isAtLeast(Rel rel) { + return this.getValue() >= rel.getValue(); + } + + public boolean isAtMost(Rel rel) { + return this.getValue() <= rel.getValue(); + } + + public boolean isLessThan(Rel rel) { + return this.getValue() < rel.getValue(); + } + + public boolean isMoreThan(Rel rel) { + return this.getValue() > rel.getValue(); + } + + // Used for friendly fire. + public boolean isFriend() { + return this.isAtLeast(TRUCE); + } + + @Deprecated + public String getPrefix() { + return ""; + } + +} diff --git a/src/main/java/com/massivecraft/factions/RelationParticipator.java b/src/main/java/com/massivecraft/factions/RelationParticipator.java new file mode 100644 index 00000000..0515d6d5 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/RelationParticipator.java @@ -0,0 +1,16 @@ +package com.massivecraft.factions; + +import org.bukkit.ChatColor; + + +public interface RelationParticipator { + String describeTo(RelationParticipator observer); + + String describeTo(RelationParticipator observer, boolean ucfirst); + + Rel getRelationTo(RelationParticipator observer); + + Rel getRelationTo(RelationParticipator observer, boolean ignorePeaceful); + + ChatColor getColorTo(RelationParticipator observer); +} diff --git a/src/main/java/com/massivecraft/factions/TerritoryAccess.java b/src/main/java/com/massivecraft/factions/TerritoryAccess.java new file mode 100644 index 00000000..63b74b46 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/TerritoryAccess.java @@ -0,0 +1,211 @@ +package com.massivecraft.factions; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.MPerm.MPermable; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.util.RelationUtil; +import com.massivecraft.massivecore.collections.MassiveSet; + +import java.util.Collection; +import java.util.Collections; +import java.util.Set; + +public class TerritoryAccess { + // -------------------------------------------- // + // FIELDS: RAW + // -------------------------------------------- // + + // no default value, can't be null + private final String hostFactionId; + + public String getHostFactionId() { + return this.hostFactionId; + } + + // default is true + private final boolean hostFactionAllowed; + + public boolean isHostFactionAllowed() { + return this.hostFactionAllowed; + } + + // default is empty + private final Set grantedIds; + + public Set getGrantedIds() { + return this.grantedIds; + } + + // default is null + private final String chunkName; + + public String getChunkName() { + return this.chunkName; + } + + // -------------------------------------------- // + // FIELDS: VERSION + // -------------------------------------------- // + + public int version = 1; + + // -------------------------------------------- // + // FIELDS: DELTA + // -------------------------------------------- // + + // The simple ones + public TerritoryAccess withHostFactionId(String hostFactionId) { + return valueOf(hostFactionId, hostFactionAllowed, grantedIds, chunkName); + } + + public TerritoryAccess withHostFactionAllowed(Boolean hostFactionAllowed) { + return valueOf(hostFactionId, hostFactionAllowed, grantedIds, chunkName); + } + + public TerritoryAccess withGrantedIds(Collection grantedIds) { + return valueOf(hostFactionId, hostFactionAllowed, grantedIds, chunkName); + } + + public TerritoryAccess withChunkName(String chunkName) { + return valueOf(hostFactionId, hostFactionAllowed, grantedIds, chunkName); + } + + // The intermediate ones + public TerritoryAccess withGranted(MPermable mpermable, boolean with) { + return withGrantedId(mpermable.getId(), with); + } + + public TerritoryAccess withGrantedId(String grantedId, boolean with) { + if (this.getHostFactionId().equals(grantedId)) { + return valueOf(hostFactionId, with, grantedIds, chunkName); + } + + Set grantedIds = new MassiveSet<>(this.getGrantedIds()); + if (with) { + grantedIds.add(grantedId); + } else { + grantedIds.remove(grantedId); + } + return valueOf(hostFactionId, hostFactionAllowed, grantedIds, chunkName); + } + + // -------------------------------------------- // + // FIELDS: DIRECT + // -------------------------------------------- // + + // This method intentionally returns null if the Faction no longer exists. + // In Board we don't even return this TerritoryAccess if that is the case. + public Faction getHostFaction() { + return Faction.get(this.getHostFactionId()); + } + + public Set getGranteds() { + return MPerm.idsToMPermables(this.getGrantedIds()); + } + + // -------------------------------------------- // + // PRIVATE CONSTRUCTOR + // -------------------------------------------- // + + // Strictly for GSON only + private TerritoryAccess() { + this.hostFactionId = null; + this.hostFactionAllowed = true; + this.grantedIds = null; + this.chunkName = null; + } + + private TerritoryAccess(String hostFactionId, Boolean hostFactionAllowed, Collection grantedIds, String chunkName) { + if (hostFactionId == null) { + throw new NullPointerException("hostFactionId"); + } + if (grantedIds == null) { + throw new NullPointerException("grantedIds"); + } + this.hostFactionId = hostFactionId; + + Set grantedIdsInner = new MassiveSet<>(); + grantedIdsInner.addAll(grantedIds); + if (grantedIdsInner.remove(hostFactionId)) { + hostFactionAllowed = true; + } + this.grantedIds = Collections.unmodifiableSet(grantedIdsInner); + + this.hostFactionAllowed = (hostFactionAllowed == null || hostFactionAllowed); + + this.chunkName = chunkName; + } + + // -------------------------------------------- // + // FACTORY: VALUE OF + // -------------------------------------------- // + + public static TerritoryAccess valueOf(String hostFactionId, Boolean hostFactionAllowed, Collection grantedIds, String chunkName) { + if (hostFactionId == null) { + throw new NullPointerException("hostFactionId"); + } + if (grantedIds == null) { + throw new NullPointerException("grantedIds"); + } + return new TerritoryAccess(hostFactionId, hostFactionAllowed, grantedIds, chunkName); + } + + public static TerritoryAccess valueOf(String hostFactionId) { + if (hostFactionId == null) { + throw new NullPointerException("hostFactionId"); + } + return valueOf(hostFactionId, null, Collections.emptySet(), null); + } + + // -------------------------------------------- // + // INSTANCE METHODS + // -------------------------------------------- // + + public boolean isGranted(MPermable permable) { + return isGranted(permable.getId()); + } + + public boolean isGranted(String permableId) { + if (permableId.equals(this.hostFactionId)) { + return this.isHostFactionAllowed(); + } + return this.getGrantedIds().contains(permableId); + } + + // A "default" TerritoryAccess could be serialized as a simple string only. + // The host faction is still allowed (default) and no faction or player has been granted explicit access (default). + public boolean isDefault() { + return this.isHostFactionAllowed() && this.getGrantedIds().isEmpty() && this.getChunkName() == null; + } + + // -------------------------------------------- // + // ACCESS STATUS + // -------------------------------------------- // + + public AccessStatus getTerritoryAccess(MPlayer mplayer) { + if (isGranted(mplayer.getId())) { + return AccessStatus.ELEVATED; + } + if (isGranted(mplayer.getRank().getId())) { + return AccessStatus.ELEVATED; + } + + if (this.getHostFactionId().equals(mplayer.getFaction().getId())) { + if (this.isHostFactionAllowed()) { + return AccessStatus.STANDARD; + } else { + return AccessStatus.DECREASED; + } + } + if (isGranted(mplayer.getFaction().getId())) { + return AccessStatus.ELEVATED; + } + if (isGranted(RelationUtil.getRelationOfThatToMe(mplayer, this.getHostFaction()).toString())) { + return AccessStatus.ELEVATED; + } + + return AccessStatus.STANDARD; + } + +} diff --git a/src/main/java/com/massivecraft/factions/adapter/BoardAdapter.java b/src/main/java/com/massivecraft/factions/adapter/BoardAdapter.java new file mode 100644 index 00000000..c8354aa5 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/adapter/BoardAdapter.java @@ -0,0 +1,39 @@ +package com.massivecraft.factions.adapter; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import com.massivecraft.factions.entity.Board; + +import java.lang.reflect.Type; + +public class BoardAdapter implements JsonDeserializer, JsonSerializer { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static BoardAdapter i = new BoardAdapter(); + + public static BoardAdapter get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @SuppressWarnings("unchecked") + @Override + public Board deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + return new Board(context.deserialize(json, Board.MAP_TYPE)); + } + + @Override + public JsonElement serialize(Board src, Type typeOfSrc, JsonSerializationContext context) { + return context.serialize(src.getMap(), Board.MAP_TYPE); + } + +} diff --git a/src/main/java/com/massivecraft/factions/adapter/BoardMapAdapter.java b/src/main/java/com/massivecraft/factions/adapter/BoardMapAdapter.java new file mode 100644 index 00000000..728b156c --- /dev/null +++ b/src/main/java/com/massivecraft/factions/adapter/BoardMapAdapter.java @@ -0,0 +1,67 @@ +package com.massivecraft.factions.adapter; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import com.massivecraft.factions.TerritoryAccess; +import com.massivecraft.massivecore.ps.PS; + +import java.lang.reflect.Type; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentSkipListMap; + +public class BoardMapAdapter implements JsonDeserializer>, JsonSerializer> { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static BoardMapAdapter i = new BoardMapAdapter(); + + public static BoardMapAdapter get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Map deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + Map ret = new ConcurrentSkipListMap<>(); + + JsonObject jsonObject = json.getAsJsonObject(); + + for (Entry entry : jsonObject.entrySet()) { + String[] ChunkCoordParts = entry.getKey().split("[,\\s]+"); + int chunkX = Integer.parseInt(ChunkCoordParts[0]); + int chunkZ = Integer.parseInt(ChunkCoordParts[1]); + PS chunk = PS.valueOf(chunkX, chunkZ); + + TerritoryAccess territoryAccess = context.deserialize(entry.getValue(), TerritoryAccess.class); + + ret.put(chunk, territoryAccess); + } + + return ret; + } + + @Override + public JsonElement serialize(Map src, Type typeOfSrc, JsonSerializationContext context) { + JsonObject ret = new JsonObject(); + + for (Entry entry : src.entrySet()) { + PS ps = entry.getKey(); + TerritoryAccess territoryAccess = entry.getValue(); + + ret.add(ps.getChunkX().toString() + "," + ps.getChunkZ().toString(), context.serialize(territoryAccess, TerritoryAccess.class)); + } + + return ret; + } + +} diff --git a/src/main/java/com/massivecraft/factions/adapter/TerritoryAccessAdapter.java b/src/main/java/com/massivecraft/factions/adapter/TerritoryAccessAdapter.java new file mode 100644 index 00000000..8802b8db --- /dev/null +++ b/src/main/java/com/massivecraft/factions/adapter/TerritoryAccessAdapter.java @@ -0,0 +1,121 @@ +package com.massivecraft.factions.adapter; + + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import com.google.gson.reflect.TypeToken; +import com.massivecraft.factions.TerritoryAccess; +import com.massivecraft.massivecore.store.migrator.MigratorUtil; + +import java.lang.reflect.Type; +import java.util.Collections; +import java.util.Set; + +public class TerritoryAccessAdapter implements JsonDeserializer, JsonSerializer { + // -------------------------------------------- // + // CONSTANTS + // -------------------------------------------- // + + public static final String HOST_FACTION_ID = "hostFactionId"; + public static final String HOST_FACTION_ALLOWED = "hostFactionAllowed"; + public static final String GRANTED_IDS = "grantedIds"; + public static final String CHUNK_NAME = "chunkName"; + + public static final Type SET_OF_STRING_TYPE = new TypeToken>() { + }.getType(); + + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static TerritoryAccessAdapter i = new TerritoryAccessAdapter(); + + public static TerritoryAccessAdapter get() { + return i; + } + + //----------------------------------------------// + // OVERRIDE + //----------------------------------------------// + + @Override + public TerritoryAccess deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + // isDefault <=> simple hostFactionId string + if (json.isJsonPrimitive()) { + String hostFactionId = json.getAsString(); + return TerritoryAccess.valueOf(hostFactionId); + } + + // Otherwise object + JsonObject obj = json.getAsJsonObject(); + + // Prepare variables + String hostFactionId = null; + Boolean hostFactionAllowed = null; + Set grantedIds = Collections.emptySet(); + String chunkName = null; + + // Read variables (test old values first) + JsonElement element = null; + + element = obj.get(HOST_FACTION_ID); + hostFactionId = element.getAsString(); + + element = obj.get(HOST_FACTION_ALLOWED); + if (element != null) { + hostFactionAllowed = element.getAsBoolean(); + } + + element = obj.get(GRANTED_IDS); + if (element != null) { + grantedIds = context.deserialize(element, SET_OF_STRING_TYPE); + } + + element = obj.get(CHUNK_NAME); + if (element != null) { + chunkName = element.getAsString(); + } + + return TerritoryAccess.valueOf(hostFactionId, hostFactionAllowed, grantedIds, chunkName); + } + + @Override + public JsonElement serialize(TerritoryAccess src, Type typeOfSrc, JsonSerializationContext context) { + if (src == null) { + return null; + } + + // isDefault <=> simple hostFactionId string + if (src.isDefault()) { + return new JsonPrimitive(src.getHostFactionId()); + } + + // Otherwise object + JsonObject obj = new JsonObject(); + + obj.addProperty(HOST_FACTION_ID, src.getHostFactionId()); + + if (!src.isHostFactionAllowed()) { + obj.addProperty(HOST_FACTION_ALLOWED, src.isHostFactionAllowed()); + } + + if (!src.getGrantedIds().isEmpty()) { + obj.add(GRANTED_IDS, context.serialize(src.getGrantedIds(), SET_OF_STRING_TYPE)); + } + + if (src.getChunkName() != null) { + obj.addProperty(CHUNK_NAME, src.getChunkName()); + } + + obj.add(MigratorUtil.VERSION_FIELD_NAME, new JsonPrimitive(src.version)); + + return obj; + } + +} diff --git a/src/main/java/com/massivecraft/factions/chat/ChatActive.java b/src/main/java/com/massivecraft/factions/chat/ChatActive.java new file mode 100644 index 00000000..0952f4e8 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/chat/ChatActive.java @@ -0,0 +1,54 @@ +package com.massivecraft.factions.chat; + +import com.massivecraft.massivecore.Active; +import com.massivecraft.massivecore.Identified; +import com.massivecraft.massivecore.MassivePlugin; + +public abstract class ChatActive implements Active, Identified { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private MassivePlugin activePlugin; + + private final String id; + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public ChatActive(final String id) { + this.id = id.toLowerCase(); + } + + // -------------------------------------------- // + // OVERRIDE > IDENTIFIED + // -------------------------------------------- // + + @Override + public String getId() { + return this.id; + } + + // -------------------------------------------- // + // OVERRIDE > ACTIVE + // -------------------------------------------- // + + @Override + public MassivePlugin setActivePlugin(MassivePlugin plugin) { + this.activePlugin = plugin; + return plugin; + } + + @Override + public MassivePlugin getActivePlugin() { + return this.activePlugin; + } + + @Override + public void setActive(MassivePlugin plugin) { + this.setActive(plugin != null); + this.setActivePlugin(plugin); + } + +} diff --git a/src/main/java/com/massivecraft/factions/chat/ChatFormatter.java b/src/main/java/com/massivecraft/factions/chat/ChatFormatter.java new file mode 100644 index 00000000..a74218fe --- /dev/null +++ b/src/main/java/com/massivecraft/factions/chat/ChatFormatter.java @@ -0,0 +1,113 @@ +package com.massivecraft.factions.chat; + +import org.bukkit.command.CommandSender; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * The ChatFormater is a system offered by factions for tag parsing. + *

+ * Note that every tag and modifier id must be lowercase. + * A tag with id "derp" is allowed but not with id "Derp". For that reason the tag {sender} will work but {Sender} wont. + */ +public class ChatFormatter { + // -------------------------------------------- // + // CONSTANTS + // -------------------------------------------- // + + public final static String START = "{"; + public final static String END = "}"; + public final static String SEPARATOR = "|"; + + public final static String ESC_START = "\\" + START; + public final static String ESC_END = "\\" + END; + public final static String ESC_SEPARATOR = "\\" + SEPARATOR; + + public final static Pattern pattern = Pattern.compile(ESC_START + "([^" + ESC_START + ESC_END + "]+)" + ESC_END); + + // -------------------------------------------- // + // FORMAT + // -------------------------------------------- // + + public static String format(String msg, CommandSender sender, CommandSender recipient) { + // We build the return value in this string buffer + StringBuffer ret = new StringBuffer(); + + // A matcher to match all the tags in the msg + Matcher matcher = pattern.matcher(msg); + + // For each tag we find + while (matcher.find()) { + // The fullmatch is something like "{sender|lp|rp}" + String fullmatch = matcher.group(0); + + // The submatch is something like "sender|lp|rp" + String submatch = matcher.group(1); + + // The parts are something like ["sender", "lp", "rp"] + String[] parts = submatch.split(ESC_SEPARATOR); + + // The modifier ids are something like ["lp", "rp"] and tagId something like "sender" + List modifierIds = new ArrayList<>(Arrays.asList(parts)); + String tagId = modifierIds.remove(0); + + // Fetch tag for the id + ChatTag tag = ChatTag.getTag(tagId); + + String replacement; + if (tag == null) { + // No change if tag wasn't found + replacement = fullmatch; + } else { + replacement = compute(tag, modifierIds, sender, recipient); + if (replacement == null) { + // If a tag or modifier returns null it's the same as opting out. + replacement = fullmatch; + } + } + + matcher.appendReplacement(ret, replacement); + } + + // Append the rest + matcher.appendTail(ret); + + // And finally we return the string value of the buffer we built + return ret.toString(); + } + + // -------------------------------------------- // + // TAG COMPUTE + // -------------------------------------------- // + + public static String compute(ChatTag tag, List modifierIds, CommandSender sender, CommandSender recipient) { + String ret = tag.getReplacement(sender, recipient); + if (ret == null) { + return null; + } + + for (String modifierId : modifierIds) { + // Find the modifier or skip + ChatModifier modifier = ChatModifier.getModifier(modifierId); + if (modifier == null) { + continue; + } + + // Modify and ignore change if null. + // Modifier can't get or return null. + String modified = modifier.getModified(ret, sender, recipient); + if (modified == null) { + continue; + } + + ret = modified; + } + + return ret; + } + +} diff --git a/src/main/java/com/massivecraft/factions/chat/ChatModifier.java b/src/main/java/com/massivecraft/factions/chat/ChatModifier.java new file mode 100644 index 00000000..be6deb32 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/chat/ChatModifier.java @@ -0,0 +1,50 @@ +package com.massivecraft.factions.chat; + +import com.massivecraft.massivecore.collections.MassiveMap; +import org.bukkit.command.CommandSender; + +import java.util.Map; + +public abstract class ChatModifier extends ChatActive { + // -------------------------------------------- // + // MODIFIER REGISTER + // -------------------------------------------- // + + private final static Map idToModifier = new MassiveMap<>(); + + public static ChatModifier getModifier(String modifierId) { + return idToModifier.get(modifierId); + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public ChatModifier(final String id) { + super(id); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public boolean isActive() { + return idToModifier.containsKey(this.getId()); + } + + @Override + public void setActive(boolean active) { + if (active) { + idToModifier.put(this.getId(), this); + } else { + idToModifier.remove(this.getId()); + } + } + + // -------------------------------------------- // + // ABSTRACT + // -------------------------------------------- // + + public abstract String getModified(String subject, CommandSender sender, CommandSender recipient); +} diff --git a/src/main/java/com/massivecraft/factions/chat/ChatTag.java b/src/main/java/com/massivecraft/factions/chat/ChatTag.java new file mode 100644 index 00000000..e80732c0 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/chat/ChatTag.java @@ -0,0 +1,51 @@ +package com.massivecraft.factions.chat; + +import com.massivecraft.massivecore.collections.MassiveMap; +import org.bukkit.command.CommandSender; + +import java.util.Map; + +public abstract class ChatTag extends ChatActive { + // -------------------------------------------- // + // TAG REGISTER + // -------------------------------------------- // + + private final static Map idToTag = new MassiveMap<>(); + + public static ChatTag getTag(String tagId) { + return idToTag.get(tagId); + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public ChatTag(final String id) { + super(id); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public boolean isActive() { + return idToTag.containsKey(this.getId()); + } + + @Override + public void setActive(boolean active) { + if (active) { + idToTag.put(this.getId(), this); + } else { + idToTag.remove(this.getId()); + } + } + + // -------------------------------------------- // + // ABSTRACT + // -------------------------------------------- // + + public abstract String getReplacement(CommandSender sender, CommandSender recipient); + +} diff --git a/src/main/java/com/massivecraft/factions/chat/modifier/ChatModifierLc.java b/src/main/java/com/massivecraft/factions/chat/modifier/ChatModifierLc.java new file mode 100644 index 00000000..869b584e --- /dev/null +++ b/src/main/java/com/massivecraft/factions/chat/modifier/ChatModifierLc.java @@ -0,0 +1,30 @@ +package com.massivecraft.factions.chat.modifier; + +import com.massivecraft.factions.chat.ChatModifier; +import org.bukkit.command.CommandSender; + +public class ChatModifierLc extends ChatModifier { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private ChatModifierLc() { + super("lc"); + } + + private static ChatModifierLc i = new ChatModifierLc(); + + public static ChatModifierLc get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getModified(String subject, CommandSender sender, CommandSender recipient) { + return subject.toLowerCase(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/chat/modifier/ChatModifierLp.java b/src/main/java/com/massivecraft/factions/chat/modifier/ChatModifierLp.java new file mode 100644 index 00000000..c5f20ef5 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/chat/modifier/ChatModifierLp.java @@ -0,0 +1,34 @@ +package com.massivecraft.factions.chat.modifier; + +import com.massivecraft.factions.chat.ChatModifier; +import org.bukkit.command.CommandSender; + + +public class ChatModifierLp extends ChatModifier { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private ChatModifierLp() { + super("lp"); + } + + private static ChatModifierLp i = new ChatModifierLp(); + + public static ChatModifierLp get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getModified(String subject, CommandSender sender, CommandSender recipient) { + if (subject.equals("")) { + return subject; + } + return " " + subject; + } + +} diff --git a/src/main/java/com/massivecraft/factions/chat/modifier/ChatModifierParse.java b/src/main/java/com/massivecraft/factions/chat/modifier/ChatModifierParse.java new file mode 100644 index 00000000..abd2c382 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/chat/modifier/ChatModifierParse.java @@ -0,0 +1,31 @@ +package com.massivecraft.factions.chat.modifier; + +import com.massivecraft.factions.chat.ChatModifier; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.command.CommandSender; + +public class ChatModifierParse extends ChatModifier { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private ChatModifierParse() { + super("parse"); + } + + private static ChatModifierParse i = new ChatModifierParse(); + + public static ChatModifierParse get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getModified(String subject, CommandSender sender, CommandSender recipient) { + return Txt.parse(subject); + } + +} diff --git a/src/main/java/com/massivecraft/factions/chat/modifier/ChatModifierRp.java b/src/main/java/com/massivecraft/factions/chat/modifier/ChatModifierRp.java new file mode 100644 index 00000000..072aecab --- /dev/null +++ b/src/main/java/com/massivecraft/factions/chat/modifier/ChatModifierRp.java @@ -0,0 +1,33 @@ +package com.massivecraft.factions.chat.modifier; + +import com.massivecraft.factions.chat.ChatModifier; +import org.bukkit.command.CommandSender; + +public class ChatModifierRp extends ChatModifier { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private ChatModifierRp() { + super("rp"); + } + + private static ChatModifierRp i = new ChatModifierRp(); + + public static ChatModifierRp get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getModified(String subject, CommandSender sender, CommandSender recipient) { + if (subject.equals("")) { + return subject; + } + return subject + " "; + } + +} diff --git a/src/main/java/com/massivecraft/factions/chat/modifier/ChatModifierUc.java b/src/main/java/com/massivecraft/factions/chat/modifier/ChatModifierUc.java new file mode 100644 index 00000000..4a23a1ba --- /dev/null +++ b/src/main/java/com/massivecraft/factions/chat/modifier/ChatModifierUc.java @@ -0,0 +1,30 @@ +package com.massivecraft.factions.chat.modifier; + +import com.massivecraft.factions.chat.ChatModifier; +import org.bukkit.command.CommandSender; + +public class ChatModifierUc extends ChatModifier { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private ChatModifierUc() { + super("uc"); + } + + private static ChatModifierUc i = new ChatModifierUc(); + + public static ChatModifierUc get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getModified(String subject, CommandSender sender, CommandSender recipient) { + return subject.toUpperCase(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/chat/modifier/ChatModifierUcf.java b/src/main/java/com/massivecraft/factions/chat/modifier/ChatModifierUcf.java new file mode 100644 index 00000000..459f045c --- /dev/null +++ b/src/main/java/com/massivecraft/factions/chat/modifier/ChatModifierUcf.java @@ -0,0 +1,31 @@ +package com.massivecraft.factions.chat.modifier; + +import com.massivecraft.factions.chat.ChatModifier; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.command.CommandSender; + +public class ChatModifierUcf extends ChatModifier { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private ChatModifierUcf() { + super("ucf"); + } + + private static ChatModifierUcf i = new ChatModifierUcf(); + + public static ChatModifierUcf get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getModified(String subject, CommandSender sender, CommandSender recipient) { + return Txt.upperCaseFirst(subject); + } + +} diff --git a/src/main/java/com/massivecraft/factions/chat/tag/ChatTagName.java b/src/main/java/com/massivecraft/factions/chat/tag/ChatTagName.java new file mode 100644 index 00000000..8bffe129 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/chat/tag/ChatTagName.java @@ -0,0 +1,41 @@ +package com.massivecraft.factions.chat.tag; + +import com.massivecraft.factions.chat.ChatTag; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPlayer; +import org.bukkit.command.CommandSender; + +public class ChatTagName extends ChatTag { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private ChatTagName() { + super("factions_name"); + } + + private static ChatTagName i = new ChatTagName(); + + public static ChatTagName get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getReplacement(CommandSender sender, CommandSender recipient) { + // Get entities + MPlayer usender = MPlayer.get(sender); + + // No "force" + Faction faction = usender.getFaction(); + if (faction.isNone()) { + return ""; + } + + return faction.getName(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/chat/tag/ChatTagNameforce.java b/src/main/java/com/massivecraft/factions/chat/tag/ChatTagNameforce.java new file mode 100644 index 00000000..f1aee0a6 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/chat/tag/ChatTagNameforce.java @@ -0,0 +1,36 @@ +package com.massivecraft.factions.chat.tag; + +import com.massivecraft.factions.chat.ChatTag; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPlayer; +import org.bukkit.command.CommandSender; + +public class ChatTagNameforce extends ChatTag { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private ChatTagNameforce() { + super("factions_nameforce"); + } + + private static ChatTagNameforce i = new ChatTagNameforce(); + + public static ChatTagNameforce get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getReplacement(CommandSender sender, CommandSender recipient) { + // Get entities + MPlayer usender = MPlayer.get(sender); + + Faction faction = usender.getFaction(); + return faction.getName(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/chat/tag/ChatTagRelcolor.java b/src/main/java/com/massivecraft/factions/chat/tag/ChatTagRelcolor.java new file mode 100644 index 00000000..6bd754a2 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/chat/tag/ChatTagRelcolor.java @@ -0,0 +1,40 @@ +package com.massivecraft.factions.chat.tag; + +import com.massivecraft.factions.chat.ChatTag; +import com.massivecraft.factions.entity.MPlayer; +import org.bukkit.command.CommandSender; + +public class ChatTagRelcolor extends ChatTag { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private ChatTagRelcolor() { + super("factions_relcolor"); + } + + private static ChatTagRelcolor i = new ChatTagRelcolor(); + + public static ChatTagRelcolor get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getReplacement(CommandSender sender, CommandSender recipient) { + // Opt out if no recipient + if (recipient == null) { + return null; + } + + // Get entities + MPlayer usender = MPlayer.get(sender); + MPlayer urecipient = MPlayer.get(recipient); + + return urecipient.getRelationTo(usender).getColor().toString(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/chat/tag/ChatTagRole.java b/src/main/java/com/massivecraft/factions/chat/tag/ChatTagRole.java new file mode 100644 index 00000000..79c98fc1 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/chat/tag/ChatTagRole.java @@ -0,0 +1,35 @@ +package com.massivecraft.factions.chat.tag; + +import com.massivecraft.factions.chat.ChatTag; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.command.CommandSender; + +public class ChatTagRole extends ChatTag { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private ChatTagRole() { + super("factions_role"); + } + + private static ChatTagRole i = new ChatTagRole(); + + public static ChatTagRole get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getReplacement(CommandSender sender, CommandSender recipient) { + // Get entities + MPlayer usender = MPlayer.get(sender); + + return Txt.upperCaseFirst(usender.getRank().getName().toLowerCase()); + } + +} diff --git a/src/main/java/com/massivecraft/factions/chat/tag/ChatTagRoleprefix.java b/src/main/java/com/massivecraft/factions/chat/tag/ChatTagRoleprefix.java new file mode 100644 index 00000000..380e79db --- /dev/null +++ b/src/main/java/com/massivecraft/factions/chat/tag/ChatTagRoleprefix.java @@ -0,0 +1,41 @@ +package com.massivecraft.factions.chat.tag; + +import com.massivecraft.factions.chat.ChatTag; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPlayer; +import org.bukkit.command.CommandSender; + +public class ChatTagRoleprefix extends ChatTag { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private ChatTagRoleprefix() { + super("factions_roleprefix"); + } + + private static ChatTagRoleprefix i = new ChatTagRoleprefix(); + + public static ChatTagRoleprefix get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getReplacement(CommandSender sender, CommandSender recipient) { + // Get entities + MPlayer usender = MPlayer.get(sender); + + // No "force" + Faction faction = usender.getFaction(); + if (faction.isNone()) { + return ""; + } + + return usender.getRank().getPrefix(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/chat/tag/ChatTagRoleprefixforce.java b/src/main/java/com/massivecraft/factions/chat/tag/ChatTagRoleprefixforce.java new file mode 100644 index 00000000..ed63210c --- /dev/null +++ b/src/main/java/com/massivecraft/factions/chat/tag/ChatTagRoleprefixforce.java @@ -0,0 +1,34 @@ +package com.massivecraft.factions.chat.tag; + +import com.massivecraft.factions.chat.ChatTag; +import com.massivecraft.factions.entity.MPlayer; +import org.bukkit.command.CommandSender; + +public class ChatTagRoleprefixforce extends ChatTag { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private ChatTagRoleprefixforce() { + super("factions_roleprefixforce"); + } + + private static ChatTagRoleprefixforce i = new ChatTagRoleprefixforce(); + + public static ChatTagRoleprefixforce get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getReplacement(CommandSender sender, CommandSender recipient) { + // Get entities + MPlayer usender = MPlayer.get(sender); + + return usender.getRank().getPrefix(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/chat/tag/ChatTagTitle.java b/src/main/java/com/massivecraft/factions/chat/tag/ChatTagTitle.java new file mode 100644 index 00000000..037ec2d2 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/chat/tag/ChatTagTitle.java @@ -0,0 +1,37 @@ +package com.massivecraft.factions.chat.tag; + +import com.massivecraft.factions.chat.ChatTag; +import com.massivecraft.factions.entity.MPlayer; +import org.bukkit.command.CommandSender; + +public class ChatTagTitle extends ChatTag { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private ChatTagTitle() { + super("factions_title"); + } + + private static ChatTagTitle i = new ChatTagTitle(); + + public static ChatTagTitle get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getReplacement(CommandSender sender, CommandSender recipient) { + // Get entities + MPlayer usender = MPlayer.get(sender); + + if (!usender.hasTitle()) { + return ""; + } + return usender.getTitle(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactions.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactions.java new file mode 100644 index 00000000..c222da1f --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactions.java @@ -0,0 +1,96 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.massivecore.command.MassiveCommandDeprecated; +import com.massivecraft.massivecore.command.MassiveCommandVersion; + +import java.util.List; + +public class CmdFactions extends FactionsCommand { + // -------------------------------------------- // + // INSTANCE + // -------------------------------------------- // + + private static CmdFactions i = new CmdFactions(); + + public static CmdFactions get() { + return i; + } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public CmdFactionsDocumentation cmdFactionsDocumentation = new CmdFactionsDocumentation(); + public CmdFactionsList cmdFactionsList = new CmdFactionsList(); + public CmdFactionsFaction cmdFactionsFaction = new CmdFactionsFaction(); + public CmdFactionsPlayer cmdFactionsPlayer = new CmdFactionsPlayer(); + public CmdFactionsStatus cmdFactionsStatus = new CmdFactionsStatus(); + public CmdFactionsJoin cmdFactionsJoin = new CmdFactionsJoin(); + public CmdFactionsLeave cmdFactionsLeave = new CmdFactionsLeave(); + public CmdFactionsWarp cmdFactionsWarp = new CmdFactionsWarp(); + public CmdFactionsHome cmdFactionsHome = new CmdFactionsHome(); + public CmdFactionsSethome cmdFactionsSethome = new CmdFactionsSethome(); + public CmdFactionsUnsethome cmdFactionsUnsethome = new CmdFactionsUnsethome(); + public CmdFactionsVote cmdFactionsVote = new CmdFactionsVote(); + 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 CmdFactionsInvite cmdFactionsInvite = new CmdFactionsInvite(); + public CmdFactionsKick cmdFactionsKick = new CmdFactionsKick(); + public CmdFactionsTitle cmdFactionsTitle = new CmdFactionsTitle(); + public CmdFactionsRank cmdFactionsRank = new CmdFactionsRank(); + public CmdFactionsMoney cmdFactionsMoney = new CmdFactionsMoney(); + public CmdFactionsTop cmdFactionsTop = new CmdFactionsTop(); + public CmdFactionsSeeChunk cmdFactionsSeeChunk = new CmdFactionsSeeChunk(); + public CmdFactionsSeeChunkOld cmdFactionsSeeChunkOld = new CmdFactionsSeeChunkOld(); + public CmdFactionsTerritorytitles cmdFactionsTerritorytitles = new CmdFactionsTerritorytitles(); + public CmdFactionsClaim cmdFactionsClaim = new CmdFactionsClaim(); + public CmdFactionsUnclaim cmdFactionsUnclaim = new CmdFactionsUnclaim(); + public CmdFactionsAccess cmdFactionsAccess = new CmdFactionsAccess(); + public CmdFactionsChunkname cmdFactionsChunkname = new CmdFactionsChunkname(); + public CmdFactionsRelation cmdFactionsRelation = new CmdFactionsRelation(); + public CmdFactionsRelationOld cmdFactionsRelationOldAlly = new CmdFactionsRelationOld("ally"); + public CmdFactionsRelationOld cmdFactionsRelationOldTruce = new CmdFactionsRelationOld("truce"); + public CmdFactionsRelationOld cmdFactionsRelationOldNeutral = new CmdFactionsRelationOld("neutral"); + public CmdFactionsRelationOld cmdFactionsRelationOldEnemy = new CmdFactionsRelationOld("enemy"); + public CmdFactionsTax cmdFactionsTax = new CmdFactionsTax(); + public CmdFactionsPerm cmdFactionsPerm = new CmdFactionsPerm(); + public CmdFactionsFlag cmdFactionsFlag = new CmdFactionsFlag(); + public CmdFactionsFly cmdFactionsFly = new CmdFactionsFly(); + public CmdFactionsUnstuck cmdFactionsUnstuck = new CmdFactionsUnstuck(); + public CmdFactionsOverride cmdFactionsOverride = new CmdFactionsOverride(); + public CmdFactionsDisband cmdFactionsDisband = new CmdFactionsDisband(); + public CmdFactionsPowerboost cmdFactionsPowerBoost = new CmdFactionsPowerboost(); + public CmdFactionsSetpower cmdFactionsSetpower = new CmdFactionsSetpower(); + public CmdFactionsMoneyconvert cmdFactionsMoneyconvert = new CmdFactionsMoneyconvert(); + public CmdFactionsConfig cmdFactionsConfig = new CmdFactionsConfig(); + public CmdFactionsClean cmdFactionsClean = new CmdFactionsClean(); + public MassiveCommandVersion cmdFactionsVersion = new MassiveCommandVersion(Factions.get()); + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactions() { + // Old rank stuff + this.addChild(new CmdFactionsRankOld("demote")); + this.addChild(new CmdFactionsRankOld("promote")); + + // Deprecated Commands + this.addChild(new MassiveCommandDeprecated(this.cmdFactionsRank, "leader", "owner", "officer", "moderator", "coleader")); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public List getAliases() { + return MConf.get().aliasesF; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccess.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccess.java new file mode 100644 index 00000000..fccb0ca2 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccess.java @@ -0,0 +1,24 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; + +public class CmdFactionsAccess extends FactionsCommand { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public CmdFactionsAccessView cmdFactionsAccessView = new CmdFactionsAccessView(); + public CmdFactionsAccessGrant cmdFactionsAccessGrant = new CmdFactionsAccessGrant(); + public CmdFactionsAccessDeny cmdFactionsAccessDeny = new CmdFactionsAccessDeny(); + public CmdFactionsAccessInspect cmdFactionsAccessInspect = new CmdFactionsAccessInspect(); + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsAccess() { + // Requirements + this.addRequirements(RequirementIsPlayer.get()); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessAbstract.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessAbstract.java new file mode 100644 index 00000000..f64ef010 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessAbstract.java @@ -0,0 +1,93 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.TerritoryAccess; +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.MPerm.MPermable; +import com.massivecraft.factions.util.AsciiMap; +import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.Txt; + +import java.util.Collection; + + +public abstract class CmdFactionsAccessAbstract extends FactionsCommand { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public PS chunk; + public TerritoryAccess ta; + public Faction hostFaction; + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsAccessAbstract() { + // Requirements + this.addRequirements(RequirementIsPlayer.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void senderFields(boolean set) { + super.senderFields(set); + + if (set) { + chunk = PS.valueOf(me.getLocation()).getChunk(true); + ta = BoardColl.get().getTerritoryAccessAt(chunk); + hostFaction = ta.getHostFaction(); + } else { + chunk = null; + ta = null; + hostFaction = null; + } + } + + public void sendAccessInfo() { + String chunkDesc = AsciiMap.getChunkDescWithName(chunk, ta); + Object title = "Access" + chunkDesc; + title = Txt.titleize(title); + message(title); + + msg("Host Faction: %s", hostFaction.describeTo(msender, true)); + msg("Host Faction Allowed: %s", ta.isHostFactionAllowed() ? Txt.parse("TRUE") : Txt.parse("FALSE")); + msg("Granted to: %s", CmdFactionsPermShow.permablesToDisplayString(ta.getGranteds(), msender)); + } + + public void setAccess(Collection chunks, MPermable mpermable, boolean granted) { + chunks.forEach(chunk -> setAccess(chunk, mpermable, granted)); + } + + public void setAccess(PS chunk, MPermable mpermable, boolean granted) { + TerritoryAccess ta = BoardColl.get().getTerritoryAccessAt(chunk); + Faction faction = ta.getHostFaction(); + + + String chunkDesc = AsciiMap.getChunkDescWithName(chunk, ta); + String grantedDenied = granted ? "granted" : "denied"; + String mpermableDesc = mpermable.getDisplayName(msender); + + if (!MPerm.getPermAccess().has(msender, faction, false)) { + msg("You do not have permission to edit access%s.", chunkDesc); + return; + } + + if (ta.isGranted(mpermable) == granted) { + msg("Access%s is already %s to %s.", chunkDesc, grantedDenied, mpermableDesc); + return; + } + + ta = ta.withGranted(mpermable, granted); + BoardColl.get().setTerritoryAccessAt(chunk, ta); + + msg("Access%s is now %s to %s.", chunkDesc, grantedDenied, mpermableDesc); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessDeny.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessDeny.java new file mode 100644 index 00000000..7f8d550d --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessDeny.java @@ -0,0 +1,24 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; + +public class CmdFactionsAccessDeny extends CmdFactionsAccessAbstract { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public CmdFactionsAccessSetOne cmdFactionsAccessDenyOne = new CmdFactionsAccessSetOne(false); + public CmdFactionsAccessSetSquare cmdFactionsAccessDenySquare = new CmdFactionsAccessSetSquare(false); + public CmdFactionsAccessSetCircle cmdFactionsAccessDenyCircle = new CmdFactionsAccessSetCircle(false); + public CmdFactionsAccessSetFill cmdFactionsAccessDenyFill = new CmdFactionsAccessSetFill(false); + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsAccessDeny() { + // Requirements + this.addRequirements(RequirementIsPlayer.get()); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessGrant.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessGrant.java new file mode 100644 index 00000000..1077f72f --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessGrant.java @@ -0,0 +1,24 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; + +public class CmdFactionsAccessGrant extends CmdFactionsAccessAbstract { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public CmdFactionsAccessSetOne cmdFactionsAccessGrantOne = new CmdFactionsAccessSetOne(true); + public CmdFactionsAccessSetSquare cmdFactionsAccessGrantSquare = new CmdFactionsAccessSetSquare(true); + public CmdFactionsAccessSetCircle cmdFactionsAccessGrantCircle = new CmdFactionsAccessSetCircle(true); + public CmdFactionsAccessSetFill cmdFactionsAccessGrantFill = new CmdFactionsAccessSetFill(true); + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsAccessGrant() { + // Requirements + this.addRequirements(RequirementIsPlayer.get()); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessInspect.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessInspect.java new file mode 100644 index 00000000..09613314 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessInspect.java @@ -0,0 +1,93 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.cmd.type.TypeMPermable; +import com.massivecraft.factions.entity.Board; +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.MPerm.MPermable; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.collections.MassiveMap; +import com.massivecraft.massivecore.mixin.MixinWorld; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.ps.PSFormatHumanSpace; +import com.massivecraft.massivecore.util.Txt; + +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.stream.Collectors; + +public class CmdFactionsAccessInspect extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsAccessInspect() { + // Parameters + this.addParameter(TypeMPermable.get(), "rank/rel/player/faction"); + this.addParameter(TypeFaction.get(), "faction", "your"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Parameter + Faction faction = this.readArgAt(1, msenderFaction); + MPermable mpermable = TypeMPermable.get(faction).read(this.argAt(0), sender); + + String factionId = faction.getId(); + + // Check if they have access perms, unless they are checking for their own access + if (mpermable != msender && mpermable != msenderFaction && mpermable != msender.getRank()) { + if (!MPerm.getPermAccess().has(msender, faction, true)) { + return; + } + } + + // Turn into id->chunks + // And filter the ones that are empty + Map> world2Chunks = new MassiveMap<>(); + for (Board board : BoardColl.get().getAll()) { + String worldId = board.getId(); + Set chunks = board.getMap().entrySet().stream() + .filter(e -> e.getValue().getHostFactionId().equals(factionId)) + .filter(e -> e.getValue().isGranted(mpermable)) + .map(Entry::getKey) + .collect(Collectors.toSet()); + if (!chunks.isEmpty()) { + world2Chunks.put(worldId, chunks); + } + } + + if (world2Chunks.isEmpty()) { + msg("%s has no special access in %s.", mpermable.getDisplayName(msender), faction.describeTo(msender)); + return; + } + + msg("%s has special access in %s in the following chunks:", mpermable.getDisplayName(msender), faction.describeTo(msender)); + + for (Entry> entry : world2Chunks.entrySet()) { + String worldId = entry.getKey(); + Set chunks = entry.getValue(); + + String worldName = MixinWorld.get().getWorldDisplayName(worldId); + + // Remove world from chunks + List chunkNames = chunks.stream() + .map(PS::getChunkCoords) + .map(PSFormatHumanSpace.get()::format) + .collect(Collectors.toList()); + + String chunkDesc = Txt.implodeCommaAnd(chunkNames, Txt.parse("")); + + msg("%s (%d): %s", worldName, chunks.size(), chunkDesc); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessSetCircle.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessSetCircle.java new file mode 100644 index 00000000..63d68a43 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessSetCircle.java @@ -0,0 +1,42 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Perm; +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; +import com.massivecraft.massivecore.util.ChunkUtil; + +import java.util.Set; + + +public class CmdFactionsAccessSetCircle extends CmdFactionsAccessSetXRadius { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsAccessSetCircle(boolean grant) { + // Super + super(grant); + + // Aliases + this.addAliases("circle"); + + // Requirements + this.addRequirements(RequirementIsPlayer.get()); + Perm perm = grant ? Perm.ACCESS_GRANT_CIRCLE : Perm.ACCESS_DENY_CIRCLE; + this.addRequirements(RequirementHasPerm.get(perm)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Set getChunks() throws MassiveException { + // Common Startup + final PS chunk = PS.valueOf(me.getLocation()).getChunk(true); + return ChunkUtil.getChunksCircle(chunk, this.getRadius()); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessSetFill.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessSetFill.java new file mode 100644 index 00000000..7696a6ff --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessSetFill.java @@ -0,0 +1,53 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Perm; +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +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; +import com.massivecraft.massivecore.util.ChunkUtil; + +import java.util.Set; +import java.util.function.Predicate; + +public class CmdFactionsAccessSetFill extends CmdFactionsAccessSetXSimple { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsAccessSetFill(boolean claim) { + // Super + super(claim); + + // Aliases + this.addAliases("fill"); + + // Requirements + this.addRequirements(RequirementIsPlayer.get()); + Perm perm = claim ? Perm.ACCESS_GRANT_FILL : Perm.ACCESS_DENY_FILL; + this.addRequirements(RequirementHasPerm.get(perm)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Set getChunks() throws MassiveException { + // Common Startup + final PS chunk = PS.valueOf(me.getLocation()).getChunk(true); + + // What faction (aka color) resides there? + // NOTE: Wilderness/None is valid. + final Faction color = BoardColl.get().getFactionAt(chunk); + + // Calculate + int max = MConf.get().setFillMax; + Predicate matcher = ps -> BoardColl.get().getFactionAt(ps) == color; + return ChunkUtil.getChunkArea(chunk, matcher, max); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessSetOne.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessSetOne.java new file mode 100644 index 00000000..60ff5077 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessSetOne.java @@ -0,0 +1,40 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Perm; +import com.massivecraft.massivecore.command.requirement.RequirementHasPerm; +import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; +import com.massivecraft.massivecore.ps.PS; + +import java.util.Collections; +import java.util.Set; + + +public class CmdFactionsAccessSetOne extends CmdFactionsAccessSetXSimple { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsAccessSetOne(boolean claim) { + // Super + super(claim); + + // Aliases + this.addAliases("one"); + + // Requirements + this.addRequirements(RequirementIsPlayer.get()); + Perm perm = claim ? Perm.ACCESS_GRANT_ONE : Perm.ACCESS_DENY_ONE; + this.addRequirements(RequirementHasPerm.get(perm)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Set getChunks() { + final PS chunk = PS.valueOf(me.getLocation()).getChunk(true); + return Collections.singleton(chunk); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessSetSquare.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessSetSquare.java new file mode 100644 index 00000000..b5515732 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessSetSquare.java @@ -0,0 +1,42 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Perm; +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; +import com.massivecraft.massivecore.util.ChunkUtil; + +import java.util.Set; + + +public class CmdFactionsAccessSetSquare extends CmdFactionsAccessSetXRadius { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsAccessSetSquare(boolean grant) { + // Super + super(grant); + + // Aliases + this.addAliases("square"); + + // Requirements + this.addRequirements(RequirementIsPlayer.get()); + Perm perm = grant ? Perm.ACCESS_GRANT_SQUARE : Perm.ACCESS_DENY_SQUARE; + this.addRequirements(RequirementHasPerm.get(perm)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Set getChunks() throws MassiveException { + // Common Startup + final PS chunk = PS.valueOf(me.getLocation()).getChunk(true); + return ChunkUtil.getChunksSquare(chunk, this.getRadius()); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessSetX.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessSetX.java new file mode 100644 index 00000000..3ddac6c4 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessSetX.java @@ -0,0 +1,78 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeMPermable; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPerm.MPermable; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.ps.PS; + +import java.util.Set; + +public abstract class CmdFactionsAccessSetX extends CmdFactionsAccessAbstract { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private boolean grant = true; + + public boolean isGranting() { + return this.grant; + } + + public void setGranting(boolean grant) { + this.grant = grant; + } + + private int mpermableArgIndex = 0; + + public int getMPermableArgIndex() { + return this.mpermableArgIndex; + } + + public void setMPermableArgIndex(int mpermableArgIndex) { + this.mpermableArgIndex = mpermableArgIndex; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsAccessSetX(boolean grant) { + this.setGranting(grant); + this.setSetupEnabled(false); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + final MPermable mpermable = this.getMPermable(hostFaction); + + final Set chunks = this.getChunks(); + if (chunks == null) { + throw new NullPointerException("chunks"); + } + + // Apply / Inform + setAccess(chunks, mpermable, this.isGranting()); + } + + // -------------------------------------------- // + // ABSTRACT + // -------------------------------------------- // + + public abstract Set getChunks() throws MassiveException; + + // -------------------------------------------- // + // EXTRAS + // -------------------------------------------- // + + public MPermable getMPermable(Faction faction) throws MassiveException { + String arg = this.argAt(this.getMPermableArgIndex()); + return TypeMPermable.get(faction).read(arg, sender); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessSetXRadius.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessSetXRadius.java new file mode 100644 index 00000000..b84b6684 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessSetXRadius.java @@ -0,0 +1,46 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeMPermable; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.primitive.TypeInteger; + + +public abstract class CmdFactionsAccessSetXRadius extends CmdFactionsAccessSetX { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsAccessSetXRadius(boolean claim) { + // Super + super(claim); + + // Parameters + this.addParameter(TypeInteger.get(), "radius"); + + this.addParameter(TypeMPermable.get(), "rank/rel/faction/player"); + this.setMPermableArgIndex(1); + + } + + // -------------------------------------------- // + // EXTRAS + // -------------------------------------------- // + + public Integer getRadius() throws MassiveException { + int radius = this.readArgAt(0); + + // Radius Claim Min + if (radius < 1) { + throw new MassiveException().setMsg("If you specify a radius, it must be at least 1."); + } + + // Radius Claim Max + if (radius > MConf.get().setRadiusMax && !msender.isOverriding()) { + throw new MassiveException().setMsg("The maximum radius allowed is %s.", MConf.get().setRadiusMax); + } + + return radius; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessSetXSimple.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessSetXSimple.java new file mode 100644 index 00000000..e6acfcec --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessSetXSimple.java @@ -0,0 +1,19 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeMPermable; + +public abstract class CmdFactionsAccessSetXSimple extends CmdFactionsAccessSetX { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsAccessSetXSimple(boolean claim) { + // Super + super(claim); + + // Parameters + this.addParameter(TypeMPermable.get(), "rank/rel/player/faction"); + this.setMPermableArgIndex(0); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessView.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessView.java new file mode 100644 index 00000000..a2e646ee --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessView.java @@ -0,0 +1,13 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsAccessView extends CmdFactionsAccessAbstract { + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() { + this.sendAccessInfo(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsChunkname.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsChunkname.java new file mode 100644 index 00000000..096631d9 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsChunkname.java @@ -0,0 +1,75 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.TerritoryAccess; +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.util.AsciiMap; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; +import com.massivecraft.massivecore.command.type.TypeNullable; +import com.massivecraft.massivecore.command.type.primitive.TypeString; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.MUtil; +import com.massivecraft.massivecore.util.Txt; + +public class CmdFactionsChunkname extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsChunkname() { + // Parameters + this.addParameter(TypeNullable.get(TypeString.get()), "name", "read"); + + this.addRequirements(RequirementIsPlayer.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + PS chunk = PS.valueOf(me.getLocation()).getChunk(true); + TerritoryAccess ta = BoardColl.get().getTerritoryAccessAt(chunk); + + if (!this.argIsSet(0)) { + String name = ta.getChunkName(); + if (name == null) { + msg("This chunk has no name."); + } else { + msg("This chunk is called %s.", name); + } + return; + } + + // MPerm + if (!MPerm.getPermTerritory().has(msender, msenderFaction, true)) { + return; + } + + // Args + String target = this.readArg(); + if (target != null) { + target = target.trim(); + target = Txt.parse(target); + } + + String old = ta.getChunkName(); + + // NoChange + if (MUtil.equals(old, target)) { + if (old == null) { + throw new MassiveException().addMsg("This chunk already has no name."); + } + throw new MassiveException().addMsg("The name for this chunk is already %s.", old); + } + + ta = ta.withChunkName(target); + BoardColl.get().setTerritoryAccessAt(chunk, ta); + + String chunkDesc = AsciiMap.getChunkDesc(chunk); + msg("The chunk name%s is now %s.", chunkDesc, target); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsClaim.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsClaim.java new file mode 100644 index 00000000..364db894 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsClaim.java @@ -0,0 +1,15 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsClaim extends FactionsCommand { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public CmdFactionsSetOne cmdFactionsClaimOne = new CmdFactionsSetOne(true); + public CmdFactionsSetAuto cmdFactionsClaimAuto = new CmdFactionsSetAuto(true); + public CmdFactionsSetFill cmdFactionsClaimFill = new CmdFactionsSetFill(true); + public CmdFactionsSetSquare cmdFactionsClaimSquare = new CmdFactionsSetSquare(true); + public CmdFactionsSetCircle cmdFactionsClaimCircle = new CmdFactionsSetCircle(true); + public CmdFactionsSetAll cmdFactionsClaimAll = new CmdFactionsSetAll(true); + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsClean.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsClean.java new file mode 100644 index 00000000..e4882e02 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsClean.java @@ -0,0 +1,158 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Rel; +import com.massivecraft.factions.TerritoryAccess; +import com.massivecraft.factions.entity.Board; +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.factions.entity.Invitation; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.entity.MPlayerColl; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.collections.MassiveSet; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.store.EntityInternalMap; +import com.massivecraft.massivecore.util.Txt; + +import java.util.Iterator; +import java.util.Map.Entry; +import java.util.Set; + +public class CmdFactionsClean extends FactionsCommand { + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + Object message; + int count; + + // Title + message = Txt.titleize("Factions Cleaner Results"); + message(message); + + // Yada + cleanMessage(this.cleanPlayer(), "player"); + cleanMessage(this.cleanFactionInvites(), "faction invites"); + cleanMessage(this.cleanFactionRelationWhishes(), "faction relation whishes"); + cleanMessage(this.cleanBoardHost(), "chunk whole"); + cleanMessage(this.cleanBoardGrant(), "chunk access"); + } + + // -------------------------------------------- // + // CLEAN + // -------------------------------------------- // + + private void cleanMessage(int count, String name) { + msg("%d %s", count, name); + } + + private int cleanPlayer() { + int ret = 0; + + for (MPlayer mplayer : MPlayerColl.get().getAll()) { + if (!mplayer.isFactionOrphan()) { + continue; + } + + mplayer.resetFactionData(); + ret += 1; + } + + return ret; + } + + private int cleanFactionInvites() { + int ret = 0; + + for (Faction faction : FactionColl.get().getAll()) { + EntityInternalMap invitations = faction.getInvitations(); + if (invitations.isEmpty()) { + continue; + } + + ret += invitations.size(); + Set invitationIds = new MassiveSet<>(invitations.keySet()); + for (String inviteId : invitationIds) { + invitations.detachIdFixed(inviteId); + } + + faction.changed(); + } + + return ret; + } + + private int cleanFactionRelationWhishes() { + int ret = 0; + + for (Faction faction : FactionColl.get().getAll()) { + for (Iterator> iterator = faction.getRelationWishes().entrySet().iterator(); iterator.hasNext(); ) { + Entry entry = iterator.next(); + String factionId = entry.getKey(); + if (FactionColl.get().containsId(factionId)) { + continue; + } + + iterator.remove(); + ret += 1; + faction.changed(); + } + } + + return ret; + } + + private int cleanBoardHost() { + int ret = 0; + + for (Board board : BoardColl.get().getAll()) { + for (Entry entry : board.getMap().entrySet()) { + PS ps = entry.getKey(); + TerritoryAccess territoryAccess = entry.getValue(); + String factionId = territoryAccess.getHostFactionId(); + + if (FactionColl.get().containsId(factionId)) { + continue; + } + + board.removeAt(ps); + ret += 1; + } + } + + return ret; + } + + private int cleanBoardGrant() { + int ret = 0; + + for (Board board : BoardColl.get().getAll()) { + for (Entry entry : board.getMap().entrySet()) { + PS ps = entry.getKey(); + TerritoryAccess territoryAccess = entry.getValue(); + boolean changed = false; + + for (String grantedIds : territoryAccess.getGrantedIds()) { + if (MPerm.idToMPermableOptional(grantedIds).isPresent()) { + continue; + } + + territoryAccess = territoryAccess.withGrantedId(grantedIds, false); + ret += 1; + changed = true; + } + + if (changed) { + board.setTerritoryAccessAt(ps, territoryAccess); + } + } + } + + return ret; + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsConfig.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsConfig.java similarity index 53% rename from src/com/massivecraft/factions/cmd/CmdFactionsConfig.java rename to src/main/java/com/massivecraft/factions/cmd/CmdFactionsConfig.java index 09ab82bf..5c454631 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsConfig.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsConfig.java @@ -5,18 +5,16 @@ import com.massivecraft.factions.entity.MConf; import com.massivecraft.massivecore.command.editor.CommandEditSingleton; import com.massivecraft.massivecore.command.requirement.RequirementHasPerm; -public class CmdFactionsConfig extends CommandEditSingleton -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsConfig() - { - super(MConf.get()); - - // Requirements - this.addRequirements(RequirementHasPerm.get(Perm.CONFIG)); - } - +public class CmdFactionsConfig extends CommandEditSingleton { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsConfig() { + super(MConf.get()); + + // Requirements + this.addRequirements(RequirementHasPerm.get(Perm.CONFIG)); + } + } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsCreate.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsCreate.java new file mode 100644 index 00000000..59f694ce --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsCreate.java @@ -0,0 +1,73 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.cmd.req.ReqHasntFaction; +import com.massivecraft.factions.cmd.type.TypeFactionNameStrict; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.event.EventFactionsCreate; +import com.massivecraft.factions.event.EventFactionsMembershipChange; +import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.mson.Mson; +import com.massivecraft.massivecore.store.MStore; +import org.bukkit.ChatColor; + +public class CmdFactionsCreate extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsCreate() { + // Aliases + this.addAliases("new"); + + // Parameters + this.addParameter(TypeFactionNameStrict.get(), "name").setDesc("the name of your new faction"); + + // Requirements + this.addRequirements(ReqHasntFaction.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + String newName = this.readArg(); + + // Pre-Generate Id + String factionId = MStore.createId(); + + // Event + EventFactionsCreate createEvent = new EventFactionsCreate(sender, factionId, newName); + createEvent.run(); + if (createEvent.isCancelled()) { + return; + } + + // Apply + Faction faction = FactionColl.get().create(factionId); + faction.setName(newName); + + msender.setRank(faction.getLeaderRank()); + msender.setFaction(faction); + + EventFactionsMembershipChange joinEvent = new EventFactionsMembershipChange(sender, msender, faction, MembershipChangeReason.CREATE); + joinEvent.run(); + // NOTE: join event cannot be cancelled or you'll have an empty faction + + // Inform + msg("You created the faction %s", faction.getName(msender)); + message(Mson.mson(mson("You should now: ").color(ChatColor.YELLOW), CmdFactions.get().cmdFactionsDescription.getTemplate())); + + // Log + if (MConf.get().logFactionCreate) { + Factions.get().log(msender.getName() + " created a new faction: " + newName); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDescription.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDescription.java new file mode 100644 index 00000000..e70fa5f6 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDescription.java @@ -0,0 +1,55 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.req.ReqHasFaction; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.event.EventFactionsDescriptionChange; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.primitive.TypeString; +import com.massivecraft.massivecore.mixin.MixinDisplayName; + +public class CmdFactionsDescription extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsDescription() { + // Parameters + this.addParameter(TypeString.get(), "desc", true).setDesc("the new faction desciption"); + + // Requirements + this.addRequirements(ReqHasFaction.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + String newDescription = this.readArg(); + + // MPerm + if (!MPerm.getPermDesc().has(msender, msenderFaction, true)) { + return; + } + + // Event + EventFactionsDescriptionChange event = new EventFactionsDescriptionChange(sender, msenderFaction, newDescription); + event.run(); + if (event.isCancelled()) { + return; + } + newDescription = event.getNewDescription(); + + // Apply + msenderFaction.setDescription(newDescription); + + // Inform + for (MPlayer follower : msenderFaction.getMPlayers()) { + follower.msg("%s set your faction description to:\n%s", MixinDisplayName.get().getDisplayName(sender, follower), msenderFaction.getDescriptionDesc()); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDisband.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDisband.java new file mode 100644 index 00000000..d0df6d30 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDisband.java @@ -0,0 +1,88 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.FactionColl; +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.EventFactionsDisband; +import com.massivecraft.factions.event.EventFactionsMembershipChange; +import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.primitive.TypeStringConfirmation; +import com.massivecraft.massivecore.util.ConfirmationUtil; +import com.massivecraft.massivecore.util.IdUtil; +import com.massivecraft.massivecore.util.Txt; + +public class CmdFactionsDisband extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsDisband() { + // Parameters + this.addParameter(TypeFaction.get(), "faction"); + this.addParameter(TypeStringConfirmation.get(), "confirmation", ""); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + Faction faction = this.readArg(); + String confirmationString = this.readArg(null); + + if (MConf.get().requireConfirmationForFactionDisbanding) { + ConfirmationUtil.tryConfirm(this); + } + + // MPerm + if (!MPerm.getPermDisband().has(msender, faction, true)) { + return; + } + + // Verify + if (faction.getFlag(MFlag.getFlagPermanent())) { + throw new MassiveException().addMsg("This faction is designated as permanent, so you cannot disband it."); + } + + // Event + EventFactionsDisband event = new EventFactionsDisband(me, faction); + event.run(); + if (event.isCancelled()) { + return; + } + + // Merged Apply and Inform + + // Run event for each player in the faction + for (MPlayer mplayer : faction.getMPlayers()) { + EventFactionsMembershipChange membershipChangeEvent = new EventFactionsMembershipChange(sender, mplayer, FactionColl.get().getNone(), MembershipChangeReason.DISBAND); + membershipChangeEvent.run(); + } + + // Inform + for (MPlayer mplayer : faction.getMPlayersWhereOnline(true)) { + mplayer.msg("%s disbanded your faction.", msender.describeTo(mplayer)); + } + + if (msenderFaction != faction) { + msender.msg("You disbanded %s.", faction.describeTo(msender)); + } + + // Log + if (MConf.get().logFactionDisband) { + Factions.get().log(Txt.parse("The faction %s (%s) was disbanded by %s.", faction.getName(), faction.getId(), msender.getDisplayName(IdUtil.getConsole()))); + } + + // Apply + faction.detach(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDocumentation.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDocumentation.java new file mode 100644 index 00000000..c4790e51 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDocumentation.java @@ -0,0 +1,26 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Factions; +import org.bukkit.ChatColor; + +public class CmdFactionsDocumentation extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsDocumentation() { + String web = Factions.get().getDescription().getWebsite(); + this.setHelp(mson("More help can be found at ", mson(web).link(web).color(ChatColor.AQUA))); + } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public CmdFactionsDocumentationPower cmdFactionsDocumentationPower = new CmdFactionsDocumentationPower(); + public CmdFactionsDocumentationRanks cmdFactionsDocumentationRanks = new CmdFactionsDocumentationRanks(); + public CmdFactionsDocumentationWarps cmdFactionsDocumentationWarps = new CmdFactionsDocumentationWarps(); + public CmdFactionsDocumentationFlags cmdFactionsDocumentationFlags = new CmdFactionsDocumentationFlags(); + public CmdFactionsDocumentationPerms cmdFactionsDocumentationPerms = new CmdFactionsDocumentationPerms(); + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDocumentationFlags.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDocumentationFlags.java new file mode 100644 index 00000000..81a8a795 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDocumentationFlags.java @@ -0,0 +1,36 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.factions.entity.MFlagColl; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.util.Txt; + +import java.util.List; +import java.util.stream.Collectors; + +public class CmdFactionsDocumentationFlags extends FactionsCommandDocumentation { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsDocumentationFlags() { + + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + msgDoc("Flags are a way to give certain factions certain attributes " + + " such as disabling pvp or enabling friendly fire."); + msgDoc("To see all the flags type:"); + message(CmdFactions.get().cmdFactionsFlag.cmdFactionsFlagList.getTemplate(false, true, sender)); + + List flags = MFlagColl.get().getAll(MFlag::isEditable).stream().map(flag -> Txt.parse("%s", flag.getName())).collect(Collectors.toList()); + String str = Txt.implodeCommaAndDot(flags, Txt.parse("")); + msgDoc("The flags you can edit for your faction are: %s", str); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDocumentationPerms.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDocumentationPerms.java new file mode 100644 index 00000000..16a02350 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDocumentationPerms.java @@ -0,0 +1,42 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.massivecore.MassiveException; + +public class CmdFactionsDocumentationPerms extends FactionsCommandDocumentation { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsDocumentationPerms() { + + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + msgDoc("Permissions decide who can do what in your faction. " + + "Permissions can be given to a rank, a player, a relation, " + + "everyone in another faction or everyone with a specific rank in another faction."); + msgDoc("Because perms can be given to all of these groups individually, it allows for extreme degrees of fine tuning."); + + msgDoc("To list all permissions type:"); + message(CmdFactions.get().cmdFactionsPerm.cmdFactionsPermList.getTemplate(false, true, sender)); + + msgDoc("To see who has a specific perm type:"); + message(CmdFactions.get().cmdFactionsPerm.cmdFactionsPermShow.getTemplate(false, true, sender)); + + msgDoc("Per default permissions are only granted to ranks within your faction " + + "and a few perms are given to allies, but if you have changed it that will be displayed by the command above."); + msgDoc("When you create a new rank, you will have to set up their perms from scratch."); + + msgDoc("If you want to know what permissions are specifically given to someone do:"); + message(CmdFactions.get().cmdFactionsPerm.cmdFactionsPermView.getTemplate(false, true, sender)); + + msgDoc("To set perms do: "); + message(CmdFactions.get().cmdFactionsPerm.cmdFactionsPermSet.getTemplate(false, true, sender)); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDocumentationPower.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDocumentationPower.java new file mode 100644 index 00000000..41c6ce70 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDocumentationPower.java @@ -0,0 +1,34 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.massivecore.MassiveException; + +public class CmdFactionsDocumentationPower extends FactionsCommandDocumentation { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsDocumentationPower() { + + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + msgDoc("All players have an amount of power ranging from %.2f to %.2f.", MConf.get().powerMin, MConf.get().powerMax); + msgDoc("The power of a faction is equal to the combined power of all it's members."); + msgDoc("Your power is %.2f", msender.getPower()); + msgDoc("Your faction's power is %.2f", msenderFaction.getPower()); + msgDoc("The amount of chunks a faction can claim is the amount power it has."); + msgDoc("For every hour you are online you gain %.2f power.", MConf.get().powerPerHour); + msgDoc("Every time you die you power is decreased by %.2f .", MConf.get().powerPerDeath * -1); + if (!MConf.get().canLeaveWithNegativePower && MConf.get().powerMin < 0) { + msgDoc("You can't leave a faction if your power is negative."); + } + + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDocumentationRanks.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDocumentationRanks.java new file mode 100644 index 00000000..c81ecee9 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDocumentationRanks.java @@ -0,0 +1,52 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.entity.Rank; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.mson.Mson; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.ChatColor; + +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +public class CmdFactionsDocumentationRanks extends FactionsCommandDocumentation { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsDocumentationRanks() { + + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + msgDoc("Ranks divide the faction into groups."); + + List ranks = msenderFaction.getRanks().getAll(Comparator.comparingInt(Rank::getPriority).reversed()); + List rankDesc = ranks.stream().map(r -> r.getDisplayName(msender)).collect(Collectors.toList()); + msgDoc("Your faction has: %s", Txt.implodeCommaAndDot(rankDesc, Txt.parse(""))); + + msgDoc("Ranks can have a prefix that will be prepended before any player name. Prefixes can be coloured."); + msgDoc("All ranks have a priority showed in parentheses after the name."); + + Mson msonLeader = mson("The rank with the highest priority is deemed the “leader rank”" + + "(can be renamed) and only one person can have that rank") + .tooltip("For yor faction the leader rank is" + rankDesc.get(0)) + .color(ChatColor.YELLOW); + messageDoc(msonLeader); + msgDoc("Whenever a new person joins the faction they will be assigned the rank with the lowest priority."); + msgDoc("Priorities are important because they determine who can do what." + + "For example: you can’t kick someone with the same or higher rank than yourself." + + "So if you have both Officers, and Co-leaders, do not fear officers kicking co-leaders or the co-leaders kicking each other." + + "They can’t. The same goes for changing ranks, titles and other similar things."); + + msgDoc("To show, set or edit ranks do:"); + message(CmdFactions.get().cmdFactionsRank.getTemplate(false, true, sender)); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDocumentationTax.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDocumentationTax.java new file mode 100644 index 00000000..fee90621 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDocumentationTax.java @@ -0,0 +1,51 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.req.ReqTaxEnabled; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.money.Money; +import com.massivecraft.massivecore.util.TimeDiffUtil; +import com.massivecraft.massivecore.util.TimeUnit; +import com.massivecraft.massivecore.util.Txt; + +import java.util.LinkedHashMap; + +public class CmdFactionsDocumentationTax extends FactionsCommandDocumentation { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsDocumentationTax() { + this.addRequirements(ReqTaxEnabled.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + LinkedHashMap timeUnitcounts = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(MConf.get().taxTaskPeriodMillis, TimeUnit.getAll()), 3); + String periodString = TimeDiffUtil.formatedVerboose(timeUnitcounts); + + msgDoc("Taxation Period: every %s.", periodString); + + long nextTaxationTime = MConf.get().taxTaskPeriodMillis + MConf.get().taxTaskPeriodMillis; + + msgDoc("Next Taxation: %s", Txt.getTimeDeltaDescriptionRelNow(nextTaxationTime)); + + String minTax = Money.format(MConf.get().taxPlayerMinimum); + String maxTax = Money.format(MConf.get().taxPlayerMaximum); + msgDoc("Taxes for players can be set between %s and %s.", minTax, maxTax); + + double tax = msenderFaction.getTaxForPlayer(msender); + if (tax > 0) { + msgDoc("You pay %s in taxes.", Money.format(tax)); + } else if (tax < 0) { + msgDoc("Instead of taxes you faction pays you %s .", Money.format(tax * -1)); + } else { + msgDoc("You don't pay taxes."); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDocumentationWarps.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDocumentationWarps.java new file mode 100644 index 00000000..9e72b95f --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDocumentationWarps.java @@ -0,0 +1,67 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.req.ReqFactionWarpsEnabled; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.MPerm.MPermable; +import com.massivecraft.massivecore.MassiveException; + +import java.util.Set; + +public class CmdFactionsDocumentationWarps extends FactionsCommandDocumentation { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsDocumentationWarps() { + this.addRequirements(ReqFactionWarpsEnabled.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + msgDoc("A faction can have warps which allows it's members to easily go to important places within the faction."); + + if (MConf.get().warpsMax < 0) { + msgDoc("There is no limit to how many warps a faction can have."); + } else { + msgDoc("A faction can only have %d warps.", MConf.get().warpsMax); + } + + if (MConf.get().warpsMustBeInClaimedTerritory) { + msgDoc("Warps must be within claimed territory."); + } + + if (MConf.get().warpsTeleportToOnDeathActive) { + msgDoc("If your faction has a warp with the name %s you will teleport there after death.", MConf.get().warpsTeleportToOnDeathName); + } + + if (!MConf.get().warpsTeleportAllowedFromEnemyTerritory) { + msgDoc("You can't use faction warps while in enemy territory."); + } + + if (!MConf.get().warpsTeleportAllowedFromDifferentWorld) { + msgDoc("You can't teleporty to a warp from another world."); + } + + if (MConf.get().warpsTeleportAllowedEnemyDistance > 0) { + String str = String.format("You can't teleport home if there is an enemy within %.1f blocks of you", MConf.get().warpsTeleportAllowedEnemyDistance); + if (MConf.get().warpsTeleportIgnoreEnemiesIfInOwnTerritory) { + str += " unless you are in your own territory."; + } else { + str += "."; + } + msgDoc(str); + } + + if (msenderFaction.isNormal()) { + Set set = msenderFaction.getPermittedPermables(MPerm.getPermWarp()); + String permables = CmdFactionsPermShow.permablesToDisplayString(set, msender); + msgDoc("In your faction warps can be used by: %s.", permables); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFaction.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFaction.java new file mode 100644 index 00000000..500ecb6e --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFaction.java @@ -0,0 +1,59 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.event.EventFactionsFactionShowAsync; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.PriorityLines; +import com.massivecraft.massivecore.mixin.MixinMessage; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; + +import java.util.TreeSet; + +public class CmdFactionsFaction extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsFaction() { + // Aliases + this.addAliases("f", "show", "who").setDesc("the faction to show info about"); + + // Parameters + this.addParameter(TypeFaction.get(), "faction", "you"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + final Faction faction = this.readArg(msenderFaction); + final CommandSender sender = this.sender; + + Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> { + // Event + EventFactionsFactionShowAsync event = new EventFactionsFactionShowAsync(sender, faction); + event.run(); + if (event.isCancelled()) { + return; + } + + // Title + MixinMessage.get().messageOne(sender, Txt.titleize("Faction " + faction.getName(msender))); + + // Lines + TreeSet priorityLiness = new TreeSet<>(event.getIdPriorityLiness().values()); + for (PriorityLines priorityLines : priorityLiness) { + MixinMessage.get().messageOne(sender, priorityLines.getLines()); + } + }); + + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFlag.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFlag.java new file mode 100644 index 00000000..863fd57e --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFlag.java @@ -0,0 +1,12 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsFlag extends FactionsCommand { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public CmdFactionsFlagList cmdFactionsFlagList = new CmdFactionsFlagList(); + public CmdFactionsFlagShow cmdFactionsFlagShow = new CmdFactionsFlagShow(); + public CmdFactionsFlagSet cmdFactionsFlagSet = new CmdFactionsFlagSet(); + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFlagList.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFlagList.java new file mode 100644 index 00000000..881d0063 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFlagList.java @@ -0,0 +1,51 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.factions.entity.MFlagColl; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.Parameter; +import com.massivecraft.massivecore.pager.Pager; +import com.massivecraft.massivecore.pager.Stringifier; +import org.bukkit.Bukkit; + +import java.util.List; + +public class CmdFactionsFlagList extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsFlagList() { + // Parameters + this.addParameter(Parameter.getPage()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Parameter + final int page = this.readArg(); + final MPlayer mplayer = msender; + + // Pager create + String title = "Flag List for " + msenderFaction.describeTo(mplayer); + final Pager pager = new Pager<>(this, title, page, (Stringifier) (mflag, index) -> mflag.getStateDesc(false, false, true, true, true, false)); + + Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> { + // Get items + List items = MFlagColl.get().getAll(mplayer.isOverriding() ? null : MFlag::isVisible); + + // Pager items + pager.setItems(items); + + // Pager message + pager.message(); + }); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFlagSet.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFlagSet.java new file mode 100644 index 00000000..e29cddf0 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFlagSet.java @@ -0,0 +1,72 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.cmd.type.TypeMFlag; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.event.EventFactionsFlagChange; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.primitive.TypeBooleanYes; + +public class CmdFactionsFlagSet extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsFlagSet() { + // Parameters + this.addParameter(TypeMFlag.get(), "flag").setDesc("the faction flag to set a value for"); + this.addParameter(TypeBooleanYes.get(), "yes/no").setDesc("should the flag be on or off?"); + this.addParameter(TypeFaction.get(), "faction", "you").setDesc("the faction to set the flag for (per default your own)"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + MFlag flag = this.readArg(); + boolean value = this.readArg(); + Faction faction = this.readArg(msenderFaction); + + // Do the sender have the right to change flags for this faction? + if (!MPerm.getPermFlags().has(msender, faction, true)) { + return; + } + + // Is this flag editable? + if (!msender.isOverriding() && !flag.isEditable()) { + throw new MassiveException().addMsg("The flag %s is not editable.", flag.getName()); + } + + // Event + EventFactionsFlagChange event = new EventFactionsFlagChange(sender, faction, flag, value); + event.run(); + if (event.isCancelled()) { + return; + } + value = event.isNewValue(); + + // No change + if (faction.getFlag(flag) == value) { + throw new MassiveException().addMsg("%s already has %s set to %s.", faction.describeTo(msender), flag.getStateDesc(value, false, true, true, false, true), flag.getStateDesc(value, true, true, false, false, false)); + } + + // Apply + faction.setFlag(flag, value); + + // Inform + String stateInfo = flag.getStateDesc(faction.getFlag(flag), true, false, true, true, true); + if (msender.getFaction() != faction) { + // Send message to sender + msg("%s set a flag for %s.", msender.describeTo(msender, true), faction.describeTo(msender, true)); + message(stateInfo); + } + faction.msg("%s set a flag for %s.", msender.describeTo(faction, true), faction.describeTo(faction, true)); + faction.sendMessage(stateInfo); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFlagShow.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFlagShow.java new file mode 100644 index 00000000..a33eb816 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFlagShow.java @@ -0,0 +1,50 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.collections.MassiveList; +import com.massivecraft.massivecore.command.Parameter; +import com.massivecraft.massivecore.pager.Pager; +import com.massivecraft.massivecore.pager.Stringifier; + +import java.util.List; + +public class CmdFactionsFlagShow extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsFlagShow() { + // Parameters + this.addParameter(TypeFaction.get(), "faction", "you").setDesc("the faction to show flags for"); + this.addParameter(Parameter.getPage()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Parameters + final Faction faction = this.readArg(msenderFaction); + int page = this.readArg(); + + // Pager create + String title = "Flags for " + faction.describeTo(msender); + Pager pager = new Pager<>(this, title, page, MFlag.getAll(), (Stringifier) (mflag, index) -> mflag.getStateDesc(faction.getFlag(mflag), true, true, true, true, true)); + + // Pager args + List pagerArgs = new MassiveList<>( + faction.getId(), + String.valueOf(page) + ); + pager.setArgs(pagerArgs); + + // Pager message + pager.messageAsync(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFly.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFly.java new file mode 100644 index 00000000..58e57dd6 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFly.java @@ -0,0 +1,61 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.engine.EngineFly; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.MassiveCommandToggle; +import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; +import com.massivecraft.massivecore.engine.EngineMassiveCorePlayerUpdate; +import com.massivecraft.massivecore.ps.PS; +import org.bukkit.entity.Player; + +public class CmdFactionsFly extends MassiveCommandToggle { + // -------------------------------------------- // + // INSTANCE + // -------------------------------------------- // + + private static CmdFactionsFly i = new CmdFactionsFly(); + + public static CmdFactionsFly get() { + return i; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsFly() { + this.addRequirements(RequirementIsPlayer.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getName() { + return "faction flying"; + } + + @Override + public boolean getValue() throws MassiveException { + return MPlayer.get(sender).isFlying(); + } + + public void setValue(boolean value) throws MassiveException { + MPlayer mplayer = MPlayer.get(sender); + Player player = me; + if (player == null) { + throw new MassiveException().addMsg("Could not find player."); + } + + PS ps = PS.valueOf(player); + if (value) { + EngineFly.canFlyInTerritoryOrThrow(mplayer, ps); + } + + mplayer.setFlying(value); + EngineMassiveCorePlayerUpdate.update(player, false); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsHome.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsHome.java new file mode 100644 index 00000000..629f3058 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsHome.java @@ -0,0 +1,39 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.Visibility; +import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; +import com.massivecraft.massivecore.util.MUtil; + +import java.util.List; + +public class CmdFactionsHome extends FactionsCommandWarp { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsHome() { + // Requirements + this.addRequirements(RequirementIsPlayer.get()); + + // Parameters + this.addParameter(TypeFaction.get(), "faction", "you"); + + + // Visibility + this.setVisibility(Visibility.INVISIBLE); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + List args = MUtil.list(MConf.get().warpsHomeName, this.argAt(0)); + CmdFactions.get().cmdFactionsWarp.cmdFactionsWarpGo.execute(me, args); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsInvite.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsInvite.java new file mode 100644 index 00000000..adacd5c4 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsInvite.java @@ -0,0 +1,12 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsInvite extends FactionsCommand { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public CmdFactionsInviteList cmdFactionsInviteList = new CmdFactionsInviteList(); + public CmdFactionsInviteAdd cmdFactionsInviteAdd = new CmdFactionsInviteAdd(); + public CmdFactionsInviteRemove cmdFactionsInviteRemove = new CmdFactionsInviteRemove(); + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsInviteAdd.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsInviteAdd.java new file mode 100644 index 00000000..a59af1c0 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsInviteAdd.java @@ -0,0 +1,88 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeMPlayer; +import com.massivecraft.factions.entity.Invitation; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.event.EventFactionsInvitedChange; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.container.TypeSet; +import com.massivecraft.massivecore.mson.Mson; +import com.massivecraft.massivecore.util.IdUtil; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.ChatColor; + +import java.util.Collection; + +public class CmdFactionsInviteAdd extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsInviteAdd() { + // Parameters + this.addParameter(TypeSet.get(TypeMPlayer.get()), "players", true).setDesc("the player to invite"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + Collection mplayers = this.readArg(); + + String senderId = IdUtil.getId(sender); + long creationMillis = System.currentTimeMillis(); + + // MPerm + if (!MPerm.getPermInvite().has(msender, msenderFaction, true)) { + return; + } + + for (MPlayer mplayer : mplayers) { + // Already member? + if (mplayer.getFaction() == msenderFaction) { + msg("%s is already a member of %s.", mplayer.getName(), msenderFaction.getName(msender)); + continue; + } + + // Already invited? + boolean isInvited = msenderFaction.isInvited(mplayer); + + if (!isInvited) { + // Event + EventFactionsInvitedChange event = new EventFactionsInvitedChange(sender, mplayer, msenderFaction, isInvited); + event.run(); + if (event.isCancelled()) { + continue; + } + isInvited = event.isNewInvited(); + + // Inform + mplayer.msg("%s invited you to %s.", msender.describeTo(mplayer, true), msenderFaction.describeTo(mplayer)); + msenderFaction.msg("%s invited %s to your faction.", msender.describeTo(msenderFaction, true), mplayer.describeTo(msenderFaction)); + + // Apply + Invitation invitation = new Invitation(senderId, creationMillis); + msenderFaction.invite(mplayer.getId(), invitation); + msenderFaction.changed(); + } else { + // Mson + String command = CmdFactions.get().cmdFactionsInvite.cmdFactionsInviteRemove.getCommandLine(mplayer.getName()); + String tooltip = Txt.parse("Click to %s.", command); + + Mson remove = Mson.mson( + mson("You might want to remove him. ").color(ChatColor.YELLOW), + mson("Click to " + command).color(ChatColor.RED).tooltip(tooltip).suggest(command) + ); + + // Inform + msg("%s is already invited to %s.", mplayer.getName(), msenderFaction.getName(msender)); + message(remove); + } + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsInviteList.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsInviteList.java new file mode 100644 index 00000000..62270407 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsInviteList.java @@ -0,0 +1,83 @@ +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.Invitation; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.collections.MassiveList; +import com.massivecraft.massivecore.command.Parameter; +import com.massivecraft.massivecore.comparator.ComparatorSmart; +import com.massivecraft.massivecore.mixin.MixinDisplayName; +import com.massivecraft.massivecore.pager.Pager; +import com.massivecraft.massivecore.pager.Stringifier; +import com.massivecraft.massivecore.util.TimeDiffUtil; +import com.massivecraft.massivecore.util.TimeUnit; +import com.massivecraft.massivecore.util.Txt; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map.Entry; + +public class CmdFactionsInviteList extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsInviteList() { + // Parameters + this.addParameter(Parameter.getPage()); + this.addParameter(TypeFaction.get(), "faction", "you").setDesc("the faction to list invites for"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + int page = this.readArg(); + + Faction faction = this.readArg(msenderFaction); + + if (faction != msenderFaction && !Perm.INVITE_LIST_OTHER.has(sender, true)) { + return; + } + + // MPerm + if (!MPerm.getPermInvite().has(msender, msenderFaction, true)) { + return; + } + + // Pager Create + final List> invitations = new MassiveList<>(faction.getInvitations().entrySet()); + + invitations.sort((i1, i2) -> ComparatorSmart.get().compare(i2.getValue().getCreationMillis(), i1.getValue().getCreationMillis())); + + final long now = System.currentTimeMillis(); + + final Pager> pager = new Pager<>(this, "Invited Players List", page, invitations, (Stringifier>) (entry, index) -> { + String inviteeId = entry.getKey(); + String inviterId = entry.getValue().getInviterId(); + + String inviteeDisplayName = MixinDisplayName.get().getDisplayName(inviteeId, sender); + String inviterDisplayName = inviterId != null ? MixinDisplayName.get().getDisplayName(inviterId, sender) : Txt.parse("unknown"); + + String ageDesc = ""; + if (entry.getValue().getCreationMillis() != null) { + long millis = now - entry.getValue().getCreationMillis(); + LinkedHashMap ageUnitcounts = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(millis, TimeUnit.getAllButMillis()), 2); + ageDesc = TimeDiffUtil.formatedMinimal(ageUnitcounts, ""); + ageDesc = " " + ageDesc + Txt.parse(" ago"); + } + + return Txt.parse("%s was invited by %s%s.", inviteeDisplayName, inviterDisplayName, ageDesc); + }); + + // Pager Message + pager.message(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsInviteRemove.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsInviteRemove.java new file mode 100644 index 00000000..c47ed221 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsInviteRemove.java @@ -0,0 +1,136 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeMPlayer; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.event.EventFactionsInvitedChange; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.container.TypeSet; +import com.massivecraft.massivecore.mson.Mson; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.ChatColor; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class CmdFactionsInviteRemove extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + public CmdFactionsInviteRemove() { + // Parameters + this.addParameter(TypeSet.get(TypeMPlayer.get()), "players/all", true).setDesc("the player to deinvite"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + Set mplayers = new HashSet<>(); + boolean all = false; + + // Args + if ("all".equalsIgnoreCase(this.argAt(0))) { + Set ids = msenderFaction.getInvitations().keySet(); + // Doesn't show up if list is empty. Test at home if it worked. + if (ids == null || ids.isEmpty()) { + throw new MassiveException().addMsg("No one is invited to your faction."); + } + all = true; + + for (String id : ids) { + mplayers.add(MPlayer.get(id)); + } + } else { + mplayers = this.readArgAt(0); + } + + // MPerm + if (!MPerm.getPermInvite().has(msender, msenderFaction, true)) { + return; + } + + for (MPlayer mplayer : mplayers) { + // Already member? + if (mplayer.getFaction() == msenderFaction) { + // Mson + String command = CmdFactions.get().cmdFactionsKick.getCommandLine(mplayer.getName()); + String tooltip = Txt.parse("Click to %s.", command); + + Mson kick = Mson.mson( + mson("You might want to kick him. ").color(ChatColor.YELLOW), + mson(ChatColor.RED.toString() + tooltip).tooltip(ChatColor.YELLOW.toString() + tooltip).suggest(command) + ); + + // Inform + msg("%s is already a member of %s.", mplayer.getName(), msenderFaction.getName(msender)); + message(kick); + continue; + } + + // Already invited? + boolean isInvited = msenderFaction.isInvited(mplayer); + + if (isInvited) { + // Event + EventFactionsInvitedChange event = new EventFactionsInvitedChange(sender, mplayer, msenderFaction, isInvited); + event.run(); + if (event.isCancelled()) { + continue; + } + isInvited = event.isNewInvited(); + + // Inform Player + mplayer.msg("%s revoked your invitation to %s.", msender.describeTo(mplayer, true), msenderFaction.describeTo(mplayer)); + + // Inform Faction + if (!all) { + msenderFaction.msg("%s revoked %s's invitation.", msender.describeTo(msenderFaction), mplayer.describeTo(msenderFaction)); + } + + // Apply + msenderFaction.uninvite(mplayer); + + // If all, we do this at last. So we only do it once. + if (!all) { + msenderFaction.changed(); + } + } else { + // Mson + String command = CmdFactions.get().cmdFactionsInvite.cmdFactionsInviteAdd.getCommandLine(mplayer.getName()); + String tooltip = Txt.parse("Click to %s.", command); + + Mson invite = Mson.mson( + mson("You might want to invite him. ").color(ChatColor.YELLOW), + mson(ChatColor.GREEN.toString() + tooltip).tooltip(ChatColor.YELLOW.toString() + tooltip).suggest(command) + ); + + // Inform + msg("%s is not invited to %s.", mplayer.describeTo(msender, true), msenderFaction.describeTo(mplayer)); + message(invite); + } + } + + // Inform Faction if all + if (all) { + List names = new ArrayList<>(); + for (MPlayer mplayer : mplayers) { + names.add(mplayer.describeTo(msender, true)); + } + + Mson factionsRevokeAll = mson( + Mson.parse("%s revoked ", msender.describeTo(msenderFaction)), + Mson.parse("all %s pending invitations", mplayers.size()).tooltip(names), + mson(" from your faction.").color(ChatColor.YELLOW) + ); + + msenderFaction.sendMessage(factionsRevokeAll); + msenderFaction.changed(); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsJoin.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsJoin.java new file mode 100644 index 00000000..96856458 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsJoin.java @@ -0,0 +1,124 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.Perm; +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.cmd.type.TypeMPlayer; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.event.EventFactionsMembershipChange; +import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.mson.Mson; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.ChatColor; + +public class CmdFactionsJoin extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsJoin() { + // Parameters + this.addParameter(TypeFaction.get(), "faction").setDesc("the faction to join"); + this.addParameter(TypeMPlayer.get(), "player", "you").setDesc("the player that should join tje faction (for admins only)"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + Faction faction = this.readArg(); + + MPlayer mplayer = this.readArg(msender); + Faction mplayerFaction = mplayer.getFaction(); + + boolean samePlayer = mplayer == msender; + + // Validate + if (!samePlayer && !Perm.JOIN_OTHERS.has(sender, false)) { + msg("You do not have permission to move other players into a faction."); + return; + } + + if (faction == mplayerFaction) { + String command = CmdFactions.get().cmdFactionsKick.getCommandLine(mplayer.getName()); + + // Mson creation + Mson alreadyMember = Mson.mson( + Mson.parse(mplayer.describeTo(msender, true)), + mson((samePlayer ? " are" : " is") + " already a member of " + faction.getName(msender) + ".").color(ChatColor.YELLOW) + ); + + message(alreadyMember.suggest(command).tooltip(Txt.parse("Click to %s.", command))); + return; + } + + if (MConf.get().factionMemberLimit > 0 && faction.getMPlayers().size() >= MConf.get().factionMemberLimit) { + msg(" ! The faction %s is at the limit of %d members, so %s cannot currently join.", faction.getName(msender), MConf.get().factionMemberLimit, mplayer.describeTo(msender, false)); + return; + } + + if (mplayerFaction.isNormal()) { + String command = CmdFactions.get().cmdFactionsLeave.getCommandLine(mplayer.getName()); + + // Mson creation + Mson leaveFirst = Mson.mson( + Mson.parse(mplayer.describeTo(msender, true)), + mson(" must leave " + (samePlayer ? "your" : "their") + " current faction first.").color(ChatColor.RED) + ); + + message(leaveFirst.suggest(command).tooltip(Txt.parse("Click to %s.", command))); + return; + } + + if (!MConf.get().canLeaveWithNegativePower && mplayer.getPower() < 0) { + msg("%s cannot join a faction with a negative power level.", mplayer.describeTo(msender, true)); + return; + } + + if (!(faction.getFlag(MFlag.getFlagOpen()) || faction.isInvited(mplayer) || msender.isOverriding())) { + msg("This faction requires invitation."); + if (samePlayer) { + faction.msg("%s tried to join your faction.", mplayer.describeTo(faction, true)); + } + return; + } + + // Event + EventFactionsMembershipChange membershipChangeEvent = new EventFactionsMembershipChange(sender, msender, faction, MembershipChangeReason.JOIN); + membershipChangeEvent.run(); + if (membershipChangeEvent.isCancelled()) { + return; + } + + // Inform + if (!samePlayer) { + mplayer.msg("%s moved you into the faction %s.", msender.describeTo(mplayer, true), faction.getName(mplayer)); + } + faction.msg("%s joined your faction.", mplayer.describeTo(faction, true)); + msender.msg("%s successfully joined %s.", mplayer.describeTo(msender, true), faction.getName(msender)); + + // Apply + mplayer.resetFactionData(); + mplayer.setFaction(faction); + mplayer.setRank(faction.getLowestRank()); + + faction.uninvite(mplayer); + + // Derplog + if (MConf.get().logFactionJoin) { + if (samePlayer) { + Factions.get().log(Txt.parse("%s joined the faction %s.", mplayer.getName(), faction.getName())); + } else { + Factions.get().log(Txt.parse("%s moved the player %s into the faction %s.", msender.getName(), mplayer.getName(), faction.getName())); + } + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsKick.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsKick.java new file mode 100644 index 00000000..534aed3d --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsKick.java @@ -0,0 +1,91 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.cmd.type.TypeMPlayer; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.event.EventFactionsMembershipChange; +import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.util.IdUtil; +import org.bukkit.ChatColor; + +public class CmdFactionsKick extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsKick() { + // Parameters + this.addParameter(TypeMPlayer.get(), "player").setDesc("the player to kick"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Arg + MPlayer mplayer = this.readArg(); + + // Validate + if (msender == mplayer) { + msg("You can't kick yourself."); + message(mson(mson("You might want to: ").color(ChatColor.YELLOW), CmdFactions.get().cmdFactionsLeave.getTemplate(false))); + return; + } + + if (!msender.isOverriding() && mplayer.getRank().isLeader()) { + throw new MassiveException().addMsg("The leader cannot be kicked."); + } + + if (!msender.isOverriding() && mplayer.getFaction() == msenderFaction && mplayer.getRank().isMoreThan(msender.getRank())) { + throw new MassiveException().addMsg("You can't kick people of higher rank than yourself."); + } + + if (!msender.isOverriding() && mplayer.getRank() == msender.getRank()) { + throw new MassiveException().addMsg("You can't kick people of the same rank as yourself."); + } + + if (!msender.isOverriding() && !MConf.get().canLeaveWithNegativePower && mplayer.getPower() < 0) { + msg("You can't kick that person until their power is positive."); + return; + } + + // MPerm + Faction mplayerFaction = mplayer.getFaction(); + if (!MPerm.getPermKick().has(msender, mplayerFaction, true)) { + return; + } + + // Event + EventFactionsMembershipChange event = new EventFactionsMembershipChange(sender, mplayer, FactionColl.get().getNone(), MembershipChangeReason.KICK); + event.run(); + if (event.isCancelled()) { + return; + } + + // Inform + mplayerFaction.msg("%s kicked %s from the faction! :O", msender.describeTo(mplayerFaction, true), mplayer.describeTo(mplayerFaction, true)); + mplayer.msg("%s kicked you from %s! :O", msender.describeTo(mplayer, true), mplayerFaction.describeTo(mplayer)); + if (mplayerFaction != msenderFaction) { + msender.msg("You kicked %s from the faction %s!", mplayer.describeTo(msender), mplayerFaction.describeTo(msender)); + } + + if (MConf.get().logFactionKick) { + Factions.get().log(msender.getDisplayName(IdUtil.getConsole()) + " kicked " + mplayer.getName() + " from the faction " + mplayerFaction.getName()); + } + + // Apply + if (mplayer.getRank().isLeader()) { + mplayerFaction.promoteNewLeader(); + } + mplayerFaction.uninvite(mplayer); + mplayer.resetFactionData(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsLeave.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsLeave.java new file mode 100644 index 00000000..dd775b10 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsLeave.java @@ -0,0 +1,24 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.req.ReqHasFaction; + +public class CmdFactionsLeave extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsLeave() { + // Requirements + this.addRequirements(ReqHasFaction.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() { + msender.leave(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsList.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsList.java new file mode 100644 index 00000000..09f1f12b --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsList.java @@ -0,0 +1,68 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.comparator.ComparatorFactionList; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.factions.entity.MPlayer; +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.util.Txt; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; + +import java.util.List; + +public class CmdFactionsList extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsList() { + // Parameters + this.addParameter(Parameter.getPage()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + int page = this.readArg(); + final CommandSender sender = this.sender; + final MPlayer msender = this.msender; + + // NOTE: The faction list is quite slow and mostly thread safe. + // We run it asynchronously to spare the primary server thread. + + // Pager Create + final Pager pager = new Pager<>(this, "Faction List", page, (Stringifier) (faction, index) -> { + if (faction.isNone()) { + return Txt.parse("Factionless %d online", FactionColl.get().getNone().getMPlayersWhereOnlineTo(sender).size()); + } else { + return Txt.parse("%s %d/%d online, %d/%d/%d", + faction.getName(msender), + faction.getMPlayersWhereOnlineTo(sender).size(), + faction.getMPlayers().size(), + faction.getLandCount(), + faction.getPowerRounded(), + faction.getPowerMaxRounded() + ); + } + }); + + Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> { + // Pager Items + final List factions = FactionColl.get().getAll(ComparatorFactionList.get(sender)); + pager.setItems(factions); + + // Pager Message + pager.message(); + }); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMap.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMap.java new file mode 100644 index 00000000..a16e8bb4 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMap.java @@ -0,0 +1,58 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.util.AsciiMap; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; +import com.massivecraft.massivecore.command.type.primitive.TypeBooleanYes; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.Txt; + +public class CmdFactionsMap extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsMap() { + // Parameters + this.addParameter(TypeBooleanYes.get(), "on/off", "once").setDesc("set to yes to get an auto updating map\nset to no to disable"); + + // Requirements + this.addRequirements(RequirementIsPlayer.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // NOTE: Map show is performed when auto == true || once + boolean argSet = this.argIsSet(); + boolean showMap = true; + + // Auto update + if (argSet) { + showMap = this.adjustAutoUpdating(); + } + if (!showMap) { + return; + } + + // Show Map + AsciiMap map = new AsciiMap(msender, PS.valueOf(me), !argSet); + message(map.render()); + } + + private boolean adjustAutoUpdating() throws MassiveException { + // Get + boolean autoUpdating = this.readArg(!msender.isMapAutoUpdating()); + + // Set + msender.setMapAutoUpdating(autoUpdating); + + // Inform + msg("Map auto update %s.", Txt.parse(autoUpdating ? "ENABLED" : "DISABLED")); + return autoUpdating; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMoney.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMoney.java new file mode 100644 index 00000000..f62bc9ea --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMoney.java @@ -0,0 +1,26 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled; + +public class CmdFactionsMoney extends FactionsCommand { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public CmdFactionsMoneyBalance cmdMoneyBalance = new CmdFactionsMoneyBalance(); + public CmdFactionsMoneyDeposit cmdMoneyDeposit = new CmdFactionsMoneyDeposit(); + public CmdFactionsMoneyWithdraw cmdMoneyWithdraw = new CmdFactionsMoneyWithdraw(); + public CmdFactionsMoneyTransferF2f cmdMoneyTransferFf = new CmdFactionsMoneyTransferF2f(); + public CmdFactionsMoneyTransferF2p cmdMoneyTransferFp = new CmdFactionsMoneyTransferF2p(); + public CmdFactionsMoneyTransferP2f cmdMoneyTransferPf = new CmdFactionsMoneyTransferP2f(); + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsMoney() { + // Requirements + this.addRequirements(ReqBankCommandsEnabled.get()); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMoneyBalance.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMoneyBalance.java new file mode 100644 index 00000000..8e3f7fef --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMoneyBalance.java @@ -0,0 +1,38 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Perm; +import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled; +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.integration.Econ; +import com.massivecraft.massivecore.MassiveException; + +public class CmdFactionsMoneyBalance extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsMoneyBalance() { + // Parameters + this.addParameter(TypeFaction.get(), "faction", "you").setDesc("the faction whose balance to check"); + + // Requirements + this.addRequirements(ReqBankCommandsEnabled.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + Faction faction = this.readArg(msenderFaction); + + if (faction != msenderFaction && !Perm.MONEY_BALANCE_ANY.has(sender, true)) { + return; + } + + Econ.sendBalanceInfo(msender, faction); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMoneyDeposit.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMoneyDeposit.java new file mode 100644 index 00000000..4eff9095 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMoneyDeposit.java @@ -0,0 +1,46 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled; +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.integration.Econ; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.primitive.TypeDouble; +import com.massivecraft.massivecore.money.Money; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.ChatColor; + +public class CmdFactionsMoneyDeposit extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsMoneyDeposit() { + // Parameters + this.addParameter(TypeDouble.get(), "amount").setDesc("the amount of money to deposit"); + this.addParameter(TypeFaction.get(), "faction", "you").setDesc("the faction to deposit money to"); + + // Requirements + this.addRequirements(ReqBankCommandsEnabled.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + double amount = this.readArg(); + + Faction faction = this.readArg(msenderFaction); + + boolean success = Econ.transferMoney(msender, msender, faction, amount); + + if (success && MConf.get().logMoneyTransactions) { + Factions.get().log(ChatColor.stripColor(Txt.parse("%s deposited %s in the faction bank: %s", msender.getName(), Money.format(amount), faction.describeTo(null)))); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferF2f.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferF2f.java new file mode 100644 index 00000000..a4f67f59 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferF2f.java @@ -0,0 +1,53 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled; +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.integration.Econ; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.primitive.TypeDouble; +import com.massivecraft.massivecore.money.Money; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.ChatColor; + +public class CmdFactionsMoneyTransferF2f extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsMoneyTransferF2f() { + // Fields + this.setSetupEnabled(false); + + // Aliases + this.addAliases("ff"); + + // Parameters + this.addParameter(TypeDouble.get(), "amount").setDesc("the amount of money to transfer"); + this.addParameter(TypeFaction.get(), "faction").setDesc("the faction to transfer money from"); + this.addParameter(TypeFaction.get(), "faction").setDesc("the faction to transfer money to"); + + // Requirements + this.addRequirements(ReqBankCommandsEnabled.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + double amount = this.readArg(); + Faction from = this.readArg(); + Faction to = this.readArg(); + + boolean success = Econ.transferMoney(msender, from, to, amount); + + if (success && MConf.get().logMoneyTransactions) { + Factions.get().log(ChatColor.stripColor(Txt.parse("%s transferred %s from the faction \"%s\" to the faction \"%s\"", msender.getName(), Money.format(amount), from.describeTo(null), to.describeTo(null)))); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferF2p.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferF2p.java new file mode 100644 index 00000000..f11d9fb0 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferF2p.java @@ -0,0 +1,55 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled; +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.cmd.type.TypeMPlayer; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.integration.Econ; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.primitive.TypeDouble; +import com.massivecraft.massivecore.money.Money; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.ChatColor; + +public class CmdFactionsMoneyTransferF2p extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsMoneyTransferF2p() { + // Fields + this.setSetupEnabled(false); + + // Aliases + this.addAliases("fp"); + + // Parameters + this.addParameter(TypeDouble.get(), "amount").setDesc("the amount of money to transfer"); + this.addParameter(TypeFaction.get(), "faction").setDesc("the faction to transfer money from"); + this.addParameter(TypeMPlayer.get(), "player").setDesc("the player to transfer money to"); + + // Requirements + this.addRequirements(ReqBankCommandsEnabled.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + double amount = this.readArg(); + Faction from = this.readArg(); + MPlayer to = this.readArg(); + + boolean success = Econ.transferMoney(msender, from, to, amount); + + if (success && MConf.get().logMoneyTransactions) { + Factions.get().log(ChatColor.stripColor(Txt.parse("%s transferred %s from the faction \"%s\" to the player \"%s\"", msender.getName(), Money.format(amount), from.describeTo(null), to.describeTo(null)))); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferP2f.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferP2f.java new file mode 100644 index 00000000..240f0456 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferP2f.java @@ -0,0 +1,55 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled; +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.cmd.type.TypeMPlayer; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.integration.Econ; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.primitive.TypeDouble; +import com.massivecraft.massivecore.money.Money; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.ChatColor; + +public class CmdFactionsMoneyTransferP2f extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsMoneyTransferP2f() { + // Fields + this.setSetupEnabled(false); + + // Aliases + this.addAliases("pf"); + + // Parameters + this.addParameter(TypeDouble.get(), "amount").setDesc("the amount of money to transfer"); + this.addParameter(TypeMPlayer.get(), "player").setDesc("the player to transfer money from"); + this.addParameter(TypeFaction.get(), "faction").setDesc("the faction to transfer money to"); + + // Requirements + this.addRequirements(ReqBankCommandsEnabled.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + double amount = this.readArg(); + MPlayer from = this.readArg(); + Faction to = this.readArg(); + + boolean success = Econ.transferMoney(msender, from, to, amount); + + if (success && MConf.get().logMoneyTransactions) { + Factions.get().log(ChatColor.stripColor(Txt.parse("%s transferred %s from the player \"%s\" to the faction \"%s\"", msender.getName(), Money.format(amount), from.describeTo(null), to.describeTo(null)))); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMoneyWithdraw.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMoneyWithdraw.java new file mode 100644 index 00000000..1525866a --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMoneyWithdraw.java @@ -0,0 +1,48 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled; +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.integration.Econ; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.primitive.TypeDouble; +import com.massivecraft.massivecore.money.Money; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.ChatColor; + +public class CmdFactionsMoneyWithdraw extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsMoneyWithdraw() { + // Parameters + this.addParameter(TypeDouble.get(), "amount").setDesc("the amount of money to withdraw"); + this.addParameter(TypeFaction.get(), "faction", "you").setDesc("the faction to transfer money to"); + + // Requirements + this.addRequirements(ReqBankCommandsEnabled.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + Double amount = this.readArg(); + Faction from = this.readArg(msenderFaction); + + MPlayer to = msender; + + boolean success = Econ.transferMoney(msender, from, to, amount); + + if (success && MConf.get().logMoneyTransactions) { + Factions.get().log(ChatColor.stripColor(Txt.parse("%s withdrew %s from the faction bank: %s", msender.getName(), Money.format(amount), from.describeTo(null)))); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMoneyconvert.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMoneyconvert.java new file mode 100644 index 00000000..9e9c95ed --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMoneyconvert.java @@ -0,0 +1,69 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.Visibility; +import com.massivecraft.massivecore.command.type.primitive.TypeStringConfirmation; +import com.massivecraft.massivecore.money.Money; +import com.massivecraft.massivecore.util.ConfirmationUtil; + +public class CmdFactionsMoneyconvert extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsMoneyconvert() { + // Parameters + this.addParameter(TypeStringConfirmation.get(), "confirmation", ""); + + // Low priority + this.setPriority(-100); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Visibility getVisibility() { + //return Visibility.INVISIBLE; + return MConf.get().useNewMoneySystem ? Visibility.INVISIBLE : Visibility.SECRET; + } + + @Override + public void perform() throws MassiveException { + if (MConf.get().useNewMoneySystem) { + throw new MassiveException().addMsg("The economy system is already converted."); + } + + // Args + if (!this.argIsSet(0)) { + msg("Money in Factions used to be stored within the applicable economy plugin." + + " This is problematic because not all economy plugins support that." + + " This command allows to convert to the new system where the money of a Faction" + + " is stored within the Factions plugin. Then all economy plugins can be used with Factions."); + } + + ConfirmationUtil.tryConfirm(this); + + MConf.get().useNewMoneySystem = true; + + for (Faction f : FactionColl.get().getAll()) { + if (!Money.exists(f)) { + msg("%s does not have any money.", f.getName()); + continue; + } + + double money = Money.get(f); + f.setMoney(money); + + Money.set(f, null, 0); + + msg("%s has %s and has been converted.", f.getName(), Money.format(money)); + } + msg("Converted all factions. Hooray!"); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMotd.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMotd.java new file mode 100644 index 00000000..ada49808 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMotd.java @@ -0,0 +1,75 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.event.EventFactionsMotdChange; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.TypeNullable; +import com.massivecraft.massivecore.command.type.primitive.TypeString; +import com.massivecraft.massivecore.mixin.MixinDisplayName; +import com.massivecraft.massivecore.util.MUtil; +import com.massivecraft.massivecore.util.Txt; + +public class CmdFactionsMotd extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsMotd() { + // Parameters + this.addParameter(TypeNullable.get(TypeString.get()), "new", "read", true).setDesc("the new motd\nif not specified you will just see the current one"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Read + if (!this.argIsSet(0)) { + message(msenderFaction.getMotdMessages()); + return; + } + + // MPerm + if (!MPerm.getPermMotd().has(msender, msenderFaction, true)) { + return; + } + + // Args + String target = this.readArg(); + + if (target != null) { + target = target.trim(); + target = Txt.parse(target); + } + + // Get Old + String old = msenderFaction.getMotd(); + + // NoChange + if (MUtil.equals(old, target)) { + msg("The motd for %s is already: %s", msenderFaction.describeTo(msender, true), msenderFaction.getMotdDesc()); + return; + } + + // Event + EventFactionsMotdChange event = new EventFactionsMotdChange(sender, msenderFaction, target); + event.run(); + if (event.isCancelled()) { + return; + } + target = event.getNewMotd(); + + // Apply + msenderFaction.setMotd(target); + + // Inform + for (MPlayer follower : msenderFaction.getMPlayers()) { + follower.msg("%s changed your faction motd.", MixinDisplayName.get().getDisplayName(sender, follower)); + follower.message(msenderFaction.getMotdMessages()); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsName.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsName.java new file mode 100644 index 00000000..6220d9fb --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsName.java @@ -0,0 +1,54 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.cmd.type.TypeFactionNameLenient; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.event.EventFactionsNameChange; +import com.massivecraft.massivecore.MassiveException; + +public class CmdFactionsName extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsName() { + // Parameters + this.addParameter(TypeFactionNameLenient.get(), "new name").setDesc("the new name of the faction"); + this.addParameter(TypeFaction.get(), "faction", "you").setDesc("the faction whose name to change"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + String newName = this.readArg(); + Faction faction = this.readArg(msenderFaction); + + // MPerm + if (!MPerm.getPermName().has(msender, faction, true)) { + return; + } + + // Event + EventFactionsNameChange event = new EventFactionsNameChange(sender, faction, newName); + event.run(); + if (event.isCancelled()) { + return; + } + newName = event.getNewName(); + + // Apply + faction.setName(newName); + + // Inform + faction.msg("%s changed your faction name to %s", msender.describeTo(faction, true), faction.getName(faction)); + if (msenderFaction != faction) { + msg("You changed the faction name to %s", faction.getName(msender)); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsOverride.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsOverride.java new file mode 100644 index 00000000..8d448136 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsOverride.java @@ -0,0 +1,44 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Factions; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.primitive.TypeBooleanYes; +import com.massivecraft.massivecore.util.IdUtil; +import com.massivecraft.massivecore.util.Txt; + +public class CmdFactionsOverride extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsOverride() { + // Aliases + this.addAliases("admin"); + + // Parameters + this.addParameter(TypeBooleanYes.get(), "on/off", "flip"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + boolean target = this.readArg(!msender.isOverriding()); + + // Apply + msender.setOverriding(target); + + // Inform + String desc = Txt.parse(msender.isOverriding() ? "ENABLED" : "DISABLED"); + + String messageYou = Txt.parse("%s %s override mode.", msender.getDisplayName(msender), desc); + String messageLog = Txt.parse("%s %s override mode.", msender.getDisplayName(IdUtil.getConsole()), desc); + + msender.message(messageYou); + Factions.get().log(messageLog); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPerm.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPerm.java new file mode 100644 index 00000000..1be3ec07 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPerm.java @@ -0,0 +1,14 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsPerm extends FactionsCommand { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + CmdFactionsPermList cmdFactionsPermList = new CmdFactionsPermList(); + CmdFactionsPermShow cmdFactionsPermShow = new CmdFactionsPermShow(); + CmdFactionsPermView cmdFactionsPermView = new CmdFactionsPermView(); + CmdFactionsPermViewall cmdFactionsPermViewall = new CmdFactionsPermViewall(); + CmdFactionsPermSet cmdFactionsPermSet = new CmdFactionsPermSet(); + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPermList.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPermList.java new file mode 100644 index 00000000..41d02aa4 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPermList.java @@ -0,0 +1,51 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.MPermColl; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.Parameter; +import com.massivecraft.massivecore.pager.Pager; +import com.massivecraft.massivecore.pager.Stringifier; +import org.bukkit.Bukkit; + +import java.util.List; +import java.util.function.Predicate; + +public class CmdFactionsPermList extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsPermList() { + // Parameters + this.addParameter(Parameter.getPage()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Parameter + int page = this.readArg(); + + // Pager create + String title = String.format("Perms for %s", msenderFaction.describeTo(msender)); + final Pager pager = new Pager<>(this, title, page, (Stringifier) (mp, i) -> mp.getDesc(true, true)); + final Predicate predicate = msender.isOverriding() ? null : MPerm::isVisible; + + Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> { + // Get items + List items = MPermColl.get().getAll(predicate); + + // Pager items + pager.setItems(items); + + // Pager message + pager.message(); + }); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPermSet.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPermSet.java new file mode 100644 index 00000000..5d43cc7b --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPermSet.java @@ -0,0 +1,80 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.cmd.type.TypeMPerm; +import com.massivecraft.factions.cmd.type.TypeMPermable; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.event.EventFactionsPermChange; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.primitive.TypeBooleanYes; +import com.massivecraft.massivecore.util.Txt; + +public class CmdFactionsPermSet extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsPermSet() { + // Parameters + this.addParameter(TypeMPerm.get(), "perm"); + this.addParameter(TypeMPermable.get(), "rank/rel/player/faction"); + this.addParameter(TypeBooleanYes.get(), "yes/no"); + this.addParameter(TypeFaction.get(), "faction", "you"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + MPerm perm = this.readArgAt(0); + Boolean value = this.readArgAt(2); + Faction faction = this.readArgAt(3, msenderFaction); + + MPerm.MPermable permable = TypeMPermable.get(faction).read(this.argAt(1), sender); + + // Do the sender have the right to change perms for this faction? + if (!MPerm.getPermPerms().has(msender, faction, true)) { + return; + } + + // Is this perm editable? + if (!msender.isOverriding() && !perm.isEditable()) { + throw new MassiveException().addMsg("The perm %s is not editable.", perm.getName()); + } + + if (permable == faction) { + throw new MassiveException().addMsg("A faction can't have perms for itself. Perhaps try ranks."); + } + + // Event + EventFactionsPermChange event = new EventFactionsPermChange(sender, faction, perm, permable, value); + event.run(); + if (event.isCancelled()) { + return; + } + value = event.getNewValue(); + + // Apply + boolean change = faction.setPermitted(permable, perm, value); + + // No change + if (!change) { + throw new MassiveException().addMsg("%s already has %s set to %s for %s.", faction.describeTo(msender), perm.getDesc(true, false), Txt.parse(value ? "YES" : "NOO"), permable.getDisplayName(msender)); + } + + // The following is to make sure the leader always has the right to change perms if that is our goal. + if (perm == MPerm.getPermPerms() && MConf.get().perm2default.get(MPerm.ID_PERMS).contains("LEADER")) { + faction.setPermitted(faction.getLeaderRank(), MPerm.getPermPerms(), true); + } + + // Inform sender + String yesNo = Txt.parse(value ? "YES" : "NOO"); + msg("Set perm %s to %s for %s in %s.", perm.getName(), yesNo, permable.getDisplayName(msender), faction.describeTo(msender)); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPermShow.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPermShow.java new file mode 100644 index 00000000..f8b93306 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPermShow.java @@ -0,0 +1,81 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.cmd.type.TypeMPerm; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.MPerm.MPermable; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.collections.MassiveList; +import com.massivecraft.massivecore.util.Txt; + +import java.util.Collection; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +public class CmdFactionsPermShow extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsPermShow() { + // Parameters + this.addParameter(TypeMPerm.get(), "perm"); + this.addParameter(TypeFaction.get(), "faction", "you"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Arg: Faction + MPerm mperm = this.readArg(); + Faction faction = this.readArg(msenderFaction); + + Set permittedIds = faction.getPerms().get(mperm.getId()); + List permables = new MassiveList<>(); + + for (String permitted : permittedIds) { + permables.add(MPerm.idToMPermable(permitted)); + } + + String removeString = Txt.parse(" of ") + faction.getDisplayName(msender); + List permableList = permables.stream() + .map(permable -> permable.getDisplayName(msender)) + .map(s -> s.replace(removeString, "")) + .collect(Collectors.toList()); + String permableNames = Txt.implodeCommaAnd(permableList, Txt.parse("")); + + // Create messages + msg("In %s permission %s is granted to %s.", faction.describeTo(msender), mperm.getDesc(true, false), permableNames); + } + + @Deprecated + public static MPerm.MPermable idToMPermable(String id) { + return MPerm.idToMPermable(id); + } + + public static String permablesToDisplayString(Collection permables, Object watcherObject) { + MPlayer mplayer = MPlayer.get(watcherObject); + Faction faction = mplayer.getFaction(); + + String removeString; + if (faction.isNone()) { + removeString = ""; + } else { + removeString = Txt.parse(" of ") + faction.getDisplayName(mplayer); + } + + List permableList = permables.stream() + .map(permable -> permable.getDisplayName(mplayer)) + .map(s -> s.replace(removeString, "")) + .collect(Collectors.toList()); + + return Txt.implodeCommaAnd(permableList, Txt.parse("")); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPermView.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPermView.java new file mode 100644 index 00000000..5c049f41 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPermView.java @@ -0,0 +1,98 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.cmd.type.TypeMPermable; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.entity.Rank; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.collections.MassiveList; +import com.massivecraft.massivecore.mson.Mson; +import com.massivecraft.massivecore.util.MUtil; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.ChatColor; + +import java.util.List; +import java.util.stream.Collectors; + +public class CmdFactionsPermView extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsPermView() { + // Parameters + this.addParameter(TypeMPermable.get(), "rank/rel/player/faction"); + this.addParameter(TypeFaction.get(), "faction", "you"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Arg: Faction + Faction faction = this.readArgAt(1, msenderFaction); + TypeMPermable permableType = TypeMPermable.get(faction); + MPerm.MPermable permable = permableType.read(this.argAt(0), sender); + + if (permable == faction) { + throw new MassiveException().addMsg("A faction can't have perms for itself."); + } + + List perms = new MassiveList<>(); + + for (MPerm mperm : MPerm.getAll()) { + if (faction.isPermitted(permable.getId(), mperm.getId())) { + perms.add(mperm); + } + } + + if (perms.isEmpty()) { + msg("In %s %s specifically has no permissions.", faction.describeTo(msender), permable.getDisplayName(sender)); + } else { + List permNames = perms.stream().map(perm -> Txt.parse("") + perm.getName()).collect(Collectors.toList()); + String names = Txt.implodeCommaAnd(permNames, Txt.parse("")); + + // Create messages + String permissionSingularPlural = permNames.size() == 1 ? "permission" : "permissions"; + msg("In %s %s specifically has the %s: %s.", faction.describeTo(msender), permable.getDisplayName(sender), permissionSingularPlural, names); + } + if (permable instanceof MPlayer) { + MPlayer mplayer = (MPlayer) permable; + msg("They may have other permissions through their faction membership, rank or relation to %s.", faction.describeTo(msender)); + + List msons = new MassiveList<>(); + + if (mplayer.getFaction() != faction) { + msons.add(Mson.parse("[faction]").command(this, mplayer.getFaction().getName(), faction.getName())); + } + msons.add(Mson.parse("[rank]").command(this, mplayer.getFaction().getName() + "-" + mplayer.getRank().getName(), faction.getName())); + if (mplayer.getFaction() != faction) { + msons.add(Mson.parse("[relation]").command(this, faction.getRelationTo(mplayer).toString(), faction.getName())); + } + Mson msons2 = Mson.implode(msons, Mson.SPACE); + message(mson(mson("Commands: ").color(ChatColor.YELLOW), msons2)); + } + if (permable instanceof Faction) { + Faction faction1 = (Faction) permable; + msg("They may have other permissions through their relation to %s.", faction.describeTo(msender)); + Mson msonRelation = Mson.parse("[relation]").command(this, faction.getRelationTo(faction1).toString(), faction.getName()); + Mson msons = Mson.implode(MUtil.list(msonRelation), Mson.SPACE); + message(mson(mson("Commands: ").color(ChatColor.YELLOW), msons)); + } + if (permable instanceof Rank && !faction.hasRank((Rank) permable)) { + Rank rank = (Rank) permable; + msg("They may have other permissions thorugh their faction membership or relation to %s.", faction.describeTo(msender)); + Mson msonFaction = Mson.parse("[faction]").command(this, rank.getFaction().getName(), faction.getName()); + Mson msonRelation = Mson.parse("[relation]").command(this, faction.getRelationTo(rank.getFaction()).toString(), faction.getName()); + Mson msons = Mson.implode(MUtil.list(msonFaction, msonRelation), Mson.SPACE); + message(mson(mson("Commands: ").color(ChatColor.YELLOW), msons)); + } + msg("To view all perms held by %s type:", permable.getDisplayName(sender)); + message(CmdFactions.get().cmdFactionsPerm.cmdFactionsPermViewall.getTemplateWithArgs(sender, MUtil.list(permable.getName(), faction.getName()))); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPermViewall.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPermViewall.java new file mode 100644 index 00000000..c01d47b8 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPermViewall.java @@ -0,0 +1,94 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.cmd.type.TypeMPermable; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.MPerm.MPermable; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.entity.Rank; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.collections.MassiveList; +import com.massivecraft.massivecore.util.Txt; + +import java.util.List; +import java.util.stream.Collectors; + +public class CmdFactionsPermViewall extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsPermViewall() { + // Parameters + this.addParameter(TypeMPermable.get(), "rank/rel/player/faction"); + this.addParameter(TypeFaction.get(), "faction", "you"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Arg: Faction + Faction faction = this.readArgAt(1, msenderFaction); + TypeMPermable permableType = TypeMPermable.get(faction); + MPerm.MPermable permable = permableType.read(this.argAt(0), sender); + + // Self check + if (permable == faction) { + throw new MassiveException().addMsg("A faction can't have perms for itself."); + } + + // Create list of all applicable permables + List permables = new MassiveList<>(); + permables.add(permable); + + if (permable instanceof MPlayer) { + MPlayer mplayer = (MPlayer) permable; + permables.add(mplayer.getFaction()); + permables.add(mplayer.getRank()); + permables.add(faction.getRelationTo(mplayer)); + } + if (permable instanceof Faction) { + Faction faction1 = (Faction) permable; + permables.add(faction.getRelationTo(faction1)); + } + if (permable instanceof Rank && !faction.hasRank((Rank) permable)) { + Rank rank = (Rank) permable; + Faction faction1 = rank.getFaction(); + permables.add(faction1); + permables.add(faction.getRelationTo(faction1)); + } + + // Find the perms they have + List perms = new MassiveList<>(); + + perm: + for (MPerm mperm : MPerm.getAll()) { + String mpermId = mperm.getId(); + permable: + for (MPermable mpa : permables) { + if (!faction.isPermitted(mpa.getId(), mperm.getId())) { + continue permable; + } + perms.add(mperm); + continue perm; + } + + } + + if (perms.isEmpty()) { + msg("In %s %s has no permissions.", faction.describeTo(msender), permable.getDisplayName(sender)); + } else { + List permNames = perms.stream().map(perm -> Txt.parse("") + perm.getName()).collect(Collectors.toList()); + String names = Txt.implodeCommaAnd(permNames, Txt.parse("")); + + // Create messages + String permissionSingularPlural = permNames.size() == 1 ? "permission" : "permissions"; + msg("In %s %s has the %s: %s either specifically granted to them or through rank, relation or faction membership.", faction.describeTo(msender), permable.getDisplayName(sender), permissionSingularPlural, names); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPlayer.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPlayer.java new file mode 100644 index 00000000..f48328a2 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPlayer.java @@ -0,0 +1,103 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeMPlayer; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.Progressbar; +import com.massivecraft.massivecore.event.EventMassiveCorePlayerCleanInactivityToleranceMillis; +import com.massivecraft.massivecore.util.TimeDiffUtil; +import com.massivecraft.massivecore.util.TimeUnit; +import com.massivecraft.massivecore.util.Txt; + +import java.util.LinkedHashMap; +import java.util.Map.Entry; + +public class CmdFactionsPlayer extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsPlayer() { + // Parameters + this.addParameter(TypeMPlayer.get(), "player", "you"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + MPlayer mplayer = this.readArg(msender); + + // INFO: Title + message(Txt.titleize("Player " + mplayer.describeTo(msender))); + + // INFO: Rank + msg("Rank: %s", mplayer.getRank().getDisplayName(sender)); + + // INFO: Power (as progress bar) + double progressbarQuota = 0; + double playerPowerMax = mplayer.getPowerMax(); + if (playerPowerMax != 0) { + progressbarQuota = mplayer.getPower() / playerPowerMax; + } + + int progressbarWidth = (int) Math.round(mplayer.getPowerMax() / mplayer.getPowerMaxUniversal() * 100); + msg("Power: %s", Progressbar.HEALTHBAR_CLASSIC.withQuota(progressbarQuota).withWidth(progressbarWidth).render()); + + // INFO: Power (as digits) + msg("Power: %.2f / %.2f", mplayer.getPower(), mplayer.getPowerMax()); + + // INFO: Power Boost + if (mplayer.hasPowerBoost()) { + double powerBoost = mplayer.getPowerBoost(); + String powerBoostType = (powerBoost > 0 ? "bonus" : "penalty"); + msg("Power Boost: %f (a manually granted %s)", powerBoost, powerBoostType); + } + + // INFO: Power per Hour + // If the player is not at maximum we wan't to display how much time left. + + String stringTillMax = ""; + double powerTillMax = mplayer.getPowerMax() - mplayer.getPower(); + if (powerTillMax > 0) { + long millisTillMax = (long) (powerTillMax * TimeUnit.MILLIS_PER_HOUR / mplayer.getPowerPerHour()); + LinkedHashMap unitcountsTillMax = TimeDiffUtil.unitcounts(millisTillMax, TimeUnit.getAllButMillis()); + unitcountsTillMax = TimeDiffUtil.limit(unitcountsTillMax, 2); + String unitcountsTillMaxFormated = TimeDiffUtil.formatedVerboose(unitcountsTillMax, ""); + stringTillMax = Txt.parse(" (%s left till max)", unitcountsTillMaxFormated); + } + + msg("Power per Hour: %.2f%s", mplayer.getPowerPerHour(), stringTillMax); + + // INFO: Power per Death + msg("Power per Death: %.2f", mplayer.getPowerPerDeath()); + + // Display automatic kick / remove info if the system is in use + if (MConf.get().cleanInactivityToleranceMillis <= 0) { + return; + } + + EventMassiveCorePlayerCleanInactivityToleranceMillis event = new EventMassiveCorePlayerCleanInactivityToleranceMillis(mplayer.getLastActivityMillis(), mplayer); + event.run(); + msg("Automatic removal after %s of inactivity:", format(event.getToleranceMillis())); + for (Entry causeMillis : event.getToleranceCauseMillis().entrySet()) { + String cause = causeMillis.getKey(); + long millis = causeMillis.getValue(); + msg("%s: %s", cause, format(millis)); + } + } + + // -------------------------------------------- // + // TIME FORMAT + // -------------------------------------------- // + + public static String format(long millis) { + LinkedHashMap unitcounts = TimeDiffUtil.unitcounts(millis, TimeUnit.getAllBut(TimeUnit.MILLISECOND, TimeUnit.WEEK, TimeUnit.MONTH)); + return TimeDiffUtil.formatedVerboose(unitcounts); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboost.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboost.java new file mode 100644 index 00000000..f40cbec8 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboost.java @@ -0,0 +1,21 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsPowerboost extends FactionsCommand { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public CmdFactionsPowerboostPlayer cmdFactionsPowerBoostPlayer = new CmdFactionsPowerboostPlayer(); + public CmdFactionsPowerboostFaction cmdFactionsPowerBoostFaction = new CmdFactionsPowerboostFaction(); + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsPowerboost() { + // Child + this.addChild(this.cmdFactionsPowerBoostPlayer); + this.addChild(this.cmdFactionsPowerBoostFaction); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostAbstract.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostAbstract.java new file mode 100644 index 00000000..7543af4e --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostAbstract.java @@ -0,0 +1,76 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.FactionsParticipator; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.Type; +import com.massivecraft.massivecore.command.type.primitive.TypeDouble; +import com.massivecraft.massivecore.util.Txt; + +public abstract class CmdFactionsPowerboostAbstract extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + protected CmdFactionsPowerboostAbstract(Type parameterType, String parameterName) { + // Parameters + this.addParameter(parameterType, parameterName); + if (!this.getClass().getSimpleName().contains("Show")) { + this.addParameter(TypeDouble.get(), "amount"); + } + } + + // -------------------------------------------- // + // ABSTRACT + // -------------------------------------------- // + + public abstract double calcNewPowerboost(double current, double d); + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Parameters + FactionsParticipator factionsParticipator = this.readArg(); + + boolean updated = false; + // Try set the powerBoost + if (this.argIsSet(1)) { + // Yes updated + updated = true; + + // Calc powerboost + double current = factionsParticipator.getPowerBoost(); + double number = this.readArg(); + double powerBoost = this.calcNewPowerboost(current, number); + + // Set + factionsParticipator.setPowerBoost(powerBoost); + } + + // Inform + this.informPowerBoost(factionsParticipator, updated); + } + + private void informPowerBoost(FactionsParticipator factionsParticipator, boolean updated) { + // Prepare + Double powerBoost = factionsParticipator.getPowerBoost(); + String participatorDescribe = factionsParticipator.describeTo(msender, true); + String powerDescription = Txt.parse(Double.compare(powerBoost, 0D) >= 0 ? "bonus" : "penalty"); + String when = updated ? "now " : ""; + String verb = factionsParticipator.equals(msender) ? "have" : "has"; + + // Create message + String messagePlayer = Txt.parse("%s %s%s a power %s of %.2f to min and max power levels.", participatorDescribe, when, verb, powerDescription, powerBoost); + String messageLog = Txt.parse("%s %s set the power %s for %s to %.2f.", msender.getName(), verb, powerDescription, factionsParticipator.getName(), powerBoost); + + // Inform + msender.message(messagePlayer); + if (updated) { + Factions.get().log(messageLog); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostFaction.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostFaction.java new file mode 100644 index 00000000..5e040dc5 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostFaction.java @@ -0,0 +1,14 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsPowerboostFaction extends FactionsCommand { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public CmdFactionsPowerboostFactionShow cmdFactionsPowerBoostFactionShow = new CmdFactionsPowerboostFactionShow(); + public CmdFactionsPowerboostFactionSet cmdFactionsPowerBoostFactionSet = new CmdFactionsPowerboostFactionSet(); + public CmdFactionsPowerboostFactionAdd cmdFactionsPowerBoostFactionAdd = new CmdFactionsPowerboostFactionAdd(); + public CmdFactionsPowerboostFactionTake cmdFactionsPowerBoostFactionTake = new CmdFactionsPowerboostFactionTake(); + public CmdFactionsPowerboostFactionMultiply cmdFactionsPowerBoostFactionMultiply = new CmdFactionsPowerboostFactionMultiply(); + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionAbstract.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionAbstract.java new file mode 100644 index 00000000..f14f3c31 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionAbstract.java @@ -0,0 +1,14 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeFaction; + +public abstract class CmdFactionsPowerboostFactionAbstract extends CmdFactionsPowerboostAbstract { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsPowerboostFactionAbstract() { + super(TypeFaction.get(), "faction"); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionAdd.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionAdd.java new file mode 100644 index 00000000..f94a6481 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionAdd.java @@ -0,0 +1,13 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsPowerboostFactionAdd extends CmdFactionsPowerboostFactionAbstract { + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public double calcNewPowerboost(double current, double d) { + return current + d; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionMultiply.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionMultiply.java new file mode 100644 index 00000000..97412da4 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionMultiply.java @@ -0,0 +1,13 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsPowerboostFactionMultiply extends CmdFactionsPowerboostFactionAbstract { + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public double calcNewPowerboost(double current, double d) { + return current * d; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionSet.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionSet.java new file mode 100644 index 00000000..becaf232 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionSet.java @@ -0,0 +1,13 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsPowerboostFactionSet extends CmdFactionsPowerboostFactionAbstract { + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public double calcNewPowerboost(double current, double d) { + return d; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionShow.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionShow.java new file mode 100644 index 00000000..026ca6e9 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionShow.java @@ -0,0 +1,13 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsPowerboostFactionShow extends CmdFactionsPowerboostFactionAbstract { + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public double calcNewPowerboost(double current, double d) { + throw new UnsupportedOperationException(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionTake.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionTake.java new file mode 100644 index 00000000..4afabe17 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostFactionTake.java @@ -0,0 +1,13 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsPowerboostFactionTake extends CmdFactionsPowerboostFactionAbstract { + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public double calcNewPowerboost(double current, double d) { + return current - d; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayer.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayer.java new file mode 100644 index 00000000..2eeceed2 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayer.java @@ -0,0 +1,14 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsPowerboostPlayer extends FactionsCommand { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public CmdFactionsPowerboostPlayerShow cmdFactionsPowerBoostPlayerShow = new CmdFactionsPowerboostPlayerShow(); + public CmdFactionsPowerboostPlayerSet cmdFactionsPowerBoostPlayerSet = new CmdFactionsPowerboostPlayerSet(); + public CmdFactionsPowerboostPlayerAdd cmdFactionsPowerBoostPlayerAdd = new CmdFactionsPowerboostPlayerAdd(); + public CmdFactionsPowerboostPlayerTake cmdFactionsPowerBoostPlayerTake = new CmdFactionsPowerboostPlayerTake(); + public CmdFactionsPowerboostPlayerMultiply cmdFactionsPowerBoostPlayerMultiply = new CmdFactionsPowerboostPlayerMultiply(); + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerAbstract.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerAbstract.java new file mode 100644 index 00000000..6aba707d --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerAbstract.java @@ -0,0 +1,14 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeMPlayer; + +public abstract class CmdFactionsPowerboostPlayerAbstract extends CmdFactionsPowerboostAbstract { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsPowerboostPlayerAbstract() { + super(TypeMPlayer.get(), "player"); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerAdd.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerAdd.java new file mode 100644 index 00000000..c6ed6964 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerAdd.java @@ -0,0 +1,13 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsPowerboostPlayerAdd extends CmdFactionsPowerboostPlayerAbstract { + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public double calcNewPowerboost(double current, double d) { + return current + d; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerMultiply.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerMultiply.java new file mode 100644 index 00000000..acb918a2 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerMultiply.java @@ -0,0 +1,13 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsPowerboostPlayerMultiply extends CmdFactionsPowerboostPlayerAbstract { + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public double calcNewPowerboost(double current, double d) { + return current * d; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerSet.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerSet.java new file mode 100644 index 00000000..55d2d818 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerSet.java @@ -0,0 +1,13 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsPowerboostPlayerSet extends CmdFactionsPowerboostPlayerAbstract { + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public double calcNewPowerboost(double current, double d) { + return d; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerShow.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerShow.java new file mode 100644 index 00000000..51edfba1 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerShow.java @@ -0,0 +1,13 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsPowerboostPlayerShow extends CmdFactionsPowerboostPlayerAbstract { + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public double calcNewPowerboost(double current, double d) { + throw new UnsupportedOperationException(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerTake.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerTake.java new file mode 100644 index 00000000..adb6c812 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPowerboostPlayerTake.java @@ -0,0 +1,13 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsPowerboostPlayerTake extends CmdFactionsPowerboostPlayerAbstract { + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public double calcNewPowerboost(double current, double d) { + return current - d; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRank.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRank.java new file mode 100644 index 00000000..ec78c717 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRank.java @@ -0,0 +1,13 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsRank extends FactionsCommand { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public CmdFactionsRankSet cmdFactionsRankSet = new CmdFactionsRankSet(); + public CmdFactionsRankShow cmdFactionsRankShow = new CmdFactionsRankShow(); + public CmdFactionsRankList cmdFactionsRankList = new CmdFactionsRankList(); + public CmdFactionsRankEdit cmdFactionsRankEdit = new CmdFactionsRankEdit(); + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankEdit.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankEdit.java new file mode 100644 index 00000000..420fd9be --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankEdit.java @@ -0,0 +1,32 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.MassiveException; + +public class CmdFactionsRankEdit extends FactionsCommand { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public CmdFactionsRankEditCreate cmdFactionsRankEditCreate = new CmdFactionsRankEditCreate(); + public CmdFactionsRankEditDelete cmdFactionsRankEditDelete = new CmdFactionsRankEditDelete(); + public CmdFactionsRankEditName cmdFactionsRankEditName = new CmdFactionsRankEditName(); + public CmdFactionsRankEditPrefix cmdFactionsRankEditPrefix = new CmdFactionsRankEditPrefix(); + public CmdFactionsRankEditPriority cmdFactionsRankEditPriority = new CmdFactionsRankEditPriority(); + + static void ensureAllowed(MPlayer msender, Faction faction, String action) throws MassiveException { + if (msender.isOverriding()) { + return; + } + + if (faction != msender.getFaction()) { + throw new MassiveException().addMsg("You can't manage ranks outside your own faction."); + } + + if (!msender.getRank().isLeader()) { + throw new MassiveException().addMsg("Only the leader can %s ranks.", action); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankEditCreate.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankEditCreate.java new file mode 100644 index 00000000..b91c7616 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankEditCreate.java @@ -0,0 +1,62 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.Rank; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.primitive.TypeInteger; +import com.massivecraft.massivecore.command.type.primitive.TypeString; +import com.massivecraft.massivecore.command.type.primitive.TypeStringParsed; + +import java.util.Collection; + +public class CmdFactionsRankEditCreate extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsRankEditCreate() { + // Parameters + this.addParameter(TypeString.get(), "name"); + this.addParameter(TypeInteger.get(), "priority"); + this.addParameter("", TypeStringParsed.get(), "prefix", "none"); + this.addParameter(TypeFaction.get(), "faction", "you"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + String name = this.readArg(); + Integer priority = this.readArg(); + String prefix = this.readArg(); + Faction faction = this.readArg(msenderFaction); + + CmdFactionsRankEdit.ensureAllowed(msender, faction, "create"); + + Collection ranks = faction.getRanks().getAll(); + + if (ranks.stream().map(Rank::getName).anyMatch(s -> s.equalsIgnoreCase(name))) { + throw new MassiveException().addMsg("There is already a rank called %s.", name); + } + if (ranks.stream().map(Rank::getPriority).anyMatch(i -> i.equals(priority))) { + throw new MassiveException().addMsg("There is already a rank with priority %s.", priority); + } + if (priority > faction.getLeaderRank().getPriority()) { + throw new MassiveException().addMsg("You can't create a rank of higher priority than the leader rank."); + } + + Rank rank = new Rank(name, priority, prefix); + + faction.getRanks().attach(rank); + + // Inform + msg("You created the rank %s.", rank.getVisual()); + msg("You might want to change its permissions:"); + CmdFactions.get().cmdFactionsPerm.getTemplate(false, true, sender).messageOne(msender); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankEditDelete.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankEditDelete.java new file mode 100644 index 00000000..63cd0148 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankEditDelete.java @@ -0,0 +1,63 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.cmd.type.TypeRank; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.entity.Rank; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.primitive.TypeString; +import com.massivecraft.massivecore.util.Txt; + +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + +public class CmdFactionsRankEditDelete extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsRankEditDelete() { + // Parameters + this.addParameter(TypeString.get(), "rank"); + this.addParameter(TypeFaction.get(), "faction", "you"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + Faction faction = this.readArgAt(1, msenderFaction); + + // Rank if any passed. + TypeRank typeRank = new TypeRank(faction); + Rank rank = typeRank.read(this.argAt(0), sender); + + CmdFactionsRankEdit.ensureAllowed(msender, faction, "delete"); + + Collection ranks = faction.getRanks().getAll(); + if (ranks.size() <= 2) { + throw new MassiveException().addMsg("A faction must have at least two ranks."); + } + + List mplayers = faction.getMPlayersWhereRank(rank); + if (!mplayers.isEmpty()) { + int count = mplayers.size(); + List names = mplayers.stream().map(m -> m.getDisplayName(sender)).collect(Collectors.toList()); + String namesDesc = Txt.implodeCommaAnd(names, Txt.parse("")); + String rankRanks = count == 1 ? "rank" : "ranks"; + throw new MassiveException().addMsg("This rank is held by %s change their %s first.", namesDesc, rankRanks); + } + + String visual = rank.getVisual(); + faction.getRanks().detachEntity(rank); + + // Inform + msg("You deleted the rank %s.", visual); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankEditName.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankEditName.java new file mode 100644 index 00000000..ceeaa5ed --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankEditName.java @@ -0,0 +1,55 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.cmd.type.TypeRank; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.Rank; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.primitive.TypeString; + +import java.util.Collection; + +public class CmdFactionsRankEditName extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsRankEditName() { + // Parameters + this.addParameter(TypeRank.get(), "rank"); + this.addParameter(TypeString.get(), "new name"); + this.addParameter(TypeFaction.get(), "faction", "you"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + String name = this.readArgAt(1); + Faction faction = this.readArgAt(2, msenderFaction); + + // Rank if any passed. + TypeRank typeRank = new TypeRank(faction); + Rank rank = typeRank.read(this.argAt(0), sender); + + // Args + + CmdFactionsRankEdit.ensureAllowed(msender, faction, "rename"); + + Collection ranks = faction.getRanks().getAll(); + + if (ranks.stream().map(Rank::getName).anyMatch(s -> s.equalsIgnoreCase(name))) { + throw new MassiveException().addMsg("There is already a rank called %s.", name); + } + + String priorVisual = rank.getVisual(); + rank.setName(name); + + // Visual + msg("You renamed the rank from %s to %s.", priorVisual, rank.getVisual()); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankEditPrefix.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankEditPrefix.java new file mode 100644 index 00000000..75ad71ff --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankEditPrefix.java @@ -0,0 +1,47 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.cmd.type.TypeRank; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.Rank; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.primitive.TypeString; + +public class CmdFactionsRankEditPrefix extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsRankEditPrefix() { + // Parameters + this.addParameter(TypeRank.get(), "rank"); + this.addParameter(TypeString.get(), "new prefix"); + this.addParameter(TypeFaction.get(), "faction", "you"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + String prefix = this.readArgAt(1); + Faction faction = this.readArgAt(2, msenderFaction); + + // Rank if any passed. + TypeRank typeRank = new TypeRank(faction); + Rank rank = typeRank.read(this.argAt(0), sender); + + // Args + + CmdFactionsRankEdit.ensureAllowed(msender, faction, "edit"); + + String priorPrefix = rank.getPrefix(); + rank.setPrefix(prefix); + + // Visual + msg("You changed the prefix of %s from %s to %s.", rank.getVisual(), priorPrefix, prefix); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankEditPriority.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankEditPriority.java new file mode 100644 index 00000000..2329f209 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankEditPriority.java @@ -0,0 +1,64 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.cmd.type.TypeRank; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.Rank; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.primitive.TypeInteger; + +import java.util.Collection; + +public class CmdFactionsRankEditPriority extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsRankEditPriority() { + // Parameters + this.addParameter(TypeRank.get(), "rank"); + this.addParameter(TypeInteger.get(), "new priority"); + this.addParameter(TypeFaction.get(), "faction", "you"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + Integer priority = this.readArgAt(1); + Faction faction = this.readArgAt(2, msenderFaction); + + // Rank if any passed. + TypeRank typeRank = new TypeRank(faction); + Rank rank = typeRank.read(this.argAt(0), sender); + + CmdFactionsRankEdit.ensureAllowed(msender, faction, "edit"); + + Collection ranks = faction.getRanks().getAll(); + + if (ranks.stream().map(Rank::getPriority).anyMatch(s -> s.equals(priority))) { + throw new MassiveException().addMsg("There is already a rank with the priority %s.", priority); + } + + if (rank.isLeader()) { + Rank below = rank.getRankBelow(); + if (below.getPriority() > priority) { + throw new MassiveException().addMsg("The leader rank must have the highest priority."); + } + } else { + if (priority >= faction.getLeaderRank().getPriority()) { + throw new MassiveException().addMsg("No rank can have higher priority than the leader rank."); + } + } + + int priorPriority = rank.getPriority(); + rank.setPriority(priority); + + // Visual + msg("You changed the priority of %s from %s to %s.", rank.getVisual(), priorPriority, priority); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankList.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankList.java new file mode 100644 index 00000000..ba6b136d --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankList.java @@ -0,0 +1,41 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.Rank; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.Parameter; +import com.massivecraft.massivecore.pager.Pager; +import com.massivecraft.massivecore.pager.Stringifier; + +import java.util.Comparator; +import java.util.List; + +public class CmdFactionsRankList extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsRankList() { + // Parameters + this.addParameter(Parameter.getPage()); + this.addParameter(TypeFaction.get(), "faction", "you"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + final int page = this.readArg(); + Faction faction = this.readArg(msenderFaction); + + List ranks = faction.getRanks().getAll(Comparator.comparingInt(Rank::getPriority).reversed()); + + String title = "Rank list for " + faction.describeTo(msender); + Pager pager = new Pager<>(this, title, page, ranks, (Stringifier) (r, i) -> r.getVisual()); + pager.message(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankOld.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankOld.java new file mode 100644 index 00000000..517c12e2 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankOld.java @@ -0,0 +1,45 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeMPlayer; +import com.massivecraft.massivecore.command.Visibility; +import com.massivecraft.massivecore.util.MUtil; + +public class CmdFactionsRankOld extends FactionsCommand { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public final String rankName; + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsRankOld(String rank) { + // Fields + this.rankName = rank.toLowerCase(); + this.setSetupEnabled(false); + + // Aliases + this.addAliases(rankName); + + // Parameters + this.addParameter(TypeMPlayer.get(), "player"); + + // Visibility + this.setVisibility(Visibility.INVISIBLE); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() { + CmdFactions.get().cmdFactionsRank.cmdFactionsRankSet.execute(sender, MUtil.list( + this.argAt(0), + this.rankName + )); + } + +} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankSet.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankSet.java new file mode 100644 index 00000000..42a1b039 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankSet.java @@ -0,0 +1,313 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.cmd.type.TypeMPlayer; +import com.massivecraft.factions.cmd.type.TypeRank; +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.entity.MPlayerColl; +import com.massivecraft.factions.entity.Rank; +import com.massivecraft.factions.event.EventFactionsMembershipChange; +import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; +import com.massivecraft.factions.event.EventFactionsRankChange; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.collections.MassiveSet; +import com.massivecraft.massivecore.util.Txt; + +import java.util.HashSet; +import java.util.Set; + +public class CmdFactionsRankSet extends FactionsCommand { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + // These fields are set upon perform() and unset afterwards. + + // Target + private Faction targetFaction = null; + private MPlayer target = null; + + // End faction (the faction they are changed to) + private Faction endFaction = null; + private boolean factionChange = false; + + // Ranks + private Rank senderRank = null; + private Rank targetRank = null; + private Rank rank = null; + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsRankSet() { + // Parameters + this.addParameter(TypeMPlayer.get(), "player"); + this.addParameter(TypeRank.get(), "rank"); + this.addParameter(TypeFaction.get(), "faction", "their"); + + // Too complicated for that + this.setSwapping(false); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // This sets target and much other. + this.registerFields(); + + // Is the player allowed or not. Method can be found later down. + this.ensureAllowed(); + + if (factionChange) { + this.changeFaction(); + } + + // Does the change make sense. + this.ensureMakesSense(); + + // Event + EventFactionsRankChange event = new EventFactionsRankChange(sender, target, rank); + event.run(); + if (event.isCancelled()) { + return; + } + rank = event.getNewRank(); + + // Change the rank. + this.changeRank(); + } + + // This is always run after performing a MassiveCommand. + @Override + public void senderFields(boolean set) { + super.senderFields(set); + + if (!set) { + this.unregisterFields(); + } + } + + // -------------------------------------------- // + // PRIVATE: REGISTER & UNREGISTER + // -------------------------------------------- // + + private void registerFields() throws MassiveException { + // Getting the target and faction. + target = this.readArg(); + targetFaction = target.getFaction(); + + + // Ranks + senderRank = msender.getRank(); + targetRank = target.getRank(); + + endFaction = this.readArgAt(2, targetFaction); + factionChange = (endFaction != targetFaction); + + // Rank if any passed. + TypeRank typeRank = new TypeRank(endFaction, target.getRank()); + rank = typeRank.read(this.argAt(1), sender); + + } + + private void unregisterFields() { + targetFaction = null; + target = null; + + endFaction = null; + factionChange = false; + + senderRank = null; + targetRank = null; + rank = null; + } + + // -------------------------------------------- // + // PRIVATE: ENSURE + // -------------------------------------------- // + + private void ensureAllowed() throws MassiveException { + // People with permission don't follow the normal rules. + if (msender.isOverriding()) { + return; + } + + // If somone gets the leadership of wilderness (Which has happened before). + // We can at least try to limit their powers. + if (endFaction.isNone()) { + throw new MassiveException().addMsg("%s doesn't use ranks sorry :(", endFaction.getName()); + } + + if (target == msender) { + // Don't change your own rank. + throw new MassiveException().addMsg("The target player mustn't be yourself."); + } + + if (factionChange) { + // Don't change peoples faction + throw new MassiveException().addMsg("You can't change %s's faction.", target.describeTo(msender)); + } + + if (!MPerm.getPermRank().has(msender, targetFaction, false)) { + throw new MassiveException().addMessage(MPerm.getPermRank().createDeniedMessage(msender, targetFaction)); + } + + // The following two if statements could be merged. + // But isn't for the sake of nicer error messages. + if (senderRank == targetRank) { + // You can't change someones rank if it is equal to yours. + throw new MassiveException().addMsg("%s can't manage eachother.", senderRank.getName() + "s"); + } + + if (senderRank.isLessThan(targetRank)) { + // You can't change someones rank if it is higher than yours. + throw new MassiveException().addMsg("You can't manage people of higher rank."); + } + + // The following two if statements could be merged. + // But isn't for the sake of nicer error messages. + if (senderRank == rank && !senderRank.isLeader()) { + // You can't set ranks equal to your own. Unless you are the leader. + throw new MassiveException().addMsg("You can't set ranks equal to your own."); + } + + if (senderRank.isLessThan(rank)) { + // You can't set ranks higher than your own. + throw new MassiveException().addMsg("You can't set ranks higher than your own."); + } + } + + private void ensureMakesSense() throws MassiveException { + // Don't change their rank to something they already are. + if (target.getRank() == rank) { + throw new MassiveException().addMsg("%s is already %s %s.", target.describeTo(msender), Txt.aan(rank.getName()), rank.getName()); + } + } + + // -------------------------------------------- // + // PRIVATE: CHANGE FACTION + // -------------------------------------------- // + + private void changeFaction() throws MassiveException { + // Don't change a leader to a new faction. + if (targetRank.isLeader()) { + throw new MassiveException().addMsg("You cannot remove the present leader. Demote them first."); + } + + // Event + EventFactionsMembershipChange membershipChangeEvent = new EventFactionsMembershipChange(sender, msender, endFaction, MembershipChangeReason.RANK); + membershipChangeEvent.run(); + if (membershipChangeEvent.isCancelled()) { + throw new MassiveException(); + } + + // Apply + target.resetFactionData(); + target.setFaction(endFaction); + + // No longer invited. + endFaction.uninvite(target); + + // Create recipients + Set recipients = new HashSet<>(); + recipients.addAll(targetFaction.getMPlayersWhereOnline(true)); + recipients.addAll(endFaction.getMPlayersWhereOnline(true)); + recipients.add(msender); + + // Send message + for (MPlayer recipient : recipients) { + recipient.msg("%s was moved from %s to %s.", target.describeTo(recipient), targetFaction.describeTo(recipient), endFaction.describeTo(recipient)); + } + + // Derplog + if (MConf.get().logFactionJoin) { + Factions.get().log(Txt.parse("%s moved %s from %s to %s.", msender.getName(), target.getName(), targetFaction.getName(), endFaction.getName())); + } + + // Now we don't need the old values. + targetFaction = target.getFaction(); + targetRank = target.getRank(); + senderRank = msender.getRank(); // In case they changed their own rank + + } + + // -------------------------------------------- // + // PRIVATE: CHANGE RANK + // -------------------------------------------- // + + private void changeRank() throws MassiveException { + // In case of leadership change, we do special things not done in other rank changes. + if (rank.isLeader()) { + this.changeRankLeader(); + } else { + this.changeRankOther(); + } + } + + private void changeRankLeader() { + // If there is a current leader. Demote & inform them. + MPlayer targetFactionCurrentLeader = targetFaction.getLeader(); + if (targetFactionCurrentLeader != null) { + // Inform & demote the old leader. + targetFactionCurrentLeader.setRank(rank.getRankBelow()); + if (targetFactionCurrentLeader != msender) { + // They kinda know if they fired the command themself. + targetFactionCurrentLeader.msg("You have been demoted from the position of faction leader by %s.", msender.describeTo(targetFactionCurrentLeader, true)); + } + } + + // Promote the new leader. + target.setRank(rank); + + // Inform everyone, this includes sender and target. + for (MPlayer recipient : MPlayerColl.get().getAllOnline()) { + String changerName = senderIsConsole ? "A server admin" : msender.describeTo(recipient); + recipient.msg("%s gave %s the leadership of %s.", changerName, target.describeTo(recipient), targetFaction.describeTo(recipient)); + } + } + + private void changeRankOther() throws MassiveException { + // If the target is currently the leader and faction isn't permanent a new leader should be promoted. + // Sometimes a bug occurs and multiple leaders exist. Then we should be able to demote without promoting new leader + if (targetRank.isLeader() && (!MConf.get().permanentFactionsDisableLeaderPromotion || !targetFaction.getFlag(MFlag.ID_PERMANENT)) && targetFaction.getMPlayersWhereRank(targetFaction.getLeaderRank()).size() == 1) + // This if statement is very long. Should I nest it for readability? + { + targetFaction.promoteNewLeader(); // This might disband the faction. + + // So if the faction disbanded... + if (targetFaction.detached()) { + // ... we inform the sender. + target.resetFactionData(); + throw new MassiveException().addMsg("The target was a leader and got demoted. The faction disbanded and no rank was set."); + } + } + + // Create recipients + Set recipients = new MassiveSet<>(targetFaction.getMPlayers()); + recipients.add(msender); + + // Were they demoted or promoted? + String change = (rank.isLessThan(targetRank) ? "demoted" : "promoted"); + + // The rank will be set before the msg, so they have the appropriate prefix. + target.setRank(rank); + String oldRankName = targetRank.getName().toLowerCase(); + String rankName = rank.getName().toLowerCase(); + + // Send message + for (MPlayer recipient : recipients) { + String targetName = target.describeTo(recipient, true); + String wasWere = (recipient == target) ? "were" : "was"; + recipient.msg("%s %s %s from %s to %s in %s.", targetName, wasWere, change, oldRankName, rankName, targetFaction.describeTo(msender)); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankShow.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankShow.java new file mode 100644 index 00000000..f2ec83d5 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankShow.java @@ -0,0 +1,49 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeMPlayer; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.entity.Rank; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.util.Txt; + +public class CmdFactionsRankShow extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsRankShow() { + // Parameters + this.addParameter(TypeMPlayer.get(), "player"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + MPlayer target = this.readArg(); + Rank rank = target.getRank(); + + // Damn you grammar, causing all these checks. + String targetName = target.describeTo(msender, true); + String isAre = (target == msender) ? "are" : "is"; // "you are" or "he is" + + String theAan = (rank.isLeader()) ? "the" : Txt.aan(rank.getName()); // "a member", "an officer" or "the leader" + String rankName = rank.getName().toLowerCase(); + String ofIn = (rank.isLeader()) ? "of" : "in"; // "member in" or "leader of" + String factionName = target.getFaction().describeTo(msender, true); + if (target.getFaction() == msenderFaction) { + // Having the "Y" in "Your faction" being uppercase in the middle of a sentence makes no sense. + factionName = factionName.toLowerCase(); + } + if (target.getFaction().isNone()) { + // Wilderness aka none doesn't use ranks + msg("%s %s factionless", targetName, isAre); + } else { + // Derp is a member in Faction + msg("%s %s %s %s %s %s.", targetName, isAre, theAan, rankName, ofIn, factionName); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRelation.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRelation.java new file mode 100644 index 00000000..4e7eda2d --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRelation.java @@ -0,0 +1,12 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsRelation extends FactionsCommand { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public CmdFactionsRelationSet cmdFactionsRelationSet = new CmdFactionsRelationSet(); + public CmdFactionsRelationList cmdFactionsRelationList = new CmdFactionsRelationList(); + public CmdFactionsRelationWishes cmdFactionsRelationWishes = new CmdFactionsRelationWishes(); + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRelationList.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRelationList.java new file mode 100644 index 00000000..59beaba1 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRelationList.java @@ -0,0 +1,79 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.Rel; +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.cmd.type.TypeRelation; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.collections.MassiveList; +import com.massivecraft.massivecore.collections.MassiveSet; +import com.massivecraft.massivecore.command.Parameter; +import com.massivecraft.massivecore.command.type.container.TypeSet; +import com.massivecraft.massivecore.pager.Pager; +import com.massivecraft.massivecore.pager.Stringifier; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.Bukkit; + +import java.util.List; +import java.util.Map.Entry; +import java.util.Set; + +public class CmdFactionsRelationList extends FactionsCommand { + // -------------------------------------------- // + // COSTANTS + // -------------------------------------------- // + + public static final Set RELEVANT_RELATIONS = new MassiveSet<>(Rel.ENEMY, Rel.TRUCE, Rel.ALLY); + public static final String SEPERATOR = Txt.parse(": "); + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsRelationList() { + // Parameter + this.addParameter(Parameter.getPage()); + this.addParameter(TypeFaction.get(), "faction", "you"); + this.addParameter(TypeSet.get(TypeRelation.get()), "relations", "all"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + int page = this.readArg(); + final Faction faction = this.readArg(msenderFaction); + final Set relations = this.readArg(RELEVANT_RELATIONS); + + // Pager Create + final Pager pager = new Pager<>(this, "", page, (Stringifier) (item, index) -> item); + + Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> { + // Prepare Items + List relNames = new MassiveList<>(); + for (Entry> entry : FactionColl.get().getRelationNames(faction, relations).entrySet()) { + Rel relation = entry.getKey(); + String coloredName = relation.getColor().toString() + relation.getName(); + + for (String name : entry.getValue()) { + relNames.add(coloredName + SEPERATOR + name); + } + } + + // Pager Title + pager.setTitle(Txt.parse("%s's Relations (%d)", faction.getName(), relNames.size())); + + // Pager Items + pager.setItems(relNames); + + // Pager Message + pager.message(); + }); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRelationOld.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRelationOld.java new file mode 100644 index 00000000..9f697844 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRelationOld.java @@ -0,0 +1,51 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.Visibility; +import com.massivecraft.massivecore.util.MUtil; + +public class CmdFactionsRelationOld extends FactionsCommand { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public final String relName; + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsRelationOld(String rel) { + // Fields + this.relName = rel.toLowerCase(); + this.setSetupEnabled(false); + + // Aliases + this.addAliases(relName); + + // Parameters + this.addParameter(TypeFaction.get(), "faction", true); + + // Visibility + this.setVisibility(Visibility.INVISIBLE); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Arguments + Faction faction = this.readArg(); + + // Apply + CmdFactions.get().cmdFactionsRelation.cmdFactionsRelationSet.execute(sender, MUtil.list( + faction.getId(), + this.relName + )); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRelationSet.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRelationSet.java new file mode 100644 index 00000000..72a36dd5 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRelationSet.java @@ -0,0 +1,98 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Rel; +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.cmd.type.TypeRelation; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.event.EventFactionsRelationChange; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.MassiveCommand; +import com.massivecraft.massivecore.mson.Mson; +import org.bukkit.ChatColor; + +public class CmdFactionsRelationSet extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsRelationSet() { + // Parameter + this.addParameter(TypeFaction.get(), "faction"); + this.addParameter(TypeRelation.get(), "relation"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + Faction otherFaction = this.readArg(); + Rel newRelation = this.readArg(); + + // MPerm + if (!MPerm.getPermRel().has(msender, msenderFaction, true)) { + return; + } + + // Verify + if (otherFaction == msenderFaction) { + throw new MassiveException().setMsg("Nope! You can't declare a relation to yourself :)"); + } + if (msenderFaction.getRelationWish(otherFaction) == newRelation) { + throw new MassiveException().setMsg("You already have that relation wish set with %s.", otherFaction.getName()); + } + + // Event + EventFactionsRelationChange event = new EventFactionsRelationChange(sender, msenderFaction, otherFaction, newRelation); + event.run(); + if (event.isCancelled()) { + return; + } + newRelation = event.getNewRelation(); + + // try to set the new relation + msenderFaction.setRelationWish(otherFaction, newRelation); + Rel currentRelation = msenderFaction.getRelationTo(otherFaction, true); + + // if the relation change was successful + if (newRelation == currentRelation) { + otherFaction.msg("%s is now %s.", msenderFaction.describeTo(otherFaction, true), newRelation.getDescFactionOne()); + msenderFaction.msg("%s is now %s.", otherFaction.describeTo(msenderFaction, true), newRelation.getDescFactionOne()); + } + // inform the other faction of your request + else { + MassiveCommand command = CmdFactions.get().cmdFactionsRelation.cmdFactionsRelationSet; + String colorOne = newRelation.getColor() + newRelation.getDescFactionOne(); + + // Mson creation + Mson factionsRelationshipChange = mson( + Mson.parse("%s wishes to be %s.", msenderFaction.describeTo(otherFaction, true), colorOne), + Mson.SPACE, + mson("[Accept]").color(ChatColor.AQUA).command(command, msenderFaction.getName(), newRelation.name()) + ); + + otherFaction.sendMessage(factionsRelationshipChange); + msenderFaction.msg("%s were informed that you wish to be %s.", otherFaction.describeTo(msenderFaction, true), colorOne); + } + + // TODO: The ally case should work!! + // this might have to be bumped up to make that happen, & allow ALLY,NEUTRAL only + if (newRelation != Rel.TRUCE && otherFaction.getFlag(MFlag.getFlagPeaceful())) { + otherFaction.msg("This will have no effect while your faction is peaceful."); + msenderFaction.msg("This will have no effect while their faction is peaceful."); + } + + if (newRelation != Rel.TRUCE && msenderFaction.getFlag(MFlag.getFlagPeaceful())) { + otherFaction.msg("This will have no effect while their faction is peaceful."); + msenderFaction.msg("This will have no effect while your faction is peaceful."); + } + + // Mark as changed + msenderFaction.changed(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRelationWishes.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRelationWishes.java new file mode 100644 index 00000000..7ea67021 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRelationWishes.java @@ -0,0 +1,75 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.Rel; +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.collections.MassiveMap; +import com.massivecraft.massivecore.command.Parameter; +import com.massivecraft.massivecore.pager.Pager; +import com.massivecraft.massivecore.pager.Stringifier; +import com.massivecraft.massivecore.util.MUtil; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.Bukkit; + +import java.util.Map; +import java.util.Map.Entry; + +public class CmdFactionsRelationWishes extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsRelationWishes() { + // Parameter + this.addParameter(Parameter.getPage()); + this.addParameter(TypeFaction.get(), "faction", "you"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + int page = this.readArg(); + final Faction faction = this.readArg(msenderFaction); + + // Pager Create + final Pager> pager = new Pager<>(this, "", page, (Stringifier>) (item, index) -> { + Rel rel = item.getValue(); + Faction fac = item.getKey(); + return rel.getColor().toString() + rel.getName() + CmdFactionsRelationList.SEPERATOR + fac.describeTo(faction, true); + }); + + Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> { + Map realWishes = new MassiveMap<>(); + + for (Entry entry : faction.getRelationWishes().entrySet()) { + Rel rel = entry.getValue(); + Faction fac = FactionColl.get().getFixed(entry.getKey()); + if (fac == null) { + continue; + } + + // A wish is not a wish anymore if both factions have atleast equal "wishes" + if (fac.getRelationTo(faction).isAtLeast(rel)) { + continue; + } + realWishes.put(fac, rel); + } + + // Pager Title + pager.setTitle(Txt.parse("%s's Relation wishes (%d)", faction.getName(), realWishes.size())); + + // Pager Items + pager.setItems(MUtil.entriesSortedByValues(realWishes)); + + // Pager Message + pager.message(); + }); + } +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSeeChunk.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSeeChunk.java new file mode 100644 index 00000000..b0e53c0f --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSeeChunk.java @@ -0,0 +1,49 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; +import com.massivecraft.massivecore.command.type.primitive.TypeBooleanOn; +import com.massivecraft.massivecore.util.Txt; + +public class CmdFactionsSeeChunk extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsSeeChunk() { + // Aliases + this.addAliases("sc"); + + // Parameters + this.addParameter(TypeBooleanOn.get(), "active", "toggle"); + + // Requirements + this.addRequirements(RequirementIsPlayer.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + boolean old = msender.isSeeingChunk(); + boolean targetDefault = !old; + boolean target = this.readArg(targetDefault); + String targetDesc = Txt.parse(target ? "ON" : "OFF"); + + // NoChange + if (target == old) { + msg("See Chunk is already %s.", targetDesc); + return; + } + + // Apply + msender.setSeeingChunk(target); + + // Inform + msg("See Chunk is now %s.", targetDesc); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSeeChunkOld.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSeeChunkOld.java new file mode 100644 index 00000000..c8e6dba8 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSeeChunkOld.java @@ -0,0 +1,75 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.util.AsciiMap; +import com.massivecraft.factions.util.VisualizeUtil; +import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.ps.PSFormatHumanSpace; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.entity.Player; + +public class CmdFactionsSeeChunkOld extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsSeeChunkOld() { + // Aliases + this.addAliases("sco"); + + // Requirements + this.addRequirements(RequirementIsPlayer.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() { + // Args + World world = me.getWorld(); + PS chunk = PS.valueOf(me.getLocation()).getChunk(true); + int chunkX = chunk.getChunkX(); + int chunkZ = chunk.getChunkZ(); + + // Apply + int blockX; + int blockZ; + + blockX = chunkX * 16; + blockZ = chunkZ * 16; + showPillar(me, world, blockX, blockZ); + + blockX = chunkX * 16 + 15; + blockZ = chunkZ * 16; + showPillar(me, world, blockX, blockZ); + + blockX = chunkX * 16; + blockZ = chunkZ * 16 + 15; + showPillar(me, world, blockX, blockZ); + + blockX = chunkX * 16 + 15; + blockZ = chunkZ * 16 + 15; + showPillar(me, world, blockX, blockZ); + + // Inform + boolean showCoords = AsciiMap.showChunkCoords(chunk); + String chunkDesc = showCoords ? chunk.toString(PSFormatHumanSpace.get()) : "chunk"; + msg("Visualized %s", chunkDesc); + } + + public static void showPillar(Player player, World world, int blockX, int blockZ) { + for (int blockY = 0; blockY < world.getMaxHeight(); blockY++) { + Location loc = new Location(world, blockX, blockY, blockZ); + if (loc.getBlock().getType() != Material.AIR) { + continue; + } + Material type = blockY % 5 == 0 ? Material.GLOWSTONE : Material.GLASS; + VisualizeUtil.addLocation(player, loc, type); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetAll.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetAll.java new file mode 100644 index 00000000..561a92ad --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetAll.java @@ -0,0 +1,86 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Perm; +import com.massivecraft.factions.entity.Board; +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.requirement.RequirementHasPerm; +import com.massivecraft.massivecore.mixin.MixinWorld; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.MUtil; + +import java.util.Collections; +import java.util.List; +import java.util.Set; + + +public class CmdFactionsSetAll extends CmdFactionsSetXAll { + // -------------------------------------------- // + // CONSTANTS + // -------------------------------------------- // + + public static final List LIST_ALL = Collections.unmodifiableList(MUtil.list("a", "al", "all")); + public static final List LIST_MAP = Collections.singletonList("map"); + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsSetAll(boolean claim) { + // Super + super(claim); + + // Aliases + this.addAliases("all"); + + // Requirements + Perm perm = claim ? Perm.CLAIM_ALL : Perm.UNCLAIM_ALL; + this.addRequirements(RequirementHasPerm.get(perm)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Set getChunks() throws MassiveException { + // World + String word = (this.isClaim() ? "claim" : "unclaim"); + + // Create Ret + Set chunks = null; + + // Args + Faction oldFaction = this.getOldFaction(); + + if (LIST_ALL.contains(this.argAt(0).toLowerCase())) { + chunks = BoardColl.get().getChunks(oldFaction); + this.setFormatOne("%s %s %d chunk using " + word + " all."); + this.setFormatMany("%s %s %d chunks using " + word + " all."); + } else { + String worldId = null; + if (LIST_MAP.contains(this.argAt(0).toLowerCase())) { + if (me != null) { + worldId = me.getWorld().getName(); + } else { + throw new MassiveException().addMsg("You must specify which map from console."); + } + } else { + worldId = this.argAt(0); + if (worldId == null) { + return null; + } + } + Board board = BoardColl.get().get(worldId); + chunks = board.getChunks(oldFaction); + String worldDisplayName = MixinWorld.get().getWorldDisplayName(worldId); + this.setFormatOne("%s %s %d chunk using " + word + " " + worldDisplayName + "."); + this.setFormatMany("%s %s %d chunks using " + word + " " + worldDisplayName + "."); + } + + // Return Ret + return chunks; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetAuto.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetAuto.java new file mode 100644 index 00000000..d20bb1eb --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetAuto.java @@ -0,0 +1,92 @@ +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.FactionColl; +import com.massivecraft.factions.entity.MPerm; +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; + +import java.util.Collections; +import java.util.Set; + + +public class CmdFactionsSetAuto extends FactionsCommand { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private boolean claim = true; + + public boolean isClaim() { + return this.claim; + } + + public void setClaim(boolean claim) { + this.claim = claim; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsSetAuto(boolean claim) { + // Fields + this.setClaim(claim); + this.setSetupEnabled(false); + + // Aliases + this.addAliases("auto"); + + // Parameters + if (claim) { + this.addParameter(TypeFaction.get(), "faction", "you"); + } + + // Requirements + this.addRequirements(RequirementIsPlayer.get()); + Perm perm = claim ? Perm.CLAIM_AUTO : Perm.UNCLAIM_AUTO; + this.addRequirements(RequirementHasPerm.get(perm)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + final Faction newFaction; + if (claim) { + newFaction = this.readArg(msenderFaction); + } else { + newFaction = FactionColl.get().getNone(); + } + + // Disable? + if (newFaction == null || newFaction == msender.getAutoClaimFaction()) { + msender.setAutoClaimFaction(null); + throw new MassiveException().addMsg("Disabled auto-setting as you walk around."); + } + + // MPerm Preemptive Check + if (newFaction.isNormal() && !MPerm.getPermTerritory().has(msender, newFaction, true)) { + return; + } + + // Apply / Inform + msender.setAutoClaimFaction(newFaction); + msg("Now auto-setting %s land.", newFaction.describeTo(msender)); + + // Chunks + final PS chunk = PS.valueOf(me.getLocation()).getChunk(true); + Set chunks = Collections.singleton(chunk); + + // Apply / Inform + msender.tryClaim(newFaction, chunks); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetCircle.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetCircle.java new file mode 100644 index 00000000..f439d40a --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetCircle.java @@ -0,0 +1,46 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Perm; +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; +import com.massivecraft.massivecore.util.ChunkUtil; + +import java.util.Set; + + +public class CmdFactionsSetCircle extends CmdFactionsSetXRadius { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsSetCircle(boolean claim) { + // Super + super(claim); + + // Aliases + this.addAliases("circle"); + + // Format + this.setFormatOne("%s %s %d chunk %s using circle."); + this.setFormatMany("%s %s %d chunks near %s using circle."); + + // Requirements + this.addRequirements(RequirementIsPlayer.get()); + Perm perm = claim ? Perm.CLAIM_CIRCLE : Perm.UNCLAIM_CIRCLE; + this.addRequirements(RequirementHasPerm.get(perm)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Set getChunks() throws MassiveException { + // Common Startup + final PS chunk = PS.valueOf(me.getLocation()).getChunk(true); + return ChunkUtil.getChunksCircle(chunk, this.getRadius()); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetFill.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetFill.java new file mode 100644 index 00000000..f13729b0 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetFill.java @@ -0,0 +1,58 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Perm; +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +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; +import com.massivecraft.massivecore.util.ChunkUtil; + +import java.util.Set; +import java.util.function.Predicate; + + +public class CmdFactionsSetFill extends CmdFactionsSetXSimple { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsSetFill(boolean claim) { + // Super + super(claim); + + // Aliases + this.addAliases("fill"); + + // Format + this.setFormatOne("%s %s %d chunk %s using fill."); + this.setFormatMany("%s %s %d chunks near %s using fill."); + + // Requirements + this.addRequirements(RequirementIsPlayer.get()); + Perm perm = claim ? Perm.CLAIM_FILL : Perm.UNCLAIM_FILL; + this.addRequirements(RequirementHasPerm.get(perm)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Set getChunks() throws MassiveException { + // Common Startup + final PS chunk = PS.valueOf(me.getLocation()).getChunk(true); + + // What faction (aka color) resides there? + // NOTE: Wilderness/None is valid. + final Faction color = BoardColl.get().getFactionAt(chunk); + + // Calculate + int max = MConf.get().setFillMax; + Predicate matcher = ps -> BoardColl.get().getFactionAt(ps) == color; + return ChunkUtil.getChunkArea(chunk, matcher, max); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetOne.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetOne.java new file mode 100644 index 00000000..269795a7 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetOne.java @@ -0,0 +1,40 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Perm; +import com.massivecraft.massivecore.command.requirement.RequirementHasPerm; +import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; +import com.massivecraft.massivecore.ps.PS; + +import java.util.Collections; +import java.util.Set; + + +public class CmdFactionsSetOne extends CmdFactionsSetXSimple { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsSetOne(boolean claim) { + // Super + super(claim); + + // Aliases + this.addAliases("one"); + + // Requirements + this.addRequirements(RequirementIsPlayer.get()); + Perm perm = claim ? Perm.CLAIM_ONE : Perm.UNCLAIM_ONE; + this.addRequirements(RequirementHasPerm.get(perm)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Set getChunks() { + final PS chunk = PS.valueOf(me.getLocation()).getChunk(true); + return Collections.singleton(chunk); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetSquare.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetSquare.java new file mode 100644 index 00000000..af8e94b8 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetSquare.java @@ -0,0 +1,46 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Perm; +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; +import com.massivecraft.massivecore.util.ChunkUtil; + +import java.util.Set; + + +public class CmdFactionsSetSquare extends CmdFactionsSetXRadius { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsSetSquare(boolean claim) { + // Super + super(claim); + + // Aliases + this.addAliases("square"); + + // Format + this.setFormatOne("%s %s %d chunk %s using square."); + this.setFormatMany("%s %s %d chunks near %s using square."); + + // Requirements + this.addRequirements(RequirementIsPlayer.get()); + Perm perm = claim ? Perm.CLAIM_SQUARE : Perm.UNCLAIM_SQUARE; + this.addRequirements(RequirementHasPerm.get(perm)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Set getChunks() throws MassiveException { + // Common Startup + final PS chunk = PS.valueOf(me.getLocation()).getChunk(true); + return ChunkUtil.getChunksSquare(chunk, this.getRadius()); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetX.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetX.java new file mode 100644 index 00000000..3262b9fc --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetX.java @@ -0,0 +1,99 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.ps.PS; + +import java.util.Set; + +public abstract class CmdFactionsSetX extends FactionsCommand { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private String formatOne = null; + + public String getFormatOne() { + return this.formatOne; + } + + public void setFormatOne(String formatOne) { + this.formatOne = formatOne; + } + + private String formatMany = null; + + public String getFormatMany() { + return this.formatMany; + } + + public void setFormatMany(String formatMany) { + this.formatMany = formatMany; + } + + private boolean claim = true; + + public boolean isClaim() { + return this.claim; + } + + public void setClaim(boolean claim) { + this.claim = claim; + } + + private int factionArgIndex = 0; + + public int getFactionArgIndex() { + return this.factionArgIndex; + } + + public void setFactionArgIndex(int factionArgIndex) { + this.factionArgIndex = factionArgIndex; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsSetX(boolean claim) { + this.setClaim(claim); + this.setSetupEnabled(false); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + final Faction newFaction = this.getNewFaction(); + final Set chunks = this.getChunks(); + if (chunks == null) { + throw new NullPointerException("chunks"); + } + + // Apply / Inform + msender.tryClaim(newFaction, chunks, this.getFormatOne(), this.getFormatMany()); + } + + // -------------------------------------------- // + // ABSTRACT + // -------------------------------------------- // + + public abstract Set getChunks() throws MassiveException; + + // -------------------------------------------- // + // EXTRAS + // -------------------------------------------- // + + public Faction getNewFaction() throws MassiveException { + if (this.isClaim()) { + return this.readArgAt(this.getFactionArgIndex(), msenderFaction); + } else { + return FactionColl.get().getNone(); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetXAll.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetXAll.java new file mode 100644 index 00000000..6253e816 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetXAll.java @@ -0,0 +1,34 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.primitive.TypeString; + +public abstract class CmdFactionsSetXAll extends CmdFactionsSetX { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsSetXAll(boolean claim) { + // Super + super(claim); + + // Parameters + this.addParameter(TypeString.get(), "all|map"); + this.addParameter(TypeFaction.get(), "faction"); + if (claim) { + this.addParameter(TypeFaction.get(), "newfaction"); + this.setFactionArgIndex(2); + } + } + + // -------------------------------------------- // + // EXTRAS + // -------------------------------------------- // + + public Faction getOldFaction() throws MassiveException { + return this.readArgAt(1); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetXRadius.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetXRadius.java new file mode 100644 index 00000000..39d06e63 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetXRadius.java @@ -0,0 +1,46 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.primitive.TypeInteger; + + +public abstract class CmdFactionsSetXRadius extends CmdFactionsSetX { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsSetXRadius(boolean claim) { + // Super + super(claim); + + // Parameters + this.addParameter(1, TypeInteger.get(), "radius"); + if (claim) { + this.addParameter(TypeFaction.get(), "faction", "you"); + this.setFactionArgIndex(1); + } + } + + // -------------------------------------------- // + // EXTRAS + // -------------------------------------------- // + + public Integer getRadius() throws MassiveException { + int radius = this.readArgAt(0); + + // Radius Claim Min + if (radius < 1) { + throw new MassiveException().setMsg("If you specify a radius, it must be at least 1."); + } + + // Radius Claim Max + if (radius > MConf.get().setRadiusMax && !msender.isOverriding()) { + throw new MassiveException().setMsg("The maximum radius allowed is %s.", MConf.get().setRadiusMax); + } + + return radius; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetXSimple.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetXSimple.java new file mode 100644 index 00000000..320ebb03 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetXSimple.java @@ -0,0 +1,21 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeFaction; + +public abstract class CmdFactionsSetXSimple extends CmdFactionsSetX { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsSetXSimple(boolean claim) { + // Super + super(claim); + + // Parameters + if (claim) { + this.addParameter(TypeFaction.get(), "faction", "you"); + this.setFactionArgIndex(0); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSethome.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSethome.java new file mode 100644 index 00000000..3bfc760b --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSethome.java @@ -0,0 +1,38 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.Visibility; +import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; +import com.massivecraft.massivecore.util.MUtil; + +import java.util.List; + +public class CmdFactionsSethome extends FactionsCommandWarp { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsSethome() { + // Requirements + this.addRequirements(RequirementIsPlayer.get()); + + // Parameters + this.addParameter(TypeFaction.get(), "faction", "you"); + + // Visibility + this.setVisibility(Visibility.INVISIBLE); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + List args = MUtil.list(MConf.get().warpsHomeName, this.argAt(0)); + CmdFactions.get().cmdFactionsWarp.cmdFactionWarpAdd.execute(me, args); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetpower.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetpower.java new file mode 100644 index 00000000..32ff57cf --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetpower.java @@ -0,0 +1,67 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Perm; +import com.massivecraft.factions.cmd.type.TypeMPlayer; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.event.EventFactionsPowerChange; +import com.massivecraft.factions.event.EventFactionsPowerChange.PowerChangeReason; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.requirement.RequirementHasPerm; +import com.massivecraft.massivecore.command.type.primitive.TypeDouble; + +public class CmdFactionsSetpower extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsSetpower() { + // Aliases + this.addAliases("sp"); + + // Parameters + this.addParameter(TypeMPlayer.get(), "player"); + this.addParameter(TypeDouble.get(), "power"); + + // Requirements + this.addRequirements(RequirementHasPerm.get(Perm.SETPOWER)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + MPlayer mplayer = this.readArg(); + double power = this.readArg(); + + // Power + double oldPower = mplayer.getPower(); + double newPower = mplayer.getLimitedPower(power); + + // Detect "no change" + double difference = Math.abs(newPower - oldPower); + double maxDifference = 0.1d; + if (difference < maxDifference) { + throw new MassiveException().addMsg("%s's power is already %.2f.", mplayer.getDisplayName(msender), newPower); + } + + // Event + EventFactionsPowerChange event = new EventFactionsPowerChange(sender, mplayer, PowerChangeReason.COMMAND, newPower); + event.run(); + if (event.isCancelled()) { + return; + } + + // Inform + msg("You changed %s's power from %.2f to %.2f.", mplayer.getDisplayName(msender), oldPower, newPower); + if (msender != mplayer) { + mplayer.msg("%s changed your power from %.2f to %.2f.", msender.getDisplayName(mplayer), oldPower, newPower); + } + + // Apply + mplayer.setPower(newPower); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsStatus.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsStatus.java new file mode 100644 index 00000000..f48d6e9e --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsStatus.java @@ -0,0 +1,87 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.cmd.type.TypeSortMPlayer; +import com.massivecraft.factions.comparator.ComparatorMPlayerInactivity; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPlayer; +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.util.TimeDiffUtil; +import com.massivecraft.massivecore.util.TimeUnit; +import com.massivecraft.massivecore.util.Txt; + +import java.util.Comparator; +import java.util.LinkedHashMap; +import java.util.List; + +public class CmdFactionsStatus extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsStatus() { + // Parameters + this.addParameter(Parameter.getPage()); + this.addParameter(TypeFaction.get(), "faction", "you").setDesc("the faction whose status to see"); + this.addParameter(TypeSortMPlayer.get(), "sort", "time").setDesc("sort mplayers by rank, power or last active time?"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + int page = this.readArg(); + Faction faction = this.readArg(msenderFaction); + Comparator sortedBy = this.readArg(ComparatorMPlayerInactivity.get()); + + // Sort list + final List mplayers = faction.getMPlayers(); + mplayers.sort(sortedBy); + + // Pager Create + String title = Txt.parse("Status of %s.", faction.describeTo(msender, true)); + final Pager pager = new Pager<>(this, title, page, mplayers, (Stringifier) (mplayer, index) -> { + // Name + String displayName = mplayer.getNameAndSomething(msender.getColorTo(mplayer).toString(), ""); + int length = 15 - displayName.length(); + length = length <= 0 ? 1 : length; + String whiteSpace = Txt.repeat(" ", length); + + // Power + double currentPower = mplayer.getPower(); + double maxPower = mplayer.getPowerMax(); + String color; + double percent = currentPower / maxPower; + + if (percent > 0.75) { + color = ""; + } else if (percent > 0.5) { + color = ""; + } else if (percent > 0.25) { + color = ""; + } else { + color = ""; + } + + String power = Txt.parse("Power: %s%.0f/%.0f", Txt.parse(color), currentPower, maxPower); + + // Time + long lastActiveMillis = mplayer.getLastActivityMillis() - System.currentTimeMillis(); + LinkedHashMap activeTimes = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(lastActiveMillis, TimeUnit.getAllButMillis()), 3); + String lastActive = mplayer.isOnline(msender) ? Txt.parse("Online right now.") : Txt.parse("Last active: " + TimeDiffUtil.formatedMinimal(activeTimes, "")); + + return Txt.parse("%s%s %s %s", displayName, whiteSpace, power, lastActive); + }); + + + // Pager Message + pager.message(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsTax.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsTax.java new file mode 100644 index 00000000..7421d8af --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsTax.java @@ -0,0 +1,13 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsTax extends FactionsCommand { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public CmdFactionsTaxPlayer cmdFactionsTaxPlayer = new CmdFactionsTaxPlayer(); + public CmdFactionsTaxFaction cmdFactionsTaxFaction = new CmdFactionsTaxFaction(); + public CmdFactionsTaxSet cmdFactionsTaxSet = new CmdFactionsTaxSet(); + public CmdFactionsTaxRun cmdFactionsTaxRun = new CmdFactionsTaxRun(); + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsTaxFaction.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsTaxFaction.java new file mode 100644 index 00000000..ee254c67 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsTaxFaction.java @@ -0,0 +1,71 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.req.ReqTaxEnabled; +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.entity.Rank; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.mson.Mson; +import com.massivecraft.massivecore.util.Txt; + +import java.util.Map.Entry; + +public class CmdFactionsTaxFaction extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsTaxFaction() { + this.addParameter(TypeFaction.get(), "faction", "your"); + + this.addRequirements(ReqTaxEnabled.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + Faction faction = this.readArg(msenderFaction); + + if (faction.isNone()) { + throw new MassiveException().addMsg("Taxes are not in place for %s.", faction.describeTo(msender)); + } + + Mson title = Txt.titleize("Tax for " + faction.getDisplayName(msender)); + message(title); + + MFlag flag = MFlag.getFlagTaxKick(); + String flagDesc = flag.getStateDesc(faction.getFlag(flag), true, false, false, true, true); + msg("Player Kick: %s", flagDesc); + + boolean anyTax = false; + for (Entry entry : faction.getTax().entrySet()) { + String id = entry.getKey(); + Double tax = entry.getValue(); + + Rank rank = faction.getRank(id); + MPlayer mplayer = MPlayer.get(id); + + String name; + if (Faction.IDENTIFIER_TAX_BASE.equals(id)) { + name = "Default"; + } else if (rank != null) { + name = rank.getName(); + } else if (mplayer != null) { + name = mplayer.getDisplayName(msender); + } else { + continue; + } + anyTax = true; + msg("%s: %.2f", name, tax); + } + if (!anyTax) { + msg("No players in this faction pays taxes."); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsTaxPlayer.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsTaxPlayer.java new file mode 100644 index 00000000..a2d132af --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsTaxPlayer.java @@ -0,0 +1,41 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.req.ReqTaxEnabled; +import com.massivecraft.factions.cmd.type.TypeMPlayer; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.money.Money; +import com.massivecraft.massivecore.mson.Mson; +import com.massivecraft.massivecore.util.Txt; + +public class CmdFactionsTaxPlayer extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsTaxPlayer() { + this.addParameter(TypeMPlayer.get(), "player", "you"); + + this.addRequirements(ReqTaxEnabled.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + MPlayer mplayer = this.readArg(msender); + + Mson title = Txt.titleize("Tax for " + mplayer.getDisplayName(msender)); + message(title); + + String factionName = mplayer.getFaction().describeTo(msender); + msg("Faction: %s", factionName); + + double tax = mplayer.getFaction().getTaxForPlayer(mplayer); + String taxDesc = Money.format(tax); + msg("Tax: %s", taxDesc); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsTaxRun.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsTaxRun.java new file mode 100644 index 00000000..9892007d --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsTaxRun.java @@ -0,0 +1,25 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.req.ReqTaxEnabled; +import com.massivecraft.factions.task.TaskTax; +import com.massivecraft.massivecore.MassiveException; + +public class CmdFactionsTaxRun extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsTaxRun() { + this.addRequirements(ReqTaxEnabled.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + TaskTax.get().invoke(System.currentTimeMillis()); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsTaxSet.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsTaxSet.java new file mode 100644 index 00000000..771d10b4 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsTaxSet.java @@ -0,0 +1,89 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.req.ReqTaxEnabled; +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.cmd.type.TypeTaxable; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.entity.MPlayerColl; +import com.massivecraft.factions.entity.Rank; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.primitive.TypeDouble; +import com.massivecraft.massivecore.money.Money; +import com.massivecraft.massivecore.util.MUtil; + +public class CmdFactionsTaxSet extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsTaxSet() { + this.addParameter(TypeDouble.get(), "tax"); + this.addParameter(TypeTaxable.get(), "default|rank|player|all", "default"); + this.addParameter(TypeFaction.get(), "faction", "your"); + + this.addRequirements(ReqTaxEnabled.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + Double tax = this.readArg(); + + if (MConf.get().taxPlayerMaximum < tax && tax != 0) { + throw new MassiveException().addMsg("Taxes can't be above %s.", Money.format(MConf.get().taxPlayerMaximum)); + } + if (MConf.get().taxPlayerMinimum > tax && tax != 0) { + throw new MassiveException().addMsg("Taxes can't be below %s.", Money.format(MConf.get().taxPlayerMinimum)); + } + + Faction faction = this.readArgAt(2, msenderFaction); + TypeTaxable typeTaxable = TypeTaxable.get(faction); + String taxable = this.argIsSet(1) ? typeTaxable.read(this.argAt(1), sender) : Faction.IDENTIFIER_TAX_BASE; + + if (!MPerm.getPermTax().has(msender, faction, true)) { + return; + } + + Rank rank = faction.getRank(taxable); + MPlayer mplayer = MPlayerColl.get().get(taxable, false); + + String name; + if (Faction.IDENTIFIER_TAX_BASE.equalsIgnoreCase(taxable)) { + name = "Default"; + } else if (rank != null) { + name = rank.getDisplayName(msender); + } else if (mplayer != null) { + name = mplayer.getDisplayName(msender); + } else { + throw new RuntimeException(taxable); + } + + String taxDesc = Money.format(tax); + + Double previous = faction.setTaxFor(taxable, tax); + + if (MUtil.equalsishNumber(tax, previous)) { + throw new MassiveException().addMsg("The tax for %s is already %s.", name, taxDesc); + } + + msg("The taxes for %s is now set to %s.", name, taxDesc); + if (tax < 0) { + msg("NOTE: A negative tax works like a salary."); + } + + if (msender != mplayer && mplayer != null) { + mplayer.msg("%s set your tax to %s.", msender.getDisplayName(mplayer), taxDesc); + } + if (rank != null) { + String msg = "Taxes for %s set to %s by %s."; + faction.getMPlayersWhereRank(rank).forEach(mp -> mp.msg(msg, name, taxDesc, msender.getDisplayName(mp))); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsTerritorytitles.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsTerritorytitles.java new file mode 100644 index 00000000..3962eba5 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsTerritorytitles.java @@ -0,0 +1,59 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.Visibility; +import com.massivecraft.massivecore.command.requirement.RequirementTitlesAvailable; +import com.massivecraft.massivecore.command.type.primitive.TypeBooleanOn; +import com.massivecraft.massivecore.mixin.MixinTitle; +import com.massivecraft.massivecore.util.Txt; + +public class CmdFactionsTerritorytitles extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsTerritorytitles() { + // Aliases + this.addAliases("tt"); + + // Parameters + this.addParameter(TypeBooleanOn.get(), "on|off", "toggle"); + + // Requirements + this.addRequirements(RequirementTitlesAvailable.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Visibility getVisibility() { + // We hide the command if titles aren't available. + if (!MixinTitle.get().isAvailable()) { + return Visibility.INVISIBLE; + } + return super.getVisibility(); + } + + @Override + public void perform() throws MassiveException { + // Args + boolean before = msender.isTerritoryInfoTitles(); + boolean after = this.readArg(!before); + String desc = Txt.parse(after ? "ON" : "OFF"); + + // NoChange + if (after == before) { + msg("Territory titles is already %s.", desc); + return; + } + + // Apply + msender.setTerritoryInfoTitles(after); + + // Inform + msg("Territory titles is now %s.", desc); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsTitle.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsTitle.java new file mode 100644 index 00000000..9b9ad927 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsTitle.java @@ -0,0 +1,67 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Perm; +import com.massivecraft.factions.cmd.type.TypeMPlayer; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.event.EventFactionsTitleChange; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.primitive.TypeString; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.ChatColor; + +public class CmdFactionsTitle extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsTitle() { + // Parameters + this.addParameter(TypeMPlayer.get(), "player"); + this.addParameter(TypeString.get(), "title", "none", true); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + MPlayer you = this.readArg(); + String newTitle = this.readArg(""); + + newTitle = Txt.parse(newTitle); + if (!Perm.TITLE_COLOR.has(sender, false)) { + newTitle = ChatColor.stripColor(newTitle); + } + + // MPerm + if (!MPerm.getPermTitle().has(msender, you.getFaction(), true)) { + return; + } + + // Rank Check + if (!msender.isOverriding() && you.getRank().isMoreThan(msender.getRank())) { + throw new MassiveException().addMsg("You can not edit titles for higher ranks."); + } + if (!msender.isOverriding() && you.getRank() == msender.getRank() && msender != you) { + throw new MassiveException().addMsg("You can't edit titles of people with the same rank as yourself."); + } + + // Event + EventFactionsTitleChange event = new EventFactionsTitleChange(sender, you, newTitle); + event.run(); + if (event.isCancelled()) { + return; + } + newTitle = event.getNewTitle(); + + // Apply + you.setTitle(newTitle); + + // Inform + msenderFaction.msg("%s changed a title: %s", msender.describeTo(msenderFaction, true), you.describeTo(msenderFaction, true)); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsTop.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsTop.java new file mode 100644 index 00000000..f58dc3f0 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsTop.java @@ -0,0 +1,108 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.integration.Econ; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.Parameter; +import com.massivecraft.massivecore.command.type.enumeration.TypeEnum; +import com.massivecraft.massivecore.money.Money; +import com.massivecraft.massivecore.pager.Pager; +import com.massivecraft.massivecore.pager.Stringifier; +import com.massivecraft.massivecore.util.TimeDiffUtil; +import com.massivecraft.massivecore.util.TimeUnit; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; + +import java.util.LinkedHashMap; +import java.util.List; + +public class CmdFactionsTop extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsTop() { + // Parameters + this.addParameter(new TypeEnum<>(TopCategory.class)); + this.addParameter(Parameter.getPage()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + TopCategory category = this.readArg(); + int page = this.readArg(); + final CommandSender sender = this.sender; + final MPlayer msender = this.msender; + + if (category == TopCategory.MONEY && !Econ.isEnabled()) { + throw new MassiveException().addMsg("Economy is not enabled."); + } + + Pager pager = new Pager<>(this, "Faction top", page); + pager.setMsonifier((Stringifier) (f, i) -> getValue(category, f, msender)); + + // NOTE: The faction list is quite slow and mostly thread safe. + // We run it asynchronously to spare the primary server thread. + + Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> { + // Pager Items + List factions = FactionColl.get().getAll((f1, f2) -> (int) (getNumber(category, f2) - getNumber(category, f1))); + pager.setItems(factions); + + // Pager Message + pager.message(); + }); + } + + private static double getNumber(TopCategory category, Faction faction) { + switch (category) { + case MONEY: + return Econ.getMoney(faction); + case MEMBERS: + return faction.getMPlayers().size(); + case TERRITORY: + return faction.getLandCount(); + case AGE: + return faction.getAge(); + } + throw new RuntimeException(); + } + + private static String getValue(TopCategory category, Faction faction, MPlayer mplayer) { + String ret = Txt.parse("%s: ", faction.getName(mplayer)); + switch (category) { + case MONEY: + ret += Money.format(Econ.getMoney(faction), true); + break; + case MEMBERS: + ret += faction.getMPlayers().size() + " members"; + break; + case TERRITORY: + ret += faction.getLandCount() + " chunks"; + break; + case AGE: + long ageMillis = faction.getAge(); + LinkedHashMap ageUnitcounts = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(ageMillis, TimeUnit.getAllButMillis()), 3); + ret += TimeDiffUtil.formatedVerboose(ageUnitcounts); + break; + } + return ret; + } + + public enum TopCategory { + MONEY, + MEMBERS, + TERRITORY, + AGE, + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java new file mode 100644 index 00000000..1196694f --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java @@ -0,0 +1,15 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsUnclaim extends FactionsCommand { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public CmdFactionsSetOne cmdFactionsUnclaimOne = new CmdFactionsSetOne(false); + public CmdFactionsSetAuto cmdFactionsUnclaimAuto = new CmdFactionsSetAuto(false); + public CmdFactionsSetFill cmdFactionsUnclaimFill = new CmdFactionsSetFill(false); + public CmdFactionsSetSquare cmdFactionsUnclaimSquare = new CmdFactionsSetSquare(false); + public CmdFactionsSetCircle cmdFactionsUnclaimCircle = new CmdFactionsSetCircle(false); + public CmdFactionsSetAll cmdFactionsUnclaimAll = new CmdFactionsSetAll(false); + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsUnsethome.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsUnsethome.java new file mode 100644 index 00000000..428122b0 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsUnsethome.java @@ -0,0 +1,38 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.Visibility; +import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; +import com.massivecraft.massivecore.util.MUtil; + +import java.util.List; + +public class CmdFactionsUnsethome extends FactionsCommandWarp { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsUnsethome() { + // Requirements + this.addRequirements(RequirementIsPlayer.get()); + + // Parameters + this.addParameter(TypeFaction.get(), "faction", "you"); + + // Visibility + this.setVisibility(Visibility.INVISIBLE); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + List args = MUtil.list(MConf.get().warpsHomeName, this.argAt(0)); + CmdFactions.get().cmdFactionsWarp.cmdFactionWarpRemove.execute(me, args); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsUnstuck.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsUnstuck.java new file mode 100644 index 00000000..7073cf23 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsUnstuck.java @@ -0,0 +1,145 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; +import com.massivecraft.massivecore.mixin.MixinTeleport; +import com.massivecraft.massivecore.mixin.TeleporterException; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.teleport.Destination; +import com.massivecraft.massivecore.teleport.DestinationSimple; +import org.bukkit.Location; +import org.bukkit.World; + +import java.util.ArrayList; +import java.util.List; + +public class CmdFactionsUnstuck extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsUnstuck() { + // Requirements + this.addRequirements(RequirementIsPlayer.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // If the player is in a chunk ... + final PS center = PS.valueOf(me.getLocation().getChunk()); + + // ... that isn't free ... + if (isFree(msender, center)) { + msg("You don't seem to be stuck."); + return; + } + + // ... get the nearest free top location ... + Location location = getNearestFreeTopLocation(msender, center); + if (location == null) { + msg("No nearby chunk with %s or build rights found.", FactionColl.get().getNone().describeTo(msender)); + return; + } + + // ... and schedule a teleport. + Destination destination = new DestinationSimple(PS.valueOf(location)); + try { + MixinTeleport.get().teleport(me, destination, MConf.get().unstuckSeconds); + } catch (TeleporterException e) { + msg("%s", e.getMessage()); + } + } + + // Get the first free top location in the spiral. + public static Location getNearestFreeTopLocation(MPlayer mplayer, PS ps) { + List chunks = getChunkSpiral(ps); + for (PS chunk : chunks) { + if (!isFree(mplayer, chunk)) { + continue; + } + Location ret = getTopLocation(chunk); + if (ret == null) { + continue; + } + return ret; + } + return null; + } + + // Return the ground level top location for this ps. + public static Location getTopLocation(PS ps) { + Location ret = null; + try { + World world = ps.asBukkitWorld(); + + int blockX = ps.getBlockX(true); + int blockZ = ps.getBlockZ(true); + int blockY = world.getHighestBlockYAt(blockX, blockZ); + + // We must have something to stand on. + if (blockY <= 1) { + return null; + } + + double locationX = blockX + 0.5D; + double locationY = blockY + 0.5D; + double locationZ = blockZ + 0.5D; + + ret = new Location(world, locationX, locationY, locationZ); + } catch (Exception e) { + e.printStackTrace(); + } + return ret; + } + + // With a "free" chunk we mean wilderness or that the player has build rights. + public static boolean isFree(MPlayer mplayer, PS ps) { + Faction faction = BoardColl.get().getFactionAt(ps); + if (faction.isNone()) { + return true; + } + return MPerm.getPermBuild().has(mplayer, ps, false); + } + + // Not exactly a spiral. But it will do. + public static List getChunkSpiral(PS center) { + // Create Ret + List ret = new ArrayList<>(); + + // Fill Ret + center = center.getChunk(true); + final int centerX = center.getChunkX(); + final int centerZ = center.getChunkZ(); + + for (int delta = 1; delta <= MConf.get().unstuckChunkRadius; delta++) { + int minX = centerX - delta; + int maxX = centerX + delta; + int minZ = centerZ - delta; + int maxZ = centerZ + delta; + + for (int x = minX; x <= maxX; x++) { + ret.add(center.withChunkX(x).withChunkZ(minZ)); + ret.add(center.withChunkX(x).withChunkZ(maxZ)); + } + + for (int z = minZ + 1; z <= maxZ - 1; z++) { + ret.add(center.withChunkX(minX).withChunkZ(z)); + ret.add(center.withChunkX(maxX).withChunkZ(z)); + } + } + + // Return Ret + return ret; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsVote.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsVote.java new file mode 100644 index 00000000..410ec86a --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsVote.java @@ -0,0 +1,14 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsVote extends FactionsCommand { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public CmdFactionsVoteShow cmdFactionsVoteShow = new CmdFactionsVoteShow(); + public CmdFactionsVoteList cmdFactionsVoteList = new CmdFactionsVoteList(); + public CmdFactionsVoteDo cmdFactionsVoteDo = new CmdFactionsVoteDo(); + public CmdFactionsVoteCreate cmdFactionsVoteCreate = new CmdFactionsVoteCreate(); + public CmdFactionsVoteRemove cmdFactionsVoteRemove = new CmdFactionsVoteRemove(); + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsVoteCreate.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsVoteCreate.java new file mode 100644 index 00000000..f95973eb --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsVoteCreate.java @@ -0,0 +1,72 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.Vote; +import com.massivecraft.factions.event.EventFactionsVoteAdd; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.collections.MassiveList; +import com.massivecraft.massivecore.command.type.container.TypeList; +import com.massivecraft.massivecore.command.type.primitive.TypeString; +import com.massivecraft.massivecore.util.IdUtil; + +import java.util.List; + +public class CmdFactionsVoteCreate extends FactionsCommandWarp { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsVoteCreate() { + // Parameters + this.addParameter(TypeString.get(), "name"); + this.addParameter(TypeList.get(TypeString.get()), "options", true); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + String name = this.readArg(); + List options = this.readArg(); + + // MPerm + if (!MPerm.getPermCreateVote().has(msender, msenderFaction, true)) { + return; + } + + if (msenderFaction.getVoteByName(name).isPresent()) { + throw new MassiveException().addMsg("There is already a vote called %s.", name); + } + + // Make sure there are no duplicated + List options2 = new MassiveList<>(); + for (String str : options) { + if (options2.stream().anyMatch(str::equalsIgnoreCase)) { + continue; + } + options2.add(str); + } + + + Vote vote = new Vote(IdUtil.getId(sender), name, options2); + + // Event + EventFactionsVoteAdd event = new EventFactionsVoteAdd(sender, msenderFaction, vote); + event.run(); + if (event.isCancelled()) { + return; + } + vote = event.getVote(); + + // Apply + msenderFaction.addVote(vote); + + // Inform + msenderFaction.msg("%s added the vote %s to your faction. You can now use:", msender.describeTo(msenderFaction, true), vote.getName()); + msenderFaction.sendMessage(CmdFactions.get().cmdFactionsVote.cmdFactionsVoteDo.getTemplateWithArgs(null, vote.getName())); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsVoteDo.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsVoteDo.java new file mode 100644 index 00000000..f7ce9142 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsVoteDo.java @@ -0,0 +1,44 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeVote; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.Vote; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.primitive.TypeString; + +public class CmdFactionsVoteDo extends FactionsCommandWarp { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsVoteDo() { + // Parameters + this.addParameter(TypeVote.get()); + this.addParameter(TypeString.get(), "option"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + Vote vote = TypeVote.get(msenderFaction).read(this.arg(), sender); + String option = this.readArg(); + + // Any and MPerm + if (!MPerm.getPermVote().has(msender, msenderFaction, true)) { + return; + } + + if (vote.getOptions().stream().noneMatch(option::equalsIgnoreCase)) { + throw new MassiveException().addMsg("No option in %s matches %s.", vote.getName(), option); + } + + vote.setVote(msender, option); + + msg("Succesfully voted for %s in %s.", option, vote.getName()); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsVoteList.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsVoteList.java new file mode 100644 index 00000000..3ce464d3 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsVoteList.java @@ -0,0 +1,39 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.entity.Vote; +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.util.Txt; + +public class CmdFactionsVoteList extends FactionsCommandWarp { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsVoteList() { + // Parameters + this.addParameter(Parameter.getPage()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + int idx = this.readArg(); + + Pager pager = new Pager<>(this, "Faction Votes", idx, msenderFaction.getVotes().getAll()); + pager.setMsonifier((Stringifier) (vote, i) -> + { + String options = Txt.implodeCommaAndDot(vote.getOptions(), Txt.parse("%s"), Txt.parse(", "), Txt.parse(" and "), ""); + return Txt.parse("%s: %s", vote.getName(), options); + }); + + pager.message(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsVoteRemove.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsVoteRemove.java new file mode 100644 index 00000000..c688cd4b --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsVoteRemove.java @@ -0,0 +1,48 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeVote; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.Vote; +import com.massivecraft.factions.event.EventFactionsVoteRemove; +import com.massivecraft.massivecore.MassiveException; + +public class CmdFactionsVoteRemove extends FactionsCommandWarp { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsVoteRemove() { + // Parameters + this.addParameter(TypeVote.get(), "vote"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + Vote vote = TypeVote.get(msenderFaction).read(this.arg(), sender); + + // Any and MPerm + if (!MPerm.getPermCreateVote().has(msender, msenderFaction, true)) { + return; + } + + // Event + EventFactionsVoteRemove event = new EventFactionsVoteRemove(sender, msenderFaction, vote); + event.run(); + if (event.isCancelled()) { + return; + } + vote = event.getVote(); + + // Apply + vote.detach(); + + // Inform + msender.msg("%s removed the vote %s from your faction.", msender.describeTo(msenderFaction, true), vote.getName()); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsVoteShow.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsVoteShow.java new file mode 100644 index 00000000..24f310dc --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsVoteShow.java @@ -0,0 +1,47 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeVote; +import com.massivecraft.factions.entity.Vote; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.util.Txt; + +public class CmdFactionsVoteShow extends FactionsCommandWarp { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsVoteShow() { + // Parameters + this.addParameter(TypeVote.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + Vote vote = TypeVote.get(msenderFaction).read(this.arg(), sender); + + // Clean the vote + vote.clean(); + + // Message + message(Txt.titleize("Votes for " + vote.getName())); + + int numberOfVotes = vote.getId2Vote().size(); + for (String option : vote.getOptions()) { + long num = vote.getId2Vote().values().stream() + .filter(option::equalsIgnoreCase).count(); + + double percent = ((double) num / (double) numberOfVotes) * 100; + if (Double.isInfinite(percent)) { + percent = 0D; + } + String str = Txt.parse("%s: %d/%d (%.2f%%)", option, num, numberOfVotes, percent); + message(str); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsWarp.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsWarp.java new file mode 100644 index 00000000..f893507c --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsWarp.java @@ -0,0 +1,13 @@ +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/main/java/com/massivecraft/factions/cmd/CmdFactionsWarpAdd.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsWarpAdd.java new file mode 100644 index 00000000..464a2a36 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsWarpAdd.java @@ -0,0 +1,82 @@ +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.getPermSetwarp().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/main/java/com/massivecraft/factions/cmd/CmdFactionsWarpGo.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsWarpGo.java new file mode 100644 index 00000000..b2765c18 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsWarpGo.java @@ -0,0 +1,142 @@ +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.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; +import com.massivecraft.massivecore.mixin.MixinTeleport; +import com.massivecraft.massivecore.mixin.TeleporterException; +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 CmdFactionsWarpGo extends FactionsCommandWarp { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsWarpGo() { + // Parameters + this.addParameter(TypeWarp.get(), "warp"); + this.addParameter(TypeFaction.get(), "faction", "you"); + + // Requirements + this.addRequirements(RequirementIsPlayer.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + 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)); + + // Must be valid + if (!warp.verifyIsValid()) { + return; + } + + // Any and MPerm + if (!MPerm.getPermWarp().has(msender, faction, true)) { + return; + } + + if (!MConf.get().warpsTeleportAllowedFromEnemyTerritory && msender.isInEnemyTerritory()) { + throw new MassiveException().addMsg("You cannot teleport to %s while in the territory of an enemy faction.", warp); + } + + if (!MConf.get().warpsTeleportAllowedFromDifferentWorld && !me.getWorld().getName().equalsIgnoreCase(warp.getWorld())) { + throw new MassiveException().addMsg("You cannot teleport to %s while in a different world.", warpDesc); + } + + 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().warpsTeleportAllowedEnemyDistance > 0 + && + factionHere.getFlag(MFlag.getFlagPvp()) + && + ( + !msender.isInOwnTerritory() + || + ( + msender.isInOwnTerritory() + && + !MConf.get().warpsTeleportIgnoreEnemiesIfInOwnTerritory + ) + ) + ) { + World w = locationHere.getWorld(); + double x = locationHere.getX(); + double y = locationHere.getY(); + double z = locationHere.getZ(); + + for (Player p : w.getPlayers()) { + if (MUtil.isntPlayer(p)) { + continue; + } + + if (!p.isOnline() || p.isDead() || p == me || p.getWorld() != w) { + continue; + } + + MPlayer fp = MPlayer.get(p); + 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().warpsTeleportAllowedEnemyDistance; + + // box-shaped distance check + if (dx > max || dy > max || dz > max) { + continue; + } + + throw new MassiveException().addMsg("You cannot teleport to %s while an enemy is within %f blocks of you.", warpDesc, max); + } + } + + // Event + EventFactionsWarpTeleport event = new EventFactionsWarpTeleport(sender, warp); + event.run(); + if (event.isCancelled()) { + return; + } + + // Apply + try { + Destination destination = new DestinationSimple(warp.getLocation(), warpDesc); + MixinTeleport.get().teleport(me, destination, sender); + } catch (TeleporterException e) { + String message = e.getMessage(); + MixinMessage.get().messageOne(me, message); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsWarpList.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsWarpList.java new file mode 100644 index 00000000..a6337df0 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsWarpList.java @@ -0,0 +1,47 @@ +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.getPermWarp().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/main/java/com/massivecraft/factions/cmd/CmdFactionsWarpRemove.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsWarpRemove.java new file mode 100644 index 00000000..acde2ed2 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsWarpRemove.java @@ -0,0 +1,55 @@ +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.entity.Warp; +import com.massivecraft.factions.event.EventFactionsWarpRemove; +import com.massivecraft.massivecore.MassiveException; + +public class CmdFactionsWarpRemove extends FactionsCommandWarp { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsWarpRemove() { + // Parameters + this.addParameter(TypeWarp.get(), "warp"); + this.addParameter(TypeFaction.get(), "faction", "you"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException { + // Args + Faction faction = this.readArgAt(1, msenderFaction); + Warp warp = TypeWarp.get(faction).read(this.argAt(0), sender); + + // Any and MPerm + if (!MPerm.getPermSetwarp().has(msender, faction, true)) { + return; + } + + // Event + EventFactionsWarpRemove event = new EventFactionsWarpRemove(sender, faction, warp); + event.run(); + if (event.isCancelled()) { + return; + } + warp = event.getWarp(); + + // Apply + warp.detach(); + + // Inform + faction.msg("%s removed the warp %s for your faction.", msender.describeTo(msenderFaction, true), warp.getName()); + if (faction != msenderFaction) { + msender.msg("You have removed the warp %s for %s.", warp.getName(), faction.getName(msender)); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/FactionsCommand.java b/src/main/java/com/massivecraft/factions/cmd/FactionsCommand.java new file mode 100644 index 00000000..3e69c93b --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/FactionsCommand.java @@ -0,0 +1,33 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.command.MassiveCommand; + +public class FactionsCommand extends MassiveCommand { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public MPlayer msender; + public Faction msenderFaction; + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public FactionsCommand() { + + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void senderFields(boolean set) { + this.msender = set ? MPlayer.get(sender) : null; + this.msenderFaction = set ? this.msender.getFaction() : null; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/FactionsCommandDocumentation.java b/src/main/java/com/massivecraft/factions/cmd/FactionsCommandDocumentation.java new file mode 100644 index 00000000..b2ba5b99 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/FactionsCommandDocumentation.java @@ -0,0 +1,46 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.req.ReqFactionWarpsEnabled; +import com.massivecraft.massivecore.mson.Mson; + +public class FactionsCommandDocumentation extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public FactionsCommandDocumentation() { + this.addRequirements(ReqFactionWarpsEnabled.get()); + } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public int num = 1; + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void senderFields(boolean set) { + super.senderFields(set); + + num = 1; + } + + // -------------------------------------------- // + // MESSAGE + // -------------------------------------------- // + + public void msgDoc(String msg, Object... args) { + msg = "" + this.num++ + ") " + msg; + msg(msg, args); + } + + public void messageDoc(Mson message) { + Mson mson = mson(Mson.parse("" + this.num++ + ") "), message); + message(mson); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/FactionsCommandWarp.java b/src/main/java/com/massivecraft/factions/cmd/FactionsCommandWarp.java new file mode 100644 index 00000000..81a4e808 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/FactionsCommandWarp.java @@ -0,0 +1,25 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.req.ReqFactionWarpsEnabled; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.massivecore.command.Visibility; + +public class FactionsCommandWarp extends FactionsCommand { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public FactionsCommandWarp() { + this.addRequirements(ReqFactionWarpsEnabled.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Visibility getVisibility() { + return MConf.get().warpsEnabled ? super.getVisibility() : Visibility.INVISIBLE; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/req/ReqBankCommandsEnabled.java b/src/main/java/com/massivecraft/factions/cmd/req/ReqBankCommandsEnabled.java new file mode 100644 index 00000000..e5bf8d1d --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/req/ReqBankCommandsEnabled.java @@ -0,0 +1,42 @@ +package com.massivecraft.factions.cmd.req; + +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.integration.Econ; +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 ReqBankCommandsEnabled extends RequirementAbstract { + // -------------------------------------------- // + // SERIALIZABLE + // -------------------------------------------- // + + private static final long serialVersionUID = 1L; + + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ReqBankCommandsEnabled i = new ReqBankCommandsEnabled(); + + public static ReqBankCommandsEnabled get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public boolean apply(CommandSender sender, MassiveCommand command) { + return MConf.get().bankEnabled && Econ.isEnabled(); + } + + @Override + public String createErrorMessage(CommandSender sender, MassiveCommand command) { + String what = !MConf.get().bankEnabled ? "banks" : "economy features"; + return Txt.parse("Faction %s are disabled.", what); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/req/ReqFactionWarpsEnabled.java b/src/main/java/com/massivecraft/factions/cmd/req/ReqFactionWarpsEnabled.java new file mode 100644 index 00000000..b321a5ab --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/req/ReqFactionWarpsEnabled.java @@ -0,0 +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 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/main/java/com/massivecraft/factions/cmd/req/ReqHasFaction.java b/src/main/java/com/massivecraft/factions/cmd/req/ReqHasFaction.java new file mode 100644 index 00000000..b34ed30f --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/req/ReqHasFaction.java @@ -0,0 +1,46 @@ +package com.massivecraft.factions.cmd.req; + +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.command.MassiveCommand; +import com.massivecraft.massivecore.command.requirement.RequirementAbstract; +import com.massivecraft.massivecore.util.MUtil; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.command.CommandSender; + +public class ReqHasFaction extends RequirementAbstract { + // -------------------------------------------- // + // SERIALIZABLE + // -------------------------------------------- // + + private static final long serialVersionUID = 1L; + + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ReqHasFaction i = new ReqHasFaction(); + + public static ReqHasFaction get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public boolean apply(CommandSender sender, MassiveCommand command) { + if (MUtil.isntSender(sender)) { + return false; + } + + MPlayer mplayer = MPlayer.get(sender); + return mplayer.hasFaction(); + } + + @Override + public String createErrorMessage(CommandSender sender, MassiveCommand command) { + return Txt.parse("You must belong to a faction to %s.", getDesc(command)); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/req/ReqHasntFaction.java b/src/main/java/com/massivecraft/factions/cmd/req/ReqHasntFaction.java new file mode 100644 index 00000000..58ae6862 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/req/ReqHasntFaction.java @@ -0,0 +1,46 @@ +package com.massivecraft.factions.cmd.req; + +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.command.MassiveCommand; +import com.massivecraft.massivecore.command.requirement.RequirementAbstract; +import com.massivecraft.massivecore.util.MUtil; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.command.CommandSender; + +public class ReqHasntFaction extends RequirementAbstract { + // -------------------------------------------- // + // SERIALIZABLE + // -------------------------------------------- // + + private static final long serialVersionUID = 1L; + + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ReqHasntFaction i = new ReqHasntFaction(); + + public static ReqHasntFaction get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public boolean apply(CommandSender sender, MassiveCommand command) { + if (MUtil.isntSender(sender)) { + return true; + } + + MPlayer mplayer = MPlayer.get(sender); + return !mplayer.hasFaction(); + } + + @Override + public String createErrorMessage(CommandSender sender, MassiveCommand command) { + return Txt.parse("You must leave your current faction before you %s.", getDesc(command)); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/req/ReqRankIsAtLeast.java b/src/main/java/com/massivecraft/factions/cmd/req/ReqRankIsAtLeast.java new file mode 100644 index 00000000..32919e4a --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/req/ReqRankIsAtLeast.java @@ -0,0 +1,59 @@ +package com.massivecraft.factions.cmd.req; + +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.entity.Rank; +import com.massivecraft.massivecore.command.MassiveCommand; +import com.massivecraft.massivecore.command.requirement.RequirementAbstract; +import com.massivecraft.massivecore.util.MUtil; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.command.CommandSender; + +public class ReqRankIsAtLeast extends RequirementAbstract { + // -------------------------------------------- // + // SERIALIZABLE + // -------------------------------------------- // + + private static final long serialVersionUID = 1L; + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final Rank rank; + + public Rank getRank() { + return this.rank; + } + + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + public static ReqRankIsAtLeast get(Rank rank) { + return new ReqRankIsAtLeast(rank); + } + + private ReqRankIsAtLeast(Rank rank) { + this.rank = rank; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public boolean apply(CommandSender sender, MassiveCommand command) { + if (MUtil.isntSender(sender)) { + return false; + } + + MPlayer mplayer = MPlayer.get(sender); + return mplayer.getRank().isAtLeast(this.getRank()); + } + + @Override + public String createErrorMessage(CommandSender sender, MassiveCommand command) { + return Txt.parse("You must be %s or higher to %s.", rank.getName(), getDesc(command)); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/req/ReqTaxEnabled.java b/src/main/java/com/massivecraft/factions/cmd/req/ReqTaxEnabled.java new file mode 100644 index 00000000..7dae5623 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/req/ReqTaxEnabled.java @@ -0,0 +1,40 @@ +package com.massivecraft.factions.cmd.req; + +import com.massivecraft.factions.task.TaskTax; +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 ReqTaxEnabled extends RequirementAbstract { + // -------------------------------------------- // + // SERIALIZABLE + // -------------------------------------------- // + + private static final long serialVersionUID = 1L; + + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ReqTaxEnabled i = new ReqTaxEnabled(); + + public static ReqTaxEnabled get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public boolean apply(CommandSender sender, MassiveCommand command) { + return TaskTax.get().areConditionsMet(); + } + + @Override + public String createErrorMessage(CommandSender sender, MassiveCommand command) { + return Txt.parse("Tax is not enabled on this server."); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/type/TypeEntityInternalFaction.java b/src/main/java/com/massivecraft/factions/cmd/type/TypeEntityInternalFaction.java new file mode 100644 index 00000000..ab100b3c --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/type/TypeEntityInternalFaction.java @@ -0,0 +1,85 @@ +package com.massivecraft.factions.cmd.type; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.collections.MassiveSet; +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; +import java.util.Set; + + +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); + } + } + + @Override + public Collection getTabList(CommandSender sender, String arg) { + if (this.getFaction() != null) { + return super.getTabList(sender, arg); + } + + // Default to tab list for the sender + Faction faction = MPlayer.get(sender).getFaction(); + + // Create + Set ret = new MassiveSet<>(); + + // Fill + for (E value : this.getAll(faction)) { + ret.addAll(this.createTabs(value)); + } + + // Return + return ret; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/type/TypeFaction.java b/src/main/java/com/massivecraft/factions/cmd/type/TypeFaction.java new file mode 100644 index 00000000..453a4f0a --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/type/TypeFaction.java @@ -0,0 +1,97 @@ +package com.massivecraft.factions.cmd.type; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.entity.MPlayerColl; +import com.massivecraft.massivecore.MassiveCore; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.TypeAbstract; +import com.massivecraft.massivecore.comparator.ComparatorCaseInsensitive; +import com.massivecraft.massivecore.util.IdUtil; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; + +import java.util.Collection; +import java.util.Set; +import java.util.TreeSet; + +public class TypeFaction extends TypeAbstract { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static TypeFaction i = new TypeFaction(); + + public static TypeFaction get() { + return i; + } + + public TypeFaction() { + super(Faction.class); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getVisualInner(Faction value, CommandSender sender) { + return value.describeTo(MPlayer.get(sender)); + } + + @Override + public String getNameInner(Faction value) { + return ChatColor.stripColor(value.getName()); + } + + @Override + public Faction read(String str, CommandSender sender) throws MassiveException { + Faction ret; + + // Nothing/Remove targets Wilderness + if (MassiveCore.NOTHING_REMOVE.contains(str)) { + return FactionColl.get().getNone(); + } + + // Faction Id Exact + if (FactionColl.get().containsId(str)) { + ret = FactionColl.get().get(str); + if (ret != null) { + return ret; + } + } + + // Faction Name Exact + ret = FactionColl.get().getByName(str); + if (ret != null) { + return ret; + } + + // MPlayer Name Exact + String id = IdUtil.getId(str); + if (id != null) { + MPlayer mplayer = MPlayerColl.get().get(id, false); + if (mplayer != null) { + return mplayer.getFaction(); + } + } + + throw new MassiveException().addMsg("No faction or player matching \"

%s\".", str); + } + + @Override + public Collection getTabList(CommandSender sender, String arg) { + // Create + Set ret = new TreeSet<>(ComparatorCaseInsensitive.get()); + + // Fill + for (Faction faction : FactionColl.get().getAll()) { + ret.add(ChatColor.stripColor(faction.getName())); + } + + // Return + return ret; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/type/TypeFactionChunkChangeType.java b/src/main/java/com/massivecraft/factions/cmd/type/TypeFactionChunkChangeType.java new file mode 100644 index 00000000..207149f5 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/type/TypeFactionChunkChangeType.java @@ -0,0 +1,21 @@ +package com.massivecraft.factions.cmd.type; + +import com.massivecraft.factions.event.EventFactionsChunkChangeType; +import com.massivecraft.massivecore.command.type.enumeration.TypeEnum; + +public class TypeFactionChunkChangeType extends TypeEnum { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static TypeFactionChunkChangeType i = new TypeFactionChunkChangeType(); + + public static TypeFactionChunkChangeType get() { + return i; + } + + public TypeFactionChunkChangeType() { + super(EventFactionsChunkChangeType.class); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/type/TypeFactionNameAbstract.java b/src/main/java/com/massivecraft/factions/cmd/type/TypeFactionNameAbstract.java new file mode 100644 index 00000000..0da32a9a --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/type/TypeFactionNameAbstract.java @@ -0,0 +1,50 @@ +package com.massivecraft.factions.cmd.type; + +import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.util.MiscUtil; +import com.massivecraft.massivecore.Named; +import com.massivecraft.massivecore.command.type.TypeNameAbstract; +import org.bukkit.command.CommandSender; + +public class TypeFactionNameAbstract extends TypeNameAbstract { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public TypeFactionNameAbstract(boolean strict) { + super(strict); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Named getCurrent(CommandSender sender) { + MPlayer mplayer = MPlayer.get(sender); + return mplayer.getFaction(); + } + + @Override + public boolean isNameTaken(String name) { + return FactionColl.get().isNameTaken(name); + } + + @Override + public boolean isCharacterAllowed(char character) { + return MiscUtil.substanceChars.contains(String.valueOf(character)); + } + + @Override + public Integer getLengthMin() { + return MConf.get().factionNameLengthMin; + } + + @Override + public Integer getLengthMax() { + return MConf.get().factionNameLengthMax; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/type/TypeFactionNameLenient.java b/src/main/java/com/massivecraft/factions/cmd/type/TypeFactionNameLenient.java new file mode 100644 index 00000000..c042fef1 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/type/TypeFactionNameLenient.java @@ -0,0 +1,18 @@ +package com.massivecraft.factions.cmd.type; + +public class TypeFactionNameLenient extends TypeFactionNameAbstract { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static TypeFactionNameLenient i = new TypeFactionNameLenient(); + + public static TypeFactionNameLenient get() { + return i; + } + + public TypeFactionNameLenient() { + super(false); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/type/TypeFactionNameStrict.java b/src/main/java/com/massivecraft/factions/cmd/type/TypeFactionNameStrict.java new file mode 100644 index 00000000..5b790c97 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/type/TypeFactionNameStrict.java @@ -0,0 +1,18 @@ +package com.massivecraft.factions.cmd.type; + +public class TypeFactionNameStrict extends TypeFactionNameAbstract { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static TypeFactionNameStrict i = new TypeFactionNameStrict(); + + public static TypeFactionNameStrict get() { + return i; + } + + public TypeFactionNameStrict() { + super(true); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/type/TypeMFlag.java b/src/main/java/com/massivecraft/factions/cmd/type/TypeMFlag.java new file mode 100644 index 00000000..97bbcb4f --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/type/TypeMFlag.java @@ -0,0 +1,38 @@ +package com.massivecraft.factions.cmd.type; + +import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.factions.entity.MFlagColl; +import com.massivecraft.massivecore.command.type.store.TypeEntity; + +import java.util.Collection; + +public class TypeMFlag extends TypeEntity { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static TypeMFlag i = new TypeMFlag(); + + public static TypeMFlag get() { + return i; + } + + public TypeMFlag() { + super(MFlagColl.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getName() { + return "faction flag"; + } + + @Override + public Collection getAll() { + return MFlag.getAll(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/type/TypeMPerm.java b/src/main/java/com/massivecraft/factions/cmd/type/TypeMPerm.java new file mode 100644 index 00000000..8e857bad --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/type/TypeMPerm.java @@ -0,0 +1,39 @@ +package com.massivecraft.factions.cmd.type; + +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.MPermColl; +import com.massivecraft.massivecore.command.type.store.TypeEntity; + +import java.util.Collection; + +public class TypeMPerm extends TypeEntity { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static TypeMPerm i = new TypeMPerm(); + + public static TypeMPerm get() { + return i; + } + + public TypeMPerm() { + super(MPermColl.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getName() { + return "faction permission"; + } + + @Override + public Collection getAll() { + return MPerm.getAll(); + } + + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/type/TypeMPermable.java b/src/main/java/com/massivecraft/factions/cmd/type/TypeMPermable.java new file mode 100644 index 00000000..c27c1ae3 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/type/TypeMPermable.java @@ -0,0 +1,192 @@ +package com.massivecraft.factions.cmd.type; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.entity.Rank; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.collections.MassiveList; +import com.massivecraft.massivecore.command.type.TypeAbstract; +import com.massivecraft.massivecore.util.MUtil; +import org.bukkit.command.CommandSender; + +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + +public class TypeMPermable extends TypeAbstract { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static TypeMPermable i = new TypeMPermable(); + + public static TypeMPermable get() { + return i; + } + + private TypeMPermable() { + super(Rank.class); + + this.faction = null; + } + + public static TypeMPermable get(Faction faction) { + return new TypeMPermable(faction); + } + + public TypeMPermable(Faction faction) { + super(MPerm.MPermable.class); + if (faction == null) { + throw new NullPointerException("faction"); + } + + this.faction = faction; + } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final Faction faction; + + public Faction getFaction() { + return this.faction; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public MPerm.MPermable read(String arg, CommandSender sender) throws MassiveException { + if (arg.toLowerCase().startsWith("rank-")) { + String subArg = arg.substring("rank-".length()); + return new TypeRank(this.getFaction()).read(subArg, sender); + } + + if (arg.toLowerCase().startsWith("relation-")) { + String subArg = arg.substring("relation-".length()); + return TypeRelation.get().read(subArg, sender); + } + + if (arg.toLowerCase().startsWith("player-")) { + String subArg = arg.substring("player-".length()); + return TypeMPlayer.get().read(subArg, sender); + } + + if (arg.toLowerCase().startsWith("faction-")) { + String subArg = arg.substring("faction-".length()); + return TypeFaction.get().read(subArg, sender); + } + + TypeRank typeRank = new TypeRank(this.getFaction()); + try { + return typeRank.read(arg, sender); + } catch (MassiveException ex) { + // Do nothing + } + + try { + return TypeRelation.get().read(arg, sender); + } catch (MassiveException ex) { + // Do nothing + } + + try { + return TypeMPlayer.get().read(arg, sender); + } catch (MassiveException ex) { + // Do nothing + } + + try { + return TypeFaction.get().read(arg, sender); + } catch (MassiveException ex) { + // Do nothing + } + + if (arg.contains("-")) { + int idx = arg.indexOf('-'); + String factionName = arg.substring(0, idx); + String rankName = arg.substring(idx + 1); + + Faction faction = TypeFaction.get().read(factionName, sender); + return TypeRank.get(faction).read(rankName, sender); + } + + throw new MassiveException().addMsg("No rank, relation, player or faction matches: %s.", arg); + } + + public Collection getTabList(CommandSender sender, String arg) { + List ret = new MassiveList<>(); + Faction faction = this.getFaction(); + if (faction == null) { + faction = MPlayer.get(sender).getFaction(); + } + + // Always add ranks, relations, other factions and other players + ret.addAll(faction.getRanks().getAll().stream().map(Rank::getName).collect(Collectors.toList())); + ret.addAll(TypeRelation.get().getTabList(sender, arg)); + ret.addAll(TypeFaction.get().getTabList(sender, arg)); + ret.addAll(TypeMPlayer.get().getTabList(sender, arg)); + + // If something has been specified, then suggest factin specific ranks + if (arg.length() >= 2) { + for (Faction f : FactionColl.get().getAll()) { + String name = f.getName(); + if (arg.length() <= name.length() && !name.toLowerCase().startsWith(arg.toLowerCase())) { + continue; + } + if (arg.length() > name.length() && !arg.toLowerCase().startsWith(name.toLowerCase())) { + continue; + } + + ret.addAll(f.getRanks().getAll().stream().map(r -> name + "-" + r.getName()).collect(Collectors.toList())); + } + } + + // Also add the cases for when type is specified + if (arg.length() >= 2) { + String compArg = arg.toLowerCase(); + if (compArg.startsWith("rank-") || "rank-".startsWith(compArg)) { + ret.addAll(faction.getRanks().getAll().stream() + .map(Rank::getName) + .map(n -> "rank-" + n) + .collect(Collectors.toList())); + } + if (compArg.startsWith("relation-") || "relation-".startsWith(compArg)) { + ret.addAll(TypeRelation.get().getTabList(sender, arg).stream() + .map(s -> "relation-" + s) + .collect(Collectors.toList())); + } + if (compArg.startsWith("faction-") || "faction-".startsWith(compArg)) { + ret.addAll(TypeFaction.get().getTabList(sender, arg).stream() + .map(s -> "faction-" + s) + .collect(Collectors.toList())); + } + if (compArg.startsWith("player-") || "player-".startsWith(compArg)) { + ret.addAll(TypeMPlayer.get().getTabList(sender, arg).stream() + .map(s -> "player-" + s) + .collect(Collectors.toList())); + } + } else { + // Or at least add the beginning + ret.addAll(MUtil.list("rank-", "relation-", "faction-", "player-")); + } + + return ret; + } + + + @Override + public boolean isValid(String arg, CommandSender sender) { + // In the generic case accept all + if (this.getFaction() == null) { + return true; + } else { + return super.isValid(arg, sender); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/type/TypeMPlayer.java b/src/main/java/com/massivecraft/factions/cmd/type/TypeMPlayer.java new file mode 100644 index 00000000..7e4d648a --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/type/TypeMPlayer.java @@ -0,0 +1,16 @@ +package com.massivecraft.factions.cmd.type; + +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.entity.MPlayerColl; +import com.massivecraft.massivecore.command.type.Type; + +public class TypeMPlayer { + // -------------------------------------------- // + // INSTANCE + // -------------------------------------------- // + + public static Type get() { + return MPlayerColl.get().getTypeEntity(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/type/TypeRank.java b/src/main/java/com/massivecraft/factions/cmd/type/TypeRank.java new file mode 100644 index 00000000..2cb01c7e --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/type/TypeRank.java @@ -0,0 +1,128 @@ +package com.massivecraft.factions.cmd.type; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.Rank; +import com.massivecraft.massivecore.collections.MassiveList; +import com.massivecraft.massivecore.collections.MassiveSet; +import org.bukkit.command.CommandSender; + +import java.util.Collection; +import java.util.List; +import java.util.Set; + +public class TypeRank extends TypeEntityInternalFaction { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static TypeRank i = new TypeRank(); + + public static TypeRank get() { + return i; + } + + private TypeRank() { + super(Rank.class); + this.currentRank = null; + } + + @Deprecated + public static TypeRank get(Faction faction) { + return new TypeRank(faction, null); + } + + @Deprecated + public TypeRank(Faction faction) { + this(faction, null); + } + + public static TypeRank get(Faction faction, Rank rank) { + return new TypeRank(faction, rank); + } + + public TypeRank(Faction faction, Rank rank) { + super(Rank.class, faction); + this.currentRank = rank; + + // When setAll is done in the super constructor some optimisations are done + // which don't take the promote/demote thing into account. + this.setAll(this.getAll(faction)); + } + + private final Rank currentRank; + + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Collection getAll(Faction faction) { + return faction.getRanks().getAll(); + } + + @Override + public Collection getTabList(CommandSender sender, String arg) { + List ret = new MassiveList<>(super.getTabList(sender, arg)); + ret.add("promote"); + ret.add("demote"); + return ret; + } + + @Override + public Set getNamesInner(Rank value) { + Set names = new MassiveSet<>(); + names.add(value.getName()); + + if (this.currentRank != null) { + // You can't use "promote" to make someone leader. + Rank promote = getPromote(currentRank); + if (value == promote && !promote.isLeader()) { + names.add("promote"); + } + + if (value == getDemote(currentRank)) { + names.add("demote"); + } + } + + return names; + } + + private static Rank getPromote(Rank rank) { + Rank ret = null; + for (Rank r : rank.getFaction().getRanks().getAll()) { + if (rank == r) { + continue; + } + if (rank.isMoreThan(r)) { + continue; + } + if (ret != null && ret.isLessThan(r)) { + continue; + } + + ret = r; + } + return ret; + } + + private static Rank getDemote(Rank rank) { + Rank ret = null; + for (Rank r : rank.getFaction().getRanks().getAll()) { + if (rank == r) { + continue; + } + if (rank.isLessThan(r)) { + continue; + } + if (ret != null && ret.isMoreThan(r)) { + continue; + } + + ret = r; + } + return ret; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/type/TypeRel.java b/src/main/java/com/massivecraft/factions/cmd/type/TypeRel.java new file mode 100644 index 00000000..0db61a3a --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/type/TypeRel.java @@ -0,0 +1,42 @@ +package com.massivecraft.factions.cmd.type; + +import com.massivecraft.factions.Rel; +import com.massivecraft.massivecore.command.type.enumeration.TypeEnum; + +import java.util.Set; + +public class TypeRel extends TypeEnum { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static TypeRel i = new TypeRel(); + + public static TypeRel get() { + return i; + } + + public TypeRel() { + super(Rel.class); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getName() { + return "relation"; + } + + @Override + public String getNameInner(Rel value) { + return value.getName(); + } + + @Override + public Set getNamesInner(Rel value) { + return value.getNames(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/type/TypeRelation.java b/src/main/java/com/massivecraft/factions/cmd/type/TypeRelation.java new file mode 100644 index 00000000..2694a7b4 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/type/TypeRelation.java @@ -0,0 +1,29 @@ +package com.massivecraft.factions.cmd.type; + +import com.massivecraft.factions.Rel; + +public class TypeRelation extends TypeRel { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static TypeRelation i = new TypeRelation(); + + public static TypeRelation get() { + return i; + } + + public TypeRelation() { + this.setAll(Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.ENEMY); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getName() { + return "relation"; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/type/TypeSortMPlayer.java b/src/main/java/com/massivecraft/factions/cmd/type/TypeSortMPlayer.java new file mode 100644 index 00000000..b1cf74fa --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/type/TypeSortMPlayer.java @@ -0,0 +1,40 @@ +package com.massivecraft.factions.cmd.type; + +import com.massivecraft.factions.comparator.ComparatorMPlayerInactivity; +import com.massivecraft.factions.comparator.ComparatorMPlayerPower; +import com.massivecraft.factions.comparator.ComparatorMPlayerRole; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.command.type.TypeAbstractChoice; + +import java.util.Comparator; + +public class TypeSortMPlayer extends TypeAbstractChoice> { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static TypeSortMPlayer i = new TypeSortMPlayer(); + + public static TypeSortMPlayer get() { + return i; + } + + public TypeSortMPlayer() { + super(Comparator.class); + this.setAll( + ComparatorMPlayerRole.get(), + ComparatorMPlayerPower.get(), + ComparatorMPlayerInactivity.get() + ); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getName() { + return "player sorter"; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/type/TypeTaxable.java b/src/main/java/com/massivecraft/factions/cmd/type/TypeTaxable.java new file mode 100644 index 00000000..a7810190 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/type/TypeTaxable.java @@ -0,0 +1,134 @@ +package com.massivecraft.factions.cmd.type; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.entity.Rank; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.collections.MassiveList; +import com.massivecraft.massivecore.command.type.TypeAbstract; +import com.massivecraft.massivecore.util.MUtil; +import org.bukkit.command.CommandSender; + +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + +// TODO: This whole thing is a copy/paste of TypeMPermable. Duplicate code. +public class TypeTaxable extends TypeAbstract { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static TypeTaxable i = new TypeTaxable(); + + public static TypeTaxable get() { + return i; + } + + private TypeTaxable() { + super(String.class); + + this.faction = null; + } + + public static TypeTaxable get(Faction faction) { + return new TypeTaxable(faction); + } + + public TypeTaxable(Faction faction) { + super(String.class); + if (faction == null) { + throw new NullPointerException("faction"); + } + + this.faction = faction; + } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final Faction faction; + + public Faction getFaction() { + return this.faction; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String read(String arg, CommandSender sender) throws MassiveException { + if (arg.toLowerCase().startsWith("rank-")) { + String subArg = arg.substring("rank-".length()); + return new TypeRank(this.getFaction()).read(subArg, sender).getId(); + } + + if (arg.toLowerCase().startsWith("player-")) { + String subArg = arg.substring("player-".length()); + return TypeMPlayer.get().read(subArg, sender).getId(); + } + + + TypeRank typeRank = new TypeRank(this.getFaction()); + try { + return typeRank.read(arg, sender).getId(); + } catch (MassiveException ex) { + // Do nothing + } + + try { + return TypeMPlayer.get().read(arg, sender).getId(); + } catch (MassiveException ex) { + // Do nothing + } + + throw new MassiveException().addMsg("No rank or player matches: %s.", arg); + } + + public Collection getTabList(CommandSender sender, String arg) { + List ret = new MassiveList<>(); + Faction faction = this.getFaction(); + if (faction == null) { + faction = MPlayer.get(sender).getFaction(); + } + + // Always add ranks, relations, other factions and other players + ret.addAll(faction.getRanks().getAll().stream().map(Rank::getName).collect(Collectors.toList())); + ret.addAll(TypeMPlayer.get().getTabList(sender, arg)); + + // Also add the cases for when type is specified + if (arg.length() >= 2) { + String compArg = arg.toLowerCase(); + if (compArg.startsWith("rank-") || "rank-".startsWith(compArg)) { + ret.addAll(faction.getRanks().getAll().stream() + .map(Rank::getName) + .map(n -> "rank-" + n) + .collect(Collectors.toList())); + } + if (compArg.startsWith("player-") || "player-".startsWith(compArg)) { + ret.addAll(TypeMPlayer.get().getTabList(sender, arg).stream() + .map(s -> "player-" + s) + .collect(Collectors.toList())); + } + } else { + // Or at least add the beginning + ret.addAll(MUtil.list("rank-", "player-")); + } + + return ret; + } + + + @Override + public boolean isValid(String arg, CommandSender sender) { + // In the generic case accept all + if (this.getFaction() == null) { + return true; + } else { + return super.isValid(arg, sender); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/type/TypeVote.java b/src/main/java/com/massivecraft/factions/cmd/type/TypeVote.java new file mode 100644 index 00000000..6b9b9076 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/type/TypeVote.java @@ -0,0 +1,40 @@ +package com.massivecraft.factions.cmd.type; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.Vote; + +import java.util.Collection; + +public class TypeVote extends TypeEntityInternalFaction { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static TypeVote i = new TypeVote(); + + public static TypeVote get() { + return i; + } + + private TypeVote() { + super(Vote.class); + } + + public static TypeVote get(Faction faction) { + return new TypeVote(faction); + } + + public TypeVote(Faction faction) { + super(Vote.class, faction); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Collection getAll(Faction faction) { + return faction.getVotes().getAll(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/type/TypeWarp.java b/src/main/java/com/massivecraft/factions/cmd/type/TypeWarp.java new file mode 100644 index 00000000..f6246d6b --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/type/TypeWarp.java @@ -0,0 +1,40 @@ +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/main/java/com/massivecraft/factions/comparator/ComparatorFactionList.java b/src/main/java/com/massivecraft/factions/comparator/ComparatorFactionList.java new file mode 100644 index 00000000..fc812853 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/comparator/ComparatorFactionList.java @@ -0,0 +1,67 @@ +package com.massivecraft.factions.comparator; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.massivecore.comparator.ComparatorAbstract; +import com.massivecraft.massivecore.comparator.ComparatorComparable; +import com.massivecraft.massivecore.util.IdUtil; +import org.bukkit.command.CommandSender; + +import java.lang.ref.WeakReference; + +public class ComparatorFactionList extends ComparatorAbstract { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final WeakReference watcher; + + public CommandSender getWatcher() { + return this.watcher.get(); + } + + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + public static ComparatorFactionList get(Object watcherObject) { + return new ComparatorFactionList(watcherObject); + } + + public ComparatorFactionList(Object watcherObject) { + this.watcher = new WeakReference<>(IdUtil.getSender(watcherObject)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public int compareInner(Faction f1, Faction f2) { + // None a.k.a. Wilderness + if (f1.isNone() && f2.isNone()) { + return 0; + } + if (f1.isNone()) { + return -1; + } + if (f2.isNone()) { + return 1; + } + + // Players Online + int ret = f2.getMPlayersWhereOnlineTo(this.getWatcher()).size() - f1.getMPlayersWhereOnlineTo(this.getWatcher()).size(); + if (ret != 0) { + return ret; + } + + // Players Total + ret = f2.getMPlayers().size() - f1.getMPlayers().size(); + if (ret != 0) { + return ret; + } + + // Tie by Id + return ComparatorComparable.get().compare(f1.getId(), f2.getId()); + } + +} diff --git a/src/main/java/com/massivecraft/factions/comparator/ComparatorMPlayerInactivity.java b/src/main/java/com/massivecraft/factions/comparator/ComparatorMPlayerInactivity.java new file mode 100644 index 00000000..6612e06d --- /dev/null +++ b/src/main/java/com/massivecraft/factions/comparator/ComparatorMPlayerInactivity.java @@ -0,0 +1,48 @@ +package com.massivecraft.factions.comparator; + +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.Named; +import com.massivecraft.massivecore.comparator.ComparatorAbstract; + +public class ComparatorMPlayerInactivity extends ComparatorAbstract implements Named { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ComparatorMPlayerInactivity i = new ComparatorMPlayerInactivity(); + + public static ComparatorMPlayerInactivity get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getName() { + return "Time"; + } + + @Override + public int compareInner(MPlayer m1, MPlayer m2) { + // Online + boolean o1 = m1.isOnline(); + boolean o2 = m2.isOnline(); + + if (o1 && o2) { + return 0; + } else if (o1) { + return -1; + } else if (o2) { + return +1; + } + + // Inactivity Time + long r1 = m1.getLastActivityMillis(); + long r2 = m2.getLastActivityMillis(); + + return (int) (r1 - r2); + } + +} diff --git a/src/main/java/com/massivecraft/factions/comparator/ComparatorMPlayerPower.java b/src/main/java/com/massivecraft/factions/comparator/ComparatorMPlayerPower.java new file mode 100644 index 00000000..2ddc6805 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/comparator/ComparatorMPlayerPower.java @@ -0,0 +1,39 @@ +package com.massivecraft.factions.comparator; + +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.Named; +import com.massivecraft.massivecore.comparator.ComparatorAbstract; + +public class ComparatorMPlayerPower extends ComparatorAbstract implements Named { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ComparatorMPlayerPower i = new ComparatorMPlayerPower(); + + public static ComparatorMPlayerPower get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getName() { + return "Power"; + } + + @Override + public int compareInner(MPlayer m1, MPlayer m2) { + // Power + int ret = m1.getPowerRounded() - m2.getPowerRounded(); + if (ret != 0) { + return ret; + } + + // MaxPower + return m1.getPowerMaxRounded() - m2.getPowerMaxRounded(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/comparator/ComparatorMPlayerRole.java b/src/main/java/com/massivecraft/factions/comparator/ComparatorMPlayerRole.java new file mode 100644 index 00000000..71199bc1 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/comparator/ComparatorMPlayerRole.java @@ -0,0 +1,39 @@ +package com.massivecraft.factions.comparator; + +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.entity.Rank; +import com.massivecraft.massivecore.Named; +import com.massivecraft.massivecore.comparator.ComparatorAbstract; + +public class ComparatorMPlayerRole extends ComparatorAbstract implements Named { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ComparatorMPlayerRole i = new ComparatorMPlayerRole(); + + public static ComparatorMPlayerRole get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getName() { + return "Rank"; + } + + @Override + public int compareInner(MPlayer m1, MPlayer m2) { + // Rank + if (m1.getFaction() != m2.getFaction()) { + throw new IllegalArgumentException("Noncomparable players"); + } + Rank r1 = m1.getRank(); + Rank r2 = m2.getRank(); + return r2.getPriority() - r1.getPriority(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/engine/DisallowCause.java b/src/main/java/com/massivecraft/factions/engine/DisallowCause.java new file mode 100644 index 00000000..033e7154 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/DisallowCause.java @@ -0,0 +1,15 @@ +package com.massivecraft.factions.engine; + +public enum DisallowCause { + // -------------------------------------------- // + // ENUM + // -------------------------------------------- // + + PEACEFUL_LAND, + FACTIONLESS, + FRIENDLYFIRE, + OWN_TERRITORY + + // END OF LIST + +} diff --git a/src/main/java/com/massivecraft/factions/engine/EngineCanCombatHappen.java b/src/main/java/com/massivecraft/factions/engine/EngineCanCombatHappen.java new file mode 100644 index 00000000..e6a654dc --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/EngineCanCombatHappen.java @@ -0,0 +1,269 @@ +package com.massivecraft.factions.engine; + +import com.massivecraft.factions.Rel; +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.MPlayer; +import com.massivecraft.factions.event.EventFactionsPvpDisallowed; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.MUtil; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Trident; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.AreaEffectCloudApplyEvent; +import org.bukkit.event.entity.EntityCombustByEntityEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.PotionSplashEvent; +import org.bukkit.projectiles.ProjectileSource; + +import java.util.ArrayList; +import java.util.List; + +public class EngineCanCombatHappen extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineCanCombatHappen i = new EngineCanCombatHappen(); + + public static EngineCanCombatHappen get() { + return i; + } + + // -------------------------------------------- // + // CAN COMBAT DAMAGE HAPPEN + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void canCombatDamageHappen(EntityDamageByEntityEvent event) { + if (this.canCombatDamageHappen(event, true)) { + return; + } + event.setCancelled(true); + + Entity damager = event.getDamager(); + if (damager instanceof Arrow && !(damager instanceof Trident)) { + damager.remove(); + } + + + } + + // mainly for flaming arrows; don't want allies or people in safe zones to be ignited even after damage event is cancelled + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void canCombatDamageHappen(EntityCombustByEntityEvent event) { + EntityDamageByEntityEvent sub = new EntityDamageByEntityEvent(event.getCombuster(), event.getEntity(), EntityDamageEvent.DamageCause.FIRE, 0D); + if (this.canCombatDamageHappen(sub, false)) { + return; + } + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void canCombatDamageHappen(PotionSplashEvent event) { + // If a harmful potion is splashing ... + if (!MUtil.isHarmfulPotion(event.getPotion())) { + return; + } + + ProjectileSource projectileSource = event.getPotion().getShooter(); + if (!(projectileSource instanceof Entity)) { + return; + } + + Entity thrower = (Entity) projectileSource; + + // ... scan through affected entities to make sure they're all valid targets. + for (LivingEntity affectedEntity : event.getAffectedEntities()) { + EntityDamageByEntityEvent sub = new EntityDamageByEntityEvent(thrower, affectedEntity, EntityDamageEvent.DamageCause.CUSTOM, 0D); + if (this.canCombatDamageHappen(sub, true)) { + continue; + } + + // affected entity list doesn't accept modification (iter.remove() is a no-go), but this works + event.setIntensity(affectedEntity, 0.0); + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void canCombatDamageHappen(AreaEffectCloudApplyEvent event) { + // If a harmful potion effect cloud is present ... + if (!MUtil.isHarmfulPotion(event.getEntity().getBasePotionData().getType().getEffectType())) { + return; + } + + ProjectileSource projectileSource = event.getEntity().getSource(); + if (!(projectileSource instanceof Entity)) { + return; + } + + Entity thrower = (Entity) projectileSource; + + // ... create a dummy list to avoid ConcurrentModificationException ... + List affectedList = new ArrayList<>(); + + // ... then scan through affected entities to make sure they're all valid targets ... + for (LivingEntity affectedEntity : event.getAffectedEntities()) { + EntityDamageByEntityEvent sub = new EntityDamageByEntityEvent(thrower, affectedEntity, EntityDamageEvent.DamageCause.CUSTOM, 0D); + // Notification disabled due to the iterating nature of effect clouds. + if (EngineCanCombatHappen.get().canCombatDamageHappen(sub, false)) { + continue; + } + + affectedList.add(affectedEntity); + } + + // finally, remove valid targets from the affected list. (Unlike splash potions, area effect cloud's affected entities list is mutable.) + event.getAffectedEntities().removeAll(affectedList); + } + + // Utility method used in "canCombatDamageHappen" below. + public static boolean falseUnlessDisallowedPvpEventCancelled(Player attacker, Player defender, DisallowCause reason, EntityDamageByEntityEvent event) { + EventFactionsPvpDisallowed dpe = new EventFactionsPvpDisallowed(attacker, defender, reason, event); + dpe.run(); + return dpe.isCancelled(); + } + + public boolean canCombatDamageHappen(EntityDamageByEntityEvent event, boolean notify) { + boolean ret = true; + + // If the defender is a player ... + Entity edefender = event.getEntity(); + if (MUtil.isntPlayer(edefender)) { + return true; + } + Player defender = (Player) edefender; + MPlayer mdefender = MPlayer.get(edefender); + + // ... and the attacker is someone else ... + Entity eattacker = MUtil.getLiableDamager(event); + + // (we check null here since there may not be an attacker) + // (lack of attacker situations can be caused by other bukkit plugins) + if (eattacker != null && eattacker.equals(edefender)) { + return true; + } + + // ... gather defender PS and faction information ... + PS defenderPs = PS.valueOf(defender.getLocation()); + Faction defenderPsFaction = BoardColl.get().getFactionAt(defenderPs); + + // ... fast evaluate if the attacker is overriding ... + if (MUtil.isPlayer(eattacker)) { + + MPlayer mplayer = MPlayer.get(eattacker); + if (mplayer != null && mplayer.isOverriding()) { + return true; + } + } + + // ... PVP flag may cause a damage block ... + if (defenderPsFaction.getFlag(MFlag.getFlagPvp()) == false) { + if (eattacker == null) { + // No attacker? + // Let's behave as if it were a player + return falseUnlessDisallowedPvpEventCancelled(null, defender, DisallowCause.PEACEFUL_LAND, event); + } + if (MUtil.isPlayer(eattacker)) { + ret = falseUnlessDisallowedPvpEventCancelled((Player) eattacker, defender, DisallowCause.PEACEFUL_LAND, event); + if (!ret && notify) { + MPlayer attacker = MPlayer.get(eattacker); + attacker.msg("PVP is disabled in %s.", defenderPsFaction.describeTo(attacker)); + } + return ret; + } + return defenderPsFaction.getFlag(MFlag.getFlagMonsters()); + } + + // ... and if the attacker is a player ... + if (MUtil.isntPlayer(eattacker)) { + return true; + } + Player attacker = (Player) eattacker; + MPlayer uattacker = MPlayer.get(attacker); + + // ... does this player bypass all protection? ... + if (MConf.get().playersWhoBypassAllProtection.contains(attacker.getName())) { + return true; + } + + // ... gather attacker PS and faction information ... + PS attackerPs = PS.valueOf(attacker.getLocation()); + Faction attackerPsFaction = BoardColl.get().getFactionAt(attackerPs); + + // ... PVP flag may cause a damage block ... + // (just checking the defender as above isn't enough. What about the attacker? It could be in a no-pvp area) + // NOTE: This check is probably not that important but we could keep it anyways. + if (attackerPsFaction.getFlag(MFlag.getFlagPvp()) == false) { + ret = falseUnlessDisallowedPvpEventCancelled(attacker, defender, DisallowCause.PEACEFUL_LAND, event); + if (!ret && notify) { + uattacker.msg("PVP is disabled in %s.", attackerPsFaction.describeTo(uattacker)); + } + return ret; + } + + // ... are PVP rules completely ignored in this world? ... + if (!MConf.get().worldsPvpRulesEnabled.contains(defenderPs.getWorld())) { + return true; + } + + Faction defendFaction = mdefender.getFaction(); + Faction attackFaction = uattacker.getFaction(); + + if (attackFaction.isNone() && MConf.get().disablePVPForFactionlessPlayers) { + ret = falseUnlessDisallowedPvpEventCancelled(attacker, defender, DisallowCause.FACTIONLESS, event); + if (!ret && notify) { + uattacker.msg("You can't hurt other players until you join a faction."); + } + return ret; + } else if (defendFaction.isNone()) { + if (defenderPsFaction == attackFaction && MConf.get().enablePVPAgainstFactionlessInAttackersLand) { + // Allow PVP vs. Factionless in attacker's faction territory + return true; + } else if (MConf.get().disablePVPForFactionlessPlayers) { + ret = falseUnlessDisallowedPvpEventCancelled(attacker, defender, DisallowCause.FACTIONLESS, event); + if (!ret && notify) { + uattacker.msg("You can't hurt players who are not currently in a faction."); + } + return ret; + } else if (attackFaction.isNone() && MConf.get().enablePVPBetweenFactionlessPlayers) { + // Allow factionless vs factionless + return true; + } + } + + Rel relation = defendFaction.getRelationTo(attackFaction); + + // Check the relation + if (relation.isFriend() && defenderPsFaction.getFlag(MFlag.getFlagFriendlyire()) == false) { + ret = falseUnlessDisallowedPvpEventCancelled(attacker, defender, DisallowCause.FRIENDLYFIRE, event); + if (!ret && notify) { + uattacker.msg("You can't hurt %s.", relation.getDescPlayerMany()); + } + return ret; + } + + // You can not hurt neutrals in their own territory. + boolean ownTerritory = mdefender.isInOwnTerritory(); + + if (mdefender.hasFaction() && ownTerritory && relation == Rel.NEUTRAL) { + ret = falseUnlessDisallowedPvpEventCancelled(attacker, defender, DisallowCause.OWN_TERRITORY, event); + if (!ret && notify) { + uattacker.msg("You can't hurt %s in their own territory unless you declare them as an enemy.", mdefender.describeTo(uattacker)); + mdefender.msg("%s tried to hurt you.", uattacker.describeTo(mdefender, true)); + } + return ret; + } + + return true; + } + +} diff --git a/src/main/java/com/massivecraft/factions/engine/EngineChat.java b/src/main/java/com/massivecraft/factions/engine/EngineChat.java new file mode 100644 index 00000000..0b2dfff9 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/EngineChat.java @@ -0,0 +1,166 @@ +package com.massivecraft.factions.engine; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.Rel; +import com.massivecraft.factions.RelationParticipator; +import com.massivecraft.factions.chat.ChatFormatter; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.event.EventMassiveCorePlayerToRecipientChat; +import com.massivecraft.massivecore.util.MUtil; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.EventException; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.plugin.EventExecutor; + +import java.util.Iterator; +import java.util.function.Predicate; + +public class EngineChat extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineChat i = new EngineChat(); + + public static EngineChat get() { + return i; + } + + public EngineChat() { + this.setPlugin(Factions.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void setActiveInner(boolean active) { + if (!active) { + return; + } + + if (MConf.get().chatSetFormat) { + Bukkit.getPluginManager().registerEvent(AsyncPlayerChatEvent.class, this, MConf.get().chatSetFormatAt, new SetFormatEventExecutor(), Factions.get(), true); + } + + if (MConf.get().chatParseTags) { + Bukkit.getPluginManager().registerEvent(AsyncPlayerChatEvent.class, this, MConf.get().chatParseTagsAt, new ParseTagsEventExecutor(), Factions.get(), true); + } + + if (MConf.get().chatParseTags) { + Bukkit.getPluginManager().registerEvent(EventMassiveCorePlayerToRecipientChat.class, this, EventPriority.NORMAL, new ParseRelcolorEventExecutor(), Factions.get(), true); + } + } + + // -------------------------------------------- // + // SET FORMAT + // -------------------------------------------- // + + private class SetFormatEventExecutor implements EventExecutor { + @Override + public void execute(Listener listener, Event event) throws EventException { + try { + if (!(event instanceof AsyncPlayerChatEvent)) { + return; + } + setFormat((AsyncPlayerChatEvent) event); + } catch (Throwable t) { + throw new EventException(t); + } + } + } + + public static void setFormat(AsyncPlayerChatEvent event) { + event.setFormat(MConf.get().chatSetFormatTo); + } + + // -------------------------------------------- // + // PARSE TAGS + // -------------------------------------------- // + + private class ParseTagsEventExecutor implements EventExecutor { + @Override + public void execute(Listener listener, Event event) throws EventException { + try { + if (!(event instanceof AsyncPlayerChatEvent)) { + return; + } + parseTags((AsyncPlayerChatEvent) event); + } catch (Throwable t) { + throw new EventException(t); + } + } + } + + public static void parseTags(AsyncPlayerChatEvent event) { + Player player = event.getPlayer(); + if (MUtil.isntPlayer(player)) { + return; + } + + String format = event.getFormat(); + format = ChatFormatter.format(format, player, null); + event.setFormat(format); + } + + // -------------------------------------------- // + // PARSE RELCOLOR + // -------------------------------------------- // + + private class ParseRelcolorEventExecutor implements EventExecutor { + @Override + public void execute(Listener listener, Event event) throws EventException { + try { + if (!(event instanceof EventMassiveCorePlayerToRecipientChat)) { + return; + } + parseRelcolor((EventMassiveCorePlayerToRecipientChat) event); + } catch (Throwable t) { + throw new EventException(t); + } + } + } + + public static void parseRelcolor(EventMassiveCorePlayerToRecipientChat event) { + String format = event.getFormat(); + format = ChatFormatter.format(format, event.getSender(), event.getRecipient()); + event.setFormat(format); + } + + // -------------------------------------------- // + // FILTER CHAT CHANNEL + // -------------------------------------------- // + + public static Predicate getPredicateIsInFaction(RelationParticipator participator) { + return player -> MPlayer.get(player).getRelationTo(participator).isAtLeast(Rel.FACTION); + } + + public static Predicate getPredicateIsAlly(RelationParticipator participator) { + return player -> MPlayer.get(player).getFaction().getRelationTo(participator).isAtLeast(Rel.ALLY); + } + + public static void filterToPredicate(AsyncPlayerChatEvent event, Predicate predicate) { + Player player = event.getPlayer(); + MPlayer mplayer = MPlayer.get(player); + Faction faction = mplayer.getFaction(); + + // Get and filter recipients + for (Iterator it = event.getRecipients().iterator(); it.hasNext(); ) { + Player recipient = it.next(); + if (predicate.test(recipient)) { + continue; + } + + it.remove(); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/engine/EngineChunkChange.java b/src/main/java/com/massivecraft/factions/engine/EngineChunkChange.java new file mode 100644 index 00000000..0e36976e --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/EngineChunkChange.java @@ -0,0 +1,270 @@ +package com.massivecraft.factions.engine; + +import com.massivecraft.factions.Rel; +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.FactionColl; +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.EventFactionsChunksChange; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.collections.MassiveList; +import com.massivecraft.massivecore.collections.MassiveSet; +import com.massivecraft.massivecore.mixin.MixinWorld; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.ChatColor; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; + +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +public class EngineChunkChange extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineChunkChange i = new EngineChunkChange(); + + public static EngineChunkChange get() { + return i; + } + + // -------------------------------------------- // + // CHUNK CHANGE: ALLOWED + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) + public void onChunksChange(EventFactionsChunksChange event) { + // For security reasons we block the chunk change on any error since an error might block security checks from happening. + try { + onChunksChangeInner(event); + } catch (Throwable throwable) { + event.setCancelled(true); + throwable.printStackTrace(); + } + } + + public void onChunksChangeInner(EventFactionsChunksChange event) { + // Args + final MPlayer mplayer = event.getMPlayer(); + final Faction newFaction = event.getNewFaction(); + final Map> currentFactionChunks = event.getOldFactionChunks(); + final Set currentFactions = currentFactionChunks.keySet(); + final Set chunks = event.getChunks(); + + // Override Mode? Sure! + if (mplayer.isOverriding()) { + return; + } + + // CALC: Is there at least one normal faction among the current ones? + boolean currentFactionsContainsAtLeastOneNormal = false; + for (Faction currentFaction : currentFactions) { + if (currentFaction.isNormal()) { + currentFactionsContainsAtLeastOneNormal = true; + break; + } + } + + // If the new faction is normal (not wilderness/none), meaning if we are claiming for a faction ... + if (newFaction.isNormal()) { + // ... ensure claiming is enabled for the worlds of all chunks ... + for (PS chunk : chunks) { + String worldId = chunk.getWorld(); + if (!MConf.get().worldsClaimingEnabled.contains(worldId)) { + String worldName = MixinWorld.get().getWorldDisplayName(worldId); + mplayer.msg("Land claiming is disabled in %s.", worldName); + event.setCancelled(true); + return; + } + } + + // ... ensure we have permission to alter the territory of the new faction ... + if (!MPerm.getPermTerritory().has(mplayer, newFaction, true)) { + // NOTE: No need to send a message. We send message from the permission check itself. + event.setCancelled(true); + return; + } + + // ... ensure the new faction has enough players to claim ... + if (newFaction.getMPlayers().size() < MConf.get().claimsRequireMinFactionMembers) { + mplayer.msg("Factions must have at least %s members to claim land.", MConf.get().claimsRequireMinFactionMembers); + event.setCancelled(true); + return; + } + + int claimedLandCount = newFaction.getLandCount(); + if (!newFaction.getFlag(MFlag.getFlagInfpower())) { + // ... ensure the claim would not bypass the global max limit ... + if (MConf.get().claimedLandsMax != 0 && claimedLandCount + chunks.size() > MConf.get().claimedLandsMax) { + mplayer.msg("Limit reached. You can't claim more land."); + event.setCancelled(true); + return; + } + + // ... ensure the claim would not bypass the global world limit ... + if (MConf.get().claimedWorldsMax >= 0) { + Set oldWorlds = newFaction.getClaimedWorlds(); + Set newWorlds = PS.getDistinctWorlds(chunks); + + Set worlds = new MassiveSet<>(); + worlds.addAll(oldWorlds); + worlds.addAll(newWorlds); + + if (!oldWorlds.containsAll(newWorlds) && worlds.size() > MConf.get().claimedWorldsMax) { + List 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("A faction may only be present on %d different %s.", MConf.get().claimedWorldsMax, worldsMax); + mplayer.msg("%s is already present on %d %s:", newFaction.describeTo(mplayer), oldWorlds.size(), worldsAlready); + mplayer.message(Txt.implodeCommaAndDot(worldNames, ChatColor.YELLOW.toString())); + mplayer.msg("Please unclaim bases on other worlds to claim here."); + + event.setCancelled(true); + return; + } + } + + } + + // ... ensure the claim would not bypass the faction power ... + if (claimedLandCount + chunks.size() > newFaction.getPowerRounded()) { + mplayer.msg("You don't have enough power to claim that land."); + event.setCancelled(true); + return; + } + + // ... ensure the claim would not violate distance to neighbors ... + // HOW: Calculate the factions nearby, excluding the chunks themselves, the faction itself and the wilderness faction. + // HOW: The chunks themselves will be handled in the "if (oldFaction.isNormal())" section below. + Set nearbyChunks = BoardColl.getNearbyChunks(chunks, MConf.get().claimMinimumChunksDistanceToOthers); + nearbyChunks.removeAll(chunks); + Set nearbyFactions = BoardColl.getDistinctFactions(nearbyChunks); + nearbyFactions.remove(FactionColl.get().getNone()); + nearbyFactions.remove(newFaction); + // HOW: Next we check if the new faction has permission to claim nearby the nearby factions. + MPerm claimnear = MPerm.getPermClaimnear(); + for (Faction nearbyFaction : nearbyFactions) { + if (claimnear.has(mplayer, nearbyFaction, true)) { + continue; + } + event.setCancelled(true); + return; + } + + // ... ensure claims are properly connected ... + if + ( + // If claims must be connected ... + MConf.get().claimsMustBeConnected + // ... and this faction already has claimed something on this map (meaning it's not their first claim) ... + && + newFaction.getLandCountInWorld(chunks.iterator().next().getWorld()) > 0 + // ... and none of the chunks are connected to an already claimed chunk for the faction ... + && + !BoardColl.get().isAnyConnectedPs(chunks, newFaction) + // ... and either claims must always be connected or there is at least one normal faction among the old factions ... + && + (!MConf.get().claimsCanBeUnconnectedIfOwnedByOtherFaction || currentFactionsContainsAtLeastOneNormal) + ) { + if (MConf.get().claimsCanBeUnconnectedIfOwnedByOtherFaction) { + mplayer.msg("You can only claim additional land which is connected to your first claim or controlled by another faction!"); + } else { + mplayer.msg("You can only claim additional land which is connected to your first claim!"); + } + event.setCancelled(true); + return; + } + } + + // Ensure claims are properly connected when unclaiming + if (newFaction.isNone() && MConf.get().claimsMustBeConnected && MConf.get().claimsMustBeConnectedStrict) { + for (Entry> entry : currentFactionChunks.entrySet()) { + Faction faction = entry.getKey(); + Set factionRemovedChunks = entry.getValue(); + + Set pssBefore = BoardColl.get().getChunks(faction); + + // Get how many "forests" of claims there are right now + List> forestsBefore = BoardColl.getForests(pssBefore); + + Set pssAfter = new MassiveSet<>(pssBefore); + pssAfter.removeAll(factionRemovedChunks); + + List> forestsAfter = BoardColl.getForests(pssAfter); + if (forestsAfter.size() > forestsBefore.size()) { + mplayer.msg("Claims must be connected. You can't make them disconnected by unclaiming."); + event.setCancelled(true); + return; + } + } + } + + // For each of the old factions ... + for (Entry> entry : currentFactionChunks.entrySet()) { + Faction oldFaction = entry.getKey(); + Set oldChunks = entry.getValue(); + + // ... that is an actual faction ... + if (oldFaction.isNone()) { + continue; + } + + // ... for which the mplayer lacks permission ... + if (MPerm.getPermTerritory().has(mplayer, oldFaction, false)) { + continue; + } + + // ... consider all reasons to forbid "overclaiming/warclaiming" ... + + // ... claiming from others may be forbidden ... + if (!MConf.get().claimingFromOthersAllowed) { + mplayer.msg("You may not claim land from others."); + event.setCancelled(true); + return; + } + + // ... and they must actually be claiming ... + if (newFaction.isNone()) { + mplayer.msg("You can't unclaim land belonging to others."); + event.setCancelled(true); + return; + } + + // ... the relation may forbid ... + if (oldFaction.getRelationTo(newFaction).isAtLeast(Rel.TRUCE)) { + mplayer.msg("You can't claim this land due to your relation with the current owner."); + event.setCancelled(true); + return; + } + + // ... the old faction might not be inflated enough ... + if (oldFaction.getPowerRounded() > oldFaction.getLandCount() - oldChunks.size() && MConf.get().claimingFromOthersMustBeInflated) { + mplayer.msg("%s owns this land and is strong enough to keep it.", oldFaction.getName(mplayer)); + event.setCancelled(true); + return; + } + + // ... and you might be trying to claim without starting at the border ... + if (!BoardColl.get().isAnyBorderPs(chunks)) { + mplayer.msg("You must start claiming land at the border of the territory."); + event.setCancelled(true); + return; + } + + // ... otherwise you may claim from this old faction even though you lack explicit permission from them. + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/engine/EngineCleanInactivity.java b/src/main/java/com/massivecraft/factions/engine/EngineCleanInactivity.java new file mode 100644 index 00000000..cc275e0e --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/EngineCleanInactivity.java @@ -0,0 +1,103 @@ +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.MPlayerColl; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.event.EventMassiveCorePlayerCleanInactivityToleranceMillis; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; + +import java.util.Map; +import java.util.Map.Entry; + +public class EngineCleanInactivity extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineCleanInactivity i = new EngineCleanInactivity(); + + public static EngineCleanInactivity get() { + return i; + } + + // -------------------------------------------- // + // REMOVE PLAYER MILLIS + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void ageBonus(EventMassiveCorePlayerCleanInactivityToleranceMillis event) { + if (event.getColl() != MPlayerColl.get()) { + return; + } + + applyPlayerAgeBonus(event); + applyFactionAgeBonus(event); + } + + public void applyPlayerAgeBonus(EventMassiveCorePlayerCleanInactivityToleranceMillis event) { + // Calculate First Played + Long firstPlayed = event.getEntity().getFirstPlayed(); + Long age = 0L; + if (firstPlayed != null) { + age = System.currentTimeMillis() - firstPlayed; + } + + // Calculate the Bonus! + Long bonus = calculateBonus(age, MConf.get().cleanInactivityToleranceMillisPlayerAgeToBonus); + if (bonus == null) { + return; + } + + // Apply + event.getToleranceCauseMillis().put("Player Age Bonus", bonus); + } + + public void applyFactionAgeBonus(EventMassiveCorePlayerCleanInactivityToleranceMillis event) { + // Calculate Faction Age + Faction faction = ((MPlayer) event.getEntity()).getFaction(); + long age = 0L; + if (!faction.isNone()) { + age = faction.getAge(); + } + + // Calculate the Bonus! + Long bonus = calculateBonus(age, MConf.get().cleanInactivityToleranceMillisFactionAgeToBonus); + if (bonus == null) { + return; + } + + // Apply + event.getToleranceCauseMillis().put("Faction Age Bonus", bonus); + } + + private Long calculateBonus(long age, Map ageToBonus) { + if (ageToBonus.isEmpty()) { + return null; + } + + Long bonus = 0L; + for (Entry entry : ageToBonus.entrySet()) { + Long key = entry.getKey(); + if (key == null) { + continue; + } + + Long value = entry.getValue(); + if (value == null) { + continue; + } + + if (age >= key) { + bonus = value; + break; + } + } + + return bonus; + } + + +} diff --git a/src/main/java/com/massivecraft/factions/engine/EngineDenyCommands.java b/src/main/java/com/massivecraft/factions/engine/EngineDenyCommands.java new file mode 100644 index 00000000..8b362eb5 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/EngineDenyCommands.java @@ -0,0 +1,114 @@ +package com.massivecraft.factions.engine; + +import com.massivecraft.factions.Rel; +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.MPlayer; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.MUtil; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +import java.util.List; + +public class EngineDenyCommands extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineDenyCommands i = new EngineDenyCommands(); + + public static EngineDenyCommands get() { + return i; + } + + // -------------------------------------------- // + // DENY COMMANDS + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) + public void denyCommands(PlayerCommandPreprocessEvent event) { + // If a player is trying to run a command ... + Player player = event.getPlayer(); + if (MUtil.isntPlayer(player)) { + return; + } + MPlayer mplayer = MPlayer.get(player); + + // ... and the player is not overriding ... + if (mplayer.isOverriding()) { + return; + } + + // ... clean up the command ... + String command = event.getMessage(); + command = Txt.removeLeadingCommandDust(command); + command = command.toLowerCase(); + command = command.trim(); + + // ... the command may be denied for members of permanent factions ... + if (mplayer.hasFaction() && mplayer.getFaction().getFlag(MFlag.getFlagPermanent()) && MUtil.containsCommand(command, MConf.get().denyCommandsPermanentFactionMember)) { + mplayer.msg("You can't use \"/%s\" as member of a permanent faction.", command); + event.setCancelled(true); + return; + } + + // ... if there is a faction at the players location we fetch the relation now ... + PS ps = PS.valueOf(player.getLocation()).getChunk(true); + Faction factionAtPs = BoardColl.get().getFactionAt(ps); + Rel factionAtRel = null; + + if (factionAtPs != null && !factionAtPs.isNone()) { + factionAtRel = factionAtPs.getRelationTo(mplayer); + } + + // ... there maybe be a player in the distance that denies the command ... + if (MConf.get().denyCommandsDistance > -1 && !MConf.get().denyCommandsDistanceBypassIn.contains(factionAtRel)) { + for (Player otherplayer : player.getWorld().getPlayers()) { + MPlayer othermplayer = MPlayer.get(otherplayer); + if (othermplayer == mplayer) { + continue; + } + + double distance = player.getLocation().distance(otherplayer.getLocation()); + if (MConf.get().denyCommandsDistance > distance) { + continue; + } + + Rel playerRel = mplayer.getRelationTo(othermplayer); + if (!MConf.get().denyCommandsDistanceRelation.containsKey(playerRel)) { + continue; + } + + String desc = playerRel.getDescPlayerOne(); + + mplayer.msg("You can't use \"/%s\" as there is %s nearby.", command, desc); + event.setCancelled(true); + return; + } + } + + // ... if there is no relation here then there are no further checks ... + if (factionAtRel == null) { + return; + } + + List deniedCommands = MConf.get().denyCommandsTerritoryRelation.get(factionAtRel); + if (deniedCommands == null) { + return; + } + if (!MUtil.containsCommand(command, deniedCommands)) { + return; + } + + mplayer.msg("You can't use \"/%s\" in %s territory.", command, Txt.getNicedEnum(factionAtRel)); + event.setCancelled(true); + } + +} diff --git a/src/main/java/com/massivecraft/factions/engine/EngineDenyTeleport.java b/src/main/java/com/massivecraft/factions/engine/EngineDenyTeleport.java new file mode 100644 index 00000000..b43cca1d --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/EngineDenyTeleport.java @@ -0,0 +1,149 @@ +package com.massivecraft.factions.engine; + +import com.massivecraft.factions.Rel; +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.Couple; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.mixin.MixinMessage; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.MUtil; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; + +import java.util.List; +import java.util.Map.Entry; + +public class EngineDenyTeleport extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineDenyTeleport i = new EngineDenyTeleport(); + + public static EngineDenyTeleport get() { + return i; + } + + // -------------------------------------------- // + // CAN COMBAT DAMAGE HAPPEN + // -------------------------------------------- // + + private enum TerritoryType { + ENEMY, + WILDERNESS, + OWN, + OTHER + } + + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) + public void canTeleportHappen(PlayerTeleportEvent event) { + Entry entry = shouldBeCancelled(event); + if (entry == null) { + return; + } + + event.setCancelled(true); + + TeleportCause cause = entry.getKey(); + TerritoryType deny = entry.getValue(); + + String teleportDesc = Txt.getNicedEnum(cause); + String denyDesc = ""; + if (deny == TerritoryType.ENEMY) { + denyDesc = "enemy"; + } + if (deny == TerritoryType.WILDERNESS) { + denyDesc = "wilderness"; + } + if (deny == TerritoryType.OWN) { + denyDesc = "your own"; + } + if (deny == TerritoryType.OTHER) { + denyDesc = "other faction's"; + } + + Player player = event.getPlayer(); + MixinMessage.get().msgOne(player, "Teleportation with %s is not allowed in %s territory.", teleportDesc, denyDesc); + } + + private Entry shouldBeCancelled(PlayerTeleportEvent event) { + Player player = event.getPlayer(); + if (MUtil.isntPlayer(player)) { + return null; + } + + MPlayer mplayer = MPlayer.get(player); + + PS from = PS.valueOf(event.getFrom()); + PS to = PS.valueOf(event.getTo()); + + TerritoryType typeFrom = getTerritoryType(mplayer, from); + TerritoryType typeTo = getTerritoryType(mplayer, to); + List types = MUtil.list(typeFrom, typeTo); + + TeleportCause cause = event.getCause(); + MConf mconf = MConf.get(); + + if (cause == TeleportCause.CHORUS_FRUIT) { + if (!mconf.allowChorusFruitInEnemyTerritory && types.contains(TerritoryType.ENEMY)) { + return Couple.valueOf(cause, TerritoryType.ENEMY); + } + + if (!mconf.allowChorusFruitInWildernessTerritory && types.contains(TerritoryType.WILDERNESS)) { + return Couple.valueOf(cause, TerritoryType.WILDERNESS); + } + + if (!mconf.allowChorusFruitInOwnTerritory && types.contains(TerritoryType.OWN)) { + return Couple.valueOf(cause, TerritoryType.OWN); + } + + if (!mconf.allowChorusFruitInOtherTerritory && types.contains(TerritoryType.OTHER)) { + return Couple.valueOf(cause, TerritoryType.OTHER); + } + } else if (cause == TeleportCause.ENDER_PEARL) { + if (!mconf.allowEnderPearlInEnemyTerritory && types.contains(TerritoryType.ENEMY)) { + return Couple.valueOf(cause, TerritoryType.ENEMY); + } + + if (!mconf.allowEnderPearlInWildernessTerritory && types.contains(TerritoryType.WILDERNESS)) { + return Couple.valueOf(cause, TerritoryType.WILDERNESS); + } + + if (!mconf.allowEnderPearlInOwnTerritory && types.contains(TerritoryType.OWN)) { + return Couple.valueOf(cause, TerritoryType.OWN); + } + + if (!mconf.allowEnderPearlInOtherTerritory && types.contains(TerritoryType.OTHER)) { + return Couple.valueOf(cause, TerritoryType.OTHER); + } + } else { + // Don't cancel other kinds of teleports + } + + return null; + } + + private TerritoryType getTerritoryType(MPlayer mplayer, PS territory) { + Faction territoryFaction = BoardColl.get().getFactionAt(territory); + Rel relation = territoryFaction.getRelationTo(mplayer); + + if (territoryFaction.isNone()) { + return TerritoryType.WILDERNESS; + } + if (relation == Rel.ENEMY) { + return TerritoryType.ENEMY; + } + if (relation == Rel.FACTION) { + return TerritoryType.OWN; + } + return TerritoryType.OTHER; + } + +} diff --git a/src/main/java/com/massivecraft/factions/engine/EngineEcon.java b/src/main/java/com/massivecraft/factions/engine/EngineEcon.java new file mode 100644 index 00000000..c1b8d490 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/EngineEcon.java @@ -0,0 +1,268 @@ +package com.massivecraft.factions.engine; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.cmd.CmdFactions; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.event.EventFactionsAbstractSender; +import com.massivecraft.factions.event.EventFactionsChunkChangeType; +import com.massivecraft.factions.event.EventFactionsChunksChange; +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.EventFactionsInvitedChange; +import com.massivecraft.factions.event.EventFactionsMembershipChange; +import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; +import com.massivecraft.factions.event.EventFactionsNameChange; +import com.massivecraft.factions.event.EventFactionsRelationChange; +import com.massivecraft.factions.event.EventFactionsTitleChange; +import com.massivecraft.factions.event.EventFactionsWarpAdd; +import com.massivecraft.factions.event.EventFactionsWarpRemove; +import com.massivecraft.factions.event.EventFactionsWarpTeleport; +import com.massivecraft.factions.integration.Econ; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.money.Money; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map.Entry; +import java.util.Set; + +public class EngineEcon extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineEcon i = new EngineEcon(); + + public static EngineEcon get() { + return i; + } + + // -------------------------------------------- // + // TAKE ON LEAVE + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void takeOnLeave(EventFactionsMembershipChange event) { + if (!Econ.isEnabled()) { + return; + } + + // If a player is leaving the faction ... + if (event.getReason() != MembershipChangeReason.LEAVE) { + return; + } + + // ... and that player was the last one in the faction ... + MPlayer mplayer = event.getMPlayer(); + Faction oldFaction = mplayer.getFaction(); + if (oldFaction.getMPlayers().size() > 1) { + return; + } + + // ... then transfer all money to the player. + double money = Econ.getMoney(oldFaction); + if (money == 0) { + return; + } + Econ.transferMoney(mplayer, oldFaction, mplayer, money); + } + + // -------------------------------------------- // + // TAKE ON DISBAND + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void takeOnDisband(EventFactionsDisband event) { + // If there is a mplayer ... + MPlayer mplayer = event.getMPlayer(); + if (mplayer == null) { + return; + } + + // ... and economy is enabled ... + if (!Econ.isEnabled()) { + return; + } + + // ... then transfer all the faction money to the sender. + Faction faction = event.getFaction(); + + double amount = Econ.getMoney(faction); + + // Check that there is an amount + if (amount == 0) { + return; + } + + String amountString = Money.format(amount); + + Econ.transferMoney(faction, mplayer, mplayer, amount, true); + + mplayer.msg("You have been given the disbanded faction's bank, totaling %s.", amountString); + Factions.get().log(mplayer.getName() + " has been given bank holdings of " + amountString + " from disbanding " + faction.getName() + "."); + } + + // -------------------------------------------- // + // PAY FOR ACTION + // -------------------------------------------- // + + public static void payForAction(EventFactionsAbstractSender event, Double cost, String desc) { + // If there is an mplayer ... + MPlayer mplayer = event.getMPlayer(); + if (mplayer == null) { + return; + } + + // ... and there is a cost ... + if (cost == null) { + return; + } + if (cost == 0) { + return; + } + + // ... that the sender can't afford ... + if (Econ.payForAction(cost, mplayer, desc)) { + return; + } + + // ... then cancel. + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForAction(EventFactionsChunksChange event) { + double cost = 0; + List typeNames = new ArrayList<>(); + + for (Entry> typeChunks : event.getTypeChunks().entrySet()) { + final EventFactionsChunkChangeType type = typeChunks.getKey(); + final Set chunks = typeChunks.getValue(); + + Double typeCost = MConf.get().econChunkCost.get(type); + if (typeCost == null) { + continue; + } + if (typeCost == 0) { + continue; + } + + typeCost *= chunks.size(); + cost += typeCost; + + typeNames.add(type.now); + } + + String desc = Txt.implodeCommaAnd(typeNames) + " this land"; + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForAction(EventFactionsMembershipChange event) { + Double cost = null; + String desc = null; + + if (event.getReason() == MembershipChangeReason.JOIN) { + cost = MConf.get().econCostJoin; + desc = "join a faction"; + } else if (event.getReason() == MembershipChangeReason.LEAVE) { + cost = MConf.get().econCostLeave; + desc = "leave a faction"; + } else if (event.getReason() == MembershipChangeReason.KICK) { + cost = MConf.get().econCostKick; + desc = "kick someone from a faction"; + } else { + return; + } + + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(EventFactionsRelationChange event) { + Double cost = MConf.get().econRelCost.get(event.getNewRelation()); + String desc = CmdFactions.get().cmdFactionsRelation.cmdFactionsRelationSet.getDesc(); + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(EventFactionsWarpAdd event) { + 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) { + Double cost = MConf.get().econCostCreate; + String desc = CmdFactions.get().cmdFactionsCreate.getDesc(); + + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(EventFactionsDescriptionChange event) { + Double cost = MConf.get().econCostDescription; + String desc = CmdFactions.get().cmdFactionsDescription.getDesc(); + + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(EventFactionsNameChange event) { + Double cost = MConf.get().econCostName; + String desc = CmdFactions.get().cmdFactionsName.getDesc(); + + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(EventFactionsTitleChange event) { + Double cost = MConf.get().econCostTitle; + String desc = CmdFactions.get().cmdFactionsTitle.getDesc(); + + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(EventFactionsFlagChange event) { + Double cost = MConf.get().econCostFlag; + String desc = CmdFactions.get().cmdFactionsFlag.getDesc(); + + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(EventFactionsInvitedChange event) { + Double cost = event.isNewInvited() ? MConf.get().econCostInvite : MConf.get().econCostDeinvite; + String desc = CmdFactions.get().cmdFactionsInvite.getDesc(); + + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(EventFactionsWarpTeleport event) { + Double cost = MConf.get().econCostWarpGo; + String desc = CmdFactions.get().cmdFactionsWarp.cmdFactionsWarpGo.getDesc(); + + payForAction(event, cost, desc); + } + +} diff --git a/src/main/java/com/massivecraft/factions/engine/EngineExploit.java b/src/main/java/com/massivecraft/factions/engine/EngineExploit.java new file mode 100644 index 00000000..bc2ea5d0 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/EngineExploit.java @@ -0,0 +1,226 @@ +package com.massivecraft.factions.engine; + +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.collections.MassiveList; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.MUtil; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockFromToEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; + +import java.util.HashMap; +import java.util.List; +import java.util.UUID; + +public class EngineExploit extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineExploit i = new EngineExploit(); + + public static EngineExploit get() { + return i; + } + + // -------------------------------------------- // + // OBSIDIAN GENERATORS + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void obsidianGenerators(BlockFromToEvent event) { + if (!MConf.get().handleExploitObsidianGenerators) { + return; + } + + // thanks to ObGenBlocker and WorldGuard for this method + Block block = event.getToBlock(); + Material source = event.getBlock().getType(); + Material target = block.getType(); + if ((target == Material.REDSTONE_WIRE || target == Material.TRIPWIRE) && (source == Material.AIR || source == Material.LAVA)) { + block.setType(Material.AIR); + } + } + + // -------------------------------------------- // + // ENDER PEARL CLIPPING + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void enderPearlClipping(PlayerTeleportEvent event) { + if (!MConf.get().handleExploitEnderPearlClipping) { + return; + } + if (event.getCause() != PlayerTeleportEvent.TeleportCause.ENDER_PEARL) { + return; + } + + // this exploit works when the target location is within 0.31 blocks or so of a door or glass block or similar... + Location target = event.getTo(); + Location from = event.getFrom(); + + // blocks who occupy less than 1 block width or length wise need to be handled differently + Material mat = event.getTo().getBlock().getType(); + if ( + ((mat == Material.GLASS_PANE || mat == Material.IRON_BARS) && clippingThrough(target, from, 0.65)) + || ((MUtil.list(Material.ACACIA_FENCE, Material.BIRCH_FENCE, Material.DARK_OAK_FENCE, Material.JUNGLE_FENCE, Material.NETHER_BRICK_FENCE, Material.OAK_FENCE, Material.SPRUCE_FENCE).contains(mat)) && clippingThrough(target, from, 0.45)) + ) { + event.setTo(from); + return; + } + + // simple fix otherwise: ender pearl target locations are standardized to be in the center (X/Z) of the target block, not at the edges + target.setX(target.getBlockX() + 0.5); + target.setZ(target.getBlockZ() + 0.5); + event.setTo(target); + + } + + public static boolean clippingThrough(Location target, Location from, double thickness) { + return + ( + (from.getX() > target.getX() && (from.getX() - target.getX() < thickness)) + || (target.getX() > from.getX() && (target.getX() - from.getX() < thickness)) + || (from.getZ() > target.getZ() && (from.getZ() - target.getZ() < thickness)) + || (target.getZ() > from.getZ() && (target.getZ() - from.getZ() < thickness)) + ); + } + + // -------------------------------------------- // + // NETHER PORTAL TRAP + // -------------------------------------------- // + // A nether portal trap can be created by the destination portal being enclosed (trapped) - resulting in the player not being able to run commands. + // This fix removes the portal blocks (client side) from the destination until they are away from the portal. + + private static final int NETHER_TRAP_RADIUS_CHECK = 5; + private static final int NETHER_TRAP_RESET_RADIUS_SQUARED = 9; + + private HashMap> portalTraps = new HashMap<>(); + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void portalTrapRemoveAnimation(PlayerTeleportEvent event) { + // If there is a teleport caused by a nether portal ... + if (!MConf.get().handleNetherPortalTrap || event.getCause() != TeleportCause.NETHER_PORTAL) { + return; + } + + Player player = event.getPlayer(); + Block from = event.getTo().getBlock(); + + // ... and the player can't build at the destination ... + if (EnginePermBuild.canPlayerBuildAt(player, PS.valueOf(from), false)) { + return; + } + + // ... reset the old portal blocks stored ... + this.portalReset(player); + + // ... get all the portal blocks belonging to the new portal at the destination ... + List portalTrap = getPortal(from); + if (portalTrap.isEmpty()) { + return; + } + + // ... and then store those blocks and send an update as if they were air. + this.portalTraps.put(player.getUniqueId(), portalTrap); + portalUpdateAir(player, portalTrap); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void portalUpdate(PlayerMoveEvent event) { + // If a player moves ... + if (!MConf.get().handleNetherPortalTrap || MUtil.isSameBlock(event)) { + return; + } + + Player player = event.getPlayer(); + UUID uuid = player.getUniqueId(); + + // ... and he recently used a portal ... + List portalTrap = this.portalTraps.get(uuid); + if (portalTrap == null) { + return; + } + + Location locationTo = event.getTo(); + Location locationFrom = portalTrap.get(0).getLocation(); + + World worldTo = locationTo.getWorld(); + World worldFrom = locationFrom.getWorld(); + + // ... update reset the portal near them, if they have moved away too far ... + if (!worldTo.equals(worldFrom) || locationTo.distanceSquared(locationFrom) > NETHER_TRAP_RESET_RADIUS_SQUARED) { + portalUpdateReset(player, portalTrap); + return; + } + + // ... or send an update as if the portal blocks were air. + portalUpdateAir(player, portalTrap); + } + + public void portalReset(Player player) { + UUID uuid = player.getUniqueId(); + + // If a player has already a portal registered to him ... + List portalTrap = this.portalTraps.get(uuid); + if (portalTrap == null) { + return; + } + + // ... remove them from the registry ... + this.portalTraps.remove(uuid); + + // ... and send updates if the player and portal are in the same world. + if (!player.getWorld().equals(portalTrap.get(0).getWorld())) { + return; + } + portalUpdateReset(player, portalTrap); + } + + public static void portalUpdateReset(Player player, List portal) { + portalUpdate(player, portal, null, null); + } + + public static void portalUpdateAir(Player player, List portal) { + portalUpdate(player, portal, Material.AIR, (byte) 0); + } + + @SuppressWarnings("deprecation") + private static void portalUpdate(Player player, List portal, Material material, Byte data) { + boolean usingDefault = material == null && data == null; + for (Block block : portal) { + Material updateMaterial = usingDefault ? block.getType() : material; + byte updateData = usingDefault ? block.getData() : data; + player.sendBlockChange(block.getLocation(), updateMaterial, updateData); + } + } + + public static List getPortal(Block from) { + // Create + List ret = new MassiveList<>(); + + // Fill - Check in a radius of the block to find the portal blocks + for (int x = -(NETHER_TRAP_RADIUS_CHECK); x <= NETHER_TRAP_RADIUS_CHECK; x++) { + for (int y = -(NETHER_TRAP_RADIUS_CHECK); y <= NETHER_TRAP_RADIUS_CHECK; y++) { + for (int z = -(NETHER_TRAP_RADIUS_CHECK); z <= NETHER_TRAP_RADIUS_CHECK; z++) { + if (from.getRelative(x, y, z).getType() == Material.NETHER_PORTAL) { + ret.add(from.getRelative(x, y, z)); + } + } + } + } + + // Return + return ret; + } + +} diff --git a/src/main/java/com/massivecraft/factions/engine/EngineFlagEndergrief.java b/src/main/java/com/massivecraft/factions/engine/EngineFlagEndergrief.java new file mode 100644 index 00000000..023acb44 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/EngineFlagEndergrief.java @@ -0,0 +1,48 @@ +package com.massivecraft.factions.engine; + +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.ps.PS; +import org.bukkit.entity.Enderman; +import org.bukkit.entity.Entity; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityChangeBlockEvent; + +public class EngineFlagEndergrief extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineFlagEndergrief i = new EngineFlagEndergrief(); + + public static EngineFlagEndergrief get() { + return i; + } + + // -------------------------------------------- // + // FLAG: ENDERGRIEF + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void blockEndergrief(EntityChangeBlockEvent event) { + // If an enderman is changing a block ... + Entity entity = event.getEntity(); + if (!(entity instanceof Enderman)) { + return; + } + + // ... and the faction there has endergrief disabled ... + PS ps = PS.valueOf(event.getBlock()); + Faction faction = BoardColl.get().getFactionAt(ps); + if (faction.getFlag(MFlag.getFlagEndergrief())) { + return; + } + + // ... stop the block alteration. + event.setCancelled(true); + } + +} diff --git a/src/main/java/com/massivecraft/factions/engine/EngineFlagExplosion.java b/src/main/java/com/massivecraft/factions/engine/EngineFlagExplosion.java new file mode 100644 index 00000000..d9f1ec81 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/EngineFlagExplosion.java @@ -0,0 +1,155 @@ +package com.massivecraft.factions.engine; + +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.util.EnumerationUtil; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.ps.PS; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Wither; +import org.bukkit.event.Cancellable; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockExplodeEvent; +import org.bukkit.event.entity.EntityChangeBlockEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.hanging.HangingBreakEvent; +import org.bukkit.event.hanging.HangingBreakEvent.RemoveCause; + +import java.util.Collection; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +public class EngineFlagExplosion extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineFlagExplosion i = new EngineFlagExplosion(); + + public static EngineFlagExplosion get() { + return i; + } + + // -------------------------------------------- // + // FLAG: EXPLOSIONS + // -------------------------------------------- // + + protected Set DAMAGE_CAUSE_EXPLOSIONS = EnumSet.of(DamageCause.BLOCK_EXPLOSION, DamageCause.ENTITY_EXPLOSION); + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void blockExplosion(HangingBreakEvent event) { + // If a hanging entity was broken by an explosion ... + if (event.getCause() != RemoveCause.EXPLOSION) { + return; + } + Entity entity = event.getEntity(); + + // ... and the faction there has explosions disabled ... + Faction faction = BoardColl.get().getFactionAt(PS.valueOf(entity.getLocation())); + if (faction.isExplosionsAllowed()) { + return; + } + + // ... then cancel. + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void blockExplosion(EntityDamageEvent event) { + // If an explosion damages ... + if (!DAMAGE_CAUSE_EXPLOSIONS.contains(event.getCause())) { + return; + } + + // ... an entity that is modified on damage ... + if (!EnumerationUtil.isEntityTypeEditOnDamage(event.getEntityType())) { + return; + } + + // ... and the faction has explosions disabled ... + if (BoardColl.get().getFactionAt(PS.valueOf(event.getEntity())).isExplosionsAllowed()) { + return; + } + + // ... then cancel! + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void blockExplosion(EntityExplodeEvent event) { + Location location = event.getLocation(); + Cancellable cancellable = event; + Collection blocks = event.blockList(); + + blockExplosion(location, cancellable, blocks); + } + + // Note that this method is used by EngineV18 for the BlockExplodeEvent + public void blockExplosion(Location location, Cancellable cancellable, Collection blocks) { + // Caching to speed things up. + Map faction2allowed = new HashMap<>(); + + // Check the entity. Are explosions disabled there? + Faction faction = BoardColl.get().getFactionAt(PS.valueOf(location)); + Boolean allowed = faction.isExplosionsAllowed(); + if (!allowed) { + cancellable.setCancelled(true); + return; + } + faction2allowed.put(faction, allowed); + + // Individually check the flag state for each block + Iterator iterator = blocks.iterator(); + while (iterator.hasNext()) { + Block block = iterator.next(); + faction = BoardColl.get().getFactionAt(PS.valueOf(block)); + allowed = faction2allowed.get(faction); + if (allowed == null) { + allowed = faction.isExplosionsAllowed(); + faction2allowed.put(faction, allowed); + } + + if (!allowed) { + iterator.remove(); + } + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void blockExplosion(EntityChangeBlockEvent event) { + // If a wither is changing a block ... + Entity entity = event.getEntity(); + if (!(entity instanceof Wither)) { + return; + } + + // ... and the faction there has explosions disabled ... + PS ps = PS.valueOf(event.getBlock()); + Faction faction = BoardColl.get().getFactionAt(ps); + + if (faction.isExplosionsAllowed()) { + return; + } + + // ... stop the block alteration. + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void blockExplosion(BlockExplodeEvent event) { + Location location = event.getBlock().getLocation(); + Cancellable cancellable = event; + Collection blocks = event.blockList(); + + EngineFlagExplosion.get().blockExplosion(location, cancellable, blocks); + } + +} diff --git a/src/main/java/com/massivecraft/factions/engine/EngineFlagFireSpread.java b/src/main/java/com/massivecraft/factions/engine/EngineFlagFireSpread.java new file mode 100644 index 00000000..f075d238 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/EngineFlagFireSpread.java @@ -0,0 +1,77 @@ +package com.massivecraft.factions.engine; + +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.ps.PS; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.event.Cancellable; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockBurnEvent; +import org.bukkit.event.block.BlockIgniteEvent; +import org.bukkit.event.block.BlockIgniteEvent.IgniteCause; +import org.bukkit.event.block.BlockSpreadEvent; + +public class EngineFlagFireSpread extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineFlagFireSpread i = new EngineFlagFireSpread(); + + public static EngineFlagFireSpread get() { + return i; + } + + // -------------------------------------------- // + // FLAG: FIRE SPREAD + // -------------------------------------------- // + + public void blockFireSpread(Block block, Cancellable cancellable) { + // If the faction at the block has firespread disabled ... + PS ps = PS.valueOf(block); + Faction faction = BoardColl.get().getFactionAt(ps); + + if (faction.getFlag(MFlag.getFlagFirespread())) { + return; + } + + // then cancel the event. + cancellable.setCancelled(true); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void blockFireSpread(BlockIgniteEvent event) { + // If fire is spreading ... + if (event.getCause() != IgniteCause.SPREAD && event.getCause() != IgniteCause.LAVA) { + return; + } + + // ... consider blocking it. + blockFireSpread(event.getBlock(), event); + } + + // TODO: Is use of this event deprecated? + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void blockFireSpread(BlockSpreadEvent event) { + // If fire is spreading ... + if (event.getNewState().getType() != Material.FIRE) { + return; + } + + // ... consider blocking it. + blockFireSpread(event.getBlock(), event); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void blockFireSpread(BlockBurnEvent event) { + // If a block is burning ... + + // ... consider blocking it. + blockFireSpread(event.getBlock(), event); + } + +} diff --git a/src/main/java/com/massivecraft/factions/engine/EngineFlagSpawn.java b/src/main/java/com/massivecraft/factions/engine/EngineFlagSpawn.java new file mode 100644 index 00000000..15dc09f4 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/EngineFlagSpawn.java @@ -0,0 +1,94 @@ +package com.massivecraft.factions.engine; + +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.factions.util.EnumerationUtil; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.collections.BackstringSet; +import com.massivecraft.massivecore.ps.PS; +import org.bukkit.Location; +import org.bukkit.entity.EntityType; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; + +import java.util.Set; + +public class EngineFlagSpawn extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineFlagSpawn i = new EngineFlagSpawn(); + + public static EngineFlagSpawn get() { + return i; + } + + // -------------------------------------------- // + // CONSTANTS + // -------------------------------------------- // + + public static final Set NATURAL_SPAWN_REASONS = new BackstringSet<>(SpawnReason.class, + "NATURAL", + "JOCKEY", + "CHUNK_GEN", + "OCELOT_BABY", + "NETHER_PORTAL", + "MOUNT", + "REINFORCEMENTS", + "VILLAGE_DEFENSE", + "VILLAGE_INVASION", + "RAID", + "PATROL" + ); + + // -------------------------------------------- // + // FLAG: MONSTERS & ANIMALS + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void blockMonstersAndAnimals(CreatureSpawnEvent event) { + // If this is a natural spawn .. + if (!NATURAL_SPAWN_REASONS.contains(event.getSpawnReason())) { + return; + } + + // ... get the spawn location ... + Location location = event.getLocation(); + PS ps = PS.valueOf(location); + + // ... get the faction there ... + Faction faction = BoardColl.get().getFactionAt(ps); + if (faction == null) { + return; + } + + // ... get the entity type ... + EntityType type = event.getEntityType(); + + // ... and if this type can't spawn in the faction ... + if (canSpawn(faction, type)) { + return; + } + + // ... then cancel. + event.setCancelled(true); + } + + public static boolean canSpawn(Faction faction, EntityType type) { + if (EnumerationUtil.isEntityTypeMonster(type)) { + // Monster + return faction.getFlag(MFlag.getFlagMonsters()); + } else if (EnumerationUtil.isEntityTypeAnimal(type)) { + // Animal + return faction.getFlag(MFlag.getFlagAnimals()); + } else { + // Other + return true; + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/engine/EngineFlagZombiegrief.java b/src/main/java/com/massivecraft/factions/engine/EngineFlagZombiegrief.java new file mode 100644 index 00000000..1834028c --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/EngineFlagZombiegrief.java @@ -0,0 +1,48 @@ +package com.massivecraft.factions.engine; + +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.ps.PS; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Zombie; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityBreakDoorEvent; + +public class EngineFlagZombiegrief extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineFlagZombiegrief i = new EngineFlagZombiegrief(); + + public static EngineFlagZombiegrief get() { + return i; + } + + // -------------------------------------------- // + // FLAG: ZOMBIEGRIEF + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void denyZombieGrief(EntityBreakDoorEvent event) { + // If a zombie is breaking a door ... + Entity entity = event.getEntity(); + if (!(entity instanceof Zombie)) { + return; + } + + // ... and the faction there has zombiegrief disabled ... + PS ps = PS.valueOf(event.getBlock()); + Faction faction = BoardColl.get().getFactionAt(ps); + if (faction.getFlag(MFlag.getFlagZombiegrief())) { + return; + } + + // ... stop the door breakage. + event.setCancelled(true); + } + +} diff --git a/src/main/java/com/massivecraft/factions/engine/EngineFly.java b/src/main/java/com/massivecraft/factions/engine/EngineFly.java new file mode 100644 index 00000000..da6fcfac --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/EngineFly.java @@ -0,0 +1,239 @@ +package com.massivecraft.factions.engine; + +import com.massivecraft.factions.Perm; +import com.massivecraft.factions.cmd.CmdFactions; +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.MFlagColl; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.event.EventFactionsFlagChange; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.event.EventMassiveCorePlayerUpdate; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.store.DriverFlatfile; +import com.massivecraft.massivecore.util.MUtil; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.player.PlayerMoveEvent; + +import java.io.File; + +public class EngineFly extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineFly i = new EngineFly(); + + public static EngineFly get() { + return i; + } + + // -------------------------------------------- // + // LISTENER + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void onMassiveCorePlayerUpdate(EventMassiveCorePlayerUpdate event) { + // If we are updating a player ... + Player player = event.getPlayer(); + if (MUtil.isntPlayer(player)) { + return; + } + + // ... and that player isn't in creative or spectator mode ... + if (EventMassiveCorePlayerUpdate.isFlyAllowed(player, false)) { + return; + } + + // ... and the player is alive ... + if (player.isDead()) { + return; + } + + MPlayer mplayer = MPlayer.get(player); + + // ... and the player enables flying ... + if (!mplayer.isFlying()) { + return; + } + + // ... and the player can fly here... + if (!canFlyInTerritory(mplayer, PS.valueOf(player))) { + return; + } + + // ... set allowed ... + event.setAllowed(true); + + // ... set speed ... + event.setFlySpeed(MConf.get().flySpeed); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void moveChunkDetect(PlayerMoveEvent event) { + // If the player is moving from one chunk to another ... + if (MUtil.isSameChunk(event)) { + return; + } + Player player = event.getPlayer(); + if (MUtil.isntPlayer(player)) { + return; + } + + // ... gather info on the player and the move ... + MPlayer mplayer = MPlayer.get(player); + PS chunkTo = PS.valueOf(event.getTo()).getChunk(true); + + // ... and they are currently flying ... + if (!mplayer.isFlying()) { + return; + } + + // ... but can't fly at the new place ... + if (canFlyInTerritory(mplayer, chunkTo)) { + return; + } + + // ... then perhaps they should not be + mplayer.setFlying(false); + deactivateForPlayer(player); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void flagUpdate(EventFactionsFlagChange event) { + if (event.getFlag() != MFlag.getFlagFly()) { + return; + } + if (event.isNewValue() == true) { + return; + } + + // Disable for all players when disabled + event.getFaction().getOnlinePlayers().forEach(EngineFly::deactivateForPlayer); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void territoryShield(EntityDamageByEntityEvent event) { + // If flying is diabled on PVP ... + if (!MConf.get().flyDisableOnPvp) { + return; + } + + // ... and the defender is a player ... + Entity entity = event.getEntity(); + if (MUtil.isntPlayer(entity)) { + return; + } + Player defender = (Player) entity; + MPlayer mdefender = MPlayer.get(defender); + + // ... and the attacker is a player ... + Entity eattacker = MUtil.getLiableDamager(event); + if (!(eattacker instanceof Player)) { + return; + } + Player attacker = (Player) eattacker; + MPlayer mattacker = MPlayer.get(attacker); + + // ... disable flying for both + if (mdefender.isFlying()) { + mdefender.setFlying(false); + deactivateForPlayer(defender); + mdefender.msg("Flying is disabled in combat."); + } + + if (mattacker.isFlying()) { + mattacker.setFlying(false); + deactivateForPlayer(attacker); + mattacker.msg("Flying is disabled in combat."); + } + } + + public static boolean canFlyInTerritory(MPlayer mplayer, PS ps) { + try { + canFlyInTerritoryOrThrow(mplayer, ps); + return true; + } catch (MassiveException ex) { + return false; + } + } + + public static void canFlyInTerritoryOrThrow(MPlayer mplayer, PS ps) throws MassiveException { + if (!mplayer.isPlayer()) { + throw new MassiveException().addMsg("Only players can fly."); + } + + Faction faction = mplayer.getFaction(); + Faction locationFaction = BoardColl.get().getFactionAt(ps.getChunk(true)); + + if (faction != locationFaction) { + throw new MassiveException().addMsg("You can only fly within your own faction."); + } + + // If the faction does not have the flag ... + if (!faction.getFlag(MFlag.getFlagFly())) { + MFlag flag = MFlag.getFlagFly(); + MassiveException ex = new MassiveException() + .addMsg("Flying requires that the %s flag is enabled for your faction.", flag.getName()); + + // ... but they can change ... + if (flag.isEditable()) { + boolean canEdit = MPerm.getPermFlags().has(mplayer, faction, false); + // ... and the player can edit it themselves ... + if (canEdit) { + // ... tell them to edit. + ex.addMsg("You can edit the flag with: "); + ex.addMessage(CmdFactions.get().cmdFactionsFlag.cmdFactionsFlagSet.getTemplate(false, true, mplayer.getSender())); + } + // ... otherwise ... + else { + // .. tell them to have someone else edit it ... + ex.addMsg("You can ask a faction admin to change the flag."); + } + } + // ... or only server admins can change it ... + else { + boolean isAdmin = Perm.OVERRIDE.has(mplayer.getSender()); + boolean isDefault = flag.isDefault(); + if (isAdmin) { + boolean overriding = mplayer.isOverriding(); + ex.addMsg("You can change the flag if you are overriding."); + if (overriding) { + ex.addMsg("You are already overriding."); + } else { + ex.addMsg("You can enable override with:"); + ex.addMessage(CmdFactions.get().cmdFactionsOverride.getTemplate(false, true, mplayer.getSender())); + } + + if (!isDefault) { + ex.addMsg("You can also ask someone with access to the configuration files to make flying enabled by default."); + if (MFlagColl.get().getDb().getDriver() instanceof DriverFlatfile) { + File file = DriverFlatfile.getDirectory(MFlagColl.get()); + ex.addMsg("Configuring the flags can be done by editing the files in %s.", file.getAbsoluteFile()); + } + } + } else { + ex.addMsg("Only server admins can change the flag. Per default flying is %s.", isDefault ? "enabled" : "disabled"); + } + } + throw ex; + } + } + + public static void deactivateForPlayer(Player player) { + EventMassiveCorePlayerUpdate.resetFlyAllowed(player); + EventMassiveCorePlayerUpdate.resetFlyActive(player); + EventMassiveCorePlayerUpdate.resetFlySpeed(player); + + EventMassiveCorePlayerUpdate.run(player); + } + +} diff --git a/src/main/java/com/massivecraft/factions/engine/EngineLastActivity.java b/src/main/java/com/massivecraft/factions/engine/EngineLastActivity.java new file mode 100644 index 00000000..ead82ec2 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/EngineLastActivity.java @@ -0,0 +1,65 @@ +package com.massivecraft.factions.engine; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.event.EventMassiveCorePlayerLeave; +import com.massivecraft.massivecore.util.MUtil; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerJoinEvent; + +public class EngineLastActivity extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineLastActivity i = new EngineLastActivity(); + + public static EngineLastActivity get() { + return i; + } + + // -------------------------------------------- // + // UPDATE LAST ACTIVITY + // -------------------------------------------- // + + public static void updateLastActivity(CommandSender sender) { + if (sender == null) { + throw new RuntimeException("sender"); + } + if (MUtil.isntSender(sender)) { + return; + } + + MPlayer mplayer = MPlayer.get(sender); + mplayer.setLastActivityMillis(); + } + + public static void updateLastActivitySoon(final CommandSender sender) { + if (sender == null) { + throw new RuntimeException("sender"); + } + Bukkit.getScheduler().scheduleSyncDelayedTask(Factions.get(), () -> updateLastActivity(sender)); + } + + // Can't be cancelled + @EventHandler(priority = EventPriority.LOWEST) + public void updateLastActivity(PlayerJoinEvent event) { + // During the join event itself we want to be able to reach the old data. + // That is also the way the underlying fallback Mixin system does it and we do it that way for the sake of symmetry. + // For that reason we wait till the next tick with updating the value. + updateLastActivitySoon(event.getPlayer()); + } + + // Can't be cancelled + @EventHandler(priority = EventPriority.LOWEST) + public void updateLastActivity(EventMassiveCorePlayerLeave event) { + // Here we do however update immediately. + // The player data should be fully updated before leaving the server. + updateLastActivity(event.getPlayer()); + } + +} diff --git a/src/main/java/com/massivecraft/factions/engine/EngineMotd.java b/src/main/java/com/massivecraft/factions/engine/EngineMotd.java new file mode 100644 index 00000000..a5af3d92 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/EngineMotd.java @@ -0,0 +1,105 @@ +package com.massivecraft.factions.engine; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.mixin.MixinActual; +import com.massivecraft.massivecore.mixin.MixinMessage; +import com.massivecraft.massivecore.util.MUtil; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerJoinEvent; + +import java.util.List; + +public class EngineMotd extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineMotd i = new EngineMotd(); + + public static EngineMotd get() { + return i; + } + + // -------------------------------------------- // + // MOTD + // -------------------------------------------- // + + public static void motd(PlayerJoinEvent event, EventPriority currentPriority) { + // Gather info ... + final Player player = event.getPlayer(); + if (MUtil.isntPlayer(player)) { + return; + } + final MPlayer mplayer = MPlayer.get(player); + final Faction faction = mplayer.getFaction(); + + // ... if there is a motd ... + if (!faction.hasMotd()) { + return; + } + + // ... and this is the priority we are supposed to act on ... + if (currentPriority != MConf.get().motdPriority) { + return; + } + + // ... and this is an actual join ... + if (!MixinActual.get().isActualJoin(event)) { + return; + } + + // ... then prepare the messages ... + final List messages = faction.getMotdMessages(); + + // ... and send to the player. + if (MConf.get().motdDelayTicks < 0) { + MixinMessage.get().messageOne(player, messages); + } else { + Bukkit.getScheduler().scheduleSyncDelayedTask(Factions.get(), () -> MixinMessage.get().messageOne(player, messages), MConf.get().motdDelayTicks); + } + } + + // Can't be cancelled + @EventHandler(priority = EventPriority.LOWEST) + public void motdLowest(PlayerJoinEvent event) { + motd(event, EventPriority.LOWEST); + } + + // Can't be cancelled + @EventHandler(priority = EventPriority.LOW) + public void motdLow(PlayerJoinEvent event) { + motd(event, EventPriority.LOW); + } + + // Can't be cancelled + @EventHandler(priority = EventPriority.NORMAL) + public void motdNormal(PlayerJoinEvent event) { + motd(event, EventPriority.NORMAL); + } + + // Can't be cancelled + @EventHandler(priority = EventPriority.HIGH) + public void motdHigh(PlayerJoinEvent event) { + motd(event, EventPriority.HIGH); + } + + // Can't be cancelled + @EventHandler(priority = EventPriority.HIGHEST) + public void motdHighest(PlayerJoinEvent event) { + motd(event, EventPriority.HIGHEST); + } + + // Can't be cancelled + @EventHandler(priority = EventPriority.MONITOR) + public void motdMonitor(PlayerJoinEvent event) { + motd(event, EventPriority.MONITOR); + } + +} diff --git a/src/main/java/com/massivecraft/factions/engine/EngineMoveChunk.java b/src/main/java/com/massivecraft/factions/engine/EngineMoveChunk.java new file mode 100644 index 00000000..b7ca383a --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/EngineMoveChunk.java @@ -0,0 +1,149 @@ +package com.massivecraft.factions.engine; + +import com.massivecraft.factions.AccessStatus; +import com.massivecraft.factions.TerritoryAccess; +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.util.AsciiMap; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.mixin.MixinTitle; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.MUtil; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerMoveEvent; + +import java.util.Collections; + +public class EngineMoveChunk extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineMoveChunk i = new EngineMoveChunk(); + + public static EngineMoveChunk get() { + return i; + } + + // -------------------------------------------- // + // MOVE CHUNK: DETECT + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void moveChunkDetect(PlayerMoveEvent event) { + // If the player is moving from one chunk to another ... + if (MUtil.isSameChunk(event)) { + return; + } + Player player = event.getPlayer(); + if (MUtil.isntPlayer(player)) { + return; + } + + // ... gather info on the player and the move ... + MPlayer mplayer = MPlayer.get(player); + + PS psFrom = PS.valueOf(event.getFrom()); + PS psTo = PS.valueOf(event.getTo()); + + // ... send info onwards and try auto-claiming. + sendChunkInfo(mplayer, player, psFrom, psTo); + tryAutoClaim(mplayer, psTo); + } + + // -------------------------------------------- // + // MOVE CHUNK: SEND CHUNK INFO + // -------------------------------------------- // + + private static void sendChunkInfo(MPlayer mplayer, Player player, PS psFrom, PS psTo) { + sendAutoMapUpdate(mplayer, psTo); + sendFactionTerritoryInfo(mplayer, player, psFrom, psTo); + sendTerritoryAccessMessage(mplayer, psFrom, psTo); + } + + private static void sendAutoMapUpdate(MPlayer mplayer, PS ps) { + if (!mplayer.isMapAutoUpdating()) { + return; + } + AsciiMap map = new AsciiMap(mplayer, ps, false); + mplayer.message(map.render()); + } + + private static void sendFactionTerritoryInfo(MPlayer mplayer, Player player, PS psFrom, PS psTo) { + Faction factionFrom = BoardColl.get().getFactionAt(psFrom); + Faction factionTo = BoardColl.get().getFactionAt(psTo); + + if (factionFrom == factionTo) { + return; + } + + if (mplayer.isTerritoryInfoTitles()) { + String titleMain = parseTerritoryInfo(MConf.get().territoryInfoTitlesMain, mplayer, factionTo); + String titleSub = parseTerritoryInfo(MConf.get().territoryInfoTitlesSub, mplayer, factionTo); + int ticksIn = MConf.get().territoryInfoTitlesTicksIn; + int ticksStay = MConf.get().territoryInfoTitlesTicksStay; + int ticksOut = MConf.get().territoryInfoTitleTicksOut; + MixinTitle.get().sendTitleMessage(player, ticksIn, ticksStay, ticksOut, titleMain, titleSub); + } else { + String message = parseTerritoryInfo(MConf.get().territoryInfoChat, mplayer, factionTo); + player.sendMessage(message); + } + } + + private static String parseTerritoryInfo(String string, MPlayer mplayer, Faction faction) { + if (string == null) { + throw new NullPointerException("string"); + } + if (faction == null) { + throw new NullPointerException("faction"); + } + + string = Txt.parse(string); + string = string.replace("{name}", faction.getName()); + string = string.replace("{relcolor}", faction.getColorTo(mplayer).toString()); + string = string.replace("{desc}", faction.getDescriptionDesc()); + + return string; + } + + private static void sendTerritoryAccessMessage(MPlayer mplayer, PS psFrom, PS psTo) { + if (!MConf.get().territoryAccessShowMessage) { + return; + } + + // Get TerritoryAccess for from & to chunks + TerritoryAccess accessFrom = BoardColl.get().getTerritoryAccessAt(psFrom); + TerritoryAccess accessTo = BoardColl.get().getTerritoryAccessAt(psTo); + + // See if the status has changed + AccessStatus statusFrom = accessFrom.getTerritoryAccess(mplayer); + AccessStatus statusTo = accessTo.getTerritoryAccess(mplayer); + if (statusFrom == statusTo) { + return; + } + + // Inform + mplayer.message(statusTo.getStatusMessage()); + } + + // -------------------------------------------- // + // MOVE CHUNK: TRY AUTO CLAIM + // -------------------------------------------- // + + private static void tryAutoClaim(MPlayer mplayer, PS chunkTo) { + // If the player is auto claiming ... + Faction autoClaimFaction = mplayer.getAutoClaimFaction(); + if (autoClaimFaction == null) { + return; + } + + // ... try claim. + mplayer.tryClaim(autoClaimFaction, Collections.singletonList(chunkTo)); + } + +} diff --git a/src/main/java/com/massivecraft/factions/engine/EnginePermBuild.java b/src/main/java/com/massivecraft/factions/engine/EnginePermBuild.java new file mode 100644 index 00000000..e801a8ea --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/EnginePermBuild.java @@ -0,0 +1,506 @@ +package com.massivecraft.factions.engine; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.TerritoryAccess; +import com.massivecraft.factions.entity.Board; +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.util.EnumerationUtil; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.MUtil; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockFromToEvent; +import org.bukkit.event.block.BlockPistonExtendEvent; +import org.bukkit.event.block.BlockPistonRetractEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.block.SignChangeEvent; +import org.bukkit.event.entity.EntityChangeBlockEvent; +import org.bukkit.event.entity.EntityCombustByEntityEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.hanging.HangingBreakByEntityEvent; +import org.bukkit.event.hanging.HangingPlaceEvent; +import org.bukkit.event.player.PlayerBucketEmptyEvent; +import org.bukkit.event.player.PlayerBucketFillEvent; +import org.bukkit.event.player.PlayerInteractAtEntityEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.projectiles.ProjectileSource; + +import java.util.List; +import java.util.Map; + +public class EnginePermBuild extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EnginePermBuild i = new EnginePermBuild(); + + public static EnginePermBuild get() { + return i; + } + + // -------------------------------------------- // + // LOGIC > PROTECT + // -------------------------------------------- // + + public static Boolean isProtected(ProtectCase protectCase, boolean verboose, MPlayer mplayer, PS ps, Object object) { + if (mplayer == null) { + return null; + } + if (protectCase == null) { + return null; + } + String name = mplayer.getName(); + if (MConf.get().playersWhoBypassAllProtection.contains(name)) { + return false; + } + if (mplayer.isOverriding()) { + return false; + } + + MPerm perm = protectCase.getPerm(object); + if (perm == null) { + return null; + } + if (protectCase != ProtectCase.BUILD) { + return !perm.has(mplayer, ps, verboose); + } + + if (!perm.has(mplayer, ps, false) && MPerm.getPermPainbuild().has(mplayer, ps, false)) { + if (!verboose) { + return false; + } + + Faction hostFaction = BoardColl.get().getFactionAt(ps); + mplayer.msg("It is painful to build in the territory of %s.", hostFaction.describeTo(mplayer)); + Player player = mplayer.getPlayer(); + if (player != null) { + player.damage(MConf.get().actionDeniedPainAmount); + } + } + + return !perm.has(mplayer, ps, verboose); + } + + public static Boolean protect(ProtectCase protectCase, boolean verboose, Player player, PS ps, Object object, Cancellable cancellable) { + Boolean ret = isProtected(protectCase, verboose, MPlayer.get(player), ps, object); + if (Boolean.TRUE.equals(ret) && cancellable != null) { + cancellable.setCancelled(true); + } + + return ret; + } + + public static Boolean build(Entity entity, Block block, Event event) { + if (!(event instanceof Cancellable)) { + return true; + } + if (MUtil.isntPlayer(entity)) { + return false; + } + Player player = (Player) entity; + boolean verboose = !isFake(event); + return protect(ProtectCase.BUILD, verboose, player, PS.valueOf(block), block, (Cancellable) event); + } + + public static Boolean useItem(Player player, Block block, Material material, Cancellable cancellable) { + return protect(ProtectCase.USE_ITEM, true, player, PS.valueOf(block), material, cancellable); + } + + public static Boolean useEntity(Player player, Entity entity, boolean verboose, Cancellable cancellable) { + return protect(ProtectCase.USE_ENTITY, verboose, player, PS.valueOf(entity), entity, cancellable); + } + + public static Boolean useBlock(Player player, Block block, boolean verboose, Cancellable cancellable) { + return protect(ProtectCase.USE_BLOCK, verboose, player, PS.valueOf(block), block.getType(), cancellable); + } + + // -------------------------------------------- // + // LOGIC > PROTECT > BUILD + // -------------------------------------------- // + + public static boolean canPlayerBuildAt(Object senderObject, PS ps, boolean verboose) { + MPlayer mplayer = MPlayer.get(senderObject); + if (mplayer == null) { + return false; + } + + Boolean ret = isProtected(ProtectCase.BUILD, verboose, mplayer, ps, null); + return !Boolean.TRUE.equals(ret); + } + + // -------------------------------------------- // + // BUILD > BLOCK + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.NORMAL) + public void build(BlockPlaceEvent event) { + build(event.getPlayer(), event.getBlock(), event); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void build(BlockBreakEvent event) { + build(event.getPlayer(), event.getBlock(), event); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void build(SignChangeEvent event) { + build(event.getPlayer(), event.getBlock(), event); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void build(HangingPlaceEvent event) { + build(event.getPlayer(), event.getBlock(), event); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void build(HangingBreakByEntityEvent event) { + build(event.getRemover(), event.getEntity().getLocation().getBlock(), event); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void build(EntityChangeBlockEvent event) { + // Handling lilypads being broken by boats + Entity entity = event.getEntity(); + if (entity.getType() != EntityType.BOAT || entity.getPassengers().size() <= 0) { + return; + } + Entity player = entity.getPassengers().stream().filter(MUtil::isPlayer).findAny().orElse(entity); + + build(player, event.getBlock(), event); + } + + + // -------------------------------------------- // + // USE > ITEM + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void useBlockItem(PlayerInteractEvent event) { + // If the player right clicks (or is physical with) a block ... + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) { + return; + } + + Block block = event.getClickedBlock(); + Player player = event.getPlayer(); + if (block == null) { + return; + } + + // ... and we are either allowed to use this block ... + Boolean ret = useBlock(player, block, true, event); + if (Boolean.TRUE.equals(ret)) { + return; + } + + // ... or are allowed to right click with the item, this event is safe to perform. + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { + return; + } + useItem(player, block, event.getMaterial(), event); + } + + // For some reason onPlayerInteract() sometimes misses bucket events depending on distance + // (something like 2-3 blocks away isn't detected), but these separate bucket events below always fire without fail + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void useItem(PlayerBucketEmptyEvent event) { + useItem(event.getPlayer(), event.getBlockClicked().getRelative(event.getBlockFace()), event.getBucket(), event); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void useItem(PlayerBucketFillEvent event) { + useItem(event.getPlayer(), event.getBlockClicked(), event.getBucket(), event); + } + + // -------------------------------------------- // + // USE > ENTITY + // -------------------------------------------- // + + // This event will not fire for Minecraft 1.8 armor stands. + // Armor stands are handled in EngineSpigot instead. + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void useEntity(PlayerInteractEntityEvent event) { + // Ignore Off Hand + if (isOffHand(event)) { + return; + } + useEntity(event.getPlayer(), event.getRightClicked(), true, event); + } + + // This is a special Spigot event that fires for Minecraft 1.8 armor stands. + // It also fires for other entity types but for those the event is buggy. + // It seems we can only cancel interaction with armor stands from here. + // Thus we only handle armor stands from here and handle everything else in EngineMain. + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void handleArmorStand(PlayerInteractAtEntityEvent event) { + // Ignore Off Hand + if (isOffHand(event)) { + return; + } + + // Gather Info + final Player player = event.getPlayer(); + if (MUtil.isntPlayer(player)) { + return; + } + final Entity entity = event.getRightClicked(); + final boolean verboose = true; + + // Only care for armor stands. + if (entity.getType() != EntityType.ARMOR_STAND) { + return; + } + + // If we can't use, block it + EnginePermBuild.useEntity(player, entity, verboose, event); + } + + // -------------------------------------------- // + // BUILD > ENTITY + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void buildEntity(EntityDamageByEntityEvent event) { + // If a player ... + Entity damager = MUtil.getLiableDamager(event); + if (MUtil.isntPlayer(damager)) { + return; + } + Player player = (Player) damager; + + // ... damages an entity which is edited on damage ... + Entity entity = event.getEntity(); + if (entity == null || !EnumerationUtil.isEntityTypeEditOnDamage(entity.getType())) { + return; + } + + // ... and the player can't build there, cancel the event + build(player, entity.getLocation().getBlock(), event); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void combustEntity(EntityCombustByEntityEvent event) { + + // If a burning projectile ... + if (!(event.getCombuster() instanceof Projectile)) { + return; + } + Projectile entityProjectile = (Projectile) event.getCombuster(); + + // ... fired by a player ... + ProjectileSource projectileSource = entityProjectile.getShooter(); + if (MUtil.isntPlayer(projectileSource)) { + return; + } + Player player = (Player) projectileSource; + + // ... and hits an entity which is edited on damage (and thus likely to burn) ... + Entity entityTarget = event.getEntity(); + if (entityTarget == null || !EnumerationUtil.isEntityTypeEditOnDamage(entityTarget.getType())) { + return; + } + + // ... and the player can't build there, cancel the event + Block block = entityTarget.getLocation().getBlock(); + protect(ProtectCase.BUILD, false, player, PS.valueOf(block), block, event); + } + + // -------------------------------------------- // + // BUILD > PISTON + // -------------------------------------------- // + + /* + * Note: With 1.8 and the slime blocks, retracting and extending pistons + * became more of a problem. Blocks located on the border of a chunk + * could have easily been stolen. That is the reason why every block + * needs to be checked now, whether he moved into a territory which + * he actually may not move into. + */ + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void blockBuild(BlockPistonExtendEvent event) { + // Is checking deactivated by MConf? + if (!MConf.get().handlePistonProtectionThroughDenyBuild) { + return; + } + + Faction pistonFaction = BoardColl.get().getFactionAt(PS.valueOf(event.getBlock())); + + List blocks = event.getBlocks(); + + // Check for all extended blocks + for (Block block : blocks) { + // Block which is being pushed into + Block targetBlock = block.getRelative(event.getDirection()); + + // Members of a faction might not have build rights in their own territory, but pistons should still work regardless + Faction targetFaction = BoardColl.get().getFactionAt(PS.valueOf(targetBlock)); + if (targetFaction == pistonFaction) { + continue; + } + + // Perm check + if (MPerm.getPermBuild().has(pistonFaction, targetFaction)) { + continue; + } + + event.setCancelled(true); + return; + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void blockBuild(BlockPistonRetractEvent event) { + // Is checking deactivated by MConf? + if (!MConf.get().handlePistonProtectionThroughDenyBuild) { + return; + } + + Faction pistonFaction = BoardColl.get().getFactionAt(PS.valueOf(event.getBlock())); + + List blocks = event.getBlocks(); + + // Check for all retracted blocks + for (Block block : blocks) { + // Is the retracted block air/water/lava? Don't worry about it + if (block.isEmpty() || block.isLiquid()) { + return; + } + + // Members of a faction might not have build rights in their own territory, but pistons should still work regardless + Faction targetFaction = BoardColl.get().getFactionAt(PS.valueOf(block)); + if (targetFaction == pistonFaction) { + continue; + } + + // Perm check + if (MPerm.getPermBuild().has(pistonFaction, targetFaction)) { + continue; + } + + event.setCancelled(true); + return; + } + } + + // -------------------------------------------- // + // BUILD > FIRE + // -------------------------------------------- // + + @SuppressWarnings("deprecation") + @EventHandler(priority = EventPriority.NORMAL) + public void buildFire(PlayerInteractEvent event) { + // If it is a left click on block and the clicked block is not null... + if (event.getAction() != Action.LEFT_CLICK_BLOCK || event.getClickedBlock() == null) { + return; + } + + // ... and the potential block is not null either ... + Block potentialBlock = event.getClickedBlock().getRelative(BlockFace.UP, 1); + if (potentialBlock == null) { + return; + } + + Material blockType = potentialBlock.getType(); + + // ... and we're only going to check for fire ... (checking everything else would be bad performance wise) + if (blockType != Material.FIRE) { + return; + } + + // ... check if they can't build, cancel the event ... + if (!Boolean.FALSE.equals(build(event.getPlayer(), potentialBlock, event))) { + return; + } + + // ... and compensate for client side prediction + event.getPlayer().sendBlockChange(potentialBlock.getLocation(), blockType, potentialBlock.getState().getRawData()); + } + + // -------------------------------------------- // + // BUILD > MOVE + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void buildMove(BlockFromToEvent event) { + if (!MConf.get().protectionLiquidFlowEnabled) { + return; + } + + // Prepare fields + Block fromBlock = event.getBlock(); + int chunkFromX = fromBlock.getX() >> 4; + int chunkFromZ = fromBlock.getZ() >> 4; + BlockFace face = event.getFace(); + int chunkToX = (fromBlock.getX() + face.getModX()) >> 4; + int chunkToZ = (fromBlock.getZ() + face.getModZ()) >> 4; + + // If a liquid (or dragon egg) moves from one chunk to another ... + if (chunkToX == chunkFromX && chunkToZ == chunkFromZ) { + return; + } + + // ... get the correct board for this block ... + Board board = BoardColl.get().getFixed(fromBlock.getWorld().getName().toLowerCase(), false); + if (board == null) { + return; + } + + // ... get the access map ... + Map map = board.getMapRaw(); + if (map.isEmpty()) { + return; + } + + // ... get the faction ids from and to ... + PS fromPs = PS.valueOf(chunkFromX, chunkFromZ); + PS toPs = PS.valueOf(chunkToX, chunkToZ); + TerritoryAccess fromTa = map.get(fromPs); + TerritoryAccess toTa = map.get(toPs); + + // Null checks are needed here since automatic board cleaning can be undesired sometimes + String fromId = fromTa != null ? fromTa.getHostFactionId() : Factions.ID_NONE; + String toId = toTa != null ? toTa.getHostFactionId() : Factions.ID_NONE; + + // ... and the chunks belong to different factions ... + if (toId.equals(fromId)) { + return; + } + + // ... and the faction "from" can not build at "to" ... + Faction fromFac = FactionColl.get().getFixed(fromId); + if (fromFac == null) { + fromFac = FactionColl.get().getNone(); + } + Faction toFac = FactionColl.get().getFixed(toId); + if (toFac == null) { + toFac = FactionColl.get().getNone(); + } + if (MPerm.getPermBuild().has(fromFac, toFac)) { + return; + } + + // ... cancel the event! + event.setCancelled(true); + } + +} diff --git a/src/main/java/com/massivecraft/factions/engine/EnginePlayerData.java b/src/main/java/com/massivecraft/factions/engine/EnginePlayerData.java new file mode 100644 index 00000000..7e9cf54d --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/EnginePlayerData.java @@ -0,0 +1,57 @@ +package com.massivecraft.factions.engine; + +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.entity.MPlayerColl; +import com.massivecraft.massivecore.Engine; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerKickEvent; + +public class EnginePlayerData extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EnginePlayerData i = new EnginePlayerData(); + + public static EnginePlayerData get() { + return i; + } + + // -------------------------------------------- // + // REMOVE PLAYER DATA WHEN BANNED + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onPlayerKick(PlayerKickEvent event) { + // If a player was kicked from the server ... + Player player = event.getPlayer(); + + // ... and if the if player was banned (not just kicked) ... + //if (!event.getReason().equals("Banned by admin.")) return; + if (!player.isBanned()) { + return; + } + + // ... and we remove player data when banned ... + if (!MConf.get().removePlayerWhenBanned) { + return; + } + + // ... get rid of their stored info. + MPlayer mplayer = MPlayerColl.get().get(player, false); + if (mplayer == null) { + return; + } + + if (mplayer.getRank().isLeader()) { + mplayer.getFaction().promoteNewLeader(); + } + + mplayer.leave(); + mplayer.detach(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/engine/EnginePower.java b/src/main/java/com/massivecraft/factions/engine/EnginePower.java new file mode 100644 index 00000000..26d151c5 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/EnginePower.java @@ -0,0 +1,80 @@ +package com.massivecraft.factions.engine; + +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.MPlayer; +import com.massivecraft.factions.event.EventFactionsPowerChange; +import com.massivecraft.factions.event.EventFactionsPowerChange.PowerChangeReason; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.MUtil; +import com.massivecraft.massivecore.util.PlayerUtil; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.PlayerDeathEvent; + +public class EnginePower extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EnginePower i = new EnginePower(); + + public static EnginePower get() { + return i; + } + + // -------------------------------------------- // + // POWER LOSS ON DEATH + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.NORMAL) + public void powerLossOnDeath(PlayerDeathEvent event) { + // If a player dies ... + Player player = event.getEntity(); + if (MUtil.isntPlayer(player)) { + return; + } + + // ... and this is the first death event this tick ... + // (yeah other plugins can case death event to fire twice the same tick) + if (PlayerUtil.isDuplicateDeathEvent(event)) { + return; + } + + MPlayer mplayer = MPlayer.get(player); + + // ... and powerloss can happen here ... + Faction faction = BoardColl.get().getFactionAt(PS.valueOf(player.getLocation())); + + if (!faction.getFlag(MFlag.getFlagPowerloss())) { + mplayer.msg("You didn't lose any power since the territory you died in works that way."); + return; + } + + if (!MConf.get().worldsPowerLossEnabled.contains(player.getWorld())) { + mplayer.msg("You didn't lose any power due to the world you died in."); + return; + } + + // ... alter the power ... + double newPower = mplayer.getPower() + mplayer.getPowerPerDeath(); + + EventFactionsPowerChange powerChangeEvent = new EventFactionsPowerChange(null, mplayer, PowerChangeReason.DEATH, newPower); + powerChangeEvent.run(); + if (powerChangeEvent.isCancelled()) { + return; + } + newPower = powerChangeEvent.getNewPower(); + + mplayer.setPower(newPower); + + // ... and inform the player. + // TODO: A progress bar here would be epic :) + mplayer.msg("Your power is now %.2f / %.2f", newPower, mplayer.getPowerMax()); + } + +} diff --git a/src/main/java/com/massivecraft/factions/engine/EngineSeeChunk.java b/src/main/java/com/massivecraft/factions/engine/EngineSeeChunk.java new file mode 100644 index 00000000..f8f01cac --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/EngineSeeChunk.java @@ -0,0 +1,192 @@ +package com.massivecraft.factions.engine; + +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.event.EventMassiveCorePlayerLeave; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.MUtil; +import com.massivecraft.massivecore.util.PeriodUtil; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerChangedWorldEvent; + +import java.security.InvalidParameterException; +import java.util.ArrayList; +import java.util.List; + +public class EngineSeeChunk extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineSeeChunk i = new EngineSeeChunk(); + + public static EngineSeeChunk get() { + return i; + } + + public EngineSeeChunk() { + this.setPeriod(1L); + } + + // -------------------------------------------- // + // LEAVE AND WORLD CHANGE REMOVAL + // -------------------------------------------- // + + public static void leaveAndWorldChangeRemoval(Player player) { + if (MUtil.isntPlayer(player)) { + return; + } + + final MPlayer mplayer = MPlayer.get(player); + mplayer.setSeeingChunk(false); + } + + // Can't be cancelled + @EventHandler(priority = EventPriority.NORMAL) + public void leaveAndWorldChangeRemoval(EventMassiveCorePlayerLeave event) { + leaveAndWorldChangeRemoval(event.getPlayer()); + } + + // Can't be cancelled + @EventHandler(priority = EventPriority.NORMAL) + public void leaveAndWorldChangeRemoval(PlayerChangedWorldEvent event) { + leaveAndWorldChangeRemoval(event.getPlayer()); + } + + // -------------------------------------------- // + // MODULO REPEAT TASK + // -------------------------------------------- // + + @Override + public void run() { + // Do we have a new period? + final long now = System.currentTimeMillis(); + final long length = 500; + if (!PeriodUtil.isNewPeriod(this, length, now)) { + return; + } + + // Get the period number + final long period = PeriodUtil.getPeriod(length, now); + + // Calculate the "step" from the period number + final int steps = 1; // Example: 4 + final int step = (int) (period % steps); // Example: 0, 1, 2, 3 + + // Load other related config options + final float offsetX = 0.0f; + final float offsetY = 2; + final float offsetZ = 0.0f; + final float speed = 0; + final int amount = 30; + + // For each player + for (Player player : Bukkit.getOnlinePlayers()) { + // Hide for dead players since the death screen looks better without. + if (player.isDead()) { + continue; + } + + // The player must obviously have the feature activated. + MPlayer mplayer = MPlayer.get(player); + if (!mplayer.isSeeingChunk()) { + continue; + } + + // Calculate locations and play the effect there. + List locations = getLocations(player, steps, step); + for (Location location : locations) { + location.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, location, amount, offsetX, offsetY, offsetZ, speed); + //ParticleEffect.EXPLOSION_NORMAL.display(location, offsetX, offsetY, offsetZ, speed, amount, player); + } + } + } + + public static List getLocations(Player player, int steps, int step) { + // Clean Args + if (player == null) { + throw new NullPointerException("player"); + } + if (steps < 1) { + throw new InvalidParameterException("steps must be larger than 0"); + } + if (step < 0) { + throw new InvalidParameterException("step must at least be 0"); + } + if (step >= steps) { + throw new InvalidParameterException("step must be less than steps"); + } + + // Create Ret + List ret = new ArrayList<>(); + + final Location location = player.getLocation(); + final World world = location.getWorld(); + PS chunk = PS.valueOf(location).getChunk(true); + + final int xmin = chunk.getChunkX() * 16; + final int xmax = xmin + 15; + final double y = location.getBlockY() + 2; + final int zmin = chunk.getChunkZ() * 16; + final int zmax = zmin + 15; + + int keepEvery = 5; + if (keepEvery <= 0) { + keepEvery = Integer.MAX_VALUE; + } + + int skipEvery = 0; + if (skipEvery <= 0) { + skipEvery = Integer.MAX_VALUE; + } + + int x = xmin; + int z = zmin; + int i = 0; + + // Add #1 + while (x + 1 <= xmax) { + x++; + i++; + if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) { + ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5)); + } + } + + // Add #2 + while (z + 1 <= zmax) { + z++; + i++; + if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) { + ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5)); + } + } + + // Add #3 + while (x - 1 >= xmin) { + x--; + i++; + if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) { + ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5)); + } + } + + // Add #4 + while (z - 1 >= zmin) { + z--; + i++; + if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) { + ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5)); + } + } + + // Return Ret + return ret; + } +} diff --git a/src/main/java/com/massivecraft/factions/engine/EngineShow.java b/src/main/java/com/massivecraft/factions/engine/EngineShow.java new file mode 100644 index 00000000..349a4bf8 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/EngineShow.java @@ -0,0 +1,238 @@ +package com.massivecraft.factions.engine; + +import com.massivecraft.factions.comparator.ComparatorMPlayerRole; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.event.EventFactionsChunkChangeType; +import com.massivecraft.factions.event.EventFactionsFactionShowAsync; +import com.massivecraft.factions.integration.Econ; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.PriorityLines; +import com.massivecraft.massivecore.money.Money; +import com.massivecraft.massivecore.util.TimeDiffUtil; +import com.massivecraft.massivecore.util.TimeUnit; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.command.CommandSender; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +public class EngineShow extends Engine { + // -------------------------------------------- // + // CONSTANTS + // -------------------------------------------- // + + public static final String BASENAME = "factions"; + public static final String BASENAME_ = BASENAME + "_"; + + public static final String SHOW_ID_FACTION_ID = BASENAME_ + "id"; + public static final String SHOW_ID_FACTION_DESCRIPTION = BASENAME_ + "description"; + public static final String SHOW_ID_FACTION_AGE = BASENAME_ + "age"; + public static final String SHOW_ID_FACTION_FLAGS = BASENAME_ + "flags"; + public static final String SHOW_ID_FACTION_POWER = BASENAME_ + "power"; + public static final String SHOW_ID_FACTION_LANDVALUES = BASENAME_ + "landvalue"; + public static final String SHOW_ID_FACTION_BANK = BASENAME_ + "bank"; + public static final String SHOW_ID_FACTION_FOLLOWERS = BASENAME_ + "followers"; + + public static final int SHOW_PRIORITY_FACTION_ID = 1000; + public static final int SHOW_PRIORITY_FACTION_DESCRIPTION = 2000; + public static final int SHOW_PRIORITY_FACTION_AGE = 3000; + public static final int SHOW_PRIORITY_FACTION_FLAGS = 4000; + public static final int SHOW_PRIORITY_FACTION_POWER = 5000; + public static final int SHOW_PRIORITY_FACTION_LANDVALUES = 6000; + public static final int SHOW_PRIORITY_FACTION_BANK = 7000; + public static final int SHOW_PRIORITY_FACTION_FOLLOWERS = 9000; + + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineShow i = new EngineShow(); + + public static EngineShow get() { + return i; + } + + // -------------------------------------------- // + // FACTION SHOW + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) + public void onFactionShow(EventFactionsFactionShowAsync event) { + final int tableCols = 4; + final CommandSender sender = event.getSender(); + final MPlayer mplayer = event.getMPlayer(); + final Faction faction = event.getFaction(); + final boolean normal = faction.isNormal(); + final Map idPriorityLiness = event.getIdPriorityLiness(); + String none = Txt.parse("none"); + + // ID + if (mplayer.isOverriding()) { + show(idPriorityLiness, SHOW_ID_FACTION_ID, SHOW_PRIORITY_FACTION_ID, "ID", faction.getId()); + } + + // DESCRIPTION + show(idPriorityLiness, SHOW_ID_FACTION_DESCRIPTION, SHOW_PRIORITY_FACTION_DESCRIPTION, "Description", faction.getDescriptionDesc()); + + // SECTION: NORMAL + if (normal) { + // AGE + long ageMillis = faction.getCreatedAtMillis() - System.currentTimeMillis(); + LinkedHashMap ageUnitcounts = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(ageMillis, TimeUnit.getAllButMillis()), 3); + String ageDesc = TimeDiffUtil.formatedVerboose(ageUnitcounts, ""); + show(idPriorityLiness, SHOW_ID_FACTION_AGE, SHOW_PRIORITY_FACTION_AGE, "Age", ageDesc); + + // FLAGS + // We display all editable and non default ones. The rest we skip. + List flagDescs = new LinkedList<>(); + for (Entry entry : faction.getFlags().entrySet()) { + final MFlag mflag = entry.getKey(); + if (mflag == null) { + continue; + } + + final Boolean value = entry.getValue(); + if (value == null) { + continue; + } + + if (!mflag.isInteresting(value)) { + continue; + } + + String flagDesc = Txt.parse(value ? "" : "") + mflag.getName(); + flagDescs.add(flagDesc); + } + String flagsDesc = Txt.parse("default"); + if (!flagDescs.isEmpty()) { + flagsDesc = Txt.implode(flagDescs, Txt.parse(" | ")); + } + show(idPriorityLiness, SHOW_ID_FACTION_FLAGS, SHOW_PRIORITY_FACTION_FLAGS, "Flags", flagsDesc); + + // POWER + double powerBoost = faction.getPowerBoost(); + String boost = (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? " (bonus: " : " (penalty: ") + powerBoost + ")"; + String powerDesc = Txt.parse("%d/%d/%d%s", faction.getLandCount(), faction.getPowerRounded(), faction.getPowerMaxRounded(), boost); + show(idPriorityLiness, SHOW_ID_FACTION_POWER, SHOW_PRIORITY_FACTION_POWER, "Land / Power / Maxpower", powerDesc); + + // SECTION: ECON + if (Econ.isEnabled()) { + // LANDVALUES + List landvalueLines = new LinkedList<>(); + long landCount = faction.getLandCount(); + for (EventFactionsChunkChangeType type : EventFactionsChunkChangeType.values()) { + Double money = MConf.get().econChunkCost.get(type); + if (money == null) { + continue; + } + if (money == 0) { + continue; + } + money *= landCount; + + String word = "Cost"; + if (money <= 0) { + word = "Reward"; + money *= -1; + } + + String key = Txt.parse("Total Land %s %s", type.toString().toLowerCase(), word); + String value = Txt.parse("%s", Money.format(money)); + String line = show(key, value); + landvalueLines.add(line); + } + idPriorityLiness.put(SHOW_ID_FACTION_LANDVALUES, new PriorityLines(SHOW_PRIORITY_FACTION_LANDVALUES, landvalueLines)); + + // BANK + if (MConf.get().bankEnabled) { + double bank = Econ.getMoney(faction); + String bankDesc = Txt.parse("%s", Money.format(bank, true)); + show(idPriorityLiness, SHOW_ID_FACTION_BANK, SHOW_PRIORITY_FACTION_BANK, "Bank", bankDesc); + } + } + } + + // FOLLOWERS + List followerLines = new ArrayList<>(); + + List followerNamesOnline = new ArrayList<>(); + List followerNamesOffline = new ArrayList<>(); + + List followers = faction.getMPlayers(); + followers.sort(ComparatorMPlayerRole.get()); + for (MPlayer follower : followers) { + if (follower.isOnline(sender)) { + followerNamesOnline.add(follower.getNameAndTitle(mplayer)); + } else if (normal) { + // For the non-faction we skip the offline members since they are far to many (infinite almost) + followerNamesOffline.add(follower.getNameAndTitle(mplayer)); + } + } + + String headerOnline = Txt.parse("Followers Online (%s):", followerNamesOnline.size()); + followerLines.add(headerOnline); + if (followerNamesOnline.isEmpty()) { + followerLines.add(none); + } else { + followerLines.addAll(table(followerNamesOnline, tableCols)); + } + + if (normal) { + String headerOffline = Txt.parse("Followers Offline (%s):", followerNamesOffline.size()); + followerLines.add(headerOffline); + if (followerNamesOffline.isEmpty()) { + followerLines.add(none); + } else { + followerLines.addAll(table(followerNamesOffline, tableCols)); + } + } + idPriorityLiness.put(SHOW_ID_FACTION_FOLLOWERS, new PriorityLines(SHOW_PRIORITY_FACTION_FOLLOWERS, followerLines)); + } + + public static String show(String key, String value) { + return Txt.parse("%s: %s", key, value); + } + + public static PriorityLines show(int priority, String key, String value) { + return new PriorityLines(priority, show(key, value)); + } + + public static void show(Map idPriorityLiness, String id, int priority, String key, String value) { + idPriorityLiness.put(id, show(priority, key, value)); + } + + public static List table(List strings, int cols) { + List ret = new ArrayList<>(); + + StringBuilder row = new StringBuilder(); + int count = 0; + + Iterator iter = strings.iterator(); + while (iter.hasNext()) { + String string = iter.next(); + row.append(string); + count++; + + if (iter.hasNext() && count != cols) { + row.append(Txt.parse(" | ")); + } else { + ret.add(row.toString()); + row = new StringBuilder(); + count = 0; + } + } + + return ret; + } + +} diff --git a/src/main/java/com/massivecraft/factions/engine/EngineTeleportHomeOnDeath.java b/src/main/java/com/massivecraft/factions/engine/EngineTeleportHomeOnDeath.java new file mode 100644 index 00000000..6986bb03 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/EngineTeleportHomeOnDeath.java @@ -0,0 +1,108 @@ +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.util.MUtil; +import org.bukkit.Location; +import org.bukkit.entity.Player; +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 { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineTeleportHomeOnDeath i = new EngineTeleportHomeOnDeath(); + + public static EngineTeleportHomeOnDeath get() { + return i; + } + + // -------------------------------------------- // + // TELEPORT TO HOME ON DEATH + // -------------------------------------------- // + + public void teleportToHomeOnDeath(PlayerRespawnEvent event, EventPriority priority) { + // If a player is respawning ... + final Player player = event.getPlayer(); + if (MUtil.isntPlayer(player)) { + return; + } + final MPlayer mplayer = MPlayer.get(player); + + // ... homes are enabled, active and at this priority ... + 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 ... + List warps = faction.getWarps().getAll((java.util.function.Predicate) (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 = warp.getLocation().asBukkitLocation(true); + } catch (Exception e) { + // The home location map may have been deleted + return; + } + + // ... then use it for the respawn location. + event.setRespawnLocation(respawnLocation); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void teleportToHomeOnDeathLowest(PlayerRespawnEvent event) { + this.teleportToHomeOnDeath(event, EventPriority.LOWEST); + } + + @EventHandler(priority = EventPriority.LOW) + public void teleportToHomeOnDeathLow(PlayerRespawnEvent event) { + this.teleportToHomeOnDeath(event, EventPriority.LOW); + } + + @EventHandler(priority = EventPriority.NORMAL) + public void teleportToHomeOnDeathNormal(PlayerRespawnEvent event) { + this.teleportToHomeOnDeath(event, EventPriority.NORMAL); + } + + @EventHandler(priority = EventPriority.HIGH) + public void teleportToHomeOnDeathHigh(PlayerRespawnEvent event) { + this.teleportToHomeOnDeath(event, EventPriority.HIGH); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void teleportToHomeOnDeathHighest(PlayerRespawnEvent event) { + this.teleportToHomeOnDeath(event, EventPriority.HIGHEST); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void teleportToHomeOnDeathMonitor(PlayerRespawnEvent event) { + this.teleportToHomeOnDeath(event, EventPriority.MONITOR); + } + +} diff --git a/src/main/java/com/massivecraft/factions/engine/EngineTerritoryShield.java b/src/main/java/com/massivecraft/factions/engine/EngineTerritoryShield.java new file mode 100644 index 00000000..b75aa1f3 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/EngineTerritoryShield.java @@ -0,0 +1,70 @@ +package com.massivecraft.factions.engine; + +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.util.MUtil; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityDamageByEntityEvent; + +import java.text.MessageFormat; + +public class EngineTerritoryShield extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineTerritoryShield i = new EngineTerritoryShield(); + + public static EngineTerritoryShield get() { + return i; + } + + // -------------------------------------------- // + // TERRITORY SHIELD + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void territoryShield(EntityDamageByEntityEvent event) { + // If the entity is a player ... + Entity entity = event.getEntity(); + if (MUtil.isntPlayer(entity)) { + return; + } + Player player = (Player) entity; + MPlayer mplayer = MPlayer.get(player); + + // ... and the attacker is a player ... + Entity attacker = MUtil.getLiableDamager(event); + if (!(attacker instanceof Player)) { + return; + } + + // ... and that player has a faction ... + if (!mplayer.hasFaction()) { + return; + } + + // ... and that player is in their own territory ... + if (!mplayer.isInOwnTerritory()) { + return; + } + + // ... and a territoryShieldFactor is configured ... + if (MConf.get().territoryShieldFactor <= 0) { + return; + } + + // ... then scale the damage ... + double factor = 1D - MConf.get().territoryShieldFactor; + MUtil.scaleDamage(event, factor); + + // ... and inform. + String perc = MessageFormat.format("{0,number,#%}", (MConf.get().territoryShieldFactor)); + mplayer.msg("Enemy damage reduced by %s.", perc); + } + +} diff --git a/src/main/java/com/massivecraft/factions/engine/EngineVisualizations.java b/src/main/java/com/massivecraft/factions/engine/EngineVisualizations.java new file mode 100644 index 00000000..907e54fe --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/EngineVisualizations.java @@ -0,0 +1,34 @@ +package com.massivecraft.factions.engine; + +import com.massivecraft.factions.util.VisualizeUtil; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.util.MUtil; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerMoveEvent; + +public class EngineVisualizations extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineVisualizations i = new EngineVisualizations(); + + public static EngineVisualizations get() { + return i; + } + + // -------------------------------------------- // + // VISUALIZE UTIL + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onPlayerMoveClearVisualizations(PlayerMoveEvent event) { + if (MUtil.isSameBlock(event)) { + return; + } + + VisualizeUtil.clear(event.getPlayer()); + } + +} diff --git a/src/main/java/com/massivecraft/factions/engine/ProtectCase.java b/src/main/java/com/massivecraft/factions/engine/ProtectCase.java new file mode 100644 index 00000000..d74f3a94 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/ProtectCase.java @@ -0,0 +1,79 @@ +package com.massivecraft.factions.engine; + +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.util.EnumerationUtil; +import org.bukkit.Material; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; + +public enum ProtectCase { + // -------------------------------------------- // + // ENUM + // -------------------------------------------- // + + BUILD, + USE_BLOCK, + USE_ITEM, + USE_ENTITY, + + // END OF LIST + ; + + // -------------------------------------------- // + // PERM + // -------------------------------------------- // + + public MPerm getPerm(Object object) { + switch (this) { + case BUILD: + return MPerm.getPermBuild(); + + case USE_ITEM: + if (!(object instanceof Material)) { + return null; + } + if (!EnumerationUtil.isMaterialEditTool((Material) object)) { + return null; + } + return MPerm.getPermBuild(); + + case USE_ENTITY: + if (!(object instanceof Entity)) { + return null; + } + Entity entity = (Entity) object; + EntityType type = entity.getType(); + if (EnumerationUtil.isEntityTypeContainer(type)) { + return MPerm.getPermContainer(); + } + if (EnumerationUtil.isEntityTypeEditOnInteract(type)) { + return MPerm.getPermBuild(); + } + + case USE_BLOCK: + if (!(object instanceof Material)) { + return null; + } + Material material = (Material) object; + if (EnumerationUtil.isMaterialEditOnInteract(material)) { + return MPerm.getPermBuild(); + } + if (EnumerationUtil.isMaterialContainer(material)) { + return MPerm.getPermContainer(); + } + if (EnumerationUtil.isMaterialDoor(material)) { + return MPerm.getPermDoor(); + } + if (material == Material.STONE_BUTTON) { + return MPerm.getPermButton(); + } + if (material == Material.LEVER) { + return MPerm.getPermLever(); + } + + default: + return null; + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/Board.java b/src/main/java/com/massivecraft/factions/entity/Board.java new file mode 100644 index 00000000..21fbb3bf --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/Board.java @@ -0,0 +1,299 @@ +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 implements BoardInterface { + public static final transient Type MAP_TYPE = new TypeToken>() { + }.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 map; + + public Map getMap() { + return Collections.unmodifiableMap(this.map); + } + + public Map getMapRaw() { + return this.map; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public Board() { + this.map = new ConcurrentSkipListMap<>(); + } + + public Board(Map 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 getChunks(Faction faction) { + return this.getChunks(faction.getId()); + } + + @Override + public Set 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> getFactionToChunks() { + return this.getFactionToChunks(true); + } + + @Override + public Map> getFactionToChunks(boolean withWorld) { + Function, 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>> 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 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 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 pss, Faction faction) { + return pss.stream().anyMatch(ps -> this.isConnectedPs(ps, faction)); + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/BoardColl.java b/src/main/java/com/massivecraft/factions/entity/BoardColl.java new file mode 100644 index 00000000..4dc3fe17 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/BoardColl.java @@ -0,0 +1,452 @@ +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 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 getChunks(Faction faction) { + return this.getAll().stream() + .flatMap(board -> board.getChunks(faction).stream()) + .collect(Collectors.toSet()); + } + + @Override + public Set getChunks(String factionId) { + return this.getAll().stream() + .flatMap(board -> board.getChunks(factionId).stream()) + .collect(Collectors.toSet()); + } + + @Override + @Deprecated + public Map> getFactionToChunks() { + return this.getFactionToChunks(false); + } + + @Override + public Map> getFactionToChunks(boolean withWorld) { + // Create + Map> ret = null; + + // Fill + for (Board board : this.getAll()) { + // Use the first board directly + Map> factionToChunks = board.getFactionToChunks(withWorld); + if (ret == null) { + ret = factionToChunks; + continue; + } + + // Merge the following boards + for (Entry> entry : factionToChunks.entrySet()) { + Faction faction = entry.getKey(); + Set 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>> 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 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 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 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 pss, Faction faction) { + for (PS ps : pss) { + if (this.isConnectedPs(ps, faction)) { + return true; + } + } + return false; + } + + // -------------------------------------------- // + // WORLDS + // -------------------------------------------- // + + public Set getClaimedWorlds(Faction faction) { + return getClaimedWorlds(faction.getId()); + } + + public Set 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 getNearbyChunks(PS psChunk, int distance) { + // Fix Args + if (psChunk == null) { + throw new NullPointerException("psChunk"); + } + psChunk = psChunk.getChunk(true); + + // Create + Set 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 getNearbyChunks(Collection chunks, int distance) { + // Fix Args + if (chunks == null) { + throw new NullPointerException("chunks"); + } + + // Create + Set ret = new MassiveSet<>(); + + if (distance < 0) { + return ret; + } + + // Fill + for (PS chunk : chunks) { + ret.addAll(getNearbyChunks(chunk, distance)); + } + + // Return + return ret; + } + + public static Set getDistinctFactions(Collection chunks) { + // Fix Args + if (chunks == null) { + throw new NullPointerException("chunks"); + } + + // Create + Set 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 getChunkFaction(Collection chunks) { + // Create + Map 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> getForests(Collection pss) { + List> forests = new MassiveList<>(); + List discovered = new MassiveList<>(); + + outer: + for (PS ps : pss) { + if (discovered.contains(ps)) { + continue outer; + } + + List forest = new MassiveList<>(); + forests.add(forest); + + Stack 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 stack, Collection source) { + if (source.contains(ps)) { + stack.push(ps); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/BoardInterface.java b/src/main/java/com/massivecraft/factions/entity/BoardInterface.java new file mode 100644 index 00000000..5cb35a7f --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/BoardInterface.java @@ -0,0 +1,58 @@ +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 getChunks(Faction faction); + + Set getChunks(String factionId); + + @Deprecated + Map> getFactionToChunks(); + + Map> getFactionToChunks(boolean withWorld); + + Map>> getWorldToFactionToChunks(boolean withWorld); + + // COUNT + int getCount(Faction faction); + + int getCount(String factionId); + + Map getFactionToCount(); + + // CLAIMED + boolean hasClaimed(Faction faction); + + boolean hasClaimed(String factionId); + + // NEARBY DETECTION + boolean isBorderPs(PS ps); + + boolean isAnyBorderPs(Set pss); + + boolean isConnectedPs(PS ps, Faction faction); + + boolean isAnyConnectedPs(Set pss, Faction faction); + +} diff --git a/src/main/java/com/massivecraft/factions/entity/Faction.java b/src/main/java/com/massivecraft/factions/entity/Faction.java new file mode 100644 index 00000000..0c502a5e --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/Faction.java @@ -0,0 +1,1372 @@ +package com.massivecraft.factions.entity; + + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.FactionsIndex; +import com.massivecraft.factions.FactionsParticipator; +import com.massivecraft.factions.Rel; +import com.massivecraft.factions.RelationParticipator; +import com.massivecraft.factions.entity.MPerm.MPermable; +import com.massivecraft.factions.predicate.PredicateCommandSenderFaction; +import com.massivecraft.factions.predicate.PredicateMPlayerRank; +import com.massivecraft.factions.util.MiscUtil; +import com.massivecraft.factions.util.RelationUtil; +import com.massivecraft.massivecore.Couple; +import com.massivecraft.massivecore.Identified; +import com.massivecraft.massivecore.collections.MassiveList; +import com.massivecraft.massivecore.collections.MassiveMap; +import com.massivecraft.massivecore.collections.MassiveMapDef; +import com.massivecraft.massivecore.collections.MassiveSet; +import com.massivecraft.massivecore.mixin.MixinMessage; +import com.massivecraft.massivecore.money.Money; +import com.massivecraft.massivecore.predicate.PredicateAnd; +import com.massivecraft.massivecore.predicate.PredicateVisibleTo; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.store.Entity; +import com.massivecraft.massivecore.store.EntityInternalMap; +import com.massivecraft.massivecore.store.SenderColl; +import com.massivecraft.massivecore.util.IdUtil; +import com.massivecraft.massivecore.util.MUtil; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +public class Faction extends Entity implements FactionsParticipator, MPerm.MPermable { + // -------------------------------------------- // + // CONSTANTS + // -------------------------------------------- // + + public static final transient String NODESCRIPTION = Txt.parse("no description set"); + public static final transient String NOMOTD = Txt.parse("no message of the day set"); + + // -------------------------------------------- // + // META + // -------------------------------------------- // + + public static Faction get(Object oid) { + return FactionColl.get().get(oid); + } + + // -------------------------------------------- // + // OVERRIDE: ENTITY + // -------------------------------------------- // + + @Override + public Faction load(Faction that) { + this.setName(that.name); + this.setDescription(that.description); + this.setMotd(that.motd); + this.setCreatedAtMillis(that.createdAtMillis); + this.warps.load(that.warps); + this.setPowerBoost(that.powerBoost); + this.money = that.money; + this.invitations.load(that.invitations); + this.ranks.load(that.ranks); + this.votes.load(that.votes); + this.setRelationWishes(that.relationWishes); + this.setFlagIds(that.flags); + this.perms = that.perms; + this.tax = that.tax; + + return this; + } + + @Override + public void preDetach(String id) { + if (!this.isLive()) { + return; + } + + // NOTE: Existence check is required for compatibility with some plugins. + // If they have money ... + if (Money.exists(this)) { + // ... remove it. + Money.set(this, null, 0, "Factions"); + } + } + + // -------------------------------------------- // + // VERSION + // -------------------------------------------- // + + public int version = 4; + + // -------------------------------------------- // + // FIELDS: RAW + // -------------------------------------------- // + // In this section of the source code we place the field declarations only. + // Each field has it's own section further down since just the getter and setter logic takes up quite some place. + + // The actual faction id looks something like "54947df8-0e9e-4471-a2f9-9af509fb5889" and that is not too easy to remember for humans. + // Thus we make use of a name. Since the id is used in all foreign key situations changing the name is fine. + // Null should never happen. The name must not be null. + private String name = null; + + // Factions can optionally set a description for themselves. + // This description can for example be seen in territorial alerts. + // Null means the faction has no description. + private String description = null; + + // Factions can optionally set a message of the day. + // This message will be shown when logging on to the server. + // Null means the faction has no motd + private String motd = null; + + // We store the creation date for the faction. + // It can be displayed on info pages etc. + private long createdAtMillis = System.currentTimeMillis(); + + // 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. + // Null means the faction has powerBoost (0). + private Double powerBoost = null; + + // The money a Faction has + // null means 0.0 + private Double money = null; + + // This is the ids of the invited players. + // They are actually "senderIds" since you can invite "@console" to your faction. + private EntityInternalMap invitations = new EntityInternalMap<>(this, Invitation.class); + + // This is where all the ranks are, they are faction specific + private EntityInternalMap ranks = this.createRankMap(); + + // This is the votes currently open in the faction + private EntityInternalMap votes = new EntityInternalMap<>(this, Vote.class); + + // The keys in this map are factionIds. + // Null means no special relation whishes. + private MassiveMapDef relationWishes = new MassiveMapDef<>(); + + // The flag overrides are modifications to the default values. + // Null means default. + private MassiveMapDef flags = new MassiveMapDef<>(); + + private Map> perms = this.createNewPermMap(); + + // What is the base tax on members of the faction? + // Specific taxes on ranks or players. + public static transient String IDENTIFIER_TAX_BASE = "base"; + + private Map tax = new MassiveMap<>(); + + // -------------------------------------------- // + // FIELD: id + // -------------------------------------------- // + + // FINER + + public boolean isNone() { + return this.getId().equals(Factions.ID_NONE); + } + + public boolean isNormal() { + return !this.isNone(); + } + + // -------------------------------------------- // + // FIELD: name + // -------------------------------------------- // + + // RAW + + @Override + public String getName() { + return this.name; + } + + public void setName(String name) { + // Clean input + String target = name; + + // Detect Nochange + if (MUtil.equals(this.name, target)) { + return; + } + + // Apply + this.name = target; + + // Mark as changed + this.changed(); + } + + // FINER + + public String getComparisonName() { + return MiscUtil.getComparisonString(this.getName()); + } + + public String getName(String prefix) { + return prefix + this.getName(); + } + + public String getName(RelationParticipator observer) { + if (observer == null) { + return getName(); + } + return this.getName(this.getColorTo(observer).toString()); + } + + // -------------------------------------------- // + // FIELD: description + // -------------------------------------------- // + + // RAW + + public boolean hasDescription() { + return this.description != null; + } + + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + // Clean input + String target = clean(description); + + // Detect Nochange + if (MUtil.equals(this.description, target)) { + return; + } + + // Apply + this.description = target; + + // Mark as changed + this.changed(); + } + + // FINER + + public String getDescriptionDesc() { + String motd = this.getDescription(); + if (motd == null) { + motd = NODESCRIPTION; + } + return motd; + } + + // -------------------------------------------- // + // FIELD: motd + // -------------------------------------------- // + + // RAW + + public boolean hasMotd() { + return this.motd != null; + } + + public String getMotd() { + return this.motd; + } + + public void setMotd(String motd) { + // Clean input + String target = clean(motd); + + // Detect Nochange + if (MUtil.equals(this.motd, target)) { + return; + } + + // Apply + this.motd = target; + + // Mark as changed + this.changed(); + } + + // FINER + + public String getMotdDesc() { + return getMotdDesc(this.getMotd()); + } + + private static String getMotdDesc(String motd) { + if (motd == null) { + motd = NOMOTD; + } + return motd; + } + + public List getMotdMessages() { + // Create + List ret = new MassiveList<>(); + + // Fill + Object title = this.getName() + " - Message of the Day"; + title = Txt.titleize(title); + ret.add(title); + + String motd = this.getMotdDesc(); + List motds = Arrays.asList(motd.split("\\\\n")); + motds = motds.stream().map(s -> Txt.parse("") + s).collect(Collectors.toList()); + ret.addAll(motds); + + ret.add(""); + + // Return + return ret; + } + + // -------------------------------------------- // + // FIELD: createdAtMillis + // -------------------------------------------- // + + public long getCreatedAtMillis() { + return this.createdAtMillis; + } + + public void setCreatedAtMillis(long createdAtMillis) { + // Detect Nochange + if (MUtil.equals(this.createdAtMillis, createdAtMillis)) { + return; + } + + // Apply + this.createdAtMillis = createdAtMillis; + + // Mark as changed + this.changed(); + } + + public long getAge() { + return this.getAge(System.currentTimeMillis()); + } + + public long getAge(long now) { + return now - this.getCreatedAtMillis(); + } + + // -------------------------------------------- // + // FIELD: warp + // -------------------------------------------- // + + public EntityInternalMap getWarps() { + return this.warps; + } + + public Warp getWarp(Object oid) { + 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 String addWarp(Warp warp) { + return this.getWarps().attach(warp); + } + + public Warp removeWarp(Warp warp) { + return this.getWarps().detachEntity(warp); + } + + // -------------------------------------------- // + // FIELD: powerBoost + // -------------------------------------------- // + + // RAW + @Override + public double getPowerBoost() { + Double ret = this.powerBoost; + if (ret == null) { + ret = 0D; + } + return ret; + } + + @Override + public void setPowerBoost(Double powerBoost) { + // Clean input + Double target = powerBoost; + + if (target == null || target == 0) { + target = null; + } + + // Detect Nochange + if (MUtil.equals(this.powerBoost, target)) { + return; + } + + // Apply + this.powerBoost = target; + + // Mark as changed + this.changed(); + } + + // -------------------------------------------- // + // FIELD: money + // -------------------------------------------- // + + public double getMoney() { + if (!MConf.get().econEnabled) { + throw new UnsupportedOperationException("econ not enabled"); + } + if (!MConf.get().bankEnabled) { + throw new UnsupportedOperationException("bank not enabled"); + } + if (!MConf.get().useNewMoneySystem) { + throw new UnsupportedOperationException("this server does not use the new econ system"); + } + + return this.convertGet(this.money, 0D); + } + + public void setMoney(Double money) { + if (!MConf.get().econEnabled) { + throw new UnsupportedOperationException("econ not enabled"); + } + if (!MConf.get().bankEnabled) { + throw new UnsupportedOperationException("bank not enabled"); + } + if (!MConf.get().useNewMoneySystem) { + throw new UnsupportedOperationException("this server does not use the new econ system"); + } + + this.money = this.convertSet(money, this.money, 0D); + } + + // -------------------------------------------- // + // FIELD: invitations + // -------------------------------------------- // + + // RAW + + public EntityInternalMap getInvitations() { + return this.invitations; + } + + // FINER + + public boolean isInvited(String playerId) { + return this.getInvitations().containsKey(playerId); + } + + public boolean isInvited(MPlayer mplayer) { + return this.isInvited(mplayer.getId()); + } + + public boolean uninvite(String playerId) { + return this.getInvitations().detachId(playerId) != null; + } + + public boolean uninvite(MPlayer mplayer) { + return uninvite(mplayer.getId()); + } + + public void invite(String playerId, Invitation invitation) { + uninvite(playerId); + this.invitations.attach(invitation, playerId); + } + + // -------------------------------------------- // + // FIELD: ranks + // -------------------------------------------- // + + // RAW + + public EntityInternalMap getRanks() { + return this.ranks; + } + + // FINER + + public boolean hasRank(Rank rank) { + return this.getRanks().containsKey(rank.getId()); + } + + public Rank getRank(String rankId) { + if (rankId == null) { + throw new NullPointerException("rankId"); + } + return this.getRanks().getFixed(rankId); + } + + private EntityInternalMap createRankMap() { + EntityInternalMap ret = new EntityInternalMap<>(this, Rank.class); + + MConf.get().defaultRanks.stream() + .map(Rank::copy) + .forEach(ret::attach); + + return ret; + } + + public Rank getLeaderRank() { + Rank ret = null; + for (Rank rank : this.getRanks().getAll()) { + if (ret != null && ret.isMoreThan(rank)) { + continue; + } + + ret = rank; + } + return ret; + } + + public Rank getLowestRank() { + Rank ret = null; + for (Rank rank : this.getRanks().getAll()) { + if (ret != null && ret.isLessThan(rank)) { + continue; + } + + ret = rank; + } + return ret; + } + + // -------------------------------------------- // + // FIELD: votes + // -------------------------------------------- // + + // RAW + + public EntityInternalMap getVotes() { + return this.votes; + } + + public void addVote(Vote vote) { + if (vote == null) { + throw new NullPointerException("vote"); + } + this.getVotes().attach(vote); + } + + public Optional getVoteByName(String name) { + if (name == null) { + throw new NullPointerException("name"); + } + return this.getVotes().getAll().stream().filter(vote -> vote.getName().equalsIgnoreCase(name)).findFirst(); + } + + // -------------------------------------------- // + // FIELD: relationWish + // -------------------------------------------- // + + // RAW + + public Map getRelationWishes() { + return this.relationWishes; + } + + public void setRelationWishes(Map relationWishes) { + // Clean input + MassiveMapDef target = new MassiveMapDef<>(relationWishes); + + // Detect Nochange + if (MUtil.equals(this.relationWishes, target)) { + return; + } + + // Apply + this.relationWishes = target; + + // Mark as changed + this.changed(); + } + + // FINER + + public Rel getRelationWish(String factionId) { + Rel ret = this.getRelationWishes().get(factionId); + if (ret == null) { + ret = Rel.NEUTRAL; + } + return ret; + } + + public Rel getRelationWish(Faction faction) { + return this.getRelationWish(faction.getId()); + } + + public void setRelationWish(String factionId, Rel rel) { + Map relationWishes = this.getRelationWishes(); + if (rel == null || rel == Rel.NEUTRAL) { + relationWishes.remove(factionId); + } else { + relationWishes.put(factionId, rel); + } + this.setRelationWishes(relationWishes); + } + + public void setRelationWish(Faction faction, Rel rel) { + this.setRelationWish(faction.getId(), rel); + } + + // -------------------------------------------- // + // FIELD: flagOverrides + // -------------------------------------------- // + + // RAW + + public Map getFlags() { + // We start with default values ... + Map ret = new MassiveMap<>(); + for (MFlag mflag : MFlag.getAll()) { + ret.put(mflag, mflag.isStandard()); + } + + // ... and if anything is explicitly set we use that info ... + Iterator> iter = this.flags.entrySet().iterator(); + while (iter.hasNext()) { + // ... for each entry ... + Map.Entry entry = iter.next(); + + // ... extract id and remove null values ... + String id = entry.getKey(); + if (id == null) { + iter.remove(); + this.changed(); + continue; + } + + // ... resolve object and skip unknowns ... + MFlag mflag = MFlag.get(id); + if (mflag == null) { + continue; + } + + ret.put(mflag, entry.getValue()); + } + + return ret; + } + + public void setFlags(Map flags) { + Map flagIds = new MassiveMap<>(); + for (Map.Entry entry : flags.entrySet()) { + flagIds.put(entry.getKey().getId(), entry.getValue()); + } + setFlagIds(flagIds); + } + + public void setFlagIds(Map flagIds) { + // Clean input + MassiveMapDef target = new MassiveMapDef<>(); + for (Map.Entry entry : flagIds.entrySet()) { + String key = entry.getKey(); + if (key == null) { + continue; + } + key = key.toLowerCase(); // Lowercased Keys Version 2.6.0 --> 2.7.0 + + Boolean value = entry.getValue(); + if (value == null) { + continue; + } + + target.put(key, value); + } + + // Detect Nochange + if (MUtil.equals(this.flags, target)) { + return; + } + + // Apply + this.flags = new MassiveMapDef<>(target); + + // Mark as changed + this.changed(); + } + + // FINER + + public boolean getFlag(String flagId) { + if (flagId == null) { + throw new NullPointerException("flagId"); + } + + Boolean ret = this.flags.get(flagId); + if (ret != null) { + return ret; + } + + MFlag flag = MFlag.get(flagId); + if (flag == null) { + throw new NullPointerException("flag"); + } + + return flag.isStandard(); + } + + public boolean getFlag(MFlag flag) { + if (flag == null) { + throw new NullPointerException("flag"); + } + + String flagId = flag.getId(); + if (flagId == null) { + throw new NullPointerException("flagId"); + } + + Boolean ret = this.flags.get(flagId); + if (ret != null) { + return ret; + } + + return flag.isStandard(); + } + + public Boolean setFlag(String flagId, boolean value) { + if (flagId == null) { + throw new NullPointerException("flagId"); + } + + Boolean ret = this.flags.put(flagId, value); + if (ret == null || ret != value) { + this.changed(); + } + return ret; + } + + public Boolean setFlag(MFlag flag, boolean value) { + if (flag == null) { + throw new NullPointerException("flag"); + } + + String flagId = flag.getId(); + if (flagId == null) { + throw new NullPointerException("flagId"); + } + + Boolean ret = this.flags.put(flagId, value); + if (ret == null || ret != value) { + this.changed(); + } + return ret; + } + + // -------------------------------------------- // + // FIELD: perms + // -------------------------------------------- // + + public Map> getPerms() { + return this.perms; + } + + public Map> createNewPermMap() { + Map> ret = new MassiveMap<>(); + for (MPerm mperm : MPerm.getAll()) { + Set granteds = mperm2granteds(mperm); + + ret.put(mperm.getId(), granteds); + } + return ret; + } + + private Set mperm2granteds(MPerm mperm) { + String permId = mperm.getId(); + Set value = new MassiveSet<>(MConf.get().perm2default.get(permId)); + Set additions = new MassiveSet<>(); + outer: + for (Iterator it = value.iterator(); it.hasNext(); ) { + String granted = it.next(); + for (Rank rank : this.getRanks().getAll()) { + if (granted.equalsIgnoreCase(rank.getName())) { + it.remove(); + additions.add(rank.getId()); + continue outer; + } + } + } + value.addAll(additions); + return value; + } + + // IS PERMITTED + + public boolean isPlayerPermitted(MPlayer mplayer, String permId) { + if (isPermitted(mplayer.getId(), permId)) { + return true; + } + if (isPermitted(mplayer.getFaction().getId(), permId)) { + return true; + } + if (isPermitted(mplayer.getRank().getId(), permId)) { + return true; + } + if (isPermitted(RelationUtil.getRelationOfThatToMe(mplayer, this).toString(), permId)) { + return true; + } + + return false; + } + + public boolean isPlayerPermitted(MPlayer mplayer, MPerm mperm) { + return isPlayerPermitted(mplayer, mperm.getId()); + } + + public boolean isFactionPermitted(Faction faction, String permId) { + if (isPermitted(faction.getId(), permId)) { + return true; + } + if (isPermitted(RelationUtil.getRelationOfThatToMe(faction, this).toString(), permId)) { + return true; + } + + return false; + } + + public boolean isFactionPermitted(Faction faction, MPerm mperm) { + return isFactionPermitted(faction, mperm.getId()); + } + + public Set getPermitted(String permId) { + if (permId == null) { + throw new NullPointerException("permId"); + } + Set permables = this.perms.get(permId); + + if (permables == null) { + // No perms was found, but likely this is just a new MPerm. + // So if this does not exist in the database, throw an error. + if (!doesPermExist(permId)) { + throw new NullPointerException(permId + " caused null"); + } + + permables = new MassiveSet<>(); + this.perms.put(permId, permables); + } + + return permables; + } + + public Set getPermitted(MPerm mperm) { + return getPermitted(mperm.getId()); + } + + public Set getPermittedPermables(String permId) { + return MPerm.idsToMPermables(getPermitted(permId)); + } + + public Set getPermittedPermables(MPerm mperm) { + return getPermittedPermables(mperm.getId()); + } + + public boolean isPermitted(String permableId, String permId) { + if (permableId == null) { + throw new NullPointerException("permableId"); + } + if (permId == null) { + throw new NullPointerException("permId"); + } + + // TODO: Isn't this section redundant and just a copy of that from getPermitted? + Set permables = this.perms.get(permId); + if (permables == null) { + // No perms was found, but likely this is just a new MPerm. + // So if this does not exist in the database, throw an error. + if (!doesPermExist(permId)) { + throw new NullPointerException(permId + " caused null"); + } + + // Otherwise handle it + return false; + } + + return getPermitted(permId).contains(permableId); + } + + // SET PERMITTED + + public boolean setPermitted(MPerm.MPermable mpermable, String permId, boolean permitted) { + boolean changed = false; + + Set perms = this.perms.get(permId); + if (perms == null) { + // No perms was found, but likely this is just a new MPerm. + // So if this does not exist in the database, throw an error. + if (!doesPermExist(permId)) { + throw new NullPointerException(permId + " caused null"); + } + + // Otherwise handle it + Set permables = new MassiveSet<>(); + this.perms.put(permId, permables); + changed = true; + } + + if (permitted) { + changed = this.getPerms().get(permId).add(mpermable.getId()) | changed; + } else { + changed = this.getPerms().get(permId).remove(mpermable.getId()) | changed; + } + if (changed) { + this.changed(); + } + return changed; + } + + public boolean setPermitted(MPerm.MPermable mpermable, MPerm mperm, boolean permitted) { + return setPermitted(mpermable, mperm.getId(), permitted); + } + + public void setPermittedRelations(String permId, Collection permables) { + Set ids = permables.stream().map(MPerm.MPermable::getId).collect(Collectors.toSet()); + this.getPerms().put(permId, ids); + } + + public void setPermittedRelations(MPerm perm, Collection permables) { + setPermittedRelations(perm.getId(), permables); + } + + + private boolean doesPermExist(String permId) { + return MPermColl.get().getFixed(permId) != null; + } + + // -------------------------------------------- // + // FIELD: tax + // -------------------------------------------- // + + // RAW + public Map getTax() { + return this.tax; + } + + // FINER GET + public Double getTaxFor(String id) { + if (id == null) { + throw new NullPointerException("id"); + } + return this.tax.get(id); + } + + public Double getTaxFor(Identified identified) { + if (identified == null) { + throw new NullPointerException("identified"); + } + return this.getTaxFor(identified.getId()); + } + + public double getTaxForPlayer(MPlayer mplayer) { + return getTaxAndReasonForPlayer(mplayer).map(Entry::getValue).orElse(0D); + } + + public Optional> getTaxAndReasonForPlayer(MPlayer mplayer) { + if (mplayer == null) { + throw new NullPointerException("mplayer"); + } + + if (mplayer.getFaction() != this) { + throw new IllegalArgumentException("Player " + mplayer.getId() + " not in " + this.getId()); + } + + Double ret = null; + + ret = this.getTaxFor(mplayer); + if (ret != null) { + return Optional.of(new Couple<>(mplayer.getId(), ret)); + } + + ret = this.getTaxFor(mplayer.getRank()); + if (ret != null) { + return Optional.of(new Couple<>(mplayer.getRank().getId(), ret)); + } + + ret = this.getTaxFor(IDENTIFIER_TAX_BASE); + if (ret != null) { + return Optional.of(new Couple<>(IDENTIFIER_TAX_BASE, ret)); + } + + return Optional.empty(); + } + + // FINER SET + public Double setTaxFor(String id, Double value) { + this.changed(); + return this.tax.put(id, value); + } + + public Double setTaxFor(Identified identified, Double value) { + return this.setTaxFor(identified.getId(), value); + } + + // -------------------------------------------- // + // OVERRIDE: RelationParticipator + // -------------------------------------------- // + + @Override + public String describeTo(RelationParticipator observer, boolean ucfirst) { + return RelationUtil.describeThatToMe(this, observer, ucfirst); + } + + @Override + public String describeTo(RelationParticipator observer) { + return RelationUtil.describeThatToMe(this, observer); + } + + @Override + public Rel getRelationTo(RelationParticipator observer) { + return RelationUtil.getRelationOfThatToMe(this, observer); + } + + @Override + public Rel getRelationTo(RelationParticipator observer, boolean ignorePeaceful) { + return RelationUtil.getRelationOfThatToMe(this, observer, ignorePeaceful); + } + + @Override + public ChatColor getColorTo(RelationParticipator observer) { + return RelationUtil.getColorOfThatToMe(this, observer); + } + + // -------------------------------------------- // + // OVERRIDE: permable + // -------------------------------------------- // + + @Override + public String getDisplayName(Object senderObject) { + MPlayer mplayer = MPlayer.get(senderObject); + if (mplayer == null) { + return this.getName(); + } + + return this.describeTo(mplayer); + } + + // -------------------------------------------- // + // POWER + // -------------------------------------------- // + // TODO: Implement a has enough feature. + + public double getPower() { + if (this.getFlag(MFlag.getFlagInfpower())) { + return 999999; + } + + double ret = 0; + for (MPlayer mplayer : this.getMPlayers()) { + ret += mplayer.getPower(); + } + + ret = this.limitWithPowerMax(ret); + ret += this.getPowerBoost(); + + return ret; + } + + public double getPowerMax() { + if (this.getFlag(MFlag.getFlagInfpower())) { + return 999999; + } + + double ret = 0; + for (MPlayer mplayer : this.getMPlayers()) { + ret += mplayer.getPowerMax(); + } + + ret = this.limitWithPowerMax(ret); + ret += this.getPowerBoost(); + + return ret; + } + + private double limitWithPowerMax(double power) { + // NOTE: 0.0 powerMax means there is no max power + double powerMax = MConf.get().factionPowerMax; + + return powerMax <= 0 || power < powerMax ? power : powerMax; + } + + public int getPowerRounded() { + return (int) Math.round(this.getPower()); + } + + public int getPowerMaxRounded() { + return (int) Math.round(this.getPowerMax()); + } + + public int getLandCount() { + return BoardColl.get().getCount(this); + } + + public int getLandCountInWorld(String worldName) { + return Board.get(worldName).getCount(this); + } + + public boolean hasLandInflation() { + return this.getLandCount() > this.getPowerRounded(); + } + + // -------------------------------------------- // + // WORLDS + // -------------------------------------------- // + + public Set getClaimedWorlds() { + return BoardColl.get().getClaimedWorlds(this); + } + + // -------------------------------------------- // + // FOREIGN KEY: MPLAYER + // -------------------------------------------- // + + public List getMPlayers() { + return new MassiveList<>(FactionsIndex.get().getMPlayers(this)); + } + + public List getMPlayers(java.util.function.Predicate where, Comparator orderby, Integer limit, Integer offset) { + return MUtil.transform(this.getMPlayers(), where, orderby, limit, offset); + } + + public List getMPlayersWhere(java.util.function.Predicate predicate) { + return this.getMPlayers(predicate, null, null, null); + } + + public List getMPlayersWhereOnline(boolean online) { + return this.getMPlayersWhere(online ? SenderColl.PREDICATE_ONLINE : SenderColl.PREDICATE_OFFLINE); + } + + public List getMPlayersWhereOnlineTo(Object senderObject) { + return this.getMPlayersWhere(PredicateAnd.get(SenderColl.PREDICATE_ONLINE, PredicateVisibleTo.get(senderObject))); + } + + public List getMPlayersWhereRank(Rank rank) { + return this.getMPlayersWhere(PredicateMPlayerRank.get(rank)); + } + + public MPlayer getLeader() { + List ret = this.getMPlayersWhereRank(this.getLeaderRank()); + if (ret.size() == 0) { + return null; + } + return ret.get(0); + } + + public Set getMPlayerIds() { + return this.getMPlayers().stream().map(MPlayer::getId).collect(Collectors.toSet()); + } + + public List getOnlineCommandSenders() { + // Create Ret + List ret = new MassiveList<>(); + + // Fill Ret + for (CommandSender sender : IdUtil.getLocalSenders()) { + if (MUtil.isntSender(sender)) { + continue; + } + + MPlayer mplayer = MPlayer.get(sender); + if (mplayer.getFaction() != this) { + continue; + } + + ret.add(sender); + } + + // Return Ret + return ret; + } + + public List getOnlinePlayers() { + // Create Ret + List ret = new MassiveList<>(); + + // Fill Ret + for (Player player : Bukkit.getOnlinePlayers()) { + if (MUtil.isntPlayer(player)) { + continue; + } + + MPlayer mplayer = MPlayer.get(player); + if (mplayer.getFaction() != this) { + continue; + } + + ret.add(player); + } + + // Return Ret + return ret; + } + + // used when current leader is about to be removed from the faction; promotes new leader, or disbands faction if no other members left + public void promoteNewLeader() { + if (!this.isNormal()) { + return; + } + if (this.getFlag(MFlag.getFlagPermanent()) && MConf.get().permanentFactionsDisableLeaderPromotion) { + return; + } + + MPlayer oldLeader = this.getLeader(); + Rank leaderRank = oldLeader.getRank(); + + List replacements = Collections.emptyList(); + for (Rank rank = leaderRank; rank != null; rank = rank.getRankBelow()) { + //Skip first + if (rank == leaderRank) { + continue; + } + + replacements = this.getMPlayersWhereRank(rank); + if (!replacements.isEmpty()) { + break; + } + } + + // if we found a replacement + if (replacements == null || replacements.isEmpty()) { + // faction leader is the only member; one-man faction + if (this.getFlag(MFlag.getFlagPermanent())) { + if (oldLeader != null) { + oldLeader.setRank(this.getLeaderRank().getRankBelow()); + } + return; + } + + // no members left and faction isn't permanent, so disband it + if (MConf.get().logFactionDisband) { + Factions.get().log("The faction " + this.getName() + " (" + this.getId() + ") has been disbanded since it has no members left."); + } + + for (MPlayer mplayer : MPlayerColl.get().getAllOnline()) { + mplayer.msg("The faction %s was disbanded.", this.getName(mplayer)); + } + + this.detach(); + } else { + // promote new faction leader + if (oldLeader != null) { + oldLeader.setRank(this.getLeaderRank().getRankBelow()); + } + + replacements.get(0).setRank(this.getLeaderRank()); + this.msg("Faction leader %s has been removed. %s has been promoted as the new faction leader.", oldLeader == null ? "" : oldLeader.getName(), replacements.get(0).getName()); + Factions.get().log("Faction " + this.getName() + " (" + this.getId() + ") leader was removed. Replacement leader: " + replacements.get(0).getName()); + } + } + + // -------------------------------------------- // + // FACTION ONLINE STATE + // -------------------------------------------- // + + public boolean isAllMPlayersOffline() { + return this.getMPlayersWhereOnline(true).size() == 0; + } + + public boolean isAnyMPlayersOnline() { + return !this.isAllMPlayersOffline(); + } + + public boolean isFactionConsideredOffline() { + return this.isAllMPlayersOffline(); + } + + public boolean isFactionConsideredOnline() { + return !this.isFactionConsideredOffline(); + } + + public boolean isExplosionsAllowed() { + boolean explosions = this.getFlag(MFlag.getFlagExplosions()); + boolean offlineexplosions = this.getFlag(MFlag.getFlagOfflineexplosions()); + + if (explosions && offlineexplosions) { + return true; + } + if (!explosions && !offlineexplosions) { + return false; + } + + boolean online = this.isFactionConsideredOnline(); + + return (online && explosions) || (!online && offlineexplosions); + } + + // -------------------------------------------- // + // MESSAGES + // -------------------------------------------- // + // These methods are simply proxied in from the Mixin. + + // CONVENIENCE SEND MESSAGE + + public boolean sendMessage(Object message) { + return MixinMessage.get().messagePredicate(new PredicateCommandSenderFaction(this), message); + } + + public boolean sendMessage(Object... messages) { + return MixinMessage.get().messagePredicate(new PredicateCommandSenderFaction(this), messages); + } + + public boolean sendMessage(Collection messages) { + return MixinMessage.get().messagePredicate(new PredicateCommandSenderFaction(this), messages); + } + + // CONVENIENCE MSG + + public boolean msg(String msg) { + return MixinMessage.get().msgPredicate(new PredicateCommandSenderFaction(this), msg); + } + + public boolean msg(String msg, Object... args) { + return MixinMessage.get().msgPredicate(new PredicateCommandSenderFaction(this), msg, args); + } + + public boolean msg(Collection msgs) { + return MixinMessage.get().msgPredicate(new PredicateCommandSenderFaction(this), msgs); + } + + // -------------------------------------------- // + // UTIL + // -------------------------------------------- // + + // FIXME this probably needs to be moved elsewhere + public static String clean(String message) { + String target = message; + if (target == null) { + return null; + } + + target = target.trim(); + if (target.isEmpty()) { + target = null; + } + + return target; + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/FactionColl.java b/src/main/java/com/massivecraft/factions/entity/FactionColl.java new file mode 100644 index 00000000..1304a116 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/FactionColl.java @@ -0,0 +1,230 @@ +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 { + // -------------------------------------------- // + // 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> getRelationNames(Faction faction, Set rels) { + // Create + Map> 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 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 names = ret.get(Rel.TRUCE); + if (names == null) { + return ret; + } + + ret.put(Rel.TRUCE, Collections.singletonList(MConf.get().colorTruce.toString() + Txt.parse("*EVERYONE*"))); + + // Return + return ret; + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/Invitation.java b/src/main/java/com/massivecraft/factions/entity/Invitation.java new file mode 100644 index 00000000..9a1a6efb --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/Invitation.java @@ -0,0 +1,57 @@ +package com.massivecraft.factions.entity; + +import com.massivecraft.massivecore.store.EntityInternal; + +public class Invitation extends EntityInternal { + // -------------------------------------------- // + // OVERRIDE: ENTITY + // -------------------------------------------- // + + @Override + public Invitation load(Invitation that) { + this.inviterId = that.inviterId; + this.creationMillis = that.creationMillis; + + return this; + } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private String inviterId; + + public String getInviterId() { + return 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; + this.changed(); + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public Invitation() { + this(null, null); + } + + public Invitation(String inviterId, Long creationMillis) { + this.inviterId = inviterId; + this.creationMillis = creationMillis; + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/MConf.java b/src/main/java/com/massivecraft/factions/entity/MConf.java new file mode 100644 index 00000000..89ca195e --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/MConf.java @@ -0,0 +1,800 @@ +package com.massivecraft.factions.entity; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.Rel; +import com.massivecraft.factions.engine.EngineChat; +import com.massivecraft.factions.event.EventFactionsChunkChangeType; +import com.massivecraft.factions.integration.dynmap.DynmapStyle; +import com.massivecraft.factions.integration.dynmap.IntegrationDynmap; +import com.massivecraft.massivecore.collections.BackstringSet; +import com.massivecraft.massivecore.collections.MassiveSet; +import com.massivecraft.massivecore.collections.WorldExceptionSet; +import com.massivecraft.massivecore.command.editor.annotation.EditorName; +import com.massivecraft.massivecore.command.editor.annotation.EditorType; +import com.massivecraft.massivecore.command.editor.annotation.EditorTypeInner; +import com.massivecraft.massivecore.command.editor.annotation.EditorVisible; +import com.massivecraft.massivecore.command.type.TypeMillisDiff; +import com.massivecraft.massivecore.store.Entity; +import com.massivecraft.massivecore.util.MUtil; +import com.massivecraft.massivecore.util.TimeUnit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.EntityType; +import org.bukkit.event.EventPriority; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +@EditorName("config") +public class MConf extends Entity { + // -------------------------------------------- // + // META + // -------------------------------------------- // + + protected static transient MConf i; + + public static MConf get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE: ENTITY + // -------------------------------------------- // + + @Override + public MConf load(MConf that) { + super.load(that); + + // Reactivate EngineChat if currently active. + // This way some event listeners are registered with the correct priority based on the config. + EngineChat engine = EngineChat.get(); + if (engine.isActive()) { + engine.setActive(false); + engine.setActive(true); + } + + return this; + } + + // -------------------------------------------- // + // VERSION + // -------------------------------------------- // + + public int version = 5; + + // -------------------------------------------- // + // COMMAND ALIASES + // -------------------------------------------- // + + // Don't you want "f" as the base command alias? Simply change it here. + public List aliasesF = MUtil.list("f"); + + // -------------------------------------------- // + // WORLDS FEATURE ENABLED + // -------------------------------------------- // + + // Use this blacklist/whitelist system to toggle features on a per world basis. + // Do you only want claiming enabled on the one map called "Hurr"? + // In such case set standard to false and add "Hurr" as an exeption to worldsClaimingEnabled. + public WorldExceptionSet worldsClaimingEnabled = new WorldExceptionSet(); + public WorldExceptionSet worldsPowerLossEnabled = new WorldExceptionSet(); + public WorldExceptionSet worldsPowerGainEnabled = new WorldExceptionSet(); + + public WorldExceptionSet worldsPvpRulesEnabled = new WorldExceptionSet(); + + // -------------------------------------------- // + // DERPY OVERRIDES + // -------------------------------------------- // + + // Add player names here who should bypass all protections. + // Should /not/ be used for admins. There is "/f adminmode" for that. + // This is for other plugins/mods that use a fake player to take actions, which shouldn't be subject to our protections. + public Set playersWhoBypassAllProtection = new MassiveSet<>(); + + // -------------------------------------------- // + // REMOVE DATA + // -------------------------------------------- // + + // Should players be kicked from their faction and their data erased when banned? + public boolean removePlayerWhenBanned = true; + + // After how many milliseconds should players be automatically kicked from their faction? + + // The Default + @EditorType(TypeMillisDiff.class) + public long cleanInactivityToleranceMillis = 10 * TimeUnit.MILLIS_PER_DAY; // 10 days + + // Player Age Bonus + @EditorTypeInner({TypeMillisDiff.class, TypeMillisDiff.class}) + public Map cleanInactivityToleranceMillisPlayerAgeToBonus = MUtil.map( + 2 * TimeUnit.MILLIS_PER_WEEK, 10 * TimeUnit.MILLIS_PER_DAY // +10 days after 2 weeks + ); + + // Faction Age Bonus + @EditorTypeInner({TypeMillisDiff.class, TypeMillisDiff.class}) + public Map cleanInactivityToleranceMillisFactionAgeToBonus = MUtil.map( + 4 * TimeUnit.MILLIS_PER_WEEK, 10 * TimeUnit.MILLIS_PER_DAY, // +10 days after 4 weeks + 2 * TimeUnit.MILLIS_PER_WEEK, 5 * TimeUnit.MILLIS_PER_DAY // +5 days after 2 weeks + ); + + // -------------------------------------------- // + // DEFAULTS + // -------------------------------------------- // + + // Which faction should new players be followers of? + // "none" means Wilderness. Remember to specify the id, like "3defeec7-b3b1-48d9-82bb-2a8903df24e3" and not the name. + public String defaultPlayerFactionId = Factions.ID_NONE; + + // What power should the player start with? + public double defaultPlayerPower = 0.0; + + // -------------------------------------------- // + // MOTD + // -------------------------------------------- // + + // During which event priority should the faction message of the day be displayed? + // Choose between: LOWEST, LOW, NORMAL, HIGH, HIGHEST and MONITOR. + // This setting only matters if "motdDelayTicks" is set to -1 + public EventPriority motdPriority = EventPriority.NORMAL; + + // How many ticks should we delay the faction message of the day with? + // -1 means we don't delay at all. We display it at once. + // 0 means it's deferred to the upcoming server tick. + // 5 means we delay it yet another 5 ticks. + public int motdDelayTicks = -1; + + // -------------------------------------------- // + // POWER + // -------------------------------------------- // + + // What is the maximum player power? + public double powerMax = 10.0; + + // What is the minimum player power? + // NOTE: Negative minimum values is possible. + public double powerMin = 0.0; + + // How much power should be regained per hour online on the server? + public double powerPerHour = 2.0; + + // How much power should be lost on death? + public double powerPerDeath = -2.0; + + // Can players with negative power leave their faction? + // NOTE: This only makes sense to set to false if your "powerMin" setting is negative. + public boolean canLeaveWithNegativePower = true; + + // -------------------------------------------- // + // CORE + // -------------------------------------------- // + + // Is there a maximum amount of members per faction? + // 0 means there is not. If you set it to 100 then there can at most be 100 members per faction. + public int factionMemberLimit = 0; + + // Is there a maximum faction power cap? + // 0 means there is not. Set it to a positive value in case you wan't to use this feature. + public double factionPowerMax = 0.0; + + // Limit the length of faction names here. + public int factionNameLengthMin = 3; + public int factionNameLengthMax = 16; + + // -------------------------------------------- // + // SET LIMITS + // -------------------------------------------- // + + // When using radius setting of faction territory, what is the maximum radius allowed? + public int setRadiusMax = 30; + + // When using fill setting of faction territory, what is the maximum chunk count allowed? + public int setFillMax = 1000; + + // -------------------------------------------- // + // CLAIMS + // -------------------------------------------- // + + // Must claims be connected to each other? + // If you set this to false you will allow factions to claim more than one base per world map. + // That would makes outposts possible but also potentially ugly weird claims messing up your Dynmap and ingame experiance. + public boolean claimsMustBeConnected = true; + + // Must claims be connected to each other enforced strictly? + // If this is enabled there is also done a check on + // unclaim which makes sure you can't make two different bases by unclaiming land. + public boolean claimsMustBeConnectedStrict = false; + + // Would you like to allow unconnected claims when conquering land from another faction? + // Setting this to true would allow taking over someone elses base even if claims normally have to be connected. + // Note that even without this you can pillage/unclaim another factions territory in war. + // You just won't be able to take the land as your own. + public boolean claimsCanBeUnconnectedIfOwnedByOtherFaction = false; + + // Is claiming from other factions even allowed? + // Set this to false to disable territorial warfare altogether. + public boolean claimingFromOthersAllowed = true; + + // Is it required for factions to have an inflated land/power ratio in order to have their land conquered by another faction? + // Set this to false to allow factions to invade each other without requiring them to have an inflated land/power ratio.. + public boolean claimingFromOthersMustBeInflated = true; + + // Is a minimum distance (measured in chunks) to other factions required? + // 0 means the feature is disabled. + // Set the feature to 10 and there must be 10 chunks of wilderness between factions. + // Factions may optionally allow their allies to bypass this limit by configuring their faction permissions ingame themselves. + public int claimMinimumChunksDistanceToOthers = 0; + + // Do you need a minimum amount of faction members to claim land? + // 1 means just the faction leader alone is enough. + public int claimsRequireMinFactionMembers = 1; + + // Is there a maximum limit to chunks claimed? + // 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 + // -------------------------------------------- // + + public boolean protectionLiquidFlowEnabled = true; + + // Protects the faction land from piston extending/retracting + // through the denying of MPerm build + public boolean handlePistonProtectionThroughDenyBuild = true; + + // -------------------------------------------- // + // WARPS + // -------------------------------------------- // + + // 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 warps inside enemy territory. + public boolean warpsMustBeInClaimedTerritory = true; + + // And what faction warp should be used when a player types /f home + public String warpsHomeName = "home"; + + // 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; + + // Should players teleport to faction warp on death? + // Set this to true to override the default respawn location. + public boolean warpsTeleportToOnDeathActive = false; + + // And what 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 warpsTeleportToOnDeathPriority = EventPriority.NORMAL; + + // -------------------------------------------- // + // TERRITORY INFO + // -------------------------------------------- // + + public boolean territoryInfoTitlesDefault = true; + + public String territoryInfoTitlesMain = "{relcolor}{name}"; + public String territoryInfoTitlesSub = "{desc}"; + public int territoryInfoTitlesTicksIn = 5; + public int territoryInfoTitlesTicksStay = 60; + public int territoryInfoTitleTicksOut = 5; + + public String territoryInfoChat = " ~ {relcolor}{name} {desc}"; + + public boolean territoryAccessShowMessage = true; + + // -------------------------------------------- // + // ASSORTED + // -------------------------------------------- // + + // Set this to true if want to block the promotion of new leaders for permanent factions. + // I don't really understand the user case for this option. + public boolean permanentFactionsDisableLeaderPromotion = false; + + // How much health damage should a player take upon placing or breaking a block in a "pain build" territory? + // 2.0 means one heart. + public double actionDeniedPainAmount = 2.0D; + + // If you set this option to true then factionless players cant partake in PVP. + // It works in both directions. Meaning you must join a faction to hurt players and get hurt by players. + public boolean disablePVPForFactionlessPlayers = false; + + // If you set this option to true then factionless players cant damage each other. + // So two factionless can't PvP, but they can PvP with others if that is allowed. + public boolean enablePVPBetweenFactionlessPlayers = true; + + // Set this option to true to create an exception to the rule above. + // Players inside their own faction territory can then hurt facitonless players. + // This way you may "evict" factionless trolls messing around in your home base. + public boolean enablePVPAgainstFactionlessInAttackersLand = false; + + // Inside your own faction territory you take less damage. + // 0.1 means that you take 10% less damage at home. + public double territoryShieldFactor = 0.1D; + + // Make faction disbanding a confirmation thing + public boolean requireConfirmationForFactionDisbanding = true; + + // At what speed can players fly with /f fly? + public float flySpeed = 0.1f; + + // Will flying be disabled on pvp + public boolean flyDisableOnPvp = false; + + // -------------------------------------------- // + // DENY COMMANDS + // -------------------------------------------- // + + // A list of commands to block for members of permanent factions. + // I don't really understand the user case for this option. + public List denyCommandsPermanentFactionMember = new ArrayList<>(); + + // Lists of commands to deny depending on your relation to the current faction territory. + // You may for example not type /home (might be the plugin Essentials) in the territory of your enemies. + public Map> denyCommandsTerritoryRelation = MUtil.map( + Rel.ENEMY, MUtil.list( + // Essentials commands + "home", + "homes", + "sethome", + "createhome", + "tpahere", + "tpaccept", + "tpyes", + "tpa", + "call", + "tpask", + "warp", + "warps", + "spawn", + // Essentials e-alliases + "ehome", + "ehomes", + "esethome", + "ecreatehome", + "etpahere", + "etpaccept", + "etpyes", + "etpa", + "ecall", + "etpask", + "ewarp", + "ewarps", + "espawn", + // Essentials fallback alliases + "essentials:home", + "essentials:homes", + "essentials:sethome", + "essentials:createhome", + "essentials:tpahere", + "essentials:tpaccept", + "essentials:tpyes", + "essentials:tpa", + "essentials:call", + "essentials:tpask", + "essentials:warp", + "essentials:warps", + "essentials:spawn", + // Other plugins + "wtp", + "uspawn", + "utp", + "mspawn", + "mtp", + "fspawn", + "ftp", + "jspawn", + "jtp" + ), + Rel.NEUTRAL, new ArrayList(), + Rel.TRUCE, new ArrayList(), + Rel.ALLY, new ArrayList(), + Rel.FACTION, new ArrayList() + ); + + // The distance for denying the following commands. Set to -1 to disable. + public double denyCommandsDistance = -1; + + // Lists of commands to deny depending on your relation to a nearby enemy in the above distance. + public Map> denyCommandsDistanceRelation = MUtil.map( + Rel.ENEMY, MUtil.list( + "home" + ), + Rel.NEUTRAL, new ArrayList(), + Rel.TRUCE, new ArrayList(), + Rel.ALLY, new ArrayList(), + Rel.FACTION, new ArrayList() + ); + + // Allow bypassing the above setting when in these territories. + public List denyCommandsDistanceBypassIn = MUtil.list( + Rel.FACTION, + Rel.ALLY + ); + + // -------------------------------------------- // + // CHAT + // -------------------------------------------- // + + // Should Factions set the chat format? + // This should be kept at false if you use an external chat format plugin. + // If you are planning on running a more lightweight server you can set this to true. + public boolean chatSetFormat = true; + + // At which event priority should the chat format be set in such case? + // Choose between: LOWEST, LOW, NORMAL, HIGH and HIGHEST. + public EventPriority chatSetFormatAt = EventPriority.LOWEST; + + // What format should be set? + public String chatSetFormatTo = "<{factions_relcolor}§l{factions_roleprefix}§r{factions_relcolor}{factions_name|rp}§f%1$s> %2$s"; + + // Should the chat tags such as {factions_name} be parsed? + // NOTE: You can set this to true even with chatSetFormat = false. + // But in such case you must set the chat format using an external chat format plugin. + public boolean chatParseTags = true; + + // At which event priority should the faction chat tags be parsed in such case? + // Choose between: LOWEST, LOW, NORMAL, HIGH, HIGHEST. + public EventPriority chatParseTagsAt = EventPriority.LOW; + + // -------------------------------------------- // + // COLORS + // -------------------------------------------- // + + // Here you can alter the colors tied to certain faction relations and settings. + // You probably don't want to edit these to much. + // Doing so might confuse players that are used to Factions. + public ChatColor colorMember = ChatColor.GREEN; + public ChatColor colorAlly = ChatColor.DARK_PURPLE; + public ChatColor colorTruce = ChatColor.LIGHT_PURPLE; + public ChatColor colorNeutral = ChatColor.WHITE; + public ChatColor colorEnemy = ChatColor.RED; + + // This one is for example applied to SafeZone since that faction has the pvp flag set to false. + public ChatColor colorNoPVP = ChatColor.GOLD; + + // This one is for example applied to WarZone since that faction has the friendly fire flag set to true. + public ChatColor colorFriendlyFire = ChatColor.DARK_RED; + + // -------------------------------------------- // + // EXPLOITS + // -------------------------------------------- // + + public boolean handleExploitObsidianGenerators = true; + public boolean handleExploitEnderPearlClipping = true; + public boolean handleNetherPortalTrap = true; + + // -------------------------------------------- // + // UNSTUCK + // -------------------------------------------- // + + public int unstuckSeconds = 30; + public int unstuckChunkRadius = 10; + + // -------------------------------------------- // + // ENDER PEARL AND CHORUS FRUIT + // -------------------------------------------- // + + public boolean allowEnderPearlInEnemyTerritory = true; + public boolean allowEnderPearlInWildernessTerritory = true; + public boolean allowEnderPearlInOwnTerritory = true; + public boolean allowEnderPearlInOtherTerritory = true; + + public boolean allowChorusFruitInEnemyTerritory = true; + public boolean allowChorusFruitInWildernessTerritory = true; + public boolean allowChorusFruitInOwnTerritory = true; + public boolean allowChorusFruitInOtherTerritory = true; + + // -------------------------------------------- // + // LOGGING + // -------------------------------------------- // + + // Here you can disable logging of certain events to the server console. + + public boolean logFactionCreate = true; + public boolean logFactionDisband = true; + public boolean logFactionJoin = true; + public boolean logFactionKick = true; + public boolean logFactionLeave = true; + public boolean logLandClaims = true; + public boolean logMoneyTransactions = true; + + // -------------------------------------------- // + // TAX + // -------------------------------------------- // + + // Should the tax system be enabled? + public boolean taxEnabled = false; + + // How much can you tax a player? + public double taxPlayerMinimum = -10; + public double taxPlayerMaximum = 10; + + // How much should Factions be taxed? + //public double taxUpkeepBase = 0; + //public double taxUpkeepPerChunk = 1; + + // When is a player inactive? + public int taxInactiveDays = 3; + + // When the last run time was (in unix time) + // 0 means never + public long taxTaskLastMillis = 0; + + // Tax run when? + // 0 means at midnight UTC it can be offset by a certain millis + public long taxTaskInvocationOffsetMillis = 0; + + // How often should the task be run? + public long taxTaskPeriodMillis = TimeUnit.MILLIS_PER_DAY; + + // -------------------------------------------- // + // RANKS + // -------------------------------------------- // + + @EditorVisible(false) + public List defaultRanks = MUtil.list( + new Rank("Leader", 400, "**"), + new Rank("Officer", 300, "*"), + new Rank("Member", 200, "+"), + new Rank("Recruit", 100, "-") + ); + + // -------------------------------------------- // + // PERMISSIONS + // -------------------------------------------- // + + public Map> perm2default = MUtil.map( + MPerm.ID_BUILD, MUtil.set("LEADER", "OFFICER", "MEMBER"), + MPerm.ID_PAINBUILD, MUtil.set(), + MPerm.ID_DOOR, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), + MPerm.ID_BUTTON, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), + MPerm.ID_LEVER, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), + MPerm.ID_CONTAINER, MUtil.set("LEADER", "OFFICER", "MEMBER"), + + MPerm.ID_NAME, MUtil.set("LEADER"), + MPerm.ID_DESC, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_MOTD, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_INVITE, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_KICK, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_RANK, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_TITLE, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_WARP, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), + MPerm.ID_SETWARP, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_DEPOSIT, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY", "TRUCE", "NEUTRAL", "ENEMY"), + MPerm.ID_WITHDRAW, MUtil.set("LEADER"), + MPerm.ID_TERRITORY, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_ACCESS, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_VOTE, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT"), + MPerm.ID_CREATEVOTE, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_CLAIMNEAR, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), + MPerm.ID_TAX, MUtil.set("LEADER"), + MPerm.ID_REL, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_DISBAND, MUtil.set("LEADER"), + MPerm.ID_FLAGS, MUtil.set("LEADER"), + MPerm.ID_PERMS, MUtil.set("LEADER") + ); + + // -------------------------------------------- // + // ENUMERATIONS + // -------------------------------------------- // + // In this configuration section you can add support for Forge mods that add new Materials and EntityTypes. + // This way they can be protected in Faction territory. + // Use the "UPPER_CASE_NAME" for the Material or EntityType in question. + // If you are running a regular Spigot server you don't have to edit this section. + // In fact all of these sets can be empty on regular Spigot servers without any risk. + + // Interacting with these materials when they are already placed in the terrain results in an edit. + public BackstringSet materialsEditOnInteract = new BackstringSet<>(Material.class); + + // Interacting with the the terrain holding this item in hand results in an edit. + // There's no need to add all block materials here. Only special items other than blocks. + public BackstringSet materialsEditTools = new BackstringSet<>(Material.class); + + // Interacting with these materials placed in the terrain results in door toggling. + public BackstringSet materialsDoor = new BackstringSet<>(Material.class); + + // Interacting with these materials placed in the terrain results in opening a container. + public BackstringSet materialsContainer = new BackstringSet<>(Material.class); + + // Interacting with these entities results in an edit. + public BackstringSet entityTypesEditOnInteract = new BackstringSet<>(EntityType.class); + + // Damaging these entities results in an edit. + public BackstringSet entityTypesEditOnDamage = new BackstringSet<>(EntityType.class); + + // Interacting with these entities results in opening a container. + public BackstringSet entityTypesContainer = new BackstringSet<>(EntityType.class); + + // The complete list of entities considered to be monsters. + public BackstringSet entityTypesMonsters = new BackstringSet<>(EntityType.class); + + // List of entities considered to be animals. + public BackstringSet entityTypesAnimals = new BackstringSet<>(EntityType.class); + + // -------------------------------------------- // + // INTEGRATION: LWC + // -------------------------------------------- // + + // Do you need faction build rights in the territory to create an LWC protection there? + public boolean lwcMustHaveBuildRightsToCreate = true; + + // The config option above does not handle situations where a player creates an LWC protection in Faction territory and then leaves the faction. + // The player would then have an LWC protection in a territory where they can not build. + // Set this config option to true to enable an automatic removal feature. + // LWC protections that couldn't be created will be removed on an attempt to open them by any player. + public boolean lwcRemoveIfNoBuildRights = false; + + // WARN: Experimental and semi buggy. + // If you change this to true: alien LWC protections will be removed upon using /f set. + public Map lwcRemoveOnChange = MUtil.map( + EventFactionsChunkChangeType.BUY, false, // when claiming from wilderness + EventFactionsChunkChangeType.SELL, false, // when selling back to wilderness + EventFactionsChunkChangeType.CONQUER, false, // when claiming from another player faction + EventFactionsChunkChangeType.PILLAGE, false // when unclaiming (to wilderness) from another player faction + ); + + // -------------------------------------------- // + // INTEGRATION: WorldGuard + // -------------------------------------------- // + + // Global WorldGuard Integration Switch + public boolean worldguardCheckEnabled = false; + + // Enable the WorldGuard check per-world + // Specify which worlds the WorldGuard Check can be used in + public WorldExceptionSet worldguardCheckWorldsEnabled = new WorldExceptionSet(); + + // -------------------------------------------- // + // INTEGRATION: VentureChat + // -------------------------------------------- // + + public String ventureChatFactionChannelName = "faction"; + public String ventureChatAllyChannelName = "ally"; + public boolean ventureChatAllowFactionchatBetweenFactionless = false; + + // -------------------------------------------- // + // INTEGRATION: ECONOMY + // -------------------------------------------- // + + // Should economy features be enabled? + // This requires that you have the external plugin called "Vault" installed. + public boolean econEnabled = true; + + // When paying a cost you may specify an account that should receive the money here. + // Per default "" the money is just destroyed. + public String econUniverseAccount = ""; + + // What is the price per chunk when using /f set? + public Map econChunkCost = MUtil.map( + EventFactionsChunkChangeType.BUY, 1.0, // when claiming from wilderness + EventFactionsChunkChangeType.SELL, 0.0, // when selling back to wilderness + EventFactionsChunkChangeType.CONQUER, 0.0, // when claiming from another player faction + EventFactionsChunkChangeType.PILLAGE, 0.0 // when unclaiming (to wilderness) from another player faction + ); + + // What is the price to create a faction? + public double econCostCreate = 100.0; + + // And so on and so forth ... you get the idea. + 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 econCostWarpGo = 0.0; + public double econCostName = 0.0; + public double econCostDescription = 0.0; + public double econCostTitle = 0.0; + public double econCostFlag = 0.0; + + public Map econRelCost = MUtil.map( + Rel.ENEMY, 0.0, + Rel.ALLY, 0.0, + Rel.TRUCE, 0.0, + Rel.NEUTRAL, 0.0 + ); + + // Should the faction bank system be enabled? + // This enables the command /f money. + public boolean bankEnabled = true; + + // That costs should the faciton bank take care of? + // If you set this to false the player executing the command will pay instead. + public boolean bankFactionPaysCosts = true; + + public boolean useNewMoneySystem = false; + + // -------------------------------------------- // + // INTEGRATION: DYNMAP + // -------------------------------------------- // + + // Should the dynmap intagration be used? + public boolean dynmapEnabled = true; + + // Should the dynmap updates be logged to console output? + public boolean dynmapLogTimeSpent = false; + + // Name of the Factions layer + public String dynmapLayerName = "Factions"; + + // Should the layer be visible per default + public boolean dynmapLayerHiddenByDefault = false; + + // Ordering priority in layer menu (low goes before high - default is 0) + public int dynmapLayerPriority = 2; + + // (optional) set minimum zoom level before layer is visible (0 = defalt, always visible) + public int dynmapLayerMinimumZoom = 0; + + // Format for popup - substitute values for macros + //public String dynmapInfowindowFormat = "
%regionname%
Flags
%flags%
"; + public String dynmapFactionDescription = + "
\n" + + "%name%
\n" + + "%description%
\n" + + "
\n" + + "Leader: %players.leader%
\n" + + "Members: %players%
\n" + + "
\n" + + "Age: %age%
\n" + + "Bank: %money%
\n" + + "
\n" + + "Flags:
\n" + + "%flags.table3%\n" + + "
"; + + // Enable the %money% macro. Only do this if you know your economy manager is thread safe. + public boolean dynmapShowMoneyInDescription = false; + + // Allow players in faction to see one another on Dynmap (only relevant if Dynmap has 'player-info-protected' enabled) + //public boolean dynmapVisibilityByFaction = true; + + // Optional setting to limit which regions to show. + // If empty all regions are shown. + // Specify Faction either by name or UUID. + // To show all regions on a given world, add 'world:' to the list. + public Set dynmapVisibleFactions = new MassiveSet<>(); + + // Optional setting to hide specific Factions. + // Specify Faction either by name or UUID. + // To hide all regions on a given world, add 'world:' to the list. + public Set dynmapHiddenFactions = new MassiveSet<>(); + + @EditorVisible(false) + public DynmapStyle dynmapDefaultStyle = new DynmapStyle( + IntegrationDynmap.DYNMAP_STYLE_LINE_COLOR, + IntegrationDynmap.DYNMAP_STYLE_LINE_OPACITY, + IntegrationDynmap.DYNMAP_STYLE_LINE_WEIGHT, + IntegrationDynmap.DYNMAP_STYLE_FILL_COLOR, + IntegrationDynmap.DYNMAP_STYLE_FILL_OPACITY, + IntegrationDynmap.DYNMAP_STYLE_HOME_MARKER, + IntegrationDynmap.DYNMAP_STYLE_BOOST + ); + + // Optional per Faction style overrides. Any defined replace those in dynmapDefaultStyle. + // Specify Faction either by name or UUID. + @EditorVisible(false) + public Map dynmapFactionStyles = MUtil.map( + "SafeZone", new DynmapStyle().withLineColor("#FF00FF").withFillColor("#FF00FF").withBoost(false), + "WarZone", new DynmapStyle().withLineColor("#FF0000").withFillColor("#FF0000").withBoost(false) + ); +} diff --git a/src/main/java/com/massivecraft/factions/entity/MConfColl.java b/src/main/java/com/massivecraft/factions/entity/MConfColl.java new file mode 100644 index 00000000..c44a5cd2 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/MConfColl.java @@ -0,0 +1,39 @@ +package com.massivecraft.factions.entity; + +import com.massivecraft.massivecore.MassiveCore; +import com.massivecraft.massivecore.store.Coll; + +public class MConfColl extends Coll { + // -------------------------------------------- // + // 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); + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/MFlag.java b/src/main/java/com/massivecraft/factions/entity/MFlag.java new file mode 100644 index 00000000..b22fc11c --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/MFlag.java @@ -0,0 +1,431 @@ +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 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 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; + + // -------------------------------------------- // + // META: CORE + // -------------------------------------------- // + + public static MFlag get(Object oid) { + return MFlagColl.get().get(oid); + } + + public static List getAll() { + return getAll(Bukkit.isPrimaryThread()); + } + + public static List 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(); + } + + 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 for members in faction territory?", "Members can fly in faction territory.", "Members 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 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 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 = "YES"; + String no = monoSpace ? "NOO" : "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("%s", desc); + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/MFlagColl.java b/src/main/java/com/massivecraft/factions/entity/MFlagColl.java new file mode 100644 index 00000000..9b5bb712 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/MFlagColl.java @@ -0,0 +1,65 @@ +package com.massivecraft.factions.entity; + +import com.massivecraft.massivecore.store.Coll; + +import java.util.ArrayList; +import java.util.List; + +public class MFlagColl extends Coll { + // -------------------------------------------- // + // 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 getAll(boolean registered) { + // Create + List ret = new ArrayList<>(); + + // Fill + for (MFlag mflag : this.getAll()) { + if (mflag.isRegistered() != registered) { + continue; + } + ret.add(mflag); + } + + // Return + return ret; + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/MPerm.java b/src/main/java/com/massivecraft/factions/entity/MPerm.java new file mode 100644 index 00000000..29243515 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/MPerm.java @@ -0,0 +1,638 @@ +package com.massivecraft.factions.entity; + +import com.massivecraft.factions.AccessStatus; +import com.massivecraft.factions.Perm; +import com.massivecraft.factions.Rel; +import com.massivecraft.factions.TerritoryAccess; +import com.massivecraft.factions.cmd.CmdFactions; +import com.massivecraft.factions.event.EventFactionsCreatePerms; +import com.massivecraft.massivecore.Identified; +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.ps.PS; +import com.massivecraft.massivecore.store.Entity; +import com.massivecraft.massivecore.util.IdUtil; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Comparator; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +public class MPerm extends Entity implements Prioritized, Registerable, Named { + // -------------------------------------------- // + // CONSTANTS + // -------------------------------------------- // + + public final static transient String ID_BUILD = "build"; + public final static transient String ID_PAINBUILD = "painbuild"; + public final static transient String ID_DOOR = "door"; + public final static transient String ID_BUTTON = "button"; + public final static transient String ID_LEVER = "lever"; + public final static transient String ID_CONTAINER = "container"; + + public final static transient String ID_NAME = "name"; + public final static transient String ID_DESC = "desc"; + public final static transient String ID_MOTD = "motd"; + public final static transient String ID_INVITE = "invite"; + public final static transient String ID_KICK = "kick"; + public final static transient String ID_RANK = "rank"; + public final static transient String ID_TITLE = "title"; + public final static transient String ID_WARP = "warp"; + public final static transient String ID_SETWARP = "setwarp"; + public final static transient String ID_DEPOSIT = "deposit"; + public final static transient String ID_WITHDRAW = "withdraw"; + public final static transient String ID_TERRITORY = "territory"; + public final static transient String ID_ACCESS = "access"; + public final static transient String ID_VOTE = "VOTE"; // Why is this capitalised? Can that be easily changed? + public final static transient String ID_CREATEVOTE = "createvote"; + public final static transient String ID_CLAIMNEAR = "claimnear"; + public final static transient String ID_TAX = "tax"; + public final static transient String ID_REL = "rel"; + public final static transient String ID_DISBAND = "disband"; + public final static transient String ID_FLAGS = "flags"; + public final static transient String ID_PERMS = "perms"; + + public final static transient int PRIORITY_BUILD = 1000; + public final static transient int PRIORITY_PAINBUILD = 2000; + public final static transient int PRIORITY_DOOR = 3000; + public final static transient int PRIORITY_BUTTON = 4000; + public final static transient int PRIORITY_LEVER = 5000; + public final static transient int PRIORITY_CONTAINER = 6000; + + public final static transient int PRIORITY_NAME = 7000; + public final static transient int PRIORITY_DESC = 8000; + public final static transient int PRIORITY_MOTD = 9000; + public final static transient int PRIORITY_INVITE = 10000; + public final static transient int PRIORITY_KICK = 11000; + public final static transient int PRIORITY_RANK = 11500; + public final static transient int PRIORITY_TITLE = 12000; + public final static transient int PRIORITY_WARP = 13000; + public final static transient int PRIORITY_SETWARP = 14000; + public final static transient int PRIORITY_DEPOSIT = 15000; + public final static transient int PRIORITY_WITHDRAW = 16000; + public final static transient int PRIORITY_TERRITORY = 17000; + public final static transient int PRIORITY_ACCESS = 18000; + public final static transient int PRIORITY_VOTE = 18200; + public final static transient int PRIORITY_CREATEVOTE = 18600; + public final static transient int PRIORITY_CLAIMNEAR = 19000; + public final static transient int PRIORITY_TAX = 19500; + public final static transient int PRIORITY_REL = 20000; + public final static transient int PRIORITY_DISBAND = 21000; + public final static transient int PRIORITY_FLAGS = 22000; + public final static transient int PRIORITY_PERMS = 23000; + + // -------------------------------------------- // + // META: CORE + // -------------------------------------------- // + + public static MPerm get(Object oid) { + return MPermColl.get().get(oid); + } + + public static List getAll() { + return getAll(false); + } + + public static List getAll(boolean isAsync) { + setupStandardPerms(); + new EventFactionsCreatePerms().run(); + + return MPermColl.get().getAll(PredicateIsRegistered.get(), ComparatorSmart.get()); + } + + public static void setupStandardPerms() { + getPermBuild(); + getPermPainbuild(); + getPermDoor(); + getPermButton(); + getPermLever(); + getPermContainer(); + + getPermName(); + getPermDesc(); + getPermMotd(); + getPermInvite(); + getPermKick(); + getPermRank(); + getPermTitle(); + getPermWarp(); + getPermSetwarp(); + getPermDeposit(); + getPermWithdraw(); + getPermTerritory(); + getPermAccess(); + getPermVote(); + getPermCreateVote(); + getPermClaimnear(); + getPermTax(); + getPermRel(); + getPermDisband(); + getPermFlags(); + getPermPerms(); + } + + public static MPerm getPermBuild() { + return getCreative(PRIORITY_BUILD, ID_BUILD, ID_BUILD, "edit the terrain", true, true, true); + } + + public static MPerm getPermPainbuild() { + return getCreative(PRIORITY_PAINBUILD, ID_PAINBUILD, ID_PAINBUILD, "edit, take damage", true, true, true); + } + + public static MPerm getPermDoor() { + return getCreative(PRIORITY_DOOR, ID_DOOR, ID_DOOR, "use doors", true, true, true); + } + + public static MPerm getPermButton() { + return getCreative(PRIORITY_BUTTON, ID_BUTTON, ID_BUTTON, "use stone buttons", true, true, true); + } + + public static MPerm getPermLever() { + return getCreative(PRIORITY_LEVER, ID_LEVER, ID_LEVER, "use levers", true, true, true); + } + + public static MPerm getPermContainer() { + return getCreative(PRIORITY_CONTAINER, ID_CONTAINER, ID_CONTAINER, "use containers", true, true, true); + } + + public static MPerm getPermName() { + return getCreative(PRIORITY_NAME, ID_NAME, ID_NAME, "set name", false, true, true); + } + + public static MPerm getPermDesc() { + return getCreative(PRIORITY_DESC, ID_DESC, ID_DESC, "set description", false, true, true); + } + + public static MPerm getPermMotd() { + return getCreative(PRIORITY_MOTD, ID_MOTD, ID_MOTD, "set motd", false, true, true); + } + + public static MPerm getPermInvite() { + return getCreative(PRIORITY_INVITE, ID_INVITE, ID_INVITE, "invite players", false, true, true); + } + + public static MPerm getPermKick() { + return getCreative(PRIORITY_KICK, ID_KICK, ID_KICK, "kick members", false, true, true); + } + + public static MPerm getPermRank() { + return getCreative(PRIORITY_RANK, ID_RANK, ID_RANK, "change ranks", false, true, true); + } + + public static MPerm getPermTitle() { + return getCreative(PRIORITY_TITLE, ID_TITLE, ID_TITLE, "set titles", false, true, true); + } + + public static MPerm getPermWarp() { + return getCreative(PRIORITY_WARP, ID_WARP, ID_WARP, "teleport to warp", false, true, true); + } + + public static MPerm getPermSetwarp() { + return getCreative(PRIORITY_SETWARP, ID_SETWARP, ID_SETWARP, "set warps", false, true, true); + } + + public static MPerm getPermDeposit() { + return getCreative(PRIORITY_DEPOSIT, ID_DEPOSIT, ID_DEPOSIT, "deposit money", false, false, false); + } // non editable, non visible. + + public static MPerm getPermWithdraw() { + return getCreative(PRIORITY_WITHDRAW, ID_WITHDRAW, ID_WITHDRAW, "withdraw money", false, true, true); + } + + public static MPerm getPermTerritory() { + return getCreative(PRIORITY_TERRITORY, ID_TERRITORY, ID_TERRITORY, "claim or unclaim", false, true, true); + } + + public static MPerm getPermAccess() { + return getCreative(PRIORITY_ACCESS, ID_ACCESS, ID_ACCESS, "grant territory", false, true, true); + } + + public static MPerm getPermVote() { + return getCreative(PRIORITY_VOTE, ID_VOTE, ID_VOTE, "vote", false, true, true); + } + + public static MPerm getPermCreateVote() { + return getCreative(PRIORITY_CREATEVOTE, ID_CREATEVOTE, ID_CREATEVOTE, "manage votes", false, true, true); + } + + public static MPerm getPermClaimnear() { + return getCreative(PRIORITY_CLAIMNEAR, ID_CLAIMNEAR, ID_CLAIMNEAR, "claim nearby", false, false, false); + } // non editable, non visible. + + public static MPerm getPermTax() { + return getCreative(PRIORITY_TAX, ID_TAX, ID_TAX, "set taxes", false, true, true); + } + + public static MPerm getPermRel() { + return getCreative(PRIORITY_REL, ID_REL, ID_REL, "change relations", false, true, true); + } + + public static MPerm getPermDisband() { + return getCreative(PRIORITY_DISBAND, ID_DISBAND, ID_DISBAND, "disband the faction", false, true, true); + } + + public static MPerm getPermFlags() { + return getCreative(PRIORITY_FLAGS, ID_FLAGS, ID_FLAGS, "manage flags", false, true, true); + } + + public static MPerm getPermPerms() { + return getCreative(PRIORITY_PERMS, ID_PERMS, ID_PERMS, "manage permissions", false, true, true); + } + + public static MPerm getCreative(int priority, String id, String name, String desc, boolean territory, boolean editable, boolean visible) { + MPerm ret = MPermColl.get().get(id, false); + if (ret != null) { + ret.setRegistered(true); + return ret; + } + + ret = new MPerm(priority, name, desc, territory, editable, visible); + MPermColl.get().attach(ret, id); + ret.setRegistered(true); + ret.sync(); + + return ret; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public MPerm load(MPerm that) { + //System.out.println("Loading MPerm"); + this.priority = that.priority; + this.name = that.name; + this.desc = that.desc; + this.territory = that.territory; + 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; + } + + // -------------------------------------------- // + // VERSION + // -------------------------------------------- // + + public int version = 2; + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + // The sort priority. Low values appear first in sorted lists. + // 1 is high up, 99999 is far down. + // Standard Faction perms use "thousand values" like 1000, 2000, 3000 etc to allow adding new perms inbetween. + // So 1000 might sound like a lot but it's actually the priority for the first perm. + private int priority = 0; + + @Override + public int getPriority() { + return this.priority; + } + + public MPerm setPriority(int priority) { + this.priority = priority; + this.changed(); + return this; + } + + // The name of the perm. According to standard it should be fully lowercase just like the perm id. + // In fact the name and the id of all standard perms are the same. + // I just added the name in case anyone feel like renaming their perms for some reason. + // Example: "build" + private String name = "defaultName"; + + @Override + public String getName() { + return this.name; + } + + public MPerm setName(String name) { + this.name = name; + this.changed(); + return this; + } + + // The perm function described as an "order". + // The desc should match the format: + // "You are not allowed to X." + // "You are not allowed to edit the terrain." + // Example: "edit the terrain" + private String desc = "defaultDesc"; + + public String getDesc() { + return this.desc; + } + + public MPerm setDesc(String desc) { + this.desc = desc; + this.changed(); + return this; + } + + // What is the standard (aka default) perm value? + // This value will be set for factions from the beginning. + // Example: ... set of relations ... + //@Deprecated + //private Set standard = null; + //@Deprecated public Set getStandard() { return this.standard; } + //@Deprecated public MPerm setStandard(Set standard) { this.standard = standard; this.changed(); return this; } + + // Is this a territory perm meaning it has to do with territory construction, modification or interaction? + // True Examples: build, container, door, lever etc. + // False Examples: name, invite, home, sethome, deposit, withdraw etc. + private boolean territory = false; + + public boolean isTerritory() { + return this.territory; + } + + public MPerm setTerritory(boolean territory) { + this.territory = territory; + this.changed(); + return this; + } + + // Is this perm editable by players? + // With this we mean standard non administrator players. + // All perms can be changed using /f override. + // Example: true (all perms are editable by default) + private boolean editable = false; + + public boolean isEditable() { + return this.editable; + } + + public MPerm setEditable(boolean editable) { + this.editable = editable; + this.changed(); + return this; + } + + // Is this perm visible to players? + // With this we mean standard non administrator players. + // All perms can be seen using /f override. + // Some perms can be rendered meaningless by settings in Factions or external plugins. + // Say we set "editable" to false. + // In such case we might want to hide the perm by setting "visible" false. + // If it can't be changed, why bother showing it? + // Example: true (yeah we need to see this permission) + private boolean visible = true; + + public boolean isVisible() { + return this.visible; + } + + public MPerm setVisible(boolean visible) { + this.visible = visible; + this.changed(); + return this; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public MPerm() { + // No argument constructor for GSON + } + + public MPerm(int priority, String name, String desc, boolean territory, boolean editable, boolean visible) { + this.priority = priority; + this.name = name; + this.desc = desc; + this.territory = territory; + this.editable = editable; + this.visible = visible; + } + + // -------------------------------------------- // + // EXTRAS + // -------------------------------------------- // + + public String createDeniedMessage(MPlayer mplayer, Faction hostFaction) { + // Null Check + if (mplayer == null) { + throw new NullPointerException("mplayer"); + } + if (hostFaction == null) { + throw new NullPointerException("hostFaction"); + } + + String ret = Txt.parse("%s does not allow you to %s.", hostFaction.describeTo(mplayer, true), this.getDesc()); + + Player player = mplayer.getPlayer(); + if (player != null && Perm.OVERRIDE.has(player)) { + ret += Txt.parse("\nYou can bypass by using " + CmdFactions.get().cmdFactionsOverride.getTemplate(false).toPlain(true)); + } + + return ret; + } + + public String getDesc(boolean withName, boolean withDesc) { + List parts = new ArrayList<>(); + + if (withName) { + String nameFormat; + if (!this.isVisible()) { + nameFormat = "%s"; + } else if (this.isEditable()) { + nameFormat = "%s"; + } else { + nameFormat = "%s"; + } + String name = this.getName(); + String nameDesc = Txt.parse(nameFormat, name); + parts.add(nameDesc); + } + + if (withDesc) { + String desc = this.getDesc(); + + String descDesc = Txt.parse("%s", desc); + parts.add(descDesc); + } + + return Txt.implode(parts, " "); + } + + public boolean has(Faction faction, Faction hostFaction) { + // Null Check + if (faction == null) { + throw new NullPointerException("faction"); + } + if (hostFaction == null) { + throw new NullPointerException("hostFaction"); + } + + return hostFaction.isFactionPermitted(faction, this); + } + + public boolean has(MPlayer mplayer, Faction hostFaction, boolean verboose) { + // Null Check + if (mplayer == null) { + throw new NullPointerException("mplayer"); + } + if (hostFaction == null) { + throw new NullPointerException("hostFaction"); + } + + if (mplayer.isOverriding()) { + return true; + } + + Rel rel = mplayer.getRelationTo(hostFaction); + MPermable permable = rel == Rel.FACTION ? mplayer.getRank() : rel; + if (hostFaction.isPlayerPermitted(mplayer, this)) { + return true; + } + + if (verboose) { + mplayer.message(this.createDeniedMessage(mplayer, hostFaction)); + } + + return false; + } + + public boolean has(MPlayer mplayer, PS ps, boolean verboose) { + // Null Check + if (mplayer == null) { + throw new NullPointerException("mplayer"); + } + if (ps == null) { + throw new NullPointerException("ps"); + } + + if (mplayer.isOverriding()) { + return true; + } + + TerritoryAccess ta = BoardColl.get().getTerritoryAccessAt(ps); + Faction hostFaction = ta.getHostFaction(); + + if (this.isTerritory()) { + AccessStatus accessStatus = ta.getTerritoryAccess(mplayer); + if (accessStatus != AccessStatus.STANDARD) { + if (verboose && accessStatus == AccessStatus.DECREASED) { + mplayer.message(this.createDeniedMessage(mplayer, hostFaction)); + } + + return accessStatus.hasAccess(); + } + } + + return this.has(mplayer, hostFaction, verboose); + } + + // -------------------------------------------- // + // PERMABLES + // -------------------------------------------- // + + public static List getPermables(Faction faction) { + if (faction == null) { + throw new NullPointerException("faction"); + } + + List list = new MassiveList<>(); + + list.addAll(Arrays.asList(Rel.values())); + list.remove(Rel.FACTION); + + list.addAll(faction.getRanks().getAll(Comparator.comparingInt(Rank::getPriority))); + + return list; + } + + public interface MPermable extends Named, Identified { + default boolean isRelation() { + return this instanceof Rel; + } + + default boolean isRank() { + return this instanceof Rank; + } + + default String getShortName() { + return this.getName().substring(0, 3).toUpperCase(); + } + + String getDisplayName(Object senderObject); + } + + public static Set idsToMPermables(Collection ids) { + return ids.stream() + .map(MPerm::idToMPermable) + .collect(Collectors.toSet()); + } + + public static MPermable idToMPermable(String id) { + return idToMPermableOptional(id).orElseThrow(() -> new RuntimeException(id)); + } + + public static Optional idToMPermableOptional(String id) { + MPlayer mplayer = MPlayerColl.get().get(id, false); + if (mplayer != null) { + return Optional.of(mplayer); + } + + // Workaround for registered senders + // Players ussually have a power, which makes sure they are in the coll + if (IdUtil.getRegistryIdToSender().containsKey(id)) { + return Optional.of(MPlayerColl.get().get(id, true)); + } + + Faction faction = Faction.get(id); + if (faction != null) { + return Optional.of(faction); + } + + for (Faction f : FactionColl.get().getAll()) { + Rank rank = f.getRank(id); + if (rank != null) { + return Optional.of(rank); + } + } + + if (Rel.ALLY.name().equalsIgnoreCase(id)) { + return Optional.of(Rel.ALLY); + } + if (Rel.TRUCE.name().equalsIgnoreCase(id)) { + return Optional.of(Rel.TRUCE); + } + if (Rel.NEUTRAL.name().equalsIgnoreCase(id)) { + return Optional.of(Rel.NEUTRAL); + } + if (Rel.ENEMY.name().equalsIgnoreCase(id)) { + return Optional.of(Rel.ENEMY); + } + + return Optional.empty(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/MPermColl.java b/src/main/java/com/massivecraft/factions/entity/MPermColl.java new file mode 100644 index 00000000..f6be6ab3 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/MPermColl.java @@ -0,0 +1,101 @@ +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 { + // -------------------------------------------- // + // 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 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 getAll(boolean registered) { + // Create + List ret = new ArrayList<>(); + + // Fill + for (MPerm mperm : this.getAll()) { + if (mperm.isRegistered() != registered) { + continue; + } + ret.add(mperm); + } + + // Return + return ret; + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/MPlayer.java b/src/main/java/com/massivecraft/factions/entity/MPlayer.java new file mode 100644 index 00000000..a72fd0f1 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/MPlayer.java @@ -0,0 +1,906 @@ +package com.massivecraft.factions.entity; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.FactionsIndex; +import com.massivecraft.factions.FactionsParticipator; +import com.massivecraft.factions.Perm; +import com.massivecraft.factions.Rel; +import com.massivecraft.factions.RelationParticipator; +import com.massivecraft.factions.event.EventFactionsChunkChangeType; +import com.massivecraft.factions.event.EventFactionsChunksChange; +import com.massivecraft.factions.event.EventFactionsDisband; +import com.massivecraft.factions.event.EventFactionsMembershipChange; +import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; +import com.massivecraft.factions.mixin.PowerMixin; +import com.massivecraft.factions.util.AsciiMap; +import com.massivecraft.factions.util.RelationUtil; +import com.massivecraft.massivecore.mixin.MixinSenderPs; +import com.massivecraft.massivecore.mixin.MixinTitle; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.ps.PSFormatHumanSpace; +import com.massivecraft.massivecore.store.SenderEntity; +import com.massivecraft.massivecore.util.IdUtil; +import com.massivecraft.massivecore.util.MUtil; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.lang.ref.WeakReference; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map.Entry; +import java.util.Set; + +public class MPlayer extends SenderEntity implements FactionsParticipator, MPerm.MPermable { + // -------------------------------------------- // + // META + // -------------------------------------------- // + + public static final transient String NOTITLE = Txt.parse("no title set"); + + // -------------------------------------------- // + // META + // -------------------------------------------- // + + public static MPlayer get(Object oid) { + return MPlayerColl.get().get(oid); + } + + // -------------------------------------------- // + // VERSION + // -------------------------------------------- // + + public int version = 2; + + // -------------------------------------------- // + // LOAD + // -------------------------------------------- // + + @Override + public MPlayer load(MPlayer that) { + this.setLastActivityMillis(that.lastActivityMillis); + this.setFactionId(that.factionId); + this.rankId = that.rankId; + this.setTitle(that.title); + this.setPowerBoost(that.powerBoost); + this.setPower(that.power); + this.setMapAutoUpdating(that.mapAutoUpdating); + this.setOverriding(that.overriding); + this.setTerritoryInfoTitles(that.territoryInfoTitles); + + return this; + } + + // -------------------------------------------- // + // IS DEFAULT + // -------------------------------------------- // + + @Override + public boolean isDefault() { + // Last activity millis is data we use for clearing out cleanable players. So it does not in itself make the player data worth keeping. + if (this.hasFaction()) { + return false; + } + // Role means nothing without a faction. + // Title means nothing without a faction. + if (this.hasPowerBoost()) { + return false; + } + if (this.getPowerRounded() != (int) Math.round(MConf.get().defaultPlayerPower)) { + return false; + } + // if (this.isMapAutoUpdating()) return false; // Just having an auto updating map is not in itself reason enough for database storage. + if (this.isOverriding()) { + return false; + } + if (this.isTerritoryInfoTitles() != MConf.get().territoryInfoTitlesDefault) { + return false; + } + + return true; + } + + // -------------------------------------------- // + // UPDATE FACTION INDEXES + // -------------------------------------------- // + + @Override + public void postAttach(String id) { + FactionsIndex.get().update(this); + } + + @Override + public void postDetach(String id) { + //System.out.println("Detaching: " + id + " : " + this.getFactionId()); + FactionsIndex.get().update(this); + } + + @Override + public void preClean() { + if (this.getRank().isLeader()) { + this.getFaction().promoteNewLeader(); + } + + this.leave(); + } + + // -------------------------------------------- // + // FIELDS: RAW + // -------------------------------------------- // + // In this section of the source code we place the field declarations only. + // Each field has it's own section further down since just the getter and setter logic takes up quite some place. + + // The last known time of explicit player activity, such as login or logout. + // This value is most importantly used for removing cleanable players. + // For that reason it defaults to the current time. + // Really cleanable players will be considered newly active when upgrading Factions from 2.6 --> 2.7. + // There is actually more than one reason we store this data ourselves and don't use the OfflinePlayer#getLastPlayed. + // 1. I don't trust that method. It's been very buggy or even completely broken in previous Bukkit versions. + // 2. The method depends on the player.dat files being present. + // Server owners clear those files at times, or move their database data around between different servers. + private long lastActivityMillis = System.currentTimeMillis(); + + // This is a foreign key. + // Each player belong to a faction. + // Null means default. + private String factionId = null; + + // What role does the player have in the faction? + // Null means default. + private String rankId = null; + + // What title does the player have in the faction? + // The title is just for fun. It's not connected to any game mechanic. + // The player title is similar to the faction description. + // + // Question: Can the title contain chat colors? + // Answer: Yes but in such case the policy is that they already must be parsed using Txt.parse. + // If the title contains raw markup, such as "" instead of "§f" it will not be parsed and "" will be displayed. + // + // Null means the player has no title. + private String title = null; + + // Player usually do not have a powerboost. It defaults to 0. + // The powerBoost is a custom increase/decrease to default and maximum power. + // Note that player powerBoost and faction powerBoost are very similar. + private Double powerBoost = null; + + // Each player has an individual power level. + // The power level for online players is occasionally updated by a recurring task and the power should stay the same for offline players. + // For that reason the value is to be considered correct when you pick it. Do not call the power update method. + // Null means default. + private Double power = null; + + // Has this player requested an auto-updating ascii art map? + // Null means false + private Boolean mapAutoUpdating = null; + + // Is this player overriding? + // Null means false + private Boolean overriding = null; + + // Does this player use titles for territory info? + // Null means default specified in MConf. + private Boolean territoryInfoTitles = null; + + // Is the player doing faction flying? + private Boolean flying = null; + + // The Faction this player is currently autoclaiming for. + // Null means the player isn't auto claiming. + // NOTE: This field will not be saved to the database ever. + private transient WeakReference autoClaimFaction = new WeakReference<>(null); + + public Faction getAutoClaimFaction() { + if (this.isFactionOrphan()) { + return null; + } + Faction ret = this.autoClaimFaction.get(); + if (ret == null) { + return null; + } + if (ret.detached()) { + return null; + } + return ret; + } + + public void setAutoClaimFaction(Faction autoClaimFaction) { + this.autoClaimFaction = new WeakReference<>(autoClaimFaction); + } + + // Does the player have /f seechunk activated? + // NOTE: This field will not be saved to the database ever. + private transient boolean seeingChunk = false; + + public boolean isSeeingChunk() { + return this.seeingChunk; + } + + public void setSeeingChunk(boolean seeingChunk) { + this.seeingChunk = seeingChunk; + } + + // -------------------------------------------- // + // CORE UTILITIES + // -------------------------------------------- // + + public void resetFactionData() { + // The default neutral faction + this.setFactionId(null); + this.setRank(null); + this.setTitle(null); + this.setAutoClaimFaction(null); + } + + // -------------------------------------------- // + // FIELD: lastActivityMillis + // -------------------------------------------- // + + public long getLastActivityMillis() { + return this.lastActivityMillis; + } + + public void setLastActivityMillis(long lastActivityMillis) { + this.lastActivityMillis = convertSet(lastActivityMillis, this.lastActivityMillis, null); + } + + public void setLastActivityMillis() { + this.setLastActivityMillis(System.currentTimeMillis()); + } + + @Override + public boolean shouldBeCleaned(long now) { + return this.shouldBeCleaned(now, this.lastActivityMillis); + } + + // -------------------------------------------- // + // FIELD: factionId + // -------------------------------------------- // + + private Faction getFactionInternal() { + String effectiveFactionId = this.convertGet(this.factionId, MConf.get().defaultPlayerFactionId); + return Faction.get(effectiveFactionId); + } + + public boolean isFactionOrphan() { + return this.getFactionInternal() == null; + } + + @Deprecated + public String getFactionId() { + return this.getFaction().getId(); + } + + // This method never returns null + public Faction getFaction() { + Faction ret; + + ret = this.getFactionInternal(); + + // Adopt orphans + if (ret == null) { + ret = FactionColl.get().getNone(); + } + + return ret; + } + + public boolean hasFaction() { + return !this.getFaction().isNone(); + } + + // This setter is so long because it search for default/null case and takes + // care of updating the faction member index + public void setFactionId(String factionId) { + // Before + String beforeId = this.factionId; + + // After + String afterId = factionId; + + // NoChange + if (MUtil.equals(beforeId, afterId)) { + return; + } + + // Apply + this.factionId = afterId; + + // Index + FactionsIndex.get().update(this); + + // Mark as changed + this.changed(); + } + + public void setFaction(Faction faction) { + this.setFactionId(faction.getId()); + } + + // -------------------------------------------- // + // FIELD: role + // -------------------------------------------- // + + public Rank getRank() { + if (this.isFactionOrphan()) { + return FactionColl.get().getNone().getLowestRank(); + } + + if (this.rankId == null) { + return this.getFaction().getLowestRank(); + } + return this.getFaction().getRank(this.rankId); + } + + public void setRank(Rank rank) { + // Clean input + String rankId = rank == null ? null : rank.getId(); + + // Detect Nochange + if (MUtil.equals(this.rankId, rankId)) { + return; + } + + // Apply + this.rankId = rankId; + + // Mark as changed + this.changed(); + } + + // -------------------------------------------- // + // FIELD: title + // -------------------------------------------- // + // TODO: Improve upon the has and get stuff. + // TODO: Has should depend on get. Visualisation should be done elsewhere. + + public boolean hasTitle() { + return !this.isFactionOrphan() && this.title != null; + } + + public String getTitle() { + if (this.isFactionOrphan()) { + return NOTITLE; + } + + if (this.hasTitle()) { + return this.title; + } + + return NOTITLE; + } + + public void setTitle(String title) { + // Clean input + String target = Faction.clean(title); + + // Detect Nochange + if (MUtil.equals(this.title, target)) { + return; + } + + // Apply + this.title = target; + + // Mark as changed + this.changed(); + } + + // -------------------------------------------- // + // FIELD: powerBoost + // -------------------------------------------- // + + @Override + public double getPowerBoost() { + Double ret = this.powerBoost; + if (ret == null) { + ret = 0D; + } + return ret; + } + + @Override + public void setPowerBoost(Double powerBoost) { + // Clean input + Double target = powerBoost; + if (target == null || target == 0) { + target = null; + } + + // Detect Nochange + if (MUtil.equals(this.powerBoost, target)) { + return; + } + + // Apply + this.powerBoost = target; + + // Mark as changed + this.changed(); + } + + public boolean hasPowerBoost() { + return this.getPowerBoost() != 0D; + } + + // -------------------------------------------- // + // FIELD: power + // -------------------------------------------- // + + // MIXIN: RAW + + public double getPowerMaxUniversal() { + return PowerMixin.get().getMaxUniversal(this); + } + + public double getPowerMax() { + return PowerMixin.get().getMax(this); + } + + public double getPowerMin() { + return PowerMixin.get().getMin(this); + } + + public double getPowerPerHour() { + return PowerMixin.get().getPerHour(this); + } + + public double getPowerPerDeath() { + return PowerMixin.get().getPerDeath(this); + } + + // MIXIN: FINER + + public double getLimitedPower(double power) { + power = Math.max(power, this.getPowerMin()); + power = Math.min(power, this.getPowerMax()); + + return power; + } + + public int getPowerMaxRounded() { + return (int) Math.round(this.getPowerMax()); + } + + public int getPowerMinRounded() { + return (int) Math.round(this.getPowerMin()); + } + + public int getPowerMaxUniversalRounded() { + return (int) Math.round(this.getPowerMaxUniversal()); + } + + // RAW + + @Deprecated + public double getDefaultPower() { + return MConf.get().defaultPlayerPower; + } + + public double getPower() { + Double ret = this.power; + if (ret == null) { + ret = MConf.get().defaultPlayerPower; + } + ret = this.getLimitedPower(ret); + return ret; + } + + public void setPower(Double power) { + // Clean input + Double target = power; + + // Detect Nochange + if (MUtil.equals(this.power, target)) { + return; + } + + // Apply + this.power = target; + + // Mark as changed + this.changed(); + } + + // FINER + + public int getPowerRounded() { + return (int) Math.round(this.getPower()); + } + + // -------------------------------------------- // + // FIELD: mapAutoUpdating + // -------------------------------------------- // + + public boolean isMapAutoUpdating() { + if (this.mapAutoUpdating == null) { + return false; + } + if (this.mapAutoUpdating == false) { + return false; + } + return true; + } + + public void setMapAutoUpdating(Boolean mapAutoUpdating) { + // Clean input + Boolean target = mapAutoUpdating; + if (MUtil.equals(target, false)) { + target = null; + } + + // Detect Nochange + if (MUtil.equals(this.mapAutoUpdating, target)) { + return; + } + + // Apply + this.mapAutoUpdating = target; + + // Mark as changed + this.changed(); + } + + // -------------------------------------------- // + // FIELD: overriding + // -------------------------------------------- // + + public boolean isOverriding() { + if (this.overriding == null) { + return false; + } + if (this.overriding == false) { + return false; + } + + if (!this.hasPermission(Perm.OVERRIDE, true)) { + this.setOverriding(false); + return false; + } + + return true; + } + + public void setOverriding(Boolean overriding) { + // Clean input + Boolean target = overriding; + if (MUtil.equals(target, false)) { + target = null; + } + + // Detect Nochange + if (MUtil.equals(this.overriding, target)) { + return; + } + + // Apply + this.overriding = target; + + // Mark as changed + this.changed(); + } + + // -------------------------------------------- // + // FIELD: territoryInfoTitles + // -------------------------------------------- // + + public boolean isTerritoryInfoTitles() { + if (!MixinTitle.get().isAvailable()) { + return false; + } + if (this.territoryInfoTitles == null) { + return MConf.get().territoryInfoTitlesDefault; + } + return this.territoryInfoTitles; + } + + public void setTerritoryInfoTitles(Boolean territoryInfoTitles) { + // Clean input + Boolean target = territoryInfoTitles; + if (MUtil.equals(target, MConf.get().territoryInfoTitlesDefault)) { + target = null; + } + + // Detect Nochange + if (MUtil.equals(this.territoryInfoTitles, target)) { + return; + } + + // Apply + this.territoryInfoTitles = target; + + // Mark as changed + this.changed(); + } + + // -------------------------------------------- // + // FIELD: fly + // -------------------------------------------- // + + public boolean isFlying() { + return this.convertGet(this.flying, false, Perm.FLY); + } + + public void setFlying(Boolean flying) { + this.flying = this.convertSet(flying, this.flying, false); + } + + // -------------------------------------------- // + // TITLE, NAME, FACTION NAME AND CHAT + // -------------------------------------------- // + + public String getFactionName() { + Faction faction = this.getFaction(); + if (faction.isNone()) { + return ""; + } + return faction.getName(); + } + + // Base concatenations: + + public String getNameAndSomething(String color, String something) { + String ret = ""; + ret += color; + ret += this.getRank().getPrefix(); + if (something != null && something.length() > 0) { + ret += something; + ret += " "; + ret += color; + } + ret += this.getName(); + return ret; + } + + public String getNameAndFactionName() { + return this.getNameAndSomething("", this.getFactionName()); + } + + public String getNameAndTitle(String color) { + if (this.hasTitle()) { + return this.getNameAndSomething(color, this.getTitle()); + } else { + return this.getNameAndSomething(color, null); + } + } + + // Colored concatenations: + // These are used in information messages + + public String getNameAndTitle(Faction faction) { + return this.getNameAndTitle(this.getColorTo(faction).toString()); + } + + public String getNameAndTitle(MPlayer mplayer) { + return this.getNameAndTitle(this.getColorTo(mplayer).toString()); + } + + // -------------------------------------------- // + // RELATION AND RELATION COLORS + // -------------------------------------------- // + + @Override + public String describeTo(RelationParticipator observer, boolean ucfirst) { + return RelationUtil.describeThatToMe(this, observer, ucfirst); + } + + @Override + public String describeTo(RelationParticipator observer) { + return RelationUtil.describeThatToMe(this, observer); + } + + @Override + public Rel getRelationTo(RelationParticipator observer) { + return RelationUtil.getRelationOfThatToMe(this, observer); + } + + @Override + public Rel getRelationTo(RelationParticipator observer, boolean ignorePeaceful) { + return RelationUtil.getRelationOfThatToMe(this, observer, ignorePeaceful); + } + + @Override + public ChatColor getColorTo(RelationParticipator observer) { + return RelationUtil.getColorOfThatToMe(this, observer); + } + + // -------------------------------------------- // + // HEALTH + // -------------------------------------------- // + + public void heal(int amnt) { + Player player = this.getPlayer(); + if (player == null) { + return; + } + player.setHealth(player.getHealth() + amnt); + } + + // -------------------------------------------- // + // TERRITORY + // -------------------------------------------- // + + public boolean isInOwnTerritory() { + PS ps = MixinSenderPs.get().getSenderPs(this.getId()); + if (ps == null) { + return false; + } + return BoardColl.get().getFactionAt(ps) == this.getFaction(); + } + + public boolean isInEnemyTerritory() { + PS ps = MixinSenderPs.get().getSenderPs(this.getId()); + if (ps == null) { + return false; + } + return BoardColl.get().getFactionAt(ps).getRelationTo(this) == Rel.ENEMY; + } + + // -------------------------------------------- // + // ACTIONS + // -------------------------------------------- // + + public void leave() { + Faction myFaction = this.getFaction(); + + boolean permanent = myFaction.getFlag(MFlag.getFlagPermanent()); + + if (myFaction.getMPlayers().size() > 1) { + if (!permanent && this.getRank().isLeader()) { + msg("You must give the leader role to someone else first."); + return; + } + + if (!MConf.get().canLeaveWithNegativePower && this.getPower() < 0) { + msg("You cannot leave until your power is positive."); + return; + } + } + + // Event + EventFactionsMembershipChange membershipChangeEvent = new EventFactionsMembershipChange(this.getSender(), this, myFaction, MembershipChangeReason.LEAVE); + membershipChangeEvent.run(); + if (membershipChangeEvent.isCancelled()) { + return; + } + + if (myFaction.isNormal()) { + for (MPlayer mplayer : myFaction.getMPlayersWhereOnline(true)) { + mplayer.msg("%s left %s.", this.describeTo(mplayer, true), myFaction.describeTo(mplayer)); + } + + if (MConf.get().logFactionLeave) { + Factions.get().log(this.getName() + " left the faction: " + myFaction.getName()); + } + } + + this.resetFactionData(); + + if (myFaction.isNormal() && !permanent && myFaction.getMPlayers().isEmpty()) { + EventFactionsDisband eventFactionsDisband = new EventFactionsDisband(this.getSender(), myFaction); + eventFactionsDisband.run(); + if (!eventFactionsDisband.isCancelled()) { + // Remove this faction + this.msg("%s was disbanded since you were the last player.", myFaction.describeTo(this, true)); + if (MConf.get().logFactionDisband) { + Factions.get().log("The faction " + myFaction.getName() + " (" + myFaction.getId() + ") was disbanded due to the last player (" + this.getName() + ") leaving."); + } + myFaction.detach(); + } + } + } + + // NEW + public boolean tryClaim(Faction newFaction, Collection pss) { + return this.tryClaim(newFaction, pss, null, null); + } + + public boolean tryClaim(Faction newFaction, Collection pss, String formatOne, String formatMany) { + // Args + if (formatOne == null) { + formatOne = "%s %s %d chunk %s."; + } + if (formatMany == null) { + formatMany = "%s %s %d chunks near %s."; + } + + if (newFaction == null) { + throw new NullPointerException("newFaction"); + } + + if (pss == null) { + throw new NullPointerException("pss"); + } + final Set chunks = PS.getDistinctChunks(pss); + + // NoChange + // We clean the chunks further by removing what does not change. + // This is also very suggested cleaning of EventFactionsChunksChange input. + Iterator iter = chunks.iterator(); + chunks.removeIf(chunk -> BoardColl.get().getFactionAt(chunk) == newFaction); + if (chunks.isEmpty()) { + msg("%s already owns this land.", newFaction.describeTo(this, true)); + return true; + } + + // Event + // NOTE: We listen to this event ourselves at LOW. + // NOTE: That is where we apply the standard checks. + CommandSender sender = this.getSender(); + if (sender == null) { + msg("ERROR: Your \"CommandSender Link\" has been severed."); + msg("It's likely that you are using Cauldron."); + msg("We do currently not support Cauldron."); + msg("We would love to but lack time to develop support ourselves."); + msg("Do you know how to code? Please send us a pull request <3, sorry."); + return false; + } + EventFactionsChunksChange event = new EventFactionsChunksChange(sender, chunks, newFaction); + event.run(); + if (event.isCancelled()) { + return false; + } + + // Apply + for (PS chunk : chunks) { + BoardColl.get().setFactionAt(chunk, newFaction); + } + + // Inform + for (Entry> entry : event.getOldFactionChunks().entrySet()) { + final Faction oldFaction = entry.getKey(); + final Set oldChunks = entry.getValue(); + final PS oldChunk = oldChunks.iterator().next(); + final Set informees = getClaimInformees(this, oldFaction, newFaction); + final EventFactionsChunkChangeType type = EventFactionsChunkChangeType.get(oldFaction, newFaction, this.getFaction()); + + String chunkString = oldChunk.toString(PSFormatHumanSpace.get()); + String typeString = type.past; + + if (!AsciiMap.showChunkCoords(oldChunk)) { + chunkString = ""; + formatMany = formatMany.replace(" near ", ""); + } + + for (MPlayer informee : informees) { + informee.msg((oldChunks.size() == 1 ? formatOne : formatMany), this.describeTo(informee, true), typeString, oldChunks.size(), chunkString); + informee.msg(" %s --> %s", oldFaction.describeTo(informee, true), newFaction.describeTo(informee, true)); + } + } + + // Success + return true; + } + + // -------------------------------------------- // + // UTIL + // -------------------------------------------- // + + public static Set getClaimInformees(MPlayer msender, Faction... factions) { + Set ret = new HashSet<>(); + + if (msender != null) { + ret.add(msender); + } + + for (Faction faction : factions) { + if (faction == null) { + continue; + } + if (faction.isNone()) { + continue; + } + ret.addAll(faction.getMPlayers()); + } + + if (MConf.get().logLandClaims) { + ret.add(MPlayer.get(IdUtil.getConsole())); + } + + return ret; + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/MPlayerColl.java b/src/main/java/com/massivecraft/factions/entity/MPlayerColl.java new file mode 100644 index 00000000..097db452 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/MPlayerColl.java @@ -0,0 +1,38 @@ +package com.massivecraft.factions.entity; + +import com.massivecraft.massivecore.store.SenderColl; + +public class MPlayerColl extends SenderColl { + // -------------------------------------------- // + // 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; + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/Rank.java b/src/main/java/com/massivecraft/factions/entity/Rank.java new file mode 100644 index 00000000..cffd14b4 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/Rank.java @@ -0,0 +1,202 @@ +package com.massivecraft.factions.entity; + +import com.massivecraft.massivecore.store.EntityInternal; +import com.massivecraft.massivecore.store.EntityInternalMap; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.ChatColor; + +import java.util.Map.Entry; +import java.util.Set; + +public class Rank extends EntityInternal implements MPerm.MPermable { + // -------------------------------------------- // + // OVERRIDE: ENTITY + // -------------------------------------------- // + + @Override + public Rank load(Rank that) { + this.name = that.name; + + return this; + } + + @Override + public void preDetach(String id) { + for (Faction f : FactionColl.get().getAll()) { + for (Entry> entry : f.getPerms().entrySet()) { + Set value = entry.getValue(); + if (value == null) { + throw new NullPointerException(entry.getKey()); + } + value.remove(id); + } + } + } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private String name; + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + this.changed(); + } + + private int priority; + + public int getPriority() { + return this.priority; + } + + public void setPriority(int priority) { + this.priority = priority; + this.changed(); + } + + private String prefix; + + public String getPrefix() { + return this.prefix; + } + + public void setPrefix(String prefix) { + this.prefix = prefix; + this.changed(); + } + + public Faction getFaction() { + EntityInternalMap internalMap = (EntityInternalMap) this.getContainer(); + return (Faction) internalMap.getEntity(); + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + // For GSON + private Rank() { + this(null, 0, ""); + } + + public Rank(String name, int priority, String prefix) { + this.name = name; + this.priority = priority; + this.prefix = prefix; + } + + public Rank copy() { + return new Rank(this.name, this.priority, this.prefix); + } + + // -------------------------------------------- // + // VISUAL + // -------------------------------------------- // + + @Override + public String getDisplayName(Object senderObject) { + String ret = this.getVisual(); + ret += Txt.parse(" of ") + this.getFaction().getDisplayName(senderObject); + return ret; + } + + public String getVisual() { + String ret = ""; + ret += ChatColor.GREEN.toString(); + ret += this.getPrefix(); + ret += this.getName(); + ret += " (" + this.getPriority() + ")"; + return ret; + } + + // -------------------------------------------- // + // RANK PRIORITY + // -------------------------------------------- // + + public boolean isLessThan(Rank otherRank) { + if (this.getContainer() != otherRank.getContainer()) { + throw new IllegalArgumentException(this.getId() + " : " + otherRank.getId()); + } + + return this.getPriority() < otherRank.getPriority(); + } + + public boolean isMoreThan(Rank otherRank) { + if (this.getContainer() != otherRank.getContainer()) { + throw new IllegalArgumentException(this.getId() + " : " + otherRank.getId()); + } + + return this.getPriority() > otherRank.getPriority(); + } + + public boolean isAtLeast(Rank otherRank) { + if (this.getContainer() != otherRank.getContainer()) { + throw new IllegalArgumentException(this.getId() + " : " + otherRank.getId()); + } + + return this.getPriority() >= otherRank.getPriority(); + } + + public boolean isAtMost(Rank otherRank) { + if (this.getContainer() != otherRank.getContainer()) { + throw new IllegalArgumentException(this.getId() + " : " + otherRank.getId()); + } + + return this.getPriority() <= otherRank.getPriority(); + } + + public boolean isLeader() { + for (Rank otherRank : this.getContainer().getAll()) { + if (otherRank == this) { + continue; + } + + if (otherRank.isMoreThan(this)) { + return false; + } + } + return true; + } + + public Rank getRankAbove() { + Rank ret = null; + for (Rank otherRank : this.getContainer().getAll()) { + if (otherRank == this) { + continue; + } + if (otherRank.isLessThan(this)) { + continue; + } + if (ret != null && ret.isLessThan(otherRank)) { + continue; + } + + ret = otherRank; + } + return ret; + } + + public Rank getRankBelow() { + Rank ret = null; + for (Rank otherRank : this.getContainer().getAll()) { + if (otherRank == this) { + continue; + } + if (otherRank.isMoreThan(this)) { + continue; + } + if (ret != null && ret.isMoreThan(otherRank)) { + continue; + } + + ret = otherRank; + } + return ret; + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/Vote.java b/src/main/java/com/massivecraft/factions/entity/Vote.java new file mode 100644 index 00000000..aa54c58d --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/Vote.java @@ -0,0 +1,138 @@ +package com.massivecraft.factions.entity; + +import com.massivecraft.massivecore.Named; +import com.massivecraft.massivecore.collections.MassiveMap; +import com.massivecraft.massivecore.store.EntityInternal; +import com.massivecraft.massivecore.store.EntityInternalMap; + +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +public class Vote extends EntityInternal implements Named { + // -------------------------------------------- // + // OVERRIDE: ENTITY + // -------------------------------------------- // + + @Override + public Vote load(Vote that) { + this.creatorId = that.creatorId; + this.creationMillis = that.creationMillis; + this.options = that.options; + this.id2Vote = that.id2Vote; + + return this; + } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private String creatorId; + + public String getCreatorId() { + return this.creatorId; + } + + private long creationMillis; + + public long getCreationMillis() { + return this.creationMillis; + } + + private String name; + + @Override + public String getName() { + return this.name; + } + + private List options; + + public List getOptions() { + return this.options; + } + + private Map id2Vote; + + public Map getId2Vote() { + return id2Vote; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + // For GSON + private Vote() { + this(null, 0, null, null); + } + + public Vote(String creatorId, String name, List options) { + this(creatorId, System.currentTimeMillis(), name, options); + } + + public Vote(String creatorId, long creationMillis, String name, List options) { + this.creatorId = creatorId; + this.creationMillis = creationMillis; + this.name = name; + this.options = options; + this.id2Vote = new MassiveMap<>(); + } + + // -------------------------------------------- // + // OTHER + // -------------------------------------------- // + + public void setVote(MPlayer mplayer, String choice) { + if (mplayer == null) { + throw new NullPointerException("mplayer"); + } + if (choice == null) { + throw new NullPointerException("choice"); + } + + if (!this.getOptions().contains(choice)) { + throw new IllegalArgumentException(choice + " is not in " + this.getOptions()); + } + + id2Vote.put(mplayer.getId(), choice); + this.changed(); + } + + public String getVote(MPlayer mplayer) { + if (mplayer == null) { + throw new NullPointerException("mplayer"); + } + + return this.getId2Vote().get(mplayer.getId()); + } + + public Faction getFaction() { + EntityInternalMap internalMap = (EntityInternalMap) this.getContainer(); + return (Faction) internalMap.getEntity(); + } + + public void clean() { + Faction faction = this.getFaction(); + for (Iterator> it = this.id2Vote.entrySet().iterator(); it.hasNext(); ) { + Entry entry = it.next(); + String id = entry.getKey(); + + // MPlayer must be a member + if (!faction.getMPlayerIds().contains(id)) { + it.remove(); + break; + } + + // And they must have the perm + MPlayer mplayer = MPlayer.get(id); + if (!MPerm.getPermVote().has(mplayer, faction, false)) { + it.remove(); + break; + } + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/Warp.java b/src/main/java/com/massivecraft/factions/entity/Warp.java new file mode 100644 index 00000000..4e6bcfb3 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/Warp.java @@ -0,0 +1,106 @@ +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(); + return (Faction) internalMap.getEntity(); + } + + // -------------------------------------------- // + // 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; + } + Faction fac = this.getFaction(); + this.detach(); + fac.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/main/java/com/massivecraft/factions/entity/migrator/MigratorFaction001Invitations.java b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorFaction001Invitations.java new file mode 100644 index 00000000..e8aabfd9 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorFaction001Invitations.java @@ -0,0 +1,68 @@ +package com.massivecraft.factions.entity.migrator; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.massivecore.store.migrator.MigratorFieldConvert; +import com.massivecraft.massivecore.store.migrator.MigratorFieldRename; +import com.massivecraft.massivecore.store.migrator.MigratorRoot; + +public class MigratorFaction001Invitations extends MigratorRoot { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static com.massivecraft.factions.entity.migrator.MigratorFaction001Invitations i = new com.massivecraft.factions.entity.migrator.MigratorFaction001Invitations(); + + public static com.massivecraft.factions.entity.migrator.MigratorFaction001Invitations get() { + return i; + } + + private MigratorFaction001Invitations() { + super(Faction.class); + this.addInnerMigrator(MigratorFieldRename.get("invitedPlayerIds", "invitations")); + this.addInnerMigrator(new MigratorFaction001InvitationsField()); + } + + public class MigratorFaction001InvitationsField extends MigratorFieldConvert { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + private MigratorFaction001InvitationsField() { + super("invitations"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + public Object migrateInner(JsonElement idList) { + JsonObject ret = new JsonObject(); + //EntityInternalMap ret = new EntityInternalMap<>(null, Invitation.class); + + // If non-null + if (!idList.isJsonNull()) { + // ... and proper type ... + if (!idList.isJsonArray()) { + throw new IllegalArgumentException(idList.toString()); + } + + // ... fill! + for (JsonElement playerId : idList.getAsJsonArray()) { + String id = playerId.getAsString(); + + // Create invitation + JsonObject invitation = new JsonObject(); + + // Attach + ret.add(id, invitation); + } + } + + return ret; + } + + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/migrator/MigratorFaction002Ranks.java b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorFaction002Ranks.java new file mode 100644 index 00000000..97312488 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorFaction002Ranks.java @@ -0,0 +1,128 @@ +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.MConf; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.Rank; +import com.massivecraft.massivecore.MassiveCore; +import com.massivecraft.massivecore.collections.MassiveMap; +import com.massivecraft.massivecore.collections.MassiveSet; +import com.massivecraft.massivecore.store.MStore; +import com.massivecraft.massivecore.store.migrator.MigratorRoot; + +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +public class MigratorFaction002Ranks extends MigratorRoot { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MigratorFaction002Ranks i = new MigratorFaction002Ranks(); + + public static MigratorFaction002Ranks get() { + return i; + } + + private MigratorFaction002Ranks() { + super(Faction.class); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void migrateInner(JsonObject entity) { + String idLeader = MStore.createId(); + String idOfficer = MStore.createId(); + String idMember = MStore.createId(); + String idRecruit = MStore.createId(); + + Rank leader = new Rank("Leader", 400, "**"); + Rank officer = new Rank("Officer", 300, "*"); + Rank member = new Rank("Member", 200, "+"); + Rank recruit = new Rank("Recruit", 100, "-"); + + Map map = new MassiveMap<>(); + map.put(idLeader, leader); + map.put(idOfficer, officer); + map.put(idMember, member); + map.put(idRecruit, recruit); + + JsonElement jsonMap = MassiveCore.gson.toJsonTree(map, (new TypeToken>() { + }).getType()); + entity.add("ranks", jsonMap); + + JsonElement priorPerms = entity.get("perms"); + Map> newPerms = getPerms(priorPerms, idLeader, idOfficer, idMember, idRecruit); + + JsonElement jsonPerms = MassiveCore.gson.toJsonTree(newPerms, (new TypeToken>>() { + }).getType()); + entity.add("perms", jsonPerms); + } + + private Map> getPerms(JsonElement priorPerms, String leaderId, String officerId, String memberId, String recruitId) { + // We start with default values ... + Map> ret = new MassiveMap<>(); + for (MPerm mperm : MPerm.getAll()) { + // This should work since MConf and MPerm is loaded /before/ Factions + //Set value = new MassiveSet<>(mperm.getStandard()); + Set value = new MassiveSet<>(MConf.get().perm2default.get(mperm.getId())); + + if (value.remove("LEADER")) { + value.add(leaderId); + } + if (value.remove("OFFICER")) { + value.add(officerId); + } + if (value.remove("MEMBER")) { + value.add(memberId); + } + if (value.remove("RECRUIT")) { + value.add(recruitId); + } + ret.put(mperm.getId(), value); + } + + if (priorPerms != null) { + Map> permMap = MassiveCore.gson.fromJson(priorPerms, (new TypeToken>>() { + }).getType()); + // ... and if anything is explicitly set we use that info ... + Iterator>> iter = permMap.entrySet().iterator(); + while (iter.hasNext()) { + // ... for each entry ... + Map.Entry> entry = iter.next(); + + // ... extract id and remove null values ... + String id = entry.getKey(); + if (id == null) { + iter.remove(); + continue; + } + + Set value = entry.getValue(); + if (value.remove("LEADER")) { + value.add(leaderId); + } + if (value.remove("OFFICER")) { + value.add(officerId); + } + if (value.remove("MEMBER")) { + value.add(memberId); + } + if (value.remove("RECRUIT")) { + value.add(recruitId); + } + ret.put(id, value); + } + } + + return ret; + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/migrator/MigratorFaction003Warps.java b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorFaction003Warps.java new file mode 100644 index 00000000..59272ba8 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorFaction003Warps.java @@ -0,0 +1,57 @@ +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/main/java/com/massivecraft/factions/entity/migrator/MigratorFaction004WarpsPerms.java b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorFaction004WarpsPerms.java new file mode 100644 index 00000000..9e763f94 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorFaction004WarpsPerms.java @@ -0,0 +1,47 @@ +package com.massivecraft.factions.entity.migrator; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.massivecore.store.migrator.MigratorRoot; + +public class MigratorFaction004WarpsPerms extends MigratorRoot { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MigratorFaction004WarpsPerms i = new MigratorFaction004WarpsPerms(); + + public static MigratorFaction004WarpsPerms get() { + return i; + } + + private MigratorFaction004WarpsPerms() { + super(Faction.class); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void migrateInner(JsonObject entity) { + JsonElement perms = entity.get("perms"); + if (perms == null || perms.isJsonNull() || !perms.isJsonObject()) { + return; + } + + JsonObject permsO = perms.getAsJsonObject(); + + JsonElement home = permsO.remove("home"); + if (home != null) { + permsO.add("warp", home); + } + + JsonElement sethome = permsO.remove("sethome"); + if (home != null) { + permsO.add("setwarp", home); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/migrator/MigratorMConf001EnumerationUtil.java b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorMConf001EnumerationUtil.java new file mode 100644 index 00000000..c1a730c2 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorMConf001EnumerationUtil.java @@ -0,0 +1,72 @@ +package com.massivecraft.factions.entity.migrator; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.util.EnumerationUtil; +import com.massivecraft.massivecore.store.migrator.MigratorRoot; + +import java.util.Collection; +import java.util.Iterator; + +public class MigratorMConf001EnumerationUtil extends MigratorRoot { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MigratorMConf001EnumerationUtil i = new MigratorMConf001EnumerationUtil(); + + public static MigratorMConf001EnumerationUtil get() { + return i; + } + + private MigratorMConf001EnumerationUtil() { + super(MConf.class); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void migrateInner(JsonObject entity) { + removeFromStringsField(entity, "materialsEditOnInteract", EnumerationUtil.MATERIALS_EDIT_ON_INTERACT.getStringSet()); + removeFromStringsField(entity, "materialsEditTools", EnumerationUtil.MATERIALS_EDIT_TOOL.getStringSet()); + removeFromStringsField(entity, "materialsDoor", EnumerationUtil.MATERIALS_DOOR.getStringSet()); + removeFromStringsField(entity, "materialsContainer", EnumerationUtil.MATERIALS_CONTAINER.getStringSet()); + removeFromStringsField(entity, "entityTypesEditOnInteract", EnumerationUtil.ENTITY_TYPES_EDIT_ON_INTERACT.getStringSet()); + removeFromStringsField(entity, "entityTypesEditOnDamage", EnumerationUtil.ENTITY_TYPES_EDIT_ON_DAMAGE.getStringSet()); + removeFromStringsField(entity, "entityTypesContainer", EnumerationUtil.ENTITY_TYPES_CONTAINER.getStringSet()); + removeFromStringsField(entity, "entityTypesMonsters", EnumerationUtil.ENTITY_TYPES_MONSTER.getStringSet()); + removeFromStringsField(entity, "entityTypesAnimals", EnumerationUtil.ENTITY_TYPES_ANIMAL.getStringSet()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + private void removeFromStringsField(JsonObject entity, String fieldName, Collection removals) { + JsonElement stringsElement = entity.get(fieldName); + if (!(stringsElement instanceof JsonArray)) { + return; + } + JsonArray strings = (JsonArray) stringsElement; + + for (Iterator iterator = strings.iterator(); iterator.hasNext(); ) { + JsonElement stringElement = iterator.next(); + if (!(stringElement instanceof JsonPrimitive)) { + continue; + } + JsonPrimitive string = (JsonPrimitive) stringElement; + + if (!removals.contains(string.getAsString())) { + continue; + } + + iterator.remove(); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/migrator/MigratorMConf002CleanInactivity.java b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorMConf002CleanInactivity.java new file mode 100644 index 00000000..c3c8518e --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorMConf002CleanInactivity.java @@ -0,0 +1,25 @@ +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 MigratorMConf002CleanInactivity extends MigratorRoot { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MigratorMConf002CleanInactivity i = new MigratorMConf002CleanInactivity(); + + public static MigratorMConf002CleanInactivity get() { + return i; + } + + private MigratorMConf002CleanInactivity() { + super(MConf.class); + this.addInnerMigrator(MigratorFieldRename.get("removePlayerMillisDefault", "playercleanToleranceMillis")); + this.addInnerMigrator(MigratorFieldRename.get("removePlayerMillisPlayerAgeToBonus", "playercleanToleranceMillisPlayerAgeToBonus")); + this.addInnerMigrator(MigratorFieldRename.get("removePlayerMillisFactionAgeToBonus", "playercleanToleranceMillisFactionAgeToBonus")); + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/migrator/MigratorMConf003CleanInactivity.java b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorMConf003CleanInactivity.java new file mode 100644 index 00000000..60bde75a --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorMConf003CleanInactivity.java @@ -0,0 +1,25 @@ +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 MigratorMConf003CleanInactivity extends MigratorRoot { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MigratorMConf003CleanInactivity i = new MigratorMConf003CleanInactivity(); + + public static MigratorMConf003CleanInactivity get() { + return i; + } + + private MigratorMConf003CleanInactivity() { + super(MConf.class); + this.addInnerMigrator(MigratorFieldRename.get("playercleanToleranceMillis", "cleanInactivityToleranceMillis")); + this.addInnerMigrator(MigratorFieldRename.get("playercleanToleranceMillisPlayerAgeToBonus", "cleanInactivityToleranceMillisPlayerAgeToBonus")); + this.addInnerMigrator(MigratorFieldRename.get("playercleanToleranceMillisFactionAgeToBonus", "cleanInactivityToleranceMillisFactionAgeToBonus")); + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/migrator/MigratorMConf004Rank.java b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorMConf004Rank.java new file mode 100644 index 00000000..8367a2a4 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorMConf004Rank.java @@ -0,0 +1,84 @@ +package com.massivecraft.factions.entity.migrator; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.massivecore.store.migrator.MigratorRoot; + +import java.util.Iterator; + +public class MigratorMConf004Rank extends MigratorRoot { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MigratorMConf004Rank i = new MigratorMConf004Rank(); + + public static MigratorMConf004Rank get() { + return i; + } + + private MigratorMConf004Rank() { + super(MConf.class); + } + + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void migrateInner(JsonObject entity) { + migrateRename(entity, "denyCommandsTerritoryRelation"); + migrateRename(entity, "denyCommandsDistanceRelation"); + migrateRename(entity, "denyCommandsDistanceBypassIn"); + + entity.remove("defaultPlayerRole"); + entity.remove("herochatFactionName"); + entity.remove("herochatFactionNick"); + entity.remove("herochatFactionFormat"); + entity.remove("herochatFactionColor"); + entity.remove("herochatFactionDistance"); + entity.remove("herochatFactionIsShortcutAllowed"); + entity.remove("herochatFactionCrossWorld"); + entity.remove("herochatFactionMuted"); + entity.remove("herochatFactionWorlds"); + entity.remove("herochatAlliesName"); + entity.remove("herochatAlliesNick"); + entity.remove("herochatAlliesFormat"); + entity.remove("herochatAlliesColor"); + entity.remove("herochatAlliesDistance"); + entity.remove("herochatAlliesIsShortcutAllowed"); + entity.remove("herochatAlliesCrossWorld"); + entity.remove("herochatAlliesMuted"); + entity.remove("herochatAlliesWorlds"); + } + + private void migrateRename(JsonObject entity, String name) { + JsonElement element = entity.get(name); + if (element.isJsonObject()) { + JsonObject map = element.getAsJsonObject(); + if (map.has("MEMBER")) { + JsonElement e = map.remove("MEMBER"); + map.add("FACTION", e); + } + } + if (element.isJsonArray()) { + JsonArray array = element.getAsJsonArray(); + boolean success = false; + for (Iterator it = array.iterator(); it.hasNext(); ) { + JsonElement e = it.next(); + if (!e.getAsString().equals("MEMBER")) { + continue; + } + it.remove(); + success = true; + } + if (success) { + array.add("FACTION"); + } + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/migrator/MigratorMConf005Warps.java b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorMConf005Warps.java new file mode 100644 index 00000000..b02eb3bf --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorMConf005Warps.java @@ -0,0 +1,30 @@ +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/main/java/com/massivecraft/factions/entity/migrator/MigratorMPerm001Warps.java b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorMPerm001Warps.java new file mode 100644 index 00000000..00efb49f --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorMPerm001Warps.java @@ -0,0 +1,52 @@ +package com.massivecraft.factions.entity.migrator; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.massivecore.store.migrator.MigratorRoot; + +public class MigratorMPerm001Warps extends MigratorRoot { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MigratorMPerm001Warps i = new MigratorMPerm001Warps(); + + public static MigratorMPerm001Warps get() { + return i; + } + + private MigratorMPerm001Warps() { + super(MPerm.class); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void migrateInner(JsonObject entity) { + JsonElement jsonName = entity.get("name"); + String name = jsonName.getAsString(); + if (name.equalsIgnoreCase("home")) { + name = "warp"; + } + if (name.equalsIgnoreCase("sethome")) { + name = "setwarp"; + } + + entity.addProperty("name", name); + + JsonElement jsonDesc = entity.get("desc"); + String desc = jsonDesc.getAsString(); + if (desc.equalsIgnoreCase("teleport home")) { + desc = "teleport to warp"; + } + if (desc.equalsIgnoreCase("set the home")) { + desc = "set warps"; + } + + entity.addProperty("desc", desc); + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/migrator/MigratorMPerm002MoveStandard.java b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorMPerm002MoveStandard.java new file mode 100644 index 00000000..59b1c347 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorMPerm002MoveStandard.java @@ -0,0 +1,50 @@ +package com.massivecraft.factions.entity.migrator; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.massivecore.collections.MassiveSet; +import com.massivecraft.massivecore.store.migrator.MigratorRoot; + +import java.util.Set; + +public class MigratorMPerm002MoveStandard extends MigratorRoot { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MigratorMPerm002MoveStandard i = new MigratorMPerm002MoveStandard(); + + public static MigratorMPerm002MoveStandard get() { + return i; + } + + private MigratorMPerm002MoveStandard() { + super(MPerm.class); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void migrateInner(JsonObject entity) { + JsonElement jsonStandard = entity.remove("standard"); + if (jsonStandard == null || !jsonStandard.isJsonArray()) { + return; + } + + JsonArray jsonArray = jsonStandard.getAsJsonArray(); + Set result = new MassiveSet<>(); + jsonArray.forEach(e -> result.add(e.getAsString())); + + String id = entity.get("name").getAsString(); + + // This is hacky but we utilise that names and ids are the same + MConf.get().perm2default.put(id, result); + MConf.get().changed(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/migrator/MigratorMPlayer001Ranks.java b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorMPlayer001Ranks.java new file mode 100644 index 00000000..2c2f96a9 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorMPlayer001Ranks.java @@ -0,0 +1,81 @@ +package com.massivecraft.factions.entity.migrator; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.entity.Rank; +import com.massivecraft.massivecore.store.migrator.MigratorRoot; + +import java.util.Collection; + +public class MigratorMPlayer001Ranks extends MigratorRoot { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MigratorMPlayer001Ranks i = new MigratorMPlayer001Ranks(); + + public static MigratorMPlayer001Ranks get() { + return i; + } + + private MigratorMPlayer001Ranks() { + super(MPlayer.class); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void migrateInner(JsonObject entity) { + // Get role + JsonElement jsonRole = entity.remove("role"); + String role; + if (jsonRole == null) { + // The role can be null. + // Then they are probably recruit in the default faction (Wilderness). + role = null; + } else { + role = jsonRole.getAsString(); + } + + // Get faction + JsonElement jsonFaction = entity.get("factionId"); + + String factionId; + if (jsonFaction == null) { + factionId = MConf.get().defaultPlayerFactionId; + } else { + factionId = jsonFaction.getAsString(); + } + + Faction faction = FactionColl.get().get(factionId); + if (faction == null) { + faction = FactionColl.get().getNone(); + } + + // Get rank + Rank rank = null; + if (role != null) { + Collection ranks = faction.getRanks().getAll(); + for (Rank r : ranks) { + if (!r.getName().equalsIgnoreCase(role)) { + continue; + } + rank = r; + break; + } + } + if (rank == null) { + rank = faction.getLowestRank(); + } + + entity.add("rankId", new JsonPrimitive(rank.getId())); + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/migrator/MigratorMPlayer002UsingAdminMode.java b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorMPlayer002UsingAdminMode.java new file mode 100644 index 00000000..0e68df23 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorMPlayer002UsingAdminMode.java @@ -0,0 +1,23 @@ +package com.massivecraft.factions.entity.migrator; + +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.store.migrator.MigratorFieldRename; +import com.massivecraft.massivecore.store.migrator.MigratorRoot; + +public class MigratorMPlayer002UsingAdminMode extends MigratorRoot { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MigratorMPlayer002UsingAdminMode i = new MigratorMPlayer002UsingAdminMode(); + + public static MigratorMPlayer002UsingAdminMode get() { + return i; + } + + private MigratorMPlayer002UsingAdminMode() { + super(MPlayer.class); + this.addInnerMigrator(MigratorFieldRename.get("usingAdminMode", "overriding")); + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/migrator/MigratorTerritoryAccess001Restructure.java b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorTerritoryAccess001Restructure.java new file mode 100644 index 00000000..8dfb81eb --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/migrator/MigratorTerritoryAccess001Restructure.java @@ -0,0 +1,51 @@ +package com.massivecraft.factions.entity.migrator; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.massivecraft.factions.TerritoryAccess; +import com.massivecraft.factions.adapter.TerritoryAccessAdapter; +import com.massivecraft.massivecore.store.migrator.MigratorRoot; + +public class MigratorTerritoryAccess001Restructure extends MigratorRoot { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MigratorTerritoryAccess001Restructure i = new MigratorTerritoryAccess001Restructure(); + + public static MigratorTerritoryAccess001Restructure get() { + return i; + } + + private MigratorTerritoryAccess001Restructure() { + super(TerritoryAccess.class); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void migrateInner(JsonObject entity) { + JsonElement factionIds = entity.remove("factionIds"); + JsonElement playerIds = entity.remove("playerIds"); + + JsonArray grantedIds = new JsonArray(); + + if (factionIds != null && factionIds.isJsonArray()) { + JsonArray factionIdsArr = factionIds.getAsJsonArray(); + grantedIds.addAll(factionIdsArr); + } + + if (playerIds != null && playerIds.isJsonArray()) { + JsonArray playerIdsArr = playerIds.getAsJsonArray(); + grantedIds.addAll(playerIdsArr); + } + + if (grantedIds.size() > 0) { + entity.add(TerritoryAccessAdapter.GRANTED_IDS, grantedIds); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/event/EventFactionsAbstract.java b/src/main/java/com/massivecraft/factions/event/EventFactionsAbstract.java new file mode 100644 index 00000000..b7a49104 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsAbstract.java @@ -0,0 +1,18 @@ +package com.massivecraft.factions.event; + +import com.massivecraft.massivecore.event.EventMassiveCore; + +public abstract class EventFactionsAbstract extends EventMassiveCore { + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsAbstract() { + + } + + public EventFactionsAbstract(boolean isAsync) { + super(isAsync); + } + +} diff --git a/src/main/java/com/massivecraft/factions/event/EventFactionsAbstractSender.java b/src/main/java/com/massivecraft/factions/event/EventFactionsAbstractSender.java new file mode 100644 index 00000000..620ee866 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsAbstractSender.java @@ -0,0 +1,35 @@ +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.event.EventMassiveCore; +import org.bukkit.command.CommandSender; + +public abstract class EventFactionsAbstractSender extends EventMassiveCore { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final CommandSender sender; + + public CommandSender getSender() { + return this.sender; + } + + public MPlayer getMPlayer() { + return this.sender == null ? null : MPlayer.get(this.sender); + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsAbstractSender(CommandSender sender) { + this.sender = sender; + } + + public EventFactionsAbstractSender(boolean async, CommandSender sender) { + super(async); + this.sender = sender; + } + +} diff --git a/src/main/java/com/massivecraft/factions/event/EventFactionsChunkChangeType.java b/src/main/java/com/massivecraft/factions/event/EventFactionsChunkChangeType.java new file mode 100644 index 00000000..2b54d35c --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsChunkChangeType.java @@ -0,0 +1,69 @@ +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.massivecore.Colorized; +import org.bukkit.ChatColor; + +public enum EventFactionsChunkChangeType implements Colorized { + // -------------------------------------------- // + // ENUM + // -------------------------------------------- // + + NONE("none", "none", ChatColor.WHITE), + BUY("buy", "bought", ChatColor.GREEN), + SELL("sell", "sold", ChatColor.GREEN), + CONQUER("conquer", "conquered", ChatColor.DARK_GREEN), + PILLAGE("pillage", "pillaged", ChatColor.RED), + + // END OF LIST + ; + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public final String now; + public final String past; + + public final ChatColor color; + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + EventFactionsChunkChangeType(String now, String past, ChatColor color) { + this.now = now; + this.past = past; + this.color = color; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public ChatColor getColor() { + return this.color; + } + + // -------------------------------------------- // + // UTIL + // -------------------------------------------- // + + public static EventFactionsChunkChangeType get(Faction oldFaction, Faction newFaction, Faction self) { + if (newFaction == oldFaction) { + return NONE; + } + if (oldFaction.isNone()) { + return BUY; + } + if (newFaction.isNormal()) { + return CONQUER; + } + if (oldFaction == self) { + return SELL; + } + return PILLAGE; + } + +} diff --git a/src/main/java/com/massivecraft/factions/event/EventFactionsChunksChange.java b/src/main/java/com/massivecraft/factions/event/EventFactionsChunksChange.java new file mode 100644 index 00000000..8c20f3fb --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsChunksChange.java @@ -0,0 +1,101 @@ +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.collections.MassiveMap; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.MUtil; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +import java.util.Collections; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +public class EventFactionsChunksChange 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 Set chunks; + + public Set getChunks() { + return this.chunks; + } + + private final Faction newFaction; + + public Faction getNewFaction() { + return this.newFaction; + } + + private final Map oldChunkFaction; + + public Map getOldChunkFaction() { + return this.oldChunkFaction; + } + + private final Map> oldFactionChunks; + + public Map> getOldFactionChunks() { + return this.oldFactionChunks; + } + + private final Map chunkType; + + public Map getChunkType() { + return this.chunkType; + } + + private final Map> typeChunks; + + public Map> getTypeChunks() { + return this.typeChunks; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsChunksChange(CommandSender sender, Set chunks, Faction newFaction) { + super(sender); + chunks = PS.getDistinctChunks(chunks); + this.chunks = Collections.unmodifiableSet(chunks); + this.newFaction = newFaction; + this.oldChunkFaction = Collections.unmodifiableMap(BoardColl.getChunkFaction(chunks)); + this.oldFactionChunks = Collections.unmodifiableMap(MUtil.reverseIndex(this.oldChunkFaction)); + + MPlayer msender = this.getMPlayer(); + Faction self = null; + if (msender != null) { + self = msender.getFaction(); + } + Map currentChunkType = new MassiveMap<>(); + for (Entry entry : this.oldChunkFaction.entrySet()) { + PS chunk = entry.getKey(); + Faction from = entry.getValue(); + currentChunkType.put(chunk, EventFactionsChunkChangeType.get(from, newFaction, self)); + } + + this.chunkType = Collections.unmodifiableMap(currentChunkType); + this.typeChunks = Collections.unmodifiableMap(MUtil.reverseIndex(this.chunkType)); + } + +} diff --git a/src/main/java/com/massivecraft/factions/event/EventFactionsCreate.java b/src/main/java/com/massivecraft/factions/event/EventFactionsCreate.java new file mode 100644 index 00000000..99f15381 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsCreate.java @@ -0,0 +1,48 @@ +package com.massivecraft.factions.event; + +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +public class EventFactionsCreate 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 String factionId; + + public final String getFactionId() { + return this.factionId; + } + + private final String factionName; + + public final String getFactionName() { + return this.factionName; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsCreate(CommandSender sender, String factionId, String factionName) { + super(sender); + this.factionId = factionId; + this.factionName = factionName; + } + +} diff --git a/src/main/java/com/massivecraft/factions/event/EventFactionsCreateFlags.java b/src/main/java/com/massivecraft/factions/event/EventFactionsCreateFlags.java new file mode 100644 index 00000000..ef6c29ff --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsCreateFlags.java @@ -0,0 +1,36 @@ +package com.massivecraft.factions.event; + +import org.bukkit.event.HandlerList; + +/** + * External plugins that add Faction flags should make sure they exist when this event is called. + */ +public class EventFactionsCreateFlags extends EventFactionsAbstract { + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + + private static final HandlerList handlers = new HandlerList(); + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsCreateFlags() { + + } + + public EventFactionsCreateFlags(boolean isAsync) { + super(isAsync); + } + +} diff --git a/src/main/java/com/massivecraft/factions/event/EventFactionsCreatePerms.java b/src/main/java/com/massivecraft/factions/event/EventFactionsCreatePerms.java new file mode 100644 index 00000000..154f26d2 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsCreatePerms.java @@ -0,0 +1,24 @@ +package com.massivecraft.factions.event; + +import org.bukkit.event.HandlerList; + +/** + * External plugins that add Faction perms should make sure they exist when this event is called. + */ +public class EventFactionsCreatePerms extends EventFactionsAbstract { + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + + private static final HandlerList handlers = new HandlerList(); + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + +} diff --git a/src/main/java/com/massivecraft/factions/event/EventFactionsDescriptionChange.java b/src/main/java/com/massivecraft/factions/event/EventFactionsDescriptionChange.java new file mode 100644 index 00000000..797eee57 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsDescriptionChange.java @@ -0,0 +1,53 @@ +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.Faction; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +public class EventFactionsDescriptionChange 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 String newDescription; + + public String getNewDescription() { + return this.newDescription; + } + + public void setNewDescription(String newDescription) { + this.newDescription = newDescription; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsDescriptionChange(CommandSender sender, Faction faction, String newDescription) { + super(sender); + this.faction = faction; + this.newDescription = newDescription; + } + +} diff --git a/src/main/java/com/massivecraft/factions/event/EventFactionsDisband.java b/src/main/java/com/massivecraft/factions/event/EventFactionsDisband.java new file mode 100644 index 00000000..e03af957 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsDisband.java @@ -0,0 +1,49 @@ +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.Faction; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +public class EventFactionsDisband 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 final String factionId; + + public String getFactionId() { + return this.factionId; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsDisband(CommandSender sender, Faction faction) { + super(sender); + this.faction = faction; + this.factionId = faction.getId(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/event/EventFactionsExpansions.java b/src/main/java/com/massivecraft/factions/event/EventFactionsExpansions.java new file mode 100644 index 00000000..2a38f652 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsExpansions.java @@ -0,0 +1,46 @@ +package com.massivecraft.factions.event; + +import com.massivecraft.massivecore.collections.MassiveTreeMap; +import com.massivecraft.massivecore.comparator.ComparatorCaseInsensitive; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +import java.util.Map; + +public class EventFactionsExpansions 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 MassiveTreeMap expansions = new MassiveTreeMap<>(ComparatorCaseInsensitive.get()); + + public Map getExpansions() { + return this.expansions; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsExpansions(CommandSender sender) { + super(sender); + this.getExpansions().put("FactionsTax", false); + this.getExpansions().put("FactionsDynmap", false); + } + +} diff --git a/src/main/java/com/massivecraft/factions/event/EventFactionsFactionShowAsync.java b/src/main/java/com/massivecraft/factions/event/EventFactionsFactionShowAsync.java new file mode 100644 index 00000000..63f06eb3 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsFactionShowAsync.java @@ -0,0 +1,53 @@ +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.massivecore.PriorityLines; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +import java.util.HashMap; +import java.util.Map; + +public class EventFactionsFactionShowAsync 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 final Map idPriorityLiness; + + public Map getIdPriorityLiness() { + return this.idPriorityLiness; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsFactionShowAsync(CommandSender sender, Faction faction) { + super(true, sender); + this.faction = faction; + this.idPriorityLiness = new HashMap<>(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/event/EventFactionsFlagChange.java b/src/main/java/com/massivecraft/factions/event/EventFactionsFlagChange.java new file mode 100644 index 00000000..49b0ed8d --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsFlagChange.java @@ -0,0 +1,61 @@ +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MFlag; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +public class EventFactionsFlagChange 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 final MFlag flag; + + public MFlag getFlag() { + return this.flag; + } + + private boolean newValue; + + public boolean isNewValue() { + return this.newValue; + } + + public void setNewValue(boolean newValue) { + this.newValue = newValue; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsFlagChange(CommandSender sender, Faction faction, MFlag flag, boolean newValue) { + super(sender); + this.faction = faction; + this.flag = flag; + this.newValue = newValue; + } + +} diff --git a/src/main/java/com/massivecraft/factions/event/EventFactionsInvitedChange.java b/src/main/java/com/massivecraft/factions/event/EventFactionsInvitedChange.java new file mode 100644 index 00000000..cb805990 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsInvitedChange.java @@ -0,0 +1,61 @@ +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +public class EventFactionsInvitedChange 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 MPlayer mplayer; + + public MPlayer getMPlayer() { + return this.mplayer; + } + + private final Faction faction; + + public Faction getFaction() { + return this.faction; + } + + private boolean newInvited; + + public boolean isNewInvited() { + return this.newInvited; + } + + public void setNewInvited(boolean newInvited) { + this.newInvited = newInvited; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsInvitedChange(CommandSender sender, MPlayer mplayer, Faction faction, boolean newInvited) { + super(sender); + this.mplayer = mplayer; + this.faction = faction; + this.newInvited = newInvited; + } + +} diff --git a/src/main/java/com/massivecraft/factions/event/EventFactionsMembershipChange.java b/src/main/java/com/massivecraft/factions/event/EventFactionsMembershipChange.java new file mode 100644 index 00000000..9a010ab3 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsMembershipChange.java @@ -0,0 +1,97 @@ +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +public class EventFactionsMembershipChange 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 + // -------------------------------------------- // + + @Override + public void setCancelled(boolean cancelled) { + if (!this.reason.isCancellable()) { + cancelled = false; + } + super.setCancelled(cancelled); + } + + private final MPlayer mplayer; + + public MPlayer getMPlayer() { + return this.mplayer; + } + + private final Faction newFaction; + + public Faction getNewFaction() { + return this.newFaction; + } + + private final MembershipChangeReason reason; + + public MembershipChangeReason getReason() { + return this.reason; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsMembershipChange(CommandSender sender, MPlayer mplayer, Faction newFaction, MembershipChangeReason reason) { + super(sender); + this.mplayer = mplayer; + this.newFaction = newFaction; + this.reason = reason; + } + + // -------------------------------------------- // + // REASON ENUM + // -------------------------------------------- // + + public enum MembershipChangeReason { + // Join + JOIN(true), + CREATE(false), + // Leader is not used, but temporarily kept to avoid other plugins crashing + @Deprecated + LEADER(true), + RANK(true), + + // Leave + LEAVE(true), + //JOINOTHER (true), + KICK(true), + DISBAND(false), + //RESET (false), + ; + + private final boolean cancellable; + + public boolean isCancellable() { + return this.cancellable; + } + + MembershipChangeReason(boolean cancellable) { + this.cancellable = cancellable; + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/event/EventFactionsMotdChange.java b/src/main/java/com/massivecraft/factions/event/EventFactionsMotdChange.java new file mode 100644 index 00000000..96060c0f --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsMotdChange.java @@ -0,0 +1,53 @@ +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.Faction; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +public class EventFactionsMotdChange 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 String newMotd; + + public String getNewMotd() { + return this.newMotd; + } + + public void setNewMotd(String newMotd) { + this.newMotd = newMotd; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsMotdChange(CommandSender sender, Faction faction, String newMotd) { + super(sender); + this.faction = faction; + this.newMotd = newMotd; + } + +} diff --git a/src/main/java/com/massivecraft/factions/event/EventFactionsNameChange.java b/src/main/java/com/massivecraft/factions/event/EventFactionsNameChange.java new file mode 100644 index 00000000..e0464dc4 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsNameChange.java @@ -0,0 +1,53 @@ +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.Faction; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +public class EventFactionsNameChange 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 String newName; + + public String getNewName() { + return this.newName; + } + + public void setNewName(String newName) { + this.newName = newName; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsNameChange(CommandSender sender, Faction faction, String newName) { + super(sender); + this.faction = faction; + this.newName = newName; + } + +} diff --git a/src/main/java/com/massivecraft/factions/event/EventFactionsPermChange.java b/src/main/java/com/massivecraft/factions/event/EventFactionsPermChange.java new file mode 100644 index 00000000..93c8d9a5 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsPermChange.java @@ -0,0 +1,68 @@ +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPerm; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +public class EventFactionsPermChange 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 final MPerm perm; + + public MPerm getPerm() { + return this.perm; + } + + private final MPerm.MPermable permable; + + public MPerm.MPermable getRel() { + return this.permable; + } + + private boolean newValue; + + public boolean getNewValue() { + return this.newValue; + } + + public void setNewValue(boolean newValue) { + this.newValue = newValue; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsPermChange(CommandSender sender, Faction faction, MPerm perm, MPerm.MPermable permable, boolean newValue) { + super(sender); + this.faction = faction; + this.perm = perm; + this.permable = permable; + this.newValue = newValue; + } + +} diff --git a/src/main/java/com/massivecraft/factions/event/EventFactionsPowerChange.java b/src/main/java/com/massivecraft/factions/event/EventFactionsPowerChange.java new file mode 100644 index 00000000..cc960a81 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsPowerChange.java @@ -0,0 +1,72 @@ +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.MPlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +public class EventFactionsPowerChange 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 MPlayer mplayer; + + public MPlayer getMPlayer() { + return this.mplayer; + } + + private final PowerChangeReason reason; + + public PowerChangeReason getReason() { + return this.reason; + } + + private double newPower; + + public double getNewPower() { + return this.newPower; + } + + public void setNewPower(double newPower) { + this.newPower = newPower; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsPowerChange(CommandSender sender, MPlayer mplayer, PowerChangeReason reason, double newPower) { + super(sender); + this.mplayer = mplayer; + this.reason = reason; + this.newPower = mplayer.getLimitedPower(newPower); + } + + // -------------------------------------------- // + // REASON ENUM + // -------------------------------------------- // + + public enum PowerChangeReason { + TIME, + DEATH, + COMMAND, + UNDEFINED, + ; + } + +} diff --git a/src/main/java/com/massivecraft/factions/event/EventFactionsPvpDisallowed.java b/src/main/java/com/massivecraft/factions/event/EventFactionsPvpDisallowed.java new file mode 100644 index 00000000..d86e1c96 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsPvpDisallowed.java @@ -0,0 +1,79 @@ +package com.massivecraft.factions.event; + +import com.massivecraft.factions.engine.DisallowCause; +import com.massivecraft.factions.entity.MPlayer; +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.event.entity.EntityDamageByEntityEvent; + +/** + * This event is fired when PVP is disallowed between players due to any rules in Factions. + * Canceling this event allows the PVP in spite of this and stops text messages from being sent. + *

+ * Note that the defender field always is set but the attacker can be null. + * Some other plugins seem to fire EntityDamageByEntityEvent without an attacker. + */ +public class EventFactionsPvpDisallowed extends EventFactionsAbstract { + // -------------------------------------------- // + // 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 Player attacker; + + public Player getAttacker() { + return this.attacker; + } + + public MPlayer getMAttacker() { + return this.attacker == null ? null : MPlayer.get(this.attacker); + } + + private final Player defender; + + public Player getDefender() { + return this.defender; + } + + public MPlayer getMDefender() { + return this.defender == null ? null : MPlayer.get(this.defender); + } + + private final DisallowCause cause; + + public DisallowCause getCause() { + return this.cause; + } + + private final EntityDamageByEntityEvent event; + + public EntityDamageByEntityEvent getEvent() { + return this.event; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsPvpDisallowed(Player attacker, Player defender, DisallowCause cause, EntityDamageByEntityEvent event) { + this.attacker = attacker; + this.defender = defender; + this.cause = cause; + this.event = event; + } + +} diff --git a/src/main/java/com/massivecraft/factions/event/EventFactionsRankChange.java b/src/main/java/com/massivecraft/factions/event/EventFactionsRankChange.java new file mode 100644 index 00000000..7905b5a2 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsRankChange.java @@ -0,0 +1,53 @@ +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.entity.Rank; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +public class EventFactionsRankChange 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 MPlayer mplayer; + + public MPlayer getMPlayer() { + return this.mplayer; + } + + private Rank newRank; + + public Rank getNewRank() { + return this.newRank; + } + + public void setNewRank(Rank newRole) { + this.newRank = newRole; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsRankChange(CommandSender sender, MPlayer mplayer, Rank newRank) { + super(sender); + this.mplayer = mplayer; + this.newRank = newRank; + } +} diff --git a/src/main/java/com/massivecraft/factions/event/EventFactionsRelationChange.java b/src/main/java/com/massivecraft/factions/event/EventFactionsRelationChange.java new file mode 100644 index 00000000..a36ace7a --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsRelationChange.java @@ -0,0 +1,62 @@ +package com.massivecraft.factions.event; + +import com.massivecraft.factions.Rel; +import com.massivecraft.factions.entity.Faction; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + + +public class EventFactionsRelationChange 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 final Faction otherFaction; + + public Faction getOtherFaction() { + return this.otherFaction; + } + + private Rel newRelation; + + public Rel getNewRelation() { + return this.newRelation; + } + + public void setNewRelation(Rel newRelation) { + this.newRelation = newRelation; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsRelationChange(CommandSender sender, Faction faction, Faction otherFaction, Rel newRelation) { + super(sender); + this.faction = faction; + this.otherFaction = otherFaction; + this.newRelation = newRelation; + } + +} diff --git a/src/main/java/com/massivecraft/factions/event/EventFactionsTitleChange.java b/src/main/java/com/massivecraft/factions/event/EventFactionsTitleChange.java new file mode 100644 index 00000000..6de85a85 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsTitleChange.java @@ -0,0 +1,53 @@ +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.MPlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +public class EventFactionsTitleChange 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 MPlayer mplayer; + + public MPlayer getMPlayer() { + return this.mplayer; + } + + private String newTitle; + + public String getNewTitle() { + return this.newTitle; + } + + public void setNewTitle(String newTitle) { + this.newTitle = newTitle; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsTitleChange(CommandSender sender, MPlayer mplayer, String newTitle) { + super(sender); + this.mplayer = mplayer; + this.newTitle = newTitle; + } + +} diff --git a/src/main/java/com/massivecraft/factions/event/EventFactionsVoteAdd.java b/src/main/java/com/massivecraft/factions/event/EventFactionsVoteAdd.java new file mode 100644 index 00000000..b2cb8564 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsVoteAdd.java @@ -0,0 +1,54 @@ +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.Vote; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +public class EventFactionsVoteAdd 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 Vote vote; + + public Vote getVote() { + return this.vote; + } + + public void setVote(Vote vote) { + this.vote = vote; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsVoteAdd(CommandSender sender, Faction faction, Vote vote) { + super(sender); + this.faction = faction; + this.vote = vote; + } + +} diff --git a/src/main/java/com/massivecraft/factions/event/EventFactionsVoteRemove.java b/src/main/java/com/massivecraft/factions/event/EventFactionsVoteRemove.java new file mode 100644 index 00000000..56edd7cd --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsVoteRemove.java @@ -0,0 +1,54 @@ +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.Vote; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +public class EventFactionsVoteRemove 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 Vote vote; + + public Vote getVote() { + return this.vote; + } + + public void setVote(Vote vote) { + this.vote = vote; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsVoteRemove(CommandSender sender, Faction faction, Vote vote) { + super(sender); + this.faction = faction; + this.vote = vote; + } + +} diff --git a/src/main/java/com/massivecraft/factions/event/EventFactionsWarpAdd.java b/src/main/java/com/massivecraft/factions/event/EventFactionsWarpAdd.java new file mode 100644 index 00000000..09645497 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsWarpAdd.java @@ -0,0 +1,54 @@ +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/main/java/com/massivecraft/factions/event/EventFactionsWarpRemove.java b/src/main/java/com/massivecraft/factions/event/EventFactionsWarpRemove.java new file mode 100644 index 00000000..725cfa38 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsWarpRemove.java @@ -0,0 +1,54 @@ +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 getWarp() { + return this.warp; + } + + public void setWarp(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/main/java/com/massivecraft/factions/event/EventFactionsWarpTeleport.java b/src/main/java/com/massivecraft/factions/event/EventFactionsWarpTeleport.java new file mode 100644 index 00000000..713543eb --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsWarpTeleport.java @@ -0,0 +1,42 @@ +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/main/java/com/massivecraft/factions/integration/Econ.java b/src/main/java/com/massivecraft/factions/integration/Econ.java new file mode 100644 index 00000000..eddb5067 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/integration/Econ.java @@ -0,0 +1,314 @@ +package com.massivecraft.factions.integration; + +import com.massivecraft.factions.EconomyParticipator; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.util.RelationUtil; +import com.massivecraft.massivecore.money.Money; + +import java.util.HashSet; +import java.util.Set; + +public class Econ { + // -------------------------------------------- // + // STATE + // -------------------------------------------- // + + public static boolean isEnabled() { + return MConf.get().econEnabled && Money.enabled(); + } + + // -------------------------------------------- // + // UTIL + // -------------------------------------------- // + + public static boolean payForAction(double cost, MPlayer usender, String actionDescription) { + if (!isEnabled()) { + return true; + } + if (cost == 0D) { + return true; + } + + if (usender.isOverriding()) { + return true; + } + + Faction usenderFaction = usender.getFaction(); + + if (MConf.get().bankEnabled && MConf.get().bankFactionPaysCosts && usenderFaction.isNormal()) { + return modifyMoney(usenderFaction, -cost, actionDescription); + } else { + return modifyMoney(usender, -cost, actionDescription); + } + } + + // -------------------------------------------- // + // ASSORTED + // -------------------------------------------- // + + public static void modifyUniverseMoney(Object universe, double delta) { + if (!isEnabled()) { + return; + } + + if (MConf.get().econUniverseAccount == null) { + return; + } + if (MConf.get().econUniverseAccount.length() == 0) { + return; + } + + if (!Money.exists(MConf.get().econUniverseAccount)) { + return; + } + + Money.spawn(MConf.get().econUniverseAccount, null, delta); + } + + public static void sendBalanceInfo(MPlayer to, EconomyParticipator about) { + to.msg("%s's balance is %s.", about.describeTo(to, true), Money.format(getMoney(about))); + } + + public static boolean isMePermittedYou(EconomyParticipator me, EconomyParticipator you, MPerm mperm) { + // Null means special system invocation and is always to be accepted. + if (me == null) { + return true; + } + + // Always accept when in admin mode. + if (me instanceof MPlayer && ((MPlayer) me).isOverriding()) { + return true; + } + + // Always accept control of self + if (me == you) { + return true; + } + + Faction fMe = RelationUtil.getFaction(me); + Faction fYou = RelationUtil.getFaction(you); + + // A faction can always transfer away the money of it's members and its own money... + // This will however probably never happen as a faction does not have free will. + // Ohh by the way... Yes it could. For daily rent to the faction. + if (me == fMe && fMe == fYou) { + return true; + } + + // Factions can be controlled by those that have permissions + if (you instanceof Faction) { + if (me instanceof Faction && mperm.has((Faction) me, fYou)) { + return true; + } + if (me instanceof MPlayer && mperm.has((MPlayer) me, fYou, false)) { + return true; + } + } + + // Otherwise you may not! ;,,; + return false; + } + + public static boolean transferMoney(EconomyParticipator invoker, EconomyParticipator from, EconomyParticipator to, double amount) { + return transferMoney(from, to, invoker, amount, true); + } + + public static boolean transferMoney(EconomyParticipator from, EconomyParticipator to, EconomyParticipator by, double amount, boolean notify) { + if (!isEnabled()) { + return false; + } + + // The amount must be positive. + // If the amount is negative we must flip and multiply amount with -1. + if (amount < 0) { + amount *= -1; + EconomyParticipator temp = from; + from = to; + to = temp; + } + + // Check Permissions + if (!isMePermittedYou(by, from, MPerm.getPermWithdraw())) { + by.msg("%s lack permission to withdraw money from %s.", by.describeTo(by, true), from.describeTo(by)); + return false; + } + + if (!isMePermittedYou(by, to, MPerm.getPermDeposit())) { + by.msg("%s lack permission to deposit money to %s.", by.describeTo(by, true), to.describeTo(by)); + return false; + } + + // Is there enough money for the transaction to happen? + if (getMoney(from) < amount) { + // There was not enough money to pay + if (by != null && notify) { + by.msg("%s can't afford to transfer %s to %s.", from.describeTo(by, true), Money.format(amount), to.describeTo(by)); + } + return false; + } + + // Transfer money + if (moveMoney(from, to, by, amount)) { + if (notify) { + sendTransferInfo(by, from, to, amount); + } + return true; + } else { + // if we get here something with the transaction failed + if (by != null && notify) { + by.msg("Unable to transfer %s to %s from %s.", Money.format(amount), to.describeTo(by), from.describeTo(by, true)); + } + return false; + } + } + + public static Set getMPlayers(EconomyParticipator ep) { + Set mplayers = new HashSet<>(); + + if (ep == null) { + // Add nothing + } else if (ep instanceof MPlayer) { + mplayers.add((MPlayer) ep); + } else if (ep instanceof Faction) { + mplayers.addAll(((Faction) ep).getMPlayers()); + } + + return mplayers; + } + + public static void sendTransferInfo(EconomyParticipator invoker, EconomyParticipator from, EconomyParticipator to, double amount) { + Set recipients = new HashSet<>(); + recipients.addAll(getMPlayers(invoker)); + recipients.addAll(getMPlayers(from)); + recipients.addAll(getMPlayers(to)); + + if (invoker == null) { + for (MPlayer recipient : recipients) { + recipient.msg("%s was transfered from %s to %s.", Money.format(amount), from.describeTo(recipient), to.describeTo(recipient)); + } + } else if (invoker == from) { + for (MPlayer recipient : recipients) { + recipient.msg("%s gave %s to %s.", from.describeTo(recipient, true), Money.format(amount), to.describeTo(recipient)); + } + } else if (invoker == to) { + for (MPlayer recipient : recipients) { + recipient.msg("%s took %s from %s.", to.describeTo(recipient, true), Money.format(amount), from.describeTo(recipient)); + } + } else { + for (MPlayer recipient : recipients) { + recipient.msg("%s transfered %s from %s to %s.", invoker.describeTo(recipient, true), Money.format(amount), from.describeTo(recipient), to.describeTo(recipient)); + } + } + } + + public static boolean hasAtLeast(EconomyParticipator ep, double delta) { + return hasAtLeast(ep, delta, null); + } + + public static boolean hasAtLeast(EconomyParticipator ep, double delta, String toDoThis) { + if (!isEnabled()) { + return true; + } + + if (getMoney(ep) < delta) { + if (toDoThis != null && !toDoThis.isEmpty()) { + ep.msg("%s can't afford %s %s.", ep.describeTo(ep, true), Money.format(delta), toDoThis); + } + return false; + } + return true; + } + + public static boolean modifyMoney(EconomyParticipator ep, double delta, String actionDescription) { + if (!isEnabled()) { + return false; + } + if (delta == 0) { + return true; + } + + String You = ep.describeTo(ep, true); + String you = ep.describeTo(ep, false); + + boolean hasActionDesctription = (actionDescription != null && !actionDescription.isEmpty()); + + if (moveMoney(null, ep, null, delta)) { + modifyUniverseMoney(ep, -delta); + + if (hasActionDesctription) { + if (delta > 0) { + ep.msg("%s gained %s since %s did %s.", You, Money.format(delta), you, actionDescription); + } else { + ep.msg("%s lost %s since %s did %s.", You, Money.format(-delta), you, actionDescription); + } + } + return true; + } else { + if (hasActionDesctription) { + if (delta > 0) { + ep.msg("%s would have gained %s since %s did %s, but the deposit failed.", You, Money.format(delta), you, actionDescription); + } else { + ep.msg("%s can't afford %s to %s.", You, Money.format(-delta), actionDescription); + } + } + return false; + } + } + + public static double getMoney(EconomyParticipator ep) { + if (ep instanceof Faction && MConf.get().useNewMoneySystem) { + return ((Faction) ep).getMoney(); + } else { + return Money.get(ep); + } + } + + public static boolean moveMoney(EconomyParticipator from, EconomyParticipator to, EconomyParticipator by, double amount) { + return moveMoney(from, to, by, amount, "Factions"); + } + + public static boolean moveMoney(EconomyParticipator from, EconomyParticipator to, EconomyParticipator by, double amount, String category) { + final boolean fromFaction = from instanceof Faction; + final boolean toFaction = to instanceof Faction; + + // If the old money system is used just do that + if (!MConf.get().useNewMoneySystem) { + return Money.move(from, to, by, amount, category); + } + + // Or if neither to or from is a faction + if (!fromFaction && !toFaction) { + return Money.move(from, to, by, amount, category); + } + + // Handle from + if (fromFaction) { + Faction faction = (Faction) from; + double money = faction.getMoney(); + if (amount > money) { + return false; + } + faction.setMoney(money - amount); + } else if (from != null) { + boolean temp = Money.despawn(from, by, amount); + if (temp == false) { + return temp; + } + } + + // Handle to + if (toFaction) { + Faction faction = (Faction) to; + double money = faction.getMoney(); + faction.setMoney(money + amount); + } else if (to != null) { + Money.spawn(to, by, amount); + } + + return true; + } + +} diff --git a/src/main/java/com/massivecraft/factions/integration/dynmap/AreaMarkerValues.java b/src/main/java/com/massivecraft/factions/integration/dynmap/AreaMarkerValues.java new file mode 100644 index 00000000..d90baed3 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/integration/dynmap/AreaMarkerValues.java @@ -0,0 +1,275 @@ +package com.massivecraft.factions.integration.dynmap; + +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.MUtil; +import org.dynmap.markers.AreaMarker; +import org.dynmap.markers.MarkerAPI; +import org.dynmap.markers.MarkerSet; + +public class AreaMarkerValues { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final String label; + + public String getLabel() { + return label; + } + + public AreaMarkerValues withLabel(String label) { + return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); + } + + private final String world; + + public String getWorld() { + return world; + } + + public AreaMarkerValues withWorld(String world) { + return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); + } + + private final PS[] corners; + + public PS[] getCorners() { + return this.corners; + } + + public AreaMarkerValues withCorners() { + return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); + } + + private final String description; + + public String getDescription() { + return description; + } + + public AreaMarkerValues withDescription(String description) { + return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); + } + + private final int lineColor; + + public int getLineColor() { + return lineColor; + } + + public AreaMarkerValues withLineColor(int lineColor) { + return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); + } + + private final double lineOpacity; + + public double getLineOpacity() { + return lineOpacity; + } + + public AreaMarkerValues withLineOpacity(double lineOpacity) { + return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); + } + + private final int lineWeight; + + public int getLineWeight() { + return lineWeight; + } + + public AreaMarkerValues withLineWright(int lineWeight) { + return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); + } + + private final int fillColor; + + public int getFillColor() { + return fillColor; + } + + public AreaMarkerValues withFillColor(int fillColor) { + return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); + } + + private final double fillOpacity; + + public double getFillOpacity() { + return fillOpacity; + } + + public AreaMarkerValues withFillOpacity(double fillOpacity) { + return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); + } + + private final boolean boost; + + public boolean isBoost() { + return boost; + } + + public AreaMarkerValues withBoost(boolean boost) { + return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); + } + + public AreaMarkerValues withStyle(DynmapStyle style) { + return new AreaMarkerValues(label, world, corners, description, style); + } + + // Caches + private final double[] x; + private final double[] z; + + // -------------------------------------------- // + // CONSTRUCTOR + // -------------------------------------------- // + + public AreaMarkerValues(String label, String world, PS[] corners, String description, DynmapStyle style) { + this(label, world, corners, description, style.getLineColor(), style.getLineOpacity(), style.getLineWeight(), style.getFillColor(), style.getFillOpacity(), style.getBoost()); + } + + public AreaMarkerValues(String label, String world, PS[] corners, String description, int lineColor, double lineOpacity, int lineWeight, int fillColor, double fillOpacity, boolean boost) { + this.label = label; + this.world = world; + this.corners = corners; + this.description = description; + this.lineColor = lineColor; + this.lineOpacity = lineOpacity; + this.lineWeight = lineWeight; + this.fillColor = fillColor; + this.fillOpacity = fillOpacity; + this.boost = boost; + + int sz = corners.length; + x = new double[sz]; + z = new double[sz]; + + for (int i = 0; i < sz; i++) { + PS ps = corners[i]; + x[i] = ps.getLocationX(true); + z[i] = ps.getLocationZ(true); + } + } + + // -------------------------------------------- // + // MASTER + // -------------------------------------------- // + + public AreaMarker ensureExistsAndUpdated(AreaMarker areaMarker, MarkerAPI markerApi, MarkerSet markerset, String markerId) { + // NOTE: I remove from the map created just in the beginning of this method. + // NOTE: That way what is left at the end will be outdated markers to remove. + if (areaMarker == null) { + areaMarker = create(markerApi, markerset, markerId); + } else { + update(markerApi, markerset, areaMarker); + } + + if (areaMarker == null) { + EngineDynmap.logSevere("Could not get/create the area marker " + markerId); + } + + return areaMarker; + } + + // -------------------------------------------- // + // CREATE + // -------------------------------------------- // + + public AreaMarker create(MarkerAPI markerApi, MarkerSet markerset, String markerId) { + AreaMarker ret = markerset.createAreaMarker( + markerId, + this.getLabel(), + false, + this.getWorld(), + this.x, + this.z, + false // not persistent + ); + + if (ret == null) { + return null; + } + + // Description + ret.setDescription(this.getDescription()); + + // Line Style + ret.setLineStyle(this.getLineWeight(), this.getLineOpacity(), this.getLineColor()); + + // Fill Style + ret.setFillStyle(this.getFillOpacity(), this.getFillColor()); + + // Boost Flag + ret.setBoostFlag(this.isBoost()); + + return ret; + } + + // -------------------------------------------- // + // UPDATE + // -------------------------------------------- // + + public void update(MarkerAPI markerApi, MarkerSet markerset, AreaMarker marker) { + // Corner Locations + if (!equals(marker, this.x, this.z)) { + marker.setCornerLocations(this.x, this.z); + } + + // Label + MUtil.setIfDifferent(this.getLabel(), marker::getLabel, marker::setLabel); + + // Description + MUtil.setIfDifferent(this.getDescription(), marker::getDescription, marker::setDescription); + + // Line Style + if + ( + !MUtil.equals(marker.getLineWeight(), this.lineWeight) + || + !MUtil.equals(marker.getLineOpacity(), this.lineOpacity) + || + !MUtil.equals(marker.getLineColor(), this.lineColor) + ) { + marker.setLineStyle(this.lineWeight, this.lineOpacity, this.lineColor); + } + + // Fill Style + if + ( + !MUtil.equals(marker.getFillOpacity(), this.fillOpacity) + || + !MUtil.equals(marker.getFillColor(), this.fillColor) + ) { + marker.setFillStyle(this.fillOpacity, this.fillColor); + } + + // Boost Flag + MUtil.setIfDifferent(this.isBoost(), marker::getBoostFlag, marker::setBoostFlag); + } + + // -------------------------------------------- // + // UTIL + // -------------------------------------------- // + + public static boolean equals(AreaMarker marker, double[] x, double[] z) { + int length = marker.getCornerCount(); + + if (x.length != length) { + return false; + } + if (z.length != length) { + return false; + } + + for (int i = 0; i < length; i++) { + if (marker.getCornerX(i) != x[i]) { + return false; + } + if (marker.getCornerZ(i) != z[i]) { + return false; + } + } + + return true; + } + +} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/integration/dynmap/DynmapStyle.java b/src/main/java/com/massivecraft/factions/integration/dynmap/DynmapStyle.java new file mode 100644 index 00000000..d6d84b7b --- /dev/null +++ b/src/main/java/com/massivecraft/factions/integration/dynmap/DynmapStyle.java @@ -0,0 +1,125 @@ +package com.massivecraft.factions.integration.dynmap; + +import com.massivecraft.factions.entity.MConf; + +public class DynmapStyle { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public final String lineColor; + + public int getLineColor() { + return getColor(coalesce(this.lineColor, MConf.get().dynmapDefaultStyle.lineColor, IntegrationDynmap.DYNMAP_STYLE_LINE_COLOR)); + } + + public DynmapStyle withLineColor(String lineColor) { + return new DynmapStyle(lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, homeMarker, boost); + } + + public final Double lineOpacity; + + public double getLineOpacity() { + return coalesce(this.lineOpacity, MConf.get().dynmapDefaultStyle.lineOpacity, IntegrationDynmap.DYNMAP_STYLE_LINE_OPACITY); + } + + public DynmapStyle withLineOpacity(Double lineOpacity) { + return new DynmapStyle(lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, homeMarker, boost); + } + + public final Integer lineWeight; + + public int getLineWeight() { + return coalesce(this.lineWeight, MConf.get().dynmapDefaultStyle.lineWeight, IntegrationDynmap.DYNMAP_STYLE_LINE_WEIGHT); + } + + public DynmapStyle withLineWeight(Integer lineWeight) { + return new DynmapStyle(lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, homeMarker, boost); + } + + public final String fillColor; + + public int getFillColor() { + return getColor(coalesce(this.fillColor, MConf.get().dynmapDefaultStyle.fillColor, IntegrationDynmap.DYNMAP_STYLE_FILL_COLOR)); + } + + public DynmapStyle withFillColor(String fillColor) { + return new DynmapStyle(lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, homeMarker, boost); + } + + public final Double fillOpacity; + + public double getFillOpacity() { + return coalesce(this.fillOpacity, MConf.get().dynmapDefaultStyle.fillOpacity, IntegrationDynmap.DYNMAP_STYLE_FILL_OPACITY); + } + + public DynmapStyle withFillOpacity(Double fillOpacity) { + return new DynmapStyle(lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, homeMarker, boost); + } + + // NOTE: We just return the string here. We do not return the resolved Dynmap MarkerIcon object. + // The reason is we use this class in the MConf. For serialization to work Dynmap would have to be loaded and we can't require that. + // Using dynmap is optional. + public final String homeMarker; + + public String getHomeMarker() { + return coalesce(this.homeMarker, MConf.get().dynmapDefaultStyle.homeMarker, IntegrationDynmap.DYNMAP_STYLE_HOME_MARKER); + } + + public DynmapStyle withHomeMarker(String homeMarker) { + return new DynmapStyle(lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, homeMarker, boost); + } + + public final Boolean boost; + + public boolean getBoost() { + return coalesce(this.boost, MConf.get().dynmapDefaultStyle.boost, IntegrationDynmap.DYNMAP_STYLE_BOOST); + } + + public DynmapStyle withBoost(Boolean boost) { + return new DynmapStyle(lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, homeMarker, boost); + } + + // -------------------------------------------- // + // CONSTRUCTOR + // -------------------------------------------- // + + public DynmapStyle() { + this(null, null, null, null, null, null, null); + } + + public DynmapStyle(String lineColor, Double lineOpacity, Integer lineWeight, String fillColor, Double fillOpacity, String homeMarker, Boolean boost) { + this.lineColor = lineColor; + this.lineOpacity = lineOpacity; + this.lineWeight = lineWeight; + this.fillColor = fillColor; + this.fillOpacity = fillOpacity; + this.homeMarker = homeMarker; + this.boost = boost; + } + + // -------------------------------------------- // + // UTIL + // -------------------------------------------- // + + @SafeVarargs + public static T coalesce(T... items) { + for (T item : items) { + if (item != null) { + return item; + } + } + return null; + } + + public static int getColor(String string) { + int ret = 0x00FF00; + try { + ret = Integer.parseInt(string.substring(1), 16); + } catch (NumberFormatException nfx) { + + } + return ret; + } + +} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/integration/dynmap/EngineDynmap.java b/src/main/java/com/massivecraft/factions/integration/dynmap/EngineDynmap.java new file mode 100644 index 00000000..9be0d82b --- /dev/null +++ b/src/main/java/com/massivecraft/factions/integration/dynmap/EngineDynmap.java @@ -0,0 +1,726 @@ +package com.massivecraft.factions.integration.dynmap; + +import com.massivecraft.factions.Factions; +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.MPlayer; +import com.massivecraft.factions.integration.Econ; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.collections.MassiveList; +import com.massivecraft.massivecore.collections.MassiveMap; +import com.massivecraft.massivecore.collections.MassiveSet; +import com.massivecraft.massivecore.money.Money; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.MUtil; +import com.massivecraft.massivecore.util.TimeDiffUtil; +import com.massivecraft.massivecore.util.TimeUnit; +import com.massivecraft.massivecore.util.Txt; +import org.apache.commons.lang.StringEscapeUtils; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.dynmap.DynmapAPI; +import org.dynmap.markers.AreaMarker; +import org.dynmap.markers.MarkerAPI; +import org.dynmap.markers.MarkerSet; + +import java.util.ArrayDeque; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class EngineDynmap extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineDynmap i = new EngineDynmap(); + + public static EngineDynmap get() { + return i; + } + + private EngineDynmap() { + // Async + this.setSync(false); + + // Every 15 seconds + this.setPeriod(15 * 20L); + } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private DynmapAPI dynmapApi; + private MarkerAPI markerApi; + private MarkerSet markerset; + + // -------------------------------------------- // + // RUN: UPDATE + // -------------------------------------------- // + + // Thread Safe / Asynchronous: Yes + @Override + public void run() { + // Is Dynmap enabled? + if (MConf.get().dynmapEnabled) { + this.perform(); + } else { + this.disable(); + } + } + + public void perform() { + long before = System.currentTimeMillis(); + + // We do what we can here. + // You /can/ run this method from the main server thread but it's not recommended at all. + // This method is supposed to be run async to avoid locking the main server thread. + //final Map homes = createHomes(); + final Map areas = createAreas(); + + logTimeSpent("Async", before); + + // Shedule non thread safe sync at the end! + Bukkit.getScheduler().scheduleSyncDelayedTask(Factions.get(), () -> this.updateFactionsDynmap(areas)); + } + + public void updateFactionsDynmap(Map areas) { + long before = System.currentTimeMillis(); + + if (!Bukkit.isPrimaryThread()) { + throw new IllegalStateException("async"); + } + + if (!fetchDynmapAPI()) { + return; + } + + // createLayer() is thread safe but it makes use of fields set in fetchDynmapAPI() so we must have it after. + if (!updateLayer(createLayer())) { + return; + } + + updateAreas(areas); + + logTimeSpent("Sync", before); + } + + public void disable() { + if (this.markerset != null) { + this.markerset.deleteMarkerSet(); + this.markerset = null; + } + } + + // Thread Safe / Asynchronous: Yes + public static void logTimeSpent(String name, long start) { + if (!MConf.get().dynmapLogTimeSpent) { + return; + } + long end = System.currentTimeMillis(); + long duration = end - start; + + String message = Txt.parse("Dynmap %s took %dms.", name, duration); + Factions.get().log(message); + } + + // -------------------------------------------- // + // API + // -------------------------------------------- // + + // Thread Safe / Asynchronous: No + public boolean fetchDynmapAPI() { + // Get DynmapAPI + this.dynmapApi = (DynmapAPI) Bukkit.getPluginManager().getPlugin("dynmap"); + if (this.dynmapApi == null) { + logSevere("Could not access the DynmapAPI."); + return false; + } + + // Get MarkerAPI + this.markerApi = this.dynmapApi.getMarkerAPI(); + if (this.markerApi == null) { + logSevere("Could not access the MarkerAPI."); + return false; + } + + return true; + } + + // -------------------------------------------- // + // UPDATE: Layer + // -------------------------------------------- // + + // Thread Safe / Asynchronous: Yes + public LayerValues createLayer() { + return new LayerValues( + MConf.get().dynmapLayerName, + MConf.get().dynmapLayerMinimumZoom, + MConf.get().dynmapLayerPriority, + MConf.get().dynmapLayerHiddenByDefault + ); + } + + // Thread Safe / Asynchronous: No + public boolean updateLayer(LayerValues temp) { + this.markerset = temp.ensureExistsAndUpdated(this.markerApi, IntegrationDynmap.FACTIONS_MARKERSET); + return this.markerset != null; + } + + // -------------------------------------------- // + // UPDATE: AREAS + // -------------------------------------------- // + + // Thread Safe: YES + public Map createAreas() { + Map>> worldFactionChunks = BoardColl.get().getWorldToFactionToChunks(false); + return createAreas(worldFactionChunks); + + } + + // Thread Safe: YES + public Map createAreas(Map>> worldFactionChunks) { + // For each world create the areas + return worldFactionChunks.entrySet().stream() + .map(this::createAreas) + // And combine all of those into a single map: + .map(Map::entrySet) + .flatMap(Set::stream) + .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); + } + + public Map createAreas(Entry>> superEntry) { + return createAreas(superEntry.getKey(), superEntry.getValue()); + } + + public Map createAreas(String world, Map> map) { + // For each entry convert it into the appropriate map (with method below) + return map.entrySet().stream() + .map(e -> createAreas(world, e)) + // And combine all of those into a single map: + .map(Map::entrySet) + .flatMap(Set::stream) + .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); + } + + public Map createAreas(String world, Entry> entry) { + return createAreas(world, entry.getKey(), entry.getValue()); + } + + public Map createAreas(String world, Faction faction, Set chunks) { + // If the faction is visible ... + if (!isVisible(faction, world)) { + return Collections.emptyMap(); + } + + // ... and has any chunks ... + if (chunks.isEmpty()) { + return Collections.emptyMap(); + } + + Map ret = new MassiveMap<>(); + + // Get info + String description = getDescription(faction); + DynmapStyle style = this.getStyle(faction); + + // Here we start of with all chunks + // This field is slowly cleared when the chunks are grouped into polygons + Set allChunksSource = new MassiveSet<>(chunks); + + while (!allChunksSource.isEmpty()) { + Iterator it = allChunksSource.iterator(); + PS somePs = it.next(); + + List linelist = new MassiveList<>(); + // Create the polygon + Set polygonChunks = new MassiveSet<>(); + floodFillTarget(allChunksSource, polygonChunks, somePs); + + List polygonCorners = new MassiveList<>(); + for (PS chunk : polygonChunks) { + for (Direction d : Direction.values()) { + polygonCorners.add(d.getCorner(chunk)); + } + } + + Set points = new MassiveSet<>(); + for (PS corner : polygonCorners) { + if (points.contains(corner)) { + points.remove(corner); + } else { + points.add(corner); + } + } + + Map edges_h = new MassiveMap<>(); + Map edges_v = new MassiveMap<>(); + + List sorted_x = new MassiveList<>(points); + Collections.sort(sorted_x, this::xThenZ); + List sorted_z = new MassiveList<>(points); + Collections.sort(sorted_z, this::zThenX); + + // Create horizontal edges + for (int i = 0; i < points.size(); ) { + int curr_z = sorted_z.get(i).getChunkZ(); + while (i < points.size() && curr_z == sorted_z.get(i + 1).getChunkZ()) { + edges_h.put(sorted_z.get(i), sorted_z.get(i + 1)); + edges_h.put(sorted_z.get(i + 1), sorted_z.get(i)); + i += 2; + } + } + + // Create vertical edges + for (int i = 0; i < points.size(); ) { + int curr_x = sorted_x.get(i).getChunkX(); + while (i < points.size() && curr_x == sorted_x.get(i + 1).getChunkX()) { + edges_v.put(sorted_x.get(i), sorted_x.get(i + 1)); + edges_v.put(sorted_x.get(i + 1), sorted_x.get(i)); + i += 2; + } + } + + //List linelist = getLineList(polygonChunks); + + + linelist = new MassiveList<>(new LinkedHashSet<>(linelist)); + + for (Direction d : Direction.values()) { + linelist.add(d.getCorner(somePs)); + } + + // Build information for specific area + String markerId = calcMarkerId(world, faction); + AreaMarkerValues values = new AreaMarkerValues(faction.getName(), world, linelist.toArray(new PS[]{}), description, style); + ret.put(markerId, values); + } + + return ret; + } + + private int zThenX(PS a, PS b) { + if (a.getChunkZ() < b.getChunkZ() || (a.getChunkZ().equals(b.getChunkZ()) && a.getChunkX() < b.getChunkX())) { + return -1; + } else if (a.equals(b)) { + return 0; + } else { + return 1; + } + } + + private int xThenZ(PS a, PS b) { + if (a.getChunkX() < b.getChunkX() || (a.getChunkX().equals(b.getChunkX()) && a.getChunkZ() < b.getChunkZ())) { + return -1; + } else if (a.equals(b)) { + return 0; + } else { + return 1; + } + } + + private static PS getMinimum(Collection pss) { + int minimumX = Integer.MAX_VALUE; + int minimumZ = Integer.MAX_VALUE; + + for (PS chunk : pss) { + int chunkX = chunk.getChunkX(); + int chunkZ = chunk.getChunkZ(); + + if (chunkX < minimumX) { + minimumX = chunkX; + minimumZ = chunkZ; + } else if (chunkX == minimumX && chunkZ < minimumZ) { + minimumZ = chunkZ; + } + } + return PS.valueOf(minimumX, minimumZ); + } + + // XPLUS, ZPLUS, XMINUS, ZMINUS + private static List getLineList(Set polygonChunks) { + PS minimumChunk = getMinimum(polygonChunks); + + //final int initialX = minimumChunk.getChunkX(); + //final int initialZ = minimumChunk.getChunkZ(); + //int currentX = initialX; + //int currentZ = initialZ; + + PS currentChunk = minimumChunk; + + Direction direction = Direction.XPLUS; + List linelist = new MassiveList<>(); + + linelist.add(minimumChunk); // Add start point + while ((!currentChunk.equals(minimumChunk)) || (direction != Direction.ZMINUS)) { + PS adjacent = direction.adjacent(currentChunk); + PS corner = direction.getCorner(currentChunk); + // If the adjacent chunk is not present + + if (!polygonChunks.contains(adjacent)) { // Right turn? + linelist.add(corner); // Finish line + direction = direction.turnRight(); // Change direction + } + + // If the chunk left of the adjacent is not present + else if (!polygonChunks.contains(direction.turnLeft().adjacent(adjacent))) { // Straight? + currentChunk = adjacent; + } else { // Left turn + linelist.add(corner); // Finish line + direction = direction.turnLeft(); + + // Left turn of adjacent + currentChunk = direction.adjacent(adjacent); + } + } + + return linelist; + } + + // IS CLAIMED + + private static boolean isSoutheastClaimed(PS ps, Collection polygon) { + return polygon.contains(PS.valueOf(ps.getChunkX() - 1, ps.getChunkZ() + 1)); + } + + private static boolean isNortheastClaimed(PS ps, Collection polygon) { + return polygon.contains(PS.valueOf(ps.getChunkX() + 1, ps.getChunkZ() + 1)); + } + + private static boolean isSouthwestClaimed(PS ps, Collection polygon) { + return polygon.contains(PS.valueOf(ps.getChunkX() - 1, ps.getChunkZ() - 1)); + } + + private static boolean isNorthwestClaimed(PS ps, Collection polygon) { + return polygon.contains(PS.valueOf(ps.getChunkX() + 1, ps.getChunkZ() - 1)); + } + + // GET CHUNKS + + private static PS getNortheastPS(PS ps) { + return PS.valueOf(ps.getChunkX() + 1, ps.getChunkZ() + 1); + } + + private static PS getSoutheastPS(PS ps) { + return PS.valueOf(ps.getChunkX(), ps.getChunkZ() + 1); + } + + private static PS getSouthwestPS(PS ps) { + return PS.valueOf(ps.getChunkX(), ps.getChunkZ()); + } + + private static PS getNorthwestPS(PS ps) { + return PS.valueOf(ps.getChunkX() + 1, ps.getChunkZ()); + } + + // This markerIndex, is if a faction has several claims in a single world + private int markerIdx = 0; + private String lastPartialMarkerId = ""; + + public String calcMarkerId(String world, Faction faction) { + // Calc current partial + String partial = IntegrationDynmap.FACTIONS_AREA_ + world + "__" + faction.getId() + "__"; + + // If different than last time, then reset the counter + if (!partial.equals(lastPartialMarkerId)) { + markerIdx = 0; + } + + this.lastPartialMarkerId = partial; + + return partial + markerIdx++; + } + + // Thread Safe: NO + public void updateAreas(Map values) { + // Cleanup old markers + this.markerset.getAreaMarkers().stream() // Get current markers + .filter(am -> !values.containsKey(am.getMarkerID())) // That are not in the new map + .forEach(AreaMarker::deleteMarker); // and delete them + + + // Map Current + Map markers = getMarkerMap(this.markerset); + + // Loop New + values.forEach((markerId, value) -> + value.ensureExistsAndUpdated(markers.get(markerId), this.markerApi, this.markerset, markerId)); + + } + + private static Map getMarkerMap(MarkerSet markerSet) { + return markerSet.getAreaMarkers().stream().collect(Collectors.toMap(AreaMarker::getMarkerID, m -> m)); + } + + // -------------------------------------------- // + // UTIL & SHARED + // -------------------------------------------- // + + // Thread Safe / Asynchronous: Yes + private String getDescription(Faction faction) { + String ret = "

"; + + // Name + String name = faction.getName(); + ret = addToHtml(ret, "name", name); + + // Description + String description = faction.getDescriptionDesc(); + ret = addToHtml(ret, "description", description); + + // MOTD (probably shouldn't be shown but if the server owner specifies it, I don't care) + String motd = faction.getMotd(); + if (motd != null) { + ret = addToHtml(ret, "motd", motd); + } + + // Age + long ageMillis = faction.getAge(); + LinkedHashMap ageUnitcounts = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(ageMillis, TimeUnit.getAllButMillisSecondsAndMinutes()), 3); + String age = TimeDiffUtil.formatedVerboose(ageUnitcounts, ""); + ret = addToHtml(ret, "age", age); + + // Money + String money = "unavailable"; + if (Econ.isEnabled() && MConf.get().dynmapShowMoneyInDescription) { + money = Money.format(Econ.getMoney(faction)); + } + ret = addToHtml(ret, "money", money); + + // Flags + Map flags = MFlag.getAll().stream() + .filter(MFlag::isVisible) + .collect(Collectors.toMap(m -> m, faction::getFlag)); + + List flagMapParts = new MassiveList<>(); + List flagTableParts = new MassiveList<>(); + + for (Entry entry : flags.entrySet()) { + String flagName = entry.getKey().getName(); + boolean value = entry.getValue(); + + String bool = String.valueOf(value); + String color = calcBoolcolor(flagName, value); + String boolcolor = calcBoolcolor(String.valueOf(value), value); + + ret = ret.replace("%" + flagName + ".bool%", bool); // true + ret = ret.replace("%" + flagName + ".color%", color); // monsters (red or green) + ret = ret.replace("%" + flagName + ".boolcolor%", boolcolor); // true (red or green) + + flagMapParts.add(flagName + ": " + boolcolor); + flagTableParts.add(color); + } + + String flagMap = Txt.implode(flagMapParts, "
\n"); + ret = ret.replace("%flags.map%", flagMap); + + // The server can specify the wished number of columns + // So we loop over the possibilities + for (int cols = 1; cols <= 10; cols++) { + String flagTable = getHtmlAsciTable(flagTableParts, cols); + ret = ret.replace("%flags.table" + cols + "%", flagTable); + } + + // Players + List playersList = faction.getMPlayers(); + String playersCount = String.valueOf(playersList.size()); + String players = getHtmlPlayerString(playersList); + + MPlayer playersLeaderObject = faction.getLeader(); + String playersLeader = getHtmlPlayerName(playersLeaderObject); + + ret = ret.replace("%players%", players); + ret = ret.replace("%players.count%", playersCount); + ret = ret.replace("%players.leader%", playersLeader); + + return ret; + } + + public static String getHtmlAsciTable(Collection strings, final int cols) { + StringBuilder ret = new StringBuilder(); + + int count = 0; + for (Iterator iter = strings.iterator(); iter.hasNext(); ) { + String string = iter.next(); + count++; + + ret.append(string); + + if (iter.hasNext()) { + boolean lineBreak = count % cols == 0; + ret.append(lineBreak ? "
" : " | "); + } + } + + return ret.toString(); + } + + public static String getHtmlPlayerString(List mplayers) { + List names = mplayers.stream().map(EngineDynmap::getHtmlPlayerName).collect(Collectors.toList()); + return Txt.implodeCommaAndDot(names); + } + + public static String getHtmlPlayerName(MPlayer mplayer) { + if (mplayer == null) { + return "none"; + } + return StringEscapeUtils.escapeHtml(mplayer.getName()); + } + + public static String calcBoolcolor(String string, boolean bool) { + return "" + string + ""; + } + + public static String addToHtml(String ret, String target, String replace) { + if (ret == null) { + throw new NullPointerException("ret"); + } + if (target == null) { + throw new NullPointerException("target"); + } + if (replace == null) { + throw new NullPointerException("replace"); + } + + target = "%" + target + "%"; + replace = ChatColor.stripColor(replace); + replace = StringEscapeUtils.escapeHtml(replace); + return ret.replace(target, replace); + } + + // Thread Safe / Asynchronous: Yes + private boolean isVisible(Faction faction, String world) { + if (faction == null) { + throw new NullPointerException("faction"); + } + if (world == null) { + throw new NullPointerException("world"); + } + + final String factionId = faction.getId(); + final String factionName = faction.getName(); + final String worldId = "world:" + world; + + Set ids = MUtil.set(factionId, factionName, worldId); + + if (factionId == null) { + throw new NullPointerException("faction id"); + } + if (factionName == null) { + throw new NullPointerException("faction name"); + } + + Set visible = MConf.get().dynmapVisibleFactions; + Set hidden = MConf.get().dynmapHiddenFactions; + + + if (!visible.isEmpty() && visible.stream().noneMatch(ids::contains)) { + return false; + } + + if (!hidden.isEmpty() && hidden.stream().anyMatch(ids::contains)) { + return false; + } + + + return true; + } + + // Thread Safe / Asynchronous: Yes + public DynmapStyle getStyle(Faction faction) { + Map styles = MConf.get().dynmapFactionStyles; + + return DynmapStyle.coalesce( + styles.get(faction.getId()), + styles.get(faction.getName()), + MConf.get().dynmapDefaultStyle + ); + } + + public static void logSevere(String msg) { + String message = ChatColor.RED.toString() + msg; + Factions.get().log(message); + } + + enum Direction { + XPLUS, ZPLUS, XMINUS, ZMINUS; + + public PS adjacent(PS ps) { + switch (this) { + case XPLUS: + return PS.valueOf(ps.getChunkX() + 1, ps.getChunkZ()); + case ZPLUS: + return PS.valueOf(ps.getChunkX(), ps.getChunkZ() + 1); + case XMINUS: + return PS.valueOf(ps.getChunkX() - 1, ps.getChunkZ()); + case ZMINUS: + return PS.valueOf(ps.getChunkX(), ps.getChunkZ() - 1); + } + throw new RuntimeException("say what"); + } + + public PS getCorner(PS ps) { + switch (this) { + case XPLUS: + return PS.valueOf(ps.getChunkX() + 1, ps.getChunkZ()); + case ZPLUS: + return PS.valueOf(ps.getChunkX() + 1, ps.getChunkZ() + 1); + case XMINUS: + return PS.valueOf(ps.getChunkX(), ps.getChunkZ() + 1); + case ZMINUS: + return PS.valueOf(ps.getChunkX(), ps.getChunkZ()); + } + throw new RuntimeException("say what"); + } + + public Direction turnRight() { + return values()[(this.ordinal() + 1) % values().length]; + } + + public Direction turnAround() { + return this.turnRight().turnRight(); + } + + public Direction turnLeft() { + return this.turnRight().turnRight().turnRight(); + } + } + + private void floodFillTarget(Collection source, Collection destination, PS startChunk) { + // Create the deque + ArrayDeque stack = new ArrayDeque<>(); + stack.push(startChunk); + + // And for each item in the queue + while (!stack.isEmpty()) { + PS next = stack.pop(); + + // If it is in the source + // Remove it from there to avoid double-counting (and endless recursion) + if (!source.remove(next)) { + continue; + } + + // Add to destination + destination.add(next); + + // And look in adjacent chunks that are within the source + Stream.of(Direction.values()) + .map(d -> d.adjacent(next)) + .filter(source::contains) + .forEach(stack::push); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/integration/dynmap/IntegrationDynmap.java b/src/main/java/com/massivecraft/factions/integration/dynmap/IntegrationDynmap.java new file mode 100644 index 00000000..a148a998 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/integration/dynmap/IntegrationDynmap.java @@ -0,0 +1,55 @@ +package com.massivecraft.factions.integration.dynmap; + +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.Integration; + +public class IntegrationDynmap extends Integration { + // -------------------------------------------- // + // CONSTANTS + // -------------------------------------------- // + + // Constants must be here rather than in EngineDynmap. + // MConf relies on DynmapStyle which relies on these constants + // and we must be able to load MConf without EngineDynmap. + public final static int BLOCKS_PER_CHUNK = 16; + + public final static String FACTIONS = "factions"; + public final static String FACTIONS_ = FACTIONS + "_"; + + public final static String FACTIONS_MARKERSET = FACTIONS_ + "markerset"; + + public final static String FACTIONS_AREA = FACTIONS_ + "area"; + public final static String FACTIONS_AREA_ = FACTIONS_AREA + "_"; + + public final static transient String DYNMAP_STYLE_LINE_COLOR = "#00FF00"; + public final static transient double DYNMAP_STYLE_LINE_OPACITY = 0.8D; + public final static transient int DYNMAP_STYLE_LINE_WEIGHT = 3; + public final static transient String DYNMAP_STYLE_FILL_COLOR = "#00FF00"; + public final static transient double DYNMAP_STYLE_FILL_OPACITY = 0.35D; + public final static transient String DYNMAP_STYLE_HOME_MARKER = "greenflag"; + public final static transient boolean DYNMAP_STYLE_BOOST = false; + + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static IntegrationDynmap i = new IntegrationDynmap(); + + public static IntegrationDynmap get() { + return i; + } + + private IntegrationDynmap() { + this.setPluginName("dynmap"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Engine getEngine() { + return EngineDynmap.get(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/integration/dynmap/LayerValues.java b/src/main/java/com/massivecraft/factions/integration/dynmap/LayerValues.java new file mode 100644 index 00000000..6128cae9 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/integration/dynmap/LayerValues.java @@ -0,0 +1,122 @@ +package com.massivecraft.factions.integration.dynmap; + +import com.massivecraft.massivecore.util.MUtil; +import org.dynmap.markers.MarkerAPI; +import org.dynmap.markers.MarkerSet; + +public class LayerValues { + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final String label; + + public String getLabel() { + return label; + } + + public LayerValues withLabel(String label) { + return new LayerValues(label, minimumZoom, priority, hiddenByDefault); + } + + private final int minimumZoom; + + public int getMinimumZoom() { + return minimumZoom; + } + + public LayerValues withMinimumZoom(int minimumZoom) { + return new LayerValues(label, minimumZoom, priority, hiddenByDefault); + } + + private final int priority; + + public int getPriority() { + return priority; + } + + public LayerValues withPriority(int priority) { + return new LayerValues(label, minimumZoom, priority, hiddenByDefault); + } + + private final boolean hiddenByDefault; + + public boolean isHiddenByDefault() { + return hiddenByDefault; + } + + public LayerValues withHidenByDefault(boolean hideByDefault) { + return new LayerValues(label, minimumZoom, priority, hideByDefault); + } + + // -------------------------------------------- // + // CONSTRUCTOR + // -------------------------------------------- // + + public LayerValues(String label, int minimumZoom, int priority, boolean hideByDefault) { + this.label = label; + this.minimumZoom = minimumZoom; + this.priority = priority; + this.hiddenByDefault = hideByDefault; + } + + // -------------------------------------------- // + // MASTER + // -------------------------------------------- // + + public MarkerSet ensureExistsAndUpdated(MarkerAPI api, String id) { + MarkerSet set = api.getMarkerSet(id); + if (set == null) { + set = this.create(api, id); + } else { + this.update(set); + } + + if (set == null) { + EngineDynmap.logSevere("Could not create the Faction Markerset/Layer"); + } + + return set; + } + + // -------------------------------------------- // + // CREATE + // -------------------------------------------- // + + public MarkerSet create(MarkerAPI markerApi, String id) { + MarkerSet ret = markerApi.createMarkerSet(id, this.label, null, false); // ("null, false" at the end means "all icons allowed, not perisistent") + if (ret == null) { + return null; + } + + // Minimum Zoom + if (this.minimumZoom > 0) { + ret.setMinZoom(this.getMinimumZoom()); + } + + // Priority + ret.setLayerPriority(this.getPriority()); + + // Hide by Default + ret.setHideByDefault(this.isHiddenByDefault()); + return ret; + } + + // -------------------------------------------- // + // UPDATE + // -------------------------------------------- // + + public void update(MarkerSet markerset) { + // Minimum Zoom + if (this.minimumZoom > 0) { + MUtil.setIfDifferent(this.getMinimumZoom(), markerset::getMinZoom, markerset::setMinZoom); + } + + // Set other values + MUtil.setIfDifferent(this.getLabel(), markerset::getMarkerSetLabel, markerset::setMarkerSetLabel); + MUtil.setIfDifferent(this.getPriority(), markerset::getLayerPriority, markerset::setLayerPriority); + MUtil.setIfDifferent(this.isHiddenByDefault(), markerset::getHideByDefault, markerset::setHideByDefault); + } + +} diff --git a/src/main/java/com/massivecraft/factions/integration/dynmap/MarkerValues.java b/src/main/java/com/massivecraft/factions/integration/dynmap/MarkerValues.java new file mode 100644 index 00000000..b6a5bc1a --- /dev/null +++ b/src/main/java/com/massivecraft/factions/integration/dynmap/MarkerValues.java @@ -0,0 +1,174 @@ +package com.massivecraft.factions.integration.dynmap; + +import com.massivecraft.massivecore.util.MUtil; +import org.dynmap.markers.Marker; +import org.dynmap.markers.MarkerAPI; +import org.dynmap.markers.MarkerIcon; +import org.dynmap.markers.MarkerSet; + +public class MarkerValues { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final String label; + + public String getLabel() { + return label; + } + + public MarkerValues withLabel(String label) { + return new MarkerValues(label, world, x, y, z, iconName, description); + } + + private final String world; + + public String getWorld() { + return world; + } + + public MarkerValues withWorld(String world) { + return new MarkerValues(label, world, x, y, z, iconName, description); + } + + private final double x; + + public double getX() { + return x; + } + + public MarkerValues withX(double x) { + return new MarkerValues(label, world, x, y, z, iconName, description); + } + + private final double y; + + public double getY() { + return y; + } + + public MarkerValues withY(double y) { + return new MarkerValues(label, world, x, y, z, iconName, description); + } + + private final double z; + + public double getZ() { + return z; + } + + public MarkerValues withZ(double z) { + return new MarkerValues(label, world, x, y, z, iconName, description); + } + + private final String iconName; + + public String getIconName() { + return iconName; + } + + public MarkerValues withIconName(String iconName) { + return new MarkerValues(label, world, x, y, z, iconName, description); + } + + private final String description; + + public String getDescription() { + return description; + } + + public MarkerValues withDescription(String description) { + return new MarkerValues(label, world, x, y, z, iconName, description); + } + + // -------------------------------------------- // + // CONSTRUCTOR + // -------------------------------------------- // + + public MarkerValues(String label, String world, double x, double y, double z, String iconName, String description) { + this.label = label; + this.world = world; + this.x = x; + this.y = y; + this.z = z; + this.iconName = iconName; + this.description = description; + } + + // -------------------------------------------- // + // MAKE SURE EXISTS + // -------------------------------------------- // + + public Marker ensureExistsAndUpdated(MarkerAPI markerApi, MarkerSet markerset, String id) { + throw new UnsupportedOperationException("todo"); + } + + // -------------------------------------------- // + // CREATE + // -------------------------------------------- // + + public Marker create(MarkerAPI markerApi, MarkerSet markerset, String markerId) { + Marker ret = markerset.createMarker( + markerId, + this.getLabel(), + this.getWorld(), + this.getX(), + this.getY(), + this.getZ(), + getMarkerIcon(markerApi, this.getIconName()), + false // not persistent + ); + + if (ret == null) { + return null; + } + + ret.setDescription(this.getDescription()); + + return ret; + } + + // -------------------------------------------- // + // UPDATE + // -------------------------------------------- // + + public void update(MarkerAPI markerApi, MarkerSet markerset, Marker marker) { + if + ( + !MUtil.equals(marker.getWorld(), this.getWorld()) + || + marker.getX() != this.getX() + || + marker.getY() != this.getY() + || + marker.getZ() != this.getZ() + ) { + marker.setLocation( + this.getWorld(), + this.getX(), + this.getY(), + this.getZ() + ); + } + + MUtil.setIfDifferent(this.getLabel(), marker::getLabel, marker::setLabel); + + MarkerIcon icon = getMarkerIcon(markerApi, this.iconName); + MUtil.setIfDifferent(icon, marker::getMarkerIcon, marker::setMarkerIcon); + + MUtil.setIfDifferent(this.getDescription(), marker::getDescription, marker::setDescription); + } + + // -------------------------------------------- // + // UTIL + // -------------------------------------------- // + + public static MarkerIcon getMarkerIcon(MarkerAPI markerApi, String name) { + MarkerIcon ret = markerApi.getMarkerIcon(name); + if (ret == null) { + ret = markerApi.getMarkerIcon(IntegrationDynmap.DYNMAP_STYLE_HOME_MARKER); + } + return ret; + } + +} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/integration/lwc/EngineLwc.java b/src/main/java/com/massivecraft/factions/integration/lwc/EngineLwc.java new file mode 100644 index 00000000..77fafbe5 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/integration/lwc/EngineLwc.java @@ -0,0 +1,130 @@ +package com.massivecraft.factions.integration.lwc; + +import com.griefcraft.lwc.LWC; +import com.griefcraft.model.Protection; +import com.griefcraft.sql.PhysDB; +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.event.EventFactionsChunkChangeType; +import com.massivecraft.factions.event.EventFactionsChunksChange; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.IdUtil; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; + +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + + +public class EngineLwc extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineLwc i = new EngineLwc(); + + public static EngineLwc get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void setActiveInner(boolean active) { + if (active) { + LWC.getInstance().getModuleLoader().registerModule(Factions.get(), new FactionsLwcModule(Factions.get())); + } else { + if (LWC.getInstance() != null) { + LWC.getInstance().getModuleLoader().removeModules(Factions.get()); + } + } + } + + // -------------------------------------------- // + // LISTENER + // -------------------------------------------- // + + public void removeProtectionsOnChunkChange(Faction newFaction, EventFactionsChunkChangeType type, Set chunks) { + // If we are supposed to clear at this chunk change type ... + Boolean remove = MConf.get().lwcRemoveOnChange.get(type); + if (remove == null) { + return; + } + if (remove == false) { + return; + } + + // ... then remove for all other factions than the new one. + // First we wait one tick to make sure the chunk ownership changes have been applied. + // Then we remove the protections but we do it asynchronously to not lock the main thread. + for (PS chunk : chunks) { + removeAlienProtectionsAsyncNextTick(chunk, newFaction); + } + } + + public void removeProtectionsOnChunkChange(Faction newFaction, Map> typeChunks) { + for (Entry> typeChunk : typeChunks.entrySet()) { + final EventFactionsChunkChangeType type = typeChunk.getKey(); + final Set chunks = typeChunk.getValue(); + removeProtectionsOnChunkChange(newFaction, type, chunks); + } + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void removeProtectionsOnChunkChange(EventFactionsChunksChange event) { + removeProtectionsOnChunkChange(event.getNewFaction(), event.getTypeChunks()); + } + + // -------------------------------------------- // + // UTIL + // -------------------------------------------- // + + // This method causes LWC to run an SQL query which can take a few milliseconds. + // For that reason this method should not be executed in the main server thread. + // After looking through the source code of LWC I am also hopeful this is thread safe. + public static List getProtectionsInChunk(PS chunkPs) { + final int xmin = chunkPs.getChunkX() * 16; + final int xmax = xmin + 15; + + final int ymin = 0; + final int ymax = 255; + + final int zmin = chunkPs.getChunkZ() * 16; + final int zmax = zmin + 15; + + PhysDB db = LWC.getInstance().getPhysicalDatabase(); + return db.loadProtections(chunkPs.getWorld(), xmin, xmax, ymin, ymax, zmin, zmax); + } + + // As with the method above: Thread safe and slow. Do run asynchronously. + public static void removeAlienProtectionsRaw(PS chunkPs, Faction faction) { + List nonAliens = faction.getMPlayers(); + for (Protection protection : getProtectionsInChunk(chunkPs)) { + // NOTE: The LWC protection owner is still the name and not the UUID. For that reason we must convert it. + String ownerName = protection.getOwner(); + String ownerId = IdUtil.getId(ownerName); + MPlayer owner = MPlayer.get(ownerId); + if (nonAliens.contains(owner)) { + continue; + } + protection.remove(); + } + } + + public static void removeAlienProtectionsAsync(final PS chunkPs, final Faction faction) { + Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> removeAlienProtectionsRaw(chunkPs, faction)); + } + + public static void removeAlienProtectionsAsyncNextTick(final PS chunkPs, final Faction faction) { + Bukkit.getScheduler().runTaskLater(Factions.get(), () -> removeAlienProtectionsAsync(chunkPs, faction), 0); + } + +} diff --git a/src/main/java/com/massivecraft/factions/integration/lwc/FactionsLwcModule.java b/src/main/java/com/massivecraft/factions/integration/lwc/FactionsLwcModule.java new file mode 100644 index 00000000..812b6528 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/integration/lwc/FactionsLwcModule.java @@ -0,0 +1,110 @@ +package com.massivecraft.factions.integration.lwc; + +import com.griefcraft.lwc.LWC; +import com.griefcraft.model.Protection; +import com.griefcraft.scripting.JavaModule; +import com.griefcraft.scripting.event.LWCProtectionInteractEvent; +import com.griefcraft.scripting.event.LWCProtectionRegisterEvent; +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.engine.EnginePermBuild; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.SoundEffect; +import com.massivecraft.massivecore.mixin.MixinMessage; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.IdUtil; +import com.massivecraft.massivecore.util.SmokeUtil; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; + +@SuppressWarnings("unused") +public class FactionsLwcModule extends JavaModule { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + // These plugin variables must be present. + // They are set by LWC using reflection somehow. + private Factions plugin; + private LWC lwc; + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public FactionsLwcModule(Factions plugin) { + this.plugin = plugin; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + // + + @Override + public void onRegisterProtection(LWCProtectionRegisterEvent event) { + // If this feature is enabled ... + if (!MConf.get().lwcMustHaveBuildRightsToCreate) { + return; + } + + // ... and the player don't have build rights here ... + // NOTE: We verbosely check the build rights so that a proper info message is sent + if (EnginePermBuild.canPlayerBuildAt(event.getPlayer(), PS.valueOf(event.getBlock()), true)) { + return; + } + + // ... then cancel the event. + event.setCancelled(true); + } + + @Override + public void onProtectionInteract(LWCProtectionInteractEvent event) { + // If this feature is enabled ... + if (!MConf.get().lwcRemoveIfNoBuildRights) { + return; + } + + // ... gather data ... + final Protection protection = event.getProtection(); + final Block block = protection.getBlock(); + final PS ps = PS.valueOf(block); + // NOTE: The LWC protection owner is still the name and not the UUID. For that reason we must convert it. + final String ownerName = protection.getOwner(); + final String ownerId = IdUtil.getId(ownerName); + final MPlayer mowner = MPlayer.get(ownerId); + if (mowner == null) { + return; + } + + // ... and if the protection owner no longer has build rights for the area ... + // NOTE: We silently check the build rights for the protection owner. + // NOTE: The protection owner may even be offline at the moment. + if (EnginePermBuild.canPlayerBuildAt(mowner, ps, false)) { + return; + } + + // ... remove the protection ... + protection.remove(); + + // ... cancel the event ... + // NOTE: The first time you click nothing but the unlock should happen. + // NOTE: This way it's more obvious the auto unlock system kicked in. + // NOTE: No inventory will get opened. + event.setResult(Result.CANCEL); + + // ... play FX ... + Location location = block.getLocation(); + SmokeUtil.spawnCloudSimple(location); + + SoundEffect.valueOf("DOOR_OPEN", 1, 1).run(location); + + // ... and inform. + Player player = event.getPlayer(); + String message = Txt.parse("Factions removed %s's LWC. They lacked build rights.", mowner.getDisplayName(player)); + MixinMessage.get().messageOne(player, message); + } + +} diff --git a/src/main/java/com/massivecraft/factions/integration/lwc/IntegrationLwc.java b/src/main/java/com/massivecraft/factions/integration/lwc/IntegrationLwc.java new file mode 100644 index 00000000..e313a1db --- /dev/null +++ b/src/main/java/com/massivecraft/factions/integration/lwc/IntegrationLwc.java @@ -0,0 +1,30 @@ +package com.massivecraft.factions.integration.lwc; + +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.Integration; + +public class IntegrationLwc extends Integration { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static IntegrationLwc i = new IntegrationLwc(); + + public static IntegrationLwc get() { + return i; + } + + private IntegrationLwc() { + this.setPluginName("LWC"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Engine getEngine() { + return EngineLwc.get(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/integration/placeholderapi/IntegrationPlaceholderAPI.java b/src/main/java/com/massivecraft/factions/integration/placeholderapi/IntegrationPlaceholderAPI.java new file mode 100644 index 00000000..8871b7cd --- /dev/null +++ b/src/main/java/com/massivecraft/factions/integration/placeholderapi/IntegrationPlaceholderAPI.java @@ -0,0 +1,58 @@ +package com.massivecraft.factions.integration.placeholderapi; + +import com.massivecraft.massivecore.Integration; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +public class IntegrationPlaceholderAPI extends Integration { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static IntegrationPlaceholderAPI i = new IntegrationPlaceholderAPI(); + + public static IntegrationPlaceholderAPI get() { + return i; + } + + private IntegrationPlaceholderAPI() { + this.setPluginName("PlaceholderAPI"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void setIntegrationActiveInner(boolean active) { + if (active) { + PlaceholderFactions.get().register(); + } + } + + public static void ensureRegistered() { + if (PlaceholderFactions.get().isRegistered()) { + return; + } + PlaceholderFactions.get().register(); + } + + // If the PlaceholderAPI command is run to reload the config + // then we should reregister. + @EventHandler(priority = EventPriority.MONITOR) + public void lookForCommand(PlayerCommandPreprocessEvent event) { + String str = event.getMessage(); + if (str.startsWith("/")) { + str = str.substring(1); + } + + if (!str.startsWith("papi")) { + return; + } + Bukkit.getScheduler().runTaskLater(this.getPlugin(), IntegrationPlaceholderAPI::ensureRegistered, 10L); + } + + +} diff --git a/src/main/java/com/massivecraft/factions/integration/placeholderapi/PlaceholderFactions.java b/src/main/java/com/massivecraft/factions/integration/placeholderapi/PlaceholderFactions.java new file mode 100644 index 00000000..5b7d59d2 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/integration/placeholderapi/PlaceholderFactions.java @@ -0,0 +1,78 @@ +package com.massivecraft.factions.integration.placeholderapi; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.MPlayer; +import me.clip.placeholderapi.expansion.PlaceholderExpansion; +import org.bukkit.entity.Player; + +import java.text.DecimalFormat; + +public class PlaceholderFactions extends PlaceholderExpansion { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static PlaceholderFactions i = new PlaceholderFactions(); + + public static PlaceholderFactions get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getIdentifier() { + return "factions"; + } + + @Override + public String getAuthor() { + return "Madus"; + } + + @Override + public String getVersion() { + return Factions.get().getDescription().getVersion(); + } + + @Override + public String onPlaceholderRequest(Player player, String params) { + if (player == null) { + return null; + } + + MPlayer mplayer = MPlayer.get(player); + if ("role".equals(params)) { + params = "rank"; + } + DecimalFormat df = new DecimalFormat("#.##"); + + switch (params) { + case "faction": + return mplayer.getFaction().getName(); + case "power": + return df.format(mplayer.getPower()); + case "powermax": + return df.format(mplayer.getPowerMax()); + case "factionpower": + return df.format(mplayer.getFaction().getPower()); + case "factionpowermax": + return df.format(mplayer.getFaction().getPowerMax()); + case "title": + return mplayer.getTitle(); + case "rank": + return mplayer.getRank().getName(); + case "claims": + return Long.toString(BoardColl.get().getAll().stream().mapToInt(board -> board.getCount(mplayer.getFaction())).sum()); + case "onlinemembers": + return Integer.toString(mplayer.getFaction().getMPlayersWhereOnlineTo(mplayer).size()); + case "allmembers": + return Integer.toString(mplayer.getFaction().getMPlayers().size()); + } + return null; + } + +} diff --git a/src/main/java/com/massivecraft/factions/integration/venturechat/EngineVentureChat.java b/src/main/java/com/massivecraft/factions/integration/venturechat/EngineVentureChat.java new file mode 100644 index 00000000..a25ce811 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/integration/venturechat/EngineVentureChat.java @@ -0,0 +1,73 @@ +package com.massivecraft.factions.integration.venturechat; + +import com.massivecraft.factions.engine.EngineChat; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.Engine; +import mineverse.Aust1n46.chat.api.MineverseChatAPI; +import mineverse.Aust1n46.chat.api.MineverseChatPlayer; +import mineverse.Aust1n46.chat.channel.ChatChannel; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.AsyncPlayerChatEvent; + +import java.util.function.Predicate; + +public class EngineVentureChat extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineVentureChat i = new EngineVentureChat(); + + public static EngineVentureChat get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void setActiveInner(boolean active) { + + } + + // -------------------------------------------- // + // LISTENER + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) + public void filterFaction(AsyncPlayerChatEvent event) { + // Get player + Player player = event.getPlayer(); + MineverseChatPlayer chatPlayer = MineverseChatAPI.getMineverseChatPlayer(player); + ChatChannel channel = chatPlayer.getCurrentChannel(); + String channelName = channel.getName(); + + // If the channel is the Factions channel + boolean factionChat = channelName.equalsIgnoreCase(MConf.get().ventureChatFactionChannelName); + boolean allyChat = channelName.equalsIgnoreCase(MConf.get().ventureChatAllyChannelName); + if (!(factionChat || allyChat)) { + return; + } + + MPlayer mplayer = MPlayer.get(player); + Faction faction = mplayer.getFaction(); + + // Wilderness check + if (!MConf.get().ventureChatAllowFactionchatBetweenFactionless && faction.isNone()) { + mplayer.msg("Factionless can't use faction chat."); + event.setCancelled(true); + } + + Predicate predicateChannel = factionChat ? EngineChat.getPredicateIsInFaction(faction) : EngineChat.getPredicateIsAlly(faction); + Predicate isSpy = recipient -> MineverseChatAPI.getMineverseChatPlayer(recipient).isSpy(); + Predicate predicate = isSpy.or(predicateChannel); + + EngineChat.filterToPredicate(event, predicate); + } + +} diff --git a/src/main/java/com/massivecraft/factions/integration/venturechat/IntegrationVentureChat.java b/src/main/java/com/massivecraft/factions/integration/venturechat/IntegrationVentureChat.java new file mode 100644 index 00000000..f6321926 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/integration/venturechat/IntegrationVentureChat.java @@ -0,0 +1,30 @@ +package com.massivecraft.factions.integration.venturechat; + +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.Integration; + +public class IntegrationVentureChat extends Integration { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static IntegrationVentureChat i = new IntegrationVentureChat(); + + public static IntegrationVentureChat get() { + return i; + } + + private IntegrationVentureChat() { + this.setPluginName("VentureChat"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Engine getEngine() { + return EngineVentureChat.get(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/integration/worldguard/EngineWorldGuard.java b/src/main/java/com/massivecraft/factions/integration/worldguard/EngineWorldGuard.java new file mode 100644 index 00000000..49fb3211 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/integration/worldguard/EngineWorldGuard.java @@ -0,0 +1,140 @@ +package com.massivecraft.factions.integration.worldguard; + +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.event.EventFactionsChunksChange; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.ps.PS; +import com.sk89q.worldedit.bukkit.BukkitWorld; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldguard.LocalPlayer; +import com.sk89q.worldguard.WorldGuard; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.managers.RegionManager; +import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion; +import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class EngineWorldGuard extends Engine { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineWorldGuard i = new EngineWorldGuard(); + + public static EngineWorldGuard get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void setActiveInner(boolean active) { + + } + + // -------------------------------------------- // + // LISTENER + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void checkForRegion(EventFactionsChunksChange event) { + // Skip checks if the configuration has worldguardCheckEnabled disabled + if (!MConf.get().worldguardCheckEnabled) { + return; + } + + // Permanent Factions should not apply this rule + if (event.getNewFaction().getFlag(MFlag.ID_PERMANENT)) { + return; + } + + MPlayer mplayer = event.getMPlayer(); + Player player = mplayer.getPlayer(); + + // Only do this for players + if (player == null) { + return; + } + + LocalPlayer wrapperPlayer = WorldGuardPlugin.inst().wrapPlayer(player); + + if (!MConf.get().worldguardCheckWorldsEnabled.contains(player)) { + return; + } + + // For overriders don't bother checking + if (mplayer.isOverriding()) { + return; + } + + for (PS chunk : event.getChunks()) { + // Grab any regions in the chunk + final List regions = this.getProtectedRegionsFor(chunk); + + // Ensure there are actually regions to go over + if (regions == null || regions.isEmpty()) { + continue; + } + + for (ProtectedRegion region : regions) { + // Ensure it's not the global region, and check if they're a member + if (region instanceof GlobalProtectedRegion || region.isMember(wrapperPlayer)) { + continue; + } + + // Check for a permission - can't use Perm enum for this + if (player.hasPermission("factions.allowregionclaim." + region.getId())) { + continue; + } + + // No permission, notify player and stop claiming + mplayer.msg("You cannot claim the chunk at %s, %s as there is a region in the way.", chunk.getChunkX(), chunk.getChunkZ()); + + event.setCancelled(true); + return; + } + } + } + + // -------------------------------------------- // + // UTIL + // -------------------------------------------- // + + public List getProtectedRegionsFor(PS ps) { + // Find overlaps in the chunk + int minChunkX = ps.getChunkX() << 4; + int minChunkZ = ps.getChunkZ() << 4; + int maxChunkX = minChunkX + 15; + int maxChunkZ = minChunkZ + 15; + + int worldHeight = ps.asBukkitWorld().getMaxHeight(); + + BlockVector3 minChunk = BlockVector3.at(minChunkX, 0, minChunkZ); + BlockVector3 maxChunk = BlockVector3.at(maxChunkX, worldHeight, maxChunkZ); + + RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(new BukkitWorld(ps.asBukkitWorld())); + + String regionName = "factions_temp"; + ProtectedCuboidRegion region = new ProtectedCuboidRegion(regionName, minChunk, maxChunk); + + Map regionMap = regionManager.getRegions(); + List regionList = new ArrayList<>(regionMap.values()); + + // Let's find what we've overlapped + List overlapRegions = region.getIntersectingRegions(regionList); + + return overlapRegions; + } + +} diff --git a/src/main/java/com/massivecraft/factions/integration/worldguard/IntegrationWorldGuard.java b/src/main/java/com/massivecraft/factions/integration/worldguard/IntegrationWorldGuard.java new file mode 100644 index 00000000..c22ce014 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/integration/worldguard/IntegrationWorldGuard.java @@ -0,0 +1,30 @@ +package com.massivecraft.factions.integration.worldguard; + +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.Integration; + +public class IntegrationWorldGuard extends Integration { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static IntegrationWorldGuard i = new IntegrationWorldGuard(); + + public static IntegrationWorldGuard get() { + return i; + } + + private IntegrationWorldGuard() { + this.setPluginName("WorldGuard"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Engine getEngine() { + return EngineWorldGuard.get(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/mixin/PowerMixin.java b/src/main/java/com/massivecraft/factions/mixin/PowerMixin.java new file mode 100644 index 00000000..79aaae9d --- /dev/null +++ b/src/main/java/com/massivecraft/factions/mixin/PowerMixin.java @@ -0,0 +1,43 @@ +package com.massivecraft.factions.mixin; + +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.mixin.Mixin; + +public class PowerMixin extends Mixin { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static PowerMixin d = new PowerMixin(); + private static PowerMixin i = d; + + public static PowerMixin get() { + return i; + } + + // -------------------------------------------- // + // METHODS + // -------------------------------------------- // + + public double getMaxUniversal(MPlayer mplayer) { + return this.getMax(mplayer); + } + + public double getMax(MPlayer mplayer) { + return MConf.get().powerMax + mplayer.getPowerBoost(); + } + + public double getMin(MPlayer mplayer) { + return MConf.get().powerMin; + } + + public double getPerHour(MPlayer mplayer) { + return MConf.get().powerPerHour; + } + + public double getPerDeath(MPlayer mplayer) { + return MConf.get().powerPerDeath; + } + +} diff --git a/src/main/java/com/massivecraft/factions/predicate/PredicateCommandSenderFaction.java b/src/main/java/com/massivecraft/factions/predicate/PredicateCommandSenderFaction.java new file mode 100644 index 00000000..27ef8465 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/predicate/PredicateCommandSenderFaction.java @@ -0,0 +1,46 @@ +package com.massivecraft.factions.predicate; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.util.MUtil; +import org.bukkit.command.CommandSender; + +import java.io.Serializable; +import java.util.function.Predicate; + +public class PredicateCommandSenderFaction implements Predicate, Serializable { + private static final long serialVersionUID = 1L; + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final String factionId; + + public String getFactionId() { + return this.factionId; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public PredicateCommandSenderFaction(Faction faction) { + this.factionId = faction.getId(); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public boolean test(CommandSender sender) { + if (MUtil.isntSender(sender)) { + return false; + } + + MPlayer mplayer = MPlayer.get(sender); + return this.factionId.equals(mplayer.getFaction().getId()); + } + +} diff --git a/src/main/java/com/massivecraft/factions/predicate/PredicateMPlayerRank.java b/src/main/java/com/massivecraft/factions/predicate/PredicateMPlayerRank.java new file mode 100644 index 00000000..3082d158 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/predicate/PredicateMPlayerRank.java @@ -0,0 +1,47 @@ +package com.massivecraft.factions.predicate; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.entity.Rank; + +import java.util.function.Predicate; + +public class PredicateMPlayerRank implements Predicate { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final Rank rank; + + public Rank getRank() { + return this.rank; + } + + // -------------------------------------------- // + // INSTANCE AND CONTRUCT + // -------------------------------------------- // + + public static PredicateMPlayerRank get(Rank rank) { + return new PredicateMPlayerRank(rank); + } + + public PredicateMPlayerRank(Rank rank) { + this.rank = rank; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public boolean test(MPlayer mplayer) { + if (mplayer == null) { + return false; + } + Faction faction = mplayer.getFaction(); + if (!faction.hasRank(this.getRank())) { + throw new IllegalStateException("rank: " + rank.getId() + " player:" + mplayer.getId()); + } + return mplayer.getRank() == this.rank; + } +} diff --git a/src/main/java/com/massivecraft/factions/task/TaskFlagPermCreate.java b/src/main/java/com/massivecraft/factions/task/TaskFlagPermCreate.java new file mode 100644 index 00000000..2765deb8 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/task/TaskFlagPermCreate.java @@ -0,0 +1,44 @@ +package com.massivecraft.factions.task; + +import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.massivecore.ModuloRepeatTask; +import com.massivecraft.massivecore.util.TimeUnit; + +public class TaskFlagPermCreate extends ModuloRepeatTask { + // -------------------------------------------- // + // CONSTANTS + // -------------------------------------------- // + + private static final long MILLIS_INTERVAL = TimeUnit.MILLIS_PER_SECOND * 3; + + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static TaskFlagPermCreate i = new TaskFlagPermCreate(); + + public static TaskFlagPermCreate get() { + return i; + } + + public TaskFlagPermCreate() { + super(MILLIS_INTERVAL); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void setDelayMillis(long delayMillis) { + // No operation + } + + @Override + public void invoke(long now) { + MPerm.getAll(); + MFlag.getAll(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/task/TaskPlayerPowerUpdate.java b/src/main/java/com/massivecraft/factions/task/TaskPlayerPowerUpdate.java new file mode 100644 index 00000000..bd055721 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/task/TaskPlayerPowerUpdate.java @@ -0,0 +1,82 @@ +package com.massivecraft.factions.task; + +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.MPlayer; +import com.massivecraft.factions.event.EventFactionsPowerChange; +import com.massivecraft.factions.event.EventFactionsPowerChange.PowerChangeReason; +import com.massivecraft.massivecore.ModuloRepeatTask; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.MUtil; +import com.massivecraft.massivecore.util.TimeUnit; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class TaskPlayerPowerUpdate extends ModuloRepeatTask { + // -------------------------------------------- // + // INSTANCE + // -------------------------------------------- // + + private static TaskPlayerPowerUpdate i = new TaskPlayerPowerUpdate(); + + public static TaskPlayerPowerUpdate get() { + return i; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public long getDelayMillis() { + // The interval is determined by the MConf rather than being set with setDelayMillis. + return TimeUnit.MILLIS_PER_MINUTE; + } + + @Override + public void invoke(long now) { + long millis = this.getDelayMillis(); + MFlag flagPowerGain = MFlag.getFlagPowergain(); + + // For each player ... + for (Player player : Bukkit.getOnlinePlayers()) { + // ... that is a living player ... + if (MUtil.isntPlayer(player)) { + continue; + } + if (player.isDead()) { + continue; + } + + // ... in a faction territory that permits power gain ... + Faction faction = BoardColl.get().getFactionAt(PS.valueOf(player)); + if (!faction.getFlag(flagPowerGain)) { + return; + } + + // ... in a world that permits power gain ... + if (!MConf.get().worldsPowerGainEnabled.contains(player)) { + return; + } + + MPlayer mplayer = MPlayer.get(player); + + // ... calculate new power ... + double newPower = mplayer.getPower() + mplayer.getPowerPerHour() * millis / TimeUnit.MILLIS_PER_HOUR; + + // ... and if other plugins don't object ... + EventFactionsPowerChange event = new EventFactionsPowerChange(null, mplayer, PowerChangeReason.TIME, newPower); + event.run(); + if (event.isCancelled()) { + continue; + } + + // ... set the new power for the player. + newPower = event.getNewPower(); + mplayer.setPower(newPower); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/task/TaskTax.java b/src/main/java/com/massivecraft/factions/task/TaskTax.java new file mode 100644 index 00000000..4bd54e85 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/task/TaskTax.java @@ -0,0 +1,230 @@ +package com.massivecraft.factions.task; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.entity.MPlayerColl; +import com.massivecraft.factions.event.EventFactionsMembershipChange; +import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; +import com.massivecraft.factions.integration.Econ; +import com.massivecraft.massivecore.Couple; +import com.massivecraft.massivecore.Task; +import com.massivecraft.massivecore.collections.MassiveMap; +import com.massivecraft.massivecore.mixin.MixinMessage; +import com.massivecraft.massivecore.money.Money; +import com.massivecraft.massivecore.util.IdUtil; +import com.massivecraft.massivecore.util.TimeUnit; + +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class TaskTax extends Task { + // -------------------------------------------- // + // INSTANCE + // -------------------------------------------- // + + private static TaskTax i = new TaskTax(); + + public static TaskTax get() { + return i; + } + + public TaskTax() { + // Just check once a minute + this.setPeriod(60L * 20L); + + this.setMustBeTaskServer(true); + this.setLoggingTimeSpent(true); + + this.addCondition(Econ::isEnabled); + this.addCondition(() -> MConf.get().taxEnabled); + } + + // -------------------------------------------- // + // OVERRIDE: TASK + // -------------------------------------------- // + + @Override + public long getPreviousMillis() { + return MConf.get().taxTaskLastMillis; + } + + @Override + public void setPreviousMillis(long millis) { + MConf.get().taxTaskLastMillis = millis; + MConf.get().changed(); + } + + @Override + public long getPeriodMillis() { + return MConf.get().taxTaskPeriodMillis; + } + + @Override + public long getOffsetMillis() { + return MConf.get().taxTaskInvocationOffsetMillis; + } + + // -------------------------------------------- // + // OVERRIDE: RUNNABLE + // -------------------------------------------- // + + @Override + public void invoke(long now) { + taxPlayers(now); + taxFactions(now); + } + + public void taxPlayers(long now) { + MixinMessage.get().msgAll("Taxation of players starting."); + long start = System.nanoTime(); + + // Tax players and track how many players are taxed and how much + Map> faction2tax = new MassiveMap<>(); + + List> taxes = MPlayerColl.get().getAll().stream() + .filter(mp -> shouldBeTaxed(now, mp)) + .map(mp -> new Couple<>(mp, getTax(mp))) + .filter(e -> e.getValue() != 0D) + .collect(Collectors.toList()); + + /*String debug = taxes.stream() + .map(c -> c.getFirst().getName() + ": " + c.getSecond()) + .reduce((s1, s2) -> s1 + "\n" + s2).orElse("No players pay tax."); + MixinMessage.get().messageAll(debug);*/ + + // Pay the highest taxes first. + // That way taxes are collected before wages are given. + Comparator> comparator = Comparator.comparingDouble(Couple::getSecond); + comparator = comparator.reversed(); + taxes.sort(comparator); + + for (Couple couple : taxes) { + double tax = doTaxPlayer(couple); + if (tax == 0D) { + continue; + } + + // Log data + Faction faction = couple.getFirst().getFaction(); + Couple newCouple = new Couple<>(1, tax); + faction2tax.merge(faction, newCouple, + (c1, c2) -> new Couple<>(c1.getFirst() + c2.getFirst(), c1.getSecond() + c2.getSecond())); + } + + // Inform factions + faction2tax.forEach(this::informFactionOfPlayerTax); + + // Inform of taxation complete + int count = faction2tax.values().stream().mapToInt(Couple::getFirst).sum(); + MixinMessage.get().msgAll("Taxation of players complete. %d players were taxed.", count); + + long end = System.nanoTime(); + double elapsedSeconds = (end - start) / 1000_000_000D; + MixinMessage.get().msgAll("Took %.2f seconds.", elapsedSeconds); + } + + private double getTax(MPlayer mplayer) { + return mplayer.getFaction().getTaxForPlayer(mplayer); + } + + private double doTaxPlayer(Couple couple) { + return doTaxPlayer(couple.getFirst(), couple.getSecond()); + } + + private double doTaxPlayer(MPlayer mplayer, double tax) { + Faction faction = mplayer.getFaction(); + boolean success = Econ.moveMoney(mplayer, faction, null, tax, "Factions Tax"); + if (success) { + // Inform player + if (mplayer.isOnline()) { + if (tax > 0) { + mplayer.msg("You were just taxed %s by your faction.", Money.format(tax)); // Tax + } else { + mplayer.msg("You were just paid %s by your faction.", Money.format(-tax)); // Salary + } + } + + return tax; + } else if (tax > 0) // If a tax + { + faction.msg("%s couldn't afford tax!", mplayer.describeTo(faction)); + boolean kicked = tryKickPlayer(mplayer); + if (!kicked) { + faction.msg("%s could not afford tax.", mplayer.describeTo(faction)); + } + return 0D; + } else // If a salary + { + faction.msg("Your faction couldn't afford to pay %s to %s.", Money.format(-tax), mplayer.describeTo(faction)); + return 0D; + } + } + + private boolean shouldBeTaxed(long now, MPlayer mplayer) { + // Must have faction + if (!mplayer.hasFaction()) { + return false; + } + + // Must have been online recently + long offlinePeriod; + if (mplayer.isOnline()) { + offlinePeriod = 0; + } else { + offlinePeriod = now - mplayer.getLastActivityMillis(); + } + + int inactiveDays = MConf.get().taxInactiveDays; + if (inactiveDays > 0 && offlinePeriod > inactiveDays * TimeUnit.MILLIS_PER_DAY) { + return false; + } + + return true; + } + + private boolean tryKickPlayer(MPlayer mplayer) { + Faction faction = mplayer.getFaction(); + if (mplayer.getRank().isLeader()) { + return false; + } + if (!faction.getFlag(MFlag.getFlagTaxKick())) { + return false; + } + + EventFactionsMembershipChange event = new EventFactionsMembershipChange(null, mplayer, FactionColl.get().getNone(), MembershipChangeReason.KICK); + event.run(); + if (event.isCancelled()) { + return false; + } + + faction.msg("%s could not afford tax and was kicked from your faction.", mplayer.describeTo(faction)); + + if (MConf.get().logFactionKick) { + MPlayer console = MPlayer.get(IdUtil.CONSOLE_ID); + Factions.get().log("%s could not afford tax and was kicked from %s.", mplayer.describeTo(console), faction.describeTo(console)); + } + + // Apply + faction.uninvite(mplayer); + mplayer.resetFactionData(); + + return true; + } + + private void informFactionOfPlayerTax(Faction faction, Couple couple) { + faction.msg("A total of %d players in your faction were taxed for a total of %s.", couple.getFirst(), Money.format(couple.getSecond())); + } + + public void taxFactions(long now) { + // TODO + String msg = "For the time being factions themselves cannot be taxed. This feature will be added at a later date."; + MixinMessage.get().msgOne(IdUtil.CONSOLE_ID, msg); + } + +} diff --git a/src/main/java/com/massivecraft/factions/util/AsciiCompass.java b/src/main/java/com/massivecraft/factions/util/AsciiCompass.java new file mode 100644 index 00000000..98b2dd21 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/util/AsciiCompass.java @@ -0,0 +1,61 @@ +package com.massivecraft.factions.util; + +import com.massivecraft.massivecore.collections.MassiveList; + +import java.util.List; + +import static com.massivecraft.factions.util.AsciiCompassDirection.E; +import static com.massivecraft.factions.util.AsciiCompassDirection.N; +import static com.massivecraft.factions.util.AsciiCompassDirection.NE; +import static com.massivecraft.factions.util.AsciiCompassDirection.NONE; +import static com.massivecraft.factions.util.AsciiCompassDirection.NW; +import static com.massivecraft.factions.util.AsciiCompassDirection.S; +import static com.massivecraft.factions.util.AsciiCompassDirection.SE; +import static com.massivecraft.factions.util.AsciiCompassDirection.SW; +import static com.massivecraft.factions.util.AsciiCompassDirection.W; + +public class AsciiCompass { + // -------------------------------------------- // + // COMPASS + // -------------------------------------------- // + + public static List getAsciiCompass(double degrees) { + return getAsciiCompass(AsciiCompassDirection.getByDegrees(degrees)); + } + + private static List getAsciiCompass(AsciiCompassDirection directionFacing) { + // Create + List ret = new MassiveList<>(); + + // Fill + ret.add(visualizeRow(directionFacing, NW, N, NE)); + ret.add(visualizeRow(directionFacing, W, NONE, E)); + ret.add(visualizeRow(directionFacing, SW, S, SE)); + + // Return + return ret; + } + + // -------------------------------------------- // + // VISUALIZE ROW + // -------------------------------------------- // + + private static String visualizeRow(AsciiCompassDirection directionFacing, AsciiCompassDirection... cardinals) { + // Catch + if (cardinals == null) { + throw new NullPointerException("cardinals"); + } + + // Create + StringBuilder ret = new StringBuilder(cardinals.length); + + // Fill + for (AsciiCompassDirection asciiCardinal : cardinals) { + ret.append(asciiCardinal.visualize(directionFacing)); + } + + // Return + return ret.toString(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/util/AsciiCompassDirection.java b/src/main/java/com/massivecraft/factions/util/AsciiCompassDirection.java new file mode 100644 index 00000000..22bdf6ed --- /dev/null +++ b/src/main/java/com/massivecraft/factions/util/AsciiCompassDirection.java @@ -0,0 +1,87 @@ +package com.massivecraft.factions.util; + +import org.bukkit.ChatColor; + +public enum AsciiCompassDirection { + // -------------------------------------------- // + // ENUM + // -------------------------------------------- // + + N('N'), + NE('/'), + E('E'), + SE('\\'), + S('S'), + SW('/'), + W('W'), + NW('\\'), + NONE('+'), + + // END OF LIST + ; + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final char asciiChar; + + public char getAsciiChar() { + return this.asciiChar; + } + + // -------------------------------------------- // + // CONSTANTS + // -------------------------------------------- // + + public static final ChatColor ACTIVE = ChatColor.RED; + public static final ChatColor INACTIVE = ChatColor.YELLOW; + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + AsciiCompassDirection(final char asciiChar) { + this.asciiChar = asciiChar; + } + + // -------------------------------------------- // + // VISUALIZE + // -------------------------------------------- // + + public String visualize(AsciiCompassDirection directionFacing) { + boolean isFacing = this.isFacing(directionFacing); + ChatColor color = this.getColor(isFacing); + + return color.toString() + this.getAsciiChar(); + } + + private boolean isFacing(AsciiCompassDirection directionFacing) { + return this == directionFacing; + } + + private ChatColor getColor(boolean active) { + return active ? ACTIVE : INACTIVE; + } + + // -------------------------------------------- // + // GET BY DEGREES + // -------------------------------------------- // + + public static AsciiCompassDirection getByDegrees(double degrees) { + // Prepare + // The conversion from bukkit to usable degrees is (degrees - 180) % 360 + // But we reduced the 180 to 157 (-23) because it makes the math easier that follows. + degrees = (degrees - 157) % 360; + if (degrees < 0) { + degrees += 360; + } + + // Get ordinal + int ordinal = (int) Math.floor(degrees / 45); + + // Return + return AsciiCompassDirection.values()[ordinal]; + } + +} diff --git a/src/main/java/com/massivecraft/factions/util/AsciiMap.java b/src/main/java/com/massivecraft/factions/util/AsciiMap.java new file mode 100644 index 00000000..385bccb4 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/util/AsciiMap.java @@ -0,0 +1,302 @@ +package com.massivecraft.factions.util; + +import com.massivecraft.factions.RelationParticipator; +import com.massivecraft.factions.TerritoryAccess; +import com.massivecraft.factions.entity.Board; +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.massivecore.collections.MassiveList; +import com.massivecraft.massivecore.mson.Mson; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.ps.PSFormatHumanSpace; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.ChatColor; +import org.bukkit.GameRule; +import org.bukkit.World; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import static com.massivecraft.massivecore.mson.Mson.EMPTY; +import static com.massivecraft.massivecore.mson.Mson.SPACE; +import static com.massivecraft.massivecore.mson.Mson.mson; + +public class AsciiMap { + // -------------------------------------------- // + // CONSTANTS + // -------------------------------------------- // + + private static final char[] FACTION_KEY_CHARS = "\\/#?笣$%=&^ABCDEFGHJKLMNOPQRSTUVWXYZÄÖÜÆØÅ1234567890abcdeghjmnopqrsuvwxyÿzäöüæøåâêîûô".toCharArray(); + private static final int KEY_SIZE = FACTION_KEY_CHARS.length; + + // Map Heights & Widths + private static final int WIDTH = 49; + private static final int WIDTH_HALF = WIDTH / 2; + private static final int HEIGHT = 8; + private static final int HEIGHT_HALF = HEIGHT / 2; + private static final int HEIGHT_EXTRA = 17; + private static final int HEIGHT_EXTRA_HALF = HEIGHT_EXTRA / 2; + + private static final String TITLE_FORMAT = "(%d,%d) %s"; + private static final String TITLE_FORMAT_NO_COORDS = "%s"; + private static final Mson KEY_MIDDLE = mson("+").color(ChatColor.AQUA); + private static final Mson KEY_WILDERNESS = mson("-").color(ChatColor.GRAY).tooltip(); + private static final Mson KEY_OVERFLOW = mson("-").style(ChatColor.MAGIC).add(mson("").style(ChatColor.RESET)); + private static final Mson OVERFLOW_MESSAGE = Mson.format("%s: Too Many Factions (>%d) on this Map.", KEY_OVERFLOW.toPlain(true), FACTION_KEY_CHARS.length); + private static final Mson LEGEND_SEPARATOR = mson(": "); + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final RelationParticipator relationParticipator; + + public RelationParticipator getRelationParticipator() { + return this.relationParticipator; + } + + private final double angle; + + public double getAngle() { + return this.angle; + } + + private final PS center; + + public PS getCenter() { + return this.center; + } + + private final PS topLeft; + + public PS getTopLeft() { + return this.topLeft; + } + + private final Board board; + + public Board getBoard() { + return this.board; + } + + private final Map factionChars = new HashMap<>(); + + public Map getFactionChars() { + return this.factionChars; + } + + private final int height; + + private int getHeight() { + return this.height; + } + + private final int heightHalf; + + private int getHeightHalf() { + return this.heightHalf; + } + + private boolean overflown = false; + + public boolean isOverflown() { + return this.overflown; + } + + public void setOverflown(boolean overflown) { + this.overflown = overflown; + } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + @Deprecated + public AsciiMap(RelationParticipator relationParticipator, Player player, boolean extraHeight) { + this(relationParticipator, PS.valueOf(player), extraHeight); + } + + public AsciiMap(RelationParticipator relationParticipator, PS ps, boolean extraHeight) { + this.relationParticipator = relationParticipator; + this.angle = ps.getYaw(); + this.center = ps.getChunk(true); + this.height = extraHeight ? HEIGHT_EXTRA : HEIGHT; + this.heightHalf = extraHeight ? HEIGHT_EXTRA_HALF : HEIGHT_HALF; + this.topLeft = this.center.plusChunkCoords(-WIDTH_HALF, -this.heightHalf); + this.board = BoardColl.get().get(this.center.getWorld()); + } + + // -------------------------------------------- // + // RENDER + // -------------------------------------------- // + + public List render() { + // Create + List ret = new ArrayList<>(); + + // Fill + ret.add(this.getTitle()); + ret.addAll(this.getLines()); + ret.add(this.getFactionLegend()); + + // Return + return ret; + } + + private Mson getTitle() { + // Prepare + PS chunk = this.getCenter(); + Faction faction = this.getBoard().getFactionAt(chunk); + int chunkX = chunk.getChunkX(); + int chunkZ = chunk.getChunkZ(); + String factionName = faction.getName(this.getRelationParticipator()); + + boolean showCoords = showChunkCoords(chunk); + + String title; + if (showCoords) { + title = String.format(TITLE_FORMAT, chunkX, chunkZ, factionName); + } else { + title = String.format(TITLE_FORMAT_NO_COORDS, factionName); + } + + // Titleize + return Txt.titleize(title); + } + + private List getLines() { + // Create + List ret = new MassiveList<>(); + List asciiCompass = AsciiCompass.getAsciiCompass(this.getAngle()); + + // Fill + for (int deltaZ = 0; deltaZ < this.getHeight(); deltaZ++) { + ret.add(this.getLine(deltaZ, asciiCompass)); + } + + // Return + return ret; + } + + private Mson getLine(int deltaZ, List asciiCompass) { + // Create + boolean isCompassLine = deltaZ < asciiCompass.size(); + int startX = isCompassLine ? 3 : 0; + Mson ret = isCompassLine ? mson(asciiCompass.get(deltaZ)) : EMPTY; + Mson factionChar; + + // Fill + for (int deltaX = startX; deltaX < WIDTH; deltaX++) { + boolean isMiddle = deltaX == WIDTH_HALF && deltaZ == this.getHeightHalf(); + factionChar = isMiddle ? KEY_MIDDLE : this.getCharChunk(deltaZ, deltaX); + ret = ret.add(factionChar); + } + + // Return + return ret; + } + + private Mson getCharChunk(int deltaZ, int deltaX) { + PS herePs = this.getTopLeft().plusChunkCoords(deltaX, deltaZ); + Faction hereFaction = this.getBoard().getFactionAt(herePs); + + String chunkName = this.getBoard().getTerritoryAccessAt(herePs).getChunkName(); + Mson charFaction = getCharFaction(hereFaction); + String tooltip = charFaction.getTooltip(); + if (chunkName != null) { + tooltip += "\n" + ChatColor.WHITE + chunkName; + } + Mson charChunk = charFaction.tooltip(tooltip); + return charChunk; + } + + private Mson getCharFaction(Faction faction) { + // Calculate overflow + int index = this.getFactionChars().size(); + if (!this.isOverflown() && index >= KEY_SIZE) { + this.setOverflown(true); + } + + Mson factionChar = this.getFactionChars().get(faction); + + // Is Wilderness or known? + if (faction.isNone()) { + return KEY_WILDERNESS; + } + if (factionChar != null) { + return factionChar; + } + + // Create descriptions + ChatColor color = faction.getColorTo(this.getRelationParticipator()); + String name = faction.getName(this.getRelationParticipator()); + String tooltip = color.toString() + name; + + // Is overflown? + if (this.isOverflown()) { + return KEY_OVERFLOW.tooltip(tooltip); + } + + // Create new one + factionChar = mson(String.valueOf(FACTION_KEY_CHARS[index])).color(color); + factionChar = factionChar.tooltip(tooltip); + + // Store for later use + this.getFactionChars().put(faction, factionChar); + + // Return + return factionChar; + } + + private Mson getFactionLegend() { + // Create + List ret = new MassiveList<>(); + + // Fill + for (Entry entry : this.getFactionChars().entrySet()) { + Faction here = entry.getKey(); + Mson factionChar = entry.getValue(); + ChatColor color = here.getColorTo(this.getRelationParticipator()); + + ret.add(mson(factionChar, LEGEND_SEPARATOR, here.getName()).color(color)); + } + + // Add overflown message if needed + if (this.isOverflown()) { + ret.add(OVERFLOW_MESSAGE); + } + + // Return + return Mson.implode(ret, SPACE); + } + + public static boolean showChunkCoords(PS chunk) { + return showChunkCoords(chunk.asBukkitWorld(true)); + } + + public static boolean showChunkCoords(World w) { + return !w.getGameRuleValue(GameRule.REDUCED_DEBUG_INFO); + } + + public static String getChunkDesc(PS chunk) { + return showChunkCoords(chunk) ? " at " + chunk.toString(PSFormatHumanSpace.get()) : ""; + } + + public static String getChunkDescWithName(PS chunk, TerritoryAccess ta) { + String name = ta.getChunkName(); + if (name == null) { + return getChunkDesc(chunk); + } + + String ret = Txt.parse(" at %s", name); + if (showChunkCoords(chunk)) { + ret += Txt.parse(" (%s)", chunk.toString(PSFormatHumanSpace.get())); + } + return ret; + } + +} diff --git a/src/main/java/com/massivecraft/factions/util/EnumerationUtil.java b/src/main/java/com/massivecraft/factions/util/EnumerationUtil.java new file mode 100644 index 00000000..83d37c9b --- /dev/null +++ b/src/main/java/com/massivecraft/factions/util/EnumerationUtil.java @@ -0,0 +1,311 @@ +package com.massivecraft.factions.util; + +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.massivecore.collections.BackstringSet; +import org.bukkit.Material; +import org.bukkit.entity.EntityType; + +public class EnumerationUtil { + // -------------------------------------------- // + // MATERIAL EDIT ON INTERACT + // -------------------------------------------- // + + public static final BackstringSet MATERIALS_EDIT_ON_INTERACT = new BackstringSet<>(Material.class, + "REPEATER", // Minecraft 1.? + "NOTE_BLOCK", // Minecraft 1.? + "CAULDRON", // Minecraft 1.? + "FARMLAND", // Minecraft 1.? + "DAYLIGHT_DETECTOR", // Minecraft 1.5 + "COMPARATOR", // Minecraft 1.? + "COMPOSTER", // Minecraft 1.14 + "LECTERN", // Minecraft 1.14 + "BEEHIVE", // Minecraft 1.15 + "BEE_NEST", // Minecraft 1.5 + "FLOWER_POT", // Minecraft 1.? + + // The various flower pots, they had to make each one a different material -.- + "POTTED_ACACIA_SAPLING", // Minecraft 1.13 + "POTTED_ALLIUM", // Minecraft 1.13 + "POTTED_AZURE_BLUET", // Minecraft 1.13 + "POTTED_BAMBOO", // Minecraft 1.13 + "POTTED_BIRCH_SAPLING", // Minecraft 1.13 + "POTTED_BLUE_ORCHID", // Minecraft 1.13 + "POTTED_BROWN_MUSHROOM", // Minecraft 1.13 + "POTTED_CACTUS", // Minecraft 1.13 + "POTTED_CACTUS", // Minecraft 1.13 + "POTTED_CORNFLOWER", // Minecraft 1.13 + "POTTED_DANDELION", // Minecraft 1.13 + "POTTED_DARK_OAK_SAPLING", // Minecraft 1.13 + "POTTED_DEAD_BUSH", // Minecraft 1.13 + "POTTED_FERN", // Minecraft 1.13 + "POTTED_JUNGLE_SAPLING", // Minecraft 1.13 + "POTTED_LILY_OF_THE_VALLEY", // Minecraft 1.13 + "POTTED_OAK_SAPLING", // Minecraft 1.13 + "POTTED_ORANGE_TULIP", // Minecraft 1.13 + "POTTED_OXEYE_DAISY", // Minecraft 1.13 + "POTTED_PINK_TULIP", // Minecraft 1.13 + "POTTED_POPPY", // Minecraft 1.13 + "POTTED_RED_MUSHROOM", // Minecraft 1.13 + "POTTED_RED_TULIP", // Minecraft 1.13 + "POTTED_SPRUCE_SAPLING", // Minecraft 1.13 + "POTTED_WHITE_TULIP", // Minecraft 1.13 + "POTTED_WITHER_ROSE", // Minecraft 1.13 + "POTTED_CRIMSON_FUNGUS", // Minecraft 1.16 + "POTTED_CRIMSON_ROOTS", // Minecraft 1.16 + "POTTED_WARPED_FUNGUS", // Minecraft 1.16 + "POTTED_WARPED_ROOTS" // Minecraft 1.16 + ); + + public static boolean isMaterialEditOnInteract(Material material) { + return MATERIALS_EDIT_ON_INTERACT.contains(material) || MConf.get().materialsEditOnInteract.contains(material); + } + + // -------------------------------------------- // + // MATERIAL EDIT TOOLS + // -------------------------------------------- // + + public static final BackstringSet MATERIALS_EDIT_TOOL = new BackstringSet<>(Material.class, + "FIRE_CHARGE", // Minecraft 1.? + "FLINT_AND_STEEL", // Minecraft 1.? + "BUCKET", + "WATER_BUCKET", // Minecraft 1.? + "LAVA_BUCKET",// Minecraft 1.? + "COD_BUCKET",// Minecraft 1.13 + "PUFFERFISH_BUCKET", // Minecraft 1.13 + "SALMON_BUCKET", // Minecraft 1.13 + "TROPICAL_FISH_BUCKET", // Minecraft 1.13 + "ARMOR_STAND", // Minecraft 1.8 + "END_CRYSTAL", // Minecraft 1.10 + + // The duplication bug found in Spigot 1.8 protocol patch + // https://github.com/MassiveCraft/Factions/issues/693 + "CHEST", // Minecraft 1.? // TODO why chest? + "SIGN_POST", // Minecraft 1.? + "TRAPPED_CHEST", // Minecraft 1.? + "SIGN", // Minecraft 1.? + "WOOD_DOOR", // Minecraft 1.? + "IRON_DOOR", // Minecraft 1.? + "BONE_MEAL" // Minecraft 1.? + ); + + public static boolean isMaterialEditTool(Material material) { + return MATERIALS_EDIT_TOOL.contains(material) || MConf.get().materialsEditTools.contains(material); + } + + // -------------------------------------------- // + // MATERIAL DOOR + // -------------------------------------------- // + + // Interacting with these materials placed in the terrain results in door toggling. + public static final BackstringSet MATERIALS_DOOR = new BackstringSet<>(Material.class, + "OAK_DOOR", + "OAK_TRAPDOOR", + "OAK_FENCE_GATE", + "ACACIA_DOOR", + "ACACIA_TRAPDOOR", + "ACACIA_FENCE_GATE", + "BIRCH_DOOR", + "BIRCH_TRAPDOOR", + "BIRCH_FENCE_GATE", + "DARK_OAK_DOOR", + "DARK_OAK_TRAPDOOR", + "DARK_OAK_FENCE_GATE", + "JUNGLE_DOOR", + "JUNGLE_TRAPDOOR", + "JUNGLE_FENCE_GATE", + "SPRUCE_DOOR", + "SPRUCE_TRAPDOOR", + "SPRUCE_FENCE_GATE", + + // Minecraft 1.16 + "CRIMSON_DOOR", + "CRIMSON_TRAPDOOR", + "CRIMSON_FENCE_GATE", + "WARPED_DOOR", + "WARPED_TRAPDOOR", + "WARPED_FENCE_GATE" + ); + + public static boolean isMaterialDoor(Material material) { + return MATERIALS_DOOR.contains(material) || MConf.get().materialsDoor.contains(material); + } + + // -------------------------------------------- // + // MATERIAL CONTAINER + // -------------------------------------------- // + + public static final BackstringSet MATERIALS_CONTAINER = new BackstringSet<>(Material.class, + "DISPENSER", + "CHEST", + "TRAPPED_CHEST", + "FURNACE", + "JUKEBOX", + "BREWING_STAND", + "ENCHANTING_TABLE", + "ANVIL", + "CHIPPED_ANVIL", + "DAMAGED_ANVIL", + "BEACON", + "HOPPER", + "DROPPER", + "BARREL", // Minecraft 1.14 + "BLAST_FURNACE", // Minecraft 1.14 + "SMOKER", // 1.14 + "RESPAWN_ANCHOR", // 1.16 + + // The various shulker boxes, they had to make each one a different material -.- + "SHULKER_BOX", + "BLACK_SHULKER_BOX", + "BLUE_SHULKER_BOX", + "BROWN_SHULKER_BOX", + "CYAN_SHULKER_BOX", + "GRAY_SHULKER_BOX", + "GREEN_SHULKER_BOX", + "LIGHT_BLUE_SHULKER_BOX", + "LIGHT_GRAY_SHULKER_BOX", + "LIME_SHULKER_BOX", + "MAGENTA_SHULKER_BOX", + "ORANGE_SHULKER_BOX", + "PINK_SHULKER_BOX", + "PURPLE_SHULKER_BOX", + "RED_SHULKER_BOX", + "SILVER_SHULKER_BOX", // Changed name to light gray, I think. Kept for backwards compatibility + "WHITE_SHULKER_BOX", + "YELLOW_SHULKER_BOX" + ); + + public static boolean isMaterialContainer(Material material) { + return MATERIALS_CONTAINER.contains(material) || MConf.get().materialsContainer.contains(material); + } + + // -------------------------------------------- // + // ENTITY TYPE EDIT ON INTERACT + // -------------------------------------------- // + + // Interacting with these entities results in an edit. + public static final BackstringSet ENTITY_TYPES_EDIT_ON_INTERACT = new BackstringSet<>(EntityType.class, + "ITEM_FRAME", // Minecraft 1.? + "ARMOR_STAND" // Minecraft 1.8 + ); + + public static boolean isEntityTypeEditOnInteract(EntityType entityType) { + return ENTITY_TYPES_EDIT_ON_INTERACT.contains(entityType) || MConf.get().entityTypesEditOnInteract.contains(entityType); + } + + // -------------------------------------------- // + // ENTITY TYPE EDIT ON DAMAGE + // -------------------------------------------- // + + // Damaging these entities results in an edit. + public static final BackstringSet ENTITY_TYPES_EDIT_ON_DAMAGE = new BackstringSet<>(EntityType.class, + "ITEM_FRAME", // Minecraft 1.? + "ARMOR_STAND", // Minecraft 1.8 + "ENDER_CRYSTAL" // Minecraft 1.10 + ); + + public static boolean isEntityTypeEditOnDamage(EntityType entityType) { + return ENTITY_TYPES_EDIT_ON_DAMAGE.contains(entityType) || MConf.get().entityTypesEditOnDamage.contains(entityType); + } + + // -------------------------------------------- // + // ENTITY TYPE CONTAINER + // -------------------------------------------- // + + public static final BackstringSet ENTITY_TYPES_CONTAINER = new BackstringSet<>(EntityType.class, + "MINECART_CHEST", // Minecraft 1.? + "MINECART_HOPPER" // Minecraft 1.? + ); + + public static boolean isEntityTypeContainer(EntityType entityType) { + return ENTITY_TYPES_CONTAINER.contains(entityType) || MConf.get().entityTypesContainer.contains(entityType); + } + + // -------------------------------------------- // + // ENTITY TYPE MONSTER + // -------------------------------------------- // + + public static final BackstringSet ENTITY_TYPES_MONSTER = new BackstringSet<>(EntityType.class, + "BLAZE", // Minecraft 1.? + "CAVE_SPIDER", // Minecraft 1.? + "CREEPER", // Minecraft 1.? + "ELDER_GUARDIAN", + "ENDERMAN", // Minecraft 1.? + "ENDERMITE", // Minecraft 1.8 + "ENDER_DRAGON", // Minecraft 1.? + "EVOKER", + "GUARDIAN", // Minecraft 1.8 + "GHAST", // Minecraft 1.? + "GIANT", // Minecraft 1.? + "HUSK", + "MAGMA_CUBE", // Minecraft 1.? + "PIG_ZOMBIE", // Minecraft 1.? + "POLAR_BEAR", // Minecraft 1.10 + "SILVERFISH", // Minecraft 1.? + "SHULKER", // Minecraft 1.10 + "SKELETON", // Minecraft 1.? + "SLIME", // Minecraft 1.? + "SPIDER", // Minecraft 1.? + "STRAY", + "VINDICATOR", + "VEX", + "WITCH", // Minecraft 1.? + "WITHER", // Minecraft 1.? + "WITHER_SKELETON", + "STRAY", // Minecraft 1.? + "ZOMBIE", // Minecraft 1.? + "ZOMBIE_VILLAGER", + "ILLUSIONER", // Minecraft 1.12 + "PHANTOM", // Minecraft 1.13 + "DOLPHIN", // Minecraft 1.13 + "DROWNED", // Minecraft 1.13 + "PILLAGER", // Minecraft 1.14 + "RAVAGER", // Minercraft 1.14 + "ZOMBIFIED_PIGLIN", // Minecraft 1.16 (rename of PIG_ZOMBIE) + "HOGLIN", // Minecraft 1.16 + "ZOGLIN" // 1.16 + ); + + public static boolean isEntityTypeMonster(EntityType entityType) { + return ENTITY_TYPES_MONSTER.contains(entityType) || MConf.get().entityTypesMonsters.contains(entityType); + } + + // -------------------------------------------- // + // ENTITY TYPE ANIMAL + // -------------------------------------------- // + + public static final BackstringSet ENTITY_TYPES_ANIMAL = new BackstringSet<>(EntityType.class, + "BAT", // Minecraft 1.? + "CHICKEN", // Minecraft 1.? + "COW", // Minecraft 1.? + "DONKEY", + "HORSE", // Minecraft 1.? + "LLAMA", + "MULE", + "MUSHROOM_COW", // Minecraft 1.? + "OCELOT", // Minecraft 1.? + "PIG", // Minecraft 1.? + "RABBIT", // Minecraft 1.? + "SHEEP", // Minecraft 1.? + "SKELETON_HORSE", + "SQUID", // Minecraft 1.? + "WOLF", // Minecraft 1.? + "ZOMBIE_HORSE", + "PARROT", // Minecraft 1.12 + "COD", // Minecraft 1.13 + "SALMON", // Minecraft 1.13 + "PUFFERFISH", // Minecraft 1.13 + "TROPICAL_FISH", // Minecraft 1.13 + "TURTLE", // Minecraft 1.13 + "CAT", // Minecraft 1.14 + "FOX", // Minecraft 1.14 + "PANDA", // Minecraft 1.14 + "LLAMA", // Minecraft 1.14 + "LLAMA_SPIT", // Minecraft 1.14 + "STRIDER" // Minecraft 1.16 + ); + + public static boolean isEntityTypeAnimal(EntityType entityType) { + return ENTITY_TYPES_ANIMAL.contains(entityType) || MConf.get().entityTypesAnimals.contains(entityType); + } + +} diff --git a/src/main/java/com/massivecraft/factions/util/MiscUtil.java b/src/main/java/com/massivecraft/factions/util/MiscUtil.java new file mode 100644 index 00000000..01f4090b --- /dev/null +++ b/src/main/java/com/massivecraft/factions/util/MiscUtil.java @@ -0,0 +1,45 @@ +package com.massivecraft.factions.util; + +import org.bukkit.ChatColor; + +import java.util.Arrays; +import java.util.HashSet; + +public class MiscUtil { + // Inclusive range + public static long[] range(long start, long end) { + long[] values = new long[(int) Math.abs(end - start) + 1]; + + if (end < start) { + long oldstart = start; + start = end; + end = oldstart; + } + + for (long i = start; i <= end; i++) { + values[(int) (i - start)] = i; + } + + return values; + } + + public static HashSet substanceChars = new HashSet<>(Arrays.asList("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", + "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", + "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", + "s", "t", "u", "v", "w", "x", "y", "z")); + + public static String getComparisonString(String str) { + StringBuilder ret = new StringBuilder(); + + str = ChatColor.stripColor(str); + str = str.toLowerCase(); + + for (char c : str.toCharArray()) { + if (substanceChars.contains(String.valueOf(c))) { + ret.append(c); + } + } + return ret.toString().toLowerCase(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/util/RelationUtil.java b/src/main/java/com/massivecraft/factions/util/RelationUtil.java new file mode 100644 index 00000000..0e41d337 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/util/RelationUtil.java @@ -0,0 +1,142 @@ +package com.massivecraft.factions.util; + +import com.massivecraft.factions.Rel; +import com.massivecraft.factions.RelationParticipator; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.ChatColor; + +public class RelationUtil { + // -------------------------------------------- // + // CONSTANTS + // -------------------------------------------- // + + private static final String UNKNOWN_RELATION_OTHER = "A server admin"; + private static final String UNDEFINED_FACTION_OTHER = "ERROR"; + private static final String OWN_FACTION = "your faction"; + private static final String SELF = "you"; + + // -------------------------------------------- // + // DESCRIBE + // -------------------------------------------- // + + public static String describeThatToMe(RelationParticipator that, RelationParticipator me, boolean ucfirst) { + String ret = ""; + + if (that == null) { + return UNKNOWN_RELATION_OTHER; + } + + Faction thatFaction = getFaction(that); + if (thatFaction == null) { + return UNDEFINED_FACTION_OTHER; // ERROR + } + + Faction myFaction = getFaction(me); + + boolean isSameFaction = thatFaction == myFaction; + + if (that instanceof Faction) { + String thatFactionName = thatFaction.getName(); + if (thatFaction.isNone()) { + ret = thatFactionName; + } else if (me instanceof MPlayer && isSameFaction) { + ret = OWN_FACTION; + } else { + ret = thatFactionName; + } + } else if (that instanceof MPlayer) { + MPlayer mplayerthat = (MPlayer) that; + if (that == me) { + ret = SELF; + } else if (isSameFaction) { + ret = mplayerthat.getNameAndTitle(myFaction); + } else { + ret = mplayerthat.getNameAndFactionName(); + } + } + + if (ucfirst) { + ret = Txt.upperCaseFirst(ret); + } + + return getColorOfThatToMe(that, me).toString() + ret; + } + + public static String describeThatToMe(RelationParticipator that, RelationParticipator me) { + return describeThatToMe(that, me, false); + } + + // -------------------------------------------- // + // RELATION + // -------------------------------------------- // + + public static Rel getRelationOfThatToMe(RelationParticipator that, RelationParticipator me) { + return getRelationOfThatToMe(that, me, false); + } + + public static Rel getRelationOfThatToMe(RelationParticipator that, RelationParticipator me, boolean ignorePeaceful) { + Faction myFaction = getFaction(me); + if (myFaction == null) { + return Rel.NEUTRAL; // ERROR + } + + Faction thatFaction = getFaction(that); + if (thatFaction == null) { + return Rel.NEUTRAL; // ERROR + } + + if (myFaction.equals(thatFaction)) { + return Rel.FACTION; + } + + MFlag flagPeaceful = MFlag.getFlagPeaceful(); + if (!ignorePeaceful && (thatFaction.getFlag(flagPeaceful) || myFaction.getFlag(flagPeaceful))) { + return Rel.TRUCE; + } + + // The faction with the lowest wish "wins" + Rel theirWish = thatFaction.getRelationWish(myFaction); + Rel myWish = myFaction.getRelationWish(thatFaction); + return theirWish.isLessThan(myWish) ? theirWish : myWish; + } + + // -------------------------------------------- // + // FACTION + // -------------------------------------------- // + + public static Faction getFaction(RelationParticipator rp) { + if (rp instanceof Faction) { + return (Faction) rp; + } + + if (rp instanceof MPlayer) { + return ((MPlayer) rp).getFaction(); + } + + // ERROR + return null; + } + + // -------------------------------------------- // + // COLOR + // -------------------------------------------- // + + public static ChatColor getColorOfThatToMe(RelationParticipator that, RelationParticipator me) { + Faction thatFaction = getFaction(that); + if (thatFaction != null && thatFaction != getFaction(me)) { + if (thatFaction.getFlag(MFlag.getFlagFriendlyire())) { + return MConf.get().colorFriendlyFire; + } + + if (!thatFaction.getFlag(MFlag.getFlagPvp())) { + return MConf.get().colorNoPVP; + } + } + return getRelationOfThatToMe(that, me).getColor(); + } + +} diff --git a/src/main/java/com/massivecraft/factions/util/VisualizeUtil.java b/src/main/java/com/massivecraft/factions/util/VisualizeUtil.java new file mode 100644 index 00000000..9f4715c2 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/util/VisualizeUtil.java @@ -0,0 +1,96 @@ +package com.massivecraft.factions.util; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; + +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.UUID; + +// TODO: Only send blocks in visual range +// TODO: Only send blocks that where changed when clearing? +// TODO: Create packed queue to avoid freezes. + +public class VisualizeUtil { + protected static Map> playerLocations = new HashMap<>(); + + public static Set getPlayerLocations(Player player) { + return getPlayerLocations(player.getUniqueId()); + } + + public static Set getPlayerLocations(UUID uuid) { + return playerLocations.computeIfAbsent(uuid, k -> new HashSet<>()); + } + + // -------------------------------------------- // + // SINGLE + // -------------------------------------------- // + + @SuppressWarnings("deprecation") + public static void addLocation(Player player, Location location, Material material, byte data) { + getPlayerLocations(player).add(location); + player.sendBlockChange(location, material, data); + } + + @SuppressWarnings("deprecation") + public static void addLocation(Player player, Location location, Material material) { + getPlayerLocations(player).add(location); + player.sendBlockChange(location, material, (byte) 0); + } + + // -------------------------------------------- // + // MANY + // -------------------------------------------- // + + @SuppressWarnings("deprecation") + public static void addLocations(Player player, Map locationMaterialIds) { + Set ploc = getPlayerLocations(player); + for (Entry entry : locationMaterialIds.entrySet()) { + ploc.add(entry.getKey()); + player.sendBlockChange(entry.getKey(), entry.getValue(), (byte) 0); + } + } + + @SuppressWarnings("deprecation") + public static void addLocations(Player player, Collection locations, Material material) { + Set ploc = getPlayerLocations(player); + for (Location location : locations) { + ploc.add(location); + player.sendBlockChange(location, material, (byte) 0); + } + } + + @SuppressWarnings("deprecation") + public static void addBlocks(Player player, Collection blocks, Material material) { + Set ploc = getPlayerLocations(player); + for (Block block : blocks) { + Location location = block.getLocation(); + ploc.add(location); + player.sendBlockChange(location, material, (byte) 0); + } + } + + // -------------------------------------------- // + // CLEAR + // -------------------------------------------- // + + @SuppressWarnings("deprecation") + public static void clear(Player player) { + Set locations = getPlayerLocations(player); + if (locations == null) { + return; + } + for (Location location : locations) { + Block block = location.getWorld().getBlockAt(location); + player.sendBlockChange(location, block.getType(), block.getData()); + } + locations.clear(); + } + +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 00000000..eedc5e51 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,461 @@ +main: ${project.groupId}.${project.name} +name: ${project.name} +version: ${project.version} +website: ${project.url} +description: ${project.description} +authors: [ Madus, Cayorion, Ulumulu1510, MarkehMe, Brettflan ] +depend: [ MassiveCore ] +softdepend: [ PermissionsEx, Permissions, Essentials, EssentialsChat, HeroChat, LocalAreaChat, LWC, ChatManager, AuthMe, Vault, WorldEdit, WorldGuard ] +api-version: 1.13 +permissions: + # -------------------------------------------- # + # THE REAL NODES + # -------------------------------------------- # + factions.access: { description: manage access, with the proper fperm, default: false } + factions.access.deny: { description: deny faction access, default: false } + factions.access.deny.one: { description: deny access in a single chunk, default: false } + factions.access.deny.fill: { description: deny access by filling, default: false } + factions.access.deny.square: { description: deny access by square and radius, default: false } + factions.access.deny.circle: { description: deny access by circle and radius, default: false } + factions.access.grant: { description: grant faction access, default: false } + factions.access.grant.one: { description: grant access in a single chunk, default: false } + factions.access.grant.fill: { description: grant access by filling, default: false } + factions.access.grant.square: { description: grant access by square and radius, default: false } + factions.access.grant.circle: { description: grant access by circle and radius, default: false } + factions.access.inspect: { description: inspect where someone has access, default: false } + factions.access.view: { description: view access, default: false } + factions.override: { description: enable override mode, default: false } + factions.basecommand: { description: use factions base command, default: false } + factions.chunkname: { description: set chunk name, default: false } + factions.claim: { description: claim faction territory, default: false } + factions.claim.one: { description: claim a single chunk, default: false } + factions.claim.auto: { description: claim as you walk around, default: false } + factions.claim.fill: { description: claim by filling, default: false } + factions.claim.square: { description: claim by square and radius, default: false } + factions.claim.circle: { description: claim by circle and radius, default: false } + factions.claim.all: { description: claim all faction land, default: false } + factions.create: { description: create new faction, default: false } + factions.description: { description: change faction description, default: false } + factions.disband: { description: disband faction, default: false } + factions.documentation: { description: show documentation, default: false } + factions.documentation.flags: { description: show flag documentation, default: false } + factions.documentation.power: { description: show power documentation, default: false } + factions.documentation.perms: { description: show perms documentation, default: false } + factions.documentation.ranks: { description: show rank documentation, default: false } + factions.documentation.tax: { description: show tax documentation, default: false } + factions.documentation.warps: { description: show warp documentation, default: false } + factions.expansions: { description: list expansions, default: false } + factions.faction: { description: show faction information, default: false } + factions.flag: { description: manage faction flags, default: false } + 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.fly: { description: faction fly, default: false } + factions.fly.other: { description: set faction fly for others, 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 } + factions.invite.add: { description: invite player, default: false } + factions.invite.remove: { description: revoke an invite, default: false } + factions.join: { description: join faction, default: false } + factions.join.others: { description: have another player join faction, default: false } + factions.kick: { description: kick player from faction, default: false } + factions.leave: { description: leave your faction, default: false } + factions.list: { description: list all factions, default: false } + factions.map: { description: show territory map, default: false } + factions.money: { description: manage faction money, default: false } + factions.money.balance: { description: show faction money, default: false } + factions.money.balance.any: { description: show another factions money, default: false } + factions.money.deposit: { description: deposit to faction, default: false } + factions.money.f2f: { description: transfer f --> f, default: false } + factions.money.f2p: { description: transfer f --> p, default: false } + factions.money.p2f: { description: transfer p --> f, default: false } + factions.money.withdraw: { description: withdraw from faction, default: false } + factions.moneyconvert: { description: convert to the new money system, default: false } + factions.motd: { description: faction motd, default: false } + factions.open: { description: set if invitation is required to join, default: false } + factions.perm: { description: change faction permissions, default: false } + factions.perm.list: { description: list perms, default: false } + factions.perm.set: { description: set perms, default: false } + factions.perm.show: { description: show who has perm, default: false } + factions.perm.view: { description: view perms given to, default: false } + factions.perm.viewall: { description: view all perms held by, default: false } + factions.player: { description: show player information } + factions.powerboost: { description: manage powerboost, default: false } + factions.powerboost.faction: { description: manage faction powerboost, default: false } + factions.powerboost.faction.add: { description: add to faction powerboost, default: false } + factions.powerboost.faction.multiply: { description: multiply faction powerboost, default: false } + factions.powerboost.faction.set: { description: set faction powerboost, default: false } + factions.powerboost.faction.show: { description: show faction powerboost, default: false } + factions.powerboost.faction.take: { description: take faction powerboost, default: false } + factions.powerboost.player: { description: manage player powerboost, default: false } + factions.powerboost.player.add: { description: add to player powerboost, default: false } + factions.powerboost.player.multiply: { description: multiply player powerboost, default: false } + factions.powerboost.player.set: { description: set player powerboost, default: false } + factions.powerboost.player.show: { description: show player powerboost, default: false } + factions.powerboost.player.take: { description: take player powerboost, default: false } + factions.rank: { description: manage/show ranks, default: false } + factions.rank.show: { description: show rank, default: false } + factions.rank.set: { description: set rank, default: false } + factions.rank.list: { description: list ranks, default: false } + factions.rank.edit: { description: edit ranks, default: false } + factions.rank.edit.create: { description: create rank, default: false } + factions.rank.edit.name: { description: set rank name, default: false } + factions.rank.edit.prefix: { description: set rank prefix, default: false } + factions.rank.edit.priority: { description: set rank priority, default: false } + factions.rank.edit.delete: { description: delete rank, default: false } + factions.relation: { description: manage faction relations, default: false } + factions.relation.list: { description: list all factions with certain relation, default: false } + factions.relation.set: { description: set relation wish to another faction, default: false } + 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.setpower: { description: set power, default: false } + factions.status: { description: show status, default: false } + factions.tax: { description: manage taxes, default: false } + factions.tax.faction: { description: show faction tax, default: false } + factions.tax.player: { description: show player tax, default: false } + factions.tax.run: { description: run a tax collection, default: false } + factions.tax.set: { description: set taxes, default: false } + factions.name: { description: set faction name, default: false } + factions.title: { description: set player title, default: false } + factions.title.color: { description: set player title with color, default: false } + factions.territorytitles: { description: toggle territory titles, default: false } + factions.top: { description: show faction top, default: false } + factions.unclaim: { description: unclaim faction territory, default: false } + factions.unclaim.one: { description: unclaim a single chunk, default: false } + factions.unclaim.auto: { description: unclaim as you walk around, default: false } + factions.unclaim.fill: { description: unclaim by filling, default: false } + 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.vote: { description: vote in faction votes, default: false } + factions.vote.do: { description: do vote, default: false } + factions.vote.list: { description: list votes, default: false } + factions.vote.show: { description: show vote result, default: false } + factions.vote.create: { description: create a vote, default: false } + factions.vote.remove: { description: remove a vote, 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 } + factions.version: { description: see plugin version, default: false } + # -------------------------------------------- # + # STAR NOTATION + # -------------------------------------------- # + factions.*: + children: + factions.access: true + factions.access.deny: true + factions.access.deny.one: true + factions.access.deny.fill: true + factions.access.deny.square: true + factions.access.deny.circle: true + factions.access.grant: true + factions.access.grant.one: true + factions.access.grant.fill: true + factions.access.grant.square: true + factions.access.grant.circle: true + factions.access.inspect: true + factions.access.view: true + factions.override: true + factions.basecommand: true + factions.chunkname: true + factions.claim: true + factions.claim.one: true + factions.claim.auto: true + factions.claim.fill: true + factions.claim.square: true + factions.claim.circle: true + factions.claim.all: true + factions.create: true + factions.demote: true + factions.description: true + factions.disband: true + factions.documentation: true + factions.documentation.flags: true + factions.documentation.perms: true + factions.documentation.power: true + factions.documentation.ranks: true + factions.documentation.tax: true + factions.documentation.warps: true + factions.expansions: true + factions.faction: true + factions.flag: true + factions.flag.list: true + factions.flag.set: true + factions.flag.show: true + factions.fly: true + factions.fly.other: true + factions.home: true + factions.invite: true + factions.invite.list: true + factions.invite.list.other: true + factions.invite.add: true + factions.invite.remove: true + factions.join: true + factions.join.others: true + factions.kick: true + factions.leader: true + factions.leader.any: true + factions.leave: true + factions.list: true + factions.map: true + factions.money: true + factions.money.balance: true + factions.money.balance.any: true + factions.money.deposit: true + factions.money.f2f: true + factions.money.f2p: true + factions.money.p2f: true + factions.money.withdraw: true + factions.moneyconvert: true + factions.motd: true + factions.officer: true + factions.officer.any: true + factions.open: true + factions.perm: true + factions.perm.list: true + factions.perm.set: true + factions.perm.show: true + factions.perm.view: true + factions.perm.viewall: true + factions.player: true + factions.powerboost: true + factions.powerboost.faction: true + factions.powerboost.faction.add: true + factions.powerboost.faction.multiply: true + factions.powerboost.faction.set: true + factions.powerboost.faction.show: true + factions.powerboost.faction.take: true + factions.powerboost.player: true + factions.powerboost.player.add: true + factions.powerboost.player.multiply: true + factions.powerboost.player.set: true + factions.powerboost.player.show: true + factions.powerboost.player.take: true + factions.rank: true + factions.rank.show: true + factions.rank.set: true + factions.rank.list: true + factions.rank.edit: true + factions.rank.edit.create: true + factions.rank.edit.name: true + factions.rank.edit.prefix: true + factions.rank.edit.priority: true + factions.rank.edit.delete: true + factions.promote: true + factions.relation: true + factions.relation.list: true + factions.relation.set: true + factions.relation.wishes: true + factions.seechunk: true + factions.seechunkold: true + factions.sethome: true + factions.setpower: true + factions.status: true + factions.tax: true + factions.tax.faction: true + factions.tax.player: true + factions.tax.run: true + factions.tax.set: true + factions.name: true + factions.title: true + factions.title.color: true + factions.territorytitles: true + factions.top: true + factions.unclaim: true + factions.unclaim.one: true + factions.unclaim.auto: true + factions.unclaim.fill: true + factions.unclaim.square: true + factions.unclaim.circle: true + factions.unclaim.all: true + factions.unsethome: true + factions.unstuck: true + factions.vote: true + factions.vote.do: true + factions.vote.list: true + factions.vote.show: true + factions.vote.create: true + factions.vote.remove: 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 + # -------------------------------------------- # + # KITS + # -------------------------------------------- # + factions.kit.op: + default: op + children: + factions.*: true + factions.kit.rank3: + default: false + children: + factions.kit.rank2: true + factions.moneyconvert: true + factions.config: true + factions.clean: true + factions.kit.rank2: + default: false + children: + factions.kit.rank1: true + factions.powerboost.faction.add: true + factions.powerboost.faction.multiply: true + factions.powerboost.faction.set: true + factions.powerboost.faction.take: true + factions.powerboost.player.add: true + factions.powerboost.player.multiply: true + factions.powerboost.player.set: true + factions.powerboost.player.take: true + factions.join.others: true + factions.leader.any: true + factions.officer.any: true + factions.access.any: true + factions.fly.other: true + factions.setpower: true + factions.kit.rank1: + default: false + children: + factions.kit.rank0: true + factions.override: true + factions.invite.list.other: true + factions.kit.rank0: + default: false + children: + factions.access: true + factions.access.deny: true + factions.access.deny.one: true + factions.access.deny.fill: true + factions.access.deny.square: true + factions.access.deny.circle: true + factions.access.grant: true + factions.access.grant.one: true + factions.access.grant.fill: true + factions.access.grant.square: true + factions.access.grant.circle: true + factions.access.inspect: true + factions.access.view: true + factions.basecommand: true + factions.chunkname: true + factions.claim: true + factions.claim.one: true + factions.claim.auto: true + factions.claim.fill: true + factions.claim.square: true + factions.claim.circle: true + factions.claim.all: true + factions.create: true + factions.demote: true + factions.description: true + factions.disband: true + factions.documentation: true + factions.documentation.flags: true + factions.documentation.perms: true + factions.documentation.power: true + factions.documentation.ranks: true + factions.documentation.warps: true + factions.expansions: true + factions.faction: true + factions.flag: true + factions.flag.list: true + factions.flag.set: true + factions.flag.show: true + factions.fly: true + factions.home: true + factions.invite: true + factions.invite.list: true + factions.invite.add: true + factions.invite.remove: true + factions.join: true + factions.kick: true + factions.leader: true + factions.leave: true + factions.list: true + factions.map: true + factions.money: true + factions.money.balance: true + factions.money.balance.any: true + factions.money.deposit: true + factions.money.f2f: true + factions.money.f2p: true + factions.money.p2f: true + factions.money.withdraw: true + factions.motd: true + factions.officer: true + factions.open: true + factions.perm: true + factions.perm.list: true + factions.perm.set: true + factions.perm.show: true + factions.perm.view: true + factions.perm.viewall: true + factions.player: true + factions.promote: true + factions.powerboost: true + factions.powerboost.faction: true + factions.powerboost.faction.show: true + factions.powerboost.player: true + factions.powerboost.player.show: true + factions.rank: true + factions.rank.show: true + factions.rank.set: true + factions.rank.list: true + factions.rank.edit: true + factions.rank.edit.create: true + factions.rank.edit.name: true + factions.rank.edit.prefix: true + factions.rank.edit.priority: true + factions.rank.edit.delete: true + factions.relation: true + factions.relation.list: true + factions.relation.set: true + factions.relation.wishes: true + factions.seechunk: true + factions.seechunkold: true + factions.sethome: true + factions.status: true + factions.tax: true + factions.tax.faction: true + factions.tax.player: true + factions.tax.run: true + factions.tax.set: true + factions.name: true + factions.title: true + factions.title.color: true + factions.territorytitles: true + factions.top: true + factions.unclaim: true + factions.unclaim.one: true + factions.unclaim.auto: true + factions.unclaim.fill: true + factions.unclaim.square: true + factions.unclaim.circle: true + factions.unclaim.all: true + factions.unsethome: true + factions.unstuck: true + factions.vote: true + factions.vote.do: true + factions.vote.list: true + factions.vote.show: true + factions.vote.create: true + factions.vote.remove: 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 + children: + factions.kit.rank0: true