Bug fixes and improvements

This commit is contained in:
Sam 2017-10-18 14:20:52 +01:00 committed by Alexander Meech
parent 3fd18c1416
commit b32b242e5a
13 changed files with 145 additions and 68 deletions

View File

@ -2,7 +2,6 @@ package mineplex.core.common.util;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.util.Vector;
@ -22,12 +21,6 @@ public class UtilColor
public static final Color DEFAULT_LEATHER_COLOR = Color.fromRGB(160, 101, 64);
public static byte chatColorToClayData(ChatColor chatColor)
{
//TODO
return 1;
}
public static byte chatColorToWoolData(ChatColor chatColor)
{
switch (chatColor)

View File

@ -165,6 +165,12 @@ class NewNPCRepository extends RepositoryBase
*/
void deleteNPC(NPC npc)
{
// If the id is -1 then it has never been inserted
if (npc.getId() == -1)
{
return;
}
executeUpdate(DELETE_NPC, new ColumnInt("id", npc.getId()));
}

View File

@ -1283,10 +1283,7 @@ public abstract class Game extends ListenerComponent implements Lifetimed
GameTeam team = GetTeam(player);
if (team == null)
return false;
return team.IsAlive(player);
return team != null && team.IsAlive(player);
}
return false;

View File

@ -23,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.AbsorptionFix;
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;
@ -57,7 +58,7 @@ public class CakeWars extends TeamGame
"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 center 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."
};
@ -97,6 +98,8 @@ public class CakeWars extends TeamGame
manager.GetCreature().SetDisableCustomDrops(true);
new AbsorptionFix(this);
new CompassModule()
.register(this);
@ -113,7 +116,7 @@ public class CakeWars extends TeamGame
.register();
_cakeShopModule = new CakeShopModule(this);
_cakeTeamModule.register();
_cakeShopModule.register();
_cakePointModule = new CakePointModule(this);
_cakePointModule.register();
@ -168,8 +171,6 @@ public class CakeWars extends TeamGame
{
scoreboard.writeNewLine();
GameTeam playerTeam = GetTeam(player);
scoreboard.write(C.cYellowB + "Teams");
for (GameTeam team : GetTeamList())
@ -193,11 +194,6 @@ public class CakeWars extends TeamGame
teamLine += " " + team.GetFormattedName();
if (playerTeam != null && playerTeam.equals(team))
{
teamLine += C.Reset + " " + C.cYellowB + "";
}
scoreboard.write(teamLine);
}
@ -236,11 +232,11 @@ public class CakeWars extends TeamGame
int i = 1;
for (Location location : WorldData.GetDataLocs("SILVER"))
{
WorldData.GetAllCustomLocs().computeIfAbsent("POINT Emerald-" + i++ + " GREEN", k -> new ArrayList<>()).add(location);
WorldData.GetAllCustomLocs().computeIfAbsent("POINT Outer-" + i++ + " GREEN", k -> new ArrayList<>()).add(location);
}
for (Location location : WorldData.GetDataLocs("WHITE"))
{
WorldData.GetAllCustomLocs().computeIfAbsent("POINT Nether-Star GOLD", k -> new ArrayList<>()).add(location);
WorldData.GetAllCustomLocs().computeIfAbsent("POINT Center GOLD", k -> new ArrayList<>()).add(location);
}
}

View File

@ -91,7 +91,7 @@ public class CakeTeam
public boolean canRespawn()
{
return _cake.getBlock().getType() != Material.AIR;
return _cake.getBlock().getType() == Material.CAKE_BLOCK;
}
public Location getCake()

View File

@ -42,10 +42,12 @@ 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")
.setUnbreakable(true)
.build();
static final ItemStack DEPLOY_PLATFORM = new ItemBuilder(Material.INK_SACK, (byte) 11)
static final ItemStack DEPLOY_PLATFORM = new ItemBuilder(Material.INK_SACK)
.setTitle(C.cYellowB + "Deploy Platform")
.addLore("", "Creates a platform of wool next to", "any block you click!", "Uses: " + C.cRed + "1")
.setUnbreakable(true)
.build();
private static final int PLATFORM_DELTA = 1;
@ -138,7 +140,7 @@ public class CakePlayerModule extends CakeModule
{
Player player = event.getEntity();
if (UtilInv.remove(player, RUNE_OF_HOLDING.getType(), RUNE_OF_HOLDING.getData().getData(), 1))
if (UtilInv.contains(player, RUNE_OF_HOLDING.getType(), RUNE_OF_HOLDING.getData().getData(), 1))
{
_game.getArcadeManager().runSyncLater(() ->
{
@ -172,7 +174,9 @@ public class CakePlayerModule extends CakeModule
inventory.setContents(storedInventory[0]);
inventory.setArmorContents(storedInventory[1]);
player.updateInventory();
}, 1);
UtilInv.remove(player, RUNE_OF_HOLDING.getType(), RUNE_OF_HOLDING.getData().getData(), 1);
}, 5);
}
}
@ -194,7 +198,7 @@ public class CakePlayerModule extends CakeModule
ItemStack itemStack = player.getItemInHand();
Block block = event.getClickedBlock();
if (UtilPlayer.isSpectator(player) || itemStack == null || !itemStack.isSimilar(DEPLOY_PLATFORM) || block == null)
if (UtilPlayer.isSpectator(player) || itemStack == null || itemStack.getType() != Material.INK_SACK || block == null)
{
return;
}
@ -212,7 +216,7 @@ public class CakePlayerModule extends CakeModule
Location nearbyLocation = nearby.getLocation();
if (nearby.getType() != Material.AIR || _game.getCapturePointModule().isOnPoint(nearbyLocation) || _game.getCakeShopModule().isNearShop(nearbyLocation))
if (!UtilBlock.airFoliage(nearby) || _game.getCapturePointModule().isOnPoint(nearbyLocation) || _game.getCakeShopModule().isNearShop(nearbyLocation))
{
continue;
}

View File

@ -28,7 +28,7 @@ public class CakePointModule extends CakeModule
for (Player player : team.GetPlayers(true))
{
_game.AddGems(player, 2, "Beacons captured", true, true);
_game.AddGems(player, 2, "Team - Beacons captured", true, true);
}
}

View File

@ -132,6 +132,14 @@ public class CakeShopModule extends CakeModule
));
}
@Override
public void cleanup()
{
_npcs.keySet().forEach(_manager::deleteNPC);
_npcs.clear();
_items.clear();
}
@EventHandler
public void prepare(GameStateChangeEvent event)
{

View File

@ -10,15 +10,19 @@ import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.F;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.hologram.Hologram;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
@ -36,7 +40,15 @@ 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 static final ItemStack[] STARTING_ITEMS =
{
new ItemBuilder(Material.WOOD_SWORD)
.setUnbreakable(true)
.build(),
new ItemBuilder(Material.BOW)
.setUnbreakable(true)
.build()
};
private final Map<GameTeam, CakeTeam> _teams;
@ -152,11 +164,13 @@ public class CakeTeamModule extends CakeModule
return;
}
if (!Recharge.Instance.use(player, "Eat Cake", 500, true, false))
if (!Recharge.Instance.use(player, "Eat Cake", 500, false, false))
{
return;
}
_game.AddGems(player, 4, "Cake Bites", true, true);
byte data = block.getData();
if (data < 6)
@ -168,9 +182,6 @@ 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, "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]));
}
@ -193,13 +204,13 @@ public class CakeTeamModule extends CakeModule
@EventHandler
public void kitGiveItems(PlayerKitGiveEvent event)
{
if (!_game.IsLive())
if (!_game.InProgress())
{
return;
}
Player player = event.getPlayer();
player.getInventory().addItem(STARTING_SWORD);
player.getInventory().addItem(STARTING_ITEMS);
_teams.get(_game.GetTeam(player)).getUpgrades().forEach((item, level) ->
{
@ -210,6 +221,27 @@ public class CakeTeamModule extends CakeModule
});
}
@EventHandler(priority = EventPriority.LOWEST)
public void playerQuit(PlayerQuitEvent event)
{
GameTeam team = _game.GetTeam(event.getPlayer());
if (team == null || team.GetPlayers(true).size() > 1)
{
return;
}
CakeTeam cakeTeam = _teams.get(team);
if (cakeTeam.canRespawn())
{
return;
}
MapUtil.QuickChangeBlockAt(cakeTeam.getCake(), Material.AIR);
_game.Announce(F.main("Game", F.name(team.GetFormattedName()) + "'s cake has been eaten! All their players have quit."));
}
public CakeTeam getCakeTeam(GameTeam team)
{
return _teams.get(team);

View File

@ -2,8 +2,8 @@ package nautilus.game.arcade.game.games.cakewars.ui;
import java.util.List;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
@ -32,14 +32,16 @@ public class CakeResourcePage extends ShopPageBase<ArcadeManager, CakeResourceSh
.setTitle(C.cRedB + "Close")
.build();
final CakeWars _game;
final CakeResource _resource;
final List<CakeItem> _items;
private final GameTeam _team;
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);
_game = (CakeWars) plugin.GetGame();
_resource = resource;
_items = items;
_team = plugin.GetGame().GetTeam(player);
@ -73,6 +75,8 @@ public class CakeResourcePage extends ShopPageBase<ArcadeManager, CakeResourceSh
ItemBuilder builder = new ItemBuilder(item.getItemStack());
boolean canPurchase = canPurchase(_player, item);
handleTeamColours(builder);
builder.setTitle(getItemName(item.getItemStack()));
builder.addLore(
"",
@ -81,22 +85,29 @@ public class CakeResourcePage extends ShopPageBase<ArcadeManager, CakeResourceSh
canPurchase ? C.cGreen + "Click to purchase!" : C.cRed + "You do not have enough resources!"
);
return builder.build();
}
private void handleTeamColours(ItemBuilder builder)
{
if (builder.getType() == Material.WOOL)
{
builder.setData(_team.GetColorData());
}
return builder.build();
else if (builder.getType() == Material.INK_SACK)
{
builder.setData(DyeColor.getByWoolData(_team.GetColorData()).getDyeData());
}
}
boolean canPurchase(Player player, CakeItem item)
private boolean canPurchase(Player player, CakeItem item)
{
ItemStack resource = _resource.getItemStack();
return UtilInv.contains(player, resource.getType(), resource.getData().getData(), item.getCost());
}
String getItemName(ItemStack itemStack)
private String getItemName(ItemStack itemStack)
{
if (itemStack.hasItemMeta() && itemStack.getItemMeta().hasDisplayName())
{
@ -119,48 +130,46 @@ public class CakeResourcePage extends ShopPageBase<ArcadeManager, CakeResourceSh
@Override
public void onClick(Player player, ClickType clickType)
{
if (!Recharge.Instance.use(player, "Buy Item", 200, false, false))
if (!Recharge.Instance.use(player, "Buy Item", 250, false, false))
{
return;
}
ItemStack resource = _resource.getItemStack();
ItemStack give = _item.getItemStack();
ItemBuilder give = new ItemBuilder(_item.getItemStack())
.setUnbreakable(true);
if (UtilInv.remove(player, resource.getType(), resource.getData().getData(), _item.getCost()))
{
if (give.getType() == Material.WOOL)
{
give = new ItemBuilder(give)
.setData(_team.GetColorData())
.build();
}
handleTeamColours(give);
if (UtilItem.isHelmet(give))
ItemStack giveItem = give.build();
if (UtilItem.isHelmet(giveItem))
{
player.getInventory().setHelmet(give);
player.getInventory().setHelmet(giveItem);
}
else if (UtilItem.isChestplate(give))
else if (UtilItem.isChestplate(giveItem))
{
player.getInventory().setChestplate(give);
player.getInventory().setChestplate(giveItem);
}
else if (UtilItem.isLeggings(give))
else if (UtilItem.isLeggings(giveItem))
{
player.getInventory().setLeggings(give);
player.getInventory().setLeggings(giveItem);
}
else if (UtilItem.isBoots(give))
else if (UtilItem.isBoots(giveItem))
{
player.getInventory().setBoots(give);
player.getInventory().setBoots(giveItem);
}
else
{
UtilInv.insert(player, give);
UtilInv.insert(player, giveItem);
}
CakeTeam cakeTeam = ((CakeWars) _plugin.GetGame()).getCakeTeamModule().getCakeTeam(_team);
CakeTeam cakeTeam = _game.getCakeTeamModule().getCakeTeam(_team);
cakeTeam.applyUpgrades();
player.sendMessage(F.main("Game", "You purchased " + F.count(give.getAmount()) + " " + F.name(getItemName(give))) + ".");
player.sendMessage(F.main("Game", "You purchased " + F.name(getItemName(giveItem))) + ".");
playAcceptSound(player);
refresh();
}

View File

@ -1,6 +1,9 @@
package nautilus.game.arcade.game.games.cakewars.ui;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import mineplex.core.shop.ShopBase;
import mineplex.core.shop.page.ShopPageBase;
@ -15,6 +18,15 @@ public class CakeResourceShop extends ShopBase<ArcadeManager>
super(plugin, plugin.GetClients(), plugin.GetDonation(), "Cake Wars Shop");
}
@EventHandler
public void inventoryClick(InventoryClickEvent event)
{
if (isPlayerInShop(event.getWhoClicked()))
{
event.setCancelled(true);
}
}
@Override
protected ShopPageBase<ArcadeManager, ? extends ShopBase<ArcadeManager>> buildPagesFor(Player player)
{

View File

@ -16,7 +16,6 @@ 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;
@ -31,9 +30,7 @@ public class CakeResourceStarPage extends CakeResourcePage
{
super(plugin, shop, player, CakeResource.STAR, Arrays.asList(CakeTeamItem.values()));
CakeWars game = (CakeWars) plugin.GetGame();
_cakeTeam = game.getCakeTeamModule().getCakeTeam(game.GetTeam(player));
_cakeTeam = _game.getCakeTeamModule().getCakeTeam(_game.GetTeam(player));
}
@Override
@ -105,7 +102,7 @@ public class CakeResourceStarPage extends CakeResourcePage
@Override
public void onClick(Player player, ClickType clickType)
{
if (!Recharge.Instance.use(player, "Buy Team Upgrade", 200, false, false))
if (!Recharge.Instance.use(player, "Buy Team Upgrade", 250, false, false))
{
return;
}
@ -121,9 +118,9 @@ public class CakeResourceStarPage extends CakeResourcePage
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.");
String message = F.main("Game", F.color(_player.getName(), _team.GetColor().toString()) + " purchased the " + F.name(_item.getName() + " " + UtilText.toRomanNumeral(newLevel)) + " team upgrade.");
for (Player other : _cakeTeam.getGameTeam().GetPlayers(false))
for (Player other : _team.GetPlayers(false))
{
other.playSound(other.getLocation(), Sound.NOTE_PLING, 1, 1.2F);
other.sendMessage(message);

View File

@ -5,18 +5,24 @@ import java.util.Iterator;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.Material;
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.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.projectiles.ProjectileSource;
import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilEvent.ActionType;
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.UtilPlayer;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
@ -38,6 +44,23 @@ public class EnderPearlModule extends Module
return this;
}
@EventHandler
public void interactEnderPearl(PlayerInteractEvent event)
{
if (!UtilEvent.isAction(event, ActionType.R))
{
return;
}
Player player = event.getPlayer();
ItemStack itemStack = player.getItemInHand();
if (itemStack != null && itemStack.getType() == Material.ENDER_PEARL && !Recharge.Instance.use(player, "Ender Pearl", 500, false, false))
{
event.setCancelled(true);
}
}
@EventHandler
public void projectileLaunch(ProjectileLaunchEvent event)
{