2011-01-30 06:07:56 +00:00
|
|
|
// $Id$
|
|
|
|
/*
|
|
|
|
* WorldEdit
|
|
|
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2011-02-18 23:14:43 +00:00
|
|
|
package com.sk89q.worldedit.tools;
|
2011-01-30 06:07:56 +00:00
|
|
|
|
|
|
|
import com.sk89q.worldedit.*;
|
2011-10-04 21:13:41 +00:00
|
|
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
2011-01-30 06:07:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A mode that cycles the data values of supported blocks.
|
|
|
|
*
|
|
|
|
* @author sk89q
|
|
|
|
*/
|
2011-04-25 08:52:34 +00:00
|
|
|
public class BlockDataCyler implements DoubleActionBlockTool {
|
2011-10-04 21:13:41 +00:00
|
|
|
|
2011-05-02 00:06:40 +00:00
|
|
|
public boolean canUse(LocalPlayer player) {
|
|
|
|
return player.hasPermission("worldedit.tool.data-cycler");
|
|
|
|
}
|
2011-10-04 21:13:41 +00:00
|
|
|
|
2011-04-25 08:52:34 +00:00
|
|
|
private boolean handleCycle(ServerInterface server, LocalConfiguration config,
|
|
|
|
LocalPlayer player, LocalSession session, WorldVector clicked, boolean forward) {
|
2011-10-04 21:13:41 +00:00
|
|
|
|
2011-01-30 06:07:56 +00:00
|
|
|
LocalWorld world = clicked.getWorld();
|
2011-10-04 21:13:41 +00:00
|
|
|
|
2011-01-30 06:07:56 +00:00
|
|
|
int type = world.getBlockType(clicked);
|
|
|
|
int data = world.getBlockData(clicked);
|
2011-10-04 21:13:41 +00:00
|
|
|
|
2011-01-30 06:07:56 +00:00
|
|
|
if (config.allowedDataCycleBlocks.size() > 0
|
2011-01-30 06:10:22 +00:00
|
|
|
&& !player.hasPermission("worldedit.override.data-cycler")
|
2011-01-30 06:07:56 +00:00
|
|
|
&& !config.allowedDataCycleBlocks.contains(type)) {
|
|
|
|
player.printError("You are not permitted to cycle the data value of that block.");
|
|
|
|
return true;
|
|
|
|
}
|
2011-10-04 21:13:41 +00:00
|
|
|
|
2011-04-25 08:52:34 +00:00
|
|
|
int increment = forward ? 1 : -1;
|
2011-10-04 21:13:41 +00:00
|
|
|
data = (new BaseBlock(type, data)).cycleData(increment);
|
|
|
|
|
2011-09-17 05:34:55 +00:00
|
|
|
if (data < 0) {
|
|
|
|
player.printError("That block's data cannot be cycled!");
|
2011-10-04 21:13:41 +00:00
|
|
|
} else {
|
|
|
|
world.setBlockData(clicked, data);
|
2011-01-30 06:07:56 +00:00
|
|
|
}
|
2011-10-04 21:13:41 +00:00
|
|
|
|
2011-01-30 06:07:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-10-04 21:13:41 +00:00
|
|
|
|
2011-04-25 08:52:34 +00:00
|
|
|
public boolean actPrimary(ServerInterface server, LocalConfiguration config,
|
|
|
|
LocalPlayer player, LocalSession session, WorldVector clicked) {
|
|
|
|
return handleCycle(server, config, player, session, clicked, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean actSecondary(ServerInterface server,
|
|
|
|
LocalConfiguration config, LocalPlayer player,
|
|
|
|
LocalSession session, WorldVector clicked) {
|
|
|
|
return handleCycle(server, config, player, session, clicked, false);
|
|
|
|
}
|
2011-09-17 05:34:55 +00:00
|
|
|
|
2011-01-30 06:07:56 +00:00
|
|
|
}
|