Staff Oscars

This commit is contained in:
Sam 2017-04-10 23:46:09 +01:00 committed by cnr
parent 26c772b8b8
commit f315689dda
4 changed files with 409 additions and 1 deletions

View File

@ -19,6 +19,7 @@ import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.games.event.kits.KitPlayer;
import nautilus.game.arcade.game.games.event.staffoscars.StaffOscarsModule;
import nautilus.game.arcade.game.modules.compass.CompassModule;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.managers.GameHostManager;
@ -126,6 +127,15 @@ public class EventGame extends Game
.register(this);
}
@Override
public void ParseData()
{
if (WorldData.MapName.equals("Staff Oscars"))
{
new StaffOscarsModule().register(this);
}
}
@EventHandler
public void registerSigns(GameStateChangeEvent event)
{

View File

@ -0,0 +1,41 @@
package nautilus.game.arcade.game.games.event.staffoscars;
import org.bukkit.block.Block;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Player;
public class ChairData
{
private Player _player;
private Block _block;
private ArmorStand _stand;
public ChairData(Player player, Block block)
{
_player = player;
_block = block;
_stand = block.getWorld().spawn(block.getLocation().add(0.5, -0.4, 0.5), ArmorStand.class);
_stand.setGravity(false);
_stand.setSmall(true);
_stand.setVisible(false);
_stand.setPassenger(player);
}
public Player getPlayer()
{
return _player;
}
public Block getBlock()
{
return _block;
}
public ArmorStand getStand()
{
return _stand;
}
}

View File

@ -0,0 +1,105 @@
package nautilus.game.arcade.game.games.event.staffoscars;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilTime;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import org.bukkit.Color;
import org.bukkit.entity.Player;
import org.bukkit.entity.Sheep;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.util.Vector;
import java.util.HashSet;
import java.util.Set;
public class RainbowSheep implements Listener
{
private static final Color[] COLOURS = {
Color.RED, Color.ORANGE, Color.YELLOW, Color.LIME, Color.AQUA, Color.BLUE, Color.PURPLE
};
private final Set<Sheep> _sheep;
private Player _player;
private boolean _active;
private long _start;
public RainbowSheep()
{
_sheep = new HashSet<>();
}
@EventHandler
public void updateSpawn(UpdateEvent event)
{
if (event.getType() != UpdateType.FASTER || !_active)
{
return;
}
if (UtilTime.elapsed(_start, 50000))
{
for (Sheep sheep : _sheep)
{
sheep.remove();
}
_sheep.clear();
_active = false;
return;
}
Vector direction = _player.getLocation().getDirection();
Vector left = UtilAlg.getLeft(direction).add(direction.clone().multiply(1.5));
Vector right = UtilAlg.getRight(direction).add(direction.clone().multiply(1.5));
spawnSheep(_player, direction);
spawnSheep(_player, left);
spawnSheep(_player, right);
}
@EventHandler
public void updateParticles(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
{
return;
}
for (Sheep sheep : _sheep)
{
UtilParticle.playColoredParticleToAll(COLOURS[UtilMath.r(COLOURS.length)], UtilParticle.ParticleType.RED_DUST, sheep.getLocation().add(0, 0.75, 0), 2, UtilParticle.ViewDist.LONGER);
}
}
@EventHandler
public void entityDamage(EntityDamageEvent event)
{
if (_sheep.contains(event.getEntity()))
{
event.setCancelled(true);
}
}
private void spawnSheep(Player player, Vector vector)
{
Sheep sheep = player.getWorld().spawn(player.getEyeLocation(), Sheep.class);
sheep.setCustomName("jeb_");
sheep.setVelocity(vector);
_sheep.add(sheep);
}
public void setActive(Player player)
{
_player = player;
_active = true;
_start = System.currentTimeMillis();
}
}

View File

@ -0,0 +1,252 @@
package nautilus.game.arcade.game.games.event.staffoscars;
import mineplex.core.common.util.*;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.modules.Module;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerArmorStandManipulateEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
public class StaffOscarsModule extends Module
{
private static final int MAX_X = 18;
private List<Location> _blocks;
private boolean _open;
private boolean _animate;
private int _x;
private Location _center;
private Set<ChairData> _chairs;
private List<Location> _fireworks;
private RainbowSheep _sheep;
@Override
protected void setup()
{
_chairs = new HashSet<>();
_blocks = getGame().WorldData.GetCustomLocs(String.valueOf(Material.EMERALD_BLOCK.getId()));
_center = UtilAlg.getAverageLocation(_blocks);
_fireworks = getGame().WorldData.GetDataLocs("YELLOW");
_sheep = new RainbowSheep();
UtilServer.RegisterEvents(_sheep);
}
@Override
public void cleanup()
{
UtilServer.Unregister(_sheep);
}
@EventHandler
public void prepare(GameStateChangeEvent event)
{
if (event.GetState() != Game.GameState.Prepare)
{
return;
}
for (Location location : _blocks)
{
MapUtil.QuickChangeBlockAt(location, Material.WOOL, (byte) 14);
}
}
@EventHandler
public void update(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST || !_animate)
{
return;
}
for (Location location : _blocks)
{
boolean in = UtilMath.offset2d(location, _center) < _x;
if (in && _open)
{
MapUtil.QuickChangeBlockAt(location, Material.AIR);
}
else if (!in && !_open)
{
MapUtil.QuickChangeBlockAt(location, Material.WOOL, (byte) 14);
}
}
if (_open)
{
_x++;
}
else
{
_x--;
}
if (_open && _x == MAX_X || !_open && _x == -1)
{
_animate = false;
}
}
@EventHandler
public void curtainCommand(PlayerCommandPreprocessEvent event)
{
String message = event.getMessage();
if (message.startsWith("/curtain") && getGame().getArcadeManager().GetGameHostManager().isAdmin(event.getPlayer(), false))
{
_open = !_open;
_animate = true;
event.setCancelled(true);
event.getPlayer().sendMessage(F.main("Event", "Curtain open state = " + _open + "."));
}
}
@EventHandler
public void chairInteract(PlayerInteractEvent event)
{
Player player = event.getPlayer();
Block block = event.getClickedBlock();
if (block == null)
{
return;
}
if (UtilBlock.usable(block))
{
event.setCancelled(true);
}
if (block.getType() != Material.WOOD_STAIRS)
{
return;
}
for (ChairData data : _chairs)
{
if (data.getBlock().equals(block))
{
return;
}
if (data.getPlayer().equals(player))
{
handleDismount(player);
break;
}
}
_chairs.add(new ChairData(player, block));
}
@EventHandler
public void playerQuit(PlayerQuitEvent event)
{
handleDismount(event.getPlayer());
}
@EventHandler
public void updateDismount(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
{
return;
}
Iterator<ChairData> iterator = _chairs.iterator();
while (iterator.hasNext())
{
ChairData data = iterator.next();
if (data.getPlayer().isInsideVehicle())
{
continue;
}
data.getStand().remove();
iterator.remove();
}
}
private void handleDismount(Player player)
{
Iterator<ChairData> iterator = _chairs.iterator();
while (iterator.hasNext())
{
ChairData data = iterator.next();
if (!data.getPlayer().equals(player))
{
continue;
}
data.getStand().remove();
iterator.remove();
}
}
@EventHandler
public void armourStandEdit(PlayerArmorStandManipulateEvent event)
{
event.setCancelled(true);
}
@EventHandler
public void fireworksCommand(PlayerCommandPreprocessEvent event)
{
String message = event.getMessage();
if (message.startsWith("/firework") && getGame().getArcadeManager().GetGameHostManager().isAdmin(event.getPlayer(), false))
{
event.setCancelled(true);
FireworkEffect fireworkEffect = FireworkEffect.builder().with(FireworkEffect.Type.BALL_LARGE).withColor(Color.YELLOW).build();
for (Location location : _fireworks)
{
for (int i = 0; i < 4; i++)
{
UtilFirework.launchFirework(location, fireworkEffect, null, UtilMath.r(3) + 1);
}
}
}
}
@EventHandler
public void rainbowSheepCommand(PlayerCommandPreprocessEvent event)
{
String message = event.getMessage();
if (!message.startsWith("/deantm") || !getGame().getArcadeManager().GetGameHostManager().isAdmin(event.getPlayer(), false))
{
return;
}
event.setCancelled(true);
_sheep.setActive(event.getPlayer());
}
}