Add Factions integration

Former-commit-id: 2dd70fe62ff4346eb826fb598ce6d04e856b5321
This commit is contained in:
Ghost_chu committed 2020-01-17 13:41:08 +08:00
1 parent 064d644751
commit ac0866af2e
5 files changed
+273

No files matched your search

@@ -0,0 +1,180 @@
/*
* This file is a part of project QuickShop, the name is FactionsUUIDIntegration.java
* Copyright (C) Ghost_chu <https://github.com/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 <http://www.gnu.org/licenses/>.
*/
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<String> createFlags;
private List<String> 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() {
}
}
@@ -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;
}
+32
View File
@@ -422,6 +422,38 @@ integration:
#FLAG = Region must set quickshop.create flag available for players.
#<OTHER> = 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: []
+1
View File
@@ -21,6 +21,7 @@ softdepend:
- Residence
- Towny
- WorldGuard
- Factions
api-version: 1.13