Skip to content

Commit

Permalink
Re-arrange new methods to fix checkstyle, and better null handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanWolf committed Jul 13, 2018
1 parent c511fda commit 514c6fe
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
Expand Up @@ -3777,11 +3777,6 @@ public Wand getWand(ItemStack itemStack) {
return wand;
}

@Override
public Wand createWand(ItemStack itemStack) {
return Wand.createWand(this, itemStack);
}

@Override
public Wand getWand(ConfigurationSection config) {
return new Wand(this, config);
Expand All @@ -3793,6 +3788,12 @@ public Wand createWand(String wandKey) {
return Wand.createWand(this, wandKey);
}

@Override
@Nonnull
public Wand createWand(@Nonnull ItemStack itemStack) {
return Wand.createWand(this, itemStack);
}

@Nullable
@Override
public WandTemplate getWandTemplate(String key) {
Expand Down
9 changes: 5 additions & 4 deletions Magic/src/main/java/com/elmakers/mine/bukkit/wand/Wand.java
Expand Up @@ -3264,17 +3264,18 @@ public static Wand createWand(MagicController controller, String templateName) {
return wand;
}

@Nullable
public static Wand createWand(MagicController controller, ItemStack itemStack) {
if (controller == null) return null;

@Nonnull
public static Wand createWand(@Nonnull MagicController controller, @Nonnull ItemStack itemStack) {
Preconditions.checkNotNull(controller);
Preconditions.checkNotNull(itemStack);
Wand wand = null;
try {
wand = controller.getWand(InventoryUtils.makeReal(itemStack.clone()));
wand.saveState();
wand.updateName();
} catch (Exception ex) {
ex.printStackTrace();
wand = new Wand(controller);
}
return wand;
}
Expand Down
Expand Up @@ -76,6 +76,15 @@ public interface MageController {
*/
Collection<LostWand> getLostWands();

/**
* Creates a copy of the given item and turns it into a Wand.
*
* @param item The item to get a wand of.
* @return The wand of this item.
*/
@Nonnull
Wand createWand(@Nonnull ItemStack item);

/**
* Create a new Wand from a template.
*
Expand Down Expand Up @@ -111,14 +120,6 @@ public interface MageController {
* @throws IllegalArgumentException If the item is not a wand.
*/
Wand getWand(ItemStack item);

/**
* Creates a copy of the given item and turns it into a Wand.
*
* @param item The item to get a wand of.
* @return The wand of this item.
*/
Wand createWand(ItemStack item);
Wand getWand(ConfigurationSection config);
@Nullable
WandTemplate getWandTemplate(String key);
Expand Down

0 comments on commit 514c6fe

Please sign in to comment.