-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1006 from CoWinkKeyDinkInc/spawner-dropped-potions
Add Splash Potions Entity to Spawner Module
- Loading branch information
1 parent
fa2b5bf
commit 5c6ab01
Showing
6 changed files
with
148 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
core/src/main/java/tc/oc/pgm/spawner/objects/SpawnablePotion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package tc.oc.pgm.spawner.objects; | ||
|
||
import java.util.List; | ||
import org.bukkit.Location; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.PotionMeta; | ||
import org.bukkit.metadata.FixedMetadataValue; | ||
import org.bukkit.potion.Potion; | ||
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; | ||
import tc.oc.pgm.util.nms.NMSHacks; | ||
|
||
public class SpawnablePotion implements Spawnable { | ||
private final ItemStack potionItem; | ||
private final String spawnerId; | ||
|
||
public SpawnablePotion(List<PotionEffect> potion, int damageValue, String spawnerId) { | ||
this.spawnerId = spawnerId; | ||
// Potion "name" determines potion color | ||
ItemStack potionItem = new Potion(damageValue).splash().toItemStack(1); | ||
PotionMeta potionMeta = (PotionMeta) potionItem.getItemMeta(); | ||
for (PotionEffect effect : potion) { | ||
potionMeta.addCustomEffect(effect, false); | ||
} | ||
potionItem.setItemMeta(potionMeta); | ||
this.potionItem = potionItem; | ||
} | ||
|
||
@Override | ||
public void spawn(Location location, Match match) { | ||
NMSHacks.EntityPotion entityPotion = new NMSHacks.EntityPotion(location, potionItem); | ||
entityPotion.spawn(); | ||
entityPotion | ||
.getBukkitEntity() | ||
.setMetadata(Spawner.METADATA_KEY, new FixedMetadataValue(PGM.get(), spawnerId)); | ||
} | ||
|
||
@Override | ||
public int getSpawnCount() { | ||
return potionItem.getAmount(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters