Skip to content

Commit

Permalink
Merge pull request #21 from Sefiraat/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Sefiraat authored Nov 15, 2021
2 parents 64f5589 + ff965bb commit 48d4461
Show file tree
Hide file tree
Showing 117 changed files with 14,264 additions and 12,175 deletions.
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,6 @@
<version>a2c4b6d</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>LATEST</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.github.mooy1</groupId>
<artifactId>InfinityLib</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.slikey.effectlib.EffectManager;
import io.github.mooy1.infinitylib.core.AbstractAddon;
import io.github.sefiraat.crystamaehistoria.commands.GetRanks;
import io.github.sefiraat.crystamaehistoria.commands.OpenSpellCompendium;
import io.github.sefiraat.crystamaehistoria.commands.OpenStoryCompendium;
import io.github.sefiraat.crystamaehistoria.commands.TestSpell;
Expand All @@ -13,6 +14,7 @@
import io.github.sefiraat.crystamaehistoria.magic.spells.spellobjects.MagicFallingBlock;
import io.github.sefiraat.crystamaehistoria.magic.spells.spellobjects.MagicProjectile;
import io.github.sefiraat.crystamaehistoria.magic.spells.spellobjects.MagicSummon;
import io.github.sefiraat.crystamaehistoria.player.PlayerStatistics;
import io.github.sefiraat.crystamaehistoria.runnables.RunnableManager;
import io.github.sefiraat.crystamaehistoria.runnables.spells.SpellTickRunnable;
import io.github.sefiraat.crystamaehistoria.slimefun.Gadgets;
Expand All @@ -22,7 +24,6 @@
import io.github.sefiraat.crystamaehistoria.slimefun.Tools;
import io.github.sefiraat.crystamaehistoria.stories.BlockDefinition;
import io.github.sefiraat.crystamaehistoria.stories.StoriesManager;
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;
Expand Down Expand Up @@ -157,6 +158,7 @@ public void enable() {
getAddonCommand().addSub(new TestSpell());
getAddonCommand().addSub(new OpenSpellCompendium());
getAddonCommand().addSub(new OpenStoryCompendium());
getAddonCommand().addSub(new GetRanks());
}

private void setupBstats() {
Expand All @@ -178,7 +180,7 @@ private void setupBstats() {
int timesCast = 0;
for (String string : CrystamaeHistoria.getConfigManager().getPlayerStats().getKeys(false)) {
UUID uuid = UUID.fromString(string);
timesCast += PlayerStatUtils.getUsages(uuid, spellType);
timesCast += PlayerStatistics.getUsages(uuid, spellType);
}
values.put(spell.getId(), timesCast);
}
Expand All @@ -191,7 +193,7 @@ private void setupBstats() {
int timesChronicled = 0;
for (String string : CrystamaeHistoria.getConfigManager().getPlayerStats().getKeys(false)) {
UUID uuid = UUID.fromString(string);
timesChronicled += PlayerStatUtils.getChronicle(uuid, definition);
timesChronicled += PlayerStatistics.getChronicle(uuid, definition);
}
values.put(definition.getMaterial().toString(), timesChronicled);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.github.sefiraat.crystamaehistoria.commands;

import io.github.mooy1.infinitylib.commands.SubCommand;
import io.github.sefiraat.crystamaehistoria.player.PlayerStatistics;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;

public class GetRanks extends SubCommand {

public GetRanks() {
super("rank", "Displays your Crystamae ranks", false);
}

@Override
@ParametersAreNonnullByDefault
protected void execute(CommandSender sender, String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;
player.sendMessage(PlayerStatistics.getSpellRankString(player.getUniqueId()));
player.sendMessage(PlayerStatistics.getStoryRankString(player.getUniqueId()));
}
}

@Override
@ParametersAreNonnullByDefault
protected void complete(CommandSender commandSender, String[] strings, List<String> list) {
// Not required
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

@Getter
public class ConfigManager {
Expand All @@ -22,35 +25,42 @@ public class ConfigManager {
private final FileConfiguration spells;

public ConfigManager() {
this.blocks = getConfig("blocks.yml");
this.blocks.options().copyDefaults(true);
this.stories = getConfig("generic-stories.yml");
this.stories.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");
this.spells.options().copyDefaults(true);
this.blocks = getConfig("blocks.yml", true);
this.stories = getConfig("generic-stories.yml", true);
this.playerStats = getConfig("player_stats.yml", false);
this.blockColors = getConfig("block_colors.yml", false);
this.spells = getConfig("spells.yml", false);
}

/**
* @noinspection ResultOfMethodCallIgnored
*/
private FileConfiguration getConfig(String fileName) {
CrystamaeHistoria plugin = CrystamaeHistoria.getInstance();
File file = new File(plugin.getDataFolder(), fileName);
private FileConfiguration getConfig(String fileName, boolean updateWithDefaults) {
final CrystamaeHistoria plugin = CrystamaeHistoria.getInstance();
final File file = new File(plugin.getDataFolder(), fileName);
if (!file.exists()) {
file.getParentFile().mkdirs();
plugin.saveResource(fileName, true);
}
YamlConfiguration yaml = new YamlConfiguration();
final FileConfiguration config = new YamlConfiguration();
try {
yaml.load(file);
config.load(file);
if (updateWithDefaults) {
updateConfig(config, file, fileName);
}
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
return yaml;
return config;
}

private void updateConfig(FileConfiguration config, File file, String fileName) throws IOException {
final InputStream inputStream = CrystamaeHistoria.getInstance().getResource(fileName);
final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
final YamlConfiguration defaults = YamlConfiguration.loadConfiguration(reader);
config.addDefaults(defaults);
config.options().copyDefaults(true);
config.save(file);
}

public boolean spellEnabled(Spell spell) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;

public class CrystalBreakListener implements Listener {

@EventHandler
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBreakCrystal(BlockBreakEvent event) {
Block block = event.getBlock();
if (block.getType() == Material.LARGE_AMETHYST_BUD) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@
import io.github.thebusybiscuit.slimefun4.libraries.dough.data.persistent.PersistentDataAPI;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ItemDespawnEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;

public class DisplayItemListener implements Listener {

@EventHandler
public void onArmorStandManipulate(InventoryPickupItemEvent e) {
public void onItemPickup(InventoryPickupItemEvent e) {
if (PersistentDataAPI.hasBoolean(e.getItem(), Keys.PDC_IS_DISPLAY_ITEM)) {
e.setCancelled(true);
}
}

@EventHandler
public void onItemDespawn(ItemDespawnEvent e) {
if (PersistentDataAPI.hasBoolean(e.getEntity(), Keys.PDC_IS_DISPLAY_ITEM)) {
e.setCancelled(true);
e.getEntity().setTicksLived(1);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package io.github.sefiraat.crystamaehistoria.listeners;

import io.github.sefiraat.crystamaehistoria.slimefun.gadgets.MysteriousTicker;
import io.github.sefiraat.crystamaehistoria.utils.GeneralUtils;
import io.github.sefiraat.crystamaehistoria.utils.StoryUtils;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;

public class MiscListener implements Listener {

Expand All @@ -21,4 +27,24 @@ public void onDontTouchMyCrap(PlayerInteractEvent e) {
}
}
}

@EventHandler
public void onPlaceStoriedBlock(BlockPlaceEvent e) {
ItemStack itemStack = e.getItemInHand();
if (StoryUtils.isStoried(itemStack)) {
e.setCancelled(true);
}
}

@EventHandler(priority = EventPriority.LOWEST)
public void checkCooldown(PlayerInteractEvent event) {
ItemStack itemStack = event.getPlayer().getInventory().getItemInMainHand();
if (itemStack.getType() != Material.AIR
&& (event.getAction() == Action.RIGHT_CLICK_AIR
|| event.getAction() == Action.RIGHT_CLICK_BLOCK)
&& GeneralUtils.isOnCooldown(itemStack)
) {
event.setCancelled(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.github.sefiraat.crystamaehistoria.slimefun.mechanisms.liquefactionbasin.LiquefactionBasin;
import io.github.sefiraat.crystamaehistoria.slimefun.tools.RefactingLens;
import io.github.sefiraat.crystamaehistoria.stories.definition.StoryType;
import io.github.sefiraat.crystamaehistoria.utils.GeneralUtils;
import io.github.sefiraat.crystamaehistoria.utils.ParticleUtils;
import io.github.sefiraat.crystamaehistoria.utils.theme.ThemeType;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
Expand All @@ -18,6 +19,7 @@
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
Expand All @@ -28,7 +30,7 @@

public class RefractingLensListener implements Listener {

@EventHandler
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onInteract(PlayerInteractEvent e) {
final Player player = e.getPlayer();
final SlimefunItem slimefunItem = SlimefunItem.getByItem(player.getInventory().getItemInMainHand());
Expand All @@ -38,6 +40,7 @@ public void onInteract(PlayerInteractEvent e) {
&& slimefunItem instanceof RefactingLens
) {
e.setCancelled(true);
GeneralUtils.putOnCooldown(player.getInventory().getItemInMainHand(), 3);
SlimefunItem item = BlockStorage.check(block);
if (item instanceof LiquefactionBasin) {
liquefactionBasin(player, item, block);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.sefiraat.crystamaehistoria.magic;

import io.github.sefiraat.crystamaehistoria.CrystamaeHistoria;
import io.github.sefiraat.crystamaehistoria.magic.spells.core.Spell;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.AbstractVoid;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.AirNova;
Expand Down Expand Up @@ -71,7 +70,6 @@
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.Tracer;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.Vacuum;
import io.github.sefiraat.crystamaehistoria.magic.spells.tier1.WitherWeather;
import io.github.sefiraat.crystamaehistoria.slimefun.mechanisms.liquefactionbasin.LiquefactionBasinCache;
import lombok.Getter;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -175,6 +173,12 @@ public static Spell getById(String id) {
return null;
}

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

@Nonnull
public String getId() {
return spell.getId();
Expand All @@ -190,10 +194,4 @@ 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 @@ -4,7 +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.player.PlayerStatistics;
import io.github.sefiraat.crystamaehistoria.utils.theme.ThemeType;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -80,7 +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);
PlayerStatistics.addUsage(castInformation.getCaster(), storedSpell);
return CastResult.CAST_SUCCESS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import java.util.ArrayList;
Expand Down Expand Up @@ -70,7 +69,7 @@ public Material getMaterial() {
return Material.GREEN_DYE;
}

@NotNull
@Nonnull
@Override
public RecipeSpell getRecipe() {
return new RecipeSpell(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.bukkit.Particle;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
Expand Down Expand Up @@ -83,7 +82,7 @@ public Material getMaterial() {
return Material.FEATHER;
}

@NotNull
@Nonnull
@Override
public RecipeSpell getRecipe() {
return new RecipeSpell(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.entity.EntityType;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
Expand Down Expand Up @@ -74,7 +73,7 @@ public Material getMaterial() {
return Material.VEX_SPAWN_EGG;
}

@NotNull
@Nonnull
@Override
public RecipeSpell getRecipe() {
return new RecipeSpell(
Expand Down
Loading

0 comments on commit 48d4461

Please sign in to comment.