Broadcast isn't working

Discussion in 'Plugin Development' started by LinkterSHD, Feb 10, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    LinkterSHD

    I have been trying to maek a plugin but i dont know what is wrong. Can some one help me:
    Code:
    package me.senators24.Broadcast;
     
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.LineNumberReader;
    import java.util.logging.Logger;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Broadcast extends JavaPlugin {
        public static Broadcast plugin;
        public final Logger logger = Logger.getLogger("Minecraft");
        public static int currentLine = 0;
        public static int tid = 0;
        public static int running = 1;
        public static long interval = 10;
       
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + "version" + pdfFile.getVersion() + "is now disabled.");
        }
       
        @Override
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + "version" + pdfFile.getVersion() + "is now enabled. Enjoy the Plugin.");
           
            tid = Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                public void run() {
                    try {
                        broadcastMessages("plugins/Broadcast/messages.yml");
                    } catch (IOException e) {
                       
                    }
                }
            }, 0, interval * 20);
        }
       
        public static void broadcastMessage(String fileName) throws IOException {
            FileInputStream fs;
            fs = new FileInputStream(fileName);
            BufferedReader br = new BufferedReader(new InputStreamReader(fs));
            for(int i = 0; i < currentLine; ++i)
                br.readLine();
            String line = br.readLine();
            line = line.replaceAll("&f", ChatColor.WHITE + "");
            line = line.replaceAll("&e", ChatColor.YELLOW + "");
            line = line.replaceAll("&d", ChatColor.LIGHT_PURPLE + "");
            line = line.replaceAll("&a", ChatColor.GREEN + "");
            line = line.replaceAll("&c", ChatColor.RED + "");
            Bukkit.getServer().broadcastMessage(ChatColor.RED + "[Broadcaster]" + ChatColor.WHITE + line);
            LineNumberReader lnr = new LineNumberReader(new FileReader(new File(fileName)));
            lnr.skip(Long.MAX_VALUE);
            int lastLine = lnr.getLineNumber();
            if(currentLine + 1 == lastLine + 1) {
                currentLine = 0;
            } else {
                currentLine++;
            }
               
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if(commandLabel.equalsIgnoreCase("bcoff")) {
                if(running == 1) {
                    Bukkit.getServer().getScheduler().cancelTask(tid);
                    Player player = (Player) sender;
                    player.sendMessage("You have cancelled the broadcast.");
                    running = 0;
                } else {
                    Player player = (Player) sender;
                    player.sendMessage("Broadcaster isn't running!");
                }
            } else if (commandLabel.equalsIgnoreCase("bcon")) {
                if(running ==1) {
                    Player player = (Player) sender;
                    player.sendMessage("Broadcaster is still running!");
                } else {
                    tid = Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                        public void run() {
                            try {
                                broadcastMessages("plugins/Broadcast/messages.yml");
                            } catch (IOException e) {
                               
                            }
                        }
                    }, 0, interval * 20);
                    Player player = (Player) sender;
                    Player.sendMessage("You have started broadcaster.");
                    running = 1;
                   
                }
            }
            return false;
        }
       
    }
    And when i load it up on Bukkit it says this:
    Code:
    06:05:06 [WARNING] Task of 'Broadcaster' generated an exception
    java.lang.Error: Unresolved compilation problem:
            The method broadcastMessages(String) is undefined for the type new Runna
    ble(){}
     
            at me.senators24.Broadcast.Broadcast$1.run(Broadcast.java:42)
            at org.bukkit.craftbukkit.scheduler.CraftScheduler.mainThreadHeartbeat(C
    raftScheduler.java:137)
            at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:503)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:435)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:465)
     
  2. Offline

    Atomic Fusion

    First of all, you have a singular method name and call it with a plural:
    Code:
    public static void broadcastMessage(String fileName) throws IOException {
    Code:
    broadcastMessages("plugins/Broadcast/messages.yml");
    Also, your onDisable doesn't actually disable anything.
     
    Senators24 likes this.
  3. Offline

    LinkterSHD

    Thanks, also i know my ondisable doesnt do anything

    UR THE BEST IT WORKS

    Something is still wrong, can you fix it here is my project file:
    http://dl.dropbox.com/u/59873863/BroadCast.rar

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
  4. Offline

    Atomic Fusion

    Was your issue with this?
    Code:
    Player.sendMessage("You have started broadcaster.");
    If so, try this:
    Code:
    player.sendMessage("You have started broadcaster.");
    As in, lowercase p in player, because in your previous line you named it "player", lowercase.
    That's the only issue that I saw.
     
  5. Offline

    LinkterSHD

    ok ty

    The only problem it isnt creating a folder

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
  6. Offline

    Atomic Fusion

    Why is it supposed to? Your plugin doesn't appear to ever write messages.yml, so I would imagine that it's the user's job to create the folder.
    Also, I would recommend not naming it messages.yml, as it does not appear to be a YAML file.
     
  7. Offline

    LinkterSHD

    ok also what code should i add to it so it creates a folder and .yml or .txt file

    Your suppose to edit the message and color prefixes like it says here:
    Code:
    public static void broadcastMessages(String fileName) throws IOException {
            FileInputStream fs;
            fs = new FileInputStream(fileName);
            BufferedReader br = new BufferedReader(new InputStreamReader(fs));
            for(int i = 0; i < currentLine; ++i)
                br.readLine();
            String line = br.readLine();
            line = line.replaceAll("&f", ChatColor.WHITE + "");
            line = line.replaceAll("&e", ChatColor.YELLOW + "");
            line = line.replaceAll("&d", ChatColor.LIGHT_PURPLE + "");
            line = line.replaceAll("&a", ChatColor.GREEN + "");
            line = line.replaceAll("&c", ChatColor.RED + "");
            Bukkit.getServer().broadcastMessage(ChatColor.RED + "[Broadcaster]" + ChatColor.WHITE + line);
            LineNumberReader lnr = new LineNumberReader(new FileReader(new File(fileName)));
            lnr.skip(Long.MAX_VALUE);
            int lastLine = lnr.getLineNumber();
            if(currentLine + 1 == lastLine + 1) {
                currentLine = 0;
            } else {
                currentLine++;
            }
               
        }
    do you think you can do it by scratch or at least edit it so it works

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
  8. Offline

    Atomic Fusion

    I would go with txt.
    Code:
    File directory = new File("plugins/Broadcast");
    directory.mkdir()
    Ought to create the directory "plugins/Broadcast", but I don't know why would would want to do that or where in your code it would go. Maybe in onEnable.
     
  9. Offline

    LinkterSHD

    what line would i paste it on?
     
  10. Offline

    Atomic Fusion

    Depends on when you want it to be created. If you must do this, I would place it at the end of onEnable().
     
  11. Offline

    LinkterSHD

    Can you edit the whol plugin for me here is the latest project file:
    http://dl.dropbox.com/u/59873863/BroadCast.zip
    Would be very appreciated
     
  12. Offline

    Atomic Fusion

    Could you lay out exactly what you want me to do?
    Do you want it to create the directory "plugins/Broadcast" when it is enabled?
     
  13. Offline

    LinkterSHD

    Can you edit the whol plugin for me here is the latest project file:
    http://dl.dropbox.com/u/59873863/BroadCast.zip
    Would be very appreciated
     
  14. Offline

    LinkterSHD

  15. Offline

    ArcheCane

    You're not going to learn java that way, ask for some more help with coding, but most developers won't go editing it.
     
  16. Offline

    Dexeron

    Hey, Im guessing you used that YouTube tut on Broadcaster, It didn't work for me.

    Just try other Ideas and Build your knowledge as you go. That Broadcaster tut is a bit too old and dodgy if you ask me
     
  17. Offline

    ferrybig

    not
    Code:text
    1. File directory = new File("plugins/Broadcast");
    2. directory.mkdir()

    but
    Code:text
    1. File directory = this.getDataFolder();
    2. directory.mkdir()

    incase bukkit team desides to chance the name of the plugin folder to addons, or an user configures this at the bukkit.yml.
     
  18. Offline

    thedeadlybutter

    Im sorry but Senators24, your basically telling people to remake your plugin. Everyone here basically did write it for you & its's obvious you do not know java. Instead of having us do your work, do yourself a favor and learn something that could help you and stick with you for life and maybe a career (Referring to java).
     
  19. Offline

    LinkterSHD

    I know i dont know java. I was just asking people to clean my code as their is some faulty code some where. And yes i dont know any Java im trying to learn how to program

    Ok thank you so much. Will try this when i get home

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
  20. Offline

    thedeadlybutter


    It's easier to start off simple. Just make simple programs with command prompt. learning java by starting with bukkit isn't the best idea, mainly because your learning the language and the API. Bukkit & Minecraft isn't going anywhere, take your time and do it right.
     
  21. Offline

    LinkterSHD

    Anygood tutorials out their then
     
  22. Offline

    Mr_H4mm3r

    Look at TheNewBoston on Youtube :) He is very easy to understand.
     
  23. Offline

    LinkterSHD

    Ok but is it based on Bukkit API or java in general
     
  24. Offline

    SirTyler

    Learn Java then learn Bukkit API. NewBoston tutorials are Java in general and that is where you should start.
     
  25. Offline

    LinkterSHD

    Ok i will. During the holidays im gonna go in a Java tutorial mod frenzy
     
  26. Offline

    AmoebaMan

    It's sort of odd that your compiler didn't catch a syntax error like that...

    Also, are you using Eclipse? If you're not, you really should. It'll prevent you from making silly typos like that.
     
  27. Offline

    LinkterSHD

    I am using Eclipse and i havent worked on it lately so i will fix all bugs later
     
Thread Status:
Not open for further replies.

Share This Page