Skip to content

Commit be23d4b

Browse files
committed
Tidy up PR and fixed wrong javadoc
1 parent 44f7380 commit be23d4b

File tree

6 files changed

+34
-22
lines changed

6 files changed

+34
-22
lines changed

worldguard-core/src/main/java/com/sk89q/worldguard/commands/CommandInputContext.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import javax.annotation.Nullable;
2727
import java.util.Map;
2828

29-
public class CommandInputContext {
29+
public abstract class CommandInputContext<T extends Exception> {
3030
protected final Actor sender;
3131
protected final String input;
3232

@@ -56,30 +56,32 @@ public String getUserInput() {
5656
* @return Player
5757
* @throws InvalidFlagFormat if the sender is not a player
5858
*/
59-
public LocalPlayer getPlayerSender() throws InvalidFlagFormat {
59+
public LocalPlayer getPlayerSender() throws T {
6060
if (sender.isPlayer() && sender instanceof LocalPlayer) {
6161
return (LocalPlayer) sender;
6262
} else {
63-
throw new InvalidFlagFormat("Not a player");
63+
throw createException("Not a player");
6464
}
6565
}
6666

67-
public Integer getUserInputAsInt() throws InvalidFlagFormat {
67+
public Integer getUserInputAsInt() throws T {
6868
try {
6969
return Integer.parseInt(input);
7070
} catch (NumberFormatException e) {
71-
throw new InvalidFlagFormat("Not a number: " + input);
71+
throw createException("Not a number: " + input);
7272
}
7373
}
7474

75-
public Double getUserInputAsDouble() throws InvalidFlagFormat {
75+
public Double getUserInputAsDouble() throws T {
7676
try {
7777
return Double.parseDouble(input);
7878
} catch (NumberFormatException e) {
79-
throw new InvalidFlagFormat("Not a number: " + input);
79+
throw createException("Not a number: " + input);
8080
}
8181
}
8282

83+
protected abstract T createException(String str);
84+
8385
/**
8486
* Get an object from the context by key name.
8587
* May return null if the object does not exist in the context.

worldguard-core/src/main/java/com/sk89q/worldguard/domains/registry/CustomDomainContext.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import javax.annotation.Nullable;
2727
import java.util.Map;
2828

29-
public final class CustomDomainContext extends CommandInputContext {
29+
public final class CustomDomainContext extends CommandInputContext<InvalidDomainFormat> {
3030

3131
private CustomDomainContext(Actor sender, String input, Map<String, Object> values) {
3232
super(sender, input, values);
@@ -38,16 +38,16 @@ public static CustomDomainContext.CustomDomainContextBuilder create() {
3838
}
3939

4040
/**
41-
* Create a copy of this FlagContext, with optional substitutions for values
41+
* Create a copy of this CustomDomainContext, with optional substitutions for values
4242
*
43-
* If any supplied variable is null, it will be ignored.
44-
* If a map is supplied, it will override this FlagContext's values of the same key,
45-
* but unprovided keys will not be overriden and will be returned as shallow copies.
43+
* <p>If any supplied variable is null, it will be ignored.
44+
* If a map is supplied, it will override this CustomDomainContext's values of the same key,
45+
* but unprovided keys will not be overriden and will be returned as shallow copies.</p>
4646
*
47-
* @param commandSender CommandSender for the new FlagContext to run under
48-
* @param s String of the user input for the new FlagContext
49-
* @param values map of values to override from the current FlagContext
50-
* @return a copy of this FlagContext
47+
* @param commandSender CommandSender for the new CustomDomainContext to run under
48+
* @param s String of the user input for the new CustomDomainContext
49+
* @param values map of values to override from the current CustomDomainContext
50+
* @return a copy of this CustomDomainContext
5151
*/
5252
public CustomDomainContext copyWith(@Nullable Actor commandSender, @Nullable String s, @Nullable Map<String, Object> values) {
5353
Map<String, Object> map = Maps.newHashMap();
@@ -58,6 +58,11 @@ public CustomDomainContext copyWith(@Nullable Actor commandSender, @Nullable Str
5858
return new CustomDomainContext(commandSender == null ? this.sender : commandSender, s == null ? this.input : s, map);
5959
}
6060

61+
@Override
62+
protected InvalidDomainFormat createException(String str) {
63+
return new InvalidDomainFormat(str);
64+
}
65+
6166
public static class CustomDomainContextBuilder {
6267
private Actor sender;
6368
private String input;

worldguard-core/src/main/java/com/sk89q/worldguard/domains/registry/DomainRegistry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public interface DomainRegistry extends Iterable<DomainFactory<?>> {
4949
* no exception will be thrown.</p>
5050
*
5151
* @param domains a collection of domain factories
52-
* @throws IllegalStateException If it is not the right time to register new flags
52+
* @throws IllegalStateException If it is not the right time to register new domains
5353
*/
5454
void registerAll(Map<String, DomainFactory<?>> domains);
5555

worldguard-core/src/main/java/com/sk89q/worldguard/domains/registry/UnknownDomain.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public UnknownDomain(String name) {
3535

3636
@Override
3737
public void parseInput(CustomDomainContext context) throws InvalidDomainFormat {
38-
throw new InvalidDomainFormat("The plugin that registered this flag is not currently installed");
38+
throw new InvalidDomainFormat("The plugin that registered this domain is not currently installed");
3939
}
4040

4141
@Override

worldguard-core/src/main/java/com/sk89q/worldguard/internal/permission/RegionPermissionModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public boolean mayRemoveOwners(ProtectedRegion region) {
179179
}
180180

181181
/**
182-
* Checks to see if the given sender has permission to modify a custom region
182+
* Checks to see if the given sender has permission to set or modify a custom domain
183183
*
184184
* @param region the region
185185
* @param isOwnerLevel whether the domain level is owner (else member)

worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/FlagContext.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import javax.annotation.Nullable;
2828
import java.util.Map;
2929

30-
public final class FlagContext extends CommandInputContext {
30+
public final class FlagContext extends CommandInputContext<InvalidFlagFormat> {
3131

3232
private FlagContext(Actor sender, String input, Map<String, Object> values) {
3333
super(sender, input, values);
@@ -40,9 +40,9 @@ public static FlagContext.FlagContextBuilder create() {
4040
/**
4141
* Create a copy of this FlagContext, with optional substitutions for values
4242
*
43-
* If any supplied variable is null, it will be ignored.
43+
* <p>If any supplied variable is null, it will be ignored.
4444
* If a map is supplied, it will override this FlagContext's values of the same key,
45-
* but unprovided keys will not be overriden and will be returned as shallow copies.
45+
* but unprovided keys will not be overriden and will be returned as shallow copies.</p>
4646
*
4747
* @param commandSender CommandSender for the new FlagContext to run under
4848
* @param s String of the user input for the new FlagContext
@@ -58,6 +58,11 @@ public FlagContext copyWith(@Nullable Actor commandSender, @Nullable String s, @
5858
return new FlagContext(commandSender == null ? this.sender : commandSender, s == null ? this.input : s, map);
5959
}
6060

61+
@Override
62+
protected InvalidFlagFormat createException(String str) {
63+
return new InvalidFlagFormat(str);
64+
}
65+
6166
public static class FlagContextBuilder {
6267
private Actor sender;
6368
private String input;

0 commit comments

Comments
 (0)