Arcturus-Community/src/main/java/com/eu/habbo/habbohotel/bots/VisitorBot.java

71 lines
2.6 KiB
Java
Raw Normal View History

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;
2019-05-26 20:14:53 +02:00
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
2019-05-26 20:14:53 +02:00
public VisitorBot(ResultSet set) throws SQLException {
2018-07-06 15:30:00 +02:00
super(set);
}
2019-05-26 20:14:53 +02:00
public VisitorBot(Bot bot) {
2018-07-06 15:30:00 +02:00
super(bot);
}
2019-05-26 20:14:53 +02:00
public static void initialise() {
DATE_FORMAT = new SimpleDateFormat(Emulator.getConfig().getValue("bots.visitor.dateformat"));
}
2018-07-06 15:30:00 +02:00
@Override
2019-05-26 20:14:53 +02:00
public void onUserSay(final RoomChatMessage message) {
if (!this.showedLog) {
if (message.getMessage().equalsIgnoreCase(Emulator.getTexts().getValue("generic.yes"))) {
2018-07-06 15:30:00 +02:00
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();
2019-05-26 20:14:53 +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();
}
}
}
2019-05-26 20:14:53 +02:00
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(), habbo.getHabboInfo().getCurrentRoom().getOwnerName());
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
if (this.visits.isEmpty()) {
2018-07-06 15:30:00 +02:00
this.talk(Emulator.getTexts().getValue("bots.visitor.no_visits"));
2019-05-26 20:14:53 +02:00
} else {
2018-07-06 15:30:00 +02:00
this.talk(Emulator.getTexts().getValue("bots.visitor.visits").replace("%count%", this.visits.size() + "").replace("%positive%", Emulator.getTexts().getValue("generic.yes")));
}
}
}
}
}