fix team-switch kit not always switching teams
This commit is contained in:
parent
9380f72614
commit
0f664153ec
|
@ -236,7 +236,7 @@ public class BlitzMatchModuleImpl extends MatchModule implements BlitzMatchModul
|
|||
.stream()
|
||||
.filter(this::eliminated)
|
||||
.forEach(eliminated -> {
|
||||
match.setPlayerParty(eliminated, match.getDefaultParty());
|
||||
match.setPlayerParty(eliminated, match.getDefaultParty(), false);
|
||||
world.spawnParticle(Particle.SMOKE_LARGE, eliminated.getLocation(), 5);
|
||||
});
|
||||
victory.invalidateAndCheckEnd();
|
||||
|
|
|
@ -215,7 +215,7 @@ public class FreeForAllMatchModule extends MatchModule implements Listener, Join
|
|||
kickMe.sendMessage(Links.shopPlug("shop.plug.ffa.neverKicked"));
|
||||
kickMe.playSound(Sound.ENTITY_VILLAGER_HURT, kickMe.getBukkit().getLocation(), 1, 1);
|
||||
|
||||
getMatch().setPlayerParty(kickMe, getMatch().getDefaultParty());
|
||||
getMatch().setPlayerParty(kickMe, getMatch().getDefaultParty(), false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -281,7 +281,7 @@ public class FreeForAllMatchModule extends MatchModule implements Listener, Join
|
|||
joining.sendWarning(new TranslatableComponent("command.gameplay.join.alreadyJoined"), false);
|
||||
}
|
||||
|
||||
return getMatch().setPlayerParty(joining, getTribute(joining));
|
||||
return getMatch().setPlayerParty(joining, getTribute(joining), false);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
|
|
|
@ -179,7 +179,7 @@ public class JoinMatchModule extends MatchModule implements Listener, JoinHandle
|
|||
public boolean observe(MatchPlayer leaving) {
|
||||
final Party observers = getMatch().getDefaultParty();
|
||||
leaving.sendMessage(new TranslatableComponent("team.join", observers.getComponentName()));
|
||||
return getMatch().setPlayerParty(leaving, observers);
|
||||
return getMatch().setPlayerParty(leaving, observers, false);
|
||||
}
|
||||
|
||||
public boolean requestObserve(MatchPlayer leaving) {
|
||||
|
@ -216,7 +216,7 @@ public class JoinMatchModule extends MatchModule implements Listener, JoinHandle
|
|||
}
|
||||
|
||||
public boolean queueToJoin(MatchPlayer joining) {
|
||||
boolean joined = getMatch().setPlayerParty(joining, queuedParticipants);
|
||||
boolean joined = getMatch().setPlayerParty(joining, queuedParticipants, false);
|
||||
if(joined) {
|
||||
joining.sendMessage(new TranslatableComponent("ffa.join"));
|
||||
}
|
||||
|
@ -255,7 +255,7 @@ public class JoinMatchModule extends MatchModule implements Listener, JoinHandle
|
|||
|
||||
public boolean cancelQueuedJoin(MatchPlayer joining) {
|
||||
if(!isQueuedToJoin(joining)) return false;
|
||||
if(getMatch().setPlayerParty(joining, getMatch().getDefaultParty())) {
|
||||
if(getMatch().setPlayerParty(joining, getMatch().getDefaultParty(), false)) {
|
||||
joining.sendMessage(new Component(new TranslatableComponent("team.join.deferred.cancel"), ChatColor.YELLOW));
|
||||
return true;
|
||||
} else {
|
||||
|
@ -273,7 +273,7 @@ public class JoinMatchModule extends MatchModule implements Listener, JoinHandle
|
|||
|
||||
// Send any leftover players to obs
|
||||
for(MatchPlayer joining : queue.getOrderedPlayers()) {
|
||||
getMatch().setPlayerParty(joining, getMatch().getDefaultParty());
|
||||
getMatch().setPlayerParty(joining, getMatch().getDefaultParty(), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -304,7 +304,7 @@ public class JoinMatchModule extends MatchModule implements Listener, JoinHandle
|
|||
final Competitor competitor = getMatch().getLastCompetitor(event.getPlayerId());
|
||||
if(competitor != null) {
|
||||
// Committed player is reconnecting
|
||||
getMatch().setPlayerParty(event.getPlayer(), competitor);
|
||||
getMatch().setPlayerParty(event.getPlayer(), competitor, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package tc.oc.pgm.kits;
|
|||
import tc.oc.pgm.match.MatchPlayer;
|
||||
import tc.oc.pgm.teams.TeamFactory;
|
||||
import tc.oc.pgm.teams.TeamMatchModule;
|
||||
import tc.oc.pgm.tracker.trackers.PlayerLocationTracker;
|
||||
|
||||
public class TeamSwitchKit extends DelayedKit {
|
||||
private final TeamFactory team;
|
||||
|
@ -14,6 +15,7 @@ public class TeamSwitchKit extends DelayedKit {
|
|||
@Override
|
||||
public void applyDelayed(MatchPlayer player, boolean force) {
|
||||
TeamMatchModule tmm = player.getMatch().needMatchModule(TeamMatchModule.class);
|
||||
//PlayerLocationTracker.setLocation(player, player.getLocation());
|
||||
tmm.forceJoin(player, tmm.team(team));
|
||||
}
|
||||
|
||||
|
|
|
@ -612,7 +612,7 @@ public interface Match extends Audience, IMatchQuery, Filterable<IMatchQuery>, M
|
|||
* This is the ONLY way that external code can change a player's party.
|
||||
* Any other methods that appear to do so are meant for internal use only.
|
||||
*/
|
||||
boolean setPlayerParty(MatchPlayer player, Party newParty);
|
||||
boolean setPlayerParty(MatchPlayer player, Party newParty, boolean force);
|
||||
|
||||
/**
|
||||
* Commit the match, if it is not already committed. Commitment is a boolean
|
||||
|
|
|
@ -712,7 +712,7 @@ public class MatchImpl implements Match, ForwardingAudience {
|
|||
|
||||
// If the player hasn't joined a party by this point, join the default party
|
||||
if(!player.hasParty()) {
|
||||
setPlayerParty(player, getDefaultParty());
|
||||
setPlayerParty(player, getDefaultParty(), false);
|
||||
}
|
||||
|
||||
return player;
|
||||
|
@ -728,7 +728,7 @@ public class MatchImpl implements Match, ForwardingAudience {
|
|||
|
||||
try {
|
||||
logger.fine("Removing player " + player);
|
||||
setOrClearPlayerParty(player, null);
|
||||
setOrClearPlayerParty(player, null, false);
|
||||
|
||||
// As with enable, facets are disabled after the player is removed
|
||||
// from their party and all collections.
|
||||
|
@ -811,8 +811,8 @@ public class MatchImpl implements Match, ForwardingAudience {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean setPlayerParty(MatchPlayer player, Party newParty) {
|
||||
return setOrClearPlayerParty(player, checkNotNull(newParty));
|
||||
public boolean setPlayerParty(MatchPlayer player, Party newParty, boolean force) {
|
||||
return setOrClearPlayerParty(player, checkNotNull(newParty), force);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -827,7 +827,7 @@ public class MatchImpl implements Match, ForwardingAudience {
|
|||
* - If the player is already in newParty, or if the party change is cancelled by {@link PlayerParticipationStopEvent},
|
||||
* none of the above changes will happen, and the method will return false.
|
||||
*/
|
||||
private boolean setOrClearPlayerParty(MatchPlayer player, @Nullable Party newParty) {
|
||||
private boolean setOrClearPlayerParty(MatchPlayer player, @Nullable Party newParty, boolean force) {
|
||||
final Party oldParty = player.party;
|
||||
|
||||
checkArgument(equals(player.getMatch()), "Player belongs to a different match");
|
||||
|
@ -847,7 +847,7 @@ public class MatchImpl implements Match, ForwardingAudience {
|
|||
throw new IllegalStateException("Nested party change: " + player + " tried to join " + newParty + " in the middle of joining " + nested);
|
||||
}
|
||||
|
||||
if(oldParty instanceof Competitor) {
|
||||
if(oldParty instanceof Competitor && !force) {
|
||||
final PlayerParticipationStopEvent request = new PlayerParticipationStopEvent(player, (Competitor) oldParty);
|
||||
bukkitEventBus.callEvent(request);
|
||||
if(request.isCancelled() && newParty != null) { // Can't cancel this if the player is leaving the match
|
||||
|
|
|
@ -2,6 +2,7 @@ package tc.oc.pgm.spawns;
|
|||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import tc.oc.pgm.features.FeatureDefinition;
|
||||
import tc.oc.pgm.features.FeatureInfo;
|
||||
|
@ -9,6 +10,7 @@ import tc.oc.pgm.kits.Kit;
|
|||
import tc.oc.pgm.kits.KitPlayerFacet;
|
||||
import tc.oc.pgm.match.MatchPlayer;
|
||||
import tc.oc.pgm.points.PointProvider;
|
||||
import tc.oc.pgm.tracker.trackers.PlayerLocationTracker;
|
||||
|
||||
@FeatureInfo(name = "spawn")
|
||||
public interface Spawn extends FeatureDefinition {
|
||||
|
@ -53,6 +55,12 @@ class SpawnImpl extends FeatureDefinition.Impl implements Spawn {
|
|||
@Override
|
||||
public Location getSpawn(MatchPlayer player) {
|
||||
Location location = this.pointProvider.getPoint(player.getMatch(), player.getBukkit());
|
||||
if (attributes.useLastParticipatingLocation) {
|
||||
Location lastParticipatingLocation = PlayerLocationTracker.getLastParticipatingLocation(player);
|
||||
if (lastParticipatingLocation != null) {
|
||||
location = lastParticipatingLocation;
|
||||
}
|
||||
}
|
||||
if(location == null) {
|
||||
player.getMatch().needMatchModule(SpawnMatchModule.class).reportFailedSpawn(this, player);
|
||||
}
|
||||
|
|
|
@ -23,8 +23,9 @@ public class SpawnAttributes extends Inspectable.Impl {
|
|||
public final @Inspect boolean spread;
|
||||
public final @Inspect boolean exclusive;
|
||||
public final @Inspect boolean persistent;
|
||||
public final @Inspect boolean useLastParticipatingLocation;
|
||||
|
||||
public SpawnAttributes(PointProviderAttributes providerAttributes, Filter filter, Optional<Kit> kit, boolean sequential, boolean spread, boolean exclusive, boolean persistent) {
|
||||
public SpawnAttributes(PointProviderAttributes providerAttributes, Filter filter, Optional<Kit> kit, boolean sequential, boolean spread, boolean exclusive, boolean persistent, boolean useLastParticipatingLocation) {
|
||||
this.filter = checkNotNull(filter);
|
||||
this.providerAttributes = checkNotNull(providerAttributes);
|
||||
this.kit = checkNotNull(kit);
|
||||
|
@ -32,10 +33,11 @@ public class SpawnAttributes extends Inspectable.Impl {
|
|||
this.spread = spread;
|
||||
this.exclusive = exclusive;
|
||||
this.persistent = persistent;
|
||||
this.useLastParticipatingLocation = useLastParticipatingLocation;
|
||||
}
|
||||
|
||||
public SpawnAttributes() {
|
||||
this(new PointProviderAttributes(), StaticFilter.ABSTAIN, Optional.empty(), false, false, false, false);
|
||||
this(new PointProviderAttributes(), StaticFilter.ABSTAIN, Optional.empty(), false, false, false, false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -52,7 +54,8 @@ public class SpawnAttributes extends Inspectable.Impl {
|
|||
this.sequential == that.sequential &&
|
||||
this.spread == that.spread &&
|
||||
this.exclusive == that.exclusive &&
|
||||
this.persistent == that.persistent
|
||||
this.persistent == that.persistent &&
|
||||
this.useLastParticipatingLocation == that.useLastParticipatingLocation
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -62,7 +65,8 @@ public class SpawnAttributes extends Inspectable.Impl {
|
|||
Optional<Boolean> sequential,
|
||||
Optional<Boolean> spread,
|
||||
Optional<Boolean> exclusive,
|
||||
Optional<Boolean> persistent) {
|
||||
Optional<Boolean> persistent,
|
||||
Optional<Boolean> useLastParticipatingLocation) {
|
||||
|
||||
return new SpawnAttributes(providerAttributes,
|
||||
AllFilter.of(filter, this.filter),
|
||||
|
@ -70,6 +74,7 @@ public class SpawnAttributes extends Inspectable.Impl {
|
|||
sequential.orElse(this.sequential),
|
||||
spread.orElse(this.spread),
|
||||
exclusive.orElse(this.exclusive),
|
||||
persistent.orElse(this.persistent));
|
||||
persistent.orElse(this.persistent),
|
||||
useLastParticipatingLocation.orElse(this.useLastParticipatingLocation));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,7 +109,8 @@ public class SpawnParser {
|
|||
booleans.property(el, "sequential").optional(),
|
||||
booleans.property(el, "spread").optional(),
|
||||
booleans.property(el, "exclusive").optional(),
|
||||
booleans.property(el, "persistent").optional()
|
||||
booleans.property(el, "persistent").optional(),
|
||||
booleans.property(el, "use-last-location").optional()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ public class TeamCommands implements NestedCommands {
|
|||
if(args.argsLength() >= 2) {
|
||||
String name = args.getString(1);
|
||||
if(name.trim().toLowerCase().startsWith("obs")) {
|
||||
player.getMatch().setPlayerParty(player, player.getMatch().getDefaultParty());
|
||||
player.getMatch().setPlayerParty(player, player.getMatch().getDefaultParty(), false);
|
||||
} else {
|
||||
Team team = utils.teamArgument(args, 1);
|
||||
utils.module().forceJoin(player, team);
|
||||
|
|
|
@ -260,7 +260,7 @@ public class TeamMatchModule extends MatchModule implements Listener, JoinHandle
|
|||
|
||||
if(Optionals.equals(newTeam, player.partyMaybe())) return true;
|
||||
|
||||
if(getMatch().setPlayerParty(player, newTeam)) {
|
||||
if(getMatch().setPlayerParty(player, newTeam, true)) {
|
||||
setAutoJoin(player, autoJoin);
|
||||
return true;
|
||||
} else {
|
||||
|
@ -546,7 +546,7 @@ public class TeamMatchModule extends MatchModule implements Listener, JoinHandle
|
|||
if(kickTo instanceof Team) {
|
||||
return forceJoin(kickMe, (Team) kickTo);
|
||||
} else {
|
||||
return getMatch().setPlayerParty(kickMe, kickTo);
|
||||
return getMatch().setPlayerParty(kickMe, kickTo, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package tc.oc.pgm.tracker;
|
||||
|
||||
import com.google.inject.multibindings.Multibinder;
|
||||
import tc.oc.commons.bukkit.inventory.Slot;
|
||||
import tc.oc.commons.core.inject.HybridManifest;
|
||||
import tc.oc.commons.core.inject.Manifest;
|
||||
import tc.oc.pgm.match.MatchScope;
|
||||
|
@ -20,6 +21,7 @@ import tc.oc.pgm.tracker.trackers.EntityTracker;
|
|||
import tc.oc.pgm.tracker.trackers.FallTracker;
|
||||
import tc.oc.pgm.tracker.trackers.FireTracker;
|
||||
import tc.oc.pgm.tracker.trackers.OwnedMobTracker;
|
||||
import tc.oc.pgm.tracker.trackers.PlayerLocationTracker;
|
||||
import tc.oc.pgm.tracker.trackers.ProjectileTracker;
|
||||
import tc.oc.pgm.tracker.trackers.SpleefTracker;
|
||||
import tc.oc.pgm.tracker.trackers.TNTTracker;
|
||||
|
@ -43,6 +45,7 @@ public class TrackerManifest extends HybridManifest implements MatchBinders {
|
|||
bind(AnvilTracker.class);
|
||||
bind(CombatLogTracker.class);
|
||||
bind(DeathTracker.class);
|
||||
bind(PlayerLocationTracker.class);
|
||||
|
||||
bind(PotionDamageResolver.class);
|
||||
bind(ExplosionDamageResolver.class);
|
||||
|
@ -73,6 +76,7 @@ public class TrackerManifest extends HybridManifest implements MatchBinders {
|
|||
matchListener(AnvilTracker.class, MatchScope.RUNNING);
|
||||
matchListener(CombatLogTracker.class, MatchScope.RUNNING);
|
||||
matchListener(DeathTracker.class, MatchScope.RUNNING);
|
||||
matchListener(PlayerLocationTracker.class, MatchScope.RUNNING);
|
||||
|
||||
// Damage resolvers - order is important!
|
||||
final Multibinder<DamageResolver> damageResolvers = inSet(DamageResolver.class);
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package tc.oc.pgm.tracker.trackers;
|
||||
|
||||
import edu.umd.cs.findbugs.detect.BadUseOfReturnValue;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import tc.oc.pgm.events.ListenerScope;
|
||||
import tc.oc.pgm.events.MatchPlayerDeathEvent;
|
||||
import tc.oc.pgm.events.PlayerChangePartyEvent;
|
||||
import tc.oc.pgm.match.MatchPlayer;
|
||||
import tc.oc.pgm.match.MatchScope;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
@ListenerScope(MatchScope.RUNNING)
|
||||
public class PlayerLocationTracker implements Listener {
|
||||
|
||||
private static final Map<MatchPlayer, Location> lastParticipatingLocation = new WeakHashMap<>();
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerChangeParty(PlayerChangePartyEvent event) {
|
||||
lastParticipatingLocation.put(event.getPlayer(), event.getPlayer().getLocation());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(MatchPlayerDeathEvent event) {
|
||||
lastParticipatingLocation.put(event.getVictim(), event.getVictim().getLocation());
|
||||
}
|
||||
|
||||
/*
|
||||
public static void setLocation(MatchPlayer player, Location location) {
|
||||
lastParticipatingLocation.put(player, location);
|
||||
}
|
||||
*/
|
||||
|
||||
public static @Nullable Location getLastParticipatingLocation(MatchPlayer player) {
|
||||
Location location = lastParticipatingLocation.get(player);
|
||||
return (location != null && location.getWorldId().equals(player.getWorldId())) ? location : null;
|
||||
}
|
||||
}
|
|
@ -136,7 +136,7 @@ public class TeamListener implements Listener {
|
|||
final Player player = event.getPlayer().getBukkit();
|
||||
Team team = teamManagerProvider.get().getTeam(player);
|
||||
if(team != null) {
|
||||
event.getMatch().setPlayerParty(event.getPlayer(), team);
|
||||
event.getMatch().setPlayerParty(event.getPlayer(), team, false);
|
||||
ChannelsPlugin.get().getPlayerManager().setMembershipChannel(
|
||||
player,
|
||||
event.getMatch().needMatchModule(ChannelMatchModule.class).getChannel(team)
|
||||
|
|
Loading…
Reference in New Issue