Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# 53: 0.5
# 44:2: 0.3
# ------
# empty: If set to true, your hand have to be empty when you rightclick to sit down on a seat.
# sneaking: If set to true, you have to sneak and rightclick to sit down on a seat.
# distance: The maximum distance between the seat (the center of the block) and the player to be able to sit down (to prevent glitching through walls, etc.).
# ------
Expand All @@ -15,5 +16,6 @@ blocks:
'53:1': 0.5
'53:2': 0.5
'53:3': 0.5
sneaking: true
empty: true
sneaking: false
distance: 2
47 changes: 26 additions & 21 deletions src/net/spoothie/comfort/Comfort.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Comfort extends JavaPlugin {

public HashMap<Player, Block> comfortPlayers = new HashMap<Player, Block>();
public HashMap<String, Double> comfortBlocks = new HashMap<String, Double>();
public boolean sneaking, useSpout;
public boolean empty, sneaking, useSpout;
public double distance;

private File pluginFolder;
Expand All @@ -37,9 +37,9 @@ public class Comfort extends JavaPlugin {
public void onEnable() {
pluginFolder = getDataFolder();
configFile = new File(pluginFolder, "config.yml");
createConfig();
saveConfig();
loadConfig();
createConfig();
saveConfig();
loadConfig();
EventListener eventListener = new EventListener(this);
getServer().getPluginManager().registerEvents(eventListener, this);

Expand Down Expand Up @@ -76,6 +76,7 @@ private void createConfig() {
}

private void loadConfig() {
empty = getConfig().getBoolean("empty");
sneaking = getConfig().getBoolean("sneaking");
distance = getConfig().getDouble("distance");

Expand All @@ -87,23 +88,27 @@ private void loadConfig() {
}
}

@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (command.getName().equalsIgnoreCase("comfort")) {
if(sender instanceof Player && !((Player)sender).hasPermission("comfort.reload"))
return true;

if(args.length > 0 && args[0].equalsIgnoreCase("reload")) {
reloadConfig();
loadConfig();
sender.sendMessage(ChatColor.YELLOW + "Comfort configuration file reloaded.");
}
else
sender.sendMessage(ChatColor.YELLOW + "Use '/comfort reload' to reload the configuration file.");
}

return true;
}

@Override
public boolean onCommand(CommandSender sender, Command command,
String label, String[] args) {
if (command.getName().equalsIgnoreCase("comfort")) {
if (sender instanceof Player
&& !((Player) sender).hasPermission("comfort.reload"))
return true;

if (args.length > 0 && args[0].equalsIgnoreCase("reload")) {
reloadConfig();
loadConfig();
sender.sendMessage(ChatColor.YELLOW
+ "Comfort configuration file reloaded.");
} else
sender.sendMessage(ChatColor.YELLOW
+ "Use '/comfort reload' to reload the configuration file.");
}

return true;
}

public void sitDown(Player player, Block block) {
player.setAllowFlight(true);
player.setFlying(true);
Expand Down
4 changes: 4 additions & 0 deletions src/net/spoothie/comfort/EventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public void onPlayerInteract(PlayerInteractEvent event) {
if(plugin.distance > 0 && player.getLocation().distance(block.getLocation().add(0.5, 0.5, 0.5)) > plugin.distance)
return;

// Check if player's hand is empty
if(plugin.empty == true && player.getItemInHand().getType() != Material.AIR)
return;

// Check if player is sneaking.
if(plugin.sneaking == false || (plugin.sneaking == true && player.isSneaking())) {
plugin.sitDown(player, block);
Expand Down