-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
312 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/dev/mikchan/mcnp/chat/commands/command/SpyCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package dev.mikchan.mcnp.chat.commands.command | ||
|
||
import dev.mikchan.mcnp.chat.ChatPlugin | ||
import org.bukkit.ChatColor | ||
import org.bukkit.command.Command | ||
import org.bukkit.command.CommandSender | ||
import org.bukkit.entity.Player | ||
|
||
class SpyCommand(private val plugin: ChatPlugin) : ICommand { | ||
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean { | ||
val player = sender as? Player | ||
|
||
if (player == null) { | ||
sender.sendMessage("${ChatColor.DARK_RED}This action is only accessible to players.") | ||
return false | ||
} | ||
|
||
if (!player.hasPermission("mcn.chat.spy")) { | ||
sender.sendMessage("${ChatColor.DARK_RED}You have no permission to do that.") | ||
return false | ||
} | ||
|
||
val prev = try { | ||
player.persistentDataContainer.getOrDefault(plugin.keys.spy.key, plugin.keys.spy.type, 0.toByte()) | ||
} catch (ignore: Exception) { | ||
0.toByte() | ||
} | ||
|
||
val next = ((prev + 1) % 2).toByte() | ||
player.persistentDataContainer.set(plugin.keys.spy.key, plugin.keys.spy.type, next) | ||
|
||
when (next) { | ||
1.toByte() -> { | ||
player.sendMessage("${ChatColor.DARK_GREEN}Spy is switched on!") | ||
} | ||
|
||
0.toByte() -> { | ||
player.sendMessage("${ChatColor.DARK_GREEN}Spy is switched off!") | ||
} | ||
|
||
else -> { | ||
player.sendMessage("${ChatColor.DARK_RED}Error.") | ||
} | ||
} | ||
|
||
return true | ||
} | ||
|
||
override fun onTabComplete( | ||
sender: CommandSender, command: Command, label: String, args: Array<out String> | ||
): MutableList<String> { | ||
return mutableListOf() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/dev/mikchan/mcnp/chat/events/listener/MCNCListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package dev.mikchan.mcnp.chat.events.listener | ||
|
||
import dev.mikchan.mcnp.chat.ChatPlugin | ||
import dev.mikchan.mcnp.chat.events.event.MCNChatEvent | ||
import org.bukkit.entity.Player | ||
import org.bukkit.event.EventHandler | ||
import org.bukkit.event.EventPriority | ||
import org.bukkit.event.Listener | ||
|
||
|
||
internal class MCNCListener(private val plugin: ChatPlugin) : Listener { | ||
private fun checkSpy(player: Player): Boolean { | ||
return try { | ||
player.persistentDataContainer.getOrDefault( | ||
plugin.keys.spy.key, plugin.keys.spy.type, 0.toByte() | ||
) != 0.toByte() && player.hasPermission("mcn.chat.spy") | ||
} catch (ignore: Exception) { | ||
false | ||
} | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) | ||
fun onMCNCEvent(event: MCNChatEvent) { | ||
if (event.isCancelled) return | ||
if (event.isPreview) return | ||
if (event.isGlobal) return | ||
|
||
plugin.server.scheduler.scheduleSyncDelayedTask(plugin) { | ||
val spies = plugin.server.onlinePlayers.filter { player -> !event.recipients.contains(player) } | ||
.filter { player -> checkSpy(player) }.toSet() | ||
|
||
if (spies.isEmpty()) return@scheduleSyncDelayedTask | ||
|
||
val msg = plugin.formatter.formatSpy(event.sender, event.message) | ||
for (spy in spies) { | ||
spy.sendMessage(event.sender.uniqueId, msg) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.