Unstuck command and colored messages

master
Trivernis 5 years ago
parent f165e11cee
commit 5cbe0bedb3

@ -37,7 +37,7 @@ repositories {
dependencies { dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12' 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 'net.ess3:EssentialsX:2.16.1'
compileOnly 'com.onarandombox.multiversecore:Multiverse-Core:4.0.0' compileOnly 'com.onarandombox.multiversecore:Multiverse-Core:4.0.0'
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8" compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"

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

@ -3,8 +3,6 @@ package net.trivernis.superutils
import com.earth2me.essentials.Essentials import com.earth2me.essentials.Essentials
import com.onarandombox.MultiverseCore.MultiverseCore import com.onarandombox.MultiverseCore.MultiverseCore
import net.trivernis.superutils.commands.* import net.trivernis.superutils.commands.*
import org.bukkit.configuration.file.FileConfiguration
import org.bukkit.entity.Minecart
import org.bukkit.plugin.java.JavaPlugin import org.bukkit.plugin.java.JavaPlugin
class SuperUtils : JavaPlugin() { class SuperUtils : JavaPlugin() {
@ -16,7 +14,7 @@ class SuperUtils : JavaPlugin() {
configure() configure()
val essentials = getEssentials() val essentials = getEssentials()
val commandC = CommandC(getMultiverseCore(), essentials) 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("superutils reload")?.setExecutor(CommandReload(this))
getCommand("scheduleshutdown")?.setExecutor(CommandScheduleShutdown(this)) getCommand("scheduleshutdown")?.setExecutor(CommandScheduleShutdown(this))
getCommand("c")?.setExecutor(commandC) getCommand("c")?.setExecutor(commandC)
@ -25,6 +23,7 @@ class SuperUtils : JavaPlugin() {
logger.info("Registering short forms for Essentials plugin features.") logger.info("Registering short forms for Essentials plugin features.")
getCommand("h")?.setExecutor(CommandH(essentials)) getCommand("h")?.setExecutor(CommandH(essentials))
getCommand("wp")?.setExecutor(CommandWp(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.earth2me.essentials.Essentials
import com.onarandombox.MultiverseCore.MultiverseCore 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.GameMode
import org.bukkit.command.Command import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor 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)) sender.addPotionEffect(PotionEffectType.NIGHT_VISION.createEffect(1000000, 255))
essUser.takeMoney(commandCost) essUser.takeMoney(commandCost)
} else { } 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 { } else {
sender.gameMode = GameMode.SPECTATOR sender.gameMode = GameMode.SPECTATOR

@ -2,6 +2,8 @@ package net.trivernis.superutils.commands
import com.earth2me.essentials.Essentials import com.earth2me.essentials.Essentials
import com.earth2me.essentials.UserData 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.Location
import org.bukkit.command.Command import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor 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 { override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
if (sender is Player && command.testPermission(sender)) { if (sender is Player && command.testPermission(sender)) {
val essUser = essentials.getUser(sender) val essUser = essentials.getUser(sender)
val userHome: Location val userHome: Location?
userHome = if (args.isNotEmpty()) { userHome = if (args.isNotEmpty()) {
try { try {
essUser.getHome(args[0]) essUser.getHome(args[0])
} catch (e: Exception) { } catch (e: Exception) {
null null
} as Location }
} else { } else {
essUser.getHome("home") essUser.getHome("home")
} }
if (userHome != null) { if (userHome != null) {
essUser.teleport.teleport(userHome.block.location, null, PlayerTeleportEvent.TeleportCause.COMMAND) essUser.teleport.teleport(userHome.block.location, null,
essUser.sendMessage("You have been teleported home.") PlayerTeleportEvent.TeleportCause.COMMAND)
sender.spigot().sendMessage(*ComponentBuilder("You have been teleported home.")
.color(ChatColor.YELLOW).create())
} else { } 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 return true
} else { } else {

@ -1,5 +1,7 @@
package net.trivernis.superutils.commands 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 java.lang.Double.parseDouble
import net.trivernis.superutils.SuperUtils import net.trivernis.superutils.SuperUtils
import org.bukkit.command.Command import org.bukkit.command.Command
@ -24,7 +26,9 @@ class CommandScheduleShutdown(private val superUtils: SuperUtils): CommandExecut
sender.server.scheduler.scheduleSyncDelayedTask(superUtils, { sender.server.scheduler.scheduleSyncDelayedTask(superUtils, {
sender.server.shutdown() sender.server.shutdown()
}, (20*scheduling).toLong()) }, (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 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.Essentials
import com.earth2me.essentials.Trade import com.earth2me.essentials.Trade
import com.earth2me.essentials.User 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.Command
import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender 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) essUser.teleport.teleport(warp.block.location, teleportCost, PlayerTeleportEvent.TeleportCause.COMMAND)
return true return true
} else { } 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 return true
} }
} else { } 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 { } 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 { } else {
sender.sendMessage("This command can only be executed by a player."); sender.sendMessage("This command can only be executed by a player.");

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

Loading…
Cancel
Save