Add rituals
This commit is contained in:
parent
7188a5efb3
commit
ad541a262c
@ -1,8 +1,5 @@
|
||||
package top.penowl.quidproquo;
|
||||
|
||||
import com.avaje.ebean.LogLevel;
|
||||
import com.sun.tools.sjavac.Log.Level;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
|
@ -1,22 +0,0 @@
|
||||
package top.penowl.quidproquo;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class Application extends JavaPlugin {
|
||||
|
||||
public ArrayList<Ritual> rituals = new ArrayList<Ritual>();
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getLogger().info("Hello, SpigotMC!");
|
||||
getServer().getPluginManager().registerEvents(new Events(), this);
|
||||
}
|
||||
@Override
|
||||
public void onDisable() {
|
||||
getLogger().info("See you again, SpigotMC!");
|
||||
HandlerList.unregisterAll(this);
|
||||
}
|
||||
|
||||
}
|
@ -1,22 +1,152 @@
|
||||
package top.penowl.quidproquo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public final class Events implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public static void onPlayerInteract(PlayerInteractEvent event) {
|
||||
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
|
||||
Block block = event.getClickedBlock();
|
||||
Player player = event.getPlayer();
|
||||
Location location = block.getLocation();
|
||||
|
||||
if (!Altar.CheckAltar(block.getLocation())) return;
|
||||
|
||||
if (player.isSneaking()) {
|
||||
|
||||
// change target
|
||||
|
||||
if (Altar.CheckAltar(block.getLocation())) {
|
||||
player.sendMessage("you clicked an altar");
|
||||
} else {
|
||||
player.sendMessage("not an altar");
|
||||
|
||||
Boolean success = false;
|
||||
|
||||
Collection<Item> items = block.getWorld().getEntitiesByClass(Item.class);
|
||||
ArrayList<Item> near_items = new ArrayList<Item>();
|
||||
|
||||
for (Item item : items) {
|
||||
if (item.getLocation().distance(location) < 2) {
|
||||
near_items.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
Bukkit.getLogger().info(near_items.toString());
|
||||
|
||||
Collection<LivingEntity> sacrifices = block.getWorld().getEntitiesByClass(LivingEntity.class);
|
||||
ArrayList<LivingEntity> near_sacrifices = new ArrayList<LivingEntity>();
|
||||
|
||||
for (LivingEntity sacrifice : sacrifices) {
|
||||
if (sacrifice.getLocation().distance(location) < 2) {
|
||||
near_sacrifices.add(sacrifice);
|
||||
}
|
||||
}
|
||||
|
||||
for (Ritual ritual : QuidProQuo.instance.rituals) {
|
||||
ArrayList<List<Item>> possibleItems = new ArrayList<List<Item>>();
|
||||
ArrayList<List<LivingEntity>> possibleSacrifices = new ArrayList<List<LivingEntity>>();
|
||||
Boolean failed = false;
|
||||
ArrayList<ItemStack> byproducts = new ArrayList<ItemStack>();
|
||||
for (Map.Entry<Material, Integer> entry : ritual.ingredients.entrySet()) {
|
||||
Material material = entry.getKey();
|
||||
int count = entry.getValue();
|
||||
|
||||
List<Item> matches = near_items.stream().filter(item -> item.getItemStack().getType() == material).collect(Collectors.toList());
|
||||
int matchCount = 0;
|
||||
for (Item item : matches) {
|
||||
matchCount += item.getItemStack().getAmount();
|
||||
}
|
||||
if (matchCount >= count) {
|
||||
possibleItems.add(matches);
|
||||
byproducts.add(new ItemStack(material, matchCount - count));
|
||||
} else {
|
||||
failed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (Map.Entry<EntityType, Integer> entry : ritual.sacrifices.entrySet()) {
|
||||
EntityType entityType = entry.getKey();
|
||||
int count = entry.getValue();
|
||||
|
||||
List<LivingEntity> matches = near_sacrifices.stream().filter(entity -> entity.getType() == entityType).limit(count).collect(Collectors.toList());
|
||||
if (matches.size() >= count) {
|
||||
possibleSacrifices.add(matches);
|
||||
} else {
|
||||
failed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (failed) continue;
|
||||
|
||||
for (List<Item> itemArray : possibleItems) {
|
||||
for (Item item : itemArray) {
|
||||
item.remove();
|
||||
}
|
||||
}
|
||||
|
||||
for (List<LivingEntity> sacrificeArray : possibleSacrifices) {
|
||||
for (LivingEntity sacrifice : sacrificeArray) {
|
||||
sacrifice.setHealth(0);
|
||||
}
|
||||
}
|
||||
|
||||
player.setHealth(player.getHealth() - ritual.health);
|
||||
|
||||
player.sendMessage(ChatColor.GREEN + "You enacted a " + ritual.name + " ritual.");
|
||||
|
||||
for (ItemStack additionalByproduct : ritual.byproducts) {
|
||||
byproducts.add(additionalByproduct);
|
||||
}
|
||||
|
||||
for (ItemStack byproduct : byproducts) {
|
||||
block.getLocation().getWorld().dropItem(location.clone().add(0, 2, 0), byproduct);
|
||||
}
|
||||
|
||||
if(new Random().nextDouble() >= ritual.backfire) {
|
||||
ritual.execute(player, null, block.getLocation());
|
||||
} else {
|
||||
ritual.execute(null, player, block.getLocation());
|
||||
}
|
||||
|
||||
player.playSound(player.getLocation(), Sound.EXPLODE, 50, 0);
|
||||
player.getWorld().playEffect(location.clone().add(0, 1, 0), Effect.EXPLOSION_LARGE, 0);
|
||||
player.getWorld().strikeLightningEffect(location.clone().add(0, 1, 0));
|
||||
|
||||
success = true;
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
player.sendMessage(ChatColor.RED + "You do not have the nessecary sacrifices to enact a ritual!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
41
src/main/java/top/penowl/quidproquo/QuidProQuo.java
Normal file
41
src/main/java/top/penowl/quidproquo/QuidProQuo.java
Normal file
@ -0,0 +1,41 @@
|
||||
package top.penowl.quidproquo;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
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.WoolingRitual;
|
||||
|
||||
public class QuidProQuo extends JavaPlugin {
|
||||
|
||||
public static QuidProQuo instance;
|
||||
public ArrayList<Ritual> rituals = new ArrayList<Ritual>();
|
||||
public HashMap<UUID, UUID> targets = new HashMap<UUID, UUID>();
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
getLogger().info("Hello, SpigotMC!");
|
||||
getServer().getPluginManager().registerEvents(new Events(), this);
|
||||
|
||||
rituals.add(new HealRitual());
|
||||
rituals.add(new WoolingRitual());
|
||||
rituals.add(new FeedingRitual());
|
||||
|
||||
for (Ritual ritual : rituals) {
|
||||
getLogger().info("Loading " + ritual.getClass().toString() + "...");
|
||||
ritual.setup();
|
||||
getLogger().info("Loaded a " + ritual.name + " ritual.");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onDisable() {
|
||||
getLogger().info("See you again, SpigotMC!");
|
||||
HandlerList.unregisterAll(this);
|
||||
}
|
||||
|
||||
}
|
@ -1,21 +1,31 @@
|
||||
package top.penowl.quidproquo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public abstract class Ritual {
|
||||
public HashMap<Material, Integer> ingredients = new HashMap<Material, Integer>();
|
||||
public HashMap<EntityType, Integer> sacrifices = new HashMap<EntityType, Integer>();
|
||||
public ArrayList<ItemStack> byproducts = new ArrayList<ItemStack>();
|
||||
public int health = 0;
|
||||
public abstract void execute(Player caster, Player target);
|
||||
public double backfire = 0.0;
|
||||
public String name = "unnamed";
|
||||
|
||||
public abstract void execute(Player caster, Player target, Location location);
|
||||
|
||||
public void addIngredient(Material material, int count) {
|
||||
ingredients.put(material, count);
|
||||
}
|
||||
|
||||
public void addSacrifice(EntityType type, int count) {
|
||||
sacrifices.put(type, count);
|
||||
}
|
||||
|
||||
public abstract void setup();
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package top.penowl.quidproquo.rituals;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import top.penowl.quidproquo.Ritual;
|
||||
@ -12,7 +13,7 @@ public class BlankRitual extends Ritual {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Player caster, Player target) {
|
||||
public void execute(Player caster, Player target, Location location) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,25 @@
|
||||
package top.penowl.quidproquo.rituals;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import top.penowl.quidproquo.Ritual;
|
||||
|
||||
public class FeedingRitual extends Ritual {
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
addSacrifice(EntityType.PIG, 1);
|
||||
addIngredient(Material.WOOD_SWORD, 1);
|
||||
health = 4;
|
||||
name = "feeding";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Player caster, Player target, Location location) {
|
||||
caster.setFoodLevel(20);
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package top.penowl.quidproquo.rituals;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import top.penowl.quidproquo.Ritual;
|
||||
@ -8,12 +10,13 @@ public class HealRitual extends Ritual {
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
|
||||
addIngredient(Material.REDSTONE, 9);
|
||||
name = "healing";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Player caster, Player target) {
|
||||
|
||||
public void execute(Player caster, Player target, Location location) {
|
||||
caster.setHealth(Math.min(caster.getMaxHealth(), caster.getHealth()+2.0));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
package top.penowl.quidproquo.rituals;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import top.penowl.quidproquo.Ritual;
|
||||
|
||||
public class WoolingRitual extends Ritual {
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
addIngredient(Material.IRON_SWORD, 1);
|
||||
addSacrifice(EntityType.SHEEP, 1);
|
||||
name = "wooling";
|
||||
health = 2;
|
||||
byproducts.add(new ItemStack(Material.WOOL, 100));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Player caster, Player target, Location location) {
|
||||
caster.setHealth(Math.min(caster.getMaxHealth(), caster.getHealth()+2.0));
|
||||
}
|
||||
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
main: top.penowl.quidproquo.Application
|
||||
main: top.penowl.quidproquo.QuidProQuo
|
||||
name: QuidProQuo
|
||||
version: 0.1
|
Loading…
x
Reference in New Issue
Block a user