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

145 lines
4.8 KiB
Java
Raw Normal View History

2015-07-30 16:25:16 +02:00
package com.plotsquared.sponge.util;
import java.util.ArrayList;
import java.util.UUID;
import org.spongepowered.api.event.Cancellable;
import org.spongepowered.api.event.Event;
import org.spongepowered.api.service.event.EventManager;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
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;
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;
2015-09-11 12:09:22 +02:00
public class SpongeEventUtil extends EventUtil
{
2015-07-30 16:25:16 +02:00
public EventManager events;
2015-09-11 12:09:22 +02:00
public SpongeEventUtil()
{
events = SpongeMain.THIS.getGame().getEventManager();
2015-07-30 16:25:16 +02:00
}
2015-09-11 12:09:22 +02:00
public boolean callEvent(final Event event)
{
2015-07-30 16:25:16 +02:00
events.post(event);
2015-09-11 12:09:22 +02:00
if (event instanceof Cancellable) { return !((Cancellable) event).isCancelled(); }
2015-07-30 16:25:16 +02:00
return true;
}
2015-09-11 12:09:22 +02:00
2015-07-30 16:25:16 +02:00
@Override
2015-09-11 12:09:22 +02:00
public boolean callClaim(final PlotPlayer player, final Plot plot, final boolean auto)
{
2015-07-30 16:25:16 +02:00
return callEvent(new PlayerClaimPlotEvent(SpongeUtil.getPlayer(player), plot, auto));
}
@Override
2015-09-11 12:09:22 +02:00
public boolean callTeleport(final PlotPlayer player, final Location from, final Plot plot)
{
2015-07-30 16:25:16 +02:00
return callEvent(new PlayerTeleportToPlotEvent(SpongeUtil.getPlayer(player), from, plot));
}
@Override
2015-09-11 12:09:22 +02:00
public boolean callClear(final String world, final PlotId id)
{
2015-07-30 16:25:16 +02:00
return callEvent(new PlotClearEvent(world, id));
}
@Override
2015-09-11 12:09:22 +02:00
public void callDelete(final String world, final PlotId id)
{
2015-07-30 16:25:16 +02:00
callEvent(new PlotDeleteEvent(world, id));
}
@Override
2015-09-11 12:09:22 +02:00
public boolean callFlagAdd(final Flag flag, final Plot plot)
{
2015-07-30 16:25:16 +02:00
return callEvent(new PlotFlagAddEvent(flag, plot));
}
@Override
2015-09-11 12:09:22 +02:00
public boolean callFlagRemove(final Flag flag, final Plot plot)
{
2015-07-30 16:25:16 +02:00
return callEvent(new PlotFlagRemoveEvent(flag, plot));
}
@Override
2015-09-11 12:09:22 +02:00
public boolean callMerge(final String world, final Plot plot, final ArrayList<PlotId> plots)
{
2015-07-30 16:25:16 +02:00
return callEvent(new PlotMergeEvent(SpongeUtil.getWorld(world), plot, plots));
}
@Override
2015-09-11 12:09:22 +02:00
public boolean callUnlink(final String world, final ArrayList<PlotId> plots)
{
2015-07-30 16:25:16 +02:00
return callEvent(new PlotUnlinkEvent(SpongeUtil.getWorld(world), plots));
}
@Override
2015-09-11 12:09:22 +02:00
public void callEntry(final PlotPlayer player, final Plot plot)
{
2015-07-30 16:25:16 +02:00
callEvent(new PlayerEnterPlotEvent(SpongeUtil.getPlayer(player), plot));
}
@Override
2015-09-11 12:09:22 +02:00
public void callLeave(final PlotPlayer player, final Plot plot)
{
2015-07-30 16:25:16 +02:00
callEvent(new PlayerLeavePlotEvent(SpongeUtil.getPlayer(player), plot));
}
@Override
2015-09-11 12:09:22 +02:00
public void callDenied(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added)
{
2015-07-30 16:25:16 +02:00
callEvent(new PlayerPlotDeniedEvent(SpongeUtil.getPlayer(initiator), plot, player, added));
}
@Override
2015-09-11 12:09:22 +02:00
public void callTrusted(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added)
{
2015-07-30 16:25:16 +02:00
callEvent(new PlayerPlotHelperEvent(SpongeUtil.getPlayer(initiator), plot, player, added));
}
@Override
2015-09-11 12:09:22 +02:00
public void callMember(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added)
{
2015-07-30 16:25:16 +02:00
callEvent(new PlayerPlotTrustedEvent(SpongeUtil.getPlayer(initiator), plot, player, added));
}
@Override
2015-09-11 12:09:22 +02:00
public boolean callFlagRemove(final Flag flag, final PlotCluster cluster)
{
2015-07-30 16:25:16 +02:00
return callEvent(new ClusterFlagRemoveEvent(flag, cluster));
}
2015-08-08 09:36:02 +02:00
@Override
2015-09-11 12:09:22 +02:00
public Rating callRating(final PlotPlayer player, final Plot plot, final Rating rating)
{
final PlotRateEvent event = new PlotRateEvent(player, rating, plot);
2015-08-08 09:36:02 +02:00
events.post(event);
return event.getRating();
}
2015-09-11 12:09:22 +02:00
2015-07-30 16:25:16 +02:00
}