Lots of bug fixes

This commit is contained in:
Sam 2017-07-18 20:12:38 +01:00 committed by cnr
parent fb28a953e6
commit 8516a98087
10 changed files with 135 additions and 101 deletions

View File

@ -2,21 +2,16 @@ package mineplex.core.imagemap;
import mineplex.core.MiniPlugin;
import mineplex.core.ReflectivelyCreateMiniPlugin;
import mineplex.core.common.util.FileUtil;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilServer;
import mineplex.core.imagemap.objects.PlayerMapBoard;
import mineplex.core.imagemap.objects.PlayerMapImage;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.utils.UtilScheduler;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -65,7 +60,7 @@ public class ImageMapManager extends MiniPlugin
{
Player player = event.getPlayer();
runSyncLater(() -> _boards.forEach(board -> board.onPlayerJoin(player)), 50);
runSyncLater(() -> _boards.forEach(board -> board.onPlayerJoin(player)), 40);
}
@EventHandler
@ -73,13 +68,13 @@ public class ImageMapManager extends MiniPlugin
{
Player player = event.getPlayer();
_boards.forEach(board -> board.getImages().forEach(image -> image.removeViewer(player)));
_boards.forEach(board -> board.onPlayerQuit(player));
}
@EventHandler
public void refreshBoards(UpdateEvent event)
{
if (event.getType() != UpdateType.SLOWER)
if (event.getType() != UpdateType.TWOSEC)
{
return;
}
@ -256,11 +251,6 @@ public class ImageMapManager extends MiniPlugin
}
}
board.getImages().forEach(image ->
{
image.getViewers().clear();
image.getItemFrames().forEach(Entity::remove);
image.getItemFrames().clear();
});
board.cleanup();
}
}

View File

@ -3,11 +3,12 @@ package mineplex.core.imagemap.objects;
import mineplex.core.common.util.UtilMath;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.util.HashSet;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.Map;
public class PlayerMapBoard
{
@ -16,66 +17,74 @@ public class PlayerMapBoard
private final Location _location;
private final List<PlayerMapImage> _images;
private final Set<Player> _viewers;
private final Map<Player, Integer> _viewers;
public PlayerMapBoard(Location location, List<PlayerMapImage> images)
{
_location = location;
_images = images;
_viewers = new HashSet<>();
_viewers = new HashMap<>();
}
public void goTo(Player player, boolean next)
{
int i = 0;
for (PlayerMapImage image : _images)
if (!_viewers.containsKey(player))
{
if (image.getViewers().contains(player))
{
if (next && _images.size() - 1 == i)
{
i = -1;
}
else if (!next && i == 0)
{
i = _images.size();
}
image.removeViewer(player);
_images.get(next ? i + 1 : i - 1).addViewer(player);
return;
}
i++;
return;
}
int index = _viewers.get(player);
if (next && _images.size() - 1 == index)
{
index = -1;
}
else if (!next && index == 0)
{
index = _images.size();
}
int newIndex = next ? index + 1 : index - 1;
_viewers.put(player, newIndex);
_images.get(newIndex).addViewer(player, true);
}
public void onPlayerJoin(Player player)
{
_images.get(0).addViewer(player);
_viewers.put(player, 0);
_images.get(0).addViewer(player, true);
}
public void onPlayerQuit(Player player)
{
_viewers.remove(player);
}
public void onRefresh()
{
Bukkit.getOnlinePlayers().forEach(player ->
{
if (UtilMath.offset2dSquared(player.getLocation(), _location) < VIEW_DIST_SQUARED)
if (player.getWorld().equals(_location.getWorld()) && UtilMath.offset2dSquared(player.getLocation(), _location) < VIEW_DIST_SQUARED && _viewers.containsKey(player))
{
_viewers.add(player);
int index = _viewers.get(player);
_images.get(index).addViewer(player, false);
}
});
}
public void cleanup()
{
_viewers.clear();
_images.forEach(image ->
{
image.getItemFrames().forEach(Entity::remove);
image.getItemFrames().clear();
});
}
public Location getLocation()
{
return _location;
}
public List<PlayerMapImage> getImages()
{
return _images;
}
}

View File

@ -16,7 +16,6 @@ public class PlayerMapImage extends MapImage
private final CustomItemFrames _itemFramesManager;
private final List<ItemStack> _itemMaps;
private final List<Player> _viewers;
public PlayerMapImage(CustomItemFrames itemFramesManager, BufferedImage image, List<ItemFrame> itemFrames, int width, int height)
{
@ -24,7 +23,6 @@ public class PlayerMapImage extends MapImage
_itemFramesManager = itemFramesManager;
_itemMaps = new ArrayList<>();
_viewers = new ArrayList<>();
}
@Override
@ -46,22 +44,20 @@ public class PlayerMapImage extends MapImage
return _itemFrames;
}
public void addViewer(Player player)
public void addViewer(Player player, boolean sendMap)
{
if (!_viewers.add(player))
if (sendMap)
{
return;
}
//FIXME
int slot = 8;
for (ItemStack itemStack : _itemMaps)
{
player.getInventory().setItem(slot++, itemStack);
}
//FIXME
int slot = 8;
for (ItemStack itemStack : _itemMaps)
{
player.getInventory().setItem(slot++, itemStack);
UtilServer.runSyncLater(() -> player.getInventory().removeItem(_itemMaps.toArray(new ItemStack[0])), 5);
}
UtilServer.runSyncLater(() -> player.getInventory().removeItem(_itemMaps.toArray(new ItemStack[0])), 5);
for (int i = 0; i < _itemMaps.size(); i++)
{
ItemFrame itemFrame = _itemFrames.get(i);
@ -70,14 +66,4 @@ public class PlayerMapImage extends MapImage
_itemFramesManager.setItem(player, itemFrame, itemStack);
}
}
public void removeViewer(Player player)
{
_viewers.remove(player);
}
public List<Player> getViewers()
{
return _viewers;
}
}

View File

@ -15,7 +15,6 @@ import mineplex.core.imagemap.objects.PlayerMapBoard;
import mineplex.core.leaderboard.Leaderboard;
import mineplex.core.leaderboard.LeaderboardManager;
import mineplex.core.leaderboard.LeaderboardRepository.LeaderboardSQLType;
import mineplex.core.stats.event.StatChangeEvent;
import mineplex.minecraft.game.core.combat.DeathMessageType;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;

View File

@ -25,6 +25,7 @@ import nautilus.game.arcade.kit.Perk;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
@ -217,27 +218,6 @@ public class HeroKit extends Kit
{
inventory.setBoots(itemstack);
}
// Give consumable items
else if (!UtilItem.isSword(itemstack) && !UtilGear.isBow(itemstack))
{
// Keep moving left from the ammo slot until a free slot is available
for (int i = AMMO_SLOT - 1; i >= GetPerks().length - 1; i--)
{
ItemStack consumable = inventory.getItem(i);
if (consumable == null)
{
inventory.setItem(i, itemstack);
break;
}
else if (consumable.isSimilar(itemstack))
{
consumable.setAmount(consumable.getAmount() + 1);
break;
}
}
}
}
// Give all skill related items
@ -267,6 +247,40 @@ public class HeroKit extends Kit
super.GiveItemsCall(player);
disguise(player);
giveConsumables(player);
}
public void giveConsumables(Player player)
{
Inventory inventory = player.getInventory();
Moba game = (Moba) Manager.GetGame();
List<MobaItem> items = game.getShop().getOwnedItems(player);
for (MobaItem item : items)
{
ItemStack itemStack = item.getItem();
// Give consumable items
if (itemStack.getType() == Material.POTION || itemStack.getType() == Material.ENDER_PEARL)
{
// Keep moving left from the ammo slot until a free slot is available
for (int i = AMMO_SLOT - 1; i >= GetPerks().length - 1; i--)
{
ItemStack consumable = inventory.getItem(i);
if (consumable == null)
{
inventory.setItem(i, itemStack);
break;
}
else if (consumable.isSimilar(itemStack))
{
consumable.setAmount(consumable.getAmount() + 1);
break;
}
}
}
}
}
public void disguise(Player player)

View File

@ -9,6 +9,7 @@ import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.common.util.UtilTime;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.events.PlayerKitGiveEvent;
@ -185,8 +186,17 @@ public class HeroSkill extends Perk
return false;
}
return itemStack.isSimilar(_item);
if (itemStack.isSimilar(_item))
{
if (_dropItemActivate && !Recharge.Instance.use(player, "Ultimate", _cooldown, false, false))
{
return false;
}
return true;
}
return false;
}
protected boolean isSkillSneak(PlayerToggleSneakEvent event)
@ -248,7 +258,7 @@ public class HeroSkill extends Perk
}
game.Announce(team.GetColor() + C.Bold + player.getName() + " " + kit.getRole().getChatColor() + kit.GetName() + C.cWhiteB + " activated their " + team.GetColor() + C.Bold + GetName() + C.cWhiteB + ".", false);
player.getWorld().playSound(player.getLocation(), Sound.NOTE_PLING, 10, 0.5F);
player.getWorld().playSound(player.getLocation(), Sound.NOTE_PLING, 1, 0.5F);
}
@EventHandler
@ -386,7 +396,6 @@ public class HeroSkill extends Perk
GameTeam team = Manager.GetGame().GetTeam((Player) damager);
return team != null && MobaUtil.isTeamEntity(damagee, team);
}
public int getSlot()

View File

@ -41,16 +41,18 @@ public class MobaProgression implements Listener
{
private static final int[] EXP_LEVELS;
private static final int EXP_PER_LEVEL = 1000;
private static final int EXP_FACTOR = 3;
public static final DecimalFormat FORMAT = new DecimalFormat("0.0");
static
{
EXP_LEVELS = new int[100];
int expRequired = 2000;
int expRequired = EXP_PER_LEVEL;
for (int level = 0; level < 100; level++)
{
EXP_LEVELS[level] = expRequired += 2000;
EXP_LEVELS[level] = expRequired += EXP_PER_LEVEL;
}
}
@ -199,6 +201,7 @@ public class MobaProgression implements Listener
int level = getLevel(player, role);
return getExperience(level) - getExperience(level - 1);
}
public int getLevel(Player player, HeroKit kit)
{
return getLevel(player, kit.getRole());
@ -238,6 +241,8 @@ public class MobaProgression implements Listener
earnedExp.getAndAdd((int) data.Gems);
}
earnedExp.getAndAdd(earnedExp.get() * EXP_FACTOR);
int level = getLevel(currentExp);
int newLevel = getLevel(currentExp + earnedExp.get());
long expForThisLevel = getExperienceCurrentLevel(player, role);

View File

@ -19,12 +19,14 @@ import nautilus.game.arcade.game.games.moba.MobaPlayer;
import nautilus.game.arcade.game.games.moba.MobaRole;
import nautilus.game.arcade.game.games.moba.kit.AmmoGiveEvent;
import nautilus.game.arcade.game.games.moba.kit.CooldownCalculateEvent;
import nautilus.game.arcade.game.games.moba.kit.HeroKit;
import nautilus.game.arcade.game.games.moba.kit.hp.MobaHPRegenEvent;
import nautilus.game.arcade.game.games.moba.shop.assassin.MobaAssassinShop;
import nautilus.game.arcade.game.games.moba.shop.hunter.MobaHunterShop;
import nautilus.game.arcade.game.games.moba.shop.mage.MobaMageShop;
import nautilus.game.arcade.game.games.moba.shop.warrior.MobaWarriorShop;
import nautilus.game.arcade.game.games.moba.util.MobaConstants;
import nautilus.game.arcade.kit.Kit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
@ -210,10 +212,11 @@ public class MobaShop implements Listener
// The respawn event needs to be called here so that effects like "Total Health Increase" will work straight away, instead of after the next respawn,
// Prevents infinite speed
double currentHealth = player.getHealth();
player.setWalkSpeed(0.2F);
player.setMaxHealth(20);
PlayerGameRespawnEvent fakeEvent = new PlayerGameRespawnEvent(null, player);
PlayerGameRespawnEvent fakeEvent = new PlayerGameRespawnEvent(_host, player);
for (MobaItem ownedItem : owned)
{
@ -223,13 +226,20 @@ public class MobaShop implements Listener
}
}
_host.GetKit(player).GiveItems(player);
HeroKit kit = (HeroKit) _host.GetKit(player);
// If we aren't tracking purchases then after we give the item remove it.
if (!category.isTrackingPurchases())
if (category.isTrackingPurchases())
{
kit.GiveItems(player);
}
else
{
kit.giveConsumables(player);
owned.remove(item);
}
player.setHealth(Math.min(currentHealth, player.getMaxHealth()));
}
public boolean ownsItem(Player player, MobaItem item)

View File

@ -2,6 +2,7 @@ package nautilus.game.arcade.game.games.moba.training;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilTime;
@ -522,4 +523,15 @@ public class MobaTraining extends Moba
SetPlayerTeam(player, GetTeam(ChatColor.YELLOW), true);
SetKit(player, kit, true);
}
@EventHandler
public void informLobbyPlayers(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC_20 || InProgress())
{
return;
}
Announce(F.main("Game", "Waiting for more players before starting the training area."), false);
}
}

View File

@ -171,7 +171,7 @@ public class GameChatManager implements Listener
event.setFormat(dead + levelStr + rankStr + _manager.GetColor(sender) + senderName + " " + C.cWhite + "%2$s");
//Public/Private (Not If Player Dead)
if (_manager.GetGame() != null && _manager.GetGame().GetState() == GameState.Live)
if (_manager.GetGame() != null && _manager.GetGame().InProgress())
{
boolean globalMessage = false;