Fix CombatManager not keeping track of attackers

This commit is contained in:
Sam 2018-07-01 16:02:26 +01:00 committed by Alexander Meech
parent d418bb276e
commit 9a24cbb377
11 changed files with 89 additions and 61 deletions

View File

@ -546,7 +546,7 @@ public enum GameKit
"Every cake needs some frosting.",
C.blankLine,
receiveItem("Snowball", 1, 6, 3),
C.cGray + "Your " + C.cGreen + "Snowballs" + C.cGray + " slow enemies for " + C.cGreen + "3 seconds"
C.cGray + "Your " + C.cGreen + "Snowballs" + C.cGray + " slow enemies for " + C.cGreen + "2.5 seconds"
},
new KitEntityData<>
(

View File

@ -268,7 +268,7 @@ public class MissionManager extends MiniDbClientPlugin<MissionClient>
client.getMissions().forEach(mission ->
{
if (mission.getTrackerType() != trackerType || !mission.canProgress(game) || !mission.validateData(data) || !mission.validateY(y))
if (mission.getTrackerType() != trackerType || mission.hasRewarded() || !mission.canProgress(game) || !mission.validateData(data) || !mission.validateY(y))
{
return;
}
@ -297,8 +297,8 @@ public class MissionManager extends MiniDbClientPlugin<MissionClient>
MissionClient client = Get(player);
int started = 0;
started += selectNewMissions(player, client, MissionLength.DAY, 5);
started += selectNewMissions(player, client, MissionLength.WEEK, 3);
started += selectNewMissions(player, client, MissionLength.DAY, MAX_DAILY);
started += selectNewMissions(player, client, MissionLength.WEEK, MAX_WEEKLY);
for (MissionContext<?> context : getSelectableMissions(true))
{

View File

@ -493,12 +493,12 @@ public class MissionPopulator
.build();
MissionContext.<String>newBuilder(manager, 601)
.name("Golden Warrior")
.name("Does This Have Rocks In It?")
.description("Kill %s players with a Snowball")
.games(CakeWars4, CakeWarsDuos)
.xRange(1, 10)
.tracker(GAME_KILL)
.trackerData("Snowball")
.trackerData("Frosting")
.rewards(
new LevelExperienceReward(200),
new LevelCurrencyReward(GlobalCurrency.GEM, 100),

View File

@ -69,7 +69,7 @@ public class CombatComponent
public LinkedList<CombatDamage> GetDamage()
{
if (_damage == null)
_damage = new LinkedList<CombatDamage>();
_damage = new LinkedList<>();
return _damage;
}

View File

@ -15,9 +15,9 @@ import mineplex.minecraft.game.core.damage.DamageChange;
public class CombatLog
{
private LinkedList<CombatComponent> _damager = new LinkedList<CombatComponent>();
private CombatComponent _player;
private long _expireTime;
private final LinkedList<CombatComponent> _damager = new LinkedList<>();
private final CombatComponent _player;
private final long _expireTime;
private long _deathTime = 0;
private CombatComponent _killer;
@ -48,23 +48,20 @@ public class CombatLog
return _player;
}
public void Attacked(String damagerName, double damage,
LivingEntity damagerEnt, String attackName, List<DamageChange> mod)
public void Attacked(String damagerName, double damage, LivingEntity damagerEnt, String attackName, List<DamageChange> mod)
{
this.Attacked(damagerName, damage, damagerEnt, attackName, mod, new HashMap<>());
Attacked(damagerName, damage, damagerEnt, attackName, mod, new HashMap<>());
}
public void Attacked(String damagerName, double damage,
LivingEntity damagerEnt, String attackName, List<DamageChange> mod, Map<String, Object> metadata)
public void Attacked(String damagerName, double damage, LivingEntity damagerEnt, String attackName, List<DamageChange> mod, Map<String, Object> metadata)
{
// Add Attacked
CombatComponent comp = GetEnemy(damagerName, damagerEnt);
comp.AddDamage(attackName, damage, mod, metadata);
// Set Last
LastDamager = comp;
_lastDamaged = System.currentTimeMillis();
// _lastCombat = System.currentTimeMillis();
}
public CombatComponent GetEnemy(String name, LivingEntity ent)
@ -72,10 +69,13 @@ public class CombatLog
ExpireOld();
CombatComponent component = null;
for (CombatComponent cur : _damager)
{
if (cur.GetName().equals(name))
{
component = cur;
}
}
// Player has attacked in past
@ -83,16 +83,19 @@ public class CombatLog
{
_damager.remove(component);
_damager.addFirst(component);
return _damager.getFirst();
return component;
}
_damager.addFirst(new CombatComponent(name, ent));
return _damager.getFirst();
component = new CombatComponent(name, ent);
_damager.addFirst(component);
return component;
}
public void ExpireOld()
{
int expireFrom = -1;
for (int i = 0; i < _damager.size(); i++)
{
if (UtilTime.elapsed(_damager.get(i).GetLastDamage(), _expireTime))
@ -103,13 +106,17 @@ public class CombatLog
}
if (expireFrom != -1)
{
while (_damager.size() > expireFrom)
{
_damager.remove(expireFrom);
}
}
}
public LinkedList<String> Display()
{
LinkedList<String> out = new LinkedList<String>();
LinkedList<String> out = new LinkedList<>();
for (int i = 0; i < 8; i++)
{
@ -122,7 +129,7 @@ public class CombatLog
public LinkedList<String> DisplayAbsolute()
{
HashMap<Long, String> components = new HashMap<Long, String>();
Map<Long, String> components = new HashMap<>();
for (CombatComponent cur : _damager)
{
@ -133,7 +140,7 @@ public class CombatLog
}
int id = components.size();
LinkedList<String> out = new LinkedList<String>();
LinkedList<String> out = new LinkedList<>();
while (!components.isEmpty())
{

View File

@ -32,7 +32,6 @@ import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
@ -356,6 +355,7 @@ public class CombatManager extends MiniPlugin
}
log.SetDeathTime(System.currentTimeMillis());
log.ExpireOld();
// Save Death
Get(event.getEntity().getUniqueId()).GetDeaths().addFirst(log);
@ -366,7 +366,7 @@ public class CombatManager extends MiniPlugin
{
CombatComponent attacker = log.GetAttackers().get(i);
if (!attacker.IsPlayer() || UtilTime.elapsed(attacker.GetLastDamage(), ExpireTime))
if (!attacker.IsPlayer())
{
continue;
}
@ -489,7 +489,6 @@ public class CombatManager extends MiniPlugin
{
UtilPlayer.message(event.getEntity(), F.main(getName(), "You have died." + combatEvent.getSuffix()));
}
else
{
UtilPlayer.message(event.getEntity(), F.main(getName(), "You were " + combatEvent.getKilledWord() + " by " + F.name(log.GetAttackers().getFirst().GetName())) + C.mBody + "." + combatEvent.getSuffix());
@ -498,26 +497,9 @@ public class CombatManager extends MiniPlugin
}
}
@EventHandler
public void ExpireOld(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
return;
for (CombatLog log : _active.values())
log.ExpireOld();
}
public CombatLog Add(Player player)
{
CombatLog log = new CombatLog(player, ExpireTime);
_active.put(player.getUniqueId(), log);
return log;
}
public CombatLog Get(Player player)
{
return _active.getOrDefault(player.getUniqueId(), Add(player));
return _active.computeIfAbsent(player.getUniqueId(), k -> new CombatLog(player, ExpireTime));
}
@EventHandler(priority = EventPriority.HIGHEST)

View File

@ -537,7 +537,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
}
else if (_gameCreationManager.getVotingManager().isVoteInProgress())
{
scoreboard.setSidebarName(C.cGreenB + "Voting ends in " + _gameCreationManager.getVotingManager().getCurrentVote().getTimer());
scoreboard.setSidebarName(C.cGreenB + "Vote ends in " + _gameCreationManager.getVotingManager().getCurrentVote().getTimer());
}
else
{

View File

@ -55,13 +55,14 @@ import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.managers.LobbyEnt;
import nautilus.game.arcade.managers.voting.Vote;
public abstract class LobbyManager implements Listener
{
protected static final World WORLD = Bukkit.getWorld("world");
protected final ArcadeManager _manager;
protected final String _serverGroup;
private final Map<GameTeam, Location> _teamLocations;
private final Map<Entity, LobbyEnt> _teams;
@ -105,8 +106,6 @@ public abstract class LobbyManager implements Listener
_teamBlocks = Maps.newHashMap();
_kitBlocks = Maps.newHashMap();
_serverGroup = _manager.GetServerConfig().ServerGroup;
_generatePodiums = new File("world/GENPODIUMS.dat").exists() || manager.GetHost() != null;
if (_generatePodiums)
@ -432,9 +431,17 @@ public abstract class LobbyManager implements Listener
writeGameLine("waiting for players", 3, 159, (byte) 13);
}
public void displayVoting()
public void displayVoting(Vote vote)
{
writeGameLine("voting", 3, Material.STAINED_CLAY.getId(), (byte) 13);
writeGameLine("Voting for the next", 0, Material.STAINED_CLAY.getId(), (byte) 14);
writeGameLine(vote.getName(), 1, Material.STAINED_CLAY.getId(), (byte) 4);
displayVotingTime(vote);
}
public void displayVotingTime(Vote vote)
{
writeGameLine("Vote ends in " + vote.getTimer(), 3, Material.STAINED_CLAY.getId(), (byte) 13);
}
public void ScoreboardDisplay(UpdateEvent event)

View File

@ -97,6 +97,7 @@ public abstract class Vote<T extends Voteable>
public void removeVote(Player player)
{
vote(player, null);
player.closeInventory();
}
public T getWinner()

View File

@ -73,7 +73,7 @@ public class VotingManager extends ListenerComponent implements Lifetimed
player.getInventory().setItem(0, _currentVote.getItemStack());
}
_manager.GetLobby().displayVoting();
_manager.GetLobby().displayVoting(vote);
activate();
_lifetime.start();
@ -190,6 +190,8 @@ public class VotingManager extends ListenerComponent implements Lifetimed
{
_finishedVote = _currentVote;
}
_manager.GetLobby().displayVotingTime(_currentVote);
}
}

View File

@ -25,21 +25,50 @@ public class KillMissionTracker extends GameMissionTracker<Game>
public void playerDeath(CombatDeathEvent event)
{
Player player = event.GetEvent().getEntity();
Player killerPlayer;
String source = null;
CombatComponent killer = event.GetLog().GetKiller();
if (killer == null || !killer.IsPlayer())
if (killer != null)
{
killerPlayer = UtilPlayer.searchExact(killer.getUniqueIdOfEntity());
source = killer.GetLastDamageSource();
Bukkit.broadcastMessage("Set killer " + killer.GetName() + " " + source);
}
else
{
Bukkit.broadcastMessage("Killer was not player");
killerPlayer = player.getKiller();
if (killerPlayer == null)
{
Bukkit.broadcastMessage("Null Killer");
return;
}
else
{
for (CombatComponent attacker : event.GetLog().GetAttackers())
{
Bukkit.broadcastMessage("Attacker " + attacker.GetName());
if (attacker.IsPlayer() && attacker.getUniqueIdOfEntity().equals(killerPlayer.getUniqueId()))
{
killerPlayer = UtilPlayer.searchExact(attacker.getUniqueIdOfEntity());
source = attacker.GetLastDamageSource();
Bukkit.broadcastMessage("Set killer " + killerPlayer.getName() + " " + source);
break;
}
}
}
}
if (killerPlayer == null || source == null || player.equals(killerPlayer))
{
Bukkit.broadcastMessage("Null Killer - END");
return;
}
Player killerPlayer = UtilPlayer.searchExact(killer.getUniqueIdOfEntity());
if (killerPlayer == null || player.equals(killerPlayer))
{
return;
}
Bukkit.broadcastMessage(killer.GetLastDamageSource());
_manager.incrementProgress(killerPlayer, 1, _trackerType, getGameType(), ChatColor.stripColor(killer.GetLastDamageSource()));
Bukkit.broadcastMessage("increment " + ChatColor.stripColor(source));
_manager.incrementProgress(killerPlayer, 1, _trackerType, getGameType(), ChatColor.stripColor(source));
}
}