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:
parent
f4be2a8d5b
commit
04444fc298
@ -1,6 +1,7 @@
|
|||||||
package me.mrCookieSlime.Slimefun.Objects;
|
package me.mrCookieSlime.Slimefun.Objects;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -363,7 +364,7 @@ public class Research {
|
|||||||
public static void sendStats(CommandSender sender, Player p) {
|
public static void sendStats(CommandSender sender, Player p) {
|
||||||
PlayerProfile profile = PlayerProfile.fromUUID(p.getUniqueId());
|
PlayerProfile profile = PlayerProfile.fromUUID(p.getUniqueId());
|
||||||
Set<Research> researched = profile.getResearches();
|
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);
|
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% ";
|
if (Float.parseFloat(progress) < 16.0F) progress = "&4" + progress + " &r% ";
|
||||||
@ -392,7 +393,7 @@ public class Research {
|
|||||||
* @see #sendStats(CommandSender, Player)
|
* @see #sendStats(CommandSender, Player)
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@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();
|
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--;
|
if (index > 0) index--;
|
||||||
return titles.get(index);
|
return titles.get(index);
|
||||||
|
@ -43,6 +43,7 @@ public abstract class AFarm extends SlimefunItem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void newInstance(BlockMenu menu, Block b) {
|
public void newInstance(BlockMenu menu, Block b) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -129,19 +130,14 @@ public abstract class AFarm extends SlimefunItem {
|
|||||||
|
|
||||||
private void constructMenu(BlockMenuPreset preset) {
|
private void constructMenu(BlockMenuPreset preset) {
|
||||||
for (int i : border) {
|
for (int i : border) {
|
||||||
preset.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " "),
|
preset.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
|
||||||
(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), " "),
|
for (int i : border_out) {
|
||||||
(p, slot, item, action) -> false
|
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()) {
|
for (int i : getOutputSlots()) {
|
||||||
preset.addMenuClickHandler(i, new AdvancedMenuClickHandler() {
|
preset.addMenuClickHandler(i, new AdvancedMenuClickHandler() {
|
||||||
@ -173,19 +169,24 @@ public abstract class AFarm extends SlimefunItem {
|
|||||||
if (ChargableBlock.isChargable(b)) {
|
if (ChargableBlock.isChargable(b)) {
|
||||||
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) return;
|
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) return;
|
||||||
int i = getSize() / 2;
|
int i = getSize() / 2;
|
||||||
loop:
|
|
||||||
for (int x = -i; x <= i; x++) {
|
for (int x = -i; x <= i; x++) {
|
||||||
for (int z = -i; z <= i; z++) {
|
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)) {
|
if (canHarvest(block)) {
|
||||||
ItemStack item = harvest(block);
|
ItemStack item = harvest(block);
|
||||||
if (!fits(block, new ItemStack[] {item})) break loop;
|
|
||||||
pushItems(b, new ItemStack[] {item});
|
if (!fits(block, item)) {
|
||||||
ChargableBlock.addCharge(b, -getEnergyConsumption());
|
return;
|
||||||
break loop;
|
}
|
||||||
}
|
|
||||||
}
|
pushItems(b, item);
|
||||||
}
|
ChargableBlock.addCharge(b, -getEnergyConsumption());
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,11 +224,11 @@ public abstract class AFarm extends SlimefunItem {
|
|||||||
return inv;
|
return inv;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean fits(Block b, ItemStack[] items) {
|
protected boolean fits(Block b, ItemStack... items) {
|
||||||
return inject(b).addItem(items).isEmpty();
|
return inject(b).addItem(items).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void pushItems(Block b, ItemStack[] items) {
|
protected void pushItems(Block b, ItemStack... items) {
|
||||||
Inventory inv = inject(b);
|
Inventory inv = inject(b);
|
||||||
inv.addItem(items);
|
inv.addItem(items);
|
||||||
|
|
||||||
|
@ -44,24 +44,29 @@ public class ReactorAccessPort extends SlimefunItem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void newInstance(BlockMenu menu, Block b) {
|
public void newInstance(BlockMenu menu, Block b) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canOpen(Block b, Player p) {
|
public boolean canOpen(Block b, Player p) {
|
||||||
if(p.hasPermission("slimefun.inventory.bypass") || CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(),b,true)) {
|
if(p.hasPermission("slimefun.inventory.bypass") || CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(),b,true)) {
|
||||||
|
|
||||||
|
|
||||||
AReactor reactor = getReactor(b.getLocation());
|
AReactor reactor = getReactor(b.getLocation());
|
||||||
if(reactor != null) {
|
if (reactor != null) {
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
BlockMenu bm = getReactorMenu(b.getLocation());
|
BlockMenu bm = getReactorMenu(b.getLocation());
|
||||||
if(bm != null) {
|
|
||||||
for(int slot:reactor.getCoolantSlots())
|
if (bm != null) {
|
||||||
if(bm.getItemInSlot(slot) != null)
|
for (int slot: reactor.getCoolantSlots()) {
|
||||||
|
if (bm.getItemInSlot(slot) != null) {
|
||||||
empty = false;
|
empty = false;
|
||||||
for(int slot:reactor.getFuelSlots())
|
}
|
||||||
if(bm.getItemInSlot(slot) != null)
|
}
|
||||||
|
|
||||||
|
for (int slot: reactor.getFuelSlots()) {
|
||||||
|
if (bm.getItemInSlot(slot) != null) {
|
||||||
empty = false;
|
empty = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(!empty || !p.isSneaking()) {
|
if(!empty || !p.isSneaking()) {
|
||||||
//reactor is not empty, lets view it's inventory instead.
|
//reactor is not empty, lets view it's inventory instead.
|
||||||
@ -100,11 +105,13 @@ public class ReactorAccessPort extends SlimefunItem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlace(Player p, Block b, SlimefunItem item) {
|
public void onPlace(Player p, Block b, SlimefunItem item) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) {
|
public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) {
|
||||||
BlockMenu inv = BlockStorage.getInventory(b);
|
BlockMenu inv = BlockStorage.getInventory(b);
|
||||||
|
|
||||||
if (inv != null) {
|
if (inv != null) {
|
||||||
for (int slot : getFuelSlots()) {
|
for (int slot : getFuelSlots()) {
|
||||||
if (inv.getItemInSlot(slot) != null) {
|
if (inv.getItemInSlot(slot) != null) {
|
||||||
@ -112,12 +119,14 @@ public class ReactorAccessPort extends SlimefunItem {
|
|||||||
inv.replaceExistingItem(slot, null);
|
inv.replaceExistingItem(slot, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int slot : getCoolantSlots()) {
|
for (int slot : getCoolantSlots()) {
|
||||||
if (inv.getItemInSlot(slot) != null) {
|
if (inv.getItemInSlot(slot) != null) {
|
||||||
b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
|
b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
|
||||||
inv.replaceExistingItem(slot, null);
|
inv.replaceExistingItem(slot, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int slot : getOutputSlots()) {
|
for (int slot : getOutputSlots()) {
|
||||||
if (inv.getItemInSlot(slot) != null) {
|
if (inv.getItemInSlot(slot) != null) {
|
||||||
b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
|
b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
|
||||||
@ -132,44 +141,24 @@ public class ReactorAccessPort extends SlimefunItem {
|
|||||||
|
|
||||||
private void constructMenu(BlockMenuPreset preset) {
|
private void constructMenu(BlockMenuPreset preset) {
|
||||||
for (int i : border) {
|
for (int i : border) {
|
||||||
preset.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " "),
|
preset.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
|
||||||
(p, slot, item, action) -> false
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i : border_1) {
|
for (int i : border_1) {
|
||||||
preset.addItem(i, new CustomItem(new ItemStack(Material.LIME_STAINED_GLASS_PANE), " "),
|
preset.addItem(i, new CustomItem(new ItemStack(Material.LIME_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
|
||||||
(p, slot, item, action) -> false
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i : border_2) {
|
for (int i : border_2) {
|
||||||
preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "),
|
preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
|
||||||
(p, slot, item, action) -> false
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i : border_3) {
|
for (int i : border_3) {
|
||||||
preset.addItem(i, new CustomItem(new ItemStack(Material.GREEN_STAINED_GLASS_PANE), " "),
|
preset.addItem(i, new CustomItem(new ItemStack(Material.GREEN_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
|
||||||
(p, slot, item, action) -> false
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
preset.addItem(1, new CustomItem(SlimefunItems.URANIUM, "&7Fuel Slot", "", "&rThis Slot accepts radioactive Fuel such as:", "&2Uranium &ror &aNeptunium"),
|
preset.addItem(1, new CustomItem(SlimefunItems.URANIUM, "&7Fuel Slot", "", "&rThis Slot accepts radioactive Fuel such as:", "&2Uranium &ror &aNeptunium"), (p, slot, item, action) -> false);
|
||||||
(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(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
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getInventoryTitle() {
|
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());
|
Location reactorL = new Location(l.getWorld(), l.getX(), l.getY() - 3, l.getZ());
|
||||||
|
|
||||||
SlimefunItem item = BlockStorage.check(reactorL.getBlock());
|
SlimefunItem item = BlockStorage.check(reactorL.getBlock());
|
||||||
if(item instanceof AReactor)
|
if (item instanceof AReactor) return (AReactor) item;
|
||||||
return (AReactor) item;
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -207,8 +195,9 @@ public class ReactorAccessPort extends SlimefunItem {
|
|||||||
|
|
||||||
String id = BlockStorage.checkID(reactorL);
|
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 BlockStorage.getInventory(reactorL);
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -216,12 +205,15 @@ public class ReactorAccessPort extends SlimefunItem {
|
|||||||
private static Inventory inject(Location l) {
|
private static Inventory inject(Location l) {
|
||||||
int size = BlockStorage.getInventory(l).toInventory().getSize();
|
int size = BlockStorage.getInventory(l).toInventory().getSize();
|
||||||
Inventory inv = Bukkit.createInventory(null, size);
|
Inventory inv = Bukkit.createInventory(null, size);
|
||||||
|
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
inv.setItem(i, new CustomItem(Material.COMMAND_BLOCK, " &4ALL YOUR PLACEHOLDERS ARE BELONG TO US"));
|
inv.setItem(i, new CustomItem(Material.COMMAND_BLOCK, " &4ALL YOUR PLACEHOLDERS ARE BELONG TO US"));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int slot : getOutputSlots()) {
|
for (int slot : getOutputSlots()) {
|
||||||
inv.setItem(slot, BlockStorage.getInventory(l).getItemInSlot(slot));
|
inv.setItem(slot, BlockStorage.getInventory(l).getItemInSlot(slot));
|
||||||
}
|
}
|
||||||
|
|
||||||
return inv;
|
return inv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,10 +225,7 @@ public class ReactorAccessPort extends SlimefunItem {
|
|||||||
BlockStorage.getInventory(l).replaceExistingItem(slot, inv.getItem(slot));
|
BlockStorage.getInventory(l).replaceExistingItem(slot, inv.getItem(slot));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<Integer, ItemStack> entry: map.entrySet()) {
|
return map.values().stream().findAny().orElse(null);
|
||||||
return entry.getValue();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ public class MagnetTask extends SlimefunTask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean cancelTask() {
|
protected boolean cancelTask() {
|
||||||
return super.cancelTask() ? true: p.getGameMode() == GameMode.SPECTATOR;
|
return super.cancelTask() || p.getGameMode() == GameMode.SPECTATOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -721,6 +721,8 @@ public class SlimefunSetup {
|
|||||||
new String[] {"chance.fireBreak"}, new Integer[] {34})
|
new String[] {"chance.fireBreak"}, new Integer[] {34})
|
||||||
.register(true, new MultiBlockInteractionHandler() {
|
.register(true, new MultiBlockInteractionHandler() {
|
||||||
|
|
||||||
|
private final String chamberID = "IGNITION_CHAMBER";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onInteract(Player p, MultiBlock mb, Block b) {
|
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.
|
// The chamber methods have been updated to reflect this change.
|
||||||
// Maybe this code snippet should be turned into a loop?
|
// Maybe this code snippet should be turned into a loop?
|
||||||
Hopper chamber = null;
|
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();
|
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();
|
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();
|
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();
|
chamber = (Hopper) dispBlock.getRelative(BlockFace.SOUTH).getState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1840,17 +1846,23 @@ public class SlimefunSetup {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onBlockBreak(BlockBreakEvent e, ItemStack item, int fortune, List<ItemStack> drops) {
|
public boolean onBlockBreak(BlockBreakEvent e, ItemStack item, int fortune, List<ItemStack> drops) {
|
||||||
if (SlimefunManager.isItemSimiliar(item, SlimefunItems.PICKAXE_OF_CONTAINMENT, true)) {
|
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 (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.
|
// 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();
|
ItemStack spawner = SlimefunItems.BROKEN_SPAWNER.clone();
|
||||||
if(BlockStorage.hasBlockInfo(b))
|
if (BlockStorage.hasBlockInfo(b)) {
|
||||||
spawner = SlimefunItems.REPAIRED_SPAWNER.clone();
|
spawner = SlimefunItems.REPAIRED_SPAWNER.clone();
|
||||||
|
}
|
||||||
|
|
||||||
ItemMeta im = spawner.getItemMeta();
|
ItemMeta im = spawner.getItemMeta();
|
||||||
List<String> lore = im.getLore();
|
List<String> lore = im.getLore();
|
||||||
|
|
||||||
for (int i = 0; i < lore.size(); i++) {
|
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())));
|
if (lore.get(i).contains("<Type>")) lore.set(i, lore.get(i).replace("<Type>", StringUtils.format(((CreatureSpawner) b.getState()).getSpawnedType().toString())));
|
||||||
}
|
}
|
||||||
|
|
||||||
im.setLore(lore);
|
im.setLore(lore);
|
||||||
spawner.setItemMeta(im);
|
spawner.setItemMeta(im);
|
||||||
b.getLocation().getWorld().dropItemNaturally(b.getLocation(), spawner);
|
b.getLocation().getWorld().dropItemNaturally(b.getLocation(), spawner);
|
||||||
@ -3860,11 +3872,11 @@ public class SlimefunSetup {
|
|||||||
public void tick(Block b, SlimefunItem item, Config data) {
|
public void tick(Block b, SlimefunItem item, Config data) {
|
||||||
int charge = ChargableBlock.getCharge(b.getLocation());
|
int charge = ChargableBlock.getCharge(b.getLocation());
|
||||||
if (charge > 2) {
|
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);
|
ChargableBlock.setCharge(b.getLocation(), charge - 3);
|
||||||
}
|
}
|
||||||
else {
|
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
|
@Override
|
||||||
public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -3900,11 +3912,11 @@ public class SlimefunSetup {
|
|||||||
public void tick(Block b, SlimefunItem item, Config data) {
|
public void tick(Block b, SlimefunItem item, Config data) {
|
||||||
int charge = ChargableBlock.getCharge(b.getLocation());
|
int charge = ChargableBlock.getCharge(b.getLocation());
|
||||||
if (charge > 10) {
|
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);
|
ChargableBlock.setCharge(b.getLocation(), charge - 11);
|
||||||
}
|
}
|
||||||
else {
|
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
|
@Override
|
||||||
public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -3940,11 +3952,11 @@ public class SlimefunSetup {
|
|||||||
public void tick(Block b, SlimefunItem item, Config data) {
|
public void tick(Block b, SlimefunItem item, Config data) {
|
||||||
int charge = ChargableBlock.getCharge(b.getLocation());
|
int charge = ChargableBlock.getCharge(b.getLocation());
|
||||||
if (charge > 45) {
|
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);
|
ChargableBlock.setCharge(b.getLocation(), charge - 46);
|
||||||
}
|
}
|
||||||
else {
|
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
|
@Override
|
||||||
public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -95,6 +95,7 @@ public class SlimefunGuide {
|
|||||||
return getItem(book ? BookDesign.BOOK: BookDesign.CHEST);
|
return getItem(book ? BookDesign.BOOK: BookDesign.CHEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public static ItemStack getDeprecatedItem(boolean book) {
|
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");
|
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<>();
|
List<String> lore = new ArrayList<>();
|
||||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&8\u21E8 &7Lasts " + getTimeLeft(fuel.getTicks() / 2)));
|
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" + (((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);
|
im.setLore(lore);
|
||||||
fItem.setItemMeta(im);
|
fItem.setItemMeta(im);
|
||||||
menu.addItem(slot, fItem);
|
menu.addItem(slot, fItem);
|
||||||
@ -1037,7 +1038,7 @@ public class SlimefunGuide {
|
|||||||
List<String> lore = new ArrayList<>();
|
List<String> lore = new ArrayList<>();
|
||||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&8\u21E8 &7Lasts " + getTimeLeft(fuel.getTicks() / 2)));
|
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" + (((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);
|
im.setLore(lore);
|
||||||
fItem.setItemMeta(im);
|
fItem.setItemMeta(im);
|
||||||
menu.addItem(slot, fItem);
|
menu.addItem(slot, fItem);
|
||||||
|
@ -713,19 +713,7 @@ 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)) {
|
if (!blockblacklist.contains(block.getType()) && !drops.isEmpty() && CSCoreLib.getLib().getProtectionManager().canBuild(UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")), block)) {
|
||||||
SlimefunItem item = BlockStorage.check(block);
|
SlimefunItem item = BlockStorage.check(block);
|
||||||
|
|
||||||
if (item != null) {
|
if (item == null) {
|
||||||
return;
|
|
||||||
/*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));
|
|
||||||
if (SlimefunItem.blockhandler.containsKey(item.getID())) SlimefunItem.blockhandler.get(item.getID()).onBreak(null, block, item, UnregisterReason.ANDROID_DIG);
|
|
||||||
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType());
|
|
||||||
block.setType(Material.AIR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
} else {
|
|
||||||
ItemStack[] items = drops.toArray(new ItemStack[drops.size()]);
|
ItemStack[] items = drops.toArray(new ItemStack[drops.size()]);
|
||||||
if (fits(b, items)) {
|
if (fits(b, items)) {
|
||||||
pushItems(b, items);
|
pushItems(b, items);
|
||||||
@ -733,6 +721,17 @@ public abstract class ProgrammableAndroid extends SlimefunItem {
|
|||||||
block.setType(Material.AIR);
|
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));
|
||||||
|
if (SlimefunItem.blockhandler.containsKey(item.getID())) SlimefunItem.blockhandler.get(item.getID()).onBreak(null, block, item, UnregisterReason.ANDROID_DIG);
|
||||||
|
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType());
|
||||||
|
block.setType(Material.AIR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -610,15 +610,17 @@ public class BlockStorage {
|
|||||||
public void clearInventory(Location l) {
|
public void clearInventory(Location l) {
|
||||||
BlockMenu menu = getInventory(l);
|
BlockMenu menu = getInventory(l);
|
||||||
|
|
||||||
for (HumanEntity human : new ArrayList<>(menu.toInventory().getViewers())) {
|
if (menu != null) {
|
||||||
// Prevents "java.lang.IllegalStateException: Asynchronous entity add!" when closing inventory while holding an item
|
for (HumanEntity human : new ArrayList<>(menu.toInventory().getViewers())) {
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, () -> {
|
// Prevents "java.lang.IllegalStateException: Asynchronous entity add!" when closing inventory while holding an item
|
||||||
human.closeInventory();
|
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, () -> {
|
||||||
});
|
human.closeInventory();
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
|
||||||
inventories.get(l).delete(l);
|
inventories.get(l).delete(l);
|
||||||
inventories.remove(l);
|
inventories.remove(l);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasInventory(Location l) {
|
public boolean hasInventory(Location l) {
|
||||||
|
@ -24,13 +24,14 @@ public class ErrorReport {
|
|||||||
private File file;
|
private File file;
|
||||||
|
|
||||||
public ErrorReport(Throwable throwable, Consumer<PrintStream> printer) {
|
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()) {
|
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();
|
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)) {
|
try (PrintStream stream = new PrintStream(file)) {
|
||||||
|
@ -23,7 +23,7 @@ import me.mrCookieSlime.Slimefun.api.inventory.BackpackInventory;
|
|||||||
* @author TheBusyBiscuit
|
* @author TheBusyBiscuit
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class PlayerProfile {
|
public final class PlayerProfile {
|
||||||
|
|
||||||
public static Map<UUID, PlayerProfile> profiles = new HashMap<>();
|
public static Map<UUID, PlayerProfile> profiles = new HashMap<>();
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ import java.text.ParseException;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
@ -21,16 +20,13 @@ public class SlimefunBackup {
|
|||||||
public static void start() {
|
public static void start() {
|
||||||
File folder = new File("data-storage/Slimefun/block-backups");
|
File folder = new File("data-storage/Slimefun/block-backups");
|
||||||
List<File> backups = Arrays.asList(folder.listFiles());
|
List<File> backups = Arrays.asList(folder.listFiles());
|
||||||
if (backups.size() > 20) {
|
|
||||||
Collections.sort(backups, new Comparator<File>() {
|
|
||||||
|
|
||||||
@Override
|
if (backups.size() > 20) {
|
||||||
public int compare(File f1, File f2) {
|
Collections.sort(backups, (a, b) -> {
|
||||||
try {
|
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) {
|
} catch (ParseException e) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -49,67 +45,68 @@ public class SlimefunBackup {
|
|||||||
try {
|
try {
|
||||||
file.createNewFile();
|
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);
|
||||||
|
|
||||||
for (File f1: new File("data-storage/Slimefun/stored-blocks/").listFiles()) {
|
try (FileInputStream input = new FileInputStream(f)) {
|
||||||
for (File f: f1.listFiles()) {
|
int length;
|
||||||
ZipEntry entry = new ZipEntry("stored-blocks/" + f1.getName() + "/" + f.getName());
|
while ((length = input.read(buffer)) > 0) {
|
||||||
|
output.write(buffer, 0, length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
output.closeEntry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (File f: new File("data-storage/Slimefun/universal-inventories/").listFiles()) {
|
||||||
|
ZipEntry entry = new ZipEntry("universal-inventories/" + f.getName());
|
||||||
output.putNextEntry(entry);
|
output.putNextEntry(entry);
|
||||||
FileInputStream input = new FileInputStream(f);
|
|
||||||
|
|
||||||
int length;
|
try (FileInputStream input = new FileInputStream(f)) {
|
||||||
while ((length = input.read(buffer)) > 0) {
|
int length;
|
||||||
output.write(buffer, 0, length);
|
while ((length = input.read(buffer)) > 0) {
|
||||||
|
output.write(buffer, 0, length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
output.closeEntry();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (File f: new File("data-storage/Slimefun/stored-inventories/").listFiles()) {
|
||||||
|
ZipEntry entry = new ZipEntry("stored-inventories/" + f.getName());
|
||||||
|
output.putNextEntry(entry);
|
||||||
|
|
||||||
|
try (FileInputStream input = new FileInputStream(f)) {
|
||||||
|
int length;
|
||||||
|
while ((length = input.read(buffer)) > 0) {
|
||||||
|
output.write(buffer, 0, length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
output.closeEntry();
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
try (FileInputStream input = new FileInputStream(chunks)) {
|
||||||
|
int length;
|
||||||
|
while ((length = input.read(buffer)) > 0) {
|
||||||
|
output.write(buffer, 0, length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
input.close();
|
|
||||||
output.closeEntry();
|
output.closeEntry();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
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()) {
|
|
||||||
ZipEntry entry = new ZipEntry("stored-chunks/chunks.sfc");
|
|
||||||
output.putNextEntry(entry);
|
|
||||||
FileInputStream input = new FileInputStream(new File("data-storage/Slimefun/stored-chunks/chunks.sfc"));
|
|
||||||
|
|
||||||
int length;
|
|
||||||
while ((length = input.read(buffer)) > 0) {
|
|
||||||
output.write(buffer, 0, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
input.close();
|
|
||||||
output.closeEntry();
|
|
||||||
}
|
|
||||||
|
|
||||||
output.close();
|
|
||||||
System.out.println("[Slimefun] Backed up Blocks to " + file.getName());
|
System.out.println("[Slimefun] Backed up Blocks to " + file.getName());
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -97,9 +97,11 @@ public abstract class Network {
|
|||||||
private Component getCurrentClassification(Location l) {
|
private Component getCurrentClassification(Location l) {
|
||||||
if(regulatorNodes.contains(l)) {
|
if(regulatorNodes.contains(l)) {
|
||||||
return Component.REGULATOR;
|
return Component.REGULATOR;
|
||||||
} else if(connectorNodes.contains(l)) {
|
}
|
||||||
|
else if(connectorNodes.contains(l)) {
|
||||||
return Component.CONNECTOR;
|
return Component.CONNECTOR;
|
||||||
} else if(terminusNodes.contains(l)) {
|
}
|
||||||
|
else if(terminusNodes.contains(l)) {
|
||||||
return Component.TERMINUS;
|
return Component.TERMINUS;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -107,27 +109,33 @@ public abstract class Network {
|
|||||||
|
|
||||||
private void discoverStep() {
|
private void discoverStep() {
|
||||||
int steps = 0;
|
int steps = 0;
|
||||||
while(nodeQueue.peek() != null) {
|
while (nodeQueue.peek() != null) {
|
||||||
Location l = nodeQueue.poll();
|
Location l = nodeQueue.poll();
|
||||||
Component currentAssignment = getCurrentClassification(l);
|
Component currentAssignment = getCurrentClassification(l);
|
||||||
Component classification = classifyLocation(l);
|
Component classification = classifyLocation(l);
|
||||||
if(classification != currentAssignment) {
|
|
||||||
if(currentAssignment == Component.REGULATOR || currentAssignment == Component.CONNECTOR) {
|
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.
|
// Requires a complete rebuild of the network, so we just throw the current one away.
|
||||||
unregisterNetwork(this);
|
unregisterNetwork(this);
|
||||||
return;
|
return;
|
||||||
} else if(currentAssignment == Component.TERMINUS) {
|
}
|
||||||
|
else if (currentAssignment == Component.TERMINUS) {
|
||||||
terminusNodes.remove(l);
|
terminusNodes.remove(l);
|
||||||
}
|
}
|
||||||
if(classification == Component.REGULATOR) {
|
|
||||||
|
if (classification == Component.REGULATOR) {
|
||||||
regulatorNodes.add(l);
|
regulatorNodes.add(l);
|
||||||
discoverNeighbors(l);
|
discoverNeighbors(l);
|
||||||
} else if(classification == Component.CONNECTOR) {
|
}
|
||||||
|
else if(classification == Component.CONNECTOR) {
|
||||||
connectorNodes.add(l);
|
connectorNodes.add(l);
|
||||||
discoverNeighbors(l);
|
discoverNeighbors(l);
|
||||||
} else if(classification == Component.TERMINUS) {
|
}
|
||||||
|
else if(classification == Component.TERMINUS) {
|
||||||
terminusNodes.add(l);
|
terminusNodes.add(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
locationClassificationChange(l, currentAssignment, classification);
|
locationClassificationChange(l, currentAssignment, classification);
|
||||||
}
|
}
|
||||||
steps += 1;
|
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 --) {
|
for(int i = getRange() + 1; i > 0; i --) {
|
||||||
Location new_location = l.clone().add(i * xDiff, i * yDiff, i * zDiff);
|
Location new_location = l.clone().add(i * xDiff, i * yDiff, i * zDiff);
|
||||||
addLocationToNetwork(new_location);
|
addLocationToNetwork(new_location);
|
||||||
@ -145,12 +153,12 @@ public abstract class Network {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void discoverNeighbors(Location l) {
|
private void discoverNeighbors(Location l) {
|
||||||
discoverNeighbors(l, 1, 0, 0);
|
discoverNeighbors(l, 1.0, 0.0, 0.0);
|
||||||
discoverNeighbors(l, -1, 0, 0);
|
discoverNeighbors(l, -1.0, 0.0, 0.0);
|
||||||
discoverNeighbors(l, 0, 1, 0);
|
discoverNeighbors(l, 0.0, 1.0, 0.0);
|
||||||
discoverNeighbors(l, 0, -1, 0);
|
discoverNeighbors(l, 0.0, -1.0, 0.0);
|
||||||
discoverNeighbors(l, 0, 0, 1);
|
discoverNeighbors(l, 0.0, 0.0, 1.0);
|
||||||
discoverNeighbors(l, 0, 0, -1);
|
discoverNeighbors(l, 0.0, 0.0, -1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void display() {
|
public void display() {
|
||||||
|
@ -37,15 +37,16 @@ public abstract class GitHubConnector {
|
|||||||
URL website = new URL("https://api.github.com/repos/" + this.getRepository() + this.getURLSuffix());
|
URL website = new URL("https://api.github.com/repos/" + this.getRepository() + this.getURLSuffix());
|
||||||
|
|
||||||
URLConnection connection = website.openConnection();
|
URLConnection connection = website.openConnection();
|
||||||
connection.setConnectTimeout(3000);
|
connection.setConnectTimeout(3000);
|
||||||
connection.addRequestProperty("User-Agent", "Slimefun 4 GitHub Agent (by TheBusyBiscuit)");
|
connection.addRequestProperty("User-Agent", "Slimefun 4 GitHub Agent (by TheBusyBiscuit)");
|
||||||
connection.setDoOutput(true);
|
connection.setDoOutput(true);
|
||||||
|
|
||||||
ReadableByteChannel rbc = Channels.newChannel(connection.getInputStream());
|
try (ReadableByteChannel channel = Channels.newChannel(connection.getInputStream())) {
|
||||||
FileOutputStream fos = new FileOutputStream(file);
|
try (FileOutputStream stream = new FileOutputStream(file)) {
|
||||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
stream.getChannel().transferFrom(channel, 0, Long.MAX_VALUE);
|
||||||
fos.close();
|
this.parseData();
|
||||||
this.parseData();
|
}
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} 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.");
|
if (SlimefunStartup.getCfg().getBoolean("options.print-out-github-data-retrieving")) System.err.println("[Slimefun - GitHub] ERROR - Could not connect to GitHub in time.");
|
||||||
|
|
||||||
@ -67,21 +68,16 @@ public abstract class GitHubConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void parseData() {
|
public void parseData() {
|
||||||
try {
|
try (BufferedReader reader = new BufferedReader(new FileReader(this.getFile()))) {
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(this.getFile()));
|
|
||||||
|
|
||||||
String full = "";
|
String full = "";
|
||||||
|
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
full = full + line;
|
full = full + line;
|
||||||
}
|
}
|
||||||
|
|
||||||
reader.close();
|
JsonElement element = new JsonParser().parse(full);
|
||||||
|
this.onSuccess(element);
|
||||||
JsonElement element = new JsonParser().parse(full);
|
|
||||||
|
|
||||||
this.onSuccess(element);
|
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -6,9 +6,9 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
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) {
|
public static String formatBigNumber(int i) {
|
||||||
return NumberFormat.getNumberInstance(Locale.US).format(i);
|
return NumberFormat.getNumberInstance(Locale.US).format(i);
|
||||||
@ -16,7 +16,7 @@ public class IntegerFormat {
|
|||||||
|
|
||||||
public static Date parseGitHubDate(String str) {
|
public static Date parseGitHubDate(String str) {
|
||||||
try {
|
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) {
|
} catch (ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user