mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Removed Reflection
This commit is contained in:
parent
4df99b6fd8
commit
6a0c45c788
@ -140,6 +140,11 @@ public final class PlayerProfile {
|
||||
* @return Whether this {@link Research} has been unlocked
|
||||
*/
|
||||
public boolean hasUnlocked(Research research) {
|
||||
if (research == null) {
|
||||
// No Research, no restriction
|
||||
return true;
|
||||
}
|
||||
|
||||
return !research.isEnabled() || researches.contains(research);
|
||||
}
|
||||
|
||||
|
@ -147,8 +147,10 @@ public class LockedCategory extends Category {
|
||||
public boolean hasUnlocked(Player p, PlayerProfile profile) {
|
||||
for (Category category : parents) {
|
||||
for (SlimefunItem item : category.getItems()) {
|
||||
// Should we replace this all with Slimefun.hasUnlocked() ?
|
||||
if (Slimefun.isEnabled(p, item, false) && Slimefun.hasPermission(p, item, false) && item.getResearch() != null && !profile.hasUnlocked(item.getResearch())) {
|
||||
// Should probably be replaced with Slimefun.hasUnlocked(...)
|
||||
// However this will result in better performance because we don't
|
||||
// request the PlayerProfile everytime
|
||||
if (Slimefun.isEnabled(p, item, false) && Slimefun.hasPermission(p, item, false) && !profile.hasUnlocked(item.getResearch())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -28,9 +28,8 @@ public class CustomTextureService {
|
||||
private String version = null;
|
||||
private boolean modified = false;
|
||||
|
||||
public CustomTextureService(Plugin plugin) {
|
||||
config = new Config(plugin, "item-models.yml");
|
||||
|
||||
public CustomTextureService(Plugin plugin, Config config) {
|
||||
this.config = config;
|
||||
config.getConfiguration().options().header("This file is used to assign items from Slimefun or any of its addons\n" + "the 'CustomModelData' NBT tag. This can be used in conjunction with a custom resource pack\n" + "to give items custom textures.\n0 means there is no data assigned to that item.\n\n" + "There is no official Slimefun resource pack at the moment.");
|
||||
config.getConfiguration().options().copyHeader(true);
|
||||
}
|
||||
|
@ -109,6 +109,7 @@ public class SoulboundRune extends SimpleSlimefunItem<ItemDropHandler> {
|
||||
* The {@link ItemStack} to apply this effect to
|
||||
*/
|
||||
public void apply(ItemStack item) {
|
||||
// Should rather use PersistentData here
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
|
||||
lore.add(ChatColor.GRAY + "Soulbound");
|
||||
|
@ -117,7 +117,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
|
||||
// Services - Systems that fulfill certain tasks, treat them as a black box
|
||||
private final CustomItemDataService itemDataService = new CustomItemDataService(this, "slimefun_item");
|
||||
private final BlockDataService blockDataService = new BlockDataService(this, "slimefun_block");
|
||||
private final CustomTextureService textureService = new CustomTextureService(this);
|
||||
private final CustomTextureService textureService = new CustomTextureService(this, new Config(this, "item-models.yml"));
|
||||
private final GitHubService gitHubService = new GitHubService("TheBusyBiscuit/Slimefun4");
|
||||
private final UpdaterService updaterService = new UpdaterService(this, getDescription().getVersion(), getFile());
|
||||
private final MetricsService metricsService = new MetricsService(this);
|
||||
|
@ -59,16 +59,14 @@ public class TestCategories {
|
||||
item.register(plugin);
|
||||
item.load();
|
||||
|
||||
Assertions.assertTrue(category.getItems().contains(item));
|
||||
Assertions.assertEquals(1, category.getItems().size());
|
||||
|
||||
// Size must still be 1 since we disallow duplicates
|
||||
item.setCategory(category);
|
||||
item.setCategory(category);
|
||||
|
||||
Assertions.assertEquals(1, category.getItems().size());
|
||||
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> category.add(null));
|
||||
|
||||
Assertions.assertTrue(category.getItems().contains(item));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -11,7 +11,6 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import io.github.thebusybiscuit.cscorelib2.config.Config;
|
||||
import io.github.thebusybiscuit.cscorelib2.reflection.ReflectionUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.core.services.CustomTextureService;
|
||||
import io.github.thebusybiscuit.slimefun4.mocks.SlimefunMocks;
|
||||
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
||||
@ -34,7 +33,8 @@ public class TextCustomTextureService {
|
||||
|
||||
@Test
|
||||
public void testInitialization() {
|
||||
CustomTextureService service = new CustomTextureService(plugin);
|
||||
Config config = new Config("plugins/temporary");
|
||||
CustomTextureService service = new CustomTextureService(plugin, config);
|
||||
Assertions.assertFalse(service.isActive());
|
||||
Assertions.assertNull(service.getVersion());
|
||||
|
||||
@ -51,12 +51,12 @@ public class TextCustomTextureService {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetTexture() throws NoSuchFieldException, IllegalAccessException {
|
||||
CustomTextureService service = new CustomTextureService(plugin);
|
||||
public void testSetTexture() {
|
||||
Config config = new Config("plugins/temporary");
|
||||
CustomTextureService service = new CustomTextureService(plugin, config);
|
||||
SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "TEXTURE_TEST", new ItemStack(Material.LANTERN));
|
||||
String version = "Unit Test v1.0";
|
||||
|
||||
Config config = (Config) ReflectionUtils.getFieldValue(service, "config");
|
||||
config.setValue(item.getID(), 300);
|
||||
config.setValue("version", version);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user