Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inital extra bed commit with back-compatibility #1070

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions .gitattributes
@@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason for keeping anything after the auto-lf normalization rule? I mean, the rest of it wont really matter to a java repository.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

honestly the only reason this is even in the commit is github for windows wouldn't stop nagging about it, so i just said, yes fix it, this is what it added.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never trust git GUIs. Things like this are exactly why I always commit and push from the command line.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never trust git GUIs.

👍

*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
8 changes: 4 additions & 4 deletions .travis.yml
@@ -1,5 +1,5 @@
language: java
jdk:
- oraclejdk6
notifications:
language: java
jdk:
- oraclejdk6
notifications:
email: false
Expand Up @@ -9,8 +9,11 @@

import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVDestination;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -21,6 +24,8 @@
*/
public class BedDestination implements MVDestination {

public static final String OLD_BED_STRING = "b:playerbed";
private String playername = "";
private boolean isValid;
private Location knownBedLoc;
private MultiverseCore plugin;
Expand All @@ -38,8 +43,18 @@ public String getIdentifier() {
*/
@Override
public boolean isThisType(JavaPlugin plugin, String destination) {
String[] split = destination.split(":");
this.isValid = split.length >= 1 && split.length <= 2 && split[0].equals(this.getIdentifier());
boolean backwardsCompat = (destination == OLD_BED_STRING);

String[] split = destination.split(":");
boolean validFormat = split.length >= 1 && split.length <= 2 && split[0].equals(this.getIdentifier());

OfflinePlayer p = Bukkit.getOfflinePlayer(split[1]);
boolean validPlayer = (p != null);

if(validFormat && validPlayer) this.playername = p.getName();

this.isValid = backwardsCompat || (validFormat && validPlayer);

return this.isValid;
}

Expand All @@ -49,9 +64,13 @@ public boolean isThisType(JavaPlugin plugin, String destination) {
@Override
public Location getLocation(Entity entity) {
if (entity instanceof Player) {
this.knownBedLoc = this.plugin.getBlockSafety().getSafeBedSpawn(((Player) entity).getBedSpawnLocation());
if (this.knownBedLoc == null) {
((Player) entity).sendMessage("Your bed was " + ChatColor.RED + "invalid or blocked" + ChatColor.RESET + ". Sorry.");
if (this.playername.isEmpty()){
this.knownBedLoc = this.plugin.getBlockSafety().getSafeBedSpawn(((Player) entity).getBedSpawnLocation());
}else{
this.knownBedLoc = this.plugin.getBlockSafety().getSafeBedSpawn(Bukkit.getOfflinePlayer(this.playername).getBedSpawnLocation());
}
if (this.knownBedLoc == null) {
((Player) entity).sendMessage("The bed was " + ChatColor.RED + "invalid or blocked" + ChatColor.RESET + ". Sorry.");
}
return this.knownBedLoc;
}
Expand Down Expand Up @@ -120,6 +139,11 @@ public boolean useSafeTeleporter() {

@Override
public String toString() {
return "b:playerbed";
if(this.playername.isEmpty()) {
return "b:playerbed";
}else{
return "b:"+this.playername;
}

}
}