Added prefix command

This commit is contained in:
Ghoti 2020-02-07 11:48:16 -06:00
parent c35d359d44
commit 3e4811ca65
6 changed files with 98 additions and 5 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>FPChatX</groupId> <groupId>FPChatX</groupId>
<artifactId>FPChatX</artifactId> <artifactId>FPChatX</artifactId>
<version>1.0.1-BETA</version> <version>1.0.3-BETA</version>
<build> <build>
<sourceDirectory>src/main/java</sourceDirectory> <sourceDirectory>src/main/java</sourceDirectory>
<resources> <resources>

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>FPChatX</groupId> <groupId>FPChatX</groupId>
<artifactId>FPChatX</artifactId> <artifactId>FPChatX</artifactId>
<version>1.0.3-BETA</version> <version>1.0.4-BETA</version>
<repositories> <repositories>
<repository> <repository>
<id>spigot-repo</id> <id>spigot-repo</id>

View File

@ -35,6 +35,7 @@ import com.fpghoti.fpchatx.command.commands.LeaveCommand;
import com.fpghoti.fpchatx.command.commands.ChannelsCommand; import com.fpghoti.fpchatx.command.commands.ChannelsCommand;
import com.fpghoti.fpchatx.command.commands.CreateCommand; import com.fpghoti.fpchatx.command.commands.CreateCommand;
import com.fpghoti.fpchatx.command.commands.MessageCommand; import com.fpghoti.fpchatx.command.commands.MessageCommand;
import com.fpghoti.fpchatx.command.commands.PrefixCommand;
import com.fpghoti.fpchatx.command.commands.ReloadCommand; import com.fpghoti.fpchatx.command.commands.ReloadCommand;
import com.fpghoti.fpchatx.command.commands.ReplyCommand; import com.fpghoti.fpchatx.command.commands.ReplyCommand;
import com.fpghoti.fpchatx.command.commands.RevokeBadgeCommand; import com.fpghoti.fpchatx.command.commands.RevokeBadgeCommand;
@ -175,7 +176,7 @@ public class FPChat extends JavaPlugin {
Commands.register(new HelpCommand(this)); Commands.register(new HelpCommand(this));
Commands.register(new RevokeBadgeCommand(this)); Commands.register(new RevokeBadgeCommand(this));
Commands.register(new GiveBadgeCommand(this)); Commands.register(new GiveBadgeCommand(this));
Commands.register(new PrefixCommand(this));
} }
public MainConfig getMainConfig() { public MainConfig getMainConfig() {

View File

@ -0,0 +1,52 @@
package com.fpghoti.fpchatx.command.commands;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.fpghoti.fpchatx.FPChat;
import com.fpghoti.fpchatx.chat.ChatFilter;
import com.fpghoti.fpchatx.command.Commands;
import com.fpghoti.fpchatx.permission.Permission;
import com.fpghoti.fpchatx.player.FPlayer;
public class PrefixCommand extends Commands {
public PrefixCommand(FPChat plugin) {
super(plugin);
name = "Prefix";
description = "Sets your own prefix";
syntax = ChatColor.GRAY + "/fpc prefix " + ChatColor.GOLD + "<prefix>";
minArgs = 1;
maxArgs = 1;
labels.add("fpc prefix");
labels.add("fpchat prefix");
labels.add("ch prefix");
}
@Override
public void execute(CommandSender sender, String[] args) {
FPlayer p = null;
Boolean console = true;
if(sender instanceof Player){
console = false;
p = FPlayer.getPlayer((Player) sender);
}
if(console) {
FPlayer.errMsg(p, "This command cannot be used by console.");
return;
}
if(Permission.canChangePrefix(p)){
String prefix = ChatColor.translateAlternateColorCodes('&', ChatFilter.filterWord(args[0]));
if(Permission.canChangePrefix(p)) {
p.setPrefix(prefix);
FPlayer.goodMsg(p, "Set prefix to: " + prefix);
}else {
FPlayer.errMsg(p, Permission.noPerm);
}
}
}
}

View File

@ -18,6 +18,30 @@ public class Permission {
return false; return false;
} }
public static boolean canChangePrefix(FPlayer p) {
return p.hasPermission("fpchat.changeprefix");
}
public static boolean canChangePrefix(String playername) {
if(FPlayer.getPlayer(playername) != null) {
FPlayer p = FPlayer.getPlayer(playername);
return canChangePrefix(p);
}
return false;
}
public static boolean canChangeSuffix(FPlayer p) {
return p.hasPermission("fpchat.changesuffix");
}
public static boolean canChangeSuffix(String playername) {
if(FPlayer.getPlayer(playername) != null) {
FPlayer p = FPlayer.getPlayer(playername);
return canChangeSuffix(p);
}
return false;
}
public static boolean canShoutColor(FPlayer p) { public static boolean canShoutColor(FPlayer p) {
return p.hasPermission("fpchat.shoutcolor"); return p.hasPermission("fpchat.shoutcolor");
} }

View File

@ -273,6 +273,22 @@ public class FPlayer {
this.shoutVisible = false; this.shoutVisible = false;
} }
public boolean setPrefix(String prefix) {
if(isOnline() && getPlayer() != null) {
VaultUtil.chat.setPlayerPrefix(getPlayer(), prefix);
return true;
}
return false;
}
public boolean setSuffix(String suffix) {
if(isOnline() && getPlayer() != null) {
VaultUtil.chat.setPlayerPrefix(getPlayer(), suffix);
return true;
}
return false;
}
public boolean isHushed() { public boolean isHushed() {
return this.hushed; return this.hushed;
} }