From ac0866af2e9668221d06f59f7ff6057654933f55 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Fri, 17 Jan 2020 13:41:08 +0800 Subject: [PATCH] Add Factions integration Former-commit-id: 2dd70fe62ff4346eb826fb598ce6d04e856b5321 --- pom.xml | 33 ++++ .../FactionsUUID/FactionsUUIDIntegration.java | 180 ++++++++++++++++++ .../org/maxgamer/quickshop/QuickShop.java | 27 +++ src/main/resources/config.yml | 32 ++++ src/main/resources/plugin.yml | 1 + 5 files changed, 273 insertions(+) create mode 100644 src/main/java/org/maxgamer/quickshop/PluginsIntegration/FactionsUUID/FactionsUUIDIntegration.java diff --git a/pom.xml b/pom.xml index 8c46e6948..9ebe690b5 100644 --- a/pom.xml +++ b/pom.xml @@ -61,6 +61,18 @@ + + + me.lucko:commodore + + + + + me.lucko.commodore + + org.maxgamer.quickshop.commodore + + @@ -167,6 +179,15 @@ p2-repo http://ci.athion.net/job/PlotSquared-Releases/ws/mvn/ + + EnderZone + http://ci.ender.zone/plugin/repository/everything/ + + + minecraft-repo + https://libraries.minecraft.net/ + + @@ -336,5 +357,17 @@ system ${basedir}/lib/Residence4.8.8.2.jar + + com.massivecraft + Factions + 1.6.9.5-U0.5.7 + provided + + + me.lucko + commodore + 1.3 + compile + diff --git a/src/main/java/org/maxgamer/quickshop/PluginsIntegration/FactionsUUID/FactionsUUIDIntegration.java b/src/main/java/org/maxgamer/quickshop/PluginsIntegration/FactionsUUID/FactionsUUIDIntegration.java new file mode 100644 index 000000000..49567cd9f --- /dev/null +++ b/src/main/java/org/maxgamer/quickshop/PluginsIntegration/FactionsUUID/FactionsUUIDIntegration.java @@ -0,0 +1,180 @@ +/* + * This file is a part of project QuickShop, the name is FactionsUUIDIntegration.java + * Copyright (C) Ghost_chu + * Copyright (C) Bukkit Commons Studio and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.maxgamer.quickshop.PluginsIntegration.FactionsUUID; + +import com.massivecraft.factions.Board; +import com.massivecraft.factions.FLocation; +import com.massivecraft.factions.FPlayers; +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.perms.PermissibleAction; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.maxgamer.quickshop.PluginsIntegration.IntegratedPlugin; +import org.maxgamer.quickshop.QuickShop; + +import java.util.List; + +public class FactionsUUIDIntegration implements IntegratedPlugin { + private List createFlags; + private List tradeFlags; + private boolean createRequireOpen; + private boolean createRequireNormal; + private boolean createRequireWilderness; + private boolean createRequirePeaceful; + private boolean createRequirePermanent; + private boolean createRequireSafeZone; + private boolean createRequireOwn; + private boolean createRequireWarZone; + private boolean tradeRequireOpen; + private boolean tradeRequireNormal; + private boolean tradeRequireWilderness; + private boolean tradeRequirePeaceful; + private boolean tradeRequirePermanent; + private boolean tradeRequireSafeZone; + private boolean tradeRequireOwn; + private boolean tradeRequireWarZone; + + public FactionsUUIDIntegration(QuickShop plugin){ + this.createFlags = plugin.getConfig().getStringList("integration.factions.create.flags"); + this.tradeFlags = plugin.getConfig().getStringList("integration.factions.trade.flags"); + + this.createRequireOpen = plugin.getConfig().getBoolean("integration.factions.create.require.open"); + this.createRequireNormal = plugin.getConfig().getBoolean("integration.factions.create.require.normal"); + this.createRequireWilderness = plugin.getConfig().getBoolean("integration.factions.create.require.wilderness"); + this.createRequirePeaceful = plugin.getConfig().getBoolean("integration.factions.create.require.peaceful"); + this.createRequirePermanent = plugin.getConfig().getBoolean("integration.factions.create.require.permanent"); + this.createRequireSafeZone = plugin.getConfig().getBoolean("integration.factions.create.require.safezone"); + this.createRequireOwn = plugin.getConfig().getBoolean("integration.factions.create.require.own"); + this.createRequireWarZone = plugin.getConfig().getBoolean("integration.factions.create.require.warzone"); + + this.tradeRequireOpen = plugin.getConfig().getBoolean("integration.factions.trade.require.open"); + this.tradeRequireNormal = plugin.getConfig().getBoolean("integration.factions.trade.require.normal"); + this.tradeRequireWilderness = plugin.getConfig().getBoolean("integration.factions.trade.require.wilderness"); + this.tradeRequirePeaceful = plugin.getConfig().getBoolean("integration.factions.trade.require.peaceful"); + this.tradeRequirePermanent = plugin.getConfig().getBoolean("integration.factions.trade.require.permanent"); + this.tradeRequireSafeZone = plugin.getConfig().getBoolean("integration.factions.trade.require.safezone"); + this.tradeRequireOwn = plugin.getConfig().getBoolean("integration.factions.trade.require.own"); + this.tradeRequireWarZone = plugin.getConfig().getBoolean("integration.factions.trade.require.warzone"); + + } + + @Override + public @NotNull String getName() { + return "Factions"; + } + + @Override + public boolean canCreateShopHere(@NotNull Player player, @NotNull Location location) { + Faction faction = Board.getInstance().getFactionAt(new FLocation(location)); + if(faction == null){ + return true; + } + if(createRequireOpen && !faction.getOpen()){ + return false; + } + if(createRequireSafeZone && !faction.isSafeZone()){ + return false; + } + if(createRequirePermanent && !faction.isPermanent()){ + return false; + } + if(createRequirePeaceful && !faction.isPeaceful()){ + return false; + } + if(createRequireWilderness && !faction.isWilderness()){ + return false; + } + if(createRequireOpen && !faction.getOpen()){ + return false; + } + if(createRequireWarZone && !faction.isWarZone()){ + return false; + } + if(createRequireNormal && !faction.isNormal()){ + return false; + } + if(createRequireOwn && !faction.getOwnerList(new FLocation(location)).contains(player.getName())){ + return false; + } + for (String flag: + createFlags) { + if(!faction.hasAccess(FPlayers.getInstance().getByPlayer(player),PermissibleAction.fromString(flag))){ + return false; + } + + } + return true; + } + + @Override + public boolean canTradeShopHere(@NotNull Player player, @NotNull Location location) { + + Faction faction = Board.getInstance().getFactionAt(new FLocation(location)); + if(faction == null){ + return true; + } + if(tradeRequireOpen && !faction.getOpen()){ + return false; + } + if(tradeRequireSafeZone && !faction.isSafeZone()){ + return false; + } + if(tradeRequirePermanent && !faction.isPermanent()){ + return false; + } + if(tradeRequirePeaceful && !faction.isPeaceful()){ + return false; + } + if(tradeRequireWilderness && !faction.isWilderness()){ + return false; + } + if(tradeRequireOpen && !faction.getOpen()){ + return false; + } + if(tradeRequireWarZone && !faction.isWarZone()){ + return false; + } + if(tradeRequireNormal && !faction.isNormal()){ + return false; + } + if(tradeRequireOwn && !faction.getOwnerList(new FLocation(location)).contains(player.getName())){ + return false; + } + for (String flag: + tradeFlags) { + if(!faction.hasAccess(FPlayers.getInstance().getByPlayer(player),PermissibleAction.fromString(flag))){ + return false; + } + + } + return true; + } + + @Override + public void load() { + + } + + @Override + public void unload() { + + } +} \ No newline at end of file diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java index cdcddadf1..ee8964bea 100644 --- a/src/main/java/org/maxgamer/quickshop/QuickShop.java +++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java @@ -40,6 +40,7 @@ import org.maxgamer.quickshop.Economy.*; import org.maxgamer.quickshop.InternalListener.InternalListener; import org.maxgamer.quickshop.Listeners.*; import org.maxgamer.quickshop.Permission.PermissionManager; +import org.maxgamer.quickshop.PluginsIntegration.FactionsUUID.FactionsUUIDIntegration; import org.maxgamer.quickshop.PluginsIntegration.IntegrateStage; import org.maxgamer.quickshop.PluginsIntegration.PlotSquared.PlotSquaredIntegration; import org.maxgamer.quickshop.PluginsIntegration.Residence.ResidenceIntegration; @@ -622,6 +623,12 @@ public class QuickShop extends JavaPlugin { this.integrationHelper.register(new ResidenceIntegration(this)); } } + if(getConfig().getBoolean("integration.factions.enable")){ + Plugin factions = Bukkit.getPluginManager().getPlugin("Factions"); + if(factions != null && factions.isEnabled()){ + this.integrationHelper.register(new FactionsUUIDIntegration(this)); + } + } } /** @@ -1245,6 +1252,26 @@ public class QuickShop extends JavaPlugin { getConfig().set("integration.residence.enable", false); getConfig().set("integration.residence.create", new String[] {"FLAG","interact","use"}); getConfig().set("integration.residence.trade", new String[] {}); + + getConfig().set("integration.factions.enable", false); + getConfig().set("integration.factions.create.flag", new String[] {}); + getConfig().set("integration.factions.trade.flag", new String[] {}); + getConfig().set("integration.factions.create.require.open", false); + getConfig().set("integration.factions.create.require.normal", true); + getConfig().set("integration.factions.create.require.wilderness", false); + getConfig().set("integration.factions.create.require.peaceful", true); + getConfig().set("integration.factions.create.require.permanent", false); + getConfig().set("integration.factions.create.require.safezone", false); + getConfig().set("integration.factions.create.require.own", false); + getConfig().set("integration.factions.create.require.warzone", false); + getConfig().set("integration.factions.trade.require.open", false); + getConfig().set("integration.factions.trade.require.normal", true); + getConfig().set("integration.factions.trade.require.wilderness", false); + getConfig().set("integration.factions.trade.require.peaceful", false); + getConfig().set("integration.factions.trade.require.permanent", false); + getConfig().set("integration.factions.trade.require.safezone", false); + getConfig().set("integration.factions.trade.require.own", false); + getConfig().set("integration.factions.trade.require.warzone", false); getConfig().set("config-version", 78); selectedVersion = 78; } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index ca03ce945..6f0406934 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -422,6 +422,38 @@ integration: #FLAG = Region must set quickshop.create flag available for players. # = Other avaliable flags in Residence plugin or Residence addons registered flags. trade: [] + factions: + enable: false + #Player if want create a shop, player must pass which checks? + create: + #Faction require the status must match with under: + require: + open: false + normal: true + wilderness: false + peaceful: true + permanent: false + safezone: false + own: false + warzone: false + #Player must have flags in the faction: + flags: + - CONTAINER + - ECONOMY + #Faction require the status must match with under? + trade: + #Faction require: + require: + open: false + normal: true + wilderness: false + peaceful: false + permanent: false + safezone: false + own: false + warzone: false + #Player must have flags in the faction: + flags: [] diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index d5070d975..510217968 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -21,6 +21,7 @@ softdepend: - Residence - Towny - WorldGuard + - Factions api-version: 1.13