mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2024-11-22 23:10:52 +01:00
Make publishing pictures deduct duckets and make publish & purchase point type configurable
This commit is contained in:
parent
52209e52bd
commit
593bb74532
3
sqlupdates/2_3_0-RC-1_TO_2_3_0-RC-2.sql
Normal file
3
sqlupdates/2_3_0-RC-1_TO_2_3_0-RC-2.sql
Normal file
@ -0,0 +1,3 @@
|
||||
INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('camera.price.points.publish', '5');
|
||||
INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('camera.price.points.publish.type', '0');
|
||||
INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('camera.price.points.type', '0');
|
@ -1,8 +1,10 @@
|
||||
package com.eu.habbo.messages.incoming.camera;
|
||||
|
||||
import com.eu.habbo.Emulator;
|
||||
import com.eu.habbo.habbohotel.users.Habbo;
|
||||
import com.eu.habbo.messages.incoming.MessageHandler;
|
||||
import com.eu.habbo.messages.outgoing.camera.CameraPublishWaitMessageComposer;
|
||||
import com.eu.habbo.messages.outgoing.catalog.NotEnoughPointsTypeComposer;
|
||||
import com.eu.habbo.plugin.events.users.UserPublishPictureEvent;
|
||||
|
||||
import java.sql.Connection;
|
||||
@ -10,40 +12,49 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class CameraPublishToWebEvent extends MessageHandler {
|
||||
public static int CAMERA_PUBLISH_POINTS = 5;
|
||||
public static int CAMERA_PUBLISH_POINTS_TYPE = 0;
|
||||
|
||||
@Override
|
||||
public void handle() throws Exception {
|
||||
if (this.client.getHabbo().getHabboInfo().getPhotoTimestamp() != 0) {
|
||||
if (!this.client.getHabbo().getHabboInfo().getPhotoJSON().isEmpty()) {
|
||||
if (this.client.getHabbo().getHabboInfo().getPhotoJSON().contains(this.client.getHabbo().getHabboInfo().getPhotoTimestamp() + "")) {
|
||||
int timestamp = Emulator.getIntUnixTimestamp();
|
||||
Habbo habbo = this.client.getHabbo();
|
||||
|
||||
boolean published = false;
|
||||
int timeDiff = timestamp - this.client.getHabbo().getHabboInfo().getWebPublishTimestamp();
|
||||
int wait = 0;
|
||||
if (timeDiff < Emulator.getConfig().getInt("camera.publish.delay")) {
|
||||
wait = timeDiff - Emulator.getConfig().getInt("camera.publish.delay");
|
||||
} else {
|
||||
UserPublishPictureEvent publishPictureEvent = new UserPublishPictureEvent(this.client.getHabbo(), this.client.getHabbo().getHabboInfo().getPhotoURL(), timestamp, this.client.getHabbo().getHabboInfo().getPhotoRoomId());
|
||||
if (!Emulator.getPluginManager().fireEvent(publishPictureEvent).isCancelled()) {
|
||||
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO camera_web (user_id, room_id, timestamp, url) VALUES (?, ?, ?, ?)")) {
|
||||
statement.setInt(1, this.client.getHabbo().getHabboInfo().getId());
|
||||
statement.setInt(2, publishPictureEvent.roomId);
|
||||
statement.setInt(3, publishPictureEvent.timestamp);
|
||||
statement.setString(4, publishPictureEvent.URL);
|
||||
statement.execute();
|
||||
this.client.getHabbo().getHabboInfo().setWebPublishTimestamp(timestamp);
|
||||
published = true;
|
||||
} catch (SQLException e) {
|
||||
Emulator.getLogging().logSQLException(e);
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (habbo == null) return;
|
||||
if (habbo.getHabboInfo().getPhotoTimestamp() == 0) return;
|
||||
if (habbo.getHabboInfo().getPhotoJSON().isEmpty()) return;
|
||||
if (!habbo.getHabboInfo().getPhotoJSON().contains(habbo.getHabboInfo().getPhotoTimestamp() + "")) return;
|
||||
|
||||
this.client.sendResponse(new CameraPublishWaitMessageComposer(published, wait, published ? this.client.getHabbo().getHabboInfo().getPhotoURL() : ""));
|
||||
if (habbo.getHabboInfo().getCurrencyAmount(CameraPublishToWebEvent.CAMERA_PUBLISH_POINTS_TYPE) < CameraPublishToWebEvent.CAMERA_PUBLISH_POINTS) {
|
||||
this.client.sendResponse(new NotEnoughPointsTypeComposer(false, true, CameraPublishToWebEvent.CAMERA_PUBLISH_POINTS));
|
||||
return;
|
||||
}
|
||||
|
||||
int timestamp = Emulator.getIntUnixTimestamp();
|
||||
|
||||
boolean isOk = false;
|
||||
int cooldownLeft = Math.max(0, Emulator.getConfig().getInt("camera.publish.delay") - (timestamp - this.client.getHabbo().getHabboInfo().getWebPublishTimestamp()));
|
||||
|
||||
if (cooldownLeft == 0) {
|
||||
UserPublishPictureEvent publishPictureEvent = new UserPublishPictureEvent(this.client.getHabbo(), this.client.getHabbo().getHabboInfo().getPhotoURL(), timestamp, this.client.getHabbo().getHabboInfo().getPhotoRoomId());
|
||||
|
||||
if (!Emulator.getPluginManager().fireEvent(publishPictureEvent).isCancelled()) {
|
||||
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO camera_web (user_id, room_id, timestamp, url) VALUES (?, ?, ?, ?)")) {
|
||||
statement.setInt(1, this.client.getHabbo().getHabboInfo().getId());
|
||||
statement.setInt(2, publishPictureEvent.roomId);
|
||||
statement.setInt(3, publishPictureEvent.timestamp);
|
||||
statement.setString(4, publishPictureEvent.URL);
|
||||
statement.execute();
|
||||
|
||||
this.client.getHabbo().getHabboInfo().setWebPublishTimestamp(timestamp);
|
||||
this.client.getHabbo().givePoints(CameraPublishToWebEvent.CAMERA_PUBLISH_POINTS_TYPE, -CameraPublishToWebEvent.CAMERA_PUBLISH_POINTS);
|
||||
|
||||
isOk = true;
|
||||
} catch (SQLException e) {
|
||||
Emulator.getLogging().logSQLException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.client.sendResponse(new CameraPublishWaitMessageComposer(isOk, cooldownLeft, isOk ? this.client.getHabbo().getHabboInfo().getPhotoURL() : ""));
|
||||
}
|
||||
}
|
@ -11,34 +11,47 @@ import com.eu.habbo.messages.outgoing.inventory.InventoryRefreshComposer;
|
||||
import com.eu.habbo.plugin.events.users.UserPurchasePictureEvent;
|
||||
|
||||
public class CameraPurchaseEvent extends MessageHandler {
|
||||
public static int CAMERA_PURCHASE_CREDITS = 5;
|
||||
public static int CAMERA_PURCHASE_POINTS = 5;
|
||||
public static int CAMERA_PURCHASE_POINTS_TYPE = 0;
|
||||
|
||||
@Override
|
||||
public void handle() throws Exception {
|
||||
if (this.client.getHabbo().getHabboInfo().getCredits() < Emulator.getConfig().getInt("camera.price.credits") || this.client.getHabbo().getHabboInfo().getCurrencyAmount(0) < Emulator.getConfig().getInt("camera.price.points")) {
|
||||
this.client.sendResponse(new NotEnoughPointsTypeComposer(this.client.getHabbo().getHabboInfo().getCredits() < Emulator.getConfig().getInt("camera.price.credits"), this.client.getHabbo().getHabboInfo().getCurrencyAmount(0) < Emulator.getConfig().getInt("camera.price.points"), 0));
|
||||
if (this.client.getHabbo().getHabboInfo().getCredits() < CameraPurchaseEvent.CAMERA_PURCHASE_CREDITS) {
|
||||
this.client.sendResponse(new NotEnoughPointsTypeComposer(true, false, 0));
|
||||
return;
|
||||
}
|
||||
if (this.client.getHabbo().getHabboInfo().getPhotoTimestamp() != 0) {
|
||||
if (!this.client.getHabbo().getHabboInfo().getPhotoJSON().isEmpty()) {
|
||||
if (this.client.getHabbo().getHabboInfo().getPhotoJSON().contains(this.client.getHabbo().getHabboInfo().getPhotoTimestamp() + "")) {
|
||||
if (Emulator.getPluginManager().fireEvent(new UserPurchasePictureEvent(this.client.getHabbo(), this.client.getHabbo().getHabboInfo().getPhotoURL(), this.client.getHabbo().getHabboInfo().getCurrentRoom().getId(), this.client.getHabbo().getHabboInfo().getPhotoTimestamp())).isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
HabboItem photoItem = Emulator.getGameEnvironment().getItemManager().createItem(this.client.getHabbo().getHabboInfo().getId(), Emulator.getGameEnvironment().getItemManager().getItem(Emulator.getConfig().getInt("camera.item_id")), 0, 0, this.client.getHabbo().getHabboInfo().getPhotoJSON());
|
||||
if (this.client.getHabbo().getHabboInfo().getCurrencyAmount(CameraPurchaseEvent.CAMERA_PURCHASE_POINTS_TYPE) < CameraPurchaseEvent.CAMERA_PURCHASE_POINTS) {
|
||||
this.client.sendResponse(new NotEnoughPointsTypeComposer(false, true, CameraPurchaseEvent.CAMERA_PURCHASE_POINTS_TYPE));
|
||||
return;
|
||||
}
|
||||
|
||||
if (photoItem != null) {
|
||||
photoItem.setExtradata(photoItem.getExtradata().replace("%id%", photoItem.getId() + ""));
|
||||
photoItem.needsUpdate(true);
|
||||
this.client.getHabbo().getInventory().getItemsComponent().addItem(photoItem);
|
||||
this.client.sendResponse(new CameraPurchaseSuccesfullComposer());
|
||||
this.client.sendResponse(new AddHabboItemComposer(photoItem));
|
||||
this.client.sendResponse(new InventoryRefreshComposer());
|
||||
this.client.getHabbo().giveCredits(-Emulator.getConfig().getInt("camera.price.credits"));
|
||||
this.client.getHabbo().givePixels(-Emulator.getConfig().getInt("camera.price.points"));
|
||||
AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("CameraPhotoCount"));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.client.getHabbo().getHabboInfo().getPhotoTimestamp() == 0) return;
|
||||
if (this.client.getHabbo().getHabboInfo().getPhotoJSON().isEmpty()) return;
|
||||
if (!this.client.getHabbo().getHabboInfo().getPhotoJSON().contains(this.client.getHabbo().getHabboInfo().getPhotoTimestamp() + ""))
|
||||
return;
|
||||
|
||||
if (Emulator.getPluginManager().fireEvent(new UserPurchasePictureEvent(this.client.getHabbo(), this.client.getHabbo().getHabboInfo().getPhotoURL(), this.client.getHabbo().getHabboInfo().getCurrentRoom().getId(), this.client.getHabbo().getHabboInfo().getPhotoTimestamp())).isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
HabboItem photoItem = Emulator.getGameEnvironment().getItemManager().createItem(this.client.getHabbo().getHabboInfo().getId(), Emulator.getGameEnvironment().getItemManager().getItem(Emulator.getConfig().getInt("camera.item_id")), 0, 0, this.client.getHabbo().getHabboInfo().getPhotoJSON());
|
||||
|
||||
if (photoItem != null) {
|
||||
photoItem.setExtradata(photoItem.getExtradata().replace("%id%", photoItem.getId() + ""));
|
||||
photoItem.needsUpdate(true);
|
||||
|
||||
this.client.getHabbo().getInventory().getItemsComponent().addItem(photoItem);
|
||||
|
||||
this.client.sendResponse(new CameraPurchaseSuccesfullComposer());
|
||||
this.client.sendResponse(new AddHabboItemComposer(photoItem));
|
||||
this.client.sendResponse(new InventoryRefreshComposer());
|
||||
|
||||
this.client.getHabbo().giveCredits(-CameraPurchaseEvent.CAMERA_PURCHASE_CREDITS);
|
||||
this.client.getHabbo().givePoints(CameraPurchaseEvent.CAMERA_PURCHASE_POINTS_TYPE, -CameraPurchaseEvent.CAMERA_PURCHASE_POINTS);
|
||||
|
||||
AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("CameraPhotoCount"));
|
||||
}
|
||||
}
|
||||
}
|
@ -5,25 +5,27 @@ import com.eu.habbo.messages.outgoing.MessageComposer;
|
||||
import com.eu.habbo.messages.outgoing.Outgoing;
|
||||
|
||||
public class CameraPublishWaitMessageComposer extends MessageComposer {
|
||||
public final boolean published;
|
||||
public final int seconds;
|
||||
public final String unknownString;
|
||||
public final boolean isOk;
|
||||
public final int cooldownSeconds;
|
||||
public final String extraDataId;
|
||||
|
||||
public CameraPublishWaitMessageComposer(boolean published, int seconds, String unknownString) {
|
||||
this.published = published;
|
||||
this.seconds = seconds;
|
||||
this.unknownString = unknownString;
|
||||
public CameraPublishWaitMessageComposer(boolean isOk, int cooldownSeconds, String extraDataId) {
|
||||
this.isOk = isOk;
|
||||
this.cooldownSeconds = cooldownSeconds;
|
||||
this.extraDataId = extraDataId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerMessage compose() {
|
||||
this.response.init(Outgoing.CameraPublishWaitMessageComposer);
|
||||
this.response.appendBoolean(this.published);
|
||||
this.response.appendInt(this.seconds);
|
||||
|
||||
if (this.published) {
|
||||
this.response.appendString(this.unknownString);
|
||||
this.response.appendBoolean(this.isOk);
|
||||
this.response.appendInt(this.cooldownSeconds);
|
||||
|
||||
if (!this.extraDataId.isEmpty()) {
|
||||
this.response.appendString(this.extraDataId);
|
||||
}
|
||||
|
||||
return this.response;
|
||||
}
|
||||
}
|
@ -22,6 +22,8 @@ import com.eu.habbo.habbohotel.users.HabboManager;
|
||||
import com.eu.habbo.habbohotel.wired.WiredHandler;
|
||||
import com.eu.habbo.habbohotel.wired.highscores.WiredHighscoreManager;
|
||||
import com.eu.habbo.messages.PacketManager;
|
||||
import com.eu.habbo.messages.incoming.camera.CameraPublishToWebEvent;
|
||||
import com.eu.habbo.messages.incoming.camera.CameraPurchaseEvent;
|
||||
import com.eu.habbo.messages.incoming.floorplaneditor.FloorPlanEditorSaveEvent;
|
||||
import com.eu.habbo.messages.incoming.hotelview.HotelViewRequestLTDAvailabilityEvent;
|
||||
import com.eu.habbo.messages.incoming.users.ChangeNameCheckUsernameEvent;
|
||||
@ -124,6 +126,11 @@ public class PluginManager {
|
||||
RoomManager.SHOW_PUBLIC_IN_POPULAR_TAB = Emulator.getConfig().getBoolean("hotel.navigator.populartab.publics");
|
||||
|
||||
ChangeNameCheckUsernameEvent.VALID_CHARACTERS = Emulator.getConfig().getValue("allowed.username.characters", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_-=!?@:,.");
|
||||
CameraPublishToWebEvent.CAMERA_PUBLISH_POINTS = Emulator.getConfig().getInt("camera.price.points.publish", 5);
|
||||
CameraPublishToWebEvent.CAMERA_PUBLISH_POINTS_TYPE = Emulator.getConfig().getInt("camera.price.points.publish.type", 0);
|
||||
CameraPurchaseEvent.CAMERA_PURCHASE_CREDITS = Emulator.getConfig().getInt("camera.price.credits", 5);
|
||||
CameraPurchaseEvent.CAMERA_PURCHASE_POINTS = Emulator.getConfig().getInt("camera.price.points", 5);
|
||||
CameraPurchaseEvent.CAMERA_PURCHASE_POINTS_TYPE = Emulator.getConfig().getInt("camera.price.points.type", 0);
|
||||
|
||||
if (Emulator.isReady) {
|
||||
Emulator.getGameEnvironment().getCreditsScheduler().reloadConfig();
|
||||
|
Loading…
Reference in New Issue
Block a user