Skip to content

Commit fee926c

Browse files
committed
Merge branch 'master' into chore/update-to-1-20-5
2 parents 0773465 + 2fd0f8a commit fee926c

File tree

13 files changed

+103
-49
lines changed

13 files changed

+103
-49
lines changed

.github/ISSUE_TEMPLATE/bug-report.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ body:
2020
options:
2121
- label: I am using the official english version of Slimefun and did not modify the jar.
2222
required: true
23+
- label: I downloaded the official version from the new build site [Blob Builds](https://blob.build/).
24+
required: true
2325
- label: I am using an up to date "DEV" (not "RC") version of Slimefun.
2426
required: true
2527
- label: I am aware that issues related to Slimefun addons need to be reported on their bug trackers and not here.

src/main/java/io/github/thebusybiscuit/slimefun4/api/events/TalismanActivateEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,4 @@ public void setCancelled(boolean cancel) {
9393
public static @Nonnull HandlerList getHandlerList() {
9494
return handlers;
9595
}
96-
}
96+
}

src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,21 @@ public SlimefunItem(ItemGroup itemGroup, SlimefunItemStack item, RecipeType reci
160160
this.recipeOutput = recipeOutput;
161161
}
162162

163+
/**
164+
* This creates a new {@link SlimefunItem} from the given arguments.
165+
*
166+
* @param itemGroup
167+
* The {@link ItemGroup} this {@link SlimefunItem} belongs
168+
* to
169+
* @param item
170+
* The {@link SlimefunItemStack} that describes the visual
171+
* features of our {@link SlimefunItem}
172+
*/
173+
@ParametersAreNonnullByDefault
174+
public SlimefunItem(ItemGroup itemGroup, SlimefunItemStack item) {
175+
this(itemGroup, item, RecipeType.NULL, new ItemStack[] {});
176+
}
177+
163178
// Previously deprecated constructor, now only for internal purposes
164179
@ParametersAreNonnullByDefault
165180
protected SlimefunItem(ItemGroup itemGroup, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe) {

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/MultiTool.java

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
package io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets;
22

33
import java.util.ArrayList;
4-
import java.util.HashMap;
54
import java.util.List;
6-
import java.util.Map;
7-
import java.util.UUID;
5+
import java.util.regex.Pattern;
86

97
import javax.annotation.Nonnull;
108
import javax.annotation.ParametersAreNonnullByDefault;
119

10+
import io.github.bakedlibs.dough.common.ChatColors;
11+
import io.github.bakedlibs.dough.data.persistent.PersistentDataAPI;
1212
import org.bukkit.ChatColor;
1313
import org.bukkit.entity.EntityType;
14+
import org.bukkit.NamespacedKey;
1415
import org.bukkit.entity.Player;
1516
import org.bukkit.inventory.ItemStack;
17+
import org.bukkit.inventory.meta.ItemMeta;
1618

1719
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
1820
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
@@ -28,18 +30,20 @@
2830
/**
2931
* The {@link MultiTool} is an electric device which can mimic
3032
* the behaviour of any other {@link SlimefunItem}.
31-
*
32-
* @author TheBusyBiscuit
3333
*
34+
* @author TheBusyBiscuit
3435
*/
3536
public class MultiTool extends SlimefunItem implements Rechargeable {
3637

3738
private static final float COST = 0.3F;
3839

39-
private final Map<UUID, Integer> selectedMode = new HashMap<>();
4040
private final List<MultiToolMode> modes = new ArrayList<>();
4141
private final float capacity;
4242

43+
private static final NamespacedKey key = new NamespacedKey(Slimefun.instance(), "multitool_mode");
44+
private static final String LORE_PREFIX = ChatColors.color("&8\u21E8 &7Mode: ");
45+
private static final Pattern REGEX = Pattern.compile(ChatColors.color("(&c&o)?" + LORE_PREFIX) + "(.+)");
46+
4347
@ParametersAreNonnullByDefault
4448
public MultiTool(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, float capacity, String... items) {
4549
super(itemGroup, item, recipeType, recipe);
@@ -75,25 +79,44 @@ protected ItemUseHandler getItemUseHandler() {
7579
return e -> {
7680
Player p = e.getPlayer();
7781
ItemStack item = e.getItem();
82+
ItemMeta meta = item.getItemMeta();
7883
e.cancel();
7984

80-
int index = selectedMode.getOrDefault(p.getUniqueId(), 0);
85+
int index = PersistentDataAPI.getInt(meta, key, 0);
86+
SlimefunItem sfItem = modes.get(index).getItem();
8187

8288
if (!p.isSneaking()) {
83-
if (removeItemCharge(item, COST)) {
84-
SlimefunItem sfItem = modes.get(index).getItem();
85-
86-
if (sfItem != null) {
87-
sfItem.callItemHandler(ItemUseHandler.class, handler -> handler.onRightClick(e));
88-
}
89+
if (sfItem != null && removeItemCharge(item, COST)) {
90+
sfItem.callItemHandler(ItemUseHandler.class, handler -> handler.onRightClick(e));
8991
}
9092
} else {
9193
index = nextIndex(index);
9294

9395
SlimefunItem selectedItem = modes.get(index).getItem();
9496
String itemName = selectedItem != null ? selectedItem.getItemName() : "Unknown";
9597
Slimefun.getLocalization().sendMessage(p, "messages.multi-tool.mode-change", true, msg -> msg.replace("%device%", "Multi Tool").replace("%mode%", ChatColor.stripColor(itemName)));
96-
selectedMode.put(p.getUniqueId(), index);
98+
99+
PersistentDataAPI.setInt(meta, key, index);
100+
101+
List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
102+
103+
boolean regexMatchFound = false;
104+
for (int i = 0; i < lore.size(); i++) {
105+
String line = lore.get(i);
106+
107+
if (REGEX.matcher(line).matches()) {
108+
lore.set(i, LORE_PREFIX + ChatColor.stripColor(itemName));
109+
regexMatchFound = true;
110+
break;
111+
}
112+
}
113+
114+
if (!regexMatchFound) {
115+
lore.add(2, LORE_PREFIX + ChatColor.stripColor(itemName));
116+
}
117+
118+
meta.setLore(lore);
119+
item.setItemMeta(meta);
97120
}
98121
};
99122
}

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/MultiToolMode.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,43 @@
88

99
class MultiToolMode {
1010

11+
private final int id;
12+
private final String itemId;
1113
private final ItemSetting<String> item;
1214
private final ItemSetting<Boolean> enabled;
1315

16+
// TODO: Move "id" into some NamespacedKey
1417
MultiToolMode(@Nonnull MultiTool multiTool, int id, @Nonnull String itemId) {
18+
this.id = id;
19+
this.itemId = itemId;
1520
this.item = new ItemSetting<>(multiTool, "mode." + id + ".item", itemId);
1621
this.enabled = new ItemSetting<>(multiTool, "mode." + id + ".enabled", true);
1722

1823
multiTool.addItemSetting(item, enabled);
1924
}
2025

26+
/**
27+
* This method is deprecated and should not be used.
28+
*
29+
*
30+
* @return The ID of this mode
31+
*/
32+
@Deprecated(since = "RC-37", forRemoval = true)
33+
public int getId() {
34+
return id;
35+
}
36+
2137
@Nullable
2238
SlimefunItem getItem() {
2339
return SlimefunItem.getById(item.getValue());
2440
}
2541

42+
@Nonnull
43+
String getItemId() {
44+
return itemId;
45+
}
46+
2647
boolean isEnabled() {
2748
return enabled.getValue();
2849
}
29-
}
50+
}

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ChargingBench.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ protected void tick(Block b) {
4444
for (int slot : getInputSlots()) {
4545
ItemStack item = inv.getItemInSlot(slot);
4646

47+
if (item == null || item.getAmount() != 1) {
48+
continue;
49+
}
50+
4751
if (charge(b, inv, slot, item)) {
4852
return;
4953
}

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/armor/RadiationTask.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
package io.github.thebusybiscuit.slimefun4.implementation.tasks.armor;
22

3-
import java.util.HashMap;
4-
import java.util.Map;
5-
import java.util.UUID;
6-
7-
import javax.annotation.Nonnull;
8-
import javax.annotation.ParametersAreNonnullByDefault;
9-
10-
import org.bukkit.GameMode;
11-
import org.bukkit.entity.Player;
12-
import org.bukkit.inventory.ItemStack;
13-
143
import io.github.bakedlibs.dough.common.ChatColors;
154
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
165
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
176
import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectionType;
187
import io.github.thebusybiscuit.slimefun4.core.attributes.RadiationSymptom;
198
import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactive;
20-
import io.github.thebusybiscuit.slimefun4.implementation.listeners.RadioactivityListener;
219
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
22-
import io.github.thebusybiscuit.slimefun4.implementation.items.RadioactiveItem;
10+
import io.github.thebusybiscuit.slimefun4.implementation.listeners.RadioactivityListener;
2311
import io.github.thebusybiscuit.slimefun4.utils.RadiationUtils;
24-
2512
import net.md_5.bungee.api.ChatMessageType;
2613
import net.md_5.bungee.api.chat.BaseComponent;
2714
import net.md_5.bungee.api.chat.ComponentBuilder;
15+
import org.bukkit.GameMode;
16+
import org.bukkit.entity.Player;
17+
import org.bukkit.inventory.ItemStack;
18+
19+
import javax.annotation.Nonnull;
20+
import javax.annotation.ParametersAreNonnullByDefault;
21+
import java.util.HashMap;
22+
import java.util.Map;
23+
import java.util.UUID;
2824

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

5046
int exposureTotal = 0;
51-
if (!profile.hasFullProtectionAgainst(ProtectionType.RADIATION) && p.getGameMode() != GameMode.CREATIVE && p.getGameMode() != GameMode.SPECTATOR) {
47+
if (!profile.hasFullProtectionAgainst(ProtectionType.RADIATION)
48+
&& p.getGameMode() != GameMode.CREATIVE
49+
&& p.getGameMode() != GameMode.SPECTATOR) {
5250
for (ItemStack item : p.getInventory()) {
5351
if (item == null || item.getType().isAir()) {
5452
continue;
5553
}
5654
SlimefunItem sfItem = SlimefunItem.getByItem(item);
57-
if (sfItem instanceof RadioactiveItem radioactiveItem) {
55+
if (sfItem instanceof Radioactive radioactiveItem) {
5856
exposureTotal += item.getAmount() * radioactiveItem.getRadioactivity().getExposureModifier();
5957
}
6058
}
@@ -72,7 +70,7 @@ protected void onPlayerTick(Player p, PlayerProfile profile) {
7270

7371
int exposureLevelAfter = RadiationUtils.getExposure(p);
7472

75-
Slimefun.runSync(() -> {
73+
Slimefun.runSync(() -> {
7674
for (RadiationSymptom symptom : symptoms) {
7775
if (symptom.shouldApply(exposureLevelAfter)) {
7876
symptom.apply(p);
@@ -81,8 +79,11 @@ protected void onPlayerTick(Player p, PlayerProfile profile) {
8179
});
8280

8381
if (exposureLevelAfter > 0 || exposureLevelBefore > 0) {
84-
String msg = Slimefun.getLocalization().getMessage(p, "actionbar.radiation").replace("%level%", "" + exposureLevelAfter);
85-
BaseComponent[] components = new ComponentBuilder().append(ChatColors.color(msg)).create();
82+
String msg = Slimefun.getLocalization()
83+
.getMessage(p, "actionbar.radiation")
84+
.replace("%level%", "" + exposureLevelAfter);
85+
BaseComponent[] components =
86+
new ComponentBuilder().append(ChatColors.color(msg)).create();
8687
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, components);
8788
}
8889
} else {

src/main/java/me/mrCookieSlime/CSCoreLibPlugin/Configuration/Config.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
* An old remnant of CS-CoreLib.
1414
* This will be removed once we updated everything.
1515
* Don't look at the code, it will be gone soon, don't worry.
16-
*
17-
* @deprecated Only used by the legacy {@link BlockStorage} system.
16+
* Only used by the legacy {@link BlockStorage} system.
1817
*/
19-
@Deprecated
2018
public class Config {
2119

2220
private final File file;

src/main/java/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/ChestMenu.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
* An old remnant of CS-CoreLib.
1717
* This will be removed once we updated everything.
1818
* Don't look at the code, it will be gone soon, don't worry.
19-
*
2019
*/
21-
@Deprecated
2220
public class ChestMenu {
2321

2422
private boolean clickable;
@@ -207,7 +205,6 @@ public ChestMenu addMenuCloseHandler(MenuCloseHandler handler) {
207205
*
208206
* @return The ChestMenu Instance
209207
*/
210-
@Deprecated
211208
public ChestMenu build() {
212209
return this;
213210
}

src/main/java/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/ClickAction.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
* An old remnant of CS-CoreLib.
55
* This will be removed once we updated everything.
66
* Don't look at the code, it will be gone soon, don't worry.
7-
*
87
*/
9-
@Deprecated
108
public class ClickAction {
119

1210
private boolean right;

0 commit comments

Comments
 (0)