1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 11:45:51 +00:00
This commit is contained in:
TheBusyBiscuit 2019-10-04 14:05:22 +02:00
commit 5d1c36734e
13 changed files with 137 additions and 167 deletions

View File

@ -36,14 +36,11 @@ public class GPSNetwork {
private static final int[] teleporter_inventory = new int[] {19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33, 34, 37, 38, 39, 40, 41, 42, 43}; private static final int[] teleporter_inventory = new int[] {19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33, 34, 37, 38, 39, 40, 41, 42, 43};
public void updateTransmitter(Location l, UUID uuid, NetworkStatus status) { public void updateTransmitter(Location l, UUID uuid, NetworkStatus status) {
Set<Location> set = new HashSet<>(); Set<Location> set = transmitters.getOrDefault(uuid, new HashSet<>());
if (transmitters.containsKey(uuid)) set = transmitters.get(uuid);
if (status == NetworkStatus.ONLINE) { if (status == NetworkStatus.ONLINE) {
if (!set.contains(l)) { if (set.add(l))
set.add(l);
transmitters.put(uuid, set); transmitters.put(uuid, set);
}
} }
else { else {
set.remove(l); set.remove(l);
@ -215,7 +212,7 @@ public class GPSNetwork {
} }
public Set<Location> getTransmitters(UUID uuid) { public Set<Location> getTransmitters(UUID uuid) {
return transmitters.containsKey(uuid) ? transmitters.get(uuid): new HashSet<>(); return transmitters.getOrDefault(uuid, new HashSet<>());
} }
public static void openTeleporterGUI(Player p, UUID uuid, Block b, final int complexity) { public static void openTeleporterGUI(Player p, UUID uuid, Block b, final int complexity) {
@ -258,7 +255,7 @@ public class GPSNetwork {
} }
} }
catch (Exception x) { catch (Exception x) {
Slimefun.getLogger().log(Level.SEVERE, "An Error occured while creating a Teleporter Menu for Slimefun " + Slimefun.getVersion(), x); Slimefun.getLogger().log(Level.SEVERE, "An Error occurred while creating a Teleporter Menu for Slimefun " + Slimefun.getVersion(), x);
} }
menu.open(p); menu.open(p);

View File

@ -82,7 +82,7 @@ public final class TeleportationSequence {
} }
destination.getWorld().spawnParticle(Particle.PORTAL,new Location(destination.getWorld(), destination.getX(), destination.getY() + 1, destination.getZ()),progress * 2, 0.2F, 0.8F, 0.2F ); destination.getWorld().spawnParticle(Particle.PORTAL,new Location(destination.getWorld(), destination.getX(), destination.getY() + 1, destination.getZ()),progress * 2, 0.2F, 0.8F, 0.2F );
destination.getWorld().playSound(destination, Sound.ENTITY_BLAZE_DEATH, 2F, 1.4F); destination.getWorld().playSound(destination, Sound.ENTITY_BLAZE_DEATH, 1F, 1.4F);
SlimefunPlugin.getUtilities().teleporterUsers.remove(uuid); SlimefunPlugin.getUtilities().teleporterUsers.remove(uuid);
} }
else { else {
@ -93,7 +93,7 @@ public final class TeleportationSequence {
subtitle.send(TitleType.SUBTITLE, p); subtitle.send(TitleType.SUBTITLE, p);
source.getWorld().spawnParticle(Particle.PORTAL, source, progress * 2, 0.2F, 0.8F, 0.2F); source.getWorld().spawnParticle(Particle.PORTAL, source, progress * 2, 0.2F, 0.8F, 0.2F);
source.getWorld().playSound(source, Sound.UI_BUTTON_CLICK, 1.7F, 0.6F); source.getWorld().playSound(source, Sound.UI_BUTTON_CLICK, 1F, 0.6F);
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> updateProgress(uuid, speed, progress + speed, source, destination, resistance), 10L); Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> updateProgress(uuid, speed, progress + speed, source, destination, resistance), 10L);
} }

View File

@ -436,8 +436,7 @@ public class SlimefunItem {
} }
public static Set<ItemHandler> getHandlers(String codeid) { public static Set<ItemHandler> getHandlers(String codeid) {
if (SlimefunPlugin.getUtilities().itemHandlers.containsKey(codeid)) return SlimefunPlugin.getUtilities().itemHandlers.get(codeid); return SlimefunPlugin.getUtilities().itemHandlers.getOrDefault(codeid, new HashSet<>());
else return new HashSet<>();
} }
public static void setRadioactive(ItemStack item) { public static void setRadioactive(ItemStack item) {

View File

@ -45,7 +45,7 @@ public class InfusedHopper extends SimpleSlimefunItem<BlockTicker> {
} }
if (sound) { if (sound) {
b.getWorld().playSound(b.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 5F, 2F); b.getWorld().playSound(b.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 1F, 2F);
} }
} }

View File

@ -18,7 +18,7 @@ public class MagnetTask extends SlimefunTask {
for (Entity item: Bukkit.getPlayer(uuid).getNearbyEntities(6D, 6D, 6D)) { for (Entity item: Bukkit.getPlayer(uuid).getNearbyEntities(6D, 6D, 6D)) {
if (item instanceof Item && !item.hasMetadata("no_pickup") && ((Item) item).getPickupDelay() <= 0) { if (item instanceof Item && !item.hasMetadata("no_pickup") && ((Item) item).getPickupDelay() <= 0) {
item.teleport(Bukkit.getPlayer(uuid).getEyeLocation()); item.teleport(Bukkit.getPlayer(uuid).getEyeLocation());
Bukkit.getPlayer(uuid).getWorld().playSound(Bukkit.getPlayer(uuid).getEyeLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 5L, 2L); Bukkit.getPlayer(uuid).getWorld().playSound(Bukkit.getPlayer(uuid).getEyeLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 1F, 2F);
} }
} }
} }

View File

@ -110,7 +110,7 @@ public class RitualAnimation implements Runnable {
else { else {
particles.add(pedestal.getLocation().add(0.5, 1.5, 0.5)); particles.add(pedestal.getLocation().add(0.5, 1.5, 0.5));
items.add(AncientAltarListener.fixItemStack(item.getItemStack(), item.getCustomName())); items.add(AncientAltarListener.fixItemStack(item.getItemStack(), item.getCustomName()));
pedestal.getWorld().playSound(pedestal.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 5F, 2F); pedestal.getWorld().playSound(pedestal.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 1F, 2F);
try { try {
l.getWorld().spawnParticle(Particle.ENCHANTMENT_TABLE,pedestal.getLocation().add(0.5, 1.5, 0.5),16, 0.3F, 0.2F, 0.3F); l.getWorld().spawnParticle(Particle.ENCHANTMENT_TABLE,pedestal.getLocation().add(0.5, 1.5, 0.5),16, 0.3F, 0.2F, 0.3F);
@ -132,7 +132,7 @@ public class RitualAnimation implements Runnable {
// This should re-enable altar blocks on craft failure. // This should re-enable altar blocks on craft failure.
utilities.altarinuse.remove(altar.getLocation()); utilities.altarinuse.remove(altar.getLocation());
l.getWorld().playSound(l, Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR, 5F, 1F); l.getWorld().playSound(l, Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR, 1F, 1F);
itemLock.clear(); itemLock.clear();
altars.remove(altar); altars.remove(altar);
} }

View File

@ -45,7 +45,7 @@ public class BlockInfoConfig extends Config {
private void checkPath(String path) { private void checkPath(String path) {
if (path.contains(".")) { if (path.indexOf('.') != -1) {
throw new UnsupportedOperationException("BlockInfoConfig only supports Map<String,String> (path: " + path + ")"); throw new UnsupportedOperationException("BlockInfoConfig only supports Map<String,String> (path: " + path + ")");
} }
} }

View File

@ -526,7 +526,7 @@ public class BlockStorage {
} }
private static void refreshCache(BlockStorage storage, Location l, String key, String value, boolean updateTicker) { private static void refreshCache(BlockStorage storage, Location l, String key, String value, boolean updateTicker) {
Config cfg = storage.blocksCache.containsKey(key) ? storage.blocksCache.get(key): new Config(path_blocks + l.getWorld().getName() + '/' + key + ".sfb"); Config cfg = storage.blocksCache.getOrDefault(key, new Config(path_blocks + l.getWorld().getName() + '/' + key + ".sfb"));
cfg.setValue(serializeLocation(l), value); cfg.setValue(serializeLocation(l), value);
storage.blocksCache.put(key, cfg); storage.blocksCache.put(key, cfg);
@ -540,7 +540,7 @@ public class BlockStorage {
locations.add(l); locations.add(l);
SlimefunPlugin.getUtilities().tickingChunks.put(chunkString, locations); SlimefunPlugin.getUtilities().tickingChunks.put(chunkString, locations);
if (!SlimefunPlugin.getUtilities().loadedTickers.contains(chunkString)) SlimefunPlugin.getUtilities().loadedTickers.add(chunkString); SlimefunPlugin.getUtilities().loadedTickers.add(chunkString);
} }
} }
} }

View File

@ -25,24 +25,24 @@ import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
public class TickerTask implements Runnable { public class TickerTask implements Runnable {
private boolean halted = false; private boolean halted = false;
protected final Map<Location, Location> move = new HashMap<>();
protected final Map<Location, Boolean> delete = new HashMap<>();
private final Map<Location, Long> blockTimings = new HashMap<>();
protected Map<Location, Location> move = new HashMap<>(); private final Set<BlockTicker> tickers = new HashSet<>();
protected Map<Location, Boolean> delete = new HashMap<>();
protected Map<Location, Long> blockTimings = new HashMap<>();
private Set<BlockTicker> tickers = new HashSet<>();
private int skipped = 0; private int skipped = 0;
private int chunks = 0; private int chunks = 0;
private int machines = 0; private int machines = 0;
private long time = 0; private long time = 0;
private Map<String, Integer> chunkItemCount = new HashMap<>(); private final Map<String, Integer> chunkItemCount = new HashMap<>();
private Map<String, Integer> machineCount = new HashMap<>(); private final Map<String, Integer> machineCount = new HashMap<>();
private Map<String, Long> machineTimings = new HashMap<>(); private final Map<String, Long> machineTimings = new HashMap<>();
private Map<String, Long> chunkTimings = new HashMap<>(); private final Map<String, Long> chunkTimings = new HashMap<>();
private Set<String> chunksSkipped = new HashSet<>(); private final Set<String> chunksSkipped = new HashSet<>();
private Map<Location, Integer> buggedBlocks = new HashMap<>(); private final Map<Location, Integer> buggedBlocks = new HashMap<>();
private boolean running = false; private boolean running = false;
@ -109,65 +109,24 @@ public class TickerTask implements Runnable {
machineCount.put(item.getID(), (machine != null ? machine: 0) + 1); machineCount.put(item.getID(), (machine != null ? machine: 0) + 1);
blockTimings.put(l, System.currentTimeMillis() - timestamp3); blockTimings.put(l, System.currentTimeMillis() - timestamp3);
} catch (Exception x) { } catch (Exception x) {
int errors = 0; int errors = bugged.getOrDefault(l, 0);
if (bugged.containsKey(l)) errors = bugged.get(l); reportErrors(l, item, x, errors);
errors++;
if (errors == 1) {
// Generate a new Error-Report
new ErrorReport(x, this, l, item);
buggedBlocks.put(l, errors);
}
else if (errors == 4) {
Slimefun.getLogger().log(Level.SEVERE, "X: " + l.getBlockX() + " Y: " + l.getBlockY() + " Z: " + l.getBlockZ() + '(' + item.getID() + ")");
Slimefun.getLogger().log(Level.SEVERE, "has thrown 4 Exceptions in the last 4 Ticks, the Block has been terminated.");
Slimefun.getLogger().log(Level.SEVERE, "Check your /plugins/Slimefun/error-reports/ folder for details.");
Slimefun.getLogger().log(Level.SEVERE, " ");
BlockStorage._integrated_removeBlockInfo(l, true);
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> l.getBlock().setType(Material.AIR));
}
else {
buggedBlocks.put(l, errors);
}
} }
}); });
} }
else { else {
long timestamp3 = System.currentTimeMillis(); long timestamp3 = System.currentTimeMillis();
item.getBlockTicker().tick(b, item, BlockStorage.getLocationInfo(l)); item.getBlockTicker().tick(b, item, BlockStorage.getLocationInfo(l));
machineTimings.put(item.getID(), (machineTimings.containsKey(item.getID()) ? machineTimings.get(item.getID()): 0) + (System.currentTimeMillis() - timestamp3)); machineTimings.merge(item.getID(), (System.currentTimeMillis() - timestamp3), Long::sum);
chunkItemCount.put(c, (chunkItemCount.containsKey(c) ? chunkItemCount.get(c): 0) + 1); chunkItemCount.merge(c, 1, Integer::sum);
machineCount.put(item.getID(), (machineCount.containsKey(item.getID()) ? machineCount.get(item.getID()): 0) + 1); machineCount.merge(item.getID(), 1, Integer::sum);
blockTimings.put(l, System.currentTimeMillis() - timestamp3); blockTimings.put(l, System.currentTimeMillis() - timestamp3);
} }
tickers.add(item.getBlockTicker()); tickers.add(item.getBlockTicker());
} catch (Exception x) { } catch (Exception x) {
int errors = 0; int errors = bugged.getOrDefault(l, 0);
if (bugged.containsKey(l)) errors = bugged.get(l); reportErrors(l, item, x, errors);
errors++;
if (errors == 1) {
// Generate a new Error-Report
new ErrorReport(x, this, l, item);
buggedBlocks.put(l, errors);
}
else if (errors == 4) {
Slimefun.getLogger().log(Level.SEVERE, "X: " + l.getBlockX() + " Y: " + l.getBlockY() + " Z: " + l.getBlockZ() + '(' + item.getID() + ")");
Slimefun.getLogger().log(Level.SEVERE, "has thrown 4 Exceptions in the last 4 Ticks, the Block has been terminated.");
Slimefun.getLogger().log(Level.SEVERE, "Check your /plugins/Slimefun/error-reports/ folder for details.");
Slimefun.getLogger().log(Level.SEVERE, " ");
BlockStorage._integrated_removeBlockInfo(l, true);
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> l.getBlock().setType(Material.AIR));
}
else {
buggedBlocks.put(l, errors);
}
} }
} }
else skipped++; else skipped++;
@ -198,7 +157,31 @@ public class TickerTask implements Runnable {
time = System.currentTimeMillis() - timestamp; time = System.currentTimeMillis() - timestamp;
running = false; running = false;
} }
private void reportErrors(Location l, SlimefunItem item, Exception x, int errors) {
errors++;
if (errors == 1) {
// Generate a new Error-Report
new ErrorReport(x, this, l, item);
buggedBlocks.put(l, errors);
}
else if (errors == 4) {
Slimefun.getLogger().log(Level.SEVERE, "X: " + l.getBlockX() + " Y: " + l.getBlockY() + " Z: " + l.getBlockZ() + '(' + item.getID() + ")");
Slimefun.getLogger().log(Level.SEVERE, "has thrown 4 Exceptions in the last 4 Ticks, the Block has been terminated.");
Slimefun.getLogger().log(Level.SEVERE, "Check your /plugins/Slimefun/error-reports/ folder for details.");
Slimefun.getLogger().log(Level.SEVERE, " ");
BlockStorage._integrated_removeBlockInfo(l, true);
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> l.getBlock().setType(Material.AIR));
}
else {
buggedBlocks.put(l, errors);
}
}
public long getTime() { public long getTime() {
return time; return time;
} }
@ -222,11 +205,11 @@ public class TickerTask implements Runnable {
for (Map.Entry<String, Integer> entry: machineCount.entrySet()) { for (Map.Entry<String, Integer> entry: machineCount.entrySet()) {
long timings = machineTimings.get(entry.getKey()); long timings = machineTimings.get(entry.getKey());
if (timings > 0) hover.append("\n&c" + entry.getKey() + " - " + entry.getValue()+ "x &7(" + timings + "ms)"); if (timings > 0) hover.append("\n&c").append(entry.getKey()).append(" - ").append(entry.getValue()).append("x &7(").append(timings).append("ms)");
else hidden++; else hidden++;
} }
hover.append("\n\n&c+ &4" + hidden + " Hidden"); hover.append("\n\n&c+ &4").append(hidden).append(" Hidden");
tellraw.addHoverEvent(HoverAction.SHOW_TEXT, hover.toString()); tellraw.addHoverEvent(HoverAction.SHOW_TEXT, hover.toString());
try { try {
@ -258,12 +241,15 @@ public class TickerTask implements Runnable {
for (Map.Entry<String, Long> entry: chunkTimings.entrySet()) { for (Map.Entry<String, Long> entry: chunkTimings.entrySet()) {
if (!chunksSkipped.contains(entry.getKey())) { if (!chunksSkipped.contains(entry.getKey())) {
if (entry.getValue() > 0) hover.append("\n&c" + entry.getKey().replace("CraftChunk", "") + " - " + (chunkItemCount.containsKey(entry.getKey()) ? chunkItemCount.get(entry.getKey()): 0) + "x &7(" + entry.getValue() + "ms)"); if (entry.getValue() > 0)
hover.append("\n&c").append(entry.getKey().replace("CraftChunk", "")).append(" - ")
.append(chunkItemCount.getOrDefault(entry.getKey(), 0))
.append("x &7(").append(entry.getValue()).append("ms)");
else hidden++; else hidden++;
} }
} }
hover.append("\n\n&c+ &4" + hidden + " Hidden"); hover.append("\n\n&c+ &4").append(hidden).append(" Hidden");
tellraw.addHoverEvent(HoverAction.SHOW_TEXT, hover.toString()); tellraw.addHoverEvent(HoverAction.SHOW_TEXT, hover.toString());
try { try {
@ -276,7 +262,8 @@ public class TickerTask implements Runnable {
int hidden = 0; int hidden = 0;
for (Map.Entry<String, Long> entry: chunkTimings.entrySet()) { for (Map.Entry<String, Long> entry: chunkTimings.entrySet()) {
if (!chunksSkipped.contains(entry.getKey())) { if (!chunksSkipped.contains(entry.getKey())) {
if (entry.getValue() > 0) sender.sendMessage(" &c" + entry.getKey().replace("CraftChunk", "") + " - " + (chunkItemCount.containsKey(entry.getKey()) ? chunkItemCount.get(entry.getKey()): 0) + "x &7(" + entry.getValue() + "ms)"); if (entry.getValue() > 0) sender.sendMessage(" &c" + entry.getKey().replace("CraftChunk", "") + " - "
+ (chunkItemCount.getOrDefault(entry.getKey(), 0)) + "x &7(" + entry.getValue() + "ms)");
else hidden++; else hidden++;
} }
} }
@ -285,15 +272,15 @@ public class TickerTask implements Runnable {
} }
public long getTimings(Block b) { public long getTimings(Block b) {
return blockTimings.containsKey(b.getLocation()) ? blockTimings.get(b.getLocation()): 0L; return blockTimings.getOrDefault(b.getLocation(), 0L);
} }
public long getTimings(String item) { public long getTimings(String item) {
return machineTimings.containsKey(item) ? machineTimings.get(item): 0L; return machineTimings.getOrDefault(item, 0L);
} }
public long getTimings(Chunk c) { public long getTimings(Chunk c) {
return chunkTimings.containsKey(c.toString()) ? chunkTimings.get(c.toString()): 0L; return chunkTimings.getOrDefault(c.toString(), 0L);
} }
public void addBlockTimings(Location l, long time) { public void addBlockTimings(Location l, long time) {

View File

@ -155,30 +155,38 @@ public class CargoNet extends Network {
final Map<Integer, List<Location>> output = new HashMap<>(); final Map<Integer, List<Location>> output = new HashMap<>();
Set<Location> combinedOutputNodes = outputNodes;
combinedOutputNodes.addAll(advancedOutputNodes);
for (Location outputNode: outputNodes) { List<Location> list = new ArrayList<>();
int lastFrequency = -1;
for (Location outputNode: combinedOutputNodes) {
Integer frequency = getFrequency(outputNode); Integer frequency = getFrequency(outputNode);
if (!output.containsKey(frequency)) { list.add(outputNode);
output.put(frequency, new ArrayList<Location>());
if (frequency != lastFrequency && lastFrequency != -1) {
output.merge(frequency, list, (list1, list2) -> {
list1.addAll(list2);
return list1;
});
list.clear();
} }
output.get(frequency).add(outputNode);
} lastFrequency = frequency;
for (Location outputNode: advancedOutputNodes) {
Integer frequency = getFrequency(outputNode);
if (!output.containsKey(frequency)) {
output.put(frequency, new ArrayList<Location>());
}
output.get(frequency).add(outputNode);
} }
if (!list.isEmpty())
output.merge(lastFrequency, list, (list1, list2) -> {
list1.addAll(list2);
return list1;
});
//Chest Terminal Stuff //Chest Terminal Stuff
final Set<Location> providers = new HashSet<>(); final Set<Location> providers = new HashSet<>();
final Set<Location> destinations; final Set<Location> destinations = new HashSet<>();
if (output.containsKey(16)) { List<Location> output16 = output.get(16);
destinations = new HashSet<>(output.get(16)); if (output16 != null)
} else { destinations.addAll(output16);
destinations = new HashSet<>();
}
for (Location inputNode: inputNodes) { for (Location inputNode: inputNodes) {
int frequency = getFrequency(inputNode); int frequency = getFrequency(inputNode);
if (frequency == 16) { if (frequency == 16) {
@ -346,11 +354,7 @@ public class CargoNet extends Network {
List<Location> outputlist = new ArrayList<>(output.get(frequency)); List<Location> outputlist = new ArrayList<>(output.get(frequency));
if (roundrobin) { if (roundrobin) {
if (!SlimefunPlugin.getUtilities().roundRobin.containsKey(input)) { int cIndex = SlimefunPlugin.getUtilities().roundRobin.getOrDefault(input, 0);
SlimefunPlugin.getUtilities().roundRobin.put(input, 0);
}
int cIndex = SlimefunPlugin.getUtilities().roundRobin.get(input);
if (cIndex < outputlist.size()) { if (cIndex < outputlist.size()) {
for (int i = 0; i < cIndex; i++) { for (int i = 0; i < cIndex; i++) {
@ -398,19 +402,7 @@ public class CargoNet extends Network {
UniversalBlockMenu menu = storage.getUniversalInventory(target); UniversalBlockMenu menu = storage.getUniversalInventory(target);
for (int slot: menu.getPreset().getSlotsAccessedByItemTransport(menu, ItemTransportFlow.WITHDRAW, null)) { for (int slot: menu.getPreset().getSlotsAccessedByItemTransport(menu, ItemTransportFlow.WITHDRAW, null)) {
ItemStack is = menu.getItemInSlot(slot); ItemStack is = menu.getItemInSlot(slot);
if (is != null && CargoManager.matchesFilter(l.getBlock(), is, -1)) { filter(is, items, l);
boolean add = true;
for (StoredItem item: items) {
if (SlimefunManager.isItemSimiliar(is, item.getItem(), true)) {
add = false;
item.add(is.getAmount());
}
}
if (add) {
items.add(new StoredItem(new CustomItem(is, 1), is.getAmount()));
}
}
} }
} }
else if (storage.hasInventory(target.getLocation())) { else if (storage.hasInventory(target.getLocation())) {
@ -435,40 +427,13 @@ public class CargoNet extends Network {
} }
} }
else { else {
for (int slot: menu.getPreset().getSlotsAccessedByItemTransport(menu, ItemTransportFlow.WITHDRAW, null)) { handleWithdraw(menu, items, l);
ItemStack is = menu.getItemInSlot(slot);
if (is != null && CargoManager.matchesFilter(l.getBlock(), is, -1)) {
boolean add = true;
for (StoredItem item: items) {
if (SlimefunManager.isItemSimiliar(is, item.getItem(), true)) {
add = false;
item.add(is.getAmount());
}
}
if (add) {
items.add(new StoredItem(new CustomItem(is, 1), is.getAmount()));
}
}
}
} }
} }
else if (target.getState() instanceof InventoryHolder) { else if (target.getState() instanceof InventoryHolder) {
Inventory inv = ((InventoryHolder) target.getState()).getInventory(); Inventory inv = ((InventoryHolder) target.getState()).getInventory();
for (ItemStack is: inv.getContents()) { for (ItemStack is: inv.getContents()) {
if (is != null && CargoManager.matchesFilter(l.getBlock(), is, -1)) { filter(is, items, l);
boolean add = true;
for (StoredItem item: items) {
if (SlimefunManager.isItemSimiliar(is, item.getItem(), true)) {
add = false;
item.add(is.getAmount());
}
}
if (add) {
items.add(new StoredItem(new CustomItem(is, 1), is.getAmount()));
}
}
} }
} }
} }
@ -495,17 +460,19 @@ public class CargoNet extends Network {
lore.add(ChatColor.translateAlternateColorCodes('&', "&7Stored Items: &r" + DoubleHandler.getFancyDouble(item.getAmount()))); lore.add(ChatColor.translateAlternateColorCodes('&', "&7Stored Items: &r" + DoubleHandler.getFancyDouble(item.getAmount())));
if (stack.getMaxStackSize() > 1) lore.add(ChatColor.translateAlternateColorCodes('&', "&7<Left Click: Request 1 | Right Click: Request " + (item.getAmount() > stack.getMaxStackSize() ? stack.getMaxStackSize(): item.getAmount()) + ">")); if (stack.getMaxStackSize() > 1) lore.add(ChatColor.translateAlternateColorCodes('&', "&7<Left Click: Request 1 | Right Click: Request " + (item.getAmount() > stack.getMaxStackSize() ? stack.getMaxStackSize(): item.getAmount()) + ">"));
else lore.add(ChatColor.translateAlternateColorCodes('&', "&7<Left Click: Request 1>")); else lore.add(ChatColor.translateAlternateColorCodes('&', "&7<Left Click: Request 1>"));
lore.add(""); lore.add("");
if (im.hasLore()) { if (im.getLore() != null) {
for (String line: im.getLore()) { lore.addAll(im.getLore());
lore.add(line);
}
} }
im.setLore(lore); im.setLore(lore);
stack.setItemMeta(im); stack.setItemMeta(im);
menu.replaceExistingItem(slot, stack); menu.replaceExistingItem(slot, stack);
menu.addMenuClickHandler(slot, (p, sl, is, action) -> { menu.addMenuClickHandler(slot, (p, sl, is, action) -> {
SlimefunPlugin.getUtilities().itemRequests.add(new ItemRequest(l, 44, new CustomItem(item.getItem(), action.isRightClicked() ? (item.getAmount() > item.getItem().getMaxStackSize() ? item.getItem().getMaxStackSize(): item.getAmount()): 1), ItemTransportFlow.WITHDRAW)); int amount = item.getAmount() > item.getItem().getMaxStackSize() ? item.getItem().getMaxStackSize() : item.getAmount();
SlimefunPlugin.getUtilities().itemRequests.add(new ItemRequest(l, 44,
new CustomItem(item.getItem(), action.isRightClicked() ? amount : 1), ItemTransportFlow.WITHDRAW));
return false; return false;
}); });
@ -539,4 +506,26 @@ public class CargoNet extends Network {
return freq; return freq;
} }
private void handleWithdraw(BlockMenu menu, List<StoredItem> items, Location l) {
for (int slot: menu.getPreset().getSlotsAccessedByItemTransport(menu, ItemTransportFlow.WITHDRAW, null)) {
ItemStack is = menu.getItemInSlot(slot);
filter(is, items, l);
}
}
private void filter(ItemStack is, List<StoredItem> items, Location l) {
if (is != null && CargoManager.matchesFilter(l.getBlock(), is, -1)) {
boolean add = true;
for (StoredItem item: items) {
if (SlimefunManager.isItemSimiliar(is, item.getItem(), true)) {
add = false;
item.add(is.getAmount());
}
}
if (add) {
items.add(new StoredItem(new CustomItem(is, 1), is.getAmount()));
}
}
}
} }

View File

@ -59,7 +59,7 @@ public class ArmorListener implements Listener {
&& e.getCause() == DamageCause.FALL && e.getCause() == DamageCause.FALL
) { ) {
e.setCancelled(true); e.setCancelled(true);
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR, 2F, 2F); p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR, 1F, 2F);
p.setVelocity(new Vector(0.0, 0.7, 0.0)); p.setVelocity(new Vector(0.0, 0.7, 0.0));
for (Entity n: p.getNearbyEntities(4, 4, 4)) { for (Entity n: p.getNearbyEntities(4, 4, 4)) {
if (n instanceof LivingEntity && !n.getUniqueId().equals(p.getUniqueId())) { if (n instanceof LivingEntity && !n.getUniqueId().equals(p.getUniqueId())) {

View File

@ -57,8 +57,8 @@ public class BackpackListener implements Listener {
@EventHandler @EventHandler
public void onClick(InventoryClickEvent e) { public void onClick(InventoryClickEvent e) {
if (SlimefunPlugin.getUtilities().backpack.containsKey(e.getWhoClicked().getUniqueId())) { ItemStack item = SlimefunPlugin.getUtilities().backpack.get(e.getWhoClicked().getUniqueId());
ItemStack item = SlimefunPlugin.getUtilities().backpack.get(e.getWhoClicked().getUniqueId()); if (item != null) {
if (e.getClick() == ClickType.NUMBER_KEY) { if (e.getClick() == ClickType.NUMBER_KEY) {
ItemStack hotbarItem = e.getWhoClicked().getInventory().getItem(e.getHotbarButton()); ItemStack hotbarItem = e.getWhoClicked().getInventory().getItem(e.getHotbarButton());
SlimefunItem sfItem = SlimefunItem.getByItem(hotbarItem); SlimefunItem sfItem = SlimefunItem.getByItem(hotbarItem);

View File

@ -54,8 +54,8 @@ public class ToolListener implements Listener {
sensitiveMaterials.add(Material.STONE_PRESSURE_PLATE); sensitiveMaterials.add(Material.STONE_PRESSURE_PLATE);
sensitiveMaterials.add(Material.LIGHT_WEIGHTED_PRESSURE_PLATE); sensitiveMaterials.add(Material.LIGHT_WEIGHTED_PRESSURE_PLATE);
sensitiveMaterials.add(Material.HEAVY_WEIGHTED_PRESSURE_PLATE); sensitiveMaterials.add(Material.HEAVY_WEIGHTED_PRESSURE_PLATE);
Tag.SAPLINGS.getValues().forEach(sensitiveMaterials::add); sensitiveMaterials.addAll(Tag.SAPLINGS.getValues());
Tag.WOODEN_PRESSURE_PLATES.getValues().forEach(sensitiveMaterials::add); sensitiveMaterials.addAll(Tag.WOODEN_PRESSURE_PLATES.getValues());
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
@ -97,11 +97,9 @@ public class ToolListener implements Listener {
public void onBlockPlace(BlockPlaceEvent e) { public void onBlockPlace(BlockPlaceEvent e) {
ItemStack item = e.getItemInHand(); ItemStack item = e.getItemInHand();
if (utilities.cancelPlace.contains(e.getPlayer().getUniqueId())) { if (utilities.cancelPlace.remove(e.getPlayer().getUniqueId()))
e.setCancelled(true); e.setCancelled(true);
utilities.cancelPlace.remove(e.getPlayer().getUniqueId());
}
if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BASIC_CIRCUIT_BOARD, true)) e.setCancelled(true); if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BASIC_CIRCUIT_BOARD, true)) e.setCancelled(true);
else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.ADVANCED_CIRCUIT_BOARD, true)) e.setCancelled(true); else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.ADVANCED_CIRCUIT_BOARD, true)) e.setCancelled(true);
@ -187,7 +185,7 @@ public class ToolListener implements Listener {
public void onBlockBreak(BlockBreakEvent e) { public void onBlockBreak(BlockBreakEvent e) {
boolean allow = true; boolean allow = true;
List<ItemStack> drops = new ArrayList<>(); List<ItemStack> drops = new ArrayList<>();
ItemStack item = e.getPlayer().getEquipment().getItemInMainHand(); ItemStack item = e.getPlayer().getInventory().getItemInMainHand();
int fortune = 1; int fortune = 1;
Block block2 = e.getBlock().getRelative(BlockFace.UP); Block block2 = e.getBlock().getRelative(BlockFace.UP);