Created
June 5, 2020 17:30
-
-
Save AmmarTee/ef332f19f7a0ad3e4e7c109b76442a42 to your computer and use it in GitHub Desktop.
Plugin To store Player data to MongoDB database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.ammart.plugin.hello; | |
import org.bukkit.plugin.java.JavaPlugin; | |
public final class Hello extends JavaPlugin{ | |
@Override | |
public void onEnable() { | |
getCommand("Hello").setExecutor(new HelloCommand()); | |
System.out.println("Hello Plugin Started"); | |
} | |
@Override | |
public void onDisable() { | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.ammart.plugin.hello; | |
import com.mongodb.client.MongoClient; | |
import com.mongodb.client.MongoClients; | |
import com.mongodb.client.MongoCollection; | |
import com.mongodb.client.MongoDatabase; | |
import org.bson.Document; | |
import org.bukkit.ChatColor; | |
import org.bukkit.command.Command; | |
import org.bukkit.command.CommandExecutor; | |
import org.bukkit.command.CommandSender; | |
import org.bukkit.entity.Player; | |
public class HelloCommand implements CommandExecutor { | |
@Override | |
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | |
sender.sendMessage("Command Executing"); | |
if(sender instanceof Player){ | |
Player player = (Player)sender; | |
String Pname = player.getName(); | |
String PUUID = player.getUniqueId().toString(); | |
if (sender.hasPermission("hello.database.add")) { | |
//Modify your Databse Files. | |
MongoClient mongoClient = MongoClients.create(""); | |
MongoDatabase dataBase = mongoClient.getDatabase(""); | |
MongoCollection<Document> collection = dataBase.getCollection(""); | |
Document PlayerData = new Document("Name",Pname).append("UUID",PUUID); | |
collection.insertOne(PlayerData); | |
return true; | |
} | |
else{ | |
player.sendMessage(ChatColor.RED+"You Do not have Permission To execute that Command"); | |
} | |
} | |
else{ | |
sender.sendMessage("You're A Console"); | |
return true; | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment