Rapha149 / SignGUI

An api to get input text via a sign in Minecraft.
MIT License
35 stars 12 forks source link

cannot find symbol method of(de.rapha149.signgui.SignGUIAction,de.rapha149.signgui.SignGUIAction) #9

Closed cmptrwhz closed 2 months ago

cmptrwhz commented 2 months ago

Do I need to return a "List.of" or would it be valid if I return an "Arrays.asList" instead? Am I missing a class import? Please advise me as to what I maybe doing incorrectly and thank you in advance for any assistance.

Error-

java: cannot find symbol symbol: method of(de.rapha149.signgui.SignGUIAction,de.rapha149.signgui.SignGUIAction) location: interface java.util.List

section of code usage and imports-

import de.rapha149.signgui.*;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.cmptrwhz.dezomarket.gui.MainSelect;
import org.cmptrwhz.dezomarket.gui.GetSellingItm;

import java.util.*;

if (isNumeric(line0)) {
    // close the sign and open an inventory
    return List.of(
            // "this" = your JavaPlugin instance
            SignGUIAction.openInventory(this, SellItemGui.getInventory()),
            SignGUIAction.run(() -> player.sendMessage("Selling Item for: " + line0))
    );
}
Rapha149 commented 2 months ago

Could you maybe send the whole code which opens the sign? I'm afraid this snippet is not enough to determine what the problem is.

cmptrwhz commented 2 months ago
package org.cmptrwhz.dezomarket.dezevents;

import de.rapha149.signgui.*;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.cmptrwhz.dezomarket.gui.MainSelect;
import org.cmptrwhz.dezomarket.gui.GetSellingItm;

import java.util.*;

public class DezEvents extends JavaPlugin implements Listener {

    private GetSellingItm SellItemGui = new GetSellingItm();

    @EventHandler
    public void onClick(InventoryClickEvent e){
        if (e.getClickedInventory() == null) { return; }

        //GUI.MAINSELECT
        if (e.getClickedInventory().getHolder() instanceof MainSelect) {
            e.setCancelled(true);
            Player player = (Player) e.getWhoClicked();
            if (e.getCurrentItem() == null) { return; }
            if (e.getSlot() == 11){
                //selling an item, open screen to accept user item
                player.openInventory(SellItemGui.getInventory());
            }
            else if (e.getSlot() == 13){
                //claiming an item, open screen to show user items purchased
                player.closeInventory();
            }
            else if (e.getSlot() == 15){
                //managing items for sale, open screen to show user items they have for sale
                player.closeInventory();
            }
        }

        //GUI.GetSellingItm
        if (e.getClickedInventory().getHolder() instanceof GetSellingItm) {
            e.setCancelled(true);
            Player player = (Player) e.getWhoClicked();
            if (e.getCurrentItem() == null) { return; }
            if (e.getSlot() == 11 || e.getCurrentItem().getType() == Material.STONE_BUTTON){
                //take player item, save to yml, open GUI.GetSellingItm replace button with item
                player.closeInventory();
            } else if (e.getSlot() == 11 || e.getCurrentItem().getType() != Material.STONE_BUTTON) {
                //return item back to their inventory
                player.closeInventory();
            } else if (e.getSlot() == 13){
                //get amount from player
                player.closeInventory();
                //https://github.com/Rapha149/SignGUI
                SignGUI signGUI = SignGUI.builder()
                        // set lines
                        .setLines(null,"§6Enter Selling Amount","§6--------------","§6-------")

                        // set the sign type
                        .setType(Material.SPRUCE_SIGN)

                        // set the handler/listener (called when the player finishes editing)
                        .setHandler((p, result) -> {
                            // get a speficic line, starting index is 0
                            String line0 = result.getLine(0);

                            if (isNumeric(line0)) {
                                // close the sign and open an inventory
                                return List.of(
                                        SignGUIAction.openInventory(this, SellItemGui.getInventory()),
                                        SignGUIAction.run(() -> player.sendMessage("Selling Item for: " + line0))
                                );
                            }
                            // Just close the sign by not returning any actions
                            return Collections.emptyList();
                        })

                        // build the SignGUI
                        .build();

                // open the sign
                signGUI.open(player);
            }
            else if (e.getSlot() == 15){
                //save transaction to mysql, clean up player item yml file, return to mainselect
                player.closeInventory();
            }
        }

        //GUI.CLAIMSCREEN

        //GUI.MANAGESCREEN

    }

    public static boolean isNumeric(String strNum) {
        if (strNum == null) {
            return false;
        }
        try {
            Integer i = Integer.parseInt(strNum);
        } catch (NumberFormatException nfe) {
            return false;
        }
        return true;
    }
}
Rapha149 commented 2 months ago

Okay, it seems like your compiler doesn't find the method List.of, I just now understood the error message. List.of was added in Java 9 so if you still compile on Java 8 that could be the reason why it's not working. You only have to return a list of actions for the method, you of course you can also use Arrays.asList or anything else that constructs a java.util.List.

cmptrwhz commented 2 months ago

Thank you for confirming my thoughts. I am not exactly sure why project believes I am using a lesser JDK i have it set to 17 but I will go through my settings again to be sure. Thank you for the information. using Arrays.asList did compile.