Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hustler;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.text.NumberFormat;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Locale;
- import java.util.Set;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.Sound;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.enchantments.Enchantment;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.EventPriority;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.Action;
- import org.bukkit.event.block.BlockBreakEvent;
- import org.bukkit.event.player.PlayerChangedWorldEvent;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.event.player.PlayerLoginEvent;
- import org.bukkit.event.player.PlayerMoveEvent;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.potion.PotionEffect;
- import org.bukkit.potion.PotionEffectType;
- public class ParkorMain extends JavaPlugin implements Listener {
- public String ip = SecurityPlus.getIP();
- public String port = SecurityPlus.getPort();
- public String database = SecurityPlus.getDataBase();
- public String username = SecurityPlus.getUsername();
- public String password = SecurityPlus.getPassword();
- public MySQL MySQL = new MySQL(ip, port, database, username, password);
- Connection c = null;
- public ArrayList<String> playeramount = new ArrayList<String>();
- public void onEnable() {
- PluginManager manager = this.getServer().getPluginManager();
- manager.registerEvents(this, this);
- try{
- c = MySQL.openConnection();
- c.createStatement().execute("CREATE TABLE IF NOT EXISTS `parkourCheckPoints` (`ID` int(32) NOT NULL AUTO_INCREMENT,`lvl` int(36),`x` int(36), `y` int(36), `z` int(36),`world` varchar(36),`yaw` float, PRIMARY KEY (`ID`))");
- c.createStatement().execute("CREATE TABLE IF NOT EXISTS `parkourPlayers` (`ID` int(32) NOT NULL AUTO_INCREMENT, `PLAYER` varchar(36), `UUID` varchar(36),`lvl` int(36),`deaths` int(36), PRIMARY KEY (`ID`))");
- // File file = new File(getDataFolder(), "config.yml");
- // if (!file.exists()) {
- // saveDefaultConfig();
- // }
- // saveConfig();
- } catch (ClassNotFoundException | SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- public boolean checkPlayer(Player p){
- String uuid = p.getUniqueId().toString();
- try {c = MySQL.openConnection();} catch (ClassNotFoundException | SQLException e1) {e1.printStackTrace();}
- try{
- Statement statement = c.createStatement();
- ResultSet getnumbers = statement.executeQuery("SELECT * FROM parkourPlayers WHERE UUID ='"+uuid+"';");
- playeramount.clear();
- while(getnumbers.next()){
- String winningL10 = getnumbers.getString("PLAYER");
- playeramount.add(winningL10);
- } c.close();
- }catch (SQLException e) {
- e.printStackTrace(); }
- if(playeramount.size()>=1){
- return false; }
- else{return true;} }
- @EventHandler
- public void event(PlayerChangedWorldEvent e) {
- Player player = e.getPlayer();
- if ((player.getWorld().getName().equals("parkor"))) {
- player.getInventory().setChestplate(new ItemStack(Material.AIR));;
- }
- }
- public HashMap<Player, Boolean> stopspam = new HashMap<Player, Boolean>();
- HashMap<Player,Long> cooldowns = new HashMap<Player,Long>();
- public boolean hasCooldown(Player player){
- int seconds = 5;
- if(cooldowns.get(player) < (System.currentTimeMillis() - seconds*1000))
- return false;
- else
- return true;
- }
- /* @EventHandler
- public void onEChestClick(PlayerMoveEvent e) {
- Player p = e.getPlayer();
- if(e.getPlayer().getLocation().add(0,-1,0).getBlock().getType().equals(Material.DAYLIGHT_DETECTOR)||e.getPlayer().getLocation().add(0,-1,0).getBlock().getType().equals(Material.DAYLIGHT_DETECTOR_INVERTED)){
- if(stopspam.get(p) == Boolean.FALSE){
- stopspam.put(p, Boolean.TRUE);
- Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
- @Override
- public void run() {
- stopspam.put(p, Boolean.FALSE);
- }
- }, 300L);
- getCheckPoints();
- for (int i = 0; i < points.size(); i++){
- if(points.get(i).distance(e.getPlayer().getLocation())<5){
- int newlvl = getlvl(points.get(i).getBlockX(),points.get(i).getBlockZ());
- p.sendMessage("New Check Point: "+ newlvl);
- changelvl(e.getPlayer(),newlvl);
- }
- }
- }
- }
- }
- */
- public HashMap<Player, Boolean> stopspam1 = new HashMap<Player, Boolean>();
- @EventHandler
- public void beaconTPER(PlayerMoveEvent e) throws SQLException {
- Player p = e.getPlayer();
- if(e.getPlayer().getLocation().add(0,-1,0).getBlock().getType().equals(Material.BEACON)){
- if(p.getWorld().getName().equals("parkor")){
- if(stopspam1.get(p) == Boolean.FALSE){
- stopspam1.put(p, Boolean.TRUE);
- changelvl(p,getlvl(p)+1);
- int blah = getlvl(p);
- resume(p);
- c.close();
- Bukkit.broadcastMessage("§3"+p.getName()+" §7Advanced to Parkour Level: §4§l"+blah);
- Bukkit.dispatchCommand(Bukkit.getServer().getConsoleSender(),"coins give "+ p.getName()+" 250");
- p.sendMessage("§7You were given §3250 §4Shards§7 for completing the level.");
- Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
- @Override
- public void run() {
- stopspam1.put(p, Boolean.FALSE);
- }
- }, 300L);
- }}
- }
- }
- @EventHandler
- public void portal(PlayerMoveEvent e){
- Player p = e.getPlayer();
- Block block = e.getPlayer().getLocation().getBlock();
- if(block.getType().equals(Material.PORTAL)){
- if(block.getLocation().add(0,-1,0).getBlock().getType().equals(Material.DIAMOND_BLOCK)){p.teleport(block.getLocation().add(0.5,10,.5));
- p.playSound(p.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 20, 0);
- }
- if(block.getLocation().add(0,-1,0).getBlock().getType().equals(Material.IRON_BLOCK)){p.teleport(block.getLocation().add(-5.5,0,.5));
- p.playSound(p.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 20, 0);}
- if(block.getLocation().add(0,-1,0).getBlock().getType().equals(Material.GOLD_BLOCK)){p.teleport(block.getLocation().add(6.5,0,.5));
- p.playSound(p.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 20, 0);}
- if(block.getLocation().add(0,-1,0).getBlock().getType().equals(Material.LAPIS_BLOCK)){p.teleport(block.getLocation().add(.5,0,6.5));
- p.playSound(p.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 20, 0);}
- if(block.getLocation().add(0,-1,0).getBlock().getType().equals(Material.COAL_BLOCK)){p.teleport(block.getLocation().add(.5,0,-5.5));
- p.playSound(p.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 20, 0);}
- if(block.getLocation().add(0,-1,0).getBlock().getType().equals(Material.EMERALD_BLOCK)){p.teleport(block.getLocation().add(.5,-10,.5));
- p.playSound(p.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 20, 0);}
- }}
- public int deaths;
- @EventHandler
- public void lava(PlayerMoveEvent e) throws SQLException {
- Player p = e.getPlayer();
- if(e.getPlayer().getLocation().getBlock().getType().equals(Material.LAVA)||e.getPlayer().getLocation().getBlock().getType().equals(Material.STATIONARY_LAVA)){
- resume(p);
- adddeath(p);
- deaths = getdeath(p);
- p.sendMessage("§4§lDEATHS: §7§l"+ NumberFormat.getNumberInstance(Locale.US).format(deaths));
- if(deaths== 1){ Bukkit.broadcastMessage("§3"+p.getName()+"§7 Had his §4First Death!"); }
- if(deaths== 5){ Bukkit.broadcastMessage("§3"+p.getName()+"§7 Had his §4Fifth Death!"); }
- if(deaths== 10){Bukkit.broadcastMessage("§3"+p.getName()+"§7 Had his §4Tenth Death!"); }
- if(deaths== 25){Bukkit.broadcastMessage("§3"+p.getName()+"§7 Has Died §425§7 Times!"); }
- if(deaths== 50){ Bukkit.broadcastMessage("§3"+p.getName()+"§7 Has Died §450§7 Times!"); }
- if(deaths== 100){ Bukkit.broadcastMessage("§3"+p.getName()+"§7 Has Died §4100§7 Times!"); }
- if(deaths== 125){ Bukkit.broadcastMessage("§3"+p.getName()+"§7 Has Died §4125§7 Times!"); }
- if(deaths== 150){ Bukkit.broadcastMessage("§3"+p.getName()+"§7 Has Died §4150§7 Times!"); }
- if(deaths== 175){ Bukkit.broadcastMessage("§3"+p.getName()+"§7 Has Died §4175§7 Times!"); }
- if(deaths== 200){ Bukkit.broadcastMessage("§3"+p.getName()+"§7 Has Died §4200§7 Times!"); }
- if(deaths== 250){Bukkit.broadcastMessage("§3"+p.getName()+"§7 Has Died §4250§7 Times!"); }
- if(deaths== 300){Bukkit.broadcastMessage("§3"+p.getName()+"§7 Has Died §4300§7 Times!"); }
- if(deaths== 350){ Bukkit.broadcastMessage("§3"+p.getName()+"§7 Has Died §4350§7 Times!"); }
- if(deaths== 400){ Bukkit.broadcastMessage("§3"+p.getName()+"§7 Has Died §4400§7 Times!"); }
- if(deaths== 450){ Bukkit.broadcastMessage("§3"+p.getName()+"§7 Has Died §4450§7 Times!"); }
- if(deaths== 500){ Bukkit.broadcastMessage("§3"+p.getName()+"§7 Has Died §4500§7 Times!"); }
- if(deaths== 600){Bukkit.broadcastMessage("§3"+p.getName()+"§7 Has Died §4600§7 Times!"); }
- if(deaths== 700){ Bukkit.broadcastMessage("§3"+p.getName()+"§7 Has Died §4700§7 Times!"); }
- if(deaths== 800){ Bukkit.broadcastMessage("§3"+p.getName()+"§7 Has Died §4800§7 Times!"); }
- if(deaths== 900){Bukkit.broadcastMessage("§3"+p.getName()+"§7 Has Died §4900§7 Times!"); }
- if(deaths== 1000){ Bukkit.broadcastMessage("§3"+p.getName()+"§7 Has Died §41000§7 Times!"); }
- c.close();
- }
- }
- public int alldeaths;
- public int getalldeaths(){
- alldeaths = 0;
- try {c = MySQL.openConnection();} catch (ClassNotFoundException | SQLException e1) {e1.printStackTrace();}
- try{
- Statement statementshards = c.createStatement();
- ResultSet servershards = statementshards.executeQuery("SELECT * FROM parkourPlayers;");
- while(servershards.next()){
- int add = servershards.getInt("deaths");
- alldeaths =alldeaths + add;
- }
- c.close();
- }catch (SQLException e) {
- e.printStackTrace(); }
- return alldeaths;
- }
- public int getthelvl;
- public int getlvl(int x ,int z){
- try {c = MySQL.openConnection();} catch (ClassNotFoundException | SQLException e1) {e1.printStackTrace();}
- try{
- Statement statement1 = c.createStatement();
- ResultSet playernotreg = statement1.executeQuery("SELECT * FROM parkourCheckPoints WHERE (x=" + x + ") AND (z = "+z+");");
- playernotreg.next();
- getthelvl = playernotreg.getInt("lvl");
- c.close();
- }catch (SQLException e) {
- e.printStackTrace(); }
- return getthelvl;
- }
- public ArrayList<Location> points = new ArrayList<Location>();
- public void getCheckPoints(){
- try {c = MySQL.openConnection();} catch (ClassNotFoundException | SQLException e1) {e1.printStackTrace();}
- try{
- points.clear();
- Statement statementshards = c.createStatement();
- ResultSet servershards = statementshards.executeQuery("SELECT * FROM parkourCheckPoints;");
- int x;
- int y;
- int z;
- String worldname;
- while (servershards.next()){
- worldname = servershards.getString("world");
- x = servershards.getInt("x");
- y = servershards.getInt("y");
- z = servershards.getInt("z");
- World world= Bukkit.getWorld(worldname);
- Location thisloc = new Location (world,x,y,z);
- points.add(thisloc);
- }
- c.close();
- }catch (SQLException e) {
- e.printStackTrace(); }
- }
- @EventHandler
- public void onEChestClick(PlayerLoginEvent e) {
- stopspam1.put(e.getPlayer(), Boolean.FALSE);
- //getalldeaths();
- Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "holograms setline park 4 §7[§8§m----§4§l"+NumberFormat.getNumberInstance(Locale.US).format(getalldeaths())+"§8§m----§7]");
- Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
- @Override
- public void run() {
- Location loc = e.getPlayer().getLocation();
- World world = e.getPlayer().getWorld();
- world.strikeLightningEffect(loc);
- e.getPlayer().setAllowFlight(true);;
- e.getPlayer().setFlying(true);
- }
- }, 20L);
- }
- public void addPlayer(String p, String uuid, int lvl){
- try {c = MySQL.openConnection();} catch (ClassNotFoundException | SQLException e1) {e1.printStackTrace();}
- try{
- Statement statement1 = c.createStatement();
- // `PLAYER` varchar(36), `UUID` varchar(36),`lvl` int(36),`time` int(36), `x` int(36), `y` int(36), `z` int(36),`world` varchar(36), PRIMARY KEY (`ID`))");
- String add = "INSERT INTO `parkourPlayers`(`PLAYER`,`UUID`,`lvl`,`deaths`) VALUES ('" + p + "','" + uuid + "','" + lvl + "','" + 0 + "')";
- statement1.execute(add);
- c.close();
- }catch (SQLException e) {
- e.printStackTrace(); }
- }
- void changelvl(Player p, int lvl){
- try {c = MySQL.openConnection();} catch (ClassNotFoundException | SQLException e1) {e1.printStackTrace();}
- try{
- Statement statement2 = c.createStatement();
- String hasreg = ("UPDATE `parkourPlayers` SET `lvl`= '"+lvl+"' WHERE UUID ='" + p.getUniqueId().toString() + "';");
- statement2.execute(hasreg);
- c.close();
- }catch (SQLException e) {
- e.printStackTrace(); }
- }
- public void addCheckpoint(int lvl,int x,int y,int z,String world,float yaw){
- try {c = MySQL.openConnection();} catch (ClassNotFoundException | SQLException e1) {e1.printStackTrace();}
- try{
- Statement statement1 = c.createStatement();
- // `PLAYER` varchar(36), `UUID` varchar(36),`lvl` int(36),`time` int(36), `x` int(36), `y` int(36), `z` int(36),`world` varchar(36), PRIMARY KEY (`ID`))");
- String add = "INSERT INTO `parkourCheckPoints`(`lvl`,`x`,`y`,`z`,`world`,`yaw`) VALUES ('" + lvl + "','" + x + "','" + y + "','" + z + "','" + world + "','" + yaw + "')";
- statement1.execute(add);
- c.close();
- }catch (SQLException e) {
- e.printStackTrace(); }
- }
- public int thelvl;
- public int getlvl(Player p){
- try {c = MySQL.openConnection();} catch (ClassNotFoundException | SQLException e1) {e1.printStackTrace();}
- try{
- Statement statementshards = c.createStatement();
- ResultSet servershards = statementshards.executeQuery("SELECT * FROM parkourPlayers WHERE UUID ='"+p.getUniqueId().toString()+"';");
- servershards.next();
- thelvl = servershards.getInt("lvl");
- c.close();
- }catch (SQLException e) {
- e.printStackTrace(); }
- return thelvl;
- }
- public void adddeath(Player p){
- try {c = MySQL.openConnection();} catch (ClassNotFoundException | SQLException e1) {e1.printStackTrace();}
- try{
- Statement statement2 = c.createStatement();
- int count = getdeath(p)+1;
- String hasreg = ("UPDATE `parkourPlayers` SET `deaths`= '"+count+"' WHERE UUID ='" + p.getUniqueId().toString() + "';");
- statement2.execute(hasreg);
- }catch (SQLException e) {
- e.printStackTrace(); }
- }
- public int pdeaths;
- public int getdeath(Player p){
- try {c = MySQL.openConnection();} catch (ClassNotFoundException | SQLException e1) {e1.printStackTrace();}
- try{
- Statement statementshards = c.createStatement();
- ResultSet servershards = statementshards.executeQuery("SELECT * FROM parkourPlayers WHERE UUID ='"+p.getUniqueId().toString()+"';");
- servershards.next();
- pdeaths = servershards.getInt("deaths");
- }catch (SQLException e) {
- e.printStackTrace(); }
- return pdeaths;
- }
- public void resume(Player p){
- try {c = MySQL.openConnection();} catch (ClassNotFoundException | SQLException e1) {e1.printStackTrace();}
- try{
- Statement statementshards = c.createStatement();
- ResultSet servershards = statementshards.executeQuery("SELECT * FROM parkourPlayers WHERE UUID ='"+p.getUniqueId().toString()+"';");
- servershards.next();
- int thelvl = servershards.getInt("lvl");
- Statement statementshards2 = c.createStatement();
- ResultSet servershards2 = statementshards2.executeQuery("SELECT * FROM parkourCheckPoints WHERE lvl ="+thelvl+";");
- servershards2.next();
- String worldname;
- worldname = servershards2.getString("world");
- int x = servershards2.getInt("x");
- int y = servershards2.getInt("y");
- int z = servershards2.getInt("z");
- float yaw =servershards2.getFloat("yaw");
- World world= Bukkit.getWorld(worldname);
- Location theloc = new Location(world,x+.5,y,z+.5,yaw,0);
- p.teleport(theloc);
- }catch (SQLException e) {
- e.printStackTrace(); }
- }
- public void start(Player p) throws SQLException{
- if(!checkPlayer(p)){
- resume(p);
- p.sendMessage("§7Resuming to last §4Checkpoint!");
- c.close();
- }
- else{
- p.sendMessage("§7Sending you to §4Level 1! §7Good Luck!");
- addPlayer(p.getName(),p.getUniqueId().toString(),1);
- resume(p);
- c.close();
- }
- }
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
- if ((cmd.getName().equalsIgnoreCase("addcheckpoint"))&& sender.hasPermission("admin")) {
- if (args.length == 1) {
- Player p = (Player) sender;
- String pname = p.getName();
- addCheckpoint(Integer.valueOf(args[0]),p.getLocation().getBlockX(),p.getLocation().getBlockY(),p.getLocation().getBlockZ(),p.getWorld().getName(),p.getLocation().getYaw());
- }
- }
- if ((cmd.getName().equalsIgnoreCase("parkour"))) {
- if (args.length == 0) {
- Player p = (Player) sender;
- String pname = p.getName();
- try {
- start(p);
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- p.setFlying(false);
- } }
- if ((cmd.getName().equalsIgnoreCase("portal"))&& sender.hasPermission("admin")) {
- if (args.length == 1) {
- ItemStack item = new ItemStack(Material.PORTAL);
- Player p = (Player) sender;
- Location looking = p.getTargetBlock((Set<Material>) null, 6).getLocation();
- if(looking.getBlock().getType().equals(Material.STONE)||looking.getBlock().getType().equals(Material.PORTAL)){
- if(args[0].contains("2")){
- looking.getBlock().setTypeIdAndData(90, (byte)2, true);}
- if(args[0].contains("1")){
- looking.getBlock().setTypeIdAndData(90, (byte)1, true);}
- }
- }}
- return true; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement