From d12337856b01ce163e23e40e45c2755c7f84cf66 Mon Sep 17 00:00:00 2001 From: Denis Indenbom <59681620+denisindenbom@users.noreply.github.com> Date: Sat, 18 Dec 2021 21:06:32 +0300 Subject: [PATCH] fixed a bug with the kick "Flights are prohibited on the server" fixed an error of receiving fire damage during registration added aliases to commands such as login, registration and logout update README.md --- README.md | 5 ++- .../cyberauth/listeners/PlayerListener.java | 44 ++++++++++++------- .../cyberauth/logfilter/ConsoleFilter.java | 2 +- src/main/resources/plugin.yml | 10 ++++- 4 files changed, 41 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 772144e..adf9eda 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ CyberAuth prohibits unauthorized users: - hitting players - writing messages -The plugin also hashes all passwords - this means that no one can find out the user's password. +The plugin also hashes all passwords - this means that no one can find out the user's password. `For minecraft 1.17.x - 1.18.x` @@ -24,10 +24,12 @@ The plugin also hashes all passwords - this means that no one can find out the u Command **login**: - Usage: `/login ` - Description: This is the login command +- Aliases: `l`, `log` Command **register**: - Usage: `/register ` - Description: This is the command to register +- Aliases: `r`, `reg` Command **change_password**: - Usage: `/change_password ` @@ -36,6 +38,7 @@ Command **change_password**: Command **logout**: - Usage: `/logout` - Description: This is the command to log out +- Aliases: `lg` Command **removeuser**: - Usage: `/removeuser ` diff --git a/src/main/java/com/denisindenbom/cyberauth/listeners/PlayerListener.java b/src/main/java/com/denisindenbom/cyberauth/listeners/PlayerListener.java index 331512c..eb66153 100644 --- a/src/main/java/com/denisindenbom/cyberauth/listeners/PlayerListener.java +++ b/src/main/java/com/denisindenbom/cyberauth/listeners/PlayerListener.java @@ -20,14 +20,13 @@ import org.bukkit.event.entity.EntityPickupItemEvent; import org.bukkit.entity.EntityType; -import org.bukkit.event.entity.EntityDamageEvent.DamageCause; - import org.bukkit.scheduler.BukkitRunnable; import com.denisindenbom.cyberauth.CyberAuth; import com.denisindenbom.cyberauth.formattext.FormatText; import com.denisindenbom.cyberauth.messagesender.MessageSender; +import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; @@ -54,6 +53,7 @@ public PlayerListener(CyberAuth plugin, FileConfiguration messages, boolean kick @EventHandler public void onPlayerJoin(@NotNull PlayerJoinEvent event) { + // start the timer on the kick if (this.kick) this.timerKick(event.getPlayer(), this.authTime); String message; @@ -68,53 +68,69 @@ public void onPlayerJoin(@NotNull PlayerJoinEvent event) @EventHandler public void onPlayerQuit(@NotNull PlayerQuitEvent event) { + // delete player from list of authorized players this.plugin.getAuthManager().removeUserByName(event.getPlayer().getName()); } @EventHandler public void onPlayerInteract(@NotNull PlayerInteractEvent event) { + // check that player is authorized if (!userIsAuth(event.getPlayer())) event.setCancelled(true); } @EventHandler public void onPlayerChat(@NotNull PlayerChatEvent event) { + // check that player is authorized if (!userIsAuth(event.getPlayer())) event.setCancelled(true); } @EventHandler public void onPlayerMove(@NotNull PlayerMoveEvent event) { - if (!userIsAuth(event.getPlayer())) event.setCancelled(true); + // check that player is authorized + if (userIsAuth(event.getPlayer())) return; + + if(event.getTo() == null) return; + + // check that player move correctly + if (event.getFrom().getBlockX() == event.getTo().getBlockX() && + event.getFrom().getBlockZ() == event.getTo().getBlockZ() && + event.getFrom().getBlockY() - event.getTo().getBlockY() >= 0) return; + + // canceled event + event.setCancelled(true); } @EventHandler public void onPlayerItemDamage(@NotNull PlayerItemDamageEvent event) { + // check that player is authorized if (!userIsAuth(event.getPlayer())) event.setCancelled(true); } @EventHandler public void onPlayerPickupItem(@NotNull EntityPickupItemEvent event) { - if (event.getEntity().getType().equals(EntityType.PLAYER)) - { - Player player = (Player) event.getEntity(); + if (event.getEntity().getType().equals(EntityType.PLAYER)) return; - if (!userIsAuth(player)) event.setCancelled(true); - } + Player player = (Player) event.getEntity(); + // check that player is authorized + if (!userIsAuth(player)) event.setCancelled(true); } @EventHandler public void onPlayerPickupArrow(@NotNull PlayerPickupArrowEvent event) { + // check that player is authorized if (!userIsAuth(event.getPlayer())) event.setCancelled(true); } @EventHandler public void onPlayerDropItem(@NotNull PlayerDropItemEvent event) { + // check that player is authorized if (!userIsAuth(event.getPlayer())) event.setCancelled(true); } @@ -122,25 +138,19 @@ public void onPlayerDropItem(@NotNull PlayerDropItemEvent event) public void onEntityDamageByEntity(@NotNull EntityDamageByEntityEvent event) { Player damager = null; - Player injured = null; if (event.getDamager().getType().equals(EntityType.PLAYER)) damager = (Player) event.getDamager(); - if (event.getEntity().getType().equals(EntityType.PLAYER)) injured = (Player) event.getEntity(); - if (!userIsAuth(injured) || !userIsAuth(damager)) event.setCancelled(true); + // check that the damager is authorized + if (!userIsAuth(damager)) event.setCancelled(true); } @EventHandler public void onEntityDamage(@NotNull EntityDamageEvent event) { if (!event.getEntityType().equals(EntityType.PLAYER)) return; - if (userIsAuth((Player) event.getEntity())) return; - - DamageCause cause = event.getCause(); - if (cause.equals(DamageCause.LAVA) || cause.equals(DamageCause.ENTITY_EXPLOSION) || - cause.equals(DamageCause.FIRE) || cause.equals(DamageCause.DROWNING) - || cause.equals(DamageCause.STARVATION)) event.setCancelled(true); + if (!userIsAuth((Player) event.getEntity())) event.setCancelled(true); } public void timerKick(Player player, long delay) diff --git a/src/main/java/com/denisindenbom/cyberauth/logfilter/ConsoleFilter.java b/src/main/java/com/denisindenbom/cyberauth/logfilter/ConsoleFilter.java index 6a266ea..600a1dd 100644 --- a/src/main/java/com/denisindenbom/cyberauth/logfilter/ConsoleFilter.java +++ b/src/main/java/com/denisindenbom/cyberauth/logfilter/ConsoleFilter.java @@ -13,7 +13,7 @@ public class ConsoleFilter extends AbstractFilter { - private final List hiddenCommands = getCommandsList("/login ", "/register ", "/change_password "); + private final List hiddenCommands = getCommandsList("/login ", "/l ", "/log ", "/register ", "/r ", "/reg ", "/change_password "); public ConsoleFilter() {} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 52a5d89..003d1f7 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: CyberAuth -version: 1.0 +version: 1.0.1 main: com.denisindenbom.cyberauth.CyberAuth prefix: CyberAuth @@ -10,15 +10,23 @@ commands: login: usage: /login description: /login + aliases: + - l + - log register: usage: /register description: /register + aliases: + - reg + - r change_password: usage: /change_password description: change password logout: usage: /logout description: logout + aliases: + - lg removeuser: usage: /removeUser description: remove user from database