Skip to content
This repository has been archived by the owner on Jan 7, 2022. It is now read-only.

Commit

Permalink
0.1.0: Full Release
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBrokenRail committed Jun 29, 2021
1 parent 519462d commit 9ca08b8
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 213 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog

**0.1.0**
* Full Release
* Replace Proxy With MCPI-Reborn's External Server Support

**0.1.0 (Release Candidate 1)**
- Java Rewrite Proof-Of-Concept
* Java Rewrite Proof-Of-Concept
Binary file modified images/play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 4 additions & 15 deletions src/main/java/com/thebrokenrail/jmcpil/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.thebrokenrail.jmcpil.util.Launcher;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -66,20 +68,7 @@ public static class GeneralSettings {
public GeneralSettings general = new GeneralSettings();

/**
* Multiplayer Settings
* Server List Property
*/
public static class MultiplayerSettings {
/**
* Ip Address
*/
public String ip = "thebrokenrail.com";
/**
* Port
*/
public int port = 19132;
}
/**
* Multiplayer Settings Property
*/
public MultiplayerSettings multiplayer = new MultiplayerSettings();
public List<String> servers = new ArrayList<>(Collections.singletonList("thebrokenrail.com"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static Config getConfig() {
return config;
}

private static final String CONFIG_FILE = System.getenv("HOME") + "/.mcpil.json";
private static final String CONFIG_FILE = System.getenv("HOME") + "/.jmcpil.json";

/**
* Save Config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public class PlayButton extends JButton implements ActionListener {
public void actionPerformed(ActionEvent actionEvent) {
String action = actionEvent.getActionCommand();
if (action.equals("play") && process == null) {
// Save
ConfigHandler.save();

// Start MCPI-Reborn
Config config = ConfigHandler.getConfig();
process = Launcher.run(Profile.getFeatures(Profile.getCurrentProfile()), config.general.renderDistance, config.general.username);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public MainTabs() {
// Add Tabs
addTab("Play", new PlayTab());
addTab("Features", new FeaturesTab());
addTab("Multiplayer", new MultiplayerTab());
addTab("Servers", new ServersTab());
addTab("Settings", new SettingsTab());
addTab("About", new AboutTab());
}
Expand Down
49 changes: 0 additions & 49 deletions src/main/java/com/thebrokenrail/jmcpil/gui/tab/MultiplayerTab.java

This file was deleted.

173 changes: 173 additions & 0 deletions src/main/java/com/thebrokenrail/jmcpil/gui/tab/ServersTab.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
package com.thebrokenrail.jmcpil.gui.tab;

import com.thebrokenrail.jmcpil.config.Config;
import com.thebrokenrail.jmcpil.util.Util;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingConstants;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
* Servers Tab
*/
public class ServersTab extends JPanel implements ActionListener {
/**
* Server List Widget
*/
private final JList<String> list;
/**
* New Server Text Entry Widget
*/
private final JTextField entry;

ServersTab() {
super(new GridBagLayout());

// Create List
list = new JList<>(new DefaultListModel<>());
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setLayoutOrientation(JList.VERTICAL);
list.setVisibleRowCount(-1);

// Configure Config
Config.addHandler("save", config -> {
config.servers.clear();
for (int i = 0; i < list.getModel().getSize(); i++) {
config.servers.add(list.getModel().getElementAt(i));
}
});
Config.addHandler("load", config -> {
// Sanitize
List<String> newServers = new ArrayList<>();
for (String server : config.servers) {
if (server.length() > 0) {
newServers.add(server.replaceAll("\n", " ").replaceAll("\r", ""));
}
}
config.servers = newServers;
// Add
DefaultListModel<String> model = new DefaultListModel<>();
model.addAll(config.servers);
list.setModel(model);
});
Config.addHandler("apply", config -> {
try {
File serverList = new File(System.getenv("HOME"), ".minecraft-pi/servers.txt");
//noinspection ResultOfMethodCallIgnored
serverList.getParentFile().mkdirs();
//noinspection ResultOfMethodCallIgnored
serverList.createNewFile();
FileWriter writer = new FileWriter(serverList, false);
writer.write("# Managed By jMCPIL\n");
for (String server : config.servers) {
writer.write(server + '\n');
}
writer.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
});

// Add List
JScrollPane scrollingList = new JScrollPane(list);
scrollingList.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
JPanel wrappedList = Util.wrap(scrollingList);
GridBagConstraints layoutRestrictions = new GridBagConstraints();
layoutRestrictions.gridx = 0;
layoutRestrictions.gridy = 0;
layoutRestrictions.gridwidth = 4;
layoutRestrictions.weightx = 1;
layoutRestrictions.weighty = 1;
layoutRestrictions.fill = GridBagConstraints.BOTH;
Util.addPadding(wrappedList, 8, 0, 8, 8);
add(wrappedList, layoutRestrictions);

// Add Delete Button
JButton delete = new JButton("Delete");
delete.setActionCommand("delete");
delete.addActionListener(this);
// Wrap
JPanel wrappedDelete = Util.wrap(delete);
layoutRestrictions = new GridBagConstraints();
layoutRestrictions.gridx = 0;
layoutRestrictions.gridy = 1;
Util.addPadding(wrappedDelete, 8);
add(wrappedDelete, layoutRestrictions);

// Add Separator
JSeparator separator = new JSeparator(SwingConstants.VERTICAL);
// Wrap
JPanel wrappedSeparator = Util.wrap(separator);
layoutRestrictions = new GridBagConstraints();
layoutRestrictions.gridx = 1;
layoutRestrictions.gridy = 1;
layoutRestrictions.fill = GridBagConstraints.VERTICAL;
Util.addPadding(wrappedSeparator, 0, 8);
add(wrappedSeparator, layoutRestrictions);

// Add New Server Entry
entry = new JTextField();
entry.setActionCommand("add");
entry.addActionListener(this);
// Wrap
JPanel wrappedEntry = Util.wrap(entry);
layoutRestrictions = new GridBagConstraints();
layoutRestrictions.gridx = 2;
layoutRestrictions.gridy = 1;
layoutRestrictions.weightx = 1;
layoutRestrictions.fill = GridBagConstraints.HORIZONTAL;
Util.addPadding(wrappedEntry, 8);
add(wrappedEntry, layoutRestrictions);

// Add New Server Button
JButton add = new JButton("Add");
add.setActionCommand("add");
add.addActionListener(this);
// Wrap
JPanel wrappedAdd = Util.wrap(add);
layoutRestrictions = new GridBagConstraints();
layoutRestrictions.gridx = 3;
layoutRestrictions.gridy = 1;
Util.addPadding(wrappedAdd, 8, 8, 0, 8);
add(wrappedAdd, layoutRestrictions);
}

/**
* Handle Button Press
* @param actionEvent Action To Handle
*/
@Override
public void actionPerformed(ActionEvent actionEvent) {
String action = actionEvent.getActionCommand();
if (action.equals("delete")) {
// Delete Selected Server
int index = list.getSelectedIndex();
if (index != -1) {
((DefaultListModel<String>) list.getModel()).remove(index);
}
} else if (action.equals("add")) {
// Add New Server
String newServer = entry.getText();
entry.setText("");
if (newServer.length() > 0) {
((DefaultListModel<String>) list.getModel()).addElement(newServer);
}
}
}
}
27 changes: 0 additions & 27 deletions src/main/java/com/thebrokenrail/jmcpil/proxy/GlobalProxy.java

This file was deleted.

Loading

0 comments on commit 9ca08b8

Please sign in to comment.