Ok, what i am trying to do is make a bukkit plugin for minecraft. I have got it working so it saves the co ords of a player in a .txt file but i now need to read that file for the x, y, and z co ords.
The text file looks like
X: -64.0
Y: 89.0
Z: 247.0
My code for the main class and writing class is:
And now the code for the write/reader:
What shall i do to make it read the .txt file and give me the x, y and z cords to teleport a player to them.
Thanks in advance.
The text file looks like
X: -64.0
Y: 89.0
Z: 247.0
My code for the main class and writing class is:
package me.kyle.detruxdrop;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.logging.Logger;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
@SuppressWarnings("unused")
public class DetruxDrop extends JavaPlugin{
public static DetruxDrop plugin;
public ListStore drops;
protected DetruxDropLogger log;
@Override
public void onDisable() {
getServer().getPluginManager().removePermission(new Permissions().perm);
getServer().getPluginManager().removePermission(new Permissions().adminperm);
this.drops.save();
}
@Override
public void onEnable() {
this.log = new DetruxDropLogger(this);
PluginManager pm = this.getServer().getPluginManager();
pm.addPermission(new Permissions().perm);
pm.addPermission(new Permissions().adminperm);
String pluginFolder = this.getDataFolder().getAbsolutePath();
(new File (pluginFolder)).mkdirs();
this.drops = new ListStore(new File(pluginFolder + File.separator + "drops.txt"));
this.drops.load();
}
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
Player player = (Player) sender;
if(commandLabel.equalsIgnoreCase("drop")) {
if(args.length == 0 && sender.hasPermission(new Permissions().perm) && ! sender.hasPermission(new Permissions().adminperm)) {
player.sendMessage(ChatColor.GREEN + " DetruxCraft Drop Party.");
player.sendMessage(ChatColor.GOLD + "Usage");
player.sendMessage(ChatColor.GOLD + "/drop -" + ChatColor.GREEN + " Displays this help dialog.");
player.sendMessage(ChatColor.GOLD + "/drop join -" + ChatColor.GREEN + " Join's the drop party.");
player.sendMessage(ChatColor.GOLD + "/drop leave -" + ChatColor.GREEN + " Leave's the current drop party.");
player.sendMessage(ChatColor.GOLD + "/drop info -" + ChatColor.GREEN + " Displays the plugin information");
}
if(args.length == 0 && sender.hasPermission(new Permissions().adminperm)){
player.sendMessage(ChatColor.GREEN + " DetruxCraft Drop Party.");
player.sendMessage(ChatColor.GOLD + "Usage");
player.sendMessage(ChatColor.GOLD + "/drop -" + ChatColor.GREEN + "Displays this help dialog.");
player.sendMessage(ChatColor.GOLD + "/drop join -" + ChatColor.GREEN + " Join's the drop party.");
player.sendMessage(ChatColor.GOLD + "/drop leave -" + ChatColor.GREEN + " Leave's the current drop party.");
player.sendMessage(ChatColor.GOLD + "/drop info -" + ChatColor.GREEN + " Displays the plugin information");
player.sendMessage(ChatColor.AQUA + "/drop set -" + ChatColor.BLUE + " Set's where the drop is.");
}
if (args.length == 1){
if(args[0].equalsIgnoreCase("set") && player.hasPermission(new Permissions().adminperm)) {
double x = player.getLocation().getBlockX();
double y = player.getLocation().getBlockY();
double z = player.getLocation().getBlockZ();
String X = Double.toString(x);
String Y = Double.toString(y);
String Z = Double.toString(z);
this.drops.add("X: " + X);
this.drops.add("Y: " + Y);
this.drops.add("Z: " + Z);
this.drops.save();
player.sendMessage(ChatColor.AQUA + "Drop Set.");
}
if(args[0].equalsIgnoreCase("info")){
player.sendMessage(ChatColor.AQUA + "-----DetruxDrop Info-----");
player.sendMessage(ChatColor.BLUE + "DetruxDrop");
player.sendMessage(ChatColor.BLUE + "Version: 1.0");
player.sendMessage(ChatColor.BLUE + "Made by: DetruxCraft Team");
}
if(args[0].equalsIgnoreCase("join")){
}
}
}
return false;
}
}
And now the code for the write/reader:
package me.kyle.detruxdrop;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class ListStore {
private File storageFile;
private ArrayList<String> values;
public ListStore(File file) {
this.storageFile = file;
this.values = new ArrayList<String>();
if(this.storageFile.exists() == false){
try {
this.storageFile.createNewFile();
}catch (IOException e){
e.printStackTrace();
}
}
}
public void load(){
try {
DataInputStream input = new DataInputStream(new FileInputStream(this.storageFile));
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String line;
while ((line = reader.readLine()) != null){
if(this.contains(line) == false){
this.values.add(line);
}
}
reader.close();
input.close();
}catch (Exception e){
e.printStackTrace();
}
}
public void save(){
try {
FileWriter stream = new FileWriter(this.storageFile);
BufferedWriter out = new BufferedWriter(stream);
for(String value : this.values){
out.write(value);
out.newLine();
}
out.close();
stream.close();
}catch (IOException e){
e.printStackTrace();
}
}
public boolean contains(String value){
return this.values.contains(value);
}
public void add(String value) {
if(this.contains(value) == false){
this.values.add(value);
}
}
public void remove(String value){
this.values.remove(value);
}
public ArrayList<String> getValues(){
return this.values;
}
}
What shall i do to make it read the .txt file and give me the x, y and z cords to teleport a player to them.
Thanks in advance.