Skip to content

Commit

Permalink
Merge pull request #321 from VolmitSoftware/Development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
NextdoorPsycho authored Oct 29, 2022
2 parents 8784230 + bf7ad20 commit 1584cff
Show file tree
Hide file tree
Showing 33 changed files with 464 additions and 157 deletions.
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ plugins {
id "de.undercouch.download" version "5.0.1"
}

version '1.4.11-1.19.2'
version '1.4.12-1.19.2'
def nmsVersion = "1.19.2" //[NMS]
def apiVersion = '1.19'
def specialSourceVersion = '1.11.0' //[NMS]
Expand Down Expand Up @@ -288,7 +288,7 @@ task adapt(type: Copy)
from ssJar
into buildDir
rename { String fileName ->
fileName.replace('Adapt-' + version + '-rma.jar', "Adapt-" + version + ".jar")
fileName.replace('Adapt-' + version + '-rma.jar', "Adapt.jar")
}
dependsOn(specialSourceRemap)
}
Expand All @@ -302,10 +302,10 @@ def registerCustomOutputTask(name, path) {
group('development')
outputs.upToDateWhen { false }
dependsOn(adapt)
from(new File(buildDir, "Adapt-" + version + ".jar"))
from(new File(buildDir, "Adapt.jar"))
into(file(path))
rename { String fileName ->
fileName.replace("Adapt-" + version + ".jar", "Adapt-" + version + ".jar")
fileName.replace("Adapt-" + version + ".jar", "Adapt.jar")
}
}
}
Expand All @@ -319,10 +319,10 @@ def registerCustomOutputTaskUnix(name, path) {
group('development')
outputs.upToDateWhen { false }
dependsOn(adapt)
from(new File(buildDir, "Adapt-" + version + ".jar"))
from(new File(buildDir, "Adapt.jar"))
into(file(path))
rename { String fileName ->
fileName.replace("Adapt-" + version + ".jar", "Adapt-" + version + ".jar")
fileName.replace("Adapt-" + version + ".jar", "Adapt.jar")
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/volmit/adapt/AdaptConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class AdaptConfig {
private boolean escClosesAllGuis = false;
private boolean guiBackButton = false;
private int learnUnlearnButtonDelayTicks = 14;
private int maxRecipeListPrecaution = 25;
private boolean actionbarNotifyXp = true;
private boolean actionbarNotifyLevel = true;
private boolean unlearnAllButton = false;
Expand Down Expand Up @@ -109,9 +110,9 @@ public static class SqlSettings {
@Getter
public static class ValueConfig {
private double baseValue = 1;
private Map<String, Double> valueMutlipliers = defaultValueMultipliers();
private Map<String, Double> valueMutlipliers = defaultValueMultipliersOverrides();

private Map<String, Double> defaultValueMultipliers() {
private Map<String, Double> defaultValueMultipliersOverrides() {
Map<String, Double> f = new HashMap<>();
f.put(Material.BLAZE_ROD.name(), 50D);
f.put(Material.ENDER_PEARL.name(), 75D);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/volmit/adapt/api/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ default void potion(Player p, PotionEffectType type, int power, int duration) {

default double blockXP(Block block, double xp) {
try {
return Math.round(xp * getBlockMultiplier(block));
return Math.round(xp * getBlockMultiplier(block));
} catch (Exception e) {
Adapt.verbose("Error in blockXP: " + e.getMessage());
}
Expand Down Expand Up @@ -284,7 +284,8 @@ default boolean safeGiveItem(Player player, Item droppedItemEntity, ItemStack is
droppedItemEntity.remove();
if (!player.getInventory().addItem(is).isEmpty()) {
player.getWorld().dropItem(player.getLocation(), is);
} return true;
}
return true;
} else {
return false;
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/volmit/adapt/api/adaptation/Adaptation.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,23 @@ private boolean hasBypass(Player p, Location l) {

default boolean hasAdaptation(Player p) {
try {
if (p == null) {
return false;
}
if (!this.getSkill().isEnabled()) {
Adapt.verbose("Skill " + this.getSkill().getName() + " is disabled. Skipping adaptation " + this.getName());
this.unregister();
}
if (p.getClass().getSimpleName().equals("PlayerNPC") || !p.getClass().getSimpleName().equals("CraftPlayer")) {
Adapt.verbose("Player " + p.getName() + " is not a player. Skipping adaptation " + this.getName());
return false;
}
if (AdaptConfig.get().blacklistedWorlds.contains(p.getWorld().getName())) {
Adapt.verbose("Player " + p.getName() + " is in a blacklisted world. Skipping adaptation " + this.getName());
return false;
}
if (p.getGameMode().equals(GameMode.CREATIVE) || p.getGameMode().equals(GameMode.SPECTATOR)) {
Adapt.verbose("Player " + p.getName() + " is in creative or spectator mode. Skipping adaptation " + this.getName());
return false;
}
if ((Bukkit.getServer().getPluginManager().getPlugin("WorldGuard") != null && Bukkit.getServer().getPluginManager().getPlugin("WorldGuard").isEnabled())
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/volmit/adapt/api/skill/SimpleSkill.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public boolean checkValidEntity(EntityType e) {
Adapt.verbose("EntityType " + e.name() + "wasChecked");
return !e.isAlive() || !ItemListings.getInvalidDamageableEntities().contains(e);
}

@Override
public String getDisplayName() {
return displayName == null ? Skill.super.getDisplayName() : (C.RESET + "" + C.BOLD + getColor().toString() + getEmojiName() + " " + displayName);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/volmit/adapt/api/skill/Skill.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ default void xp(Player p, Location at, double xp) {
if (xp > 50) {
vfxXP(p, at, (int) xp);
}
Adapt.verbose("Gave " + p.getName() + " " + xp + " xp in " + getName() + " " + this.getClass() );
} catch (Exception e) {
Adapt.verbose("Failed to give xp to " + p.getName() + " for " + getName() + " (" + xp + ")");
}
Expand Down
45 changes: 20 additions & 25 deletions src/main/java/com/volmit/adapt/api/value/MaterialValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.gson.Gson;
import com.volmit.adapt.Adapt;
import com.volmit.adapt.AdaptConfig;
import com.volmit.adapt.api.recipe.AdaptRecipe;
import com.volmit.adapt.util.Form;
import com.volmit.adapt.util.IO;
import com.volmit.adapt.util.JSONObject;
Expand All @@ -43,10 +44,7 @@ public class MaterialValue {
AdaptConfig.get().getValue().getValueMutlipliers().forEach((k, v) -> {
try {
Material m = Material.valueOf(k.toUpperCase());

if (m != null) {
valueMultipliers.put(m, v);
}
valueMultipliers.put(m, v);
} catch (Exception e) {
Adapt.verbose("Invalid material value multiplier: " + k);
}
Expand Down Expand Up @@ -100,7 +98,7 @@ public static void debugValue(Material m) {

private static void debugValue(Material m, int ind, int x, Set<MaterialRecipe> ignore) {
PrecisionStopwatch p = PrecisionStopwatch.start();
Adapt.info(Form.repeat(" ", ind) + m.name() + ": " + getValue(m) + (x == 1 ? "" : " (x" + x + ")"));
Adapt.verbose(Form.repeat(" ", ind) + m.name() + ": " + getValue(m) + (x == 1 ? "" : " (x" + x + ")"));

int r = 0;
for (MaterialRecipe i : getRecipes(m)) {
Expand All @@ -109,22 +107,25 @@ private static void debugValue(Material m, int ind, int x, Set<MaterialRecipe> i
}

ignore.add(i);
if (ignore.size() > AdaptConfig.get().getMaxRecipeListPrecaution()) {
Adapt.verbose("Avoiding infinite loop");
return;
}

int o = i.getOutput().getAmount();
Adapt.info(Form.repeat(" ", ind) + "# Recipe [" + ind + "x" + r + (o == 1 ? "]" : "] (x" + o + ")"));
Adapt.verbose(Form.repeat(" ", ind) + "# Recipe [" + ind + "x" + r + (o == 1 ? "]" : "] (x" + o + ") "));

for (MaterialCount j : i.getInput()) {
debugValue(j.getMaterial(), ind + 1, j.getAmount(), ignore);
}

r++;
}
Adapt.info(Form.repeat(" ", ind) + " took " + Form.duration(p.getMilliseconds(), 0));
Adapt.verbose(Form.repeat(" ", ind) + " took " + Form.duration(p.getMilliseconds(), 0));
}

private static double getMultiplier(Material m) {
Double d = AdaptConfig.get().getValue().getValueMutlipliers().get(m);

return d == null ? 1 : d;
}

Expand All @@ -136,64 +137,58 @@ private static double getValue(Material m, Set<MaterialRecipe> ignore) {
if (get().value.containsKey(m)) {
return get().value.get(m);
}

double v = AdaptConfig.get().getValue().getBaseValue();

List<MaterialRecipe> recipes = getRecipes(m);

if (recipes.isEmpty()) {
get().value.put(m, v * getMultiplier(m));
get().value.put(m, v * getMultiplier(m)); // No recipes, just use base value, if no base value then 1
} else {
List<Double> d = new ArrayList<>();
for (MaterialRecipe i : recipes) {
if (ignore.contains(i)) {
continue;
}

ignore.add(i);

double vx = v;

for (MaterialCount j : i.getInput()) {
vx += getValue(j.getMaterial(), ignore);
}

d.add(vx / i.getOutput().getAmount());
}

if (d.size() > 0) {
v += d.stream().mapToDouble(i -> i).average().getAsDouble();
}
if (v > AdaptConfig.get().getMaxRecipeListPrecaution()) {
get().value.put(m,(v/10 + 1) * getMultiplier(m));
} else {
get().value.put(m, v);
}

get().value.put(m, v);
}

return get().value.get(m);
}

private static List<MaterialRecipe> getRecipes(Material mat) {
List<MaterialRecipe> r = new ArrayList<>();

try {
ItemStack is = new ItemStack(mat);

try {
is.setDurability((short) -1);
} catch (Throwable e) {
Adapt.verbose("Failed to set durability of " + mat.name());
}

Bukkit.getRecipesFor(is).forEach(i -> {
if (i instanceof AdaptRecipe) {
Adapt.verbose("Skipping Adapt Recipe to prevent duplicates, " + mat.name() + " -> " + ((AdaptRecipe) i).getKey() + "");
return;
}
MaterialRecipe rx = toMaterial(i);

if (rx != null) {
r.add(rx);
}
});
} catch (Throwable e) {
Adapt.verbose("Failed to get recipes for " + mat.name());
}

return r;
}

Expand All @@ -211,7 +206,7 @@ private static MaterialRecipe toMaterial(Recipe r) {
.build();
Map<Material, Integer> f = new HashMap<>();
for (ItemStack i : recipe.getIngredientMap().values()) {
if (i == null || i.getType() == null || i.getType().isAir()) {
if (i == null || i.getType().isAir()) {
continue;
}

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/volmit/adapt/api/world/AdaptComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ default boolean isMelee(ItemStack is) {
return isTool(is);
}

default boolean isXpBlock(Material material) {
return material.equals(Material.EXPERIENCE_BOTTLE);
}

default boolean isRanged(ItemStack it) {
if (isItem(it)) {
return switch (it.getType()) {
Expand Down Expand Up @@ -108,7 +112,6 @@ default boolean isShovel(ItemStack it) {
default -> false;
};
}

return false;
}

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/volmit/adapt/api/xp/NewtonCurve.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ default double computeLevelForXP(double xp, double maxError) {
if (last) {
jumpSize /= div;
}

last = false;
cursor += jumpSize;
} else {
Expand All @@ -49,7 +48,6 @@ default double computeLevelForXP(double xp, double maxError) {
cursor -= jumpSize;
}
}

return cursor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public void on(BlockBreakEvent e) {
J.a(() -> vfxSingleCubeOutline(e.getBlock(), Particle.REVERSE_PORTAL));
}
e.getBlock().breakNaturally();
xp(p, 3);
}
}
}
Expand Down
Loading

0 comments on commit 1584cff

Please sign in to comment.