Skip to content

Commit

Permalink
Lots of changes (and getting a full 1.8 spigot-compatible release ready)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuntherDW committed Jan 3, 2015
1 parent 109c62e commit d5065e3
Show file tree
Hide file tree
Showing 16 changed files with 410 additions and 120 deletions.
5 changes: 3 additions & 2 deletions 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
Expand Down
4 changes: 2 additions & 2 deletions src/com/guntherdw/bukkit/tweakcraft/Chat/Modes/AdminChat.java
Expand Up @@ -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);
Expand Down
Expand Up @@ -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<Player> players = new HashSet<Player>();
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);
Expand Down
Expand Up @@ -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!");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1108,14 +1126,62 @@ 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());
}
if (dc != null) ((Sheep) lent).setColor(dc);
}
}

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);
Expand Down Expand Up @@ -1238,10 +1304,14 @@ public boolean who(CommandSender sender, String command, String[] realargs)
if (w == null) throw new CommandUsageException("World not found!");
}

List<Player> list = null;
Collection<? extends Player> playerList = null;
List<Player> list = new ArrayList<Player>();

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);
Expand Down Expand Up @@ -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))
Expand Down
Expand Up @@ -158,7 +158,7 @@ public boolean broadcast(CommandSender sender, String command, String[] realargs
}
}
} else
recipients = Arrays.asList(plugin.getServer().getOnlinePlayers());
recipients = new ArrayList<Player>(plugin.getServer().getOnlinePlayers());

String[] args = ap.getUnusedArgs();

Expand All @@ -169,10 +169,9 @@ public boolean broadcast(CommandSender sender, String command, String[] realargs
message += args[x] + (x<args.length?" ":"");
}

if(recipients!=null)
for (Player p : recipients) {
p.sendMessage(ChatColor.RED + "[" + ChatColor.GREEN + "Broadcast" + ChatColor.RED + "] " + ChatColor.GREEN + message);
}
for (Player p : recipients) {
p.sendMessage(ChatColor.RED + "[" + ChatColor.GREEN + "Broadcast" + ChatColor.RED + "] " + ChatColor.GREEN + message);
}

if(plugin.getConfigHandler().enableIRC && plugin.getCraftIRC()!=null && groups==null ) {
if(plugin.getConfigHandler().GIRCenabled) {
Expand Down
Expand Up @@ -518,7 +518,7 @@ public boolean tpHere(CommandSender sender, String command, String[] args)
Player player = (Player) sender;

if (args.length == 1 && args[0].equals("*")) {
victims = Arrays.asList(plugin.getServer().getOnlinePlayers());
victims = new ArrayList<Player>(plugin.getServer().getOnlinePlayers());
if (victims.contains(player))
victims.remove(player); // remove the origin player!
}
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -53,24 +54,55 @@ public Ban searchBan(String playername) {
return null; // I Has found nothing!
}

private void loadBans() {
bans = new HashMap<String, Ban>();
private void convertOldBanFile(File oldBanFile, YamlConfiguration newBanConfig) {

Map<String, Ban> oldBans = new HashMap<String, Ban>();

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<String, Ban>();

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<PlayerOptions> popts = plugin.getDatabase(). find(PlayerOptions.class).where().ieq("optionname", "ban").findList();
for(PlayerOptions po : popts) {
Expand Down Expand Up @@ -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);
}
Expand Down
Expand Up @@ -46,7 +46,6 @@
import org.bukkit.inventory.ItemStack;

import java.io.IOException;
import java.lang.reflect.Method;
import java.util.*;

/**
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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())) {
Expand Down

0 comments on commit d5065e3

Please sign in to comment.