Skip to content

Commit

Permalink
release changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim W committed Jul 13, 2020
1 parent 5688b13 commit 659344c
Show file tree
Hide file tree
Showing 17 changed files with 365 additions and 26 deletions.
12 changes: 8 additions & 4 deletions src/main/java/tim03we/futureplots/FuturePlots.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private void registerEvents() {
}

private void checkVersion() {
if(!Language.getNoPrefix("version").equals("1.2.5")) {
if(!Language.getNoPrefix("version").equals("1.2.6")) {
new File(getDataFolder() + "/lang/" + Settings.language + "_old.yml").delete();
if(new File(getDataFolder() + "/lang/" + Settings.language + ".yml").renameTo(new File(getDataFolder() + "/lang/" + Settings.language + "_old.yml"))) {
getLogger().critical("The version of the language configuration does not match. You will find the old file marked \"" + Settings.language + "_old.yml\" in the same language directory.");
Expand All @@ -102,7 +102,7 @@ private void checkVersion() {
saveDefaultConfig();
}
}
if(!cmds.getString("version").equals("1.0.1")) {
if(!cmds.getString("version").equals("1.0.2")) {
new File(getDataFolder() + "/commands_old.yml").delete();
if(new File(getDataFolder() + "/commands.yml").renameTo(new File(getDataFolder() + "/commands_old.yml"))) {
getLogger().critical("The version of the commands file does not match. You will find the old file marked \"commands_old.yml\" in the same directory.");
Expand Down Expand Up @@ -163,6 +163,8 @@ private void registerCommands() {
commandHandler.registerCommand(cmds.getString("plot.dispose.name"), new DisposeCommand(cmds.getString("plot.dispose.name"), cmds.getString("plot.dispose.description"), cmds.getString("plot.dispose.usage")), cmds.getStringList("plot.dispose.alias").toArray(new String[0]));
commandHandler.registerCommand(cmds.getString("plot.kick.name"), new KickCommand(cmds.getString("plot.kick.name"), cmds.getString("plot.kick.description"), cmds.getString("plot.kick.usage")), cmds.getStringList("plot.kick.alias").toArray(new String[0]));
commandHandler.registerCommand(cmds.getString("plot.setowner.name"), new SetOwnerCommand(cmds.getString("plot.setowner.name"), cmds.getString("plot.setowner.description"), cmds.getString("plot.setowner.usage")), cmds.getStringList("plot.setowner.alias").toArray(new String[0]));
commandHandler.registerCommand(cmds.getString("plot.sethome.name"), new SetHomeCommand(cmds.getString("plot.sethome.name"), cmds.getString("plot.sethome.description"), cmds.getString("plot.sethome.usage")), cmds.getStringList("plot.sethome.alias").toArray(new String[0]));
commandHandler.registerCommand(cmds.getString("plot.deletehome.name"), new DeleteHomeCommand(cmds.getString("plot.deletehome.name"), cmds.getString("plot.deletehome.description"), cmds.getString("plot.deletehome.usage")), cmds.getStringList("plot.deletehome.alias").toArray(new String[0]));
FuturePlots.getInstance().getServer().getCommandMap().register(cmds.getString("plot.name"), new MainCommand());
}

Expand Down Expand Up @@ -194,8 +196,10 @@ public void clearPlot(Plot plot) {
getServer().getScheduler().scheduleDelayedTask(this, new PlotClearTask(plot), 1, true);
for (Entity entity : getServer().getLevelByName(plot.getLevelName()).getEntities()) {
if(!(entity instanceof Player)) {
if(getPlotByPosition(entity.getLocation()).getX() == plot.getX() && getPlotByPosition(entity.getLocation()).getZ() == plot.getZ() && getPlotByPosition(entity.getLocation()).getLevelName().equals(plot.getLevelName())) {
entity.close();
if(entity != null) {
if(getPlotByPosition(entity.getLocation()).getX() == plot.getX() && getPlotByPosition(entity.getLocation()).getZ() == plot.getZ() && getPlotByPosition(entity.getLocation()).getLevelName().equals(plot.getLevelName())) {
entity.close();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package tim03we.futureplots.commands.sub;

/*
* This software is distributed under "GNU General Public License v3.0".
* This license allows you to use it and/or modify it but you are not at
* all allowed to sell this plugin at any cost. If found doing so the
* necessary action required would be taken.
*
* FuturePlots is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License v3.0 for more details.
*
* You should have received a copy of the GNU General Public License v3.0
* along with this program. If not, see
* <https://opensource.org/licenses/GPL-3.0>.
*/

import cn.nukkit.Player;
import cn.nukkit.command.CommandSender;
import tim03we.futureplots.FuturePlots;
import tim03we.futureplots.commands.BaseCommand;
import tim03we.futureplots.utils.Plot;
import tim03we.futureplots.utils.PlotPlayer;

public class DeleteHomeCommand extends BaseCommand {

public DeleteHomeCommand(String name, String description, String usage) {
super(name, description, usage);
}

@Override
public void execute(CommandSender sender, String command, String[] args) {
if(sender instanceof Player) {
Plot plot = new PlotPlayer((Player) sender).getPlot();
if(plot != null) {
if(plot.canByPass((Player) sender)) {
FuturePlots.provider.deleteHome(plot);
sender.sendMessage(translate(true, "plot.home.delete"));
} else {
sender.sendMessage(translate(true, "not.a.owner"));
}
} else {
sender.sendMessage(translate(true, "not.in.plot"));
}
}
}
}
18 changes: 15 additions & 3 deletions src/main/java/tim03we/futureplots/commands/sub/HomeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ public void execute(CommandSender sender, String command, String[] args) {
if(provider.getPlots(sender.getName(), args[2]).size() > 0) {
Plot plot = provider.getPlot(sender.getName(), Integer.parseInt(args[1]), args[2]);
if(plot != null) {
((Player) sender).teleport(plot.getBorderPosition());
if(provider.getHome(plot) != null) {
((Player) sender).teleport(provider.getHome(plot));
} else {
((Player) sender).teleport(plot.getBorderPosition());
}
sender.sendMessage(translate(true, "plot.teleport"));
} else {
sender.sendMessage(translate(true, "has.no.plot.world"));
Expand Down Expand Up @@ -75,7 +79,11 @@ public void execute(CommandSender sender, String command, String[] args) {
if(provider.getPlots(sender.getName(), Settings.levels.get(0)).size() > 0) {
Plot plot = provider.getPlot(sender.getName(), Integer.parseInt(args[1]), Settings.levels.get(0));
if(plot != null) {
((Player) sender).teleport(plot.getBorderPosition());
if(provider.getHome(plot) != null) {
((Player) sender).teleport(provider.getHome(plot));
} else {
((Player) sender).teleport(plot.getBorderPosition());
}
sender.sendMessage(translate(true, "plot.teleport"));
} else {
sender.sendMessage(translate(true, "has.no.plot.number", args[1]));
Expand All @@ -86,7 +94,11 @@ public void execute(CommandSender sender, String command, String[] args) {
}
} else {
Plot plot = provider.getPlot(sender.getName(), homeNumber, null);
((Player) sender).teleport(plot.getBorderPosition());
if(provider.getHome(plot) != null) {
((Player) sender).teleport(provider.getHome(plot));
} else {
((Player) sender).teleport(plot.getBorderPosition());
}
sender.sendMessage(translate(true, "plot.teleport"));
}
}
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/tim03we/futureplots/commands/sub/SetHomeCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package tim03we.futureplots.commands.sub;

/*
* This software is distributed under "GNU General Public License v3.0".
* This license allows you to use it and/or modify it but you are not at
* all allowed to sell this plugin at any cost. If found doing so the
* necessary action required would be taken.
*
* FuturePlots is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License v3.0 for more details.
*
* You should have received a copy of the GNU General Public License v3.0
* along with this program. If not, see
* <https://opensource.org/licenses/GPL-3.0>.
*/

import cn.nukkit.Player;
import cn.nukkit.command.CommandSender;
import tim03we.futureplots.FuturePlots;
import tim03we.futureplots.commands.BaseCommand;
import tim03we.futureplots.utils.Plot;
import tim03we.futureplots.utils.PlotPlayer;

public class SetHomeCommand extends BaseCommand {

public SetHomeCommand(String name, String description, String usage) {
super(name, description, usage);
}

@Override
public void execute(CommandSender sender, String command, String[] args) {
if(sender instanceof Player) {
Plot plot = new PlotPlayer((Player) sender).getPlot();
if(plot != null) {
if(plot.canByPass((Player) sender)) {
FuturePlots.provider.setHome(plot, ((Player) sender).getLocation());
sender.sendMessage(translate(true, "plot.home.set"));
} else {
sender.sendMessage(translate(true, "not.a.owner"));
}
} else {
sender.sendMessage(translate(true, "not.in.plot"));
}
}
}
}
7 changes: 7 additions & 0 deletions src/main/java/tim03we/futureplots/provider/DataProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* <https://opensource.org/licenses/GPL-3.0>.
*/

import cn.nukkit.level.Location;
import tim03we.futureplots.utils.Plot;

import java.util.List;
Expand Down Expand Up @@ -60,6 +61,12 @@ public interface DataProvider {

void removeDenied(String name, Plot plot);

void setHome(Plot plot, Location location);

void deleteHome(Plot plot);

Location getHome(Plot plot);

Plot getPlot(String name, Object number, Object level);

List<String> getPlots(String name, Object level);
Expand Down
69 changes: 67 additions & 2 deletions src/main/java/tim03we/futureplots/provider/MySQLProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
*/

import cn.nukkit.Server;
import cn.nukkit.level.Location;
import cn.nukkit.utils.Config;
import com.google.gson.Gson;
import tim03we.futureplots.FuturePlots;
import tim03we.futureplots.utils.Plot;
import tim03we.futureplots.utils.SQLHelper;
import tim03we.futureplots.utils.Settings;

import java.sql.*;
Expand All @@ -45,21 +47,32 @@ public void connect() {
Class.forName("com.mysql.cj.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://" + config.getString("mysql.host") + ":" + config.getString("mysql.port") + "/" + config.getString("mysql.database") + "?autoReconnect=true&useTimezone=true&serverTimezone=GMT%2B8", config.getString("mysql.user"), config.getString("mysql.password"));
connection.setAutoCommit(false);
checkAndCreate();
checkAndRun();
Server.getInstance().getLogger().info("[FuturePlots] Connection to MySQL database successful.");
} catch (SQLException | ClassNotFoundException ex) {
Server.getInstance().getLogger().error("[FuturePlots] No connection to the database could be established.");
ex.printStackTrace();
}
}

private void checkAndCreate() {
private void checkAndRun() {
CompletableFuture.runAsync(() -> {
String[] array = new String[]{"home VARCHAR(999)"};
if (connection != null) {
try {
PreparedStatement statement = connection.prepareStatement("CREATE TABLE IF NOT EXISTS plots(level VARCHAR(255), plotid VARCHAR(255), owner VARCHAR(255), helpers VARCHAR(999), members VARCHAR(999), denied VARCHAR(999), flags VARCHAR(999), mmerge VARCHAR(255), merges VARCHAR(999));");
statement.executeUpdate();
statement.close();

for (String s : array) {
String[] ex = s.split(" ");
if(!new SQLHelper(connection).columnExists(ex[0])) {
statement = connection.prepareStatement("ALTER TABLE plots ADD COLUMN " + s + ";");
statement.executeUpdate();
statement.close();
connection.commit();
}
}
} catch (Exception e) {
if(Settings.debug) e.printStackTrace();
}
Expand Down Expand Up @@ -314,6 +327,58 @@ public void removeDenied(String name, Plot plot) {
});
}

@Override
public void setHome(Plot plot, Location location) {
CompletableFuture.runAsync(() -> {
try {
PreparedStatement statement = connection.prepareStatement("UPDATE plots SET home = ? WHERE level = ? AND plotid = ?;");
statement.setString(1, location.getX() + ":" + location.getY() + ":" + location.getZ());
statement.setString(2, plot.getLevelName());
statement.setString(3, plot.getFullID());
statement.executeUpdate();
connection.commit();
} catch (SQLException e) {
if(Settings.debug) e.printStackTrace();
}
});
}

@Override
public void deleteHome(Plot plot) {
CompletableFuture.runAsync(() -> {
try {
PreparedStatement statement = connection.prepareStatement("UPDATE plots SET home = ? WHERE level = ? AND plotid = ?;");
statement.setString(1, null);
statement.setString(2, plot.getLevelName());
statement.setString(3, plot.getFullID());
statement.executeUpdate();
connection.commit();
} catch (SQLException e) {
if(Settings.debug) e.printStackTrace();
}
});
}

@Override
public Location getHome(Plot plot) {
try {
PreparedStatement statement = connection.prepareStatement("SELECT * FROM plots WHERE level = ? AND plotid = ?");
statement.setString(1, plot.getLevelName());
statement.setString(2, plot.getFullID());
ResultSet result = statement.executeQuery();
result.next();
connection.commit();
String locationString = result.getString("home");
if(locationString != null) {
String[] ex = result.getString("home").split(":");
return new Location(Double.parseDouble(ex[0]), Double.parseDouble(ex[1]), Double.parseDouble(ex[2]), Server.getInstance().getLevelByName(plot.getLevelName()));
}
} catch (SQLException e) {
if(Settings.debug) e.printStackTrace();
}
return null;
}

@Override
public Plot getPlot(String name, Object number, Object level) {
int i = 1;
Expand Down

0 comments on commit 659344c

Please sign in to comment.