Javadoc and Formatting fixes. (#619)

Javadoc and Formatting fixes.

Also, extremely minor code changes which have been tested.
This commit is only part one of two commits that aim to fix problems with formatting in our project. In part two I will modify the Google Java Style Guide (since it closely matches our code style) for our project so there is guidance on how to format and document. 

* Updated PlotSquared URL
* Removed plugin acronyms
* Fixed a typo
* Fixed grammar
* Use modern block id's
* Update YouTube video URL
This commit is contained in:
Matt
2020-10-05 13:41:41 -04:00
committed by GitHub
parent b06d943f7c
commit 96dcb95b7c
393 changed files with 6537 additions and 4700 deletions

View File

@ -76,22 +76,8 @@ import javax.annotation.Nullable;
* players that make use of WorldEdit.
*/
public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
private final Map<String, Object> meta;
public AbstractPlayerActor(Map<String, Object> meta) {
this.meta = meta;
}
public AbstractPlayerActor() {
this(new ConcurrentHashMap<>());
}
@Override
public Map<String, Object> getRawMeta() {
return meta;
}
// Queue for async tasks
private AtomicInteger runningCount = new AtomicInteger();
private AsyncNotifyQueue asyncNotifyQueue = new AsyncNotifyQueue(
@ -111,6 +97,14 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
}
});
public AbstractPlayerActor(Map<String, Object> meta) {
this.meta = meta;
}
public AbstractPlayerActor() {
this(new ConcurrentHashMap<>());
}
@Override
public final Extent getExtent() {
return getWorld();
@ -146,6 +140,11 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
}
}
@Override
public Map<String, Object> getRawMeta() {
return meta;
}
@Override
public boolean isHoldingPickAxe() {
ItemType item = getItemInHand(HandSide.MAIN_HAND).getType();
@ -250,7 +249,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
return false;
}
return getWorld().getBlock(location.add(0, -1, 0)).getBlockType().getMaterial()
.isMovementBlocker();
.isMovementBlocker();
}
@Override
@ -522,6 +521,52 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
return getCardinalDirection(0);
}
/**
* Get the player's current allowed WorldEdit regions.
*
* @return an array of allowed regions
*/
public Region[] getCurrentRegions() {
return getCurrentRegions(FaweMaskManager.MaskType.MEMBER);
}
public Region[] getCurrentRegions(FaweMaskManager.MaskType type) {
return WEManager.IMP.getMask(this, type);
}
/**
* Get the largest region in the player's allowed WorldEdit region.
*/
public Region getLargestRegion() {
long area = 0;
Region max = null;
for (Region region : this.getCurrentRegions()) {
final long tmp = region.getVolume();
if (tmp > area) {
area = tmp;
max = region;
}
}
return max;
}
public void setSelection(Region region) {
RegionSelector selector;
if (region instanceof ConvexPolyhedralRegion) {
selector = new ConvexPolyhedralRegionSelector((ConvexPolyhedralRegion) region);
} else if (region instanceof CylinderRegion) {
selector = new CylinderRegionSelector((CylinderRegion) region);
} else if (region instanceof Polygonal2DRegion) {
selector = new Polygonal2DRegionSelector((Polygonal2DRegion) region);
} else {
selector = new CuboidRegionSelector(null, region.getMinimumPoint(),
region.getMaximumPoint());
}
selector.setWorld(region.getWorld());
getSession().setRegionSelector(getWorld(), selector);
}
@Override
public Direction getCardinalDirection(int yawOffset) {
final Location location = getLocation();
@ -631,6 +676,36 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
return null;
}
/**
* Run a task either async, or on the current thread.
*
* @param ifFree the task to run if free
* @param checkFree Whether to first check if a task is running
* @param async TODO description
* @return false if the task was ran or queued
*/
public boolean runAction(Runnable ifFree, boolean checkFree, boolean async) {
if (checkFree) {
if (runningCount.get() != 0) {
return false;
}
}
Runnable wrapped = () -> {
try {
runningCount.addAndGet(1);
ifFree.run();
} finally {
runningCount.decrementAndGet();
}
};
if (async) {
asyncNotifyQueue.run(wrapped);
} else {
TaskManager.IMP.taskNow(wrapped, false);
}
return true;
}
@Override
public boolean canDestroyBedrock() {
return hasPermission("worldedit.override.bedrock");
@ -690,84 +765,4 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
}
/**
* Run a task either async, or on the current thread.
*
* @param ifFree the task to run if free
* @param checkFree Whether to first check if a task is running
* @param async TODO description
* @return false if the task was ran or queued
*/
public boolean runAction(Runnable ifFree, boolean checkFree, boolean async) {
if (checkFree) {
if (runningCount.get() != 0) {
return false;
}
}
Runnable wrapped = () -> {
try {
runningCount.addAndGet(1);
ifFree.run();
} finally {
runningCount.decrementAndGet();
}
};
if (async) {
asyncNotifyQueue.run(wrapped);
} else {
TaskManager.IMP.taskNow(wrapped, false);
}
return true;
}
/**
* Get the player's current allowed WorldEdit regions.
*
* @return an array of allowed regions
*/
public Region[] getCurrentRegions() {
return getCurrentRegions(FaweMaskManager.MaskType.MEMBER);
}
public Region[] getCurrentRegions(FaweMaskManager.MaskType type) {
return WEManager.IMP.getMask(this, type);
}
/**
* Get the largest region in the player's allowed WorldEdit region.
*
* @return
*/
public Region getLargestRegion() {
long area = 0;
Region max = null;
for (Region region : this.getCurrentRegions()) {
final long tmp = region.getVolume();
if (tmp > area) {
area = tmp;
max = region;
}
}
return max;
}
public void setSelection(Region region) {
RegionSelector selector;
if (region instanceof ConvexPolyhedralRegion) {
selector = new ConvexPolyhedralRegionSelector((ConvexPolyhedralRegion) region);
} else if (region instanceof CylinderRegion) {
selector = new CylinderRegionSelector((CylinderRegion) region);
} else if (region instanceof Polygonal2DRegion) {
selector = new Polygonal2DRegionSelector((Polygonal2DRegion) region);
} else {
selector = new CuboidRegionSelector(null, region.getMinimumPoint(),
region.getMaximumPoint());
}
selector.setWorld(region.getWorld());
getSession().setRegionSelector(getWorld(), selector);
}
}

View File

@ -98,7 +98,8 @@ public interface Platform {
*
* @return the watchdog service, or {@code null} if none
*/
default @Nullable Watchdog getWatchdog() {
@Nullable
default Watchdog getWatchdog() {
return null;
}

View File

@ -620,7 +620,9 @@ public final class PlatformCommandManager {
}
public int parseCommand(String args, InjectedValueAccess access) {
if (args.isEmpty()) return 0;
if (args.isEmpty()) {
return 0;
}
String[] split = parseArgs(args)
.map(Substring::getSubstring)
.toArray(String[]::new);
@ -841,6 +843,7 @@ public final class PlatformCommandManager {
}
throw t;
}
event.setSuggestions(suggestions.stream()
.map(suggestion -> {
int noSlashLength = arguments.length() - 1;

View File

@ -77,7 +77,8 @@ public class PlatformManager {
private final PlatformCommandManager platformCommandManager;
private final List<Platform> platforms = new ArrayList<>();
private final Map<Capability, Platform> preferences = new EnumMap<>(Capability.class);
private @Nullable String firstSeenVersion;
@Nullable
private String firstSeenVersion;
private final AtomicBoolean initialized = new AtomicBoolean();
private final AtomicBoolean configured = new AtomicBoolean();
@ -112,9 +113,8 @@ public class PlatformManager {
// Make sure that versions are in sync
if (firstSeenVersion != null) {
if (!firstSeenVersion.equals(platform.getVersion())) {
logger.warn("Multiple ports of WorldEdit are installed but they report different versions ({} and {}). " +
"If these two versions are truly different, then you may run into unexpected crashes and errors.",
new Object[]{ firstSeenVersion, platform.getVersion() });
logger.warn("Multiple ports of WorldEdit are installed but they report different versions ({} and {}). "
+ "If these two versions are truly different, then you may run into unexpected crashes and errors.", firstSeenVersion, platform.getVersion());
}
} else {
firstSeenVersion = platform.getVersion();
@ -209,7 +209,8 @@ public class PlatformManager {
* @param capability the capability
* @return the most preferred platform, or null if no platform was found
*/
private synchronized @Nullable Platform findMostPreferred(Capability capability) {
@Nullable
private synchronized Platform findMostPreferred(Capability capability) {
Platform preferred = null;
Preference highest = null;
@ -352,7 +353,9 @@ public class PlatformManager {
}
virtual.handleBlockInteract(player, vector.toBlockPoint(), event);
if (event.isCancelled()) return;
if (event.isCancelled()) {
return;
}
}
if (event.getType() == Interaction.HIT) {
@ -363,8 +366,8 @@ public class PlatformManager {
if (superPickaxe != null && superPickaxe.canUse(player)) {
player.runAction(() -> reset(superPickaxe)
.actPrimary(queryCapability(Capability.WORLD_EDITING),
getConfiguration(), player, session, location), false, true);
event.setCancelled(true);
getConfiguration(), player, session, location), false, true);
event.setCancelled(true);
return;
}
}
@ -373,11 +376,11 @@ public class PlatformManager {
if (tool instanceof DoubleActionBlockTool && tool.canUse(player)) {
player.runAction(() -> reset((DoubleActionBlockTool) tool)
.actSecondary(queryCapability(Capability.WORLD_EDITING),
getConfiguration(), player, session, location), false, true);
event.setCancelled(true);
}
getConfiguration(), player, session, location), false, true);
event.setCancelled(true);
}
} else if (event.getType() == Interaction.OPEN) {
} else if (event.getType() == Interaction.OPEN) {
Tool tool = session.getTool(player);
if (tool instanceof BlockTool && tool.canUse(player)) {
if (player.checkAction()) {
@ -385,14 +388,14 @@ public class PlatformManager {
BlockTool blockTool = (BlockTool) tool;
if (!(tool instanceof BrushTool)) {
blockTool = reset(blockTool);
}
}
blockTool.actPrimary(queryCapability(Capability.WORLD_EDITING),
getConfiguration(), player, session, location);
getConfiguration(), player, session, location);
}, false, true);
event.setCancelled(true);
}
}
}
}
}
} catch (Throwable e) {
handleThrowable(e, actor);
} finally {
@ -403,7 +406,7 @@ public class PlatformManager {
public void handleThrowable(Throwable e, Actor actor) {
FaweException faweException = FaweException.get(e);
if (faweException != null) {
actor.print(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason" , faweException.getComponent()));
actor.print(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason", faweException.getComponent()));
} else {
actor.printError("Please report this error: [See console]");
actor.printRaw(e.getClass().getName() + ": " + e.getMessage());
@ -423,7 +426,9 @@ public class PlatformManager {
logger.info("virtualWorld was not null in handlePlayerInput()");
}
virtual.handlePlayerInput(player, event);
if (event.isCancelled()) return;
if (event.isCancelled()) {
return;
}
}
try {
@ -432,10 +437,10 @@ public class PlatformManager {
Tool tool = session.getTool(player);
if (tool instanceof DoubleActionTraceTool && tool.canUse(player)) {
player.runAsyncIfFree(() -> reset((DoubleActionTraceTool) tool).actSecondary(queryCapability(Capability.WORLD_EDITING),
getConfiguration(), player, session));
event.setCancelled(true);
return;
}
getConfiguration(), player, session));
event.setCancelled(true);
return;
}
break;
}
@ -445,10 +450,10 @@ public class PlatformManager {
if (tool instanceof TraceTool && tool.canUse(player)) {
//todo this needs to be fixed so the event is canceled after actPrimary is used and returns true
player.runAction(() -> reset((TraceTool) tool).actPrimary(queryCapability(Capability.WORLD_EDITING),
getConfiguration(), player, session), false, true);
event.setCancelled(true);
return;
}
getConfiguration(), player, session), false, true);
event.setCancelled(true);
return;
}
break;
}
@ -456,7 +461,7 @@ public class PlatformManager {
} catch (Throwable e) {
FaweException faweException = FaweException.get(e);
if (faweException != null) {
player.print(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason" , faweException.getComponent()));
player.print(TranslatableComponent.of("fawe.cancel.worldedit.cancel.reason", faweException.getComponent()));
} else {
player.printError("Please report this error: [See console]");
player.printRaw(e.getClass().getName() + ": " + e.getMessage());

View File

@ -41,7 +41,9 @@ public class Bindings {
private boolean register(Method method, InjectedValueStore store, CommandManager manager) {
// Check that it has the binding
Binding binding = method.getAnnotation(Binding.class);
if (binding == null) return false;
if (binding == null) {
return false;
}
Annotation[] annotations = method.getAnnotations();
// Get the key
@ -49,7 +51,7 @@ public class Bindings {
Key key;
if ( annotations.length == 1) {
key = Key.of(ret);
}else if (annotations.length == 2) {
} else if (annotations.length == 2) {
Annotation annotation = annotations[0] == binding ? annotations[1] : annotations[0];
key = Key.of(ret, annotation);
} else {

View File

@ -124,7 +124,7 @@ public class ConsumeBindings extends Bindings {
uuid = Fawe.imp().getUUID(argument);
}
if (uuid == null) {
throw new InputParseException(Caption.toString(Caption.of("fawe.error.player.not.found" , argument)));
throw new InputParseException(Caption.toString(Caption.of("fawe.error.player.not.found", argument)));
}
return uuid;
}
@ -202,7 +202,9 @@ public class ConsumeBindings extends Bindings {
public BiomeType getBiomeType(String argument) throws WorldEditException {
if (argument != null) {
if (MathMan.isInteger(argument)) return BiomeTypes.getLegacy(Integer.parseInt(argument));
if (MathMan.isInteger(argument)) {
return BiomeTypes.getLegacy(Integer.parseInt(argument));
}
BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager()
.queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry();
Collection<BiomeType> knownBiomes = BiomeType.REGISTRY.values();

View File

@ -103,7 +103,9 @@ public class PrimitiveBindings extends Bindings {
@Binding
public Vector3 getVector3(String argument) {
String[] radii = argument.split(",");
final double radiusX, radiusY, radiusZ;
final double radiusX;
final double radiusY;
final double radiusZ;
switch (radii.length) {
case 1:
radiusX = radiusY = radiusZ = PrimitiveBindings.parseNumericInput(radii[0]);
@ -133,7 +135,8 @@ public class PrimitiveBindings extends Bindings {
public Vector2 getVector2(String argument) {
String radiusString = argument;
String[] radii = radiusString.split(",");
final double radiusX, radiusZ;
final double radiusX;
final double radiusZ;
switch (radii.length) {
case 1:
radiusX = radiusZ = PrimitiveBindings.parseNumericInput(radii[0]);
@ -161,7 +164,9 @@ public class PrimitiveBindings extends Bindings {
public BlockVector3 getBlockVector3(String argument) {
String radiusString = argument;
String[] radii = radiusString.split(",");
final double radiusX, radiusY, radiusZ;
final double radiusX;
final double radiusY;
final double radiusZ;
switch (radii.length) {
case 1:
radiusX = radiusY = radiusZ = PrimitiveBindings.parseNumericInput(radii[0]);
@ -190,7 +195,8 @@ public class PrimitiveBindings extends Bindings {
@Binding
public BlockVector2 getBlockVector2(String argument) {
String[] radii = argument.split(",");
final double radiusX, radiusZ;
final double radiusX;
final double radiusZ;
switch (radii.length) {
case 1:
radiusX = radiusZ = parseNumericInput(radii[0]);
@ -214,7 +220,8 @@ public class PrimitiveBindings extends Bindings {
* @return a number
* @throws InputParseException thrown on parse error
*/
public static @Nullable Double parseNumericInput(@Nullable String input) {
@Nullable
public static Double parseNumericInput(@Nullable String input) {
if (input == null) {
return null;
}