Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ plugins {

String packagePath = 'org.minecast.bedhome'
group packagePath
version = '2.33'
version = '2.34'

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenCentral()
maven { url "https://hub.spigotmc.org/nexus/content/groups/public" }
maven { url "http://repo.gravitydevelopment.net" }
//maven { url "http://repo.gravitydevelopment.net" }
maven { url "http://nexus.hc.to/content/repositories/pub_releases" }
maven { url "https://jitpack.io" }
maven { url 'https://repo.codemc.org/repository/maven-public' }
Expand Down
46 changes: 33 additions & 13 deletions src/main/java/org/minecast/bedhome/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class Main extends JavaPlugin implements Listener {
// Locale File
File localeFile = new File(this.getDataFolder(), "locale.yml");
YamlConfiguration locale = YamlConfiguration.loadConfiguration(localeFile);

private boolean autoDL() { return (getConfig().getBoolean("auto-update")); }

void reloadLocale() {
Expand Down Expand Up @@ -205,6 +205,7 @@ public void setConfigOpts() {
checkConfig("relaxed_checking", false);
checkConfig("nobedmode", 'c');
checkConfig("locale", "en");
checkConfig("teleportDelay", 0);
this.getConfig().options().copyDefaults(true);
}

Expand Down Expand Up @@ -281,7 +282,7 @@ public void reloadEconomy() {
public void onEnable() {
plugin = this;
log = getLogger();

PaperLib.suggestPaper(this);

verifyLocale();
Expand All @@ -299,7 +300,7 @@ public void onEnable() {
this.yml.options().copyDefaults(true);

reloadEconomy();

if (!getConfig().getBoolean("permissions")) {
// If permissions are disabled, give all players the /bed command
new Permission("bedhome.bed").setDefault(PermissionDefault.TRUE);
Expand Down Expand Up @@ -355,6 +356,7 @@ public boolean isPlayerAuthorized(CommandSender s, String perm) {
}

public void teleToBed(Player player, World w) {

PaperLib.teleportAsync(player, getSavedBedLocation(player, w)).thenAccept(result -> {
if (result) {
sendUTF8Message(getLocaleString("BED_TELE"), player);
Expand Down Expand Up @@ -385,7 +387,7 @@ private void noBedCheck(Player p, World w, boolean isOtherWorld) {
case "a":
if (bedInConfig(p, w)) {
if (chargePlayerAccount(p, bedTpCost)) {
teleToBed(p, w);
startBedTeleport(p, w, getConfig().getInt("teleportDelay"));
}
if (getConfig().getBoolean("console_messages")) {
log.info(getLocaleString("CONSOLE_PLAYER_TELE").replace("$player", ChatColor.stripColor(p.getDisplayName())));
Expand Down Expand Up @@ -434,7 +436,7 @@ public Location getSavedBedLocation(Player p, World w){
double z = (Double) yml.get(id + "." + wn + ".z");
return new Location(w, x, y, z);
}

/**
* Old method (pre 1.13) of checking for bed block
* @param b Block of bed to get alternate
Expand All @@ -456,17 +458,17 @@ private Location _legacyGetAltBedBlock(Block b) {
}
return b.getLocation();
}

public Block getAltBedBlock(Block block) {
try {
Class.forName("org.bukkit.block.data.type.Bed");
} catch (ClassNotFoundException e) {
return _legacyGetAltBedBlock(block).getBlock();
}

if (!(block.getBlockData() instanceof Bed)) return block;
Bed bed = (Bed) block.getBlockData();

// Get the alternate block of the bed
Bed.Part part = bed.getPart();
Block supposedAltBlock = getBlockFaceLocation(block.getLocation(), bed.getFacing().getOppositeFace()).getBlock();
Expand All @@ -477,7 +479,7 @@ public Block getAltBedBlock(Block block) {
return _legacyGetAltBedBlock(block).getBlock();
}
}

public static Location getBlockFaceLocation(Location l, BlockFace blockFace) {
// It would be nice if BlockFace extended Vector
Location newLoc = l.clone();
Expand All @@ -493,7 +495,7 @@ public boolean bedAtPos(Player p, World w){
return true;
}
}

public static boolean blockIsBed(Block b) {
if (b == null) return false; // This shouldn't happen
try {
Expand All @@ -504,7 +506,7 @@ public static boolean blockIsBed(Block b) {
//noinspection deprecation
return b.getState() instanceof org.bukkit.block.Bed;
}

return b.getBlockData() instanceof Bed;
}

Expand Down Expand Up @@ -597,7 +599,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
World w = Bukkit.getWorld(args[0]);
if (bedInConfig(p, w) && bedAtPos(p, w)) {
if (chargePlayerAccount(p, bedTpCost)) {
teleToBed(p, w);
startBedTeleport(p, w, getConfig().getInt("teleportDelay"));
}
} else {
noBedCheck(p, w, true);
Expand All @@ -613,7 +615,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
if (p.getBedSpawnLocation() != null && p.getBedSpawnLocation().getWorld() == p.getWorld()) {
if (bedInConfig(p, p.getWorld())) {
if (chargePlayerAccount(p, bedTpCost)) {
teleToBed(p, p.getWorld());
startBedTeleport(p, p.getWorld(), getConfig().getInt("teleportDelay"));
}
if (getConfig().getBoolean("console_messages")) {
log.info(getLocaleString("CONSOLE_PLAYER_TELE").replace("$player", ChatColor.stripColor(p.getDisplayName())));
Expand Down Expand Up @@ -641,6 +643,24 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
return false;
}

public void startBedTeleport(Player player, World world, int teleportDelay){
if (teleportDelay == 0) {
teleToBed(player, world);
}

player.sendMessage(getLocaleString("BH_DELAYED"));
Location playerLocation = player.getLocation().clone(); //clone to get value, not a reference. just to be sure.
getServer().getScheduler().runTaskLater(plugin, () -> {
// why not use .equals(_? because then rotation is taken into account, and ideally you'd want to be able to look around while the teleport is winding up.
if (player.getLocation().getX() != playerLocation.getX() || player.getLocation().getY() != playerLocation.getY() || player.getLocation().getZ() != playerLocation.getZ()){
player.sendMessage(getLocaleString("BH_MOVED_DELAY"));
}
else {
teleToBed(player, world);
}
}, teleportDelay * 20L);
};

public static final Main getPlugin() {
return plugin;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# If you specify a language that doesn't exist, the plugin will just use English.
# bedTpCost - If you want to charge players to use /bed, specify the amount here. 0.0 disables economy
# bedSetCost - If you want to charge players to set their bed, specify the amount here. 0.0 disables economy
# teleportDelay - the delay between when the command is issued, and when someone is actually teleported. 0 disables the windup altogether.
# The plugin must be reloaded in order for any changes here to take effect.
permissions: true
auto-update: true
Expand All @@ -23,3 +24,4 @@ locale: en
bedTpCost: 0.0
bedSetCost: 0.0
first-run: true
teleportDelay: 0
2 changes: 2 additions & 0 deletions src/main/resources/locale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ en:
BH_VERSION: '&9BedHome v$version by Superior_Slime'
BH_RELOADED: '&9Config and locale reloaded!'
BH_CONSOLE_CMD: 'Only players can use this command!'
BH_MOVED_DELAY: 'Cancelling your teleport because you moved.'
BH_DELAYED: 'Teleporting you in a few seconds, stay still!'
##These are used for /bedhome help. No point in editing them.
NAME: '&3<name>'
WORLD: '&3<world>'
Expand Down