2014-11-08 20:27:09 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
|
|
|
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
|
|
|
// /
|
|
|
|
// This program is free software; you can redistribute it and/or modify /
|
|
|
|
// it under the terms of the GNU General Public License as published by /
|
|
|
|
// the Free Software Foundation; either version 3 of the License, or /
|
|
|
|
// (at your option) any later version. /
|
|
|
|
// /
|
|
|
|
// This program 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 for more details. /
|
|
|
|
// /
|
|
|
|
// You should have received a copy of the GNU General Public License /
|
|
|
|
// along with this program; if not, write to the Free Software Foundation, /
|
|
|
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
|
|
|
// /
|
|
|
|
// You can contact us via: support@intellectualsites.com /
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
package com.intellectualcrafters.plot.commands;
|
2014-10-03 04:36:30 +02:00
|
|
|
|
2014-11-16 10:48:18 +01:00
|
|
|
import com.intellectualcrafters.plot.config.C;
|
2014-11-15 12:05:48 +01:00
|
|
|
import com.intellectualcrafters.plot.database.DBFunc;
|
2015-02-22 08:03:25 +01:00
|
|
|
import com.intellectualcrafters.plot.object.Location;
|
2014-11-16 10:48:18 +01:00
|
|
|
import com.intellectualcrafters.plot.object.Plot;
|
2015-02-21 12:38:44 +01:00
|
|
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
2015-02-22 07:06:59 +01:00
|
|
|
import com.intellectualcrafters.plot.util.MainUtil;
|
2014-12-30 14:09:11 +01:00
|
|
|
|
2015-02-20 07:34:19 +01:00
|
|
|
public class Rate extends SubCommand {
|
2014-11-05 04:42:08 +01:00
|
|
|
/*
|
|
|
|
* 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, true);
|
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
@Override
|
2015-02-21 08:30:55 +01:00
|
|
|
public boolean execute(final PlotPlayer plr, final String... args) {
|
2014-11-05 04:42:08 +01:00
|
|
|
if (args.length < 1) {
|
|
|
|
sendMessage(plr, C.RATING_NOT_VALID);
|
|
|
|
return true;
|
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
final Location loc = plr.getLocation();
|
2015-02-21 13:01:15 +01:00
|
|
|
final Plot plot = MainUtil.getPlot(loc);
|
2015-02-22 08:03:25 +01:00
|
|
|
if (plot == null) {
|
|
|
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
|
|
|
}
|
2014-11-05 04:42:08 +01:00
|
|
|
if (!plot.hasOwner()) {
|
|
|
|
sendMessage(plr, C.RATING_NOT_OWNED);
|
|
|
|
return true;
|
|
|
|
}
|
2015-03-20 04:00:02 +01:00
|
|
|
if (plot.isOwner(plr.getUUID())) {
|
2014-11-05 04:42:08 +01:00
|
|
|
sendMessage(plr, C.RATING_NOT_YOUR_OWN);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
final String arg = args[0];
|
|
|
|
boolean o = false;
|
|
|
|
for (final 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
|
2014-11-15 12:05:48 +01:00
|
|
|
boolean rated = true;
|
|
|
|
try {
|
|
|
|
DBFunc.getRatings(plot);
|
2014-12-18 03:15:11 +01:00
|
|
|
} catch (final Exception e) {
|
2014-11-15 12:05:48 +01:00
|
|
|
rated = false;
|
|
|
|
}
|
2014-11-05 04:42:08 +01:00
|
|
|
if (rated) {
|
|
|
|
sendMessage(plr, C.RATING_ALREADY_EXISTS, plot.getId().toString());
|
2015-05-15 11:32:38 +02:00
|
|
|
return false;
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2014-12-16 06:03:20 +01:00
|
|
|
final boolean success = true;
|
2014-11-05 04:42:08 +01:00
|
|
|
if (success) {
|
|
|
|
sendMessage(plr, C.RATING_APPLIED, plot.getId().toString());
|
2014-12-18 03:15:11 +01:00
|
|
|
} else {
|
2014-11-05 04:42:08 +01:00
|
|
|
sendMessage(plr, C.COMMAND_WENT_WRONG);
|
|
|
|
}
|
2015-05-14 14:55:57 +02:00
|
|
|
DBFunc.setRating(plot, plr.getUUID(), rating);
|
2014-11-05 04:42:08 +01:00
|
|
|
return true;
|
|
|
|
}
|
2014-10-02 17:38:31 +02:00
|
|
|
}
|