Skip to content

Commit

Permalink
Cumulative Armor-Scheduling changes (Rainbow Armor + Radiation update) (
Browse files Browse the repository at this point in the history
#3892)

* armor task continuation

* added empty line

* requested changes

* Dirty bandage fix armor not working in creative

* rainbow armor clean up

* fixed radiation - not sure if this is the intended way

* ugly fix

* clean up

* requested changes

* import order

* made tiny uranium radiactive

* requested changes

* missed import from comment

* made it gold

* requested changes and actually make solar helmet work

* requested cahnges
  • Loading branch information
J3fftw1 committed Jul 8, 2023
1 parent 4fccf2b commit 5b458f1
Show file tree
Hide file tree
Showing 34 changed files with 682 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.bukkit.inventory.meta.ItemMeta;

import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.ArmorTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.armor.SlimefunArmorTask;

/**
* This class serves as a way of checking whether a {@link Player} has changed their armor
Expand All @@ -25,7 +25,7 @@
* @author TheBusyBiscuit
*
* @see SlimefunArmorPiece
* @see ArmorTask
* @see SlimefunArmorTask
*/
public final class HashedArmorpiece {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package io.github.thebusybiscuit.slimefun4.core.attributes;

import javax.annotation.Nonnull;

import com.google.common.base.Preconditions;

import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.utils.RadiationUtils;

/**
* An enum of potential radiation symptoms.
* A symptom will be applied when the minExposure
* threshold is reached on the {@link Player}'s
* exposure level.
* When the {@link Player} gets above the minExposure threshold
* the {@link PotionEffect} will be applied.
*
* @author Semisol
*
* @see RadiationUtils
*/
public enum RadiationSymptom {

SLOW(10, PotionEffectType.SLOW, 3),
WITHER_LOW(25, PotionEffectType.WITHER, 0),
BLINDNESS(50, PotionEffectType.BLINDNESS, 4),
WITHER_HIGH(75, PotionEffectType.WITHER, 3),
IMMINENT_DEATH(100, PotionEffectType.HARM, 49);

private final int minExposure;
private final PotionEffect potionEffect;

RadiationSymptom(int minExposure, @Nonnull PotionEffectType type, int level) {
Preconditions.checkNotNull(type, "The effect type cannot be null");
Preconditions.checkArgument(minExposure > 0, "The minimum exposure must be greater than 0.");
Preconditions.checkArgument(level >= 0, "The status effect level must be non-negative.");

this.minExposure = minExposure;
this.potionEffect = new PotionEffect(type, Slimefun.getCfg().getOrSetDefault("options.radiation-update-interval", 1) * 20 + 20, level);
}

/**
* This method applies the symptom to a player.
*
* @param p
* The player
*/
public void apply(@Nonnull Player p) {
Preconditions.checkNotNull(p, "The player cannot be null");
p.addPotionEffect(potionEffect);
}

/**
* This method returns if this symptom
* should be applied.
*
* @param exposure
* Exposure level
*
* @return If the symptom should be applied
*/
public boolean shouldApply(int exposure) {
return exposure >= minExposure;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import javax.annotation.Nonnull;

import io.github.thebusybiscuit.slimefun4.implementation.tasks.armor.RadiationTask;

import org.bukkit.ChatColor;
import org.bukkit.entity.Player;

Expand All @@ -20,41 +22,53 @@ public enum Radioactivity {
* This represents a low level of radiation.
* It will still cause damage but will take a while before it becomes deadly.
*/
LOW(ChatColor.YELLOW),
LOW(ChatColor.YELLOW, 1),

/**
* This represents a medium level of radiation.
* This can be considered the default.
*/
MODERATE(ChatColor.YELLOW),
MODERATE(ChatColor.YELLOW, 2),

/**
* This is a high level of radiation.
* It will cause death if the {@link Player} does not act quickly.
*/
HIGH(ChatColor.DARK_GREEN),
HIGH(ChatColor.GOLD, 3),

/**
* A very high level of radiation will be deadly.
* The {@link Player} should not take this too lightly...
*/
VERY_HIGH(ChatColor.RED),
VERY_HIGH(ChatColor.RED, 5),

/**
* This is the deadlies level of radiation.
* This is the deadliest level of radiation.
* The {@link Player} has basically no chance to protect themselves in time.
* It will cause certain death.
*/
VERY_DEADLY(ChatColor.DARK_RED);
VERY_DEADLY(ChatColor.DARK_RED, 10);

private final ChatColor color;
private final int exposureModifier;

Radioactivity(@Nonnull ChatColor color) {
Radioactivity(@Nonnull ChatColor color, int exposureModifier) {
this.color = color;
this.exposureModifier = exposureModifier;
}

/**
* This method returns the amount of exposure applied
* to a player every run of the {@link RadiationTask}
* for this radiation level.
*
* @return The exposure amount applied per run.
*/
public int getExposureModifier() {
return exposureModifier;
}

@Nonnull
public String getLore() {
public @Nonnull String getLore() {
return ChatColor.GREEN + "\u2622" + ChatColor.GRAY + " Radiation level: " + color + toString().replace('_', ' ');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
import io.github.thebusybiscuit.slimefun4.implementation.listeners.MultiBlockListener;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.NetworkListener;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.PlayerProfileListener;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.RadioactivityListener;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.SeismicAxeListener;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.SlimefunBootsListener;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.SlimefunBowListener;
Expand Down Expand Up @@ -115,7 +116,10 @@
import io.github.thebusybiscuit.slimefun4.implementation.setup.PostSetup;
import io.github.thebusybiscuit.slimefun4.implementation.setup.ResearchSetup;
import io.github.thebusybiscuit.slimefun4.implementation.setup.SlimefunItemSetup;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.ArmorTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.armor.RadiationTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.armor.RainbowArmorTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.armor.SlimefunArmorTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.armor.SolarHelmetTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.SlimefunStartupTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.TickerTask;
import io.github.thebusybiscuit.slimefun4.integrations.IntegrationsManager;
Expand Down Expand Up @@ -361,8 +365,10 @@ private void onPluginStart() {

// Armor Update Task
if (config.getBoolean("options.enable-armor-effects")) {
boolean radioactiveFire = config.getBoolean("options.burn-players-when-radioactive");
getServer().getScheduler().runTaskTimerAsynchronously(this, new ArmorTask(radioactiveFire), 0L, config.getInt("options.armor-update-interval") * 20L);
new SlimefunArmorTask().schedule(this, config.getInt("options.armor-update-interval") * 20L);
new RadiationTask().schedule(this, config.getInt("options.radiation-update-interval") * 20L);
new RainbowArmorTask().schedule(this, config.getInt("options.rainbow-armor-update-interval") * 20L);
new SolarHelmetTask().schedule(this, config.getInt("options.armor-update-interval"));
}

// Starting our tasks
Expand Down Expand Up @@ -644,6 +650,7 @@ private void registerListeners() {
// Item-specific Listeners
new CoolerListener(this, (Cooler) SlimefunItems.COOLER.getItem());
new SeismicAxeListener(this, (SeismicAxe) SlimefunItems.SEISMIC_AXE.getItem());
new RadioactivityListener(this);
new AncientAltarListener(this, (AncientAltar) SlimefunItems.ANCIENT_ALTAR.getItem(), (AncientPedestal) SlimefunItems.ANCIENT_PEDESTAL.getItem());
grapplingHookListener.register(this, (GrapplingHook) SlimefunItems.GRAPPLING_HOOK.getItem());
bowListener.register(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,11 @@ private SlimefunItems() {}
public static final SlimefunItemStack GLOWSTONE_CHESTPLATE = new SlimefunItemStack("GLOWSTONE_CHESTPLATE", Material.LEATHER_CHESTPLATE, Color.YELLOW, "&e&lGlowstone Chestplate", "", "&a&oShining like the sun!", "", "&9+ Night Vision");
public static final SlimefunItemStack GLOWSTONE_LEGGINGS = new SlimefunItemStack("GLOWSTONE_LEGGINGS", Material.LEATHER_LEGGINGS, Color.YELLOW, "&e&lGlowstone Leggings", "", "&a&oShining like the sun!", "", "&9+ Night Vision");
public static final SlimefunItemStack GLOWSTONE_BOOTS = new SlimefunItemStack("GLOWSTONE_BOOTS", Material.LEATHER_BOOTS, Color.YELLOW, "&e&lGlowstone Boots", "", "&a&oShining like the sun!", "", "&9+ Night Vision");

public static final SlimefunItemStack RAINBOW_LEATHER = new SlimefunItemStack("RAINBOW_LEATHER", Material.RABBIT_HIDE, Color.FUCHSIA, "&dRainbow Leather", "", "&fCan be used to craft rainbow armor");
public static final SlimefunItemStack RAINBOW_HELMET = new SlimefunItemStack("RAINBOW_HELMET", Material.LEATHER_HELMET, Color.FUCHSIA, "&d&lRainbow Helmet", "", LoreBuilder.RAINBOW);
public static final SlimefunItemStack RAINBOW_CHESTPLATE = new SlimefunItemStack("RAINBOW_CHESTPLATE", Material.LEATHER_CHESTPLATE, Color.FUCHSIA, "&d&lRainbow Chestplate", "", LoreBuilder.RAINBOW);
public static final SlimefunItemStack RAINBOW_LEGGINGS = new SlimefunItemStack("RAINBOW_LEGGINGS", Material.LEATHER_LEGGINGS, Color.FUCHSIA, "&d&lRainbow Leggings", "", LoreBuilder.RAINBOW);
public static final SlimefunItemStack RAINBOW_BOOTS = new SlimefunItemStack("RAINBOW_BOOTS", Material.LEATHER_BOOTS, Color.FUCHSIA, "&d&lRainbow Boots", "", LoreBuilder.RAINBOW);
public static final SlimefunItemStack ENDER_HELMET = new SlimefunItemStack("ENDER_HELMET", Material.LEATHER_HELMET, Color.fromRGB(28, 25, 112), "&5&lEnder Helmet", "", "&a&oSometimes its here, sometimes there!");
public static final SlimefunItemStack ENDER_CHESTPLATE = new SlimefunItemStack("ENDER_CHESTPLATE", Material.LEATHER_CHESTPLATE, Color.fromRGB(28, 25, 112), "&5&lEnder Chestplate", "", "&a&oSometimes its here, sometimes there!");
public static final SlimefunItemStack ENDER_LEGGINGS = new SlimefunItemStack("ENDER_LEGGINGS", Material.LEATHER_LEGGINGS, Color.fromRGB(28, 25, 112), "&5&lEnder Leggings", "", "&a&oSometimes its here, sometimes there!");
Expand Down Expand Up @@ -419,14 +423,12 @@ private SlimefunItems() {}
public static final SlimefunItemStack CRAFTING_MOTOR = new SlimefunItemStack("CRAFTING_MOTOR", HeadTexture.CRAFTING_MOTOR, "&6Crafting Motor", "", "&7Important component of Auto-Crafters");

/* Rainbow blocks */
private static final String RAINBOW = "&dCycles through all Colors of the Rainbow!";
public static final SlimefunItemStack RAINBOW_WOOL = new SlimefunItemStack("RAINBOW_WOOL", Material.WHITE_WOOL, "&5Rainbow Wool", "", RAINBOW);
public static final SlimefunItemStack RAINBOW_GLASS = new SlimefunItemStack("RAINBOW_GLASS", Material.WHITE_STAINED_GLASS, "&5Rainbow Glass", "", RAINBOW);
public static final SlimefunItemStack RAINBOW_CLAY = new SlimefunItemStack("RAINBOW_CLAY", Material.WHITE_TERRACOTTA, "&5Rainbow Clay", "", RAINBOW);
public static final SlimefunItemStack RAINBOW_GLASS_PANE = new SlimefunItemStack("RAINBOW_GLASS_PANE", Material.WHITE_STAINED_GLASS_PANE, "&5Rainbow Glass Pane", "", RAINBOW);
public static final SlimefunItemStack RAINBOW_CONCRETE = new SlimefunItemStack("RAINBOW_CONCRETE", Material.WHITE_CONCRETE, "&5Rainbow Concrete", "", RAINBOW);
public static final SlimefunItemStack RAINBOW_GLAZED_TERRACOTTA = new SlimefunItemStack("RAINBOW_GLAZED_TERRACOTTA", Material.WHITE_GLAZED_TERRACOTTA, "&5Rainbow Glazed Terracotta", "", RAINBOW);

public static final SlimefunItemStack RAINBOW_WOOL = new SlimefunItemStack("RAINBOW_WOOL", Material.WHITE_WOOL, "&5Rainbow Wool", "", LoreBuilder.RAINBOW);
public static final SlimefunItemStack RAINBOW_GLASS = new SlimefunItemStack("RAINBOW_GLASS", Material.WHITE_STAINED_GLASS, "&5Rainbow Glass", "", LoreBuilder.RAINBOW);
public static final SlimefunItemStack RAINBOW_CLAY = new SlimefunItemStack("RAINBOW_CLAY", Material.WHITE_TERRACOTTA, "&5Rainbow Clay", "", LoreBuilder.RAINBOW);
public static final SlimefunItemStack RAINBOW_GLASS_PANE = new SlimefunItemStack("RAINBOW_GLASS_PANE", Material.WHITE_STAINED_GLASS_PANE, "&5Rainbow Glass Pane", "", LoreBuilder.RAINBOW);
public static final SlimefunItemStack RAINBOW_CONCRETE = new SlimefunItemStack("RAINBOW_CONCRETE", Material.WHITE_CONCRETE, "&5Rainbow Concrete", "", LoreBuilder.RAINBOW);
public static final SlimefunItemStack RAINBOW_GLAZED_TERRACOTTA = new SlimefunItemStack("RAINBOW_GLAZED_TERRACOTTA", Material.WHITE_GLAZED_TERRACOTTA, "&5Rainbow Glazed Terracotta", "", LoreBuilder.RAINBOW);
/* Seasonal */
private static final String CHRISTMAS = ChatUtils.christmas("[Christmas Edition]");
public static final SlimefunItemStack RAINBOW_WOOL_XMAS = new SlimefunItemStack("RAINBOW_WOOL_XMAS", Material.WHITE_WOOL, "&5Rainbow Wool &7(Christmas)", "", CHRISTMAS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets.Jetpack;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.ParachuteTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.player.ParachuteTask;

/**
* The {@link Parachute} is a {@link SlimefunItem} that can be equipped as a chestplate.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.armor;

import java.util.Arrays;

import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;

import org.apache.commons.lang.Validate;
import org.bukkit.Color;
import org.bukkit.DyeColor;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;

import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;

/**
* Represents a {@link SlimefunArmorPiece} with rainbow properties (leather armor changing color).
*
* @author martinbrom
*/
public class RainbowArmorPiece extends SlimefunArmorPiece {

private final Color[] colors;

/**
* This creates a new {@link RainbowArmorPiece} from the given arguments.
*
* @param itemGroup The {@link ItemGroup} this {@link RainbowArmorPiece} belongs to
* @param item The {@link SlimefunItemStack} that describes the visual features of our {@link RainbowArmorPiece}
* @param recipeType the {@link RecipeType} that determines how this {@link RainbowArmorPiece} is crafted
* @param recipe An Array representing the recipe of this {@link RainbowArmorPiece}
* @param dyeColors An Array representing the {@link DyeColor}s this {@link RainbowArmorPiece} will cycle between
*/
@ParametersAreNonnullByDefault
public RainbowArmorPiece(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, DyeColor[] dyeColors) {
super(itemGroup, item, recipeType, recipe, new PotionEffect[0]);

// TODO Change this validation over to our custom validation blocked by https://github.com/baked-libs/dough/pull/184
Validate.notEmpty(dyeColors, "RainbowArmorPiece colors cannot be empty!");

if (!SlimefunTag.LEATHER_ARMOR.isTagged(item.getType())) {
throw new IllegalArgumentException("Rainbow armor needs to be a leather armor piece!");
}

colors = Arrays.stream(dyeColors)
.map(DyeColor::getColor)
.toArray(Color[]::new);
}

/**
* Returns the {@link Color}s this {@link RainbowArmorPiece} cycles between
*
* @return The {@link Color}s of this {@link RainbowArmorPiece}
*/
public @Nonnull Color[] getColors() {
return colors;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.core.attributes.Rechargeable;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.JetBootsTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.player.JetBootsTask;

/**
* {@link JetBoots} allow you to hover for a bit.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.core.attributes.Rechargeable;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.JetpackTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.player.JetpackTask;

/**
* {@link JetBoots} allow you to fly up into the air.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import io.github.thebusybiscuit.slimefun4.api.items.settings.DoubleRangeSetting;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.core.attributes.Rechargeable;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.ArmorTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.armor.SolarHelmetTask;

/**
* The {@link SolarHelmet} can be worn by {@link Player}.
Expand All @@ -24,8 +24,8 @@
* or holding.
*
* @author TheBusyBiscuit
*
* @see ArmorTask
*
* @see SolarHelmetTask
* @see Rechargeable
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.BeeWingsListener;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.BeeWingsTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.player.BeeWingsTask;

/**
* The {@link BeeWings} are a special form of the elytra which gives you a slow falling effect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemConsumptionHandler;
import io.github.thebusybiscuit.slimefun4.utils.RadiationUtils;

public class Medicine extends MedicalSupply<ItemConsumptionHandler> {

Expand All @@ -21,6 +22,7 @@ public ItemConsumptionHandler getItemHandler() {
return (e, p, item) -> {
p.setFireTicks(0);
clearNegativeEffects(p);
RadiationUtils.clearExposure(p);
heal(p);
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import io.github.thebusybiscuit.slimefun4.core.services.sounds.SoundEffect;
import io.github.thebusybiscuit.slimefun4.utils.RadiationUtils;

public class Vitamins extends MedicalSupply<ItemUseHandler> {

Expand All @@ -34,6 +35,7 @@ public Vitamins(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeTy
e.cancel();
p.setFireTicks(0);
clearNegativeEffects(p);
RadiationUtils.clearExposure(p);
heal(p);
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.items.magical.BeeWings;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.BeeWingsTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.player.BeeWingsTask;

/**
* This {@link Listener} is responsible for the slow falling effect given to the {@link Player}
Expand Down
Loading

0 comments on commit 5b458f1

Please sign in to comment.