This repository has been archived by the owner on Jan 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
108 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package net.flectone.commands; | ||
|
||
import net.flectone.misc.commands.FCommand; | ||
import net.flectone.misc.commands.FTabCompleter; | ||
import net.flectone.utils.ObjectUtil; | ||
import org.bukkit.Location; | ||
import org.bukkit.World; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.EntityType; | ||
import org.bukkit.entity.LlamaSpit; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
|
||
public class CommandSpit implements FTabCompleter { | ||
@Override | ||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) { | ||
|
||
FCommand fCommand = new FCommand(commandSender, command.getName(), s, strings); | ||
if (fCommand.isConsoleMessage()) return true; | ||
|
||
Player player = (Player) commandSender; | ||
Location location = player.getEyeLocation(); | ||
World world = player.getWorld(); | ||
|
||
location.setY(location.getY() - 0.3); | ||
|
||
ObjectUtil.playSound(player, command.getName()); | ||
LlamaSpit spit = (LlamaSpit) world.spawnEntity(location, EntityType.LLAMA_SPIT); | ||
spit.setVelocity(location.getDirection()); | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public String getCommandName() { | ||
return "spit"; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) { | ||
return null; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/net/flectone/listeners/PlayerSpitListener.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,38 @@ | ||
package net.flectone.listeners; | ||
|
||
import net.flectone.Main; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.Material; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.block.Action; | ||
import org.bukkit.event.player.PlayerInteractEvent; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import static net.flectone.managers.FileManager.config; | ||
|
||
public class PlayerSpitListener implements Listener { | ||
|
||
@EventHandler | ||
public void onPlayerSpitEvent(PlayerInteractEvent event) { | ||
if (!config.getBoolean("command.spit.enable")) return; | ||
if (!event.getAction().equals(Action.RIGHT_CLICK_AIR)) return; | ||
ItemStack item = event.getItem(); | ||
|
||
if (item == null) return; | ||
|
||
Material configMaterial; | ||
|
||
try { | ||
configMaterial = Material.valueOf(config.getString("command.spit.item").toUpperCase()); | ||
} catch (IllegalArgumentException | NullPointerException exception) { | ||
Main.warning("Item for spit was not found"); | ||
configMaterial = Material.WHITE_DYE; | ||
} | ||
|
||
if (!item.getType().equals(configMaterial)) return; | ||
|
||
Bukkit.dispatchCommand(event.getPlayer(), "spit"); | ||
|
||
} | ||
} |
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