mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-01 02:46:41 +00:00
It started on work with commands then I got carried away.
This commit is contained in:
@ -10,8 +10,8 @@ public class CleanTextureUtil extends TextureUtil {
|
||||
super(parent.getFolder());
|
||||
this.min = minPercent;
|
||||
this.max = maxPercent;
|
||||
int minIndex = ((parent.distances.length - 1) * minPercent) / 100;
|
||||
int maxIndex = ((parent.distances.length - 1) * maxPercent) / 100;
|
||||
int minIndex = (parent.distances.length - 1) * minPercent / 100;
|
||||
int maxIndex = (parent.distances.length - 1) * maxPercent / 100;
|
||||
long min = parent.distances[minIndex];
|
||||
long max = parent.distances[maxIndex];
|
||||
for (; minIndex > 0 && parent.distances[minIndex - 1] == min; minIndex--) ;
|
||||
@ -44,4 +44,4 @@ public class CleanTextureUtil extends TextureUtil {
|
||||
public int getMax() {
|
||||
return max;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.boydti.fawe.util;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.FaweAPI;
|
||||
import com.boydti.fawe.config.BBC;
|
||||
@ -24,12 +26,9 @@ import com.sk89q.worldedit.extent.inventory.BlockBag;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.eventbus.EventBus;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class EditSessionBuilder {
|
||||
private World world;
|
||||
@ -294,7 +293,7 @@ public class EditSessionBuilder {
|
||||
}
|
||||
if (checkMemory) {
|
||||
if (MemUtil.isMemoryLimitedSlow()) {
|
||||
if (Perm.hasPermission(player, "worldedit.fast")) {
|
||||
if (Permission.hasPermission(player.toWorldEditPlayer(), "worldedit.fast")) {
|
||||
BBC.WORLDEDIT_OOM_ADMIN.send(player);
|
||||
}
|
||||
throw FaweException.LOW_MEMORY;
|
||||
|
@ -15,14 +15,14 @@ public final class IOUtil {
|
||||
int ch4 = in.read();
|
||||
if ((ch1 | ch2 | ch3 | ch4) < 0)
|
||||
throw new EOFException();
|
||||
return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
|
||||
return (ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0);
|
||||
}
|
||||
|
||||
public static void writeInt(OutputStream out, int v) throws IOException {
|
||||
out.write((v >>> 24) & 0xFF);
|
||||
out.write((v >>> 16) & 0xFF);
|
||||
out.write((v >>> 8) & 0xFF);
|
||||
out.write((v >>> 0) & 0xFF);
|
||||
out.write(v >>> 24 & 0xFF);
|
||||
out.write(v >>> 16 & 0xFF);
|
||||
out.write(v >>> 8 & 0xFF);
|
||||
out.write(v >>> 0 & 0xFF);
|
||||
}
|
||||
|
||||
public static int readVarInt(InputStream in) throws IOException {
|
||||
@ -30,7 +30,7 @@ public final class IOUtil {
|
||||
int offset = 0;
|
||||
int b;
|
||||
while ((b = in.read()) > 127) {
|
||||
i |= (b - 128) << offset;
|
||||
i |= b - 128 << offset;
|
||||
offset += 7;
|
||||
}
|
||||
i |= b << offset;
|
||||
|
@ -17,12 +17,12 @@ public class ImgurUtility {
|
||||
return uploadImage(new FileInputStream(file));
|
||||
}
|
||||
|
||||
public static URL uploadImage(InputStream is) throws IOException {
|
||||
is = new BufferedInputStream(is);
|
||||
public static URL uploadImage(InputStream inputStream) throws IOException {
|
||||
inputStream = new BufferedInputStream(inputStream);
|
||||
FastByteArrayOutputStream baos = new FastByteArrayOutputStream(Short.MAX_VALUE);
|
||||
int d;
|
||||
while ((d = is.read()) != -1) {
|
||||
baos.write(d);
|
||||
int i;
|
||||
while ((i = inputStream.read()) != -1) {
|
||||
baos.write(i);
|
||||
}
|
||||
baos.flush();
|
||||
return uploadImage(baos.toByteArray());
|
||||
|
@ -1,44 +0,0 @@
|
||||
package com.boydti.fawe.util;
|
||||
|
||||
import com.boydti.fawe.object.FawePlayer;
|
||||
|
||||
public enum Perm {
|
||||
/*
|
||||
* Permission related functions
|
||||
*/
|
||||
ADMIN("fawe.admin", "admin");
|
||||
|
||||
public String s;
|
||||
public String cat;
|
||||
|
||||
Perm(String perm, String cat) {
|
||||
this.s = perm;
|
||||
this.cat = cat;
|
||||
}
|
||||
|
||||
public boolean has(FawePlayer<?> player) {
|
||||
return this.hasPermission(player, this);
|
||||
}
|
||||
|
||||
public boolean hasPermission(FawePlayer<?> player, Perm perm) {
|
||||
return hasPermission(player, perm.s);
|
||||
}
|
||||
|
||||
public static boolean hasPermission(FawePlayer<?> player, String perm) {
|
||||
if (player == null || player.hasPermission(ADMIN.s)) {
|
||||
return true;
|
||||
}
|
||||
if (player.hasPermission(perm)) {
|
||||
return true;
|
||||
}
|
||||
final String[] nodes = perm.split("\\.");
|
||||
final StringBuilder n = new StringBuilder();
|
||||
for (int i = 0; i < nodes.length - 1; i++) {
|
||||
n.append(nodes[i]).append(".");
|
||||
if (player.hasPermission(n + "*")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.boydti.fawe.util;
|
||||
|
||||
import com.sk89q.worldedit.util.auth.Subject;
|
||||
|
||||
public enum Permission {
|
||||
/*
|
||||
* Permission related functions
|
||||
*/
|
||||
ADMIN("fawe.admin", "admin");
|
||||
|
||||
public String permission;
|
||||
public String cat;
|
||||
|
||||
Permission(String permission, String category) {
|
||||
this.permission = permission;
|
||||
this.cat = category;
|
||||
}
|
||||
|
||||
|
||||
public static boolean hasPermission(Subject player, String permission) {
|
||||
if (player == null || player.hasPermission(ADMIN.permission)) {
|
||||
return true;
|
||||
}
|
||||
if (player.hasPermission(permission)) {
|
||||
return true;
|
||||
}
|
||||
final String[] nodes = permission.split("\\.");
|
||||
final StringBuilder n = new StringBuilder();
|
||||
for (int i = 0; i < nodes.length - 1; i++) {
|
||||
n.append(nodes[i]).append(".");
|
||||
if (player.hasPermission(n + "*")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -21,9 +21,9 @@ public class RandomTextureUtil extends CachedTextureUtil {
|
||||
int red1 = (c1 >> 16) & 0xFF;
|
||||
int green1 = (c1 >> 8) & 0xFF;
|
||||
int blue1 = (c1 >> 0) & 0xFF;
|
||||
byte red2 = (byte) ((c2 >> 16));
|
||||
byte green2 = (byte) ((c2 >> 8));
|
||||
byte blue2 = (byte) ((c2 >> 0));
|
||||
byte red2 = (byte) (c2 >> 16);
|
||||
byte green2 = (byte) (c2 >> 8);
|
||||
byte blue2 = (byte) (c2 >> 0);
|
||||
int red = MathMan.clamp(red1 + random(red2), 0, 255);
|
||||
int green = MathMan.clamp(green1 + random(green2), 0, 255);
|
||||
int blue = MathMan.clamp(blue1 + random(blue2), 0, 255);
|
||||
|
@ -8,10 +8,8 @@ import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class StringMan {
|
||||
@ -37,10 +35,8 @@ public class StringMan {
|
||||
}
|
||||
|
||||
public static boolean containsAny(CharSequence sequence, String any) {
|
||||
for (int i = 0; i < sequence.length(); i++) {
|
||||
if (any.indexOf(sequence.charAt(i)) != -1) return true;
|
||||
}
|
||||
return false;
|
||||
return IntStream.range(0, sequence.length())
|
||||
.anyMatch(i -> any.indexOf(sequence.charAt(i)) != -1);
|
||||
}
|
||||
|
||||
public static boolean containsIgnoreCase(String haystack, String needle) {
|
||||
@ -122,14 +118,11 @@ public class StringMan {
|
||||
int len = string.length();
|
||||
for (int i = len - 1; i >= 0; i--) {
|
||||
char c = string.charAt(i);
|
||||
switch (c) {
|
||||
case '-':
|
||||
val = -val;
|
||||
break;
|
||||
default:
|
||||
val = val + (c - 48) * numIndex;
|
||||
numIndex *= 10;
|
||||
break;
|
||||
if (c == '-') {
|
||||
val = -val;
|
||||
} else {
|
||||
val = val + (c - 48) * numIndex;
|
||||
numIndex *= 10;
|
||||
}
|
||||
}
|
||||
return val;
|
||||
@ -518,7 +511,8 @@ public class StringMan {
|
||||
}
|
||||
|
||||
public static boolean isEqualIgnoreCase(String a, String b) {
|
||||
return ((a == b) || ((a != null) && (b != null) && (a.length() == b.length()) && a.equalsIgnoreCase(b)));
|
||||
return a == b ||
|
||||
a != null && b != null && a.length() == b.length() && a.equalsIgnoreCase(b);
|
||||
}
|
||||
|
||||
public static String repeat(String s, int n) {
|
||||
|
@ -32,7 +32,7 @@ public class WEManager {
|
||||
if (!(currentExtent instanceof NullExtent)) {
|
||||
field.set(parent, new NullExtent((Extent) field.get(parent), reason));
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
throw reason;
|
||||
@ -42,41 +42,33 @@ public class WEManager {
|
||||
cancelEditSafe(parent, reason);
|
||||
}
|
||||
|
||||
public boolean maskContains(final HashSet<RegionWrapper> mask, final int x, final int z) {
|
||||
for (final RegionWrapper region : mask) {
|
||||
if ((x >= region.minX) && (x <= region.maxX) && (z >= region.minZ) && (z <= region.maxZ)) {
|
||||
public boolean maskContains(HashSet<RegionWrapper> mask, int x, int z) {
|
||||
for (RegionWrapper region : mask) {
|
||||
if (x >= region.minX && x <= region.maxX && z >= region.minZ && z <= region.maxZ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean maskContains(RegionWrapper[] mask, final int x, final int z) {
|
||||
public boolean maskContains(RegionWrapper[] mask, int x, int z) {
|
||||
switch (mask.length) {
|
||||
case 0:
|
||||
return false;
|
||||
case 1:
|
||||
return mask[0].isIn(x, z);
|
||||
default:
|
||||
for (final RegionWrapper region : mask) {
|
||||
if (region.isIn(x, z)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return Arrays.stream(mask).anyMatch(region -> region.isIn(x, z));
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Region[] getMask(final FawePlayer<?> player) {
|
||||
public Region[] getMask(FawePlayer<?> player) {
|
||||
return getMask(player, FaweMaskManager.MaskType.getDefaultMaskType());
|
||||
}
|
||||
|
||||
public boolean isIn(int x, int y, int z, Region region) {
|
||||
if (region.contains(x, y, z)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return region.contains(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,7 +77,7 @@ public class WEManager {
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public Region[] getMask(final FawePlayer<?> player, FaweMaskManager.MaskType type) {
|
||||
public Region[] getMask(FawePlayer<?> player, FaweMaskManager.MaskType type) {
|
||||
if (!Settings.IMP.REGION_RESTRICTIONS || player.hasPermission("fawe.bypass") || player.hasPermission("fawe.bypass.regions")) {
|
||||
return new Region[]{RegionWrapper.GLOBAL()};
|
||||
}
|
||||
@ -129,7 +121,7 @@ public class WEManager {
|
||||
}
|
||||
}
|
||||
Set<FaweMask> tmpMasks = new HashSet<>();
|
||||
for (final FaweMaskManager manager : managers) {
|
||||
for (FaweMaskManager manager : managers) {
|
||||
if (player.hasPermission("fawe." + manager.getKey())) {
|
||||
try {
|
||||
if (manager.isExclusive() && !masks.isEmpty()) continue;
|
||||
@ -154,17 +146,19 @@ public class WEManager {
|
||||
}
|
||||
|
||||
|
||||
public boolean intersects(final Region region1, final Region region2) {
|
||||
public boolean intersects(Region region1, Region region2) {
|
||||
BlockVector3 rg1P1 = region1.getMinimumPoint();
|
||||
BlockVector3 rg1P2 = region1.getMaximumPoint();
|
||||
BlockVector3 rg2P1 = region2.getMinimumPoint();
|
||||
BlockVector3 rg2P2 = region2.getMaximumPoint();
|
||||
|
||||
return (rg1P1.getBlockX() <= rg2P2.getBlockX()) && (rg1P2.getBlockX() >= rg2P1.getBlockX()) && (rg1P1.getBlockZ() <= rg2P2.getBlockZ()) && (rg1P2.getBlockZ() >= rg2P1.getBlockZ());
|
||||
return rg1P1.getBlockX() <= rg2P2.getBlockX() && rg1P2.getBlockX() >= rg2P1.getBlockX() &&
|
||||
rg1P1.getBlockZ() <= rg2P2.getBlockZ() &&
|
||||
rg1P2.getBlockZ() >= rg2P1.getBlockZ();
|
||||
}
|
||||
|
||||
public boolean regionContains(final Region selection, final HashSet<Region> mask) {
|
||||
for (final Region region : mask) {
|
||||
public boolean regionContains(Region selection, HashSet<Region> mask) {
|
||||
for (Region region : mask) {
|
||||
if (this.intersects(region, selection)) {
|
||||
return true;
|
||||
}
|
||||
@ -172,29 +166,29 @@ public class WEManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean delay(final FawePlayer<?> player, final String command) {
|
||||
public boolean delay(FawePlayer<?> player, String command) {
|
||||
final long start = System.currentTimeMillis();
|
||||
return this.delay(player, () -> {
|
||||
try {
|
||||
if ((System.currentTimeMillis() - start) > 1000) {
|
||||
if (System.currentTimeMillis() - start > 1000) {
|
||||
BBC.WORLDEDIT_RUN.send(FawePlayer.wrap(player));
|
||||
}
|
||||
TaskManager.IMP.task(() -> {
|
||||
final long start1 = System.currentTimeMillis();
|
||||
player.executeCommand(command.substring(1));
|
||||
TaskManager.IMP.later(() -> SetQueue.IMP.addEmptyTask(() -> {
|
||||
if ((System.currentTimeMillis() - start1) > 1000) {
|
||||
if (System.currentTimeMillis() - start1 > 1000) {
|
||||
BBC.WORLDEDIT_COMPLETE.send(FawePlayer.wrap(player));
|
||||
}
|
||||
}), 2);
|
||||
});
|
||||
} catch (final Exception e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, false, false);
|
||||
}
|
||||
|
||||
public boolean delay(final FawePlayer<?> player, final Runnable whenDone, final boolean delayed, final boolean onlyDelayedExecution) {
|
||||
public boolean delay(FawePlayer<?> player, Runnable whenDone, boolean delayed, boolean onlyDelayedExecution) {
|
||||
final boolean free = SetQueue.IMP.addEmptyTask(null);
|
||||
if (free) {
|
||||
if (delayed) {
|
||||
@ -202,14 +196,14 @@ public class WEManager {
|
||||
whenDone.run();
|
||||
}
|
||||
} else {
|
||||
if ((whenDone != null) && !onlyDelayedExecution) {
|
||||
if (whenDone != null && !onlyDelayedExecution) {
|
||||
whenDone.run();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!delayed && (player != null)) {
|
||||
if (!delayed && player != null) {
|
||||
BBC.WORLDEDIT_DELAYED.send(player);
|
||||
}
|
||||
SetQueue.IMP.addEmptyTask(whenDone);
|
||||
|
@ -1,21 +0,0 @@
|
||||
package com.boydti.fawe.util.chat;
|
||||
|
||||
import com.boydti.fawe.object.FawePlayer;
|
||||
|
||||
public interface ChatManager<T> {
|
||||
T builder();
|
||||
|
||||
void color(Message message, String color);
|
||||
|
||||
void tooltip(Message message, Message... tooltip);
|
||||
|
||||
void command(Message message, String command);
|
||||
|
||||
void text(Message message, String text);
|
||||
|
||||
void send(Message message, FawePlayer player);
|
||||
|
||||
void suggest(Message message, String command);
|
||||
|
||||
void link(Message message, String url);
|
||||
}
|
@ -1,127 +0,0 @@
|
||||
package com.boydti.fawe.util.chat;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.boydti.fawe.object.FawePlayer;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Message {
|
||||
|
||||
private Object builder;
|
||||
private boolean active;
|
||||
|
||||
public Message() {
|
||||
try {
|
||||
reset(Fawe.get().getChatManager());
|
||||
} catch (Throwable e) {
|
||||
Fawe.debug("Doesn't support fancy chat for " + Fawe.imp().getPlatform());
|
||||
Fawe.get().setChatManager(new PlainChatManager());
|
||||
reset(Fawe.get().getChatManager());
|
||||
}
|
||||
active = !(Fawe.get().getChatManager() instanceof PlainChatManager);
|
||||
}
|
||||
|
||||
public Message(String text) {
|
||||
this();
|
||||
text(text);
|
||||
}
|
||||
|
||||
public <T> T $(ChatManager<T> manager) {
|
||||
return (T) this.builder;
|
||||
}
|
||||
|
||||
public <T> T reset(ChatManager<T> manager) {
|
||||
return (T) (this.builder = manager.builder());
|
||||
}
|
||||
|
||||
public boolean supportsInteraction() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public Message text(BBC caption, Object... args) {
|
||||
return text(caption.format(args));
|
||||
}
|
||||
|
||||
public Message text(Serializable text) {
|
||||
Fawe.get().getChatManager().text(this, BBC.color(Objects.toString(text)));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Message link(String text) {
|
||||
Fawe.get().getChatManager().link(this, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Message tooltip(Message... tooltip) {
|
||||
Fawe.get().getChatManager().tooltip(this, tooltip);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Message tooltip(String tooltip) {
|
||||
return tooltip(new Message(tooltip));
|
||||
}
|
||||
|
||||
public Message command(String command) {
|
||||
Fawe.get().getChatManager().command(this, "/" + command);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Message newline() {
|
||||
return text("\n");
|
||||
}
|
||||
|
||||
public Message cmdTip(String commandAndTooltip) {
|
||||
return tooltip(commandAndTooltip).command(commandAndTooltip);
|
||||
}
|
||||
|
||||
public Message linkTip(String linkAndTooltip) {
|
||||
return tooltip(linkAndTooltip).link(linkAndTooltip);
|
||||
}
|
||||
|
||||
public Message cmdOptions(String prefix, String suffix, String... options) {
|
||||
for (int i = 0; i < options.length; i++) {
|
||||
if (i != 0) text(" | ");
|
||||
text("[" + options[i] + "]")
|
||||
.cmdTip(prefix + options[i] + suffix);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Message suggestTip(String commandAndTooltip) {
|
||||
return tooltip(commandAndTooltip).suggest(commandAndTooltip);
|
||||
}
|
||||
|
||||
public Message suggest(String command) {
|
||||
Fawe.get().getChatManager().suggest(this, command);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void send(Actor player) {
|
||||
send(FawePlayer.wrap(player));
|
||||
}
|
||||
|
||||
public void send(FawePlayer player) {
|
||||
Fawe.get().getChatManager().send(this, player);
|
||||
}
|
||||
|
||||
public Message paginate(String baseCommand, int page, int totalPages) {
|
||||
if (!active) {
|
||||
return text(BBC.PAGE_FOOTER.format(baseCommand, page + 1));
|
||||
}
|
||||
if (page < totalPages && page > 1) { // Back | Next
|
||||
this.text("<<").command(baseCommand + " " + (page - 1)).text(" | ").text(">>")
|
||||
.command(baseCommand + " " + (page + 1));
|
||||
} else if (page <= 1 && totalPages > page) { // Next
|
||||
this.text(" -").text(" | ").text(">>")
|
||||
.command(baseCommand + " " + (page + 1));
|
||||
|
||||
} else if (page == totalPages && totalPages > 1) { // Back
|
||||
this.text("<<").command(baseCommand + " " + (page - 1)).text(" | ").text("- ");
|
||||
} else {
|
||||
this.text(" - | - ");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package com.boydti.fawe.util.chat;
|
||||
|
||||
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.boydti.fawe.object.FawePlayer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PlainChatManager implements ChatManager<List<StringBuilder>> {
|
||||
|
||||
@Override
|
||||
public List<StringBuilder> builder() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void color(Message message, String color) {
|
||||
List<StringBuilder> parts = message.$(this);
|
||||
parts.get(parts.size() - 1).insert(0, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tooltip(Message message, Message... tooltips) {}
|
||||
|
||||
@Override
|
||||
public void command(Message message, String command) {}
|
||||
|
||||
@Override
|
||||
public void text(Message message, String text) {
|
||||
message.$(this).add(new StringBuilder(BBC.color(text)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Message plotMessage, FawePlayer player) {
|
||||
StringBuilder built = new StringBuilder();
|
||||
for (StringBuilder sb : plotMessage.$(this)) {
|
||||
built.append(sb);
|
||||
}
|
||||
player.sendMessage(built.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void suggest(Message plotMessage, String command) {}
|
||||
|
||||
@Override
|
||||
public void link(Message message, String url) {}
|
||||
}
|
@ -23,51 +23,44 @@ import java.net.URL;
|
||||
|
||||
public class ImageUtil {
|
||||
|
||||
public static BufferedImage getScaledInstance(BufferedImage img,
|
||||
int targetWidth,
|
||||
int targetHeight,
|
||||
Object hint,
|
||||
boolean higherQuality) {
|
||||
if (img.getHeight() == targetHeight && img.getWidth() == targetWidth) {
|
||||
return img;
|
||||
public static BufferedImage getScaledInstance(BufferedImage image, int targetWidth,
|
||||
int targetHeight, Object hint, boolean higherQuality) {
|
||||
if (image.getHeight() == targetHeight && image.getWidth() == targetWidth) {
|
||||
return image;
|
||||
}
|
||||
int type = img.getTransparency() == Transparency.OPAQUE ?
|
||||
int type = image.getTransparency() == Transparency.OPAQUE ?
|
||||
BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
|
||||
BufferedImage ret = img;
|
||||
int w, h;
|
||||
BufferedImage scaledImage = image;
|
||||
int width, height;
|
||||
if (higherQuality) {
|
||||
// Use multi-step technique: start with original size, then
|
||||
// scale down in multiple passes with drawImage()
|
||||
// until the target size is reached
|
||||
w = ret.getWidth();
|
||||
h = ret.getHeight();
|
||||
width = scaledImage.getWidth();
|
||||
height = scaledImage.getHeight();
|
||||
} else {
|
||||
// Use one-step technique: scale directly from original
|
||||
// size to target size with a single drawImage() call
|
||||
w = targetWidth;
|
||||
h = targetHeight;
|
||||
width = targetWidth;
|
||||
height = targetHeight;
|
||||
}
|
||||
|
||||
do {
|
||||
if (higherQuality && w > targetWidth) {
|
||||
w /= 2;
|
||||
if (w < targetWidth) {
|
||||
w = targetWidth;
|
||||
}
|
||||
} else if (w < targetWidth) {
|
||||
w = targetWidth;
|
||||
if (higherQuality && width > targetWidth) {
|
||||
width /= 2;
|
||||
}
|
||||
if (width < targetWidth) {
|
||||
width = targetWidth;
|
||||
}
|
||||
|
||||
if (higherQuality && h > targetHeight) {
|
||||
h /= 2;
|
||||
if (h < targetHeight) {
|
||||
h = targetHeight;
|
||||
}
|
||||
} else if (h < targetHeight) {
|
||||
h = targetHeight;
|
||||
if (higherQuality && height > targetHeight) {
|
||||
height /= 2;
|
||||
}
|
||||
if (height < targetHeight) {
|
||||
height = targetHeight;
|
||||
}
|
||||
|
||||
BufferedImage tmp = new BufferedImage(w, h, type);
|
||||
BufferedImage tmp = new BufferedImage(width, height, type);
|
||||
Graphics2D g2 = tmp.createGraphics();
|
||||
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hint);
|
||||
g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
|
||||
@ -75,13 +68,13 @@ public class ImageUtil {
|
||||
RenderingHints.VALUE_COLOR_RENDER_SPEED);
|
||||
g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
|
||||
RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);
|
||||
g2.drawImage(ret, 0, 0, w, h, null);
|
||||
g2.drawImage(scaledImage, 0, 0, width, height, null);
|
||||
g2.dispose();
|
||||
|
||||
ret = tmp;
|
||||
} while (w != targetWidth || h != targetHeight);
|
||||
scaledImage = tmp;
|
||||
} while (width != targetWidth || height != targetHeight);
|
||||
|
||||
return ret;
|
||||
return scaledImage;
|
||||
}
|
||||
|
||||
public static void fadeAlpha(BufferedImage image) {
|
||||
@ -207,14 +200,14 @@ public class ImageUtil {
|
||||
throw new IOException("Failed to read " + url + ", please try again later");
|
||||
}
|
||||
return img;
|
||||
} else if (arg.startsWith("file:/")) {
|
||||
}
|
||||
if (arg.startsWith("file:/")) {
|
||||
arg = arg.replaceFirst("file:/+", "");
|
||||
File file = MainUtil.getFile(MainUtil.getFile(Fawe.imp().getDirectory(),
|
||||
Settings.IMP.PATHS.HEIGHTMAP), arg);
|
||||
return MainUtil.readImage(file);
|
||||
} else {
|
||||
throw new InputParseException("Invalid image " + arg);
|
||||
}
|
||||
throw new InputParseException("Invalid image " + arg);
|
||||
} catch (IOException e) {
|
||||
throw new InputParseException(e.getMessage());
|
||||
}
|
||||
@ -227,7 +220,8 @@ public class ImageUtil {
|
||||
arg = "https://i.imgur.com/" + arg.split("imgur.com/")[1] + ".png";
|
||||
}
|
||||
return new URL(arg).toURI();
|
||||
} else if (arg.startsWith("file:/")) {
|
||||
}
|
||||
if (arg.startsWith("file:/")) {
|
||||
arg = arg.replaceFirst("file:/+", "");
|
||||
File file = MainUtil.getFile(MainUtil.getFile(Fawe.imp().getDirectory(),
|
||||
Settings.IMP.PATHS.HEIGHTMAP), arg);
|
||||
@ -238,9 +232,8 @@ public class ImageUtil {
|
||||
throw new InputParseException("File is a directory " + file);
|
||||
}
|
||||
return file.toURI();
|
||||
} else {
|
||||
throw new InputParseException("Invalid image " + arg);
|
||||
}
|
||||
throw new InputParseException("Invalid image " + arg);
|
||||
} catch (IOException | URISyntaxException e) {
|
||||
throw new InputParseException(e.getMessage());
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public class TaskBuilder extends Metadatable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public TaskBuilder async(ReceiveTask task) {
|
||||
public TaskBuilder async(ReceiveTask<Object> task) {
|
||||
tasks.add(RunnableTask.adapt(task, TaskType.ASYNC));
|
||||
return this;
|
||||
}
|
||||
@ -53,7 +53,7 @@ public class TaskBuilder extends Metadatable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public TaskBuilder sync(ReceiveTask task) {
|
||||
public TaskBuilder sync(ReceiveTask<Object> task) {
|
||||
tasks.add(RunnableTask.adapt(task, TaskType.SYNC));
|
||||
return this;
|
||||
}
|
||||
@ -95,7 +95,7 @@ public class TaskBuilder extends Metadatable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public TaskBuilder syncParallel(ReceiveTask run) {
|
||||
public TaskBuilder syncParallel(ReceiveTask<Object> run) {
|
||||
tasks.add(RunnableTask.adapt(run, TaskType.SYNC_PARALLEL));
|
||||
return this;
|
||||
}
|
||||
@ -122,7 +122,7 @@ public class TaskBuilder extends Metadatable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public TaskBuilder asyncParallel(ReceiveTask run) {
|
||||
public TaskBuilder asyncParallel(ReceiveTask<Object> run) {
|
||||
tasks.add(RunnableTask.adapt(run, TaskType.ASYNC_PARALLEL));
|
||||
return this;
|
||||
}
|
||||
@ -151,7 +151,7 @@ public class TaskBuilder extends Metadatable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public TaskBuilder syncWhenFree(ReceiveTask run) {
|
||||
public TaskBuilder syncWhenFree(ReceiveTask<Object> run) {
|
||||
tasks.add(RunnableTask.adapt(run, TaskType.SYNC_WHEN_FREE));
|
||||
return this;
|
||||
}
|
||||
@ -363,7 +363,7 @@ public class TaskBuilder extends Metadatable {
|
||||
};
|
||||
}
|
||||
|
||||
public static RunnableTask adapt(final ReceiveTask task, TaskType type) {
|
||||
public static RunnableTask adapt(final ReceiveTask<Object> task, TaskType type) {
|
||||
return new RunnableTask(type) {
|
||||
@Override
|
||||
public Object exec(Object previous) {
|
||||
|
Reference in New Issue
Block a user