Hopefully fixed java 8 Optional errors

This commit is contained in:
Jared committed 2016-10-30 22:35:44 +02:00
1 parent c6643a65d9
commit e20b304083
6 files changed
+138 -153

No files matched your search

@@ -70,10 +70,6 @@ public class IngredientAnyAdvanced implements IIngredient {
@Override
public boolean matches(IItemStack item) {
// TODO: what is the point of this?
if (!item.matches(item))
return false;
for (IItemCondition condition : conditions) {
if (!condition.matches(item))
return false;
@@ -84,10 +80,6 @@ public class IngredientAnyAdvanced implements IIngredient {
@Override
public boolean matchesExact(IItemStack item) {
// TODO: what is the point of this?
if (!item.matchesExact(item))
return false;
for (IItemCondition condition : conditions) {
if (!condition.matches(item))
return false;
@@ -11,85 +11,75 @@ import java.io.IOException;
import java.util.Iterator;
/**
*
* @author Stan
*/
public class CloseablePriorityList<T> implements Iterable<T> {
private CloseableEntry first;
private CloseableEntry first;
/**
* Adds a new item to the list. The new item will be inserted at the head of
* the list.
*
* @param value
* @return
*/
public Closeable add(T value) {
if (first == null) {
first = new CloseableEntry(value);
} else {
CloseableEntry entry = new CloseableEntry(value);
entry.next = first;
first.prev = entry;
first = entry;
}
/**
* Adds a new item to the list. The new item will be inserted at the head of
* the list.
*
* @param value
* @return
*/
public Closeable add(T value) {
if(first == null) {
first = new CloseableEntry(value);
} else {
CloseableEntry entry = new CloseableEntry(value);
entry.next = first;
first.prev = entry;
first = entry;
}
return first;
}
return first;
}
@Override
public Iterator<T> iterator() {
return new MyIterator();
}
@Override
public Iterator<T> iterator() {
return new MyIterator();
}
private class MyIterator implements Iterator<T> {
private CloseableEntry current = null;
private class MyIterator implements Iterator<T> {
private CloseableEntry current = null;
@Override
public boolean hasNext() {
return current == null || current.next != null;
}
@Override
public boolean hasNext() {
return current == null || current.next != null;
}
@Override
public T next() {
current = current == null ? first : current.next;
return current.value;
}
@Override
public T next() {
current = current == null ? first : current.next;
return current.value;
}
@Override
public void remove() {
throw new UnsupportedOperationException("Not supported yet."); // To
// change
// body
// of
// generated
// methods,
// choose
// Tools
// |
// Templates.
}
}
@Override
public void remove() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
private class CloseableEntry implements Closeable {
private final T value;
private CloseableEntry next;
private CloseableEntry prev;
private class CloseableEntry implements Closeable {
private final T value;
private CloseableEntry next;
private CloseableEntry prev;
public CloseableEntry(T value) {
this.value = value;
}
public CloseableEntry(T value) {
this.value = value;
}
@Override
public void close() throws IOException {
if (next != null) {
next.prev = prev;
}
if (prev == null) {
first = next;
} else {
prev.next = next;
}
}
}
@Override
public void close() throws IOException {
if(next != null) {
next.prev = prev;
}
if(prev == null) {
first = next;
} else {
prev.next = next;
}
}
}
}
@@ -17,6 +17,7 @@ import minetweaker.mc1102.item.MCItemStack;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraftforge.fml.common.registry.GameRegistry;
import stanhebben.zenscript.annotations.Optional;
import java.util.ArrayList;
import java.util.List;
@@ -34,7 +35,7 @@ public class MCFurnaceManager implements IFurnaceManager{
}
@Override
public void remove(IIngredient output, IIngredient input){
public void remove(IIngredient output, @Optional IIngredient input){
if(output == null)
throw new IllegalArgumentException("output cannot be null");
@@ -57,7 +58,7 @@ public class MCFurnaceManager implements IFurnaceManager{
}
@Override
public void addRecipe(IItemStack output, IIngredient input, double xp){
public void addRecipe(IItemStack output, IIngredient input, @Optional double xp){
List<IItemStack> items = input.getItems();
if(items == null){
MineTweakerAPI.logError("Cannot turn " + input.toString() + " into a furnace recipe");
@@ -14,6 +14,7 @@ import minetweaker.api.oredict.IOreDictEntry;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import stanhebben.zenscript.annotations.Optional;
import java.util.ArrayList;
import java.util.List;
@@ -41,7 +42,7 @@ public class MCItemDefinition implements IItemDefinition{
}
@Override
public IItemStack makeStack(int meta){
public IItemStack makeStack(@Optional int meta){
return MineTweakerMC.getIItemStackWildcardSize(new ItemStack(item, 1, meta));
}
@@ -38,15 +38,15 @@ public class MCRecipeManager implements IRecipeManager {
}
private static boolean matches(Object input, IIngredient ingredient) {
if ((input == null) != (ingredient == null)) {
if((input == null) != (ingredient == null)) {
return false;
} else if (ingredient != null) {
if (input instanceof ItemStack) {
if (!ingredient.matches(getIItemStack((ItemStack) input))) {
} else if(ingredient != null) {
if(input instanceof ItemStack) {
if(!ingredient.matches(getIItemStack((ItemStack) input))) {
return false;
}
} else if (input instanceof String) {
if (!ingredient.contains(getOreDict((String) input))) {
} else if(input instanceof String) {
if(!ingredient.contains(getOreDict((String) input))) {
return false;
}
}
@@ -60,8 +60,8 @@ public class MCRecipeManager implements IRecipeManager {
}
public void applyTransformations(ICraftingInventory inventory, IPlayer byPlayer) {
for (ICraftingRecipe recipe : transformerRecipes) {
if (recipe.matches(inventory)) {
for(ICraftingRecipe recipe : transformerRecipes) {
if(recipe.matches(inventory)) {
recipe.applyTransformers(inventory, byPlayer);
return;
}
@@ -72,8 +72,8 @@ public class MCRecipeManager implements IRecipeManager {
public List<ICraftingRecipe> getRecipesFor(IIngredient ingredient) {
List<ICraftingRecipe> results = new ArrayList<ICraftingRecipe>();
for (IRecipe recipe : recipes) {
if (ingredient.matches(MineTweakerMC.getIItemStack(recipe.getRecipeOutput()))) {
for(IRecipe recipe : recipes) {
if(ingredient.matches(MineTweakerMC.getIItemStack(recipe.getRecipeOutput()))) {
ICraftingRecipe converted = RecipeConverter.toCraftingRecipe(recipe);
results.add(converted);
}
@@ -86,7 +86,7 @@ public class MCRecipeManager implements IRecipeManager {
public List<ICraftingRecipe> getAll() {
List<ICraftingRecipe> results = new ArrayList<ICraftingRecipe>();
for (IRecipe recipe : recipes) {
for(IRecipe recipe : recipes) {
ICraftingRecipe converted = RecipeConverter.toCraftingRecipe(recipe);
results.add(converted);
}
@@ -98,13 +98,13 @@ public class MCRecipeManager implements IRecipeManager {
public int remove(IIngredient output, @Optional boolean nbtMatch) {
List<IRecipe> toRemove = new ArrayList<IRecipe>();
List<Integer> removeIndex = new ArrayList<Integer>();
for (int i = 0; i < recipes.size(); i++) {
for(int i = 0; i < recipes.size(); i++) {
IRecipe recipe = recipes.get(i);
// certain special recipes have no predefined output. ignore those
// since these cannot be removed with MineTweaker scripts
if (recipe.getRecipeOutput() != null) {
if (nbtMatch ? output.matchesExact(getIItemStack(recipe.getRecipeOutput())) : output.matches(getIItemStack(recipe.getRecipeOutput()))) {
if(recipe.getRecipeOutput() != null) {
if(nbtMatch ? output.matchesExact(getIItemStack(recipe.getRecipeOutput())) : output.matches(getIItemStack(recipe.getRecipeOutput()))) {
toRemove.add(recipe);
removeIndex.add(i);
}
@@ -116,31 +116,31 @@ public class MCRecipeManager implements IRecipeManager {
}
@Override
public void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function) {
public void addShaped(IItemStack output, IIngredient[][] ingredients, @Optional IRecipeFunction function) {
addShaped(output, ingredients, function, false);
}
@Override
public void addShapedMirrored(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function) {
public void addShapedMirrored(IItemStack output, IIngredient[][] ingredients, @Optional IRecipeFunction function) {
addShaped(output, ingredients, function, true);
}
@Override
public void addShapeless(IItemStack output, IIngredient[] ingredients, IRecipeFunction function) {
public void addShapeless(IItemStack output, IIngredient[] ingredients, @Optional IRecipeFunction function) {
ShapelessRecipe recipe = new ShapelessRecipe(output, ingredients, function);
IRecipe irecipe = RecipeConverter.convert(recipe);
MineTweakerAPI.apply(new ActionAddRecipe(irecipe, recipe));
}
@Override
public int removeShaped(IIngredient output, IIngredient[][] ingredients) {
public int removeShaped(IIngredient output, @Optional IIngredient[][] ingredients) {
int ingredientsWidth = 0;
int ingredientsHeight = 0;
if (ingredients != null) {
if(ingredients != null) {
ingredientsHeight = ingredients.length;
for (int i = 0; i < ingredients.length; i++) {
for(int i = 0; i < ingredients.length; i++) {
ingredientsWidth = Math.max(ingredientsWidth, ingredients[i].length);
}
}
@@ -148,54 +148,54 @@ public class MCRecipeManager implements IRecipeManager {
List<IRecipe> toRemove = new ArrayList<IRecipe>();
List<Integer> removeIndex = new ArrayList<Integer>();
outer:
for (int i = 0; i < recipes.size(); i++) {
for(int i = 0; i < recipes.size(); i++) {
IRecipe recipe = recipes.get(i);
if (recipe.getRecipeOutput() == null || !output.matches(getIItemStack(recipe.getRecipeOutput()))) {
if(recipe.getRecipeOutput() == null || !output.matches(getIItemStack(recipe.getRecipeOutput()))) {
continue;
}
if (ingredients != null) {
if (recipe instanceof ShapedRecipes) {
if(ingredients != null) {
if(recipe instanceof ShapedRecipes) {
ShapedRecipes srecipe = (ShapedRecipes) recipe;
if (ingredientsWidth != srecipe.recipeWidth || ingredientsHeight != srecipe.recipeHeight) {
if(ingredientsWidth != srecipe.recipeWidth || ingredientsHeight != srecipe.recipeHeight) {
continue;
}
for (int j = 0; j < ingredientsHeight; j++) {
for(int j = 0; j < ingredientsHeight; j++) {
IIngredient[] row = ingredients[j];
for (int k = 0; k < ingredientsWidth; k++) {
for(int k = 0; k < ingredientsWidth; k++) {
IIngredient ingredient = k > row.length ? null : row[k];
ItemStack recipeIngredient = srecipe.recipeItems[j * srecipe.recipeWidth + k];
if (!matches(recipeIngredient, ingredient)) {
if(!matches(recipeIngredient, ingredient)) {
continue outer;
}
}
}
} else if (recipe instanceof ShapedOreRecipe) {
} else if(recipe instanceof ShapedOreRecipe) {
ShapedOreRecipe srecipe = (ShapedOreRecipe) recipe;
int recipeWidth = MineTweakerHacks.getShapedOreRecipeWidth(srecipe);
int recipeHeight = srecipe.getRecipeSize() / recipeWidth;
if (ingredientsWidth != recipeWidth || ingredientsHeight != recipeHeight) {
if(ingredientsWidth != recipeWidth || ingredientsHeight != recipeHeight) {
continue;
}
for (int j = 0; j < ingredientsHeight; j++) {
for(int j = 0; j < ingredientsHeight; j++) {
IIngredient[] row = ingredients[j];
for (int k = 0; k < ingredientsWidth; k++) {
for(int k = 0; k < ingredientsWidth; k++) {
IIngredient ingredient = k > row.length ? null : row[k];
Object input = srecipe.getInput()[j * recipeWidth + k];
if (!matches(input, ingredient)) {
if(!matches(input, ingredient)) {
continue outer;
}
}
}
}
} else {
if (recipe instanceof ShapedRecipes) {
if(recipe instanceof ShapedRecipes) {
} else if (recipe instanceof ShapedOreRecipe) {
} else if(recipe instanceof ShapedOreRecipe) {
} else {
continue;
@@ -211,52 +211,52 @@ public class MCRecipeManager implements IRecipeManager {
}
@Override
public int removeShapeless(IIngredient output, IIngredient[] ingredients, boolean wildcard) {
public int removeShapeless(IIngredient output, @Optional IIngredient[] ingredients, @Optional boolean wildcard) {
List<IRecipe> toRemove = new ArrayList<IRecipe>();
List<Integer> removeIndex = new ArrayList<Integer>();
outer:
for (int i = 0; i < recipes.size(); i++) {
for(int i = 0; i < recipes.size(); i++) {
IRecipe recipe = recipes.get(i);
if (recipe.getRecipeOutput() == null || !output.matches(getIItemStack(recipe.getRecipeOutput()))) {
if(recipe.getRecipeOutput() == null || !output.matches(getIItemStack(recipe.getRecipeOutput()))) {
continue;
}
if (ingredients != null) {
if (recipe instanceof ShapelessRecipes) {
if(ingredients != null) {
if(recipe instanceof ShapelessRecipes) {
ShapelessRecipes srecipe = (ShapelessRecipes) recipe;
if (ingredients.length > srecipe.getRecipeSize()) {
if(ingredients.length > srecipe.getRecipeSize()) {
continue;
} else if (!wildcard && ingredients.length < srecipe.getRecipeSize()) {
} else if(!wildcard && ingredients.length < srecipe.getRecipeSize()) {
continue;
}
checkIngredient:
for (int j = 0; j < ingredients.length; j++) {
for (int k = 0; k < srecipe.getRecipeSize(); k++) {
if (matches(srecipe.recipeItems.get(k), ingredients[j])) {
for(int j = 0; j < ingredients.length; j++) {
for(int k = 0; k < srecipe.getRecipeSize(); k++) {
if(matches(srecipe.recipeItems.get(k), ingredients[j])) {
continue checkIngredient;
}
}
continue outer;
}
} else if (recipe instanceof ShapelessOreRecipe) {
} else if(recipe instanceof ShapelessOreRecipe) {
ShapelessOreRecipe srecipe = (ShapelessOreRecipe) recipe;
ArrayList<Object> inputs = srecipe.getInput();
if (inputs.size() < ingredients.length) {
if(inputs.size() < ingredients.length) {
continue;
}
if (!wildcard && inputs.size() > ingredients.length) {
if(!wildcard && inputs.size() > ingredients.length) {
continue;
}
checkIngredient:
for (int j = 0; j < ingredients.length; j++) {
for (int k = 0; k < srecipe.getRecipeSize(); k++) {
if (matches(inputs.get(k), ingredients[j])) {
for(int j = 0; j < ingredients.length; j++) {
for(int k = 0; k < srecipe.getRecipeSize(); k++) {
if(matches(inputs.get(k), ingredients[j])) {
continue checkIngredient;
}
}
@@ -265,9 +265,9 @@ public class MCRecipeManager implements IRecipeManager {
}
}
} else {
if (recipe instanceof ShapelessRecipes) {
if(recipe instanceof ShapelessRecipes) {
} else if (recipe instanceof ShapelessOreRecipe) {
} else if(recipe instanceof ShapelessOreRecipe) {
} else {
continue;
@@ -288,25 +288,25 @@ public class MCRecipeManager implements IRecipeManager {
int width = 0;
int height = contents.length;
for (IItemStack[] row : contents) {
for(IItemStack[] row : contents) {
width = Math.max(width, row.length);
}
ItemStack[] iContents = new ItemStack[width * height];
for (int i = 0; i < height; i++) {
for (int j = 0; j < contents[i].length; j++) {
if (contents[i][j] != null) {
for(int i = 0; i < height; i++) {
for(int j = 0; j < contents[i].length; j++) {
if(contents[i][j] != null) {
iContents[i * width + j] = getItemStack(contents[i][j]);
}
}
}
InventoryCrafting inventory = new InventoryCrafting(container, width, height);
for (int i = 0; i < iContents.length; i++) {
for(int i = 0; i < iContents.length; i++) {
inventory.setInventorySlotContents(i, iContents[i]);
}
ItemStack result = CraftingManager.getInstance().findMatchingRecipe(inventory, null);
if (result == null) {
if(result == null) {
return null;
} else {
return getIItemStack(result);
@@ -337,7 +337,7 @@ public class MCRecipeManager implements IRecipeManager {
@Override
public void apply() {
for (int i = removingIndices.size() - 1; i >= 0; i--) {
for(int i = removingIndices.size() - 1; i >= 0; i--) {
recipes.remove((int) removingIndices.get(i));
}
}
@@ -349,7 +349,7 @@ public class MCRecipeManager implements IRecipeManager {
@Override
public void undo() {
for (int i = 0; i < removingIndices.size(); i++) {
for(int i = 0; i < removingIndices.size(); i++) {
int index = Math.min(recipes.size(), removingIndices.get(i));
recipes.add(index, removingRecipes.get(i));
}
@@ -383,7 +383,7 @@ public class MCRecipeManager implements IRecipeManager {
@Override
public void apply() {
recipes.add(recipe);
if (craftingRecipe.hasTransformers()) {
if(craftingRecipe.hasTransformers()) {
transformerRecipes.add(craftingRecipe);
}
}
@@ -396,7 +396,7 @@ public class MCRecipeManager implements IRecipeManager {
@Override
public void undo() {
recipes.remove(recipe);
if (craftingRecipe.hasTransformers()) {
if(craftingRecipe.hasTransformers()) {
transformerRecipes.remove(craftingRecipe);
}
}
@@ -28,6 +28,7 @@ import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.server.management.UserListOps;
import net.minecraft.tileentity.CommandBlockBaseLogic;
import net.minecraft.util.math.BlockPos;
import stanhebben.zenscript.annotations.Optional;
import java.util.Arrays;
import java.util.List;
@@ -43,13 +44,13 @@ public class MCServer extends AbstractServer {
}
private static IPlayer getPlayer(ICommandSender commandSender) {
if (commandSender instanceof EntityPlayer) {
if(commandSender instanceof EntityPlayer) {
return MineTweakerMC.getIPlayer((EntityPlayer) commandSender);
} else if (commandSender instanceof DedicatedServer) {
} else if(commandSender instanceof DedicatedServer) {
return ServerPlayer.INSTANCE;
} else if (commandSender instanceof RConConsoleSource) {
} else if(commandSender instanceof RConConsoleSource) {
return new RconPlayer(commandSender);
}else if(commandSender instanceof CommandBlockBaseLogic){
} else if(commandSender instanceof CommandBlockBaseLogic) {
return new CommandBlockPlayer(commandSender);
} else {
System.out.println("Unsupported command sender: " + commandSender);
@@ -59,7 +60,7 @@ public class MCServer extends AbstractServer {
}
@Override
public void addCommand(String name, String usage, String[] aliases, ICommandFunction function, ICommandValidator validator, ICommandTabCompletion completion) {
public void addCommand(String name, String usage, String[] aliases, ICommandFunction function, @Optional ICommandValidator validator, @Optional ICommandTabCompletion completion) {
ICommand command = new MCCommand(name, usage, aliases, function, validator, completion);
MineTweakerAPI.apply(new AddCommandAction(command));
@@ -67,11 +68,11 @@ public class MCServer extends AbstractServer {
@Override
public boolean isOp(IPlayer player) {
if (player == ServerPlayer.INSTANCE)
if(player == ServerPlayer.INSTANCE)
return true;
UserListOps ops = MineTweakerMod.server.getPlayerList().getOppedPlayers();
if (server.isDedicatedServer() && ops != null) {
if(server.isDedicatedServer() && ops != null) {
//TODO figure if this is correct
// return ops.func_152690_d() || ops.func_152700_a(player.getName()) != null || player instanceof RconPlayer;
return ops.isEmpty() || ops.getGameProfileFromName(player.getName()) != null || player instanceof RconPlayer;
@@ -124,7 +125,7 @@ public class MCServer extends AbstractServer {
@Override
public boolean checkPermission(MinecraftServer server, ICommandSender sender) {
if (validator == null) {
if(validator == null) {
return true;
} else {
return validator.canExecute(getPlayer(sender));
@@ -133,7 +134,7 @@ public class MCServer extends AbstractServer {
@Override
public List<String> getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) {
if (completion != null) {
if(completion != null) {
return Arrays.asList(completion.getTabCompletionOptions(args, getPlayer(sender)));
} else {
return null;
@@ -161,7 +162,7 @@ public class MCServer extends AbstractServer {
@Override
public void apply() {
CommandHandler ch = (CommandHandler) MineTweakerMod.server.getCommandManager();
if (!ch.getCommands().containsValue(command))
if(!ch.getCommands().containsValue(command))
ch.registerCommand(command);
}
@@ -178,7 +179,7 @@ public class MCServer extends AbstractServer {
@Override
public String describe() {
CommandHandler ch = (CommandHandler) MineTweakerMod.server.getCommandManager();
if (!ch.getCommands().containsValue(command))
if(!ch.getCommands().containsValue(command))
return "Adding command " + command.getCommandName();
return "";
}