use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class CommandMotd method onCommand.
@Override
public void onCommand(CommandData commandData) {
PartyPlayerEntity pp = commandData.getPartyPlayer();
PartyEntity party = commandData.getParty();
/*
* Command handling
*/
boolean isRemove = false;
String motd = "";
if (commandData.getArgs()[1].equalsIgnoreCase(ConfigMain.COMMANDS_SUB_REMOVE)) {
// Remove command
isRemove = true;
} else {
StringBuilder sb = new StringBuilder();
for (int word = 1; word < commandData.getArgs().length; word++) {
if (sb.length() > 0)
sb.append(" ");
sb.append(commandData.getArgs()[word]);
}
if (!Pattern.compile(ConfigParties.MOTD_ALLOWEDCHARS).matcher(sb.toString()).matches() || (sb.toString().length() > ConfigParties.MOTD_MAXLENGTH) || (sb.toString().length() < ConfigParties.MOTD_MINLENGTH)) {
pp.sendMessage(Messages.ADDCMD_MOTD_INVALID);
return;
}
if (PartiesUtils.checkCensor(sb.toString())) {
pp.sendMessage(Messages.ADDCMD_MOTD_CENSORED);
return;
}
if (VaultHandler.payCommand(VaultHandler.VaultCommand.MOTD, pp, commandData.getCommandLabel(), commandData.getArgs()))
return;
motd = sb.toString();
}
/*
* Command starts
*/
party.setMotd(motd);
party.updateParty();
if (isRemove) {
pp.sendMessage(Messages.ADDCMD_MOTD_REMOVED);
LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_MOTD.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
} else {
pp.sendMessage(Messages.ADDCMD_MOTD_CHANGED);
party.sendBroadcast(pp, Messages.ADDCMD_MOTD_BROADCAST);
LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_MOTD_REM.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
}
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class CommandP method onCommand.
@Override
public void onCommand(CommandData commandData) {
PartyPlayerEntity pp = commandData.getPartyPlayer();
PartyEntity party = commandData.getParty();
/*
* Command handling
*/
if (ConfigParties.GENERAL_CHAT_CHATCD > 0 && !PartiesUtils.checkPlayerRank(pp, PartiesPermission.PRIVATE_BYPASSCOOLDOWN)) {
Long unixTimestamp = plugin.getPlayerManager().getChatCooldown().get(pp.getPlayerUUID());
long unixNow = System.currentTimeMillis() / 1000L;
if (unixTimestamp != null) {
pp.sendMessage(Messages.MAINCMD_P_COOLDOWN.replace("%seconds%", String.valueOf(ConfigParties.GENERAL_CHAT_CHATCD - (unixNow - unixTimestamp))));
return;
}
plugin.getPlayerManager().getChatCooldown().put(pp.getPlayerUUID(), unixNow);
new ChatTask(pp.getPlayerUUID(), plugin.getPlayerManager()).runTaskLater(plugin, ConfigParties.GENERAL_CHAT_CHATCD * 20);
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_CMD_P_TASK.replace("{value}", Integer.toString(ConfigParties.GENERAL_CHAT_CHATCD * 20)).replace("{player}", pp.getName()), true);
}
/*
* Command starts
*/
StringBuilder sb = new StringBuilder();
for (String word : commandData.getArgs()) {
if (sb.length() > 0) {
sb.append(" ");
}
sb.append(word);
}
// Calling API event
PartiesChatEvent partiesChatEvent = new PartiesChatEvent(pp, party, sb.toString());
Bukkit.getServer().getPluginManager().callEvent(partiesChatEvent);
String newMessage = partiesChatEvent.getMessage();
if (!partiesChatEvent.isCancelled()) {
party.sendPlayerMessage(pp, newMessage);
if (ConfigMain.STORAGE_LOG_CHAT)
LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_CMD_P.replace("{party}", party.getName()).replace("{player}", pp.getName()).replace("{message}", newMessage), true);
} else
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_CHATEVENT_DENY.replace("{player}", pp.getName()).replace("{message}", sb.toString()), true);
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class CommandParty method onCommand.
@Override
public void onCommand(CommandData commandData) {
PartyPlayerEntity pp = commandData.getPartyPlayer();
/*
* Command starts
*/
List<String> list = new ArrayList<String>();
LinkedHashMap<String, String> commands = pp.getAllowedCommands();
for (Entry<String, String> entry : commands.entrySet()) {
list.add(entry.getValue());
}
// Split commands per page
int page = 1;
int maxpages;
if (list.size() == 0)
maxpages = 1;
else if ((list.size() % ConfigMain.COMMANDS_HELP_PERPAGE) == 0)
maxpages = list.size() / ConfigMain.COMMANDS_HELP_PERPAGE;
else
maxpages = (list.size() / ConfigMain.COMMANDS_HELP_PERPAGE) + 1;
// Start priting
int commandNumber = 0;
String message = Messages.HELP_HEADER.replace("%page%", Integer.toString(page)).replace("%maxpages%", Integer.toString(maxpages)) + "\n";
for (String string : list) {
int currentChoosenPage = (page - 1) * ConfigMain.COMMANDS_HELP_PERPAGE;
if (commandNumber >= currentChoosenPage && commandNumber < currentChoosenPage + ConfigMain.COMMANDS_HELP_PERPAGE) {
message += string + "\n";
}
commandNumber++;
}
message += Messages.HELP_FOOTER.replace("%page%", Integer.toString(page)).replace("%maxpages%", Integer.toString(maxpages));
pp.sendMessage(message);
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class CommandPassword method preRequisites.
@Override
public boolean preRequisites(CommandData commandData) {
Player player = (Player) commandData.getSender();
PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(player.getUniqueId());
/*
* Checks for command prerequisites
*/
if (!player.hasPermission(PartiesPermission.PASSWORD.toString())) {
pp.sendNoPermission(PartiesPermission.PASSWORD);
return false;
}
PartyEntity party = pp.getPartyName().isEmpty() ? null : plugin.getPartyManager().getParty(pp.getPartyName());
if (party == null) {
pp.sendMessage(Messages.PARTIES_COMMON_NOTINPARTY);
return false;
}
if (!PartiesUtils.checkPlayerRankAlerter(pp, PartiesPermission.PRIVATE_EDIT_PASSWORD))
return false;
if (commandData.getArgs().length != 2) {
pp.sendMessage(Messages.ADDCMD_PASSWORD_WRONGCMD);
return false;
}
commandData.setPlayer(player);
commandData.setPartyPlayer(pp);
commandData.setParty(party);
return true;
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class CommandPassword method onCommand.
@Override
public void onCommand(CommandData commandData) {
PartyPlayerEntity pp = commandData.getPartyPlayer();
PartyEntity party = commandData.getParty();
/*
* Command handling
*/
boolean isRemove = false;
String password = "";
if (commandData.getArgs()[1].equalsIgnoreCase(ConfigMain.COMMANDS_SUB_REMOVE)) {
// Remove command
isRemove = true;
} else {
// Normal command
if (!Pattern.compile(ConfigParties.PASSWORD_ALLOWECHARS).matcher(commandData.getArgs()[1]).matches() || (commandData.getArgs()[1].length() > ConfigParties.PASSWORD_MAXLENGTH) || (commandData.getArgs()[1].length() < ConfigParties.PASSWORD_MINLENGTH)) {
pp.sendMessage(Messages.ADDCMD_PASSWORD_INVALID);
return;
}
password = hash(commandData.getArgs()[1]);
}
/*
* Command starts
*/
party.setPassword(password);
party.updateParty();
if (isRemove) {
pp.sendMessage(Messages.ADDCMD_PASSWORD_REMOVED);
LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_PASSWORD_REM.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
} else {
pp.sendMessage(Messages.ADDCMD_PASSWORD_CHANGED);
party.sendBroadcast(pp, Messages.ADDCMD_PASSWORD_BROADCAST);
LoggerManager.log(LogLevel.MEDIUM, Constants.DEBUG_CMD_PASSWORD.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
}
}
Aggregations