use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class MoveListener method onPlayerMove.
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
if (ConfigParties.HOME_MOVING) {
// Make it async
plugin.getPartiesScheduler().getEventsExecutor().execute(() -> {
if (plugin.getPlayerManager().getHomeCounts() != 0) {
if (event.getFrom().getBlockX() != event.getTo().getBlockX() || event.getFrom().getBlockY() != event.getTo().getBlockY() || event.getFrom().getBlockZ() != event.getTo().getBlockZ()) {
// Player moved
PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(event.getPlayer().getUniqueId());
if (pp.getHomeTask() != -1) {
if (pp.getHomeFrom().distance(event.getTo()) > ConfigParties.HOME_DISTANCE) {
// Cancel home
plugin.getServer().getScheduler().cancelTask(pp.getHomeTask());
plugin.getPlayerManager().remHomeCount();
pp.setHomeTask(-1);
pp.sendMessage(Messages.ADDCMD_HOME_TELEPORTDENIED);
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_TASK_HOME_DENIED_MOVING.replace("{player}", pp.getName()), true);
}
}
}
}
});
}
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class MoveListener method onPlayerGotHit.
@EventHandler
public void onPlayerGotHit(EntityDamageByEntityEvent event) {
if (event.getEntity() instanceof Player && ConfigParties.HOME_HIT) {
// Make it async
plugin.getPartiesScheduler().getEventsExecutor().execute(() -> {
if (plugin.getPlayerManager().getHomeCounts() != 0) {
PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(event.getEntity().getUniqueId());
if (pp.getHomeTask() != -1) {
plugin.getServer().getScheduler().cancelTask(pp.getHomeTask());
plugin.getPlayerManager().remHomeCount();
pp.setHomeTask(-1);
pp.sendMessage(Messages.ADDCMD_HOME_TELEPORTDENIED);
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_TASK_HOME_DENIED_FIGHT.replace("{player}", pp.getName()), true);
}
}
});
}
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class TabCompleterHandler method onTabComplete.
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String commandLabel, String[] args) {
if (sender instanceof Player) {
if (cmd.getName().equalsIgnoreCase(ConfigMain.COMMANDS_CMD_PARTY)) {
if (args.length == 1) {
PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(((Player) sender).getUniqueId());
LinkedHashMap<String, String> commands = pp.getAllowedCommands();
List<String> list = new ArrayList<String>();
for (String str : commands.keySet()) {
if (str.equalsIgnoreCase(ConfigMain.COMMANDS_CMD_P))
continue;
list.add(str);
}
for (Iterator<String> iterator = list.iterator(); iterator.hasNext(); ) {
String str = iterator.next();
if (!str.startsWith(args[0]))
iterator.remove();
}
return list;
}
}
}
return null;
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class EssentialsChatHandler method onChatPlayer.
@EventHandler
public void onChatPlayer(AsyncPlayerChatEvent event) {
String old = event.getFormat();
if (old.toLowerCase().contains("{parties_")) {
// Bypass useless checks if parties doesn't exist
boolean somethingChanged = false;
PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(event.getPlayer().getUniqueId());
PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
Pattern pat = Pattern.compile("\\{parties_([a-z\\_]+)\\}", Pattern.CASE_INSENSITIVE);
Matcher mat = pat.matcher(old);
while (mat.find()) {
String base = mat.group(0);
String identifier = mat.group(1);
if (identifier != null) {
PartiesPlaceholder ph = PartiesPlaceholder.getPlaceholder(identifier);
if (ph != null) {
old = old.replace(base, ph.formatPlaceholder(pp, party));
somethingChanged = true;
}
}
}
if (somethingChanged)
event.setFormat(old);
}
}
use of com.alessiodp.parties.players.objects.PartyPlayerEntity in project Parties by AlessioDP.
the class BungeeService method onPluginMessageReceived.
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
if (!channel.equals(partiesChannel)) {
return;
}
ByteArrayInputStream stream = new ByteArrayInputStream(message);
DataInputStream in = new DataInputStream(stream);
// Load entities
PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(player.getUniqueId());
PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
try {
// Get packet in input
Packet packet = new Packet(in);
if (packet.getVersion().equals(plugin.getDescription().getVersion())) {
// Does the player have a party
if (party != null) {
// Check for rank needed to follow
if (pp.getRank() < packet.getRankNeeded())
return;
// Preparing a list that contains the name of each player to teleport
List<String> list = new ArrayList<String>();
for (Player pl : party.getOnlinePlayers()) {
UUID pUuid = pl.getUniqueId();
if (!pUuid.equals(player.getUniqueId())) {
// Have the player the minimum rank to follow?
if (plugin.getPlayerManager().getPlayer(pUuid).getRank() >= packet.getRankMinimum()) {
list.add(pUuid.toString());
}
}
}
// Set the info list
packet.setInfo(list);
// Set the message for the user
packet.setMessage(ChatColor.translateAlternateColorCodes('&', Messages.OTHER_FOLLOW_SERVER.replace("%server%", packet.getServer())));
// Send the output
ByteArrayOutputStream outstream = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(outstream);
packet.write(out);
try {
Player p = Bukkit.getServer().getOnlinePlayers().iterator().next();
if (p != null) {
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_BUNGEE_REPLY, true);
p.sendPluginMessage(plugin, partiesChannel, outstream.toByteArray());
}
} catch (Exception ex) {
// Server empty
}
}
} else {
LoggerManager.printError(Constants.DEBUG_BUNGEE_VERSIONMISMATCH.replace("{packet}", packet.getVersion()));
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
Aggregations