use of com.alessiodp.partiesapi.events.PartiesChatEvent in project Parties by AlessioDP.
the class ChatListener method onPlayerChat.
@EventHandler(priority = EventPriority.LOW)
public void onPlayerChat(AsyncPlayerChatEvent event) {
if (!event.isCancelled()) {
Player p = event.getPlayer();
PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(p.getUniqueId());
if (!pp.getPartyName().isEmpty() && pp.isChatParty()) {
// Make it async
plugin.getPartiesScheduler().getEventsExecutor().execute(() -> {
if (PartiesUtils.checkPlayerRankAlerter(pp, PartiesPermission.PRIVATE_SENDMESSAGE)) {
// Chat allowed
boolean mustWait = false;
if (ConfigParties.GENERAL_CHAT_CHATCD > 0 && !PartiesUtils.checkPlayerRank(pp, PartiesPermission.PRIVATE_BYPASSCOOLDOWN)) {
Long unixTimestamp = plugin.getPlayerManager().getChatCooldown().get(p.getUniqueId());
long unixNow = System.currentTimeMillis() / 1000L;
// Check cooldown
if (unixTimestamp != null) {
pp.sendMessage(Messages.MAINCMD_P_COOLDOWN.replace("%seconds%", String.valueOf(ConfigParties.GENERAL_CHAT_CHATCD - (unixNow - unixTimestamp))));
mustWait = true;
} else {
plugin.getPlayerManager().getChatCooldown().put(p.getUniqueId(), unixNow);
new ChatTask(p.getUniqueId(), 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}", p.getName()), true);
}
}
if (!mustWait) {
PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
// Calling API event
PartiesChatEvent partiesChatEvent = new PartiesChatEvent(pp, party, event.getMessage());
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}", p.getName()).replace("{message}", newMessage), true);
} else
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_CHATEVENT_DENY.replace("{player}", p.getName()).replace("{message}", event.getMessage()), true);
}
} else
pp.sendNoPermission(PartiesPermission.PRIVATE_SENDMESSAGE);
});
event.setCancelled(true);
}
}
}
use of com.alessiodp.partiesapi.events.PartiesChatEvent 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);
}
Aggregations