mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2025-01-31 12:22:36 +01:00
Vote Counters - By Beny
This commit is contained in:
parent
1151a6197d
commit
cf5283c66f
@ -355,6 +355,8 @@ public class ItemManager {
|
||||
this.interactionsList.add(new ItemInteraction("snowstorm_tree", null));
|
||||
this.interactionsList.add(new ItemInteraction("snowstorm_machine", null));
|
||||
this.interactionsList.add(new ItemInteraction("snowstorm_pile", null));
|
||||
|
||||
this.interactionsList.add(new ItemInteraction("vote_counter", InteractionVoteCounter.class));
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,106 @@
|
||||
package com.eu.habbo.habbohotel.items.interactions;
|
||||
|
||||
import com.eu.habbo.Emulator;
|
||||
import com.eu.habbo.habbohotel.gameclients.GameClient;
|
||||
import com.eu.habbo.habbohotel.items.Item;
|
||||
import com.eu.habbo.habbohotel.rooms.Room;
|
||||
import com.eu.habbo.habbohotel.rooms.RoomUnit;
|
||||
import com.eu.habbo.habbohotel.users.HabboItem;
|
||||
import com.eu.habbo.habbohotel.wired.WiredEffectType;
|
||||
import com.eu.habbo.messages.ServerMessage;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class InteractionVoteCounter extends HabboItem {
|
||||
|
||||
private boolean frozen;
|
||||
private int votes;
|
||||
private List<Integer> votedUsers;
|
||||
|
||||
public InteractionVoteCounter(ResultSet set, Item baseItem) throws SQLException {
|
||||
super(set, baseItem);
|
||||
if(!this.getExtradata().contains(",")) {
|
||||
this.setExtradata("1,0"); // frozen,votes
|
||||
}
|
||||
|
||||
String[] bits = this.getExtradata().split(",");
|
||||
frozen = bits[0].equals("1");
|
||||
votes = Integer.parseInt(bits[1]);
|
||||
votedUsers = new ArrayList<>();
|
||||
}
|
||||
|
||||
public InteractionVoteCounter(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
|
||||
super(id, userId, item, extradata, limitedStack, limitedSells);
|
||||
|
||||
if(!extradata.contains(",")) {
|
||||
extradata = "1,0";
|
||||
}
|
||||
|
||||
String[] bits = extradata.split(",");
|
||||
frozen = bits[0].equals("1");
|
||||
votes = Integer.parseInt(bits[1]);
|
||||
votedUsers = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serializeExtradata(ServerMessage serverMessage) {
|
||||
serverMessage.appendInt((this.isLimited() ? 256 : 0) + 3);
|
||||
serverMessage.appendString(this.frozen ? "0" : "1");
|
||||
serverMessage.appendInt(this.votes);
|
||||
super.serializeExtradata(serverMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWalkable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void updateExtradata() {
|
||||
this.setExtradata((this.frozen ? "1" : "0") + "," + this.votes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
|
||||
if (!((client != null && room != null && room.hasRights(client.getHabbo())) || (objects.length >= 2 && objects[1] instanceof WiredEffectType)))
|
||||
return;
|
||||
|
||||
this.frozen = !this.frozen;
|
||||
|
||||
if(!frozen) {
|
||||
this.votes = 0;
|
||||
this.votedUsers.clear();
|
||||
}
|
||||
|
||||
updateExtradata();
|
||||
this.needsUpdate(true);
|
||||
room.updateItem(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
public void vote(Room room, int UserId, int vote) {
|
||||
if(frozen)
|
||||
return;
|
||||
|
||||
if(votedUsers.contains(UserId))
|
||||
return;
|
||||
|
||||
votedUsers.add(UserId);
|
||||
|
||||
votes += vote;
|
||||
updateExtradata();
|
||||
this.needsUpdate(true);
|
||||
room.updateItem(this);
|
||||
}
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
package com.eu.habbo.messages.incoming.rooms.users;
|
||||
|
||||
import com.eu.habbo.Emulator;
|
||||
import com.eu.habbo.habbohotel.items.interactions.InteractionVoteCounter;
|
||||
import com.eu.habbo.habbohotel.rooms.Room;
|
||||
import com.eu.habbo.habbohotel.rooms.RoomUnitStatus;
|
||||
import com.eu.habbo.habbohotel.users.HabboItem;
|
||||
import com.eu.habbo.messages.incoming.MessageHandler;
|
||||
import com.eu.habbo.plugin.events.users.UserSignEvent;
|
||||
|
||||
@ -20,6 +22,16 @@ public class RoomUserSignEvent extends MessageHandler {
|
||||
if (!Emulator.getPluginManager().fireEvent(event).isCancelled()) {
|
||||
this.client.getHabbo().getRoomUnit().setStatus(RoomUnitStatus.SIGN, event.sign + "");
|
||||
this.client.getHabbo().getHabboInfo().getCurrentRoom().unIdle(this.client.getHabbo());
|
||||
|
||||
if(signId <= 10) {
|
||||
|
||||
int userId = this.client.getHabbo().getHabboInfo().getId();
|
||||
for (HabboItem item : room.getFloorItems()) {
|
||||
if (item instanceof InteractionVoteCounter) {
|
||||
((InteractionVoteCounter)item).vote(room, userId, signId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user