Skip to content

Commit 7235c30

Browse files
committed
Update
1 parent 3f06dc5 commit 7235c30

15 files changed

+158
-164
lines changed

src/plugin.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: SkUniversal
2-
version: '2.12'
2+
version: '2.12.5'
33
author: Donut
44
main: us.donut.skuniversal.SkUniversal
55
api-version: 1.13

src/us/donut/skuniversal/slimefun/SlimefunHook.java

+41-9
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@
33
import ch.njol.skript.Skript;
44
import ch.njol.skript.registrations.EventValues;
55
import ch.njol.skript.util.Getter;
6-
import me.mrCookieSlime.Slimefun.Events.ResearchUnlockEvent;
6+
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
7+
import io.github.thebusybiscuit.slimefun4.api.events.ResearchUnlockEvent;
8+
import io.github.thebusybiscuit.slimefun4.core.researching.Research;
9+
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
710
import me.mrCookieSlime.Slimefun.Objects.Category;
811
import org.bukkit.entity.Player;
12+
import org.bukkit.plugin.java.JavaPlugin;
13+
import org.jetbrains.annotations.NotNull;
14+
import org.jetbrains.annotations.Nullable;
915
import us.donut.skuniversal.SkUniversalEvent;
1016

11-
import java.util.HashMap;
12-
import java.util.Map;
17+
public class SlimefunHook implements SlimefunAddon {
1318

14-
public class SlimefunHook {
15-
16-
public static Map<String, Category> customCategories = new HashMap<>();
19+
public final static SlimefunHook ADDON = new SlimefunHook();
1720

1821
static {
1922
Skript.registerEvent("Slimefun - Research Unlock", SkUniversalEvent.class, ResearchUnlockEvent.class,
@@ -26,11 +29,40 @@ public Player get(ResearchUnlockEvent e) {
2629
return e.getPlayer();
2730
}
2831
}, 0);
29-
EventValues.registerEventValue(ResearchUnlockEvent.class, Number.class, new Getter<Number, ResearchUnlockEvent>() {
30-
public Number get(ResearchUnlockEvent e) {
31-
return e.getResearch().getID();
32+
EventValues.registerEventValue(ResearchUnlockEvent.class, String.class, new Getter<String, ResearchUnlockEvent>() {
33+
public String get(ResearchUnlockEvent e) {
34+
return e.getResearch().getKey().getKey();
3235
}
3336
}, 0);
3437
}
3538

39+
public static Category getCategory(String id) {
40+
for (Category category : SlimefunPlugin.getRegistry().getCategories()) {
41+
if (category.getKey().getKey().equalsIgnoreCase(id)) {
42+
return category;
43+
}
44+
}
45+
return null;
46+
}
47+
48+
public static Research getResearch(String id) {
49+
for (Research research : SlimefunPlugin.getRegistry().getResearches()) {
50+
if (research.getKey().getKey().equalsIgnoreCase(id)) {
51+
return research;
52+
}
53+
}
54+
return null;
55+
}
56+
57+
@NotNull
58+
@Override
59+
public JavaPlugin getJavaPlugin() {
60+
return Skript.getInstance();
61+
}
62+
63+
@Nullable
64+
@Override
65+
public String getBugTrackerURL() {
66+
return null;
67+
}
3668
}

src/us/donut/skuniversal/slimefun/conditions/CondHasResearch.java

+13-7
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,33 @@
88
import ch.njol.skript.lang.Expression;
99
import ch.njol.skript.lang.SkriptParser;
1010
import ch.njol.util.Kleenean;
11-
import me.mrCookieSlime.Slimefun.Objects.Research;
11+
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
1212
import org.bukkit.OfflinePlayer;
1313
import org.bukkit.event.Event;
14+
import us.donut.skuniversal.slimefun.SlimefunHook;
1415

1516
import javax.annotation.Nullable;
17+
import java.util.Optional;
1618

1719
@Name("Slimefun - Has Unlocked Research")
1820
@Description("Checks if a player has a research unlocked.")
19-
@Examples({"if the player has unlocked the research with id 2048:"})
21+
@Examples({"if the player has unlocked the research with id \"cool_research\":"})
2022
public class CondHasResearch extends Condition {
2123

2224
static {
2325
Skript.registerCondition(CondHasResearch.class,
24-
"offlineplayer% has [unlocked] [the] [Slimefun] research [with ID] %integer%",
25-
"offlineplayer% has(n't| not) [unlocked] [the] [Slimefun] research [with ID] %integer%");
26+
"%offlineplayer% has [unlocked] [the] [Slimefun] research [with ID] %string%",
27+
"%offlineplayer% has(n't| not) [unlocked] [the] [Slimefun] research [with ID] %string%");
2628
}
2729

2830
private Expression<OfflinePlayer> player;
29-
private Expression<Integer> id;
31+
private Expression<String> id;
3032

3133
@SuppressWarnings("unchecked")
3234
@Override
3335
public boolean init(Expression<?>[] e, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult pr) {
3436
player = (Expression<OfflinePlayer>) e[0];
35-
id = (Expression<Integer>) e[1];
37+
id = (Expression<String>) e[1];
3638
setNegated(matchedPattern == 1);
3739
return true;
3840
}
@@ -45,6 +47,10 @@ public String toString(@Nullable Event e, boolean b) {
4547
@Override
4648
public boolean check(Event e) {
4749
if (player.getSingle(e) == null || id.getSingle(e) == null) return isNegated();
48-
return Research.getByID(id.getSingle(e)).hasUnlocked(player.getSingle(e).getUniqueId()) != isNegated();
50+
Optional<PlayerProfile> profile = PlayerProfile.find(player.getSingle(e));
51+
if (profile.isPresent()) {
52+
return profile.get().hasUnlocked(SlimefunHook.getResearch(id.getSingle(e))) != isNegated();
53+
}
54+
return isNegated();
4955
}
5056
}

src/us/donut/skuniversal/slimefun/effects/EffAddResearch.java

+11-8
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,23 @@
1010
import ch.njol.skript.lang.Expression;
1111
import ch.njol.skript.lang.SkriptParser;
1212
import ch.njol.util.Kleenean;
13-
import me.mrCookieSlime.Slimefun.Objects.Research;
13+
import io.github.thebusybiscuit.slimefun4.core.researching.Research;
1414
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
1515
import org.bukkit.event.Event;
16+
import us.donut.skuniversal.slimefun.SlimefunHook;
1617

1718
import javax.annotation.Nullable;
1819

1920
@Name("Slimefun - Add Research")
2021
@Description("Adds Slimefun research to an item.")
21-
@Examples({"add the slimefun research with id 2048 to the slimefun item named \"COOL_DIRT\""})
22+
@Examples({"add the slimefun research with ID \"cool_research\" to the slimefun item \"COOL_DIRT\""})
2223
public class EffAddResearch extends Effect {
2324

2425
static {
25-
Skript.registerEffect(EffAddResearch.class, "add [the] [Slimefun] research [with ID] %integer% to [the] [Slimefun] [item] [(named|with name)] %string%");
26+
Skript.registerEffect(EffAddResearch.class, "add [the] [Slimefun] research [with ID] %string% to [the] [Slimefun] [item] [with ID] %string%");
2627
}
2728

28-
private Expression<Integer> id;
29+
private Expression<String> id;
2930
private Expression<String> item;
3031

3132
@SuppressWarnings("unchecked")
@@ -35,7 +36,7 @@ public boolean init(Expression<?>[] e, int matchedPattern, Kleenean isDelayed, S
3536
Skript.error("You can not use Slimefun add research expression in any event but on script load.");
3637
return false;
3738
}
38-
id = (Expression<Integer>) e[0];
39+
id = (Expression<String>) e[0];
3940
item = (Expression<String>) e[1];
4041
return true;
4142
}
@@ -47,8 +48,10 @@ public String toString(@Nullable Event e, boolean b) {
4748
@Override
4849
protected void execute(Event e) {
4950
if (id.getSingle(e) == null || item.getSingle(e) == null) return;
50-
Research research = Research.getByID(id.getSingle(e));
51-
research.addItems(SlimefunItem.getByID(item.getSingle(e)));
52-
research.register();
51+
Research research = SlimefunHook.getResearch(id.getSingle(e));
52+
if (research != null) {
53+
research.addItems(SlimefunItem.getByID(item.getSingle(e)));
54+
research.register();
55+
}
5356
}
5457
}

src/us/donut/skuniversal/slimefun/effects/EffCreateCategory.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import ch.njol.skript.lang.SkriptParser;
1212
import ch.njol.util.Kleenean;
1313
import me.mrCookieSlime.Slimefun.Objects.Category;
14+
import org.bukkit.NamespacedKey;
1415
import org.bukkit.event.Event;
1516
import org.bukkit.inventory.ItemStack;
1617
import us.donut.skuniversal.slimefun.SlimefunHook;
@@ -19,14 +20,14 @@
1920

2021
@Name("Slimefun - Create Category")
2122
@Description("Creates Slimefun category (it will not show up in the guide unless you create at least 1 item for it)")
22-
@Examples("create slimefun category named \"Cool Stuff\" with menu item dirt named \"Cool Stuff\" with priority 0")
23+
@Examples("create slimefun category with ID \"cool_stuff\" with menu item dirt named \"Cool Stuff\" with priority 0")
2324
public class EffCreateCategory extends Effect {
2425

2526
static {
26-
Skript.registerEffect(EffCreateCategory.class, "create [a] [new] [Slimefun] category [(named|with name)] %string% with [menu] item %itemstack% with (level|priority) %integer%");
27+
Skript.registerEffect(EffCreateCategory.class, "create [a] [new] [Slimefun] category [with ID] %string% with [menu] item %itemstack% with (level|priority|tier) %integer%");
2728
}
2829

29-
private Expression<String> name;
30+
private Expression<String> id;
3031
private Expression<ItemStack> item;
3132
private Expression<Integer> level;
3233

@@ -37,19 +38,19 @@ public boolean init(Expression<?>[] e, int matchedPattern, Kleenean isDelayed, S
3738
Skript.error("You can not use Slimefun create category effect in any event but on skript load.");
3839
return false;
3940
}
40-
name = (Expression<String>) e[0];
41+
id = (Expression<String>) e[0];
4142
item = (Expression<ItemStack>) e[1];
4243
level = (Expression<Integer>) e[2];
4344
return true;
4445
}
4546
@Override
4647
public String toString(@Nullable Event e, boolean b) {
47-
return "create Slimefun category " + name.toString(e, b) + " with item " + item.toString(e, b) + " with level " + level.toString(e, b);
48+
return "create Slimefun category " + id.toString(e, b) + " with item " + item.toString(e, b) + " with level " + level.toString(e, b);
4849
}
4950

5051
@Override
5152
protected void execute(Event e) {
52-
if (name.getSingle(e) == null || item.getSingle(e) == null || level.getSingle(e) == null) return;
53-
SlimefunHook.customCategories.put(name.getSingle(e).toLowerCase(), new Category(item.getSingle(e), level.getSingle(e)));
53+
if (id.getSingle(e) == null || item.getSingle(e) == null || level.getSingle(e) == null) return;
54+
new Category(new NamespacedKey(Skript.getInstance(), id.getSingle(e).toLowerCase()), item.getSingle(e), level.getSingle(e)).register(SlimefunHook.ADDON);
5455
}
5556
}

src/us/donut/skuniversal/slimefun/effects/EffCreateItem.java

+9-16
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
import ch.njol.skript.lang.Expression;
1111
import ch.njol.skript.lang.SkriptParser;
1212
import ch.njol.util.Kleenean;
13-
import me.mrCookieSlime.Slimefun.Lists.Categories;
1413
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
15-
import me.mrCookieSlime.Slimefun.Objects.Category;
1614
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
15+
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
1716
import org.bukkit.Material;
1817
import org.bukkit.event.Event;
1918
import org.bukkit.inventory.ItemStack;
@@ -59,24 +58,18 @@ public String toString(@Nullable Event e, boolean b) {
5958
@Override
6059
protected void execute(Event e) {
6160
if (item.getSingle(e) == null || id.getSingle(e) == null || category.getSingle(e) == null || recipe.getSingle(e) == null || recipeType.getSingle(e) == null) return;
62-
Category actualCategory;
63-
RecipeType actualRecipeType;
64-
ItemStack[] actualRecipe = recipe.getArray(e);
61+
RecipeType slimefunRecipeType;
6562
try {
66-
actualCategory = (Category) Categories.class.getField(category.getSingle(e)).get(Category.class);
63+
slimefunRecipeType = (RecipeType) RecipeType.class.getField(recipeType.getSingle(e)).get(null);
6764
} catch (NoSuchFieldException | IllegalAccessException exc) {
68-
actualCategory = SlimefunHook.customCategories.getOrDefault(category.getSingle(e).toLowerCase(), Categories.MISC);
65+
slimefunRecipeType = RecipeType.ENHANCED_CRAFTING_TABLE;
6966
}
70-
try {
71-
actualRecipeType = (RecipeType) RecipeType.class.getField(recipeType.getSingle(e)).get(RecipeType.class);
72-
} catch (NoSuchFieldException | IllegalAccessException exc) {
73-
actualRecipeType = RecipeType.ENHANCED_CRAFTING_TABLE;
74-
}
75-
for (int i = 0; i < actualRecipe.length; i++) {
76-
if (actualRecipe[i].getType() == Material.AIR) {
77-
actualRecipe[i] = null;
67+
ItemStack[] recipeItems = recipe.getArray(e);
68+
for (int i = 0; i < recipeItems.length; i++) {
69+
if (recipeItems[i].getType() == Material.AIR) {
70+
recipeItems[i] = null;
7871
}
7972
}
80-
new SlimefunItem(actualCategory, item.getSingle(e), id.getSingle(e), actualRecipeType, actualRecipe).register();
73+
new SlimefunItem(SlimefunHook.getCategory(category.getSingle(e).toLowerCase()), new SlimefunItemStack(id.getSingle(e), item.getSingle(e)), slimefunRecipeType, recipeItems).register(SlimefunHook.ADDON);
8174
}
8275
}

src/us/donut/skuniversal/slimefun/effects/EffCreateLockedCategory.java

+14-17
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import ch.njol.skript.lang.Expression;
1111
import ch.njol.skript.lang.SkriptParser;
1212
import ch.njol.util.Kleenean;
13-
import me.mrCookieSlime.Slimefun.Lists.Categories;
13+
import io.github.thebusybiscuit.slimefun4.core.categories.LockedCategory;
1414
import me.mrCookieSlime.Slimefun.Objects.Category;
15-
import me.mrCookieSlime.Slimefun.Objects.LockedCategory;
15+
import org.bukkit.NamespacedKey;
1616
import org.bukkit.event.Event;
1717
import org.bukkit.inventory.ItemStack;
1818
import us.donut.skuniversal.slimefun.SlimefunHook;
@@ -23,14 +23,14 @@
2323

2424
@Name("Slimefun - Create Locked Category")
2525
@Description("Creates Slimefun locked category (it will not show up in the guide unless you create at least 1 item for it)")
26-
@Examples("create locked slimefun category named \"Locked Cool Stuff\" with menu item dirt named \"Locked Cool Stuff\" with priority 0 with required categories \"RESOURCES\"")
26+
@Examples("create locked slimefun category with ID \"cool_locked_stuff\" with menu item dirt named \"Cool Locked Stuff\" with priority 0 with required categories \"RESOURCES\"")
2727
public class EffCreateLockedCategory extends Effect {
2828

2929
static {
30-
Skript.registerEffect(EffCreateLockedCategory.class, "create [a] [new] locked [Slimefun] category [(named|with name)] %string% with [menu] item %itemstack% with (level|priority) %integer% with required categor(y|ies) %strings%");
30+
Skript.registerEffect(EffCreateLockedCategory.class, "create [a] [new] locked [Slimefun] category [with ID] %string% with [menu] item %itemstack% with (level|priority|tier) %integer% with required categor(y|ies) %strings%");
3131
}
3232

33-
private Expression<String> name;
33+
private Expression<String> id;
3434
private Expression<ItemStack> item;
3535
private Expression<Integer> level;
3636
private Expression<String> categories;
@@ -42,30 +42,27 @@ public boolean init(Expression<?>[] e, int matchedPattern, Kleenean isDelayed, S
4242
Skript.error("You can not use Slimefun create locked category effect in any event but on skript load.");
4343
return false;
4444
}
45-
name = (Expression<String>) e[0];
45+
id = (Expression<String>) e[0];
4646
item = (Expression<ItemStack>) e[1];
4747
level = (Expression<Integer>) e[2];
4848
categories = (Expression<String>) e[3];
4949
return true;
5050
}
5151
@Override
5252
public String toString(@Nullable Event e, boolean b) {
53-
return "create Slimefun category " + name.toString(e, b) + " with item " + item.toString(e, b) + " with level " + level.toString(e, b) + " with required categories " + categories.toString(e, b);
53+
return "create Slimefun category " + id.toString(e, b) + " with item " + item.toString(e, b) + " with level " + level.toString(e, b) + " with required categories " + categories.toString(e, b);
5454
}
5555

5656
@Override
5757
protected void execute(Event e) {
58-
if (name.getSingle(e) == null || item.getSingle(e) == null || level.getSingle(e) == null || categories.getSingle(e) == null) return;
59-
List<Category> requiredCategories = new ArrayList<>();
60-
for (String categoryString : categories.getArray(e)) {
61-
try {
62-
requiredCategories.add((Category) Categories.class.getField(categoryString).get(Category.class));
63-
} catch (NoSuchFieldException | IllegalAccessException exc) {
64-
if (SlimefunHook.customCategories.containsKey(categoryString.toLowerCase())) {
65-
requiredCategories.add(SlimefunHook.customCategories.get(categoryString.toLowerCase()));
66-
}
58+
if (id.getSingle(e) == null || item.getSingle(e) == null || level.getSingle(e) == null || categories.getSingle(e) == null) return;
59+
List<NamespacedKey> requiredCategories = new ArrayList<>();
60+
for (String categoryID : categories.getArray(e)) {
61+
Category category = SlimefunHook.getCategory(categoryID);
62+
if (category != null) {
63+
requiredCategories.add(category.getKey());
6764
}
6865
}
69-
SlimefunHook.customCategories.put(name.getSingle(e).toLowerCase(), new LockedCategory(item.getSingle(e), level.getSingle(e), requiredCategories.toArray(new Category[0])));
66+
new LockedCategory(new NamespacedKey(Skript.getInstance(), id.getSingle(e).toLowerCase()), item.getSingle(e), level.getSingle(e), requiredCategories.toArray(new NamespacedKey[0])).register(SlimefunHook.ADDON);
7067
}
7168
}

0 commit comments

Comments
 (0)