Skip to content

Commit

Permalink
BlocksHub
Browse files Browse the repository at this point in the history
ADD: Added support for GriefPrevention 8.x
  • Loading branch information
prime authored and prime committed Oct 4, 2014
1 parent 008cae1 commit 9b7c89a
Show file tree
Hide file tree
Showing 8 changed files with 297 additions and 40 deletions.
6 changes: 4 additions & 2 deletions BlocksHub/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ endorsed.classpath=
excludes=
file.reference.CoreProtect.jar=lib/CoreProtect.jar
file.reference.craftbukkit.jar=lib/craftbukkit.jar
file.reference.GriefPrevention.jar=lib\\GriefPrevention.jar
file.reference.GriefPrevention-7x.jar=lib/GriefPrevention-7x.jar
file.reference.GriefPrevention-8x.jar=lib/GriefPrevention-8x.jar
file.reference.HawkEye.jar=lib/HawkEye.jar
file.reference.LogBlock.jar=lib/LogBlock.jar
file.reference.Prism.jar=lib/Prism.jar
Expand All @@ -44,7 +45,8 @@ javac.classpath=\
${file.reference.Residence.jar}:\
${file.reference.WorldGuard.jar}:\
${file.reference.craftbukkit.jar}:\
${file.reference.GriefPrevention.jar}
${file.reference.GriefPrevention-8x.jar}:\
${file.reference.GriefPrevention-7x.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 @@ -23,7 +23,6 @@
*/
package org.PrimeSoft.blocksHub.accessControl;

import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import org.bukkit.Server;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
Expand Down Expand Up @@ -71,6 +70,10 @@ public String getName() {
return m_name;
}

protected void disable() {

}

protected BaseAccessController(JavaPlugin plugin, final String pluginName) {
m_isEnabled = false;
PluginDescriptionFile pd = null;
Expand All @@ -87,10 +90,18 @@ protected BaseAccessController(JavaPlugin plugin, final String pluginName) {
}
} catch (NoClassDefFoundError ex) {
hook = null;
m_isEnabled = false;
}

m_hook = hook;
if (m_isEnabled) {
m_isEnabled = postInit(pd);
}
m_name = pd != null && m_isEnabled ? pd.getFullName() : "Disabled - " + pluginName;
}

m_name = pd != null ? pd.getFullName() : "Disabled - " + pluginName;
protected boolean postInit(PluginDescriptionFile pd) {
return true;
}

protected abstract boolean instanceOfT(Class<? extends Plugin> aClass);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.PrimeSoft.blocksHub.accessControl.GriefPrevention;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.logging.Level;
import java.util.logging.Logger;
import me.ryanhamshire.GriefPrevention.BlockEventHandler;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import org.PrimeSoft.blocksHub.SilentPlayer;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;

/*
* The MIT License
*
* Copyright 2014 SBPrime.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
*
* @author SBPrime
*/
public class GriefPrevention7x extends GriefPreventionBase {
@Override
public boolean Initialize(GriefPrevention hook) {
try {
m_listener = hook != null ?
(BlockEventHandler)BlockEventHandler.class.getConstructor().newInstance() : null;
return m_listener != null;
} catch (NoSuchMethodException ex) {
return false;
} catch (SecurityException ex) {
return false;
} catch (InstantiationException ex) {
return false;
} catch (IllegalAccessException ex) {
return false;
} catch (IllegalArgumentException ex) {
return false;
} catch (InvocationTargetException ex) {
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package org.PrimeSoft.blocksHub.accessControl.GriefPrevention;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import me.ryanhamshire.GriefPrevention.BlockEventHandler;
import me.ryanhamshire.GriefPrevention.DataStore;
import me.ryanhamshire.GriefPrevention.GriefPrevention;

/*
* The MIT License
*
* Copyright 2014 SBPrime.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
*
* @author SBPrime
*/
public class GriefPrevention8x extends GriefPreventionBase {

@Override
public boolean Initialize(GriefPrevention hook) {
try {
if (hook == null) {
return false;
}

Class<?> sourceClass = hook.getClass();
Field field = sourceClass.getDeclaredField("dataStore");
field.setAccessible(true);
Field modifiersField = Field.class.getDeclaredField("modifiers");

boolean accessible = modifiersField.isAccessible();
if (!accessible) {
modifiersField.setAccessible(true);
}
try {
m_listener = (BlockEventHandler) BlockEventHandler.class.getConstructor(DataStore.class)
.newInstance(field.get(hook));
} finally {
if (!accessible) {
modifiersField.setAccessible(false);
}
}

return m_listener != null;
} catch (NoSuchMethodException ex) {
ex.printStackTrace();
return false;
} catch (SecurityException ex) {
ex.printStackTrace();
return false;
} catch (InstantiationException ex) {
ex.printStackTrace();
return false;
} catch (IllegalAccessException ex) {
ex.printStackTrace();
return false;
} catch (IllegalArgumentException ex) {
ex.printStackTrace();
return false;
} catch (InvocationTargetException ex) {
ex.printStackTrace();
return false;
} catch (NoSuchFieldException ex) {
ex.printStackTrace();
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* The MIT License
*
* Copyright 2014 SBPrime.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.PrimeSoft.blocksHub.accessControl.GriefPrevention;

import me.ryanhamshire.GriefPrevention.BlockEventHandler;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import org.PrimeSoft.blocksHub.SilentPlayer;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;

/**
*
* @author SBPrime
*/
public abstract class GriefPreventionBase {
protected BlockEventHandler m_listener;

/**
* Initialize the GP hook
* @param hook
* @return
*/
public abstract boolean Initialize(GriefPrevention hook);


/**
* Test if the block can by placed
* @param player
* @param world
* @param location
* @return
*/
public boolean canPlace(Player player, World world, Location location) {
if (player == null) {
return true;
}
player = new SilentPlayer(player);
Block block = location.getBlock();

if (!block.isEmpty()) {
BlockBreakEvent event = new BlockBreakEvent(block, player);
m_listener.onBlockBreak(event);

if (event.isCancelled()) {
return false;
}
} else {
BlockPlaceEvent event = new BlockPlaceEvent(block, block.getState(), block,
player.getItemInHand(), player, true);
m_listener.onBlockPlace(event);

if (event.isCancelled()) {
return false;
}
}

//We do not support white/black lists
return true;
}
}
Loading

0 comments on commit 9b7c89a

Please sign in to comment.