Skip to content

Commit

Permalink
v1.2: Small updates and fixes, Fabric release
Browse files Browse the repository at this point in the history
  • Loading branch information
0KepOnline committed Feb 9, 2024
1 parent 3788853 commit 3388f64
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ apply plugin: 'eclipse'
apply plugin: 'maven-publish'

def mcversion = '1.12.2'
def modversion = '1.1'
def modversion = '1.2'
def id = 'nbtexporter'
def author = 'scenarioplanet'

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/scenariopla/nbtexporter/NBTExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class NBTExporter {
public static class Reference {
public static final String MODID = "nbtexporter";
public static final String NAME = "NBT Exporter";
public static final String VERSION = "1.1";
public static final String VERSION = "1.2";

public static final String MODDIR = MODID;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Date;
import java.util.List;

import javax.annotation.Nullable;

import org.apache.commons.io.IOUtils;

import com.google.common.collect.Lists;

import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.SyntaxErrorException;
Expand All @@ -16,10 +21,11 @@
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.GameRules;

import net.scenariopla.nbtexporter.NBTExporter.Reference;
import net.scenariopla.nbtexporter.NBTExporter;
import net.scenariopla.nbtexporter.init.DirectoryInit;

public class CommandExportItemStackNBT extends CommandNBTExporter {
Expand Down Expand Up @@ -55,12 +61,13 @@ private static CommandException exceptions(ExportItemStackNBTExceptions exceptio
return exceptions(exception, new Object[0]);
}

private static CommandException exceptions(ExportItemStackNBTExceptions exception, Object[] args) {
private static CommandException exceptions(ExportItemStackNBTExceptions exception,
Object[] args) {
switch (exception) {
case SYNTAX_ERROR_USAGE:
return new WrongUsageException("commands.nbtexporter.global.usage", args);
case SYNTAX_ERROR_STRING_TERMINATION:
return new SyntaxErrorException("commands.nbtexporter.exportnbt.syntaxError.stringTermination", args);
return new SyntaxErrorException("commands.nbtexporter.global.syntaxError.stringTermination", args);

case HELD_ITEM_ERROR_EMPTY:
return new CommandException("commands.nbtexporter.global.heldItemError.empty", args);
Expand All @@ -74,6 +81,41 @@ private static CommandException exceptions(ExportItemStackNBTExceptions exceptio
return null;
}

@Override
public List<String> getTabCompletions(MinecraftServer server,
ICommandSender sender,
String[] args,
@Nullable BlockPos targetPos) {
if (sender instanceof EntityPlayer) {
final ItemStack heldItem = ((EntityPlayer) sender).getHeldItemMainhand();
if (!heldItem.isEmpty()) {
final String heldItemName = heldItem.getDisplayName();
final boolean heldItemNameHasSpaces = heldItemName.contains(" ");
if (args.length == 1) {
if (heldItemNameHasSpaces) {
return Lists.newArrayList('"' + heldItemName + '"');
}
return Lists.newArrayList(heldItemName);
} else if (args.length > 1 && heldItemNameHasSpaces) {
String[] argsExpected = ('"' + heldItemName + '"').split(" ");
if (args.length <= argsExpected.length) {
for (int argNum = 0; argNum < args.length - 1; argNum++) {
if (!args[argNum].equals(argsExpected[argNum])) {
return Lists.newArrayList();
}
}
final StringBuilder stringBuilder = new StringBuilder();
for (int argNum = args.length - 1; argNum < argsExpected.length; argNum++) {
stringBuilder.append(argsExpected[argNum]).append(" ");
}
return Lists.newArrayList(stringBuilder.toString().trim());
}
}
}
}
return Lists.newArrayList();
}

@Override
public void execute(MinecraftServer server,
ICommandSender sender,
Expand All @@ -90,17 +132,15 @@ public void execute(MinecraftServer server,
throw exceptions(ExportItemStackNBTExceptions.SYNTAX_ERROR_STRING_TERMINATION,
new Object[] {argsString});
}
} else if (args.length == 1) {
filename = argsString;
} else {
if (args.length == 1) {
filename = argsString;
} else {
throw exceptions(ExportItemStackNBTExceptions.SYNTAX_ERROR_USAGE);
}
throw exceptions(ExportItemStackNBTExceptions.SYNTAX_ERROR_USAGE);
}
}

if (filename == null) {
filename = Reference.DATE_FORMAT.format(new Date());
filename = NBTExporter.Reference.DATE_FORMAT.format(new Date());
} else {
filename = replaceIllegalCharacters(trimExtension(filename, FILE_EXTENSION), '_');
}
Expand All @@ -115,7 +155,7 @@ public void execute(MinecraftServer server,
if (nbtTagCompound == null) {
throw exceptions(ExportItemStackNBTExceptions.NBT_ERROR_EMPTY);
}
final GameRules gameRules = Reference.MINECRAFT.world.getGameRules();
final GameRules gameRules = NBTExporter.Reference.MINECRAFT.world.getGameRules();

for (File existingFile : modOutputFiles) {
if (existingFile.getName().equals(filename + FILE_EXTENSION)) {
Expand Down

0 comments on commit 3388f64

Please sign in to comment.