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

[Ci skip] Added a small failsafe

This commit is contained in:
TheBusyBiscuit 2020-03-27 08:39:27 +01:00
parent de9039e6db
commit 1cd84ff17a

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.logging.Level;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -257,17 +258,23 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
else { else {
menu.addItem(index, sfitem.getItem()); menu.addItem(index, sfitem.getItem());
menu.addMenuClickHandler(index, (pl, slot, item, action) -> { menu.addMenuClickHandler(index, (pl, slot, item, action) -> {
if (survival) { try {
displayItem(profile, sfitem, true); if (survival) {
} displayItem(profile, sfitem, true);
else {
if (sfitem instanceof MultiBlockMachine) {
SlimefunPlugin.getLocal().sendMessage(pl, "guide.cheat.no-multiblocks");
} }
else { else {
pl.getInventory().addItem(sfitem.getItem().clone()); if (sfitem instanceof MultiBlockMachine) {
SlimefunPlugin.getLocal().sendMessage(pl, "guide.cheat.no-multiblocks");
}
else {
pl.getInventory().addItem(sfitem.getItem().clone());
}
} }
} }
catch (RuntimeException x) {
printErrorMessage(pl, x);
}
return false; return false;
}); });
@ -320,11 +327,16 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
menu.addItem(index, itemstack); menu.addItem(index, itemstack);
menu.addMenuClickHandler(index, (pl, slot, itm, action) -> { menu.addMenuClickHandler(index, (pl, slot, itm, action) -> {
if (!survival) { try {
pl.getInventory().addItem(item.getItem().clone()); if (!survival) {
pl.getInventory().addItem(item.getItem().clone());
}
else {
displayItem(profile, item, true);
}
} }
else { catch (RuntimeException x) {
displayItem(profile, item, true); printErrorMessage(pl, x);
} }
return false; return false;
@ -486,7 +498,14 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
addBackButton(menu, 0, p, profile, true); addBackButton(menu, 0, p, profile, true);
MenuClickHandler clickHandler = (pl, slot, itemstack, action) -> { MenuClickHandler clickHandler = (pl, slot, itemstack, action) -> {
displayItem(profile, itemstack, 0, true); try {
if (itemstack.getType() != Material.BARRIER) {
displayItem(profile, itemstack, 0, true);
}
}
catch (RuntimeException x) {
printErrorMessage(pl, x);
}
return false; return false;
}; };
@ -661,4 +680,9 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
return menu; return menu;
} }
private void printErrorMessage(Player p, RuntimeException x) {
p.sendMessage(ChatColor.DARK_RED + "An internal server error has occured. Please inform an admin, check the console for further info.");
Slimefun.getLogger().log(Level.SEVERE, "An error has occured while trying to open a SlimefunItem in the guide!");
}
} }