mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-24 19:45:43 +01:00
Added ability to customize the mob-drops
This commit is contained in:
parent
0cc7d3fa2b
commit
05773281d9
@ -10,12 +10,14 @@ import net.minecraft.server.v1_4_6.Item;
|
|||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPigZombie;
|
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPigZombie;
|
||||||
import org.bukkit.craftbukkit.v1_4_6.entity.CraftSkeleton;
|
import org.bukkit.craftbukkit.v1_4_6.entity.CraftSkeleton;
|
||||||
import org.bukkit.craftbukkit.v1_4_6.entity.CraftZombie;
|
import org.bukkit.craftbukkit.v1_4_6.entity.CraftZombie;
|
||||||
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftItemStack;
|
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftItemStack;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Ocelot;
|
import org.bukkit.entity.Ocelot;
|
||||||
@ -41,6 +43,7 @@ public class DMobType {
|
|||||||
private Item ItemBoots;
|
private Item ItemBoots;
|
||||||
|
|
||||||
private Map<ItemStack, Integer> drops = new HashMap<ItemStack, Integer>();
|
private Map<ItemStack, Integer> drops = new HashMap<ItemStack, Integer>();
|
||||||
|
public Map<ItemStack, Integer> getDrops() { return this.drops; }
|
||||||
|
|
||||||
/* Extra Values for different Mob Types */
|
/* Extra Values for different Mob Types */
|
||||||
private boolean isWitherSkeleton = false;
|
private boolean isWitherSkeleton = false;
|
||||||
@ -123,7 +126,7 @@ public class DMobType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Spawn Mob */
|
/* Spawn Mob */
|
||||||
new DMob(entity, maxHealth, gWorld);
|
new DMob(entity, maxHealth, gWorld, this);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,13 +136,8 @@ public class DMobType {
|
|||||||
public static void load(File file){
|
public static void load(File file){
|
||||||
FileConfiguration configFile = YamlConfiguration.loadConfiguration(file);
|
FileConfiguration configFile = YamlConfiguration.loadConfiguration(file);
|
||||||
|
|
||||||
DungeonsXL.p.log(configFile.getKeys(true));
|
|
||||||
|
|
||||||
//Read Mobs
|
//Read Mobs
|
||||||
for(String mobName:configFile.getKeys(true)){
|
for(String mobName:configFile.getKeys(false)){
|
||||||
if(!mobName.contains(".")){
|
|
||||||
DungeonsXL.p.log("Test"+mobName);
|
|
||||||
|
|
||||||
EntityType type=EntityType.fromName(configFile.getString(mobName+".Type"));
|
EntityType type=EntityType.fromName(configFile.getString(mobName+".Type"));
|
||||||
|
|
||||||
DMobType mobType=new DMobType(mobName, type);
|
DMobType mobType=new DMobType(mobName, type);
|
||||||
@ -180,19 +178,67 @@ public class DMobType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Drops
|
//Drops
|
||||||
Set<String> list=configFile.getKeys(true);
|
ConfigurationSection configSetion = configFile.getConfigurationSection(mobName+".drops");
|
||||||
|
if(configSetion!=null){
|
||||||
|
Set<String> list=configSetion.getKeys(false);
|
||||||
for(String dropPath:list){
|
for(String dropPath:list){
|
||||||
if(dropPath.contains(mobName+"drops.")){
|
ItemStack item = null;
|
||||||
//TODO Add Drops funtionality
|
int chance = 100;
|
||||||
|
|
||||||
|
/* Item Stack */
|
||||||
|
Material mat = Material.getMaterial(configSetion.getInt(dropPath+".id"));
|
||||||
|
int amount = 1;
|
||||||
|
short data = 0;
|
||||||
|
|
||||||
|
if(configSetion.contains(dropPath+".amount")){
|
||||||
|
amount = configSetion.getInt(dropPath+".amount");
|
||||||
|
}
|
||||||
|
if(configSetion.contains(dropPath+".data")){
|
||||||
|
data = Short.parseShort(configSetion.getString(dropPath+".data"));
|
||||||
|
}
|
||||||
|
|
||||||
|
item = new ItemStack(mat,amount,data);
|
||||||
|
|
||||||
|
/* Enchantments */
|
||||||
|
if (configSetion.contains(dropPath+".enchantments")) {
|
||||||
|
for(String enchantment:configSetion.getStringList(dropPath+".enchantments")){
|
||||||
|
String[] splittedEnchantment = enchantment.split(" ");
|
||||||
|
if (splittedEnchantment.length>1) {
|
||||||
|
item.getItemMeta().addEnchant(Enchantment.getByName(splittedEnchantment[0]), Integer.parseInt(splittedEnchantment[1]), true);
|
||||||
|
} else {
|
||||||
|
item.getItemMeta().addEnchant(Enchantment.getByName(splittedEnchantment[0]), 1, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Item Name */
|
||||||
|
if (configSetion.contains(dropPath+".name")) {
|
||||||
|
item.getItemMeta().setDisplayName(configSetion.getString(dropPath+".name"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Item Lore */
|
||||||
|
if (configSetion.contains(dropPath+".lore")) {
|
||||||
|
item.getItemMeta().setDisplayName(configSetion.getString(dropPath+".lore"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Drop chance */
|
||||||
|
if (configSetion.contains(dropPath+".chance")) {
|
||||||
|
chance = configSetion.getInt(dropPath+".chance");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add Item to the drops map */
|
||||||
|
mobType.drops.put(item, chance);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Clear
|
||||||
|
public static void clear(){
|
||||||
|
mobTypes.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Get
|
//Get
|
||||||
public static DMobType get(String name){
|
public static DMobType get(String name){
|
||||||
for(DMobType mobType:DMobType.mobTypes){
|
for(DMobType mobType:DMobType.mobTypes){
|
||||||
|
@ -172,6 +172,7 @@ public class DungeonsXL extends JavaPlugin{
|
|||||||
DPortal.portals.clear();
|
DPortal.portals.clear();
|
||||||
DGSign.dgsigns.clear();
|
DGSign.dgsigns.clear();
|
||||||
LeaveSign.lsigns.clear();
|
LeaveSign.lsigns.clear();
|
||||||
|
DMobType.clear();
|
||||||
|
|
||||||
//Delete Worlds
|
//Delete Worlds
|
||||||
GameWorld.deleteAll();
|
GameWorld.deleteAll();
|
||||||
|
@ -1,21 +1,29 @@
|
|||||||
package com.dre.dungeonsxl.game;
|
package com.dre.dungeonsxl.game;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Monster;
|
import org.bukkit.entity.Monster;
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDeathEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import com.dre.dungeonsxl.DMobType;
|
||||||
|
|
||||||
public class DMob {
|
public class DMob {
|
||||||
|
|
||||||
//Variables
|
//Variables
|
||||||
public LivingEntity entity;
|
public LivingEntity entity;
|
||||||
|
public DMobType type;
|
||||||
public int live;
|
public int live;
|
||||||
|
|
||||||
public DMob(LivingEntity entity, int live, GameWorld gworld){
|
public DMob(LivingEntity entity, int live, GameWorld gworld, DMobType type){
|
||||||
gworld.dmobs.add(this);
|
gworld.dmobs.add(this);
|
||||||
|
|
||||||
this.entity=entity;
|
this.entity=entity;
|
||||||
this.live=live;
|
this.live=live;
|
||||||
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Statics
|
//Statics
|
||||||
@ -53,4 +61,29 @@ public class DMob {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void onDeath(EntityDeathEvent event){
|
||||||
|
if(event.getEntity() instanceof LivingEntity){
|
||||||
|
LivingEntity victim=(LivingEntity) event.getEntity();
|
||||||
|
|
||||||
|
GameWorld gworld=GameWorld.get(victim.getWorld());
|
||||||
|
|
||||||
|
if(gworld!=null){
|
||||||
|
for(DMob dmob:gworld.dmobs){
|
||||||
|
if(dmob.entity==victim){
|
||||||
|
if(dmob.type!=null){
|
||||||
|
for(ItemStack item:dmob.type.getDrops().keySet()){
|
||||||
|
Random randomGenerator = new Random();
|
||||||
|
int random = randomGenerator.nextInt(101);
|
||||||
|
if(dmob.type.getDrops().get(item)<=random){
|
||||||
|
event.getDrops().add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ public class MobSpawner {
|
|||||||
if(EntityType.fromName(this.mob).isAlive()){
|
if(EntityType.fromName(this.mob).isAlive()){
|
||||||
LivingEntity entity=(LivingEntity)world.spawnEntity(this.block.getLocation(), EntityType.fromName(this.mob));
|
LivingEntity entity=(LivingEntity)world.spawnEntity(this.block.getLocation(), EntityType.fromName(this.mob));
|
||||||
if(this.live>0){
|
if(this.live>0){
|
||||||
new DMob(entity,this.live,GameWorld.get(world));
|
new DMob(entity,this.live,GameWorld.get(world),null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,7 @@ public class EntityListener implements Listener{
|
|||||||
if(gworld.isPlaying){
|
if(gworld.isPlaying){
|
||||||
if(entity.getType()!=EntityType.PLAYER){
|
if(entity.getType()!=EntityType.PLAYER){
|
||||||
event.getDrops().clear();
|
event.getDrops().clear();
|
||||||
|
DMob.onDeath(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user