use of riskyken.armourersWorkshop.common.library.LibraryFile in project Armourers-Workshop by RiskyKen.
the class GuiSkinLibrary method dialogResult.
@Override
public void dialogResult(AbstractGuiDialog dialog, DialogResult result) {
if (result == DialogResult.OK) {
if (dialog instanceof GuiDialogNewFolder) {
GuiDialogNewFolder newFolderDialog = (GuiDialogNewFolder) dialog;
if (fileSwitchType == LibraryFileType.LOCAL) {
File dir = new File(SkinIOUtils.getSkinLibraryDirectory(), currentFolder);
dir = new File(dir, newFolderDialog.getFolderName());
if (!dir.exists()) {
dir.mkdir();
}
reloadLocalLibrary();
ModLogger.log(String.format("making folder call %s in %s", newFolderDialog.getFolderName(), currentFolder));
ModLogger.log("full path: " + dir.getAbsolutePath());
} else {
MessageClientGuiSkinLibraryCommand message = new MessageClientGuiSkinLibraryCommand();
message.newFolder(new LibraryFile(newFolderDialog.getFolderName(), currentFolder, null, true), fileSwitchType == LibraryFileType.SERVER_PUBLIC);
PacketHandler.networkWrapper.sendToServer(message);
}
}
if (dialog instanceof GuiDialogDelete) {
GuiDialogDelete deleteDialog = (GuiDialogDelete) dialog;
boolean isFolder = deleteDialog.isFolder();
String name = deleteDialog.getFileName();
if (fileSwitchType == LibraryFileType.LOCAL) {
File dir = new File(SkinIOUtils.getSkinLibraryDirectory(), currentFolder);
if (deleteDialog.isFolder()) {
dir = new File(dir, name + "/");
} else {
dir = new File(dir, name + SkinIOUtils.SKIN_FILE_EXTENSION);
}
if (dir.isDirectory() == isFolder) {
if (dir.exists()) {
if (isFolder) {
try {
FileUtils.deleteDirectory(dir);
reloadLocalLibrary();
} catch (IOException e) {
e.printStackTrace();
}
} else {
LibraryFile libraryFile = new LibraryFile(currentFolder + deleteDialog.getFileName());
ClientSkinCache.INSTANCE.markSkinAsDirty(new SkinIdentifier(0, libraryFile, 0, null));
dir.delete();
reloadLocalLibrary();
}
}
}
} else {
MessageClientGuiSkinLibraryCommand message = new MessageClientGuiSkinLibraryCommand();
message.delete(new LibraryFile(deleteDialog.getFileName(), currentFolder, null, isFolder), fileSwitchType == LibraryFileType.SERVER_PUBLIC);
PacketHandler.networkWrapper.sendToServer(message);
// ClientSkinCache.INSTANCE.clearIdForFileName(currentFolder + deleteDialog.getName());
}
}
if (dialog instanceof GuiDialogOverwrite) {
GuiDialogOverwrite overwriteDialog = (GuiDialogOverwrite) dialog;
MessageClientGuiLoadSaveArmour message;
boolean clientLoad = false;
boolean publicList = true;
if (fileSwitchType == LibraryFileType.LOCAL && !mc.isIntegratedServerRunning()) {
// Is playing on a server.
clientLoad = true;
}
if (fileSwitchType == LibraryFileType.SERVER_PRIVATE) {
publicList = false;
}
if (clientLoad) {
message = new MessageClientGuiLoadSaveArmour(overwriteDialog.getFileName(), currentFolder, LibraryPacketType.CLIENT_SAVE, false, trackFile);
PacketHandler.networkWrapper.sendToServer(message);
} else {
message = new MessageClientGuiLoadSaveArmour(overwriteDialog.getFileName(), currentFolder, LibraryPacketType.SERVER_SAVE, publicList, trackFile);
PacketHandler.networkWrapper.sendToServer(message);
}
LibraryFile libraryFile = new LibraryFile(currentFolder + overwriteDialog.getFileName());
ClientSkinCache.INSTANCE.markSkinAsDirty(new SkinIdentifier(0, libraryFile, 0, null));
// reloadLocalLibrary();
// TODO clear name lookup list on clients or just removed this one name
}
}
super.dialogResult(dialog, result);
}
use of riskyken.armourersWorkshop.common.library.LibraryFile in project Armourers-Workshop by RiskyKen.
the class GuiSkinLibrary method actionPerformed.
@Override
protected void actionPerformed(GuiButton button) {
String filename = filenameTextbox.getText().trim();
if (button == fileSwitchlocal | button == fileSwitchRemotePublic | button == fileSwitchRemotePrivate) {
if (button == fileSwitchlocal) {
setFileSwitchType(LibraryFileType.LOCAL);
}
if (button == fileSwitchRemotePublic) {
setFileSwitchType(LibraryFileType.SERVER_PUBLIC);
}
if (button == fileSwitchRemotePrivate) {
setFileSwitchType(LibraryFileType.SERVER_PRIVATE);
}
}
if (button == reloadButton) {
if (fileSwitchType == LibraryFileType.LOCAL) {
ILibraryManager libraryManager = ArmourersWorkshop.proxy.libraryManager;
libraryManager.reloadLibrary();
} else {
// TODO reload server library
}
}
if (button == openFolderButton) {
openEquipmentFolder();
}
if (button == deleteButton) {
if (fileList.getSelectedListEntry() != null) {
GuiFileListItem item = (GuiFileListItem) fileList.getSelectedListEntry();
openDialog(new GuiDialogDelete(this, armourLibrary.getInventoryName() + ".dialog.delete", this, 190, 100, item.getFile().isDirectory(), item.getDisplayName()));
}
}
if (button == newFolderButton) {
openDialog(new GuiDialogNewFolder(this, armourLibrary.getInventoryName() + ".dialog.newFolder", this, 190, 120));
}
if (button == checkBoxTrack) {
trackFile = checkBoxTrack.isChecked();
}
GuiFileListItem fileItem = (GuiFileListItem) fileList.getSelectedListEntry();
boolean clientLoad = false;
boolean publicList = true;
MessageClientGuiLoadSaveArmour message;
if (fileSwitchType == LibraryFileType.LOCAL && !mc.isIntegratedServerRunning()) {
// Is playing on a server.
clientLoad = true;
}
if (fileSwitchType == LibraryFileType.SERVER_PRIVATE) {
publicList = false;
}
if (button == loadSaveButton) {
if (fileItem != null && !fileItem.getFile().isDirectory()) {
LibraryFile file = fileItem.getFile();
if (isLoading()) {
if (clientLoad) {
Skin itemData = SkinIOUtils.loadSkinFromFileName(file.filePath + filename + SkinIOUtils.SKIN_FILE_EXTENSION);
if (itemData != null) {
SkinUploadHelper.uploadSkinToServer(itemData);
}
} else {
message = new MessageClientGuiLoadSaveArmour(file.fileName, file.filePath, LibraryPacketType.SERVER_LOAD, publicList, trackFile);
PacketHandler.networkWrapper.sendToServer(message);
}
filenameTextbox.setText("");
}
}
if (!filename.isEmpty()) {
if (!isLoading()) {
if (fileExists(currentFolder, filename)) {
openDialog(new GuiDialogOverwrite(this, armourLibrary.getInventoryName() + ".dialog.overwrite", this, 190, 100, filename));
return;
}
if (clientLoad) {
message = new MessageClientGuiLoadSaveArmour(filename, currentFolder, LibraryPacketType.CLIENT_SAVE, false, trackFile);
PacketHandler.networkWrapper.sendToServer(message);
} else {
message = new MessageClientGuiLoadSaveArmour(filename, currentFolder, LibraryPacketType.SERVER_SAVE, publicList, trackFile);
PacketHandler.networkWrapper.sendToServer(message);
}
// filenameTextbox.setText("");
}
}
}
setupLibraryEditButtons();
}
use of riskyken.armourersWorkshop.common.library.LibraryFile in project Armourers-Workshop by RiskyKen.
the class GuiFileListItem method drawListItem.
@Override
public void drawListItem(FontRenderer fontRenderer, int x, int y, int mouseX, int mouseY, boolean selected, int width) {
int iconOffset = 0;
if (GuiSkinLibrary.showModelPreviews() | file.isDirectory()) {
iconOffset = 10;
}
int fontColour = UtilColour.getMinecraftColor(8, ColourFamily.MINECRAFT);
if (isHovering(fontRenderer, x, y, mouseX, mouseY, width)) {
Gui.drawRect(x, y, x + width - 3, y + 12, 0xFFCCCCCC);
fontColour = UtilColour.getMinecraftColor(15, ColourFamily.MINECRAFT);
}
if (selected) {
Gui.drawRect(x, y, x + width - 3, y + 12, 0xFFFFFF88);
fontColour = UtilColour.getMinecraftColor(15, ColourFamily.MINECRAFT);
}
if (!file.isDirectory()) {
fontRenderer.drawString(file.fileName, x + 2 + iconOffset, y + 2, fontColour);
if (GuiSkinLibrary.showModelPreviews() | file.isDirectory()) {
IGuiListItem item = this;
if (item != null) {
SkinIdentifier identifier = new SkinIdentifier(0, new LibraryFile(file.getFullName()), 0, null);
Skin skin = ClientSkinCache.INSTANCE.getSkin(identifier, true);
if (skin != null) {
SkinPointer skinPointer = new SkinPointer(identifier);
float scale = 10F;
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glTranslatef((float) x + 5, (float) y + 6, 50.0F);
GL11.glScalef((float) (-scale), (float) scale, (float) scale);
GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(20.0F, 1.0F, 0.0F, 0.0F);
float rotation = (float) ((double) System.currentTimeMillis() / 10 % 360);
GL11.glRotatef(rotation, 0.0F, 1.0F, 0.0F);
RenderHelper.enableStandardItemLighting();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glEnable(GL11.GL_NORMALIZE);
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
ModRenderHelper.enableAlphaBlend();
// ItemStackRenderHelper.renderItemModelFromSkinPointer(skinPointer, true, false);
SkinItemRenderHelper.renderSkinAsItem(skin, skinPointer, true, false, 16, 16);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glPopAttrib();
GL11.glPopMatrix();
}
}
}
} else {
GL11.glColor4f(1, 1, 1, 1);
Minecraft.getMinecraft().renderEngine.bindTexture(texture);
if (file.fileName.equals("private")) {
drawTexturedModalRect(x, y, 32, 0, 12, 12);
fontRenderer.drawString(file.fileName, x + 2 + iconOffset, y + 2, 0xFF8888FF);
} else {
drawTexturedModalRect(x, y, 16, 0, 10, 10);
fontRenderer.drawString(file.fileName, x + 2 + iconOffset, y + 2, 0xFF88FF88);
}
GL11.glColor4f(1, 1, 1, 1);
}
}
use of riskyken.armourersWorkshop.common.library.LibraryFile in project Armourers-Workshop by RiskyKen.
the class CommandGiveSkin method processCommand.
@Override
public void processCommand(ICommandSender commandSender, String[] currentCommand) {
if (currentCommand.length < 3) {
throw new WrongUsageException(getCommandUsage(commandSender), (Object) currentCommand);
}
String playerName = currentCommand[1];
EntityPlayerMP player = getPlayer(commandSender, playerName);
if (player == null) {
return;
}
String skinName = currentCommand[2];
if (!skinName.substring(0, 1).equals("\"")) {
throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
}
int usedCommands = 2;
if (!skinName.substring(skinName.length() - 1, skinName.length()).equals("\"")) {
for (int i = 3; i < currentCommand.length; i++) {
skinName += " " + currentCommand[i];
if (skinName.substring(skinName.length() - 1, skinName.length()).equals("\"")) {
usedCommands = i;
break;
}
}
}
ModLogger.log("usedCommands used: " + usedCommands);
ModLogger.log("total commands used: " + currentCommand.length);
if (!skinName.substring(skinName.length() - 1, skinName.length()).equals("\"")) {
throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
}
skinName = skinName.replace("\"", "");
SkinDye skinDye = new SkinDye();
for (int i = usedCommands + 1; i < currentCommand.length; i++) {
String dyeCommand = currentCommand[i];
ModLogger.log("Command dye: " + dyeCommand);
if (!dyeCommand.contains("-")) {
throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
}
String[] commandSplit = dyeCommand.split("-");
if (commandSplit.length != 2) {
throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
}
int dyeIndex = parseIntBounded(commandSender, commandSplit[0], 1, 8) - 1;
String dye = commandSplit[1];
if (dye.startsWith("#") && dye.length() == 7) {
// dye = dye.substring(2, 8);
if (isValidHex(dye)) {
Color dyeColour = Color.decode(dye);
int r = dyeColour.getRed();
int g = dyeColour.getGreen();
int b = dyeColour.getBlue();
skinDye.addDye(dyeIndex, new byte[] { (byte) r, (byte) g, (byte) b, (byte) 255 });
} else {
throw new WrongUsageException("commands.armourers.invalidDyeFormat", (Object) dye);
}
} else if (dye.length() >= 5 & dye.contains(",")) {
String[] dyeValues = dye.split(",");
if (dyeValues.length != 3) {
throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
}
int r = parseIntBounded(commandSender, dyeValues[0], 0, 255);
int g = parseIntBounded(commandSender, dyeValues[1], 0, 255);
int b = parseIntBounded(commandSender, dyeValues[2], 0, 255);
skinDye.addDye(dyeIndex, new byte[] { (byte) r, (byte) g, (byte) b, (byte) 255 });
} else {
throw new WrongUsageException("commands.armourers.invalidDyeFormat", (Object) dye);
}
}
LibraryFile libraryFile = new LibraryFile(skinName);
Skin skin = SkinIOUtils.loadSkinFromLibraryFile(libraryFile);
if (skin == null) {
throw new WrongUsageException("commands.armourers.fileNotFound", (Object) skinName);
}
try {
skin.lightHash();
} catch (Exception e) {
ModLogger.log(Level.ERROR, String.format("Unable to create ID for file %s.", libraryFile.toString()));
return;
}
CommonSkinCache.INSTANCE.addEquipmentDataToCache(skin, libraryFile);
SkinIdentifier skinIdentifier = new SkinIdentifier(0, libraryFile, 0, skin.getSkinType());
ItemStack skinStack = SkinNBTHelper.makeEquipmentSkinStack(new SkinPointer(skinIdentifier, skinDye));
EntityItem entityItem = player.dropPlayerItemWithRandomChoice(skinStack, false);
entityItem.delayBeforeCanPickup = 0;
entityItem.func_145797_a(player.getCommandSenderName());
}
use of riskyken.armourersWorkshop.common.library.LibraryFile in project Armourers-Workshop by RiskyKen.
the class CommandSetSkin method processCommand.
@Override
public void processCommand(ICommandSender commandSender, String[] currentCommand) {
if (currentCommand.length < 3) {
throw new WrongUsageException(getCommandUsage(commandSender), (Object) currentCommand);
}
String playerName = currentCommand[1];
EntityPlayerMP player = getPlayer(commandSender, playerName);
if (player == null) {
return;
}
int slotNum = 0;
slotNum = parseIntBounded(commandSender, currentCommand[2], 1, 8);
String skinName = currentCommand[3];
if (!skinName.substring(0, 1).equals("\"")) {
throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
}
int usedCommands = 3;
if (!skinName.substring(skinName.length() - 1, skinName.length()).equals("\"")) {
for (int i = 3; i < currentCommand.length; i++) {
skinName += " " + currentCommand[i];
if (skinName.substring(skinName.length() - 1, skinName.length()).equals("\"")) {
usedCommands = i;
break;
}
}
}
ModLogger.log("usedCommands used: " + usedCommands);
ModLogger.log("total commands used: " + currentCommand.length);
if (!skinName.substring(skinName.length() - 1, skinName.length()).equals("\"")) {
throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
}
skinName = skinName.replace("\"", "");
SkinDye skinDye = new SkinDye();
for (int i = usedCommands + 1; i < currentCommand.length; i++) {
String dyeCommand = currentCommand[i];
ModLogger.log("Command dye: " + dyeCommand);
if (!dyeCommand.contains("-")) {
throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
}
String[] commandSplit = dyeCommand.split("-");
if (commandSplit.length != 2) {
throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
}
int dyeIndex = parseIntBounded(commandSender, commandSplit[0], 1, 8) - 1;
String dye = commandSplit[1];
if (dye.startsWith("#") && dye.length() == 7) {
// dye = dye.substring(2, 8);
if (isValidHex(dye)) {
Color dyeColour = Color.decode(dye);
int r = dyeColour.getRed();
int g = dyeColour.getGreen();
int b = dyeColour.getBlue();
skinDye.addDye(dyeIndex, new byte[] { (byte) r, (byte) g, (byte) b, (byte) 255 });
} else {
throw new WrongUsageException("commands.armourers.invalidDyeFormat", (Object) dye);
}
} else if (dye.length() >= 5 & dye.contains(",")) {
String[] dyeValues = dye.split(",");
if (dyeValues.length != 3) {
throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
}
int r = parseIntBounded(commandSender, dyeValues[0], 0, 255);
int g = parseIntBounded(commandSender, dyeValues[1], 0, 255);
int b = parseIntBounded(commandSender, dyeValues[2], 0, 255);
skinDye.addDye(dyeIndex, new byte[] { (byte) r, (byte) g, (byte) b, (byte) 255 });
} else {
throw new WrongUsageException("commands.armourers.invalidDyeFormat", (Object) dye);
}
}
LibraryFile libraryFile = new LibraryFile(skinName);
Skin skin = SkinIOUtils.loadSkinFromLibraryFile(libraryFile);
if (skin == null) {
throw new WrongUsageException("commands.armourers.fileNotFound", (Object) skinName);
}
try {
skin.lightHash();
} catch (Exception e) {
ModLogger.log(Level.ERROR, String.format("Unable to create ID for file %s.", libraryFile.toString()));
return;
}
CommonSkinCache.INSTANCE.addEquipmentDataToCache(skin, libraryFile);
SkinIdentifier skinIdentifier = new SkinIdentifier(0, libraryFile, 0, skin.getSkinType());
ItemStack skinStack = SkinNBTHelper.makeEquipmentSkinStack(new SkinPointer(skinIdentifier, skinDye));
ExPropsPlayerSkinData.get(player).setEquipmentStack(skinStack, slotNum - 1);
}
Aggregations