Skip to content

Commit

Permalink
[ERREUR] Merge du players et freeze
Browse files Browse the repository at this point in the history
  • Loading branch information
gab4000 committed Jul 7, 2024
1 parent 9a20bd7 commit 4f7d6c9
Show file tree
Hide file tree
Showing 10 changed files with 295 additions and 111 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ version = '1.0-SNAPSHOT'

repositories {
mavenCentral()
mavenLocal()
maven {
name = "spigotmc-repo"
url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/"
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/fr/communaywen/core/AywenCraftPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@
import fr.communaywen.core.utils.command.InteractiveHelpMenu;
import fr.communaywen.core.utils.database.DatabaseManager;
import fr.communaywen.core.staff.freeze.FreezeCommand;
import fr.communaywen.core.staff.freeze.FreezeListener;
import fr.communaywen.core.listeners.FreezeListener;

import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.luckperms.api.LuckPerms;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import revxrsal.commands.bukkit.BukkitCommandHandler;

import java.util.HashSet;
Expand All @@ -36,7 +39,7 @@
import java.io.File;

public final class AywenCraftPlugin extends JavaPlugin {
private final Set<UUID> frozenPlayers = new HashSet<>();
public ArrayList<Player> frozenPlayers = new ArrayList<>();


private MOTDChanger motdChanger;
Expand Down Expand Up @@ -131,8 +134,7 @@ public void onEnable() {
this.getCommand("tpaccept").setExecutor(new CommandTpaccept());
this.getCommand("tpdeny").setExecutor(new CommandTpdeny());

this.getCommand("freeze").setExecutor(new FreezeCommand(this));
this.getCommand("unfreeze").setExecutor(new FreezeCommand(this));
this.getCommand("freeze").setExecutor(new FreezeCommand());



Expand Down Expand Up @@ -185,7 +187,7 @@ public void onDisable() {
this.quizManager.close();
}

public Set<UUID> getFrozenPlayers() {
public ArrayList<Player> getFrozenPlayers() {
return frozenPlayers;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package fr.communaywen.core.staff.freeze;
package fr.communaywen.core.listeners;

import fr.communaywen.core.AywenCraftPlugin;
import fr.communaywen.core.utils.FreezeUtils;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;

import java.net.http.WebSocket;
import java.util.Date;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
Expand All @@ -22,14 +25,6 @@ public FreezeListener(AywenCraftPlugin plugin) {
this.plugin = plugin;
}

@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
if (plugin.getFrozenPlayers().contains(player.getUniqueId())) {
event.setCancelled(true);
}
}

@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
Expand All @@ -42,4 +37,21 @@ public void onPlayerQuit(PlayerQuitEvent event) {

}
}

@EventHandler
public void onPlayerMove(PlayerMoveEvent e) {
Player player = e.getPlayer();
if (plugin.frozenPlayers.contains(player)) {
e.setTo(e.getFrom());
player.sendMessage(FreezeUtils.prefix + ChatColor.DARK_RED + "Vous êtes freeze !");
}
}

@EventHandler
public void onDamage(EntityDamageEvent e) {
Entity entity = e.getEntity();
if (entity instanceof Player && plugin.frozenPlayers.contains(entity)) {
e.setCancelled(true);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package fr.communaywen.core.listeners;


import fr.communaywen.core.utils.FreezeUtils;
import fr.communaywen.core.utils.PlayersMenuUtils;
import org.bukkit.BanList;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;

import java.util.Objects;

public class PlayersMenuListener implements Listener {

@EventHandler
public void onMenuClick(InventoryClickEvent e) {
Player player = (Player) e.getWhoClicked();

if (e.getView().getTitle().equalsIgnoreCase(ChatColor.BLUE + "Liste des joueurs")) {
if (Objects.requireNonNull(e.getCurrentItem()).getType() == (Material.PLAYER_HEAD)) {
Player target = player.getServer().getPlayerExact(ChatColor.stripColor(Objects.requireNonNull(e.getCurrentItem().getItemMeta()).getDisplayName()));
assert target != null;
PlayersMenuUtils.openDetailsPlayersMenu(player, target);
}
e.setCancelled(true);
} else if (e.getView().getTitle().equalsIgnoreCase(ChatColor.BLUE + "Détails")) {
Player target = player.getServer().getPlayerExact(ChatColor.stripColor(e.getClickedInventory().getItem(4).getItemMeta().getDisplayName()));
if (e.getCurrentItem().getType() == Material.BARRIER) {
PlayersMenuUtils.openPlayersMenu(player);
return;
}
else if (e.getCurrentItem().getType() == Material.COMPASS) {
assert target != null;
player.teleport(target.getLocation());
player.sendMessage(ChatColor.DARK_GREEN + "Vous avez été téléporté au joueur " + ChatColor.BLUE + target.getDisplayName() + ChatColor.DARK_GREEN + " !");
player.closeInventory();
}
else if (e.getCurrentItem().getType() == Material.ENDER_EYE) {
assert target != null;
player.openInventory(target.getInventory());
}
else if (e.getCurrentItem().getType() == Material.PACKED_ICE) {
FreezeUtils.switch_freeze(player, target);
player.closeInventory();
}
else if (e.getCurrentItem().getType() == Material.WOODEN_AXE) {
assert target != null;
String name = target.getDisplayName();
player.getServer().getBanList(BanList.Type.NAME).addBan(name, "Aucune raison spécifiée", null, player.getDisplayName());
player.sendMessage(ChatColor.BLUE + name + ChatColor.DARK_RED + " a bien été banni !");
target.kickPlayer("Vous avez été banni pour Aucune raison spécifiée");
player.closeInventory();
}
e.setCancelled(true);
}
}
}
66 changes: 23 additions & 43 deletions src/main/java/fr/communaywen/core/staff/freeze/FreezeCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fr.communaywen.core.staff.freeze;

import fr.communaywen.core.AywenCraftPlugin;
import org.bukkit.Bukkit;
import fr.communaywen.core.utils.FreezeUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand All @@ -10,51 +10,31 @@

public class FreezeCommand implements CommandExecutor {

private final AywenCraftPlugin plugin;

public FreezeCommand(AywenCraftPlugin plugin) {

this.plugin = plugin;
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("§cLa commande ne peut seulement être exécutée par un joueur");
return true;
}

Player player = (Player) sender;
if (!player.hasPermission("openmc.staff.freeze")) {
player.sendMessage("§cHé, tu ne peut pas faire ça !");
return true;
}

if (args.length != 1) {
player.sendMessage("§cUsage: /freeze [joueur]");
return true;
if (sender instanceof Player player) {
if (!player.hasPermission("openmc.staff.freeze")) {
if (args.length == 1) {
Player target = player.getServer().getPlayer(args[0]);

if (target == null) {
player.sendMessage(ChatColor.RED + "Ce joueur n'existe pas ou n'est pas connecté");
return false;
}

FreezeUtils.switch_freeze(player, target);
} else {
player.sendMessage(ChatColor.RED + "La commande est " + ChatColor.BLUE + "/freeze <joueur>");
return false;
}
} else {
player.sendMessage(ChatColor.RED + "Hé, tu ne peut pas faire ça !");
return false;
}
} else {
sender.sendMessage(ChatColor.RED + "La commande ne peut seulement être exécutée par un joueur");
return false;
}

Player target = Bukkit.getPlayer(args[0]);
if (target == null) {
player.sendMessage("§cDésolé, le joueur n'est pas en ligne.");
return true;
}

if (target.equals(player)) {
player.sendMessage("§cTu ne peut pas te freeze toi même...");
return true;
}

if (plugin.getFrozenPlayers().contains(target.getUniqueId())) {
player.sendMessage("§cLe joueur est déjà freeze.");
return true;
}

plugin.getFrozenPlayers().add(target.getUniqueId());
target.sendTitle(ChatColor.RED + "Vous êtes freeze !", ChatColor.YELLOW + "Regardez votre chat", 10, 1000, 20);
target.sendMessage(ChatColor.RED + "Vous êtes Freeze, si vous déconnectez, vous serez banni !");
player.sendMessage(ChatColor.GREEN + target.getName() + " a bien été freeze.");
return true;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fr.communaywen.core.staff.players;

import fr.communaywen.core.utils.PlayersMenuUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class PlayersCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender instanceof Player player) {
if (args.length != 0) {
player.sendMessage(ChatColor.RED + "La commande est " + ChatColor.BLUE + "/players");
return false;
}
PlayersMenuUtils.openPlayersMenu(player);
} else {
return false;
}
return true;
}
}
37 changes: 37 additions & 0 deletions src/main/java/fr/communaywen/core/utils/FreezeUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package fr.communaywen.core.utils;

import fr.communaywen.core.AywenCraftPlugin;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;

import java.util.ArrayList;

public class FreezeUtils {
public static String prefix = ChatColor.GRAY + "[" + ChatColor.BLUE + "Freeze" + ChatColor.GRAY + "] ";

private static AywenCraftPlugin plugin;

public FreezeUtils(AywenCraftPlugin plugin) {
this.plugin = plugin;
}

public static void switch_freeze(Player player, Player target) {
if (target == null) {
player.sendMessage(prefix + ChatColor.DARK_RED + "Joueur introuvable !");
} else {
if (!plugin.frozenPlayers.contains(target)) {
target.sendTitle(ChatColor.DARK_RED + "Vous êtes freeze !", ChatColor.YELLOW + "Regardez votre chat", 10, 70, 20);
target.sendMessage(prefix + ChatColor.DARK_RED + "Vous êtes freeze, si vous déconnectez, vous serez banni !");
player.sendMessage(prefix + ChatColor.DARK_RED + "Vous avez freeze " + ChatColor.BLUE + target.getDisplayName() + ChatColor.DARK_RED + " !");
plugin.frozenPlayers.add(target);
PlayersMenuUtils.state = "§4Freeze";
} else {
target.resetTitle();
target.sendMessage(prefix + ChatColor.DARK_GREEN + "Tu a été unfreeze !");
player.sendMessage(prefix + ChatColor.DARK_GREEN + "Vous avez unfreeze " + ChatColor.BLUE + target.getDisplayName() + ChatColor.DARK_GREEN + " !");
plugin.frozenPlayers.remove(target);
PlayersMenuUtils.state = "§2Unfreeze";
}
}
}
}
Loading

0 comments on commit 4f7d6c9

Please sign in to comment.