use of com.easterlyn.machine.Machine in project Easterlyn by Easterlyn.
the class EasterlynMachines method loadMachine.
/**
* Loads a machine from the given ConfigurationSection.
*
* @param key the machine's key location or null if it is to be parsed from storage
* @param storage the ConfigurationSection used to store the machine data
* @return a Pair containing the Machine and its corresponding data
* @throws IllegalArgumentException if the provided ConfigurationSection cannot be used to load a
* Machine.
*/
@NotNull
private Pair<Machine, ConfigurationSection> loadMachine(@Nullable Block key, @NotNull ConfigurationSection storage) throws IllegalArgumentException {
if (storage.getCurrentPath() == null) {
throw new IllegalArgumentException("Machine storage must be a ConfigurationSection stored at its location.");
}
if (key == null) {
key = locFromPath(storage.getCurrentPath()).getBlock();
}
if (getConfig().getStringList("+disabled-worlds+").contains(key.getWorld().getName())) {
throw new IllegalArgumentException("Invalid machine at " + storage.getCurrentPath());
}
Machine machine = nameRegistry.get(storage.getString("type"));
if (machine == null) {
throw new IllegalArgumentException("Invalid machine at " + storage.getCurrentPath());
}
for (Block block : machine.getShape().getBuildLocations(key, machine.getDirection(storage)).keySet()) {
blocksToKeys.put(block, key);
keysToBlocks.put(key, block);
}
return new Pair<>(machine, storage);
}
use of com.easterlyn.machine.Machine in project Easterlyn by Easterlyn.
the class EasterlynMachines method registerInventoryEvent.
private <T extends InventoryEvent> void registerInventoryEvent(Class<T> clazz, Function<Machine, BiConsumer<T, ConfigurationSection>> consumer) {
Event.register(clazz, event -> {
Machine machine;
ConfigurationSection section = null;
Pair<Machine, ConfigurationSection> machineData = getInventoryMachine(event.getView().getTopInventory());
if (machineData != null) {
machine = machineData.getLeft();
section = machineData.getRight();
} else if (event.getView().getTopInventory().getHolder() instanceof Machine) {
machine = (Machine) event.getView().getTopInventory().getHolder();
if (event.getView().getTopInventory().getLocation() != null) {
section = getConfig().getConfigurationSection(pathFromLoc(event.getView().getTopInventory().getLocation()));
}
} else {
return;
}
if (machine == null) {
return;
}
try {
consumer.apply(machine).accept(event, section);
} catch (Exception exception) {
ReportableEvent.call("Caught exception handling Machine event", exception, 5);
}
}, this, EventPriority.LOW, true);
}
use of com.easterlyn.machine.Machine in project Easterlyn by Easterlyn.
the class MachineCommand method getMachine.
@CommandAlias("machine")
@Description("Machinations.")
@CommandPermission("easterlyn.command.machine")
@Syntax("<machine>")
@CommandCompletion("@machines")
public void getMachine(@Flags(CoreContexts.SELF) Player player, String machineName) {
Machine machine = plugin.getByName(machineName);
if (machine == null) {
player.sendMessage("Invalid machine type!");
return;
}
player.getWorld().dropItem(player.getLocation(), machine.getUniqueDrop()).setPickupDelay(0);
}
Aggregations