diff --git a/PlotSquared/pom.xml b/PlotSquared/pom.xml
index 13b14b2fc..71a5a1fc6 100644
--- a/PlotSquared/pom.xml
+++ b/PlotSquared/pom.xml
@@ -103,5 +103,10 @@
1.5
provided
+
+ com.google.code.gson
+ gson
+ 2.3.1
+
\ No newline at end of file
diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java
index 726ced113..b619e44e3 100644
--- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java
+++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java
@@ -26,6 +26,7 @@ import java.util.Comparator;
import java.util.Map.Entry;
import java.util.UUID;
+import com.intellectualcrafters.plot.events.PlotRateEvent;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.mutable.MutableInt;
@@ -41,6 +42,7 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.Rating;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.TaskManager;
+import org.bukkit.Bukkit;
public class Rate extends SubCommand {
/*
@@ -116,9 +118,17 @@ public class Rate extends SubCommand {
index.increment();
if (index.intValue() >= Settings.RATING_CATEGORIES.size()) {
close();
- // set rating!
- plot.settings.ratings.put(player.getUUID(), rating.intValue());
- DBFunc.setRating(plot, player.getUUID(), rating.intValue());
+ // handle ratings
+ int rV = rating.intValue();
+ // CALL THE EVENT
+ PlotRateEvent rateEvent = new PlotRateEvent(player, rV, plot);
+ Bukkit.getPluginManager().callEvent(rateEvent);
+ // DONE CALLING THE EVENT
+ // get new rating
+ rV = rateEvent.getRating();
+ // set rating
+ plot.settings.ratings.put(player.getUUID(), rV);
+ DBFunc.setRating(plot, player.getUUID(), rV);
sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
return false;
diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerLeavePlotEvent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerLeavePlotEvent.java
index 0a26eca47..725c22d43 100644
--- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerLeavePlotEvent.java
+++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerLeavePlotEvent.java
@@ -31,6 +31,7 @@ import com.intellectualcrafters.plot.object.Plot;
* @author Empire92
*/
public class PlayerLeavePlotEvent extends PlayerEvent {
+
private static HandlerList handlers = new HandlerList();
private final Plot plot;
diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerPlotDeniedEvent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerPlotDeniedEvent.java
index 97b90f61f..df438348e 100644
--- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerPlotDeniedEvent.java
+++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerPlotDeniedEvent.java
@@ -32,9 +32,9 @@ import com.intellectualcrafters.plot.object.Plot;
* @author Citymonstret
* @author Empire92
*/
-public class PlayerPlotDeniedEvent extends Event {
+public class PlayerPlotDeniedEvent extends PlotEvent {
+
private static HandlerList handlers = new HandlerList();
- private final Plot plot;
private final Player initiator;
private final boolean added;
private final UUID player;
@@ -48,8 +48,8 @@ public class PlayerPlotDeniedEvent extends Event {
* @param added true of add to deny list, false if removed
*/
public PlayerPlotDeniedEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) {
+ super(plot);
this.initiator = initiator;
- this.plot = plot;
this.added = added;
this.player = player;
}
@@ -76,15 +76,6 @@ public class PlayerPlotDeniedEvent extends Event {
return this.player;
}
- /**
- * The plot involved
- *
- * @return Plot
- */
- public Plot getPlot() {
- return this.plot;
- }
-
/**
* The player initiating the action
*
diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerPlotHelperEvent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerPlotHelperEvent.java
index c5b9a0909..a81d3f0c3 100644
--- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerPlotHelperEvent.java
+++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerPlotHelperEvent.java
@@ -32,9 +32,9 @@ import com.intellectualcrafters.plot.object.Plot;
* @author Empire92
* @author Citymonstret
*/
-public class PlayerPlotHelperEvent extends Event {
+public class PlayerPlotHelperEvent extends PlotEvent {
+
private static HandlerList handlers = new HandlerList();
- private final Plot plot;
private final Player initiator;
private final boolean added;
private final UUID player;
@@ -48,8 +48,8 @@ public class PlayerPlotHelperEvent extends Event {
* @param added true of the player was added, false if the player was removed
*/
public PlayerPlotHelperEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) {
+ super(plot);
this.initiator = initiator;
- this.plot = plot;
this.added = added;
this.player = player;
}
@@ -76,15 +76,6 @@ public class PlayerPlotHelperEvent extends Event {
return this.player;
}
- /**
- * The plot involved
- *
- * @return Plot
- */
- public Plot getPlot() {
- return this.plot;
- }
-
/**
* The player initiating the action
*
diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerPlotTrustedEvent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerPlotTrustedEvent.java
index 02248ebc3..847afa619 100644
--- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerPlotTrustedEvent.java
+++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerPlotTrustedEvent.java
@@ -32,9 +32,9 @@ import com.intellectualcrafters.plot.object.Plot;
* @author Citymonstret
* @author Empire92
*/
-public class PlayerPlotTrustedEvent extends Event {
+public class PlayerPlotTrustedEvent extends PlotEvent {
+
private static HandlerList handlers = new HandlerList();
- private final Plot plot;
private final Player initiator;
private final boolean added;
private final UUID player;
@@ -48,8 +48,8 @@ public class PlayerPlotTrustedEvent extends Event {
* @param added true of the player was added, false if the player was removed
*/
public PlayerPlotTrustedEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) {
+ super(plot);
this.initiator = initiator;
- this.plot = plot;
this.added = added;
this.player = player;
}
@@ -76,15 +76,6 @@ public class PlayerPlotTrustedEvent extends Event {
return this.player;
}
- /**
- * The plot involved
- *
- * @return Plot
- */
- public Plot getPlot() {
- return this.plot;
- }
-
/**
* The player initiating the action
*
diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotEvent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotEvent.java
new file mode 100644
index 000000000..395263c23
--- /dev/null
+++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotEvent.java
@@ -0,0 +1,20 @@
+package com.intellectualcrafters.plot.events;
+
+import com.intellectualcrafters.plot.object.Plot;
+import com.sk89q.worldedit.event.Cancellable;
+import org.bukkit.event.Event;
+import org.bukkit.event.HandlerList;
+
+public abstract class PlotEvent extends Event {
+
+ private final Plot plot;
+
+ public PlotEvent(final Plot plot) {
+ this.plot = plot;
+ }
+
+ public final Plot getPlot() {
+ return this.plot;
+ }
+
+}
diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotFlagAddEvent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotFlagAddEvent.java
index b8c00be8b..98e74ea45 100644
--- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotFlagAddEvent.java
+++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotFlagAddEvent.java
@@ -33,9 +33,9 @@ import com.intellectualcrafters.plot.object.Plot;
* @author Citymonstret
* @author Empire92
*/
-public class PlotFlagAddEvent extends Event implements Cancellable {
+public class PlotFlagAddEvent extends PlotEvent implements Cancellable {
+
private static HandlerList handlers = new HandlerList();
- private final Plot plot;
private final Flag flag;
private boolean cancelled;
@@ -46,7 +46,7 @@ public class PlotFlagAddEvent extends Event implements Cancellable {
* @param plot Plot to which the flag was added
*/
public PlotFlagAddEvent(final Flag flag, final Plot plot) {
- this.plot = plot;
+ super(plot);
this.flag = flag;
}
@@ -54,15 +54,6 @@ public class PlotFlagAddEvent extends Event implements Cancellable {
return handlers;
}
- /**
- * Get the plot involved
- *
- * @return Plot
- */
- public Plot getPlot() {
- return this.plot;
- }
-
/**
* Get the flag involved
*
@@ -78,12 +69,12 @@ public class PlotFlagAddEvent extends Event implements Cancellable {
}
@Override
- public boolean isCancelled() {
+ public final boolean isCancelled() {
return this.cancelled;
}
@Override
- public void setCancelled(final boolean b) {
- this.cancelled = b;
+ public final void setCancelled(boolean cancelled) {
+ this.cancelled = cancelled;
}
}
diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotFlagRemoveEvent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotFlagRemoveEvent.java
index 0e813f7bf..be003fdcc 100644
--- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotFlagRemoveEvent.java
+++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotFlagRemoveEvent.java
@@ -33,9 +33,9 @@ import com.intellectualcrafters.plot.object.Plot;
* @author Citymonstret
* @author Empire92
*/
-public class PlotFlagRemoveEvent extends Event implements Cancellable {
+public class PlotFlagRemoveEvent extends PlotEvent implements Cancellable {
+
private static HandlerList handlers = new HandlerList();
- private final Plot plot;
private final Flag flag;
private boolean cancelled;
@@ -46,7 +46,7 @@ public class PlotFlagRemoveEvent extends Event implements Cancellable {
* @param plot Plot from which the flag was removed
*/
public PlotFlagRemoveEvent(final Flag flag, final Plot plot) {
- this.plot = plot;
+ super(plot);
this.flag = flag;
}
@@ -54,14 +54,6 @@ public class PlotFlagRemoveEvent extends Event implements Cancellable {
return handlers;
}
- /**
- * Get the plot involved
- *
- * @return Plot
- */
- public Plot getPlot() {
- return this.plot;
- }
/**
* Get the flag involved
@@ -78,12 +70,12 @@ public class PlotFlagRemoveEvent extends Event implements Cancellable {
}
@Override
- public boolean isCancelled() {
+ public final boolean isCancelled() {
return this.cancelled;
}
@Override
- public void setCancelled(final boolean b) {
- this.cancelled = b;
+ public final void setCancelled(boolean cancelled) {
+ this.cancelled = cancelled;
}
}
diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotRateEvent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotRateEvent.java
new file mode 100644
index 000000000..e81715575
--- /dev/null
+++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotRateEvent.java
@@ -0,0 +1,46 @@
+package com.intellectualcrafters.plot.events;
+
+import com.intellectualcrafters.plot.object.Plot;
+import com.intellectualcrafters.plot.object.PlotPlayer;
+
+import org.bukkit.event.HandlerList;
+
+/**
+ * Created 2015-07-13 for PlotSquaredGit
+ *
+ * @author Citymonstret
+ */
+public class PlotRateEvent extends PlotEvent {
+
+ private static HandlerList handlers = new HandlerList();
+ private final PlotPlayer rater;
+ private int rating;
+
+ public PlotRateEvent(final PlotPlayer rater, final int rating, final Plot plot) {
+ super(plot);
+ this.rater = rater;
+ this.rating = rating;
+ }
+
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+
+ public PlotPlayer getRater() {
+ return this.rater;
+ }
+
+ public void setRating(int rating) {
+ this.rating = rating;
+ }
+
+ public int getRating() {
+ return this.rating;
+ }
+
+ @Override
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+}
diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/StringComparison.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/StringComparison.java
index 6086f8454..8f6f91efd 100644
--- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/StringComparison.java
+++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/StringComparison.java
@@ -29,22 +29,13 @@ import org.apache.commons.lang.StringUtils;
* String comparison library
*
* @author Citymonstret
+ * @author Empire92
*/
@SuppressWarnings("unused")
public class StringComparison {
- /**
- * Best Match
- */
+
private T bestMatch;
- /**
- * Match Value
- *
- * Can be checked for low match (< .25 or something)
- */
private double match = Integer.MAX_VALUE;
- /**
- * The actual object
- */
private T bestMatchObject;
/**
@@ -154,11 +145,21 @@ public class StringComparison {
public ComparisonResult getBestMatchAdvanced() {
return new ComparisonResult(this.match, this.bestMatch);
}
-
+
+ /**
+ * The comparison result
+ */
public class ComparisonResult {
- public T best;
+
+ public final T best;
public final double match;
- public ComparisonResult(double match, T best) {
+
+ /**
+ * The constructor
+ * @param match Match value
+ * @param best Best Match
+ */
+ public ComparisonResult(final double match, final T best) {
this.match = match;
this.best = best;
}