-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ignore command, add unignore command, add ignorelist command (#2)
- Loading branch information
Showing
12 changed files
with
361 additions
and
7 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
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
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
49 changes: 49 additions & 0 deletions
49
src/main/java/eu/rex2go/chat2go/command/ignore/IgnoreCommand.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,49 @@ | ||
package eu.rex2go.chat2go.command.ignore; | ||
|
||
import eu.rex2go.chat2go.Chat2Go; | ||
import eu.rex2go.chat2go.ChatPermission; | ||
import eu.rex2go.chat2go.command.WrappedCommandExecutor; | ||
import eu.rex2go.chat2go.command.exception.CommandException; | ||
import eu.rex2go.chat2go.command.exception.PlayerNotFoundCommandException; | ||
import eu.rex2go.chat2go.user.User; | ||
import org.bukkit.command.CommandSender; | ||
|
||
public class IgnoreCommand extends WrappedCommandExecutor { | ||
|
||
public IgnoreCommand() { | ||
super("ignore"); | ||
} | ||
|
||
@Override | ||
protected void execute(CommandSender sender, User user, String label, String... args) throws CommandException { | ||
|
||
checkPermission(sender, ChatPermission.COMMAND_IGNORE.getPermission()); | ||
|
||
if (args.length < 1) { | ||
getTranslator().sendMessage(sender, "§7/ignore <{player}>"); | ||
return; | ||
} | ||
|
||
String targetName = args[0]; | ||
|
||
if(targetName.equalsIgnoreCase(sender.getName())) { | ||
user.sendMessage("command.ignore.ignore_yourself", false); | ||
return; | ||
} | ||
|
||
User target = Chat2Go.getUserManager().loadUser(null, targetName, false); | ||
|
||
if (target == null) { | ||
throw new PlayerNotFoundCommandException(targetName); | ||
} | ||
|
||
if (user.getIgnored().contains(target.getUuid())) { | ||
user.sendMessage("command.ignore.already_ignoring", false, target.getName()); | ||
} else { | ||
user.ignore(target); | ||
user.sendMessage("command.ignore.ignored", false, target.getName()); | ||
} | ||
|
||
Chat2Go.getUserManager().unloadOffline(user); | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
src/main/java/eu/rex2go/chat2go/command/ignorelist/IgnoreListCommand.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,128 @@ | ||
package eu.rex2go.chat2go.command.ignorelist; | ||
|
||
import eu.rex2go.chat2go.Chat2Go; | ||
import eu.rex2go.chat2go.ChatPermission; | ||
import eu.rex2go.chat2go.command.WrappedCommandExecutor; | ||
import eu.rex2go.chat2go.command.exception.CommandException; | ||
import eu.rex2go.chat2go.user.User; | ||
import eu.rex2go.chat2go.util.MathUtil; | ||
import net.md_5.bungee.api.chat.BaseComponent; | ||
import net.md_5.bungee.api.chat.ClickEvent; | ||
import net.md_5.bungee.api.chat.ComponentBuilder; | ||
import net.md_5.bungee.api.chat.HoverEvent; | ||
import net.md_5.bungee.api.chat.hover.content.Text; | ||
import org.bukkit.command.CommandSender; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public class IgnoreListCommand extends WrappedCommandExecutor { | ||
|
||
public IgnoreListCommand() { | ||
super("ignorelist"); | ||
} | ||
|
||
@Override | ||
protected void execute(CommandSender sender, User user, String label, String... args) throws CommandException { | ||
|
||
checkPermission(sender, ChatPermission.COMMAND_IGNORE.getPermission()); | ||
|
||
getTranslator().sendMessage(sender, "§7-§b-§7- §f{ignore_list} §7-§b-§7-"); | ||
|
||
List<String> ignoredList = new ArrayList<>(); | ||
|
||
for (UUID ignored : user.getIgnored()) { | ||
User ignoredUser = Chat2Go.getUserManager().loadUser(ignored, null, false); | ||
ignoredList.add(ignoredUser.getName()); | ||
} | ||
|
||
int entriesPerPage = 8; | ||
int entryCount = ignoredList.size(); | ||
int pages = entryCount / entriesPerPage + (entryCount % entriesPerPage == 0 ? 0 : 1); | ||
int page = 1; | ||
|
||
if (entryCount == 0) { | ||
user.sendMessage("command.ignorelist.no_ignored", false); | ||
return; | ||
} | ||
|
||
if (args.length > 2) { | ||
String pageStr = args[2]; | ||
|
||
if (MathUtil.isNumber(pageStr)) { | ||
page = Integer.parseInt(pageStr); | ||
|
||
if (page > pages) page = pages; | ||
if (page < 1) page = 1; | ||
} | ||
} | ||
|
||
int offset = entriesPerPage * (page - 1); | ||
|
||
for (int i = offset; i < offset + entriesPerPage; i++) { | ||
if (entryCount <= i) break; | ||
|
||
String ignore = ignoredList.get(i); | ||
String deleteTranslation = getTranslator().getTranslation("unignore"); | ||
String deleteHoverTranslation = getTranslator().getTranslation("command.ignorelist.unignore_hover", ignore); | ||
|
||
BaseComponent[] deleteComponents = new ComponentBuilder("§c[" + deleteTranslation + "]") | ||
.event(new HoverEvent( | ||
HoverEvent.Action.SHOW_TEXT, | ||
new Text(deleteHoverTranslation))) | ||
.event(new ClickEvent( | ||
ClickEvent.Action.RUN_COMMAND, | ||
"/unignore " + ignore)) | ||
.create(); | ||
|
||
BaseComponent[] components = new ComponentBuilder("§7- §f" + ignore + " ") | ||
.append(deleteComponents) | ||
.create(); | ||
|
||
sender.spigot().sendMessage(components); | ||
} | ||
|
||
if (pages > 1) { | ||
ComponentBuilder componentBuilder = new ComponentBuilder(); | ||
|
||
if (page != 1) { | ||
componentBuilder.append( | ||
new ComponentBuilder(" §f[<]") | ||
.event(new HoverEvent( | ||
HoverEvent.Action.SHOW_TEXT, | ||
new Text(getTranslator().getTranslation("previous_page")))) | ||
.event(new ClickEvent( | ||
ClickEvent.Action.RUN_COMMAND, | ||
"/ignorelist " + (page - 1))) | ||
.create() | ||
); | ||
} | ||
|
||
if (pages != page) { | ||
componentBuilder.append( | ||
new ComponentBuilder(" §f[>]") | ||
.event(new HoverEvent( | ||
HoverEvent.Action.SHOW_TEXT, | ||
new Text(getTranslator().getTranslation("next_page")))) | ||
.event(new ClickEvent( | ||
ClickEvent.Action.RUN_COMMAND, | ||
"/ignorelist " + (page + 1))) | ||
.create() | ||
); | ||
} | ||
|
||
String translation = getTranslator().getTranslation( | ||
"pagination", | ||
String.valueOf(page), | ||
String.valueOf(pages)); | ||
|
||
|
||
BaseComponent[] components = new ComponentBuilder(translation).append(componentBuilder.create()).create(); | ||
|
||
sender.spigot().sendMessage(components); | ||
} | ||
|
||
Chat2Go.getUserManager().unloadOffline(user); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/eu/rex2go/chat2go/command/unignore/UnignoreCommand.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,43 @@ | ||
package eu.rex2go.chat2go.command.unignore; | ||
|
||
import eu.rex2go.chat2go.Chat2Go; | ||
import eu.rex2go.chat2go.ChatPermission; | ||
import eu.rex2go.chat2go.command.WrappedCommandExecutor; | ||
import eu.rex2go.chat2go.command.exception.CommandException; | ||
import eu.rex2go.chat2go.command.exception.PlayerNotFoundCommandException; | ||
import eu.rex2go.chat2go.user.User; | ||
import org.bukkit.command.CommandSender; | ||
|
||
public class UnignoreCommand extends WrappedCommandExecutor { | ||
|
||
public UnignoreCommand() { | ||
super("unignore"); | ||
} | ||
|
||
@Override | ||
protected void execute(CommandSender sender, User user, String label, String... args) throws CommandException { | ||
|
||
checkPermission(sender, ChatPermission.COMMAND_IGNORE.getPermission()); | ||
|
||
if (args.length < 1) { | ||
getTranslator().sendMessage(sender, "§7/unignore <{player}>"); | ||
return; | ||
} | ||
|
||
String targetName = args[0]; | ||
User target = Chat2Go.getUserManager().loadUser(null, targetName, false); | ||
|
||
if (target == null) { | ||
throw new PlayerNotFoundCommandException(targetName); | ||
} | ||
|
||
if (!user.getIgnored().contains(target.getUuid())) { | ||
user.sendMessage("command.unignore.not_ignoring", false, target.getName()); | ||
} else { | ||
user.unignore(target); | ||
user.sendMessage("command.unignore.unignored", false, target.getName()); | ||
} | ||
|
||
Chat2Go.getUserManager().unloadOffline(user); | ||
} | ||
} |
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
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
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
Oops, something went wrong.