This commit is contained in:
Sauilitired 2015-07-13 19:48:22 +02:00
parent 857e7d29f4
commit 5ddb9db6ea
11 changed files with 121 additions and 82 deletions

View File

@ -103,5 +103,10 @@
<version>1.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
</dependencies>
</project>

View File

@ -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;

View File

@ -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;

View File

@ -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
*

View File

@ -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
*

View File

@ -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
*

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -29,22 +29,13 @@ import org.apache.commons.lang.StringUtils;
* String comparison library
*
* @author Citymonstret
* @author Empire92
*/
@SuppressWarnings("unused")
public class StringComparison<T> {
/**
* 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<T> {
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;
}