Skip to content

Commit

Permalink
fix: misjudgment of the attribute of radioactive items
Browse files Browse the repository at this point in the history
  • Loading branch information
JWJUN233233 committed May 30, 2024
1 parent 45601c8 commit c3e37e6
Showing 1 changed file with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
package io.github.thebusybiscuit.slimefun4.implementation.tasks.armor;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

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

import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import io.github.bakedlibs.dough.common.ChatColors;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectionType;
import io.github.thebusybiscuit.slimefun4.core.attributes.RadiationSymptom;
import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactive;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.RadioactivityListener;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.items.RadioactiveItem;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.RadioactivityListener;
import io.github.thebusybiscuit.slimefun4.utils.RadiationUtils;

import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
* The {@link RadiationTask} handles radioactivity for
Expand All @@ -48,13 +44,15 @@ protected void onPlayerTick(Player p, PlayerProfile profile) {
}

int exposureTotal = 0;
if (!profile.hasFullProtectionAgainst(ProtectionType.RADIATION) && p.getGameMode() != GameMode.CREATIVE && p.getGameMode() != GameMode.SPECTATOR) {
if (!profile.hasFullProtectionAgainst(ProtectionType.RADIATION)
&& p.getGameMode() != GameMode.CREATIVE
&& p.getGameMode() != GameMode.SPECTATOR) {
for (ItemStack item : p.getInventory()) {
if (item == null || item.getType().isAir()) {
continue;
}
SlimefunItem sfItem = SlimefunItem.getByItem(item);
if (sfItem instanceof RadioactiveItem radioactiveItem) {
if (sfItem instanceof Radioactive radioactiveItem) {
exposureTotal += item.getAmount() * radioactiveItem.getRadioactivity().getExposureModifier();
}
}
Expand All @@ -72,7 +70,7 @@ protected void onPlayerTick(Player p, PlayerProfile profile) {

int exposureLevelAfter = RadiationUtils.getExposure(p);

Slimefun.runSync(() -> {
Slimefun.runSync(() -> {
for (RadiationSymptom symptom : symptoms) {
if (symptom.shouldApply(exposureLevelAfter)) {
symptom.apply(p);
Expand All @@ -81,8 +79,11 @@ protected void onPlayerTick(Player p, PlayerProfile profile) {
});

if (exposureLevelAfter > 0 || exposureLevelBefore > 0) {
String msg = Slimefun.getLocalization().getMessage(p, "actionbar.radiation").replace("%level%", "" + exposureLevelAfter);
BaseComponent[] components = new ComponentBuilder().append(ChatColors.color(msg)).create();
String msg = Slimefun.getLocalization()
.getMessage(p, "actionbar.radiation")
.replace("%level%", "" + exposureLevelAfter);
BaseComponent[] components =
new ComponentBuilder().append(ChatColors.color(msg)).create();
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, components);
}
} else {
Expand Down

0 comments on commit c3e37e6

Please sign in to comment.