Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package wcs;
- import java.io.File;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.block.Block;
- import org.bukkit.block.BlockState;
- import org.bukkit.block.Sign;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.SignChangeEvent;
- import org.bukkit.event.player.PlayerChangedWorldEvent;
- import org.bukkit.event.player.PlayerJoinEvent;
- import org.bukkit.event.player.PlayerQuitEvent;
- import org.bukkit.plugin.java.JavaPlugin;
- //import java.util.UUID;
- //import org.bukkit.World;
- public class Main extends JavaPlugin implements Listener {
- public void onEnable() {
- getServer().getPluginManager().registerEvents(this, this);
- //File configFile = new File(getDataFolder() + "/config.yml");
- File signsFile = new File(getDataFolder() + "/Signs.yml");
- //if (!configFile.exists()) {
- //saveDefaultConfig();
- // }
- if(!signsFile.exists()){
- Files.saveDefaultConfig(this);
- }
- getConfig();
- File pluginFolder = new File("./plugins/WorldCountSigns/");
- if (!pluginFolder.exists()) {
- pluginFolder.mkdir();
- }
- //if ((pluginFolder.exists()) && (!configFile.exists())){
- //saveDefaultConfig(); }
- if((pluginFolder.exists()) && (!signsFile.exists())){
- Files.saveDefaultConfig(this); }
- }
- public void onDisable() {
- }
- @EventHandler
- public void onSignCreate(SignChangeEvent event) {
- if (event.getBlock().getType() == Material.SIGN_POST
- || event.getBlock().getType() == Material.WALL_SIGN) {
- String worldname = event.getLine(0);
- if(event.getLine(1).equalsIgnoreCase("[WCS]")){
- if(!event.getLine(0).isEmpty()){
- if(Bukkit.getWorld(worldname) != null){
- event.setLine(1, "[" + worldname + "]" );
- int PlayersOnline = Bukkit.getWorld(worldname).getPlayers().size();
- String players = Integer.toString(PlayersOnline);
- event.setLine(2, "Players: " + players);
- Location loc = event.getBlock().getLocation();
- int x = (int) loc.getX();
- int y = (int) loc.getY();
- int z = (int) loc.getZ();
- String world = event.getBlock().getWorld().getName();
- int signnumber = Files.getCustomConfig(this).getInt("signnumber") + 1;
- Files.getCustomConfig(this).set("signs." + signnumber + ".x", x);
- Files.getCustomConfig(this).set("signs." + signnumber + ".y", y);
- Files.getCustomConfig(this).set("signs." + signnumber + ".z", z);
- Files.getCustomConfig(this).set("signs." + signnumber + ".world", world);
- Files.getCustomConfig(this).set("signs." + signnumber + ".worldb", worldname);
- Files.getCustomConfig(this).set("signnumber", signnumber);
- Files.saveCustomConfig(this);
- //Files.reloadCustomConfig(this);
- this.getLogger().info("World Sign Created At " + x + ", " + y + ", " + z + " in " + world);
- event.setLine(0, "");
- }
- }else if(event.getLine(0).isEmpty()){
- event.setLine(1, "[" + event.getPlayer().getWorld().getName() + "]" );
- int PlayersOnline = event.getPlayer().getWorld().getPlayers().size();
- String players = Integer.toString(PlayersOnline);
- event.setLine(2, "Players: " + players);
- Location loc = event.getBlock().getLocation();
- int x = (int) loc.getX();
- int y = (int) loc.getY();
- int z = (int) loc.getZ();
- String world = event.getBlock().getWorld().getName();
- int signnumber = Files.getCustomConfig(this).getInt("signnumber") + 1;
- Files.getCustomConfig(this).set("signs." + signnumber + ".x", x);
- Files.getCustomConfig(this).set("signs." + signnumber + ".y", y);
- Files.getCustomConfig(this).set("signs." + signnumber + ".z", z);
- Files.getCustomConfig(this).set("signs." + signnumber + ".world", world);
- Files.saveCustomConfig(this);
- //Files.reloadCustomConfig(this);
- this.getLogger().info("World Sign Created At " + x + ", " + y + ", " + z + " in " + world);
- }
- }
- }
- }
- @EventHandler
- public void onPlayerMoveWorld(PlayerChangedWorldEvent event) {
- int sign = Files.getCustomConfig(this).getInt("signnumber") + 1;
- for(int currentSign = 1; currentSign<sign; currentSign++)
- {
- int x = Files.getCustomConfig(this).getInt("signs." + currentSign + ".x");
- int y = Files.getCustomConfig(this).getInt("signs." + currentSign + ".y");
- int z = Files.getCustomConfig(this).getInt("signs." + currentSign + ".z");
- String worldname = Files.getCustomConfig(this).getString("signs." + currentSign + ".worldb");
- String world1 = Files.getCustomConfig(this).getString("signs." + currentSign + ".world");
- Block block = Bukkit.getWorld(world1).getBlockAt(x, y, z);
- block.getChunk().load();
- BlockState state = block.getState();
- int PlayersOnline = Bukkit.getWorld(worldname).getPlayers().size();
- String players = Integer.toString(PlayersOnline);
- if (state instanceof Sign){
- Sign s = (Sign) state;
- s.setLine(2, "Players: " + players);
- s.update(true);
- }
- }
- }
- @EventHandler
- public void onPlayerLeave(PlayerQuitEvent event){
- int sign = Files.getCustomConfig(this).getInt("signnumber") + 1;
- for(int currentSign = 1; currentSign<sign; currentSign++)
- {
- int x = Files.getCustomConfig(this).getInt("signs." + currentSign + ".x");
- int y = Files.getCustomConfig(this).getInt("signs." + currentSign + ".y");
- int z = Files.getCustomConfig(this).getInt("signs." + currentSign + ".z");
- String world1 = Files.getCustomConfig(this).getString("signs." + currentSign + ".world");
- String worldname = Files.getCustomConfig(this).getString("signs." + currentSign + ".worldb");
- Block block = Bukkit.getWorld(world1).getBlockAt(x, y, z);
- block.getChunk().load();
- BlockState state = block.getState();
- int PlayersOnline = Bukkit.getWorld(worldname).getPlayers().size();
- String players = null;
- if(worldname.equals(state.getWorld().getName())){
- players = Integer.toString(PlayersOnline - 1);
- }else{
- players = Integer.toString(PlayersOnline);
- }
- if (state instanceof Sign){
- Sign s = (Sign) state;
- s.setLine(2, "Players: " + players);
- s.update(true);
- }
- }
- }
- @EventHandler
- public void onPlayerJoin(PlayerJoinEvent event){
- int sign = Files.getCustomConfig(this).getInt("signnumber") + 1;
- for(int currentSign = 1; currentSign<sign; currentSign++)
- {
- int x = Files.getCustomConfig(this).getInt("signs." + currentSign + ".x");
- int y = Files.getCustomConfig(this).getInt("signs." + currentSign + ".y");
- int z = Files.getCustomConfig(this).getInt("signs." + currentSign + ".z");
- String world1 = Files.getCustomConfig(this).getString("signs." + currentSign + ".world");
- String worldname = Files.getCustomConfig(this).getString("signs." + currentSign + ".worldb");
- Block block = Bukkit.getWorld(world1).getBlockAt(x, y, z);
- block.getChunk().load();
- BlockState state = block.getState();
- int PlayersOnline = Bukkit.getWorld(worldname).getPlayers().size();
- String players = null;
- if(worldname.equals(state.getWorld().getName())){
- players = Integer.toString(PlayersOnline + 1);
- }else{
- players = Integer.toString(PlayersOnline);
- }
- if (state instanceof Sign){
- Sign s = (Sign) state;
- s.setLine(2, "Players: " + players);
- s.update(true);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement