Skip to content

Commit

Permalink
0.6.3
Browse files Browse the repository at this point in the history
- Fixed a logical error which caused a false to be returned when the
villager data was found but was not in need of an update
  • Loading branch information
chrissamael committed Sep 30, 2019
1 parent 2f9aa97 commit 2cff787
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 35 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>eu.chrissamael</groupId>
<artifactId>TheLibrary</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.6.3</version>
<build>
<plugins>
<plugin>
Expand Down
67 changes: 33 additions & 34 deletions src/main/java/theLibrary/VillagerListeners.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,46 +124,45 @@ private boolean updateVillagerData(Villager villager)
//nmsEntity.c(tag);
try
{
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM villager WHERE uuid='"+villager.getUniqueId()+"'");
rs.next();
//player.sendMessage("result: "+rs.getString("name"));
if(!rs.isClosed())
{
String nbtDB = rs.getString("nbt").replaceAll("Spigot.ticksLived:[0123456789]*,", "");
String nbtWorld = tag.asString().replaceAll("Spigot.ticksLived:[0123456789]*,", "");
if(!nbtDB.equals(nbtWorld))
{

PreparedStatement updateStmt = con.prepareStatement("UPDATE villager SET "
+ "posx='"+villager.getLocation().getX()+"',"
+ "posy='"+villager.getLocation().getY()+"',"
+ "posz='"+villager.getLocation().getZ()+"',"
+ "world='"+villager.getLocation().getWorld().getName()+"',"
+ "nbt='"+tag.asString().replaceAll("'", "''")+"',"
+ "name='"+villager.getCustomName()+"',"
+ "timestamp='"+sdf.format(System.currentTimeMillis())+"' "
+ "WHERE uuid='"+villager.getUniqueId()+"'");
updateStmt.executeUpdate();
return true;
}
else
{

}

}
else
{
return false;
}
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM villager WHERE uuid='"+villager.getUniqueId()+"'");
rs.next();
//player.sendMessage("result: "+rs.getString("name"));
if(!rs.isClosed())
{
String nbtDB = rs.getString("nbt").replaceAll("Spigot.ticksLived:[0123456789]*,", "");
String nbtWorld = tag.asString().replaceAll("Spigot.ticksLived:[0123456789]*,", "");
if(!nbtDB.equals(nbtWorld))
{
PreparedStatement updateStmt = con.prepareStatement("UPDATE villager SET "
+ "posx='"+villager.getLocation().getX()+"',"
+ "posy='"+villager.getLocation().getY()+"',"
+ "posz='"+villager.getLocation().getZ()+"',"
+ "world='"+villager.getLocation().getWorld().getName()+"',"
+ "nbt='"+tag.asString().replaceAll("'", "''")+"',"
+ "name='"+villager.getCustomName()+"',"
+ "timestamp='"+sdf.format(System.currentTimeMillis())+"' "
+ "WHERE uuid='"+villager.getUniqueId()+"'");
updateStmt.executeUpdate();
return true;
}
else
{
return true;
}
}
else
{
return false;
}

}catch(SQLException exc)
{
exc.printStackTrace();
return false;
}
return false;
}

@EventHandler
Expand Down

0 comments on commit 2cff787

Please sign in to comment.