From c48362b94e3965755ca51d9329554fea6541670c Mon Sep 17 00:00:00 2001 From: WuChenyu <73216826+wcy6457@users.noreply.github.com> Date: Thu, 26 Jan 2023 15:51:44 +0800 Subject: [PATCH 1/8] Update config.yml --- src/main/resources/config.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 1649a99..14cc950 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,8 +1,9 @@ # If the plugin should auto-update auto-update: true on-death: - # If true, a player will lose a random research every death - reset-random-research: true + # Chance to reset one player's researches on death. Percent scale of 0 to 100. + # 100 will always fire and 0 will never fire. + chance-to-reset-random-research: 70 # Chance to reset all the player's researches on death. Percent scale of 0 to 100. # 100 will always fire and 0 will never fire. chance-to-reset-all-researches: 5 From c9fee7ff6af72b47cb7ecd180b69d885848a5c0e Mon Sep 17 00:00:00 2001 From: WuChenyu <73216826+wcy6457@users.noreply.github.com> Date: Thu, 26 Jan 2023 15:56:30 +0800 Subject: [PATCH 2/8] Update Config.java --- src/main/java/dev/walshy/hardcoreslimefun/utils/Config.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/walshy/hardcoreslimefun/utils/Config.java b/src/main/java/dev/walshy/hardcoreslimefun/utils/Config.java index e8fd8fb..e48d02c 100644 --- a/src/main/java/dev/walshy/hardcoreslimefun/utils/Config.java +++ b/src/main/java/dev/walshy/hardcoreslimefun/utils/Config.java @@ -11,7 +11,7 @@ public class Config { public static final Config INSTANCE = new Config(); // on-death.reset-random-research - private boolean resetResearchOnDeath; + private double resetResearchOnDeath; // on-death.chance-to-reset-all-researches private double resetAllResearchesOnDeath; @@ -36,7 +36,7 @@ public class Config { private String androidMalfunctioned; public void load(@Nonnull FileConfiguration config) { - resetResearchOnDeath = config.getBoolean("on-death.reset-random-research", true); + resetResearchOnDeath = getPercent(config,"on-death.resetResearchChance",70); resetAllResearchesOnDeath = getPercent(config, "on-death.chance-to-reset-all-researches", 5); researchFailChance = getPercent(config, "on-research.chance-of-failure", 10); From 244e9a814064db53b2295184d1b0988442f22287 Mon Sep 17 00:00:00 2001 From: WuChenyu <73216826+wcy6457@users.noreply.github.com> Date: Thu, 26 Jan 2023 16:00:24 +0800 Subject: [PATCH 3/8] Update Events.java --- src/main/java/dev/walshy/hardcoreslimefun/events/Events.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/walshy/hardcoreslimefun/events/Events.java b/src/main/java/dev/walshy/hardcoreslimefun/events/Events.java index 10900a8..4d8aafa 100644 --- a/src/main/java/dev/walshy/hardcoreslimefun/events/Events.java +++ b/src/main/java/dev/walshy/hardcoreslimefun/events/Events.java @@ -22,6 +22,7 @@ public class Events implements Listener { public void onDeath(@Nonnull PlayerDeathEvent event) { PlayerProfile.get(event.getEntity(), profile -> { final boolean shouldResetAllResearches = Utils.chance(Config.INSTANCE.getResetAllResearchesOnDeath()); + final boolean shouldResetOneResearch = Utils.chance(Config.INSTANCE.getResetResearchChance()); // If we should reset all researches, do it if (shouldResetAllResearches) { @@ -30,11 +31,11 @@ public void onDeath(@Nonnull PlayerDeathEvent event) { } Utils.send(event.getEntity(), Config.INSTANCE.getLostAllResearch()); - } else if (Config.INSTANCE.isResetResearchOnDeath()) { + } else if (shouldResetOneResearch) { // If we should reset a random one, do it final Research randomResearch = Utils.randomValue(profile.getResearches()); if (randomResearch == null) return; - + profile.setResearched(randomResearch, false); String message = Config.INSTANCE.getLostRandomResearch().replace("%research%", randomResearch.getName(event.getEntity())); Utils.send(event.getEntity(), message); From 92ba3bcaf18dfebb261ca131da16ddd977710ba3 Mon Sep 17 00:00:00 2001 From: WuChenyu <73216826+wcy6457@users.noreply.github.com> Date: Fri, 3 Feb 2023 15:50:47 +0800 Subject: [PATCH 4/8] Add files via upload --- .../hardcoreslimefun/HardcoreMetrics.java | 61 ++++++++++++++ .../hardcoreslimefun/HardcoreSlimefun.java | 63 ++++++++++++++ .../events/AndroidEvents.java | 83 +++++++++++++++++++ .../hardcoreslimefun/events/Events.java | 59 +++++++++++++ .../walshy/hardcoreslimefun/utils/Config.java | 67 +++++++++++++++ .../walshy/hardcoreslimefun/utils/Keys.java | 18 ++++ .../walshy/hardcoreslimefun/utils/Utils.java | 43 ++++++++++ main/resources/config.yml | 28 +++++++ main/resources/plugin.yml | 8 ++ 9 files changed, 430 insertions(+) create mode 100644 main/java/dev/walshy/hardcoreslimefun/HardcoreMetrics.java create mode 100644 main/java/dev/walshy/hardcoreslimefun/HardcoreSlimefun.java create mode 100644 main/java/dev/walshy/hardcoreslimefun/events/AndroidEvents.java create mode 100644 main/java/dev/walshy/hardcoreslimefun/events/Events.java create mode 100644 main/java/dev/walshy/hardcoreslimefun/utils/Config.java create mode 100644 main/java/dev/walshy/hardcoreslimefun/utils/Keys.java create mode 100644 main/java/dev/walshy/hardcoreslimefun/utils/Utils.java create mode 100644 main/resources/config.yml create mode 100644 main/resources/plugin.yml diff --git a/main/java/dev/walshy/hardcoreslimefun/HardcoreMetrics.java b/main/java/dev/walshy/hardcoreslimefun/HardcoreMetrics.java new file mode 100644 index 0000000..f4a1636 --- /dev/null +++ b/main/java/dev/walshy/hardcoreslimefun/HardcoreMetrics.java @@ -0,0 +1,61 @@ +package dev.walshy.hardcoreslimefun; + +import dev.walshy.hardcoreslimefun.utils.Config; +import org.bstats.bukkit.Metrics; +import org.bstats.charts.SimplePie; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import java.util.concurrent.Callable; +import java.util.function.BooleanSupplier; +import java.util.function.DoubleSupplier; + +class HardcoreMetrics { + + private final HardcoreSlimefun plugin; + + HardcoreMetrics(@Nonnull HardcoreSlimefun plugin) { + this.plugin = plugin; + } + + void start() { + Metrics metrics = new Metrics(plugin, 13641); + + addPercentChart(metrics, "chance-to-reset-random-research",25,Config.INSTANCE::getResetResearchOnDeath); + addPercentChart(metrics, "chance_to_reset_all_researches_on_death", 25, + Config.INSTANCE::getResetAllResearchesOnDeath); + + addPercentChart(metrics, "chance_for_research_failure", 25, Config.INSTANCE::getResearchFailChance); + + addPercentChart(metrics, "chance_for_android_malfunction", 25, Config.INSTANCE::getResearchFailChance); + } + + @ParametersAreNonnullByDefault + private void addBooleanPie(Metrics metrics, String label, BooleanSupplier setting) { + metrics.addCustomChart(new SimplePie(label, getPieText(setting))); + } + + @ParametersAreNonnullByDefault + private void addPercentChart(Metrics metrics, String label, double rangeStep, DoubleSupplier setting) { + metrics.addCustomChart(new SimplePie(label, () -> { + double value = setting.getAsDouble(); + double lastStep = 0; + for (double d = rangeStep; d <= 100; d += rangeStep) { + // if (13 <= 25) { return "0-25%"; } + if (value <= d) { + return lastStep + "% - " + d + '%'; + } + lastStep = d; + } + + // This shouldn't fire + return "0%"; + })); + } + + @Nonnull + private Callable getPieText(@Nonnull BooleanSupplier setting) { + return () -> setting.getAsBoolean() ? "Yes" : "No"; + } + +} \ No newline at end of file diff --git a/main/java/dev/walshy/hardcoreslimefun/HardcoreSlimefun.java b/main/java/dev/walshy/hardcoreslimefun/HardcoreSlimefun.java new file mode 100644 index 0000000..097e9f4 --- /dev/null +++ b/main/java/dev/walshy/hardcoreslimefun/HardcoreSlimefun.java @@ -0,0 +1,63 @@ +package dev.walshy.hardcoreslimefun; + +import dev.walshy.hardcoreslimefun.events.AndroidEvents; +import dev.walshy.hardcoreslimefun.events.Events; +import dev.walshy.hardcoreslimefun.utils.Config; +import io.github.thebusybiscuit.slimefun4.libraries.dough.updater.GitHubBuildsUpdater; +import org.bukkit.plugin.java.JavaPlugin; + +import javax.annotation.Nullable; + +/* + * Ideas: + * + Reset research on death + * + Chance to reset all research on death + * + Research fail chance + * + Android fail chance (farm/mine) + * * Enchanter fail chance + * * Disenchant fail chance + * * Block placer fail chance + * * Reactors actually explode + * * Explosives can damage/knockback + * * Ancient altar can fail and instead output some rubbish item :^) + */ +public class HardcoreSlimefun extends JavaPlugin { + + private static HardcoreSlimefun instance; + + @Override + public void onEnable() { + setInstance(this); + saveDefaultConfig(); + + Config.INSTANCE.load(this.getConfig()); + + if (getServer().getPluginManager().getPlugin("Slimefun") == null) { + getLogger().severe("Slimefun not found! Disabling plugin..."); + getServer().getPluginManager().disablePlugin(this); + return; + } + + if (getConfig().getBoolean("auto-update") && getDescription().getVersion().startsWith("DEV - ")) { + new GitHubBuildsUpdater(this, getFile(), "Slimefun-Addon-Community/HardcoreSlimefun/main", "DEV").start(); + } + + new HardcoreMetrics(this).start(); + + getServer().getPluginManager().registerEvents(new Events(), this); + getServer().getPluginManager().registerEvents(new AndroidEvents(), this); + } + + @Override + public void onDisable() { + setInstance(null); + } + + public static HardcoreSlimefun getInstance() { + return instance; + } + + private static void setInstance(@Nullable HardcoreSlimefun plugin) { + instance = plugin; + } +} diff --git a/main/java/dev/walshy/hardcoreslimefun/events/AndroidEvents.java b/main/java/dev/walshy/hardcoreslimefun/events/AndroidEvents.java new file mode 100644 index 0000000..d5393d6 --- /dev/null +++ b/main/java/dev/walshy/hardcoreslimefun/events/AndroidEvents.java @@ -0,0 +1,83 @@ +package dev.walshy.hardcoreslimefun.events; + +import dev.walshy.hardcoreslimefun.utils.Config; +import dev.walshy.hardcoreslimefun.utils.Keys; +import dev.walshy.hardcoreslimefun.utils.Utils; +import io.github.thebusybiscuit.slimefun4.api.events.AndroidFarmEvent; +import io.github.thebusybiscuit.slimefun4.api.events.AndroidMineEvent; +import io.github.thebusybiscuit.slimefun4.implementation.items.androids.AndroidInstance; +import io.github.thebusybiscuit.slimefun4.libraries.dough.data.persistent.PersistentDataAPI; +import me.mrCookieSlime.Slimefun.api.BlockStorage; +import org.bukkit.block.Block; +import org.bukkit.block.Skull; +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; +import org.bukkit.inventory.EquipmentSlot; + +import javax.annotation.Nonnull; +import java.util.concurrent.TimeUnit; + +/* + * This class covers: + * - Chance for androids to malfunction (break for x time) + */ +public class AndroidEvents implements Listener { + + @EventHandler + public void onAndroidMine(@Nonnull AndroidMineEvent event) { + if (Utils.chance(Config.INSTANCE.getMalfunctionChance())) { + setMalfunctioned(event.getAndroid()); + } + } + + @EventHandler + public void onAndroidFarm(@Nonnull AndroidFarmEvent event) { + if (Utils.chance(Config.INSTANCE.getMalfunctionChance())) { + setMalfunctioned(event.getAndroid()); + } + } + + @EventHandler(priority = EventPriority.LOW) + public void onAndroidInteract(@Nonnull PlayerInteractEvent event) { + if (event.getHand() == EquipmentSlot.HAND + && event.getAction() == Action.RIGHT_CLICK_BLOCK + && event.getClickedBlock() != null + && !event.getClickedBlock().getType().isAir() + && event.getClickedBlock().getState() instanceof Skull + ) { + final Skull skull = (Skull) event.getClickedBlock().getState(); + + final long timeout = PersistentDataAPI.getLong(skull, Keys.MALFUNCTION_TIME_OUT); + if (timeout != -1) { + if (PersistentDataAPI.getLong(skull, Keys.MALFUNCTION_TIME_OUT) <= System.currentTimeMillis()) { + event.setCancelled(true); + Utils.send(event.getPlayer(), Config.INSTANCE.getAndroidMalfunctioned()); + } else { + PersistentDataAPI.remove(skull, Keys.MALFUNCTION_TIME_OUT); + } + } + } + } + + private void setMalfunctioned(@Nonnull AndroidInstance android) { + final Block block = android.getBlock(); + + // Pause android + BlockStorage.addBlockInfo(block, "paused", "true"); + + // Set malfunctioned + if (block.getState() instanceof Skull) { + final Skull skull = (Skull) block.getState(); + + PersistentDataAPI.setLong( + skull, + Keys.MALFUNCTION_TIME_OUT, + System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(Config.INSTANCE.getMalfunctionDuration()) + ); + skull.update(); + } + } +} diff --git a/main/java/dev/walshy/hardcoreslimefun/events/Events.java b/main/java/dev/walshy/hardcoreslimefun/events/Events.java new file mode 100644 index 0000000..bd8cc8f --- /dev/null +++ b/main/java/dev/walshy/hardcoreslimefun/events/Events.java @@ -0,0 +1,59 @@ +package dev.walshy.hardcoreslimefun.events; + +import dev.walshy.hardcoreslimefun.utils.Config; +import dev.walshy.hardcoreslimefun.utils.Utils; +import io.github.thebusybiscuit.slimefun4.api.events.ResearchUnlockEvent; +import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; +import io.github.thebusybiscuit.slimefun4.api.researches.Research; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; + +import javax.annotation.Nonnull; + +public class Events implements Listener { + + /* + * This event covers: + * - Losing a random research on death + * - Chance to lose all research on death + */ + @EventHandler + public void onDeath(@Nonnull PlayerDeathEvent event) { + PlayerProfile.get(event.getEntity(), profile -> { + final boolean shouldResetAllResearches = Utils.chance(Config.INSTANCE.getResetAllResearchesOnDeath()); + final boolean shouldResetOneResearch = Utils.chance(Config.INSTANCE.getResetResearchOnDeath()); + + // If we should reset all researches, do it + if (shouldResetAllResearches) { + for (Research research : profile.getResearches()) { + profile.setResearched(research, false); + } + Utils.send(event.getEntity(), Config.INSTANCE.getLostAllResearch()); + + } else if (shouldResetOneResearch) { + // If we should reset a random one, do it + final Research randomResearch = Utils.randomValue(profile.getResearches()); + if (randomResearch == null) return; + + profile.setResearched(randomResearch, false); + String message = Config.INSTANCE.getLostRandomResearch().replace("%research%", randomResearch.getName(event.getEntity())); + Utils.send(event.getEntity(), message); + } + }); + } + + /* + * This event covers: + * - Chance to fail researching + */ + @EventHandler + public void onResearch(@Nonnull ResearchUnlockEvent event) { + final boolean shouldResearchFail = Utils.chance(Config.INSTANCE.getResearchFailChance()); + + if (shouldResearchFail) { + event.setCancelled(true); + Utils.send(event.getPlayer(), Config.INSTANCE.getResearchFailed()); + } + } +} diff --git a/main/java/dev/walshy/hardcoreslimefun/utils/Config.java b/main/java/dev/walshy/hardcoreslimefun/utils/Config.java new file mode 100644 index 0000000..e48d02c --- /dev/null +++ b/main/java/dev/walshy/hardcoreslimefun/utils/Config.java @@ -0,0 +1,67 @@ +package dev.walshy.hardcoreslimefun.utils; + +import lombok.Getter; +import org.bukkit.configuration.file.FileConfiguration; + +import javax.annotation.Nonnull; + +@Getter +public class Config { + + public static final Config INSTANCE = new Config(); + + // on-death.reset-random-research + private double resetResearchOnDeath; + // on-death.chance-to-reset-all-researches + private double resetAllResearchesOnDeath; + + // on-research.chance-of-failure + private double researchFailChance; + + // android.chance-to-malfunction + private double malfunctionChance; + // android.malfunction-duration + private long malfunctionDuration; + + //////////////////////// + // Messages + //////////////////////// + // lost-random-research + private String lostRandomResearch; + // lost-all-research + private String lostAllResearch; + // research-failed + private String researchFailed; + // android-malfunctioned + private String androidMalfunctioned; + + public void load(@Nonnull FileConfiguration config) { + resetResearchOnDeath = getPercent(config,"on-death.resetResearchChance",70); + resetAllResearchesOnDeath = getPercent(config, "on-death.chance-to-reset-all-researches", 5); + + researchFailChance = getPercent(config, "on-research.chance-of-failure", 10); + + malfunctionChance = getPercent(config, "android.chance-to-malfunction", 10); + malfunctionDuration = config.getLong("android.malfunction-duration", 30); + + //////////////////////// + // Messages + //////////////////////// + lostRandomResearch = config.getString("messages.lost-random-research", "&cYou lost a random research!"); + lostAllResearch = config.getString("messages.lost-all-research", "&cYou lost all your research!"); + researchFailed = config.getString("messages.research-failed", "&cResearch failed!"); + androidMalfunctioned = config.getString("messages.android-malfunctioned", + "&cYour Android has malfunctioned! Let it cool down and start it again"); + } + + private double getPercent(@Nonnull FileConfiguration config, @Nonnull String path, double defaultValue) { + final double d = config.getDouble(path, defaultValue); + if (d > 100) { + return 100; + } else if (d < 0) { + return 0; + } else { + return d; + } + } +} diff --git a/main/java/dev/walshy/hardcoreslimefun/utils/Keys.java b/main/java/dev/walshy/hardcoreslimefun/utils/Keys.java new file mode 100644 index 0000000..d3067e3 --- /dev/null +++ b/main/java/dev/walshy/hardcoreslimefun/utils/Keys.java @@ -0,0 +1,18 @@ +package dev.walshy.hardcoreslimefun.utils; + +import dev.walshy.hardcoreslimefun.HardcoreSlimefun; +import org.bukkit.NamespacedKey; + +import javax.annotation.Nonnull; + +public class Keys { + + public static final NamespacedKey MALFUNCTION_TIME_OUT = create("malfunction_time_out"); + + private Keys() {} + + @Nonnull + private static NamespacedKey create(@Nonnull String value) { + return new NamespacedKey(HardcoreSlimefun.getInstance(), value); + } +} diff --git a/main/java/dev/walshy/hardcoreslimefun/utils/Utils.java b/main/java/dev/walshy/hardcoreslimefun/utils/Utils.java new file mode 100644 index 0000000..1761e0c --- /dev/null +++ b/main/java/dev/walshy/hardcoreslimefun/utils/Utils.java @@ -0,0 +1,43 @@ +package dev.walshy.hardcoreslimefun.utils; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.Set; +import java.util.concurrent.ThreadLocalRandom; + +public class Utils { + + private Utils() {} + + @Nullable + public static T randomValue(@Nonnull Set set) { + if (set.isEmpty()) return null; + + final int rand = ThreadLocalRandom.current().nextInt(set.size()); + + int i = 0; + for (T value : set) { + if (i++ == rand) { + return value; + } + } + return null; + } + + public static boolean chance(double chance) { + if (chance >= 100) { + return true; + } else if (chance <= 0) { + return false; + } + + return ThreadLocalRandom.current().nextDouble(100) + 1 <= chance; + } + + public static void send(@Nonnull Player player, @Nonnull String message) { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); + } +} diff --git a/main/resources/config.yml b/main/resources/config.yml new file mode 100644 index 0000000..14cc950 --- /dev/null +++ b/main/resources/config.yml @@ -0,0 +1,28 @@ +# If the plugin should auto-update +auto-update: true +on-death: + # Chance to reset one player's researches on death. Percent scale of 0 to 100. + # 100 will always fire and 0 will never fire. + chance-to-reset-random-research: 70 + # Chance to reset all the player's researches on death. Percent scale of 0 to 100. + # 100 will always fire and 0 will never fire. + chance-to-reset-all-researches: 5 + +on-research: + # Chance that researching can fail. Percent scale of 0 to 100. + # 100 will always fire and 0 will never fire. + chance-of-failure: 10 + +android: + # Chance for the Android to malfunction. Percent scale of 0 to 100. + # 100 will always fire and 0 will never fire. + chance-to-malfunction: 10 + # Duration of the malfunction in seconds. + malfunction-duration: 30 + +messages: + # %research% can be used to show the lost research's name + lost-random-research: '&cYou lost a random research!' + lost-all-research: '&cOh noes... You lost all your research!' + research-failed: '&cResearch failed! You''ll need to do that again :^)' + android-malfunctioned: '&cYour Android has malfunctioned! Let it cool down and start it again' diff --git a/main/resources/plugin.yml b/main/resources/plugin.yml new file mode 100644 index 0000000..9c38b6e --- /dev/null +++ b/main/resources/plugin.yml @@ -0,0 +1,8 @@ +name: HardcoreSlimefun +description: Slimefun but impossibly hard to beat +version: 1.0 +api-version: 1.14 +author: WalshyDev, TheBusyBiscuit +website: https://github.com/Slimefun-Addon-Community/HardcoreSlimefun +main: dev.walshy.hardcoreslimefun.HardcoreSlimefun +depend: [Slimefun] \ No newline at end of file From f20c76480018e195af676835b7e282317aa5185d Mon Sep 17 00:00:00 2001 From: WuChenyu <73216826+wcy6457@users.noreply.github.com> Date: Fri, 3 Feb 2023 15:53:00 +0800 Subject: [PATCH 5/8] Delete main directory --- .../hardcoreslimefun/HardcoreMetrics.java | 61 -------------- .../hardcoreslimefun/HardcoreSlimefun.java | 63 -------------- .../events/AndroidEvents.java | 83 ------------------- .../hardcoreslimefun/events/Events.java | 59 ------------- .../walshy/hardcoreslimefun/utils/Config.java | 67 --------------- .../walshy/hardcoreslimefun/utils/Keys.java | 18 ---- .../walshy/hardcoreslimefun/utils/Utils.java | 43 ---------- main/resources/config.yml | 28 ------- main/resources/plugin.yml | 8 -- 9 files changed, 430 deletions(-) delete mode 100644 main/java/dev/walshy/hardcoreslimefun/HardcoreMetrics.java delete mode 100644 main/java/dev/walshy/hardcoreslimefun/HardcoreSlimefun.java delete mode 100644 main/java/dev/walshy/hardcoreslimefun/events/AndroidEvents.java delete mode 100644 main/java/dev/walshy/hardcoreslimefun/events/Events.java delete mode 100644 main/java/dev/walshy/hardcoreslimefun/utils/Config.java delete mode 100644 main/java/dev/walshy/hardcoreslimefun/utils/Keys.java delete mode 100644 main/java/dev/walshy/hardcoreslimefun/utils/Utils.java delete mode 100644 main/resources/config.yml delete mode 100644 main/resources/plugin.yml diff --git a/main/java/dev/walshy/hardcoreslimefun/HardcoreMetrics.java b/main/java/dev/walshy/hardcoreslimefun/HardcoreMetrics.java deleted file mode 100644 index f4a1636..0000000 --- a/main/java/dev/walshy/hardcoreslimefun/HardcoreMetrics.java +++ /dev/null @@ -1,61 +0,0 @@ -package dev.walshy.hardcoreslimefun; - -import dev.walshy.hardcoreslimefun.utils.Config; -import org.bstats.bukkit.Metrics; -import org.bstats.charts.SimplePie; - -import javax.annotation.Nonnull; -import javax.annotation.ParametersAreNonnullByDefault; -import java.util.concurrent.Callable; -import java.util.function.BooleanSupplier; -import java.util.function.DoubleSupplier; - -class HardcoreMetrics { - - private final HardcoreSlimefun plugin; - - HardcoreMetrics(@Nonnull HardcoreSlimefun plugin) { - this.plugin = plugin; - } - - void start() { - Metrics metrics = new Metrics(plugin, 13641); - - addPercentChart(metrics, "chance-to-reset-random-research",25,Config.INSTANCE::getResetResearchOnDeath); - addPercentChart(metrics, "chance_to_reset_all_researches_on_death", 25, - Config.INSTANCE::getResetAllResearchesOnDeath); - - addPercentChart(metrics, "chance_for_research_failure", 25, Config.INSTANCE::getResearchFailChance); - - addPercentChart(metrics, "chance_for_android_malfunction", 25, Config.INSTANCE::getResearchFailChance); - } - - @ParametersAreNonnullByDefault - private void addBooleanPie(Metrics metrics, String label, BooleanSupplier setting) { - metrics.addCustomChart(new SimplePie(label, getPieText(setting))); - } - - @ParametersAreNonnullByDefault - private void addPercentChart(Metrics metrics, String label, double rangeStep, DoubleSupplier setting) { - metrics.addCustomChart(new SimplePie(label, () -> { - double value = setting.getAsDouble(); - double lastStep = 0; - for (double d = rangeStep; d <= 100; d += rangeStep) { - // if (13 <= 25) { return "0-25%"; } - if (value <= d) { - return lastStep + "% - " + d + '%'; - } - lastStep = d; - } - - // This shouldn't fire - return "0%"; - })); - } - - @Nonnull - private Callable getPieText(@Nonnull BooleanSupplier setting) { - return () -> setting.getAsBoolean() ? "Yes" : "No"; - } - -} \ No newline at end of file diff --git a/main/java/dev/walshy/hardcoreslimefun/HardcoreSlimefun.java b/main/java/dev/walshy/hardcoreslimefun/HardcoreSlimefun.java deleted file mode 100644 index 097e9f4..0000000 --- a/main/java/dev/walshy/hardcoreslimefun/HardcoreSlimefun.java +++ /dev/null @@ -1,63 +0,0 @@ -package dev.walshy.hardcoreslimefun; - -import dev.walshy.hardcoreslimefun.events.AndroidEvents; -import dev.walshy.hardcoreslimefun.events.Events; -import dev.walshy.hardcoreslimefun.utils.Config; -import io.github.thebusybiscuit.slimefun4.libraries.dough.updater.GitHubBuildsUpdater; -import org.bukkit.plugin.java.JavaPlugin; - -import javax.annotation.Nullable; - -/* - * Ideas: - * + Reset research on death - * + Chance to reset all research on death - * + Research fail chance - * + Android fail chance (farm/mine) - * * Enchanter fail chance - * * Disenchant fail chance - * * Block placer fail chance - * * Reactors actually explode - * * Explosives can damage/knockback - * * Ancient altar can fail and instead output some rubbish item :^) - */ -public class HardcoreSlimefun extends JavaPlugin { - - private static HardcoreSlimefun instance; - - @Override - public void onEnable() { - setInstance(this); - saveDefaultConfig(); - - Config.INSTANCE.load(this.getConfig()); - - if (getServer().getPluginManager().getPlugin("Slimefun") == null) { - getLogger().severe("Slimefun not found! Disabling plugin..."); - getServer().getPluginManager().disablePlugin(this); - return; - } - - if (getConfig().getBoolean("auto-update") && getDescription().getVersion().startsWith("DEV - ")) { - new GitHubBuildsUpdater(this, getFile(), "Slimefun-Addon-Community/HardcoreSlimefun/main", "DEV").start(); - } - - new HardcoreMetrics(this).start(); - - getServer().getPluginManager().registerEvents(new Events(), this); - getServer().getPluginManager().registerEvents(new AndroidEvents(), this); - } - - @Override - public void onDisable() { - setInstance(null); - } - - public static HardcoreSlimefun getInstance() { - return instance; - } - - private static void setInstance(@Nullable HardcoreSlimefun plugin) { - instance = plugin; - } -} diff --git a/main/java/dev/walshy/hardcoreslimefun/events/AndroidEvents.java b/main/java/dev/walshy/hardcoreslimefun/events/AndroidEvents.java deleted file mode 100644 index d5393d6..0000000 --- a/main/java/dev/walshy/hardcoreslimefun/events/AndroidEvents.java +++ /dev/null @@ -1,83 +0,0 @@ -package dev.walshy.hardcoreslimefun.events; - -import dev.walshy.hardcoreslimefun.utils.Config; -import dev.walshy.hardcoreslimefun.utils.Keys; -import dev.walshy.hardcoreslimefun.utils.Utils; -import io.github.thebusybiscuit.slimefun4.api.events.AndroidFarmEvent; -import io.github.thebusybiscuit.slimefun4.api.events.AndroidMineEvent; -import io.github.thebusybiscuit.slimefun4.implementation.items.androids.AndroidInstance; -import io.github.thebusybiscuit.slimefun4.libraries.dough.data.persistent.PersistentDataAPI; -import me.mrCookieSlime.Slimefun.api.BlockStorage; -import org.bukkit.block.Block; -import org.bukkit.block.Skull; -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; -import org.bukkit.inventory.EquipmentSlot; - -import javax.annotation.Nonnull; -import java.util.concurrent.TimeUnit; - -/* - * This class covers: - * - Chance for androids to malfunction (break for x time) - */ -public class AndroidEvents implements Listener { - - @EventHandler - public void onAndroidMine(@Nonnull AndroidMineEvent event) { - if (Utils.chance(Config.INSTANCE.getMalfunctionChance())) { - setMalfunctioned(event.getAndroid()); - } - } - - @EventHandler - public void onAndroidFarm(@Nonnull AndroidFarmEvent event) { - if (Utils.chance(Config.INSTANCE.getMalfunctionChance())) { - setMalfunctioned(event.getAndroid()); - } - } - - @EventHandler(priority = EventPriority.LOW) - public void onAndroidInteract(@Nonnull PlayerInteractEvent event) { - if (event.getHand() == EquipmentSlot.HAND - && event.getAction() == Action.RIGHT_CLICK_BLOCK - && event.getClickedBlock() != null - && !event.getClickedBlock().getType().isAir() - && event.getClickedBlock().getState() instanceof Skull - ) { - final Skull skull = (Skull) event.getClickedBlock().getState(); - - final long timeout = PersistentDataAPI.getLong(skull, Keys.MALFUNCTION_TIME_OUT); - if (timeout != -1) { - if (PersistentDataAPI.getLong(skull, Keys.MALFUNCTION_TIME_OUT) <= System.currentTimeMillis()) { - event.setCancelled(true); - Utils.send(event.getPlayer(), Config.INSTANCE.getAndroidMalfunctioned()); - } else { - PersistentDataAPI.remove(skull, Keys.MALFUNCTION_TIME_OUT); - } - } - } - } - - private void setMalfunctioned(@Nonnull AndroidInstance android) { - final Block block = android.getBlock(); - - // Pause android - BlockStorage.addBlockInfo(block, "paused", "true"); - - // Set malfunctioned - if (block.getState() instanceof Skull) { - final Skull skull = (Skull) block.getState(); - - PersistentDataAPI.setLong( - skull, - Keys.MALFUNCTION_TIME_OUT, - System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(Config.INSTANCE.getMalfunctionDuration()) - ); - skull.update(); - } - } -} diff --git a/main/java/dev/walshy/hardcoreslimefun/events/Events.java b/main/java/dev/walshy/hardcoreslimefun/events/Events.java deleted file mode 100644 index bd8cc8f..0000000 --- a/main/java/dev/walshy/hardcoreslimefun/events/Events.java +++ /dev/null @@ -1,59 +0,0 @@ -package dev.walshy.hardcoreslimefun.events; - -import dev.walshy.hardcoreslimefun.utils.Config; -import dev.walshy.hardcoreslimefun.utils.Utils; -import io.github.thebusybiscuit.slimefun4.api.events.ResearchUnlockEvent; -import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; -import io.github.thebusybiscuit.slimefun4.api.researches.Research; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.PlayerDeathEvent; - -import javax.annotation.Nonnull; - -public class Events implements Listener { - - /* - * This event covers: - * - Losing a random research on death - * - Chance to lose all research on death - */ - @EventHandler - public void onDeath(@Nonnull PlayerDeathEvent event) { - PlayerProfile.get(event.getEntity(), profile -> { - final boolean shouldResetAllResearches = Utils.chance(Config.INSTANCE.getResetAllResearchesOnDeath()); - final boolean shouldResetOneResearch = Utils.chance(Config.INSTANCE.getResetResearchOnDeath()); - - // If we should reset all researches, do it - if (shouldResetAllResearches) { - for (Research research : profile.getResearches()) { - profile.setResearched(research, false); - } - Utils.send(event.getEntity(), Config.INSTANCE.getLostAllResearch()); - - } else if (shouldResetOneResearch) { - // If we should reset a random one, do it - final Research randomResearch = Utils.randomValue(profile.getResearches()); - if (randomResearch == null) return; - - profile.setResearched(randomResearch, false); - String message = Config.INSTANCE.getLostRandomResearch().replace("%research%", randomResearch.getName(event.getEntity())); - Utils.send(event.getEntity(), message); - } - }); - } - - /* - * This event covers: - * - Chance to fail researching - */ - @EventHandler - public void onResearch(@Nonnull ResearchUnlockEvent event) { - final boolean shouldResearchFail = Utils.chance(Config.INSTANCE.getResearchFailChance()); - - if (shouldResearchFail) { - event.setCancelled(true); - Utils.send(event.getPlayer(), Config.INSTANCE.getResearchFailed()); - } - } -} diff --git a/main/java/dev/walshy/hardcoreslimefun/utils/Config.java b/main/java/dev/walshy/hardcoreslimefun/utils/Config.java deleted file mode 100644 index e48d02c..0000000 --- a/main/java/dev/walshy/hardcoreslimefun/utils/Config.java +++ /dev/null @@ -1,67 +0,0 @@ -package dev.walshy.hardcoreslimefun.utils; - -import lombok.Getter; -import org.bukkit.configuration.file.FileConfiguration; - -import javax.annotation.Nonnull; - -@Getter -public class Config { - - public static final Config INSTANCE = new Config(); - - // on-death.reset-random-research - private double resetResearchOnDeath; - // on-death.chance-to-reset-all-researches - private double resetAllResearchesOnDeath; - - // on-research.chance-of-failure - private double researchFailChance; - - // android.chance-to-malfunction - private double malfunctionChance; - // android.malfunction-duration - private long malfunctionDuration; - - //////////////////////// - // Messages - //////////////////////// - // lost-random-research - private String lostRandomResearch; - // lost-all-research - private String lostAllResearch; - // research-failed - private String researchFailed; - // android-malfunctioned - private String androidMalfunctioned; - - public void load(@Nonnull FileConfiguration config) { - resetResearchOnDeath = getPercent(config,"on-death.resetResearchChance",70); - resetAllResearchesOnDeath = getPercent(config, "on-death.chance-to-reset-all-researches", 5); - - researchFailChance = getPercent(config, "on-research.chance-of-failure", 10); - - malfunctionChance = getPercent(config, "android.chance-to-malfunction", 10); - malfunctionDuration = config.getLong("android.malfunction-duration", 30); - - //////////////////////// - // Messages - //////////////////////// - lostRandomResearch = config.getString("messages.lost-random-research", "&cYou lost a random research!"); - lostAllResearch = config.getString("messages.lost-all-research", "&cYou lost all your research!"); - researchFailed = config.getString("messages.research-failed", "&cResearch failed!"); - androidMalfunctioned = config.getString("messages.android-malfunctioned", - "&cYour Android has malfunctioned! Let it cool down and start it again"); - } - - private double getPercent(@Nonnull FileConfiguration config, @Nonnull String path, double defaultValue) { - final double d = config.getDouble(path, defaultValue); - if (d > 100) { - return 100; - } else if (d < 0) { - return 0; - } else { - return d; - } - } -} diff --git a/main/java/dev/walshy/hardcoreslimefun/utils/Keys.java b/main/java/dev/walshy/hardcoreslimefun/utils/Keys.java deleted file mode 100644 index d3067e3..0000000 --- a/main/java/dev/walshy/hardcoreslimefun/utils/Keys.java +++ /dev/null @@ -1,18 +0,0 @@ -package dev.walshy.hardcoreslimefun.utils; - -import dev.walshy.hardcoreslimefun.HardcoreSlimefun; -import org.bukkit.NamespacedKey; - -import javax.annotation.Nonnull; - -public class Keys { - - public static final NamespacedKey MALFUNCTION_TIME_OUT = create("malfunction_time_out"); - - private Keys() {} - - @Nonnull - private static NamespacedKey create(@Nonnull String value) { - return new NamespacedKey(HardcoreSlimefun.getInstance(), value); - } -} diff --git a/main/java/dev/walshy/hardcoreslimefun/utils/Utils.java b/main/java/dev/walshy/hardcoreslimefun/utils/Utils.java deleted file mode 100644 index 1761e0c..0000000 --- a/main/java/dev/walshy/hardcoreslimefun/utils/Utils.java +++ /dev/null @@ -1,43 +0,0 @@ -package dev.walshy.hardcoreslimefun.utils; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.util.Set; -import java.util.concurrent.ThreadLocalRandom; - -public class Utils { - - private Utils() {} - - @Nullable - public static T randomValue(@Nonnull Set set) { - if (set.isEmpty()) return null; - - final int rand = ThreadLocalRandom.current().nextInt(set.size()); - - int i = 0; - for (T value : set) { - if (i++ == rand) { - return value; - } - } - return null; - } - - public static boolean chance(double chance) { - if (chance >= 100) { - return true; - } else if (chance <= 0) { - return false; - } - - return ThreadLocalRandom.current().nextDouble(100) + 1 <= chance; - } - - public static void send(@Nonnull Player player, @Nonnull String message) { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); - } -} diff --git a/main/resources/config.yml b/main/resources/config.yml deleted file mode 100644 index 14cc950..0000000 --- a/main/resources/config.yml +++ /dev/null @@ -1,28 +0,0 @@ -# If the plugin should auto-update -auto-update: true -on-death: - # Chance to reset one player's researches on death. Percent scale of 0 to 100. - # 100 will always fire and 0 will never fire. - chance-to-reset-random-research: 70 - # Chance to reset all the player's researches on death. Percent scale of 0 to 100. - # 100 will always fire and 0 will never fire. - chance-to-reset-all-researches: 5 - -on-research: - # Chance that researching can fail. Percent scale of 0 to 100. - # 100 will always fire and 0 will never fire. - chance-of-failure: 10 - -android: - # Chance for the Android to malfunction. Percent scale of 0 to 100. - # 100 will always fire and 0 will never fire. - chance-to-malfunction: 10 - # Duration of the malfunction in seconds. - malfunction-duration: 30 - -messages: - # %research% can be used to show the lost research's name - lost-random-research: '&cYou lost a random research!' - lost-all-research: '&cOh noes... You lost all your research!' - research-failed: '&cResearch failed! You''ll need to do that again :^)' - android-malfunctioned: '&cYour Android has malfunctioned! Let it cool down and start it again' diff --git a/main/resources/plugin.yml b/main/resources/plugin.yml deleted file mode 100644 index 9c38b6e..0000000 --- a/main/resources/plugin.yml +++ /dev/null @@ -1,8 +0,0 @@ -name: HardcoreSlimefun -description: Slimefun but impossibly hard to beat -version: 1.0 -api-version: 1.14 -author: WalshyDev, TheBusyBiscuit -website: https://github.com/Slimefun-Addon-Community/HardcoreSlimefun -main: dev.walshy.hardcoreslimefun.HardcoreSlimefun -depend: [Slimefun] \ No newline at end of file From 79d8959e9f5cdcef888b8a47a728489f630e7023 Mon Sep 17 00:00:00 2001 From: WuChenyu <73216826+wcy6457@users.noreply.github.com> Date: Fri, 3 Feb 2023 15:53:36 +0800 Subject: [PATCH 6/8] Add files via upload --- src/main/java/dev/walshy/hardcoreslimefun/HardcoreMetrics.java | 2 +- src/main/java/dev/walshy/hardcoreslimefun/events/Events.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/walshy/hardcoreslimefun/HardcoreMetrics.java b/src/main/java/dev/walshy/hardcoreslimefun/HardcoreMetrics.java index 55ac626..f4a1636 100644 --- a/src/main/java/dev/walshy/hardcoreslimefun/HardcoreMetrics.java +++ b/src/main/java/dev/walshy/hardcoreslimefun/HardcoreMetrics.java @@ -21,7 +21,7 @@ class HardcoreMetrics { void start() { Metrics metrics = new Metrics(plugin, 13641); - addBooleanPie(metrics, "reset_random_research_on_death", Config.INSTANCE::isResetResearchOnDeath); + addPercentChart(metrics, "chance-to-reset-random-research",25,Config.INSTANCE::getResetResearchOnDeath); addPercentChart(metrics, "chance_to_reset_all_researches_on_death", 25, Config.INSTANCE::getResetAllResearchesOnDeath); diff --git a/src/main/java/dev/walshy/hardcoreslimefun/events/Events.java b/src/main/java/dev/walshy/hardcoreslimefun/events/Events.java index 4d8aafa..bd8cc8f 100644 --- a/src/main/java/dev/walshy/hardcoreslimefun/events/Events.java +++ b/src/main/java/dev/walshy/hardcoreslimefun/events/Events.java @@ -22,7 +22,7 @@ public class Events implements Listener { public void onDeath(@Nonnull PlayerDeathEvent event) { PlayerProfile.get(event.getEntity(), profile -> { final boolean shouldResetAllResearches = Utils.chance(Config.INSTANCE.getResetAllResearchesOnDeath()); - final boolean shouldResetOneResearch = Utils.chance(Config.INSTANCE.getResetResearchChance()); + final boolean shouldResetOneResearch = Utils.chance(Config.INSTANCE.getResetResearchOnDeath()); // If we should reset all researches, do it if (shouldResetAllResearches) { From 64e6a2ad917f52d5cd2e5aad9d3acb6b73075606 Mon Sep 17 00:00:00 2001 From: WuChenyu <73216826+wcy6457@users.noreply.github.com> Date: Thu, 20 Jul 2023 21:40:08 +0800 Subject: [PATCH 7/8] Update src/main/java/dev/walshy/hardcoreslimefun/HardcoreMetrics.java Co-authored-by: Daniel Walsh --- src/main/java/dev/walshy/hardcoreslimefun/HardcoreMetrics.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/dev/walshy/hardcoreslimefun/HardcoreMetrics.java b/src/main/java/dev/walshy/hardcoreslimefun/HardcoreMetrics.java index f4a1636..fecfbb1 100644 --- a/src/main/java/dev/walshy/hardcoreslimefun/HardcoreMetrics.java +++ b/src/main/java/dev/walshy/hardcoreslimefun/HardcoreMetrics.java @@ -21,7 +21,7 @@ class HardcoreMetrics { void start() { Metrics metrics = new Metrics(plugin, 13641); - addPercentChart(metrics, "chance-to-reset-random-research",25,Config.INSTANCE::getResetResearchOnDeath); + addPercentChart(metrics, "chance-to-reset-random-research", 25, Config.INSTANCE::getResetResearchOnDeath); addPercentChart(metrics, "chance_to_reset_all_researches_on_death", 25, Config.INSTANCE::getResetAllResearchesOnDeath); From 5d6a4ff4cb7f56aa2264b11cbb664c8a75dcee14 Mon Sep 17 00:00:00 2001 From: WuChenyu <73216826+wcy6457@users.noreply.github.com> Date: Thu, 20 Jul 2023 21:40:23 +0800 Subject: [PATCH 8/8] Update src/main/java/dev/walshy/hardcoreslimefun/events/Events.java Co-authored-by: Daniel Walsh --- src/main/java/dev/walshy/hardcoreslimefun/events/Events.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/dev/walshy/hardcoreslimefun/events/Events.java b/src/main/java/dev/walshy/hardcoreslimefun/events/Events.java index bd8cc8f..c8b1e92 100644 --- a/src/main/java/dev/walshy/hardcoreslimefun/events/Events.java +++ b/src/main/java/dev/walshy/hardcoreslimefun/events/Events.java @@ -35,7 +35,6 @@ public void onDeath(@Nonnull PlayerDeathEvent event) { // If we should reset a random one, do it final Research randomResearch = Utils.randomValue(profile.getResearches()); if (randomResearch == null) return; - profile.setResearched(randomResearch, false); String message = Config.INSTANCE.getLostRandomResearch().replace("%research%", randomResearch.getName(event.getEntity())); Utils.send(event.getEntity(), message);