Merge branch 'guild-right-level-refactor' into 'dev'

Guild right level refactor

See merge request morningstar/Arcturus-Community!337
This commit is contained in:
Harmonic 2020-12-21 08:53:32 -05:00
commit eda660c2a7
9 changed files with 49 additions and 28 deletions

View File

@ -10,6 +10,7 @@ import com.eu.habbo.habbohotel.pets.PetCommand;
import com.eu.habbo.habbohotel.pets.PetVocalsType; import com.eu.habbo.habbohotel.pets.PetVocalsType;
import com.eu.habbo.habbohotel.pets.RideablePet; import com.eu.habbo.habbohotel.pets.RideablePet;
import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomRightLevels;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserTypingComposer; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserTypingComposer;
import com.eu.habbo.plugin.events.users.UserCommandEvent; import com.eu.habbo.plugin.events.users.UserCommandEvent;
import com.eu.habbo.plugin.events.users.UserExecuteCommandEvent; import com.eu.habbo.plugin.events.users.UserExecuteCommandEvent;
@ -72,7 +73,7 @@ public class CommandHandler {
for (String s : command.keys) { for (String s : command.keys) {
if (s.toLowerCase().equals(parts[0].toLowerCase())) { if (s.toLowerCase().equals(parts[0].toLowerCase())) {
boolean succes = false; boolean succes = false;
if (command.permission == null || gameClient.getHabbo().hasPermission(command.permission, gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null && (gameClient.getHabbo().getHabboInfo().getCurrentRoom().hasRights(gameClient.getHabbo())) || gameClient.getHabbo().hasPermission(Permission.ACC_PLACEFURNI) || (gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null && gameClient.getHabbo().getHabboInfo().getCurrentRoom().getGuildId() > 0 && gameClient.getHabbo().getHabboInfo().getCurrentRoom().guildRightLevel(gameClient.getHabbo()) >= 2))) { if (command.permission == null || gameClient.getHabbo().hasPermission(command.permission, gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null && (gameClient.getHabbo().getHabboInfo().getCurrentRoom().hasRights(gameClient.getHabbo())) || gameClient.getHabbo().hasPermission(Permission.ACC_PLACEFURNI) || (gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null && gameClient.getHabbo().getHabboInfo().getCurrentRoom().getGuildId() > 0 && gameClient.getHabbo().getHabboInfo().getCurrentRoom().getGuildRightLevel(gameClient.getHabbo()).isEqualOrGreaterThan(RoomRightLevels.GUILD_RIGHTS)))) {
try { try {
UserExecuteCommandEvent userExecuteCommandEvent = new UserExecuteCommandEvent(gameClient.getHabbo(), command, parts); UserExecuteCommandEvent userExecuteCommandEvent = new UserExecuteCommandEvent(gameClient.getHabbo(), command, parts);
Emulator.getPluginManager().fireEvent(userExecuteCommandEvent); Emulator.getPluginManager().fireEvent(userExecuteCommandEvent);

View File

@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.commands;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomRightLevels;
public class EjectAllCommand extends Command { public class EjectAllCommand extends Command {
public EjectAllCommand() { public EjectAllCommand() {
@ -14,7 +15,7 @@ public class EjectAllCommand extends Command {
Room room = gameClient.getHabbo().getHabboInfo().getCurrentRoom(); Room room = gameClient.getHabbo().getHabboInfo().getCurrentRoom();
if (room != null) { if (room != null) {
if (room.isOwner(gameClient.getHabbo()) || (room.hasGuild() && room.guildRightLevel(gameClient.getHabbo()) == 3)) { if (room.isOwner(gameClient.getHabbo()) || (room.hasGuild() && room.getGuildRightLevel(gameClient.getHabbo()).equals(RoomRightLevels.GUILD_ADMIN))) {
room.ejectAll(gameClient.getHabbo()); room.ejectAll(gameClient.getHabbo());
} }
} }

View File

@ -73,7 +73,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.awt.*; import java.awt.*;
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
@ -3864,20 +3863,27 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
} }
//TODO: Return Enum public RoomRightLevels getGuildRightLevel(Habbo habbo) {
public int guildRightLevel(Habbo habbo) {
if (this.guild > 0 && habbo.getHabboStats().hasGuild(this.guild)) { if (this.guild > 0 && habbo.getHabboStats().hasGuild(this.guild)) {
Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(this.guild); Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(this.guild);
if (Emulator.getGameEnvironment().getGuildManager().getOnlyAdmins(guild).get(habbo.getHabboInfo().getId()) != null) if (Emulator.getGameEnvironment().getGuildManager().getOnlyAdmins(guild).get(habbo.getHabboInfo().getId()) != null)
return 3; return RoomRightLevels.GUILD_ADMIN;
if (guild.getRights()) { if (guild.getRights()) {
return 2; return RoomRightLevels.GUILD_RIGHTS;
} }
} }
return 0; return RoomRightLevels.NONE;
}
/**
* @deprecated Deprecated since 2.5.0. Use {@link #getGuildRightLevel(Habbo)} instead.
*/
@Deprecated
public int guildRightLevel(Habbo habbo) {
return this.getGuildRightLevel(habbo).level;
} }
public boolean isOwner(Habbo habbo) { public boolean isOwner(Habbo habbo) {
@ -3994,15 +4000,8 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} else if (this.hasRights(habbo) && !this.hasGuild()) { } else if (this.hasRights(habbo) && !this.hasGuild()) {
flatCtrl = RoomRightLevels.RIGHTS; flatCtrl = RoomRightLevels.RIGHTS;
} else if (this.hasGuild()) { } else if (this.hasGuild()) {
int level = this.guildRightLevel(habbo); flatCtrl = this.getGuildRightLevel(habbo);
if (level == 3) {
flatCtrl = RoomRightLevels.GUILD_ADMIN;
} else if (level == 2) {
flatCtrl = RoomRightLevels.GUILD_RIGHTS;
} }
}
habbo.getClient().sendResponse(new RoomRightsComposer(flatCtrl)); habbo.getClient().sendResponse(new RoomRightsComposer(flatCtrl));
habbo.getRoomUnit().setStatus(RoomUnitStatus.FLAT_CONTROL, flatCtrl.level + ""); habbo.getRoomUnit().setStatus(RoomUnitStatus.FLAT_CONTROL, flatCtrl.level + "");
@ -4445,7 +4444,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
rotation %= 8; rotation %= 8;
if (this.hasRights(habbo) || this.guildRightLevel(habbo) >= 2 || habbo.hasPermission(Permission.ACC_MOVEROTATE)) { if (this.hasRights(habbo) || this.getGuildRightLevel(habbo).isEqualOrGreaterThan(RoomRightLevels.GUILD_RIGHTS) || habbo.hasPermission(Permission.ACC_MOVEROTATE)) {
return FurnitureMovementError.NONE; return FurnitureMovementError.NONE;
} }
@ -4560,7 +4559,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
public FurnitureMovementError placeWallFurniAt(HabboItem item, String wallPosition, Habbo owner) { public FurnitureMovementError placeWallFurniAt(HabboItem item, String wallPosition, Habbo owner) {
if (!(this.hasRights(owner) || this.guildRightLevel(owner) >= 2)) { if (!(this.hasRights(owner) || this.getGuildRightLevel(owner).isEqualOrGreaterThan(RoomRightLevels.GUILD_RIGHTS))) {
return FurnitureMovementError.NO_RIGHTS; return FurnitureMovementError.NO_RIGHTS;
} }

View File

@ -531,14 +531,14 @@ public class RoomManager {
habbo.hasPermission(Permission.ACC_ENTERANYROOM) || habbo.hasPermission(Permission.ACC_ENTERANYROOM) ||
room.hasRights(habbo) || room.hasRights(habbo) ||
(room.getState().equals(RoomState.INVISIBLE) && room.hasRights(habbo)) || (room.getState().equals(RoomState.INVISIBLE) && room.hasRights(habbo)) ||
(room.hasGuild() && room.guildRightLevel(habbo) > 2)) { (room.hasGuild() && room.getGuildRightLevel(habbo).isGreaterThan(RoomRightLevels.GUILD_RIGHTS))) {
this.openRoom(habbo, room, doorLocation); this.openRoom(habbo, room, doorLocation);
} else if (room.getState() == RoomState.LOCKED) { } else if (room.getState() == RoomState.LOCKED) {
boolean rightsFound = false; boolean rightsFound = false;
synchronized (room.roomUnitLock) { synchronized (room.roomUnitLock) {
for (Habbo current : room.getHabbos()) { for (Habbo current : room.getHabbos()) {
if (room.hasRights(current) || current.getHabboInfo().getId() == room.getOwnerId() || (room.hasGuild() && room.guildRightLevel(current) >= 2)) { if (room.hasRights(current) || current.getHabboInfo().getId() == room.getOwnerId() || (room.hasGuild() && room.getGuildRightLevel(current).isEqualOrGreaterThan(RoomRightLevels.GUILD_RIGHTS))) {
current.getClient().sendResponse(new DoorbellAddUserComposer(habbo.getHabboInfo().getUsername())); current.getClient().sendResponse(new DoorbellAddUserComposer(habbo.getHabboInfo().getUsername()));
rightsFound = true; rightsFound = true;
} }
@ -875,7 +875,7 @@ public class RoomManager {
habbo.getClient().sendResponse(new RoomUsersGuildBadgesComposer(guildBadges)); habbo.getClient().sendResponse(new RoomUsersGuildBadgesComposer(guildBadges));
if (room.hasRights(habbo) || (room.hasGuild() && room.guildRightLevel(habbo) >= 2)) { if (room.hasRights(habbo) || (room.hasGuild() && room.getGuildRightLevel(habbo).isEqualOrGreaterThan(RoomRightLevels.GUILD_RIGHTS))) {
if (!room.getHabboQueue().isEmpty()) { if (!room.getHabboQueue().isEmpty()) {
for (Habbo waiting : room.getHabboQueue().valueCollection()) { for (Habbo waiting : room.getHabboQueue().valueCollection()) {
habbo.getClient().sendResponse(new DoorbellAddUserComposer(waiting.getHabboInfo().getUsername())); habbo.getClient().sendResponse(new DoorbellAddUserComposer(waiting.getHabboInfo().getUsername()));

View File

@ -36,4 +36,20 @@ public enum RoomRightLevels {
RoomRightLevels(int level) { RoomRightLevels(int level) {
this.level = level; this.level = level;
} }
public boolean equals(RoomRightLevels level) {
return this.level == level.level;
}
public boolean isEqualOrGreaterThan(RoomRightLevels level) {
return this.level >= level.level;
}
public boolean isGreaterThan(RoomRightLevels level) {
return this.level > level.level;
}
public boolean isLessThan(RoomRightLevels level) {
return this.level < level.level;
}
} }

View File

@ -5,6 +5,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionMoodLight;
import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.modtool.ScripterManager;
import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomMoodlightData; import com.eu.habbo.habbohotel.rooms.RoomMoodlightData;
import com.eu.habbo.habbohotel.rooms.RoomRightLevels;
import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.messages.outgoing.rooms.items.MoodLightDataComposer; import com.eu.habbo.messages.outgoing.rooms.items.MoodLightDataComposer;
@ -20,7 +21,7 @@ public class MoodLightSaveSettingsEvent extends MessageHandler {
public void handle() throws Exception { public void handle() throws Exception {
Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom();
if ((room.getGuildId() <= 0 && room.guildRightLevel(this.client.getHabbo()) < 2) && !room.hasRights(this.client.getHabbo())) if ((room.getGuildId() <= 0 && room.getGuildRightLevel(this.client.getHabbo()).isLessThan(RoomRightLevels.GUILD_RIGHTS)) && !room.hasRights(this.client.getHabbo()))
return; return;
int id = this.packet.readInt(); int id = this.packet.readInt();

View File

@ -4,6 +4,7 @@ import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.interactions.InteractionMoodLight; import com.eu.habbo.habbohotel.items.interactions.InteractionMoodLight;
import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomMoodlightData; import com.eu.habbo.habbohotel.rooms.RoomMoodlightData;
import com.eu.habbo.habbohotel.rooms.RoomRightLevels;
import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.incoming.MessageHandler;
@ -12,7 +13,7 @@ public class MoodLightTurnOnEvent extends MessageHandler {
public void handle() throws Exception { public void handle() throws Exception {
Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom();
if ((room.getGuildId() > 0 && room.guildRightLevel(this.client.getHabbo()) < 2) && !room.hasRights(this.client.getHabbo())) if ((room.getGuildId() > 0 && room.getGuildRightLevel(this.client.getHabbo()).isLessThan(RoomRightLevels.GUILD_RIGHTS)) && !room.hasRights(this.client.getHabbo()))
return; return;
for (HabboItem moodLight : room.getRoomSpecialTypes().getItemsOfType(InteractionMoodLight.class)) { for (HabboItem moodLight : room.getRoomSpecialTypes().getItemsOfType(InteractionMoodLight.class)) {

View File

@ -3,6 +3,7 @@ package com.eu.habbo.messages.incoming.rooms.items;
import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.permissions.Permission;
import com.eu.habbo.habbohotel.rooms.FurnitureMovementError; import com.eu.habbo.habbohotel.rooms.FurnitureMovementError;
import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomRightLevels;
import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer; import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer;
@ -16,7 +17,7 @@ public class MoveWallItemEvent extends MessageHandler {
if (room == null) if (room == null)
return; return;
if (!room.hasRights(this.client.getHabbo()) && !this.client.getHabbo().hasPermission(Permission.ACC_PLACEFURNI) && !(room.getGuildId() > 0 && room.guildRightLevel(this.client.getHabbo()) >= 2)) { if (!room.hasRights(this.client.getHabbo()) && !this.client.getHabbo().hasPermission(Permission.ACC_PLACEFURNI) && !(room.getGuildId() > 0 && room.getGuildRightLevel(this.client.getHabbo()).isEqualOrGreaterThan(RoomRightLevels.GUILD_RIGHTS))) {
this.client.sendResponse(new BubbleAlertComposer(BubbleAlertKeys.FURNITURE_PLACEMENT_ERROR.key, FurnitureMovementError.NO_RIGHTS.errorCode)); this.client.sendResponse(new BubbleAlertComposer(BubbleAlertKeys.FURNITURE_PLACEMENT_ERROR.key, FurnitureMovementError.NO_RIGHTS.errorCode));
return; return;
} }

View File

@ -5,6 +5,7 @@ import com.eu.habbo.habbohotel.catalog.CatalogItem;
import com.eu.habbo.habbohotel.catalog.CatalogPage; import com.eu.habbo.habbohotel.catalog.CatalogPage;
import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.permissions.Permission;
import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomRightLevels;
import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.messages.outgoing.catalog.AlertPurchaseFailedComposer; import com.eu.habbo.messages.outgoing.catalog.AlertPurchaseFailedComposer;
import com.eu.habbo.messages.outgoing.catalog.PurchaseOKComposer; import com.eu.habbo.messages.outgoing.catalog.PurchaseOKComposer;
@ -35,7 +36,7 @@ public class BuyRoomPromotionEvent extends MessageHandler {
if (this.client.getHabbo().getHabboInfo().canBuy(item)) { if (this.client.getHabbo().getHabboInfo().canBuy(item)) {
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(roomId); Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(roomId);
if (!(room.isOwner(this.client.getHabbo()) || room.hasRights(this.client.getHabbo()) || room.guildRightLevel(this.client.getHabbo()) == 3)) { if (!(room.isOwner(this.client.getHabbo()) || room.hasRights(this.client.getHabbo()) || room.getGuildRightLevel(this.client.getHabbo()).equals(RoomRightLevels.GUILD_ADMIN))) {
return; return;
} }