From d5065e3e9b80516756d297b01d8970bc14ee0b07 Mon Sep 17 00:00:00 2001 From: Gunther De Wachter Date: Sat, 3 Jan 2015 21:17:23 +0100 Subject: [PATCH] Lots of changes (and getting a full 1.8 spigot-compatible release ready) --- plugin.yml | 5 +- .../tweakcraft/Chat/Modes/AdminChat.java | 4 +- .../Commands/Commands/ChatCommands.java | 2 +- .../Commands/Commands/EssentialsCommands.java | 81 +++++++- .../Commands/Commands/GeneralCommands.java | 9 +- .../Commands/TeleportationCommands.java | 2 +- .../DataSources/Ban/BanHandler.java | 52 +++++- .../Listeners/TweakcraftPlayerListener.java | 30 ++- .../bukkit/tweakcraft/Packages/Ban.java | 19 ++ .../Packages/CraftIRCAdminEndPoint.java | 2 + .../tweakcraft/Packages/LocalPlayer.java | 13 ++ .../tweakcraft/Tools/PluginResolver.java | 25 +++ .../bukkit/tweakcraft/Tools/TamerTool.java | 174 ++++++++++-------- .../bukkit/tweakcraft/TweakcraftUtils.java | 30 ++- .../tweakcraft/Util/TweakTravelAgent.java | 4 +- .../bukkit/tweakcraft/Util/UUIDResolver.java | 78 ++++++++ 16 files changed, 410 insertions(+), 120 deletions(-) create mode 100644 src/com/guntherdw/bukkit/tweakcraft/Tools/PluginResolver.java create mode 100644 src/com/guntherdw/bukkit/tweakcraft/Util/UUIDResolver.java diff --git a/plugin.yml b/plugin.yml index 01705e1..1bdd91f 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,8 +1,9 @@ name: TweakcraftUtils main: com.guntherdw.bukkit.tweakcraft.TweakcraftUtils # softdepend: [ 'CraftIRC' ] -# depend: [ CraftIRC ] -version: 2.8.1-git +depend: [ CraftIRC ] +softdepend: [ 'PermissionsEx' ] +version: 2.8.2-git authors: - GuntherDW - Meaglin diff --git a/src/com/guntherdw/bukkit/tweakcraft/Chat/Modes/AdminChat.java b/src/com/guntherdw/bukkit/tweakcraft/Chat/Modes/AdminChat.java index a7f6e0f..6a72c6b 100644 --- a/src/com/guntherdw/bukkit/tweakcraft/Chat/Modes/AdminChat.java +++ b/src/com/guntherdw/bukkit/tweakcraft/Chat/Modes/AdminChat.java @@ -67,14 +67,14 @@ public boolean sendMessage(CommandSender sender, String message) { String msg = ChatColor.GREEN + "A: [" + pcolor + sendername + ChatColor.GREEN + "] " + message; if (plugin.getConfigHandler().enableIRC && plugin.getCraftIRC() != null && plugin.getConfigHandler().AIRCenabled) { - String targetmsg = plugin.getConfigHandler().AIRCMessageFormat; targetmsg = targetmsg.replace("%name%", cleanname). replace("%message%", message). replace("%dispname%", ChatColor.stripColor(sendername)); targetmsg = targetmsg.replace("%clearcolors%", Character.toString((char) 3)); - RelayedMessage rmsg = plugin.getCraftIRC().newMsgToTag(plugin.getAdminEndPoint(), plugin.getConfigHandler().AIRCtag, "generic"); + RelayedMessage rmsg = plugin.getCraftIRC().newMsgToTag(plugin.getAdminEndPoint(), plugin.getConfigHandler().AIRCtag, "chat"); + rmsg.setField("sender", pcolor + sendername); rmsg.setField("realSender", cleanname); rmsg.setField("message", targetmsg); diff --git a/src/com/guntherdw/bukkit/tweakcraft/Commands/Commands/ChatCommands.java b/src/com/guntherdw/bukkit/tweakcraft/Commands/Commands/ChatCommands.java index 8292cef..eb4ef10 100644 --- a/src/com/guntherdw/bukkit/tweakcraft/Commands/Commands/ChatCommands.java +++ b/src/com/guntherdw/bukkit/tweakcraft/Commands/Commands/ChatCommands.java @@ -274,7 +274,7 @@ public boolean chatCommand(CommandSender sender, String command, String chatMode // plugin.getServer().broadcastMessage(ChatColor.WHITE + "<" + (sender instanceof Player ? ((Player) sender).getDisplayName() : ChatColor.LIGHT_PURPLE + "CONSOLE") + ChatColor.WHITE + "> " + spam); if(sender instanceof Player) { Set players = new HashSet(); - players.addAll(Arrays.asList(plugin.getServer().getOnlinePlayers())); + players.addAll(plugin.getServer().getOnlinePlayers()); org.bukkit.event.player.AsyncPlayerChatEvent playerChatEvent = new org.bukkit.event.player.AsyncPlayerChatEvent(false, (Player) sender, spam, players); plugin.getServer().getPluginManager().callEvent(playerChatEvent); diff --git a/src/com/guntherdw/bukkit/tweakcraft/Commands/Commands/EssentialsCommands.java b/src/com/guntherdw/bukkit/tweakcraft/Commands/Commands/EssentialsCommands.java index 6e01eb8..e0be13d 100644 --- a/src/com/guntherdw/bukkit/tweakcraft/Commands/Commands/EssentialsCommands.java +++ b/src/com/guntherdw/bukkit/tweakcraft/Commands/Commands/EssentialsCommands.java @@ -93,6 +93,16 @@ public boolean ban(CommandSender sender, String command, String[] realargs) throw new CommandException("Didn't find the player, cancelling!"); } } + // Check for GameProfile + + OfflinePlayer checkPlayer = null; + checkPlayer = Bukkit.getOfflinePlayer(playername); + UUID uuid = checkPlayer.getUniqueId(); + + if(uuid == null) { + throw new CommandException("Didn't find the player's profile, does this player exist?"); + } + if (handler.isBanned(playername)) { sender.sendMessage(ChatColor.YELLOW + "This player is already banned!"); @@ -979,6 +989,14 @@ public boolean spawnMob(CommandSender sender, String command, String[] realargs) int age = ap.getInteger("a", -1); boolean sitting = ap.getBoolean("sit", false); boolean tame = ap.getBoolean("tame", false); + + String horseColor = ap.getString("hc", null); + String horseVariant = ap.getString("hv", null); + int horseDomestication = ap.getInteger("hd", -1); + int horseMaxDomestication = ap.getInteger("hmd", -1); + boolean horseHasChest = ap.getBoolean("hhc", false); + int horseJumpStrength = ap.getInteger("hjs", -1); + String[] args = ap.getUnusedArgs(); String mobName; @@ -1108,7 +1126,7 @@ public boolean spawnMob(CommandSender sender, String command, String[] realargs) if (sheepcolor != null) { DyeColor dc = null; if (sheepcolor.equalsIgnoreCase("random")) { - dc = DyeColor.getByData((byte) rnd.nextInt(16)); + dc = DyeColor.getByWoolData((byte) rnd.nextInt(16)); } else { dc = DyeColor.valueOf(sheepcolor.toUpperCase()); } @@ -1116,6 +1134,54 @@ public boolean spawnMob(CommandSender sender, String command, String[] realargs) } } + if(lent instanceof Horse) { + Horse horse = (Horse) lent; + if(horseColor != null) { + Horse.Color c = null; + if(horseColor.equalsIgnoreCase("random")) { + c = Horse.Color.values()[rnd.nextInt(Horse.Color.values().length)]; + } else { + c = Horse.Color.valueOf(horseColor.toUpperCase()); + } + + if(c != null) + horse.setColor(c); + else + sender.sendMessage(ChatColor.YELLOW + "Horse color not valid!"); + + } + + if (horseVariant != null) { + Horse.Variant v = null; + if (horseVariant.equalsIgnoreCase("random")) { + v = Horse.Variant.values()[rnd.nextInt(Horse.Variant.values().length)]; + } else { + v = Horse.Variant.valueOf(horseVariant.toUpperCase()); + } + + if (v != null) + horse.setVariant(v); + else + sender.sendMessage(ChatColor.YELLOW + "Horse variant not valid!"); + + } + + if(horseDomestication != -1) horse.setDomestication(horseDomestication); + if(horseMaxDomestication != -1) horse.setMaxDomestication(horseMaxDomestication); + if(horseHasChest) horse.setCarryingChest(horseHasChest); + + // sender.sendMessage("horseJumpStrength : "+horseJumpStrength); + + if(horseJumpStrength == -1) { + double f = rnd.nextInt(2000000); + f /= 1000000.0D; + horse.setJumpStrength(f); + // sender.sendMessage("setJumpStrength("+f+")"); + } else { + horse.setJumpStrength(horseJumpStrength/100); + } + } + if (riders != null && riders.size() != 0) { for (EntityType t : riders) { rid = (LivingEntity) victimplayer.getWorld().spawnEntity(loc, t); @@ -1238,10 +1304,14 @@ public boolean who(CommandSender sender, String command, String[] realargs) if (w == null) throw new CommandUsageException("World not found!"); } - List list = null; + Collection playerList = null; + List list = new ArrayList(); - if (w == null) list = Arrays.asList(plugin.getServer().getOnlinePlayers()); - else list = w.getPlayers(); + if (w == null) { + list.addAll(plugin.getServer().getOnlinePlayers()); + } else { + list = w.getPlayers(); + } Integer amountofinvis = 0; for (Player p : list) { LocalPlayer lp = plugin.wrapPlayer(p); @@ -1350,12 +1420,15 @@ public boolean world(CommandSender sender, String command, String[] args) } } } + // player.sendMessage("tloc : "+toLocation); + if (po == null) { po = new PlayerOptions(); po.setOptionname("worldpos"); po.setName(player.getName()); } po.setOptionvalue(this.exportLocationString(player.getLocation())); + // player.sendMessage("nloc : "+this.exportLocationString(player.getLocation())); plugin.getDatabase().save(po); } if (player.teleport(toLocation)) diff --git a/src/com/guntherdw/bukkit/tweakcraft/Commands/Commands/GeneralCommands.java b/src/com/guntherdw/bukkit/tweakcraft/Commands/Commands/GeneralCommands.java index 7a04aa2..49422c3 100644 --- a/src/com/guntherdw/bukkit/tweakcraft/Commands/Commands/GeneralCommands.java +++ b/src/com/guntherdw/bukkit/tweakcraft/Commands/Commands/GeneralCommands.java @@ -158,7 +158,7 @@ public boolean broadcast(CommandSender sender, String command, String[] realargs } } } else - recipients = Arrays.asList(plugin.getServer().getOnlinePlayers()); + recipients = new ArrayList(plugin.getServer().getOnlinePlayers()); String[] args = ap.getUnusedArgs(); @@ -169,10 +169,9 @@ public boolean broadcast(CommandSender sender, String command, String[] realargs message += args[x] + (x(plugin.getServer().getOnlinePlayers()); if (victims.contains(player)) victims.remove(player); // remove the origin player! } diff --git a/src/com/guntherdw/bukkit/tweakcraft/DataSources/Ban/BanHandler.java b/src/com/guntherdw/bukkit/tweakcraft/DataSources/Ban/BanHandler.java index e7758c5..2c8377f 100644 --- a/src/com/guntherdw/bukkit/tweakcraft/DataSources/Ban/BanHandler.java +++ b/src/com/guntherdw/bukkit/tweakcraft/DataSources/Ban/BanHandler.java @@ -22,6 +22,7 @@ import com.guntherdw.bukkit.tweakcraft.Packages.Ban; import com.guntherdw.bukkit.tweakcraft.TweakcraftUtils; import com.guntherdw.bukkit.tweakcraft.Util.TimeTool; +import org.bukkit.configuration.file.YamlConfiguration; import java.io.*; import java.text.SimpleDateFormat; @@ -53,24 +54,55 @@ public Ban searchBan(String playername) { return null; // I Has found nothing! } - private void loadBans() { - bans = new HashMap(); + private void convertOldBanFile(File oldBanFile, YamlConfiguration newBanConfig) { + + Map oldBans = new HashMap(); + try { - File banfile = new File(plugin.getDataFolder(), "banned-players.txt"); - BufferedReader banfilereader = new BufferedReader(new FileReader(banfile)); + // File banfile = new File(plugin.getDataFolder(), "banned-players.txt"); + + BufferedReader banfilereader = new BufferedReader(new FileReader(oldBanFile)); String line = ""; while ((line = banfilereader.readLine()) != null) { if (!line.trim().equals("")) { String[] lin = line.split(","); if (lin.length > 1) - bans.put(lin[0], new Ban(lin[0], lin[1])); + oldBans.put(lin[0], new Ban(lin[0], lin[1])); else - bans.put(lin[0], new Ban(lin[0], "")); + oldBans.put(lin[0], new Ban(lin[0], "")); } } banfilereader.close(); - } catch (FileNotFoundException e) { plugin.getLogger().warning("Ban file not found!"); - } catch (IOException e) { plugin.getLogger().info("Ban file I/O error!"); } + boolean deleted = oldBanFile.delete(); + if(!deleted) plugin.getLogger().warning("Could not remove old banfile!"); + plugin.getLogger().info("Converted banned players file to newer format."); + } catch (FileNotFoundException e) { + plugin.getLogger().warning("Ban file not found!"); + } catch (IOException e) { + plugin.getLogger().info("Ban file I/O error!"); + } + } + + private void loadBans() { + bans = new HashMap(); + + File banFile = new File(plugin.getDataFolder(), "banned-players.yml"); + + YamlConfiguration banConfig = new YamlConfiguration(); + try { + banConfig.load(banFile); + } catch(Exception e) { + plugin.getLogger().warning("Error while loading banned-players.yml, does this file exist?"); + } + + // check for old BanFile + File oldBanFile = new File(plugin.getDataFolder(), "banned-players.txt"); + if (oldBanFile.exists()) { + plugin.getLogger().warning("Old banned-players file found, converting to new format!"); + this.convertOldBanFile(oldBanFile, banConfig); + } + + if(plugin.getConfigHandler().enablePersistence) { List popts = plugin.getDatabase(). find(PlayerOptions.class).where().ieq("optionname", "ban").findList(); for(PlayerOptions po : popts) { @@ -154,6 +186,10 @@ public Ban isBannedBan(String playername) { return null; } + public Ban isBannedBan(UUID uuid) { + return null; + } + public boolean isBannedFullname(String playername) { return bans.containsKey(playername); } diff --git a/src/com/guntherdw/bukkit/tweakcraft/Listeners/TweakcraftPlayerListener.java b/src/com/guntherdw/bukkit/tweakcraft/Listeners/TweakcraftPlayerListener.java index 327d659..7e00ffb 100644 --- a/src/com/guntherdw/bukkit/tweakcraft/Listeners/TweakcraftPlayerListener.java +++ b/src/com/guntherdw/bukkit/tweakcraft/Listeners/TweakcraftPlayerListener.java @@ -46,7 +46,6 @@ import org.bukkit.inventory.ItemStack; import java.io.IOException; -import java.lang.reflect.Method; import java.util.*; /** @@ -477,7 +476,15 @@ public void onPlayerTeleport(PlayerTeleportEvent event) { @EventHandler(priority = EventPriority.HIGH) public void onPlayerLogin(PlayerLoginEvent event) { BanHandler handler = plugin.getBanhandler(); - Ban isBanned = handler.isBannedBan(event.getPlayer().getName()); + + Player p = event.getPlayer(); + UUID playerUUID = p.getUniqueId(); + + /* Check for profile, update/link playerName if required. */ + // TODO: check when it actually is allowed to change names + plugin.getUUIDResolver().checkProfile(p); + + Ban isBanned = handler.isBannedBan(playerUUID); if (isBanned != null) { event.disallow(PlayerLoginEvent.Result.KICK_BANNED, isBanned.getReason()); } @@ -932,7 +939,17 @@ public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { } } else { - EntityType type = EntityType.fromName(animal.getClass().getCanonicalName().split("Craft")[1]); + String clsName = animal.getClass().getCanonicalName().split("Craft")[1]; + /* if (clsName.equals("Horse")) + clsName = "EntityHorse"; */ + + EntityType type = EntityType.fromName(clsName); + + if(type == null) { + player.sendMessage(ChatColor.RED+"Error while getting AnimalInfo."); + player.sendMessage(ChatColor.RED+"ClassName was "+animal.getClass().getCanonicalName()); + return; + } String cname = type.getName().toLowerCase(); player.sendMessage(ChatColor.BLUE + "Animal info : "); player.sendMessage(ChatColor.BLUE + "type : " + ChatColor.YELLOW + cname); @@ -943,7 +960,7 @@ public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { return; - } else if (player.getItemInHand().getType().equals(Material.WHEAT) && animal.getAge() < 0) { + } else if (player.getItemInHand().getType().equals(Material.WHEAT) && animal.getAge() < 0 && !(animal instanceof Horse)) { ItemStack inHand = player.getItemInHand(); if (inHand.getAmount() > 1) inHand.setAmount(inHand.getAmount() - 1); @@ -957,7 +974,7 @@ public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { player.setItemInHand(inHand); player.getWorld().playEffect(animal.getLocation(), Effect.POTION_BREAK, 0); - } else if (player.getItemInHand().getType().equals(Material.MILK_BUCKET) && animal.getAge() < 0) { + } else if (player.getItemInHand().getType().equals(Material.MILK_BUCKET) && animal.getAge() < 0 && !(animal instanceof Horse)) { int newAge = animal.getAge() + 2500; if (newAge > 0) newAge = 0; animal.setAge(newAge); @@ -992,7 +1009,8 @@ public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { } - if (player.getItemInHand() != null && player.getItemInHand().getType() == Material.SADDLE) { + if (player.getItemInHand() != null && player.getItemInHand().getType() == Material.SADDLE + && !(entity instanceof Horse)) { // Horses have their own saddle thing. if (entity.isEmpty()) { boolean allowed = true; if (nomount.contains(player.getName())) { diff --git a/src/com/guntherdw/bukkit/tweakcraft/Packages/Ban.java b/src/com/guntherdw/bukkit/tweakcraft/Packages/Ban.java index b80ebaa..482ffa3 100644 --- a/src/com/guntherdw/bukkit/tweakcraft/Packages/Ban.java +++ b/src/com/guntherdw/bukkit/tweakcraft/Packages/Ban.java @@ -18,11 +18,17 @@ package com.guntherdw.bukkit.tweakcraft.Packages; +import org.bukkit.Bukkit; + +import java.util.UUID; + /** * @author GuntherDW */ public final class Ban { + // String player; + UUID uuid; String player; String reason; Long toTime; @@ -31,18 +37,31 @@ public Ban(String Player, String Reason) { this.player = Player; this.reason = Reason; this.toTime = null; + this.uuid = Bukkit.getOfflinePlayer(player).getUniqueId(); } public Ban(String Player, String Reason, Long ToTime) { this.player = Player; this.reason = Reason; this.toTime = ToTime; + this.uuid = Bukkit.getOfflinePlayer(player).getUniqueId(); + } + + public Ban(UUID uuid, String Reason, Long ToTime) { + this.uuid = uuid; + this.player = Bukkit.getOfflinePlayer(uuid).getName(); + this.reason = Reason; + this.toTime = ToTime; } public String getPlayer() { return player; } + public UUID getUUID() { + return uuid; + } + public String getReason() { if (reason == null || reason.equals("")) { return "You are banned!"; diff --git a/src/com/guntherdw/bukkit/tweakcraft/Packages/CraftIRCAdminEndPoint.java b/src/com/guntherdw/bukkit/tweakcraft/Packages/CraftIRCAdminEndPoint.java index e3f7f24..7161ddb 100644 --- a/src/com/guntherdw/bukkit/tweakcraft/Packages/CraftIRCAdminEndPoint.java +++ b/src/com/guntherdw/bukkit/tweakcraft/Packages/CraftIRCAdminEndPoint.java @@ -70,6 +70,8 @@ public void messageIn(RelayedMessage relayedMessage) { String name = relayedMessage.getField("sender"); String nick = plugin.getPlayerListener().findPlayerNameByNick(name, true); relayedMessage.setField("sender", plugin.getNickWithColors(nick == null ? name : nick)); + } else { + relayedMessage.setField("sender", "unknownSender"); } ac.broadcastMessage(relayedMessage.getMessage(this)); } diff --git a/src/com/guntherdw/bukkit/tweakcraft/Packages/LocalPlayer.java b/src/com/guntherdw/bukkit/tweakcraft/Packages/LocalPlayer.java index fc771fb..a9b1a53 100644 --- a/src/com/guntherdw/bukkit/tweakcraft/Packages/LocalPlayer.java +++ b/src/com/guntherdw/bukkit/tweakcraft/Packages/LocalPlayer.java @@ -24,12 +24,15 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import java.util.UUID; + /** * @author GuntherDW */ public class LocalPlayer { private String name; + private UUID uuid; private Player bukkitPlayer; private ChatMode chatMode; private boolean afk; @@ -150,12 +153,22 @@ public String getName() { public LocalPlayer(Player player) { this.bukkitPlayer = player; this.name = player.getName(); + this.uuid = player.getUniqueId(); } public LocalPlayer(String name) { this.name = name; } + public LocalPlayer(UUID uuid) { + this.uuid = uuid; + } + + public LocalPlayer(String name, UUID uuid) { + this.name = name; + this.uuid = uuid; + } + public ChatMode getChatMode() { return chatMode; } diff --git a/src/com/guntherdw/bukkit/tweakcraft/Tools/PluginResolver.java b/src/com/guntherdw/bukkit/tweakcraft/Tools/PluginResolver.java new file mode 100644 index 0000000..917c41d --- /dev/null +++ b/src/com/guntherdw/bukkit/tweakcraft/Tools/PluginResolver.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2014 GuntherDW + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package com.guntherdw.bukkit.tweakcraft.Tools; + +/** + * @author GuntherDW + */ +public class PluginResolver { +} diff --git a/src/com/guntherdw/bukkit/tweakcraft/Tools/TamerTool.java b/src/com/guntherdw/bukkit/tweakcraft/Tools/TamerTool.java index 5c57ce8..9590146 100644 --- a/src/com/guntherdw/bukkit/tweakcraft/Tools/TamerTool.java +++ b/src/com/guntherdw/bukkit/tweakcraft/Tools/TamerTool.java @@ -45,29 +45,36 @@ public Map getTamers() { public void getOwner(Player player, Tameable tameable) { String className = tameable.getClass().getCanonicalName().split("Craft")[1]; - if(className.equals("Ocelot")) className = "Ozelot"; + if (className.equals("Ocelot")) className = "Ozelot"; + if (className.equals("Horse")) className = "EntityHorse"; EntityType entityType = EntityType.fromName(className); String cname = entityType.getName().toLowerCase(); - player.sendMessage(ChatColor.AQUA + "Tameable type : "+cname); + player.sendMessage(ChatColor.AQUA + "Tameable type : " + cname); - if(tameable.isTamed()) { + if (tameable.isTamed()) { AnimalTamer tamer = tameable.getOwner(); - if(tamer instanceof Player || tamer instanceof OfflinePlayer) { + if (tamer instanceof Player || tamer instanceof OfflinePlayer) { // Player ptamer = (Player) tamer; boolean online = false; - Player ptamer=null; OfflinePlayer offlinetamer=null; - if(tamer instanceof Player) { ptamer = (Player) tamer; online = true; } - else { offlinetamer = (OfflinePlayer) tamer; online = false; } + Player ptamer = null; + OfflinePlayer offlinetamer = null; + if (tamer instanceof Player) { + ptamer = (Player) tamer; + online = true; + } else { + offlinetamer = (OfflinePlayer) tamer; + online = false; + } boolean allowed = true; - if(online && !ptamer.equals(player)) { - if(!plugin.check(player, "tamer.info.other")) + if (online && !ptamer.equals(player)) { + if (!plugin.check(player, "tamer.info.other")) allowed = false; } - if(allowed) { - player.sendMessage(ChatColor.AQUA + "Tameable owner : "+(online?ptamer.getDisplayName():offlinetamer.getName())); + if (allowed) { + player.sendMessage(ChatColor.AQUA + "Tameable owner : " + (online ? ptamer.getDisplayName() : offlinetamer.getName())); } else { player.sendMessage(ChatColor.RED + "You do not have the permission to check the ownership of other wolves!"); } @@ -77,71 +84,81 @@ public void getOwner(Player player, Tameable tameable) { } else { player.sendMessage(ChatColor.AQUA + "This tameable isn't tamed!"); } - player.sendMessage(ChatColor.AQUA + "Tameable health : "+((LivingEntity)tameable).getHealth()); - if(tameable instanceof Ageable) { - player.sendMessage(ChatColor.AQUA + "Tameable age : "+((Ageable)tameable).getAge() + (((Ageable)tameable).getAgeLock() ? ChatColor.RED+" L":"")); + player.sendMessage(ChatColor.AQUA + "Tameable health : " + ((LivingEntity) tameable).getHealth()); + if (tameable instanceof Ageable) { + player.sendMessage(ChatColor.AQUA + "Tameable age : " + ((Ageable) tameable).getAge() + (((Ageable) tameable).getAgeLock() ? ChatColor.RED + " L" : "")); } - if(tameable instanceof Ocelot) { - player.sendMessage(ChatColor.AQUA + "Tameable cat-type : "+((Ocelot)tameable).getCatType().toString().toLowerCase()); + if (tameable instanceof Ocelot) { + player.sendMessage(ChatColor.AQUA + "Tameable cat-type : " + ((Ocelot) tameable).getCatType().toString().toLowerCase()); } - if(tameable instanceof Wolf) { + if (tameable instanceof Horse) { + Horse horse = (Horse) tameable; + + player.sendMessage(ChatColor.AQUA + "Tameable color : " + horse.getColor().toString().toLowerCase()); + player.sendMessage(ChatColor.AQUA + "Tameable style : " + horse.getStyle().toString().toLowerCase()); + player.sendMessage(ChatColor.AQUA + "Tameable variant : " + horse.getVariant().toString().toLowerCase()); + player.sendMessage(ChatColor.AQUA + "Tameable jumpstrength : " + horse.getJumpStrength()); + player.sendMessage(ChatColor.AQUA + "Tameable domestication : " + horse.getDomestication()); + player.sendMessage(ChatColor.AQUA + "Tameable maxdomestication : " + horse.getMaxDomestication()); + } + if (tameable instanceof Wolf) { Wolf wolf = (Wolf) tameable; - if(wolf.isAngry()) { - player.sendMessage(ChatColor.AQUA + "This tameable is "+ChatColor.RED+"angry"+ChatColor.AQUA+"!"); + if (wolf.isAngry()) { + player.sendMessage(ChatColor.AQUA + "This tameable is " + ChatColor.RED + "angry" + ChatColor.AQUA + "!"); LivingEntity le = wolf.getTarget(); String target = ""; - if(le instanceof OfflinePlayer) - if(((OfflinePlayer) le).isOnline()) - target = ((Player)le).getDisplayName(); + if (le instanceof OfflinePlayer) + if (((OfflinePlayer) le).isOnline()) + target = ((Player) le).getDisplayName(); else target = ((OfflinePlayer) le).getName(); else { String extraInfo = ""; - if ( le != null ) { + if (le != null) { EntityType et = le.getType(); extraInfo = et.getName(); } - target = "Animal "+extraInfo;// +le!=null?" ("+(et.getName())+")":""; + target = "Animal " + extraInfo;// +le!=null?" ("+(et.getName())+")":""; } - player.sendMessage(ChatColor.AQUA + "Target : "+target); + player.sendMessage(ChatColor.AQUA + "Target : " + target); } } } public void setTame(Tameable tameable, Boolean tame, Player player) { - if(plugin.check(player, "tamer.tame")) { + if (plugin.check(player, "tamer.tame")) { Boolean allowed = true; - if(tame==null) { + if (tame == null) { tame = !tameable.isTamed(); } - if(tameable.isTamed() && !tame) { + if (tameable.isTamed() && !tame) { AnimalTamer tamer = tameable.getOwner(); - if(tamer instanceof Player) { - if(!((Player)tamer).equals(player)) { - if(!plugin.check(player, "tamer.tame.untame.other")) + if (tamer instanceof Player) { + if (!((Player) tamer).equals(player)) { + if (!plugin.check(player, "tamer.tame.untame.other")) allowed = false; } else { - if(!plugin.check(player, "tamer.tame.untame.own")) + if (!plugin.check(player, "tamer.tame.untame.own")) allowed = false; } } - if(allowed) { + if (allowed) { tameable.setOwner(null); tameable.setTamed(false); } else { player.sendMessage(ChatColor.RED + "You do not have permission to untame this tameables!"); } - } else if(!tameable.isTamed() && tame) { - if(!plugin.check(player, "tamer.tame.tame")) + } else if (!tameable.isTamed() && tame) { + if (!plugin.check(player, "tamer.tame.tame")) allowed = false; - if(allowed) { + if (allowed) { tameable.setTamed(true); - if(tameable instanceof Wolf) { - ((Wolf)tameable).setAngry(false); + if (tameable instanceof Wolf) { + ((Wolf) tameable).setAngry(false); } - ((Creature)tameable).setTarget(null); + ((Creature) tameable).setTarget(null); tameable.setOwner(player); } else { @@ -154,27 +171,27 @@ public void setTame(Tameable tameable, Boolean tame, Player player) { } public void setAngry(Tameable tameable, Boolean angry, Player player) { - if(plugin.check(player, "tamer.angry")) { - if(tameable instanceof Wolf) { + if (plugin.check(player, "tamer.angry")) { + if (tameable instanceof Wolf) { Wolf wolf = (Wolf) tameable; Boolean allowed = true; - if(tameable.isTamed()) { - if(tameable.getOwner().equals(player)) { - if(!plugin.check(player, "tamer.angry.own")) + if (tameable.isTamed()) { + if (tameable.getOwner().equals(player)) { + if (!plugin.check(player, "tamer.angry.own")) allowed = false; } else { - if(!plugin.check(player, "tamer.angry.other")) + if (!plugin.check(player, "tamer.angry.other")) allowed = false; } } - if(angry==null) { + if (angry == null) { angry = !wolf.isAngry(); } - if(allowed) { + if (allowed) { wolf.setAngry(angry); - if(!angry) { + if (!angry) { wolf.setTarget(null); } } else { @@ -189,37 +206,34 @@ public void setAngry(Tameable tameable, Boolean angry, Player player) { } public void sit(Tameable tameable, Boolean sit, Player player) { - if(plugin.check(player, "tamer.sit")) { + if (plugin.check(player, "tamer.sit")) { Boolean allowed = true; - Boolean sitting = tameable instanceof Ocelot ? ((Ocelot)tameable).isSitting() : + Boolean sitting = tameable instanceof Ocelot ? ((Ocelot) tameable).isSitting() : tameable instanceof Wolf && ((Wolf) tameable).isSitting(); - if(sitting) { - if(tameable.getOwner()!=null && tameable.getOwner().equals(player)) { - if(!plugin.check(player, "tamer.sit.own")) + if (sitting) { + if (tameable.getOwner() != null && tameable.getOwner().equals(player)) { + if (!plugin.check(player, "tamer.sit.own")) allowed = false; } else { - if(!plugin.check(player, "tamer.sit.other")) + if (!plugin.check(player, "tamer.sit.other")) allowed = false; } } else { - if(!plugin.check(player, "tamer.sit.wild")) + if (!plugin.check(player, "tamer.sit.wild")) allowed = false; } - if(sit==null) + if (sit == null) sit = !sitting; - if(allowed) { - if(tameable instanceof Wolf) - ((Wolf)tameable).setSitting(sit); - if(tameable instanceof Ocelot) - ((Ocelot)tameable).setSitting(sit); - } - - - else + if (allowed) { + if (tameable instanceof Wolf) + ((Wolf) tameable).setSitting(sit); + if (tameable instanceof Ocelot) + ((Ocelot) tameable).setSitting(sit); + } else player.sendMessage(ChatColor.RED + "You do not have permission to command this tameables!"); } else { player.sendMessage(ChatColor.RED + "You do not have permission to command tameables!"); @@ -227,23 +241,23 @@ public void sit(Tameable tameable, Boolean sit, Player player) { } public void heal(Tameable tameable, Boolean kill, Player player) { - if(plugin.check(player, "tamer.heal")) { + if (plugin.check(player, "tamer.heal")) { Boolean allowed = true; - if(tameable.isTamed()) { - if(tameable.getOwner()!=null && tameable.getOwner().equals(player)) { - if(!plugin.check(player, "tamer.heal.own")) + if (tameable.isTamed()) { + if (tameable.getOwner() != null && tameable.getOwner().equals(player)) { + if (!plugin.check(player, "tamer.heal.own")) allowed = false; } else { - if(!plugin.check(player, "tamer.heal.other")) + if (!plugin.check(player, "tamer.heal.other")) allowed = false; } } else { - if(!plugin.check(player, "tamer.heal.wild")) + if (!plugin.check(player, "tamer.heal.wild")) allowed = false; } - if(allowed) - ((LivingEntity)tameable).setHealth(((LivingEntity)tameable).getMaxHealth()); + if (allowed) + ((LivingEntity) tameable).setHealth(((LivingEntity) tameable).getMaxHealth()); else player.sendMessage(ChatColor.RED + "You do not have permission to heal this tameables!"); } else { @@ -252,26 +266,26 @@ public void heal(Tameable tameable, Boolean kill, Player player) { } public void setAge(Tameable tameable, Integer age, Player player) { - if(plugin.check(player, "tamer.setage")) { - if(tameable instanceof Ageable) ((Ageable)tameable).setAge(age); + if (plugin.check(player, "tamer.setage")) { + if (tameable instanceof Ageable) ((Ageable) tameable).setAge(age); } } public void setAgeLock(Tameable tameable, Boolean lock, Player player) { - if(plugin.check(player, "tamer.setage")) { - if(tameable instanceof Ageable) { + if (plugin.check(player, "tamer.setage")) { + if (tameable instanceof Ageable) { player.sendMessage(ChatColor.BLUE + "Setting animal agelock to " + lock); - ((Ageable)tameable).setAgeLock(lock); + ((Ageable) tameable).setAgeLock(lock); } } } public void handleEvent(Player player, Tameable tameable) { - if(!tamers.containsKey(player)) + if (!tamers.containsKey(player)) return; TamerMode tamermode = tamers.get(player); - switch(tamermode.getMode()) { + switch (tamermode.getMode()) { case INFO: this.getOwner(player, tameable); break; diff --git a/src/com/guntherdw/bukkit/tweakcraft/TweakcraftUtils.java b/src/com/guntherdw/bukkit/tweakcraft/TweakcraftUtils.java index c4c739b..7351ce3 100644 --- a/src/com/guntherdw/bukkit/tweakcraft/TweakcraftUtils.java +++ b/src/com/guntherdw/bukkit/tweakcraft/TweakcraftUtils.java @@ -39,6 +39,7 @@ import com.guntherdw.bukkit.tweakcraft.Tools.PermissionsResolver; import com.guntherdw.bukkit.tweakcraft.Tools.TamerTool; import com.guntherdw.bukkit.tweakcraft.Util.TeleportHistory; +import com.guntherdw.bukkit.tweakcraft.Util.UUIDResolver; import com.guntherdw.bukkit.tweakcraft.Worlds.WorldManager; import com.sk89q.worldedit.bukkit.WorldEditPlugin; @@ -93,6 +94,8 @@ public class TweakcraftUtils extends JavaPlugin { private final ChatHandler chathandler = new ChatHandler(this); private final PermissionsResolver permsResolver = new PermissionsResolver(this); + private final UUIDResolver uuidResolver = new UUIDResolver(this); + private HashMap localPlayers = new HashMap(); private Object circendpoint = null; @@ -142,15 +145,6 @@ public static TweakcraftUtils getInstance() { return instance; } - /* public TCUtilsClientBridgePlugin getClientBridge() { - return tcUtilsClientBridgePlugin; - } - - public static void registerClientBridge(TCUtilsClientBridgePlugin clientBridgePlugin) { - if(instance==null) return; - instance.tcUtilsClientBridgePlugin = clientBridgePlugin; - } */ - public void sendCUIChatMode(Player player) { if (this.cuiPlayers != null && this.cuiPlayers.contains(player)) { ChatMode cm = getChathandler().getPlayerChatMode(player); @@ -188,6 +182,10 @@ public void sendCUIHandShake(Player player) { } } + public UUIDResolver getUUIDResolver() { + return uuidResolver; + } + /** * Send the player a mod_InfDura string, setting the new ToolDurabilty mode * @@ -365,6 +363,20 @@ public static List findPlayerByNick(String part) { return null; } + public static List findPlayerByNick_string(String part) { + if (getInstance() != null) { + List lijst = getInstance().findPlayerasPlayerList(part); + List userList = new ArrayList(); + if(lijst.size()>0) { + for(Player p : lijst) { + userList.add(p.getName()); + } + } + return userList; + } else + return null; + } + public Player findPlayerasPlayer(String partOfName) { // Go for the nicks first! Player nick = playerListener.findPlayerByNick(partOfName); diff --git a/src/com/guntherdw/bukkit/tweakcraft/Util/TweakTravelAgent.java b/src/com/guntherdw/bukkit/tweakcraft/Util/TweakTravelAgent.java index e339f81..1f4dec3 100644 --- a/src/com/guntherdw/bukkit/tweakcraft/Util/TweakTravelAgent.java +++ b/src/com/guntherdw/bukkit/tweakcraft/Util/TweakTravelAgent.java @@ -40,7 +40,7 @@ public class TweakTravelAgent implements TravelAgent { private int creationRadius = 14; // 16 -> 14 private boolean canCreatePortal = true; private TweakcraftUtils plugin = null; - + private Map buildable; public TweakTravelAgent(TweakcraftUtils instance) {this.plugin=instance;} @@ -99,7 +99,7 @@ public void fillBuildableMap() { buildable.put(Material.MOSSY_COBBLESTONE.getId(), true); buildable.put(Material.OBSIDIAN.getId(), true); } - + public Location findOrCreate(Location location) { /* WorldServer worldServer = ((CraftWorld) location.getWorld()).getHandle(); worldServer.chunkProviderServer.forceChunkLoad = true; */ diff --git a/src/com/guntherdw/bukkit/tweakcraft/Util/UUIDResolver.java b/src/com/guntherdw/bukkit/tweakcraft/Util/UUIDResolver.java new file mode 100644 index 0000000..3628b88 --- /dev/null +++ b/src/com/guntherdw/bukkit/tweakcraft/Util/UUIDResolver.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2014 GuntherDW + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package com.guntherdw.bukkit.tweakcraft.Util; + +import com.guntherdw.bukkit.tweakcraft.DataSources.PersistenceClass.PlayerOptions; +import com.guntherdw.bukkit.tweakcraft.TweakcraftUtils; +import org.bukkit.entity.Player; + +import java.util.Iterator; +import java.util.List; + +/** + * @author GuntherDW + */ + +/* + * This class primary use will be to check for older profiles in the DB and update if required. + */ +public class UUIDResolver { + + private TweakcraftUtils plugin; + + public UUIDResolver(TweakcraftUtils instance) { + this.plugin = instance; + } + + public void checkProfile(Player p) { + + List popts = plugin.getDatabase().find(PlayerOptions.class).where().ieq("name", p.getName()).findList(); + if(popts.size() != 0) { + PlayerOptions uuid = plugin.getDatabase().find(PlayerOptions.class).where().ieq("name", p.getName()).ieq("optionname", "uuid").findUnique(); + if(uuid == null) { + // Check if he changed his name + PlayerOptions oldName = plugin.getDatabase().find(PlayerOptions.class).where().ieq("optionname", "uuid").ieq("optionvalue", p.getUniqueId().toString()).findUnique(); + + if(oldName != null) { + plugin.getLogger().warning(oldName.getName() + " changed his name to "+p.getName() +", updating PlayerOptions database!"); + + List oldOpts = plugin.getDatabase().find(PlayerOptions.class).where().ieq("name", oldName.getName()).findList(); + + // Update DB! + String newName = p.getName(); + // plugin.getDatabase().find(PlayerOptions.class).where().ieq("name", oldName).findList() + for (Iterator iterator = oldOpts.iterator(); iterator.hasNext(); ) { + PlayerOptions next = iterator.next(); + next.setName(newName); + } + plugin.getDatabase().save(oldOpts); + + } else { + plugin.getLogger().warning(p.getName() + " had an old profile, updating PlayerOptions database!"); + uuid = new PlayerOptions(); + uuid.setName(p.getName()); + uuid.setOptionname("uuid"); + uuid.setOptionvalue(p.getUniqueId().toString()); + plugin.getDatabase().save(uuid); + } + } + } + + } +}