This commit is contained in:
Florian Bouillon 2017-05-12 01:38:50 +02:00
parent 8a43da2019
commit bf621ef443
14 changed files with 149 additions and 83 deletions

7
.idea/kotlinc.xml generated Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="KotlinCommonCompilerArguments">
<option name="languageVersion" value="1.1" />
<option name="apiVersion" value="1.1" />
</component>
</project>

4
.idea/misc.xml generated
View File

@ -12,7 +12,7 @@
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/../BetterTP/out" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8.0_121" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -9,7 +9,7 @@
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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 {

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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<String> 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();
}
}

View File

@ -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();
}
}

View File

@ -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