You are not logged in.

  • Login

[Java] World Reseten

Bitte besucht unser neues Forum unter https://forum.nitrado.net | Please visit our new Forum at https://forum.nitrado.net

DerRuedi

User / Kunde

  • "DerRuedi" started this thread

Posts: 136

  • Send private message

1

Friday, June 19th 2015, 4:15pm

World Reseten

Hey,

ich habe mal wieder ein Problem. Und zwar möchte ich bei den stoppen es Servers eine Welt löschen und die und sie aus den Plugin Ordner wieder raus kopieren. Mir ist zwar bewusst das es schon 100 mal die Frage gibt aber ich habe keine Lösung zu mein Problem gefunden.

Error:

Spoiler Spoiler

[16:07:18] [Server thread/WARN]: [BedWars] Task #14 for BedWars v0.1 generated an exception
java.lang.NullPointerException
at de.DerRuedi.BedWars.Sonstiges.WorldManager.deleteDirectory(WorldManager.java:34) ~[?:?]
at de.DerRuedi.BedWars.Sonstiges.WorldManager.resetWorld(WorldManager.java:24) ~[?:?]
at de.DerRuedi.BedWars.Timer.BlockBreak$2.run(BlockBreak.java:71) ~[?:?]
at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(CraftTask.java:71) ~[spigot.jar:git-Spigot-3ccbe77-a6a57a9]
at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350) [spigot.jar:git-Spigot-3ccbe77-a6a57a9]
at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:726) [spigot.jar:git-Spigot-3ccbe77-a6a57a9]
at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:367) [spigot.jar:git-Spigot-3ccbe77-a6a57a9]
at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:657) [spigot.jar:git-Spigot-3ccbe77-a6a57a9]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:560) [spigot.jar:git-Spigot-3ccbe77-a6a57a9]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_25]



Code:

Spoiler Spoiler

public class WorldManager {

public static void resetWorld(String worldName) {
for (Player p : Bukkit.getOnlinePlayers()) {
p.kickPlayer("§cWelt wird zurückgesetzt!");
}
File sourceFile = new File(Main.getInstance().getDataFolder(), worldName);
Bukkit.unloadWorld(worldName, false);
try {
deleteDirectory(new File(Bukkit.getWorldContainer(), worldName));
copyDirectory(sourceFile, new File(Bukkit.getWorldContainer(), worldName));
} catch (IOException e) {
e.printStackTrace();
}
Bukkit.createWorld(new WorldCreator(worldName));
System.out.println("Die Welt wurde zurückgesetzt!");
}

public static void deleteDirectory(File ziel) {
for (File file : ziel.listFiles()) {
if (file.isDirectory()) {
deleteDirectory(file);
}
file.delete();
}
ziel.delete();
}

public static void copyDirectory(File quelle, File ziel)throws FileNotFoundException, IOException {
File[] files = quelle.listFiles();
File newFile = null;

ziel.mkdirs();
if (files != null) {
for (int i = 0; i < files.length; i++) {
newFile = new File(ziel.getAbsolutePath() + System.getProperty("file.separator") + files.getName());
if (files[i].isDirectory()) {
copyDirectory(files[i], newFile);
} else {
copyFile(files[i], newFile);
}
}
}
}

public static void copyFile(File file, File ziel)
throws FileNotFoundException, IOException {
BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(ziel, true));
int bytes = 0;
while ((bytes = in.read()) != -1) {
out.write(bytes);
}
in.close();
out.close();
}
}
[/i][/i][/i]

Hier könnte ihre Werbung stehen.


Ridh

User / Kunde

Posts: 704

Thanks: 11

  • Send private message

2

Friday, June 19th 2015, 5:26pm

Bitte füge dein Code in einen von uns lesbaren Format rein, bsp.

Source code

1
[Java] Quelltext [/Java]
Made by Paint

DerRuedi

User / Kunde

  • "DerRuedi" started this thread

Posts: 136

  • Send private message

3

Friday, June 19th 2015, 5:27pm

Bitte Closen!

Hier könnte ihre Werbung stehen.

This post has been edited 1 times, last edit by "DerRuedi" (Jun 19th 2015, 6:39pm)


Bitte besucht unser neues Forum unter https://forum.nitrado.net| Please visit our new Forum at https://forum.nitrado.net

Similar threads