mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 14:38:48 +00:00
Add helper methods to context
This commit is contained in:
1 parent
82023a0e72
commit
eec630a48e
2 files changed
+45
-3
No files matched your search
@@ -4,8 +4,44 @@ import net.draycia.carbon.channels.ChatChannel;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
|
||||
public interface MessageContext {
|
||||
|
||||
ChatUser getSender();
|
||||
ChatUser getTarget();
|
||||
|
||||
ChatChannel getChatChannel();
|
||||
|
||||
Object getValue();
|
||||
|
||||
default boolean isDouble() {
|
||||
return getValue() instanceof Double;
|
||||
}
|
||||
|
||||
default boolean isString() {
|
||||
return getValue() instanceof String;
|
||||
}
|
||||
|
||||
default boolean isInteger() {
|
||||
return getValue() instanceof Integer;
|
||||
}
|
||||
|
||||
default boolean isBoolean() {
|
||||
return getValue() instanceof Boolean;
|
||||
}
|
||||
|
||||
default Double asDouble() {
|
||||
return (Double)getValue();
|
||||
}
|
||||
|
||||
default String asString() {
|
||||
return (String)getValue();
|
||||
}
|
||||
|
||||
default Integer asInteger() {
|
||||
return (Integer)getValue();
|
||||
}
|
||||
|
||||
default Boolean asBoolean() {
|
||||
return (Boolean)getValue();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,6 +13,10 @@ public class DistanceContext implements Function<MessageContext, Boolean> {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (context.isBoolean() && !context.asBoolean()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Location senderLocation = context.getSender().asPlayer().getLocation();
|
||||
Location targetLocation = context.getTarget().asPlayer().getLocation();
|
||||
|
||||
@@ -20,10 +24,12 @@ public class DistanceContext implements Function<MessageContext, Boolean> {
|
||||
return false;
|
||||
}
|
||||
|
||||
Double value = (Double) context.getValue();
|
||||
if (context.isDouble()) {
|
||||
Double value = context.asDouble();
|
||||
|
||||
if (value > 0) {
|
||||
return senderLocation.distance(targetLocation) <= value;
|
||||
if (value > 0) {
|
||||
return senderLocation.distance(targetLocation) <= value;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in new issue
Block a user