-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extended chat/command functionality
- Loading branch information
Showing
17 changed files
with
906 additions
and
25 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
36 changes: 36 additions & 0 deletions
36
...entalsCore/src/main/java/com/johnymuffin/beta/fundamentals/commands/CommandBroadcast.java
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,36 @@ | ||
package com.johnymuffin.beta.fundamentals.commands; | ||
|
||
import com.johnymuffin.beta.fundamentals.Fundamentals; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
|
||
import static com.johnymuffin.beta.fundamentals.FundamentalPermission.isPlayerAuthorized; | ||
import static com.johnymuffin.beta.fundamentals.util.Utils.*; | ||
|
||
public class CommandBroadcast implements CommandExecutor { | ||
|
||
private Fundamentals plugin; | ||
|
||
public CommandBroadcast(Fundamentals plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
@Override | ||
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { | ||
if (!isPlayerAuthorized(commandSender, "fundamentals.broadcast")) { | ||
commandSender.sendMessage(plugin.getFundamentalsLanguageConfig().getMessage("no_permission")); | ||
return true; | ||
} | ||
if (strings.length == 0) { | ||
commandSender.sendMessage(plugin.getFundamentalsLanguageConfig().getMessage("broadcast_info")); | ||
return true; | ||
} | ||
String message = getFullArg(strings, 0); | ||
String broadcast = formatColor(plugin.getFundamentalConfig().getConfigString("settings.chat.broadcast-format") | ||
.replace("{message}", message)); | ||
Bukkit.broadcastMessage(broadcast); | ||
return true; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
FundamentalsCore/src/main/java/com/johnymuffin/beta/fundamentals/commands/CommandIgnore.java
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,58 @@ | ||
package com.johnymuffin.beta.fundamentals.commands; | ||
|
||
import com.johnymuffin.beta.fundamentals.Fundamentals; | ||
import com.johnymuffin.beta.fundamentals.player.FundamentalsPlayer; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.UUID; | ||
|
||
import static com.johnymuffin.beta.fundamentals.FundamentalPermission.isPlayerAuthorized; | ||
|
||
public class CommandIgnore implements CommandExecutor { | ||
|
||
private Fundamentals plugin; | ||
|
||
public CommandIgnore(Fundamentals plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
@Override | ||
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { | ||
if (!isPlayerAuthorized(commandSender,"fundamentals.ignore")) { | ||
commandSender.sendMessage(plugin.getFundamentalsLanguageConfig().getMessage("no_permission")); | ||
return true; | ||
} | ||
if (!(commandSender instanceof Player)) { | ||
commandSender.sendMessage(plugin.getFundamentalsLanguageConfig().getMessage("unavailable_to_console")); | ||
return true; | ||
} | ||
if (strings.length == 0) { | ||
commandSender.sendMessage(plugin.getFundamentalsLanguageConfig().getMessage("ignore_info")); | ||
return true; | ||
} | ||
UUID uuid = plugin.getPlayerCache().getUUIDFromUsername(strings[0]); | ||
if (uuid == null) { | ||
commandSender.sendMessage(plugin.getFundamentalsLanguageConfig().getMessage("player_not_found_full") | ||
.replace("%username%", strings[0])); | ||
return true; | ||
} | ||
if (uuid.equals(((Player) commandSender).getUniqueId())){ | ||
commandSender.sendMessage(plugin.getFundamentalsLanguageConfig().getMessage("ignore_self")); | ||
return true; | ||
} | ||
FundamentalsPlayer fPlayer = plugin.getPlayerMap().getPlayer((Player) commandSender); | ||
if (fPlayer.getIgnoreList().contains(uuid)) { | ||
fPlayer.removeUserIgnore(uuid); | ||
commandSender.sendMessage(plugin.getFundamentalsLanguageConfig().getMessage("ignore_remove") | ||
.replace("%player%", plugin.getPlayerCache().getUsernameFromUUID(uuid))); | ||
} else { | ||
fPlayer.addUserIgnore(uuid); | ||
commandSender.sendMessage(plugin.getFundamentalsLanguageConfig().getMessage("ignore_add") | ||
.replace("%player%", plugin.getPlayerCache().getUsernameFromUUID(uuid))); | ||
} | ||
return true; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
FundamentalsCore/src/main/java/com/johnymuffin/beta/fundamentals/commands/CommandList.java
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,70 @@ | ||
package com.johnymuffin.beta.fundamentals.commands; | ||
|
||
import com.johnymuffin.beta.fundamentals.Fundamentals; | ||
import com.johnymuffin.beta.fundamentals.player.FundamentalsPlayer; | ||
import com.johnymuffin.beta.fundamentals.util.Utils; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.*; | ||
|
||
import static com.johnymuffin.beta.fundamentals.FundamentalPermission.isPlayerAuthorized; | ||
|
||
public class CommandList implements CommandExecutor { | ||
|
||
private Fundamentals plugin; | ||
|
||
public CommandList(Fundamentals plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
@Override | ||
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { | ||
if (!isPlayerAuthorized(commandSender, "fundamentals.list")) { | ||
commandSender.sendMessage(plugin.getFundamentalsLanguageConfig().getMessage("no_permission")); | ||
return true; | ||
} | ||
boolean showHidden = isPlayerAuthorized(commandSender, "fundamentals.list.hidden"); | ||
commandSender.sendMessage(plugin.getFundamentalsLanguageConfig().getMessage("list_online") | ||
.replace("%online%", String.valueOf(Bukkit.getOnlinePlayers().length)) | ||
.replace("%maximum%", String.valueOf(Bukkit.getMaxPlayers()))); | ||
|
||
List<String> list = new ArrayList<>(); | ||
List<FundamentalsPlayer> players = new ArrayList<>(); | ||
if (plugin.getFundamentalConfig().getConfigBoolean("settings.list.sort-groups")) { | ||
Map<String, List<FundamentalsPlayer>> groups = new TreeMap<>(); | ||
for (Player p : Bukkit.getOnlinePlayers()) { | ||
FundamentalsPlayer fPlayer = plugin.getPlayerMap().getPlayer(p); | ||
String group = plugin.getPermissionsHook().getMainUserGroup(fPlayer.getUuid()); | ||
List<FundamentalsPlayer> groupList = groups.get(group); | ||
if (groupList == null) groupList = new ArrayList<>(); | ||
groupList.add(fPlayer); | ||
groups.put(group, groupList); | ||
} | ||
for (String group : groups.keySet()) { | ||
List<FundamentalsPlayer> groupList = groups.get(group); | ||
groupList.sort(Comparator.comparing(fPlayer -> fPlayer.getBukkitPlayer().getName())); | ||
players.addAll(groupList); | ||
} | ||
} else { | ||
for (Player p : Bukkit.getOnlinePlayers()) { | ||
players.add(plugin.getPlayerMap().getPlayer(p)); | ||
} | ||
players.sort(Comparator.comparing(fPlayer -> fPlayer.getBukkitPlayer().getName())); | ||
} | ||
for (FundamentalsPlayer fPlayer : players) { | ||
boolean isHidden = Utils.isEssentialsHidden(fPlayer.getBukkitPlayer()); | ||
if (isHidden && !showHidden) continue; | ||
StringBuilder sb = new StringBuilder(); | ||
if (fPlayer.isAFK()) sb.append("§7[AFK]§f"); | ||
if (isHidden) sb.append("§7[HIDDEN]§f"); | ||
sb.append(fPlayer.getFullDisplayName()); | ||
list.add(sb.toString()); | ||
} | ||
commandSender.sendMessage("Connected players: " + String.join("§f, ", list)); | ||
return true; | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
FundamentalsCore/src/main/java/com/johnymuffin/beta/fundamentals/commands/CommandMsg.java
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,81 @@ | ||
package com.johnymuffin.beta.fundamentals.commands; | ||
|
||
import com.johnymuffin.beta.fundamentals.Fundamentals; | ||
import com.johnymuffin.beta.fundamentals.player.FundamentalsPlayer; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.List; | ||
|
||
import static com.johnymuffin.beta.fundamentals.FundamentalPermission.isPlayerAuthorized; | ||
import static com.johnymuffin.beta.fundamentals.util.Utils.*; | ||
|
||
public class CommandMsg implements CommandExecutor { | ||
|
||
private Fundamentals plugin; | ||
|
||
public CommandMsg(Fundamentals plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
@Override | ||
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { | ||
if (!isPlayerAuthorized(commandSender, "fundamentals.msg")) { | ||
commandSender.sendMessage(plugin.getFundamentalsLanguageConfig().getMessage("no_permission")); | ||
return true; | ||
} | ||
if (!(commandSender instanceof Player)) { | ||
commandSender.sendMessage(plugin.getFundamentalsLanguageConfig().getMessage("unavailable_to_console")); | ||
return true; | ||
} | ||
if (strings.length < 2) { | ||
commandSender.sendMessage(plugin.getFundamentalsLanguageConfig().getMessage("msg_info")); | ||
return true; | ||
} | ||
|
||
List<Player> matches = Bukkit.matchPlayer(strings[0].trim()); | ||
FundamentalsPlayer fPlayer = plugin.getPlayerMap().getPlayer((Player) commandSender); | ||
|
||
if (fPlayer.isMuted()) { | ||
String mutedMessage = plugin.getFundamentalsLanguageConfig().getMessage("mute_player_chat") | ||
.replace("%duration%", fPlayer.getMuteStatus() == -1 ? "permanently" : "for" + formatDateDiff(fPlayer.getMuteStatus())); | ||
commandSender.sendMessage(mutedMessage); | ||
return true; | ||
} | ||
if (matches.isEmpty()) { | ||
commandSender.sendMessage(plugin.getFundamentalsLanguageConfig().getMessage("player_not_found_full") | ||
.replace("%username%", strings[0])); | ||
return true; | ||
} | ||
|
||
Player recipient = matches.get(0); | ||
if (fPlayer.getIgnoreList().contains(recipient.getUniqueId())) { | ||
commandSender.sendMessage(plugin.getFundamentalsLanguageConfig().getMessage("msg_player_ignored") | ||
.replace("%player%", recipient.getName())); | ||
return true; | ||
} | ||
String message = getFullArg(strings, 1); | ||
if (isPlayerAuthorized(commandSender, "fundamentals.chat.color")) { | ||
message = formatColor(message); | ||
} | ||
|
||
FundamentalsPlayer fRecipient = plugin.getPlayerMap().getPlayer(recipient); | ||
String send = formatColor(plugin.getFundamentalConfig().getConfigString("settings.chat.msg-send-format")) | ||
.replace("{displayname}", fRecipient.getFullDisplayName()) | ||
.replace("{message}", message); | ||
commandSender.sendMessage(send); | ||
fPlayer.setReplyTo(recipient); | ||
|
||
if (!fRecipient.getIgnoreList().contains(fPlayer.getUuid())) { | ||
String receive = formatColor(plugin.getFundamentalConfig().getConfigString("settings.chat.msg-receive-format")) | ||
.replace("{displayname}", fPlayer.getFullDisplayName()) | ||
.replace("{message}", message); | ||
recipient.sendMessage(receive); | ||
fRecipient.setReplyTo((Player) commandSender); | ||
} | ||
return true; | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
FundamentalsCore/src/main/java/com/johnymuffin/beta/fundamentals/commands/CommandMute.java
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,77 @@ | ||
package com.johnymuffin.beta.fundamentals.commands; | ||
|
||
import com.johnymuffin.beta.fundamentals.Fundamentals; | ||
import com.johnymuffin.beta.fundamentals.player.FundamentalsPlayer; | ||
import com.johnymuffin.beta.fundamentals.util.Utils; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.UUID; | ||
|
||
import static com.johnymuffin.beta.fundamentals.FundamentalPermission.isPlayerAuthorized; | ||
|
||
public class CommandMute implements CommandExecutor { | ||
|
||
private Fundamentals plugin; | ||
|
||
public CommandMute(Fundamentals plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
@Override | ||
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { | ||
if (!isPlayerAuthorized(commandSender,"fundamentals.mute")) { | ||
commandSender.sendMessage(plugin.getFundamentalsLanguageConfig().getMessage("no_permission")); | ||
return true; | ||
} | ||
if (strings.length == 0) { | ||
commandSender.sendMessage(plugin.getFundamentalsLanguageConfig().getMessage("mute_info")); | ||
return true; | ||
} | ||
UUID uuid = plugin.getPlayerCache().getUUIDFromUsername(strings[0]); | ||
if (uuid == null) { | ||
commandSender.sendMessage(plugin.getFundamentalsLanguageConfig().getMessage("player_not_found_full") | ||
.replace("%username%", strings[0])); | ||
return true; | ||
} | ||
if (commandSender instanceof Player && uuid.equals(((Player) commandSender).getUniqueId())){ | ||
commandSender.sendMessage(plugin.getFundamentalsLanguageConfig().getMessage("mute_self")); | ||
return true; | ||
} | ||
|
||
FundamentalsPlayer fPlayer = plugin.getPlayerMap().getPlayer(uuid); | ||
Player player = fPlayer.getBukkitPlayer(); | ||
|
||
if (strings.length == 1 && fPlayer.isMuted()){ | ||
fPlayer.setMuteTimer(null); | ||
|
||
commandSender.sendMessage(plugin.getFundamentalsLanguageConfig().getMessage("mute_unmute_successful") | ||
.replace("%player%", plugin.getPlayerCache().getUsernameFromUUID(fPlayer.getUuid()))); | ||
if (player != null) | ||
player.sendMessage(plugin.getFundamentalsLanguageConfig().getMessage("mute_player_unmuted")); | ||
|
||
return true; | ||
} | ||
|
||
String time = Utils.getFullArg(strings, 1); | ||
long unixTime = System.currentTimeMillis(); | ||
long duration; | ||
try { | ||
duration = Utils.parseDateDiff(time, true); | ||
} catch (Exception e){ | ||
duration = -1; | ||
} | ||
|
||
fPlayer.setMuteTimer(duration); | ||
String formattedTime = Utils.formatDateDiff(unixTime, duration); | ||
commandSender.sendMessage(plugin.getFundamentalsLanguageConfig().getMessage("mute_successful") | ||
.replace("%player%", plugin.getPlayerCache().getUsernameFromUUID(fPlayer.getUuid())) | ||
.replace("%duration%", duration == -1 ? "permanently" : "for" + formattedTime)); | ||
if (player != null) | ||
player.sendMessage(plugin.getFundamentalsLanguageConfig().getMessage("mute_player_muted") | ||
.replace("%duration%", duration == -1 ? "permanently" : "for" + formattedTime)); | ||
return true; | ||
} | ||
} |
Oops, something went wrong.