Why does not my code work Minecraft Java Eclipse?

fl
- in Worlds
5

I'm trying to code a plugin like in suro with the zombies. When leavt a villigar is placed while spawning but not removet.

Quit:

@EventHandler
public void onQuit (PlayerQuitEvents) {
Player p = e.getPlayer (); String playername = p.getName (); File Vill = new File ("plugins // Lol // Vill //" + playername + ". Yml");

Villager person = (Villager) p.getWorld (). SpawnEntity (p.getLocation (), EntityType.VILLAGER); person.setCustomName (p.getName ()); YamlConfiguration vil = YamlConfiguration.loadConfiguration (Vill); person.addPotionEffect (new PotionEffect (PotionEffectType.SLOW, 500000, 200)); if (! Vill.exists ()) {try {Vill.createNewFile (); } catch (IOException jh) {// TODO Auto-generated catch block p.sendMessage ("§4 The specified path was not found!"); } vil.set (p.getName (), person.getEntityId ());

try {vil.save (Vill); } catch (IOException jh) {// TODO Auto-generated catch block p.sendMessage ("§4path not found"); }}

} public void checkFolder () {if (! Vill.exists ()) {Vill.mkdir (); }}

Join:

@EventHandler
public void onJoin (PlayerJoinEvents) {

Player p = e.getPlayer ();

String playername = p.getName ();
File Vill = new File ("plugins // Lol // Vill //" + playername + ". Yml");
YamlConfiguration vil = YamlConfiguration.loadConfiguration (Vill);
int offperson = vil.getInt (p.getName ());
Entity Villager = (entity) Bukkit.getWorld ("world"). GetEntities (). Get (offperson);
Villager.remove ();
Vill.delete ();

Hope you can help me why it is not possible.

Ay

1. Would I advise you to save everything in the file at once, because that can lead to a certain number of logins (which is the case with Suro, if all players are kicked at the same time) to laggs, or the server can even completely lubricate. I would put the UUID of the Villager first with the player's UUID in a hashmap and then at the end, when the server shuts down in peace all saving.

2. In no case work with the name of the player, because in principle he could change it at any time (and because of the thing with the Nametag.)

3. I do not know exactly how entities are stored in Minecraft, but I believe that reloading the world assigns a new ID to each entity, so I would work with the UUID rather than the ID.

I hope I could help you. Just ask me if anything is still unclear.

lg

Edit: I would still write Bukkit or Spigot in the title, otherwise it can lead to ambiguity.

fl

Thank you, I will try to implement

fl

If I want to save the uuid from the villager with:

Villager person = (Villager) p.getWorld (). SpawnEntity (p.getLocation (), EntityType.VILLAGER);

vil.set (p.getName (), person.getUniqueId ());

fl

If I want to save the uuid from the villager with:

Villager person = (Villager) p.getWorld (). SpawnEntity (p.getLocation (), EntityType.VILLAGER);

vil.set (p.getName (), person.getUniqueId ());

SSheht in the yml:
SSpielername:! Java.util.UUID {}

Ay

You have to hang behind the UUID still .toString ().