Skip to content

Commit a5d6e3a

Browse files
committed
PR fixes
1 parent dacc574 commit a5d6e3a

File tree

7 files changed

+22
-27
lines changed

7 files changed

+22
-27
lines changed

worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeAdapter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.sk89q.worldedit.world.biome.BiomeType;
3333
import com.sk89q.worldedit.world.block.BlockState;
3434
import com.sk89q.worldedit.world.item.ItemTypes;
35+
import net.minecraft.world.level.block.Block;
3536
import org.enginehub.linbus.tree.LinCompoundTag;
3637
import org.spongepowered.api.ResourceKey;
3738
import org.spongepowered.api.Sponge;
@@ -58,16 +59,16 @@
5859
*/
5960
public class SpongeAdapter {
6061

61-
public static org.spongepowered.api.block.BlockState adapt(BlockState blockState, ServerWorld world) {
62+
public static org.spongepowered.api.block.BlockState adapt(BlockState blockState) {
6263
int blockStateId = BlockStateIdAccess.getBlockStateId(blockState);
6364
if (!BlockStateIdAccess.isValidInternalId(blockStateId)) {
6465
return SpongeTransmogrifier.transmogToMinecraft(blockState);
6566
}
66-
return world.blockPalette().get(blockStateId, world).orElseThrow();
67+
return (org.spongepowered.api.block.BlockState) Block.stateById(blockStateId);
6768
}
6869

69-
public static BlockState adapt(org.spongepowered.api.block.BlockState blockState, ServerWorld world) {
70-
int blockStateId = world.blockPalette().get(blockState).orElseThrow();
70+
public static BlockState adapt(org.spongepowered.api.block.BlockState blockState) {
71+
int blockStateId = Block.getId((net.minecraft.world.level.block.state.BlockState) blockState);
7172
BlockState worldEdit = BlockStateIdAccess.getBlockStateById(blockStateId);
7273
if (worldEdit == null) {
7374
return SpongeTransmogrifier.transmogToWorldEdit(blockState);

worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeBlockRegistry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public BlockMaterial getMaterial(BlockType blockType) {
8181
@Override
8282
public OptionalInt getInternalBlockStateId(BlockState state) {
8383
ServerWorld world = Sponge.server().worldManager().world(DefaultWorldKeys.DEFAULT).orElseThrow();
84-
org.spongepowered.api.block.BlockState equivalent = SpongeAdapter.adapt(state, world);
84+
org.spongepowered.api.block.BlockState equivalent = SpongeAdapter.adapt(state);
8585

8686
return world.blockPalette().get(equivalent);
8787
}

worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B bl
234234
if (block == null) {
235235
player.resetBlockChange(pos.x(), pos.y(), pos.z());
236236
} else {
237-
BlockState spongeBlock = SpongeAdapter.adapt(block.toImmutableState(), player.world());
237+
BlockState spongeBlock = SpongeAdapter.adapt(block.toImmutableState());
238238
player.sendBlockChange(pos.x(), pos.y(), pos.z(), spongeBlock);
239239
if (block instanceof final BaseBlock baseBlock
240240
&& block.getBlockType().equals(com.sk89q.worldedit.world.block.BlockTypes.STRUCTURE_BLOCK)) {

worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorld.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public Path getStoragePath() {
158158
public BlockState getBlock(BlockVector3 position) {
159159
return SpongeAdapter.adapt(getWorld().block(
160160
position.x(), position.y(), position.z()
161-
), getWorld());
161+
));
162162
}
163163

164164
@Override
@@ -191,7 +191,7 @@ public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B
191191

192192
ServerWorld world = getWorld();
193193

194-
org.spongepowered.api.block.BlockState newState = SpongeAdapter.adapt(block.toImmutableState(), world);
194+
org.spongepowered.api.block.BlockState newState = SpongeAdapter.adapt(block.toImmutableState());
195195

196196
boolean didSet = world.setBlock(
197197
position.x(), position.y(), position.z(),
@@ -408,7 +408,7 @@ public void simulateBlockMine(BlockVector3 position) {
408408

409409
@Override
410410
public boolean canPlaceAt(BlockVector3 position, com.sk89q.worldedit.world.block.BlockState blockState) {
411-
return ((net.minecraft.world.level.block.state.BlockState) SpongeAdapter.adapt(blockState, getWorld()))
411+
return ((net.minecraft.world.level.block.state.BlockState) SpongeAdapter.adapt(blockState))
412412
.canSurvive(
413413
((LevelReader) getWorld()),
414414
new BlockPos(position.x(), position.y(), position.z())

worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldEdit.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import com.sk89q.worldedit.extension.platform.PlatformManager;
3535
import com.sk89q.worldedit.internal.anvil.ChunkDeleter;
3636
import com.sk89q.worldedit.internal.command.CommandUtil;
37-
import com.sk89q.worldedit.internal.event.InteractionDebouncer;
3837
import com.sk89q.worldedit.sponge.config.SpongeConfiguration;
3938
import com.sk89q.worldedit.world.biome.BiomeCategory;
4039
import com.sk89q.worldedit.world.biome.BiomeType;
@@ -64,7 +63,6 @@
6463
import org.spongepowered.api.event.lifecycle.StoppingEngineEvent;
6564
import org.spongepowered.api.registry.RegistryTypes;
6665
import org.spongepowered.api.scheduler.Task;
67-
import org.spongepowered.api.world.DefaultWorldKeys;
6866
import org.spongepowered.api.world.LocatableBlock;
6967
import org.spongepowered.api.world.server.ServerWorld;
7068
import org.spongepowered.plugin.PluginContainer;
@@ -103,7 +101,6 @@ public static SpongeWorldEdit inst() {
103101
private final SpongeConfiguration config;
104102
private final Path workingDir;
105103

106-
private InteractionDebouncer debouncer;
107104
private SpongePermissionsProvider provider;
108105
private SpongePlatform platform;
109106

@@ -125,7 +122,6 @@ public SpongeWorldEdit(Logger logger,
125122
@Listener
126123
public void onPluginConstruction(ConstructPluginEvent event) {
127124
this.platform = new SpongePlatform(this);
128-
debouncer = new InteractionDebouncer(platform);
129125

130126
WorldEdit.getInstance().getPlatformManager().register(platform);
131127

@@ -171,7 +167,7 @@ public void serverStarted(StartedEngineEvent<Server> event) {
171167
BlockType spongeBlockType = Sponge.game().registry(RegistryTypes.BLOCK_TYPE).value(
172168
ResourceKey.resolve(input.getBlockType().id())
173169
);
174-
return SpongeAdapter.adapt(spongeBlockType.defaultState(), Sponge.server().worldManager().world(DefaultWorldKeys.DEFAULT).orElseThrow());
170+
return SpongeAdapter.adapt(spongeBlockType.defaultState());
175171
}
176172
));
177173
}
@@ -380,8 +376,4 @@ public void setPermissionsProvider(SpongePermissionsProvider provider) {
380376
public SpongePermissionsProvider getPermissionsProvider() {
381377
return provider;
382378
}
383-
384-
public InteractionDebouncer getDebouncer() {
385-
return debouncer;
386-
}
387379
}

worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldEditListener.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.sk89q.worldedit.WorldEdit;
2323
import com.sk89q.worldedit.event.platform.SessionIdleEvent;
24+
import com.sk89q.worldedit.internal.event.InteractionDebouncer;
2425
import org.spongepowered.api.block.BlockSnapshot;
2526
import org.spongepowered.api.data.type.HandTypes;
2627
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
@@ -39,9 +40,11 @@
3940
public class SpongeWorldEditListener {
4041

4142
private final SpongeWorldEdit plugin;
43+
private final InteractionDebouncer debouncer;
4244

4345
public SpongeWorldEditListener(SpongeWorldEdit plugin) {
4446
this.plugin = plugin;
47+
debouncer = new InteractionDebouncer(plugin.getPlatform());
4548
}
4649

4750
public boolean skipEvents() {
@@ -61,13 +64,13 @@ public void onPlayerInteractItemPrimary(InteractItemEvent.Primary event, @Root S
6164
WorldEdit we = WorldEdit.getInstance();
6265
SpongePlayer player = SpongeAdapter.adapt(spongePlayer);
6366

64-
Optional<Boolean> previousResult = plugin.getDebouncer().getDuplicateInteractionResult(player);
67+
Optional<Boolean> previousResult = debouncer.getDuplicateInteractionResult(player);
6568
if (previousResult.isPresent()) {
6669
return;
6770
}
6871

6972
boolean result = we.handleArmSwing(player);
70-
plugin.getDebouncer().setLastInteraction(player, result);
73+
debouncer.setLastInteraction(player, result);
7174
}
7275

7376
@Listener
@@ -79,7 +82,7 @@ public void onPlayerInteractItemSecondary(InteractItemEvent.Secondary event, @Ro
7982
WorldEdit we = WorldEdit.getInstance();
8083
SpongePlayer player = SpongeAdapter.adapt(spongePlayer);
8184

82-
Optional<Boolean> previousResult = plugin.getDebouncer().getDuplicateInteractionResult(player);
85+
Optional<Boolean> previousResult = debouncer.getDuplicateInteractionResult(player);
8386
if (previousResult.isPresent()) {
8487
if (previousResult.get()) {
8588
event.setCancelled(true);
@@ -88,7 +91,7 @@ public void onPlayerInteractItemSecondary(InteractItemEvent.Secondary event, @Ro
8891
}
8992

9093
boolean result = we.handleRightClick(player);
91-
plugin.getDebouncer().setLastInteraction(player, result);
94+
debouncer.setLastInteraction(player, result);
9295

9396
if (result) {
9497
event.setCancelled(true);
@@ -116,7 +119,7 @@ public void onPlayerInteractBlockPrimary(InteractBlockEvent.Primary.Start event,
116119
}
117120

118121
result = we.handleArmSwing(player) || result;
119-
plugin.getDebouncer().setLastInteraction(player, result);
122+
debouncer.setLastInteraction(player, result);
120123

121124
if (result) {
122125
event.setCancelled(true);
@@ -144,7 +147,7 @@ public void onPlayerInteractBlockSecondary(InteractBlockEvent.Secondary.Pre even
144147
}
145148

146149
result = we.handleRightClick(player) || result;
147-
plugin.getDebouncer().setLastInteraction(player, result);
150+
debouncer.setLastInteraction(player, result);
148151

149152
if (result) {
150153
event.setCancelled(true);
@@ -154,7 +157,7 @@ public void onPlayerInteractBlockSecondary(InteractBlockEvent.Secondary.Pre even
154157
@Listener
155158
public void onPlayerQuit(ServerSideConnectionEvent.Disconnect event) {
156159
event.profile().ifPresent(profile -> {
157-
plugin.getDebouncer().clearInteraction(profile::uniqueId);
160+
debouncer.clearInteraction(profile::uniqueId);
158161

159162
WorldEdit.getInstance().getEventBus()
160163
.post(new SessionIdleEvent(new SpongePlayer.SessionKeyImpl(profile.uniqueId(), profile.name().orElseThrow())));

worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/internal/SpongeWorldNativeAccess.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import net.minecraft.world.level.block.state.BlockState;
3232
import net.minecraft.world.level.chunk.LevelChunk;
3333
import org.enginehub.linbus.tree.LinCompoundTag;
34-
import org.spongepowered.api.world.server.ServerWorld;
3534

3635
import java.lang.ref.WeakReference;
3736
import java.util.Objects;
@@ -64,7 +63,7 @@ public LevelChunk getChunk(int x, int z) {
6463

6564
@Override
6665
public BlockState toNative(com.sk89q.worldedit.world.block.BlockState state) {
67-
return (BlockState) SpongeAdapter.adapt(state, (ServerWorld) world.get());
66+
return (BlockState) SpongeAdapter.adapt(state);
6867
}
6968

7069
@Override

0 commit comments

Comments
 (0)