Skip to content

Commit

Permalink
Some bugfixes and optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
boxbeam committed May 14, 2020
1 parent 7d3851b commit 6d99516
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/redempt/redlib/misc/Hologram.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private void fixStands(int start) {
}
task = -1;
iter = -1;
});
}, 2);
}

/**
Expand Down
25 changes: 13 additions & 12 deletions src/redempt/redlib/multiblock/MultiBlockStructure.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,25 +160,26 @@ private static String minify(String data) {
data = data.replace("minecraft:", "");
String[] split = data.split(";");
int same = 0;
String output = split[0] + ";";
StringBuilder output = new StringBuilder().append(split[0]).append(";");
for (int i = 1; i < split.length - 1; i++) {
if (split[i].equals(split[i + 1])) {
same += same == 0 ? 2 : 1;
continue;
} else if (same > 0) {
output += split[i - 1] + "*" + same + ";";
output.append(split[i - 1]).append('*').append(same).append(';');
same = 0;
continue;
}
output += split[i] + ";";
output.append(split[i]).append(';');
}
if (same > 0) {
output += split[split.length - 1] + "*" + same + ";";
output.append(split[split.length - 1]).append('*').append(same).append(';');
} else {
output += split[split.length - 1];
output.append(split[split.length - 1]);
}
Map<String, Integer> count = new HashMap<>();
split = output.split(";");
String combine = output.toString();
split = combine.split(";");
for (int i = 1; i < split.length; i++) {
String str = split[i];
if (str.contains("*")) {
Expand All @@ -196,17 +197,17 @@ private static String minify(String data) {
replace.add(entry.getKey());
}
}
replace.sort((a, b) -> b.length() - a.length());
String prepend = "";
replace.sort((a, b) -> a.length() - b.length());
StringBuilder prepend = new StringBuilder();
for (int i = 0; i < replace.size(); i++) {
String str = replace.get(i);
prepend += str + ";";
output = output.replaceAll("(?<=;|^)" + Pattern.quote(str) + "(?=[^a-z_]|$)", i + "");
prepend.append(str).append(';');
combine = combine.replaceAll("(?<=;|^)" + Pattern.quote(str) + "(?=[^a-z_]|$)", i + "");
}
if (replace.size() > 0) {
output = "(" + prepend.substring(0, prepend.length() - 1) + ")" + output + ";";
combine = "(" + prepend.substring(0, prepend.length() - 1) + ")" + combine + ";";
}
return output;
return combine;
}

private static String expand(String data) {
Expand Down
2 changes: 1 addition & 1 deletion src/redempt/redlib/region/MultiRegion.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public void recalculate() {
for (Region region : regions) {
region.stream().map(Block::getLocation)
.filter(l -> this.contains(l) && !contains(newRegions, l))
.sorted((a, b) -> (int) Math.signum(b.distanceSquared(center) - a.distanceSquared(center)))
.sorted((a, b) -> (int) Math.signum(a.distanceSquared(center) - b.distanceSquared(center)))
.findFirst().ifPresent(l -> {
added[0] = true;
Region reg = new Region(l, l.clone().add(1, 1, 1));
Expand Down
3 changes: 2 additions & 1 deletion src/redempt/redlib/region/SelectionTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import redempt.redlib.RedLib;
import redempt.redlib.commandmanager.Messages;
import redempt.redlib.itemutils.ItemUtils;
import redempt.redlib.misc.Path;

/**
Expand All @@ -41,7 +42,7 @@ public void onClick(PlayerInteractEvent e) {
if (e.getAction() != Action.RIGHT_CLICK_BLOCK || e.getItem() == null) {
return;
}
if (!item.isSimilar(e.getItem())) {
if (!ItemUtils.compare(e.getItem(), item)) {
return;
}
Location[] locations = selections.getOrDefault(e.getPlayer().getUniqueId(), new Location[2]);
Expand Down

0 comments on commit 6d99516

Please sign in to comment.