Add teleport on death feature

This commit is contained in:
manuelgu 2016-04-04 11:31:15 +02:00
parent b1cb6c0f57
commit 6ab3a029b2
4 changed files with 31 additions and 6 deletions

View File

@ -96,6 +96,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.vehicle.VehicleCreateEvent; import org.bukkit.event.vehicle.VehicleCreateEvent;
import org.bukkit.event.vehicle.VehicleDestroyEvent; import org.bukkit.event.vehicle.VehicleDestroyEvent;
@ -461,6 +462,13 @@ public class PlayerEvents extends PlotListener implements Listener {
}, 20); }, 20);
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void playerRespawn(PlayerRespawnEvent event) {
final Player player = event.getPlayer();
final PlotPlayer pp = BukkitUtil.getPlayer(player);
EventUtil.manager.doDeathTask(pp);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void playerMove(PlayerMoveEvent event) { public void playerMove(PlayerMoveEvent event) {
org.bukkit.Location from = event.getFrom(); org.bukkit.Location from = event.getFrom();

View File

@ -53,7 +53,6 @@ import com.intellectualcrafters.plot.util.WorldUtil;
import com.intellectualcrafters.plot.util.area.QuadMap; import com.intellectualcrafters.plot.util.area.QuadMap;
import com.plotsquared.listener.WESubscriber; import com.plotsquared.listener.WESubscriber;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -2030,6 +2029,7 @@ public class PS {
// Teleportation // Teleportation
options.put("teleport.on_login", Settings.TELEPORT_ON_LOGIN); options.put("teleport.on_login", Settings.TELEPORT_ON_LOGIN);
options.put("teleport.on_death", Settings.TELEPORT_ON_DEATH);
options.put("teleport.delay", Settings.TELEPORT_DELAY); options.put("teleport.delay", Settings.TELEPORT_DELAY);
// WorldEdit // WorldEdit
@ -2140,6 +2140,7 @@ public class PS {
// Teleportation // Teleportation
Settings.TELEPORT_DELAY = this.config.getInt("teleport.delay"); Settings.TELEPORT_DELAY = this.config.getInt("teleport.delay");
Settings.TELEPORT_ON_LOGIN = this.config.getBoolean("teleport.on_login"); Settings.TELEPORT_ON_LOGIN = this.config.getBoolean("teleport.on_login");
Settings.TELEPORT_ON_DEATH = this.config.getBoolean("teleport.on_death");
// WorldEdit // WorldEdit
Settings.QUEUE_COMMANDS = this.config.getBoolean("worldedit.queue-commands"); Settings.QUEUE_COMMANDS = this.config.getBoolean("worldedit.queue-commands");

View File

@ -82,6 +82,10 @@ public class Settings {
* Teleport to path on login * Teleport to path on login
*/ */
public static boolean TELEPORT_ON_LOGIN = false; public static boolean TELEPORT_ON_LOGIN = false;
/**
* Teleport to path on death
*/
public static boolean TELEPORT_ON_DEATH = false;
/** /**
* Display titles * Display titles
*/ */

View File

@ -15,7 +15,6 @@ import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.Rating; import com.intellectualcrafters.plot.object.Rating;
import com.plotsquared.listener.PlayerBlockEventType; import com.plotsquared.listener.PlayerBlockEventType;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.UUID; import java.util.UUID;
@ -78,6 +77,19 @@ public abstract class EventUtil {
} }
} }
public void doDeathTask(final PlotPlayer pp) {
final Plot plot = pp.getCurrentPlot();
if (Settings.TELEPORT_ON_DEATH && plot != null) {
TaskManager.runTask(new Runnable() {
@Override
public void run() {
plot.teleportPlayer(pp);
}
});
MainUtil.sendMessage(pp, C.TELEPORTED_TO_ROAD);
}
}
public boolean checkPlayerBlockEvent(PlotPlayer pp, PlayerBlockEventType type, Location loc, LazyBlock block, boolean notifyPerms) { public boolean checkPlayerBlockEvent(PlotPlayer pp, PlayerBlockEventType type, Location loc, LazyBlock block, boolean notifyPerms) {
PlotArea area = PS.get().getPlotAreaAbs(loc); PlotArea area = PS.get().getPlotAreaAbs(loc);
Plot plot; Plot plot;