2015-07-30 19:24:01 +02:00
|
|
|
package com.plotsquared.bukkit.util;
|
2015-02-23 06:29:45 +01:00
|
|
|
|
2015-07-30 16:25:16 +02:00
|
|
|
import com.intellectualcrafters.plot.flag.Flag;
|
2016-08-08 23:20:31 +02:00
|
|
|
import com.intellectualcrafters.plot.object.Location;
|
|
|
|
import com.intellectualcrafters.plot.object.Plot;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotArea;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotCluster;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotId;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
|
|
import com.intellectualcrafters.plot.object.Rating;
|
2015-07-30 16:25:16 +02:00
|
|
|
import com.intellectualcrafters.plot.util.EventUtil;
|
2016-08-08 23:20:31 +02:00
|
|
|
import com.plotsquared.bukkit.events.ClusterFlagRemoveEvent;
|
|
|
|
import com.plotsquared.bukkit.events.PlayerClaimPlotEvent;
|
|
|
|
import com.plotsquared.bukkit.events.PlayerEnterPlotEvent;
|
|
|
|
import com.plotsquared.bukkit.events.PlayerLeavePlotEvent;
|
|
|
|
import com.plotsquared.bukkit.events.PlayerPlotDeniedEvent;
|
|
|
|
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;
|
|
|
|
import com.plotsquared.bukkit.events.PlotMergeEvent;
|
|
|
|
import com.plotsquared.bukkit.events.PlotRateEvent;
|
|
|
|
import com.plotsquared.bukkit.events.PlotUnlinkEvent;
|
2015-07-30 16:25:16 +02:00
|
|
|
import com.plotsquared.bukkit.object.BukkitPlayer;
|
2016-02-11 02:37:21 +01:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.Cancellable;
|
|
|
|
import org.bukkit.event.Event;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.UUID;
|
2015-02-23 06:29:45 +01:00
|
|
|
|
2015-09-13 06:04:31 +02:00
|
|
|
public class BukkitEventUtil extends EventUtil {
|
2016-02-14 02:01:18 +01:00
|
|
|
|
2016-03-23 02:41:37 +01:00
|
|
|
public Player getPlayer(PlotPlayer player) {
|
2015-09-13 06:04:31 +02:00
|
|
|
if (player instanceof BukkitPlayer) {
|
|
|
|
return ((BukkitPlayer) player).player;
|
|
|
|
}
|
2015-07-27 20:12:51 +02:00
|
|
|
return null;
|
2015-02-23 06:29:45 +01:00
|
|
|
}
|
2016-02-14 02:01:18 +01:00
|
|
|
|
2016-03-23 02:41:37 +01:00
|
|
|
public boolean callEvent(Event event) {
|
2015-02-23 06:29:45 +01:00
|
|
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
2016-02-14 02:01:18 +01:00
|
|
|
return !(event instanceof Cancellable) || !((Cancellable) event).isCancelled();
|
2015-02-23 06:29:45 +01:00
|
|
|
}
|
2016-02-14 02:01:18 +01:00
|
|
|
|
2015-02-23 06:29:45 +01:00
|
|
|
@Override
|
2016-03-23 02:41:37 +01:00
|
|
|
public boolean callClaim(PlotPlayer player, Plot plot, boolean auto) {
|
2015-02-23 06:29:45 +01:00
|
|
|
return callEvent(new PlayerClaimPlotEvent(getPlayer(player), plot, auto));
|
|
|
|
}
|
2016-02-14 02:01:18 +01:00
|
|
|
|
2015-02-23 06:29:45 +01:00
|
|
|
@Override
|
2016-03-23 02:41:37 +01:00
|
|
|
public boolean callTeleport(PlotPlayer player, Location from, Plot plot) {
|
2015-02-23 06:29:45 +01:00
|
|
|
return callEvent(new PlayerTeleportToPlotEvent(getPlayer(player), from, plot));
|
|
|
|
}
|
2016-02-14 02:01:18 +01:00
|
|
|
|
2016-05-25 21:49:55 +02:00
|
|
|
@Override
|
|
|
|
public boolean callComponentSet(Plot plot, String component) {
|
|
|
|
return callEvent(new PlotComponentSetEvent(plot, component));
|
|
|
|
}
|
|
|
|
|
2015-02-23 06:29:45 +01:00
|
|
|
@Override
|
2016-03-23 02:41:37 +01:00
|
|
|
public boolean callClear(Plot plot) {
|
2016-02-10 19:59:51 +01:00
|
|
|
return callEvent(new PlotClearEvent(plot));
|
2015-02-23 06:29:45 +01:00
|
|
|
}
|
2016-02-14 02:01:18 +01:00
|
|
|
|
2015-02-23 06:29:45 +01:00
|
|
|
@Override
|
2016-03-23 02:41:37 +01:00
|
|
|
public void callDelete(Plot plot) {
|
2016-02-10 19:59:51 +01:00
|
|
|
callEvent(new PlotDeleteEvent(plot));
|
2015-02-23 06:29:45 +01:00
|
|
|
}
|
2016-02-14 02:01:18 +01:00
|
|
|
|
2015-02-23 06:29:45 +01:00
|
|
|
@Override
|
2016-03-23 02:41:37 +01:00
|
|
|
public boolean callFlagAdd(Flag flag, Plot plot) {
|
2015-02-23 06:29:45 +01:00
|
|
|
return callEvent(new PlotFlagAddEvent(flag, plot));
|
|
|
|
}
|
2016-02-14 02:01:18 +01:00
|
|
|
|
2015-02-23 06:29:45 +01:00
|
|
|
@Override
|
2016-04-19 22:59:10 +02:00
|
|
|
public boolean callFlagRemove(Flag<?> flag, Plot plot, Object value) {
|
2015-02-23 06:29:45 +01:00
|
|
|
return callEvent(new PlotFlagRemoveEvent(flag, plot));
|
|
|
|
}
|
2016-02-14 02:01:18 +01:00
|
|
|
|
2015-02-23 06:29:45 +01:00
|
|
|
@Override
|
2016-03-23 02:41:37 +01:00
|
|
|
public boolean callMerge(Plot plot, ArrayList<PlotId> plots) {
|
2016-02-11 02:37:21 +01:00
|
|
|
return callEvent(new PlotMergeEvent(BukkitUtil.getWorld(plot.getArea().worldname), plot, plots));
|
2015-02-23 06:29:45 +01:00
|
|
|
}
|
2016-02-14 02:01:18 +01:00
|
|
|
|
2015-02-23 06:29:45 +01:00
|
|
|
@Override
|
2016-03-23 02:41:37 +01:00
|
|
|
public boolean callUnlink(PlotArea area, ArrayList<PlotId> plots) {
|
2016-02-10 19:59:51 +01:00
|
|
|
return callEvent(new PlotUnlinkEvent(BukkitUtil.getWorld(area.worldname), area, plots));
|
2015-02-23 06:29:45 +01:00
|
|
|
}
|
2016-02-14 02:01:18 +01:00
|
|
|
|
2015-02-23 06:29:45 +01:00
|
|
|
@Override
|
2016-03-23 02:41:37 +01:00
|
|
|
public void callEntry(PlotPlayer player, Plot plot) {
|
2015-02-23 06:29:45 +01:00
|
|
|
callEvent(new PlayerEnterPlotEvent(getPlayer(player), plot));
|
|
|
|
}
|
2016-02-14 02:01:18 +01:00
|
|
|
|
2015-02-23 06:29:45 +01:00
|
|
|
@Override
|
2016-03-23 02:41:37 +01:00
|
|
|
public void callLeave(PlotPlayer player, Plot plot) {
|
2015-02-23 06:29:45 +01:00
|
|
|
callEvent(new PlayerLeavePlotEvent(getPlayer(player), plot));
|
|
|
|
}
|
2016-02-14 02:01:18 +01:00
|
|
|
|
2015-02-23 06:29:45 +01:00
|
|
|
@Override
|
2016-03-23 02:41:37 +01:00
|
|
|
public void callDenied(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
|
2015-02-23 06:29:45 +01:00
|
|
|
callEvent(new PlayerPlotDeniedEvent(getPlayer(initiator), plot, player, added));
|
|
|
|
}
|
2016-02-14 02:01:18 +01:00
|
|
|
|
2015-02-23 06:29:45 +01:00
|
|
|
@Override
|
2016-03-23 02:41:37 +01:00
|
|
|
public void callTrusted(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
|
2016-08-08 22:45:08 +02:00
|
|
|
callEvent(new PlayerPlotTrustedEvent(getPlayer(initiator), plot, player, added));
|
2015-02-23 06:29:45 +01:00
|
|
|
}
|
2016-02-14 02:01:18 +01:00
|
|
|
|
2015-02-23 06:29:45 +01:00
|
|
|
@Override
|
2016-03-23 02:41:37 +01:00
|
|
|
public void callMember(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
|
2016-08-08 22:45:08 +02:00
|
|
|
callEvent(new PlayerPlotHelperEvent(getPlayer(initiator), plot, player, added));
|
2015-02-23 06:29:45 +01:00
|
|
|
}
|
2016-02-14 02:01:18 +01:00
|
|
|
|
2015-06-23 23:44:44 +02:00
|
|
|
@Override
|
2016-04-19 22:59:10 +02:00
|
|
|
public boolean callFlagRemove(Flag flag, Object object, PlotCluster cluster) {
|
2015-06-23 23:44:44 +02:00
|
|
|
return callEvent(new ClusterFlagRemoveEvent(flag, cluster));
|
|
|
|
}
|
2016-02-14 02:01:18 +01:00
|
|
|
|
2015-08-08 09:36:02 +02:00
|
|
|
@Override
|
2016-03-23 02:41:37 +01:00
|
|
|
public Rating callRating(PlotPlayer player, Plot plot, Rating rating) {
|
|
|
|
PlotRateEvent event = new PlotRateEvent(player, rating, plot);
|
2015-08-08 09:36:02 +02:00
|
|
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
|
|
|
return event.getRating();
|
|
|
|
}
|
2016-02-14 02:01:18 +01:00
|
|
|
|
2015-02-23 06:29:45 +01:00
|
|
|
}
|