Skip to content

Commit

Permalink
Merge pull request #15 from Sefiraat/dev
Browse files Browse the repository at this point in the history
Fix Fans, Gadgets, Rejig guide, Stats and Metrics
  • Loading branch information
Sefiraat authored Nov 6, 2021
2 parents 53017d0 + 460791b commit 23118b0
Show file tree
Hide file tree
Showing 29 changed files with 673 additions and 514 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,31 @@
import io.github.sefiraat.crystamaehistoria.config.ConfigManager;
import io.github.sefiraat.crystamaehistoria.listeners.ListenerManager;
import io.github.sefiraat.crystamaehistoria.magic.CastInformation;
import io.github.sefiraat.crystamaehistoria.magic.SpellType;
import io.github.sefiraat.crystamaehistoria.magic.spells.core.MagicFallingBlock;
import io.github.sefiraat.crystamaehistoria.magic.spells.core.MagicProjectile;
import io.github.sefiraat.crystamaehistoria.magic.spells.core.MagicSummon;
import io.github.sefiraat.crystamaehistoria.magic.spells.core.Spell;
import io.github.sefiraat.crystamaehistoria.runnables.RunnableManager;
import io.github.sefiraat.crystamaehistoria.runnables.spells.SpellTickRunnable;
import io.github.sefiraat.crystamaehistoria.slimefun.Gadgets;
import io.github.sefiraat.crystamaehistoria.slimefun.ItemGroups;
import io.github.sefiraat.crystamaehistoria.slimefun.Mechanisms;
import io.github.sefiraat.crystamaehistoria.slimefun.Materials;
import io.github.sefiraat.crystamaehistoria.slimefun.Mechanisms;
import io.github.sefiraat.crystamaehistoria.slimefun.Tools;
import io.github.sefiraat.crystamaehistoria.stories.StoriedBlockDefinition;
import io.github.sefiraat.crystamaehistoria.stories.StoriesManager;
import io.github.sefiraat.crystamaehistoria.utils.CrystaTag;
import io.github.sefiraat.crystamaehistoria.utils.PlayerStatUtils;
import io.github.thebusybiscuit.slimefun4.libraries.dough.collections.Pair;
import org.apache.commons.lang.Validate;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.AdvancedPie;
import org.bukkit.plugin.PluginManager;

import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

Expand Down Expand Up @@ -141,23 +148,68 @@ public void enable() {
setupSlimefun();
configManager.setupConfigs();

new Metrics(this, 12065);
setupBstats();

getAddonCommand().addSub(new TestSpell());
CrystaTag.getCachedValues();
}

private void setupBstats() {
Metrics metrics = new Metrics(this, 12065);

AdvancedPie disabledSpellsChart = new AdvancedPie("disabled_spells", () -> {
Map<String, Integer> values = new HashMap<>();
for (SpellType spellType : SpellType.getCachedValues()) {
Spell spell = spellType.getSpell();
values.put(spell.getId(), spell.isEnabled() ? 0 : 1);
}
return values;
});

AdvancedPie spellsCastChart = new AdvancedPie("spells_cast", () -> {
Map<String, Integer> values = new HashMap<>();
for (SpellType spellType : SpellType.getCachedValues()) {
Spell spell = spellType.getSpell();
int timesCast = 0;
for (String string : CrystamaeHistoria.getConfigManager().getPlayerStats().getKeys(false)) {
UUID uuid = UUID.fromString(string);
timesCast += PlayerStatUtils.getUsages(uuid, spellType);
}
values.put(spell.getId(), timesCast);
}
return values;
});

AdvancedPie storiesChronicled = new AdvancedPie("stories_chronicled", () -> {
Map<String, Integer> values = new HashMap<>();
for (StoriedBlockDefinition definition : CrystamaeHistoria.getStoriesManager().getStoriedBlockDefinitionMap().values()) {
int timesChronicled = 0;
for (String string : CrystamaeHistoria.getConfigManager().getPlayerStats().getKeys(false)) {
UUID uuid = UUID.fromString(string);
timesChronicled += PlayerStatUtils.getChronicle(uuid, definition);
}
values.put(definition.getMaterial().toString(), timesChronicled);
}
return values;
});

metrics.addCustomChart(disabledSpellsChart);
metrics.addCustomChart(spellsCastChart);
metrics.addCustomChart(storiesChronicled);
}

@Override
protected void disable() {
spellMemory.clearAll();
saveConfig();
configManager.saveAll();
instance = null;
}

private void setupSlimefun() {
ItemGroups.setup();
Materials.setup();
Mechanisms.setup();
Gadgets.setup();
Tools.setup();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.sefiraat.crystamaehistoria;

import io.github.sefiraat.crystamaehistoria.magic.CastInformation;
import io.github.sefiraat.crystamaehistoria.magic.SpellType;
import io.github.sefiraat.crystamaehistoria.magic.spells.core.MagicFallingBlock;
import io.github.sefiraat.crystamaehistoria.magic.spells.core.MagicProjectile;
import io.github.sefiraat.crystamaehistoria.magic.spells.core.MagicSummon;
Expand All @@ -13,6 +14,7 @@
import org.bukkit.block.Block;
import org.bukkit.entity.Player;

import java.util.EnumMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand All @@ -35,6 +37,8 @@ public class SpellMemory {
private final Map<MagicSummon, Long> summonedEntities = new HashMap<>();
@Getter
private final Map<UUID, Long> playersWithFlight = new HashMap<>();
@Getter
private final Map<SpellType, Integer> spellsCast = new EnumMap<>(SpellType.class);

public void clearAll() {
// Cancels all outstanding spells being cast
Expand Down Expand Up @@ -62,6 +66,9 @@ public void clearAll() {
// Remove and disable all players flight
removeFlight(true);
playersWithFlight.clear();

// Clear spells cast amount
spellsCast.clear();
}

public void removeProjectiles(boolean forceRemoveAll) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ protected void execute(CommandSender sender, String[] args) {
return;
}
int power = Integer.parseInt(args[1]);
SpellType.getById(args[0]).castSpell(new CastInformation((Player) sender, power));
if (power <= 5) {
SpellType.getById(args[0]).castSpell(new CastInformation((Player) sender, power));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ConfigManager {

private final FileConfiguration blocks;
private final FileConfiguration stories;
private final FileConfiguration research;
private final FileConfiguration playerStats;
private final FileConfiguration blockColors;
private final FileConfiguration spells;

Expand All @@ -25,8 +25,8 @@ public ConfigManager() {
this.blocks.options().copyDefaults(true);
this.stories = getConfig("generic-stories.yml");
this.stories.options().copyDefaults(true);
this.research = getConfig("research.yml");
this.research.options().copyDefaults(true);
this.playerStats = getConfig("player_stats.yml");
this.playerStats.options().copyDefaults(true);
this.blockColors = getConfig("block_colors.yml");
this.blockColors.options().copyDefaults(true);
this.spells = getConfig("spells.yml");
Expand All @@ -52,15 +52,6 @@ private FileConfiguration getConfig(String fileName) {
return yaml;
}

public void saveResearches() {
File file = new File(CrystamaeHistoria.getInstance().getDataFolder(), "research.yml");
try {
research.save(file);
} catch (IOException exception) {
exception.printStackTrace();
}
}

public boolean spellEnabled(Spell spell) {
return spells.getBoolean(spell.getId());
}
Expand All @@ -81,4 +72,18 @@ public void setupConfigs() {
}
}

public void saveAll() {
CrystamaeHistoria.getInstance().getLogger().info("Crystamae saving data.");
CrystamaeHistoria.getInstance().getConfig().save();
saveResearches();
}

private void saveResearches() {
File file = new File(CrystamaeHistoria.getInstance().getDataFolder(), "player_stats.yml");
try {
playerStats.save(file);
} catch (IOException exception) {
exception.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.LightningStrike;
import org.bukkit.entity.LivingEntity;
Expand All @@ -26,7 +25,6 @@
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityInteractEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.player.PlayerEggThrowEvent;
import org.bukkit.event.player.PlayerQuitEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.Compass;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.CurificationRitual;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.Deity;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.Gravity;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.Hearthstone;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.PhantomsFlight;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.EarthNova;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.EndermansVeil;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.EtherealFlow;
Expand All @@ -30,11 +27,13 @@
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.Fireball;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.FlameSprite;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.FrostNova;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.Gravity;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.Gyroscopic;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.HarmonysSonata;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.HarvestMoon;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.Heal;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.HealingMist;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.Hearthstone;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.Hellscape;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.HolyCow;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.ImbueVoid;
Expand All @@ -43,6 +42,7 @@
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.LeechBomb;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.LovePotion;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.Oviparous;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.PhantomsFlight;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.PhilosophersStone;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.PlutosDecent;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.PoisonNova;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.github.sefiraat.crystamaehistoria.magic.CastInformation;
import io.github.sefiraat.crystamaehistoria.magic.CastResult;
import io.github.sefiraat.crystamaehistoria.magic.SpellType;
import io.github.sefiraat.crystamaehistoria.utils.PlayerStatUtils;
import io.github.sefiraat.crystamaehistoria.utils.theme.ThemeType;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -79,6 +80,7 @@ public CastResult tryCastSpell(CastInformation castInformation) {
this.crysta -= crystaCost;
final long cdSeconds = (long) (spell.getCooldownSeconds(castInformation) * 1000);
this.cooldown = System.currentTimeMillis() + cdSeconds;
PlayerStatUtils.addUsage(castInformation.getCaster(), storedSpell);
return CastResult.CAST_SUCCESS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.bukkit.Location;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.Projectile;
import org.bukkit.util.Vector;

import javax.annotation.Nonnull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package io.github.sefiraat.crystamaehistoria.runnables;

import io.github.sefiraat.crystamaehistoria.CrystamaeHistoria;
import io.github.sefiraat.crystamaehistoria.runnables.spells.TemporaryEffectsRunnable;
import lombok.Getter;

public class RunnableManager {

@Getter
public final TemporaryEffectsRunnable temporaryEffectsRunnable;
@Getter
public final SaveConfigRunnable saveConfigRunnable;

public RunnableManager() {
CrystamaeHistoria plugin = CrystamaeHistoria.getInstance();

this.temporaryEffectsRunnable = new TemporaryEffectsRunnable();
this.temporaryEffectsRunnable.runTaskTimer(plugin, 1, 20);

this.saveConfigRunnable = new SaveConfigRunnable();
this.saveConfigRunnable.runTaskTimer(plugin, 1, 1200);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.github.sefiraat.crystamaehistoria.runnables;

import io.github.sefiraat.crystamaehistoria.CrystamaeHistoria;
import org.bukkit.scheduler.BukkitRunnable;

public class SaveConfigRunnable extends BukkitRunnable {

@Override
public void run() {
CrystamaeHistoria.getConfigManager().saveAll();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.sefiraat.crystamaehistoria.runnables.spells;
package io.github.sefiraat.crystamaehistoria.runnables;

import io.github.sefiraat.crystamaehistoria.CrystamaeHistoria;
import io.github.sefiraat.crystamaehistoria.SpellMemory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.sefiraat.crystamaehistoria.runnables.animation;
package io.github.sefiraat.crystamaehistoria.runnables.spells;

import io.github.sefiraat.crystamaehistoria.utils.ArmourStandUtils;
import org.bukkit.entity.ArmorStand;
Expand Down
Loading

0 comments on commit 23118b0

Please sign in to comment.