Last active
October 17, 2015 23:44
-
-
Save NeatMonster/4d43c6efe7b79c043832 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: TNTLimit | |
| version: 1.0 | |
| author: NeatMonster | |
| main: fr.neatmonster.tntlimit.TNTLimit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package fr.neatmonster.tntlimit; | |
| import org.bukkit.ChatColor; | |
| import org.bukkit.Material; | |
| import org.bukkit.block.Block; | |
| import org.bukkit.block.BlockFace; | |
| import org.bukkit.event.EventHandler; | |
| import org.bukkit.event.Listener; | |
| import org.bukkit.event.block.BlockPlaceEvent; | |
| import org.bukkit.plugin.java.JavaPlugin; | |
| public class TNTLimit extends JavaPlugin implements Listener { | |
| public static Block getAbove(final Block block) { | |
| return block.getRelative(BlockFace.UP); | |
| } | |
| public static Block getBelow(final Block block) { | |
| return block.getRelative(BlockFace.DOWN); | |
| } | |
| public static boolean isTNT(final Block block) { | |
| return block.getType() == Material.TNT; | |
| } | |
| @Override | |
| public void onEnable() { | |
| getServer().getPluginManager().registerEvents(this, this); | |
| } | |
| @EventHandler | |
| public void onBlockPlace(final BlockPlaceEvent event) { | |
| if (event.getPlayer().isOp()) | |
| return; | |
| final Block block = event.getBlockPlaced(); | |
| if ((isTNT(block) && isTNT(getAbove(block)) && isTNT(getAbove(getAbove(block)))) | |
| || (isTNT(block) && isTNT(getBelow(block)) && isTNT(getBelow(getBelow(block))))) { | |
| event.getPlayer().sendMessage(ChatColor.RED + "Les colonnes de TNT sont interdites !"); | |
| event.setCancelled(true); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment