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

This File gets a Refactoring,

that File gets a Refactoring,
everybody gets a Refactoring!
This commit is contained in:
TheBusyBiscuit 2019-08-27 16:26:35 +02:00
parent f4be2a8d5b
commit 04444fc298
14 changed files with 256 additions and 249 deletions

View File

@ -1,6 +1,7 @@
package me.mrCookieSlime.Slimefun.Objects;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@ -363,7 +364,7 @@ public class Research {
public static void sendStats(CommandSender sender, Player p) {
PlayerProfile profile = PlayerProfile.fromUUID(p.getUniqueId());
Set<Research> researched = profile.getResearches();
int levels = researched.stream().mapToInt(r -> r.getCost()).sum();
int levels = researched.stream().mapToInt(Research::getCost).sum();
String progress = String.valueOf(Math.round(((researched.size() * 100.0F) / list().size()) * 100.0F) / 100.0F);
if (Float.parseFloat(progress) < 16.0F) progress = "&4" + progress + " &r% ";
@ -392,7 +393,7 @@ public class Research {
* @see #sendStats(CommandSender, Player)
*/
@Deprecated
public static String getTitle(Player p, Set<Research> researched) {
public static String getTitle(Player p, Collection<Research> researched) {
int index = Math.round(Float.valueOf(String.valueOf(Math.round(((researched.size() * 100.0F) / list().size()) * 100.0F) / 100.0F)) / 100.0F) * titles.size();
if (index > 0) index--;
return titles.get(index);

View File

@ -43,6 +43,7 @@ public abstract class AFarm extends SlimefunItem {
@Override
public void newInstance(BlockMenu menu, Block b) {
}
@Override
@ -129,19 +130,14 @@ public abstract class AFarm extends SlimefunItem {
private void constructMenu(BlockMenuPreset preset) {
for (int i : border) {
preset.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " "),
(p, slot, item, action) -> false
);
}
for (int i : border_out) {
preset.addItem(i, new CustomItem(new ItemStack(Material.ORANGE_STAINED_GLASS_PANE), " "),
(p, slot, item, action) -> false
);
preset.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
}
preset.addItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "),
(p, slot, item, action) -> false
);
for (int i : border_out) {
preset.addItem(i, new CustomItem(new ItemStack(Material.ORANGE_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
}
preset.addItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
for (int i : getOutputSlots()) {
preset.addMenuClickHandler(i, new AdvancedMenuClickHandler() {
@ -173,16 +169,21 @@ public abstract class AFarm extends SlimefunItem {
if (ChargableBlock.isChargable(b)) {
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) return;
int i = getSize() / 2;
loop:
for (int x = -i; x <= i; x++) {
for (int z = -i; z <= i; z++) {
Block block = new Location(b.getWorld(), b.getX() + x, b.getY() + 2, b.getZ() + z).getBlock();
Block block = new Location(b.getWorld(), b.getX() + (double) x, b.getY() + 2.0, b.getZ() + (double) z).getBlock();
if (canHarvest(block)) {
ItemStack item = harvest(block);
if (!fits(block, new ItemStack[] {item})) break loop;
pushItems(b, new ItemStack[] {item});
if (!fits(block, item)) {
return;
}
pushItems(b, item);
ChargableBlock.addCharge(b, -getEnergyConsumption());
break loop;
return;
}
}
}
@ -223,11 +224,11 @@ public abstract class AFarm extends SlimefunItem {
return inv;
}
protected boolean fits(Block b, ItemStack[] items) {
protected boolean fits(Block b, ItemStack... items) {
return inject(b).addItem(items).isEmpty();
}
protected void pushItems(Block b, ItemStack[] items) {
protected void pushItems(Block b, ItemStack... items) {
Inventory inv = inject(b);
inv.addItem(items);

View File

@ -44,24 +44,29 @@ public class ReactorAccessPort extends SlimefunItem {
@Override
public void newInstance(BlockMenu menu, Block b) {
}
@Override
public boolean canOpen(Block b, Player p) {
if(p.hasPermission("slimefun.inventory.bypass") || CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(),b,true)) {
AReactor reactor = getReactor(b.getLocation());
if (reactor != null) {
boolean empty = true;
BlockMenu bm = getReactorMenu(b.getLocation());
if (bm != null) {
for(int slot:reactor.getCoolantSlots())
if(bm.getItemInSlot(slot) != null)
for (int slot: reactor.getCoolantSlots()) {
if (bm.getItemInSlot(slot) != null) {
empty = false;
for(int slot:reactor.getFuelSlots())
if(bm.getItemInSlot(slot) != null)
}
}
for (int slot: reactor.getFuelSlots()) {
if (bm.getItemInSlot(slot) != null) {
empty = false;
}
}
if(!empty || !p.isSneaking()) {
//reactor is not empty, lets view it's inventory instead.
@ -100,11 +105,13 @@ public class ReactorAccessPort extends SlimefunItem {
@Override
public void onPlace(Player p, Block b, SlimefunItem item) {
}
@Override
public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) {
BlockMenu inv = BlockStorage.getInventory(b);
if (inv != null) {
for (int slot : getFuelSlots()) {
if (inv.getItemInSlot(slot) != null) {
@ -112,12 +119,14 @@ public class ReactorAccessPort extends SlimefunItem {
inv.replaceExistingItem(slot, null);
}
}
for (int slot : getCoolantSlots()) {
if (inv.getItemInSlot(slot) != null) {
b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
inv.replaceExistingItem(slot, null);
}
}
for (int slot : getOutputSlots()) {
if (inv.getItemInSlot(slot) != null) {
b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
@ -132,44 +141,24 @@ public class ReactorAccessPort extends SlimefunItem {
private void constructMenu(BlockMenuPreset preset) {
for (int i : border) {
preset.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " "),
(p, slot, item, action) -> false
);
preset.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
}
for (int i : border_1) {
preset.addItem(i, new CustomItem(new ItemStack(Material.LIME_STAINED_GLASS_PANE), " "),
(p, slot, item, action) -> false
);
preset.addItem(i, new CustomItem(new ItemStack(Material.LIME_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
}
for (int i : border_2) {
preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "),
(p, slot, item, action) -> false
);
preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
}
for (int i : border_3) {
preset.addItem(i, new CustomItem(new ItemStack(Material.GREEN_STAINED_GLASS_PANE), " "),
(p, slot, item, action) -> false
);
preset.addItem(i, new CustomItem(new ItemStack(Material.GREEN_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
}
preset.addItem(1, new CustomItem(SlimefunItems.URANIUM, "&7Fuel Slot", "", "&rThis Slot accepts radioactive Fuel such as:", "&2Uranium &ror &aNeptunium"),
(p, slot, item, action) -> false
);
preset.addItem(22, new CustomItem(SlimefunItems.PLUTONIUM, "&7Byproduct Slot", "", "&rThis Slot contains the Reactor's Byproduct", "&rsuch as &aNeptunium &ror &7Plutonium"),
(p, slot, item, action) -> false
);
preset.addItem(7, new CustomItem(SlimefunItems.REACTOR_COOLANT_CELL, "&bCoolant Slot", "", "&rThis Slot accepts Coolant Cells", "&4Without any Coolant Cells, your Reactor", "&4will explode"),
(p, slot, item, action) -> false
);
preset.addItem(7, new CustomItem(SlimefunItems.REACTOR_COOLANT_CELL, "&bCoolant Slot", "", "&rThis Slot accepts Coolant Cells", "&4Without any Coolant Cells, your Reactor", "&4will explode"),
(p, slot, item, action) -> false
);
preset.addItem(1, new CustomItem(SlimefunItems.URANIUM, "&7Fuel Slot", "", "&rThis Slot accepts radioactive Fuel such as:", "&2Uranium &ror &aNeptunium"), (p, slot, item, action) -> false);
preset.addItem(22, new CustomItem(SlimefunItems.PLUTONIUM, "&7Byproduct Slot", "", "&rThis Slot contains the Reactor's Byproduct", "&rsuch as &aNeptunium &ror &7Plutonium"), (p, slot, item, action) -> false);
preset.addItem(7, new CustomItem(SlimefunItems.REACTOR_COOLANT_CELL, "&bCoolant Slot", "", "&rThis Slot accepts Coolant Cells", "&4Without any Coolant Cells, your Reactor", "&4will explode"),(p, slot, item, action) -> false);
}
public String getInventoryTitle() {
@ -196,8 +185,7 @@ public class ReactorAccessPort extends SlimefunItem {
Location reactorL = new Location(l.getWorld(), l.getX(), l.getY() - 3, l.getZ());
SlimefunItem item = BlockStorage.check(reactorL.getBlock());
if(item instanceof AReactor)
return (AReactor) item;
if (item instanceof AReactor) return (AReactor) item;
return null;
}
@ -207,8 +195,9 @@ public class ReactorAccessPort extends SlimefunItem {
String id = BlockStorage.checkID(reactorL);
if(id.equals("NUCLEAR_REACTOR") || id.equals("NETHERSTAR_REACTOR"))
if(id.equals("NUCLEAR_REACTOR") || id.equals("NETHERSTAR_REACTOR")) {
return BlockStorage.getInventory(reactorL);
}
return null;
}
@ -216,12 +205,15 @@ public class ReactorAccessPort extends SlimefunItem {
private static Inventory inject(Location l) {
int size = BlockStorage.getInventory(l).toInventory().getSize();
Inventory inv = Bukkit.createInventory(null, size);
for (int i = 0; i < size; i++) {
inv.setItem(i, new CustomItem(Material.COMMAND_BLOCK, " &4ALL YOUR PLACEHOLDERS ARE BELONG TO US"));
}
for (int slot : getOutputSlots()) {
inv.setItem(slot, BlockStorage.getInventory(l).getItemInSlot(slot));
}
return inv;
}
@ -233,10 +225,7 @@ public class ReactorAccessPort extends SlimefunItem {
BlockStorage.getInventory(l).replaceExistingItem(slot, inv.getItem(slot));
}
for (Map.Entry<Integer, ItemStack> entry: map.entrySet()) {
return entry.getValue();
}
return null;
return map.values().stream().findAny().orElse(null);
}
}

View File

@ -27,7 +27,7 @@ public class MagnetTask extends SlimefunTask {
@Override
protected boolean cancelTask() {
return super.cancelTask() ? true: p.getGameMode() == GameMode.SPECTATOR;
return super.cancelTask() || p.getGameMode() == GameMode.SPECTATOR;
}
}

View File

@ -721,6 +721,8 @@ public class SlimefunSetup {
new String[] {"chance.fireBreak"}, new Integer[] {34})
.register(true, new MultiBlockInteractionHandler() {
private final String chamberID = "IGNITION_CHAMBER";
@Override
public boolean onInteract(Player p, MultiBlock mb, Block b) {
@ -764,13 +766,17 @@ public class SlimefunSetup {
// The chamber methods have been updated to reflect this change.
// Maybe this code snippet should be turned into a loop?
Hopper chamber = null;
if (BlockStorage.check(dispBlock.getRelative(BlockFace.EAST).getState().getBlock(), "IGNITION_CHAMBER")) {
if (BlockStorage.check(dispBlock.getRelative(BlockFace.EAST).getState().getBlock(), chamberID)) {
chamber = (Hopper) dispBlock.getRelative(BlockFace.EAST).getState();
} else if (BlockStorage.check(dispBlock.getRelative(BlockFace.WEST).getState().getBlock(), "IGNITION_CHAMBER")) {
}
else if (BlockStorage.check(dispBlock.getRelative(BlockFace.WEST).getState().getBlock(), chamberID)) {
chamber = (Hopper) dispBlock.getRelative(BlockFace.WEST).getState();
} else if (BlockStorage.check(dispBlock.getRelative(BlockFace.NORTH).getState().getBlock(), "IGNITION_CHAMBER")) {
}
else if (BlockStorage.check(dispBlock.getRelative(BlockFace.NORTH).getState().getBlock(), chamberID)) {
chamber = (Hopper) dispBlock.getRelative(BlockFace.NORTH).getState();
} else if (BlockStorage.check(dispBlock.getRelative(BlockFace.SOUTH).getState().getBlock(), "IGNITION_CHAMBER")){
}
else if (BlockStorage.check(dispBlock.getRelative(BlockFace.SOUTH).getState().getBlock(), chamberID)){
chamber = (Hopper) dispBlock.getRelative(BlockFace.SOUTH).getState();
}
@ -1840,17 +1846,23 @@ public class SlimefunSetup {
@Override
public boolean onBlockBreak(BlockBreakEvent e, ItemStack item, int fortune, List<ItemStack> drops) {
if (SlimefunManager.isItemSimiliar(item, SlimefunItems.PICKAXE_OF_CONTAINMENT, true)) {
Block b = e.getBlock(); // Refactored it into this so we don't need to call e.getBlock() all the time.
// Refactored it into this so we don't need to call e.getBlock() all the time.
Block b = e.getBlock();
if (b.getType() != Material.SPAWNER) return true;
// If the spawner's BlockStorage has BlockInfo, then it's not a vanilla spawner and shouldn't give a broken spawner.
ItemStack spawner = SlimefunItems.BROKEN_SPAWNER.clone();
if(BlockStorage.hasBlockInfo(b))
if (BlockStorage.hasBlockInfo(b)) {
spawner = SlimefunItems.REPAIRED_SPAWNER.clone();
}
ItemMeta im = spawner.getItemMeta();
List<String> lore = im.getLore();
for (int i = 0; i < lore.size(); i++) {
if (lore.get(i).contains("<Type>")) lore.set(i, lore.get(i).replace("<Type>", StringUtils.format(((CreatureSpawner) b.getState()).getSpawnedType().toString())));
}
im.setLore(lore);
spawner.setItemMeta(im);
b.getLocation().getWorld().dropItemNaturally(b.getLocation(), spawner);
@ -3860,11 +3872,11 @@ public class SlimefunSetup {
public void tick(Block b, SlimefunItem item, Config data) {
int charge = ChargableBlock.getCharge(b.getLocation());
if (charge > 2) {
Slimefun.getGPSNetwork().updateTransmitter(new Location(b.getWorld(), b.getX(), b.getY() * 4 + 100, b.getZ()), UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")), NetworkStatus.ONLINE);
Slimefun.getGPSNetwork().updateTransmitter(new Location(b.getWorld(), b.getX(), b.getY() * 4.0 + 100, b.getZ()), UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")), NetworkStatus.ONLINE);
ChargableBlock.setCharge(b.getLocation(), charge - 3);
}
else {
Slimefun.getGPSNetwork().updateTransmitter(new Location(b.getWorld(), b.getX(), b.getY() * 4 + 100, b.getZ()), UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")), NetworkStatus.OFFLINE);
Slimefun.getGPSNetwork().updateTransmitter(new Location(b.getWorld(), b.getX(), b.getY() * 4.0 + 100, b.getZ()), UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")), NetworkStatus.OFFLINE);
}
}
@ -3887,7 +3899,7 @@ public class SlimefunSetup {
@Override
public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) {
Slimefun.getGPSNetwork().updateTransmitter(new Location(b.getWorld(), b.getX(), b.getY() * 4 + 100, b.getZ()), UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")), NetworkStatus.OFFLINE);
Slimefun.getGPSNetwork().updateTransmitter(new Location(b.getWorld(), b.getX(), b.getY() * 4.0 + 100, b.getZ()), UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")), NetworkStatus.OFFLINE);
return true;
}
});
@ -3900,11 +3912,11 @@ public class SlimefunSetup {
public void tick(Block b, SlimefunItem item, Config data) {
int charge = ChargableBlock.getCharge(b.getLocation());
if (charge > 10) {
Slimefun.getGPSNetwork().updateTransmitter(new Location(b.getWorld(), b.getX(), b.getY() * 16 + 500, b.getZ()), UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")), NetworkStatus.ONLINE);
Slimefun.getGPSNetwork().updateTransmitter(new Location(b.getWorld(), b.getX(), b.getY() * 16.0 + 500, b.getZ()), UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")), NetworkStatus.ONLINE);
ChargableBlock.setCharge(b.getLocation(), charge - 11);
}
else {
Slimefun.getGPSNetwork().updateTransmitter(new Location(b.getWorld(), b.getX(), b.getY() * 16 + 500, b.getZ()), UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")), NetworkStatus.OFFLINE);
Slimefun.getGPSNetwork().updateTransmitter(new Location(b.getWorld(), b.getX(), b.getY() * 16.0 + 500, b.getZ()), UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")), NetworkStatus.OFFLINE);
}
}
@ -3927,7 +3939,7 @@ public class SlimefunSetup {
@Override
public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) {
Slimefun.getGPSNetwork().updateTransmitter(new Location(b.getWorld(), b.getX(), b.getY() * 16 + 500, b.getZ()), UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")), NetworkStatus.OFFLINE);
Slimefun.getGPSNetwork().updateTransmitter(new Location(b.getWorld(), b.getX(), b.getY() * 16.0 + 500, b.getZ()), UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")), NetworkStatus.OFFLINE);
return true;
}
});
@ -3940,11 +3952,11 @@ public class SlimefunSetup {
public void tick(Block b, SlimefunItem item, Config data) {
int charge = ChargableBlock.getCharge(b.getLocation());
if (charge > 45) {
Slimefun.getGPSNetwork().updateTransmitter(new Location(b.getWorld(), b.getX(), b.getY() * 64 + 800, b.getZ()), UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")), NetworkStatus.ONLINE);
Slimefun.getGPSNetwork().updateTransmitter(new Location(b.getWorld(), b.getX(), b.getY() * 64.0 + 800, b.getZ()), UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")), NetworkStatus.ONLINE);
ChargableBlock.setCharge(b.getLocation(), charge - 46);
}
else {
Slimefun.getGPSNetwork().updateTransmitter(new Location(b.getWorld(), b.getX(), b.getY() * 64 + 800, b.getZ()), UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")), NetworkStatus.OFFLINE);
Slimefun.getGPSNetwork().updateTransmitter(new Location(b.getWorld(), b.getX(), b.getY() * 64.0 + 800, b.getZ()), UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")), NetworkStatus.OFFLINE);
}
}
@ -3967,7 +3979,7 @@ public class SlimefunSetup {
@Override
public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) {
Slimefun.getGPSNetwork().updateTransmitter(new Location(b.getWorld(), b.getX(), b.getY() * 64 + 800, b.getZ()), UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")), NetworkStatus.OFFLINE);
Slimefun.getGPSNetwork().updateTransmitter(new Location(b.getWorld(), b.getX(), b.getY() * 64.0 + 800, b.getZ()), UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")), NetworkStatus.OFFLINE);
return true;
}
});

View File

@ -95,6 +95,7 @@ public class SlimefunGuide {
return getItem(book ? BookDesign.BOOK: BookDesign.CHEST);
}
@Deprecated
public static ItemStack getDeprecatedItem(boolean book) {
return new CustomItem(new ItemStack(Material.ENCHANTED_BOOK), "&eSlimefun Guide &7(Right Click)", (book ? "": "&2"), "&rThis is your basic Guide for Slimefun", "&rYou can see all Items added by this Plugin", "&ror its Addons including their Recipes", "&ra bit of information and more");
}
@ -1018,7 +1019,7 @@ public class SlimefunGuide {
List<String> lore = new ArrayList<>();
lore.add(ChatColor.translateAlternateColorCodes('&', "&8\u21E8 &7Lasts " + getTimeLeft(fuel.getTicks() / 2)));
lore.add(ChatColor.translateAlternateColorCodes('&', "&8\u21E8 &e\u26A1 &7" + (((AGenerator) sfItem).getEnergyProduction() * 2) + " J/s"));
lore.add(ChatColor.translateAlternateColorCodes('&', "&8\u21E8 &e\u26A1 &7" + DoubleHandler.getFancyDouble(fuel.getTicks() * ((AGenerator) sfItem).getEnergyProduction()) + " J in total"));
lore.add(ChatColor.translateAlternateColorCodes('&', "&8\u21E8 &e\u26A1 &7" + DoubleHandler.getFancyDouble((double) fuel.getTicks() * ((AGenerator) sfItem).getEnergyProduction()) + " J in total"));
im.setLore(lore);
fItem.setItemMeta(im);
menu.addItem(slot, fItem);
@ -1037,7 +1038,7 @@ public class SlimefunGuide {
List<String> lore = new ArrayList<>();
lore.add(ChatColor.translateAlternateColorCodes('&', "&8\u21E8 &7Lasts " + getTimeLeft(fuel.getTicks() / 2)));
lore.add(ChatColor.translateAlternateColorCodes('&', "&8\u21E8 &e\u26A1 &7" + (((AReactor) sfItem).getEnergyProduction() * 2) + " J/s"));
lore.add(ChatColor.translateAlternateColorCodes('&', "&8\u21E8 &e\u26A1 &7" + DoubleHandler.getFancyDouble(fuel.getTicks() * ((AReactor) sfItem).getEnergyProduction()) + " J in total"));
lore.add(ChatColor.translateAlternateColorCodes('&', "&8\u21E8 &e\u26A1 &7" + DoubleHandler.getFancyDouble((double) fuel.getTicks() * ((AReactor) sfItem).getEnergyProduction()) + " J in total"));
im.setLore(lore);
fItem.setItemMeta(im);
menu.addItem(slot, fItem);

View File

@ -713,9 +713,16 @@ public abstract class ProgrammableAndroid extends SlimefunItem {
if (!blockblacklist.contains(block.getType()) && !drops.isEmpty() && CSCoreLib.getLib().getProtectionManager().canBuild(UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")), block)) {
SlimefunItem item = BlockStorage.check(block);
if (item != null) {
return;
/*if (fits(b, item.getItem())) {
if (item == null) {
ItemStack[] items = drops.toArray(new ItemStack[drops.size()]);
if (fits(b, items)) {
pushItems(b, items);
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType());
block.setType(Material.AIR);
}
}
/*
else if (fits(b, item.getItem())) {
if (SlimefunItem.blockhandler.containsKey(item.getID())) {
if (SlimefunItem.blockhandler.get(item.getID()).onBreak(null, block, item, UnregisterReason.ANDROID_DIG)) {
pushItems(b, BlockStorage.retrieve(block));
@ -725,14 +732,6 @@ public abstract class ProgrammableAndroid extends SlimefunItem {
}
}
}*/
} else {
ItemStack[] items = drops.toArray(new ItemStack[drops.size()]);
if (fits(b, items)) {
pushItems(b, items);
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType());
block.setType(Material.AIR);
}
}
}
}

View File

@ -610,6 +610,7 @@ public class BlockStorage {
public void clearInventory(Location l) {
BlockMenu menu = getInventory(l);
if (menu != null) {
for (HumanEntity human : new ArrayList<>(menu.toInventory().getViewers())) {
// Prevents "java.lang.IllegalStateException: Asynchronous entity add!" when closing inventory while holding an item
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, () -> {
@ -620,6 +621,7 @@ public class BlockStorage {
inventories.get(l).delete(l);
inventories.remove(l);
}
}
public boolean hasInventory(Location l) {
return inventories.containsKey(l);

View File

@ -24,13 +24,14 @@ public class ErrorReport {
private File file;
public ErrorReport(Throwable throwable, Consumer<PrintStream> printer) {
file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + ".err");
String path = "plugins/Slimefun/error-reports/" + Clock.getFormattedTime();
file = new File(path + ".err");
if (file.exists()) {
IntStream stream = IntStream.iterate(1, i -> i + 1).filter(i -> !new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(" + i + ").err").exists());
IntStream stream = IntStream.iterate(1, i -> i + 1).filter(i -> !new File(path + " (" + i + ").err").exists());
int id = stream.findFirst().getAsInt();
file = new File("plugins/Slimefun/error-reports/" + Clock.getFormattedTime() + "(" + id + ").err");
file = new File(path + " (" + id + ").err");
}
try (PrintStream stream = new PrintStream(file)) {

View File

@ -23,7 +23,7 @@ import me.mrCookieSlime.Slimefun.api.inventory.BackpackInventory;
* @author TheBusyBiscuit
*
*/
public class PlayerProfile {
public final class PlayerProfile {
public static Map<UUID, PlayerProfile> profiles = new HashMap<>();

View File

@ -8,7 +8,6 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.zip.ZipEntry;
@ -21,17 +20,14 @@ public class SlimefunBackup {
public static void start() {
File folder = new File("data-storage/Slimefun/block-backups");
List<File> backups = Arrays.asList(folder.listFiles());
if (backups.size() > 20) {
Collections.sort(backups, new Comparator<File>() {
@Override
public int compare(File f1, File f2) {
if (backups.size() > 20) {
Collections.sort(backups, (a, b) -> {
try {
return (int) (new SimpleDateFormat("yyyy-MM-dd-HH-mm").parse(f1.getName().replace(".zip", "")).getTime() - new SimpleDateFormat("yyyy-MM-dd-HH-mm").parse(f2.getName().replace(".zip", "")).getTime());
return (int) (new SimpleDateFormat("yyyy-MM-dd-HH-mm").parse(a.getName().replace(".zip", "")).getTime() - new SimpleDateFormat("yyyy-MM-dd-HH-mm").parse(b.getName().replace(".zip", "")).getTime());
} catch (ParseException e) {
return 0;
}
}
});
for (int i = backups.size() - 20; i > 0; i--) {
@ -49,20 +45,19 @@ public class SlimefunBackup {
try {
file.createNewFile();
ZipOutputStream output = new ZipOutputStream(new FileOutputStream(file));
try (ZipOutputStream output = new ZipOutputStream(new FileOutputStream(file))) {
for (File f1: new File("data-storage/Slimefun/stored-blocks/").listFiles()) {
for (File f: f1.listFiles()) {
ZipEntry entry = new ZipEntry("stored-blocks/" + f1.getName() + "/" + f.getName());
output.putNextEntry(entry);
FileInputStream input = new FileInputStream(f);
try (FileInputStream input = new FileInputStream(f)) {
int length;
while ((length = input.read(buffer)) > 0) {
output.write(buffer, 0, length);
}
}
input.close();
output.closeEntry();
}
}
@ -70,46 +65,48 @@ public class SlimefunBackup {
for (File f: new File("data-storage/Slimefun/universal-inventories/").listFiles()) {
ZipEntry entry = new ZipEntry("universal-inventories/" + f.getName());
output.putNextEntry(entry);
FileInputStream input = new FileInputStream(f);
try (FileInputStream input = new FileInputStream(f)) {
int length;
while ((length = input.read(buffer)) > 0) {
output.write(buffer, 0, length);
}
}
input.close();
output.closeEntry();
}
for (File f: new File("data-storage/Slimefun/stored-inventories/").listFiles()) {
ZipEntry entry = new ZipEntry("stored-inventories/" + f.getName());
output.putNextEntry(entry);
FileInputStream input = new FileInputStream(f);
try (FileInputStream input = new FileInputStream(f)) {
int length;
while ((length = input.read(buffer)) > 0) {
output.write(buffer, 0, length);
}
}
input.close();
output.closeEntry();
}
if (new File("data-storage/Slimefun/stored-chunks/chunks.sfc").exists()) {
File chunks = new File("data-storage/Slimefun/stored-chunks/chunks.sfc");
if (chunks.exists()) {
ZipEntry entry = new ZipEntry("stored-chunks/chunks.sfc");
output.putNextEntry(entry);
FileInputStream input = new FileInputStream(new File("data-storage/Slimefun/stored-chunks/chunks.sfc"));
try (FileInputStream input = new FileInputStream(chunks)) {
int length;
while ((length = input.read(buffer)) > 0) {
output.write(buffer, 0, length);
}
input.close();
output.closeEntry();
}
output.close();
output.closeEntry();
}
}
System.out.println("[Slimefun] Backed up Blocks to " + file.getName());
} catch(IOException e) {
e.printStackTrace();

View File

@ -97,9 +97,11 @@ public abstract class Network {
private Component getCurrentClassification(Location l) {
if(regulatorNodes.contains(l)) {
return Component.REGULATOR;
} else if(connectorNodes.contains(l)) {
}
else if(connectorNodes.contains(l)) {
return Component.CONNECTOR;
} else if(terminusNodes.contains(l)) {
}
else if(terminusNodes.contains(l)) {
return Component.TERMINUS;
}
return null;
@ -111,23 +113,29 @@ public abstract class Network {
Location l = nodeQueue.poll();
Component currentAssignment = getCurrentClassification(l);
Component classification = classifyLocation(l);
if (classification != currentAssignment) {
if (currentAssignment == Component.REGULATOR || currentAssignment == Component.CONNECTOR) {
// Requires a complete rebuild of the network, so we just throw the current one away.
unregisterNetwork(this);
return;
} else if(currentAssignment == Component.TERMINUS) {
}
else if (currentAssignment == Component.TERMINUS) {
terminusNodes.remove(l);
}
if (classification == Component.REGULATOR) {
regulatorNodes.add(l);
discoverNeighbors(l);
} else if(classification == Component.CONNECTOR) {
}
else if(classification == Component.CONNECTOR) {
connectorNodes.add(l);
discoverNeighbors(l);
} else if(classification == Component.TERMINUS) {
}
else if(classification == Component.TERMINUS) {
terminusNodes.add(l);
}
locationClassificationChange(l, currentAssignment, classification);
}
steps += 1;
@ -137,7 +145,7 @@ public abstract class Network {
}
}
private void discoverNeighbors(Location l, int xDiff, int yDiff, int zDiff) {
private void discoverNeighbors(Location l, double xDiff, double yDiff, double zDiff) {
for(int i = getRange() + 1; i > 0; i --) {
Location new_location = l.clone().add(i * xDiff, i * yDiff, i * zDiff);
addLocationToNetwork(new_location);
@ -145,12 +153,12 @@ public abstract class Network {
}
private void discoverNeighbors(Location l) {
discoverNeighbors(l, 1, 0, 0);
discoverNeighbors(l, -1, 0, 0);
discoverNeighbors(l, 0, 1, 0);
discoverNeighbors(l, 0, -1, 0);
discoverNeighbors(l, 0, 0, 1);
discoverNeighbors(l, 0, 0, -1);
discoverNeighbors(l, 1.0, 0.0, 0.0);
discoverNeighbors(l, -1.0, 0.0, 0.0);
discoverNeighbors(l, 0.0, 1.0, 0.0);
discoverNeighbors(l, 0.0, -1.0, 0.0);
discoverNeighbors(l, 0.0, 0.0, 1.0);
discoverNeighbors(l, 0.0, 0.0, -1.0);
}
public void display() {

View File

@ -41,11 +41,12 @@ public abstract class GitHubConnector {
connection.addRequestProperty("User-Agent", "Slimefun 4 GitHub Agent (by TheBusyBiscuit)");
connection.setDoOutput(true);
ReadableByteChannel rbc = Channels.newChannel(connection.getInputStream());
FileOutputStream fos = new FileOutputStream(file);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
try (ReadableByteChannel channel = Channels.newChannel(connection.getInputStream())) {
try (FileOutputStream stream = new FileOutputStream(file)) {
stream.getChannel().transferFrom(channel, 0, Long.MAX_VALUE);
this.parseData();
}
}
} catch (IOException e) {
if (SlimefunStartup.getCfg().getBoolean("options.print-out-github-data-retrieving")) System.err.println("[Slimefun - GitHub] ERROR - Could not connect to GitHub in time.");
@ -67,9 +68,7 @@ public abstract class GitHubConnector {
}
public void parseData() {
try {
BufferedReader reader = new BufferedReader(new FileReader(this.getFile()));
try (BufferedReader reader = new BufferedReader(new FileReader(this.getFile()))) {
String full = "";
String line;
@ -77,10 +76,7 @@ public abstract class GitHubConnector {
full = full + line;
}
reader.close();
JsonElement element = new JsonParser().parse(full);
this.onSuccess(element);
}
catch (IOException e) {

View File

@ -6,9 +6,9 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class IntegerFormat {
public final class IntegerFormat {
private static final SimpleDateFormat date_format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private IntegerFormat() {}
public static String formatBigNumber(int i) {
return NumberFormat.getNumberInstance(Locale.US).format(i);
@ -16,7 +16,7 @@ public class IntegerFormat {
public static Date parseGitHubDate(String str) {
try {
return date_format.parse(str.replace("T", " ").replace("Z", ""));
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(str.replace("T", " ").replace("Z", ""));
} catch (ParseException e) {
e.printStackTrace();
return null;