Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Saving gui setting Snippet

Featured Replies

Support enums for those who like using them.

ps. im still fucking around with Loading method.

 

Snippet

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * @author Josedpay
 */
public class Saving {

	public Properties prop = new Properties();
	private File filePath, textPath;
	
	public Saving(String folder, String text)	{
		this.filePath = new File(System.getProperty("user.home") +File.separator +"OSBot" +File.separator +"data" +File.separator +folder);
		this.textPath = new File(System.getProperty("user.home") +File.separator +"OSBot" +File.separator +"data" +File.separator +folder +File.separator  +text +".txt");
	}
		
	public File getTextPath()	{
		return this.textPath;
	}
	
	/**
	 * @return - all necessary folder are made
	 */
	public boolean foldersAreReady()	{
		if (filePath.mkdirs())
			filePath.mkdirs();		
		return !filePath.mkdirs();
	}

	/**
	 * 
	 * @return - the necessary text file
	 * @throws IOException
	 */
	public boolean containsText() throws IOException	{
		if (textPath.createNewFile())
			textPath.createNewFile();
		return !textPath.createNewFile();
	}

	/** Recommended:
	 *  Make void methods that set your gui component, with a argument.
	 *  Also, use the same name as your void methods, the same as the setting Key 
	 *  example: "setExampleComboBox" with out the "()"
	 */
	public void save(String comment, Setting...settings) throws FileNotFoundException, IOException	{
		if (foldersAreReady())	{
			if (containsText())	{
				prop.load(new FileInputStream(this.textPath));
				
				for (Setting setting: settings)	{
					if (setting != null)
						prop.put(setting.getKey(), setting.getValue());
				}
				
				prop.store(new FileOutputStream(this.textPath), (comment != null ? comment: ""));				
			}
		}
	}
		
	/**
	 * A Simple Map class
	 */
	public static class Setting	{
		private Object key, value;

		public Setting(Object key, Object value)	{
			this.key = key;
			this.value = value;
		}
		
		public Object getKey()	{
			return this.key;
		}
		
		public Object getValue()	{
			return this.value;
		}
	}	
}

  
Picture example: (my construction )
87612babef.png
 
Results:

#my new gui setting
#Tue Jul 08 16:45:53 EDT 2014
setToHouse=RUNES
setConStaff=LAVA_BATTLESTAFF
setToBank=EDGEVILLE_1_GLORY
setNail=NONE
setServant=DEMON_BUTLER
setMouseSpeed=10

Edited by josedpay

Use a Hash Map instead of the class 'setting'. Since that's what it is :)

 

Good job, will be useful for quite some people. 

  • Author

Use a Hash Map instead of the class 'setting'. Since that's what it is smile.png

 

Good job, will be useful for quite some people. 

i could but the struggle to add variables into the map, unless there is an easier way.

 

I created the class because its easier to create a setting class

new Setting("setToBank", toBank().name()),

 

i could but the struggle to add variables into the map, unless there is an easier way.

 

I created the class because its easier to create a setting class

new Setting("setToBank", toBank().name()),

 

I see, hmm true. 

Personally I would create a wrapper class that I could pass my properties file to when loading. This way I can have a generic class which handles all of the logic in the properties file, making it easy for later use.

 

For example this is what I use for saving paths in a x;y;z;x;y;z format:

import org.osbot.rs07.api.map.Position;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

/**
 * Created with IntelliJ IDEA
 * User: Anthony
 * Date: 6/3/2014
 */

public class Path {

	private String name;
	private List<Position> path;

	public Path(Properties properties) {
		this.name = properties.getProperty("name");
		this.path = getPathFromProperties(properties);
	}

	public String getName() {
		return name;
	}

	public List<Position> getPath() {
		return path;
	}

	@Override
	public String toString() {
		return name;
	}

	private List<Position> getPathFromProperties(Properties properties) {
		List<Position> returnPath = new ArrayList<>();
		for (String s : properties.getProperty("path").split(";")) {
			String[] coords = s.split(",");
			returnPath.add(new Position(Integer.parseInt(coords[0]), Integer.parseInt(coords[1]), Integer.parseInt(coords[2])));
		}
		return returnPath;
	}

}
  • Author

Personally I would create a wrapper class that I could pass my properties file to when loading. This way I can have a generic class which handles all of the logic in the properties file, making it easy for later use.

 

For example this is what I use for saving paths in a x;y;z;x;y;z format:

import org.osbot.rs07.api.map.Position;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

/**
 * Created with IntelliJ IDEA
 * User: Anthony
 * Date: 6/3/2014
 */

public class Path {

	private String name;
	private List<Position> path;

	public Path(Properties properties) {
		this.name = properties.getProperty("name");
		this.path = getPathFromProperties(properties);
	}

	public String getName() {
		return name;
	}

	public List<Position> getPath() {
		return path;
	}

	@Override
	public String toString() {
		return name;
	}

	private List<Position> getPathFromProperties(Properties properties) {
		List<Position> returnPath = new ArrayList<>();
		for (String s : properties.getProperty("path").split(";")) {
			String[] coords = s.split(",");
			returnPath.add(new Position(Integer.parseInt(coords[0]), Integer.parseInt(coords[1]), Integer.parseInt(coords[2])));
		}
		return returnPath;
	}

}

I Made my snippet generic, the different between yours and mine would be that my contains a key, your are separated with comas. It would be very difficult for me, because I could save all my setting but when it come to my furniture list I'll be fucked.

And the reason why I created a map class was so people could name there key exactly as there method (Their SETTERS). I look through all decleard method in the GUI class. Looking the identical one. And just like I asked the question before, execute the method using the value key as the argument.

I Made my snippet generic, the different between yours and mine would be that my contains a key, your are separated with comas. It would be very difficult for me, because I could save all my setting but when it come to my furniture list I'll be fucked.

And the reason why I created a map class was so people could name there key exactly as there method (Their SETTERS). I look through all decleard method in the GUI class. Looking the identical one. And just like I asked the question before, execute the method using the value key as the argument.

The Properties Object stores key/value pairs. All I'm saying is creating a wrapper class to grab each value based on it's key could prove to be beneficial :p

  • Author

The Properties Object stores key/value pairs. All I'm saying is creating a wrapper class to grab each value based on it's key could prove to be beneficial :p

But that's what I did in my class

Guest
This topic is now closed to further replies.

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.