World Events and Sheets rewrite
This commit is contained in:
parent
1a580251e9
commit
36c0c56f27
@ -25,21 +25,6 @@
|
||||
<artifactId>mineplex-serverdata</artifactId>
|
||||
<version>dev-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.api-client</groupId>
|
||||
<artifactId>google-api-client</artifactId>
|
||||
<version>1.22.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.oauth-client</groupId>
|
||||
<artifactId>google-oauth-client-jetty</artifactId>
|
||||
<version>1.22.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.apis</groupId>
|
||||
<artifactId>google-api-services-sheets</artifactId>
|
||||
<version>v4-rev20-1.22.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -1672,7 +1672,7 @@ public class UtilBlock
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Pair<Location, Pair<Material, Byte>> {@link HashSet} containing all the relevant data regarding beacon construction.
|
||||
* Returns a {@link Set} containing all the relevant data regarding beacon construction.
|
||||
* Useful for adding them to block restore.
|
||||
*
|
||||
* @param surface
|
||||
|
@ -1,66 +1,120 @@
|
||||
package mineplex.core.google;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.api.services.sheets.v4.model.Sheet;
|
||||
import com.google.api.services.sheets.v4.model.Spreadsheet;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.common.google.GoogleSheetProvider;
|
||||
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
public class GoogleSheetsManager extends MiniPlugin
|
||||
{
|
||||
|
||||
private final GoogleSheetProvider _sheets;
|
||||
private static final File DATA_STORE_DIR = new File(".." + File.separatorChar + ".." + File.separatorChar + "update" + File.separatorChar + "files");
|
||||
|
||||
private GoogleSheetsManager()
|
||||
public GoogleSheetsManager()
|
||||
{
|
||||
super("Google Sheets");
|
||||
|
||||
_sheets = new GoogleSheetProvider();
|
||||
}
|
||||
|
||||
public final void addSheet(MineplexGoogleSheet sheet, String sheetName, int maxColumn, int maxRow) throws IOException
|
||||
public <T> Map<String, Set<T>> getSheetData(String name, Class<T> clazz)
|
||||
{
|
||||
_sheets.create(sheet.getID(), sheetName, _sheets.getNextSheetID(sheet.getID()), maxColumn, maxRow);
|
||||
return getSheetData(new File(DATA_STORE_DIR + File.separator + name + ".json"), clazz);
|
||||
}
|
||||
|
||||
public final List<List<Object>> getCellValues(MineplexGoogleSheet spreadsheet, String sheetName, String a1Notation) throws IOException
|
||||
public <T> Map<String, Set<T>> getSheetData(File file, Class<T> clazz)
|
||||
{
|
||||
return _sheets.getSheetsService().spreadsheets().values().get(spreadsheet.getID(), sheetName + "!" + a1Notation).execute().getValues();
|
||||
}
|
||||
|
||||
public final List<List<Object>> getCellValues(MineplexGoogleSheet spreadsheet, String sheetName) throws IOException
|
||||
{
|
||||
return _sheets.getSheetsService().spreadsheets().values().get(spreadsheet.getID(), sheetName).execute().getValues();
|
||||
}
|
||||
|
||||
public final Map<String, List<List<Object>>> getCellValues(MineplexGoogleSheet spreadsheet) throws IOException
|
||||
{
|
||||
Spreadsheet googleSpreadsheet = _sheets.getSheetsService().spreadsheets().get(spreadsheet.getID()).execute();
|
||||
|
||||
Map<String, List<List<Object>>> valuesMap = new HashMap<>(googleSpreadsheet.getSheets().size() - 1);
|
||||
|
||||
int index = 0;
|
||||
|
||||
for (Sheet sheet : googleSpreadsheet.getSheets())
|
||||
if (!file.exists())
|
||||
{
|
||||
if (index++ == 0)
|
||||
Bukkit.broadcastMessage("No file");
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<String, Set<T>> valuesMap = new HashMap<>();
|
||||
|
||||
try
|
||||
{
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonElement data = parser.parse(new FileReader(file));
|
||||
JsonArray parent = data.getAsJsonObject().getAsJsonArray("data");
|
||||
|
||||
Bukkit.broadcastMessage("p=" + parent.size());
|
||||
|
||||
for (int i = 0; i < parent.size(); i++)
|
||||
{
|
||||
continue;
|
||||
JsonObject sheet = parent.get(i).getAsJsonObject();
|
||||
String name = sheet.get("name").getAsString();
|
||||
JsonArray values = sheet.getAsJsonArray("values");
|
||||
List<List<Object>> valuesList = new ArrayList<>(values.size());
|
||||
|
||||
for (int j = 0; j < values.size(); j++)
|
||||
{
|
||||
List<Object> list = new ArrayList<>();
|
||||
Iterator<JsonElement> iterator = values.get(j).getAsJsonArray().iterator();
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
String value = iterator.next().getAsString();
|
||||
list.add(value);
|
||||
}
|
||||
|
||||
valuesList.add(list);
|
||||
}
|
||||
|
||||
valuesMap.put(name, toSet(valuesList, clazz));
|
||||
}
|
||||
|
||||
String name = sheet.getProperties().getTitle();
|
||||
|
||||
valuesMap.put(name, getCellValues(spreadsheet, name));
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
for (String key : valuesMap.keySet())
|
||||
{
|
||||
Set<T> set = valuesMap.get(key);
|
||||
|
||||
for (T t : set)
|
||||
{
|
||||
Bukkit.broadcastMessage(t.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return valuesMap;
|
||||
}
|
||||
|
||||
public <T> Set<T> toSet(List<List<Object>> values, Class<T> clazz)
|
||||
{
|
||||
Set<T> result = new HashSet<>();
|
||||
Constructor<?> constructor = clazz.getConstructors()[0];
|
||||
|
||||
for (List<Object> objects : values)
|
||||
{
|
||||
try
|
||||
{
|
||||
result.add(clazz.cast(constructor.newInstance(objects)));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ import mineplex.core.visibility.VisibilityManager;
|
||||
import mineplex.gemhunters.chat.ChatModule;
|
||||
import mineplex.gemhunters.death.DeathModule;
|
||||
import mineplex.gemhunters.economy.CashOutModule;
|
||||
import mineplex.gemhunters.economy.EconomyModule;
|
||||
import mineplex.gemhunters.loot.LootModule;
|
||||
import mineplex.gemhunters.safezone.SafezoneModule;
|
||||
import mineplex.gemhunters.scoreboard.ScoreboardModule;
|
||||
@ -208,6 +209,7 @@ public class GemHunters extends JavaPlugin
|
||||
require(CashOutModule.class);
|
||||
require(ChatModule.class);
|
||||
require(DeathModule.class);
|
||||
require(EconomyModule.class);
|
||||
require(LootModule.class);
|
||||
require(SafezoneModule.class);
|
||||
require(ScoreboardModule.class);
|
||||
|
@ -22,10 +22,12 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.common.currency.GlobalCurrency;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilEvent;
|
||||
import mineplex.core.common.util.UtilEvent.ActionType;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.common.util.UtilTextMiddle;
|
||||
@ -44,12 +46,16 @@ public class CashOutModule extends MiniPlugin
|
||||
private static final int CASH_OUT_COOLDOWN = 10000;
|
||||
private static final int CASH_OUT_MAX_MOVE_DISTANCE_SQUARED = 4;
|
||||
|
||||
private final DonationManager _donation;
|
||||
|
||||
private final Map<UUID, CashOutSession> _sessions;
|
||||
|
||||
public CashOutModule()
|
||||
{
|
||||
super("Cash Out");
|
||||
|
||||
_donation = require(DonationManager.class);
|
||||
|
||||
_sessions = new HashMap<>();
|
||||
}
|
||||
|
||||
@ -155,10 +161,11 @@ public class CashOutModule extends MiniPlugin
|
||||
|
||||
UtilServer.CallEvent(completeEvent);
|
||||
|
||||
_donation.Get(player).addBalance(GlobalCurrency.GEM, completeEvent.getGems());
|
||||
|
||||
session.endSession();
|
||||
iterator.remove();
|
||||
player.sendMessage(C.cGreen + "Imagine you are being sent to the Lobby.");
|
||||
rewardCashOut(player, session);
|
||||
player.sendMessage(C.cGreen + "Imagine you are being sent to the Lobby.");
|
||||
// Portal.getInstance().sendToHub(player, "You cashed out!");
|
||||
}
|
||||
}
|
||||
@ -235,18 +242,12 @@ public class CashOutModule extends MiniPlugin
|
||||
_sessions.put(key, new CashOutSession(player, 10));
|
||||
}
|
||||
|
||||
public void rewardCashOut(Player player, CashOutSession session)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void cancelCashOut(Player player, String message)
|
||||
{
|
||||
UUID key = player.getUniqueId();
|
||||
CashOutSession session = _sessions.get(key);
|
||||
|
||||
player.sendMessage(F.main("Game", message + " Your cash out has been cancelled."));
|
||||
|
||||
session.endSession();
|
||||
_sessions.remove(key);
|
||||
}
|
||||
|
@ -0,0 +1,95 @@
|
||||
package mineplex.gemhunters.economy;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
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;
|
||||
import mineplex.gemhunters.loot.LootItem;
|
||||
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
public class EconomyModule extends MiniPlugin
|
||||
{
|
||||
|
||||
private static final float GEM_KILL_FACTOR = 0.5F;
|
||||
|
||||
private Map<UUID, Integer> _storedGems;
|
||||
|
||||
public EconomyModule()
|
||||
{
|
||||
super("Economy");
|
||||
|
||||
_storedGems = new HashMap<>();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void join(PlayerJoinEvent event)
|
||||
{
|
||||
_storedGems.put(event.getPlayer().getUniqueId(), 0);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void death(PlayerDeathEvent event)
|
||||
{
|
||||
Player player = event.getEntity();
|
||||
Entity killer = event.getEntity().getKiller();
|
||||
|
||||
if (!(killer instanceof Player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Player killerPlayer = (Player) killer;
|
||||
|
||||
int gems = (int) (_storedGems.get(player.getUniqueId()) * GEM_KILL_FACTOR);
|
||||
|
||||
addToStore(killerPlayer, "Killing " + F.name(player.getName()), gems);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void quit(PlayerQuitEvent event)
|
||||
{
|
||||
_storedGems.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
public void addToStore(Player player, String reason, int gems)
|
||||
{
|
||||
_storedGems.put(player.getUniqueId(), _storedGems.get(player.getUniqueId()) + gems);
|
||||
|
||||
if (reason != null)
|
||||
{
|
||||
player.sendMessage(F.main(_moduleName, "+" + F.currency(GlobalCurrency.GEM, gems) + " (" + reason + ")."));
|
||||
}
|
||||
}
|
||||
|
||||
public int getGems(Player player)
|
||||
{
|
||||
return _storedGems.get(player.getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void test(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
if (event.getMessage().startsWith("/test"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
|
||||
require(GoogleSheetsManager.class).getSheetData("GEM_HUNTERS_CHESTS", LootItem.class);
|
||||
//addToStore(event.getPlayer(), "Testing", 100);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -9,11 +9,28 @@ public class PlayerCashOutCompleteEvent extends PlayerEvent
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
private int _gems;
|
||||
|
||||
public PlayerCashOutCompleteEvent(Player player)
|
||||
{
|
||||
super(player);
|
||||
}
|
||||
|
||||
|
||||
public void incrementGems(int gems)
|
||||
{
|
||||
_gems += gems;
|
||||
}
|
||||
|
||||
public void setGems(int gems)
|
||||
{
|
||||
_gems = gems;
|
||||
}
|
||||
|
||||
public int getGems()
|
||||
{
|
||||
return _gems;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return HANDLERS;
|
||||
@ -23,5 +40,5 @@ public class PlayerCashOutCompleteEvent extends PlayerEvent
|
||||
{
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,11 @@ public class LootItem
|
||||
private double _probability;
|
||||
private String _metadata;
|
||||
|
||||
public LootItem(String... strings)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public LootItem(ItemStack itemStack, int minAmount, int maxAmount, double probability, String metadata)
|
||||
{
|
||||
_itemStack = itemStack;
|
||||
|
@ -37,7 +37,6 @@ import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.common.util.UtilWorld;
|
||||
import mineplex.core.google.GoogleSheetsManager;
|
||||
import mineplex.core.google.MineplexGoogleSheet;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
@ -63,8 +62,6 @@ public class LootModule extends MiniPlugin
|
||||
private static final int MAX_CHEST_PLACEMENT_RANGE = 10;
|
||||
private static final int MAX_CHEST_CHECK_DISTANCE_SQUARED = 4;
|
||||
|
||||
private static final MineplexGoogleSheet CHEST_LOOT_SHEET = MineplexGoogleSheet.GEM_HUNTERS_CHESTS;
|
||||
|
||||
private final GoogleSheetsManager _sheets;
|
||||
private final SafezoneModule _safezone;
|
||||
private final WorldDataModule _worldData;
|
||||
@ -234,103 +231,96 @@ public class LootModule extends MiniPlugin
|
||||
|
||||
public void updateChestLoot()
|
||||
{
|
||||
try
|
||||
Map<String, List<List<Object>>> map = null;
|
||||
|
||||
for (String key : map.keySet())
|
||||
{
|
||||
Map<String, List<List<Object>>> map = _sheets.getCellValues(CHEST_LOOT_SHEET);
|
||||
Set<LootItem> items = new HashSet<>();
|
||||
List<List<Object>> grid = map.get(key);
|
||||
int index = 0;
|
||||
|
||||
for (String key : map.keySet())
|
||||
try
|
||||
{
|
||||
Set<LootItem> items = new HashSet<>();
|
||||
List<List<Object>> grid = map.get(key);
|
||||
int index = 0;
|
||||
|
||||
try
|
||||
for (List<Object> values : grid)
|
||||
{
|
||||
for (List<Object> values : grid)
|
||||
if (index++ < 2)
|
||||
{
|
||||
if (index++ < 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (values.size() > 7)
|
||||
{
|
||||
metadata = String.valueOf(values.get(7));
|
||||
}
|
||||
items.add(new LootItem(builder.build(), minAmount, maxAmount, probability, metadata));
|
||||
continue;
|
||||
}
|
||||
|
||||
_chestLoot.put(key, items);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// TODO send slack message?
|
||||
e.printStackTrace();
|
||||
log("An error occured while parsing spreadsheet data! " + key);
|
||||
continue;
|
||||
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;
|
||||
|
||||
if (values.size() > 7)
|
||||
{
|
||||
metadata = String.valueOf(values.get(7));
|
||||
}
|
||||
items.add(new LootItem(builder.build(), minAmount, maxAmount, probability, metadata));
|
||||
}
|
||||
|
||||
_chestLoot.put(key, items);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// TODO send slack message?
|
||||
e.printStackTrace();
|
||||
log("An error occured while parsing spreadsheet data! " + key);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,37 +3,56 @@ package mineplex.gemhunters.scoreboard;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.Managers;
|
||||
import mineplex.core.common.currency.GlobalCurrency;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.scoreboard.WritableMineplexScoreboard;
|
||||
import mineplex.gemhunters.economy.EconomyModule;
|
||||
import mineplex.gemhunters.worldevent.WorldEvent;
|
||||
import mineplex.gemhunters.worldevent.WorldEventModule;
|
||||
|
||||
public class GemHuntersScoreboard extends WritableMineplexScoreboard
|
||||
{
|
||||
|
||||
private final DonationManager _donation;
|
||||
|
||||
|
||||
private final EconomyModule _economy;
|
||||
private final WorldEventModule _worldEvent;
|
||||
|
||||
public GemHuntersScoreboard(Player player)
|
||||
{
|
||||
super(player);
|
||||
|
||||
_donation = Managers.require(DonationManager.class);
|
||||
|
||||
_economy = Managers.require(EconomyModule.class);
|
||||
_worldEvent = Managers.require(WorldEventModule.class);
|
||||
}
|
||||
|
||||
public void writeContent(Player player)
|
||||
{
|
||||
writeNewLine();
|
||||
|
||||
|
||||
write(C.cGreenB + "Gems");
|
||||
write(String.valueOf(_donation.Get(player).getBalance(GlobalCurrency.GEM)));
|
||||
|
||||
write(String.valueOf(_economy.getGems(player)));
|
||||
|
||||
writeNewLine();
|
||||
|
||||
write(C.cYellowB + "World Event");
|
||||
|
||||
if (!_worldEvent.isMajorEventActive())
|
||||
{
|
||||
write(UtilTime.MakeStr(_worldEvent.getLastEventComplete() + _worldEvent.getEventTimer() - System.currentTimeMillis()));
|
||||
}
|
||||
else
|
||||
{
|
||||
for (WorldEvent event : _worldEvent.getActiveEvents())
|
||||
{
|
||||
write(event.getEventType().getName() + " (" + event.getEventState().getName() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
writeNewLine();
|
||||
}
|
||||
|
||||
|
||||
public String getSuffix(Player perspective, Player subject)
|
||||
{
|
||||
return C.cGray + " " + perspective.getName();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,43 +1,32 @@
|
||||
package mineplex.gemhunters.shop;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
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 org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.common.Pair;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.google.GoogleSheetsManager;
|
||||
import mineplex.core.google.MineplexGoogleSheet;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.gemhunters.loot.LootItem;
|
||||
import mineplex.gemhunters.safezone.SafezoneModule;
|
||||
import mineplex.gemhunters.world.WorldDataModule;
|
||||
import mineplex.serverdata.commands.PlayerJoinCommand;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
public class ShopModule extends MiniPlugin
|
||||
{
|
||||
|
||||
private static final MineplexGoogleSheet VILLAGER_LOOT_SHEET = MineplexGoogleSheet.GEM_HUNTERS_VILLAGERS;
|
||||
|
||||
private final GoogleSheetsManager _sheets;
|
||||
private final WorldDataModule _worldData;
|
||||
|
||||
@ -54,112 +43,105 @@ public class ShopModule extends MiniPlugin
|
||||
|
||||
_tradeItems = new HashMap<>();
|
||||
|
||||
updateVillagerLoot();
|
||||
//updateVillagerLoot();
|
||||
}
|
||||
|
||||
public void updateVillagerLoot()
|
||||
{
|
||||
try
|
||||
Map<String, List<List<Object>>> map = null;
|
||||
|
||||
for (String key : map.keySet())
|
||||
{
|
||||
Map<String, List<List<Object>>> map = _sheets.getCellValues(VILLAGER_LOOT_SHEET);
|
||||
Set<TradeableItem> items = new HashSet<>();
|
||||
List<List<Object>> grid = map.get(key);
|
||||
int index = 0;
|
||||
|
||||
for (String key : map.keySet())
|
||||
try
|
||||
{
|
||||
Set<TradeableItem> items = new HashSet<>();
|
||||
List<List<Object>> grid = map.get(key);
|
||||
int index = 0;
|
||||
|
||||
try
|
||||
for (List<Object> values : grid)
|
||||
{
|
||||
for (List<Object> values : grid)
|
||||
if (index++ < 2)
|
||||
{
|
||||
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));
|
||||
continue;
|
||||
}
|
||||
|
||||
_tradeItems.put(key, items);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// TODO send slack message?
|
||||
e.printStackTrace();
|
||||
log("An error occured while parsing spreadsheet data! " + key);
|
||||
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);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// TODO send slack message?
|
||||
e.printStackTrace();
|
||||
log("An error occured while parsing spreadsheet data! " + key);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ 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;
|
||||
@ -69,7 +70,11 @@ public class SpawnModule extends MiniPlugin
|
||||
|
||||
_npcsSpawned = true;
|
||||
|
||||
new SimpleNPC(_plugin, _worldData.getSpawnLocation("Purple").get(0), Villager.class, C.cDRed + "! " + C.cRedB + "Enter The World" + C.cDRed + " !", new Callback<Player>()
|
||||
Location location = _worldData.getSpawnLocation("Purple").get(0);
|
||||
|
||||
location.setYaw(UtilAlg.GetYaw(location.toVector()));
|
||||
|
||||
new SimpleNPC(_plugin, location, Villager.class, C.cDRed + "! " + C.cRedB + "Enter The World" + C.cDRed + " !", new Callback<Player>()
|
||||
{
|
||||
|
||||
@Override
|
||||
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -23,6 +24,7 @@ import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.common.util.UtilTextMiddle;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.common.util.UtilWorld;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
@ -34,18 +36,22 @@ import mineplex.gemhunters.world.WorldDataModule;
|
||||
public class SupplyDropModule extends MiniPlugin
|
||||
{
|
||||
|
||||
private static final long SEQUENCE_TIMER = TimeUnit.MINUTES.toMillis(15);
|
||||
|
||||
private static final String CHEST_COLOUR = "RED";
|
||||
private static final String LOCATION_DATA = "SUPPLY_DROP";
|
||||
|
||||
|
||||
private final BlockRestore _blockRestore;
|
||||
private final LootModule _loot;
|
||||
private final WorldDataModule _worldData;
|
||||
|
||||
|
||||
private final Set<Block> _beaconBlocks;
|
||||
|
||||
|
||||
private String[] _locationKeys;
|
||||
private SupplyDrop _current;
|
||||
|
||||
private long _lastSupplyDrop;
|
||||
|
||||
private SupplyDropModule()
|
||||
{
|
||||
super("Supply Drop");
|
||||
@ -53,8 +59,10 @@ public class SupplyDropModule extends MiniPlugin
|
||||
_blockRestore = require(BlockRestore.class);
|
||||
_loot = require(LootModule.class);
|
||||
_worldData = require(WorldDataModule.class);
|
||||
|
||||
|
||||
_beaconBlocks = new HashSet<>();
|
||||
|
||||
_lastSupplyDrop = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -66,45 +74,54 @@ public class SupplyDropModule extends MiniPlugin
|
||||
@EventHandler
|
||||
public void update(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.SEC || !isActive())
|
||||
if (event.getType() != UpdateType.SEC)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_current.advancePath())
|
||||
|
||||
if (isActive())
|
||||
{
|
||||
_current = null;
|
||||
if (_current.advancePath())
|
||||
{
|
||||
stopSequence();
|
||||
}
|
||||
}
|
||||
else if (UtilTime.elapsed(_lastSupplyDrop, SEQUENCE_TIMER))
|
||||
{
|
||||
startSequence();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void itemSpawn(ItemSpawnEvent event)
|
||||
{
|
||||
// The Helicopter has a door. This stops it dropping items when it moves.
|
||||
// The Helicopter has a door. This stops it dropping items when it
|
||||
// moves.
|
||||
if (event.getEntity().getItemStack().getType() == Material.IRON_DOOR)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void fallingBlockChange(EntityChangeBlockEvent event)
|
||||
{
|
||||
if (event.getEntity() instanceof FallingBlock && event.getTo() == Material.WOOD)
|
||||
{
|
||||
if (event.getEntity() instanceof FallingBlock && event.getTo() == Material.WOOD && isActive())
|
||||
{
|
||||
Block block = event.getBlock();
|
||||
|
||||
|
||||
block.setType(Material.CHEST);
|
||||
|
||||
// Add location that the chest will appear at into the spawned chests list so that LootModule can populate it with loot.
|
||||
|
||||
// Add location that the chest will appear at into the spawned
|
||||
// chests list so that LootModule can populate it with loot.
|
||||
_loot.addSpawnedChest(block.getLocation(), CHEST_COLOUR);
|
||||
|
||||
|
||||
// Remove beacon
|
||||
for (Block beacon : _beaconBlocks)
|
||||
{
|
||||
_blockRestore.restore(beacon);
|
||||
}
|
||||
|
||||
|
||||
_beaconBlocks.clear();
|
||||
|
||||
event.setCancelled(true);
|
||||
@ -124,19 +141,20 @@ public class SupplyDropModule extends MiniPlugin
|
||||
_beaconBlocks.add(pair.getLeft().getBlock());
|
||||
_blockRestore.add(pair.getLeft().getBlock(), pair.getRight().getLeft().getId(), pair.getRight().getRight(), Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
|
||||
// Inform the masses
|
||||
UtilTextMiddle.display(C.cYellow + locationKey, C.cGray + "A Supply Drop is spawning!", 10, 40, 10);
|
||||
UtilServer.broadcast(F.main(_moduleName, "A Supply Drop is spawning at " + F.elem(locationKey) + " - " + C.cYellow + UtilWorld.locToStrClean(destination)));
|
||||
|
||||
|
||||
_lastSupplyDrop = System.currentTimeMillis();
|
||||
_current = new SupplyDrop(spawn, destination, despawn);
|
||||
}
|
||||
|
||||
|
||||
public void startSequence()
|
||||
{
|
||||
startSequence(getLocationKeys()[UtilMath.r(getLocationKeys().length)]);
|
||||
}
|
||||
|
||||
|
||||
public void stopSequence()
|
||||
{
|
||||
// Remove beacon (only needed incase the command was executed)
|
||||
@ -144,39 +162,39 @@ public class SupplyDropModule extends MiniPlugin
|
||||
{
|
||||
_blockRestore.restore(block);
|
||||
}
|
||||
|
||||
|
||||
_beaconBlocks.clear();
|
||||
_current.stop();
|
||||
_current = null;
|
||||
}
|
||||
|
||||
|
||||
public boolean isActive()
|
||||
{
|
||||
return _current != null;
|
||||
}
|
||||
|
||||
|
||||
public String[] getLocationKeys()
|
||||
{
|
||||
if (_locationKeys == null)
|
||||
{
|
||||
List<String> supplyDropKeys = new ArrayList<>();
|
||||
|
||||
|
||||
for (String key : _worldData.getAllCustomLocations().keySet())
|
||||
{
|
||||
if (key.startsWith(LOCATION_DATA))
|
||||
{
|
||||
String splitKey = key.split(" ")[1];
|
||||
|
||||
|
||||
if (!supplyDropKeys.contains(splitKey))
|
||||
{
|
||||
supplyDropKeys.add(splitKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_locationKeys = supplyDropKeys.toArray(new String[supplyDropKeys.size()]);
|
||||
}
|
||||
|
||||
|
||||
return _locationKeys;
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ public class SupplyDropCommand extends MultiCommandBase<SupplyDropModule>
|
||||
{
|
||||
caller.sendMessage(F.main(Plugin.getName(), "Command List:"));
|
||||
caller.sendMessage(F.help("/" + _aliasUsed + " start [location]", "Starts the supply drop sequence at a certain location. Leaving [location] blank picks a random one.", Rank.ADMIN));
|
||||
caller.sendMessage(F.help("/" + _aliasUsed + " stop", "Ends the current supply drop.", Rank.ADMIN));
|
||||
caller.sendMessage(F.help("/" + _aliasUsed + " stop", "Stops the current supply drop.", Rank.ADMIN));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,14 +4,12 @@ import java.io.BufferedReader;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Difficulty;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
@ -1,10 +0,0 @@
|
||||
package mineplex.gemhunters.worldevent;
|
||||
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
|
||||
public abstract class TriggerableWorldEvent extends WorldEvent
|
||||
{
|
||||
|
||||
public abstract boolean onTriggerCheck(UpdateEvent event);
|
||||
|
||||
}
|
@ -1,21 +1,53 @@
|
||||
package mineplex.gemhunters.worldevent;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import mineplex.core.Managers;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.gemhunters.world.WorldDataModule;
|
||||
|
||||
public abstract class WorldEvent implements Listener
|
||||
{
|
||||
|
||||
protected WorldEventModule _worldEventModule;
|
||||
private final WorldEventType _eventType;
|
||||
|
||||
public WorldEvent()
|
||||
private WorldEventState _eventState;
|
||||
|
||||
protected final WorldDataModule _worldData;
|
||||
protected final WorldEventModule _worldEvent;
|
||||
|
||||
protected final Set<LivingEntity> _entities;
|
||||
|
||||
protected final long _start;
|
||||
private long _complete;
|
||||
|
||||
public WorldEvent(WorldEventType eventType)
|
||||
{
|
||||
_worldEventModule = Managers.get(WorldEventModule.class);
|
||||
_eventType = eventType;
|
||||
_eventState = null;
|
||||
|
||||
_worldData = Managers.get(WorldDataModule.class);
|
||||
_worldEvent = Managers.get(WorldEventModule.class);
|
||||
|
||||
_entities = new HashSet<>();
|
||||
_start = System.currentTimeMillis();
|
||||
|
||||
_worldEvent.registerEvents(this);
|
||||
}
|
||||
|
||||
public abstract void onStart();
|
||||
|
||||
public abstract boolean checkToEnd();
|
||||
|
||||
public abstract void onEnd();
|
||||
|
||||
public final void start()
|
||||
@ -25,7 +57,73 @@ public abstract class WorldEvent implements Listener
|
||||
|
||||
public final void end()
|
||||
{
|
||||
_complete = System.currentTimeMillis();
|
||||
|
||||
for (LivingEntity entity : _entities)
|
||||
{
|
||||
entity.damage(Double.MAX_VALUE);
|
||||
}
|
||||
|
||||
UtilServer.Unregister(this);
|
||||
|
||||
onEnd();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void updateEntities(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.SEC)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Iterator<LivingEntity> iterator = _entities.iterator();
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
Entity entity = iterator.next();
|
||||
|
||||
if (entity.isDead() || !entity.isValid())
|
||||
{
|
||||
entity.remove();
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addEntity(LivingEntity entity)
|
||||
{
|
||||
_entities.add(entity);
|
||||
}
|
||||
|
||||
public WorldEventType getEventType()
|
||||
{
|
||||
return _eventType;
|
||||
}
|
||||
|
||||
public void setEventState(WorldEventState eventState)
|
||||
{
|
||||
_eventState = eventState;
|
||||
|
||||
switch (eventState)
|
||||
{
|
||||
case WARMUP:
|
||||
start();
|
||||
break;
|
||||
case COMPLETE:
|
||||
end();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public WorldEventState getEventState()
|
||||
{
|
||||
return _eventState;
|
||||
}
|
||||
|
||||
public long getCompleteTime()
|
||||
{
|
||||
return _complete;
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,32 @@
|
||||
package mineplex.gemhunters.worldevent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.gemhunters.worldevent.command.WorldEventCommand;
|
||||
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
public class WorldEventModule extends MiniPlugin
|
||||
{
|
||||
|
||||
private static final long EVENT_TIMER = TimeUnit.MINUTES.toMillis(15);
|
||||
|
||||
private static final long COMPLETE_TIMER = TimeUnit.SECONDS.toMillis(30);
|
||||
|
||||
private final List<WorldEvent> _events;
|
||||
private long _lastEventComplete;
|
||||
private int _lastEventId;
|
||||
|
||||
private WorldEventModule()
|
||||
{
|
||||
@ -34,21 +39,41 @@ public class WorldEventModule extends MiniPlugin
|
||||
@Override
|
||||
public void addCommands()
|
||||
{
|
||||
|
||||
addCommand(new WorldEventCommand(this));
|
||||
}
|
||||
|
||||
public void startEvent(WorldEventType eventType)
|
||||
{
|
||||
WorldEvent event = eventType.createInstance();
|
||||
|
||||
_events.add(event);
|
||||
_lastEventId = eventType.ordinal();
|
||||
|
||||
event.start();
|
||||
event.setEventState(WorldEventState.WARMUP);
|
||||
}
|
||||
|
||||
public void startRandomEvent()
|
||||
{
|
||||
WorldEventType[] eventTypes = WorldEventType.values();
|
||||
|
||||
startEvent(eventTypes[UtilMath.r(eventTypes.length)]);
|
||||
Set<WorldEventType> possibleWorldEvents = new HashSet<>();
|
||||
|
||||
for (WorldEventType eventType : eventTypes)
|
||||
{
|
||||
if (_lastEventId == eventType.ordinal() || eventType.isMajor() || eventType.isTriggerable())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
possibleWorldEvents.add(eventType);
|
||||
}
|
||||
|
||||
if (possibleWorldEvents.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
startEvent(UtilAlg.Random(possibleWorldEvents));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -59,20 +84,59 @@ public class WorldEventModule extends MiniPlugin
|
||||
return;
|
||||
}
|
||||
|
||||
Iterator<WorldEvent> iterator = _events.iterator();
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
WorldEvent worldEvent = iterator.next();
|
||||
|
||||
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())
|
||||
{
|
||||
worldEvent.setEventState(WorldEventState.COMPLETE);
|
||||
}
|
||||
}
|
||||
|
||||
if (UtilTime.elapsed(_lastEventComplete, EVENT_TIMER))
|
||||
{
|
||||
|
||||
startRandomEvent();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void test(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
if (event.getMessage().startsWith("/test"))
|
||||
public boolean isMajorEventActive()
|
||||
{
|
||||
for (WorldEvent event : _events)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
startEvent(WorldEventType.GIANT);
|
||||
if (event.getEventType().isMajor())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<WorldEvent> getActiveEvents()
|
||||
{
|
||||
return _events;
|
||||
}
|
||||
|
||||
public long getLastEventComplete()
|
||||
{
|
||||
return _lastEventComplete;
|
||||
}
|
||||
|
||||
public long getEventTimer()
|
||||
{
|
||||
return EVENT_TIMER;
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,13 @@ package mineplex.gemhunters.worldevent;
|
||||
public enum WorldEventState
|
||||
{
|
||||
|
||||
WARMUP,
|
||||
LIVE,
|
||||
COMPLETE;
|
||||
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return Character.toUpperCase(name().charAt(0)) + name().substring(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,22 +5,25 @@ import mineplex.gemhunters.worldevent.giant.GiantWorldEvent;
|
||||
public enum WorldEventType
|
||||
{
|
||||
|
||||
GIANT("Giant", GiantWorldEvent.class, true);
|
||||
GIANT("Zombie Awakening", GiantWorldEvent.class, true, false);
|
||||
|
||||
private String _name;
|
||||
private Class<? extends WorldEvent> _clazz;
|
||||
private boolean _major;
|
||||
private boolean _major, _triggerable;
|
||||
private long _last;
|
||||
|
||||
private WorldEventType(String name, Class<? extends WorldEvent> clazz)
|
||||
{
|
||||
this(name, clazz, false);
|
||||
this(name, clazz, false, false);
|
||||
}
|
||||
|
||||
private WorldEventType(String name, Class<? extends WorldEvent> clazz, boolean major)
|
||||
private WorldEventType(String name, Class<? extends WorldEvent> clazz, boolean major, boolean triggerable)
|
||||
{
|
||||
_name = name;
|
||||
_clazz = clazz;
|
||||
_major = major;
|
||||
_triggerable = triggerable;
|
||||
_last = 0;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -28,7 +31,8 @@ public enum WorldEventType
|
||||
{
|
||||
try
|
||||
{
|
||||
return (T) _clazz.newInstance();
|
||||
_last = System.currentTimeMillis();
|
||||
return (T) _clazz.getConstructor(this.getClass()).newInstance(this);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -47,5 +51,15 @@ public enum WorldEventType
|
||||
{
|
||||
return _major;
|
||||
}
|
||||
|
||||
public boolean isTriggerable()
|
||||
{
|
||||
return _triggerable;
|
||||
}
|
||||
|
||||
public long getLast()
|
||||
{
|
||||
return _last;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +0,0 @@
|
||||
package mineplex.gemhunters.worldevent.command;
|
||||
|
||||
public class AddCommand
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package mineplex.gemhunters.worldevent.command;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.gemhunters.worldevent.WorldEventModule;
|
||||
import mineplex.gemhunters.worldevent.WorldEventType;
|
||||
|
||||
public class StartCommand extends CommandBase<WorldEventModule>
|
||||
{
|
||||
|
||||
public StartCommand(WorldEventModule plugin)
|
||||
{
|
||||
super(plugin, Rank.ADMIN, "start");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Execute(Player caller, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
caller.sendMessage(F.main(Plugin.getName(), "Starting a random world event."));
|
||||
Plugin.startRandomEvent();
|
||||
return;
|
||||
}
|
||||
|
||||
for (WorldEventType eventType : WorldEventType.values())
|
||||
{
|
||||
if (args[0].equalsIgnoreCase(eventType.name()))
|
||||
{
|
||||
caller.sendMessage(F.main(Plugin.getName(), "Starting the " + F.elem(eventType.name()) + " world event."));
|
||||
Plugin.startEvent(eventType);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
caller.sendMessage(F.main(Plugin.getName(), "I wasn\'t able to find a world event by the name " + F.elem(args[0]) + ". Possible values:"));
|
||||
|
||||
for (WorldEventType eventType : WorldEventType.values())
|
||||
{
|
||||
caller.sendMessage(C.cGray + "- " + F.elem(eventType.name()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package mineplex.gemhunters.worldevent.command;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.gemhunters.worldevent.WorldEvent;
|
||||
import mineplex.gemhunters.worldevent.WorldEventModule;
|
||||
import mineplex.gemhunters.worldevent.WorldEventState;
|
||||
|
||||
public class StopCommand extends CommandBase<WorldEventModule>
|
||||
{
|
||||
|
||||
public StopCommand(WorldEventModule plugin)
|
||||
{
|
||||
super(plugin, Rank.ADMIN, "stop");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Execute(Player caller, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
caller.sendMessage(F.main(Plugin.getName(), "Stopping all world events."));
|
||||
|
||||
for (WorldEvent event : Plugin.getActiveEvents())
|
||||
{
|
||||
event.setEventState(WorldEventState.COMPLETE);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (WorldEvent event : Plugin.getActiveEvents())
|
||||
{
|
||||
if (args[0].equalsIgnoreCase(event.getEventType().name()) && event.getEventState() != WorldEventState.COMPLETE)
|
||||
{
|
||||
caller.sendMessage(F.main(Plugin.getName(), "Stopping " + F.elem(event.getEventType().name()) + "."));
|
||||
event.setEventState(WorldEventState.COMPLETE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
caller.sendMessage(F.main(Plugin.getName(), "I wasn\'t able to find an active world event by the name " + F.elem(args[0]) + ". Possible values:"));
|
||||
|
||||
for (WorldEvent event : Plugin.getActiveEvents())
|
||||
{
|
||||
caller.sendMessage(C.cGray + "- " + F.elem(event.getEventType().name()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -13,14 +13,17 @@ public class WorldEventCommand extends MultiCommandBase<WorldEventModule>
|
||||
public WorldEventCommand(WorldEventModule plugin)
|
||||
{
|
||||
super(plugin, Rank.ADMIN, "worldevent", "we");
|
||||
|
||||
AddCommand(new StartCommand(plugin));
|
||||
AddCommand(new StopCommand(plugin));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void Help(Player caller, String[] args)
|
||||
{
|
||||
caller.sendMessage(F.help("/" + _aliasUsed + " start", "Start a World Event", Rank.ADMIN));
|
||||
caller.sendMessage(F.help("/" + _aliasUsed + " clear", "Clears all World Events", Rank.ADMIN));
|
||||
caller.sendMessage(F.help("/" + _aliasUsed + " random", "Starts a random World Event", Rank.ADMIN));
|
||||
caller.sendMessage(F.main(Plugin.getName(), "Command List:"));
|
||||
caller.sendMessage(F.help("/" + _aliasUsed + " start [name]", "Starts a world event. Leaving [name] blank picks a random one.", Rank.ADMIN));
|
||||
caller.sendMessage(F.help("/" + _aliasUsed + " stop [name]", "Stops a world event. Leaving [name] blank stops all events.", Rank.ADMIN));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import mineplex.core.Managers;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
@ -24,48 +25,68 @@ import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.gemhunters.worldevent.WorldEventModule;
|
||||
import mineplex.gemhunters.safezone.SafezoneModule;
|
||||
import mineplex.gemhunters.world.WorldDataModule;
|
||||
|
||||
public class CustomGiant implements Listener
|
||||
{
|
||||
|
||||
private static final int GIANT_HEALTH = 100;
|
||||
private static final int DESTORY_BLOCK_RADIUS = 7;
|
||||
private static final float DESTORY_FALLING_BLOCK_CHANCE = 0.05F;
|
||||
private static final int GIANT_WIDTH = 5;
|
||||
private static final int GIANT_HEIGHT = 13;
|
||||
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 final SafezoneModule _safezone;
|
||||
|
||||
private final Monster _giant;
|
||||
|
||||
private Player _target;
|
||||
|
||||
|
||||
private final Location _fallback;
|
||||
private Location _target;
|
||||
|
||||
public CustomGiant(Location spawn)
|
||||
{
|
||||
_safezone = Managers.get(SafezoneModule.class);
|
||||
|
||||
_giant = spawn.getWorld().spawn(spawn, Giant.class);
|
||||
|
||||
|
||||
_giant.setMaxHealth(GIANT_HEALTH);
|
||||
_giant.setHealth(_giant.getMaxHealth());
|
||||
|
||||
_giant.setRemoveWhenFarAway(false);
|
||||
|
||||
UtilEnt.vegetate(_giant);
|
||||
UtilEnt.setStepHeight(_giant, 2);
|
||||
|
||||
Managers.get(WorldEventModule.class).registerEvents(this);
|
||||
_fallback = Managers.get(WorldDataModule.class).getCustomLocation("CENTER").get(0);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void updateMovement(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.SEC || Bukkit.getOnlinePlayers().isEmpty())
|
||||
if (event.getType() != UpdateType.FASTEST || Bukkit.getOnlinePlayers().isEmpty())
|
||||
{
|
||||
if (event.getType() == UpdateType.SEC)
|
||||
{
|
||||
_target = acquireTarget();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (_target == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_target == null)
|
||||
{
|
||||
_target = acquireTarget();
|
||||
}
|
||||
|
||||
UtilEnt.CreatureMove(_giant, _target.getLocation(), 0.5F);
|
||||
Vector direction = UtilAlg.getTrajectory2d(_giant.getLocation(), _target).multiply(MOVE_FACTOR);
|
||||
Location toTeleport = _giant.getLocation().add(direction);
|
||||
|
||||
toTeleport.setYaw(UtilAlg.GetYaw(direction));
|
||||
toTeleport.setPitch(UtilAlg.GetPitch(direction));
|
||||
|
||||
_giant.teleport(toTeleport);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void updateBlockDestrory(UpdateEvent event)
|
||||
{
|
||||
@ -73,22 +94,22 @@ public class CustomGiant implements Listener
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (Block block : UtilBlock.getInBoundingBox(_giant.getLocation().subtract(5, 0, 5), _giant.getLocation().add(5, 13, 5)))
|
||||
|
||||
for (Block block : UtilBlock.getInBoundingBox(_giant.getLocation().subtract(GIANT_WIDTH, 0, GIANT_WIDTH), _giant.getLocation().add(GIANT_WIDTH, GIANT_HEIGHT, GIANT_WIDTH)))
|
||||
{
|
||||
if (Math.random() < DESTORY_FALLING_BLOCK_CHANCE)
|
||||
{
|
||||
FallingBlock fallingBlock = block.getWorld().spawnFallingBlock(block.getLocation(), block.getType(), block.getData());
|
||||
|
||||
|
||||
fallingBlock.setDropItem(false);
|
||||
fallingBlock.setHurtEntities(false);
|
||||
fallingBlock.setVelocity(new Vector(UtilMath.random(-1, 1), UtilMath.random(0.5, 1), UtilMath.random(-1, 1)));
|
||||
}
|
||||
|
||||
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void playerQuit(PlayerQuitEvent event)
|
||||
{
|
||||
@ -97,21 +118,32 @@ public class CustomGiant implements Listener
|
||||
_target = acquireTarget();
|
||||
}
|
||||
}
|
||||
|
||||
public Player acquireTarget()
|
||||
|
||||
public Location acquireTarget()
|
||||
{
|
||||
Collection<Player> ignore = new ArrayList<>();
|
||||
|
||||
|
||||
for (Player player : UtilServer.getPlayers())
|
||||
{
|
||||
if (UtilPlayer.isSpectator(player))
|
||||
if (UtilPlayer.isSpectator(player) || _safezone.getSafezone(player.getLocation()) != null)
|
||||
{
|
||||
ignore.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
return UtilPlayer.getClosest(_giant.getLocation(), ignore);
|
||||
|
||||
Player player = UtilPlayer.getClosest(_giant.getLocation(), ignore);
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
return _fallback;
|
||||
}
|
||||
|
||||
return UtilMath.offsetSquared(_giant, player) > MAX_SEARCH_DISTANCE_SQUARED ? _fallback : player.getLocation();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Monster getGiant()
|
||||
{
|
||||
return _giant;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,21 +1,91 @@
|
||||
package mineplex.gemhunters.worldevent.giant;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Zombie;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityCombustEvent;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.gemhunters.worldevent.WorldEvent;
|
||||
import mineplex.gemhunters.worldevent.WorldEventState;
|
||||
import mineplex.gemhunters.worldevent.WorldEventType;
|
||||
|
||||
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 CustomGiant _giant;
|
||||
|
||||
public GiantWorldEvent(WorldEventType eventType)
|
||||
{
|
||||
super(eventType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
new CustomGiant(Bukkit.getPlayer("Moppletop").getLocation());
|
||||
_giant = new CustomGiant(_worldData.getCustomLocation("GIANT_SPAWN").get(0));
|
||||
addEntity(_giant.getGiant());
|
||||
|
||||
_worldEvent.registerEvents(_giant);
|
||||
|
||||
setEventState(WorldEventState.LIVE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkToEnd()
|
||||
{
|
||||
return UtilTime.elapsed(_start, MAX_TIME) || _giant.getGiant().isDead() || !_giant.getGiant().isValid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnd()
|
||||
{
|
||||
{
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void zombieCombust(EntityCombustEvent event)
|
||||
{
|
||||
if (_entities.contains(event.getEntity()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void update(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.SEC || _giant == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (Entity entity : _entities)
|
||||
{
|
||||
if (UtilMath.offsetSquared(entity, _giant.getGiant()) > MINI_ZOMBIES_MAX_DISTANCE_SQUARED)
|
||||
{
|
||||
entity.teleport(_giant.getGiant());
|
||||
}
|
||||
}
|
||||
|
||||
// -1 for the giant
|
||||
if (_entities.size() - 1 < MINI_ZOMBIES)
|
||||
{
|
||||
Zombie zombie = _worldData.World.spawn(_giant.getGiant().getLocation(), Zombie.class);
|
||||
|
||||
zombie.setRemoveWhenFarAway(false);
|
||||
zombie.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 1));
|
||||
|
||||
addEntity(zombie);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
61
Plugins/mineplex-google-sheets/pom.xml
Normal file
61
Plugins/mineplex-google-sheets/pom.xml
Normal file
@ -0,0 +1,61 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.mineplex</groupId>
|
||||
<artifactId>mineplex-plugin</artifactId>
|
||||
<version>dev-SNAPSHOT</version>
|
||||
<relativePath>../plugin.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<name>Google Sheets</name>
|
||||
<artifactId>mineplex-google-sheets</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20160212</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.api-client</groupId>
|
||||
<artifactId>google-api-client</artifactId>
|
||||
<version>1.22.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.oauth-client</groupId>
|
||||
<artifactId>google-oauth-client-jetty</artifactId>
|
||||
<version>1.22.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.apis</groupId>
|
||||
<artifactId>google-api-services-sheets</artifactId>
|
||||
<version>v4-rev20-1.22.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<!-- Build an executable JAR -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<classpathPrefix>lib/</classpathPrefix>
|
||||
<mainClass>mineplex.googlesheets.GoogleSheetController</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -0,0 +1,63 @@
|
||||
package mineplex.googlesheets;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class GoogleSheetController
|
||||
{
|
||||
|
||||
private static final int SLEEP_TIME = 2000;
|
||||
private static final String DATA_STORE_DIR = ".." + File.separatorChar + ".." + File.separatorChar + "update" + File.separatorChar + "files";
|
||||
|
||||
public static void main(String[] args) throws InterruptedException
|
||||
{
|
||||
System.out.println("Loading Sheet Provider");
|
||||
SheetProvider provider = new SheetProvider();
|
||||
System.out.println("Loaded Sheet Provider");
|
||||
|
||||
for (SpreadsheetType type : SpreadsheetType.values())
|
||||
{
|
||||
System.out.println("Sleeping...");
|
||||
Thread.sleep(SLEEP_TIME);
|
||||
System.out.println("Getting data for " + type.name() + " (" + type.getID() + ")");
|
||||
|
||||
JSONObject object = provider.asJSONObject(type);
|
||||
|
||||
System.out.println("Done");
|
||||
System.out.println("Saving to file...");
|
||||
|
||||
File dir = new File(DATA_STORE_DIR);
|
||||
File file = new File(dir + File.separator + type.name() + ".json");
|
||||
|
||||
if (!dir.exists())
|
||||
{
|
||||
System.out.println("mkdir");
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
System.out.println("Deleting");
|
||||
file.delete();
|
||||
System.out.println("new File");
|
||||
file.createNewFile();
|
||||
|
||||
FileWriter writer = new FileWriter(file);
|
||||
|
||||
System.out.println("Writing");
|
||||
writer.write(object.toString());
|
||||
|
||||
System.out.println("Closing...");
|
||||
writer.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package mineplex.core.common.google;
|
||||
package mineplex.googlesheets;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@ -6,7 +6,12 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.google.api.client.auth.oauth2.Credential;
|
||||
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
|
||||
@ -20,24 +25,17 @@ import com.google.api.client.json.jackson2.JacksonFactory;
|
||||
import com.google.api.client.util.store.FileDataStoreFactory;
|
||||
import com.google.api.services.sheets.v4.Sheets;
|
||||
import com.google.api.services.sheets.v4.SheetsScopes;
|
||||
import com.google.api.services.sheets.v4.model.AddSheetRequest;
|
||||
import com.google.api.services.sheets.v4.model.BatchUpdateSpreadsheetRequest;
|
||||
import com.google.api.services.sheets.v4.model.GridProperties;
|
||||
import com.google.api.services.sheets.v4.model.GridRange;
|
||||
import com.google.api.services.sheets.v4.model.MergeCellsRequest;
|
||||
import com.google.api.services.sheets.v4.model.Request;
|
||||
import com.google.api.services.sheets.v4.model.SheetProperties;
|
||||
import com.google.api.services.sheets.v4.model.Sheet;
|
||||
import com.google.api.services.sheets.v4.model.Spreadsheet;
|
||||
import com.google.api.services.sheets.v4.model.ValueRange;
|
||||
|
||||
public class GoogleSheetProvider
|
||||
public class SheetProvider
|
||||
{
|
||||
|
||||
/** Application name. */
|
||||
private static final String APPLICATION_NAME = "Mineplex Google Sheets";
|
||||
|
||||
/** Directory to store user credentials for this application. */
|
||||
private static final File DATA_STORE_DIR = new java.io.File(".." + File.separatorChar + ".." + File.separatorChar + "update" + File.separatorChar + "files");
|
||||
private static final File DATA_STORE_DIR = new File(".." + File.separatorChar + ".." + File.separatorChar + "update" + File.separatorChar + "files");
|
||||
|
||||
/** Global instance of the {@link FileDataStoreFactory}. */
|
||||
private static FileDataStoreFactory DATA_STORE_FACTORY;
|
||||
@ -52,26 +50,28 @@ public class GoogleSheetProvider
|
||||
|
||||
private Sheets _service;
|
||||
private Credential _credential;
|
||||
|
||||
|
||||
static
|
||||
{
|
||||
try
|
||||
{
|
||||
HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
|
||||
DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR);
|
||||
} catch (Throwable t)
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public GoogleSheetProvider()
|
||||
public SheetProvider()
|
||||
{
|
||||
try
|
||||
{
|
||||
_credential = authorize();
|
||||
_service = getSheetsService();
|
||||
} catch (IOException e)
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -106,67 +106,55 @@ public class GoogleSheetProvider
|
||||
return new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY, _credential).setApplicationName(APPLICATION_NAME).build();
|
||||
}
|
||||
|
||||
public void create(String spreadsheetID, String name, int id, int maxColumn, int maxRow) throws IOException
|
||||
public JSONObject asJSONObject(SpreadsheetType spreadsheet)
|
||||
{
|
||||
BatchUpdateSpreadsheetRequest spreadsheetRequest = new BatchUpdateSpreadsheetRequest();
|
||||
Request request = new Request();
|
||||
AddSheetRequest addSheetRequest = new AddSheetRequest();
|
||||
SheetProperties sheetProperties = new SheetProperties();
|
||||
GridProperties gridProperties = new GridProperties();
|
||||
JSONObject parent = new JSONObject();
|
||||
JSONArray array = new JSONArray();
|
||||
Map<String, List<List<Object>>> valuesMap = get(spreadsheet);
|
||||
|
||||
for (String sheetName : valuesMap.keySet())
|
||||
{
|
||||
List<List<Object>> values = valuesMap.get(sheetName);
|
||||
|
||||
JSONObject object = new JSONObject();
|
||||
|
||||
object.put("name", sheetName);
|
||||
object.put("values", values);
|
||||
|
||||
array.put(object);
|
||||
}
|
||||
|
||||
parent.put("data", array);
|
||||
return parent;
|
||||
}
|
||||
|
||||
public Map<String, List<List<Object>>> get(SpreadsheetType spreadsheet)
|
||||
{
|
||||
try
|
||||
{
|
||||
Spreadsheet googleSpreadsheet = _service.spreadsheets().get(spreadsheet.getID()).execute();
|
||||
Map<String, List<List<Object>>> valuesMap = new HashMap<>(googleSpreadsheet.getSheets().size() - 1);
|
||||
|
||||
gridProperties.setColumnCount(maxColumn);
|
||||
gridProperties.setRowCount(maxRow);
|
||||
for (Sheet sheet : googleSpreadsheet.getSheets())
|
||||
{
|
||||
String name = sheet.getProperties().getTitle();
|
||||
|
||||
sheetProperties.setGridProperties(gridProperties);
|
||||
sheetProperties.setTitle(name);
|
||||
sheetProperties.setSheetId(id);
|
||||
valuesMap.put(name, get(spreadsheet, name));
|
||||
}
|
||||
|
||||
addSheetRequest.setProperties(sheetProperties);
|
||||
return valuesMap;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
request.setAddSheet(addSheetRequest);
|
||||
|
||||
spreadsheetRequest.setRequests(Arrays.asList(request));
|
||||
_service.spreadsheets().batchUpdate(spreadsheetID, spreadsheetRequest).execute();
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(String spreadsheetID, String sheetName, String range, List<List<Object>> values) throws IOException
|
||||
public List<List<Object>> get(SpreadsheetType spreadsheet, String sheetName) throws IOException
|
||||
{
|
||||
ValueRange valueRange = new ValueRange();
|
||||
|
||||
valueRange.setValues(values);
|
||||
|
||||
_service.spreadsheets().values().update(spreadsheetID, sheetName + "!" + range, valueRange).setValueInputOption("RAW").execute();
|
||||
}
|
||||
|
||||
public void merge(String spreadsheetID, String sheetName, int id, String mergeType, int startRow, int endRow, int startColumn, int endColumn) throws IOException
|
||||
{
|
||||
BatchUpdateSpreadsheetRequest spreadsheetRequest = new BatchUpdateSpreadsheetRequest();
|
||||
Request request = new Request();
|
||||
MergeCellsRequest mergeCellsRequest = new MergeCellsRequest();
|
||||
GridRange gridRange = new GridRange();
|
||||
|
||||
gridRange.setSheetId(id);
|
||||
|
||||
gridRange.setStartRowIndex(startRow);
|
||||
gridRange.setEndRowIndex(endRow);
|
||||
|
||||
gridRange.setStartColumnIndex(startColumn);
|
||||
gridRange.setEndColumnIndex(endColumn);
|
||||
|
||||
mergeCellsRequest.setMergeType(mergeType);
|
||||
mergeCellsRequest.setRange(gridRange);
|
||||
|
||||
request.setMergeCells(mergeCellsRequest);
|
||||
|
||||
spreadsheetRequest.setRequests(Arrays.asList(request));
|
||||
_service.spreadsheets().batchUpdate(spreadsheetID, spreadsheetRequest).execute();
|
||||
}
|
||||
|
||||
public int getNextSheetID(String spreadsheetID) throws IOException
|
||||
{
|
||||
Spreadsheet spreadsheet = _service.spreadsheets().get(spreadsheetID).execute();
|
||||
|
||||
return spreadsheet.getSheets().size();
|
||||
return _service.spreadsheets().values().get(spreadsheet.getID(), sheetName).execute().getValues();
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +1,9 @@
|
||||
package mineplex.core.google;
|
||||
package mineplex.googlesheets;
|
||||
|
||||
/**
|
||||
* An enum containing all the google spreadsheet links relating to Mineplex. <br>
|
||||
* <br>
|
||||
* This should really be changed to a config.
|
||||
* An enum containing all the google spreadsheet links relating to Mineplex.<br>
|
||||
*/
|
||||
public enum MineplexGoogleSheet
|
||||
public enum SpreadsheetType
|
||||
{
|
||||
|
||||
GEM_HUNTERS_CHESTS("11Noztgbpu_gUKkc5F4evKKfyxS-Jv1coE0IrBToX_gg"),
|
||||
@ -14,7 +12,7 @@ public enum MineplexGoogleSheet
|
||||
|
||||
private String _id;
|
||||
|
||||
private MineplexGoogleSheet(String id)
|
||||
private SpreadsheetType(String id)
|
||||
{
|
||||
_id = id;
|
||||
}
|
@ -40,6 +40,7 @@
|
||||
|
||||
<module>mavericks-review-hub</module>
|
||||
<module>mineplex-game-gemhunters</module>
|
||||
<module>mineplex-google-sheets</module>
|
||||
</modules>
|
||||
|
||||
<repositories>
|
||||
|
Loading…
Reference in New Issue
Block a user