Skip to content

Commit

Permalink
Added SPC toggle option and a workaround for a JComboBox bug.
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Iverson <[email protected]>
  • Loading branch information
iversc committed Apr 22, 2012
1 parent 652d292 commit 15e106f
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 12 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
===============================================================
Version 1.7 -
===============================================================

Added a toggle to enable/disable in-game single player commands, added in the 12w16a preview.

Added a workaround for an issue with JComboBox and duplicate item names(in this case, duplicate world names)

===============================================================
Version 1.6.2 -
===============================================================
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
This software and it's source are distributed under the terms of the Modified BSD License, detailed below.

Copyright (c) 2011, Christopher Iverson
Copyright (c) 2011-2012, Christopher Iverson
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
Binary file added bin/minecraftSeed/MinecraftSeed$1.class
Binary file not shown.
Binary file modified bin/minecraftSeed/MinecraftSeed.class
Binary file not shown.
Binary file modified builds/latest/MinecraftSeed.jar
Binary file not shown.
Binary file added builds/version-1.7/MinecraftSeed.jar
Binary file not shown.
56 changes: 46 additions & 10 deletions src/minecraftSeed/MinecraftSeed.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This software and it's source are distributed under the terms of the Modified BSD License, detailed below.
Copyright (c) 2011, Christopher Iverson
Copyright (c) 2011-2012, Christopher Iverson
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -54,19 +54,21 @@ public class MinecraftSeed implements ActionListener {
private String[] filePaths;
private String lastFolder;
private int validNames;
private JComboBox<String> combo;
private JComboBox<Object> combo;
private JCheckBox cbCreative;
private boolean creativeEnabled;
private boolean hardcoreEnabled;
private boolean commandsEnabled;
private boolean abilitiesExist; //To control tags added in Beta 1.9 PR 5.
//If these tags are not changed properly, Creative mode
//abilities can be enabled in Survival mode.

private JButton btnSave;
private String selectedFilePath;

private final String version = "1.6.2";
private final String version = "1.7";
private JCheckBox cbHardcore;
private JCheckBox cbCommands;

public MinecraftSeed()
{
Expand Down Expand Up @@ -109,7 +111,7 @@ public MinecraftSeed()

panel = new JPanel();

combo = new JComboBox<String>();
combo = new JComboBox<Object>();
combo.addActionListener(this);

text = new JTextField();
Expand Down Expand Up @@ -139,7 +141,7 @@ public MinecraftSeed()

menuBar.add(helpMenu);
frame.setJMenuBar(menuBar);
panel.setLayout(new MigLayout("", "[28px][166px][95px]", "[23px][][]"));
panel.setLayout(new MigLayout("", "[28px][166px,grow][95px]", "[23px][][][]"));

panel.add(combo, "cell 0 0,alignx left,aligny center");
panel.add(text, "cell 1 0 2 1,growx");
Expand All @@ -149,19 +151,25 @@ public MinecraftSeed()
cbCreative.setEnabled(false);
cbCreative.setActionCommand("creativetoggle");
cbCreative.addActionListener(this);
panel.add(cbCreative, "flowx,cell 1 1,alignx left,aligny top");

cbHardcore = new JCheckBox("Hardcore Mode");
cbHardcore.setEnabled(false);
cbHardcore.setActionCommand("hardcoretoggle");
cbHardcore.addActionListener(this);
panel.add(cbHardcore, "cell 1 2");
panel.add(cbHardcore, "cell 1 1");
panel.add(cbCreative, "flowx,cell 2 1,alignx left,aligny top");

btnSave = new JButton("Save Changes");
btnSave.setEnabled(false);
btnSave.setActionCommand("save");
btnSave.addActionListener(this);
panel.add(btnSave, "cell 2 2");

cbCommands = new JCheckBox("Enable Commands");
cbCommands.setEnabled(false);
cbCommands.setActionCommand("commandstoggle");
cbCommands.addActionListener(this);
panel.add(cbCommands, "cell 1 2");
panel.add(btnSave, "cell 2 3");

//Try to load the save data
setupData();
Expand Down Expand Up @@ -240,9 +248,9 @@ private void setupData()
//go by the folder's name
Tag name = main.findTagByName("LevelName");
if(name == null) {
combo.addItem(file.getParentFile().getName());
combo.addItem(makeObj(file.getParentFile().getName()));
} else {
combo.addItem((String)name.getValue());
combo.addItem(makeObj((String)name.getValue()));
}

} catch (FileNotFoundException e) {
Expand Down Expand Up @@ -365,6 +373,19 @@ public void actionPerformed(ActionEvent arg0) {
cbHardcore.setSelected(hardcoreEnabled);
}

Tag commands = main.findTagByName("allowCommands");
if(commands==null)
{
cbCommands.setEnabled(false);
cbCommands.setSelected(false);
}
else
{
cbCommands.setEnabled(true);

commandsEnabled = ((Byte)commands.getValue() == 1);
cbCommands.setSelected(commandsEnabled);
}
//The reason "Player" is also used here is to make sure we find the correct tag.
Tag abilities = main.findTagByName("Player").findTagByName("abilities");

Expand Down Expand Up @@ -459,6 +480,16 @@ public void actionPerformed(ActionEvent arg0) {
btnSave.setEnabled(true);
}

if(cmd.equals("commandstoggle"))
{
commandsEnabled = !commandsEnabled;

Tag commands = main.findTagByName("allowCommands");
commands.setValue((byte)(commandsEnabled? 1 : 0));

btnSave.setEnabled(true);
}

//Save button pressed
if(cmd.equals("save"))
{
Expand Down Expand Up @@ -487,5 +518,10 @@ public void actionPerformed(ActionEvent arg0) {
} // else

} //actionPerformed

private Object makeObj(final String item) {
return new Object() { public String toString() { return item; } };
}


}
2 changes: 1 addition & 1 deletion src/minecraftSeed/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* NBT IO class
*
* @see <a href="http://www.minecraft.net/docs/NBT.txt">Online NBT specification</a>
* @see <a href="https://github.com/udoprog/c10t/blob/master/docs/NBT.txt">Online NBT specification</a>
*/
public class Tag {
private final Type type;
Expand Down

0 comments on commit 15e106f

Please sign in to comment.