Skip to content

Commit

Permalink
Merge branch 'develop' into 'main'
Browse files Browse the repository at this point in the history
Develop

See merge request Griefed/ServerPackCreator!596
  • Loading branch information
Griefed committed Aug 4, 2024
2 parents c4d01ed + 34563c1 commit 8efd153
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class ServerPackHandler(
# installation of a compatible Java version, should JAVA be set to 'java'.
# JDK_VENDOR is for the automatic installation of a JDK compatible with the Minecraft
# version of your server pack. For an extensive list of available vendors, check out
# https://github.com/Jabba-Team/jabba/blob/c19c6ce2ae9645c39bbdca07b6c4e2ea39155f73/index.json
# https://github.com/Jabba-Team/index/blob/main/index.json
# Note - For the installation to take place:
# - SKIP_JAVA_CHECK must be set to 'false'
# - JAVA be set to 'java'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ de.griefed.serverpackcreator.configuration.directories.shouldexclude=animation,a
de.griefed.serverpackcreator.spring.schedules.database.cleanup=0 0 0 * * *
de.griefed.serverpackcreator.spring.schedules.files.cleanup=0 30 0 * * *
de.griefed.serverpackcreator.spring.schedules.versions.refresh=0 0 0 * * *
de.griefed.serverpackcreator.configuration.directories.mustinclude=addonpacks,blueprints,config,configs,customnpcs,defaultconfigs,global_data_packs,global_packs,kubejs,maps,mods,openloader,scripts,shrines-saves,structures,structurize,worldshape,Zoestria
de.griefed.serverpackcreator.configuration.directories.mustinclude=addonpacks,blueprints,config,configs,customnpcs,defaultconfigs,global_data_packs,global_packs,kubejs,maps,mods,openloader,scripts,shrines-saves,structures,structurize,worldshape,Zoestria,modernfix
de.griefed.serverpackcreator.serverpack.zip.exclude=minecraft_server.MINECRAFT_VERSION.jar,server.jar,libraries/net/minecraft/server/MINECRAFT_VERSION/server-MINECRAFT_VERSION.jar
de.griefed.serverpackcreator.serverpack.zip.exclude.enabled=true
de.griefed.serverpackcreator.minecraft.snapshots=false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* Copyright (C) 2024 Griefed
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
* The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE
*/
package de.griefed.serverpackcreator.app.gui.components

/**
* Drop type to determine whether filters should only include certain types of files or folders.
*
* @author Griefed
*/
enum class FileFieldDropType {
FILE,
FOLDER,
FOLDER_OR_ZIP,
IMAGE,
PROPERTIES
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ package de.griefed.serverpackcreator.app.gui.components
import de.griefed.serverpackcreator.app.gui.GuiProps
import de.griefed.serverpackcreator.app.gui.window.configs.components.SuggestionProvider
import java.awt.Toolkit
import java.awt.dnd.DropTarget
import java.awt.event.KeyEvent
import java.awt.event.KeyListener
import javax.swing.BorderFactory
import javax.swing.DropMode
import javax.swing.JScrollPane
import javax.swing.JTextField
import javax.swing.event.DocumentListener
Expand Down Expand Up @@ -92,6 +94,22 @@ open class ScrollTextField(
}
}

override fun getDropTarget(): DropTarget {
return textField.dropTarget
}

override fun setDropTarget(dropTarget: DropTarget) {
textField.dropTarget = dropTarget
}

fun setDropMode(mode: DropMode) {
textField.dropMode = mode
}

fun getDropMode(): DropMode {
return textField.dropMode
}

/**
* @author Griefed
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
package de.griefed.serverpackcreator.app.gui.components

import de.griefed.serverpackcreator.app.gui.GuiProps
import java.awt.datatransfer.DataFlavor
import java.awt.dnd.DnDConstants
import java.awt.dnd.DropTarget
import java.awt.dnd.DropTargetDropEvent
import java.io.File
import javax.swing.DropMode
import javax.swing.JTextField

/**
Expand All @@ -32,10 +37,11 @@ import javax.swing.JTextField
class ScrollTextFileField(
guiProps: GuiProps,
text: String,
dropType: FileFieldDropType,
textField: JTextField = JTextField(text),
horizontalScrollbarVisibility: Int = HORIZONTAL_SCROLLBAR_AS_NEEDED
) : ScrollTextField(guiProps, text, null, textField, horizontalScrollbarVisibility) {
constructor(guiProps: GuiProps,file: File, documentChangeListener: DocumentChangeListener) : this(guiProps,file.absolutePath) {
constructor(guiProps: GuiProps,file: File, dropType: FileFieldDropType, documentChangeListener: DocumentChangeListener) : this(guiProps,file.absolutePath, dropType) {
this.addDocumentListener(documentChangeListener)
}

Expand All @@ -50,5 +56,68 @@ class ScrollTextFileField(
init {
textField.isEditable = guiProps.allowManualEditing
file = File(text).absoluteFile

textField.setDropMode(DropMode.INSERT)
textField.dropTarget = object : DropTarget() {
override fun drop(event: DropTargetDropEvent?) {
val transferable = event?.transferable ?: return
if (!event.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
return
}
val files : List<File>

try {
event.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE)
files = transferable.getTransferData(DataFlavor.javaFileListFlavor) as List<File>
} catch (e: Exception) {
return
}

if (files.size != 1) {
return
}

val file = files[0]

when (dropType) {
FileFieldDropType.FILE -> {
if (!file.isFile || file.isDirectory) {
return
}
}

FileFieldDropType.FOLDER -> {
if (!file.isDirectory) {
return
}
}

FileFieldDropType.FOLDER_OR_ZIP -> {
if (!file.isDirectory && !file.name.endsWith(".zip", ignoreCase = true)) {
return
}
}

FileFieldDropType.IMAGE -> {
if (!file.isFile || file.isDirectory ||
(!file.name.endsWith(".png", ignoreCase = true) &&
!file.name.endsWith(".jpg", ignoreCase = true) &&
!file.name.endsWith(".jpeg", ignoreCase = true) &&
!file.name.endsWith(".bmp", ignoreCase = true))) {
return
}
}

FileFieldDropType.PROPERTIES -> {
if (!file.isFile || file.isDirectory ||
!file.name.endsWith(".properties", ignoreCase = true)) {
return
}
}
}

this@ScrollTextFileField.file = file
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,21 @@ class ConfigEditor(

private val modpackIcon = StatusIcon(guiProps,Translations.createserverpack_gui_createserverpack_labelmodpackdir_tip.toString())
private val modpackLabel = ElementLabel(Translations.createserverpack_gui_createserverpack_labelmodpackdir.toString())
private val modpackSetting = ScrollTextFileField(guiProps,apiWrapper.apiProperties.homeDirectory, validationChangeListener)
private val modpackSetting = ScrollTextFileField(guiProps,apiWrapper.apiProperties.homeDirectory, FileFieldDropType.FOLDER_OR_ZIP, validationChangeListener)
private val modpackChooser = BalloonTipButton(null, guiProps.folderIcon, Translations.createserverpack_gui_browser.toString(), guiProps) { selectModpackDirectory() }
private val modpackCheck = BalloonTipButton(null, guiProps.inspectIcon,Translations.createserverpack_gui_buttonmodpackdir_scan_tip.toString(), guiProps) { updateGuiFromSelectedModpack() }

private val propertiesIcon = StatusIcon(guiProps,Translations.createserverpack_gui_createserverpack_labelpropertiespath_tip.toString())
private val propertiesLabel = ElementLabel(Translations.createserverpack_gui_createserverpack_labelpropertiespath.toString())
private val propertiesSetting = ScrollTextFileField(guiProps,apiWrapper.apiProperties.defaultServerProperties, validationChangeListener)
private val propertiesSetting = ScrollTextFileField(guiProps,apiWrapper.apiProperties.defaultServerProperties, FileFieldDropType.PROPERTIES, validationChangeListener)
private val propertiesQuickSelectLabel = ElementLabel(Translations.createserverpack_gui_quickselect.toString())
private val propertiesQuickSelect = QuickSelect(tabbedConfigsTab.propertiesQuickSelections()) { setProperties() }
private val propertiesChooser = BalloonTipButton(null, guiProps.folderIcon, Translations.createserverpack_gui_browser.toString(), guiProps) { selectServerProperties() }
private val propertiesOpen = BalloonTipButton(null, guiProps.openIcon, Translations.createserverpack_gui_createserverpack_button_open_properties.toString(), guiProps) { openServerProperties() }

private val iconIcon = StatusIcon(guiProps,Translations.createserverpack_gui_createserverpack_labeliconpath_tip.toString())
private val iconLabel = ElementLabel(Translations.createserverpack_gui_createserverpack_labeliconpath.toString())
private val iconSetting = ScrollTextFileField(guiProps,apiWrapper.apiProperties.defaultServerIcon, validationChangeListener)
private val iconSetting = ScrollTextFileField(guiProps,apiWrapper.apiProperties.defaultServerIcon, FileFieldDropType.IMAGE, validationChangeListener)
private val iconQuickSelectLabel = ElementLabel(Translations.createserverpack_gui_quickselect.toString())
private val iconQuickSelect = QuickSelect(tabbedConfigsTab.iconQuickSelections()) { setIcon() }
private val iconChooser = BalloonTipButton(null, guiProps.folderIcon, Translations.createserverpack_gui_browser.toString(), guiProps) { selectServerIcon() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ import org.apache.commons.io.monitor.FileAlterationListener
import org.apache.commons.io.monitor.FileAlterationMonitor
import org.apache.commons.io.monitor.FileAlterationObserver
import org.apache.logging.log4j.kotlin.cachedLoggerOf
import java.awt.datatransfer.DataFlavor
import java.awt.dnd.DnDConstants
import java.awt.dnd.DropTarget
import java.awt.dnd.DropTargetDropEvent
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import java.io.File
Expand Down Expand Up @@ -88,6 +92,29 @@ class TabbedConfigsTab(

}

tabs.dropTarget = object : DropTarget() {
override fun drop(event: DropTargetDropEvent) {
val transferable = event?.transferable ?: return
if (!event.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
return
}
val files : List<File>

try {
event.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE)
files = transferable.getTransferData(DataFlavor.javaFileListFlavor) as List<File>
} catch (e: Exception) {
return
}

for (file in files) {
if (file.name.endsWith(".conf", ignoreCase = true)) {
loadConfig(file)
}
}
}
}

val lastLoadedConfigs = guiProps.getGuiProperty("lastloaded")
if (!lastLoadedConfigs.isNullOrBlank()) {
val configs = if (lastLoadedConfigs.contains(",")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import net.miginfocom.swing.MigLayout
import org.apache.logging.log4j.kotlin.cachedLoggerOf
import java.awt.BorderLayout
import java.awt.Dimension
import java.awt.datatransfer.DataFlavor
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import java.io.File
Expand Down Expand Up @@ -194,6 +195,9 @@ class InclusionsEditor(
inclusionList.selectionMode = ListSelectionModel.SINGLE_SELECTION
inclusionList.cellRenderer = InclusionSpecificationRenderer()
inclusionList.addListSelectionListener { event -> selectionOccurred(event) }
inclusionList.dropMode = DropMode.INSERT
inclusionList.transferHandler = InclusionsListHandler(this)

leftPanel.add(listScroller, BorderLayout.CENTER)
selectedInclusionDetailsScrollPanel.text = Translations.createserverpack_gui_inclusions_editor_tip_default.toString()
expertInclusionSettingsPanel.isVisible = false
Expand All @@ -219,7 +223,7 @@ class InclusionsEditor(
rightPanel.add(sourceSelect, "cell 2 0")
rightPanel.add(expertInclusionSettingsPanel, "cell 1 1 2 4, grow, w 50:50:, h 150:200:, hidemode 3")
rightPanel.add(selectedInclusionDetailsScrollPanel, "cell 1 1 2 4, grow, w 50:50:, h 150:200:, hidemode 3")
//rightPanel.add(inclusionsSelection, "cell 3 0")

rightPanel.add(inclusionsRevert, "cell 3 2")
rightPanel.add(inclusionsReset, "cell 3 3")
source.addDocumentListener(sourceListener)
Expand Down Expand Up @@ -507,13 +511,13 @@ class InclusionsEditor(
*/
@Suppress("SameParameterValue")
private fun addEntry(entry: String) {
addEntry(InclusionSpecification(entry))
addEntry(createInclusionSpec(File(entry)))
}

/**
* @author Griefed
*/
private fun addEntry(entry: InclusionSpecification) {
fun addEntry(entry: InclusionSpecification) {
inclusionModel.addElement(entry)
inclusionList.selectedIndex = inclusionList.lastVisibleIndex
if (inclusionList.model.size == 1) {
Expand Down Expand Up @@ -593,7 +597,7 @@ class InclusionsEditor(
/**
* @author Griefed
*/
private fun createInclusionSpec(sourceFile: File): InclusionSpecification {
fun createInclusionSpec(sourceFile: File): InclusionSpecification {
return if (sourceFile.path.startsWith(configEditor.getModpackDirectory())) {
val cleaned = sourceFile.path.replace(configEditor.getModpackDirectory() + File.separator, "")
InclusionSpecification(cleaned)
Expand Down Expand Up @@ -647,4 +651,35 @@ class InclusionsEditor(
"autocomplete.${exclusionFilter.identifier}",
exclusionSuggestions.joinToString(",") { entry -> entry.trim { it <= ' ' } }.trim { it <= ' ' })
}

class InclusionsListHandler(private val editor: InclusionsEditor): TransferHandler() {
override fun canImport(support: TransferSupport): Boolean {
if (!support.isDrop) {
return false
}
return support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
}

override fun importData(support: TransferSupport): Boolean {
if (!canImport(support)) {
return false
}

val transferable = support.transferable
val files: List<File>
try {
files = transferable.getTransferData(DataFlavor.javaFileListFlavor) as List<File>
} catch (e: Exception) {
return false
}

val inclSpecs = files.map { editor.createInclusionSpec(it) }

for (spec in inclSpecs) {
editor.addEntry(spec)
}

return true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,16 @@ class SelectedInclusionDetails(
menu.add(addToWhitelist)
textPane.addMouseListener(object: MouseAdapter() {
override fun mouseClicked(e: MouseEvent) {
val selection = inclusionList.selectedValue
if (inclusionList.valueIsAdjusting) {
return
}
if (inclusionList.isSelectionEmpty) {
return
}
if (!SwingUtilities.isRightMouseButton(e)) {
return
}
when (selection.source) {
when (inclusionList.selectedValue.source) {
"mods" -> {
if (textPane.selectedText.isNullOrEmpty()) {
addToExclusions.isEnabled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class GlobalSettings(

private val homeIcon = StatusIcon(guiProps, Translations.settings_global_home_tooltip.toString())
private val homeLabel = ElementLabel(Translations.settings_global_home_label.toString())
private val homeSetting = ScrollTextFileField(guiProps, apiProperties.homeDirectory.absoluteFile, changeListener)
private val homeSetting = ScrollTextFileField(guiProps, apiProperties.homeDirectory.absoluteFile, FileFieldDropType.FOLDER, changeListener)
private val homeRevert = BalloonTipButton(null, guiProps.revertIcon, Translations.settings_revert.toString(), guiProps) { homeSetting.file = apiProperties.homeDirectory }
private val homeReset = BalloonTipButton(null, guiProps.resetIcon,Translations.settings_reset.toString(), guiProps) { homeSetting.file = apiProperties.home }
private val homeChoose = BalloonTipButton(null, guiProps.folderIcon,Translations.settings_select_directory.toString(), guiProps) {
Expand Down Expand Up @@ -87,7 +87,7 @@ class GlobalSettings(

private val serverPacksIcon = StatusIcon(guiProps, Translations.settings_global_serverpacks_tooltip.toString())
private val serverPacksLabel = ElementLabel(Translations.settings_global_serverpacks_label.toString())
private val serverPacksSetting = ScrollTextFileField(guiProps, apiProperties.serverPacksDirectory.absoluteFile, changeListener)
private val serverPacksSetting = ScrollTextFileField(guiProps, apiProperties.serverPacksDirectory.absoluteFile, FileFieldDropType.FOLDER, changeListener)
private val serverPacksRevert = BalloonTipButton(null, guiProps.revertIcon, Translations.settings_revert.toString(), guiProps) { serverPacksSetting.file = apiProperties.serverPacksDirectory }
private val serverPacksReset = BalloonTipButton(null, guiProps.resetIcon,Translations.settings_reset.toString(), guiProps) { serverPacksSetting.file = apiProperties.defaultServerPacksDirectory() }
private val serverPacksChoose = BalloonTipButton(null, guiProps.folderIcon,Translations.settings_select_directory.toString(), guiProps) {
Expand Down
Loading

0 comments on commit 8efd153

Please sign in to comment.