2014-11-08 20:27:09 +01:00
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands ;
2014-11-05 04:42:08 +01:00
2015-01-13 17:38:15 +01:00
import com.intellectualcrafters.plot.config.C ;
2015-07-03 04:11:41 +02:00
import com.intellectualcrafters.plot.flag.Flag ;
import com.intellectualcrafters.plot.flag.FlagManager ;
2015-07-30 16:25:16 +02:00
import com.intellectualcrafters.plot.object.Location ;
import com.intellectualcrafters.plot.object.Plot ;
import com.intellectualcrafters.plot.object.PlotBlock ;
import com.intellectualcrafters.plot.object.PlotInventory ;
import com.intellectualcrafters.plot.object.PlotItemStack ;
import com.intellectualcrafters.plot.object.PlotPlayer ;
2015-07-03 04:11:41 +02:00
import com.intellectualcrafters.plot.util.BlockManager ;
2015-02-22 07:06:59 +01:00
import com.intellectualcrafters.plot.util.MainUtil ;
2015-07-27 19:50:04 +02:00
import com.plotsquared.general.commands.CommandDeclaration ;
2014-11-05 04:42:08 +01:00
2015-09-13 06:04:31 +02:00
@CommandDeclaration ( command = " music " , permission = " plots.music " , description = " Player music in a plot " , usage = " /plot music " , category = CommandCategory . ACTIONS , requiredType = RequiredType . NONE )
public class MusicSubcommand extends SubCommand {
2014-10-30 16:16:26 +01:00
@Override
2015-09-13 06:04:31 +02:00
public boolean onCommand ( final PlotPlayer player , final String [ ] args ) {
2015-02-23 02:32:27 +01:00
final Location loc = player . getLocation ( ) ;
2015-09-22 15:23:28 +02:00
final Plot plot = MainUtil . getPlotAbs ( loc ) ;
2015-09-13 06:04:31 +02:00
if ( plot = = null ) {
return ! sendMessage ( player , C . NOT_IN_PLOT ) ;
}
if ( ! plot . isAdded ( player . getUUID ( ) ) ) {
2014-10-30 16:16:26 +01:00
sendMessage ( player , C . NO_PLOT_PERMS ) ;
return true ;
}
2015-09-13 06:04:31 +02:00
final PlotInventory inv = new PlotInventory ( player , 2 , " Plot Jukebox " ) {
2015-09-11 12:09:22 +02:00
@Override
2015-09-13 06:04:31 +02:00
public boolean onClick ( final int index ) {
2015-09-11 12:09:22 +02:00
final PlotItemStack item = getItem ( index ) ;
2015-07-25 09:09:47 +02:00
if ( item = = null ) {
2015-09-12 17:19:39 +02:00
return true ;
2015-07-25 09:09:47 +02:00
}
2015-09-11 12:09:22 +02:00
final int id = item . id = = 7 ? 0 : item . id ;
2015-09-13 06:04:31 +02:00
if ( id = = 0 ) {
2015-07-25 09:09:47 +02:00
FlagManager . removePlotFlag ( plot , " music " ) ;
2015-09-13 06:04:31 +02:00
} else {
2015-07-25 09:09:47 +02:00
FlagManager . addPlotFlag ( plot , new Flag ( FlagManager . getFlag ( " music " ) , id ) ) ;
}
return false ;
}
} ;
2015-07-03 04:11:41 +02:00
int index = 0 ;
2015-09-13 06:04:31 +02:00
for ( int i = 2256 ; i < 2268 ; i + + ) {
2015-09-11 12:09:22 +02:00
final String name = " &r&6 " + BlockManager . manager . getClosestMatchingName ( new PlotBlock ( ( short ) i , ( byte ) 0 ) ) ;
final String [ ] lore = { " &r&aClick to play! " } ;
final PlotItemStack item = new PlotItemStack ( i , ( byte ) 0 , 1 , name , lore ) ;
2015-07-03 04:11:41 +02:00
inv . setItem ( index , item ) ;
index + + ;
2014-10-30 16:16:26 +01:00
}
2015-09-13 06:04:31 +02:00
if ( player . getMeta ( " music " ) ! = null ) {
2015-09-11 12:09:22 +02:00
final String name = " &r&6Cancel music " ;
final String [ ] lore = { " &r&cClick to cancel! " } ;
2015-07-05 12:51:34 +02:00
inv . setItem ( index , new PlotItemStack ( 7 , ( short ) 0 , 1 , name , lore ) ) ;
}
2015-07-03 04:11:41 +02:00
inv . openInventory ( ) ;
2014-10-30 16:16:26 +01:00
return true ;
}
2014-11-05 04:42:08 +01:00
}