Added Preview command.
Used to get a preview of your world so you could edit it and stuff.
This commit is contained in:
		@@ -1,5 +1,6 @@
 | 
				
			|||||||
package nl.Steffion.BlockHunt;
 | 
					package nl.Steffion.BlockHunt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import nl.Steffion.BlockHunt.Listeners.PlayerListener;
 | 
				
			||||||
import nl.Steffion.BlockHunt.Managers.CommandC;
 | 
					import nl.Steffion.BlockHunt.Managers.CommandC;
 | 
				
			||||||
import nl.Steffion.BlockHunt.Managers.ConfigC;
 | 
					import nl.Steffion.BlockHunt.Managers.ConfigC;
 | 
				
			||||||
import nl.Steffion.BlockHunt.Managers.MessageM;
 | 
					import nl.Steffion.BlockHunt.Managers.MessageM;
 | 
				
			||||||
@@ -18,6 +19,8 @@ public class BlockHunt extends JavaPlugin implements Listener {
 | 
				
			|||||||
	public void onEnable() {
 | 
						public void onEnable() {
 | 
				
			||||||
		W.newFiles();
 | 
							W.newFiles();
 | 
				
			||||||
		getServer().getPluginManager().registerEvents(this, this);
 | 
							getServer().getPluginManager().registerEvents(this, this);
 | 
				
			||||||
 | 
							getServer().getPluginManager().registerEvents(new PlayerListener(this),
 | 
				
			||||||
 | 
									this);
 | 
				
			||||||
		MessageM.sendFMessage(null, ConfigC.log_Enabled, true, "name-"
 | 
							MessageM.sendFMessage(null, ConfigC.log_Enabled, true, "name-"
 | 
				
			||||||
				+ W.pluginName, "version-" + W.pluginVersion, "autors-"
 | 
									+ W.pluginName, "version-" + W.pluginVersion, "autors-"
 | 
				
			||||||
				+ W.pluginAutors);
 | 
									+ W.pluginAutors);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										73
									
								
								src/nl/Steffion/BlockHunt/Commands/CMDpreview.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								src/nl/Steffion/BlockHunt/Commands/CMDpreview.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,73 @@
 | 
				
			|||||||
 | 
					package nl.Steffion.BlockHunt.Commands;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.io.File;
 | 
				
			||||||
 | 
					import java.io.IOException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import nl.Steffion.BlockHunt.W;
 | 
				
			||||||
 | 
					import nl.Steffion.BlockHunt.Managers.CommandC;
 | 
				
			||||||
 | 
					import nl.Steffion.BlockHunt.Managers.ConfigC;
 | 
				
			||||||
 | 
					import nl.Steffion.BlockHunt.Managers.FileM;
 | 
				
			||||||
 | 
					import nl.Steffion.BlockHunt.Managers.MessageM;
 | 
				
			||||||
 | 
					import nl.Steffion.BlockHunt.Managers.PlayerM;
 | 
				
			||||||
 | 
					import nl.Steffion.BlockHunt.Managers.PlayerM.PermsC;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
 | 
					import org.bukkit.World;
 | 
				
			||||||
 | 
					import org.bukkit.WorldCreator;
 | 
				
			||||||
 | 
					import org.bukkit.command.Command;
 | 
				
			||||||
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class CMDpreview extends DefaultCMD {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Override
 | 
				
			||||||
 | 
						public boolean exectue(Player player, Command cmd, String label,
 | 
				
			||||||
 | 
								String[] args) {
 | 
				
			||||||
 | 
							if (PlayerM.hasPerm(player, PermsC.preview, true)) {
 | 
				
			||||||
 | 
								if (args.length == 1) {
 | 
				
			||||||
 | 
									MessageM.sendFMessage(player, ConfigC.error_notEnoughArguments,
 | 
				
			||||||
 | 
											true, "syntax-" + CommandC.PREVIEW.usage);
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									File arenaworldFolder = new File("plugins/" + W.pluginName
 | 
				
			||||||
 | 
											+ "/defaultArenas/" + args[1]);
 | 
				
			||||||
 | 
									if (!arenaworldFolder.exists()) {
 | 
				
			||||||
 | 
										MessageM.sendFMessage(player, ConfigC.error_noArena, true,
 | 
				
			||||||
 | 
												"name-" + args[1]);
 | 
				
			||||||
 | 
										return true;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									boolean notFound = true;
 | 
				
			||||||
 | 
									int subID = 1;
 | 
				
			||||||
 | 
									while (notFound) {
 | 
				
			||||||
 | 
										File destFolder = new File("plugins/" + W.pluginName
 | 
				
			||||||
 | 
												+ "/loadedArenas/" + args[1] + "_" + subID);
 | 
				
			||||||
 | 
										if (!destFolder.exists()) {
 | 
				
			||||||
 | 
											MessageM.sendFMessage(player,
 | 
				
			||||||
 | 
													ConfigC.normal_previewWorld, true);
 | 
				
			||||||
 | 
											try {
 | 
				
			||||||
 | 
												FileM.copyFolder(arenaworldFolder, destFolder);
 | 
				
			||||||
 | 
												W.previewWorlds.add(destFolder.getPath());
 | 
				
			||||||
 | 
												MessageM.broadcastMessage(destFolder.getPath(),
 | 
				
			||||||
 | 
														false);
 | 
				
			||||||
 | 
											} catch (IOException e) {
 | 
				
			||||||
 | 
												e.printStackTrace();
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
											WorldCreator wc = new WorldCreator(destFolder.getPath());
 | 
				
			||||||
 | 
											Bukkit.getServer().createWorld(wc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
											World world = Bukkit.getWorld(destFolder.getPath());
 | 
				
			||||||
 | 
											player.teleport(world.getSpawnLocation());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
											notFound = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
											MessageM.sendFMessage(player,
 | 
				
			||||||
 | 
													ConfigC.normal_previewWorldDone, true);
 | 
				
			||||||
 | 
										} else {
 | 
				
			||||||
 | 
											subID = subID + 1;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										90
									
								
								src/nl/Steffion/BlockHunt/Listeners/PlayerListener.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								src/nl/Steffion/BlockHunt/Listeners/PlayerListener.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,90 @@
 | 
				
			|||||||
 | 
					package nl.Steffion.BlockHunt.Listeners;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.io.File;
 | 
				
			||||||
 | 
					import java.io.IOException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import nl.Steffion.BlockHunt.BlockHunt;
 | 
				
			||||||
 | 
					import nl.Steffion.BlockHunt.W;
 | 
				
			||||||
 | 
					import nl.Steffion.BlockHunt.Managers.ConfigC;
 | 
				
			||||||
 | 
					import nl.Steffion.BlockHunt.Managers.FileM;
 | 
				
			||||||
 | 
					import nl.Steffion.BlockHunt.Managers.MessageM;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					import org.bukkit.event.EventHandler;
 | 
				
			||||||
 | 
					import org.bukkit.event.EventPriority;
 | 
				
			||||||
 | 
					import org.bukkit.event.Listener;
 | 
				
			||||||
 | 
					import org.bukkit.event.player.PlayerTeleportEvent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class PlayerListener implements Listener {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private BlockHunt plugin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public PlayerListener (BlockHunt plugin) {
 | 
				
			||||||
 | 
							this.plugin = plugin;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@EventHandler(priority = EventPriority.HIGHEST)
 | 
				
			||||||
 | 
						public void onPlayerTeleportEvent(PlayerTeleportEvent event) {
 | 
				
			||||||
 | 
							final Player player = event.getPlayer();
 | 
				
			||||||
 | 
							MessageM.broadcastMessage("-2", false);
 | 
				
			||||||
 | 
							if (W.previewWorlds.contains(event.getFrom().getWorld().getName())) {
 | 
				
			||||||
 | 
								MessageM.broadcastMessage("-1", false);
 | 
				
			||||||
 | 
								if (!event.getFrom().getWorld().getName()
 | 
				
			||||||
 | 
										.equals(event.getTo().getWorld().getName())) {
 | 
				
			||||||
 | 
									MessageM.broadcastMessage("0", false);
 | 
				
			||||||
 | 
									final String worldLoc = event.getFrom().getWorld().getName();
 | 
				
			||||||
 | 
									boolean unload = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									for (Player pl : Bukkit.getOnlinePlayers()) {
 | 
				
			||||||
 | 
										MessageM.broadcastMessage("1", false);
 | 
				
			||||||
 | 
										if (pl.getLocation().getWorld().getName().equals(worldLoc)) {
 | 
				
			||||||
 | 
											MessageM.broadcastMessage("2", false);
 | 
				
			||||||
 | 
											if (!pl.equals(player)) {
 | 
				
			||||||
 | 
												MessageM.broadcastMessage("3a", false);
 | 
				
			||||||
 | 
												unload = false;
 | 
				
			||||||
 | 
											} else {
 | 
				
			||||||
 | 
												MessageM.broadcastMessage("3b", false);
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									MessageM.broadcastMessage("4", false);
 | 
				
			||||||
 | 
									if (unload) {
 | 
				
			||||||
 | 
										MessageM.broadcastMessage("5", false);
 | 
				
			||||||
 | 
										Bukkit.getScheduler().runTaskLaterAsynchronously(
 | 
				
			||||||
 | 
												this.plugin, new Runnable() {
 | 
				
			||||||
 | 
													@Override
 | 
				
			||||||
 | 
													public void run() {
 | 
				
			||||||
 | 
														Bukkit.unloadWorld(
 | 
				
			||||||
 | 
																Bukkit.getWorld(worldLoc), false);
 | 
				
			||||||
 | 
														MessageM.sendFMessage(
 | 
				
			||||||
 | 
																player,
 | 
				
			||||||
 | 
																ConfigC.normal_previewWorldUnloaded,
 | 
				
			||||||
 | 
																true);
 | 
				
			||||||
 | 
													}
 | 
				
			||||||
 | 
												}, 20);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										Bukkit.getScheduler().runTaskLaterAsynchronously(
 | 
				
			||||||
 | 
												this.plugin, new Runnable() {
 | 
				
			||||||
 | 
													@Override
 | 
				
			||||||
 | 
													public void run() {
 | 
				
			||||||
 | 
														try {
 | 
				
			||||||
 | 
															FileM.delete(new File(worldLoc));
 | 
				
			||||||
 | 
														} catch (IOException e) {
 | 
				
			||||||
 | 
															e.printStackTrace();
 | 
				
			||||||
 | 
														}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
														MessageM.sendFMessage(player,
 | 
				
			||||||
 | 
																ConfigC.normal_previewWorldDeleted,
 | 
				
			||||||
 | 
																true);
 | 
				
			||||||
 | 
													}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
												}, 40);
 | 
				
			||||||
 | 
										W.previewWorlds
 | 
				
			||||||
 | 
												.remove(event.getFrom().getWorld().getName());
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -50,6 +50,14 @@ public enum CommandC {
 | 
				
			|||||||
			ConfigC.help_list,
 | 
								ConfigC.help_list,
 | 
				
			||||||
			1,
 | 
								1,
 | 
				
			||||||
			W.pluginName + " <list|l>"),
 | 
								W.pluginName + " <list|l>"),
 | 
				
			||||||
 | 
						PREVIEW ("BlockHunt%preview_",
 | 
				
			||||||
 | 
								"BlockHunt%p_",
 | 
				
			||||||
 | 
								new CMDpreview(),
 | 
				
			||||||
 | 
								ConfigC.commandEnabled_preview,
 | 
				
			||||||
 | 
								PermsC.preview,
 | 
				
			||||||
 | 
								ConfigC.help_preview,
 | 
				
			||||||
 | 
								1,
 | 
				
			||||||
 | 
								W.pluginName + " <preview|p> <arenaname>"),
 | 
				
			||||||
	NOT_FOUND ("%_",
 | 
						NOT_FOUND ("%_",
 | 
				
			||||||
			"%_",
 | 
								"%_",
 | 
				
			||||||
			new CMDnotfound(),
 | 
								new CMDnotfound(),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,6 +19,7 @@ public enum ConfigC {
 | 
				
			|||||||
	commandEnabled_help (true, W.config),
 | 
						commandEnabled_help (true, W.config),
 | 
				
			||||||
	commandEnabled_reload (true, W.config),
 | 
						commandEnabled_reload (true, W.config),
 | 
				
			||||||
	commandEnabled_list (true, W.config),
 | 
						commandEnabled_list (true, W.config),
 | 
				
			||||||
 | 
						commandEnabled_preview (true, W.config),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	log_Enabled ("%N%name%&a&k + %N%version% is now Enabled. Made by %A%autors%%N.",
 | 
						log_Enabled ("%N%name%&a&k + %N%version% is now Enabled. Made by %A%autors%%N.",
 | 
				
			||||||
			W.messages),
 | 
								W.messages),
 | 
				
			||||||
@@ -29,8 +30,17 @@ public enum ConfigC {
 | 
				
			|||||||
	help_help ("%NShows a list of commands.", W.messages),
 | 
						help_help ("%NShows a list of commands.", W.messages),
 | 
				
			||||||
	help_reload ("%NReloads all configs.", W.messages),
 | 
						help_reload ("%NReloads all configs.", W.messages),
 | 
				
			||||||
	help_list ("%NDisplays a list of available arenas.", W.messages),
 | 
						help_list ("%NDisplays a list of available arenas.", W.messages),
 | 
				
			||||||
 | 
						help_preview ("%NMakes a copy of an arena to make changes in your arena.",
 | 
				
			||||||
 | 
								W.messages),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	normal_reloadedConfigs ("&aReloaded all configs!", W.messages),
 | 
						normal_reloadedConfigs ("&aReloaded all configs!", W.messages),
 | 
				
			||||||
 | 
						normal_previewWorld ("%NMaking a preview world for you...", W.messages),
 | 
				
			||||||
 | 
						normal_previewWorldDone ("%NYour preview world has been created! Sending you...",
 | 
				
			||||||
 | 
								W.messages),
 | 
				
			||||||
 | 
						normal_previewWorldUnloaded ("%NYour preview world has been %Eunloaded%N!",
 | 
				
			||||||
 | 
								W.messages),
 | 
				
			||||||
 | 
						normal_previewWorldDeleted ("%NYour preview world has been %Edeleted%N!",
 | 
				
			||||||
 | 
								W.messages),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	error_noPermission ("%EYou don't have the permissions to do that!",
 | 
						error_noPermission ("%EYou don't have the permissions to do that!",
 | 
				
			||||||
			W.messages),
 | 
								W.messages),
 | 
				
			||||||
@@ -38,7 +48,8 @@ public enum ConfigC {
 | 
				
			|||||||
	error_commandNotFound ("%ECouldn't find the command. Try %A/"
 | 
						error_commandNotFound ("%ECouldn't find the command. Try %A/"
 | 
				
			||||||
			+ W.pluginName + " help %Efor more info.", W.messages),
 | 
								+ W.pluginName + " help %Efor more info.", W.messages),
 | 
				
			||||||
	error_notEnoughArguments ("%EYou're missing arguments, correct syntax: %A/%syntax%",
 | 
						error_notEnoughArguments ("%EYou're missing arguments, correct syntax: %A/%syntax%",
 | 
				
			||||||
			W.messages);
 | 
								W.messages),
 | 
				
			||||||
 | 
						error_noArena ("%ENo arena found with the name '%A%name%%E'.", W.messages);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Object value;
 | 
						Object value;
 | 
				
			||||||
	ConfigM config;
 | 
						ConfigM config;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,7 +19,8 @@ public class PlayerM {
 | 
				
			|||||||
		info (main + "info", PType.ALL),
 | 
							info (main + "info", PType.ALL),
 | 
				
			||||||
		help (main + "help", PType.ALL),
 | 
							help (main + "help", PType.ALL),
 | 
				
			||||||
		reload (main + "reload", PType.MODERATOR),
 | 
							reload (main + "reload", PType.MODERATOR),
 | 
				
			||||||
		list (main + "list", PType.MODERATOR);
 | 
							list (main + "list", PType.MODERATOR),
 | 
				
			||||||
 | 
							preview (main + "preview", PType.ADMIN);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public String perm;
 | 
							public String perm;
 | 
				
			||||||
		public PType type;
 | 
							public PType type;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,6 +17,7 @@ public class W {
 | 
				
			|||||||
	public static String pluginMainPermission = pluginName + ".";
 | 
						public static String pluginMainPermission = pluginName + ".";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public static ArrayList<String> newFiles = new ArrayList<String>();
 | 
						public static ArrayList<String> newFiles = new ArrayList<String>();
 | 
				
			||||||
 | 
						public static ArrayList<String> previewWorlds = new ArrayList<String>();
 | 
				
			||||||
	public static ConfigM config = new ConfigM("config", "");
 | 
						public static ConfigM config = new ConfigM("config", "");
 | 
				
			||||||
	public static ConfigM messages = new ConfigM("messages", "");
 | 
						public static ConfigM messages = new ConfigM("messages", "");
 | 
				
			||||||
	public static ConfigM note1 = new ConfigM("PLACE WORLD FOLDERS HERE!",
 | 
						public static ConfigM note1 = new ConfigM("PLACE WORLD FOLDERS HERE!",
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user