PlotSquared/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java

130 lines
4.7 KiB
Java
Raw Normal View History

2015-07-30 16:25:16 +02:00
package com.plotsquared.sponge.util;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
2016-02-19 18:50:38 +01:00
import com.intellectualcrafters.plot.object.PlotArea;
2015-07-30 16:25:16 +02:00
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
2015-08-08 09:36:02 +02:00
import com.intellectualcrafters.plot.object.Rating;
2015-07-30 16:25:16 +02:00
import com.intellectualcrafters.plot.util.EventUtil;
import com.plotsquared.sponge.SpongeMain;
import com.plotsquared.sponge.events.ClusterFlagRemoveEvent;
import com.plotsquared.sponge.events.PlayerClaimPlotEvent;
import com.plotsquared.sponge.events.PlayerEnterPlotEvent;
import com.plotsquared.sponge.events.PlayerLeavePlotEvent;
import com.plotsquared.sponge.events.PlayerPlotDeniedEvent;
import com.plotsquared.sponge.events.PlayerPlotHelperEvent;
import com.plotsquared.sponge.events.PlayerPlotTrustedEvent;
import com.plotsquared.sponge.events.PlayerTeleportToPlotEvent;
import com.plotsquared.sponge.events.PlotClearEvent;
2016-05-25 21:49:55 +02:00
import com.plotsquared.sponge.events.PlotComponentSetEvent;
2015-07-30 16:25:16 +02:00
import com.plotsquared.sponge.events.PlotDeleteEvent;
import com.plotsquared.sponge.events.PlotFlagAddEvent;
import com.plotsquared.sponge.events.PlotFlagRemoveEvent;
import com.plotsquared.sponge.events.PlotMergeEvent;
2015-08-08 09:36:02 +02:00
import com.plotsquared.sponge.events.PlotRateEvent;
2015-07-30 16:25:16 +02:00
import com.plotsquared.sponge.events.PlotUnlinkEvent;
2016-02-19 18:50:38 +01:00
import org.spongepowered.api.event.Event;
import org.spongepowered.api.event.EventManager;
import java.util.ArrayList;
import java.util.UUID;
2015-07-30 16:25:16 +02:00
2015-09-13 06:04:31 +02:00
public class SpongeEventUtil extends EventUtil {
2015-07-30 16:25:16 +02:00
public EventManager events;
2015-09-13 06:04:31 +02:00
public SpongeEventUtil() {
this.events = SpongeMain.THIS.getGame().getEventManager();
2015-07-30 16:25:16 +02:00
}
public boolean callEvent(Event event) {
return !this.events.post(event);
2015-07-30 16:25:16 +02:00
}
2015-09-13 06:04:31 +02:00
2015-07-30 16:25:16 +02:00
@Override
public boolean callClaim(PlotPlayer player, Plot plot, boolean auto) {
2015-07-30 16:25:16 +02:00
return callEvent(new PlayerClaimPlotEvent(SpongeUtil.getPlayer(player), plot, auto));
}
2015-09-13 06:04:31 +02:00
2015-07-30 16:25:16 +02:00
@Override
public boolean callTeleport(PlotPlayer player, Location from, Plot plot) {
2015-07-30 16:25:16 +02:00
return callEvent(new PlayerTeleportToPlotEvent(SpongeUtil.getPlayer(player), from, plot));
}
2016-05-25 21:49:55 +02:00
@Override
public boolean callComponentSet(Plot plot, String component) {
return callEvent(new PlotComponentSetEvent(plot, component));
}
2015-09-13 06:04:31 +02:00
2015-07-30 16:25:16 +02:00
@Override
public boolean callClear(Plot plot) {
2016-02-19 18:50:38 +01:00
return callEvent(new PlotClearEvent(plot));
2015-07-30 16:25:16 +02:00
}
2015-09-13 06:04:31 +02:00
2015-07-30 16:25:16 +02:00
@Override
2016-02-19 18:50:38 +01:00
public void callDelete(Plot plot) {
callEvent(new PlotDeleteEvent(plot));
2015-07-30 16:25:16 +02:00
}
2015-09-13 06:04:31 +02:00
2015-07-30 16:25:16 +02:00
@Override
public boolean callFlagAdd(Flag flag, Plot plot) {
2015-07-30 16:25:16 +02:00
return callEvent(new PlotFlagAddEvent(flag, plot));
}
2015-09-13 06:04:31 +02:00
2015-07-30 16:25:16 +02:00
@Override
2016-04-19 22:59:10 +02:00
public boolean callFlagRemove(Flag<?> flag, Plot plot, Object value) {
2015-07-30 16:25:16 +02:00
return callEvent(new PlotFlagRemoveEvent(flag, plot));
}
2015-09-13 06:04:31 +02:00
2015-07-30 16:25:16 +02:00
@Override
public boolean callMerge(Plot plot, ArrayList<PlotId> plots) {
2016-02-19 18:50:38 +01:00
return callEvent(new PlotMergeEvent(SpongeUtil.getWorld(plot.getArea().worldname), plot, plots));
2015-07-30 16:25:16 +02:00
}
2015-09-13 06:04:31 +02:00
2015-07-30 16:25:16 +02:00
@Override
public boolean callUnlink(PlotArea area, ArrayList<PlotId> plots) {
2016-02-19 18:50:38 +01:00
return callEvent(new PlotUnlinkEvent(SpongeUtil.getWorld(area.worldname), plots));
2015-07-30 16:25:16 +02:00
}
2015-09-13 06:04:31 +02:00
2015-07-30 16:25:16 +02:00
@Override
public void callEntry(PlotPlayer player, Plot plot) {
2015-07-30 16:25:16 +02:00
callEvent(new PlayerEnterPlotEvent(SpongeUtil.getPlayer(player), plot));
}
2015-09-13 06:04:31 +02:00
2015-07-30 16:25:16 +02:00
@Override
public void callLeave(PlotPlayer player, Plot plot) {
2015-07-30 16:25:16 +02:00
callEvent(new PlayerLeavePlotEvent(SpongeUtil.getPlayer(player), plot));
}
2015-09-13 06:04:31 +02:00
2015-07-30 16:25:16 +02:00
@Override
public void callDenied(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
2015-07-30 16:25:16 +02:00
callEvent(new PlayerPlotDeniedEvent(SpongeUtil.getPlayer(initiator), plot, player, added));
}
2015-09-13 06:04:31 +02:00
2015-07-30 16:25:16 +02:00
@Override
public void callTrusted(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
2015-07-30 16:25:16 +02:00
callEvent(new PlayerPlotHelperEvent(SpongeUtil.getPlayer(initiator), plot, player, added));
}
2015-09-13 06:04:31 +02:00
2015-07-30 16:25:16 +02:00
@Override
public void callMember(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
2015-07-30 16:25:16 +02:00
callEvent(new PlayerPlotTrustedEvent(SpongeUtil.getPlayer(initiator), plot, player, added));
}
2015-09-13 06:04:31 +02:00
2015-07-30 16:25:16 +02:00
@Override
2016-04-19 22:59:10 +02:00
public boolean callFlagRemove(Flag flag, Object object, PlotCluster cluster) {
2015-07-30 16:25:16 +02:00
return callEvent(new ClusterFlagRemoveEvent(flag, cluster));
}
2015-09-13 06:04:31 +02:00
2015-08-08 09:36:02 +02:00
@Override
public Rating callRating(PlotPlayer player, Plot plot, Rating rating) {
PlotRateEvent event = new PlotRateEvent(player, rating, plot);
this.events.post(event);
2015-08-08 09:36:02 +02:00
return event.getRating();
}
2015-09-13 06:04:31 +02:00
2015-07-30 16:25:16 +02:00
}