Skip to content

Commit 794c27c

Browse files
committed
Didn't end up needing the listener, adjust config, add bed teleport option
1 parent 0cf0545 commit 794c27c

7 files changed

Lines changed: 27 additions & 68 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>simplexity</groupId>
88
<artifactId>SimpleHomes</artifactId>
9-
<version>1.2.1</version>
9+
<version>1.2.0</version>
1010
<packaging>jar</packaging>
1111

1212
<name>SimpleHomes</name>

src/main/java/simplexity/simplehomes/SimpleHomes.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
import net.kyori.adventure.text.minimessage.MiniMessage;
44
import org.bukkit.plugin.java.JavaPlugin;
5-
import simplexity.simplehomes.commands.*;
5+
import simplexity.simplehomes.commands.DeleteHome;
66
import simplexity.simplehomes.commands.Home;
7+
import simplexity.simplehomes.commands.HomeList;
8+
import simplexity.simplehomes.commands.HomesReload;
9+
import simplexity.simplehomes.commands.ImportHomes;
10+
import simplexity.simplehomes.commands.SetHome;
711
import simplexity.simplehomes.configs.ConfigHandler;
812
import simplexity.simplehomes.configs.LocaleHandler;
9-
import simplexity.simplehomes.listeners.BedEnterListener;
1013
import simplexity.simplehomes.listeners.PlayerMoveListener;
1114
import simplexity.simplehomes.saving.SQLHandler;
1215

@@ -27,7 +30,6 @@ public void onEnable() {
2730
LocaleHandler.getInstance().loadLocale();
2831
SQLHandler.getInstance().init();
2932
this.getServer().getPluginManager().registerEvents(new PlayerMoveListener(), this);
30-
this.getServer().getPluginManager().registerEvents(new BedEnterListener(), this);
3133
registerCommands();
3234
}
3335

src/main/java/simplexity/simplehomes/commands/Home.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
5050
}
5151
}
5252
String homeName = args[0].toLowerCase();
53+
boolean bypass = false;
54+
if (args.length > 1) {
55+
if (args[1].equalsIgnoreCase("-o")) {
56+
bypass = true;
57+
}
58+
}
59+
if (ConfigHandler.getInstance().areBedHomesEnabled() && homeName.equalsIgnoreCase("bed") && player.hasPermission("homes.bed")) {
60+
Location location = player.getPotentialBedLocation();
61+
if (!safeTeleport(location, bypass, player)) return false;
62+
delayTeleport(location, player, "bed");
63+
return true;
64+
}
5365
simplexity.simplehomes.Home home = null;
5466
if (Util.homeExists(playerHomes, homeName)) {
5567
home = SQLHandler.getInstance().getHome(player.getUniqueId(), homeName);
@@ -59,12 +71,6 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
5971
return false;
6072
}
6173
Location homeLocation = home.location();
62-
boolean bypass = false;
63-
if (args.length > 1) {
64-
if (args[1].equalsIgnoreCase("-o")) {
65-
bypass = true;
66-
}
67-
}
6874
if (!safeTeleport(homeLocation, bypass, player)) return false;
6975
delayTeleport(homeLocation, player, homeName);
7076
return false;
@@ -142,6 +148,9 @@ private boolean bypassSafetyChecks(Player player, boolean bypass) {
142148
for (simplexity.simplehomes.Home home : SQLHandler.getInstance().getHomes(player.getUniqueId())) {
143149
homeList.add(home.name());
144150
}
151+
if (ConfigHandler.getInstance().areBedHomesEnabled() && player.getPotentialBedLocation() != null) {
152+
homeList.add("bed");
153+
}
145154
return homeList;
146155
}
147156
return null;

src/main/java/simplexity/simplehomes/configs/ConfigHandler.java

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.bukkit.Material;
44
import org.bukkit.configuration.file.FileConfiguration;
5-
import org.bukkit.event.player.PlayerBedEnterEvent;
65
import simplexity.simplehomes.SimpleHomes;
76

87
import java.util.ArrayList;
@@ -13,7 +12,6 @@ public class ConfigHandler {
1312
private static ConfigHandler instance;
1413

1514
private final ArrayList<Material> blacklistedBlocks = new ArrayList<>();
16-
private final ArrayList<PlayerBedEnterEvent.BedEnterResult> allowedResults = new ArrayList<>();
1715
private boolean creativeBypass, invulnerableBypass, mysql, lockoutEnabled, disableHome, disableHomeList,
1816
disableDeleteHome, delayEnabled, cancelOnMove, bedHomesEnabled;
1917
private String ip, name, username, password;
@@ -29,7 +27,6 @@ public void loadConfigValues() {
2927
SimpleHomes.getInstance().reloadConfig();
3028
FileConfiguration config = SimpleHomes.getInstance().getConfig();
3129
List<String> blockList = config.getStringList("blacklisted-blocks");
32-
List<String> resultList = config.getStringList("bed-home.allowed-results");
3330
creativeBypass = config.getBoolean("safety-bypass.creative", true);
3431
invulnerableBypass = config.getBoolean("safety-bypass.invulnerable", true);
3532
lockoutEnabled = config.getBoolean("lockout.enabled", false);
@@ -40,9 +37,8 @@ public void loadConfigValues() {
4037
cancelOnMove = config.getBoolean("delay.cancel-on-move", true);
4138
timeInSeconds = config.getInt("delay.time-in-seconds", 5);
4239
bufferMovement = config.getDouble("delay.buffer-movement", 0.5);
43-
bedHomesEnabled = config.getBoolean("bed-home.enabled", true);
40+
bedHomesEnabled = config.getBoolean("bed-home.enabled", false);
4441
fillList(blockList);
45-
verifyEnterEventResults(resultList);
4642
mysql = config.getBoolean("mysql.enabled", false);
4743
ip = config.getString("mysql.ip");
4844
name = config.getString("mysql.name");
@@ -62,36 +58,10 @@ private void fillList(List<String> stringList) {
6258
}
6359
}
6460

65-
private void verifyEnterEventResults(List<String> stringList) {
66-
allowedResults.clear();
67-
if (stringList.isEmpty()) {
68-
SimpleHomes.getInstance().getLogger().warning(stringList + " is empty. Please check your config, setting default configuration");
69-
allowedResults.add(PlayerBedEnterEvent.BedEnterResult.NOT_POSSIBLE_NOW);
70-
allowedResults.add(PlayerBedEnterEvent.BedEnterResult.NOT_SAFE);
71-
allowedResults.add(PlayerBedEnterEvent.BedEnterResult.OK);
72-
return;
73-
}
74-
for (String string : stringList) {
75-
PlayerBedEnterEvent.BedEnterResult result;
76-
try {
77-
result = PlayerBedEnterEvent.BedEnterResult.valueOf(string);
78-
} catch (IllegalArgumentException e) {
79-
SimpleHomes.getInstance().getLogger().warning(string + " is not a valid event result, please check your config");
80-
continue;
81-
}
82-
allowedResults.add(result);
83-
}
84-
}
85-
86-
8761
public ArrayList<Material> getBlacklistedBlocks() {
8862
return blacklistedBlocks;
8963
}
9064

91-
public ArrayList<PlayerBedEnterEvent.BedEnterResult> getAllowedResults() {
92-
return allowedResults;
93-
}
94-
9565
public boolean doCreativeBypass() {
9666
return creativeBypass;
9767
}
@@ -151,4 +121,8 @@ public int getTimeInSeconds() {
151121
public double getBufferMovement() {
152122
return bufferMovement;
153123
}
124+
125+
public boolean areBedHomesEnabled() {
126+
return bedHomesEnabled;
127+
}
154128
}

src/main/java/simplexity/simplehomes/listeners/BedEnterListener.java

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/main/java/simplexity/simplehomes/saving/SQLHandler.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package simplexity.simplehomes.saving;
22

3-
import org.bukkit.Bukkit;
43
import org.bukkit.Location;
5-
import org.bukkit.OfflinePlayer;
6-
import org.bukkit.entity.Player;
74
import simplexity.simplehomes.Home;
85
import simplexity.simplehomes.SimpleHomes;
96
import simplexity.simplehomes.configs.ConfigHandler;
@@ -52,7 +49,6 @@ world_name VARCHAR(255),
5249
pitch FLOAT
5350
);""");
5451
}
55-
5652
} catch (SQLException e) {
5753
logger.severe("Failed to connect to SQLite database");
5854
logger.severe("Error: " + e.getMessage());

src/main/resources/config.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,4 @@ delay: # Delay after running the command to teleporting
2525
cancel-on-move: true
2626
buffer: 0.5
2727
bed-home: #set a home when interacting with a bed
28-
enabled: true
29-
allowed-results: #results on interaction with a bed to set a home automatically with. https://jd.papermc.io/paper/1.21.3/org/bukkit/event/player/PlayerBedEnterEvent.BedEnterResult.html
30-
- OK
31-
- NOT_POSSIBLE_NOW
32-
- NOT_SAFE
28+
enabled: false

0 commit comments

Comments
 (0)