Skip to content

Commit

Permalink
Starting to adding (M)uSkyblock support
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoxkk0 committed May 19, 2020
1 parent 409e8c0 commit 563bb5f
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 1 deletion.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ dependencies {

compileOnly 'com.sk89q.worldedit:worldedit-bukkit:6.1.5'
compileOnly 'com.sk89q.worldedit:worldedit-core:6.0.0-SNAPSHOT'

compileOnly 'com.sk89q.worldguard:worldguard-legacy:6.2'
compileOnly 'com.github.TechFortress:GriefPrevention:16.12.0'
compileOnly 'com.plotsquared:PlotSquared:5.1'
compileOnly fileTree(dir: 'flatLibs', include: '*.jar')

}
Binary file added flatLibs/MuSkyBlock-1.0-SNAPSHOT.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions src/main/java/net/kaikk/mc/fr/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void load() {
ProtectionPlugins.GriefPrevention.setEnabled(this.config.getBoolean("Protection.GriefPrevention", true));
ProtectionPlugins.PlotSquared.setEnabled(this.config.getBoolean("Protection.PlotSquared", true));
ProtectionPlugins.WorldGuard.setEnabled(this.config.getBoolean("Protection.WorldGuard", true));
ProtectionPlugins.uSkyBlock.setEnabled(this.config.getBoolean("Protection.uSkyBlock", true));

this.whitelist= new ArrayList<>();
for (String serialized : this.config.getStringList("Whitelist")) {
Expand Down Expand Up @@ -72,6 +73,7 @@ void save() {
this.config.set("Protection.GriefPrevention", ProtectionPlugins.GriefPrevention.isEnabled());
this.config.set("Protection.PlotSquared", ProtectionPlugins.PlotSquared.isEnabled());
this.config.set("Protection.WorldGuard", ProtectionPlugins.WorldGuard.isEnabled());
this.config.set("Protection.uSkyBlock", ProtectionPlugins.uSkyBlock.isEnabled());

this.config.set("Whitelist", serializeListedItemList(this.whitelist));
this.config.set("Ranged", serializeListedItemList(this.ranged));
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/net/kaikk/mc/fr/ProtectionPlugins.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import net.kaikk.mc.fr.protectionplugins.GriefPreventionHandler;
import net.kaikk.mc.fr.protectionplugins.PlotSquaredHandler;
import net.kaikk.mc.fr.protectionplugins.WorldGuardHandler;
import net.kaikk.mc.fr.protectionplugins.uSkyBlockHandler;

enum ProtectionPlugins {

GriefPrevention(GriefPreventionHandler.class),
PlotSquared(PlotSquaredHandler.class),
WorldGuard(WorldGuardHandler.class);
WorldGuard(WorldGuardHandler.class),
uSkyBlock(uSkyBlockHandler.class);

private final Class<? extends ProtectionHandler> clazz;
private ProtectionHandler handler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.sk89q.worldguard.protection.regions.ProtectedRegion;

public class WorldGuardHandler implements ProtectionHandler {

WorldGuardPlugin worldGuard;

public WorldGuardHandler() {
Expand Down
156 changes: 156 additions & 0 deletions src/main/java/net/kaikk/mc/fr/protectionplugins/uSkyBlockHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
package net.kaikk.mc.fr.protectionplugins;

import net.kaikk.mc.fr.ProtectionHandler;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import us.talabrek.ultimateskyblock.api.IslandInfo;
import us.talabrek.ultimateskyblock.api.uSkyBlockAPI;
import us.talabrek.ultimateskyblock.uSkyBlock;


public class uSkyBlockHandler implements ProtectionHandler {

uSkyBlockAPI uSkyBlockAPI = (us.talabrek.ultimateskyblock.api.uSkyBlockAPI) Bukkit.getPluginManager().getPlugin("uSkyBlock");

private int islandSize = -1;

public uSkyBlockHandler(){

islandSize = uSkyBlockAPI.getConfig().getInt("options.island.protectionRange", -1);

if(islandSize == -1) islandSize = 64; // Maybe it's a good number

}

@Override
public String getName() {
return "uSkyBlock";
}

public IslandInfo getIslandInfo(Location location){

if(uSkyBlockAPI != null){
System.out.println("!");
return (((uSkyBlock)uSkyBlockAPI).getIslandInfo(location));
}
System.out.println("@");
return null;
}

public boolean isMember(Player player, IslandInfo islandInfo){
System.out.println(islandInfo.getMembers());
return islandInfo.getMembers().contains(player.getName());
}

public boolean haveAccess(Player player, Location location){
IslandInfo islandInfo;

System.out.println("A");

if((islandInfo = getIslandInfo(location)) != null){

System.out.println("B");

return isMember(player, islandInfo);
}

System.out.println("C");
return false;
}

@Override
public boolean canBuild(Player player, Location location) {
return haveAccess(player, location);
}

@Override
public boolean canAccess(Player player, Location location) {
return haveAccess(player, location);
}

@Override
public boolean canUse(Player player, Location location) {
return haveAccess(player, location);
}

@Override
public boolean canOpenContainer(Player player, Block block) {
return haveAccess(player, block.getLocation());
}

@Override
public boolean canInteract(Player player, Location location) {
return haveAccess(player, location);
}

@Override
public boolean canAttack(Player damager, Entity damaged) {
return haveAccess(damager, damaged.getLocation());
}

@Override
public boolean canProjectileHit(Player player, Location location) {
return haveAccess(player, location);
}

@Override
public boolean canUseAoE(Player player, Location location, int range) {

IslandInfo islandInfo;
Location isCenter = null;

if((islandInfo = getIslandInfo(location)) != null){
isCenter = islandInfo.getIslandLocation();
}

if(isCenter != null){

int lx = isCenter.getBlockX() - islandSize;
int lz = isCenter.getBlockZ() - islandSize;

int ux = isCenter.getBlockX() + islandSize;
int uz = isCenter.getBlockZ() + islandSize;

if(isOnBounds(isCenter, lx, lz, ux, uz)){
return canAccess(player, location);
}

}

int x1 = location.getBlockX() + range;
int z1 = location.getBlockZ() + range;

int x2 = location.getBlockX() - range;
int z2 = location.getBlockZ() - range;

IslandInfo predominantIsland = null;

for(int i = x2; i < x1; i++) {
for (int k = z2; k < z1; k++) {
if(predominantIsland != null){

int lx = predominantIsland.getIslandLocation().getBlockX() - islandSize;
int lz = predominantIsland.getIslandLocation().getBlockZ() - islandSize;
int ux = predominantIsland.getIslandLocation().getBlockX() + islandSize;
int uz = predominantIsland.getIslandLocation().getBlockZ() + islandSize;

if(isOnBounds(predominantIsland.getIslandLocation(), lx, lz, ux, uz)){
return canAccess(player, location);
}

}else {
predominantIsland = getIslandInfo(new Location(location.getWorld(), i, location.getBlockY(), k));
}
}
}

return false;
}

public boolean isOnBounds(Location location, int lx, int lz, int ux, int uz){
return (location.getBlockX() > lx && location.getBlockX() < ux && location.getBlockZ() > lz && location.getBlockZ() < uz);
}
}

0 comments on commit 563bb5f

Please sign in to comment.