<commit_before>package com.elmakers.mine.bukkit.wand;

import java.util.LinkedList;

import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.inventory.ItemStack;

import com.elmakers.mine.bukkit.api.magic.MagicAPI;
import com.elmakers.mine.bukkit.api.wand.LostWand;
import com.elmakers.mine.bukkit.api.wand.Wand;
import com.elmakers.mine.bukkit.utility.RunnableJob;

public class WandCleanupRunnable extends RunnableJob {
	private final LinkedList<LostWand> lostWands = new LinkedList<LostWand>();
	private final World world;
	private final MagicAPI api;
	private final String owner;
	private final boolean removeAll;
    private final boolean check;
	
	public WandCleanupRunnable(MagicAPI api, World world, String owner, boolean check) {
		super(api.getLogger());
		this.world = world;
		this.api = api;
		lostWands.addAll(api.getLostWands());
		this.removeAll = owner.equals("ALL");
        this.check = check;
		this.owner = owner == null ? "" : owner;
	}
	
	public WandCleanupRunnable(MagicAPI api, World world) {
		super(api.getLogger());
		this.world = world;
		this.api = api;
		this.removeAll = true;
        this.check = false;
		this.owner = "";
		lostWands.addAll(api.getLostWands());
	}
	
	public void finish() {
		super.finish();
		lostWands.clear();
	}
	
	public void run() {
		if (lostWands.isEmpty()) {
			finish();
			return;
		}
		LostWand lostWand = lostWands.getFirst();
		Location location = lostWand.getLocation();
		if (world != null && !location.getWorld().getName().equals(world.getName())) {
			lostWands.removeFirst();
			return;
		}<commit_msg>Fix NPE in "/magic clean".<commit_after>package com.elmakers.mine.bukkit.wand;

import java.util.LinkedList;

import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.inventory.ItemStack;

import com.elmakers.mine.bukkit.api.magic.MagicAPI;
import com.elmakers.mine.bukkit.api.wand.LostWand;
import com.elmakers.mine.bukkit.api.wand.Wand;
import com.elmakers.mine.bukkit.utility.RunnableJob;

public class WandCleanupRunnable extends RunnableJob {
	private final LinkedList<LostWand> lostWands = new LinkedList<LostWand>();
	private final World world;
	private final MagicAPI api;
	private final String owner;
	private final boolean removeAll;
    private final boolean check;
	
	public WandCleanupRunnable(MagicAPI api, World world, String owner, boolean check) {
		super(api.getLogger());
		this.world = world;
		this.api = api;
		lostWands.addAll(api.getLostWands());
		this.removeAll = owner != null && owner.equals("ALL");
        this.check = check;
		this.owner = owner == null ? "" : owner;
	}
	
	public WandCleanupRunnable(MagicAPI api, World world) {
		super(api.getLogger());
		this.world = world;
		this.api = api;
		this.removeAll = true;
        this.check = false;
		this.owner = "";
		lostWands.addAll(api.getLostWands());
	}
	
	public void finish() {
		super.finish();
		lostWands.clear();
	}
	
	public void run() {
		if (lostWands.isEmpty()) {
			finish();
			return;
		}
		LostWand lostWand = lostWands.getFirst();
		Location location = lostWand.getLocation();
		if (world != null && !location.getWorld().getName().equals(world.getName())) {
			lostWands.removeFirst();
			return;
		}
{'fraction_non_alphanumeric': 0.13010053222945003, 'fraction_numerical': 0.0, 'mean_word_length': 4.2612752721617415, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1464196', 'n_tokens_mistral': 1259, 'n_tokens_neox': 1128, 'n_words': 242}