-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADD: Added support for GriefPrevention 8.x
- Loading branch information
prime
authored and
prime
committed
Oct 4, 2014
1 parent
008cae1
commit 9b7c89a
Showing
8 changed files
with
297 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
BlocksHub/src/org/PrimeSoft/blocksHub/accessControl/GriefPrevention/GriefPrevention7x.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
BlocksHub/src/org/PrimeSoft/blocksHub/accessControl/GriefPrevention/GriefPrevention8x.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
BlocksHub/src/org/PrimeSoft/blocksHub/accessControl/GriefPrevention/GriefPreventionBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.