Reputation: 88
all. I've been having this issue where apparently I'm referencing a method that doesn't exist. The IDE doesn't flag anything as bad, so I am a little lost. I've tried a couple of things, but they don't seem to work. This is a work-in-progress, so not everything is finished, but it should still work. Anyways, here is the main class:
package me.xeyler;
import java.io.File;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class MazeMain extends JavaPlugin{
@Override
public void onEnable() {
new EventHandle(this);
File file = new File(getDataFolder(), "config.yml");
if(!file.exists()) {
getLogger().info("Generating config.yml...");
saveDefaultConfig();
}
getLogger().info("MinecraftMazer has been enabled!");
}
@Override
public void onDisable() {
getLogger().info("MinecraftMazer has been disabled!");
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if(cmd.getName().equalsIgnoreCase("makemaze")) {
if(!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "You must be a player to preform this command!");
} else {
Player player = (Player) sender;
MazeGenerator maze = new MazeGenerator();
//maze.generate(width, length, height, sender);
}
}
return false;
}
public class MazeGenerator {
public void generate( int width, int length, int height, Player sender ) {
}
}
}
And, of course, the "non-existent" class with the "non-existent" method:
package me.xeyler;
import java.util.HashMap;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.block.BlockState;
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.player.PlayerInteractEvent;
public class EventHandle implements Listener {
MazeMain Plugin;
public EventHandle(MazeMain plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
Plugin = plugin;
}
//setting some variables
private HashMap<Player, Location> start = new HashMap<Player, Location>();
private HashMap<Player, Location> end = new HashMap<Player, Location>();
//THESE VARIABLES WILL BE USED LATER FOR MARKING THE ENTRANCE AND EXIT TO A MAZE
//private HashMap<Player, Location> entrance = new HashMap<Player, Location>();
//private HashMap<Player, Location> exit = new HashMap<Player, Location>();
HashMap<Player, BlockState> startBlock = new HashMap<Player, BlockState>();
HashMap<Player, BlockState> endBlock = new HashMap<Player, BlockState>();
HashMap<Player, BlockState> entranceBlock = new HashMap<Player, BlockState>();
HashMap<Player, BlockState> exitBlock = new HashMap<Player, BlockState>();
ChatColor green = ChatColor.GREEN;
ChatColor red = ChatColor.RED;
ChatColor yellow = ChatColor.YELLOW;
ChatColor blue = ChatColor.BLUE;
@SuppressWarnings("deprecation")
@EventHandler
public void onMarkBlock(PlayerInteractEvent event) {
Player player = event.getPlayer();
if (player.hasPermission("MinecraftMazer.allowed")) {
if (player.getItemInHand().getType().toString().equalsIgnoreCase(Plugin.getConfig().getString("selectTool"))) {
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
event.setCancelled(true);
if (startBlock.get(player) != null) {
Location oldLoc = start.get(player);
BlockState oldBlock = startBlock.get(player);
oldLoc.getBlock().setType(oldBlock.getType());
oldLoc.getBlock().getState().setData(oldBlock.getData());
oldBlock.update(false, false);
}
start.put(player, event.getClickedBlock().getLocation());
if (Plugin.getConfig().getBoolean("markSelections")) {
startBlock.put(player, (event.getClickedBlock().getState()));
event.getClickedBlock().setType(org.bukkit.Material.WOOL);
event.getClickedBlock().setData((byte) 0);
}
int x = (int) start.get(player).getX();
int y = (int) start.get(player).getY();
int z = (int) start.get(player).getZ();
player.sendMessage(yellow + "Position one set as " + red + x + ", " + green + y + ", " + blue + z);
player.getWorld().playSound(player.getLocation(), Sound.ORB_PICKUP, 20, 1);
}
}
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (endBlock.get(player) != null) {
Location oldLoc2 = end.get(player);
BlockState oldBlock2 = endBlock.get(player);
oldLoc2.getBlock().setType(oldBlock2.getType());
oldLoc2.getBlock().getState().setData(oldBlock2.getData());
oldBlock2.update(false, false);
}
end.put(player, event.getClickedBlock().getLocation());
if (Plugin.getConfig().getBoolean("markSelections")) {
endBlock.put(player, event.getClickedBlock().getState());
event.getClickedBlock().setType(org.bukkit.Material.WOOL);
event.getClickedBlock().setData((byte) 15);
}
int x = (int) end.get(player).getX();
int y = (int) end.get(player).getY();
int z = (int) end.get(player).getZ();
player.sendMessage(yellow + "Position two set as " + red + x + ", " + green + y + ", " + blue + z);
player.getWorld().playSound(player.getLocation(), Sound.ORB_PICKUP, 20, 1);
}
}
}
}
And... drumroll, please! dum da-dum The all-powerful errors:
java.lang.NoSuchMethodError: me.xeyler.EventHandle.<init>(Lme/xeyler/MazeMain;)V
at me.xeyler.MazeMain.onEnable(MazeMain.java:15) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316) ~[spigot1658.jar:git-Spigot-"606148f"]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:333) [spigot1658.jar:git-Spigot-"606148f"]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:412) [spigot1658.jar:git-Spigot-"606148f"]
at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin(CraftServer.java:352) [spigot1658.jar:git-Spigot-"606148f"]
at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlugins(CraftServer.java:313) [spigot1658.jar:git-Spigot-"606148f"]
at org.bukkit.craftbukkit.v1_8_R1.CraftServer.reload(CraftServer.java:742) [spigot1658.jar:git-Spigot-"606148f"]
at org.bukkit.Bukkit.reload(Bukkit.java:301) [spigot1658.jar:git-Spigot-"606148f"]
at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:23) [spigot1658.jar:git-Spigot-"606148f"]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:181) [spigot1658.jar:git-Spigot-"606148f"]
at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java:643) [spigot1658.jar:git-Spigot-"606148f"]
at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchServerCommand(CraftServer.java:629) [spigot1658.jar:git-Spigot-"606148f"]
at net.minecraft.server.v1_8_R1.DedicatedServer.aM(DedicatedServer.java:353) [spigot1658.jar:git-Spigot-"606148f"]
at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:317) [spigot1658.jar:git-Spigot-"606148f"]
at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:625) [spigot1658.jar:git-Spigot-"606148f"]
at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:528) [spigot1658.jar:git-Spigot-"606148f"]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
Thanks for solving my stupid and hopefully easily-fixed problems, guys! You are the best!
Upvotes: 0
Views: 2091
Reputation: 81
Try removing the constructor from the listener.
In your main class:
private static MazeMain instance;
// Does not need override
public void onEnable(){
PluginManager manager = Bukkit.getPluginManager();
manager.registerEvents(new EventHandle(), this);
// Make the instance of this class available for other classes
instance = this;
// Your config generator
// You don't need to log enabling and disabling
// ^(Bukkit does that automatically)
}
public void onDisable(){
instance = null;
}
public static MazeMain getInstance(){
return instance;
}
In your listener, remove this:
public EventHandle(MazeMain plugin){
plugin.getServer().getPluginManager().registerEvents(this, plugin);
Plugin = plugin;
}
Also, change out all the
Plugin.getConfig()
with
MazeMain.getInstance().getConfig()
NEVER STORE PLAYER AND LOCATION OBJECTS! Just like the Block object, it's really heavy and will cause memory leaks. If you don't want tons of lag, I'd recommend you to convert the object to a string/UUID.
Player: Player.getUniqueId() will give you the UUID, then you can just do Bukkit.getPlayer(UUID) to get the Player object again (remember to check that object is not null).
Location: Store the World name/UID, x, y, z, yaw, pitch in a string seperated by a character. Turn it into a object by splitting the string and instantiate a new Location. If you are just going to keep location of blocks, then you don't need yaw and pitch for this case (it has to do with which way a player is looking).
Please remember private/public/protected flags in your classes.
You should fix the deprecations as it will lose support pretty quick. It's losing support for the reason that there is a better solution.
Also, why store the ChatColors in a variable?
(I'm pretty bad at explaining)
Upvotes: 1