mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-28 05:26:29 +01:00
New Mob System
This commit is contained in:
parent
ecacf0376e
commit
4139aecb42
133
DungeonsXL/src/com/dre/dungeonsxl/DMobType.java
Normal file
133
DungeonsXL/src/com/dre/dungeonsxl/DMobType.java
Normal file
@ -0,0 +1,133 @@
|
||||
package com.dre.dungeonsxl;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.server.Item;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.craftbukkit.entity.CraftSkeleton;
|
||||
import org.bukkit.craftbukkit.entity.CraftZombie;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.dre.dungeonsxl.game.DMob;
|
||||
import com.dre.dungeonsxl.game.GameWorld;
|
||||
|
||||
public class DMobType {
|
||||
private static Set<DMobType> mobTypes = new HashSet<DMobType>();
|
||||
|
||||
private String name;
|
||||
private EntityType type;
|
||||
|
||||
private int maxHealth;
|
||||
|
||||
private Item ItemHand;
|
||||
private Item ItemHelmet;
|
||||
private Item ItemChestplate;
|
||||
private Item ItemLeggings;
|
||||
private Item ItemBoots;
|
||||
|
||||
public DMobType(String name, EntityType type){
|
||||
mobTypes.add(this);
|
||||
|
||||
this.name=name;
|
||||
this.type=type;
|
||||
}
|
||||
|
||||
public void spawn(GameWorld gWorld, Location loc){
|
||||
if(type!=null){
|
||||
if(type.isAlive()){
|
||||
LivingEntity entity=(LivingEntity)gWorld.world.spawnEntity(loc, type);
|
||||
|
||||
/* Set the Items */
|
||||
|
||||
//Check if it's a Zombie
|
||||
if(type==EntityType.ZOMBIE){
|
||||
CraftZombie entityC = (CraftZombie)entity;
|
||||
net.minecraft.server.EntityZombie entityMC = entityC.getHandle();
|
||||
|
||||
if(ItemHand!=null) entityMC.setEquipment(0, new net.minecraft.server.ItemStack(ItemHand));
|
||||
if(ItemBoots!=null) entityMC.setEquipment(1, new net.minecraft.server.ItemStack(ItemBoots));
|
||||
if(ItemLeggings!=null) entityMC.setEquipment(2, new net.minecraft.server.ItemStack(ItemLeggings));
|
||||
if(ItemChestplate!=null) entityMC.setEquipment(3, new net.minecraft.server.ItemStack(ItemChestplate));
|
||||
if(ItemHelmet!=null) entityMC.setEquipment(4, new net.minecraft.server.ItemStack(ItemHelmet));
|
||||
}
|
||||
|
||||
//Check if it's a Skeleton
|
||||
if(type==EntityType.SKELETON){
|
||||
CraftSkeleton entityC = (CraftSkeleton)entity;
|
||||
net.minecraft.server.EntitySkeleton entityMC = entityC.getHandle();
|
||||
|
||||
if(ItemHand!=null) entityMC.setEquipment(0, new net.minecraft.server.ItemStack(ItemHand));
|
||||
if(ItemBoots!=null) entityMC.setEquipment(1, new net.minecraft.server.ItemStack(ItemBoots));
|
||||
if(ItemLeggings!=null) entityMC.setEquipment(2, new net.minecraft.server.ItemStack(ItemLeggings));
|
||||
if(ItemChestplate!=null) entityMC.setEquipment(3, new net.minecraft.server.ItemStack(ItemChestplate));
|
||||
if(ItemHelmet!=null) entityMC.setEquipment(4, new net.minecraft.server.ItemStack(ItemHelmet));
|
||||
}
|
||||
|
||||
/* Spawn Mob */
|
||||
new DMob(entity, maxHealth, gWorld);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Load Config
|
||||
public static void load(File file){
|
||||
FileConfiguration configFile = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
//Read Mobs
|
||||
for(String mobName:configFile.getKeys(true)){
|
||||
if(!mobName.contains(".")){
|
||||
DungeonsXL.p.log("Test"+mobName);
|
||||
|
||||
EntityType type=EntityType.fromName(configFile.getString(mobName+".Type"));
|
||||
|
||||
DMobType mobType=new DMobType(mobName, type);
|
||||
|
||||
//Load MaxHealth
|
||||
if(configFile.contains(mobName+".MaxHealth")){
|
||||
mobType.maxHealth=configFile.getInt(mobName+".MaxHealth");
|
||||
}
|
||||
|
||||
//Load Items
|
||||
if(configFile.contains(mobName+".ItemHelmet")){
|
||||
mobType.ItemHelmet=CraftItemStack.createNMSItemStack(new ItemStack(configFile.getInt(mobName+".ItemHelmet"))).getItem();
|
||||
}
|
||||
|
||||
if(configFile.contains(mobName+".ItemChestplate")){
|
||||
mobType.ItemChestplate=CraftItemStack.createNMSItemStack(new ItemStack(configFile.getInt(mobName+".ItemChestplate"))).getItem();
|
||||
}
|
||||
|
||||
if(configFile.contains(mobName+".ItemBoots")){
|
||||
mobType.ItemBoots=CraftItemStack.createNMSItemStack(new ItemStack(configFile.getInt(mobName+".ItemBoots"))).getItem();
|
||||
}
|
||||
|
||||
if(configFile.contains(mobName+".ItemLeggings")){
|
||||
mobType.ItemLeggings=CraftItemStack.createNMSItemStack(new ItemStack(configFile.getInt(mobName+".ItemLeggings"))).getItem();
|
||||
}
|
||||
|
||||
if(configFile.contains(mobName+".ItemHand")){
|
||||
mobType.ItemHand=CraftItemStack.createNMSItemStack(new ItemStack(configFile.getInt(mobName+".ItemHand"))).getItem();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Get
|
||||
public static DMobType get(String name){
|
||||
for(DMobType mobType:DMobType.mobTypes){
|
||||
if(mobType.name.equalsIgnoreCase(name)){
|
||||
return mobType;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -91,6 +91,9 @@ public class DungeonsXL extends JavaPlugin{
|
||||
//Load Config
|
||||
mainConfig=new ConfigReader(new File(p.getDataFolder(), "config.yml"));
|
||||
|
||||
//Load MobTypes
|
||||
DMobType.load(new File(p.getDataFolder(), "mobs.yml"));
|
||||
|
||||
// -------------------------------------------- //
|
||||
// Update Sheduler
|
||||
// -------------------------------------------- //
|
||||
|
@ -30,6 +30,8 @@ public class DMob {
|
||||
if(dmob.entity==victim){
|
||||
dmob.live=dmob.live-event.getDamage();
|
||||
dmob.entity.damage(1);
|
||||
|
||||
|
||||
dmob.entity.setHealth(dmob.entity.getMaxHealth());
|
||||
|
||||
if(event instanceof EntityDamageByEntityEvent){
|
||||
|
@ -155,7 +155,7 @@ public class GameWorld {
|
||||
}else{
|
||||
if(lines[1].equalsIgnoreCase("mob")){
|
||||
if(lines[2]!=""&&lines[3]!=""){
|
||||
EntityType mob=p.getEntitiyType(lines[2]);
|
||||
String mob=lines[2];
|
||||
if(mob!=null){
|
||||
String[] atributes=lines[3].split(",");
|
||||
if(atributes.length==3){
|
||||
|
@ -8,26 +8,28 @@ import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.dre.dungeonsxl.DMobType;
|
||||
|
||||
public class MobSpawner {
|
||||
public static CopyOnWriteArrayList<MobSpawner> mobspawners=new CopyOnWriteArrayList<MobSpawner>();
|
||||
|
||||
//Variables
|
||||
public EntityType mob;
|
||||
public Block block;
|
||||
public int maxinterval;
|
||||
public int interval=0;
|
||||
public int ammount;
|
||||
public int radius;
|
||||
private String mob;
|
||||
private Block block;
|
||||
private int maxinterval;
|
||||
private int interval=0;
|
||||
private int amount;
|
||||
private int radius;
|
||||
private int live;
|
||||
|
||||
|
||||
public MobSpawner(Block block, EntityType mob, int interval, int ammount, int radius, int live){
|
||||
public MobSpawner(Block block, String mob, int interval, int amount, int radius, int live){
|
||||
mobspawners.add(this);
|
||||
|
||||
this.block=block;
|
||||
this.mob=mob;
|
||||
this.maxinterval=interval;
|
||||
this.ammount=ammount;
|
||||
this.amount=amount;
|
||||
this.radius=radius;
|
||||
this.live=live;
|
||||
}
|
||||
@ -39,14 +41,28 @@ public class MobSpawner {
|
||||
if(player.getWorld()==world){
|
||||
if(player.getLocation().distance(this.block.getLocation())<this.radius){
|
||||
if(this.interval<=0){
|
||||
LivingEntity mob=world.spawnCreature(this.block.getLocation(), this.mob);
|
||||
if(this.live>0){
|
||||
new DMob(mob,live,GameWorld.get(world));
|
||||
|
||||
//Check normal mobs
|
||||
if(EntityType.fromName(this.mob)!=null){
|
||||
if(EntityType.fromName(this.mob).isAlive()){
|
||||
LivingEntity entity=(LivingEntity)world.spawnEntity(this.block.getLocation(), EntityType.fromName(this.mob));
|
||||
if(this.live>0){
|
||||
new DMob(entity,this.live,GameWorld.get(world));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(ammount!=-1){
|
||||
if(ammount>1){
|
||||
ammount--;
|
||||
//Check custom mobs
|
||||
DMobType mobType = DMobType.get(this.mob);
|
||||
|
||||
if(mobType!=null){
|
||||
mobType.spawn(GameWorld.get(world), this.block.getLocation());
|
||||
}
|
||||
|
||||
//Set the amount
|
||||
if(amount!=-1){
|
||||
if(amount>1){
|
||||
amount--;
|
||||
}else{
|
||||
mobspawners.remove(this);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user