use of me.botsko.prism.api.BlockStateChange in project Prism-Bukkit by prism.
the class DrainCommand method handle.
@Override
public void handle(CallInfo call) {
String drainType = "";
int radius = plugin.getConfig().getInt("prism.drain.default-radius");
if (call.getArgs().length == 3) {
if (call.getArg(1).equalsIgnoreCase("water") || call.getArg(1).equalsIgnoreCase("lava")) {
drainType = call.getArg(1);
} else {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Invalid drain type. Must be lava, water, or left out."));
return;
}
// Validate radius
radius = validateRadius(call, call.getArg(2));
} else if (call.getArgs().length == 2) {
if (TypeUtils.isNumeric(call.getArg(1))) {
radius = validateRadius(call, call.getArg(1));
} else {
if (call.getArg(1).equalsIgnoreCase("water") || call.getArg(1).equalsIgnoreCase("lava")) {
drainType = call.getArg(1);
} else {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Invalid drain type. Must be lava, water, or left out."));
return;
}
}
}
if (radius == 0) {
return;
}
TextComponent.Builder builder = Component.text().append(Il8nHelper.formatMessage("command-drain-lookup", drainType, radius));
String key = "command-drain-lookup-water";
if (drainType.equals("lava")) {
key = "command-drain-lookup-lava";
}
builder.append(Component.text(" ")).append(Il8nHelper.getMessage(key).color(NamedTextColor.GRAY));
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerHeaderMsg(builder.build()));
ArrayList<BlockStateChange> blockStateChanges = null;
if (drainType.isEmpty()) {
blockStateChanges = Utilities.drain(call.getPlayer().getLocation(), radius);
} else if (drainType.equals("water")) {
blockStateChanges = Utilities.drainWater(call.getPlayer().getLocation(), radius);
} else if (drainType.equals("lava")) {
blockStateChanges = Utilities.drainLava(call.getPlayer().getLocation(), radius);
}
if (blockStateChanges != null && !blockStateChanges.isEmpty()) {
// @todo remove the extra space in msg
Component out = Prism.messenger.playerHeaderMsg(Il8nHelper.formatMessage("command-drain-lookup-result", blockStateChanges.size(), drainType)).append(Component.newline()).append(Prism.messenger.playerSubduedHeaderMsg(Il8nHelper.getMessage("command-drain-result-undo")));
Prism.messenger.sendMessage(call.getSender(), out);
// Trigger the event
final PrismDrainEvent event = EventHelper.createDrainEvent(blockStateChanges, call.getPlayer(), radius);
plugin.getServer().getPluginManager().callEvent(event);
} else {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError(Il8nHelper.getMessage("command-drain-result-empty")));
}
}
use of me.botsko.prism.api.BlockStateChange in project Prism-Bukkit by prism.
the class PrismMiscEvents method onPrismBlocksDrainEvent.
/**
* PrismDrainEvent.
*
* @param event PrismDrainEvent
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPrismBlocksDrainEvent(final PrismDrainEvent event) {
// Get all block changes for this event
final ArrayList<BlockStateChange> blockStateChanges = event.getBlockStateChanges();
if (!blockStateChanges.isEmpty()) {
// Create an entry for the rollback as a whole
final Handler primaryAction = ActionFactory.createPrismProcess("prism-process", PrismProcessType.DRAIN, event.onBehalfOf(), "" + event.getRadius());
final long id = RecordingTask.insertActionIntoDatabase(primaryAction);
if (id == 0) {
return;
}
for (final BlockStateChange stateChange : blockStateChanges) {
final BlockState orig = stateChange.getOriginalBlock();
final BlockState newBlock = stateChange.getNewBlock();
// Build the action
RecordingQueue.addToQueue(ActionFactory.createPrismRollback("prism-drain", orig, newBlock, event.onBehalfOf(), id));
}
// ActionQueue.save();
}
}
use of me.botsko.prism.api.BlockStateChange in project Prism-Bukkit by prism.
the class ExtinguishCommand method handle.
/**
* Handle the command.
*/
@Override
public void handle(CallInfo call) {
int radius = plugin.getConfig().getInt("prism.ex.default-radius");
if (call.getArgs().length == 2) {
if (TypeUtils.isNumeric(call.getArg(1))) {
final int _tmp_radius = Integer.parseInt(call.getArg(1));
if (_tmp_radius > 0) {
if (_tmp_radius > plugin.getConfig().getInt("prism.ex.max-radius")) {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError(Il8nHelper.getMessage("radius-max")));
return;
} else {
radius = _tmp_radius;
}
} else {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError(Il8nHelper.getMessage("radius-small")));
return;
}
} else {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError(Il8nHelper.getMessage("radius-not-numeric")));
return;
}
}
final ArrayList<BlockStateChange> blockStateChanges = Utilities.extinguish(call.getPlayer().getLocation(), radius);
if (!blockStateChanges.isEmpty()) {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerHeaderMsg(Il8nHelper.getMessage("fire-extinguished-sucess")));
// Trigger the event
final PrismExtinguishEvent event = EventHelper.createExtinguishEvent(blockStateChanges, call.getPlayer(), radius);
plugin.getServer().getPluginManager().callEvent(event);
} else {
Prism.getAudiences().player(call.getPlayer()).sendMessage(Identity.nil(), Prism.messenger.playerError(Il8nHelper.getMessage("no-fires-found")));
}
}
use of me.botsko.prism.api.BlockStateChange in project Prism-Bukkit by prism.
the class Preview method cancel_preview.
@Override
public void cancel_preview() {
if (player == null) {
return;
}
if (!blockStateChanges.isEmpty()) {
// pull all players that are part of this preview
final List<CommandSender> previewPlayers = parameters.getSharedPlayers();
previewPlayers.add(player);
for (final BlockStateChange u : blockStateChanges) {
Location loc = u.getOriginalBlock().getLocation();
BlockData data = u.getOriginalBlock().getBlockData();
for (final CommandSender sharedPlayer : previewPlayers) {
if (sharedPlayer instanceof Player) {
EntityUtils.sendBlockChange((Player) sharedPlayer, loc, data);
}
}
}
}
Prism.messenger.sendMessage(sender, Prism.messenger.playerHeaderMsg(Il8nHelper.getMessage("preview-cancel")));
}
use of me.botsko.prism.api.BlockStateChange in project Prism-Bukkit by prism.
the class Utilities method removeMaterialsFromRadius.
/**
* Remove materials in an radius.
*
* @param materials Material array
* @param loc Location
* @param radius integer
*/
@SuppressWarnings("WeakerAccess")
public static ArrayList<BlockStateChange> removeMaterialsFromRadius(Material[] materials, final Location loc, int radius) {
final ArrayList<BlockStateChange> blockStateChanges = new ArrayList<>();
if (loc != null && radius > 0 && materials != null && materials.length > 0) {
final int x1 = loc.getBlockX();
final int y1 = loc.getBlockY();
final int z1 = loc.getBlockZ();
final World world = loc.getWorld();
for (int x = x1 - radius; x <= x1 + radius; x++) {
for (int y = y1 - radius; y <= y1 + radius; y++) {
for (int z = z1 - radius; z <= z1 + radius; z++) {
Location testLocation = new Location(world, x, y, z);
final Block b = testLocation.getBlock();
if (b.getType().equals(Material.AIR)) {
continue;
}
if (Arrays.asList(materials).contains(testLocation.getBlock().getType())) {
final BlockState originalBlock = testLocation.getBlock().getState();
testLocation.getBlock().setType(Material.AIR);
final BlockState newBlock = testLocation.getBlock().getState();
blockStateChanges.add(new BlockStateChangeImpl(originalBlock, newBlock));
}
}
}
}
}
return blockStateChanges;
}
Aggregations