Update Villager trading and Events

This commit is contained in:
Sam 2017-01-21 14:21:00 +00:00
parent a16acedb14
commit f5e86f4bc1
16 changed files with 205 additions and 201 deletions

View File

@ -16,7 +16,6 @@ import mineplex.core.MiniPlugin;
import mineplex.core.ReflectivelyCreateMiniPlugin;
import mineplex.core.common.currency.GlobalCurrency;
import mineplex.core.common.util.F;
import mineplex.core.google.GoogleSheetsManager;
@ReflectivelyCreateMiniPlugin
public class EconomyModule extends MiniPlugin
@ -74,6 +73,11 @@ public class EconomyModule extends MiniPlugin
}
}
public void removeFromStore(Player player, int gems)
{
_storedGems.put(player.getUniqueId(), _storedGems.get(player.getUniqueId()) - gems);
}
public int getGems(Player player)
{
return _storedGems.get(player.getUniqueId());

View File

@ -1,7 +1,5 @@
package mineplex.gemhunters.loot;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@ -22,6 +20,7 @@ import org.bukkit.block.Chest;
import org.bukkit.block.DoubleChest;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
@ -32,13 +31,12 @@ import mineplex.core.MiniPlugin;
import mineplex.core.ReflectivelyCreateMiniPlugin;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.common.util.UtilEvent.ActionType;
import mineplex.core.google.GoogleSheetsManager;
import mineplex.core.slack.SlackAPI;
import mineplex.core.slack.SlackMessage;
import mineplex.core.slack.SlackTeam;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.gemhunters.economy.PlayerCashOutCompleteEvent;
@ -48,6 +46,7 @@ import mineplex.gemhunters.loot.deserialisers.LootItemDeserialiser;
import mineplex.gemhunters.loot.rewards.LootItemReward;
import mineplex.gemhunters.loot.rewards.LootRankReward;
import mineplex.gemhunters.safezone.SafezoneModule;
import mineplex.gemhunters.util.SlackSheetsBot;
import mineplex.gemhunters.world.WorldDataModule;
@ReflectivelyCreateMiniPlugin
@ -56,8 +55,6 @@ public class LootModule extends MiniPlugin
private static final String SHEET_FILE_NAME = "GEM_HUNTERS_CHESTS";
private static final String CHEST_MASTER_SHEET_NAME = "CHEST_MASTER";
private static final int MINIMUM_CHEST_ITEMS = 3;
private static final int MAXIMUM_CHEST_ITEMS = 6;
private static final long CHEST_DESPAWN_TIME_OPENED = TimeUnit.SECONDS.toMillis(15);
private static final String[] IGNORED_COLOURS = { "RED" };
private static final int MAX_SEARCH_ATTEMPTS = 40;
@ -65,9 +62,6 @@ public class LootModule extends MiniPlugin
private static final int MAX_CHEST_CHECK_DISTANCE_SQUARED = 4;
private static final LootItemDeserialiser DESERIALISER = new LootItemDeserialiser();
private static final ChestPropertiesDeserialiser CHEST_DESERIALISER = new ChestPropertiesDeserialiser();
private static final String SLACK_CHANNEL_NAME = "#google-sheet-errors";
private static final String SLACK_USERNAME = "Google Sheets";
private static final String SLACK_ICON = "http://moppletop.github.io/mineplex/google-sheets-image.png";
private final GoogleSheetsManager _sheets;
private final SafezoneModule _safezone;
@ -153,6 +147,13 @@ public class LootModule extends MiniPlugin
List<Location> locations = _worldData.getDataLocation(key);
ChestProperties properties = _chestProperties.get(key);
if (!UtilTime.elapsed(properties.getLastSpawn(), properties.getSpawnRate()))
{
continue;
}
properties.setLastSpawn();
// Only spawn more chests if we need to
int max = (int) (_spawnedChest.size() * properties.getPercentile());
int spawned = 0;
@ -223,7 +224,7 @@ public class LootModule extends MiniPlugin
Bukkit.broadcastMessage("Spawned at " + UtilWorld.blockToStrClean(block) + " with key=" + key + " and index=" + index + " and max=" + max);
_spawnedChest.add(new SpawnedChest(chestToPlace, properties, index));
block.setType(Material.CHEST);
block.setType(properties.getBlockMaterial());
}
}
@ -232,7 +233,7 @@ public class LootModule extends MiniPlugin
Block up = block.getRelative(BlockFace.UP);
Block down = block.getRelative(BlockFace.DOWN);
if (block.getType() != Material.AIR || down.getType() == Material.AIR || UtilBlock.liquid(down) || UtilBlock.liquid(up) || UtilBlock.liquid(block) || _safezone.getSafezone(block.getLocation()) != null)
if (block.getType() != Material.AIR || down.getType() == Material.AIR || UtilBlock.liquid(down) || UtilBlock.liquid(up) || UtilBlock.liquid(block) || _safezone.isInSafeZone(block.getLocation()))
{
return false;
}
@ -263,7 +264,7 @@ public class LootModule extends MiniPlugin
{
if (row != 1)
{
reportParsingError(e, key, row);
SlackSheetsBot.reportParsingError(e, "Chest Loot", key, row);
}
continue;
@ -274,7 +275,6 @@ public class LootModule extends MiniPlugin
}
Set<LootItem> items = new HashSet<>();
int row = 0;
for (List<String> rows : map.get(key))
@ -288,7 +288,7 @@ public class LootModule extends MiniPlugin
{
if (row != 1)
{
reportParsingError(e, key, row);
SlackSheetsBot.reportParsingError(e, "Chest Loot", key, row);
}
continue;
@ -342,7 +342,7 @@ public class LootModule extends MiniPlugin
}
}
private LootItem getRandomItem(Set<LootItem> items)
public LootItem getRandomItem(Set<LootItem> items)
{
double totalWeight = 0;
@ -410,7 +410,7 @@ public class LootModule extends MiniPlugin
@EventHandler
public void chestOpen(PlayerInteractEvent event)
{
if (event.isCancelled())
if (event.isCancelled() || !UtilEvent.isAction(event, ActionType.R_BLOCK))
{
return;
}
@ -532,16 +532,4 @@ public class LootModule extends MiniPlugin
}
}
}
private final void reportParsingError(Exception exception, String sheetName, int row)
{
try
{
SlackAPI.getInstance().sendMessage(SlackTeam.DEVELOPER, SLACK_CHANNEL_NAME, new SlackMessage(SLACK_USERNAME, new URL(SLACK_ICON), "A parsing error has occured on sheet *" + sheetName + "* at row *" + row + "*.\n Details: " + exception.getMessage()), true);
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
}
}

View File

@ -97,7 +97,7 @@ public class SafezoneModule extends MiniPlugin
Player player = (Player) event.getEntity();
if (getSafezone(player.getLocation()) != null)
if (isInSafeZone(player.getLocation()))
{
event.setCancelled(true);
}
@ -113,12 +113,17 @@ public class SafezoneModule extends MiniPlugin
Player player = (Player) event.getDamager();
if (getSafezone(player.getLocation()) != null)
if (isInSafeZone(player.getLocation()))
{
event.setCancelled(true);
}
}
public boolean isInSafeZone(Location location)
{
return getSafezone(location) != null;
}
public boolean isInSafeZone(Location location, String safezone)
{
if (safezone == null)

View File

@ -28,14 +28,14 @@ public class GemHuntersScoreboard extends WritableMineplexScoreboard
{
writeNewLine();
write(C.cGreenB + "Gems");
write(C.cGreenB + "Gems Earned");
write(String.valueOf(_economy.getGems(player)));
writeNewLine();
write(C.cYellowB + "World Event");
if (!_worldEvent.isMajorEventActive())
if (!_worldEvent.isEventActive())
{
write(UtilTime.MakeStr(_worldEvent.getLastEventComplete() + _worldEvent.getEventTimer() - System.currentTimeMillis()));
}

View File

@ -7,30 +7,45 @@ import java.util.Map;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Villager;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import com.google.common.collect.Sets;
import mineplex.core.MiniPlugin;
import mineplex.core.ReflectivelyCreateMiniPlugin;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath;
import mineplex.core.google.GoogleSheetsManager;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.google.SheetObjectDeserialiser;
import mineplex.gemhunters.loot.deserialisers.LootItemDeserialiser;
import mineplex.gemhunters.safezone.SafezoneModule;
import mineplex.gemhunters.util.SlackSheetsBot;
import mineplex.gemhunters.world.WorldDataModule;
import net.md_5.bungee.api.ChatColor;
@ReflectivelyCreateMiniPlugin
public class ShopModule extends MiniPlugin
{
private static final String SHEET_FILE_NAME = "GEM_HUNTERS_SHOP";
private static final LootItemDeserialiser DESERIALISER = new LootItemDeserialiser();
private static final SheetObjectDeserialiser<Integer> COST_DESERIALISER = new SheetObjectDeserialiser<Integer>()
{
@Override
public Integer deserialise(String[] values) throws ArrayIndexOutOfBoundsException, NumberFormatException
{
return Integer.parseInt(values[10]);
}
};
private static final int MINIMUM_ITEMS = 1;
private static final int MAXIMUM_ITEMS = 5;
private final GoogleSheetsManager _sheets;
private final SafezoneModule _safezone;
private final WorldDataModule _worldData;
private final Map<String, Set<TradeableItem>> _tradeItems;
private final Map<String, Set<TradeableItem>> _trades;
private boolean _npcsSpawned;
@ -39,110 +54,47 @@ public class ShopModule extends MiniPlugin
super("Shop");
_sheets = require(GoogleSheetsManager.class);
_safezone = require(SafezoneModule.class);
_worldData = require(WorldDataModule.class);
_tradeItems = new HashMap<>();
_trades = new HashMap<>();
//updateVillagerLoot();
runSyncLater(() -> updateVillagerTrades(), 20);
}
public void updateVillagerLoot()
public void updateVillagerTrades()
{
Map<String, List<List<Object>>> map = null;
log("Updating villager trades");
Map<String, List<List<String>>> map = _sheets.getSheetData(SHEET_FILE_NAME);
for (String key : map.keySet())
{
Set<TradeableItem> items = new HashSet<>();
List<List<Object>> grid = map.get(key);
int index = 0;
int row = 0;
for (List<String> rows : map.get(key))
{
row++;
try
{
for (List<Object> values : grid)
{
if (index++ < 2)
{
continue;
}
log("Size = " + values.size());
Material material = Material.valueOf(String.valueOf(values.get(0)));
byte data = Byte.parseByte(String.valueOf(values.get(1)));
int minAmount = 1;
int maxAmount = 1;
try
{
String[] numbers = String.valueOf(values.get(2)).split("-");
if (numbers.length < 2)
{
minAmount = Integer.parseInt(String.valueOf(values.get(2)));
maxAmount = minAmount;
}
else
{
minAmount = Integer.parseInt(numbers[0]);
maxAmount = Integer.parseInt(numbers[1]);
}
}
catch (NumberFormatException e)
{
continue;
}
ItemBuilder builder = new ItemBuilder(material, data);
String title = ChatColor.translateAlternateColorCodes('&', String.valueOf(values.get(3)));
String[] lore = String.valueOf(values.get(4)).split(":");
String[] colouredLore = new String[lore.length];
int loreIndex = 0;
for (String line : lore)
{
colouredLore[loreIndex++] = ChatColor.translateAlternateColorCodes('&', line);
}
builder.setTitle(title);
builder.setLore(colouredLore);
String[] enchants = String.valueOf(values.get(5)).split(",");
for (String enchant : enchants)
{
String[] enchantData = enchant.split(":");
if (enchantData.length < 2)
{
continue;
}
builder.addEnchantment(Enchantment.getByName(enchantData[0]), Integer.parseInt(enchantData[1]));
}
double probability = Double.parseDouble(String.valueOf(values.get(6)));
String metadata = null;
int cost = Integer.parseInt(String.valueOf(values.get(7)));
if (values.size() > 8)
{
metadata = String.valueOf(values.get(8));
}
items.add(new TradeableItem(builder.build(), minAmount, maxAmount, probability, metadata, cost));
}
_tradeItems.put(key, items);
String[] values = rows.toArray(new String[0]);
items.add(new TradeableItem(DESERIALISER.deserialise(values), COST_DESERIALISER.deserialise(values)));
}
catch (Exception e)
{
// TODO send slack message?
e.printStackTrace();
log("An error occured while parsing spreadsheet data! " + key);
if (row != 1)
{
SlackSheetsBot.reportParsingError(e, "Villager Trades", key, row);
}
continue;
}
}
_trades.put(key, items);
}
log("Finished updating villager trades");
}
@EventHandler
@ -155,18 +107,29 @@ public class ShopModule extends MiniPlugin
_npcsSpawned = true;
for (String key : _worldData.getAllSpawnLocations().keySet())
for (String key : _trades.keySet())
{
if (!_tradeItems.containsKey(key))
{
continue;
}
for (Location location : _worldData.getSpawnLocation(key))
{
new TraderNPC(_plugin, location, Villager.class, "Bob", true, Sets.newHashSet(UtilAlg.Random(_tradeItems.get(key))));
boolean vegetated = _safezone.isInSafeZone(location);
Set<TradeableItem> items = getRandomItemSet(_trades.get(key));
new TraderNPC(_plugin, location, Villager.class, "Sam", vegetated, items);
}
}
}
public Set<TradeableItem> getRandomItemSet(Set<TradeableItem> items)
{
int size = UtilMath.rRange(MINIMUM_ITEMS, MAXIMUM_ITEMS);
Set<TradeableItem> items2 = new HashSet<>(size);
for (int i = 0; i < size; i++)
{
items2.add(UtilAlg.Random(items));
}
return items2;
}
}

View File

@ -1,21 +1,24 @@
package mineplex.gemhunters.shop;
import org.bukkit.inventory.ItemStack;
import mineplex.gemhunters.loot.LootItem;
public class TradeableItem extends LootItem
public class TradeableItem
{
private int _cost;
private final LootItem _item;
private final int _cost;
public TradeableItem(ItemStack itemStack, int minAmount, int maxAmount, double probability, String metadata, int cost)
public TradeableItem(LootItem item, int cost)
{
super(itemStack, minAmount, maxAmount, probability, metadata);
_item = item;
_cost = cost;
}
public LootItem getLootItem()
{
return _item;
}
public int getCost()
{
return _cost;

View File

@ -14,16 +14,13 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.Managers;
import mineplex.core.common.Pair;
import mineplex.core.common.currency.GlobalCurrency;
import mineplex.core.donation.DonationManager;
import mineplex.core.donation.Donor;
import mineplex.gemhunters.economy.EconomyModule;
import mineplex.gemhunters.util.SimpleNPC;
public class TraderNPC extends SimpleNPC
{
private final DonationManager _donation;
private final EconomyModule _economy;
private final Set<TradeableItem> _selling;
private final Inventory _inv;
@ -32,16 +29,16 @@ public class TraderNPC extends SimpleNPC
{
super(plugin, spawn, type, name, null, vegetated);
_donation = Managers.require(DonationManager.class);
_economy = Managers.require(EconomyModule.class);
_selling = selling;
_inv = plugin.getServer().createInventory(null, 9, name);
int index = 1;
for (TradeableItem item : selling)
for (TradeableItem item : _selling)
{
_inv.setItem(index++, item.getItemStack());
_inv.setItem(index++, item.getLootItem().getItemStack());
}
}
@ -78,8 +75,7 @@ public class TraderNPC extends SimpleNPC
}
Player player = (Player) event.getWhoClicked();
Donor donor = _donation.Get(player);
int gems = donor.getBalance(GlobalCurrency.GEM);
int gems = _economy.getGems(player);
int cost = fromItemStack(itemStack);
if (cost == 0)
@ -95,7 +91,7 @@ public class TraderNPC extends SimpleNPC
return;
}
donor.addBalance(GlobalCurrency.GEM, -cost);
_economy.removeFromStore(player, cost);
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1, 1.2F);
player.getInventory().addItem(itemStack);
@ -106,7 +102,7 @@ public class TraderNPC extends SimpleNPC
{
for (TradeableItem item : _selling)
{
if (item.getItemStack().isSimilar(itemStack))
if (item.getLootItem().getItemStack().isSimilar(itemStack))
{
return item.getCost();
}

View File

@ -20,7 +20,6 @@ import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEnt;
import mineplex.gemhunters.safezone.SafezoneModule;
import mineplex.gemhunters.util.ColouredTextAnimation;
import mineplex.gemhunters.util.SimpleNPC;
@ -52,7 +51,7 @@ public class SpawnModule extends MiniPlugin
{
if (_spawn == null || _center == null)
{
_spawn = _worldData.getSpawnLocation("Yellow").get(0);
_spawn = _worldData.getCustomLocation("PLAYER_SPAWN").get(0);
_center = _worldData.getCustomLocation("CENTER").get(0);
}
@ -70,9 +69,9 @@ public class SpawnModule extends MiniPlugin
_npcsSpawned = true;
Location location = _worldData.getSpawnLocation("Purple").get(0);
Location location = _worldData.getCustomLocation("TELEPORT_NPC").get(0);
location.setYaw(UtilAlg.GetYaw(location.toVector()));
location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, _spawn)));
new SimpleNPC(_plugin, location, Villager.class, C.cDRed + "! " + C.cRedB + "Enter The World" + C.cDRed + " !", new Callback<Player>()
{
@ -115,7 +114,7 @@ public class SpawnModule extends MiniPlugin
Block up = block.getRelative(BlockFace.UP);
Block down = block.getRelative(BlockFace.DOWN);
if (block.getType() != Material.AIR || down.getType() == Material.AIR || UtilBlock.liquid(down) || UtilBlock.liquid(up) || UtilBlock.liquid(block) || _safezone.getSafezone(block.getLocation()) != null)
if (block.getType() != Material.AIR || down.getType() == Material.AIR || UtilBlock.liquid(down) || UtilBlock.liquid(up) || UtilBlock.liquid(block) || _safezone.isInSafeZone(block.getLocation()))
{
return false;
}

View File

@ -0,0 +1,30 @@
package mineplex.gemhunters.util;
import java.net.MalformedURLException;
import java.net.URL;
import mineplex.core.slack.SlackAPI;
import mineplex.core.slack.SlackMessage;
import mineplex.core.slack.SlackTeam;
public class SlackSheetsBot
{
private static final String SLACK_CHANNEL_NAME = "#google-sheet-errors";
private static final String SLACK_USERNAME = "Google Sheets";
private static final String SLACK_ICON = "http://moppletop.github.io/mineplex/google-sheets-image.png";
public static final void reportParsingError(Exception exception, String spreadsheetName, String sheetName, int row)
{
try
{
SlackAPI.getInstance().sendMessage(SlackTeam.DEVELOPER, SLACK_CHANNEL_NAME, new SlackMessage(SLACK_USERNAME, new URL(SLACK_ICON), "A parsing error has occured on spreadsheet *" + spreadsheetName + "* sheet *" + sheetName + "* at row *" + row + "*.\n Details: " + exception.getMessage()),
true);
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
}
}

View File

@ -21,12 +21,12 @@ import mineplex.gemhunters.worldevent.command.WorldEventCommand;
public class WorldEventModule extends MiniPlugin
{
private static final long EVENT_TIMER = TimeUnit.MINUTES.toMillis(15);
private static final long EVENT_TIMER = TimeUnit.MINUTES.toMillis(30);
private static final long EVENT_COOLDOWN_TIMER = TimeUnit.MINUTES.toMillis(40);
private static final long COMPLETE_TIMER = TimeUnit.SECONDS.toMillis(30);
private final List<WorldEvent> _events;
private long _lastEventComplete;
private int _lastEventId;
private WorldEventModule()
{
@ -47,7 +47,6 @@ public class WorldEventModule extends MiniPlugin
WorldEvent event = eventType.createInstance();
_events.add(event);
_lastEventId = eventType.ordinal();
event.setEventState(WorldEventState.WARMUP);
}
@ -60,7 +59,7 @@ public class WorldEventModule extends MiniPlugin
for (WorldEventType eventType : eventTypes)
{
if (_lastEventId == eventType.ordinal() || eventType.isMajor() || eventType.isTriggerable())
if (UtilTime.elapsed(eventType.getLast(), EVENT_COOLDOWN_TIMER))
{
continue;
}
@ -92,31 +91,32 @@ public class WorldEventModule extends MiniPlugin
if (worldEvent.getEventState() == WorldEventState.COMPLETE && UtilTime.elapsed(worldEvent.getCompleteTime(), COMPLETE_TIMER))
{
if (!worldEvent.getEventType().isTriggerable())
{
_lastEventComplete = System.currentTimeMillis();
}
iterator.remove();
}
if (worldEvent.getEventState() == WorldEventState.LIVE && worldEvent.checkToEnd())
{
_lastEventComplete = System.currentTimeMillis();
worldEvent.setEventState(WorldEventState.COMPLETE);
}
}
if (UtilTime.elapsed(_lastEventComplete, EVENT_TIMER))
if (!isEventActive() && UtilTime.elapsed(_lastEventComplete, EVENT_TIMER))
{
startRandomEvent();
}
}
public boolean isMajorEventActive()
public boolean isEventActive()
{
return !_events.isEmpty();
}
public boolean isGlboalEventActive()
{
for (WorldEvent event : _events)
{
if (event.getEventType().isMajor())
if (event.getEventType().getPriority() == WorldEventPriority.GLOBAL)
{
return true;
}

View File

@ -0,0 +1,8 @@
package mineplex.gemhunters.worldevent;
public enum WorldEventPriority
{
GLOBAL, ISOLATED
}

View File

@ -5,24 +5,18 @@ import mineplex.gemhunters.worldevent.giant.GiantWorldEvent;
public enum WorldEventType
{
GIANT("Zombie Awakening", GiantWorldEvent.class, true, false);
GIANT("Zombie Awakening", GiantWorldEvent.class, WorldEventPriority.GLOBAL);
private String _name;
private Class<? extends WorldEvent> _clazz;
private boolean _major, _triggerable;
private WorldEventPriority _priority;
private long _last;
private WorldEventType(String name, Class<? extends WorldEvent> clazz)
{
this(name, clazz, false, false);
}
private WorldEventType(String name, Class<? extends WorldEvent> clazz, boolean major, boolean triggerable)
private WorldEventType(String name, Class<? extends WorldEvent> clazz, WorldEventPriority priority)
{
_name = name;
_clazz = clazz;
_major = major;
_triggerable = triggerable;
_priority = priority;
_last = 0;
}
@ -47,19 +41,13 @@ public enum WorldEventType
return _name;
}
public boolean isMajor()
public WorldEventPriority getPriority()
{
return _major;
}
public boolean isTriggerable()
{
return _triggerable;
return _priority;
}
public long getLast()
{
return _last;
}
}

View File

@ -37,6 +37,7 @@ public class CustomGiant implements Listener
private static final float DESTORY_FALLING_BLOCK_CHANCE = 0.04F;
private static final float MOVE_FACTOR = 0.3F;
private static final int MAX_SEARCH_DISTANCE_SQUARED = 2500;
private static final int TOO_CLOSE_DISTANCE_SQUARED = 625;
private final SafezoneModule _safezone;
@ -56,6 +57,8 @@ public class CustomGiant implements Listener
_giant.setRemoveWhenFarAway(false);
UtilEnt.vegetate(_giant);
UtilEnt.ghost(_giant, true, false);
UtilEnt.setFakeHead(_giant, true);
_fallback = Managers.get(WorldDataModule.class).getCustomLocation("CENTER").get(0);
}
@ -78,6 +81,16 @@ public class CustomGiant implements Listener
return;
}
if (_target.equals(_fallback) && UtilMath.offsetSquared(_giant.getLocation(), _fallback) < TOO_CLOSE_DISTANCE_SQUARED)
{
return;
}
if (_safezone.isInSafeZone(_giant.getLocation()))
{
_target = _fallback;
}
Vector direction = UtilAlg.getTrajectory2d(_giant.getLocation(), _target).multiply(MOVE_FACTOR);
Location toTeleport = _giant.getLocation().add(direction);
@ -97,6 +110,11 @@ public class CustomGiant implements Listener
for (Block block : UtilBlock.getInBoundingBox(_giant.getLocation().subtract(GIANT_WIDTH, 0, GIANT_WIDTH), _giant.getLocation().add(GIANT_WIDTH, GIANT_HEIGHT, GIANT_WIDTH)))
{
if (_safezone.isInSafeZone(block.getLocation()))
{
continue;
}
if (Math.random() < DESTORY_FALLING_BLOCK_CHANCE)
{
FallingBlock fallingBlock = block.getWorld().spawnFallingBlock(block.getLocation(), block.getType(), block.getData());
@ -125,7 +143,7 @@ public class CustomGiant implements Listener
for (Player player : UtilServer.getPlayers())
{
if (UtilPlayer.isSpectator(player) || _safezone.getSafezone(player.getLocation()) != null)
if (UtilPlayer.isSpectator(player) || _safezone.isInSafeZone(player.getLocation()))
{
ignore.add(player);
}

View File

@ -1,5 +1,7 @@
package mineplex.gemhunters.worldevent.giant;
import java.util.concurrent.TimeUnit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Zombie;
import org.bukkit.event.EventHandler;
@ -20,7 +22,7 @@ public class GiantWorldEvent extends WorldEvent
private static final int MINI_ZOMBIES = 10;
private static final int MINI_ZOMBIES_MAX_DISTANCE_SQUARED = 900;
private static final int MAX_TIME = 180000;
private static final long MAX_TIME = TimeUnit.MINUTES.toMillis(6);
private CustomGiant _giant;

View File

@ -9,7 +9,7 @@ import org.json.JSONObject;
public class GoogleSheetController
{
private static final int SLEEP_TIME = 2000;
private static final int SLEEP_TIME = 1000;
private static final String DATA_STORE_DIR = ".." + File.separatorChar + ".." + File.separatorChar + "update" + File.separatorChar + "files";
public static void main(String[] args) throws InterruptedException

View File

@ -7,7 +7,7 @@ public enum SpreadsheetType
{
GEM_HUNTERS_CHESTS("11Noztgbpu_gUKkc5F4evKKfyxS-Jv1coE0IrBToX_gg"),
GEM_HUNTERS_VILLAGERS("1OcYktxVZaW6Fm29Zh6w4Lb-UVyuN8r1x-TFb_3USYYI"),
GEM_HUNTERS_SHOP("1OcYktxVZaW6Fm29Zh6w4Lb-UVyuN8r1x-TFb_3USYYI"),
;
private String _id;