From 87940c9eaec3200a4f00826ba7c38cf60fcc1fa3 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Tue, 13 Dec 2011 03:43:26 +0100 Subject: [PATCH] Added an asPlayer method to LocalCommandSender, which casts the object to LocalPlayer if possible and throws an exception otherwise. --- src/main/java/com/sk89q/worldedit/LocalCommandSender.java | 4 ++++ src/main/java/com/sk89q/worldedit/LocalPlayer.java | 4 ++++ src/main/java/com/sk89q/worldedit/PlayerNeededException.java | 5 +++++ 3 files changed, 13 insertions(+) create mode 100644 src/main/java/com/sk89q/worldedit/PlayerNeededException.java diff --git a/src/main/java/com/sk89q/worldedit/LocalCommandSender.java b/src/main/java/com/sk89q/worldedit/LocalCommandSender.java index f60c96921..9f29a32fd 100644 --- a/src/main/java/com/sk89q/worldedit/LocalCommandSender.java +++ b/src/main/java/com/sk89q/worldedit/LocalCommandSender.java @@ -114,4 +114,8 @@ public abstract class LocalCommandSender { public int hashCode() { return getName().hashCode(); } + + public LocalPlayer asPlayer() throws PlayerNeededException { + throw new PlayerNeededException(); + } } diff --git a/src/main/java/com/sk89q/worldedit/LocalPlayer.java b/src/main/java/com/sk89q/worldedit/LocalPlayer.java index c801e0299..9f3989224 100644 --- a/src/main/java/com/sk89q/worldedit/LocalPlayer.java +++ b/src/main/java/com/sk89q/worldedit/LocalPlayer.java @@ -549,4 +549,8 @@ public abstract class LocalPlayer extends LocalCommandSender { public void dispatchCUIHandshake() { } + @Override + public LocalPlayer asPlayer() { + return this; + } } diff --git a/src/main/java/com/sk89q/worldedit/PlayerNeededException.java b/src/main/java/com/sk89q/worldedit/PlayerNeededException.java new file mode 100644 index 000000000..83c459cae --- /dev/null +++ b/src/main/java/com/sk89q/worldedit/PlayerNeededException.java @@ -0,0 +1,5 @@ +package com.sk89q.worldedit; + +public class PlayerNeededException extends WorldEditException { + private static final long serialVersionUID = 1L; +}