Skip to content

Commit 1b811c2

Browse files
committed
Moved smart inventory to com.smc.smartinvs namespace.
Removed a few methods from ScriptablePluginContext and general cleanup of unused methods now that the class loader is fixed.
1 parent 4308902 commit 1b811c2

File tree

9 files changed

+158
-188
lines changed

9 files changed

+158
-188
lines changed

src/main/kotlin/com/pixlfox/scriptablemc/TypescriptLibraryExporter.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,19 @@ class TypescriptLibraryExporter {
8686
addClasses(
8787
com.pixlfox.scriptablemc.core.ScriptablePluginContext::class.java,
8888
com.pixlfox.scriptablemc.core.ScriptablePluginEngine::class.java,
89-
fr.minuskube.inv.SmartInventory::class.java,
90-
com.smc.utils.FileWrapper::class.java,
89+
90+
com.smc.utils.ItemBuilder::class.java,
9191
com.smc.utils.MysqlWrapper::class.java,
92+
9293
com.smc.version.MinecraftVersion::class.java,
9394
com.smc.version.MinecraftVersions::class.java,
94-
com.pixlfox.scriptablemc.smartinvs.SmartInventoryProvider::class.java,
95-
com.pixlfox.scriptablemc.smartinvs.SmartInventoryInterface::class.java,
95+
96+
fr.minuskube.inv.SmartInventory::class.java,
97+
com.smc.smartinvs.SmartInventoryProvider::class.java,
98+
com.smc.smartinvs.SmartInventory::class.java,
99+
96100
com.google.common.io.ByteStreams::class.java,
101+
97102
java.io.File::class.java
98103
)
99104
return this
@@ -492,7 +497,7 @@ class TypescriptLibraryExporter {
492497
}
493498
}
494499

495-
for (_methodGroups in _class.methods.filter { e -> Modifier.isStatic(e.modifiers) && Modifier.isPublic(e.modifiers) }.groupBy { e -> e.name }) {
500+
for (_methodGroups in _class.methods.filter { e -> Modifier.isStatic(e.modifiers) && !Modifier.isPrivate(e.modifiers) }.groupBy { e -> e.name }) {
496501

497502
val jsMethodName: String = _methodGroups.key
498503

src/main/kotlin/com/pixlfox/scriptablemc/core/ScriptablePluginContext.kt

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package com.pixlfox.scriptablemc.core
22

3-
import com.pixlfox.scriptablemc.smartinvs.SmartInventoryInterface
4-
import com.pixlfox.scriptablemc.smartinvs.SmartItemBuilder
5-
import com.smc.utils.FileWrapper
6-
import com.smc.utils.MysqlWrapper
73
import me.clip.placeholderapi.PlaceholderAPI
84
import org.bukkit.Bukkit
95
import org.bukkit.OfflinePlayer
@@ -17,7 +13,6 @@ import java.util.HashMap
1713
import java.lang.reflect.InvocationTargetException
1814
import org.bukkit.command.PluginCommand
1915
import org.bukkit.entity.Player
20-
import org.bukkit.inventory.ItemStack
2116
import org.bukkit.plugin.*
2217
import org.bukkit.plugin.java.JavaPlugin
2318
import org.bukkit.plugin.messaging.PluginMessageListener
@@ -146,22 +141,6 @@ class ScriptablePluginContext(private val engine: ScriptablePluginEngine, val pl
146141
knownCommandsField?.isAccessible = false
147142
}
148143

149-
fun getFile(pathName: String): FileWrapper {
150-
return FileWrapper(pathName)
151-
}
152-
153-
fun newMysqlInstance(host: String, port: Int, database: String, username: String, password: String): MysqlWrapper {
154-
return MysqlWrapper(host, port, database, username, password)
155-
}
156-
157-
fun smartInventory(): SmartInventoryInterface {
158-
return SmartInventoryInterface()
159-
}
160-
161-
fun itemBuilder(itemStack: ItemStack): SmartItemBuilder {
162-
return SmartItemBuilder(itemStack)
163-
}
164-
165144
fun setPlaceholders(player: Player, placeholderText: String): String {
166145
if(Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
167146
return PlaceholderAPI.setPlaceholders(player, placeholderText)

src/main/kotlin/com/pixlfox/scriptablemc/core/ScriptablePluginEngine.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ private val helperClasses: Array<String> = arrayOf(
1414
"com.smc.version.MinecraftVersion",
1515
"com.smc.version.MinecraftVersions",
1616
"com.smc.version.SnapshotVersion",
17-
"com.smc.utils.FileWrapper",
18-
"com.smc.utils.MysqlWrapper"
17+
18+
"com.smc.utils.ItemBuilder",
19+
"com.smc.utils.MysqlWrapper",
20+
21+
"com.smc.smartinvs.SmartInventory",
22+
"com.smc.smartinvs.SmartInventoryProvider",
23+
24+
"*me.clip.placeholderapi.PlaceholderAPI"
25+
1926
)
2027

2128
@Suppress("MemberVisibilityCanBePrivate", "unused")
@@ -41,11 +48,13 @@ class ScriptablePluginEngine(val bootstrapPlugin: JavaPlugin, val rootScriptsFol
4148

4249
for(helperClass in helperClasses) {
4350
try {
44-
javaClass.classLoader.loadClass(helperClass)
51+
javaClass.classLoader.loadClass(helperClass.replace("*", ""))
4552
}
4653
catch (e: Exception) {
47-
bootstrapPlugin.logger.warning("Failed to load helper class \"$helperClass\" via classloader.")
48-
e.printStackTrace()
54+
if(!helperClass.startsWith("*")) {
55+
bootstrapPlugin.logger.warning("Failed to load helper class \"$helperClass\" via classloader.")
56+
e.printStackTrace()
57+
}
4958
}
5059
}
5160

src/main/kotlin/com/pixlfox/scriptablemc/smartinvs/ScriptablePluginMenu.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.pixlfox.scriptablemc.smartinvs
22

33
import com.pixlfox.scriptablemc.core.ScriptablePluginEngine
4+
import com.smc.utils.ItemBuilder
45
import fr.minuskube.inv.content.InventoryContents
56
import fr.minuskube.inv.content.InventoryProvider
67
import org.bukkit.entity.Player
@@ -19,23 +20,23 @@ class MainMenu(private val pluginEngine: ScriptablePluginEngine) : InventoryProv
1920
override fun init(player: Player?, contents: InventoryContents?) {
2021
if(contents != null && player != null) {
2122
if(player.hasPermission("scriptablemc.reload")) {
22-
contents.set(0, 0, ClickableItem.of(SmartItemBuilder(Material.GOLD_NUGGET)
23+
contents.set(0, 0, ClickableItem.of(ItemBuilder(Material.GOLD_NUGGET)
2324
.setDisplayName("${ChatColor.DARK_AQUA}Reload Script Engine")
2425
.build()) {
2526
Bukkit.getServer().dispatchCommand(player, "scriptablemc reload")
2627
})
2728
}
2829

2930
if(player.hasPermission("scriptablemc.info")) {
30-
contents.set(0, 1, ClickableItem.of(SmartItemBuilder(Material.IRON_NUGGET)
31+
contents.set(0, 1, ClickableItem.of(ItemBuilder(Material.IRON_NUGGET)
3132
.setDisplayName("${ChatColor.GREEN}Print ScriptableMC Info")
3233
.build()) {
3334
Bukkit.getServer().dispatchCommand(player, "scriptablemc info")
3435
player.closeInventory()
3536
})
3637
}
3738

38-
contents.set(0, 8, ClickableItem.of(SmartItemBuilder(Material.BARRIER)
39+
contents.set(0, 8, ClickableItem.of(ItemBuilder(Material.BARRIER)
3940
.setDisplayName("${ChatColor.RED}Close Menu")
4041
.build()) {
4142
player.closeInventory()

src/main/kotlin/com/pixlfox/scriptablemc/smartinvs/SmartInventoryInterface.kt

Lines changed: 0 additions & 122 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.smc.smartinvs
2+
3+
import com.pixlfox.scriptablemc.core.ScriptablePluginEngine
4+
import fr.minuskube.inv.ClickableItem
5+
import fr.minuskube.inv.SmartInventory
6+
import fr.minuskube.inv.content.InventoryContents
7+
import fr.minuskube.inv.content.InventoryProvider
8+
import org.bukkit.entity.Player
9+
import org.bukkit.event.inventory.InventoryClickEvent
10+
import org.bukkit.inventory.ItemStack
11+
import org.graalvm.polyglot.Value
12+
import java.util.function.Consumer
13+
14+
@Suppress("unused", "MemberVisibilityCanBePrivate")
15+
object SmartInventory {
16+
@JvmStatic
17+
fun builder(): SmartInventory.Builder {
18+
return SmartInventory.builder().manager(ScriptablePluginEngine.instance!!.inventoryManager)
19+
}
20+
21+
@JvmStatic
22+
fun provider(scriptableObject: Value): SmartInventoryProvider {
23+
if (scriptableObject.canInstantiate()) {
24+
return provider(scriptableObject.newInstance())
25+
}
26+
27+
return SmartInventoryProvider(scriptableObject)
28+
}
29+
30+
@JvmStatic
31+
fun clickableItem(item: ItemStack): ClickableItem {
32+
return ClickableItem.empty(item)
33+
}
34+
35+
@JvmStatic
36+
fun clickableItem(item: ItemStack, consumer: Consumer<InventoryClickEvent>): ClickableItem {
37+
return ClickableItem.of(item, consumer)
38+
}
39+
}
40+
41+
class SmartInventoryProvider(private val scriptableObject: Value) : InventoryProvider {
42+
override fun init(player: Player, contents: InventoryContents) {
43+
if(scriptableObject.hasMember("init") && scriptableObject.canInvokeMember("init")) {
44+
scriptableObject.invokeMember("init", player, contents)
45+
}
46+
}
47+
48+
override fun update(player: Player, contents: InventoryContents) {
49+
if(scriptableObject.hasMember("update") && scriptableObject.canInvokeMember("update")) {
50+
scriptableObject.invokeMember("update", player, contents)
51+
}
52+
}
53+
}

src/main/kotlin/com/smc/utils/FileWrapper.kt

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)