Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cz.sam.plugin;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.SkullType;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- import org.bukkit.block.Skull;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.java.JavaPlugin;
- import com.mysql.jdbc.Connection;
- import com.mysql.jdbc.Statement;
- public class XHeads extends JavaPlugin {
- public void onEnable() {
- Config.log = Bukkit.getServer().getLogger();
- Config.log.info("[XHeads] Activated.");
- this.saveDefaultConfig();
- Config.DBActive = this.getConfig().getBoolean("mysql.active");
- Config.DBIp = this.getConfig().getString("mysql.server");
- Config.DBPort = this.getConfig().getInt("mysql.port");
- Config.DBUser = this.getConfig().getString("mysql.user");
- Config.DBPass = this.getConfig().getString("mysql.pass");
- Config.Databse = this.getConfig().getString("mysql.database");
- this.Connect();
- this.UpdateSkull();
- }
- public void UpdateSkull() {
- Bukkit.getScheduler().runTaskTimer(this, new Runnable() {
- public void run() {
- try {
- ResultSet readHeads = Config.st.executeQuery("SELECT * FROM `sg_heads`");
- while(readHeads.next()) {
- updateSkull(readHeads.getString("world"), getName(readHeads.getInt("position")), readHeads.getInt("x"), readHeads.getInt("y"), readHeads.getInt("z"));
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }, 30, 60);
- }
- public String getName(int Position) {
- String name = null;
- try {
- ResultSet getName = Config.st.executeQuery("SELECT * FROM `sg_playerstats` WHERE `position`='" + Position + "'");
- while(getName.next()) {
- name = getName.getString("player");
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- }
- return name;
- }
- public void updateSkull(String World, String PlayerName, int x, int y, int z){
- World Sworld = Bukkit.getWorld(World);
- Location loc = new Location(Sworld, x, y, z);
- Block b = loc.getBlock();
- if(b.getType() == Material.SKULL){
- Skull skull = (Skull) b.getState();
- skull.setSkullType(SkullType.PLAYER);
- skull.setOwner(PlayerName);
- skull.update(true);
- }
- }
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
- Player player = (Player) sender;
- if(cmd.getName().equalsIgnoreCase("setskull")) {
- if(args[0] != null & args[1] != null & args[2] != null & args[3] != null & args[4] != null) {
- try {
- Config.st.execute("INSERT INTO `sg_heads` (position, world, x, y, z) values('" + args[0] + "', '" + args[1] + "', '" + args[2] + "', '" + args[3] + "', '" + args[4] + "')");
- player.sendMessage("Pozice hlavy ulozena.");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- return false;
- }
- public void Connect() {
- if(Config.DBActive) {
- try {
- Config.con = (Connection) DriverManager.getConnection("jdbc:mysql://" + Config.DBIp + ":" + Config.DBPort + "/" + Config.Databse, Config.DBUser, Config.DBPass);
- Config.st = (Statement) Config.con.createStatement();
- Config.st.execute("CREATE TABLE IF NOT EXISTS `sg_heads` (`id` int(255) NOT NULL AUTO_INCREMENT, `position` int(255) NOT NULL, `world` varchar(255) NOT NULL, `x` int(255) NOT NULL, `y` int(255) NOT NULL, `z` int(255) NOT NULL, PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1");
- Config.log.info("[XHeads] Plugin se pripojil do database !");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- } else {
- Config.log.info("[XHeads] Pro pouziti pluginu musi byt nastavena database !");
- }
- }
- public void onDisable() {
- Config.log.info("[XHeads] Deactivated.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement