Last active
August 29, 2015 14:07
-
-
Save keepoff07/1c0da3f77eddc6f17251 to your computer and use it in GitHub Desktop.
[Bukkit] DefWorld: get DefaultWorld
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.util.Properties; | |
import org.bukkit.Bukkit; | |
import org.bukkit.World; | |
import org.bukkit.plugin.java.JavaPlugin; | |
public class DefWorld { | |
public static World defworld = null; | |
public static void defaultWorld(JavaPlugin plugin){ | |
try { | |
Properties configuration = new Properties(); | |
String AbsolutePath = plugin.getDataFolder().getAbsolutePath(); | |
String parentPath = plugin.getDataFolder().toString(); | |
String filePath = AbsolutePath.replace(parentPath, "server.properties"); | |
File file = new File(filePath); | |
InputStream inputStream = new FileInputStream(file); | |
configuration.load(inputStream); | |
String level = configuration.getProperty("level-name"); | |
World w = Bukkit.getWorld(level); | |
if(w != null) { | |
defworld = w; | |
return; | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
World w = Bukkit.getWorlds().get(0); | |
defworld = w; | |
return; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.bukkit.plugin.java.JavaPlugin; | |
public class Main extends JavaPlugin{ | |
public void onEnable(){ | |
//get&set DefaultWorld | |
DefWorld.defaultWorld(this); | |
} | |
public void onDisable() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment