fix custom crafting

This commit is contained in:
cswhite2000 2017-08-01 01:28:00 -07:00
parent a08b8e178e
commit c66a2de7bb
2 changed files with 21 additions and 7 deletions

View File

@ -1,15 +1,21 @@
package tc.oc.pgm.crafting;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.bukkit.Server;
import org.bukkit.inventory.Recipe;
import tc.oc.pgm.match.Match;
import tc.oc.pgm.match.MatchModule;
import tc.oc.pgm.utils.MaterialPattern;
import javax.inject.Inject;
public class CraftingMatchModule extends MatchModule {
@Inject private Server server;
private final Set<Recipe> customRecipes;
private final Set<MaterialPattern> disabledRecipes;
@ -23,18 +29,27 @@ public class CraftingMatchModule extends MatchModule {
public void enable() {
super.enable();
for(Iterator<Recipe> iter = getMatch().getServer().recipeIterator(); iter.hasNext();) {
List<Recipe> recipes = new ArrayList<>();
for(Iterator<Recipe> iter = server.recipeIterator(); iter.hasNext();) {
Recipe recipe = iter.next();
boolean add = true;
for(MaterialPattern result : disabledRecipes) {
if(result.matches(recipe.getResult())) {
iter.remove();
add = false;
break;
}
}
if (add) {
recipes.add(recipe);
}
}
for (Recipe recipe: customRecipes) {
recipes.add(recipe);
}
server.clearRecipes();
for(Recipe recipe : customRecipes) {
getMatch().getServer().addRecipe(recipe);
for(Recipe recipe : recipes) {
server.addRecipe(recipe);
}
}
@ -43,7 +58,7 @@ public class CraftingMatchModule extends MatchModule {
// Recipe changes affect all worlds on the server, so we make changes at match start/end
// to avoid interfering with adjacent matches. If we wait until unload() to reset them,
// the next match would already be loaded.
getMatch().getServer().resetRecipes();
server.resetRecipes();
super.disable();
}
}

View File

@ -84,8 +84,7 @@ public class CraftingModule implements MapModule, MatchModuleFactory<CraftingMat
}
}
//return customRecipes.isEmpty() && disabledRecipes.isEmpty() ? null : new CraftingModule(customRecipes, disabledRecipes);
return null;
return customRecipes.isEmpty() && disabledRecipes.isEmpty() ? null : new CraftingModule(customRecipes, disabledRecipes);
}
private ItemStack parseRecipeResult(MapModuleContext context, Element elRecipe) throws InvalidXMLException {