is it because you forgot to check the bukkitemptyevent? give us more information what part is not working
I think you mean .java, not .jar. Anyway, you used @EventHandler for functions that have nothing to do with events (onEnable, onDisable... ) and you didn't use it on actual events. Then, I don't get the reason for those events in the main class, you only check if it's cancelled and just end there... ?!
@MrDent009 That's because you never checked if the placed block was in the black list and just cancelled the event straight out. Code: @EventHandler(priority = EventPriority.NORMAL) public void onBlockPlace(BlockPlaceEvent event) { if (!Arrays.asList(placedBlackList).contains(event.getBlock().getType())) return; Player player = event.getPlayer(); player.sendMessage(ChatColor.DARK_RED + " No! That's a BadBlock!"); event.setCancelled(true); }
@r0306 Is this correct? MyBlockListener.java Code: package me.Dent009.BadBlock; import java.util.Arrays; import net.minecraft.server.Material; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockPlaceEvent; public class MyBlockListener implements Listener { public static MyBlockListener plugin; public static Material[] placedBlacklist = {Material.TNT, Material.LAVA}; public static Material[] destroyedBlacklist = {Material.TNT, Material.LAVA}; public MyBlockListener(MyBlockListener instance) { plugin = instance; } @EventHandler(priority = EventPriority.NORMAL) public void onBlockPlace(BlockPlaceEvent event) { if (!Arrays.asList(placedBlacklist).contains(event.getBlock().getType())) return; Player player = event.getPlayer(); player.sendMessage(ChatColor.DARK_RED + " No! That's a BadBlock!"); event.setCancelled(true); } } And. How would I make my permission work? I'm pretty new with Java. And bukkit. Java is good for the soul
@MrDent009 I would just add this permissions check right after the player variable declaration. Code: if (player.hasPermission("bb.place")) return; Or, you could combine it: Code: if (!Arrays.asList(placedBlacklist).contains(event.getBlock().getType()) || player.hasPermission("bb.place")) return;
in your main class, as @Digi said, there is an event that just sets it to cancelled, no matter what. Even if you had set up and registered the events from the listener class (which you didnt, and they therefore do not even execute), the main class's event, and the second class's event methods would both run. Lets say they place a valid block. The second classes event wouldnt change the cancellation, but the main class's would. Remove the event cancellation (preferrably the entire method...) and lets go from there.
Okay, you gotta think logically how your plugin works. In typical programming, when you create an application, everything derives from public static main(String[] args) Well in bukkit programming, it starts in onEnable()* Everything you do must start/be initialized from on enable. Code: public void onEnable() { PluginManager pm = getServer().getPluginManager(); pm.registerEvents(this, this); PluginDescriptionFile pdfFile = this.getDescription(); this.log.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " is now enabled."); } Look at your onEnable method. Your second class file is nowhere to be found. All you are doing is registering your main class (not your secondary class) as a listener. Well, whats going on there? This: Code: @EventHandler(priority = EventPriority.NORMAL) public void onBlockPlace(BlockPlaceEvent event) { Player player = event.getPlayer(); player.sendMessage(ChatColor.GREEN + " [BadBlock] Must be member! "); event.setCancelled(true); } This just flat out cancels all block places. You Remove this method, stop making your main class implement Listener, dont register it as a listener, create your secondary class file, and then register it as a listener. *Technically not ooooooooooone hundred percent true... If you do some fancy programming you can program outside of onEnable... but it'd be fairly tricky and either niche, or pointless.
So should it be... Code: @EventHandler(priority = EventPriority.NORMAL) public void onBlockPlace(BlockPlaceEvent event) { if (!Arrays.asList(placedBlacklist).contains(event.getBlock().getType()) || player.hasPermission("bb.place")) return; Player player = event.getPlayer(); player.sendMessage(ChatColor.DARK_RED + " No! That's a BadBlock!"); event.setCancelled(true); return false; I'm so sorry if I am bothering you. But I want to see my plugin work [first bukkit plugin]
You are a noob, but dont worry, we all were at one point Woah, that return looks weird to me. But... technically should work. However, they will still be able to place lava, because lava placing doesnt throw a block place event.
@MrDent009 Why return false? The method has return type void so that means the return shouldn't return anything. Remove the false after return and also place the Player player declaration in front of the if statement.
@r0306 So, this is correct? Because it still isn't working correctly. Now I have an error in my log [at startup] Code: @EventHandler(priority = EventPriority.NORMAL) public void onBlockPlace(BlockPlaceEvent event) { Player player = event.getPlayer(); if (!Arrays.asList(placedBlacklist).contains(event.getBlock().getType()) || player.hasPermission("bb.place")) return; player.sendMessage(ChatColor.DARK_RED + " No! That's a BadBlock!"); event.setCancelled(true);
Code: 02:52:59 [SEVERE] Could not load 'plugins\BadBlock.jar' in folder 'plugins' org.bukkit.plugin.InvalidDescriptionException: Invalid plugin.yml at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPlug inLoader.java:194) at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager .java:132) at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:213) at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:189) at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigur ationManager.java:53) at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:166) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:432) at net.minecraft.server.ThreadServerApplication.run(SourceFile:492) Caused by: java.io.FileNotFoundException: Jar does not contain plugin.yml ... 8 more This is the error in the log [startup]
Here it is Code: author: Dent009 database: false description: > Stop users from placing lava or tnt! main: me.Dent009.BadBlock.BadBlock name: BadBlock startup: postworld version: '1.0' commands:
@JxAxVxAx Okay. I fixed the errors, but my plugin isn't working properly. PROBLEM = Disables users to place ANY blocks!
@r0306 @CorrieKay I updated it to how the project is currently. Check it out and tell me what is wrong with it.
Your listener class is not in your main class so don't register the main class in the plugin manager. Register your listener class instead. Code: pm.registerEvents(new MyBlockListener(this), this);
BadBlock.java Code: package me.Dent009.BadBlock; import java.util.logging.Logger; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.permissions.Permission; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginManager; import org.bukkit.event.Listener; public class BadBlock extends JavaPlugin implements Listener { private static final Logger log = Logger.getLogger("Minecraft"); public Permission openPermission = new Permission("bb.place"); @SuppressWarnings("static-access") @Override public void onEnable() { PluginManager pm = getServer().getPluginManager(); pm.registerEvents(this, this); pm.registerEvents(new MyBlockListener(this), this); PluginDescriptionFile pdfFile = this.getDescription(); this.log.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " is now enabled."); } @SuppressWarnings("static-access") @Override public void onDisable() { PluginDescriptionFile pdfFile = this.getDescription(); this.log.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " is now disabled."); } @Override public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { return false; } } Is this correct....I feel really stupid
@r0306 Another error on boot-up. Isn't that wonderful? Code: 04:37:59 [SEVERE] Error occurred while enabling BadBlock v1.0 (Is it up to date? ) java.lang.Error: Unresolved compilation problems: The method registerEvents(Listener, Plugin) in the type PluginManager is not applicable for the arguments (MyBlockListener, BadBlock) The constructor MyBlockListener(BadBlock) is undefined at me.Dent009.BadBlock.BadBlock.onEnable(BadBlock.java:23) at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:215) at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader .java:337) at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage r.java:381) at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:256) at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:238 ) at net.minecraft.server.MinecraftServer.t(MinecraftServer.java:381) at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:368) at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:197) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:432) at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)