2019-06-11 07:05:05 +02:00
package de.steamwar.bausystem ;
import de.steamwar.bausystem.commands.* ;
2020-07-07 21:21:00 +02:00
import de.steamwar.bausystem.tracer.TNTListener ;
import de.steamwar.bausystem.tracer.TNTTracer15 ;
import de.steamwar.bausystem.tracer.trace.ShowManager ;
2020-01-27 07:04:47 +01:00
import de.steamwar.bausystem.world.* ;
2019-11-10 17:29:01 +01:00
import de.steamwar.core.CommandRemover ;
2020-04-08 17:06:01 +02:00
import de.steamwar.core.Core ;
2020-01-08 23:50:07 +01:00
import de.steamwar.scoreboard.SWScoreboard ;
2019-11-10 17:29:01 +01:00
import de.steamwar.sql.SteamwarUser ;
2019-06-11 07:05:05 +02:00
import org.bukkit.Bukkit ;
2020-07-26 23:00:03 +02:00
import org.bukkit.GameRule ;
2020-03-21 20:01:00 +01:00
import org.bukkit.Material ;
import org.bukkit.attribute.Attribute ;
2019-06-13 10:22:07 +02:00
import org.bukkit.configuration.InvalidConfigurationException ;
2020-03-21 20:01:00 +01:00
import org.bukkit.enchantments.Enchantment ;
2019-06-11 07:05:05 +02:00
import org.bukkit.entity.Player ;
import org.bukkit.event.EventHandler ;
import org.bukkit.event.Listener ;
import org.bukkit.event.entity.PlayerDeathEvent ;
2020-03-21 20:01:00 +01:00
import org.bukkit.event.inventory.InventoryClickEvent ;
2019-09-18 19:19:54 +02:00
import org.bukkit.event.player.PlayerLoginEvent ;
2019-06-13 10:22:07 +02:00
import org.bukkit.event.player.PlayerQuitEvent ;
2020-03-21 20:01:00 +01:00
import org.bukkit.inventory.ItemStack ;
import org.bukkit.inventory.meta.ItemMeta ;
2019-06-11 07:05:05 +02:00
import org.bukkit.plugin.java.JavaPlugin ;
2020-01-19 07:01:07 +01:00
import org.bukkit.scheduler.BukkitTask ;
2019-06-11 07:05:05 +02:00
2019-06-13 10:22:07 +02:00
import java.io.File ;
import java.io.IOException ;
import java.util.List ;
2019-06-11 07:05:05 +02:00
import java.util.UUID ;
2019-09-03 19:56:41 +02:00
import java.util.logging.Level ;
2019-06-11 07:05:05 +02:00
public class BauSystem extends JavaPlugin implements Listener {
private static BauSystem plugin ;
private static UUID owner ;
2019-06-13 10:22:07 +02:00
private static List < ArenaSection > sections ;
2019-06-11 07:05:05 +02:00
public static final String PREFIX = " §eBauSystem§8» §7 " ;
2019-06-20 12:13:30 +02:00
public static final String SECTION_PATH = " /home/minecraft/backbone/server/UserBau/ " ;
2019-06-11 07:05:05 +02:00
2020-01-19 07:01:07 +01:00
private BukkitTask autoShutdown ;
2019-06-11 07:05:05 +02:00
@Override
public void onEnable ( ) {
plugin = this ;
2019-12-31 12:58:55 +01:00
String worldName = Bukkit . getWorlds ( ) . get ( 0 ) . getName ( ) ;
2019-06-11 07:05:05 +02:00
try {
2019-12-31 12:58:55 +01:00
owner = UUID . fromString ( worldName ) ;
2019-12-31 13:02:15 +01:00
sections = ArenaSection . loadFromFile ( new File ( Bukkit . getWorldContainer ( ) . getPath ( ) + '/' + owner . toString ( ) + " /sections.yml " ) ) ;
2019-06-11 07:05:05 +02:00
} catch ( IllegalArgumentException e ) {
2019-12-31 12:58:55 +01:00
try {
2019-12-31 13:02:15 +01:00
int ownerID = Integer . parseInt ( worldName ) ;
owner = SteamwarUser . get ( ownerID ) . getUUID ( ) ;
sections = ArenaSection . loadFromFile ( new File ( Bukkit . getWorldContainer ( ) . getPath ( ) + '/' + ownerID + " /sections.yml " ) ) ;
} catch ( NumberFormatException | IOException | InvalidConfigurationException ex ) {
getLogger ( ) . log ( Level . SEVERE , " owner is no UUID / failed to load sections.yml " , e ) ;
2019-12-31 12:58:55 +01:00
Bukkit . shutdown ( ) ;
return ;
}
2019-12-31 13:02:15 +01:00
} catch ( InvalidConfigurationException | IOException e ) {
getLogger ( ) . log ( Level . SEVERE , " Failed to load sections.yml " , e ) ;
Bukkit . shutdown ( ) ;
return ;
2019-06-11 07:05:05 +02:00
}
try {
2020-01-07 16:38:45 +01:00
CommandRemover . removeAll ( " tp " , " gamemode " , " time " , " clear " ) ;
2019-11-10 17:29:01 +01:00
CommandInjector . injectCommand ( new CommandTeleport ( ) ) ;
CommandInjector . injectCommand ( new CommandGamemode ( ) ) ;
CommandInjector . injectCommand ( new CommandTime ( ) ) ;
2020-01-07 16:38:45 +01:00
CommandInjector . injectCommand ( new CommandClear ( ) ) ;
2019-06-11 07:05:05 +02:00
} catch ( Exception e ) {
2019-09-03 19:56:41 +02:00
getLogger ( ) . log ( Level . SEVERE , " Failed to replace commands " , e ) ;
2019-06-11 07:05:05 +02:00
Bukkit . shutdown ( ) ;
return ;
}
getCommand ( " trace " ) . setExecutor ( new CommandTrace ( ) ) ;
2020-07-18 23:01:50 +02:00
getCommand ( " trace " ) . setTabCompleter ( new CommandTraceTabCompleter ( ) ) ;
2019-06-11 07:05:05 +02:00
getCommand ( " nightvision " ) . setExecutor ( new CommandNV ( ) ) ;
getCommand ( " reset " ) . setExecutor ( new CommandReset ( ) ) ;
getCommand ( " speed " ) . setExecutor ( new CommandSpeed ( ) ) ;
getCommand ( " tnt " ) . setExecutor ( new CommandTNT ( ) ) ;
getCommand ( " fire " ) . setExecutor ( new CommandFire ( ) ) ;
2019-10-24 18:47:23 +02:00
getCommand ( " freeze " ) . setExecutor ( new CommandFreeze ( ) ) ;
2019-06-11 07:05:05 +02:00
getCommand ( " testblock " ) . setExecutor ( new CommandTestblock ( ) ) ;
2019-06-13 10:22:07 +02:00
getCommand ( " bau " ) . setExecutor ( new CommandBau ( ) ) ;
2019-06-14 08:43:40 +02:00
getCommand ( " bauinfo " ) . setExecutor ( new CommandInfo ( ) ) ;
2019-07-11 18:27:46 +02:00
getCommand ( " protect " ) . setExecutor ( new CommandProtect ( ) ) ;
2019-07-14 20:07:46 +02:00
getCommand ( " skull " ) . setExecutor ( new CommandSkull ( ) ) ;
2019-09-03 19:56:41 +02:00
getCommand ( " loader " ) . setExecutor ( new CommandLoader ( ) ) ;
2019-11-23 21:36:49 +01:00
getCommand ( " lockschem " ) . setExecutor ( new CommandLockschem ( ) ) ;
2020-07-04 09:29:04 +02:00
getCommand ( " debugstick " ) . setExecutor ( new CommandDebugStick ( ) ) ;
2020-06-30 07:34:19 +02:00
getCommand ( " watervision " ) . setExecutor ( new CommandGills ( ) ) ;
2019-06-11 07:05:05 +02:00
Bukkit . getPluginManager ( ) . registerEvents ( this , this ) ;
Bukkit . getPluginManager ( ) . registerEvents ( new RegionListener ( ) , this ) ;
2019-09-03 19:56:41 +02:00
Bukkit . getPluginManager ( ) . registerEvents ( new TNTListener ( ) , this ) ;
2020-01-07 23:22:31 +01:00
Bukkit . getPluginManager ( ) . registerEvents ( new BauScoreboard ( ) , this ) ;
2020-01-27 07:04:47 +01:00
new AFKStopper ( ) ;
2020-07-07 21:21:00 +02:00
if ( Core . getVersion ( ) = = 15 ) {
TNTTracer15 . initTNTTracer_15 ( ) ;
}
2020-01-19 07:01:07 +01:00
autoShutdown = Bukkit . getScheduler ( ) . runTaskLater ( this , Bukkit : : shutdown , 1200 ) ;
2019-06-11 07:05:05 +02:00
}
public static BauSystem getPlugin ( ) {
return plugin ;
}
public static UUID getOwner ( ) {
return owner ;
}
2019-06-13 10:22:07 +02:00
public static List < ArenaSection > getSections ( ) {
return sections ;
}
public static int getOwnerID ( ) {
2019-11-10 17:29:01 +01:00
return SteamwarUser . get ( owner ) . getId ( ) ;
2019-06-13 10:22:07 +02:00
}
2019-06-11 07:05:05 +02:00
@EventHandler
public void onDeath ( PlayerDeathEvent e ) {
e . setDeathMessage ( null ) ;
}
@EventHandler
2019-09-18 19:19:54 +02:00
public void onJoin ( PlayerLoginEvent e ) {
2020-01-19 07:01:07 +01:00
if ( autoShutdown ! = null ) {
autoShutdown . cancel ( ) ;
autoShutdown = null ;
}
2019-06-11 07:05:05 +02:00
Player p = e . getPlayer ( ) ;
2020-02-25 18:04:38 +01:00
p . setOp ( true ) ;
/ * PermissionAttachment attachment = p . addAttachment ( this ) ;
2019-06-11 07:05:05 +02:00
attachment . setPermission ( " F3NPerm.use " , true ) ;
2020-02-21 16:58:00 +01:00
attachment . setPermission ( " fawe.tips " , false ) ;
attachment . setPermission ( " fawe.admin " , true ) ;
2019-06-11 07:05:05 +02:00
attachment . setPermission ( " fawe.permpack.basic " , true ) ;
attachment . setPermission ( " worldedit.navigation.jumpto.tool " , true ) ;
attachment . setPermission ( " worldedit.navigation.thru.tool " , true ) ;
2020-01-03 17:01:28 +01:00
attachment . setPermission ( " worldedit.biome.info " , true ) ;
attachment . setPermission ( " worldedit.biome.set " , true ) ;
attachment . setPermission ( " worldedit.biome.list " , true ) ;
attachment . setPermission ( " worldedit.chunkinfo " , true ) ;
attachment . setPermission ( " worldedit.listchunks " , true ) ;
attachment . setPermission ( " worldedit.clipboard.cut " , true ) ;
attachment . setPermission ( " worldedit.clipboard.paste " , true ) ;
attachment . setPermission ( " worldedit.schematic.formats " , true ) ;
attachment . setPermission ( " worldedit.schematic.load " , true ) ;
attachment . setPermission ( " worldedit.schematic.list " , true ) ;
attachment . setPermission ( " worldedit.schematic.save " , true ) ;
attachment . setPermission ( " worldedit.clipboard.clear " , true ) ;
attachment . setPermission ( " worldedit.clipboard.copy " , true ) ;
attachment . setPermission ( " worldedit.clipboard.lazycopy " , true ) ;
attachment . setPermission ( " worldedit.clipboard.place " , true ) ;
attachment . setPermission ( " worldedit.clipboard.download " , true ) ;
attachment . setPermission ( " worldedit.clipboard.flip " , true ) ;
attachment . setPermission ( " worldedit.clipboard.rotate " , true ) ;
attachment . setPermission ( " worldedit.help " , true ) ;
attachment . setPermission ( " worldedit.global-mask " , true ) ;
attachment . setPermission ( " worldedit.global-transform " , true ) ;
attachment . setPermission ( " worldedit.generation.cylinder " , true ) ;
attachment . setPermission ( " worldedit.generation.sphere " , true ) ;
attachment . setPermission ( " worldedit.generation.forest " , true ) ;
attachment . setPermission ( " worldedit.generation.pumpkins " , true ) ;
attachment . setPermission ( " worldedit.generation.pyramid " , true ) ;
attachment . setPermission ( " worldedit.generation.shape " , true ) ;
attachment . setPermission ( " worldedit.biome.set " , true ) ;
attachment . setPermission ( " worldedit.history.undo " , true ) ;
attachment . setPermission ( " worldedit.history.redo " , true ) ;
attachment . setPermission ( " worldedit.history.rollback " , true ) ;
attachment . setPermission ( " worldedit.navigation.unstuck " , true ) ;
attachment . setPermission ( " worldedit.navigation.ascend " , true ) ;
attachment . setPermission ( " worldedit.navigation.descend " , true ) ;
attachment . setPermission ( " worldedit.navigation.ceiling " , true ) ;
attachment . setPermission ( " worldedit.navigation.thru.command " , true ) ;
attachment . setPermission ( " worldedit.navigation.jumpto.command " , true ) ;
attachment . setPermission ( " worldedit.navigation.up " , true ) ;
attachment . setPermission ( " worldedit.region.hollow " , true ) ;
attachment . setPermission ( " worldedit.region.line " , true ) ;
attachment . setPermission ( " worldedit.region.curve " , true ) ;
attachment . setPermission ( " worldedit.region.overlay " , true ) ;
attachment . setPermission ( " worldedit.region.center " , true ) ;
attachment . setPermission ( " worldedit.region.naturalize " , true ) ;
attachment . setPermission ( " worldedit.region.walls " , true ) ;
attachment . setPermission ( " worldedit.region.faces " , true ) ;
attachment . setPermission ( " worldedit.region.smooth " , true ) ;
attachment . setPermission ( " worldedit.region.move " , true ) ;
attachment . setPermission ( " worldedit.region.forest " , true ) ;
attachment . setPermission ( " worldedit.region.replace " , true ) ;
attachment . setPermission ( " worldedit.region.stack " , true ) ;
attachment . setPermission ( " worldedit.region.set " , true ) ;
attachment . setPermission ( " worldedit.selection.pos " , true ) ;
attachment . setPermission ( " worldedit.selection.chunk " , true ) ;
attachment . setPermission ( " worldedit.selection.hpos " , true ) ;
attachment . setPermission ( " worldedit.wand " , true ) ;
attachment . setPermission ( " worldedit.wand.toggle " , true ) ;
attachment . setPermission ( " worldedit.selection.contract " , true ) ;
attachment . setPermission ( " worldedit.selection.outset " , true ) ;
attachment . setPermission ( " worldedit.selection.inset " , true ) ;
attachment . setPermission ( " worldedit.analysis.distr " , true ) ;
attachment . setPermission ( " worldedit.analysis.count " , true ) ;
attachment . setPermission ( " worldedit.selection.size " , true ) ;
attachment . setPermission ( " worldedit.selection.expand " , true ) ;
attachment . setPermission ( " worldedit.selection.shift " , true ) ;
attachment . setPermission ( " worldedit.snapshots.list " , true ) ;
attachment . setPermission ( " worldedit.superpickaxe " , true ) ;
attachment . setPermission ( " worldedit.superpickaxe.area " , true ) ;
attachment . setPermission ( " worldedit.superpickaxe.recursive " , true ) ;
attachment . setPermission ( " worldedit.brush.blendball " , true ) ;
attachment . setPermission ( " worldedit.brush.erode " , true ) ;
attachment . setPermission ( " worldedit.brush.pull " , true ) ;
attachment . setPermission ( " worldedit.brush.circle " , true ) ;
attachment . setPermission ( " worldedit.brush.recursive " , true ) ;
attachment . setPermission ( " worldedit.brush.line " , true ) ;
attachment . setPermission ( " worldedit.brush.spline " , true ) ;
attachment . setPermission ( " worldedit.brush.surfacespline " , true ) ;
attachment . setPermission ( " worldedit.brush.shatter " , true ) ;
attachment . setPermission ( " worldedit.brush.stencil " , true ) ;
attachment . setPermission ( " worldedit.brush.height " , true ) ;
attachment . setPermission ( " worldedit.brush.layer " , true ) ;
attachment . setPermission ( " worldedit.brush.populateschematic " , true ) ;
attachment . setPermission ( " worldedit.brush.scatter " , true ) ;
attachment . setPermission ( " worldedit.brush.splatter " , true ) ;
attachment . setPermission ( " worldedit.brush.scattercommand " , true ) ;
attachment . setPermission ( " worldedit.brush.copy " , true ) ;
attachment . setPermission ( " worldedit.brush.command " , true ) ;
attachment . setPermission ( " worldedit.brush.apply " , true ) ;
attachment . setPermission ( " worldedit.brush.sphere " , true ) ;
attachment . setPermission ( " worldedit.brush.cylinder " , true ) ;
attachment . setPermission ( " worldedit.brush.clipboard " , true ) ;
attachment . setPermission ( " worldedit.brush.smooth " , true ) ;
attachment . setPermission ( " worldedit.brush.ex " , true ) ;
attachment . setPermission ( " worldedit.brush.gravity " , true ) ;
attachment . setPermission ( " worldedit.brush.options.range " , true ) ;
attachment . setPermission ( " worldedit.brush.options.material " , true ) ;
attachment . setPermission ( " worldedit.brush.options.size " , true ) ;
attachment . setPermission ( " worldedit.brush.options.mask " , true ) ;
attachment . setPermission ( " worldedit.brush.options.smask " , true ) ;
attachment . setPermission ( " worldedit.brush.options.transform " , true ) ;
attachment . setPermission ( " worldedit.brush.options.scroll " , true ) ;
attachment . setPermission ( " worldedit.brush.options.visualize " , true ) ;
attachment . setPermission ( " worldedit.tool.deltree " , true ) ;
attachment . setPermission ( " worldedit.tool.farwand " , true ) ;
attachment . setPermission ( " worldedit.tool.lrbuild " , true ) ;
attachment . setPermission ( " worldedit.tool.info " , true ) ;
attachment . setPermission ( " worldedit.tool.tree " , true ) ;
attachment . setPermission ( " worldedit.tool.replacer " , true ) ;
attachment . setPermission ( " worldedit.tool.data-cycler " , true ) ;
attachment . setPermission ( " worldedit.tool.flood-fill " , true ) ;
attachment . setPermission ( " worldedit.tool.inspect " , true ) ;
attachment . setPermission ( " worldedit.fill.recursive " , true ) ;
attachment . setPermission ( " worldedit.drain " , true ) ;
attachment . setPermission ( " worldedit.fixlava " , true ) ;
attachment . setPermission ( " worldedit.fixwater " , true ) ;
attachment . setPermission ( " worldedit.removeabove " , true ) ;
attachment . setPermission ( " worldedit.removebelow " , true ) ;
attachment . setPermission ( " worldedit.removenear " , true ) ;
attachment . setPermission ( " worldedit.replacenear " , true ) ;
attachment . setPermission ( " worldedit.snow " , true ) ;
attachment . setPermission ( " worldedit.thaw " , true ) ;
attachment . setPermission ( " worldedit.green " , true ) ;
attachment . setPermission ( " worldedit.extinguish " , true ) ;
attachment . setPermission ( " worldedit.calc " , true ) ;
2020-02-25 18:04:38 +01:00
attachment . setPermission ( " worldedit.fill " , true ) ; * /
2020-07-07 21:21:00 +02:00
if ( Core . getVersion ( ) = = 15 ) ShowManager . add ( p ) ;
2020-07-26 23:00:03 +02:00
Bukkit . getWorlds ( ) . get ( 0 ) . setGameRule ( GameRule . REDUCED_DEBUG_INFO , false ) ;
2019-06-11 07:05:05 +02:00
}
2019-06-13 10:22:07 +02:00
@EventHandler
2020-01-07 23:22:31 +01:00
public void onLeave ( PlayerQuitEvent e ) {
2020-01-20 18:16:15 +01:00
Player player = e . getPlayer ( ) ;
SWScoreboard . removeScoreboard ( player ) ;
2020-07-07 21:21:00 +02:00
if ( Bukkit . getOnlinePlayers ( ) . isEmpty ( ) | | ( Bukkit . getOnlinePlayers ( ) . size ( ) = = 1 & & Bukkit . getOnlinePlayers ( ) . contains ( player ) ) ) {
2019-06-13 10:22:07 +02:00
Bukkit . shutdown ( ) ;
2020-07-07 21:21:00 +02:00
return ;
}
if ( Core . getVersion ( ) = = 15 ) ShowManager . remove ( e . getPlayer ( ) ) ;
2019-06-13 10:22:07 +02:00
}
2020-03-21 20:01:00 +01:00
@EventHandler
public void onInventoryClick ( InventoryClickEvent e ) {
ItemStack stack = e . getCursor ( ) ;
if ( stack = = null )
return ;
if ( ! stack . hasItemMeta ( ) )
return ;
if ( stack . getItemMeta ( ) . hasEnchants ( ) ) {
for ( Enchantment en : Enchantment . values ( ) ) {
if ( stack . getEnchantmentLevel ( en ) > en . getMaxLevel ( ) )
stack . removeEnchantment ( en ) ;
}
}
Player p = ( Player ) e . getWhoClicked ( ) ;
2020-04-08 17:06:01 +02:00
Material material = stack . getType ( ) ;
if ( material = = Material . POTION | | material = = Material . SPLASH_POTION | | material = = Material . LINGERING_POTION )
stack . setType ( Material . MILK_BUCKET ) ;
if ( Core . getVersion ( ) < 14 ) {
e . setCurrentItem ( stack ) ;
return ;
}
2020-03-21 20:01:00 +01:00
if ( stack . getItemMeta ( ) . hasAttributeModifiers ( ) ) {
ItemMeta meta = stack . getItemMeta ( ) ;
for ( Attribute a : Attribute . values ( ) )
meta . removeAttributeModifier ( a ) ;
stack . setItemMeta ( meta ) ;
2020-04-05 15:13:40 +02:00
Bukkit . getLogger ( ) . log ( Level . SEVERE , " Spieler " + p . getName ( ) + " ( " + p . getUniqueId ( ) . toString ( ) + " ) hat versucht ein Item mit einem Attribute-Modifier zu bekommen. " ) ;
2020-03-21 20:01:00 +01:00
}
e . setCurrentItem ( stack ) ;
}
2019-06-11 07:05:05 +02:00
}