Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class CmdCommand extends Command {
public CmdCommand() {
super("cmd_commands", new String[] { "cmd", "command", "cmds", "commands" });
super("cmd_commands", new String[]{"cmd", "command", "cmds", "commands"});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.skeletor.plugin.javascript.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.rooms.Room;
Expand All @@ -9,26 +10,31 @@
import com.skeletor.plugin.javascript.utils.RegexUtility;

public class YoutubeCommand extends Command {
public YoutubeCommand(){
super("cmd_youtube", new String[] {"youtube"});
public YoutubeCommand() {
super("cmd_youtube", Emulator.getTexts().getValue("javascript.cmd.youtube.keys").split(";"));
}

@Override
public boolean handle(GameClient gameClient, String[] strings) throws Exception {
Room room = gameClient.getHabbo().getHabboInfo().getCurrentRoom();

if(room.hasRights(gameClient.getHabbo()) || gameClient.getHabbo().getHabboInfo().getRank().getName().equals("VIP")) {
if (strings.length > 1) {
String videoId = RegexUtility.getYouTubeId(strings[1]);
if(videoId.isEmpty()) {
gameClient.getHabbo().whisper("Invalid youtube url");
return true;
}
OutgoingWebMessage webMsg = new YoutubeTVComposer(videoId);
room.sendComposer(new JavascriptCallbackComposer(webMsg).compose());
return true;
}
if (room == null)
return false;

if (strings.length == 1) {
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("javascript.cmd.youtube.usage"));
return true;
}

String videoId = RegexUtility.getYouTubeId(strings[1]);

if (videoId.isEmpty()) {
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("javascript.cmd.youtube.invalid"));
return true;
}
gameClient.getHabbo().whisper("You do not have permission to use this command in this room");

OutgoingWebMessage webMsg = new YoutubeTVComposer(videoId);
room.sendComposer(new JavascriptCallbackComposer(webMsg).compose());
return true;
}
}
80 changes: 51 additions & 29 deletions src/main/java/com/skeletor/plugin/javascript/main.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,42 +34,55 @@ public class main extends HabboPlugin implements EventListener {
private static final Logger LOGGER = LoggerFactory.getLogger(main.class);
public static final int JSCALLBACKEVENTHEADER = 314;

public void onEnable () throws Exception {
public void onEnable() throws Exception {
Emulator.getPluginManager().registerEvents(this, this);
if(Emulator.isReady && !Emulator.isShuttingDown) {
if (Emulator.isReady && !Emulator.isShuttingDown) {
this.onEmulatorLoadedEvent(null);
}
}

@EventHandler
public void onEmulatorLoadedEvent ( EmulatorLoadedEvent e ) throws Exception {
//register incoming message
Emulator.getGameServer().getPacketManager().registerHandler(JSCALLBACKEVENTHEADER, JavascriptCallbackEvent.class);
public void onEmulatorLoadedEvent(EmulatorLoadedEvent e) throws Exception {
// register incoming message
Emulator.getGameServer().getPacketManager().registerHandler(JSCALLBACKEVENTHEADER,
JavascriptCallbackEvent.class);

Emulator.getTexts().register("javascript.cmd.youtube.keys", "roomvideo;youtube");
Emulator.getTexts().register("javascript.cmd.youtube.usage", "Usage: :roomvideo youtube.com/watch?v=videoId");
Emulator.getTexts().register("javascript.cmd.youtube.invalid", "Invalid youtube video url");
Emulator.getTexts().register("commands.description.cmd_youtube", ":youtube <VideoUrl>");

Emulator.getConfig().register("javascript.cmd.commands.enabled", "1");
// register commands

//register commands
CommandHandler.addCommand(new YoutubeCommand());
CommandHandler.addCommand(new CmdCommand());

if (Emulator.getConfig().getBoolean("javascript.cmd.commands.enabled", true)) {
CommandHandler.addCommand(new CmdCommand());
}

// initialize singleton
JSPlugin.init();

LOGGER.info("PLUGIN - Javascript-Plugin has started!");
}

@EventHandler
public void onLoadItemsManager(EmulatorLoadItemsManagerEvent e) {
Emulator.getGameEnvironment().getItemManager().addItemInteraction(new ItemInteraction("slots_machine", InteractionSlotMachine.class));
Emulator.getGameEnvironment().getItemManager().addItemInteraction(new ItemInteraction("yt_jukebox", InteractionYoutubeJukebox.class));
Emulator.getGameEnvironment().getItemManager()
.addItemInteraction(new ItemInteraction("slots_machine", InteractionSlotMachine.class));
Emulator.getGameEnvironment().getItemManager()
.addItemInteraction(new ItemInteraction("yt_jukebox", InteractionYoutubeJukebox.class));
}

@EventHandler
public void onUserEnterRoomEvent(UserEnterRoomEvent e) {
RoomPlaylist playlist = JSPlugin.getInstance().getRoomAudioManager().getPlaylistForRoom(e.room.getId());
// here send the playlist to the user
if(playlist.getPlaylist().size() > 0) {
if (playlist.getPlaylist().size() > 0) {
e.habbo.getClient().sendResponse(new JavascriptCallbackComposer(new PlaylistComposer(playlist)));
if(playlist.isPlaying()) {
e.habbo.getClient().sendResponse(new JavascriptCallbackComposer(new PlaySongComposer(playlist.getCurrentIndex())));
if (playlist.isPlaying()) {
e.habbo.getClient()
.sendResponse(new JavascriptCallbackComposer(new PlaySongComposer(playlist.getCurrentIndex())));
e.habbo.getClient().sendResponse(playlist.getNowPlayingBubbleAlert());
}
}
Expand All @@ -87,24 +100,33 @@ public void onRoomUncachedEvent(RoomUncachedEvent e) {
JSPlugin.getInstance().getRoomAudioManager().dispose(e.room.getId());
}

/* Trash
@EventHandler
public void onUserTalkEvent(UserTalkEvent e) {
String userMentioned = RegexUtility.getUserMentionedFromChat(e.chatMessage.getMessage());
if(!userMentioned.isEmpty()) {
Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userMentioned);

if (habbo != null) {
MentionComposer msg = new MentionComposer(e.habbo.getHabboInfo().getUsername(), e.chatMessage.getMessage());
habbo.getClient().sendResponse(new JavascriptCallbackComposer(msg));
e.habbo.whisper("You mentioned " + userMentioned, RoomChatMessageBubbles.ALERT);
}
}
}
*/
/*
* Trash
*
* @EventHandler
* public void onUserTalkEvent(UserTalkEvent e) {
* String userMentioned =
* RegexUtility.getUserMentionedFromChat(e.chatMessage.getMessage());
* if(!userMentioned.isEmpty()) {
* Habbo habbo =
* Emulator.getGameEnvironment().getHabboManager().getHabbo(userMentioned);
*
* if (habbo != null) {
* MentionComposer msg = new
* MentionComposer(e.habbo.getHabboInfo().getUsername(),
* e.chatMessage.getMessage());
* habbo.getClient().sendResponse(new JavascriptCallbackComposer(msg));
* e.habbo.whisper("You mentioned " + userMentioned,
* RoomChatMessageBubbles.ALERT);
* }
* }
* }
*/
@EventHandler
public void onUserLoginEvent(UserLoginEvent e) {
SessionDataComposer sessionDataComposer = new SessionDataComposer(e.habbo.getHabboInfo().getId(), e.habbo.getHabboInfo().getUsername(), e.habbo.getHabboInfo().getLook(), e.habbo.getHabboInfo().getCredits());
SessionDataComposer sessionDataComposer = new SessionDataComposer(e.habbo.getHabboInfo().getId(),
e.habbo.getHabboInfo().getUsername(), e.habbo.getHabboInfo().getLook(),
e.habbo.getHabboInfo().getCredits());
e.habbo.getClient().sendResponse(new JavascriptCallbackComposer(sessionDataComposer));
}

Expand Down