Fix tokens not being removed from the player when a poll succeeds if the player leaves
This commit is contained in:
parent
46d335bf0e
commit
ae8a175eaa
|
@ -0,0 +1,27 @@
|
|||
package tc.oc.pgm.kits;
|
||||
|
||||
import tc.oc.pgm.match.MatchPlayer;
|
||||
|
||||
public class GravityKit extends Kit.Impl {
|
||||
|
||||
boolean gravity;
|
||||
|
||||
public GravityKit(boolean gravity) {
|
||||
this.gravity = gravity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(MatchPlayer player, boolean force, ItemKitApplicator items) {
|
||||
player.getBukkit().setGravity(gravity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRemovable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(MatchPlayer player) {
|
||||
player.getBukkit().setGravity(true);
|
||||
}
|
||||
}
|
|
@ -150,6 +150,11 @@ public class KitDefinitionParser extends MagicMethodFeatureParser<Kit> implement
|
|||
return new FlyKit(canFly, flying, flySpeedMultiplier);
|
||||
}
|
||||
|
||||
@MethodParser
|
||||
public Kit gravity(Element el) throws InvalidXMLException {
|
||||
return new GravityKit(XMLUtils.parseBoolean(el, true));
|
||||
}
|
||||
|
||||
@MethodParser({"effect", "potion"})
|
||||
public Kit effect(Element el) throws InvalidXMLException {
|
||||
return new PotionKit(itemParser.parsePotionEffect(el));
|
||||
|
|
|
@ -4,7 +4,9 @@ import org.bukkit.Bukkit;
|
|||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import tc.oc.api.docs.User;
|
||||
import tc.oc.commons.bukkit.tokens.TokenUtil;
|
||||
import tc.oc.pgm.Config;
|
||||
import tc.oc.pgm.mutation.Mutation;
|
||||
import tc.oc.pgm.mutation.MutationMatchModule;
|
||||
|
||||
|
@ -14,6 +16,7 @@ public class PollMutation extends Poll {
|
|||
private CommandSender sender;
|
||||
private MutationMatchModule module;
|
||||
private String mutationName;
|
||||
private User user;
|
||||
|
||||
public PollMutation(PollManager pollManager, Server server, CommandSender sender, Mutation mutation,
|
||||
MutationMatchModule module) {
|
||||
|
@ -22,6 +25,9 @@ public class PollMutation extends Poll {
|
|||
this.sender = sender;
|
||||
this.module = module;
|
||||
this.mutationName = mutationName;
|
||||
if (sender instanceof Player) {
|
||||
user = TokenUtil.getUser((Player)sender);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -29,9 +35,8 @@ public class PollMutation extends Poll {
|
|||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(),
|
||||
"mutation enable -q " + mutation.name().toLowerCase());
|
||||
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
TokenUtil.giveMutationTokens(TokenUtil.getUser(player), -1);
|
||||
if (user != null) {
|
||||
TokenUtil.giveMutationTokens(user, -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package tc.oc.pgm.polls;
|
|||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import tc.oc.api.docs.User;
|
||||
import tc.oc.commons.bukkit.tokens.TokenUtil;
|
||||
import tc.oc.pgm.map.PGMMap;
|
||||
import tc.oc.pgm.match.MatchManager;
|
||||
|
@ -11,20 +12,23 @@ public class PollNextMap extends Poll {
|
|||
private final MatchManager mm;
|
||||
private final PGMMap nextMap;
|
||||
private CommandSender sender;
|
||||
private User user;
|
||||
|
||||
public PollNextMap(PollManager pollManager, Server server, CommandSender sender, String initiator, MatchManager mm, PGMMap nextMap) {
|
||||
super(pollManager, server, initiator);
|
||||
this.mm = mm;
|
||||
this.nextMap = nextMap;
|
||||
this.sender = sender;
|
||||
if (sender instanceof Player) {
|
||||
user = TokenUtil.getUser((Player)sender);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeAction() {
|
||||
this.mm.setNextMap(this.nextMap);
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
TokenUtil.giveMapTokens(TokenUtil.getUser(player), -1);
|
||||
if (user != null) {
|
||||
TokenUtil.giveMapTokens(user, -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ public class Dead extends Spawning {
|
|||
super.enterState();
|
||||
|
||||
player.clearInventory();
|
||||
bukkit.setGravity(true);
|
||||
|
||||
if(player.isVisible()) NMSHacks.playDeathAnimation(player.getBukkit());
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ public class Joining extends Spawning {
|
|||
@Override
|
||||
public void enterState() {
|
||||
player.setVisible(false);
|
||||
bukkit.setGravity(true);
|
||||
|
||||
super.enterState();
|
||||
trySpawn();
|
||||
|
|
|
@ -16,6 +16,7 @@ public class Participating extends State {
|
|||
@Override
|
||||
public void enterState() {
|
||||
super.enterState();
|
||||
bukkit.setGravity(true);
|
||||
permissionAttachment = bukkit.addAttachment(smm.getMatch().getPlugin(), Permissions.PARTICIPANT, true);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ public abstract class Spawning extends Participating {
|
|||
public void enterState() {
|
||||
super.enterState();
|
||||
|
||||
bukkit.setGravity(true);
|
||||
player.setDead(true);
|
||||
player.refreshInteraction();
|
||||
player.refreshVisibility();
|
||||
|
|
|
@ -44,6 +44,7 @@ public abstract class State {
|
|||
}
|
||||
|
||||
public void enterState() {
|
||||
bukkit.setGravity(true);
|
||||
if(exited) {
|
||||
throw new IllegalStateException("Tried to enter already exited state " + this);
|
||||
} else if(entered) {
|
||||
|
@ -55,6 +56,7 @@ public abstract class State {
|
|||
/**
|
||||
*/
|
||||
public void leaveState() {
|
||||
bukkit.setGravity(true);
|
||||
if(!entered) {
|
||||
throw new IllegalStateException("Tried to leave state before entering " + this);
|
||||
} else if(exited) {
|
||||
|
|
Loading…
Reference in New Issue