fix castexception & make messages more consistent

This commit is contained in:
speedxx 2020-06-26 13:50:19 -04:00
parent 142fdbf9f8
commit bc7ca70e72
13 changed files with 124 additions and 85 deletions

View file

@ -6,7 +6,7 @@
<groupId>me.totalfreedom</groupId>
<artifactId>TFGuilds</artifactId>
<version>0.1.4</version>
<version>0.1.5</version>
<packaging>jar</packaging>
<name>TFGuilds</name>

View file

@ -1,6 +1,7 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.util.GBase;
import me.totalfreedom.tfguilds.util.GMessage;
import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -20,14 +21,14 @@ public class CreateGuildCommand extends GBase implements CommandExecutor
return false;
}
Player player = (Player) sender;
if (GUtil.isConsole(player))
if (GUtil.isConsole(sender))
{
sender.sendMessage(ChatColor.RED + "You are not allowed to run this command.");
sender.sendMessage(GMessage.PLAYER_ONLY);
return true;
}
Player player = (Player) sender;
ConfigurationSection guildMembers = plugin.guilds.getConfigurationSection("guilds");
if (guildMembers != null)
@ -38,7 +39,7 @@ public class CreateGuildCommand extends GBase implements CommandExecutor
{
if (plugin.guilds.getString("guilds." + guild + ".members").contains(player.getName()))
{
player.sendMessage(ChatColor.RED + "You are already in a guild.");
player.sendMessage(GMessage.IN_GUILD);
return true;
}
@ -59,17 +60,17 @@ public class CreateGuildCommand extends GBase implements CommandExecutor
{
if (args[0].equalsIgnoreCase(blacklisted))
{
if (!plugin.tfmb.isAdmin((Player) sender))
if (!plugin.tfmb.isAdmin(player))
{
sender.sendMessage(ChatColor.RED + "You may not use that name.");
player.sendMessage(ChatColor.RED + "You may not use that name.");
return true;
}
}
}
GUtil.createGuild(sender, args[0]);
Bukkit.broadcastMessage(GUtil.color("&a" + sender.getName() + " has created guild &a&l" + args[0]));
sender.sendMessage(ChatColor.GREEN + "Successfully created a guild named " + args[0]);
GUtil.createGuild(player, args[0]);
Bukkit.broadcastMessage(GUtil.color("&a" + player.getName() + " has created guild &a&l" + args[0]));
player.sendMessage(ChatColor.GREEN + "Successfully created a guild named " + args[0]);
return true;
}
}

View file

@ -1,6 +1,7 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.util.GLog;
import me.totalfreedom.tfguilds.util.GMessage;
import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -14,39 +15,39 @@ public class DisbandGuildCommand implements CommandExecutor
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
Player player = (Player) sender;
String guild = GUtil.getGuild(player);
if (GUtil.isConsole(player))
if (GUtil.isConsole(sender))
{
sender.sendMessage(ChatColor.RED + "You are not allowed to run this command.");
sender.sendMessage(GMessage.PLAYER_ONLY);
return true;
}
Player player = (Player) sender;
String guild = GUtil.getGuild(player);
if (guild == null)
{
sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
player.sendMessage(GMessage.NOT_IN_GUILD);
return true;
}
String owner = GUtil.getOwner(guild);
if (!owner.equalsIgnoreCase(player.getName()))
{
sender.sendMessage(ChatColor.RED + "You aren't the owner of your guild!");
player.sendMessage(GMessage.NOT_OWNER);
return true;
}
if (args.length == 0)
{
sender.sendMessage(ChatColor.RED + "Are you sure you want to delete your guild? Type 'CONFIRM' to continue.");
player.sendMessage(ChatColor.RED + "Are you sure you want to delete your guild? Type 'CONFIRM' to continue.");
return true;
}
if (args[0].toLowerCase().equalsIgnoreCase("confirm"))
if (args[0].equalsIgnoreCase("confirm"))
{
GUtil.deleteGuild(player);
Bukkit.broadcastMessage(GUtil.color("&c&l" + guild + " &chas been disbanded"));
sender.sendMessage(ChatColor.GREEN + "Successfully deleted and cleared data for " + guild + ".");
player.sendMessage(ChatColor.GREEN + "Successfully deleted and cleared data for " + guild + ".");
GLog.info(player.getName() + " deleted guild " + guild);
return true;
}

View file

@ -2,6 +2,7 @@ package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.util.GBase;
import me.totalfreedom.tfguilds.util.GLog;
import me.totalfreedom.tfguilds.util.GMessage;
import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -20,7 +21,7 @@ public class GuildAdminCommand extends GBase implements CommandExecutor
Player player = (Player) sender;
if (!plugin.tfmb.isAdmin(player))
{
player.sendMessage(ChatColor.RED + "No permission.");
player.sendMessage(GMessage.NO_PERMISSION);
return true;
}
@ -32,7 +33,7 @@ public class GuildAdminCommand extends GBase implements CommandExecutor
String guild = GUtil.getGuild(args[1]);
if (guild == null)
{
player.sendMessage(ChatColor.RED + "Guild not found.");
player.sendMessage(GMessage.GUILD_NOT_FOUND);
return true;
}
@ -56,13 +57,13 @@ public class GuildAdminCommand extends GBase implements CommandExecutor
{
if (GUtil.isConsole(sender))
{
sender.sendMessage(ChatColor.RED + "You are not allowed to run this command.");
sender.sendMessage(GMessage.PLAYER_ONLY);
return true;
}
if (GUtil.isGuildMember(player, GUtil.getGuild(player)))
{
player.sendMessage(ChatColor.RED + "You are already in a guild.");
player.sendMessage(GMessage.IN_GUILD);
return true;
}

View file

@ -1,9 +1,9 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.util.GBase;
import me.totalfreedom.tfguilds.util.GMessage;
import me.totalfreedom.tfguilds.util.GUtil;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@ -19,18 +19,18 @@ public class GuildChatCommand extends GBase implements CommandExecutor
return false;
}
Player player = (Player) sender;
if (GUtil.isConsole(player))
if (GUtil.isConsole(sender))
{
sender.sendMessage(ChatColor.RED + "You are not allowed to run this command.");
sender.sendMessage(GMessage.PLAYER_ONLY);
return true;
}
Player player = (Player) sender;
String guild = GUtil.getGuild(player);
if (guild == null)
{
sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
sender.sendMessage(GMessage.NOT_IN_GUILD);
return true;
}

View file

@ -1,8 +1,8 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.util.GBase;
import me.totalfreedom.tfguilds.util.GMessage;
import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@ -15,15 +15,20 @@ public class GuildInfoCommand extends GBase implements CommandExecutor
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
Player player = (Player) sender;
if (args.length == 0)
{
if (GUtil.isConsole(sender))
{
sender.sendMessage(GUtil.color("&cProvide a guild name."));
return true;
}
Player player = (Player) sender;
String guild = GUtil.getGuild(player);
if (guild == null)
{
sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
player.sendMessage(GMessage.NOT_IN_GUILD);
return true;
}
@ -46,7 +51,7 @@ public class GuildInfoCommand extends GBase implements CommandExecutor
String guild = GUtil.getGuild(args[0]);
if (guild == null)
{
sender.sendMessage(ChatColor.RED + "Guild not found.");
sender.sendMessage(GMessage.GUILD_NOT_FOUND);
return true;
}
@ -55,14 +60,14 @@ public class GuildInfoCommand extends GBase implements CommandExecutor
String creation = GUtil.getTimeCreated(guild);
List<String> members = GUtil.getMember(guild);
player.sendMessage(GUtil.color("&2-=-=-=- &aGuild Information &2-=-=-=-"));
player.sendMessage(GUtil.color("&2Guild Name: &a" + guild));
player.sendMessage(GUtil.color("&2Guild Owner: &a" + owner));
player.sendMessage(GUtil.color("&2Guild Tag: &a" + tag));
player.sendMessage(GUtil.color("&2Guild Creation Date: &a" + creation));
player.sendMessage(GUtil.color("&2Member Count: &a" + members.size()));
player.sendMessage(GUtil.color("&2Members: &a" + members));
player.sendMessage(GUtil.color("&2-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"));
sender.sendMessage(GUtil.color("&2-=-=-=- &aGuild Information &2-=-=-=-"));
sender.sendMessage(GUtil.color("&2Guild Name: &a" + guild));
sender.sendMessage(GUtil.color("&2Guild Owner: &a" + owner));
sender.sendMessage(GUtil.color("&2Guild Tag: &a" + tag));
sender.sendMessage(GUtil.color("&2Guild Creation Date: &a" + creation));
sender.sendMessage(GUtil.color("&2Member Count: &a" + members.size()));
sender.sendMessage(GUtil.color("&2Members: &a" + members));
sender.sendMessage(GUtil.color("&2-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"));
return true;
}
}

View file

@ -1,6 +1,7 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.util.GBase;
import me.totalfreedom.tfguilds.util.GMessage;
import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -21,37 +22,44 @@ public class GuildKickCommand extends GBase implements CommandExecutor
return false;
}
Player player = (Player) sender;
if (GUtil.isConsole(player))
if (GUtil.isConsole(sender))
{
sender.sendMessage(ChatColor.RED + "You are not allowed to run this command.");
sender.sendMessage(GMessage.PLAYER_ONLY);
return true;
}
Player player = (Player) sender;
String guild = GUtil.getGuild(player);
if (guild == null)
{
sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
player.sendMessage(GMessage.NOT_IN_GUILD);
return true;
}
String owner = GUtil.getOwner(guild);
if (!owner.equalsIgnoreCase(player.getName()))
{
sender.sendMessage(ChatColor.RED + "You aren't the owner of your guild!");
player.sendMessage(GMessage.NOT_OWNER);
return true;
}
Player target = Bukkit.getPlayer(args[0]);
if (target == null)
{
sender.sendMessage(ChatColor.RED + "Player not found");
player.sendMessage(GMessage.PLAYER_NOT_FOUND);
return true;
}
if (!GUtil.isGuildMember(target, GUtil.getGuild(player)))
{
player.sendMessage(ChatColor.RED + "That player isn't in your guild.");
return true;
}
if (target == player)
{
sender.sendMessage(ChatColor.RED + "You may not kick yourself.");
player.sendMessage(ChatColor.RED + "You may not kick yourself.");
return true;
}
@ -66,7 +74,7 @@ public class GuildKickCommand extends GBase implements CommandExecutor
p.sendMessage(ChatColor.RED + target.getName() + " has been kicked from the guild");
}
}
sender.sendMessage(ChatColor.GREEN + "Successfully kicked " + target.getName() + " from the guild");
player.sendMessage(ChatColor.GREEN + "Successfully kicked " + target.getName() + " from the guild");
target.sendMessage(ChatColor.RED + "You have been kicked from guild " + guild);
return true;
}

View file

@ -1,8 +1,8 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.util.GBase;
import me.totalfreedom.tfguilds.util.GMessage;
import me.totalfreedom.tfguilds.util.GUtil;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@ -19,25 +19,25 @@ public class GuildTagCommand extends GBase implements CommandExecutor
return false;
}
Player player = (Player) sender;
if (GUtil.isConsole(player))
if (GUtil.isConsole(sender))
{
sender.sendMessage(ChatColor.RED + "You are not allowed to run this command.");
sender.sendMessage(GMessage.PLAYER_ONLY);
return true;
}
Player player = (Player) sender;
String guild = GUtil.getGuild(player);
if (guild == null)
{
sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
player.sendMessage(GMessage.NOT_IN_GUILD);
return true;
}
String owner = GUtil.getOwner(guild);
if (!owner.equalsIgnoreCase(player.getName()))
{
sender.sendMessage(ChatColor.RED + "You aren't the owner of your guild!");
player.sendMessage(GMessage.NOT_OWNER);
return true;
}
@ -47,12 +47,12 @@ public class GuildTagCommand extends GBase implements CommandExecutor
{
if (!args[1].toLowerCase().contains(guild))
{
sender.sendMessage(ChatColor.RED + "Your guild tag must contain your guild name.");
player.sendMessage(ChatColor.RED + "Your guild tag must contain your guild name.");
return true;
}
GUtil.setTag(GUtil.color(args[1]) + " ", guild);
sender.sendMessage(ChatColor.GREEN + "Guild tag set to \"" + GUtil.color(args[1]) + ChatColor.GREEN + "\"");
player.sendMessage(ChatColor.GREEN + "Guild tag set to \"" + GUtil.color(args[1]) + ChatColor.GREEN + "\"");
return true;
}
return false;
@ -63,7 +63,7 @@ public class GuildTagCommand extends GBase implements CommandExecutor
return false;
}
GUtil.setTag(GUtil.color("&8[&7" + guild + "&8]&r "), guild);
sender.sendMessage(ChatColor.GRAY + "Removed your guild's tag.");
player.sendMessage(ChatColor.GRAY + "Removed your guild's tag.");
return true;
}
}

View file

@ -1,5 +1,6 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.util.GMessage;
import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -21,35 +22,37 @@ public class GuildTeleportCommand implements CommandExecutor
if (GUtil.isConsole(sender))
{
sender.sendMessage(ChatColor.RED + "You are not allowed to run this command.");
sender.sendMessage(GMessage.PLAYER_ONLY);
return true;
}
String guild = GUtil.getGuild((Player) sender);
Player player = (Player) sender;
String guild = GUtil.getGuild(player);
if (guild == null)
{
sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
player.sendMessage(GMessage.NOT_IN_GUILD);
return true;
}
Player target = Bukkit.getPlayer(args[0]);
if (target == null)
{
sender.sendMessage(ChatColor.RED + "Player not found.");
player.sendMessage(GMessage.PLAYER_NOT_FOUND);
return true;
}
if (!GUtil.isGuildMember(target, GUtil.getGuild((Player) sender)))
if (!GUtil.isGuildMember(target, GUtil.getGuild(player)))
{
sender.sendMessage(ChatColor.RED + "That player isn't in your guild.");
player.sendMessage(ChatColor.RED + "That player isn't in your guild.");
return true;
}
Location targetLoc = target.getLocation();
((Player) sender).teleport(targetLoc);
player.teleport(targetLoc);
sender.sendMessage(ChatColor.GREEN + "Teleported to " + target.getName() + " successfully.");
target.sendMessage(ChatColor.GREEN + sender.getName() + " has teleported to you.");
target.sendMessage(ChatColor.GREEN + player.getName() + " has teleported to you.");
return true;
}
}

View file

@ -1,6 +1,7 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.util.GBase;
import me.totalfreedom.tfguilds.util.GMessage;
import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -23,7 +24,7 @@ public class InviteGuildCommand extends GBase implements CommandExecutor
if (GUtil.isConsole(sender))
{
sender.sendMessage(ChatColor.RED + "You are not allowed to run this command.");
sender.sendMessage(GMessage.PLAYER_ONLY);
return true;
}
@ -37,7 +38,8 @@ public class InviteGuildCommand extends GBase implements CommandExecutor
player.sendMessage(ChatColor.RED + "That player is already in a guild.");
return true;
}
target.sendMessage(GUtil.color("&a" + sender.getName() + " has invited you to join &a&l" + GUtil.getGuild(player) + "&a."));
target.sendMessage(GUtil.color("&a" + player.getName() + " has invited you to join &a&l" + GUtil.getGuild(player) + "&a."));
GUtil.invitePlayer(target, GUtil.getGuild(player), 60);
player.sendMessage(GUtil.color("&aSent an invitation to " + target.getName()));
return true;
@ -62,6 +64,7 @@ public class InviteGuildCommand extends GBase implements CommandExecutor
}
}
}
if (args[0].equalsIgnoreCase("deny"))
{
GUtil.invitedPlayers.remove(player.getName());
@ -70,7 +73,7 @@ public class InviteGuildCommand extends GBase implements CommandExecutor
return true;
}
sender.sendMessage(ChatColor.RED + "Player not found.");
player.sendMessage(ChatColor.RED + "Player not found.");
return true;
}
}

View file

@ -1,6 +1,7 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.util.GBase;
import me.totalfreedom.tfguilds.util.GMessage;
import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -16,35 +17,35 @@ public class LeaveGuildCommand extends GBase implements CommandExecutor
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
Player player = (Player) sender;
if (GUtil.isConsole(player))
if (GUtil.isConsole(sender))
{
sender.sendMessage(ChatColor.RED + "You are not allowed to run this command.");
sender.sendMessage(GMessage.PLAYER_ONLY);
return true;
}
Player player = (Player) sender;
String guild = GUtil.getGuild(player);
if (guild == null)
{
sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
player.sendMessage(GMessage.NOT_IN_GUILD);
return true;
}
String owner = GUtil.getOwner(guild);
if (owner.equalsIgnoreCase(player.getName()))
{
sender.sendMessage(ChatColor.RED + "You may not leave your guild. However, if you want to delete it run /disbandguild");
player.sendMessage(ChatColor.RED + "You may not leave your guild. However, if you want to delete it run /disbandguild");
return true;
}
if (args.length == 0)
{
sender.sendMessage(ChatColor.RED + "Are you sure you want to leave your guild? Type 'CONFIRM' to continue.");
player.sendMessage(ChatColor.RED + "Are you sure you want to leave your guild? Type 'CONFIRM' to continue.");
return true;
}
if (args[0].toLowerCase().equalsIgnoreCase("confirm"))
if (args[0].equalsIgnoreCase("confirm"))
{
List<String> players = plugin.guilds.getStringList("guilds." + guild + ".members");
players.remove(player.getName());
@ -57,7 +58,7 @@ public class LeaveGuildCommand extends GBase implements CommandExecutor
p.sendMessage(ChatColor.RED + player.getName() + " has left the guild");
}
}
sender.sendMessage(ChatColor.GREEN + "Successfully left " + guild + ".");
player.sendMessage(ChatColor.GREEN + "Successfully left " + guild + ".");
return true;
}
return true;

View file

@ -2,8 +2,8 @@ package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.util.GBase;
import me.totalfreedom.tfguilds.util.GLog;
import me.totalfreedom.tfguilds.util.GMessage;
import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@ -18,7 +18,9 @@ public class TfGuildsCommand extends GBase implements CommandExecutor
{
sender.sendMessage(GUtil.color("&aTFGuilds &2is a plugin which allows for players to make their own guilds, providing guild chat, guild teleportation, and more."));
sender.sendMessage(String.format(GUtil.color("&2Version &av%s"), plugin.getDescription().getVersion()));
sender.sendMessage(GUtil.color("&2Developed by &aspeednt & supernt"));
sender.sendMessage(GUtil.color("&2Developed by &aspeednt"));
sender.sendMessage(GUtil.color("&2Contributors"));
sender.sendMessage(GUtil.color("&a- supernt"));
sender.sendMessage(GUtil.color("&2https://github.com/speedxx/TFGuilds"));
return true;
}
@ -27,7 +29,7 @@ public class TfGuildsCommand extends GBase implements CommandExecutor
{
if (!plugin.tfmb.isAdmin((Player) sender))
{
sender.sendMessage(ChatColor.RED + "No permission.");
sender.sendMessage(GMessage.NO_PERMISSION);
return true;
}

View file

@ -0,0 +1,14 @@
package me.totalfreedom.tfguilds.util;
import org.bukkit.ChatColor;
public class GMessage
{
public static String NO_PERMISSION = ChatColor.RED + "No permission.";
public static String PLAYER_ONLY = ChatColor.RED + "You are not allowed to run this command.";
public static String IN_GUILD = ChatColor.RED + "You are already in a guild!";
public static String NOT_OWNER = ChatColor.RED + "You aren't the owner of your guild.";
public static String GUILD_NOT_FOUND = ChatColor.RED + "Guild not found.";
public static String NOT_IN_GUILD = ChatColor.RED + "You aren't in a guild!";
public static String PLAYER_NOT_FOUND = ChatColor.RED + "Player not found.";
}