-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add flags to disable riding & leashing (#36)
* update maven group for Vault * add disableLeash & disableRiding flags
- Loading branch information
Showing
5 changed files
with
71 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/com/hm/petmaster/listener/PlayerLeashListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.hm.petmaster.listener; | ||
|
||
import com.hm.mcshared.particle.ReflectionUtils; | ||
import com.hm.petmaster.PetMaster; | ||
import org.bukkit.entity.AnimalTamer; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.entity.Tameable; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.entity.PlayerLeashEntityEvent; | ||
|
||
public class PlayerLeashListener implements Listener { | ||
private final PetMaster plugin; | ||
private final int version; | ||
|
||
// Configuration parameters. | ||
private boolean disableLeash; | ||
|
||
public PlayerLeashListener(PetMaster petMaster) { | ||
this.plugin = petMaster; | ||
version = Integer.parseInt(ReflectionUtils.PackageType.getServerVersion().split("_")[1]); | ||
} | ||
|
||
public void extractParameters() { | ||
disableLeash = plugin.getPluginConfig().getBoolean("disableLeash", false); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) | ||
public void onPlayerLeashEntityEvent(PlayerLeashEntityEvent event) { | ||
if (plugin.getEnableDisableCommand().isDisabled() || !disableLeash) | ||
return; | ||
Entity entity = event.getEntity(); | ||
if (!(entity instanceof Tameable)) | ||
return; | ||
|
||
Player player = event.getPlayer(); | ||
Tameable tameable = (Tameable) entity; | ||
AnimalTamer currentOwner = tameable.getOwner(); | ||
if (currentOwner == null || currentOwner.getUniqueId().equals(player.getUniqueId()) || player.hasPermission("petmaster.admin")) | ||
return; | ||
|
||
player.sendMessage(plugin.getChatHeader() + plugin.getPluginLang() | ||
.getString("not-owner", "You do not own this pet!").replace("PLAYER", player.getName())); | ||
event.setCancelled(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters