Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package spielplatz.tuhlienn.spielplatzachievements;
- import java.io.File;
- import java.io.PrintStream;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.text.DecimalFormat;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.Set;
- import java.util.UUID;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.Server;
- import org.bukkit.Sound;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- import org.bukkit.command.PluginCommand;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.YamlConfiguration;
- 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.block.BlockBreakEvent;
- import org.bukkit.event.inventory.InventoryClickEvent;
- import org.bukkit.event.inventory.InventoryCloseEvent;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.inventory.EquipmentSlot;
- import org.bukkit.inventory.Inventory;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.PlayerInventory;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.scheduler.BukkitScheduler;
- public class SpielplatzAchievements
- extends JavaPlugin
- implements Listener
- {
- File configFile;
- FileConfiguration config;
- public MySQLConnection mysql;
- ResultSet rs;
- Connection con;
- boolean connected = true;
- public ChatColor farbe = ChatColor.DARK_AQUA;
- private String saHelp = this.farbe + "-----�f[" + this.farbe + "SpielplatzAchievements�f]" + this.farbe + "----- \n" +
- this.farbe + "/sa add <1> <2>�r: Erstellt ein Achievement mit einem Wert " + this.farbe + "<1>�r und einem Namen " + this.farbe + "<2>�r an der aktuellen Position \n" +
- this.farbe + "/sa modify <1> <2> <3>�r: Weist dem Achievement mit der ID " + this.farbe + "<1>�r einen neuen Wert " + this.farbe + "<2>�r und einen neuen Namen " + this.farbe + "<3>�r zu \n" +
- this.farbe + "/sa info [achievement|stats]�r: Zeigt erweiterte Informationen an \n" +
- this.farbe + "/sa remove <1>�r: Entfernt das Achievement mit ID " + this.farbe + "<1> \n" +
- this.farbe + "/sa list (<1>)�r: Zeigt die Seite " + this.farbe + "<1>�r aller bestehenden Achievements an \n" +
- this.farbe + "/sa tp <1>�r: Teleport den Spieler zum Achievement mit ID " + this.farbe + "<1> \n" +
- this.farbe + "/sa set <1>�r: Setzt die Position des Achievements mit ID " + this.farbe + "<1>�r an die aktuelle Position \n" +
- this.farbe + "/sa activate <1>�r: Aktiviert/Deaktiviert das Achievement mit der ID " + this.farbe + "<1>";
- private int size = 9;
- private int updatecycle = 12000;
- private String reward = "";
- private ItemStack pot = new ItemStack(Material.FLOWER_POT_ITEM);
- private ItemMeta potmeta = this.pot.getItemMeta();
- private ItemStack flower = new ItemStack(Material.DOUBLE_PLANT);
- private ItemMeta flowermeta = this.flower.getItemMeta();
- private HashMap<Player, Integer> inMenu = new HashMap();
- private HashMap<Integer, String> achievementNames = new HashMap();
- private HashMap<Integer, Integer> achievementValues = new HashMap();
- private HashMap<Integer, Location> achievementLocations = new HashMap();
- private HashMap<Integer, Boolean> achievementActive = new HashMap();
- private HashMap<UUID, ArrayList<Integer>> players = new HashMap();
- int timer = 0;
- Runnable run = new Runnable()
- {
- public void run()
- {
- if (SpielplatzAchievements.this.connected) {
- SpielplatzAchievements.this.writeToDataBase();
- }
- }
- };
- public void onEnable()
- {
- getServer().getPluginManager().registerEvents(this, this);
- this.configFile = new File(getDataFolder(), "config.yml");
- this.config = YamlConfiguration.loadConfiguration(this.configFile);
- saveDefaultConfig();
- this.size = getConfig().getInt("general.size");
- this.updatecycle = getConfig().getInt("general.updatecycle");
- this.reward = getConfig().getString("general.reward");
- String hostname = getConfig().getString("MySQL.hostname");
- String hostport = getConfig().getString("MySQL.hostport");
- String database = getConfig().getString("MySQL.database");
- String user = getConfig().getString("MySQL.user");
- String password = getConfig().getString("MySQL.password");
- this.mysql = new MySQLConnection(hostname, hostport, database, user, password);
- try
- {
- this.mysql.open();
- this.mysql.createTables();
- this.mysql.close();
- }
- catch (Exception e)
- {
- this.connected = false;
- }
- if (this.connected)
- {
- loadFromDataBase();
- System.out.println("[SpielplatzAchievements] Connected to MySQL");
- this.timer = Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this.run, 0L, this.updatecycle);
- }
- registerCommand();
- }
- public void onDisable()
- {
- if (this.connected)
- {
- writeToDataBase();
- Bukkit.getScheduler().cancelTask(this.timer);
- }
- }
- public void registerCommand()
- {
- Command_sa cmd_sa = new Command_sa(this);
- getCommand("sa").setExecutor(cmd_sa);
- Command_erfolge cmd_erfolge = new Command_erfolge(this);
- getCommand("erfolge").setExecutor(cmd_erfolge);
- }
- @EventHandler
- public void onPlayerClick(PlayerInteractEvent event)
- {
- Player p = event.getPlayer();
- if (p.hasPermission("sa.erfolge")) {
- if ((event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) &&
- (event.getHand().equals(EquipmentSlot.HAND))) {
- if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK))
- {
- Location clicked = event.getClickedBlock().getLocation();
- for (Integer id : this.achievementNames.keySet()) {
- if (((Location)this.achievementLocations.get(id)).equals(clicked)) {
- if (((Boolean)this.achievementActive.get(id)).booleanValue())
- {
- UUID uuid = p.getUniqueId();
- String name = (String)this.achievementNames.get(id);
- int value = ((Integer)this.achievementValues.get(id)).intValue();
- if (this.players.containsKey(uuid)) {
- for (Integer test : (ArrayList)this.players.get(uuid)) {
- if (id == test)
- {
- p.sendMessage("�f[" + this.farbe + "SpielplatzAchievements�f] Du hast das Achievement " + this.farbe + id + ": " + name + "�r bereits gefunden!");
- return;
- }
- }
- }
- putAchievementToPlayer(uuid, id.intValue());
- if (this.reward.equals("diamond"))
- {
- p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.DIAMOND, value) });
- p.sendMessage("�f[" + this.farbe + "SpielplatzAchievements�f] Du hast das Achievement " + this.farbe + id + ": " + name + "�r gefunden und " + this.farbe + value + "�r Diamanten erhalten!");
- }
- else if (this.reward.equals("votepoint"))
- {
- Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "svp add " + p.getName() + " " + value);
- p.sendMessage("�f[" + this.farbe + "SpielplatzAchievements�f] Du hast das Achievement " + this.farbe + id + ": " + name + "�r gefunden und " + this.farbe + value + "�r Votepunkte erhalten!");
- }
- else
- {
- p.sendMessage("�f[" + this.farbe + "SpielplatzAchievements�f] Du hast das Achievement " + this.farbe + id + ": " + name + "�r gefunden!");
- }
- p.playSound(clicked, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0F, 0.0F);
- event.setCancelled(true);
- }
- }
- }
- }
- }
- }
- }
- @EventHandler
- public void onBlockBreak(BlockBreakEvent event)
- {
- Player p = event.getPlayer();
- Location broken = event.getBlock().getLocation();
- ArrayList<Integer> toRemove = new ArrayList();
- for (Integer id : this.achievementNames.keySet()) {
- if (((Location)this.achievementLocations.get(id)).equals(broken)) {
- toRemove.add(id);
- }
- }
- if (!toRemove.isEmpty()) {
- if (p.hasPermission("sa.op"))
- {
- for (Integer id : toRemove) {
- removeAchievement(p, id.intValue());
- }
- updateIDs();
- }
- else
- {
- p.sendMessage("�f[" + this.farbe + "SpielplatzAchievements�f] �cDu kannst keine Achievements zerst�ren!");
- event.setCancelled(true);
- }
- }
- }
- @EventHandler
- public void onInventoryClick(InventoryClickEvent event)
- {
- Player p = (Player)event.getWhoClicked();
- if (this.inMenu.containsKey(p))
- {
- int page = ((Integer)this.inMenu.get(p)).intValue();
- int clicked = event.getSlot();
- if ((clicked == 0) && (page != 1))
- {
- showAchievementPage(page - 1, p, p);
- event.setCancelled(true);
- }
- else if ((clicked == 8) && (page != 6))
- {
- showAchievementPage(page + 1, p, p);
- event.setCancelled(true);
- }
- else
- {
- event.setCancelled(true);
- }
- }
- }
- @EventHandler
- public void onInventoryClose(InventoryCloseEvent event)
- {
- Player p = (Player)event.getPlayer();
- if (this.inMenu.containsKey(p)) {
- this.inMenu.remove(p);
- }
- }
- public void lockPlayer(Player p)
- {
- this.inMenu.put(p, Integer.valueOf(1));
- }
- public int getPage(Player p)
- {
- return ((Integer)this.inMenu.get(p)).intValue();
- }
- public int getNextID()
- {
- if (this.achievementNames.isEmpty()) {
- return 0;
- }
- int max = 0;
- for (Integer id : this.achievementNames.keySet()) {
- max = id.intValue() > max ? id.intValue() : max;
- }
- return max + 1;
- }
- public void updateIDs()
- {
- HashMap<Integer, String> newAchievementNames = new HashMap();
- HashMap<Integer, Integer> newAchievementValues = new HashMap();
- HashMap<Integer, Location> newAchievementLocations = new HashMap();
- HashMap<Integer, Boolean> newAchievementActive = new HashMap();
- HashMap<UUID, ArrayList<Integer>> newPlayers = new HashMap();
- int counter = 0;
- for (Integer id : this.achievementNames.keySet())
- {
- newAchievementNames.put(Integer.valueOf(counter), (String)this.achievementNames.get(id));
- newAchievementValues.put(Integer.valueOf(counter), (Integer)this.achievementValues.get(id));
- newAchievementLocations.put(Integer.valueOf(counter), (Location)this.achievementLocations.get(id));
- newAchievementActive.put(Integer.valueOf(counter), (Boolean)this.achievementActive.get(id));
- for (UUID uuid : this.players.keySet()) {
- if (((ArrayList)this.players.get(uuid)).contains(id)) {
- if (newPlayers.containsKey(uuid))
- {
- ArrayList<Integer> ids = (ArrayList)newPlayers.get(uuid);
- ids.add(Integer.valueOf(counter));
- newPlayers.remove(uuid);
- newPlayers.put(uuid, ids);
- }
- else
- {
- ArrayList<Integer> ids = new ArrayList();
- ids.add(Integer.valueOf(counter));
- newPlayers.put(uuid, ids);
- }
- }
- }
- counter++;
- }
- this.achievementNames = newAchievementNames;
- this.achievementValues = newAchievementValues;
- this.achievementLocations = newAchievementLocations;
- this.achievementActive = newAchievementActive;
- this.players = newPlayers;
- }
- public void showAchievementPage(int page, Player sender, Player shown)
- {
- int current = page;
- lockPlayer(sender);
- Inventory inv = Bukkit.createInventory(sender, this.size + 9, "Erfolge - Seite " + page);
- ItemStack glass = null;
- for (int index = 0; index < 9; index++)
- {
- if (index == 0)
- {
- if (current != 1)
- {
- glass = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)14);
- ItemMeta glassmeta = glass.getItemMeta();
- glassmeta.setDisplayName("�cZur�ck");
- glass.setItemMeta(glassmeta);
- }
- else
- {
- glass = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)0);
- }
- }
- else if (index == 8)
- {
- if (current != 6)
- {
- glass = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)5);
- ItemMeta glassmeta = glass.getItemMeta();
- glassmeta.setDisplayName("�aWeiter");
- glass.setItemMeta(glassmeta);
- }
- }
- else {
- glass = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)0);
- }
- inv.setItem(index, glass);
- }
- int i = 0;
- for (Integer id : this.achievementNames.keySet())
- {
- if ((i >= (current - 1) * this.size) && (i < current * this.size))
- {
- String name = (String)this.achievementNames.get(id);
- String world = ((Location)this.achievementLocations.get(id)).getWorld().getName();
- boolean hasAchievement = false;
- if ((this.players.containsKey(shown.getUniqueId())) &&
- (((ArrayList)this.players.get(shown.getUniqueId())).contains(id))) {
- hasAchievement = true;
- }
- if (hasAchievement)
- {
- this.flowermeta.setDisplayName("�a" + id + ": " + name);
- this.flowermeta.setLore(Arrays.asList(new String[] { "�f" + world }));
- this.flower.setItemMeta(this.flowermeta);
- inv.setItem(i % this.size + 9, this.flower);
- }
- else
- {
- this.potmeta.setDisplayName("�c" + id + ": " + name);
- this.potmeta.setLore(Arrays.asList(new String[] { "�f" + world }));
- this.pot.setItemMeta(this.potmeta);
- inv.setItem(i % this.size + 9, this.pot);
- }
- }
- i++;
- }
- sender.openInventory(inv);
- this.inMenu.put(sender, Integer.valueOf(current));
- }
- public void showListPage(int page, Player p)
- {
- int entries = 10;
- int min = (page - 1) * entries;
- int max = page * entries - 1;
- p.sendMessage("�f[" + this.farbe + "SpielplatzAchievements�f] Achievements (" + this.farbe + "Seite " + page + "�f):�r");
- for (Integer id : this.achievementNames.keySet()) {
- if ((id.intValue() >= min) && (id.intValue() <= max))
- {
- ChatColor color;
- ChatColor color;
- if (((Boolean)this.achievementActive.get(id)).booleanValue()) {
- color = ChatColor.GREEN;
- } else {
- color = ChatColor.RED;
- }
- p.sendMessage(color + id + "�f:" + color + (String)this.achievementNames.get(id));
- }
- }
- }
- public void addAchievement(Player p, int value, String name)
- {
- Location loc = p.getLocation().getBlock().getLocation();
- int id = getNextID();
- this.achievementNames.put(Integer.valueOf(id), name);
- this.achievementValues.put(Integer.valueOf(id), Integer.valueOf(value));
- this.achievementLocations.put(Integer.valueOf(id), loc);
- this.achievementActive.put(Integer.valueOf(id), Boolean.valueOf(true));
- p.sendMessage("�f[" + this.farbe + "SpielplatzAchievements�f] Das neue Achievement " + this.farbe + id + ": " + name + "�r mit dem Wert " + this.farbe + value + "�r wurde an der Position " + this.farbe + loc.getBlockX() + "�r, " + this.farbe + loc.getBlockY() + "�r, " + this.farbe + loc.getBlockZ() + "�r gesetzt!");
- }
- public void removeAchievement(Player p, int id)
- {
- if (this.achievementNames.containsKey(Integer.valueOf(id)))
- {
- this.achievementNames.remove(Integer.valueOf(id));
- this.achievementLocations.remove(Integer.valueOf(id));
- this.achievementValues.remove(Integer.valueOf(id));
- this.achievementActive.remove(Integer.valueOf(id));
- for (UUID uuid : this.players.keySet())
- {
- ArrayList<Integer> achievements = (ArrayList)this.players.get(uuid);
- if (achievements.contains(Integer.valueOf(id)))
- {
- achievements.remove(Integer.valueOf(id));
- this.players.replace(uuid, achievements);
- }
- }
- p.sendMessage("�f[" + this.farbe + "SpielplatzAchievements�f] Das Achievement mit der ID " + this.farbe + id + "�r wurde entfernt!");
- }
- else
- {
- p.sendMessage("�f[" + this.farbe + "SpielplatzAchievements�f] Ein Achievement mit der ID " + this.farbe + id + "�r existiert nicht!");
- }
- }
- public void setAchievement(Player p, int id)
- {
- if (this.achievementNames.containsKey(Integer.valueOf(id)))
- {
- Location loc = p.getLocation().getBlock().getLocation();
- this.achievementLocations.remove(Integer.valueOf(id));
- this.achievementLocations.put(Integer.valueOf(id), loc);
- p.sendMessage("�f[" + this.farbe + "SpielplatzAchievements�f] Das Achievement mit der ID " + this.farbe + id + "�r wurde auf die Position " + this.farbe + loc.getBlockX() + "�r, " + this.farbe + loc.getBlockY() + "�r, " + this.farbe + loc.getBlockZ() + "�r verschoben!");
- }
- else
- {
- p.sendMessage("�f[" + this.farbe + "SpielplatzAchievements�f] Ein Achievement mit der ID " + this.farbe + id + "�r existiert nicht!");
- }
- }
- public void activateAchievement(Player p, int id)
- {
- if (this.achievementNames.containsKey(Integer.valueOf(id)))
- {
- boolean activated = ((Boolean)this.achievementActive.get(Integer.valueOf(id))).booleanValue();
- this.achievementActive.remove(Integer.valueOf(id));
- this.achievementActive.put(Integer.valueOf(id), Boolean.valueOf(!activated));
- if (activated) {
- p.sendMessage("�f[" + this.farbe + "SpielplatzAchievements�f] Das Achievement mit der ID " + this.farbe + id + "�r wurde deaktiviert!");
- } else {
- p.sendMessage("�f[" + this.farbe + "SpielplatzAchievements�f] Das Achievement mit der ID " + this.farbe + id + "�r wurde aktiviert!");
- }
- }
- else
- {
- p.sendMessage("�f[" + this.farbe + "SpielplatzAchievements�f] �cEs existiert kein Achievement mit der ID " + this.farbe + id + "�c!");
- }
- }
- public void tpToAchievement(Player p, int id)
- {
- if (this.achievementNames.containsKey(Integer.valueOf(id)))
- {
- Location achievementLoc = (Location)this.achievementLocations.get(Integer.valueOf(id));
- Location newLoc = new Location(achievementLoc.getWorld(), achievementLoc.getX() + 0.5D, achievementLoc.getY() + 1.0D, achievementLoc.getZ() + 0.5D);
- p.teleport(newLoc);
- p.sendMessage("�f[" + this.farbe + "SpielplatzAchievements�f] Du wurdest zu dem Achievement " + this.farbe + id + ": " + (String)this.achievementNames.get(Integer.valueOf(id)) + "�r teleportiert!");
- }
- else
- {
- p.sendMessage("�f[" + this.farbe + "SpielplatzAchievements�f] �cEs existiert kein Achievement mit der ID " + this.farbe + id + "�c!");
- }
- }
- public void modifyAchievement(Player p, int id, int value, String name)
- {
- if (this.achievementNames.containsKey(Integer.valueOf(id)))
- {
- String newName = name.equals("0") ? (String)this.achievementNames.get(Integer.valueOf(id)) : name;
- int newValue = value == 0 ? ((Integer)this.achievementValues.get(Integer.valueOf(id))).intValue() : value;
- this.achievementNames.remove(Integer.valueOf(id));
- this.achievementNames.put(Integer.valueOf(id), newName);
- this.achievementValues.remove(Integer.valueOf(id));
- this.achievementValues.put(Integer.valueOf(id), Integer.valueOf(newValue));
- p.sendMessage("�f[" + this.farbe + "SpielplatzAchievements�f] Das Achievement mit der ID " + this.farbe + id + "�r tr�gt nun den Namen" + this.farbe + name + "�r und den Votepunkte-Wert " + this.farbe + value + "�r!");
- }
- else
- {
- p.sendMessage("�f[" + this.farbe + "SpielplatzAchievements�f] �cEs existiert kein Achievement mit der ID " + this.farbe + id + "�c!");
- }
- }
- public void getAchievementInfo(Player p, int id)
- {
- String name = (String)this.achievementNames.get(Integer.valueOf(id));
- int value = ((Integer)this.achievementValues.get(Integer.valueOf(id))).intValue();
- String world = ((Location)this.achievementLocations.get(Integer.valueOf(id))).getWorld().getName();
- String active = ((Boolean)this.achievementActive.get(Integer.valueOf(id))).booleanValue() ? "Ja" : "Nein";
- int count = 0;
- for (UUID uuid : this.players.keySet()) {
- if (((ArrayList)this.players.get(uuid)).contains(Integer.valueOf(id))) {
- count++;
- }
- }
- p.sendMessage(this.farbe + "-----�f[" + this.farbe + "Achievement " + id + "�f]" + this.farbe + "----- \n" +
- this.farbe + "Name�r: " + name + "\n" +
- this.farbe + "Votepunkte�r: " + value + "\n" +
- this.farbe + "Welt�r: " + world + " \n" +
- this.farbe + "Aktiv�r: " + active + "\n" +
- this.farbe + "Gesamtanzahl Funde�r: " + count);
- }
- public void getStats(Player p)
- {
- int count = 0;
- int totalValue = 0;
- double involvedPlayers = 0.0D;
- double totalFound = 0.0D;
- String average = "";
- DecimalFormat df = new DecimalFormat("#.##");
- for (Iterator localIterator1 = this.achievementNames.keySet().iterator(); localIterator1.hasNext();)
- {
- int id = ((Integer)localIterator1.next()).intValue();
- count++;
- totalValue += ((Integer)this.achievementValues.get(Integer.valueOf(id))).intValue();
- }
- Iterator localIterator2;
- for (localIterator1 = this.players.keySet().iterator(); localIterator1.hasNext(); localIterator2.hasNext())
- {
- UUID uuid = (UUID)localIterator1.next();
- involvedPlayers += 1.0D;
- localIterator2 = ((ArrayList)this.players.get(uuid)).iterator(); continue;int id = ((Integer)localIterator2.next()).intValue();
- totalFound += 1.0D;
- }
- average = average + (involvedPlayers == 0.0D ? "Nicht vorhanden!" : df.format(totalFound / involvedPlayers));
- p.sendMessage(this.farbe + "-----�f[" + this.farbe + "Statistiken�f]" + this.farbe + "----- \n" +
- this.farbe + "Anzahl an Achievements�r: " + count + "\n" +
- this.farbe + "Gesamtwert der Achievements�r: " + totalValue + "\n" +
- this.farbe + "Spieler mit mindestens einem Achievement�r: " + (int)involvedPlayers + " \n" +
- this.farbe + "Durchschnittlich gefundene Achievements�r: " + average);
- }
- public void loadFromDataBase()
- {
- this.achievementNames.clear();
- this.achievementLocations.clear();
- this.achievementValues.clear();
- this.achievementActive.clear();
- this.players.clear();
- try
- {
- this.mysql.open();
- this.con = this.mysql.getConnection();
- PreparedStatement achievements = this.con.prepareStatement("SELECT * FROM Achievements");
- this.rs = achievements.executeQuery();
- while (this.rs.next())
- {
- int id = this.rs.getInt("id");
- String name = this.rs.getString("name");
- Location loc = new Location(getServer().getWorld(this.rs.getString("world")), this.rs.getInt("x"), this.rs.getInt("y"), this.rs.getInt("z"));
- int value = this.rs.getInt("value");
- Boolean activated = Boolean.valueOf(this.rs.getBoolean("activated"));
- this.achievementNames.put(Integer.valueOf(id), name);
- this.achievementLocations.put(Integer.valueOf(id), loc);
- this.achievementValues.put(Integer.valueOf(id), Integer.valueOf(value));
- this.achievementActive.put(Integer.valueOf(id), activated);
- }
- PreparedStatement playerAchievements = this.con.prepareStatement("SELECT * FROM Players");
- this.rs = playerAchievements.executeQuery();
- while (this.rs.next())
- {
- UUID uuid = UUID.fromString(this.rs.getString("uuid"));
- int achievement = this.rs.getInt("achievement");
- putAchievementToPlayer(uuid, achievement);
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- public void writeToDataBase()
- {
- try
- {
- this.mysql.open();
- this.con = this.mysql.getConnection();
- PreparedStatement clear = this.con.prepareStatement("TRUNCATE TABLE Achievements");
- clear.executeUpdate();
- clear.close();
- PreparedStatement clear2 = this.con.prepareStatement("TRUNCATE TABLE Players");
- clear2.executeUpdate();
- clear2.close();
- for (Integer id : this.achievementNames.keySet())
- {
- PreparedStatement achievement = this.con.prepareStatement("INSERT INTO Achievements(id,name,world,x,y,z,value,activated) VALUES (?,?,?,?,?,?,?,?)");
- achievement.setInt(1, id.intValue());
- achievement.setString(2, (String)this.achievementNames.get(id));
- achievement.setString(3, ((Location)this.achievementLocations.get(id)).getWorld().getName());
- achievement.setDouble(4, ((Location)this.achievementLocations.get(id)).getX());
- achievement.setDouble(5, ((Location)this.achievementLocations.get(id)).getY());
- achievement.setDouble(6, ((Location)this.achievementLocations.get(id)).getZ());
- achievement.setInt(7, ((Integer)this.achievementValues.get(id)).intValue());
- achievement.setBoolean(8, ((Boolean)this.achievementActive.get(id)).booleanValue());
- achievement.executeUpdate();
- achievement.close();
- }
- Iterator localIterator2;
- for (??? = this.players.keySet().iterator(); ???.hasNext(); localIterator2.hasNext())
- {
- UUID uuid = (UUID)???.next();
- localIterator2 = ((ArrayList)this.players.get(uuid)).iterator(); continue;Integer achievement = (Integer)localIterator2.next();
- PreparedStatement player = this.con.prepareStatement("INSERT INTO Players(uuid,achievement) VALUES (?,?)");
- player.setString(1, uuid.toString());
- player.setInt(2, achievement.intValue());
- player.executeUpdate();
- player.close();
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- public void putAchievementToPlayer(UUID uuid, int id)
- {
- if (this.players.containsKey(uuid))
- {
- ArrayList<Integer> ids = (ArrayList)this.players.get(uuid);
- ids.add(Integer.valueOf(id));
- this.players.remove(uuid);
- this.players.put(uuid, ids);
- }
- else
- {
- ArrayList<Integer> ids = new ArrayList();
- ids.add(Integer.valueOf(id));
- this.players.put(uuid, ids);
- }
- }
- public String getSaHelp()
- {
- return this.saHelp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement