EnderFurnace (Last thing I should do in my plugin)

Discussion in 'Spigot Plugin Help' started by Newpredator, Jun 26, 2018.

  1. The ender thing works but the materials doesn´t cook. They changed the methods of TileEntityFurnace from previous versions.
    Code (Text):
    package me.newpredator.Annihilation.listeners;

    import java.util.HashMap;

    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
    import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryFurnace;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.InventoryHolder;
    import me.newpredator.Annihilation.object.PlayerMeta;

    import me.newpredator.Annihilation.Annihilation;
    import me.newpredator.Annihilation.object.GameTeam;
    import net.minecraft.server.v1_12_R1.EntityHuman;
    import net.minecraft.server.v1_12_R1.EntityPlayer;
    import net.minecraft.server.v1_12_R1.TileEntityFurnace;


    public class EnderFurnaceListener implements Listener {
       
        private HashMap<GameTeam, Location> locations;
        private HashMap<String, VirtualFurnace> furnaces;
       
        public EnderFurnaceListener(Annihilation plugin) {
            locations = new HashMap<GameTeam, Location>();
            furnaces = new HashMap<String, VirtualFurnace>();
            Bukkit.getScheduler().runTaskTimer(plugin, new Runnable() {
                public void run() {
                    for (VirtualFurnace f : furnaces.values()) {
                        try {
                            f.d();
                        } catch (Exception e) {
                        }
                    }
                }
            }, 0L, 1L);
        }
        public void setFurnaceLocation(GameTeam team, Location loc) {
            locations.put(team, loc);
        }
        @EventHandler
        public void onFurnaceOpen(PlayerInteractEvent e) {
            if (e.getAction() != Action.RIGHT_CLICK_BLOCK) {
                return;
            }
            Block b = e.getClickedBlock();
            if (b.getType() != Material.FURNACE) {
                return;
            }
            Location loc = b.getLocation();
            Player player = e.getPlayer();
            GameTeam team = PlayerMeta.getMeta(player).getTeam();
            if (team == null || !locations.containsKey(team)) {
                return;
            }
            if (locations.get(team).equals(loc)) {
                e.setCancelled(true);
                EntityHuman handle = ((CraftPlayer) player).getHandle();
                handle.openContainer(getFurnace(player));
                player.sendMessage(Annihilation.getInstance().getConfig().getString("prefix").replace("&", "§") + " §7Has entrado en el §3horno privado");
               
            } else if (locations.containsValue(loc)) {
                e.setCancelled(true);
            }
        }
        @EventHandler
        public void onFurnaceBreak(BlockBreakEvent e) {
            if (locations.values().contains(e.getBlock().getLocation())) {
                e.setCancelled(true);
            }
        }
        private VirtualFurnace getFurnace(Player player) {
            if (!furnaces.containsKey(player.getName())) {
                EntityPlayer handle = ((CraftPlayer) player).getHandle();
                furnaces.put(player.getName(), new VirtualFurnace(handle));
            }
            return furnaces.get(player.getName());
        }
        private class VirtualFurnace extends TileEntityFurnace {
            public VirtualFurnace(EntityHuman entity) {
                world = entity.world;
            }
            @Override
            public boolean a(EntityHuman entity) {
                return true;
            }

           
            @Override
            public InventoryHolder getOwner() {
                return new InventoryHolder() {
                    public Inventory getInventory() {
                        return new CraftInventoryFurnace(VirtualFurnace.this);
                    }
                };
            }
        }
    }
    I think the mistake is f.d(); because it was changed with the version
     
  2. someone knows how to do it?