TriggerReactor

TriggerReactor

24.6k Downloads

new placeholder $isnumber and new CommonFunction typeOf(Object value)

rkdrns4747 opened this issue · 16 comments

commented

$typeof:value

ㄴ returns type in string, only lowercase.
this can also be $isbool, $isint...etc, but $typeof looks a lot better for me.

$isnumber:string

ㄴreturns boolean value, checking if the string only contains numeric value, like:

$isnumber:"-13.2" // true
$isnumber:"395S" // false

typeOf(Object value)

ㄴ returns type in String, in only UPPERCASE.

#MESSAGE typeOf("hi")
//result: "STRING"
commented

@gerzytet#2873 cuz It's more easy for newcomers or someone who does not used to Java, since I've always had trouble with choosing uppercase or lowercase on initial letter. that's why I decided to use STRING instead of String.

commented

@rkdrns4747
Why does it return the type as uppercase only?
It would be much better for it to return the actual case, since other reflection methods will accept that.

commented

I ALWAYS HAVE A HARD TIME DECIDING WHETHER TO CAPITALIZE OR NOT CAPITALIZE THE BEGINNING OF A SENTENCE, SO ILL MAKE IT EASIER FOR ISSUE BOARD NEWCOMERS AND PEOPLE WHO DONT USE ENGLISH.
YOURE FORGETTING THAT JAVA CLASSES ARE CASE SENSITIVE, SO MAKING SURE THE CAPITALS ARE EXACT IS ESSENTIAL TO IDENTIFYING THE CORRECT CLASS, ESPECIALLY SINCE THIS IS A REFLECTION FEATURE (NOT FOR NEWCOMERS). IN MOST CONTEXTS, FORCING ALL CAPS ON A CLASS NAME MAKES IT NEARLY USELESS. WHAT ARE YOU SUPPOSED TO DO IF YOU WANTED TO USE IT, SINCE NO REFLECTION METHODS SUPPORT ALL-CAPS CLASS NAMES? LOOK THROUGH EVERY CLASS IN THE JVM AND FIGURE OUT WHICH ONE MATCHES?

commented

@gerzytet
It wasn't really necessary to be sarcastic there.

I can't really read when you capitalize on every words.

commented

@wysohn
@rkdrns4747
Sorry, I should have been kinder with my comment,
What I'm trying to say is that types of objects aren't just used for == testing and human-readable reports. They can be passed in to other reflection CommonFunctions as well. When you capitalize the whole class name, they can't be used that way anymore since class names are case sensitive.
If users want uppercase or lowercase names, they can convert it themselves.
However, this won't be a problem anyway since most users don't poke around in commonfunctions unless they can understand a javadoc which requires understanding java's type system which requires understanding camelCase.

commented

@gerzytet you're right. CommonFunctions is pretty advanced one, so typeOf() will be used mostly by java advanced user.

commented

@rkdrns4747
I noticed that $isnumber only accepts strings
I think it would make more sense for it to accept anything

commented

@gerzytet can you explain more about it? I thought it would be used only for string.

commented

I think what @gerzytet means is that $isnumber should check if the given object is an instance of Number,

and the proposal here is trying to check if the provided string is a valid number so that it can be converted by toInt(String), etc. method.

commented

@rkdrns4747
That is exactly what I mean
$isnumber:3.2 should be true

commented

If I pretend that I'm the newcomer and not knowing deeply about this plugin, it would be useful to have those placeholders.

People usually don't go through all the way to the deep java capability of this plugin, yet they tend to rely on things like Executor and Placeholder.

Which is completely fine since that's our target users. Having more Executors and Placeholders is always good in my opinion.

commented

But if you’re a newcomer, would you use these placeholders?
Operating on the type of arbitrary objects is a reflection feature. This would be the first ever reflection feature that’s been added as a placeholder.
Placeholders should be useable and understandable by newcomers, but newcomers won’t use reflection, so it should be a commonfunction instead.
$isnumber, on the other hand, is simpler and doesn’t rely on reflection

commented

@rkdrns4747
We might not need this as a placeholder
Consider trying to implement as a special case of the IS operator

commented

Think about the use cases. The need to validate the exact type of an object should only come up when java interaction is needed. As a result, I think requiring an IS expression is more appropriate:

IMPORT java.lang.Integer
#MESSAGE 3 IS Integer

In fact, this code might already work
As for $typeof, it’s a bad idea to try implementing this as a placeholder since js interprets types differently than java does. The java way is more useful, especially in the case of Double vs Integer.

Implementing typeof as a CommonFunction instead would be better.

I support $isnumber though, since it can be used to validate arguments in a command trigger.

commented

hmm, I don't think newcomer never use the placeholder, cuz it would be more helpful in such as EntityDeathEvent which can return lots each type of entity.

However, in reflection point, what gerzytet said makes sense, so it's better to make it as commonFuction feature.

commented

Good point

What do you think @rkdrns4747?