Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*** Eclipse Class Decompiler plugin, copyright (c) 2016 Chen Chao (cnfree2000@hotmail.com) ***/
- package me.robifoxx.block;
- import java.io.File;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.List;
- import me.robifoxx.block.Config;
- import me.robifoxx.block.MySQL;
- import me.robifoxx.block.SQLPlayer;
- import org.bukkit.Bukkit;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.Action;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.event.player.PlayerJoinEvent;
- import org.bukkit.event.player.PlayerQuitEvent;
- import org.bukkit.inventory.EquipmentSlot;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.scheduler.BukkitScheduler;
- public class Main extends JavaPlugin implements Listener {
- public static MySQL mysql;
- ArrayList<String> inEdit = new ArrayList<String>();
- HashMap<String, List<String>> blocksss = new HashMap();
- HashMap<String, String> saved_x = new HashMap<String, String>();
- HashMap<String, String> saved_y = new HashMap<String, String>();
- HashMap<String, String> saved_z = new HashMap<String, String>();
- HashMap<String, String> saved_world = new HashMap<String, String>();
- public Config data;
- boolean useMysql = false;
- boolean unsafeSave = true;
- public void onEnable() {
- if (!(new File("plugins/BlockQuest/config.yml")).exists()) {
- this.getConfig().options().copyDefaults(true);
- this.saveConfig();
- }
- Config c = new Config("plugins/BlockQuest", "data.yml");
- c.create();
- c.setDefault("data.yml");
- if (!c.exists()) {
- c.getConfig().options().copyDefaults(true);
- c.saveConfig();
- }
- this.data = c;
- if (this.getConfig().getString("use-mysql").equalsIgnoreCase("true")) {
- mysql = new MySQL(this.getConfig().getString("mysql-host"), this
- .getConfig().getString("mysql-database"), this.getConfig()
- .getString("mysql-username"), this.getConfig().getString(
- "mysql-password"));
- mysql.update("CREATE TABLE IF NOT EXISTS Games (UUID varchar(128), X varchar(2048) default \"none\", Y varchar(2048) default \"none\", Z varchar(2048) default \"none\", WORLD varchar(2048) default \"none\")");
- this.useMysql = true;
- }
- Bukkit.getPluginManager().registerEvents(this, this);
- if (this.getConfig().getString("mysql-unsafe-save") != null
- && this.getConfig().getString("mysql-unsafe-save")
- .equalsIgnoreCase("false")) {
- this.unsafeSave = false;
- }
- }
- public void onDisable() {
- Iterator<?> arg0 = Bukkit.getOnlinePlayers().iterator();
- while (arg0.hasNext()) {
- Player pl = (Player) arg0.next();
- if (this.useMysql) {
- SQLPlayer.setString(pl.getUniqueId().toString(), "X",
- (String) this.saved_x.get(pl.getName()));
- SQLPlayer.setString(pl.getUniqueId().toString(), "Y",
- (String) this.saved_y.get(pl.getName()));
- SQLPlayer.setString(pl.getUniqueId().toString(), "Z",
- (String) this.saved_z.get(pl.getName()));
- SQLPlayer.setString(pl.getUniqueId().toString(), "WORLD",
- (String) this.saved_world.get(pl.getName()));
- } else {
- this.data.getConfig().set(
- "data." + pl.getUniqueId().toString() + ".x",
- this.saved_x.get(pl.getName()));
- this.data.getConfig().set(
- "data." + pl.getUniqueId().toString() + ".y",
- this.saved_y.get(pl.getName()));
- this.data.getConfig().set(
- "data." + pl.getUniqueId().toString() + ".z",
- this.saved_z.get(pl.getName()));
- this.data.getConfig().set(
- "data." + pl.getUniqueId().toString() + ".world",
- this.saved_world.get(pl.getName()));
- this.data.saveConfig();
- }
- }
- }
- public boolean onCommand(CommandSender sender, Command cmd, String label,
- String[] args) {
- if (cmd.getName().equalsIgnoreCase("blockquest")) {
- if (!sender.hasPermission("blockquest.command")) {
- sender.sendMessage(this.getConfig().getString("no-permission")
- .replace("&", "§"));
- return true;
- }
- if (args.length < 1) {
- if (this.inEdit.remove(sender.getName())) {
- sender.sendMessage("§cYou disabled edit mode.");
- } else {
- sender.sendMessage("§aYou entered edit mode!");
- sender.sendMessage("§aClick on blocks to add it to the config file!");
- sender.sendMessage("§aType §6/blockquest §ato exit edit mode.");
- sender.sendMessage("§a§lType §6§l/blockquest reload §a§lto reload the config!");
- this.inEdit.add(sender.getName());
- }
- } else if (args[0].equalsIgnoreCase("reload")) {
- this.reloadConfig();
- sender.sendMessage("§aConfigr reloaded!");
- }
- }
- return true;
- }
- @EventHandler
- public void join(PlayerJoinEvent e) {
- if (this.data.getConfig().get(
- "data." + e.getPlayer().getUniqueId().toString() + ".x") == null) {
- this.data.getConfig().set(
- "data." + e.getPlayer().getUniqueId().toString() + ".x",
- "none");
- this.data.getConfig().set(
- "data." + e.getPlayer().getUniqueId().toString() + ".y",
- "none");
- this.data.getConfig().set(
- "data." + e.getPlayer().getUniqueId().toString() + ".z",
- "none");
- this.data.getConfig()
- .set("data." + e.getPlayer().getUniqueId().toString()
- + ".world", "none");
- if (!this.data.getConfig().contains(
- "data." + e.getPlayer().getUniqueId() + ".finished")) {
- this.data.getConfig().set("data." + e.getPlayer().getUniqueId() + ".finished", false);
- }
- this.data.saveConfig();
- }
- if (this.blocksss.get(e.getPlayer().getName()) == null) {
- String x;
- String y;
- String z;
- String world;
- if (this.saved_x.get(e.getPlayer().getName()) != null) {
- x = (String) this.saved_x.get(e.getPlayer().getName());
- y = (String) this.saved_z.get(e.getPlayer().getName());
- z = (String) this.saved_y.get(e.getPlayer().getName());
- world = (String) this.saved_world.get(e.getPlayer().getName());
- } else if (this.useMysql) {
- x = SQLPlayer.getString(e.getPlayer().getUniqueId().toString(),
- "X");
- y = SQLPlayer.getString(e.getPlayer().getUniqueId().toString(),
- "Y");
- z = SQLPlayer.getString(e.getPlayer().getUniqueId().toString(),
- "Z");
- world = SQLPlayer.getString(e.getPlayer().getUniqueId()
- .toString(), "WORLD");
- } else {
- x = this.data.getConfig()
- .getString(
- "data."
- + e.getPlayer().getUniqueId()
- .toString() + ".x");
- y = this.data.getConfig()
- .getString(
- "data."
- + e.getPlayer().getUniqueId()
- .toString() + ".y");
- z = this.data.getConfig()
- .getString(
- "data."
- + e.getPlayer().getUniqueId()
- .toString() + ".z");
- world = this.data.getConfig().getString(
- "data." + e.getPlayer().getUniqueId().toString()
- + ".world");
- }
- this.saved_x.put(e.getPlayer().getName(), x);
- this.saved_y.put(e.getPlayer().getName(), y);
- this.saved_z.put(e.getPlayer().getName(), z);
- this.saved_world.put(e.getPlayer().getName(), world);
- String[] x_splt = x.split(";");
- String[] y_splt = y.split(";");
- String[] z_splt = z.split(";");
- String[] world_splt = world.split(";");
- int loc = 0;
- ArrayList lst = new ArrayList<>();
- String[] arg11 = x_splt;
- int arg12 = x_splt.length;
- for (int arg13 = 0; arg13 < arg12; ++arg13) {
- String s = arg11[arg13];
- if (!s.equalsIgnoreCase("none")) {
- lst.add(x_splt[loc] + ";" + y_splt[loc] + ";" + z_splt[loc]
- + ";" + world_splt[loc]);
- }
- ++loc;
- }
- this.blocksss.put(e.getPlayer().getName(), lst);
- }
- }
- @EventHandler
- public void leave(PlayerQuitEvent e) {
- if (this.useMysql) {
- SQLPlayer.setString(e.getPlayer().getUniqueId().toString(), "X",
- (String) this.saved_x.get(e.getPlayer().getName()));
- SQLPlayer.setString(e.getPlayer().getUniqueId().toString(), "Y",
- (String) this.saved_y.get(e.getPlayer().getName()));
- SQLPlayer.setString(e.getPlayer().getUniqueId().toString(), "Z",
- (String) this.saved_z.get(e.getPlayer().getName()));
- SQLPlayer.setString(e.getPlayer().getUniqueId().toString(),
- "WORLD",
- (String) this.saved_world.get(e.getPlayer().getName()));
- } else {
- this.data.getConfig().set(
- "data." + e.getPlayer().getUniqueId().toString() + ".x",
- this.saved_x.get(e.getPlayer().getName()));
- this.data.getConfig().set(
- "data." + e.getPlayer().getUniqueId().toString() + ".y",
- this.saved_y.get(e.getPlayer().getName()));
- this.data.getConfig().set(
- "data." + e.getPlayer().getUniqueId().toString() + ".z",
- this.saved_z.get(e.getPlayer().getName()));
- this.data.getConfig()
- .set("data." + e.getPlayer().getUniqueId().toString()
- + ".world",
- this.saved_world.get(e.getPlayer().getName()));
- this.data.saveConfig();
- }
- }
- @EventHandler
- public void click(final PlayerInteractEvent e) {
- if (e.getHand() != EquipmentSlot.OFF_HAND) {
- if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
- List<String> blocks = this.getConfig().getStringList("blocks");
- String block = e.getClickedBlock().getLocation().getBlockX()
- + ";"
- + e.getClickedBlock().getLocation().getBlockY()
- + ";"
- + e.getClickedBlock().getLocation().getBlockZ()
- + ";"
- + e.getClickedBlock().getLocation().getWorld()
- .getName();
- if (this.inEdit.contains(e.getPlayer().getName())) {
- if (blocks.contains(block)) {
- e.getPlayer().sendMessage("§cRemoved this block!");
- blocks.remove(block);
- this.getConfig().set("blocks", blocks);
- this.saveConfig();
- } else {
- e.getPlayer().sendMessage("§aAdded this block!");
- blocks.add(block);
- this.getConfig().set("blocks", blocks);
- this.saveConfig();
- }
- } else if (this.getConfig().getStringList("blocks")
- .contains(block)) {
- String s;
- int blocksLeft;
- Iterator<?> lst1;
- if (this.blocksss.get(e.getPlayer().getName()) != null
- && ((List<?>) this.blocksss.get(e.getPlayer()
- .getName())).contains(block)) {
- if (((List<?>) this.blocksss.get(e.getPlayer().getName()))
- .contains(block)) {
- lst1 = this.getConfig()
- .getStringList("already-found-commands")
- .iterator();
- while (lst1.hasNext()) {
- s = (String) lst1.next();
- blocksLeft = this.getConfig()
- .getStringList("blocks").size()
- - ((List<?>) this.blocksss.get(e
- .getPlayer().getName())).size();
- Bukkit.dispatchCommand(
- Bukkit.getConsoleSender(),
- s.replace("%player%",
- e.getPlayer().getName())
- .replace(
- "%pLocX%",
- ""
- + e.getPlayer()
- .getLocation()
- .getX())
- .replace(
- "%pLocY%",
- ""
- + e.getPlayer()
- .getLocation()
- .getY())
- .replace(
- "%pLocZ%",
- ""
- + e.getPlayer()
- .getLocation()
- .getZ())
- .replace(
- "%locX5%",
- ""
- + (e.getClickedBlock()
- .getLocation()
- .getX() + 0.5D))
- .replace(
- "%locY5%",
- ""
- + (e.getClickedBlock()
- .getLocation()
- .getY() + 0.5D))
- .replace(
- "%locZ5%",
- ""
- + (e.getClickedBlock()
- .getLocation()
- .getZ() + 0.5D))
- .replace(
- "%locX%",
- ""
- + e.getClickedBlock()
- .getLocation()
- .getX())
- .replace(
- "%locY%",
- ""
- + e.getClickedBlock()
- .getLocation()
- .getY())
- .replace(
- "%locZ%",
- ""
- + e.getClickedBlock()
- .getLocation()
- .getZ())
- .replace("%blockLeft%",
- "" + blocksLeft)
- .replace("%blocksLeft%",
- "" + blocksLeft));
- }
- }
- } else {
- this.saved_x.put(
- e.getPlayer().getName(),
- (String) this.saved_x.get(e.getPlayer()
- .getName())
- + ";"
- + e.getClickedBlock().getLocation()
- .getBlockX());
- this.saved_y.put(
- e.getPlayer().getName(),
- (String) this.saved_y.get(e.getPlayer()
- .getName())
- + ";"
- + e.getClickedBlock().getLocation()
- .getBlockY());
- this.saved_z.put(
- e.getPlayer().getName(),
- (String) this.saved_z.get(e.getPlayer()
- .getName())
- + ";"
- + e.getClickedBlock().getLocation()
- .getBlockZ());
- this.saved_world.put(
- e.getPlayer().getName(),
- (String) this.saved_world.get(e.getPlayer()
- .getName())
- + ";"
- + e.getClickedBlock().getLocation()
- .getWorld().getName());
- if (this.blocksss.get(e.getPlayer().getName()) == null) {
- ArrayList<String> lst = new ArrayList<String>();
- lst.add(block);
- this.blocksss.put(e.getPlayer().getName(), lst);
- } else {
- ((List<String>) this.blocksss.get(e.getPlayer().getName()))
- .add(block);
- }
- if (this.useMysql) {
- if (!this.unsafeSave) {
- SQLPlayer.setString(e.getPlayer().getUniqueId()
- .toString(), "X", (String) this.saved_x
- .get(e.getPlayer().getName()));
- SQLPlayer.setString(e.getPlayer().getUniqueId()
- .toString(), "Y", (String) this.saved_y
- .get(e.getPlayer().getName()));
- SQLPlayer.setString(e.getPlayer().getUniqueId()
- .toString(), "Z", (String) this.saved_z
- .get(e.getPlayer().getName()));
- SQLPlayer.setString(e.getPlayer().getUniqueId()
- .toString(), "WORLD",
- (String) this.saved_world.get(e
- .getPlayer().getName()));
- }
- } else {
- this.data.getConfig().set(
- "data."
- + e.getPlayer().getUniqueId()
- .toString() + ".x",
- this.saved_x.get(e.getPlayer().getName()));
- this.data.getConfig().set(
- "data."
- + e.getPlayer().getUniqueId()
- .toString() + ".y",
- this.saved_y.get(e.getPlayer().getName()));
- this.data.getConfig().set(
- "data."
- + e.getPlayer().getUniqueId()
- .toString() + ".z",
- this.saved_z.get(e.getPlayer().getName()));
- this.data.getConfig().set(
- "data."
- + e.getPlayer().getUniqueId()
- .toString() + ".world",
- this.saved_world.get(e.getPlayer()
- .getName()));
- this.data.saveConfig();
- }
- lst1 = this.getConfig()
- .getStringList("find-block-commands")
- .iterator();
- while (lst1.hasNext()) {
- s = (String) lst1.next();
- blocksLeft = this.getConfig()
- .getStringList("blocks").size()
- - ((List<?>) this.blocksss.get(e.getPlayer()
- .getName())).size();
- Bukkit.dispatchCommand(
- Bukkit.getConsoleSender(),
- s.replace("%player%",
- e.getPlayer().getName())
- .replace(
- "%pLocX%",
- ""
- + e.getPlayer()
- .getLocation()
- .getX())
- .replace(
- "%pLocY%",
- ""
- + e.getPlayer()
- .getLocation()
- .getY())
- .replace(
- "%pLocZ%",
- ""
- + e.getPlayer()
- .getLocation()
- .getZ())
- .replace(
- "%locX5%",
- ""
- + (e.getClickedBlock()
- .getLocation()
- .getX() + 0.5D))
- .replace(
- "%locY5%",
- ""
- + (e.getClickedBlock()
- .getLocation()
- .getY() + 0.5D))
- .replace(
- "%locZ5%",
- ""
- + (e.getClickedBlock()
- .getLocation()
- .getZ() + 0.5D))
- .replace(
- "%locX%",
- ""
- + e.getClickedBlock()
- .getLocation()
- .getX())
- .replace(
- "%locY%",
- ""
- + e.getClickedBlock()
- .getLocation()
- .getY())
- .replace(
- "%locZ%",
- ""
- + e.getClickedBlock()
- .getLocation()
- .getZ())
- .replace("%blockLeft%",
- "" + blocksLeft)
- .replace("%blocksLeft%",
- "" + blocksLeft));
- }
- if (((List<?>) this.blocksss.get(e.getPlayer().getName()))
- .size() >= this.getConfig()
- .getStringList("blocks").size()) {
- lst1 = this.getConfig()
- .getStringList("all-blocks-found-commands")
- .iterator();
- while (lst1.hasNext()) {
- s = (String) lst1.next();
- blocksLeft = this.getConfig()
- .getStringList("blocks").size()
- - ((List<?>) this.blocksss.get(e
- .getPlayer().getName())).size();
- if ((blocksLeft == 0) && (this.data.getConfig().getBoolean("data." + e.getPlayer().getUniqueId() + ".finished") != true)) {
- Bukkit.dispatchCommand(
- Bukkit.getConsoleSender(),
- s.replace("%player%",
- e.getPlayer().getName())
- .replace(
- "%pLocX%",
- ""
- + e.getPlayer()
- .getLocation()
- .getX())
- .replace(
- "%pLocY%",
- ""
- + e.getPlayer()
- .getLocation()
- .getY())
- .replace(
- "%pLocZ%",
- ""
- + e.getPlayer()
- .getLocation()
- .getZ())
- .replace(
- "%locX5%",
- ""
- + (e.getClickedBlock()
- .getLocation()
- .getX() + 0.5D))
- .replace(
- "%locY5%",
- ""
- + (e.getClickedBlock()
- .getLocation()
- .getY() + 0.5D))
- .replace(
- "%locZ5%",
- ""
- + (e.getClickedBlock()
- .getLocation()
- .getZ() + 0.5D))
- .replace(
- "%locX%",
- ""
- + e.getClickedBlock()
- .getLocation()
- .getX())
- .replace(
- "%locY%",
- ""
- + e.getClickedBlock()
- .getLocation()
- .getY())
- .replace(
- "%locZ%",
- ""
- + e.getClickedBlock()
- .getLocation()
- .getZ())
- .replace("%blockLeft%",
- "" + blocksLeft)
- .replace("%blocksLeft%",
- "" + blocksLeft));
- this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
- private Config data;
- public void run() {
- this.data.getConfig().set("data." + e.getPlayer().getUniqueId() + ".finsihed", true);
- }
- }, 40L);
- }
- }
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement