Mob Gui + Ground Change Gui + UtilSkull for special mob skulls

This commit is contained in:
Shaun Bennett 2015-05-03 18:18:16 -05:00
parent c3a7dcfcf8
commit fbfb5e637e
7 changed files with 354 additions and 15 deletions

View File

@ -0,0 +1,80 @@
package mineplex.core.common.util;
import org.bukkit.entity.*;
public class UtilSkull
{
public static byte getSkullData(Entity entity)
{
if (entity instanceof Skeleton)
{
Skeleton sk = ((Skeleton) entity);
if (sk.getSkeletonType() == Skeleton.SkeletonType.WITHER)
return 1;
else return 0;
}
else if (entity instanceof Zombie || entity instanceof Giant)
{
return 2;
}
else if (entity instanceof Creeper)
{
return 4;
}
else
return 3;
}
public static boolean isPlayerHead(byte data)
{
return data == 3;
}
public static String getPlayerHeadName(Entity entity)
{
String name = "MHF_Alex";
// order is important for some of these
if (entity instanceof Blaze)
name = "MHF_Blaze";
else if (entity instanceof CaveSpider)
name = "MHF_CaveSpider";
else if (entity instanceof Chicken)
name = "MHF_Chicken";
else if (entity instanceof MushroomCow)
name = "MHF_MushroomCow";
else if (entity instanceof Cow)
name = "MHF_Cow";
else if (entity instanceof Creeper)
name = "MHF_Creeper";
else if (entity instanceof Enderman)
name = "MHF_Enderman";
else if (entity instanceof Ghast)
name = "MHF_Ghast";
else if (entity instanceof Golem)
name = "MHF_Golem";
else if (entity instanceof PigZombie)
name = "MHF_PigZombie";
else if (entity instanceof MagmaCube)
name = "MHF_LavaSlime";
else if (entity instanceof Slime)
name = "MHF_Slime";
else if (entity instanceof Ocelot)
name = "MHF_Ocelot";
else if (entity instanceof PigZombie)
name = "MHF_PigZombie";
else if (entity instanceof Pig)
name = "MHF_Pig";
else if (entity instanceof Sheep)
name = "MHF_Pig";
else if (entity instanceof Squid)
name = "MHF_Squid";
else if (entity instanceof HumanEntity)
name = "MHF_Steve";
else if (entity instanceof Villager)
name = "MHF_Villager";
return name;
}
}

View File

@ -375,6 +375,11 @@ public class Build extends SoloGame
}
}
public boolean isBuildTime()
{
return _buildStateTime == 0;
}
private void teleportPlayers(BuildData data)
{
//Teleport
@ -784,17 +789,6 @@ public class Build extends SoloGame
data.removeEntity(event.GetDamageeEntity());
}
@EventHandler
public void entKill(PlayerInteractEntityEvent event)
{
BuildData data = _data.get(event.getPlayer());
if (data == null)
return;
data.removeEntity(event.getRightClicked());
}
@EventHandler
public void vehicleSpawn(VehicleCreateEvent event)
{

View File

@ -15,6 +15,7 @@ import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilParticle.ParticleType;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.WeatherType;
import org.bukkit.block.Block;
@ -280,5 +281,18 @@ public class BuildData
(int)(Spawn.getX() + Math.random() * 200 - 100));
}
}
public void setGround(GroundData ground)
{
// TODO chiss
Material mat = ground.getMaterial();
byte data = ground.getData();
if (mat == Material.LAVA_BUCKET) mat = Material.LAVA;
else if (mat == Material.WATER_BUCKET) mat = Material.WATER;
}
}

View File

@ -0,0 +1,30 @@
package nautilus.game.arcade.game.games.build;
import org.bukkit.Material;
public class GroundData
{
public final Material _material;
public final byte _data;
public GroundData(Material material)
{
this(material, (byte) 0);
}
public GroundData(Material material, byte data)
{
_material = material;
_data = data;
}
public byte getData()
{
return _data;
}
public Material getMaterial()
{
return _material;
}
}

View File

@ -0,0 +1,81 @@
package nautilus.game.arcade.game.games.build.gui.page;
import java.util.Arrays;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.donation.DonationManager;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.shop.item.IButton;
import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.page.ShopPageBase;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.games.build.Build;
import nautilus.game.arcade.game.games.build.BuildData;
import nautilus.game.arcade.game.games.build.GroundData;
import nautilus.game.arcade.game.games.build.gui.OptionsShop;
public class GroundPage extends ShopPageBase<ArcadeManager, OptionsShop>
{
private static GroundData[] GROUNDS = {
new GroundData(Material.STONE), new GroundData(Material.GRASS), new GroundData(Material.DIRT),
new GroundData(Material.SAND), new GroundData(Material.WATER_BUCKET), new GroundData(Material.LAVA_BUCKET),
new GroundData(Material.WOOD), new GroundData(Material.COBBLESTONE), new GroundData(Material.NETHERRACK),
new GroundData(Material.SMOOTH_BRICK), new GroundData(Material.ENDER_STONE), new GroundData(Material.MYCEL),
new GroundData(Material.STAINED_CLAY, (byte) 0), new GroundData(Material.STAINED_CLAY, (byte) 15),
new GroundData(Material.STAINED_CLAY, (byte) 4), new GroundData(Material.STAINED_CLAY, (byte) 3),
new GroundData(Material.STAINED_CLAY, (byte) 5), new GroundData(Material.STAINED_CLAY, (byte) 6),
new GroundData(Material.QUARTZ_BLOCK)};
private Build _game;
public GroundPage(Build game, ArcadeManager plugin, OptionsShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
{
super(plugin, shop, clientManager, donationManager, "Change Ground", player);
_game = game;
buildPage();
}
@Override
protected void buildPage()
{
final BuildData buildData = _game.getBuildData(getPlayer());
if (buildData == null)
{
getPlayer().closeInventory();
return;
}
int index = 0;
for (final GroundData data : GROUNDS)
{
ShopItem shopItem = new ShopItem(data.getMaterial(), data.getData(), data.getMaterial().name().toLowerCase().replace('_', ' '), null, 0, false, false);
addButton(index, shopItem, new IButton()
{
@Override
public void onClick(Player player, ClickType clickType)
{
buildData.setGround(data);
}
});
index++;
}
addButton((9 * 5) + 4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]{}, 1, false), new IButton()
{
@Override
public void onClick(Player player, ClickType clickType)
{
getShop().openPageForPlayer(player, new OptionsPage(_game, getPlugin(), getShop(), getClientManager(), getDonationManager(), player));
}
});
}
}

View File

@ -1,10 +1,23 @@
package nautilus.game.arcade.game.games.build.gui.page;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftLivingEntity;
import org.bukkit.entity.Ageable;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Slime;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.meta.SkullMeta;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilSkull;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.item.IButton;
import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.page.ShopPageBase;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.games.build.BuildData;
@ -18,15 +31,133 @@ public class MobPage extends ShopPageBase<ArcadeManager, MobShop>
public MobPage(ArcadeManager plugin, MobShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player, BuildData buildData, Entity entity)
{
super(plugin, shop, clientManager, donationManager, "Mob Options", player);
super(plugin, shop, clientManager, donationManager, "Mob Options", player, 18);
_buildData = buildData;
_entity = entity;
buildPage();
}
@Override
protected void buildPage()
{
byte entityData = UtilSkull.getSkullData(_entity);
// Add Skull delete button
final String entityName = _entity.getType().getName();
ShopItem head = new ShopItem(Material.SKULL_ITEM, entityData, entityName, new String[] {C.cGray + "Right Click to Delete Entity" }, 0, false, false);
if (UtilSkull.isPlayerHead(entityData))
{
SkullMeta meta = ((SkullMeta) head.getItemMeta());
meta.setOwner(UtilSkull.getPlayerHeadName(_entity));
head.setItemMeta(meta);
}
addButton(4, head, new IButton()
{
@Override
public void onClick(Player player, ClickType clickType)
{
if (clickType == ClickType.RIGHT)
{
_buildData.removeEntity(_entity);
UtilPlayer.message(player, F.main("Game", "Entity Deleted"));
player.closeInventory();
}
}
});
int buttonSlot = 11;
if (_entity instanceof Ageable)
{
final Ageable ageable = ((Ageable) _entity);
ShopItem item = new ShopItem(Material.BLAZE_ROD, "Make " + (ageable.isAdult() ? "Baby" : "Adult"), null, 0, false, false);
addButton(buttonSlot, item, new IButton()
{
@Override
public void onClick(Player player, ClickType clickType)
{
if (ageable.isAdult())
ageable.setBaby();
else
ageable.setAdult();
UtilPlayer.message(player, F.main("Game", entityName + " is now a " + (ageable.isAdult() ? "Adult" : "Baby")));
buildPage();
}
});
buttonSlot+= 2;
}
if (_entity instanceof LivingEntity)
{
final LivingEntity livingEntity = ((LivingEntity) _entity);
final boolean ghost = ((CraftLivingEntity) livingEntity).getHandle().ghost;
ShopItem item = new ShopItem(Material.FEATHER, (ghost ? "Allow " : "Disable ") + "Pushing " + entityName, null, 0, false, false);
addButton(buttonSlot, item, new IButton()
{
@Override
public void onClick(Player player, ClickType clickType)
{
((CraftLivingEntity) livingEntity).getHandle().ghost = !ghost;
UtilPlayer.message(player, F.main("Game", "Pushing " + (ghost ? "Enabled" : "Disabled") + " for " + entityName));
buildPage();
}
});
buttonSlot += 2;
}
if (_entity instanceof Slime)
{
final Slime slime = ((Slime) _entity);
ShopItem decreaseSize = new ShopItem(Material.CLAY_BALL, "Decrease Size", null, 0, false, false);
ShopItem increaseSize = new ShopItem(Material.CLAY, "Increase Size", null, 0, false, false);
addButton(buttonSlot, decreaseSize, new IButton()
{
@Override
public void onClick(Player player, ClickType clickType)
{
if (slime.getSize() <= 1)
{
UtilPlayer.message(player, F.main("Game", "Slime is already smallest size"));
}
else
{
slime.setSize(slime.getSize() - 1);
}
}
});
buttonSlot += 2;
addButton(buttonSlot, increaseSize, new IButton()
{
@Override
public void onClick(Player player, ClickType clickType)
{
if (slime.getSize() >= 10)
{
UtilPlayer.message(player, F.main("Game", "Slime is already largest size"));
}
else
{
slime.setSize(slime.getSize() + 1);
}
}
});
}
}
}

View File

@ -28,11 +28,20 @@ public class OptionsPage extends ShopPageBase<ArcadeManager, OptionsShop>
protected void buildPage()
{
ShopItem ground = new ShopItem(Material.STAINED_CLAY, "Change Ground", 0, false);
ShopItem particles = new ShopItem(Material.NETHER_STAR, "Particles", 0, false);
ShopItem weather = new ShopItem(Material.FEATHER, "Weather", 0, false);
ShopItem time = new ShopItem(Material.WATCH, "Time of Day", 0, false);
addButton(2, particles, new IButton()
addButton(1, ground, new IButton()
{
@Override
public void onClick(Player player, ClickType clickType)
{
getShop().openPageForPlayer(player, new GroundPage(_game, getPlugin(), getShop(), getClientManager(), getDonationManager(), player));
}
});
addButton(3, particles, new IButton()
{
@Override
public void onClick(Player player, ClickType clickType)
@ -41,7 +50,7 @@ public class OptionsPage extends ShopPageBase<ArcadeManager, OptionsShop>
}
});
addButton(4, weather, new IButton()
addButton(5, weather, new IButton()
{
@Override
public void onClick(Player player, ClickType clickType)
@ -50,7 +59,7 @@ public class OptionsPage extends ShopPageBase<ArcadeManager, OptionsShop>
}
});
addButton(6, time, new IButton()
addButton(7, time, new IButton()
{
@Override
public void onClick(Player player, ClickType clickType)