forked from Zrips/Residence
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
- Loading branch information
Showing
24 changed files
with
376 additions
and
181 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.bekvon.bukkit.residence.bigDoors; | ||
|
||
import nl.pim16aap2.bigDoors.compatibility.IProtectionCompat; | ||
import nl.pim16aap2.bigDoors.compatibility.IProtectionCompatDefinition; | ||
|
||
public class BigDoorsDef implements IProtectionCompatDefinition { | ||
|
||
private final String name; | ||
|
||
public BigDoorsDef(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public Class<? extends IProtectionCompat> getClass(String arg0) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
src/com/bekvon/bukkit/residence/bigDoors/BigDoorsManager.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,53 @@ | ||
package com.bekvon.bukkit.residence.bigDoors; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import com.bekvon.bukkit.residence.Residence; | ||
|
||
import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; | ||
import net.Zrips.CMILib.Version.Schedulers.CMITask; | ||
import nl.pim16aap2.bigDoors.BigDoors; | ||
import nl.pim16aap2.bigDoors.compatibility.IProtectionCompat; | ||
import nl.pim16aap2.bigDoors.compatibility.ProtectionCompatManager; | ||
|
||
public class BigDoorsManager { | ||
|
||
// Fail safe to avoid infinite checks | ||
private final static int TRIES = 3; | ||
private static int times = 0; | ||
private static CMITask task = null; | ||
|
||
public static void register(Residence residence) { | ||
task = CMIScheduler.scheduleSyncRepeatingTask(() -> { | ||
++times; | ||
if (times >= TRIES) { | ||
residence.consoleMessage("&cFailed to initialize BigDoors support"); | ||
task.cancel(); | ||
} | ||
|
||
ProtectionCompatManager manager = BigDoors.get().getProtectionCompatManager(); | ||
|
||
// Wait for protectionManager to load (loaded on first server tick) | ||
if (manager != null) { | ||
try { | ||
|
||
manager.registerProtectionCompatDefinition(new BigDoorsDef("Residence") { | ||
@Override | ||
public Class<? extends IProtectionCompat> getClass(String version) { | ||
return BigDoorsModule.class; | ||
} | ||
}); | ||
|
||
Method method = manager.getClass().getDeclaredMethod("addProtectionCompat", IProtectionCompat.class); | ||
method.setAccessible(true); | ||
method.invoke(manager, new BigDoorsModule()); | ||
|
||
residence.consoleMessage("Enabled compatability with BigDoors plugin"); | ||
task.cancel(); | ||
} catch (Throwable e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
}, 20, 20); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/com/bekvon/bukkit/residence/bigDoors/BigDoorsModule.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,49 @@ | ||
package com.bekvon.bukkit.residence.bigDoors; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.util.Vector; | ||
|
||
import com.bekvon.bukkit.residence.listeners.ResidenceBlockListener; | ||
import com.bekvon.bukkit.residence.protection.CuboidArea; | ||
|
||
import nl.pim16aap2.bigDoors.compatibility.IProtectionCompat; | ||
|
||
public class BigDoorsModule implements IProtectionCompat { | ||
|
||
@Override | ||
public boolean canBreakBlock(Player player, Location loc) { | ||
return ResidenceBlockListener.canBreakBlock(player, loc, false); | ||
} | ||
|
||
@Override | ||
public boolean canBreakBlocksBetweenLocs(Player player, Location loc1, Location loc2) { | ||
|
||
CuboidArea area = new CuboidArea(loc1, loc2); | ||
|
||
Vector min = area.getLowVector(); | ||
Vector max = area.getHighVector(); | ||
|
||
for (int xPos = min.getBlockX(); xPos <= max.getBlockX(); xPos++) { | ||
for (int yPos = min.getBlockY(); yPos <= max.getBlockY(); yPos++) { | ||
for (int zPos = min.getBlockZ(); zPos <= max.getBlockZ(); zPos++) { | ||
if (!ResidenceBlockListener.canBreakBlock(player, new Location(loc1.getWorld(), xPos, yPos, zPos), false)) { | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "Residence"; | ||
} | ||
|
||
@Override | ||
public boolean success() { | ||
return true; | ||
} | ||
} |
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
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
Oops, something went wrong.