Thread: some java issues

Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1 some java issues 
    Donator

    Join Date
    Jul 2012
    Age
    28
    Posts
    657
    Thanks given
    269
    Thanks received
    58
    Rep Power
    10
    hey guys i have some issues in my bloodlust
    first i had sql issues but those are fixed thanks to xylate

    but now i have soem other errors and since i suck realy hard can someone please tell me what is wrong with this code

    the line in red is the line eclipse says its wrong in this error

    [00:02:00]: java.lang.ArithmeticException: / by zero
    [00:02:00]: at com.rs.worldserver.model.player.BloodlustDatabase. updateKills(BloodlustDatabase.java:372)
    [00:02:00]: at com.rs.worldserver.model.player.ActionAssistant.ap plyDead(ActionAssistant.java:9351)
    [00:02:00]: at com.rs.worldserver.model.player.Client.process(Cli ent.java:1615)
    [00:02:00]: at com.rs.worldserver.world.PlayerManager.process(Pla yerManager.java:399)
    [00:02:00]: at com.rs.worldserver.Server$1.execute(Server.java:34 5)
    [00:02:00]: at com.rs.worldserver.events.EventContainer.execute(E ventContainer.java:130)
    [00:02:00]: at com.rs.worldserver.events.EventManager.run(EventMa nager.java:122)
    [00:02:00]: at java.lang.Thread.run(Unknown Source)


    Spoiler for the class file:

    package com.rs.worldserver.model.player;

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Properties;

    import com.rs.worldserver.Server;

    @SuppressWarnings("all")
    public class BloodlustDatabase {

    private static BloodlustDatabase singleton;

    private static final String SQL_HOST = "----------------";
    private static final String SQL_USER = "patronep_bloodlu";
    private static final String SQL_PASS = "-----------------";
    private static final String SQL_DB = "patronep_Bloodlust";

    private Connection getConnection() throws SQLException {
    Properties connectionProperties = new Properties();
    connectionProperties.put("user", SQL_USER);
    connectionProperties.put("password", SQL_PASS);
    return DriverManager.getConnection("jdbc:mysql://" + SQL_HOST + "/",
    connectionProperties);
    }

    public void join(Client me, int teamId) {
    System.err.println("Called");
    Connection connection = null;
    PreparedStatement statement = null;
    try {
    connection = getConnection();
    statement = connection
    .prepareStatement("INSERT INTO `patronep_Bloodlust`.`blplayer` (`pname`, `pkills`, `pdeaths`, `pratio`, `tid`) VALUES (?, ?, ?, ?, ?);");
    statement.setString(1, me.getPlayerName());
    statement.setInt(2, 0);
    statement.setInt(3, 0);
    statement.setDouble(4, 1.00);
    statement.setInt(5, teamId);
    if (statement.executeUpdate() > 0) {
    me.getActionAssistant()
    .sendMessage("You have joined the team.");
    me.blTeamId = teamId;
    me.title += "[ " + BLTeam.getBy(teamId).getName() + " ] ";
    } else {
    me.getActionAssistant()
    .sendMessage(
    "There was a problem joining the team, please try again.");
    }
    } catch (SQLException e) {
    e.printStackTrace();
    } finally {
    try {
    statement.close();
    connection.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }

    }
    }

    public HashMap<Integer, BLTeam> getTeams() {
    Connection connection = null;
    Statement statement = null;
    ResultSet results;
    HashMap<Integer, BLTeam> teams = new HashMap<Integer, BLTeam>();
    try {
    connection = getConnection();
    statement = connection.createStatement();
    results = statement.executeQuery("SELECT * FROM `" + SQL_DB
    + "`.`blteams`");
    // String owner, String name, int teamId, int kills, int deaths, int
    // rating
    while (results.next()) {
    teams.put(
    results.getInt("tid"),
    new BLTeam(results.getString("tcapt"), results
    .getString("tname"), results.getInt("tid"),
    results.getInt("tkills"), results
    .getInt("tdeaths"), results
    .getInt("TRating")));
    }
    return teams;
    } catch (SQLException e) {
    e.printStackTrace();
    return teams;
    } finally {
    try {
    statement.close();
    connection.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }

    }
    }

    public List<String> getTeamates(int teamId) {
    Connection connection = null;
    PreparedStatement statement = null;
    ResultSet results;
    try {
    connection = getConnection();
    statement = connection.prepareStatement("SELECT * FROM `" + SQL_DB
    + "`.blplayer` WHERE `tid`=?");
    statement.setInt(1, teamId);
    results = statement.executeQuery();
    List<String> clients = new ArrayList<String>();
    while (results.next()) {
    clients.add(results.getString("pname"));
    }
    return clients;
    } catch (SQLException e) {
    e.printStackTrace();
    return new ArrayList<String>();
    } finally {
    try {
    statement.close();
    connection.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }

    }
    }

    public void invite(Client player, String target) {
    Connection connection = null;
    PreparedStatement statement = null;
    ResultSet results = null;
    try {
    connection = getConnection();
    statement = connection.prepareStatement("SELECT * FROM `" + SQL_DB
    + "`.`blteams` WHERE `tcapt`=?");
    statement.setString(1, player.getPlayerName());
    results = statement.executeQuery();
    // If the team exists.
    while (results.next()) {
    for (Player p : Server.getPlayerManager().getPlayers()) {
    if (p == null)
    continue;
    if (p.getPlayerName().equalsIgnoreCase(target)) {
    ((Client) p).setBLInvite(new BLInvite(player,
    (Client) p, results.getInt("tid")));
    ((Client) p).getBLInvite().sendInvite(
    results.getString("tname"));
    // Connection is closed in finally, eclipse bug.
    return;
    }
    }
    }
    } catch (SQLException e) {
    e.printStackTrace();
    } finally {
    try {
    statement.close();
    connection.close();
    results.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }

    }
    }

    public void kickMember(Client me, String member) {
    if (me.getBLTeam() == null)
    return;
    if (!(me.getBLTeam().getOwner().equalsIgnoreCase(me.g etPlayerName())))
    return;
    Connection connection = null;
    PreparedStatement statement = null;
    ResultSet results;
    try {
    connection = getConnection();
    statement = connection.prepareStatement("SELECT * FROM `" + SQL_DB
    + "`.`blteams` WHERE `tcapt`=?");
    statement.setString(1, me.getPlayerName());
    results = statement.executeQuery();
    while (results.next()) {
    statement = connection.prepareStatement("SELECT * FROM `"
    + SQL_DB + "`.`blplayer` WHERE `tid`=?");
    statement.setInt(1, results.getInt("tid"));
    ResultSet r = statement.executeQuery();
    while (r.next()) {
    statement = connection.prepareStatement("DELETE FROM `"
    + SQL_DB + "`.`blplayer` WHERE `pname`=?");
    statement.setString(1, member);
    if (statement.executeUpdate() > 0) {
    me.getActionAssistant().sendMessage(
    "You have successfully kicked " + member
    + " from your BL team");
    for (Client c : (Client[]) Server.getPlayerManager()
    .getPlayers()) {
    if (c == null)
    continue;
    if (c.getPlayerName().equalsIgnoreCase(member)) {
    c.setBLTeam(null);
    c.blTeamId = 0;
    c.getActionAssistant()
    .sendMessage(
    "You have been removed from your bloodlust team.");
    return;
    }
    }
    } else {
    me.getActionAssistant().sendMessage(
    member + " is not in your team.");
    }
    }
    }
    } catch (SQLException e) {
    e.printStackTrace();
    } finally {
    try {
    statement.close();
    connection.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }

    }
    }

    public void updateKills(String killer, int killerTeam, String victim,
    int victimTeam) {
    Connection connection = null;
    PreparedStatement killerStatement = null;
    PreparedStatement victimStatement = null;
    PreparedStatement statement = null;
    ResultSet results;
    try {
    connection = getConnection();
    killerStatement = connection.prepareStatement("SELECT * FROM `"
    + SQL_DB + "`.`blplayer` WHERE `pname`=?");
    killerStatement.setString(1, killer);
    results = killerStatement.executeQuery();
    String teamA = "";
    String teamB = "";
    while (results.next()) {
    killerStatement = connection
    .prepareStatement("UPDATE `"
    + SQL_DB
    + "`.`blplayer` SET `pkills` = ?, `pratio` = ? WHERE `blplayer`.`pname` =?;");
    killerStatement.setInt(1, results.getInt("pkills") + 1);
    if (results.getInt("pdeaths") == 0) {
    killerStatement.setDouble(2, results.getInt("pkills"));
    } else if (results.getInt("pkills") == 0) {
    killerStatement.setDouble(2, 0);
    } else {
    killerStatement.setDouble(2,
    (float) (results.getInt("pkills") + 1)
    / (float) results.getInt("pdeaths"));
    }
    killerStatement.setString(3, killer);
    killerStatement.executeUpdate();
    }

    victimStatement = connection.prepareStatement("SELECT * FROM `"
    + SQL_DB + "`.`blplayer` WHERE `pname`=?");
    victimStatement.setString(1, victim);
    results = victimStatement.executeQuery();

    while (results.next()) {
    victimStatement = connection
    .prepareStatement("UPDATE `"
    + SQL_DB
    + "`.`blplayer` SET `pdeaths` = ?, `pratio` = ? WHERE `blplayer`.`pname` =?;");
    victimStatement.setInt(1, results.getInt("pdeaths") + 1);
    if (results.getInt("pdeaths") == 0) {
    victimStatement.setDouble(2, results.getInt("pkills"));
    } else if (results.getInt("pkills") == 0) {
    victimStatement.setDouble(2, 0);
    } else {
    victimStatement.setDouble(2,
    (float) (results.getInt("pkills"))
    / (float) (results.getInt("pdeaths") + 1));
    }
    victimStatement.setString(3, victim);
    victimStatement.executeUpdate();
    }

    statement = connection.prepareStatement("SELECT * FROM `" + SQL_DB
    + "`.`blplayer` WHERE `tid`=?");
    statement.setInt(1, killerTeam);
    results = statement.executeQuery();

    List<Integer> ratios = new ArrayList<Integer>();
    List<Integer> kills = new ArrayList<Integer>();
    List<Integer> deaths = new ArrayList<Integer>();

    while (results.next()) {
    ratios.add(results.getInt("pratio"));
    kills.add(results.getInt("pkills"));
    deaths.add(results.getInt("pdeaths"));
    }

    float ratio = 0;
    for (float f : ratios) {
    ratio += f;
    }
    ratio = ratio / ratios.size();

    int kill = 0;
    for (int i : kills) {
    kill += i;
    }
    kill = (int) Math.floor((double) (kill / kills.size()));

    int death = 0;
    for (int i : deaths) {
    death += i;
    }
    death = (int) Math.floor((double) (death / deaths.size()));

    statement = connection.prepareStatement("SELECT * FROM `" + SQL_DB
    + "`.`blteams` WHERE `tid`=?");
    statement.setInt(1, killerTeam);
    results = statement.executeQuery();
    int rating = 0;
    while (results.next()) {
    rating = results.getInt("TRating");
    }

    // Statement is closed in finally, eclipse bug.
    statement = connection
    .prepareStatement("UPDATE `"
    + SQL_DB
    + "`.`blteams` SET `tkills`=?, `tdeaths`=?, `TRating`=?, `tratio`=? WHERE `tid`=?");
    statement.setInt(1, kill);
    statement.setInt(2, death);
    statement.setInt(3, rating + 12);
    statement.setDouble(4, ratio);
    statement.setInt(5, killerTeam);
    statement.executeUpdate();

    kills.clear();
    deaths.clear();
    ratios.clear();
    kill = 0;
    death = 0;
    ratio = 0;
    // ----------------------------
    // Statement is closed in finally, eclipse bug.
    statement = connection.prepareStatement("SELECT * FROM `" + SQL_DB
    + "`.`blplayer` WHERE `tid`=?");
    statement.setInt(1, victimTeam);
    results = statement.executeQuery();
    while (results.next()) {
    ratios.add(results.getInt("pratio"));
    kills.add(results.getInt("pkills"));
    deaths.add(results.getInt("pdeaths"));
    }

    for (float f : ratios) {
    ratio += f;
    }

    ratio = ratio / ratios.size();

    for (int i : kills) {
    kill += i;
    }
    kill = (int) Math.floor((double) (kill / kills.size()));

    for (int i : deaths) {
    death += i;
    }
    death = (int) Math.floor((double) (death / deaths.size()));

    statement = connection.prepareStatement("SELECT * FROM `" + SQL_DB
    + "`.`blteams` WHERE `tid`=?");
    statement.setInt(1, victimTeam);
    results = statement.executeQuery();
    rating = 0;
    while (results.next()) {
    rating = results.getInt("TRating");
    }
    // Statement is closed in finally, eclipse bug.
    statement = connection
    .prepareStatement("UPDATE `"
    + SQL_DB
    + "`.`blteams` SET `tkills`=?, `tdeaths`=?, `TRating`=?, `tratio`=? WHERE `tid`=?");
    statement.setInt(1, kill);
    statement.setInt(2, death);
    statement.setInt(3, rating - 12);
    statement.setDouble(4, ratio);
    statement.setInt(5, victimTeam);
    statement.executeUpdate();

    Client cKiller = null;
    Client cVictim = null;
    for (Player client : Server.getPlayerManager().getPlayers()) {
    if (client == null)
    continue;
    Client c = (Client) client;
    if (c.getPlayerName().equalsIgnoreCase(victim)) {
    cVictim = c;
    teamA = c.getBLTeam().getName();
    } else if (c.getPlayerName().equalsIgnoreCase(killer)) {
    cKiller = c;
    teamB = c.getBLTeam().getName();
    }
    }
    if (cKiller != null)
    cKiller.getActionAssistant().sendMessage(
    "@red@You have killed " + victim + " of team [" + teamA
    + "] and gain a +12 rating.");
    if (cVictim != null)
    cVictim.getActionAssistant().sendMessage(
    "@red@You have been defeated by " + killer
    + " of team [" + teamB
    + "] and lost -12 rating.");
    } catch (SQLException e) {
    e.printStackTrace();
    } finally {
    try {
    statement.close();
    killerStatement.close();
    victimStatement.close();
    connection.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }

    }
    }

    public boolean createTeam(Client player, String name) {
    Connection connection = null;
    PreparedStatement statement = null;
    ResultSet results;
    try {
    connection = getConnection();
    statement = connection
    .prepareStatement("INSERT INTO `patronep_Bloodlust`.`blteams` (`tname`, `tcapt`, `tkills`, `tdeaths`, `TRating`, `tratio`) VALUES (?, ?, ?, ?, ?, ?)");
    statement.setString(1, name);
    statement.setString(2, player.getPlayerName());
    statement.setInt(3, 0);
    statement.setInt(4, 0);
    statement.setInt(5, 1200);
    statement.setDouble(6, 1.00);
    if (statement.executeUpdate() > 0) {
    player.getActionAssistant().sendMessage(
    "Your team as been successfully created");
    // Statement is closed in finally, eclipse bug.
    statement = connection.prepareStatement("SELECT * FROM `"
    + SQL_DB + "`.`blteams` WHERE `tname`=?");
    statement.setString(1, name);
    results = statement.executeQuery();
    while (results.next()) {
    BLTeam.getTeams().put(
    results.getInt("tid"),
    new BLTeam(player.getPlayerName(), name, results
    .getInt("tid"), 0, 0, 1200));
    player.blTeamId = results.getInt("tid");
    join(player, results.getInt("tid"));
    return true;
    }
    return false;
    } else {
    player.getActionAssistant().sendMessage(
    "There was an error creating your team.");
    return false;

    }
    } catch (SQLException e) {
    e.printStackTrace();
    return false;
    } finally {
    try {
    statement.close();
    connection.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }

    }
    }

    public static BloodlustDatabase getSingleton() {
    if (singleton == null)
    singleton = new BloodlustDatabase();
    return singleton;
    }

    }

    Reply With Quote  
     

  2. #2  
    Respected Member


    Join Date
    Jan 2009
    Posts
    5,743
    Thanks given
    1,162
    Thanks received
    3,603
    Rep Power
    5000
    you cant divide by 0
    Reply With Quote  
     

  3. #3  
    Donator

    Join Date
    Jul 2012
    Age
    28
    Posts
    657
    Thanks given
    269
    Thanks received
    58
    Rep Power
    10
    Quote Originally Posted by Stuart View Post
    you cant divide by 0
    huh wait where?
    Reply With Quote  
     

  4. #4  
    MOD DESIGNER RM MORE COMING


    TheeRash's Avatar
    Join Date
    Dec 2010
    Age
    30
    Posts
    5,128
    Thanks given
    639
    Thanks received
    2,123
    Rep Power
    5000
    /0 = no no


    Feel free to message me with any questions you may have - any offers of work will not be considered unless details are in the subject.
    Attached imageAttached imageAttached image
    Reply With Quote  
     

  5. #5  
    Donator

    Join Date
    Jul 2012
    Age
    28
    Posts
    657
    Thanks given
    269
    Thanks received
    58
    Rep Power
    10
    Quote Originally Posted by Thee Rash View Post
    /0 = no no
    can you add me on skype
    skypename dutchxxje
    and help me fix this i can pay u for it
    Reply With Quote  
     

  6. #6  
    MOD DESIGNER RM MORE COMING


    TheeRash's Avatar
    Join Date
    Dec 2010
    Age
    30
    Posts
    5,128
    Thanks given
    639
    Thanks received
    2,123
    Rep Power
    5000
    no you idiot just remove any /0 you have


    Feel free to message me with any questions you may have - any offers of work will not be considered unless details are in the subject.
    Attached imageAttached imageAttached image
    Reply With Quote  
     

  7. Thankful users:


  8. #7  
    Respected Member


    Join Date
    Jan 2009
    Posts
    5,743
    Thanks given
    1,162
    Thanks received
    3,603
    Rep Power
    5000
    Quote Originally Posted by glaiven-rsps View Post
    huh wait where?
    at com.rs.worldserver.model.player.BloodlustDatabase. updateKills(BloodlustDatabase.java:372)

    I'm guessing this is a k/d ratio and you're dividing by 0 deaths which you cant
    Reply With Quote  
     

  9. #8  
    Donator

    Join Date
    Jul 2012
    Age
    28
    Posts
    657
    Thanks given
    269
    Thanks received
    58
    Rep Power
    10
    Quote Originally Posted by Stuart View Post
    at com.rs.worldserver.model.player.BloodlustDatabase. updateKills(BloodlustDatabase.java:372)

    I'm guessing this is a k/d ratio and you're dividing by 0 deaths which you cant
    but i cant find any i suck at this
    Reply With Quote  
     

  10. #9  
    MOD DESIGNER RM MORE COMING


    TheeRash's Avatar
    Join Date
    Dec 2010
    Age
    30
    Posts
    5,128
    Thanks given
    639
    Thanks received
    2,123
    Rep Power
    5000
    ok idk if im right because im dumb but

    line 372 or thereabouts:


    1. =kill = (int) Math.floor((double) (kill / kills.size()));

      Ok, there is a dividing error, right. OK. ONLY ONE DIVISION TAKES PLACE WHICH IS /KILLS.SIZE.

      You are not adding any value to that int which means it's 0 which means you are diving by zero. better?


    Feel free to message me with any questions you may have - any offers of work will not be considered unless details are in the subject.
    Attached imageAttached imageAttached image
    Reply With Quote  
     

  11. #10  
    Donator

    Join Date
    Jul 2012
    Age
    28
    Posts
    657
    Thanks given
    269
    Thanks received
    58
    Rep Power
    10
    Quote Originally Posted by Thee Rash View Post
    ok idk if im right because im dumb but

    line 372 or thereabouts:


    1. =kill = (int) Math.floor((double) (kill / kills.size()));

      Ok, there is a dividing error, right. OK. ONLY ONE DIVISION TAKES PLACE WHICH IS /KILLS.SIZE.

      You are not adding any value to that int which means it's 0 which means you are diving by zero. better?
    but above that its the same thing

    float ratio = 0;
    for (float f : ratios) {
    ratio += f;
    }
    ratio = ratio / ratios.size();

    int kill = 0;
    for (int i : kills) {
    kill += i;
    }
    kill = (int) Math.floor((double) (kill / kills.size()));

    int death = 0;
    for (int i : deaths) {
    death += i;
    }
    death = (int) Math.floor((double) (death / deaths.size()));


    im fucking bad at this


    anyways cant i just pay u like 10$ to fix it im dumb
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Fix for some java issues
    By GrumpyThe1st in forum Tutorials
    Replies: 6
    Last Post: 08-12-2012, 08:09 AM
  2. windows 7 java issue
    By owned by psy in forum Help
    Replies: 5
    Last Post: 06-13-2010, 08:18 PM
  3. Some java code i made...
    By Streax in forum Application Development
    Replies: 6
    Last Post: 05-14-2010, 10:57 PM
  4. Trying to learn some Java, HELP!
    By Ardy in forum Help
    Replies: 15
    Last Post: 11-13-2009, 08:34 PM
  5. Clearing up some Java speed myths
    By Colby in forum Application Development
    Replies: 11
    Last Post: 09-05-2009, 01:07 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •