Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobwgillespie committed Nov 9, 2015
0 parents commit 8641d9d
Show file tree
Hide file tree
Showing 14 changed files with 489 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea/
*.iml
target/
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: java
jdk:
- oraclejdk8

deploy:
provider: releases
api_key:
secure: i69Ci149qroyjyvq86Za2d99eXLdvDJkQUxPFld1HTwq3/KAMzeTMvXwePhzNinlI6tL8gz+sCqbVc7a+c9WxzQ9uyFjx56nalbXkpKHS+g8P6U3JiK+807XhoSn3YPB0bHMHjDZaGUjd435NQ7RPzbgRluWJFO0XLiJ1DhkDPYzYoN9T4S18USeVQPVIe8XW0r5/7oGLQbdGjH39LKpfpYXVrEMddwnqrjs4jjYUmNVOABiW+lMCkWi71aR4xE6MOvwaTKlmXZoX6YA3atUVBJtIDQfLoo4ubgFWKzOs0Azmt9Vn8p9tnxEQCNNhsuZfj6J1Rauat94VLrmgfRNFYFhT0aUr87TkE5l1nJuX8mUSSX4zj+5AFaR6NB7OsEfVrzZHE5grd7YJL3eks5CflLQVx8NIuhLAKU+fRxp26+ckQVNcLuB2xKIIZtFO8FYDItl2A2nCyvA6KZXFu/5OR1wUI/QoKroYNjpQhgfFp8Cn2+Zy5FLUMk18DWcb1ljrk4lr41lAfnbkcZ6DP3aQw1IQZWekhbKmYN2LzLJr889EPvdL5nyxXutR1kjpJOw3K0kafFQHNTSdivhV6hSgY8ns8sIZGQslwMcwgUpSYOVANRAz1lIRXNkAOfVeJfbth/my9/X6eb4gtD0o5FkHus3Y30enOddu1eYIdCZRuY=
file: target/ModTools-*.jar
file_glob: true
on:
repo: the-obsidian/ModTools
tags: true
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Copyright (c) 2015 Jacob Gillespie <[email protected]>

Permission is hereby granted, free of charge, to any person ob-
taining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without restric-
tion, including without limitation the rights to use, copy, modi-
fy, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is fur-
nished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONIN-
FRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# ModTools [![Build Status](https://travis-ci.org/the-obsidian/ModTools.svg?branch=master)](https://travis-ci.org/the-obsidian/ModTools)

Tools to enable moderation of our Minecraft servers

## Dependencies

* none

## Installation

1. Download the [latest release](https://github.com/the-obsidian/ModTools/releases) from GitHub
1. Add it to your `plugins` folder
1. Either run Bukkit/Spigot once to generate `ModTools/config.yml` or create it using the guide below.
1. All done!

## Configuration

ModTools has several options that can be configured in the `config.yml` file:

```yaml
# Prefix for plugin message
prefix: '&8[&7ModTools&8] &7'

# Format for spied private message
spy-format: '&8[&7%from% &8-> &7%to%&8] &7%msg%'

# Commands watched by spy
watched-commands:
- m
- msg
- r
- reply
- t
- tell
- whisper
```
## Permissions
* `modtools.use` - use modtools
* `modtools.spy` - use message spy
* `modtools.spy.auto` - automatically enable message spy on join

## Commands

* `/spy` - toggles message spy

## Features

* Message spy for listening into private messages

## Upcoming Features

* More mod tools
128 changes: 128 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>gg.obsidian</groupId>
<artifactId>ModTools</artifactId>
<version>1.0.0</version>
<description>Basic moderator toolkit</description>
<url>https://github.com/the-obsidian/ModTools</url>

<scm>
<connection>scm:git:https://github.com/the-obsidian/ModTools.git</connection>
<developerConnection>scm:git:https://github.com/the-obsidian/ModTools.git</developerConnection>
<url>https://github.com/the-obsidian/ModTools</url>
</scm>

<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.version>1.0.0-beta-1103</kotlin.version>
</properties>

<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>vault-repo</id>
<url>http://nexus.theyeticave.net/content/repositories/pub_releases</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>

<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId>
<version>2.5.0</version>
</dependency>

<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.5</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<defaultGoal>clean install</defaultGoal>

<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>*.yml</include>
</includes>
</resource>
</resources>

<plugins>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>

<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<createDependencyReducedPom>false</createDependencyReducedPom>
<artifactSet>
<excludes>
<exclude>org.spigotmc:*</exclude>
</excludes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
38 changes: 38 additions & 0 deletions src/main/kotlin/gg/obsidian/modtools/CommandHandler.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package gg.obsidian.modtools

import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player

class CommandHandler(val plugin: ModTools): CommandExecutor {

override fun onCommand(player: CommandSender, cmd: Command, alias: String?, args: Array<out String>?): Boolean {
if (player !is Player) {
plugin.utils.sendPrefixedMessage(player, "This command only works in-game")
return true
}

if (!Permissions.modtools.has(player)) {
plugin.utils.sendPrefixedMessage(player, "You do not have permission")
return true
}

if (cmd.name == "spy") {
if (!Permissions.spy.has(player)) {
plugin.utils.sendPrefixedMessage(player, "You do not have permission")
return true
}

if (plugin.hasSpyEnabled(player)) {
plugin.disableSpy(player)
plugin.utils.sendPrefixedMessage(player, "Spy disabled")
} else {
plugin.enableSpy(player)
plugin.utils.sendPrefixedMessage(player, "Spy enabled")
}
}

return true
}
}
18 changes: 18 additions & 0 deletions src/main/kotlin/gg/obsidian/modtools/Configuration.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package gg.obsidian.modtools

import java.util.*

class Configuration(val plugin: ModTools) {

var PREFIX = ""
var SPY_FORMAT = ""
var WATCHED_COMMANDS = ArrayList<String>()

fun load() {
plugin.reloadConfig()

SPY_FORMAT = plugin.getConfig().getString("spy-format")
PREFIX = plugin.getConfig().getString("prefix")
WATCHED_COMMANDS = plugin.getConfig().getStringList("watched-commands") as ArrayList<String>
}
}
56 changes: 56 additions & 0 deletions src/main/kotlin/gg/obsidian/modtools/EventListener.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package gg.obsidian.modtools

import org.bukkit.Bukkit
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerCommandPreprocessEvent
import org.bukkit.event.player.PlayerJoinEvent

class EventListener(val plugin: ModTools): Listener {

@EventHandler
fun onPlayerJoin(e: PlayerJoinEvent) {
if (Permissions.spyAuto.has(e.player)) {
plugin.enableSpy(e.player)
}
}

@EventHandler
fun onCommandPreprocess(e: PlayerCommandPreprocessEvent) {
plugin.logger.info("Got a command event")
try {
var message = e.message
if (message.startsWith("/")) {
message = message.substring(1)
}
message = message.replace("([ ]+)", "$1")

val args = message.split(" ")

plugin.logger.info("command was " + args)

if (!plugin.config.WATCHED_COMMANDS.contains(args[0].toLowerCase())) {
return
}

if (args[0].equals("r", ignoreCase = true) || args[0].equals("reply", ignoreCase = true)) {
if (args.size <= 1) return

val from = e.player
val to = Bukkit.getPlayer(MsgHistory.getTo(from))

MsgHistory.reportMessage(from, to)
plugin.utils.sendSpyMessage(from, to, args.subList(1, args.size).joinToString(" "))
} else if (args.size > 2) {
val from = e.player
val to = from.server.getPlayer(args[1])

MsgHistory.reportMessage(from, to)
plugin.utils.sendSpyMessage(from, to, args.subList(2, args.size).joinToString(" "))
}
} catch (e: Exception) {
plugin.logger.severe(e.message)
// Ignore errors
}
}
}
49 changes: 49 additions & 0 deletions src/main/kotlin/gg/obsidian/modtools/ModTools.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package gg.obsidian.modtools

import org.bukkit.entity.Player
import org.bukkit.metadata.FixedMetadataValue
import org.bukkit.plugin.java.JavaPlugin
import java.io.File

val SPY_METADATA_KEY = "MODTOOLS_SPY_ENABLED"

class ModTools : JavaPlugin() {

val config = Configuration(this)
val utils = Utils(this)

override fun onEnable() {
val configFile = File(dataFolder, "config.yml")
if (!configFile.exists()) {
getConfig().options().copyDefaults(true)
saveConfig()
}

config.load()

server.pluginManager.registerEvents(EventListener(this), this)
getCommand("spy").executor = CommandHandler(this)
}

fun enableSpy(player: Player) {
player.setMetadata(SPY_METADATA_KEY, FixedMetadataValue(this, true))
}

fun disableSpy(player: Player) {
player.setMetadata(SPY_METADATA_KEY, FixedMetadataValue(this, false))
}

fun hasSpyEnabled(player: Player): Boolean {
logger.info("checking spy for player " + player.name)
if (!player.hasMetadata(SPY_METADATA_KEY)) {
return false
}

val meta = player.getMetadata(SPY_METADATA_KEY)
if (meta.size == 0) {
return false
}

return meta[0].asBoolean()
}
}
Loading

0 comments on commit 8641d9d

Please sign in to comment.