#String "Arrow" to Arrow.class ?

1 messages · Page 1 of 1 (latest)

livid herald
#

Hello, I have a quick question: how can I convert a string to a class. For example, I have the following string: "Arrow" and I want to covert it to Arrow.class, how can I do this please ? Any help is greatly appreciated 😄

daring knoll
livid herald
#

Ok, I'll check these links and what I can do, thank you for the links 🙂

daring knoll
#

Do you need the class itself or an instance of the class?

livid herald
#

the class itself

daring knoll
#

kk

livid herald
#

I have a global class, and basicaly what I want to do is change the projectile fired by a bow when entrering a command

daring knoll
#

Ah, but you only want to change newly fired projectiles and not the already existing ones, right?

livid herald
#

Exactly

daring knoll
#

Even then, I'd rather suggest you just use if-statements, instead of doing it via Class.forName() as it would be less of a hassle and not as prone to unforseen issues

livid herald
#

global file

public static Class current_projectile=Arrow.class;

The target file

Projectile projectile=player.launchProjectile(global.current_projectile);
daring knoll
#

Ah, btw, the Class.forName() needs the entire class path, as in: "net.minecraft_1_12_2.Entities.Arrow" or smth like that

livid herald
#

ok, i'll try that, ty for the help 😄

daring knoll
#

Well don't be discouraged from trying stuff out, but things, especially where you do stuff dynamically with classes, can cause to some really nasty bugs/security issues

#

Anyways, good luck and have fun :D