-
-
Notifications
You must be signed in to change notification settings - Fork 141
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
Decouple island location from island center. #1659
Merged
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3ea4b58
Decouple island location from island center.
tastybento 20ba4b8
Paste island at island location.
tastybento 46e223a
Move visitors to the island location
tastybento d95c318
Added island location placeholders
tastybento bfb50ae
Use island location instead of island center
tastybento 1386757
Fix tests
tastybento 4f435de
Allow radius 1 islands.
tastybento b18df47
Correct admin range set limit
tastybento 88f0029
Debug in progress
tastybento 77ae27e
Fix island deletion.
tastybento 6304d2c
Soft depend for WorldGeneratorApi for Boxed game mode
tastybento a076393
Merge remote-tracking branch 'origin/develop' into island_location
tastybento 1600618
Changed to "protectionCenter".
tastybento a321556
Merge branch 'develop' into island_location
tastybento ad3c7d1
Fix tests.
tastybento File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
src/main/java/world/bentobox/bentobox/api/commands/admin/AdminSetLocationCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package world.bentobox.bentobox.api.commands.admin; | ||
|
||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.bukkit.Location; | ||
|
||
import world.bentobox.bentobox.api.commands.CompositeCommand; | ||
import world.bentobox.bentobox.api.commands.ConfirmableCommand; | ||
import world.bentobox.bentobox.api.localization.TextVariables; | ||
import world.bentobox.bentobox.api.user.User; | ||
import world.bentobox.bentobox.database.objects.Island; | ||
import world.bentobox.bentobox.util.Util; | ||
|
||
|
||
/** | ||
* This command sets the island location. This defines the center of the protected area. | ||
* The island location can be anywhere inside the island range area. Therefore the protected | ||
* range can be up to 2x the island range. | ||
* The island location will change for all environments. | ||
* @author tastybento | ||
* @since 1.16.0 | ||
*/ | ||
public class AdminSetLocationCommand extends ConfirmableCommand | ||
{ | ||
private Location targetLoc; | ||
private Island island; | ||
|
||
|
||
/** | ||
* Sub-command constructor | ||
* | ||
* @param parent - the parent composite command | ||
*/ | ||
public AdminSetLocationCommand(CompositeCommand parent) { | ||
super(parent, "setlocation"); | ||
} | ||
|
||
|
||
@Override | ||
public void setup() | ||
{ | ||
this.setPermission("admin.setlocation"); | ||
this.setParametersHelp("commands.admin.setlocation.parameters"); | ||
this.setDescription("commands.admin.setlocation.description"); | ||
} | ||
|
||
@Override | ||
public boolean canExecute(User user, String label, List<String> args) { | ||
if (args.size() == 3) { | ||
// Get location | ||
targetLoc = getLocation(user, args); | ||
} else { | ||
targetLoc = new Location(getWorld(), user.getLocation().getBlockX(), user.getLocation().getBlockY(), user.getLocation().getBlockZ()); | ||
} | ||
if (targetLoc == null) { | ||
user.sendMessage("commands.admin.setlocation.xyz-error"); | ||
return false; | ||
} | ||
Optional<Island> optionalIsland = getIslands().getIslandAt(targetLoc); | ||
if (!optionalIsland.isPresent()) { | ||
user.sendMessage("commands.admin.setspawnpoint.no-island-here"); | ||
return false; | ||
} | ||
island = optionalIsland.get(); | ||
return true; | ||
} | ||
|
||
private Location getLocation(User user, List<String> args) { | ||
try { | ||
int x = Integer.parseInt(args.get(0)); | ||
int y = Integer.parseInt(args.get(1)); | ||
int z = Integer.parseInt(args.get(2)); | ||
return new Location(getWorld(), x, y, z); | ||
} catch (Exception e) { | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean execute(User user, String label, List<String> args) { | ||
String name = getPlayers().getName(island.getOwner()); | ||
user.sendMessage("commands.admin.setlocation.island", TextVariables.XYZ, Util.xyz(island.getCenter().toVector()), TextVariables.NAME, name); | ||
// Confirm | ||
this.askConfirmation(user, user.getTranslation("commands.admin.setlocation.confirmation", TextVariables.XYZ, Util.xyz(targetLoc.toVector())), | ||
() -> this.setLocation(user)); | ||
return true; | ||
} | ||
|
||
|
||
/** | ||
* Set the island location to the user's location. | ||
* @param user User who initiate change. | ||
*/ | ||
private void setLocation(User user) { | ||
try { | ||
// Set | ||
island.setLocation(targetLoc); | ||
user.sendMessage("commands.admin.setlocation.success", TextVariables.XYZ, Util.xyz(targetLoc.toVector())); | ||
} catch (Exception e) { | ||
user.sendMessage("commands.admin.setlocation.failure", TextVariables.XYZ, Util.xyz(targetLoc.toVector())); | ||
getAddon().logError("Island location could not be changed because the island does not exist"); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if this is a correct way how to do it.
I would prefer to calculate by offset from the actual island center.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The protection range is now relative to the protection center location, so if the player is to be given the ability to use all of their island area, then their protection range must be able to go up to 2x island distance away from that point.
For example:
Island range = 400
Island center = 0,0
Island location = 399, 0
Island protection range = 800
This last value will enable them to operate anywhere with all of the island space.