Merge remote-tracking branch 'refs/remotes/origin/develop' into feature/moba

This commit is contained in:
Sam 2017-05-26 18:34:23 +01:00
commit d70cd38049
16 changed files with 1396 additions and 4 deletions

View File

@ -0,0 +1,57 @@
package mineplex.core.common.api.mothership;
import java.util.UUID;
import org.bukkit.Bukkit;
import mineplex.core.common.api.ApiHost;
import mineplex.core.common.api.ApiWebCall;
import mineplex.core.common.util.UtilServer;
public class Mothership
{
private static final ApiWebCall API_BASE = new ApiWebCall("http://" + ApiHost.getAPIHost("MOTHERSHIP").getHost() + ":" + ApiHost.getAPIHost("MOTHERSHIP").getPort() + "/");
public static void addPlayer(UUID uuid, Runnable afterward)
{
UtilServer.runAsync(() ->
{
Boolean response = API_BASE.get("addPlayer/" + uuid.toString(), Boolean.class);
if (response == null)
{
System.out.println("!!! Issue adding player to Mothership server !!!");
}
UtilServer.runSync(afterward);
});
}
public static boolean isWhitelisted(UUID uuid)
{
if (Bukkit.isPrimaryThread())
{
throw new IllegalStateException("This method MUST NOT be called from the main thread!");
}
Boolean response = API_BASE.get("getPlayer/" + uuid.toString(), Boolean.class);
if (response == null)
{
System.out.println("!!! Issue retrieving player whitelist status. Allowing them in anyway! !!!");
}
return response == null || response;
}
public static boolean shouldStartEvent()
{
if (Bukkit.isPrimaryThread())
{
throw new IllegalStateException("This method MUST NOT be called from the main thread");
}
Boolean response = API_BASE.get("startEvent/" + UtilServer.getRegion().toString() + "/" + UtilServer.getServerName(), Boolean.class);
if (response == null)
{
System.out.println("!!! Issue checking whether server should start event. Keeping event disabled! !!!");
}
return response != null && response;
}
}

View File

@ -0,0 +1,18 @@
package mineplex.core.common.api.mothership;
import mineplex.serverdata.commands.ServerCommand;
public class MothershipCommand extends ServerCommand
{
private Action action;
public Action getAction()
{
return action;
}
public enum Action
{
CLEANUP, START
}
}

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

@ -64,6 +64,13 @@ public enum Achievement
new int[]{200},
AchievementCategory.HOLIDAY),
GLOBAL_ALIEN_INVASION("2017 Alien Hub Defender", 4000,
new String[]{"Global.Alien Invasion 2017"},
new String[]{"Kill 50 Aliens in the Lobby,",
"during the Alien Invasion event"},
new int[]{300},
AchievementCategory.HOLIDAY),
//Bridges
BRIDGES_WINS("Bridge Champion", 600,
new String[]{"The Bridges.Wins"},

View File

@ -7,6 +7,7 @@ import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import mineplex.core.titles.tracks.award.AlienInvasionTrack;
import mineplex.core.titles.tracks.award.AprilFools2017Track;
import net.md_5.bungee.api.ChatColor;
@ -82,6 +83,7 @@ public class TrackManager extends MiniPlugin
// Awarded tracks
registerTrack(new Bridges2017Track());
registerTrack(new AprilFools2017Track());
registerTrack(new AlienInvasionTrack());
// Custom tracks
// registerTrack(track("lenny", "Lenny", "( ͡° ͜ʖ ͡°)"));

View File

@ -0,0 +1,30 @@
package mineplex.core.titles.tracks.award;
import mineplex.core.titles.tracks.ItemizedTrack;
import mineplex.core.titles.tracks.TrackFormat;
import mineplex.core.titles.tracks.TrackTier;
import net.md_5.bungee.api.ChatColor;
public class AlienInvasionTrack extends ItemizedTrack
{
public AlienInvasionTrack()
{
super(
"alien-invasion",
ChatColor.GREEN,
"Alien",
"Alien Invasion",
"This track is awarded to players who survived the Alien Invasion Event.",
true);
special();
getRequirements()
.addTier(new TrackTier(
"Alien Invasion",
null,
this::owns,
new TrackFormat(ChatColor.GREEN, ChatColor.DARK_GREEN)
)); }
}

View File

@ -1,5 +1,6 @@
package mineplex.hub;
import mineplex.hub.modules.AlienInvasion;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@ -247,6 +248,7 @@ public class Hub extends JavaPlugin implements IRelation
require(AprilFoolsTreasureHunt.class);
}
require(TwitchIntegrationFix.class);
require(AlienInvasion.class);
}
@Override

View File

@ -0,0 +1,395 @@
package mineplex.hub.modules;
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.EnderPearl;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Skeleton;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.BlockVector;
import mineplex.core.Managers;
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.api.mothership.Mothership;
import mineplex.core.common.api.mothership.MothershipCommand;
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.C;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilTextMiddle;
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 mineplex.hub.server.ServerManager;
import mineplex.serverdata.commands.ServerCommandManager;
@ReflectivelyCreateMiniPlugin
public class AlienInvasion extends MiniPlugin
{
private static final String SCHEMATIC_PATH = ".." + File.separator + ".." + File.separator + "update" + File.separator + "files" + File.separator + "UFO.schematic";
private static final int[][] UFO_SPAWNS = {
{
0, 81, -14
},
{
15, 91, -11
},
{
-10, 94, 5
},
{
-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",
"Hey you, I see you using the game log output. You should totally go to Moppletop's wall on enjin and say HOI"
};
private static final ItemStack HELMET = new ItemStack(Material.GLASS);
private final BlockRestore _restore;
private final Creature _creature;
private final StatsManager _stats;
private final ServerManager _serverManager;
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);
_serverManager = Managers.get(ServerManager.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")
{
@Override
public void Execute(Player caller, String[] args)
{
startAnimation();
}
});
addCommand(new CommandBase<AlienInvasion>(this, Rank.ADMIN, "alien-animation-stop")
{
@Override
public void Execute(Player caller, String[] args)
{
stopAnimation();
}
});
ServerCommandManager.getInstance().registerCommandType("mothership", MothershipCommand.class, command ->
{
switch (command.getAction())
{
case START:
if (Mothership.shouldStartEvent())
{
runSync(this::startAnimation);
}
break;
case CLEANUP:
runSync(this::stopAnimation);
break;
}
});
runAsync(() ->
{
if (Mothership.shouldStartEvent())
{
runSync(this::startAnimation);
}
});
}
public void startAnimation()
{
if (_active)
{
return;
}
try
{
_schematic = UtilSchematic.loadSchematic(new File(SCHEMATIC_PATH));
}
catch (IOException e)
{
e.printStackTrace();
return;
}
_lastUFOIndex = 0;
_active = true;
_world.setTime(18000);
for (Player player : Bukkit.getOnlinePlayers())
{
player.playSound(player.getLocation(), Sound.ENDERDRAGON_DEATH, 1, 0.5F);
}
UtilTextMiddle.display(C.cGreen + "Aliens Are Invading", "Defend the Hub!");
}
public void sendPlayerToInstance(Player player)
{
Mothership.addPlayer(player.getUniqueId(), () -> _serverManager.selectServer(player, "UFO"));
}
public void stopAnimation()
{
if (!_active)
{
return;
}
_active = false;
for (Block block : _ufoBlocks)
{
block.setType(Material.AIR);
}
_ufoBlocks.clear();
for (LivingEntity entity : _aliens)
{
entity.remove();
}
_aliens.clear();
for (Block block : _beaconBlocks)
{
_restore.restore(block);
}
_beaconBlocks.clear();
_world.setTime(6000);
}
@EventHandler
public void updateUFOSpwawn(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC || !_active || _lastUFOIndex == UFO_SPAWNS.length)
{
return;
}
int[] cords = UFO_SPAWNS[_lastUFOIndex];
Location location = new Location(_world, cords[0], cords[1], cords[2]);
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())
{
Location block = location.add(vector);
_ufoBlocks.add(block.getBlock());
location.subtract(vector);
}
if (_lastUFOIndex == 0)
{
// 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++;
}
@EventHandler
public void updateAlienSpawn(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST || !_active || _beam == null || _aliens.size() > 20)
{
return;
}
_creature.SetForce(true);
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);
_creature.SetForce(false);
}
@EventHandler
public void updateSendToInstance(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC || !_active || _beam == null)
{
return;
}
for (Player player : Bukkit.getOnlinePlayers())
{
if (UtilMath.offsetSquared(player.getLocation(), _beam) > 25)
{
continue;
}
sendPlayerToInstance(player);
}
}
@EventHandler
public void interactAlien(EntityDamageByEntityEvent event)
{
Entity entity = event.getEntity();
Entity damager = event.getDamager();
if (!_aliens.contains(entity))
{
return;
}
if (damager instanceof Player)
{
Player player = (Player) damager;
sendAlienSpeak(player);
}
else if (damager instanceof EnderPearl)
{
((LivingEntity) entity).setHealth(0);
_aliens.remove(entity);
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(C.cGreen + C.Scramble + ALIEN_SPEAK[UtilMath.r(ALIEN_SPEAK.length)]);
}
}

View File

@ -0,0 +1,101 @@
package nautilus.game.arcade.game.games.alieninvasion;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.utils.UtilVariant;
import nautilus.game.arcade.ArcadeManager;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Player;
import org.bukkit.entity.Skeleton;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
public class Alien
{
private static final int RADIUS = 3;
private static final ItemStack BLASTER = new ItemStack(Material.DIAMOND_BARDING);
private static final ItemStack HELMET = new ItemStack(Material.GLASS);
private final ArcadeManager _manager;
private ArmorStand _stand;
private Skeleton _skeleton;
private Location _center;
private double _theta;
public Alien(ArcadeManager manager, Location location)
{
_manager = manager;
_stand = location.getWorld().spawn(location, ArmorStand.class);
_skeleton = UtilVariant.spawnWitherSkeleton(location);
_center = location;
_stand.setSmall(true);
_stand.setVisible(false);
_stand.setGravity(false);
_stand.setPassenger(_skeleton);
_stand.setRemoveWhenFarAway(false);
_skeleton.setMaxHealth(4);
_skeleton.setRemoveWhenFarAway(false);
EntityEquipment equipment = _skeleton.getEquipment();
equipment.setItemInHand(BLASTER);
equipment.setHelmet(HELMET);
UtilEnt.silence(_stand, true);
UtilEnt.vegetate(_skeleton);
_theta = Math.random();
}
public void update()
{
double x = RADIUS * Math.cos(_theta);
double z = RADIUS * Math.sin(_theta);
_center.add(x, 0, z);
((CraftLivingEntity) _stand).getHandle().setPosition(_center.getX(), _center.getY(), _center.getZ());
_center.subtract(x, 0, z);
_theta += Math.PI / 30;
if (Math.random() < 0.9)
{
return;
}
Vector last = null;
for (Player player : UtilPlayer.getNearby(_skeleton.getLocation(), 20))
{
last = UtilAlg.getTrajectory(_skeleton.getEyeLocation(), player.getEyeLocation());
new PhaserProjectile(_manager, _skeleton, last);
}
if (last != null)
{
UtilEnt.CreatureLook(_skeleton, last);
}
}
public boolean isValid()
{
boolean remove = !_stand.isValid() || !_skeleton.isValid();
if (remove)
{
_stand.remove();
_skeleton.remove();
}
return !remove;
}
}

View File

@ -0,0 +1,475 @@
package nautilus.game.arcade.game.games.alieninvasion;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.ExperienceOrb;
import org.bukkit.entity.Player;
import org.bukkit.entity.Skeleton;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scoreboard.Team;
import mineplex.core.common.Pair;
import mineplex.core.common.api.mothership.Mothership;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.titles.tracks.Track;
import mineplex.core.titles.tracks.TrackManager;
import mineplex.core.titles.tracks.award.AlienInvasionTrack;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.utils.UtilVariant;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.SoloGame;
import nautilus.game.arcade.game.games.alieninvasion.kit.KitPlayer;
import nautilus.game.arcade.game.games.dragonescape.DragonScore;
import nautilus.game.arcade.game.modules.compass.CompassModule;
import nautilus.game.arcade.kit.Kit;
public class AlienInvasion extends SoloGame
{
private static final String[] DESCRIPTION = {
"You've been captured by Aliens!",
"Parkour your way to the end.",
"Use the Paintball Gun to kill Aliens.",
"Watch out for UFOs!"
};
private static final Comparator<DragonScore> SCORE_SORTER = (o1, o2) ->
{
if (o1.Score > o2.Score)
{
return 1;
}
else if (o1.Score < o2.Score)
{
return -1;
}
return 0;
};
private final List<BeamSource> _sources = new ArrayList<>();
private final List<Location> _targets = new ArrayList<>();
private final ArrayList<Location> _path = new ArrayList<>();
private int _lastBeamId;
private long _lastBeam;
private long _nextBeam;
private final List<DragonScore> _score = new ArrayList<>(16);
private final Set<Alien> _aliens = new HashSet<>();
public AlienInvasion(ArcadeManager manager)
{
super(manager, GameType.AlienInvasion, new Kit[]{new KitPlayer(manager)}, DESCRIPTION);
WorldTimeSet = 18000;
DamagePvP = false;
DamageFall = false;
HungerSet = 20;
manager.GetCreature().SetDisableCustomDrops(true);
new CompassModule()
.register(this);
}
@EventHandler
public void onJoin(AsyncPlayerPreLoginEvent event)
{
if (!Mothership.isWhitelisted(event.getUniqueId()))
{
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_WHITELIST, "You must join by finding a UFO!");
}
}
@Override
@EventHandler
public void ScoreboardUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST || !InProgress())
{
return;
}
Scoreboard.writeNewLine();
sortScores();
Scoreboard.writeGroup(_score.subList(0, Math.min(14, _score.size())), score ->
{
ChatColor col = IsAlive(score.Player) ? ChatColor.GREEN : ChatColor.RED;
return Pair.create(col + score.Player.getName(), (int) score.Score);
}, true);
Scoreboard.writeNewLine();
Scoreboard.draw();
}
@Override
public void ParseData()
{
// Setup all Beam Sources
List<Location> sources = WorldData.GetDataLocs("LIME");
for (Location location : sources)
{
_sources.add(new BeamSource(location));
}
Location start = WorldData.GetDataLocs("RED").get(0);
Location last = start;
List<Location> targets = WorldData.GetDataLocs("BLACK");
ArrayList<Location> path = new ArrayList<>();
path.addAll(targets);
path.addAll(WorldData.GetDataLocs("BROWN"));
while (!path.isEmpty())
{
Location closestPath = UtilAlg.findClosest(last, path);
if (targets.contains(closestPath))
{
_targets.add(closestPath);
}
_path.add(closestPath);
path.remove(closestPath);
last = closestPath;
}
int id = 0;
for (Location target : _targets)
{
BeamSource source = getClosestSource(target);
source.addBeam(Manager, id++, target);
}
}
private BeamSource getClosestSource(Location location)
{
BeamSource best = null;
double bestDist = Double.MAX_VALUE;
for (BeamSource source : _sources)
{
double dist = UtilMath.offsetSquared(source.getSource(), location);
if (best == null || dist < bestDist)
{
best = source;
bestDist = dist;
}
}
return best;
}
@EventHandler
public void prepare(GameStateChangeEvent event)
{
if (event.GetState() != GameState.Prepare)
{
return;
}
for (Player player : GetPlayers(true))
{
Manager.GetCondition().Factory().Invisible(GetName(), player, null, Integer.MAX_VALUE, 0, false, false, false);
_score.add(new DragonScore(player, 0));
}
for (Team team : Scoreboard.getHandle().getTeams())
{
team.setCanSeeFriendlyInvisibles(true);
}
}
@EventHandler
public void live(GameStateChangeEvent event)
{
if (event.GetState() != GameState.Live)
{
return;
}
_lastBeam = System.currentTimeMillis();
_nextBeam = 10000;
ItemStack glass = new ItemStack(Material.GLASS);
CreatureAllowOverride = true;
for (Location location : WorldData.GetDataLocs("BLUE"))
{
Skeleton skeleton = UtilVariant.spawnWitherSkeleton(location);
skeleton.setMaxHealth(4);
skeleton.getEquipment().setHelmet(glass);
}
for (Location location : WorldData.GetDataLocs("LIGHT_BLUE"))
{
_aliens.add(new Alien(Manager, location));
}
CreatureAllowOverride = false;
}
@EventHandler
public void updateAliens(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK || !IsLive())
{
return;
}
for (Alien alien : _aliens)
{
alien.update();
}
_aliens.removeIf(alien -> !alien.isValid());
}
@EventHandler
public void updateBeam(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST || !IsLive())
{
return;
}
Beam beam = getSuitableBeam();
if (beam == null)
{
return;
}
_lastBeam = System.currentTimeMillis();
_nextBeam -= 100;
_lastBeamId++;
Manager.runSyncTimer(new BukkitRunnable()
{
@Override
public void run()
{
if (beam.update())
{
for (Entry<Player, Double> entry : UtilPlayer.getInRadius(beam.getLastLocation(), 20).entrySet())
{
Manager.GetDamage().NewDamageEvent(entry.getKey(), null, null, DamageCause.CUSTOM, 20 * entry.getValue(), false, true, false, GetName(), "Photon Torpedo");
}
int killIfBefore = 0;
for (int i = 0; i < _path.size(); i++)
{
if (UtilMath.offsetSquared(beam.getLastLocation(), _path.get(i++)) < 25)
{
killIfBefore = i;
break;
}
}
for (DragonScore score : _score)
{
if (score.Score <= killIfBefore)
{
Manager.GetDamage().NewDamageEvent(score.Player, null, null, DamageCause.CUSTOM, 9999, false, true, false, GetName(), "Photon Torpedo");
}
}
cancel();
}
}
}, 0, 2);
}
private Beam getSuitableBeam()
{
if (!UtilTime.elapsed(_lastBeam, _nextBeam))
{
return null;
}
for (BeamSource beamSource : _sources)
{
Beam beam = beamSource.getFromId(_lastBeamId);
if (beam != null)
{
return beam;
}
}
return null;
}
@EventHandler
public void updatePlayerTracker(UpdateEvent event)
{
if (event.getType() != UpdateType.FASTEST || !IsLive())
{
return;
}
for (Player player : GetPlayers(true))
{
DragonScore score = getScore(player);
double currentScore = score.Score;
int newScore = 0;
Location location = UtilAlg.findClosest(player.getLocation(), _path);
if (UtilMath.offsetSquared(player.getLocation(), location) > 100)
{
break;
}
for (int i = 0; i < _path.size(); i++)
{
Location a = _path.get(i);
if (location.equals(a))
{
newScore = i;
}
}
if (newScore > currentScore)
{
score.Score = newScore;
// Reward title
if (score.Score == _path.size() - 1)
{
TrackManager trackManager = Manager.getTrackManager();
Track track = trackManager.getTrack(AlienInvasionTrack.class);
if (trackManager.hasTrack(player, track))
{
continue;
}
trackManager.unlockTrack(player, track, result ->
{
switch (result)
{
case UNKNOWN_ERROR:
player.sendMessage(F.main("Game", "Oops, somehow I could not give you the title track, you should inform a staff member!"));
break;
case SUCCESS:
player.sendMessage(F.main("Game", "Unlocked " + track.getColor() + track.getLongName() + C.mBody + " Title!"));
break;
}
});
}
}
}
}
@EventHandler
public void itemSpawn(ItemSpawnEvent event)
{
if (!IsLive())
{
return;
}
event.setCancelled(true);
}
@EventHandler
public void entitySpawn(EntitySpawnEvent event)
{
if (event.getEntity() instanceof ExperienceOrb)
{
event.setCancelled(true);
}
}
@Override
public void EndCheck()
{
if (!IsLive())
{
return;
}
List<Player> alive = GetPlayers(true);
for (DragonScore score : _score)
{
if (score.Score == _path.size() - 1 || alive.isEmpty())
{
sortScores();
List<Player> players = new ArrayList<>(_score.size());
for (DragonScore score1 : _score)
{
players.add(score1.Player);
}
Collections.reverse(players);
AnnounceEnd(players);
SetState(GameState.End);
return;
}
}
}
private void sortScores()
{
_score.sort(SCORE_SORTER);
}
private DragonScore getScore(Player player)
{
for (DragonScore score : _score)
{
if (score.Player.equals(player))
{
return score;
}
}
return null;
}
@Override
public Location GetSpectatorLocation()
{
if (SpectatorSpawn == null)
{
return new Location(WorldData.World, 0, 158, 0);
}
return SpectatorSpawn;
}
}

View File

@ -0,0 +1,65 @@
package nautilus.game.arcade.game.games.alieninvasion;
import mineplex.core.common.util.*;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.particles.effects.LineParticle;
import nautilus.game.arcade.ArcadeManager;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import java.util.Set;
public class Beam extends LineParticle
{
private static final int EXPLOSION_RADIUS = 20;
private static final int BEAM_BLOCK_TIME = 1500;
private final ArcadeManager _manager;
private final Location _target;
private final int _id;
public Beam(ArcadeManager manager, int id, BeamSource source, Location target)
{
super(source.getSource(), target, null, 1, Integer.MAX_VALUE, null, ParticleType.FIREWORKS_SPARK, UtilServer.getPlayers());
_manager = manager;
_id = id;
_target = target;
}
@Override
public boolean update()
{
super.update();
Location last = getLastLocation();
boolean hit = UtilMath.offset(last, _target) < 5;
if (hit)
{
last.getWorld().playSound(last, Sound.EXPLODE, 2f, 0.75f);
UtilParticle.PlayParticleToAll(ParticleType.HUGE_EXPLOSION, last, 4, 1, 4, 0.5F, 10, ViewDist.LONG);
Set<Block> blocks = UtilBlock.getInRadius(last, EXPLOSION_RADIUS).keySet();
//blocks.removeIf(block -> block.getRelative(BlockFace.DOWN).getType() == Material.AIR);
blocks.forEach(block -> MapUtil.QuickChangeBlockAt(block.getLocation(), Material.AIR));
}
else
{
last.getWorld().playSound(last, Sound.ZOMBIE_REMEDY, 2f, 0.75f);
_manager.GetBlockRestore().add(last.getBlock(), Material.SEA_LANTERN.getId(), (byte) 0, BEAM_BLOCK_TIME);
}
return hit;
}
public int getId()
{
return _id;
}
}

View File

@ -0,0 +1,43 @@
package nautilus.game.arcade.game.games.alieninvasion;
import nautilus.game.arcade.ArcadeManager;
import org.bukkit.Location;
import java.util.ArrayList;
import java.util.List;
public class BeamSource
{
private final Location _source;
private final List<Beam> _beams;
BeamSource(Location source)
{
_source = source;
_beams = new ArrayList<>(5);
}
public void addBeam(ArcadeManager manager, int id, Location target)
{
_beams.add(new Beam(manager, id, this, target));
}
public Location getSource()
{
return _source;
}
public Beam getFromId(int id)
{
for (Beam beam : _beams)
{
if (beam.getId() == id)
{
return beam;
}
}
return null;
}
}

View File

@ -0,0 +1,86 @@
package nautilus.game.arcade.game.games.alieninvasion;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilServer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.ArcadeManager;
import org.bukkit.Sound;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Snowball;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.util.Vector;
public class PhaserProjectile implements Listener
{
private ArcadeManager _manager;
private Projectile _projectile;
public PhaserProjectile(ArcadeManager manager, LivingEntity player)
{
this(manager, player, player.getLocation().getDirection());
}
public PhaserProjectile(ArcadeManager manager, LivingEntity player, Vector direction)
{
_manager = manager;
_projectile = player.launchProjectile(Snowball.class);
_projectile.setVelocity(direction.multiply(2));
UtilServer.RegisterEvents(this);
}
@EventHandler
public void damage(CustomDamageEvent event)
{
if (_projectile == null || event.GetProjectile() == null || !event.GetProjectile().equals(_projectile) || event.GetReason() != null && event.GetReason().contains("Blaster"))
{
return;
}
Projectile projectile = event.GetProjectile();
LivingEntity damagee = event.GetDamageeEntity();
Player damager = event.GetDamagerPlayer(true);
if (event.GetDamagerEntity(true) instanceof Player)
{
if (damagee instanceof Player)
{
projectile.remove();
return;
}
damager.playSound(damager.getLocation(), Sound.CHICKEN_EGG_POP, 1, 0.7F);
}
event.SetCancelled("Blaster Snowball");
UtilParticle.PlayParticle(ParticleType.CLOUD, projectile.getLocation(), 0.5F, 0.5F, 0.5F, 0.05F, 5, ViewDist.NORMAL);
_manager.GetDamage().NewDamageEvent(damagee, damager, projectile, DamageCause.CUSTOM, 4, false, true, true, UtilEnt.getName(damager), "Blaster");
UtilServer.Unregister(this);
}
@EventHandler
public void cleanup(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
{
return;
}
if (_projectile == null || _projectile.isDead() || !_projectile.isValid())
{
UtilServer.Unregister(this);
}
}
}

View File

@ -0,0 +1,41 @@
package nautilus.game.arcade.game.games.alieninvasion.kit;
import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemBuilder;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.PerkDoubleJump;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class KitPlayer extends Kit
{
private static final Perk[] PERKS = {
new PerkDoubleJump("Leap", 1, 1, true, 10000, true),
new PerkBlaster()
};
private static final ItemStack[] PLAYER_ITEMS = {
new ItemBuilder(Material.DIAMOND_BARDING)
.setTitle(C.cBlue + C.Scramble + "ABC " + C.cAqua + "Super Snow Blaster 3000" + C.cBlue + C.Scramble + " ABC")
.build()
};
private static final ItemStack IN_HAND = new ItemStack(Material.DIAMOND_BARDING);
public KitPlayer(ArcadeManager manager)
{
super(manager, "Player", KitAvailability.Free, new String[0], PERKS, EntityType.SKELETON, IN_HAND);
}
@Override
public void GiveItems(Player player)
{
player.getInventory().addItem(PLAYER_ITEMS);
}
}

View File

@ -0,0 +1,58 @@
package nautilus.game.arcade.game.games.alieninvasion.kit;
import mineplex.core.common.util.*;
import mineplex.core.common.util.UtilEvent.ActionType;
import mineplex.core.recharge.Recharge;
import nautilus.game.arcade.game.games.alieninvasion.PhaserProjectile;
import nautilus.game.arcade.kit.Perk;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerInteractEvent;
public class PerkBlaster extends Perk
{
public PerkBlaster()
{
super("Space Blaster", new String[0]);
}
@EventHandler
public void interact(PlayerInteractEvent event)
{
if (event.isCancelled())
{
return;
}
if (!UtilEvent.isAction(event, ActionType.R))
{
return;
}
if (UtilBlock.usable(event.getClickedBlock()))
{
return;
}
Player player = event.getPlayer();
if (event.getItem() == null || event.getItem().getType() != Material.DIAMOND_BARDING)
{
return;
}
if (!hasPerk(player))
{
return;
}
if (!Recharge.Instance.use(player, GetName(), 200, false, false))
{
return;
}
new PhaserProjectile(Manager, player);
}
}

View File

@ -29,7 +29,7 @@ public class KitJumper extends ProgressingKit
};
private static final Perk[] PERKS = {
new PerkDoubleJump("Double Jump", 1.2, 1.2, false, 6000, true),
new PerkDoubleJump("Double Jump", 1.2, 1.2, false, 3000, true),
new PerkDummy("Feathered Boots", Collections.singletonList(C.cGray + "You take no fall damage.").toArray(new String[1])),
new PerkCraftman()
};