Skip to content

Commit

Permalink
Some bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ceskyDJ committed Apr 28, 2020
1 parent b19df2b commit 43aceb3
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 20 deletions.
8 changes: 6 additions & 2 deletions src/com/leetzilantonis/netherwater/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public void reloadConfig() {
this.plugin.reloadConfig();
}

public boolean isDebugOn() {
return this.plugin.getConfig().getBoolean("debug");
}

public List<String> getDisabledWorlds() {
return this.plugin.getConfig().getStringList("disabled-worlds");
}
Expand All @@ -37,10 +41,10 @@ public String getMessage(String name) {
}

public int getMinHeight() {
return plugin.getConfig().getInt("min-height");
return this.plugin.getConfig().getInt("min-height");
}

public int getMaxHeight() {
return plugin.getConfig().getInt("max-height");
return this.plugin.getConfig().getInt("max-height");
}
}
9 changes: 8 additions & 1 deletion src/com/leetzilantonis/netherwater/NetherWater.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import org.bukkit.ChatColor;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
Expand Down Expand Up @@ -69,6 +70,12 @@ public boolean canBuild(Player p, Block b) {
}

public ConfigManager getConfigManager() {
return configManager;
return this.configManager;
}

public void dump(String message) {
if (this.configManager.isDebugOn()) {
this.getServer().getConsoleSender().sendMessage(ChatColor.YELLOW + "[NetherWater] " + message);
}
}
}
55 changes: 39 additions & 16 deletions src/com/leetzilantonis/netherwater/WaterPlaceListener.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.leetzilantonis.netherwater;

import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.World.Environment;
Expand All @@ -10,52 +11,74 @@
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;

import java.util.Objects;

public class WaterPlaceListener implements Listener {
private final NetherWater plugin;
private final ConfigManager configManager;

public WaterPlaceListener(NetherWater plugin) {
this.plugin = plugin;
this.configManager = plugin.getConfigManager();

this.configManager = this.plugin.getConfigManager();
}

@EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEvent e) {
if (e.getAction() != Action.RIGHT_CLICK_BLOCK)
public void onPlayerInteract(PlayerInteractEvent event) {
this.plugin.dump("Player interact event has been handled.");
this.plugin.dump("- Action: " + event.getAction());
this.plugin.dump("- Item: " + (event.getItem() != null ? event.getItem().getType() : "NULL"));
this.plugin.dump("- World: " + Objects.requireNonNull(event.getClickedBlock()).getWorld().getName() + " (type: " + event.getClickedBlock().getWorld().getEnvironment() + ")");
this.plugin.dump("- Player: " + event.getPlayer());

if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}

if (e.getItem() == null)
if (event.getItem() == null) {
return;
}

World w = e.getClickedBlock().getWorld();
Player p = e.getPlayer();
World world = event.getClickedBlock().getWorld();
Player player = event.getPlayer();

if (world.getEnvironment() != Environment.NETHER) {
return;
}

if (w.getEnvironment() == Environment.NETHER && e.getItem().getType() == Material.WATER_BUCKET)
if (event.getItem() == null || event.getItem().getType() != Material.WATER_BUCKET) {
return;
}

if (p.hasPermission("netherwater.use." + w.getName()) || p.hasPermission("netherwater.use.*"))
if (!(player.hasPermission("netherwater.use." + world.getName()) || player.hasPermission("netherwater.use.*"))) {
return;
}

if (!this.configManager.getDisabledWorlds().contains(w.getName()) || p.hasPermission("netherwater.world.bypass"))
if (this.configManager.getDisabledWorlds().contains(world.getName()) && !player.hasPermission("netherwater.world.bypass")) {
return;
}

if (plugin.canBuild(p, e.getClickedBlock().getRelative(e.getBlockFace())))
if (!plugin.canBuild(player, event.getClickedBlock().getRelative(event.getBlockFace())))
return;

int y = e.getClickedBlock().getRelative(e.getBlockFace()).getY();
if (y <= this.configManager.getMaxHeight())
int y = event.getClickedBlock().getRelative(event.getBlockFace()).getY();
if (y > this.configManager.getMaxHeight()) {
return;
}

if (y >= this.configManager.getMinHeight())
if (y < this.configManager.getMinHeight()) {
return;
}

// Cancel native event actions
e.setCancelled(true);
event.setCancelled(true);

// Add watter block
e.getClickedBlock().getRelative(e.getBlockFace()).setType(Material.WATER);
event.getClickedBlock().getRelative(event.getBlockFace()).setType(Material.WATER);

// Replace water bucket with empty one
e.getItem().setType(Material.BUCKET);
if (player.getGameMode() != GameMode.CREATIVE) {
event.getItem().setType(Material.BUCKET);
}
}
}
2 changes: 2 additions & 0 deletions src/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Allow using debug dumps. It's not recommended on production servers.
debug: false
disabled-worlds:
- nether_without_water
max-height: 999
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: NetherWater
version: 1.0.5
version: 1.0.6
description: Allow players to use water in the nether
authors: [Lee Tzilantonis, ceskyDJ]

Expand Down

0 comments on commit 43aceb3

Please sign in to comment.