Unstuck command and colored messages

master
Trivernis 5 years ago
parent f165e11cee
commit 5cbe0bedb3

@ -37,7 +37,7 @@ repositories {
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compileOnly "org.spigotmc:spigot-api:1.14.2-R0.1-SNAPSHOT"
compileOnly "org.spigotmc:spigot-api:1.14.4-R0.1-SNAPSHOT"
compileOnly 'net.ess3:EssentialsX:2.16.1'
compileOnly 'com.onarandombox.multiversecore:Multiverse-Core:4.0.0'
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"

@ -2,6 +2,8 @@ package net.trivernis.superutils
import com.earth2me.essentials.Essentials
import com.onarandombox.MultiverseCore.MultiverseCore
import net.md_5.bungee.api.ChatColor
import net.md_5.bungee.api.chat.ComponentBuilder
import net.trivernis.superutils.commands.CommandC
import org.bukkit.Server
import org.bukkit.configuration.file.FileConfiguration
@ -11,9 +13,9 @@ import org.bukkit.event.player.PlayerAdvancementDoneEvent
import org.bukkit.event.player.PlayerGameModeChangeEvent
import org.bukkit.event.world.WorldSaveEvent
import org.bukkit.potion.PotionEffectType
import net.md_5.bungee.api.chat.TextComponent
class EventListener(private val config: FileConfiguration, private val essentials: Essentials?,
private val multiverseCore: MultiverseCore?,
private val commandC: CommandC, private val server: Server): Listener {
/**
* Removes the night vision effect from the player if given by /c command
@ -44,13 +46,14 @@ class EventListener(private val config: FileConfiguration, private val essential
*/
@EventHandler fun onWorldSave(event: WorldSaveEvent) {
if (config.getBoolean("save-notification")) {
if (multiverseCore != null) {
if (multiverseCore.mvWorldManager.firstSpawnWorld.name == event.world.name) {
server.broadcastMessage("The world has been saved.")
}
} else {
if (event.world.name == "world") {
server.broadcastMessage("The world has been saved.")
server.consoleSender.sendMessage("The ${event.world.name} has been saved.")
server.operators.forEach {
val player = it.player
val message = ComponentBuilder("World ")
.append(event.world.name).color(ChatColor.RED)
.append(" has been saved").color(ChatColor.WHITE).create()
if (player?.world == event.world) {
player.spigot().sendMessage(*message)
}
}
}

@ -3,8 +3,6 @@ package net.trivernis.superutils
import com.earth2me.essentials.Essentials
import com.onarandombox.MultiverseCore.MultiverseCore
import net.trivernis.superutils.commands.*
import org.bukkit.configuration.file.FileConfiguration
import org.bukkit.entity.Minecart
import org.bukkit.plugin.java.JavaPlugin
class SuperUtils : JavaPlugin() {
@ -16,7 +14,7 @@ class SuperUtils : JavaPlugin() {
configure()
val essentials = getEssentials()
val commandC = CommandC(getMultiverseCore(), essentials)
server.pluginManager.registerEvents(EventListener(config, essentials, getMultiverseCore(), commandC, server), this)
server.pluginManager.registerEvents(EventListener(config, essentials, commandC, server), this)
getCommand("superutils reload")?.setExecutor(CommandReload(this))
getCommand("scheduleshutdown")?.setExecutor(CommandScheduleShutdown(this))
getCommand("c")?.setExecutor(commandC)
@ -25,6 +23,7 @@ class SuperUtils : JavaPlugin() {
logger.info("Registering short forms for Essentials plugin features.")
getCommand("h")?.setExecutor(CommandH(essentials))
getCommand("wp")?.setExecutor(CommandWp(essentials))
getCommand("unstuck")?.setExecutor(CommandUnstuck(essentials))
}
}

@ -2,6 +2,8 @@ package net.trivernis.superutils.commands
import com.earth2me.essentials.Essentials
import com.onarandombox.MultiverseCore.MultiverseCore
import net.md_5.bungee.api.ChatColor
import net.md_5.bungee.api.chat.ComponentBuilder
import org.bukkit.GameMode
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
@ -25,7 +27,8 @@ class CommandC(private var multiverseCore: MultiverseCore?, private var essentia
sender.addPotionEffect(PotionEffectType.NIGHT_VISION.createEffect(1000000, 255))
essUser.takeMoney(commandCost)
} else {
sender.sendMessage("You do not have enough money for this command")
sender.spigot().sendMessage(*ComponentBuilder("You do not have enough money for this command")
.color(ChatColor.RED).create())
}
} else {
sender.gameMode = GameMode.SPECTATOR

@ -2,6 +2,8 @@ package net.trivernis.superutils.commands
import com.earth2me.essentials.Essentials
import com.earth2me.essentials.UserData
import net.md_5.bungee.api.ChatColor
import net.md_5.bungee.api.chat.ComponentBuilder
import org.bukkit.Location
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
@ -35,21 +37,24 @@ class CommandH(private var essentials: Essentials) : CommandExecutor, TabComplet
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
if (sender is Player && command.testPermission(sender)) {
val essUser = essentials.getUser(sender)
val userHome: Location
val userHome: Location?
userHome = if (args.isNotEmpty()) {
try {
essUser.getHome(args[0])
} catch (e: Exception) {
null
} as Location
}
} else {
essUser.getHome("home")
}
if (userHome != null) {
essUser.teleport.teleport(userHome.block.location, null, PlayerTeleportEvent.TeleportCause.COMMAND)
essUser.sendMessage("You have been teleported home.")
essUser.teleport.teleport(userHome.block.location, null,
PlayerTeleportEvent.TeleportCause.COMMAND)
sender.spigot().sendMessage(*ComponentBuilder("You have been teleported home.")
.color(ChatColor.YELLOW).create())
} else {
essUser.sendMessage("The specified home was not found.")
sender.spigot().sendMessage(*ComponentBuilder("The specified home was not found.")
.color(ChatColor.RED).create())
}
return true
} else {

@ -1,5 +1,7 @@
package net.trivernis.superutils.commands
import net.md_5.bungee.api.ChatColor
import net.md_5.bungee.api.chat.ComponentBuilder
import java.lang.Double.parseDouble
import net.trivernis.superutils.SuperUtils
import org.bukkit.command.Command
@ -24,7 +26,9 @@ class CommandScheduleShutdown(private val superUtils: SuperUtils): CommandExecut
sender.server.scheduler.scheduleSyncDelayedTask(superUtils, {
sender.server.shutdown()
}, (20*scheduling).toLong())
sender.server.broadcastMessage("Server shutdown in $scheduling seconds!")
sender.server.spigot().broadcast(*ComponentBuilder("Server restart in ")
.append(scheduling.toString()).color(ChatColor.RED).append("seconds!").color(ChatColor.WHITE)
.create())
return true
}

@ -0,0 +1,32 @@
package net.trivernis.superutils.commands
import com.earth2me.essentials.Essentials
import net.md_5.bungee.api.ChatColor
import org.bukkit.Material
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.bukkit.event.player.PlayerTeleportEvent
import net.md_5.bungee.api.chat.TextComponent
class CommandUnstuck(private val essentials: Essentials): CommandExecutor {
/**
* Teleports the player to the next air block above.
*/
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
return if (command.testPermission(sender) && sender is Player) {
val essUser = essentials.getUser(sender)
val location = sender.location
while (location.block.type != Material.AIR)
location.add(.0, 1.0, .0)
essUser.teleport.teleport(location, null, PlayerTeleportEvent.TeleportCause.PLUGIN)
true
} else {
val message = TextComponent("You do not have permission!")
message.color = ChatColor.RED
sender.spigot().sendMessage(message)
true
}
}
}

@ -3,6 +3,8 @@ package net.trivernis.superutils.commands
import com.earth2me.essentials.Essentials
import com.earth2me.essentials.Trade
import com.earth2me.essentials.User
import net.md_5.bungee.api.ChatColor
import net.md_5.bungee.api.chat.ComponentBuilder
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
@ -40,14 +42,17 @@ class CommandWp(private val essentials: Essentials): CommandExecutor, TabComplet
essUser.teleport.teleport(warp.block.location, teleportCost, PlayerTeleportEvent.TeleportCause.COMMAND)
return true
} else {
sender.sendMessage("You do not have enough money for this command.")
sender.spigot().sendMessage(*ComponentBuilder("You do not have enough money for this command.")
.color(ChatColor.RED).create())
return true
}
} else {
sender.sendMessage("Warp \"${args.first()}\" not found")
sender.spigot().sendMessage(*ComponentBuilder("Warp ").append(args.first()).color(ChatColor.RED)
.append(" not found!").color(ChatColor.WHITE).create())
}
} else {
sender.sendMessage("You need to specify a warp location.")
sender.spigot().sendMessage(*ComponentBuilder("You need to specify a warp location.")
.color(ChatColor.RED).create())
}
} else {
sender.sendMessage("This command can only be executed by a player.");

@ -30,6 +30,11 @@ commands:
permission: superutils.scheduleshutdown
permission-message: You do not have permission!
usage: /schedulerestart {seconds}
unstuck:
description: Teleports you to unstuck you.
permission: superutils.unstuck
permission-message: You do not have permission!
usage: /unstuck
permissions:
superutils.reload:
description: Allows reload command
@ -46,6 +51,9 @@ permissions:
superutils.scheduleshutdown:
description: Allow scheduleshutdown command
default: op
superutils.unstuck:
description: Allow unstuck command
default: op
superutils.*:
description: Wildcard permission
default: op

Loading…
Cancel
Save