This commit is contained in:
Butzlabben 2019-10-04 14:29:06 +02:00
parent ac67e124cf
commit a32e6c51d0
6 changed files with 59 additions and 47 deletions

View File

@ -220,7 +220,7 @@ public class WSCommand {
DependenceConfig dc = new DependenceConfig(args.getArgument(0));
String worldname = dc.getWorldNamebyOfflinePlayer();
String worldname = dc.getWorldNameByOfflinePlayer();
if (!dc.hasWorld()) {
p.sendMessage(MessageConfig.getNoWorldOther());
return;

View File

@ -11,7 +11,7 @@ import java.util.UUID;
public class DependenceConfig {
private OfflinePlayer op;
private UUID uuid;
public DependenceConfig() {
setConfig();
@ -27,19 +27,23 @@ public class DependenceConfig {
if (op == null) {
op = Bukkit.getOfflinePlayer(s);
}
this.op = op;
uuid = op.getUniqueId();
}
public DependenceConfig(Player p) {
this.op = p;
uuid = p.getUniqueId();
refreshName();
}
public DependenceConfig(OfflinePlayer p) {
this.op = p;
uuid = p.getUniqueId();
refreshName();
}
public DependenceConfig(UUID uuid) {
this.uuid = uuid;
}
public static int getHighestID() {
File dconfig = new File("plugins//WorldSystem//dependence.yml");
YamlConfiguration dcfg = YamlConfiguration.loadConfiguration(dconfig);
@ -80,8 +84,8 @@ public class DependenceConfig {
if (hasWorld()) {
File dconfig = new File("plugins//WorldSystem//dependence.yml");
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig);
String uuid = this.op.getUniqueId().toString();
cfg.set("Dependences." + uuid + ".ActualName", op.getName());
String uuid = this.uuid.toString();
cfg.set("Dependences." + uuid + ".ActualName", Bukkit.getOfflinePlayer(this.uuid).getName());
try {
cfg.save(dconfig);
} catch (IOException e) {
@ -93,12 +97,12 @@ public class DependenceConfig {
public void createNewEntry() {
File dconfig = new File("plugins//WorldSystem//dependence.yml");
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig);
String uuid = this.op.getUniqueId().toString();
String uuid = this.uuid.toString();
int id = cfg.getInt("HighestID");
id++;
cfg.set("HighestID", id);
cfg.set("Dependences." + uuid + ".ID", id);
cfg.set("Dependences." + uuid + ".ActualName", op.getName());
cfg.set("Dependences." + uuid + ".ActualName", Bukkit.getOfflinePlayer(this.uuid).getName());
try {
cfg.save(dconfig);
} catch (IOException e) {
@ -109,7 +113,7 @@ public class DependenceConfig {
public boolean hasWorld() {
File dconfig = new File("plugins//WorldSystem//dependence.yml");
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig);
String uuid = op.getUniqueId().toString();
String uuid = this.uuid.toString();
//Fix for #40
return cfg.isInt("Dependences." + uuid + ".ID");
}
@ -117,14 +121,14 @@ public class DependenceConfig {
public String getWorldname() {
File dconfig = new File("plugins//WorldSystem//dependence.yml");
YamlConfiguration dcfg = YamlConfiguration.loadConfiguration(dconfig);
String uuid = op.getUniqueId().toString();
String uuid = this.uuid.toString();
int id = dcfg.getInt("Dependences." + uuid + ".ID");
return "ID" + id + "-" + uuid;
}
public String getWorldNamebyOfflinePlayer() {
public String getWorldNameByOfflinePlayer() {
String name;
String uuid = op.getUniqueId().toString();
String uuid = this.uuid.toString();
File dconfig = new File("plugins//WorldSystem//dependence.yml");
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig);
if (cfg.getString("Dependences." + uuid + ".ActualName") == null) {
@ -138,7 +142,7 @@ public class DependenceConfig {
public void setLastLoaded() {
File dconfig = new File("plugins//WorldSystem//dependence.yml");
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig);
String uuid = op.getUniqueId().toString();
String uuid = this.uuid.toString();
cfg.set("Dependences." + uuid + ".last_loaded", System.currentTimeMillis());
try {
cfg.save(dconfig);
@ -150,10 +154,10 @@ public class DependenceConfig {
public int getID() {
File dconfig = new File("plugins//WorldSystem//dependence.yml");
YamlConfiguration dcfg = YamlConfiguration.loadConfiguration(dconfig);
return dcfg.getInt("Dependences." + op.getUniqueId().toString() + ".ID");
return dcfg.getInt("Dependences." + this.uuid.toString() + ".ID");
}
public OfflinePlayer getOwner() {
return op;
return Bukkit.getOfflinePlayer(uuid);
}
}

View File

@ -9,7 +9,6 @@ import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import java.io.File;
import java.io.IOException;
@ -78,20 +77,20 @@ public class WorldConfig {
return instances.get(worldname).load();
}
public static void create(Player p, WorldTemplate template) {
DependenceConfig dc = new DependenceConfig(p);
public static void create(UUID uuid, WorldTemplate template) {
DependenceConfig dc = new DependenceConfig(uuid);
String worldname = dc.getWorldname();
File file = new File(PluginConfig.getWorlddir() + worldname + "/worldconfig.yml");
try {
file.createNewFile();
} catch (IOException e1) {
e1.printStackTrace();
System.err.println("Error while creating worldconfig for " + p.getUniqueId().toString());
System.err.println("Error while creating worldconfig for " + uuid.toString());
}
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
cfg.set("Informations.ID", dc.getID());
cfg.set("Informations.Owner.PlayerUUID", p.getUniqueId().toString());
cfg.set("Informations.Owner.Actualname", p.getName());
cfg.set("Informations.Owner.PlayerUUID", uuid.toString());
cfg.set("Informations.Owner.Actualname", Objects.requireNonNull(Bukkit.getOfflinePlayer(uuid)).getName());
cfg.set("Informations.template_key", template.getName());
cfg.set("Settings.TNTDamage", false);
cfg.set("Settings.Fire", false);
@ -100,7 +99,7 @@ public class WorldConfig {
cfg.save(file);
} catch (IOException e) {
e.printStackTrace();
System.err.println("Error while saving worldconfig for " + p.getUniqueId().toString());
System.err.println("Error while saving worldconfig for " + uuid.toString());
}
}

View File

@ -1,9 +1,10 @@
package de.butzlabben.world.event;
import org.bukkit.WorldCreator;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import java.util.UUID;
/**
* Event if a SystemWorld gets created.
* Do mix up with the WorldCreateEvent from Bukkit
@ -14,10 +15,10 @@ import org.bukkit.event.HandlerList;
public class WorldCreateEvent extends WorldEvent {
public final static HandlerList handlers = new HandlerList();
private final Player owner;
private final UUID owner;
private WorldCreator worldCreator;
public WorldCreateEvent(Player owner, WorldCreator creator) {
public WorldCreateEvent(UUID owner, WorldCreator creator) {
this.owner = owner;
this.setWorldCreator(creator);
}
@ -29,7 +30,7 @@ public class WorldCreateEvent extends WorldEvent {
/**
* @return owner of world that gets created
*/
public Player getOwner() {
public UUID getOwner() {
return owner;
}

View File

@ -16,6 +16,7 @@ import org.bukkit.scheduler.BukkitTask;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.UUID;
/**
* This class represents a systemworld, loaded or not
@ -73,24 +74,30 @@ public class SystemWorld {
}, 20);
}
public static boolean create(Player p, WorldTemplate template) {
return create(p.getUniqueId(), template);
}
/**
* Trys to create a new systemworld with all entries etc. finally loads the
* world
*
* @param p Player to create the world for
* @param uniqueID UUID of the player to create the world for
* @return whether it succesfull or not
*/
public static boolean create(Player p, WorldTemplate template) {
public static boolean create(UUID uniqueID, WorldTemplate template) {
DependenceConfig dc = new DependenceConfig(p);
DependenceConfig dc = new DependenceConfig(uniqueID);
String uuid = p.getUniqueId().toString();
String uuid = uniqueID.toString();
int id = DependenceConfig.getHighestID() + 1;
String worldname = "ID" + id + "-" + uuid;
Player p = Bukkit.getPlayer(uniqueID);
WorldCreator creator = template.getGeneratorSettings().asWorldCreator(worldname);
WorldCreateEvent event = new WorldCreateEvent(p, creator);
WorldCreateEvent event = new WorldCreateEvent(uniqueID, creator);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return false;
@ -109,13 +116,13 @@ public class SystemWorld {
try {
FileUtils.copyDirectory(exampleworld, newworld);
} catch (IOException e) {
System.err.println("Couldn't create world for " + p.getName());
System.err.println("Couldn't create world for " + uuid);
e.printStackTrace();
}
else
newworld.mkdirs();
WorldConfig.create(p, template);
WorldConfig.create(uniqueID, template);
// Move World into Server dir
File world = new File(worlddir + "/" + worldname);
@ -133,8 +140,9 @@ public class SystemWorld {
try {
FileUtils.moveDirectoryToDirectory(world, Bukkit.getWorldContainer(), false);
} catch (IOException e) {
if (p != null && p.isOnline())
p.sendMessage(PluginConfig.getPrefix() + "§cError: " + e.getMessage());
System.err.println("Couldn't load world of " + p.getName());
System.err.println("Couldn't load world of " + uuid);
e.printStackTrace();
return false;
}

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report-3.0.xsd" version="3.0" name="de.butzlabben.world.wrapper.GeneratorSettingsTest" time="0.021" tests="1" errors="0" skipped="0" failures="0">
<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report-3.0.xsd" version="3.0" name="de.butzlabben.world.wrapper.GeneratorSettingsTest" time="0.081" tests="1" errors="0" skipped="0" failures="0">
<properties>
<property name="sun.desktop" value="windows"/>
<property name="awt.toolkit" value="sun.awt.windows.WToolkit"/>
@ -18,7 +18,7 @@
<property name="user.country" value="DE"/>
<property name="sun.java.launcher" value="SUN_STANDARD"/>
<property name="sun.boot.library.path" value="C:\Program Files\Java\jdk1.8.0_201\jre\bin"/>
<property name="sun.java.command" value="C:\Users\Daniel\AppData\Local\Temp\surefire9022411946843047751\surefirebooter3945445194430347641.jar C:\Users\Daniel\AppData\Local\Temp\surefire9022411946843047751 2019-09-07T21-26-34_843-jvmRun1 surefire566841560838190623tmp surefire_02403458146514272146tmp"/>
<property name="sun.java.command" value="C:\Users\Daniel\AppData\Local\Temp\surefire4842291927356751410\surefirebooter1961109782025746048.jar C:\Users\Daniel\AppData\Local\Temp\surefire4842291927356751410 2019-10-04T14-25-31_750-jvmRun1 surefire5547760009693727186tmp surefire_02465458387862569454tmp"/>
<property name="surefire.test.class.path" value="C:\Users\Daniel\IdeaProjects\PersonalProjects\worldsystem\target\test-classes;C:\Users\Daniel\IdeaProjects\PersonalProjects\worldsystem\target\classes;C:\Users\Daniel\.m2\repository\org\spigotmc\spigot-api\1.14-R0.1-SNAPSHOT\spigot-api-1.14-R0.1-SNAPSHOT.jar;C:\Users\Daniel\.m2\repository\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;C:\Users\Daniel\.m2\repository\com\google\guava\guava\21.0\guava-21.0.jar;C:\Users\Daniel\.m2\repository\com\google\code\gson\gson\2.8.0\gson-2.8.0.jar;C:\Users\Daniel\.m2\repository\net\md-5\bungeecord-chat\1.13-SNAPSHOT\bungeecord-chat-1.13-SNAPSHOT.jar;C:\Users\Daniel\.m2\repository\org\yaml\snakeyaml\1.23\snakeyaml-1.23.jar;C:\Users\Daniel\.m2\repository\com\mojang\authlib\1.5.21\authlib-1.5.21.jar;C:\Users\Daniel\.m2\repository\org\apache\commons\commons-lang3\3.3.2\commons-lang3-3.3.2.jar;C:\Users\Daniel\.m2\repository\org\apache\logging\log4j\log4j-core\2.0-beta9\log4j-core-2.0-beta9.jar;C:\Users\Daniel\.m2\repository\commons-codec\commons-codec\1.9\commons-codec-1.9.jar;C:\Users\Daniel\.m2\repository\org\apache\logging\log4j\log4j-api\2.0-beta9\log4j-api-2.0-beta9.jar;C:\Users\Daniel\.m2\repository\com\google\code\findbugs\jsr305\2.0.1\jsr305-2.0.1.jar;C:\Users\Daniel\.m2\repository\commons-io\commons-io\2.6\commons-io-2.6.jar;C:\Users\Daniel\IdeaProjects\PersonalProjects\worldsystem\lib\FastAsyncWorldEdit.jar;C:\Users\Daniel\.m2\repository\com\sk89q\worldedit\worldedit-core\7.0.0-SNAPSHOT\worldedit-core-7.0.0-SNAPSHOT.jar;C:\Users\Daniel\.m2\repository\com\sk89q\worldedit\worldedit-libs\core\7.0.0-SNAPSHOT\core-7.0.0-SNAPSHOT.jar;C:\Users\Daniel\.m2\repository\de\schlichtherle\truezip\6.8.3\truezip-6.8.3.jar;C:\Users\Daniel\.m2\repository\rhino\js\1.7R2\js-1.7R2.jar;C:\Users\Daniel\.m2\repository\com\googlecode\json-simple\json-simple\1.1.1\json-simple-1.1.1.jar;C:\Users\Daniel\.m2\repository\junit\junit\4.10\junit-4.10.jar;C:\Users\Daniel\.m2\repository\org\hamcrest\hamcrest-core\1.1\hamcrest-core-1.1.jar;C:\Users\Daniel\.m2\repository\org\slf4j\slf4j-api\1.7.26\slf4j-api-1.7.26.jar;C:\Users\Daniel\.m2\repository\com\sk89q\worldedit\worldedit-bukkit\7.0.0-SNAPSHOT\worldedit-bukkit-7.0.0-SNAPSHOT.jar;C:\Users\Daniel\.m2\repository\com\sk89q\worldedit\worldedit-libs\bukkit\7.0.0-SNAPSHOT\bukkit-7.0.0-SNAPSHOT.jar;C:\Users\Daniel\.m2\repository\org\bukkit\bukkit\1.13.2-R0.1-SNAPSHOT\bukkit-1.13.2-R0.1-SNAPSHOT.jar;C:\Users\Daniel\.m2\repository\io\papermc\paperlib\1.0.2\paperlib-1.0.2.jar;C:\Users\Daniel\.m2\repository\org\apache\logging\log4j\log4j-slf4j-impl\2.8.1\log4j-slf4j-impl-2.8.1.jar;C:\Users\Daniel\.m2\repository\org\bstats\bstats-bukkit\1.4\bstats-bukkit-1.4.jar;C:\Users\Daniel\.m2\repository\net\myplayplanet\CommandFramework\2.0.0-SNAPSHOT\CommandFramework-2.0.0-SNAPSHOT.jar;C:\Users\Daniel\.m2\repository\net\milkbowl\vault\VaultAPI\1.6\VaultAPI-1.6.jar;C:\Users\Daniel\.m2\repository\me\clip\placeholderapi\2.9.2\placeholderapi-2.9.2.jar;C:\Users\Daniel\.m2\repository\org\projectlombok\lombok\1.18.4\lombok-1.18.4.jar;"/>
<property name="sun.cpu.endian" value="little"/>
<property name="user.home" value="C:\Users\Daniel"/>
@ -28,10 +28,11 @@
<property name="basedir" value="C:\Users\Daniel\IdeaProjects\PersonalProjects\worldsystem"/>
<property name="file.separator" value="\"/>
<property name="line.separator" value="&#10;"/>
<property name="idea.version2019.2.3" value="true"/>
<property name="java.vm.specification.vendor" value="Oracle Corporation"/>
<property name="java.specification.name" value="Java Platform API Specification"/>
<property name="java.awt.graphicsenv" value="sun.awt.Win32GraphicsEnvironment"/>
<property name="surefire.real.class.path" value="C:\Users\Daniel\AppData\Local\Temp\surefire9022411946843047751\surefirebooter3945445194430347641.jar"/>
<property name="surefire.real.class.path" value="C:\Users\Daniel\AppData\Local\Temp\surefire4842291927356751410\surefirebooter1961109782025746048.jar"/>
<property name="sun.boot.class.path" value="C:\Program Files\Java\jdk1.8.0_201\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\sunrsasign.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_201\jre\classes"/>
<property name="user.script" value=""/>
<property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
@ -52,8 +53,7 @@
<property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
<property name="java.awt.printerjob" value="sun.awt.windows.WPrinterJob"/>
<property name="sun.os.patch.level" value=""/>
<property name="idea.version2019.2" value="true"/>
<property name="java.library.path" value="C:\Program Files\Java\jdk1.8.0_201\jre\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Users\Daniel\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\192.5728.98\jbr\\bin;C:\Users\Daniel\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\192.5728.98\jbr\\bin\server;C:\Program Files (x86)\Razer\ChromaBroadcast\bin;C:\Program Files\Razer\ChromaBroadcast\bin;C:\Program Files\Microsoft MPI\Bin\;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Razer Chroma SDK\bin;C:\Program Files\Razer Chroma SDK\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\PuTTY\;C:\Users\Daniel\AppData\Local\Microsoft\WindowsApps;C:\Program Files\nodejs\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Windows Live\Shared;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Users\Daniel\AppData\Local\Programs\Python\Python36;C:\Users\Daniel\AppData\Local\Programs\Python\Python36\Scripts;C:\Program Files\flutter\bin;C:\Program Files\apache-maven-3.6.0\bin;C:\Users\Daniel\AppData\Roaming\npm;E:\Programs\Android\Sdk\platform-tools;C:\Program Files\flutter\.pub-cache\bin;C:\Program Files\Git\bin;C:\Program Files\Java\jdk1.8.0_201\bin;C:\Program Files\flutter\bin\cache\dart-sdk\bin;C:\Users\Daniel\.cargo\bin;C:\Program Files\flutter\bin;C:\Program Files\ffmpeg\bin;C:\Users\Daniel\AppData\Roaming\npm;C:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Daniel\AppData\Local\Android\Sdk\platform-tools;C:\Program Files\flutter\.pub-cache\bin;C:\Program Files\Git\bin;C:\Program Files (x86)\Nmap;C:\Program Files\flutter\bin\cache\dart-sdk\bin;;."/>
<property name="java.library.path" value="C:\Program Files\Java\jdk1.8.0_201\jre\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files (x86)\Razer\ChromaBroadcast\bin;C:\Program Files\Razer\ChromaBroadcast\bin;C:\Program Files\Microsoft MPI\Bin\;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Razer Chroma SDK\bin;C:\Program Files\Razer Chroma SDK\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\PuTTY\;C:\Users\Daniel\AppData\Local\Microsoft\WindowsApps;C:\Program Files\nodejs\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Windows Live\Shared;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Users\Daniel\AppData\Local\Programs\Python\Python36;C:\Users\Daniel\AppData\Local\Programs\Python\Python36\Scripts;C:\Program Files\flutter\bin;C:\Program Files\apache-maven-3.6.0\bin;C:\Users\Daniel\AppData\Roaming\npm;E:\Programs\Android\Sdk\platform-tools;C:\Program Files\flutter\.pub-cache\bin;C:\Program Files\Git\bin;C:\Program Files\Java\jdk1.8.0_201\bin;C:\Program Files\flutter\bin\cache\dart-sdk\bin;C:\Users\Daniel\.cargo\bin;C:\Program Files\flutter\bin;C:\Program Files\ffmpeg\bin;C:\Users\Daniel\AppData\Roaming\npm;C:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Daniel\AppData\Local\Android\Sdk\platform-tools;C:\Program Files\flutter\.pub-cache\bin;C:\Program Files\Git\bin;C:\Program Files (x86)\Nmap;C:\Program Files\flutter\bin\cache\dart-sdk\bin;C:\Users\Daniel\AppData\Local\GitHubDesktop\bin;."/>
<property name="java.vm.info" value="mixed mode"/>
<property name="java.vendor" value="Oracle Corporation"/>
<property name="java.vm.version" value="25.201-b09"/>
@ -61,5 +61,5 @@
<property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
<property name="java.class.version" value="52.0"/>
</properties>
<testcase name="asWorldCreator" classname="de.butzlabben.world.wrapper.GeneratorSettingsTest" time="0.012"/>
<testcase name="asWorldCreator" classname="de.butzlabben.world.wrapper.GeneratorSettingsTest" time="0.073"/>
</testsuite>