Add compatibility to misc disguise

This commit is contained in:
libraryaddict 2013-11-24 08:43:16 +13:00
parent 4d42dca712
commit bfd2b1b329

View File

@ -1,7 +1,13 @@
package me.libraryaddict.disguise.disguisetypes; package me.libraryaddict.disguise.disguisetypes;
import me.libraryaddict.disguise.disguisetypes.watchers.DroppedItemWatcher; import java.util.Random;
import me.libraryaddict.disguise.disguisetypes.watchers.DroppedItemWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.PaintingWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SplashPotionWatcher;
import org.bukkit.Art;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -39,19 +45,37 @@ public class MiscDisguise extends Disguise {
data = -1; data = -1;
break; break;
} }
if (disguiseType == DisguiseType.FALLING_BLOCK && id != -1) { if (getType() == DisguiseType.FALLING_BLOCK && id != -1) {
this.id = id; this.id = id;
} else { } else {
this.id = disguiseType.getDefaultId(); this.id = disguiseType.getDefaultId();
} }
if (data == -1) if (data == -1) {
data = disguiseType.getDefaultData(); if (getType() == DisguiseType.PAINTING) {
data = new Random().nextInt(Art.values().length);
} else {
data = disguiseType.getDefaultData();
}
}
this.data = data; this.data = data;
createDisguise(disguiseType, replaceSounds); createDisguise(disguiseType, replaceSounds);
if (disguiseType == DisguiseType.DROPPED_ITEM) { switch (getType()) {
case DROPPED_ITEM:
if (id > 0) { if (id > 0) {
((DroppedItemWatcher) getWatcher()).setItemStack(new ItemStack(id, data)); ((DroppedItemWatcher) getWatcher()).setItemStack(new ItemStack(id, data));
} }
break;
case FALLING_BLOCK:
((FallingBlockWatcher) getWatcher()).setBlock(new ItemStack(this.id, 1, (short) this.data));
break;
case PAINTING:
((PaintingWatcher) getWatcher()).setPainting(this.data);
break;
case SPLASH_POTION:
((SplashPotionWatcher) getWatcher()).setPotionId(this.data);
break;
default:
break;
} }
} }
@ -91,11 +115,29 @@ public class MiscDisguise extends Disguise {
return disguise; return disguise;
} }
/**
* This is the getId of everything but falling block.
*/
public int getData() { public int getData() {
return data; switch (getType()) {
case FALLING_BLOCK:
return ((FallingBlockWatcher) getWatcher()).getBlock().getDurability();
case PAINTING:
return ((PaintingWatcher) getWatcher()).getPainting().getId();
case SPLASH_POTION:
return ((SplashPotionWatcher) getWatcher()).getPotionId();
default:
return data;
}
} }
/**
* Only falling block should use this
*/
public int getId() { public int getId() {
if (getType() == DisguiseType.FALLING_BLOCK) {
return ((FallingBlockWatcher) getWatcher()).getBlock().getTypeId();
}
return id; return id;
} }