Skip to content

Commit

Permalink
Umstieg auf UUIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
ThexXTURBOXx committed Aug 10, 2016
1 parent bcaf9d1 commit 54ba24f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
14 changes: 6 additions & 8 deletions src/de/thexxturboxx/autonick/AutoNick.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collection;

import org.bukkit.BanList.Type;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -75,17 +74,16 @@ public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
public void run() {
Collection<? extends Player> pc = getServer().getOnlinePlayers();
for(Player p : pc) {
for(Player p : getServer().getOnlinePlayers()) {
if(p.hasPermission("nick.cmd.nick")) {
try {
Statement s = c.createStatement();
ResultSet res = s.executeQuery("SELECT * FROM " + TABLE + " WHERE UUID = '" + p.getName() + "';");
ResultSet res = s.executeQuery("SELECT * FROM " + TABLE + " WHERE UUID = '" + p.getUniqueId().toString() + "';");
int nicked = 0;
if(res.next())
nicked = res.getInt("nicked");
else
s.executeUpdate("INSERT INTO " + TABLE + " (UUID, nicked, name) VALUES ('" + p.getName() + "','0','');");
s.executeUpdate("INSERT INTO " + TABLE + " (UUID, nicked, name) VALUES ('" + p.getUniqueId().toString() + "','0','');");
if(nicked == 2) {
String name = res.getString("name");
p.getInventory().setItem(8, getAutoNickItem(name));
Expand Down Expand Up @@ -147,19 +145,19 @@ public void nickSwitch(PlayerInteractEvent e) {
if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
try {
Statement s = c.createStatement();
ResultSet res = s.executeQuery("SELECT * FROM " + TABLE + " WHERE UUID = '" + e.getPlayer().getName() + "';");
ResultSet res = s.executeQuery("SELECT * FROM " + TABLE + " WHERE UUID = '" + e.getPlayer().getUniqueId().toString() + "';");
String name = null;
if(res.next()) {
name = res.getString("name");
}
if(e.getPlayer().getItemInHand().isSimilar(getAutoNickItem(true)) ||
(name != null && e.getPlayer().getItemInHand().isSimilar(getAutoNickItem(name)))) {
e.getPlayer().getInventory().setItem(8, getAutoNickItem(false));
s.executeUpdate("UPDATE " + TABLE + " SET nicked = '0' WHERE UUID = '" + e.getPlayer().getName() + "'");
s.executeUpdate("UPDATE " + TABLE + " SET nicked = '0' WHERE UUID = '" + e.getPlayer().getUniqueId().toString() + "'");
e.getPlayer().sendMessage(getPrefix() + "§4AutoNick wurde §cdeaktiviert");
} else if(e.getPlayer().getItemInHand().isSimilar(getAutoNickItem(false))) {
e.getPlayer().getInventory().setItem(8, getAutoNickItem(true));
s.executeUpdate("UPDATE " + TABLE + " SET nicked = '1' WHERE UUID = '" + e.getPlayer().getName() + "'");
s.executeUpdate("UPDATE " + TABLE + " SET nicked = '1' WHERE UUID = '" + e.getPlayer().getUniqueId().toString() + "'");
e.getPlayer().sendMessage(getPrefix() + "§4AutoNick wurde §aaktiviert");
}
} catch (SQLException e1) {
Expand Down
4 changes: 2 additions & 2 deletions src/de/thexxturboxx/autonick/NickCmdExec.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if(p.hasPermission("nick.cmd.nick")) {
if(args.length == 1) {
try {
s.executeUpdate("UPDATE " + AutoNick.TABLE + " SET nicked = '2' WHERE UUID = '" + p.getName() + "'");
s.executeUpdate("UPDATE " + AutoNick.TABLE + " SET name = '" + args[0] + "' WHERE UUID = '" + p.getName() + "'");
s.executeUpdate("UPDATE " + AutoNick.TABLE + " SET nicked = '2' WHERE UUID = '" + p.getUniqueId().toString() + "'");
s.executeUpdate("UPDATE " + AutoNick.TABLE + " SET name = '" + args[0] + "' WHERE UUID = '" + p.getUniqueId().toString() + "'");
p.sendMessage(AutoNick.getPrefix() + ChatColor.DARK_RED + "Du wirst als " + ChatColor.GOLD + args[0] + ChatColor.DARK_RED + " spielen!");
} catch (SQLException e) {
e.printStackTrace();
Expand Down

0 comments on commit 54ba24f

Please sign in to comment.