Skip to content

Commit

Permalink
chore: more style refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Machine-Maker committed Jun 22, 2023
1 parent 7c93827 commit 0a991eb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,42 @@

import com.google.inject.Inject;
import me.machinemaker.papertweaks.modules.ModuleListener;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.Plugin;
import org.checkerframework.checker.nullness.qual.Nullable;

import static net.kyori.adventure.text.Component.text;

class EntityInteractionListener implements ModuleListener {

private final Plugin plugin;

@Inject
EntityInteractionListener(Plugin plugin) {
EntityInteractionListener(final Plugin plugin) {
this.plugin = plugin;
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
public void onPlayerInteractEntity(final PlayerInteractEntityEvent event) {
if (!event.getPlayer().hasPermission("vanillatweaks.silencemobs")) return;
ItemStack item = event.getPlayer().getInventory().getItemInMainHand();
final ItemStack item = event.getPlayer().getInventory().getItem(event.getHand());
if (item.getType() == Material.NAME_TAG) {
if (item.getItemMeta() != null && item.getItemMeta().hasDisplayName()) {
String name = item.getItemMeta().getDisplayName();
boolean toSilent = name.equalsIgnoreCase("silence me") || name.equalsIgnoreCase("silence_me");
final @Nullable ItemMeta meta = item.getItemMeta();
if (meta != null && meta.displayName() != null) {
final String name = PlainTextComponentSerializer.plainText().serializeOr(meta.displayName(), "");
final boolean toSilent = name.equalsIgnoreCase("silence me") || name.equalsIgnoreCase("silence_me");
if (toSilent) {
event.getRightClicked().setSilent(true);
Bukkit.getScheduler().runTaskLater(this.plugin, () -> event.getRightClicked().setCustomName("silenced"), 10L);
final Entity clickedEntity = event.getRightClicked();
clickedEntity.setSilent(true);
Bukkit.getScheduler().runTaskLater(this.plugin, () -> clickedEntity.customName(text("silenced")), 10L);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* GNU General Public License v3
*
* PaperTweaks, a performant replacement for the VanillaTweaks datapacks.
*
* Copyright (C) 2023 Machine_Maker
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* SilenceMobs module
*/
@DefaultQualifier(NonNull.class)
package me.machinemaker.papertweaks.modules.mobs.silencemobs;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;

0 comments on commit 0a991eb

Please sign in to comment.