Skip to content

Commit

Permalink
Dev/v1 (#9)
Browse files Browse the repository at this point in the history
* Format, fixes and organisation

* Chaos and Break hardness + perms

* PhantomsFlight, Hearthstone, Tracer, Compass

* Gravity
  • Loading branch information
Sefiraat authored Nov 1, 2021
1 parent e1a6c8b commit 597fdc6
Show file tree
Hide file tree
Showing 60 changed files with 2,022 additions and 375 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/bin/
/lib/
/.settings/
/target/
/.idea/
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
import io.github.sefiraat.crystamaehistoria.magic.spells.core.MagicProjectile;
import io.github.sefiraat.crystamaehistoria.magic.spells.core.MagicSummon;
import io.github.sefiraat.crystamaehistoria.runnables.RunnableManager;
import io.github.sefiraat.crystamaehistoria.runnables.spells.SpellTick;
import io.github.sefiraat.crystamaehistoria.runnables.spells.SpellTickRunnable;
import io.github.sefiraat.crystamaehistoria.slimefun.Structure;
import io.github.sefiraat.crystamaehistoria.stories.StoriesManager;
import io.github.sefiraat.crystamaehistoria.utils.CrystaTag;
import io.github.thebusybiscuit.slimefun4.libraries.dough.collections.Pair;
import org.apache.commons.lang.Validate;
import org.bstats.bukkit.Metrics;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.PluginManager;

import javax.annotation.Nonnull;
Expand All @@ -33,7 +32,7 @@ public class CrystamaeHistoria extends AbstractAddon {
private StoriesManager storiesManager;
private ListenerManager listenerManager;
private RunnableManager runnableManager;
private ActiveStorage activeStorage;
private SpellMemory spellMemory;
private EffectManager effectManager;

public CrystamaeHistoria() {
Expand All @@ -60,8 +59,8 @@ public static StoriesManager getStoriesManager() {
return instance.storiesManager;
}

public static ActiveStorage getActiveStorage() {
return instance.activeStorage;
public static SpellMemory getActiveStorage() {
return instance.spellMemory;
}

public static EffectManager getEffectManager() {
Expand All @@ -78,17 +77,17 @@ public static PluginManager getPluginManager() {

@Nonnull
public static Map<MagicProjectile, Pair<CastInformation, Long>> getProjectileMap() {
return instance.activeStorage.getProjectileMap();
return instance.spellMemory.getProjectileMap();
}

@Nonnull
public static Map<UUID, Pair<CastInformation, Long>> getStrikeMap() {
return instance.activeStorage.getStrikeMap();
return instance.spellMemory.getStrikeMap();
}

@Nonnull
public static Map<MagicSummon, Long> getSummonedEntityMap() {
return instance.activeStorage.getSummonedEntities();
return instance.spellMemory.getSummonedEntities();
}

@Nonnull
Expand All @@ -108,8 +107,8 @@ public static CastInformation getStrikeCastInfo(UUID lightningStrike) {
}

@Nonnull
public static Map<SpellTick, Integer> getTickingMap() {
return instance.activeStorage.getTickingCastables();
public static Map<SpellTickRunnable, Integer> getTickingMap() {
return instance.spellMemory.getTickingCastables();
}

@Override
Expand All @@ -125,7 +124,7 @@ public void enable() {
this.storiesManager = new StoriesManager();
this.listenerManager = new ListenerManager();
this.runnableManager = new RunnableManager();
this.activeStorage = new ActiveStorage();
this.spellMemory = new SpellMemory();
this.effectManager = new EffectManager(this);

structure.setup();
Expand All @@ -138,7 +137,7 @@ public void enable() {

@Override
protected void disable() {
activeStorage.clearAll();
spellMemory.clearAll();
saveConfig();
instance = null;
}
Expand Down
122 changes: 122 additions & 0 deletions src/main/java/io/github/sefiraat/crystamaehistoria/SpellMemory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package io.github.sefiraat.crystamaehistoria;

import io.github.sefiraat.crystamaehistoria.magic.CastInformation;
import io.github.sefiraat.crystamaehistoria.magic.spells.core.MagicProjectile;
import io.github.sefiraat.crystamaehistoria.magic.spells.core.MagicSummon;
import io.github.sefiraat.crystamaehistoria.runnables.spells.SpellTickRunnable;
import io.github.thebusybiscuit.slimefun4.libraries.dough.blocks.BlockPosition;
import io.github.thebusybiscuit.slimefun4.libraries.dough.collections.Pair;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

public class SpellMemory {

@Getter
private final Map<MagicProjectile, Pair<CastInformation, Long>> projectileMap = new HashMap<>();
@Getter
private final Map<UUID, Pair<CastInformation, Long>> strikeMap = new HashMap<>();
@Getter
private final Map<SpellTickRunnable, Integer> tickingCastables = new HashMap<>();
@Getter
private final Map<BlockPosition, Long> blocksToRemove = new HashMap<>();
@Getter
private final Map<MagicSummon, Long> summonedEntities = new HashMap<>();
@Getter
private final Map<UUID, Long> playersWithFlight = new HashMap<>();

public void clearAll() {
// Cancels all outstanding spells being cast
for (SpellTickRunnable spellTickRunnable : tickingCastables.keySet()) {
spellTickRunnable.cancel();
}
tickingCastables.clear();

// Clear all projectiles created from spells
removeProjectiles(true);
projectileMap.clear();

// Clear all spawned entities created from spells
removeEntities(true);
summonedEntities.clear();

// Remove all temporary blocks
removeBlocks(true);
blocksToRemove.clear();

// Remove all temporary blocks
removeFlight(true);
playersWithFlight.clear();
}

public void removeProjectiles(boolean forceRemoveAll) {
Set<MagicProjectile> set = new HashSet<>(CrystamaeHistoria.getProjectileMap().keySet());
for (MagicProjectile magicProjectile : set) {
long expiry = projectileMap.get(magicProjectile).getSecondValue();
if (System.currentTimeMillis() > expiry || forceRemoveAll) {
magicProjectile.kill();
} else {
magicProjectile.run();
}
}
}

public void removeEntities(boolean forceRemoveAll) {
Set<MagicSummon> set = new HashSet<>(CrystamaeHistoria.getSummonedEntityMap().keySet());
for (MagicSummon magicSummon : set) {
long expiry = summonedEntities.get(magicSummon);
if (System.currentTimeMillis() > expiry || magicSummon.getMob() == null || forceRemoveAll) {
magicSummon.kill();
} else {
magicSummon.run();
}
}
}

public void removeBlocks(boolean forceRemoveAll) {
long time = System.currentTimeMillis();
final Set<Map.Entry<BlockPosition, Long>> set = new HashSet<>(blocksToRemove.entrySet());
for (Map.Entry<BlockPosition, Long> entry : set) {
if (forceRemoveAll || entry.getValue() < time) {
entry.getKey().getBlock().setType(Material.AIR);
blocksToRemove.remove(entry.getKey());
}
}
}

public void removeFlight(boolean forceRemoveAll) {
long time = System.currentTimeMillis();
final Set<Map.Entry<UUID, Long>> set = new HashSet<>(playersWithFlight.entrySet());
for (Map.Entry<UUID, Long> entry : set) {
if (forceRemoveAll || entry.getValue() < time) {
Player player = Bukkit.getPlayer(entry.getKey());
if (player != null) {
player.setAllowFlight(false);
player.setFlying(false);
playersWithFlight.remove(entry.getKey());
}
}
}
}

public void removeFlight(Player player) {
if (playersWithFlight.containsKey(player.getUniqueId())) {
player.setAllowFlight(false);
player.setFlying(false);
playersWithFlight.remove(player.getUniqueId());
}
}

public void stopBlockRemoval(Block block) {
BlockPosition blockPosition = new BlockPosition(block);
blocksToRemove.remove(blockPosition);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//package io.github.sefiraat.crystamaehistoria.commands;
//
//import io.github.mooy1.infinitylib.commands.SubCommand;
//import org.bukkit.Color;
//import org.bukkit.Material;
//import org.bukkit.block.Block;
//import org.bukkit.command.CommandSender;
// import org.bukkit.craftbukkit.v1_17_R1.block.CraftBlock;
//import org.bukkit.entity.Player;
//
//import javax.annotation.ParametersAreNonnullByDefault;
//import java.io.BufferedWriter;
//import java.io.File;
//import java.io.FileWriter;
//import java.io.IOException;
//import java.util.List;
//
//public class GetBlockColors extends SubCommand {
//
// public GetBlockColors() {
// super("block_color", "Generates block colors", true);
// }
//
// @Override
// @ParametersAreNonnullByDefault
// protected void execute(CommandSender sender, String[] args) {
// if (sender instanceof Player) {
// Player player = (Player) sender;
// Block block = player.getLocation().getBlock();
// try (BufferedWriter writer = new BufferedWriter(new FileWriter(new File("block_colors.yml")))) {
// for (Material material : Material.values()) {
// if (material.isBlock()) {
// block.setType(material);
// Color color = Color.fromRGB(((CraftBlock) block).getNMS().getBlock().s().al);
// writeLine(writer,
// material.name() + ": [" +
// + color.getRed() + ", "
// + color.getGreen() + ", "
// + color.getBlue() + "]"
// );
// }
// }
// } catch (IOException exception) {
// exception.printStackTrace();
// }
// }
// }
//
// private static void writeLine(BufferedWriter writer, String line) throws IOException {
// writer.write(line);
// writer.newLine();
// }
//
// @Override
// protected void complete(CommandSender commandSender, String[] strings, List<String> list) {
//
// }
//
//}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class ConfigManager {
private final FileConfiguration blocks;
private final FileConfiguration stories;
private final FileConfiguration research;
private final FileConfiguration blockColors;

public ConfigManager() {
this.blocks = getConfig("blocks.yml");
Expand All @@ -23,6 +24,8 @@ public ConfigManager() {
this.stories.options().copyDefaults(true);
this.research = getConfig("research.yml");
this.research.options().copyDefaults(true);
this.blockColors = getConfig("block_colors.yml");
this.blockColors.options().copyDefaults(true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;

public class RemovalBlocksListener implements Listener {
public class BlockRemovalListener implements Listener {

@EventHandler
public void onRemovableBlockBreak(BlockBreakEvent event) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.github.sefiraat.crystamaehistoria.slimefun.machines.realisationaltar;
package io.github.sefiraat.crystamaehistoria.listeners;

import io.github.sefiraat.crystamaehistoria.CrystamaeHistoria;
import io.github.sefiraat.crystamaehistoria.slimefun.machines.realisationaltar.RealisationAltar;
import io.github.sefiraat.crystamaehistoria.slimefun.machines.realisationaltar.RealisationAltarCache;
import io.github.sefiraat.crystamaehistoria.stories.Story;
import io.github.sefiraat.crystamaehistoria.stories.definition.StoryRarity;
import io.github.sefiraat.crystamaehistoria.stories.definition.StoryShardProfile;
Expand All @@ -27,7 +29,7 @@ public void onBreakCrystal(BlockBreakEvent event) {

private void handleCrystal(Block block) {
BlockPosition blockPosition = new BlockPosition(block);
for (RealisationAltarCache cache : RealisationAltar.CACHE_MAP.values()) {
for (RealisationAltarCache cache : RealisationAltar.getCaches().values()) {
Pair<StoryRarity, String> pair = cache.getCrystalStoryMap().get(blockPosition);
if (pair != null) {
StoryRarity rarity = pair.getFirstValue();
Expand Down
Loading

0 comments on commit 597fdc6

Please sign in to comment.