-
-
Notifications
You must be signed in to change notification settings - Fork 204
/
SelectionCommands.java
865 lines (780 loc) · 35.8 KB
/
SelectionCommands.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* 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 <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.command;
import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder;
import com.fastasyncworldedit.core.function.mask.IdMask;
import com.fastasyncworldedit.core.regions.selector.FuzzyRegionSelector;
import com.fastasyncworldedit.core.regions.selector.PolyhedralRegionSelector;
import com.fastasyncworldedit.core.util.MaskTraverser;
import com.google.common.base.Strings;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.command.argument.SelectorChoice;
import com.sk89q.worldedit.command.tool.NavigationWand;
import com.sk89q.worldedit.command.tool.SelectionWand;
import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.Logging;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Locatable;
import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.block.BlockDistributionCounter;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.function.visitor.RegionVisitor;
import com.sk89q.worldedit.internal.annotation.Direction;
import com.sk89q.worldedit.internal.annotation.MultiDirection;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionOperationException;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.ConvexPolyhedralRegionSelector;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.regions.selector.CylinderRegionSelector;
import com.sk89q.worldedit.regions.selector.EllipsoidRegionSelector;
import com.sk89q.worldedit.regions.selector.ExtendingCuboidRegionSelector;
import com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector;
import com.sk89q.worldedit.regions.selector.RegionSelectorType;
import com.sk89q.worldedit.regions.selector.SphereRegionSelector;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.util.Countable;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.formatting.component.CommandListBox;
import com.sk89q.worldedit.util.formatting.component.InvalidComponentException;
import com.sk89q.worldedit.util.formatting.component.PaginationBox;
import com.sk89q.worldedit.util.formatting.component.SubtleFormat;
import com.sk89q.worldedit.util.formatting.component.TextComponentProducer;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
import com.sk89q.worldedit.util.formatting.text.event.HoverEvent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.storage.ChunkStore;
import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer;
import org.enginehub.piston.annotation.param.Arg;
import org.enginehub.piston.annotation.param.ArgFlag;
import org.enginehub.piston.annotation.param.Switch;
import org.enginehub.piston.exception.StopExecutionException;
import java.io.File;
import java.net.URI;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import static com.sk89q.worldedit.command.util.Logging.LogMode.POSITION;
import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION;
import static com.sk89q.worldedit.world.storage.ChunkStore.CHUNK_SHIFTS;
import static com.sk89q.worldedit.world.storage.ChunkStore.CHUNK_SHIFTS_Y;
/**
* Selection commands.
*/
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
public class SelectionCommands {
private final WorldEdit we;
public SelectionCommands(WorldEdit we) {
this.we = we;
}
@Command(
name = "/pos1",
aliases = "/1",
desc = "Set position 1"
)
@Logging(POSITION)
@CommandPermissions("worldedit.selection.pos")
public void pos1(
Actor actor, World world, LocalSession session,
@Arg(desc = "Coordinates to set position 1 to", def = "")
BlockVector3 coordinates
) throws WorldEditException {
Location pos;
//FAWE start - clamp
if (coordinates != null) {
pos = new Location(world, coordinates.toVector3().clampY(world.getMinY(), world.getMaxY()));
} else if (actor instanceof Locatable) {
pos = ((Locatable) actor).getBlockLocation().clampY(world.getMinY(), world.getMaxY());
//FAWE end
} else {
actor.print(Caption.of("worldedit.pos.console-require-coords"));
return;
}
if (!session.getRegionSelector(world).selectPrimary(pos.toVector().toBlockPoint(), ActorSelectorLimits.forActor(actor))) {
actor.print(Caption.of("worldedit.pos.already-set"));
return;
}
session.getRegionSelector(world)
.explainPrimarySelection(actor, session, pos.toVector().toBlockPoint());
}
@Command(
name = "/pos2",
aliases = "/2",
desc = "Set position 2"
)
@Logging(POSITION)
@CommandPermissions("worldedit.selection.pos")
public void pos2(
Actor actor, World world, LocalSession session,
@Arg(desc = "Coordinates to set position 2 to", def = "")
BlockVector3 coordinates
) throws WorldEditException {
Location pos;
if (coordinates != null) {
//FAWE start - clamp
pos = new Location(world, coordinates.toVector3().clampY(world.getMinY(), world.getMaxY()));
} else if (actor instanceof Locatable) {
pos = ((Locatable) actor).getBlockLocation().clampY(world.getMinY(), world.getMaxY());
//Fawe end
} else {
actor.print(Caption.of("worldedit.pos.console-require-coords"));
return;
}
if (!session.getRegionSelector(world).selectSecondary(
pos.toVector().toBlockPoint(),
ActorSelectorLimits.forActor(actor)
)) {
actor.print(Caption.of("worldedit.pos.already-set"));
return;
}
session.getRegionSelector(world)
.explainSecondarySelection(actor, session, pos.toVector().toBlockPoint());
}
@Command(
name = "/hpos1",
desc = "Set position 1 to targeted block"
)
@CommandPermissions("worldedit.selection.hpos")
public void hpos1(Player player, LocalSession session) throws WorldEditException {
Location pos = player.getBlockTrace(300);
if (pos != null) {
if (!session.getRegionSelector(player.getWorld()).selectPrimary(
pos.toVector().toBlockPoint(),
ActorSelectorLimits.forActor(player)
)) {
player.print(Caption.of("worldedit.hpos.already-set"));
return;
}
session.getRegionSelector(player.getWorld())
.explainPrimarySelection(player, session, pos.toBlockPoint());
} else {
player.print(Caption.of("worldedit.hpos.no-block"));
}
}
@Command(
name = "/hpos2",
desc = "Set position 2 to targeted block"
)
@CommandPermissions("worldedit.selection.hpos")
public void hpos2(Player player, LocalSession session) throws WorldEditException {
Location pos = player.getBlockTrace(300);
if (pos != null) {
if (!session.getRegionSelector(player.getWorld()).selectSecondary(
pos.toVector().toBlockPoint(),
ActorSelectorLimits.forActor(player)
)) {
player.print(Caption.of("worldedit.hpos.already-set"));
return;
}
session.getRegionSelector(player.getWorld())
.explainSecondarySelection(player, session, pos.toBlockPoint());
} else {
player.print(Caption.of("worldedit.hpos.no-block"));
}
}
@Command(
name = "/chunk",
desc = "Set the selection to your current chunk.",
descFooter = "This command selects 256-block-tall areas,\nwhich can be specified by the y-coordinate.\nE.g. -c x,1,z will select from y=256 to y=511."
)
@Logging(POSITION)
@CommandPermissions("worldedit.selection.chunk")
public void chunk(
Actor actor, World world, LocalSession session,
@Arg(desc = "The chunk to select", def = "")
BlockVector3 coordinates,
@Switch(name = 's', desc = "Expand your selection to encompass all chunks that are part of it")
boolean expandSelection,
@Switch(name = 'c', desc = "Use chunk coordinates instead of block coordinates")
boolean useChunkCoordinates
) throws WorldEditException {
final BlockVector3 min;
final BlockVector3 max;
if (expandSelection) {
Region region = session.getSelection(world);
int minChunkY = world.getMinY() >> CHUNK_SHIFTS_Y;
int maxChunkY = world.getMaxY() >> CHUNK_SHIFTS_Y;
BlockVector3 minChunk = ChunkStore.toChunk3d(region.getMinimumPoint())
.clampY(minChunkY, maxChunkY);
BlockVector3 maxChunk = ChunkStore.toChunk3d(region.getMaximumPoint())
.clampY(minChunkY, maxChunkY);
min = minChunk.shl(CHUNK_SHIFTS, CHUNK_SHIFTS_Y, CHUNK_SHIFTS);
max = maxChunk.shl(CHUNK_SHIFTS, CHUNK_SHIFTS_Y, CHUNK_SHIFTS).add(15, 255, 15);
actor.print(Caption.of(
"worldedit.chunk.selected-multiple",
TextComponent.of(minChunk.getBlockX()),
TextComponent.of(minChunk.getBlockY()),
TextComponent.of(minChunk.getBlockZ()),
TextComponent.of(maxChunk.getBlockX()),
TextComponent.of(maxChunk.getBlockY()),
TextComponent.of(maxChunk.getBlockZ())
));
} else {
BlockVector3 minChunk;
if (coordinates != null) {
// coords specified
minChunk = useChunkCoordinates
? coordinates
: ChunkStore.toChunk3d(coordinates);
} else {
// use player loc
if (actor instanceof Locatable) {
minChunk = ChunkStore.toChunk3d(((Locatable) actor).getBlockLocation().toVector().toBlockPoint());
} else {
throw new StopExecutionException(TextComponent.of("A player or coordinates are required."));
}
}
min = minChunk.shl(CHUNK_SHIFTS, CHUNK_SHIFTS_Y, CHUNK_SHIFTS);
max = min.add(15, 255, 15);
actor.print(Caption.of(
"worldedit.chunk.selected",
TextComponent.of(minChunk.getBlockX()),
TextComponent.of(minChunk.getBlockY()),
TextComponent.of(minChunk.getBlockZ())
));
}
final CuboidRegionSelector selector;
if (session.getRegionSelector(world) instanceof ExtendingCuboidRegionSelector) {
selector = new ExtendingCuboidRegionSelector(world);
} else {
selector = new CuboidRegionSelector(world);
}
selector.selectPrimary(min, ActorSelectorLimits.forActor(actor));
selector.selectSecondary(max, ActorSelectorLimits.forActor(actor));
session.setRegionSelector(world, selector);
session.dispatchCUISelection(actor);
}
@Command(
name = "/wand",
desc = "Get the wand object"
)
@CommandPermissions(
value = "worldedit.wand",
queued = false
)
public void wand(
Player player, LocalSession session,
@Switch(name = 'n', desc = "Get a navigation wand") boolean navWand
) throws WorldEditException {
//FAWE start
session.loadDefaults(player, true);
//FAWE end
String wandId = navWand ? session.getNavWandItem() : session.getWandItem();
if (wandId == null) {
wandId = navWand ? we.getConfiguration().navigationWand : we.getConfiguration().wandItem;
}
ItemType itemType = ItemTypes.parse(wandId);
if (itemType == null) {
player.print(Caption.of("worldedit.wand.invalid"));
return;
}
player.giveItem(new BaseItemStack(itemType, 1));
//FAWE start - instance-iate session
if (navWand) {
session.setTool(itemType, NavigationWand.INSTANCE);
player.print(Caption.of("worldedit.wand.navwand.info"));
} else {
session.setTool(itemType, SelectionWand.INSTANCE);
player.print(Caption.of("worldedit.wand.selwand.info"));
//FAWE end
}
}
@Command(
name = "toggleeditwand",
aliases = {"/toggleeditwand"},
desc = "Remind the user that the wand is now a tool and can be unbound with /tool none."
)
@CommandPermissions(
value = "worldedit.wand.toggle",
queued = false
)
public void toggleWand(Player player) {
player.print(
Caption.of(
"worldedit.wand.selwand.now.tool",
TextComponent.of("/tool none").clickEvent(
ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "/tool none")),
TextComponent.of("/tool selwand").clickEvent(
ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "/tool selwand")),
TextComponent.of("//wand").clickEvent(
ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "//wand"))
)
);
}
@Command(
name = "/contract",
desc = "Contract the selection area"
)
@Logging(REGION)
@CommandPermissions("worldedit.selection.contract")
public void contract(
Actor actor, World world, LocalSession session,
@Arg(desc = "Amount to contract the selection by")
int amount,
@Arg(desc = "Amount to contract the selection by in the other direction", def = "0")
int reverseAmount,
@Arg(desc = "Direction to contract", def = Direction.AIM)
@MultiDirection
List<BlockVector3> direction
) throws WorldEditException {
try {
Region region = session.getSelection(world);
long oldSize = region.getVolume();
if (reverseAmount == 0) {
for (BlockVector3 dir : direction) {
region.contract(dir.multiply(amount));
}
} else {
for (BlockVector3 dir : direction) {
region.contract(dir.multiply(amount), dir.multiply(-reverseAmount));
}
}
session.getRegionSelector(world).learnChanges();
long newSize = region.getVolume();
session.getRegionSelector(world).explainRegionAdjust(actor, session);
actor.print(Caption.of("worldedit.contract.contracted", TextComponent.of(oldSize - newSize)));
} catch (RegionOperationException e) {
actor.printError(TextComponent.of(e.getMessage()));
}
}
@Command(
name = "/shift",
desc = "Shift the selection area"
)
@Logging(REGION)
@CommandPermissions("worldedit.selection.shift")
public void shift(
Actor actor, World world, LocalSession session,
@Arg(desc = "Amount to shift the selection by")
int amount,
@Arg(desc = "Direction to contract", def = Direction.AIM)
@MultiDirection
List<BlockVector3> direction
) throws WorldEditException {
try {
Region region = session.getSelection(world);
for (BlockVector3 dir : direction) {
region.shift(dir.multiply(amount));
}
session.getRegionSelector(world).learnChanges();
session.getRegionSelector(world).explainRegionAdjust(actor, session);
actor.print(Caption.of("worldedit.shift.shifted"));
} catch (RegionOperationException e) {
actor.printError(TextComponent.of(e.getMessage()));
}
}
@Command(
name = "/outset",
desc = "Outset the selection area"
)
@Logging(REGION)
@CommandPermissions("worldedit.selection.outset")
public void outset(
Actor actor, World world, LocalSession session,
@Arg(desc = "Amount to expand the selection by in all directions")
int amount,
@Switch(name = 'h', desc = "Only expand horizontally")
boolean onlyHorizontal,
@Switch(name = 'v', desc = "Only expand vertically")
boolean onlyVertical
) throws WorldEditException {
Region region = session.getSelection(world);
region.expand(getChangesForEachDir(amount, onlyHorizontal, onlyVertical));
session.getRegionSelector(world).learnChanges();
session.getRegionSelector(world).explainRegionAdjust(actor, session);
actor.print(Caption.of("worldedit.outset.outset"));
}
@Command(
name = "/inset",
desc = "Inset the selection area"
)
@Logging(REGION)
@CommandPermissions("worldedit.selection.inset")
public void inset(
Actor actor, World world, LocalSession session,
@Arg(desc = "Amount to contract the selection by in all directions")
int amount,
@Switch(name = 'h', desc = "Only contract horizontally")
boolean onlyHorizontal,
@Switch(name = 'v', desc = "Only contract vertically")
boolean onlyVertical
) throws WorldEditException {
Region region = session.getSelection(world);
region.contract(getChangesForEachDir(amount, onlyHorizontal, onlyVertical));
session.getRegionSelector(world).learnChanges();
session.getRegionSelector(world).explainRegionAdjust(actor, session);
actor.print(Caption.of("worldedit.inset.inset"));
}
private BlockVector3[] getChangesForEachDir(int amount, boolean onlyHorizontal, boolean onlyVertical) {
Stream.Builder<BlockVector3> changes = Stream.builder();
if (!onlyHorizontal) {
changes.add(BlockVector3.UNIT_Y);
changes.add(BlockVector3.UNIT_MINUS_Y);
}
if (!onlyVertical) {
changes.add(BlockVector3.UNIT_X);
changes.add(BlockVector3.UNIT_MINUS_X);
changes.add(BlockVector3.UNIT_Z);
changes.add(BlockVector3.UNIT_MINUS_Z);
}
return changes.build().map(v -> v.multiply(amount)).toArray(BlockVector3[]::new);
}
@Command(
name = "/size",
desc = "Get information about the selection"
)
@CommandPermissions(
value = "worldedit.selection.size",
queued = false
)
public void size(
Actor actor, World world, LocalSession session,
@Switch(name = 'c', desc = "Get clipboard info instead")
boolean clipboardInfo
) throws WorldEditException {
Region region;
if (clipboardInfo) {
//FAWE start - Modify for cross server clipboards
ClipboardHolder root = session.getClipboard();
int index = 0;
for (ClipboardHolder holder : root.getHolders()) {
Clipboard clipboard = holder.getClipboard();
String name;
if (holder instanceof URIClipboardHolder) {
URI uri = ((URIClipboardHolder) holder).getUri();
if (uri.toString().startsWith("file:/")) {
name = new File(uri.getPath()).getName();
} else {
name = uri.getFragment();
}
} else {
name = Integer.toString(index);
}
region = clipboard.getRegion();
BlockVector3 size = region.getMaximumPoint()
.subtract(region.getMinimumPoint()).add(1, 1, 1);
BlockVector3 origin = clipboard.getOrigin();
String sizeStr = size.getBlockX() + "*" + size.getBlockY() + "*" + size.getBlockZ();
String originStr = origin.getBlockX() + "," + origin.getBlockY() + "," + origin.getBlockZ();
long numBlocks = ((long) size.getBlockX() * size.getBlockY() * size.getBlockZ());
actor.print(Caption.of(
"worldedit.size.offset",
TextComponent.of(name),
TextComponent.of(sizeStr),
TextComponent.of(originStr),
TextComponent.of(numBlocks)
));
index++;
}
return;
//FAWE end
} else {
region = session.getSelection(world);
actor.print(Caption.of("worldedit.size.type", TextComponent.of(session.getRegionSelector(world).getTypeName())));
for (Component line : session.getRegionSelector(world).getSelectionInfoLines()) {
actor.printInfo(line);
}
}
BlockVector3 size = region.getMaximumPoint()
.subtract(region.getMinimumPoint())
.add(1, 1, 1);
actor.print(Caption.of("worldedit.size.size", TextComponent.of(size.toString())));
actor.print(Caption.of(
"worldedit.size.distance",
TextComponent.of(region.getMaximumPoint().distance(region.getMinimumPoint()))
));
actor.print(Caption.of("worldedit.size.blocks", TextComponent.of(region.getVolume())));
}
@Command(
name = "/count",
desc = "Counts the number of blocks matching a mask"
)
@CommandPermissions("worldedit.analysis.count")
public int count(
Actor actor, World world, LocalSession session, EditSession editSession,
@Arg(desc = "The mask of blocks to match")
Mask mask
) throws WorldEditException {
//FAWE start > the mask will have been initialised with a WorldWrapper extent (very bad/slow)
new MaskTraverser(mask).setNewExtent(editSession);
//FAWE end
int count = editSession.countBlocks(session.getSelection(world), mask);
actor.print(Caption.of("worldedit.count.counted", TextComponent.of(count)));
return count;
}
@Command(
name = "/distr",
desc = "Get the distribution of blocks in the selection"
)
@CommandPermissions("worldedit.analysis.distr")
public void distr(
Actor actor, World world, LocalSession session,
//FAWE start > add extent to RegionVisitor to allow chunk preloading
EditSession editSession,
//FAWE end
@Switch(name = 'c', desc = "Get the distribution of the clipboard instead")
boolean clipboardDistr,
@Switch(name = 'd', desc = "Separate blocks by state")
boolean separateStates,
@ArgFlag(name = 'p', desc = "Gets page from a previous distribution.")
Integer page
) throws WorldEditException {
List<Countable<BlockState>> distribution;
if (page == null) {
if (clipboardDistr) {
Clipboard clipboard = session.getClipboard().getClipboard(); // throws if missing
BlockDistributionCounter count = new BlockDistributionCounter(clipboard, separateStates);
//FAWE start > add extent to RegionVisitor to allow chunk preloading
RegionVisitor visitor = new RegionVisitor(clipboard.getRegion(), count, editSession);
//FAWE end
Operations.completeBlindly(visitor);
distribution = count.getDistribution();
} else {
distribution = editSession.getBlockDistribution(session.getSelection(world), separateStates);
}
session.setLastDistribution(distribution);
page = 1;
} else {
distribution = session.getLastDistribution();
if (distribution == null) {
actor.print(Caption.of("worldedit.distr.no-previous"));
return;
}
}
if (distribution.isEmpty()) { // *Should* always be false
actor.print(Caption.of("worldedit.distr.no-blocks"));
return;
}
BlockDistributionResult res = new BlockDistributionResult(distribution, separateStates);
if (!actor.isPlayer()) {
res.formatForConsole();
}
actor.print(res.create(page));
}
@Command(
name = "/sel",
aliases = {";", "/desel", "/deselect"},
desc = "Choose a region selector"
)
//FAWE start
@CommandPermissions("worldedit.analysis.sel")
//FAWE end
public void select(
Actor actor, World world, LocalSession session,
@Arg(desc = "Selector to switch to", def = "")
SelectorChoice selector,
@Switch(name = 'd', desc = "Set default selector")
boolean setDefaultSelector
) throws WorldEditException {
if (selector == null) {
session.getRegionSelector(world).clear();
session.dispatchCUISelection(actor);
actor.print(Caption.of("worldedit.select.cleared"));
return;
}
final RegionSelector oldSelector = session.getRegionSelector(world);
final RegionSelector newSelector;
switch (selector) {
case CUBOID:
newSelector = new CuboidRegionSelector(oldSelector);
actor.print(Caption.of("worldedit.select.cuboid.message"));
break;
case EXTEND:
newSelector = new ExtendingCuboidRegionSelector(oldSelector);
actor.print(Caption.of("worldedit.select.extend.message"));
break;
case POLY: {
newSelector = new Polygonal2DRegionSelector(oldSelector);
actor.print(Caption.of("worldedit.select.poly.message"));
Optional<Integer> limit = ActorSelectorLimits.forActor(actor).getPolygonVertexLimit();
limit.ifPresent(integer -> actor.print(Caption.of(
"worldedit.select.poly.limit-message",
TextComponent.of(integer)
)));
break;
}
case ELLIPSOID:
newSelector = new EllipsoidRegionSelector(oldSelector);
actor.print(Caption.of("worldedit.select.ellipsoid.message"));
break;
case SPHERE:
newSelector = new SphereRegionSelector(oldSelector);
actor.print(Caption.of("worldedit.select.sphere.message"));
break;
case CYL:
newSelector = new CylinderRegionSelector(oldSelector);
actor.print(Caption.of("worldedit.select.cyl.message"));
break;
case CONVEX:
case HULL:
case POLYHEDRON: {
newSelector = new ConvexPolyhedralRegionSelector(oldSelector);
actor.print(Caption.of("worldedit.select.convex.message"));
Optional<Integer> limit = ActorSelectorLimits.forActor(actor).getPolyhedronVertexLimit();
limit.ifPresent(integer -> actor.print(Caption.of(
"worldedit.select.convex.limit-message",
TextComponent.of(integer)
)));
break;
}
//FAWE start
case POLYHEDRAL:
newSelector = new PolyhedralRegionSelector(world);
actor.print(Caption.of("fawe.selection.sel.convex.polyhedral"));
Optional<Integer> limit = ActorSelectorLimits.forActor(actor).getPolyhedronVertexLimit();
limit.ifPresent(integer -> actor.print(Caption.of("fawe.selection.sel.max", integer)));
actor.print(Caption.of("fawe.selection.sel.list"));
break;
case FUZZY:
case MAGIC:
Mask maskOpt = new IdMask(world);
newSelector = new FuzzyRegionSelector(actor, world, maskOpt);
actor.print(Caption.of("fawe.selection.sel.fuzzy"));
actor.print(Caption.of("fawe.selection.sel.list"));
break;
//FAWE end
case LIST:
default:
CommandListBox box = new CommandListBox("Selection modes", null, null);
box.setHidingHelp(true);
TextComponentProducer contents = box.getContents();
contents.append(SubtleFormat.wrap("Select one of the modes below:")).newline();
box.appendCommand("cuboid", Caption.of("worldedit.select.cuboid.description"), "//sel cuboid");
box.appendCommand("extend", Caption.of("worldedit.select.extend.description"), "//sel extend");
box.appendCommand("poly", Caption.of("worldedit.select.poly.description"), "//sel poly");
box.appendCommand("ellipsoid", Caption.of("worldedit.select.ellipsoid.description"), "//sel ellipsoid");
box.appendCommand("sphere", Caption.of("worldedit.select.sphere.description"), "//sel sphere");
box.appendCommand("cyl", Caption.of("worldedit.select.cyl.description"), "//sel cyl");
box.appendCommand("convex", Caption.of("worldedit.select.convex.description"), "//sel convex");
//FAWE start
box.appendCommand("polyhedral", Caption.of("fawe.selection.sel.polyhedral"), "//sel polyhedral");
box.appendCommand("fuzzy[=<mask>]", Caption.of("fawe.selection.sel.fuzzy-instruction"), "//sel fuzzy[=<mask>]");
box.setComponentsPerPage(box.getComponentsSize());
//FAWE end
actor.print(box.create(1));
return;
}
if (setDefaultSelector) {
RegionSelectorType found = RegionSelectorType.getForSelector(newSelector);
if (found != null) {
session.setDefaultRegionSelector(found);
actor.print(Caption.of("worldedit.select.default-set", TextComponent.of(found.name())));
} else {
throw new RuntimeException("Something unexpected happened. Please report this.");
}
}
session.setRegionSelector(world, newSelector);
session.dispatchCUISelection(actor);
}
public static class BlockDistributionResult extends PaginationBox {
private final List<Countable<BlockState>> distribution;
private final int totalBlocks;
private final boolean separateStates;
//FAWE start
private final int maxDigits;
private boolean consoleFormat = false;
//FAWE end
public BlockDistributionResult(List<Countable<BlockState>> distribution, boolean separateStates) {
this(distribution, separateStates, "//distr -p %page%" + (separateStates ? " -d" : ""));
}
public BlockDistributionResult(List<Countable<BlockState>> distribution, boolean separateStates, String pageCommand) {
super("Block Distribution", pageCommand);
this.distribution = distribution;
// note: doing things like region.getArea is inaccurate for non-cuboids.
this.totalBlocks = distribution.stream().mapToInt(Countable::getAmount).sum();
this.separateStates = separateStates;
setComponentsPerPage(7);
//FAWE start
this.maxDigits = (int) (Math.log10(distribution.get(0).getAmount()) + 1);
//FAWE end
}
@Override
public Component getComponent(int number) {
Countable<BlockState> c = distribution.get(number);
TextComponent.Builder line = TextComponent.builder();
final int count = c.getAmount();
//FAWE start - better formatting, support console
final double perc = count / (double) totalBlocks * 100;
final int curDigits = (int) (Math.log10(count) + 1);
// Assume console uses monospaced font
final String space = consoleFormat ? " " : " ";
line.append(String.format("%s%.3f%% ", perc < 10 ? space : "", perc), TextColor.GOLD);
final int diff = maxDigits - curDigits;
final int multipler;
if (consoleFormat) {
multipler = diff + 2;
} else {
multipler = diff == 0 ? 2 : 2 * diff + 1;
}
String pad = Strings.repeat(" ", multipler);
//FAWE end
line.append(String.format("%s%s", count, pad), TextColor.YELLOW);
final BlockState state = c.getID();
final BlockType blockType = state.getBlockType();
//FAWE start - better formatting, support console; Translation keys will not work on console
Component blockName = consoleFormat ? TextComponent.of(blockType.getName()) : blockType.getRichName();
//FAWE end
TextComponent toolTip;
if (separateStates && state != blockType.getDefaultState()) {
toolTip = TextComponent.of(state.getAsString());
blockName = blockName.append(TextComponent.of("*"));
} else {
toolTip = TextComponent.of(blockType.getId());
}
blockName = blockName.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, toolTip));
line.append(blockName);
return line.build();
}
@Override
public int getComponentsSize() {
return distribution.size();
}
//FAWE start - support for console
@Override
public void formatForConsole() {
this.consoleFormat = true;
super.formatForConsole();
}
//FAWE end
@Override
public Component create(int page) throws InvalidComponentException {
super.getContents().append(Caption.of("worldedit.distr.total", TextComponent.of(totalBlocks)))
.append(TextComponent.newline());
return super.create(page);
}
}
}