Permalink
Browse files

Merge remote-tracking branch 'origin/master' into feature/sponge-1.10.2

  • Loading branch information...
DarkArc committed Jun 29, 2016
2 parents c7309b1 + 6e36b52 commit b5a49b12fc38f5cc788cc949072c8ca0f1c6fbbf
@@ -22,11 +22,7 @@
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.Logging;
-import com.sk89q.worldedit.EditSession;
-import com.sk89q.worldedit.LocalSession;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.WorldEdit;
-import com.sk89q.worldedit.WorldEditException;
+import com.sk89q.worldedit.*;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
@@ -162,8 +158,10 @@ public void paste(Player player, LocalSession session, EditSession editSession,
Operations.completeLegacy(operation);
if (selectPasted) {
- Vector max = to.add(region.getMaximumPoint().subtract(region.getMinimumPoint()));
- RegionSelector selector = new CuboidRegionSelector(player.getWorld(), to, max);
+ Vector clipboardOffset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
+ Vector realTo = to.add(clipboardOffset);
+ Vector max = realTo.add(region.getMaximumPoint().subtract(region.getMinimumPoint()));
+ RegionSelector selector = new CuboidRegionSelector(player.getWorld(), realTo, max);
session.setRegionSelector(player.getWorld(), selector);
selector.learnChanges();
selector.explainRegionAdjust(player, session);
@@ -28,41 +28,15 @@
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
-import com.sk89q.worldedit.command.BiomeCommands;
-import com.sk89q.worldedit.command.BrushCommands;
-import com.sk89q.worldedit.command.ChunkCommands;
-import com.sk89q.worldedit.command.ClipboardCommands;
-import com.sk89q.worldedit.command.GeneralCommands;
-import com.sk89q.worldedit.command.GenerationCommands;
-import com.sk89q.worldedit.command.HistoryCommands;
-import com.sk89q.worldedit.command.NavigationCommands;
-import com.sk89q.worldedit.command.RegionCommands;
-import com.sk89q.worldedit.command.SchematicCommands;
-import com.sk89q.worldedit.command.ScriptingCommands;
-import com.sk89q.worldedit.command.SelectionCommands;
-import com.sk89q.worldedit.command.SnapshotCommands;
-import com.sk89q.worldedit.command.SnapshotUtilCommands;
-import com.sk89q.worldedit.command.SuperPickaxeCommands;
-import com.sk89q.worldedit.command.ToolCommands;
-import com.sk89q.worldedit.command.ToolUtilCommands;
-import com.sk89q.worldedit.command.UtilityCommands;
-import com.sk89q.worldedit.command.WorldEditCommands;
+import com.sk89q.worldedit.command.*;
import com.sk89q.worldedit.command.argument.ReplaceParser;
import com.sk89q.worldedit.command.argument.TreeGeneratorParser;
-import com.sk89q.worldedit.command.composition.ApplyCommand;
-import com.sk89q.worldedit.command.composition.DeformCommand;
-import com.sk89q.worldedit.command.composition.PaintCommand;
-import com.sk89q.worldedit.command.composition.SelectionCommand;
-import com.sk89q.worldedit.command.composition.ShapedBrushCommand;
+import com.sk89q.worldedit.command.composition.*;
import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.event.platform.CommandSuggestionEvent;
import com.sk89q.worldedit.function.factory.Deform;
import com.sk89q.worldedit.function.factory.Deform.Mode;
-import com.sk89q.worldedit.internal.command.ActorAuthorizer;
-import com.sk89q.worldedit.internal.command.CommandLoggingHandler;
-import com.sk89q.worldedit.internal.command.UserCommandCompleter;
-import com.sk89q.worldedit.internal.command.WorldEditBinding;
-import com.sk89q.worldedit.internal.command.WorldEditExceptionConverter;
+import com.sk89q.worldedit.internal.command.*;
import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.util.command.Dispatcher;
import com.sk89q.worldedit.util.command.InvalidUsageException;
@@ -129,7 +103,6 @@
builder.setAuthorizer(new ActorAuthorizer());
builder.setDefaultCompleter(new UserCommandCompleter(platformManager));
builder.addBinding(new WorldEditBinding(worldEdit));
- builder.addExceptionConverter(exceptionConverter);
builder.addInvokeListener(new LegacyCommandsHandler());
builder.addInvokeListener(new CommandLoggingHandler(worldEdit, commandLog));
@@ -267,7 +240,23 @@ public void handleCommand(CommandEvent event) {
long start = System.currentTimeMillis();
try {
- dispatcher.call(Joiner.on(" ").join(split), locals, new String[0]);
+ // This is a bit of a hack, since the call method can only throw CommandExceptions
+ // everything needs to be wrapped at least once. Which means to handle all WorldEdit
+ // exceptions without writing a hook into every dispatcher, we need to unwrap these
+ // exceptions and rethrow their converted form, if their is one.
+ try {
+ dispatcher.call(Joiner.on(" ").join(split), locals, new String[0]);
+ } catch (Throwable t) {
+ // Use the exception converter to convert the exception if any of its causes
+ // can be converted, otherwise throw the original exception
+ Throwable next = t;
+ do {
+ exceptionConverter.convert(next);
+ next = next.getCause();
+ } while (next != null);
+
+ throw t;
+ }
} catch (CommandPermissionsException e) {
actor.printError("You are not permitted to do that. Are you in the right mode?");
} catch (InvalidUsageException e) {
@@ -68,7 +68,7 @@ public DispatcherNode describeAs(String description) {
* @param alias the list of aliases, where the first alias is the primary one
*/
public DispatcherNode register(CommandCallable callable, String... alias) {
- dispatcher.registerCommand(callable, alias);;
+ dispatcher.registerCommand(callable, alias);
return this;
}
@@ -57,7 +57,6 @@
private final Map<Type, Binding> bindings = new HashMap<Type, Binding>();
private final Paranamer paranamer = new CachingParanamer();
private final List<InvokeListener> invokeListeners = new ArrayList<InvokeListener>();
- private final List<ExceptionConverter> exceptionConverters = new ArrayList<ExceptionConverter>();
private Authorizer authorizer = new NullAuthorizer();
private CommandCompleter defaultCompleter = new NullCompleter();
@@ -126,19 +125,6 @@ public void addBinding(Binding binding, Type... type) {
public void addInvokeListener(InvokeListener listener) {
invokeListeners.add(listener);
}
-
- /**
- * Attach an exception converter to this builder in order to wrap unknown
- * {@link Throwable}s into known {@link CommandException}s.
- *
- * <p>Exception converters are called in order that they are registered.</p>
- *
- * @param converter the converter
- * @see ExceptionConverter for an explanation
- */
- public void addExceptionConverter(ExceptionConverter converter) {
- exceptionConverters.add(converter);
- }
/**
* Build a list of commands from methods specially annotated with {@link Command}
@@ -201,15 +187,6 @@ Paranamer getParanamer() {
return invokeListeners;
}
- /**
- * Get the list of exception converters.
- *
- * @return a list of exception converters
- */
- List<ExceptionConverter> getExceptionConverters() {
- return exceptionConverters;
- }
-
/**
* Get the authorizer.
*
@@ -20,30 +20,15 @@
package com.sk89q.worldedit.util.command.parametric;
import com.google.common.primitives.Chars;
-import com.sk89q.minecraft.util.commands.Command;
-import com.sk89q.minecraft.util.commands.CommandContext;
-import com.sk89q.minecraft.util.commands.CommandException;
-import com.sk89q.minecraft.util.commands.CommandLocals;
-import com.sk89q.minecraft.util.commands.CommandPermissions;
-import com.sk89q.minecraft.util.commands.CommandPermissionsException;
-import com.sk89q.minecraft.util.commands.WrappedCommandException;
-import com.sk89q.worldedit.util.command.CommandCallable;
-import com.sk89q.worldedit.util.command.InvalidUsageException;
-import com.sk89q.worldedit.util.command.MissingParameterException;
-import com.sk89q.worldedit.util.command.Parameter;
-import com.sk89q.worldedit.util.command.SimpleDescription;
-import com.sk89q.worldedit.util.command.UnconsumedParameterException;
+import com.sk89q.minecraft.util.commands.*;
+import com.sk89q.worldedit.util.command.*;
import com.sk89q.worldedit.util.command.binding.Switch;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
/**
* The implementation of a {@link CommandCallable} for the {@link ParametricBuilder}.
@@ -255,17 +240,8 @@ public Object call(String stringArguments, CommandLocals locals, String[] parent
String name = parameter.getName();
throw new InvalidUsageException("For parameter '" + name + "': " + e.getMessage(), this);
- } catch (InvocationTargetException e) {
- for (ExceptionConverter converter : builder.getExceptionConverters()) {
- converter.convert(e.getCause());
- }
- throw new WrappedCommandException(e);
- } catch (IllegalArgumentException e) {
- throw new WrappedCommandException(e);
- } catch (CommandException e) {
- throw e;
- } catch (Throwable e) {
- throw new WrappedCommandException(e);
+ } catch (Throwable t) {
+ throw new WrappedCommandException(t);
}
return true;
@@ -42,7 +42,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
-import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;
@@ -54,15 +53,21 @@
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.item.EntityItem;
+import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.IInventory;
import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.network.play.server.SPacketChunkData;
+import net.minecraft.server.management.PlayerChunkMap;
+import net.minecraft.server.management.PlayerChunkMapEntry;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.World;
+import net.minecraft.world.WorldServer;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.Chunk;
+import net.minecraft.world.chunk.IChunkGenerator;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.ChunkProviderServer;
import net.minecraft.world.gen.feature.WorldGenBigMushroom;
@@ -238,6 +243,11 @@ public void dropItem(Vector position, BaseItemStack item) {
@Override
public boolean regenerate(Region region, EditSession editSession) {
+ // Don't even try to regen if it's going to fail.
+ IChunkProvider provider = getWorld().getChunkProvider();
+ if (!(provider instanceof ChunkProviderServer)) {
+ return false;
+ }
BaseBlock[] history = new BaseBlock[256 * (getMaxY() + 1)];
for (Vector2D chunk : region.getChunks()) {
@@ -252,28 +262,29 @@ public boolean regenerate(Region region, EditSession editSession) {
}
}
}
+ PlayerChunkMap playerManager = ((WorldServer) getWorld()).getPlayerChunkMap();
+ List<EntityPlayerMP> oldWatchers = null;
+ Chunk mcChunk = null;
try {
- Set<Vector2D> chunks = region.getChunks();
- IChunkProvider provider = getWorld().getChunkProvider();
- if (!(provider instanceof ChunkProviderServer)) {
- return false;
- }
ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
- for (Vector2D coord : chunks) {
- long pos = ChunkPos.chunkXZ2Int(coord.getBlockX(), coord.getBlockZ());
- Chunk mcChunk;
- if (chunkServer.chunkExists(coord.getBlockX(), coord.getBlockZ())) {
- mcChunk = chunkServer.loadChunk(coord.getBlockX(), coord.getBlockZ());
- mcChunk.onChunkUnload();
- }
- chunkServer.droppedChunksSet.remove(pos);
- chunkServer.id2ChunkMap.remove(pos);
- mcChunk = chunkServer.provideChunk(coord.getBlockX(), coord.getBlockZ());
- chunkServer.id2ChunkMap.put(pos, mcChunk);
- if (mcChunk != null) {
- mcChunk.onChunkLoad();
- mcChunk.populateChunk(chunkServer, chunkServer.chunkGenerator);
+ IChunkGenerator gen = chunkServer.chunkGenerator;
+ long pos = ChunkPos.chunkXZ2Int(chunk.getBlockX(), chunk.getBlockZ());
+ if (chunkServer.chunkExists(chunk.getBlockX(), chunk.getBlockZ())) {
+ mcChunk = chunkServer.loadChunk(chunk.getBlockX(), chunk.getBlockZ());
+ PlayerChunkMapEntry entry = playerManager.getEntry(chunk.getBlockX(), chunk.getBlockZ());
+ if (entry != null) {
+ oldWatchers = entry.players;
+ playerManager.removeEntry(entry);
}
+ mcChunk.onChunkUnload();
+ }
+ chunkServer.droppedChunksSet.remove(pos);
+ chunkServer.id2ChunkMap.remove(pos);
+ mcChunk = gen.provideChunk(chunk.getBlockX(), chunk.getBlockZ());
+ chunkServer.id2ChunkMap.put(pos, mcChunk);
+ if (mcChunk != null) {
+ mcChunk.onChunkLoad();
+ mcChunk.populateChunk(chunkServer, chunkServer.chunkGenerator);
}
} catch (Throwable t) {
logger.log(Level.WARNING, "Failed to generate chunk", t);
@@ -294,6 +305,13 @@ public boolean regenerate(Region region, EditSession editSession) {
}
}
}
+ // We don't need to recreate the ChunkMapEntry unless there are players
+ // but addPlayer handles that for us
+ if (oldWatchers != null) {
+ for (EntityPlayerMP player : oldWatchers) {
+ playerManager.addPlayer(player);
+ }
+ }
}
return false;
@@ -1 +1,2 @@
public net.minecraft.world.gen.ChunkProviderServer field_73248_b # droppedChunksSet
+public net.minecraft.server.management.PlayerChunkMapEntry field_187283_c # players

0 comments on commit b5a49b1

Please sign in to comment.