Merge remote-tracking branch 'upstream/master' into breaking

This commit is contained in:
Jesse Boyd
2019-04-03 16:53:34 +11:00
281 changed files with 5963 additions and 5444 deletions

View File

@ -208,6 +208,9 @@ public class Location extends Vector3 {
* @return the direction vector
*/
public Vector3 getDirection() {
if (Float.isNaN(getYaw()) && Float.isNaN(getPitch())) {
return Vector3.ZERO;
}
double yaw = Math.toRadians(this.getYaw());
double pitch = Math.toRadians(this.getPitch());
double xz = Math.cos(pitch);

View File

@ -1,283 +1,282 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// $Id$
package com.sk89q.worldedit.util;
import com.google.common.collect.Lists;
import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import com.sk89q.worldedit.world.snapshot.SnapshotRepository;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
/**
* Simple LocalConfiguration that loads settings using
* {@code java.util.Properties}.
*/
public class PropertiesConfiguration extends LocalConfiguration {
private static final Logger log = Logger.getLogger(PropertiesConfiguration.class.getCanonicalName());
protected Properties properties;
protected File path;
/**
* Construct the object. The configuration isn't loaded yet.
*
* @param path the path tot he configuration
*/
public PropertiesConfiguration(File path) {
this.path = path;
properties = new Properties();
}
@Override
public void load() {
try (InputStream stream = new FileInputStream(path)) {
properties.load(stream);
} catch (FileNotFoundException ignored) {
} catch (IOException e) {
log.log(Level.WARNING, "Failed to read configuration", e);
}
loadExtra();
profile = getBool("profile", profile);
disallowedBlocks =
new HashSet<>(getStringSet("limits.disallowed-blocks", getDefaultDisallowedBlocks()));
allowedDataCycleBlocks =
new HashSet<>(getStringSet("limits.allowed-data-cycle-blocks", null));
defaultChangeLimit = getInt("default-max-changed-blocks", defaultChangeLimit);
maxChangeLimit = getInt("max-changed-blocks", maxChangeLimit);
defaultMaxPolygonalPoints = getInt("default-max-polygon-points", defaultMaxPolygonalPoints);
maxPolygonalPoints = getInt("max-polygon-points", maxPolygonalPoints);
defaultMaxPolyhedronPoints = getInt("default-max-polyhedron-points", defaultMaxPolyhedronPoints);
maxPolyhedronPoints = getInt("max-polyhedron-points", maxPolyhedronPoints);
shellSaveType = getString("shell-save-type", shellSaveType);
maxRadius = getInt("max-radius", maxRadius);
maxSuperPickaxeSize = getInt("max-super-pickaxe-size", maxSuperPickaxeSize);
maxBrushRadius = getInt("max-brush-radius", maxBrushRadius);
logCommands = getBool("log-commands", logCommands);
logFile = getString("log-file", logFile);
logFormat = getString("log-format", logFormat);
registerHelp = getBool("register-help", registerHelp);
wandItem = getString("wand-item", wandItem);
try {
wandItem = LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(wandItem)).getId();
} catch (Throwable e) {}
superPickaxeDrop = getBool("super-pickaxe-drop-items", superPickaxeDrop);
superPickaxeManyDrop = getBool("super-pickaxe-many-drop-items", superPickaxeManyDrop);
noDoubleSlash = getBool("no-double-slash", noDoubleSlash);
useInventory = getBool("use-inventory", useInventory);
useInventoryOverride = getBool("use-inventory-override", useInventoryOverride);
useInventoryCreativeOverride = getBool("use-inventory-creative-override", useInventoryCreativeOverride);
navigationWand = getString("nav-wand-item", navigationWand);
try {
navigationWand = LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(navigationWand)).getId();
} catch (Throwable e) {}
navigationWandMaxDistance = getInt("nav-wand-distance", navigationWandMaxDistance);
navigationUseGlass = getBool("nav-use-glass", navigationUseGlass);
scriptTimeout = getInt("scripting-timeout", scriptTimeout);
saveDir = getString("schematic-save-dir", saveDir);
scriptsDir = getString("craftscript-dir", scriptsDir);
butcherDefaultRadius = getInt("butcher-default-radius", butcherDefaultRadius);
butcherMaxRadius = getInt("butcher-max-radius", butcherMaxRadius);
allowSymlinks = getBool("allow-symbolic-links", allowSymlinks);
LocalSession.MAX_HISTORY_SIZE = Math.max(15, getInt("history-size", 15));
String snapshotsDir = getString("snapshots-dir", "");
if (!snapshotsDir.isEmpty()) {
snapshotRepo = new SnapshotRepository(snapshotsDir);
}
path.getParentFile().mkdirs();
try (OutputStream output = new FileOutputStream(path)) {
properties.store(output, "Don't put comments; they get removed");
} catch (IOException e) {
log.log(Level.WARNING, "Failed to write configuration", e);
}
}
/**
* Called to load extra configuration.
*/
protected void loadExtra() {
}
/**
* Get a string value.
*
* @param key the key
* @param def the default value
* @return the value
*/
protected String getString(String key, String def) {
if (def == null) {
def = "";
}
String val = properties.getProperty(key);
if (val == null) {
properties.setProperty(key, def);
return def;
} else {
return val;
}
}
/**
* Get a boolean value.
*
* @param key the key
* @param def the default value
* @return the value
*/
protected boolean getBool(String key, boolean def) {
String val = properties.getProperty(key);
if (val == null) {
properties.setProperty(key, def ? "true" : "false");
return def;
} else {
return val.equalsIgnoreCase("true")
|| val.equals("1");
}
}
/**
* Get an integer value.
*
* @param key the key
* @param def the default value
* @return the value
*/
protected int getInt(String key, int def) {
String val = properties.getProperty(key);
if (val == null) {
properties.setProperty(key, String.valueOf(def));
return def;
} else {
try {
return Integer.parseInt(val);
} catch (NumberFormatException e) {
properties.setProperty(key, String.valueOf(def));
return def;
}
}
}
/**
* Get a double value.
*
* @param key the key
* @param def the default value
* @return the value
*/
protected double getDouble(String key, double def) {
String val = properties.getProperty(key);
if (val == null) {
properties.setProperty(key, String.valueOf(def));
return def;
} else {
try {
return Double.parseDouble(val);
} catch (NumberFormatException e) {
properties.setProperty(key, String.valueOf(def));
return def;
}
}
}
/**
* Get a double value.
*
* @param key the key
* @param def the default value
* @return the value
*/
protected Set<Integer> getIntSet(String key, int[] def) {
String val = properties.getProperty(key);
if (val == null) {
properties.setProperty(key, StringUtil.joinString(def, ",", 0));
Set<Integer> set = new HashSet<>();
for (int i : def) {
set.add(i);
}
return set;
} else {
Set<Integer> set = new HashSet<>();
String[] parts = val.split(",");
for (String part : parts) {
try {
int v = Integer.parseInt(part.trim());
set.add(v);
} catch (NumberFormatException ignored) {
}
}
return set;
}
}
/**
* Get a String set.
*
* @param key the key
* @param def the default value
* @return the value
*/
protected Set<String> getStringSet(String key, String[] def) {
String val = properties.getProperty(key);
if (val == null) {
properties.setProperty(key, StringUtil.joinString(def, ",", 0));
return new HashSet<>(Arrays.asList(def));
} else {
Set<String> set = new HashSet<>();
String[] parts = val.split(",");
for (String part : parts) {
try {
String v = part.trim();
set.add(v);
} catch (NumberFormatException ignored) {
}
}
return set;
}
}
}
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// $Id$
package com.sk89q.worldedit.util;
import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.util.report.Unreported;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import com.sk89q.worldedit.world.snapshot.SnapshotRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
/**
* Simple LocalConfiguration that loads settings using
* {@code java.util.Properties}.
*/
public class PropertiesConfiguration extends LocalConfiguration {
@Unreported private static final Logger log = LoggerFactory.getLogger(PropertiesConfiguration.class);
@Unreported protected Properties properties;
@Unreported protected File path;
/**
* Construct the object. The configuration isn't loaded yet.
*
* @param path the path tot he configuration
*/
public PropertiesConfiguration(File path) {
this.path = path;
properties = new Properties();
}
@Override
public void load() {
try (InputStream stream = new FileInputStream(path)) {
properties.load(stream);
} catch (FileNotFoundException ignored) {
} catch (IOException e) {
log.warn("Failed to read configuration", e);
}
loadExtra();
profile = getBool("profile", profile);
traceUnflushedSessions = getBool("trace-unflushed-sessions", traceUnflushedSessions);
disallowedBlocks = getStringSet("disallowed-blocks", getDefaultDisallowedBlocks());
defaultChangeLimit = getInt("default-max-changed-blocks", defaultChangeLimit);
maxChangeLimit = getInt("max-changed-blocks", maxChangeLimit);
defaultMaxPolygonalPoints = getInt("default-max-polygon-points", defaultMaxPolygonalPoints);
maxPolygonalPoints = getInt("max-polygon-points", maxPolygonalPoints);
defaultMaxPolyhedronPoints = getInt("default-max-polyhedron-points", defaultMaxPolyhedronPoints);
maxPolyhedronPoints = getInt("max-polyhedron-points", maxPolyhedronPoints);
shellSaveType = getString("shell-save-type", shellSaveType);
maxRadius = getInt("max-radius", maxRadius);
maxSuperPickaxeSize = getInt("max-super-pickaxe-size", maxSuperPickaxeSize);
maxBrushRadius = getInt("max-brush-radius", maxBrushRadius);
logCommands = getBool("log-commands", logCommands);
logFile = getString("log-file", logFile);
logFormat = getString("log-format", logFormat);
registerHelp = getBool("register-help", registerHelp);
wandItem = getString("wand-item", wandItem);
try {
wandItem = LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(wandItem)).getId();
} catch (Throwable e) {
}
superPickaxeDrop = getBool("super-pickaxe-drop-items", superPickaxeDrop);
superPickaxeManyDrop = getBool("super-pickaxe-many-drop-items", superPickaxeManyDrop);
noDoubleSlash = getBool("no-double-slash", noDoubleSlash);
useInventory = getBool("use-inventory", useInventory);
useInventoryOverride = getBool("use-inventory-override", useInventoryOverride);
useInventoryCreativeOverride = getBool("use-inventory-creative-override", useInventoryCreativeOverride);
navigationWand = getString("nav-wand-item", navigationWand);
try {
navigationWand = LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(navigationWand)).getId();
} catch (Throwable e) {
}
navigationWandMaxDistance = getInt("nav-wand-distance", navigationWandMaxDistance);
navigationUseGlass = getBool("nav-use-glass", navigationUseGlass);
scriptTimeout = getInt("scripting-timeout", scriptTimeout);
calculationTimeout = getInt("calculation-timeout", calculationTimeout);
maxCalculationTimeout = getInt("max-calculation-timeout", maxCalculationTimeout);
saveDir = getString("schematic-save-dir", saveDir);
scriptsDir = getString("craftscript-dir", scriptsDir);
butcherDefaultRadius = getInt("butcher-default-radius", butcherDefaultRadius);
butcherMaxRadius = getInt("butcher-max-radius", butcherMaxRadius);
allowSymlinks = getBool("allow-symbolic-links", allowSymlinks);
serverSideCUI = getBool("server-side-cui", serverSideCUI);
LocalSession.MAX_HISTORY_SIZE = Math.max(15, getInt("history-size", 15));
String snapshotsDir = getString("snapshots-dir", "");
if (!snapshotsDir.isEmpty()) {
snapshotRepo = new SnapshotRepository(snapshotsDir);
}
path.getParentFile().mkdirs();
try (OutputStream output = new FileOutputStream(path)) {
properties.store(output, "Don't put comments; they get removed");
} catch (IOException e) {
log.warn("Failed to write configuration", e);
}
}
/**
* Called to load extra configuration.
*/
protected void loadExtra() {
}
/**
* Get a string value.
*
* @param key the key
* @param def the default value
* @return the value
*/
protected String getString(String key, String def) {
if (def == null) {
def = "";
}
String val = properties.getProperty(key);
if (val == null) {
properties.setProperty(key, def);
return def;
} else {
return val;
}
}
/**
* Get a boolean value.
*
* @param key the key
* @param def the default value
* @return the value
*/
protected boolean getBool(String key, boolean def) {
String val = properties.getProperty(key);
if (val == null) {
properties.setProperty(key, def ? "true" : "false");
return def;
} else {
return val.equalsIgnoreCase("true")
|| val.equals("1");
}
}
/**
* Get an integer value.
*
* @param key the key
* @param def the default value
* @return the value
*/
protected int getInt(String key, int def) {
String val = properties.getProperty(key);
if (val == null) {
properties.setProperty(key, String.valueOf(def));
return def;
} else {
try {
return Integer.parseInt(val);
} catch (NumberFormatException e) {
properties.setProperty(key, String.valueOf(def));
return def;
}
}
}
/**
* Get a double value.
*
* @param key the key
* @param def the default value
* @return the value
*/
protected double getDouble(String key, double def) {
String val = properties.getProperty(key);
if (val == null) {
properties.setProperty(key, String.valueOf(def));
return def;
} else {
try {
return Double.parseDouble(val);
} catch (NumberFormatException e) {
properties.setProperty(key, String.valueOf(def));
return def;
}
}
}
/**
* Get a double value.
*
* @param key the key
* @param def the default value
* @return the value
*/
protected Set<Integer> getIntSet(String key, int[] def) {
String val = properties.getProperty(key);
if (val == null) {
properties.setProperty(key, StringUtil.joinString(def, ",", 0));
Set<Integer> set = new HashSet<>();
for (int i : def) {
set.add(i);
}
return set;
} else {
Set<Integer> set = new HashSet<>();
String[] parts = val.split(",");
for (String part : parts) {
try {
int v = Integer.parseInt(part.trim());
set.add(v);
} catch (NumberFormatException ignored) {
}
}
return set;
}
}
/**
* Get a String set.
*
* @param key the key
* @param def the default value
* @return the value
*/
protected Set<String> getStringSet(String key, String[] def) {
String val = properties.getProperty(key);
if (val == null) {
properties.setProperty(key, StringUtil.joinString(def, ",", 0));
return new HashSet<>(Arrays.asList(def));
} else {
Set<String> set = new HashSet<>();
String[] parts = val.split(",");
for (String part : parts) {
try {
String v = part.trim();
set.add(v);
} catch (NumberFormatException ignored) {
}
}
return set;
}
}
}

View File

@ -26,11 +26,10 @@ import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.session.SessionManager;
import com.sk89q.worldedit.util.report.Unreported;
import com.sk89q.worldedit.world.snapshot.SnapshotRepository;
import org.slf4j.Logger;
import java.io.IOException;
import java.util.HashSet;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* A less simple implementation of {@link LocalConfiguration}
@ -51,10 +50,11 @@ public class YAMLConfiguration extends LocalConfiguration {
try {
config.load();
} catch (IOException e) {
logger.log(Level.WARNING, "Error loading WorldEdit configuration", e);
logger.warn("Error loading WorldEdit configuration", e);
}
profile = config.getBoolean("debug", profile);
traceUnflushedSessions = config.getBoolean("debugging.trace-unflushed-sessions", traceUnflushedSessions);
wandItem = convertLegacyItem(config.getString("wand-item", wandItem));
defaultChangeLimit = Math.max(-1, config.getInt(
@ -79,8 +79,7 @@ public class YAMLConfiguration extends LocalConfiguration {
butcherMaxRadius = Math.max(-1, config.getInt("limits.butcher-radius.maximum", butcherMaxRadius));
disallowedBlocks = new HashSet<>(config.getStringList("limits.disallowed-blocks", Lists.newArrayList(getDefaultDisallowedBlocks())));
allowedDataCycleBlocks =
new HashSet<>(config.getStringList("limits.allowed-data-cycle-blocks", null));
allowedDataCycleBlocks = new HashSet<>(config.getStringList("limits.allowed-data-cycle-blocks", null));
registerHelp = config.getBoolean("register-help", true);
logCommands = config.getBoolean("logging.log-commands", logCommands);
@ -107,6 +106,9 @@ public class YAMLConfiguration extends LocalConfiguration {
scriptTimeout = config.getInt("scripting.timeout", scriptTimeout);
scriptsDir = config.getString("scripting.dir", scriptsDir);
calculationTimeout = config.getInt("calculation.timeout", calculationTimeout);
maxCalculationTimeout = config.getInt("calculation.max-timeout", maxCalculationTimeout);
saveDir = config.getString("saving.dir", saveDir);
allowSymlinks = config.getBoolean("files.allow-symbolic-links", false);
@ -114,6 +116,7 @@ public class YAMLConfiguration extends LocalConfiguration {
SessionManager.EXPIRATION_GRACE = config.getInt("history.expiration", 10) * 60 * 1000;
showHelpInfo = config.getBoolean("show-help-on-first-use", true);
serverSideCUI = config.getBoolean("server-side-cui", true);
String snapshotsDir = config.getString("snapshots.directory", "");
if (!snapshotsDir.isEmpty()) {

View File

@ -1,114 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.util.collection;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
/**
* A fast iterator for lists that uses an internal index integer
* and caches the size of the list. The size of the list cannot change
* during iteration and {@link Iterator#remove()} is not supported.
*
* <p>The iterator in Java, at least in older Java versions, is very slow,
* causing a significant amount of time in operations in WorldEdit
* being spent on {@link Iterator#hasNext()}. In contrast, the iterator
* implemented by this class is very quick, as long as
* {@link List#get(int)} is fast.</p>
*
* @param <E> the element
*/
public class FastListIterator<E> implements Iterator<E> {
private final List<E> list;
private int index;
private final int size;
private final int increment;
/**
* Create a new fast iterator.
*
* @param list the list
* @param index the index to start from
* @param size the size of the list
* @param increment the increment amount (i.e. 1 or -1)
*/
private FastListIterator(List<E> list, int index, int size, int increment) {
checkNotNull(list);
checkArgument(size >= 0, "size >= 0 required");
checkArgument(index >= 0, "index >= 0 required");
this.list = list;
this.index = index;
this.size = size;
this.increment = increment;
}
@Override
public boolean hasNext() {
return index >= 0 && index < size;
}
@Override
public E next() {
if (hasNext()) {
E entry = list.get(index);
index += increment;
return entry;
} else {
throw new NoSuchElementException();
}
}
@Override
public void remove() {
throw new UnsupportedOperationException("Not supported");
}
/**
* Create a new forward iterator for the given list.
*
* @param list the list
* @param <E> the element
* @return an iterator
*/
public static <E> Iterator<E> forwardIterator(List<E> list) {
return new FastListIterator<>(list, 0, list.size(), 1);
}
/**
* Create a new reverse iterator for the given list.
*
* @param list the list
* @param <E> the element
* @return an iterator
*/
public static <E> Iterator<E> reverseIterator(List<E> list) {
if (!list.isEmpty()) {
return new FastListIterator<>(list, list.size() - 1, list.size(), -1);
} else {
return new FastListIterator<>(list, 0, 0, -1);
}
}
}

View File

@ -1,94 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.util.collection;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
/**
* An {@link ArrayList} that takes {@link Map.Entry}-like tuples. This class
* exists for legacy reasons.
*
* @param <A> the first type in the tuple
* @param <B> the second type in the tuple
*/
public class TupleArrayList<A, B> extends ArrayList<Map.Entry<A, B>> {
/**
* Add an item to the list.
*
* @param a the 'key'
* @param b the 'value'
*/
public void put(A a, B b) {
add(new Tuple<>(a, b));
}
/**
* Return an entry iterator that traverses in the reverse direction.
*
* @param reverse true to return the reverse iterator
* @return an entry iterator
*/
public Iterator<Map.Entry<A, B>> iterator(boolean reverse) {
return reverse ? reverseIterator() : iterator();
}
@Override
public Iterator<Map.Entry<A, B>> iterator() {
return FastListIterator.forwardIterator(this);
}
/**
* Return an entry iterator that traverses in the reverse direction.
*
* @return an entry iterator
*/
public Iterator<Map.Entry<A, B>> reverseIterator() {
return FastListIterator.reverseIterator(this);
}
private static class Tuple<A, B> implements Map.Entry<A, B> {
private A key;
private B value;
private Tuple(A key, B value) {
this.key = key;
this.value = value;
}
@Override
public A getKey() {
return key;
}
@Override
public B getValue() {
return value;
}
@Override
public B setValue(B value) {
throw new UnsupportedOperationException();
}
}
}

View File

@ -19,13 +19,13 @@
package com.sk89q.worldedit.util.eventbus;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import com.google.common.collect.SetMultimap;
import com.google.common.eventbus.DeadEvent;
import com.sk89q.worldedit.internal.annotation.RequiresNewerGuava;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
@ -36,8 +36,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Dispatches events to listeners, and provides ways for listeners to register
@ -53,7 +53,7 @@ import java.util.logging.Logger;
*/
public class EventBus {
private final Logger logger = Logger.getLogger(EventBus.class.getCanonicalName());
private final Logger logger = LoggerFactory.getLogger(EventBus.class);
private final SetMultimap<Class<?>, EventHandler> handlersByType =
Multimaps.newSetMultimap(new HashMap<>(), this::newHandlerSet);
@ -186,8 +186,7 @@ public class EventBus {
try {
handler.handleEvent(event);
} catch (InvocationTargetException e) {
logger.log(Level.SEVERE,
"Could not dispatch event: " + event + " to handler " + handler, e);
logger.error("Could not dispatch event: " + event + " to handler " + handler, e);
}
}

View File

@ -19,23 +19,23 @@
package com.sk89q.worldedit.util.io;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Throwables;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.Closeable;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.ZipFile;
import static com.google.common.base.Preconditions.checkNotNull;
public final class Closer implements Closeable {
private static final Logger logger = Logger.getLogger(Closer.class.getCanonicalName());
private static final Logger logger = LoggerFactory.getLogger(Closer.class);
/**
* The suppressor implementation to use for the current Java version.
@ -218,7 +218,7 @@ public final class Closer implements Closeable {
@Override
public void suppress(Object closeable, Throwable thrown, Throwable suppressed) {
// log to the same place as Closeables
logger.log(Level.WARNING, "Suppressing exception thrown when closing " + closeable, suppressed);
logger.warn("Suppressing exception thrown when closing " + closeable, suppressed);
}
}

View File

@ -1,59 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.util.logging;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
/**
* Adds a WorldEdit prefix to WorldEdit's logger messages using a handler.
*/
public final class WorldEditPrefixHandler extends Handler {
private WorldEditPrefixHandler() {
}
@Override
public void publish(LogRecord record) {
String message = record.getMessage();
if (!message.startsWith("WorldEdit: ") && !message.startsWith("[WorldEdit] ")) {
record.setMessage("[WorldEdit] " + message);
}
}
@Override
public void flush() {
}
@Override
public void close() throws SecurityException {
}
/**
* Add the handler to the following logger name.
*
* @param name the logger name
*/
public static void register(String name) {
Logger.getLogger(name).addHandler(new WorldEditPrefixHandler());
}
}

View File

@ -26,14 +26,14 @@ import com.sk89q.worldedit.command.util.AsyncCommandHelper;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.util.command.parametric.ExceptionConverter;
import com.sk89q.worldedit.util.task.Supervisor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ActorCallbackPaste {
private static final Logger LOGGER = Logger.getLogger(ActorCallbackPaste.class.getSimpleName());
private static final Logger LOGGER = LoggerFactory.getLogger(ActorCallbackPaste.class);
private ActorCallbackPaste() {
}
@ -47,7 +47,7 @@ public class ActorCallbackPaste {
* @param content The content
* @param successMessage The message, formatted with {@link String#format(String, Object...)} on success
*/
public static void pastebin(Supervisor supervisor, final Actor sender, String content, final String successMessage, final ExceptionConverter exceptionConverter) {
public static void pastebin(Supervisor supervisor, final Actor sender, String content, final String successMessage, final ExceptionConverter exceptionConverter) {
ListenableFuture<URL> future = new IncendoPaste("fastasyncworldedit").paste(content);
AsyncCommandHelper.wrap(future, supervisor, sender, exceptionConverter)
@ -62,7 +62,7 @@ public static void pastebin(Supervisor supervisor, final Actor sender, String co
@Override
public void onFailure(Throwable throwable) {
LOGGER.log(Level.WARNING, "Failed to submit pastebin", throwable);
LOGGER.warn("Failed to submit pastebin", throwable);
sender.printError("Failed to submit to a pastebin. Please see console for the error.");
}
});

View File

@ -19,16 +19,17 @@
package com.sk89q.worldedit.util.report;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.logging.Level;
import java.util.logging.Logger;
import static com.google.common.base.Preconditions.checkNotNull;
public class ShallowObjectReport extends DataReport {
private static final Logger log = Logger.getLogger(ShallowObjectReport.class.getCanonicalName());
private static final Logger log = LoggerFactory.getLogger(ShallowObjectReport.class);
public ShallowObjectReport(String title, Object object) {
super(title);
@ -52,7 +53,7 @@ public class ShallowObjectReport extends DataReport {
Object value = field.get(object);
append(field.getName(), String.valueOf(value));
} catch (IllegalAccessException e) {
log.log(Level.WARNING, "Failed to get value of '" + field.getName() + "' on " + type);
log.warn("Failed to get value of '" + field.getName() + "' on " + type);
}
}
}

View File

@ -83,7 +83,7 @@ public class ProgressIterator<V> implements Iterator<V>, ProgressObservable {
* @return an instance
*/
public static <V> ProgressIterator<V> create(Iterator<V> iterator, int count) {
return new ProgressIterator<>(iterator, count);
return new ProgressIterator<V>(iterator, count);
}
/**