Skip to content

Commit

Permalink
Block chat with permission
Browse files Browse the repository at this point in the history
  • Loading branch information
EpiCanard committed Nov 12, 2020
1 parent d5d6074 commit d01950e
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.classpath
.factorypath
.project
.settings
target/
8 changes: 8 additions & 0 deletions README.md
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
60 changes: 60 additions & 0 deletions pom.xml
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>
35 changes: 35 additions & 0 deletions src/main/java/fr/freebuild/shutup/Logger.java
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);
}
}
}

62 changes: 62 additions & 0 deletions src/main/java/fr/freebuild/shutup/ShutUp.java
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"));
}
}
}
3 changes: 3 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
debug: false
message: 'You are not allowed to talk !'

10 changes: 10 additions & 0 deletions src/main/resources/plugin.yml
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

0 comments on commit d01950e

Please sign in to comment.