daily pastebin goal
68%
SHARE
TWEET

Untitled

a guest Apr 19th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.Ondrej.AntiMove.Listeners;
  2.  
  3. import me.Ondrej.AntiMove.Main;
  4. import org.bukkit.Bukkit;
  5. import org.bukkit.ChatColor;
  6. import org.bukkit.configuration.file.FileConfiguration;
  7. import org.bukkit.configuration.file.YamlConfiguration;
  8. import org.bukkit.entity.Player;
  9. import org.bukkit.event.EventHandler;
  10. import org.bukkit.event.Listener;
  11. import org.bukkit.event.player.*;
  12.  
  13. import java.io.File;
  14. import java.io.IOException;
  15. import java.util.ArrayList;
  16.  
  17. public class Join implements Listener{
  18.  
  19.  
  20.     ArrayList<Player> player = new ArrayList<>();
  21.  
  22.     @EventHandler
  23.     public void onJoin(PlayerJoinEvent e) {
  24.         Player p = e.getPlayer();
  25.  
  26.         File f = new File(Bukkit.getServer().getPluginManager().getPlugin("AntiMove").getDataFolder(), File.separator + "config.yml");
  27.         FileConfiguration config = YamlConfiguration.loadConfiguration(f);
  28.  
  29.         player.add(p);
  30.  
  31.         if (!f.exists()) {
  32.             try {
  33.  
  34.                 config.createSection("message");
  35.                 config.set("message", "&7[&6&lSystem&7] You are joining? Wait three seconds, please.");
  36.  
  37.                 config.createSection("time");
  38.                 config.set("time", 3);
  39.  
  40.                 int tim = config.getInt("time");
  41.  
  42.                 String mess = config.getString("message");
  43.  
  44.                 p.sendMessage(ChatColor.translateAlternateColorCodes('&', mess));
  45.  
  46.                 int vypocet = tim * 20;
  47.  
  48.                 Main.pl.getServer().getScheduler().runTaskLater(Main.pl, () -> player.remove(p), vypocet);
  49.  
  50.                 config.save(f);
  51.  
  52.             } catch (IOException exception) {
  53.                 exception.printStackTrace();
  54.             }
  55.         } else {
  56.             int tim = config.getInt("time");
  57.  
  58.             String mess = config.getString("message");
  59.  
  60.  
  61.             p.sendMessage(ChatColor.translateAlternateColorCodes('&', mess));
  62.  
  63.             int vypocet = tim * 20;
  64.  
  65.             Main.pl.getServer().getScheduler().runTaskLater(Main.pl, () -> player.remove(p), vypocet);
  66.         }
  67.     }
  68.  
  69.     @EventHandler
  70.     public void onMove(PlayerMoveEvent e){
  71.         Player p = e.getPlayer();
  72.  
  73.         if (this.player.contains(p)){
  74.             e.setCancelled(true);
  75.         }
  76.     }
  77.  
  78.     @EventHandler
  79.     public void onChat(PlayerChatEvent e){
  80.         Player p = e.getPlayer();
  81.  
  82.         if (this.player.contains(p)){
  83.             e.setCancelled(true);
  84.         }
  85.     }
  86.  
  87. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top