Compare commits
33 Commits
Author | SHA1 | Date | |
---|---|---|---|
445638a561 | |||
7f9dc6756b | |||
b2bb995d7e | |||
f92fd2de5d | |||
2ed0fe7817 | |||
27b964837f | |||
4b34ea3cf5 | |||
0740cd0a66 | |||
bab51d76fd | |||
6ddc15eeef | |||
14511f558d | |||
32975ca35d | |||
6e7ac5dbb9 | |||
2b4d15dab4 | |||
22bb75d4df | |||
ab9a118d49 | |||
a80a8520ce | |||
48bb68d665 | |||
1247c54899 | |||
37ac3d4877 | |||
70495220eb | |||
10c3914a60 | |||
4699f717ec | |||
29c1a00fcd | |||
51f5420f9e | |||
e1a3d2d560 | |||
a84210d550 | |||
351d1762e7 | |||
2c53b7d2a6 | |||
42e02eb141 | |||
ad310ddb9c | |||
3db630f60e | |||
7a03f49fb1 |
81
README.md
81
README.md
@ -3,18 +3,18 @@
|
||||
Create gates that allow for instant-teleportation between large distances. Gates can be always-open or triggered; they
|
||||
can share a network or be split into clusters; they can be hidden on a network or accessible to everybody.
|
||||
|
||||
- Player permissions -- let players build their own networks.
|
||||
- Vault economy support -- can add costs for create, destroy and use.
|
||||
- Ability to create custom gate configurations. Three different default gate configurations are available.
|
||||
- Message customization
|
||||
- Multiple built-in languages (de, en, es, fr, hu, it, nb-no, nl, nn-no, pt-br, ru)
|
||||
- Teleport across worlds or servers (BungeeCord supported)
|
||||
- Vehicle teleportation -- teleport minecarts, boats, horses, pigs and striders
|
||||
- Leashed teleportation -- teleport any creature in a leash with the player
|
||||
- Underwater portals -- portals can be placed underwater as long as a waterproof button is used
|
||||
- API available -- using the API, a lot of behavior can be changed
|
||||
- Button customization -- a large amount of materials usable as buttons (buttons, wall corals, shulkers, chests)
|
||||
- Config commands -- All main config values can be changed from the commandline
|
||||
- **Player permissions** -- let players build their own networks.
|
||||
- **Vault economy support** -- can add costs for create, destroy and use.
|
||||
- **Ability to create custom gate configurations**. Four different default gate configurations are available.
|
||||
- **Message customization**
|
||||
- **Multiple built-in languages** (de, en, es, fr, hu, it, nb-no, nl, nn-no, pt-br, ru)
|
||||
- **Teleport across worlds or servers** (BungeeCord supported)
|
||||
- **Vehicle teleportation** -- teleport minecarts, boats, horses, pigs and striders
|
||||
- **Leashed teleportation** -- teleport any creature in a leash with the player
|
||||
- **Underwater portals** -- portals can be placed underwater as long as a waterproof button is used
|
||||
- **API available** -- using the API, a lot of behavior can be changed
|
||||
- **Button customization** -- a large amount of materials usable as buttons (buttons, wall corals, shulkers, chests)
|
||||
- **Config commands** -- All main config values can be changed from the commandline
|
||||
|
||||
## Background
|
||||
|
||||
@ -36,10 +36,8 @@ Permissions have had a few changes, so you should check the permissions section
|
||||
permissions.
|
||||
|
||||
Payment to owner using Economy, through Vault, is only possible if the portal owner in the portal database is defined by
|
||||
a UUID, and not a username. Right now, there is no automatic upgrade from usernames to UUID. You must either make the
|
||||
stargate owner re-create the stargate or edit the file in the portals folder in a text editor. There are various ways to
|
||||
find the UUID of players. You may look in the usercache.json file in the server directory or search for the username on
|
||||
various websites.
|
||||
a UUID, and not a username. A player name will be upgraded to a UUID when the player with the given name joins the
|
||||
server.
|
||||
|
||||
# Permissions
|
||||
|
||||
@ -119,9 +117,9 @@ section). See the Custom Gate Layout section to learn how to add custom gates.
|
||||
|
||||
### Sign Layout:
|
||||
|
||||
- Line 1: Gate Name (Max 11 characters)
|
||||
- Line 2: Destination Name \[Optional] (Max 11 characters, used for fixed-gates only)
|
||||
- Line 3: Network name \[Optional] (Max 11 characters)
|
||||
- Line 1: Gate Name (Max 13 characters)
|
||||
- Line 2: Destination Name \[Optional] (Max 13 characters, used for fixed-gates only)
|
||||
- Line 3: Network name \[Optional] (Max 13 characters)
|
||||
- Line 4: Options \[Optional] :
|
||||
- 'A' for always-on fixed gate
|
||||
- 'H' for hidden networked gate
|
||||
@ -134,9 +132,11 @@ section). See the Custom Gate Layout section to learn how to add custom gates.
|
||||
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
|
||||
- 'E' is for a 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'.
|
||||
The options are the single letter, not the word. So to make a private hidden gate, your 4th line would be 'PH'. The
|
||||
&\[0-9a-f] color codes are not counted in the character limit, thus allowing a 13-character name with an additional 2
|
||||
characters used for the color code.
|
||||
|
||||
#### Gate networks:
|
||||
|
||||
@ -323,7 +323,8 @@ economy:
|
||||
useCost - The cost to use a stargate
|
||||
toOwner - Whether the money from gate-use goes to the owner or nobody
|
||||
chargeFreeDestination - Enable to make players pay for teleportation even if the destination is free
|
||||
freeGatesGreen - Enable to make gates that won't cost the player money show up as green
|
||||
freeGatesColored - Enable to make gates that won't cost the player money show up as green
|
||||
freeGatesColor - This allows you to specify the color of the markings and name of free stargates
|
||||
debugging:
|
||||
debug - Whether to show massive debug output
|
||||
permissionDebug - Whether to show massive permission debug output
|
||||
@ -388,6 +389,42 @@ portalInfoServer=Server: %server%
|
||||
|
||||
# Changes
|
||||
|
||||
#### \[Version 0.9.2.3] EpicKnarvik97 fork
|
||||
|
||||
- Fixes a typo which caused both colors to change into the highlightSignColor
|
||||
|
||||
#### \[Version 0.9.2.2] EpicKnarvik97 fork
|
||||
|
||||
- Prevents teleportation of a player holding creatures on a leash when handleLeashedCreatures is disabled, to prevent
|
||||
players accidentally losing the creatures during teleportation
|
||||
- Fixes a potential exception when a gate's open-block or closed-block is set to a material which isn't a block
|
||||
- Fixes a potential exception when a portal without a sign has an invalid gate type
|
||||
- Prevents loading of gate files using non-blocks as part of the border
|
||||
- Prevents a player smuggling another player through a restricted stargate by sitting on a creature held in a lead by
|
||||
the first player
|
||||
|
||||
#### \[Version 0.9.2.1] EpicKnarvik97 fork
|
||||
|
||||
- Makes sure to only reload whatever is necessary when config values are changed using commands, instead of reloading
|
||||
the entire config file every time
|
||||
- Protects portals from block placement when protectEntrance is enabled
|
||||
|
||||
#### \[Version 0.9.2.0] EpicKnarvik97 fork
|
||||
|
||||
- Increases max length of names and networks to 13 characters
|
||||
- Excludes color codes from the counted character length to allow a colored, 13-character name
|
||||
- Makes portal names and networks case- and color-agnostic to prevent some confusion caused by typos or sloppy
|
||||
configuration
|
||||
- Makes the free gate color configurable, and renames freeGatesGreen to freeGatesColored
|
||||
|
||||
#### \[Version 0.9.1.2] EpicKnarvik97 fork
|
||||
|
||||
- Allows a sneaking player to see information about a silent stargate with no sign
|
||||
|
||||
#### \[Version 0.9.1.1] EpicKnarvik97 fork
|
||||
|
||||
- Makes sure to translate the `&` character to fix a bug causing portal signs to not be colored on some servers
|
||||
|
||||
#### \[Version 0.9.1.0] EpicKnarvik97 fork
|
||||
|
||||
- Rewrites config loading as a part of the changes required to implement config commands
|
||||
|
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
||||
|
||||
<groupId>net.knarcraft</groupId>
|
||||
<artifactId>Stargate</artifactId>
|
||||
<version>0.9.1.0</version>
|
||||
<version>0.9.2.3</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
|
@ -139,6 +139,16 @@ public class Stargate extends JavaPlugin {
|
||||
return logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the max length of portal names and networks
|
||||
*
|
||||
* @return <p>The max portal name/network length</p>
|
||||
*/
|
||||
@SuppressWarnings("SameReturnValue")
|
||||
public static int getMaxNameNetworkLength() {
|
||||
return 13;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a debug message
|
||||
*
|
||||
|
@ -2,6 +2,10 @@ package net.knarcraft.stargate.command;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.ConfigOption;
|
||||
import net.knarcraft.stargate.config.ConfigTag;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
import net.knarcraft.stargate.portal.PortalSignDrawer;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -55,7 +59,7 @@ public class CommandConfig implements CommandExecutor {
|
||||
FileConfiguration configuration = Stargate.getInstance().getConfig();
|
||||
|
||||
//Validate any sign colors
|
||||
if (selectedOption == ConfigOption.MAIN_SIGN_COLOR || selectedOption == ConfigOption.HIGHLIGHT_SIGN_COLOR) {
|
||||
if (ConfigTag.COLOR.isTagged(selectedOption)) {
|
||||
try {
|
||||
ChatColor.valueOf(value.toUpperCase());
|
||||
} catch (IllegalArgumentException | NullPointerException ignored) {
|
||||
@ -66,13 +70,21 @@ public class CommandConfig implements CommandExecutor {
|
||||
|
||||
//Store the config values, accounting for the data type
|
||||
switch (selectedOption.getDataType()) {
|
||||
case BOOLEAN -> configuration.set(selectedOption.getConfigNode(), Boolean.parseBoolean(value));
|
||||
case BOOLEAN -> {
|
||||
boolean newValue = Boolean.parseBoolean(value);
|
||||
if (selectedOption == ConfigOption.ENABLE_BUNGEE && newValue != Stargate.getGateConfig().enableBungee()) {
|
||||
Stargate.getStargateConfig().startStopBungeeListener(newValue);
|
||||
}
|
||||
Stargate.getStargateConfig().getConfigOptionsReference().put(selectedOption, newValue);
|
||||
configuration.set(selectedOption.getConfigNode(), newValue);
|
||||
}
|
||||
case INTEGER -> {
|
||||
try {
|
||||
configuration.set(selectedOption.getConfigNode(), Integer.parseInt(value));
|
||||
} catch (NumberFormatException exception) {
|
||||
commandSender.sendMessage(ChatColor.RED + "Invalid number given");
|
||||
Integer intValue = getInteger(commandSender, selectedOption, value);
|
||||
if (intValue == null) {
|
||||
return;
|
||||
} else {
|
||||
Stargate.getStargateConfig().getConfigOptionsReference().put(selectedOption, intValue);
|
||||
configuration.set(selectedOption.getConfigNode(), intValue);
|
||||
}
|
||||
}
|
||||
case STRING -> {
|
||||
@ -83,26 +95,119 @@ public class CommandConfig implements CommandExecutor {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (ConfigTag.COLOR.isTagged(selectedOption)) {
|
||||
if (!registerColor(selectedOption, value, commandSender)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (selectedOption == ConfigOption.LANGUAGE) {
|
||||
Stargate.getStargateConfig().getLanguageLoader().setChosenLanguage(value);
|
||||
}
|
||||
Stargate.getStargateConfig().getConfigOptionsReference().put(selectedOption, value);
|
||||
configuration.set(selectedOption.getConfigNode(), value);
|
||||
}
|
||||
default -> {
|
||||
Stargate.getStargateConfig().getConfigOptionsReference().put(selectedOption, value);
|
||||
configuration.set(selectedOption.getConfigNode(), value);
|
||||
}
|
||||
default -> configuration.set(selectedOption.getConfigNode(), value);
|
||||
}
|
||||
|
||||
//Save the config file and reload if necessary
|
||||
Stargate.getInstance().saveConfig();
|
||||
reloadIfNecessary(commandSender);
|
||||
|
||||
Stargate.getMessageSender().sendSuccessMessage(commandSender, "Config updated");
|
||||
|
||||
//Reload whatever is necessary
|
||||
reloadIfNecessary(commandSender, selectedOption);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the chat color if
|
||||
*
|
||||
* @param selectedOption <p>The option to change</p>
|
||||
* @param commandSender <p>The command sender to alert if the color is invalid</p>
|
||||
* @param value <p>The new option value</p>
|
||||
*/
|
||||
private boolean registerColor(ConfigOption selectedOption, String value, CommandSender commandSender) {
|
||||
ChatColor parsedColor = parseColor(value);
|
||||
if (parsedColor == null) {
|
||||
commandSender.sendMessage(ChatColor.RED + "Invalid color given");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (selectedOption == ConfigOption.FREE_GATES_COLOR) {
|
||||
PortalSignDrawer.setFreeColor(parsedColor);
|
||||
} else if (selectedOption == ConfigOption.MAIN_SIGN_COLOR) {
|
||||
PortalSignDrawer.setMainColor(parsedColor);
|
||||
} else if (selectedOption == ConfigOption.HIGHLIGHT_SIGN_COLOR) {
|
||||
PortalSignDrawer.setHighlightColor(parsedColor);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a chat color
|
||||
*
|
||||
* @param value <p>The value to parse</p>
|
||||
* @return <p>The parsed color or null</p>
|
||||
*/
|
||||
private ChatColor parseColor(String value) {
|
||||
try {
|
||||
return ChatColor.valueOf(value.toUpperCase());
|
||||
} catch (IllegalArgumentException | NullPointerException ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an integer from a string
|
||||
*
|
||||
* @param commandSender <p>The command sender that sent the config command</p>
|
||||
* @param selectedOption <p>The option the command sender is trying to change</p>
|
||||
* @param value <p>The value given</p>
|
||||
* @return <p>An integer, or null if it was invalid</p>
|
||||
*/
|
||||
private Integer getInteger(CommandSender commandSender, ConfigOption selectedOption, String value) {
|
||||
try {
|
||||
int intValue = Integer.parseInt(value);
|
||||
|
||||
if ((selectedOption == ConfigOption.USE_COST || selectedOption == ConfigOption.CREATE_COST) && intValue < 0) {
|
||||
commandSender.sendMessage(ChatColor.RED + "This config option cannot be negative.");
|
||||
return null;
|
||||
}
|
||||
|
||||
return intValue;
|
||||
} catch (NumberFormatException exception) {
|
||||
commandSender.sendMessage(ChatColor.RED + "Invalid number given");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the config if necessary
|
||||
*
|
||||
* @param commandSender <p>The command sender initiating the reload</p>
|
||||
* @param configOption <p>The changed config option</p>
|
||||
*/
|
||||
private void reloadIfNecessary(CommandSender commandSender) {
|
||||
//TODO: Only update the config values which have changed and do the least amount of work necessary to load the
|
||||
// changes. Only do a full reload if absolutely necessary, or when the partial reloading would be as
|
||||
// inefficient as a full reload.
|
||||
Stargate.getStargateConfig().reload(commandSender);
|
||||
private void reloadIfNecessary(CommandSender commandSender, ConfigOption configOption) {
|
||||
if (ConfigTag.requiresFullReload(configOption)) {
|
||||
//Reload everything
|
||||
Stargate.getStargateConfig().reload(commandSender);
|
||||
} else if (ConfigTag.requiresPortalReload(configOption)) {
|
||||
//Just unload and reload the portals
|
||||
Stargate.getStargateConfig().unloadAllPortals();
|
||||
Stargate.getStargateConfig().loadAllPortals();
|
||||
} else if (ConfigTag.requiresLanguageReload(configOption)) {
|
||||
//Reload the language loader
|
||||
Stargate.getStargateConfig().getLanguageLoader().reload();
|
||||
//Re-draw all portal signs
|
||||
for (Portal portal : PortalRegistry.getAllPortals()) {
|
||||
portal.drawSign();
|
||||
}
|
||||
} else if (ConfigTag.requiresEconomyReload(configOption)) {
|
||||
//Load or unload Vault and Economy as necessary
|
||||
Stargate.getStargateConfig().reloadEconomy();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -86,6 +86,7 @@ public class ConfigTabCompleter implements TabCompleter {
|
||||
}
|
||||
case MAIN_SIGN_COLOR:
|
||||
case HIGHLIGHT_SIGN_COLOR:
|
||||
case FREE_GATES_COLOR:
|
||||
//Return all colors
|
||||
return filterMatching(getColors(), typedText);
|
||||
}
|
||||
|
@ -9,86 +9,144 @@ public enum ConfigOption {
|
||||
* The language used for player-interface text
|
||||
*/
|
||||
LANGUAGE("language", "The language used for all signs and all messages to players", "en"),
|
||||
|
||||
/**
|
||||
* The folder for portal files
|
||||
*/
|
||||
PORTAL_FOLDER("folders.portalFolder", "The folder containing the portal databases", "plugins/Stargate/portals/"),
|
||||
|
||||
/**
|
||||
* The folder for gate files
|
||||
*/
|
||||
GATE_FOLDER("folders.gateFolder", "The folder containing all gate files", "plugins/Stargate/gates/"),
|
||||
|
||||
/**
|
||||
* The max number of portals on a single network
|
||||
*/
|
||||
MAX_GATES_EACH_NETWORK("gates.maxGatesEachNetwork", "The max number of stargates in a single network", 0),
|
||||
|
||||
/**
|
||||
* The network used if not specified
|
||||
*/
|
||||
DEFAULT_GATE_NETWORK("gates.defaultGateNetwork", "The network used when no network is specified", "central"),
|
||||
|
||||
/**
|
||||
* Whether to remember the lastly used destination
|
||||
*/
|
||||
REMEMBER_DESTINATION("gates.cosmetic.rememberDestination", "Whether to remember the last destination used", false),
|
||||
|
||||
/**
|
||||
* Whether to sort the network destinations
|
||||
*/
|
||||
SORT_NETWORK_DESTINATIONS("gates.cosmetic.sortNetworkDestinations", "Whether to sort destinations by name", false),
|
||||
|
||||
/**
|
||||
* The main color to use for all signs
|
||||
*/
|
||||
MAIN_SIGN_COLOR("gates.cosmetic.mainSignColor", "The main text color of all stargate signs", "BLACK"),
|
||||
|
||||
/**
|
||||
* The color to use for highlighting sign text
|
||||
*/
|
||||
HIGHLIGHT_SIGN_COLOR("gates.cosmetic.highlightSignColor", "The text color used for highlighting stargate signs", "WHITE"),
|
||||
|
||||
/**
|
||||
* Whether to destroy portals when any blocks are broken by explosions
|
||||
*/
|
||||
DESTROYED_BY_EXPLOSION("gates.integrity.destroyedByExplosion", "Whether stargates should be destroyed by explosions", false),
|
||||
|
||||
/**
|
||||
* Whether to verify each portal's gate layout after each load
|
||||
*/
|
||||
VERIFY_PORTALS("gates.integrity.verifyPortals", "Whether to verify that portals match their gate layout on load", false),
|
||||
|
||||
/**
|
||||
* Whether to protect the entrance of portals
|
||||
*/
|
||||
PROTECT_ENTRANCE("gates.integrity.protectEntrance", "Whether to protect stargates' entrances", false),
|
||||
|
||||
/**
|
||||
* Whether to enable BungeeCord support
|
||||
*/
|
||||
ENABLE_BUNGEE("gates.functionality.enableBungee", "Whether to enable BungeeCord support", false),
|
||||
|
||||
/**
|
||||
* Whether to enable vehicle teleportation
|
||||
*/
|
||||
HANDLE_VEHICLES("gates.functionality.handleVehicles", "Whether to enable vehicle teleportation", true),
|
||||
|
||||
/**
|
||||
* Whether to enable teleportation of empty vehicles
|
||||
*/
|
||||
HANDLE_EMPTY_VEHICLES("gates.functionality.handleEmptyVehicles", "Whether to enable teleportation of empty vehicles", true),
|
||||
|
||||
/**
|
||||
* Whether to enable teleportation of creatures using vehicles
|
||||
*/
|
||||
HANDLE_CREATURE_TRANSPORTATION("gates.functionality.handleCreatureTransportation",
|
||||
"Whether to enable teleportation of vehicles containing non-player creatures", true),
|
||||
|
||||
/**
|
||||
* Whether to allow creatures to teleport alone, bypassing any access restrictions
|
||||
*/
|
||||
HANDLE_NON_PLAYER_VEHICLES("gates.functionality.handleNonPlayerVehicles",
|
||||
"Whether to enable teleportation of non-empty vehicles without a player", true),
|
||||
|
||||
/**
|
||||
* Whether to enable teleportations of creatures on a leash
|
||||
*/
|
||||
HANDLE_LEASHED_CREATURES("gates.functionality.handleLeashedCreatures",
|
||||
"Whether to enable players to teleport a creature on a leash", true),
|
||||
|
||||
/**
|
||||
* Whether to enable economy support for taking payment from players creating/destroying/using stargates
|
||||
*/
|
||||
USE_ECONOMY("economy.useEconomy", "Whether to use economy to incur fees when stargates are used, created or destroyed", false),
|
||||
|
||||
/**
|
||||
* The cost of creating a new stargate
|
||||
*/
|
||||
CREATE_COST("economy.createCost", "The cost of creating a new stargate", 0),
|
||||
|
||||
/**
|
||||
* The cost of destroying a stargate
|
||||
*/
|
||||
DESTROY_COST("economy.destroyCost", "The cost of destroying a stargate. Negative to refund", 0),
|
||||
|
||||
/**
|
||||
* The cost of using (teleporting through) a stargate
|
||||
*/
|
||||
USE_COST("economy.useCost", "The cost of using (teleporting through) a stargate", 0),
|
||||
|
||||
/**
|
||||
* Whether any payments should go to the stargate's owner
|
||||
*/
|
||||
TO_OWNER("economy.toOwner", "Whether any teleportation fees should go to the owner of the used stargate", false),
|
||||
|
||||
/**
|
||||
* Whether to charge for using a stargate, even if its destination is free
|
||||
*/
|
||||
CHARGE_FREE_DESTINATION("economy.chargeFreeDestination",
|
||||
"Whether to require payment if the destination is free, but the entrance stargate is not", true),
|
||||
FREE_GATES_GREEN("economy.freeGatesGreen", "Whether to use green coloring to mark all free stargates", false),
|
||||
|
||||
/**
|
||||
* Whether to mark free gates with a different color
|
||||
*/
|
||||
FREE_GATES_COLORED("economy.freeGatesColored", "Whether to use coloring to mark all free stargates", false),
|
||||
|
||||
/**
|
||||
* The color to use for marking free stargates
|
||||
*/
|
||||
FREE_GATES_COLOR("economy.freeGatesColor", "The color to use for marking free stargates", "DARK_GREEN"),
|
||||
|
||||
/**
|
||||
* Whether to enable debug output
|
||||
*/
|
||||
DEBUG("debugging.debug", "Whether to enable debugging output", false),
|
||||
|
||||
/**
|
||||
* Whether to enable debug output for debugging permissions
|
||||
*/
|
||||
PERMISSION_DEBUG("debugging.permissionDebug", "Whether to enable permission debugging output", false);
|
||||
|
||||
|
||||
|
74
src/main/java/net/knarcraft/stargate/config/ConfigTag.java
Normal file
74
src/main/java/net/knarcraft/stargate/config/ConfigTag.java
Normal file
@ -0,0 +1,74 @@
|
||||
package net.knarcraft.stargate.config;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* A config tag groups config values by a property
|
||||
*/
|
||||
public enum ConfigTag {
|
||||
|
||||
COLOR(new ConfigOption[]{ConfigOption.FREE_GATES_COLOR, ConfigOption.MAIN_SIGN_COLOR, ConfigOption.HIGHLIGHT_SIGN_COLOR}),
|
||||
FOLDER(new ConfigOption[]{ConfigOption.GATE_FOLDER, ConfigOption.PORTAL_FOLDER});
|
||||
|
||||
private final ConfigOption[] taggedOptions;
|
||||
|
||||
/**
|
||||
* Instantiates a new config tag
|
||||
*
|
||||
* @param taggedOptions <p>The config options included in this tag</p>
|
||||
*/
|
||||
ConfigTag(ConfigOption[] taggedOptions) {
|
||||
this.taggedOptions = taggedOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a config tag includes the given config option
|
||||
*
|
||||
* @param option <p>The config option to check</p>
|
||||
* @return <p>True of the config option is tagged</p>
|
||||
*/
|
||||
public boolean isTagged(ConfigOption option) {
|
||||
return Arrays.stream(taggedOptions).anyMatch((item) -> item == option);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a given config option requires a full reload to take effect
|
||||
*
|
||||
* @param option <p>The config option to check</p>
|
||||
* @return <p>True if changing the config option requires a full reload to take effect</p>
|
||||
*/
|
||||
public static boolean requiresFullReload(ConfigOption option) {
|
||||
return FOLDER.isTagged(option);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a given config option requires a portal reload to take effect
|
||||
*
|
||||
* @param option <p>The config option to check</p>
|
||||
* @return <p>True if changing the config option requires a portal reload to take effect</p>
|
||||
*/
|
||||
public static boolean requiresPortalReload(ConfigOption option) {
|
||||
return COLOR.isTagged(option) || FOLDER.isTagged(option) || option == ConfigOption.VERIFY_PORTALS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a given config option requires the language loader to be reloaded
|
||||
*
|
||||
* @param option <p>The config option to check</p>
|
||||
* @return <p>True if the language loader requires a reload</p>
|
||||
*/
|
||||
public static boolean requiresLanguageReload(ConfigOption option) {
|
||||
return option == ConfigOption.LANGUAGE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a given config option requires economy to be reloaded
|
||||
*
|
||||
* @param option <p>The config option to check</p>
|
||||
* @return <p>True if economy requires a reload</p>
|
||||
*/
|
||||
public static boolean requiresEconomyReload(ConfigOption option) {
|
||||
return option == ConfigOption.USE_ECONOMY;
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
package net.knarcraft.stargate.config;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalSignDrawer;
|
||||
import net.knarcraft.stargate.portal.property.gate.Gate;
|
||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
@ -13,22 +13,16 @@ import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.ServicesManager;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* The economy config keeps track of economy config values and performs economy actions such as payment for using a gate
|
||||
*/
|
||||
public final class EconomyConfig {
|
||||
|
||||
private boolean economyEnabled = false;
|
||||
private Economy economy = null;
|
||||
private Plugin vault = null;
|
||||
private int useCost = 0;
|
||||
private int createCost = 0;
|
||||
private int destroyCost = 0;
|
||||
private boolean toOwner = false;
|
||||
private boolean chargeFreeDestination = true;
|
||||
private boolean freeGatesGreen = false;
|
||||
|
||||
private final Map<ConfigOption, Object> configOptions;
|
||||
|
||||
/**
|
||||
* Instantiates a new economy config
|
||||
@ -36,7 +30,13 @@ public final class EconomyConfig {
|
||||
* @param configOptions <p>The loaded config options to read</p>
|
||||
*/
|
||||
public EconomyConfig(Map<ConfigOption, Object> configOptions) {
|
||||
loadEconomyConfig(configOptions);
|
||||
this.configOptions = configOptions;
|
||||
try {
|
||||
String freeColor = (String) configOptions.get(ConfigOption.FREE_GATES_COLOR);
|
||||
PortalSignDrawer.setFreeColor(ChatColor.valueOf(freeColor.toUpperCase()));
|
||||
} catch (IllegalArgumentException | NullPointerException ignored) {
|
||||
PortalSignDrawer.setFreeColor(ChatColor.DARK_GREEN);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -45,7 +45,7 @@ public final class EconomyConfig {
|
||||
* @return <p>The gate use cost</p>
|
||||
*/
|
||||
public int getDefaultUseCost() {
|
||||
return useCost;
|
||||
return (Integer) configOptions.get(ConfigOption.USE_COST);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -54,7 +54,7 @@ public final class EconomyConfig {
|
||||
* @return <p>Whether economy is enabled</p>
|
||||
*/
|
||||
public boolean isEconomyEnabled() {
|
||||
return economyEnabled;
|
||||
return (boolean) configOptions.get(ConfigOption.USE_ECONOMY);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -84,12 +84,12 @@ public final class EconomyConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether free portals should be marked with green coloring
|
||||
* Gets whether free portals should be marked with a different coloring
|
||||
*
|
||||
* @return <p>Whether free portals should be green</p>
|
||||
* @return <p>Whether free portals should be colored</p>
|
||||
*/
|
||||
public boolean drawFreePortalsGreen() {
|
||||
return freeGatesGreen;
|
||||
public boolean drawFreePortalsColored() {
|
||||
return (boolean) configOptions.get(ConfigOption.FREE_GATES_COLORED);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -101,8 +101,8 @@ public final class EconomyConfig {
|
||||
*
|
||||
* @return <p>Whether to charge for free destinations</p>
|
||||
*/
|
||||
public boolean chargeFreeDestination() {
|
||||
return chargeFreeDestination;
|
||||
public boolean freeIfFreeDestination() {
|
||||
return !((boolean) configOptions.get(ConfigOption.CHARGE_FREE_DESTINATION));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,21 +111,7 @@ public final class EconomyConfig {
|
||||
* @return <p>Whether to send payments to the portal owner</p>
|
||||
*/
|
||||
public boolean sendPaymentToOwner() {
|
||||
return toOwner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cost of using a gate without a specified cost
|
||||
*
|
||||
* <p>The use cost cannot be negative.</p>
|
||||
*
|
||||
* @param useCost <p>The gate use cost</p>
|
||||
*/
|
||||
public void setDefaultUseCost(int useCost) {
|
||||
if (useCost < 0) {
|
||||
throw new IllegalArgumentException("Using a gate cannot cost a negative amount");
|
||||
}
|
||||
this.useCost = useCost;
|
||||
return (boolean) configOptions.get(ConfigOption.TO_OWNER);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,18 +120,7 @@ public final class EconomyConfig {
|
||||
* @return <p>The gate creation cost</p>
|
||||
*/
|
||||
public int getDefaultCreateCost() {
|
||||
return createCost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cost of creating a gate without a specified cost
|
||||
*
|
||||
* <p>The gate create cost cannot be negative</p>
|
||||
*
|
||||
* @param createCost <p>The gate creation cost</p>
|
||||
*/
|
||||
public void setDefaultCreateCost(int createCost) {
|
||||
this.createCost = createCost;
|
||||
return (Integer) configOptions.get(ConfigOption.CREATE_COST);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -154,31 +129,7 @@ public final class EconomyConfig {
|
||||
* @return <p>The gate destruction cost</p>
|
||||
*/
|
||||
public int getDefaultDestroyCost() {
|
||||
return destroyCost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cost of destroying a gate without a specified cost
|
||||
*
|
||||
* @param destroyCost <p>The gate destruction cost</p>
|
||||
*/
|
||||
public void setDefaultDestroyCost(int destroyCost) {
|
||||
this.destroyCost = destroyCost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Charges the player for an action, if required
|
||||
*
|
||||
* @param player <p>The player to take money from</p>
|
||||
* @param cost <p>The cost of the transaction</p>
|
||||
* @return <p>True if the player was charged successfully</p>
|
||||
*/
|
||||
public boolean chargePlayerIfNecessary(Player player, int cost) {
|
||||
if (skipPayment(cost)) {
|
||||
return true;
|
||||
}
|
||||
//Charge player
|
||||
return chargePlayer(player, cost);
|
||||
return (Integer) configOptions.get(ConfigOption.DESTROY_COST);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -192,22 +143,6 @@ public final class EconomyConfig {
|
||||
return economy.getBalance(player) > cost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Charges the player for an action, if required
|
||||
*
|
||||
* @param player <p>The player to take money from</p>
|
||||
* @param target <p>The target to pay</p>
|
||||
* @param cost <p>The cost of the transaction</p>
|
||||
* @return <p>True if the player was charged successfully</p>
|
||||
*/
|
||||
public boolean chargePlayerIfNecessary(Player player, UUID target, int cost) {
|
||||
if (skipPayment(cost)) {
|
||||
return true;
|
||||
}
|
||||
//Charge player
|
||||
return chargePlayer(player, target, cost);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a formatted string for an amount, adding the name of the currency
|
||||
*
|
||||
@ -215,7 +150,7 @@ public final class EconomyConfig {
|
||||
* @return <p>A formatted text string describing the amount</p>
|
||||
*/
|
||||
public String format(int amount) {
|
||||
if (economyEnabled) {
|
||||
if (isEconomyEnabled()) {
|
||||
return economy.format(amount);
|
||||
} else {
|
||||
return "";
|
||||
@ -229,7 +164,7 @@ public final class EconomyConfig {
|
||||
* @return <p>True if economy was enabled</p>
|
||||
*/
|
||||
public boolean setupEconomy(PluginManager pluginManager) {
|
||||
if (!economyEnabled) {
|
||||
if (!isEconomyEnabled()) {
|
||||
return false;
|
||||
}
|
||||
//Check if vault is loaded
|
||||
@ -247,7 +182,7 @@ public final class EconomyConfig {
|
||||
} else {
|
||||
Stargate.logInfo(Stargate.getString("vaultLoadError"));
|
||||
}
|
||||
economyEnabled = false;
|
||||
configOptions.put(ConfigOption.USE_ECONOMY, false);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -257,46 +192,7 @@ public final class EconomyConfig {
|
||||
* @return <p>True if the user has turned on economy and economy is available</p>
|
||||
*/
|
||||
public boolean useEconomy() {
|
||||
return economyEnabled && economy != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a payment transaction should be skipped
|
||||
*
|
||||
* @param cost <p>The cost of the transaction</p>
|
||||
* @return <p>True if the transaction should be skipped</p>
|
||||
*/
|
||||
private boolean skipPayment(int cost) {
|
||||
return cost == 0 || !useEconomy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the cost of using a gate
|
||||
*
|
||||
* @param player <p>The player trying to use the gate</p>
|
||||
* @param source <p>The source/entry portal</p>
|
||||
* @param destination <p>The destination portal</p>
|
||||
* @return <p>The cost of using the portal</p>
|
||||
*/
|
||||
public int getUseCost(Player player, Portal source, Portal destination) {
|
||||
//No payment required
|
||||
if (!useEconomy() || source.getOptions().isFree()) {
|
||||
return 0;
|
||||
}
|
||||
//Not charging for free destinations
|
||||
if (destination != null && !chargeFreeDestination && destination.getOptions().isFree()) {
|
||||
return 0;
|
||||
}
|
||||
//Cost is 0 if the player owns this gate and funds go to the owner
|
||||
if (source.getGate().getToOwner() && source.isOwner(player)) {
|
||||
return 0;
|
||||
}
|
||||
//Player gets free gate use
|
||||
if (PermissionHelper.hasPermission(player, "stargate.free.use")) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return source.getGate().getUseCost();
|
||||
return isEconomyEnabled() && economy != null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -329,21 +225,6 @@ public final class EconomyConfig {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all config values related to economy
|
||||
*
|
||||
* @param configOptions <p>The loaded config options to get values from</p>
|
||||
*/
|
||||
private void loadEconomyConfig(Map<ConfigOption, Object> configOptions) {
|
||||
economyEnabled = (boolean) configOptions.get(ConfigOption.USE_ECONOMY);
|
||||
setDefaultCreateCost((Integer) configOptions.get(ConfigOption.CREATE_COST));
|
||||
setDefaultDestroyCost((Integer) configOptions.get(ConfigOption.DESTROY_COST));
|
||||
setDefaultUseCost((Integer) configOptions.get(ConfigOption.USE_COST));
|
||||
toOwner = (boolean) configOptions.get(ConfigOption.TO_OWNER);
|
||||
chargeFreeDestination = (boolean) configOptions.get(ConfigOption.CHARGE_FREE_DESTINATION);
|
||||
freeGatesGreen = (boolean) configOptions.get(ConfigOption.FREE_GATES_GREEN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a player can do a gate action for free
|
||||
*
|
||||
@ -355,41 +236,4 @@ public final class EconomyConfig {
|
||||
return !useEconomy() || PermissionHelper.hasPermission(player, "stargate.free." + permissionNode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Charges a player
|
||||
*
|
||||
* @param player <p>The player to charge</p>
|
||||
* @param amount <p>The amount to charge</p>
|
||||
* @return <p>True if the payment succeeded, or if no payment was necessary</p>
|
||||
*/
|
||||
private boolean chargePlayer(Player player, double amount) {
|
||||
if (economyEnabled && economy != null) {
|
||||
if (!economy.has(player, amount)) {
|
||||
return false;
|
||||
}
|
||||
economy.withdrawPlayer(player, amount);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Charges a player, giving the charge to a target
|
||||
*
|
||||
* @param player <p>The player to charge</p>
|
||||
* @param target <p>The UUID of the player to pay</p>
|
||||
* @param amount <p>The amount to charge</p>
|
||||
* @return <p>True if the payment succeeded, or if no payment was necessary</p>
|
||||
*/
|
||||
private boolean chargePlayer(Player player, UUID target, double amount) {
|
||||
if (economyEnabled && player.getUniqueId().compareTo(target) != 0 && economy != null) {
|
||||
if (!economy.has(player, amount)) {
|
||||
return false;
|
||||
}
|
||||
//Take money from the user and give to the owner
|
||||
economy.withdrawPlayer(player, amount);
|
||||
economy.depositPlayer(Bukkit.getOfflinePlayer(target), amount);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -46,8 +46,6 @@ public final class StargateConfig {
|
||||
private String portalFolder;
|
||||
private String languageName = "en";
|
||||
|
||||
private boolean debuggingEnabled = false;
|
||||
private boolean permissionDebuggingEnabled = false;
|
||||
private final Map<ConfigOption, Object> configOptions;
|
||||
|
||||
/**
|
||||
@ -65,6 +63,18 @@ public final class StargateConfig {
|
||||
languageLoader = new LanguageLoader(dataFolderPath + "/lang/");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a direct reference to the config option map
|
||||
*
|
||||
* <p>This reference can be used to alter the value of config options. Values should only be altered after it's
|
||||
* been verified that the value is valid.</p>
|
||||
*
|
||||
* @return <p>A reference to the config options map</p>
|
||||
*/
|
||||
public Map<ConfigOption, Object> getConfigOptionsReference() {
|
||||
return configOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finish the config setup by loading languages, gates and portals, and loading economy if vault is loaded
|
||||
*/
|
||||
@ -81,7 +91,7 @@ public final class StargateConfig {
|
||||
languageLoader.reload();
|
||||
|
||||
messageSender = new MessageSender(languageLoader);
|
||||
if (debuggingEnabled) {
|
||||
if (isDebuggingEnabled()) {
|
||||
languageLoader.debug();
|
||||
}
|
||||
|
||||
@ -130,7 +140,7 @@ public final class StargateConfig {
|
||||
* @return <p>Whether debugging is enabled</p>
|
||||
*/
|
||||
public boolean isDebuggingEnabled() {
|
||||
return debuggingEnabled;
|
||||
return (boolean) configOptions.get(ConfigOption.DEBUG);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -139,7 +149,7 @@ public final class StargateConfig {
|
||||
* @return <p>Whether permission debugging is enabled</p>
|
||||
*/
|
||||
public boolean isPermissionDebuggingEnabled() {
|
||||
return permissionDebuggingEnabled;
|
||||
return (boolean) configOptions.get(ConfigOption.PERMISSION_DEBUG);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -186,6 +196,17 @@ public final class StargateConfig {
|
||||
* Un-loads all loaded data
|
||||
*/
|
||||
private void unload() {
|
||||
//De-activate, close and unload all loaded portals
|
||||
unloadAllPortals();
|
||||
|
||||
//Clear all loaded gates
|
||||
GateHandler.clearGates();
|
||||
}
|
||||
|
||||
/**
|
||||
* Un-loads all loaded portals
|
||||
*/
|
||||
public void unloadAllPortals() {
|
||||
//De-activate all currently active portals
|
||||
for (Portal activePortal : activePortalsQueue) {
|
||||
activePortal.getPortalActivator().deactivate();
|
||||
@ -201,9 +222,6 @@ public final class StargateConfig {
|
||||
|
||||
//Clear all loaded portals
|
||||
PortalRegistry.clearPortals();
|
||||
|
||||
//Clear all loaded gates
|
||||
GateHandler.clearGates();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -256,7 +274,7 @@ public final class StargateConfig {
|
||||
//Update the language loader in case the loaded language changed
|
||||
languageLoader.setChosenLanguage(languageName);
|
||||
languageLoader.reload();
|
||||
if (debuggingEnabled) {
|
||||
if (isDebuggingEnabled()) {
|
||||
languageLoader.debug();
|
||||
}
|
||||
|
||||
@ -267,7 +285,7 @@ public final class StargateConfig {
|
||||
/**
|
||||
* Starts the listener for listening to BungeeCord messages
|
||||
*/
|
||||
private void startStopBungeeListener(boolean start) {
|
||||
public void startStopBungeeListener(boolean start) {
|
||||
Messenger messenger = Bukkit.getMessenger();
|
||||
String bungeeChannel = "BungeeCord";
|
||||
|
||||
@ -283,7 +301,7 @@ public final class StargateConfig {
|
||||
/**
|
||||
* Reloads economy by enabling or disabling it as necessary
|
||||
*/
|
||||
private void reloadEconomy() {
|
||||
public void reloadEconomy() {
|
||||
EconomyConfig economyConfig = getEconomyConfig();
|
||||
if (economyConfig.isEconomyEnabled() && economyConfig.getEconomy() == null) {
|
||||
setupVaultEconomy();
|
||||
@ -309,9 +327,7 @@ public final class StargateConfig {
|
||||
FileConfiguration newConfig = Stargate.getInstance().getConfig();
|
||||
|
||||
boolean isMigrating = false;
|
||||
if (newConfig.getString("lang") != null ||
|
||||
newConfig.getString("gates.integrity.ignoreEntrance") != null ||
|
||||
newConfig.getString("ignoreEntrance") != null) {
|
||||
if (newConfig.getString("lang") != null || newConfig.getString("economy.freeGatesGreen") != null) {
|
||||
migrateConfig(newConfig);
|
||||
isMigrating = true;
|
||||
}
|
||||
@ -344,10 +360,6 @@ public final class StargateConfig {
|
||||
portalFolder = (String) configOptions.get(ConfigOption.PORTAL_FOLDER);
|
||||
gateFolder = (String) configOptions.get(ConfigOption.GATE_FOLDER);
|
||||
|
||||
//Get enabled debug settings from the config
|
||||
debuggingEnabled = (boolean) configOptions.get(ConfigOption.DEBUG);
|
||||
permissionDebuggingEnabled = (boolean) configOptions.get(ConfigOption.PERMISSION_DEBUG);
|
||||
|
||||
//If users have an outdated config, assume they also need to update their default gates
|
||||
if (isMigrating) {
|
||||
GateHandler.writeDefaultGatesToFolder(gateFolder);
|
||||
|
@ -188,15 +188,13 @@ public final class StargateGateConfig {
|
||||
* @param mainSignColor <p>A string representing the main sign color</p>
|
||||
*/
|
||||
private void loadSignColor(String mainSignColor, String highlightSignColor) {
|
||||
if (mainSignColor != null) {
|
||||
try {
|
||||
PortalSignDrawer.setColors(ChatColor.valueOf(mainSignColor.toUpperCase()),
|
||||
ChatColor.valueOf(highlightSignColor.toUpperCase()));
|
||||
return;
|
||||
} catch (IllegalArgumentException | NullPointerException ignored) {
|
||||
}
|
||||
try {
|
||||
PortalSignDrawer.setMainColor(ChatColor.valueOf(mainSignColor.toUpperCase()));
|
||||
PortalSignDrawer.setHighlightColor(ChatColor.valueOf(highlightSignColor.toUpperCase()));
|
||||
} catch (IllegalArgumentException | NullPointerException exception) {
|
||||
Stargate.logWarning("You have specified an invalid color in your config.yml. Defaulting to BLACK and WHITE");
|
||||
PortalSignDrawer.setMainColor(ChatColor.BLACK);
|
||||
PortalSignDrawer.setHighlightColor(ChatColor.WHITE);
|
||||
}
|
||||
Stargate.logWarning("You have specified an invalid color in your config.yml. Defaulting to BLACK and WHITE");
|
||||
PortalSignDrawer.setColors(ChatColor.BLACK, ChatColor.WHITE);
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import org.bukkit.event.block.BlockPhysicsEvent;
|
||||
import org.bukkit.event.block.BlockPistonEvent;
|
||||
import org.bukkit.event.block.BlockPistonExtendEvent;
|
||||
import org.bukkit.event.block.BlockPistonRetractEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.block.EntityBlockFormEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
|
||||
@ -96,6 +97,22 @@ public class BlockEventListener implements Listener {
|
||||
portal::drawSign, 1);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (event.isCancelled() || !Stargate.getGateConfig().protectEntrance()) {
|
||||
return;
|
||||
}
|
||||
Block block = event.getBlock();
|
||||
Player player = event.getPlayer();
|
||||
|
||||
Portal portal = PortalHandler.getByEntrance(block);
|
||||
if (portal != null) {
|
||||
//Prevent blocks from being placed in the entrance, if protectEntrance is enabled, as breaking the block
|
||||
// would destroy the portal
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects block breaking to detect if the user is destroying a gate
|
||||
*
|
||||
@ -140,7 +157,9 @@ public class BlockEventListener implements Listener {
|
||||
|
||||
//Destroy denied
|
||||
if (destroyEvent.getDeny()) {
|
||||
Stargate.getMessageSender().sendErrorMessage(player, destroyEvent.getDenyReason());
|
||||
if (!destroyEvent.getDenyReason().trim().isEmpty()) {
|
||||
Stargate.getMessageSender().sendErrorMessage(player, destroyEvent.getDenyReason());
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -169,7 +188,7 @@ public class BlockEventListener implements Listener {
|
||||
if (cost != 0) {
|
||||
String portalName = portal.getName();
|
||||
//Cannot pay
|
||||
if (!Stargate.getEconomyConfig().chargePlayerIfNecessary(player, cost)) {
|
||||
if (!EconomyHelper.chargePlayerIfNecessary(player, cost)) {
|
||||
Stargate.debug("onBlockBreak", "Insufficient Funds");
|
||||
EconomyHelper.sendInsufficientFundsMessage(portalName, player, cost);
|
||||
event.setCancelled(true);
|
||||
|
@ -7,6 +7,7 @@ import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalActivator;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.teleporter.PlayerTeleporter;
|
||||
import net.knarcraft.stargate.portal.teleporter.Teleporter;
|
||||
import net.knarcraft.stargate.portal.teleporter.VehicleTeleporter;
|
||||
import net.knarcraft.stargate.utility.BungeeHelper;
|
||||
import net.knarcraft.stargate.utility.MaterialHelper;
|
||||
@ -170,7 +171,9 @@ public class PlayerEventListener implements Listener {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
//Make sure to check if the player has any leashed creatures, even though leashed teleportation is disabled
|
||||
return Teleporter.noLeashedCreaturesPreventTeleportation(player);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -244,7 +247,7 @@ public class PlayerEventListener implements Listener {
|
||||
* @return <p>True if the player should be denied</p>
|
||||
*/
|
||||
private boolean cannotAccessPortal(Player player, Portal portal) {
|
||||
boolean deny = PermissionHelper.cannotAccessNetwork(player, portal.getNetwork());
|
||||
boolean deny = PermissionHelper.cannotAccessNetwork(player, portal.getCleanNetwork());
|
||||
|
||||
if (PermissionHelper.portalAccessDenied(player, portal, deny)) {
|
||||
if (!portal.getOptions().isSilent()) {
|
||||
@ -317,7 +320,7 @@ public class PlayerEventListener implements Listener {
|
||||
}
|
||||
|
||||
//Display portal information as a portal without a sign does not display any
|
||||
if (portal.getOptions().hasNoSign() && !portal.getOptions().isSilent()) {
|
||||
if (portal.getOptions().hasNoSign() && (!portal.getOptions().isSilent() || player.isSneaking())) {
|
||||
MessageSender sender = Stargate.getMessageSender();
|
||||
sender.sendSuccessMessage(player, ChatColor.GOLD + Stargate.getString("portalInfoTitle"));
|
||||
sender.sendSuccessMessage(player, Stargate.replaceVars(Stargate.getString("portalInfoName"),
|
||||
|
@ -3,6 +3,7 @@ package net.knarcraft.stargate.listener;
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.teleporter.Teleporter;
|
||||
import net.knarcraft.stargate.portal.teleporter.VehicleTeleporter;
|
||||
import net.knarcraft.stargate.utility.EconomyHelper;
|
||||
import net.knarcraft.stargate.utility.EntityHelper;
|
||||
@ -110,7 +111,7 @@ public class VehicleEventListener implements Listener {
|
||||
|
||||
//To prevent the case where the first passenger pays and then the second passenger is denied, this has to be
|
||||
// run after it has been confirmed that all passengers are able to pay
|
||||
int cost = Stargate.getEconomyConfig().getUseCost(player, entrancePortal, destinationPortal);
|
||||
int cost = EconomyHelper.getUseCost(player, entrancePortal, destinationPortal);
|
||||
if (cost > 0) {
|
||||
if (!takePlayerPayment(passengers, entrancePortal, cost)) {
|
||||
return;
|
||||
@ -164,12 +165,16 @@ public class VehicleEventListener implements Listener {
|
||||
}
|
||||
|
||||
//Check if the player is able to afford the teleport fee
|
||||
int cost = Stargate.getEconomyConfig().getUseCost(player, entrancePortal, destinationPortal);
|
||||
int cost = EconomyHelper.getUseCost(player, entrancePortal, destinationPortal);
|
||||
boolean canAffordFee = cost <= 0 || Stargate.getEconomyConfig().canAffordFee(player, cost);
|
||||
if (!canAffordFee && !entrancePortal.getOptions().isSilent()) {
|
||||
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("ecoInFunds"));
|
||||
if (!canAffordFee) {
|
||||
if (!entrancePortal.getOptions().isSilent()) {
|
||||
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("ecoInFunds"));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return canAffordFee;
|
||||
|
||||
return Teleporter.noLeashedCreaturesPreventTeleportation(player);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import net.knarcraft.stargate.portal.property.PortalOptions;
|
||||
import net.knarcraft.stargate.portal.property.PortalOwner;
|
||||
import net.knarcraft.stargate.portal.property.PortalStructure;
|
||||
import net.knarcraft.stargate.portal.property.gate.Gate;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -19,7 +20,10 @@ import java.util.Map;
|
||||
public class Portal {
|
||||
|
||||
private final String name;
|
||||
private final String cleanName;
|
||||
private final String network;
|
||||
private final String cleanNetwork;
|
||||
|
||||
private final PortalOwner portalOwner;
|
||||
private boolean isRegistered;
|
||||
|
||||
@ -53,6 +57,8 @@ public class Portal {
|
||||
this.portalOpener = new PortalOpener(this, destination);
|
||||
this.structure = new PortalStructure(this, gate, button);
|
||||
this.portalActivator = portalOpener.getPortalActivator();
|
||||
this.cleanName = cleanString(name);
|
||||
this.cleanNetwork = cleanString(network);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -149,6 +155,15 @@ public class Portal {
|
||||
return network;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the clean name of the network this portal belongs to
|
||||
*
|
||||
* @return <p>The clean network name</p>
|
||||
*/
|
||||
public String getCleanNetwork() {
|
||||
return cleanNetwork;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the time this portal was triggered (activated/opened)
|
||||
*
|
||||
@ -170,6 +185,15 @@ public class Portal {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the clean name of this portal
|
||||
*
|
||||
* @return <p>The clean name of this portal</p>
|
||||
*/
|
||||
public String getCleanName() {
|
||||
return cleanName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the portal opener used by this portal
|
||||
*
|
||||
@ -273,6 +297,16 @@ public class Portal {
|
||||
return getTopLeft().getRelativeLocation(vector, getYaw());
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans a string by removing color codes, lower-casing and replacing spaces with underscores
|
||||
*
|
||||
* @param string <p>The string to clean</p>
|
||||
* @return <p>The clean string</p>
|
||||
*/
|
||||
public static String cleanString(String string) {
|
||||
return ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', string)).toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Portal [id=%s, network=%s name=%s, type=%s]", getSignLocation(), network, name,
|
||||
@ -283,8 +317,8 @@ public class Portal {
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((network == null) ? 0 : network.hashCode());
|
||||
result = prime * result + ((cleanName == null) ? 0 : cleanName.hashCode());
|
||||
result = prime * result + ((cleanNetwork == null) ? 0 : cleanNetwork.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -297,18 +331,18 @@ public class Portal {
|
||||
return false;
|
||||
}
|
||||
Portal other = (Portal) object;
|
||||
if (name == null) {
|
||||
if (other.name != null) {
|
||||
if (cleanName == null) {
|
||||
if (other.cleanName != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!name.equalsIgnoreCase(other.name)) {
|
||||
} else if (!cleanName.equalsIgnoreCase(other.cleanName)) {
|
||||
return false;
|
||||
}
|
||||
//If none of the portals have a name, check if the network is the same
|
||||
if (network == null) {
|
||||
return other.network == null;
|
||||
if (cleanNetwork == null) {
|
||||
return other.cleanNetwork == null;
|
||||
} else {
|
||||
return network.equalsIgnoreCase(other.network);
|
||||
return cleanNetwork.equalsIgnoreCase(other.cleanNetwork);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import net.knarcraft.stargate.event.StargateDeactivateEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
@ -64,7 +64,7 @@ public class PortalActivator {
|
||||
* @return <p>The destination portal the player should teleport to</p>
|
||||
*/
|
||||
public Portal getDestination(Player player) {
|
||||
String portalNetwork = portal.getNetwork();
|
||||
String portalNetwork = portal.getCleanNetwork();
|
||||
if (portal.getOptions().isRandom()) {
|
||||
//Find possible destinations
|
||||
List<String> destinations = PortalHandler.getDestinations(portal, player, portalNetwork);
|
||||
@ -73,10 +73,10 @@ public class PortalActivator {
|
||||
}
|
||||
//Get one random destination
|
||||
String destination = destinations.get((new Random()).nextInt(destinations.size()));
|
||||
return PortalHandler.getByName(destination, portalNetwork);
|
||||
return PortalHandler.getByName(Portal.cleanString(destination), portalNetwork);
|
||||
} else {
|
||||
//Just return the normal fixed destination
|
||||
return PortalHandler.getByName(destination, portalNetwork);
|
||||
return PortalHandler.getByName(Portal.cleanString(destination), portalNetwork);
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,12 +136,12 @@ public class PortalActivator {
|
||||
//Set the given player as the active player
|
||||
activePlayer = player;
|
||||
|
||||
String network = portal.getNetwork();
|
||||
String network = portal.getCleanNetwork();
|
||||
destinations = PortalHandler.getDestinations(portal, player, network);
|
||||
|
||||
//Sort destinations if enabled
|
||||
if (Stargate.getGateConfig().sortNetworkDestinations()) {
|
||||
Collections.sort(destinations);
|
||||
destinations.sort(Comparator.comparing(Portal::cleanString));
|
||||
}
|
||||
|
||||
//Select last used destination if remember destination is enabled
|
||||
@ -242,7 +242,7 @@ public class PortalActivator {
|
||||
activate = true;
|
||||
|
||||
Stargate.debug("cycleDestination", "Network Size: " +
|
||||
PortalHandler.getNetwork(portal.getNetwork()).size());
|
||||
PortalHandler.getNetwork(portal.getCleanNetwork()).size());
|
||||
Stargate.debug("cycleDestination", "Player has access to: " + destinations.size());
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,8 @@ import org.bukkit.event.block.SignChangeEvent;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static net.knarcraft.stargate.Stargate.getMaxNameNetworkLength;
|
||||
|
||||
/**
|
||||
* The portal creator can create and validate a new portal
|
||||
*/
|
||||
@ -105,7 +107,8 @@ public class PortalCreator {
|
||||
Stargate.debug("createPortal", builder.toString());
|
||||
|
||||
//Use default network if a proper alternative is not set
|
||||
if (!portalOptions.get(PortalOption.BUNGEE) && (network.length() < 1 || network.length() > 11)) {
|
||||
if (!portalOptions.get(PortalOption.BUNGEE) && (network.length() < 1 || network.length() >
|
||||
getMaxNameNetworkLength())) {
|
||||
network = Stargate.getDefaultNetwork();
|
||||
}
|
||||
|
||||
@ -117,8 +120,8 @@ public class PortalCreator {
|
||||
Stargate.debug("createPortal", "Player doesn't have create permissions on network. Trying personal");
|
||||
if (PermissionHelper.canCreatePersonalPortal(player)) {
|
||||
network = player.getName();
|
||||
if (network.length() > 11) {
|
||||
network = network.substring(0, 11);
|
||||
if (network.length() > getMaxNameNetworkLength()) {
|
||||
network = network.substring(0, getMaxNameNetworkLength());
|
||||
}
|
||||
Stargate.debug("createPortal", "Creating personal portal");
|
||||
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("createPersonal"));
|
||||
@ -189,7 +192,9 @@ public class PortalCreator {
|
||||
|
||||
//Tell the user why it was denied from creating the portal
|
||||
if (stargateCreateEvent.getDeny()) {
|
||||
Stargate.getMessageSender().sendErrorMessage(player, stargateCreateEvent.getDenyReason());
|
||||
if (!stargateCreateEvent.getDenyReason().trim().isEmpty()) {
|
||||
Stargate.getMessageSender().sendErrorMessage(player, stargateCreateEvent.getDenyReason());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -228,29 +233,30 @@ public class PortalCreator {
|
||||
*/
|
||||
private boolean checkIfNewPortalIsValid(int cost, String portalName) {
|
||||
//Check if the portal name can fit on the sign with padding (>name<)
|
||||
if (portal.getName().length() < 1 || portal.getName().length() > 11) {
|
||||
Stargate.debug("createPortal", "Name length error");
|
||||
if (portal.getCleanName().length() < 1 || portal.getCleanName().length() > getMaxNameNetworkLength()) {
|
||||
Stargate.debug("createPortal", String.format("Name length error. %s is too long.",
|
||||
portal.getCleanName()));
|
||||
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("createNameLength"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (portal.getOptions().isBungee()) {
|
||||
//Check if the bungee portal's name has been duplicated
|
||||
if (PortalHandler.getBungeePortals().get(portal.getName().toLowerCase()) != null) {
|
||||
if (PortalHandler.getBungeePortals().get(portal.getCleanName()) != null) {
|
||||
Stargate.debug("createPortal::Bungee", "Gate name duplicate");
|
||||
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("createExists"));
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
//Check if the portal name has been duplicated on the network
|
||||
if (PortalHandler.getByName(portal.getName(), portal.getNetwork()) != null) {
|
||||
if (PortalHandler.getByName(portal.getCleanName(), portal.getCleanNetwork()) != null) {
|
||||
Stargate.debug("createPortal", "Gate name duplicate");
|
||||
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("createExists"));
|
||||
return false;
|
||||
}
|
||||
|
||||
//Check if the number of portals in the network has been surpassed
|
||||
List<String> networkList = PortalHandler.getAllPortalNetworks().get(portal.getNetwork().toLowerCase());
|
||||
List<String> networkList = PortalHandler.getAllPortalNetworks().get(portal.getCleanNetwork());
|
||||
int maxGates = Stargate.getGateConfig().maxGatesEachNetwork();
|
||||
if (maxGates > 0 && networkList != null && networkList.size() >= maxGates) {
|
||||
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("createFull"));
|
||||
@ -260,7 +266,7 @@ public class PortalCreator {
|
||||
|
||||
if (cost > 0) {
|
||||
//Deduct the required fee from the player
|
||||
if (!Stargate.getEconomyConfig().chargePlayerIfNecessary(player, cost)) {
|
||||
if (!EconomyHelper.chargePlayerIfNecessary(player, cost)) {
|
||||
EconomyHelper.sendInsufficientFundsMessage(portalName, player, cost);
|
||||
Stargate.debug("createPortal", "Insufficient Funds");
|
||||
return false;
|
||||
@ -283,7 +289,7 @@ public class PortalCreator {
|
||||
portal.getPortalOpener().openPortal(true);
|
||||
} else if (portal.getOptions().isAlwaysOn()) {
|
||||
//For a normal always-on portal, open both the portal and the destination
|
||||
Portal destinationPortal = PortalHandler.getByName(destinationName, portal.getNetwork());
|
||||
Portal destinationPortal = PortalHandler.getByName(destinationName, portal.getCleanNetwork());
|
||||
if (destinationPortal != null) {
|
||||
portal.getPortalOpener().openPortal(true);
|
||||
destinationPortal.drawSign();
|
||||
|
@ -66,7 +66,7 @@ public class PortalHandler {
|
||||
*/
|
||||
public static List<String> getDestinations(Portal entrancePortal, Player player, String network) {
|
||||
List<String> destinations = new ArrayList<>();
|
||||
for (String destination : PortalRegistry.getAllPortalNetworks().get(network.toLowerCase())) {
|
||||
for (String destination : PortalRegistry.getAllPortalNetworks().get(network)) {
|
||||
Portal portal = getByName(destination, network);
|
||||
if (portal == null) {
|
||||
continue;
|
||||
@ -80,11 +80,12 @@ public class PortalHandler {
|
||||
continue;
|
||||
}
|
||||
//Check if destination is this portal
|
||||
if (destination.equalsIgnoreCase(entrancePortal.getName())) {
|
||||
if (destination.equals(entrancePortal.getCleanName())) {
|
||||
continue;
|
||||
}
|
||||
//Check if destination is a fixed portal not pointing to this portal
|
||||
if (portal.getOptions().isFixed() && !portal.getDestinationName().equalsIgnoreCase(entrancePortal.getName())) {
|
||||
if (portal.getOptions().isFixed() &&
|
||||
!Portal.cleanString(portal.getDestinationName()).equals(entrancePortal.getCleanName())) {
|
||||
continue;
|
||||
}
|
||||
//Allow random use by non-players (Minecarts)
|
||||
@ -182,10 +183,10 @@ public class PortalHandler {
|
||||
* @param portal <p>The newly created portal</p>
|
||||
*/
|
||||
static void updatePortalsPointingAtNewPortal(Portal portal) {
|
||||
for (String originName : PortalRegistry.getAllPortalNetworks().get(portal.getNetwork().toLowerCase())) {
|
||||
Portal origin = getByName(originName, portal.getNetwork());
|
||||
for (String originName : PortalRegistry.getAllPortalNetworks().get(portal.getCleanNetwork())) {
|
||||
Portal origin = getByName(originName, portal.getCleanNetwork());
|
||||
if (origin == null ||
|
||||
!origin.getDestinationName().equalsIgnoreCase(portal.getName()) ||
|
||||
!Portal.cleanString(origin.getDestinationName()).equals(portal.getCleanName()) ||
|
||||
!origin.getStructure().isVerified()) {
|
||||
continue;
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ public class PortalOpener {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean thisIsDestination = destination.getDestinationName().equalsIgnoreCase(portal.getName());
|
||||
boolean thisIsDestination = Portal.cleanString(destination.getDestinationName()).equals(portal.getCleanName());
|
||||
//Only open destination if it's not-fixed or points at this portal, and is not already open
|
||||
if (!options.isRandom() && (!destination.getOptions().isFixed() || thisIsDestination) && !destination.isOpen()) {
|
||||
//Open the destination portal
|
||||
|
@ -63,7 +63,7 @@ public class PortalRegistry {
|
||||
private static void clearPortals(List<Portal> portalsToRemove) {
|
||||
//Store the names of the portals to remove as some maps require the name, not the object
|
||||
List<String> portalNames = new ArrayList<>();
|
||||
portalsToRemove.forEach((portal) -> portalNames.add(portal.getName()));
|
||||
portalsToRemove.forEach((portal) -> portalNames.add(portal.getCleanName()));
|
||||
|
||||
//Clear all the lookup locations for the portals
|
||||
lookupBlocks.keySet().removeIf((key) -> portalsToRemove.contains(lookupBlocks.get(key)));
|
||||
@ -165,8 +165,8 @@ public class PortalRegistry {
|
||||
portal.getPortalActivator().deactivate();
|
||||
portal.getPortalOpener().closePortal(true);
|
||||
|
||||
String portalName = portal.getName().toLowerCase();
|
||||
String networkName = portal.getNetwork().toLowerCase();
|
||||
String portalName = portal.getCleanName();
|
||||
String networkName = portal.getCleanNetwork();
|
||||
|
||||
//Remove portal from lookup blocks
|
||||
for (BlockLocation block : portal.getStructure().getFrame()) {
|
||||
@ -203,7 +203,7 @@ public class PortalRegistry {
|
||||
|
||||
//Update all portals in the same network with this portal as its destination
|
||||
for (String originName : allPortalNetworks.get(networkName)) {
|
||||
Portal origin = PortalHandler.getByName(originName, portal.getNetwork());
|
||||
Portal origin = PortalHandler.getByName(originName, portal.getCleanNetwork());
|
||||
if (origin == null || !origin.getDestinationName().equalsIgnoreCase(portalName) ||
|
||||
!origin.getStructure().isVerified()) {
|
||||
continue;
|
||||
@ -235,8 +235,8 @@ public class PortalRegistry {
|
||||
portal.getOptions().setFixed(portal.getDestinationName().length() > 0 || portal.getOptions().isRandom() ||
|
||||
portal.getOptions().isBungee());
|
||||
|
||||
String portalName = portal.getName().toLowerCase();
|
||||
String networkName = portal.getNetwork().toLowerCase();
|
||||
String portalName = portal.getCleanName();
|
||||
String networkName = portal.getCleanNetwork();
|
||||
|
||||
//Bungee portals are stored in their own list
|
||||
if (portal.getOptions().isBungee()) {
|
||||
|
@ -15,7 +15,7 @@ public class PortalSignDrawer {
|
||||
|
||||
private final Portal portal;
|
||||
private final static ChatColor errorColor = ChatColor.DARK_RED;
|
||||
private final static ChatColor freeColor = ChatColor.DARK_GREEN;
|
||||
private static ChatColor freeColor;
|
||||
private static ChatColor mainColor;
|
||||
private static ChatColor highlightColor;
|
||||
|
||||
@ -29,19 +29,36 @@ public class PortalSignDrawer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the main sign color
|
||||
* Sets the highlighting sign color
|
||||
*
|
||||
* <p>The main sign color is used for most text on the sign, while the highlighting color is used for the markings
|
||||
* around portal names and network names ('>','<','-',')','(')</p>
|
||||
* <p>The highlighting color is used for the markings around portal names and network names ('>','<','-',')','(').</p>
|
||||
*
|
||||
* @param newMainColor <p>The new main sign color</p>
|
||||
* @param newHighlightColor <p>The new highlight color</p>
|
||||
*/
|
||||
public static void setColors(ChatColor newMainColor, ChatColor newHighlightColor) {
|
||||
mainColor = newMainColor;
|
||||
public static void setHighlightColor(ChatColor newHighlightColor) {
|
||||
highlightColor = newHighlightColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the main sign color
|
||||
*
|
||||
* <p>The main sign color is used for most text on the sign.</p>
|
||||
*
|
||||
* @param newMainColor <p>The new main sign color</p>
|
||||
*/
|
||||
public static void setMainColor(ChatColor newMainColor) {
|
||||
mainColor = newMainColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color to use for marking free stargates
|
||||
*
|
||||
* @param freeColor <p>The new color to use for marking free stargates</p>
|
||||
*/
|
||||
public static void setFreeColor(ChatColor freeColor) {
|
||||
PortalSignDrawer.freeColor = freeColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the sign of the portal this sign drawer is responsible for
|
||||
*/
|
||||
@ -81,8 +98,7 @@ public class PortalSignDrawer {
|
||||
private void drawSign(Sign sign) {
|
||||
//Clear sign
|
||||
clearSign(sign);
|
||||
setLine(sign, 0, highlightColor + "-" + mainColor +
|
||||
portal.getName() + highlightColor + "-");
|
||||
setLine(sign, 0, highlightColor + "-" + mainColor + fixColor(portal.getName()) + highlightColor + "-");
|
||||
|
||||
if (!portal.getPortalActivator().isActive()) {
|
||||
//Default sign text
|
||||
@ -123,7 +139,7 @@ public class PortalSignDrawer {
|
||||
return;
|
||||
}
|
||||
clearSign(sign);
|
||||
sign.setLine(0, portal.getName());
|
||||
sign.setLine(0, fixColor(portal.getName()));
|
||||
sign.update();
|
||||
}
|
||||
|
||||
@ -137,46 +153,46 @@ public class PortalSignDrawer {
|
||||
int maxIndex = destinations.getDestinations().size() - 1;
|
||||
int signLineIndex = 0;
|
||||
int destinationIndex = destinations.getDestinations().indexOf(portal.getDestinationName());
|
||||
boolean freeGatesGreen = Stargate.getEconomyConfig().useEconomy() &&
|
||||
Stargate.getEconomyConfig().drawFreePortalsGreen();
|
||||
boolean freeGatesColored = Stargate.getEconomyConfig().useEconomy() &&
|
||||
Stargate.getEconomyConfig().drawFreePortalsColored();
|
||||
|
||||
//Last, and not only entry. Draw the entry two back
|
||||
if ((destinationIndex == maxIndex) && (maxIndex > 1)) {
|
||||
drawNetworkSignLine(freeGatesGreen, sign, ++signLineIndex, destinationIndex - 2);
|
||||
drawNetworkSignLine(freeGatesColored, sign, ++signLineIndex, destinationIndex - 2);
|
||||
}
|
||||
//Not first entry. Draw the previous entry
|
||||
if (destinationIndex > 0) {
|
||||
drawNetworkSignLine(freeGatesGreen, sign, ++signLineIndex, destinationIndex - 1);
|
||||
drawNetworkSignLine(freeGatesColored, sign, ++signLineIndex, destinationIndex - 1);
|
||||
}
|
||||
//Draw the chosen entry (line 2 or 3)
|
||||
drawNetworkSignChosenLine(freeGatesGreen, sign, ++signLineIndex);
|
||||
drawNetworkSignChosenLine(freeGatesColored, sign, ++signLineIndex);
|
||||
//Has another entry and space on the sign
|
||||
if ((maxIndex >= destinationIndex + 1)) {
|
||||
drawNetworkSignLine(freeGatesGreen, sign, ++signLineIndex, destinationIndex + 1);
|
||||
drawNetworkSignLine(freeGatesColored, sign, ++signLineIndex, destinationIndex + 1);
|
||||
}
|
||||
//Has another entry and space on the sign
|
||||
if ((maxIndex >= destinationIndex + 2) && (++signLineIndex <= 3)) {
|
||||
drawNetworkSignLine(freeGatesGreen, sign, signLineIndex, destinationIndex + 2);
|
||||
drawNetworkSignLine(freeGatesColored, sign, signLineIndex, destinationIndex + 2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the chosen destination on one sign line
|
||||
*
|
||||
* @param freeGatesGreen <p>Whether to display free gates in a green color</p>
|
||||
* @param sign <p>The sign to draw on</p>
|
||||
* @param signLineIndex <p>The line to draw on</p>
|
||||
* @param freeGatesColored <p>Whether to display free gates in a different color</p>
|
||||
* @param sign <p>The sign to draw on</p>
|
||||
* @param signLineIndex <p>The line to draw on</p>
|
||||
*/
|
||||
private void drawNetworkSignChosenLine(boolean freeGatesGreen, Sign sign, int signLineIndex) {
|
||||
if (freeGatesGreen) {
|
||||
private void drawNetworkSignChosenLine(boolean freeGatesColored, Sign sign, int signLineIndex) {
|
||||
if (freeGatesColored) {
|
||||
Portal destination = PortalHandler.getByName(portal.getDestinationName(), portal.getNetwork());
|
||||
boolean green = PermissionHelper.isFree(portal.getActivePlayer(), portal, destination);
|
||||
ChatColor nameColor = (green ? freeColor : highlightColor);
|
||||
setLine(sign, signLineIndex, nameColor + ">" + (green ? freeColor : mainColor) +
|
||||
portal.getDestinationName() + nameColor + "<");
|
||||
boolean free = PermissionHelper.isFree(portal.getActivePlayer(), portal, destination);
|
||||
ChatColor nameColor = (free ? freeColor : highlightColor);
|
||||
setLine(sign, signLineIndex, nameColor + ">" + (free ? freeColor : mainColor) +
|
||||
fixColor(portal.getDestinationName()) + nameColor + "<");
|
||||
} else {
|
||||
setLine(sign, signLineIndex, highlightColor + ">" + mainColor + portal.getDestinationName() +
|
||||
highlightColor + "<");
|
||||
setLine(sign, signLineIndex, highlightColor + ">" + mainColor +
|
||||
fixColor(portal.getDestinationName()) + highlightColor + "<");
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,20 +210,20 @@ public class PortalSignDrawer {
|
||||
/**
|
||||
* Draws one network destination on one sign line
|
||||
*
|
||||
* @param freeGatesGreen <p>Whether to display free gates in a green color</p>
|
||||
* @param freeGatesColored <p>Whether to display free gates in a different color</p>
|
||||
* @param sign <p>The sign to draw on</p>
|
||||
* @param signLineIndex <p>The line to draw on</p>
|
||||
* @param destinationIndex <p>The index of the destination to draw</p>
|
||||
*/
|
||||
private void drawNetworkSignLine(boolean freeGatesGreen, Sign sign, int signLineIndex, int destinationIndex) {
|
||||
private void drawNetworkSignLine(boolean freeGatesColored, Sign sign, int signLineIndex, int destinationIndex) {
|
||||
PortalActivator destinations = portal.getPortalActivator();
|
||||
String destinationName = destinations.getDestinations().get(destinationIndex);
|
||||
if (freeGatesGreen) {
|
||||
if (freeGatesColored) {
|
||||
Portal destination = PortalHandler.getByName(destinationName, portal.getNetwork());
|
||||
boolean green = PermissionHelper.isFree(portal.getActivePlayer(), portal, destination);
|
||||
setLine(sign, signLineIndex, (green ? freeColor : mainColor) + destinationName);
|
||||
boolean free = PermissionHelper.isFree(portal.getActivePlayer(), portal, destination);
|
||||
setLine(sign, signLineIndex, (free ? freeColor : mainColor) + fixColor(destinationName));
|
||||
} else {
|
||||
setLine(sign, signLineIndex, mainColor + destinationName);
|
||||
setLine(sign, signLineIndex, mainColor + fixColor(destinationName));
|
||||
}
|
||||
}
|
||||
|
||||
@ -218,8 +234,10 @@ public class PortalSignDrawer {
|
||||
*/
|
||||
private void drawBungeeSign(Sign sign) {
|
||||
setLine(sign, 1, Stargate.getString("bungeeSign"));
|
||||
setLine(sign, 2, highlightColor + ">" + mainColor + portal.getDestinationName() + highlightColor + "<");
|
||||
setLine(sign, 3, highlightColor + "[" + mainColor + portal.getNetwork() + highlightColor + "]");
|
||||
setLine(sign, 2, highlightColor + ">" + mainColor + fixColor(portal.getDestinationName()) +
|
||||
highlightColor + "<");
|
||||
setLine(sign, 3, highlightColor + "[" + mainColor + fixColor(portal.getNetwork()) +
|
||||
highlightColor + "]");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -233,7 +251,8 @@ public class PortalSignDrawer {
|
||||
setLine(sign, 1, Stargate.getString("signRightClick"));
|
||||
setLine(sign, 2, Stargate.getString("signToUse"));
|
||||
if (!portal.getOptions().isNoNetwork()) {
|
||||
setLine(sign, 3, highlightColor + "(" + mainColor + portal.getNetwork() + highlightColor + ")");
|
||||
setLine(sign, 3, highlightColor + "(" + mainColor + fixColor(portal.getNetwork()) +
|
||||
highlightColor + ")");
|
||||
} else {
|
||||
setLine(sign, 3, "");
|
||||
}
|
||||
@ -245,16 +264,20 @@ public class PortalSignDrawer {
|
||||
* @param sign <p>The sign to re-draw</p>
|
||||
*/
|
||||
private void drawFixedSign(Sign sign) {
|
||||
Portal destinationPortal = PortalHandler.getByName(Portal.cleanString(portal.getDestinationName()),
|
||||
portal.getCleanNetwork());
|
||||
String destinationName = portal.getOptions().isRandom() ? Stargate.getString("signRandom") :
|
||||
portal.getDestinationName();
|
||||
setLine(sign, 1, highlightColor + ">" + mainColor + destinationName + highlightColor + "<");
|
||||
(destinationPortal != null ? destinationPortal.getName() : portal.getDestinationName());
|
||||
setLine(sign, 1, highlightColor + ">" + mainColor + fixColor(destinationName) + highlightColor + "<");
|
||||
|
||||
if (portal.getOptions().isNoNetwork()) {
|
||||
setLine(sign, 2, "");
|
||||
} else {
|
||||
setLine(sign, 2, highlightColor + "(" + mainColor + portal.getNetwork() + highlightColor + ")");
|
||||
setLine(sign, 2, highlightColor + "(" + mainColor + fixColor(portal.getNetwork()) +
|
||||
highlightColor + ")");
|
||||
}
|
||||
Portal destination = PortalHandler.getByName(portal.getDestinationName(), portal.getNetwork());
|
||||
Portal destination = PortalHandler.getByName(Portal.cleanString(portal.getDestinationName()),
|
||||
portal.getNetwork());
|
||||
if (destination == null && !portal.getOptions().isRandom()) {
|
||||
setLine(sign, 3, errorColor + Stargate.getString("signDisconnected"));
|
||||
} else {
|
||||
@ -270,11 +293,24 @@ public class PortalSignDrawer {
|
||||
* @param lineIndex <p>The index of the line the invalid portal was found at</p>
|
||||
*/
|
||||
public static void markPortalWithInvalidGate(PortalLocation portalLocation, String gateName, int lineIndex) {
|
||||
Sign sign = (Sign) portalLocation.getSignLocation().getBlock().getState();
|
||||
BlockState blockState = portalLocation.getSignLocation().getBlock().getState();
|
||||
if (!(blockState instanceof Sign sign)) {
|
||||
return;
|
||||
}
|
||||
sign.setLine(3, errorColor + Stargate.getString("signInvalidGate"));
|
||||
sign.update();
|
||||
|
||||
Stargate.logInfo(String.format("Gate layout on line %d does not exist [%s]", lineIndex, gateName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes coloring of signs as the & character isn't translated on all servers
|
||||
*
|
||||
* @param text <p>The text to fix the coloring of</p>
|
||||
* @return <p>The text with the coloring fixed</p>
|
||||
*/
|
||||
private String fixColor(String text) {
|
||||
return ChatColor.translateAlternateColorCodes('&', text);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -69,6 +69,15 @@ public class Gate {
|
||||
return layout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a copy of the character to material mapping for this gate
|
||||
*
|
||||
* @return <p>The character to material map</p>
|
||||
*/
|
||||
public Map<Character, Material> getCharacterMaterialMap() {
|
||||
return new HashMap<>(characterMaterialMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the material type used for this gate's control blocks
|
||||
*
|
||||
|
@ -188,16 +188,35 @@ public class GateHandler {
|
||||
* @return <p>True if the gate is valid. False otherwise</p>
|
||||
*/
|
||||
private static boolean validateGate(Gate gate, String fileName) {
|
||||
String failString = String.format("Could not load Gate %s", fileName) + " - %s";
|
||||
|
||||
if (gate.getLayout().getControls().length != 2) {
|
||||
Stargate.logSevere(String.format("Could not load Gate %s - Gates must have exactly 2 control points.",
|
||||
fileName));
|
||||
Stargate.logSevere(String.format(failString, "Gates must have exactly 2 control points."));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!MaterialHelper.isButtonCompatible(gate.getPortalButton())) {
|
||||
Stargate.logSevere(String.format("Could not load Gate %s - Gate button must be a type of button.", fileName));
|
||||
Stargate.logSevere(String.format(failString, "Gate button must be a type of button."));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!gate.getPortalOpenBlock().isBlock()) {
|
||||
Stargate.logSevere(String.format(failString, "Gate open block must be a type of block."));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!gate.getPortalClosedBlock().isBlock()) {
|
||||
Stargate.logSevere(String.format(failString, "Gate closed block must be a type of block."));
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Material material : gate.getCharacterMaterialMap().values()) {
|
||||
if (!material.isBlock()) {
|
||||
Stargate.logSevere(String.format(failString, "Every gate border block must be a type of block."));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -191,9 +191,9 @@ public abstract class Teleporter {
|
||||
*/
|
||||
private Location adjustExitLocation(Location traveller, Location exitLocation) {
|
||||
if (exitLocation != null) {
|
||||
BlockData blockData = portal.getWorld().getBlockAt(exitLocation).getBlockData();
|
||||
if ((blockData instanceof Bisected && ((Bisected) blockData).getHalf() == Bisected.Half.BOTTOM) ||
|
||||
(blockData instanceof Slab) && ((Slab) blockData).getType() == Slab.Type.BOTTOM) {
|
||||
BlockData blockData = exitLocation.getBlock().getBlockData();
|
||||
if ((blockData instanceof Bisected bisected && bisected.getHalf() == Bisected.Half.BOTTOM) ||
|
||||
(blockData instanceof Slab slab && slab.getType() == Slab.Type.BOTTOM)) {
|
||||
//Prevent traveller from spawning inside a slab
|
||||
Stargate.debug("adjustExitLocation", "Added a block to get above a slab");
|
||||
exitLocation.add(0, 1, 0);
|
||||
@ -250,9 +250,37 @@ public abstract class Teleporter {
|
||||
return chunksToLoad;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a player has leashed creatures that block the teleportation
|
||||
*
|
||||
* @param player <p>The player trying to teleport</p>
|
||||
* @return <p>False if the player has leashed any creatures that cannot go through the portal</p>
|
||||
*/
|
||||
public static boolean noLeashedCreaturesPreventTeleportation(Player player) {
|
||||
//Find any nearby leashed entities to teleport with the player
|
||||
List<Creature> nearbyCreatures = getLeashedCreatures(player);
|
||||
|
||||
//Disallow creatures with passengers to prevent smuggling
|
||||
for (Creature creature : nearbyCreatures) {
|
||||
if (!creature.getPassengers().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//If it's enabled, there is no problem
|
||||
if (Stargate.getGateConfig().handleLeashedCreatures()) {
|
||||
return true;
|
||||
} else {
|
||||
return nearbyCreatures.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleports any creatures leashed by the player
|
||||
*
|
||||
* <p>Will return false if the teleportation should be aborted because the player has leashed creatures that
|
||||
* aren't allowed to be teleported with the player.</p>
|
||||
*
|
||||
* @param player <p>The player which is teleported</p>
|
||||
* @param origin <p>The portal the player is teleporting from</p>
|
||||
*/
|
||||
@ -264,6 +292,7 @@ public abstract class Teleporter {
|
||||
|
||||
//Find any nearby leashed entities to teleport with the player
|
||||
List<Creature> nearbyEntities = getLeashedCreatures(player);
|
||||
|
||||
//Teleport all creatures leashed by the player to the portal the player is to exit from
|
||||
for (Creature creature : nearbyEntities) {
|
||||
creature.setLeashHolder(null);
|
||||
@ -280,7 +309,7 @@ public abstract class Teleporter {
|
||||
* @param player <p>The player to check</p>
|
||||
* @return <p>A list of all creatures the player is holding in a leash (lead)</p>
|
||||
*/
|
||||
protected List<Creature> getLeashedCreatures(Player player) {
|
||||
protected static List<Creature> getLeashedCreatures(Player player) {
|
||||
List<Creature> leashedCreatures = new ArrayList<>();
|
||||
//Find any nearby leashed entities to teleport with the player
|
||||
List<Entity> nearbyEntities = player.getNearbyEntities(15, 15, 15);
|
||||
|
@ -4,6 +4,7 @@ import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.teleporter.PlayerTeleporter;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
@ -71,7 +72,7 @@ public final class BungeeHelper {
|
||||
//Build the message data and send it over the SGBungee BungeeCord channel
|
||||
dataOutputStream.writeUTF("Forward");
|
||||
//Send the message to the server defined in the entrance portal's network line
|
||||
dataOutputStream.writeUTF(entrancePortal.getNetwork());
|
||||
dataOutputStream.writeUTF(stripColor(entrancePortal.getNetwork()));
|
||||
//Specify the sub-channel/tag to make it recognizable on arrival
|
||||
dataOutputStream.writeUTF(bungeeSubChannel);
|
||||
//Write the length of the message
|
||||
@ -102,7 +103,7 @@ public final class BungeeHelper {
|
||||
|
||||
//Send a connect-message to connect the player to the server defined in the entrance portal's network line
|
||||
dataOutputStream.writeUTF("Connect");
|
||||
dataOutputStream.writeUTF(entrancePortal.getNetwork());
|
||||
dataOutputStream.writeUTF(stripColor(entrancePortal.getNetwork()));
|
||||
|
||||
//Send the plugin message
|
||||
player.sendPluginMessage(Stargate.getInstance(), bungeeChannel, byteArrayOutputStream.toByteArray());
|
||||
@ -207,4 +208,14 @@ public final class BungeeHelper {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips all color tags from a string
|
||||
*
|
||||
* @param string <p>The string to strip color from</p>
|
||||
* @return <p>The string without color codes</p>
|
||||
*/
|
||||
private static String stripColor(String string) {
|
||||
return ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', string));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
package net.knarcraft.stargate.utility;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.EconomyConfig;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.property.PortalOwner;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
@ -34,9 +37,9 @@ public final class EconomyHelper {
|
||||
"was therefore not possible. Make the owner re-create the portal to fix this.", entrancePortal));
|
||||
}
|
||||
if (entrancePortal.getGate().getToOwner() && ownerUUID != null) {
|
||||
success = Stargate.getEconomyConfig().chargePlayerIfNecessary(player, ownerUUID, cost);
|
||||
success = chargePlayerIfNecessary(player, ownerUUID, cost);
|
||||
} else {
|
||||
success = Stargate.getEconomyConfig().chargePlayerIfNecessary(player, cost);
|
||||
success = chargePlayerIfNecessary(player, cost);
|
||||
}
|
||||
|
||||
//Send the insufficient funds message
|
||||
@ -118,6 +121,116 @@ public final class EconomyHelper {
|
||||
Stargate.getMessageSender().sendSuccessMessage(player, refundMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the cost of using a gate
|
||||
*
|
||||
* @param player <p>The player trying to use the gate</p>
|
||||
* @param source <p>The source/entry portal</p>
|
||||
* @param destination <p>The destination portal</p>
|
||||
* @return <p>The cost of using the portal</p>
|
||||
*/
|
||||
public static int getUseCost(Player player, Portal source, Portal destination) {
|
||||
EconomyConfig config = Stargate.getEconomyConfig();
|
||||
//No payment required
|
||||
if (!config.useEconomy() || source.getOptions().isFree()) {
|
||||
return 0;
|
||||
}
|
||||
//Not charging for free destinations
|
||||
if (destination != null && config.freeIfFreeDestination() && destination.getOptions().isFree()) {
|
||||
return 0;
|
||||
}
|
||||
//Cost is 0 if the player owns this gate and funds go to the owner
|
||||
if (source.getGate().getToOwner() && source.isOwner(player)) {
|
||||
return 0;
|
||||
}
|
||||
//Player gets free gate use
|
||||
if (PermissionHelper.hasPermission(player, "stargate.free.use")) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return source.getGate().getUseCost();
|
||||
}
|
||||
|
||||
/**
|
||||
* Charges the player for an action, if required
|
||||
*
|
||||
* @param player <p>The player to take money from</p>
|
||||
* @param target <p>The target to pay</p>
|
||||
* @param cost <p>The cost of the transaction</p>
|
||||
* @return <p>True if the player was charged successfully</p>
|
||||
*/
|
||||
public static boolean chargePlayerIfNecessary(Player player, UUID target, int cost) {
|
||||
if (skipPayment(cost)) {
|
||||
return true;
|
||||
}
|
||||
//Charge player
|
||||
return chargePlayer(player, target, cost);
|
||||
}
|
||||
|
||||
/**
|
||||
* Charges a player
|
||||
*
|
||||
* @param player <p>The player to charge</p>
|
||||
* @param amount <p>The amount to charge</p>
|
||||
* @return <p>True if the payment succeeded, or if no payment was necessary</p>
|
||||
*/
|
||||
private static boolean chargePlayer(Player player, double amount) {
|
||||
Economy economy = Stargate.getEconomyConfig().getEconomy();
|
||||
if (Stargate.getEconomyConfig().isEconomyEnabled() && economy != null) {
|
||||
if (!economy.has(player, amount)) {
|
||||
return false;
|
||||
}
|
||||
economy.withdrawPlayer(player, amount);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Charges the player for an action, if required
|
||||
*
|
||||
* @param player <p>The player to take money from</p>
|
||||
* @param cost <p>The cost of the transaction</p>
|
||||
* @return <p>True if the player was charged successfully</p>
|
||||
*/
|
||||
public static boolean chargePlayerIfNecessary(Player player, int cost) {
|
||||
if (skipPayment(cost)) {
|
||||
return true;
|
||||
}
|
||||
//Charge player
|
||||
return chargePlayer(player, cost);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a payment transaction should be skipped
|
||||
*
|
||||
* @param cost <p>The cost of the transaction</p>
|
||||
* @return <p>True if the transaction should be skipped</p>
|
||||
*/
|
||||
private static boolean skipPayment(int cost) {
|
||||
return cost == 0 || !Stargate.getEconomyConfig().useEconomy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Charges a player, giving the charge to a target
|
||||
*
|
||||
* @param player <p>The player to charge</p>
|
||||
* @param target <p>The UUID of the player to pay</p>
|
||||
* @param amount <p>The amount to charge</p>
|
||||
* @return <p>True if the payment succeeded, or if no payment was necessary</p>
|
||||
*/
|
||||
private static boolean chargePlayer(Player player, UUID target, double amount) {
|
||||
Economy economy = Stargate.getEconomyConfig().getEconomy();
|
||||
if (Stargate.getEconomyConfig().isEconomyEnabled() && player.getUniqueId().compareTo(target) != 0 && economy != null) {
|
||||
if (!economy.has(player, amount)) {
|
||||
return false;
|
||||
}
|
||||
//Take money from the user and give to the owner
|
||||
economy.withdrawPlayer(player, amount);
|
||||
economy.depositPlayer(Bukkit.getOfflinePlayer(target), amount);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the cost and portal variables in a string
|
||||
*
|
||||
|
@ -8,6 +8,8 @@ import net.knarcraft.stargate.portal.teleporter.PlayerTeleporter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
import static net.knarcraft.stargate.Stargate.getMaxNameNetworkLength;
|
||||
|
||||
/**
|
||||
* Helper class for deciding which actions a player is allowed to perform
|
||||
*/
|
||||
@ -105,12 +107,12 @@ public final class PermissionHelper {
|
||||
boolean deny = false;
|
||||
|
||||
if (entrancePortal.getOptions().isBungee()) {
|
||||
if (!PermissionHelper.canAccessServer(player, entrancePortal.getNetwork())) {
|
||||
if (!PermissionHelper.canAccessServer(player, entrancePortal.getCleanNetwork())) {
|
||||
//If the portal is a bungee portal, and the player cannot access the server, deny
|
||||
Stargate.debug("cannotAccessPortal", "Cannot access server");
|
||||
deny = true;
|
||||
}
|
||||
} else if (PermissionHelper.cannotAccessNetwork(player, entrancePortal.getNetwork())) {
|
||||
} else if (PermissionHelper.cannotAccessNetwork(player, entrancePortal.getCleanNetwork())) {
|
||||
//If the player does not have access to the network, deny
|
||||
Stargate.debug("cannotAccessPortal", "Cannot access network");
|
||||
deny = true;
|
||||
@ -200,8 +202,8 @@ public final class PermissionHelper {
|
||||
}
|
||||
//Is able to create personal gates (Assumption is made they can also access them)
|
||||
String playerName = player.getName();
|
||||
if (playerName.length() > 11) {
|
||||
playerName = playerName.substring(0, 11);
|
||||
if (playerName.length() > getMaxNameNetworkLength()) {
|
||||
playerName = playerName.substring(0, getMaxNameNetworkLength());
|
||||
}
|
||||
return !network.equals(playerName) || !hasPermission(player, "stargate.create.personal");
|
||||
}
|
||||
@ -241,7 +243,7 @@ public final class PermissionHelper {
|
||||
return true;
|
||||
}
|
||||
//Don't charge for free destinations unless specified in the config
|
||||
return dest != null && !Stargate.getEconomyConfig().chargeFreeDestination() && dest.getOptions().isFree();
|
||||
return dest != null && Stargate.getEconomyConfig().freeIfFreeDestination() && dest.getOptions().isFree();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -345,7 +347,7 @@ public final class PermissionHelper {
|
||||
* @return <p>True if the player is allowed to destroy the portal</p>
|
||||
*/
|
||||
public static boolean canDestroyPortal(Player player, Portal portal) {
|
||||
String network = portal.getNetwork();
|
||||
String network = portal.getCleanNetwork();
|
||||
|
||||
//Use a special check for bungee portals
|
||||
if (portal.getOptions().isBungee()) {
|
||||
@ -405,7 +407,7 @@ public final class PermissionHelper {
|
||||
}
|
||||
|
||||
//Player cannot pay for teleportation
|
||||
int cost = Stargate.getEconomyConfig().getUseCost(player, entrancePortal, destination);
|
||||
int cost = EconomyHelper.getUseCost(player, entrancePortal, destination);
|
||||
if (cost > 0) {
|
||||
return EconomyHelper.cannotPayTeleportFee(entrancePortal, player, cost);
|
||||
}
|
||||
|
@ -292,16 +292,15 @@ public final class PortalFileHelper {
|
||||
*/
|
||||
private static void updatePortalButton(Portal portal) {
|
||||
BlockLocation buttonLocation = getButtonLocation(portal);
|
||||
BlockData buttonData = buttonLocation.getBlock().getBlockData();
|
||||
if (portal.getOptions().isAlwaysOn()) {
|
||||
//Clear button if not already air or water
|
||||
if (MaterialHelper.isButtonCompatible(buttonData.getMaterial())) {
|
||||
if (MaterialHelper.isButtonCompatible(buttonLocation.getType())) {
|
||||
Material newMaterial = decideRemovalMaterial(buttonLocation, portal);
|
||||
Stargate.addBlockChangeRequest(new BlockChangeRequest(buttonLocation, newMaterial, null));
|
||||
}
|
||||
} else {
|
||||
//Replace button if the material does not match
|
||||
if (buttonData.getMaterial() != portal.getGate().getPortalButton()) {
|
||||
if (buttonLocation.getType() != portal.getGate().getPortalButton()) {
|
||||
generatePortalButton(portal, DirectionHelper.getBlockFaceFromYaw(portal.getYaw()));
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,11 @@ import java.util.UUID;
|
||||
/**
|
||||
* Helps migrate player names to UUID where necessary
|
||||
*/
|
||||
public class UUIDMigrationHelper {
|
||||
public final class UUIDMigrationHelper {
|
||||
|
||||
private UUIDMigrationHelper() {
|
||||
|
||||
}
|
||||
|
||||
private static Map<String, List<Portal>> playerNamesToMigrate;
|
||||
|
||||
@ -40,7 +44,7 @@ public class UUIDMigrationHelper {
|
||||
return;
|
||||
}
|
||||
|
||||
Stargate.debug("PlayerEventListener::migrateUUID", String.format("Migrating name to UUID for player %s",
|
||||
Stargate.debug("UUIDMigrationHelper::migrateUUID", String.format("Migrating name to UUID for player %s",
|
||||
playerName));
|
||||
List<Portal> portalsOwned = playersToMigrate.get(playerName);
|
||||
if (portalsOwned == null) {
|
||||
@ -64,7 +68,7 @@ public class UUIDMigrationHelper {
|
||||
|
||||
//Get the real portal from the copy and set UUID
|
||||
for (Portal portalCopy : portals) {
|
||||
Portal portal = PortalHandler.getByName(portalCopy.getName(), portalCopy.getNetwork());
|
||||
Portal portal = PortalHandler.getByName(portalCopy.getCleanName(), portalCopy.getCleanNetwork());
|
||||
if (portal != null) {
|
||||
portal.getOwner().setUUID(uniqueId);
|
||||
worldsToSave.add(portal.getWorld());
|
||||
|
@ -24,4 +24,5 @@ usecost=economy.useCost
|
||||
toowner=economy.toOwner
|
||||
chargefreedestination=economy.chargeFreeDestination
|
||||
freegatesgreen=economy.freeGatesGreen
|
||||
CheckUpdates=
|
||||
CheckUpdates=
|
||||
economy.freeGatesGreen=economy.freeGatesColored
|
@ -27,7 +27,8 @@
|
||||
# useCost - The cost to use a gate
|
||||
# toOwner - Whether the charge for using a gate goes to the gate's owner
|
||||
# chargeFreeDestination - Whether a gate whose destination is a free gate is still charged
|
||||
# freeGatesGreen - Whether a free gate in the destination list is drawn green
|
||||
# freeGatesColored - Whether a free gate in the destination list is marked with a color
|
||||
# freeGatesColor - The color to use for marking free gates
|
||||
# I-------I-------I #
|
||||
# Debug options #
|
||||
# I-------I-------I #
|
||||
@ -64,7 +65,8 @@ economy:
|
||||
useCost: 0
|
||||
toOwner: false
|
||||
chargeFreeDestination: true
|
||||
freeGatesGreen: false
|
||||
freeGatesColored: false
|
||||
freeGatesColor: DARK_GREEN
|
||||
debugging:
|
||||
debug: false
|
||||
permissionDebug: false
|
@ -1,6 +1,6 @@
|
||||
name: Stargate
|
||||
main: net.knarcraft.stargate.Stargate
|
||||
version: 0.9.1.0
|
||||
version: 0.9.2.3
|
||||
description: Stargate mod for Bukkit Revived
|
||||
author: EpicKnarvik97
|
||||
authors: [ Drakia, PseudoKnight, EpicKnarvik97 ]
|
||||
@ -11,8 +11,8 @@ commands:
|
||||
stargate:
|
||||
aliases:
|
||||
- sg
|
||||
description: Used to see stargate info
|
||||
usage: /<command> <reload/about> - Used to see stargate info or reload the plugin
|
||||
description: Used to see stargate info, reloading and editing config values
|
||||
usage: /<command> <reload/about/config> - Used to see stargate info, reload the plugin or change config values
|
||||
permissions:
|
||||
stargate.*:
|
||||
description: Wildcard permission which gives all Stargate permissions
|
||||
|
Reference in New Issue
Block a user