Master Builder update

This commit is contained in:
Mini-Chiss 2015-05-02 22:05:12 -05:00
parent 5b04d43400
commit 6ad09f0ade
5 changed files with 608 additions and 96 deletions

View File

@ -12,7 +12,7 @@ public class UtilParticle
{
public enum ParticleType
{
ANGRY_VILLAGER("angryVillager", "Angry Villager", Material.SAPLING, (byte) 0),
ANGRY_VILLAGER("angryVillager", "Lightning Cloud", Material.INK_SACK, (byte) 11),
BLOCK_CRACK("blockcrack_1_0")
{
@ -34,33 +34,33 @@ public class UtilParticle
BUBBLE("bubble"),
CLOUD("cloud"),
CLOUD("cloud", "White Smoke", Material.INK_SACK, (byte) 7),
CRIT("crit"),
CRIT("crit", "Brown Magic", Material.INK_SACK, (byte) 14),
DEPTH_SUSPEND("depthSuspend"),
DRIP_LAVA("dripLava"),
DRIP_LAVA("dripLava", "Lava Drip", Material.LAVA_BUCKET, (byte) 0),
DRIP_WATER("dripWater"),
DRIP_WATER("dripWater", "Water Drop", Material.WATER_BUCKET, (byte) 0),
DROPLET("droplet"),
DROPLET("droplet", "Water Splash", Material.INK_SACK, (byte) 4),
ENCHANTMENT_TABLE("enchantmenttable"),
ENCHANTMENT_TABLE("enchantmenttable", "Enchantment Words", Material.BOOK, (byte) 0),
EXPLODE("explode"),
EXPLODE("explode", "Big White Smoke", Material.INK_SACK, (byte) 15),
FIREWORKS_SPARK("fireworksSpark"),
FIREWORKS_SPARK("fireworksSpark", "White Sparkle", Material.GHAST_TEAR, (byte) 0),
FLAME("flame"),
FLAME("flame", "Flame", Material.BLAZE_POWDER, (byte) 0),
FOOTSTEP("footstep"),
FOOTSTEP("footstep", "Foot Step", Material.LEATHER_BOOTS, (byte) 0),
HAPPY_VILLAGER("happyVillager"),
HAPPY_VILLAGER("happyVillager", "Emerald Sparkle", Material.EMERALD, (byte) 0),
HEART("heart"),
HEART("heart", "Love Heart", Material.APPLE, (byte) 0),
HUGE_EXPLOSION("hugeexplosion"),
HUGE_EXPLOSION("hugeexplosion", "Huge Explosion", Material.TNT, (byte) 0),
ICON_CRACK("iconcrack_1_0")
{
@ -73,48 +73,48 @@ public class UtilParticle
INSTANT_SPELL("instantSpell"),
LARGE_EXPLODE("largeexplode"),
LARGE_EXPLODE("largeexplode", "Explosion", Material.FIREBALL, (byte) 0),
LARGE_SMOKE("largesmoke"),
LARGE_SMOKE("largesmoke", "Black Smoke", Material.INK_SACK, (byte) 0),
LAVA("lava"),
LAVA("lava", "Lava Debris", Material.LAVA, (byte) 0),
MAGIC_CRIT("magicCrit"),
MAGIC_CRIT("magicCrit", "Teal Magic", Material.INK_SACK, (byte) 6),
/**
* Can be colored if count is 0, color is RGB and depends on the offset of xyz
*/
MOB_SPELL("mobSpell"),
MOB_SPELL("mobSpell", "Black Swirls", Material.getMaterial(2263), (byte) 0),
/**
* Can be colored if count is 0, color is RGB and depends on the offset of xyz
*/
MOB_SPELL_AMBIENT("mobSpellAmbient"),
MOB_SPELL_AMBIENT("mobSpellAmbient", "Transparent Black Swirls", Material.getMaterial(2266), (byte) 0),
NOTE("note"),
NOTE("note", "Musical Note", Material.JUKEBOX, (byte) 0),
PORTAL("portal"),
PORTAL("portal", "Portal Effect", Material.INK_SACK, (byte) 5),
/**
* Can be colored if count is 0, color is RGB and depends on the offset of xyz. Offset y if 0 will default to 1, counter by making it 0.0001
*/
RED_DUST("reddust"),
RED_DUST("reddust", "Red Smoke", Material.INK_SACK, (byte) 1),
SLIME("slime"),
SLIME("slime", "Slime Particles", Material.SLIME_BALL, (byte) 0),
SNOW_SHOVEL("snowshovel"),
SNOW_SHOVEL("snowshovel", "Snow Puffs", Material.SNOW_BALL, (byte) 0),
SNOWBALL_POOF("snowballpoof"),
SPELL("spell"),
SPELL("spell", "White Swirls", Material.getMaterial(2264), (byte) 0),
SPLASH("splash"),
SUSPEND("suspended"),
TOWN_AURA("townaura"),
TOWN_AURA("townaura", "Black Specks", Material.COAL, (byte) 0),
WITCH_MAGIC("witchMagic");
WITCH_MAGIC("witchMagic", "Purple Magic", Material.INK_SACK, (byte) 13);
public String particleName;
private boolean _friendlyData;
@ -130,6 +130,7 @@ public class UtilParticle
ParticleType(String particleName, String friendlyName, Material material, byte data)
{
this.particleName = particleName;
_friendlyData = true;
_friendlyName = friendlyName;
_material = material;
@ -148,6 +149,11 @@ public class UtilParticle
public String getFriendlyName()
{
if (_friendlyName == null)
{
return toString();
}
return _friendlyName;
}

View File

@ -8,27 +8,48 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Boat;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Painting;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.entity.ThrownPotion;
import org.bukkit.entity.minecart.CommandMinecart;
import org.bukkit.entity.minecart.ExplosiveMinecart;
import org.bukkit.entity.minecart.HopperMinecart;
import org.bukkit.entity.minecart.PoweredMinecart;
import org.bukkit.entity.minecart.RideableMinecart;
import org.bukkit.entity.minecart.SpawnerMinecart;
import org.bukkit.entity.minecart.StorageMinecart;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.entity.ItemDespawnEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.vehicle.VehicleCreateEvent;
import org.bukkit.event.vehicle.VehicleDamageEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
@ -46,10 +67,12 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.explosion.ExplosionEvent;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
@ -100,16 +123,18 @@ public class Build extends SoloGame
this.BlockBreak = true;
this.BlockPlace = true;
this.ItemDrop = true;
this.ItemPickup = true;
this.InventoryClick = true;
this.WorldTimeSet = 6000;
this.PrepareFreeze = false;
this.CreatureAllow = true;
_words = new String[]
{
"Pirate Ship", "Mineshaft", "Archers Tower", "Dinner Table", "Pokemon"
@ -124,6 +149,7 @@ public class Build extends SoloGame
{
event.GetPlayer().setGameMode(GameMode.CREATIVE);
event.GetPlayer().setFlying(true);
event.GetPlayer().setFlySpeed(0.04f);
}
@EventHandler
@ -146,10 +172,12 @@ public class Build extends SoloGame
Location spawn = UtilAlg.findClosest(player.getLocation(), this.GetTeamList().get(0).GetSpawns());
_data.put(player, new BuildData(player, spawn, WorldData.GetDataLocs("YELLOW")));
player.setFlySpeed(0.1f);
}
_word = _words[UtilMath.r(_words.length)];
UtilTextMiddle.display(null, C.cYellow + "Build " + C.cWhite + _word, 0, 80, 5);
}
}
@ -170,13 +198,13 @@ public class Build extends SoloGame
{
_buildGameState++;
_buildStateTime = System.currentTimeMillis();
//Flags
this.BlockBreak = false;
this.BlockPlace = false;
this.InventoryClick = false;
UtilTextMiddle.display(null, C.cYellow + "Time Up!", 0, 60, 5);
for (Player player : GetPlayers(true))
@ -201,33 +229,33 @@ public class Build extends SoloGame
{
for (Player player : GetPlayers(true))
UtilInv.Clear(player);
//Verdict
if (!_viewData.Judged)
{
BuildQuality quality = getQuality(_viewData.getScore());
BuildQuality quality = BuildQuality.getQuality(_viewData.getScore());
if (quality == BuildQuality.Failure)
{
Manager.GetExplosion().BlockExplosion(_viewData.Blocks, _viewData.Spawn, false);
//Effects
_viewData.Spawn.getWorld().playSound(_viewData.Spawn, Sound.EXPLODE, 3f, 1f);
UtilParticle.PlayParticle(ParticleType.HUGE_EXPLOSION, _viewData.Spawn, 4f, 4f, 4f, 0, 10);
}
//Announce Builder
UtilTextMiddle.display(quality.getText(), "Built by: " + C.Bold + _viewData.Player.getName(), 0, 80, 5);
}
_viewData.Judged = true;
}
//Start Vote
if (UtilTime.elapsed(_buildStateTime, _viewTime) || _viewData == null)
{
_viewData = null;
//Get Next View Data
for (BuildData data : _data.values())
{
@ -237,7 +265,7 @@ public class Build extends SoloGame
break;
}
}
//All Builds are Viewed
if (_viewData == null)
{
@ -252,7 +280,7 @@ public class Build extends SoloGame
else
{
teleportPlayers(_viewData);
//Give Items
for (Player player : GetPlayers(true))
{
@ -265,10 +293,10 @@ public class Build extends SoloGame
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(160, (byte)3, 1, C.Bold + "+4 " + C.cAqua + C.Bold + "Amazing"));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(160, (byte)10, 1, C.Bold + "+5 " + C.cPurple + C.Bold + "WOW! EVERYTHING IS AWESOME!"));
}
//Text
UtilTextMiddle.display(null, C.cYellow + "Cast Your Vote!", 0, 60, 5);
_buildStateTime = System.currentTimeMillis();
}
}
@ -306,19 +334,19 @@ public class Build extends SoloGame
AddGems(bestPlayer, bestScore, "Build Votes", false, false);
BuildData data = _data.remove(bestPlayer);
//Teleport to winner
if (first)
{
teleportPlayers(data);
first = false;
}
//Only count if they got above TERRIBLE score
if (getQuality(bestScore) != BuildQuality.Failure)
if (BuildQuality.getQuality(bestScore) != BuildQuality.Failure)
places.add(bestPlayer);
}
@ -346,14 +374,14 @@ public class Build extends SoloGame
private void teleportPlayers(BuildData data)
{
//Teleport
//Teleport
for (int i=0 ; i<UtilServer.getPlayers().length ; i++)
{
double lead = i * ((2d * Math.PI)/UtilServer.getPlayers().length);
double oX = -Math.sin(lead) * 26;
double oZ = Math.cos(lead) * 26;
Location loc = data.Spawn.clone().add(oX, 0, oZ);
loc.setDirection(UtilAlg.getTrajectory(loc, data.Spawn));
@ -361,14 +389,11 @@ public class Build extends SoloGame
UtilServer.getPlayers()[i].eject();
UtilServer.getPlayers()[i].leaveVehicle();
UtilServer.getPlayers()[i].teleport(loc);
UtilServer.getPlayers()[i].setFlying(true);
}
}
private BuildQuality getQuality(double score)
{
return BuildQuality.getQuality(score / (double)(GetPlayers(true).size()-1));
}
public BuildData getBuildData(Player player)
{
return _data.get(player);
@ -405,7 +430,7 @@ public class Build extends SoloGame
if (!inBuildArea(data, event.getBlock()))
event.setCancelled(true);
}
@EventHandler
public void bucketEmpty(PlayerBucketEmptyEvent event)
{
@ -414,7 +439,7 @@ public class Build extends SoloGame
event.setCancelled(true);
return;
}
BuildData data = _data.get(event.getPlayer());
if (data == null)
@ -435,7 +460,8 @@ public class Build extends SoloGame
if (data == null)
return;
if (event.getTo().getY() > Math.max(data.CornerA.getBlockY(), data.CornerB.getBlockY()) + 3)
if (event.getTo().getY() > Math.max(data.CornerA.getBlockY(), data.CornerB.getBlockY()) + 3 &&
UtilMath.offset(data.Spawn, event.getFrom()) < UtilMath.offset(data.Spawn, event.getTo()))
{
//Inform
if (Recharge.Instance.use(event.getPlayer(), "Boundary Check", 1000, false, false))
@ -468,28 +494,28 @@ public class Build extends SoloGame
if (_buildGameState != 2)
return;
if (_viewData == null)
return;
if (!IsAlive(event.getPlayer()))
return;
if (!UtilGear.isMat(event.getPlayer().getItemInHand(), Material.STAINED_GLASS_PANE))
return;
if (!UtilEvent.isAction(event, ActionType.R) && !UtilEvent.isAction(event, ActionType.L))
return;
if (event.getPlayer().equals(_viewData.Player))
{
UtilPlayer.message(event.getPlayer(), F.main("Game", "You cannot vote on your own creation!"));
return;
}
if (!UtilTime.elapsed(_buildStateTime, 1500))
return;
switch (event.getPlayer().getItemInHand().getData().getData())
{
case 14:
@ -520,18 +546,18 @@ public class Build extends SoloGame
break;
}
}
@EventHandler
public void playerQuit(PlayerQuitEvent event)
{
_data.remove(event.getPlayer());
for (BuildData data : _data.values())
data.removeScore(event.getPlayer());
}
@EventHandler
public void clean(UpdateEvent event)
public void cleanTNT(UpdateEvent event)
{
if (!InProgress())
return;
@ -541,40 +567,38 @@ public class Build extends SoloGame
for (Entity ent : this.WorldData.World.getEntities())
{
if (ent instanceof TNTPrimed ||
ent instanceof ExplosiveMinecart ||
ent instanceof Item)
if (ent instanceof TNTPrimed)
{
ent.remove();
}
}
}
@EventHandler
public void potionThrow(ProjectileLaunchEvent event)
{
if (event.getEntity() instanceof ThrownPotion)
event.getEntity().remove();
}
@EventHandler
public void bowShoot(EntityShootBowEvent event)
{
event.getProjectile().remove();
}
@EventHandler
public void blockFromTo(BlockFromToEvent event)
{
for (BuildData data : _data.values())
if (data.inBuildArea(event.getToBlock()))
return;
event.setCancelled(true);
}
@EventHandler
public void blockFromTo(BlockPistonExtendEvent event)
public void pistonExtend(BlockPistonExtendEvent event)
{
for (BuildData data : _data.values())
for (Block block : event.getBlocks())
@ -584,9 +608,9 @@ public class Build extends SoloGame
return;
}
}
@EventHandler
public void blockFromTo(BlockPistonRetractEvent event)
public void pistonRetract(BlockPistonRetractEvent event)
{
for (BuildData data : _data.values())
if (!data.inBuildArea(event.getBlock()))
@ -595,6 +619,255 @@ public class Build extends SoloGame
return;
}
}
@EventHandler
public void entityCombust(EntityCombustEvent event)
{
event.setCancelled(true);
}
@EventHandler
public void itemClean(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
return;
for (BuildData data : _data.values())
{
data.clean();
}
for (Entity ent : this.WorldData.World.getEntities())
{
if (!(ent instanceof Item))
continue;
boolean isPlacedItem = false;
for (BuildData data : _data.values())
{
if (data.Items.contains(ent))
{
isPlacedItem = true;
break;
}
}
if (!isPlacedItem)
ent.remove();
}
}
@EventHandler
public void itemDrop(PlayerDropItemEvent event)
{
BuildData data = _data.get(event.getPlayer());
if (data == null)
{
event.setCancelled(true);
return;
}
data.addItem(event.getItemDrop());
}
@EventHandler
public void itemPickup(PlayerPickupItemEvent event)
{
event.setCancelled(true);
BuildData data = _data.get(event.getPlayer());
if (data == null)
return;
if (data.Player.equals(event.getPlayer()))
{
event.getItem().remove();
UtilParticle.PlayParticle(ParticleType.LARGE_EXPLODE, event.getItem().getLocation().add(0, 0.5, 0), 0, 0, 0, 0, 1);
}
}
@EventHandler
public void itemExpire(ItemDespawnEvent event)
{
for (BuildData data : _data.values())
{
if (data.Items.contains(event.getEntity()))
{
event.setCancelled(true);
return;
}
}
}
@EventHandler
public void dataClean(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
return;
for (BuildData data : _data.values())
{
data.clean();
}
}
@EventHandler
public void entSpawn(CreatureSpawnEvent event)
{
if (event.getSpawnReason() != SpawnReason.SPAWNER_EGG)
{
event.setCancelled(true);
return;
}
Player bestPlayer = null;
double bestDist = 0;
for (Player player : GetPlayers(true))
{
double dist = UtilMath.offset(event.getLocation(), player.getLocation());
if (bestPlayer == null || dist < bestDist)
{
bestPlayer = player;
bestDist = dist;
}
}
if (bestPlayer == null)
{
event.setCancelled(true);
return;
}
BuildData data = _data.get(bestPlayer);
if (data == null)
{
event.setCancelled(true);
return;
}
//Not in area
if (!inBuildArea(data, event.getLocation().getBlock()))
{
event.setCancelled(true);
}
//Maxed
else if (!data.addEntity(event.getEntity()))
{
event.setCancelled(true);
}
}
@EventHandler
public void entKill(CustomDamageEvent event)
{
if (event.GetDamagerPlayer(false) == null)
return;
BuildData data = _data.get(event.GetDamagerPlayer(false));
if (data == null)
return;
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)
{
if (event.getVehicle() instanceof Boat ||
event.getVehicle() instanceof Minecart ||
event.getVehicle() instanceof ExplosiveMinecart ||
event.getVehicle() instanceof HopperMinecart ||
event.getVehicle() instanceof CommandMinecart ||
event.getVehicle() instanceof StorageMinecart ||
event.getVehicle() instanceof SpawnerMinecart ||
event.getVehicle() instanceof PoweredMinecart ||
event.getVehicle() instanceof RideableMinecart ||
event.getVehicle() instanceof Painting ||
event.getVehicle() instanceof ItemFrame)
{
Player bestPlayer = null;
double bestDist = 0;
for (Player player : GetPlayers(true))
{
double dist = UtilMath.offset(event.getVehicle().getLocation(), player.getLocation());
if (bestPlayer == null || dist < bestDist)
{
bestPlayer = player;
bestDist = dist;
}
}
if (bestPlayer == null)
{
event.getVehicle().remove();
return;
}
BuildData data = _data.get(bestPlayer);
if (data == null)
{
event.getVehicle().remove();
return;
}
//Not in area
if (!inBuildArea(data, event.getVehicle().getLocation().getBlock()))
{
event.getVehicle().remove();
}
//Maxed
else if (!data.addEntity(event.getVehicle()))
{
event.getVehicle().remove();
}
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void vehicleDamage(VehicleDamageEvent event)
{
if (_buildGameState != 0 || event.getAttacker() == null || !(event.getAttacker() instanceof Player))
{
event.setCancelled(true);
return;
}
Player player = (Player)event.getAttacker();
BuildData data = _data.get(player);
if (data == null)
{
event.setCancelled(true);
return;
}
data.removeEntity(event.getVehicle());
}
@Override
@EventHandler
@ -625,13 +898,23 @@ public class Build extends SoloGame
{
Scoreboard.Write(C.cYellow + C.Bold + "Vote Time");
Scoreboard.Write(UtilTime.MakeStr(Math.max(0, _voteTime - (System.currentTimeMillis() - _buildStateTime)), 1));
if (_viewData != null)
{
Scoreboard.WriteBlank();
Scoreboard.Write(C.cYellow + C.Bold + "Votes Cast");
Scoreboard.Write(C.cYellow + C.Bold + "Debug Voted");
Scoreboard.Write(_viewData.Score.size() + " / " + (GetPlayers(true).size()-1));
Scoreboard.WriteBlank();
Scoreboard.Write(C.cYellow + C.Bold + "Debug Avg");
Scoreboard.Write(UtilMath.trim(2, _viewData.getScore()) + "");
Scoreboard.WriteBlank();
Scoreboard.Write(C.cYellow + C.Bold + "Debug Rating");
Scoreboard.Write(BuildQuality.getQuality(_viewData.getScore()) + "");
}
}
@ -639,6 +922,13 @@ public class Build extends SoloGame
Scoreboard.Draw();
}
@EventHandler
public void disableInteraction(PlayerInteractEvent event)
{
if (_buildGameState != 0 && IsLive())
event.setCancelled(true);
}
@EventHandler
public void openShop(PlayerInteractEvent event)
{
@ -659,7 +949,8 @@ public class Build extends SoloGame
@EventHandler
public void giveItem(UpdateEvent event)
{
if (event.getType() != UpdateType.TWOSEC) return;
if (event.getType() != UpdateType.FAST)
return;
if (IsLive() && _buildGameState == 0)
for (Player player : GetPlayers(true))
@ -683,18 +974,25 @@ public class Build extends SoloGame
@EventHandler
public void placeParticles(PlayerInteractEvent event)
{
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK)
return;
ItemStack itemInHand = event.getPlayer().getItemInHand();
if (itemInHand != null && itemInHand.getItemMeta().getDisplayName().startsWith(ChatColor.GREEN + "Place "))
if (itemInHand != null &&
itemInHand.getItemMeta() != null &&
itemInHand.getItemMeta().getDisplayName() != null &&
itemInHand.getItemMeta().getDisplayName().startsWith(ChatColor.GREEN + "Place "))
{
ParticleType particleType = ParticleType.getFromFriendlyName(itemInHand.getItemMeta().getDisplayName().substring(8));
if (particleType != null)
{
BuildData data = _data.get(event.getPlayer());
if (data != null)
{
data.Particles.put(event.getPlayer().getLocation(), particleType);
data.addParticles(particleType);
}
event.setCancelled(true);
@ -705,4 +1003,54 @@ public class Build extends SoloGame
}
}
}
@EventHandler
public void playParticles(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
return;
if (_viewData != null)
{
_viewData.playParticles(true);
}
else
{
for (BuildData data : _data.values())
{
data.playParticles(false);
}
}
}
@EventHandler
public void setWeather(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
return;
if (_viewData != null)
{
_viewData.playWeather(true);
}
else
{
for (BuildData data : _data.values())
{
data.playWeather(false);
}
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void explode(ExplosionEvent event)
{
event.GetBlocks().clear();
}
@EventHandler(priority = EventPriority.LOWEST)
public void explode(EntityExplodeEvent event)
{
event.blockList().clear();
}
}

View File

@ -2,19 +2,25 @@ package nautilus.game.arcade.game.games.build;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilParticle.ParticleType;
import org.bukkit.Location;
import org.bukkit.WeatherType;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Ghast;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.ItemMeta;
public class BuildData
{
@ -31,6 +37,8 @@ public class BuildData
public HashSet<Entity> Entities = new HashSet<Entity>();
public HashSet<Entity> Items = new HashSet<Entity>();
public NautHashMap<Location, ParticleType> Particles = new NautHashMap<Location, ParticleType>();
public int Time = 6000;
@ -50,6 +58,79 @@ public class BuildData
buildBorders.remove(CornerB);
}
public boolean addItem(Item item)
{
if (Items.size() >= 16)
{
UtilPlayer.message(Player, F.main("Game", "You cannot drop more than 16 Items!"));
item.remove();
return false;
}
Items.add(item);
ItemMeta meta = item.getItemStack().getItemMeta();
meta.setDisplayName(item.getUniqueId() + " NoStack");
item.getItemStack().setItemMeta(meta);
return true;
}
public boolean addParticles(ParticleType particleType)
{
if (Particles.size() >= 24)
{
UtilPlayer.message(Player, F.main("Game", "You cannot spawn more than 24 Particles!"));
return false;
}
Particles.put(Player.getEyeLocation().add(Player.getLocation().getDirection()), particleType);
UtilPlayer.message(Player, F.main("Game", "You placed " + particleType.getFriendlyName() + "!"));
return true;
}
public void resetParticles()
{
Particles.clear();
UtilPlayer.message(Player, F.main("Game", "You cleared your Particles!"));
}
public boolean addEntity(Entity entity)
{
if (entity instanceof Ghast)
{
UtilPlayer.message(Player, F.main("Game", "You cannot spawn Ghasts!"));
entity.remove();
return false;
}
if (Entities.size() >= 16)
{
UtilPlayer.message(Player, F.main("Game", "You cannot spawn more than 16 Entities!"));
entity.remove();
return false;
}
Entities.add(entity);
UtilEnt.Vegetate(entity, true);
UtilEnt.ghost(entity, true, false);
return true;
}
public void removeEntity(Entity entity)
{
if (Entities.remove(entity))
{
entity.remove();
UtilParticle.PlayParticle(ParticleType.LARGE_EXPLODE, entity.getLocation().add(0, 0.5, 0), 0, 0, 0, 0, 1);
}
}
public void addBlock(Block block)
{
Blocks.add(block);
@ -67,6 +148,9 @@ public class BuildData
public double getScore()
{
if (Score.isEmpty())
return -1;
double score = 0;
for (int i : Score.values())
@ -102,4 +186,75 @@ public class BuildData
{
SUNNY, RAINING, STORMING;
}
public void clean()
{
//Clean Ents
Iterator<Entity> entIter = Entities.iterator();
while (entIter.hasNext())
{
Entity ent = entIter.next();
if (!ent.isValid() || !inBuildArea(ent.getLocation().getBlock()))
{
entIter.remove();
ent.remove();
UtilParticle.PlayParticle(ParticleType.LARGE_EXPLODE, ent.getLocation().add(0, 0.5, 0), 0, 0, 0, 0, 1);
}
}
//Clean Items
Iterator<Entity> itemIter = Items.iterator();
while (itemIter.hasNext())
{
Entity ent = itemIter.next();
if (!ent.isValid() || !inBuildArea(ent.getLocation().getBlock()))
{
itemIter.remove();
ent.remove();
UtilParticle.PlayParticle(ParticleType.LARGE_EXPLODE, ent.getLocation().add(0, 0.5, 0), 0, 0, 0, 0, 1);
}
}
}
public void playParticles(boolean all)
{
for (Location loc : Particles.keySet())
{
int amount = 8;
ParticleType type = Particles.get(loc);
if (type == ParticleType.HUGE_EXPLOSION ||
type == ParticleType.LARGE_EXPLODE ||
type == ParticleType.NOTE)
amount = 1;
if (all)
UtilParticle.PlayParticle(type, loc, 0.4f, 0.4f, 0.4f, 0, amount);
else
UtilParticle.PlayParticle(Player, type, loc, 0.4f, 0.4f, 0.4f, 0, amount);
}
}
public void playWeather(boolean b)
{
org.bukkit.WeatherType type = org.bukkit.WeatherType.CLEAR;
if (Weather == WeatherType.STORMING || Weather == WeatherType.RAINING)
type = org.bukkit.WeatherType.DOWNFALL;
if (b)
{
for (Player player : UtilServer.getPlayers())
player.setPlayerWeather(type);
}
else
{
Player.setPlayerWeather(type);
}
}
}

View File

@ -4,6 +4,8 @@ import mineplex.core.common.util.C;
public enum BuildQuality
{
NoVotes(C.cGray + "No Votes"),
Mindblowing(C.cAqua + "Mindblowing"),
Amazing(C.cGreen + "Amazing"),
Good(C.cYellow + "Good"),
@ -22,12 +24,13 @@ public enum BuildQuality
return _text;
}
public static BuildQuality getQuality(double score)
public static BuildQuality getQuality(double avgScore)
{
if (score <= 0.25) return Failure;
if (score <= 0.50) return Satisfactory;
if (score <= 0.70) return Good;
if (score <= 0.95) return Amazing;
if (avgScore < 0) return NoVotes;
if (avgScore <= 1) return Failure;
if (avgScore <= 2) return Satisfactory;
if (avgScore <= 3) return Good;
if (avgScore <= 4) return Amazing;
return Mindblowing;
}
}

View File

@ -48,7 +48,7 @@ public class ParticlesPage extends ShopPageBase<ArcadeManager, OptionsShop>
{
if (particleType.hasFriendlyData())
{
ShopItem shopItem = new ShopItem(particleType.getMaterial(), particleType.getFriendlyName(), null, 0, false);
ShopItem shopItem = new ShopItem(particleType.getMaterial(), particleType.getData(), particleType.getFriendlyName(), null, 0, false, false);
addButton(index, shopItem, new IButton()
{
@Override
@ -70,7 +70,7 @@ public class ParticlesPage extends ShopPageBase<ArcadeManager, OptionsShop>
@Override
public void onClick(Player player, ClickType clickType)
{
buildData.Particles.clear();
buildData.resetParticles();
}
});