Leaderboards and UFO world event

This commit is contained in:
Sam 2017-06-06 19:28:41 +01:00
parent 4a91d2821b
commit a63399943d
12 changed files with 265 additions and 147 deletions

View File

@ -216,7 +216,7 @@ public enum AchievementCategory
Material.DIAMOND_BOOTS, 0, GameCategory.SURVIVAL, null, false, GameDisplay.Skyfall.getGameId(), GameDisplay.SkyfallTeams.getGameId()),
GEM_HUNTERS("Gem Hunters", null,
new StatDisplay[] {StatDisplay.KILLS, StatDisplay.GEMS_EARNED, StatDisplay.fromGame("Quests Complete", GameDisplay.GemHunters, "QuestsCompleted"), StatDisplay.fromGame("Chests Opened", GameDisplay.GemHunters, "ChestsOpened")},
new StatDisplay[] {StatDisplay.KILLS, StatDisplay.GEMS_EARNED, StatDisplay.fromGame("Quests Completed", GameDisplay.GemHunters, "QuestsCompleted"), StatDisplay.fromGame("Chests Opened", GameDisplay.GemHunters, "ChestsOpened")},
Material.EMERALD, 0, GameCategory.SURVIVAL, null, false, GameDisplay.GemHunters.getGameId());
private String _name;

View File

@ -10,7 +10,7 @@ public class GemHuntersTrack extends Track
public GemHuntersTrack()
{
super("gem-hunters-gems", "Gem Hunter Millionaire", "This track is unlocked by earning gems in Gem Hunters");
super("gem-hunters-gems", "GH Millionaire", "This track is unlocked by earning gems in Gem Hunters");
getRequirements()
.addTier(new TrackTier(

View File

@ -1,4 +1,3 @@
<<<<<<< HEAD
package nautilus.game.arcade.game.games.castleassault.data;
import org.bukkit.Location;
@ -126,128 +125,4 @@ public class TeamKing
return true;
}
}
=======
package nautilus.game.arcade.game.games.castleassault.data;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Zombie;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilTime;
import mineplex.core.itemstack.ItemBuilder;
import nautilus.game.arcade.game.GameTeam;
public class TeamKing
{
private static final int MAX_HEALTH = 600;
private Location _loc;
private String _name;
private GameTeam _owner;
private Zombie _entity;
private int _health;
private String _lastDamager;
private long _lastDamage;
public TeamKing(GameTeam owner, String name, Location loc)
{
_owner = owner;
_loc = loc;
_name = name;
_health = MAX_HEALTH;
_entity = (Zombie) loc.getWorld().spawnEntity(loc, EntityType.ZOMBIE);
UtilEnt.vegetate(_entity, true);
_entity.getEquipment().setHelmet(new ItemBuilder(Material.DIAMOND_HELMET).setUnbreakable(true).build());
_entity.getEquipment().setChestplate(new ItemBuilder(Material.DIAMOND_CHESTPLATE).setUnbreakable(true).build());
_entity.getEquipment().setLeggings(new ItemBuilder(Material.DIAMOND_LEGGINGS).setUnbreakable(true).build());
_entity.getEquipment().setBoots(new ItemBuilder(Material.DIAMOND_BOOTS).setUnbreakable(true).build());
_entity.setRemoveWhenFarAway(false);
_entity.setCustomName(owner.GetColor() + name);
}
public GameTeam getOwner()
{
return _owner;
}
public Location getLocation()
{
return _loc;
}
public String getName(boolean bold)
{
return _owner.GetColor() + (bold ? C.Bold : "") + _name;
}
public String getLastDamager()
{
return _lastDamager;
}
public int getHealth()
{
return Math.max(_health, 0);
}
public boolean isDead()
{
return getHealth() <= 0;
}
public void update(boolean beaconsAlive)
{
_entity.teleport(_loc);
for (int y = 0; y <= 4; y++)
{
for (int x = -4; x <= 4; x++)
{
for (int z = -4; z <= 4; z++)
{
Block block = _loc.clone().add(x, y, z).getBlock();
if ((block.getType() != Material.IRON_FENCE && block.getType() != Material.IRON_BLOCK) || !beaconsAlive)
{
block.setType(Material.AIR);
}
if (beaconsAlive)
{
if (x == -4 || x == 4 || z == -4 || z == 4)
{
if (y != 4)
{
block.setType(Material.IRON_FENCE);
}
}
if (y == 4)
{
block.setType(Material.IRON_BLOCK);
}
}
}
}
}
}
public boolean handleDamage(String player, double damage)
{
if (!UtilTime.elapsed(_lastDamage, 400))
{
return false;
}
_lastDamager = player;
_lastDamage = System.currentTimeMillis();
int dmg = (int)Math.ceil(damage);
_health -= dmg;
UtilEnt.PlayDamageSound(_entity);
return true;
}
}
>>>>>>> refs/remotes/origin/update/gem-hunters-11-5
}

View File

@ -1,15 +1,5 @@
package mineplex.gemhunters;
import mineplex.core.titles.Titles;
import mineplex.core.titles.tracks.TrackManager;
import net.minecraft.server.v1_8_R3.MinecraftServer;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.plugin.java.JavaPlugin;
import org.spigotmc.SpigotConfig;
import mineplex.core.CustomTagFix;
import mineplex.core.FoodDupeFix;
import mineplex.core.TimingsFix;
@ -67,6 +57,7 @@ import mineplex.core.task.TaskManager;
import mineplex.core.teleport.Teleport;
import mineplex.core.texttutorial.TextTutorialManager;
import mineplex.core.thank.ThankManager;
import mineplex.core.titles.Titles;
import mineplex.core.twofactor.TwoFactorAuth;
import mineplex.core.updater.FileUpdater;
import mineplex.core.updater.Updater;
@ -94,6 +85,7 @@ import mineplex.gemhunters.spawn.SpawnModule;
import mineplex.gemhunters.supplydrop.SupplyDropModule;
import mineplex.gemhunters.tutorial.GemHuntersTutorial;
import mineplex.gemhunters.world.DebugListeners;
import mineplex.gemhunters.world.Leaderboards;
import mineplex.gemhunters.world.TimeCycle;
import mineplex.gemhunters.world.UndergroundMobs;
import mineplex.gemhunters.world.WorldListeners;
@ -101,6 +93,12 @@ import mineplex.gemhunters.worldevent.WorldEventModule;
import mineplex.minecraft.game.core.combat.CombatManager;
import mineplex.minecraft.game.core.condition.ConditionManager;
import mineplex.minecraft.game.core.damage.DamageManager;
import net.minecraft.server.v1_8_R3.MinecraftServer;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.plugin.java.JavaPlugin;
import org.spigotmc.SpigotConfig;
import static mineplex.core.Managers.require;
@ -274,7 +272,7 @@ public class GemHunters extends JavaPlugin
tutorialManager.addTutorial(new GemHuntersTutorial());
require(Titles.class).forceDisable();
// Now we finally get to enable the Gem Hunters modules
// Though if any other module needs one of these it will be generated in
// order, however they are all here just for good measure.
@ -306,7 +304,8 @@ public class GemHunters extends JavaPlugin
new WorldListeners(this);
new TimeCycle(this);
new UndergroundMobs(this);
new DebugListeners(this);
new DebugListeners(this);
new Leaderboards();
// UpdateEvent!!!
new Updater(this);

View File

@ -84,7 +84,7 @@ public class DeathModule extends MiniPlugin
if (killer != null)
{
_stats.incrementStat(player, "Gem Hunters.Kills", 1);
_stats.incrementStat(killer, "Gem Hunters.Kills", 1);
}
startAnimation(player);

View File

@ -160,7 +160,11 @@ public class CashOutModule extends MiniPlugin
_aboutToCashOut.add(player.getUniqueId());
_stats.incrementStat(player, "Gem Hunters.GemsEarned", completeEvent.getGems());
if (completeEvent.getGems() != EconomyModule.GEM_START_COST)
{
_stats.incrementStat(player, "Gem Hunters.GemsEarned", completeEvent.getGems());
}
_donation.rewardCurrencyUntilSuccess(GlobalCurrency.GEM, player, "Earned", completeEvent.getGems());
session.endSession();

View File

@ -315,7 +315,7 @@ public class QuestModule extends MiniClientPlugin<QuestPlayerData>
player.sendMessage(F.main(_moduleName, "Completed " + F.name(quest.getName()) + "."));
_stats.incrementStat(player, "Gem Hunters.Quests Completed", 1);
_stats.incrementStat(player, "Gem Hunters.QuestsCompleted", 1);
QuestPlayerData playerData = Get(player);
playerData.getActiveQuests().remove(Integer.valueOf(quest.getId()));

View File

@ -217,7 +217,7 @@ public class SafezoneModule extends MiniPlugin
@EventHandler
public void flintAndSteelInteract(PlayerInteractEvent event)
{
if (event.getItem() == null || event.getItem().getType() != Material.FLINT_AND_STEEL)
if (event.getItem() == null || event.getItem().getType() != Material.FLINT_AND_STEEL || event.getClickedBlock() == null || !isInSafeZone(event.getClickedBlock().getLocation()))
{
return;
}

View File

@ -0,0 +1,33 @@
package mineplex.gemhunters.world;
import mineplex.core.Managers;
import mineplex.core.common.Pair;
import mineplex.core.common.util.UtilServer;
import mineplex.core.leaderboard.Leaderboard;
import mineplex.core.leaderboard.LeaderboardManager;
import mineplex.core.leaderboard.LeaderboardRepository.LeaderboardSQLType;
public class Leaderboards
{
private final LeaderboardManager _manager;
private final WorldDataModule _worldData;
public Leaderboards()
{
_manager = Managers.require(LeaderboardManager.class);
_worldData = Managers.require(WorldDataModule.class);
// Make sure the world is loaded
UtilServer.runSyncLater(this::createLeaderboards, 20);
}
private void createLeaderboards()
{
_manager.registerLeaderboard("TOP_GEM_HUNTERS_KILLS", new Leaderboard("Top Kills", Pair.create("Kill", "Kills"), new String[] {"Gem Hunters.Kills"}, LeaderboardSQLType.ALL, _worldData.getCustomLocation("TOP_KILLS").get(0), 10));
_manager.registerLeaderboard("TOP_GEM_HUNTERS_DAILY_KILLS", new Leaderboard("Top Daily Kills", Pair.create("Kill", "Kills"), new String[] {"Gem Hunters.Kills"}, LeaderboardSQLType.DAILY, _worldData.getCustomLocation("TOP_DAILY_KILLS").get(0), 10));
_manager.registerLeaderboard("TOP_GEM_HUNTERS_GEMS", new Leaderboard("Top Gems Cashed Out", Pair.create("Gem", "Gems"), new String[] {"Gem Hunters.GemsEarned"}, LeaderboardSQLType.ALL, _worldData.getCustomLocation("TOP_GEMS").get(0), 10));
_manager.registerLeaderboard("TOP_GEM_HUNTERS_DAILY_GEMS", new Leaderboard("Top Daily Gems Cashed Out", Pair.create("Gem", "Gems"), new String[] {"Gem Hunters.GemsEarned"}, LeaderboardSQLType.DAILY, _worldData.getCustomLocation("TOP_DAILY_GEMS").get(0), 10));
}
}

View File

@ -8,6 +8,7 @@ import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import mineplex.gemhunters.worldevent.ufo.UFOWorldEvent;
import org.bukkit.event.EventHandler;
import mineplex.core.MiniPlugin;
@ -45,7 +46,8 @@ public class WorldEventModule extends MiniPlugin
new BlizzardWorldEvent(),
//new NetherPortalWorldEvent(),
new WitherWorldEvent(),
new GwenMartWorldEvent()
new GwenMartWorldEvent(),
new UFOWorldEvent()
);
}

View File

@ -8,14 +8,15 @@ public enum WorldEventType
NETHER("Dark Portal", WorldEventPriority.TRIGGERED),
WITHER("Wither Temple", WorldEventPriority.TRIGGERED),
GWEN_MART("Gwen-Mart Mega Sale", WorldEventPriority.GLOBAL),
UFO("UFO", WorldEventPriority.GLOBAL),
;
private String _name;
private WorldEventPriority _priority;
private long _last;
private WorldEventType(String name, WorldEventPriority priority)
WorldEventType(String name, WorldEventPriority priority)
{
_name = name;
_priority = priority;

View File

@ -0,0 +1,204 @@
package mineplex.gemhunters.worldevent.ufo;
import mineplex.core.Managers;
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.skin.SkinData;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilTime;
import mineplex.core.utils.UtilVariant;
import mineplex.gemhunters.economy.EconomyModule;
import mineplex.gemhunters.loot.LootModule;
import mineplex.gemhunters.loot.rewards.LootChestReward;
import mineplex.gemhunters.worldevent.WorldEvent;
import mineplex.gemhunters.worldevent.WorldEventState;
import mineplex.gemhunters.worldevent.WorldEventType;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Skeleton;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.BlockVector;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;
public class UFOWorldEvent extends WorldEvent
{
private static final String SCHEMATIC_PATH = ".." + File.separator + ".." + File.separator + "update" + File.separator + "files" + File.separator + "UFO.schematic";
private static final long MAX_TIME = TimeUnit.MINUTES.toMillis(10);
private static final ItemStack HELMET = new ItemStack(Material.GLASS);
private static final ItemStack SWORD = new ItemStack(Material.STONE_SWORD);
private static final ItemStack SWORD_LEADER = new ItemStack(Material.IRON_SWORD);
private static final long CASH_OUT_DELAY = TimeUnit.MINUTES.toMillis(10);
private final EconomyModule _economy;
private final LootModule _loot;
private Skeleton _leader;
private Set<Skeleton> _skeletons;
private Set<Block> _ufoBlocks;
public UFOWorldEvent()
{
super(WorldEventType.UFO);
_economy = Managers.require(EconomyModule.class);
_loot = Managers.require(LootModule.class);
_skeletons = new HashSet<>();
_ufoBlocks = new HashSet<>();
}
@Override
public void onStart()
{
Location location = UtilAlg.Random(_worldData.getCustomLocation("NETHER_PORTAL")).clone().subtract(5, -10, 5);
Schematic schematic;
try
{
schematic = UtilSchematic.loadSchematic(new File(SCHEMATIC_PATH));
}
catch (IOException e)
{
e.printStackTrace();
return;
}
SchematicData data = schematic.paste(location, false, false, false);
for (BlockVector vector : data.getBlocks())
{
Location block = location.add(vector);
_ufoBlocks.add(block.getBlock());
location.subtract(vector);
}
_leader = UtilVariant.spawnWitherSkeleton(location);
_leader.setMaxHealth(200);
_leader.setHealth(_leader.getMaxHealth());
_leader.getEquipment().setItemInHand(SWORD_LEADER);
_leader.setCustomName(C.cDGreenB + "Alien Leader");
prepareSkeleton(_leader);
for (int i = 0; i < 10; i++)
{
Skeleton skeleton = _leader.getWorld().spawn(location, Skeleton.class);
skeleton.getEquipment().setItemInHand(SWORD);
skeleton.setCustomName(C.cGreenB + "Alien");
prepareSkeleton(skeleton);
_skeletons.add(skeleton);
}
setEventState(WorldEventState.LIVE);
}
private void prepareSkeleton(Skeleton skeleton)
{
skeleton.getEquipment().setHelmet(HELMET);
skeleton.setRemoveWhenFarAway(false);
skeleton.setCustomNameVisible(true);
}
@EventHandler
public void entityDeath(EntityDeathEvent event)
{
LivingEntity entity = event.getEntity();
if (_skeletons.remove(entity))
{
event.getDrops().clear();
event.setDroppedExp(0);
Player killer = entity.getKiller();
if (killer != null)
{
_economy.addToStore(killer, "Killing an Alien", 10);
}
}
if (_leader != null && _leader.equals(entity))
{
Player killer = _leader.getKiller();
if (killer != null)
{
ItemStack itemStack = SkinData.OMEGA_CHEST.getSkull(C.cAqua + "Omega Chest", new ArrayList<>());
LootChestReward reward = new LootChestReward(CASH_OUT_DELAY, itemStack, "Omega", 1);
_leader.getWorld().dropItemNaturally(_leader.getEyeLocation(), itemStack);
_loot.addItemReward(reward);
_economy.addToStore(killer, "Killing The Alien Leader", 1000);
}
}
}
@EventHandler
public void entityDamage(EntityCombustEvent event)
{
Entity entity = event.getEntity();
if (entity.equals(_leader) || _skeletons.contains(entity))
{
event.setCancelled(true);
}
}
@Override
public boolean checkToEnd()
{
return _leader.isDead() || UtilTime.elapsed(_start, MAX_TIME);
}
@Override
public void onEnd()
{
_leader.remove();
for (Skeleton skeleton : _skeletons)
{
skeleton.remove();
}
_skeletons.clear();
for (Block block : _ufoBlocks)
{
block.setType(Material.AIR);
}
_ufoBlocks.clear();
}
@Override
public Location[] getEventLocations()
{
return new Location[]{_leader.getLocation()};
}
@Override
public double getProgress()
{
return _leader.getHealth() / _leader.getMaxHealth();
}
}