Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolV1994 committed Apr 2, 2015
0 parents commit ba1bbdb
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "Spawn",
"version": "1.0",
"mainClass": "tk.coolv1994.plugins.spawn.Spawn",
"commands": {
"spawn": "tk.coolv1994.plugins.spawn.CommandSpawn"
}
}
14 changes: 14 additions & 0 deletions src/tk/coolv1994/plugins/spawn/CommandSpawn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package tk.coolv1994.plugins.spawn;

import tk.coolv1994.gawdserver.events.Command;
import tk.coolv1994.gawdserver.launcher.Launch;

/**
* Created by Vinnie on 2/17/2015.
*/
public class CommandSpawn implements Command {
@Override
public void onCommand(String player, String[] args) {
Launch.sendCommand("tp " + player + " " + Spawn.coords);
}
}
69 changes: 69 additions & 0 deletions src/tk/coolv1994/plugins/spawn/Spawn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package tk.coolv1994.plugins.spawn;

import tk.coolv1994.gawdserver.plugin.Plugin;

import java.io.*;

/**
* Created by Vinnie on 2/2/2015.
*/
public class Spawn implements Plugin {
public static String coords = "0 64 0";

@Override
public void startup() {
File configFile = new File("./plugins/Spawn/coordinates.txt");
if (!configFile.exists())
{
configFile.getParentFile().mkdirs();
try {
FileWriter fw = new FileWriter(configFile);
BufferedWriter bw = new BufferedWriter(fw);
bw.write("# Spawn Coordinates");
bw.newLine();
bw.write("x=0");
bw.newLine();
bw.write("y=64");
bw.newLine();
bw.write("z=0");
bw.newLine();
bw.close();
} catch (IOException e) {
System.out.println("Error creating default Spawn coordinates.");
}
}
else
{
BufferedReader br = null;
try {
int x = 0;
int y = 64;
int z = 0;
String currentLine;
br = new BufferedReader(new FileReader(configFile));
while ((currentLine = br.readLine()) != null) {
if (currentLine.startsWith("x="))
x = Integer.valueOf(currentLine.substring(2));
if (currentLine.startsWith("y="))
y = Integer.valueOf(currentLine.substring(2));
if (currentLine.startsWith("z="))
z = Integer.valueOf(currentLine.substring(2));
}
coords = String.format("%d %d %d", x, y, z);
} catch (IOException e) {
System.out.println("Error loading Spawn coordinates.");
} finally {
try {
if (br != null)
br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}

@Override
public void shutdown() {
}
}

0 comments on commit ba1bbdb

Please sign in to comment.