mirror of
https://github.com/BentoBoxWorld/Warps.git
synced 2024-11-25 03:55:25 +01:00
Finished warps addon.
This commit is contained in:
parent
9b1f8bd14c
commit
dc5394ede2
@ -3,27 +3,26 @@
|
||||
# the one at http://yaml-online-parser.appspot.com #
|
||||
###########################################################################################
|
||||
|
||||
### Credits ###
|
||||
# Tastybento: maintainer
|
||||
# Poslovitch: maintainer
|
||||
#
|
||||
# This translation is adapted to version : [alpha-0.0.1]
|
||||
|
||||
warps:
|
||||
welcomeLine: "[Welcome]"
|
||||
removed: "Warp sign removed"
|
||||
success: "Success!"
|
||||
sign-removed: "Warp sign removed!"
|
||||
removed: "&CWarp sign removed"
|
||||
success: "&ASuccess!"
|
||||
sign-removed: "&CWarp sign removed!"
|
||||
title: "Warp Signs"
|
||||
previous: "Previous page"
|
||||
next: "Next page"
|
||||
warpToPlayersSign: "Warping to [player]'s sign"
|
||||
warpTip: "Place a warp sign with [Welcome] on the top"
|
||||
previous: "&6Previous page"
|
||||
next: "&6Next page"
|
||||
warpToPlayersSign: "&6Warping to [player]'s sign"
|
||||
warpTip: "&6Place a warp sign with [Welcome] on the top"
|
||||
error:
|
||||
no-remove: "You cannot remove that sign!"
|
||||
not-enough-level: "Your island level is not high enough!"
|
||||
no-permission: "You do not have permission to do that!"
|
||||
not-on-island: "You must be on your island to do that!"
|
||||
duplicate: "Duplicate sign placed"
|
||||
no-warps-yet: "There are no warps available yet"
|
||||
|
||||
no-remove: "&CYou cannot remove that sign!"
|
||||
not-enough-level: "&CYour island level is not high enough!"
|
||||
no-permission: "&CYou do not have permission to do that!"
|
||||
not-on-island: "&CYou must be on your island to do that!"
|
||||
duplicate: "&CDuplicate sign placed"
|
||||
no-warps-yet: "&CThere are no warps available yet"
|
||||
help:
|
||||
description: "open the warps panel"
|
||||
warp:
|
||||
help:
|
||||
parameters: "<name>"
|
||||
description: "warp to the player's warp sign"
|
||||
|
@ -21,7 +21,7 @@ import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder;
|
||||
public class WarpPanelManager {
|
||||
|
||||
private static final boolean DEBUG = true;
|
||||
private static final int PANEL_MAX_SIZE = 47;
|
||||
private static final int PANEL_MAX_SIZE = 52;
|
||||
private Warp plugin;
|
||||
// This is a cache of heads, so they don't need to be created everytime
|
||||
private HashMap<UUID, PanelItem> cachedWarps;
|
||||
@ -50,9 +50,9 @@ public class WarpPanelManager {
|
||||
|
||||
private PanelItem getPanelItem(UUID warpOwner) {
|
||||
return new PanelItemBuilder()
|
||||
.setIcon(getSkull(warpOwner))
|
||||
.setName(plugin.getBSkyBlock().getPlayers().getName(warpOwner))
|
||||
.setDescription(plugin.getWarpSignsManager().getSignText(warpOwner))
|
||||
.setIcon(getSkull(warpOwner))
|
||||
.setClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
@ -97,7 +97,9 @@ public class WarpPanelManager {
|
||||
} else if (index > (warps.size() / PANEL_MAX_SIZE)) {
|
||||
index = warps.size() / PANEL_MAX_SIZE;
|
||||
}
|
||||
PanelBuilder panelBuilder = new PanelBuilder().setUser(user).setName(user.getTranslation("panel.title"));
|
||||
// TODO use when locales are done.
|
||||
//PanelBuilder panelBuilder = new PanelBuilder().setUser(user).setName(user.getTranslation("panel.title", "[number]", String.valueOf(index + 1)));
|
||||
PanelBuilder panelBuilder = new PanelBuilder().setUser(user).setName(user.getTranslation("panel.title") + " " + String.valueOf(index + 1));
|
||||
int i = index * PANEL_MAX_SIZE;
|
||||
for (; i < (index * PANEL_MAX_SIZE + PANEL_MAX_SIZE) && i < warps.size(); i++) {
|
||||
UUID owner = warps.get(i);
|
||||
@ -117,6 +119,7 @@ public class WarpPanelManager {
|
||||
|
||||
@Override
|
||||
public boolean onClick(User user, ClickType click) {
|
||||
user.closeInventory();
|
||||
showWarpPanel(user, panelNum+1);
|
||||
return true;
|
||||
}
|
||||
@ -126,12 +129,13 @@ public class WarpPanelManager {
|
||||
if (i > PANEL_MAX_SIZE) {
|
||||
// Previous
|
||||
panelBuilder.addItem(new PanelItemBuilder()
|
||||
.setName("Next")
|
||||
.setName("Previous")
|
||||
.setIcon(new ItemStack(Material.SIGN))
|
||||
.setClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public boolean onClick(User user, ClickType click) {
|
||||
user.closeInventory();
|
||||
showWarpPanel(user, panelNum-1);
|
||||
return true;
|
||||
}
|
||||
@ -140,4 +144,9 @@ public class WarpPanelManager {
|
||||
}
|
||||
panelBuilder.build();
|
||||
}
|
||||
|
||||
|
||||
public void remove(UUID uuid) {
|
||||
cachedWarps.remove(uuid);
|
||||
}
|
||||
}
|
||||
|
@ -9,12 +9,14 @@ import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang.math.RandomUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
@ -222,6 +224,21 @@ public class WarpSignsManager implements Listener {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
if (warpList.size() < 100) {
|
||||
// TEST CODE
|
||||
for (int i = 0; i < 300; i++) {
|
||||
UUID rand = UUID.randomUUID();
|
||||
int x = RandomUtils.nextInt(100000) - RandomUtils.nextInt(100000);
|
||||
int z = RandomUtils.nextInt(100000) - RandomUtils.nextInt(100000);
|
||||
Block b = IslandWorld.getIslandWorld().getBlockAt(x, 119, z);
|
||||
b.setType(Material.STONE);
|
||||
b.getRelative(BlockFace.UP).setType(Material.SIGN_POST);
|
||||
Sign sign = (Sign)b.getRelative(BlockFace.UP).getState();
|
||||
sign.setLine(0, ChatColor.GREEN + plugin.getConfig().getString("welcomeLine"));
|
||||
sign.update();
|
||||
warpList.put(rand, new Location(IslandWorld.getIslandWorld(), x, 120, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -387,20 +404,20 @@ public class WarpSignsManager implements Listener {
|
||||
Entry<UUID, Location> en = it.next();
|
||||
if (en.getValue().equals(loc)) {
|
||||
// Inform player
|
||||
User p = User.getInstance(plugin.getServer().getPlayer(en.getKey()));
|
||||
if (p != null) {
|
||||
User user = User.getInstance(plugin.getServer().getPlayer(en.getKey()));
|
||||
if (user != null) {
|
||||
// Inform the player
|
||||
p.sendMessage("warps.sign-removed");
|
||||
}
|
||||
user.sendMessage("warps.sign-removed");
|
||||
}
|
||||
plugin.getWarpPanelManager().remove(en.getKey());
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
saveWarpList();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes a warp when the welcome sign is destroyed. Called by
|
||||
* WarpSigns.java.
|
||||
* Remove warp sign owned by UUID
|
||||
*
|
||||
* @param uuid
|
||||
*/
|
||||
@ -410,6 +427,7 @@ public class WarpSignsManager implements Listener {
|
||||
warpList.remove(uuid);
|
||||
}
|
||||
saveWarpList();
|
||||
plugin.getWarpPanelManager().remove(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -440,12 +458,31 @@ public class WarpSignsManager implements Listener {
|
||||
Location signLocation = getWarp(uuid);
|
||||
if (signLocation == null) {
|
||||
plugin.getWarpSignsManager().removeWarp(uuid);
|
||||
} else
|
||||
} else {
|
||||
if (DEBUG)
|
||||
Bukkit.getLogger().info("DEBUG: getting sign text");
|
||||
// Get the sign info if it exists
|
||||
if (signLocation.getBlock().getType().equals(Material.SIGN_POST) || signLocation.getBlock().getType().equals(Material.WALL_SIGN)) {
|
||||
if (DEBUG)
|
||||
Bukkit.getLogger().info("DEBUG: sign is a sign");
|
||||
Sign sign = (Sign)signLocation.getBlock().getState();
|
||||
result.addAll(Arrays.asList(sign.getLines()));
|
||||
if (DEBUG)
|
||||
Bukkit.getLogger().info("DEBUG: " + result.toString());
|
||||
}
|
||||
// Clean up - remove the [WELCOME] line
|
||||
result.remove(0);
|
||||
// Remove any trailing blank lines
|
||||
ListIterator<String> it = result.listIterator(result.size());
|
||||
while (it.hasPrevious()) {
|
||||
String line = it.previous();
|
||||
if (line.isEmpty())
|
||||
it.remove();
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -538,9 +575,11 @@ public class WarpSignsManager implements Listener {
|
||||
|
||||
Island island = plugin.getBSkyBlock().getIslands().getIsland(owner);
|
||||
boolean pvp = false;
|
||||
if ((warpSpot.getWorld().equals(IslandWorld.getIslandWorld()) && island.getFlag(SettingsFlag.PVP_OVERWORLD))
|
||||
|| (warpSpot.getWorld().equals(IslandWorld.getNetherWorld()) && island.getFlag(SettingsFlag.PVP_NETHER))) {
|
||||
pvp = true;
|
||||
if (island != null) {
|
||||
if ((warpSpot.getWorld().equals(IslandWorld.getIslandWorld()) && island.getFlag(SettingsFlag.PVP_OVERWORLD))
|
||||
|| (warpSpot.getWorld().equals(IslandWorld.getNetherWorld()) && island.getFlag(SettingsFlag.PVP_NETHER))) {
|
||||
pvp = true;
|
||||
}
|
||||
}
|
||||
// Find out which direction the warp is facing
|
||||
Block b = warpSpot.getBlock();
|
||||
|
@ -1,6 +1,9 @@
|
||||
package bskyblock.addin.warps.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -9,6 +12,12 @@ import us.tastybento.bskyblock.api.commands.CompositeCommand;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
|
||||
/**
|
||||
* The /is warp <name> command
|
||||
*
|
||||
* @author ben
|
||||
*
|
||||
*/
|
||||
public class WarpCommand extends CompositeCommand {
|
||||
|
||||
private Warp plugin;
|
||||
@ -22,6 +31,20 @@ public class WarpCommand extends CompositeCommand {
|
||||
public void setup() {
|
||||
this.setPermission(Settings.PERMPREFIX + "island.warp");
|
||||
this.setOnlyPlayer(true);
|
||||
this.setParameters("warp.help.parameters");
|
||||
this.setDescription("warp.help.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, LinkedList<String> args) {
|
||||
List<String> options = new ArrayList<>();
|
||||
final Set<UUID> warpList = plugin.getWarpSignsManager().listWarps();
|
||||
|
||||
for (UUID warp : warpList) {
|
||||
options.add(plugin.getBSkyBlock().getPlayers().getName(warp));
|
||||
}
|
||||
|
||||
return Optional.of(options);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,6 +30,7 @@ public class WarpsCommand extends CompositeCommand {
|
||||
public void setup() {
|
||||
this.setPermission(Settings.PERMPREFIX + "island.warp");
|
||||
this.setOnlyPlayer(true);
|
||||
this.setDescription("warps.help.description");
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
Loading…
Reference in New Issue
Block a user