Archived
0

Mini-Update for API 0.0.4

This commit is contained in:
Prot-CN
2019-02-01 13:20:01 +06:00
parent 53bc91d2e6
commit 5692fdad74
5 changed files with 72 additions and 18 deletions

12
pom.xml
View File

@@ -7,6 +7,18 @@
<groupId>ru.prisonlife</groupId>
<artifactId>PrisonAPI</artifactId>
<version>0.0.1</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>

View File

@@ -0,0 +1,40 @@
package ru.prisonlife.PrisonAPI.template;
import ru.prisonlife.PrisonAPI.PrisonAPI;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
public class Faction {
private enum Factions { NONE, ASIANS, LATINOS, NIGGAZ, POLICE }
private Map<Integer, Factions> pick = new HashMap<Integer, Factions>();
{
for(int i = 0; i < Factions.values().length; i++)
pick.put(i, Factions.values()[i]);
}
private PreparedStatement state;
private ResultSet r_set;
private Prisoner me;
Faction(Prisoner prisoner) { me = prisoner; }
public void change(int id) throws SQLException {
get_t();
if(r_set.first())
state.execute("UPDATE player_stats SET FACTION = '" + pick.get(id) + "'");
dis_t();
}
private void get_t() throws SQLException {
state = PrisonAPI.CONN.prepareStatement("SELECT * UUID FROM player_stats WHERE UUID = ?;");
state.setString(1, me.getPlayer().getUniqueId().toString());
r_set = state.executeQuery("SELECT UUID FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
}
private void dis_t() throws SQLException {
r_set.close();
state.close();
}
}

View File

@@ -43,6 +43,7 @@ public class Level {
setInResUUID();
if(r_set.first())
state.execute("UPDATE player_stats SET LEVEL = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
disconnect();
}
private void setInResUUID() throws SQLException {

View File

@@ -10,35 +10,39 @@ import java.sql.SQLException;
public class Prisoner {
private Player me;
private Level level;
private Stats stats;
private Faction faction;
private Wallet wallet;
private Stats stats;
private PreparedStatement state;
private ResultSet r_set;
public Prisoner(Player player) {
me = player;
level = new Level(this);
stats = new Stats(this);
wallet = new Wallet(this);
faction = new Faction(this);
stats = new Stats(this);
}
public Player getPlayer() { return me; }
public Level getPrisonLevel() throws SQLException { return this.level; }
public Faction getFaction() { return faction; }
public Wallet getWallet() { return wallet; }
public Stats getStats() { return stats; }
public Level getPrisonLevel() throws SQLException { return this.level; }
public void register() throws SQLException {
state = PrisonAPI.CONN.prepareStatement("SELECT * UUID FROM player_stats WHERE UUID = ?;");
state.setString(1, me.getUniqueId().toString());
r_set = state.executeQuery("SELECT UUID FROM player_stats WHERE UUID = '" + me.getUniqueId() + "'");
if(!r_set.next()) {
state.execute(
"INSERT INTO player_stats(NAME, UUID, LEVEL, POINTS, G_TIME, D_BLOCKS, " +
"K_PLAYERS, K_MOBS, DEATHS, WALLET) VALUES (" +"'" + getPlayer().getName()
+ "', '" + me.getUniqueId() + "', 1, 0, 0, 0, 0, 0, 0, 0);");
"INSERT INTO player_stats(NAME, UUID, LEVEL, POINTS, FACTION, WALLET, G_TIME, D_BLOCKS, " +
"K_PLAYERS, K_MOBS, DEATHS) VALUES (" +"'" + getPlayer().getName()
+ "', '" + me.getUniqueId() + "', 1, 0, 'None', 0, 0, 0, 0, 0, 0);");
level = new Level(this);
stats = new Stats(this);
wallet = new Wallet(this);

View File

@@ -16,35 +16,32 @@ public class Wallet {
setInResUUID();
if(r_set.first()) {
r_set = state.executeQuery("SELECT WALLET FROM player_stats WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
if(r_set.first()) {
if(r_set.first())
return r_set.getInt(1);
}
disconnect();
}
disconnect();
return NullPointerException.class.hashCode();
}
public void addBalance(int value) throws SQLException {
setInResUUID();
if(r_set.first()) {
if(r_set.first())
state.execute("UPDATE player_stats SET WALLET = " + (getBalance() + value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
disconnect();
}
disconnect();
}
public void deposit(int value) throws SQLException {
setInResUUID();
if(r_set.first()) {
if(r_set.first())
state.execute("UPDATE player_stats SET WALLET = " + (getBalance() - value) + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
}
disconnect();
}
public void setBalance(int value) throws SQLException {
setInResUUID();
if(r_set.first()) {
if(r_set.first())
state.execute("UPDATE player_stats SET WALLET = " + value + " WHERE UUID = '" + me.getPlayer().getUniqueId() + "'");
disconnect();
}
disconnect();
}
private void setInResUUID() throws SQLException {