Skip to content

Commit

Permalink
More stories, Block Ranks, Trophies
Browse files Browse the repository at this point in the history
  • Loading branch information
Sefiraat committed Nov 15, 2021
1 parent 78b19f0 commit ff965bb
Show file tree
Hide file tree
Showing 15 changed files with 902 additions and 404 deletions.
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
Expand Up @@ -2,6 +2,7 @@

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;
Expand All @@ -10,6 +11,7 @@
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;

Expand All @@ -26,6 +28,14 @@ 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();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.github.sefiraat.crystamaehistoria.player;

import io.github.sefiraat.crystamaehistoria.utils.theme.ThemeType;
import lombok.Getter;

public enum BlockRank {

SME(100, ThemeType.RANK_BLOCK_SME),
MASTER_OF(90, ThemeType.RANK_BLOCK_MASTER_OF),
EXPERT_OF(70, ThemeType.RANK_BLOCK_EXPERT_OF),
RESEARCHED(50, ThemeType.RANK_BLOCK_RESEARCHED),
DETAILED(30, ThemeType.RANK_BLOCK_DETAILED),
KNOWN(20, ThemeType.RANK_BLOCK_KNOWN),
HEARD_OF(10, ThemeType.RANK_BLOCK_HEARD_OF),
UNKNOWN(0, ThemeType.RANK_BLOCK_UNKNOWN);

private final double numberRequired;
@Getter
private final ThemeType theme;

BlockRank(double numberRequired, ThemeType themeType) {
this.numberRequired = numberRequired;
this.theme = themeType;
}

public static BlockRank getByAmount(double percent) {
if (percent >= SME.numberRequired) {
return SME;
} else if (percent >= MASTER_OF.numberRequired) {
return MASTER_OF;
} else if (percent >= EXPERT_OF.numberRequired) {
return EXPERT_OF;
} else if (percent >= RESEARCHED.numberRequired) {
return RESEARCHED;
} else if (percent >= DETAILED.numberRequired) {
return DETAILED;
} else if (percent >= KNOWN.numberRequired) {
return KNOWN;
} else if (percent >= HEARD_OF.numberRequired) {
return HEARD_OF;
} else {
return UNKNOWN;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@
import io.github.sefiraat.crystamaehistoria.utils.theme.ThemeType;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;

import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

public class PlayerStatistics {
Expand All @@ -23,7 +20,7 @@ public static void unlockSpell(Player player, SpellType spellType) {
}

public static void unlockSpell(UUID player, SpellType spellType) {
String path = MessageFormat.format("{0}.{1}.{2}.Unlocked", player, StatType.SPELL, spellType.getId());
String path = MessageFormat.format("{0}.{1}.{2}.UNLOCKED", player, StatType.SPELL, spellType.getId());
CrystamaeHistoria.getConfigManager().getPlayerStats().set(path, true);
}

Expand All @@ -32,7 +29,7 @@ public static boolean hasUnlockedSpell(Player player, SpellType spellType) {
}

public static boolean hasUnlockedSpell(UUID player, SpellType spellType) {
String path = MessageFormat.format("{0}.{1}.{2}.Unlocked", player, StatType.SPELL, spellType.getId());
String path = MessageFormat.format("{0}.{1}.{2}.UNLOCKED", player, StatType.SPELL, spellType.getId());
return CrystamaeHistoria.getConfigManager().getPlayerStats().getBoolean(path);
}

Expand All @@ -43,7 +40,7 @@ public static void addUsage(Player player, SpellType spellType) {
public static void addUsage(UUID player, SpellType spellType) {
int uses = getUsages(player, spellType);
uses++;
String path = MessageFormat.format("{0}.{1}.{2}.Times_Cast", player, StatType.SPELL, spellType.getId());
String path = MessageFormat.format("{0}.{1}.{2}.TIMES_CAST", player, StatType.SPELL, spellType.getId());
CrystamaeHistoria.getConfigManager().getPlayerStats().set(path, uses);
}

Expand All @@ -52,7 +49,7 @@ public static int getUsages(Player player, SpellType spellType) {
}

public static int getUsages(UUID player, SpellType spellType) {
String path = MessageFormat.format("{0}.{1}.{2}.Times_Cast", player, StatType.SPELL, spellType.getId());
String path = MessageFormat.format("{0}.{1}.{2}.TIMES_CAST", player, StatType.SPELL, spellType.getId());
return CrystamaeHistoria.getConfigManager().getPlayerStats().getInt(path);
}

Expand All @@ -61,7 +58,7 @@ public static void unlockUniqueStory(Player player, BlockDefinition definition)
}

public static void unlockUniqueStory(UUID player, BlockDefinition definition) {
String path = MessageFormat.format("{0}.{1}.{2}.Unlocked", player, StatType.STORY, definition.getMaterial());
String path = MessageFormat.format("{0}.{1}.{2}.UNLOCKED", player, StatType.STORY, definition.getMaterial());
CrystamaeHistoria.getConfigManager().getPlayerStats().set(path, true);
}

Expand All @@ -74,7 +71,7 @@ public static boolean hasUnlockedUniqueStory(UUID player, BlockDefinition defini
}

public static boolean hasUnlockedUniqueStory(UUID player, Material material) {
String path = MessageFormat.format("{0}.{1}.{2}.Unlocked", player, StatType.STORY, material);
String path = MessageFormat.format("{0}.{1}.{2}.UNLOCKED", player, StatType.STORY, material);
return CrystamaeHistoria.getConfigManager().getPlayerStats().getBoolean(path);
}

Expand All @@ -85,7 +82,7 @@ public static void addChronicle(Player player, BlockDefinition definition) {
public static void addChronicle(UUID player, BlockDefinition definition) {
int uses = getChronicle(player, definition);
uses++;
String path = MessageFormat.format("{0}.{1}.{2}.Times_Chronicled", player, StatType.STORY, definition.getMaterial());
String path = MessageFormat.format("{0}.{1}.{2}.TIMES_CHRONICLED", player, StatType.STORY, definition.getMaterial());
CrystamaeHistoria.getConfigManager().getPlayerStats().set(path, uses);
}

Expand All @@ -94,16 +91,45 @@ public static int getChronicle(Player player, BlockDefinition definition) {
}

public static int getChronicle(UUID player, BlockDefinition definition) {
String path = MessageFormat.format("{0}.{1}.{2}.Times_Chronicled", player, StatType.STORY, definition.getMaterial());
String path = MessageFormat.format("{0}.{1}.{2}.TIMES_CHRONICLED", player, StatType.STORY, definition.getMaterial());
return CrystamaeHistoria.getConfigManager().getPlayerStats().getInt(path);
}

public static void addRealisation(Player player, BlockDefinition definition) {
addChronicle(player.getUniqueId(), definition);
}

public static void addRealisation(UUID player, BlockDefinition definition) {
int uses = getRealisation(player, definition);
uses++;
String path = MessageFormat.format("{0}.{1}.{2}.TIMES_REALISED", player, StatType.STORY, definition.getMaterial());
CrystamaeHistoria.getConfigManager().getPlayerStats().set(path, uses);
}

public static int getRealisation(Player player, BlockDefinition definition) {
return getChronicle(player.getUniqueId(), definition);
}

public static int getRealisation(UUID player, BlockDefinition definition) {
String path = MessageFormat.format("{0}.{1}.{2}.TIMES_REALISED", player, StatType.STORY, definition.getMaterial());
return CrystamaeHistoria.getConfigManager().getPlayerStats().getInt(path);
}

@ParametersAreNonnullByDefault
public static BlockRank getBlockRank(UUID uuid, BlockDefinition definition) {
final int chronicleAmount = Math.min(getChronicle(uuid, definition), 100);
final int realisedAmount = Math.min(getRealisation(uuid, definition), 100);
final int blockValue = (chronicleAmount + realisedAmount) / 2;
return BlockRank.getByAmount(blockValue);
}


public static int getStoriesUnlocked(@Nonnull UUID uuid) {
String path = MessageFormat.format("{0}.{1}", uuid, StatType.STORY);
ConfigurationSection section = CrystamaeHistoria.getConfigManager().getPlayerStats().getConfigurationSection(path);
int unlocked = 0;
for (String story : section.getKeys(false)) {
String storyPath = MessageFormat.format("{0}.{1}.{2}.Unlocked", uuid, StatType.STORY, story);
String storyPath = MessageFormat.format("{0}.{1}.{2}.UNLOCKED", uuid, StatType.STORY, story);
if (CrystamaeHistoria.getConfigManager().getPlayerStats().getBoolean(storyPath)) unlocked++;
}
return unlocked;
Expand Down Expand Up @@ -134,7 +160,7 @@ public static int getSpellsUnlocked(@Nonnull UUID uuid) {
ConfigurationSection section = CrystamaeHistoria.getConfigManager().getPlayerStats().getConfigurationSection(path);
int unlocked = 0;
for (String spell : section.getKeys(false)) {
String storyPath = MessageFormat.format("{0}.{1}.{2}.Unlocked", uuid, StatType.SPELL, spell);
String storyPath = MessageFormat.format("{0}.{1}.{2}.UNLOCKED", uuid, StatType.SPELL, spell);
if (CrystamaeHistoria.getConfigManager().getPlayerStats().getBoolean(storyPath)) unlocked++;
}
return unlocked;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import io.github.sefiraat.crystamaehistoria.slimefun.gadgets.MobLamp;
import io.github.sefiraat.crystamaehistoria.slimefun.gadgets.MobMat;
import io.github.sefiraat.crystamaehistoria.slimefun.gadgets.MysteriousTicker;
import io.github.sefiraat.crystamaehistoria.slimefun.gadgets.TrophyDisplay;
import io.github.sefiraat.crystamaehistoria.slimefun.mechanisms.DisplayStandHolder;
import io.github.sefiraat.crystamaehistoria.slimefun.mechanisms.liquefactionbasin.DummyLiquefactionBasinCrafting;
import io.github.sefiraat.crystamaehistoria.slimefun.mechanisms.liquefactionbasin.LiquefactionBasinCache;
import io.github.sefiraat.crystamaehistoria.slimefun.mechanisms.liquefactionbasin.RecipeItem;
Expand Down Expand Up @@ -74,6 +76,8 @@ public class Gadgets {
private static GreenHouseGlass greenHouseGlass;
@Getter
private static GreenHouseGlass focusedGreenHouseGlass;
@Getter
private static TrophyDisplay trophyDisplay;

public static void setup() {

Expand Down Expand Up @@ -624,6 +628,30 @@ amalgamateDustEpic, new ItemStack(Material.GLASS), amalgamateDustEpic,
10
);

// Trophy Stand
RecipeItem trophyDisplayRecipe = new RecipeItem(
new ItemStack(Material.POLISHED_BLACKSTONE_BRICK_WALL),
StoryType.MECHANICAL, 10,
StoryType.HUMAN, 10,
StoryType.PHILOSOPHICAL, 10
);
trophyDisplay = new TrophyDisplay(
ItemGroups.GADGETS,
ThemeType.themedSlimefunItemStack(
"CRY_TROPHY_DISPLAY_1",
new ItemStack(Material.POLISHED_BLACKSTONE_BRICK_WALL),
ThemeType.GADGET,
"Trophy Display",
"Used to place your trophies on to show",
"off to the world.",
"",
"Currently allowable trophies include:",
ThemeType.CLICK_INFO.getColor() + "A block in which you have a S.M.E. rank"
),
DummyLiquefactionBasinCrafting.TYPE,
trophyDisplayRecipe.getDisplayRecipe()
);

// Slimefun Registry
abstractionLamp.register(plugin);
dispersionLamp.register(plugin);
Expand All @@ -645,6 +673,7 @@ amalgamateDustEpic, new ItemStack(Material.GLASS), amalgamateDustEpic,
mysteriousPlant.register(plugin);
greenHouseGlass.register(plugin);
focusedGreenHouseGlass.register(plugin);
trophyDisplay.register(plugin);

// Liquefaction Recipes
LiquefactionBasinCache.addCraftingRecipe(abstractionLamp, abstractionLampRecipe);
Expand All @@ -669,5 +698,7 @@ amalgamateDustEpic, new ItemStack(Material.GLASS), amalgamateDustEpic,
LiquefactionBasinCache.addCraftingRecipe(mysteriousPlant, mysteriousPlantRecipe);

LiquefactionBasinCache.addCraftingRecipe(focusedGreenHouseGlass, focusedGreenHouseGlassRecipe);

LiquefactionBasinCache.addCraftingRecipe(trophyDisplay, trophyDisplayRecipe);
}
}
Loading

0 comments on commit ff965bb

Please sign in to comment.