2018-07-06 13:30:00 +00:00
|
|
|
package com.eu.habbo.habbohotel.guides;
|
|
|
|
|
|
|
|
import com.eu.habbo.Emulator;
|
|
|
|
import com.eu.habbo.habbohotel.achievements.AchievementManager;
|
|
|
|
import com.eu.habbo.habbohotel.modtool.ModToolChatLog;
|
|
|
|
import com.eu.habbo.habbohotel.modtool.ModToolIssue;
|
|
|
|
import com.eu.habbo.habbohotel.modtool.ModToolTicketType;
|
|
|
|
import com.eu.habbo.habbohotel.users.Habbo;
|
|
|
|
import com.eu.habbo.messages.outgoing.guardians.*;
|
|
|
|
import com.eu.habbo.messages.outgoing.guides.BullyReportClosedComposer;
|
|
|
|
import com.eu.habbo.threading.runnables.GuardianNotAccepted;
|
|
|
|
import com.eu.habbo.threading.runnables.GuardianVotingFinish;
|
|
|
|
import gnu.trove.map.hash.THashMap;
|
|
|
|
|
2018-09-28 19:25:00 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Map;
|
2018-07-06 13:30:00 +00:00
|
|
|
|
|
|
|
public class GuardianTicket
|
|
|
|
{
|
|
|
|
private ArrayList<ModToolChatLog> chatLogs;
|
2018-09-28 19:25:00 +00:00
|
|
|
private final THashMap<Habbo, GuardianVote> votes = new THashMap<>();
|
2018-07-06 13:30:00 +00:00
|
|
|
private GuardianVoteType verdict;
|
|
|
|
private int timeLeft = 120;
|
|
|
|
private int resendCount = 0;
|
|
|
|
private int checkSum = 0;
|
|
|
|
private final Habbo reporter;
|
|
|
|
private final Habbo reported;
|
|
|
|
private final Date date;
|
|
|
|
|
|
|
|
private int guardianCount = 0;
|
|
|
|
|
|
|
|
public GuardianTicket(Habbo reporter, Habbo reported, ArrayList<ModToolChatLog> chatLogs)
|
|
|
|
{
|
|
|
|
this.chatLogs = chatLogs;
|
|
|
|
Collections.sort(chatLogs);
|
|
|
|
Emulator.getThreading().run(new GuardianVotingFinish(this), 120000);
|
|
|
|
|
|
|
|
this.reported = reported;
|
|
|
|
this.reporter = reporter;
|
|
|
|
this.date = new Date();
|
|
|
|
}
|
|
|
|
|
2018-07-08 21:32:00 +00:00
|
|
|
|
2018-07-06 13:30:00 +00:00
|
|
|
public void requestToVote(Habbo guardian)
|
|
|
|
{
|
|
|
|
guardian.getClient().sendResponse(new GuardianNewReportReceivedComposer(this));
|
|
|
|
|
|
|
|
this.votes.put(guardian, new GuardianVote(guardianCount, guardian));
|
|
|
|
|
|
|
|
Emulator.getThreading().run(new GuardianNotAccepted(this, guardian), Emulator.getConfig().getInt("guardians.accept.timer") * 1000);
|
|
|
|
}
|
|
|
|
|
2018-07-08 21:32:00 +00:00
|
|
|
|
2018-07-06 13:30:00 +00:00
|
|
|
public void addGuardian(Habbo guardian)
|
|
|
|
{
|
|
|
|
GuardianVote vote = this.votes.get(guardian);
|
|
|
|
|
|
|
|
if(vote != null && vote.type == GuardianVoteType.SEARCHING)
|
|
|
|
{
|
|
|
|
guardian.getClient().sendResponse(new GuardianVotingRequestedComposer(this));
|
|
|
|
vote.type = GuardianVoteType.WAITING;
|
|
|
|
this.updateVotes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-08 21:32:00 +00:00
|
|
|
|
2018-07-06 13:30:00 +00:00
|
|
|
public void removeGuardian(Habbo guardian)
|
|
|
|
{
|
|
|
|
GuardianVote vote = this.getVoteForGuardian(guardian);
|
|
|
|
|
|
|
|
if(vote == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(vote.type == GuardianVoteType.SEARCHING || vote.type == GuardianVoteType.WAITING)
|
|
|
|
{
|
|
|
|
this.getVoteForGuardian(guardian).type = GuardianVoteType.NOT_VOTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.getVoteForGuardian(guardian).ignore = true;
|
|
|
|
|
|
|
|
guardian.getClient().sendResponse(new GuardianVotingTimeEnded());
|
|
|
|
|
|
|
|
this.updateVotes();
|
|
|
|
}
|
|
|
|
|
2018-07-08 21:32:00 +00:00
|
|
|
|
2018-07-06 13:30:00 +00:00
|
|
|
public void vote(Habbo guardian, GuardianVoteType vote)
|
|
|
|
{
|
|
|
|
this.votes.get(guardian).type = vote;
|
|
|
|
|
|
|
|
this.updateVotes();
|
|
|
|
|
|
|
|
AchievementManager.progressAchievement(guardian, Emulator.getGameEnvironment().getAchievementManager().getAchievement("GuideChatReviewer"));
|
|
|
|
|
|
|
|
this.finish();
|
|
|
|
}
|
|
|
|
|
2018-07-08 21:32:00 +00:00
|
|
|
|
2018-07-06 13:30:00 +00:00
|
|
|
public void updateVotes()
|
|
|
|
{
|
|
|
|
synchronized (this.votes)
|
|
|
|
{
|
|
|
|
for(Map.Entry<Habbo, GuardianVote> set : this.votes.entrySet())
|
|
|
|
{
|
|
|
|
if(set.getValue().type == GuardianVoteType.WAITING || set.getValue().type == GuardianVoteType.NOT_VOTED || set.getValue().ignore || set.getValue().type == GuardianVoteType.SEARCHING)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
set.getKey().getClient().sendResponse(new GuardianVotingVotesComposer(this, set.getKey()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-08 21:32:00 +00:00
|
|
|
|
2018-07-06 13:30:00 +00:00
|
|
|
public void finish()
|
|
|
|
{
|
|
|
|
int votedCount = this.getVotedCount();
|
|
|
|
if(votedCount < Emulator.getConfig().getInt("guardians.minimum.votes"))
|
|
|
|
{
|
|
|
|
if(this.votes.size() >= Emulator.getConfig().getInt("guardians.maximum.guardians.total") || this.resendCount == Emulator.getConfig().getInt("guardians.maximum.resends"))
|
|
|
|
{
|
|
|
|
this.verdict = GuardianVoteType.FORWARDED;
|
|
|
|
|
|
|
|
Emulator.getGameEnvironment().getGuideManager().closeTicket(this);
|
|
|
|
|
|
|
|
ModToolIssue issue = new ModToolIssue(this.reporter.getHabboInfo().getId(),
|
|
|
|
this.reporter.getHabboInfo().getUsername(),
|
|
|
|
this.reported.getHabboInfo().getId(),
|
|
|
|
this.reported.getHabboInfo().getUsername(),
|
|
|
|
0,
|
|
|
|
"",
|
|
|
|
ModToolTicketType.GUARDIAN);
|
|
|
|
|
|
|
|
Emulator.getGameEnvironment().getModToolManager().addTicket(issue);
|
|
|
|
Emulator.getGameEnvironment().getModToolManager().updateTicketToMods(issue);
|
|
|
|
|
|
|
|
this.reporter.getClient().sendResponse(new BullyReportClosedComposer(BullyReportClosedComposer.CLOSED));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.timeLeft = 30;
|
|
|
|
Emulator.getThreading().run(new GuardianVotingFinish(this), 10000);
|
|
|
|
this.resendCount++;
|
|
|
|
|
|
|
|
Emulator.getGameEnvironment().getGuideManager().findGuardians(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.verdict = calculateVerdict();
|
|
|
|
|
|
|
|
for(Map.Entry<Habbo, GuardianVote> set : this.votes.entrySet())
|
|
|
|
{
|
|
|
|
if(set.getValue().type == GuardianVoteType.ACCEPTABLY ||
|
|
|
|
set.getValue().type == GuardianVoteType.BADLY ||
|
|
|
|
set.getValue().type == GuardianVoteType.AWFULLY)
|
|
|
|
{
|
|
|
|
set.getKey().getClient().sendResponse(new GuardianVotingResultComposer(this, set.getValue()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Emulator.getGameEnvironment().getGuideManager().closeTicket(this);
|
|
|
|
|
|
|
|
if(this.verdict == GuardianVoteType.ACCEPTABLY)
|
|
|
|
this.reporter.getClient().sendResponse(new BullyReportClosedComposer(BullyReportClosedComposer.MISUSE));
|
|
|
|
else
|
|
|
|
this.reporter.getClient().sendResponse(new BullyReportClosedComposer(BullyReportClosedComposer.CLOSED));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-08 21:32:00 +00:00
|
|
|
|
2018-07-06 13:30:00 +00:00
|
|
|
public boolean isFinished()
|
|
|
|
{
|
|
|
|
return !(this.verdict == null);
|
|
|
|
}
|
|
|
|
|
2018-07-08 21:32:00 +00:00
|
|
|
|
2018-07-06 13:30:00 +00:00
|
|
|
public GuardianVoteType calculateVerdict()
|
|
|
|
{
|
|
|
|
int countAcceptably = 0;
|
|
|
|
int countBadly = 0;
|
|
|
|
int countAwfully = 0;
|
|
|
|
int total = 0;
|
|
|
|
|
|
|
|
synchronized (this.votes)
|
|
|
|
{
|
|
|
|
for(Map.Entry<Habbo, GuardianVote> set : this.votes.entrySet())
|
|
|
|
{
|
|
|
|
GuardianVote vote = set.getValue();
|
|
|
|
|
|
|
|
if(vote.type == GuardianVoteType.ACCEPTABLY)
|
|
|
|
{
|
|
|
|
countAcceptably++;
|
|
|
|
}
|
|
|
|
else if(vote.type == GuardianVoteType.BADLY)
|
|
|
|
{
|
|
|
|
countBadly++;
|
|
|
|
}
|
|
|
|
else if(vote.type == GuardianVoteType.AWFULLY)
|
|
|
|
{
|
|
|
|
countAwfully++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
total += countAcceptably;
|
|
|
|
total += countBadly;
|
|
|
|
total += countAwfully;
|
|
|
|
|
2018-09-28 19:25:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-07-06 13:30:00 +00:00
|
|
|
|
|
|
|
return GuardianVoteType.BADLY;
|
|
|
|
}
|
|
|
|
|
|
|
|
public GuardianVote getVoteForGuardian(Habbo guardian)
|
|
|
|
{
|
|
|
|
return this.votes.get(guardian);
|
|
|
|
}
|
|
|
|
|
|
|
|
public THashMap<Habbo, GuardianVote> getVotes()
|
|
|
|
{
|
|
|
|
return this.votes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getTimeLeft()
|
|
|
|
{
|
|
|
|
return this.timeLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
public GuardianVoteType getVerdict()
|
|
|
|
{
|
|
|
|
return this.verdict;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ArrayList<ModToolChatLog> getChatLogs()
|
|
|
|
{
|
|
|
|
return this.chatLogs;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getResendCount()
|
|
|
|
{
|
|
|
|
return this.resendCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getCheckSum()
|
|
|
|
{
|
|
|
|
return this.checkSum;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Habbo getReporter()
|
|
|
|
{
|
|
|
|
return this.reporter;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Habbo getReported()
|
|
|
|
{
|
|
|
|
return this.reported;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Date getDate()
|
|
|
|
{
|
|
|
|
return this.date;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getGuardianCount()
|
|
|
|
{
|
|
|
|
return this.guardianCount;
|
|
|
|
}
|
|
|
|
|
2018-07-08 21:32:00 +00:00
|
|
|
|
2018-07-06 13:30:00 +00:00
|
|
|
public ArrayList<GuardianVote> getSortedVotes(Habbo guardian)
|
|
|
|
{
|
|
|
|
synchronized (this.votes)
|
|
|
|
{
|
2018-09-28 19:25:00 +00:00
|
|
|
ArrayList<GuardianVote> votes = new ArrayList<>(this.votes.values());
|
2018-07-06 13:30:00 +00:00
|
|
|
Collections.sort(votes);
|
|
|
|
|
|
|
|
GuardianVote v = null;
|
|
|
|
for(GuardianVote vote : votes)
|
|
|
|
{
|
|
|
|
if(vote.guardian == guardian)
|
|
|
|
{
|
|
|
|
v = vote;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
votes.remove(v);
|
|
|
|
|
|
|
|
return votes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-08 21:32:00 +00:00
|
|
|
|
2018-07-06 13:30:00 +00:00
|
|
|
public int getVotedCount()
|
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
synchronized (this.votes)
|
|
|
|
{
|
|
|
|
for(Map.Entry<Habbo, GuardianVote> set : this.votes.entrySet())
|
|
|
|
{
|
|
|
|
if(set.getValue().type == GuardianVoteType.ACCEPTABLY ||
|
|
|
|
set.getValue().type == GuardianVoteType.BADLY ||
|
|
|
|
set.getValue().type == GuardianVoteType.AWFULLY)
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
}
|