fix databáze
parent
ce244213c3
commit
d8502bc791
4 changed files with 65 additions and 3 deletions
@ -0,0 +1,16 @@ |
|||||||
|
package xyz.mineconomia.mineconomiacore; |
||||||
|
|
||||||
|
import com.arangodb.ArangoDB; |
||||||
|
import com.arangodb.ArangoDatabase; |
||||||
|
import com.arangodb.Protocol; |
||||||
|
import org.bukkit.configuration.file.FileConfiguration; |
||||||
|
|
||||||
|
public interface database { |
||||||
|
FileConfiguration config = MineconomiaCore.getPlugin(MineconomiaCore.class).getConfig(); |
||||||
|
ArangoDB arangodb = new ArangoDB.Builder() |
||||||
|
.host(config.getString("database.host"), config.getInt("database.port")) |
||||||
|
.user(config.getString("database.user")) |
||||||
|
.password(config.getString("database.password")) |
||||||
|
.build(); |
||||||
|
ArangoDatabase database = arangodb.db(config.getString("database.database")); |
||||||
|
} |
||||||
@ -0,0 +1,36 @@ |
|||||||
|
package xyz.mineconomia.mineconomiacore.events; |
||||||
|
|
||||||
|
import com.arangodb.ArangoCollection; |
||||||
|
import com.arangodb.entity.BaseDocument; |
||||||
|
import com.arangodb.model.DocumentCreateOptions; |
||||||
|
import org.bukkit.entity.Player; |
||||||
|
import org.bukkit.event.EventHandler; |
||||||
|
import org.bukkit.event.Listener; |
||||||
|
import org.bukkit.event.player.PlayerJoinEvent; |
||||||
|
import xyz.mineconomia.mineconomiacore.MineconomiaCore; |
||||||
|
|
||||||
|
import java.util.EventListener; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Objects; |
||||||
|
|
||||||
|
import static xyz.mineconomia.mineconomiacore.database.database; |
||||||
|
|
||||||
|
public class playerAccount implements Listener { |
||||||
|
@EventHandler |
||||||
|
public static void createAccout(PlayerJoinEvent event){ |
||||||
|
Player player = event.getPlayer(); |
||||||
|
String playerName = player.getDisplayName(); |
||||||
|
ArangoCollection playersCollection = database.collection("players"); |
||||||
|
|
||||||
|
if (!playersCollection.documentExists(playerName)){ |
||||||
|
BaseDocument playerDocument = new BaseDocument(playerName); |
||||||
|
playerDocument.addAttribute("money", 0); |
||||||
|
playerDocument.addAttribute("rank", "default"); |
||||||
|
playersCollection.insertDocument(playerDocument); |
||||||
|
}else { |
||||||
|
BaseDocument playerDocument = playersCollection.getDocument(playerName, BaseDocument.class); |
||||||
|
Map<String, Object> playerProperties = playerDocument.getProperties(); |
||||||
|
MineconomiaCore.getPlugin(MineconomiaCore.class).getLogger().info(String.valueOf(playerProperties.get("money"))); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue