-
-
Notifications
You must be signed in to change notification settings - Fork 204
/
ProcessedWEExtent.java
124 lines (109 loc) · 4.06 KB
/
ProcessedWEExtent.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package com.fastasyncworldedit.core.extent;
import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.limit.FaweLimit;
import com.fastasyncworldedit.core.util.WEManager;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.UUID;
public final class ProcessedWEExtent extends AbstractDelegateExtent {
private final FaweLimit limit;
private final Extent extent;
public ProcessedWEExtent(Extent parent, FaweLimit limit) {
super(parent);
this.limit = limit;
this.extent = parent;
}
public void setLimit(FaweLimit other) {
this.limit.set(other);
}
@Override
public Entity createEntity(Location location, BaseEntity entity) {
if (entity == null) {
return null;
}
if (!limit.MAX_ENTITIES()) {
WEManager.weManager().cancelEditSafe(this, FaweCache.MAX_ENTITIES);
return null;
}
return super.createEntity(location, entity);
}
@Override
public Entity createEntity(Location location, BaseEntity entity, UUID uuid) {
if (entity == null) {
return null;
}
if (!limit.MAX_ENTITIES()) {
WEManager.weManager().cancelEditSafe(this, FaweCache.MAX_ENTITIES);
return null;
}
return super.createEntity(location, entity, uuid);
}
@Override
public BlockState getBlock(int x, int y, int z) {
if (!limit.MAX_CHECKS()) {
WEManager.weManager().cancelEditSafe(this, FaweCache.MAX_CHECKS);
return BlockTypes.AIR.getDefaultState();
} else {
return extent.getBlock(x, y, z);
}
}
@Override
public BaseBlock getFullBlock(BlockVector3 pos) {
if (!limit.MAX_CHECKS()) {
WEManager.weManager().cancelEditSafe(this, FaweCache.MAX_CHECKS);
return BlockTypes.AIR.getDefaultState().toBaseBlock();
} else {
return extent.getFullBlock(pos);
}
}
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block)
throws WorldEditException {
return setBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ(), block);
}
@Override
public BlockState getBlock(BlockVector3 location) {
return getBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ());
}
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block)
throws WorldEditException {
boolean hasNbt = block instanceof BaseBlock && block.hasNbtData();
if (hasNbt) {
if (!limit.MAX_BLOCKSTATES()) {
WEManager.weManager().cancelEdit(this, FaweCache.MAX_TILES);
return false;
} else {
if (!limit.MAX_CHANGES()) {
WEManager.weManager().cancelEdit(this, FaweCache.MAX_CHANGES);
return false;
}
return extent.setBlock(x, y, z, block);
}
}
if (!limit.MAX_CHANGES()) {
WEManager.weManager().cancelEdit(this, FaweCache.MAX_CHANGES);
return false;
} else {
return extent.setBlock(x, y, z, block);
}
}
@Override
public boolean setBiome(BlockVector3 position, BiomeType biome) {
if (!limit.MAX_CHANGES()) {
WEManager.weManager().cancelEditSafe(this, FaweCache.MAX_CHANGES);
return false;
}
return super.setBiome(position, biome);
}
}