-
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
1 parent
9d5422e
commit 2d52fff
Showing
34 changed files
with
1,132 additions
and
922 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
48 changes: 48 additions & 0 deletions
48
src/main/java/io/github/brenoepics/commands/BlockMentionCommand.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,48 @@ | ||
package io.github.brenoepics.commands; | ||
|
||
import com.eu.habbo.Emulator; | ||
import com.eu.habbo.habbohotel.commands.Command; | ||
import com.eu.habbo.habbohotel.gameclients.GameClient; | ||
import com.eu.habbo.habbohotel.users.Habbo; | ||
|
||
/** | ||
* Class representing the `BlockMentionCommand` command. It is used to block or unblock mentions for | ||
* a user. | ||
* | ||
* @author BrenoEpic#9671 | ||
*/ | ||
public class BlockMentionCommand extends Command { | ||
|
||
/** | ||
* Constructor for the `BlockMentionCommand` command. It takes in the permission and command keys | ||
* needed to execute the command. | ||
* | ||
* @param permission the permission required to execute the command | ||
* @param keys the command keys used to execute the command | ||
*/ | ||
public BlockMentionCommand(final String permission, final String[] keys) { | ||
super(permission, keys); | ||
} | ||
|
||
/** | ||
* Handles the execution of the `BlockMentionCommand` command. | ||
* | ||
* @param gameClient the game client that sent the command | ||
* @param strings any additional parameters passed with the command | ||
* @return a boolean indicating if the command was successfully handled | ||
*/ | ||
public boolean handle(final GameClient gameClient, final String[] strings) { | ||
Habbo habbo = gameClient.getHabbo(); | ||
final boolean blockMention = (boolean) habbo.getHabboStats().cache.get("blockmention"); | ||
habbo.whisper(getMessage(blockMention)); | ||
habbo.getHabboStats().cache.put("blockmention", !blockMention); | ||
|
||
return true; | ||
} | ||
|
||
private static String getMessage(boolean blockMention) { | ||
return Emulator.getTexts() | ||
.getValue( | ||
!blockMention ? "commands.cmd_mention.success.on" : "commands.cmd_mention.success.off"); | ||
} | ||
} |
138 changes: 138 additions & 0 deletions
138
src/main/java/io/github/brenoepics/core/MentionManager.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,138 @@ | ||
package io.github.brenoepics.core; | ||
|
||
import static io.github.brenoepics.utils.Functions.buildPattern; | ||
|
||
import com.eu.habbo.Emulator; | ||
import com.eu.habbo.habbohotel.users.Habbo; | ||
import io.github.brenoepics.MentionExtractor; | ||
import io.github.brenoepics.core.modes.*; | ||
import io.github.brenoepics.core.types.HandleResult; | ||
import io.github.brenoepics.core.types.IMention; | ||
import io.github.brenoepics.core.types.exception.ExceptionHandler; | ||
import io.github.brenoepics.core.types.exception.MentionException; | ||
import io.github.brenoepics.logging.Message; | ||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
import lombok.Getter; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
/** | ||
* MentionManager class is responsible for handling all the mentions in the MentionPlugin. It holds | ||
* all the mention modes in a LinkedHashMap where the key is the mention mode name and the value is | ||
* an object of the IMention type. The class also holds a list of all the messages that are sent | ||
* using the mention plugin. | ||
*/ | ||
@Slf4j | ||
public class MentionManager { | ||
private final LinkedHashMap<String, IMention> mentionModes; | ||
private final MentionExtractor extract; | ||
@Getter private final List<Message> messages; | ||
|
||
/** | ||
* Constructor for MentionManager. | ||
* | ||
* @param messages List of all messages sent using the mention plugin. | ||
*/ | ||
public MentionManager(List<Message> messages) { | ||
this.messages = messages; | ||
this.mentionModes = new LinkedHashMap<>(); | ||
this.extract = buildPattern(); | ||
|
||
this.mentionModes.put("everyone", new MentionEveryone("acc_mention_everyone", "everyone")); | ||
this.mentionModes.put("here", new MentionHere("acc_mention_here", "here")); | ||
this.mentionModes.put("room", new MentionRoom("acc_mention_room", "room")); | ||
this.mentionModes.put("friends", new MentionFriends("acc_mention_friends", "friends")); | ||
this.mentionModes.put("user", new MentionUser("acc_mention", "user")); | ||
log.info("[MentionPlugin] successfully loaded with {} modes!", this.mentionModes.size()); | ||
} | ||
|
||
/** | ||
* Method to handle the mentions. | ||
* | ||
* @param sender The sender of the message. | ||
* @param message The message sent. | ||
* @return Returns a boolean indicating whether the message should be deleted or not. | ||
*/ | ||
public boolean handle(Habbo sender, String message) { | ||
Collection<IMention> iMentions = this.mentionModes.values(); | ||
Set<String> mentioned = extract.fromString(message); | ||
if (mentioned.isEmpty()) return false; | ||
|
||
ArrayList<IMention> mentions = getCollected(sender, iMentions); | ||
for (IMention mode : mentions) { | ||
HandleResult res = handleMentionList(sender, mentioned, message, mode); | ||
if (!res.getError().isEmpty()) { | ||
sender.whisper(res.getError()); | ||
} | ||
if (res.isHandle()) { | ||
return res.isDelete(); | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private static ArrayList<IMention> getCollected(Habbo sender, Collection<IMention> iMentions) { | ||
return iMentions.stream() | ||
.filter(mode -> sender.hasPermission(mode.getPermission(), mode.allowRoomOwner())) | ||
.collect(Collectors.toCollection(ArrayList::new)); | ||
} | ||
|
||
private HandleResult handleMentionList( | ||
Habbo sender, Set<String> mentioned, String message, IMention mode) { | ||
HandleResult result = new HandleResult(false, false); | ||
for (String mention : mentioned) { | ||
tryHandle(sender, message, mode, mention, result); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
private void tryHandle( | ||
Habbo sender, String message, IMention mode, String mention, HandleResult result) { | ||
try { | ||
HandleResult res = executeMention(sender, message, mode, mention); | ||
if (res.isHandle()) { | ||
result.setHandle(true); | ||
if (res.isDelete()) { | ||
result.setDelete(true); | ||
} | ||
} | ||
} catch (MentionException e) { | ||
if (Emulator.getConfig().getBoolean("commands.cmd_mention.message_error.delete")) { | ||
result.setDelete(true); | ||
} | ||
result.setError(ExceptionHandler.handle(e)); | ||
} | ||
} | ||
|
||
private HandleResult executeMention(Habbo sender, String message, IMention mode, String receiver) | ||
throws MentionException { | ||
boolean delete = false; | ||
boolean handle = false; | ||
if (mode.execute(sender, receiver, message)) { | ||
delete = handleSuccess(sender, mode, receiver, message); | ||
handle = true; | ||
} | ||
|
||
return new HandleResult(delete, handle); | ||
} | ||
|
||
|
||
private boolean handleSuccess(Habbo sender, IMention mode, String receiver, String message) { | ||
int timeout = Emulator.getConfig().getInt("mentionplugin.timeout_" + mode.getPrefix(), 20); | ||
mode.getTimer().ofUser(sender, timeout); | ||
this.addMessage(new Message(sender.getHabboInfo().getId(), receiver, message)); | ||
|
||
sender.whisper(Emulator.getTexts().getValue("commands.cmd_mention.message.sent")); | ||
|
||
return Emulator.getConfig().getBoolean("commands.cmd_mention.message_success.delete"); | ||
} | ||
|
||
public void disposeMessages() { | ||
this.messages.clear(); | ||
} | ||
|
||
public void addMessage(Message message) { | ||
messages.add(message); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...n/java/tech/brenoepic/core/Variables.java → .../io/github/brenoepics/core/Variables.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package tech.brenoepic.core; | ||
package io.github.brenoepics.core; | ||
|
||
import com.eu.habbo.Emulator; | ||
|
||
|
Oops, something went wrong.