summaryrefslogtreecommitdiff
path: root/src/main/java/com/encrox/zombie/Mob.java
blob: 82958a30b3485bbd636bb594cf2219563a9ff685 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.encrox.zombie;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

import org.bukkit.entity.EntityType;
import org.bukkit.util.BlockVector;

import com.encrox.zombie.interactable.Lever;

public class Mob {
	
	public EntityType type;
	public BlockVector bv;
	public String rounds;
	public Lever[] levers;
	
	public Mob(EntityType type, BlockVector bv, String rounds, Lever[] levers) {
		this.type = type;
		this.bv = bv;
		this.rounds = rounds;
		this.levers = levers;
	}
	
	public boolean spawn(int round) {
		for(int i = 0; i<levers.length; i++) {
			if(!levers[i].isToggled())
				return false;
		}
		ScriptEngineManager factory = new ScriptEngineManager();
		ScriptEngine engine = factory.getEngineByName("JavaScript");
		try {
			return (boolean)engine.eval(rounds.replace("%round%", ""+round));
		} catch (ScriptException e) {
			e.printStackTrace();
		}
		return false;
	}

}