Adds an option for a stargate without a sign #10

This commit is contained in:
Kristian Knarvik 2021-11-07 13:41:19 +01:00
parent 1565707809
commit fc744b04dc
8 changed files with 93 additions and 26 deletions

View File

@ -61,6 +61,7 @@ stargate.option -- Allow use of all options
stargate.option.nonetwork -- Allow use of 'N'oNetwork
stargate.option.random -- Allow use of 'R'andom stargates
stargate.option.silent -- Allow use of S'i'lent stargates
stargate.option.nosign -- Allow use of 'E' (No sign)
stargate.create -- Allow creating Stargates on any network (Override all create permissions)
stargate.create.personal -- Allow creating Stargates on network {playername}
@ -128,9 +129,10 @@ section). See the Custom Gate Layout section to learn how to add custom gates.
- 'S' is for showing an always-on gate in the network list
- 'N' is for hiding the network name
- 'R' is for random gates. These follow standard permissions of gates, but have a random exit location every time a
player enters.
- 'U' is for a gate connecting to another through bungee
player enters. (Implicitly always on)
- 'U' is for a gate connecting to another through bungee (Implicitly always on)
- 'I' is for a silent gate, which does not output anything to the chat while teleporting. Increases immersion
- 'E' is for gate without a sign. Only for fixed stargates
The options are the single letter, not the word. So to make a private hidden gate, your 4th line would be 'PH'.
@ -385,6 +387,8 @@ bungeeSign=Teleport to
- Adds an option to make a stargate silent (no text in chat when teleporting) for better immersion on RP servers
- Makes buttons update and/or remove themselves when their location or material changes
- Adds another default gate to show that it's possible to use any number of materials for a stargate's border
- Adds an option for stargates without a sign. Right-clicking such a stargate will display gate information
- Fixes a bug causing signs to be re-drawn after they're broken
#### \[Version 0.9.0.5] EpicKnarvik97 fork

View File

@ -1,6 +1,7 @@
package net.knarcraft.stargate.listener;
import net.knarcraft.stargate.Stargate;
import net.knarcraft.stargate.container.BlockChangeRequest;
import net.knarcraft.stargate.event.StargateDestroyEvent;
import net.knarcraft.stargate.portal.Portal;
import net.knarcraft.stargate.portal.PortalCreator;
@ -81,6 +82,12 @@ public class BlockEventListener implements Listener {
return;
}
//Remove the sign if the no sign option is enabled
if (portal.getOptions().hasNoSign()) {
BlockChangeRequest request = new BlockChangeRequest(portal.getSignLocation(), Material.AIR, null);
Stargate.addBlockChangeRequest(request);
}
Stargate.getMessageSender().sendSuccessMessage(player, Stargate.getString("createMsg"));
Stargate.debug("onSignChange", "Initialized stargate: " + portal.getName());
Stargate.getInstance().getServer().getScheduler().scheduleSyncDelayedTask(Stargate.getInstance(),

View File

@ -1,6 +1,7 @@
package net.knarcraft.stargate.listener;
import net.knarcraft.stargate.Stargate;
import net.knarcraft.stargate.config.MessageSender;
import net.knarcraft.stargate.container.BlockLocation;
import net.knarcraft.stargate.portal.Portal;
import net.knarcraft.stargate.portal.PortalActivator;
@ -11,6 +12,7 @@ import net.knarcraft.stargate.utility.BungeeHelper;
import net.knarcraft.stargate.utility.MaterialHelper;
import net.knarcraft.stargate.utility.PermissionHelper;
import net.knarcraft.stargate.utility.UUIDMigrationHelper;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.block.Block;
import org.bukkit.block.data.type.WallSign;
@ -264,12 +266,13 @@ public class PlayerEventListener implements Listener {
return;
}
if (MaterialHelper.isButtonCompatible(block.getType())) {
//Prevent a double click caused by a Spigot bug
if (clickIsBug(event, block)) {
return;
}
if (MaterialHelper.isButtonCompatible(block.getType())) {
Portal portal = PortalHandler.getByBlock(block);
if (portal == null) {
return;
@ -288,21 +291,48 @@ public class PlayerEventListener implements Listener {
if (portal.getPortalOpener().isOpenFor(player) && !MaterialHelper.isContainer(block.getType())) {
event.setUseInteractedBlock(Event.Result.ALLOW);
}
} else {
//Display information about the portal if it has no sign
displayPortalInfo(block, player);
}
}
/**
* This function decides if a right click of a coral is caused by a Spigot bug
* Displays information about a clicked portal
*
* <p>The Spigot bug currently makes every right click of a coral trigger twice, causing the portal to close
* immediately. This fix should detect the bug without breaking wall coral buttons once the bug is fixed.</p>
* <p>This will only display portal info if the portal has no sign and is not silent.</p>
*
* @param block <p>The clicked block</p>
* @param player <p>The player that clicked the block</p>
*/
private void displayPortalInfo(Block block, Player player) {
Portal portal = PortalHandler.getByBlock(block);
if (portal == null) {
return;
}
//Display portal information as a portal without a sign does not display any
if (portal.getOptions().hasNoSign() && !portal.getOptions().isSilent()) {
MessageSender sender = Stargate.getMessageSender();
sender.sendSuccessMessage(player, ChatColor.GOLD + "[PORTAL INFO]");
sender.sendSuccessMessage(player, String.format("Portal name: %s", portal.getName()));
sender.sendSuccessMessage(player, String.format("Portal destination: %s", portal.getDestinationName()));
sender.sendSuccessMessage(player, String.format("Portal network: %s", portal.getNetwork()));
}
}
/**
* This function decides if a right click of a block is caused by a Spigot bug
*
* <p>The Spigot bug currently makes every right click of some blocks trigger twice, causing the portal to close
* immediately, or causing portal information printing twice. This fix should detect the bug without breaking
* clicking once the bug is fixed.</p>
*
* @param event <p>The event causing the right click</p>
* @param block <p>The block to check</p>
* @return <p>True if the click is a bug and should be cancelled</p>
*/
private boolean clickIsBug(PlayerInteractEvent event, Block block) {
if (MaterialHelper.isWallCoral(block.getType())) {
if (previousEvent != null &&
event.getPlayer() == previousEvent.getPlayer() && eventTime + 15 > System.currentTimeMillis()) {
previousEvent = null;
@ -311,7 +341,6 @@ public class PlayerEventListener implements Listener {
}
previousEvent = event;
eventTime = System.currentTimeMillis();
}
return false;
}

View File

@ -63,9 +63,11 @@ public class PortalSignDrawer {
Block signBlock = portal.getSignLocation().getBlock();
BlockState state = signBlock.getState();
if (!(state instanceof Sign sign)) {
if (!portal.getOptions().hasNoSign()) {
Stargate.logWarning("Sign block is not a Sign object");
Stargate.debug("Portal::drawSign", String.format("Block: %s @ %s", signBlock.getType(),
signBlock.getLocation()));
}
return null;
}
return sign;
@ -122,7 +124,6 @@ public class PortalSignDrawer {
}
clearSign(sign);
sign.setLine(0, portal.getName());
sign.setLine(3, errorColor + Stargate.getString("signInvalidGate"));
sign.update();
}

View File

@ -53,7 +53,12 @@ public enum PortalOption {
/**
* This option allows a portal which does not display a teleportation message, for better immersion
*/
SILENT('i', "stargate.option.silent", 21);
SILENT('i', "stargate.option.silent", 21),
/**
* This option causes a fixed portal's sign to be removed after creation
*/
NO_SIGN('e', "stargate.option.nosign", 22);
private final char characterRepresentation;
private final String permissionString;

View File

@ -25,12 +25,17 @@ public class PortalOptions {
if (this.isAlwaysOn() && !isFixed) {
this.options.put(PortalOption.ALWAYS_ON, false);
Stargate.debug("Portal", "Can not create a non-fixed always-on gate. Setting AlwaysOn = false");
Stargate.debug("PortalOptions", "Can not create a non-fixed always-on gate. Setting AlwaysOn = false");
}
if ((this.isRandom() || this.isBungee()) && !this.isAlwaysOn()) {
this.options.put(PortalOption.ALWAYS_ON, true);
Stargate.debug("Portal", "Gate marked as random or bungee, set to always-on");
Stargate.debug("PortalOptions", "Gate marked as random or bungee, set to always-on");
}
if (this.hasNoSign() && !this.isFixed) {
this.options.put(PortalOption.NO_SIGN, false);
Stargate.debug("PortalOptions", "Gate marked with no sign, but not fixed. Setting NoSign = false");
}
}
@ -177,4 +182,15 @@ public class PortalOptions {
return this.options.get(PortalOption.SILENT);
}
/**
* Gets whether this portal has no sign
*
* <p>An always-on portal is allowed to not have a sign as it will never be interacted with anyway.</p>
*
* @return <p>Whether this portal has no sign</p>
*/
public boolean hasNoSign() {
return this.options.get(PortalOption.NO_SIGN);
}
}

View File

@ -122,7 +122,8 @@ public final class PortalFileHelper {
builder.append(options.isNoNetwork()).append(':');
builder.append(options.isRandom()).append(':');
builder.append(options.isBungee()).append(':');
builder.append(options.isSilent());
builder.append(options.isSilent()).append(':');
builder.append(options.hasNoSign());
}
/**

View File

@ -98,6 +98,7 @@ permissions:
stargate.option.nonetwork: true
stargate.option.random: true
stargate.option.silent: true
stargate.option.nosign: true
stargate.option.hidden:
description: Allows the creation of a hidden stargate
default: false
@ -125,6 +126,9 @@ permissions:
stargate.option.silent:
description: Allows the creation of a stargate which does not output anything to the chat
default: false
stargate.option.nosign:
description: Allows the creation of a stargate which has no sign
default: false
stargate.admin.hidden:
description: Allows this player to see all hidden stargates
default: false