diff --git a/src/main/java/top/penowl/quidproquo/Events.java b/src/main/java/top/penowl/quidproquo/Events.java index ab0b43c..c2ab75c 100644 --- a/src/main/java/top/penowl/quidproquo/Events.java +++ b/src/main/java/top/penowl/quidproquo/Events.java @@ -14,6 +14,7 @@ import org.bukkit.ChatColor; import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.OfflinePlayer; import org.bukkit.Sound; import org.bukkit.block.Block; import org.bukkit.entity.EntityType; @@ -58,15 +59,20 @@ public final class Events implements Listener { } Collections.sort(uuids); - // if the player already has a target, pick the next one, otherwise pick the first - if (QuidProQuo.instance.targets.containsKey(playerUuid)) { - UUID current_target = QuidProQuo.instance.targets.get(playerUuid); - if (Bukkit.getPlayer(QuidProQuo.instance.targets.get(playerUuid)) == null) { + if (uuids.size() == 0) { + player.sendMessage(ChatColor.YELLOW + "No targets online!"); + } else { + // if the player already has a target, pick the next one, otherwise pick the first + if (QuidProQuo.instance.targets.containsKey(playerUuid)) { + UUID current_target = QuidProQuo.instance.targets.get(playerUuid); + if (Bukkit.getPlayer(QuidProQuo.instance.targets.get(playerUuid)) instanceof OfflinePlayer) { + QuidProQuo.instance.targets.put(playerUuid, uuids.get(0)); + } + QuidProQuo.instance.targets.put(playerUuid, uuids.get((uuids.indexOf(current_target) + 1) % uuids.size())); + } else { QuidProQuo.instance.targets.put(playerUuid, uuids.get(0)); } - QuidProQuo.instance.targets.put(playerUuid, uuids.get((uuids.indexOf(current_target) + 1) % uuids.size())); - } else { - QuidProQuo.instance.targets.put(playerUuid, uuids.get(0)); + player.sendMessage(ChatColor.YELLOW + "Switched target to " + Bukkit.getPlayer(QuidProQuo.instance.targets.get(playerUuid))); } // friendly message @@ -182,13 +188,17 @@ public final class Events implements Listener { } Collections.sort(uuids); - if (!QuidProQuo.instance.targets.containsKey(playerUuid)) { - QuidProQuo.instance.targets.put(playerUuid, uuids.get(0)); + if (uuids.size() == 0) { + otherPlayer = null; + } else { + if (!QuidProQuo.instance.targets.containsKey(playerUuid)) { + QuidProQuo.instance.targets.put(playerUuid, uuids.get(0)); + } + if (Bukkit.getPlayer(QuidProQuo.instance.targets.get(playerUuid)) instanceof OfflinePlayer) { + QuidProQuo.instance.targets.put(playerUuid, uuids.get(0)); + } + otherPlayer = Bukkit.getPlayer(QuidProQuo.instance.targets.get(playerUuid)); } - if (Bukkit.getPlayer(QuidProQuo.instance.targets.get(playerUuid)) == null) { - QuidProQuo.instance.targets.put(playerUuid, uuids.get(0)); - } - otherPlayer = Bukkit.getPlayer(QuidProQuo.instance.targets.get(playerUuid)); // backfire check, if succeeds then the ritual gets reversed if(new Random().nextDouble() >= ritual.backfire) { diff --git a/src/main/java/top/penowl/quidproquo/QuidProQuo.java b/src/main/java/top/penowl/quidproquo/QuidProQuo.java index df8d260..b8ae2eb 100644 --- a/src/main/java/top/penowl/quidproquo/QuidProQuo.java +++ b/src/main/java/top/penowl/quidproquo/QuidProQuo.java @@ -6,10 +6,7 @@ import java.util.UUID; import org.bukkit.event.HandlerList; import org.bukkit.plugin.java.JavaPlugin; -import top.penowl.quidproquo.rituals.FeedingRitual; -import top.penowl.quidproquo.rituals.HealRitual; -import top.penowl.quidproquo.rituals.SnowmanRitual; -import top.penowl.quidproquo.rituals.WoolingRitual; +import top.penowl.quidproquo.rituals.*; public class QuidProQuo extends JavaPlugin { @@ -38,6 +35,7 @@ public class QuidProQuo extends JavaPlugin { rituals.add(new WoolingRitual()); rituals.add(new FeedingRitual()); rituals.add(new SnowmanRitual()); + rituals.add(new GetLuckyRitual()); // run ritual setup scripts for (Ritual ritual : rituals) { diff --git a/src/main/java/top/penowl/quidproquo/rituals/FeedingRitual.java b/src/main/java/top/penowl/quidproquo/rituals/FeedingRitual.java index a403e23..08ec3a2 100644 --- a/src/main/java/top/penowl/quidproquo/rituals/FeedingRitual.java +++ b/src/main/java/top/penowl/quidproquo/rituals/FeedingRitual.java @@ -13,7 +13,7 @@ public class FeedingRitual extends Ritual { public void setup() { addSacrifice(EntityType.PIG, 1); addIngredient(Material.WOOD_SWORD, 1); - health = 4; + health = 1; name = "feeding"; } diff --git a/src/main/java/top/penowl/quidproquo/rituals/GetLuckyRitual.java b/src/main/java/top/penowl/quidproquo/rituals/GetLuckyRitual.java new file mode 100644 index 0000000..9a75979 --- /dev/null +++ b/src/main/java/top/penowl/quidproquo/rituals/GetLuckyRitual.java @@ -0,0 +1,30 @@ +package top.penowl.quidproquo.rituals; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import top.penowl.quidproquo.Ritual; + +public class GetLuckyRitual extends Ritual { + + @Override + public void setup() { + addIngredient(Material.GOLD_BLOCK, 3); + addIngredient(Material.TNT, 1); + health = 3; + lightning = true; + name = "daring"; + } + + @Override + public void execute(Player caster, Player target, Location location) { + if (Math.random() < 0.5) { + location.getWorld().createExplosion(location, 100F); + } else { + byproducts.add(new ItemStack(Material.GOLD_BLOCK, 16)); + } + } + +}