use of com.sk89q.worldedit.extension.platform.Actor in project Prism-Bukkit by prism.
the class PrismBlockEditHandler method wrapForLogging.
/**
* Wrap and edit session so it can be logged.
*
* @param event EditSessionEvent
*/
@Subscribe
public void wrapForLogging(EditSessionEvent event) {
if (event.getStage().equals(EditSession.Stage.BEFORE_CHANGE)) {
Actor actor = event.getActor();
org.bukkit.World world = Bukkit.getWorld(event.getWorld().getName());
if (actor != null && actor.isPlayer() && world != null) {
event.setExtent(new PrismWorldEditLogger(actor, event.getExtent(), world));
}
}
}
use of com.sk89q.worldedit.extension.platform.Actor in project CoreProtect by PlayPro.
the class CoreProtectEditSessionEvent method wrapForLogging.
@Subscribe
public void wrapForLogging(EditSessionEvent event) {
Actor actor = event.getActor();
World world = event.getWorld();
if (actor != null && event.getStage() == (isFAWE ? Stage.BEFORE_HISTORY : Stage.BEFORE_CHANGE)) {
event.setExtent(new CoreProtectLogger(actor, world, event.getExtent()));
}
}
use of com.sk89q.worldedit.extension.platform.Actor in project FastAsyncWorldEdit by IntellectualSites.
the class Settings method getLimit.
public FaweLimit getLimit(Actor actor) {
FaweLimit limit;
if (actor.hasPermission("fawe.limit.*") || actor.hasPermission("fawe.bypass")) {
limit = FaweLimit.MAX.copy();
} else {
limit = new FaweLimit();
}
ArrayList<String> keys = new ArrayList<>(LIMITS.getSections());
if (keys.remove("default")) {
keys.add("default");
}
boolean limitFound = false;
for (String key : keys) {
if (actor.hasPermission("fawe.limit." + key) || !limitFound && key.equals("default")) {
limitFound = true;
LIMITS newLimit = LIMITS.get(key);
limit.MAX_ACTIONS = Math.max(limit.MAX_ACTIONS, newLimit.MAX_ACTIONS != -1 ? newLimit.MAX_ACTIONS : Integer.MAX_VALUE);
limit.MAX_CHANGES = Math.max(limit.MAX_CHANGES, newLimit.MAX_CHANGES != -1 ? newLimit.MAX_CHANGES : Long.MAX_VALUE);
limit.MAX_BLOCKSTATES = Math.max(limit.MAX_BLOCKSTATES, newLimit.MAX_BLOCKSTATES != -1 ? newLimit.MAX_BLOCKSTATES : Integer.MAX_VALUE);
limit.MAX_CHECKS = Math.max(limit.MAX_CHECKS, newLimit.MAX_CHECKS != -1 ? newLimit.MAX_CHECKS : Long.MAX_VALUE);
limit.MAX_ENTITIES = Math.max(limit.MAX_ENTITIES, newLimit.MAX_ENTITIES != -1 ? newLimit.MAX_ENTITIES : Integer.MAX_VALUE);
limit.MAX_FAILS = Math.max(limit.MAX_FAILS, newLimit.MAX_FAILS != -1 ? newLimit.MAX_FAILS : Integer.MAX_VALUE);
limit.MAX_ITERATIONS = Math.max(limit.MAX_ITERATIONS, newLimit.MAX_ITERATIONS != -1 ? newLimit.MAX_ITERATIONS : Integer.MAX_VALUE);
limit.MAX_HISTORY = Math.max(limit.MAX_HISTORY, newLimit.MAX_HISTORY_MB != -1 ? newLimit.MAX_HISTORY_MB : Integer.MAX_VALUE);
limit.MAX_EXPRESSION_MS = Math.max(limit.MAX_EXPRESSION_MS, newLimit.MAX_EXPRESSION_MS != -1 ? newLimit.MAX_EXPRESSION_MS : Integer.MAX_VALUE);
limit.INVENTORY_MODE = Math.min(limit.INVENTORY_MODE, newLimit.INVENTORY_MODE);
limit.SPEED_REDUCTION = Math.min(limit.SPEED_REDUCTION, newLimit.SPEED_REDUCTION);
limit.FAST_PLACEMENT |= newLimit.FAST_PLACEMENT;
limit.CONFIRM_LARGE &= newLimit.CONFIRM_LARGE;
limit.RESTRICT_HISTORY_TO_REGIONS &= newLimit.RESTRICT_HISTORY_TO_REGIONS;
if (limit.STRIP_NBT == null) {
limit.STRIP_NBT = newLimit.STRIP_NBT.isEmpty() ? Collections.emptySet() : new HashSet<>(newLimit.STRIP_NBT);
} else if (limit.STRIP_NBT.isEmpty() || newLimit.STRIP_NBT.isEmpty()) {
limit.STRIP_NBT = Collections.emptySet();
} else {
limit.STRIP_NBT = new HashSet<>(limit.STRIP_NBT);
limit.STRIP_NBT.retainAll(newLimit.STRIP_NBT);
if (limit.STRIP_NBT.isEmpty()) {
limit.STRIP_NBT = Collections.emptySet();
}
}
limit.UNIVERSAL_DISALLOWED_BLOCKS &= newLimit.UNIVERSAL_DISALLOWED_BLOCKS;
if (limit.DISALLOWED_BLOCKS == null) {
limit.DISALLOWED_BLOCKS = newLimit.DISALLOWED_BLOCKS.isEmpty() ? Collections.emptySet() : new HashSet<>(newLimit.DISALLOWED_BLOCKS);
} else if (limit.DISALLOWED_BLOCKS.isEmpty() || newLimit.DISALLOWED_BLOCKS.isEmpty()) {
limit.DISALLOWED_BLOCKS = Collections.emptySet();
} else {
limit.DISALLOWED_BLOCKS = new HashSet<>(limit.DISALLOWED_BLOCKS);
limit.DISALLOWED_BLOCKS.retainAll(newLimit.DISALLOWED_BLOCKS.stream().map(s -> s.contains(":") ? s.toLowerCase(Locale.ROOT) : ("minecraft:" + s).toLowerCase(Locale.ROOT)).collect(Collectors.toSet()));
if (limit.DISALLOWED_BLOCKS.isEmpty()) {
limit.DISALLOWED_BLOCKS = Collections.emptySet();
}
}
if (limit.REMAP_PROPERTIES == null) {
limit.REMAP_PROPERTIES = newLimit.REMAP_PROPERTIES.isEmpty() ? Collections.emptySet() : newLimit.REMAP_PROPERTIES.stream().flatMap(s -> {
String propertyStr = s.substring(0, s.indexOf('['));
List<Property<?>> properties = BlockTypesCache.getAllProperties().get(propertyStr.toLowerCase(Locale.ROOT));
if (properties == null || properties.isEmpty()) {
return Stream.empty();
}
String[] mappings = s.substring(s.indexOf('[') + 1, s.indexOf(']')).split(",");
Set<PropertyRemap<?>> remaps = new HashSet<>();
for (Property<?> property : properties) {
for (String mapping : mappings) {
try {
String[] fromTo = mapping.split(":");
remaps.add(property.getRemap(property.getValueFor(fromTo[0]), property.getValueFor(fromTo[1])));
} catch (IllegalArgumentException ignored) {
// This property is unlikely to be the one being targeted.
break;
}
}
}
return remaps.stream();
}).collect(Collectors.toSet());
} else if (limit.REMAP_PROPERTIES.isEmpty() || newLimit.REMAP_PROPERTIES.isEmpty()) {
limit.REMAP_PROPERTIES = Collections.emptySet();
} else {
limit.REMAP_PROPERTIES = new HashSet<>(limit.REMAP_PROPERTIES);
limit.REMAP_PROPERTIES.retainAll(newLimit.REMAP_PROPERTIES.stream().flatMap(s -> {
String propertyStr = s.substring(0, s.indexOf('['));
List<Property<?>> properties = BlockTypesCache.getAllProperties().get(propertyStr.toLowerCase(Locale.ROOT));
if (properties == null || properties.isEmpty()) {
return Stream.empty();
}
String[] mappings = s.substring(s.indexOf('[') + 1, s.indexOf(']')).split(",");
Set<PropertyRemap<?>> remaps = new HashSet<>();
for (Property<?> property : properties) {
for (String mapping : mappings) {
try {
String[] fromTo = mapping.split(":");
remaps.add(property.getRemap(property.getValueFor(fromTo[0]), property.getValueFor(fromTo[1])));
} catch (IllegalArgumentException ignored) {
// This property is unlikely to be the one being targeted.
break;
}
}
}
return remaps.stream();
}).collect(Collectors.toSet()));
if (limit.REMAP_PROPERTIES.isEmpty()) {
limit.REMAP_PROPERTIES = Collections.emptySet();
}
}
}
}
return limit;
}
use of com.sk89q.worldedit.extension.platform.Actor in project FastAsyncWorldEdit by IntellectualSites.
the class RandomFullClipboardPatternParser method parseFromInput.
@Override
protected Pattern parseFromInput(@Nonnull String[] arguments, ParserContext context) throws InputParseException {
if (arguments.length == 0 || arguments.length > 3) {
throw new InputParseException(Caption.of("fawe.error.command.syntax", TextComponent.of(getPrefix() + "[pattern] (e.g. " + getPrefix() + "[#copy][true][false])")));
}
try {
boolean rotate = arguments.length >= 2 && Boolean.getBoolean(arguments[1]);
boolean flip = arguments.length == 3 && Boolean.getBoolean(arguments[2]);
List<ClipboardHolder> clipboards;
if ("#copy".startsWith(arguments[0].toUpperCase(Locale.ROOT)) || "#clipboard".startsWith(arguments[0].toUpperCase(Locale.ROOT))) {
ClipboardHolder clipboard = context.requireSession().getExistingClipboard();
if (clipboard == null) {
throw new InputParseException(Caption.of("fawe.error.parse.no-clipboard", getPrefix()));
}
clipboards = Collections.singletonList(clipboard);
} else {
Actor player = context.requireActor();
MultiClipboardHolder multi = ClipboardFormats.loadAllFromInput(player, arguments[0], ClipboardFormats.findByAlias("fast"), false);
if (multi == null) {
multi = ClipboardFormats.loadAllFromInput(player, arguments[0], ClipboardFormats.findByAlias("mcedit"), false);
}
if (multi == null) {
multi = ClipboardFormats.loadAllFromInput(player, arguments[0], ClipboardFormats.findByAlias("sponge"), false);
}
if (multi == null) {
throw new InputParseException(Caption.of("fawe.error.parse.no-clipboard-source", arguments[0]));
}
clipboards = multi.getHolders();
}
return new RandomFullClipboardPattern(clipboards, rotate, flip);
} catch (IOException e) {
throw new InputParseException(TextComponent.of(e.getMessage()), e);
}
}
use of com.sk89q.worldedit.extension.platform.Actor in project FastAsyncWorldEdit by IntellectualSites.
the class OffsetConverter method convert.
@Override
public ConversionResult<BlockVector3> convert(String input, InjectedValueAccess context) {
if (input.startsWith("^")) {
try {
// Looking at a relative vector.
Actor actor = context.injectedValue(Key.of(Actor.class)).orElseThrow(() -> new IllegalStateException("An actor is required to use relative offsets"));
if (!(actor instanceof Locatable)) {
throw new IllegalStateException("Only a locatable actor may use relative offsets");
}
Location location = ((Locatable) actor).getLocation();
return vectorConverter.convert(input.substring(1), context).map(blockVector3s -> blockVector3s.stream().map(vector -> rotateToRelative(location, vector)).collect(Collectors.toList()));
} catch (IllegalStateException e) {
return FailedConversion.from(e);
}
} else {
return directionVectorConverter.convert(input, context).orElse(vectorConverter.convert(input, context));
}
}
Aggregations