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

Added CS-CoreLib permission check for Slimefun Machines

Removed the horrible whitespaces and updated the code to the last commit.
This commit is contained in:
Redemption 2018-04-25 11:18:49 +02:00 committed by GitHub
parent 827bc3c370
commit 3a0d73ae9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -692,7 +692,7 @@ public class SlimefunSetup {
public boolean onRightClick(ItemUseEvent e, Player p, ItemStack item) { public boolean onRightClick(ItemUseEvent e, Player p, ItemStack item) {
if (SlimefunManager.isItemSimiliar(item, SlimefunItems.GOLD_PAN, true)) { if (SlimefunManager.isItemSimiliar(item, SlimefunItems.GOLD_PAN, true)) {
if (e.getClickedBlock() != null && e.getClickedBlock().getType() == Material.GRAVEL) { if (e.getClickedBlock() != null && e.getClickedBlock().getType() == Material.GRAVEL) {
if(CSCoreLib.getLib().getProtectionManager().canBuild(p.getUniqueId(), e.getClickedBlock(), true)) { if (CSCoreLib.getLib().getProtectionManager().canBuild(p.getUniqueId(), e.getClickedBlock(), true)) {
List<ItemStack> drops = new ArrayList<ItemStack>(); List<ItemStack> drops = new ArrayList<ItemStack>();
if (SlimefunStartup.chance(100, (Integer) Slimefun.getItemValue("GOLD_PAN", "chance.SIFTED_ORE"))) drops.add(SlimefunItems.SIFTED_ORE); if (SlimefunStartup.chance(100, (Integer) Slimefun.getItemValue("GOLD_PAN", "chance.SIFTED_ORE"))) drops.add(SlimefunItems.SIFTED_ORE);
else if (SlimefunStartup.chance(100, (Integer) Slimefun.getItemValue("GOLD_PAN", "chance.CLAY"))) drops.add(new ItemStack(Material.CLAY_BALL)); else if (SlimefunStartup.chance(100, (Integer) Slimefun.getItemValue("GOLD_PAN", "chance.CLAY"))) drops.add(new ItemStack(Material.CLAY_BALL));
@ -1158,24 +1158,7 @@ public class SlimefunSetup {
SlimefunMachine machine = (SlimefunMachine) SlimefunItem.getByID("MAGIC_WORKBENCH"); SlimefunMachine machine = (SlimefunMachine) SlimefunItem.getByID("MAGIC_WORKBENCH");
if (mb.isMultiBlock(machine)) { if (mb.isMultiBlock(machine)) {
if(CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) { if(CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) {
if (Slimefun.hasUnlocked(p, machine.getItem(), true)) {
Dispenser disp = null;
if (b.getRelative(1, 0, 0).getType() == Material.DISPENSER) disp = (Dispenser) b.getRelative(1, 0, 0).getState();
else if (b.getRelative(0, 0, 1).getType() == Material.DISPENSER) disp = (Dispenser) b.getRelative(0, 0, 1).getState();
else if (b.getRelative(-1, 0, 0).getType() == Material.DISPENSER) disp = (Dispenser) b.getRelative(-1, 0, 0).getState();
else if (b.getRelative(0, 0, -1).getType() == Material.DISPENSER) disp = (Dispenser) b.getRelative(0, 0, -1).getState();
final Inventory inv = disp.getInventory();
List<ItemStack[]> inputs = RecipeType.getRecipeInputList(machine);
for (int i = 0; i < inputs.size(); i++) {
boolean craft = true;
for (int j = 0; j < inv.getContents().length; j++) {
if (!SlimefunManager.isItemSimiliar(inv.getContents()[j], inputs.get(i)[j], true)) {
if (Slimefun.hasUnlocked(p, machine.getItem(), true)) { if (Slimefun.hasUnlocked(p, machine.getItem(), true)) {
Dispenser disp = null; Dispenser disp = null;
@ -1198,26 +1181,10 @@ public class SlimefunSetup {
} }
} }
else { else {
craft = false; craft = false;
break; break;
} }
} }
if (craft) {
final ItemStack adding = RecipeType.getRecipeOutputList(machine, inputs.get(i));
if (Slimefun.hasUnlocked(p, adding, true)) {
Inventory inv2 = Bukkit.createInventory(null, 9, "test");
for (int j = 0; j < inv.getContents().length; j++) {
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)) {
for (int j = 0; j < 9; j++) {
if (inv.getContents()[j] != null) {
if (inv.getContents()[j].getType() != Material.AIR) {
if (inv.getContents()[j].getAmount() > 1) inv.setItem(j, new CustomItem(inv.getContents()[j], inv.getContents()[j].getAmount() - 1));
else inv.setItem(j, null);
} }
if (craft) { if (craft) {
@ -1289,7 +1256,7 @@ public class SlimefunSetup {
if (inv.getContents()[j].getType() != Material.AIR) { if (inv.getContents()[j].getType() != Material.AIR) {
if (inv.getContents()[j].getAmount() > 1) inv.setItem(j, new CustomItem(inv.getContents()[j], inv.getContents()[j].getAmount() - 1)); if (inv.getContents()[j].getAmount() > 1) inv.setItem(j, new CustomItem(inv.getContents()[j], inv.getContents()[j].getAmount() - 1));
else inv.setItem(j, null); else inv.setItem(j, null);
}
} }
} }
p.getWorld().playSound(b.getLocation(), Sound.BLOCK_WOOD_BUTTON_CLICK_ON, 1, 1); p.getWorld().playSound(b.getLocation(), Sound.BLOCK_WOOD_BUTTON_CLICK_ON, 1, 1);
@ -2285,8 +2252,8 @@ public class SlimefunSetup {
SlimefunItem sfItem = BlockStorage.check(b); SlimefunItem sfItem = BlockStorage.check(b);
boolean allow = true; boolean allow = true;
if (sfItem != null && !(sfItem instanceof HandledBlock)) { if (sfItem != null && !(sfItem instanceof HandledBlock)) {
if (SlimefunItem.blockhandler.containsKey(sfItem.getID())) { if (SlimefunItem.blockhandler.containsKey(sfItem.getName())) {
allow = SlimefunItem.blockhandler.get(sfItem.getID()).onBreak(e.getPlayer(), e.getBlock(), sfItem, UnregisterReason.PLAYER_BREAK); allow = SlimefunItem.blockhandler.get(sfItem.getName()).onBreak(e.getPlayer(), e.getBlock(), sfItem, UnregisterReason.PLAYER_BREAK);
} }
if (allow) { if (allow) {
drops.add(BlockStorage.retrieve(e.getBlock())); drops.add(BlockStorage.retrieve(e.getBlock()));
@ -2988,10 +2955,10 @@ public class SlimefunSetup {
SlimefunItem sfItem = SlimefunItem.getByItem(e.getItem()); SlimefunItem sfItem = SlimefunItem.getByItem(e.getItem());
if (sfItem != null) { if (sfItem != null) {
if (!SlimefunItem.blockhandler.containsKey(sfItem.getID())) { if (!SlimefunItem.blockhandler.containsKey(sfItem.getName())) {
block.setType(e.getItem().getType()); block.setType(e.getItem().getType());
block.setData(e.getItem().getData().getData()); block.setData(e.getItem().getData().getData());
BlockStorage.store(block, sfItem.getID()); BlockStorage.store(block, sfItem.getName());
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, e.getItem().getType()); block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, e.getItem().getType());
if (d.getInventory().containsAtLeast(e.getItem(), 2)) d.getInventory().removeItem(new CustomItem(e.getItem(), 1)); if (d.getInventory().containsAtLeast(e.getItem(), 2)) d.getInventory().removeItem(new CustomItem(e.getItem(), 1));
else { else {
@ -4174,7 +4141,7 @@ public class SlimefunSetup {
public boolean onRightClick(ItemUseEvent e, Player p, ItemStack stack) { public boolean onRightClick(ItemUseEvent e, Player p, ItemStack stack) {
if (e.getClickedBlock() == null) return false; if (e.getClickedBlock() == null) return false;
SlimefunItem item = BlockStorage.check(e.getClickedBlock()); SlimefunItem item = BlockStorage.check(e.getClickedBlock());
if (item == null || !item.getID().equals("GPS_CONTROL_PANEL")) return false; if (item == null || !item.getName().equals("GPS_CONTROL_PANEL")) return false;
e.setCancelled(true); e.setCancelled(true);
try { try {
Slimefun.getGPSNetwork().openTransmitterControlPanel(p); Slimefun.getGPSNetwork().openTransmitterControlPanel(p);
@ -4608,7 +4575,7 @@ public class SlimefunSetup {
public boolean onRightClick(ItemUseEvent e, Player p, ItemStack stack) { public boolean onRightClick(ItemUseEvent e, Player p, ItemStack stack) {
if (e.getClickedBlock() == null) return false; if (e.getClickedBlock() == null) return false;
SlimefunItem item = BlockStorage.check(e.getClickedBlock()); SlimefunItem item = BlockStorage.check(e.getClickedBlock());
if (item == null || !item.getID().equals("GPS_GEO_SCANNER")) return false; if (item == null || !item.getName().equals("GPS_GEO_SCANNER")) return false;
e.setCancelled(true); e.setCancelled(true);
try { try {
Slimefun.getGPSNetwork().scanChunk(p, e.getClickedBlock().getChunk()); Slimefun.getGPSNetwork().scanChunk(p, e.getClickedBlock().getChunk());
@ -4770,7 +4737,7 @@ public class SlimefunSetup {
public boolean onRightClick(ItemUseEvent e, Player p, ItemStack stack) { public boolean onRightClick(ItemUseEvent e, Player p, ItemStack stack) {
if (e.getClickedBlock() == null) return false; if (e.getClickedBlock() == null) return false;
SlimefunItem item = BlockStorage.check(e.getClickedBlock()); SlimefunItem item = BlockStorage.check(e.getClickedBlock());
if (item == null || !item.getID().equals("HOLOGRAM_PROJECTOR")) return false; if (item == null || !item.getName().equals("HOLOGRAM_PROJECTOR")) return false;
e.setCancelled(true); e.setCancelled(true);
if (BlockStorage.getBlockInfo(e.getClickedBlock(), "owner").equals(p.getUniqueId().toString())) { if (BlockStorage.getBlockInfo(e.getClickedBlock(), "owner").equals(p.getUniqueId().toString())) {
@ -4874,7 +4841,7 @@ public class SlimefunSetup {
if (e.getClickedBlock() == null) return false; if (e.getClickedBlock() == null) return false;
SlimefunItem item = BlockStorage.check(e.getClickedBlock()); SlimefunItem item = BlockStorage.check(e.getClickedBlock());
if (item == null) return false; if (item == null) return false;
if (!item.getID().equals("ELEVATOR_PLATE")) return false; if (!item.getName().equals("ELEVATOR_PLATE")) return false;
if (BlockStorage.getBlockInfo(e.getClickedBlock(), "owner").equals(p.getUniqueId().toString())) Elevator.openEditor(p, e.getClickedBlock()); if (BlockStorage.getBlockInfo(e.getClickedBlock(), "owner").equals(p.getUniqueId().toString())) Elevator.openEditor(p, e.getClickedBlock());
return true; return true;
@ -5293,7 +5260,7 @@ public class SlimefunSetup {
public boolean onRightClick(ItemUseEvent e, Player p, ItemStack stack) { public boolean onRightClick(ItemUseEvent e, Player p, ItemStack stack) {
if (e.getClickedBlock() == null) return false; if (e.getClickedBlock() == null) return false;
SlimefunItem item = BlockStorage.check(e.getClickedBlock()); SlimefunItem item = BlockStorage.check(e.getClickedBlock());
if (item == null || !item.getID().equals("CARGO_MANAGER")) return false; if (item == null || !item.getName().equals("CARGO_MANAGER")) return false;
e.setCancelled(true); e.setCancelled(true);
if (BlockStorage.getBlockInfo(e.getClickedBlock(), "visualizer") == null) { if (BlockStorage.getBlockInfo(e.getClickedBlock(), "visualizer") == null) {
@ -5330,7 +5297,7 @@ public class SlimefunSetup {
if (e.getClickedBlock() == null) return false; if (e.getClickedBlock() == null) return false;
SlimefunItem item = BlockStorage.check(e.getClickedBlock()); SlimefunItem item = BlockStorage.check(e.getClickedBlock());
if (item == null) return false; if (item == null) return false;
if (!item.getID().equals("CARGO_NODE")) return false; if (!item.getName().equals("CARGO_NODE")) return false;
if (CargoNet.isConnected(e.getClickedBlock())) { if (CargoNet.isConnected(e.getClickedBlock())) {
p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7Connected: " + "&2\u2714")); p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7Connected: " + "&2\u2714"));