diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 787ba6c62..f3194d9c9 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -13,14 +13,11 @@
-
+
+
-
-
-
-
-
+
@@ -44,21 +41,21 @@
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
@@ -68,17 +65,40 @@
-
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -87,90 +107,78 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -181,16 +189,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -209,7 +207,6 @@
-
@@ -226,14 +223,17 @@
-
-
+
+
+
+
+
@@ -685,7 +685,7 @@
-
+
1411382351159
@@ -759,11 +759,15 @@
1412011248692
1412011248692
-
+
+ 1412262034394
+ 1412262034394
+
+
-
+
@@ -787,7 +791,7 @@
-
+
@@ -801,7 +805,8 @@
-
+
+
@@ -812,7 +817,6 @@
-
@@ -847,11 +851,12 @@
-
+
+
-
+
@@ -859,27 +864,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -918,13 +902,6 @@
-
-
-
-
-
-
-
@@ -1148,14 +1125,6 @@
-
-
-
-
-
-
-
-
@@ -1174,22 +1143,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1198,54 +1151,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1267,22 +1172,134 @@
-
+
-
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/PlotSquared/src/com/intellectualcrafters/plot/C.java b/PlotSquared/src/com/intellectualcrafters/plot/C.java
index c726abdf3..4f050e645 100644
--- a/PlotSquared/src/com/intellectualcrafters/plot/C.java
+++ b/PlotSquared/src/com/intellectualcrafters/plot/C.java
@@ -18,7 +18,15 @@ import org.bukkit.ChatColor;
*
*/
public enum C {
- /**
+ /*
+ * Ratings
+ */
+ RATING_NOT_VALID("&cYou need to specify a number between 1 and 10"),
+ RATING_ALREADY_EXISTS("&cYou have already rated plot &c%s"),
+ RATING_APPLIED("&cYou successfully rated plot &6%s"),
+ RATING_NOT_YOUR_OWN("&cYou cannot rate your own plot"),
+ RATING_NOT_OWNED("&cYou cannot rate a plot that is not claimed by anyone"),
+ /*
* Economy Stuff
*/
CANNOT_AFFORD_PLOT("&cYou cannot afford to buy this plot. It costs &6%s"),
@@ -85,6 +93,7 @@ public enum C {
/*
*
*/
+ COMMAND_WENT_WRONG("&cSomething went wrong when executing that command..."),
/*
* No {plot}
*/
@@ -124,7 +133,7 @@ public enum C {
/*
* Info
*/
- PLOT_INFO_UNCLAIMED("&cPlot &6%s&c is not yet claimed"), PLOT_INFO("plot ID: &6%id%&c, plot Alias: &6%alias%&c, plot Owner: &6%owner%&c, plot Biome: &6%biome%&c, plot Time: &6%time%&c, plot Weather: &6%weather%&c, plot Helpers:&6%helpers%&c, plot Trusted:&6%trusted%&c, plot Denied:&6%denied%&c, plot flags: &6%flags%"), PLOT_USER_LIST(" &6%user%&c,"),
+ PLOT_INFO_UNCLAIMED("&cPlot &6%s&c is not yet claimed"), PLOT_INFO("plot ID: &6%id%&c, plot Alias: &6%alias%&c, plot Owner: &6%owner%&c, plot Biome: &6%biome%&c, plot Time: &6%time%&c, plot Weather: &6%weather%&c, plot Helpers:&6%helpers%&c, plot Trusted:&6%trusted%&c, plot Denied:&6%denied%&c, plot Rating: &6%rating%, &cplot flags: &6%flags%"), PLOT_USER_LIST(" &6%user%&c,"),
/*
* Generating
*/
diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java
index 1e5cf9ee5..f46fbd838 100644
--- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java
+++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java
@@ -90,6 +90,7 @@ public class Info extends SubCommand {
info = info.replaceAll("%helpers%", getPlayerList(plot.helpers));
info = info.replaceAll("%trusted%", getPlayerList(plot.trusted));
info = info.replaceAll("%denied%", getPlayerList(plot.denied));
+ info = info.replaceAll("%rating%", "" + DBFunc.getRatings(plot));
info = info.replaceAll("%flags%", StringUtils.join(plot.settings.getFlags(), "").length() > 0 ? StringUtils.join(plot.settings.getFlags(), ",") : "none");
//PlayerFunctions.sendMessage(player, PlayerFunctions.getTopPlot(player.getWorld(), plot).id.toString());
//PlayerFunctions.sendMessage(player, PlayerFunctions.getBottomPlot(player.getWorld(), plot).id.toString());
diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Rate.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Rate.java
new file mode 100644
index 000000000..a74aa68eb
--- /dev/null
+++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Rate.java
@@ -0,0 +1,70 @@
+package com.intellectualcrafters.plot.commands;
+
+import com.intellectualcrafters.plot.C;
+import com.intellectualcrafters.plot.PlayerFunctions;
+import com.intellectualcrafters.plot.Plot;
+import org.bukkit.entity.Player;
+
+/**
+ * Created by Citymonstret on 2014-10-02.
+ */
+public class Rate extends SubCommand {
+
+ /*
+ String cmd, String permission, String description, String usage, String alias, CommandCategory category
+ */
+
+ public Rate() {
+ super("rate", "plots.rate", "Rate the plot", "rate {0-10}", "rt", CommandCategory.ACTIONS);
+ }
+
+ @Override
+ public boolean execute(Player plr, String... args) {
+ if(args.length < 1) {
+ sendMessage(plr, C.RATING_NOT_VALID);
+ return true;
+ }
+ if(!PlayerFunctions.isInPlot(plr)) {
+ sendMessage(plr, C.NOT_IN_PLOT);
+ return true;
+ }
+ Plot plot = PlayerFunctions.getCurrentPlot(plr);
+ if(!plot.hasOwner()) {
+ sendMessage(plr, C.RATING_NOT_OWNED);
+ return true;
+ }
+ if(plot.getOwner().equals(plr.getUniqueId())) {
+ sendMessage(plr, C.RATING_NOT_YOUR_OWN);
+ return true;
+ }
+ String arg = args[0];
+ boolean o = false;
+ for(char c : arg.toCharArray()) {
+ if(!Character.isDigit(c)) {
+ o = true;
+ break;
+ }
+ }
+ int rating = 0;
+ if(!o) {
+ rating = Integer.parseInt(arg);
+ }
+ if(o || (rating < 0 || rating > 10)) {
+ sendMessage(plr, C.RATING_NOT_VALID);
+ return true;
+ }
+ //TODO implement check for already rated
+ boolean rated = false;
+ if(rated) {
+ sendMessage(plr, C.RATING_ALREADY_EXISTS, plot.getId().toString());
+ }
+ //TODO actually do something...
+ boolean success = false;
+ if(success) {
+ sendMessage(plr, C.RATING_APPLIED, plot.getId().toString());
+ } else {
+ sendMessage(plr, C.COMMAND_WENT_WRONG);
+ }
+ return true;
+ }
+}
diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/SubCommand.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/SubCommand.java
index 14b32532a..b36355332 100644
--- a/PlotSquared/src/com/intellectualcrafters/plot/commands/SubCommand.java
+++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/SubCommand.java
@@ -90,6 +90,8 @@ public abstract class SubCommand {
this.category = category;
}
+
+
/**
* Execute.
*
diff --git a/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java b/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java
index 1ecf08f61..46d9f10df 100644
--- a/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java
+++ b/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java
@@ -223,6 +223,7 @@ public class DBFunc {
stmt.addBatch("CREATE TABLE IF NOT EXISTS `plot_helpers` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
stmt.addBatch("CREATE TABLE IF NOT EXISTS `plot_trusted` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
stmt.addBatch("CREATE TABLE IF NOT EXISTS `plot_settings` (" + " `plot_plot_id` INT(11) NOT NULL," + " `biome` VARCHAR(45) DEFAULT 'FOREST'," + " `rain` INT(1) DEFAULT 0," + " `custom_time` TINYINT(1) DEFAULT '0'," + " `time` INT(11) DEFAULT '8000'," + " `deny_entry` TINYINT(1) DEFAULT '0'," + " `alias` VARCHAR(50) DEFAULT NULL," + " `flags` VARCHAR(512) DEFAULT NULL," + " `merged` INT(11) DEFAULT NULL," + " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT'," + " PRIMARY KEY (`plot_plot_id`)," + " UNIQUE KEY `unique_alias` (`alias`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
+ stmt.addBatch("CREATE TABLE IF NOT EXISTS `plot_ratings` ( `plot_plot_id` INT(11) NOT NULL, `rating` INT(2) NOT NULL, `player` VARCHAR(40) NOT NULL, PRIMARY KEY(`plot_plot_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8");
if (add_constraint) {
stmt.addBatch("ALTER TABLE `plot_settings` ADD CONSTRAINT `plot_settings_ibfk_1` FOREIGN KEY (`plot_plot_id`) REFERENCES `plot` (`id`) ON DELETE CASCADE");
}
@@ -233,6 +234,7 @@ public class DBFunc {
stmt.addBatch("CREATE TABLE IF NOT EXISTS `plot_helpers` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")");
stmt.addBatch("CREATE TABLE IF NOT EXISTS `plot_trusted` (" + "`plot_plot_id` INT(11) NOT NULL," + "`user_uuid` VARCHAR(40) NOT NULL" + ")");
stmt.addBatch("CREATE TABLE IF NOT EXISTS `plot_settings` (" + " `plot_plot_id` INT(11) NOT NULL," + " `biome` VARCHAR(45) DEFAULT 'FOREST'," + " `rain` INT(1) DEFAULT 0," + " `custom_time` TINYINT(1) DEFAULT '0'," + " `time` INT(11) DEFAULT '8000'," + " `deny_entry` TINYINT(1) DEFAULT '0'," + " `alias` VARCHAR(50) DEFAULT NULL," + " `flags` VARCHAR(512) DEFAULT NULL," + " `merged` INT(11) DEFAULT NULL," + " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT'," + " PRIMARY KEY (`plot_plot_id`)" + ")");
+ stmt.addBatch("CREATE TABLE IF NOT EXISTS `plot_ratings` (`plot_plot_id` INT(11) NOT NULL, `rating` INT(2) NOT NULL, `player` VARCHAR(40) NOT NULL, PRIMARY KEY(`plot_plot_id`))");
}
stmt.executeBatch();
@@ -844,4 +846,22 @@ public class DBFunc {
}
});
}
+
+ public static double getRatings(final Plot plot) {
+ try {
+ PreparedStatement statement = connection.prepareStatement("SELECT AVG(`rating`) AS `rating` FROM `plot_ratings` WHERE `plot_plot_id` = ? ");
+ statement.setInt(1, getId(plot.getWorld().getName(), plot.id));
+ ResultSet set = statement.executeQuery();
+ double rating = 0;
+ while(set.next()) {
+ rating = set.getDouble("rating");
+ }
+ statement.close();
+ return rating;
+ } catch (SQLException e) {
+ Logger.add(LogLevel.WARNING, "Failed to fetch rating for plot " + plot.getId().toString());
+ e.printStackTrace();
+ }
+ return 0.0d;
+ }
}