diff --git a/.circleci/config.yml b/.circleci/config.yml
index 034ef2b569..1d4ba67277 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -61,7 +61,13 @@ jobs:
- ~/.m2
key: glowstone-{{ checksum "pom.xml" }}
- - run: mvn -T 2 -B -s .circleci/maven.xml source:jar javadoc:jar deploy
+ # Ensure we are on the right repo before attempting a deploy
+ - run: |
+ if [ "${CIRCLE_PROJECT_USERNAME}" == "GlowstoneMC" ]; then
+ mvn -T 2 -B -s .circleci/maven.xml source:jar javadoc:jar deploy
+ else
+ mvn -T 2 -B package
+ fi
- store_test_results:
path: target/surefire-reports
@@ -92,4 +98,4 @@ workflows:
- build:
filters:
branches:
- ignore: dev
\ No newline at end of file
+ ignore: dev
diff --git a/.gitignore b/.gitignore
index e8efa22d01..e18fc028c5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,3 +20,4 @@ dependency-reduced-pom.xml
.settings
.db
.DS_Store
+.vscode
diff --git a/docs/CHEATING_AND_ILLEGAL_BEHAVIOR_POLICY.md b/docs/CHEATING_AND_ILLEGAL_BEHAVIOR_POLICY.md
new file mode 100644
index 0000000000..9cd854941a
--- /dev/null
+++ b/docs/CHEATING_AND_ILLEGAL_BEHAVIOR_POLICY.md
@@ -0,0 +1,23 @@
+# Cheating and Illegal Behavior Policy
+
+## Purpose
+
+The purpose of this Policy is to define guidelines as to the usage of software or services deemed unreasonable in the context of the Glowstone Project.
+This Policy affirms the Project's position against cheating and unauthorized use of products and services.
+
+
+## Extent
+
+This Policy extends to the following actions, deemed unreasonable in the context of the Project:
+ * The usage of illegally distributed, obtained and/or pirated copies of the *Minecraft* client (commonly known as "*cracked clients*");
+ * The usage of pirated or stolen *Minecraft* or *Mojang AB* accounts;
+ * The usage of illegally distributed and/or obtained software, plugins and libraries with the Glowstone server;
+ * The usage of *Minecraft* clients modified with the foremost purpose of using game exploits and cheating.
+
+
+## Enforcement
+
+The enforcement of this Policy is under the discretion of the Project's administration, which may include but is not limited to:
+* The refusal to provide support to an end-user utilizing software or services deemed unreasonable to the extent of this Policy;
+ * Support may still be provided if the user accepts to stop utilizing unreasonable software or services in the context of the support request.
+* The refusal to provide support to an end-user seeking help to use software or services unreasonably to the extent of this Policy.
diff --git a/CODE_OF_CONDUCT.md b/docs/CODE_OF_CONDUCT.md
similarity index 100%
rename from CODE_OF_CONDUCT.md
rename to docs/CODE_OF_CONDUCT.md
diff --git a/.github/CONTRIBUTING.md b/docs/CONTRIBUTING.md
similarity index 100%
rename from .github/CONTRIBUTING.md
rename to docs/CONTRIBUTING.md
diff --git a/.github/ISSUE_TEMPLATE.md b/docs/ISSUE_TEMPLATE.md
similarity index 100%
rename from .github/ISSUE_TEMPLATE.md
rename to docs/ISSUE_TEMPLATE.md
diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/docs/PULL_REQUEST_TEMPLATE.md
similarity index 100%
rename from .github/PULL_REQUEST_TEMPLATE.md
rename to docs/PULL_REQUEST_TEMPLATE.md
diff --git a/README.md b/docs/README.md
similarity index 91%
rename from README.md
rename to docs/README.md
index 91199be369..701958c890 100644
--- a/README.md
+++ b/docs/README.md
@@ -1,8 +1,8 @@
![Built with Love](http://forthebadge.com/images/badges/built-with-love.svg)
-[![Join the Discord chat](https://img.shields.io/badge/discord-glowstone-738bd7.svg?style=flat-square)](https://discord.gg/TFJqhsC)
+[![Join the Discord chat](https://img.shields.io/badge/discord-glowstone-7289da.svg?style=flat-square&logo=discord)](https://discord.gg/TFJqhsC)
[![Build Status](https://circleci.com/gh/GlowstoneMC/Glowstone/tree/dev.svg?style=shield)](https://circleci.com/gh/GlowstoneMC/Glowstone/tree/dev)
-
+
# Glowstone
@@ -51,9 +51,10 @@ However, there are several drawbacks:
For a current list of features, [check the wiki](https://github.com/GlowstoneMC/Glowstone/wiki/Current-Features).
## Downloads
-[![Build Status](https://circleci.com/gh/GlowstoneMC/Glowstone.svg?style=svg)](https://circleci.com/gh/GlowstoneMC/Glowstone)
-If you don't want to build from source, pre-built jar files are available to download from [**CircleCI**](https://circleci.com/gh/GlowstoneMC/Glowstone) - click the latest build and then open the "Artifacts" tab **(you must be logged in for this to show)**. The `glowstone.jar` artifact will be under `tmp/circle-artifacts.#######/`.
+The latest LTS and monthly releases, as well as a direct link to our latest build can be found on [our website](https://glowstone.net/#downloads).
+
+Older releases can be found on [GitHub](https://github.com/GlowstoneMC/Glowstone/releases).
## Building
diff --git a/pom.xml b/pom.xml
index 902de4b2ff..9f33e2d7cd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
net.glowstoneglowstonejar
- 2018.0.1-SNAPSHOT
+ 2018.0.1Glowstonehttps://www.glowstone.netA fast, customizable and compatible open source Minecraft server.
@@ -18,6 +18,7 @@
yyyyMMdd-HHmm1.81.8
+ 1.2.10
@@ -45,7 +46,7 @@
org.slf4j
- slf4j-log4j12
+ slf4j-jdk141.7.25runtime
@@ -73,7 +74,7 @@
org.projectlomboklombok
- 1.14.8
+ 1.16.20provided
@@ -85,12 +86,12 @@
org.jetbrains.kotlinkotlin-runtime
- 1.2.0
+ ${kotlin.version}org.jetbrains.kotlinkotlin-reflect
- 1.2.0
+ ${kotlin.version}
diff --git a/src/main/java/net/glowstone/ConsoleManager.java b/src/main/java/net/glowstone/ConsoleManager.java
index d608f0c6d8..20d8e516b7 100644
--- a/src/main/java/net/glowstone/ConsoleManager.java
+++ b/src/main/java/net/glowstone/ConsoleManager.java
@@ -22,6 +22,7 @@
import java.util.logging.StreamHandler;
import jline.console.ConsoleReader;
import jline.console.completer.Completer;
+import lombok.Getter;
import net.md_5.bungee.api.chat.BaseComponent;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandException;
@@ -54,6 +55,12 @@ public final class ConsoleManager {
private final ChatColor[] colors = ChatColor.values();
private ConsoleReader reader;
+ /**
+ * Returns this ConsoleManager's console as a ConsoleCommandSender.
+ *
+ * @return the ConsoleCommandSender instance for this ConsoleManager's console
+ */
+ @Getter
private ConsoleCommandSender sender;
private boolean running = true;
@@ -135,19 +142,10 @@ public ConsoleManager(GlowServer server) {
replacements.put(ChatColor.RESET, Ansi.ansi().a(Attribute.RESET).toString());
}
- /**
- * Returns this ConsoleManager's console as a ConsoleCommandSender.
- *
- * @return the ConsoleCommandSender instance for this ConsoleManager's console
- */
- public ConsoleCommandSender getSender() {
- return sender;
- }
-
/**
* Starts the console.
*
- * @param jline TODO: document this parameter
+ * @param jline whether the console should use JLine
*/
public void startConsole(boolean jline) {
this.jline = jline;
diff --git a/src/main/java/net/glowstone/GlowOfflinePlayer.java b/src/main/java/net/glowstone/GlowOfflinePlayer.java
index df739c15bb..69b80bc80d 100644
--- a/src/main/java/net/glowstone/GlowOfflinePlayer.java
+++ b/src/main/java/net/glowstone/GlowOfflinePlayer.java
@@ -6,6 +6,7 @@
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
+import lombok.Getter;
import net.glowstone.entity.meta.profile.PlayerProfile;
import net.glowstone.entity.meta.profile.ProfileCache;
import net.glowstone.io.PlayerDataService.PlayerReader;
@@ -23,16 +24,21 @@
public final class GlowOfflinePlayer implements OfflinePlayer {
private final GlowServer server;
+ @Getter
private final PlayerProfile profile;
private boolean hasPlayed;
+ @Getter
private long firstPlayed;
+ @Getter
private long lastPlayed;
private String lastName;
- private Location bedSpawn;
+ @Getter
+ private Location bedSpawnLocation;
/**
- * Create a new offline player for the given name. If possible, the player's data will be loaded.
+ * Create a new offline player for the given name. If possible, the player's data will be
+ * loaded.
*
* @param server The server of the offline player. Must not be null.
* @param profile The profile associated with the player. Must not be null.
@@ -46,18 +52,28 @@ public GlowOfflinePlayer(GlowServer server, PlayerProfile profile) {
}
/**
- * Returns a Future for a GlowOfflinePlayer by UUID. If possible, the player's data (including name) will be loaded based on the UUID.
+ * Returns a Future for a GlowOfflinePlayer by UUID. If possible, the player's data (including
+ * name) will be loaded based on the UUID.
*
* @param server The server of the offline player. Must not be null.
* @param uuid The UUID of the player. Must not be null.
* @return A {@link GlowOfflinePlayer} future.
*/
- public static CompletableFuture getOfflinePlayer(GlowServer server, UUID uuid) {
+ public static CompletableFuture getOfflinePlayer(GlowServer server,
+ UUID uuid) {
checkNotNull(server, "server must not be null");
checkNotNull(uuid, "UUID must not be null");
- return ProfileCache.getProfile(uuid).thenApplyAsync((profile) -> new GlowOfflinePlayer(server, profile));
+ return ProfileCache.getProfile(uuid)
+ .thenApplyAsync((profile) -> new GlowOfflinePlayer(server, profile));
}
+ /**
+ * Required method for configuration serialization.
+ *
+ * @param val map to deserialize
+ * @return deserialized player record
+ * @see org.bukkit.configuration.serialization.ConfigurationSerializable
+ */
@SuppressWarnings("UnusedDeclaration")
public static OfflinePlayer deserialize(Map val) {
if (val.get("name") != null) {
@@ -78,7 +94,7 @@ private void loadData() {
if (hasPlayed) {
firstPlayed = reader.getFirstPlayed();
lastPlayed = reader.getLastPlayed();
- bedSpawn = reader.getBedSpawnLocation();
+ bedSpawnLocation = reader.getBedSpawnLocation();
String lastName = reader.getLastKnownName();
if (lastName != null) {
@@ -126,28 +142,9 @@ public boolean hasPlayedBefore() {
return hasPlayed;
}
- @Override
- public long getFirstPlayed() {
- return firstPlayed;
- }
-
- @Override
- public long getLastPlayed() {
- return lastPlayed;
- }
-
- public PlayerProfile getProfile() {
- return profile;
- }
-
////////////////////////////////////////////////////////////////////////////
// Ban, op, whitelist
- @Override
- public Location getBedSpawnLocation() {
- return bedSpawn;
- }
-
@Override
public boolean isBanned() {
return server.getBanList(Type.NAME).isBanned(getName());
@@ -169,7 +166,7 @@ public void setWhitelisted(boolean value) {
@Override
public boolean isOp() {
- return server.getOpsList().containsUUID(getUniqueId());
+ return server.getOpsList().containsUuid(getUniqueId());
}
////////////////////////////////////////////////////////////////////////////
@@ -191,6 +188,7 @@ public Map serialize() {
return ret;
}
+ @Override
public boolean equals(Object o) {
if (this == o) {
return true;
diff --git a/src/main/java/net/glowstone/GlowPluginTypeDetector.java b/src/main/java/net/glowstone/GlowPluginTypeDetector.java
index e65b388223..f7fe91181b 100644
--- a/src/main/java/net/glowstone/GlowPluginTypeDetector.java
+++ b/src/main/java/net/glowstone/GlowPluginTypeDetector.java
@@ -31,6 +31,9 @@ public GlowPluginTypeDetector(File directory) {
this.directory = directory;
}
+ /**
+ * Scans all jars in the plugin directory for their types.
+ */
public void scan() {
GlowServer.logger.info("Scanning plugins...");
File[] files = directory.listFiles(new PatternFilenameFilter(".+\\.jar"));
@@ -42,7 +45,15 @@ public void scan() {
scanFile(file);
}
- GlowServer.logger.info("PluginTypeDetector: found " + bukkitPlugins.size() + " Bukkit, " + spongePlugins.size() + " Sponge, " + (forgefPlugins.size() + forgenPlugins.size()) + " Forge, " + canaryPlugins.size() + " Canary, " + unrecognizedPlugins.size() + " unknown plugins (total " + files.length + ")");
+ GlowServer.logger.info(String.format(
+ "PluginTypeDetector: found %d Bukkit, %d Sponge, %d Forge, %d Canary, "
+ + "%d unknown plugins (total %d)",
+ bukkitPlugins.size(),
+ spongePlugins.size(),
+ forgefPlugins.size() + forgenPlugins.size(),
+ canaryPlugins.size(),
+ unrecognizedPlugins.size(),
+ files.length));
if (!unrecognizedPlugins.isEmpty()) {
for (File file : unrecognizedPlugins) {
@@ -84,7 +95,8 @@ private void scanFile(File file) {
// Analyze class file
ClassReader classReader = new ClassReader(zip.getInputStream(entryIn));
GlowVisitor visitor = new GlowVisitor();
- classReader.accept(visitor, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
+ classReader.accept(visitor, ClassReader.SKIP_CODE
+ | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
if (visitor.isSponge) {
isSponge = true;
@@ -146,6 +158,8 @@ public AnnotationVisitor visitAnnotation(String name, boolean visible) {
case "Lnet/minecraftforge/fml/common/Mod;": // newer
isForgeN = true;
break;
+ default:
+ // do nothing
}
return null;
diff --git a/src/main/java/net/glowstone/GlowServer.java b/src/main/java/net/glowstone/GlowServer.java
index f09bbfe3bd..a9aa9c872b 100644
--- a/src/main/java/net/glowstone/GlowServer.java
+++ b/src/main/java/net/glowstone/GlowServer.java
@@ -82,6 +82,7 @@
import net.glowstone.command.minecraft.TellCommand;
import net.glowstone.command.minecraft.TellrawCommand;
import net.glowstone.command.minecraft.TestForBlockCommand;
+import net.glowstone.command.minecraft.TestForBlocksCommand;
import net.glowstone.command.minecraft.TestForCommand;
import net.glowstone.command.minecraft.TimeCommand;
import net.glowstone.command.minecraft.TitleCommand;
@@ -121,7 +122,6 @@
import net.glowstone.util.GlowHelpMap;
import net.glowstone.util.GlowServerIcon;
import net.glowstone.util.GlowUnsafeValues;
-import net.glowstone.util.LibraryManager;
import net.glowstone.util.OpenCompute;
import net.glowstone.util.SecurityUtils;
import net.glowstone.util.ShutdownMonitorThread;
@@ -131,6 +131,8 @@
import net.glowstone.util.config.ServerConfig;
import net.glowstone.util.config.ServerConfig.Key;
import net.glowstone.util.config.WorldConfig;
+import net.glowstone.util.library.Library;
+import net.glowstone.util.library.LibraryManager;
import net.glowstone.util.loot.LootingManager;
import net.md_5.bungee.api.chat.BaseComponent;
import org.bukkit.BanEntry;
@@ -383,6 +385,16 @@ public org.bukkit.configuration.file.YamlConfiguration getConfig() {
* The storage provider for the world.
*/
private WorldStorageProviderFactory storageProviderFactory = null;
+ /**
+ * Whether the server should just generate and load configuration files, then exit.
+ *
+ *
This can be enabled by using the --generate-config launch argument.
+ */
+ private static boolean generateConfigOnly;
+ /**
+ * The file name for the server icon.
+ */
+ private static final String SERVER_ICON_FILE = "server-icon.png";
/**
* Creates a new server.
@@ -395,7 +407,11 @@ public GlowServer(ServerConfig config) {
// test advancement
GlowAdvancement advancement = new GlowAdvancement(NamespacedKey.minecraft("test"), null);
advancement.addCriterion("minecraft:test/criterion");
- advancement.setDisplay(new GlowAdvancementDisplay(new TextMessage("Advancements in Glowstone"), new TextMessage("=)"), new ItemStack(Material.GLOWSTONE), GlowAdvancementDisplay.FrameType.GOAL, -10F, 0));
+ advancement.setDisplay(new GlowAdvancementDisplay(
+ new TextMessage("Advancements in Glowstone"), new TextMessage("=)"),
+ new ItemStack(Material.GLOWSTONE),
+ GlowAdvancementDisplay.FrameType.GOAL,
+ -10F, 0));
addAdvancement(advancement);
this.config = config;
@@ -418,10 +434,14 @@ public static void main(String... args) {
try {
GlowServer server = createFromArguments(args);
- // we don't want to run a server when called with --version
+ // we don't want to run a server when called with --version, --help or --generate-config
if (server == null) {
return;
}
+ if (generateConfigOnly) {
+ GlowServer.logger.info("Configuration files have been loaded, exiting...");
+ return;
+ }
server.run();
} catch (SecurityException e) {
@@ -433,6 +453,12 @@ public static void main(String... args) {
}
}
+ /**
+ * Initialize a server using the command-line arguments.
+ *
+ * @param args the command-line arguments
+ * @return the new server, or null if the command-line arguments include e.g. {@code --version}
+ */
public static GlowServer createFromArguments(String... args) {
ServerConfig config = parseArguments(args);
@@ -466,30 +492,61 @@ private static ServerConfig parseArguments(String... args) {
// Help and version
if ("--help".equals(opt) || "-h".equals(opt) || "-?".equals(opt)) {
System.out.println("Available command-line options:");
- System.out.println(" --help, -h, -? Shows this help message and exits.");
- System.out.println(" --version, -v Shows version information and exits.");
- System.out.println(" --configdir Sets the configuration directory.");
+ System.out
+ .println(" --help, -h, -? Shows this help message and "
+ + "exits.");
+ System.out
+ .println(" --version, -v Shows version information and "
+ + "exits.");
+ System.out
+ .println(" --generate-config Generates and loads "
+ + "configuration files, then exits.");
+ System.out
+ .println(" --configdir Sets the configuration "
+ + "directory.");
System.out.println(" --configfile Sets the configuration file.");
- System.out.println(" --port, -p Sets the server listening port.");
- System.out.println(" --host, -H Sets the server listening address.");
- System.out.println(" --onlinemode, -o Sets the server's online-mode.");
- System.out.println(" --jline Enables or disables JLine console.");
- System.out.println(" --plugins-dir, -P Sets the plugin directory to use.");
- System.out.println(" --worlds-dir, -W Sets the world directory to use.");
- System.out.println(" --update-dir, -U Sets the plugin update folder to use.");
- System.out.println(" --max-players, -M Sets the maximum amount of players.");
+ System.out
+ .println(" --port, -p Sets the server listening port"
+ + ".");
+ System.out
+ .println(" --host, -H Sets the server listening "
+ + "address.");
+ System.out
+ .println(" --onlinemode, -o Sets the server's online-mode.");
+ System.out
+ .println(" --jline Enables or disables JLine "
+ + "console.");
+ System.out
+ .println(" --plugins-dir, -P Sets the plugin directory to "
+ + "use.");
+ System.out
+ .println(" --worlds-dir, -W Sets the world directory to "
+ + "use.");
+ System.out
+ .println(" --update-dir, -U Sets the plugin update folder "
+ + "to use.");
+ System.out
+ .println(" --max-players, -M Sets the maximum amount of "
+ + "players.");
System.out.println(" --world-name, -N Sets the main world name.");
- System.out.println(" --log-pattern, -L Sets the log file pattern (%D for date).");
+ System.out
+ .println(" --log-pattern, -L Sets the log file pattern (%D "
+ + "for date).");
return null;
} else if ("--version".equals(opt) || "-v".equals(opt)) {
- System.out.println("Glowstone version: " + GlowServer.class.getPackage().getImplementationVersion());
- System.out.println("Bukkit version: " + GlowServer.class.getPackage().getSpecificationVersion());
- System.out.println("Minecraft version: " + GAME_VERSION + " protocol " + PROTOCOL_VERSION);
+ System.out.println("Glowstone version: " + GlowServer.class.getPackage()
+ .getImplementationVersion());
+ System.out.println("Bukkit version: " + GlowServer.class.getPackage()
+ .getSpecificationVersion());
+ System.out.println(
+ "Minecraft version: " + GAME_VERSION + " protocol " + PROTOCOL_VERSION);
return null;
+ } else if ("--generate-config".equals(opt)) {
+ generateConfigOnly = true;
}
// Below this point, options require parameters
- if (i == args.length - 1) {
+ if (i == args.length - 1 && !"--generate-config".equals(opt)) {
System.err.println("Ignored option specified without value: " + opt);
continue;
}
@@ -540,6 +597,9 @@ private static ServerConfig parseArguments(String... args) {
case "-L":
parameters.put(Key.LOG_FILE, args[++i]);
break;
+ case "--generate-config":
+ // previously handled
+ break;
default:
System.err.println("Ignored invalid option: " + opt);
}
@@ -576,7 +636,8 @@ public void start() {
logger.info("Proxy support is enabled.");
}
} else if (!getOnlineMode()) {
- logger.warning("The server is running in offline mode! Only do this if you know what you're doing.");
+ logger.warning("The server is running in offline mode! Only do this if you know what "
+ + "you're doing.");
}
int openClMajor = 1;
@@ -591,7 +652,8 @@ public void start() {
CLPlatform bestCpuPlatform = null;
// gets the max flops device across platforms on the computer
for (CLPlatform platform : CLPlatform.listCLPlatforms()) {
- if (platform.isAtLeast(openClMajor, openClMinor) && platform.isExtensionAvailable("cl_khr_fp64")) {
+ if (platform.isAtLeast(openClMajor, openClMinor) && platform
+ .isExtensionAvailable("cl_khr_fp64")) {
for (CLDevice device : platform.listCLDevices()) {
if (device.getType() == CLDevice.Type.GPU) {
int flops = device.getMaxComputeUnits() * device.getMaxClockFrequency();
@@ -602,9 +664,12 @@ public void start() {
logger.info("Device is best platform so far, on " + platform);
bestIntelPlatform = platform;
} else if (flops == maxIntelFlops) {
- if (bestIntelPlatform != null && bestIntelPlatform.getVersion().compareTo(platform.getVersion()) < 0) {
+ if (bestIntelPlatform != null && bestIntelPlatform.getVersion()
+ .compareTo(platform.getVersion()) < 0) {
maxIntelFlops = flops;
- logger.info("Device tied for flops, but had higher version on " + platform);
+ logger.info(
+ "Device tied for flops, but had higher version on "
+ + platform);
bestIntelPlatform = platform;
}
}
@@ -614,9 +679,12 @@ public void start() {
logger.info("Device is best platform so far, on " + platform);
bestPlatform = platform;
} else if (flops == maxGpuFlops) {
- if (bestPlatform != null && bestPlatform.getVersion().compareTo(platform.getVersion()) < 0) {
+ if (bestPlatform != null && bestPlatform.getVersion()
+ .compareTo(platform.getVersion()) < 0) {
maxGpuFlops = flops;
- logger.info("Device tied for flops, but had higher version on " + platform);
+ logger.info(
+ "Device tied for flops, but had higher version on "
+ + platform);
bestPlatform = platform;
}
}
@@ -629,9 +697,11 @@ public void start() {
logger.info("Device is best platform so far, on " + platform);
bestCpuPlatform = platform;
} else if (flops == maxCpuFlops) {
- if (bestCpuPlatform != null && bestCpuPlatform.getVersion().compareTo(platform.getVersion()) < 0) {
+ if (bestCpuPlatform != null && bestCpuPlatform.getVersion()
+ .compareTo(platform.getVersion()) < 0) {
maxCpuFlops = flops;
- logger.info("Device tied for flops, but had higher version on " + platform);
+ logger.info("Device tied for flops, but had higher version on "
+ + platform);
bestCpuPlatform = platform;
}
}
@@ -649,10 +719,12 @@ public void start() {
} else {
if (maxGpuFlops == 0) {
if (maxIntelFlops == 0) {
- logger.info("No Intel graphics found, best platform is the best CPU platform we could find...");
+ logger.info("No Intel graphics found, best platform is the best CPU "
+ + "platform we could find...");
bestPlatform = bestCpuPlatform;
} else {
- logger.info("No dGPU found, best platform is the best Intel graphics we could find...");
+ logger.info("No dGPU found, best platform is the best Intel graphics we "
+ + "could find...");
bestPlatform = bestIntelPlatform;
}
}
@@ -660,7 +732,8 @@ public void start() {
if (bestPlatform == null) {
isGraphicsComputeAvailable = false;
- logger.info("Your system does not meet the OpenCL requirements for Glowstone. See if driver updates are available.");
+ logger.info("Your system does not meet the OpenCL requirements for Glowstone. See"
+ + " if driver updates are available.");
logger.info("Required version: " + openClMajor + '.' + openClMinor);
logger.info("Required extensions: [ cl_khr_fp64 ]");
} else {
@@ -684,14 +757,16 @@ public void start() {
}
// Start loading plugins
- new LibraryManager().run();
+ List libraries = aggregateLibraries();
+ new LibraryManager(config.getString(Key.LIBRARY_REPOSITORY_URL),
+ config.getString(Key.LIBRARIES_FOLDER),
+ config.getBoolean(Key.LIBRARY_CHECKSUM_VALIDATION),
+ config.getInt(Key.LIBRARY_DOWNLOAD_ATTEMPTS), libraries).run();
loadPlugins();
enablePlugins(PluginLoadOrder.STARTUP);
// Create worlds
- String name = config.getString(Key.LEVEL_NAME);
String seedString = config.getString(Key.LEVEL_SEED);
- boolean structs = getGenerateStructures();
WorldType type = WorldType.getByName(getWorldType());
if (type == null) {
type = WorldType.NORMAL;
@@ -710,17 +785,23 @@ public void start() {
}
if (storageProviderFactory == null) {
- storageProviderFactory = (worldName) -> new AnvilWorldStorageProvider(new File(getWorldContainer(), worldName));
+ storageProviderFactory
+ = (worldName) -> new AnvilWorldStorageProvider(new File(getWorldContainer(),
+ worldName));
}
-
- createWorld(WorldCreator.name(name).environment(Environment.NORMAL).seed(seed).type(type).generateStructures(structs));
+ String name = config.getString(Key.LEVEL_NAME);
+ boolean structs = getGenerateStructures();
+ createWorld(WorldCreator.name(name).environment(Environment.NORMAL).seed(seed).type(type)
+ .generateStructures(structs));
if (getAllowNether()) {
checkTransfer(name, "_nether", Environment.NETHER);
- createWorld(WorldCreator.name(name + "_nether").environment(Environment.NETHER).seed(seed).type(type).generateStructures(structs));
+ createWorld(WorldCreator.name(name + "_nether").environment(Environment.NETHER)
+ .seed(seed).type(type).generateStructures(structs));
}
if (getAllowEnd()) {
checkTransfer(name, "_the_end", Environment.THE_END);
- createWorld(WorldCreator.name(name + "_the_end").environment(Environment.THE_END).seed(seed).type(type).generateStructures(structs));
+ createWorld(WorldCreator.name(name + "_the_end").environment(Environment.THE_END)
+ .seed(seed).type(type).generateStructures(structs));
}
// Finish loading plugins
@@ -731,14 +812,16 @@ public void start() {
private void checkTransfer(String name, String suffix, Environment environment) {
// todo: import things like per-dimension villages.dat when those are implemented
- Path srcPath = new File(new File(getWorldContainer(), name), "DIM" + environment.getId()).toPath();
+ Path srcPath = new File(new File(getWorldContainer(), name), "DIM" + environment.getId())
+ .toPath();
Path destPath = new File(getWorldContainer(), name + suffix).toPath();
if (Files.exists(srcPath) && !Files.exists(destPath)) {
logger.info("Importing " + destPath + " from " + srcPath);
try {
Files.walkFileTree(srcPath, new FileVisitor() {
@Override
- public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
+ public FileVisitResult preVisitDirectory(Path dir,
+ BasicFileAttributes attrs) throws IOException {
Path target = destPath.resolve(srcPath.relativize(dir));
if (!Files.exists(target)) {
Files.createDirectory(target);
@@ -747,19 +830,24 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th
}
@Override
- public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
- Files.copy(file, destPath.resolve(srcPath.relativize(file)), StandardCopyOption.COPY_ATTRIBUTES);
+ public FileVisitResult visitFile(Path file,
+ BasicFileAttributes attrs) throws IOException {
+ Files.copy(file, destPath.resolve(srcPath
+ .relativize(file)), StandardCopyOption.COPY_ATTRIBUTES);
return FileVisitResult.CONTINUE;
}
@Override
- public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
- logger.warning("Importing file " + srcPath.relativize(file) + " + failed: " + exc);
+ public FileVisitResult visitFileFailed(Path file,
+ IOException exc) throws IOException {
+ logger.warning(
+ "Importing file " + srcPath.relativize(file) + " + failed: " + exc);
return FileVisitResult.CONTINUE;
}
@Override
- public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
+ public FileVisitResult postVisitDirectory(Path dir,
+ IOException exc) throws IOException {
return FileVisitResult.CONTINUE;
}
});
@@ -888,15 +976,37 @@ private void loadConfig() {
// server icon
defaultIcon = new GlowServerIcon();
try {
- File file = config.getFile("server-icon.png");
- if (file.isFile()) {
- defaultIcon = new GlowServerIcon(file);
+ File serverIconFile = config.getFile(SERVER_ICON_FILE);
+ if (serverIconFile.isFile()) {
+ defaultIcon = new GlowServerIcon(serverIconFile);
+ } else {
+ try {
+ File vanillaServerIcon = new File(SERVER_ICON_FILE);
+ if (vanillaServerIcon.isFile()) {
+ // Import from Vanilla
+ logger.info("Importing '" + SERVER_ICON_FILE + "' from Vanilla.");
+ Files.copy(vanillaServerIcon.toPath(), serverIconFile.toPath());
+ defaultIcon = new GlowServerIcon(serverIconFile);
+ }
+ } catch (Exception e) {
+ logger.log(Level.WARNING,
+ "Failed to import '" + SERVER_ICON_FILE + "' from Vanilla", e);
+ }
}
} catch (Exception e) {
- logger.log(Level.WARNING, "Failed to load server-icon.png", e);
+ logger.log(Level.WARNING, "Failed to load '" + SERVER_ICON_FILE + "'", e);
}
}
+ /**
+ * Aggregates libraries from all relevant sources together.
+ */
+ private List aggregateLibraries() {
+ return config.getMapList(Key.LIBRARIES).stream()
+ .map(Library::fromConfigMap)
+ .collect(Collectors.toList());
+ }
+
/**
* Loads all plugins, calling onLoad, &c.
*/
@@ -953,6 +1063,7 @@ private void loadPlugins() {
commandMap.register("minecraft", new TestForBlockCommand());
commandMap.register("minecraft", new SetBlockCommand());
commandMap.register("minecraft", new CloneCommand());
+ commandMap.register("minecraft", new TestForBlocksCommand());
File folder = new File(config.getString(Key.PLUGIN_FOLDER));
if (!folder.isDirectory() && !folder.mkdirs()) {
@@ -966,14 +1077,17 @@ private void loadPlugins() {
// clear plugins and prepare to load (Bukkit)
pluginManager.clearPlugins();
pluginManager.registerInterface(JavaPluginLoader.class);
- Plugin[] plugins = pluginManager.loadPlugins(folder.getPath(), pluginTypeDetector.bukkitPlugins.toArray(new File[pluginTypeDetector.bukkitPlugins.size()]));
+ Plugin[] plugins = pluginManager
+ .loadPlugins(folder.getPath(), pluginTypeDetector.bukkitPlugins
+ .toArray(new File[pluginTypeDetector.bukkitPlugins.size()]));
// call onLoad methods
for (Plugin plugin : plugins) {
try {
plugin.onLoad();
} catch (Exception ex) {
- logger.log(Level.SEVERE, "Error loading " + plugin.getDescription().getFullName(), ex);
+ logger.log(Level.SEVERE,
+ "Error loading " + plugin.getDescription().getFullName(), ex);
}
}
@@ -981,7 +1095,9 @@ private void loadPlugins() {
boolean hasSponge = false;
for (Plugin plugin : plugins) {
if (plugin.getName().equals("Bukkit2Sponge")) {
- hasSponge = true; // TODO: better detection method, plugin description file annotation APIs?
+ hasSponge
+ = true; // TODO: better detection method, plugin description file
+ // annotation APIs?
break;
}
}
@@ -994,15 +1110,19 @@ private void loadPlugins() {
}
if (!hasSponge && spongeOnlyPlugins) {
- logger.log(Level.WARNING, "SpongeAPI plugins found, but no Sponge bridge present! They will be ignored.");
+ logger.log(Level.WARNING, "SpongeAPI plugins found, but no Sponge bridge present!"
+ + " They will be ignored.");
for (File file : getSpongePlugins()) {
logger.log(Level.WARNING, "Ignored SpongeAPI plugin: " + file.getPath());
}
- logger.log(Level.WARNING, "Suggestion: install https://github.com/GlowstoneMC/Bukkit2Sponge to load these plugins");
+ logger.log(Level.WARNING, "Suggestion: install https://github"
+ + ".com/GlowstoneMC/Bukkit2Sponge to load these plugins");
}
}
- if (!pluginTypeDetector.canaryPlugins.isEmpty() || !pluginTypeDetector.forgefPlugins.isEmpty() || !pluginTypeDetector.forgenPlugins.isEmpty() || !pluginTypeDetector.unrecognizedPlugins.isEmpty()) {
+ if (!pluginTypeDetector.canaryPlugins.isEmpty() || !pluginTypeDetector.forgefPlugins
+ .isEmpty() || !pluginTypeDetector.forgenPlugins.isEmpty()
+ || !pluginTypeDetector.unrecognizedPlugins.isEmpty()) {
logger.log(Level.WARNING, "Unsupported plugin types found, will be ignored:");
for (File file : pluginTypeDetector.canaryPlugins) {
@@ -1053,14 +1173,18 @@ private void enablePlugins(PluginLoadOrder type) {
try {
pluginManager.addPermission(perm);
} catch (IllegalArgumentException ex) {
- getLogger().log(Level.WARNING, "Plugin " + plugin.getDescription().getFullName() + " tried to register permission '" + perm.getName() + "' but it's already registered", ex);
+ getLogger().log(Level.WARNING,
+ "Plugin " + plugin.getDescription().getFullName()
+ + " tried to register permission '" + perm.getName()
+ + "' but it's already registered", ex);
}
}
try {
pluginManager.enablePlugin(plugin);
} catch (Throwable ex) {
- logger.log(Level.SEVERE, "Error loading " + plugin.getDescription().getFullName(), ex);
+ logger.log(Level.SEVERE,
+ "Error loading " + plugin.getDescription().getFullName(), ex);
}
}
}
@@ -1070,9 +1194,15 @@ private void enablePlugins(PluginLoadOrder type) {
commandMap.registerServerAliases();
DefaultPermissions.registerCorePermissions();
// Default permissions
- this.permissionRoot = DefaultPermissions.registerPermission("minecraft", "Gives the user the ability to use all Minecraft utilities and commands");
- this.permissionRootCommand = DefaultPermissions.registerPermission("minecraft.command", "Gives the user the ability to use all Minecraft commands", permissionRoot);
- DefaultPermissions.registerPermission("minecraft.command.tell", "Allows the user to send a private message", PermissionDefault.TRUE, permissionRootCommand);
+ this.permissionRoot = DefaultPermissions
+ .registerPermission("minecraft", "Gives the user the ability to use all "
+ + "Minecraft utilities and commands");
+ this.permissionRootCommand = DefaultPermissions
+ .registerPermission("minecraft.command", "Gives the user the ability to use "
+ + "all Minecraft commands", permissionRoot);
+ DefaultPermissions
+ .registerPermission("minecraft.command.tell", "Allows the user to send a "
+ + "private message", PermissionDefault.TRUE, permissionRootCommand);
permissionRootCommand.recalculatePermissibles();
permissionRoot.recalculatePermissibles();
helpMap.initializeCommands();
@@ -1083,15 +1213,20 @@ private void enablePlugins(PluginLoadOrder type) {
Map> data = new HashMap<>();
- permConfig.getValues(false).forEach((key, value) -> data.put(key, ((MemorySection) value).getValues(false)));
+ permConfig.getValues(false).forEach((key, value) -> data
+ .put(key, ((MemorySection) value).getValues(false)));
- List perms = Permission.loadPermissions(data, "Permission node '%s' in permissions config is invalid", PermissionDefault.OP);
+ List perms = Permission
+ .loadPermissions(data, "Permission node '%s' in permissions config is "
+ + "invalid", PermissionDefault.OP);
for (Permission perm : perms) {
try {
pluginManager.addPermission(perm);
} catch (IllegalArgumentException ex) {
- getLogger().log(Level.WARNING, "Permission config tried to register '" + perm.getName() + "' but it's already registered", ex);
+ getLogger().log(Level.WARNING,
+ "Permission config tried to register '" + perm.getName()
+ + "' but it's already registered", ex);
}
}
}
@@ -1129,7 +1264,8 @@ public void reloadData() {
@Override
public String toString() {
- return "GlowServer{name=" + getName() + ",version=" + getVersion() + ",minecraftVersion=" + GAME_VERSION + "}";
+ return "GlowServer{name=" + getName() + ",version=" + getVersion() + ",minecraftVersion="
+ + GAME_VERSION + "}";
}
////////////////////////////////////////////////////////////////////////////
@@ -1164,29 +1300,36 @@ public void addAdvancement(Advancement advancement) {
}
/**
- * Creates an {@link AdvancementsMessage} containing a list of advancements the server has, along with some extra actions.
+ * Creates an {@link AdvancementsMessage} containing a list of advancements the server has,
+ * along with some extra actions.
*
*
This does not affect the server's advancement registry.
*
- * @param clear whether to clear the advancements on the player's perspective.
- * @param remove a list of advancement {@link NamespacedKey NamespacedKeys} to remove from the player's perspective.
+ * @param clear whether to clear the advancements on the player's perspective.
+ * @param remove a list of advancement {@link NamespacedKey NamespacedKeys} to remove
+ * from the player's perspective.
* @return a resulting {@link AdvancementsMessage} packet
*/
- public AdvancementsMessage createAdvancementsMessage(boolean clear, List remove, Player player) {
+ public AdvancementsMessage createAdvancementsMessage(boolean clear, List remove,
+ Player player) {
return createAdvancementsMessage(advancements, clear, remove, player);
}
/**
- * Creates an {@link AdvancementsMessage} containing a given list of advancements, along with some extra actions.
+ * Creates an {@link AdvancementsMessage} containing a given list of advancements, along with
+ * some extra actions.
*
*
This does not affect the server's advancement registry.
*
* @param advancements the advancements to add to the player's perspective.
- * @param clear whether to clear the advancements on the player's perspective.
- * @param remove a list of advancement {@link NamespacedKey NamespacedKeys} to remove from the player's perspective.
+ * @param clear whether to clear the advancements on the player's perspective.
+ * @param remove a list of advancement {@link NamespacedKey NamespacedKeys} to remove
+ * from the player's perspective.
* @return a resulting {@link AdvancementsMessage} packet
*/
- public AdvancementsMessage createAdvancementsMessage(Map advancements, boolean clear, List remove, Player player) {
+ public AdvancementsMessage createAdvancementsMessage(
+ Map advancements, boolean clear, List remove,
+ Player player) {
return new AdvancementsMessage(clear, advancements, remove);
}
@@ -1419,7 +1562,8 @@ public String getName() {
@Override
public String getVersion() {
- return GlowServer.class.getPackage().getImplementationVersion() + " (MC: " + GAME_VERSION + ")";
+ return GlowServer.class.getPackage().getImplementationVersion() + " (MC: " + GAME_VERSION
+ + ")";
}
@Override
@@ -1511,8 +1655,7 @@ public boolean reloadCommandAliases() {
@Override
public boolean suggestPlayerNamesWhenNullTabCompletions() {
- // TODO: Implementation (1.12.1)
- return false;
+ return config.getBoolean(Key.SUGGEST_PLAYER_NAMES_WHEN_NULL_TAB_COMPLETIONS);
}
@Override
@@ -1548,7 +1691,8 @@ public PluginCommand getPluginCommand(String name) {
@Override
public Map getCommandAliases() {
Map aliases = new HashMap<>();
- ConfigurationSection section = config.getConfigFile(Key.COMMANDS_FILE).getConfigurationSection("aliases");
+ ConfigurationSection section = config.getConfigFile(Key.COMMANDS_FILE)
+ .getConfigurationSection("aliases");
if (section == null) {
return aliases;
}
@@ -1560,7 +1704,8 @@ public Map getCommandAliases() {
}
@Override
- public boolean dispatchCommand(CommandSender sender, String commandLine) throws CommandException {
+ public boolean dispatchCommand(CommandSender sender,
+ String commandLine) throws CommandException {
if (commandMap.dispatch(sender, commandLine)) {
return true;
}
@@ -1576,7 +1721,8 @@ public boolean dispatchCommand(CommandSender sender, String commandLine) throws
@Override
public Set getOperators() {
- return opsList.getProfiles().stream().map(this::getOfflinePlayer).collect(Collectors.toSet());
+ return opsList.getProfiles().stream().map(this::getOfflinePlayer)
+ .collect(Collectors.toSet());
}
////////////////////////////////////////////////////////////////////////////
@@ -1588,7 +1734,7 @@ public Collection extends Player> getOnlinePlayers() {
}
/**
- * Gets the modifiable set of the server's online players
+ * Gets the modifiable set of the server's online players.
*
* @return the server's modifiable set of players.
*/
@@ -1618,11 +1764,13 @@ public CompletableFuture getOfflinePlayersAsync() {
}
}
- return getPlayerDataService().getOfflinePlayers().thenAcceptAsync(offlinePlayers -> offlinePlayers.stream()
- .filter(offline -> !uuids.contains(offline.getUniqueId())).forEach(offline -> {
- result.add(offline);
- uuids.add(offline.getUniqueId());
- })).thenApply((v) -> result.toArray(new OfflinePlayer[result.size()]));
+ return getPlayerDataService().getOfflinePlayers()
+ .thenAcceptAsync(offlinePlayers -> offlinePlayers.stream()
+ .filter(offline -> !uuids.contains(offline.getUniqueId()))
+ .forEach(offline -> {
+ result.add(offline);
+ uuids.add(offline.getUniqueId());
+ })).thenApply((v) -> result.toArray(new OfflinePlayer[result.size()]));
}
@Override
@@ -1758,11 +1906,13 @@ public CompletableFuture getOfflinePlayerAsync(UUID uuid) {
return CompletableFuture.completedFuture(onlinePlayer);
}
- return GlowOfflinePlayer.getOfflinePlayer(this, uuid).thenApply((player) -> (OfflinePlayer) player);
+ return GlowOfflinePlayer.getOfflinePlayer(this, uuid)
+ .thenApply((player) -> (OfflinePlayer) player);
}
private OfflinePlayer getOfflinePlayerFallback(String name) {
- return getOfflinePlayer(new PlayerProfile(name, UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes())));
+ return getOfflinePlayer(new PlayerProfile(name, UUID
+ .nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes())));
}
@@ -1811,7 +1961,8 @@ public void broadcastPacket(Message message) {
@Override
public Set getWhitelistedPlayers() {
- return whitelist.getProfiles().stream().map(this::getOfflinePlayer).collect(Collectors.toSet());
+ return whitelist.getProfiles().stream().map(this::getOfflinePlayer)
+ .collect(Collectors.toSet());
}
@Override
@@ -1836,7 +1987,8 @@ public void unbanIP(String address) {
@Override
public Set getBannedPlayers() {
- return nameBans.getBanEntries().stream().map(entry -> getOfflinePlayer(entry.getTarget())).collect(Collectors.toSet());
+ return nameBans.getBanEntries().stream().map(entry -> getOfflinePlayer(entry.getTarget()))
+ .collect(Collectors.toSet());
}
@Override
@@ -1874,7 +2026,8 @@ private ChunkGenerator getGenerator(String name, Environment environment, WorldT
ConfigurationSection worlds = config.getWorlds();
if (worlds != null) {
String genName = worlds.getString(name + ".generator", null);
- ChunkGenerator generator = WorldCreator.getGeneratorForName(name, genName, getConsoleSender());
+ ChunkGenerator generator = WorldCreator
+ .getGeneratorForName(name, genName, getConsoleSender());
if (generator != null) {
return generator;
}
@@ -1901,7 +2054,8 @@ public GlowWorld createWorld(WorldCreator creator) {
return world;
}
if (isGenerationDisabled()) {
- logger.warning("World generation is disabled! World '" + creator.name() + "' will be empty.");
+ logger.warning(
+ "World generation is disabled! World '" + creator.name() + "' will be empty.");
}
if (creator.generator() == null) {
@@ -1909,7 +2063,8 @@ public GlowWorld createWorld(WorldCreator creator) {
}
// GlowWorld's constructor calls addWorld below.
- return new GlowWorld(this, creator, storageProviderFactory.createWorldStorageProvider(creator.name()));
+ return new GlowWorld(this, creator, storageProviderFactory
+ .createWorldStorageProvider(creator.name()));
}
/**
@@ -2351,7 +2506,8 @@ public boolean getAllowClientMods() {
}
/**
- * Gets the maximum size of the player sample as shown on the client's server list when pinging the server.
+ * Gets the maximum size of the player sample as shown on the client's server list when pinging
+ * the server.
*
* @return the maximum size of the player sample as shown on the client's server list.
*/
@@ -2371,7 +2527,8 @@ public boolean isGenerationDisabled() {
/**
* Gets whether the server is OpenCL-capable and allowed to use graphics compute functionality.
*
- * @return true if the server is capable and allowed to use graphics compute functionality, false otherwise.
+ * @return true if the server is capable and allowed to use graphics compute functionality,
+ * false otherwise.
*/
public boolean doesUseGraphicsCompute() {
return isGraphicsComputeAvailable && config.getBoolean(Key.GRAPHICS_COMPUTE);
@@ -2387,8 +2544,9 @@ public boolean shouldPreventProxy() {
}
/**
- * Gets the current storage provider factory, or null if none has been set by a plugin and the server has not
- * started yet. The storage provider factory will be used to initialize storage for each world.
+ * Gets the current storage provider factory, or null if none has been set by a plugin and the
+ * server has not started yet. The storage provider factory will be used to initialize storage
+ * for each world.
*
* @return The current storage provider, or null.
*/
@@ -2397,14 +2555,17 @@ public WorldStorageProviderFactory getStorageProviderFactory() {
}
/**
- * If a storage provider factory has not yet been set, and the server has not fully started yet, this allows plugins
- * to set a storage provider factory, which will be used to create a storage provider for each world. Otherwise,
- * this will throw an {@link IllegalStateException}.
- * @param storageProviderFactory The world storage provider that is attempting to be set.
+ * If a storage provider factory has not yet been set, and the server has not fully started yet,
+ * this allows plugins to set a storage provider factory, which will be used to create a storage
+ * provider for each world. Otherwise, this will throw an {@link IllegalStateException}.
+ *
+ * @param storageProviderFactory The world storage provider that is attempting to be
+ * set.
*/
public void setStorageProvider(WorldStorageProviderFactory storageProviderFactory) {
if (this.storageProviderFactory != null) {
- throw new IllegalStateException("Duplicate storage provider attempting to be set. Only one custom storage provider may be provided.");
+ throw new IllegalStateException("Duplicate storage provider attempting to be set. "
+ + "Only one custom storage provider may be provided.");
}
this.storageProviderFactory = storageProviderFactory;
}
diff --git a/src/main/java/net/glowstone/GlowWorld.java b/src/main/java/net/glowstone/GlowWorld.java
index c554abb678..f2159c1337 100644
--- a/src/main/java/net/glowstone/GlowWorld.java
+++ b/src/main/java/net/glowstone/GlowWorld.java
@@ -45,7 +45,7 @@
import net.glowstone.entity.GlowLightningStrike;
import net.glowstone.entity.GlowLivingEntity;
import net.glowstone.entity.GlowPlayer;
-import net.glowstone.entity.GlowTNTPrimed;
+import net.glowstone.entity.GlowTntPrimed;
import net.glowstone.entity.objects.GlowFallingBlock;
import net.glowstone.entity.objects.GlowItem;
import net.glowstone.entity.physics.BoundingBox;
@@ -140,29 +140,42 @@ public final class GlowWorld implements World {
*/
private static int seaLevel;
/**
- * The server of this world.
+ * Get the world's parent server.
+ *
+ * @return The GlowServer for the world.
*/
+ @Getter
private final GlowServer server;
/**
* The name of this world.
*/
+ @Getter
private final String name;
/**
* The chunk manager.
+ *
+ * @return The ChunkManager for the world.
*/
- private final ChunkManager chunks;
+ @Getter
+ private final ChunkManager chunkManager;
/**
- * The world metadata service used.
+ * The storage provider for the world.
+ *
+ * @return The {@link WorldStorageProvider}.
*/
- private final WorldStorageProvider storageProvider;
+ @Getter
+ private final WorldStorageProvider storage;
/**
* The world's UUID.
*/
private final UUID uid;
/**
* The entity manager.
+ *
+ * @return the entity manager
*/
- private final EntityManager entities = new EntityManager();
+ @Getter
+ private final EntityManager entityManager = new EntityManager();
/**
* The chunk generator for this world.
*/
@@ -174,10 +187,12 @@ public final class GlowWorld implements World {
/**
* The game rules used in this world.
*/
- private final GameRuleManager gameRules = new GameRuleManager();
+ @Getter
+ private final GameRuleManager gameRuleMap = new GameRuleManager();
/**
* The environment.
*/
+ @Getter
private final Environment environment;
/**
* Whether structure generation is enabled.
@@ -186,6 +201,7 @@ public final class GlowWorld implements World {
/**
* The world seed.
*/
+ @Getter
private final long seed;
/**
* Contains how regular blocks should be pulsed.
@@ -198,8 +214,10 @@ public void playEffect(Location location, Effect effect) {
}
@Override
- public void playEffect(Location location, Effect effect, int id, int data, float offsetX, float offsetY, float offsetZ, float speed, int particleCount, int radius) {
- showParticle(location, effect, id, data, offsetX, offsetY, offsetZ, speed, particleCount, radius);
+ public void playEffect(Location location, Effect effect, int id, int data, float offsetX,
+ float offsetY, float offsetZ, float speed, int particleCount, int radius) {
+ showParticle(location, effect, id, data, offsetX, offsetY, offsetZ, speed,
+ particleCount, radius);
}
@Override
@@ -219,13 +237,14 @@ public LightningStrike strikeLightningEffect(Location loc, boolean isSilent) {
/**
* The world border.
*/
+ @Getter
private final GlowWorldBorder worldBorder;
/**
* The functions for this world.
*/
private final Map functions;
/**
- * A lock kept on the spawn chunks.
+ * A lock kept on the spawn chunkManager.
*/
private ChunkLock spawnChunkLock;
/**
@@ -239,11 +258,11 @@ public LightningStrike strikeLightningEffect(Location loc, boolean isSilent) {
*/
private Location spawnLocation;
/**
- * Whether to keep the spawn chunks in memory (prevent them from being unloaded).
+ * Whether to keep the spawn chunkManager in memory (prevent them from being unloaded).
*/
private boolean keepSpawnLoaded = true;
/**
- * Whether to populate chunks when they are anchored.
+ * Whether to populate chunkManager when they are anchored.
*/
private boolean populateAnchoredChunks;
/**
@@ -265,30 +284,40 @@ public LightningStrike strikeLightningEffect(Location loc, boolean isSilent) {
/**
* How many ticks until the rain/snow status is expected to change.
*/
- private int rainingTicks;
+ @Getter
+ @Setter
+ private int weatherDuration;
/**
* Whether it is currently thundering on this world.
*/
- private boolean currentlyThundering = true;
+ @Getter
+ private boolean thundering = true;
/**
* How many ticks until the thundering status is expected to change.
*/
- private int thunderingTicks;
+ @Getter
+ @Setter
+ private int thunderDuration;
/**
* The rain density on the current world tick.
*/
- private float currentRainDensity;
+ @Getter
+ private float rainDensity;
/**
* The sky darkness on the current world tick.
*/
- private float currentSkyDarkness;
+ @Getter
+ private float skyDarkness;
/**
* The age of the world, in ticks.
*/
- private long worldAge;
+ @Getter
+ @Setter
+ private long fullTime;
/**
* The current world time.
*/
+ @Getter
private long time;
/**
* The time until the next full-save.
@@ -297,40 +326,54 @@ public LightningStrike strikeLightningEffect(Location loc, boolean isSilent) {
/**
* The check to autosave.
*/
- private boolean autosave = true;
+ @Getter
+ @Setter
+ private boolean autoSave = true;
/**
* The world's gameplay difficulty.
*/
+ @Getter
private Difficulty difficulty;
/**
* Ticks between when passive mobs are spawned.
*/
- private long ticksPerAnimal;
+ @Setter
+ private int ticksPerAnimalSpawns;
/**
* Ticks between when hostile mobs are spawned.
*/
- private long ticksPerMonster;
+ @Setter
+ private int ticksPerMonsterSpawns;
/**
* Per-world spawn limits on hostile mobs.
*/
- private int monsterLimit;
+ @Getter
+ @Setter
+ private int monsterSpawnLimit;
/**
* Per-world spawn limits on passive mobs.
*/
- private int animalLimit;
+ @Getter
+ @Setter
+ private int animalSpawnLimit;
/**
* Per-world spawn limits on water mobs (squids).
*/
- private int waterAnimalLimit;
+ @Getter
+ @Setter
+ private int waterAnimalSpawnLimit;
/**
* Per-world spawn limits on ambient mobs (bats).
*/
- private int ambientLimit;
+ @Getter
+ @Setter
+ private int ambientSpawnLimit;
private Map structures;
/**
* The maximum height at which players may place blocks.
*/
- private int maxBuildHeight;
+ @Getter
+ private int maxHeight;
private Set activeChunksSet = new HashSet<>();
/**
@@ -339,7 +382,8 @@ public LightningStrike strikeLightningEffect(Location loc, boolean isSilent) {
* @param server The server for the world.
* @param creator The WorldCreator to use.
*/
- public GlowWorld(GlowServer server, WorldCreator creator, WorldStorageProvider worldStorageProvider) {
+ public GlowWorld(GlowServer server, WorldCreator creator,
+ WorldStorageProvider worldStorageProvider) {
this.server = server;
// set up values from WorldCreator
@@ -350,27 +394,27 @@ public GlowWorld(GlowServer server, WorldCreator creator, WorldStorageProvider w
generator = creator.generator();
- storageProvider = worldStorageProvider;
- storageProvider.setWorld(this);
+ storage = worldStorageProvider;
+ storage.setWorld(this);
populators = generator.getDefaultPopulators(this);
// set up values from server defaults
- ticksPerAnimal = server.getTicksPerAnimalSpawns();
- ticksPerMonster = server.getTicksPerMonsterSpawns();
- monsterLimit = server.getMonsterSpawnLimit();
- animalLimit = server.getAnimalSpawnLimit();
- waterAnimalLimit = server.getWaterAnimalSpawnLimit();
- ambientLimit = server.getAmbientSpawnLimit();
+ ticksPerAnimalSpawns = server.getTicksPerAnimalSpawns();
+ ticksPerMonsterSpawns = server.getTicksPerMonsterSpawns();
+ monsterSpawnLimit = server.getMonsterSpawnLimit();
+ animalSpawnLimit = server.getAnimalSpawnLimit();
+ waterAnimalSpawnLimit = server.getWaterAnimalSpawnLimit();
+ ambientSpawnLimit = server.getAmbientSpawnLimit();
keepSpawnLoaded = server.keepSpawnLoaded();
populateAnchoredChunks = server.populateAnchoredChunks();
difficulty = server.getDifficulty();
- maxBuildHeight = server.getMaxBuildHeight();
+ maxHeight = server.getMaxBuildHeight();
seaLevel = GlowServer.getWorldConfig().getInt(WorldConfig.Key.SEA_LEVEL);
worldBorder = new GlowWorldBorder(this);
// read in world data
WorldFinalValues values;
- values = storageProvider.getMetadataService().readWorldData();
+ values = storage.getMetadataService().readWorldData();
if (values != null) {
if (values.getSeed() == 0L) {
seed = creator.seed();
@@ -383,9 +427,10 @@ public GlowWorld(GlowServer server, WorldCreator creator, WorldStorageProvider w
uid = UUID.randomUUID();
}
- chunks = new ChunkManager(this, storageProvider.getChunkIoService(), generator);
- structures = storageProvider.getStructureDataService().readStructuresData();
- functions = storageProvider.getFunctionIoService().readFunctions().stream().collect(Collectors.toMap(CommandFunction::getFullName, function -> function));
+ chunkManager = new ChunkManager(this, storage.getChunkIoService(), generator);
+ structures = storage.getStructureDataService().readStructuresData();
+ functions = storage.getFunctionIoService().readFunctions().stream()
+ .collect(Collectors.toMap(CommandFunction::getFullName, function -> function));
server.addWorld(this);
server.getLogger().info("Preparing spawn for " + name + "...");
EventFactory.callEvent(new WorldInitEvent(this));
@@ -405,38 +450,20 @@ public GlowWorld(GlowServer server, WorldCreator creator, WorldStorageProvider w
// Various internal mechanisms
/**
- * Get the world chunk manager.
- *
- * @return The ChunkManager for the world.
- */
- public ChunkManager getChunkManager() {
- return chunks;
- }
-
- /**
- * Get the world's parent server.
- *
- * @return The GlowServer for the world.
- */
- public GlowServer getServer() {
- return server;
- }
-
- /**
- * Get a new chunk lock object a player or other party can use to keep chunks loaded.
+ * Get a new chunk lock object a player or other party can use to keep chunkManager loaded.
*
* @param desc A description for this chunk lock.
* @return The ChunkLock.
*/
public ChunkLock newChunkLock(String desc) {
- return new ChunkLock(chunks, name + ": " + desc);
+ return new ChunkLock(chunkManager, name + ": " + desc);
}
/**
* Updates all the entities within this world.
*/
public void pulse() {
- List allEntities = new ArrayList<>(entities.getAll());
+ List allEntities = new ArrayList<>(entityManager.getAll());
List players = new LinkedList<>();
activeChunksSet.clear();
@@ -457,7 +484,8 @@ public void pulse() {
}
updateBlocksInActiveChunks();
- // why update blocks before Players or Entities? if there is a specific reason we should document it here.
+ // why update blocks before Players or Entities? if there is a specific reason we should
+ // document it here.
pulsePlayers(players);
resetEntities(allEntities);
@@ -473,7 +501,7 @@ public void pulse() {
}
private void updateActiveChunkCollection(GlowEntity entity) {
- // build a set of chunks around each player in this world, the
+ // build a set of chunkManager around each player in this world, the
// server view distance is taken here
int radius = server.getViewDistance();
Location playerLocation = entity.getLocation();
@@ -533,8 +561,8 @@ private void updateBlocksInSection(GlowChunk chunk, ChunkSection section, int i)
private void saveWorld() {
if (--saveTimer <= 0) {
saveTimer = AUTOSAVE_TIME;
- chunks.unloadOldChunks();
- if (autosave) {
+ chunkManager.unloadOldChunks();
+ if (autoSave) {
save(true);
}
}
@@ -543,12 +571,12 @@ private void saveWorld() {
private void updateOverworldWeather() {
// only tick weather in a NORMAL world
if (environment == Environment.NORMAL) {
- if (--rainingTicks <= 0) {
+ if (--weatherDuration <= 0) {
setStorm(!currentlyRaining);
}
- if (--thunderingTicks <= 0) {
- setThundering(!currentlyThundering);
+ if (--thunderDuration <= 0) {
+ setThundering(!thundering);
}
updateWeather();
@@ -556,7 +584,7 @@ private void updateOverworldWeather() {
}
private void informPlayersOfTime() {
- if (worldAge % (30 * TICKS_PER_SECOND) == 0) {
+ if (fullTime % (30 * TICKS_PER_SECOND) == 0) {
// Only send the time every 30 seconds; clients are smart.
getRawPlayers().forEach(GlowPlayer::sendTime);
}
@@ -564,12 +592,13 @@ private void informPlayersOfTime() {
// Tick the world age and time of day
private void updateWorldTime() {
- worldAge++;
- // worldAge is used to determine when to (periodically) update clients of server time (time of day - "time")
+ fullTime++;
+ // fullTime is used to determine when to (periodically) update clients of server time
+ // (time of day - "time")
// also used to occasionally pulse some blocks (see "tickMap" and "requestPulse()")
// Modulus by 24000, the tick length of a day
- if (gameRules.getBoolean("doDaylightCycle")) {
+ if (gameRuleMap.getBoolean("doDaylightCycle")) {
time = (time + 1) % DAY_LENGTH;
}
}
@@ -591,7 +620,8 @@ private void handleSleepAndWake(List players) {
wakeUpAllPlayers(players);
// no need to send them the time - handle that normally
} else { // otherwise check whether everyone is asleep
- boolean skipNight = gameRules.getBoolean("doDaylightCycle") && areAllPlayersSleeping(players);
+ boolean skipNight = gameRuleMap.getBoolean("doDaylightCycle")
+ && areAllPlayersSleeping(players);
// check gamerule before iterating players (micro-optimization)
if (skipNight) {
skipRestOfNight(players);
@@ -601,7 +631,7 @@ private void handleSleepAndWake(List players) {
}
private void skipRestOfNight(List players) {
- worldAge = (worldAge / DAY_LENGTH + 1) * DAY_LENGTH;
+ fullTime = (fullTime / DAY_LENGTH + 1) * DAY_LENGTH;
time = 0;
wakeUpAllPlayers(players, true);
// true = send time to all players because we just changed it (to 0), above
@@ -626,7 +656,8 @@ private void wakeUpAllPlayers(List players, boolean sendTime) {
private boolean areAllPlayersSleeping(List players) {
for (GlowPlayer player : players) {
- if (!(player.isSleeping() && player.getSleepTicks() >= 100) && !player.isSleepingIgnored()) {
+ if (!(player.isSleeping() && player.getSleepTicks() >= 100) && !player
+ .isSleepingIgnored()) {
return false;
}
}
@@ -634,11 +665,12 @@ private boolean areAllPlayersSleeping(List players) {
}
public void broadcastBlockChangeInRange(GlowChunk.Key chunkKey, BlockChangeMessage message) {
- getRawPlayers().stream().filter(player -> player.canSeeChunk(chunkKey)).forEach(player -> player.sendBlockChangeForce(message));
+ getRawPlayers().stream().filter(player -> player.canSeeChunk(chunkKey))
+ .forEach(player -> player.sendBlockChangeForce(message));
}
private void maybeStrikeLightningInChunk(int cx, int cz) {
- if (environment == Environment.NORMAL && currentlyRaining && currentlyThundering) {
+ if (environment == Environment.NORMAL && currentlyRaining && thundering) {
if (ThreadLocalRandom.current().nextInt(100000) == 0) {
strikeLightningInChunk(cx, cz);
}
@@ -652,27 +684,32 @@ private void strikeLightningInChunk(int cx, int cz) {
int z = (cz << 4) + (n >> 8 & 0xF);
int y = getHighestBlockYAt(x, z);
- // search for living entities in a 6×6×h (there's an error in the wiki!) region from 3 below the
+ // search for living entities in a 6×6×h (there's an error in the wiki!) region from 3
+ // below the
// target block up to the world height
- BoundingBox searchBox = BoundingBox.fromPositionAndSize(new Vector(x, y, z), new Vector(0, 0, 0));
+ BoundingBox searchBox = BoundingBox
+ .fromPositionAndSize(new Vector(x, y, z), new Vector(0, 0, 0));
Vector vec = new Vector(3, 3, 3);
Vector vec2 = new Vector(0, getMaxHeight(), 0);
searchBox.minCorner.subtract(vec);
searchBox.maxCorner.add(vec).add(vec2);
List livingEntities = new LinkedList<>();
// make sure entity can see sky
- getEntityManager().getEntitiesInside(searchBox, null).stream().filter(entity -> entity instanceof LivingEntity && !entity.isDead()).forEach(entity -> {
- Vector pos = entity.getLocation().toVector();
- int minY = getHighestBlockYAt(pos.getBlockX(), pos.getBlockZ());
- if (pos.getBlockY() >= minY) {
- livingEntities.add((LivingEntity) entity);
- }
- });
+ getEntityManager().getEntitiesInside(searchBox, null).stream()
+ .filter(entity -> entity instanceof LivingEntity && !entity.isDead())
+ .forEach(entity -> {
+ Vector pos = entity.getLocation().toVector();
+ int minY = getHighestBlockYAt(pos.getBlockX(), pos.getBlockZ());
+ if (pos.getBlockY() >= minY) {
+ livingEntities.add((LivingEntity) entity);
+ }
+ });
// re-target lightning if required
if (!livingEntities.isEmpty()) {
// randomly choose an entity
- LivingEntity entity = livingEntities.get(ThreadLocalRandom.current().nextInt(livingEntities.size()));
+ LivingEntity entity = livingEntities
+ .get(ThreadLocalRandom.current().nextInt(livingEntities.size()));
// re-target lightning on this living entity
Vector newTarget = entity.getLocation().toVector();
x = newTarget.getBlockX();
@@ -694,9 +731,11 @@ private void strikeLightningInChunk(int cx, int cz) {
* @return a value between 0 and 1, where 0 = all rays blocked and 1 = all rays unblocked
*/
public float rayTrace(Location location, GlowEntity entity) {
- // TODO: calculate how much of the entity is visible (not blocked by blocks) from the location
+ // TODO: calculate how much of the entity is visible (not blocked by blocks) from the
+ // location
/*
- * To calculate this step through the entity's bounding box and check whether the ray to the point
+ * To calculate this step through the entity's bounding box and check whether the ray to
+ * the point
* in the bounding box is blocked.
*
* Return (unblockedRays / allRays)
@@ -704,17 +743,8 @@ public float rayTrace(Location location, GlowEntity entity) {
return RayUtil.getExposure(location, entity.getLocation());
}
- /**
- * Gets the entity manager.
- *
- * @return The entity manager.
- */
- public EntityManager getEntityManager() {
- return entities;
- }
-
public Collection getRawPlayers() {
- return entities.getAll(GlowPlayer.class);
+ return entityManager.getAll(GlowPlayer.class);
}
////////////////////////////////////////////////////////////////////////////
@@ -722,13 +752,14 @@ public Collection getRawPlayers() {
@Override
public List getPlayers() {
- return new ArrayList<>(entities.getAll(GlowPlayer.class));
+ return new ArrayList<>(entityManager.getAll(GlowPlayer.class));
}
/**
* Returns a list of entities within a bounding box centered around a Location.
*
- *
Some implementations may impose artificial restrictions on the size of the search bounding box.
+ *
Some implementations may impose artificial restrictions on the size of the search bounding
+ * box.
*
* @param location The center of the bounding box
* @param x 1/2 the size of the box along x axis
@@ -738,21 +769,24 @@ public List getPlayers() {
*/
@Override
public Collection getNearbyEntities(Location location, double x, double y, double z) {
- Vector minCorner = new Vector(location.getX() - x, location.getY() - y, location.getZ() - z);
- Vector maxCorner = new Vector(location.getX() + x, location.getY() + y, location.getZ() + z);
+ Vector minCorner = new Vector(
+ location.getX() - x, location.getY() - y, location.getZ() - z);
+ Vector maxCorner = new Vector(
+ location.getX() + x, location.getY() + y, location.getZ() + z);
BoundingBox searchBox = BoundingBox.fromCorners(minCorner, maxCorner); // TODO: test
GlowEntity except = null;
- return entities.getEntitiesInside(searchBox, except);
+ return entityManager.getEntitiesInside(searchBox, except);
}
@Override
public List getEntities() {
- return new ArrayList<>(entities.getAll());
+ return new ArrayList<>(entityManager.getAll());
}
@Override
public List getLivingEntities() {
- return entities.getAll().stream().filter(e -> e instanceof GlowLivingEntity).map(e -> (GlowLivingEntity) e).collect(Collectors.toCollection(LinkedList::new));
+ return entityManager.getAll().stream().filter(e -> e instanceof GlowLivingEntity)
+ .map(e -> (GlowLivingEntity) e).collect(Collectors.toCollection(LinkedList::new));
}
@Override
@@ -765,13 +799,14 @@ public Collection getEntitiesByClass(Class... classes)
@Override
@SuppressWarnings("unchecked")
public Collection getEntitiesByClass(Class cls) {
- return entities.getAll().stream().filter(e -> cls.isAssignableFrom(e.getClass())).map(e -> (T) e).collect(Collectors.toCollection(ArrayList::new));
+ return entityManager.getAll().stream().filter(e -> cls.isAssignableFrom(e.getClass()))
+ .map(e -> (T) e).collect(Collectors.toCollection(ArrayList::new));
}
@Override
public Collection getEntitiesByClasses(Class>... classes) {
ArrayList result = new ArrayList<>();
- for (Entity e : entities.getAll()) {
+ for (Entity e : entityManager.getAll()) {
for (Class> cls : classes) {
if (cls.isAssignableFrom(e.getClass())) {
result.add(e);
@@ -800,6 +835,13 @@ public boolean setSpawnLocation(int x, int y, int z) {
return setSpawnLocation(new Location(this, x, y, z), true);
}
+ /**
+ * Sets the spawn location of the world.
+ *
+ * @param newSpawn the new spawn location
+ * @param anchor if true, the spawn is never unloaded while the world is running
+ * @return true if the spawn location has changed
+ */
public boolean setSpawnLocation(Location newSpawn, boolean anchor) {
Location oldSpawn = spawnLocation;
if (newSpawn.equals(oldSpawn)) {
@@ -845,9 +887,11 @@ public void setKeepSpawnInMemory(boolean keepLoaded) {
// determine a location randomly
int spawnX = ThreadLocalRandom.current().nextInt(256) - 128;
int spawnZ = ThreadLocalRandom.current().nextInt(256) - 128;
- getChunkAt(spawnX >> 4, spawnZ >> 4).load(true); // I'm not sure there's a sane way around this
+ getChunkAt(spawnX >> 4, spawnZ >> 4)
+ .load(true); // I'm not sure there's a sane way around this
- for (int tries = 0; tries < 1000 && !generator.canSpawn(this, spawnX, spawnZ); ++tries) {
+ for (int tries = 0; tries < 1000 && !generator.canSpawn(this, spawnX, spawnZ);
+ ++tries) {
spawnX += ThreadLocalRandom.current().nextInt(256) - 128;
spawnZ += ThreadLocalRandom.current().nextInt(256) - 128;
}
@@ -870,13 +914,14 @@ public void setKeepSpawnInMemory(boolean keepLoaded) {
prepareSpawn();
} else {
// attempt to immediately unload the spawn
- chunks.unloadOldChunks();
+ chunkManager.unloadOldChunks();
spawnChunkLock = null;
}
}
if (needSpawn) {
- setSpawnLocation(spawnLocation.getBlockX(), getHighestBlockYAt(spawnLocation.getBlockX(), spawnLocation.getBlockZ()), spawnLocation.getBlockZ(), false);
+ setSpawnLocation(spawnLocation.getBlockX(), getHighestBlockYAt(spawnLocation
+ .getBlockX(), spawnLocation.getBlockZ()), spawnLocation.getBlockZ(), false);
}
}
@@ -908,21 +953,6 @@ private void prepareSpawn() {
}
}
- @Override
- public boolean isAutoSave() {
- return autosave;
- }
-
- @Override
- public void setAutoSave(boolean value) {
- autosave = value;
- }
-
- @Override
- public Difficulty getDifficulty() {
- return difficulty;
- }
-
@Override
public void setDifficulty(Difficulty difficulty) {
this.difficulty = difficulty;
@@ -951,94 +981,14 @@ public boolean getAllowMonsters() {
return spawnMonsters;
}
- @Override
- public long getTicksPerAnimalSpawns() {
- return ticksPerAnimal;
- }
-
- @Override
- public void setTicksPerAnimalSpawns(int ticksPerAnimalSpawns) {
- ticksPerAnimal = ticksPerAnimalSpawns;
- }
-
- @Override
- public long getTicksPerMonsterSpawns() {
- return ticksPerMonster;
- }
-
- @Override
- public void setTicksPerMonsterSpawns(int ticksPerMonsterSpawns) {
- ticksPerMonster = ticksPerMonsterSpawns;
- }
-
- @Override
- public int getMonsterSpawnLimit() {
- return monsterLimit;
- }
-
- @Override
- public void setMonsterSpawnLimit(int limit) {
- monsterLimit = limit;
- }
-
- @Override
- public int getAnimalSpawnLimit() {
- return animalLimit;
- }
-
- @Override
- public void setAnimalSpawnLimit(int limit) {
- animalLimit = limit;
- }
-
- @Override
- public int getWaterAnimalSpawnLimit() {
- return waterAnimalLimit;
- }
-
- @Override
- public void setWaterAnimalSpawnLimit(int limit) {
- waterAnimalLimit = limit;
- }
-
- @Override
- public int getAmbientSpawnLimit() {
- return ambientLimit;
- }
-
- @Override
- public void setAmbientSpawnLimit(int limit) {
- ambientLimit = limit;
- }
-
////////////////////////////////////////////////////////////////////////////
// Various fixed world properties
- @Override
- public Environment getEnvironment() {
- return environment;
- }
-
- @Override
- public long getSeed() {
- return seed;
- }
-
@Override
public UUID getUID() {
return uid;
}
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public int getMaxHeight() {
- return maxBuildHeight;
- }
-
@Override
public int getSeaLevel() {
if (worldType == WorldType.FLAT) {
@@ -1055,6 +1005,18 @@ public boolean canGenerateStructures() {
return generateStructures;
}
+ @Override
+ public long getTicksPerAnimalSpawns() {
+ // Can't be lombokified because inherited return type is long, not int
+ return ticksPerAnimalSpawns;
+ }
+
+ @Override
+ public long getTicksPerMonsterSpawns() {
+ // Can't be lombokified because inherited return type is long, not int
+ return ticksPerMonsterSpawns;
+ }
+
////////////////////////////////////////////////////////////////////////////
// force-save
@@ -1063,16 +1025,21 @@ public void save() {
save(false);
}
+ /**
+ * Saves world to disk synchronously or asynchronously.
+ *
+ * @param async if true, save asynchronously
+ */
public void save(boolean async) {
EventFactory.callEvent(new WorldSaveEvent(this));
// save metadata
writeWorldData(async);
- // save chunks
+ // save chunkManager
maybeAsync(async, () -> {
- for (GlowChunk chunk : chunks.getLoadedChunks()) {
- chunks.performSave(chunk);
+ for (GlowChunk chunk : chunkManager.getLoadedChunks()) {
+ chunkManager.performSave(chunk);
}
});
@@ -1087,7 +1054,7 @@ public void save(boolean async) {
@Override
public ChunkGenerator getGenerator() {
- return chunks.getGenerator();
+ return chunkManager.getGenerator();
}
@Override
@@ -1103,15 +1070,18 @@ public boolean generateTree(Location location, TreeType type) {
@Override
public boolean generateTree(Location loc, TreeType type, BlockChangeDelegate delegate) {
BlockStateDelegate blockStateDelegate = new BlockStateDelegate();
- if (GlowTree.newInstance(type, ThreadLocalRandom.current(), loc, blockStateDelegate).generate()) {
+ if (GlowTree.newInstance(type, ThreadLocalRandom.current(), blockStateDelegate)
+ .generate(loc)) {
List blockStates = new ArrayList<>(blockStateDelegate.getBlockStates());
- StructureGrowEvent growEvent = new StructureGrowEvent(loc, type, false, null, blockStates);
+ StructureGrowEvent growEvent
+ = new StructureGrowEvent(loc, type, false, null, blockStates);
EventFactory.callEvent(growEvent);
if (!growEvent.isCancelled()) {
for (BlockState state : blockStates) {
state.update(true);
if (delegate != null) {
- delegate.setTypeIdAndData(state.getX(), state.getY(), state.getZ(), state.getTypeId(), state.getRawData());
+ delegate.setTypeIdAndData(state.getX(), state.getY(), state.getZ(), state
+ .getTypeId(), state.getRawData());
}
}
return true;
@@ -1121,6 +1091,7 @@ public boolean generateTree(Location loc, TreeType type, BlockChangeDelegate del
}
public Map getStructures() {
+ // TODO: Replace with a facade
return structures;
}
@@ -1138,6 +1109,11 @@ public int getTileEntityCount() {
return getBlockEntityCount();
}
+ /**
+ * Returns the number of block entities in loaded chunkManager.
+ *
+ * @return the number of block entities
+ */
public int getBlockEntityCount() {
int length = 0;
for (GlowChunk chunk : getChunkManager().getLoadedChunks()) {
@@ -1152,6 +1128,11 @@ public int getTickableTileEntityCount() {
return getTickableBlockEntityCount();
}
+ /**
+ * Returns the number of tickable block entities in loaded chunkManager.
+ *
+ * @return the number of tickable block entities
+ */
public int getTickableBlockEntityCount() {
// TODO: distinguish between block entity types
int length = 0;
@@ -1214,7 +1195,15 @@ public Block getHighestBlockAt(Location location) {
return getBlockAt(location.getBlockX(), getHighestBlockYAt(location), location.getBlockZ());
}
- public Block getHighestBlockAt(Location location, Material[] except) {
+ /**
+ * Gets the lowest block at the given {@link Location} such that the block
+ * and all blocks above it are either air or one of the given materials.
+ *
+ * @param location Coordinates to get the highest block
+ * @param except Blocks to exclude in addition to air
+ * @return Highest non-empty block
+ */
+ public Block getHighestBlockAt(Location location, Material... except) {
Block block = getHighestBlockAt(location);
List array = Arrays.asList(except);
for (int i = 0; i < 6; i++) {
@@ -1234,7 +1223,7 @@ public Chunk getChunkAt(Location location) {
@Override
public GlowChunk getChunkAt(int x, int z) {
- return chunks.getChunk(x, z);
+ return chunkManager.getChunk(x, z);
}
@Override
@@ -1244,7 +1233,8 @@ public Chunk getChunkAt(Block block) {
@Override
public void getChunkAtAsync(int x, int z, ChunkLoadCallback cb) {
- Bukkit.getServer().getScheduler().runTaskAsynchronously(null, () -> cb.onLoad(chunks.getChunk(x, z)));
+ Bukkit.getServer().getScheduler()
+ .runTaskAsynchronously(null, () -> cb.onLoad(chunkManager.getChunk(x, z)));
}
@Override
@@ -1267,17 +1257,17 @@ public boolean isChunkLoaded(Chunk chunk) {
@Override
public boolean isChunkLoaded(int x, int z) {
- return chunks.isChunkLoaded(x, z);
+ return chunkManager.isChunkLoaded(x, z);
}
@Override
public boolean isChunkInUse(int x, int z) {
- return chunks.isChunkInUse(x, z);
+ return chunkManager.isChunkInUse(x, z);
}
@Override
public Chunk[] getLoadedChunks() {
- return chunks.getLoadedChunks();
+ return chunkManager.getLoadedChunks();
}
@Override
@@ -1333,7 +1323,7 @@ public boolean unloadChunkRequest(int x, int z, boolean safe) {
@Override
public boolean regenerateChunk(int x, int z) {
- if (!chunks.forceRegeneration(x, z)) {
+ if (!chunkManager.forceRegeneration(x, z)) {
return false;
}
refreshChunk(x, z);
@@ -1360,7 +1350,8 @@ public boolean refreshChunk(int x, int z) {
}
@Override
- public ChunkSnapshot getEmptyChunkSnapshot(int x, int z, boolean includeBiome, boolean includeBiomeTempRain) {
+ public ChunkSnapshot getEmptyChunkSnapshot(int x, int z, boolean includeBiome,
+ boolean includeBiomeTempRain) {
return new EmptySnapshot(x, z, this, includeBiome, includeBiomeTempRain);
}
@@ -1380,7 +1371,9 @@ public Biome getBiome(int x, int z) {
@Override
public void setBiome(int x, int z, Biome bio) {
- getChunkAtAsync(x >> 4, z >> 4, chunk -> ((GlowChunk) chunk).setBiome(x & 0xF, z & 0xF, GlowBiome.getId(bio)));
+ getChunkAtAsync(
+ x >> 4, z >> 4, chunk -> ((GlowChunk) chunk)
+ .setBiome(x & 0xF, z & 0xF, GlowBiome.getId(bio)));
}
@Override
@@ -1397,31 +1390,45 @@ public double getHumidity(int x, int z) {
// Entity spawning
@Override
- public T spawn(Location location, Class clazz) throws IllegalArgumentException {
+ public T spawn(Location location,
+ Class clazz) throws IllegalArgumentException {
return (T) spawn(location, EntityRegistry.getEntity(clazz), SpawnReason.CUSTOM);
}
@Override
- public T spawn(Location location, Class clazz, Consumer function) throws IllegalArgumentException {
+ public T spawn(Location location, Class clazz,
+ Consumer function) throws IllegalArgumentException {
return null; // TODO: work on type mismatches
}
- public GlowEntity spawn(Location location, Class extends GlowEntity> clazz, SpawnReason reason) throws IllegalArgumentException {
+ /**
+ * Spawns an entity.
+ *
+ * @param location the {@link Location} to spawn the entity at
+ * @param clazz the class of the {@link Entity} to spawn
+ * @param reason the reason for the spawning of the entity
+ * @return an instance of the spawned {@link Entity}
+ * @throws IllegalArgumentException TODO: document the reason this can happen
+ */
+ public GlowEntity spawn(Location location, Class extends GlowEntity> clazz,
+ SpawnReason reason) throws IllegalArgumentException {
GlowEntity entity = null;
if (TNTPrimed.class.isAssignableFrom(clazz)) {
- entity = new GlowTNTPrimed(location, null);
+ entity = new GlowTntPrimed(location, null);
}
if (entity == null) {
try {
- Constructor extends GlowEntity> constructor = clazz.getConstructor(Location.class);
+ Constructor extends GlowEntity> constructor = clazz
+ .getConstructor(Location.class);
entity = constructor.newInstance(location);
GlowEntity impl = entity;
// function.accept(entity); TODO: work on type mismatches
EntitySpawnEvent spawnEvent = null;
if (entity instanceof LivingEntity) {
- spawnEvent = EventFactory.callEvent(new CreatureSpawnEvent((LivingEntity) entity, reason));
+ spawnEvent = EventFactory
+ .callEvent(new CreatureSpawnEvent((LivingEntity) entity, reason));
} else if (!(entity instanceof Item)) { // ItemSpawnEvent is called elsewhere
spawnEvent = EventFactory.callEvent(new EntitySpawnEvent(entity));
}
@@ -1430,11 +1437,14 @@ public GlowEntity spawn(Location location, Class extends GlowEntity> clazz, Sp
entity.remove();
} else {
List spawnMessage = entity.createSpawnMessage();
- getRawPlayers().stream().filter(player -> player.canSeeEntity(impl)).forEach(player -> player.getSession().sendAll(spawnMessage.toArray(new Message[spawnMessage.size()])));
+ getRawPlayers().stream().filter(player -> player.canSeeEntity(impl))
+ .forEach(player -> player.getSession().sendAll(spawnMessage
+ .toArray(new Message[spawnMessage.size()])));
}
} catch (NoSuchMethodException e) {
GlowServer.logger.log(Level.WARNING, "Invalid entity spawn: ", e);
- } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
+ } catch (IllegalAccessException | InstantiationException | InvocationTargetException
+ e) {
GlowServer.logger.log(Level.SEVERE, "Unable to spawn entity: ", e);
}
}
@@ -1447,19 +1457,20 @@ public GlowEntity spawn(Location location, Class extends GlowEntity> clazz, Sp
}
/**
- * Spawn a custom entity at the given {@link Location}
+ * Spawn a custom entity at the given {@link Location}.
*
* @param location the {@link Location} to spawn the entity at
* @param id the id of the custom entity
* @param the class of the {@link Entity} to spawn
* @return an instance of the spawned {@link Entity}
*/
- public T spawnCustomEntity(Location location, String id) throws IllegalArgumentException {
+ public T spawnCustomEntity(Location location,
+ String id) throws IllegalArgumentException {
return spawnCustomEntity(location, id, SpawnReason.CUSTOM);
}
/**
- * Spawn a custom entity at the given {@link Location}, with the given {@link SpawnReason}
+ * Spawn a custom entity at the given {@link Location}, with the given {@link SpawnReason}.
*
* @param location the {@link Location} to spawn the entity at
* @param id the id of the custom entity
@@ -1467,11 +1478,14 @@ public T spawnCustomEntity(Location location, String id) thro
* @param the class of the {@link Entity} to spawn
* @return an instance of the spawned {@link Entity}
*/
- public T spawnCustomEntity(Location location, String id, SpawnReason reason) throws IllegalArgumentException {
+ @SuppressWarnings("unchecked")
+ public T spawnCustomEntity(Location location, String id,
+ SpawnReason reason) throws IllegalArgumentException {
Preconditions.checkNotNull(id);
CustomEntityDescriptor descriptor = EntityRegistry.getCustomEntityDescriptor(id);
if (descriptor == null) {
- throw new IllegalArgumentException("Could not find a custom entity descriptor for the given id '" + id + "'");
+ throw new IllegalArgumentException(
+ "Could not find a custom entity descriptor for the given id '" + id + "'");
}
return (T) spawn(location, descriptor.getEntityClass(), reason);
}
@@ -1500,7 +1514,8 @@ public GlowItem dropItemNaturally(Location location, ItemStack item) {
@Override
public Arrow spawnArrow(Location location, Vector velocity, float speed, float spread) {
// Transformative magic
- Vector randVec = new Vector(ThreadLocalRandom.current().nextGaussian(), ThreadLocalRandom.current().nextGaussian(), ThreadLocalRandom.current().nextGaussian());
+ Vector randVec = new Vector(ThreadLocalRandom.current().nextGaussian(), ThreadLocalRandom
+ .current().nextGaussian(), ThreadLocalRandom.current().nextGaussian());
randVec.multiply(0.0075 * spread);
velocity.normalize();
@@ -1516,17 +1531,20 @@ public Arrow spawnArrow(Location location, Vector velocity, float speed, float s
}
@Override
- public T spawnArrow(Location location, Vector direction, float speed, float spread, Class clazz) {
+ public T spawnArrow(Location location, Vector direction, float speed,
+ float spread, Class clazz) {
return null;
}
@Override
- public FallingBlock spawnFallingBlock(Location location, MaterialData data) throws IllegalArgumentException {
+ public FallingBlock spawnFallingBlock(Location location,
+ MaterialData data) throws IllegalArgumentException {
return spawnFallingBlock(location, data.getItemType(), data.getData());
}
@Override
- public FallingBlock spawnFallingBlock(Location location, Material material, byte data) throws IllegalArgumentException {
+ public FallingBlock spawnFallingBlock(Location location, Material material,
+ byte data) throws IllegalArgumentException {
if (location == null || material == null) {
throw new IllegalArgumentException();
}
@@ -1534,7 +1552,8 @@ public FallingBlock spawnFallingBlock(Location location, Material material, byte
}
@Override
- public FallingBlock spawnFallingBlock(Location location, int blockId, byte blockData) throws IllegalArgumentException {
+ public FallingBlock spawnFallingBlock(Location location, int blockId,
+ byte blockData) throws IllegalArgumentException {
Material material = Material.getMaterial(blockId);
return spawnFallingBlock(location, material, blockData);
}
@@ -1544,7 +1563,8 @@ public Entity spawnEntity(Location loc, EntityType type) {
return spawn(loc, type.getEntityClass());
}
- private GlowLightningStrike strikeLightningFireEvent(Location loc, boolean effect, boolean isSilent) {
+ private GlowLightningStrike strikeLightningFireEvent(Location loc, boolean effect,
+ boolean isSilent) {
GlowLightningStrike strike = new GlowLightningStrike(loc, effect, isSilent);
LightningStrikeEvent event = new LightningStrikeEvent(this, strike);
if (EventFactory.callEvent(event).isCancelled()) {
@@ -1566,11 +1586,6 @@ public GlowLightningStrike strikeLightningEffect(Location loc) {
////////////////////////////////////////////////////////////////////////////
// Time
- @Override
- public long getTime() {
- return time;
- }
-
@Override
public void setTime(long time) {
this.time = (time % DAY_LENGTH + DAY_LENGTH) % DAY_LENGTH;
@@ -1578,16 +1593,6 @@ public void setTime(long time) {
getRawPlayers().forEach(GlowPlayer::sendTime);
}
- @Override
- public long getFullTime() {
- return worldAge;
- }
-
- @Override
- public void setFullTime(long time) {
- worldAge = time;
- }
-
////////////////////////////////////////////////////////////////////////////
// Weather
@@ -1610,9 +1615,11 @@ public void setStorm(boolean hasStorm) {
// Numbers borrowed from CraftBukkit.
if (currentlyRaining) {
- setWeatherDuration(ThreadLocalRandom.current().nextInt(HALF_DAY_IN_TICKS) + HALF_DAY_IN_TICKS);
+ setWeatherDuration(
+ ThreadLocalRandom.current().nextInt(HALF_DAY_IN_TICKS) + HALF_DAY_IN_TICKS);
} else {
- setWeatherDuration(ThreadLocalRandom.current().nextInt(WEEK_IN_TICKS) + HALF_DAY_IN_TICKS);
+ setWeatherDuration(
+ ThreadLocalRandom.current().nextInt(WEEK_IN_TICKS) + HALF_DAY_IN_TICKS);
}
// update players
@@ -1621,21 +1628,6 @@ public void setStorm(boolean hasStorm) {
}
}
- @Override
- public int getWeatherDuration() {
- return rainingTicks;
- }
-
- @Override
- public void setWeatherDuration(int duration) {
- rainingTicks = duration;
- }
-
- @Override
- public boolean isThundering() {
- return currentlyThundering;
- }
-
@Override
public void setThundering(boolean thundering) {
// call event
@@ -1645,47 +1637,31 @@ public void setThundering(boolean thundering) {
}
// change weather
- currentlyThundering = thundering;
+ this.thundering = thundering;
// Numbers borrowed from CraftBukkit.
- if (currentlyThundering) {
- setThunderDuration(ThreadLocalRandom.current().nextInt(HALF_DAY_IN_TICKS) + 180 * TICKS_PER_SECOND);
+ if (this.thundering) {
+ setThunderDuration(ThreadLocalRandom.current().nextInt(HALF_DAY_IN_TICKS)
+ + 180 * TICKS_PER_SECOND);
} else {
- setThunderDuration(ThreadLocalRandom.current().nextInt(WEEK_IN_TICKS) + HALF_DAY_IN_TICKS);
+ setThunderDuration(
+ ThreadLocalRandom.current().nextInt(WEEK_IN_TICKS) + HALF_DAY_IN_TICKS);
}
}
- @Override
- public int getThunderDuration() {
- return thunderingTicks;
- }
-
- @Override
- public void setThunderDuration(int duration) {
- thunderingTicks = duration;
- }
-
- public float getRainDensity() {
- return currentRainDensity;
- }
-
- public float getSkyDarkness() {
- return currentSkyDarkness;
- }
-
private void updateWeather() {
- float previousRainDensity = currentRainDensity;
- float previousSkyDarkness = currentSkyDarkness;
+ float previousRainDensity = rainDensity;
+ float previousSkyDarkness = skyDarkness;
float rainDensityModifier = currentlyRaining ? .01F : -.01F;
- float skyDarknessModifier = currentlyThundering ? .01F : -.01F;
- currentRainDensity = Math.max(0, Math.min(1, previousRainDensity + rainDensityModifier));
- currentSkyDarkness = Math.max(0, Math.min(1, previousSkyDarkness + skyDarknessModifier));
+ float skyDarknessModifier = thundering ? .01F : -.01F;
+ rainDensity = Math.max(0, Math.min(1, previousRainDensity + rainDensityModifier));
+ skyDarkness = Math.max(0, Math.min(1, previousSkyDarkness + skyDarknessModifier));
- if (previousRainDensity != currentRainDensity) {
+ if (previousRainDensity != rainDensity) {
getRawPlayers().forEach(GlowPlayer::sendRainDensity);
}
- if (previousSkyDarkness != currentSkyDarkness) {
+ if (previousSkyDarkness != skyDarkness) {
getRawPlayers().forEach(GlowPlayer::sendSkyDarkness);
}
}
@@ -1714,7 +1690,8 @@ public boolean createExplosion(double x, double y, double z, float power, boolea
}
@Override
- public boolean createExplosion(double x, double y, double z, float power, boolean setFire, boolean breakBlocks) {
+ public boolean createExplosion(double x, double y, double z, float power, boolean setFire,
+ boolean breakBlocks) {
return createExplosion(null, x, y, z, power, setFire, breakBlocks);
}
@@ -1730,7 +1707,8 @@ public boolean createExplosion(double x, double y, double z, float power, boolea
* @param breakBlocks Whether or not to have blocks be destroyed
* @return false if explosion was canceled, otherwise true
*/
- public boolean createExplosion(Entity source, double x, double y, double z, float power, boolean incendiary, boolean breakBlocks) {
+ public boolean createExplosion(Entity source, double x, double y, double z, float power,
+ boolean incendiary, boolean breakBlocks) {
Explosion explosion = new Explosion(source, this, x, y, z, power, incendiary, breakBlocks);
return explosion.explodeWithEvent();
}
@@ -1746,7 +1724,9 @@ public void playEffect(Location location, Effect effect, int data) {
@Override
public void playEffect(Location location, Effect effect, int data, int radius) {
int radiusSquared = radius * radius;
- getRawPlayers().stream().filter(player -> player.getLocation().distanceSquared(location) <= radiusSquared).forEach(player -> player.playEffect(location, effect, data));
+ getRawPlayers().stream()
+ .filter(player -> player.getLocation().distanceSquared(location) <= radiusSquared)
+ .forEach(player -> player.playEffect(location, effect, data));
}
@Override
@@ -1759,14 +1739,28 @@ public void playEffect(Location location, Effect effect, T data, int radius)
playEffect(location, effect, GlowEffect.getDataValue(effect, data), radius);
}
- public void playEffectExceptTo(Location location, Effect effect, int data, int radius, Player exclude) {
+ /**
+ * Plays an effect to all but one player within a given radius around a location.
+ *
+ * @param location the {@link Location} around which players must be to
+ * hear the effect
+ * @param effect the {@link Effect}
+ * @param data a data bit needed for some effects
+ * @param radius the radius around the location
+ * @param exclude the player who won't see the effect
+ */
+ public void playEffectExceptTo(Location location, Effect effect, int data, int radius,
+ Player exclude) {
int radiusSquared = radius * radius;
- getRawPlayers().stream().filter(player -> !player.equals(exclude) && player.getLocation().distanceSquared(location) <= radiusSquared).forEach(player -> player.playEffect(location, effect, data));
+ getRawPlayers().stream().filter(player -> !player.equals(exclude)
+ && player.getLocation().distanceSquared(location) <= radiusSquared)
+ .forEach(player -> player.playEffect(location, effect, data));
}
@Override
public void playSound(Location location, Sound sound, float volume, float pitch) {
- playSound(location, sound, GlowSound.getSoundCategory(GlowSound.getVanillaId(sound)), volume, pitch);
+ playSound(location, sound, GlowSound
+ .getSoundCategory(GlowSound.getVanillaId(sound)), volume, pitch);
}
@Override
@@ -1775,17 +1769,21 @@ public void playSound(Location location, String sound, float volume, float pitch
}
@Override
- public void playSound(Location location, Sound sound, SoundCategory category, float volume, float pitch) {
+ public void playSound(Location location, Sound sound, SoundCategory category, float volume,
+ float pitch) {
if (location == null || sound == null) {
return;
}
double radiusSquared = Math.pow(volume * 16, 2);
- getRawPlayers().stream().filter(player -> player.getLocation().distanceSquared(location) <= radiusSquared).forEach(player -> player.playSound(location, sound, category, volume, pitch));
+ getRawPlayers().stream()
+ .filter(player -> player.getLocation().distanceSquared(location) <= radiusSquared)
+ .forEach(player -> player.playSound(location, sound, category, volume, pitch));
}
@Override
- public void playSound(Location location, String sound, SoundCategory category, float volume, float pitch) {
+ public void playSound(Location location, String sound, SoundCategory category, float volume,
+ float pitch) {
playSound(location, GlowSound.getVanillaSound(sound), category, volume, pitch);
}
@@ -1794,8 +1792,20 @@ public Spigot spigot() {
return spigot;
}
+ /**
+ * Displays the given particle to all players.
+ *
+ * @param loc the location
+ * @param particle the particle type
+ * @param offsetX TODO: document this parameter
+ * @param offsetY TODO: document this parameter
+ * @param offsetZ TODO: document this parameter
+ * @param speed TODO: document this parameter
+ * @param amount the number of particles
+ */
//@Override
- public void showParticle(Location loc, Effect particle, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
+ public void showParticle(Location loc, Effect particle, float offsetX, float offsetY,
+ float offsetZ, float speed, int amount) {
int radius;
if (GlowParticle.isLongDistance(particle)) {
radius = 48;
@@ -1803,18 +1813,37 @@ public void showParticle(Location loc, Effect particle, float offsetX, float off
radius = 16;
}
- showParticle(loc, particle, particle.getId(), 0, offsetX, offsetY, offsetZ, speed, amount, radius);
+ showParticle(loc, particle, particle
+ .getId(), 0, offsetX, offsetY, offsetZ, speed, amount, radius);
}
+ /**
+ * Displays the given particle to all players.
+ *
+ * @param loc the location
+ * @param particle the particle type
+ * @param id the block or item type ID
+ * @param data the block or item data
+ * @param offsetX TODO: document this parameter
+ * @param offsetY TODO: document this parameter
+ * @param offsetZ TODO: document this parameter
+ * @param speed TODO: document this parameter
+ * @param amount the number of particles
+ */
//@Override
- public void showParticle(Location loc, Effect particle, int id, int data, float offsetX, float offsetY, float offsetZ, float speed, int amount, int radius) {
+ public void showParticle(Location loc, Effect particle, int id, int data, float offsetX,
+ float offsetY, float offsetZ, float speed, int amount, int radius) {
if (loc == null || particle == null) {
return;
}
double radiusSquared = radius * radius;
- getRawPlayers().stream().filter(player -> player.getLocation().distanceSquared(loc) <= radiusSquared).forEach(player -> player.spigot().playEffect(loc, particle, id, data, offsetX, offsetY, offsetZ, speed, amount, radius));
+ getRawPlayers().stream()
+ .filter(player -> player.getLocation().distanceSquared(loc) <= radiusSquared)
+ .forEach(player -> player.spigot()
+ .playEffect(loc, particle, id, data, offsetX, offsetY, offsetZ, speed,
+ amount, radius));
}
/**
@@ -1825,14 +1854,14 @@ public void showParticle(Location loc, Effect particle, int id, int data, float
private void writeWorldData(boolean async) {
maybeAsync(async, () -> {
try {
- storageProvider.getMetadataService().writeWorldData();
- storageProvider.getScoreboardIoService().save();
+ storage.getMetadataService().writeWorldData();
+ storage.getScoreboardIoService().save();
} catch (IOException e) {
server.getLogger().severe("Could not save metadata for world: " + getName());
e.printStackTrace();
}
- storageProvider.getStructureDataService().writeStructuresData(structures);
+ storage.getStructureDataService().writeStructuresData(structures);
});
}
@@ -1865,23 +1894,14 @@ public boolean unload() {
return false;
}
try {
- storageProvider.getChunkIoService().unload();
- storageProvider.getScoreboardIoService().unload();
+ storage.getChunkIoService().unload();
+ storage.getScoreboardIoService().unload();
} catch (IOException e) {
return false;
}
return true;
}
- /**
- * Get the storage provider for the world.
- *
- * @return The {@link WorldStorageProvider}.
- */
- public WorldStorageProvider getStorage() {
- return storageProvider;
- }
-
/**
* Get the world folder.
*
@@ -1889,12 +1909,12 @@ public WorldStorageProvider getStorage() {
*/
@Override
public File getWorldFolder() {
- return storageProvider.getFolder();
+ return storage.getFolder();
}
@Override
public String[] getGameRules() {
- return gameRules.getKeys();
+ return gameRuleMap.getKeys();
}
////////////////////////////////////////////////////////////////////////////
@@ -1902,12 +1922,12 @@ public String[] getGameRules() {
@Override
public String getGameRuleValue(String rule) {
- return gameRules.getString(rule);
+ return gameRuleMap.getString(rule);
}
@Override
public boolean setGameRuleValue(String rule, String value) {
- if (!gameRules.setValue(rule, value)) {
+ if (!gameRuleMap.setValue(rule, value)) {
return false;
}
if (rule.equals("doDaylightCycle")) {
@@ -1915,7 +1935,10 @@ public boolean setGameRuleValue(String rule, String value) {
getRawPlayers().forEach(GlowPlayer::sendTime);
} else if (rule.equals("reducedDebugInfo")) {
// inform clients about the debug info change
- EntityStatusMessage message = new EntityStatusMessage(0, gameRules.getBoolean("reducedDebugInfo") ? EntityStatusMessage.ENABLE_REDUCED_DEBUG_INFO : EntityStatusMessage.DISABLE_REDUCED_DEBUG_INFO);
+ EntityStatusMessage message = new EntityStatusMessage(0,
+ gameRuleMap.getBoolean("reducedDebugInfo")
+ ? EntityStatusMessage.ENABLE_REDUCED_DEBUG_INFO
+ : EntityStatusMessage.DISABLE_REDUCED_DEBUG_INFO);
for (GlowPlayer player : getRawPlayers()) {
player.getSession().send(message);
}
@@ -1925,15 +1948,11 @@ public boolean setGameRuleValue(String rule, String value) {
@Override
public boolean isGameRule(String rule) {
- return gameRules.isGameRule(rule);
- }
-
- @Override
- public GlowWorldBorder getWorldBorder() {
- return worldBorder;
+ return gameRuleMap.isGameRule(rule);
}
public Map getFunctions() {
+ // TODO: replace this with a facade
return functions;
}
@@ -1953,48 +1972,60 @@ public void spawnParticle(Particle particle, Location location, int count, T
}
@Override
- public void spawnParticle(Particle particle, double x, double y, double z, int count, T data) {
+ public void spawnParticle(Particle particle, double x, double y, double z, int count,
+ T data) {
spawnParticle(particle, x, y, z, count, 0, 0, 0, data);
}
@Override
- public void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY, double offsetZ) {
- spawnParticle(particle, location.getX(), location.getY(), location.getZ(), count, offsetX, offsetY, offsetZ);
+ public void spawnParticle(Particle particle, Location location, int count, double offsetX,
+ double offsetY, double offsetZ) {
+ spawnParticle(particle, location.getX(), location.getY(), location
+ .getZ(), count, offsetX, offsetY, offsetZ);
}
@Override
- public void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ) {
+ public void spawnParticle(Particle particle, double x, double y, double z, int count,
+ double offsetX, double offsetY, double offsetZ) {
spawnParticle(particle, x, y, z, count, offsetX, offsetY, offsetZ, null);
}
@Override
- public void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY, double offsetZ, T data) {
- spawnParticle(particle, location.getX(), location.getY(), location.getZ(), count, offsetX, offsetY, offsetZ, data);
+ public void spawnParticle(Particle particle, Location location, int count, double offsetX,
+ double offsetY, double offsetZ, T data) {
+ spawnParticle(particle, location.getX(), location.getY(), location
+ .getZ(), count, offsetX, offsetY, offsetZ, data);
}
@Override
- public void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, T data) {
+ public void spawnParticle(Particle particle, double x, double y, double z, int count,
+ double offsetX, double offsetY, double offsetZ, T data) {
spawnParticle(particle, x, y, z, count, offsetX, offsetY, offsetZ, 1, data);
}
@Override
- public void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY, double offsetZ, double extra) {
- spawnParticle(particle, location.getX(), location.getY(), location.getZ(), count, offsetX, offsetY, offsetZ, extra);
+ public void spawnParticle(Particle particle, Location location, int count, double offsetX,
+ double offsetY, double offsetZ, double extra) {
+ spawnParticle(particle, location.getX(), location.getY(), location
+ .getZ(), count, offsetX, offsetY, offsetZ, extra);
}
@Override
- public void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, double extra) {
+ public void spawnParticle(Particle particle, double x, double y, double z, int count,
+ double offsetX, double offsetY, double offsetZ, double extra) {
spawnParticle(particle, x, y, z, count, offsetX, offsetY, offsetZ, extra, null);
}
@Override
- public void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY, double offsetZ, double extra, T data) {
+ public void spawnParticle(Particle particle, Location location, int count, double offsetX,
+ double offsetY, double offsetZ, double extra, T data) {
if (particle == null) {
throw new IllegalArgumentException("particle cannot be null!");
}
if (data != null && !particle.getDataType().isInstance(data)) {
- throw new IllegalArgumentException("wrong data type " + data.getClass() + " should be " + particle.getDataType());
+ throw new IllegalArgumentException(
+ "wrong data type " + data.getClass() + " should be " + particle.getDataType());
}
for (GlowPlayer player : getRawPlayers()) {
@@ -2006,12 +2037,10 @@ public void spawnParticle(Particle particle, Location location, int count, d
}
@Override
- public void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, double extra, T data) {
- spawnParticle(particle, new Location(this, x, y, z), count, offsetX, offsetY, offsetZ, extra, data);
- }
-
- public GameRuleManager getGameRuleMap() {
- return gameRules;
+ public void spawnParticle(Particle particle, double x, double y, double z, int count,
+ double offsetX, double offsetY, double offsetZ, double extra, T data) {
+ spawnParticle(particle, new Location(this, x, y, z), count, offsetX, offsetY, offsetZ,
+ extra, data);
}
@Override
@@ -2059,24 +2088,26 @@ public Set getListeningPluginChannels() {
private void pulseTickMap() {
ItemTable itemTable = ItemTable.instance();
- for (Location location : getTickMap()) {
+ for (Location location : tickMap) {
GlowChunk chunk = (GlowChunk) location.getChunk();
if (!chunk.isLoaded()) {
continue;
}
- int typeId = chunk.getType(location.getBlockX() & 0xF, location.getBlockZ() & 0xF, location.getBlockY());
+ int typeId = chunk.getType(
+ location.getBlockX() & 0xF, location.getBlockZ() & 0xF, location.getBlockY());
BlockType type = itemTable.getBlock(Material.getMaterial(typeId));
if (type == null) {
cancelPulse(location);
continue;
}
- GlowBlock block = new GlowBlock(chunk, location.getBlockX(), location.getBlockY(), location.getBlockZ());
+ GlowBlock block = new GlowBlock(chunk, location.getBlockX(), location
+ .getBlockY(), location.getBlockZ());
Integer speed = type.getPulseTickSpeed(block);
boolean once = type.isPulseOnce(block);
if (speed == 0) {
continue;
}
- if (worldAge % speed == 0) {
+ if (fullTime % speed == 0) {
type.receivePulse(block);
if (once) {
cancelPulse(location);
@@ -2086,6 +2117,7 @@ private void pulseTickMap() {
}
public ConcurrentSet getTickMap() {
+ // TODO: replace with a facade
return tickMap;
}
@@ -2118,7 +2150,8 @@ public boolean equals(Object obj) {
/**
* The metadata store class for worlds.
*/
- private static final class WorldMetadataStore extends MetadataStoreBase implements MetadataStore {
+ private static final class WorldMetadataStore extends MetadataStoreBase
+ implements MetadataStore {
@Override
protected String disambiguate(World subject, String metadataKey) {
diff --git a/src/main/java/net/glowstone/GlowWorldBorder.java b/src/main/java/net/glowstone/GlowWorldBorder.java
index 1a8fb36fd8..63c1215aca 100644
--- a/src/main/java/net/glowstone/GlowWorldBorder.java
+++ b/src/main/java/net/glowstone/GlowWorldBorder.java
@@ -1,5 +1,7 @@
package net.glowstone;
+import lombok.Getter;
+import lombok.Setter;
import net.glowstone.entity.GlowPlayer;
import net.glowstone.net.message.play.game.WorldBorderMessage;
import org.bukkit.Location;
@@ -9,15 +11,35 @@
public class GlowWorldBorder implements WorldBorder {
private final World world;
+ @Getter
private double size;
- private double futureSize;
+ /**
+ * The target side length the world border is being resized to, in blocks.
+ *
+ * @return the target side length the world border is being resized to.
+ */
+ @Getter
+ private double sizeLerpTarget;
private double step;
+ @Getter
private Location center;
+ @Getter
+ @Setter
private double damageBuffer;
- private double damagePerBlock;
+ @Getter
+ @Setter
+ private double damageAmount;
+ @Getter
private int warningTime;
+ @Getter
private int warningDistance;
- private long time;
+ /**
+ * The delay in ticks until the world border's sides should reach the target length.
+ *
+ * @return the delay until the world border's sides should reach the target length.
+ */
+ @Getter
+ private long sizeLerpTime;
private long lastWorldTick;
/**
@@ -29,23 +51,27 @@ public GlowWorldBorder(World world) {
this.world = world;
lastWorldTick = world.getFullTime();
size = 60000000;
- time = 0;
- futureSize = size;
+ sizeLerpTime = 0;
+ sizeLerpTarget = size;
step = 0;
center = new Location(world, 0, 0, 0);
damageBuffer = 5;
- damagePerBlock = 0.2;
+ damageAmount = 0.2;
warningTime = 15;
warningDistance = 5;
}
/**
- * Creates a {@link WorldBorderMessage} containing information to initialize the world border on the client-side.
+ * Creates a {@link WorldBorderMessage} containing information to initialize the world border on
+ * the client-side.
*
* @return a new {@link WorldBorderMessage} for this world border.
*/
public WorldBorderMessage createMessage() {
- return new WorldBorderMessage(WorldBorderMessage.Action.INITIALIZE, center.getX(), center.getZ(), size, futureSize, time * 1000, 29999984, warningTime, warningDistance);
+ return new WorldBorderMessage(
+ WorldBorderMessage.Action.INITIALIZE, center.getX(), center.getZ(),
+ size, sizeLerpTarget, sizeLerpTime * 1000, 29999984,
+ warningTime, warningDistance);
}
/**
@@ -61,10 +87,10 @@ public void pulse() {
lastWorldTick = world.getFullTime();
if (step != 0) {
size += step;
- if (Math.abs(size - futureSize) < 1) {
+ if (Math.abs(size - sizeLerpTarget) < 1) {
// completed
- size = futureSize;
- time = 0;
+ size = sizeLerpTarget;
+ sizeLerpTime = 0;
step = 0;
}
}
@@ -73,8 +99,8 @@ public void pulse() {
@Override
public void reset() {
setSize(60000000);
- time = 0;
- futureSize = size;
+ sizeLerpTime = 0;
+ sizeLerpTarget = size;
step = 0;
setCenter(new Location(world, 0, 0, 0));
setDamageBuffer(5);
@@ -83,15 +109,10 @@ public void reset() {
setWarningDistance(5);
}
- @Override
- public double getSize() {
- return size;
- }
-
@Override
public void setSize(double size) {
this.size = size;
- this.futureSize = size;
+ this.sizeLerpTarget = size;
broadcast(new WorldBorderMessage(WorldBorderMessage.Action.SET_SIZE, size));
}
@@ -103,20 +124,17 @@ public void setSize(double size, long seconds) {
}
long ticks = seconds * 20;
step = (size - this.size) / (double) ticks;
- futureSize = size;
- time = seconds;
- broadcast(new WorldBorderMessage(WorldBorderMessage.Action.LERP_SIZE, this.size, futureSize, time * 1000));
- }
-
- @Override
- public Location getCenter() {
- return center;
+ sizeLerpTarget = size;
+ sizeLerpTime = seconds;
+ broadcast(new WorldBorderMessage(WorldBorderMessage.Action.LERP_SIZE,
+ this.size, sizeLerpTarget, sizeLerpTime * 1000));
}
@Override
public void setCenter(Location location) {
center = location.clone();
- broadcast(new WorldBorderMessage(WorldBorderMessage.Action.SET_CENTER, center.getX(), center.getZ()));
+ broadcast(new WorldBorderMessage(
+ WorldBorderMessage.Action.SET_CENTER, center.getX(), center.getZ()));
}
@Override
@@ -124,42 +142,12 @@ public void setCenter(double x, double z) {
setCenter(new Location(world, x, 0, z));
}
- @Override
- public double getDamageBuffer() {
- return damageBuffer;
- }
-
- @Override
- public void setDamageBuffer(double blocks) {
- this.damageBuffer = blocks;
- }
-
- @Override
- public double getDamageAmount() {
- return damagePerBlock;
- }
-
- @Override
- public void setDamageAmount(double damage) {
- this.damagePerBlock = damage;
- }
-
- @Override
- public int getWarningTime() {
- return warningTime;
- }
-
@Override
public void setWarningTime(int seconds) {
this.warningTime = seconds;
broadcast(new WorldBorderMessage(WorldBorderMessage.Action.SET_WARNING_TIME, seconds));
}
- @Override
- public int getWarningDistance() {
- return warningDistance;
- }
-
@Override
public void setWarningDistance(int distance) {
this.warningDistance = distance;
@@ -170,25 +158,8 @@ public void setWarningDistance(int distance) {
public boolean isInside(Location location) {
Location max = center.clone().add(size / 2, 0, size / 2);
Location min = center.clone().subtract(size / 2, 0, size / 2);
- return location.getX() <= max.getX() && location.getZ() <= max.getZ() && location.getX() >= min.getX() && location.getZ() >= min.getZ();
- }
-
- /**
- * The target side length the world border is being resized to, in blocks.
- *
- * @return the target side length the world border is being resized to.
- */
- public double getSizeLerpTarget() {
- return futureSize;
- }
-
- /**
- * The delay in ticks until the world border's sides should reach the target length.
- *
- * @return the delay until the world border's sides should reach the target length.
- */
- public long getSizeLerpTime() {
- return time;
+ return location.getX() <= max.getX() && location.getZ() <= max.getZ()
+ && location.getX() >= min.getX() && location.getZ() >= min.getZ();
}
private void broadcast(WorldBorderMessage message) {
diff --git a/src/main/java/net/glowstone/advancement/GlowAdvancement.java b/src/main/java/net/glowstone/advancement/GlowAdvancement.java
index 44c715e56f..51825791b7 100644
--- a/src/main/java/net/glowstone/advancement/GlowAdvancement.java
+++ b/src/main/java/net/glowstone/advancement/GlowAdvancement.java
@@ -56,6 +56,7 @@ public void addRequirement(List criteria) {
requirements.add(criteria);
}
+ @Override
public List getCriteria() {
return criteriaIds;
}
diff --git a/src/main/java/net/glowstone/block/GlowBlock.java b/src/main/java/net/glowstone/block/GlowBlock.java
index 5801563aab..0b60f1ce78 100644
--- a/src/main/java/net/glowstone/block/GlowBlock.java
+++ b/src/main/java/net/glowstone/block/GlowBlock.java
@@ -6,6 +6,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
+import lombok.Getter;
import net.glowstone.GlowServer;
import net.glowstone.GlowWorld;
import net.glowstone.block.MaterialValueManager.ValueCollection;
@@ -54,9 +55,13 @@ public final class GlowBlock implements Block {
*/
private static final MetadataStore metadata = new BlockMetadataStore();
private static final Map> counterMap = new HashMap<>();
+ @Getter
private final int x;
+ @Getter
private final int y;
+ @Getter
private final int z;
+ @Getter
private GlowWorld world;
/**
@@ -76,31 +81,11 @@ public GlowBlock(GlowChunk chunk, int x, int y, int z) {
////////////////////////////////////////////////////////////////////////////
// Basics
- @Override
- public GlowWorld getWorld() {
- return world;
- }
-
@Override
public GlowChunk getChunk() {
return (GlowChunk) world.getChunkAt(this);
}
- @Override
- public int getX() {
- return x;
- }
-
- @Override
- public int getY() {
- return y;
- }
-
- @Override
- public int getZ() {
- return z;
- }
-
@Override
public Location getLocation() {
return new Location(getWorld(), x, y, z);
diff --git a/src/main/java/net/glowstone/block/GlowBlockState.java b/src/main/java/net/glowstone/block/GlowBlockState.java
index 2e42acd4aa..f132eb5233 100644
--- a/src/main/java/net/glowstone/block/GlowBlockState.java
+++ b/src/main/java/net/glowstone/block/GlowBlockState.java
@@ -1,6 +1,8 @@
package net.glowstone.block;
import java.util.List;
+import lombok.Getter;
+import lombok.Setter;
import net.glowstone.GlowWorld;
import net.glowstone.chunk.GlowChunk;
import org.bukkit.Location;
@@ -16,13 +18,23 @@
*/
public class GlowBlockState implements BlockState {
+ @Getter
private final GlowWorld world;
+ @Getter
private final int x;
+ @Getter
private final int y;
+ @Getter
private final int z;
- private final byte light;
- protected int type;
+ @Getter
+ private final byte lightLevel;
+ @Getter
+ protected int typeId;
+ @Getter
+ @Setter
protected MaterialData data;
+ @Getter
+ @Setter
private boolean flowed;
////////////////////////////////////////////////////////////////////////////
@@ -38,16 +50,11 @@ public GlowBlockState(GlowBlock block) {
x = block.getX();
y = block.getY();
z = block.getZ();
- type = block.getTypeId();
- light = block.getLightLevel();
+ typeId = block.getTypeId();
+ lightLevel = block.getLightLevel();
makeData(block.getData());
}
- @Override
- public GlowWorld getWorld() {
- return world;
- }
-
@Override
public GlowChunk getChunk() {
return getBlock().getChunk();
@@ -58,21 +65,6 @@ public GlowBlock getBlock() {
return world.getBlockAt(x, y, z);
}
- @Override
- public int getX() {
- return x;
- }
-
- @Override
- public int getY() {
- return y;
- }
-
- @Override
- public int getZ() {
- return z;
- }
-
@Override
public Location getLocation() {
return getBlock().getLocation();
@@ -88,7 +80,7 @@ public Location getLocation(Location loc) {
@Override
public final Material getType() {
- return Material.getMaterial(type);
+ return Material.getMaterial(typeId);
}
@Override
@@ -96,28 +88,13 @@ public final void setType(Material type) {
setTypeId(type.getId());
}
- @Override
- public final int getTypeId() {
- return type;
- }
-
@Override
public final boolean setTypeId(int type) {
- this.type = type;
+ this.typeId = type;
makeData((byte) 0);
return true;
}
- @Override
- public final MaterialData getData() {
- return data;
- }
-
- @Override
- public final void setData(MaterialData data) {
- this.data = data;
- }
-
@Override
public final byte getRawData() {
return getData().getData();
@@ -136,11 +113,6 @@ public boolean isPlaced() {
////////////////////////////////////////////////////////////////////////////
// Update
- @Override
- public final byte getLightLevel() {
- return light;
- }
-
@Override
public final boolean update() {
return update(false, true);
@@ -155,25 +127,17 @@ public final boolean update(boolean force) {
public boolean update(boolean force, boolean applyPhysics) {
Block block = getBlock();
- return (block.getTypeId() == type || force)
- && block.setTypeIdAndData(type, getRawData(), applyPhysics);
- }
-
- public boolean getFlowed() {
- return flowed;
- }
-
- public void setFlowed(boolean flowed) {
- this.flowed = flowed;
+ return (block.getTypeId() == typeId || force)
+ && block.setTypeIdAndData(typeId, getRawData(), applyPhysics);
}
////////////////////////////////////////////////////////////////////////////
// Internals
private void makeData(byte data) {
- Material mat = Material.getMaterial(type);
+ Material mat = Material.getMaterial(typeId);
if (mat == null) {
- this.data = new MaterialData(type, data);
+ this.data = new MaterialData(typeId, data);
} else {
this.data = mat.getNewData(data);
}
@@ -210,7 +174,7 @@ public int hashCode() {
result = prime * result + x;
result = prime * result + y;
result = prime * result + z;
- result = prime * result + type;
+ result = prime * result + typeId;
result = prime * result + (data != null ? data.hashCode() : 0);
return result;
}
@@ -234,7 +198,7 @@ public boolean equals(Object obj) {
} else if (!data.equals(other.data)) {
return false;
}
- if (type != other.type) {
+ if (typeId != other.typeId) {
return false;
}
if (world == null) {
diff --git a/src/main/java/net/glowstone/block/ItemTable.java b/src/main/java/net/glowstone/block/ItemTable.java
index eae0c6d62c..6125cf338c 100644
--- a/src/main/java/net/glowstone/block/ItemTable.java
+++ b/src/main/java/net/glowstone/block/ItemTable.java
@@ -40,6 +40,7 @@
import net.glowstone.block.blocktype.BlockFlowerPot;
import net.glowstone.block.blocktype.BlockFurnace;
import net.glowstone.block.blocktype.BlockGrass;
+import net.glowstone.block.blocktype.BlockGrassPath;
import net.glowstone.block.blocktype.BlockGravel;
import net.glowstone.block.blocktype.BlockHay;
import net.glowstone.block.blocktype.BlockHopper;
@@ -349,8 +350,10 @@ private void registerBuiltins() {
reg(Material.DIODE_BLOCK_ON, new BlockRedstoneRepeater());
reg(Material.DIODE_BLOCK_OFF, new BlockRedstoneRepeater());
reg(Material.MAGMA, new BlockMagma());
- reg(Material.NETHER_WART_BLOCK, new BlockDirectDrops(Material.NETHER_WART_BLOCK, ToolType.AXE));
- reg(Material.RED_NETHER_BRICK, new BlockDirectDrops(Material.RED_NETHER_BRICK, ToolType.PICKAXE));
+ reg(Material.NETHER_WART_BLOCK, new BlockDirectDrops(Material.NETHER_WART_BLOCK, ToolType
+ .AXE));
+ reg(Material.RED_NETHER_BRICK, new BlockDirectDrops(Material.RED_NETHER_BRICK, ToolType
+ .PICKAXE));
reg(Material.BONE_BLOCK, new BlockDirectDrops(Material.BONE_BLOCK, ToolType.PICKAXE));
reg(Material.OBSERVER, new BlockObserver());
reg(Material.REDSTONE_COMPARATOR_ON, new BlockRedstoneComparator());
@@ -361,24 +364,35 @@ private void registerBuiltins() {
reg(Material.END_ROD, new BlockEndRod());
reg(Material.CONCRETE, new BlockDirectDrops(Material.CONCRETE));
reg(Material.CONCRETE_POWDER, new BlockConcretePowder());
- reg(Material.WHITE_GLAZED_TERRACOTTA, new BlockDirectDrops(Material.WHITE_GLAZED_TERRACOTTA));
- reg(Material.BLACK_GLAZED_TERRACOTTA, new BlockDirectDrops(Material.BLACK_GLAZED_TERRACOTTA));
+ reg(Material.WHITE_GLAZED_TERRACOTTA, new BlockDirectDrops(Material
+ .WHITE_GLAZED_TERRACOTTA));
+ reg(Material.BLACK_GLAZED_TERRACOTTA, new BlockDirectDrops(Material
+ .BLACK_GLAZED_TERRACOTTA));
reg(Material.BLUE_GLAZED_TERRACOTTA, new BlockDirectDrops(Material.BLUE_GLAZED_TERRACOTTA));
- reg(Material.BROWN_GLAZED_TERRACOTTA, new BlockDirectDrops(Material.BROWN_GLAZED_TERRACOTTA));
+ reg(Material.BROWN_GLAZED_TERRACOTTA, new BlockDirectDrops(Material
+ .BROWN_GLAZED_TERRACOTTA));
reg(Material.CYAN_GLAZED_TERRACOTTA, new BlockDirectDrops(Material.CYAN_GLAZED_TERRACOTTA));
reg(Material.GRAY_GLAZED_TERRACOTTA, new BlockDirectDrops(Material.GRAY_GLAZED_TERRACOTTA));
- reg(Material.GREEN_GLAZED_TERRACOTTA, new BlockDirectDrops(Material.GREEN_GLAZED_TERRACOTTA));
- reg(Material.LIGHT_BLUE_GLAZED_TERRACOTTA, new BlockDirectDrops(Material.LIGHT_BLUE_GLAZED_TERRACOTTA));
+ reg(Material.GREEN_GLAZED_TERRACOTTA, new BlockDirectDrops(Material
+ .GREEN_GLAZED_TERRACOTTA));
+ reg(Material.LIGHT_BLUE_GLAZED_TERRACOTTA, new BlockDirectDrops(Material
+ .LIGHT_BLUE_GLAZED_TERRACOTTA));
reg(Material.LIME_GLAZED_TERRACOTTA, new BlockDirectDrops(Material.LIME_GLAZED_TERRACOTTA));
- reg(Material.MAGENTA_GLAZED_TERRACOTTA, new BlockDirectDrops(Material.MAGENTA_GLAZED_TERRACOTTA));
- reg(Material.ORANGE_GLAZED_TERRACOTTA, new BlockDirectDrops(Material.ORANGE_GLAZED_TERRACOTTA));
+ reg(Material.MAGENTA_GLAZED_TERRACOTTA, new BlockDirectDrops(Material
+ .MAGENTA_GLAZED_TERRACOTTA));
+ reg(Material.ORANGE_GLAZED_TERRACOTTA, new BlockDirectDrops(Material
+ .ORANGE_GLAZED_TERRACOTTA));
reg(Material.PINK_GLAZED_TERRACOTTA, new BlockDirectDrops(Material.PINK_GLAZED_TERRACOTTA));
- reg(Material.PURPLE_GLAZED_TERRACOTTA, new BlockDirectDrops(Material.PURPLE_GLAZED_TERRACOTTA));
+ reg(Material.PURPLE_GLAZED_TERRACOTTA, new BlockDirectDrops(Material
+ .PURPLE_GLAZED_TERRACOTTA));
reg(Material.RED_GLAZED_TERRACOTTA, new BlockDirectDrops(Material.RED_GLAZED_TERRACOTTA));
- reg(Material.SILVER_GLAZED_TERRACOTTA, new BlockDirectDrops(Material.SILVER_GLAZED_TERRACOTTA));
- reg(Material.YELLOW_GLAZED_TERRACOTTA, new BlockDirectDrops(Material.YELLOW_GLAZED_TERRACOTTA));
+ reg(Material.SILVER_GLAZED_TERRACOTTA, new BlockDirectDrops(Material
+ .SILVER_GLAZED_TERRACOTTA));
+ reg(Material.YELLOW_GLAZED_TERRACOTTA, new BlockDirectDrops(Material
+ .YELLOW_GLAZED_TERRACOTTA));
reg(Material.CHORUS_FLOWER, new BlockChorusFlower());
reg(Material.CHORUS_PLANT, new BlockChorusPlant());
+ reg(Material.GRASS_PATH, new BlockGrassPath(), Sound.BLOCK_GRASS_BREAK);
reg(Material.FLINT_AND_STEEL, new ItemFlintAndSteel());
reg(Material.SIGN, new ItemSign());
@@ -473,12 +487,14 @@ private void registerBuiltins() {
private void reg(Material material, ItemType type) {
if (material.isBlock() != type instanceof BlockType) {
- throw new IllegalArgumentException("Cannot mismatch item and block: " + material + ", " + type);
+ throw new IllegalArgumentException(
+ "Cannot mismatch item and block: " + material + ", " + type);
}
if (materialToType.containsKey(material)) {
- throw new IllegalArgumentException("Cannot use " + type + " for " + material + ", is already " + materialToType
- .get(material));
+ throw new IllegalArgumentException(
+ "Cannot use " + type + " for " + material + ", is already " + materialToType
+ .get(material));
}
materialToType.put(material, type);
@@ -496,12 +512,14 @@ private void reg(Material material, ItemType type) {
private void reg(Material material, ItemType type, Sound sound) {
if (material.isBlock() != type instanceof BlockType) {
- throw new IllegalArgumentException("Cannot mismatch item and block: " + material + ", " + type);
+ throw new IllegalArgumentException(
+ "Cannot mismatch item and block: " + material + ", " + type);
}
if (materialToType.containsKey(material)) {
- throw new IllegalArgumentException("Cannot use " + type + " for " + material + ", is already " + materialToType
- .get(material));
+ throw new IllegalArgumentException(
+ "Cannot use " + type + " for " + material + ", is already " + materialToType
+ .get(material));
}
materialToType.put(material, type);
@@ -566,6 +584,12 @@ public ItemType getItem(int id) {
return getItem(Material.getMaterial(id));
}
+ /**
+ * Returns the {@link ItemType} for a {@link Material}, or null if not a block.
+ *
+ * @param mat a {@link Material}
+ * @return {@code mat} as an {@link ItemType}
+ */
public ItemType getItem(Material mat) {
ItemType type = materialToType.get(mat);
if (type == null) {
@@ -579,6 +603,12 @@ public BlockType getBlock(int id) {
return getBlock(Material.getMaterial(id));
}
+ /**
+ * Returns the {@link BlockType} for a {@link Material}, or null if not a block.
+ *
+ * @param mat a {@link Material}
+ * @return {@code mat} as a {@link BlockType}, or null if {@code mat} isn't a block
+ */
public BlockType getBlock(Material mat) {
ItemType itemType = getItem(mat);
if (itemType instanceof BlockType) {
diff --git a/src/main/java/net/glowstone/block/MaterialValueManager.java b/src/main/java/net/glowstone/block/MaterialValueManager.java
index c30f1fd3fa..975adbe4cd 100644
--- a/src/main/java/net/glowstone/block/MaterialValueManager.java
+++ b/src/main/java/net/glowstone/block/MaterialValueManager.java
@@ -3,12 +3,14 @@
import org.bukkit.Material;
/**
- * MaterialValueManager provides easily access to {@link Material} related values (e.g. block hardness).
+ * MaterialValueManager provides easily access to {@link Material} related values (e.g. block
+ * hardness).
*/
public interface MaterialValueManager {
/**
- * Returns the {@link ValueCollection} for the given material. If there aren't concrete values for this material, a {@link ValueCollection} with default values will be returned.
+ * Returns the {@link ValueCollection} for the given material. If there aren't concrete values
+ * for this material, a {@link ValueCollection} with default values will be returned.
*
* @param material The material to look for
* @return a {@link ValueCollection} object with values for the given material or default values
diff --git a/src/main/java/net/glowstone/block/blocktype/BlockCactus.java b/src/main/java/net/glowstone/block/blocktype/BlockCactus.java
index 8d5e895f92..afdd809f1d 100644
--- a/src/main/java/net/glowstone/block/blocktype/BlockCactus.java
+++ b/src/main/java/net/glowstone/block/blocktype/BlockCactus.java
@@ -1,5 +1,8 @@
package net.glowstone.block.blocktype;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
import net.glowstone.EventFactory;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.GlowBlockState;
@@ -7,6 +10,7 @@
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.event.block.BlockGrowEvent;
+import org.bukkit.inventory.ItemStack;
public class BlockCactus extends BlockType {
@@ -123,4 +127,10 @@ private boolean canPlaceNear(Material type) {
return true;
}
}
+
+ @Override
+ public Collection getDrops(GlowBlock me, ItemStack tool) {
+ // Overridden for cactus to remove data from the dropped item
+ return Collections.unmodifiableList(Arrays.asList(new ItemStack(Material.CACTUS)));
+ }
}
diff --git a/src/main/java/net/glowstone/block/blocktype/BlockDeadBush.java b/src/main/java/net/glowstone/block/blocktype/BlockDeadBush.java
index 1f3ead0b08..699593d2c5 100644
--- a/src/main/java/net/glowstone/block/blocktype/BlockDeadBush.java
+++ b/src/main/java/net/glowstone/block/blocktype/BlockDeadBush.java
@@ -1,6 +1,9 @@
package net.glowstone.block.blocktype;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.ThreadLocalRandom;
import net.glowstone.block.GlowBlock;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
@@ -25,6 +28,20 @@ public boolean canPlaceAt(GlowBlock block, BlockFace against) {
@Override
public Collection getDrops(GlowBlock me, ItemStack tool) {
- return BlockDropless.EMPTY_STACK;
+ // If the block below the dead bush is removed,
+ // the bush will simply disappear without dropping anything.
+ if (tool == null) {
+ return BlockDropless.EMPTY_STACK;
+ }
+
+ // Dead bush drops it self when broken with shears
+ if (tool.getType().equals(Material.SHEARS)) {
+ return Collections.unmodifiableList(Arrays.asList(new ItemStack(Material.DEAD_BUSH)));
+ }
+
+ // Dead bush drops 0-2 sticks when broken without shears
+ ThreadLocalRandom random = ThreadLocalRandom.current();
+ return Collections.unmodifiableList(Arrays.asList(
+ new ItemStack(Material.STICK,random.nextInt(3))));
}
}
diff --git a/src/main/java/net/glowstone/block/blocktype/BlockGrassPath.java b/src/main/java/net/glowstone/block/blocktype/BlockGrassPath.java
new file mode 100644
index 0000000000..6140e81e78
--- /dev/null
+++ b/src/main/java/net/glowstone/block/blocktype/BlockGrassPath.java
@@ -0,0 +1,20 @@
+package net.glowstone.block.blocktype;
+
+import net.glowstone.block.GlowBlock;
+import org.bukkit.Material;
+import org.bukkit.block.BlockFace;
+
+public class BlockGrassPath extends BlockDirectDrops {
+
+ public BlockGrassPath() {
+ super(Material.DIRT);
+ }
+
+ @Override
+ public void onNearBlockChanged(GlowBlock block, BlockFace face, GlowBlock changedBlock,
+ Material oldType, byte oldData, Material newType, byte newData) {
+ if (face == BlockFace.UP && newType.isSolid()) {
+ block.setType(Material.DIRT);
+ }
+ }
+}
diff --git a/src/main/java/net/glowstone/block/blocktype/BlockLiquid.java b/src/main/java/net/glowstone/block/blocktype/BlockLiquid.java
index 03f1605f31..cc4d4f5c7b 100644
--- a/src/main/java/net/glowstone/block/blocktype/BlockLiquid.java
+++ b/src/main/java/net/glowstone/block/blocktype/BlockLiquid.java
@@ -7,6 +7,7 @@
import static org.bukkit.block.BlockFace.UP;
import static org.bukkit.block.BlockFace.WEST;
+import lombok.Getter;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.GlowBlockState;
import net.glowstone.block.ItemTable;
@@ -28,6 +29,12 @@ public abstract class BlockLiquid extends BlockType {
private static final int TICK_RATE_WATER = 4;
private static final int TICK_RATE_LAVA = 20;
+ /**
+ * Get the bucket type to replace the empty bucket when the liquid has been collected.
+ *
+ * @return The associated bucket types material
+ */
+ @Getter
private final Material bucketType;
protected BlockLiquid(Material bucketType) {
@@ -73,15 +80,6 @@ private static Material getOpposite(Material material) {
}
}
- /**
- * Get the bucket type to replace the empty bucket when the liquid has been collected.
- *
- * @return The associated bucket types material
- */
- public Material getBucketType() {
- return bucketType;
- }
-
/**
* Check if the BlockState block is collectible by a bucket.
*
@@ -102,7 +100,7 @@ public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face,
@Override
public void onNearBlockChanged(GlowBlock block, BlockFace face, GlowBlock changedBlock,
Material oldType, byte oldData, Material newType, byte newData) {
- if (block.getState().getFlowed() && !(isWater(newType) || newType == Material.LAVA
+ if (block.getState().isFlowed() && !(isWater(newType) || newType == Material.LAVA
|| newType == Material.STATIONARY_LAVA)) {
block.getState().setFlowed(false);
}
@@ -120,7 +118,7 @@ public void receivePulse(GlowBlock block) {
}
private void calculateFlow(GlowBlock block) {
- if (!block.getState().getFlowed()) {
+ if (!block.getState().isFlowed()) {
GlowBlockState state = block.getState();
// see if we can flow down
if (block.getY() > 0) {
@@ -143,7 +141,7 @@ private void calculateFlow(GlowBlock block) {
}
}
// if we already found a match at this radius, stop
- if (state.getFlowed()) {
+ if (state.isFlowed()) {
return;
}
}
diff --git a/src/main/java/net/glowstone/block/blocktype/BlockMushroom.java b/src/main/java/net/glowstone/block/blocktype/BlockMushroom.java
index 0531bceb85..4935657e1a 100644
--- a/src/main/java/net/glowstone/block/blocktype/BlockMushroom.java
+++ b/src/main/java/net/glowstone/block/blocktype/BlockMushroom.java
@@ -75,8 +75,8 @@ public void grow(GlowPlayer player, GlowBlock block) {
}
Location loc = block.getLocation();
BlockStateDelegate blockStateDelegate = new BlockStateDelegate();
- if (GlowTree.newInstance(type, ThreadLocalRandom.current(), loc, blockStateDelegate)
- .generate()) {
+ if (GlowTree.newInstance(type, ThreadLocalRandom.current(), blockStateDelegate)
+ .generate(loc)) {
List blockStates = new ArrayList<>(blockStateDelegate.getBlockStates());
StructureGrowEvent growEvent = new StructureGrowEvent(loc, type, true, player,
blockStates);
diff --git a/src/main/java/net/glowstone/block/blocktype/BlockPiston.java b/src/main/java/net/glowstone/block/blocktype/BlockPiston.java
index 429b9b83b9..344aa4e322 100644
--- a/src/main/java/net/glowstone/block/blocktype/BlockPiston.java
+++ b/src/main/java/net/glowstone/block/blocktype/BlockPiston.java
@@ -2,6 +2,7 @@
import java.util.ArrayList;
import java.util.List;
+import lombok.Getter;
import net.glowstone.GlowWorld;
import net.glowstone.block.GlowBlock;
import net.glowstone.chunk.GlowChunk;
@@ -19,6 +20,12 @@
public class BlockPiston extends BlockDirectional {
private static final int PUSH_LIMIT = 12;
+ /**
+ * The piston is either non-sticky (default), or has a sticky behavior.
+ *
+ * @return true if the piston has a sticky base
+ */
+ @Getter
private final boolean sticky;
/** Creates the basic (non-sticky) piston block type. */
@@ -41,15 +48,6 @@ public BlockPiston(boolean sticky) {
}
}
- /**
- * The piston is either non-sticky (default), or has a sticky behavior.
- *
- * @return true if the piston has a sticky base
- */
- public boolean isSticky() {
- return sticky;
- }
-
@Override
public void blockDestroy(GlowPlayer player, GlowBlock block, BlockFace face) {
if (block.getType() == Material.PISTON_BASE) {
diff --git a/src/main/java/net/glowstone/block/blocktype/BlockSapling.java b/src/main/java/net/glowstone/block/blocktype/BlockSapling.java
index 73a2e3ff62..50f24d0ce0 100644
--- a/src/main/java/net/glowstone/block/blocktype/BlockSapling.java
+++ b/src/main/java/net/glowstone/block/blocktype/BlockSapling.java
@@ -111,8 +111,8 @@ private void generateTree(TreeType type, GlowBlock block, GlowPlayer player) {
Location loc = block.getLocation();
BlockStateDelegate blockStateDelegate = new BlockStateDelegate();
boolean canGrow = false;
- if (GlowTree.newInstance(type, ThreadLocalRandom.current(), loc, blockStateDelegate)
- .generate()) {
+ if (GlowTree.newInstance(type, ThreadLocalRandom.current(), blockStateDelegate)
+ .generate(loc)) {
List blockStates = new ArrayList<>(blockStateDelegate.getBlockStates());
StructureGrowEvent growEvent =
new StructureGrowEvent(loc, type, player != null, player, blockStates);
diff --git a/src/main/java/net/glowstone/block/blocktype/BlockSugarCane.java b/src/main/java/net/glowstone/block/blocktype/BlockSugarCane.java
index 8cf7d67010..5a0eda6548 100644
--- a/src/main/java/net/glowstone/block/blocktype/BlockSugarCane.java
+++ b/src/main/java/net/glowstone/block/blocktype/BlockSugarCane.java
@@ -49,7 +49,7 @@ public void updateBlock(GlowBlock block) {
}
GlowBlock blockAbove = block.getRelative(BlockFace.UP);
- // check it's the highest block of cactus
+ // check it's the highest block of sugar cane
if (blockAbove.isEmpty()) {
// check the current cane height
Block blockBelow = block.getRelative(BlockFace.DOWN);
@@ -98,6 +98,7 @@ private boolean isNearWater(Block block) {
@Override
public Collection getDrops(GlowBlock me, ItemStack tool) {
+ // Overridden for sugar cane to remove data from the dropped item
return Collections.unmodifiableList(Arrays.asList(new ItemStack(Material.SUGAR_CANE)));
}
}
diff --git a/src/main/java/net/glowstone/block/blocktype/BlockTnt.java b/src/main/java/net/glowstone/block/blocktype/BlockTnt.java
index 9a305a9c1b..a208752c80 100644
--- a/src/main/java/net/glowstone/block/blocktype/BlockTnt.java
+++ b/src/main/java/net/glowstone/block/blocktype/BlockTnt.java
@@ -3,10 +3,11 @@
import net.glowstone.block.GlowBlock;
import net.glowstone.block.GlowBlockState;
import net.glowstone.entity.GlowPlayer;
-import net.glowstone.entity.GlowTNTPrimed;
+import net.glowstone.entity.GlowTntPrimed;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.World;
+import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
@@ -14,20 +15,33 @@
public class BlockTnt extends BlockType {
/**
- * Convert a TNT block into a primed TNT entity.
+ * Convert a TNT block into a primed TNT entity with the player who ignited the TNT.
*
* @param tntBlock The block to ignite.
* @param ignitedByExplosion True if another explosion caused this ignition.
+ * @param player The player who ignited the TNT.
*/
- public static void igniteBlock(GlowBlock tntBlock, boolean ignitedByExplosion) {
+ public static void igniteBlock(
+ Block tntBlock, boolean ignitedByExplosion, GlowPlayer player) {
tntBlock.setType(Material.AIR);
World world = tntBlock.getWorld();
- GlowTNTPrimed tnt = (GlowTNTPrimed) world
+ GlowTntPrimed tnt = (GlowTntPrimed) world
.spawnEntity(tntBlock.getLocation().add(0.5, 0, 0.5), EntityType.PRIMED_TNT);
+ tnt.setSource(player);
tnt.setIgnitedByExplosion(ignitedByExplosion);
world.playSound(tntBlock.getLocation(), Sound.ENTITY_TNT_PRIMED, 1, 1);
}
+ /**
+ * Convert a TNT block into a primed TNT entity.
+ *
+ * @param tntBlock The block to ignite.
+ * @param ignitedByExplosion True if another explosion caused this ignition.
+ */
+ public static void igniteBlock(Block tntBlock, boolean ignitedByExplosion) {
+ igniteBlock(tntBlock, ignitedByExplosion, null);
+ }
+
@Override
public void afterPlace(GlowPlayer player, GlowBlock block, ItemStack holding,
GlowBlockState oldState) {
@@ -43,7 +57,7 @@ public void onNearBlockChanged(GlowBlock block, BlockFace face, GlowBlock change
@Override
public void updatePhysics(GlowBlock me) {
if (me.isBlockIndirectlyPowered()) {
- igniteBlock(me, false);
+ igniteBlock(me, false, null);
}
}
diff --git a/src/main/java/net/glowstone/block/blocktype/BlockType.java b/src/main/java/net/glowstone/block/blocktype/BlockType.java
index a5377f4c49..fad2fc2175 100644
--- a/src/main/java/net/glowstone/block/blocktype/BlockType.java
+++ b/src/main/java/net/glowstone/block/blocktype/BlockType.java
@@ -4,6 +4,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import lombok.Getter;
import net.glowstone.EventFactory;
import net.glowstone.GlowServer;
import net.glowstone.block.GlowBlock;
@@ -43,6 +44,12 @@ public class BlockType extends ItemType {
protected List drops;
+ /**
+ * Gets the sound that will be played when a player places the block.
+ *
+ * @return The sound to be played
+ */
+ @Getter
protected SoundInfo placeSound = new SoundInfo(Sound.BLOCK_WOOD_BREAK, 1F, 0.75F);
////////////////////////////////////////////////////////////////////////////
@@ -109,15 +116,6 @@ public Collection getDrops(GlowBlock block, ItemStack tool) {
}
}
- /**
- * Gets the sound that will be played when a player places the block.
- *
- * @return The sound to be played
- */
- public SoundInfo getPlaceSound() {
- return placeSound;
- }
-
/**
* Sets the sound that will be played when a player places the block.
*
diff --git a/src/main/java/net/glowstone/block/blocktype/IBlockGrowable.java b/src/main/java/net/glowstone/block/blocktype/IBlockGrowable.java
index e11d4594fc..562d93704b 100644
--- a/src/main/java/net/glowstone/block/blocktype/IBlockGrowable.java
+++ b/src/main/java/net/glowstone/block/blocktype/IBlockGrowable.java
@@ -27,7 +27,8 @@ public interface IBlockGrowable {
/**
* Called to grow a growable block.
*
- * @param player the player who triggered the growth, this can be null if the growth is natural or by plugin source
+ * @param player the player who triggered the growth, this can be null if the growth is natural
+ * or by plugin source
* @param block the targeted block to grow
*/
void grow(GlowPlayer player, GlowBlock block);
diff --git a/src/main/java/net/glowstone/block/entity/BannerEntity.java b/src/main/java/net/glowstone/block/entity/BannerEntity.java
index 90f0af75a7..00ebb69a18 100644
--- a/src/main/java/net/glowstone/block/entity/BannerEntity.java
+++ b/src/main/java/net/glowstone/block/entity/BannerEntity.java
@@ -2,6 +2,8 @@
import java.util.ArrayList;
import java.util.List;
+import lombok.Getter;
+import lombok.Setter;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.GlowBlockState;
import net.glowstone.block.blocktype.BlockBanner;
@@ -15,6 +17,8 @@
public class BannerEntity extends BlockEntity {
+ @Getter
+ @Setter
private DyeColor base = DyeColor.WHITE;
private List patterns = new ArrayList<>();
@@ -56,19 +60,13 @@ public void update(GlowPlayer player) {
player.sendBlockEntityChange(getBlock().getLocation(), GlowBlockEntity.BANNER, nbt);
}
- public DyeColor getBase() {
- return base;
- }
-
- public void setBase(DyeColor base) {
- this.base = base;
- }
-
public List getPatterns() {
+ // TODO: Defensive copy?
return patterns;
}
public void setPatterns(List patterns) {
+ // TODO: Defensive copy
this.patterns = patterns;
}
}
diff --git a/src/main/java/net/glowstone/block/entity/BeaconEntity.java b/src/main/java/net/glowstone/block/entity/BeaconEntity.java
index bffa2d070c..357d269f4f 100644
--- a/src/main/java/net/glowstone/block/entity/BeaconEntity.java
+++ b/src/main/java/net/glowstone/block/entity/BeaconEntity.java
@@ -1,13 +1,21 @@
package net.glowstone.block.entity;
+import lombok.Getter;
+import lombok.Setter;
import net.glowstone.block.GlowBlock;
import net.glowstone.util.nbt.CompoundTag;
public class BeaconEntity extends BlockEntity {
private String lock = null; // todo: support item locks
+ @Getter
+ @Setter
private int levels = 0;
+ @Getter
+ @Setter
private int primaryId = 0;
+ @Getter
+ @Setter
private int secondaryId = 0;
public BeaconEntity(GlowBlock block) {
@@ -36,28 +44,4 @@ public void saveNbt(CompoundTag tag) {
tag.putInt("Primary", primaryId);
tag.putInt("Secondary", secondaryId);
}
-
- public int getLevels() {
- return levels;
- }
-
- public void setLevels(int levels) {
- this.levels = levels;
- }
-
- public int getPrimaryId() {
- return primaryId;
- }
-
- public void setPrimaryId(int primaryId) {
- this.primaryId = primaryId;
- }
-
- public int getSecondaryId() {
- return secondaryId;
- }
-
- public void setSecondaryId(int secondaryId) {
- this.secondaryId = secondaryId;
- }
}
diff --git a/src/main/java/net/glowstone/block/entity/BlockEntity.java b/src/main/java/net/glowstone/block/entity/BlockEntity.java
index a9022e4718..0ee0558ce4 100644
--- a/src/main/java/net/glowstone/block/entity/BlockEntity.java
+++ b/src/main/java/net/glowstone/block/entity/BlockEntity.java
@@ -1,12 +1,12 @@
package net.glowstone.block.entity;
+import lombok.Getter;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.GlowBlockState;
import net.glowstone.chunk.GlowChunk;
import net.glowstone.chunk.GlowChunk.Key;
import net.glowstone.entity.GlowPlayer;
import net.glowstone.util.nbt.CompoundTag;
-import org.bukkit.block.Block;
/**
* Base class for block entities (blocks with NBT data) in the world. Most access to block entities
@@ -14,6 +14,12 @@
*/
public abstract class BlockEntity {
+ /**
+ * Get the block this BlockEntity is associated with.
+ *
+ * @return The entity's block.
+ */
+ @Getter
protected final GlowBlock block;
private String saveId;
@@ -29,15 +35,6 @@ public BlockEntity(GlowBlock block) {
////////////////////////////////////////////////////////////////////////////
// Utility stuff
- /**
- * Get the block this BlockEntity is associated with.
- *
- * @return The entity's block.
- */
- public final Block getBlock() {
- return block;
- }
-
/**
* Update this BlockEntity's visible state to all players in range.
*/
diff --git a/src/main/java/net/glowstone/block/entity/BrewingStandEntity.java b/src/main/java/net/glowstone/block/entity/BrewingStandEntity.java
index 9de31c5234..1850d63d05 100644
--- a/src/main/java/net/glowstone/block/entity/BrewingStandEntity.java
+++ b/src/main/java/net/glowstone/block/entity/BrewingStandEntity.java
@@ -1,5 +1,7 @@
package net.glowstone.block.entity;
+import lombok.Getter;
+import lombok.Setter;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.GlowBlockState;
import net.glowstone.block.entity.state.GlowBrewingStand;
@@ -8,6 +10,8 @@
public class BrewingStandEntity extends ContainerEntity {
+ @Getter
+ @Setter
private int brewTime;
public BrewingStandEntity(GlowBlock block) {
@@ -15,14 +19,6 @@ public BrewingStandEntity(GlowBlock block) {
setSaveId("minecraft:brewing_stand");
}
- public int getBrewTime() {
- return brewTime;
- }
-
- public void setBrewTime(int brewTime) {
- this.brewTime = brewTime;
- }
-
@Override
public void loadNbt(CompoundTag tag) {
super.loadNbt(tag);
diff --git a/src/main/java/net/glowstone/block/entity/ContainerEntity.java b/src/main/java/net/glowstone/block/entity/ContainerEntity.java
index d31ba04398..21074c4169 100644
--- a/src/main/java/net/glowstone/block/entity/ContainerEntity.java
+++ b/src/main/java/net/glowstone/block/entity/ContainerEntity.java
@@ -1,11 +1,11 @@
package net.glowstone.block.entity;
+import lombok.Getter;
import net.glowstone.block.GlowBlock;
import net.glowstone.inventory.GlowInventory;
import net.glowstone.io.nbt.NbtSerialization;
import net.glowstone.util.nbt.CompoundTag;
import net.glowstone.util.nbt.TagType;
-import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
/**
@@ -13,6 +13,7 @@
*/
public abstract class ContainerEntity extends BlockEntity {
+ @Getter
private final GlowInventory inventory;
public ContainerEntity(GlowBlock block, GlowInventory inventory) {
@@ -20,10 +21,6 @@ public ContainerEntity(GlowBlock block, GlowInventory inventory) {
this.inventory = inventory;
}
- public Inventory getInventory() {
- return inventory;
- }
-
public void setContents(ItemStack... contents) {
inventory.setContents(contents);
}
diff --git a/src/main/java/net/glowstone/block/entity/FlowerPotEntity.java b/src/main/java/net/glowstone/block/entity/FlowerPotEntity.java
index f0ad571f10..75a2eab731 100644
--- a/src/main/java/net/glowstone/block/entity/FlowerPotEntity.java
+++ b/src/main/java/net/glowstone/block/entity/FlowerPotEntity.java
@@ -1,5 +1,7 @@
package net.glowstone.block.entity;
+import lombok.Getter;
+import lombok.Setter;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.GlowBlockState;
import net.glowstone.block.entity.state.GlowFlowerPot;
@@ -11,7 +13,8 @@
import org.bukkit.material.MaterialData;
public class FlowerPotEntity extends BlockEntity {
-
+ @Getter
+ @Setter
private MaterialData contents;
public FlowerPotEntity(GlowBlock block) {
@@ -19,14 +22,6 @@ public FlowerPotEntity(GlowBlock block) {
setSaveId("minecraft:flower_pot");
}
- public MaterialData getContents() {
- return contents;
- }
-
- public void setContents(MaterialData contents) {
- this.contents = contents;
- }
-
@Override
public void loadNbt(CompoundTag tag) {
super.loadNbt(tag);
diff --git a/src/main/java/net/glowstone/block/entity/FurnaceEntity.java b/src/main/java/net/glowstone/block/entity/FurnaceEntity.java
index 5fec20e047..8e467c4c76 100644
--- a/src/main/java/net/glowstone/block/entity/FurnaceEntity.java
+++ b/src/main/java/net/glowstone/block/entity/FurnaceEntity.java
@@ -1,5 +1,7 @@
package net.glowstone.block.entity;
+import lombok.Getter;
+import lombok.Setter;
import net.glowstone.EventFactory;
import net.glowstone.GlowServer;
import net.glowstone.block.GlowBlock;
@@ -20,7 +22,11 @@
public class FurnaceEntity extends ContainerEntity {
+ @Getter
+ @Setter
private short burnTime;
+ @Getter
+ @Setter
private short cookTime;
private short burnTimeFuel;
@@ -59,22 +65,6 @@ public void loadNbt(CompoundTag tag) {
}
}
- public short getBurnTime() {
- return burnTime;
- }
-
- public void setBurnTime(short burnTime) {
- this.burnTime = burnTime;
- }
-
- public short getCookTime() {
- return cookTime;
- }
-
- public void setCookTime(short cookTime) {
- this.cookTime = cookTime;
- }
-
/**
* Advances the cooking process for the tick.
*/
diff --git a/src/main/java/net/glowstone/block/entity/JukeboxEntity.java b/src/main/java/net/glowstone/block/entity/JukeboxEntity.java
index 155477f75c..d72443eb69 100644
--- a/src/main/java/net/glowstone/block/entity/JukeboxEntity.java
+++ b/src/main/java/net/glowstone/block/entity/JukeboxEntity.java
@@ -1,5 +1,7 @@
package net.glowstone.block.entity;
+import lombok.Getter;
+import lombok.Setter;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.GlowBlockState;
import net.glowstone.block.entity.state.GlowJukebox;
@@ -9,6 +11,8 @@
public class JukeboxEntity extends BlockEntity {
+ @Getter
+ @Setter
private ItemStack playing;
public JukeboxEntity(GlowBlock block) {
@@ -34,12 +38,4 @@ public void saveNbt(CompoundTag tag) {
public GlowBlockState getState() {
return new GlowJukebox(block);
}
-
- public ItemStack getPlaying() {
- return playing;
- }
-
- public void setPlaying(ItemStack playing) {
- this.playing = playing;
- }
}
diff --git a/src/main/java/net/glowstone/block/entity/MobSpawnerEntity.java b/src/main/java/net/glowstone/block/entity/MobSpawnerEntity.java
index 7080d3269c..f37d0cc3a6 100644
--- a/src/main/java/net/glowstone/block/entity/MobSpawnerEntity.java
+++ b/src/main/java/net/glowstone/block/entity/MobSpawnerEntity.java
@@ -1,5 +1,7 @@
package net.glowstone.block.entity;
+import lombok.Getter;
+import lombok.Setter;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.GlowBlockState;
import net.glowstone.block.entity.state.GlowCreatureSpawner;
@@ -10,7 +12,11 @@ public class MobSpawnerEntity extends BlockEntity {
private static final EntityType DEFAULT = EntityType.PIG;
+ @Getter
+ @Setter
private EntityType spawning;
+ @Getter
+ @Setter
private int delay;
public MobSpawnerEntity(GlowBlock block) {
@@ -38,31 +44,15 @@ public void loadNbt(CompoundTag tag) {
}
}
- @Override
- public void saveNbt(CompoundTag tag) {
- super.saveNbt(tag);
- tag.putString("EntityId", spawning == null ? "" : spawning.getName());
- tag.putInt("Delay", delay);
- }
-
@Override
public GlowBlockState getState() {
return new GlowCreatureSpawner(block);
}
- public EntityType getSpawning() {
- return spawning;
- }
-
- public void setSpawning(EntityType spawning) {
- this.spawning = spawning;
- }
-
- public int getDelay() {
- return delay;
- }
-
- public void setDelay(int delay) {
- this.delay = delay;
+ @Override
+ public void saveNbt(CompoundTag tag) {
+ super.saveNbt(tag);
+ tag.putString("EntityId", spawning == null ? "" : spawning.getName());
+ tag.putInt("Delay", delay);
}
}
diff --git a/src/main/java/net/glowstone/block/entity/NoteblockEntity.java b/src/main/java/net/glowstone/block/entity/NoteblockEntity.java
index e9a4aaeb1e..f7a38b9fd5 100644
--- a/src/main/java/net/glowstone/block/entity/NoteblockEntity.java
+++ b/src/main/java/net/glowstone/block/entity/NoteblockEntity.java
@@ -1,5 +1,7 @@
package net.glowstone.block.entity;
+import lombok.Getter;
+import lombok.Setter;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.GlowBlockState;
import net.glowstone.block.entity.state.GlowNoteBlock;
@@ -8,6 +10,8 @@
public class NoteblockEntity extends BlockEntity {
+ @Getter
+ @Setter
private Note note = new Note(0);
public NoteblockEntity(GlowBlock block) {
@@ -31,12 +35,4 @@ public void saveNbt(CompoundTag tag) {
public GlowBlockState getState() {
return new GlowNoteBlock(block);
}
-
- public Note getNote() {
- return note;
- }
-
- public void setNote(Note note) {
- this.note = note;
- }
}
diff --git a/src/main/java/net/glowstone/block/entity/SignEntity.java b/src/main/java/net/glowstone/block/entity/SignEntity.java
index 09fd1afbfe..29165c1d3f 100644
--- a/src/main/java/net/glowstone/block/entity/SignEntity.java
+++ b/src/main/java/net/glowstone/block/entity/SignEntity.java
@@ -13,6 +13,11 @@ public class SignEntity extends BlockEntity {
private final TextMessage[] lines = new TextMessage[4];
+ /**
+ * Creates the entity for the given sign block.
+ *
+ * @param block a sign block (wall or post)
+ */
public SignEntity(GlowBlock block) {
super(block);
setSaveId("minecraft:sign");
diff --git a/src/main/java/net/glowstone/block/entity/SkullEntity.java b/src/main/java/net/glowstone/block/entity/SkullEntity.java
index a6e17cd5ea..82dd7999de 100644
--- a/src/main/java/net/glowstone/block/entity/SkullEntity.java
+++ b/src/main/java/net/glowstone/block/entity/SkullEntity.java
@@ -1,5 +1,7 @@
package net.glowstone.block.entity;
+import lombok.Getter;
+import lombok.Setter;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.GlowBlockState;
import net.glowstone.block.blocktype.BlockSkull;
@@ -13,8 +15,13 @@
public class SkullEntity extends BlockEntity {
+ @Getter
+ @Setter
private byte type;
+ @Getter
+ @Setter
private byte rotation;
+ @Getter
private PlayerProfile owner;
public SkullEntity(GlowBlock block) {
@@ -32,7 +39,7 @@ public void loadNbt(CompoundTag tag) {
}
if (tag.containsKey("Owner")) {
CompoundTag ownerTag = tag.getCompound("Owner");
- owner = PlayerProfile.fromNBT(ownerTag).join();
+ owner = PlayerProfile.fromNbt(ownerTag).join();
} else if (tag.containsKey("ExtraType")) {
// Pre-1.8 uses just a name, instead of a profile object
String name = tag.getString("ExtraType");
@@ -50,7 +57,7 @@ public void saveNbt(CompoundTag tag) {
tag.putByte("Rot", rotation);
}
if (type == BlockSkull.getType(SkullType.PLAYER) && owner != null) {
- tag.putCompound("Owner", owner.toNBT());
+ tag.putCompound("Owner", owner.toNbt());
}
}
@@ -67,26 +74,6 @@ public void update(GlowPlayer player) {
player.sendBlockEntityChange(getBlock().getLocation(), GlowBlockEntity.SKULL, nbt);
}
- public byte getType() {
- return type;
- }
-
- public void setType(byte type) {
- this.type = type;
- }
-
- public byte getRotation() {
- return rotation;
- }
-
- public void setRotation(byte rotation) {
- this.rotation = rotation;
- }
-
- public PlayerProfile getOwner() {
- return owner;
- }
-
public void setOwner(PlayerProfile owner) {
this.owner = owner;
type = BlockSkull.getType(SkullType.PLAYER);
diff --git a/src/main/java/net/glowstone/block/entity/state/GlowBanner.java b/src/main/java/net/glowstone/block/entity/state/GlowBanner.java
index 388de37bb0..d044ea56b6 100644
--- a/src/main/java/net/glowstone/block/entity/state/GlowBanner.java
+++ b/src/main/java/net/glowstone/block/entity/state/GlowBanner.java
@@ -3,6 +3,7 @@
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.List;
+import lombok.Getter;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.GlowBlockState;
import net.glowstone.block.entity.BannerEntity;
@@ -12,7 +13,8 @@
public class GlowBanner extends GlowBlockState implements Banner {
- private DyeColor base;
+ @Getter
+ private DyeColor baseColor;
private List patterns;
/**
@@ -22,7 +24,7 @@ public class GlowBanner extends GlowBlockState implements Banner {
*/
public GlowBanner(GlowBlock block) {
super(block);
- base = getBlockEntity().getBase();
+ baseColor = getBlockEntity().getBase();
patterns = getBlockEntity().getPatterns();
}
@@ -41,24 +43,21 @@ public int numberOfPatterns() {
return patterns.size();
}
- @Override
- public DyeColor getBaseColor() {
- return base;
- }
-
@Override
public void setBaseColor(DyeColor dyeColor) {
- checkNotNull(base, "Base cannot be null");
- base = dyeColor;
+ checkNotNull(baseColor, "Base cannot be null");
+ baseColor = dyeColor;
}
@Override
public List getPatterns() {
+ // TODO: Defensive copy
return patterns;
}
@Override
public void setPatterns(List patterns) {
+ // TODO: Defensive copy
this.patterns = patterns;
}
@@ -83,7 +82,7 @@ public boolean update(boolean force, boolean applyPhysics) {
boolean result = super.update(force, applyPhysics);
if (result) {
BannerEntity banner = getBlockEntity();
- banner.setBase(base);
+ banner.setBase(baseColor);
banner.setPatterns(patterns);
getBlockEntity().updateInRange();
}
diff --git a/src/main/java/net/glowstone/block/entity/state/GlowBeacon.java b/src/main/java/net/glowstone/block/entity/state/GlowBeacon.java
index 45f7299037..6cf6dc7ee2 100644
--- a/src/main/java/net/glowstone/block/entity/state/GlowBeacon.java
+++ b/src/main/java/net/glowstone/block/entity/state/GlowBeacon.java
@@ -2,6 +2,7 @@
import java.util.Collection;
import java.util.Collections;
+import lombok.Getter;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.entity.BeaconEntity;
import org.bukkit.block.Beacon;
@@ -12,7 +13,9 @@
public class GlowBeacon extends GlowContainer implements Beacon {
+ @Getter
private PotionEffect primaryEffect;
+ @Getter
private PotionEffect secondaryEffect;
/**
@@ -44,22 +47,12 @@ public int getTier() {
return getBlockEntity().getLevels();
}
- @Override
- public PotionEffect getPrimaryEffect() {
- return primaryEffect;
- }
-
@Override
public void setPrimaryEffect(PotionEffectType primary) {
this.primaryEffect = new PotionEffect(primary, 7, getTier(), true);
getBlockEntity().setPrimaryId(primary.getId());
}
- @Override
- public PotionEffect getSecondaryEffect() {
- return secondaryEffect;
- }
-
@Override
public void setSecondaryEffect(PotionEffectType secondary) {
this.secondaryEffect = new PotionEffect(secondary, 7, getTier(), true);
diff --git a/src/main/java/net/glowstone/block/entity/state/GlowBed.java b/src/main/java/net/glowstone/block/entity/state/GlowBed.java
index 9edda88d0f..d933efc486 100644
--- a/src/main/java/net/glowstone/block/entity/state/GlowBed.java
+++ b/src/main/java/net/glowstone/block/entity/state/GlowBed.java
@@ -1,5 +1,7 @@
package net.glowstone.block.entity.state;
+import lombok.Getter;
+import lombok.Setter;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.GlowBlockState;
import net.glowstone.block.entity.BedEntity;
@@ -8,6 +10,8 @@
public class GlowBed extends GlowBlockState implements Bed {
+ @Getter
+ @Setter
private DyeColor color;
public GlowBed(GlowBlock block) {
@@ -19,16 +23,6 @@ public BedEntity getBlockEntity() {
return (BedEntity) getBlock().getBlockEntity();
}
- @Override
- public DyeColor getColor() {
- return color;
- }
-
- @Override
- public void setColor(DyeColor color) {
- this.color = color;
- }
-
@Override
public boolean update(boolean force, boolean applyPhysics) {
boolean result = super.update(force, applyPhysics);
diff --git a/src/main/java/net/glowstone/block/entity/state/GlowBrewingStand.java b/src/main/java/net/glowstone/block/entity/state/GlowBrewingStand.java
index 49c80dbefe..6d2cbcc3a1 100644
--- a/src/main/java/net/glowstone/block/entity/state/GlowBrewingStand.java
+++ b/src/main/java/net/glowstone/block/entity/state/GlowBrewingStand.java
@@ -1,5 +1,7 @@
package net.glowstone.block.entity.state;
+import lombok.Getter;
+import lombok.Setter;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.entity.BrewingStandEntity;
import org.bukkit.block.BrewingStand;
@@ -7,42 +9,27 @@
public class GlowBrewingStand extends GlowContainer implements BrewingStand {
- private int brewTime;
+ @Getter
+ @Setter
+ private int brewingTime;
+ @Getter
+ @Setter
+ private int fuelLevel;
public GlowBrewingStand(GlowBlock block) {
super(block);
- brewTime = getBlockEntity().getBrewTime();
+ brewingTime = getBlockEntity().getBrewTime();
}
public GlowBrewingStand(GlowBlock block, int brewTime) {
super(block);
- this.brewTime = brewTime;
+ this.brewingTime = brewTime;
}
private BrewingStandEntity getBlockEntity() {
return (BrewingStandEntity) getBlock().getBlockEntity();
}
- @Override
- public int getBrewingTime() {
- return brewTime;
- }
-
- @Override
- public void setBrewingTime(int brewTime) {
- this.brewTime = brewTime;
- }
-
- @Override
- public int getFuelLevel() {
- return 0;
- }
-
- @Override
- public void setFuelLevel(int i) {
-
- }
-
@Override
public BrewerInventory getInventory() {
return (BrewerInventory) getBlockEntity().getInventory();
@@ -53,7 +40,7 @@ public boolean update(boolean force, boolean applyPhysics) {
boolean result = super.update(force, applyPhysics);
if (result) {
BrewingStandEntity stand = getBlockEntity();
- stand.setBrewTime(brewTime);
+ stand.setBrewTime(brewingTime);
stand.updateInRange();
}
return result;
diff --git a/src/main/java/net/glowstone/block/entity/state/GlowContainer.java b/src/main/java/net/glowstone/block/entity/state/GlowContainer.java
index a43f7f792d..40103673e9 100644
--- a/src/main/java/net/glowstone/block/entity/state/GlowContainer.java
+++ b/src/main/java/net/glowstone/block/entity/state/GlowContainer.java
@@ -1,7 +1,13 @@
package net.glowstone.block.entity.state;
import com.destroystokyo.paper.loottable.LootableBlockInventory;
+import java.util.Map;
import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.AtomicReference;
+import lombok.Getter;
+import lombok.Setter;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.GlowBlockState;
import org.bukkit.Nameable;
@@ -11,6 +17,17 @@
public abstract class GlowContainer extends GlowBlockState implements LootableBlockInventory,
Lockable, Nameable, Container {
+ private final AtomicLong lastFilled = new AtomicLong(-1);
+ private final AtomicLong nextRefill = new AtomicLong(-1);
+ private final AtomicLong lootTableSeed = new AtomicLong(0);
+ private final AtomicReference lootTable = new AtomicReference<>(null);
+ private final Map playersWhoHaveLooted = new ConcurrentHashMap<>();
+ @Getter
+ @Setter
+ private String lock;
+ @Getter
+ @Setter
+ private String customName;
public GlowContainer(GlowBlock block) {
super(block);
@@ -20,111 +37,96 @@ public GlowContainer(GlowBlock block) {
@Override
public String getLootTableName() {
- return null;
+ return lootTable.get();
}
@Override
public boolean hasLootTable() {
- return false;
+ return lootTable.get() != null;
}
@Override
public String setLootTable(String name) {
- return null;
+ return setLootTable(name, 0);
}
@Override
- public String setLootTable(String s, long l) {
- return null;
+ public String setLootTable(String name, long seed) {
+ setLootTableSeed(seed);
+ return lootTable.getAndSet(name);
}
@Override
public long getLootTableSeed() {
- return 0;
+ return lootTableSeed.get();
}
@Override
public long setLootTableSeed(long seed) {
- return 0;
+ return lootTableSeed.getAndSet(seed);
}
@Override
public void clearLootTable() {
-
+ setLootTable(null);
}
@Override
public boolean isRefillEnabled() {
+ // TODO
return false;
}
@Override
public boolean hasBeenFilled() {
- return false;
+ return lastFilled.get() >= 0;
}
@Override
public boolean hasPlayerLooted(UUID uuid) {
- return false;
+ return playersWhoHaveLooted.containsKey(uuid);
}
@Override
public Long getLastLooted(UUID uuid) {
- return null;
+ return playersWhoHaveLooted.get(uuid);
}
@Override
public boolean setHasPlayerLooted(UUID uuid, boolean b) {
- return false;
+ return b
+ ? playersWhoHaveLooted.put(uuid, getWorld().getFullTime()) != null
+ : playersWhoHaveLooted.remove(uuid) != null;
}
@Override
public boolean hasPendingRefill() {
- return false;
+ return getNextRefill() >= Math.max(0, getLastFilled());
}
@Override
public long getLastFilled() {
- return 0;
+ return lastFilled.get();
}
@Override
public long getNextRefill() {
- return 0;
+ return nextRefill.get();
}
@Override
public long setNextRefill(long l) {
- return 0;
- }
-
- @Override
- public String getCustomName() {
- return null;
- }
-
- @Override
- public void setCustomName(String s) {
-
+ return nextRefill.getAndSet(l);
}
@Override
public boolean isLocked() {
- return false;
- }
-
- @Override
- public String getLock() {
- return null;
- }
-
- @Override
- public void setLock(String s) {
-
+ return getLock() != null;
}
@Override
public Inventory getSnapshotInventory() {
+ // TODO
throw new UnsupportedOperationException();
}
}
diff --git a/src/main/java/net/glowstone/block/entity/state/GlowCreatureSpawner.java b/src/main/java/net/glowstone/block/entity/state/GlowCreatureSpawner.java
index 5bf0f98799..141579ed81 100644
--- a/src/main/java/net/glowstone/block/entity/state/GlowCreatureSpawner.java
+++ b/src/main/java/net/glowstone/block/entity/state/GlowCreatureSpawner.java
@@ -1,5 +1,7 @@
package net.glowstone.block.entity.state;
+import lombok.Getter;
+import lombok.Setter;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.GlowBlockState;
import net.glowstone.block.entity.MobSpawnerEntity;
@@ -8,7 +10,10 @@
public class GlowCreatureSpawner extends GlowBlockState implements CreatureSpawner {
- private EntityType spawned;
+ @Getter
+ @Setter
+ private EntityType spawnedType;
+ @Getter
private int delay;
/**
@@ -20,7 +25,7 @@ public GlowCreatureSpawner(GlowBlock block) {
super(block);
MobSpawnerEntity spawner = getBlockEntity();
- spawned = spawner.getSpawning();
+ spawnedType = spawner.getSpawning();
delay = spawner.getDelay();
}
@@ -33,18 +38,13 @@ public boolean update(boolean force, boolean applyPhysics) {
boolean result = super.update(force, applyPhysics);
if (result) {
MobSpawnerEntity spawner = getBlockEntity();
- spawner.setSpawning(spawned);
+ spawner.setSpawning(spawnedType);
spawner.setDelay(delay);
spawner.updateInRange();
}
return result;
}
- @Override
- public int getDelay() {
- return delay;
- }
-
@Override
public void setDelay(int i) {
if (i < 0) {
@@ -56,27 +56,17 @@ public void setDelay(int i) {
////////////////////////////////////////////////////////////////////////////
// Spawned Type
- @Override
- public EntityType getSpawnedType() {
- return spawned;
- }
-
- @Override
- public void setSpawnedType(EntityType creatureType) {
- spawned = creatureType;
- }
-
@Override
public void setCreatureTypeByName(String creatureType) {
EntityType type = EntityType.fromName(creatureType);
if (type != null) {
- spawned = type;
+ spawnedType = type;
}
}
@Override
public String getCreatureTypeName() {
- return spawned.getName();
+ return spawnedType.getName();
}
}
diff --git a/src/main/java/net/glowstone/block/entity/state/GlowDispenser.java b/src/main/java/net/glowstone/block/entity/state/GlowDispenser.java
index bd543458a9..22356e1789 100644
--- a/src/main/java/net/glowstone/block/entity/state/GlowDispenser.java
+++ b/src/main/java/net/glowstone/block/entity/state/GlowDispenser.java
@@ -2,6 +2,7 @@
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
+import lombok.Getter;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.entity.DispenserEntity;
import net.glowstone.dispenser.ArmorDispenseBehavior;
@@ -11,7 +12,7 @@
import net.glowstone.dispenser.DispenseBehaviorRegistry;
import net.glowstone.dispenser.EmptyBucketDispenseBehavior;
import net.glowstone.dispenser.FlintAndSteelDispenseBehavior;
-import net.glowstone.dispenser.TNTDispenseBehavior;
+import net.glowstone.dispenser.TntDispenseBehavior;
import net.glowstone.util.InventoryUtil;
import org.bukkit.Effect;
import org.bukkit.Material;
@@ -24,6 +25,7 @@
public class GlowDispenser extends GlowContainer implements Dispenser, BlockProjectileSource {
+ @Getter
private static final DispenseBehaviorRegistry dispenseBehaviorRegistry =
new DispenseBehaviorRegistry();
@@ -31,10 +33,6 @@ public GlowDispenser(GlowBlock block) {
super(block);
}
- public static DispenseBehaviorRegistry getDispenseBehaviorRegistry() {
- return dispenseBehaviorRegistry;
- }
-
/**
* Registers all vanilla dispense behaviors.
*/
@@ -47,7 +45,7 @@ public static void register() {
.putBehavior(Material.BUCKET, new EmptyBucketDispenseBehavior());
getDispenseBehaviorRegistry()
.putBehavior(Material.FLINT_AND_STEEL, new FlintAndSteelDispenseBehavior());
- getDispenseBehaviorRegistry().putBehavior(Material.TNT, new TNTDispenseBehavior());
+ getDispenseBehaviorRegistry().putBehavior(Material.TNT, new TntDispenseBehavior());
ArmorDispenseBehavior armorDispenseBehavior = new ArmorDispenseBehavior();
getDispenseBehaviorRegistry().putBehavior(Material.LEATHER_BOOTS, armorDispenseBehavior);
diff --git a/src/main/java/net/glowstone/block/entity/state/GlowFlowerPot.java b/src/main/java/net/glowstone/block/entity/state/GlowFlowerPot.java
index ab071618b1..30cb0e1fb9 100644
--- a/src/main/java/net/glowstone/block/entity/state/GlowFlowerPot.java
+++ b/src/main/java/net/glowstone/block/entity/state/GlowFlowerPot.java
@@ -1,5 +1,7 @@
package net.glowstone.block.entity.state;
+import lombok.Getter;
+import lombok.Setter;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.GlowBlockState;
import net.glowstone.block.entity.FlowerPotEntity;
@@ -8,6 +10,8 @@
public class GlowFlowerPot extends GlowBlockState implements FlowerPot {
+ @Getter
+ @Setter
private MaterialData contents;
/**
@@ -33,16 +37,6 @@ private boolean hasFlowerPotData() {
return getData() instanceof org.bukkit.material.FlowerPot;
}
- @Override
- public MaterialData getContents() {
- return contents;
- }
-
- @Override
- public void setContents(MaterialData contents) {
- this.contents = contents;
- }
-
@Override
public boolean update(boolean force, boolean applyPhysics) {
// Pre-1.7 uses block data.
diff --git a/src/main/java/net/glowstone/block/entity/state/GlowFurnace.java b/src/main/java/net/glowstone/block/entity/state/GlowFurnace.java
index 24a3cf53cb..be7ad37bcd 100644
--- a/src/main/java/net/glowstone/block/entity/state/GlowFurnace.java
+++ b/src/main/java/net/glowstone/block/entity/state/GlowFurnace.java
@@ -1,5 +1,7 @@
package net.glowstone.block.entity.state;
+import lombok.Getter;
+import lombok.Setter;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.entity.FurnaceEntity;
import org.bukkit.block.Furnace;
@@ -7,7 +9,11 @@
public class GlowFurnace extends GlowContainer implements Furnace {
+ @Getter
+ @Setter
private short burnTime;
+ @Getter
+ @Setter
private short cookTime;
/**
@@ -40,26 +46,6 @@ private FurnaceEntity getBlockEntity() {
return (FurnaceEntity) getBlock().getBlockEntity();
}
- @Override
- public short getBurnTime() {
- return burnTime;
- }
-
- @Override
- public void setBurnTime(short burnTime) {
- this.burnTime = burnTime;
- }
-
- @Override
- public short getCookTime() {
- return cookTime;
- }
-
- @Override
- public void setCookTime(short cookTime) {
- this.cookTime = cookTime;
- }
-
@Override
public FurnaceInventory getInventory() {
return (FurnaceInventory) getBlockEntity().getInventory();
diff --git a/src/main/java/net/glowstone/block/entity/state/GlowJukebox.java b/src/main/java/net/glowstone/block/entity/state/GlowJukebox.java
index 5746d7be09..587942e95b 100644
--- a/src/main/java/net/glowstone/block/entity/state/GlowJukebox.java
+++ b/src/main/java/net/glowstone/block/entity/state/GlowJukebox.java
@@ -1,6 +1,7 @@
package net.glowstone.block.entity.state;
import java.util.Collection;
+import lombok.Getter;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.GlowBlockState;
import net.glowstone.block.entity.JukeboxEntity;
@@ -12,7 +13,8 @@
public class GlowJukebox extends GlowBlockState implements Jukebox {
- private ItemStack playing;
+ @Getter
+ private ItemStack playingItem;
/**
* Creates a block state for the given jukebox block.
@@ -25,7 +27,7 @@ public GlowJukebox(GlowBlock block) {
throw new IllegalArgumentException(
"GlowJukebox: expected JUKEBOX, got " + block.getType());
}
- playing = getBlockEntity().getPlaying();
+ playingItem = getBlockEntity().getPlaying();
}
private JukeboxEntity getBlockEntity() {
@@ -36,21 +38,17 @@ private JukeboxEntity getBlockEntity() {
public boolean update(boolean force, boolean applyPhysics) {
boolean result = super.update(force, applyPhysics);
if (result) {
- getBlockEntity().setPlaying(playing);
+ getBlockEntity().setPlaying(playingItem);
}
return result;
}
- public ItemStack getPlayingItem() {
- return playing;
- }
-
////////////////////////////////////////////////////////////////////////////
// Implementation
@Override
public Material getPlaying() {
- return playing.getType();
+ return playingItem.getType();
}
@Override
@@ -62,9 +60,9 @@ public boolean isPlaying() {
public void setPlaying(Material record) {
int id = 0;
if (record == null || record == Material.AIR) {
- playing = null;
+ playingItem = null;
} else {
- playing = new ItemStack(record);
+ playingItem = new ItemStack(record);
id = record.getId();
}
Collection players = getWorld().getRawPlayers();
@@ -77,7 +75,7 @@ public void setPlaying(Material record) {
@Override
public boolean eject() {
if (isPlaying()) {
- getWorld().dropItemNaturally(getLocation(), playing);
+ getWorld().dropItemNaturally(getLocation(), playingItem);
setPlaying(null);
return true;
}
diff --git a/src/main/java/net/glowstone/block/entity/state/GlowNoteBlock.java b/src/main/java/net/glowstone/block/entity/state/GlowNoteBlock.java
index 437d1054a8..2cfee90a33 100644
--- a/src/main/java/net/glowstone/block/entity/state/GlowNoteBlock.java
+++ b/src/main/java/net/glowstone/block/entity/state/GlowNoteBlock.java
@@ -2,6 +2,7 @@
import static com.google.common.base.Preconditions.checkNotNull;
+import lombok.Getter;
import net.glowstone.EventFactory;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.GlowBlockState;
@@ -18,8 +19,14 @@
public class GlowNoteBlock extends GlowBlockState implements NoteBlock {
+ @Getter
private Note note;
+ /**
+ * Creates the instance for a note block.
+ *
+ * @param block the note block
+ */
public GlowNoteBlock(GlowBlock block) {
super(block);
if (block.getType() != Material.NOTE_BLOCK) {
@@ -152,11 +159,6 @@ public boolean update(boolean force, boolean applyPhysics) {
return result;
}
- @Override
- public Note getNote() {
- return note;
- }
-
@Override
public void setNote(Note note) {
checkNotNull(note);
diff --git a/src/main/java/net/glowstone/block/entity/state/GlowSign.java b/src/main/java/net/glowstone/block/entity/state/GlowSign.java
index 763c1137c0..9aa6d0738f 100644
--- a/src/main/java/net/glowstone/block/entity/state/GlowSign.java
+++ b/src/main/java/net/glowstone/block/entity/state/GlowSign.java
@@ -10,6 +10,11 @@ public class GlowSign extends GlowBlockState implements Sign {
private final String[] lines;
+ /**
+ * Creates the instance for the given sign block.
+ *
+ * @param block a sign block (wall or post)
+ */
public GlowSign(GlowBlock block) {
super(block);
if (block.getType() != Material.WALL_SIGN && block.getType() != Material.SIGN_POST) {
@@ -25,7 +30,7 @@ private SignEntity getBlockEntity() {
@Override
public String[] getLines() {
- return lines;
+ return lines.clone();
}
@Override
diff --git a/src/main/java/net/glowstone/block/entity/state/GlowSkull.java b/src/main/java/net/glowstone/block/entity/state/GlowSkull.java
index e8ccdabfab..0fe8a2bebb 100644
--- a/src/main/java/net/glowstone/block/entity/state/GlowSkull.java
+++ b/src/main/java/net/glowstone/block/entity/state/GlowSkull.java
@@ -1,5 +1,7 @@
package net.glowstone.block.entity.state;
+import lombok.Getter;
+import lombok.Setter;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.GlowBlockState;
import net.glowstone.block.blocktype.BlockSkull;
@@ -14,13 +16,21 @@
public class GlowSkull extends GlowBlockState implements Skull {
- private SkullType type;
+ @Getter
+ private SkullType skullType;
private PlayerProfile owner;
+ @Getter
+ @Setter
private BlockFace rotation;
+ /**
+ * Creates the instance for the given block.
+ *
+ * @param block a head/skull block
+ */
public GlowSkull(GlowBlock block) {
super(block);
- type = BlockSkull.getType(getBlockEntity().getType());
+ skullType = BlockSkull.getType(getBlockEntity().getType());
rotation = Position.getDirection(getBlockEntity().getRotation());
owner = getBlockEntity().getOwner();
}
@@ -34,11 +44,11 @@ public boolean update(boolean force, boolean applyPhysics) {
boolean result = super.update(force, applyPhysics);
if (result) {
SkullEntity skull = getBlockEntity();
- skull.setType(BlockSkull.getType(type));
+ skull.setType(BlockSkull.getType(skullType));
if (BlockSkull.canRotate((org.bukkit.material.Skull) getBlock().getState().getData())) {
skull.setRotation(Position.getDirection(rotation));
}
- if (type == SkullType.PLAYER) {
+ if (skullType == SkullType.PLAYER) {
skull.setOwner(owner);
}
getBlockEntity().updateInRange();
@@ -77,26 +87,11 @@ public void setOwningPlayer(OfflinePlayer offlinePlayer) {
this.owner = new PlayerProfile(offlinePlayer.getName(), offlinePlayer.getUniqueId());
}
- @Override
- public BlockFace getRotation() {
- return rotation;
- }
-
- @Override
- public void setRotation(BlockFace rotation) {
- this.rotation = rotation;
- }
-
- @Override
- public SkullType getSkullType() {
- return type;
- }
-
@Override
public void setSkullType(SkullType type) {
if (type != SkullType.PLAYER) {
owner = null;
}
- this.type = type;
+ this.skullType = type;
}
}
diff --git a/src/main/java/net/glowstone/block/itemtype/ItemBoat.java b/src/main/java/net/glowstone/block/itemtype/ItemBoat.java
index 670052eda2..04657d93af 100644
--- a/src/main/java/net/glowstone/block/itemtype/ItemBoat.java
+++ b/src/main/java/net/glowstone/block/itemtype/ItemBoat.java
@@ -28,15 +28,19 @@ public void rightClickAir(GlowPlayer player, ItemStack holding) {
}
@Override
- public void rightClickBlock(GlowPlayer player, GlowBlock target, BlockFace face, ItemStack holding, Vector clickedLoc, EquipmentSlot hand) {
- // Two cases are handled here: Either the player clicked on a block on the land or beneath water
+ public void rightClickBlock(
+ GlowPlayer player, GlowBlock target, BlockFace face, ItemStack holding,
+ Vector clickedLoc, EquipmentSlot hand) {
+ // Two cases are handled here: Either the player clicked on a block on the land or beneath
+ // water
placeBoat(player);
}
private void placeBoat(GlowPlayer player) {
Block targetBlock = player.getTargetBlock((Set) null, 5);
- if (targetBlock != null && !targetBlock.isEmpty() && targetBlock.getRelative(BlockFace.UP).isEmpty()) {
+ if (targetBlock != null && !targetBlock.isEmpty()
+ && targetBlock.getRelative(BlockFace.UP).isEmpty()) {
Location location = targetBlock.getRelative(BlockFace.UP).getLocation();
// center boat on cursor location
location.add(0.6875f, 0, 0.6875f);
diff --git a/src/main/java/net/glowstone/block/itemtype/ItemBucket.java b/src/main/java/net/glowstone/block/itemtype/ItemBucket.java
index 28d2f23b36..febe943240 100644
--- a/src/main/java/net/glowstone/block/itemtype/ItemBucket.java
+++ b/src/main/java/net/glowstone/block/itemtype/ItemBucket.java
@@ -35,7 +35,9 @@ public void rightClickAir(GlowPlayer player, ItemStack holding) {
}
@Override
- public void rightClickBlock(GlowPlayer player, GlowBlock target, BlockFace face, ItemStack holding, Vector clickedLoc, EquipmentSlot hand) {
+ public void rightClickBlock(
+ GlowPlayer player, GlowBlock target, BlockFace face, ItemStack holding,
+ Vector clickedLoc, EquipmentSlot hand) {
clickBucket(player, holding);
}
@@ -47,7 +49,8 @@ private void clickBucket(GlowPlayer player, ItemStack holding) {
BlockType targetBlockType = null;
boolean validTarget = false;
- // Find the next available non-air liquid block type which is collectible in a radius of 5 blocks
+ // Find the next available non-air liquid block type which is collectible in a radius of 5
+ // blocks
while (itr.hasNext()) {
previousTarget = target;
target = itr.next();
diff --git a/src/main/java/net/glowstone/block/itemtype/ItemChorusFruit.java b/src/main/java/net/glowstone/block/itemtype/ItemChorusFruit.java
index 70999bb7ff..34c5e5ac10 100644
--- a/src/main/java/net/glowstone/block/itemtype/ItemChorusFruit.java
+++ b/src/main/java/net/glowstone/block/itemtype/ItemChorusFruit.java
@@ -43,32 +43,32 @@ public boolean eat(GlowPlayer player, ItemStack item) {
}
private Location getSafeLocation(Location loc) {
- int yCoord = loc.getBlockY();
+ int blockY = loc.getBlockY();
World world = loc.getWorld();
- if (yCoord > world.getHighestBlockYAt(loc)) {
- yCoord = world.getHighestBlockYAt(loc) + 1;
+ if (blockY > world.getHighestBlockYAt(loc)) {
+ blockY = world.getHighestBlockYAt(loc) + 1;
}
boolean found = false;
boolean hadSpace = false;
- while (yCoord > 0) {
- Block current = world.getBlockAt(loc.getBlockX(), yCoord, loc.getBlockZ());
+ while (blockY > 0) {
+ Block current = world.getBlockAt(loc.getBlockX(), blockY, loc.getBlockZ());
if (current.isEmpty() && current.getRelative(BlockFace.UP).isEmpty()) {
hadSpace = true;
} else if (hadSpace) {
if (current.getType().isSolid()) {
found = true;
- yCoord++;
+ blockY++;
break;
} else {
hadSpace = false;
}
}
- yCoord--;
+ blockY--;
}
if (found) {
- loc.setY(yCoord);
- loc.setX(loc.getBlockX()
- + 0.5); //TODO: Do a proper bounding box check instead of just centering the location
+ loc.setY(blockY);
+ loc.setX(loc.getBlockX() + 0.5);
+ //TODO: Do a proper bounding box check instead of just centering the location
loc.setZ(loc.getBlockZ() + 0.5);
return loc;
} else {
diff --git a/src/main/java/net/glowstone/block/itemtype/ItemFilledBucket.java b/src/main/java/net/glowstone/block/itemtype/ItemFilledBucket.java
index 45f805693a..3e8867c581 100644
--- a/src/main/java/net/glowstone/block/itemtype/ItemFilledBucket.java
+++ b/src/main/java/net/glowstone/block/itemtype/ItemFilledBucket.java
@@ -1,5 +1,6 @@
package net.glowstone.block.itemtype;
+import lombok.Getter;
import net.glowstone.EventFactory;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.GlowBlockState;
@@ -16,6 +17,7 @@
public class ItemFilledBucket extends ItemType {
+ @Getter
private final BlockType liquid;
public ItemFilledBucket(Material liquid) {
@@ -23,10 +25,6 @@ public ItemFilledBucket(Material liquid) {
setMaxStackSize(1);
}
- public BlockType getLiquid() {
- return liquid;
- }
-
@Override
public void rightClickBlock(GlowPlayer player, GlowBlock against, BlockFace face,
ItemStack holding, Vector clickedLoc, EquipmentSlot hand) {
diff --git a/src/main/java/net/glowstone/block/itemtype/ItemFishCooked.java b/src/main/java/net/glowstone/block/itemtype/ItemFishCooked.java
index 965d86d1ea..77fac23e70 100644
--- a/src/main/java/net/glowstone/block/itemtype/ItemFishCooked.java
+++ b/src/main/java/net/glowstone/block/itemtype/ItemFishCooked.java
@@ -12,8 +12,9 @@ protected float getSaturation(ItemStack stack) {
return 6f;
case 1:
return 9.6f;
+ default:
+ throw new IllegalArgumentException("Cannot find fish(350) for data: " + data);
}
- throw new IllegalArgumentException("Cannot find fish(350) for data: " + data);
}
@Override
@@ -24,7 +25,8 @@ protected int getFoodLevel(ItemStack stack) {
return 5;
case 1:
return 6;
+ default:
+ throw new IllegalArgumentException("Cannot find fish(350) for data: " + data);
}
- throw new IllegalArgumentException("Cannot find fish(350) for data: " + data);
}
}
diff --git a/src/main/java/net/glowstone/block/itemtype/ItemFishRaw.java b/src/main/java/net/glowstone/block/itemtype/ItemFishRaw.java
index 527e492471..4f8c9cbfb1 100644
--- a/src/main/java/net/glowstone/block/itemtype/ItemFishRaw.java
+++ b/src/main/java/net/glowstone/block/itemtype/ItemFishRaw.java
@@ -17,8 +17,9 @@ protected float getSaturation(ItemStack stack) {
case 2:
case 3:
return 0.2f;
+ default:
+ throw new IllegalArgumentException("Cannot find fish(349) for data: " + data);
}
- throw new IllegalArgumentException("Cannot find fish(349) for data: " + data);
}
@Override
@@ -31,8 +32,9 @@ protected int getFoodLevel(ItemStack stack) {
case 2:
case 3:
return 1;
+ default:
+ throw new IllegalArgumentException("Cannot find fish(349) for data: " + data);
}
- throw new IllegalArgumentException("Cannot find fish(349) for data: " + data);
}
@Override
diff --git a/src/main/java/net/glowstone/block/itemtype/ItemFlintAndSteel.java b/src/main/java/net/glowstone/block/itemtype/ItemFlintAndSteel.java
index cea9c712dc..9a28f8c45e 100644
--- a/src/main/java/net/glowstone/block/itemtype/ItemFlintAndSteel.java
+++ b/src/main/java/net/glowstone/block/itemtype/ItemFlintAndSteel.java
@@ -27,7 +27,7 @@ public boolean onToolRightClick(GlowPlayer player, GlowBlock target, BlockFace f
return true;
}
if (target.getType() == Material.TNT) {
- fireTnt(target);
+ fireTnt(target, player);
return true;
}
if (target.isFlammable() || target.getType().isOccluding()) {
@@ -49,8 +49,8 @@ private void fireNetherPortal(GlowBlock target, BlockFace face) {
}
}
- private void fireTnt(GlowBlock tnt) {
- BlockTnt.igniteBlock(tnt, false);
+ private void fireTnt(GlowBlock tnt,GlowPlayer player) {
+ BlockTnt.igniteBlock(tnt, false, player);
}
private boolean setBlockOnFire(GlowPlayer player, GlowBlock clicked, BlockFace face,
diff --git a/src/main/java/net/glowstone/block/itemtype/ItemFood.java b/src/main/java/net/glowstone/block/itemtype/ItemFood.java
index fe7cdce65e..ddde2083c2 100644
--- a/src/main/java/net/glowstone/block/itemtype/ItemFood.java
+++ b/src/main/java/net/glowstone/block/itemtype/ItemFood.java
@@ -50,6 +50,13 @@ protected boolean handleEat(GlowPlayer player, ItemStack item) {
return true;
}
+ /**
+ * Player attempts to eat this food.
+ *
+ * @param player the eating player
+ * @param item the item stack eaten from
+ * @return whether food was eaten successfully
+ */
public boolean eat(GlowPlayer player, ItemStack item) {
if (!handleEat(player, item)) {
return false;
diff --git a/src/main/java/net/glowstone/block/itemtype/ItemFoodSeeds.java b/src/main/java/net/glowstone/block/itemtype/ItemFoodSeeds.java
index acebe16d64..61a8d940ff 100644
--- a/src/main/java/net/glowstone/block/itemtype/ItemFoodSeeds.java
+++ b/src/main/java/net/glowstone/block/itemtype/ItemFoodSeeds.java
@@ -10,11 +10,23 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
+/**
+ * A type of edible item that can be planted on one specific type of block, such as a carrot or
+ * potato.
+ */
public class ItemFoodSeeds extends ItemFood {
private Material cropsType;
private Material soilType;
+ /**
+ * Creates an instance.
+ *
+ * @param cropsType this item's block form
+ * @param soilType the type of block this can be planted on
+ * @param food the amount of hunger this food fills, in half icons
+ * @param saturation the amount of saturation this food grants, in half icons saved
+ */
public ItemFoodSeeds(Material cropsType, Material soilType, int food, float saturation) {
super(food, saturation);
this.cropsType = cropsType;
diff --git a/src/main/java/net/glowstone/block/itemtype/ItemKnowledgeBook.java b/src/main/java/net/glowstone/block/itemtype/ItemKnowledgeBook.java
index 6a6fd9cf00..b91b79a722 100644
--- a/src/main/java/net/glowstone/block/itemtype/ItemKnowledgeBook.java
+++ b/src/main/java/net/glowstone/block/itemtype/ItemKnowledgeBook.java
@@ -24,7 +24,9 @@ public Context getContext() {
}
@Override
- public void rightClickBlock(GlowPlayer player, GlowBlock target, BlockFace face, ItemStack holding, Vector clickedLoc, EquipmentSlot hand) {
+ public void rightClickBlock(
+ GlowPlayer player, GlowBlock target, BlockFace face, ItemStack holding,
+ Vector clickedLoc, EquipmentSlot hand) {
rightClickBook(player, holding);
}
diff --git a/src/main/java/net/glowstone/block/itemtype/ItemMinecart.java b/src/main/java/net/glowstone/block/itemtype/ItemMinecart.java
index 44b0654f08..f88b4ac40c 100644
--- a/src/main/java/net/glowstone/block/itemtype/ItemMinecart.java
+++ b/src/main/java/net/glowstone/block/itemtype/ItemMinecart.java
@@ -54,8 +54,8 @@ private float getYaw(BlockFace face) {
case WEST:
return 90f;
case SOUTH:
+ default:
return 0f;
}
- return getYaw(BlockFace.SOUTH);
}
}
diff --git a/src/main/java/net/glowstone/block/itemtype/ItemPainting.java b/src/main/java/net/glowstone/block/itemtype/ItemPainting.java
index 227aa36730..066ab9a533 100644
--- a/src/main/java/net/glowstone/block/itemtype/ItemPainting.java
+++ b/src/main/java/net/glowstone/block/itemtype/ItemPainting.java
@@ -25,7 +25,7 @@
public class ItemPainting extends ItemType {
/**
- * Contains all Arts Key is the size of the art in descending order
+ * Contains all Arts. Key is the size of the art in descending order.
*/
private static final ListMultimap ART_BY_SIZE;
diff --git a/src/main/java/net/glowstone/block/itemtype/ItemShovel.java b/src/main/java/net/glowstone/block/itemtype/ItemShovel.java
index 087cbbc1e0..8152e02fb1 100644
--- a/src/main/java/net/glowstone/block/itemtype/ItemShovel.java
+++ b/src/main/java/net/glowstone/block/itemtype/ItemShovel.java
@@ -15,14 +15,12 @@ public class ItemShovel extends ItemTool {
public boolean onToolRightClick(GlowPlayer player, GlowBlock target, BlockFace face,
ItemStack holding, Vector clickedLoc, EquipmentSlot hand) {
if (target.getRelative(BlockFace.UP).getType() == Material.AIR
- && target.getType() == Material.GRASS) {
- if (target.getType() == Material.GRASS) {
- target.getWorld()
- .playSound(target.getLocation().add(0.5D, 0.5D, 0.5D), Sound.BLOCK_GRAVEL_STEP,
- 1, 0.8F);
- target.setType(Material.GRASS_PATH);
- return true;
- }
+ && target.getType() == Material.GRASS && face != BlockFace.DOWN) {
+ target.getWorld()
+ .playSound(target.getLocation().add(0.5D, 0.5D, 0.5D), Sound.BLOCK_GRAVEL_STEP,
+ 1, 0.8F);
+ target.setType(Material.GRASS_PATH);
+ return true;
}
return false;
}
diff --git a/src/main/java/net/glowstone/block/itemtype/ItemType.java b/src/main/java/net/glowstone/block/itemtype/ItemType.java
index e3cdb7e7ce..002ea92b23 100644
--- a/src/main/java/net/glowstone/block/itemtype/ItemType.java
+++ b/src/main/java/net/glowstone/block/itemtype/ItemType.java
@@ -1,6 +1,10 @@
package net.glowstone.block.itemtype;
import com.google.common.base.Preconditions;
+import lombok.AccessLevel;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.ItemTable;
import net.glowstone.block.blocktype.BlockType;
@@ -17,13 +21,29 @@
public class ItemType {
private int id = -1;
+ /**
+ * Get the Material assigned to this ItemType.
+ *
+ * @return The corresponding Material.
+ */
+ @Getter
private Material material;
+ /**
+ * The type of block to place when the item is used.
+ *
+ * @return the type of block to place
+ */
+ @Getter
private BlockType placeAs;
/**
* The maximum stack size of the item.
+ *
+ * @return The maximum stack size.
*/
+ @Getter
+ @Setter(AccessLevel.PROTECTED)
private int maxStackSize = 64;
/**
@@ -57,15 +77,6 @@ public final void setId(int id) {
}
}
- /**
- * Get the Material assigned to this ItemType.
- *
- * @return The corresponding Material.
- */
- public final Material getMaterial() {
- return material;
- }
-
/**
* Assign a Material to this ItemType (for internal use only).
*
@@ -106,44 +117,16 @@ protected final void setPlaceAs(Material placeAs) {
* @param placeAs The block to place as.
*/
protected final void setPlaceAs(BlockType placeAs) {
+ // Cannot be Lombokified because of the overload
this.placeAs = placeAs;
}
- /**
- * The type of block to place when the item is used.
- *
- * @return the type of block to place
- */
- public BlockType getPlaceAs() {
- return placeAs;
- }
-
- /**
- * Get the maximum stack size of the item.
- *
- * @return The maximum stack size.
- */
- public int getMaxStackSize() {
- return maxStackSize;
- }
-
- ////////////////////////////////////////////////////////////////////////////
- // Public accessors
-
- /**
- * Set the maximum stack size of the item.
- *
- * @param maxStackSize The new maximum stack size.
- */
- protected final void setMaxStackSize(int maxStackSize) {
- this.maxStackSize = maxStackSize;
- }
-
////////////////////////////////////////////////////////////////////////////
// Actions
/**
- * Called when a player right-clicks in midair while holding this item.
+ * Called when a player right-clicks in midair while holding this item. Also called by default
+ * if rightClickBlock is not overridden.
*
* @param player The player
* @param holding The ItemStack the player was holding
@@ -153,7 +136,7 @@ public void rightClickAir(GlowPlayer player, ItemStack holding) {
}
/**
- * Get the context this item can be used in
+ * Get the context this item can be used in.
*
* @return context of the item, default is {{@link Context#BLOCK}}
*/
@@ -172,8 +155,10 @@ public Context getContext() {
*/
public void rightClickBlock(GlowPlayer player, GlowBlock target, BlockFace face,
ItemStack holding, Vector clickedLoc, EquipmentSlot hand) {
- if (placeAs != null && (placeAs.getContext() == Context.ANY || placeAs.getContext() == Context.BLOCK)) {
- placeAs.rightClickBlock(player, target, face, holding, clickedLoc, hand);
+ if (placeAs != null) {
+ if (placeAs.getContext().isBlockApplicable()) {
+ placeAs.rightClickBlock(player, target, face, holding, clickedLoc, hand);
+ }
}
}
@@ -182,24 +167,31 @@ public void rightClickBlock(GlowPlayer player, GlowBlock target, BlockFace face,
@Override
public final String toString() {
- return getClass().getSimpleName() + "{" + (getMaterial() == null ? getId() : getMaterial()) + "}";
+ return getClass().getSimpleName()
+ + "{" + (getMaterial() == null ? getId() : getMaterial()) + "}";
}
/**
- * Context of the Items interaction
+ * Context of the Items interaction.
*/
+ @AllArgsConstructor
public enum Context {
/**
- * The item can only be used when clicking in the air
+ * The item can only be used when clicking in the air.
*/
- AIR,
+ AIR(true, false),
/**
- * The item can only be used when clicking against a block
+ * The item can only be used when clicking against a block.
*/
- BLOCK,
+ BLOCK(false, true),
/**
- * The item can be used on any click
+ * The item can be used on any click.
*/
- ANY
+ ANY(true, true);
+
+ @Getter
+ private boolean airApplicable;
+ @Getter
+ private boolean blockApplicable;
}
}
diff --git a/src/main/java/net/glowstone/block/itemtype/ItemWrittenBook.java b/src/main/java/net/glowstone/block/itemtype/ItemWrittenBook.java
index c8efb08538..b58f7dfebf 100644
--- a/src/main/java/net/glowstone/block/itemtype/ItemWrittenBook.java
+++ b/src/main/java/net/glowstone/block/itemtype/ItemWrittenBook.java
@@ -23,7 +23,9 @@ public void rightClickAir(GlowPlayer player, ItemStack holding) {
}
@Override
- public void rightClickBlock(GlowPlayer player, GlowBlock target, BlockFace face, ItemStack holding, Vector clickedLoc, EquipmentSlot hand) {
+ public void rightClickBlock(
+ GlowPlayer player, GlowBlock target, BlockFace face, ItemStack holding,
+ Vector clickedLoc, EquipmentSlot hand) {
openBook(player);
}
diff --git a/src/main/java/net/glowstone/block/state/BlockStateData.java b/src/main/java/net/glowstone/block/state/BlockStateData.java
index 18006c6fcd..2aa07b55ee 100644
--- a/src/main/java/net/glowstone/block/state/BlockStateData.java
+++ b/src/main/java/net/glowstone/block/state/BlockStateData.java
@@ -2,10 +2,12 @@
import com.google.common.collect.Maps;
import java.util.Map;
+import lombok.Getter;
public class BlockStateData {
private final Map map = Maps.newHashMap();
+ @Getter
private final byte numericValue;
public BlockStateData(byte numericValue) {
@@ -36,10 +38,6 @@ public boolean isNumeric() {
return numericValue != -1;
}
- public byte getNumericValue() {
- return numericValue;
- }
-
@Override
public String toString() {
if (isNumeric()) {
diff --git a/src/main/java/net/glowstone/block/state/StateSerialization.java b/src/main/java/net/glowstone/block/state/StateSerialization.java
index 90b2f6a465..5d23f66da8 100644
--- a/src/main/java/net/glowstone/block/state/StateSerialization.java
+++ b/src/main/java/net/glowstone/block/state/StateSerialization.java
@@ -15,6 +15,16 @@ public class StateSerialization {
READERS.put(Material.WOOL, new WoolStateDataReader());
}
+ /**
+ * Reads a {@link BlockStateData} instance from a string.
+ *
+ * @param material the block type
+ * @param state the state as a string, or null
+ * @return the default state if {@code state} is null, empty or "*" after stripping leading and
+ * trailing whitespace; otherwise, a state parsed from the string.
+ * @throws InvalidBlockStateException if {@code type} isn't a block type with a
+ * {@link BlockStateReader}, or {@code state} is an invalid block-state string
+ */
public static BlockStateData parse(Material material, String state)
throws InvalidBlockStateException {
if (state == null || state.trim().isEmpty() || state.trim().equals("*")) {
@@ -47,6 +57,17 @@ public static BlockStateData parse(Material material, String state)
return data;
}
+ /**
+ * Returns whether the given {@link MaterialData} and the given {@link BlockStateData} are valid
+ * for the given block type and describe the same state.
+ * @param type the block type, or null
+ * @param data the block state that's a {@link MaterialData}, or null
+ * @param state the block state that's a {@link BlockStateData}, or null
+ * @return true if all parameters are non-null, {@code data} is valid for {@code type}, and
+ * {@code state} is empty or matches {@code data}; false otherwise
+ * @throws InvalidBlockStateException if {@code type} is not null but isn't a block type with a
+ * {@link BlockStateReader}
+ */
public static boolean matches(Material type, MaterialData data, BlockStateData state)
throws InvalidBlockStateException {
if (state == null || data == null || data.getItemType() != type) {
@@ -62,6 +83,16 @@ public static boolean matches(Material type, MaterialData data, BlockStateData s
return reader.matches(state, data);
}
+ /**
+ * Converts a {@link BlockStateData} instance to a {@link MaterialData} instance.
+ *
+ * @param type the block type, or null
+ * @param state the block state, or null
+ * @return the block state as a {@link MaterialData} instance, or null if either parameter is
+ * null
+ * @throws InvalidBlockStateException if {@code type} is not null but isn't a block type with a
+ * {@link BlockStateReader}
+ */
public static MaterialData parseData(Material type, BlockStateData state)
throws InvalidBlockStateException {
if (type == null || state == null) {
@@ -74,13 +105,27 @@ public static MaterialData parseData(Material type, BlockStateData state)
return reader.read(type, state);
}
- public static BlockStateReader getReader(Material material) {
+ /**
+ * Returns the {@link BlockStateReader} for a block type.
+ *
+ * @param material a material, or null
+ * @return the {@link BlockStateReader} for {@code material}, or null if {@code material} is
+ * null or not a block type that has a {@link BlockStateReader}
+ */
+ public static BlockStateReader> getReader(Material material) {
if (material == null) {
return null;
}
return READERS.get(material);
}
+ /**
+ * Returns the {@link DyeColor} with a given name (case-insensitive).
+ *
+ * @param color the name of a color, or null
+ * @return the {@link DyeColor} with that name, or null if {@code color} is null or no colors
+ * match
+ */
public static DyeColor getColor(String color) {
if (color == null) {
return null;
diff --git a/src/main/java/net/glowstone/block/state/impl/WoolStateDataReader.java b/src/main/java/net/glowstone/block/state/impl/WoolStateDataReader.java
index f0abaf12b0..fad6832112 100644
--- a/src/main/java/net/glowstone/block/state/impl/WoolStateDataReader.java
+++ b/src/main/java/net/glowstone/block/state/impl/WoolStateDataReader.java
@@ -1,6 +1,6 @@
package net.glowstone.block.state.impl;
-import com.google.common.collect.Sets;
+import com.google.common.collect.ImmutableSet;
import java.util.Set;
import net.glowstone.block.state.BlockStateData;
import net.glowstone.block.state.BlockStateReader;
@@ -12,7 +12,7 @@
public class WoolStateDataReader extends BlockStateReader {
- private static final Set VALID_STATES = Sets.newHashSet("color");
+ private static final Set VALID_STATES = ImmutableSet.of("color");
@Override
public Set getValidStates() {
diff --git a/src/main/java/net/glowstone/boss/GlowBossBar.java b/src/main/java/net/glowstone/boss/GlowBossBar.java
index e9b983bf99..e378e2189e 100644
--- a/src/main/java/net/glowstone/boss/GlowBossBar.java
+++ b/src/main/java/net/glowstone/boss/GlowBossBar.java
@@ -4,6 +4,7 @@
import java.util.Collections;
import java.util.List;
import java.util.UUID;
+import lombok.Getter;
import net.glowstone.entity.GlowPlayer;
import net.glowstone.net.message.play.player.BossBarMessage;
import net.glowstone.util.TextMessage;
@@ -15,13 +16,19 @@
public class GlowBossBar implements BossBar {
+ @Getter
private final UUID uniqueId;
private final List flags = new ArrayList<>();
private final List players = new ArrayList<>();
+ @Getter
private String title;
+ @Getter
private BarColor color;
+ @Getter
private BarStyle style;
+ @Getter
private double progress = 1.0;
+ @Getter
private boolean visible = true;
/**
@@ -47,11 +54,6 @@ public GlowBossBar(String title, BarColor color, BarStyle style, BarFlag... flag
this(title, color, style, 1.0, flags);
}
- @Override
- public String getTitle() {
- return title;
- }
-
@Override
public void setTitle(String title) {
this.title = title;
@@ -61,11 +63,6 @@ public void setTitle(String title) {
}
}
- @Override
- public BarColor getColor() {
- return color;
- }
-
@Override
public void setColor(BarColor color) {
this.color = color;
@@ -76,11 +73,6 @@ public void setColor(BarColor color) {
}
}
- @Override
- public BarStyle getStyle() {
- return style;
- }
-
@Override
public void setStyle(BarStyle style) {
this.style = style;
@@ -118,11 +110,6 @@ public boolean hasFlag(BarFlag flag) {
return flags.contains(flag);
}
- @Override
- public double getProgress() {
- return progress;
- }
-
@Override
public void setProgress(double progress) {
this.progress = progress;
@@ -173,14 +160,10 @@ public void removeAll() {
@Override
public List getPlayers() {
+ // TODO: Defensive copy
return players;
}
- @Override
- public boolean isVisible() {
- return visible;
- }
-
@Override
public void setVisible(boolean visible) {
if (this.visible != visible) {
@@ -203,10 +186,6 @@ public void hide() {
setVisible(false);
}
- public UUID getUniqueId() {
- return uniqueId;
- }
-
private byte flagsToByte() {
byte flags = 0;
if (this.flags.contains(BarFlag.DARKEN_SKY)) {
diff --git a/src/main/java/net/glowstone/chunk/ChunkManager.java b/src/main/java/net/glowstone/chunk/ChunkManager.java
index 6189478e36..9f13e9f81c 100644
--- a/src/main/java/net/glowstone/chunk/ChunkManager.java
+++ b/src/main/java/net/glowstone/chunk/ChunkManager.java
@@ -13,6 +13,7 @@
import java.util.concurrent.ConcurrentMap;
import java.util.logging.Level;
import java.util.stream.Collectors;
+import lombok.Getter;
import net.glowstone.EventFactory;
import net.glowstone.GlowServer;
import net.glowstone.GlowWorld;
@@ -49,7 +50,10 @@ public final class ChunkManager {
/**
* The chunk generator used to generate new chunks.
+ *
+ * @return the chunk generator
*/
+ @Getter
private final ChunkGenerator generator;
/**
@@ -81,16 +85,7 @@ public ChunkManager(GlowWorld world, ChunkIoService service, ChunkGenerator gene
biomeGrid = MapLayer.initialize(
world.getSeed(), world.getEnvironment(), world.getWorldType());
}
-
- /**
- * Get the chunk generator.
- *
- * @return The chunk generator.
- */
- public ChunkGenerator getGenerator() {
- return generator;
- }
-
+
/**
* Gets a chunk object representing the specified coordinates, which might not yet be loaded.
*
diff --git a/src/main/java/net/glowstone/chunk/ChunkSection.java b/src/main/java/net/glowstone/chunk/ChunkSection.java
index d11806f541..e3e16b7861 100644
--- a/src/main/java/net/glowstone/chunk/ChunkSection.java
+++ b/src/main/java/net/glowstone/chunk/ChunkSection.java
@@ -6,6 +6,7 @@
import it.unimi.dsi.fastutil.ints.IntList;
import it.unimi.dsi.fastutil.ints.IntListIterator;
import javax.annotation.Nullable;
+import lombok.Getter;
import net.glowstone.util.NibbleArray;
import net.glowstone.util.VariableValueArray;
import net.glowstone.util.nbt.CompoundTag;
@@ -49,11 +50,16 @@ public final class ChunkSection {
private VariableValueArray data;
/**
* The sky light array. This array is always set, even in dimensions without skylight.
+ *
+ * @return The sky light array. If the dimension of this chunk section's chunk's world is not
+ * the overworld, this array contains only maximum light levels.
*/
+ @Getter
private NibbleArray skyLight;
/**
* The block light array.
*/
+ @Getter
private NibbleArray blockLight;
/**
* The number of non-air blocks in this section, used to determine whether it is empty.
@@ -397,15 +403,6 @@ public char[] getTypes() {
return types;
}
- /**
- * Gets the block light array.
- *
- * @return The block light array.
- */
- public NibbleArray getBlockLight() {
- return blockLight;
- }
-
/**
* Gets the block light at the given block.
*
@@ -430,16 +427,6 @@ public void setBlockLight(int x, int y, int z, byte light) {
blockLight.set(index(x, y, z), light);
}
- /**
- * Gets the sky light array.
- *
- * @return The sky light array. If the dimension of this chunk section's chunk's world is not
- * the overworld, this array contains only maximum light levels.
- */
- public NibbleArray getSkyLight() {
- return skyLight;
- }
-
/**
* Gets the sky light at the given block.
*
diff --git a/src/main/java/net/glowstone/chunk/GlowChunk.java b/src/main/java/net/glowstone/chunk/GlowChunk.java
index cc4cd1d53f..a9403a1793 100644
--- a/src/main/java/net/glowstone/chunk/GlowChunk.java
+++ b/src/main/java/net/glowstone/chunk/GlowChunk.java
@@ -13,6 +13,8 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import lombok.Data;
+import lombok.Getter;
+import lombok.Setter;
import net.glowstone.EventFactory;
import net.glowstone.GlowServer;
import net.glowstone.GlowWorld;
@@ -60,14 +62,17 @@ public final class GlowChunk implements Chunk {
/**
* The world of this chunk.
*/
+ @Getter
private final GlowWorld world;
/**
* The x-coordinate of this chunk.
*/
+ @Getter
private final int x;
/**
* The z-coordinate of this chunk.
*/
+ @Getter
private final int z;
/**
* The block entities that reside in this chunk.
@@ -79,7 +84,10 @@ public final class GlowChunk implements Chunk {
private final Set entities = ConcurrentHashMap.newKeySet(4);
/**
* The array of chunk sections this chunk contains, or null if it is unloaded.
+ *
+ * @return The chunk sections array.
*/
+ @Getter
private ChunkSection[] sections;
/**
* The array of biomes this chunk contains, or null if it is unloaded.
@@ -92,7 +100,12 @@ public final class GlowChunk implements Chunk {
private byte[] heightMap;
/**
* Whether the chunk has been populated by special features. Used in map generation.
+ *
+ * @param populated Population status.
+ * @return Population status.
*/
+ @Getter
+ @Setter
private boolean populated;
/**
@@ -114,21 +127,6 @@ public String toString() {
return "GlowChunk{world=" + world.getName() + ",x=" + x + ",z=" + z + '}';
}
- @Override
- public GlowWorld getWorld() {
- return world;
- }
-
- @Override
- public int getX() {
- return x;
- }
-
- @Override
- public int getZ() {
- return z;
- }
-
@Override
public GlowBlock getBlock(int x, int y, int z) {
return new GlowBlock(this, this.x << 4 | x & 0xf, y & 0xff, this.z << 4 | z & 0xf);
@@ -197,15 +195,6 @@ public boolean isPopulated() {
return populated;
}
- /**
- * Sets the population status of this chunk.
- *
- * @param populated Population status.
- */
- public void setPopulated(boolean populated) {
- this.populated = populated;
- }
-
@Override
public boolean isLoaded() {
return sections != null;
@@ -400,15 +389,6 @@ private ChunkSection getSection(int y) {
return sections[idx];
}
- /**
- * Get all ChunkSection of this chunk.
- *
- * @return The chunk sections array.
- */
- public ChunkSection[] getSections() {
- return sections;
- }
-
/**
* Attempt to get the block entity located at the given coordinates.
*
diff --git a/src/main/java/net/glowstone/chunk/GlowChunkSnapshot.java b/src/main/java/net/glowstone/chunk/GlowChunkSnapshot.java
index bbe7efd392..e54c39b4a8 100644
--- a/src/main/java/net/glowstone/chunk/GlowChunkSnapshot.java
+++ b/src/main/java/net/glowstone/chunk/GlowChunkSnapshot.java
@@ -16,15 +16,25 @@ public class GlowChunkSnapshot implements ChunkSnapshot {
private final int x;
@Getter
private final int z;
- private final String world;
- private final long time;
+ @Getter
+ private final String worldName;
+ @Getter
+ private final long captureFullTime;
- private final ChunkSection[] sections;
+ /**
+ * The ChunkSection array backing this snapshot. In general, it should not be modified
+ * externally.
+ *
+ * @return The array of ChunkSections.
+ */
+ @Getter
+ private final ChunkSection[] rawSections;
private final byte[] height;
private final double[] temp;
private final double[] humid;
- private final byte[] biomes;
+ @Getter
+ private final byte[] rawBiomes;
/**
* Creates a snapshot of a chunk.
@@ -41,19 +51,19 @@ public GlowChunkSnapshot(int x, int z, World world, ChunkSection[] sections, byt
byte[] biomes, boolean svTemp) {
this.x = x;
this.z = z;
- this.world = world.getName();
- time = world.getFullTime();
+ this.worldName = world.getName();
+ captureFullTime = world.getFullTime();
int numSections = sections != null ? sections.length : 0;
- this.sections = new ChunkSection[numSections];
+ this.rawSections = new ChunkSection[numSections];
for (int i = 0; i < numSections; ++i) {
if (sections[i] != null) {
- this.sections[i] = sections[i].snapshot();
+ this.rawSections[i] = sections[i].snapshot();
}
}
this.height = height;
- this.biomes = biomes;
+ this.rawBiomes = biomes;
if (svTemp) {
int baseX = x << 4;
@@ -73,19 +83,10 @@ public GlowChunkSnapshot(int x, int z, World world, ChunkSection[] sections, byt
private ChunkSection getSection(int y) {
int idx = y >> 4;
- if (idx < 0 || idx >= sections.length) {
+ if (idx < 0 || idx >= rawSections.length) {
return null;
}
- return sections[idx];
- }
-
- /**
- * Get the ChunkSection array backing this snapshot. In general, it should not be modified.
- *
- * @return The array of ChunkSections.
- */
- public ChunkSection[] getRawSections() {
- return sections;
+ return rawSections[idx];
}
/**
@@ -101,23 +102,9 @@ public int[] getRawHeightmap() {
return result;
}
- public byte[] getRawBiomes() {
- return biomes;
- }
-
- @Override
- public String getWorldName() {
- return world;
- }
-
- @Override
- public long getCaptureFullTime() {
- return time;
- }
-
@Override
public boolean isSectionEmpty(int sy) {
- return sy < 0 || sy >= sections.length || sections[sy] == null;
+ return sy < 0 || sy >= rawSections.length || rawSections[sy] == null;
}
@Override
@@ -156,7 +143,7 @@ public int getHighestBlockYAt(int x, int z) {
@Override
public Biome getBiome(int x, int z) {
- return GlowBiome.getBiome(biomes[coordToIndex(x, z)]);
+ return GlowBiome.getBiome(rawBiomes[coordToIndex(x, z)]);
}
@Override
diff --git a/src/main/java/net/glowstone/command/CommandTarget.java b/src/main/java/net/glowstone/command/CommandTarget.java
index 2cfc151a37..fda476d77f 100644
--- a/src/main/java/net/glowstone/command/CommandTarget.java
+++ b/src/main/java/net/glowstone/command/CommandTarget.java
@@ -9,6 +9,7 @@
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
import lombok.Getter;
+import lombok.RequiredArgsConstructor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
@@ -19,6 +20,12 @@
public class CommandTarget {
private final CommandSender sender;
+ /**
+ * The type of selector (target).
+ *
+ * @return the type of selector of this target
+ */
+ @Getter
private final SelectorType selector;
private final HashMap arguments;
@@ -47,21 +54,13 @@ public CommandTarget(CommandSender sender, String target) {
}
}
- /**
- * The type of selector (target).
- *
- * @return the type of selector of this target
- */
- public SelectorType getSelector() {
- return selector;
- }
-
/**
* The arguments of the selector (target).
*
* @return the arguments of the selector of this target
*/
public HashMap getArguments() {
+ // TODO: Defensive copy
return arguments;
}
@@ -266,6 +265,7 @@ public Entity[] getMatched(Location source) {
* Types of selectors, namely @p (closest player), @r (random player), @a (all players), @e
* (all entities).
*/
+ @RequiredArgsConstructor
enum SelectorType {
NEAREST_PLAYER('p'),
RANDOM('r'),
@@ -273,11 +273,8 @@ enum SelectorType {
ALL_ENTITIES('e'),
SENDER('s');
- private char selector;
-
- SelectorType(char selector) {
- this.selector = selector;
- }
+ @Getter
+ private final char selector;
public static SelectorType get(char selector) {
for (SelectorType selectorType : values()) {
@@ -287,10 +284,6 @@ public static SelectorType get(char selector) {
}
return null;
}
-
- public char getSelector() {
- return selector;
- }
}
/**
diff --git a/src/main/java/net/glowstone/command/glowstone/GlowstoneCommand.java b/src/main/java/net/glowstone/command/glowstone/GlowstoneCommand.java
index 1c1596d39d..bc82941565 100644
--- a/src/main/java/net/glowstone/command/glowstone/GlowstoneCommand.java
+++ b/src/main/java/net/glowstone/command/glowstone/GlowstoneCommand.java
@@ -27,11 +27,14 @@
public class GlowstoneCommand extends BukkitCommand {
private static final List SUBCOMMANDS = Arrays
- .asList("about", "chunk", "eval", "help", "property", "vm", "world");
+ .asList("about", "chunk", "eval", "help", "property", "vm", "world");
+ /**
+ * Creates the instance for this command.
+ */
public GlowstoneCommand() {
super("glowstone", "A handful of Glowstone commands for debugging purposes",
- "/glowstone help", Arrays.asList("gs"));
+ "/glowstone help", Arrays.asList("gs"));
setPermission("glowstone.debug");
}
@@ -44,25 +47,28 @@ public boolean execute(CommandSender sender, String label, String[] args) {
// some info about this Glowstone server
sender.sendMessage("Information about this server:");
sender.sendMessage(
- " - " + ChatColor.GOLD + "Server brand: " + ChatColor.AQUA + Bukkit.getName()
- + ChatColor.RESET + ".");
+ " - " + ChatColor.GOLD + "Server brand: " + ChatColor.AQUA + Bukkit.getName()
+ + ChatColor.RESET + ".");
sender.sendMessage(
- " - " + ChatColor.GOLD + "Server name: " + ChatColor.AQUA + Bukkit.getServerName()
- + ChatColor.RESET + ".");
+ " - " + ChatColor.GOLD + "Server name: " + ChatColor.AQUA + Bukkit
+ .getServerName()
+ + ChatColor.RESET + ".");
sender.sendMessage(
- " - " + ChatColor.GOLD + "Glowstone version: " + ChatColor.AQUA + Bukkit
- .getVersion() + ChatColor.RESET + ".");
+ " - " + ChatColor.GOLD + "Glowstone version: " + ChatColor.AQUA + Bukkit
+ .getVersion() + ChatColor.RESET + ".");
sender.sendMessage(" - " + ChatColor.GOLD + "API version: " + ChatColor.AQUA + Bukkit
- .getBukkitVersion() + ChatColor.RESET + ".");
+ .getBukkitVersion() + ChatColor.RESET + ".");
sender.sendMessage(
- " - " + ChatColor.GOLD + "Players: " + ChatColor.AQUA + Bukkit.getOnlinePlayers()
- .size() + ChatColor.RESET + ".");
+ " - " + ChatColor.GOLD + "Players: " + ChatColor.AQUA + Bukkit
+ .getOnlinePlayers()
+ .size() + ChatColor.RESET + ".");
sender.sendMessage(
- " - " + ChatColor.GOLD + "Worlds: " + ChatColor.AQUA + Bukkit.getWorlds().size()
- + ChatColor.RESET + ".");
+ " - " + ChatColor.GOLD + "Worlds: " + ChatColor.AQUA + Bukkit.getWorlds().size()
+ + ChatColor.RESET + ".");
sender.sendMessage(
- " - " + ChatColor.GOLD + "Plugins: " + ChatColor.AQUA + Bukkit.getPluginManager()
- .getPlugins().length + ChatColor.RESET + ".");
+ " - " + ChatColor.GOLD + "Plugins: " + ChatColor.AQUA + Bukkit
+ .getPluginManager()
+ .getPlugins().length + ChatColor.RESET + ".");
// thread count
int threadCount = 0;
@@ -73,27 +79,31 @@ public boolean execute(CommandSender sender, String label, String[] args) {
}
}
sender.sendMessage(" - " + ChatColor.GOLD + "Threads: " + ChatColor.AQUA + threadCount
- + ChatColor.RESET + ".");
+ + ChatColor.RESET + ".");
return false;
}
if ("help".equalsIgnoreCase(args[0])) {
// some help
sender.sendMessage(ChatColor.GOLD + "Glowstone command help:");
sender.sendMessage(helpForSubCommand(label, "about", "Information about this server"));
- sender.sendMessage(helpForSubCommand(label, "eval ", "Evaluate a reflection string"));
+ sender.sendMessage(helpForSubCommand(label, "eval ", "Evaluate a reflection "
+ + "string"));
sender.sendMessage(helpForSubCommand(label, "help", "Shows the help screen"));
- sender.sendMessage(helpForSubCommand(label, "property [name]", "Lists or gets system properties"));
- sender.sendMessage(helpForSubCommand(label, "chunk", "Gets the coordinates of the current chunk"));
+ sender.sendMessage(helpForSubCommand(label, "property [name]", "Lists or gets system "
+ + "properties"));
+ sender.sendMessage(helpForSubCommand(label, "chunk", "Gets the coordinates of the "
+ + "current chunk"));
sender.sendMessage(helpForSubCommand(label, "vm", "Lists JVM options"));
- sender.sendMessage(helpForSubCommand(label, "world [teleportTo]", "Lists or teleports to worlds"));
+ sender.sendMessage(helpForSubCommand(label, "world [teleportTo]", "Lists or teleports"
+ + " to worlds"));
return false;
}
if ("property".equalsIgnoreCase(args[0])) {
if (args.length == 1) {
// list all
System.getProperties().forEach((key, value) -> sender.sendMessage(
- "Property '" + ChatColor.AQUA + key + ChatColor.RESET + "' = \""
- + ChatColor.GOLD + value + ChatColor.RESET + "\"."));
+ "Property '" + ChatColor.AQUA + key + ChatColor.RESET + "' = \""
+ + ChatColor.GOLD + value + ChatColor.RESET + "\"."));
} else {
// get a property
String key = args[1].toLowerCase();
@@ -102,8 +112,8 @@ public boolean execute(CommandSender sender, String label, String[] args) {
sender.sendMessage(ChatColor.RED + "Unknown system property '" + key + "'.");
} else {
sender.sendMessage(
- "Property '" + ChatColor.AQUA + key + ChatColor.RESET + "' = \""
- + ChatColor.GOLD + value + ChatColor.RESET + "\".");
+ "Property '" + ChatColor.AQUA + key + ChatColor.RESET + "' = \""
+ + ChatColor.GOLD + value + ChatColor.RESET + "\".");
}
}
return false;
@@ -126,7 +136,8 @@ public boolean execute(CommandSender sender, String label, String[] args) {
if (args.length == 1) {
// list worlds
sender.sendMessage(
- "Worlds: " + CommandUtils.prettyPrint(getWorldNames().toArray(new String[0])));
+ "Worlds: " + CommandUtils
+ .prettyPrint(getWorldNames().toArray(new String[0])));
return true;
}
if (!(sender instanceof Player)) {
@@ -138,7 +149,8 @@ public boolean execute(CommandSender sender, String label, String[] args) {
GlowWorld world = player.getServer().getWorld(worldName);
if (world == null) {
sender.sendMessage(
- ChatColor.RED + "World '" + worldName + "' is not loaded, or does not exist");
+ ChatColor.RED + "World '" + worldName
+ + "' is not loaded, or does not exist");
return false;
}
player.teleport(world.getSpawnLocation());
@@ -147,13 +159,14 @@ public boolean execute(CommandSender sender, String label, String[] args) {
}
if ("chunk".equalsIgnoreCase(args[0])) {
if (!CommandUtils.isPhysical(sender)) {
- sender
- .sendMessage(ChatColor.RED + "This command may only be used by physical objects");
+ sender.sendMessage(
+ ChatColor.RED + "This command may only be used by physical objects");
return false;
}
Chunk chunk = CommandUtils.getLocation(sender).getChunk();
sender
- .sendMessage("Chunk coordinates: [x=" + chunk.getX() + ", z=" + chunk.getZ() + "]");
+ .sendMessage(
+ "Chunk coordinates: [x=" + chunk.getX() + ", z=" + chunk.getZ() + "]");
return true;
}
if ("eval".equalsIgnoreCase(args[0])) {
@@ -167,11 +180,12 @@ public boolean execute(CommandSender sender, String label, String[] args) {
builder.append(args[i] + (i == args.length - 1 ? "" : " "));
}
ReflectionProcessor processor = new ReflectionProcessor(builder.toString(),
- sender instanceof Entity ? sender : Bukkit.getServer());
+ sender instanceof Entity ? sender : Bukkit.getServer());
Object result = processor.process();
sender.sendMessage(
- ChatColor.GOLD + "Eval returned: " + (result == null ? ChatColor.RED + ""
- : ChatColor.AQUA + result.toString()));
+ ChatColor.GOLD + "Eval returned: " + (result == null ? ChatColor.RED
+ + ""
+ : ChatColor.AQUA + result.toString()));
return true;
}
sender.sendMessage(ChatColor.RED + "Usage: /" + label + " <"
@@ -181,7 +195,7 @@ public boolean execute(CommandSender sender, String label, String[] args) {
@Override
public List tabComplete(CommandSender sender, String alias, String[] args)
- throws IllegalArgumentException {
+ throws IllegalArgumentException {
Preconditions.checkNotNull(sender, "Sender cannot be null");
Preconditions.checkNotNull(args, "Arguments cannot be null");
Preconditions.checkNotNull(alias, "Alias cannot be null");
@@ -190,28 +204,30 @@ public List tabComplete(CommandSender sender, String alias, String[] arg
}
if (args.length == 1) {
return StringUtil
- .copyPartialMatches(args[0], SUBCOMMANDS, new ArrayList<>(SUBCOMMANDS.size()));
+ .copyPartialMatches(args[0], SUBCOMMANDS, new ArrayList<>(SUBCOMMANDS.size()));
}
if (args.length == 2 && args[0].equalsIgnoreCase("property")) {
return StringUtil
- .copyPartialMatches(args[1], System.getProperties().stringPropertyNames(),
- new ArrayList<>(System.getProperties().stringPropertyNames().size()));
+ .copyPartialMatches(args[1], System.getProperties().stringPropertyNames(),
+ new ArrayList<>(System.getProperties().stringPropertyNames().size()));
}
if (args.length == 2 && (args[0].equalsIgnoreCase("world") || args[0]
- .equalsIgnoreCase("worlds")) && sender instanceof Player) {
+ .equalsIgnoreCase("worlds")) && sender instanceof Player) {
Collection worlds = getWorldNames();
return StringUtil
- .copyPartialMatches(args[1], worlds, new ArrayList<>(worlds.size()));
+ .copyPartialMatches(args[1], worlds, new ArrayList<>(worlds.size()));
}
return Collections.emptyList();
}
private String helpForSubCommand(String label, String subcommand, String description) {
- return "- " + ChatColor.GOLD + "/" + label + " " + ChatColor.AQUA + subcommand + ChatColor.GRAY + ": " + description;
+ return "- " + ChatColor.GOLD + "/" + label + " "
+ + ChatColor.AQUA + subcommand
+ + ChatColor.GRAY + ": " + description;
}
private Collection getWorldNames() {
return Bukkit.getServer().getWorlds().stream().map(World::getName)
- .collect(Collectors.toList());
+ .collect(Collectors.toList());
}
}
diff --git a/src/main/java/net/glowstone/command/minecraft/BanCommand.java b/src/main/java/net/glowstone/command/minecraft/BanCommand.java
index 564c0fcc6b..ed02b314ce 100644
--- a/src/main/java/net/glowstone/command/minecraft/BanCommand.java
+++ b/src/main/java/net/glowstone/command/minecraft/BanCommand.java
@@ -2,7 +2,7 @@
import java.util.Collections;
import java.util.List;
-import net.glowstone.entity.meta.profile.PlayerProfile;
+import net.glowstone.GlowServer;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@@ -16,7 +16,7 @@ public class BanCommand extends VanillaCommand {
*/
public BanCommand() {
super("ban", "Bans a player from the server.", "/ban [reason]",
- Collections.emptyList());
+ Collections.emptyList());
setPermission("minecraft.command.ban");
}
@@ -26,20 +26,34 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
return false;
}
if (args.length > 0) {
- if (PlayerProfile.getProfile(args[0]).join() == null) {
- sender.sendMessage(ChatColor.RED + "Could not ban player " + args[0]);
- return false;
- }
- if (args.length == 1) {
- Bukkit.getBanList(BanList.Type.NAME).addBan(args[0], null, null, null);
- } else {
- StringBuilder reason = new StringBuilder();
- for (int i = 1; i < args.length; i++) {
- reason.append(args[i]).append(" ");
+ String name = args[0];
+ GlowServer server = (GlowServer) Bukkit.getServer();
+ // asynchronously lookup player
+ server.getOfflinePlayerAsync(name).whenCompleteAsync((player, ex) -> {
+ if (ex != null) {
+ sender.sendMessage(ChatColor.RED + "Failed to ban " + name + ": "
+ + ex.getMessage());
+ ex.printStackTrace();
+ return;
}
- Bukkit.getBanList(BanList.Type.NAME).addBan(args[0], reason.toString(), null, null);
- }
- sender.sendMessage("Banned player " + args[0]);
+ if (player == null) {
+ sender.sendMessage(ChatColor.RED + "Could not ban player " + args[0]);
+ return;
+ }
+ if (args.length == 1) {
+ Bukkit.getBanList(BanList.Type.NAME).addBan(player.getName(),
+ null, null, null);
+ } else {
+ StringBuilder reason = new StringBuilder();
+ for (int i = 1; i < args.length; i++) {
+ reason.append(args[i]).append(" ");
+ }
+ Bukkit.getBanList(BanList.Type.NAME).addBan(player.getName(),
+ reason.toString(), null, null);
+ }
+ sender.sendMessage("Banned player " + player.getName());
+ });
+ // todo: asynchronous command callbacks?
return true;
}
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
@@ -48,7 +62,7 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
@Override
public List tabComplete(CommandSender sender, String alias, String[] args)
- throws IllegalArgumentException {
+ throws IllegalArgumentException {
if (args.length == 1) {
super.tabComplete(sender, alias, args);
}
diff --git a/src/main/java/net/glowstone/command/minecraft/CloneCommand.java b/src/main/java/net/glowstone/command/minecraft/CloneCommand.java
index 9ce5e20449..4cae3ff0a7 100644
--- a/src/main/java/net/glowstone/command/minecraft/CloneCommand.java
+++ b/src/main/java/net/glowstone/command/minecraft/CloneCommand.java
@@ -4,6 +4,7 @@
import java.util.Collections;
import java.util.Iterator;
import lombok.Getter;
+import lombok.RequiredArgsConstructor;
import net.glowstone.GlowWorld;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.entity.BlockEntity;
@@ -19,21 +20,15 @@
public class CloneCommand extends VanillaCommand {
+ @RequiredArgsConstructor
public enum MaskMode {
REPLACE("replace"),
MASKED("masked"),
FILTERED("filter");
+ @Getter
private final String commandName;
- MaskMode(String commandName) {
- this.commandName = commandName;
- }
-
- public String getCommandName() {
- return commandName;
- }
-
/**
* Returns the MaskMode with a given subcommand name, or null if none match.
*
diff --git a/src/main/java/net/glowstone/command/minecraft/DeopCommand.java b/src/main/java/net/glowstone/command/minecraft/DeopCommand.java
index 9b07788a58..83856d9e8e 100644
--- a/src/main/java/net/glowstone/command/minecraft/DeopCommand.java
+++ b/src/main/java/net/glowstone/command/minecraft/DeopCommand.java
@@ -4,6 +4,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
+import net.glowstone.GlowServer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
@@ -18,7 +19,7 @@ public class DeopCommand extends VanillaCommand {
*/
public DeopCommand() {
super("deop", "Removes server operator status from a player.", "/deop ",
- Collections.emptyList());
+ Collections.emptyList());
setPermission("minecraft.command.deop");
}
@@ -32,19 +33,30 @@ public boolean execute(CommandSender sender, String label, String[] args) {
return false;
}
String name = args[0];
- OfflinePlayer player = Bukkit.getOfflinePlayer(name);
- if (player.isOp()) {
- player.setOp(false);
- sender.sendMessage("Deopped " + player.getName());
- } else {
- sender.sendMessage("Could not deop " + player.getName());
- }
+ GlowServer server = (GlowServer) Bukkit.getServer();
+ // asynchronously lookup player
+ server.getOfflinePlayerAsync(name).whenCompleteAsync((player, ex) -> {
+ if (ex != null) {
+ sender.sendMessage(ChatColor.RED + "Failed to deop " + name + ": "
+ + ex.getMessage());
+ ex.printStackTrace();
+ return;
+ }
+ if (player.isOp()) {
+ player.setOp(false);
+ sender.sendMessage("Deopped " + player.getName());
+ } else {
+ sender.sendMessage(ChatColor.RED + "Could not deop " + player.getName()
+ + ": not an operator");
+ }
+ });
+ // todo: asynchronous command callbacks?
return true;
}
@Override
public List tabComplete(CommandSender sender, String alias, String[] args)
- throws IllegalArgumentException {
+ throws IllegalArgumentException {
if (args.length == 1) {
List operators = new ArrayList<>();
Bukkit.getOperators().stream().map(OfflinePlayer::getName)
diff --git a/src/main/java/net/glowstone/command/minecraft/KickCommand.java b/src/main/java/net/glowstone/command/minecraft/KickCommand.java
index 6326cfe6f1..ac42215c6f 100644
--- a/src/main/java/net/glowstone/command/minecraft/KickCommand.java
+++ b/src/main/java/net/glowstone/command/minecraft/KickCommand.java
@@ -11,6 +11,9 @@
public class KickCommand extends VanillaCommand {
+ /**
+ * Creates the instance for this command.
+ */
public KickCommand() {
super("kick", "Removes a player from the server.", "/kick [reason]",
Collections.emptyList());
diff --git a/src/main/java/net/glowstone/command/minecraft/MeCommand.java b/src/main/java/net/glowstone/command/minecraft/MeCommand.java
index f171d8a887..2d0dbd3995 100644
--- a/src/main/java/net/glowstone/command/minecraft/MeCommand.java
+++ b/src/main/java/net/glowstone/command/minecraft/MeCommand.java
@@ -10,6 +10,9 @@
public class MeCommand extends VanillaCommand {
+ /**
+ * Creates the instance for this command.
+ */
public MeCommand() {
super("me", "Displays a message about yourself.", "/me ",
Collections.emptyList());
diff --git a/src/main/java/net/glowstone/command/minecraft/OpCommand.java b/src/main/java/net/glowstone/command/minecraft/OpCommand.java
index efd12b48ef..09d43a2337 100644
--- a/src/main/java/net/glowstone/command/minecraft/OpCommand.java
+++ b/src/main/java/net/glowstone/command/minecraft/OpCommand.java
@@ -1,17 +1,20 @@
package net.glowstone.command.minecraft;
import java.util.Collections;
+import net.glowstone.GlowServer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
-import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.VanillaCommand;
public class OpCommand extends VanillaCommand {
+ /**
+ * Creates the instance for this command.
+ */
public OpCommand() {
super("op", "Turns a player into a server operator.", "/op ",
- Collections.emptyList());
+ Collections.emptyList());
setPermission("minecraft.command.op");
}
@@ -25,9 +28,19 @@ public boolean execute(CommandSender sender, String label, String[] args) {
return false;
}
String name = args[0];
- OfflinePlayer player = Bukkit.getOfflinePlayer(name);
- player.setOp(true);
- sender.sendMessage("Opped " + player.getName());
+ GlowServer server = (GlowServer) Bukkit.getServer();
+ // asynchronously lookup player
+ server.getOfflinePlayerAsync(name).whenCompleteAsync((player, ex) -> {
+ if (ex != null) {
+ sender.sendMessage(ChatColor.RED + "Failed to op " + name + ": "
+ + ex.getMessage());
+ ex.printStackTrace();
+ return;
+ }
+ player.setOp(true);
+ sender.sendMessage("Opped " + player.getName());
+ });
+ // todo: asynchronous command callbacks?
return true;
}
}
diff --git a/src/main/java/net/glowstone/command/minecraft/PardonCommand.java b/src/main/java/net/glowstone/command/minecraft/PardonCommand.java
index 5d323c8ded..835ed902a1 100644
--- a/src/main/java/net/glowstone/command/minecraft/PardonCommand.java
+++ b/src/main/java/net/glowstone/command/minecraft/PardonCommand.java
@@ -1,15 +1,18 @@
package net.glowstone.command.minecraft;
import java.util.Collections;
+import net.glowstone.GlowServer;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
-import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.VanillaCommand;
public class PardonCommand extends VanillaCommand {
+ /**
+ * Creates the instance for this command.
+ */
public PardonCommand() {
super("pardon", "Unbans a player from the server.", "/pardon ",
Collections.emptyList());
@@ -26,14 +29,25 @@ public boolean execute(CommandSender sender, String label, String[] args) {
return false;
}
String name = args[0];
- OfflinePlayer player = Bukkit.getOfflinePlayer(name);
- BanList banList = Bukkit.getServer().getBanList(BanList.Type.NAME);
- if (!banList.isBanned(player.getName())) {
- sender.sendMessage(ChatColor.RED + "Could not unban player " + name);
- return false;
- }
- banList.pardon(player.getName());
- sender.sendMessage("Unbanned player " + name);
+ GlowServer server = (GlowServer) Bukkit.getServer();
+ // asynchronously lookup player
+ server.getOfflinePlayerAsync(name).whenCompleteAsync((player, ex) -> {
+ if (ex != null) {
+ sender.sendMessage(ChatColor.RED + "Failed to unban " + name + ": "
+ + ex.getMessage());
+ ex.printStackTrace();
+ return;
+ }
+ BanList banList = Bukkit.getServer().getBanList(BanList.Type.NAME);
+ if (!banList.isBanned(player.getName())) {
+ sender.sendMessage(ChatColor.RED + "Could not unban player " + player.getName()
+ + ": not banned");
+ return;
+ }
+ banList.pardon(player.getName());
+ sender.sendMessage("Unbanned player " + name);
+ });
+ // todo: asynchronous command callbacks?
return true;
}
}
diff --git a/src/main/java/net/glowstone/command/minecraft/PardonIpCommand.java b/src/main/java/net/glowstone/command/minecraft/PardonIpCommand.java
index 693615ff5a..c6ddf8a0c4 100644
--- a/src/main/java/net/glowstone/command/minecraft/PardonIpCommand.java
+++ b/src/main/java/net/glowstone/command/minecraft/PardonIpCommand.java
@@ -9,6 +9,9 @@
public class PardonIpCommand extends VanillaCommand {
+ /**
+ * Creates the instance for this command.
+ */
public PardonIpCommand() {
super("pardon-ip", "Unbans an IP address from the server.", "/pardon-ip ",
Collections.emptyList());
diff --git a/src/main/java/net/glowstone/command/minecraft/PlaySoundCommand.java b/src/main/java/net/glowstone/command/minecraft/PlaySoundCommand.java
index 9f5e50eab5..1492d65f38 100644
--- a/src/main/java/net/glowstone/command/minecraft/PlaySoundCommand.java
+++ b/src/main/java/net/glowstone/command/minecraft/PlaySoundCommand.java
@@ -29,6 +29,9 @@ public class PlaySoundCommand extends VanillaCommand {
private static final Set SOUNDS = GlowSound.getSounds().keySet();
+ /**
+ * Creates the instance for this command.
+ */
public PlaySoundCommand() {
super("playsound", "Plays a sound.",
"/playsound