Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Feature: add spit
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFaser committed Oct 7, 2023
1 parent 81ea50d commit a4ecc95
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 2 deletions.
48 changes: 48 additions & 0 deletions src/main/java/net/flectone/commands/CommandSpit.java
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 src/main/java/net/flectone/listeners/PlayerSpitListener.java
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");

}
}
18 changes: 16 additions & 2 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,20 @@ command:
enable: true
aliases: []

spit:
enable: true
aliases: []

# allows to use a command if you hold this item in your hand and press RMB
item: "WHITE_DYE"

cool-down:
enable: false

spit:
enable: false
time: 5
permission: "flectonechat.spit.cooldown.immune"
kick:
enable: false
time: 5
Expand Down Expand Up @@ -588,12 +599,15 @@ cool-down:
# Sound type format
# SOUND_NAME:VOLUME:PITCH
sound:
spit:
enable: true
type: "ENTITY_LLAMA_SPIT:0.3:1"
glass-knocking:
enable: true
type: "BLOCK_GLASS_PLACE:3:1"
type: "BLOCK_GLASS_PLACE:1:1"
door-knocking:
enable: true
type: "BLOCK_WOOD_PLACE:3:1"
type: "BLOCK_WOOD_PLACE:1:1"
auto-message:
enable: false
type: "BLOCK_NOTE_BLOCK_BELL:1:1"
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ commands:
usage: /kick <player> <message>
permission: flectonechat.kick

spit:
usage: /spit
permission: flectonechat.spit

permissions:
flectonechat.reload:
default: op
Expand Down Expand Up @@ -283,4 +287,6 @@ permissions:
flectonechat.chat-settings.kick:
default: true
flectonechat.chat-settings.auto-message:
default: true
flectonechat.spit:
default: true

0 comments on commit a4ecc95

Please sign in to comment.