Fixed #16 on github

This commit is contained in:
Butzlabben 2019-02-14 19:05:37 +01:00
parent 93b322116b
commit b5faa1d836
6 changed files with 403 additions and 403 deletions

17
pom.xml
View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.butzlabben.world</groupId>
<artifactId>WorldSystem</artifactId>
<version>2.4.3</version>
<version>2.4.3.2</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.number>-</project.build.number>
@ -11,6 +11,16 @@
Build:${project.build.number}</project.build.version>
</properties>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version>
</plugin>
</plugins>
</reporting>
<build>
<defaultGoal>package</defaultGoal>
<sourceDirectory>src/main/java</sourceDirectory>
@ -22,6 +32,11 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>

View File

@ -69,6 +69,13 @@ public class WSCommand {
@Command(name = "ws.get", inGameOnly = true)
public void getCommand(CommandArgs args) {
Player p = args.getSender(Player.class);
// Check if use can create a world
if (!p.hasPermission("ws.get")) {
p.sendMessage(MessageConfig.getNoPermission());
return;
}
// create New Entry
DependenceConfig dc = new DependenceConfig(p);
if (dc.hasWorld()) {
@ -76,16 +83,13 @@ public class WSCommand {
return;
}
if (!p.hasPermission("ws.get")) {
p.sendMessage(MessageConfig.getNoPermission());
return;
}
if (PluginConfig.isMultiChoose()) {
if (args.length() > 0) {
String key = args.getArgument(0);
WorldTemplate template = WorldTemplateProvider.getInstace().getTemplate(key);
if (template != null) {
// Permission for this specific template
if (template.getPermission() != null && !p.hasPermission(template.getPermission())) {
p.sendMessage(MessageConfig.getNoPermission());
return;
@ -94,7 +98,7 @@ public class WSCommand {
return;
}
}
p.openInventory(new WorldChooseGUI().getInventory(p));
WorldChooseGUI.letChoose(p);
} else {
WorldTemplate template = WorldTemplateProvider.getInstace()
.getTemplate(PluginConfig.getDefaultWorldTemplate());

View File

@ -22,6 +22,10 @@ public class WorldChooseGUI extends OrcInventory {
this(null, null);
}
public WorldChooseGUI(Player player) {
this(null, player);
}
public WorldChooseGUI(Consumer<WorldTemplate> onClick, Player player) {
super(GuiConfig.getTitle(GuiConfig.getConfig(), "worldchoose"), GuiConfig.getRows("worldchoose"),
GuiConfig.isFill("worldchoose"));
@ -54,6 +58,10 @@ public class WorldChooseGUI extends OrcInventory {
player.openInventory(new WorldChooseGUI(template, player).getInventory(player));
}
public static void letChoose(Player player) {
player.openInventory(new WorldChooseGUI(player).getInventory(player));
}
public void loadItem(String subpath, OrcClickListener listener) {
if (GuiConfig.isEnabled(path + subpath) == false)
return;

View File

@ -1,31 +1,20 @@
package de.butzlabben.world.wrapper;
import com.google.common.base.Preconditions;
import de.butzlabben.world.WorldSystem;
import de.butzlabben.world.config.*;
import de.butzlabben.world.event.WorldCreateEvent;
import de.butzlabben.world.event.WorldLoadEvent;
import de.butzlabben.world.event.WorldUnloadEvent;
import org.apache.commons.io.FileUtils;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.GameMode;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import com.google.common.base.Preconditions;
import de.butzlabben.world.WorldSystem;
import de.butzlabben.world.config.DependenceConfig;
import de.butzlabben.world.config.MessageConfig;
import de.butzlabben.world.config.PluginConfig;
import de.butzlabben.world.config.SettingsConfig;
import de.butzlabben.world.config.WorldConfig;
import de.butzlabben.world.event.WorldCreateEvent;
import de.butzlabben.world.event.WorldLoadEvent;
import de.butzlabben.world.event.WorldUnloadEvent;
/**
* This class represents a systemworld, loaded or not
*
@ -34,399 +23,404 @@ import de.butzlabben.world.event.WorldUnloadEvent;
*/
public class SystemWorld {
private World w;
private String worldname;
private boolean unloading = false;
private boolean creating = false;
private World w;
private String worldname;
private boolean unloading = false;
private boolean creating = false;
private static HashMap<String, SystemWorld> cached = new HashMap<>();
private static HashMap<String, SystemWorld> cached = new HashMap<>();
/**
* This method is the online way to get a system world instance
*
* @param worldname as in minecraft
* @return a systemworld instance if it is a systemworld or null if is not a
* systemworld
* @exception NullPointerException worldname == null
*/
public static SystemWorld getSystemWorld(String worldname) {
Preconditions.checkNotNull(worldname, "worldname must not be null");
if (cached.containsKey(worldname))
return cached.get(worldname);
SystemWorld sw = new SystemWorld(worldname);
if (sw != null && sw.exists()) {
cached.put(worldname, sw);
return sw;
}
return null;
}
/**
* This method is the online way to get a system world instance
*
* @param worldname as in minecraft
* @return a systemworld instance if it is a systemworld or null if is not a
* systemworld
* @throws NullPointerException worldname == null
*/
public static SystemWorld getSystemWorld(String worldname) {
Preconditions.checkNotNull(worldname, "worldname must not be null");
if (cached.containsKey(worldname))
return cached.get(worldname);
SystemWorld sw = new SystemWorld(worldname);
if (sw != null && sw.exists()) {
cached.put(worldname, sw);
return sw;
}
return null;
}
/**
* @param w a world in bukkit, no matter if systemworld or not Trys to unload a
* systemworld later, with the given delay in the config
*/
public static void tryUnloadLater(World w) {
if (w != null)
Bukkit.getScheduler().runTaskLater(WorldSystem.getInstance(), () -> {
if (w.getPlayers().size() == 0) {
SystemWorld sw = SystemWorld.getSystemWorld(w.getName());
if (sw != null && sw.isLoaded())
sw.unloadLater(w);
}
}, 20);
}
/**
* @param w a world in bukkit, no matter if systemworld or not Trys to unload a
* systemworld later, with the given delay in the config
*/
public static void tryUnloadLater(World w) {
if (w != null)
Bukkit.getScheduler().runTaskLater(WorldSystem.getInstance(), () -> {
if (w.getPlayers().size() == 0) {
SystemWorld sw = SystemWorld.getSystemWorld(w.getName());
if (sw != null && sw.isLoaded())
sw.unloadLater(w);
}
}, 20);
}
private SystemWorld(String worldname) {
this.worldname = worldname;
w = Bukkit.getWorld(worldname);
}
private SystemWorld(String worldname) {
this.worldname = worldname;
w = Bukkit.getWorld(worldname);
}
/**
* Trys to force-unload this world
*
* @param w associated world
* @exception NullPointerException w == null
*/
public void directUnload(World w) {
if (!Bukkit.isPrimaryThread()) {
Bukkit.getScheduler().runTask(WorldSystem.getInstance(), () -> {
directUnload(w);
});
return;
}
Preconditions.checkNotNull(w, "world must not be null");
unloading = true;
w.save();
Chunk[] arrayOfChunk;
int j = (arrayOfChunk = w.getLoadedChunks()).length;
for (int i = 0; i < j; i++) {
Chunk c = arrayOfChunk[i];
c.unload();
}
for (Player a : w.getPlayers()) {
a.teleport(PluginConfig.getSpawn());
a.setGameMode(PluginConfig.getSpawnGamemode());
}
if (unloading) {
if (Bukkit.unloadWorld(w, true)) {
File worldinserver = new File(Bukkit.getWorldContainer(), worldname);
File worlddir = new File(PluginConfig.getWorlddir());
try {
FileUtils.moveDirectoryToDirectory(worldinserver, worlddir, false);
Bukkit.getWorlds().remove(w);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
/**
* Trys to force-unload this world
*
* @param w associated world
* @throws NullPointerException w == null
*/
public void directUnload(World w) {
if (!Bukkit.isPrimaryThread()) {
Bukkit.getScheduler().runTask(WorldSystem.getInstance(), () -> {
directUnload(w);
});
return;
}
Preconditions.checkNotNull(w, "world must not be null");
unloading = true;
w.save();
Chunk[] arrayOfChunk;
int j = (arrayOfChunk = w.getLoadedChunks()).length;
for (int i = 0; i < j; i++) {
Chunk c = arrayOfChunk[i];
c.unload();
}
for (Player a : w.getPlayers()) {
a.teleport(PluginConfig.getSpawn());
a.setGameMode(PluginConfig.getSpawnGamemode());
}
if (unloading) {
if (Bukkit.unloadWorld(w, true)) {
File worldinserver = new File(Bukkit.getWorldContainer(), worldname);
File worlddir = new File(PluginConfig.getWorlddir());
try {
FileUtils.moveDirectoryToDirectory(worldinserver, worlddir, false);
Bukkit.getWorlds().remove(w);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
/**
* Trys to unload this world later, with the given delay in the config
*
* @param w the associated world
* @exception NullPointerException w == null
*/
public void unloadLater(World w) {
if (!Bukkit.isPrimaryThread()) {
Bukkit.getScheduler().runTask(WorldSystem.getInstance(), () -> {
unloadLater(w);
});
return;
}
Preconditions.checkNotNull(w, "world must not be null");
WorldUnloadEvent event = new WorldUnloadEvent(this);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return;
// Set unloading to true
unloading = true;
w.save();
Chunk[] arrayOfChunk;
int j = (arrayOfChunk = w.getLoadedChunks()).length;
for (int i = 0; i < j; i++) {
Chunk c = arrayOfChunk[i];
c.unload();
}
for (Player a : w.getPlayers()) {
a.teleport(PluginConfig.getSpawn());
a.setGameMode(PluginConfig.getSpawnGamemode());
}
/**
* Trys to unload this world later, with the given delay in the config
*
* @param w the associated world
* @throws NullPointerException w == null
*/
public void unloadLater(World w) {
if (!Bukkit.isPrimaryThread()) {
Bukkit.getScheduler().runTask(WorldSystem.getInstance(), () -> {
unloadLater(w);
});
return;
}
Preconditions.checkNotNull(w, "world must not be null");
WorldUnloadEvent event = new WorldUnloadEvent(this);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return;
// Set unloading to true
unloading = true;
w.save();
Chunk[] arrayOfChunk;
int j = (arrayOfChunk = w.getLoadedChunks()).length;
for (int i = 0; i < j; i++) {
Chunk c = arrayOfChunk[i];
c.unload();
}
for (Player a : w.getPlayers()) {
a.teleport(PluginConfig.getSpawn());
a.setGameMode(PluginConfig.getSpawnGamemode());
}
Bukkit.getScheduler().runTaskLater(WorldSystem.getInstance(), new Runnable() {
@Override
public void run() {
// Still in world unloading process?
if (unloading && w.getPlayers().size() == 0) {
if (Bukkit.unloadWorld(w, true)) {
File worldinserver = new File(Bukkit.getWorldContainer(), worldname);
File worlddir = new File(PluginConfig.getWorlddir());
try {
FileUtils.moveDirectoryToDirectory(worldinserver, worlddir, false);
Bukkit.getWorlds().remove(w);
unloading = false;
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}, 20 * PluginConfig.getUnloadingTime());
}
Bukkit.getScheduler().runTaskLater(WorldSystem.getInstance(), new Runnable() {
@Override
public void run() {
// Still in world unloading process?
if (unloading && w.getPlayers().size() == 0) {
if (Bukkit.unloadWorld(w, true)) {
File worldinserver = new File(Bukkit.getWorldContainer(), worldname);
File worlddir = new File(PluginConfig.getWorlddir());
try {
FileUtils.moveDirectoryToDirectory(worldinserver, worlddir, false);
Bukkit.getWorlds().remove(w);
unloading = false;
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}, 20 * PluginConfig.getUnloadingTime());
}
/**
* Trys to load this world, and messages the player about the process
*
* @param p the player to teleport on the world
* @exception NullPointerException if p is null
* @exception IllegalArgumentException if player is not online
*/
public void load(Player p) {
if (!Bukkit.isPrimaryThread()) {
Bukkit.getScheduler().runTask(WorldSystem.getInstance(), () -> {
load(p);
});
return;
}
Preconditions.checkNotNull(p, "player must not be null");
Preconditions.checkArgument(p.isOnline(), "player must be online");
/**
* Trys to load this world, and messages the player about the process
*
* @param p the player to teleport on the world
* @throws NullPointerException if p is null
* @throws IllegalArgumentException if player is not online
*/
public void load(Player p) {
if (!Bukkit.isPrimaryThread()) {
Bukkit.getScheduler().runTask(WorldSystem.getInstance(), () -> {
load(p);
});
return;
}
Preconditions.checkNotNull(p, "player must not be null");
Preconditions.checkArgument(p.isOnline(), "player must be online");
if (creating) {
p.sendMessage(MessageConfig.getWorldStillCreating());
return;
}
if (creating) {
p.sendMessage(MessageConfig.getWorldStillCreating());
return;
}
WorldLoadEvent event = new WorldLoadEvent(p, this);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return;
WorldLoadEvent event = new WorldLoadEvent(p, this);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return;
unloading = false;
unloading = false;
p.sendMessage(MessageConfig.getSettingUpWorld());
p.sendMessage(MessageConfig.getSettingUpWorld());
// Move World into Server dir
String worlddir = PluginConfig.getWorlddir();
File world = new File(worlddir + "/" + worldname);
if (!world.exists()) {
world = new File(Bukkit.getWorldContainer(), worldname);
} else {
if (new File(Bukkit.getWorldContainer(), worldname).exists()
&& new File(PluginConfig.getWorlddir() + "/" + worldname).exists()) {
System.err.println("World " + worldname + " exists twice!");
// try {
// FileUtils.deleteDirectory(new
// File(Bukkit.getWorldContainer(), worldname));
// } catch (IOException e) {
// p.sendMessage(PluginConfig.getPrefix() + "§cError");
// e.printStackTrace();
// }
}
try {
FileUtils.moveDirectoryToDirectory(world, Bukkit.getWorldContainer(), false);
} catch (IOException e) {
System.err.println("Couldn't load world of " + p.getName());
p.sendMessage(PluginConfig.getPrefix() + "§cError: " + e.getMessage());
e.printStackTrace();
}
}
// Move World into Server dir
String worlddir = PluginConfig.getWorlddir();
File world = new File(worlddir + "/" + worldname);
if (!world.exists()) {
world = new File(Bukkit.getWorldContainer(), worldname);
} else {
if (new File(Bukkit.getWorldContainer(), worldname).exists()
&& new File(PluginConfig.getWorlddir() + "/" + worldname).exists()) {
System.err.println("World " + worldname + " exists twice!");
// try {
// FileUtils.deleteDirectory(new
// File(Bukkit.getWorldContainer(), worldname));
// } catch (IOException e) {
// p.sendMessage(PluginConfig.getPrefix() + "§cError");
// e.printStackTrace();
// }
}
try {
FileUtils.moveDirectoryToDirectory(world, Bukkit.getWorldContainer(), false);
} catch (IOException e) {
System.err.println("Couldn't load world of " + p.getName());
p.sendMessage(PluginConfig.getPrefix() + "§cError: " + e.getMessage());
e.printStackTrace();
}
}
if (worldname.charAt(worldname.length() - 37) == ' ') {
StringBuilder myName = new StringBuilder(worldname);
myName.setCharAt(worldname.length() - 37, '-');
world.renameTo(new File(Bukkit.getWorldContainer(), myName.toString()));
worldname = myName.toString();
}
if (worldname.charAt(worldname.length() - 37) == ' ') {
StringBuilder myName = new StringBuilder(worldname);
myName.setCharAt(worldname.length() - 37, '-');
world.renameTo(new File(Bukkit.getWorldContainer(), myName.toString()));
worldname = myName.toString();
}
WorldCreator creator = PluginConfig.getWorldCreator(worldname);
WorldCreator creator = PluginConfig.getWorldCreator(worldname);
World w = Bukkit.getWorld(worldname);
if (w == null)
w = Bukkit.createWorld(creator);
World w = Bukkit.getWorld(worldname);
if (w == null)
w = Bukkit.createWorld(creator);
this.w = w;
this.w = w;
teleportToWorldSpawn(p);
teleportToWorldSpawn(p);
OfflinePlayer owner = Bukkit.getOfflinePlayer(WorldConfig.getWorldConfig(worldname).getOwner());
DependenceConfig dc = new DependenceConfig(owner);
dc.setLastLoaded();
}
OfflinePlayer owner = Bukkit.getOfflinePlayer(WorldConfig.getWorldConfig(worldname).getOwner());
DependenceConfig dc = new DependenceConfig(owner);
dc.setLastLoaded();
}
/**
* Trys to create a new systemworld with all entries etc. finally loads the
* world
*
* @param p Player to create the world for
* @return whether it succesfull or not
*/
public static boolean create(Player p, WorldTemplate template) {
/**
* Trys to create a new systemworld with all entries etc. finally loads the
* world
*
* @param p Player to create the world for
* @return whether it succesfull or not
*/
public static boolean create(Player p, WorldTemplate template) {
DependenceConfig dc = new DependenceConfig(p);
DependenceConfig dc = new DependenceConfig(p);
String uuid = p.getUniqueId().toString();
int id = DependenceConfig.getHighestID() + 1;
String worldname = "ID" + id + "-" + uuid;
String uuid = p.getUniqueId().toString();
int id = DependenceConfig.getHighestID() + 1;
String worldname = "ID" + id + "-" + uuid;
WorldCreator creator = PluginConfig.getWorldCreator(worldname);
WorldCreator creator = PluginConfig.getWorldCreator(worldname);
WorldCreateEvent event = new WorldCreateEvent(p, creator);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return false;
WorldCreateEvent event = new WorldCreateEvent(p, creator);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return false;
dc.createNewEntry();
dc.createNewEntry();
String worlddir = PluginConfig.getWorlddir();
File exampleworld = new File(template.getPath());
if (new File(template.getPath() + "/uid.dat").exists()) {
new File(template.getPath() + "/uid.dat").delete();
}
String worlddir = PluginConfig.getWorlddir();
File exampleworld = new File(template.getPath());
if (new File(template.getPath() + "/uid.dat").exists()) {
new File(template.getPath() + "/uid.dat").delete();
}
File newworld = new File(worlddir + "/" + worldname);
File newworld = new File(worlddir + "/" + worldname);
if (exampleworld.isDirectory())
try {
FileUtils.copyDirectory(exampleworld, newworld);
} catch (IOException e) {
System.err.println("Couldn't create world for " + p.getName());
e.printStackTrace();
}
else
newworld.mkdirs();
if (exampleworld.isDirectory())
try {
FileUtils.copyDirectory(exampleworld, newworld);
} catch (IOException e) {
System.err.println("Couldn't create world for " + p.getName());
e.printStackTrace();
}
else
newworld.mkdirs();
WorldConfig.create(p);
WorldConfig.create(p);
// Move World into Server dir
File world = new File(worlddir + "/" + worldname);
if (!world.exists()) {
world = new File(Bukkit.getWorldContainer(), worldname);
} else {
if (new File(Bukkit.getWorldContainer(), worldname).exists()
&& new File(PluginConfig.getWorlddir() + "/" + worldname).exists()) {
try {
FileUtils.deleteDirectory(new File(Bukkit.getWorldContainer(), worldname));
} catch (IOException e) {
e.printStackTrace();
}
}
try {
FileUtils.moveDirectoryToDirectory(world, Bukkit.getWorldContainer(), false);
} catch (IOException e) {
p.sendMessage(PluginConfig.getPrefix() + "§cError: " + e.getMessage());
System.err.println("Couldn't load world of " + p.getName());
e.printStackTrace();
return false;
}
}
// Move World into Server dir
File world = new File(worlddir + "/" + worldname);
if (!world.exists()) {
world = new File(Bukkit.getWorldContainer(), worldname);
} else {
if (new File(Bukkit.getWorldContainer(), worldname).exists()
&& new File(PluginConfig.getWorlddir() + "/" + worldname).exists()) {
try {
FileUtils.deleteDirectory(new File(Bukkit.getWorldContainer(), worldname));
} catch (IOException e) {
e.printStackTrace();
}
}
try {
FileUtils.moveDirectoryToDirectory(world, Bukkit.getWorldContainer(), false);
} catch (IOException e) {
p.sendMessage(PluginConfig.getPrefix() + "§cError: " + e.getMessage());
System.err.println("Couldn't load world of " + p.getName());
e.printStackTrace();
return false;
}
}
SystemWorld sw = SystemWorld.getSystemWorld(worldname);
sw.setCreating(true);
SystemWorld sw = SystemWorld.getSystemWorld(worldname);
sw.setCreating(true);
// Run in scheduler so method returns without delay
new BukkitRunnable() {
@Override
public void run() {
// For #16
WorldSystem.getInstance().getAdapter().create(event.getWorldCreator(), sw, () -> {
if (p != null && p.isOnline()) {
p.sendMessage(MessageConfig.getWorldCreated());
SettingsConfig.getCommandsonGet().stream()
.map(s -> s.replace("%player", p.getName()).replace("%world", sw.getName())
.replace("%uuid", p.getUniqueId().toString()))
.forEach(s -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), s));
}
});
}
}.runTaskLater(WorldSystem.getInstance(), 1);
// Run in scheduler so method returns without delay
new BukkitRunnable() {
@Override
public void run() {
WorldSystem.getInstance().getAdapter().create(event.getWorldCreator(), sw, () -> {
// Fix for #16
new BukkitRunnable() {
@Override
public void run() {
if (p != null && p.isOnline()) {
p.sendMessage(MessageConfig.getWorldCreated());
SettingsConfig.getCommandsonGet().stream()
.map(s -> s.replace("%player", p.getName()).replace("%world", sw.getName())
.replace("%uuid", p.getUniqueId().toString()))
.forEach(s -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), s));
}
}
}.runTask(WorldSystem.getInstance());
});
}
}.runTaskLater(WorldSystem.getInstance(), 1);
return true;
}
return true;
}
/**
* @return if the world is loaded
*/
public boolean isLoaded() {
File worldAsDir = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml");
World w = Bukkit.getWorld(worldname);
if (worldAsDir.exists() && w != null)
return true;
return false;
}
/**
* @return if the world is loaded
*/
public boolean isLoaded() {
File worldAsDir = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml");
World w = Bukkit.getWorld(worldname);
if (worldAsDir.exists() && w != null)
return true;
return false;
}
private boolean exists() {
File worldAsDir = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml");
if (worldAsDir.exists()) {
return true;
}
worldAsDir = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml");
if (worldAsDir.exists()) {
return true;
}
return false;
}
private boolean exists() {
File worldAsDir = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml");
if (worldAsDir.exists()) {
return true;
}
worldAsDir = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml");
if (worldAsDir.exists()) {
return true;
}
return false;
}
/**
* Teleports the player to the world with the given settings in the config
*
* @param p player to teleport
* @exception NullPointerException if player is null
* @exception IllegalArgumentException if player is not online
*/
public void teleportToWorldSpawn(Player p) {
Preconditions.checkNotNull(p, "player must not be null");
Preconditions.checkArgument(p.isOnline(), "player must be online");
/**
* Teleports the player to the world with the given settings in the config
*
* @param p player to teleport
* @throws NullPointerException if player is null
* @throws IllegalArgumentException if player is not online
*/
public void teleportToWorldSpawn(Player p) {
Preconditions.checkNotNull(p, "player must not be null");
Preconditions.checkArgument(p.isOnline(), "player must be online");
if (creating) {
p.sendMessage(MessageConfig.getWorldStillCreating());
return;
}
if (creating) {
p.sendMessage(MessageConfig.getWorldStillCreating());
return;
}
unloading = false;
w = Bukkit.getWorld(worldname);
if (w == null)
return;
unloading = false;
w = Bukkit.getWorld(worldname);
if (w == null)
return;
WorldConfig config = WorldConfig.getWorldConfig(worldname);
if (config.getHome() != null) {
p.teleport(config.getHome());
} else {
if (PluginConfig.useWorldSpawn()) {
p.teleport(PluginConfig.getWorldSpawn(w));
} else {
p.teleport(w.getSpawnLocation());
}
}
if (PluginConfig.isSurvival()) {
p.setGameMode(GameMode.SURVIVAL);
} else {
p.setGameMode(GameMode.CREATIVE);
}
WorldConfig config = WorldConfig.getWorldConfig(worldname);
if (config.getHome() != null) {
p.teleport(config.getHome());
} else {
if (PluginConfig.useWorldSpawn()) {
p.teleport(PluginConfig.getWorldSpawn(w));
} else {
p.teleport(w.getSpawnLocation());
}
}
if (PluginConfig.isSurvival()) {
p.setGameMode(GameMode.SURVIVAL);
} else {
p.setGameMode(GameMode.CREATIVE);
}
OfflinePlayer owner = Bukkit.getOfflinePlayer(WorldConfig.getWorldConfig(worldname).getOwner());
DependenceConfig dc = new DependenceConfig(owner);
dc.setLastLoaded();
}
OfflinePlayer owner = Bukkit.getOfflinePlayer(WorldConfig.getWorldConfig(worldname).getOwner());
DependenceConfig dc = new DependenceConfig(owner);
dc.setLastLoaded();
}
/**
* @return the world
*/
public World getWorld() {
return w;
}
/**
* @return the world
*/
public World getWorld() {
return w;
}
public void setCreating(boolean creating) {
this.creating = creating;
}
public void setCreating(boolean creating) {
this.creating = creating;
}
public boolean isCreating() {
return creating;
}
public boolean isCreating() {
return creating;
}
/**
* @return the worldname
*/
public String getName() {
return worldname;
}
/**
* @return the worldname
*/
public String getName() {
return worldname;
}
}

View File

@ -293,7 +293,7 @@ worldchoose:
slot:
row: 2
col: 7
material: STONE_BLOCK
material: STONE
display: '&aAnother template'

View File

@ -1,21 +0,0 @@
package de.butzlabben.autoupdater.test;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import de.butzlabben.autoupdater.UpdateInformations;
/**
* @author Butzlabben
* @since 03.09.2018
*/
public class UpdateInformationsTest {
private final String url = "https://seagiants.eu/worldsystem/info.php?version=1.0";
@Test
public void testCallURL() {
assertNotNull("Failed to call URL to AutoUpdate Server", UpdateInformations.callURL(url));
}
}