Started by
Someone is here
on
Topic category: Help with Minecraft modding (Java Edition)
so i am creating a hopper sorter plugin, but it says it cannot find symbol.
here is the HopperSorter.java:
package com.ravijol1.hoppersorter.custom;
import org.bukkit.block.Container;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.inventory.InventoryType;
import java.util.Arrays;
public class HopperSorter implements Listener {
String getItemName(String translationKey) {
if(translationKey==null) return null;
String[] names = translationKey.split("\\.");
return names[names.length-1];
}
boolean filterMatch(String filterString, String fullItemName) {
String itemName = getItemName(fullItemName);
String[] filter = filterString.split(",");
return Arrays.asList(filter).stream().anyMatch((filter_i) -> {
if(filter_i.endsWith("*")) {
return itemName.startsWith(filter_i.substring(0, filter_i.length()-1));
} else if(filter_i.startsWith("*")) {
return itemName.endsWith(filter_i.substring(1));
} else {
return filter_i.equalsIgnoreCase(itemName);
}
});
}
@EventHandler
void onInventoryMoveItemEvent(InventoryMoveItemEvent event) {
if(event.getDestination().getType().equals(InventoryType.HOPPER)
&& event.getDestination().getHolder() instanceof Container) {
String customName = ((Container) event.getDestination().getHolder()).getCustomName();
if(customName != null) {
String itemName = event.getItem().getType().translationKey();
if(!filterMatch(customName, itemName)) {
event.setCancelled(true);
}
}
}
}
@EventHandler
void onInventoryPickupItemEvent(InventoryPickupItemEvent event) {
if(event.getInventory().getHolder() instanceof Container) {
String customName = ((Container) event.getInventory().getHolder()).getCustomName();
if (customName != null) {
String itemName = event.getItem().getItemStack().getType().translationKey();
if(!filterMatch(customName, itemName)) {
event.setCancelled(true);
}
}
}
}
}
and here is the error:
Executing Gradle task: build
Build info: MCreator 2022.3.48217, spigot-1.19, 64-bit, 8101 MB, Windows 10, JVM 17.0.3, JAVA_HOME: C:\Program Files\Pylo\MCreator\jdk, started on: 2023-02-08-16:30:33
> Task :compileJava FAILED
C:\Users\liams\MCreatorWorkspaces\hopper_sorter\src\main\java\com\ravijol1\hoppersorter\custom\HopperSorter.java:41: error: cannot find symbol String itemName = event.getItem().getType().translationKey();
^
symbol: method translationKey()
location: class Material
C:\Users\liams\MCreatorWorkspaces\hopper_sorter\src\main\java\com\ravijol1\hoppersorter\custom\HopperSorter.java:54: error: cannot find symbol String itemName = event.getItem().getItemStack().getType().translationKey();
^
symbol: method translationKey()
location: class Material
2 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 550ms
1 actionable task: 1 executed
BUILD FAILED
Task completed in 2 seconds