Skip to content

Commit

Permalink
other things
Browse files Browse the repository at this point in the history
  • Loading branch information
tim03we committed Jul 31, 2022
1 parent 4763b4a commit cfd43e0
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public AddMemberCommand(String name, String description, String usage) {
@Override
public void execute(CommandSender sender, String command, String[] args) {
if(sender instanceof Player) {
Player player = (Player) sender;
Plot plot = new PlotPlayer((Player) sender).getPlot();
if(plot != null) {
if(plot.canByPass((Player) sender)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public DeleteHomeCommand(String name, String description, String usage) {
@Override
public void execute(CommandSender sender, String command, String[] args) {
if(sender instanceof Player) {
Player player = (Player) sender;
Plot plot = new PlotPlayer((Player) sender).getPlot();
if(plot != null) {
if(plot.canByPass((Player) sender)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public DisposeCommand(String name, String description, String usage) {
@Override
public void execute(CommandSender sender, String command, String[] args) {
if(sender instanceof Player) {
Player player = (Player) sender;
Plot plot = new PlotPlayer((Player) sender).getPlot();
if(plot != null) {
if(plot.canByPass((Player) sender)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public RemoveHelperCommand(String name, String description, String usage) {
@Override
public void execute(CommandSender sender, String command, String[] args) {
if(sender instanceof Player) {
Player player = (Player) sender;
Plot plot = new PlotPlayer((Player) sender).getPlot();
if(plot != null) {
if(plot.canByPass((Player) sender)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public RemoveMemberCommand(String name, String description, String usage) {
@Override
public void execute(CommandSender sender, String command, String[] args) {
if(sender instanceof Player) {
Player player = (Player) sender;
Plot plot = new PlotPlayer((Player) sender).getPlot();
if(plot != null) {
if(plot.canByPass((Player) sender)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public UnDenyCommand(String name, String description, String usage) {
@Override
public void execute(CommandSender sender, String command, String[] args) {
if(sender instanceof Player) {
Player player = (Player) sender;
Plot plot = new PlotPlayer((Player) sender).getPlot();
if(plot != null) {
if(plot.canByPass((Player) sender)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface DataProvider {

void checkPlayer(Player player);

void claimPlot(String name, Plot plot);
boolean claimPlot(String name, Plot plot);

void deletePlot(Plot plot);

Expand Down
34 changes: 23 additions & 11 deletions src/main/java/tim03we/futureplots/provider/data/MySQLProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private void checkAndRun() {
if(Settings.debug) e.printStackTrace();
}
try {
PreparedStatement statement = database.getConnection().prepareStatement("CREATE TABLE player_data ( `id` INT NOT NULL AUTO_INCREMENT , `xuid` VARCHAR NOT NULL , `playername` VARCHAR NOT NULL , PRIMARY KEY (`id`), UNIQUE (`xuid`)) ENGINE = InnoDB;");
PreparedStatement statement = database.getConnection().prepareStatement("CREATE TABLE IF NOT EXISTS player_data(id INT(255) NOT NULL AUTO_INCREMENT , xuid VARCHAR(255) NOT NULL , playername VARCHAR(255) NOT NULL , UNIQUE (id));");
statement.executeUpdate();
statement.close();
} catch (Exception e) {
Expand All @@ -97,6 +97,14 @@ private void checkAndRun() {
});
}

private String getXuid(String name) {
SQLTable table = database.getTable("player_data");
SQLEntity search = new SQLEntity("playername", name);
SQLEntity find = table.find(search, true, "playername");
if(find == null) return null;
return find.getString("xuid");
}

@Override
public void save() {
}
Expand All @@ -109,7 +117,7 @@ public void checkPlayer(Player player) {

SQLTable table = database.getTable("player_data");
SQLEntity search = new SQLEntity("xuid", xuid);
SQLEntity find = table.find(search);
SQLEntity find = table.find(search, false, null);
if(find == null) {
search.append("playername", playername);
table.insert(search);
Expand All @@ -129,14 +137,18 @@ public void checkPlayer(Player player) {
}

@Override
public void claimPlot(String name, Plot plot) {
public boolean claimPlot(String name, Plot plot) {
// TODO: String xuid = getXuid(name);
// TODO: if(xuid == null) return false;
CompletableFuture.runAsync(() -> {
SQLTable table = database.getTable("plots");
SQLEntity insertEntity = new SQLEntity("level", plot.getLevelName());
insertEntity.append("plotid", plot.getFullID());
// TODO: insertEntity.append("owner", getXuid(name));
insertEntity.append("owner", name);
table.insert(insertEntity);
});
return true;
}

@Override
Expand Down Expand Up @@ -182,7 +194,7 @@ public void setOwner(String name, Plot plot) {
public String getOwner(Plot plot) {
SQLTable table = database.getTable("plots");
SQLEntity searchEntity = new SQLEntity("level", plot.getLevelName()).append("plotid", plot.getFullID());
SQLEntity find = table.find(searchEntity);
SQLEntity find = table.find(searchEntity, false, null);
if(find != null) {
return find.getString("owner");
}
Expand All @@ -193,7 +205,7 @@ public String getOwner(Plot plot) {
public List<String> getHelpers(Plot plot) {
SQLTable table = database.getTable("plots");
SQLEntity searchEntity = new SQLEntity("level", plot.getLevelName()).append("plotid", plot.getFullID());
SQLEntity find = table.find(searchEntity);
SQLEntity find = table.find(searchEntity, false, null);
if(find != null) {
if(find.getString("helpers") == null) return new ArrayList<>();
return new Gson().fromJson(find.getString("helpers"), List.class);
Expand All @@ -205,7 +217,7 @@ public List<String> getHelpers(Plot plot) {
public List<String> getMembers(Plot plot) {
SQLTable table = database.getTable("plots");
SQLEntity searchEntity = new SQLEntity("level", plot.getLevelName()).append("plotid", plot.getFullID());
SQLEntity find = table.find(searchEntity);
SQLEntity find = table.find(searchEntity, false, null);
if(find != null) {
if(find.getString("members") == null) return new ArrayList<>();
return new Gson().fromJson(find.getString("members"), List.class);
Expand All @@ -217,7 +229,7 @@ public List<String> getMembers(Plot plot) {
public List<String> getDenied(Plot plot) {
SQLTable table = database.getTable("plots");
SQLEntity searchEntity = new SQLEntity("level", plot.getLevelName()).append("plotid", plot.getFullID());
SQLEntity find = table.find(searchEntity);
SQLEntity find = table.find(searchEntity, false, null);
if(find != null) {
if(find.getString("denied") == null) return new ArrayList<>();
return new Gson().fromJson(find.getString("denied"), List.class);
Expand Down Expand Up @@ -306,7 +318,7 @@ public void deleteHome(Plot plot) {
public Location getHome(Plot plot) {
SQLTable table = database.getTable("plots");
SQLEntity searchEntity = new SQLEntity("level", plot.getLevelName()).append("plotid", plot.getFullID());
SQLEntity find = table.find(searchEntity);
SQLEntity find = table.find(searchEntity, false, null);
if(find != null) {
String locationString = find.getString("home");
if(locationString != null) {
Expand Down Expand Up @@ -417,7 +429,7 @@ public void setMergeCheck(Plot plot, Plot mergePlot) {
public List<Plot> getMergeCheck(Plot plot) {
SQLTable table = database.getTable("plots");
SQLEntity searchEntity = new SQLEntity("level", plot.getLevelName()).append("plotid", plot.getFullID());
SQLEntity find = table.find(searchEntity);
SQLEntity find = table.find(searchEntity, false, null);
List<Plot> list = new ArrayList<>();
if(find != null) {
if(find.getString("merge_check") == null) return new ArrayList<>();
Expand All @@ -434,7 +446,7 @@ public List<Plot> getMergeCheck(Plot plot) {
public Plot getOriginPlot(Plot plot) {
SQLTable table = database.getTable("plots");
SQLEntity searchEntity = new SQLEntity("level", plot.getLevelName()).append("plotid", plot.getFullID());
SQLEntity find = table.find(searchEntity);
SQLEntity find = table.find(searchEntity, false, null);
if(find != null) {
if(find.getString("merge") == null) return null;
String[] ex = find.getString("merge").split(";");
Expand Down Expand Up @@ -469,7 +481,7 @@ public void addMerge(Plot originPlot, Plot mergePlot) {
public List<Plot> getMerges(Plot plot) {
SQLTable table = database.getTable("plots");
SQLEntity searchEntity = new SQLEntity("level", plot.getLevelName()).append("plotid", plot.getFullID());
SQLEntity find = table.find(searchEntity);
SQLEntity find = table.find(searchEntity, false, null);
List<Plot> list = new ArrayList<>();
if(find != null) {
if(find.getString("merges") == null) return new ArrayList<>();
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/tim03we/futureplots/provider/data/SQLiteProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void checkPlayer(Player player) {

SQLTable table = database.getTable("player_data");
SQLEntity search = new SQLEntity("xuid", xuid);
SQLEntity find = table.find(search);
SQLEntity find = table.find(search, false, null);
if(find == null) {
search.append("playername", playername);
table.insert(search);
Expand All @@ -117,14 +117,15 @@ public void checkPlayer(Player player) {
}

@Override
public void claimPlot(String name, Plot plot) {
public boolean claimPlot(String name, Plot plot) {
CompletableFuture.runAsync(() -> {
SQLTable table = database.getTable("plots");
SQLEntity insertEntity = new SQLEntity("level", plot.getLevelName());
insertEntity.append("plotid", plot.getFullID());
insertEntity.append("owner", name);
table.insert(insertEntity);
});
return true;
}

@Override
Expand Down Expand Up @@ -170,7 +171,7 @@ public void setOwner(String name, Plot plot) {
public String getOwner(Plot plot) {
SQLTable table = database.getTable("plots");
SQLEntity searchEntity = new SQLEntity("level", plot.getLevelName()).append("plotid", plot.getFullID());
SQLEntity find = table.find(searchEntity);
SQLEntity find = table.find(searchEntity, false, null);
if(find != null) {
return find.getString("owner");
}
Expand All @@ -181,7 +182,7 @@ public String getOwner(Plot plot) {
public List<String> getHelpers(Plot plot) {
SQLTable table = database.getTable("plots");
SQLEntity searchEntity = new SQLEntity("level", plot.getLevelName()).append("plotid", plot.getFullID());
SQLEntity find = table.find(searchEntity);
SQLEntity find = table.find(searchEntity, false, null);
if(find != null) {
if(find.getString("helpers") == null) return new ArrayList<>();
return new Gson().fromJson(find.getString("helpers"), List.class);
Expand All @@ -193,7 +194,7 @@ public List<String> getHelpers(Plot plot) {
public List<String> getMembers(Plot plot) {
SQLTable table = database.getTable("plots");
SQLEntity searchEntity = new SQLEntity("level", plot.getLevelName()).append("plotid", plot.getFullID());
SQLEntity find = table.find(searchEntity);
SQLEntity find = table.find(searchEntity, false, null);
if(find != null) {
if(find.getString("members") == null) return new ArrayList<>();
return new Gson().fromJson(find.getString("members"), List.class);
Expand All @@ -205,7 +206,7 @@ public List<String> getMembers(Plot plot) {
public List<String> getDenied(Plot plot) {
SQLTable table = database.getTable("plots");
SQLEntity searchEntity = new SQLEntity("level", plot.getLevelName()).append("plotid", plot.getFullID());
SQLEntity find = table.find(searchEntity);
SQLEntity find = table.find(searchEntity, false, null);
if(find != null) {
if(find.getString("denied") == null) return new ArrayList<>();
return new Gson().fromJson(find.getString("denied"), List.class);
Expand Down Expand Up @@ -294,7 +295,7 @@ public void deleteHome(Plot plot) {
public Location getHome(Plot plot) {
SQLTable table = database.getTable("plots");
SQLEntity searchEntity = new SQLEntity("level", plot.getLevelName()).append("plotid", plot.getFullID());
SQLEntity find = table.find(searchEntity);
SQLEntity find = table.find(searchEntity, false, null);
if(find != null) {
String locationString = find.getString("home");
if(locationString != null) {
Expand Down Expand Up @@ -405,7 +406,7 @@ public void setMergeCheck(Plot plot, Plot mergePlot) {
public List<Plot> getMergeCheck(Plot plot) {
SQLTable table = database.getTable("plots");
SQLEntity searchEntity = new SQLEntity("level", plot.getLevelName()).append("plotid", plot.getFullID());
SQLEntity find = table.find(searchEntity);
SQLEntity find = table.find(searchEntity, false, null);
List<Plot> list = new ArrayList<>();
if(find != null) {
if(find.getString("merge_check") == null) return new ArrayList<>();
Expand All @@ -422,7 +423,7 @@ public List<Plot> getMergeCheck(Plot plot) {
public Plot getOriginPlot(Plot plot) {
SQLTable table = database.getTable("plots");
SQLEntity searchEntity = new SQLEntity("level", plot.getLevelName()).append("plotid", plot.getFullID());
SQLEntity find = table.find(searchEntity);
SQLEntity find = table.find(searchEntity, false, null);
if(find != null) {
if(find.getString("merge") == null) return null;
String[] ex = find.getString("merge").split(";");
Expand Down Expand Up @@ -457,7 +458,7 @@ public void addMerge(Plot originPlot, Plot mergePlot) {
public List<Plot> getMerges(Plot plot) {
SQLTable table = database.getTable("plots");
SQLEntity searchEntity = new SQLEntity("level", plot.getLevelName()).append("plotid", plot.getFullID());
SQLEntity find = table.find(searchEntity);
SQLEntity find = table.find(searchEntity, false, null);
List<Plot> list = new ArrayList<>();
if(find != null) {
if(find.getString("merges") == null) return new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void checkPlayer(Player player) {
}

@Override
public void claimPlot(String username, Plot plot) {
public boolean claimPlot(String username, Plot plot) {
yaml.set(plot.getLevelName() + ";" + plot.getX() + ";" + plot.getZ() + ".owner", username);
yaml.set(plot.getLevelName() + ";" + plot.getX() + ";" + plot.getZ() + ".helpers", new ArrayList<String>());
yaml.set(plot.getLevelName() + ";" + plot.getX() + ";" + plot.getZ() + ".members", new ArrayList<String>());
Expand All @@ -81,6 +81,7 @@ public void claimPlot(String username, Plot plot) {
yaml.set(plot.getLevelName() + ";" + plot.getX() + ";" + plot.getZ() + ".merge", "");
yaml.set(plot.getLevelName() + ";" + plot.getX() + ";" + plot.getZ() + ".merges", new ArrayList<String>());
yaml.set(plot.getLevelName() + ";" + plot.getX() + ";" + plot.getZ() + ".merge_check", new ArrayList<String>());
return true;
}

@Override
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/tim03we/futureplots/provider/sql/SQLTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,18 @@ public Set<SQLEntity> find() {
return null;
}

public SQLEntity find(SQLEntity sqlDocument) {
public SQLEntity find(SQLEntity sqlDocument, boolean uppercase, String upperColum) {
String uppercaseString = "";
if(uppercase) {
uppercaseString = "UPPER(" + upperColum + ")";
}
try {
StringBuilder whereBuilder = new StringBuilder();
for (String where : sqlDocument.getDataMap().keySet()) {
whereBuilder.append(where).append(" = ? AND ");
}
String whereString = whereBuilder.toString().substring(0, (whereBuilder.toString().length() - 5));
PreparedStatement statement = instance.connection.prepareStatement("SELECT * FROM " + this.table + " WHERE " + whereString + ";");
PreparedStatement statement = instance.connection.prepareStatement("SELECT * FROM " + this.table + " WHERE " + whereString + " " + uppercaseString + ";");
int whereInt = 1;
for (Object value : sqlDocument.getDataMap().values()) {
statement.setObject(whereInt, value);
Expand Down

0 comments on commit cfd43e0

Please sign in to comment.