Skip to content

Commit 8641d9d

Browse files
Initial commit
0 parents  commit 8641d9d

File tree

14 files changed

+489
-0
lines changed

14 files changed

+489
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea/
2+
*.iml
3+
target/

.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
language: java
2+
jdk:
3+
- oraclejdk8
4+
5+
deploy:
6+
provider: releases
7+
api_key:
8+
secure: i69Ci149qroyjyvq86Za2d99eXLdvDJkQUxPFld1HTwq3/KAMzeTMvXwePhzNinlI6tL8gz+sCqbVc7a+c9WxzQ9uyFjx56nalbXkpKHS+g8P6U3JiK+807XhoSn3YPB0bHMHjDZaGUjd435NQ7RPzbgRluWJFO0XLiJ1DhkDPYzYoN9T4S18USeVQPVIe8XW0r5/7oGLQbdGjH39LKpfpYXVrEMddwnqrjs4jjYUmNVOABiW+lMCkWi71aR4xE6MOvwaTKlmXZoX6YA3atUVBJtIDQfLoo4ubgFWKzOs0Azmt9Vn8p9tnxEQCNNhsuZfj6J1Rauat94VLrmgfRNFYFhT0aUr87TkE5l1nJuX8mUSSX4zj+5AFaR6NB7OsEfVrzZHE5grd7YJL3eks5CflLQVx8NIuhLAKU+fRxp26+ckQVNcLuB2xKIIZtFO8FYDItl2A2nCyvA6KZXFu/5OR1wUI/QoKroYNjpQhgfFp8Cn2+Zy5FLUMk18DWcb1ljrk4lr41lAfnbkcZ6DP3aQw1IQZWekhbKmYN2LzLJr889EPvdL5nyxXutR1kjpJOw3K0kafFQHNTSdivhV6hSgY8ns8sIZGQslwMcwgUpSYOVANRAz1lIRXNkAOfVeJfbth/my9/X6eb4gtD0o5FkHus3Y30enOddu1eYIdCZRuY=
9+
file: target/ModTools-*.jar
10+
file_glob: true
11+
on:
12+
repo: the-obsidian/ModTools
13+
tags: true

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Copyright (c) 2015 Jacob Gillespie <[email protected]>
2+
3+
Permission is hereby granted, free of charge, to any person ob-
4+
taining a copy of this software and associated documentation
5+
files (the "Software"), to deal in the Software without restric-
6+
tion, including without limitation the rights to use, copy, modi-
7+
fy, merge, publish, distribute, sublicense, and/or sell copies of
8+
the Software, and to permit persons to whom the Software is fur-
9+
nished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONIN-
17+
FRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19+
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# ModTools [![Build Status](https://travis-ci.org/the-obsidian/ModTools.svg?branch=master)](https://travis-ci.org/the-obsidian/ModTools)
2+
3+
Tools to enable moderation of our Minecraft servers
4+
5+
## Dependencies
6+
7+
* none
8+
9+
## Installation
10+
11+
1. Download the [latest release](https://github.com/the-obsidian/ModTools/releases) from GitHub
12+
1. Add it to your `plugins` folder
13+
1. Either run Bukkit/Spigot once to generate `ModTools/config.yml` or create it using the guide below.
14+
1. All done!
15+
16+
## Configuration
17+
18+
ModTools has several options that can be configured in the `config.yml` file:
19+
20+
```yaml
21+
# Prefix for plugin message
22+
prefix: '&8[&7ModTools&8] &7'
23+
24+
# Format for spied private message
25+
spy-format: '&8[&7%from% &8-> &7%to%&8] &7%msg%'
26+
27+
# Commands watched by spy
28+
watched-commands:
29+
- m
30+
- msg
31+
- r
32+
- reply
33+
- t
34+
- tell
35+
- whisper
36+
```
37+
38+
## Permissions
39+
40+
* `modtools.use` - use modtools
41+
* `modtools.spy` - use message spy
42+
* `modtools.spy.auto` - automatically enable message spy on join
43+
44+
## Commands
45+
46+
* `/spy` - toggles message spy
47+
48+
## Features
49+
50+
* Message spy for listening into private messages
51+
52+
## Upcoming Features
53+
54+
* More mod tools

pom.xml

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>gg.obsidian</groupId>
7+
<artifactId>ModTools</artifactId>
8+
<version>1.0.0</version>
9+
<description>Basic moderator toolkit</description>
10+
<url>https://github.com/the-obsidian/ModTools</url>
11+
12+
<scm>
13+
<connection>scm:git:https://github.com/the-obsidian/ModTools.git</connection>
14+
<developerConnection>scm:git:https://github.com/the-obsidian/ModTools.git</developerConnection>
15+
<url>https://github.com/the-obsidian/ModTools</url>
16+
</scm>
17+
18+
<packaging>jar</packaging>
19+
20+
<properties>
21+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
<kotlin.version>1.0.0-beta-1103</kotlin.version>
23+
</properties>
24+
25+
<repositories>
26+
<repository>
27+
<id>spigot-repo</id>
28+
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
29+
</repository>
30+
<repository>
31+
<id>vault-repo</id>
32+
<url>http://nexus.theyeticave.net/content/repositories/pub_releases</url>
33+
</repository>
34+
<repository>
35+
<id>jitpack.io</id>
36+
<url>https://jitpack.io</url>
37+
</repository>
38+
</repositories>
39+
40+
<dependencies>
41+
<dependency>
42+
<groupId>org.spigotmc</groupId>
43+
<artifactId>spigot-api</artifactId>
44+
<version>1.8.8-R0.1-SNAPSHOT</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.jetbrains.kotlin</groupId>
48+
<artifactId>kotlin-stdlib</artifactId>
49+
<version>${kotlin.version}</version>
50+
</dependency>
51+
52+
<dependency>
53+
<groupId>com.squareup.okhttp</groupId>
54+
<artifactId>okhttp</artifactId>
55+
<version>2.5.0</version>
56+
</dependency>
57+
58+
<dependency>
59+
<groupId>net.milkbowl.vault</groupId>
60+
<artifactId>VaultAPI</artifactId>
61+
<version>1.5</version>
62+
<scope>compile</scope>
63+
</dependency>
64+
</dependencies>
65+
66+
<build>
67+
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
68+
<defaultGoal>clean install</defaultGoal>
69+
70+
<resources>
71+
<resource>
72+
<targetPath>.</targetPath>
73+
<filtering>true</filtering>
74+
<directory>${basedir}/src/main/resources</directory>
75+
<includes>
76+
<include>*.yml</include>
77+
</includes>
78+
</resource>
79+
</resources>
80+
81+
<plugins>
82+
<plugin>
83+
<artifactId>kotlin-maven-plugin</artifactId>
84+
<groupId>org.jetbrains.kotlin</groupId>
85+
<version>${kotlin.version}</version>
86+
87+
<executions>
88+
<execution>
89+
<id>compile</id>
90+
<phase>compile</phase>
91+
<goals>
92+
<goal>compile</goal>
93+
</goals>
94+
</execution>
95+
<execution>
96+
<id>test-compile</id>
97+
<phase>test-compile</phase>
98+
<goals>
99+
<goal>test-compile</goal>
100+
</goals>
101+
</execution>
102+
</executions>
103+
</plugin>
104+
<plugin>
105+
<groupId>org.apache.maven.plugins</groupId>
106+
<artifactId>maven-shade-plugin</artifactId>
107+
<version>2.3</version>
108+
<executions>
109+
<execution>
110+
<phase>package</phase>
111+
<goals>
112+
<goal>shade</goal>
113+
</goals>
114+
<configuration>
115+
<minimizeJar>true</minimizeJar>
116+
<createDependencyReducedPom>false</createDependencyReducedPom>
117+
<artifactSet>
118+
<excludes>
119+
<exclude>org.spigotmc:*</exclude>
120+
</excludes>
121+
</artifactSet>
122+
</configuration>
123+
</execution>
124+
</executions>
125+
</plugin>
126+
</plugins>
127+
</build>
128+
</project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package gg.obsidian.modtools
2+
3+
import org.bukkit.command.Command
4+
import org.bukkit.command.CommandExecutor
5+
import org.bukkit.command.CommandSender
6+
import org.bukkit.entity.Player
7+
8+
class CommandHandler(val plugin: ModTools): CommandExecutor {
9+
10+
override fun onCommand(player: CommandSender, cmd: Command, alias: String?, args: Array<out String>?): Boolean {
11+
if (player !is Player) {
12+
plugin.utils.sendPrefixedMessage(player, "This command only works in-game")
13+
return true
14+
}
15+
16+
if (!Permissions.modtools.has(player)) {
17+
plugin.utils.sendPrefixedMessage(player, "You do not have permission")
18+
return true
19+
}
20+
21+
if (cmd.name == "spy") {
22+
if (!Permissions.spy.has(player)) {
23+
plugin.utils.sendPrefixedMessage(player, "You do not have permission")
24+
return true
25+
}
26+
27+
if (plugin.hasSpyEnabled(player)) {
28+
plugin.disableSpy(player)
29+
plugin.utils.sendPrefixedMessage(player, "Spy disabled")
30+
} else {
31+
plugin.enableSpy(player)
32+
plugin.utils.sendPrefixedMessage(player, "Spy enabled")
33+
}
34+
}
35+
36+
return true
37+
}
38+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package gg.obsidian.modtools
2+
3+
import java.util.*
4+
5+
class Configuration(val plugin: ModTools) {
6+
7+
var PREFIX = ""
8+
var SPY_FORMAT = ""
9+
var WATCHED_COMMANDS = ArrayList<String>()
10+
11+
fun load() {
12+
plugin.reloadConfig()
13+
14+
SPY_FORMAT = plugin.getConfig().getString("spy-format")
15+
PREFIX = plugin.getConfig().getString("prefix")
16+
WATCHED_COMMANDS = plugin.getConfig().getStringList("watched-commands") as ArrayList<String>
17+
}
18+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package gg.obsidian.modtools
2+
3+
import org.bukkit.Bukkit
4+
import org.bukkit.event.EventHandler
5+
import org.bukkit.event.Listener
6+
import org.bukkit.event.player.PlayerCommandPreprocessEvent
7+
import org.bukkit.event.player.PlayerJoinEvent
8+
9+
class EventListener(val plugin: ModTools): Listener {
10+
11+
@EventHandler
12+
fun onPlayerJoin(e: PlayerJoinEvent) {
13+
if (Permissions.spyAuto.has(e.player)) {
14+
plugin.enableSpy(e.player)
15+
}
16+
}
17+
18+
@EventHandler
19+
fun onCommandPreprocess(e: PlayerCommandPreprocessEvent) {
20+
plugin.logger.info("Got a command event")
21+
try {
22+
var message = e.message
23+
if (message.startsWith("/")) {
24+
message = message.substring(1)
25+
}
26+
message = message.replace("([ ]+)", "$1")
27+
28+
val args = message.split(" ")
29+
30+
plugin.logger.info("command was " + args)
31+
32+
if (!plugin.config.WATCHED_COMMANDS.contains(args[0].toLowerCase())) {
33+
return
34+
}
35+
36+
if (args[0].equals("r", ignoreCase = true) || args[0].equals("reply", ignoreCase = true)) {
37+
if (args.size <= 1) return
38+
39+
val from = e.player
40+
val to = Bukkit.getPlayer(MsgHistory.getTo(from))
41+
42+
MsgHistory.reportMessage(from, to)
43+
plugin.utils.sendSpyMessage(from, to, args.subList(1, args.size).joinToString(" "))
44+
} else if (args.size > 2) {
45+
val from = e.player
46+
val to = from.server.getPlayer(args[1])
47+
48+
MsgHistory.reportMessage(from, to)
49+
plugin.utils.sendSpyMessage(from, to, args.subList(2, args.size).joinToString(" "))
50+
}
51+
} catch (e: Exception) {
52+
plugin.logger.severe(e.message)
53+
// Ignore errors
54+
}
55+
}
56+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package gg.obsidian.modtools
2+
3+
import org.bukkit.entity.Player
4+
import org.bukkit.metadata.FixedMetadataValue
5+
import org.bukkit.plugin.java.JavaPlugin
6+
import java.io.File
7+
8+
val SPY_METADATA_KEY = "MODTOOLS_SPY_ENABLED"
9+
10+
class ModTools : JavaPlugin() {
11+
12+
val config = Configuration(this)
13+
val utils = Utils(this)
14+
15+
override fun onEnable() {
16+
val configFile = File(dataFolder, "config.yml")
17+
if (!configFile.exists()) {
18+
getConfig().options().copyDefaults(true)
19+
saveConfig()
20+
}
21+
22+
config.load()
23+
24+
server.pluginManager.registerEvents(EventListener(this), this)
25+
getCommand("spy").executor = CommandHandler(this)
26+
}
27+
28+
fun enableSpy(player: Player) {
29+
player.setMetadata(SPY_METADATA_KEY, FixedMetadataValue(this, true))
30+
}
31+
32+
fun disableSpy(player: Player) {
33+
player.setMetadata(SPY_METADATA_KEY, FixedMetadataValue(this, false))
34+
}
35+
36+
fun hasSpyEnabled(player: Player): Boolean {
37+
logger.info("checking spy for player " + player.name)
38+
if (!player.hasMetadata(SPY_METADATA_KEY)) {
39+
return false
40+
}
41+
42+
val meta = player.getMetadata(SPY_METADATA_KEY)
43+
if (meta.size == 0) {
44+
return false
45+
}
46+
47+
return meta[0].asBoolean()
48+
}
49+
}

0 commit comments

Comments
 (0)