Skip to content

Commit

Permalink
Merge remote-tracking branch 'Slimefun/master'
Browse files Browse the repository at this point in the history
DEV - 1081
  • Loading branch information
xMikux committed Jul 10, 2023
2 parents 8aa7a9c + 240024e commit a129862
Show file tree
Hide file tree
Showing 55 changed files with 726 additions and 158 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@
<dependency>
<groupId>com.konghq</groupId>
<artifactId>unirest-java</artifactId>
<version>3.14.1</version>
<version>3.14.5</version>
<scope>compile</scope>

<exclusions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public enum MinecraftVersion {

/**
* This constant represents Minecraft (Java Edition) Version 1.20
* ("The Trails & Tales Update")
* ("The Trails &amp; Tales Update")
*/
MINECRAFT_1_20(20, "1.20.x"),

Expand Down
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
Expand Up @@ -39,16 +39,12 @@
import io.github.thebusybiscuit.slimefun4.core.attributes.NotConfigurable;
import io.github.thebusybiscuit.slimefun4.core.attributes.Placeable;
import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactive;
import io.github.thebusybiscuit.slimefun4.core.attributes.Rechargeable;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide;
import io.github.thebusybiscuit.slimefun4.core.handlers.GlobalItemHandler;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.items.VanillaItem;
import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.SlimefunBackpack;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting.AutoDisenchanter;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting.AutoEnchanter;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper;

import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;

Expand Down Expand Up @@ -479,6 +475,14 @@ public void register(@Nonnull SlimefunAddon addon) {
// Now we can be certain this item should be enabled
if (state == ItemState.ENABLED) {
onEnable();
} else {
// Clear item handlers if we are disabled so that calling them isn't possible later on
for (ItemHandler handler : this.itemhandlers.values()) {
if (handler instanceof BlockTicker) {
Slimefun.getRegistry().getTickerBlocks().remove(getId());
}
}
this.itemhandlers.clear();
}

// Lock the SlimefunItemStack from any accidental manipulations
Expand Down Expand Up @@ -767,13 +771,7 @@ public boolean isItem(@Nullable ItemStack item) {
}
}

// Backwards compatibility
if (Slimefun.getRegistry().isBackwardsCompatible()) {
boolean loreInsensitive = this instanceof Rechargeable || this instanceof SlimefunBackpack || id.equals("BROKEN_SPAWNER") || id.equals("REINFORCED_SPAWNER");
return SlimefunUtils.isItemSimilar(item, this.itemStackTemplate, !loreInsensitive);
} else {
return false;
}
return false;
}

/**
Expand Down Expand Up @@ -1179,33 +1177,8 @@ public final int hashCode() {

Optional<String> itemID = Slimefun.getItemDataService().getItemData(item);

if (itemID.isPresent()) {
return getById(itemID.get());
}

// Backwards compatibility
if (Slimefun.getRegistry().isBackwardsCompatible()) {
// This wrapper improves the heavy ItemStack#getItemMeta() call by caching it.
ItemStackWrapper wrapper = ItemStackWrapper.wrap(item);

/*
* Quite expensive performance-wise.
* But necessary for supporting legacy items
*/
for (SlimefunItem sfi : Slimefun.getRegistry().getAllSlimefunItems()) {
if (sfi.isItem(wrapper)) {
/*
* If we have to loop all items for the given item, then at least
* set the id via PersistentDataAPI for future performance boosts
*/
Slimefun.getItemDataService().setItemData(item, sfi.getId());

return sfi;
}
}
}
return itemID.map(SlimefunItem::getById).orElse(null);

return null;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public final class SlimefunRegistry {
private final Set<UUID> researchingPlayers = Collections.synchronizedSet(new HashSet<>());

// TODO: Move this all into a proper "config cache" class
private boolean backwardsCompatibility;
private boolean automaticallyLoadItems;
private boolean enableResearches;
private boolean freeCreativeResearches;
Expand Down Expand Up @@ -109,7 +108,6 @@ public void load(@Nonnull Slimefun plugin, @Nonnull Config cfg) {

researchRanks.addAll(cfg.getStringList("research-ranks"));

backwardsCompatibility = cfg.getBoolean("options.backwards-compatibility");
freeCreativeResearches = cfg.getBoolean("researches.free-in-creative-mode");
researchFireworks = cfg.getBoolean("researches.enable-fireworks");
disableLearningAnimation = cfg.getBoolean("researches.disable-learning-animation");
Expand All @@ -129,29 +127,6 @@ public boolean isAutoLoadingEnabled() {
return automaticallyLoadItems;
}

/**
* This method returns whether backwards-compatibility is enabled.
* Backwards compatibility allows Slimefun to recognize items from older versions but comes
* at a huge performance cost.
*
* @return Whether backwards compatibility is enabled
*/
public boolean isBackwardsCompatible() {
return backwardsCompatibility;
}

/**
* This method sets the status of backwards compatibility.
* Backwards compatibility allows Slimefun to recognize items from older versions but comes
* at a huge performance cost.
*
* @param compatible
* Whether backwards compatibility should be enabled
*/
public void setBackwardsCompatible(boolean compatible) {
backwardsCompatibility = compatible;
}

/**
* This method will make any {@link SlimefunItem} which is registered automatically
* call {@link SlimefunItem#load()}.
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,43 +22,56 @@ 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;

private final String alias;

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

@Nonnull
public String getLore() {
/**
* 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;
}

public @Nonnull String getLore() {
return ChatColor.GREEN + "\u2622" + ChatColor.GRAY + " 輻射等級:" + color + alias;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,6 @@ public void onExecute(@Nonnull CommandSender sender, @Nonnull String[] args) {

addJavaVersion(builder);

if (Slimefun.getRegistry().isBackwardsCompatible()) {
// @formatter:off
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(
"向後相容會對效能產生極大的負面影響!\n" +
"我們建議你關閉此設定,除非你的伺服器\n" +
"仍有在流通舊版的 Slimefun 物品(來自 2019 夏季之前)。"
));
// @formatter:on

builder.append("\n向後相容已啟用!\n").color(ChatColor.RED).event(hoverEvent);
}

builder.append("\n由 芒果綠茶 翻譯").color(ChatColor.WHITE)
.append(
"\n請不要將此版本資訊截圖到官方的 Discord/GitHub 回報 Bug" +
"\n請優先到翻譯專案回報" + "\n"
).color(ChatColor.RED);

builder.append("\n").event((HoverEvent) null);
addPluginVersions(builder);

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
Loading

0 comments on commit a129862

Please sign in to comment.