Skip to content

Commit

Permalink
1.0.1
Browse files Browse the repository at this point in the history
Pet page fix
Dismount on damaged option
Spawn on reconnect option
  • Loading branch information
AlexandreChaussard committed Feb 23, 2022
1 parent 56cd970 commit 0f7f1e5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 28 deletions.
10 changes: 10 additions & 0 deletions src/main/java/fr/nocsy/mcpets/data/config/GlobalConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public class GlobalConfig extends AbstractConfig {
@Getter
private boolean sneakMode;
@Getter
private boolean dismountOnDamaged;
@Getter
private boolean spawnPetOnReconnect;
@Getter
private int distanceTeleport = 30;
@Getter
private int maxNameLenght = 16;
Expand Down Expand Up @@ -69,6 +73,10 @@ public void init()
getConfig().set("RightClickToOpenMenu", true);
if(getConfig().get("LeftClickToOpenMenu") == null)
getConfig().set("LeftClickToOpenMenu", true);
if(getConfig().get("DismountOnDamaged") == null)
getConfig().set("DismountOnDamaged", true);
if(getConfig().get("SpawnPetOnReconnect") == null)
getConfig().set("SpawnPetOnReconnect", true);
if(getConfig().get("SneakMode") == null)
getConfig().set("SneakMode", false);
if(getConfig().get("Nameable") == null)
Expand Down Expand Up @@ -115,6 +123,8 @@ public void reload() {
sneakMode = getConfig().getBoolean("SneakMode");
nameable = getConfig().getBoolean("Nameable");
mountable = getConfig().getBoolean("Mountable");
dismountOnDamaged = getConfig().getBoolean("DismountOnDamaged");
spawnPetOnReconnect = getConfig().getBoolean("SpawnPetOnReconnect");
distanceTeleport = getConfig().getInt("DistanceTeleport");
maxNameLenght = getConfig().getInt("MaxNameLenght");
activateBackMenuIcon = getConfig().getBoolean("ActivateBackMenuIcon");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public void click(InventoryClickEvent e)
openBackPetMenu(p);
return;
}
if(it.getItemMeta().hasLocalizedName() && it.getItemMeta().getLocalizedName().contains("AlmPetPage;"))
return;

Pet pet = Pet.getFromLastInteractedWith(p);

Expand Down
58 changes: 30 additions & 28 deletions src/main/java/fr/nocsy/mcpets/listeners/PetListener.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package fr.nocsy.mcpets.listeners;

import com.destroystokyo.paper.event.entity.EntityRemoveFromWorldEvent;
import fr.nocsy.mcpets.MCPets;
import fr.nocsy.mcpets.data.PetDespawnReason;
import fr.nocsy.mcpets.data.config.GlobalConfig;
Expand All @@ -17,16 +16,16 @@
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.*;
import org.bukkit.metadata.FixedMetadataValue;

import java.util.HashMap;
import java.util.UUID;

public class PetListener implements Listener {

private HashMap<UUID, Pet> reconnectionPets = new HashMap<>();

@EventHandler
public void interact(PlayerInteractEntityEvent e)
{
Expand Down Expand Up @@ -80,6 +79,29 @@ public void interact(EntityDamageByEntityEvent e)
}
}

@EventHandler
public void disconnectPlayer(PlayerQuitEvent e)
{
Player p = e.getPlayer();
if(Pet.getActivePets().containsKey(p.getUniqueId()))
{
Pet pet = Pet.getActivePets().get(p.getUniqueId());
reconnectionPets.put(p.getUniqueId(), pet);
}
}

@EventHandler
public void reconnectionPlayer(PlayerJoinEvent e)
{
Player p = e.getPlayer();
if(reconnectionPets.containsKey(p.getUniqueId()))
{
Pet pet = reconnectionPets.get(p.getUniqueId());
pet.spawn(p.getLocation());
reconnectionPets.remove(p.getUniqueId());
}
}

@EventHandler
public void teleport(PlayerChangedWorldEvent e)
{
Expand Down Expand Up @@ -108,6 +130,9 @@ public void teleport(PlayerTeleportEvent e)
@EventHandler
public void riding(EntityDamageEvent e)
{
if(!GlobalConfig.getInstance().isDismountOnDamaged())
return;

if(e.getEntity() instanceof Player)
{
Player p = (Player) e.getEntity();
Expand Down Expand Up @@ -176,29 +201,6 @@ public void despawn(MythicMobDespawnEvent e)
}
}

/**
* Handle random despawn
* @param e
*/
@EventHandler
public void despawn(EntityRemoveFromWorldEvent e)
{
e.getEntity();
Pet pet = Pet.getFromEntity(e.getEntity());
if(pet != null)
{
if(!pet.isRemoved())
{
pet.despawn(PetDespawnReason.UNKNOWN);
Player owner = Bukkit.getPlayer(pet.getOwner());
if(owner != null)
{
Language.REVOKED.sendMessage(owner);
}
}
}
}

/**
* Handle death of the pet
* @param e
Expand Down

0 comments on commit 0f7f1e5

Please sign in to comment.