Skip to content
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

Add splash potions entity to Spawner module #1002

Merged
merged 23 commits into from
May 22, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6d8ed1f
Add dropped potions support to spawners
CoWinkKeyDinkInc May 2, 2022
05bbe97
Make Splash potions have multiple effects, simplify code
CoWinkKeyDinkInc May 2, 2022
2487058
Simplify code
CoWinkKeyDinkInc May 2, 2022
dc2fbaa
Use <effect> inside <potion> for parsing
CoWinkKeyDinkInc May 2, 2022
f779edd
Add evaluation
CoWinkKeyDinkInc May 2, 2022
c627279
Fix evaluation of <potion> and <element>
CoWinkKeyDinkInc May 3, 2022
5a3e16b
Simplify Code
CoWinkKeyDinkInc May 3, 2022
a6a533c
Use finals for SpawnableItem and SpawnablePotion
CoWinkKeyDinkInc May 3, 2022
3e405a9
Refactor, convert spawner ID to string
CoWinkKeyDinkInc May 4, 2022
48eae5c
Use AtomicInteger for numericID, rearrange SpawnerDefinition
CoWinkKeyDinkInc May 5, 2022
3212cb2
Clone potionItem
CoWinkKeyDinkInc May 5, 2022
e956706
Parse potion effects properly
CoWinkKeyDinkInc May 5, 2022
fb03925
Rename spawner Element to spawnerEl
CoWinkKeyDinkInc May 5, 2022
ff95283
Reformat code
CoWinkKeyDinkInc May 5, 2022
cd081d4
Add damage value to determine potion color
CoWinkKeyDinkInc May 5, 2022
f0630e5
Make spawnerID string
CoWinkKeyDinkInc May 6, 2022
d610cbc
Rename variable
CoWinkKeyDinkInc May 9, 2022
cdf5fa9
Use NMSHacks to create EntityPotion
CoWinkKeyDinkInc May 9, 2022
f13edf6
Use NMSHacks properly
CoWinkKeyDinkInc May 11, 2022
04de451
Rework spawner IDs
CoWinkKeyDinkInc May 11, 2022
3e5624e
Simplify EntityPotion spawning
CoWinkKeyDinkInc May 12, 2022
682b7f3
Do pablo's suggestions
CoWinkKeyDinkInc May 13, 2022
1de5d6f
Set metadata to EntityPotion
CoWinkKeyDinkInc May 13, 2022
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
14 changes: 14 additions & 0 deletions core/src/main/java/tc/oc/pgm/spawner/SpawnerModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.List;
import java.util.logging.Logger;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.jdom2.Attribute;
import org.jdom2.Document;
import org.jdom2.Element;
Expand All @@ -24,6 +25,7 @@
import tc.oc.pgm.regions.RegionModule;
import tc.oc.pgm.regions.RegionParser;
import tc.oc.pgm.spawner.objects.SpawnableItem;
import tc.oc.pgm.spawner.objects.SpawnablePotion;
import tc.oc.pgm.util.xml.InvalidXMLException;
import tc.oc.pgm.util.xml.XMLUtils;

Expand Down Expand Up @@ -87,6 +89,18 @@ public SpawnerModule parse(MapFactory factory, Logger logger, Document doc)
objects.add(item);
}

List<PotionEffect> thrownPotion = new ArrayList<>();
// All listed effects for a spawner will be included in one splash potion
for (Element spawnable :
XMLUtils.getChildren(element, "potion", "potions", "effect", "effects")) {
PotionEffect potionEffect = XMLUtils.parsePotionEffect(spawnable);
thrownPotion.add(potionEffect);
CoWinkKeyDinkInc marked this conversation as resolved.
Show resolved Hide resolved
}
if (!thrownPotion.isEmpty()) {
SpawnablePotion potion = new SpawnablePotion(thrownPotion, numericID);
objects.add(potion);
CoWinkKeyDinkInc marked this conversation as resolved.
Show resolved Hide resolved
}

SpawnerDefinition spawnerDefinition =
new SpawnerDefinition(
objects,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package tc.oc.pgm.spawner.objects;

import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.ThrownPotion;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.potion.PotionEffect;
import tc.oc.pgm.api.PGM;
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.spawner.Spawnable;
import tc.oc.pgm.spawner.Spawner;

public class SpawnablePotion implements Spawnable {
private ItemStack potionItem;
private String METADATA_VALUE;
CoWinkKeyDinkInc marked this conversation as resolved.
Show resolved Hide resolved

public SpawnablePotion(List<PotionEffect> potion, int spawnerID) {
CoWinkKeyDinkInc marked this conversation as resolved.
Show resolved Hide resolved
this.METADATA_VALUE = Integer.toString(spawnerID);
ItemStack potionItem = new ItemStack(Material.POTION);
PotionMeta potionMeta = (PotionMeta) potionItem.getItemMeta();
for (PotionEffect effect : potion) {
potionMeta.addCustomEffect(
new PotionEffect((effect.getType()), effect.getDuration(), effect.getAmplifier()), false);
CoWinkKeyDinkInc marked this conversation as resolved.
Show resolved Hide resolved
}
potionItem.setItemMeta(potionMeta);
this.potionItem = potionItem;
}

@Override
public void spawn(Location location, Match match) {
ThrownPotion thrownPotion = location.getWorld().spawn(location, ThrownPotion.class);
thrownPotion.setItem(potionItem);
CoWinkKeyDinkInc marked this conversation as resolved.
Show resolved Hide resolved
thrownPotion.setMetadata(
Spawner.METADATA_KEY, new FixedMetadataValue(PGM.get(), METADATA_VALUE));
}

@Override
public int getSpawnCount() {
return potionItem.getAmount();
}
}