1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Merge pull request #659 from mrcoffee1026/master

Anvil / Broken Spawner patch, Further Fix for keep-inv flags, Soulbound Backpack Recipe fix
This commit is contained in:
TheBusyBiscuit 2018-04-24 11:24:29 +02:00 committed by GitHub
commit af9a09e2c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 83 additions and 13 deletions

View File

@ -38,7 +38,7 @@ public class ItemHash {
StringBuilder builder = new StringBuilder(LENGTH * 2);
for (char c: item.getHash().toCharArray()) {
builder.append('§');
builder.append('§');
builder.append(c);
}
@ -47,7 +47,7 @@ public class ItemHash {
public static SlimefunItem fromString(String input) {
if (input == null || input.length() != LENGTH * 2) return null;
String hex = input.replaceAll("§", "");
String hex = input.replaceAll("§", "");
if (hex.length() != LENGTH || !map.containsKey(hex)) return null;

View File

@ -11,6 +11,7 @@ import java.util.Set;
import me.mrCookieSlime.Slimefun.SlimefunStartup;
import me.mrCookieSlime.Slimefun.AncientAltar.AltarRecipe;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.Research;
import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler;
@ -328,12 +329,14 @@ public class SlimefunItem {
}
public static SlimefunItem getByItem(ItemStack item) {
if (item == null) return null;
if (item == null) return null;
if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BROKEN_SPAWNER, false)) return getByID("BROKEN_SPAWNER");
if (SlimefunManager.isItemSimiliar(item, SlimefunItems.REPAIRED_SPAWNER, false)) return getByID("REPAIRED_SPAWNER");
for (SlimefunItem sfi: items) {
if (sfi instanceof ChargableItem && SlimefunManager.isItemSimiliar(item, sfi.getItem(), false)) return sfi;
else if (sfi instanceof DamagableChargableItem && SlimefunManager.isItemSimiliar(item, sfi.getItem(), false)) return sfi;
else if (sfi instanceof ChargedItem && SlimefunManager.isItemSimiliar(item, sfi.getItem(), false)) return sfi;
else if (sfi instanceof SlimefunBackpack && SlimefunManager.isItemSimiliar(item, sfi.getItem(), false)) return sfi;
else if (sfi instanceof SlimefunBackpack && SlimefunManager.isItemSimiliar(item, sfi.getItem(), false)) return sfi;
else if (SlimefunManager.isItemSimiliar(item, sfi.getItem(), true)) return sfi;
}
return null;
@ -344,7 +347,7 @@ public class SlimefunItem {
if (this instanceof ChargableItem && SlimefunManager.isItemSimiliar(item, this.item, false)) return true;
else if (this instanceof DamagableChargableItem && SlimefunManager.isItemSimiliar(item, this.item, false)) return true;
else if (this instanceof ChargedItem && SlimefunManager.isItemSimiliar(item, this.item, false)) return true;
else return SlimefunManager.isItemSimiliar(item, this.item, true);
else return SlimefunManager.isItemSimiliar(item, this.item, true);
}
public void load() {

View File

@ -1158,8 +1158,16 @@ public class SlimefunSetup {
boolean craft = true;
for (int j = 0; j < inv.getContents().length; j++) {
if (!SlimefunManager.isItemSimiliar(inv.getContents()[j], inputs.get(i)[j], true)) {
craft = false;
break;
if (SlimefunItem.getByItem(inputs.get(i)[j]) instanceof SlimefunBackpack) {
if (!SlimefunManager.isItemSimiliar(inv.getContents()[j], inputs.get(i)[j], false)) {
craft = false;
break;
}
}
else {
craft = false;
break;
}
}
}
@ -1171,6 +1179,62 @@ public class SlimefunSetup {
inv2.setItem(j, inv.getContents()[j] != null ? (inv.getContents()[j].getAmount() > 1 ? new CustomItem(inv.getContents()[j], inv.getContents()[j].getAmount() - 1): null): null);
}
if (InvUtils.fits(inv2, adding)) {
SlimefunItem sfItem = SlimefunItem.getByItem(adding);
if (sfItem instanceof SlimefunBackpack) {
ItemStack backpack = null;
for (int j = 0; j < 9; j++) {
if (inv.getContents()[j] != null) {
if (inv.getContents()[j].getType() != Material.AIR) {
if (SlimefunItem.getByItem(inv.getContents()[j]) instanceof SlimefunBackpack) {
backpack = inv.getContents()[j];
break;
}
}
}
}
String id = "";
int size = ((SlimefunBackpack) sfItem).size;
if (backpack != null) {
for (String line: backpack.getItemMeta().getLore()) {
if (line.startsWith(ChatColor.translateAlternateColorCodes('&', "&7ID: ")) && line.contains("#")) {
id = line.replace(ChatColor.translateAlternateColorCodes('&', "&7ID: "), "");
Config cfg = new Config(new File("data-storage/Slimefun/Players/" + id.split("#")[0] + ".yml"));
cfg.setValue("backpacks." + id.split("#")[1] + ".size", size);
cfg.save();
break;
}
}
}
if (id.equals("")) {
for (int line = 0; line < adding.getItemMeta().getLore().size(); line++) {
if (adding.getItemMeta().getLore().get(line).equals(ChatColor.translateAlternateColorCodes('&', "&7ID: <ID>"))) {
ItemMeta im = adding.getItemMeta();
List<String> lore = im.getLore();
lore.set(line, lore.get(line).replace("<ID>", Backpacks.createBackpack(p, size)));
im.setLore(lore);
adding.setItemMeta(im);
break;
}
}
}
else {
for (int line = 0; line < adding.getItemMeta().getLore().size(); line++) {
if (adding.getItemMeta().getLore().get(line).equals(ChatColor.translateAlternateColorCodes('&', "&7ID: <ID>"))) {
ItemMeta im = adding.getItemMeta();
List<String> lore = im.getLore();
lore.set(line, lore.get(line).replace("<ID>", id));
im.setLore(lore);
adding.setItemMeta(im);
break;
}
}
}
}
for (int j = 0; j < 9; j++) {
if (inv.getContents()[j] != null) {
if (inv.getContents()[j].getType() != Material.AIR) {
@ -4625,7 +4689,7 @@ public class SlimefunSetup {
@Override
public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) {
return BlockStorage.getBlockInfo(b, "owner").equals(p.getUniqueId().toString());
return true;
}
});
@ -4661,11 +4725,8 @@ public class SlimefunSetup {
@Override
public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) {
if (BlockStorage.getBlockInfo(b, "owner").equals(p.getUniqueId().toString())) {
Projector.getArmorStand(b).remove();
return true;
}
else return false;
Projector.getArmorStand(b).remove();
return true;
}
});

View File

@ -21,6 +21,12 @@ public class Soul {
public static void retrieveItems(Player p) {
if (Variables.soulbound.containsKey(p.getUniqueId())) {
for (ItemStack item: Variables.soulbound.get(p.getUniqueId())) {
if (item.equals(p.getInventory().getHelmet())) continue;
if (item.equals(p.getInventory().getChestplate())) continue;
if (item.equals(p.getInventory().getLeggings())) continue;
if (item.equals(p.getInventory().getBoots())) continue;
if (item.equals(p.getInventory().getItemInOffHand())) continue;
if(!p.getInventory().contains(item)) {
p.getInventory().addItem(item);
}