2018-07-06 15:30:00 +02:00
|
|
|
package com.eu.habbo.habbohotel.bots;
|
|
|
|
|
|
|
|
import com.eu.habbo.Emulator;
|
|
|
|
import com.eu.habbo.habbohotel.modtool.ModToolRoomVisit;
|
|
|
|
import com.eu.habbo.habbohotel.rooms.RoomChatMessage;
|
|
|
|
import com.eu.habbo.habbohotel.users.Habbo;
|
|
|
|
import gnu.trove.set.hash.THashSet;
|
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
public class VisitorBot extends Bot
|
|
|
|
{
|
2019-03-18 02:22:00 +01:00
|
|
|
private static SimpleDateFormat DATE_FORMAT;
|
2018-07-06 15:30:00 +02:00
|
|
|
private boolean showedLog = false;
|
2019-03-18 02:22:00 +01:00
|
|
|
private THashSet<ModToolRoomVisit> visits = new THashSet<>(3);
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
public VisitorBot(ResultSet set) throws SQLException
|
|
|
|
{
|
|
|
|
super(set);
|
|
|
|
}
|
|
|
|
|
|
|
|
public VisitorBot(Bot bot)
|
|
|
|
{
|
|
|
|
super(bot);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUserSay(final RoomChatMessage message)
|
|
|
|
{
|
|
|
|
if(!this.showedLog)
|
|
|
|
{
|
|
|
|
if(message.getMessage().equalsIgnoreCase(Emulator.getTexts().getValue("generic.yes")))
|
|
|
|
{
|
|
|
|
this.showedLog = true;
|
|
|
|
|
|
|
|
String visitMessage = Emulator.getTexts().getValue("bots.visitor.list").replace("%count%", this.visits.size() + "");
|
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
StringBuilder list = new StringBuilder();
|
2018-07-06 15:30:00 +02:00
|
|
|
for(ModToolRoomVisit visit : this.visits)
|
|
|
|
{
|
2019-03-18 02:22:00 +01:00
|
|
|
list.append("\r");
|
|
|
|
list.append(visit.roomName).append(" ");
|
|
|
|
list.append(Emulator.getTexts().getValue("generic.time.at")).append(" ");
|
|
|
|
list.append(DATE_FORMAT.format(new Date((visit.timestamp * 1000L))));
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
visitMessage = visitMessage.replace("%list%", list.toString());
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
this.talk(visitMessage);
|
|
|
|
|
|
|
|
this.visits.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onUserEnter(Habbo habbo)
|
|
|
|
{
|
|
|
|
if(!this.showedLog)
|
|
|
|
{
|
|
|
|
if(habbo.getHabboInfo().getCurrentRoom() != null)
|
|
|
|
{
|
|
|
|
this.visits = Emulator.getGameEnvironment().getModToolManager().getVisitsForRoom(habbo.getHabboInfo().getCurrentRoom(), 10, true, habbo.getHabboInfo().getLastOnline(), Emulator.getIntUnixTimestamp());
|
|
|
|
|
|
|
|
if(this.visits.isEmpty())
|
|
|
|
{
|
|
|
|
this.talk(Emulator.getTexts().getValue("bots.visitor.no_visits"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.talk(Emulator.getTexts().getValue("bots.visitor.visits").replace("%count%", this.visits.size() + "").replace("%positive%", Emulator.getTexts().getValue("generic.yes")));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void initialise()
|
|
|
|
{
|
2019-03-18 02:22:00 +01:00
|
|
|
DATE_FORMAT = new SimpleDateFormat(Emulator.getConfig().getValue("bots.visitor.dateformat"));
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|