Skip to content

Commit

Permalink
add CraftingBlock (replaces Shaped Recipe map stuff), add StackUtils …
Browse files Browse the repository at this point in the history
…back, and you dont need commands
  • Loading branch information
Mooy1 committed Sep 4, 2021
1 parent 94536b5 commit afd89fb
Show file tree
Hide file tree
Showing 37 changed files with 574 additions and 119 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.mooy1</groupId>
<artifactId>InfinityLib</artifactId>
<version>1.0.2</version>
<version>1.1.0</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.Locale;
import java.util.Objects;

import javax.annotation.ParametersAreNonnullByDefault;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
Expand All @@ -24,6 +26,7 @@
*
* @author Mooy1
*/
@ParametersAreNonnullByDefault
public final class AddonCommand extends ParentCommand implements TabExecutor, Listener {

private final String help;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import java.util.List;

import javax.annotation.ParametersAreNonnullByDefault;

import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;

@ParametersAreNonnullByDefault
final class AliasesCommand extends SubCommand {

private final String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import java.util.List;

import javax.annotation.ParametersAreNonnullByDefault;

import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;

@ParametersAreNonnullByDefault
final class HelpCommand extends SubCommand {

private final ParentCommand command;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import java.util.List;
import java.util.Objects;

import javax.annotation.ParametersAreNonnullByDefault;

import org.bukkit.command.CommandSender;

import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.libraries.dough.common.ChatColors;

@ParametersAreNonnullByDefault
final class InfoCommand extends SubCommand {

private final String[] message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import java.util.Locale;
import java.util.function.Predicate;

import javax.annotation.ParametersAreNonnullByDefault;

import org.bukkit.command.CommandSender;

/**
* A command
*
* @author Mooy1
*/
@ParametersAreNonnullByDefault
public abstract class SubCommand {

private final Predicate<CommandSender> permission;
Expand Down

This file was deleted.

3 changes: 3 additions & 0 deletions src/main/java/io/github/mooy1/infinitylib/common/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.function.Consumer;

import javax.annotation.ParametersAreNonnullByDefault;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

Expand All @@ -17,6 +19,7 @@
*
* @author Mooy1
*/
@ParametersAreNonnullByDefault
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class Events implements Listener {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.function.Function;

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

import lombok.RequiredArgsConstructor;

Expand All @@ -28,6 +29,7 @@
* @author Mooy1
*/
@RequiredArgsConstructor
@ParametersAreNonnullByDefault
public final class PersistentType<T, Z> implements PersistentDataType<T, Z> {

public static final PersistentDataType<byte[], ItemStack> ITEM_STACK = new PersistentType<>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.mooy1.infinitylib.common;

import javax.annotation.ParametersAreNonnullByDefault;

import lombok.experimental.UtilityClass;

import org.bukkit.Bukkit;
Expand All @@ -12,6 +14,7 @@
* @author Mooy1
*/
@UtilityClass
@ParametersAreNonnullByDefault
public final class Scheduler {

public static void run(Runnable runnable) {
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/io/github/mooy1/infinitylib/common/StackUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.github.mooy1.infinitylib.common;

import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

import lombok.experimental.UtilityClass;

import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;

import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;

@UtilityClass
@ParametersAreNonnullByDefault
public final class StackUtils {

private static final NamespacedKey ID_KEY = Slimefun.getItemDataService().getKey();

@Nullable
public static String getId(ItemStack item) {
if (item instanceof SlimefunItemStack) {
return ((SlimefunItemStack) item).getItemId();
} else if (item.hasItemMeta()) {
return getId(item.getItemMeta());
} else {
return null;
}
}

@Nullable
public static String getId(ItemMeta meta) {
return meta.getPersistentDataContainer().get(ID_KEY, PersistentDataType.STRING);
}

}

This file was deleted.

20 changes: 4 additions & 16 deletions src/main/java/io/github/mooy1/infinitylib/core/AbstractAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.logging.Logger;

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

import org.bukkit.NamespacedKey;
import org.bukkit.command.PluginCommand;
Expand All @@ -25,6 +26,7 @@
*
* @author Mooy1
*/
@ParametersAreNonnullByDefault
public abstract class AbstractAddon extends JavaPlugin implements SlimefunAddon {

private static AbstractAddon instance;
Expand Down Expand Up @@ -178,10 +180,7 @@ else if (config.getBoolean(autoUpdateKey)) {

// Get plugin command
PluginCommand pluginCommand = getCommand(getName());
if (pluginCommand == null) {
handle(new IllegalStateException("Command named '" + getName() + "' missing from plugin.yml!"));
}
else {
if (pluginCommand != null) {
command = new AddonCommand(pluginCommand);
}

Expand Down Expand Up @@ -257,7 +256,7 @@ protected void load() {
*/
@Nonnull
protected final AddonCommand getAddonCommand() {
return instance().command;
return Objects.requireNonNull(instance().command, "Command '" + getName() + "' missing from plugin.yml!");
}

/**
Expand Down Expand Up @@ -300,17 +299,6 @@ public final void saveDefaultConfig() {
// Do nothing, it's covered in onEnable()
}

@Nonnull
@Override
public final String getPluginVersion() {
return getDescription().getVersion();
}

@Override
public final boolean hasDependency(String dependency) {
return SlimefunAddon.super.hasDependency(dependency);
}

@Nonnull
@SuppressWarnings("unchecked")
public static <T extends AbstractAddon> T instance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

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

import org.apache.commons.lang.StringUtils;
import org.bukkit.configuration.file.YamlConfiguration;
Expand All @@ -20,6 +21,7 @@
*
* @author Mooy1
*/
@ParametersAreNonnullByDefault
public final class AddonConfig extends YamlConfiguration {

private final YamlConfiguration defaults = new YamlConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Nonnull;

final class PathBuilder {

List<String> path = new ArrayList<>();

@Nonnull
PathBuilder append(@Nonnull String line) {
PathBuilder append(String line) {
// count indent
int indent = 0;
for (char c : line.toCharArray()) {
Expand Down Expand Up @@ -47,7 +44,6 @@ boolean inMainSection() {
return path.size() == 1;
}

@Nonnull
String build() {
StringBuilder builder = new StringBuilder();
if (path.size() > 0) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.Arrays;
import java.util.Comparator;

import javax.annotation.ParametersAreNonnullByDefault;

import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
Expand All @@ -27,6 +29,7 @@
* @author Mooy1
*/
// TODO check if it works in cheat mode
@ParametersAreNonnullByDefault
public final class MultiGroup extends FlexItemGroup {

private final ItemGroup[] subGroups;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.mooy1.infinitylib.groups;

import javax.annotation.ParametersAreNonnullByDefault;

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

Expand All @@ -11,6 +13,7 @@
*
* @author Mooy1
*/
@ParametersAreNonnullByDefault
public final class SubGroup extends ItemGroup {

public SubGroup(String key, ItemStack item) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,18 @@
import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNetComponentType;
import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;

@Setter
@ParametersAreNonnullByDefault
public abstract class AbstractMachineBlock extends TickingMenuBlock implements EnergyNetComponent {

protected static final ItemStack PROCESSING_ITEM = new CustomItemStack(Material.LIME_STAINED_GLASS_PANE, "&aProcessing...");
protected static final ItemStack NO_ENERGY_ITEM = new CustomItemStack(Material.RED_STAINED_GLASS_PANE, "&cNot enough energy!");
protected static final ItemStack NO_ROOM_ITEM = new CustomItemStack(Material.ORANGE_STAINED_GLASS_PANE, "&6Not enough room!");
protected static final ItemStack OUTPUT_BORDER = new CustomItemStack(ChestMenuUtils.getOutputSlotTexture(), "&6Output");
protected static final ItemStack INPUT_BORDER = new CustomItemStack(ChestMenuUtils.getInputSlotTexture(), "&9Input");
protected static final ItemStack IDLE_ITEM = new CustomItemStack(Material.BLACK_STAINED_GLASS_PANE, "&8Idle");
protected static final ChestMenu.MenuClickHandler EMPTY_CLICK_HANDLER = ChestMenuUtils.getEmptyClickHandler();
protected static final ItemStack BACKGROUND_ITEM = ChestMenuUtils.getBackground();
public static final ItemStack PROCESSING_ITEM = new CustomItemStack(Material.LIME_STAINED_GLASS_PANE, "&aProcessing...");
public static final ItemStack NO_ENERGY_ITEM = new CustomItemStack(Material.RED_STAINED_GLASS_PANE, "&cNot enough energy!");
public static final ItemStack IDLE_ITEM = new CustomItemStack(Material.BLACK_STAINED_GLASS_PANE, "&8Idle");

protected MachineLayout layout;
protected MachineLayout layout = MachineLayout.MACHINE_DEFAULT;
protected int energyPerTick = -1;
protected int energyCapacity = -1;

Expand All @@ -60,7 +54,7 @@ protected void setup(BlockMenuPreset preset) {
preset.drawBackground(OUTPUT_BORDER, layout.outputBorder());
preset.drawBackground(INPUT_BORDER, layout.inputBorder());
preset.drawBackground(BACKGROUND_ITEM, layout.background());
preset.addItem(layout.statusSlot(), IDLE_ITEM, EMPTY_CLICK_HANDLER);
preset.addItem(layout.statusSlot(), IDLE_ITEM, ChestMenuUtils.getEmptyClickHandler());
}

@Override
Expand Down Expand Up @@ -92,9 +86,6 @@ public final void register(@Nonnull SlimefunAddon addon) {
if (energyCapacity == -1) {
energyCapacity = energyPerTick * 2;
}
if (layout == null) {
layout = MachineLayout.DEFAULT;
}
super.register(addon);
}

Expand Down
Loading

0 comments on commit afd89fb

Please sign in to comment.