Skip to content

Commit

Permalink
Merge branch 'master' into mc1.12.2-we6
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsimmo committed Oct 10, 2021
2 parents cefac85 + 5ca9b99 commit 13bdfb1
Show file tree
Hide file tree
Showing 28 changed files with 762 additions and 210 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ Bomberman

A Bukkit plugin for Minecraft which adds Bomberman.

See more on the bukkit page:
http://dev.bukkit.org/bukkit-plugins/bomberman/
https://www.spigotmc.org/resources/bomberman.77616/

## Building

To build bomberman, run

<code>./gradlew build</code>
```shell
# To build exactly as released
./gradlew minify

# To skip shading and proguard
# ./gradlew build
```


To have the built file automatically copied to a local testing minecraft server:

Expand Down
75 changes: 55 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.guardsquare:proguard-gradle:7.1.0'
}
}

plugins {
id 'com.github.johnrengelman.shadow' version '7.1.0'
id 'java'
id "org.jetbrains.kotlin.jvm" version "1.5.21"
id 'idea'
id "org.jetbrains.kotlin.jvm" version "1.5.31"
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

group = 'io.github.mdsimmo'
version = '0.5.0-1.12.2-R1'
version = '0.6.4-1.12.2-R1'

repositories {
mavenCentral()
Expand All @@ -20,11 +29,23 @@ repositories {
// world edit repo
url "https://maven.enginehub.org/repo"
}
maven {
// PlaceholderAPI
url = 'https://repo.extendedclip.com/content/repositories/placeholderapi/'
}
maven {
name = "sonatype-oss-snapshots"
url = "https://oss.sonatype.org/content/repositories/snapshots/"
}
maven {
url 'https://libraries.minecraft.net/'
}
}

dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.21'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.31'
implementation "net.objecthunter:exp4j:0.4.8"
//implementation "me.lucko:commodore:1.10"

compileOnly "org.bukkit:bukkit:1.12.2-R0.1-SNAPSHOT"
testImplementation "org.bukkit:bukkit:1.12.2-R0.1-SNAPSHOT"
Expand All @@ -33,23 +54,45 @@ dependencies {
compileOnly "com.sk89q.worldedit:worldedit-bukkit:6.1.5"
testImplementation "com.sk89q.worldedit:worldedit-bukkit:6.1.5"

compileOnly 'me.clip:placeholderapi:2.10+'
testImplementation 'me.clip:placeholderapi:2.10+'

testImplementation "junit:junit:4.13.+"
testImplementation "org.mockito:mockito-core:3.3.+"
}

shadowJar {
relocate 'net.objecthunter', 'io.github.mdsimmo.bomberman.lib.net.objecthunter'
//relocate 'me.lucko', 'io.github.mdsimmo.bomberman.lib.me.lucko'
relocate 'com.mojang', 'io.github.mdsimmo.bomberman.lib.com.mojang'
relocate 'kotlin', 'io.github.mdsimmo.bomberman.lib.kotlin'
relocate 'org.jetbrains', 'io.github.mdsimmo.bomberman.lib.org.jetbrains'
relocate 'org.intellij', 'io.github.mdsimmo.bomberman.lib.org.intellij'
}

processResources {
// auto assign values in the plugin.yml
// Do not filter schematics as they get corrupted when trying to be read as text
filesNotMatching(["**.schematic"]) {
filesMatching("plugin.yml") {
filter {
line ->
line
.replace('${version}', version)
line -> line.replace('${version}', version)
}
}
}

task minify(type: proguard.gradle.ProGuardTask, dependsOn: shadowJar) {
injars shadowJar.outputs.files
outjars "build/libs/Bomberman-${version}-min.jar"

libraryjars "${System.getProperty('java.home')}/jmods/java.base.jmod"
libraryjars "${System.getProperty('java.home')}/jmods/java.logging.jmod"
libraryjars configurations.findByName('compileOnly').getFiles()

// only remove unused library code (mostly kotlin)
keep "public class !io.github.mdsimmo.bomberman.lib.** { *; }"

// Don't rename anything
dontobfuscate
}

task clearOldPluginJar( type: Delete ) {
description 'Deletes any old bomberman plugins from the server'
if ( project.hasProperty("serverLocation" ) ) {
Expand All @@ -62,23 +105,15 @@ task clearOldPluginJar( type: Delete ) {
task copyToServer(type: Copy, dependsOn: clearOldPluginJar ) {
description 'Copies the plugin to the server'
if ( project.hasProperty("serverLocation" ) ) {
from jar
from minify
into "$serverLocation/plugins/update"
}
}

task install( dependsOn: [build, copyToServer] ) {
task install( dependsOn: [minify, copyToServer] ) {
description 'Compiles, tests and copies the code to the server'
}

jar {
from {
configurations.runtimeClasspath.collect {
it.isDirectory() ? it : zipTree(it)
}
}
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Expand Down
5 changes: 2 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Thu Apr 16 19:13:08 AEST 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
50 changes: 50 additions & 0 deletions src/main/java/io/github/mdsimmo/bomberman/BmPlaceholder.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package io.github.mdsimmo.bomberman

import io.github.mdsimmo.bomberman.events.BmGameListIntent
import io.github.mdsimmo.bomberman.events.BmGameLookupIntent
import io.github.mdsimmo.bomberman.messaging.Message
import io.github.mdsimmo.bomberman.messaging.SenderWrapper
import io.github.mdsimmo.bomberman.messaging.SimpleContext
import me.clip.placeholderapi.expansion.PlaceholderExpansion
import org.bukkit.entity.Player

class BmPlaceholder : PlaceholderExpansion() {

override fun getIdentifier(): String = "bomberman"

override fun getAuthor(): String = "mdsimmo"

override fun getVersion(): String = "internal"

override fun persist(): Boolean = true

override fun onPlaceholderRequest(player: Player?, params: String): String {
val content = params.split('_')
when (content.getOrNull(0)) {
"info" -> {
val gameName = content.getOrNull(1) ?: return "info <name> <stat>"
val game = BmGameLookupIntent.find(gameName)
return game?.format(content.drop(2).map { Message.of(it) }, false)?.toString() ?: ""
}
"msg" -> {
return try {
SimpleContext(params.substring("msg_".length), false)
.with("games", BmGameListIntent.listGames())
.let {
if (player != null)
it.with("player", SenderWrapper(player))
else
it
}
.format()
.toString()
} catch (e: RuntimeException) {
Message.error(e.message ?: "Error").toString()
}
}
else -> return "<info|msg> ..."
}
}


}
6 changes: 5 additions & 1 deletion src/main/java/io/github/mdsimmo/bomberman/Bomberman.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bukkit.command.PluginCommand;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;

Expand Down Expand Up @@ -52,8 +53,11 @@ public void onEnable() {
bukkitBmCmd.setExecutor(bmCmd);
bukkitBmCmd.setTabCompleter(bmCmd);

Game.loadGames();
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
new BmPlaceholder().register();
}

Game.loadGames();
GamePlayer.setupLoginWatcher();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BaseCommand : CommandGroup(null), TabCompleter, CommandExecutor {

init {
addChildren(
//DevInfo(this),
// DevInfo(this),
Configure(this),
GameCreate(this),
GameInfo(this),
Expand All @@ -23,7 +23,8 @@ class BaseCommand : CommandGroup(null), TabCompleter, CommandExecutor {
RunStart(this),
RunStop(this),
GameList(this),
GameReload(this)
GameReload(this),
UndoBuild(this)
)
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/github/mdsimmo/bomberman/commands/Cmd.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ abstract class Cmd(protected var parent: Cmd?) : Formattable {
return text.with("command", this)
}

override fun format(args: List<Message>): Message {
override fun format(args: List<Message>, elevated: Boolean): Message {
return when (args.getOrElse(0) { "name" }.toString()) {
"name" -> name()
"path" -> Message.of(path())
Expand All @@ -108,15 +108,15 @@ abstract class Cmd(protected var parent: Cmd?) : Formattable {
"description" -> description()
"flags" -> CollectionWrapper(flags(Bukkit.getConsoleSender(), listOf(), mapOf())
.map { flag -> object: Formattable {
override fun format(args: List<Message>): Message {
override fun format(args: List<Message>, elevated: Boolean): Message {
return when ((args.firstOrNull() ?: "name").toString()) {
"name" -> Message.of(flag)
"ext" -> flagExtension(flag)
"description" -> flagDescription(flag)
else -> throw RuntimeException("Unknown flag value '" + args[0] + "'")
}
}
} }).format(args.drop(1))
} }).format(args.drop(1), elevated)
else -> throw RuntimeException("Unknown command value '" + args[0] + "'")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ abstract class CommandGroup(parent: Cmd?) : Cmd(parent) {
}
}

override fun format(args: List<Message>): Message {
override fun format(args: List<Message>, elevated: Boolean): Message {
return if (args.getOrNull(0).toString().equals("children", ignoreCase = true)) {
CollectionWrapper(children).format(args.drop(1))
CollectionWrapper(children).format(args.drop(1), elevated)
} else {
super.format(args)
super.format(args, elevated)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ enum class Permissions(val permission: String) : Permission {
BASE("bomberman.bm"),
CREATE("bomberman.create"),
DELETE("bomberman.delete"),
UNDO("bomberman.undo"),
RELOAD("bomberman.reload"),
CONFIGURE("bomberman.configure"),
START("bomberman.start"),
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/io/github/mdsimmo/bomberman/commands/game/DevInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.github.mdsimmo.bomberman.commands.Cmd
import io.github.mdsimmo.bomberman.commands.Permission
import io.github.mdsimmo.bomberman.commands.Permissions
import io.github.mdsimmo.bomberman.messaging.Message
import io.github.mdsimmo.bomberman.messaging.SimpleContext
import org.bukkit.Bukkit
import org.bukkit.ChatColor
import org.bukkit.command.CommandSender
Expand All @@ -18,7 +19,7 @@ class DevInfo(parent: Cmd) : Cmd(parent) {

override fun options(sender: CommandSender, args: List<String>): List<String> {
return listOf("handlerlist", "handlercount", "handlerwatch", "nocancelled",
"tasklist", "taskcount", "taskwatch", "watch")
"tasklist", "taskcount", "taskwatch", "watch", "permissions")
}

override fun run(sender: CommandSender, args: List<String>, flags: Map<String, String>): Boolean {
Expand Down Expand Up @@ -123,14 +124,24 @@ class DevInfo(parent: Cmd) : Cmd(parent) {
sender.sendMessage("Watching for new tasks")
true
}
"permissions" -> {
if (args.size == 1) {
sender.effectivePermissions.forEach {
sender.sendMessage(" - ${it.permission}")
}
} else {
sender.sendMessage(args[1] + " : " + sender.hasPermission(args[1]))
}
true
}
else -> {
false
}
}
}

override fun permission(): Permission {
return Permissions.CREATE
return Permissions.BASE
}

override fun example(): Message {
Expand Down
Loading

0 comments on commit 13bdfb1

Please sign in to comment.