8000 Add clear-effects option to ClearItemsKit by CoWinkKeyDinkInc · Pull Request #901 · PGMDev/PGM · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add clear-effects option to ClearItemsKit #901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions core/src/main/java/tc/oc/pgm/kits/ClearItemsKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,37 @@

import java.util.List;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import tc.oc.pgm.api.player.MatchPlayer;

/** Clears the player's inventory, including anything they may be holding on the cursor */
/**
* Clears the player's inventory and status effects, including anything they may be holding on the
* cursor
*/
public class ClearItemsKit extends AbstractKit {
private final boolean items;
private final boolean armor;
private final boolean effects;

public ClearItemsKit(boolean armor) {
public ClearItemsKit(boolean items, boolean armor, boolean effects) {
this.items = items;
this.armor = armor;
this.effects = effects;
}

@Override
public void applyPostEvent(MatchPlayer player, boolean force, List<ItemStack> displacedItems) {
if (this.armor) {
player.getBukkit().getInventory().setArmorContents(new ItemStack[4]);
}
player.getBukkit().getInventory().clear();
player.getBukkit().getOpenInventory().setCursor(null);
if (this.effects) {
for (PotionEffect potion : player.getBukkit().getActivePotionEffects()) {
player.getBukkit().removePotionEffect(potion.getType());
}
}
if (this.items) {
player.getBukkit().getInventory().clear();
player.getBukkit().getOpenInventory().setCursor(null);
}
}
}
12 changes: 10 additions & 2 deletions core/src/main/java/tc/oc/pgm/kits/KitParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,16 @@ public WalkSpeedKit parseWalkSpeedKit(Element el) throws InvalidXMLException {
}

public ClearItemsKit parseClearItemsKit(Element el) throws InvalidXMLException {
if ("".equals(el.getChildText("clear"))) return new ClearItemsKit(true);
if ("".equals(el.getChildText("clear-items"))) return new ClearItemsKit(false);
Element applyClear = el.getChild("clear");
if (applyClear != null) {
boolean items = XMLUtils.parseBoolean(applyClear.getAttribute("items"), true);
boolean armor = XMLUtils.parseBoolean(applyClear.getAttribute("armor"), true);
boolean effects = XMLUtils.parseBoolean(applyClear.getAttribute("effects"), false);
return new ClearItemsKit(items, armor, effects);
} else {
// legacy
if ("".equals(el.getChildText("clear-items"))) return new ClearItemsKit(true, false, false);
}
return null;
}

Expand Down
0