Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.dreamscape.server.net.mysql.store;
- import com.dreamscape.server.game.content.CollectedGameItem;
- import com.dreamscape.server.game.content.CollectionBox;
- import com.dreamscape.server.game.content.DonationDataHolder;
- import com.dreamscape.server.game.content.ItemSet;
- import com.dreamscape.server.game.content.StoreItems;
- import com.dreamscape.server.game.minigames.duelarena.Types;
- import com.dreamscape.server.game.players.Client;
- import com.mysql.jdbc.Statement;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.Map;
- public class Donation {
- private static final Logger logger = LoggerFactory.getLogger(Donation.class);
- public static final int EMPEROR_BOX_ID = 20484;
- public static final int[] BOXES = {6200, 6202, 6204, 6855, 3230};
- public static Map<Integer, StoreItems> map = new HashMap<Integer, StoreItems>();
- public static void loadStore() {
- map.put(11, StoreItems.REGULAR_DONATOR);
- map.put(13, StoreItems.SUPER_DONATOR);
- map.put(14, StoreItems.ICE_KATANA);
- map.put(15, StoreItems.BRUTAL_WHIP);
- map.put(16, StoreItems.SWORD_OF_1000_TRUTHS);
- map.put(18, StoreItems.TENTACLE_WHIP);
- map.put(19, StoreItems.TORMENTED_JR);
- map.put(20, StoreItems.ASSAULT_RIFLE);
- map.put(21, StoreItems.GLOCK);
- map.put(22, StoreItems.CALLISTO_JR);
- map.put(23, StoreItems.SCORPIA_JR);
- //map.put(24, StoreItems.OFFHAND_ICE);
- map.put(25, StoreItems.PIKACHU_JR);
- map.put(26, StoreItems.VENENATIS_JR);
- map.put(27, StoreItems.BLACK_MASK);
- map.put(28, StoreItems.VETION_JR);
- map.put(29, StoreItems.THUGBOB_JR);
- map.put(30, StoreItems.GOLD_MASK);
- map.put(31, StoreItems.PARTY_PIE);
- map.put(32, StoreItems.BANDOS_PET);
- map.put(33, StoreItems.HOT_HWEEN_MASK);
- map.put(34, StoreItems.CAMEL_PET);
- map.put(35, StoreItems.LAVA_SANTA_HAT);
- map.put(36, StoreItems.PET_MYSTERY_BOX);
- map.put(37, StoreItems.ICY_GLAIVE);
- map.put(38, StoreItems.LIME_SANTA_HAT);
- map.put(39, StoreItems.PURPLE_SANTA);
- map.put(40, StoreItems.RAINBOW_SANTA_HAT);
- map.put(41, StoreItems.OWNERS_CAPE);
- map.put(42, StoreItems.BLACK_SANTA_HAT);
- map.put(43, StoreItems.DREAM_BOX);
- map.put(44, StoreItems.DYNAMIC_MYSTERY_BOX);
- map.put(45, StoreItems.ICY_BRUTAL_WINGS);
- map.put(46, StoreItems.RAINBOW_WINGS);
- map.put(47, StoreItems.PET_MYSTERY_BOX);
- map.put(48, StoreItems.SUPER_MYSTERY_BOX);
- map.put(49, StoreItems.FLAME_TORVA_SET);
- map.put(50, StoreItems.DOUBLE_XP_RING);
- map.put(51, StoreItems.DEMONIC_BLUE_TORVA_SET);
- map.put(52, StoreItems.FULL_RAINBOW_ARMOUR);
- map.put(54, StoreItems.AMERICAN_TORVA);
- map.put(55, StoreItems.FALLEN_DEATH_CAPE);
- map.put(56, StoreItems.MORPHING_RING);
- map.put(57, StoreItems.BLUE_DEATH_CAPE);
- map.put(58, StoreItems.AMERICAN_PERNIX);
- map.put(59, StoreItems.EXTREME_DONATOR_TICKET);
- map.put(60, StoreItems.DREAM_WING_BOOTS);
- map.put(61, StoreItems.GOLDEN_AK_47);
- map.put(62, StoreItems.RING_OF_WEILTH_I);
- //map.put(63, StoreItems.ARMADYL_CROSSBOW);
- map.put(64, StoreItems.TORVA_SET);
- map.put(65, StoreItems.BLOOD_SPIRIT_SHIELD);
- map.put(66, StoreItems.SHADOW_KING_EGGS_100);
- map.put(67, StoreItems.SLED);
- map.put(68, StoreItems.SHADOW_KING_EGGS_500);
- map.put(72, StoreItems.SHADOW_KING_EGGS_1000);
- map.put(73, StoreItems.GOLD_CHAIN);
- map.put(74, StoreItems.B500_CASH);
- map.put(75, StoreItems.T1_CASH);
- map.put(76, StoreItems.AK_47);
- map.put(77, StoreItems.DREAM_TORVA_SET);
- map.put(78, StoreItems.MINIGUN);
- map.put(79, StoreItems.NOCTURNAL_CHAIN);
- map.put(80, StoreItems.PUMPKIN_PET);
- map.put(81, StoreItems.SILVER_CHAIN);
- map.put(82, StoreItems.BLUE_BOXING_GLOVES);
- map.put(83, StoreItems.BASS_GUITAR);
- map.put(84, StoreItems.SOUL_FLARE);
- map.put(85, StoreItems.CORPOREAL_PET);
- map.put(86, StoreItems.MEGA_CRATE);
- map.put(87, StoreItems.INVICTUS_BOX);
- map.put(88, StoreItems.AMERICAN_BOXING_GLOVES);
- try {
- Class.forName("com.mysql.jdbc.Driver");
- } catch (ClassNotFoundException e) {
- System.out.println("Where is your MySQL JDBC Driver?");
- e.printStackTrace();
- return;
- }
- Connection connection = null;
- Statement statement = null;
- try {
- connection = DriverManager.getConnection(
- "jdbc:mysql://149.56.129.176:3306/dsrpay",
- "standev", "h7a6leijHjB4U1su");
- if (connection != null) {
- statement = (Statement) connection.createStatement();
- Iterator<Integer> iterator = map.keySet().iterator();
- while (iterator.hasNext()) {
- int id = iterator.next();
- String sql = "SELECT productPrice FROM products WHERE id='" + id
- + "' AND storeId='54'";
- try {
- ResultSet rs = null;
- rs = ((Statement) connection.createStatement()).executeQuery(sql);
- while (rs.next())
- map.get(id).setPrice(rs.getInt("productPrice"));
- rs.close();
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- } else {
- System.out.println("Failed to make connection!");
- }
- } catch (SQLException e) {
- System.out.println("Connection Failed! Check output console");
- e.printStackTrace();
- return;
- }
- try {
- connection.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- logger.info("Successfully loaded MySQL.");
- }
- private static int addPointsForAmount(int price) {
- return (int) (price / 5);
- }
- public static void main(String[] args) throws SQLException {
- System.out.println(addPointsForAmount(6));
- }
- public static int priceFor(int id) throws SQLException {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- } catch (ClassNotFoundException e) {
- System.out.println("Where is your MySQL JDBC Driver?");
- e.printStackTrace();
- return 0;
- }
- Connection connection = null;
- Statement stmt = null;
- try {
- connection = DriverManager.getConnection("jdbc:mysql://149.56.129.176:3306/dsrpay",
- "standev", "h7a6leijHjB4U1su");
- } catch (SQLException e) {
- System.out.println("Connection Failed! Check output console");
- e.printStackTrace();
- return 0;
- }
- if (connection != null) {
- stmt = (Statement) connection.createStatement();
- String sql;
- sql = "SELECT productPrice FROM products WHERE id='" + id
- + "' AND storeId='54'";
- ResultSet rs = stmt.executeQuery(sql);
- while (rs.next())
- return rs.getInt("productPrice");
- rs.close();
- stmt.close();
- connection.close();
- } else {
- System.out.println("Failed to make connection!");
- }
- return 0;
- }
- public static boolean checkDonation(String username, Client c) throws SQLException {
- long start = System.currentTimeMillis();
- try {
- Class.forName("com.mysql.jdbc.Driver");
- } catch (ClassNotFoundException e) {
- System.out.println("Where is your MySQL JDBC Driver?");
- e.printStackTrace();
- return false;
- }
- Connection connection = null;
- Statement stmt = null;
- try {
- connection = DriverManager.getConnection("jdbc:mysql://149.56.129.176:3306/dsrpay",
- "standev", "h7a6leijHjB4U1su");
- } catch (SQLException e) {
- System.out.println("Connection Failed! Check output console");
- e.printStackTrace();
- return false;
- }
- if (connection != null) {
- stmt = (Statement) connection.createStatement();
- String sql;
- sql = "SELECT productId, quantity FROM checkout WHERE playerName='" + username
- + "' AND canClaim='1' AND storeId='54'";
- ResultSet rs = stmt.executeQuery(sql);
- ItemSet rewards = new ItemSet();
- while (rs.next()) {
- int id = rs.getInt("productId");
- int quantity = rs.getInt("quantity");
- int price = 0;
- if (map.containsKey(id)) {
- StoreItems reward = map.get(id);
- String rewardName = reward.getName();
- price = (int) reward.getPrice();
- price *= quantity;
- c.getPA().writeDonationLogs(rewardName);
- System.out.println(reward.name() + " " + reward.getItemId() + " " + reward.getAmount() + " " + quantity);
- int count = 0;
- if (reward.getItemIds() == null) {
- count = reward.getAmount() * quantity;
- rewards.add(new CollectedGameItem(reward.getItemId(), (reward.getAmount() * quantity), Types.DONATION_ITEM));
- } else {
- for (int index = 0; index < reward.getItemIds().length; index++) {
- for (int ia : BOXES) {
- if (reward.getItemIds()[index] == ia) {
- count++;
- }
- }
- rewards.add(new CollectedGameItem(reward.getItemIds()[index], (reward.getAmounts()[index] * quantity), Types.DONATION_ITEM)); // was
- }
- }
- int gave = 0;
- if (count >= 3)
- gave = count / 3;
- if (gave <= 0 && count >= 3) {
- while (count > 0) {
- if (count < 3) {
- break;
- }
- if (count > 3) {
- count -= 3;
- gave++;
- }
- }
- }
- System.out.println(gave + " ----- "+ count);
- if (gave > 0) {
- rewards.add(new CollectedGameItem(EMPEROR_BOX_ID, gave, Types.DONATION_ITEM));
- c.sendMessage("As a bonus for donating for boxes, you've received x"+gave+" Emperor box(es).");
- }
- c.forcedText = "I just donated for " + rewardName;
- c.sendMessage("You have successfully donated and recieved " + quantity + "x " + rewardName);
- c.getPA().handleDonation(rewardName, quantity);
- int points = addPointsForAmount(price);
- if (points > 0) {
- c.sendMessage("<col=255>You have been rewarded with <col=800000000>" + points
- + "<col=255> Donation Points for this donation!");
- c.donationPoints += points;
- }
- DonationDataHolder.storeDonatedAmountFor(c, reward.getPrice());
- }
- }
- sql = "UPDATE checkout SET canClaim = '2' WHERE playerName='" + username
- + "' AND canClaim='1' AND storeId='54'";
- stmt.execute(sql);
- rs.close();
- stmt.close();
- connection.close();
- if (rewards.isEmpty()) {
- return false;
- } else {
- CollectionBox.save(username, rewards);
- if (CollectionBox.hasItems(username)) {
- c.sendMessage("@cya@You have items waiting in your collection box.");
- }
- return true;
- }
- } else {
- System.out.println("Failed to make connection!");
- }
- long end = System.currentTimeMillis();
- System.out.println("TOOK " + (end - start));
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement