-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c1a7a0
commit 47ae3af
Showing
4 changed files
with
377 additions
and
195 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
AtlasParent/Atlas/src/main/java/cc/funkemunky/api/utils/PotionBuilder.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,86 @@ | ||
package cc.funkemunky.api.utils; | ||
|
||
import org.bukkit.Material; | ||
import org.bukkit.inventory.ItemFlag; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.PotionMeta; | ||
import org.bukkit.potion.Potion; | ||
import org.bukkit.potion.PotionEffect; | ||
import org.bukkit.potion.PotionType; | ||
|
||
import java.util.*; | ||
|
||
public class PotionBuilder { | ||
|
||
private String name; | ||
private List<String> description; | ||
private final Map<PotionEffect, Boolean> potionEffects; | ||
private ItemFlag[] itemFlags; | ||
private final PotionType type; | ||
private int amount = 1; | ||
|
||
public PotionBuilder(PotionType potionType) { | ||
this.potionEffects = new HashMap<>(); | ||
this.type = potionType; | ||
} | ||
|
||
public PotionBuilder setName(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
public PotionBuilder setDescription(String... lines) { | ||
this.description = new ArrayList<>(Arrays.asList(lines)); | ||
return this; | ||
} | ||
|
||
public PotionBuilder addEffect(PotionEffect potionEffect, boolean overwrite) { | ||
potionEffects.put(potionEffect, overwrite); | ||
return this; | ||
} | ||
|
||
public PotionBuilder addEffect(PotionEffect potionEffect) { | ||
potionEffects.put(potionEffect, true); | ||
return this; | ||
} | ||
|
||
public PotionBuilder amount(int amount) { | ||
this.amount = amount; | ||
return this; | ||
} | ||
|
||
public PotionBuilder addEffects(HashMap<PotionEffect, Boolean> potionEffects) { | ||
this.potionEffects.putAll(potionEffects); | ||
return this; | ||
} | ||
|
||
public PotionBuilder addItemFlags(ItemFlag... itemFlags) { | ||
this.itemFlags = itemFlags; | ||
return this; | ||
} | ||
|
||
public ItemStack build() { | ||
|
||
|
||
ItemStack potionItem = new ItemStack(Material.POTION); | ||
new Potion(type).apply(potionItem); | ||
|
||
potionItem.setAmount(amount); | ||
|
||
PotionMeta pM = (PotionMeta) potionItem.getItemMeta(); | ||
if (name != null) pM.setDisplayName(name); | ||
if (description != null) pM.setLore(description); | ||
for (Map.Entry<PotionEffect, Boolean> effect : potionEffects.entrySet()) { | ||
pM.addCustomEffect(effect.getKey(), effect.getValue()); | ||
} | ||
if (itemFlags != null) pM.addItemFlags(itemFlags); | ||
potionItem.setItemMeta(pM); | ||
|
||
|
||
return potionItem; | ||
} | ||
|
||
public static PotionBuilder of(PotionType type) { | ||
return new PotionBuilder(type); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
AtlasParent/Atlas/src/main/java/cc/funkemunky/api/utils/PotionEffectBuilder.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,54 @@ | ||
package cc.funkemunky.api.utils; | ||
|
||
import org.bukkit.potion.PotionEffect; | ||
import org.bukkit.potion.PotionEffectType; | ||
|
||
public class PotionEffectBuilder { | ||
private int amplifier; | ||
private int duration; | ||
private PotionEffectType type; | ||
private boolean ambient; | ||
private boolean particles; | ||
|
||
private PotionEffectBuilder() { | ||
duration = 100; | ||
amplifier = 0; | ||
type = PotionEffectType.SPEED; | ||
ambient = false; | ||
particles = true; | ||
} | ||
|
||
public PotionEffectBuilder amplifier(int amplifier) { | ||
this.amplifier = amplifier; | ||
return this; | ||
} | ||
|
||
public PotionEffectBuilder duration(int duration) { | ||
this.duration = duration; | ||
return this; | ||
} | ||
|
||
public PotionEffectBuilder type(PotionEffectType type) { | ||
this.type = type; | ||
return this; | ||
} | ||
|
||
public PotionEffectBuilder ambient(boolean ambient) { | ||
this.ambient = ambient; | ||
return this; | ||
} | ||
|
||
public PotionEffectBuilder particles(boolean particles) { | ||
this.particles = particles; | ||
return this; | ||
} | ||
|
||
public PotionEffect build() { | ||
return new PotionEffect(type, duration, amplifier, ambient, particles); | ||
} | ||
|
||
|
||
public static PotionEffectBuilder builder() { | ||
return new PotionEffectBuilder(); | ||
} | ||
} |
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
Oops, something went wrong.