forked from CodyScheer/NetherWater
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
97 additions
and
41 deletions.
There are no files selected for viewing
55 changes: 51 additions & 4 deletions
55
src/com/leetzilantonis/netherwater/BlockBreakListener.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,54 @@ | ||
package com.leetzilantonis.netherwater; | ||
|
||
/** | ||
* Created by Michal ŠMAHEL (ceskyDJ) on 4/28/20. | ||
*/ | ||
public class BlockBreakListener { | ||
import org.bukkit.GameMode; | ||
import org.bukkit.Material; | ||
import org.bukkit.enchantments.Enchantment; | ||
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.BlockBreakEvent; | ||
|
||
import java.util.Objects; | ||
|
||
public class BlockBreakListener implements Listener { | ||
private final NetherWater plugin; | ||
|
||
public BlockBreakListener(NetherWater plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
@EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = true) | ||
public void onBlockBreak(BlockBreakEvent event) { | ||
this.plugin.dump("Block break event has been handled."); | ||
this.plugin.dump("- World: " + Objects.requireNonNull(event.getBlock()).getWorld().getName() + " (type: " + event.getBlock().getWorld().getEnvironment() + ")"); | ||
this.plugin.dump("- Player: " + event.getPlayer()); | ||
|
||
Player player = event.getPlayer(); | ||
|
||
if (event.getBlock().getType() != Material.ICE) { | ||
return; | ||
} | ||
|
||
// Silk touch has different behaviour | ||
if (event.getPlayer().getInventory().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH)) { | ||
return; | ||
} | ||
|
||
// Ice to water change doesn't apply to creative game players | ||
if (player.getGameMode() == GameMode.CREATIVE) { | ||
return; | ||
} | ||
|
||
// Check general conditions for using this plugin (world type, player permissions, world height etc.) | ||
if (!plugin.canBeUsedThisPlugin(player, event.getBlock())) { | ||
return; | ||
} | ||
|
||
// Cancel native event actions | ||
event.setCancelled(true); | ||
|
||
// Replace ice for watter block | ||
event.getBlock().setType(Material.WATER); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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