mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-27 11:14:43 +02:00
Started working on rate system :D
This commit is contained in:
@ -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
|
||||
*/
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -90,6 +90,8 @@ public abstract class SubCommand {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Execute.
|
||||
*
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user