[Add-On] News board system~

Page 2 of 4 FirstFirst 1234 LastLast
Results 16 to 30 of 49
  1. #16
    Im back! FINALLY KenoRIK10 is offline
    MemberRank
    Apr 2010 Join Date
    KonohaLocation
    366Posts

    Re: [Add-On] News board system~

    A M A Z I N G ! !

    I have not posted in RZ for a month lol and I come back this is just nice :D awesome man.


    T H A N K Y O U

  2. #17
    Alpha Member Soulfist is offline
    MemberRank
    Dec 2010 Join Date
    a hovelLocation
    1,835Posts

    Re: [Add-On] News board system~

    Quote Originally Posted by KenoRIK10 View Post
    A M A Z I N G ! !

    I have not posted in RZ for a month lol and I come back this is just nice :D awesome man.


    T H A N K Y O U

    Your enthusiasm is contagious

  3. #18
    :) iJFAC is offline
    MemberRank
    Sep 2007 Join Date
    SomewhereLocation
    519Posts

    Re: [Add-On] News board system~

    Pretty good job Sparrow.. i'm using it right now XD.. now it's easier to communicate with players :D

  4. #19
    Ooo, shiny! FateJiki is offline
    MemberRank
    Feb 2008 Join Date
    1,057Posts

    Re: [Add-On] News board system~

    This is great! Perhaps next time, you could make it reach into another table, the one that manages announcements on the website. That way, people can click on the title + date and read the content of an announcement. :P

  5. #20
    Account Upgraded | Title Enabled! redeemer34 is offline
    MemberRank
    Aug 2008 Join Date
    335Posts

    Re: [Add-On] News board system~

    I added a few things that I thought were nice. Since my server is low rate, it automatically makes an News post about it. Same with defeating horntail.
    I also had it make a server wide announcement whenever there is a new News post.

    EDIT: 300TH POST OH YEAH BIZNOTCH!!!! :D

    Oh and 69 likes. ;)

  6. #21
    Alpha Member Soulfist is offline
    MemberRank
    Dec 2010 Join Date
    a hovelLocation
    1,835Posts

    Re: [Add-On] News board system~

    Quote Originally Posted by redeemer34 View Post
    I added a few things that I thought were nice. Since my server is low rate, it automatically makes an News post about it. Same with defeating horntail.
    I also had it make a server wide announcement whenever there is a new News post.

    EDIT: 300TH POST OH YEAH BIZNOTCH!!!! :D

    Oh and 69 likes. ;)

    EDIT: 1'186TH POST OH YEAH BIZNOTCH!!!! :D

    Oh and 114 likes. ;)

  7. #22
    Account Upgraded | Title Enabled! redeemer34 is offline
    MemberRank
    Aug 2008 Join Date
    335Posts

    Re: [Add-On] News board system~

    Quote Originally Posted by Soulfist View Post
    EDIT: 1'186TH POST OH YEAH BIZNOTCH!!!! :D

    Oh and 114 likes. ;)
    :P Lmao. My number is more special.

    On-Topic: You might wanna expand the amount of characters able to be used in News in the SQL

  8. #23
    Gamma Sparrow is offline
    MemberRank
    Mar 2009 Join Date
    SydneyLocation
    2,960Posts

    Re: [Add-On] News board system~

    Quote Originally Posted by redeemer34 View Post
    :P Lmao. My number is more special.

    On-Topic: You might wanna expand the amount of characters able to be used in News in the SQL
    Yeah, I realized that while trying to make an announcement.

    Btw guys, you can use colours and tabs in the command as well. Eg, !news Title #bHey guys, added NPCs in FM.#k\r\ n Second lot of text.

  9. #24
    Account Upgraded | Title Enabled! Spiderman is offline
    MemberRank
    Feb 2010 Join Date
    417Posts

    Re: [Add-On] News board system~

    Quote Originally Posted by redeemer34 View Post
    :P Lmao. My number is more special.

    On-Topic: You might wanna expand the amount of characters able to be used in News in the SQL
    I liked your post, now your amount of likes isn't your favorite position anymore :(

  10. #25
    Account Upgraded | Title Enabled! redeemer34 is offline
    MemberRank
    Aug 2008 Join Date
    335Posts

    Re: [Add-On] News board system~

    Quote Originally Posted by Prio View Post
    I liked your post, now your amount of likes isn't your favorite position anymore :(
    :(( Thanks. Sort of. Oh well. 70 is an okay number too. haha.

  11. #26
    :) RpViet is offline
    MemberRank
    Jun 2008 Join Date
    356Posts

    Re: [Add-On] News board system~

    Quote Originally Posted by AuroX View Post
    Yea, you didn't close the statements. Also, I suggest you to cache them all and only reload it whenever a news has been added. If you didn't do so and your server has huge amount of players, and if players spam click that NPC, you'll have huge loads on your database.

    EDIT* Here, Cached in a list where you load it upon startup. It will only reload it when you add or delete news. Not tested yet, but it should work.

    Command
    PHP Code:
        } else if (splitted[0].equals("!news")) { // !news <title> <message>
            
    if (splitted.length || splitted[1] == null || splitted[1].equals("") || splitted[2] == null || splitted[2].equals("")) {
               
    c.getPlayer().dropMessage(6"!news <title> <message>");
               return;
            }
            try {
                
    Connection con DatabaseConnection.getConnection();
                
    PreparedStatement ps con.prepareStatement("INSERT INTO `custom_news` (title, message, date) VALUES (?, ?, ?)");
                
    ps.setString(1splitted[1]);
                
    ps.setString(2StringUtil.joinStringFrom(splitted2));
                
    ps.setString(3KoreanDateUtil.getDate("dd/MM/yy"));
                
    ps.executeUpdate();
                
    ps.close();
                
    con.close();
                
    MapleNews.getInstance().reload();
            } catch (
    SQLException e) {
                
    c.getPlayer().dropMessage(6"[Error] Unable to save news!");
                
    System.out.println("[MapleNews] Unable to save news..." e);
            }
            
        } else if (
    splitted[0].equals("!deletenews")) { // !deletenews <id>
            
    if (splitted.length || splitted[1] == null || splitted[1].equals("")) {
                
    c.getPlayer().dropMessage(6"!deletenews <id>");
                return;
            }
            final 
    int newsID Integer.parseInt(splitted[1]);
            try {
                
    Connection con DatabaseConnection.getConnection();
                
    PreparedStatement ps con.prepareStatement("DELETE FROM `custom_news` WHERE `newsid` = ?");
                
    ps.setInt(1newsID);
                
    ps.execute();
                
    ps.close();
                
    con.close();
                
    MapleNews.getInstance().reload();
            } catch (
    SQLException e) {
                
    c.getPlayer().dropMessage(6"[Error] Unable to delete news!");
                
    System.out.println("[MapleNews] Unable to delete news..." e);
            } 
    You didn't close connections :)
    Last edited by RpViet; 18-04-11 at 07:31 PM.

  12. #27
    Account Upgraded | Title Enabled! Spiderman is offline
    MemberRank
    Feb 2010 Join Date
    417Posts

    Re: [Add-On] News board system~

    Quote Originally Posted by rpviet View Post
    you didn't close connections :)
    fail.

  13. #28
    return null; mertjuh is offline
    MemberRank
    Dec 2008 Join Date
    The NetherlandsLocation
    1,269Posts

    Re: [Add-On] News board system~

    Quote Originally Posted by RpViet View Post
    You didn't close connections :)
    You're kidding right? ...

  14. #29
    Account Upgraded | Title Enabled! Expedia is offline
    MemberRank
    Nov 2009 Join Date
    884Posts

    Re: [Add-On] News board system~

    Quote Originally Posted by AuroX View Post
    Yea, you didn't close the statements. Also, I suggest you to cache them all and only reload it whenever a news has been added. If you didn't do so and your server has huge amount of players, and if players spam click that NPC, you'll have huge loads on your database.

    EDIT* Here, Cached in a list where you load it upon startup. It will only reload it when you add or delete news. Not tested yet, but it should work.

    MapleNews.java
    PHP Code:

    package server
    ;


    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.LinkedList;
    import java.util.List;
    import util.DatabaseConnection;

    /**
     * 
     * @author AuroX
     */
    public class MapleNews {

        private static 
    MapleNews instance = new MapleNews();
        private List<
    MapleNewsInfonews = new LinkedList<MapleNewsInfo>();

        public static 
    MapleNews getInstance() {
            return 
    instance;
        }

        public List<
    MapleNewsInfogetNews() {
            if (
    news.isEmpty()) {
                
    reload();
            }
            return 
    news;
        }

        public 
    void reload() {
            
    news.clear();
            try {
                
    Connection con DatabaseConnection.getConnection();
                
    PreparedStatement ps con.prepareStatement("SELECT * FROM custom_news ORDER BY `id` DESC LIMIT 5");
                
    ResultSet rs ps.executeQuery();

                while (
    rs.next()) {
                    final 
    MapleNewsInfo rank = new MapleNewsInfo(rs.getString("title"), rs.getString("date"), rs.getString("message"));
                    
    news.add(rank);
                }
                
    ps.close();
                
    rs.close();
            } catch (
    SQLException e) {
                
    System.err.println("[MapleNews] Error retrieving data..." e);
            }
        }

        public static class 
    MapleNewsInfo {

            private 
    String titledatemessage;

            public 
    MapleNewsInfo(String titleString dateString message) {
                
    this.title title;
                
    this.date date;
                
    this.message message;
            }

            public 
    String getTitle() {
                return 
    title;
            }

            public 
    String getDate() {
                return 
    date;
            }

            public 
    String getMessage() {
                return 
    message;
            }
        }

    NPC function
    PHP Code:
    public String getCustomNews() {
            
    StringBuilder ret = new StringBuilder();
            final List<
    MapleNewsInfonews MapleNews.getInstance().getNews();
            for (
    MapleNewsInfo info news) {
                
    ret.append("\r\n#e");
                
    ret.append(info.getTitle());
                
    ret.append(" - (");
                
    ret.append(info.getDate());
                
    ret.append(")#n\r\n");
                
    ret.append(info.getMessage());
                
    ret.append("\r\n");
            }
            return 
    ret.toString();
        } 
    Command
    PHP Code:
        } else if (splitted[0].equals("!news")) { // !news <title> <message>
            
    if (splitted.length || splitted[1] == null || splitted[1].equals("") || splitted[2] == null || splitted[2].equals("")) {
               
    c.getPlayer().dropMessage(6"!news <title> <message>");
               return;
            }
            try {
                
    Connection con DatabaseConnection.getConnection();
                
    PreparedStatement ps con.prepareStatement("INSERT INTO `custom_news` (title, message, date) VALUES (?, ?, ?)");
                
    ps.setString(1splitted[1]);
                
    ps.setString(2StringUtil.joinStringFrom(splitted2));
                
    ps.setString(3KoreanDateUtil.getDate("dd/MM/yy"));
                
    ps.executeUpdate();
                
    ps.close();
                
    MapleNews.getInstance().reload();
            } catch (
    SQLException e) {
                
    c.getPlayer().dropMessage(6"[Error] Unable to save news!");
                
    System.out.println("[MapleNews] Unable to save news..." e);
            }
            
        } else if (
    splitted[0].equals("!deletenews")) { // !deletenews <id>
            
    if (splitted.length || splitted[1] == null || splitted[1].equals("")) {
                
    c.getPlayer().dropMessage(6"!deletenews <id>");
                return;
            }
            final 
    int newsID Integer.parseInt(splitted[1]);
            try {
                
    Connection con DatabaseConnection.getConnection();
                
    PreparedStatement ps con.prepareStatement("DELETE FROM `custom_news` WHERE `newsid` = ?");
                
    ps.setInt(1newsID);
                
    ps.execute();
                
    ps.close();
                
    MapleNews.getInstance().reload();
            } catch (
    SQLException e) {
                
    c.getPlayer().dropMessage(6"[Error] Unable to delete news!");
                
    System.out.println("[MapleNews] Unable to delete news..." e);
            } 
    ChannelServer add this where you load your data
    PHP Code:
    MapleNews.getInstance().getNews(); 
    NO FLAME. BUT WTF IS THIS?

    You're telling him to cache it instead of constantly preparing a query to the database, YET you're doing the same thing. The point of the cache is you get the data from the HashMap, not just waste memory and prepare a statement every mother fucking time you want to add or delete a news ... You only call to the database twice, when you load it into the HashMap (or w/e you're using)/saving it into the database when you're doing .. or force backups.

    PS: Using ps.close frees the memory, BUT STILL.
    Last edited by Expedia; 19-04-11 at 12:57 AM.

  15. #30
    Account Upgraded | Title Enabled! AuroX is offline
    MemberRank
    Sep 2008 Join Date
    1,431Posts

    Re: [Add-On] News board system~

    Quote Originally Posted by Expedia View Post
    You're telling him to cache it instead of constantly preparing a query to the database, YET you're doing the same thing. The point of the cache is you get the data from the HashMap, not just waste memory and prepare a statement every mother fucking time you want to add or delete a news ... You only call to the database twice, when you load it into the HashMap (or w/e you're using)/saving it into the database when you're doing .. or force backups.

    PS: Using ps.close frees the memory, BUT STILL.
    I guess I'll have to apologize for not explaining properly. But still, I didn't meant it to be full and its just my idea. Nothing much. But its still better than preparing a query every time someone clicks on that NPC especially when a server has huge amount of players clicking on that specific NPC at the same time as well. Its just a small way to prevent it. Likewise, I only prepared a query when someone adds or remove news.

    * And I know that you're way better than me. I'm still learning.
    Last edited by AuroX; 19-04-11 at 11:34 AM.



Page 2 of 4 FirstFirst 1234 LastLast

Advertisement