Skip to content

Commit

Permalink
Improved signs, menu and added a spawn schematic
Browse files Browse the repository at this point in the history
  • Loading branch information
rlf committed Jul 14, 2018
1 parent 9881b77 commit 1af3736
Show file tree
Hide file tree
Showing 30 changed files with 481 additions and 215 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class PurgeCommand extends AbstractCommand {
private String days = null;

public PurgeCommand(uSkyBlock plugin) {
super("purge", "usb.admin.purge", "time-in-days|stop ?force", tr("purges all abandoned islands"));
super("purge", "usb.admin.purge", "time-in-days|stop ?level ?force", tr("purges all abandoned islands"));
this.plugin = plugin;
}

Expand All @@ -38,27 +38,34 @@ public boolean execute(final CommandSender sender, String alias, Map<String, Obj
return false;
}
days = args[0];
final boolean force = args.length > 1 && args[1].equalsIgnoreCase("force");
double purgeLevel = plugin.getConfig().getDouble("options.advanced.purgeLevel", 10);
if (args.length > 1 && args[1].matches("[0-9]+([.,][0-9]+)?")) {
try {
purgeLevel = Double.parseDouble(args[1]);
} catch (NumberFormatException e) {
sender.sendMessage(tr("\u00a74The level must be a valid number"));
return false;
}
}
final boolean force = args[args.length-1].equalsIgnoreCase("force");

final int time = Integer.parseInt(days, 10) * 24;
sender.sendMessage(tr("\u00a7eFinding all islands that has been abandoned for more than {0} days.", args[0]));
scanTask = new PurgeScanTask(plugin, plugin.directoryIslands, time, sender, new Runnable() {
@Override
public void run() {
if (force) {
doPurge(sender);
} else {
int timeout = plugin.getConfig().getInt("options.advanced.purgeTimeout", 600000);
sender.sendMessage(tr("\u00a74PURGE:\u00a7e Repeat the command within {0} to accept.", TimeUtil.millisAsString(timeout)));
new BukkitRunnable() {
@Override
public void run() {
if (scanTask.isActive()) {
sender.sendMessage("\u00a77purge timed out");
scanTask.stop();
}
sender.sendMessage(tr("\u00a7eFinding all islands that has been abandoned for more than {0} days below level {1}", args[0], purgeLevel));
scanTask = new PurgeScanTask(plugin, plugin.directoryIslands, time, purgeLevel, sender, () -> {
if (force) {
doPurge(sender);
} else {
int timeout = plugin.getConfig().getInt("options.advanced.purgeTimeout", 600000);
sender.sendMessage(tr("\u00a74PURGE:\u00a7e Repeat the command within {0} to accept.", TimeUtil.millisAsString(timeout)));
new BukkitRunnable() {
@Override
public void run() {
if (scanTask.isActive()) {
sender.sendMessage("\u00a77purge timed out");
scanTask.stop();
}
}.runTaskLaterAsynchronously(plugin, TimeUtil.millisAsTicks(timeout));
}
}
}.runTaskLaterAsynchronously(plugin, TimeUtil.millisAsTicks(timeout));
}
});
scanTask.runTaskAsynchronously(plugin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public boolean execute(final CommandSender sender, String alias, Map<String, Obj
String playerName = args[0];
Player player = (Player) sender;
if (uSkyBlock.getInstance().devSetPlayerIsland(player, player.getLocation(), playerName)) {
sender.sendMessage(I18nUtil.tr("\u00a7aSet {0}'s island to the bedrock nearest you.", playerName));
sender.sendMessage(I18nUtil.tr("\u00a7aSet {0}'s island to the current island.", playerName));
} else {
sender.sendMessage(I18nUtil.tr("\u00a74Bedrock not found: unable to set the island!"));
sender.sendMessage(I18nUtil.tr("\u00a74Island not found: unable to set the island!"));
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import dk.lockfuglsang.minecraft.file.FileUtil;
import dk.lockfuglsang.minecraft.util.TimeUtil;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
Expand Down Expand Up @@ -38,15 +36,15 @@ public class PurgeScanTask extends BukkitRunnable {
private volatile boolean active;
private boolean done;

public PurgeScanTask(uSkyBlock plugin, File islandDir, int time, CommandSender sender, Runnable callback) {
public PurgeScanTask(uSkyBlock plugin, File islandDir, int time, double purgeLevel, CommandSender sender, Runnable callback) {
this.plugin = plugin;
this.sender = sender;
this.callback = callback;
this.cutOff = System.currentTimeMillis() - (time * 3600000L);
String[] islandList = islandDir.list(IslandUtil.createIslandFilenameFilter());
this.islandList = new ArrayList<>(Arrays.asList(islandList));
purgeList = new ArrayList<>();
purgeLevel = plugin.getConfig().getDouble("options.advanced.purgeLevel", 10);
this.purgeLevel = purgeLevel;
int feedbackEvery = plugin.getConfig().getInt("async.long.feedbackEvery", 30000);
tStart = System.currentTimeMillis();
tracker = new ProgressTracker(sender, marktr("\u00a77- SCANNING: {0,number,##}% ({1}/{2} failed: {3}) ~ {4}"), 25, feedbackEvery);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package us.talabrek.ultimateskyblock.event;

import dk.lockfuglsang.minecraft.util.ItemStackUtil;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
Expand All @@ -12,7 +13,6 @@
import org.bukkit.inventory.ItemStack;
import us.talabrek.ultimateskyblock.challenge.Challenge;
import us.talabrek.ultimateskyblock.uSkyBlock;
import dk.lockfuglsang.minecraft.util.ItemStackUtil;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -69,6 +69,7 @@ public void onBlockHit(PlayerInteractEvent e) {
if (!plugin.isSkyAssociatedWorld(player.getWorld()) || !isTool(e.getItem())) {
return;
}

// We are in a skyworld, a block has been hit, with the tool
Material block = e.getClickedBlock().getType();
short data = e.getClickedBlock().getData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,20 @@ public static WorldEditPlugin getWorldEdit() {

public static void loadIslandSchematic(final File file, final Location origin, PlayerPerk playerPerk) {
log.finer("Trying to load schematic " + file);
try (InputStream in = new BufferedInputStream(new FileInputStream(file))) {
boolean noAir = false;
boolean entities = true;
Vector to = new Vector(origin.getBlockX(), origin.getBlockY(), origin.getBlockZ());
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(origin.getWorld()), -1);
try {
SchematicFormat.getFormat(file)
.load(file)
.paste(editSession, to, noAir, entities);
editSession.flushQueue();
} catch (MaxChangedBlocksException | IOException | DataException e) {
log.log(Level.INFO, "Unable to paste schematic " + file, e);
}
} catch (IOException e) {
LogUtil.log(Level.WARNING, "Unable to load schematic " + file, e);
if (file == null || !file.exists() || !file.canRead()) {
LogUtil.log(Level.WARNING, "Unable to load schematic " + file);
}
boolean noAir = false;
boolean entities = true;
Vector to = new Vector(origin.getBlockX(), origin.getBlockY(), origin.getBlockZ());
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(origin.getWorld()), -1);
try {
SchematicFormat.getFormat(file)
.load(file)
.paste(editSession, to, noAir, entities);
editSession.flushQueue();
} catch (MaxChangedBlocksException | IOException | DataException e) {
log.log(Level.INFO, "Unable to paste schematic " + file, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package us.talabrek.ultimateskyblock.island;

import dk.lockfuglsang.minecraft.file.FileUtil;
import dk.lockfuglsang.minecraft.util.ItemStackUtil;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
Expand All @@ -14,30 +15,27 @@
import us.talabrek.ultimateskyblock.player.Perk;
import us.talabrek.ultimateskyblock.player.PlayerPerk;
import us.talabrek.ultimateskyblock.uSkyBlock;
import dk.lockfuglsang.minecraft.util.ItemStackUtil;
import us.talabrek.ultimateskyblock.util.LocationUtil;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.security.CodeSource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

/**
* The factory for creating islands (actual blocks).
*/
@SuppressWarnings("deprecation")
public class IslandGenerator {
private static final List<String> USB_SCHEMATICS = Arrays.asList(
"uSkyBlockNether",
"default",
"skySMP"
);
private static final Logger log = Logger.getLogger(IslandGenerator.class.getName());
private final File[] schemFiles;
private final File netherSchematic;
Expand All @@ -49,14 +47,27 @@ public IslandGenerator(File dataFolder, final FileConfiguration config) {
directorySchematics.mkdir();
}
netherSchematic = new File(directorySchematics, config.getString("nether.schematicName", "uSkyBlockNether") + ".schematic");
for (String schem : USB_SCHEMATICS) {
File f = new File(directorySchematics, schem + ".schematic");
if (!f.exists()) {
try (InputStream inputStream = uSkyBlock.class.getClassLoader().getResourceAsStream("schematics/" + schem + ".schematic")) {
FileUtil.copy(inputStream, f);
} catch (IOException e) {
log.log(Level.WARNING, "Unable to load schematic " + schem, e);
CodeSource codeSource = getClass().getProtectionDomain().getCodeSource();
if (codeSource != null) {
URL jar = codeSource.getLocation();
try (ZipInputStream zin = new ZipInputStream(jar.openStream())) {
ZipEntry entry = null;
while ((entry = zin.getNextEntry()) != null) {
String prefix = "schematics/";
if (entry.getName().startsWith(prefix) && entry.getName().endsWith(".schematic")) {
File f = new File(directorySchematics + File.separator + entry.getName().substring(prefix.length()));
if (!f.exists()) {
try (InputStream inputStream = uSkyBlock.class.getClassLoader().getResourceAsStream(entry.getName())) {
FileUtil.copy(inputStream, f);
} catch (IOException e) {
log.log(Level.WARNING, "Unable to load schematic " + entry.getName(), e);
}
}
}
zin.closeEntry();
}
} catch (IOException e) {
log.log(Level.WARNING, "Unable to find schematics in jar", e);
}
}
this.schemFiles = directorySchematics.listFiles(new FilenameFilter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ private Inventory createInitMenu(Player player) {
int menuSize = (int) Math.ceil(getMaxSchemeIndex(schemeNames) / 9d)*9;
Inventory menu = Bukkit.createInventory(null, menuSize, "\u00a79" + tr("Island Create Menu"));
List<String> lores = new ArrayList<>();
ItemStack menuItem = new ItemStack(Material.GRASS, 1);
ItemStack menuItem = new ItemStack(Material.SAPLING, 1);
ItemMeta meta = menuItem.getItemMeta();
meta.setDisplayName(tr("\u00a7a\u00a7lStart an Island"));
addLore(lores, "\u00a7f", tr("Start your skyblock journey\nby starting your own island.\nComplete challenges to earn\nitems and skybucks to help\nexpand your skyblock. You can\ninvite others to join in\nbuilding your island empire!\n\u00a7e\u00a7lClick here to start!"));
Expand All @@ -463,7 +463,7 @@ private Inventory createInitMenu(Player player) {
menu.addItem(menuItem);
lores.clear();

if (plugin.getConfig().getBoolean("island-schemes-enabled", true)) {
if (plugin.getConfig().getBoolean("island-schemes-enabled", true) && schemeNames.size() > 1) {
int index = 1;
for (String schemeName : schemeNames) {
IslandPerk islandPerk = plugin.getPerkLogic().getIslandPerk(schemeName);
Expand All @@ -478,7 +478,6 @@ private Inventory createInitMenu(Player player) {
if (lores == null) {
lores = new ArrayList<>();
}
// TODO: 30/01/2016 - R4zorax: Add the extra items?
if (player.hasPermission(islandPerk.getPermission())) {
addLore(lores, tr("\u00a7aClick to create!"));
} else {
Expand All @@ -490,6 +489,15 @@ private Inventory createInitMenu(Player player) {
}
}

lores.clear();
menuItem = new ItemStack(Material.GRASS, 1);
meta = menuItem.getItemMeta();
meta.setDisplayName(tr("\u00a7a\u00a7lReturn to Spawn"));
addLore(lores, "\u00a7f", tr("Teleport to the spawn area."));
meta.setLore(lores);
menuItem.setItemMeta(meta);
menu.setItem(menuSize-2, menuItem);

lores.clear();
menuItem = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
final SkullMeta meta2 = (SkullMeta) menuItem.getItemMeta();
Expand All @@ -511,7 +519,7 @@ private int getMaxSchemeIndex(List<String> schemeNames) {
index++;
}
}
return index + 2;
return index + 3;
}

private Inventory createMainMenu(Player player) {
Expand Down Expand Up @@ -627,6 +635,15 @@ private Inventory createMainMenu(Player player) {
menu.addItem(menuItem);
lores.clear();

menuItem = new ItemStack(Material.GRASS, 1);
meta4 = menuItem.getItemMeta();
meta4.setDisplayName(tr("\u00a7a\u00a7lReturn to Spawn"));
addLore(lores, "\u00a7f", tr("Teleport to the spawn area."));
meta4.setLore(lores);
menuItem.setItemMeta(meta4);
menu.addItem(menuItem);
lores.clear();

menuItem = new ItemStack(Material.BOOK_AND_QUILL, 1);
meta4 = menuItem.getItemMeta();
meta4.setDisplayName(tr("\u00a7a\u00a7lIsland Log"));
Expand All @@ -636,7 +653,7 @@ private Inventory createMainMenu(Player player) {
menu.setItem(8, menuItem); // Last item, first line
lores.clear();

menuItem = new ItemStack(Material.BED, 1);
menuItem = new ItemStack(Material.BED, 1, (short)14); // red bed
meta4 = menuItem.getItemMeta();
meta4.setDisplayName(tr("\u00a7a\u00a7lChange Home Location"));
addLore(lores, "\u00a7f", tr("When you teleport to your\nisland you will be taken to\nthis location.\n\u00a7e\u00a7lClick here to change."));
Expand Down Expand Up @@ -762,6 +779,9 @@ private void onClickCreateMenu(InventoryClickEvent event, Player p, ItemMeta met
if (slotIndex == 0) {
p.closeInventory();
p.performCommand("island create");
} else if (slotIndex == menuSize-2) {
p.closeInventory();
p.performCommand("island spawn");
} else if (slotIndex == menuSize-1) {
p.closeInventory();
p.performCommand("island accept");
Expand Down Expand Up @@ -793,6 +813,9 @@ private void onClickMainMenu(InventoryClickEvent event, ItemStack currentItem, P
p.closeInventory();
p.performCommand("island sethome");
p.performCommand("island");
} else if (currentItem.getType() == Material.GRASS) {
p.closeInventory();
p.performCommand("island spawn");
} else if (currentItem.getType() == Material.HOPPER) {
p.closeInventory();
p.performCommand("island setwarp");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public PerkLogic(uSkyBlock plugin, IslandGenerator islandGenerator) {
.extraItems(ItemStackUtil.createItemList(config.getString("extraItems", null), config.getStringList("extraItems")))
.build();
ItemStack itemStack = ItemStackUtil.createItemStack(
config.getString("displayItem", "GRASS"),
config.getString("displayItem", "SAPLING"),
schemeName,
config.getString("description", null)
);
Expand All @@ -75,7 +75,7 @@ public PerkLogic(uSkyBlock plugin, IslandGenerator islandGenerator) {
Perk perk = new PerkBuilder(defaultPerk).schematics(schemeName).build();
if (!islandPerks.containsKey(schemeName)) {
islandPerks.put(schemeName, new IslandPerk(schemeName, "usb.schematic." + schemeName,
ItemStackUtil.createItemStack("GRASS", schemeName, null), perk,
ItemStackUtil.createItemStack("SAPLING", schemeName, null), perk,
1d, 0d));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void run() {
public void spawnTeleport(final Player player, boolean force) {
int delay = teleportDelay;
final Location spawnLocation = LocationUtil.centerOnBlock(plugin.getWorld().getSpawnLocation());
if (hasPermission(player, "usb.mod.bypassteleport") || (delay == 0) || force) {
if (player.hasPermission("usb.mod.bypassteleport") || (delay == 0) || force) {
if (Settings.extras_sendToSpawn) {
plugin.execCommand(player, "op:spawn", false);
} else {
Expand Down
Loading

0 comments on commit 1af3736

Please sign in to comment.