Add support for FactionsOne

This commit is contained in:
Jesse Boyd 2016-04-21 15:53:37 +10:00
parent bf7d066520
commit a7763cd8fd
4 changed files with 128 additions and 4 deletions

View File

@ -5,6 +5,7 @@ dependencies {
compile 'net.milkbowl.vault:VaultAPI:1.5'
compile 'com.massivecraft:factions:2.8.0'
compile 'com.drtshock:factions:1.6.9.5'
compile 'com.factionsone:FactionsOne:1.2.2'
compile 'me.ryanhamshire:GriefPrevention:11.5.2'
compile 'com.massivecraft:mcore:7.0.1'
compile 'net.sacredlabyrinth.Phaed:PreciousStones:10.0.4-SNAPSHOT'

View File

@ -4,6 +4,7 @@ import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.IFawe;
import com.boydti.fawe.bukkit.regions.FactionsFeature;
import com.boydti.fawe.bukkit.regions.FactionsOneFeature;
import com.boydti.fawe.bukkit.regions.FactionsUUIDFeature;
import com.boydti.fawe.bukkit.regions.GriefPreventionFeature;
import com.boydti.fawe.bukkit.regions.PlotMeFeature;
@ -252,8 +253,18 @@ public class FaweBukkit extends JavaPlugin implements IFawe, Listener {
managers.add(new FactionsFeature(factionsPlugin, this));
Fawe.debug("Plugin 'Factions' found. Using it now.");
} catch (final Throwable e) {
managers.add(new FactionsUUIDFeature(factionsPlugin, this));
Fawe.debug("Plugin 'FactionsUUID' found. Using it now.");
try {
managers.add(new FactionsUUIDFeature(factionsPlugin, this));
Fawe.debug("Plugin 'FactionsUUID' found. Using it now.");
} catch (Throwable e2) {
try {
managers.add(new FactionsOneFeature(factionsPlugin, this));
Fawe.debug("Plugin 'FactionsUUID' found. Using it now.");
} catch (Throwable e3) {
e.printStackTrace();
}
}
}
} else {
Fawe.debug("Plugin 'Factions' not found. Factions features disabled.");

View File

@ -0,0 +1,113 @@
package com.boydti.fawe.bukkit.regions;
import com.boydti.fawe.bukkit.FaweBukkit;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.RegionWrapper;
import com.boydti.fawe.util.Perm;
import com.massivecraft.factions.FLocation;
import java.lang.reflect.Method;
import java.util.List;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
public class FactionsOneFeature extends BukkitMaskManager implements Listener {
private final Class clazzBoard;
private final Method methodGetFactionAt;
public FactionsOneFeature(final Plugin factionsPlugin, final FaweBukkit p3) throws Throwable {
super(factionsPlugin.getName());
this.clazzBoard = Class.forName("com.massivecraft.factions.Board");
this.methodGetFactionAt = clazzBoard.getDeclaredMethod("getFactionAt", FLocation.class);
}
@Override
public BukkitMask getMask(final FawePlayer<Player> fp) {
final Player player = fp.parent;
final Chunk chunk = player.getLocation().getChunk();
final boolean perm = Perm.hasPermission(FawePlayer.wrap(player), "fawe.factions.wilderness");
final RegionWrapper locs = new RegionWrapper(chunk.getX(), chunk.getX(), chunk.getZ(), chunk.getZ());
final World world = player.getWorld();
int count = 32;
if (this.isAdded(locs, world, player, perm)) {
boolean hasPerm = true;
RegionWrapper chunkSelection;
while (hasPerm && (count > 0)) {
count--;
hasPerm = false;
chunkSelection = new RegionWrapper(locs.maxX + 1, locs.maxX + 1, locs.minZ, locs.maxZ);
if (this.isAdded(chunkSelection, world, player, perm)) {
locs.maxX += 1;
hasPerm = true;
}
chunkSelection = new RegionWrapper(locs.minX - 1, locs.minX - 1, locs.minZ, locs.maxZ);
if (this.isAdded(chunkSelection, world, player, perm)) {
locs.minX -= 1;
hasPerm = true;
}
chunkSelection = new RegionWrapper(locs.minX, locs.maxX, locs.maxZ + 1, locs.maxZ + 1);
if (this.isAdded(chunkSelection, world, player, perm)) {
locs.maxZ += 1;
hasPerm = true;
}
chunkSelection = new RegionWrapper(locs.minX, locs.maxX, locs.minZ - 1, locs.minZ - 1);
if (this.isAdded(chunkSelection, world, player, perm)) {
locs.minZ -= 1;
hasPerm = true;
}
}
final Location pos1 = new Location(world, locs.minX << 4, 1, locs.minZ << 4);
final Location pos2 = new Location(world, 15 + (locs.maxX << 4), 256, 15 + (locs.maxZ << 4));
return new BukkitMask(pos1, pos2) {
@Override
public String getName() {
return "CHUNK:" + pos1.getChunk().getX() + "," + pos1.getChunk().getZ();
}
};
}
return null;
}
public boolean isAdded(final RegionWrapper locs, final World world, final Player player, final boolean perm) {
try {
for (int x = locs.minX; x <= locs.maxX; x++) {
for (int z = locs.minZ; z <= locs.maxZ; z++) {
final Object fac = methodGetFactionAt.invoke(null, new FLocation(world.getName(), x, z));
if (fac == null) {
return false;
}
Method methodGetOnlinePlayers = fac.getClass().getDeclaredMethod("getOnlinePlayers");
List<Player> players = (List<Player>) methodGetOnlinePlayers.invoke(fac);
if (!players.contains(player)) {
return false;
}
Method isNone = fac.getClass().getDeclaredMethod("isNone");
if ((boolean) isNone.invoke(fac)) {
return false;
}
}
}
return true;
} catch (Throwable e) {
e.printStackTrace();
return false;
}
}
}

View File

@ -166,9 +166,8 @@ public class Fawe {
TaskManager.IMP.later(new Runnable() {
@Override
public void run() {
// worldedit
WEManager.IMP.managers.addAll(Fawe.this.IMP.getMaskManagers());
try {
WEManager.IMP.managers.addAll(Fawe.this.IMP.getMaskManagers());
WEManager.IMP.managers.add(new PlotSquaredFeature());
} catch (Throwable e) {}
Fawe.this.worldedit = WorldEdit.getInstance();