Finish up new generators

This commit is contained in:
Sam 2018-01-07 17:42:32 +00:00 committed by Alexander Meech
parent 0934239e0c
commit 54a605de5b
10 changed files with 489 additions and 195 deletions

View File

@ -14,7 +14,6 @@ import java.util.Random;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -482,7 +481,7 @@ public class UtilPlayer
public static List<Player> getNearby(Location loc, double maxDist, boolean onlySurvival) public static List<Player> getNearby(Location loc, double maxDist, boolean onlySurvival)
{ {
maxDist *= maxDist; maxDist *= maxDist;
LinkedList<Player> nearbyMap = new LinkedList<Player>(); LinkedList<Player> nearbyMap = new LinkedList<>();
for (Player cur : loc.getWorld().getPlayers()) for (Player cur : loc.getWorld().getPlayers())
{ {

View File

@ -4,11 +4,13 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.concurrent.TimeUnit;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
@ -20,50 +22,32 @@ import org.bukkit.entity.Egg;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Snowball; import org.bukkit.entity.Snowball;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.entity.Zombie; import org.bukkit.entity.Zombie;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent; import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockFadeEvent; import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockSpreadEvent; import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.LeavesDecayEvent; import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.entity.ItemDespawnEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.MapUtil; import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.explosion.ExplosionEvent; import mineplex.core.explosion.ExplosionEvent;
import mineplex.core.loot.ChestLoot; import mineplex.core.loot.ChestLoot;
import mineplex.core.loot.RandomItem; import mineplex.core.loot.RandomItem;
import mineplex.core.recharge.Recharge; import mineplex.core.recharge.Recharge;
import mineplex.core.titles.tracks.standard.LuckyTrack; import mineplex.core.titles.tracks.standard.LuckyTrack;
import mineplex.core.titles.tracks.standard.UnluckyTrack; import mineplex.core.titles.tracks.standard.UnluckyTrack;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.combat.CombatComponent;
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent; import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.ArcadeManager;
@ -80,9 +64,14 @@ import nautilus.game.arcade.game.games.skywars.kits.KitIce;
import nautilus.game.arcade.game.games.skywars.kits.KitMetal; import nautilus.game.arcade.game.games.skywars.kits.KitMetal;
import nautilus.game.arcade.game.games.skywars.modes.kits.KitElementalist; import nautilus.game.arcade.game.games.skywars.modes.kits.KitElementalist;
import nautilus.game.arcade.game.games.skywars.module.ZombieGuardianModule; import nautilus.game.arcade.game.games.skywars.module.ZombieGuardianModule;
import nautilus.game.arcade.game.modules.EXPForKillsModule;
import nautilus.game.arcade.game.modules.EnderPearlModule; import nautilus.game.arcade.game.modules.EnderPearlModule;
import nautilus.game.arcade.game.modules.MapCrumbleModule; import nautilus.game.arcade.game.modules.MapCrumbleModule;
import nautilus.game.arcade.game.modules.ThrowableTNTModule;
import nautilus.game.arcade.game.modules.compass.CompassModule; import nautilus.game.arcade.game.modules.compass.CompassModule;
import nautilus.game.arcade.game.modules.generator.Generator;
import nautilus.game.arcade.game.modules.generator.GeneratorModule;
import nautilus.game.arcade.game.modules.generator.GeneratorType;
import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.ore.OreHider; import nautilus.game.arcade.ore.OreHider;
@ -162,10 +151,6 @@ public abstract class Skywars extends Game
HideTeamSheep = true; HideTeamSheep = true;
new CompassModule()
.setGiveCompassToAlive(true)
.register(this);
GameTimeout = 1500000L; GameTimeout = 1500000L;
DeathDropItems = true; DeathDropItems = true;
@ -205,9 +190,16 @@ public abstract class Skywars extends Game
}; };
new CompassModule()
.setGiveCompassToAlive(true)
.register(this);
new EnderPearlModule() new EnderPearlModule()
.register(this); .register(this);
new EXPForKillsModule()
.register(this);
setAlreadyAnnounced(false); setAlreadyAnnounced(false);
setupBookEnchantments(); setupBookEnchantments();
setupPlayerLoot(); setupPlayerLoot();
@ -218,7 +210,6 @@ public abstract class Skywars extends Game
@Override @Override
public void ParseData() public void ParseData()
{ {
parseCreateZombieSpawns();
parseCreateMiddleChests(); parseCreateMiddleChests();
parseCreateConnectorChests(); parseCreateConnectorChests();
parseCreatePlayerChests(); parseCreatePlayerChests();
@ -232,6 +223,22 @@ public abstract class Skywars extends Game
.addSpawns(WorldData.GetDataLocs("RED")) .addSpawns(WorldData.GetDataLocs("RED"))
.register(this); .register(this);
ThrowableTNTModule tntModule = new ThrowableTNTModule()
.setThrowAndDrop(true)
.setThrowStrength(1.4);
tntModule.register(this);
ItemStack tntItem = tntModule.getTntItem().clone();
tntItem.setAmount(2);
new GeneratorModule()
.addGenerator(new Generator
(
new GeneratorType(tntItem, TimeUnit.SECONDS.toMillis(30), "Throwable TNT", ChatColor.RED, Color.RED, true),
WorldData.GetDataLocs("LIME").get(0)
))
.register(this);
for (Location oreLoc : WorldData.GetCustomLocs("56")) for (Location oreLoc : WorldData.GetCustomLocs("56"))
{ {
oreLoc.getBlock().setType(Material.STONE); oreLoc.getBlock().setType(Material.STONE);
@ -243,11 +250,11 @@ public abstract class Skywars extends Game
MapUtil.QuickChangeBlockAt(loc, Material.AIR); MapUtil.QuickChangeBlockAt(loc, Material.AIR);
} }
// TNT // // TNT
for (Location loc : WorldData.GetDataLocs("LIME")) // for (Location loc : WorldData.GetDataLocs("LIME"))
{ // {
_tntGen = new TNTGenerator(this, loc); // _tntGen = new TNTGenerator(this, loc);
} // }
// // Register Blocks // // Register Blocks
// for (int y = WorldData.MinY; y < WorldData.MaxY; y++) // for (int y = WorldData.MinY; y < WorldData.MaxY; y++)
@ -520,66 +527,6 @@ public abstract class Skywars extends Game
} }
} }
@EventHandler
public void onPlayerPickupItem(PlayerPickupItemEvent e)
{
ItemStack is = e.getItem().getItemStack();
Player player = e.getPlayer();
if (is.getType() == Material.TNT)
{
e.setCancelled(true);
_tntGen.pickup(player, e.getItem());
}
}
@EventHandler
public void onPlayerInteractTNT(PlayerInteractEvent e)
{
if (!IsLive())
{
return;
}
Player player = e.getPlayer();
if (!IsAlive(player))
{
return;
}
if (!UtilInv.IsItem(player.getItemInHand(), Material.TNT, (byte) 0))
{
return;
}
e.setCancelled(true);
UtilInv.remove(player, Material.TNT, (byte) 0, 1);
UtilInv.Update(player);
TNTPrimed tnt = (TNTPrimed) player.getWorld().spawn(player.getEyeLocation().add(player.getLocation().getDirection()), TNTPrimed.class);
tnt.setFuseTicks(60);
if (UtilEvent.isAction(e, UtilEvent.ActionType.L))
{
UtilAction.velocity(tnt, player.getLocation().getDirection(), 1.75D, false, 0.0D, 0.1D, 10.0D, false);
player.playSound(player.getLocation(), Sound.GHAST_FIREBALL, 3.0F, 1.0F);
}
_tntMap.put(tnt, player);
}
@EventHandler
public void onUpdateTNTCannon(UpdateEvent e)
{
if (!IsLive())
return;
if (e.getType() == UpdateType.FAST)
{
_tntGen.update();
}
}
@EventHandler @EventHandler
public void onBlockBurn(BlockBurnEvent event) public void onBlockBurn(BlockBurnEvent event)
{ {
@ -608,23 +555,14 @@ public abstract class Skywars extends Game
public void onBlockPlaceAdd(BlockPlaceEvent event) public void onBlockPlaceAdd(BlockPlaceEvent event)
{ {
Material material = event.getBlock().getType(); Material material = event.getBlock().getType();
_worldBlocks.add(event.getBlock());
if (material == Material.CHEST || material == Material.PISTON_BASE || material == Material.PISTON_STICKY_BASE || material == Material.HOPPER) if (material == Material.CHEST || material == Material.PISTON_BASE || material == Material.PISTON_STICKY_BASE || material == Material.HOPPER)
{ {
event.getPlayer().sendMessage(F.main("Game", "You cannot place this block."));
event.setCancelled(true); event.setCancelled(true);
} }
} }
@EventHandler
public void onBlockPhysics(BlockPhysicsEvent event)
{
if (IsLive() && event.getBlock().getWorld().equals(WorldData.World))
{
_worldBlocks.add(event.getBlock());
}
}
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onBlockBreakBonusDrops(BlockBreakEvent event) public void onBlockBreakBonusDrops(BlockBreakEvent event)
{ {
@ -1103,80 +1041,15 @@ public abstract class Skywars extends Game
public void onExplosion(ExplosionEvent event) public void onExplosion(ExplosionEvent event)
{ {
_oreHider.Explosion(event); _oreHider.Explosion(event);
event.GetBlocks().removeIf(block -> block.getType() == Material.CHEST || block.getType() == Material.ANVIL); event.GetBlocks().removeIf(block -> block.getType() == Material.CHEST || block.getType() == Material.ANVIL);
} }
@EventHandler
public void onEntityChangeBlock(EntityChangeBlockEvent event)
{
if (event.getBlock().getType() == Material.ANVIL)
{
event.setCancelled(true);
}
}
@EventHandler @EventHandler
public void onBlockBreakOreReveal(BlockBreakEvent event) public void onBlockBreakOreReveal(BlockBreakEvent event)
{ {
_oreHider.BlockBreak(event); _oreHider.BlockBreak(event);
} }
@EventHandler
public void onExplosionPrime(ExplosionPrimeEvent event)
{
Player player = _tntMap.get(event.getEntity());
if (player != null)
{
for (Player other : UtilPlayer.getNearby(event.getEntity().getLocation(), 14))
{
Manager.GetCondition().Factory().Explosion("Throwing TNT", other, player, 50, 0.1, false, false);
}
}
}
@EventHandler
public void onCombatDeathEventLevels(CombatDeathEvent event)
{
Game game = Manager.GetGame();
if (game == null)
return;
if (!(event.GetEvent().getEntity() instanceof Player))
return;
Player killed = (Player) event.GetEvent().getEntity();
if (event.GetLog().GetKiller() != null)
{
Player killer = UtilPlayer.searchExact(event.GetLog().GetKiller().GetName());
if (killer != null && !killer.equals(killed))
{
// Kill
killer.giveExpLevels(2);
killer.playSound(killer.getLocation(), Sound.LEVEL_UP, 1f, 1f);
}
}
for (CombatComponent log : event.GetLog().GetAttackers())
{
if (event.GetLog().GetKiller() != null && log.equals(event.GetLog().GetKiller()))
continue;
Player assist = UtilPlayer.searchExact(log.GetName());
// Assist
if (assist != null)
{
assist.giveExpLevels(1);
assist.playSound(assist.getLocation(), Sound.ORB_PICKUP, 1f, 1f);
}
}
}
@Override @Override
public double GetKillsGems(Player killer, Player killed, boolean assist) public double GetKillsGems(Player killer, Player killed, boolean assist)
{ {

View File

@ -118,29 +118,29 @@ public class SoloSkywars extends Skywars
} }
} }
if (IsLive()) // if (IsLive())
{ // {
Scoreboard.writeNewLine(); // Scoreboard.writeNewLine();
Scoreboard.write(C.cYellow + C.Bold + "Time"); // Scoreboard.write(C.cYellow + C.Bold + "Time");
Scoreboard.write(UtilTime.convertString(System.currentTimeMillis() - GetStateTime(), 0, TimeUnit.FIT)); // Scoreboard.write(UtilTime.convertString(System.currentTimeMillis() - GetStateTime(), 0, TimeUnit.FIT));
//
Scoreboard.writeNewLine(); // Scoreboard.writeNewLine();
Scoreboard.write((this.getTnTGen().active() ? C.cGreen : C.cRed) + C.Bold + "TNT Spawn"); // Scoreboard.write((this.getTnTGen().active() ? C.cGreen : C.cRed) + C.Bold + "TNT Spawn");
Scoreboard.write(this.getTnTGen().getScoreboardInfo()); // Scoreboard.write(this.getTnTGen().getScoreboardInfo());
//
Scoreboard.writeNewLine(); // Scoreboard.writeNewLine();
//
if (UtilTime.elapsed(GetStateTime(), this.getCrumbleTime())) // if (UtilTime.elapsed(GetStateTime(), this.getCrumbleTime()))
{ // {
Scoreboard.write(C.cRed + C.Bold + "Map Crumble"); // Scoreboard.write(C.cRed + C.Bold + "Map Crumble");
Scoreboard.write("Active"); // Scoreboard.write("Active");
} // }
else // else
{ // {
Scoreboard.write(C.cGreen + C.Bold + "Map Crumble"); // Scoreboard.write(C.cGreen + C.Bold + "Map Crumble");
Scoreboard.write(UtilTime.convertString(this.getCrumbleTime() - (System.currentTimeMillis() - GetStateTime()), 0, TimeUnit.FIT)); // Scoreboard.write(UtilTime.convertString(this.getCrumbleTime() - (System.currentTimeMillis() - GetStateTime()), 0, TimeUnit.FIT));
} // }
} // }

View File

@ -46,6 +46,13 @@ public class ZombieGuardianModule extends Module
_zombies = new HashMap<>(); _zombies = new HashMap<>();
} }
@Override
public void cleanup()
{
_zombies.clear();
_spawns.clear();
}
public ZombieGuardianModule addSpawns(List<Location> spawns) public ZombieGuardianModule addSpawns(List<Location> spawns)
{ {
_spawns.addAll(spawns); _spawns.addAll(spawns);

View File

@ -0,0 +1,69 @@
package nautilus.game.arcade.game.modules;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.common.util.UtilPlayer;
import mineplex.minecraft.game.core.combat.CombatComponent;
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
/**
* A legacy module that awards players enchanting levels when they kill or assist on killing another player.
*/
public class EXPForKillsModule extends Module
{
private final int _levelsForKill, _levelsForAssist;
public EXPForKillsModule()
{
this(2, 1);
}
public EXPForKillsModule(int levelsForKill, int levelsForAssist)
{
_levelsForKill = levelsForKill;
_levelsForAssist = levelsForAssist;
}
@EventHandler
public void onCombatDeathEventLevels(CombatDeathEvent event)
{
if (!(event.GetEvent().getEntity() instanceof Player))
{
return;
}
Player killed = (Player) event.GetEvent().getEntity();
if (event.GetLog().GetKiller() != null)
{
Player killer = UtilPlayer.searchExact(event.GetLog().GetKiller().GetName());
if (killer != null && !killer.equals(killed))
{
// Kill
killer.giveExpLevels(_levelsForKill);
killer.playSound(killer.getLocation(), Sound.LEVEL_UP, 1f, 1f);
}
}
for (CombatComponent log : event.GetLog().GetAttackers())
{
if (event.GetLog().GetKiller() != null && log.equals(event.GetLog().GetKiller()))
{
continue;
}
Player assist = UtilPlayer.searchExact(log.GetName());
// Assist
if (assist != null)
{
assist.giveExpLevels(_levelsForAssist);
assist.playSound(assist.getLocation(), Sound.ORB_PICKUP, 1f, 1f);
}
}
}
}

View File

@ -74,6 +74,12 @@ public class MapCrumbleModule extends Module
}, 1, 2); }, 1, 2);
} }
@Override
public void cleanup()
{
_worldBlocks.clear();
}
public MapCrumbleModule setEnabled(boolean enabled) public MapCrumbleModule setEnabled(boolean enabled)
{ {
_enabled = enabled; _enabled = enabled;

View File

@ -0,0 +1,100 @@
package nautilus.game.arcade.game.modules;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilEvent.ActionType;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.itemstack.ItemBuilder;
public class ThrowableTNTModule extends Module
{
private ItemStack _tntItem;
private int _fuseTicks = 60;
private boolean _throwAndDrop;
private double _throwStrength = 1.3;
@Override
protected void setup()
{
ItemBuilder builder = new ItemBuilder(Material.TNT);
if (_throwAndDrop)
{
builder.setTitle(C.cYellowB + "Left Click - Throw" + C.cWhite + " / " + C.cYellowB + " Right Click - Drop");
}
else
{
builder.setTitle(C.cYellowB + "Throwable TNT");
}
_tntItem = builder.build();
}
public ThrowableTNTModule setFuseTicks(int fuseTicks)
{
_fuseTicks = fuseTicks;
return this;
}
public ThrowableTNTModule setThrowAndDrop(boolean throwAndDrop)
{
_throwAndDrop = throwAndDrop;
return this;
}
public ThrowableTNTModule setThrowStrength(double throwStrength)
{
_throwStrength = throwStrength;
return this;
}
public ItemStack getTntItem()
{
return _tntItem;
}
@EventHandler
public void playerThrowTNT(PlayerInteractEvent event)
{
if (event.getAction() == Action.PHYSICAL || !getGame().IsLive())
{
return;
}
Player player = event.getPlayer();
ItemStack itemStack = player.getItemInHand();
if (UtilPlayer.isSpectator(player) || itemStack == null || itemStack.getType() != Material.TNT)
{
return;
}
player.setItemInHand(UtilInv.decrement(itemStack));
event.setCancelled(true);
Location location = player.getEyeLocation();
location.add(location.getDirection());
TNTPrimed tntPrimed = location.getWorld().spawn(location, TNTPrimed.class);
tntPrimed.setFuseTicks(_fuseTicks);
if (!_throwAndDrop || UtilEvent.isAction(event, ActionType.L))
{
UtilAction.velocity(tntPrimed, location.getDirection(), _throwStrength, false, 0, 0.3, 1, false);
player.playEffect(location, Effect.GHAST_SHOOT, 0);
}
}
}

View File

@ -1,5 +1,114 @@
package nautilus.game.arcade.game.modules.generator; package nautilus.game.arcade.game.modules.generator;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Player;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime;
public class Generator public class Generator
{ {
private static final int COLLECT_RADIUS = 2;
private static final float ROTATION_DELTA_YAW = 10;
private final GeneratorType _type;
private final Location _location;
private final Block _block;
private ArmorStand _holder;
private long _lastCollect;
private boolean _colourTick = true;
public Generator(GeneratorType type, Location location)
{
_type = type;
_location = location.clone().subtract(0, 0.5, 0);
_block = location.getBlock().getRelative(BlockFace.DOWN);
}
public void checkCollect()
{
if (_holder == null)
{
return;
}
List<Player> nearby = UtilPlayer.getNearby(_location, COLLECT_RADIUS);
if (nearby.isEmpty())
{
return;
}
Player player = nearby.get(0);
_type.collect(this, player);
_holder.remove();
_holder = null;
_lastCollect = System.currentTimeMillis();
}
public void checkSpawn()
{
if (_holder != null || !UtilTime.elapsed(_lastCollect, _type.getSpawnRate()))
{
return;
}
_holder = _type.spawnHolder(this);
}
public void animateHolder()
{
if (_holder == null)
{
return;
}
Location location = _holder.getLocation();
((CraftEntity) _holder).getHandle().setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw() + ROTATION_DELTA_YAW, location.getPitch());
}
public void updateName()
{
if (_holder == null)
{
return;
}
if (!_holder.isCustomNameVisible())
{
_holder.setCustomNameVisible(true);
}
if (_type.isFlashName())
{
_colourTick = !_colourTick;
}
_holder.setCustomName((_colourTick ? _type.getColour() + C.Bold : C.cWhiteB) + _type.getName());
}
public ArmorStand getHolder()
{
return _holder;
}
public Location getLocation()
{
return _location;
}
public Block getBlock()
{
return _block;
}
} }

View File

@ -1,12 +1,92 @@
package nautilus.game.arcade.game.modules.generator; package nautilus.game.arcade.game.modules.generator;
import org.bukkit.Location; import java.util.HashSet;
import org.bukkit.entity.ArmorStand; import java.util.Set;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerArmorStandManipulateEvent;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.game.modules.Module; import nautilus.game.arcade.game.modules.Module;
public class GeneratorModule extends Module public class GeneratorModule extends Module
{ {
private final Set<Generator> _generators;
public GeneratorModule()
{
_generators = new HashSet<>();
}
@Override
public void cleanup()
{
_generators.clear();
}
public GeneratorModule addGenerator(Generator generator)
{
_generators.add(generator);
return this;
}
@EventHandler
public void update(UpdateEvent event)
{
if (!getGame().IsLive())
{
return;
}
if (event.getType() == UpdateType.FAST)
{
getGame().CreatureAllowOverride = true;
for (Generator generator : _generators)
{
generator.checkSpawn();
generator.checkCollect();
generator.updateName();
}
getGame().CreatureAllowOverride = false;
}
else if (event.getType() == UpdateType.TICK)
{
for (Generator generator : _generators)
{
generator.animateHolder();
}
}
}
@EventHandler
public void armourStandManipulate(PlayerArmorStandManipulateEvent event)
{
for (Generator generator: _generators)
{
if (generator.getHolder().equals(event.getRightClicked()))
{
event.setCancelled(true);
return;
}
}
}
@EventHandler
public void armourStandDamage(CustomDamageEvent event)
{
for (Generator generator: _generators)
{
if (generator.getHolder().equals(event.GetDamageeEntity()))
{
event.SetCancelled("Generator Holder");
return;
}
}
}
} }

View File

@ -5,22 +5,30 @@ import org.bukkit.Color;
import org.bukkit.FireworkEffect; import org.bukkit.FireworkEffect;
import org.bukkit.FireworkEffect.Type; import org.bukkit.FireworkEffect.Type;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilFirework; import mineplex.core.common.util.UtilFirework;
public class GeneratorType public class GeneratorType
{ {
private final ItemStack _itemStack; private final ItemStack _itemStack;
private final long _spawnRate;
private final String _name;
private final ChatColor _colour; private final ChatColor _colour;
private final boolean _flashName; private final boolean _flashName;
private final FireworkEffect _effect; private final FireworkEffect _effect;
public GeneratorType(ItemStack itemStack, ChatColor chatColour, Color bukkitColour, boolean flashName) public GeneratorType(ItemStack itemStack, long spawnRate, String name, ChatColor chatColour, Color bukkitColour, boolean flashName)
{ {
_itemStack = itemStack; _itemStack = itemStack;
_spawnRate = spawnRate;
_name = name;
_colour = chatColour; _colour = chatColour;
_flashName = flashName; _flashName = flashName;
_effect = FireworkEffect.builder() _effect = FireworkEffect.builder()
@ -29,10 +37,34 @@ public class GeneratorType
.build(); .build();
} }
final void collect(Generator generator) final void collect(Generator generator, Player player)
{ {
Location location = playEffect(generator);
UtilFirework.playFirework(ge, _effect); MapUtil.QuickChangeBlockAt(generator.getBlock().getLocation(), Material.IRON_BLOCK);
collect(player);
}
final ArmorStand spawnHolder(Generator generator)
{
Location location = generator.getLocation();
ArmorStand holder = location.getWorld().spawn(location, ArmorStand.class);
holder.setGravity(false);
holder.setVisible(false);
holder.setHelmet(_itemStack);
holder.setRemoveWhenFarAway(false);
UtilEnt.setTickWhenFarAway(holder, true);
playEffect(generator);
MapUtil.QuickChangeBlockAt(generator.getBlock().getLocation(), Material.GOLD_BLOCK);
return holder;
}
private void playEffect(Generator generator)
{
Location location = generator.getLocation();
UtilFirework.playFirework(location, _effect);
} }
public void collect(Player player) public void collect(Player player)
@ -40,4 +72,23 @@ public class GeneratorType
player.getInventory().addItem(_itemStack); player.getInventory().addItem(_itemStack);
} }
public String getName()
{
return _name;
}
public long getSpawnRate()
{
return _spawnRate;
}
public ChatColor getColour()
{
return _colour;
}
public boolean isFlashName()
{
return _flashName;
}
} }