[FIXED] Bukkit TNT Notifier

Post here is you are having problems with any of the tutorials.
Post Reply
User avatar
DomC
Posts: 91
Joined: Mon Jul 18, 2011 1:58 pm

[FIXED] Bukkit TNT Notifier

Post by DomC »

I fixed the problem - I had put CAKE as opposed to CAKE_BLOCK

Hey,
I was just watching the Java tutorials on how to make a TNT Notifier for Bukkit (the permissions section)
and when i tested it, the plugin ran fine if I was an op - placing TNT as normal but as soon as I deop-ed myself when I tried to place the TNT it just disappeared altogether so i tried again in a different place where it placed stone...

Has anyone else had this (weird) problem?

Here is the code for the TNTNotifierBlockListener.java
package com.technotizer;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack;

public class TNTNotifierBlockListener extends BlockListener {
	
	private TNTNotifier plugin;
	
	public TNTNotifierBlockListener(TNTNotifier instance) {
		this.plugin = instance;
	}
	
	public void onBlockPlace(BlockPlaceEvent event) {
		if(event.isCancelled()) return;
		
		Block block = event.getBlock();
		Player player = event.getPlayer();
		
		if(block.getType() == Material.TNT && player.hasPermission("tntnotifier.allow-tnt") == false) {
			block.setType(Material.CAKE);
			player.sendMessage(ChatColor.RED + "You are not allowed to use TNT on this server - sorry but have a cake!");
			plugin.logMessage(player.getName() + " placed a TNT block at " + block.getX() + "," + block.getY() + "," + block.getZ() + ".");
		}
	}
	
	public void onBlockBreak(BlockBreakEvent event) {
		if(event.isCancelled()) return;
		
		Block block = event.getBlock();
		
		if(block.getType() == Material.TNT) {
			event.setCancelled(true);
			block.setType(Material.AIR);
			
			block.getWorld().dropItemNaturally(block.getLocation(), new ItemStack(Material.CAKE, 1));
		}
	}
}
and here is the code for the plugin.yml file
name: TNTNotifier
version: 0.1
main: com.technotizer.TNTNotifier
permissions:
    tntnotifier.allow-tnt:
        description: Allows the use of TNT
        default: op
Thanks for any help you can provide
I can't think of anything witty to put here!

Check out some of my projects on GitHub: https://github.com/DomTC
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: [FIXED] Bukkit TNT Notifier

Post by jacek »

Self solving topics, I like this :D
Image
Post Reply