Enhance empty hand chair clicking

This commit is contained in:
NotAlexNoyle committed 2026-05-25 11:21:56 -04:00
1 parent fd5e8cfef7
commit 05e0ab364e
8 files changed
+67 -33

No files matched your search

+4
View File
@@ -31,6 +31,10 @@ java {
withJavadocJar()
}
tasks.jar { enabled = false }
tasks.named("sourcesJar") { enabled = false }
tasks.named("javadocJar") { enabled = false }
allprojects {
if (selfMavenLocalRepo != null) {
repositories {
@@ -77,9 +77,7 @@ public class ChairManager {
*/
public boolean create(Player player, Block block) {
return create(
player,
block,
ChairUtils.getSitOffset(block, !Settings.bool(Settings.SIT_ON_ARROWS), this.chairNMS));
player, block, ChairUtils.getSitOffset(block, !Settings.bool(Settings.SIT_ON_ARROWS), this.chairNMS));
}
/**
@@ -22,6 +22,7 @@ public final class Messages {
public static final String USE_ALREADY_OCCUPIED = "ChairUse.AlreadyOccupied";
public static final String USE_NEEDS_SIGNS = "ChairUse.NeedsSignsOnBothSides";
public static final String USE_NEEDS_EMPTY_HAND = "ChairUse.NeedsEmptyHand";
public static final String USE_NOW_SITTING = "ChairUse.NowSitting";
private static YamlConfiguration yaml;
@@ -45,11 +46,21 @@ public final class Messages {
return false;
}
File file = new File(plugin.getDataFolder(), "messages.yml");
if (!file.exists()) {
plugin.saveResource("messages.yml", false);
if (!file.isFile()) {
plugin.getLogger().severe("Missing required Git-managed messages.yml");
return false;
}
yaml = YamlConfiguration.loadConfiguration(file);
return true;
return yaml.isString(PREFIX)
&& yaml.isString(NO_PERMISSION)
&& yaml.isString(TOGGLE_ENABLED)
&& yaml.isString(TOGGLE_DISABLED)
&& yaml.isString(TOGGLE_STATUS_ENABLED)
&& yaml.isString(TOGGLE_STATUS_DISABLED)
&& yaml.isString(USE_ALREADY_OCCUPIED)
&& yaml.isString(USE_NEEDS_SIGNS)
&& yaml.isString(USE_NEEDS_EMPTY_HAND)
&& yaml.isString(USE_NOW_SITTING);
}
public static void reset() {
@@ -1,5 +1,6 @@
package de.sprax2013.betterchairs;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -11,13 +12,11 @@ public final class Settings {
public static final String SIT_ON_ARROWS = "Chairs.SitOnArrows";
public static final String ALLOWED_DISTANCE_TO_CHAIR = "Chairs.AllowedDistanceToChair";
public static final String AUTO_ROTATE_PLAYER = "Chairs.AutoRotatePlayer";
public static final String NEEDS_EMPTY_HANDS = "Chairs.NeedEmptyHands";
public static final String NEEDS_SIGNS = "Chairs.NeedsSignsOnBothSides";
public static final String IGNORES_INTERACT_PREVENTION = "Chairs.IgnoreOtherPluginsPreventingInteract";
public static final String HAVE_CHAIRS_DISABLED_FOR_PLAYER_BY_DEFAULT =
"Chairs.HaveChairsDisabledForPlayerByDefault";
public static final String REMEMBER_IF_PLAYER_DISABLED_CHAIRS =
"Chairs.RememberIfPlayerDisabledChairsAfterRelogin";
public static final String REMEMBER_IF_PLAYER_DISABLED_CHAIRS = "Chairs.RememberIfPlayerDisabledChairsAfterRelogin";
public static final String CHAIR_NEED_AIR_ABOVE = "Chairs.Position.NeedAirAbove";
public static final String CHAIR_ALLOW_AIR_BELOW = "Chairs.Position.AllowAirBelow";
public static final String USE_STAIRS = "Chairs.UseStairs";
@@ -71,7 +70,10 @@ public final class Settings {
if (plugin == null) {
return false;
}
plugin.saveDefaultConfig();
if (!new File(plugin.getDataFolder(), "config.yml").isFile()) {
plugin.getLogger().severe("Missing required Git-managed config.yml");
return false;
}
plugin.reloadConfig();
for (Runnable r : listeners.toArray(new Runnable[0])) {
r.run();
@@ -48,8 +48,11 @@ public class BetterChairsPlugin extends JavaPlugin {
chairManager = new ChairManager(this, chairNMS);
// Init configuration files
Settings.reload();
Messages.reload();
if (!Settings.reload() || !Messages.reload()) {
getLogger().severe("BetterChairs requires valid Git-managed config.yml and messages.yml files.");
Bukkit.getPluginManager().disablePlugin(this);
return;
}
// Register Bukkit Event Listener
Bukkit.getPluginManager().registerEvents(new EventListener(), this);
@@ -15,6 +15,7 @@ import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@@ -84,8 +85,8 @@ public class EventListener implements Listener {
this.filteredMaterials.add(mat);
} else {
ChairManager.getLogger()
.warning(() -> "Invalid block type '" + name + "' in "
+ Settings.MATERIAL_FILTER_NAMES);
.warning(
() -> "Invalid block type '" + name + "' in " + Settings.MATERIAL_FILTER_NAMES);
}
}
}
@@ -119,9 +120,6 @@ public class EventListener implements Listener {
if (e.getPlayer().getVehicle() != null && !Settings.bool(Settings.ALLOW_SWITCHING_SEATS))
return; // Already sitting on something else
if (!e.getPlayer().hasPermission(BetterChairsPlugin.LEGACY_NAMESPACE + ".use")) return;
if (Settings.bool(Settings.NEEDS_EMPTY_HANDS)
&& !getManager().chairNMS.hasEmptyMainHand(e.getPlayer())) return;
// Is world disabled?
if (Settings.bool(Settings.WORLD_FILTER_ENABLED)) {
boolean worldInFilter = Objects.requireNonNull(Settings.stringList(Settings.WORLD_FILTER_NAMES))
@@ -137,18 +135,17 @@ public class EventListener implements Listener {
&& !getManager().chairNMS.isStair(e.getClickedBlock())
&& !getManager().chairNMS.isSlab(e.getClickedBlock())) return; // Not a Stair or Slab
if (!e.getClickedBlock().getRelative(BlockFace.UP).isEmpty()
&& Settings.bool(Settings.CHAIR_NEED_AIR_ABOVE)) return; // Needs air above chair
if (!e.getClickedBlock().getRelative(BlockFace.UP).isEmpty() && Settings.bool(Settings.CHAIR_NEED_AIR_ABOVE))
return; // Needs air above chair
if (e.getClickedBlock().getRelative(BlockFace.DOWN).isEmpty()
&& !Settings.bool(Settings.CHAIR_ALLOW_AIR_BELOW)) return; // Does not allow air below chair
if (e.getClickedBlock().getRelative(BlockFace.DOWN).isEmpty() && !Settings.bool(Settings.CHAIR_ALLOW_AIR_BELOW))
return; // Does not allow air below chair
// Block type disabled in config?
if (!Settings.bool(Settings.MATERIAL_FILTER_ENABLED)
|| (Settings.bool(Settings.MATERIAL_FILTER_ENABLED)
&& !Settings.bool(Settings.MATERIAL_FILTER_ALLOW_ALL_TYPES))) {
if ((!Settings.bool(Settings.USE_STAIRS)
&& getManager().chairNMS.isStair(e.getClickedBlock()))
if ((!Settings.bool(Settings.USE_STAIRS) && getManager().chairNMS.isStair(e.getClickedBlock()))
|| (!Settings.bool(Settings.USE_SLABS)
&& getManager().chairNMS.isSlab(e.getClickedBlock()))) return;
@@ -164,6 +161,13 @@ public class EventListener implements Listener {
if (blockInFilter == Settings.bool(Settings.MATERIAL_FILTER_AS_BLACKLIST)) return;
}
if (!getManager().chairNMS.hasEmptyMainHand(e.getPlayer())) {
if (isHoldingWeapon(e.getPlayer())) {
e.getPlayer().sendMessage(Messages.getString(Messages.USE_NEEDS_EMPTY_HAND));
}
return;
}
// Check Chair
if (getManager().isOccupied(e.getClickedBlock())) {
if (Settings.bool(Settings.MSG_ALREADY_OCCUPIED)
@@ -256,6 +260,16 @@ public class EventListener implements Listener {
}
}
private static boolean isHoldingWeapon(Player player) {
String materialName = player.getItemInHand().getType().name();
return materialName.endsWith("_SWORD")
|| materialName.endsWith("_AXE")
|| materialName.equals("BOW")
|| materialName.equals("CROSSBOW")
|| materialName.equals("TRIDENT")
|| materialName.equals("MACE");
}
/**
* This Event only works in latest spigot-1.8.8 and newer
*/
@@ -19,8 +19,7 @@ Chairs:
# Should a player automatically look forward when starting to sit
AutoRotatePlayer: true
# Does a player need his hands empty when trying to sit?
NeedEmptyHands: true
# Right-clicking a chair always requires an empty main hand.
# Does a chair need signs on both sides attached to be detected as an chair
NeedsSignsOnBothSides: false
@@ -14,22 +14,25 @@ General:
Prefix: '&7[&2BetterChairs&f-&4OG&7]'
# What should we tell players that are not allowed to use an command?
NoPermission: ${Prefix} &cERROR: You do not have permission to use that command!
NoPermission: '${Prefix} &cERROR: You do not have permission to use that command!'
# What should we tell players when they enable or disable chairs for themselves?
ToggleChairs:
Enabled: ${Prefix} &aYou can now use chairs again.
Disabled: ${Prefix} &6Chairs are now disabled for you.
Enabled: '${Prefix} &aYou can now use chairs again.'
Disabled: '${Prefix} &6Chairs are now disabled for you.'
Status:
Enabled: ${Prefix} &eYou currently have chairs&a enabled.
Disabled: ${Prefix} &eYou currently have chairs &4disabled.
Enabled: '${Prefix} &eYou currently have chairs&a enabled.'
Disabled: '${Prefix} &eYou currently have chairs &4disabled.'
ChairUse:
# What should we tell players when a chair is already occupied?
AlreadyOccupied: ${Prefix} &6That chair is already occupied.
AlreadyOccupied: '${Prefix} &6That chair is already occupied.'
# What should we tell players when a chair is missing signs on both sides?
NeedsSignsOnBothSides: ${Prefix} &cERROR: A chair needs a sign attached to it on both sides.
NeedsSignsOnBothSides: '${Prefix} &cERROR: A chair needs a sign attached to it on both sides.'
# What should we tell players when they right-click a chair with a weapon?
NeedsEmptyHand: '${Prefix} &eTo sit, right-click with an empty hand or use &6/sit&e.'
# What should we tell players when they sit?
NowSitting: ${Prefix} &aYou are now sitting. You can sneak to stand up.
NowSitting: '${Prefix} &aYou are now sitting. You can sneak to stand up.'