mirror of
https://github.com/SKCraft/Launcher.git
synced 2025-01-06 19:18:27 +01:00
Add creator tools dialog for enabling plugins
This commit is contained in:
parent
638c9d9fb5
commit
7aacb4ec01
@ -15,7 +15,7 @@ import com.skcraft.launcher.creator.model.creator.CreatorConfig;
|
|||||||
import com.skcraft.launcher.creator.model.creator.RecentEntry;
|
import com.skcraft.launcher.creator.model.creator.RecentEntry;
|
||||||
import com.skcraft.launcher.creator.model.creator.Workspace;
|
import com.skcraft.launcher.creator.model.creator.Workspace;
|
||||||
import com.skcraft.launcher.creator.plugin.CreatorPluginLoader;
|
import com.skcraft.launcher.creator.plugin.CreatorPluginLoader;
|
||||||
import com.skcraft.launcher.creator.plugin.CreatorToolsPlugin;
|
import com.skcraft.launcher.creator.plugin.CreatorPluginWrapper;
|
||||||
import com.skcraft.launcher.persistence.Persistence;
|
import com.skcraft.launcher.persistence.Persistence;
|
||||||
import com.skcraft.launcher.swing.SwingHelper;
|
import com.skcraft.launcher.swing.SwingHelper;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@ -35,7 +35,7 @@ public class Creator {
|
|||||||
@Getter private final File dataDir;
|
@Getter private final File dataDir;
|
||||||
@Getter private final CreatorConfig config;
|
@Getter private final CreatorConfig config;
|
||||||
@Getter private final ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
|
@Getter private final ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
|
||||||
@Getter private final List<CreatorToolsPlugin> plugins;
|
@Getter private final List<CreatorPluginWrapper<?>> plugins;
|
||||||
|
|
||||||
public Creator() {
|
public Creator() {
|
||||||
this.dataDir = getAppDataDir();
|
this.dataDir = getAppDataDir();
|
||||||
|
@ -463,6 +463,15 @@ public class PackManagerController {
|
|||||||
selectedPack.ifPresent(pack -> SwingHelper.browseDir(pack.getDirectory(), frame));
|
selectedPack.ifPresent(pack -> SwingHelper.browseDir(pack.getDirectory(), frame));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
frame.getEditPluginsMenuItem().addActionListener(e -> {
|
||||||
|
Optional<Pack> optional = getSelectedPack(true);
|
||||||
|
|
||||||
|
if (optional.isPresent()) {
|
||||||
|
PluginSelectionDialog.showPluginDialog(frame, creator, optional.get());
|
||||||
|
updatePackInWorkspace(optional.get());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
frame.getCheckProblemsMenuItem().addActionListener(e -> {
|
frame.getCheckProblemsMenuItem().addActionListener(e -> {
|
||||||
Optional<Pack> optional = getSelectedPack(true);
|
Optional<Pack> optional = getSelectedPack(true);
|
||||||
|
|
||||||
@ -654,6 +663,10 @@ public class PackManagerController {
|
|||||||
menuItem.addActionListener(e -> frame.getOpenFolderMenuItem().doClick());
|
menuItem.addActionListener(e -> frame.getOpenFolderMenuItem().doClick());
|
||||||
popup.add(menuItem);
|
popup.add(menuItem);
|
||||||
|
|
||||||
|
menuItem = new JMenuItem("Enabled Plugins...");
|
||||||
|
menuItem.addActionListener(e -> frame.getEditPluginsMenuItem().doClick());
|
||||||
|
popup.add(menuItem);
|
||||||
|
|
||||||
menuItem = new JMenuItem("Check for Problems");
|
menuItem = new JMenuItem("Check for Problems");
|
||||||
menuItem.addActionListener(e -> frame.getCheckProblemsMenuItem().doClick());
|
menuItem.addActionListener(e -> frame.getCheckProblemsMenuItem().doClick());
|
||||||
popup.add(menuItem);
|
popup.add(menuItem);
|
||||||
@ -711,6 +724,10 @@ public class PackManagerController {
|
|||||||
}
|
}
|
||||||
} while (!canAddPackDir(dir));
|
} while (!canAddPackDir(dir));
|
||||||
|
|
||||||
|
if (!creator.getPlugins().isEmpty()) {
|
||||||
|
PluginSelectionDialog.showPluginDialog(frame, creator, pack);
|
||||||
|
}
|
||||||
|
|
||||||
pack.setLocation(dir.getAbsolutePath());
|
pack.setLocation(dir.getAbsolutePath());
|
||||||
|
|
||||||
if (pack.getConfigFile().exists()) {
|
if (pack.getConfigFile().exists()) {
|
||||||
|
@ -13,6 +13,7 @@ import com.skcraft.launcher.LauncherUtils;
|
|||||||
import com.skcraft.launcher.builder.PackageBuilder;
|
import com.skcraft.launcher.builder.PackageBuilder;
|
||||||
import com.skcraft.launcher.creator.Creator;
|
import com.skcraft.launcher.creator.Creator;
|
||||||
import com.skcraft.launcher.creator.model.creator.Pack;
|
import com.skcraft.launcher.creator.model.creator.Pack;
|
||||||
|
import com.skcraft.launcher.creator.plugin.CreatorPluginWrapper;
|
||||||
import com.skcraft.launcher.creator.plugin.CreatorToolsPlugin;
|
import com.skcraft.launcher.creator.plugin.CreatorToolsPlugin;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
@ -61,7 +62,12 @@ public class PackBuilder implements Callable<PackBuilder>, ProgressObservable {
|
|||||||
"-o", outputDir.getAbsolutePath()
|
"-o", outputDir.getAbsolutePath()
|
||||||
);
|
);
|
||||||
|
|
||||||
for (CreatorToolsPlugin plugin : creator.getPlugins()) {
|
for (CreatorPluginWrapper<?> wrapper : creator.getPlugins()) {
|
||||||
|
if (!pack.getEnabledPlugins().contains(wrapper.getInfo().getId())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
CreatorToolsPlugin plugin = wrapper.getInstance();
|
||||||
if (plugin.getBuilderPlugin() != null) {
|
if (plugin.getBuilderPlugin() != null) {
|
||||||
args.add("--plugin-class");
|
args.add("--plugin-class");
|
||||||
args.add(plugin.getBuilderPlugin().getCanonicalName());
|
args.add(plugin.getBuilderPlugin().getCanonicalName());
|
||||||
|
@ -39,6 +39,7 @@ public class PackManagerFrame extends JFrame {
|
|||||||
@Getter private final JMenuItem quitMenuItem = new JMenuItem("Exit");
|
@Getter private final JMenuItem quitMenuItem = new JMenuItem("Exit");
|
||||||
@Getter private final JMenuItem editConfigMenuItem = new JMenuItem("Edit modpack.json...");
|
@Getter private final JMenuItem editConfigMenuItem = new JMenuItem("Edit modpack.json...");
|
||||||
@Getter private final JMenuItem openFolderMenuItem = new JMenuItem("Open Directory");
|
@Getter private final JMenuItem openFolderMenuItem = new JMenuItem("Open Directory");
|
||||||
|
@Getter private final JMenuItem editPluginsMenuItem = new JMenuItem("Enabled Plugins...");
|
||||||
@Getter private final JMenuItem checkProblemsMenuItem = new JMenuItem("Scan for Problems...");
|
@Getter private final JMenuItem checkProblemsMenuItem = new JMenuItem("Scan for Problems...");
|
||||||
@Getter private final JMenuItem testMenuItem = new JMenuItem("Test");
|
@Getter private final JMenuItem testMenuItem = new JMenuItem("Test");
|
||||||
@Getter private final JMenuItem testOnlineMenuItem = new JMenuItem("Test Online");
|
@Getter private final JMenuItem testOnlineMenuItem = new JMenuItem("Test Online");
|
||||||
@ -153,6 +154,7 @@ public class PackManagerFrame extends JFrame {
|
|||||||
menuBar.add(menu);
|
menuBar.add(menu);
|
||||||
menu.add(editConfigMenuItem);
|
menu.add(editConfigMenuItem);
|
||||||
menu.add(openFolderMenuItem);
|
menu.add(openFolderMenuItem);
|
||||||
|
menu.add(editPluginsMenuItem);
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
menu.add(checkProblemsMenuItem);
|
menu.add(checkProblemsMenuItem);
|
||||||
|
|
||||||
|
@ -0,0 +1,72 @@
|
|||||||
|
package com.skcraft.launcher.creator.dialog;
|
||||||
|
|
||||||
|
import com.skcraft.launcher.creator.Creator;
|
||||||
|
import com.skcraft.launcher.creator.model.creator.Pack;
|
||||||
|
import com.skcraft.launcher.creator.model.swing.PluginsTableModel;
|
||||||
|
import com.skcraft.launcher.swing.CheckboxTable;
|
||||||
|
import com.skcraft.launcher.swing.LinedBoxPanel;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class PluginSelectionDialog extends JDialog {
|
||||||
|
private final LinedBoxPanel panel = new LinedBoxPanel(false).fullyPadded();
|
||||||
|
private final JLabel title = new JLabel("Select which plugins to use while building this pack.");
|
||||||
|
private final CheckboxTable pluginsTable = new CheckboxTable();
|
||||||
|
private final LinedBoxPanel buttonsPanel = new LinedBoxPanel(true);
|
||||||
|
private final JButton okButton = new JButton("OK");
|
||||||
|
|
||||||
|
private List<PluginsTableModel.PluginModel> plugins;
|
||||||
|
|
||||||
|
public PluginSelectionDialog(Window owner, Creator creator, Pack pack) {
|
||||||
|
super(owner, "Enable Plugins", ModalityType.DOCUMENT_MODAL);
|
||||||
|
|
||||||
|
this.plugins = creator.getPlugins().stream()
|
||||||
|
.map(wrapper -> {
|
||||||
|
PluginsTableModel.PluginModel model = new PluginsTableModel.PluginModel(wrapper.getInfo().getId());
|
||||||
|
model.setEnabled(pack.getEnabledPlugins().contains(model.getPluginId()));
|
||||||
|
return model;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
setTitle("Select plugins to enable");
|
||||||
|
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||||
|
initComponents();
|
||||||
|
setPreferredSize(new Dimension(400, 320));
|
||||||
|
pack();
|
||||||
|
setLocationRelativeTo(owner);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initComponents() {
|
||||||
|
pluginsTable.setModel(new PluginsTableModel(plugins));
|
||||||
|
pluginsTable.setRowSelectionAllowed(false);
|
||||||
|
|
||||||
|
okButton.setMargin(new Insets(0, 10, 0, 10));
|
||||||
|
|
||||||
|
buttonsPanel.addGlue();
|
||||||
|
buttonsPanel.addElement(okButton);
|
||||||
|
|
||||||
|
panel.addElement(title);
|
||||||
|
panel.addElement(pluginsTable);
|
||||||
|
panel.addElement(buttonsPanel);
|
||||||
|
|
||||||
|
add(panel);
|
||||||
|
|
||||||
|
okButton.addActionListener(e -> PluginSelectionDialog.this.dispose());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showPluginDialog(Window owner, Creator creator, Pack pack) {
|
||||||
|
PluginSelectionDialog dialog = new PluginSelectionDialog(owner, creator, pack);
|
||||||
|
dialog.setVisible(true);
|
||||||
|
|
||||||
|
Set<String> enabled = dialog.plugins.stream()
|
||||||
|
.filter(PluginsTableModel.PluginModel::isEnabled)
|
||||||
|
.map(PluginsTableModel.PluginModel::getPluginId)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
pack.setEnabledPlugins(enabled);
|
||||||
|
}
|
||||||
|
}
|
@ -13,11 +13,14 @@ import com.skcraft.launcher.persistence.Persistence;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class Pack {
|
public class Pack {
|
||||||
|
|
||||||
private String location;
|
private String location;
|
||||||
|
private Set<String> enabledPlugins = new HashSet<>();
|
||||||
@JsonIgnore private Workspace workspace;
|
@JsonIgnore private Workspace workspace;
|
||||||
@JsonIgnore private BuilderConfig cachedConfig;
|
@JsonIgnore private BuilderConfig cachedConfig;
|
||||||
|
|
||||||
|
@ -0,0 +1,70 @@
|
|||||||
|
package com.skcraft.launcher.creator.model.swing;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
import javax.swing.table.AbstractTableModel;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class PluginsTableModel extends AbstractTableModel {
|
||||||
|
private final List<PluginModel> plugins;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRowCount() {
|
||||||
|
return plugins.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getColumnCount() {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||||
|
if (columnIndex == 0) {
|
||||||
|
return plugins.get(rowIndex).isEnabled();
|
||||||
|
} else {
|
||||||
|
return plugins.get(rowIndex).getPluginId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getColumnName(int column) {
|
||||||
|
if (column == 1) {
|
||||||
|
return "Plugin";
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<?> getColumnClass(int columnIndex) {
|
||||||
|
switch (columnIndex) {
|
||||||
|
case 0:
|
||||||
|
return Boolean.class;
|
||||||
|
case 1:
|
||||||
|
return String.class;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCellEditable(int rowIndex, int columnIndex) {
|
||||||
|
return columnIndex == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
|
||||||
|
if (columnIndex == 0) {
|
||||||
|
plugins.get(rowIndex).setEnabled((Boolean) aValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class PluginModel {
|
||||||
|
private final String pluginId;
|
||||||
|
private boolean enabled;
|
||||||
|
}
|
||||||
|
}
|
@ -39,7 +39,7 @@ public class CreatorPluginLoader extends DirectoryWalker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CreatorToolsPlugin> loadAll() {
|
public List<CreatorPluginWrapper<?>> loadAll() {
|
||||||
URLClassLoader pluginClassLoader = new URLClassLoader(
|
URLClassLoader pluginClassLoader = new URLClassLoader(
|
||||||
candidates.stream().map(PluginCandidate::getJarUrl).toArray(URL[]::new),
|
candidates.stream().map(PluginCandidate::getJarUrl).toArray(URL[]::new),
|
||||||
this.getClass().getClassLoader()
|
this.getClass().getClassLoader()
|
||||||
@ -53,11 +53,12 @@ public class CreatorPluginLoader extends DirectoryWalker {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends CreatorToolsPlugin> CreatorToolsPlugin loadPlugin(URLClassLoader classLoader, PluginCandidate candidate) {
|
private <T extends CreatorToolsPlugin> CreatorPluginWrapper<T> loadPlugin(URLClassLoader classLoader, PluginCandidate candidate) {
|
||||||
try {
|
try {
|
||||||
Class<T> pluginClass = (Class<T>) classLoader.loadClass(candidate.getInfo().getPluginClass());
|
Class<T> pluginClass = (Class<T>) classLoader.loadClass(candidate.getInfo().getPluginClass());
|
||||||
|
|
||||||
return pluginClass.getConstructor().newInstance();
|
T instance = pluginClass.getConstructor().newInstance();
|
||||||
|
return new CreatorPluginWrapper<>(candidate.getInfo(), instance);
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
log.warning(candidate.format("Could not find plugin class %s for plugin %s"));
|
log.warning(candidate.format("Could not find plugin class %s for plugin %s"));
|
||||||
} catch (ClassCastException e) {
|
} catch (ClassCastException e) {
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.skcraft.launcher.creator.plugin;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CreatorPluginWrapper<T extends CreatorToolsPlugin> {
|
||||||
|
private final CreatorPluginInfo info;
|
||||||
|
private final T instance;
|
||||||
|
}
|
@ -419,8 +419,10 @@ public class PackageBuilder implements Builder {
|
|||||||
|
|
||||||
// Load plugins
|
// Load plugins
|
||||||
BuilderPluginLoader pluginLoader = new BuilderPluginLoader();
|
BuilderPluginLoader pluginLoader = new BuilderPluginLoader();
|
||||||
pluginLoader.loadClasses(options.getPluginClasses());
|
if (options.getPluginClasses() != null) {
|
||||||
pluginLoader.dispatchAcceptOptions(options, args);
|
pluginLoader.loadClasses(options.getPluginClasses());
|
||||||
|
pluginLoader.dispatchAcceptOptions(options, args);
|
||||||
|
}
|
||||||
|
|
||||||
Manifest manifest = new Manifest();
|
Manifest manifest = new Manifest();
|
||||||
manifest.setMinimumVersion(Manifest.MIN_PROTOCOL_VERSION);
|
manifest.setMinimumVersion(Manifest.MIN_PROTOCOL_VERSION);
|
||||||
|
Loading…
Reference in New Issue
Block a user