New config option update-bed-at-daytime that allows players to always set their bed location

This commit is contained in:
snowleo 2011-11-30 02:51:02 +01:00
parent b8d60674cb
commit 35f5578436
6 changed files with 57 additions and 0 deletions

View file

@ -182,6 +182,7 @@ public class Essentials extends JavaPlugin implements IEssentials
pm.registerEvent(Type.PLAYER_BUCKET_EMPTY, playerListener, Priority.High, this);
pm.registerEvent(Type.PLAYER_ANIMATION, playerListener, Priority.High, this);
pm.registerEvent(Type.PLAYER_CHANGED_WORLD, playerListener, Priority.Normal, this);
pm.registerEvent(Type.PLAYER_INTERACT, playerListener, Priority.Monitor, this);
pm.registerEvent(Type.PLAYER_TELEPORT, new ItemDupeFix(), Priority.Monitor, this);
final EssentialsBlockListener blockListener = new EssentialsBlockListener(this);

View file

@ -1,6 +1,7 @@
package com.earth2me.essentials;
import com.earth2me.essentials.craftbukkit.EnchantmentFix;
import com.earth2me.essentials.craftbukkit.SetBed;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.textreader.IText;
import com.earth2me.essentials.textreader.KeywordReplacer;
@ -17,6 +18,7 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerLoginEvent.Result;
import org.bukkit.event.player.*;
import org.bukkit.inventory.ItemStack;
@ -354,4 +356,22 @@ public class EssentialsPlayerListener extends PlayerListener
}
}
}
@Override
public void onPlayerInteract(final PlayerInteractEvent event)
{
if (event.isCancelled())
{
return;
}
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
{
return;
}
if (ess.getSettings().getUpdateBedAtDaytime() && event.getClickedBlock().getType() == Material.BED_BLOCK)
{
SetBed.setBed(event.getPlayer(), event.getClickedBlock());
}
}
}

View file

@ -136,4 +136,6 @@ public interface ISettings extends IConf
public void setDebug(boolean debug);
Set<String> getNoGodWorlds();
boolean getUpdateBedAtDaytime();
}

View file

@ -35,6 +35,12 @@ public class Settings implements ISettings
{
return config.getBoolean("respawn-at-home", false);
}
@Override
public boolean getUpdateBedAtDaytime()
{
return config.getBoolean("update-bed-at-daytime", true);
}
@Override
public List<String> getMultipleHomes()

View file

@ -0,0 +1,25 @@
package com.earth2me.essentials.craftbukkit;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.minecraft.server.ChunkCoordinates;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
public class SetBed
{
public static void setBed(final Player player, final Block block)
{
try
{
final CraftPlayer cplayer = (CraftPlayer)player;
cplayer.getHandle().a(new ChunkCoordinates(block.getX(), block.getY(), block.getZ()));
}
catch (Throwable ex)
{
Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex);
}
}
}

View file

@ -239,6 +239,9 @@ respawn-at-home: false
# If no home is set send you to bed or spawn when /home is used
spawn-if-no-home: true
# Allows people to set their bed at daytime
update-bed-at-daytime: true
# Allow players to have multiple homes.
# Define different amounts of multiple homes for different permissions, e.g. essentials.sethome.multiple.vip
# People with essentials.sethome.multiple.unlimited are not limited by these numbers.