Skip to content

Commit

Permalink
Merge pull request #18 from Sefiraat/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Sefiraat authored Nov 9, 2021
2 parents 2cc307b + 9f72030 commit e90b67e
Show file tree
Hide file tree
Showing 65 changed files with 1,028 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

import de.slikey.effectlib.EffectManager;
import io.github.mooy1.infinitylib.core.AbstractAddon;
import io.github.sefiraat.crystamaehistoria.commands.OpenSpellCompendium;
import io.github.sefiraat.crystamaehistoria.commands.OpenStoryCompendium;
import io.github.sefiraat.crystamaehistoria.commands.TestSpell;
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.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.runnables.RunnableManager;
import io.github.sefiraat.crystamaehistoria.runnables.spells.SpellTickRunnable;
import io.github.sefiraat.crystamaehistoria.slimefun.Gadgets;
Expand Down Expand Up @@ -151,6 +153,9 @@ public void enable() {
setupBstats();

getAddonCommand().addSub(new TestSpell());
getAddonCommand().addSub(new OpenSpellCompendium());
getAddonCommand().addSub(new OpenStoryCompendium());

CrystaTag.getCachedValues();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
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;
import io.github.sefiraat.crystamaehistoria.magic.DisplayItem;
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.runnables.spells.SpellTickRunnable;
import io.github.thebusybiscuit.slimefun4.libraries.dough.blocks.BlockPosition;
import io.github.thebusybiscuit.slimefun4.libraries.dough.collections.Pair;
Expand All @@ -15,7 +15,6 @@
import org.bukkit.entity.Player;
import org.bukkit.util.BoundingBox;

import java.util.EnumMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand Down Expand Up @@ -43,7 +42,7 @@ public class SpellMemory {
@Getter
private final Map<BoundingBox, Long> noSpawningAreas = new HashMap<>();
@Getter
private final Map<SpellType, Integer> spellsCast = new EnumMap<>(SpellType.class);
private final Map<DisplayItem, Long> displayItems = new HashMap<>();

public void clearAll() {
// Cancels all outstanding spells being cast
Expand Down Expand Up @@ -76,12 +75,14 @@ public void clearAll() {
removeEnderman(true);
inhibitedEndermen.clear();

// Reenable Chunk Spawning
// Re-enable Chunk Spawning
enableSpawningInArea(true);
noSpawningAreas.clear();

// Clear spells cast amount
spellsCast.clear();
// Remove Floating display items
removeDisplayItems(true);
displayItems.clear();

}

public void removeProjectiles(boolean forceRemoveAll) {
Expand Down Expand Up @@ -162,6 +163,17 @@ public void enableSpawningInArea(boolean forceRemoveAll) {
}
}

public void removeDisplayItems(boolean forceRemoveAll) {
long time = System.currentTimeMillis();
final Set<Map.Entry<DisplayItem, Long>> set = new HashSet<>(displayItems.entrySet());
for (Map.Entry<DisplayItem, Long> entry : set) {
if (forceRemoveAll || entry.getValue() < time) {
entry.getKey().kill();
displayItems.remove(entry.getKey());
}
}
}

public void removeFlight(Player player) {
if (playersWithFlight.containsKey(player.getUniqueId())) {
player.setAllowFlight(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package io.github.sefiraat.crystamaehistoria.commands;

import io.github.mooy1.infinitylib.commands.SubCommand;
import io.github.sefiraat.crystamaehistoria.magic.CastInformation;
import io.github.sefiraat.crystamaehistoria.magic.SpellType;
import io.github.sefiraat.crystamaehistoria.magic.spells.core.Spell;
import io.github.sefiraat.crystamaehistoria.slimefun.ItemGroups;
import io.github.sefiraat.crystamaehistoria.slimefun.itemgroups.SpellCollectionFlexGroup;
import io.github.sefiraat.crystamaehistoria.utils.theme.ThemeType;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

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

public class OpenSpellCompendium extends SubCommand {

public OpenSpellCompendium() {
super("spells", "Opens the spell compendium", false);
}

@Override
@ParametersAreNonnullByDefault
protected void execute(CommandSender sender, String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(player.getUniqueId());
Optional<PlayerProfile> playerProfile = PlayerProfile.find(offlinePlayer);
playerProfile.ifPresent(profile -> ItemGroups.SPELL_COLLECTION.open(player, profile, SlimefunGuideMode.SURVIVAL_MODE));
}
}

@Override
@ParametersAreNonnullByDefault
protected void complete(CommandSender commandSender, String[] strings, List<String> list) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.github.sefiraat.crystamaehistoria.commands;

import io.github.mooy1.infinitylib.commands.SubCommand;
import io.github.sefiraat.crystamaehistoria.slimefun.ItemGroups;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

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

public class OpenStoryCompendium extends SubCommand {

public OpenStoryCompendium() {
super("stories", "Opens the story compendium", false);
}

@Override
@ParametersAreNonnullByDefault
protected void execute(CommandSender sender, String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(player.getUniqueId());
Optional<PlayerProfile> playerProfile = PlayerProfile.find(offlinePlayer);
playerProfile.ifPresent(profile -> ItemGroups.STORY_COLLECTION.open(player, profile, SlimefunGuideMode.SURVIVAL_MODE));
}
}

@Override
@ParametersAreNonnullByDefault
protected void complete(CommandSender commandSender, String[] strings, List<String> list) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import io.github.mooy1.infinitylib.commands.SubCommand;
import io.github.sefiraat.crystamaehistoria.magic.CastInformation;
import io.github.sefiraat.crystamaehistoria.magic.SpellType;
import io.github.sefiraat.crystamaehistoria.magic.spells.core.Spell;
import io.github.sefiraat.crystamaehistoria.utils.theme.ThemeType;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

Expand All @@ -12,19 +14,25 @@
public class TestSpell extends SubCommand {

public TestSpell() {
super("cast", "Casts the selected spell", true);
super("test-spell", "Casts the selected spell", true);
}

@Override
@ParametersAreNonnullByDefault
protected void execute(CommandSender sender, String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;
if (args.length != 2) {
return;
}
int power = Integer.parseInt(args[1]);
if (power <= 5) {
SpellType.getById(args[0]).castSpell(new CastInformation((Player) sender, power));
Spell spell = SpellType.getById(args[0]);
if (spell != null) {
spell.castSpell(new CastInformation((Player) sender, power));
} else {
player.sendMessage(ThemeType.ERROR.getColor() + "Spell does not exist or is very broken!");
}
}
}
}
Expand All @@ -33,7 +41,7 @@ protected void execute(CommandSender sender, String[] args) {
@ParametersAreNonnullByDefault
protected void complete(CommandSender commandSender, String[] strings, List<String> list) {
if (strings.length == 1) {
for (SpellType spell : SpellType.getCachedValues()) {
for (SpellType spell : SpellType.getEnabledSpells()) {
list.add(spell.name());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.github.sefiraat.crystamaehistoria.listeners;

import io.github.sefiraat.crystamaehistoria.utils.Keys;
import io.github.thebusybiscuit.slimefun4.libraries.dough.data.persistent.PersistentDataAPI;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryPickupItemEvent;

public class DisplayItemListener implements Listener {

@EventHandler
public void onArmorStandManipulate(InventoryPickupItemEvent e) {
if (PersistentDataAPI.hasBoolean(e.getItem(), Keys.PDC_IS_DISPLAY_ITEM)) {
e.setCancelled(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ public ListenerManager() {
addListener(new BlockRemovalListener());
addListener(new MaintenanceListener());
addListener(new RefractingLensListener());
addListener(new ThaumaturgicSaltsListener());
addListener(new EndermanInhibitorListener());
addListener(new MobCandleListener());
addListener(new DisplayItemListener());
}

private void addListener(Listener listener) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
package io.github.sefiraat.crystamaehistoria.listeners;

import io.github.sefiraat.crystamaehistoria.magic.DisplayItem;
import io.github.sefiraat.crystamaehistoria.slimefun.Materials;
import io.github.sefiraat.crystamaehistoria.slimefun.mechanisms.gadgets.ExpCollector;
import io.github.sefiraat.crystamaehistoria.slimefun.mechanisms.liquefactionbasin.LiquefactionBasin;
import io.github.sefiraat.crystamaehistoria.slimefun.mechanisms.liquefactionbasin.LiquefactionBasinCache;
import io.github.sefiraat.crystamaehistoria.slimefun.tools.RefactingLens;
import io.github.sefiraat.crystamaehistoria.stories.definition.StoryType;
import io.github.sefiraat.crystamaehistoria.utils.ParticleUtils;
import io.github.sefiraat.crystamaehistoria.utils.theme.ThemeType;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.TextComponent.Builder;
import net.kyori.adventure.text.format.TextDecoration;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;

import java.util.Map;

Expand All @@ -37,45 +42,62 @@ public void onInteract(PlayerInteractEvent e) {
if (item instanceof LiquefactionBasin) {
liquefactionBasin(player, item, block);
} else if (item instanceof ExpCollector) {
expCollector(player, item, block);
expCollector(item, block);
}
}
}

private void liquefactionBasin(Player player, SlimefunItem blockItem, Block clickedBlock) {
final Location location = clickedBlock.getLocation().add(0.5, 1, 0.5);
final LiquefactionBasin basin = (LiquefactionBasin) blockItem;
final LiquefactionBasinCache cache = basin.getCacheMap().get(clickedBlock.getLocation());
final Builder component = Component.text();
boolean first = true;
for (Map.Entry<StoryType, Integer> entry : cache.getContentMap().entrySet()) {
if (first) {
first = false;
} else {
component.append(
Component.text()
.content(" | ")
.color(ThemeType.PASSIVE.getComponentColor()));
}
component.append(
Component.text()
.content(String.valueOf(entry.getValue()))
.color(ThemeType.getByType(entry.getKey()).getComponentColor())
final Map<StoryType, Integer> cacheMap = basin.getCacheMap().get(clickedBlock.getLocation()).getContentMap();

final double space = 0.5;
final int numberToDisplay = cacheMap.size();
final int mod = (numberToDisplay % 2);
final double evenOffset = mod == 0 ? space / 2 : 0;

double xPos = (space * (numberToDisplay - mod));

for (Map.Entry<StoryType, Integer> entry : cacheMap.entrySet()) {
final Integer integer = entry.getValue();
final StoryType storyType = entry.getKey();
final ItemStack itemStack = Materials.DUMMY_CRYSTAL_MAP.get(storyType).getItem().clone();
final double xOffset = (space * xPos) - evenOffset;

final Vector pointVector = new Vector(xOffset, 0, 0)
.rotateAroundY(-(player.getLocation().getYaw() * (Math.PI / 180)));

final DisplayItem displayItem = new DisplayItem(
itemStack,
location.clone().add(pointVector),
ThemeType.getByType(storyType).getColor() + String.valueOf(integer),
item -> {
Particle.DustOptions dustOptions = ThemeType.getByType(storyType).getDustOptions(1);
ParticleUtils.displayParticleEffect(item, 0.3, 4, dustOptions);
}
);

displayItem.registerRemoval(3000);
xPos--;
}
player.sendActionBar(component.build());
}

private void expCollector(Player player, SlimefunItem blockItem, Block clickedBlock) {
private void expCollector(SlimefunItem blockItem, Block clickedBlock) {
final ExpCollector collector = (ExpCollector) blockItem;
final Location location = clickedBlock.getLocation();
final int volume = collector.getVolumeMap().get(clickedBlock.getLocation());
final TextComponent component = Component.text()
.append(Component.text("Exp Stored: ")
.color(ThemeType.CLICK_INFO.getComponentColor())
.decoration(TextDecoration.BOLD, true))
.append(Component.text(String.valueOf(volume))
.color(ThemeType.PASSIVE.getComponentColor()))
.build();
player.sendActionBar(component);
final ItemStack itemStack = new ItemStack(Material.EXPERIENCE_BOTTLE);
final DisplayItem displayItem = new DisplayItem(
itemStack,
location.clone().add(0.5, 1, 0.5),
ChatColor.GREEN + String.valueOf(volume),
item -> {
Particle.DustOptions dustOptions = new Particle.DustOptions(Color.GREEN, 1);
ParticleUtils.displayParticleEffect(item, 0.3, 4, dustOptions);
}
);
displayItem.registerRemoval(3000);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import io.github.sefiraat.crystamaehistoria.CrystamaeHistoria;
import io.github.sefiraat.crystamaehistoria.magic.CastInformation;
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.spellobjects.MagicFallingBlock;
import io.github.sefiraat.crystamaehistoria.magic.spells.spellobjects.MagicProjectile;
import io.github.sefiraat.crystamaehistoria.utils.Keys;
import io.github.sefiraat.crystamaehistoria.utils.datatypes.DataTypeMethods;
import io.github.sefiraat.crystamaehistoria.utils.datatypes.PersistentUUIDDataType;
Expand Down
Loading

0 comments on commit e90b67e

Please sign in to comment.