Skip to content

Commit 1c9abeb

Browse files
Merge pull request #391 from VolmitSoftware/Development
lots of fixes
2 parents 1677edc + 097da2c commit 1c9abeb

File tree

14 files changed

+229
-93
lines changed

14 files changed

+229
-93
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ plugins {
2323
id "de.undercouch.download" version "5.0.1"
2424
}
2525

26-
version '1.5.4-1.19.3'
26+
version '1.5.5-1.19.3'
2727
def nmsVersion = "1.19.3" //[NMS]
2828
def apiVersion = '1.19'
2929
def specialSourceVersion = '1.11.0' //[NMS]

src/main/java/com/volmit/adapt/AdaptConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class AdaptConfig {
6666
private boolean actionbarNotifyXp = true;
6767
private boolean actionbarNotifyLevel = true;
6868
private boolean unlearnAllButton = false;
69-
private boolean potionStackingPreventionInAllSKills = false;
69+
boolean preventHunterSkillsWhenHungerApplied = true;
7070
private SqlSettings sql = new SqlSettings();
7171

7272
@Setter

src/main/java/com/volmit/adapt/api/Component.java

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@
2626
import com.volmit.adapt.api.data.WorldData;
2727
import com.volmit.adapt.api.value.MaterialValue;
2828
import com.volmit.adapt.api.xp.XP;
29+
import com.volmit.adapt.util.J;
2930
import org.bukkit.*;
3031
import org.bukkit.block.Block;
3132
import org.bukkit.block.BlockFace;
3233
import org.bukkit.block.data.BlockData;
3334
import org.bukkit.entity.Entity;
3435
import org.bukkit.entity.Item;
3536
import org.bukkit.entity.Player;
37+
import org.bukkit.event.entity.EntityDamageEvent;
3638
import org.bukkit.event.entity.EntityPickupItemEvent;
3739
import org.bukkit.inventory.Inventory;
3840
import org.bukkit.inventory.ItemStack;
@@ -47,7 +49,7 @@
4749
import java.util.ArrayList;
4850
import java.util.Arrays;
4951
import java.util.List;
50-
import java.util.Objects;
52+
import java.util.Set;
5153
import java.util.function.Predicate;
5254

5355
public interface Component {
@@ -180,32 +182,55 @@ default PotionEffect getRawPotionEffect(ItemStack is) {
180182
return null;
181183
}
182184

183-
default void addPotionStacks(Player p, PotionEffectType potionEffect, int amplifier, int duration, Boolean overlap) {
184-
List<PotionEffectType> activeList = p.getActivePotionEffects().stream().map(PotionEffect::getType).toList();
185-
if (activeList.size() > 0) {
186-
for (PotionEffectType type : activeList) {
187-
if (type.equals(potionEffect)) {
188-
if (!AdaptConfig.get().isPotionStackingPreventionInAllSKills()) {
189-
if (overlap) {
190-
p.playSound(p.getLocation(), Sound.ENTITY_IRON_GOLEM_STEP, 0.25f, 0.25f);
191-
int newAmplifier = Objects.requireNonNull(p.getPotionEffect(type)).getAmplifier();
192-
int newDuration = Objects.requireNonNull(p.getPotionEffect(type)).getDuration();
193-
p.removePotionEffect(type);
194-
p.addPotionEffect(new PotionEffect(potionEffect, newDuration + duration, newAmplifier + amplifier, false, false));
195-
}
196-
int newAmplifier = Objects.requireNonNull(p.getPotionEffect(type)).getAmplifier();
197-
int newDuration = Objects.requireNonNull(p.getPotionEffect(type)).getDuration();
198-
p.removePotionEffect(type);
199-
p.addPotionEffect(new PotionEffect(potionEffect, newDuration, newAmplifier + 1, false, false));
200-
}
185+
default boolean isAdaptableDamageCause(EntityDamageEvent event) {
186+
Set<EntityDamageEvent.DamageCause> excludedCauses = Set.of(
187+
// These are not damage causes that can are going to trigger adaptability
188+
EntityDamageEvent.DamageCause.VOID,
189+
EntityDamageEvent.DamageCause.LAVA,
190+
EntityDamageEvent.DamageCause.HOT_FLOOR,
191+
EntityDamageEvent.DamageCause.CRAMMING,
192+
EntityDamageEvent.DamageCause.MELTING,
193+
EntityDamageEvent.DamageCause.SUFFOCATION,
194+
EntityDamageEvent.DamageCause.SUICIDE,
195+
EntityDamageEvent.DamageCause.WITHER,
196+
EntityDamageEvent.DamageCause.FLY_INTO_WALL,
197+
EntityDamageEvent.DamageCause.FALL,
198+
EntityDamageEvent.DamageCause.SONIC_BOOM,
199+
EntityDamageEvent.DamageCause.THORNS
200+
);
201+
return !excludedCauses.contains(event.getCause());
202+
}
203+
204+
default void addPotionStacks(Player p, PotionEffectType potionEffect, int amplifier, int duration, boolean overlap) {
205+
List<PotionEffect> activeEffects = new ArrayList<>(p.getActivePotionEffects());
206+
207+
for (PotionEffect activeEffect : activeEffects) {
208+
if (activeEffect.getType() == potionEffect) {
209+
if (!overlap) {
210+
return; // don't modify the effect if overlap is false
201211
}
212+
// modify the effect if overlap is true
213+
int newDuration = activeEffect.getDuration() + duration;
214+
int newAmplifier = Math.max(activeEffect.getAmplifier(), amplifier);
215+
p.removePotionEffect(potionEffect);
216+
p.addPotionEffect(new PotionEffect(potionEffect, newDuration, newAmplifier));
217+
p.playSound(p.getLocation(), Sound.ENTITY_IRON_GOLEM_STEP, 0.25f, 0.25f);
218+
return;
202219
}
203-
204-
}
205-
if (!activeList.contains(potionEffect)) {
206-
p.playSound(p.getLocation(), Sound.ENTITY_IRON_GOLEM_STEP, 0.25f, 0.25f);
207-
p.addPotionEffect(new PotionEffect(potionEffect, duration, amplifier));
208220
}
221+
// if we didn't find an existing effect, add a new one
222+
J.a(() -> {
223+
try {
224+
Thread.sleep(5);
225+
} catch (InterruptedException e) {
226+
throw new RuntimeException(e);
227+
}
228+
J.s(() -> {
229+
p.addPotionEffect(new PotionEffect(potionEffect, duration, amplifier));
230+
p.playSound(p.getLocation(), Sound.ENTITY_IRON_GOLEM_STEP, 0.25f, 0.25f);
231+
});
232+
});
233+
209234
}
210235

211236

src/main/java/com/volmit/adapt/api/adaptation/Adaptation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ default void openGui(Player player) {
370370
.setProgress(1D)
371371
.addLore(Form.wrapWordsPrefixed(getDescription(), "" + C.GRAY, 40))
372372
.addLore(mylevel >= lvl ? ("") : ("" + C.WHITE + c + C.GRAY + " " + Localizer.dLocalize("snippets", "adaptmenu", "knowledgecost") + " " + (AdaptConfig.get().isHardcoreNoRefunds() ? C.DARK_RED + "" + C.BOLD + Localizer.dLocalize("snippets", "adaptmenu", "norefunds") : "")))
373-
.addLore(mylevel >= lvl ? AdaptConfig.get().isHardcoreNoRefunds() ? (C.GREEN + Localizer.dLocalize("snippets", "adaptmenu", "alreadylearned") + " " + C.DARK_RED + "" + C.BOLD + Localizer.dLocalize("snippets", "adaptmenu", "norefunds")) : (isPermanent() ? "" : (C.GREEN + Localizer.dLocalize("snippets", "adaptmenu", "alreadylearned") + " " + C.GRAY + Localizer.dLocalize("snippets", "adaptmenu", "unlearnrefund") + " " + C.GREEN + rc + " " + Localizer.dLocalize("snippets", "adaptmenu", "knowledgecost"))) : (k >= c ? (C.BLUE + Localizer.dLocalize("snippets", "adaptmenu", "clicklearn") + " " + getDisplayName(i)) : (k == 0 ? (C.RED + Localizer.dLocalize("snippets", "adaptmenu", "noknowledge")) : (C.RED + "(" + Localizer.dLocalize("snippets", "adaptmenu", "youonlyhave") + " " + C.WHITE + k + C.RED + " " + Localizer.dLocalize("snippets", "adaptmenu", "knowledgecost") + ")"))))
373+
.addLore(mylevel >= lvl ? AdaptConfig.get().isHardcoreNoRefunds() ? (C.GREEN + Localizer.dLocalize("snippets", "adaptmenu", "alreadylearned") + " " + C.DARK_RED + "" + C.BOLD + Localizer.dLocalize("snippets", "adaptmenu", "norefunds")) : (isPermanent() ? "" : (C.GREEN + Localizer.dLocalize("snippets", "adaptmenu", "alreadylearned") + " " + C.GRAY + Localizer.dLocalize("snippets", "adaptmenu", "unlearnrefund") + " " + C.GREEN + rc + " " + Localizer.dLocalize("snippets", "adaptmenu", "knowledgecost"))) : (k >= c ? (C.BLUE + Localizer.dLocalize("snippets", "adaptmenu", "clicklearn") + " " + getDisplayName(i)) : (k == 0 ? (C.RED + Localizer.dLocalize("snippets", "adaptmenu", "noknowledge")) : (C.RED + "(" + Localizer.dLocalize("snippets", "adaptmenu", "youonlyhave") + " " + C.WHITE + k + C.RED + " " + Localizer.dLocalize("snippets", "adaptmenu", "knowledgeavailable") + ")"))))
374374
.addLore(mylevel < lvl && getPlayer(player).getData().hasPowerAvailable(pc) ? C.GREEN + "" + lvl + " " + Localizer.dLocalize("snippets", "adaptmenu", "powerdrain") : mylevel >= lvl ? C.GREEN + "" + lvl + " " + Localizer.dLocalize("snippets", "adaptmenu", "powerdrain") : C.RED + Localizer.dLocalize("snippets", "adaptmenu", "notenoughpower") + "\n" + C.RED + Localizer.dLocalize("snippets", "adaptmenu", "howtolevelup"))
375375
.addLore((isPermanent() ? C.RED + "" + C.BOLD + Localizer.dLocalize("snippets", "adaptmenu", "maynotunlearn") : ""))
376376
.onLeftClick((e) -> {

src/main/java/com/volmit/adapt/api/adaptation/SimpleAdaptation.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import art.arcane.amulet.io.FileWatcher;
2222
import com.google.gson.Gson;
2323
import com.volmit.adapt.Adapt;
24-
import com.volmit.adapt.AdaptConfig;
2524
import com.volmit.adapt.api.advancement.AdaptAdvancement;
2625
import com.volmit.adapt.api.potion.BrewingRecipe;
2726
import com.volmit.adapt.api.recipe.AdaptRecipe;
@@ -171,7 +170,7 @@ public AdaptAdvancement buildAdvancements() {
171170
return AdaptAdvancement.builder()
172171
.key("adaptation_" + getName())
173172
.title(C.WHITE + "[ " + getDisplayName() + C.WHITE + " ]")
174-
.description(getDescription() + ". " + Localizer.dLocalize("snippets", "gui", "unlockthisbyclicking") + AdaptConfig.get().adaptActivatorBlock.toLowerCase().capitalizeWords())
173+
.description(getDescription() + ". " + Localizer.dLocalize("snippets", "gui", "unlockthisbyclicking") + " " + Localizer.dLocalize("snippets", "adaptmenu", "activatorblock"))
175174
.icon(getIcon())
176175
.children(a)
177176
.visibility(AdvancementVisibility.PARENT_GRANTED)

src/main/java/com/volmit/adapt/content/adaptation/axe/AxeWoodVeinminer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void on(BlockBreakEvent e) {
8686
}
8787

8888
if (isLog(new ItemStack(e.getBlock().getType()))) {
89-
89+
Adapt.info("Axe Wood Veinminer: " + p.getName() + " is using " + e.getBlock().getType() + " at " + e.getBlock().getLocation());
9090
Block block = e.getBlock();
9191
Set<Block> blockMap = new HashSet<>();
9292
int blockCount = 0;
@@ -114,7 +114,8 @@ public void on(BlockBreakEvent e) {
114114

115115
J.s(() -> {
116116
for (Block blocks : blockMap) {
117-
if (getPlayer(p).getData().getSkillLines().get("axes").getAdaptations().get("axe-drop-to-inventory").getLevel() > 0) {
117+
Adapt.info("Axe Wood Veinminer: " + p.getName() + " is breaking " + blocks.getType() + " at " + blocks.getLocation());
118+
if (getPlayer(p).getData().getSkillLines().get("axes").getAdaptations().get("axe-drop-to-inventory") != null && getPlayer(p).getData().getSkillLines().get("axes").getAdaptations().get("axe-drop-to-inventory").getLevel() > 0) {
118119
Collection<ItemStack> items = blocks.getDrops();
119120
for (ItemStack item : items) {
120121
safeGiveItem(p, item);

src/main/java/com/volmit/adapt/content/adaptation/hunter/HunterInvis.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package com.volmit.adapt.content.adaptation.hunter;
2020

21+
import com.volmit.adapt.AdaptConfig;
2122
import com.volmit.adapt.api.adaptation.SimpleAdaptation;
2223
import com.volmit.adapt.util.C;
2324
import com.volmit.adapt.util.Element;
@@ -48,7 +49,7 @@ public HunterInvis() {
4849
public void addStats(int level, Element v) {
4950
v.addLore(C.GRAY + Localizer.dLocalize("hunter", "invisibility", "lore1"));
5051
v.addLore(C.GREEN + "+ " + level + C.GRAY + Localizer.dLocalize("hunter", "invisibility", "lore2"));
51-
v.addLore(C.RED + "- " + 5 + level + C.GRAY + Localizer.dLocalize("hunter", "invisibility", "lore3"));
52+
v.addLore(C.RED + "- " + (5 + level) + C.GRAY + Localizer.dLocalize("hunter", "invisibility", "lore3"));
5253
v.addLore(C.GRAY + "* " + level + C.GRAY + " " + Localizer.dLocalize("hunter", "invisibility", "lore4"));
5354
v.addLore(C.GRAY + "* " + level + C.GRAY + " " + Localizer.dLocalize("hunter", "invisibility", "lore5"));
5455
v.addLore(C.RED + "* " + level + C.GRAY + " " + Localizer.dLocalize("hunter", "penalty", "lore1"));
@@ -62,24 +63,29 @@ public void on(EntityDamageEvent e) {
6263
if (e.isCancelled()) {
6364
return;
6465
}
65-
if (e.getEntity() instanceof org.bukkit.entity.Player p && !e.getCause().equals(EntityDamageEvent.DamageCause.STARVATION) && hasAdaptation(p)) {
66+
if (e.getEntity() instanceof org.bukkit.entity.Player p && isAdaptableDamageCause(e) && hasAdaptation(p)) {
67+
if (AdaptConfig.get().isPreventHunterSkillsWhenHungerApplied() && p.hasPotionEffect(PotionEffectType.HUNGER)) {
68+
return;
69+
}
6670
if (!getConfig().useConsumable) {
67-
6871
if (p.getFoodLevel() == 0) {
69-
addPotionStacks(p, PotionEffectType.POISON, 2 + getLevel(p), 300, true);
70-
72+
if (getConfig().poisonPenalty) {
73+
addPotionStacks(p, PotionEffectType.POISON, getConfig().basePoisonFromLevel - getLevel(p), getConfig().baseHungerDuration, getConfig().stackPoisonPenalty);
74+
}
7175
} else {
72-
addPotionStacks(p, PotionEffectType.HUNGER, 5 + getLevel(p), 100, true);
73-
addPotionStacks(p, PotionEffectType.INVISIBILITY, 1, 50 * getLevel(p), true);
76+
addPotionStacks(p, PotionEffectType.HUNGER, getConfig().baseHungerFromLevel - getLevel(p), getConfig().baseHungerDuration* getLevel(p), getConfig().stackHungerPenalty);
77+
addPotionStacks(p, PotionEffectType.INVISIBILITY, getLevel(p), getConfig().baseEffectbyLevel * getLevel(p), getConfig().stackBuff);
7478
}
7579
} else {
7680
if (getConfig().consumable != null && Material.getMaterial(getConfig().consumable) != null) {
7781
Material mat = Material.getMaterial(getConfig().consumable);
7882
if (mat != null && p.getInventory().contains(mat)) {
7983
p.getInventory().removeItem(new ItemStack(mat, 1));
80-
addPotionStacks(p, PotionEffectType.INVISIBILITY, getLevel(p), 50, false);
84+
addPotionStacks(p, PotionEffectType.INVISIBILITY, getLevel(p), getConfig().baseEffectbyLevel * getLevel(p), getConfig().stackBuff);
8185
} else {
82-
addPotionStacks(p, PotionEffectType.POISON, 2 + getLevel(p), 300, true);
86+
if (getConfig().poisonPenalty) {
87+
addPotionStacks(p, PotionEffectType.POISON, getConfig().basePoisonFromLevel - getLevel(p), getConfig().baseHungerDuration, getConfig().stackPoisonPenalty);
88+
}
8389
}
8490
}
8591
}
@@ -106,6 +112,14 @@ protected static class Config {
106112
boolean permanent = false;
107113
boolean enabled = true;
108114
boolean useConsumable = false;
115+
boolean poisonPenalty = true;
116+
boolean stackHungerPenalty = false;
117+
boolean stackPoisonPenalty = false;
118+
boolean stackBuff = false;
119+
int baseEffectbyLevel = 100;
120+
int baseHungerFromLevel = 10;
121+
int baseHungerDuration = 50;
122+
int basePoisonFromLevel = 6;
109123
String consumable = "ROTTEN_FLESH";
110124
int baseCost = 4;
111125
int maxLevel = 5;

src/main/java/com/volmit/adapt/content/adaptation/hunter/HunterJumpBoost.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package com.volmit.adapt.content.adaptation.hunter;
2020

21+
import com.volmit.adapt.AdaptConfig;
2122
import com.volmit.adapt.api.adaptation.SimpleAdaptation;
2223
import com.volmit.adapt.util.C;
2324
import com.volmit.adapt.util.Element;
@@ -47,7 +48,7 @@ public HunterJumpBoost() {
4748
public void addStats(int level, Element v) {
4849
v.addLore(C.GRAY + Localizer.dLocalize("hunter", "jumpboost", "lore1"));
4950
v.addLore(C.GREEN + "+ " + level + C.GRAY + Localizer.dLocalize("hunter", "jumpboost", "lore2"));
50-
v.addLore(C.RED + "- " + 5 + level + C.GRAY + Localizer.dLocalize("hunter", "jumpboost", "lore3"));
51+
v.addLore(C.RED + "- " + (5 + level) + C.GRAY + Localizer.dLocalize("hunter", "jumpboost", "lore3"));
5152
v.addLore(C.GRAY + "* " + level + C.GRAY + " " + Localizer.dLocalize("hunter", "jumpboost", "lore4"));
5253
v.addLore(C.GRAY + "* " + level + C.GRAY + " " + Localizer.dLocalize("hunter", "jumpboost", "lore5"));
5354
v.addLore(C.GRAY + "- " + level + C.RED + " " + Localizer.dLocalize("hunter", "penalty", "lore1"));
@@ -60,24 +61,31 @@ public void on(EntityDamageEvent e) {
6061
if (e.isCancelled()) {
6162
return;
6263
}
63-
if (e.getEntity() instanceof org.bukkit.entity.Player p && !e.getCause().equals(EntityDamageEvent.DamageCause.STARVATION) && hasAdaptation(p)) {
64-
if (!getConfig().useConsumable) {
64+
if (e.getEntity() instanceof org.bukkit.entity.Player p && isAdaptableDamageCause(e) && hasAdaptation(p)) {
65+
if (AdaptConfig.get().isPreventHunterSkillsWhenHungerApplied() && p.hasPotionEffect(PotionEffectType.HUNGER)) {
66+
return;
67+
}
6568

69+
if (!getConfig().useConsumable) {
6670
if (p.getFoodLevel() == 0) {
67-
addPotionStacks(p, PotionEffectType.POISON, 2 + getLevel(p), 300, true);
71+
if (getConfig().poisonPenalty) {
72+
addPotionStacks(p, PotionEffectType.POISON, getConfig().basePoisonFromLevel - getLevel(p), getConfig().baseHungerDuration, getConfig().stackPoisonPenalty);
73+
}
6874

6975
} else {
70-
addPotionStacks(p, PotionEffectType.HUNGER, 5 + getLevel(p), 100, true);
71-
addPotionStacks(p, PotionEffectType.JUMP, getLevel(p), 50, false);
76+
addPotionStacks(p, PotionEffectType.HUNGER, getConfig().baseHungerFromLevel - getLevel(p), getConfig().baseHungerDuration* getLevel(p), getConfig().stackHungerPenalty);
77+
addPotionStacks(p, PotionEffectType.JUMP, getLevel(p), getConfig().baseEffectbyLevel * getLevel(p), getConfig().stackBuff);
7278
}
7379
} else {
7480
if (getConfig().consumable != null && Material.getMaterial(getConfig().consumable) != null) {
7581
Material mat = Material.getMaterial(getConfig().consumable);
7682
if (mat != null && p.getInventory().contains(mat)) {
7783
p.getInventory().removeItem(new ItemStack(mat, 1));
78-
addPotionStacks(p, PotionEffectType.JUMP, getLevel(p), 50, false);
84+
addPotionStacks(p, PotionEffectType.JUMP, getLevel(p), getConfig().baseEffectbyLevel * getLevel(p), getConfig().stackBuff);
7985
} else {
80-
addPotionStacks(p, PotionEffectType.POISON, 2 + getLevel(p), 300, true);
86+
if (getConfig().poisonPenalty) {
87+
addPotionStacks(p, PotionEffectType.POISON, getConfig().basePoisonFromLevel - getLevel(p), getConfig().baseHungerDuration, getConfig().stackPoisonPenalty);
88+
}
8189
}
8290
}
8391
}
@@ -104,6 +112,14 @@ protected static class Config {
104112
boolean permanent = false;
105113
boolean enabled = true;
106114
boolean useConsumable = false;
115+
boolean poisonPenalty = true;
116+
boolean stackHungerPenalty = false;
117+
boolean stackPoisonPenalty = false;
118+
boolean stackBuff = false;
119+
int baseEffectbyLevel = 100;
120+
int baseHungerFromLevel = 10;
121+
int baseHungerDuration = 50;
122+
int basePoisonFromLevel = 6;
107123
String consumable = "ROTTEN_FLESH";
108124
int baseCost = 4;
109125
int maxLevel = 5;

0 commit comments

Comments
 (0)