Can't cast String to Particle

Discussion in 'Plugin Development' started by HenriPotter, Apr 8, 2021.

Thread Status:
Not open for further replies.
  1. Offline

    HenriPotter

    Hello,
    I want to get a particle (as a string) out of a .yml file and convert it into a Particel. I want to do that, so I can spawn particle at the Player which he slected previous. I tryed it like that:
    Particle partikel = (Particle) yamlConfiguration.get(String.valueOf(player));
     
  2. Offline

    timtower Administrator Administrator Moderator

    @HenriPotter Show the full method please and the value of "player"
     
  3. Offline

    HenriPotter

    The method:
    Code:
    @EventHandler
    public static void onPlayerMove(PlayerMoveEvent event) {
    if (!event.getFrom().getBlock().equals(event.getTo().getBlock())) {
    Player player = event.getPlayer();
    File file = new File("plugins//config//partikel.yml");
    YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(file);
    if (yamlConfiguration.contains(String.valueOf(player))) {
    String partikell = (String) yamlConfiguration.get(String.valueOf(player));
    if (!(partikell == "NONE")) {
    Particle partikel = (Particle) yamlConfiguration.get(String.valueOf(player));
    World world = player.getWorld();
    world.spawnParticle(partikel, event.getFrom(), 2, 0, 0.5, 0);
    }
    }
    }
    }
    
    Sorry, I'm new to this forum and I don't know how to format code right.

    The partikel.yml:

    CraftPlayer{name=HenriPotter}: HEART
     
    Last edited: Apr 8, 2021
  4. Offline

    timtower Administrator Administrator Moderator

    @HenriPotter 1. new File(plugin.getDataFolder(), "partikel.yml") to get the correct file.
    2. Use UUID's instead of Player objects.
     
    davidclue likes this.
Thread Status:
Not open for further replies.

Share This Page