org.bukkit.NamespacedKey Java Examples

The following examples show how to use org.bukkit.NamespacedKey. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestSlimefunItemRegistration.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testCategoryRegistration() {
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "CATEGORY_TEST", new CustomItem(Material.DIAMOND, "&cTest"));
    item.register(plugin);
    item.load();

    // null should not be a valid argument
    Assertions.assertThrows(IllegalArgumentException.class, () -> item.setCategory(null));

    Category category = item.getCategory();
    Category category2 = new Category(new NamespacedKey(plugin, "test2"), new CustomItem(Material.OBSIDIAN, "&6Test 2"));

    Assertions.assertTrue(category.contains(item));
    Assertions.assertFalse(category2.contains(item));
    Assertions.assertEquals(category, item.getCategory());

    item.setCategory(category2);
    Assertions.assertFalse(category.contains(item));
    Assertions.assertTrue(category2.contains(item));
    Assertions.assertEquals(category2, item.getCategory());
}
 
Example #2
Source File: TestProfileResearches.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testHasUnlocked() throws InterruptedException {
    SlimefunPlugin.getRegistry().setResearchingEnabled(true);

    Player player = server.addPlayer();
    PlayerProfile profile = TestUtilities.awaitProfile(player);

    NamespacedKey key = new NamespacedKey(plugin, "player_profile_test");
    Research research = new Research(key, 280, "Test", 100);
    research.register();

    profile.setResearched(research, true);

    Assertions.assertTrue(profile.hasUnlocked(research));
    Assertions.assertTrue(profile.hasUnlocked(null));

    profile.setResearched(research, false);
    Assertions.assertFalse(profile.hasUnlocked(research));

    // Researches are disabled now, so this method should pass
    // Whether Research#isEnabled() works correctly is covered elsewhere
    SlimefunPlugin.getRegistry().setResearchingEnabled(false);
    Assertions.assertTrue(profile.hasUnlocked(research));
}
 
Example #3
Source File: V1_14ToV1_15NmsBridge.java    From CraftserveRadiation with Apache License 2.0 6 votes vote down vote up
@Override
public void registerLugolsIodinePotion(final NamespacedKey potionKey, final LugolsIodinePotion.Config config) {
    try {
        Object basePotion = getPotion.invoke(potionRegistry, newMinecraftKey.invoke(null, config.getRecipe().getBasePotion().name().toLowerCase()));
        Object ingredient = getItem.invoke(null, config.getRecipe().getIngredient());

        Object registryType = this.iRegistryClass.getDeclaredField("POTION").get(null);
        Object mobEffectArray = Array.newInstance(this.mobEffectClass, 0);
        Object newPotion = this.potionRegistryClass.getConstructor(mobEffectArray.getClass()).newInstance(mobEffectArray);

        Method registerMethod = this.iRegistryClass.getDeclaredMethod("a", this.iRegistryClass, String.class, Object.class);
        Object potion = registerMethod.invoke(null, registryType, potionKey.getKey(), newPotion);

        Method registerBrewingRecipe = this.potionBrewerClass.getDeclaredMethod("a", this.potionRegistryClass, this.itemClass, this.potionRegistryClass);
        registerBrewingRecipe.setAccessible(true);
        registerBrewingRecipe.invoke(null, basePotion, ingredient, potion);
    } catch (Exception e) {
        this.plugin.getLogger().log(Level.SEVERE, "Could not handle reflective operation.", e);
    }
}
 
Example #4
Source File: ArmorStandDisplayItem.java    From QuickShop-Reremake with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void safeGuard(@NotNull Entity entity) {
    if (!(entity instanceof ArmorStand)) {
        Util.debugLog(
                "Failed to safeGuard " + entity.getLocation() + ", cause target not a ArmorStand");
        return;
    }
    ArmorStand armorStand = (ArmorStand) entity;
    // Set item protect in the armorstand's hand
    this.guardedIstack = DisplayItem.createGuardItemStack(this.originalItemStack, this.shop);
    armorStand.setHelmet(guardedIstack);
    try {
        armorStand
                .getPersistentDataContainer()
                .set(
                        new NamespacedKey(plugin, "displayMark"),
                        DisplayItemPersistentDataType.INSTANCE,
                        DisplayItem.createShopProtectionFlag(this.originalItemStack, shop));
    } catch (Throwable ignored) {
    }
}
 
Example #5
Source File: TestCategories.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testLockedCategoriesParents() {
    Assertions.assertThrows(IllegalArgumentException.class, () -> new LockedCategory(new NamespacedKey(plugin, "locked"), new CustomItem(Material.GOLD_NUGGET, "&6Locked Test"), (NamespacedKey) null));

    Category category = new Category(new NamespacedKey(plugin, "unlocked"), new CustomItem(Material.EMERALD, "&5I am SHERlocked"));
    category.register();

    Category unregistered = new Category(new NamespacedKey(plugin, "unregistered"), new CustomItem(Material.EMERALD, "&5I am unregistered"));

    LockedCategory locked = new LockedCategory(new NamespacedKey(plugin, "locked"), new CustomItem(Material.GOLD_NUGGET, "&6Locked Test"), category.getKey(), unregistered.getKey());
    locked.register();

    Assertions.assertTrue(locked.getParents().contains(category));
    Assertions.assertFalse(locked.getParents().contains(unregistered));

    locked.removeParent(category);
    Assertions.assertFalse(locked.getParents().contains(category));

    Assertions.assertThrows(IllegalArgumentException.class, () -> locked.addParent(locked));
    Assertions.assertThrows(IllegalArgumentException.class, () -> locked.addParent(null));

    locked.addParent(category);
    Assertions.assertTrue(locked.getParents().contains(category));
}
 
Example #6
Source File: TestRecipeService.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testShapelessRecipeShape() {
    MinecraftRecipeService service = new MinecraftRecipeService(plugin);

    Assertions.assertThrows(IllegalArgumentException.class, () -> service.getRecipeShape(null));

    NamespacedKey key = new NamespacedKey(plugin, "shapeless_test");
    ShapelessRecipe recipe = new ShapelessRecipe(key, new ItemStack(Material.TNT_MINECART));
    MaterialChoice choice = new MaterialChoice(Material.TNT);
    recipe.addIngredient(choice);

    server.addRecipe(recipe);
    service.refresh();

    Assertions.assertArrayEquals(new RecipeChoice[] { choice }, service.getRecipeShape(recipe));
}
 
Example #7
Source File: TestResearches.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testFreeCreativeResearch() {
    SlimefunPlugin.getRegistry().setResearchingEnabled(true);

    Player player = server.addPlayer();
    NamespacedKey key = new NamespacedKey(plugin, "freeCreativeResearch");
    Research research = new Research(key, 153, "Test", 100);

    SlimefunPlugin.getRegistry().setFreeCreativeResearchingEnabled(false);

    player.setGameMode(GameMode.SURVIVAL);
    Assertions.assertFalse(research.canUnlock(player));

    player.setGameMode(GameMode.CREATIVE);
    Assertions.assertFalse(research.canUnlock(player));

    SlimefunPlugin.getRegistry().setFreeCreativeResearchingEnabled(true);

    player.setGameMode(GameMode.SURVIVAL);
    Assertions.assertFalse(research.canUnlock(player));

    player.setGameMode(GameMode.CREATIVE);
    Assertions.assertTrue(research.canUnlock(player));
}
 
Example #8
Source File: TestResourceRegistration.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testOilResource() {
    NamespacedKey key = new NamespacedKey(plugin, "oil");
    GEOResource resource = testResource(key, "Oil", SlimefunItems.OIL_BUCKET, false, 8);

    Assertions.assertEquals(0, resource.getDefaultSupply(Environment.NETHER, Biome.NETHER_WASTES));

    Assertions.assertNotEquals(0, resource.getDefaultSupply(Environment.NORMAL, Biome.BEACH));
    Assertions.assertTrue(resource.getDefaultSupply(Environment.NORMAL, Biome.DESERT) > 10);
    Assertions.assertTrue(resource.getDefaultSupply(Environment.NORMAL, Biome.MOUNTAINS) > 10);
    Assertions.assertTrue(resource.getDefaultSupply(Environment.NORMAL, Biome.ICE_SPIKES) > 10);
    Assertions.assertTrue(resource.getDefaultSupply(Environment.NORMAL, Biome.BADLANDS) > 10);
    Assertions.assertTrue(resource.getDefaultSupply(Environment.NORMAL, Biome.OCEAN) > 10);
    Assertions.assertTrue(resource.getDefaultSupply(Environment.NORMAL, Biome.SWAMP) > 10);
    Assertions.assertEquals(10, resource.getDefaultSupply(Environment.NORMAL, Biome.SUNFLOWER_PLAINS));
}
 
Example #9
Source File: TestGuideHistory.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testCategory() throws InterruptedException {
    Player player = server.addPlayer();
    PlayerProfile profile = TestUtilities.awaitProfile(player);
    GuideHistory history = profile.getGuideHistory();

    Category category = new Category(new NamespacedKey(plugin, "category_guide_history"), new CustomItem(Material.BEDROCK, "&4Can't touch this"));

    Assertions.assertThrows(IllegalArgumentException.class, () -> history.add((Category) null, 1));
    Assertions.assertThrows(IllegalArgumentException.class, () -> history.add(category, -20));

    Assertions.assertEquals(0, history.size());
    history.add(category, 1);
    Assertions.assertEquals(1, history.size());

    // This should not add a new entry but rather only update the page
    history.add(category, 2);
    Assertions.assertEquals(1, history.size());
}
 
Example #10
Source File: TestCategories.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testSeasonalCategories() {
    // Category with current Month
    Month month = LocalDate.now().getMonth();
    SeasonalCategory category = new SeasonalCategory(new NamespacedKey(plugin, "seasonal"), month, 1, new CustomItem(Material.NETHER_STAR, "&cSeasonal Test"));
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "SEASONAL_ITEM", new CustomItem(Material.NETHER_STAR, "&dSeasonal Test Star"));
    item.setCategory(category);
    item.register(plugin);
    item.load();

    Player player = server.addPlayer();

    Assertions.assertEquals(month, category.getMonth());
    Assertions.assertFalse(category.isHidden(player));

    // Category with future Month
    SeasonalCategory category2 = new SeasonalCategory(category.getKey(), month.plus(6), 1, new CustomItem(Material.MILK_BUCKET, "&dSeasonal Test"));
    Assertions.assertTrue(category2.isHidden(player));
}
 
Example #11
Source File: TestRecipeService.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testRecipe() {
    MinecraftRecipeService service = new MinecraftRecipeService(plugin);

    NamespacedKey key = new NamespacedKey(plugin, "furnace_recipe_test");
    ItemStack result = new ItemStack(Material.EMERALD_BLOCK);
    FurnaceRecipe recipe = new FurnaceRecipe(key, result, new MaterialChoice(Material.DIAMOND), 1, 2);
    server.addRecipe(recipe);

    // The Snapshot has not been taken, so it should fallback to an empty array
    Assertions.assertEquals(0, service.getRecipesFor(result).length);

    service.refresh();

    Recipe[] recipes = service.getRecipesFor(result);
    Assertions.assertEquals(1, recipes.length);
    Assertions.assertEquals(recipe, recipes[0]);
}
 
Example #12
Source File: TestResearches.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testResearchRegistration() {
    NamespacedKey key = new NamespacedKey(plugin, "testResearch");
    Research research = new Research(key, 1, "Test", 100);
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "RESEARCH_TEST", new CustomItem(Material.TORCH, "&bResearch Test"));
    research.addItems(item, null);
    research.register();

    SlimefunPlugin.getRegistry().setResearchingEnabled(true);

    Assertions.assertTrue(research.isEnabled());
    Assertions.assertEquals(research, item.getResearch());
    Assertions.assertTrue(SlimefunPlugin.getRegistry().getResearches().contains(research));

    Optional<Research> optional = Research.getResearch(key);
    Assertions.assertTrue(optional.isPresent());
    Assertions.assertEquals(research, optional.get());
}
 
Example #13
Source File: NMS_1_15.java    From 1.13-Command-API with Apache License 2.0 6 votes vote down vote up
@Override
public ComplexRecipe getRecipe(CommandContext cmdCtx, String key) throws CommandSyntaxException {
	IRecipe<?> recipe = ArgumentMinecraftKeyRegistered.b(cmdCtx, key);
	return new ComplexRecipe() {
		
		@SuppressWarnings("deprecation")
		@Override
		public NamespacedKey getKey() {
			return new NamespacedKey(recipe.getKey().getNamespace(), recipe.getKey().getKey());
		}
		
		@Override
		public ItemStack getResult() {
			return recipe.toBukkitRecipe().getResult();
		}
	};
}
 
Example #14
Source File: NMS_1_14_4.java    From 1.13-Command-API with Apache License 2.0 6 votes vote down vote up
@Override
public FunctionWrapper[] getFunction(CommandContext cmdCtx, String str) throws CommandSyntaxException {
    Collection<CustomFunction> customFuncList = ArgumentTag.a(cmdCtx, str);

    FunctionWrapper[] result = new FunctionWrapper[customFuncList.size()];

    CustomFunctionData customFunctionData = getCLW(cmdCtx).getServer().getFunctionData();
    CommandListenerWrapper commandListenerWrapper = getCLW(cmdCtx).a().b(2);

    int count = 0;
    for(CustomFunction customFunction : customFuncList) {
        @SuppressWarnings("deprecation")
        NamespacedKey minecraftKey = new NamespacedKey(customFunction.a().getNamespace(), customFunction.a().getKey());
        ToIntBiFunction<CustomFunction, CommandListenerWrapper> obj = customFunctionData::a;

        FunctionWrapper wrapper = new FunctionWrapper(minecraftKey, obj, customFunction, commandListenerWrapper, e -> {
            return (Object) getCLW(cmdCtx).a(((CraftEntity) e).getHandle());
        });

        result[count] = wrapper;
        count++;
    }

    return result;
}
 
Example #15
Source File: RecipeType.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
public RecipeType(ItemStack item, String machine) {
    this.item = item;
    this.machine = machine;

    if (machine.length() > 0) {
        this.key = new NamespacedKey(SlimefunPlugin.instance, machine.toLowerCase(Locale.ROOT));
    }
    else {
        this.key = new NamespacedKey(SlimefunPlugin.instance, "unknown");
    }
}
 
Example #16
Source File: NMS_1_13_2.java    From 1.13-Command-API with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public LootTable getLootTable(CommandContext cmdCtx, String str) {
    MinecraftKey minecraftKey = ArgumentMinecraftKeyRegistered.c(cmdCtx, str);
    String namespace = minecraftKey.b();
    String key = minecraftKey.getKey();

    net.minecraft.server.v1_13_R2.LootTable lootTable = getCLW(cmdCtx).getServer().getLootTableRegistry().getLootTable(minecraftKey);
    return new CraftLootTable(new NamespacedKey(namespace, key), lootTable);
}
 
Example #17
Source File: TestResourceRegistration.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testUraniumResource() {
    NamespacedKey key = new NamespacedKey(plugin, "uranium");
    GEOResource resource = testResource(key, "Small Chunks of Uranium", SlimefunItems.SMALL_URANIUM, true, 2);

    Assertions.assertNotEquals(0, resource.getDefaultSupply(Environment.NORMAL, Biome.MOUNTAINS));
    Assertions.assertEquals(0, resource.getDefaultSupply(Environment.NETHER, Biome.NETHER_WASTES));
    Assertions.assertEquals(0, resource.getDefaultSupply(Environment.THE_END, Biome.THE_END));
}
 
Example #18
Source File: Research.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Attempts to get a {@link Research} with the given {@link NamespacedKey}.
 * 
 * @param key
 *            the {@link NamespacedKey} of the {@link Research} you are looking for
 * 
 * @return An {@link Optional} with or without the found {@link Research}
 */
public static Optional<Research> getResearch(NamespacedKey key) {
    if (key == null) {
        return Optional.empty();
    }

    for (Research research : SlimefunPlugin.getRegistry().getResearches()) {
        if (research.getKey().equals(key)) {
            return Optional.of(research);
        }
    }

    return Optional.empty();
}
 
Example #19
Source File: WorldBorderDataTagType.java    From WorldBorderAPI with MIT License 5 votes vote down vote up
public WorldBorderDataTagType(JavaPlugin javaPlugin) {
    this.sizeKey = new NamespacedKey(javaPlugin, "size");
    this.xKey = new NamespacedKey(javaPlugin, "center_x");
    this.zKey = new NamespacedKey(javaPlugin, "center_z");
    this.damageBufferInBlocksKey = new NamespacedKey(javaPlugin, "damage_buffer_in_blocks");
    this.damageAmountKey = new NamespacedKey(javaPlugin, "damage_amount");
    this.warningTimeSecondsKey = new NamespacedKey(javaPlugin, "warning_time_seconds");
    this.warningDistanceKey = new NamespacedKey(javaPlugin, "warning_distance");
}
 
Example #20
Source File: OilPump.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
public OilPump(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
    super(category, item, recipeType, recipe);

    oil = SlimefunPlugin.getRegistry().getGEOResources().get(new NamespacedKey(SlimefunPlugin.instance, "oil")).orElse(null);

    new BlockMenuPreset(getID(), getInventoryTitle()) {

        @Override
        public void init() {
            constructMenu(this);
        }

        @Override
        public boolean canOpen(Block b, Player p) {
            if (!(p.hasPermission("slimefun.inventory.bypass") || SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.ACCESS_INVENTORIES))) {
                return false;
            }

            if (!SlimefunPlugin.getGPSNetwork().getResourceManager().getSupplies(oil, b.getWorld(), b.getX() >> 4, b.getZ() >> 4).isPresent()) {
                SlimefunPlugin.getLocalization().sendMessage(p, "gps.geo.scan-required", true);
                return false;
            }

            return true;
        }

        @Override
        public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) {
            if (flow == ItemTransportFlow.INSERT) {
                return getInputSlots();
            }
            else {
                return getOutputSlots();
            }
        }
    };
}
 
Example #21
Source File: NMS_1_13_1.java    From 1.13-Command-API with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public LootTable getLootTable(CommandContext cmdCtx, String str) {
    MinecraftKey minecraftKey = ArgumentMinecraftKeyRegistered.c(cmdCtx, str);
    String namespace = minecraftKey.b();
    String key = minecraftKey.getKey();

    net.minecraft.server.v1_13_R2.LootTable lootTable = getCLW(cmdCtx).getServer().getLootTableRegistry().getLootTable(minecraftKey);
    return new CraftLootTable(new NamespacedKey(namespace, key), lootTable);
}
 
Example #22
Source File: NMS_1_13.java    From 1.13-Command-API with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public LootTable getLootTable(CommandContext cmdCtx, String str) {
    MinecraftKey minecraftKey = ArgumentMinecraftKeyRegistered.c(cmdCtx, str);
    String namespace = minecraftKey.b();
    String key = minecraftKey.getKey();

    net.minecraft.server.v1_13_R1.LootTable lootTable = getCLW(cmdCtx).getServer().aP().a(minecraftKey);
    return new CraftLootTable(new NamespacedKey(namespace, key), lootTable);
}
 
Example #23
Source File: TestResearches.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testAddItems() {
    NamespacedKey key = new NamespacedKey(plugin, "addItemsResearch");
    Research research = new Research(key, 17, "Test", 100);
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "RESEARCH_ITEMS_TEST", new CustomItem(Material.LAPIS_LAZULI, "&9Adding items is fun"));
    item.register(plugin);

    research.addItems(item.getItem(), null);

    Assertions.assertTrue(research.getAffectedItems().contains(item));
    Assertions.assertEquals(research, item.getResearch());
}
 
Example #24
Source File: TestResourceRegistration.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testSaltResource() {
    NamespacedKey key = new NamespacedKey(plugin, "salt");
    GEOResource resource = testResource(key, "Salt", SlimefunItems.SALT, true, 18);

    Assertions.assertEquals(0, resource.getDefaultSupply(Environment.NETHER, Biome.NETHER_WASTES));
    Assertions.assertEquals(0, resource.getDefaultSupply(Environment.THE_END, Biome.THE_END));

    Assertions.assertNotEquals(0, resource.getDefaultSupply(Environment.NORMAL, Biome.MOUNTAINS));
    Assertions.assertTrue(resource.getDefaultSupply(Environment.NORMAL, Biome.BEACH) > 10);
    Assertions.assertTrue(resource.getDefaultSupply(Environment.NORMAL, Biome.OCEAN) > 10);
    Assertions.assertTrue(resource.getDefaultSupply(Environment.NORMAL, Biome.SWAMP) > 10);
}
 
Example #25
Source File: MetricsHandler.java    From CraftserveRadiation with Apache License 2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onMetricSubmit(MetricSubmitEvent event) {
    Map<NamespacedKey, Object> data = event.getData();
    data.put(this.key("lugols_iodine_duration"), this.potion.getDuration().getSeconds());
    data.put(this.key("lugols_iodione_affected_count"), (int) this.server.getOnlinePlayers().stream()
            .filter(player -> this.effect.getEffect(player) != null)
            .count());
}
 
Example #26
Source File: ItemService.java    From Transport-Pipes with MIT License 5 votes vote down vote up
public ShapelessRecipe createShapelessRecipe(TransportPipes transportPipes, String recipeKey, ItemStack resultItem, Material... ingredients) {
    ShapelessRecipe recipe = new ShapelessRecipe(new NamespacedKey(transportPipes, recipeKey), resultItem);
    for (int i = 0; i < ingredients.length; i += 2) {
        recipe.addIngredient(ingredients[i]);
    }
    return recipe;
}
 
Example #27
Source File: LugolsIodinePotion.java    From CraftserveRadiation with Apache License 2.0 5 votes vote down vote up
public void enable(RadiationNmsBridge nmsBridge) {
    Objects.requireNonNull(nmsBridge, "nmsBridge");

    this.potionKey = new NamespacedKey(this.plugin, "lugols_iodine");
    this.durationKey = new NamespacedKey(this.plugin, "duration");
    this.durationSecondsKey = new NamespacedKey(this.plugin, "duration_seconds");

    if (this.config.getRecipe().enabled) {
        nmsBridge.registerLugolsIodinePotion(this.potionKey, this.config);
    }
    this.plugin.getServer().getPluginManager().registerEvents(this, this.plugin);
}
 
Example #28
Source File: NMS_1_16_R1.java    From 1.13-Command-API with Apache License 2.0 5 votes vote down vote up
@Override
public FunctionWrapper[] getFunction(CommandContext cmdCtx, String str) throws CommandSyntaxException {
	Collection<CustomFunction> customFuncList = ArgumentTag.a(cmdCtx, str);

	FunctionWrapper[] result = new FunctionWrapper[customFuncList.size()];

	CustomFunctionData customFunctionData = getCLW(cmdCtx).getServer().getFunctionData();
	CommandListenerWrapper commandListenerWrapper = getCLW(cmdCtx).a().b(2);

	int count = 0;

	for (CustomFunction customFunction : customFuncList) {
		@SuppressWarnings("deprecation")
		NamespacedKey minecraftKey = new NamespacedKey(customFunction.a().getNamespace(),
				customFunction.a().getKey());
		ToIntBiFunction<CustomFunction, CommandListenerWrapper> obj = customFunctionData::a;

		FunctionWrapper wrapper = new FunctionWrapper(minecraftKey, obj, customFunction, commandListenerWrapper,
				e -> {
					return (Object) getCLW(cmdCtx).a(((CraftEntity) e).getHandle());
				});

		result[count] = wrapper;
		count++;
	}

	return result;
}
 
Example #29
Source File: VersionUtils_1_15.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void removeRecipeFor(ItemStack item){
    try{
        Method removeRecipe = NMSUtils.getMethod(Bukkit.class, "removeRecipe", NamespacedKey.class);
        boolean removed = (boolean) removeRecipe.invoke(null, item.getType().getKey());
        Validate.isTrue(removed, "Failed to remove recipe.");

        Bukkit.getLogger().info("[UhcCore] Banned item "+JsonItemUtils.getItemJson(item)+" registered");
    }catch (Exception ex){
        Bukkit.getLogger().warning("[UhcCore] Failed to register "+JsonItemUtils.getItemJson(item)+" banned craft, make sure your on 1.15.2+!");
        ex.printStackTrace();
    }
}
 
Example #30
Source File: PersistentDataService.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
default Optional<String> getString(Object obj, NamespacedKey key) {
    if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_14) && obj instanceof PersistentDataHolder) {
        PersistentDataContainer container = ((PersistentDataHolder) obj).getPersistentDataContainer();
        return Optional.ofNullable(container.get(key, PersistentDataType.STRING));
    }

    return Optional.empty();
}