Polish the hub event

This commit is contained in:
Sam 2017-05-13 17:13:47 +01:00
parent 9a96ce5018
commit d493a61d3d
2 changed files with 130 additions and 20 deletions

View File

@ -79,6 +79,11 @@ public class Schematic
}
public SchematicData paste(Location originLocation, boolean ignoreAir, boolean worldEditOffset)
{
return paste(originLocation, ignoreAir, worldEditOffset, true);
}
public SchematicData paste(Location originLocation, boolean ignoreAir, boolean worldEditOffset, boolean quickSet)
{
if(worldEditOffset && hasWorldEditOffset())
{
@ -144,9 +149,16 @@ public class Schematic
continue;
}
}
UtilBlock.setQuick(originLocation.getWorld(), startX + x, startY + y, startZ + z, materialId, _blockData[index]);
if (quickSet)
{
UtilBlock.setQuick(originLocation.getWorld(), startX + x, startY + y, startZ + z, materialId, _blockData[index]);
}
else
{
originLocation.getWorld().getBlockAt(startX + x, startY + y, startZ + z).setTypeIdAndData(materialId, _blockData[index], false);
}
BlockVector bv = new BlockVector(x,y,z);
output.getBlocksRaw().add(bv);

View File

@ -3,27 +3,29 @@ package mineplex.hub.modules;
import mineplex.core.MiniPlugin;
import mineplex.core.ReflectivelyCreateMiniPlugin;
import mineplex.core.achievement.Achievement;
import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Pair;
import mineplex.core.common.Rank;
import mineplex.core.common.block.schematic.Schematic;
import mineplex.core.common.block.schematic.SchematicData;
import mineplex.core.common.block.schematic.UtilSchematic;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.*;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.creature.Creature;
import mineplex.core.stats.StatsManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.utils.UtilVariant;
import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.BlockVector;
@ -49,32 +51,68 @@ public class AlienInvasion extends MiniPlugin
},
{
-25, 97, -26
},
{
-17, 94, -47
},
{
20, 95, -55,
},
{
45, 106, -23
},
{
50, 110, 16
},
{
-33, 125, 5
},
{
30, 102, 10
}
};
/**
* Bob Ross is not an alien
*/
private static final String[] ALIEN_SPEAK = {
"Every day is a good day when you paint",
"Beat the devil out of it",
"Happy little clouds",
"Happy little trees",
"I believe",
"I wonder if anyone can see these messages",
"Get involved",
"Ruff"
};
private static final ItemStack HELMET = new ItemStack(Material.GLASS);
private final BlockRestore _restore;
private final Creature _creature;
private final StatsManager _stats;
private final World _world;
private Schematic _schematic;
private boolean _active;
private int _lastUFOIndex;
private Location _beam;
private final Set<Block> _ufoBlocks;
private final Set<Block> _beaconBlocks;
private final Set<LivingEntity> _aliens;
public AlienInvasion()
{
super("Alien Invasion");
_restore = require(BlockRestore.class);
_creature = require(Creature.class);
_stats = require(StatsManager.class);
_world = Bukkit.getWorld("world");
_ufoBlocks = new HashSet<>(200);
_beaconBlocks = new HashSet<>();
_aliens = new HashSet<>();
addCommand(new CommandBase<AlienInvasion>(this, Rank.ADMIN, "alien-animation-start")
@ -109,11 +147,21 @@ public class AlienInvasion extends MiniPlugin
_lastUFOIndex = 0;
_active = true;
_world.setTime(18000);
for (Player player : Bukkit.getOnlinePlayers())
{
player.playSound(player.getLocation(), Sound.AMBIENCE_CAVE, 1, 0.5F);
}
UtilTextMiddle.display(C.cGreenB + "Alien Invasion", "Event is starting!", 10, 40, 10);
Bukkit.broadcastMessage(F.main("Alien", ""));
}
public void sendPlayerToInstance(Player player)
{
player.sendMessage("Testing");
player.sendMessage("Imagine you are being sent to a game server, ooooo spooky");
}
public void stopAnimation()
@ -122,7 +170,7 @@ public class AlienInvasion extends MiniPlugin
for (Block block : _ufoBlocks)
{
MapUtil.QuickChangeBlockAt(block.getLocation(), Material.AIR);
block.setType(Material.AIR);
}
_ufoBlocks.clear();
@ -133,6 +181,15 @@ public class AlienInvasion extends MiniPlugin
}
_aliens.clear();
for (Block block : _beaconBlocks)
{
_restore.restore(block);
}
_beaconBlocks.clear();
_world.setTime(6000);
}
@EventHandler
@ -144,9 +201,13 @@ public class AlienInvasion extends MiniPlugin
}
int[] cords = UFO_SPAWNS[_lastUFOIndex];
Location location = new Location(Bukkit.getWorld("world"), cords[0], cords[1], cords[2]);
Location location = new Location(_world, cords[0], cords[1], cords[2]);
SchematicData data = _schematic.paste(location, true);
location.subtract(5, 0, 5);
UtilParticle.PlayParticleToAll(ParticleType.FIREWORKS_SPARK, location, 5F, 5F, 5F, 1, 50, ViewDist.LONG);
SchematicData data = _schematic.paste(location, true, false, false);
Location beam = data.getDataLocationMap().getIronLocations(DyeColor.LIME).get(0);
for (BlockVector vector : data.getBlocks())
@ -160,7 +221,24 @@ public class AlienInvasion extends MiniPlugin
if (_lastUFOIndex == 0)
{
_beam = beam;
// Spawn a beacon
Block ground = beam.getBlock();
while (ground.getType() == Material.AIR)
{
ground = ground.getRelative(BlockFace.DOWN);
}
ground = ground.getRelative(BlockFace.UP);
_beam = ground.getLocation();
for (Pair<Location, Pair<Material, Byte>> pair : UtilBlock.getBeaconBlocks(ground.getLocation(), (byte) 5))
{
Block block = pair.getLeft().getBlock();
_restore.add(block, pair.getRight().getLeft().getId(), pair.getRight().getRight(), Long.MAX_VALUE);
_beaconBlocks.add(block);
}
}
_lastUFOIndex++;
@ -169,16 +247,21 @@ public class AlienInvasion extends MiniPlugin
@EventHandler
public void updateAlienSpawn(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST || !_active || _aliens.size() > 20)
if (event.getType() != UpdateType.FAST || !_active || _beam == null || _aliens.size() > 20)
{
return;
}
_creature.SetForce(true);
Location random = UtilAlg.getRandomLocation(_beam, 30, 5, 30);
Location random = UtilAlg.getRandomLocation(_beam.clone().add(0, 5, 0), 30, 4, 30);
random.setYaw(UtilMath.r(180));
Skeleton skeleton = UtilVariant.spawnWitherSkeleton(random);
skeleton.getEquipment().setHelmet(HELMET);
skeleton.setCustomNameVisible(true);
skeleton.setCustomName(C.cGreenB + "Alien");
UtilEnt.vegetate(skeleton);
_aliens.add(skeleton);
@ -188,14 +271,14 @@ public class AlienInvasion extends MiniPlugin
@EventHandler
public void updateSendToInstance(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC || !_active)
if (event.getType() != UpdateType.SEC || !_active || _beam == null)
{
return;
}
for (Player player : Bukkit.getOnlinePlayers())
{
if (UtilMath.offset2d(player.getLocation(), _beam) > 5)
if (UtilMath.offsetSquared(player.getLocation(), _beam) > 25)
{
continue;
}
@ -229,12 +312,27 @@ public class AlienInvasion extends MiniPlugin
Projectile projectile = (Projectile) damager;
Player shooter = (Player) projectile.getShooter();
shooter.playSound(shooter.getLocation(), Sound.NOTE_PLING, 1, 1.8F);
_stats.incrementStat(shooter, Achievement.GLOBAL_ALIEN_INVASION.getStats()[0], 1);
}
}
@EventHandler
public void interactAlien(PlayerInteractAtEntityEvent event)
{
Player player = event.getPlayer();
Entity entity = event.getRightClicked();
if (!_aliens.contains(entity))
{
return;
}
sendAlienSpeak(player);
}
private void sendAlienSpeak(Player player)
{
player.sendMessage(ALIEN_SPEAK[UtilMath.r(ALIEN_SPEAK.length)]);
player.sendMessage(C.cGreen + C.Scramble + ALIEN_SPEAK[UtilMath.r(ALIEN_SPEAK.length)]);
}
}