Utoljára aktív 1694505565

pp

RealRONiN's Avatar RealRONiN gist felülvizsgálása 1694505565. Revízióhoz ugrás

1 file changed, 63 insertions

tp.java(fájl létrehozva)

@@ -0,0 +1,63 @@
1 + /*
2 + * LifeSteal - Yet another lifecore smp core.
3 + * Copyright (C) 2022 Arcade Labs
4 + *
5 + * This program is free software: you can redistribute it and/or modify
6 + * it under the terms of the GNU General Public License as published by
7 + * the Free Software Foundation, either version 3 of the License, or
8 + * (at your option) any later version.
9 + *
10 + * This program is distributed in the hope that it will be useful,
11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 + * GNU General Public License for more details.
14 + *
15 + * You should have received a copy of the GNU General Public License
16 + * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 + */
18 +
19 + package in.arcadelabs.lifesteal.api.datatypes;
20 +
21 + import com.j256.ormlite.field.FieldType;
22 + import com.j256.ormlite.field.SqlType;
23 + import com.j256.ormlite.field.types.BaseDataType;
24 + import com.j256.ormlite.support.DatabaseResults;
25 + import in.arcadelabs.lifesteal.api.profile.LifeState;
26 +
27 + import java.sql.SQLException;
28 +
29 + public class LifeStateDataType extends BaseDataType {
30 +
31 + private static final LifeStateDataType singleton = new LifeStateDataType();
32 +
33 + private LifeStateDataType() {
34 + super(SqlType.STRING, new Class<?>[]{LifeState.class});
35 + }
36 +
37 + @Override
38 + public Object parseDefaultString(FieldType fieldType, String defaultStr) {
39 + return LifeState.valueOf(defaultStr);
40 + }
41 +
42 + @Override
43 + public Object resultToSqlArg(FieldType fieldType, DatabaseResults results, int columnPos) throws SQLException {
44 + String identifier = results.getString(columnPos);
45 + return LifeState.valueOf(identifier);
46 + }
47 +
48 + @Override
49 + public Object sqlArgToJava(FieldType fieldType, Object sqlArg, int columnPos) {
50 + String identifier = (String) sqlArg;
51 + return LifeState.valueOf(identifier);
52 + }
53 +
54 + @Override
55 + public Object javaToSqlArg(FieldType fieldType, Object javaObject) {
56 + LifeState lifeState = (LifeState) javaObject;
57 + return lifeState.identifier();
58 + }
59 +
60 + public static LifeStateDataType getSingleton() {
61 + return singleton;
62 + }
63 + }
Újabb Régebbi