diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml
new file mode 100644
index 0000000..1c24f9a
--- /dev/null
+++ b/.idea/kotlinc.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index bf6c7e6..589f302 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -12,7 +12,7 @@
-
-
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/BetterTP.iml b/BetterTP.iml
index 1771554..c22320d 100644
--- a/BetterTP.iml
+++ b/BetterTP.iml
@@ -9,7 +9,7 @@
-
+
diff --git a/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Bettertp.java b/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Bettertp.java
index f012f31..2aae2b1 100644
--- a/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Bettertp.java
+++ b/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Bettertp.java
@@ -8,42 +8,68 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
+import java.io.IOException;
+
public class Bettertp implements CommandExecutor {
- private Config m = new Config("", "messages");
-
@Override
- public boolean onCommand(CommandSender s, Command d, String g, String[] a) {
+ public boolean onCommand(CommandSender s, Command unu2, String unu1, String[] a) {
+ Config m = new Config("", "messages");
+ Config g = new Config("", "config");
if(s instanceof Player && s.hasPermission("bettertp.admin")) {
Player p = (Player) s;
if(a.length == 2) {
if(a[0].equalsIgnoreCase("set")) {
if(a[1].equalsIgnoreCase("spawn")) {
- Config c = new Config("data/spawn", "config");
- if(!c.exist()) c.create();
+ Config c = null;
+ if(g.getString("spawn.work").equalsIgnoreCase("server")) c = new Config("data/spawn", "config");
+ else if(g.getString("spawn.work").equalsIgnoreCase("world")) c = new Config("data/spawn", ((Player) s).getWorld().getName());
+ if(c != null && !c.exist()) try {
+ c.create();
+ } catch ( IOException e ) {
+ e.printStackTrace();
+ s.sendMessage("Error please call an administrator !");
+ }
Location l = p.getLocation();
c.set("world", l.getWorld().getName());
c.set("x", l.getX());
c.set("y", l.getY());
c.set("z", l.getZ());
- c.save();
+ try {
+ c.save();
+ } catch ( IOException e ) {
+ e.printStackTrace();
+ s.sendMessage("Error please call an administrator !");
+ }
s.sendMessage(m.getString("spawn.set").replace("&","§"));
+
return true;
} else if(a[1].equalsIgnoreCase("lobby")) {
Config c = new Config("data/lobby", "config");
- if(!c.exist()) c.create();
+ if(!c.exist()) try {
+ c.create();
+ } catch (IOException e) {
+ e.printStackTrace();
+ s.sendMessage("Error Please call an administrator !");
+ }
Location l = p.getLocation();
c.set("world", l.getWorld().getName());
c.set("x", l.getX());
c.set("y", l.getY());
c.set("z", l.getZ());
- c.save();
+ try {
+ c.save();
+ } catch ( IOException e ) {
+ e.printStackTrace();
+ s.sendMessage("Error Please call an administrator !");
+ }
s.sendMessage(m.getString("lobby.set").replace("&","§"));
return true;
}
} else if(a[0].equalsIgnoreCase("del") || a[0].equalsIgnoreCase("delete")) {
if(a[1].equalsIgnoreCase("spawn")) {
- new Config("data/spawn", "config").delete();
+ if(g.getString("spawn.work").equalsIgnoreCase("server")) new Config("data/spawn", "config").delete();
+ else if(g.getString("spawn.work").equalsIgnoreCase("world")) new Config("data/spawn", ((Player) s).getWorld().getName()).delete();
s.sendMessage(m.getString("spawn.deleted").replace("&","§"));
return true;
} else if(a[1].equalsIgnoreCase("lobby")) {
@@ -55,15 +81,18 @@ public class Bettertp implements CommandExecutor {
} else if(a.length == 1) {
if(a[0].equalsIgnoreCase("help")) {
Config c = new Config("", "messages");
- p.sendMessage(c.getString("help.top").replace("&", "§"));
+ p.sendMessage(c.getString("help.top").replace("[help]", "BetterTP").replace("&", "§"));
p.sendMessage("&4| &9/btp &lset &llobby/spawn".replace("&", "§"));
p.sendMessage("&4| &9To set spawn or lobby".replace("&", "§"));
p.sendMessage("&4| &9/btp &ldel &llobby/spawn".replace("&", "§"));
p.sendMessage("&4| &9To delete spawn/lobby".replace("&", "§"));
- p.sendMessage(c.getString("help.bottom").replace("&", "§"));
+ p.sendMessage(c.getString("help.bottom").replace("[help]", "BetterTP").replace("&", "§"));
return true;
}
}
+ } else if(s instanceof Player){
+ s.sendMessage(m.getString("global.permission").replace("&", "§"));
+ return true;
}
return false;
}
diff --git a/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Delhome.java b/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Delhome.java
index 52ff356..8b5505d 100644
--- a/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Delhome.java
+++ b/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Delhome.java
@@ -7,6 +7,8 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
+import java.io.IOException;
+
public class Delhome implements CommandExecutor {
private Config m = new Config("", "messages");
@@ -18,7 +20,12 @@ public class Delhome implements CommandExecutor {
if(a.length == 1) {
if(c.isSet(a[0])) {
c.set(a[0], null);
- c.save();
+ try {
+ c.save();
+ } catch ( IOException e ) {
+ e.printStackTrace();
+ s.sendMessage("Error, Please call an Admin !");
+ }
s.sendMessage(m.getString("home.deleted").replace("[home]", a[0]).replace("&", "§"));
return true;
} else {
@@ -28,7 +35,12 @@ public class Delhome implements CommandExecutor {
} else if(a.length == 0) {
if(c.isSet("home")) {
c.set("home", null);
- c.save();
+ try {
+ c.save();
+ } catch ( IOException e ) {
+ e.printStackTrace();
+ s.sendMessage("Error, Please call an Admin !");
+ }
s.sendMessage(m.getString("home.deleted").replace("[home]", "home").replace("&", "§"));
return true;
} else {
@@ -40,7 +52,7 @@ public class Delhome implements CommandExecutor {
s.sendMessage(m.getString("global.permission").replace("&", "§"));
return true;
} else {
- s.sendMessage("global.not-console");
+ s.sendMessage(m.getString("global.not-console"));
return true;
}
return false;
diff --git a/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Home.java b/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Home.java
index 9f16fbf..a525c4d 100644
--- a/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Home.java
+++ b/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Home.java
@@ -3,6 +3,8 @@ package net.DeltaWings.Minecraft.BetterTP.Commands;
import net.DeltaWings.Minecraft.BetterTP.Custom.Config;
import net.DeltaWings.Minecraft.BetterTP.Main;
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@@ -18,26 +20,23 @@ public class Home implements CommandExecutor {
if(c.exist()) {
if(a.length == 0) {
if ( c.isSet("home") ) {
- String[] l = new String[2];
- l[0] = "home";
- l[1] = "home";
- Main.getInstance().tp(l, (Player) s);
+ String t = "home.";
+ ((Player) s).teleport(new Location(Bukkit.getServer().getWorld(c.getString(t+"world")), c.getDouble(t+"x"), c.getDouble(t+"y"), c.getDouble(t+"z")));
s.sendMessage(m.getString("home.teleported").replace("[home]", "home").replace("&", "§"));
return true;
} else {
- s.sendMessage(m.getString("home.dont-exist").replace("&", "§"));
+ s.sendMessage(m.getString("home.dont-exist").replace("&", "§").replace("[home]", "Home"));
return true;
}
} else if(a.length == 1) {
if ( c.isSet(a[0]) ) {
- String[] l = new String[2];
- l[0] = "home";
- l[1] = a[0];
- Main.getInstance().tp(l, (Player) s);
+ String t = a[0] + ".";
+ ((Player) s).teleport(new Location(Bukkit.getServer().getWorld(c.getString(t+"world")), c.getDouble(t+"x"), c.getDouble(t+"y"), c.getDouble(t+"z")));
+
s.sendMessage(m.getString("home.teleported").replace("[home]", a[0]).replace("&", "§"));
return true;
} else {
- s.sendMessage(m.getString("home.dont-exist").replace("&", "§"));
+ s.sendMessage(m.getString("home.dont-exist").replace("&", "§").replace("[home]", a[0]));
return true;
}
}
@@ -45,6 +44,12 @@ public class Home implements CommandExecutor {
s.sendMessage(m.getString("home.dont-exist"));
return true;
}
+ } else if(s instanceof Player && !s.hasPermission("bettertp.home")) {
+ s.sendMessage(m.getString("global.permission").replace("&", "§"));
+ return true;
+ } else {
+ s.sendMessage(m.getString("global.not-console"));
+ return true;
}
return false;
}
diff --git a/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Homelist.java b/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Homelist.java
index b50a485..0bba950 100644
--- a/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Homelist.java
+++ b/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Homelist.java
@@ -11,10 +11,14 @@ public class Homelist implements CommandExecutor {
@Override
public boolean onCommand(CommandSender s, Command command, String label, String[] args) {
if(s instanceof Player) {
+ Config c = new Config("", "messages");
+ s.sendMessage(c.getString("help.top").replace("[help]", "Homelist").replace("&", "§"));
for(String a : new Config("data", s.getName()).getSection("")) {
- s.sendMessage(("&b"+a).replace("&", "§"));
+ s.sendMessage(("&4| &9").replace("&", "§") + a);
}
+ s.sendMessage(c.getString("help.bottom").replace("[help]", "Homelist").replace("&", "§"));
+ return true;
}
- return true;
+ return false;
}
}
diff --git a/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Lobby.java b/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Lobby.java
index c9bb4cb..508577d 100644
--- a/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Lobby.java
+++ b/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Lobby.java
@@ -2,28 +2,26 @@ package net.DeltaWings.Minecraft.BetterTP.Commands;
import net.DeltaWings.Minecraft.BetterTP.Custom.Config;
import net.DeltaWings.Minecraft.BetterTP.Main;
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
-/**
- * Created by Delta Wings on 18/03/2017 at.15:24
- */
public class Lobby implements CommandExecutor {
private Config m = new Config("", "messages");
@Override
- public boolean onCommand(CommandSender s, Command command, String label, String[] args) {
+ public boolean onCommand(CommandSender s, Command unu1, String unu2, String[] unu3) {
if(s instanceof Player ) {
if(s.hasPermission("bettertp.lobby")) {
Config c = new Config("data/lobby", "config");
if(c.exist()) {
Double y = c.getDouble("x", (double) -1);
- if(!(y == -1)) {
- String[] sl = new String[2];
- sl[0] = "lobby";
- Main.getInstance().tp(sl, (Player) s );
+ if(y != -1) {
+ ((Player) s).teleport(new Location(Bukkit.getServer().getWorld(c.getString("world")), c.getDouble("x"), c.getDouble("y"), c.getDouble("z")));
+ s.sendMessage(m.getString("lobby.teleported").replace("&", "§"));
return true;
}
} else {
diff --git a/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Sethome.java b/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Sethome.java
index 320460e..0efd3da 100644
--- a/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Sethome.java
+++ b/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Sethome.java
@@ -8,6 +8,7 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
+import java.io.IOException;
import java.util.ArrayList;
public class Sethome implements CommandExecutor {
@@ -28,26 +29,41 @@ public class Sethome implements CommandExecutor {
if(c.getSection("").size() == mc.getInt("maxhomes." + e)) p = true;
}
if(p) {
- s.sendMessage(m.getString("home.max").replace("[max]", c.getSection("").size() + ""));
+ s.sendMessage(m.getString("home.max").replace("[max]", c.getSection("").size() + "").replace("&", "§"));
+ return true;
} else {
+ if(!c.exist()) try {
+ c.create();
+ } catch ( IOException e ) {
+ e.printStackTrace();
+ s.sendMessage("Error, Please call an Admin !");
+ }
if(a.length == 0) {
- if(!c.exist()) c.create();
Location l = ((Player) s).getLocation();
c.set("home.world", l.getWorld().getName());
c.set("home.x", l.getX());
c.set("home.y", l.getY());
c.set("home.z", l.getZ());
- c.save();
+ try {
+ c.save();
+ } catch ( IOException e ) {
+ e.printStackTrace();
+ s.sendMessage("Error, Please call an Admin !");
+ }
s.sendMessage(m.getString("home.set").replace("[home]", "home").replace("&", "§"));
return true;
} else if(a.length == 1) {
- if(!c.exist()) c.create();
Location l = ((Player) s).getLocation();
c.set(a[0] + ".world", l.getWorld().getName());
c.set(a[0] + ".x", l.getX());
c.set(a[0] + ".y", l.getY());
c.set(a[0] + ".z", l.getZ());
- c.save();
+ try {
+ c.save();
+ } catch ( IOException e ) {
+ e.printStackTrace();
+ s.sendMessage("Error, Please call an Admin !");
+ }
s.sendMessage(m.getString("home.set").replace("[home]", a[0]).replace("&", "§"));
return true;
}
diff --git a/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Spawn.java b/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Spawn.java
index ae2372a..392d75e 100644
--- a/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Spawn.java
+++ b/src/main/java/net/DeltaWings/Minecraft/BetterTP/Commands/Spawn.java
@@ -10,21 +10,20 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Spawn implements CommandExecutor {
- private Config m = new Config("", "messages");
@Override
public boolean onCommand(CommandSender s, Command d, String l, String[] a) {
+ Config m = new Config("", "messages");
if(s instanceof Player) {
if(s.hasPermission("bettertp.spawn")) {
- Config c = new Config("data/spawn", "config");
- if(c.exist()) {
- Double y = c.getDouble("x", (double) -1);
- if(!(y == -1)) {
- String[] sl = new String[2];
- sl[0] = "spawn";
- Main.getInstance().tp(sl, (Player) s );
- return true;
- }
+ Config g = new Config("", "config");
+ Config c = null;
+ if(g.getString("spawn.work").equalsIgnoreCase("server")) c = new Config("data/spawn", "config");
+ else if(g.getString("spawn.work").equalsIgnoreCase("world")) c = new Config("data/spawn", ((Player) s).getWorld().getName());
+ if(c != null && c.exist()) {
+ ((Player) s).teleport(new Location(Bukkit.getServer().getWorld(c.getString("world")), c.getDouble("x"), c.getDouble("y"), c.getDouble("z")));
+ s.sendMessage(m.getString("spawn.teleported").replace("&", "§"));
+ return true;
} else {
s.sendMessage(m.getString("spawn.not-set").replace("&", "§"));
return true;
@@ -37,6 +36,5 @@ public class Spawn implements CommandExecutor {
s.sendMessage(m.getString("global.not-console"));
return true;
}
- return false;
}
}
diff --git a/src/main/java/net/DeltaWings/Minecraft/BetterTP/Custom/Config.java b/src/main/java/net/DeltaWings/Minecraft/BetterTP/Custom/Config.java
index cea483b..63e226d 100644
--- a/src/main/java/net/DeltaWings/Minecraft/BetterTP/Custom/Config.java
+++ b/src/main/java/net/DeltaWings/Minecraft/BetterTP/Custom/Config.java
@@ -15,7 +15,6 @@ public class Config {
private final File root = Main.getInstance().getDataFolder();
private final File folder;
private final File file;
- private final FileManager fm = new FileManager();
public Config(String folder, String file) {
this.folder = new File(folder);
@@ -71,12 +70,8 @@ public class Config {
return config.getLong(path, def);
}
- public void save() {
- try {
- config.save(file);
- } catch ( IOException e ) {
- e.printStackTrace();
- }
+ public void save() throws IOException {
+ config.save(file);
}
public ArrayList getSection(String path) {
@@ -87,16 +82,12 @@ public class Config {
return config.getStringList(path);
}
- public void create() {
+ public void create() throws IOException {
if(!exist()) {
if(!root.exists()) root.mkdirs();
File rfolder = new File(root.toString() + File.separator + folder.toString());
if(!rfolder.exists()) rfolder.mkdirs();
- try {
- file.createNewFile();
- } catch ( IOException e ) {
- e.printStackTrace();
- }
+ file.createNewFile();
}
}
@@ -113,6 +104,6 @@ public class Config {
}
public void delete() {
- fm.delete(file);
+ file.delete();
}
}
\ No newline at end of file
diff --git a/src/main/java/net/DeltaWings/Minecraft/BetterTP/Main.java b/src/main/java/net/DeltaWings/Minecraft/BetterTP/Main.java
index ac93235..c3fbbaf 100644
--- a/src/main/java/net/DeltaWings/Minecraft/BetterTP/Main.java
+++ b/src/main/java/net/DeltaWings/Minecraft/BetterTP/Main.java
@@ -8,6 +8,7 @@ import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
+import java.io.IOException;
import java.util.logging.Level;
public final class Main extends JavaPlugin {
@@ -16,17 +17,6 @@ public final class Main extends JavaPlugin {
Bukkit.getLogger().log(Level.INFO, Message);
}
- public void tp(String[] Type, Player Player) {
- if(Type[0].equals("spawn") || Type[0].equals("lobby")) {
- Config c = new Config("data/"+Type[0], "config");
- Player.teleport(new Location(Bukkit.getServer().getWorld(c.getString("world")), c.getDouble("x"), c.getDouble("y"), c.getDouble("z")));
- } else {
- Config c = new Config("data", Player.getName());
- String t = Type[1] + ".";
- Player.teleport(new Location(Bukkit.getServer().getWorld(c.getString(t+"world")), c.getDouble(t+"x"), c.getDouble(t+"y"), c.getDouble(t+"z")));
- }
- }
-
private static Main instance;
public static Main getInstance() {
return instance;
@@ -43,7 +33,13 @@ public final class Main extends JavaPlugin {
getCommand("Delhome").setExecutor(new Delhome());
getCommand("Homelist").setExecutor(new Homelist());
- config();
+ try {
+ config();
+ } catch ( IOException e ) {
+ e.printStackTrace();
+ log("Shutting Down for security...");
+ this.getPluginLoader().disablePlugin(this);
+ }
log("Plugin Loaded !");
}
@@ -53,7 +49,7 @@ public final class Main extends JavaPlugin {
log("Plugin Unloaded !");
}
- private void config() {
+ private void config() throws IOException {
Config messages = new Config("", "messages");
if(!messages.exist()) {
messages.create();
@@ -73,15 +69,18 @@ public final class Main extends JavaPlugin {
messages.set("home.dont-exist", "&8 >&c Your home [home] do not exist");
messages.set("home.teleported", "&8 >&c You have been teleported to your home : [home]");
messages.set("home.max", "&8 >&c You already have [max] homes");
- messages.set("help.top", "&4-&c=&4-&c=&4-&c=&4-&c=&4-&c=&4-&c=&4-&c= &2BetterTP &c=&4-&c=&4-&c=&4-&c=&4-&c=&4-&c=&4-&c=&4-");
- messages.set("help.bottom", "&4-&c=&4-&c=&4-&c=&4-&c=&4-&c=&4-&c=&4-&c= &2BetterTP &c=&4-&c=&4-&c=&4-&c=&4-&c=&4-&c=&4-&c=&4-");
+ messages.set("help.top", "&4-&c=&4-&c=&4-&c=&4-&c=&4-&c=&4-&c=&4-&c= &2[help] &c=&4-&c=&4-&c=&4-&c=&4-&c=&4-&c=&4-&c=&4-");
+ messages.set("help.bottom", "&4-&c=&4-&c=&4-&c=&4-&c=&4-&c=&4-&c=&4-&c= &2[help] &c=&4-&c=&4-&c=&4-&c=&4-&c=&4-&c=&4-&c=&4-");
messages.save();
}
Config c = new Config("", "config");
if(!c.exist()) {
c.create();
- c.set("maxhomes");
+ c.header("How to config : https://bitbucket.org/delta-wings/bettertp/wiki/");
+ c.set("maxhomes.default", 1);
+ c.set("spawn.work", "world");
+ c.set("spawn.server.lobby", false);
c.save();
}
}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index f4087d3..c75ad85 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -12,6 +12,7 @@ commands:
lobby:
description: Teleport to the lobby
usage: Usage /lobby
+ aliases: [hub]
bettertp:
description: Manage the plugin
usage: Usage /bettertp help