Skip to content

Commit

Permalink
Fix factions 2.12 support
Browse files Browse the repository at this point in the history
(fix #34)
  • Loading branch information
SBPrime committed Jun 21, 2017
1 parent 633b678 commit 81de52b
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 30 deletions.
4 changes: 3 additions & 1 deletion BlocksHub-Factions/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ endorsed.classpath=
excludes=
file.reference.BlocksHub.jar=lib/BlocksHub.jar
file.reference.craftbukkit-1.10.jar=lib/craftbukkit-1.10.jar
file.reference.Factions.2.12.jar=lib/Factions.2.12.jar
file.reference.Factions.jar=lib/Factions.jar
file.reference.MassiveCore.jar=lib/MassiveCore.jar
includes=**
Expand All @@ -39,7 +40,8 @@ javac.classpath=\
${file.reference.BlocksHub.jar}:\
${file.reference.Factions.jar}:\
${file.reference.MassiveCore.jar}:\
${file.reference.craftbukkit-1.10.jar}
${file.reference.craftbukkit-1.10.jar}:\
${file.reference.Factions.2.12.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package org.primesoft.blockshub.accessors.bukkit.factions;

import com.massivecraft.factions.Factions;
Expand All @@ -48,7 +47,6 @@
import org.bukkit.entity.Player;
import org.primesoft.blockshub.api.BlockData;
import org.primesoft.blockshub.api.IAccessController;
import org.primesoft.blockshub.api.ILog;
import org.primesoft.blockshub.api.IPlayer;
import org.primesoft.blockshub.api.IWorld;
import org.primesoft.blockshub.api.Vector;
Expand All @@ -60,21 +58,6 @@
* @author SBPrime
*/
public class FactionsAc extends BukkitBaseEntity implements IAccessController {

static IAccessController create(ILog logger, Object plugin) {
if (!(plugin instanceof Factions)) {
logger.log("plugin not found.");
return null;
}

if (EngineMain.get() == null) {
logger.log("unable to get engine.");
return null;
}

return new FactionsAc((Factions)plugin);
}

public FactionsAc(Factions plugin) {
super(plugin, "Factions");
}
Expand All @@ -84,30 +67,28 @@ public boolean hasAccess(IPlayer player, IWorld world, Vector vector) {
if (world == null || vector == null) {
return false;
}



BukkitPlayer bukkitPlayer = BukkitPlayer.getPlayer(player);
Player bPlayer = bukkitPlayer != null ? bukkitPlayer.getPlayer() : null;
if (bPlayer == null) {
return true;
}

String worldName = world.getName();
Integer blockX = (int)(vector.getX());
Integer blockY = (int)(vector.getY());
Integer blockZ = (int)(vector.getZ());
PS ps = PS.valueOf(worldName,
Integer blockX = (int) (vector.getX());
Integer blockY = (int) (vector.getY());
Integer blockZ = (int) (vector.getZ());

PS ps = PS.valueOf(worldName,
blockX, blockY, blockZ,
null, null, null, null, null, null, null, null, null, null);



return EngineMain.canPlayerBuildAt(bPlayer, ps, false);
}

@Override
public boolean canPlace(IPlayer player, IWorld world, Vector vector, BlockData oldBlock, BlockData newBlock) {
return hasAccess(player, world, vector);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* BlocksHub a library plugin providing easy access to block loggers
* and block access controllers.
* Copyright (c) 2017, SBPrime <https://github.com/SBPrime/>
* Copyright (c) BlocksHub contributors
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted free of charge provided that the following
* conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution,
* 3. Redistributions of source code, with or without modification, in any form
* other then free of charge is not allowed,
* 4. Redistributions in binary form in any form other then free of charge is
* not allowed.
* 5. Any derived work based on or containing parts of this software must reproduce
* the above copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with the
* derived work.
* 6. The original author of the software is allowed to change the license
* terms or the entire license of the software as he sees fit.
* 7. The original author of the software is allowed to sublicense the software
* or its parts using any license terms he sees fit.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.primesoft.blockshub.accessors.bukkit.factions;

import com.massivecraft.factions.Factions;
import com.massivecraft.factions.engine.EnginePermBuild;
import com.massivecraft.massivecore.ps.PS;
import org.bukkit.entity.Player;
import org.primesoft.blockshub.api.BlockData;
import org.primesoft.blockshub.api.IAccessController;
import org.primesoft.blockshub.api.IPlayer;
import org.primesoft.blockshub.api.IWorld;
import org.primesoft.blockshub.api.Vector;
import org.primesoft.blockshub.platform.bukkit.BukkitBaseEntity;
import org.primesoft.blockshub.platform.bukkit.BukkitPlayer;

/**
*
* @author SBPrime
*/
public class FactionsAc12 extends BukkitBaseEntity implements IAccessController {
public FactionsAc12(Factions plugin) {
super(plugin, "Factions");
}

@Override
public boolean hasAccess(IPlayer player, IWorld world, Vector vector) {
if (world == null || vector == null) {
return false;
}

BukkitPlayer bukkitPlayer = BukkitPlayer.getPlayer(player);
Player bPlayer = bukkitPlayer != null ? bukkitPlayer.getPlayer() : null;
if (bPlayer == null) {
return true;
}

String worldName = world.getName();
Integer blockX = (int) (vector.getX());
Integer blockY = (int) (vector.getY());
Integer blockZ = (int) (vector.getZ());

PS ps = PS.valueOf(worldName,
blockX, blockY, blockZ,
null, null, null, null, null, null, null, null, null, null);

return EnginePermBuild.canPlayerBuildAt(bPlayer, ps, false);
}

@Override
public boolean canPlace(IPlayer player, IWorld world, Vector vector, BlockData oldBlock, BlockData newBlock) {
return hasAccess(player, world, vector);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@

package org.primesoft.blockshub.accessors.bukkit.factions;

import com.massivecraft.factions.Factions;
import com.massivecraft.factions.engine.EngineMain;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.primesoft.blockshub.IBlocksHubApi;
import org.primesoft.blockshub.api.BaseAccessorEndpoint;
import org.primesoft.blockshub.api.IAccessController;
Expand All @@ -57,6 +61,27 @@ public FactionsPlugin() {

@Override
protected IAccessController createAccessor(IBlocksHubApi api, IPlatform platform, Object plugin) {
return FactionsAc.create(this, plugin);
if (!(plugin instanceof Factions)) {
log("plugin not found.");
return null;
}

try {
if (EngineMain.get() != null) {
return new FactionsAc((Factions)plugin);
}
} catch (Error ex) {
}

try {
if (Class.forName("com.massivecraft.factions.engine.EnginePermBuild") != null) {
return new FactionsAc12((Factions)plugin);
}
} catch (Error ex) {
} catch (Exception ex) {
}

log("unsupported version");
return null;
}
}

0 comments on commit 81de52b

Please sign in to comment.