-
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
7 changed files
with
183 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
target/ |
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 |
---|---|---|
@@ -1,2 +1,10 @@ | ||
# ShutUp | ||
Plugin to prevent player to speak in chat | ||
|
||
## Commands | ||
|
||
- /shutup reload - Used to reload plugin configuration | ||
|
||
## Permissions | ||
|
||
- shutup - Can't talk in chat if set |
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,60 @@ | ||
<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>fr.freebuild</groupId> | ||
<artifactId>shutup</artifactId> | ||
<version>0.3</version> | ||
<name>ShutUp</name> | ||
<description>Plugin to prevent player to speak in chat</description> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<spigot.version>1.16.4-R0.1-SNAPSHOT</spigot.version> | ||
</properties> | ||
|
||
<build> | ||
<finalName>${project.name}-${project.version}</finalName> | ||
<resources> | ||
<resource> | ||
<targetPath>.</targetPath> | ||
<filtering>true</filtering> | ||
<directory>${basedir}/src/main/resources</directory> | ||
</resource> | ||
</resources> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.1.2</version> | ||
<configuration> | ||
<archive> | ||
<index>true</index> | ||
<manifestEntries> | ||
<Built-By>EpiCanard</Built-By> | ||
<Project-Version>${project.version}</Project-Version> | ||
</manifestEntries> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<repositories> | ||
<repository> | ||
<id>spigot-repo</id> | ||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<!--Spigot API --> | ||
<dependency> | ||
<groupId>org.spigotmc</groupId> | ||
<artifactId>spigot-api</artifactId> | ||
<version>${spigot.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
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,35 @@ | ||
package fr.freebuild.shutup; | ||
|
||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.command.ConsoleCommandSender; | ||
|
||
public class Logger { | ||
private ShutUp plugin; | ||
private boolean debug = false; | ||
|
||
public Logger(final ShutUp plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
public void setDebug(final boolean debug) { | ||
this.debug = debug; | ||
} | ||
|
||
public void info(final String message) { | ||
this.plugin.getLogger().info(message); | ||
} | ||
|
||
public void info(final String message, final CommandSender sender) { | ||
this.info(message); | ||
if (!(sender instanceof ConsoleCommandSender)) { | ||
sender.sendMessage("[ShutUp] " + message); | ||
} | ||
} | ||
|
||
public void debug(final String message) { | ||
if (this.debug) { | ||
info(message); | ||
} | ||
} | ||
} | ||
|
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,62 @@ | ||
package fr.freebuild.shutup; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.AsyncPlayerChatEvent; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
public class ShutUp extends JavaPlugin implements Listener { | ||
public Logger logger; | ||
|
||
public void onEnable() { | ||
this.logger = new Logger(this); | ||
this.saveDefaultConfig(); | ||
this.logger.setDebug(getConfig().getBoolean("debug", false)); | ||
|
||
getCommand("shutup").setExecutor(this); | ||
|
||
Bukkit.getServer().getPluginManager().registerEvents(this, this); | ||
} | ||
|
||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { | ||
this.logger.debug("Execute command /shutup reload"); | ||
|
||
if (sender.isOp()) { | ||
this.logger.debug("Player is op"); | ||
|
||
if (args.length > 0 && args[0].equals("reload")){ | ||
this.logger.info("Reloading the config...", sender); | ||
this.reloadConfig(); | ||
this.logger.setDebug(getConfig().getBoolean("debug", false)); | ||
this.logger.info("Config reloaded !", sender); | ||
return true; | ||
} else { | ||
this.logger.debug("Not enough arguments"); | ||
sender.sendMessage("Usage: /shutup reload"); | ||
} | ||
} else { | ||
this.logger.debug("Player is NOT op"); | ||
sender.sendMessage("You don't have permission to do that !"); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@EventHandler(priority=EventPriority.HIGHEST) | ||
public void onPlayerSendChatMessage(final AsyncPlayerChatEvent apce) { | ||
this.logger.debug("Player trying to send message in chat"); | ||
final Player player = apce.getPlayer(); | ||
|
||
if (player != null && player.hasPermission("shutup") && !player.isOp()) { | ||
this.logger.debug("The player is not allowed to send message in chat"); | ||
apce.setCancelled(true); | ||
player.sendMessage(ChatColor.RED + this.getConfig().getString("message", "Not allowed")); | ||
} | ||
} | ||
} |
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,3 @@ | ||
debug: false | ||
message: 'You are not allowed to talk !' | ||
|
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,10 @@ | ||
name: ShutUp | ||
main: fr.freebuild.shutup.ShutUp | ||
version: ${project.version} | ||
authors: [zedentox, Epicanard] | ||
commands: | ||
shutup: | ||
description: Used to reload plugin configuration | ||
permissions: | ||
shutup: | ||
description: Can't talk in chat if set |