Implement PlotComponentSetEvent

This commit is contained in:
manuelgu 2016-05-25 21:49:55 +02:00
parent ef60aeb017
commit ceb8fb9fa3
8 changed files with 136 additions and 3 deletions

View File

@ -0,0 +1,56 @@
package com.plotsquared.bukkit.events;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import org.bukkit.event.HandlerList;
/**
* Called when a plot component is set
*
*/
public class PlotComponentSetEvent extends PlotEvent {
private static final HandlerList handlers = new HandlerList();
private final String component;
public PlotComponentSetEvent(Plot plot, String component) {
super(plot);
this.component = component;
}
public static HandlerList getHandlerList() {
return handlers;
}
/**
* Get the PlotId
*
* @return PlotId
*/
public PlotId getPlotId() {
return getPlot().getId();
}
/**
* Get the world name
*
* @return String
*/
public String getWorld() {
return getPlot().getArea().worldname;
}
/**
* Get the component which was set
*
* @return Component name
*/
public String getComponent() {
return this.component;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
}

View File

@ -109,7 +109,6 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.projectiles.BlockProjectileSource;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;

View File

@ -18,6 +18,7 @@ import com.plotsquared.bukkit.events.PlayerPlotHelperEvent;
import com.plotsquared.bukkit.events.PlayerPlotTrustedEvent;
import com.plotsquared.bukkit.events.PlayerTeleportToPlotEvent;
import com.plotsquared.bukkit.events.PlotClearEvent;
import com.plotsquared.bukkit.events.PlotComponentSetEvent;
import com.plotsquared.bukkit.events.PlotDeleteEvent;
import com.plotsquared.bukkit.events.PlotFlagAddEvent;
import com.plotsquared.bukkit.events.PlotFlagRemoveEvent;
@ -57,6 +58,11 @@ public class BukkitEventUtil extends EventUtil {
return callEvent(new PlayerTeleportToPlotEvent(getPlayer(player), from, plot));
}
@Override
public boolean callComponentSet(Plot plot, String component) {
return callEvent(new PlotComponentSetEvent(plot, component));
}
@Override
public boolean callClear(Plot plot) {
return callEvent(new PlotClearEvent(plot));

View File

@ -7,9 +7,9 @@ import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.SetQueue;
import java.util.ArrayList;
/**
@ -22,27 +22,35 @@ public class ClassicPlotManager extends SquarePlotManager {
switch (component) {
case "floor":
setFloor(plotworld, plotid, blocks);
EventUtil.manager.callComponentSet(plotworld.getPlot(plotid), component);
return true;
case "wall":
setWallFilling(plotworld, plotid, blocks);
EventUtil.manager.callComponentSet(plotworld.getPlot(plotid), component);
return true;
case "all":
setAll(plotworld, plotid, blocks);
EventUtil.manager.callComponentSet(plotworld.getPlot(plotid), component);
return true;
case "air":
setAir(plotworld, plotid, blocks);
EventUtil.manager.callComponentSet(plotworld.getPlot(plotid), component);
return true;
case "main":
setMain(plotworld, plotid, blocks);
EventUtil.manager.callComponentSet(plotworld.getPlot(plotid), component);
return true;
case "middle":
setMiddle(plotworld, plotid, blocks);
EventUtil.manager.callComponentSet(plotworld.getPlot(plotid), component);
return true;
case "outline":
setOutline(plotworld, plotid, blocks);
EventUtil.manager.callComponentSet(plotworld.getPlot(plotid), component);
return true;
case "border":
setWall(plotworld, plotid, blocks);
EventUtil.manager.callComponentSet(plotworld.getPlot(plotid), component);
return true;
}
return false;

View File

@ -31,6 +31,8 @@ public abstract class EventUtil {
public abstract boolean callTeleport(PlotPlayer player, Location from, Plot plot);
public abstract boolean callComponentSet(Plot plot, String component);
public abstract boolean callClear(Plot plot);
public abstract void callDelete(Plot plot);

View File

@ -26,6 +26,8 @@ public class EventUtilTest extends EventUtil {
return false;
}
@Override public boolean callComponentSet(Plot plot, String component) { return false; }
@Override public boolean callClear(Plot plot) {
return false;
}
@ -61,4 +63,4 @@ public class EventUtilTest extends EventUtil {
@Override public void callTrusted(PlotPlayer initiator, Plot plot, UUID player, boolean added) {}
@Override public void callMember(PlotPlayer initiator, Plot plot, UUID player, boolean added) {}
}
}

View File

@ -0,0 +1,54 @@
package com.plotsquared.sponge.events;
import com.intellectualcrafters.plot.object.Plot;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.event.impl.AbstractEvent;
import com.intellectualcrafters.plot.object.PlotId;
public class PlotComponentSetEvent extends AbstractEvent {
private final Plot plot;
private final String component;
/**
* PlotDeleteEvent: Called when a plot is deleted
*
* @param plot The plot that was deleted
*/
public PlotComponentSetEvent(Plot plot, String component) {
this.plot = plot;
this.component = component;
}
/**
* Get the PlotId
*
* @return PlotId
*/
public PlotId getPlotId() {
return this.plot.getId();
}
/**
* Get the world name
*
* @return String
*/
public String getWorld() {
return this.plot.getArea().worldname;
}
/**
* Get the component which was set
*
* @return Component name
*/
public String getComponent() {
return this.component;
}
@Override
public Cause getCause() {
return null;
}
}

View File

@ -19,6 +19,7 @@ import com.plotsquared.sponge.events.PlayerPlotHelperEvent;
import com.plotsquared.sponge.events.PlayerPlotTrustedEvent;
import com.plotsquared.sponge.events.PlayerTeleportToPlotEvent;
import com.plotsquared.sponge.events.PlotClearEvent;
import com.plotsquared.sponge.events.PlotComponentSetEvent;
import com.plotsquared.sponge.events.PlotDeleteEvent;
import com.plotsquared.sponge.events.PlotFlagAddEvent;
import com.plotsquared.sponge.events.PlotFlagRemoveEvent;
@ -52,6 +53,11 @@ public class SpongeEventUtil extends EventUtil {
public boolean callTeleport(PlotPlayer player, Location from, Plot plot) {
return callEvent(new PlayerTeleportToPlotEvent(SpongeUtil.getPlayer(player), from, plot));
}
@Override
public boolean callComponentSet(Plot plot, String component) {
return callEvent(new PlotComponentSetEvent(plot, component));
}
@Override
public boolean callClear(Plot plot) {