-
Notifications
You must be signed in to change notification settings - Fork 58
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 #254 from VolmitSoftware/Development
Development
- Loading branch information
Showing
33 changed files
with
398 additions
and
84 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
26 changes: 26 additions & 0 deletions
26
src/main/java/com/volmit/adapt/api/potion/BrewingListener.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,26 @@ | ||
package com.volmit.adapt.api.potion; | ||
|
||
import com.google.common.collect.Maps; | ||
import org.bukkit.Location; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.inventory.ClickType; | ||
import org.bukkit.event.inventory.InventoryClickEvent; | ||
import org.bukkit.event.inventory.InventoryType; | ||
import org.bukkit.inventory.BrewerInventory; | ||
|
||
import java.util.Map; | ||
|
||
public class BrewingListener implements Listener { | ||
|
||
private static final Map<String, BrewingRecipe> recipes = Maps.newHashMap(); | ||
private static final Map<Location, BrewingTask> activeTasks = Maps.newHashMap(); | ||
|
||
@EventHandler | ||
public void onInventoryClick(InventoryClickEvent e) { | ||
if(e.getClickedInventory().getType() != InventoryType.BREWING) | ||
return; | ||
|
||
BrewerInventory inv = (BrewerInventory)e.getClickedInventory(); | ||
} | ||
} |
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,6 @@ | ||
package com.volmit.adapt.api.potion; | ||
|
||
|
||
import org.bukkit.inventory.ItemStack; | ||
|
||
public record BrewingRecipe(ItemStack basePotion, ItemStack ingredient, ItemStack result, int brewingTime, int fuelCost) { } |
85 changes: 85 additions & 0 deletions
85
src/main/java/com/volmit/adapt/api/potion/BrewingTask.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,85 @@ | ||
package com.volmit.adapt.api.potion; | ||
|
||
import com.volmit.adapt.Adapt; | ||
import org.bukkit.Material; | ||
import org.bukkit.Sound; | ||
import org.bukkit.block.BrewingStand; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.inventory.BrewerInventory; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.scheduler.BukkitRunnable; | ||
|
||
public class BrewingTask extends BukkitRunnable { | ||
|
||
private final BrewingRecipe recipe; | ||
private final BrewerInventory inventory; | ||
private final BrewingStand block; | ||
|
||
private int brewTime; | ||
|
||
public BrewingTask(BrewingRecipe recipe, BrewerInventory inventory, BrewingStand block) { | ||
this.recipe = recipe; | ||
this.inventory = inventory; | ||
this.block = block; | ||
|
||
this.brewTime = recipe.brewingTime(); | ||
|
||
if(block.getFuelLevel() > recipe.fuelCost()) { | ||
block.setFuelLevel(block.getFuelLevel() - recipe.fuelCost()); | ||
} else { | ||
int rest = recipe.fuelCost() - block.getFuelLevel(); | ||
inventory.setFuel(decrease(inventory.getFuel(), rest / 20)); | ||
block.setFuelLevel(20 - rest % 20); | ||
} | ||
|
||
runTaskTimer(Adapt.instance, 0L, 1L); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
if(brewTime <= 0) { | ||
inventory.setIngredient(decrease(inventory.getIngredient(), 1)); | ||
|
||
for(int i = 0; i < 3; i++) { | ||
if(recipe.basePotion().equals(inventory.getItem(i))) | ||
inventory.setItem(i, recipe.result()); | ||
} | ||
|
||
inventory.getViewers().forEach(e -> { | ||
if(e instanceof Player p) | ||
p.playSound(block.getLocation(), Sound.BLOCK_BREWING_STAND_BREW, 1, 1); | ||
}); | ||
cancel(); | ||
return; | ||
} | ||
|
||
brewTime--; | ||
block.setBrewingTime(brewTime); | ||
block.update(true); | ||
} | ||
|
||
private ItemStack decrease(ItemStack source, int amount) { | ||
if(source.getAmount() > amount) { | ||
source.setAmount(source.getAmount() - amount); | ||
return source; | ||
} else | ||
return new ItemStack(Material.AIR); | ||
} | ||
|
||
public static boolean isValid(BrewingRecipe recipe, BrewingStand block) { | ||
BrewerInventory inv = block.getInventory(); | ||
if(!recipe.ingredient().equals(inv.getIngredient())) | ||
return false; | ||
|
||
int totalFuel = (inv.getFuel() != null && inv.getFuel().getType() != Material.AIR ? inv.getFuel().getAmount() * 20 : 0) + block.getFuelLevel(); | ||
if(totalFuel < recipe.fuelCost()) | ||
return false; | ||
|
||
for(int i = 0; i < 3; i++) { | ||
if(recipe.basePotion().equals(inv.getItem(i))) | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/com/volmit/adapt/api/potion/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,71 @@ | ||
package com.volmit.adapt.api.potion; | ||
|
||
import com.google.common.collect.Lists; | ||
import lombok.AllArgsConstructor; | ||
import org.bukkit.Color; | ||
import org.bukkit.Material; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.PotionMeta; | ||
import org.bukkit.potion.PotionData; | ||
import org.bukkit.potion.PotionEffect; | ||
import org.bukkit.potion.PotionEffectType; | ||
import org.bukkit.potion.PotionType; | ||
|
||
import java.util.List; | ||
|
||
public class PotionBuilder { | ||
|
||
private final List<PotionEffect> effects = Lists.newArrayList(); | ||
|
||
private Type type = Type.REGULAR; | ||
private Color color = Color.WHITE; | ||
private String name = "Mysterious Potion"; | ||
private boolean upgraded, extended; | ||
|
||
public PotionBuilder setType(Type type) { | ||
this.type = type; | ||
return this; | ||
} | ||
|
||
public PotionBuilder setColor(Color color) { | ||
this.color = color; | ||
return this; | ||
} | ||
|
||
public PotionBuilder addEffect(PotionEffectType type, int duration, int amplifier, boolean ambient, boolean particles, boolean icon) { | ||
effects.add(new PotionEffect(type, duration, amplifier, ambient, particles, icon)); | ||
return this; | ||
} | ||
|
||
public PotionBuilder setFlags(boolean extended, boolean upgraded) { | ||
this.upgraded = upgraded; | ||
this.extended = extended; | ||
return this; | ||
} | ||
|
||
public PotionBuilder setName(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
@SuppressWarnings("ConstantConditions") | ||
public ItemStack build() { | ||
ItemStack stack = new ItemStack(type.material); | ||
PotionMeta meta = (PotionMeta)stack.getItemMeta(); | ||
effects.forEach(e -> meta.addCustomEffect(e, true)); | ||
meta.setColor(color); | ||
meta.setBasePotionData(new PotionData(PotionType.UNCRAFTABLE, extended, upgraded)); | ||
meta.setDisplayName(name); | ||
stack.setItemMeta(meta); | ||
return stack; | ||
} | ||
|
||
@AllArgsConstructor | ||
public enum Type { | ||
REGULAR(Material.POTION), | ||
SPLASH(Material.SPLASH_POTION), | ||
LINGERING(Material.LINGERING_POTION); | ||
|
||
private final Material material; | ||
} | ||
} |
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
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
Oops, something went wrong.