· 8 years ago · Jun 22, 2018, 08:12 PM
1ChannelServer.java add these:
2 private List<Pair<String, String>> eventStuff = new LinkedList<Pair<String, String>>();
3
4 public void loadEventStuff() {
5 try {
6 PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT name, characters FROM event");
7 ResultSet rs = ps.executeQuery();
8 if (!rs.next()) {
9 ps.close();
10 rs.close();
11 PreparedStatement pse = DatabaseConnection.getConnection().prepareStatement("INSERT INTO event (name) VALUES (?)");
12 for (String name : ServerConstants.EVENT_NAMES) {
13 if (!name.equalsIgnoreCase("")) {
14 pse.setString(1, name);
15 pse.executeUpdate();
16 }
17 }
18 pse.close();
19 System.out.println(" Restart Server.. ");
20 } else {
21 while (rs.next()) {
22 System.out.println(" Continue... ?");
23 eventStuff.add(new Pair(rs.getString("name"), rs.getString("characters")));
24 }
25 ps.close();
26 rs.close();
27 for (Pair<String, String> hmm : eventStuff) {
28 if (hmm.getLeft().length() != ServerConstants.EVENT_NAMES.length) {
29 PreparedStatement ps2 = DatabaseConnection.getConnection().prepareStatement("INSERT INTO event (name) VALUES (?)");
30 for (String newnames : ServerConstants.EVENT_NAMES) {
31 if (!hmm.getLeft().equalsIgnoreCase(newnames)) {
32 ps2.setString(1, newnames);
33 ps2.executeUpdate();
34 System.out.println(" New event added to database: " + newnames);
35 }
36 }
37 ps2.close();
38 }
39 }
40 }
41
42 } catch (SQLException ex) {
43 ex.printStackTrace();
44 }
45 }
46 List<Pair<String, Integer>> eventnumbers = new LinkedList<Pair<String, Integer>>(); // Etc
47
48 public void addNames() {
49 for (String names : ServerConstants.EVENT_NAMES) {
50 for (int i : ServerConstants.EVENT_NULBER_ALLOWED) {
51 eventnumbers.add(new Pair(names, i));
52 }
53 }
54 }
55
56 public boolean joinEvent(String name, MapleCharacter player) {
57 try {
58 List<String> charactersInEvent = new LinkedList<String>();
59 for (Pair<String, String> hmm : eventStuff) {
60 if (hmm.getLeft().equalsIgnoreCase(name)) {
61 charactersInEvent.addAll(Arrays.asList(hmm.getRight().split(",")));
62 }
63 }
64 if (eventnumbers.isEmpty()) {
65 addNames();
66 }
67 int number = 0;
68 for (Pair<String, Integer> wtf : eventnumbers) {
69 if (wtf.getLeft().equalsIgnoreCase(name)) {
70 number = wtf.getRight();
71 }
72 }
73 PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT time FROM event WHERE name = ?");
74 ps.setString(1, name);
75 ResultSet rs = ps.executeQuery();
76 if (!rs.next()) {
77 ps.close();
78 rs.close();
79 PreparedStatement pse = DatabaseConnection.getConnection().prepareStatement("INSERT INTO event (characters, time) VALUES (?, ?)");
80 charactersInEvent.add(player.getName());
81 pse.setString(1, charactersInEvent.toString());
82 pse.setLong(2, System.currentTimeMillis());
83 pse.executeUpdate();
84 pse.close();
85 } else if (rs.next()) {
86 if (charactersInEvent.size() < number) {
87 PreparedStatement ps2 = DatabaseConnection.getConnection().prepareStatement("UPDATE event SET characters = ? WHERE name = ?");
88 charactersInEvent.add(player.getName());
89 ps2.setString(1, charactersInEvent.toString());
90 ps2.setString(2, name);
91 ps2.executeUpdate();
92 ps2.close();
93 } else {
94 return false;
95 }
96 }
97 ps.close();
98 rs.close();
99 } catch (SQLException ex) {
100 ex.printStackTrace();
101 }
102 return true;
103 }
104
105And then under SkillFactory.getSkill(9999999); add:
106loadEventStuff();
107
108Now add this into NPCConversationManager.java:
109 ChannelServer cserv = getClient().getChannelServer();
110
111 public void joinEvent(String name, MapleCharacter player) {
112 cserv.joinEvent(name, player);
113 }
114
115And finally this into ServerConstants.java:
116 public static String[] EVENT_NAMES = {"ProItem", "event2"};
117 public static int[] EVENT_NULBER_ALLOWED = {2, 6}; // etc
118
119Oh... execute this in SQL:
120DROP TABLE IF EXISTS `event`;
121CREATE TABLE `event` (
122 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
123 `name` varchar(45) NOT NULL DEFAULT ' ',
124 `characters` varchar(2000) NOT NULL DEFAULT ' ',
125 `time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
126 PRIMARY KEY (`id`)
127) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=latin1;