mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-01-03 23:07:55 +01:00
Route all teleports through the SafeTTeleporter
There are still some access caveats. When you request that a player be tp'd to you, there's currently not a good way to tell the teleport event that… So we either get full control of all plugins and limited control to override it, or unlimited control to override and no access to other plugins' access to teleport players to potentially restricted locations… This will break the latest other Plugin builds.
This commit is contained in:
parent
d3c1538083
commit
ab17064006
@ -655,7 +655,7 @@ public class MVWorld implements MultiverseWorld {
|
||||
|
||||
@Override
|
||||
public boolean setGameMode(String gameMode) {
|
||||
GameMode mode = null;
|
||||
GameMode mode;
|
||||
try {
|
||||
mode = GameMode.valueOf(gameMode.toUpperCase());
|
||||
} catch (Exception e) {
|
||||
@ -768,7 +768,7 @@ public class MVWorld implements MultiverseWorld {
|
||||
|
||||
@Override
|
||||
public boolean setDifficulty(String difficulty) {
|
||||
Difficulty worlddiff = null;
|
||||
Difficulty worlddiff;
|
||||
try {
|
||||
worlddiff = Difficulty.valueOf(difficulty.toUpperCase());
|
||||
} catch (Exception e) {
|
||||
|
@ -553,8 +553,9 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
* @param p Player
|
||||
* @param l The potentially unsafe location.
|
||||
*/
|
||||
public void teleportPlayer(Player p, Location l) {
|
||||
p.teleport(l);
|
||||
public void teleportPlayer(CommandSender teleporter, Player p, Location l) {
|
||||
// This command is the override, and MUST NOT TELEPORT SAFELY
|
||||
this.getTeleporter().safelyTeleport(teleporter, p, l, false);
|
||||
}
|
||||
|
||||
private void checkServerProps() {
|
||||
|
@ -13,7 +13,6 @@ import com.onarandombox.MultiverseCore.utils.*;
|
||||
import com.pneumaticraft.commandhandler.CommandHandler;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
|
||||
/**
|
||||
* Multiverse 2 Core API
|
||||
|
@ -58,7 +58,7 @@ public class ConfigCommand extends MultiverseCommand {
|
||||
|
||||
if (property != null) {
|
||||
try {
|
||||
this.plugin.getMVConfiguration().set(args.get(0).toLowerCase(), Boolean.parseBoolean(args.get(0)));
|
||||
this.plugin.getMVConfiguration().set(args.get(0).toLowerCase(), Boolean.parseBoolean(args.get(1)));
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.RED + "Sorry, " + ChatColor.AQUA + args.get(0) + ChatColor.WHITE + " must be true or false!");
|
||||
return;
|
||||
|
@ -103,7 +103,7 @@ public class InfoCommand extends MultiverseCommand {
|
||||
message.add(new FancyMessage("World Name: ", world.getName(), colors));
|
||||
message.add(new FancyMessage("World Alias: ", world.getColoredWorldString(), colors));
|
||||
String enforced = "";
|
||||
if(!MultiverseCore.EnforceGameModes) {
|
||||
if (!MultiverseCore.EnforceGameModes) {
|
||||
enforced = ChatColor.RED + " Not Enforced!";
|
||||
}
|
||||
message.add(new FancyMessage("Game Mode: ", world.getGameMode() + enforced, colors));
|
||||
|
@ -35,13 +35,5 @@ public class SleepCommand extends MultiverseCommand {
|
||||
if (p == null) {
|
||||
return;
|
||||
}
|
||||
// MVPlayerSession session = this.plugin.getPlayerSession(p);
|
||||
// if (session.getBedRespawnLocation() != null) {
|
||||
// p.teleport(session.getBedRespawnLocation());
|
||||
// } else {
|
||||
// sender.sendMessage("Hmm this is awkward...");
|
||||
// sender.sendMessage("Something is wrong with your bed.");
|
||||
// sender.sendMessage("It has either been destroyed or obstructed.");
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ package com.onarandombox.MultiverseCore.commands;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
@ -74,10 +75,12 @@ public class SpawnCommand extends MultiverseCommand {
|
||||
|
||||
private void spawnAccurately(Player player) {
|
||||
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(player.getWorld().getName());
|
||||
Location spawnLocation;
|
||||
if (world != null) {
|
||||
player.teleport(world.getSpawnLocation());
|
||||
spawnLocation = world.getSpawnLocation();
|
||||
} else {
|
||||
player.teleport(player.getWorld().getSpawnLocation());
|
||||
spawnLocation = player.getWorld().getSpawnLocation();
|
||||
}
|
||||
this.plugin.getTeleporter().safelyTeleport(player, player, spawnLocation, false);
|
||||
}
|
||||
}
|
||||
|
@ -86,10 +86,10 @@ public class TeleportCommand extends MultiverseCommand {
|
||||
MVDestination d = df.getDestination(destinationName);
|
||||
|
||||
|
||||
MVTeleportEvent teleportEvent = new MVTeleportEvent(d, teleportee, teleporter);
|
||||
MVTeleportEvent teleportEvent = new MVTeleportEvent(d, teleportee, teleporter, true);
|
||||
this.plugin.getServer().getPluginManager().callEvent(teleportEvent);
|
||||
if (teleportEvent.isCancelled()) {
|
||||
this.plugin.log(Level.FINE, "Someone else cancelled the SafeTTeleporter Event!!!");
|
||||
this.plugin.log(Level.FINE, "Someone else cancelled the MVTeleport Event!!!");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -144,11 +144,12 @@ public class TeleportCommand extends MultiverseCommand {
|
||||
teleporter.sendMessage("Sorry Boss, I tried everything, but just couldn't teleport ya there!");
|
||||
return;
|
||||
}
|
||||
if (!this.playerTeleporter.safelyTeleport(teleportee, d)) {
|
||||
if (!this.playerTeleporter.safelyTeleport(teleporter, teleportee, d)) {
|
||||
this.plugin.log(Level.FINE, "Could not teleport " + teleportee.getName() + " to " + LocationManipulation.strCoordsRaw(d.getLocation(teleportee)));
|
||||
this.plugin.log(Level.FINE, "Queueing Command");
|
||||
Class<?> paramTypes[] = {Player.class, Location.class};
|
||||
Class<?> paramTypes[] = {CommandSender.class, Player.class, Location.class};
|
||||
List<Object> items = new ArrayList<Object>();
|
||||
items.add(teleporter);
|
||||
items.add(teleportee);
|
||||
items.add(d.getLocation(teleportee));
|
||||
String player = "you";
|
||||
@ -157,6 +158,9 @@ public class TeleportCommand extends MultiverseCommand {
|
||||
}
|
||||
String message = ChatColor.GREEN + "Multiverse" + ChatColor.WHITE + " did not teleport " + ChatColor.AQUA + player + ChatColor.WHITE + " to " + ChatColor.DARK_AQUA + d.getName() + ChatColor.WHITE + " because it was unsafe.";
|
||||
this.plugin.getCommandHandler().queueCommand(sender, "mvteleport", "teleportPlayer", items, paramTypes, message, "Would you like to try anyway?", "", "", 15);
|
||||
} else {
|
||||
// Player was teleported successfully (or the tp event was fired I should say);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,17 +20,18 @@ import org.bukkit.event.Event;
|
||||
* @author fernferret
|
||||
*/
|
||||
public class MVTeleportEvent extends Event implements Cancellable {
|
||||
private static final long serialVersionUID = 854826818438649269L;
|
||||
private Player teleportee;
|
||||
private CommandSender teleporter;
|
||||
private MVDestination dest;
|
||||
private boolean useSafeTeleport;
|
||||
private boolean isCancelled;
|
||||
|
||||
public MVTeleportEvent(MVDestination dest, Player teleportee, CommandSender teleporter) {
|
||||
public MVTeleportEvent(MVDestination dest, Player teleportee, CommandSender teleporter, boolean safeTeleport) {
|
||||
super("SafeTTeleporter");
|
||||
this.teleportee = teleportee;
|
||||
this.teleporter = teleporter;
|
||||
this.dest = dest;
|
||||
this.useSafeTeleport = safeTeleport;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.listeners;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
||||
|
@ -47,7 +47,7 @@ public class MVPlayerListener extends PlayerListener {
|
||||
return;
|
||||
}
|
||||
MultiverseWorld mvworld = this.worldManager.getMVWorld(world);
|
||||
if(mvworld.isHidden()) {
|
||||
if (mvworld.isHidden()) {
|
||||
return;
|
||||
}
|
||||
prefix = mvworld.getColoredWorldString();
|
||||
|
@ -11,6 +11,7 @@ import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.InvalidDestination;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Minecart;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -36,14 +37,11 @@ public class SafeTTeleporter {
|
||||
* @return
|
||||
*/
|
||||
public Location getSafeBedDestination(Location bedLocation) {
|
||||
// System.out.print(bedLocation);
|
||||
Location idealLocation = bedLocation;
|
||||
idealLocation.setY(idealLocation.getY() + 1);
|
||||
idealLocation.setX(idealLocation.getX() + .5);
|
||||
idealLocation.setZ(idealLocation.getZ() + .5);
|
||||
// System.out.print(idealLocation);
|
||||
if (this.bs.playerCanSpawnHereSafely(idealLocation)) {
|
||||
// System.out.print(idealLocation);
|
||||
return bedLocation;
|
||||
}
|
||||
return null;
|
||||
@ -198,26 +196,27 @@ public class SafeTTeleporter {
|
||||
* Safely teleport the entity to the MVDestination. This will perform checks to see if the place is safe, and if
|
||||
* it's not, will adjust the final destination accordingly.
|
||||
*
|
||||
* @param e Entity to teleport
|
||||
* @param d Destination to teleport them to
|
||||
* @param temeporter Person who performed the teleport command.
|
||||
* @param teleportee Entity to teleport
|
||||
* @param d Destination to teleport them to
|
||||
*
|
||||
* @return true for success, false for failure
|
||||
*/
|
||||
public boolean safelyTeleport(Entity e, MVDestination d) {
|
||||
public boolean safelyTeleport(CommandSender teleporter, Entity teleportee, MVDestination d) {
|
||||
if (d instanceof InvalidDestination) {
|
||||
this.plugin.log(Level.FINER, "Entity tried to teleport to an invalid destination");
|
||||
return false;
|
||||
}
|
||||
|
||||
Location safeLoc = d.getLocation(e);
|
||||
Location safeLoc = d.getLocation(teleportee);
|
||||
if (d.useSafeTeleporter()) {
|
||||
safeLoc = this.getSafeLocation(e, d);
|
||||
safeLoc = this.getSafeLocation(teleportee, d);
|
||||
}
|
||||
|
||||
if (safeLoc != null) {
|
||||
if (e.teleport(safeLoc)) {
|
||||
if (teleportee.teleport(safeLoc)) {
|
||||
if (!d.getVelocity().equals(new Vector(0, 0, 0))) {
|
||||
e.setVelocity(d.getVelocity());
|
||||
teleportee.setVelocity(d.getVelocity());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -225,6 +224,31 @@ public class SafeTTeleporter {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely teleport the entity to the Location. This may perform checks to
|
||||
* see if the place is safe, and if
|
||||
* it's not, will adjust the final destination accordingly.
|
||||
*
|
||||
* @param temeporter Person who issued the teleport command.
|
||||
* @param teleportee Entity to teleport.
|
||||
* @param location Location to teleport them to.
|
||||
* @param safely Should the destination be checked for safety before teleport?
|
||||
*
|
||||
* @return true for success, false for failure.
|
||||
*/
|
||||
public boolean safelyTeleport(CommandSender teleporter, Entity teleportee, Location location, boolean safely) {
|
||||
if (safely) {
|
||||
location = this.getSafeLocation(location);
|
||||
}
|
||||
|
||||
if (location != null) {
|
||||
if (teleportee.teleport(location)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a safe location for the entity to spawn at.
|
||||
*
|
||||
|
@ -249,9 +249,10 @@ public class WorldManager implements MVWorldManager {
|
||||
if (w != null) {
|
||||
World safeWorld = this.plugin.getServer().getWorlds().get(0);
|
||||
List<Player> ps = w.getPlayers();
|
||||
SafeTTeleporter teleporter = this.plugin.getTeleporter();
|
||||
for (Player p : ps) {
|
||||
|
||||
p.teleport(safeWorld.getSpawnLocation());
|
||||
// We're removing players forcefully from a world, they'd BETTER spawn safely.
|
||||
teleporter.safelyTeleport(null, p, safeWorld.getSpawnLocation(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user