I have two classes "main" for commands and more and "events" for events and now I want to make that the event "PlayerdeathEvent" teleport me to a point and the cordinates from the point are saved in a config now i test this:
I made it in the event class
public void lbbkampfrespawn() { FileConfiguration cfg = this.getConfig(); { String world = cfg.getString("LBBsetkampfrespawn1.world"); double x = cfg.getDouble("LBBsetkampfrespawn1.x"); double y = cfg.getDouble("LBBsetkampfrespawn1.y"); double z = cfg.getDouble("LBBsetkampfrespawn1.z"); double yaw = cfg.getDouble("LBBsetkampfrespawn1.yaw"); double pitch = cfg.getDouble("LBBsetkampfrespawn1.pitch"); Location loc = new Location(Bukkit.getWorld(world), x, y, z); loc.setYaw((float) yaw); loc.setPitch((float) pitch); p1.teleport(loc); } { String world = cfg.getString("LBBsetkampfrespawn2.world"); double x = cfg.getDouble("LBBsetkampfrespawn2.x"); double y = cfg.getDouble("LBBsetkampfrespawn2.y"); double z = cfg.getDouble("LBBsetkampfrespawn2.z"); double yaw = cfg.getDouble("LBBsetkampfrespawn2.yaw"); double pitch = cfg.getDouble("LBBsetkampfrespawn2.pitch"); Location loc = new Location(Bukkit.getWorld(world), x, y, z); loc.setYaw((float) yaw); loc.setPitch((float) pitch); p2.teleport(loc); } } }
Problem :
the dont know about "getConfig()"
eclipse said me to crathe the method getConfig()
i made it in the main class with static
public static void lbbkampfrespawn() { FileConfiguration cfg = this.getConfig(); { String world = cfg.getString("LBBsetkampfrespawn1.world"); double x = cfg.getDouble("LBBsetkampfrespawn1.x"); double y = cfg.getDouble("LBBsetkampfrespawn1.y"); double z = cfg.getDouble("LBBsetkampfrespawn1.z"); double yaw = cfg.getDouble("LBBsetkampfrespawn1.yaw"); double pitch = cfg.getDouble("LBBsetkampfrespawn1.pitch"); Location loc = new Location(Bukkit.getWorld(world), x, y, z); loc.setYaw((float) yaw); loc.setPitch((float) pitch); p1.teleport(loc); } { String world = cfg.getString("LBBsetkampfrespawn2.world"); double x = cfg.getDouble("LBBsetkampfrespawn2.x"); double y = cfg.getDouble("LBBsetkampfrespawn2.y"); double z = cfg.getDouble("LBBsetkampfrespawn2.z"); double yaw = cfg.getDouble("LBBsetkampfrespawn2.yaw"); double pitch = cfg.getDouble("LBBsetkampfrespawn2.pitch"); Location loc = new Location(Bukkit.getWorld(world), x, y, z); loc.setYaw((float) yaw); loc.setPitch((float) pitch); p2.teleport(loc); } }
Problem : I dont can uset this. in static
What I have to do thanks for your help !
When you need more from the cod please send what.
Thanks. Sry for the spelling
The
getConfig()
method is inherited from theJavaPlugin
class which only one of your classes should extend. There are many ways you can access the config file from another class though. One could, for example, keep a reference to your "main" class or plugin (the one that extendsJavaPlugin
) and to then callgetConfig()
using that object/reference. You could also create a static getter method that returns the instance of your plugin (not sure if this is good practice). Eclipse is probably telling you to create thegetConfig()
method because you are calling it in a class that doesn't extendJavaPlugin
.For example, let's say your class that extends
JavaPlugin
is called "Main". If you for example have a listener class that wants to access your Main class, you could ask for this information in the constructor for the listener class. In your listener class you would have:As you can see, this enables you to use
plugin.getConfig()
anywhere in yourMainListener
class. You would instantiate the listener (for example in theonEnable()
method of your Main class) withnew MainListener(this);
. Don't forget to register the listener of course.I understand what you are trying to do here but I believe there is a better way to do it (teleporting the player while he is dead is glitchy or plain doesn't work). I'm not sure why you made your method static, are you calling it in the event method?
P1
andp2
are not being passed as arguments in the method. This is what I would do (tried this and it worked): Instead of teleporting the player on the event of a death, change the respawn location when a player respawns like so:Here is my test config.yml file:
Note: I didn't check whether the world with that name really exists and whether the location is a safe one for the player to teleport to. That would be things you would need to implement.