mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-24 19:45:43 +01:00
Fixed listeners do not reload, fixed item drops do not have item meta,
fixed data leak on reload
This commit is contained in:
parent
05773281d9
commit
97a07b0128
@ -1,10 +1,12 @@
|
|||||||
package com.dre.dungeonsxl;
|
package com.dre.dungeonsxl;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import net.minecraft.server.v1_4_6.Item;
|
import net.minecraft.server.v1_4_6.Item;
|
||||||
|
|
||||||
@ -24,6 +26,7 @@ import org.bukkit.entity.Ocelot;
|
|||||||
import org.bukkit.entity.Skeleton;
|
import org.bukkit.entity.Skeleton;
|
||||||
import org.bukkit.entity.Skeleton.SkeletonType;
|
import org.bukkit.entity.Skeleton.SkeletonType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
import com.dre.dungeonsxl.game.DMob;
|
import com.dre.dungeonsxl.game.DMob;
|
||||||
import com.dre.dungeonsxl.game.GameWorld;
|
import com.dre.dungeonsxl.game.GameWorld;
|
||||||
@ -55,7 +58,6 @@ public class DMobType {
|
|||||||
|
|
||||||
this.name=name;
|
this.name=name;
|
||||||
this.type=type;
|
this.type=type;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void spawn(GameWorld gWorld, Location loc){
|
public void spawn(GameWorld gWorld, Location loc){
|
||||||
@ -140,6 +142,7 @@ public class DMobType {
|
|||||||
for(String mobName:configFile.getKeys(false)){
|
for(String mobName:configFile.getKeys(false)){
|
||||||
EntityType type=EntityType.fromName(configFile.getString(mobName+".Type"));
|
EntityType type=EntityType.fromName(configFile.getString(mobName+".Type"));
|
||||||
|
|
||||||
|
if (type!=null) {
|
||||||
DMobType mobType=new DMobType(mobName, type);
|
DMobType mobType=new DMobType(mobName, type);
|
||||||
|
|
||||||
//Load MaxHealth
|
//Load MaxHealth
|
||||||
@ -183,6 +186,7 @@ public class DMobType {
|
|||||||
Set<String> list=configSetion.getKeys(false);
|
Set<String> list=configSetion.getKeys(false);
|
||||||
for(String dropPath:list){
|
for(String dropPath:list){
|
||||||
ItemStack item = null;
|
ItemStack item = null;
|
||||||
|
ItemMeta itemMeta = null;
|
||||||
int chance = 100;
|
int chance = 100;
|
||||||
|
|
||||||
/* Item Stack */
|
/* Item Stack */
|
||||||
@ -198,27 +202,33 @@ public class DMobType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
item = new ItemStack(mat,amount,data);
|
item = new ItemStack(mat,amount,data);
|
||||||
|
itemMeta = item.getItemMeta();
|
||||||
|
|
||||||
/* Enchantments */
|
/* Enchantments */
|
||||||
if (configSetion.contains(dropPath+".enchantments")) {
|
if (configSetion.contains(dropPath+".enchantments")) {
|
||||||
for(String enchantment:configSetion.getStringList(dropPath+".enchantments")){
|
for(String enchantment:configSetion.getStringList(dropPath+".enchantments")){
|
||||||
String[] splittedEnchantment = enchantment.split(" ");
|
String[] splittedEnchantment = enchantment.split(" ");
|
||||||
|
if(Enchantment.getByName(splittedEnchantment[0].toUpperCase())!=null){
|
||||||
if (splittedEnchantment.length>1) {
|
if (splittedEnchantment.length>1) {
|
||||||
item.getItemMeta().addEnchant(Enchantment.getByName(splittedEnchantment[0]), Integer.parseInt(splittedEnchantment[1]), true);
|
itemMeta.addEnchant(Enchantment.getByName(splittedEnchantment[0].toUpperCase()), Integer.parseInt(splittedEnchantment[1]), true);
|
||||||
} else {
|
} else {
|
||||||
item.getItemMeta().addEnchant(Enchantment.getByName(splittedEnchantment[0]), 1, true);
|
itemMeta.addEnchant(Enchantment.getByName(splittedEnchantment[0].toUpperCase()), 1, true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
DungeonsXL.p.log(Level.WARNING,"Error at loading mob.yml: Enchantmet '"+splittedEnchantment[0]+"' doesn't exist!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Item Name */
|
/* Item Name */
|
||||||
if (configSetion.contains(dropPath+".name")) {
|
if (configSetion.contains(dropPath+".name")) {
|
||||||
item.getItemMeta().setDisplayName(configSetion.getString(dropPath+".name"));
|
itemMeta.setDisplayName(configSetion.getString(dropPath+".name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Item Lore */
|
/* Item Lore */
|
||||||
if (configSetion.contains(dropPath+".lore")) {
|
if (configSetion.contains(dropPath+".lore")) {
|
||||||
item.getItemMeta().setDisplayName(configSetion.getString(dropPath+".lore"));
|
String[] lore=configSetion.getString(dropPath+".lore").split("//");
|
||||||
|
itemMeta.setLore(Arrays.asList(lore));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Drop chance */
|
/* Drop chance */
|
||||||
@ -227,9 +237,13 @@ public class DMobType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Add Item to the drops map */
|
/* Add Item to the drops map */
|
||||||
|
item.setItemMeta(itemMeta);
|
||||||
mobType.drops.put(item, chance);
|
mobType.drops.put(item, chance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
DungeonsXL.p.log(Level.WARNING,"Error at loading mob.yml: Mob '"+configFile.getString(mobName+".Type")+"' doesn't exist!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ import org.bukkit.configuration.file.FileConfiguration;
|
|||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@ -92,7 +93,6 @@ public class DungeonsXL extends JavaPlugin{
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// Update Sheduler
|
// Update Sheduler
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
p.getServer().getScheduler().scheduleSyncRepeatingTask(p, new Runnable() {
|
p.getServer().getScheduler().scheduleSyncRepeatingTask(p, new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
for(GameWorld gworld:GameWorld.gworlds){
|
for(GameWorld gworld:GameWorld.gworlds){
|
||||||
@ -104,7 +104,6 @@ public class DungeonsXL extends JavaPlugin{
|
|||||||
}
|
}
|
||||||
for(EditWorld eworld:EditWorld.eworlds){
|
for(EditWorld eworld:EditWorld.eworlds){
|
||||||
if(eworld.world.getPlayers().isEmpty()){
|
if(eworld.world.getPlayers().isEmpty()){
|
||||||
|
|
||||||
eworld.delete();
|
eworld.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -169,14 +168,28 @@ public class DungeonsXL extends JavaPlugin{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Delete all Data
|
//Delete all Data
|
||||||
DPortal.portals.clear();
|
DGroup.dgroups.clear();
|
||||||
DGSign.dgsigns.clear();
|
DGSign.dgsigns.clear();
|
||||||
LeaveSign.lsigns.clear();
|
DLootInventory.LootInventorys.clear();
|
||||||
DMobType.clear();
|
DMobType.clear();
|
||||||
|
DOfflinePlayer.players.clear();
|
||||||
|
DPlayer.players.clear();
|
||||||
|
DPortal.portals.clear();
|
||||||
|
LeaveSign.lsigns.clear();
|
||||||
|
DCommandRoot.root.commands.clear();
|
||||||
|
GameCheckpoint.gcheckpoints.clear();
|
||||||
|
GameMessage.gmessages.clear();
|
||||||
|
MobSpawner.mobspawners.clear();
|
||||||
|
|
||||||
//Delete Worlds
|
//Delete Worlds
|
||||||
GameWorld.deleteAll();
|
GameWorld.deleteAll();
|
||||||
EditWorld.deleteAll();
|
EditWorld.deleteAll();
|
||||||
|
|
||||||
|
//Disable listeners
|
||||||
|
HandlerList.unregisterAll(p);
|
||||||
|
|
||||||
|
//Stop shedulers
|
||||||
|
p.getServer().getScheduler().cancelTasks(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,9 +3,6 @@ package com.dre.dungeonsxl.game;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Monster;
|
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
|
||||||
import org.bukkit.event.entity.EntityDeathEvent;
|
import org.bukkit.event.entity.EntityDeathEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
@ -24,48 +21,18 @@ public class DMob {
|
|||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
this.live = live;
|
this.live = live;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
|
||||||
|
/* Max Health */
|
||||||
|
if(live>0){
|
||||||
|
this.entity.setMaxHealth(live);
|
||||||
|
this.entity.setHealth(live);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Statics
|
//Statics
|
||||||
public static void onDamage(EntityDamageEvent 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){
|
|
||||||
dmob.live=dmob.live-event.getDamage();
|
|
||||||
dmob.entity.damage(1);
|
|
||||||
|
|
||||||
|
|
||||||
dmob.entity.setHealth(dmob.entity.getMaxHealth());
|
|
||||||
|
|
||||||
if(event instanceof EntityDamageByEntityEvent){
|
|
||||||
EntityDamageByEntityEvent eByEEvent=(EntityDamageByEntityEvent) event;
|
|
||||||
if(dmob.entity instanceof Monster && eByEEvent.getDamager() instanceof LivingEntity){
|
|
||||||
Monster mob=(Monster)dmob.entity;
|
|
||||||
mob.setTarget((LivingEntity) eByEEvent.getDamager());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(dmob.live<=0){
|
|
||||||
dmob.entity.damage(dmob.entity.getMaxHealth());
|
|
||||||
gworld.dmobs.remove(dmob);
|
|
||||||
}
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void onDeath (EntityDeathEvent event) {
|
public static void onDeath (EntityDeathEvent event) {
|
||||||
if (event.getEntity() instanceof LivingEntity) {
|
if (event.getEntity() instanceof LivingEntity) {
|
||||||
LivingEntity victim = (LivingEntity) event.getEntity();
|
LivingEntity victim = (LivingEntity) event.getEntity();
|
||||||
|
|
||||||
GameWorld gworld = GameWorld.get(victim.getWorld());
|
GameWorld gworld = GameWorld.get(victim.getWorld());
|
||||||
|
|
||||||
if (gworld!=null) {
|
if (gworld!=null) {
|
||||||
@ -74,12 +41,15 @@ public class DMob {
|
|||||||
if (dmob.type != null) {
|
if (dmob.type != null) {
|
||||||
for (ItemStack item:dmob.type.getDrops().keySet()) {
|
for (ItemStack item:dmob.type.getDrops().keySet()) {
|
||||||
Random randomGenerator = new Random();
|
Random randomGenerator = new Random();
|
||||||
int random = randomGenerator.nextInt(101);
|
int random = randomGenerator.nextInt(100);
|
||||||
if(dmob.type.getDrops().get(item)<=random){
|
|
||||||
|
if (dmob.type.getDrops().get(item)>random) {
|
||||||
event.getDrops().add(item);
|
event.getDrops().add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gworld.dmobs.remove(dmob);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,9 +61,8 @@ public class EntityListener implements Listener{
|
|||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onEntityDeath(EntityDeathEvent event){
|
public void onEntityDeath(EntityDeathEvent event){
|
||||||
World world=event.getEntity().getWorld();
|
World world=event.getEntity().getWorld();
|
||||||
//Deny all drops from mobs
|
|
||||||
if (event.getEntity() instanceof LivingEntity)
|
if (event.getEntity() instanceof LivingEntity) {
|
||||||
{
|
|
||||||
LivingEntity entity = (LivingEntity) event.getEntity();
|
LivingEntity entity = (LivingEntity) event.getEntity();
|
||||||
GameWorld gworld = GameWorld.get(world);
|
GameWorld gworld = GameWorld.get(world);
|
||||||
if(gworld!=null){
|
if(gworld!=null){
|
||||||
@ -90,9 +89,6 @@ public class EntityListener implements Listener{
|
|||||||
if (event instanceof EntityDamageByEntityEvent)
|
if (event instanceof EntityDamageByEntityEvent)
|
||||||
{
|
{
|
||||||
EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent)event;
|
EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent)event;
|
||||||
|
|
||||||
DMob.onDamage(sub);
|
|
||||||
|
|
||||||
Entity entity = sub.getDamager();
|
Entity entity = sub.getDamager();
|
||||||
Entity entity2 = sub.getEntity();
|
Entity entity2 = sub.getEntity();
|
||||||
|
|
||||||
@ -138,7 +134,6 @@ public class EntityListener implements Listener{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -159,11 +154,9 @@ public class EntityListener implements Listener{
|
|||||||
|
|
||||||
// Zombie/skeleton combustion from the sun.
|
// Zombie/skeleton combustion from the sun.
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onEntityCombust(EntityCombustEvent event)
|
public void onEntityCombust (EntityCombustEvent event) {
|
||||||
{
|
|
||||||
GameWorld gworld = GameWorld.get(event.getEntity().getWorld());
|
GameWorld gworld = GameWorld.get(event.getEntity().getWorld());
|
||||||
if(gworld != null)
|
if (gworld != null) {
|
||||||
{
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -181,9 +174,9 @@ public class EntityListener implements Listener{
|
|||||||
|
|
||||||
//Explosions
|
//Explosions
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onEntityExplode(EntityExplodeEvent event)
|
public void onEntityExplode (EntityExplodeEvent event) {
|
||||||
{
|
|
||||||
GameWorld gworld=GameWorld.get(event.getEntity().getWorld());
|
GameWorld gworld=GameWorld.get(event.getEntity().getWorld());
|
||||||
|
|
||||||
if(gworld!=null){
|
if(gworld!=null){
|
||||||
if(event.getEntity() instanceof LivingEntity){
|
if(event.getEntity() instanceof LivingEntity){
|
||||||
//Disable Creeper explosions in gameworlds
|
//Disable Creeper explosions in gameworlds
|
||||||
@ -217,6 +210,4 @@ public class EntityListener implements Listener{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user