forked from SteamWar/SteamWar
+2
-1
@@ -24,6 +24,7 @@ import com.sk89q.worldedit.entity.Entity;
|
|||||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.sql.GameModeConfig;
|
import de.steamwar.sql.GameModeConfig;
|
||||||
import de.steamwar.sql.SchematicType;
|
import de.steamwar.sql.SchematicType;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -109,7 +110,7 @@ public class AutoChecker15 implements AutoChecker.IAutoChecker {
|
|||||||
if (!itemsInInv.getOrDefault(itemType, EnumSet.noneOf(Material.class)).contains(material)) {
|
if (!itemsInInv.getOrDefault(itemType, EnumSet.noneOf(Material.class)).contains(material)) {
|
||||||
result.getForbiddenItems().computeIfAbsent(pos, blockVector3 -> new HashSet<>()).add(itemType);
|
result.getForbiddenItems().computeIfAbsent(pos, blockVector3 -> new HashSet<>()).add(itemType);
|
||||||
} else if(material == Material.DISPENSER && (itemType == Material.ARROW || itemType == Material.FIRE_CHARGE)) {
|
} else if(material == Material.DISPENSER && (itemType == Material.ARROW || itemType == Material.FIRE_CHARGE)) {
|
||||||
counter += item.getByte("Count");
|
counter += Core.getVersion() >= 21 ? item.getInt("count") : item.getByte("Count");
|
||||||
}
|
}
|
||||||
if (item.containsKey("tag")) {
|
if (item.containsKey("tag")) {
|
||||||
result.getForbiddenNbt().computeIfAbsent(pos, blockVector3 -> new HashSet<>()).add(itemType);
|
result.getForbiddenNbt().computeIfAbsent(pos, blockVector3 -> new HashSet<>()).add(itemType);
|
||||||
|
|||||||
+13
-4
@@ -31,6 +31,7 @@ import com.sk89q.worldedit.math.BlockVector3;
|
|||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.sql.GameModeConfig;
|
import de.steamwar.sql.GameModeConfig;
|
||||||
import de.steamwar.schematicsystem.autocheck.AutoCheckerResult;
|
import de.steamwar.schematicsystem.autocheck.AutoCheckerResult;
|
||||||
import de.steamwar.schematicsystem.autocheck.BlockPos;
|
import de.steamwar.schematicsystem.autocheck.BlockPos;
|
||||||
@@ -38,9 +39,17 @@ import de.steamwar.sql.SchematicType;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class SchematicCommand15 implements SchematicCommand.ISchematicCommand {
|
public class SchematicCommand15 implements SchematicCommand.ISchematicCommand {
|
||||||
|
private static final Function<CompoundTag, Integer> getCount = item -> Core.getVersion() >= 21 ? item.getInt("count") : item.getByte("Count");
|
||||||
|
private static final BiFunction<CompoundTag, Integer, CompoundTag> setCount = (item, count) -> Core.getVersion() >= 21 ?
|
||||||
|
item.createBuilder().putInt("count", count).build() :
|
||||||
|
item.createBuilder().putByte("Count", count.byteValue()).build();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, GameModeConfig<Material, String> type) throws Exception {
|
public Clipboard fixClipboard(Clipboard clipboard, AutoCheckerResult result, GameModeConfig<Material, String> type) throws Exception {
|
||||||
for (BlockPos blockPos : result.getBlockScanResult().getRecords()) {
|
for (BlockPos blockPos : result.getBlockScanResult().getRecords()) {
|
||||||
@@ -87,7 +96,7 @@ public class SchematicCommand15 implements SchematicCommand.ISchematicCommand {
|
|||||||
BaseBlock block = clipboard.getFullBlock(vector);
|
BaseBlock block = clipboard.getFullBlock(vector);
|
||||||
CompoundTag tag = block.getNbtData();
|
CompoundTag tag = block.getNbtData();
|
||||||
CompoundTagBuilder builder = tag.createBuilder();
|
CompoundTagBuilder builder = tag.createBuilder();
|
||||||
List<CompoundTag> items = tag.getList("Items", CompoundTag.class);
|
List<CompoundTag> items = new ArrayList<>(tag.getList("Items", CompoundTag.class));
|
||||||
Collections.reverse(items); // To let the first item be in the Dispenser
|
Collections.reverse(items); // To let the first item be in the Dispenser
|
||||||
List<CompoundTag> list = new ArrayList<>();
|
List<CompoundTag> list = new ArrayList<>();
|
||||||
int diff = entry.getValue() - type.Schematic.MaxDispenserItems;
|
int diff = entry.getValue() - type.Schematic.MaxDispenserItems;
|
||||||
@@ -101,12 +110,12 @@ public class SchematicCommand15 implements SchematicCommand.ISchematicCommand {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(diff > item.getByte("Count")) {
|
if(diff > getCount.apply(item)) {
|
||||||
diff -= item.getByte("Count");
|
diff -= getCount.apply(item);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
item = item.createBuilder().putByte("Count", (byte) (item.getByte("Count") - diff)).build();
|
item = setCount.apply(item, getCount.apply(item) - diff);
|
||||||
diff = 0;
|
diff = 0;
|
||||||
list.add(item);
|
list.add(item);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user