Finish adding all features to match PE Cake Wars

This commit is contained in:
Sam 2017-10-17 20:27:00 +01:00 committed by Alexander Meech
parent 1721f7016c
commit 3fd18c1416
23 changed files with 963 additions and 229 deletions

View File

@ -3,7 +3,6 @@ package nautilus.game.arcade.game.games.cakewars;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Location;
import org.bukkit.Material;
@ -15,7 +14,6 @@ import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
@ -25,6 +23,7 @@ import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.TeamGame;
import nautilus.game.arcade.game.games.cakewars.data.CakeTeam;
import nautilus.game.arcade.game.games.cakewars.kits.KitCakeArcher;
import nautilus.game.arcade.game.games.cakewars.kits.KitCakeBuilder;
import nautilus.game.arcade.game.games.cakewars.kits.KitCakeWarrior;
@ -35,9 +34,11 @@ import nautilus.game.arcade.game.games.cakewars.module.CakeShopModule;
import nautilus.game.arcade.game.games.cakewars.module.CakeSpawnerModule;
import nautilus.game.arcade.game.games.cakewars.module.CakeTeamModule;
import nautilus.game.arcade.game.modules.CustomScoreboardModule;
import nautilus.game.arcade.game.modules.EnderPearlModule;
import nautilus.game.arcade.game.modules.capturepoint.CapturePointModule;
import nautilus.game.arcade.game.modules.chest.ChestLootModule;
import nautilus.game.arcade.game.modules.chest.ChestLootPool;
import nautilus.game.arcade.game.modules.compass.CompassModule;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.scoreboard.GameScoreboard;
@ -51,9 +52,21 @@ public class CakeWars extends TeamGame
"Control the " + C.cAqua + "Beacons" + C.cWhite + " to get more resources.",
"Last team standing wins!"
};
private static final String[] TIPS =
{
"Your teammates kit's appear next to their name or in the tab-list.",
"Controlling the beacons is essential to victory.",
"Watch out for other teams incase they try to rush your Cake!",
"Controlling the middle beacon will spawn Nether-Stars at your base, these can be used to give your whole team a bonus.",
"Controlling the outer beacons will spawn Emeralds at your base, these can be used to buy strong weapons and armor.",
"Players will respawn as long as there cake hasn't been eaten."
};
private static final int RESPAWN_TIME = 6;
private final Map<GameTeam, Location> _averages;
private final CakeTeamModule _cakeTeamModule;
private final CakeShopModule _cakeShopModule;
private final ChestLootModule _chestLootModule;
private final CustomScoreboardModule _customScoreboardModule;
private final CapturePointModule _capturePointModule;
@ -72,9 +85,7 @@ public class CakeWars extends TeamGame
BlockPlace = true;
BlockBreak = true;
QuitDropItems = true;
DeathDropItems = true;
DeathSpectateSecs = 5;
DeathSpectateSecs = RESPAWN_TIME;
StrictAntiHack = true;
HungerSet = 20;
InventoryClick = true;
@ -82,9 +93,15 @@ public class CakeWars extends TeamGame
InventoryOpenBlock = true;
ItemDrop = true;
ItemPickup = true;
_help = TIPS;
new CakeTeamModule(this)
.register();
manager.GetCreature().SetDisableCustomDrops(true);
new CompassModule()
.register(this);
_cakeTeamModule = new CakeTeamModule(this);
_cakeTeamModule.register();
new CakeIslandModule(this)
.register();
@ -95,8 +112,8 @@ public class CakeWars extends TeamGame
new CakeSpawnerModule(this)
.register();
new CakeShopModule(this)
.register();
_cakeShopModule = new CakeShopModule(this);
_cakeTeamModule.register();
_cakePointModule = new CakePointModule(this);
_cakePointModule.register();
@ -104,6 +121,9 @@ public class CakeWars extends TeamGame
_capturePointModule = new CapturePointModule();
_capturePointModule.register(this);
new EnderPearlModule()
.register(this);
_chestLootModule = new ChestLootModule();
_customScoreboardModule = new CustomScoreboardModule()
@ -148,9 +168,38 @@ public class CakeWars extends TeamGame
{
scoreboard.writeNewLine();
scoreboard.write("Hello World");
scoreboard.write(player.getName());
scoreboard.write("");
GameTeam playerTeam = GetTeam(player);
scoreboard.write(C.cYellowB + "Teams");
for (GameTeam team : GetTeamList())
{
CakeTeam cakeTeam = _cakeTeamModule.getCakeTeam(team);
boolean hasCake = cakeTeam != null && cakeTeam.canRespawn();
String teamLine = "";
if (hasCake)
{
teamLine += C.cGreenB + "";
}
else if (!team.IsTeamAlive())
{
teamLine += C.cRedB + "";
}
else
{
teamLine += C.cGreen + team.GetPlayers(true).size();
}
teamLine += " " + team.GetFormattedName();
if (playerTeam != null && playerTeam.equals(team))
{
teamLine += C.Reset + " " + C.cYellowB + "";
}
scoreboard.write(teamLine);
}
scoreboard.writeNewLine();
}
@ -232,25 +281,6 @@ public class CakeWars extends TeamGame
return _averages.get(team);
}
public GameTeam getClosest(Location location)
{
GameTeam closest = null;
double closestDist = Double.MAX_VALUE;
for (Entry<GameTeam, Location> entry : _averages.entrySet())
{
double dist = UtilMath.offsetSquared(location, entry.getValue());
if (closest == null || dist < closestDist)
{
closest = entry.getKey();
closestDist = dist;
}
}
return closest;
}
public ChestLootModule getChestLootModule()
{
return _chestLootModule;
@ -265,4 +295,14 @@ public class CakeWars extends TeamGame
{
return _cakePointModule;
}
public CakeTeamModule getCakeTeamModule()
{
return _cakeTeamModule;
}
public CakeShopModule getCakeShopModule()
{
return _cakeShopModule;
}
}

View File

@ -0,0 +1,12 @@
package nautilus.game.arcade.game.games.cakewars.data;
import org.bukkit.inventory.ItemStack;
public interface CakeItem
{
ItemStack getItemStack();
int getCost();
}

View File

@ -12,7 +12,7 @@ import nautilus.game.arcade.game.games.cakewars.module.CakeSpawnerModule;
public enum CakeResource
{
BRICK("Brick", ChatColor.RED, new ItemStack(Material.CLAY_BRICK), UpdateType.TWOSEC)
BRICK("Brick", ChatColor.RED, new ItemStack(Material.CLAY_BRICK), UpdateType.TWOSEC, 64)
{
@Override
@ -22,7 +22,7 @@ public enum CakeResource
}
},
EMERALD("Emerald", ChatColor.GREEN, new ItemStack(Material.EMERALD), UpdateType.SEC_05)
EMERALD("Emerald", ChatColor.GREEN, new ItemStack(Material.EMERALD), UpdateType.SEC_05, 24)
{
@Override
@ -32,7 +32,7 @@ public enum CakeResource
}
},
STAR("Nether Star", ChatColor.GOLD, new ItemStack(Material.NETHER_STAR), UpdateType.SEC_08)
STAR("Nether Star", ChatColor.GOLD, new ItemStack(Material.NETHER_STAR), UpdateType.SEC_08, 8)
{
@Override
@ -47,13 +47,15 @@ public enum CakeResource
private final ChatColor _chatColor;
private final ItemStack _itemStack;
private final UpdateType _spawnerUpdate;
private final int _maxSpawned;
CakeResource(String name, ChatColor chatColor, ItemStack itemStack, UpdateType spawnerUpdate)
CakeResource(String name, ChatColor chatColor, ItemStack itemStack, UpdateType spawnerUpdate, int maxSpawned)
{
_name = name;
_chatColor = chatColor;
_itemStack = itemStack;
_spawnerUpdate = spawnerUpdate;
_maxSpawned = maxSpawned;
}
public abstract void handleDistribution(CakeSpawnerModule module, GameTeam team);
@ -77,4 +79,9 @@ public enum CakeResource
{
return _spawnerUpdate;
}
public int getMaxSpawned()
{
return _maxSpawned;
}
}

View File

@ -2,30 +2,25 @@ package nautilus.game.arcade.game.games.cakewars.data;
import org.bukkit.inventory.ItemStack;
public class CakeShopItem
public class CakeShopItem implements CakeItem
{
private final ItemStack _itemStack;
private final CakeResource _resource;
private final int _cost;
public CakeShopItem(ItemStack itemStack, CakeResource resource, int cost)
public CakeShopItem(ItemStack itemStack, int cost)
{
_itemStack = itemStack;
_resource = resource;
_cost = cost;
}
@Override
public ItemStack getItemStack()
{
return _itemStack;
}
public CakeResource getResource()
{
return _resource;
}
@Override
public int getCost()
{
return _cost;

View File

@ -1,6 +1,5 @@
package nautilus.game.arcade.game.games.cakewars.data;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -25,27 +24,33 @@ public class CakeTeam
C.cGold + "Capture the beacons around the",
C.cGold + "map to earn different resources!"
};
private static final String SHOP_HOLOGRAM_TEXT = C.cGold + "Click the NPCs to buy better gear!";
private static final String CAKE_HOLOGRAM_TEXT = C.cGold + "Protect your cake at all costs!";
private final CakeWars _game;
private final GameTeam _team;
private final Location _edgeHologram;
private final Location _shopHologram;
private final Location _cake;
private final List<Hologram> _holograms;
private final Map<CakeTeamPowerup, Integer> _upgrades;
private final Map<CakeTeamItem, Integer> _upgrades;
private Hologram _cakeHologram;
public CakeTeam(CakeWars game, GameTeam team, Location edgeHologram)
public CakeTeam(CakeWars game, GameTeam team, Location edgeHologram, Location shopHologram)
{
_game = game;
_team = team;
_edgeHologram = edgeHologram.add(0, 2, 0);
_shopHologram = shopHologram.add(0, 2, 0);
_cake = game.WorldData.GetDataLocs(team.GetName().toUpperCase()).get(0).getBlock().getLocation();
_cake.getBlock().setType(Material.CAKE_BLOCK);
_holograms = new ArrayList<>(3);
_upgrades = new HashMap<>(CakeTeamPowerup.values().length);
_upgrades = new HashMap<>(CakeTeamItem.values().length);
for (CakeTeamItem item : CakeTeamItem.values())
{
_upgrades.put(item, 0);
}
setupHolograms();
}
@ -60,12 +65,30 @@ public class CakeTeam
.addPlayers(teamPlayers)
.start();
new Hologram(hologramManager, _shopHologram, SHOP_HOLOGRAM_TEXT)
.setHologramTarget(HologramTarget.WHITELIST)
.addPlayers(teamPlayers)
.start();
_cakeHologram = new Hologram(hologramManager, _cake.clone().add(0.5, 1.3, 0.5), CAKE_HOLOGRAM_TEXT)
.setHologramTarget(HologramTarget.WHITELIST)
.addPlayers(teamPlayers)
.start();
}
public void applyUpgrades()
{
List<Player> alive = _team.GetPlayers(true);
_upgrades.forEach((item, level) ->
{
if (level > 0)
{
alive.forEach(player -> item.apply(player, level));
}
});
}
public boolean canRespawn()
{
return _cake.getBlock().getType() != Material.AIR;
@ -76,13 +99,18 @@ public class CakeTeam
return _cake;
}
public List<Hologram> getHolograms()
public GameTeam getGameTeam()
{
return _holograms;
return _team;
}
public Hologram getCakeHologram()
{
return _cakeHologram;
}
public Map<CakeTeamItem, Integer> getUpgrades()
{
return _upgrades;
}
}

View File

@ -0,0 +1,119 @@
package nautilus.game.arcade.game.games.cakewars.data;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import mineplex.core.common.util.UtilItem;
import mineplex.core.itemstack.ItemBuilder;
public enum CakeTeamItem implements CakeItem
{
PROTECTION(
"Protection",
new ItemStack(Material.DIAMOND_CHESTPLATE),
4,
10
)
{
@Override
public void apply(Player player, int level)
{
for (ItemStack itemStack : player.getInventory().getArmorContents())
{
if (itemStack != null && itemStack.getType() != Material.AIR)
{
itemStack.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, level);
}
}
}
},
HASTE(
"Haste",
new ItemStack(Material.GOLD_PICKAXE),
4,
10
)
{
@Override
public void apply(Player player, int level)
{
player.removePotionEffect(PotionEffectType.FAST_DIGGING);
player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, Integer.MAX_VALUE, level - 1, true, false));
}
},
SHARPNESS(
"Sharpness",
new ItemStack(Material.DIAMOND_SWORD),
4,
10
)
{
@Override
public void apply(Player player, int level)
{
for (ItemStack itemStack : player.getInventory().getContents())
{
if (UtilItem.isSword(itemStack))
{
itemStack.addEnchantment(Enchantment.DAMAGE_ALL, level);
}
}
}
},
RESOURCE(
"Resource Generator",
new ItemStack(Material.NETHER_STAR),
4,
10
)
{
@Override
public void apply(Player player, int level)
{
}
};
private final String _name;
private final ItemStack _itemStack;
private final int[] _costs;
CakeTeamItem(String name, ItemStack itemStack, int... costs)
{
_name = name;
_itemStack = new ItemBuilder(itemStack)
.setTitle(name)
.setGlow(true)
.build();
_costs = costs;
}
public abstract void apply(Player player, int level);
public String getName()
{
return _name;
}
@Override
public ItemStack getItemStack()
{
return _itemStack;
}
public int[] getCosts()
{
return _costs;
}
@Override
public int getCost()
{
return 0;
}
}

View File

@ -1,29 +0,0 @@
package nautilus.game.arcade.game.games.cakewars.data;
public enum CakeTeamPowerup
{
PROTECTION("Protection", 2),
SHARPNESS("Sharpness", 2),
HASTE("Haste", 2),
RESOURCE("Resource", 2);
private final String _name;
private final int _max;
CakeTeamPowerup(String name, int max)
{
_name = name;
_max = max;
}
public String getName()
{
return _name;
}
public int getMax()
{
return _max;
}
}

View File

@ -8,6 +8,7 @@ import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.games.cakewars.kits.perk.PerkPassiveWoolGain;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.ProgressingKit;
@ -19,11 +20,12 @@ public class KitCakeBuilder extends ProgressingKit
{
"Get extra blocks to build with!",
"",
"Spawn with an extra " + C.cGreen + "32" + C.cWhite + " blocks"
"Receive " + C.cGreen + "1" + C.cWhite + " wool block every " + C.cGreen + "4" + C.cWhite + " seconds",
};
private static final Perk[] PERKS =
{
new PerkPassiveWoolGain()
};
private static final ItemStack IN_HAND = new ItemStack(Material.WOOL);

View File

@ -0,0 +1,42 @@
package nautilus.game.arcade.game.games.cakewars.kits.perk;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.kit.Perk;
public class PerkPassiveWoolGain extends Perk
{
public PerkPassiveWoolGain()
{
super("Knitter");
}
@EventHandler
public void updateGain(UpdateEvent event)
{
if (event.getType() != UpdateType.SLOW || !Manager.GetGame().IsLive())
{
return;
}
for (Player player : Manager.GetGame().GetPlayers(true))
{
if (UtilPlayer.isSpectator(player) || !hasPerk(player))
{
continue;
}
ItemStack itemStack = new ItemStack(Material.WOOL, 1, (short) 0, Manager.GetGame().GetTeam(player).GetColorData());
player.getInventory().addItem(itemStack);
}
}
}

View File

@ -1,38 +1,72 @@
package nautilus.game.arcade.game.games.cakewars.module;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.events.PlayerKitGiveEvent;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.games.cakewars.CakeWars;
public class CakePlayerModule extends CakeModule
{
static final ItemStack RUNE_OF_HOLDING = new ItemBuilder(Material.SKULL_ITEM, (byte) 1)
.setTitle(C.cPurpleB + "Rune of Holding")
.addLore("", "Preserves your inventory on death", "Uses: " + C.cRed + "1")
.build();
static final ItemStack DEPLOY_PLATFORM = new ItemBuilder(Material.INK_SACK, (byte) 11)
.setTitle(C.cYellowB + "Deploy Platform")
.addLore("", "Creates a platform of wool next to", "any block you click!", "Uses: " + C.cRed + "1")
.build();
private static final int PLATFORM_DELTA = 1;
private final Set<Block> _placedBlocks;
// Used to store the inventory of a player when using the rune of holding
// Inventory[0], Armour[1]
private final Map<Player, ItemStack[][]> _storedInventory;
public CakePlayerModule(CakeWars game)
{
super(game);
_placedBlocks = new HashSet<>();
_storedInventory = new HashMap<>();
}
@Override
public void cleanup()
{
_placedBlocks.clear();
_storedInventory.clear();
}
@EventHandler
@ -69,4 +103,140 @@ public class CakePlayerModule extends CakeModule
event.getPlayer().sendMessage(F.main("Game", "You cannot break blocks that have not been placed by players."));
}
}
@EventHandler
public void holdingRunePlace(BlockPlaceEvent event)
{
if (event.getItemInHand().getType() == RUNE_OF_HOLDING.getType())
{
event.setCancelled(true);
event.getPlayer().sendMessage(F.main("Game", "You cannot place a " + F.name(RUNE_OF_HOLDING.getItemMeta().getDisplayName()) + "."));
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void damage(CustomDamageEvent event)
{
Player player = event.GetDamageePlayer();
if (player == null || !UtilInv.contains(player, RUNE_OF_HOLDING.getType(), RUNE_OF_HOLDING.getData().getData(), 1))
{
return;
}
PlayerInventory inventory = player.getInventory();
_storedInventory.put(player, new ItemStack[][]
{
inventory.getContents(),
inventory.getArmorContents()
});
}
@EventHandler(priority = EventPriority.LOWEST)
public void playerDeath(PlayerDeathEvent event)
{
Player player = event.getEntity();
if (UtilInv.remove(player, RUNE_OF_HOLDING.getType(), RUNE_OF_HOLDING.getData().getData(), 1))
{
_game.getArcadeManager().runSyncLater(() ->
{
player.playSound(player.getLocation(), Sound.ENDERMAN_TELEPORT, 1, 0.8F);
player.sendMessage(F.main("Game", "You consumed one " + F.name(RUNE_OF_HOLDING.getItemMeta().getDisplayName()) + ". You will respawn with your inventory."));
}, 20);
}
else
{
_storedInventory.remove(player);
}
}
@EventHandler
public void kitGiveItems(PlayerKitGiveEvent event)
{
if (!_game.IsLive())
{
return;
}
Player player = event.getPlayer();
ItemStack[][] storedInventory = _storedInventory.remove(player);
if (storedInventory != null)
{
_game.getArcadeManager().runSyncLater(() ->
{
PlayerInventory inventory = player.getInventory();
inventory.setContents(storedInventory[0]);
inventory.setArmorContents(storedInventory[1]);
player.updateInventory();
}, 1);
}
}
@EventHandler
public void playerQuit(PlayerQuitEvent event)
{
_storedInventory.remove(event.getPlayer());
}
@EventHandler(priority = EventPriority.HIGH)
public void playerInteractPlatform(PlayerInteractEvent event)
{
if (event.isCancelled())
{
return;
}
Player player = event.getPlayer();
ItemStack itemStack = player.getItemInHand();
Block block = event.getClickedBlock();
if (UtilPlayer.isSpectator(player) || itemStack == null || !itemStack.isSimilar(DEPLOY_PLATFORM) || block == null)
{
return;
}
BlockFace face = UtilBlock.getFace(player.getLocation().getYaw()).getOppositeFace();
block = block.getRelative(face).getRelative(face);
byte teamData = _game.GetTeam(player).GetColorData();
boolean blockChanged = false;
for (int x = -PLATFORM_DELTA; x <= PLATFORM_DELTA; x++)
{
for (int z = -PLATFORM_DELTA; z <= PLATFORM_DELTA; z++)
{
Block nearby = block.getRelative(x, 0, z);
Location nearbyLocation = nearby.getLocation();
if (nearby.getType() != Material.AIR || _game.getCapturePointModule().isOnPoint(nearbyLocation) || _game.getCakeShopModule().isNearShop(nearbyLocation))
{
continue;
}
_placedBlocks.add(nearby);
MapUtil.QuickChangeBlockAt(nearbyLocation, Material.WOOL, teamData);
blockChanged = true;
}
}
if (blockChanged)
{
player.setItemInHand(UtilInv.decrement(itemStack));
}
}
@EventHandler
public void itemCraft(CraftItemEvent event)
{
if (!_game.IsLive())
{
return;
}
event.setCancelled(true);
}
}

View File

@ -35,6 +35,11 @@ public class CakePointModule extends CakeModule
@EventHandler
public void blockPlace(BlockPlaceEvent event)
{
if (!_game.IsLive())
{
return;
}
Location location = event.getBlock().getLocation();
for (CapturePoint point : _game.getCapturePointModule().getCapturePoints())

View File

@ -11,11 +11,15 @@ import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.Managers;
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.itemstack.ItemBuilder;
import mineplex.core.newnpc.NPC;
import mineplex.core.newnpc.NewNPCManager;
@ -25,18 +29,22 @@ import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.games.cakewars.CakeWars;
import nautilus.game.arcade.game.games.cakewars.data.CakeItem;
import nautilus.game.arcade.game.games.cakewars.data.CakeResource;
import nautilus.game.arcade.game.games.cakewars.data.CakeShopItem;
import nautilus.game.arcade.game.games.cakewars.ui.CakeResourcePage;
import nautilus.game.arcade.game.games.cakewars.ui.CakeResourceShop;
import nautilus.game.arcade.game.games.cakewars.ui.CakeResourceStarPage;
public class CakeShopModule extends CakeModule
{
private static final int MIN_BLOCK_PLACE_DIST_SQUARED = 49;
private final NewNPCManager _manager;
private final Map<NPC, CakeResource> _npcs;
private final CakeResourceShop _shop;
private final Map<CakeResource, List<CakeShopItem>> _items;
private final Map<CakeResource, List<CakeItem>> _items;
public CakeShopModule(CakeWars game)
{
@ -52,44 +60,74 @@ public class CakeShopModule extends CakeModule
// Iron Set
new CakeShopItem(new ItemBuilder(Material.IRON_HELMET)
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
.build(), CakeResource.BRICK, 5),
.build(), 5),
new CakeShopItem(new ItemBuilder(Material.IRON_CHESTPLATE)
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
.build(), CakeResource.BRICK, 7),
.build(), 7),
new CakeShopItem(new ItemBuilder(Material.IRON_LEGGINGS)
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
.build(), CakeResource.BRICK, 7),
.build(), 7),
new CakeShopItem(new ItemBuilder(Material.IRON_BOOTS)
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
.build(), CakeResource.BRICK, 5),
.build(), 5),
// Sword
new CakeShopItem(new ItemStack(Material.DIAMOND_SWORD), CakeResource.BRICK, 5),
new CakeShopItem(new ItemStack(Material.DIAMOND_SWORD), 5),
// Pickaxe
new CakeShopItem(new ItemStack(Material.IRON_PICKAXE), CakeResource.BRICK, 3),
new CakeShopItem(new ItemStack(Material.IRON_PICKAXE), 3),
// Arrow
new CakeShopItem(new ItemStack(Material.ARROW, 3), CakeResource.BRICK, 6),
new CakeShopItem(new ItemStack(Material.ARROW, 3), 6),
// Wool
new CakeShopItem(new ItemStack(Material.WOOL, 20), CakeResource.BRICK, 3),
new CakeShopItem(new ItemStack(Material.WOOL, 20), 3),
// Deploy Platform
new CakeShopItem(CakePlayerModule.DEPLOY_PLATFORM, 5),
// Emerald
new CakeShopItem(new ItemStack(Material.EMERALD), CakeResource.BRICK, 20)
new CakeShopItem(new ItemStack(Material.EMERALD), 20)
)
);
_items.put(CakeResource.EMERALD, Arrays.asList(
// Obsidian
new CakeShopItem(new ItemStack(Material.OBSIDIAN), CakeResource.EMERALD, 5),
new CakeShopItem(new ItemStack(Material.OBSIDIAN), 5),
// Pickaxe
new CakeShopItem(new ItemStack(Material.DIAMOND_PICKAXE), CakeResource.EMERALD, 10)
new CakeShopItem(new ItemStack(Material.DIAMOND_PICKAXE), 10),
));
_items.put(CakeResource.STAR, Arrays.asList(
// Sword
new CakeShopItem(new ItemBuilder(Material.DIAMOND_SWORD)
.addEnchantment(Enchantment.DAMAGE_ALL, 1)
.build(), 10),
// Diamond Set
new CakeShopItem(new ItemBuilder(Material.DIAMOND_HELMET)
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
.build(), 10),
new CakeShopItem(new ItemBuilder(Material.DIAMOND_CHESTPLATE)
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
.build(), 20),
new CakeShopItem(new ItemBuilder(Material.DIAMOND_LEGGINGS)
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
.build(), 20),
new CakeShopItem(new ItemBuilder(Material.DIAMOND_BOOTS)
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
.build(), 10),
// Rune of Holding
new CakeShopItem(CakePlayerModule.RUNE_OF_HOLDING, 20),
// Shears
new CakeShopItem(new ItemStack(Material.SHEARS), 5),
// Golden Apple
new CakeShopItem(new ItemStack(Material.GOLDEN_APPLE), 5),
// Ender pearl
new CakeShopItem(new ItemStack(Material.ENDER_PEARL), 5)
));
}
@ -130,6 +168,11 @@ public class CakeShopModule extends CakeModule
@EventHandler
public void npcInteract(NPCInteractEvent event)
{
if (!_game.IsLive())
{
return;
}
NPC npc = event.getNpc();
CakeResource resource = _npcs.get(npc);
@ -138,9 +181,51 @@ public class CakeShopModule extends CakeModule
return;
}
Player player = event.getPlayer();
event.setCancelled(true);
_shop.openPageForPlayer(player, new CakeResourcePage(_game.getArcadeManager(), _shop, player, resource, _items.get(resource)));
Player player = event.getPlayer();
CakeResourcePage page;
if (resource == CakeResource.STAR)
{
page = new CakeResourceStarPage(_game.getArcadeManager(), _shop, player);
}
else
{
page = new CakeResourcePage(_game.getArcadeManager(), _shop, player, resource, _items.get(resource));
}
page.refresh();
_shop.openPageForPlayer(player, page);
}
@EventHandler
public void blockPlace(BlockPlaceEvent event)
{
if (!_game.IsLive() || UtilPlayer.isSpectator(event.getPlayer()))
{
return;
}
Location location = event.getBlock().getLocation();
if (isNearShop(location))
{
event.setCancelled(true);
event.getPlayer().sendMessage(F.main("Game", "You cannot place blocks that close to the Shop."));
}
}
public boolean isNearShop(Location location)
{
for (NPC npc : _npcs.keySet())
{
if (UtilMath.offsetSquared(location, npc.getEntity().getLocation()) < MIN_BLOCK_PLACE_DIST_SQUARED)
{
return true;
}
}
return false;
}
}

View File

@ -21,6 +21,7 @@ import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.games.cakewars.CakeWars;
import nautilus.game.arcade.game.games.cakewars.data.CakeResource;
import nautilus.game.arcade.game.games.cakewars.data.CakeTeamItem;
public class CakeSpawnerModule extends CakeModule
{
@ -31,7 +32,6 @@ public class CakeSpawnerModule extends CakeModule
.put("GREEN", "LIME")
.put("YELLOW", "ORANGE")
.build();
private static final int MAX_ITEMS = 32;
public CakeSpawnerModule(CakeWars game)
{
@ -55,6 +55,11 @@ public class CakeSpawnerModule extends CakeModule
for (GameTeam team : _game.GetTeamList())
{
if (!team.IsTeamAlive())
{
continue;
}
resource.handleDistribution(this, team);
}
}
@ -67,7 +72,10 @@ public class CakeSpawnerModule extends CakeModule
return;
}
ItemStack itemStack = resource.getItemStack();
amount += _game.getCakeTeamModule().getCakeTeam(team).getUpgrades().get(CakeTeamItem.RESOURCE);
ItemStack itemStack = resource.getItemStack().clone();
itemStack.setAmount(amount);
Location location = _game.WorldData.GetDataLocs(SPAWNER_CONVERTERS.get(team.GetName().toUpperCase())).get(0);
boolean drop = true;
List<Player> players = new ArrayList<>();
@ -102,7 +110,7 @@ public class CakeSpawnerModule extends CakeModule
{
if (item != null)
{
item.getItemStack().setAmount(Math.min(item.getItemStack().getAmount() + 1, MAX_ITEMS));
item.getItemStack().setAmount(Math.min(item.getItemStack().getAmount() + itemStack.getAmount(), resource.getMaxSpawned()));
}
else
{
@ -118,6 +126,7 @@ public class CakeSpawnerModule extends CakeModule
{
continue;
}
player.getInventory().addItem(itemStack);
player.playSound(player.getLocation(), Sound.ITEM_PICKUP, 1, 1);
}

View File

@ -11,6 +11,7 @@ import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAlg;
@ -24,6 +25,7 @@ import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.events.PlayerDeathOutEvent;
import nautilus.game.arcade.events.PlayerKitGiveEvent;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.games.cakewars.CakeWars;
@ -34,6 +36,7 @@ public class CakeTeamModule extends CakeModule
{
private static final int HOLOGRAM_VIEW_SQUARED = 16;
private static final ItemStack STARTING_SWORD = new ItemStack(Material.WOOD_SWORD);
private final Map<GameTeam, CakeTeam> _teams;
@ -47,7 +50,6 @@ public class CakeTeamModule extends CakeModule
@Override
public void cleanup()
{
_teams.values().forEach(cakeTeam -> cakeTeam.getHolograms().forEach(Hologram::stop));
_teams.clear();
}
@ -61,6 +63,7 @@ public class CakeTeamModule extends CakeModule
WorldData worldData = _game.WorldData;
List<Location> edgeHolograms = worldData.GetDataLocs("BLACK");
List<Location> shopHolograms = worldData.GetDataLocs("GRAY");
_game.GetTeamList().forEach(team ->
{
@ -69,13 +72,19 @@ public class CakeTeamModule extends CakeModule
return;
}
Location average = _game.getAverageLocation(team);
_teams.put(team,
new CakeTeam(
_game,
team,
UtilAlg.findClosest(
_game.getAverageLocation(team),
average,
edgeHolograms
),
UtilAlg.findClosest(
average,
shopHolograms
)
)
);
@ -98,7 +107,7 @@ public class CakeTeamModule extends CakeModule
for (Player player : team.GetPlayers(false))
{
if (!player.isOnline() || !team.IsAlive(player) || UtilMath.offsetSquared(player.getLocation(), location) < HOLOGRAM_VIEW_SQUARED)
if (!player.isOnline() || !team.IsAlive(player) || !cakeTeam.canRespawn() || UtilMath.offsetSquared(player.getLocation(), location) < HOLOGRAM_VIEW_SQUARED)
{
hologram.removePlayer(player);
}
@ -160,7 +169,7 @@ public class CakeTeamModule extends CakeModule
block.setType(Material.AIR);
_game.AddGems(player, 20, "Cakes Eaten", true, true);
playerTeam.GetPlayers(true).forEach(other -> _game.AddGems(player, 2, "Team Cakes Eaten", true, true));
playerTeam.GetPlayers(true).forEach(other -> _game.AddGems(player, 2, "Cakes Eaten", true, true));
_game.Announce(F.main("Game", F.name(team.GetFormattedName()) + "'s Cake was eaten by " + F.name(playerTeam.GetColor() + player.getName()) + "! They can no longer respawn."));
UtilTextMiddle.display(team.GetColor() + "CAKE EATEN", "You can no longer respawn", 10, 30, 10, team.GetPlayers(true).toArray(new Player[0]));
@ -180,4 +189,29 @@ public class CakeTeamModule extends CakeModule
event.setCancelled(true);
}
@EventHandler
public void kitGiveItems(PlayerKitGiveEvent event)
{
if (!_game.IsLive())
{
return;
}
Player player = event.getPlayer();
player.getInventory().addItem(STARTING_SWORD);
_teams.get(_game.GetTeam(player)).getUpgrades().forEach((item, level) ->
{
if (level > 0)
{
item.apply(player, level);
}
});
}
public CakeTeam getCakeTeam(GameTeam team)
{
return _teams.get(team);
}
}

View File

@ -3,6 +3,7 @@ package nautilus.game.arcade.game.games.cakewars.ui;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
@ -10,81 +11,107 @@ import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilItem;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.recharge.Recharge;
import mineplex.core.shop.item.IButton;
import mineplex.core.shop.page.ShopPageBase;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.games.cakewars.CakeWars;
import nautilus.game.arcade.game.games.cakewars.data.CakeItem;
import nautilus.game.arcade.game.games.cakewars.data.CakeResource;
import nautilus.game.arcade.game.games.cakewars.data.CakeShopItem;
import nautilus.game.arcade.game.games.cakewars.data.CakeTeam;
public class CakeResourcePage extends ShopPageBase<ArcadeManager, CakeResourceShop>
{
private final List<CakeShopItem> _items;
private final byte _teamData;
private static final ItemStack CLOSE_ITEM = new ItemBuilder(Material.BARRIER)
.setTitle(C.cRedB + "Close")
.build();
public CakeResourcePage(ArcadeManager plugin, CakeResourceShop shop, Player player, CakeResource resource, List<CakeShopItem> items)
final CakeResource _resource;
final List<CakeItem> _items;
private final GameTeam _team;
public CakeResourcePage(ArcadeManager plugin, CakeResourceShop shop, Player player, CakeResource resource, List<CakeItem> items)
{
super(plugin, shop, plugin.GetClients(), plugin.GetDonation(), resource.getName() + " Shop", player, 27);
_resource = resource;
_items = items;
_teamData = plugin.GetGame().GetTeam(player).GetColorData();
buildPage();
_team = plugin.GetGame().GetTeam(player);
}
@Override
protected void buildPage()
{
addCloseButton();
int slot = 10;
for (CakeShopItem item : _items)
for (CakeItem item : _items)
{
addButton(slot++, prepareItem(item), new CakeShopButton(item));
addButton(slot, prepareItem(item), new CakeShopButton(item));
if (slot % 9 == 0)
if (++slot % 9 == 8)
{
slot += 2;
}
}
}
private ItemStack prepareItem(CakeShopItem item)
void addCloseButton()
{
addButton(4, CLOSE_ITEM, (player, clickType) -> player.closeInventory());
}
ItemStack prepareItem(CakeItem item)
{
ItemBuilder builder = new ItemBuilder(item.getItemStack());
boolean canPurchase = canPurchase(_player, item);
builder.setTitle((canPurchase ? C.cGreen : C.cRed) + ItemStackFactory.Instance.GetName(item.getItemStack(), true));
builder.setTitle(getItemName(item.getItemStack()));
builder.addLore(
"",
"Cost: " + item.getResource().getChatColor() + item.getCost() + " " + item.getResource().getName() + "s",
"Cost: " + _resource.getChatColor() + item.getCost() + " " + _resource.getName() + "s",
"",
canPurchase ? C.cGreen + "Click to purchase!" : C.cRed + "You do not have enough resources!"
);
if (builder.getType() == Material.WOOL)
{
builder.setData(_teamData);
builder.setData(_team.GetColorData());
}
return builder.build();
}
private boolean canPurchase(Player player, CakeShopItem item)
boolean canPurchase(Player player, CakeItem item)
{
ItemStack resource = item.getResource().getItemStack();
ItemStack resource = _resource.getItemStack();
return UtilInv.contains(player, resource.getType(), resource.getData().getData(), item.getCost());
}
String getItemName(ItemStack itemStack)
{
if (itemStack.hasItemMeta() && itemStack.getItemMeta().hasDisplayName())
{
return itemStack.getItemMeta().getDisplayName();
}
return ItemStackFactory.Instance.GetName(itemStack, true);
}
private class CakeShopButton implements IButton
{
private final CakeShopItem _item;
private final CakeItem _item;
CakeShopButton(CakeShopItem item)
CakeShopButton(CakeItem item)
{
_item = item;
}
@ -92,21 +119,54 @@ public class CakeResourcePage extends ShopPageBase<ArcadeManager, CakeResourceSh
@Override
public void onClick(Player player, ClickType clickType)
{
ItemStack resource = _item.getResource().getItemStack();
if (!Recharge.Instance.use(player, "Buy Item", 200, false, false))
{
return;
}
ItemStack resource = _resource.getItemStack();
ItemStack give = _item.getItemStack();
if (UtilInv.remove(player, resource.getType(), resource.getData().getData(), _item.getCost()))
{
give = give.clone();
give.getData().setData(_teamData);
if (give.getType() == Material.WOOL)
{
give = new ItemBuilder(give)
.setData(_team.GetColorData())
.build();
}
UtilInv.insert(player, give);
player.sendMessage(F.main("Game", "You purchased " + F.count(give.getAmount()) + " " + F.name(ItemStackFactory.Instance.GetName(give, true))));
playAcceptSound(player);
if (UtilItem.isHelmet(give))
{
player.getInventory().setHelmet(give);
}
else if (UtilItem.isChestplate(give))
{
player.getInventory().setChestplate(give);
}
else if (UtilItem.isLeggings(give))
{
player.getInventory().setLeggings(give);
}
else if (UtilItem.isBoots(give))
{
player.getInventory().setBoots(give);
}
else
{
player.sendMessage(F.main("Game", "You do not have enough " + F.name(_item.getResource().getName() + "s") + " to purchase this item."));
UtilInv.insert(player, give);
}
CakeTeam cakeTeam = ((CakeWars) _plugin.GetGame()).getCakeTeamModule().getCakeTeam(_team);
cakeTeam.applyUpgrades();
player.sendMessage(F.main("Game", "You purchased " + F.count(give.getAmount()) + " " + F.name(getItemName(give))) + ".");
playAcceptSound(player);
refresh();
}
else
{
player.sendMessage(F.main("Game", "You do not have enough " + F.name(_resource.getName() + "s") + " to purchase this item."));
playDenySound(player);
}
}

View File

@ -0,0 +1,144 @@
package nautilus.game.arcade.game.games.cakewars.ui;
import java.util.Arrays;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilText;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.recharge.Recharge;
import mineplex.core.shop.item.IButton;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.games.cakewars.CakeWars;
import nautilus.game.arcade.game.games.cakewars.data.CakeItem;
import nautilus.game.arcade.game.games.cakewars.data.CakeResource;
import nautilus.game.arcade.game.games.cakewars.data.CakeTeam;
import nautilus.game.arcade.game.games.cakewars.data.CakeTeamItem;
public class CakeResourceStarPage extends CakeResourcePage
{
private final CakeTeam _cakeTeam;
public CakeResourceStarPage(ArcadeManager plugin, CakeResourceShop shop, Player player)
{
super(plugin, shop, player, CakeResource.STAR, Arrays.asList(CakeTeamItem.values()));
CakeWars game = (CakeWars) plugin.GetGame();
_cakeTeam = game.getCakeTeamModule().getCakeTeam(game.GetTeam(player));
}
@Override
protected void buildPage()
{
addCloseButton();
int slot = 10;
for (CakeItem item : _items)
{
addButton(slot++, prepareItem(item), new CakeTeamItemButton((CakeTeamItem) item));
}
}
@Override
ItemStack prepareItem(CakeItem item)
{
CakeTeamItem teamItem = (CakeTeamItem) item;
ItemBuilder builder = new ItemBuilder(item.getItemStack());
int level = _cakeTeam.getUpgrades().get(item);
boolean canPurchase = canPurchase(_player, teamItem, level);
boolean maxTier = teamItem.getCosts().length == level;
builder.setTitle(C.mItem + teamItem.getName() + (maxTier ? "" : " " + UtilText.toRomanNumeral(level + 1)));
if (maxTier)
{
builder.addLore("", C.cRed + "You have already purchased the maximum", C.cRed + "tier for this upgrade.");
}
else
{
builder.addLore(
"",
"Cost: " + _resource.getChatColor() + teamItem.getCosts()[level] + " " + _resource.getName() + "s",
"",
canPurchase ? C.cGreen + "Click to purchase!" : C.cRed + "You do not have enough resources!"
);
}
return builder.build();
}
private boolean canPurchase(Player player, CakeTeamItem item, int level)
{
if (item.getCosts().length <= level)
{
return false;
}
ItemStack resource = _resource.getItemStack();
return UtilInv.contains(player, resource.getType(), resource.getData().getData(), item.getCosts()[level]);
}
private class CakeTeamItemButton implements IButton
{
private final CakeTeamItem _item;
private final int _level;
CakeTeamItemButton(CakeTeamItem item)
{
_item = item;
_level = _cakeTeam.getUpgrades().get(item);
}
@Override
public void onClick(Player player, ClickType clickType)
{
if (!Recharge.Instance.use(player, "Buy Team Upgrade", 200, false, false))
{
return;
}
ItemStack resource = _resource.getItemStack();
if (_item.getCosts().length == _level)
{
player.sendMessage(F.main("Game", "You have already purchased the maximum tier for this upgrade."));
return;
}
if (UtilInv.remove(player, resource.getType(), resource.getData().getData(), _item.getCosts()[_level]))
{
int newLevel = _level + 1;
String message = F.main("Game", F.color(_player.getName(), _cakeTeam.getGameTeam().GetColor().toString()) + " purchased the " + F.name(_item.getName() + " " + UtilText.toRomanNumeral(newLevel)) + " team upgrade.");
for (Player other : _cakeTeam.getGameTeam().GetPlayers(false))
{
other.playSound(other.getLocation(), Sound.NOTE_PLING, 1, 1.2F);
other.sendMessage(message);
_item.apply(other, newLevel);
}
_cakeTeam.getUpgrades().put(_item, newLevel);
playAcceptSound(player);
refresh();
}
else
{
player.sendMessage(F.main("Game", "You do not have enough " + F.name(_resource.getName() + "s") + " to purchase this item."));
playDenySound(player);
}
}
}
}

View File

@ -175,7 +175,7 @@ public class TowerManager implements Listener
{
_def.put(tower, new DefenderAI(this, tower));
/*int[] rgb;
if (tower.getTeam().GetColor() == red.GetColor())
if (tower.getGameTeam().GetColor() == red.GetColor())
rgb = redRGB;
else
rgb = blueRGB;
@ -216,8 +216,8 @@ public class TowerManager implements Listener
public void handleTowerDeath(TeamTowerBase towerBase)
{
towerBase.setVulnerable(false);
//ironOreGen(towerBase.getTeam());
/*for (Player player : towerBase.getTeam().GetPlayers(true))
//ironOreGen(towerBase.getGameTeam());
/*for (Player player : towerBase.getGameTeam().GetPlayers(true))
{
player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 20 * 60, 1));
}*/
@ -225,7 +225,7 @@ public class TowerManager implements Listener
{
public void run()
{
UtilTextMiddle.display("", towerBase.getTeam().GetColor() + towerBase.getTeam().getName() + " Team ores have been replenished!", UtilServer.getPlayers());
UtilTextMiddle.display("", towerBase.getGameTeam().GetColor() + towerBase.getGameTeam().getName() + " Team ores have been replenished!", UtilServer.getPlayers());
}
}, 20 * 5);*/
//_mapZone.get(towerBase).setValid(false);
@ -257,7 +257,7 @@ public class TowerManager implements Listener
//Host.Objective.setTeamObjective(enemy, new KillObjective());
//Host.TeamPoison.put(towerBase.getTeam(), System.currentTimeMillis() + (UtilTime.convert(5, TimeUnit.MINUTES, TimeUnit.MILLISECONDS) - UtilTime.convert(1, TimeUnit.SECONDS, TimeUnit.MILLISECONDS)));
//Host.TeamPoison.put(towerBase.getGameTeam(), System.currentTimeMillis() + (UtilTime.convert(5, TimeUnit.MINUTES, TimeUnit.MILLISECONDS) - UtilTime.convert(1, TimeUnit.SECONDS, TimeUnit.MILLISECONDS)));
return;
}

View File

@ -54,7 +54,6 @@ import nautilus.game.arcade.game.games.moba.buff.BuffManager;
import nautilus.game.arcade.game.games.moba.fountain.MobaFountain;
import nautilus.game.arcade.game.games.moba.general.ArrowKBManager;
import nautilus.game.arcade.game.games.moba.general.BetaManager;
import nautilus.game.arcade.game.games.moba.general.EnderPearlManager;
import nautilus.game.arcade.game.games.moba.general.MobaDamageManager;
import nautilus.game.arcade.game.games.moba.gold.GoldManager;
import nautilus.game.arcade.game.games.moba.kit.HeroKit;
@ -79,6 +78,7 @@ import nautilus.game.arcade.game.games.moba.structure.tower.TowerManager;
import nautilus.game.arcade.game.games.moba.training.MobaTraining;
import nautilus.game.arcade.game.games.moba.util.MobaUtil;
import nautilus.game.arcade.game.modules.CustomScoreboardModule;
import nautilus.game.arcade.game.modules.EnderPearlModule;
import nautilus.game.arcade.game.modules.capturepoint.CapturePointModule;
import nautilus.game.arcade.game.modules.compass.CompassModule;
import nautilus.game.arcade.kit.Kit;
@ -160,7 +160,9 @@ public class Moba extends TeamGame
registerManager(new HPManager(this));
registerManager(new MobaDamageManager(this));
registerManager(new MobaFountain(this));
registerManager(new EnderPearlManager());
new EnderPearlModule()
.setMaxTicks(40)
.register(this);
// Structures
_tower = registerManager(new TowerManager(this));

View File

@ -1,11 +1,11 @@
package nautilus.game.arcade.game.modules;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.games.moba.Moba;
import nautilus.game.arcade.scoreboard.GameScoreboard;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -18,11 +18,13 @@ import org.bukkit.scoreboard.Score;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.games.moba.Moba;
import nautilus.game.arcade.scoreboard.GameScoreboard;
/**
* CustomScoreboardModule allows for the use of per-player scoreboards in an Arcade game.
@ -151,6 +153,23 @@ public class CustomScoreboardModule extends Module
}
}
/**
* Updates the title animation of the scoreboard
*/
@EventHandler
public void updateTitle(UpdateEvent event)
{
if (event.getType() != UpdateType.FASTEST)
{
return;
}
for (CustomArcadeScoreboard scoreboard : _scoreboard.values())
{
scoreboard.updateTitle();
}
}
private void setupScoreboard(Player player)
{
UUID key = player.getUniqueId();

View File

@ -1,4 +1,17 @@
package nautilus.game.arcade.game.games.moba.general;
package nautilus.game.arcade.game.modules;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.entity.EnderPearl;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.projectiles.ProjectileSource;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
@ -6,31 +19,25 @@ import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import org.bukkit.Location;
import org.bukkit.entity.EnderPearl;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.projectiles.ProjectileSource;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class EnderPearlManager implements Listener
public class EnderPearlModule extends Module
{
private static final int MAX_TICKS = 2 * 20;
private final Map<Player, Projectile> _pearls;
public EnderPearlManager()
private int _maxTicks = Integer.MAX_VALUE;
public EnderPearlModule()
{
_pearls = new HashMap<>();
}
public EnderPearlModule setMaxTicks(int maxTicks)
{
_maxTicks = maxTicks;
return this;
}
@EventHandler
public void projectileLaunch(ProjectileLaunchEvent event)
{
@ -66,7 +73,7 @@ public class EnderPearlManager implements Listener
iterator.remove();
entity.remove();
}
else if (entity.getTicksLived() > MAX_TICKS)
else if (entity.getTicksLived() > _maxTicks)
{
teleport(shooter, entity);
entity.remove();
@ -96,5 +103,6 @@ public class EnderPearlManager implements Listener
toTeleport.setPitch(playerLocation.getPitch());
shooter.teleport(toTeleport);
shooter.setFallDistance(0);
}
}

View File

@ -55,7 +55,7 @@ public class CapturePoint
private int _progress;
private long _lastInform;
public CapturePoint(Game host, String name, ChatColor colour, Location center)
CapturePoint(Game host, String name, ChatColor colour, Location center)
{
_host = host;
_name = name;
@ -85,7 +85,7 @@ public class CapturePoint
}
Collections.shuffle(_wool);
_captureDist = highestDist * (double) MAX_RADIUS;
_captureDist = Math.pow(highestDist * (double) MAX_RADIUS + 0.5D, 2);
}
public void update()

View File

@ -87,6 +87,19 @@ public class CapturePointModule extends Module
return out.toString().trim();
}
public boolean isOnPoint(Location location)
{
for (CapturePoint point : _capturePoints)
{
if (point.isOnPoint(location))
{
return true;
}
}
return false;
}
public List<CapturePoint> getCapturePoints()
{
return _capturePoints;

View File

@ -1,17 +1,6 @@
package nautilus.game.arcade.scoreboard;
import mineplex.core.common.Pair;
import mineplex.core.common.util.C;
import mineplex.core.scoreboard.WritableMineplexScoreboard;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.GameTeam;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
@ -19,13 +8,33 @@ import java.util.List;
import java.util.Map;
import java.util.function.Function;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import mineplex.core.common.Pair;
import mineplex.core.common.util.C;
import mineplex.core.scoreboard.WritableMineplexScoreboard;
import mineplex.core.titles.tracks.custom.ScrollAnimation;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.GameTeam;
public class GameScoreboard extends WritableMineplexScoreboard
{
private Game _game;
private String _title;
private static final String[] TITLE = new ScrollAnimation(" MINEPLEX ")
.withPrimaryColour(ChatColor.GOLD)
.withSecondaryColour(ChatColor.YELLOW)
.withTertiaryColour(ChatColor.WHITE)
.bold()
.build();
private final Game _game;
private int _shineIndex;
private boolean _shineDirection = true;
public GameScoreboard(Game game)
{
@ -37,8 +46,7 @@ public class GameScoreboard extends WritableMineplexScoreboard
super(player);
_game = game;
_title = " MINEPLEX ";
setSidebarName(C.Bold + _title);
setSidebarName(TITLE[0]);
}
@Override
@ -61,50 +69,11 @@ public class GameScoreboard extends WritableMineplexScoreboard
public void updateTitle()
{
String out;
setSidebarName(TITLE[_shineIndex]);
if (_shineDirection)
{
out = C.cGold + C.Bold;
}
else
{
out = C.cWhite + C.Bold;
}
for (int i = 0; i < _title.length(); i++)
{
char c = _title.charAt(i);
if (_shineDirection)
{
if (i == _shineIndex)
out += C.cYellow + C.Bold;
if (i == _shineIndex + 1)
out += C.cWhite + C.Bold;
}
else
{
if (i == _shineIndex)
out += C.cYellow + C.Bold;
if (i == _shineIndex + 1)
out += C.cGold + C.Bold;
}
out += c;
}
setSidebarName(out);
_shineIndex++;
if (_shineIndex == _title.length() * 2)
if (++_shineIndex == TITLE.length)
{
_shineIndex = 0;
_shineDirection = !_shineDirection;
}
}
@ -177,7 +146,7 @@ public class GameScoreboard extends WritableMineplexScoreboard
private <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map)
{
List<Map.Entry<K, V>> list = new LinkedList<>(map.entrySet());
Collections.sort(list, (o1, o2) -> (o2.getValue()).compareTo(o1.getValue()));
list.sort((o1, o2) -> (o2.getValue()).compareTo(o1.getValue()));
Map<K, V> result = new LinkedHashMap<>();
for (Map.Entry<K, V> entry : list)