2016-07-09 13:19:56 +02:00
package eu.univento.teamvento.listener ;
2016-09-17 12:10:01 +02:00
import eu.univento.commons.player.Rank ;
import eu.univento.core.Core ;
2016-07-09 13:19:56 +02:00
import eu.univento.core.api.gui.AnvilGUI ;
import eu.univento.core.api.items.ItemBuilder ;
2016-09-17 12:10:01 +02:00
import eu.univento.core.api.items.PageInventory ;
2016-07-09 13:19:56 +02:00
import eu.univento.core.api.player.CustomPlayer ;
import eu.univento.core.api.utils.UUIDFetcher ;
import eu.univento.teamvento.TeamVento ;
import eu.univento.teamvento.utils.* ;
2016-10-10 13:14:01 +02:00
import net.gpedro.integrations.slack.SlackApi ;
import net.gpedro.integrations.slack.SlackMessage ;
2016-07-09 13:19:56 +02:00
import org.bukkit.Bukkit ;
import org.bukkit.Location ;
import org.bukkit.Material ;
import org.bukkit.WeatherType ;
import org.bukkit.block.Biome ;
import org.bukkit.entity.Player ;
import org.bukkit.event.EventHandler ;
import org.bukkit.event.Listener ;
import org.bukkit.event.block.Action ;
import org.bukkit.event.inventory.InventoryClickEvent ;
import org.bukkit.event.player.PlayerInteractEvent ;
import org.bukkit.inventory.ItemStack ;
import org.bukkit.inventory.meta.ItemMeta ;
import org.bukkit.inventory.meta.SkullMeta ;
2016-09-17 12:10:01 +02:00
import java.util.ArrayList ;
2016-07-09 13:19:56 +02:00
public class MenuEvents implements Listener {
@EventHandler
public void onInteract ( PlayerInteractEvent e ) {
CustomPlayer p = CustomPlayer . getPlayer ( e . getPlayer ( ) ) ;
Inventorys invs = new Inventorys ( p ) ;
if ( e . getAction ( ) = = Action . RIGHT_CLICK_BLOCK | | e . getAction ( ) = = Action . RIGHT_CLICK_AIR ) {
if ( p . getItemInHand ( ) . getType ( ) = = Material . WATCH & & p . getItemInHand ( ) . getItemMeta ( ) . getDisplayName ( ) . equals ( " §eErweiterungen " ) ) {
p . openInventory ( invs . getMainInventory ( ) ) ;
}
}
}
@EventHandler
public void onInventoryClick ( InventoryClickEvent e ) {
CustomPlayer p = CustomPlayer . getPlayer ( ( Player ) e . getWhoClicked ( ) ) ;
Inventorys invs = new Inventorys ( p ) ;
if ( e . isShiftClick ( ) & & e . getCurrentItem ( ) . getItemMeta ( ) . getDisplayName ( ) . equalsIgnoreCase ( " §eErweiterungen " ) ) e . setCancelled ( true ) ;
if ( ! PlotManager . hasPlot ( p ) ) return ;
if ( e . getCurrentItem ( ) = = null ) return ;
if ( ! e . getCurrentItem ( ) . hasItemMeta ( ) ) return ;
if ( ! e . getCurrentItem ( ) . getItemMeta ( ) . hasDisplayName ( ) ) return ;
Plot plot = PlotManager . getPlotByPlayer ( p ) ;
2016-09-17 12:10:01 +02:00
assert plot ! = null ;
2016-07-09 13:19:56 +02:00
if ( e . getInventory ( ) . getName ( ) . equals ( invs . getMainInventory ( ) . getName ( ) ) ) {
e . setCancelled ( true ) ;
if ( e . getCurrentItem ( ) . getType ( ) = = Material . BED ) {
p . closeInventory ( ) ;
Location loc = plot . getSpawn ( ) ;
p . teleport ( new Location ( Bukkit . getWorld ( " plots " ) , loc . getX ( ) , loc . getY ( ) , loc . getZ ( ) , 89 . 0F , 6 . 0F ) ) ;
}
if ( e . getCurrentItem ( ) . getType ( ) = = Material . LEASH ) {
p . closeInventory ( ) ;
p . openInventory ( invs . getAnimalsInventory ( ) ) ;
}
if ( e . getCurrentItem ( ) . getItemMeta ( ) . getDisplayName ( ) . equals ( " §ePlot zurücksetzen " ) ) {
2016-10-10 13:14:01 +02:00
PlotManager . resetPlot ( plot ) ;
2016-07-09 13:19:56 +02:00
p . closeInventory ( ) ;
}
2016-09-17 12:10:01 +02:00
if ( e . getCurrentItem ( ) . getItemMeta ( ) . getDisplayName ( ) . equalsIgnoreCase ( " §eFertig " ) ) {
p . closeInventory ( ) ;
if ( plot . hasName ( ) & & plot . hasContact ( ) )
p . openInventory ( invs . getReadyInventory ( ) ) ;
else
p . sendMessage ( " §cName und Kontaktinformationen müssen angegeben werden " ) ;
}
2016-07-09 13:19:56 +02:00
if ( e . getCurrentItem ( ) . getItemMeta ( ) . getDisplayName ( ) . equals ( " §eBiom ändern " ) ) {
p . closeInventory ( ) ;
p . openInventory ( invs . getBiomeInventory ( ) ) ;
}
if ( e . getCurrentItem ( ) . getItemMeta ( ) . getDisplayName ( ) . equals ( " §eWetter ändern " ) ) {
p . closeInventory ( ) ;
p . openInventory ( invs . getWeatherInventory ( ) ) ;
}
if ( e . getCurrentItem ( ) . getType ( ) = = Material . WATCH ) {
p . closeInventory ( ) ;
p . openInventory ( invs . getTimeInventory ( ) ) ;
}
if ( e . getCurrentItem ( ) . getType ( ) = = Material . LADDER ) {
p . closeInventory ( ) ;
p . openInventory ( invs . getSettingsInventory ( ) ) ;
}
if ( e . getCurrentItem ( ) . getType ( ) = = Material . MINECART ) {
p . closeInventory ( ) ;
Bukkit . getScheduler ( ) . runTaskAsynchronously ( TeamVento . getInstance ( ) , ( ) - > {
2016-09-17 12:10:01 +02:00
PageInventory inventory = new PageInventory ( " §eTeleport " , p , true ) ;
ArrayList < ItemStack > items = new ArrayList < > ( ) ;
2016-07-09 13:19:56 +02:00
for ( Plot plots : PlotManager . getPlots ( ) ) {
String name = UUIDFetcher . getName ( plots . getOwner ( ) ) ;
2016-09-17 12:10:01 +02:00
items . add ( new ItemBuilder ( Material . SKULL_ITEM ) . durability ( ) . skullOwner ( name ) . name ( " §e " + plots . getName ( ) ) . lore ( " §evon " + name ) . make ( ) ) ;
2016-07-09 13:19:56 +02:00
}
2016-09-17 12:10:01 +02:00
inventory . setPages ( items ) ;
2016-07-09 13:19:56 +02:00
inventory . openInventory ( ) ;
} ) ;
}
}
2016-09-17 12:10:01 +02:00
if ( e . getInventory ( ) . getName ( ) . equals ( invs . getReadyInventory ( ) . getName ( ) ) ) {
if ( e . getCurrentItem ( ) . getItemMeta ( ) . getDisplayName ( ) . equals ( " Ja " ) ) {
p . closeInventory ( ) ;
plot . setReady ( ) ;
p . getInventory ( ) . remove ( p . getInventory ( ) . getItem ( 8 ) ) ;
Core . getOnlinePlayers ( ) . stream ( ) . filter ( player - > player . getDatabasePlayer ( ) . isAllowed ( Rank . Builder ) ) . forEach ( player - > player . sendMessage ( " §a[Plot]§e " + p . getName ( ) + " ist fertig " ) ) ;
2016-10-10 13:14:01 +02:00
SlackApi api = new SlackApi ( " https://hooks.slack.com/services/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 " ) ;
SlackMessage message = new SlackMessage ( " #bauevent " , p . getName ( ) , " ist nun fertig mit bauen " ) ;
message . setIcon ( " http://cravatar.eu/head/ " + p . getUniqueId ( ) . toString ( ) ) ;
api . call ( message ) ;
2016-09-17 12:10:01 +02:00
}
if ( e . getCurrentItem ( ) . getItemMeta ( ) . getDisplayName ( ) . equals ( " Nein " ) )
p . closeInventory ( ) ;
}
2016-07-09 13:19:56 +02:00
if ( e . getInventory ( ) . getName ( ) . equals ( invs . getBiomeInventory ( ) . getName ( ) ) ) {
e . setCancelled ( true ) ;
if ( e . getCurrentItem ( ) . getType ( ) = = Material . WATER_LILY ) {
p . closeInventory ( ) ;
plot . setBiome ( Biome . SWAMPLAND ) ;
}
if ( e . getCurrentItem ( ) . getType ( ) = = Material . DEAD_BUSH ) {
p . closeInventory ( ) ;
plot . setBiome ( Biome . DESERT ) ;
}
if ( e . getCurrentItem ( ) . getItemMeta ( ) . getDisplayName ( ) . equals ( " §eWald " ) ) {
p . closeInventory ( ) ;
plot . setBiome ( Biome . FOREST ) ;
}
if ( e . getCurrentItem ( ) . getItemMeta ( ) . getDisplayName ( ) . equals ( " §eFlachland " ) ) {
p . closeInventory ( ) ;
plot . setBiome ( Biome . PLAINS ) ;
}
if ( e . getCurrentItem ( ) . getItemMeta ( ) . getDisplayName ( ) . equals ( " §eTaiga " ) ) {
p . closeInventory ( ) ;
plot . setBiome ( Biome . TAIGA ) ;
}
if ( e . getCurrentItem ( ) . getItemMeta ( ) . getDisplayName ( ) . equals ( " §eTundra " ) ) {
p . closeInventory ( ) ;
plot . setBiome ( Biome . TAIGA_COLD ) ;
}
if ( e . getCurrentItem ( ) . getType ( ) = = Material . STAINED_CLAY ) {
p . closeInventory ( ) ;
plot . setBiome ( Biome . MESA ) ;
}
if ( e . getCurrentItem ( ) . getItemMeta ( ) . getDisplayName ( ) . equals ( " §eDschungel " ) ) {
p . closeInventory ( ) ;
plot . setBiome ( Biome . JUNGLE ) ;
}
}
if ( e . getInventory ( ) . getName ( ) . equals ( invs . getTimeInventory ( ) . getName ( ) ) ) {
e . setCancelled ( true ) ;
if ( e . getCurrentItem ( ) . getType ( ) = = Material . MILK_BUCKET ) {
p . closeInventory ( ) ;
plot . setTime ( Time . MORNING ) ;
if ( plot . isInPlot ( p . getLocation ( ) ) ) p . setPlayerTime ( Time . MORNING . getValue ( ) , false ) ;
}
if ( e . getCurrentItem ( ) . getType ( ) = = Material . DOUBLE_PLANT ) {
p . closeInventory ( ) ;
plot . setTime ( Time . DAY ) ;
if ( plot . isInPlot ( p . getLocation ( ) ) ) p . setPlayerTime ( Time . DAY . getValue ( ) , false ) ;
}
if ( e . getCurrentItem ( ) . getType ( ) = = Material . BEETROOT_SOUP ) {
p . closeInventory ( ) ;
plot . setTime ( Time . EVENING ) ;
if ( plot . isInPlot ( p . getLocation ( ) ) ) p . setPlayerTime ( Time . EVENING . getValue ( ) , false ) ;
}
if ( e . getCurrentItem ( ) . getType ( ) = = Material . COAL ) {
p . closeInventory ( ) ;
plot . setTime ( Time . NIGHT ) ;
if ( plot . isInPlot ( p . getLocation ( ) ) ) p . setPlayerTime ( Time . NIGHT . getValue ( ) , false ) ;
}
}
if ( e . getInventory ( ) . getName ( ) . equals ( invs . getWeatherInventory ( ) . getName ( ) ) ) {
e . setCancelled ( true ) ;
if ( e . getCurrentItem ( ) . getType ( ) = = Material . DOUBLE_PLANT ) {
p . closeInventory ( ) ;
plot . setWeather ( Weather . CLEAR ) ;
if ( plot . isInPlot ( p . getLocation ( ) ) ) p . setPlayerWeather ( WeatherType . CLEAR ) ;
}
if ( e . getCurrentItem ( ) . getType ( ) = = Material . WATER_BUCKET ) {
p . closeInventory ( ) ;
plot . setWeather ( Weather . DOWNFALL ) ;
if ( plot . isInPlot ( p . getLocation ( ) ) ) p . setPlayerWeather ( WeatherType . DOWNFALL ) ;
}
if ( e . getCurrentItem ( ) . getType ( ) = = Material . BLAZE_ROD ) {
p . closeInventory ( ) ;
plot . setWeather ( Weather . THUNDER ) ;
if ( plot . isInPlot ( p . getLocation ( ) ) ) p . setPlayerWeather ( WeatherType . DOWNFALL ) ;
}
}
if ( e . getInventory ( ) . getName ( ) . equals ( invs . getSettingsInventory ( ) . getName ( ) ) ) {
e . setCancelled ( true ) ;
if ( e . getCurrentItem ( ) . getType ( ) = = Material . SIGN ) {
AnvilGUI gui = new AnvilGUI ( p , event - > {
if ( event . getSlot ( ) = = AnvilGUI . AnvilSlot . OUTPUT ) {
2016-08-03 00:28:53 +02:00
event . setWillClose ( ) ;
event . setWillDestroy ( ) ;
2016-07-09 13:19:56 +02:00
plot . setName ( event . getName ( ) ) ;
p . refreshExperience ( ) ;
} else {
2016-08-03 00:28:53 +02:00
event . setWillDestroy ( ) ;
event . setWillClose ( ) ;
2016-07-09 13:19:56 +02:00
}
} ) ;
ItemStack name = new ItemStack ( Material . SIGN ) ;
ItemMeta nameMeta = name . getItemMeta ( ) ;
nameMeta . setDisplayName ( plot . getName ( ) = = null ? " §cunbennantes Plot " : plot . getName ( ) ) ;
name . setItemMeta ( nameMeta ) ;
2016-08-03 00:28:53 +02:00
gui . setSlot ( name ) ;
2016-07-09 13:19:56 +02:00
gui . open ( ) ;
}
if ( e . getCurrentItem ( ) . getType ( ) = = Material . NAME_TAG ) {
AnvilGUI gui = new AnvilGUI ( p , event - > {
if ( event . getSlot ( ) = = AnvilGUI . AnvilSlot . OUTPUT ) {
2016-08-03 00:28:53 +02:00
event . setWillClose ( ) ;
event . setWillDestroy ( ) ;
2016-07-09 13:19:56 +02:00
plot . setContact ( event . getName ( ) ) ;
p . refreshExperience ( ) ;
} else {
2016-08-03 00:28:53 +02:00
event . setWillDestroy ( ) ;
event . setWillClose ( ) ;
2016-07-09 13:19:56 +02:00
}
} ) ;
ItemStack name = new ItemStack ( Material . NAME_TAG ) ;
ItemMeta nameMeta = name . getItemMeta ( ) ;
2016-09-17 12:10:01 +02:00
nameMeta . setDisplayName ( plot . getContact ( ) = = null ? " §cKontaktdaten " : plot . getContact ( ) ) ;
2016-07-09 13:19:56 +02:00
name . setItemMeta ( nameMeta ) ;
2016-08-03 00:28:53 +02:00
gui . setSlot ( name ) ;
2016-07-09 13:19:56 +02:00
gui . open ( ) ;
}
}
if ( e . getInventory ( ) . getName ( ) . equals ( " §eTeleport " ) ) {
if ( e . getCurrentItem ( ) . getType ( ) = = Material . SKULL_ITEM ) {
SkullMeta skull = ( SkullMeta ) e . getCurrentItem ( ) . getItemMeta ( ) ;
Bukkit . getScheduler ( ) . runTaskAsynchronously ( TeamVento . getInstance ( ) , ( ) - > {
Plot tpPlot = PlotManager . getPlotByOwner ( UUIDFetcher . getUUID ( skull . getOwner ( ) ) . toString ( ) ) ;
2016-09-17 12:10:01 +02:00
assert tpPlot ! = null ;
2016-07-09 13:19:56 +02:00
Location loc = tpPlot . getSpawn ( ) ;
Bukkit . getScheduler ( ) . runTask ( TeamVento . getInstance ( ) , ( ) - > p . teleport ( new Location ( loc . getWorld ( ) , loc . getX ( ) , loc . getY ( ) , loc . getZ ( ) , 89 . 0F , 6 . 0F ) ) ) ;
} ) ;
}
}
}
}