Skip to content

Commit

Permalink
A couple fixes, plus range replace mode
Browse files Browse the repository at this point in the history
  • Loading branch information
gdude2002 committed Jul 16, 2014
1 parent 0723d27 commit e5eed6f
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 29 deletions.
14 changes: 8 additions & 6 deletions src/main/java/com/archivesmc/painter/Painter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.archivesmc.painter.listeners.BlockBreakListener;
import com.archivesmc.painter.listeners.CommandRunner;
import com.archivesmc.painter.listeners.PlayerInteractListener;
import com.archivesmc.painter.loggers.*;

import net.milkbowl.vault.permission.Permission;
Expand Down Expand Up @@ -29,9 +30,7 @@ public class Painter extends JavaPlugin {
boolean useTool = false;

public Set<UUID> painters;

private BlockBreakListener breakListener;
private CommandRunner commands;
public Set<UUID> range_painters;

public Permission permissions;

Expand All @@ -43,6 +42,7 @@ public void onEnable() {

// Assign painters set here in case we're reloading, instead of in the class definition
this.painters = new HashSet<>();
this.range_painters = new HashSet<>();

// First, let's start with the paint tool material
this.toolString = this.getConfig().getString("paint_tool", null);
Expand Down Expand Up @@ -121,11 +121,13 @@ public void onEnable() {
}

// Now that that's done, let's register events and commands
this.breakListener = new BlockBreakListener(this);
this.commands = new CommandRunner(this);
BlockBreakListener breakListener = new BlockBreakListener(this);
PlayerInteractListener interactListener = new PlayerInteractListener(this);
CommandRunner commands = new CommandRunner(this);

this.getServer().getPluginManager().registerEvents(breakListener, this);
getCommand("painter").setExecutor(this.commands);
this.getServer().getPluginManager().registerEvents(interactListener, this);
getCommand("painter").setExecutor(commands);
}

private void setupLogBlock() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public void onBlockBreakEvent(BlockBreakEvent event) {
if (this.plugin.painters.contains(player.getUniqueId())) {
if (! this.plugin.permissions.has(player, "painter.replace")) {
this.plugin.painters.remove(player.getUniqueId());

Map<String, String> args = new HashMap<>();
args.put("permission", "painter.replace");
args.put("name", player.getName());
Expand All @@ -39,14 +40,16 @@ public void onBlockBreakEvent(BlockBreakEvent event) {
return;
}

Block block = event.getBlock();
BlockState oldBlockState = block.getState();
ItemStack items = player.getItemInHand();
Material heldMat = items.getType();

if (heldMat.isBlock()) {
Block block = event.getBlock();
BlockState oldBlockState = block.getState();

block.setType(heldMat);
block.setData(items.getData().getData());

event.setCancelled(true);

// Log it if it's being logged
Expand Down
29 changes: 25 additions & 4 deletions src/main/java/com/archivesmc/painter/listeners/CommandRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
this.plugin.sendMessage(commandSender, "command_player_only", args);
} else {
UUID id = ((Player) commandSender).getUniqueId();
if (strings.length < 1) {
if (strings.length < 1 || "toggle".equalsIgnoreCase(strings[0])) {
if (this.plugin.permissions.has(commandSender, "painter.replace")) {
if (this.plugin.painters.contains(id)) {
this.plugin.painters.remove(id);
Expand All @@ -50,9 +50,30 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,

this.plugin.sendMessage(commandSender, "command_replace_no_permission", args);
}
} else {
// TODO: Paint tool
commandSender.sendMessage("Paint tool isn't implemented yet!");
} else if ("range".equalsIgnoreCase(strings[0])) {
if (this.plugin.permissions.has(commandSender, "painter.replace.range")) {
if (this.plugin.range_painters.contains(id)) {
this.plugin.range_painters.remove(id);

Map<String, String> args = new HashMap<>();
args.put("name", commandSender.getName());

this.plugin.sendMessage(commandSender, "range_replace_mode_disable", args);
} else {
this.plugin.range_painters.add(id);

Map<String, String> args = new HashMap<>();
args.put("name", commandSender.getName());

this.plugin.sendMessage(commandSender, "range_replace_mode_enable", args);
}
} else {
Map<String, String> args = new HashMap<>();
args.put("permission", "painter.replace.range");
args.put("name", commandSender.getName());

this.plugin.sendMessage(commandSender, "command_range_replace_no_permission", args);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.archivesmc.painter.listeners;

import com.archivesmc.painter.Painter;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
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.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;

import java.util.HashMap;
import java.util.Map;

public class PlayerInteractListener implements Listener {
Painter plugin;

public PlayerInteractListener(Painter plugin) {
this.plugin = plugin;
}

@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerInteractEvent(PlayerInteractEvent event) {
if(! event.isCancelled()) {
Player player = event.getPlayer();

if (this.plugin.range_painters.contains(player.getUniqueId())
&& event.getAction() == Action.LEFT_CLICK_AIR) {
if (! this.plugin.permissions.has(player, "painter.replace.range")) {
this.plugin.range_painters.remove(player.getUniqueId());

Map<String, String> args = new HashMap<>();
args.put("permission", "painter.replace.range");
args.put("name", player.getName());

this.plugin.sendMessage(player, "range_replace_perm_lost", args);
return;
}

ItemStack items = player.getItemInHand();
Material heldMat = items.getType();

if (heldMat.isBlock()) {
Block block = player.getTargetBlock(null, 100);
BlockState oldBlockState = block.getState();

block.setType(heldMat);
block.setData(items.getData().getData());

event.setCancelled(true);

// Log it if it's being logged
this.plugin.blockPainted(player, oldBlockState, block.getState(), block);
}
}
}
}
}
18 changes: 10 additions & 8 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
# Paint tool - the item to use
# See here for names: http://jd.bukkit.org/dev/apidocs/org/bukkit/Material.html
# Comment out this entry to disable the wool/clay paint tool
paint_tool: WOOD_SWORD

# This can be coreprotect, logblock, hawkeye or prism
# See the plugin documentation for more information on how this works
# Comment out this entry to disable block logging
logger: logblock
logger: prism

# The rest of this file contains various message strings for you to customize.
# You can't leave any of these out! Make sure they're all here!
Expand All @@ -19,12 +14,19 @@ messages:
# Tokens: {NAME}
replace_mode_disable: "&dCMP &5\u00BB&6 Replace mode disabled, you are no longer replacing blocks"

# Tokens: {PERMISSION}, {NAME}
range_replace_perm_lost: "&dCMP &5\u00BB&6 Range replace disabled, your access to it has been &crevoked"
# Tokens: {NAME}
range_replace_mode_enable: "&dCMP &5\u00BB&6 Range replace enabled, you are now replacing blocks at a distance"
# Tokens: {NAME}
range_replace_mode_disable: "&dCMP &5\u00BB&6 Range replace disabled, you are no longer replacing blocks at a distance"

# Tokens: {NAME}
command_player_only: "&dCMP &5\u00BB&6 This command can only be run by a player"
# Tokens: {PERMISSION}, {NAME}
command_replace_no_permission: "&dCMP &5\u00BB&6 You do not have permission to toggle replace mode"
# Tokens: {PERMISSION}, {NAME}
command_paint_tool_no_permission: "&dCMP &5\u00BB&6 You do not have permission to use the paint tool"
command_range_replace_no_permission: "&dCMP &5\u00BB&6 You do not have permission to toggle range replace mode"

# Don't change this! You'll break stuff!
version: 0.0.1pre4
version: 0.0.1pre5
17 changes: 8 additions & 9 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
name: Painter
version: 0.0.1pre4
version: 0.0.1pre5
description: Allows the painting of wool and clay, and the replacing of blocks

author: Gareth Coles

main: com.archivesmc.painter.Painter
database: false
depend: [Vault]
softdepend: [LogBlock, CoreProtect, Prism, Hawkeye]
softdepend: [LogBlock, CoreProtect, Prism, HawkEye]

commands:
painter:
aliases: [paint, ptr, pt, p]
description: "Enter or leave block replacement mode, or change the colours on your wool/clay paint tool"
usage: "/<command> [left-click colour] [right-click colour]\n/<command> \u00BB Toggle block replacement mode\n/<command> red white \u00BB Set colours on the paint tool\n/<command> - black \u00BB Set only the right-click colour on the paint tool"
description: "Toggle replacement ("toggle" or no arguments) and range replacement modes"
usage: "/<command> [toggle|range]"

permissions:
painter.*:
children:
painter.tool: true
painter.replace: true
painter.command: true
painter.replace.range: true
description: All the Painter permissions
painter.tool:
description: Use the wool/clay paint tool
painter.replace:
description: Replace blocks by breaking them
description: Replace blocks by breaking them
painter.replace.range:
description: Replace blocks at range by left-clicking

0 comments on commit e5eed6f

Please sign in to comment.