mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-01-07 16:57:50 +01:00
Inital extra bed commit with back-compatibility
Needs review and permissions advice before continuing. line ending derp --- Modified by @main--: * formatting fixed * removed changes to travis.yml and gitattributes * improved code style
This commit is contained in:
parent
07a38e3e58
commit
ce80fc190d
@ -9,8 +9,11 @@ package com.onarandombox.MultiverseCore.destination;
|
|||||||
|
|
||||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@ -20,7 +23,8 @@ import org.bukkit.util.Vector;
|
|||||||
* A bed-{@link MVDestination}.
|
* A bed-{@link MVDestination}.
|
||||||
*/
|
*/
|
||||||
public class BedDestination implements MVDestination {
|
public class BedDestination implements MVDestination {
|
||||||
|
public static final String OLD_BED_STRING = "b:playerbed";
|
||||||
|
private String playername = "";
|
||||||
private boolean isValid;
|
private boolean isValid;
|
||||||
private Location knownBedLoc;
|
private Location knownBedLoc;
|
||||||
private MultiverseCore plugin;
|
private MultiverseCore plugin;
|
||||||
@ -39,7 +43,15 @@ public class BedDestination implements MVDestination {
|
|||||||
@Override
|
@Override
|
||||||
public boolean isThisType(JavaPlugin plugin, String destination) {
|
public boolean isThisType(JavaPlugin plugin, String destination) {
|
||||||
String[] split = destination.split(":");
|
String[] split = destination.split(":");
|
||||||
this.isValid = split.length >= 1 && split.length <= 2 && split[0].equals(this.getIdentifier());
|
boolean validFormat = split.length >= 1 && split.length <= 2 && split[0].equals(this.getIdentifier());
|
||||||
|
|
||||||
|
OfflinePlayer p = Bukkit.getOfflinePlayer(split[1]);
|
||||||
|
boolean validPlayer = (p != null);
|
||||||
|
|
||||||
|
if (validFormat && validPlayer) this.playername = p.getName();
|
||||||
|
|
||||||
|
this.isValid = destination.equals(OLD_BED_STRING) || (validFormat && validPlayer);
|
||||||
|
|
||||||
return this.isValid;
|
return this.isValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,9 +61,13 @@ public class BedDestination implements MVDestination {
|
|||||||
@Override
|
@Override
|
||||||
public Location getLocation(Entity entity) {
|
public Location getLocation(Entity entity) {
|
||||||
if (entity instanceof Player) {
|
if (entity instanceof Player) {
|
||||||
this.knownBedLoc = this.plugin.getBlockSafety().getSafeBedSpawn(((Player) entity).getBedSpawnLocation());
|
if (this.playername.isEmpty())
|
||||||
|
this.knownBedLoc = this.plugin.getBlockSafety().getSafeBedSpawn(((Player) entity).getBedSpawnLocation());
|
||||||
|
else
|
||||||
|
this.knownBedLoc = this.plugin.getBlockSafety().getSafeBedSpawn(Bukkit.getOfflinePlayer(this.playername).getBedSpawnLocation());
|
||||||
|
|
||||||
if (this.knownBedLoc == null) {
|
if (this.knownBedLoc == null) {
|
||||||
((Player) entity).sendMessage("Your bed was " + ChatColor.RED + "invalid or blocked" + ChatColor.RESET + ". Sorry.");
|
((Player) entity).sendMessage("The bed was " + ChatColor.RED + "invalid or blocked" + ChatColor.RESET + ". Sorry.");
|
||||||
}
|
}
|
||||||
return this.knownBedLoc;
|
return this.knownBedLoc;
|
||||||
}
|
}
|
||||||
@ -120,6 +136,6 @@ public class BedDestination implements MVDestination {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "b:playerbed";
|
return playername.isEmpty() ? OLD_BED_STRING : ("b:" + playername);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user