I have a plugin where I made a custom recipe for mending, everything works great, but I can't use this custom crafted book in the anvil. I think it's because of the ItemMeta, I'm relatively clueless and have already googled, but no result. I ask for help and thanks in advance.
ItemStack mending = new ItemStack(Material.ENCHANTED_BOOK, 1);
EnchantmentStorageMeta esm = (EnchantmentStorageMeta)mending.getItemMeta();
esm.addStoredEnchant(Enchantment.MENDING, 1, false);
mending.setItemMeta(esm);
ShapedRecipe mendingRecipe = new ShapedRecipe(mending);
mendingRecipe.shape(new String[]{"ABA", "CDC", "ABA"});
mendingRecipe.setIngredient('A', Material.BOOK);
mendingRecipe.setIngredient('B', Material.DIAMOND_BLOCK);
mendingRecipe.setIngredient('C', Material.EMERALD_BLOCK);
mendingRecipe.setIngredient('D', Material.NETHER_STAR);
Bukkit.getServer().addRecipe(mendingRecipe);
I've already tried to make an extra Anvil recipe but that didn't work.
Related
I'm attempting to update and ArrayList with new data - however when I attempt to do so - the previous data is overwritten and the new data is never appended to the list and I'm unsure why.
if (keylist.contains(item) && !value.equals("start") && !value.equals("stop") && !value.equals("done")){
final Integer number = keylist.indexOf(item);
this.runOnUiThread(new Runnable() {
#Override
public void run() {
// GET PREVIOUS VALUES
String previous_key = App.sharedPrefs.getString(LIVE_VIEW_KEY, null);
String previous_value = App.sharedPrefs.getString(LIVE_VIEW_VALUE, null);
// ADD NEW AND OLD VALUES TO LIST
mCallElements.clear();
mCallElements.add(new CallElement(previous_key, previous_value));
mCallElements.add(new CallElement(valuelist.get(number), value));
mAdapter.notifyDataSetChanged();
// SAVE NEW VALUES
final SharedPreferences.Editor editor = App.sharedPrefs.edit();
editor.putString(LIVE_VIEW_KEY, valuelist.get(number));
editor.putString(LIVE_VIEW_VALUE, value);
editor.apply();
}
});
}
P.S.
This is part of a Twilio chat implementation - full source can be seen here: https://pastebin.com/imNQdCJ0
You're clearing the ArrayList with .clear() and then calling .notifyDataSetChanged(). This clears the last set of data, and then forces the Adapter to completely reload.
To make your life as a developer significantly easier, I would recommend using DiffUtil. This calculates the difference between two lists, and deals with the changes for you. A really good tutorial on how to implement this can be found on CodePath: https://guides.codepath.com/android/using-the-recyclerview#diffing-larger-changes
The Android Documentation says:
'rely on notifyDataSetChanged() as a last resort'
But because of DiffUtil you don't have to care anymore.
I think if you just want to add new data to the old data,you do not need to use mCallElements.clear(),if the notifydatachanged still doesn't update the data, I think you need to check if your ArrayList is the same object.I hope my answer will help you
Background
I am trying to create an immutable object that contains a list of immutable objects, as well as object type totals within the list.
I created a slightly sudo gist to try and show what I mean.
Gist - Adjusting an immutable object that contains an immutable object list.
Explanation
My example shows how I'm currently doing it, it does work. However not for all cases.
My VeggieCartView will have a recyclerview that gets filled with a new/saved VeggieCart.
Each VeggieCart has a list of veggies. Veggie totals etc...
I then have a helper class VeggieChanger, it contains an rx.Consumer<Veggie[]> that gets set and accepts any 1:1 veggie changes from the veggie views.
The VeggieCartView sets the consumer so when any one veggie changes, it creates an updated cart using the changes' corresponding cart factory method. The adapter is used to change/retrieve its list.
Working and not
This works well for changing one at a time, however batching changes is throwing concurrency exceptions.
I realize my gist is not runnable and doesn't show most boilerplate, and that I may be fundamentally wrong with some or all of my approaches. With that said I still hope someone can give me advice on how to better implement what I'm trying to do.
If more information is needed to understand, please ask. Thank you for anybody who does have help to offer,
Jon.
I ended up figuring out my main issue.
By adding this to my VeggieCartView:
public void bagAllCanned() {
final Veggie[] canned = new Veggie[cart.canTotal()];
final Veggie[] bagged = new Veggie[canned.length];
int t = 0;
final List<Veggie> veggies = cart.veggies();
for (int i = 0; i < veggies.size(); i++) {
final Veggie veggie = veggies.get(i);
if (veggie.canned()) {
canned[t] = veggie;
if (veggie instanceof Potato)
bagged[t] = Potato.can(veggie);
else if (veggie instanceof Tomato)
bagged[t] = Tomato.can(veggie);
t++;
}
}
for (int i = 0; i < canned.length; i++) {
veggieChange(canned[i], bagged[i]);
}
}
It fixes the concurrency errors.
I'm still unsure if my approach is correct or not. So even though the question is mostly answered, opinions are still VERY welcome.
I am using the Microsoft Dynamics CRM, using the Java API generated as per their tutorial and SDK downloads.
I can create, delete, and update entities with no problems.
I am now at the stage where I need to set entities to active or inactive.
I had thought that the right way to do this was roughly
public void doIt(OrganisationServicesStub stub, OptionSetValue stateValue, OptionSetValue statusValue)
{
Guid g = new Guid();
g.setGuid("abc-def-ghijkl");
Entity updateMe = new Entity();
updateMe.setId(g);
updateMe.setLogicalName("ei_teacherdetails");
AttributeCollection updateCollection = new AttributeCollection();
updateCollection.addKeyValuePairOfstringanyType(pair("statecode", stateValue));
updateCollection.addKeyValuePairOfstringanyType(pair("statuscode", statusValue));
updateMe.setAttributes(updateCollection);
update.setEntity(updateMe);
stub.update(update);
}
public static KeyValuePairOfstringanyType pair(String key, Object value)
{
KeyValuePairOfstringanyType attr = new KeyValuePairOfstringanyType();
attr.setKey(key);
attr.setValue(value);
return attr;
}
The above code has been tested and works for updating any attributes except the state/status ones. When I try the above code, however, (i.e. the code that tries to update the state/status), I get the following error (calling with state/status values of 1 and 2 respectively. I got those values by looking at existing Invalid entries in the CRM dumped through the same api, so I am (almost) certain that they are correct.
org.apache.axis2.AxisFault: 2 is not a valid status code for state code ei_teacherdetailsState.Active
I have noticed that in other languages, there is a SetState request, but I don't find a similar one in Java.
If anyone has been down this path before me, I'd greatly appreciate any assistance you could give.
It turns out that the correct answer is as follows, as best I can tell....
private void doIt(OrganizationServiceStub stub, OptionSetValue state, OptionSetValue status)
{
OrganizationRequest request = new OrganizationRequest();
request.setRequestName("SetState");
ParameterCollection collection = new ParameterCollection();
collection.addKeyValuePairOfstringanyType(pair("State", state));
collection.addKeyValuePairOfstringanyType(pair("Status", status));
request.setParameters(collection);
Guid g = new Guid();
g.setGuid("abc0def-ghi");
EntityReference ref = new EntityReference();
ref.setId(g);
ref.setLogicalName("ei_teacherdetails");
collection.addKeyValuePairOfstringanyType(pair("EntityMoniker", ref));
Execute exe = new Execute();
exe.setRequest(request);
stub.execute(exe);
}
Which is pretty obscure, I think. Especially I like that there's a parameter called "EntryMoniker". Anyway, I leave this answer here just in case some other poor soul ends up having to deal with this MS CRM intricacy.
I am new to ATg commerce world and was wondering if someone can help me with an issue. We have Additional properties for our CommerceItem. Once a user logs into our website, these additional properties of the commerceItem are not getting copied over. Can someone advise or give an example as to how can i make sure that the properties are copied over?
Below is a snippet of my code:
CommerceItem sourceCitem;
CommerceItem destCitem;
List citemList = pSrcOrder.getCommerceItems(); //get commerce item from source order
for (int i = 0, citemListSize = citemList .size(); i < citemListSize; i++) {
sourceCitem= (CommerceItem) ciList.get(i);
destCitem= getCommerceItemManager().mergeOrdersCopyCommerceItem(pSrcOrder,pDestOrder, sourceCitem);
I extended CommerceItemImpl and added all additional properties in the new class which are not getting added to destCitem.
Any help will be appreciated.
Thanks
You need to subclass CommerceItemManager and override the mergeOrdersCopyCommerceItem method to first call the superclass method to do the basic copy and then copy your extended commerce item data.
For e.g:
protected CommerceItem mergeOrdersCopyCommerceItem(Order pSrcOrder, Order pDstOrder, CommerceItem pItem) throws CommerceException {
NewCommerceItem item = (NewCommerceItem) pItem;
NewCommerceItem newItem = (NewCommerceItem) super.mergeOrdersCopyCommerceItem(pSrcOrder, pDstOrder, pItem);
//Now your code to add the changes.
newItem.setABC(item.getABC());
return newItem;
}
And, as the change you have already done, so it's all we need.
I couldn't quite get this to work, and the examples I found only worked with a single RowFilter.andFilter or a RowFilter.orFilter. Is there a way to combine two to get something like (A || B) && (C || D)? Below is some sample code of what I'm attempting.
ArrayList<RowFilter<Object,Object>> arrLstColorFilters = new ArrayList<RowFilter<Object,Object>>();
ArrayList<RowFilter<Object,Object>> arrLstCandyFilters = new ArrayList<RowFilter<Object,Object>>();
RowFilter<Object,Object> colorFilter;
RowFilter<Object,Object> candyFilter;
TableRowSorter<TableModel> sorter;
// OR colors
RowFilter<Object,Object> blueFilter = RowFilter.regexFilter("Blue", myTable.getColumnModel().getColumnIndex("Color"));
RowFilter<Object,Object> redFilter = RowFilter.regexFilter("Red", myTable.getColumnModel().getColumnIndex("Color"));
arrLstColorFilters.add(redFilter);
arrLstColorFilters.add(blueFilter);
colorFilter = RowFilter.orFilter(arrLstColorFilters);
// OR candies
RowFilter<Object,Object> mAndMFilter = RowFilter.regexFilter("M&M", myTable.getColumnModel().getColumnIndex("Candy"));
RowFilter<Object,Object> mentosFilter = RowFilter.regexFilter("Mentos", myTable.getColumnModel().getColumnIndex("Candy"));
arrLstCandyFilters.add(mAndMFilter);
arrLstCandyFilters.add(mentosFilter);
candyFilter = RowFilter.orFilter(arrLstCandyFilters);
// Mentos and M&Ms that are red or blue (this is where I'm stuck)
sorter.setRowFilter(RowFilter.andFilter(candyFilter, colorFilter); //this does not work
If someone could provide a working snippet for what I'm trying to do in the last line, it'd be much appreciated. Currently maintaining two separate table models to circumvent this problem, and I'd like to avoid duplicating data.
Thanks,
Kai
Your last line doesn't even compile, because andFilter also requires a list instead of separate arguments.
Otherwise your example seem to work find in my tests. I replaced the last line in your example with the following code:
ArrayList<RowFilter<Object, Object>> andFilters = new ArrayList<RowFilter<Object, Object>>();
andFilters.add(candyFilter);
andFilters.add(colorFilter);
sorter = new TableRowSorter<TableModel>(myTable.getModel());
// Mentos and M&Ms that are red or blue
sorter.setRowFilter(RowFilter.andFilter(andFilters));
myTable.setRowSorter(sorter);
Please make sure that you initialize the TableRowSorter with the appropriate table model.