Skip to content

Commit

Permalink
Enabled formatting of warp sign text
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Sep 18, 2019
1 parent 675f579 commit bbc748a
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/main/java/world/bentobox/warps/Warp.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ private void loadSettings() {
// Disable
this.logError("WelcomeWarp settings could not load! Addon disabled.");
this.setState(State.DISABLED);
return;
}
settingsConfig.saveConfigObject(settings);
}


Expand Down
2 changes: 1 addition & 1 deletion src/main/java/world/bentobox/warps/WarpPanelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public WarpPanelManager(Warp addon) {

private PanelItem getPanelItem(World world, UUID warpOwner) {
PanelItemBuilder pib = new PanelItemBuilder()
.name(addon.getPlugin().getPlayers().getName(warpOwner))
.name(addon.getSettings().getNameFormat() + addon.getPlugin().getPlayers().getName(warpOwner))
.description(getSign(world, warpOwner))
.clickHandler((panel, clicker, click, slot) -> { {
clicker.closeInventory();
Expand Down
23 changes: 13 additions & 10 deletions src/main/java/world/bentobox/warps/WarpSignsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public WarpSignsManager(Warp addon, BentoBox plugin) {
*/
public boolean addWarp(final UUID playerUUID, final Location loc) {
// Do not allow null players to set warps
if (playerUUID == null) {
if (playerUUID == null || loc == null) {
return false;
}
// Check for warps placed in a location where there was a warp before
Expand Down Expand Up @@ -148,7 +148,7 @@ public List<UUID> getSortedWarps(World world) {
}
// Fire event
WarpListEvent event = new WarpListEvent(addon, list);
addon.getServer().getPluginManager().callEvent(event);
Bukkit.getPluginManager().callEvent(event);
// Get the result of any changes by listeners
list = event.getWarps();
return list;
Expand Down Expand Up @@ -268,10 +268,13 @@ public SignCache getSignInfo(World world, UUID uuid) {
result.remove(0);
// Remove any trailing blank lines
result.removeIf(String::isEmpty);
// Set the initial color per lore setting
for (int i = 0; i< result.size(); i++) {
result.set(i, ChatColor.translateAlternateColorCodes('&', addon.getSettings().getLoreFormat()) + result.get(i));
}
// Get the sign type

String prefix = this.plugin.getIWM().getAddon(world).map(
Addon::getPermissionPrefix).orElse("");
String prefix = plugin.getIWM().getAddon(world).map(Addon::getPermissionPrefix).orElse("");

Material icon;

Expand Down Expand Up @@ -394,7 +397,7 @@ public void warpPlayer(World world, User user, UUID owner) {
return;
}

Island island = addon.getPlugin().getIslands().getIsland(world, owner);
Island island = addon.getIslands().getIsland(world, owner);
boolean pvp = false;
if (island != null) {
// Check for PVP
Expand All @@ -421,25 +424,25 @@ public void warpPlayer(World world, User user, UUID owner) {
Location inFront = b.getRelative(directionFacing).getLocation();
Location oneDown = b.getRelative(directionFacing).getRelative(BlockFace.DOWN).getLocation();
if ((plugin.getIslands().isSafeLocation(inFront))) {
addon.getWarpSignsManager().warpPlayer(user, inFront, owner, directionFacing, pvp);
warpPlayer(user, inFront, owner, directionFacing, pvp);
return;
} else if (plugin.getIslands().isSafeLocation(oneDown)) {
// Try one block down if this is a wall sign
addon.getWarpSignsManager().warpPlayer(user, oneDown, owner, directionFacing, pvp);
warpPlayer(user, oneDown, owner, directionFacing, pvp);
return;
}
} else if (b.getType().name().contains("SIGN")) {
org.bukkit.block.data.type.Sign s = (org.bukkit.block.data.type.Sign) b.getBlockData();
BlockFace directionFacing = s.getRotation();
Location inFront = b.getRelative(directionFacing).getLocation();
if ((plugin.getIslands().isSafeLocation(inFront))) {
addon.getWarpSignsManager().warpPlayer(user, inFront, owner, directionFacing, pvp);
if ((addon.getIslands().isSafeLocation(inFront))) {
warpPlayer(user, inFront, owner, directionFacing, pvp);
return;
}
} else {
// Warp has been removed
user.sendMessage("warps.error.does-not-exist");
addon.getWarpSignsManager().removeWarp(warpSpot);
removeWarp(warpSpot);
return;
}
if (!(plugin.getIslands().isSafeLocation(warpSpot))) {
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/world/bentobox/warps/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,19 @@ public class Settings implements ConfigObject
@ConfigComment(" - BSkyBlock")
@ConfigEntry(path = "disabled-gamemodes")
private Set<String> disabledGameModes = new HashSet<>();

@ConfigComment("")
@ConfigComment("Warp panel name formatting.")
@ConfigComment("Example: &c will make names red. &f is white")
@ConfigEntry(path = "name-format")
private String nameFormat = "&f";

@ConfigComment("")
@ConfigComment("Warp panel default lore formatting.")
@ConfigComment("Example: &c will make lore red. &f is white")
@ConfigEntry(path = "lore-format")
private String loreFormat = "&f";

// ---------------------------------------------------------------------
// Section: Constructor
// ---------------------------------------------------------------------
Expand Down Expand Up @@ -143,4 +155,38 @@ public void setIcon(String icon)
{
this.icon = icon;
}


/**
* @return the nameFormat
*/
public String getNameFormat() {
return nameFormat;
}


/**
* @param nameFormat the nameFormat to set
*/
public void setNameFormat(String nameFormat) {
this.nameFormat = nameFormat;
}


/**
* @return the loreFormat
*/
public String getLoreFormat() {
return loreFormat;
}


/**
* @param loreFormat the loreFormat to set
*/
public void setLoreFormat(String loreFormat) {
this.loreFormat = loreFormat;
}


}
8 changes: 8 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ icon: 'SIGN'
# disabled-gamemodes:
# - BSkyBlock
disabled-gamemodes: []
#
# Warp panel name formatting.
# Example: &c will make names red, &f is white
name-format: &f
#
# Warp panel default lore formatting.
# Example: &c will make lore red. &f is white
lore-format: &f

0 comments on commit bbc748a

Please sign in to comment.