This commit is contained in:
Sam 2017-02-05 22:24:10 +00:00
parent 6cc5a14073
commit bc510e5ad5
13 changed files with 250 additions and 62 deletions

View File

@ -61,6 +61,7 @@ import mineplex.gemhunters.scoreboard.ScoreboardModule;
import mineplex.gemhunters.shop.ShopModule;
import mineplex.gemhunters.spawn.SpawnModule;
import mineplex.gemhunters.supplydrop.SupplyDropModule;
import mineplex.gemhunters.world.TimeCycle;
import mineplex.gemhunters.world.WorldListeners;
import mineplex.gemhunters.worldevent.WorldEventModule;
import mineplex.minecraft.game.core.combat.CombatManager;
@ -224,6 +225,7 @@ public class GemHunters extends JavaPlugin
require(WorldEventModule.class);
new WorldListeners(this);
new TimeCycle(this);
// UpdateEvent!!!
new Updater(this);

View File

@ -8,11 +8,13 @@ import java.util.UUID;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
@ -29,6 +31,7 @@ import mineplex.core.common.util.UtilTime;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.visibility.VisibilityManager;
import mineplex.gemhunters.death.events.PlayerCustomRespawnEvent;
import mineplex.gemhunters.spawn.SpawnModule;
/**
@ -59,6 +62,14 @@ public class DeathModule extends MiniPlugin
_toRemove = new HashMap<>();
}
@EventHandler
public void join(PlayerJoinEvent event)
{
PlayerCustomRespawnEvent event2 = new PlayerCustomRespawnEvent(event.getPlayer());
UtilServer.CallEvent(event2);
}
@EventHandler
public void death(PlayerDeathEvent event)
{
@ -71,7 +82,7 @@ public class DeathModule extends MiniPlugin
startAnimation(player);
_toRemove.put(player.getUniqueId(), System.currentTimeMillis());
Iterator<ItemStack> iterator = event.getDrops().iterator();
// Iterate through all items and clear any disallowed items
@ -109,7 +120,7 @@ public class DeathModule extends MiniPlugin
long start = _toRemove.get(key);
long end = start + DEATH_ANIMATION_TIME + 1000;
if (UtilTime.elapsed(start, DEATH_ANIMATION_TIME))
{
stopAnimation(player);
@ -127,6 +138,7 @@ public class DeathModule extends MiniPlugin
{
UtilTextMiddle.display(C.cRedB + "YOU DIED", "Respawning shortly", 0, 60, 0, player);
VisibilityManager.Instance.setVisibility(player, false, UtilServer.getPlayers());
((CraftPlayer) player).getHandle().spectating = true;
player.setAllowFlight(true);
player.setFlying(true);
player.setGameMode(GameMode.CREATIVE);
@ -136,10 +148,15 @@ public class DeathModule extends MiniPlugin
{
UtilTextMiddle.display(C.cGreenB + "RESPAWNED", "", 0, 20, 20, player);
VisibilityManager.Instance.setVisibility(player, true, UtilServer.getPlayers());
((CraftPlayer) player).getHandle().spectating = false;
player.setFlying(false);
player.setAllowFlight(false);
player.setGameMode(GameMode.SURVIVAL);
_spawn.teleportToSpawn(player);
PlayerCustomRespawnEvent event = new PlayerCustomRespawnEvent(player);
UtilServer.CallEvent(event);
}
@EventHandler
@ -150,7 +167,7 @@ public class DeathModule extends MiniPlugin
event.setCancelled(true);
}
}
@EventHandler
public void blockBreak(BlockBreakEvent event)
{
@ -159,7 +176,7 @@ public class DeathModule extends MiniPlugin
event.setCancelled(true);
}
}
@EventHandler
public void blockPlace(BlockPlaceEvent event)
{

View File

@ -0,0 +1,27 @@
package mineplex.gemhunters.death.events;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
public class PlayerCustomRespawnEvent extends PlayerEvent
{
private static final HandlerList HANDLERS = new HandlerList();
public PlayerCustomRespawnEvent(Player who)
{
super(who);
}
public HandlerList getHandlers()
{
return HANDLERS;
}
public static HandlerList getHandlerList()
{
return HANDLERS;
}
}

View File

@ -35,6 +35,7 @@ import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.gemhunters.death.events.PlayerCustomRespawnEvent;
@ReflectivelyCreateMiniPlugin
public class CashOutModule extends MiniPlugin
@ -111,7 +112,7 @@ public class CashOutModule extends MiniPlugin
}
@EventHandler
public void playerJoin(PlayerJoinEvent event)
public void respawn(PlayerCustomRespawnEvent event)
{
Player player = event.getPlayer();

View File

@ -9,13 +9,13 @@ 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.gemhunters.death.events.PlayerCustomRespawnEvent;
@ReflectivelyCreateMiniPlugin
public class EconomyModule extends MiniPlugin
@ -33,7 +33,7 @@ public class EconomyModule extends MiniPlugin
}
@EventHandler
public void join(PlayerJoinEvent event)
public void respawn(PlayerCustomRespawnEvent event)
{
_storedGems.put(event.getPlayer().getUniqueId(), 0);
}

View File

@ -11,7 +11,6 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
@ -24,6 +23,7 @@ import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilEvent.ActionType;
import mineplex.core.common.util.UtilInv;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.gemhunters.death.events.PlayerCustomRespawnEvent;
@ReflectivelyCreateMiniPlugin
public class InventoryModule extends MiniPlugin
@ -42,7 +42,7 @@ public class InventoryModule extends MiniPlugin
}
@EventHandler
public void join(PlayerJoinEvent event)
public void respawn(PlayerCustomRespawnEvent event)
{
Player player = event.getPlayer();
Inventory inv = player.getInventory();

View File

@ -16,7 +16,6 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.Chest;
import org.bukkit.block.DoubleChest;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.inventory.InventoryClickEvent;
@ -137,9 +136,9 @@ public class LootModule extends MiniPlugin
{
continue;
}
properties.setLastSpawn();
// Only spawn more chests if we need to
int max = properties.getMaxActive();
int spawned = 0;
@ -298,21 +297,22 @@ public class LootModule extends MiniPlugin
Set<LootItem> items = _chestLoot.get(key);
ChestProperties properties = _chestProperties.get(key);
int sizeMultiplier = 1;
BlockState state = block.getState();
// TODO fix double chests
if (state instanceof DoubleChest)
Inventory inventory = null;
if (block.getType() == Material.ENDER_CHEST)
{
sizeMultiplier = 2;
inventory = player.getEnderChest();
}
else
{
BlockState state = block.getState();
Chest chest = (Chest) state;
inventory = chest.getBlockInventory();
}
Chest chest = (Chest) state;
Inventory inventory = chest.getBlockInventory();
inventory.clear();
for (int i = 0; i < UtilMath.rRange(properties.getMinAmount(), properties.getMaxAmount()) * sizeMultiplier; i++)
for (int i = 0; i < UtilMath.rRange(properties.getMinAmount(), properties.getMaxAmount()); i++)
{
LootItem lootItem = getRandomItem(items);
ItemStack itemStack = lootItem.getItemStack();
@ -404,7 +404,7 @@ public class LootModule extends MiniPlugin
Player player = event.getPlayer();
Block block = event.getClickedBlock();
if (block == null || block.getType() != Material.CHEST && block.getType() != Material.ENDER_CHEST)
if (block.getType() != Material.CHEST && block.getType() != Material.ENDER_CHEST)
{
return;
}

View File

@ -59,6 +59,7 @@ public class TraderNPC extends SimpleNPC
if (event.getRightClicked().equals(_entity))
{
event.setCancelled(true);
event.getPlayer().openInventory(_inv);
}
}

View File

@ -5,6 +5,7 @@ import org.bukkit.Material;
import org.bukkit.WorldBorder;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.Player;
import org.bukkit.entity.Villager;
import org.bukkit.event.EventHandler;
@ -20,6 +21,8 @@ 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.portal.Intent;
import mineplex.core.portal.Portal;
import mineplex.gemhunters.safezone.SafezoneModule;
import mineplex.gemhunters.util.ColouredTextAnimation;
import mineplex.gemhunters.util.SimpleNPC;
@ -29,7 +32,7 @@ import mineplex.gemhunters.world.WorldDataModule;
public class SpawnModule extends MiniPlugin
{
private static final int WORLD_BORDER_RADIUS = 300;
private static final int WORLD_BORDER_RADIUS = 900;
private final SafezoneModule _safezone;
private final WorldDataModule _worldData;
@ -56,9 +59,9 @@ public class SpawnModule extends MiniPlugin
}
Player player = event.getPlayer();
player.teleport(_spawn);
if (_npcsSpawned)
{
return;
@ -71,51 +74,82 @@ public class SpawnModule extends MiniPlugin
_npcsSpawned = true;
Location location = _worldData.getCustomLocation("TELEPORT_NPC").get(0);
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>()
{
Location location = _worldData.getCustomLocation("TELEPORT_NPC").get(0);
@Override
public void run(Player data)
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>()
{
Location location = getRandomLocation();
if (location == null)
@Override
public void run(Player data)
{
data.sendMessage(F.main(_moduleName, "A suitable teleport location could not be found. Please try again in a few seconds."));
return;
}
Location location = getRandomLocation();
data.teleport(location);
data.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 4 * 20, 9));
data.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 4 * 20, 9));
ColouredTextAnimation animation = new ColouredTextAnimation("GEM HUNTERS", C.cGoldB + "M ", C.cGoldB + " M", new String[] { C.cDGreenB, C.cGreenB, C.cWhiteB });
runSyncTimer(new BukkitRunnable()
{
@Override
public void run()
if (location == null)
{
if (animation.displayAsTitle(data))
{
cancel();
}
data.sendMessage(F.main(_moduleName, "A suitable teleport location could not be found. Please try again in a few seconds."));
return;
}
}, 10, 4);
}
});
data.teleport(location);
data.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 4 * 20, 9));
data.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 4 * 20, 9));
ColouredTextAnimation animation = new ColouredTextAnimation("GEM HUNTERS", C.cGoldB + "M ", C.cGoldB + " M", new String[] { C.cDGreenB, C.cGreenB, C.cWhiteB });
runSyncTimer(new BukkitRunnable()
{
@Override
public void run()
{
if (animation.displayAsTitle(data))
{
cancel();
}
}
}, 10, 4);
}
});
}
{
Location location = _worldData.getCustomLocation("RETURN_TO_HUB").get(0);
location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, _spawn)));
new SimpleNPC(_plugin, location, Villager.class, C.cGoldB + "Return To Hub", new Callback<Player>()
{
@Override
public void run(Player data)
{
Portal.getInstance().sendToHub(data, null, Intent.PLAYER_REQUEST);
}
});
}
{
Location location = _worldData.getCustomLocation("CARL").get(0);
location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, _spawn)));
new SimpleNPC(_plugin, location, Creeper.class, C.cGreenB + "Carl", new Callback<Player>()
{
@Override
public void run(Player data)
{
}
});
}
}
public void teleportToSpawn(Player player)
{
player.teleport(_spawn);
}
public boolean isSuitable(Block block)
{
Block up = block.getRelative(BlockFace.UP);
@ -149,4 +183,9 @@ public class SpawnModule extends MiniPlugin
return null;
}
public Location getCenter()
{
return _center;
}
}

View File

@ -28,6 +28,7 @@ public class SimpleNPC implements Listener
public SimpleNPC(JavaPlugin plugin, Location spawn, Class<? extends LivingEntity> type, String name, Callback<Player> clickEvent, boolean vegetated)
{
spawn.getWorld().loadChunk(spawn.getChunk());
_entity = spawn.getWorld().spawn(spawn, type);
_entity.setRemoveWhenFarAway(false);

View File

@ -0,0 +1,93 @@
package mineplex.gemhunters.world;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.Managers;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class TimeCycle implements Listener
{
private static final int TICKS_DAY = 1;
private static final int TICKS_NIGHT = 2;
private final WorldDataModule _worldData;
private World _world;
private boolean _night;
public TimeCycle(JavaPlugin plugin)
{
//plugin.getServer().getPluginManager().registerEvents(this, plugin);
_worldData = Managers.get(WorldDataModule.class);
}
public void setStreetLights()
{
Bukkit.broadcastMessage("Set " + _night + " " + _worldData.getCustomLocation("123").size());
for (Location location : _worldData.getCustomLocation("123"))
{
Block block = location.getBlock().getRelative(BlockFace.UP);
Bukkit.broadcastMessage("set");
block.setType(_night ? Material.REDSTONE_BLOCK : Material.STONE_SLAB2);
}
}
@EventHandler
public void update(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
{
return;
}
if (_world == null)
{
_world = _worldData.World;
return;
}
if (!_night && _world.getTime() > 12000)
{
_night = true;
setStreetLights();
}
if (_world.getTime() >= 23900)
{
_world.setTime(0);
_night = false;
setStreetLights();
}
_world.setTime(_world.getTime() + (isNight() ? TICKS_NIGHT : TICKS_DAY));
}
@EventHandler
public void test(PlayerCommandPreprocessEvent event) {
if (event.getMessage().startsWith("/lamp"))
{
event.setCancelled(true);
event.getPlayer().getLocation().getBlock().setType(Material.REDSTONE_LAMP_ON);
}
}
public boolean isNight()
{
return _world.getTime() > 12000;
}
}

View File

@ -9,6 +9,7 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerArmorStandManipulateEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class WorldListeners implements Listener
@ -19,7 +20,7 @@ public class WorldListeners implements Listener
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler(priority=EventPriority.LOWEST)
@EventHandler(priority = EventPriority.LOWEST)
public void blockBreak(BlockBreakEvent event)
{
if (shouldBlock(event.getPlayer()))
@ -28,7 +29,7 @@ public class WorldListeners implements Listener
}
}
@EventHandler(priority=EventPriority.LOWEST)
@EventHandler(priority = EventPriority.LOWEST)
public void blockPlace(BlockPlaceEvent event)
{
if (shouldBlock(event.getPlayer()))
@ -45,7 +46,7 @@ public class WorldListeners implements Listener
event.setCancelled(true);
}
}
@EventHandler
public void armorStandDestory(PlayerInteractAtEntityEvent event)
{
@ -55,6 +56,12 @@ public class WorldListeners implements Listener
}
}
@EventHandler
public void chunkUnload(ChunkUnloadEvent event)
{
event.setCancelled(true);
}
public boolean shouldBlock(Player player)
{
return player.getGameMode() != GameMode.CREATIVE;

View File

@ -26,7 +26,7 @@ import mineplex.core.common.util.UtilServer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.gemhunters.safezone.SafezoneModule;
import mineplex.gemhunters.world.WorldDataModule;
import mineplex.gemhunters.spawn.SpawnModule;
public class CustomGiant implements Listener
{
@ -60,7 +60,7 @@ public class CustomGiant implements Listener
UtilEnt.ghost(_giant, true, false);
UtilEnt.setFakeHead(_giant, true);
_fallback = Managers.get(WorldDataModule.class).getCustomLocation("CENTER").get(0);
_fallback = Managers.get(SpawnModule.class).getCenter();
}
@EventHandler