Skip to content

Commit

Permalink
Merge pull request #1 from retromcorg/Factions-Import-Support
Browse files Browse the repository at this point in the history
Faction Import Support and Fundamentals Depedency Removal
  • Loading branch information
RhysB authored Mar 30, 2024
2 parents ded796f + 535b75f commit 702b31a
Show file tree
Hide file tree
Showing 24 changed files with 1,524 additions and 105 deletions.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>groupId</groupId>
<artifactId>JVillage</artifactId>
<version>1.0.12-SNAPSHOT</version>
<version>1.0.13-SNAPSHOT</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down Expand Up @@ -105,6 +105,12 @@
<version>3.1.0</version>
</dependency>

<dependency>
<groupId>com.massivecraft</groupId>
<artifactId>factions</artifactId>
<version>1.5.1</version>
</dependency>

</dependencies>

</project>
109 changes: 109 additions & 0 deletions src/main/java/com/johnymuffin/jvillage/beta/JVUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@
import com.johnymuffin.jvillage.beta.models.VCords;
import com.johnymuffin.jvillage.beta.models.Village;
import com.johnymuffin.jvillage.beta.models.chunk.VChunk;
import com.projectposeidon.api.PoseidonUUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

public class JVUtility {
Expand Down Expand Up @@ -94,5 +101,107 @@ public static String formatUsernames(JVillage plugin, UUID[] players) {
return stringBuilder.toString();
}

public static UUID getUUIDFromPoseidonCache(String username) {
UUID uuid = PoseidonUUID.getPlayerUUIDFromCache(username, true);

if(uuid == null) {
uuid = PoseidonUUID.getPlayerUUIDFromCache(username, false);
}

return uuid;
}

//Essentials Code Start: com.earth2me.essentials.Util
private static final Set<Integer> AIR_MATERIALS = new HashSet<Integer>();

static {
AIR_MATERIALS.add(Material.AIR.getId());
AIR_MATERIALS.add(Material.SAPLING.getId());
AIR_MATERIALS.add(Material.POWERED_RAIL.getId());
AIR_MATERIALS.add(Material.DETECTOR_RAIL.getId());
AIR_MATERIALS.add(Material.DEAD_BUSH.getId());
AIR_MATERIALS.add(Material.RAILS.getId());
AIR_MATERIALS.add(Material.YELLOW_FLOWER.getId());
AIR_MATERIALS.add(Material.RED_ROSE.getId());
AIR_MATERIALS.add(Material.RED_MUSHROOM.getId());
AIR_MATERIALS.add(Material.BROWN_MUSHROOM.getId());
AIR_MATERIALS.add(Material.SEEDS.getId());
AIR_MATERIALS.add(Material.SIGN_POST.getId());
AIR_MATERIALS.add(Material.WALL_SIGN.getId());
AIR_MATERIALS.add(Material.LADDER.getId());
AIR_MATERIALS.add(Material.SUGAR_CANE_BLOCK.getId());
AIR_MATERIALS.add(Material.REDSTONE_WIRE.getId());
AIR_MATERIALS.add(Material.REDSTONE_TORCH_OFF.getId());
AIR_MATERIALS.add(Material.REDSTONE_TORCH_ON.getId());
AIR_MATERIALS.add(Material.TORCH.getId());
AIR_MATERIALS.add(Material.SOIL.getId());
AIR_MATERIALS.add(Material.DIODE_BLOCK_OFF.getId());
AIR_MATERIALS.add(Material.DIODE_BLOCK_ON.getId());
AIR_MATERIALS.add(Material.TRAP_DOOR.getId());
AIR_MATERIALS.add(Material.STONE_BUTTON.getId());
AIR_MATERIALS.add(Material.STONE_PLATE.getId());
AIR_MATERIALS.add(Material.WOOD_PLATE.getId());
AIR_MATERIALS.add(Material.IRON_DOOR_BLOCK.getId());
AIR_MATERIALS.add(Material.WOODEN_DOOR.getId());
}

public static Location getSafeDestination(final Location loc) throws Exception {
if (loc == null || loc.getWorld() == null) {
throw new Exception("Invalid Location Object");
}
final World world = loc.getWorld();
int x = (int) Math.round(loc.getX());
int y = (int) Math.round(loc.getY());
int z = (int) Math.round(loc.getZ());

while (isBlockAboveAir(world, x, y, z)) {
y -= 1;
if (y < 0) {
break;
}
}

while (isBlockUnsafe(world, x, y, z)) {
y += 1;
if (y >= 127) {
x += 1;
break;
}
}
while (isBlockUnsafe(world, x, y, z)) {
y -= 1;
if (y <= 1) {
y = 127;
x += 1;
if (x - 32 > loc.getBlockX()) {
throw new Exception("Sorry, there is a hole in the floor");
}
}
}
return new Location(world, x + 0.5D, y, z + 0.5D, loc.getYaw(), loc.getPitch());
}

private static boolean isBlockAboveAir(final World world, final int x, final int y, final int z) {
return AIR_MATERIALS.contains(world.getBlockAt(x, y - 1, z).getType().getId());
}

private static boolean isBlockUnsafe(final World world, final int x, final int y, final int z) {
final Block below = world.getBlockAt(x, y - 1, z);
if (below.getType() == Material.LAVA || below.getType() == Material.STATIONARY_LAVA) {
return true;
}

if (below.getType() == Material.FIRE) {
return true;
}

if ((!AIR_MATERIALS.contains(world.getBlockAt(x, y, z).getType().getId()))
|| (!AIR_MATERIALS.contains(world.getBlockAt(x, y + 1, z).getType().getId()))) {
return true;
}
return isBlockAboveAir(world, x, y, z);
}
//Essentials Code End


}
Loading

0 comments on commit 702b31a

Please sign in to comment.