Skip to content

Commit

Permalink
Merge pull request #20 from Sefiraat/dev
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
Sefiraat authored Nov 10, 2021
2 parents ed6cda2 + 711576a commit 64f5589
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,11 @@ public void enable() {
this.spellMemory = new SpellMemory();
this.effectManager = new EffectManager(this);

configManager.loadConfig();

SpellType.setupEnabledSpells();

setupSlimefun();
configManager.setupConfigs();

setupBstats();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.github.sefiraat.crystamaehistoria.CrystamaeHistoria;
import io.github.sefiraat.crystamaehistoria.magic.SpellType;
import io.github.sefiraat.crystamaehistoria.magic.spells.core.Spell;
import io.github.sefiraat.crystamaehistoria.slimefun.mechanisms.liquefactionbasin.LiquefactionBasinCache;
import lombok.Getter;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
Expand Down Expand Up @@ -56,7 +57,7 @@ public boolean spellEnabled(Spell spell) {
return spells.getBoolean(spell.getId());
}

public void setupConfigs() {
public void loadConfig() {
// Spells
for (SpellType spellType : SpellType.getCachedValues()) {
Spell spell = spellType.getSpell();
Expand All @@ -69,6 +70,11 @@ public void setupConfigs() {
exception.printStackTrace();
}
}
boolean enabled = spells.getBoolean(spell.getId());
spell.setEnabled(enabled);
if (enabled) {
LiquefactionBasinCache.addSpellRecipe(spellType, spell.getRecipe());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,12 @@ public enum SpellType {
@Getter
protected static final SpellType[] cachedValues = values();
@Getter
protected static final SpellType[] enabledSpells = Arrays.stream(values())
.filter(spellType -> spellType.getSpell().isEnabled())
.toArray(SpellType[]::new);
protected static SpellType[] enabledSpells;
@Getter
private final Spell spell;

@ParametersAreNonnullByDefault
SpellType(Spell spell) {
spell.setEnabled(CrystamaeHistoria.getConfigManager().spellEnabled(spell));
if (spell.isEnabled()) {
LiquefactionBasinCache.addSpellRecipe(this, spell.getRecipe());
}
this.spell = spell;
}

Expand Down Expand Up @@ -196,4 +190,10 @@ public void cast(CastInformation castInformation) {
this.spell.castSpell(castInformation);
}

public static void setupEnabledSpells() {
enabledSpells = Arrays.stream(values())
.filter(spellType -> spellType.getSpell().isEnabled())
.toArray(SpellType[]::new);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void cast(CastInformation castInformation) {
if (location.getBlock().isEmpty()) {
final MagicProjectile projectile = SpellUtils.summonMagicProjectile(castInformation, EntityType.SPECTRAL_ARROW, pointLocation, this::onTick);
projectile.getProjectile().setGravity(false);
projectile.setVelocity(location.getDirection(), 1);
projectile.setVelocity(caster.getEyeLocation().getDirection(), 1);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ public enum CrystaTag implements Tag<Material> {
CrystaTag() {
final String name = this.name().toLowerCase(Locale.ROOT);
final String fileLocation = "/tags/" + name + ".json";
final JsonParser parser = new JsonParser();

try {
final InputStream stream = CrystamaeHistoria.class.getResourceAsStream(fileLocation);
final JsonReader reader = new JsonReader(new InputStreamReader(stream));
final JsonObject object = (JsonObject) JsonParser.parseReader(reader);
final JsonObject object = (JsonObject) parser.parse(reader);

for (JsonElement element : object.get("values").getAsJsonArray()) {
final String tagString = element.getAsString();
Expand Down
Loading

0 comments on commit 64f5589

Please sign in to comment.