summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2011-11-30 02:51:02 +0100
committersnowleo <schneeleo@gmail.com>2011-11-30 02:51:02 +0100
commit35f5578436c1d61085324c330d37867fb6977733 (patch)
tree0f6064f0b48a3385001116a9398121a74897e4d6
parentb8d60674cb725bcd1900b7a5e1250d2a863805f2 (diff)
downloadEssentials-35f5578436c1d61085324c330d37867fb6977733.tar
Essentials-35f5578436c1d61085324c330d37867fb6977733.tar.gz
Essentials-35f5578436c1d61085324c330d37867fb6977733.tar.lz
Essentials-35f5578436c1d61085324c330d37867fb6977733.tar.xz
Essentials-35f5578436c1d61085324c330d37867fb6977733.zip
New config option update-bed-at-daytime that allows players to always set their bed location
-rw-r--r--Essentials/src/com/earth2me/essentials/Essentials.java1
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java20
-rw-r--r--Essentials/src/com/earth2me/essentials/ISettings.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/Settings.java6
-rw-r--r--Essentials/src/com/earth2me/essentials/craftbukkit/SetBed.java25
-rw-r--r--Essentials/src/config.yml3
6 files changed, 57 insertions, 0 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java
index 19073b1aa..629b6bbba 100644
--- a/Essentials/src/com/earth2me/essentials/Essentials.java
+++ b/Essentials/src/com/earth2me/essentials/Essentials.java
@@ -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);
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
index 537a2de06..ad7a396d7 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
@@ -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());
+ }
+ }
}
diff --git a/Essentials/src/com/earth2me/essentials/ISettings.java b/Essentials/src/com/earth2me/essentials/ISettings.java
index 1b71f30e4..9724d1a16 100644
--- a/Essentials/src/com/earth2me/essentials/ISettings.java
+++ b/Essentials/src/com/earth2me/essentials/ISettings.java
@@ -136,4 +136,6 @@ public interface ISettings extends IConf
public void setDebug(boolean debug);
Set<String> getNoGodWorlds();
+
+ boolean getUpdateBedAtDaytime();
}
diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java
index 961b0b9b6..42f6764b3 100644
--- a/Essentials/src/com/earth2me/essentials/Settings.java
+++ b/Essentials/src/com/earth2me/essentials/Settings.java
@@ -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()
diff --git a/Essentials/src/com/earth2me/essentials/craftbukkit/SetBed.java b/Essentials/src/com/earth2me/essentials/craftbukkit/SetBed.java
new file mode 100644
index 000000000..331d14139
--- /dev/null
+++ b/Essentials/src/com/earth2me/essentials/craftbukkit/SetBed.java
@@ -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);
+ }
+ }
+}
diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml
index 22cac25a9..f9584f89a 100644
--- a/Essentials/src/config.yml
+++ b/Essentials/src/config.yml
@@ -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.