-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a course GUI with warping. Use warped pressure plate to set spot
- Loading branch information
1 parent
30bb96b
commit b69dbb4
Showing
12 changed files
with
385 additions
and
56 deletions.
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
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
41 changes: 41 additions & 0 deletions
41
src/main/java/world/bentobox/parkour/commands/CoursesCommand.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,41 @@ | ||
package world.bentobox.parkour.commands; | ||
|
||
import java.util.List; | ||
|
||
import world.bentobox.bentobox.api.commands.CompositeCommand; | ||
import world.bentobox.bentobox.api.panels.builders.TabbedPanelBuilder; | ||
import world.bentobox.bentobox.api.user.User; | ||
import world.bentobox.parkour.Parkour; | ||
import world.bentobox.parkour.gui.CoursesTab; | ||
|
||
public class CoursesCommand extends CompositeCommand { | ||
|
||
public CoursesCommand(Parkour addon, CompositeCommand parent) { | ||
super(parent, "courses", "tracks"); | ||
} | ||
|
||
@Override | ||
public void setup() { | ||
this.setPermission("parkour.courses"); | ||
setOnlyPlayer(true); | ||
setDescription("parkour.commands.parkour.courses.description"); | ||
} | ||
|
||
@Override | ||
public boolean canExecute(User user, String label, List<String> args) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean execute(User user, String label, List<String> args) { | ||
new TabbedPanelBuilder() | ||
.user(user) | ||
.world(getWorld()) | ||
.tab(1, new CoursesTab(getAddon(), user)) | ||
.startingSlot(1) | ||
.size(54) | ||
.build().openPanel(); | ||
return true; | ||
} | ||
|
||
} |
142 changes: 142 additions & 0 deletions
142
src/main/java/world/bentobox/parkour/gui/CoursesTab.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,142 @@ | ||
package world.bentobox.parkour.gui; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
import org.bukkit.ChatColor; | ||
import org.bukkit.Material; | ||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; | ||
import org.bukkit.util.Vector; | ||
import org.eclipse.jdt.annotation.NonNull; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
|
||
import world.bentobox.bentobox.api.panels.PanelItem; | ||
import world.bentobox.bentobox.api.panels.Tab; | ||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; | ||
import world.bentobox.bentobox.api.user.User; | ||
import world.bentobox.bentobox.database.objects.Island; | ||
import world.bentobox.bentobox.util.Util; | ||
import world.bentobox.parkour.Parkour; | ||
import world.bentobox.parkour.objects.ParkourData; | ||
|
||
/** | ||
* Implements a {@link Tab} that shows course rankings | ||
* @author tastybento | ||
* @since 1.0.0 | ||
* | ||
*/ | ||
public class CoursesTab implements Tab { | ||
|
||
private final Parkour addon; | ||
private final User user; | ||
|
||
/** | ||
* Show a tab of settings | ||
* @param user - user who is viewing the tab | ||
* @param island - the island | ||
* @param type - flag type | ||
*/ | ||
public CoursesTab(Parkour addon, User user) { | ||
super(); | ||
this.addon = addon; | ||
this.user = user; | ||
} | ||
|
||
/** | ||
* Get the icon for this tab | ||
* @return panel item | ||
*/ | ||
@Override | ||
public PanelItem getIcon() { | ||
PanelItemBuilder pib = new PanelItemBuilder(); | ||
// Set the icon | ||
pib.icon(Material.HEAVY_WEIGHTED_PRESSURE_PLATE); | ||
pib.name(getName()); | ||
pib.description(user.getTranslation("parkour.courses.description")); | ||
return pib.build(); | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see world.bentobox.bentobox.api.panels.Tab#getName() | ||
*/ | ||
@Override | ||
public String getName() { | ||
return user.getTranslation("parkour.courses.gui-title"); | ||
} | ||
|
||
/** | ||
* Get all the flags as panel items | ||
* @return list of all the panel items for this flag type | ||
*/ | ||
@Override | ||
@NonNull | ||
public List<@Nullable PanelItem> getPanelItems() { | ||
// Create the list | ||
List<PanelItem> heads = new ArrayList<>(); | ||
// Sort the courses by runs | ||
addon.getPm().getParkourData().stream() | ||
.sorted() | ||
.filter(hs -> Objects.nonNull(hs.getWarpSpot())) | ||
.forEach(hs -> { | ||
UUID owner = addon.getIslands().getIslandById(hs.getUniqueId()).map(Island::getOwner).orElse(null); | ||
if (owner != null) { | ||
heads.add(getHead(hs, owner)); | ||
} | ||
}); | ||
return heads; | ||
} | ||
|
||
/** | ||
* Get the head panel item | ||
* @param pd - parkour data | ||
* @param playerUUID - the UUID of the owner | ||
* @return PanelItem | ||
*/ | ||
private PanelItem getHead(ParkourData pd, UUID playerUUID) { | ||
final String name = addon.getPlayers().getName(playerUUID); | ||
List<String> description = new ArrayList<>(); | ||
if (pd.getRunCount() > 0) { | ||
description.add(user.getTranslation("parkour.courses.head-description", "[name]", name, "[runs]", String.valueOf(pd.getRunCount()))); | ||
} | ||
if (addon.getIslands().inTeam(addon.getOverWorld(), playerUUID)) { | ||
List<String> memberList = new ArrayList<>(); | ||
for (UUID members : addon.getIslands().getMembers(addon.getOverWorld(), playerUUID)) { | ||
memberList.add(ChatColor.AQUA + addon.getPlayers().getName(members)); | ||
} | ||
description.addAll(memberList); | ||
} | ||
|
||
PanelItemBuilder builder = new PanelItemBuilder() | ||
.icon(name) | ||
.name(name) | ||
.clickHandler((panel, user, clickType, slot) -> { | ||
user.sendMessage("parkour.warp.warping"); | ||
// Teleport user | ||
Util.teleportAsync(user.getPlayer(), pd.getWarpSpot().clone().add(new Vector(0.5, 1, 0.5)), TeleportCause.COMMAND); | ||
return true; | ||
}) | ||
.description(description); | ||
return builder.build(); | ||
} | ||
|
||
@Override | ||
public Map<Integer, PanelItem> getTabIcons() { | ||
Map<Integer, PanelItem> icons = new HashMap<>(); | ||
|
||
return icons; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see world.bentobox.bentobox.api.panels.Tab#getPermission() | ||
*/ | ||
@Override | ||
public String getPermission() { | ||
// All of these tabs can be seen by anyone | ||
return ""; | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** | ||
* Contains GUIs | ||
*/ | ||
package world.bentobox.parkour.gui; |
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.