Skip to content

Instantly share code, notes, and snippets.

@keepoff07
Last active August 29, 2015 14:07
Show Gist options
  • Save keepoff07/1c0da3f77eddc6f17251 to your computer and use it in GitHub Desktop.
Save keepoff07/1c0da3f77eddc6f17251 to your computer and use it in GitHub Desktop.
[Bukkit] DefWorld: get DefaultWorld
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;
}
}
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