Skip to content

Commit

Permalink
fixed a bug with the kick "Flights are prohibited on the server"
Browse files Browse the repository at this point in the history
fixed an error of receiving fire damage during registration
added aliases to commands such as login, registration and logout
update README.md
  • Loading branch information
DenisIndenbom committed Dec 18, 2021
1 parent 6059e38 commit d123378
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand All @@ -24,10 +24,12 @@ The plugin also hashes all passwords - this means that no one can find out the u
Command **login**:
- Usage: `/login <password>`
- Description: This is the login command
- Aliases: `l`, `log`

Command **register**:
- Usage: `/register <password> <new_password>`
- Description: This is the command to register
- Aliases: `r`, `reg`

Command **change_password**:
- Usage: `/change_password <old_password> <new_password>`
Expand All @@ -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 <username>`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand All @@ -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;
Expand All @@ -68,79 +68,89 @@ 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);
}

@EventHandler
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

public class ConsoleFilter extends AbstractFilter
{
private final List<String> hiddenCommands = getCommandsList("/login ", "/register ", "/change_password ");
private final List<String> hiddenCommands = getCommandsList("/login ", "/l ", "/log ", "/register ", "/r ", "/reg ", "/change_password ");

public ConsoleFilter()
{}
Expand Down
10 changes: 9 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: CyberAuth
version: 1.0
version: 1.0.1
main: com.denisindenbom.cyberauth.CyberAuth

prefix: CyberAuth
Expand All @@ -10,15 +10,23 @@ commands:
login:
usage: /login
description: /login <password>
aliases:
- l
- log
register:
usage: /register
description: /register <password> <password>
aliases:
- reg
- r
change_password:
usage: /change_password <old_password> <new_password>
description: change password
logout:
usage: /logout
description: logout
aliases:
- lg
removeuser:
usage: /removeUser
description: remove user from database
Expand Down

0 comments on commit d123378

Please sign in to comment.