Skip to content

Commit

Permalink
Merge branch 'Narimm-patch-1' of https://github.com/Narimm/uSkyBlock-1
Browse files Browse the repository at this point in the history
…into Narimm-Narimm-patch-1
  • Loading branch information
rlf committed Dec 29, 2016
2 parents eeb45d1 + 70de9d2 commit b213710
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,19 @@
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Blaze;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.PigZombie;
import org.bukkit.entity.Player;
import org.bukkit.entity.Skeleton;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import us.talabrek.ultimateskyblock.handler.EntitySpawner;
import us.talabrek.ultimateskyblock.uSkyBlock;
import us.talabrek.ultimateskyblock.util.LocationUtil;
import us.talabrek.ultimateskyblock.util.MaterialUtil;
Expand Down Expand Up @@ -54,6 +50,7 @@ public class NetherTerraFormEvents implements Listener {
private final boolean netherRoof;
private final double minPitch;
private final double maxPitch;
private final EntitySpawner entitySpawner;

public NetherTerraFormEvents(uSkyBlock plugin) {
this.plugin = plugin;
Expand Down Expand Up @@ -89,6 +86,7 @@ public NetherTerraFormEvents(uSkyBlock plugin) {
chanceWither = 0.4;
chanceSkeleton = 0.1;
}
entitySpawner = new EntitySpawner();
}

@EventHandler(priority = EventPriority.LOW)
Expand Down Expand Up @@ -260,16 +258,11 @@ public void onCreatureSpawn(CreatureSpawnEvent e) {
e.setCancelled(true);
double p = RND.nextDouble();
if (p <= chanceWither) {
// Spawn Wither.
Skeleton mob = (Skeleton) e.getLocation().getWorld().spawnEntity(e.getLocation(), EntityType.SKELETON);
mob.setSkeletonType(Skeleton.SkeletonType.WITHER);
mob.getEquipment().setItemInHand(new ItemStack(Material.STONE_SWORD, 1));
entitySpawner.spawnWitherSkeleton(e.getLocation());
} else if (p <= chanceWither+chanceBlaze) {
// Spawn Blaze
Blaze mob = (Blaze) e.getLocation().getWorld().spawnEntity(e.getLocation(), EntityType.BLAZE);
entitySpawner.spawnBlaze(e.getLocation());
} else if (p <= chanceWither+chanceBlaze+chanceSkeleton) {
// Spawn Skeleton
Skeleton mob = (Skeleton) e.getLocation().getWorld().spawnEntity(e.getLocation(), EntityType.SKELETON);
entitySpawner.spawnSkeleton(e.getLocation());
} else {
e.setCancelled(false); // Spawn PigZombie
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package us.talabrek.ultimateskyblock.handler;

import dk.lockfuglsang.minecraft.reflection.ReflectionUtil;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Blaze;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Skeleton;
import org.bukkit.inventory.ItemStack;
import us.talabrek.ultimateskyblock.util.VersionUtil;

/**
* Abstraction for spawning entities (cross-version-support)
*/
public class EntitySpawner {
public Skeleton spawnWitherSkeleton(Location location) {
String craftBukkitVersion = ReflectionUtil.getCraftBukkitVersion();
VersionUtil.Version version = VersionUtil.getVersion(craftBukkitVersion);
Skeleton mob;
// TODO: R4zorax - 29-12-2016: The deprecated parts might need to be used using reflection *sigh*
if (version.isGTE("1.11")) {
mob = (Skeleton) location.getWorld().spawnEntity(location, EntityType.fromId(5));
} else {
mob = (Skeleton) location.getWorld().spawnEntity(location, EntityType.SKELETON);
mob.setSkeletonType(Skeleton.SkeletonType.WITHER);
}
mob.getEquipment().setItemInMainHand(new ItemStack(Material.STONE_SWORD, 1));
return mob;
}

public Blaze spawnBlaze(Location location) {
return (Blaze) location.getWorld().spawnEntity(location, EntityType.BLAZE);
}

public Skeleton spawnSkeleton(Location location) {
return (Skeleton) location.getWorld().spawnEntity(location, EntityType.SKELETON);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Utility methods for versions
*/
public enum VersionUtil {;
private static final Pattern VERSION_PATTERN = Pattern.compile("v?(?<major>[0-9]+)\\.(?<minor>[0-9]+)(?:\\.(?<micro>[0-9]+))?(?<sub>.*)");
private static final Pattern VERSION_PATTERN = Pattern.compile("v?(?<major>[0-9]+)[\\._](?<minor>[0-9]+)(?:[\\._](?<micro>[0-9]+))?(?<sub>.*)");
public static Version getVersion(String versionString) {
Matcher m = VERSION_PATTERN.matcher(versionString);
if (m.matches()) {
Expand Down

0 comments on commit b213710

Please sign in to comment.