Hey guys! After about 30 minutes of researching, I came up with this lil' snippet of code that you can use to return text from a .txt file (from a website, not your computer). You could use this to send players the server news, display the rules on a sign, whatever you want! It's not much, but I thought it was pretty cool, so I decided I'd share it with everybody: Code:Java // Put this inside a method or a command:try { // (Something could go wrong) URL news = new URL("[url]http://yourdomain.com/file.txt[/url]");BufferedReader in = new BufferedReader(new InputStreamReader(news.openStream()));String inputLine; while ((inputLine = in.readLine()) != null) { // While it still has lines to read fromplayer.sendMessage(inputLine.replace("&", "\247")); // Sends the message (with chat color support)} in.close(); // close it! } catch (Exception e) { // The file doesn't exist, it couldn't connect, etc.player.sendMessage(ChatColor.RED + "an error has occured..");e.printStackTrace();} View the direct source here. Alternate way based off of this by Goblom: https://github.com/Goblom/Bukkit-Li...in/java/org/goblom/bukkitlibs/TextReader.java
I took this a bit further and created a simpler way to do it... Code:java TextReader reader = new TextReader("[url]http://yourdomain.com/file.txt[/url]"); reader.getDocument(); Source: https://github.com/Goblom/Bukkit-Li...in/java/org/goblom/bukkitlibs/TextReader.java Code: getDocument() returns a List<String> every line is a new string in the list.
Goblom No hate intended, but how did you take this a bit further? What's the "simpler" way? You basically just used the same code, put it in a class and added a method to get the data.
Assist Simpler as in less work, I know i used same code and everything, i gave credit to Wizehh and everything. I in no way shape or form take credit for it.
Goblom Yours actually requires more work (to set up, not use). I'd have to make a new class, then paste the code in it from your GitHub. When I want to use it, I have to create a new instance of that class, and call one (or more, I didn't check if you closed the stream) of its methods. You could just put the code in a method that returns a list/array of strings, along with a parameter for the URL. Or if you're going to use the code only once, or if you don't care how good your code looks, then just place it in wherever you need it. I know this isn't much work at all, but still, creating a class for it is unnecessary Edit: Also, Wizehh , you shouldn't be posting Java tutorials here. I know, this has a potential uses in Bukkit plugins, but so does like 99% of Java methods. If someone needs this, they could just Google search it, I'm sure there's plenty of tutorials and snippets out there.
As I said before, I thought I would share it since it did take me some time to find said resource. If you don't want to use it, that's fine; however, I thought it could potentially be useful to a lot of people. If I'm not mistaken, this is the "resource" section, correct?
Correct, but as explained in this thread, And my point to you is that you made a Java tutorial which in my opinion shouldn't be posted here since this is the bukkit forums in a section related to bukkit And he's correct, this sub forum is in a "Bukkit" forum section, therefore everything posted here should have some relation to Bukkit. This is the forum for Bukkit API resources and tutorials, everything else is somewhere else. I will thank you for the utility, and the time you spent finding/creating it, but same code can be found all over the internet.
I agree with Assist. Java tutorials are better for external websites, and answers for these things can easily be found on stackoverflow or another website with a quick google search. IMO, The resources section should mainly be for bukkit related things.
Wizehh Something like this would most likely get your project rejected. Reading from external sources other than BukkitDev is against the Plugin Submission Guidelines.