diff --git a/.gitignore b/.gitignore index f6b5a60..b37c262 100644 --- a/.gitignore +++ b/.gitignore @@ -1,35 +1,16 @@ -# Eclipse -/.classpath -/.project -/.settings +## IntelliJ : https://github.com/github/gitignore/blob/master/Global/JetBrains.gitignore +## Maven : https://github.com/github/gitignore/blob/master/Maven.gitignore -# Netbeans -/nbproject +# User-specific stuff: +.idea/dictionaries +.idea/libraries +.idea/workspace.xml +.idea/vcs.xml -# We use maven! -/build.xml +# Sensitive or high-churn files: +.idea/uiDesigner.xml -# Maven -/target +# Maven: +target/ -# Vim -.*.sw[a-p] - -# Various other potential build files -/build -/bin -/dist -/manifest.mf - -/world - -# Mac filesystem dust -.DS_Store - -# IntelliJ -*.iml -*.ipr -*.iws -.idea/ -/bin1 -/lib \ No newline at end of file +## Plugin-specific files: diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..cb6eb59 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +BloodMoon \ No newline at end of file diff --git a/.idea/BloodMoon.iml b/.idea/BloodMoon.iml new file mode 100644 index 0000000..bda24c7 --- /dev/null +++ b/.idea/BloodMoon.iml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/artifacts/BloodMoon.xml b/.idea/artifacts/BloodMoon.xml new file mode 100644 index 0000000..21ab61f --- /dev/null +++ b/.idea/artifacts/BloodMoon.xml @@ -0,0 +1,9 @@ + + + $PROJECT_DIR$/../../Serveurs/Tests/plugins + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..6ec466a --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/Apache_2_0.xml b/.idea/copyright/Apache_2_0.xml new file mode 100644 index 0000000..d5e226a --- /dev/null +++ b/.idea/copyright/Apache_2_0.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..8c8fd2d --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..54f4238 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..22fbae1 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/CONFIG.md b/CONFIG.md new file mode 100644 index 0000000..18915b2 --- /dev/null +++ b/CONFIG.md @@ -0,0 +1,543 @@ +## Config +All aspects of the blood moon can be configured, below is an example of a config file which would enable all of the features. More details on each section can be found below. Each section contains an enabled setting, this controls if that feature will be used or not. You will almost certainly want to configure the plugin to your needs, by default everything is enabled. One of these files will be created for each world that exists on the server, there is no global config. + +``` +enabled: false +always-on: false +chance: 14 +features: + chat-message: + enabled: true + message: '&cThe bloodmoon is rising !' + server-commands: + enabled: false + commands: + start: + - toggledownfall + - time set 0 + - op Notch + end: + - toggledownfall + - time set 12000 + - deop Notch + play-sound: + enabled: true + sound: WITHER_SPAWN + pitch: 1.0 + volume: 1.0 + arrow-rate: + enabled: true + multiplier: 2 + fire-arrows: + enabled: true + chance: 100 + ignite-target: true + zombie-weapon: + enabled: true + chance: 60 + drop-chance: 25 + ignore-spawners: true + weapons: + - DIAMOND_SWORD + - GOLD_SWORD + - IRON_SWORD + zombie-armor: + enabled: true + chance: 60 + drop-chance: 7 + ignore-spawners: true + armor: + - DIAMOND + - GOLD + - IRON + target-distance: + enabled: true + multiplier: 3 + mobs: + - ZOMBIE + - SKELETON + - SPIDER + - CREEPER + movement-speed: + enabled: true + multiplier: 1.3 + fast-chance: 15 + fast-multiplier: 1.5 + mobs: + - ZOMBIE + - SKELETON + - CREEPER + break-blocks: + enabled: true + drop-items: true + realistic-drop: true + mobs: + - ZOMBIE + - SKELETON + - SPIDER + - CREEPER + - ENDERMAN + blocks: + - WOOD + - LOG + - GLASS + max-health: + enabled: true + multiplier: 2.0 + mobs: + - ZOMBIE + - SKELETON + - SPIDER + - CREEPER + - ENDERMAN + more-spawning: + enabled: true + multiplier: 2 + mobs: + - ZOMBIE + - SKELETON + - SPIDER + - CREEPER + - ENDERMAN + more-exp: + enabled: true + ignore-spawners: false + multiplier: 2 + more-drops: + enabled: true + ignore-spawners: false + multiplier: 2 + sword-damage: + enabled: true + mobs: + - ZOMBIE + - SKELETON + - SPIDER + - CREEPER + - ENDERMAN + chance: 10 + super-creepers: + enabled: true + power: 4.0 + fire: true + spawn-on-kill: + enabled: true + mobs: + - ZOMBIE + - SKELETON + - SPIDER + - CREEPER + - ENDERMAN + chance: 10 + spawn: + - ZOMBIE + - SKELETON + - SPIDER + - CREEPER + - ENDERMAN + spawn-on-sleep: + enabled: true + spawn: + - ZOMBIE + spawn-control: + enabled: true + spawn: + - ZOMBIE + - SKELETON + - SPIDER + - CREEPER + - ENDERMAN + - PIG_ZOMBIE + - BLAZE + - MAGMA_CUBE + lock-in-world: + enabled: false + texture-pack: + enabled: false + normal: http://bukkit.jacekk.co.uk/bloodmoon_tps/normal.zip + bloodmoon: http://bukkit.jacekk.co.uk/bloodmoon_tps/bloodmoon.zip + extended-night: + enabled: true + min-kills: 16 + max-resets: 6 + weather: + enabled: true + thunder: true + rain: true + daylight-proof-mobs: + enabled: true + nether-sky: + enabled: false + dungeons: + enabled: true + biomes: + - PLAINS + - ICE_PLAINS + - DESERT + - SWAMPLAND + chance: 10 + min-layers: 3 + max-layers: 5 + chest-items: + - BREAD + - APPLE + - PORK + - SADDLE + - BUCKET + - STRING + - REDSTONE + - SULPHUR + - COCOA + min-stack-size: 1 + max-stack-size: 8 + items-per-chest: 12 + spawner-types: + - ZOMBIE + - SKELETON + spawner-delay: 100 + spawner-count: 6 + spawner-max-mobs: 8 +``` + +## Main Options +``` +enabled: false +always-on: false +chance: 14 +``` +Setting enabled to true will enable the plugin for this world, when disabled none of the other options have any effect. Setting always-on to true will override the chance and force the blood moon to be active all of the time. The chance setting controls how often a blood moon will occur, this is a percentage so setting it to 100 will cause the blood moon to happen every night. + +## Features +### chat-message +``` + chat-message: + enabled: true + message: '&cThe bloodmoon is rising !' +``` +This section controls the chat message that is sent to players when they enter a world that has a bloodmoon or one starts in their world. The standard colour codes can be used. + +### server-commands +``` + server-commands: + enabled: false + commands: + start: + - toggledownfall + - time set 0 + - op Notch + end: + - toggledownfall + - time set 12000 + - deop Notch +``` +This section controls server commands that are executed when a bloodmoon starts and ends, allowing for customisation with other plugins and server features. The commands.start and commands.end sections list the commands that are executed if this feature is enabled. + +### play-sound +``` + play-sound: + enabled: true + sound: WITHER_SPAWN + pitch: 1.0 + volume: 1.0 +``` +If this feature is enabled a sound will be played when the blood moon starts. The sound option controls which sound is played and the pitch and volume options modify the pitch and volume of the sound. For a full list of supported sounds see the Bukkit JavaDoc + +### arrow-rate +``` + arrow-rate: + enabled: true + multiplier: 2 +``` +This section controls the rate at which skeletons will shoot arrows during a bloodmoon the multiplier option controls how fast arrows will be fired. + +**WARNING:** Setting multiplier to a value above 20 will cause a divide by zero error. + +### fire-arrows +``` + fire-arrows: + enabled: true + chance: 100 + ignite-arget: true +``` +This section controls if the arrows that skeletons shoot should be set alight or not, the ignite-target option controls if they should set the blocks they hit alight too. + +### zombie-weapon +``` + zombie-weapon: + enabled: true + chance: 60 + drop-chance: 25 + weapons: + - DIAMOND_SWORD + - GOLD_SWORD + - IRON_SWORD +``` +This section controls if zombies should spawn with weapons in their hand, the chance is how likely it is that a zombie will have a weapon and drop-chance is how likely they are to drop it when they are killed. The name of any item can be used in the weapons list, an entry is picked from here at random. + +### zombie-armor +``` + zombie-armor: + enabled: true + chance: 60 + drop-chance: 7 + armor: + - DIAMOND + - GOLD + - IRON +``` +This section controls if zombies should spawn wearing armor, the chance is how likely it is that a zombie will have armor and drop-chance is how likely they are to drop a single part of it when they are killed. The type of armor is picked at random from the armor list. + +### target-distance +``` + target-distance: + enabled: true + multiplier: 3 + mobs: + - ZOMBIE + - SKELETON + - SPIDER + - CREEPER +``` +This section controls how much further mobs will target players from, the mobs list controls which mobs this will affect. Setting the multiplier to a high value will cause a significant drop in performance. + +### movement-speed +``` + movement-speed: + enabled: true + multiplier: 1.3 + fast-chance: 15 + fast-multiplier: 1.5 + mobs: + - ZOMBIE + - SKELETON + - CREEPER +``` +This section controls how much faster mobs should move. Setting the multiplier option to 1.0 will leave the mobs at their normal speed, the default of 1.35 make zombies move slightly faster than spiders do by default. fast-chance is the percentage chance that the mob will move at the fast-multiplier instead of the previous one. + +### break-blocks +``` + break-blocks: + enabled: true + drop-items: true + realistic-drop: true + mobs: + - ZOMBIE + - SKELETON + - SPIDER + - CREEPER + - ENDERMAN + blocks: + - WOOD + - LOG + - GLASS +``` +This section allows you to configure which mobs are able to break the blocks they are facing as well as which blocks can be broken. The mobs section is the same as for the above double-health section except that it controls which mobs can break the blocks. If the realistic-drop option is set to true the blocks will drop the same items as they would if broken by a player, if not (the default) they will drop their block type. For example, a glowstone block will drop glowstone dust with realistic-drop set to true and a glowstone block with it set to false, if stop-items is set to false no items will drop at all (useful for large servers). Finally the blocks section controls which blocks can be broken, their names should be used and as with the mob lists they must be in upper-case. + +### max-health +``` + double-health: + enabled: true + multiplier: 2.0 + mobs: + - ZOMBIE + - SKELETON + - SPIDER + - CREEPER + - ENDERMAN +``` +This section controls which mobs should have their health increased, the mobs setting should contain a list of mob names to apply this feature to and the multiplier option controls how much higher the health should be. + +### more-spawning +``` + more-spawning: + enabled: true + multiplier: 2 + mobs: + - ZOMBIE + - SKELETON + - SPIDER + - CREEPER + - ENDERMAN +``` +This section allows you to control how many more mobs than usual should spawn, the multiplier controls how many more should spawn. The mobs list controls which mobs this should affect. + +### more-exp +``` + more-exp: + enabled: true + ignore-spawners: false + multiplier: 2 +``` +This section controls how much more experience orbs should be dropped when a player kills a mob. The ignore-spawners option makes this not affect mobs that came form spawners and the multiplier controls how much more XP should be dropped. + +### more-drops +``` + more-drops: + enabled: true + ignore-spawners: false + multiplier: 2 +``` +This section controls how many more items should be dropped when a player kills a mob. The ignore-spawners option makes this not affect mobs that came form spawners and the multiplier controls how many more items should be dropped. + +### sword-damage +``` + sword-damage: + enabled: true + mobs: + - ZOMBIE + - SKELETON + - SPIDER + - CREEPER + - ENDERMAN + chance: 10 +``` +This section allows you to configure the random large damage that can be done to weapons when attacking mobs. The mobs section controls which mobs this should work for, as above this needs to be a list of their names in upper-case. The chance option controls the percentage chance that a weapon will receive large damage with every strike of one of the mobs on the list. + +### super-creepers +``` + super-creepers: + enabled: true + power: 4.0 + fire: true +``` +This section controls the modification of creeper explosions, with this enabled the explosions will cause fires to start on the destroyed blocks. The power setting controls the size of the explosion, the default of 4.0 is the same as a TNT explosion, there is no limit imposed on this value so be sensible. The fire setting controls if the explosions should start fires or not. + +### spawn-on-kill +``` + spawn-on-kill: + enabled: true + mobs: + - ZOMBIE + - SKELETON + - SPIDER + - CREEPER + - ENDERMAN + chance: 10 + spawn: + - ZOMBIE + - SKELETON + - SPIDER + - CREEPER + - ENDERMAN +``` +This controls if a mob should be spawned when a player kills a mob. The spawn section is the same as for spawn-on-sleep it should contains a list of mobs that might spawn. The mobs section controls which mobs this applies to, and the chance option controls the percentage chance that a mob will spawn. There is no limit imposed on the chance but setting it to anything close to 100 will be very irritating. + +### spawn-on-sleep +``` + spawn-on-sleep: + enabled: true + spawn: + - ZOMBIE +``` +This controls if a mob should be spawned if a player tries to sleep during a blood moon. The spawn section should specify a list of mobs, one mob from this list will be randomly picked and spawned if a player tries to use a bed. + +### spawn-control +``` + spawn-control: + enabled: true + spawn: + - ZOMBIE + - SKELETON + - SPIDER + - CREEPER + - ENDERMAN + - PIG_ZOMBIE + - BLAZE + - MAGMA_CUBE +``` +This section allows you to modify the mobs that will spawn during a bloodmoon, only the entities names in the spawn list will appear. You can add mobs that do not naturally spawn in the overworld. + +### lock-in-world +``` + lock-in-world: + enabled: true +``` +If this is set to false the player will not be allowed to leave the world they are in until the bloodmoon has ended. New players will still be able to enter so this may be seen as a little unfair. + +### texture-pack +``` + texture-pack: + enabled: false + normal: http://bukkit.jacekk.co.uk/bloodmoon_tps/normal.zip + bloodmoon: http://bukkit.jacekk.co.uk/bloodmoon_tps/bloodmoon.zip +``` +These texture packs are sent to the client depending on the bloodmoon state, the default values for this feature simply make the moon red during a bloodmoon. + +### extended-night +``` + extended-night: + enabled: true + min-kills: 16 + max-resets: 6 +``` +This feature will cause the night to repeat if the required number of mobs have not been killed. The night will stop repeating after mine-kills mobs have been killed or it has already reset max-resets times. + +### weather +``` + weather: + enabled: true + thunder: true + rain: true +``` +This section allows you to control the weather during a blood moon, setting rain to true will make it rain until the event is over and thunder will make it thunder until the event is over. + +### daylight-proof-mobs +``` + daylight-proof-mobs: + enabled: true +``` +If enabled mobs will not take damage from being in sunlight, useful for always-on mode. + +### nether-sky +``` + nether-sky: + enabled: false +``` +If this feature is enabled players will see the sky from the nether in all worlds with an active bloodmoon, this defaults to false as it causes the player to see the respawn screen when the bloodmoon starts. + +### dungeons +``` + dungeons: + enabled: true + biomes: + - PLAINS + - ICE_PLAINS + - DESERT + - SWAMPLAND + chance: 10 + min-layers: 3 + max-layers: 5 + chest-items: + - BREAD + - APPLE + - PORK + - SADDLE + - BUCKET + - STRING + - REDSTONE + - SULPHUR + - COCOA + min-stack-size: 1 + max-stack-size: 8 + items-per-chest: 12 + spawner-types: + - ZOMBIE + - SKELETON + spawner-delay: 100 + spawner-count: 6 + spawner-max-mobs: 8 +``` +This section controls the occurrence and features of the dungeons that can be generated in the world. These are much larger than the vanilla ones and will typically be much more hostile. They are also the only feature which is always present in the world regardless of the time. + +- biomes - A list of biomes which will generate dungeons, they work much better in flat areas and can cause problems in jungles where there are lots of other structures. +- chance - The chance that each chunk has of containing a dungeon. this is a fraction of 10,000 +- min-layers - The minimum number of floors that a dungeon can have +- max-layers - The maximum number of floors that a dungeon can have, note that setting this too high will result in them reaching the bottom of the would and there being no loot being added. +- chest-items - A list of items which can be found in the loot chests. +- min-stack-size - The minimum number of items which will be placed into each stack in the chest. +- max-stack-size - The maximum number of items which will be placed into each stack in the chest. Items which cannot normally be stacked will only ever generate as a single item. +- items-per-chest - The number of items to place in each of the four chests in the loot room. This is actually the number of times an item will be placed into a random slot in the chest meaning that less items can be found if the same slot if picked more than once. +- spawner-types - The mob types to place spawners for. +- spawner-delay - The time in ticks between spawn attempts from a spawner, a lower value will make it harder to break a spawner without more mobs spawning. The vanilla dungeons use a value between 600 and 800 for this. +- spawner-count - The number of attempts a spawner will make to spawn a mob after each delay, a higher value will mean that players become overrun much faster. Vanilla dungeons use a value of 4. +- spanwer-max-mobs - The number of mobs that need to be around a spawner to prevent it from spawning, each floor of the dungeon has 2 spawners so this will roughly be half of the number of mobs found on each floor. Vanilla dungeons use a value of 4. diff --git a/LICENSE.md b/LICENSE.md deleted file mode 100644 index 9cecc1d..0000000 --- a/LICENSE.md +++ /dev/null @@ -1,674 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - {one line to give the program's name and a brief idea of what it does.} - Copyright (C) {year} {name of author} - - 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, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - {project} Copyright (C) {year} {fullname} - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. diff --git a/README.md b/README.md index 9bd5cc1..99e6638 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,43 @@ -# BloodMoon -Contiuous integration of BloodMoon *Hopefully* -# Status -Currently working in spigot 1.8, although still looking for bugs and issues. -# Source -http://dev.bukkit.org/bukkit-plugins/bloodmoon/ \ No newline at end of file +# BloodMoon by Hexosse +This is a modified version of [Jacek (betterphp) BloodMoon project](https://github.com/betterphp/BloodMoon) + +## Status +Currently working in spigot 1.9 + +## Description +This plugin will add a blood moon event to your server, each night has a configurable chance of a blood moon. During a blood mood the game is made a lot harder: +- Skeletons shoot faster. +- Skeletons shoot fire arrows (that start fires). +- Zombies spawn with weapons and armor. +- Mobs can break blocks when focused on a player. +- Hostile mobs have more health. +- Small chance of your sword taking massive damage with each strike. +- Creepers have much more powerful explosions (that cause fire). +- Any hostile mob killed has a small chance of coming back as a zombie (or other mob). +- A mob will spawn if you try to sleep. +- More mobs will spawn. +- Mobs will drop more XP when killed. +- Mobs will drop more items when killed +- Mobs will target players from further away +- Mobs will move faster +- Custom texture pack during a bloodmoon, the default one makes the moon red. + +All of the features can be configured for each world. See the config section for more information. + +## Commands +- /bloodmoon start - Starts a bloodmoon event. +- /bloodmoon stop - Stops a current bloodmoon event. +- /bloodmoon next - Schedules a bloodmoon for the next night. + +## Permissions +- bloodmoon.admin.start - Allows the player to manually start a bloodmoon +- bloodmoon.admin.stop - Allows the player to manually stop a bloodmoon +- bloodmoon.admin.ignore-world-lock - Allows the player to leave the world even if the bloodmoon is active and the lock-in-world feature is enabled + +All of these default to OPs only. + +## Config +Information relating to the config file for this plugin can be found on the config page. + +## Potential Conflicts +Due to limitations of the Bukkit API, this plugin has to override certain methods from the Minecraft source. If any other plugin replaces the same things it will not be compatible with BloodMoon and weird stuff may happen ! You would still be able to use both plugins but you would need to disable the break-blocks option in the config file, even them some features of either plugin may not work properly. \ No newline at end of file diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml deleted file mode 100644 index a80b3b4..0000000 --- a/dependency-reduced-pom.xml +++ /dev/null @@ -1,118 +0,0 @@ - - - 4.0.0 - uk.co.jacekk.bukkit - bloodmoon - BloodMoon - 0.55 - http://dev.bukkit.org/bukkit-plugins/bloodmoon/ - - install - - - . - true - ${basedir}/src/main/resources/ - - plugin.yml - - - - ${basedir}/target - ${project.name} - - - maven-shade-plugin - 2.4.1 - - - package - - shade - - - - - ${project.name} - - - uk.co.jacekk.bukkit:baseplugin - - - - - uk.co.jacekk.bukkit.baseplugin - uk.co.jacekk.bukkit.baseplugin.v${baseplugin.package} - - - - - - maven-compiler-plugin - 3.3 - - 1.7 - 1.7 - - - - maven-jar-plugin - 2.6 - - - false - - ${project.name} - ${project.version} - ${BUILD_NUMBER} - - - - - - - - - bukkit-repo - https://hub.spigotmc.org/nexus/content/groups/public/ - - - jacekk-repo - http://bukkit.jacekk.co.uk:8000/plugin/repository/everything/ - - - - - junit - junit - 4.12 - test - - - hamcrest-core - org.hamcrest - - - - - org.bukkit - bukkit - 1.8.8-R0.1-SNAPSHOT - compile - - - org.bukkit - craftbukkit - 1.8.8-R0.1-SNAPSHOT - compile - - - - bukkit-plugins - 13 - 13 - bloodmoon - UTF-8 - - - diff --git a/lib/craftbukkit-1.8.7-R0.1-SNAPSHOT.jar b/lib/craftbukkit-1.8.7-R0.1-SNAPSHOT.jar deleted file mode 100644 index 5a6c3f6..0000000 Binary files a/lib/craftbukkit-1.8.7-R0.1-SNAPSHOT.jar and /dev/null differ diff --git a/pom.xml b/pom.xml index 9ba50f2..c10c9d1 100644 --- a/pom.xml +++ b/pom.xml @@ -1,136 +1,233 @@ 4.0.0 - uk.co.jacekk.bukkit + com.github.hexosse bloodmoon BloodMoon - 0.55 + 0.70-Hexosse jar - http://dev.bukkit.org/bukkit-plugins/bloodmoon/ + https://github.com/hexosse/bloodmoon/ + + + + + Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + + + http://github.com/hexosse/bloodmoon + scm:git:git://github.com/hexosse/bloodmoon.git + scm:git:git@github.com:hexosse/bloodmoon.git + + + + GitHub + https://github.com/hexosse/bloodmoon/issues + + + + + ${project.name} + ${project.version} + 1.10.2 + 1.10.2-R0.1-SNAPSHOT + 1.7 UTF-8 + - bukkit-plugins - bloodmoon - 13 - 13 - + + + + hexosse + hexosse + https://github.com/hexosse + + + + + - bukkit-repo + spigot-repo https://hub.spigotmc.org/nexus/content/groups/public/ - + - jacekk-repo - http://bukkit.jacekk.co.uk:8000/plugin/repository/everything/ + hexosse-repo + https://raw.github.com/hexosse/maven-repo/master/ + + true + - + - junit - junit - 4.12 - test + org.spigotmc + spigot-api + ${spigot.version} + provided - - - uk.co.jacekk.bukkit - baseplugin - 16 - compile - - + + org.bukkit bukkit - 1.8.8-R0.1-SNAPSHOT - compile - + ${spigot.version} + provided - + + org.bukkit craftbukkit - 1.8.8-R0.1-SNAPSHOT + ${spigot.version} + provided + + + + + com.github.hexosse + pluginframework + 0.5.0 compile - + + + + + 3rdParty + MassiveCore + 2.8.7 + provided + + + + 3rdParty + Factions + 2.8.7 + provided + + - install + src/main/java ${basedir}/target - ${project.name} + ${plugin.name}-${plugin.version}-${minecraft.version} + . true ${basedir}/src/main/resources/ - plugin.yml + **/* + + + + org.apache.maven.plugins - maven-shade-plugin - 2.4.1 + maven-clean-plugin + 3.0.0 + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + ${jdk.version} + ${jdk.version} + true + + + + + + org.apache.maven.plugins - maven-compiler-plugin - 3.3 - - 1.7 - 1.7 - + maven-shade-plugin + 2.4.3 + + + package + + shade + + + + + com.github.hexosse.pluginframework + com.github.hexosse.${project.artifactId}.framework + + + + true + + false + + false + + + + org.apache.maven.plugins maven-jar-plugin - 2.6 + 3.0.0 false - ${project.name} + ${plugin.name} ${project.version} - ${BUILD_NUMBER} + + diff --git a/src/main/java/com/github/hexosse/bloodmoon/BloodMoon.java b/src/main/java/com/github/hexosse/bloodmoon/BloodMoon.java new file mode 100644 index 0000000..addd02b --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/BloodMoon.java @@ -0,0 +1,358 @@ +package com.github.hexosse.bloodmoon; + +import com.github.hexosse.bloodmoon.command.BmCommands; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.bloodmoon.entity.BloodMoonEntityType; +import com.github.hexosse.bloodmoon.events.BloodMoonEndEvent; +import com.github.hexosse.bloodmoon.events.BloodMoonStartEvent; +import com.github.hexosse.bloodmoon.exceptions.EntityRegistrationException; +import com.github.hexosse.bloodmoon.feature.client.ChatMessageListener; +import com.github.hexosse.bloodmoon.feature.client.PlaySoundListener; +import com.github.hexosse.bloodmoon.feature.client.TexturePackListener; +import com.github.hexosse.bloodmoon.feature.mob.*; +import com.github.hexosse.bloodmoon.feature.player.SwordDamageListener; +import com.github.hexosse.bloodmoon.feature.server.DisabledCommandsListener; +import com.github.hexosse.bloodmoon.feature.server.ServerCommandsListener; +import com.github.hexosse.bloodmoon.feature.spawning.*; +import com.github.hexosse.bloodmoon.feature.world.*; +import com.github.hexosse.bloodmoon.integrations.Factions; +import com.github.hexosse.bloodmoon.listeners.SpawnReasonListener; +import com.github.hexosse.bloodmoon.listeners.WorldInitListener; +import com.github.hexosse.bloodmoon.tasks.TimeMonitorTask; +import com.github.hexosse.pluginframework.pluginapi.Plugin; +import com.github.hexosse.pluginframework.pluginapi.message.Message; +import net.md_5.bungee.api.ChatColor; +import org.apache.commons.lang3.Validate; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; +import org.bukkit.metadata.MetadataValue; + +import java.util.ArrayList; +import java.util.HashMap; + +import static com.github.hexosse.bloodmoon.integrations.Factions.hookFactionsPlugin; + +public final class BloodMoon extends Plugin +{ + public static BloodMoon instance = null; + + public static boolean debug = false; + + public ArrayList activeWorlds; + public HashMap worldConfig; + public ArrayList forceWorlds; + + @Override + public void onEnable() + { + /* Plugin instance */ + instance = this; + + /* */ + activeWorlds = new ArrayList<>(); + forceWorlds = new ArrayList<>(); + worldConfig = new HashMap<>(); + + /* Register entities */ + try { + BloodMoonEntityType.registerEntities(); + } catch (EntityRegistrationException e) { + e.printStackTrace();// + } + + /* Create a world config file per world */ + for (World world : getServer().getWorlds()) { + createConfig(world); + } + + /* Register commands */ + registerCommands(new BmCommands(this)); + + /* Register listeners */ + getServer().getPluginManager().registerEvents(new WorldInitListener(this), this); + getServer().getPluginManager().registerEvents(new SpawnReasonListener(this), this); + // Mob features + getServer().getPluginManager().registerEvents(new SuperCreepersListener(this), this); + getServer().getPluginManager().registerEvents(new ZombieArmorListener(this), this); + getServer().getPluginManager().registerEvents(new ZombieWeaponListener(this), this); + getServer().getPluginManager().registerEvents(new DaylightProofMobsListener(this), this); + getServer().getPluginManager().registerEvents(new FireArrowsListener(this), this); + getServer().getPluginManager().registerEvents(new MaxHealthListener(this), this); + getServer().getPluginManager().registerEvents(new MoreDropsListener(this), this); + getServer().getPluginManager().registerEvents(new MoreExpListener(this), this); + getServer().getPluginManager().registerEvents(new TargetDistanceListener(this), this); + getServer().getPluginManager().registerEvents(new MovementSpeedListener(this), this); + // World features + getServer().getPluginManager().registerEvents(new WeatherListener(this), this); + getServer().getPluginManager().registerEvents(new NetherSkyListener(this), this); + getServer().getPluginManager().registerEvents(new LockInWorldListener(this), this); + getServer().getPluginManager().registerEvents(new ExtendedNightListener(this), this); + getServer().getPluginManager().registerEvents(new DungeonListener(this), this); + // Spawning features + getServer().getPluginManager().registerEvents(new SpawnOnKillListener(this), this); + getServer().getPluginManager().registerEvents(new SpawnOnSleepListener(this), this); + getServer().getPluginManager().registerEvents(new MoreSpawningListener(this), this); + getServer().getPluginManager().registerEvents(new MoreMobsListener(this), this); + getServer().getPluginManager().registerEvents(new GiantsListener(this), this); + // Server features + getServer().getPluginManager().registerEvents(new ServerCommandsListener(this), this); + getServer().getPluginManager().registerEvents(new DisabledCommandsListener(this), this); + // Player features + getServer().getPluginManager().registerEvents(new SwordDamageListener(this), this); + // Client Features. + getServer().getPluginManager().registerEvents(new PlaySoundListener(this), this); + getServer().getPluginManager().registerEvents(new ChatMessageListener(this), this); + getServer().getPluginManager().registerEvents(new TexturePackListener(this), this); + + /* Register tasks */ + getServer().getScheduler().scheduleSyncRepeatingTask(this, new TimeMonitorTask(this), 100L, 100L); + + /* Hook faction plugin */ + hookFactionsPlugin(); + + /* Console message */ + Message message = new Message(); + message.setPrefix("§4[§c" + BloodMoon.instance.getDescription().getName() + " " + BloodMoon.instance.getDescription().getVersion() + "§4]§r"); + message.add(new Message(ChatColor.YELLOW, "Enable")); + messageManager.send(Bukkit.getConsoleSender(), message); + } + + @Override + public void onDisable() + { + super.onDisable(); + + for (World world : getServer().getWorlds()) + { + if(isActive(world)) + deactivate(world); + } + + /* Console message */ + Message message = new Message(); + message.setPrefix("§4[§c" + BloodMoon.instance.getDescription().getName() + " " + BloodMoon.instance.getDescription().getVersion() + "§4]§r"); + message.add(new Message(ChatColor.YELLOW, "Disabled")); + messageManager.send(Bukkit.getConsoleSender(), message); + } + + /** + * Starts a bloodmoon in a specific world + * + * @param world The world + */ + public boolean activate(World world) + { + Validate.notNull(world); + + if(isActive(world)) + return false; + + BloodMoonStartEvent event = new BloodMoonStartEvent(world); + + getServer().getPluginManager().callEvent(event); + + if (!event.isCancelled()) { + activeWorlds.add(world.getName()); + } + + return true; + } + + /** + * Stops an existing bloodmoon in a world + * + * @param world The world + */ + public void deactivate(World world) + { + Validate.notNull(world); + + if(isActive(world)) + { + BloodMoonEndEvent event = new BloodMoonEndEvent(world); + + getServer().getPluginManager().callEvent(event); + + if(!event.isCancelled()) + activeWorlds.remove(world.getName()); + } + } + + /** + * Checks if a bloodmoon is currently active in a world + * + * @param world The world + * @return true if a bloodmoon is active false if not + */ + public boolean isActive(World world) + { + Validate.notNull(world); + return activeWorlds.contains(world.getName()); + } + + /** + * Checks if the bloodmoon is enabled for a world + * + * @param world The world + * @return true if the bloodmoon is enabled false if not + */ + public boolean isEnabled(World world) + { + Validate.notNull(world); + + if (!worldConfig.containsKey(world.getName())) + return false; + + WorldConfig worldConfig = this.worldConfig.get(world.getName()); + + return worldConfig.ENABLED.getValue(); + } + + /** + * Starts a bloodmoon the next time night is reached in a specific world + * + * @param world The world + */ + public void forceNextNight(World world) { + Validate.notNull(world); + forceWorlds.add(world.getName()); + } + + /** + * Checks if a specific feature is enabled in a world. + * + * @param world The world + * @param feature The {@link Feature} to check + * @return true if the feature is enabled false if not + */ + /*public Boolean isFeatureEnabled(World world, Feature feature) + { + Validate.notNull(world); + + if(!worldConfig.containsKey(world.getName())) + return false; + + ConfigKey enabledConfigKey = feature.getEnabledConfigKey(); + WorldConfig worldConfig = this.worldConfig.get(world.getName()); + ConfigKey enablefeature = (ConfigKey)worldConfig.getKey(enabledConfigKey.getKey()); + return enablefeature.getValue(); + }*/ + + /** + * Sets up the config for a world. This should only be used by other plugins + * if a world is being loaded that would not call a WorldInitEvent. + * + * @param world The {@link World} being loaded + * @return The config object that was created for the world or null if it + * already existed. + */ + public WorldConfig createConfig(World world) + { + Validate.notNull(world); + + String worldName = world.getName(); + + if(!worldConfig.containsKey(worldName)) + { + WorldConfig worldConfig = new WorldConfig(this, this.getDataFolder(), worldName + ".yml"); + + this.worldConfig.put(worldName, worldConfig); + + if(worldConfig.ALWAYS_ON.getValue()) + activate(world); + + return worldConfig; + } + + return null; + } + + /** + * Gets the config for a world + * + * @param world The world + * @return the {@link WorldConfig} for this world + */ + public WorldConfig getConfig(World world) + { + Validate.notNull(world); + + if(!worldConfig.containsKey(world.getName())) + return createConfig(world); + + return worldConfig.get(world.getName()); + } + + /** + * Reloads all config files. + */ + public void reloadWorldConfig() + { + for (WorldConfig config : worldConfig.values()) { + config.load(); + } + } + + /** + * Gets the reason that an entity spawned. Note that these reasons are reset + * when the server restarts. + * + * @param entity The entity + * @return The {@link SpawnReason} + */ + public SpawnReason getSpawnReason(Entity entity) + { + for (MetadataValue value : entity.getMetadata("spawn-reason")) { + if (value.getOwningPlugin() instanceof BloodMoon) { + return (SpawnReason) value.value(); + } + } + + return SpawnReason.DEFAULT; + } + + /** + * @param type Entity to spawn + * @param location Location of spawn + * @return true if an entity can spawn at location + */ + public boolean spawnEntityAllowed(EntityType type, Location location) + { + if(Factions.getPlugin()!=null && worldConfig.get(location.getWorld().getName()).INTEGRATION_FACTIONS_PREVENT_SPAWING.getValue()) { + if(!Factions.spawnEntityAllowed(type, location)) + return false; + } + return true; + } + + public String formatMessage(String message) { + return this.formatMessage(message, true, false); + } + + public String formatMessage(String message, boolean colour) { + return this.formatMessage(message, colour, !colour); + } + + public String formatMessage(String message, boolean colour, boolean version) { + StringBuilder line = new StringBuilder(); + if(colour) { + line.append(ChatColor.BLUE); + } + + line.append("["); + line.append(this.getDescription().getName()); + if(version) { + line.append(" v"); + line.append(this.getDescription().getVersion()); + } + + line.append("] "); + line.append(ChatColor.RESET); + line.append(message); + return line.toString(); + } +} diff --git a/src/main/java/com/github/hexosse/bloodmoon/command/BmCommandHelp.java b/src/main/java/com/github/hexosse/bloodmoon/command/BmCommandHelp.java new file mode 100644 index 0000000..b89487a --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/command/BmCommandHelp.java @@ -0,0 +1,37 @@ +package com.github.hexosse.bloodmoon.command; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.Permissions; +import com.github.hexosse.pluginframework.pluginapi.command.CommandInfo; +import com.github.hexosse.pluginframework.pluginapi.command.predifined.CommandHelp; + +/** + * @author hexosse (hexosse on GitHub)) + */ +public class BmCommandHelp extends CommandHelp +{ + /** + * @param plugin The plugin that this object belong to. + */ + public BmCommandHelp(BloodMoon plugin) + { + super(plugin); + this.removeArgument("page"); + this.setPermission(""+Permissions.ADMIN_START.toString()+";"+Permissions.ADMIN_STOP.toString()); + } + + /** + * Executes the given command, returning its success + * + * @param commandInfo Info about the command + * + * @return true if a valid command, otherwise false + */ + @Override + public boolean onCommand(CommandInfo commandInfo) + { + super.onCommand(commandInfo); + + return true; + } +} diff --git a/src/main/java/com/github/hexosse/bloodmoon/command/BmCommandNext.java b/src/main/java/com/github/hexosse/bloodmoon/command/BmCommandNext.java new file mode 100644 index 0000000..86b77ab --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/command/BmCommandNext.java @@ -0,0 +1,62 @@ +package com.github.hexosse.bloodmoon.command; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.Permissions; +import com.github.hexosse.pluginframework.pluginapi.PluginCommand; +import com.github.hexosse.pluginframework.pluginapi.command.CommandArgument; +import com.github.hexosse.pluginframework.pluginapi.command.CommandInfo; +import com.github.hexosse.pluginframework.pluginapi.command.type.ArgTypeWorld; +import com.github.hexosse.pluginframework.pluginapi.message.Message; +import com.github.hexosse.pluginframework.pluginapi.message.MessageTarget; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.World; + +/** + * @author hexosse (hexosse on GitHub)) + */ +public class BmCommandNext extends PluginCommand +{ + /** + * @param plugin The plugin that this object belong to. + */ + public BmCommandNext(BloodMoon plugin) + { + super("next", plugin); + this.addArgument(new CommandArgument("world", ArgTypeWorld.get(), true, true, "World to stop the bloodmoon.")); + this.setPermission(Permissions.ADMIN_START.toString()); + } + + /** + * Executes the given command, returning its success + * + * @param commandInfo Info about the command + * + * @return true if a valid command, otherwise false + */ + @Override + public boolean onCommand(CommandInfo commandInfo) + { + // The world to start the bloodmoon + World world = plugin.getServer().getWorld(commandInfo.getNamedArg("world")); + + // Prepare the message to send + Message message = new Message(); + MessageTarget target = new MessageTarget(Bukkit.getConsoleSender()).add(commandInfo.getSender()); + + if(plugin.isEnabled(world)) + { + plugin.forceNextNight(world); + message.add(new Message(ChatColor.GREEN + "Bloodmoon forced in world " + world.getName())); + } + else + { + message.add(new Message(ChatColor.RED + "The blood moon is not enabled for the world " + world.getName())); + } + + // Send the message + messageManager.send(target, message); + + return true; + } +} diff --git a/src/main/java/com/github/hexosse/bloodmoon/command/BmCommandReload.java b/src/main/java/com/github/hexosse/bloodmoon/command/BmCommandReload.java new file mode 100644 index 0000000..298f6d9 --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/command/BmCommandReload.java @@ -0,0 +1,57 @@ +package com.github.hexosse.bloodmoon.command; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.Permissions; +import com.github.hexosse.pluginframework.pluginapi.command.CommandInfo; +import com.github.hexosse.pluginframework.pluginapi.command.predifined.CommandReload; +import com.github.hexosse.pluginframework.pluginapi.message.Message; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +/** + * @author hexosse (hexosse on GitHub)) + */ +public class BmCommandReload extends CommandReload +{ + /** + * @param plugin The plugin that this object belong to. + */ + public BmCommandReload(BloodMoon plugin) + { + super(plugin, Permissions.ADMIN_RELOAD.toString()); + } + + /** + * Executes the given command, returning its success + * + * @param commandInfo Info about the command + * + * @return true if a valid command, otherwise false + */ + @Override + public boolean onCommand(CommandInfo commandInfo) + { + final Player player = commandInfo.getPlayer(); + + super.onCommand(commandInfo); + + new BukkitRunnable() + { + @Override + public void run() + { + plugin.reloadWorldConfig(); + + // Message + Message message = new Message(); + message.setPrefix("§4[§c" + BloodMoon.instance.getDescription().getName() + " " + BloodMoon.instance.getDescription().getVersion() + "§4]§r"); + message.add(ChatColor.GREEN + "WorldConfig reloaded for all worlds."); + messageManager.send(player, message); + } + + }.runTask(plugin); + + return true; + } +} diff --git a/src/main/java/com/github/hexosse/bloodmoon/command/BmCommandStart.java b/src/main/java/com/github/hexosse/bloodmoon/command/BmCommandStart.java new file mode 100644 index 0000000..c44f5b4 --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/command/BmCommandStart.java @@ -0,0 +1,62 @@ +package com.github.hexosse.bloodmoon.command; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.Permissions; +import com.github.hexosse.pluginframework.pluginapi.PluginCommand; +import com.github.hexosse.pluginframework.pluginapi.command.CommandArgument; +import com.github.hexosse.pluginframework.pluginapi.command.CommandInfo; +import com.github.hexosse.pluginframework.pluginapi.command.type.ArgTypeWorld; +import com.github.hexosse.pluginframework.pluginapi.message.Message; +import com.github.hexosse.pluginframework.pluginapi.message.MessageTarget; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.World; + +/** + * @author hexosse (hexosse on GitHub)) + */ +public class BmCommandStart extends PluginCommand +{ + /** + * @param plugin The plugin that this object belong to. + */ + public BmCommandStart(BloodMoon plugin) + { + super("start", plugin); + this.addArgument(new CommandArgument("world", ArgTypeWorld.get(), true, true, "World to start the bloodmoon.")); + this.setPermission(Permissions.ADMIN_START.toString()); + } + + /** + * Executes the given command, returning its success + * + * @param commandInfo Info about the command + * + * @return true if a valid command, otherwise false + */ + @Override + public boolean onCommand(CommandInfo commandInfo) + { + // The world to start the bloodmoon + World world = plugin.getServer().getWorld(commandInfo.getNamedArg("world")); + + // Prepare the message to send + Message message = new Message(); + MessageTarget target = new MessageTarget(Bukkit.getConsoleSender()).add(commandInfo.getSender()); + + if(plugin.isEnabled(world)) + { + plugin.activate(world); + message.add(new Message(ChatColor.GREEN + "Bloodmoon started in world " + world.getName())); + } + else + { + message.add(new Message(ChatColor.RED + "The blood moon is not enabled for the world " + world.getName())); + } + + // Send the message + messageManager.send(target, message); + + return true; + } +} diff --git a/src/main/java/com/github/hexosse/bloodmoon/command/BmCommandStop.java b/src/main/java/com/github/hexosse/bloodmoon/command/BmCommandStop.java new file mode 100644 index 0000000..28e4ed6 --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/command/BmCommandStop.java @@ -0,0 +1,62 @@ +package com.github.hexosse.bloodmoon.command; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.Permissions; +import com.github.hexosse.pluginframework.pluginapi.PluginCommand; +import com.github.hexosse.pluginframework.pluginapi.command.CommandArgument; +import com.github.hexosse.pluginframework.pluginapi.command.CommandInfo; +import com.github.hexosse.pluginframework.pluginapi.command.type.ArgTypeWorld; +import com.github.hexosse.pluginframework.pluginapi.message.Message; +import com.github.hexosse.pluginframework.pluginapi.message.MessageTarget; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.World; + +/** + * @author hexosse (hexosse on GitHub)) + */ +public class BmCommandStop extends PluginCommand +{ + /** + * @param plugin The plugin that this object belong to. + */ + public BmCommandStop(BloodMoon plugin) + { + super("stop", plugin); + this.addArgument(new CommandArgument("world", ArgTypeWorld.get(), true, true, "World to stop the bloodmoon.")); + this.setPermission(Permissions.ADMIN_STOP.toString()); + } + + /** + * Executes the given command, returning its success + * + * @param commandInfo Info about the command + * + * @return true if a valid command, otherwise false + */ + @Override + public boolean onCommand(CommandInfo commandInfo) + { + // The world to start the bloodmoon + World world = plugin.getServer().getWorld(commandInfo.getNamedArg("world")); + + // Prepare the message to send + Message message = new Message(); + MessageTarget target = new MessageTarget(Bukkit.getConsoleSender()).add(commandInfo.getSender()); + + if(plugin.isEnabled(world)) + { + plugin.deactivate(world); + message.add(new Message(ChatColor.GREEN + "Bloodmoon stopped in world " + world.getName())); + } + else + { + message.add(new Message(ChatColor.RED + "The blood moon is not enabled for the world " + world.getName())); + } + + // Send the message + messageManager.send(target, message); + + return true; + } +} diff --git a/src/main/java/com/github/hexosse/bloodmoon/command/BmCommands.java b/src/main/java/com/github/hexosse/bloodmoon/command/BmCommands.java new file mode 100644 index 0000000..144fbab --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/command/BmCommands.java @@ -0,0 +1,51 @@ +package com.github.hexosse.bloodmoon.command; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.pluginframework.pluginapi.PluginCommand; +import com.github.hexosse.pluginframework.pluginapi.command.CommandInfo; +import com.google.common.collect.Lists; + +/** + * @author hexosse (hexosse on GitHub)) + */ +public class BmCommands extends PluginCommand +{ + /** + * @param plugin The plugin that this object belong to. + */ + public BmCommands(BloodMoon plugin) + { + super("bloodmoon", plugin); + this.setAliases(Lists.newArrayList("bm")); + + this.addSubCommand(new BmCommandHelp(plugin)); + this.addSubCommand(new BmCommandStart(plugin)); + this.addSubCommand(new BmCommandStop(plugin)); + this.addSubCommand(new BmCommandNext(plugin)); + this.addSubCommand(new BmCommandReload(plugin)); + + /* + this.specifyWorld = plugin.formatMessage(ChatColor.RED + "You must specify a world when using the command from the console"); + this.invalidArgs = plugin.formatMessage(ChatColor.RED + "Invalid argument length"); + this.noPerm = plugin.formatMessage(ChatColor.RED + "You do not have permission use this command"); + this.noPermStart = plugin.formatMessage(ChatColor.RED + "You do not have permission to start a bloodmoon"); + this.noPermStop = plugin.formatMessage(ChatColor.RED + "You do not have permission to stop a bloodmoon"); + this.notEnabledWorld = plugin.formatMessage(ChatColor.RED + "The blood moon is not enabled for this world"); + */ + } + + /** + * Executes the given command, returning its success + * + * @param commandInfo Info about the command + * + * @return true if a valid command, otherwise false + */ + @Override + public boolean onCommand(CommandInfo commandInfo) + { + plugin.getServer().dispatchCommand(commandInfo.getSender(), "bloodmoon help"); + + return true; + } +} diff --git a/src/main/java/com/github/hexosse/bloodmoon/configuration/Permissions.java b/src/main/java/com/github/hexosse/bloodmoon/configuration/Permissions.java new file mode 100644 index 0000000..08d4d3f --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/configuration/Permissions.java @@ -0,0 +1,38 @@ +package com.github.hexosse.bloodmoon.configuration; + +import org.bukkit.command.CommandSender; + +public enum Permissions +{ + ADMIN_START("bloodmoon.admin.start") + ,ADMIN_STOP("bloodmoon.admin.stop") + ,ADMIN_RELOAD("bloodmoon.admin.reload") + ,ADMIN_IGNORE_WORLD_LOCK("bloodmoon.admin.ignore-world-lock"); + + private final String permission; + + // Constructeur + Permissions(String permission) + { + this.permission = permission; + } + + // Test si le sender à la permission + public static boolean has(CommandSender sender, Permissions permission) + { + return has(sender, permission.permission); + } + + // Test si le sender à la permission + public static boolean has(CommandSender sender, String node) + { + return sender.hasPermission(node) || sender.hasPermission(node.toLowerCase()); + } + + // Permissions to string + public String toString() + { + return permission; + } + +} diff --git a/src/main/java/com/github/hexosse/bloodmoon/configuration/WorldConfig.java b/src/main/java/com/github/hexosse/bloodmoon/configuration/WorldConfig.java new file mode 100644 index 0000000..5b01db8 --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/configuration/WorldConfig.java @@ -0,0 +1,151 @@ +package com.github.hexosse.bloodmoon.configuration; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.pluginframework.pluginapi.config.ConfigKey; +import com.github.hexosse.pluginframework.pluginapi.config.ConfigKeyFile; +import org.bukkit.Material; +import org.bukkit.block.Biome; +import org.bukkit.entity.EntityType; + +import java.io.File; +import java.util.Arrays; +import java.util.List; + +public class WorldConfig extends ConfigKeyFile +{ + public final ConfigKey ENABLED = new ConfigKey("enabled", false); + public final ConfigKey ALWAYS_ON = new ConfigKey("always-on", false); + public final ConfigKey CHANCE = new ConfigKey("chance", 14); + + public final ConfigKey FEATURE_CHAT_MESSAGE_ENABLED = new ConfigKey("features.chat-message.enabled", true); + public final ConfigKey FEATURE_CHAT_MESSAGE_START_MESSAGE = new ConfigKey("features.chat-message.start-message", "&cThe bloodmoon is rising !"); + public final ConfigKey FEATURE_CHAT_MESSAGE_END_MESSAGE = new ConfigKey("features.chat-message.end-message", "&cThe bloodmoon is over !"); + + public final ConfigKey FEATURE_SERVER_COMMANDS_ENABLED = new ConfigKey("features.server-commands.enabled", false); + public final ConfigKey> FEATURE_SERVER_COMMANDS_START_COMMANDS = new ConfigKey("features.server-commands.commands.start", Arrays.asList("toggledownfall", "time set 0", "op Notch")); + public final ConfigKey> FEATURE_SERVER_COMMANDS_END_COMMANDS = new ConfigKey("features.server-commands.commands.end", Arrays.asList("toggledownfall", "time set 12000", "deop Notch")); + + public final ConfigKey FEATURE_DISABLED_COMMANDS_ENABLED = new ConfigKey("features.disabled-commands.enabled", true); + public final ConfigKey> FEATURE_DISABLED_COMMANDS_COMMANDS = new ConfigKey("features.disabled-commands.commands", Arrays.asList("spawn", "home", "f home")); + + public final ConfigKey FEATURE_PLAY_SOUND_ENABLED = new ConfigKey("features.play-sound.enabled", true); + public final ConfigKey FEATURE_PLAY_SOUND_SOUND = new ConfigKey("features.play-sound.sound", "ENTITY_WITHER_SPAWN"); + public final ConfigKey FEATURE_PLAY_SOUND_PITCH = new ConfigKey("features.play-sound.pitch", 1.0f); + public final ConfigKey FEATURE_PLAY_SOUND_VOLUME = new ConfigKey("features.play-sound.volume", 1.0f); + + public final ConfigKey FEATURE_ARROW_RATE_ENABLED = new ConfigKey("features.arrow-rate.enabled", true); + public final ConfigKey FEATURE_ARROW_RATE_MULTIPLIER = new ConfigKey("features.arrow-rate.multiplier", 2); + + public final ConfigKey FEATURE_FIRE_ARROWS_ENABLED = new ConfigKey("features.fire-arrows.enabled", true); + public final ConfigKey FEATURE_FIRE_ARROWS_CHANCE = new ConfigKey("features.fire-arrows.chance", 100); + public final ConfigKey FEATURE_FIRE_ARROWS_IGNITE_TARGET = new ConfigKey("features.fire-arrows.ignite-target", true); + + public final ConfigKey FEATURE_ZOMBIE_WEAPON_ENABLED = new ConfigKey("features.zombie-weapon.enabled", true); + public final ConfigKey FEATURE_ZOMBIE_WEAPON_CHANCE = new ConfigKey("features.zombie-weapon.chance", 60); + public final ConfigKey FEATURE_ZOMBIE_WEAPON_DROP_CHANCE = new ConfigKey("features.zombie-weapon.drop-chance", 25.0f); + public final ConfigKey FEATURE_ZOMBIE_WEAPON_IGNORE_SPAWNERS = new ConfigKey("features.zombie-weapon.ignore-spawners", true); + public final ConfigKey> FEATURE_ZOMBIE_WEAPON_WEAPONS = new ConfigKey("features.zombie-weapon.weapons", Arrays.asList("DIAMOND_SWORD", "GOLD_SWORD", "IRON_SWORD")); + + public final ConfigKey FEATURE_ZOMBIE_ARMOR_ENABLED = new ConfigKey("features.zombie-armor.enabled", true); + public final ConfigKey FEATURE_ZOMBIE_ARMOR_CHANCE = new ConfigKey("features.zombie-armor.chance", 60); + public final ConfigKey FEATURE_ZOMBIE_ARMOR_DROP_CHANCE = new ConfigKey("features.zombie-armor.drop-chance", 7); + public final ConfigKey FEATURE_ZOMBIE_ARMOR_IGNORE_SPAWNERS = new ConfigKey("features.zombie-armor.ignore-spawners", true); + public final ConfigKey> FEATURE_ZOMBIE_ARMOR_ARMOR = new ConfigKey("features.zombie-armor.armor", Arrays.asList("DIAMOND", "GOLD", "IRON")); + + public final ConfigKey FEATURE_TARGET_DISTANCE_ENABLED = new ConfigKey("features.target-distance.enabled", true); + public final ConfigKey FEATURE_TARGET_DISTANCE_MULTIPLIER = new ConfigKey("features.target-distance.multiplier", 2.0d); + public final ConfigKey> FEATURE_TARGET_DISTANCE_MOBS = new ConfigKey("features.target-distance.mobs", Arrays.asList("ZOMBIE", "SKELETON", "SPIDER", "CREEPER")); + + public final ConfigKey FEATURE_MOVEMENT_SPEED_ENABLED = new ConfigKey("features.movement-speed.enabled", true); + public final ConfigKey FEATURE_MOVEMENT_SPEED_MULTIPLIER = new ConfigKey("features.movement-speed.multiplier", 1.20d); + public final ConfigKey FEATURE_MOVEMENT_SPEED_FAST_CHANCE = new ConfigKey("features.movement-speed.fast-chance", 15); + public final ConfigKey FEATURE_MOVEMENT_SPEED_FAST_MULTIPLIER = new ConfigKey("features.movement-speed.fast-multiplier", 1.3d); + public final ConfigKey> FEATURE_MOVEMENT_SPEED_MOBS = new ConfigKey("features.movement-speed.mobs", Arrays.asList("ZOMBIE", "SKELETON", "CREEPER")); + + public final ConfigKey FEATURE_BREAK_BLOCKS_ENABLED = new ConfigKey("features.break-blocks.enabled", true); + public final ConfigKey FEATURE_BREAK_BLOCKS_DROP_ITEMS = new ConfigKey("features.break-blocks.drop-items", true); + public final ConfigKey FEATURE_BREAK_BLOCKS_REALISTIC_DROP = new ConfigKey("features.break-blocks.realistic-drop", true); + public final ConfigKey> FEATURE_BREAK_BLOCKS_MOBS = new ConfigKey("features.break-blocks.mobs", Arrays.asList("ZOMBIE", "SKELETON", "SPIDER", "CREEPER", "ENDERMAN")); + public final ConfigKey> FEATURE_BREAK_BLOCKS_BLOCKS = new ConfigKey("features.break-blocks.blocks", Arrays.asList("WOOD", "LOG", "GLASS")); + + public final ConfigKey FEATURE_MAX_HEALTH_ENABLED = new ConfigKey("features.max-health.enabled", true); + public final ConfigKey FEATURE_MAX_HEALTH_MULTIPLIER = new ConfigKey("features.max-health.multiplier", 2.0d); + public final ConfigKey> FEATURE_MAX_HEALTH_MOBS = new ConfigKey("features.max-health.mobs", Arrays.asList("ZOMBIE", "SKELETON", "SPIDER", "CREEPER", "ENDERMAN")); + + public final ConfigKey FEATURE_MORE_SPAWNING_ENABLED = new ConfigKey("features.more-spawning.enabled", true); + public final ConfigKey FEATURE_MORE_SPAWNING_MULTIPLIER = new ConfigKey("features.more-spawning.multiplier", 2); + public final ConfigKey> FEATURE_MORE_SPAWNING_MOBS = new ConfigKey("features.more-spawning.mobs", Arrays.asList("ZOMBIE", "SKELETON", "SPIDER", "CREEPER", "ENDERMAN")); + + public final ConfigKey FEATURE_MORE_EXP_ENABLED = new ConfigKey("features.more-exp.enabled", true); + public final ConfigKey FEATURE_MORE_EXP_IGNORE_SPAWNERS = new ConfigKey("features.more-exp.ignore-spawners", false); + public final ConfigKey FEATURE_MORE_EXP_MULTIPLIER = new ConfigKey("features.more-exp.multiplier", 2); + + public final ConfigKey FEATURE_MORE_DROPS_ENABLED = new ConfigKey("features.more-drops.enabled", true); + public final ConfigKey FEATURE_MORE_DROPS_IGNORE_SPAWNERS = new ConfigKey("features.more-drops.ignore-spawners", false); + public final ConfigKey FEATURE_MORE_DROPS_MULTIPLIER = new ConfigKey("features.more-drops.multiplier", 2); + + public final ConfigKey FEATURE_SWORD_DAMAGE_ENABLED = new ConfigKey("features.sword-damage.enabled", true); + public final ConfigKey> FEATURE_SWORD_DAMAGE_MOBS = new ConfigKey("features.sword-damage.mobs", Arrays.asList("ZOMBIE", "SKELETON", "SPIDER", "CREEPER", "ENDERMAN")); + public final ConfigKey FEATURE_SWORD_DAMAGE_CHANCE = new ConfigKey("features.sword-damage.chance", 10); + + public final ConfigKey FEATURE_SUPER_CREEPERS_ENABLED = new ConfigKey("features.super-creepers.enabled", true); + public final ConfigKey FEATURE_SUPER_CREEPERS_POWER = new ConfigKey("features.super-creepers.power", 4.0f); + public final ConfigKey FEATURE_SUPER_CREEPERS_FIRE = new ConfigKey("features.super-creepers.fire", true); + public final ConfigKey FEATURE_SUPER_CREEPERS_LIGHTNING = new ConfigKey("features.super-creepers.lightning", true); + + public final ConfigKey FEATURE_SPAWN_ON_KILL_ENABLED = new ConfigKey("features.spawn-on-kill.enabled", true); + public final ConfigKey> FEATURE_SPAWN_ON_KILL_MOBS = new ConfigKey("features.spawn-on-kill.mobs", Arrays.asList("ZOMBIE", "SKELETON", "SPIDER", "CREEPER", "ENDERMAN")); + public final ConfigKey FEATURE_SPAWN_ON_KILL_CHANCE = new ConfigKey("features.spawn-on-kill.chance", 10); + public final ConfigKey> FEATURE_SPAWN_ON_KILL_SPAWN = new ConfigKey("features.spawn-on-kill.spawn", Arrays.asList("ZOMBIE", "SKELETON", "SPIDER", "CREEPER", "ENDERMAN")); + + public final ConfigKey FEATURE_SPAWN_ON_SLEEP_ENABLED = new ConfigKey("features.spawn-on-sleep.enabled", true); + public final ConfigKey> FEATURE_SPAWN_ON_SLEEP_SPAWN = new ConfigKey("features.spawn-on-sleep.spawn", Arrays.asList("ZOMBIE")); + + public final ConfigKey FEATURE_SPAWN_CONTROL_ENABLED = new ConfigKey("features.spawn-control.enabled", true); + public final ConfigKey> FEATURE_SPAWN_CONTROL_SPAWN = new ConfigKey("features.spawn-control.spawn", Arrays.asList("ZOMBIE", "SKELETON", "SPIDER", "CREEPER", "ENDERMAN", "PIG_ZOMBIE", "BLAZE", "MAGMA_CUBE")); + + public final ConfigKey FEATURE_LOCK_IN_WORLD_ENABLED = new ConfigKey("features.lock-in-world.enabled", false); + + public final ConfigKey FEATURE_TEXTURE_PACK_ENABLED = new ConfigKey("features.texture-pack.enabled", false); + public final ConfigKey FEATURE_TEXTURE_PACK_NORMAL = new ConfigKey("features.texture-pack.normal", "https://raw.githubusercontent.com/hexosse/bloodmoon/master/src/main/texture_pack/normal.zip"); + public final ConfigKey FEATURE_TEXTURE_PACK_BLOODMOON = new ConfigKey("features.texture-pack.bloodmoon", "http://raw.githubusercontent.com/hexosse/bloodmoon/master/src/main/texture_pack/bloodmoon.zip"); + + public final ConfigKey FEATURE_EXTENDED_NIGHT_ENABLED = new ConfigKey("features.extended-night.enabled", true); + public final ConfigKey FEATURE_EXTENDED_NIGHT_MIN_KILLS = new ConfigKey("features.extended-night.min-kills", 16); + + public final ConfigKey FEATURE_WEATHER_ENABLED = new ConfigKey("features.weather.enabled", true); + public final ConfigKey FEATURE_WEATHER_THUNDER = new ConfigKey("features.weather.thunder", true); + public final ConfigKey FEATURE_WEATHER_RAIN = new ConfigKey("features.weather.rain", true); + public final ConfigKey FEATURE_WEATHER_CHANCE = new ConfigKey("features.weather.chance", 50); + + public final ConfigKey FEATURE_DAYLIGHT_PROOF_MOBS_ENABLED = new ConfigKey("features.daylight-proof-mobs.enabled", true); + + public final ConfigKey FEATURE_NETHER_SKY_ENABLED = new ConfigKey("features.nether-sky.enabled", false); + + public final ConfigKey FEATURE_DUNGEONS_ENABLED = new ConfigKey("features.dungeons.enabled", true); + public final ConfigKey FEATURE_DUNGEONS_PROTECTED = new ConfigKey("features.dungeons.protected", true); + public final ConfigKey> FEATURE_DUNGEONS_BIOMES = new ConfigKey("features.dungeons.biomes", Arrays.asList(Biome.PLAINS.name(), Biome.ICE_FLATS.name(), Biome.DESERT.name(), Biome.SWAMPLAND.name())); + public final ConfigKey FEATURE_DUNGEONS_CHANCE = new ConfigKey("features.dungeons.chance", 10); + public final ConfigKey FEATURE_DUNGEONS_MIN_LAYERS = new ConfigKey("features.dungeons.min-layers", 3); + public final ConfigKey FEATURE_DUNGEONS_MAX_LAYERS = new ConfigKey("features.dungeons.max-layers", 5); + public final ConfigKey> FEATURE_DUNGEONS_SPAWNER_TYPES = new ConfigKey("features.dungeons.spawner-types", Arrays.asList(EntityType.ZOMBIE.name(), EntityType.SKELETON.name())); + public final ConfigKey FEATURE_DUNGEONS_SPAWNER_DELAY = new ConfigKey("features.dungeons.spawner-delay", 100); + public final ConfigKey FEATURE_DUNGEONS_SPAWNER_COUNT = new ConfigKey("features.dungeons.spawner-count", 6); + public final ConfigKey FEATURE_DUNGEONS_SPAWNER_MAX_MOBS = new ConfigKey("features.dungeons.spawner-max-mobs", 8); + public final ConfigKey> FEATURE_DUNGEONS_CHEST_ITEMS = new ConfigKey("features.dungeons.chest-items", Arrays.asList(Material.BREAD.name(), Material.APPLE.name(), Material.PORK.name(), Material.SADDLE.name(), Material.BUCKET.name(), Material.STRING.name(), Material.REDSTONE.name(), Material.SULPHUR.name(), Material.COCOA.name())); + public final ConfigKey FEATURE_DUNGEONS_MIN_STACK_SIZE = new ConfigKey("features.dungeons.min-stack-size", 1); + public final ConfigKey FEATURE_DUNGEONS_MAX_STACK_SIZE = new ConfigKey("features.dungeons.max-stack-size", 8); + public final ConfigKey FEATURE_DUNGEONS_ITEMS_PER_CHEST = new ConfigKey("features.dungeons.items-per-chest", 12); + + public final ConfigKey FEATURE_GIANTS_ENABLED = new ConfigKey("features.giants.enabled", true); + public final ConfigKey> FEATURE_GIANTS_BREAK_BLOCKS = new ConfigKey("features.giants.break-blocks", Arrays.asList(Material.GRASS.name(), Material.LEAVES.name(), Material.WOOD.name(), Material.GLASS.name(), Material.CROPS.name(), Material.SOIL.name(), Material.LOG.name(), Material.WOOD_STEP.name(), Material.WOOD_STAIRS.name())); + + public final ConfigKey INTEGRATION_FACTIONS_PREVENT_SPAWING = new ConfigKey("features.integration.factions.prevent-spawing", true); + + + public WorldConfig(BloodMoon plugin, File dataFolder, String filename) + { + super(plugin, new File(dataFolder, filename)); + load(); + } +} diff --git a/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityBlaze.java b/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityBlaze.java new file mode 100644 index 0000000..e0aeea9 --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityBlaze.java @@ -0,0 +1,40 @@ +package com.github.hexosse.bloodmoon.entity; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import net.minecraft.server.v1_10_R1.EntityHuman; +import net.minecraft.server.v1_10_R1.EntityMonster; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; + +public class BloodMoonEntityBlaze extends BloodMoonEntityMonster +{ + + public BloodMoonEntityBlaze(BloodMoon plugin, EntityMonster nmsEntity, BloodMoonEntityType type) + { + super(plugin, nmsEntity, type); + } + + @Override + public void onTick() + { + World world = getBukkitWorld(); + String entityName = getEntityType().name().toUpperCase(); + WorldConfig worldConfig = plugin.getConfig(world); + + if(nmsEntity.getGoalTarget() instanceof EntityHuman && plugin.isActive(world) && worldConfig.FEATURE_BREAK_BLOCKS_ENABLED.getValue() && worldConfig.FEATURE_BREAK_BLOCKS_MOBS.getValue().contains(entityName) && nmsEntity.world.getTime() % 20 == 0 && nmsEntity.world.worldData.getName().equals(nmsEntity.getGoalTarget().world.worldData.getName())) + { + Block[] blocks = new Block[2]; + + blocks[0] = this.getBreakableTargetBlock(); + blocks[1] = blocks[0].getRelative(BlockFace.DOWN); + + for(Block block : blocks) + { + this.attemptBreakBlock(worldConfig, block); + } + } + } + +} diff --git a/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityCreeper.java b/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityCreeper.java new file mode 100644 index 0000000..ffd4af6 --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityCreeper.java @@ -0,0 +1,35 @@ +package com.github.hexosse.bloodmoon.entity; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import net.minecraft.server.v1_10_R1.EntityHuman; +import net.minecraft.server.v1_10_R1.EntityMonster; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; + +public class BloodMoonEntityCreeper extends BloodMoonEntityMonster { + + public BloodMoonEntityCreeper(BloodMoon plugin, EntityMonster nmsEntity, BloodMoonEntityType type) { + super(plugin, nmsEntity, type); + } + + @Override + public void onTick() { + World world = getBukkitWorld(); + String entityName = getEntityType().name().toUpperCase(); + WorldConfig worldConfig = plugin.getConfig(world); + + if (nmsEntity.getGoalTarget() instanceof EntityHuman && plugin.isActive(world) && worldConfig.FEATURE_BREAK_BLOCKS_ENABLED.getValue() && worldConfig.FEATURE_BREAK_BLOCKS_MOBS.getValue().contains(entityName) && nmsEntity.world.getTime() % 20 == 0 && nmsEntity.world.worldData.getName().equals(nmsEntity.getGoalTarget().world.worldData.getName())) { + Block[] blocks = new Block[2]; + + blocks[0] = this.getBreakableTargetBlock(); + blocks[1] = blocks[0].getRelative(BlockFace.DOWN); + + for (Block block : blocks) { + this.attemptBreakBlock(worldConfig, block); + } + } + } + +} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityEndermen.java b/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityEndermen.java similarity index 51% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityEndermen.java rename to src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityEndermen.java index 302200b..afd485d 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityEndermen.java +++ b/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityEndermen.java @@ -1,13 +1,12 @@ -package uk.co.jacekk.bukkit.bloodmoon.entity; +package com.github.hexosse.bloodmoon.entity; -import net.minecraft.server.v1_8_R3.EntityHuman; -import net.minecraft.server.v1_8_R3.EntityMonster; +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import net.minecraft.server.v1_10_R1.EntityHuman; +import net.minecraft.server.v1_10_R1.EntityMonster; +import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; public class BloodMoonEntityEndermen extends BloodMoonEntityMonster { @@ -17,11 +16,11 @@ public BloodMoonEntityEndermen(BloodMoon plugin, EntityMonster nmsEntity, BloodM @Override public void onTick() { - String worldName = getWorldName(); + World world = getBukkitWorld(); String entityName = getEntityType().name().toUpperCase(); - PluginConfig worldConfig = plugin.getConfig(worldName); + WorldConfig worldConfig = plugin.getConfig(world); - if (nmsEntity.getGoalTarget() instanceof EntityHuman && plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.BREAK_BLOCKS) && worldConfig.getStringList(Config.FEATURE_BREAK_BLOCKS_MOBS).contains(entityName) && nmsEntity.world.getTime() % 20 == 0 && nmsEntity.world.worldData.getName().equals(nmsEntity.getGoalTarget().world.worldData.getName())) { + if (nmsEntity.getGoalTarget() instanceof EntityHuman && plugin.isActive(world) && worldConfig.FEATURE_BREAK_BLOCKS_ENABLED.getValue() && worldConfig.FEATURE_BREAK_BLOCKS_MOBS.getValue().contains(entityName) && nmsEntity.world.getTime() % 20 == 0 && nmsEntity.world.worldData.getName().equals(nmsEntity.getGoalTarget().world.worldData.getName())) { Block[] blocks = new Block[3]; blocks[0] = this.getBreakableTargetBlock(); diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityGhast.java b/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityGhast.java similarity index 60% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityGhast.java rename to src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityGhast.java index 9202480..0e8150c 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityGhast.java +++ b/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityGhast.java @@ -1,8 +1,7 @@ -package uk.co.jacekk.bukkit.bloodmoon.entity; +package com.github.hexosse.bloodmoon.entity; -import net.minecraft.server.v1_8_R3.EntityLiving; - -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.BloodMoon; +import net.minecraft.server.v1_10_R1.EntityLiving; public class BloodMoonEntityGhast extends BloodMoonEntityLiving { diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityGiantZombie.java b/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityGiantZombie.java similarity index 58% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityGiantZombie.java rename to src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityGiantZombie.java index ac0767d..a779d38 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityGiantZombie.java +++ b/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityGiantZombie.java @@ -1,16 +1,13 @@ -package uk.co.jacekk.bukkit.bloodmoon.entity; - -import net.minecraft.server.v1_8_R3.EntityMonster; +package com.github.hexosse.bloodmoon.entity; +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import net.minecraft.server.v1_10_R1.EntityMonster; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.World; import org.bukkit.block.Block; -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; - public class BloodMoonEntityGiantZombie extends BloodMoonEntityMonster { public BloodMoonEntityGiantZombie(BloodMoon plugin, EntityMonster nmsEntity, BloodMoonEntityType type) { @@ -21,12 +18,12 @@ public BloodMoonEntityGiantZombie(BloodMoon plugin, EntityMonster nmsEntity, Blo public void onTick() { if (this.nmsEntity.locX != this.nmsEntity.lastX || this.nmsEntity.locZ != this.nmsEntity.lastZ) { World world = this.getBukkitWorld(); - PluginConfig worldConfig = plugin.getConfig(world.getName()); + WorldConfig worldConfig = plugin.getConfig(world); Block block = world.getBlockAt((int) this.nmsEntity.locX, (int) this.nmsEntity.locY - 1, (int) this.nmsEntity.locZ); - if (worldConfig.getStringList(Config.FEATURE_GIANTS_BREAK_BLOCKS).contains(block.getType().name())) { + if (worldConfig.FEATURE_GIANTS_BREAK_BLOCKS.getValue().contains(block.getType().name())) { block.setType(Material.AIR); - world.playSound(this.getLocation(), Sound.ZOMBIE_WOODBREAK, 1.0f, 1.0f); + world.playSound(this.getLocation(), Sound.ENTITY_ZOMBIE_BREAK_DOOR_WOOD, 1.0f, 1.0f); } } } diff --git a/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityLiving.java b/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityLiving.java new file mode 100644 index 0000000..9c7ae84 --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityLiving.java @@ -0,0 +1,150 @@ +package com.github.hexosse.bloodmoon.entity; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.pluginframework.pluginapi.reflexion.Reflexion; +import net.minecraft.server.v1_10_R1.AttributeInstance; +import net.minecraft.server.v1_10_R1.AttributeModifier; +import net.minecraft.server.v1_10_R1.EntityLiving; +import net.minecraft.server.v1_10_R1.GenericAttributes; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; + +import java.util.Random; +import java.util.UUID; + +public abstract class BloodMoonEntityLiving +{ + + private static final UUID maxHealthUID = UUID.fromString("f8b0a945-2d6a-4bdb-9a6f-59c285bf1e5d"); + private static final UUID followRangeUID = UUID.fromString("1737400d-3c18-41ba-8314-49a158481e1e"); + private static final UUID knockbackResistanceUID = UUID.fromString("8742c557-fcd5-4079-a462-b58db99b0f2c"); + private static final UUID movementSpeedUID = UUID.fromString("206a89dc-ae78-4c4d-b42c-3b31db3f5a7c"); + private static final UUID attackDamageUID = UUID.fromString("7bbe3bb1-079d-4150-ac6f-669e71550776"); + + protected BloodMoon plugin; + protected EntityLiving nmsEntity; + protected Entity bukkitEntity; + protected BloodMoonEntityType type; + + protected Random rand = new Random(); + + + public BloodMoonEntityLiving(BloodMoon plugin, EntityLiving nmsEntity, BloodMoonEntityType type) + { + this.plugin = plugin; + this.nmsEntity = nmsEntity; + this.bukkitEntity = nmsEntity.getBukkitEntity(); + this.type = type; + } + + public static BloodMoonEntityLiving getBloodMoonEntity(EntityLiving nmsEntity) + { + try + { + return Reflexion.getField(nmsEntity.getClass(), "bloodMoonEntity", BloodMoonEntityLiving.class, nmsEntity); + } + catch(Exception e) + { + throw new IllegalArgumentException(nmsEntity.getClass().getName() + " not supported"); + } + } + + public void setFollowRangeMultiplier(double multiplier) + { + AttributeInstance attributes = this.nmsEntity.getAttributeInstance(GenericAttributes.FOLLOW_RANGE); + AttributeModifier modifier = new AttributeModifier(followRangeUID, "BloodMoon follow range multiplier", multiplier, 1); + + attributes.c(modifier); + attributes.b(modifier); + } + + public void clearFollowRangeMultiplier() + { + AttributeInstance attributes = this.nmsEntity.getAttributeInstance(GenericAttributes.FOLLOW_RANGE); + AttributeModifier modifier = new AttributeModifier(followRangeUID, "BloodMoon follow range multiplier", 1.0d, 1); + + attributes.c(modifier); + } + + public void setKnockbackResistanceMultiplier(double multiplier) + { + AttributeInstance attributes = this.nmsEntity.getAttributeInstance(GenericAttributes.c); + //AttributeModifier modifier = new AttributeModifier(knockbackResistanceUID, "BloodMoon knockback resistance multiplier", multiplier, 1); + + //attributes.c(modifier); + //attributes.b(modifier); + } + + public void clearKnockbackResistanceMultiplier() + { + AttributeInstance attributes = this.nmsEntity.getAttributeInstance(GenericAttributes.c); + //AttributeModifier modifier = new AttributeModifier(knockbackResistanceUID, "BloodMoon knockback resistance multiplier", , 1); + attributes.setValue(1.0d); + //attributes.c(modifier); + } + + public void setSpeedMultiplier(double multiplier) + { + try + { + AttributeInstance theAttribute = this.nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED); + if(theAttribute == null) + { + System.err.println("That was null, wierd"); + return; + } + double oldValue = theAttribute.getValue(); + theAttribute.setValue(oldValue * multiplier); + if(BloodMoon.debug) + { + System.err.println("Set speed attribute for mob " + this.nmsEntity.getName() + " was " + oldValue + " and is now " + theAttribute.getValue()); + } + } + catch(NullPointerException e) + { + System.err.println("Null Exception"); + } + + //AttributeInstance attributes = this.nmsEntity.getAttributeInstance(GenericAttributes.d); + //AttributeModifier modifier = new AttributeModifier(movementSpeedUID, "BloodMoon movement speed multiplier", multiplier, 1); + //attributes.c(modifier); + //attributes.b(modifier); + } + + public void clearSpeedMultiplier() + { + AttributeInstance attributes = this.nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED); + AttributeModifier modifier = new AttributeModifier(movementSpeedUID, "BloodMoon movement speed multiplier", 1.0d, 1); + + attributes.c(modifier); + } + + //public abstract void onTick(); + public void onTick() + { + + } + + public World getBukkitWorld() + { + return nmsEntity.getWorld().getWorld(); + } + + public String getWorldName() + { + return nmsEntity.getWorld().getWorld().getName(); + } + + public Location getLocation() + { + return bukkitEntity.getLocation(); + } + + public EntityType getEntityType() + { + return bukkitEntity.getType(); + } + +} diff --git a/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityMonster.java b/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityMonster.java new file mode 100644 index 0000000..581e362 --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityMonster.java @@ -0,0 +1,90 @@ +package com.github.hexosse.bloodmoon.entity; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import net.minecraft.server.v1_10_R1.EntityMonster; +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.event.entity.EntityChangeBlockEvent; +import org.bukkit.inventory.ItemStack; + +public abstract class BloodMoonEntityMonster extends BloodMoonEntityLiving +{ + + protected EntityMonster nmsEntity; + + public BloodMoonEntityMonster(BloodMoon plugin, EntityMonster nmsEntity, BloodMoonEntityType type) + { + super(plugin, nmsEntity, type); + + this.nmsEntity = nmsEntity; + } + + protected Block getBreakableTargetBlock() + { + Location direction = nmsEntity.getGoalTarget().getBukkitEntity().getLocation().subtract(bukkitEntity.getLocation()); + + double dx = direction.getX(); + double dz = direction.getY(); + + int bdx = 0; + int bdz = 0; + + if(Math.abs(dx) > Math.abs(dz)) + { + bdx = (dx > 0) ? 1 : -1; + } + else + { + bdz = (dx > 0) ? 1 : -1; + } + + return nmsEntity.world.getWorld().getBlockAt((int) Math.floor(nmsEntity.locX + bdx), (int) Math.floor(nmsEntity.locY), (int) Math.floor(nmsEntity.locZ + bdz)); + } + + protected void attemptBreakBlock(WorldConfig worldConfig, Block block) + { + Material type = block.getType(); + + if(type != Material.AIR && worldConfig.FEATURE_BREAK_BLOCKS_BLOCKS.getValue().contains(type.name())) + { + Location location = block.getLocation(); + + if(this.rand.nextInt(100) < 80) + { + if(this.rand.nextInt(100) < 50) + { + nmsEntity.world.getWorld().playSound(location, Sound.ENTITY_ZOMBIE_ATTACK_DOOR_WOOD, Math.min(this.rand.nextFloat() + 0.2f, 1.0f), 1.0f); + } + } + else + { + EntityChangeBlockEvent event = new EntityChangeBlockEvent(bukkitEntity, block, Material.AIR, (byte) 0); + plugin.getServer().getPluginManager().callEvent(event); + + if(!event.isCancelled()) + { + nmsEntity.world.getWorld().playEffect(location, Effect.ZOMBIE_DESTROY_DOOR, 0); + + if(worldConfig.FEATURE_BREAK_BLOCKS_REALISTIC_DROP.getValue()) + { + block.breakNaturally(); + } + else + { + block.setType(Material.AIR); + + if(worldConfig.FEATURE_BREAK_BLOCKS_DROP_ITEMS.getValue()) + { + nmsEntity.world.getWorld().dropItemNaturally(location, new ItemStack(type, 1, block.getData())); + } + } + } + } + } + } + +} diff --git a/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntitySkeleton.java b/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntitySkeleton.java new file mode 100644 index 0000000..eaf3764 --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntitySkeleton.java @@ -0,0 +1,35 @@ +package com.github.hexosse.bloodmoon.entity; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import net.minecraft.server.v1_10_R1.EntityHuman; +import net.minecraft.server.v1_10_R1.EntityMonster; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; + +public class BloodMoonEntitySkeleton extends BloodMoonEntityMonster { + + public BloodMoonEntitySkeleton(BloodMoon plugin, EntityMonster nmsEntity, BloodMoonEntityType type) { + super(plugin, nmsEntity, type); + } + + @Override + public void onTick() { + World world = getBukkitWorld(); + String entityName = getEntityType().name().toUpperCase(); + WorldConfig worldConfig = plugin.getConfig(world); + + if (nmsEntity.getGoalTarget() instanceof EntityHuman && plugin.isActive(world) && worldConfig.FEATURE_BREAK_BLOCKS_ENABLED.getValue() && worldConfig.FEATURE_BREAK_BLOCKS_MOBS.getValue().contains(entityName) && nmsEntity.world.getTime() % 20 == 0 && nmsEntity.world.worldData.getName().equals(nmsEntity.getGoalTarget().world.worldData.getName())) { + Block[] blocks = new Block[2]; + + blocks[0] = this.getBreakableTargetBlock(); + blocks[1] = blocks[0].getRelative(BlockFace.DOWN); + + for (Block block : blocks) { + this.attemptBreakBlock(worldConfig, block); + } + } + } + +} diff --git a/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntitySpider.java b/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntitySpider.java new file mode 100644 index 0000000..8f3356d --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntitySpider.java @@ -0,0 +1,26 @@ +package com.github.hexosse.bloodmoon.entity; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import net.minecraft.server.v1_10_R1.EntityHuman; +import net.minecraft.server.v1_10_R1.EntityMonster; +import org.bukkit.World; + +public class BloodMoonEntitySpider extends BloodMoonEntityMonster { + + public BloodMoonEntitySpider(BloodMoon plugin, EntityMonster nmsEntity, BloodMoonEntityType type) { + super(plugin, nmsEntity, type); + } + + @Override + public void onTick() { + World world = getBukkitWorld(); + String entityName = getEntityType().name().toUpperCase(); + WorldConfig worldConfig = plugin.getConfig(world); + + if (nmsEntity.getGoalTarget() instanceof EntityHuman && plugin.isActive(world) && worldConfig.FEATURE_BREAK_BLOCKS_ENABLED.getValue() && worldConfig.FEATURE_BREAK_BLOCKS_MOBS.getValue().contains(entityName) && nmsEntity.world.getTime() % 20 == 0 && nmsEntity.world.worldData.getName().equals(nmsEntity.getGoalTarget().world.worldData.getName())) { + this.attemptBreakBlock(worldConfig, this.getBreakableTargetBlock()); + } + } + +} diff --git a/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityType.java b/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityType.java new file mode 100644 index 0000000..150da75 --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityType.java @@ -0,0 +1,152 @@ +package com.github.hexosse.bloodmoon.entity; + +import com.github.hexosse.bloodmoon.exceptions.EntityRegistrationException; +import com.github.hexosse.pluginframework.pluginapi.reflexion.Reflexion; +import net.minecraft.server.v1_10_R1.BiomeBase; +import net.minecraft.server.v1_10_R1.EntityInsentient; +import net.minecraft.server.v1_10_R1.EntityTypes; +import net.minecraft.server.v1_10_R1.World; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_10_R1.CraftWorld; +import org.bukkit.entity.EntityType; +import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; + +import java.util.List; +import java.util.Map; + +public enum BloodMoonEntityType { + + CREEPER("Creeper", 50, EntityType.CREEPER, net.minecraft.server.v1_10_R1.EntityCreeper.class, com.github.hexosse.bloodmoon.nms.EntityCreeper.class), + SKELETON("Skeleton", 51, EntityType.SKELETON, net.minecraft.server.v1_10_R1.EntitySkeleton.class, com.github.hexosse.bloodmoon.nms.EntitySkeleton.class), + SPIDER("Spider", 52, EntityType.SPIDER, net.minecraft.server.v1_10_R1.EntitySpider.class, com.github.hexosse.bloodmoon.nms.EntitySpider.class), + GIANT_ZOMBIE("Giant", 53, EntityType.GIANT, net.minecraft.server.v1_10_R1.EntityGiantZombie.class, com.github.hexosse.bloodmoon.nms.EntityGiantZombie.class), + ZOMBIE("Zombie", 54, EntityType.ZOMBIE, net.minecraft.server.v1_10_R1.EntityZombie.class, com.github.hexosse.bloodmoon.nms.EntityZombie.class), + GHAST("Ghast", 56, EntityType.GHAST, net.minecraft.server.v1_10_R1.EntityGhast.class, com.github.hexosse.bloodmoon.nms.EntityGhast.class), + ENDERMAN("Enderman", 58, EntityType.ENDERMAN, net.minecraft.server.v1_10_R1.EntityEnderman.class, com.github.hexosse.bloodmoon.nms.EntityEnderman.class), + BLAZE("Blaze", 61, EntityType.BLAZE, net.minecraft.server.v1_10_R1.EntityBlaze.class, com.github.hexosse.bloodmoon.nms.EntityBlaze.class), + WITHER("WitherBoss", 64, EntityType.WITHER, net.minecraft.server.v1_10_R1.EntityWither.class, com.github.hexosse.bloodmoon.nms.EntityWither.class), + WITCH("Witch", 66, EntityType.WITCH, net.minecraft.server.v1_10_R1.EntityWitch.class, com.github.hexosse.bloodmoon.nms.EntityWitch.class); + + private static boolean registered = false; + private final String name; + private final int id; + private final EntityType entityType; + private final Class nmsClass; + private final Class bloodMoonClass; + + private BloodMoonEntityType(String name, int id, EntityType entityType, Class nmsClass, Class bloodMoonClass) + { + this.name = name; + this.id = id; + this.entityType = entityType; + this.nmsClass = nmsClass; + this.bloodMoonClass = bloodMoonClass; + } + + @SuppressWarnings("unchecked") + public static void registerEntities() throws EntityRegistrationException + { + if(registered) + { + return; + //throw new EntityRegistrationException("Already registered."); + } + + Map> nameMap; + Map> idMap; + + try + { + nameMap = Reflexion.getField(EntityTypes.class, "c", Map.class, null); + idMap = Reflexion.getField(EntityTypes.class, "e", Map.class, null); + } + catch(Exception e) + { + throw new EntityRegistrationException("Failed to get existing entity maps.", e); + } + + for(BloodMoonEntityType entity : values()) + { + try + { + nameMap.remove(entity.getName()); + idMap.remove(entity.getID()); + + Reflexion.getMethod(EntityTypes.class, "a", Class.class, String.class, int.class).invoke(null, entity.getBloodMoonClass(), entity.getName(), entity.getID()); + //ReflectionUtils.invokeMethod(EntityTypes.class, "a", Void.class, null, new Class[] { Class.class, String.class, int.class }, new Object[] { entity.getBloodMoonClass(), entity.getName(), entity.getID() }); + } + catch(Exception e) + { + throw new EntityRegistrationException("Failed to call EntityTypes.a() for " + entity.getName(), e); + } + } + + for(BiomeBase biomeBase : BiomeBase.i) + { + if(biomeBase == null) + break; + + for(String fieldName : new String[] { "u", "v", "w", "x" }) + { + try + { + List mobList = Reflexion.getField(BiomeBase.class, fieldName, List.class, biomeBase); + for(BiomeBase.BiomeMeta meta : mobList) + { + for(BloodMoonEntityType entity : values()) + { + if(entity.getNMSClass().equals(meta.b)) + meta.b = entity.getBloodMoonClass(); + } + } + } + catch(Exception e) + { + throw new EntityRegistrationException("Failed to modify biome data field " + fieldName, e); + } + } + } + + registered = true; + } + + public String getName() { + return this.name; + } + + public int getID() { + return this.id; + } + + public EntityType getEntityType() { + return this.entityType; + } + + public Class getNMSClass() { + return this.nmsClass; + } + + public Class getBloodMoonClass() { + return this.bloodMoonClass; + } + + private EntityInsentient createEntity(World world) { + try { + return this.getBloodMoonClass().getConstructor(World.class).newInstance(world); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + + public void spawnEntity(Location location) { + World world = ((CraftWorld) location.getWorld()).getHandle(); + + EntityInsentient entity = this.createEntity(world); + entity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + world.addEntity(entity, SpawnReason.CUSTOM); + entity.z(null); + } + +} diff --git a/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityWitch.java b/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityWitch.java new file mode 100644 index 0000000..393cb6c --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityWitch.java @@ -0,0 +1,35 @@ +package com.github.hexosse.bloodmoon.entity; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import net.minecraft.server.v1_10_R1.EntityHuman; +import net.minecraft.server.v1_10_R1.EntityMonster; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; + +public class BloodMoonEntityWitch extends BloodMoonEntityMonster { + + public BloodMoonEntityWitch(BloodMoon plugin, EntityMonster nmsEntity, BloodMoonEntityType type) { + super(plugin, nmsEntity, type); + } + + @Override + public void onTick() { + World world = getBukkitWorld(); + String entityName = getEntityType().name().toUpperCase(); + WorldConfig worldConfig = plugin.getConfig(world); + + if (nmsEntity.getGoalTarget() instanceof EntityHuman && plugin.isActive(world) && worldConfig.FEATURE_BREAK_BLOCKS_ENABLED.getValue() && worldConfig.FEATURE_BREAK_BLOCKS_MOBS.getValue().contains(entityName) && nmsEntity.world.getTime() % 20 == 0 && nmsEntity.world.worldData.getName().equals(nmsEntity.getGoalTarget().world.worldData.getName())) { + Block[] blocks = new Block[2]; + + blocks[0] = this.getBreakableTargetBlock(); + blocks[1] = blocks[0].getRelative(BlockFace.DOWN); + + for (Block block : blocks) { + this.attemptBreakBlock(worldConfig, block); + } + } + } + +} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityWither.java b/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityWither.java similarity index 60% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityWither.java rename to src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityWither.java index 6ceb89b..51371f5 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityWither.java +++ b/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityWither.java @@ -1,8 +1,7 @@ -package uk.co.jacekk.bukkit.bloodmoon.entity; +package com.github.hexosse.bloodmoon.entity; -import net.minecraft.server.v1_8_R3.EntityMonster; - -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.BloodMoon; +import net.minecraft.server.v1_10_R1.EntityMonster; public class BloodMoonEntityWither extends BloodMoonEntityMonster { diff --git a/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityZombie.java b/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityZombie.java new file mode 100644 index 0000000..6a9e030 --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/entity/BloodMoonEntityZombie.java @@ -0,0 +1,35 @@ +package com.github.hexosse.bloodmoon.entity; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import net.minecraft.server.v1_10_R1.EntityHuman; +import net.minecraft.server.v1_10_R1.EntityMonster; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; + +public class BloodMoonEntityZombie extends BloodMoonEntityMonster { + + public BloodMoonEntityZombie(BloodMoon plugin, EntityMonster nmsEntity, BloodMoonEntityType type) { + super(plugin, nmsEntity, type); + } + + @Override + public void onTick() { + World world = getBukkitWorld(); + String entityName = getEntityType().name().toUpperCase(); + WorldConfig worldConfig = plugin.getConfig(world); + + if (nmsEntity.getGoalTarget() instanceof EntityHuman && plugin.isActive(world) && worldConfig.FEATURE_BREAK_BLOCKS_ENABLED.getValue() && worldConfig.FEATURE_BREAK_BLOCKS_MOBS.getValue().contains(entityName) && nmsEntity.world.getTime() % 20 == 0 && nmsEntity.world.worldData.getName().equals(nmsEntity.getGoalTarget().world.worldData.getName())) { + Block[] blocks = new Block[2]; + + blocks[0] = this.getBreakableTargetBlock(); + blocks[1] = blocks[0].getRelative(BlockFace.UP); + + for (Block block : blocks) { + this.attemptBreakBlock(worldConfig, block); + } + } + } + +} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/event/BloodMoonEndEvent.java b/src/main/java/com/github/hexosse/bloodmoon/events/BloodMoonEndEvent.java similarity index 94% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/event/BloodMoonEndEvent.java rename to src/main/java/com/github/hexosse/bloodmoon/events/BloodMoonEndEvent.java index dc37b05..2daab0b 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/event/BloodMoonEndEvent.java +++ b/src/main/java/com/github/hexosse/bloodmoon/events/BloodMoonEndEvent.java @@ -1,4 +1,4 @@ -package uk.co.jacekk.bukkit.bloodmoon.event; +package com.github.hexosse.bloodmoon.events; import org.bukkit.World; import org.bukkit.event.Cancellable; diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/event/BloodMoonStartEvent.java b/src/main/java/com/github/hexosse/bloodmoon/events/BloodMoonStartEvent.java similarity index 95% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/event/BloodMoonStartEvent.java rename to src/main/java/com/github/hexosse/bloodmoon/events/BloodMoonStartEvent.java index 00eb85f..887642d 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/event/BloodMoonStartEvent.java +++ b/src/main/java/com/github/hexosse/bloodmoon/events/BloodMoonStartEvent.java @@ -1,4 +1,4 @@ -package uk.co.jacekk.bukkit.bloodmoon.event; +package com.github.hexosse.bloodmoon.events; import org.bukkit.World; import org.bukkit.event.Cancellable; diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/event/DungeonChestFillEvent.java b/src/main/java/com/github/hexosse/bloodmoon/events/DungeonChestFillEvent.java similarity index 92% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/event/DungeonChestFillEvent.java rename to src/main/java/com/github/hexosse/bloodmoon/events/DungeonChestFillEvent.java index 0dcdcc2..9b6e685 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/event/DungeonChestFillEvent.java +++ b/src/main/java/com/github/hexosse/bloodmoon/events/DungeonChestFillEvent.java @@ -1,4 +1,4 @@ -package uk.co.jacekk.bukkit.bloodmoon.event; +package com.github.hexosse.bloodmoon.events; import org.bukkit.block.Chest; import org.bukkit.event.Event; diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/exceptions/EntityRegistrationException.java b/src/main/java/com/github/hexosse/bloodmoon/exceptions/EntityRegistrationException.java similarity index 87% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/exceptions/EntityRegistrationException.java rename to src/main/java/com/github/hexosse/bloodmoon/exceptions/EntityRegistrationException.java index b1b67dc..b27658e 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/exceptions/EntityRegistrationException.java +++ b/src/main/java/com/github/hexosse/bloodmoon/exceptions/EntityRegistrationException.java @@ -1,4 +1,4 @@ -package uk.co.jacekk.bukkit.bloodmoon.exceptions; +package com.github.hexosse.bloodmoon.exceptions; public class EntityRegistrationException extends Exception { diff --git a/src/main/java/com/github/hexosse/bloodmoon/feature/client/ChatMessageListener.java b/src/main/java/com/github/hexosse/bloodmoon/feature/client/ChatMessageListener.java new file mode 100644 index 0000000..5142665 --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/client/ChatMessageListener.java @@ -0,0 +1,118 @@ +package com.github.hexosse.bloodmoon.feature.client; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.bloodmoon.events.BloodMoonEndEvent; +import com.github.hexosse.bloodmoon.events.BloodMoonStartEvent; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; +import org.bukkit.ChatColor; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerChangedWorldEvent; +import org.bukkit.event.player.PlayerJoinEvent; + +import java.util.UUID; + +public class ChatMessageListener extends PluginListener +{ + public ChatMessageListener(BloodMoon plugin) + { + super(plugin); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onBloodMoonStart(BloodMoonStartEvent event) + { + World world = event.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + if(worldConfig.FEATURE_CHAT_MESSAGE_ENABLED.getValue()) + { + String message = worldConfig.FEATURE_CHAT_MESSAGE_START_MESSAGE.getValue(); + + if(!message.isEmpty()) + { + for(Player player : world.getPlayers()) + { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); + } + } + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onPlayerChangedWorld(PlayerChangedWorldEvent event) + { + Player player = event.getPlayer(); + World world = player.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + if(worldConfig.FEATURE_CHAT_MESSAGE_ENABLED.getValue()) + { + String message = worldConfig.FEATURE_CHAT_MESSAGE_START_MESSAGE.getValue(); + + if(!message.isEmpty()) + { + if(plugin.isActive(world)) + { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); + } + } + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onPlayerJoin(PlayerJoinEvent event) + { + Player player = event.getPlayer(); + World world = player.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + if(plugin.isActive(world) && worldConfig.FEATURE_CHAT_MESSAGE_ENABLED.getValue()) + { + final UUID playerUUID = player.getUniqueId(); + final String message = worldConfig.FEATURE_CHAT_MESSAGE_START_MESSAGE.getValue(); + + if(!message.isEmpty()) + { + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() + { + + @Override + public void run() + { + Player player = plugin.getServer().getPlayer(playerUUID); + + if(player != null) + { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); + } + } + + }, 40L); + } + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onEnd(BloodMoonEndEvent event) + { + World world = event.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + if(worldConfig.FEATURE_CHAT_MESSAGE_ENABLED.getValue()) + { + String message = worldConfig.FEATURE_CHAT_MESSAGE_END_MESSAGE.getValue(); + + if(!message.isEmpty()) + { + for(Player player : world.getPlayers()) + { + player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); + } + } + } + } +} diff --git a/src/main/java/com/github/hexosse/bloodmoon/feature/client/PlaySoundListener.java b/src/main/java/com/github/hexosse/bloodmoon/feature/client/PlaySoundListener.java new file mode 100644 index 0000000..cbb3f59 --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/client/PlaySoundListener.java @@ -0,0 +1,80 @@ +package com.github.hexosse.bloodmoon.feature.client; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.bloodmoon.events.BloodMoonStartEvent; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; +import org.bukkit.Sound; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerChangedWorldEvent; +import org.bukkit.event.player.PlayerJoinEvent; + +import java.util.UUID; + +public class PlaySoundListener extends PluginListener +{ + public PlaySoundListener(BloodMoon plugin) + { + super(plugin); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onBloodMoonStart(BloodMoonStartEvent event) + { + World world = event.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + if(worldConfig.FEATURE_PLAY_SOUND_ENABLED.getValue()) + { + for(Player player : event.getWorld().getPlayers()) + { + player.playSound(player.getLocation(), Sound.valueOf(worldConfig.FEATURE_PLAY_SOUND_SOUND.getValue()), (float) worldConfig.FEATURE_PLAY_SOUND_VOLUME.getValue(), (float) worldConfig.FEATURE_PLAY_SOUND_PITCH.getValue()); + } + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onPlayerChangedWorld(PlayerChangedWorldEvent event) + { + Player player = event.getPlayer(); + World world = player.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + if(plugin.isActive(world) && worldConfig.FEATURE_PLAY_SOUND_ENABLED.getValue()) + { + player.playSound(player.getLocation(), Sound.valueOf(worldConfig.FEATURE_PLAY_SOUND_SOUND.getValue()), (float) worldConfig.FEATURE_PLAY_SOUND_VOLUME.getValue(), (float) worldConfig.FEATURE_PLAY_SOUND_PITCH.getValue()); + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onPlayerJoin(PlayerJoinEvent event) + { + Player player = event.getPlayer(); + World world = player.getWorld(); + final WorldConfig worldConfig = plugin.getConfig(world); + + if(plugin.isActive(world) && worldConfig.FEATURE_PLAY_SOUND_ENABLED.getValue()) + { + final UUID playerUUID = player.getUniqueId(); + + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() + { + + @Override + public void run() + { + Player player = plugin.getServer().getPlayer(playerUUID); + + if(player != null) + { + player.playSound(player.getLocation(), Sound.valueOf(worldConfig.FEATURE_PLAY_SOUND_SOUND.getValue()), (float) worldConfig.FEATURE_PLAY_SOUND_VOLUME.getValue(), (float) worldConfig.FEATURE_PLAY_SOUND_PITCH.getValue()); + } + } + + }, 40L); + } + } +} diff --git a/src/main/java/com/github/hexosse/bloodmoon/feature/client/TexturePackListener.java b/src/main/java/com/github/hexosse/bloodmoon/feature/client/TexturePackListener.java new file mode 100644 index 0000000..63880a1 --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/client/TexturePackListener.java @@ -0,0 +1,135 @@ +package com.github.hexosse.bloodmoon.feature.client; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.bloodmoon.events.BloodMoonEndEvent; +import com.github.hexosse.bloodmoon.events.BloodMoonStartEvent; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerChangedWorldEvent; +import org.bukkit.event.player.PlayerJoinEvent; + + +public class TexturePackListener extends PluginListener +{ + public TexturePackListener(BloodMoon plugin) + { + super(plugin); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onBloodMoonStart(BloodMoonStartEvent event) + { + final World world = event.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + if(worldConfig.FEATURE_TEXTURE_PACK_ENABLED.getValue()) + { + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() + { + + @Override + public void run() + { + sendResourcePack(world, true); + } + }); + + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onBloodMoonEnd(BloodMoonEndEvent event) + { + final World world = event.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + if(worldConfig.FEATURE_TEXTURE_PACK_ENABLED.getValue()) + { + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() + { + + @Override + public void run() + { + sendResourcePack(world, false); + } + }); + + } + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onPlayerChangedWorld(PlayerChangedWorldEvent event) + { + Player player = event.getPlayer(); + World from = event.getFrom(); + World to = player.getWorld(); + WorldConfig worldConfig = plugin.getConfig(to); + + if(plugin.isActive(to) && worldConfig.FEATURE_TEXTURE_PACK_ENABLED.getValue()) + { + if(!plugin.isActive(from) && plugin.isActive(to)) + { + player.setResourcePack(worldConfig.FEATURE_TEXTURE_PACK_BLOODMOON.getValue()); + } + else if(plugin.isActive(from) && !plugin.isActive(to)) + { + player.setResourcePack(worldConfig.FEATURE_TEXTURE_PACK_NORMAL.getValue()); + } + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onPlayerJoin(PlayerJoinEvent event) + { + Player player = event.getPlayer(); + World world = player.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + if(plugin.isActive(world) && worldConfig.FEATURE_TEXTURE_PACK_ENABLED.getValue()) + { + player.setResourcePack(worldConfig.FEATURE_TEXTURE_PACK_BLOODMOON.getValue()); + } + } + + /** + * Send the resource pack to all players in the specified world True + * + * @param world the world to send the texture pack to + * @param bloodmoon true to send BloodMoon texture pack, false to send + * normal texture pack + */ + public void sendResourcePack(World world, boolean bloodmoon) + { + WorldConfig worldConfig = plugin.getConfig(world); + + String resource = bloodmoon + ? worldConfig.FEATURE_TEXTURE_PACK_BLOODMOON.getValue() + : worldConfig.FEATURE_TEXTURE_PACK_NORMAL.getValue(); + + for(Player player : world.getPlayers()) + player.setResourcePack(resource); + } + + /** + * Send the resource pack to the specified player + * + * @param player the player to send the resource pack to + * @param bloodmoon true to send BloodMoon texture pack, false to send + * normal texture pack + */ + public void sendResourcePack(Player player, boolean bloodmoon) + { + WorldConfig worldConfig = plugin.getConfig(player.getWorld()); + + String resource = bloodmoon + ? worldConfig.FEATURE_TEXTURE_PACK_BLOODMOON.getValue() + : worldConfig.FEATURE_TEXTURE_PACK_NORMAL.getValue(); + + player.setResourcePack(resource); + } +} diff --git a/src/main/java/com/github/hexosse/bloodmoon/feature/mob/DaylightProofMobsListener.java b/src/main/java/com/github/hexosse/bloodmoon/feature/mob/DaylightProofMobsListener.java new file mode 100644 index 0000000..01e6643 --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/mob/DaylightProofMobsListener.java @@ -0,0 +1,35 @@ +package com.github.hexosse.bloodmoon.feature.mob; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; +import org.bukkit.World; +import org.bukkit.entity.EntityType; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityCombustEvent; + +public class DaylightProofMobsListener extends PluginListener +{ + public DaylightProofMobsListener(BloodMoon plugin) + { + super(plugin); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onEntityCombust(EntityCombustEvent event) + { + World world = event.getEntity().getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + EntityType type = event.getEntityType(); + + if(type == EntityType.ZOMBIE || type == EntityType.SKELETON) + { + if(plugin.isActive(world) && worldConfig.FEATURE_DAYLIGHT_PROOF_MOBS_ENABLED.getValue()) + { + event.setCancelled(true); + } + } + + } +} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/FireArrowsListener.java b/src/main/java/com/github/hexosse/bloodmoon/feature/mob/FireArrowsListener.java similarity index 58% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/FireArrowsListener.java rename to src/main/java/com/github/hexosse/bloodmoon/feature/mob/FireArrowsListener.java index da95d2b..952f307 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/FireArrowsListener.java +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/mob/FireArrowsListener.java @@ -1,38 +1,33 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.mob; +package com.github.hexosse.bloodmoon.feature.mob; +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.bloodmoon.nms.EntitySkeleton; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; -import org.bukkit.entity.Entity; +import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Projectile; -import org.bukkit.entity.Skeleton; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; import org.bukkit.event.entity.ProjectileHitEvent; -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; -import uk.co.jacekk.bukkit.bloodmoon.nms.EntitySkeleton; - -public class FireArrowsListener implements Listener { - - private final BloodMoon plugin; +public class FireArrowsListener extends PluginListener +{ public FireArrowsListener(BloodMoon plugin) { - this.plugin = plugin; + super(plugin); } @EventHandler(priority = EventPriority.NORMAL) public void onProjectileHit(ProjectileHitEvent event) { Projectile projectile = event.getEntity(); - String worldName = projectile.getWorld().getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); + World world = projectile.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); - if (plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.FIRE_ARROWS) && worldConfig.getBoolean(Config.FEATURE_FIRE_ARROWS_IGNITE_TARGET)) { + if (plugin.isActive(world) && worldConfig.FEATURE_FIRE_ARROWS_ENABLED.getValue() && worldConfig.FEATURE_FIRE_ARROWS_IGNITE_TARGET.getValue()) { LivingEntity shooter = (LivingEntity) projectile.getShooter(); if (shooter.getType() == EntityType.SKELETON) { //Not sure why this is here, or why fire arrows even work with it here return; @@ -48,5 +43,4 @@ public void onProjectileHit(ProjectileHitEvent event) { } } } - } diff --git a/src/main/java/com/github/hexosse/bloodmoon/feature/mob/MaxHealthListener.java b/src/main/java/com/github/hexosse/bloodmoon/feature/mob/MaxHealthListener.java new file mode 100644 index 0000000..c460a6a --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/mob/MaxHealthListener.java @@ -0,0 +1,73 @@ +package com.github.hexosse.bloodmoon.feature.mob; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.bloodmoon.events.BloodMoonEndEvent; +import com.github.hexosse.bloodmoon.events.BloodMoonStartEvent; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; +import org.bukkit.World; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.metadata.FixedMetadataValue; + +public class MaxHealthListener extends PluginListener +{ + private final String metaKey = "Bloodmoon-" + getClass().getSimpleName(); + + public MaxHealthListener(BloodMoon plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onStart(BloodMoonStartEvent event) { + World world = event.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + if (worldConfig.FEATURE_MAX_HEALTH_ENABLED.getValue()) { + for (LivingEntity entity : world.getLivingEntities()) { + if (worldConfig.FEATURE_MAX_HEALTH_MOBS.getValue().contains(entity.getType().name())) { + doEntity(entity, worldConfig); + } + } + } + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onCreatureSpawn(CreatureSpawnEvent event) { + LivingEntity entity = event.getEntity(); + World world = event.getLocation().getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + if (plugin.isActive(world) && worldConfig.FEATURE_MAX_HEALTH_ENABLED.getValue() && worldConfig.FEATURE_MAX_HEALTH_MOBS.getValue().contains(entity.getType().name())) { + doEntity(entity, worldConfig); + } + } + + private void doEntity(LivingEntity entity, WorldConfig worldConfig) { + double newMaxHealth = entity.getMaxHealth() * worldConfig.FEATURE_MAX_HEALTH_MULTIPLIER.getValue(); + double damage = entity.getMaxHealth() - entity.getHealth(); + + entity.setMaxHealth(newMaxHealth); + entity.setHealth(Math.min(newMaxHealth - damage, newMaxHealth)); + + entity.setMetadata(metaKey, new FixedMetadataValue(plugin, true)); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onStop(BloodMoonEndEvent event) { + World world = event.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + if (worldConfig.FEATURE_MAX_HEALTH_ENABLED.getValue()) { + for (LivingEntity entity : world.getLivingEntities()) { + if (worldConfig.FEATURE_MAX_HEALTH_MOBS.getValue().contains(entity.getType().name())) { + if (entity.hasMetadata(metaKey)) { + entity.resetMaxHealth(); + } + } + } + } + } +} diff --git a/src/main/java/com/github/hexosse/bloodmoon/feature/mob/MoreDropsListener.java b/src/main/java/com/github/hexosse/bloodmoon/feature/mob/MoreDropsListener.java new file mode 100644 index 0000000..90eca8c --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/mob/MoreDropsListener.java @@ -0,0 +1,35 @@ +package com.github.hexosse.bloodmoon.feature.mob; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; +import org.bukkit.World; +import org.bukkit.entity.Creature; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.inventory.ItemStack; + +public class MoreDropsListener extends PluginListener +{ + public MoreDropsListener(BloodMoon plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.NORMAL) + public void onEntityDeath(EntityDeathEvent event) { + LivingEntity entity = event.getEntity(); + World world = entity.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + if (entity instanceof Creature && plugin.isActive(world) && worldConfig.FEATURE_MORE_DROPS_ENABLED.getValue()) { + if (!worldConfig.FEATURE_MORE_DROPS_IGNORE_SPAWNERS.getValue() || plugin.getSpawnReason(entity) != SpawnReason.SPAWNER) { + for (ItemStack drop : event.getDrops()) { + drop.setAmount(drop.getAmount() * Math.max(worldConfig.FEATURE_MORE_DROPS_MULTIPLIER.getValue(), 0)); + } + } + } + } +} diff --git a/src/main/java/com/github/hexosse/bloodmoon/feature/mob/MoreExpListener.java b/src/main/java/com/github/hexosse/bloodmoon/feature/mob/MoreExpListener.java new file mode 100644 index 0000000..afa1551 --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/mob/MoreExpListener.java @@ -0,0 +1,32 @@ +package com.github.hexosse.bloodmoon.feature.mob; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; +import org.bukkit.World; +import org.bukkit.entity.Creature; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; +import org.bukkit.event.entity.EntityDeathEvent; + +public class MoreExpListener extends PluginListener +{ + public MoreExpListener(BloodMoon plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onEntityDeath(EntityDeathEvent event) { + LivingEntity entity = event.getEntity(); + World world = entity.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + if (entity instanceof Creature && plugin.isActive(world) && worldConfig.FEATURE_MORE_EXP_ENABLED.getValue()) { + if (!worldConfig.FEATURE_MORE_EXP_IGNORE_SPAWNERS.getValue() || plugin.getSpawnReason(entity) != SpawnReason.SPAWNER) { + event.setDroppedExp(event.getDroppedExp() * Math.max(worldConfig.FEATURE_MORE_EXP_MULTIPLIER.getValue(), 0)); + } + } + } +} diff --git a/src/main/java/com/github/hexosse/bloodmoon/feature/mob/MovementSpeedListener.java b/src/main/java/com/github/hexosse/bloodmoon/feature/mob/MovementSpeedListener.java new file mode 100644 index 0000000..d2b2d3b --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/mob/MovementSpeedListener.java @@ -0,0 +1,94 @@ +package com.github.hexosse.bloodmoon.feature.mob; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.bloodmoon.entity.BloodMoonEntityLiving; +import com.github.hexosse.bloodmoon.events.BloodMoonEndEvent; +import com.github.hexosse.bloodmoon.events.BloodMoonStartEvent; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_10_R1.entity.CraftLivingEntity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.CreatureSpawnEvent; + +import java.util.Random; + +public class MovementSpeedListener extends PluginListener +{ + private final Random random = new Random(); + + public MovementSpeedListener(BloodMoon plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onStart(BloodMoonStartEvent event) + { + World world = event.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + if(worldConfig.FEATURE_MOVEMENT_SPEED_ENABLED.getValue()) + { + for(LivingEntity entity : world.getLivingEntities()) + { + if(worldConfig.FEATURE_MOVEMENT_SPEED_MOBS.getValue().contains(entity.getType().name())) + { + try + { + double multiplier = (this.random.nextInt(100) < worldConfig.FEATURE_MOVEMENT_SPEED_FAST_CHANCE.getValue()) ? worldConfig.FEATURE_MOVEMENT_SPEED_FAST_MULTIPLIER.getValue() : worldConfig.FEATURE_MOVEMENT_SPEED_MULTIPLIER.getValue(); + + BloodMoonEntityLiving bloodMoonEntity = BloodMoonEntityLiving.getBloodMoonEntity(((CraftLivingEntity) entity).getHandle()); + bloodMoonEntity.setSpeedMultiplier(multiplier); + } + catch(IllegalArgumentException e) { + // This means the entity is not supported *shrug* + } + } + } + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onStop(BloodMoonEndEvent event) + { + World world = event.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + if (worldConfig.FEATURE_MOVEMENT_SPEED_ENABLED.getValue()) { + for (LivingEntity entity : world.getLivingEntities()) { + try { + BloodMoonEntityLiving bloodMoonEntity = BloodMoonEntityLiving.getBloodMoonEntity(((CraftLivingEntity) entity).getHandle()); + bloodMoonEntity.clearSpeedMultiplier(); + } catch (IllegalArgumentException e) { + // This means the entity is not supported *shrug* + } + } + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onCreatureSpawn(CreatureSpawnEvent event) + { + LivingEntity entity = event.getEntity(); + World world = entity.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + if(plugin.isActive(world) && worldConfig.FEATURE_MOVEMENT_SPEED_ENABLED.getValue()) + { + if(worldConfig.FEATURE_MOVEMENT_SPEED_MOBS.getValue().contains(entity.getType().name())) + { + try + { + BloodMoonEntityLiving bloodMoonEntity = BloodMoonEntityLiving.getBloodMoonEntity(((CraftLivingEntity) entity).getHandle()); + double multiplier = (this.random.nextInt(100) < worldConfig.FEATURE_MOVEMENT_SPEED_FAST_CHANCE.getValue()) ? worldConfig.FEATURE_MOVEMENT_SPEED_FAST_MULTIPLIER.getValue() : worldConfig.FEATURE_MOVEMENT_SPEED_MULTIPLIER.getValue(); + bloodMoonEntity.setSpeedMultiplier(multiplier); + } + catch(IllegalArgumentException e) { + // This means the entity is not supported *shrug* + } + } + } + } +} diff --git a/src/main/java/com/github/hexosse/bloodmoon/feature/mob/SuperCreepersListener.java b/src/main/java/com/github/hexosse/bloodmoon/feature/mob/SuperCreepersListener.java new file mode 100644 index 0000000..3bd5ac1 --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/mob/SuperCreepersListener.java @@ -0,0 +1,74 @@ +package com.github.hexosse.bloodmoon.feature.mob; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.bloodmoon.events.BloodMoonEndEvent; +import com.github.hexosse.bloodmoon.events.BloodMoonStartEvent; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; +import org.bukkit.World; +import org.bukkit.entity.Creeper; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.ExplosionPrimeEvent; + +public class SuperCreepersListener extends PluginListener +{ + public SuperCreepersListener(BloodMoon plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onStart(BloodMoonStartEvent event) { + World world = event.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + if (worldConfig.FEATURE_SUPER_CREEPERS_ENABLED.getValue() && worldConfig.FEATURE_SUPER_CREEPERS_LIGHTNING.getValue()) { + for (LivingEntity entity : world.getLivingEntities()) { + if (entity.getType() == EntityType.CREEPER) { + ((Creeper) entity).setPowered(true); + } + } + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onStop(BloodMoonEndEvent event) { + World world = event.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + if (worldConfig.FEATURE_SUPER_CREEPERS_ENABLED.getValue() && worldConfig.FEATURE_SUPER_CREEPERS_LIGHTNING.getValue()) { + for (LivingEntity entity : world.getLivingEntities()) { + if (entity.getType() == EntityType.CREEPER) { + ((Creeper) entity).setPowered(false); + } + } + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onCreatureSpawn(CreatureSpawnEvent event) { + LivingEntity entity = event.getEntity(); + World world = entity.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + if (entity.getType() == EntityType.CREEPER && plugin.isActive(world) && worldConfig.FEATURE_SUPER_CREEPERS_ENABLED.getValue() && worldConfig.FEATURE_SUPER_CREEPERS_LIGHTNING.getValue()) { + ((Creeper) entity).setPowered(true); + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onExplosionPrime(ExplosionPrimeEvent event) { + if (event.getEntity() != null && event.getEntityType() == EntityType.CREEPER) { + World world = event.getEntity().getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + if (plugin.isActive(world) && worldConfig.FEATURE_SUPER_CREEPERS_ENABLED.getValue()) { + event.setRadius(worldConfig.FEATURE_SUPER_CREEPERS_POWER.getValue()); + event.setFire(worldConfig.FEATURE_SUPER_CREEPERS_FIRE.getValue()); + } + } + } +} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/TargetDistanceListener.java b/src/main/java/com/github/hexosse/bloodmoon/feature/mob/TargetDistanceListener.java similarity index 53% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/TargetDistanceListener.java rename to src/main/java/com/github/hexosse/bloodmoon/feature/mob/TargetDistanceListener.java index 4a40ac5..d4b14df 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/TargetDistanceListener.java +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/mob/TargetDistanceListener.java @@ -1,41 +1,35 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.mob; +package com.github.hexosse.bloodmoon.feature.mob; +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.bloodmoon.entity.BloodMoonEntityLiving; +import com.github.hexosse.bloodmoon.events.BloodMoonEndEvent; +import com.github.hexosse.bloodmoon.events.BloodMoonStartEvent; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; import org.bukkit.World; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity; +import org.bukkit.craftbukkit.v1_10_R1.entity.CraftLivingEntity; import org.bukkit.entity.LivingEntity; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; import org.bukkit.event.entity.CreatureSpawnEvent; -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; -import uk.co.jacekk.bukkit.bloodmoon.entity.BloodMoonEntityLiving; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonEndEvent; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonStartEvent; - -public class TargetDistanceListener implements Listener { - - private final BloodMoon plugin; - +public class TargetDistanceListener extends PluginListener +{ public TargetDistanceListener(BloodMoon plugin) { - this.plugin = plugin; + super(plugin); } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onStart(BloodMoonStartEvent event) { World world = event.getWorld(); - String worldName = world.getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); + WorldConfig worldConfig = plugin.getConfig(world); - if (plugin.isFeatureEnabled(worldName, Feature.TARGET_DISTANCE)) { + if (worldConfig.FEATURE_TARGET_DISTANCE_ENABLED.getValue()) { for (LivingEntity entity : world.getLivingEntities()) { - if (worldConfig.getStringList(Config.FEATURE_TARGET_DISTANCE_MOBS).contains(entity.getType().name())) { + if (worldConfig.FEATURE_TARGET_DISTANCE_MOBS.getValue().contains(entity.getType().name())) { try { BloodMoonEntityLiving bloodMoonEntity = BloodMoonEntityLiving.getBloodMoonEntity(((CraftLivingEntity) entity).getHandle()); - bloodMoonEntity.setFollowRangeMultiplier(worldConfig.getDouble(Config.FEATURE_TARGET_DISTANCE_MULTIPLIER)); + bloodMoonEntity.setFollowRangeMultiplier(worldConfig.FEATURE_TARGET_DISTANCE_MULTIPLIER.getValue()); } catch (IllegalArgumentException e) { // This means the entity is not supported *shrug* } @@ -47,12 +41,13 @@ public void onStart(BloodMoonStartEvent event) { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onStop(BloodMoonEndEvent event) { World world = event.getWorld(); - String worldName = world.getName(); + WorldConfig worldConfig = plugin.getConfig(world); - if (plugin.isFeatureEnabled(worldName, Feature.TARGET_DISTANCE)) { + if (worldConfig.FEATURE_TARGET_DISTANCE_ENABLED.getValue()) { for (LivingEntity entity : world.getLivingEntities()) { try { - BloodMoonEntityLiving.getBloodMoonEntity(((CraftLivingEntity) entity).getHandle()).clearFollowRangeMultiplier(); + BloodMoonEntityLiving bloodMoonEntity = BloodMoonEntityLiving.getBloodMoonEntity(((CraftLivingEntity) entity).getHandle()); + bloodMoonEntity.clearFollowRangeMultiplier(); } catch (IllegalArgumentException e) { // This means the entity is not supported *shrug* } @@ -64,20 +59,17 @@ public void onStop(BloodMoonEndEvent event) { public void onCreatureSpawn(CreatureSpawnEvent event) { LivingEntity entity = event.getEntity(); World world = entity.getWorld(); - String worldName = world.getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); + WorldConfig worldConfig = plugin.getConfig(world); - if (plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.TARGET_DISTANCE)) { - if (worldConfig.getStringList(Config.FEATURE_TARGET_DISTANCE_MOBS).contains(entity.getType().name())) { + if (plugin.isActive(world) && worldConfig.FEATURE_TARGET_DISTANCE_ENABLED.getValue()) { + if (worldConfig.FEATURE_TARGET_DISTANCE_MOBS.getValue().contains(entity.getType().name())) { try { - //((CraftLivingEntity)entity).setfol BloodMoonEntityLiving bloodMoonEntity = BloodMoonEntityLiving.getBloodMoonEntity(((CraftLivingEntity) entity).getHandle()); - bloodMoonEntity.setFollowRangeMultiplier(worldConfig.getDouble(Config.FEATURE_TARGET_DISTANCE_MULTIPLIER)); + bloodMoonEntity.setFollowRangeMultiplier(worldConfig.FEATURE_TARGET_DISTANCE_MULTIPLIER.getValue()); } catch (IllegalArgumentException e) { // This means the entity is not supported *shrug* } } } } - } diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/ZombieArmorListener.java b/src/main/java/com/github/hexosse/bloodmoon/feature/mob/ZombieArmorListener.java similarity index 60% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/ZombieArmorListener.java rename to src/main/java/com/github/hexosse/bloodmoon/feature/mob/ZombieArmorListener.java index df6ef8c..a99b5a5 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/ZombieArmorListener.java +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/mob/ZombieArmorListener.java @@ -1,38 +1,35 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.mob; - -import java.util.Random; -import java.util.logging.Level; - +package com.github.hexosse.bloodmoon.feature.mob; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.bloodmoon.events.BloodMoonEndEvent; +import com.github.hexosse.bloodmoon.events.BloodMoonStartEvent; +import com.github.hexosse.bloodmoon.util.RandomUtils; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.inventory.EntityEquipment; import org.bukkit.inventory.ItemStack; -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.baseplugin.util.ListUtils; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonEndEvent; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonStartEvent; - -public class ZombieArmorListener implements Listener { +import java.util.Random; +import java.util.logging.Level; - private final BloodMoon plugin; +public class ZombieArmorListener extends PluginListener +{ private final Random random = new Random(); public ZombieArmorListener(BloodMoon plugin) { - this.plugin = plugin; + super(plugin); } - private void giveArmor(LivingEntity entity, PluginConfig worldConfig) { - String name = ListUtils.getRandom(worldConfig.getStringList(Config.FEATURE_ZOMBIE_ARMOR_ARMOR)).toUpperCase(); + private void giveArmor(LivingEntity entity, WorldConfig worldConfig) { + String name = RandomUtils.getRandom(worldConfig.FEATURE_ZOMBIE_ARMOR_ARMOR.getValue()).toUpperCase(); if (Material.getMaterial(name + "_BOOTS") == null) { plugin.getLogger().log(Level.WARNING, "{0} is not a valid armor name", name); @@ -46,7 +43,7 @@ private void giveArmor(LivingEntity entity, PluginConfig worldConfig) { equipment.setChestplate(new ItemStack(Material.getMaterial(name + "_CHESTPLATE"))); equipment.setHelmet(new ItemStack(Material.getMaterial(name + "_HELMET"))); - float dropChance = worldConfig.getInt(Config.FEATURE_ZOMBIE_ARMOR_DROP_CHANCE) / 100.0f; + float dropChance = worldConfig.FEATURE_ZOMBIE_ARMOR_DROP_CHANCE.getValue() / 100.0f; equipment.setBootsDropChance(dropChance); equipment.setLeggingsDropChance(dropChance); @@ -56,13 +53,13 @@ private void giveArmor(LivingEntity entity, PluginConfig worldConfig) { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onStart(BloodMoonStartEvent event) { - String worldName = event.getWorld().getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); + World world = event.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); - if (plugin.isFeatureEnabled(worldName, Feature.ZOMBIE_ARMOR)) { + if (worldConfig.FEATURE_ZOMBIE_ARMOR_ENABLED.getValue()) { for (LivingEntity entity : event.getWorld().getLivingEntities()) { - if (!worldConfig.getBoolean(Config.FEATURE_ZOMBIE_ARMOR_IGNORE_SPAWNERS) || plugin.getSpawnReason(entity) != SpawnReason.SPAWNER) { - if (entity.getType() == EntityType.ZOMBIE && this.random.nextInt(100) < worldConfig.getInt(Config.FEATURE_ZOMBIE_WEAPON_CHANCE)) { + if (!worldConfig.FEATURE_ZOMBIE_ARMOR_IGNORE_SPAWNERS.getValue() || plugin.getSpawnReason(entity) != SpawnReason.SPAWNER) { + if (entity.getType() == EntityType.ZOMBIE && this.random.nextInt(100) < worldConfig.FEATURE_ZOMBIE_WEAPON_CHANCE.getValue()) { this.giveArmor(entity, worldConfig); } } @@ -72,14 +69,14 @@ public void onStart(BloodMoonStartEvent event) { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onCreatureSpawn(CreatureSpawnEvent event) { - String worldName = event.getLocation().getWorld().getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); + World world = event.getLocation().getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); - if (plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.ZOMBIE_ARMOR)) { + if (plugin.isActive(world) && worldConfig.FEATURE_ZOMBIE_ARMOR_ENABLED.getValue()) { LivingEntity entity = event.getEntity(); - if (!worldConfig.getBoolean(Config.FEATURE_ZOMBIE_ARMOR_IGNORE_SPAWNERS) || event.getSpawnReason() != SpawnReason.SPAWNER) { - if (entity.getType() == EntityType.ZOMBIE && this.random.nextInt(100) < worldConfig.getInt(Config.FEATURE_ZOMBIE_WEAPON_CHANCE)) { + if (!worldConfig.FEATURE_ZOMBIE_ARMOR_IGNORE_SPAWNERS.getValue() || event.getSpawnReason() != SpawnReason.SPAWNER) { + if (entity.getType() == EntityType.ZOMBIE && this.random.nextInt(100) < worldConfig.FEATURE_ZOMBIE_WEAPON_CHANCE.getValue()) { this.giveArmor(entity, worldConfig); } } @@ -88,9 +85,10 @@ public void onCreatureSpawn(CreatureSpawnEvent event) { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onStop(BloodMoonEndEvent event) { - String worldName = event.getWorld().getName(); + World world = event.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); - if (plugin.isFeatureEnabled(worldName, Feature.ZOMBIE_ARMOR)) { + if (worldConfig.FEATURE_ZOMBIE_ARMOR_ENABLED.getValue()) { for (LivingEntity entity : event.getWorld().getLivingEntities()) { if (entity.getType() == EntityType.ZOMBIE) { EntityEquipment equipment = entity.getEquipment(); @@ -108,5 +106,4 @@ public void onStop(BloodMoonEndEvent event) { } } } - } diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/ZombieWeaponListener.java b/src/main/java/com/github/hexosse/bloodmoon/feature/mob/ZombieWeaponListener.java similarity index 50% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/ZombieWeaponListener.java rename to src/main/java/com/github/hexosse/bloodmoon/feature/mob/ZombieWeaponListener.java index e0ec959..c923493 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/ZombieWeaponListener.java +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/mob/ZombieWeaponListener.java @@ -1,38 +1,35 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.mob; - -import java.util.Random; -import java.util.logging.Level; - +package com.github.hexosse.bloodmoon.feature.mob; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.bloodmoon.events.BloodMoonEndEvent; +import com.github.hexosse.bloodmoon.events.BloodMoonStartEvent; +import com.github.hexosse.bloodmoon.util.RandomUtils; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.inventory.EntityEquipment; import org.bukkit.inventory.ItemStack; -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.baseplugin.util.ListUtils; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonEndEvent; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonStartEvent; - -public class ZombieWeaponListener implements Listener { +import java.util.Random; +import java.util.logging.Level; - private final BloodMoon plugin; +public class ZombieWeaponListener extends PluginListener +{ private final Random random = new Random(); public ZombieWeaponListener(BloodMoon plugin) { - this.plugin = plugin; + super(plugin); } - private void giveWeapon(LivingEntity entity, PluginConfig worldConfig) { - String name = ListUtils.getRandom(worldConfig.getStringList(Config.FEATURE_ZOMBIE_WEAPON_WEAPONS)).toUpperCase(); + private void giveWeapon(LivingEntity entity, WorldConfig worldConfig) { + String name = RandomUtils.getRandom(worldConfig.FEATURE_ZOMBIE_WEAPON_WEAPONS.getValue()).toUpperCase(); Material type = Material.getMaterial(name); if (type == null || type.isBlock()) { @@ -43,18 +40,18 @@ private void giveWeapon(LivingEntity entity, PluginConfig worldConfig) { EntityEquipment equipment = entity.getEquipment(); equipment.setItemInHand(new ItemStack(type)); - equipment.setItemInHandDropChance(worldConfig.getInt(Config.FEATURE_ZOMBIE_WEAPON_DROP_CHANCE) / 100.0f); + equipment.setItemInHandDropChance(worldConfig.FEATURE_ZOMBIE_WEAPON_DROP_CHANCE.getValue() / 100.0f); } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onStart(BloodMoonStartEvent event) { - String worldName = event.getWorld().getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); + World world = event.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); - if (plugin.isFeatureEnabled(worldName, Feature.ZOMBIE_WEAPON)) { + if (worldConfig.FEATURE_ZOMBIE_WEAPON_ENABLED.getValue()) { for (LivingEntity entity : event.getWorld().getLivingEntities()) { - if (!worldConfig.getBoolean(Config.FEATURE_ZOMBIE_WEAPON_IGNORE_SPAWNERS) || plugin.getSpawnReason(entity) != SpawnReason.SPAWNER) { - if (entity.getType() == EntityType.ZOMBIE && this.random.nextInt(100) < worldConfig.getInt(Config.FEATURE_ZOMBIE_WEAPON_CHANCE)) { + if (!worldConfig.FEATURE_ZOMBIE_WEAPON_IGNORE_SPAWNERS.getValue() || plugin.getSpawnReason(entity) != SpawnReason.SPAWNER) { + if (entity.getType() == EntityType.ZOMBIE && this.random.nextInt(100) < worldConfig.FEATURE_ZOMBIE_WEAPON_CHANCE.getValue()) { this.giveWeapon(entity, worldConfig); } } @@ -64,14 +61,14 @@ public void onStart(BloodMoonStartEvent event) { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onCreatureSpawn(CreatureSpawnEvent event) { - String worldName = event.getLocation().getWorld().getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); + World world = event.getLocation().getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); - if (plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.ZOMBIE_WEAPON)) { + if (plugin.isActive(world) && worldConfig.FEATURE_ZOMBIE_WEAPON_ENABLED.getValue()) { LivingEntity entity = event.getEntity(); - if (!worldConfig.getBoolean(Config.FEATURE_ZOMBIE_WEAPON_IGNORE_SPAWNERS) || event.getSpawnReason() != SpawnReason.SPAWNER) { - if (entity.getType() == EntityType.ZOMBIE && this.random.nextInt(100) < worldConfig.getInt(Config.FEATURE_ZOMBIE_WEAPON_CHANCE)) { + if (!worldConfig.FEATURE_ZOMBIE_WEAPON_IGNORE_SPAWNERS.getValue() || event.getSpawnReason() != SpawnReason.SPAWNER) { + if (entity.getType() == EntityType.ZOMBIE && this.random.nextInt(100) < worldConfig.FEATURE_ZOMBIE_WEAPON_CHANCE.getValue()) { this.giveWeapon(entity, worldConfig); } } @@ -80,10 +77,11 @@ public void onCreatureSpawn(CreatureSpawnEvent event) { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onStop(BloodMoonEndEvent event) { - String worldName = event.getWorld().getName(); + World world = event.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); - if (plugin.isFeatureEnabled(worldName, Feature.ZOMBIE_WEAPON)) { - for (LivingEntity entity : event.getWorld().getLivingEntities()) { + if (worldConfig.FEATURE_ZOMBIE_WEAPON_ENABLED.getValue()) { + for (LivingEntity entity : world.getLivingEntities()) { if (entity.getType() == EntityType.ZOMBIE) { EntityEquipment equipment = entity.getEquipment(); @@ -93,5 +91,4 @@ public void onStop(BloodMoonEndEvent event) { } } } - } diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/player/SwordDamageListener.java b/src/main/java/com/github/hexosse/bloodmoon/feature/player/SwordDamageListener.java similarity index 65% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/player/SwordDamageListener.java rename to src/main/java/com/github/hexosse/bloodmoon/feature/player/SwordDamageListener.java index a694f46..d0dde3b 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/player/SwordDamageListener.java +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/player/SwordDamageListener.java @@ -1,7 +1,9 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.player; - -import java.util.Random; +package com.github.hexosse.bloodmoon.feature.player; +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; +import org.bukkit.World; import org.bukkit.entity.Creature; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; @@ -12,14 +14,10 @@ import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.inventory.ItemStack; -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.baseplugin.event.BaseListener; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; - -public class SwordDamageListener extends BaseListener { +import java.util.Random; +public class SwordDamageListener extends PluginListener +{ private final Random random = new Random(); public SwordDamageListener(BloodMoon plugin) { @@ -29,10 +27,10 @@ public SwordDamageListener(BloodMoon plugin) { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onEntityDamage(EntityDamageEvent event) { Entity entity = event.getEntity(); - String worldName = entity.getWorld().getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); + World world = entity.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); - if (event.getCause() == DamageCause.ENTITY_ATTACK && plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.SWORD_DAMAGE)) { + if (event.getCause() == DamageCause.ENTITY_ATTACK && plugin.isActive(world) && worldConfig.FEATURE_SWORD_DAMAGE_ENABLED.getValue()) { if (entity instanceof Creature) { Creature creature = (Creature) entity; String creatureName = creature.getType().name().toUpperCase(); @@ -43,7 +41,7 @@ public void onEntityDamage(EntityDamageEvent event) { ItemStack item = player.getItemInHand(); String itemName = item.getType().name().toUpperCase(); - if (worldConfig.getStringList(Config.FEATURE_SWORD_DAMAGE_MOBS).contains(creatureName) && itemName.endsWith("_SWORD") && this.random.nextInt(100) <= worldConfig.getInt(Config.FEATURE_SWORD_DAMAGE_CHANCE)) { + if (worldConfig.FEATURE_SWORD_DAMAGE_MOBS.getValue().contains(creatureName) && itemName.endsWith("_SWORD") && this.random.nextInt(100) <= worldConfig.FEATURE_SWORD_DAMAGE_CHANCE.getValue()) { short damage = item.getDurability(); short remove = (short) (item.getType().getMaxDurability() / 50); diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/server/DisabledCommandsListener.java b/src/main/java/com/github/hexosse/bloodmoon/feature/server/DisabledCommandsListener.java similarity index 57% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/server/DisabledCommandsListener.java rename to src/main/java/com/github/hexosse/bloodmoon/feature/server/DisabledCommandsListener.java index a4a896e..734bd25 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/server/DisabledCommandsListener.java +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/server/DisabledCommandsListener.java @@ -1,18 +1,17 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.server; +package com.github.hexosse.bloodmoon.feature.server; +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; import org.bukkit.ChatColor; +import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import uk.co.jacekk.bukkit.baseplugin.event.BaseListener; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; - -public final class DisabledCommandsListener extends BaseListener { - +public final class DisabledCommandsListener extends PluginListener +{ public DisabledCommandsListener(BloodMoon plugin) { super(plugin); } @@ -21,18 +20,18 @@ public DisabledCommandsListener(BloodMoon plugin) { public void onPlayerCommand(PlayerCommandPreprocessEvent event) { Player player = event.getPlayer(); String message = event.getMessage(); - String worldName = player.getWorld().getName(); + World world = player.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); int spaceIndex = message.indexOf(' '); String command = (spaceIndex > 0) ? message.substring(1, spaceIndex) : message.substring(1); - if (plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.DISABLED_COMMANDS)) { - if (plugin.getConfig(worldName).getStringList(Config.FEATURE_DISABLED_COMMANDS_COMMANDS).contains(command)) { + if (plugin.isActive(world) && worldConfig.FEATURE_DISABLED_COMMANDS_ENABLED.getValue()) { + if (plugin.getConfig(world).FEATURE_DISABLED_COMMANDS_COMMANDS.getValue().contains(command)) { event.setCancelled(true); player.sendMessage(ChatColor.RED + "The /" + command + " is disabled during a bloodmoon!"); } } } - } diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/server/ServerCommandsListener.java b/src/main/java/com/github/hexosse/bloodmoon/feature/server/ServerCommandsListener.java similarity index 72% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/server/ServerCommandsListener.java rename to src/main/java/com/github/hexosse/bloodmoon/feature/server/ServerCommandsListener.java index 60d3993..3ae98ed 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/server/ServerCommandsListener.java +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/server/ServerCommandsListener.java @@ -1,24 +1,21 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.server; - -import java.util.logging.Level; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +package com.github.hexosse.bloodmoon.feature.server; +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.bloodmoon.events.BloodMoonEndEvent; +import com.github.hexosse.bloodmoon.events.BloodMoonStartEvent; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; import org.bukkit.World; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.scheduler.BukkitScheduler; -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.baseplugin.event.BaseListener; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonEndEvent; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonStartEvent; - -public class ServerCommandsListener extends BaseListener { +import java.util.logging.Level; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +public class ServerCommandsListener extends PluginListener +{ public ServerCommandsListener(BloodMoon plugin) { super(plugin); } @@ -26,11 +23,10 @@ public ServerCommandsListener(BloodMoon plugin) { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onBloodMoonStart(BloodMoonStartEvent event) { World world = event.getWorld(); - String worldName = world.getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); + WorldConfig worldConfig = plugin.getConfig(world); - if (plugin.isFeatureEnabled(worldName, Feature.SERVER_COMMANDS)) { - for (String command : worldConfig.getStringList(Config.FEATURE_SERVER_COMMANDS_START_COMMANDS)) { + if (worldConfig.FEATURE_SERVER_COMMANDS_ENABLED.getValue()) { + for (String command : worldConfig.FEATURE_SERVER_COMMANDS_START_COMMANDS.getValue()) { if (command.startsWith("(")) { String mydata = command; Pattern pattern = Pattern.compile("^(\\(([^()]*)\\))"); @@ -74,14 +70,12 @@ public void run() { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onBloodMoonStop(BloodMoonEndEvent event) { World world = event.getWorld(); - String worldName = world.getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); + WorldConfig worldConfig = plugin.getConfig(world); - if (plugin.isFeatureEnabled(worldName, Feature.SERVER_COMMANDS)) { - for (String command : worldConfig.getStringList(Config.FEATURE_SERVER_COMMANDS_END_COMMANDS)) { + if (worldConfig.FEATURE_SERVER_COMMANDS_ENABLED.getValue()) { + for (String command : worldConfig.FEATURE_SERVER_COMMANDS_END_COMMANDS.getValue()) { plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), command); } } } - } diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/spawning/GiantsListener.java b/src/main/java/com/github/hexosse/bloodmoon/feature/spawning/GiantsListener.java similarity index 69% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/spawning/GiantsListener.java rename to src/main/java/com/github/hexosse/bloodmoon/feature/spawning/GiantsListener.java index 521ff0a..c8fa4d7 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/spawning/GiantsListener.java +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/spawning/GiantsListener.java @@ -1,22 +1,21 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.spawning; - -import java.util.HashMap; - +package com.github.hexosse.bloodmoon.feature.spawning; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.bloodmoon.events.BloodMoonEndEvent; +import com.github.hexosse.bloodmoon.events.BloodMoonStartEvent; +import com.github.hexosse.bloodmoon.tasks.GiantsTask; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; import org.bukkit.World; -import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import uk.co.jacekk.bukkit.baseplugin.event.BaseListener; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Feature; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonEndEvent; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonStartEvent; - -public class GiantsListener extends BaseListener { +import java.util.HashMap; +public class GiantsListener extends PluginListener +{ private final HashMap worldTasks = new HashMap<>(); public GiantsListener(BloodMoon plugin) { @@ -25,10 +24,11 @@ public GiantsListener(BloodMoon plugin) { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onStart(BloodMoonStartEvent event) { - CraftWorld world = (CraftWorld) event.getWorld(); + World world = event.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); String worldName = world.getName(); - if (plugin.isFeatureEnabled(worldName, Feature.GIANTS)) { + if (worldConfig.FEATURE_GIANTS_ENABLED.getValue()) { int taskID = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new GiantsTask(plugin, world), 0L, 100L); if (taskID != -1) { @@ -55,5 +55,4 @@ public void onEnd(BloodMoonEndEvent event) { } } } - } diff --git a/src/main/java/com/github/hexosse/bloodmoon/feature/spawning/MoreMobsListener.java b/src/main/java/com/github/hexosse/bloodmoon/feature/spawning/MoreMobsListener.java new file mode 100644 index 0000000..b2a2ff0 --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/spawning/MoreMobsListener.java @@ -0,0 +1,29 @@ +package com.github.hexosse.bloodmoon.feature.spawning; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.bloodmoon.events.BloodMoonEndEvent; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; +import org.bukkit.World; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; + +public final class MoreMobsListener extends PluginListener +{ + public MoreMobsListener(BloodMoon plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onStop(BloodMoonEndEvent event) { + World world = event.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + for (LivingEntity entity : world.getLivingEntities()) { + if (worldConfig.FEATURE_SPAWN_CONTROL_SPAWN.getValue().contains(entity.getType().name())) { + entity.remove(); + } + } + } +} diff --git a/src/main/java/com/github/hexosse/bloodmoon/feature/spawning/MoreSpawningListener.java b/src/main/java/com/github/hexosse/bloodmoon/feature/spawning/MoreSpawningListener.java new file mode 100644 index 0000000..51a98b4 --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/spawning/MoreSpawningListener.java @@ -0,0 +1,48 @@ +package com.github.hexosse.bloodmoon.feature.spawning; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.bloodmoon.entity.BloodMoonEntityType; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.EntityType; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; + +import java.util.Random; + +public final class MoreSpawningListener extends PluginListener +{ + private final Random random = new Random(); + + public MoreSpawningListener(BloodMoon plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onCreatureSpawn(CreatureSpawnEvent event) { + if (event.getSpawnReason() != SpawnReason.NATURAL) { //TODO: Should check for Custom instead of checking against natural? + return; + } + + EntityType type = event.getEntityType(); + World world = event.getLocation().getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + if (plugin.isActive(world) && worldConfig.FEATURE_MORE_SPAWNING_ENABLED.getValue() && worldConfig.FEATURE_MORE_SPAWNING_MOBS.getValue().contains(type.getName().toUpperCase())) { + for (int i = 0; i < Math.max(worldConfig.FEATURE_MORE_SPAWNING_MULTIPLIER.getValue(), 1); ++i) { + for (BloodMoonEntityType bloodMoonEntity : BloodMoonEntityType.values()) { + if (type == bloodMoonEntity.getEntityType()) { + Location loc = event.getLocation().add((random.nextDouble() * 3) - 1.5, (random.nextDouble() * 3) - 1.5, (random.nextDouble() * 3) - 1.5); + if(plugin.spawnEntityAllowed(type, loc)) + bloodMoonEntity.spawnEntity(loc); + return; + } + } + } + } + } +} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/spawning/SpawnOnKillListener.java b/src/main/java/com/github/hexosse/bloodmoon/feature/spawning/SpawnOnKillListener.java similarity index 62% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/spawning/SpawnOnKillListener.java rename to src/main/java/com/github/hexosse/bloodmoon/feature/spawning/SpawnOnKillListener.java index 51746ae..1346d2d 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/spawning/SpawnOnKillListener.java +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/spawning/SpawnOnKillListener.java @@ -1,11 +1,10 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.spawning; +package com.github.hexosse.bloodmoon.feature.spawning; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Random; +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.bloodmoon.util.RandomUtils; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; import org.bukkit.World; - import org.bukkit.entity.Creature; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -16,15 +15,13 @@ import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDeathEvent; -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.baseplugin.event.BaseListener; -import uk.co.jacekk.bukkit.baseplugin.util.ListUtils; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; - -public final class SpawnOnKillListener extends BaseListener { +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Random; +public final class SpawnOnKillListener extends PluginListener +{ private static final List playerCauses = Collections.unmodifiableList(new ArrayList(5) { { add(DamageCause.ENTITY_ATTACK); @@ -45,19 +42,18 @@ public SpawnOnKillListener(BloodMoon plugin) { public void onEntityDeath(EntityDeathEvent event) { Entity entity = event.getEntity(); World world = entity.getWorld(); - String worldName = world.getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); + WorldConfig worldConfig = plugin.getConfig(world); - if (entity instanceof Creature && plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.SPAWN_ON_KILL)) { + if (entity instanceof Creature && plugin.isActive(world) && worldConfig.FEATURE_SPAWN_ON_KILL_ENABLED.getValue()) { Creature creature = (Creature) entity; EntityDamageEvent lastDamage = entity.getLastDamageCause(); - if (lastDamage != null && creature.getTarget() instanceof Player && playerCauses.contains(lastDamage.getCause()) && worldConfig.getStringList(Config.FEATURE_SPAWN_ON_KILL_MOBS).contains(creature.getType().name().toUpperCase())) { - if (this.random.nextInt(100) < worldConfig.getInt(Config.FEATURE_SPAWN_ON_KILL_CHANCE)) { - String mobName = ListUtils.getRandom(worldConfig.getStringList(Config.FEATURE_SPAWN_ON_KILL_SPAWN)); + if (lastDamage != null && creature.getTarget() instanceof Player && playerCauses.contains(lastDamage.getCause()) && worldConfig.FEATURE_SPAWN_ON_KILL_MOBS.getValue().contains(creature.getType().name().toUpperCase())) { + if (this.random.nextInt(100) < worldConfig.FEATURE_SPAWN_ON_KILL_CHANCE.getValue()) { + String mobName = RandomUtils.getRandom(worldConfig.FEATURE_SPAWN_ON_KILL_SPAWN.getValue()); EntityType creatureType = EntityType.fromName(mobName.toUpperCase()); - if (creatureType != null) { + if (creatureType != null && plugin.spawnEntityAllowed(creatureType, creature.getLocation())) { world.spawnEntity(creature.getLocation(), creatureType); //world.spawn(creature.getLocation(), creatureType.getEntityClass(), SpawnReason.NATURAL); } @@ -65,5 +61,4 @@ public void onEntityDeath(EntityDeathEvent event) { } } } - } diff --git a/src/main/java/com/github/hexosse/bloodmoon/feature/spawning/SpawnOnSleepListener.java b/src/main/java/com/github/hexosse/bloodmoon/feature/spawning/SpawnOnSleepListener.java new file mode 100644 index 0000000..a354393 --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/spawning/SpawnOnSleepListener.java @@ -0,0 +1,35 @@ +package com.github.hexosse.bloodmoon.feature.spawning; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.bloodmoon.util.RandomUtils; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; +import org.bukkit.World; +import org.bukkit.entity.EntityType; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerBedEnterEvent; + +public final class SpawnOnSleepListener extends PluginListener +{ + public SpawnOnSleepListener(BloodMoon plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onPlayerBedEnter(PlayerBedEnterEvent event) + { + World world = event.getPlayer().getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + if (plugin.isActive(world) && worldConfig.FEATURE_SPAWN_ON_SLEEP_ENABLED.getValue()) { + String mobName = RandomUtils.getRandom(worldConfig.FEATURE_SPAWN_ON_SLEEP_SPAWN.getValue()); + EntityType creatureType = EntityType.fromName(mobName.toUpperCase()); + + if (creatureType != null && plugin.spawnEntityAllowed(creatureType, event.getPlayer().getLocation())) { + //world.spawn(location, creatureType.getEntityClass(), SpawnReason.NATURAL); + world.spawnEntity(event.getPlayer().getLocation(), creatureType); + } + } + } +} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/world/DungeonGenerator.java b/src/main/java/com/github/hexosse/bloodmoon/feature/world/DungeonGenerator.java similarity index 85% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/world/DungeonGenerator.java rename to src/main/java/com/github/hexosse/bloodmoon/feature/world/DungeonGenerator.java index d254ad6..b1a95c4 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/world/DungeonGenerator.java +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/world/DungeonGenerator.java @@ -1,26 +1,25 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.world; - -import net.minecraft.server.v1_8_R3.MobSpawnerAbstract; -import net.minecraft.server.v1_8_R3.TileEntityMobSpawner; +package com.github.hexosse.bloodmoon.feature.world; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.bloodmoon.events.DungeonChestFillEvent; +import com.github.hexosse.bloodmoon.util.RandomUtils; +import com.github.hexosse.pluginframework.pluginapi.reflexion.Reflexion; +import net.minecraft.server.v1_10_R1.MobSpawnerAbstract; +import net.minecraft.server.v1_10_R1.TileEntityMobSpawner; import org.bukkit.Chunk; import org.bukkit.Material; import org.bukkit.TreeSpecies; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.Chest; -import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; +import org.bukkit.craftbukkit.v1_10_R1.CraftWorld; import org.bukkit.entity.EntityType; import org.bukkit.generator.BlockPopulator; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.material.Step; import org.bukkit.material.WoodenStep; -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.baseplugin.util.ListUtils; -import uk.co.jacekk.bukkit.baseplugin.util.ReflectionUtils; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.event.DungeonChestFillEvent; import java.util.Random; @@ -33,11 +32,12 @@ public DungeonGenerator(BloodMoon plugin) { } @Override - public void populate(World world, Random random, Chunk chunk) { + public void populate(World world, Random random, Chunk chunk) + { int gridX = (int) (Math.floor(chunk.getX() / 10.0d) * 10); int gridZ = (int) (Math.floor(chunk.getZ() / 10.0d) * 10); - PluginConfig worldConfig = plugin.getConfig(world.getName()); + WorldConfig worldConfig = plugin.getConfig(world); DungeonProperties properties = new DungeonProperties(world, worldConfig, gridX, gridZ); @@ -149,7 +149,7 @@ public void populate(World world, Random random, Chunk chunk) { }; for (Block block : spawners) { - EntityType type = EntityType.valueOf(ListUtils.getRandom(worldConfig.getStringList(Config.FEATURE_DUNGEONS_SPAWNER_TYPES))); + EntityType type = EntityType.valueOf(RandomUtils.getRandom(worldConfig.FEATURE_DUNGEONS_SPAWNER_TYPES.getValue())); if (type != null) { block.setTypeIdAndData(Material.MOB_SPAWNER.getId(), (byte) 0, false); @@ -158,11 +158,11 @@ public void populate(World world, Random random, Chunk chunk) { spawner.setMobName(type.getName()); try { - ReflectionUtils.setFieldValue(MobSpawnerAbstract.class, "minSpawnDelay", spawner, worldConfig.getInt(Config.FEATURE_DUNGEONS_SPAWNER_DELAY)); - ReflectionUtils.setFieldValue(MobSpawnerAbstract.class, "maxSpawnDelay", spawner, worldConfig.getInt(Config.FEATURE_DUNGEONS_SPAWNER_DELAY)); - ReflectionUtils.setFieldValue(MobSpawnerAbstract.class, "spawnCount", spawner, worldConfig.getInt(Config.FEATURE_DUNGEONS_SPAWNER_COUNT)); - ReflectionUtils.setFieldValue(MobSpawnerAbstract.class, "maxNearbyEntities", spawner, worldConfig.getInt(Config.FEATURE_DUNGEONS_SPAWNER_MAX_MOBS)); - ReflectionUtils.setFieldValue(MobSpawnerAbstract.class, "spawnRange", spawner, 4); + Reflexion.getField(MobSpawnerAbstract.class, "minSpawnDelay").set(spawner, worldConfig.FEATURE_DUNGEONS_SPAWNER_DELAY.getValue()); + Reflexion.getField(MobSpawnerAbstract.class, "maxSpawnDelay").set(spawner, worldConfig.FEATURE_DUNGEONS_SPAWNER_DELAY.getValue()); + Reflexion.getField(MobSpawnerAbstract.class, "spawnCount").set(spawner, worldConfig.FEATURE_DUNGEONS_SPAWNER_COUNT.getValue()); + Reflexion.getField(MobSpawnerAbstract.class, "maxNearbyEntities").set(spawner, worldConfig.FEATURE_DUNGEONS_SPAWNER_MAX_MOBS.getValue()); + Reflexion.getField(MobSpawnerAbstract.class, "spawnRange").set(spawner, 4); } catch (Exception e) { e.printStackTrace(); } @@ -263,14 +263,14 @@ public void populate(World world, Random random, Chunk chunk) { for (Chest chest : chests) { Inventory inv = chest.getInventory(); - for (int i = 0; i < worldConfig.getInt(Config.FEATURE_DUNGEONS_ITEMS_PER_CHEST); ++i) { - Material type = Material.getMaterial(ListUtils.getRandom(worldConfig.getStringList(Config.FEATURE_DUNGEONS_CHEST_ITEMS))); + for (int i = 0; i < worldConfig.FEATURE_DUNGEONS_ITEMS_PER_CHEST.getValue(); ++i) { + Material type = Material.getMaterial(RandomUtils.getRandom(worldConfig.FEATURE_DUNGEONS_CHEST_ITEMS.getValue())); if (type != null) { ItemStack item = new ItemStack(type); - //item.setAmount(Math.min(type.getMaxStackSize(), rand.nextInt(worldConfig.getInt(Config.FEATURE_DUNGEONS_MAX_STACK_SIZE)))); - int low = worldConfig.getInt(Config.FEATURE_DUNGEONS_MIN_STACK_SIZE); - int high = worldConfig.getInt(Config.FEATURE_DUNGEONS_MAX_STACK_SIZE); + //item.setAmount(Math.min(type.getMaxStackSize(), rand.nextInt(worldConfig.getInt(WorldConfig.FEATURE_DUNGEONS_MAX_STACK_SIZE)))); + int low = worldConfig.FEATURE_DUNGEONS_MIN_STACK_SIZE.getValue(); + int high = worldConfig.FEATURE_DUNGEONS_MAX_STACK_SIZE.getValue(); Random randomSam = new Random(); int randomInt = randomSam.nextInt((high + 1) - low) + low; item.setAmount(randomInt); diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/world/DungeonListener.java b/src/main/java/com/github/hexosse/bloodmoon/feature/world/DungeonListener.java similarity index 66% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/world/DungeonListener.java rename to src/main/java/com/github/hexosse/bloodmoon/feature/world/DungeonListener.java index 611d733..218f8ef 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/world/DungeonListener.java +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/world/DungeonListener.java @@ -1,14 +1,9 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.world; +package com.github.hexosse.bloodmoon.feature.world; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import org.bukkit.ChatColor; -import org.bukkit.Chunk; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -21,13 +16,12 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.world.WorldInitEvent; -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.baseplugin.event.BaseListener; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; -public class DungeonListener extends BaseListener { +public class DungeonListener extends PluginListener +{ public DungeonListener(BloodMoon plugin) { super(plugin); @@ -36,9 +30,9 @@ public DungeonListener(BloodMoon plugin) { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onWorldInit(WorldInitEvent event) { World world = event.getWorld(); - String worldName = world.getName(); + WorldConfig worldConfig = plugin.getConfig(world); - if (plugin.isEnabled(worldName) && plugin.isFeatureEnabled(worldName, Feature.DUNGEONS)) { + if (plugin.isEnabled(world) && worldConfig.FEATURE_DUNGEONS_ENABLED.getValue()) { world.getPopulators().add(new DungeonGenerator(plugin)); } } @@ -47,7 +41,7 @@ private boolean isProtected(Location location) { Chunk chunk = location.getChunk(); World world = location.getWorld(); - PluginConfig worldConfig = plugin.getConfig(world.getName()); + WorldConfig worldConfig = plugin.getConfig(world); int gridX = (int) (Math.floor(chunk.getX() / 10.0d) * 10); int gridZ = (int) (Math.floor(chunk.getZ() / 10.0d) * 10); @@ -84,14 +78,14 @@ private boolean isProtected(Location location) { public void onPlayerCommand(PlayerCommandPreprocessEvent event) { Player player = event.getPlayer(); String message = event.getMessage(); - String worldName = player.getWorld().getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); + World world = player.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); int spaceIndex = message.indexOf(' '); String command = (spaceIndex > 0) ? message.substring(1, spaceIndex) : message.substring(1); - if (plugin.isFeatureEnabled(worldName, Feature.DISABLED_COMMANDS) && worldConfig.getStringList(Config.FEATURE_DISABLED_COMMANDS_COMMANDS).contains(command) && this.isProtected(player.getLocation())) { + if (worldConfig.FEATURE_DISABLED_COMMANDS_ENABLED.getValue() && worldConfig.FEATURE_DISABLED_COMMANDS_COMMANDS.getValue().contains(command) && this.isProtected(player.getLocation())) { event.setCancelled(true); player.sendMessage(ChatColor.RED + "The /" + command + " is disabled in bloodmoon dungeons!"); } @@ -101,12 +95,11 @@ public void onPlayerCommand(PlayerCommandPreprocessEvent event) { public void onBlockBreak(BlockBreakEvent event) { Block block = event.getBlock(); World world = block.getWorld(); - String worldName = world.getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); + WorldConfig worldConfig = plugin.getConfig(world); List allowed = Arrays.asList(Material.IRON_FENCE, Material.MOB_SPAWNER, Material.COBBLE_WALL); - if (plugin.isEnabled(worldName) && worldConfig.getBoolean(Config.FEATURE_DUNGEONS_PROTECTED) && !allowed.contains(block.getType()) && this.isProtected(block.getLocation())) { + if (plugin.isEnabled(world) && worldConfig.FEATURE_DUNGEONS_PROTECTED.getValue() && !allowed.contains(block.getType()) && this.isProtected(block.getLocation())) { event.setCancelled(true); } } @@ -116,10 +109,10 @@ public void onEntityExplode(EntityExplodeEvent event) { List blocks = event.blockList(); if (!blocks.isEmpty()) { - String worldName = blocks.get(0).getWorld().getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); + World world = blocks.get(0).getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); - if (plugin.isEnabled(worldName) && worldConfig.getBoolean(Config.FEATURE_DUNGEONS_PROTECTED)) { + if (plugin.isEnabled(world) && worldConfig.FEATURE_DUNGEONS_PROTECTED.getValue()) { Iterator iterator = blocks.iterator(); while (iterator.hasNext()) { @@ -136,10 +129,9 @@ public void onEntityExplode(EntityExplodeEvent event) { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onPistonExtend(BlockPistonExtendEvent event) { World world = event.getBlock().getWorld(); - String worldName = world.getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); + WorldConfig worldConfig = plugin.getConfig(world); - if (plugin.isEnabled(worldName) && worldConfig.getBoolean(Config.FEATURE_DUNGEONS_PROTECTED)) { + if (plugin.isEnabled(world) && worldConfig.FEATURE_DUNGEONS_PROTECTED.getValue()) { for (Block moved : event.getBlocks()) { if (this.isProtected(moved.getLocation())) { event.setCancelled(true); @@ -152,10 +144,9 @@ public void onPistonExtend(BlockPistonExtendEvent event) { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onPistonRetract(BlockPistonRetractEvent event) { World world = event.getBlock().getWorld(); - String worldName = world.getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); + WorldConfig worldConfig = plugin.getConfig(world); - if (plugin.isEnabled(worldName) && worldConfig.getBoolean(Config.FEATURE_DUNGEONS_PROTECTED)) { + if (plugin.isEnabled(world) && worldConfig.FEATURE_DUNGEONS_PROTECTED.getValue()) { if (this.isProtected(event.getRetractLocation())) { event.setCancelled(true); } @@ -166,12 +157,11 @@ public void onPistonRetract(BlockPistonRetractEvent event) { public void onBlockPlace(BlockPlaceEvent event) { Block block = event.getBlock(); World world = block.getWorld(); - String worldName = world.getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); + WorldConfig worldConfig = plugin.getConfig(world); List allowed = Arrays.asList(Material.TORCH); - if (plugin.isEnabled(worldName) && worldConfig.getBoolean(Config.FEATURE_DUNGEONS_PROTECTED) && !allowed.contains(block.getType()) && this.isProtected(block.getLocation())) { + if (plugin.isEnabled(world) && worldConfig.FEATURE_DUNGEONS_PROTECTED.getValue() && !allowed.contains(block.getType()) && this.isProtected(block.getLocation())) { event.setCancelled(true); } } diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/world/DungeonProperties.java b/src/main/java/com/github/hexosse/bloodmoon/feature/world/DungeonProperties.java similarity index 75% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/world/DungeonProperties.java rename to src/main/java/com/github/hexosse/bloodmoon/feature/world/DungeonProperties.java index 021859e..95a81f9 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/world/DungeonProperties.java +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/world/DungeonProperties.java @@ -1,24 +1,22 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.world; - -import java.util.Random; +package com.github.hexosse.bloodmoon.feature.world; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.block.Biome; -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.bloodmoon.Config; +import java.util.Random; public class DungeonProperties { private final World world; - private final PluginConfig worldConfig; + private final WorldConfig worldConfig; private int gridX, gridZ; private int chunkX, chunkZ; private int layers; - public DungeonProperties(World world, PluginConfig worldConfig, int gridX, int gridZ) { + public DungeonProperties(World world, WorldConfig worldConfig, int gridX, int gridZ) { this.world = world; this.worldConfig = worldConfig; this.gridX = gridX; @@ -29,8 +27,8 @@ public DungeonProperties(World world, PluginConfig worldConfig, int gridX, int g this.chunkX = this.gridX + random.nextInt(10); this.chunkZ = this.gridZ + random.nextInt(10); - int minLayers = worldConfig.getInt(Config.FEATURE_DUNGEONS_MIN_LAYERS); - int maxLayers = worldConfig.getInt(Config.FEATURE_DUNGEONS_MAX_LAYERS); + int minLayers = worldConfig.FEATURE_DUNGEONS_MIN_LAYERS.getValue(); + int maxLayers = worldConfig.FEATURE_DUNGEONS_MAX_LAYERS.getValue(); this.layers = random.nextInt(maxLayers - minLayers) + minLayers; } @@ -85,11 +83,11 @@ public boolean isInChunk(Chunk chunk) { Biome biome = this.world.getBiome((this.chunkX * 16) + 8, (this.chunkZ * 16) + 8); - if (!this.worldConfig.getStringList(Config.FEATURE_DUNGEONS_BIOMES).contains(biome.name())) { + if (!this.worldConfig.FEATURE_DUNGEONS_BIOMES.getValue().contains(biome.name())) { return false; } - if (this.getRandom().nextInt(100) > this.worldConfig.getInt(Config.FEATURE_DUNGEONS_CHANCE)) { + if (this.getRandom().nextInt(100) > this.worldConfig.FEATURE_DUNGEONS_CHANCE.getValue()) { return false; } diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/world/ExtendedNightListener.java b/src/main/java/com/github/hexosse/bloodmoon/feature/world/ExtendedNightListener.java similarity index 62% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/world/ExtendedNightListener.java rename to src/main/java/com/github/hexosse/bloodmoon/feature/world/ExtendedNightListener.java index 4a60c81..ac364e0 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/world/ExtendedNightListener.java +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/world/ExtendedNightListener.java @@ -1,23 +1,21 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.world; - -import java.util.ArrayList; -import java.util.HashMap; +package com.github.hexosse.bloodmoon.feature.world; +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.bloodmoon.events.BloodMoonEndEvent; +import com.github.hexosse.bloodmoon.events.BloodMoonStartEvent; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; import org.bukkit.World; import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDeathEvent; -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.baseplugin.event.BaseListener; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonEndEvent; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonStartEvent; +import java.util.ArrayList; +import java.util.HashMap; -public class ExtendedNightListener extends BaseListener { +public class ExtendedNightListener extends PluginListener +{ private final HashMap killCount = new HashMap<>(); private final ArrayList hostileTypes = new ArrayList() { @@ -47,14 +45,13 @@ public ExtendedNightListener(BloodMoon plugin) { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onStart(BloodMoonStartEvent event) { World world = event.getWorld(); - String worldName = world.getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); + WorldConfig worldConfig = plugin.getConfig(world); - if (plugin.isFeatureEnabled(worldName, Feature.EXTENDED_NIGHT)) { + if (worldConfig.FEATURE_EXTENDED_NIGHT_ENABLED.getValue()) { world.setGameRuleValue("doDaylightCycle", "false"); - if (!worldConfig.getBoolean(Config.ALWAYS_ON)) { - killCount.put(worldName, 0); + if (!worldConfig.ALWAYS_ON.getValue()) { + killCount.put(world.getName(), 0); } } } @@ -62,10 +59,10 @@ public void onStart(BloodMoonStartEvent event) { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onStop(BloodMoonEndEvent event) { World world = event.getWorld(); - String worldName = world.getName(); + WorldConfig worldConfig = plugin.getConfig(world); - if (plugin.isFeatureEnabled(worldName, Feature.EXTENDED_NIGHT)) { - killCount.remove(worldName); + if (worldConfig.FEATURE_EXTENDED_NIGHT_ENABLED.getValue()) { + killCount.remove(world.getName()); world.setGameRuleValue("doDaylightCycle", "true"); } } @@ -75,12 +72,12 @@ public void onEntityDeath(EntityDeathEvent event) { if (hostileTypes.contains(event.getEntityType())) { World world = event.getEntity().getWorld(); String worldName = world.getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); + WorldConfig worldConfig = plugin.getConfig(world); - if (plugin.isFeatureEnabled(worldName, Feature.EXTENDED_NIGHT) && killCount.containsKey(worldName)) { + if (worldConfig.FEATURE_EXTENDED_NIGHT_ENABLED.getValue() && killCount.containsKey(worldName)) { killCount.put(worldName, killCount.get(worldName) + 1); - if (killCount.get(worldName) > worldConfig.getInt(Config.FEATURE_EXTENDED_NIGHT_MIN_KILLS)) { + if (killCount.get(worldName) > worldConfig.FEATURE_EXTENDED_NIGHT_MIN_KILLS.getValue()) { world.setGameRuleValue("doDaylightCycle", "true"); } } diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/world/LockInWorldListener.java b/src/main/java/com/github/hexosse/bloodmoon/feature/world/LockInWorldListener.java similarity index 63% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/world/LockInWorldListener.java rename to src/main/java/com/github/hexosse/bloodmoon/feature/world/LockInWorldListener.java index 2cbfcee..1d1f7dc 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/world/LockInWorldListener.java +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/world/LockInWorldListener.java @@ -1,5 +1,9 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.world; +package com.github.hexosse.bloodmoon.feature.world; +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.Permissions; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.World; @@ -10,25 +14,25 @@ import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerTeleportEvent; -import uk.co.jacekk.bukkit.baseplugin.event.BaseListener; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Feature; -import uk.co.jacekk.bukkit.bloodmoon.Permission; +import static com.github.hexosse.bloodmoon.configuration.Permissions.ADMIN_IGNORE_WORLD_LOCK; -public class LockInWorldListener extends BaseListener { +public class LockInWorldListener extends PluginListener +{ public LockInWorldListener(BloodMoon plugin) { super(plugin); } - private boolean canTeleport(Player player, World from, World to) { - String worldName = from.getName(); + private boolean canTeleport(Player player, World from, World to) + { + WorldConfig worldConfig = plugin.getConfig(from); - return (player.hasPermission(Permission.ADMIN_IGNORE_WORLD_LOCK) || from.equals(to) || !plugin.isActive(worldName) || !plugin.isFeatureEnabled(worldName, Feature.LOCK_IN_WORLD)); + return (Permissions.has(player,ADMIN_IGNORE_WORLD_LOCK) || from.equals(to) || !plugin.isActive(from) || !worldConfig.FEATURE_LOCK_IN_WORLD_ENABLED.getValue()); } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onPlayerTeleport(PlayerTeleportEvent event) { + public void onPlayerTeleport(PlayerTeleportEvent event) + { Player player = event.getPlayer(); Location from = event.getFrom(); Location to = event.getTo(); @@ -40,12 +44,14 @@ public void onPlayerTeleport(PlayerTeleportEvent event) { } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onPlayerPortal(PlayerPortalEvent event) { + public void onPlayerPortal(PlayerPortalEvent event) + { this.onPlayerTeleport(event); } @EventHandler(priority = EventPriority.NORMAL) - public void onPlayerRespawn(PlayerRespawnEvent event) { + public void onPlayerRespawn(PlayerRespawnEvent event) + { Player player = event.getPlayer(); World fromWorld = player.getWorld(); World toWorld = event.getRespawnLocation().getWorld(); diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/world/NetherSkyListener.java b/src/main/java/com/github/hexosse/bloodmoon/feature/world/NetherSkyListener.java similarity index 62% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/world/NetherSkyListener.java rename to src/main/java/com/github/hexosse/bloodmoon/feature/world/NetherSkyListener.java index 37c9140..93d27aa 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/world/NetherSkyListener.java +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/world/NetherSkyListener.java @@ -1,16 +1,19 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.world; - -import net.minecraft.server.v1_8_R3.EnumDifficulty; -//import net.minecraft.server.v1_8_R2.EnumGamemode; -import net.minecraft.server.v1_8_R3.PacketPlayOutRespawn; -import net.minecraft.server.v1_8_R3.WorldSettings; -import net.minecraft.server.v1_8_R3.WorldType; - +package com.github.hexosse.bloodmoon.feature.world; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.bloodmoon.events.BloodMoonEndEvent; +import com.github.hexosse.bloodmoon.events.BloodMoonStartEvent; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; +import net.minecraft.server.v1_10_R1.EnumDifficulty; +import net.minecraft.server.v1_10_R1.PacketPlayOutRespawn; +import net.minecraft.server.v1_10_R1.WorldSettings; +import net.minecraft.server.v1_10_R1.WorldType; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.World.Environment; -import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_10_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -18,13 +21,8 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerRespawnEvent; -import uk.co.jacekk.bukkit.baseplugin.event.BaseListener; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Feature; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonEndEvent; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonStartEvent; - -public class NetherSkyListener extends BaseListener { +public class NetherSkyListener extends PluginListener +{ public NetherSkyListener(BloodMoon plugin) { super(plugin); @@ -35,7 +33,7 @@ private void sendWorldEnvironment(Player player, Environment environment) { CraftWorld world = (CraftWorld) player.getWorld(); Location location = player.getLocation(); - PacketPlayOutRespawn packet = new PacketPlayOutRespawn(environment.getId(), EnumDifficulty.getById(world.getDifficulty().getValue()), WorldType.NORMAL, WorldSettings.EnumGamemode.getById(player.getGameMode().getValue())); + PacketPlayOutRespawn packet = new PacketPlayOutRespawn(environment.getId(), EnumDifficulty.getById(world.getDifficulty().getValue()), WorldType.NORMAL, WorldSettings.a(player.getGameMode().getValue())); craftPlayer.getHandle().playerConnection.sendPacket(packet); @@ -57,10 +55,11 @@ private void sendWorldEnvironment(Player player, Environment environment) { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onStart(BloodMoonStartEvent event) { - String worldName = event.getWorld().getName(); + World world = event.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); - if (plugin.isFeatureEnabled(worldName, Feature.NETHER_SKY)) { - for (Player player : event.getWorld().getPlayers()) { + if (worldConfig.FEATURE_NETHER_SKY_ENABLED.getValue()) { + for (Player player : world.getPlayers()) { this.sendWorldEnvironment(player, Environment.NETHER); } } @@ -70,9 +69,9 @@ public void onStart(BloodMoonStartEvent event) { public void onStop(BloodMoonEndEvent event) { World world = event.getWorld(); Environment environment = world.getEnvironment(); - String worldName = world.getName(); + WorldConfig worldConfig = plugin.getConfig(world); - if (plugin.isFeatureEnabled(worldName, Feature.NETHER_SKY)) { + if (worldConfig.FEATURE_NETHER_SKY_ENABLED.getValue()) { for (Player player : event.getWorld().getPlayers()) { this.sendWorldEnvironment(player, environment); } @@ -81,18 +80,20 @@ public void onStop(BloodMoonEndEvent event) { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onJoin(PlayerJoinEvent event) { - String worldName = event.getPlayer().getWorld().getName(); + World world = event.getPlayer().getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); - if (plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.NETHER_SKY)) { + if (plugin.isActive(world) && worldConfig.FEATURE_NETHER_SKY_ENABLED.getValue()) { this.sendWorldEnvironment(event.getPlayer(), Environment.NETHER); } } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onRespawn(final PlayerRespawnEvent event) { - String worldName = event.getPlayer().getWorld().getName(); + World world = event.getPlayer().getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); - if (plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.NETHER_SKY)) { + if (plugin.isActive(world) && worldConfig.FEATURE_NETHER_SKY_ENABLED.getValue()) { plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() { @Override @@ -106,9 +107,10 @@ public void run() { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onChangeWorlds(PlayerChangedWorldEvent event) { - String worldName = event.getPlayer().getWorld().getName(); + World world = event.getPlayer().getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); - if (plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.NETHER_SKY)) { + if (plugin.isActive(world) && worldConfig.FEATURE_NETHER_SKY_ENABLED.getValue()) { this.sendWorldEnvironment(event.getPlayer(), Environment.NETHER); } } diff --git a/src/main/java/com/github/hexosse/bloodmoon/feature/world/WeatherListener.java b/src/main/java/com/github/hexosse/bloodmoon/feature/world/WeatherListener.java new file mode 100644 index 0000000..dafcf7e --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/feature/world/WeatherListener.java @@ -0,0 +1,65 @@ +package com.github.hexosse.bloodmoon.feature.world; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.bloodmoon.events.BloodMoonEndEvent; +import com.github.hexosse.bloodmoon.events.BloodMoonStartEvent; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; +import org.bukkit.World; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.weather.WeatherChangeEvent; + +import java.util.Random; + +public class WeatherListener extends PluginListener +{ + + private final Random random = new Random(); + + public WeatherListener(BloodMoon plugin) + { + super(plugin); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onStart(BloodMoonStartEvent event) + { + World world = event.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + if(worldConfig.FEATURE_WEATHER_ENABLED.getValue() && random.nextInt(100) < worldConfig.FEATURE_WEATHER_CHANCE.getValue()) + { + world.setStorm(worldConfig.FEATURE_WEATHER_RAIN.getValue()); + world.setThundering(worldConfig.FEATURE_WEATHER_THUNDER.getValue()); + + world.setWeatherDuration(10000); + world.setThunderDuration(10000); + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onStop(BloodMoonEndEvent event) + { + World world = event.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + if(worldConfig.FEATURE_WEATHER_ENABLED.getValue()) + { + world.setThundering(false); + world.setStorm(false); + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onWeatherChange(WeatherChangeEvent event) + { + World world = event.getWorld(); + WorldConfig worldConfig = plugin.getConfig(world); + + if(plugin.isActive(world) && worldConfig.FEATURE_WEATHER_ENABLED.getValue()) + { + event.setCancelled(true); + } + } +} diff --git a/src/main/java/com/github/hexosse/bloodmoon/integrations/Factions.java b/src/main/java/com/github/hexosse/bloodmoon/integrations/Factions.java new file mode 100644 index 0000000..0b406a6 --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/integrations/Factions.java @@ -0,0 +1,100 @@ +package com.github.hexosse.bloodmoon.integrations; + +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.massivecore.ps.PS; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.EntityType; +import org.bukkit.plugin.PluginManager; + +/** + * This file is part of bloodmoon + * + * @author hexosse (hexosse on GitHub). + */ +public class Factions +{ + private static com.massivecraft.factions.Factions factions = null; + + /** + * @return factions plugin instance + */ + public static com.massivecraft.factions.Factions hookFactionsPlugin() + { + if(Factions.getPlugin()!=null) + return Factions.getPlugin(); + + PluginManager pm = Bukkit.getServer().getPluginManager(); + com.massivecraft.factions.Factions factions = (com.massivecraft.factions.Factions)pm.getPlugin("Factions"); + if(factions != null && pm.isPluginEnabled(factions)) + { + Factions.setPlugin(factions); + return factions; + } + else return null; + } + + /** + * @param plugin The factions plugin that this object belong to. + */ + public static void setPlugin(com.massivecraft.factions.Factions plugin) + { + factions = plugin; + } + + /** + * @return The factions plugin that this object belong to. + */ + public static com.massivecraft.factions.Factions getPlugin() + { + return factions; + } + + /** + * @param type Entity to spawn + * @param location Location of spawn + * @return true if an entity can spawn at location + */ + public static boolean spawnEntityAllowed(EntityType type, Location location) + { + if(factions==null) + return true; + + // ... get the spawn location ... + if (location == null) return true; + PS ps = PS.valueOf(location); + + // ... get the faction there ... + Faction faction = BoardColl.get().getFactionAt(ps); + if (faction == null) return true; + + // ... and if this type can't spawn in the faction ... + if (canSpawn(faction, type)) return true; + + return false; + } + + /** + * @return true if an entity can spawn in the faction. + */ + protected static boolean canSpawn(Faction faction, EntityType type) + { + if (MConf.get().entityTypesMonsters.contains(type)) + { + // Monster + return faction.getFlag(MFlag.getFlagMonsters()); + } + else if (MConf.get().entityTypesAnimals.contains(type)) + { + // Animal + return faction.getFlag(MFlag.getFlagAnimals()); + } + else + { + // Other + return true; + } + }} diff --git a/src/main/java/com/github/hexosse/bloodmoon/listeners/SpawnReasonListener.java b/src/main/java/com/github/hexosse/bloodmoon/listeners/SpawnReasonListener.java new file mode 100644 index 0000000..bf7ced2 --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/listeners/SpawnReasonListener.java @@ -0,0 +1,22 @@ +package com.github.hexosse.bloodmoon.listeners; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.metadata.FixedMetadataValue; + +public class SpawnReasonListener extends PluginListener +{ + public SpawnReasonListener(BloodMoon plugin) + { + super(plugin); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onCreatureSpawn(CreatureSpawnEvent event) + { + event.getEntity().setMetadata("spawn-reason", new FixedMetadataValue(plugin, event.getSpawnReason())); + } +} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/WorldInitListener.java b/src/main/java/com/github/hexosse/bloodmoon/listeners/WorldInitListener.java similarity index 76% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/WorldInitListener.java rename to src/main/java/com/github/hexosse/bloodmoon/listeners/WorldInitListener.java index f8227be..7f0d9f3 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/WorldInitListener.java +++ b/src/main/java/com/github/hexosse/bloodmoon/listeners/WorldInitListener.java @@ -1,27 +1,31 @@ -package uk.co.jacekk.bukkit.bloodmoon; +package com.github.hexosse.bloodmoon.listeners; //import net.minecraft.server.v1_8_R1.IChunkLoader; //import net.minecraft.server.v1_8_R1.WorldServer; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.pluginframework.pluginapi.PluginListener; import org.bukkit.World; -//import org.bukkit.craftbukkit.v1_8_R1.CraftWorld; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.world.WorldInitEvent; -import uk.co.jacekk.bukkit.baseplugin.event.BaseListener; -//import uk.co.jacekk.bukkit.baseplugin.util.ReflectionUtils; -//import uk.co.jacekk.bukkit.bloodmoon.nms.ChunkProviderServer; +//import org.bukkit.craftbukkit.v1_8_R1.CraftWorld; +// +//import com.github.hexosse.bloodmoon.nms.ChunkProviderServer; -public class WorldInitListener extends BaseListener { +public class WorldInitListener extends PluginListener +{ - public WorldInitListener(BloodMoon plugin) { + public WorldInitListener(BloodMoon plugin) + { super(plugin); } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onWorldInit(WorldInitEvent event) { + public void onWorldInit(WorldInitEvent event) + { World world = event.getWorld(); - plugin.createConfig(world); /*if (plugin.isFeatureEnabled(world.getName(), Feature.SPAWN_CONTROL)){ diff --git a/src/main/java/com/github/hexosse/bloodmoon/nms/ChunkProviderServer.java b/src/main/java/com/github/hexosse/bloodmoon/nms/ChunkProviderServer.java new file mode 100644 index 0000000..16a6695 --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/nms/ChunkProviderServer.java @@ -0,0 +1,35 @@ +package com.github.hexosse.bloodmoon.nms; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import net.minecraft.server.v1_10_R1.*; +import org.bukkit.entity.EntityType; + +import java.util.ArrayList; +import java.util.List; + +public class ChunkProviderServer extends net.minecraft.server.v1_10_R1.ChunkProviderServer { + + private final BloodMoon plugin; + private final List bloodMoonMobs = new ArrayList<>(); + + public ChunkProviderServer(BloodMoon plugin, WorldServer worldserver, IChunkLoader ichunkloader, ChunkGenerator chunkgenerator) { + super(worldserver, ichunkloader, chunkgenerator); + + this.plugin = plugin; + + WorldConfig worldConfig = this.plugin.getConfig(this.world.worldData.world.getWorld()); + + for (String name : worldConfig.FEATURE_SPAWN_CONTROL_SPAWN.getValue()) { + Class entityClass = EntityTypes.a(EntityType.valueOf(name).getTypeId()); + this.bloodMoonMobs.add(new BiomeBase.BiomeMeta((Class) entityClass, 10, 4, 4)); // Entity class, weight, minGroupSize, maxGroupSize + } + } + + @SuppressWarnings("unchecked") + public List getMobsFor(EnumCreatureType creatureType, int x, int y, int z) { +// return (this.plugin.isActive(this.world.worldData.getName())) ? this.bloodMoonMobs : super.getMobsFor(creatureType, new BlockPosition(x, y, z)); + return (this.plugin.isActive(this.world.worldData.world.getWorld())) ? this.bloodMoonMobs : super.chunkGenerator.getMobsFor(creatureType, new BlockPosition(x, y, z)); + } + +} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntityBlaze.java b/src/main/java/com/github/hexosse/bloodmoon/nms/EntityBlaze.java similarity index 64% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntityBlaze.java rename to src/main/java/com/github/hexosse/bloodmoon/nms/EntityBlaze.java index a91698f..41d89be 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntityBlaze.java +++ b/src/main/java/com/github/hexosse/bloodmoon/nms/EntityBlaze.java @@ -1,15 +1,15 @@ -package uk.co.jacekk.bukkit.bloodmoon.nms; +package com.github.hexosse.bloodmoon.nms; -import net.minecraft.server.v1_8_R3.World; +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.entity.BloodMoonEntityBlaze; +import com.github.hexosse.bloodmoon.entity.BloodMoonEntityType; +import net.minecraft.server.v1_10_R1.World; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_8_R3.CraftServer; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftBlaze; +import org.bukkit.craftbukkit.v1_10_R1.CraftServer; +import org.bukkit.craftbukkit.v1_10_R1.entity.CraftBlaze; import org.bukkit.plugin.Plugin; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.entity.BloodMoonEntityBlaze; -import uk.co.jacekk.bukkit.bloodmoon.entity.BloodMoonEntityType; -public class EntityBlaze extends net.minecraft.server.v1_8_R3.EntityBlaze { +public class EntityBlaze extends net.minecraft.server.v1_10_R1.EntityBlaze { private BloodMoon plugin; private BloodMoonEntityBlaze bloodMoonEntity; @@ -31,10 +31,10 @@ public EntityBlaze(World world) { } @Override - public boolean bM() { + public boolean ct() { try { this.bloodMoonEntity.onTick(); - super.bL(); + super.co(); } catch (Exception e) { plugin.getLogger().warning("Exception caught while ticking entity"); e.printStackTrace(); diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntityCreeper.java b/src/main/java/com/github/hexosse/bloodmoon/nms/EntityCreeper.java similarity index 64% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntityCreeper.java rename to src/main/java/com/github/hexosse/bloodmoon/nms/EntityCreeper.java index d0c0204..f9041d8 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntityCreeper.java +++ b/src/main/java/com/github/hexosse/bloodmoon/nms/EntityCreeper.java @@ -1,15 +1,15 @@ -package uk.co.jacekk.bukkit.bloodmoon.nms; +package com.github.hexosse.bloodmoon.nms; -import net.minecraft.server.v1_8_R3.World; +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.entity.BloodMoonEntityCreeper; +import com.github.hexosse.bloodmoon.entity.BloodMoonEntityType; +import net.minecraft.server.v1_10_R1.World; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_8_R3.CraftServer; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftCreeper; +import org.bukkit.craftbukkit.v1_10_R1.CraftServer; +import org.bukkit.craftbukkit.v1_10_R1.entity.CraftCreeper; import org.bukkit.plugin.Plugin; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.entity.BloodMoonEntityCreeper; -import uk.co.jacekk.bukkit.bloodmoon.entity.BloodMoonEntityType; -public class EntityCreeper extends net.minecraft.server.v1_8_R3.EntityCreeper { +public class EntityCreeper extends net.minecraft.server.v1_10_R1.EntityCreeper { private BloodMoon plugin; private BloodMoonEntityCreeper bloodMoonEntity; @@ -31,10 +31,10 @@ public EntityCreeper(World world) { } @Override - public boolean bM() { + public boolean ct() { try { this.bloodMoonEntity.onTick(); - super.bL(); + super.co(); } catch (Exception e) { plugin.getLogger().warning("Exception caught while ticking entity"); e.printStackTrace(); diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntityEnderman.java b/src/main/java/com/github/hexosse/bloodmoon/nms/EntityEnderman.java similarity index 65% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntityEnderman.java rename to src/main/java/com/github/hexosse/bloodmoon/nms/EntityEnderman.java index d052b01..f1dad35 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntityEnderman.java +++ b/src/main/java/com/github/hexosse/bloodmoon/nms/EntityEnderman.java @@ -1,15 +1,15 @@ -package uk.co.jacekk.bukkit.bloodmoon.nms; +package com.github.hexosse.bloodmoon.nms; -import net.minecraft.server.v1_8_R3.World; +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.entity.BloodMoonEntityEndermen; +import com.github.hexosse.bloodmoon.entity.BloodMoonEntityType; +import net.minecraft.server.v1_10_R1.World; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_8_R3.CraftServer; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEnderman; +import org.bukkit.craftbukkit.v1_10_R1.CraftServer; +import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEnderman; import org.bukkit.plugin.Plugin; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.entity.BloodMoonEntityEndermen; -import uk.co.jacekk.bukkit.bloodmoon.entity.BloodMoonEntityType; -public class EntityEnderman extends net.minecraft.server.v1_8_R3.EntityEnderman { +public class EntityEnderman extends net.minecraft.server.v1_10_R1.EntityEnderman { private BloodMoon plugin; private BloodMoonEntityEndermen bloodMoonEntity; @@ -34,10 +34,10 @@ public EntityEnderman(World world) { } @Override - public boolean bM() { + public boolean ct() { try { this.bloodMoonEntity.onTick(); - super.bL(); + super.co(); } catch (Exception e) { plugin.getLogger().warning("Exception caught while ticking entity"); e.printStackTrace(); diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntityGhast.java b/src/main/java/com/github/hexosse/bloodmoon/nms/EntityGhast.java similarity index 64% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntityGhast.java rename to src/main/java/com/github/hexosse/bloodmoon/nms/EntityGhast.java index 318592e..f36450f 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntityGhast.java +++ b/src/main/java/com/github/hexosse/bloodmoon/nms/EntityGhast.java @@ -1,15 +1,15 @@ -package uk.co.jacekk.bukkit.bloodmoon.nms; +package com.github.hexosse.bloodmoon.nms; -import net.minecraft.server.v1_8_R3.World; +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.entity.BloodMoonEntityGhast; +import com.github.hexosse.bloodmoon.entity.BloodMoonEntityType; +import net.minecraft.server.v1_10_R1.World; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_8_R3.CraftServer; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftGhast; +import org.bukkit.craftbukkit.v1_10_R1.CraftServer; +import org.bukkit.craftbukkit.v1_10_R1.entity.CraftGhast; import org.bukkit.plugin.Plugin; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.entity.BloodMoonEntityGhast; -import uk.co.jacekk.bukkit.bloodmoon.entity.BloodMoonEntityType; -public class EntityGhast extends net.minecraft.server.v1_8_R3.EntityGhast { +public class EntityGhast extends net.minecraft.server.v1_10_R1.EntityGhast { private BloodMoon plugin; private BloodMoonEntityGhast bloodMoonEntity; @@ -31,10 +31,10 @@ public EntityGhast(World world) { } @Override - public boolean bM() { + public boolean ct() { try { this.bloodMoonEntity.onTick(); - super.bL(); + super.co(); } catch (Exception e) { plugin.getLogger().warning("Exception caught while ticking entity"); e.printStackTrace(); diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntityGiantZombie.java b/src/main/java/com/github/hexosse/bloodmoon/nms/EntityGiantZombie.java similarity index 58% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntityGiantZombie.java rename to src/main/java/com/github/hexosse/bloodmoon/nms/EntityGiantZombie.java index 1f58037..4b9fd30 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntityGiantZombie.java +++ b/src/main/java/com/github/hexosse/bloodmoon/nms/EntityGiantZombie.java @@ -1,22 +1,20 @@ -package uk.co.jacekk.bukkit.bloodmoon.nms; +package com.github.hexosse.bloodmoon.nms; +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.entity.BloodMoonEntityGiantZombie; +import com.github.hexosse.bloodmoon.entity.BloodMoonEntityType; import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_8_R3.CraftServer; -import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftGiant; +import org.bukkit.craftbukkit.v1_10_R1.CraftServer; +import org.bukkit.craftbukkit.v1_10_R1.entity.CraftGiant; import org.bukkit.plugin.Plugin; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.entity.BloodMoonEntityGiantZombie; -import uk.co.jacekk.bukkit.bloodmoon.entity.BloodMoonEntityType; -public class EntityGiantZombie extends net.minecraft.server.v1_8_R3.EntityGiantZombie { +public class EntityGiantZombie extends net.minecraft.server.v1_10_R1.EntityGiantZombie { private BloodMoon plugin; private BloodMoonEntityGiantZombie bloodMoonEntity; - public EntityGiantZombie(World world) { - super(((CraftWorld) world).getHandle()); + public EntityGiantZombie(net.minecraft.server.v1_10_R1.World world) { + super(world); Plugin gPlugin = Bukkit.getPluginManager().getPlugin("BloodMoon"); @@ -32,10 +30,10 @@ public EntityGiantZombie(World world) { } @Override - public boolean bM() { + public boolean ct() { try { this.bloodMoonEntity.onTick(); - super.bL(); + super.co(); motY = 10D; } catch (Exception e) { plugin.getLogger().warning("Exception caught while ticking entity"); diff --git a/src/main/java/com/github/hexosse/bloodmoon/nms/EntitySkeleton.java b/src/main/java/com/github/hexosse/bloodmoon/nms/EntitySkeleton.java new file mode 100644 index 0000000..923c393 --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/nms/EntitySkeleton.java @@ -0,0 +1,152 @@ +package com.github.hexosse.bloodmoon.nms; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.bloodmoon.entity.BloodMoonEntitySkeleton; +import com.github.hexosse.bloodmoon.entity.BloodMoonEntityType; +import com.github.hexosse.pluginframework.pluginapi.reflexion.Reflexion; +import net.minecraft.server.v1_10_R1.*; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_10_R1.CraftServer; +import org.bukkit.craftbukkit.v1_10_R1.entity.CraftSkeleton; +import org.bukkit.event.entity.EntityCombustEvent; +import org.bukkit.plugin.Plugin; + +import java.util.Set; + +//public class EntitySkeleton { +public class EntitySkeleton extends net.minecraft.server.v1_10_R1.EntitySkeleton implements IRangedEntity { + + private BloodMoon plugin; + private BloodMoonEntitySkeleton bloodMoonEntity; + + public EntitySkeleton(net.minecraft.server.v1_10_R1.World world) { + super(world); + + Plugin gPlugin = Bukkit.getPluginManager().getPlugin("BloodMoon"); + + if (gPlugin == null || !(gPlugin instanceof BloodMoon)) { + this.world.removeEntity(this); + return; + } + + this.plugin = (BloodMoon) gPlugin; + + this.bukkitEntity = new CraftSkeleton((CraftServer) this.plugin.getServer(), this); + this.bloodMoonEntity = new BloodMoonEntitySkeleton(this.plugin, this, BloodMoonEntityType.SKELETON); + + try { + Reflexion.getField(this.goalSelector.getClass(), "b", Set.class, this.goalSelector).clear(); + Reflexion.getField(this.targetSelector.getClass(), "b", Set.class, this.targetSelector).clear(); + + this.goalSelector.a(1, new PathfinderGoalFloat(this)); + this.goalSelector.a(2, new PathfinderGoalRestrictSun(this)); + this.goalSelector.a(3, new PathfinderGoalFleeSun(this, 1.0d)); + // NOTE: See bJ() below + this.goalSelector.a(5, new PathfinderGoalRandomStroll(this, 1.0d)); + this.goalSelector.a(6, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 8.0F)); + this.goalSelector.a(6, new PathfinderGoalRandomLookaround(this)); + + this.targetSelector.a(1, new PathfinderGoalHurtByTarget(this, false)); + this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget(this, EntityHuman.class, false, true)); + } catch (Exception e) { + e.printStackTrace(); + this.world.removeEntity(this); + } + } + +// @Override +// public GroupDataEntity prepare(GroupDataEntity entityData){ +// if (this.world.worldProvider instanceof WorldProviderHell && this.aI().nextInt(5) > 0){ +// this.goalSelector.a(4, new PathfinderGoalMeleeAttack(this, EntityHuman.class, 1.2d, false)); +// this.setSkeletonType(1); +// this.setEquipment(0, new ItemStack(Items.STONE_SWORD)); +// }else{ +// this.goalSelector.a(4, new PathfinderGoalArrowAttack(this.plugin, this, 1.0d, 20, 60, 15.0f)); +// +// this.bC(); +// this.bD(); +// } +// +// this.h(this.random.nextFloat() < 0.55F * this.world.b(this.locX, this.locY, this.locZ)); +// +// if (getEquipment(4) == null){ +// Calendar calendar = this.world.V(); +// +// if (calendar.get(2) + 1 == 10 && calendar.get(5) == 31 && this.random.nextFloat() < 0.25F){ +// setEquipment(4, new ItemStack(this.random.nextFloat() < 0.1F ? Blocks.JACK_O_LANTERN : Blocks.PUMPKIN)); +// this.dropChances[4] = 0.0F; +// } +// } +// +// return entityData; +// } +// @Override +// public boolean bL(){ +// try{ +// this.bloodMoonEntity.onTick(); +// super.bL(); +// }catch (Exception e){ +// plugin.log.warn("Exception caught while ticking entity"); +// e.printStackTrace(); +// } +// return true; +// } + @Override + public void a(net.minecraft.server.v1_10_R1.EntityLiving entityLiving, float f) { + EntityTippedArrow entitytippedarrow = new EntityTippedArrow(this.world, this); + double d0 = entityLiving.locX - this.locX; + double d1 = entityLiving.getBoundingBox().b + (double) (entityLiving.length / 3.0F) - entitytippedarrow.locY; + double d2 = entityLiving.locZ - this.locZ; + double d3 = (double) MathHelper.sqrt(d0 * d0 + d2 * d2); + + entitytippedarrow.shoot(d0, d1 + d3 * 0.20000000298023224D, d2, 1.6F, (float) (14 - this.world.getDifficulty().a() * 4)); + int i = EnchantmentManager.a(Enchantments.ARROW_DAMAGE, this); + int j = EnchantmentManager.a(Enchantments.ARROW_KNOCKBACK, this); + + entitytippedarrow.c((double) (f * 2.0F) + this.random.nextGaussian() * 0.25D + (double) ((float) this.world.getDifficulty().a() * 0.11F)); + if (i > 0) {//set enchantment level + entitytippedarrow.c(entitytippedarrow.k() + i * 0.5D + 0.5D); + } + + if (j > 0) {//set knockback + entitytippedarrow.setKnockbackStrength(j); + } + + World bukkitWorld = this.world.worldData.world.getWorld(); + WorldConfig worldConfig = plugin.getConfig(bukkitWorld); + + if (plugin.isActive(bukkitWorld) && worldConfig.FEATURE_FIRE_ARROWS_ENABLED.getValue() && (this.random.nextInt(100) < worldConfig.FEATURE_FIRE_ARROWS_CHANCE.getValue()) + || (EnchantmentManager.a(Enchantments.ARROW_FIRE, this) > 0 || this.getSkeletonType() == EnumSkeletonType.WITHER)) { + // CraftBukkit start - call EntityCombustEvent + EntityCombustEvent event = new EntityCombustEvent(entitytippedarrow.getBukkitEntity(), 100); + this.world.getServer().getPluginManager().callEvent(event); + + if (!event.isCancelled()) { + entitytippedarrow.setOnFire(event.getDuration()); + } + // CraftBukkit end + } + +// if (plugin.isActive(worldName) && worldConfig.getBoolean(WorldConfig.FEATURE_FIRE_ARROWS_ENABLED) && (this.random.nextInt(100) < worldConfig.getInt(WorldConfig.FEATURE_FIRE_ARROWS_CHANCE))) { +// //if (EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_FIRE.id, this.bz()) > 0 || getSkeletonType() == 1) { +// //entityarrow.setOnFire(1024); +// //} +// } + + // CraftBukkit start + org.bukkit.event.entity.EntityShootBowEvent event = org.bukkit.craftbukkit.v1_10_R1.event.CraftEventFactory.callEntityShootBowEvent(this, this.getItemInMainHand(), entitytippedarrow, 0.8f); + if (event.isCancelled()) { + event.getProjectile().remove(); + return; + } + + if (event.getProjectile() == entitytippedarrow.getBukkitEntity()) { + world.addEntity(entitytippedarrow); + } + // CraftBukkit end + + this.a(SoundEffects.fn, 1.0f, 1.0f / (this.getRandom().nextFloat() * 0.4f + 0.8f)); + } +} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntitySpider.java b/src/main/java/com/github/hexosse/bloodmoon/nms/EntitySpider.java similarity index 64% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntitySpider.java rename to src/main/java/com/github/hexosse/bloodmoon/nms/EntitySpider.java index 3e538ef..65e3a07 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntitySpider.java +++ b/src/main/java/com/github/hexosse/bloodmoon/nms/EntitySpider.java @@ -1,15 +1,15 @@ -package uk.co.jacekk.bukkit.bloodmoon.nms; +package com.github.hexosse.bloodmoon.nms; -import net.minecraft.server.v1_8_R3.World; +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.entity.BloodMoonEntitySpider; +import com.github.hexosse.bloodmoon.entity.BloodMoonEntityType; +import net.minecraft.server.v1_10_R1.World; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_8_R3.CraftServer; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftSpider; +import org.bukkit.craftbukkit.v1_10_R1.CraftServer; +import org.bukkit.craftbukkit.v1_10_R1.entity.CraftSpider; import org.bukkit.plugin.Plugin; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.entity.BloodMoonEntitySpider; -import uk.co.jacekk.bukkit.bloodmoon.entity.BloodMoonEntityType; -public class EntitySpider extends net.minecraft.server.v1_8_R3.EntitySpider { +public class EntitySpider extends net.minecraft.server.v1_10_R1.EntitySpider { private BloodMoon plugin; private BloodMoonEntitySpider bloodMoonEntity; @@ -31,10 +31,10 @@ public EntitySpider(World world) { } @Override - public boolean bM() { + public boolean ct() { try { this.bloodMoonEntity.onTick(); - super.bL(); + super.co(); } catch (Exception e) { plugin.getLogger().warning("Exception caught while ticking entity"); e.printStackTrace(); diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntityWitch.java b/src/main/java/com/github/hexosse/bloodmoon/nms/EntityWitch.java similarity index 64% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntityWitch.java rename to src/main/java/com/github/hexosse/bloodmoon/nms/EntityWitch.java index 3fdc397..a02ab56 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntityWitch.java +++ b/src/main/java/com/github/hexosse/bloodmoon/nms/EntityWitch.java @@ -1,15 +1,15 @@ -package uk.co.jacekk.bukkit.bloodmoon.nms; +package com.github.hexosse.bloodmoon.nms; -import net.minecraft.server.v1_8_R3.World; +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.entity.BloodMoonEntityType; +import com.github.hexosse.bloodmoon.entity.BloodMoonEntityWitch; +import net.minecraft.server.v1_10_R1.World; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_8_R3.CraftServer; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftWitch; +import org.bukkit.craftbukkit.v1_10_R1.CraftServer; +import org.bukkit.craftbukkit.v1_10_R1.entity.CraftWitch; import org.bukkit.plugin.Plugin; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.entity.BloodMoonEntityType; -import uk.co.jacekk.bukkit.bloodmoon.entity.BloodMoonEntityWitch; -public class EntityWitch extends net.minecraft.server.v1_8_R3.EntityWitch { +public class EntityWitch extends net.minecraft.server.v1_10_R1.EntityWitch { private BloodMoon plugin; private BloodMoonEntityWitch bloodMoonEntity; @@ -31,10 +31,10 @@ public EntityWitch(World world) { } @Override - public boolean bM() { + public boolean ct() { try { this.bloodMoonEntity.onTick(); - super.bL(); + super.co(); } catch (Exception e) { plugin.getLogger().warning("Exception caught while ticking entity"); e.printStackTrace(); diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntityWither.java b/src/main/java/com/github/hexosse/bloodmoon/nms/EntityWither.java similarity index 64% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntityWither.java rename to src/main/java/com/github/hexosse/bloodmoon/nms/EntityWither.java index ad97421..c3b53c3 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntityWither.java +++ b/src/main/java/com/github/hexosse/bloodmoon/nms/EntityWither.java @@ -1,15 +1,15 @@ -package uk.co.jacekk.bukkit.bloodmoon.nms; +package com.github.hexosse.bloodmoon.nms; -import net.minecraft.server.v1_8_R3.World; +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.entity.BloodMoonEntityType; +import com.github.hexosse.bloodmoon.entity.BloodMoonEntityWither; +import net.minecraft.server.v1_10_R1.World; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_8_R3.CraftServer; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftWither; +import org.bukkit.craftbukkit.v1_10_R1.CraftServer; +import org.bukkit.craftbukkit.v1_10_R1.entity.CraftWither; import org.bukkit.plugin.Plugin; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.entity.BloodMoonEntityType; -import uk.co.jacekk.bukkit.bloodmoon.entity.BloodMoonEntityWither; -public class EntityWither extends net.minecraft.server.v1_8_R3.EntityWither { +public class EntityWither extends net.minecraft.server.v1_10_R1.EntityWither { private BloodMoon plugin; private BloodMoonEntityWither bloodMoonEntity; @@ -31,10 +31,10 @@ public EntityWither(World world) { } @Override - public boolean bM() { + public boolean ct() { try { this.bloodMoonEntity.onTick(); - super.bL(); + super.co(); } catch (Exception e) { plugin.getLogger().warning("Exception caught while ticking entity"); e.printStackTrace(); diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntityZombie.java b/src/main/java/com/github/hexosse/bloodmoon/nms/EntityZombie.java similarity index 64% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntityZombie.java rename to src/main/java/com/github/hexosse/bloodmoon/nms/EntityZombie.java index 8abf1ab..ec96863 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntityZombie.java +++ b/src/main/java/com/github/hexosse/bloodmoon/nms/EntityZombie.java @@ -1,15 +1,15 @@ -package uk.co.jacekk.bukkit.bloodmoon.nms; +package com.github.hexosse.bloodmoon.nms; -import net.minecraft.server.v1_8_R3.World; +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.entity.BloodMoonEntityType; +import com.github.hexosse.bloodmoon.entity.BloodMoonEntityZombie; +import net.minecraft.server.v1_10_R1.World; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_8_R3.CraftServer; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftZombie; +import org.bukkit.craftbukkit.v1_10_R1.CraftServer; +import org.bukkit.craftbukkit.v1_10_R1.entity.CraftZombie; import org.bukkit.plugin.Plugin; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.entity.BloodMoonEntityType; -import uk.co.jacekk.bukkit.bloodmoon.entity.BloodMoonEntityZombie; -public class EntityZombie extends net.minecraft.server.v1_8_R3.EntityZombie { +public class EntityZombie extends net.minecraft.server.v1_10_R1.EntityZombie { private BloodMoon plugin; private BloodMoonEntityZombie bloodMoonEntity; @@ -29,12 +29,12 @@ public EntityZombie(World world) { this.bukkitEntity = new CraftZombie((CraftServer) this.plugin.getServer(), this); this.bloodMoonEntity = new BloodMoonEntityZombie(this.plugin, this, BloodMoonEntityType.ZOMBIE); } - + @Override - public boolean bM() { + public boolean ct() { try { this.bloodMoonEntity.onTick(); - super.bL(); + super.co(); } catch (Exception e) { plugin.getLogger().warning("Exception caught while ticking entity"); e.printStackTrace(); diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/PathfinderGoalArrowAttack.java b/src/main/java/com/github/hexosse/bloodmoon/nms/PathfinderGoalArrowAttack.java similarity index 88% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/PathfinderGoalArrowAttack.java rename to src/main/java/com/github/hexosse/bloodmoon/nms/PathfinderGoalArrowAttack.java index cb7980f..46cba0d 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/PathfinderGoalArrowAttack.java +++ b/src/main/java/com/github/hexosse/bloodmoon/nms/PathfinderGoalArrowAttack.java @@ -1,9 +1,9 @@ -package uk.co.jacekk.bukkit.bloodmoon.nms; +package com.github.hexosse.bloodmoon.nms; -import net.minecraft.server.v1_8_R3.EntityInsentient; -import net.minecraft.server.v1_8_R3.EntityLiving; -import net.minecraft.server.v1_8_R3.IRangedEntity; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.BloodMoon; +import net.minecraft.server.v1_10_R1.EntityInsentient; +import net.minecraft.server.v1_10_R1.EntityLiving; +import net.minecraft.server.v1_10_R1.IRangedEntity; public class PathfinderGoalArrowAttack { //public class PathfinderGoalArrowAttack extends PathfinderGoal { @@ -95,9 +95,9 @@ public class PathfinderGoalArrowAttack { // this.a.getControllerLook().a(this.c, 30.0F, 30.0F); // // String worldName = this.a.world.worldData.getName(); -// PluginConfig worldConfig = plugin.getConfig(worldName); +// WorldConfig worldConfig = plugin.getConfig(worldName); // -// this.d = Math.max(this.d - ((plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.ARROW_RATE)) ? worldConfig.getInt(Config.FEATURE_ARROW_RATE_MULTIPLIER) : 1), 0); +// this.d = Math.max(this.d - ((plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.ARROW_RATE)) ? worldConfig.getInt(WorldConfig.FEATURE_ARROW_RATE_MULTIPLIER) : 1), 0); // // float f; // diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/spawning/GiantsTask.java b/src/main/java/com/github/hexosse/bloodmoon/tasks/GiantsTask.java similarity index 77% rename from src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/spawning/GiantsTask.java rename to src/main/java/com/github/hexosse/bloodmoon/tasks/GiantsTask.java index e5d65b2..14a23d4 100644 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/spawning/GiantsTask.java +++ b/src/main/java/com/github/hexosse/bloodmoon/tasks/GiantsTask.java @@ -1,18 +1,19 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.spawning; +package com.github.hexosse.bloodmoon.tasks; +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.nms.EntityGiantZombie; +import com.github.hexosse.pluginframework.pluginapi.PluginTask; import org.bukkit.Chunk; import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_10_R1.CraftWorld; import org.bukkit.entity.Entity; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; -import uk.co.jacekk.bukkit.baseplugin.scheduler.BaseTask; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.nms.EntityGiantZombie; import java.util.Random; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; -public final class GiantsTask extends BaseTask { +public final class GiantsTask extends PluginTask +{ private final Random random = new Random(); private final World world; @@ -23,7 +24,8 @@ public GiantsTask(BloodMoon plugin, World world) { } @Override - public void run() { + public void run() + { long worldTime = world.getTime(); if (worldTime < 13000 || worldTime > 23000) { @@ -45,11 +47,11 @@ public void run() { } } - EntityGiantZombie entity = new EntityGiantZombie(world); + EntityGiantZombie entity = new EntityGiantZombie(((CraftWorld) world).getHandle()); entity.setPositionRotation(x, y, z, 0, 90); ((CraftWorld) world).getHandle().addEntity(entity, SpawnReason.CUSTOM); - entity.p(null); + entity.z(null); } } } diff --git a/src/main/java/com/github/hexosse/bloodmoon/tasks/TimeMonitorTask.java b/src/main/java/com/github/hexosse/bloodmoon/tasks/TimeMonitorTask.java new file mode 100644 index 0000000..8e5eba5 --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/tasks/TimeMonitorTask.java @@ -0,0 +1,56 @@ +package com.github.hexosse.bloodmoon.tasks; + +import com.github.hexosse.bloodmoon.BloodMoon; +import com.github.hexosse.bloodmoon.configuration.WorldConfig; +import com.github.hexosse.pluginframework.pluginapi.PluginTask; +import org.bukkit.World; + +import java.util.Random; + +public class TimeMonitorTask extends PluginTask +{ + + private final Random random; + + public TimeMonitorTask(BloodMoon plugin) + { + super(plugin); + this.random = new Random(); + } + + @Override + public void run() + { + for(World world : plugin.getServer().getWorlds()) + { + String worldName = world.getName(); + + if(plugin.isEnabled(world)) + { + WorldConfig worldConfig = plugin.getConfig(world); + + if(!worldConfig.ALWAYS_ON.getValue()) + { + long worldTime = world.getTime(); + + if(worldTime >= 13000 && worldTime <= 13100) + { + if(plugin.forceWorlds.contains(worldName) || this.random.nextInt(100) < worldConfig.CHANCE.getValue()) + { + if(!plugin.isActive(world)) + plugin.activate(world); + + plugin.forceWorlds.remove(worldName); + } + } + else if(worldTime >= 23000 && worldTime <= 23100) + { + if(plugin.isActive(world)) + plugin.deactivate(world); + } + } + } + } + } + +} diff --git a/src/main/java/com/github/hexosse/bloodmoon/util/RandomUtils.java b/src/main/java/com/github/hexosse/bloodmoon/util/RandomUtils.java new file mode 100644 index 0000000..52c4272 --- /dev/null +++ b/src/main/java/com/github/hexosse/bloodmoon/util/RandomUtils.java @@ -0,0 +1,23 @@ +package com.github.hexosse.bloodmoon.util; + +import java.util.List; +import java.util.Random; + +/** + * @author hexosse (hexosse on GitHub)) + */ +public class RandomUtils +{ + private static final Random rand = new Random(); + + /** + * Gets a random entry from the list. + * + * @param items The list to use. + * @param The object being conversed with + * @return A random entry from the list. + */ + public static T getRandom(List items){ + return items.get(rand.nextInt(items.size())); + } +} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/BloodMoon.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/BloodMoon.java deleted file mode 100644 index 33f5d05..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/BloodMoon.java +++ /dev/null @@ -1,228 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon; - -import uk.co.jacekk.bukkit.bloodmoon.exceptions.EntityRegistrationException; -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; - -import org.bukkit.World; -import org.bukkit.entity.Entity; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; -import org.bukkit.metadata.MetadataValue; - -import uk.co.jacekk.bukkit.baseplugin.BasePlugin; -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.bloodmoon.command.BloodMoonExecuter; -import uk.co.jacekk.bukkit.bloodmoon.entity.BloodMoonEntityType; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonEndEvent; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonStartEvent; - -public final class BloodMoon extends BasePlugin { - - public static boolean DEBUG = false; - - private ArrayList activeWorlds; - private HashMap worldConfig; - protected ArrayList forceWorlds; - - @Override - public void onEnable() { - super.onEnable(true); - - activeWorlds = new ArrayList<>(); - forceWorlds = new ArrayList<>(); - worldConfig = new HashMap<>(); - - try { - BloodMoonEntityType.registerEntities(); - } catch (EntityRegistrationException e) { - e.printStackTrace();// - } - - for (World world : getServer().getWorlds()) { - createConfig(world); - } - - getCommandManager().registerCommandExecutor(new BloodMoonExecuter(this)); - getServer().getPluginManager().registerEvents(new WorldInitListener(this), this); - getServer().getPluginManager().registerEvents(new SpawnReasonListener(this), this); - getServer().getScheduler().scheduleSyncRepeatingTask(this, new TimeMonitorTask(this), 100L, 100L); - - for (Feature feature : Feature.values()) { - try { - Class listener = feature.getListenerClass(); - - if (listener != null) { - getServer().getPluginManager().registerEvents(listener.getConstructor(BloodMoon.class).newInstance(this), this); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - /** - * Starts a bloodmoon in a specific world - * - * @param worldName The name of the world - */ - public void activate(String worldName) { - World world = getServer().getWorld(worldName); - - if (world == null || isActive(worldName)) { - return; - } - - BloodMoonStartEvent event = new BloodMoonStartEvent(world); - - getServer().getPluginManager().callEvent(event); - - if (!event.isCancelled()) { - activeWorlds.add(worldName); - } - } - - /** - * Starts a bloodmoon the next time night is reached in a specific world - * - * @param worldName The name of the world - */ - public void forceNextNight(String worldName) { - World world = getServer().getWorld(worldName); - - if (world != null) { - forceWorlds.add(worldName); - } - } - - /** - * Stops an existing bloodmoon in a world - * - * @param worldName The name of the world - */ - public void deactivate(String worldName) { - World world = getServer().getWorld(worldName); - - if (world != null || isActive(worldName)) { - - BloodMoonEndEvent event = new BloodMoonEndEvent(world); - - getServer().getPluginManager().callEvent(event); - - if (!event.isCancelled()) { - activeWorlds.remove(worldName); - } - } - } - - /** - * Checks if a bloodmoon is currently active in a world - * - * @param worldName The name of the world - * @return true if a bloodmoon is active false if not - */ - public boolean isActive(String worldName) { - return activeWorlds.contains(worldName); - } - - /** - * Checks if the bloodmoon is enabled for a world - * - * @param worldName The name of the world - * @return true if the bloodmoon is enabled false if not - */ - public boolean isEnabled(String worldName) { - if (!worldConfig.containsKey(worldName)) { - return false; - } - - return worldConfig.get(worldName).getBoolean(Config.ENABLED); - } - - /** - * Checks if a specific feature is enabled in a world. - * - * @param worldName The name of the world - * @param feature The {@link Feature} to check - * @return true if the feature is enabled false if not - */ - public boolean isFeatureEnabled(String worldName, Feature feature) { - if (!worldConfig.containsKey(worldName)) { - return false; - } - - return worldConfig.get(worldName).getBoolean(feature.getEnabledConfigKey()); - } - - /** - * Sets up the config for a world. This should only be used by other plugins - * if a world is being loaded that would not call a WorldInitEvent. - * - * @param world The {@link World} being loaded - * @return The config object that was created for the world or null if it - * already existed. - */ - public PluginConfig createConfig(World world) { - String worldName = world.getName(); - - if (!worldConfig.containsKey(worldName)) { - PluginConfig newConfig = new PluginConfig(new File(getBaseDirPath() + File.separator + worldName + ".yml"), Config.class, getLogger()); - - worldConfig.put(worldName, newConfig); - - if (newConfig.getBoolean(Config.ALWAYS_ON)) { - activate(worldName); - } - - return newConfig; - } - - return null; - } - - /** - * Gets the config for a world - * - * @param worldName The name of the world - * @return the {@link PluginConfig} for this world - */ - public PluginConfig getConfig(String worldName) { - if (!worldConfig.containsKey(worldName)) { - World world = getServer().getWorld(worldName); - - if (world != null) { - return createConfig(world); - } - } - - return worldConfig.get(worldName); - } - - /** - * Reloads all config files. - */ - public void reloadWorldConfig() { - for (PluginConfig config : worldConfig.values()) { - config.reload(); - } - } - - /** - * Gets the reason that an entity spawned. Note that these reasons are reset - * when the server restarts. - * - * @param entity The entity - * @return The {@link SpawnReason} - */ - public SpawnReason getSpawnReason(Entity entity) { - for (MetadataValue value : entity.getMetadata("spawn-reason")) { - if (value.getOwningPlugin() instanceof BloodMoon) { - return (SpawnReason) value.value(); - } - } - - return SpawnReason.DEFAULT; - } - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/Config.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/Config.java deleted file mode 100644 index efab466..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/Config.java +++ /dev/null @@ -1,140 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon; - -import java.util.Arrays; - -import org.bukkit.Material; -import org.bukkit.block.Biome; -import org.bukkit.entity.EntityType; - -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfigKey; - -public class Config { - - public static final PluginConfigKey ENABLED = new PluginConfigKey("enabled", false); - public static final PluginConfigKey ALWAYS_ON = new PluginConfigKey("always-on", false); - public static final PluginConfigKey CHANCE = new PluginConfigKey("chance", 14); - - public static final PluginConfigKey FEATURE_CHAT_MESSAGE_ENABLED = new PluginConfigKey("features.chat-message.enabled", true); - public static final PluginConfigKey FEATURE_CHAT_MESSAGE_START_MESSAGE = new PluginConfigKey("features.chat-message.start-message", "&cThe bloodmoon is rising !"); - public static final PluginConfigKey FEATURE_CHAT_MESSAGE_END_MESSAGE = new PluginConfigKey("features.chat-message.end-message", "&cThe bloodmoon is over !"); - - public static final PluginConfigKey FEATURE_SERVER_COMMANDS_ENABLED = new PluginConfigKey("features.server-commands.enabled", false); - public static final PluginConfigKey FEATURE_SERVER_COMMANDS_START_COMMANDS = new PluginConfigKey("features.server-commands.commands.start", Arrays.asList("toggledownfall", "time set 0", "op Notch")); - public static final PluginConfigKey FEATURE_SERVER_COMMANDS_END_COMMANDS = new PluginConfigKey("features.server-commands.commands.end", Arrays.asList("toggledownfall", "time set 12000", "deop Notch")); - - public static final PluginConfigKey FEATURE_DISABLED_COMMANDS_ENABLED = new PluginConfigKey("features.disabled-commands.enabled", true); - public static final PluginConfigKey FEATURE_DISABLED_COMMANDS_COMMANDS = new PluginConfigKey("features.disabled-commands.commands", Arrays.asList("spawn", "home")); - - public static final PluginConfigKey FEATURE_PLAY_SOUND_ENABLED = new PluginConfigKey("features.play-sound.enabled", true); - public static final PluginConfigKey FEATURE_PLAY_SOUND_SOUND = new PluginConfigKey("features.play-sound.sound", "WITHER_SPAWN"); - public static final PluginConfigKey FEATURE_PLAY_SOUND_PITCH = new PluginConfigKey("features.play-sound.pitch", 1.0d); - public static final PluginConfigKey FEATURE_PLAY_SOUND_VOLUME = new PluginConfigKey("features.play-sound.volume", 1.0d); - - public static final PluginConfigKey FEATURE_ARROW_RATE_ENABLED = new PluginConfigKey("features.arrow-rate.enabled", true); - public static final PluginConfigKey FEATURE_ARROW_RATE_MULTIPLIER = new PluginConfigKey("features.arrow-rate.multiplier", 2); - - public static final PluginConfigKey FEATURE_FIRE_ARROWS_ENABLED = new PluginConfigKey("features.fire-arrows.enabled", true); - public static final PluginConfigKey FEATURE_FIRE_ARROWS_CHANCE = new PluginConfigKey("features.fire-arrows.chance", 100); - public static final PluginConfigKey FEATURE_FIRE_ARROWS_IGNITE_TARGET = new PluginConfigKey("features.fire-arrows.ignite-target", true); - - public static final PluginConfigKey FEATURE_ZOMBIE_WEAPON_ENABLED = new PluginConfigKey("features.zombie-weapon.enabled", true); - public static final PluginConfigKey FEATURE_ZOMBIE_WEAPON_CHANCE = new PluginConfigKey("features.zombie-weapon.chance", 60); - public static final PluginConfigKey FEATURE_ZOMBIE_WEAPON_DROP_CHANCE = new PluginConfigKey("features.zombie-weapon.drop-chance", 25); - public static final PluginConfigKey FEATURE_ZOMBIE_WEAPON_IGNORE_SPAWNERS = new PluginConfigKey("features.zombie-weapon.ignore-spawners", true); - public static final PluginConfigKey FEATURE_ZOMBIE_WEAPON_WEAPONS = new PluginConfigKey("features.zombie-weapon.weapons", Arrays.asList("DIAMOND_SWORD", "GOLD_SWORD", "IRON_SWORD")); - - public static final PluginConfigKey FEATURE_ZOMBIE_ARMOR_ENABLED = new PluginConfigKey("features.zombie-armor.enabled", true); - public static final PluginConfigKey FEATURE_ZOMBIE_ARMOR_CHANCE = new PluginConfigKey("features.zombie-armor.chance", 60); - public static final PluginConfigKey FEATURE_ZOMBIE_ARMOR_DROP_CHANCE = new PluginConfigKey("features.zombie-armor.drop-chance", 7); - public static final PluginConfigKey FEATURE_ZOMBIE_ARMOR_IGNORE_SPAWNERS = new PluginConfigKey("features.zombie-armor.ignore-spawners", true); - public static final PluginConfigKey FEATURE_ZOMBIE_ARMOR_ARMOR = new PluginConfigKey("features.zombie-armor.armor", Arrays.asList("DIAMOND", "GOLD", "IRON")); - - public static final PluginConfigKey FEATURE_TARGET_DISTANCE_ENABLED = new PluginConfigKey("features.target-distance.enabled", true); - public static final PluginConfigKey FEATURE_TARGET_DISTANCE_MULTIPLIER = new PluginConfigKey("features.target-distance.multiplier", 2.0d); - public static final PluginConfigKey FEATURE_TARGET_DISTANCE_MOBS = new PluginConfigKey("features.target-distance.mobs", Arrays.asList("ZOMBIE", "SKELETON", "SPIDER", "CREEPER")); - - public static final PluginConfigKey FEATURE_MOVEMENT_SPEED_ENABLED = new PluginConfigKey("features.movement-speed.enabled", true); - public static final PluginConfigKey FEATURE_MOVEMENT_SPEED_MULTIPLIER = new PluginConfigKey("features.movement-speed.multiplier", 1.20d); - public static final PluginConfigKey FEATURE_MOVEMENT_SPEED_FAST_CHANCE = new PluginConfigKey("features.movement-speed.fast-chance", 15); - public static final PluginConfigKey FEATURE_MOVEMENT_SPEED_FAST_MULTIPLIER = new PluginConfigKey("features.movement-speed.fast-multiplier", 1.3d); - public static final PluginConfigKey FEATURE_MOVEMENT_SPEED_MOBS = new PluginConfigKey("features.movement-speed.mobs", Arrays.asList("ZOMBIE", "SKELETON", "CREEPER")); - - public static final PluginConfigKey FEATURE_BREAK_BLOCKS_ENABLED = new PluginConfigKey("features.break-blocks.enabled", true); - public static final PluginConfigKey FEATURE_BREAK_BLOCKS_DROP_ITEMS = new PluginConfigKey("features.break-blocks.drop-items", true); - public static final PluginConfigKey FEATURE_BREAK_BLOCKS_REALISTIC_DROP = new PluginConfigKey("features.break-blocks.realistic-drop", true); - public static final PluginConfigKey FEATURE_BREAK_BLOCKS_MOBS = new PluginConfigKey("features.break-blocks.mobs", Arrays.asList("ZOMBIE", "SKELETON", "SPIDER", "CREEPER", "ENDERMAN")); - public static final PluginConfigKey FEATURE_BREAK_BLOCKS_BLOCKS = new PluginConfigKey("features.break-blocks.blocks", Arrays.asList("WOOD", "LOG", "GLASS")); - - public static final PluginConfigKey FEATURE_MAX_HEALTH_ENABLED = new PluginConfigKey("features.max-health.enabled", true); - public static final PluginConfigKey FEATURE_MAX_HEALTH_MULTIPLIER = new PluginConfigKey("features.max-health.multiplier", 2.0d); - public static final PluginConfigKey FEATURE_MAX_HEALTH_MOBS = new PluginConfigKey("features.max-health.mobs", Arrays.asList("ZOMBIE", "SKELETON", "SPIDER", "CREEPER", "ENDERMAN")); - - public static final PluginConfigKey FEATURE_MORE_SPAWNING_ENABLED = new PluginConfigKey("features.more-spawning.enabled", true); - public static final PluginConfigKey FEATURE_MORE_SPAWNING_MULTIPLIER = new PluginConfigKey("features.more-spawning.multiplier", 2); - public static final PluginConfigKey FEATURE_MORE_SPAWNING_MOBS = new PluginConfigKey("features.more-spawning.mobs", Arrays.asList("ZOMBIE", "SKELETON", "SPIDER", "CREEPER", "ENDERMAN")); - - public static final PluginConfigKey FEATURE_MORE_EXP_ENABLED = new PluginConfigKey("features.more-exp.enabled", true); - public static final PluginConfigKey FEATURE_MORE_EXP_IGNORE_SPAWNERS = new PluginConfigKey("features.more-exp.ignore-spawners", false); - public static final PluginConfigKey FEATURE_MORE_EXP_MULTIPLIER = new PluginConfigKey("features.more-exp.multiplier", 2); - - public static final PluginConfigKey FEATURE_MORE_DROPS_ENABLED = new PluginConfigKey("features.more-drops.enabled", true); - public static final PluginConfigKey FEATURE_MORE_DROPS_IGNORE_SPAWNERS = new PluginConfigKey("features.more-drops.ignore-spawners", false); - public static final PluginConfigKey FEATURE_MORE_DROPS_MULTIPLIER = new PluginConfigKey("features.more-drops.multiplier", 2); - - public static final PluginConfigKey FEATURE_SWORD_DAMAGE_ENABLED = new PluginConfigKey("features.sword-damage.enabled", true); - public static final PluginConfigKey FEATURE_SWORD_DAMAGE_MOBS = new PluginConfigKey("features.sword-damage.mobs", Arrays.asList("ZOMBIE", "SKELETON", "SPIDER", "CREEPER", "ENDERMAN")); - public static final PluginConfigKey FEATURE_SWORD_DAMAGE_CHANCE = new PluginConfigKey("features.sword-damage.chance", 10); - - public static final PluginConfigKey FEATURE_SUPER_CREEPERS_ENABLED = new PluginConfigKey("features.super-creepers.enabled", true); - public static final PluginConfigKey FEATURE_SUPER_CREEPERS_POWER = new PluginConfigKey("features.super-creepers.power", 4.0D); - public static final PluginConfigKey FEATURE_SUPER_CREEPERS_FIRE = new PluginConfigKey("features.super-creepers.fire", true); - public static final PluginConfigKey FEATURE_SUPER_CREEPERS_LIGHTNING = new PluginConfigKey("features.super-creepers.lightning", true); - - public static final PluginConfigKey FEATURE_SPAWN_ON_KILL_ENABLED = new PluginConfigKey("features.spawn-on-kill.enabled", true); - public static final PluginConfigKey FEATURE_SPAWN_ON_KILL_MOBS = new PluginConfigKey("features.spawn-on-kill.mobs", Arrays.asList("ZOMBIE", "SKELETON", "SPIDER", "CREEPER", "ENDERMAN")); - public static final PluginConfigKey FEATURE_SPAWN_ON_KILL_CHANCE = new PluginConfigKey("features.spawn-on-kill.chance", 10); - public static final PluginConfigKey FEATURE_SPAWN_ON_KILL_SPAWN = new PluginConfigKey("features.spawn-on-kill.spawn", Arrays.asList("ZOMBIE", "SKELETON", "SPIDER", "CREEPER", "ENDERMAN")); - - public static final PluginConfigKey FEATURE_SPAWN_ON_SLEEP_ENABLED = new PluginConfigKey("features.spawn-on-sleep.enabled", true); - public static final PluginConfigKey FEATURE_SPAWN_ON_SLEEP_SPAWN = new PluginConfigKey("features.spawn-on-sleep.spawn", Arrays.asList("ZOMBIE")); - - public static final PluginConfigKey FEATURE_SPAWN_CONTROL_ENABLED = new PluginConfigKey("features.spawn-control.enabled", true); - public static final PluginConfigKey FEATURE_SPAWN_CONTROL_SPAWN = new PluginConfigKey("features.spawn-control.spawn", Arrays.asList("ZOMBIE", "SKELETON", "SPIDER", "CREEPER", "ENDERMAN", "PIG_ZOMBIE", "BLAZE", "MAGMA_CUBE")); - - public static final PluginConfigKey FEATURE_LOCK_IN_WORLD_ENABLED = new PluginConfigKey("features.lock-in-world.enabled", false); - - public static final PluginConfigKey FEATURE_TEXTURE_PACK_ENABLED = new PluginConfigKey("features.texture-pack.enabled", false); - public static final PluginConfigKey FEATURE_TEXTURE_PACK_NORMAL = new PluginConfigKey("features.texture-pack.normal", "http://bukkit.jacekk.co.uk/bloodmoon_tps/normal.zip"); - public static final PluginConfigKey FEATURE_TEXTURE_PACK_BLOODMOON = new PluginConfigKey("features.texture-pack.bloodmoon", "http://bukkit.jacekk.co.uk/bloodmoon_tps/bloodmoon.zip"); - - public static final PluginConfigKey FEATURE_EXTENDED_NIGHT_ENABLED = new PluginConfigKey("features.extended-night.enabled", true); - public static final PluginConfigKey FEATURE_EXTENDED_NIGHT_MIN_KILLS = new PluginConfigKey("features.extended-night.min-kills", 16); - - public static final PluginConfigKey FEATURE_WEATHER_ENABLED = new PluginConfigKey("features.weather.enabled", true); - public static final PluginConfigKey FEATURE_WEATHER_THUNDER = new PluginConfigKey("features.weather.thunder", true); - public static final PluginConfigKey FEATURE_WEATHER_RAIN = new PluginConfigKey("features.weather.rain", true); - public static final PluginConfigKey FEATURE_WEATHER_CHANCE = new PluginConfigKey("features.weather.chance", 50); - - public static final PluginConfigKey FEATURE_DAYLIGHT_PROOF_MOBS_ENABLED = new PluginConfigKey("features.daylight-proof-mobs.enabled", true); - - public static final PluginConfigKey FEATURE_NETHER_SKY_ENABLED = new PluginConfigKey("features.nether-sky.enabled", false); - - public static final PluginConfigKey FEATURE_DUNGEONS_ENABLED = new PluginConfigKey("features.dungeons.enabled", true); - public static final PluginConfigKey FEATURE_DUNGEONS_PROTECTED = new PluginConfigKey("features.dungeons.protected", true); - public static final PluginConfigKey FEATURE_DUNGEONS_BIOMES = new PluginConfigKey("features.dungeons.biomes", Arrays.asList(Biome.PLAINS.name(), Biome.ICE_PLAINS.name(), Biome.DESERT.name(), Biome.SWAMPLAND.name())); - public static final PluginConfigKey FEATURE_DUNGEONS_CHANCE = new PluginConfigKey("features.dungeons.chance", 10); - public static final PluginConfigKey FEATURE_DUNGEONS_MIN_LAYERS = new PluginConfigKey("features.dungeons.min-layers", 3); - public static final PluginConfigKey FEATURE_DUNGEONS_MAX_LAYERS = new PluginConfigKey("features.dungeons.max-layers", 5); - public static final PluginConfigKey FEATURE_DUNGEONS_SPAWNER_TYPES = new PluginConfigKey("features.dungeons.spawner-types", Arrays.asList(EntityType.ZOMBIE.name(), EntityType.SKELETON.name())); - public static final PluginConfigKey FEATURE_DUNGEONS_SPAWNER_DELAY = new PluginConfigKey("features.dungeons.spawner-delay", 100); - public static final PluginConfigKey FEATURE_DUNGEONS_SPAWNER_COUNT = new PluginConfigKey("features.dungeons.spawner-count", 6); - public static final PluginConfigKey FEATURE_DUNGEONS_SPAWNER_MAX_MOBS = new PluginConfigKey("features.dungeons.spawner-max-mobs", 8); - public static final PluginConfigKey FEATURE_DUNGEONS_CHEST_ITEMS = new PluginConfigKey("features.dungeons.chest-items", Arrays.asList(Material.BREAD.name(), Material.APPLE.name(), Material.PORK.name(), Material.SADDLE.name(), Material.BUCKET.name(), Material.STRING.name(), Material.REDSTONE.name(), Material.SULPHUR.name(), Material.COCOA.name())); - public static final PluginConfigKey FEATURE_DUNGEONS_MIN_STACK_SIZE = new PluginConfigKey("features.dungeons.min-stack-size", 1); - public static final PluginConfigKey FEATURE_DUNGEONS_MAX_STACK_SIZE = new PluginConfigKey("features.dungeons.max-stack-size", 8); - public static final PluginConfigKey FEATURE_DUNGEONS_ITEMS_PER_CHEST = new PluginConfigKey("features.dungeons.items-per-chest", 12); - - public static final PluginConfigKey FEATURE_GIANTS_ENABLED = new PluginConfigKey("features.giants.enabled", true); - public static final PluginConfigKey FEATURE_GIANTS_BREAK_BLOCKS = new PluginConfigKey("features.giants.break-blocks", Arrays.asList(Material.GRASS.name(), Material.LEAVES.name(), Material.WOOD.name(), Material.GLASS.name(), Material.CROPS.name(), Material.SOIL.name(), Material.LOG.name(), Material.WOOD_STEP.name(), Material.WOOD_STAIRS.name())); - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/Feature.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/Feature.java deleted file mode 100644 index 300e73e..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/Feature.java +++ /dev/null @@ -1,101 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon; - -import org.bukkit.event.Listener; -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfigKey; -import uk.co.jacekk.bukkit.baseplugin.event.BaseListener; -import uk.co.jacekk.bukkit.bloodmoon.feature.client.ChatMessageListener; -import uk.co.jacekk.bukkit.bloodmoon.feature.client.PlaySoundListener; -import uk.co.jacekk.bukkit.bloodmoon.feature.client.TexturePackListener; -import uk.co.jacekk.bukkit.bloodmoon.feature.mob.DaylightProofMobsListener; -import uk.co.jacekk.bukkit.bloodmoon.feature.mob.FireArrowsListener; -import uk.co.jacekk.bukkit.bloodmoon.feature.mob.MaxHealthListener; -import uk.co.jacekk.bukkit.bloodmoon.feature.mob.MoreDropsListener; -import uk.co.jacekk.bukkit.bloodmoon.feature.mob.MoreExpListener; -import uk.co.jacekk.bukkit.bloodmoon.feature.mob.MovementSpeedListener; -import uk.co.jacekk.bukkit.bloodmoon.feature.mob.SuperCreepersListener; -import uk.co.jacekk.bukkit.bloodmoon.feature.mob.TargetDistanceListener; -import uk.co.jacekk.bukkit.bloodmoon.feature.mob.ZombieArmorListener; -import uk.co.jacekk.bukkit.bloodmoon.feature.mob.ZombieWeaponListener; -import uk.co.jacekk.bukkit.bloodmoon.feature.player.SwordDamageListener; -import uk.co.jacekk.bukkit.bloodmoon.feature.server.DisabledCommandsListener; -import uk.co.jacekk.bukkit.bloodmoon.feature.server.ServerCommandsListener; -import uk.co.jacekk.bukkit.bloodmoon.feature.spawning.GiantsListener; -import uk.co.jacekk.bukkit.bloodmoon.feature.spawning.MoreMobsListener; -import uk.co.jacekk.bukkit.bloodmoon.feature.spawning.MoreSpawningListener; -import uk.co.jacekk.bukkit.bloodmoon.feature.spawning.SpawnOnKillListener; -import uk.co.jacekk.bukkit.bloodmoon.feature.spawning.SpawnOnSleepListener; -import uk.co.jacekk.bukkit.bloodmoon.feature.world.DungeonListener; -import uk.co.jacekk.bukkit.bloodmoon.feature.world.ExtendedNightListener; -import uk.co.jacekk.bukkit.bloodmoon.feature.world.LockInWorldListener; -import uk.co.jacekk.bukkit.bloodmoon.feature.world.NetherSkyListener; -import uk.co.jacekk.bukkit.bloodmoon.feature.world.WeatherListener; - -public enum Feature { - - // Mob features - SUPER_CREEPERS(SuperCreepersListener.class, Config.FEATURE_SUPER_CREEPERS_ENABLED), - ZOMBIE_ARMOR(ZombieArmorListener.class, Config.FEATURE_ZOMBIE_ARMOR_ENABLED), - ZOMBIE_WEAPON(ZombieWeaponListener.class, Config.FEATURE_ZOMBIE_WEAPON_ENABLED), - DAYLIGHT_PROOF_MOBS(DaylightProofMobsListener.class, Config.FEATURE_DAYLIGHT_PROOF_MOBS_ENABLED), - FIRE_ARROWS(FireArrowsListener.class, Config.FEATURE_FIRE_ARROWS_ENABLED), - MAX_HEALTH(MaxHealthListener.class, Config.FEATURE_MAX_HEALTH_ENABLED), - MORE_DROPS(MoreDropsListener.class, Config.FEATURE_MORE_DROPS_ENABLED), - MORE_EXP(MoreExpListener.class, Config.FEATURE_MORE_EXP_ENABLED), - BREAK_BLOCKS(null, Config.FEATURE_BREAK_BLOCKS_ENABLED), // handled in BloodMoonEntity* - TARGET_DISTANCE(TargetDistanceListener.class, Config.FEATURE_TARGET_DISTANCE_ENABLED), - ARROW_RATE(null, Config.FEATURE_ARROW_RATE_ENABLED), // handled in BloodMoonPathfinderGoalArrowAttack - MOVEMENT_SPEED(MovementSpeedListener.class, Config.FEATURE_MOVEMENT_SPEED_ENABLED), - - // World features - WEATHER(WeatherListener.class, Config.FEATURE_WEATHER_ENABLED), - NETHER_SKY(NetherSkyListener.class, Config.FEATURE_NETHER_SKY_ENABLED), - LOCK_IN_WORLD(LockInWorldListener.class, Config.FEATURE_LOCK_IN_WORLD_ENABLED), - EXTENDED_NIGHT(ExtendedNightListener.class, Config.FEATURE_EXTENDED_NIGHT_ENABLED), - DUNGEONS(DungeonListener.class, Config.FEATURE_DUNGEONS_ENABLED), - - // Spawning features - SPAWN_ON_KILL(SpawnOnKillListener.class, Config.FEATURE_SPAWN_ON_KILL_ENABLED), - SPAWN_ON_SLEEP(SpawnOnSleepListener.class, Config.FEATURE_SPAWN_ON_SLEEP_ENABLED), - MORE_SPAWNING(MoreSpawningListener.class, Config.FEATURE_MORE_SPAWNING_ENABLED), - SPAWN_CONTROL(MoreMobsListener.class, Config.FEATURE_SPAWN_CONTROL_ENABLED), // partially handled in ChunkProviderServer - GIANTS(GiantsListener.class, Config.FEATURE_GIANTS_ENABLED), - - // Server features - SERVER_COMMANDS(ServerCommandsListener.class, Config.FEATURE_SERVER_COMMANDS_ENABLED), - DISABLED_COMMANDS(DisabledCommandsListener.class, Config.FEATURE_DISABLED_COMMANDS_ENABLED), - - // Player features - SWORD_DAMAGE(SwordDamageListener.class, Config.FEATURE_SWORD_DAMAGE_ENABLED), - - // Client Features. - PLAY_SOUND(PlaySoundListener.class, Config.FEATURE_PLAY_SOUND_ENABLED), - CHAT_MESSAGE(ChatMessageListener.class, Config.FEATURE_CHAT_MESSAGE_ENABLED), - TEXTURE_PACK(TexturePackListener.class, Config.FEATURE_TEXTURE_PACK_ENABLED); - - //private Class> listenerClass; - private final Class listenerClass; - private final PluginConfigKey enabledConfigKey; - - /*private Feature(Class> listenerClass, PluginConfigKey enabledConfigKey){ - this.listenerClass = listenerClass; - this.enabledConfigKey = enabledConfigKey; - } - - public Class> getListenerClass(){ - return this.listenerClass; - }*/ - - private Feature(Class listenerClass, PluginConfigKey enabledConfigKey){ - this.listenerClass = listenerClass; - this.enabledConfigKey = enabledConfigKey; - } - - public Class getListenerClass(){ - return this.listenerClass; - } - - public PluginConfigKey getEnabledConfigKey(){ - return this.enabledConfigKey; - } - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/Permission.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/Permission.java deleted file mode 100644 index 20fb193..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/Permission.java +++ /dev/null @@ -1,10 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon; - -public class Permission { - - public static final String ADMIN_START = "bloodmoon.admin.start"; - public static final String ADMIN_STOP = "bloodmoon.admin.stop"; - public static final String ADMIN_RELOAD = "bloodmoon.admin.reload"; - public static final String ADMIN_IGNORE_WORLD_LOCK = "bloodmoon.admin.ignore-world-lock"; - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/SpawnReasonListener.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/SpawnReasonListener.java deleted file mode 100644 index dd2b75d..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/SpawnReasonListener.java +++ /dev/null @@ -1,22 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.bukkit.metadata.FixedMetadataValue; - -public class SpawnReasonListener implements Listener { - - private final BloodMoon plugin; - - public SpawnReasonListener(BloodMoon plugin) { - this.plugin = plugin; - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onCreatureSpawn(CreatureSpawnEvent event) { - event.getEntity().setMetadata("spawn-reason", new FixedMetadataValue(plugin, event.getSpawnReason())); - } - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/TimeMonitorTask.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/TimeMonitorTask.java deleted file mode 100644 index d4b442b..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/TimeMonitorTask.java +++ /dev/null @@ -1,46 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon; - -import java.util.Random; -import org.bukkit.World; -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; - -public class TimeMonitorTask implements Runnable { - - private final Random random; - private final BloodMoon plugin; - - public TimeMonitorTask(BloodMoon plugin) { - this.plugin = plugin; - this.random = new Random(); - } - - @Override - public void run() { - for (World world : plugin.getServer().getWorlds()) { - String worldName = world.getName(); - - if (plugin.isEnabled(worldName)) { - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (!worldConfig.getBoolean(Config.ALWAYS_ON)) { - long worldTime = world.getTime(); - - if (worldTime >= 13000 && worldTime <= 13100) { - if (plugin.forceWorlds.contains(worldName) || this.random.nextInt(100) < worldConfig.getInt(Config.CHANCE)) { - if (!plugin.isActive(worldName)) { - plugin.activate(worldName); - } - - plugin.forceWorlds.remove(worldName); - } - } else if (worldTime >= 23000 && worldTime <= 23100) { - if (plugin.isActive(worldName)) { - plugin.deactivate(worldName); - } - } - } - } - } - } - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/command/BloodMoonExecuter.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/command/BloodMoonExecuter.java deleted file mode 100644 index ed20126..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/command/BloodMoonExecuter.java +++ /dev/null @@ -1,201 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon.command; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.ChatColor; -import org.bukkit.World; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import uk.co.jacekk.bukkit.baseplugin.command.BaseCommandExecutor; -import uk.co.jacekk.bukkit.baseplugin.command.CommandHandler; -import uk.co.jacekk.bukkit.baseplugin.command.CommandTabCompletion; -import uk.co.jacekk.bukkit.baseplugin.command.SubCommandHandler; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Permission; - -public class BloodMoonExecuter extends BaseCommandExecutor { - - private final String specify_world; - private final String invalid_args_l; - private final String no_perm; - private final String no_perm_start; - private final String no_perm_stop; - private final String not_enabled_world; - - public BloodMoonExecuter(BloodMoon plugin) { - super(plugin); - this.specify_world = plugin.formatMessage(ChatColor.RED + "You must specify a world when using the command from the console"); - this.invalid_args_l = plugin.formatMessage(ChatColor.RED + "Invalid argument length"); - this.no_perm = plugin.formatMessage(ChatColor.RED + "You do not have permission use this command"); - this.no_perm_start = plugin.formatMessage(ChatColor.RED + "You do not have permission to start a bloodmoon"); - this.no_perm_stop = plugin.formatMessage(ChatColor.RED + "You do not have permission to stop a bloodmoon"); - this.not_enabled_world = plugin.formatMessage(ChatColor.RED + "The blood moon is not enabled for this world"); - } - - @CommandHandler(names = {"bloodmoon", "bm"}, description = "Toggles the bloodmoon for the current world.", usage = "[action] [world_name]") - @CommandTabCompletion({"start|next|stop|reload"}) - public void bloodmoon(CommandSender sender, String label, String[] args) { - sender.sendMessage(plugin.formatMessage(ChatColor.RED + "Usage: /" + label + " [action] [world_name]")); - sender.sendMessage(ChatColor.RED + "Actions:"); - - if (sender.hasPermission(Permission.ADMIN_START)) { - sender.sendMessage(ChatColor.RED + " start - Forces a bloodmoon to start"); - sender.sendMessage(ChatColor.RED + " next - Forces a bloodmoon to start at the next night"); - } - - if (sender.hasPermission(Permission.ADMIN_STOP)) { - sender.sendMessage(ChatColor.RED + " stop - Stops a bloodmoon"); - } - - if (sender.hasPermission(Permission.ADMIN_RELOAD)) { - sender.sendMessage(ChatColor.RED + " reload - Reloads the config."); - } - } - - private List activeWorldNames() { - ArrayList names = new ArrayList<>(plugin.getServer().getWorlds().size()); - for (World world : plugin.getServer().getWorlds()) { - String worldName = world.getName(); - if (plugin.isEnabled(worldName)) { - names.add(worldName); - } - } - return names; - } - - @SubCommandHandler(parent = "bloodmoon", name = "start") - @CommandTabCompletion({"[activeWorldNames]"}) - public void bloodmoonStart(CommandSender sender, String label, String[] args) { - if (sender.hasPermission(Permission.ADMIN_START)) { - String worldName; - if (sender instanceof Player) { - switch (args.length) { - case 0: - worldName = ((Player) sender).getWorld().getName(); - break; - case 1: - worldName = args[0]; - break; - default: - sender.sendMessage(invalid_args_l); - return; - } - } else { - switch (args.length) { - case 0: - sender.sendMessage(specify_world); - return; - case 1: - worldName = args[0]; - break; - default: - sender.sendMessage(invalid_args_l); - return; - } - } - if (plugin.isEnabled(worldName)) { - plugin.activate(worldName); - sender.sendMessage(ChatColor.GREEN + "Bloodmoon started in " + worldName); - } else { - sender.sendMessage(not_enabled_world); - } - } else { - sender.sendMessage(no_perm_start); - } - } - - @SubCommandHandler(parent = "bloodmoon", name = "next") - @CommandTabCompletion({"[activeWorldNames]"}) - public void bloodmoonNext(CommandSender sender, String label, String[] args) { - if (sender.hasPermission(Permission.ADMIN_START)) { - String worldName; - if (sender instanceof Player) { - switch (args.length) { - case 0: - worldName = ((Player) sender).getWorld().getName(); - break; - case 1: - worldName = args[0]; - break; - default: - sender.sendMessage(invalid_args_l); - return; - } - } else { - switch (args.length) { - case 0: - sender.sendMessage(specify_world); - return; - case 1: - worldName = args[0]; - break; - default: - sender.sendMessage(invalid_args_l); - return; - } - } - if (plugin.isEnabled(worldName)) { - plugin.forceNextNight(worldName); - sender.sendMessage(ChatColor.GREEN + "Bloodmoon forced in " + worldName); - } else { - sender.sendMessage(not_enabled_world); - } - } else { - sender.sendMessage(no_perm_start); - } - } - - @SubCommandHandler(parent = "bloodmoon", name = "stop") - @CommandTabCompletion({"[activeWorldNames]"}) - public void bloodmoonStop(CommandSender sender, String label, String[] args) { - if (sender.hasPermission(Permission.ADMIN_STOP)) { - String worldName; - if (sender instanceof Player) { - switch (args.length) { - case 0: - worldName = ((Player) sender).getWorld().getName(); - break; - case 1: - worldName = args[0]; - break; - default: - sender.sendMessage(invalid_args_l); - return; - } - } else { - switch (args.length) { - case 0: - sender.sendMessage(specify_world); - return; - case 1: - worldName = args[0]; - break; - default: - sender.sendMessage(invalid_args_l); - return; - } - } - if (plugin.isEnabled(worldName)) { - plugin.deactivate(worldName); - sender.sendMessage(ChatColor.GREEN + "Bloodmoon stopped in " + worldName); - } else { - sender.sendMessage(not_enabled_world); - } - } else { - sender.sendMessage(no_perm_stop); - } - } - - @SubCommandHandler(parent = "bloodmoon", name = "reload") - public void bloodmoonReload(CommandSender sender, String label, String[] args) { - if (sender.hasPermission(Permission.ADMIN_RELOAD)) { - plugin.reloadWorldConfig(); - sender.sendMessage(ChatColor.GREEN + "Config reloaded for all worlds."); - } else { - sender.sendMessage(no_perm); - } - } - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityBlaze.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityBlaze.java deleted file mode 100644 index a9daf9e..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityBlaze.java +++ /dev/null @@ -1,36 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon.entity; - -import net.minecraft.server.v1_8_R3.EntityHuman; -import net.minecraft.server.v1_8_R3.EntityMonster; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; - -public class BloodMoonEntityBlaze extends BloodMoonEntityMonster { - - public BloodMoonEntityBlaze(BloodMoon plugin, EntityMonster nmsEntity, BloodMoonEntityType type) { - super(plugin, nmsEntity, type); - } - - @Override - public void onTick() { - String worldName = getWorldName(); - String entityName = getEntityType().name().toUpperCase(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (nmsEntity.getGoalTarget() instanceof EntityHuman && plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.BREAK_BLOCKS) && worldConfig.getStringList(Config.FEATURE_BREAK_BLOCKS_MOBS).contains(entityName) && nmsEntity.world.getTime() % 20 == 0 && nmsEntity.world.worldData.getName().equals(nmsEntity.getGoalTarget().world.worldData.getName())) { - Block[] blocks = new Block[2]; - - blocks[0] = this.getBreakableTargetBlock(); - blocks[1] = blocks[0].getRelative(BlockFace.DOWN); - - for (Block block : blocks) { - this.attemptBreakBlock(worldConfig, block); - } - } - } - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityCreeper.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityCreeper.java deleted file mode 100644 index 6d53df2..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityCreeper.java +++ /dev/null @@ -1,36 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon.entity; - -import net.minecraft.server.v1_8_R3.EntityHuman; -import net.minecraft.server.v1_8_R3.EntityMonster; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; - -public class BloodMoonEntityCreeper extends BloodMoonEntityMonster { - - public BloodMoonEntityCreeper(BloodMoon plugin, EntityMonster nmsEntity, BloodMoonEntityType type) { - super(plugin, nmsEntity, type); - } - - @Override - public void onTick() { - String worldName = getWorldName(); - String entityName = getEntityType().name().toUpperCase(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (nmsEntity.getGoalTarget() instanceof EntityHuman && plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.BREAK_BLOCKS) && worldConfig.getStringList(Config.FEATURE_BREAK_BLOCKS_MOBS).contains(entityName) && nmsEntity.world.getTime() % 20 == 0 && nmsEntity.world.worldData.getName().equals(nmsEntity.getGoalTarget().world.worldData.getName())) { - Block[] blocks = new Block[2]; - - blocks[0] = this.getBreakableTargetBlock(); - blocks[1] = blocks[0].getRelative(BlockFace.DOWN); - - for (Block block : blocks) { - this.attemptBreakBlock(worldConfig, block); - } - } - } - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityLiving.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityLiving.java deleted file mode 100644 index 4b69c66..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityLiving.java +++ /dev/null @@ -1,129 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon.entity; - -import java.util.Random; -import java.util.UUID; - -import net.minecraft.server.v1_8_R3.AttributeInstance; -import net.minecraft.server.v1_8_R3.AttributeModifier; -import net.minecraft.server.v1_8_R3.EntityLiving; -import net.minecraft.server.v1_8_R3.GenericAttributes; -import org.bukkit.Location; -import org.bukkit.World; - -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; - -import uk.co.jacekk.bukkit.baseplugin.util.ReflectionUtils; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; - -public abstract class BloodMoonEntityLiving { - - private static final UUID maxHealthUID = UUID.fromString("f8b0a945-2d6a-4bdb-9a6f-59c285bf1e5d"); - private static final UUID followRangeUID = UUID.fromString("1737400d-3c18-41ba-8314-49a158481e1e"); - private static final UUID knockbackResistanceUID = UUID.fromString("8742c557-fcd5-4079-a462-b58db99b0f2c"); - private static final UUID movementSpeedUID = UUID.fromString("206a89dc-ae78-4c4d-b42c-3b31db3f5a7c"); - private static final UUID attackDamageUID = UUID.fromString("7bbe3bb1-079d-4150-ac6f-669e71550776"); - - protected BloodMoon plugin; - protected EntityLiving nmsEntity; - protected Entity bukkitEntity; - protected BloodMoonEntityType type; - - protected Random rand = new Random(); - - public BloodMoonEntityLiving(BloodMoon plugin, EntityLiving nmsEntity, BloodMoonEntityType type) { - this.plugin = plugin; - this.nmsEntity = nmsEntity; - this.bukkitEntity = nmsEntity.getBukkitEntity(); - this.type = type; - } - - public static BloodMoonEntityLiving getBloodMoonEntity(EntityLiving nmsEntity) { - try { - return ReflectionUtils.getFieldValue(nmsEntity.getClass(), "bloodMoonEntity", BloodMoonEntityLiving.class, nmsEntity); - } catch (Exception e) { - throw new IllegalArgumentException(nmsEntity.getClass().getName() + " not supported"); - } - } - - public void setFollowRangeMultiplier(double multiplier) { - AttributeInstance attributes = this.nmsEntity.getAttributeInstance(GenericAttributes.FOLLOW_RANGE); - AttributeModifier modifier = new AttributeModifier(followRangeUID, "BloodMoon follow range multiplier", multiplier, 1); - - attributes.c(modifier); - attributes.b(modifier); - } - - public void clearFollowRangeMultiplier() { - AttributeInstance attributes = this.nmsEntity.getAttributeInstance(GenericAttributes.FOLLOW_RANGE); - AttributeModifier modifier = new AttributeModifier(followRangeUID, "BloodMoon follow range multiplier", 1.0d, 1); - - attributes.c(modifier); - } - - public void setKnockbackResistanceMultiplier(double multiplier) { - AttributeInstance attributes = this.nmsEntity.getAttributeInstance(GenericAttributes.c); - //AttributeModifier modifier = new AttributeModifier(knockbackResistanceUID, "BloodMoon knockback resistance multiplier", multiplier, 1); - - //attributes.c(modifier); - //attributes.b(modifier); - } - - public void clearKnockbackResistanceMultiplier() { - AttributeInstance attributes = this.nmsEntity.getAttributeInstance(GenericAttributes.c); - //AttributeModifier modifier = new AttributeModifier(knockbackResistanceUID, "BloodMoon knockback resistance multiplier", , 1); - attributes.setValue(1.0d); - //attributes.c(modifier); - } - - public void setSpeedMultiplier(double multiplier) { - try { - AttributeInstance theAttribute = this.nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED); - if (theAttribute == null) { - System.err.println("That was null, wierd"); - return; - } - double oldValue = theAttribute.getValue(); - theAttribute.setValue(oldValue * multiplier); - if (BloodMoon.DEBUG) { - System.err.println("Set speed attribute for mob " + this.nmsEntity.getName() + " was " + oldValue + " and is now " + theAttribute.getValue()); - } - } catch (NullPointerException e) { - System.err.println("Null Exception"); - } - - //AttributeInstance attributes = this.nmsEntity.getAttributeInstance(GenericAttributes.d); - //AttributeModifier modifier = new AttributeModifier(movementSpeedUID, "BloodMoon movement speed multiplier", multiplier, 1); - //attributes.c(modifier); - //attributes.b(modifier); - } - - public void clearSpeedMultiplier() { - AttributeInstance attributes = this.nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED); - AttributeModifier modifier = new AttributeModifier(movementSpeedUID, "BloodMoon movement speed multiplier", 1.0d, 1); - - attributes.c(modifier); - } - - //public abstract void onTick(); - public void onTick() { - - } - - public World getBukkitWorld() { - return nmsEntity.getWorld().getWorld(); - } - - public String getWorldName() { - return nmsEntity.getWorld().getWorld().getName(); - } - - public Location getLocation() { - return bukkitEntity.getLocation(); - } - - public EntityType getEntityType() { - return bukkitEntity.getType(); - } - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityMonster.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityMonster.java deleted file mode 100644 index e2b2d1b..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityMonster.java +++ /dev/null @@ -1,74 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon.entity; - -import net.minecraft.server.v1_8_R3.EntityMonster; -import org.bukkit.Effect; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.block.Block; -import org.bukkit.event.entity.EntityChangeBlockEvent; -import org.bukkit.inventory.ItemStack; -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; - -public abstract class BloodMoonEntityMonster extends BloodMoonEntityLiving { - - protected EntityMonster nmsEntity; - - public BloodMoonEntityMonster(BloodMoon plugin, EntityMonster nmsEntity, BloodMoonEntityType type) { - super(plugin, nmsEntity, type); - - this.nmsEntity = nmsEntity; - } - - protected Block getBreakableTargetBlock() { - Location direction = nmsEntity.getGoalTarget().getBukkitEntity().getLocation().subtract(bukkitEntity.getLocation()); - - double dx = direction.getX(); - double dz = direction.getY(); - - int bdx = 0; - int bdz = 0; - - if (Math.abs(dx) > Math.abs(dz)) { - bdx = (dx > 0) ? 1 : -1; - } else { - bdz = (dx > 0) ? 1 : -1; - } - - return nmsEntity.world.getWorld().getBlockAt((int) Math.floor(nmsEntity.locX + bdx), (int) Math.floor(nmsEntity.locY), (int) Math.floor(nmsEntity.locZ + bdz)); - } - - protected void attemptBreakBlock(PluginConfig worldConfig, Block block) { - Material type = block.getType(); - - if (type != Material.AIR && worldConfig.getStringList(Config.FEATURE_BREAK_BLOCKS_BLOCKS).contains(type.name())) { - Location location = block.getLocation(); - - if (this.rand.nextInt(100) < 80) { - if (this.rand.nextInt(100) < 50) { - nmsEntity.world.getWorld().playSound(location, Sound.ZOMBIE_WOOD, Math.min(this.rand.nextFloat() + 0.2f, 1.0f), 1.0f); - } - } else { - EntityChangeBlockEvent event = new EntityChangeBlockEvent(bukkitEntity, block, Material.AIR, (byte) 0); - plugin.getServer().getPluginManager().callEvent(event); - - if (!event.isCancelled()) { - nmsEntity.world.getWorld().playEffect(location, Effect.ZOMBIE_DESTROY_DOOR, 0); - - if (worldConfig.getBoolean(Config.FEATURE_BREAK_BLOCKS_REALISTIC_DROP)) { - block.breakNaturally(); - } else { - block.setType(Material.AIR); - - if (worldConfig.getBoolean(Config.FEATURE_BREAK_BLOCKS_DROP_ITEMS)) { - nmsEntity.world.getWorld().dropItemNaturally(location, new ItemStack(type, 1, block.getData())); - } - } - } - } - } - } - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntitySkeleton.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntitySkeleton.java deleted file mode 100644 index ba2d209..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntitySkeleton.java +++ /dev/null @@ -1,36 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon.entity; - -import net.minecraft.server.v1_8_R3.EntityHuman; -import net.minecraft.server.v1_8_R3.EntityMonster; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; - -public class BloodMoonEntitySkeleton extends BloodMoonEntityMonster { - - public BloodMoonEntitySkeleton(BloodMoon plugin, EntityMonster nmsEntity, BloodMoonEntityType type) { - super(plugin, nmsEntity, type); - } - - @Override - public void onTick() { - String worldName = getWorldName(); - String entityName = getEntityType().name().toUpperCase(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (nmsEntity.getGoalTarget() instanceof EntityHuman && plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.BREAK_BLOCKS) && worldConfig.getStringList(Config.FEATURE_BREAK_BLOCKS_MOBS).contains(entityName) && nmsEntity.world.getTime() % 20 == 0 && nmsEntity.world.worldData.getName().equals(nmsEntity.getGoalTarget().world.worldData.getName())) { - Block[] blocks = new Block[2]; - - blocks[0] = this.getBreakableTargetBlock(); - blocks[1] = blocks[0].getRelative(BlockFace.DOWN); - - for (Block block : blocks) { - this.attemptBreakBlock(worldConfig, block); - } - } - } - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntitySpider.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntitySpider.java deleted file mode 100644 index 4c8a778..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntitySpider.java +++ /dev/null @@ -1,27 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon.entity; - -import net.minecraft.server.v1_8_R3.EntityHuman; -import net.minecraft.server.v1_8_R3.EntityMonster; -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; - -public class BloodMoonEntitySpider extends BloodMoonEntityMonster { - - public BloodMoonEntitySpider(BloodMoon plugin, EntityMonster nmsEntity, BloodMoonEntityType type) { - super(plugin, nmsEntity, type); - } - - @Override - public void onTick() { - String worldName = getWorldName(); - String entityName = getEntityType().name().toUpperCase(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (nmsEntity.getGoalTarget() instanceof EntityHuman && plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.BREAK_BLOCKS) && worldConfig.getStringList(Config.FEATURE_BREAK_BLOCKS_MOBS).contains(entityName) && nmsEntity.world.getTime() % 20 == 0 && nmsEntity.world.worldData.getName().equals(nmsEntity.getGoalTarget().world.worldData.getName())) { - this.attemptBreakBlock(worldConfig, this.getBreakableTargetBlock()); - } - } - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityType.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityType.java deleted file mode 100644 index daf9b42..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityType.java +++ /dev/null @@ -1,138 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon.entity; - -import net.minecraft.server.v1_8_R3.*; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; -import org.bukkit.entity.EntityType; -import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; -import uk.co.jacekk.bukkit.baseplugin.util.ReflectionUtils; -import uk.co.jacekk.bukkit.bloodmoon.exceptions.EntityRegistrationException; - -import java.util.List; -import java.util.Map; - -public enum BloodMoonEntityType { - - CREEPER("Creeper", 50, EntityType.CREEPER, net.minecraft.server.v1_8_R3.EntityCreeper.class, uk.co.jacekk.bukkit.bloodmoon.nms.EntityCreeper.class), - ENDERMAN("Enderman", 58, EntityType.ENDERMAN, net.minecraft.server.v1_8_R3.EntityEnderman.class, uk.co.jacekk.bukkit.bloodmoon.nms.EntityEnderman.class), - SKELETON("Skeleton", 51, EntityType.SKELETON, net.minecraft.server.v1_8_R3.EntitySkeleton.class, uk.co.jacekk.bukkit.bloodmoon.nms.EntitySkeleton.class), - SPIDER("Spider", 52, EntityType.SPIDER, net.minecraft.server.v1_8_R3.EntitySpider.class, uk.co.jacekk.bukkit.bloodmoon.nms.EntitySpider.class), - ZOMBIE("Zombie", 54, EntityType.ZOMBIE, net.minecraft.server.v1_8_R3.EntityZombie.class, uk.co.jacekk.bukkit.bloodmoon.nms.EntityZombie.class), - GHAST("Ghast", 56, EntityType.GHAST, net.minecraft.server.v1_8_R3.EntityGhast.class, uk.co.jacekk.bukkit.bloodmoon.nms.EntityGhast.class), - BLAZE("Blaze", 61, EntityType.BLAZE, net.minecraft.server.v1_8_R3.EntityBlaze.class, uk.co.jacekk.bukkit.bloodmoon.nms.EntityBlaze.class), - WITHER("WitherBoss", 64, EntityType.WITHER, net.minecraft.server.v1_8_R3.EntityWither.class, uk.co.jacekk.bukkit.bloodmoon.nms.EntityWither.class), - WITCH("Witch", 66, EntityType.WITCH, net.minecraft.server.v1_8_R3.EntityWitch.class, uk.co.jacekk.bukkit.bloodmoon.nms.EntityWitch.class), - GIANT_ZOMBIE("Giant", 53, EntityType.GIANT, net.minecraft.server.v1_8_R3.EntityGiantZombie.class, uk.co.jacekk.bukkit.bloodmoon.nms.EntityGiantZombie.class); - - private final String name; - private final int id; - private final EntityType entityType; - private final Class nmsClass; - private final Class bloodMoonClass; - - private static boolean registered = false; - - private BloodMoonEntityType(String name, int id, EntityType entityType, Class nmsClass, Class bloodMoonClass) { - this.name = name; - this.id = id; - this.entityType = entityType; - this.nmsClass = nmsClass; - this.bloodMoonClass = bloodMoonClass; - } - - @SuppressWarnings("unchecked") - public static void registerEntities() throws EntityRegistrationException { - if (registered) { - throw new EntityRegistrationException("Already registered."); - } - - Map> nameMap; - Map> idMap; - - try { - nameMap = ReflectionUtils.getFieldValue(EntityTypes.class, "c", Map.class, null); - idMap = ReflectionUtils.getFieldValue(EntityTypes.class, "e", Map.class, null); - } catch (Exception e) { - throw new EntityRegistrationException("Failed to get existing entity maps.", e); - } - - for (BloodMoonEntityType entity : values()) { - try { - nameMap.remove(entity.getName()); - idMap.remove(entity.getID()); - - ReflectionUtils.invokeMethod(EntityTypes.class, "a", Void.class, null, new Class[]{Class.class, String.class, int.class}, new Object[]{entity.getBloodMoonClass(), entity.getName(), entity.getID()}); - } catch (Exception e) { - throw new EntityRegistrationException("Failed to call EntityTypes.a() for " + entity.getName(), e); - } - } - - for (BiomeBase biomeBase : BiomeBase.getBiomes()) { - if (biomeBase == null) { - break; - } - - //for (String field : new String[]{"as", "at", "au", "av"}){ - for (String field : new String[]{"at", "au", "av", "aw"}) { - try { - //System.out.println(field); - List mobList = ReflectionUtils.getFieldValue(BiomeBase.class, field, List.class, biomeBase); -// @SuppressWarnings("unchecked") - //List mobList = (List) ReflectionUtils.getFieldValue(BiomeBase.class, field, BiomeBase.class, biomeBase); - - for (BiomeBase.BiomeMeta meta : mobList) { - for (BloodMoonEntityType entity : values()) { - if (entity.getNMSClass().equals(meta.b)) { - meta.b = entity.getBloodMoonClass(); - } - } - } - } catch (Exception e) { - throw new EntityRegistrationException("Failed to modify biome data field " + field, e); - } - } - } - - registered = true; - } - - public String getName() { - return this.name; - } - - public int getID() { - return this.id; - } - - public EntityType getEntityType() { - return this.entityType; - } - - public Class getNMSClass() { - return this.nmsClass; - } - - public Class getBloodMoonClass() { - return this.bloodMoonClass; - } - - private EntityInsentient createEntity(World world) { - try { - return this.getBloodMoonClass().getConstructor(World.class).newInstance(world); - } catch (Exception e) { - e.printStackTrace(); - } - - return null; - } - - public void spawnEntity(Location location) { - World world = ((CraftWorld) location.getWorld()).getHandle(); - - EntityInsentient entity = this.createEntity(world); - entity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); - world.addEntity(entity, SpawnReason.CUSTOM); - entity.p(null); - } - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityWitch.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityWitch.java deleted file mode 100644 index 36ef2ed..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityWitch.java +++ /dev/null @@ -1,37 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon.entity; - -import net.minecraft.server.v1_8_R3.EntityHuman; -import net.minecraft.server.v1_8_R3.EntityMonster; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; - -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; - -public class BloodMoonEntityWitch extends BloodMoonEntityMonster { - - public BloodMoonEntityWitch(BloodMoon plugin, EntityMonster nmsEntity, BloodMoonEntityType type) { - super(plugin, nmsEntity, type); - } - - @Override - public void onTick() { - String worldName = getWorldName(); - String entityName = getEntityType().name().toUpperCase(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (nmsEntity.getGoalTarget() instanceof EntityHuman && plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.BREAK_BLOCKS) && worldConfig.getStringList(Config.FEATURE_BREAK_BLOCKS_MOBS).contains(entityName) && nmsEntity.world.getTime() % 20 == 0 && nmsEntity.world.worldData.getName().equals(nmsEntity.getGoalTarget().world.worldData.getName())) { - Block[] blocks = new Block[2]; - - blocks[0] = this.getBreakableTargetBlock(); - blocks[1] = blocks[0].getRelative(BlockFace.DOWN); - - for (Block block : blocks) { - this.attemptBreakBlock(worldConfig, block); - } - } - } - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityZombie.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityZombie.java deleted file mode 100644 index 0e397df..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/entity/BloodMoonEntityZombie.java +++ /dev/null @@ -1,36 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon.entity; - -import net.minecraft.server.v1_8_R3.EntityHuman; -import net.minecraft.server.v1_8_R3.EntityMonster; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; - -public class BloodMoonEntityZombie extends BloodMoonEntityMonster { - - public BloodMoonEntityZombie(BloodMoon plugin, EntityMonster nmsEntity, BloodMoonEntityType type) { - super(plugin, nmsEntity, type); - } - - @Override - public void onTick() { - String worldName = getWorldName(); - String entityName = getEntityType().name().toUpperCase(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (nmsEntity.getGoalTarget() instanceof EntityHuman && plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.BREAK_BLOCKS) && worldConfig.getStringList(Config.FEATURE_BREAK_BLOCKS_MOBS).contains(entityName) && nmsEntity.world.getTime() % 20 == 0 && nmsEntity.world.worldData.getName().equals(nmsEntity.getGoalTarget().world.worldData.getName())) { - Block[] blocks = new Block[2]; - - blocks[0] = this.getBreakableTargetBlock(); - blocks[1] = blocks[0].getRelative(BlockFace.UP); - - for (Block block : blocks) { - this.attemptBreakBlock(worldConfig, block); - } - } - } - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/client/ChatMessageListener.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/client/ChatMessageListener.java deleted file mode 100644 index 6f1bcec..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/client/ChatMessageListener.java +++ /dev/null @@ -1,104 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.client; - -import java.util.UUID; -import org.bukkit.ChatColor; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerChangedWorldEvent; -import org.bukkit.event.player.PlayerJoinEvent; - -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.baseplugin.event.BaseListener; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonEndEvent; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonStartEvent; - -public class ChatMessageListener extends BaseListener { - - public ChatMessageListener(BloodMoon plugin) { - super(plugin); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onBloodMoonStart(BloodMoonStartEvent event) { - World world = event.getWorld(); - String worldName = world.getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (plugin.isFeatureEnabled(worldName, Feature.CHAT_MESSAGE)) { - String message = worldConfig.getString(Config.FEATURE_CHAT_MESSAGE_START_MESSAGE); - - if (!message.isEmpty()) { - for (Player player : world.getPlayers()) { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); - } - } - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onPlayerChangedWorld(PlayerChangedWorldEvent event) { - Player player = event.getPlayer(); - String worldName = player.getWorld().getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (plugin.isFeatureEnabled(worldName, Feature.CHAT_MESSAGE)) { - String message = worldConfig.getString(Config.FEATURE_CHAT_MESSAGE_START_MESSAGE); - - if (!message.isEmpty()) { - if (plugin.isActive(worldName)) { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); - } - } - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onPlayerJoin(PlayerJoinEvent event) { - Player player = event.getPlayer(); - String worldName = player.getWorld().getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.CHAT_MESSAGE)) { - final UUID playerUUID = player.getUniqueId(); - final String message = worldConfig.getString(Config.FEATURE_CHAT_MESSAGE_START_MESSAGE); - - if (!message.isEmpty()) { - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - - @Override - public void run() { - Player player = plugin.getServer().getPlayer(playerUUID); - - if (player != null) { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); - } - } - - }, 40L); - } - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onEnd(BloodMoonEndEvent event) { - World world = event.getWorld(); - String worldName = world.getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (plugin.isFeatureEnabled(worldName, Feature.CHAT_MESSAGE)) { - String message = worldConfig.getString(Config.FEATURE_CHAT_MESSAGE_END_MESSAGE); - - if (!message.isEmpty()) { - for (Player player : world.getPlayers()) { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); - } - } - } - } - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/client/PlaySoundListener.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/client/PlaySoundListener.java deleted file mode 100644 index ad55b5d..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/client/PlaySoundListener.java +++ /dev/null @@ -1,73 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.client; - -import java.util.UUID; -import org.bukkit.Sound; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerChangedWorldEvent; -import org.bukkit.event.player.PlayerJoinEvent; - -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.baseplugin.event.BaseListener; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonStartEvent; - -public class PlaySoundListener extends BaseListener { - - public PlaySoundListener(BloodMoon plugin) { - super(plugin); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onBloodMoonStart(BloodMoonStartEvent event) { - World world = event.getWorld(); - String worldName = world.getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (plugin.isFeatureEnabled(worldName, Feature.PLAY_SOUND)) { - for (Player player : event.getWorld().getPlayers()) { - player.playSound(player.getLocation(), Sound.valueOf(worldConfig.getString(Config.FEATURE_PLAY_SOUND_SOUND)), (float) worldConfig.getDouble(Config.FEATURE_PLAY_SOUND_VOLUME), (float) worldConfig.getDouble(Config.FEATURE_PLAY_SOUND_PITCH)); - } - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onPlayerChangedWorld(PlayerChangedWorldEvent event) { - Player player = event.getPlayer(); - String worldName = player.getWorld().getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.PLAY_SOUND)) { - player.playSound(player.getLocation(), Sound.valueOf(worldConfig.getString(Config.FEATURE_PLAY_SOUND_SOUND)), (float) worldConfig.getDouble(Config.FEATURE_PLAY_SOUND_VOLUME), (float) worldConfig.getDouble(Config.FEATURE_PLAY_SOUND_PITCH)); - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onPlayerJoin(PlayerJoinEvent event) { - Player player = event.getPlayer(); - String worldName = player.getWorld().getName(); - final PluginConfig worldConfig = plugin.getConfig(worldName); - - if (plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.PLAY_SOUND)) { - final UUID playerUUID = player.getUniqueId(); - - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - - @Override - public void run() { - Player player = plugin.getServer().getPlayer(playerUUID); - - if (player != null) { - player.playSound(player.getLocation(), Sound.valueOf(worldConfig.getString(Config.FEATURE_PLAY_SOUND_SOUND)), (float) worldConfig.getDouble(Config.FEATURE_PLAY_SOUND_VOLUME), (float) worldConfig.getDouble(Config.FEATURE_PLAY_SOUND_PITCH)); - } - } - - }, 40L); - } - } - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/client/TexturePackListener.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/client/TexturePackListener.java deleted file mode 100644 index 6bf2b3d..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/client/TexturePackListener.java +++ /dev/null @@ -1,102 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.client; - -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerChangedWorldEvent; -import org.bukkit.event.player.PlayerJoinEvent; - -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.baseplugin.event.BaseListener; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonEndEvent; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonStartEvent; - -public class TexturePackListener extends BaseListener { - - public TexturePackListener(BloodMoon plugin) { - super(plugin); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onBloodMoonStart(BloodMoonStartEvent event) { - final World world = event.getWorld(); - - if (plugin.isFeatureEnabled(world.getName(), Feature.TEXTURE_PACK)) { - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - - @Override - public void run() { - sendResourcePack(world, true); - } - }); - - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onBloodMoonEnd(BloodMoonEndEvent event) { - final World world = event.getWorld(); - - if (plugin.isFeatureEnabled(world.getName(), Feature.TEXTURE_PACK)) { - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - - @Override - public void run() { - sendResourcePack(world, false); - } - }); - - } - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onPlayerChangedWorld(PlayerChangedWorldEvent event) { - Player player = event.getPlayer(); - String fromName = event.getFrom().getName(); - String toName = player.getWorld().getName(); - PluginConfig worldConfig = plugin.getConfig(toName); - - if (plugin.isFeatureEnabled(toName, Feature.TEXTURE_PACK)) { - if (!plugin.isActive(fromName) && plugin.isActive(toName)) { - player.setResourcePack(worldConfig.getString(Config.FEATURE_TEXTURE_PACK_BLOODMOON)); - } else if (plugin.isActive(fromName) && !plugin.isActive(toName)) { - player.setResourcePack(worldConfig.getString(Config.FEATURE_TEXTURE_PACK_NORMAL)); - } - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onPlayerJoin(PlayerJoinEvent event) { - Player player = event.getPlayer(); - String worldName = player.getWorld().getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.TEXTURE_PACK)) { - player.setResourcePack(worldConfig.getString(Config.FEATURE_TEXTURE_PACK_BLOODMOON)); - } - } - - /** - * Send the resource pack to all players in the specified world True - * - * @param world - * @param special true:TEXTURE_PACK_BLOODMOON false:TEXTURE_PACK_NORMAL - */ - public void sendResourcePack(World world, boolean special) { - PluginConfig worldConfig = plugin.getConfig(world.getName()); - String resource; - if (special) { - resource = worldConfig.getString(Config.FEATURE_TEXTURE_PACK_BLOODMOON); - } else { - resource = worldConfig.getString(Config.FEATURE_TEXTURE_PACK_NORMAL); - } - - for (Player player : world.getPlayers()) { - player.setResourcePack(resource); - } - } -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/DaylightProofMobsListener.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/DaylightProofMobsListener.java deleted file mode 100644 index ab7bc42..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/DaylightProofMobsListener.java +++ /dev/null @@ -1,36 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.mob; - -import org.bukkit.entity.EntityType; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityCombustEvent; - -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Feature; - -public class DaylightProofMobsListener implements Listener { - - private final BloodMoon plugin; - - public DaylightProofMobsListener(BloodMoon plugin) { - this.plugin = plugin; - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onEntityCombust(EntityCombustEvent event) { - String worldName = event.getEntity().getWorld().getName(); - EntityType type = event.getEntityType(); - - if (type == EntityType.ZOMBIE || type == EntityType.SKELETON) { - if (plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.DAYLIGHT_PROOF_MOBS)) { - event.setCancelled(true); - } - } - - } - -} - - -//Class score 10/10 diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/MaxHealthListener.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/MaxHealthListener.java deleted file mode 100644 index 929a8ce..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/MaxHealthListener.java +++ /dev/null @@ -1,74 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.mob; - -import org.bukkit.World; -import org.bukkit.entity.LivingEntity; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.CreatureSpawnEvent; - -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonEndEvent; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonStartEvent; - -public class MaxHealthListener implements Listener { - - private final BloodMoon plugin; - - public MaxHealthListener(BloodMoon plugin) { - this.plugin = plugin; - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onStart(BloodMoonStartEvent event) { - World world = event.getWorld(); - String worldName = world.getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (plugin.isFeatureEnabled(worldName, Feature.MAX_HEALTH)) { - for (LivingEntity entity : world.getLivingEntities()) { - if (worldConfig.getStringList(Config.FEATURE_MAX_HEALTH_MOBS).contains(entity.getType().name())) { - double newMaxHealth = entity.getMaxHealth() * worldConfig.getDouble(Config.FEATURE_MAX_HEALTH_MULTIPLIER); - double damage = entity.getMaxHealth() - entity.getHealth(); - - entity.setMaxHealth(newMaxHealth); - entity.setHealth(Math.min(newMaxHealth - damage, newMaxHealth)); - } - } - } - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onCreatureSpawn(CreatureSpawnEvent event) { - LivingEntity entity = event.getEntity(); - String worldName = event.getLocation().getWorld().getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.MAX_HEALTH) && worldConfig.getStringList(Config.FEATURE_MAX_HEALTH_MOBS).contains(entity.getType().name())) { - double newMaxHealth = entity.getMaxHealth() * worldConfig.getDouble(Config.FEATURE_MAX_HEALTH_MULTIPLIER); - double damage = entity.getMaxHealth() - entity.getHealth(); - - entity.setMaxHealth(newMaxHealth); - entity.setHealth(Math.min(newMaxHealth - damage, newMaxHealth)); - } - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onStop(BloodMoonEndEvent event) { - World world = event.getWorld(); - String worldName = world.getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (plugin.isFeatureEnabled(worldName, Feature.MAX_HEALTH)) { - for (LivingEntity entity : world.getLivingEntities()) { - if (worldConfig.getStringList(Config.FEATURE_MAX_HEALTH_MOBS).contains(entity.getType().name())) { - entity.resetMaxHealth(); - } - } - } - } - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/MoreDropsListener.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/MoreDropsListener.java deleted file mode 100644 index d5b5d98..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/MoreDropsListener.java +++ /dev/null @@ -1,39 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.mob; - -import org.bukkit.entity.Creature; -import org.bukkit.entity.LivingEntity; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDeathEvent; -import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; -import org.bukkit.inventory.ItemStack; - -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; - -public class MoreDropsListener implements Listener { - - private final BloodMoon plugin; - - public MoreDropsListener(BloodMoon plugin) { - this.plugin = plugin; - } - - @EventHandler(priority = EventPriority.NORMAL) - public void onEntityDeath(EntityDeathEvent event) { - LivingEntity entity = event.getEntity(); - String worldName = entity.getWorld().getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (entity instanceof Creature && plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.MORE_DROPS)) { - if (!worldConfig.getBoolean(Config.FEATURE_MORE_DROPS_IGNORE_SPAWNERS) || plugin.getSpawnReason(entity) != SpawnReason.SPAWNER) { - for (ItemStack drop : event.getDrops()) { - drop.setAmount(drop.getAmount() * Math.max(worldConfig.getInt(Config.FEATURE_MORE_DROPS_MULTIPLIER), 0)); - } - } - } - } -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/MoreExpListener.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/MoreExpListener.java deleted file mode 100644 index fda9417..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/MoreExpListener.java +++ /dev/null @@ -1,37 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.mob; - -import org.bukkit.entity.Creature; -import org.bukkit.entity.LivingEntity; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; -import org.bukkit.event.entity.EntityDeathEvent; - -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; - -public class MoreExpListener implements Listener { - - private final BloodMoon plugin; - - public MoreExpListener(BloodMoon plugin) { - this.plugin = plugin; - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onEntityDeath(EntityDeathEvent event) { - LivingEntity entity = event.getEntity(); - String worldName = entity.getWorld().getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (entity instanceof Creature && plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.MORE_EXP)) { - if (!worldConfig.getBoolean(Config.FEATURE_MORE_EXP_IGNORE_SPAWNERS) || plugin.getSpawnReason(entity) != SpawnReason.SPAWNER) { - event.setDroppedExp(event.getDroppedExp() * Math.max(worldConfig.getInt(Config.FEATURE_MORE_EXP_MULTIPLIER), 0)); - } - } - } - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/MovementSpeedListener.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/MovementSpeedListener.java deleted file mode 100644 index e522861..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/MovementSpeedListener.java +++ /dev/null @@ -1,89 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.mob; - -import java.util.Random; - -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.CreatureSpawnEvent; - -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; -import uk.co.jacekk.bukkit.bloodmoon.entity.BloodMoonEntityLiving; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonEndEvent; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonStartEvent; - -public class MovementSpeedListener implements Listener { - - private final BloodMoon plugin; - private final Random random = new Random(); - - public MovementSpeedListener(BloodMoon plugin) { - this.plugin = plugin; - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onStart(BloodMoonStartEvent event) { - World world = event.getWorld(); - String worldName = world.getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (plugin.isFeatureEnabled(worldName, Feature.MOVEMENT_SPEED)) { - for (LivingEntity entity : world.getLivingEntities()) { - if (worldConfig.getStringList(Config.FEATURE_MOVEMENT_SPEED_MOBS).contains(entity.getType().name())) { - try { - BloodMoonEntityLiving bloodMoonEntity = BloodMoonEntityLiving.getBloodMoonEntity(((CraftLivingEntity) entity).getHandle()); - double multiplier = worldConfig.getDouble((this.random.nextInt(100) < worldConfig.getInt(Config.FEATURE_MOVEMENT_SPEED_FAST_CHANCE)) ? Config.FEATURE_MOVEMENT_SPEED_FAST_MULTIPLIER : Config.FEATURE_MOVEMENT_SPEED_MULTIPLIER); - bloodMoonEntity.setSpeedMultiplier(multiplier); - } catch (IllegalArgumentException e) { - // This means the entity is not supported *shrug* - } - } - } - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onStop(BloodMoonEndEvent event) { - World world = event.getWorld(); - String worldName = world.getName(); - - if (plugin.isFeatureEnabled(worldName, Feature.MOVEMENT_SPEED)) { - for (LivingEntity entity : world.getLivingEntities()) { - try { - BloodMoonEntityLiving.getBloodMoonEntity(((CraftLivingEntity) entity).getHandle()).clearSpeedMultiplier(); - } catch (IllegalArgumentException e) { - // This means the entity is not supported *shrug* - } - } - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onCreatureSpawn(CreatureSpawnEvent event) { - LivingEntity entity = event.getEntity(); - World world = entity.getWorld(); - String worldName = world.getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.MOVEMENT_SPEED)) { - if (worldConfig.getStringList(Config.FEATURE_MOVEMENT_SPEED_MOBS).contains(entity.getType().name())) { - try { - BloodMoonEntityLiving bloodMoonEntity = BloodMoonEntityLiving.getBloodMoonEntity(((CraftLivingEntity) entity).getHandle()); - //EntityInsentient sam = (EntityInsentient)((CraftLivingEntity) entity).getHandle(); - //System.err.println(bloodMoonEntity.toString() + "le mob"); - double multiplier = worldConfig.getDouble((this.random.nextInt(100) < worldConfig.getInt(Config.FEATURE_MOVEMENT_SPEED_FAST_CHANCE)) ? Config.FEATURE_MOVEMENT_SPEED_FAST_MULTIPLIER : Config.FEATURE_MOVEMENT_SPEED_MULTIPLIER); - bloodMoonEntity.setSpeedMultiplier(multiplier); - } catch (IllegalArgumentException e) { - // This means the entity is not supported *shrug* - } - } - } - } - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/SuperCreepersListener.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/SuperCreepersListener.java deleted file mode 100644 index 2c38a1e..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/mob/SuperCreepersListener.java +++ /dev/null @@ -1,83 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.mob; - -import org.bukkit.World; -import org.bukkit.entity.Creeper; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.LivingEntity; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.bukkit.event.entity.ExplosionPrimeEvent; - -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonEndEvent; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonStartEvent; - -public class SuperCreepersListener implements Listener { - - private final BloodMoon plugin; - - public SuperCreepersListener(BloodMoon plugin) { - this.plugin = plugin; - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onStart(BloodMoonStartEvent event) { - World world = event.getWorld(); - String worldName = world.getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (plugin.isFeatureEnabled(worldName, Feature.SUPER_CREEPERS) && worldConfig.getBoolean(Config.FEATURE_SUPER_CREEPERS_LIGHTNING)) { - for (LivingEntity entity : world.getLivingEntities()) { - if (entity.getType() == EntityType.CREEPER) { - ((Creeper) entity).setPowered(true); - } - } - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onStop(BloodMoonEndEvent event) { - World world = event.getWorld(); - String worldName = world.getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (plugin.isFeatureEnabled(worldName, Feature.SUPER_CREEPERS) && worldConfig.getBoolean(Config.FEATURE_SUPER_CREEPERS_LIGHTNING)) { - for (LivingEntity entity : world.getLivingEntities()) { - if (entity.getType() == EntityType.CREEPER) { - ((Creeper) entity).setPowered(false); - } - } - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onCreatureSpawn(CreatureSpawnEvent event) { - LivingEntity entity = event.getEntity(); - World world = entity.getWorld(); - String worldName = world.getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (entity.getType() == EntityType.CREEPER && plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.SUPER_CREEPERS) && worldConfig.getBoolean(Config.FEATURE_SUPER_CREEPERS_LIGHTNING)) { - ((Creeper)entity).setPowered(true); - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onExplosionPrime(ExplosionPrimeEvent event) { - if (event.getEntity() != null && event.getEntityType() == EntityType.CREEPER) { - String worldName = event.getEntity().getWorld().getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.SUPER_CREEPERS)) { - event.setRadius((float) worldConfig.getDouble(Config.FEATURE_SUPER_CREEPERS_POWER)); - event.setFire(worldConfig.getBoolean(Config.FEATURE_SUPER_CREEPERS_FIRE)); - } - } - } - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/spawning/MoreMobsListener.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/spawning/MoreMobsListener.java deleted file mode 100644 index 5230ae7..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/spawning/MoreMobsListener.java +++ /dev/null @@ -1,32 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.spawning; - -import org.bukkit.World; -import org.bukkit.entity.LivingEntity; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; - -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.baseplugin.event.BaseListener; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonEndEvent; - -public final class MoreMobsListener extends BaseListener { - - public MoreMobsListener(BloodMoon plugin) { - super(plugin); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onStop(BloodMoonEndEvent event) { - World world = event.getWorld(); - PluginConfig worldConfig = plugin.getConfig(world.getName()); - - for (LivingEntity entity : world.getLivingEntities()) { - if (worldConfig.getStringList(Config.FEATURE_SPAWN_CONTROL_SPAWN).contains(entity.getType().name())) { - entity.remove(); - } - } - } - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/spawning/MoreSpawningListener.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/spawning/MoreSpawningListener.java deleted file mode 100644 index a6d30b1..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/spawning/MoreSpawningListener.java +++ /dev/null @@ -1,48 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.spawning; - -import java.util.Random; - -import org.bukkit.entity.EntityType; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; - -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.baseplugin.event.BaseListener; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; -import uk.co.jacekk.bukkit.bloodmoon.entity.BloodMoonEntityType; - -public final class MoreSpawningListener extends BaseListener { - - private final Random random = new Random(); - - public MoreSpawningListener(BloodMoon plugin) { - super(plugin); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onCreatureSpawn(CreatureSpawnEvent event) { - if (event.getSpawnReason() != SpawnReason.NATURAL) { //TODO: Should check for Custom instead of checking against natural? - return; - } - - EntityType type = event.getEntityType(); - String worldName = event.getLocation().getWorld().getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.MORE_SPAWNING) && worldConfig.getStringList(Config.FEATURE_MORE_SPAWNING_MOBS).contains(type.getName().toUpperCase())) { - for (int i = 0; i < Math.max(worldConfig.getInt(Config.FEATURE_MORE_SPAWNING_MULTIPLIER), 1); ++i) { - for (BloodMoonEntityType bloodMoonEntity : BloodMoonEntityType.values()) { - if (type == bloodMoonEntity.getEntityType()) { - bloodMoonEntity.spawnEntity(event.getLocation().add((random.nextDouble() * 3) - 1.5, (random.nextDouble() * 3) - 1.5, (random.nextDouble() * 3) - 1.5)); - return; - } - } - } - } - } - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/spawning/SpawnOnSleepListener.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/spawning/SpawnOnSleepListener.java deleted file mode 100644 index 7536900..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/spawning/SpawnOnSleepListener.java +++ /dev/null @@ -1,39 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.spawning; - -import org.bukkit.World; -import org.bukkit.entity.EntityType; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerBedEnterEvent; - -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.baseplugin.event.BaseListener; -import uk.co.jacekk.bukkit.baseplugin.util.ListUtils; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; - -public final class SpawnOnSleepListener extends BaseListener { - - public SpawnOnSleepListener(BloodMoon plugin) { - super(plugin); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onPlayerBedEnter(PlayerBedEnterEvent event) { - World world = event.getPlayer().getWorld(); - String worldName = world.getName(); - - if (plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.SPAWN_ON_SLEEP)) { - PluginConfig worldConfig = plugin.getConfig(worldName); - String mobName = ListUtils.getRandom(worldConfig.getStringList(Config.FEATURE_SPAWN_ON_SLEEP_SPAWN)); - EntityType creatureType = EntityType.fromName(mobName.toUpperCase()); - - if (creatureType != null) { - //world.spawn(location, creatureType.getEntityClass(), SpawnReason.NATURAL); - world.spawnEntity(event.getPlayer().getLocation(), creatureType); - } - } - } - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/world/WeatherListener.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/world/WeatherListener.java deleted file mode 100644 index b45192a..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/feature/world/WeatherListener.java +++ /dev/null @@ -1,62 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon.feature.world; - -import java.util.Random; - -import org.bukkit.World; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.weather.WeatherChangeEvent; - -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.baseplugin.event.BaseListener; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.Feature; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonEndEvent; -import uk.co.jacekk.bukkit.bloodmoon.event.BloodMoonStartEvent; - -public class WeatherListener extends BaseListener { - - private final Random random = new Random(); - - public WeatherListener(BloodMoon plugin) { - super(plugin); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onStart(BloodMoonStartEvent event) { - World world = event.getWorld(); - String worldName = world.getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (plugin.isFeatureEnabled(worldName, Feature.WEATHER) && random.nextInt(100) < worldConfig.getInt(Config.FEATURE_WEATHER_CHANCE)) { - world.setStorm(worldConfig.getBoolean(Config.FEATURE_WEATHER_RAIN)); - world.setThundering(worldConfig.getBoolean(Config.FEATURE_WEATHER_THUNDER)); - - world.setWeatherDuration(10000); - world.setThunderDuration(10000); - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onStop(BloodMoonEndEvent event) { - World world = event.getWorld(); - String worldName = world.getName(); - - if (plugin.isFeatureEnabled(worldName, Feature.WEATHER)) { - world.setThundering(false); - world.setStorm(false); - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onWeatherChange(WeatherChangeEvent event) { - World world = event.getWorld(); - String worldName = world.getName(); - - if (plugin.isActive(worldName) && plugin.isFeatureEnabled(worldName, Feature.WEATHER)) { - event.setCancelled(true); - } - } - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/ChunkProviderServer.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/ChunkProviderServer.java deleted file mode 100644 index 1c369c7..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/ChunkProviderServer.java +++ /dev/null @@ -1,35 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon.nms; - -import net.minecraft.server.v1_8_R3.*; -import org.bukkit.entity.EntityType; -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; - -import java.util.ArrayList; -import java.util.List; - -public class ChunkProviderServer extends net.minecraft.server.v1_8_R3.ChunkProviderServer { - - private final BloodMoon plugin; - private final List bloodMoonMobs = new ArrayList<>(); - - public ChunkProviderServer(BloodMoon plugin, WorldServer worldserver, IChunkLoader ichunkloader, IChunkProvider ichunkprovider) { - super(worldserver, ichunkloader, ichunkprovider); - - this.plugin = plugin; - - PluginConfig worldConfig = this.plugin.getConfig(this.world.worldData.getName()); - - for (String name : worldConfig.getStringList(Config.FEATURE_SPAWN_CONTROL_SPAWN)) { - Class entityClass = EntityTypes.a(EntityType.valueOf(name).getTypeId()); - this.bloodMoonMobs.add(new BiomeBase.BiomeMeta((Class) entityClass, 10, 4, 4)); // Entity class, weight, minGroupSize, maxGroupSize - } - } - - @SuppressWarnings("unchecked") - public List getMobsFor(EnumCreatureType creatureType, int x, int y, int z) { - return (this.plugin.isActive(this.world.worldData.getName())) ? this.bloodMoonMobs : super.getMobsFor(creatureType, new BlockPosition(x, y, z)); - } - -} diff --git a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntitySkeleton.java b/src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntitySkeleton.java deleted file mode 100644 index 099213e..0000000 --- a/src/main/java/uk/co/jacekk/bukkit/bloodmoon/nms/EntitySkeleton.java +++ /dev/null @@ -1,156 +0,0 @@ -package uk.co.jacekk.bukkit.bloodmoon.nms; - -import java.util.List; -import net.minecraft.server.v1_8_R3.Enchantment; -import net.minecraft.server.v1_8_R3.EnchantmentManager; -import net.minecraft.server.v1_8_R3.EntityArrow; -import net.minecraft.server.v1_8_R3.EntityHuman; -import net.minecraft.server.v1_8_R3.IRangedEntity; -import net.minecraft.server.v1_8_R3.PathfinderGoalFleeSun; -import net.minecraft.server.v1_8_R3.PathfinderGoalFloat; -import net.minecraft.server.v1_8_R3.PathfinderGoalHurtByTarget; -import net.minecraft.server.v1_8_R3.PathfinderGoalLookAtPlayer; -import net.minecraft.server.v1_8_R3.PathfinderGoalNearestAttackableTarget; -import net.minecraft.server.v1_8_R3.PathfinderGoalRandomLookaround; -import net.minecraft.server.v1_8_R3.PathfinderGoalRandomStroll; -import net.minecraft.server.v1_8_R3.PathfinderGoalRestrictSun; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_8_R3.CraftServer; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftSkeleton; -import org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory; -import org.bukkit.event.entity.EntityCombustEvent; -import org.bukkit.event.entity.EntityShootBowEvent; -import org.bukkit.plugin.Plugin; -import uk.co.jacekk.bukkit.baseplugin.config.PluginConfig; -import uk.co.jacekk.bukkit.baseplugin.util.ReflectionUtils; -import uk.co.jacekk.bukkit.bloodmoon.BloodMoon; -import uk.co.jacekk.bukkit.bloodmoon.Config; -import uk.co.jacekk.bukkit.bloodmoon.entity.BloodMoonEntitySkeleton; -import uk.co.jacekk.bukkit.bloodmoon.entity.BloodMoonEntityType; - -//public class EntitySkeleton { -public class EntitySkeleton extends net.minecraft.server.v1_8_R3.EntitySkeleton implements IRangedEntity { - - private BloodMoon plugin; - private BloodMoonEntitySkeleton bloodMoonEntity; - - public EntitySkeleton(net.minecraft.server.v1_8_R3.World world) { - super(world); - - Plugin gPlugin = Bukkit.getPluginManager().getPlugin("BloodMoon"); - - if (gPlugin == null || !(gPlugin instanceof BloodMoon)) { - this.world.removeEntity(this); - return; - } - - this.plugin = (BloodMoon) gPlugin; - - this.bukkitEntity = new CraftSkeleton((CraftServer) this.plugin.getServer(), this); - this.bloodMoonEntity = new BloodMoonEntitySkeleton(this.plugin, this, BloodMoonEntityType.SKELETON); - - try { - ReflectionUtils.getFieldValue(this.goalSelector.getClass(), "b", List.class, this.goalSelector).clear(); - ReflectionUtils.getFieldValue(this.targetSelector.getClass(), "b", List.class, this.targetSelector).clear(); - - this.goalSelector.a(1, new PathfinderGoalFloat(this)); - this.goalSelector.a(2, new PathfinderGoalRestrictSun(this)); - this.goalSelector.a(3, new PathfinderGoalFleeSun(this, 1.0d)); - // NOTE: See bJ() below - this.goalSelector.a(5, new PathfinderGoalRandomStroll(this, 1.0d)); - this.goalSelector.a(6, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 8.0F)); - this.goalSelector.a(6, new PathfinderGoalRandomLookaround(this)); - - this.targetSelector.a(1, new PathfinderGoalHurtByTarget(this, false)); - this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget(this, EntityHuman.class, false, true)); - } catch (Exception e) { - e.printStackTrace(); - this.world.removeEntity(this); - } - } - -// @Override -// public GroupDataEntity prepare(GroupDataEntity entityData){ -// if (this.world.worldProvider instanceof WorldProviderHell && this.aI().nextInt(5) > 0){ -// this.goalSelector.a(4, new PathfinderGoalMeleeAttack(this, EntityHuman.class, 1.2d, false)); -// this.setSkeletonType(1); -// this.setEquipment(0, new ItemStack(Items.STONE_SWORD)); -// }else{ -// this.goalSelector.a(4, new PathfinderGoalArrowAttack(this.plugin, this, 1.0d, 20, 60, 15.0f)); -// -// this.bC(); -// this.bD(); -// } -// -// this.h(this.random.nextFloat() < 0.55F * this.world.b(this.locX, this.locY, this.locZ)); -// -// if (getEquipment(4) == null){ -// Calendar calendar = this.world.V(); -// -// if (calendar.get(2) + 1 == 10 && calendar.get(5) == 31 && this.random.nextFloat() < 0.25F){ -// setEquipment(4, new ItemStack(this.random.nextFloat() < 0.1F ? Blocks.JACK_O_LANTERN : Blocks.PUMPKIN)); -// this.dropChances[4] = 0.0F; -// } -// } -// -// return entityData; -// } -// @Override -// public boolean bL(){ -// try{ -// this.bloodMoonEntity.onTick(); -// super.bL(); -// }catch (Exception e){ -// plugin.log.warn("Exception caught while ticking entity"); -// e.printStackTrace(); -// } -// return true; -// } - @Override - public void a(net.minecraft.server.v1_8_R3.EntityLiving entityLiving, float f) { - - final EntityArrow entityarrow = new EntityArrow(this.world, this, entityLiving, 1.6f, 14 - this.world.getDifficulty().a() * 4); - int arrow_damage = EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_DAMAGE.id, bA());//assumming bz() - int knockback = EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_KNOCKBACK.id, bA()); //assumming bz() - entityarrow.b(f * 2.0F + this.random.nextGaussian() * 0.25D + this.world.getDifficulty().a() * 0.11F); - if (arrow_damage > 0) { - entityarrow.b(entityarrow.j() + arrow_damage * 0.5 + 0.5); - //set enchantment level - } - - if (knockback > 0) { - entityarrow.setKnockbackStrength(knockback); - } - - String worldName = this.world.worldData.getName(); - PluginConfig worldConfig = plugin.getConfig(worldName); - - if (plugin.isActive(worldName) && worldConfig.getBoolean(Config.FEATURE_FIRE_ARROWS_ENABLED) && (this.random.nextInt(100) < worldConfig.getInt(Config.FEATURE_FIRE_ARROWS_CHANCE)) - || (EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_FIRE.id, this.bA()) > 0 || this.getSkeletonType() == 1)) { - final EntityCombustEvent event = new EntityCombustEvent(entityarrow.getBukkitEntity(), 100); - this.world.getServer().getPluginManager().callEvent(event); - if (!event.isCancelled()) { - entityarrow.setOnFire(event.getDuration()); - } - } - -// if (plugin.isActive(worldName) && worldConfig.getBoolean(Config.FEATURE_FIRE_ARROWS_ENABLED) && (this.random.nextInt(100) < worldConfig.getInt(Config.FEATURE_FIRE_ARROWS_CHANCE))) { -// //if (EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_FIRE.id, this.bz()) > 0 || getSkeletonType() == 1) { -// //entityarrow.setOnFire(1024); -// //} -// } - final EntityShootBowEvent event2 = CraftEventFactory.callEntityShootBowEvent(this, this.bA(), entityarrow, 0.8f); - if (event2.isCancelled()) { - event2.getProjectile().remove(); - return; - } - if (event2.getProjectile() == entityarrow.getBukkitEntity()) { - this.world.addEntity(entityarrow); - } - this.makeSound("random.bow", 1.0f, 1.0f / (this.bc().nextFloat() * 0.4f + 0.8f)); - - //this.world.makeSound(this, "random.bow", 1.0F, 1.0F / (this.aI().nextFloat() * 0.4F + 0.8F)); - //world.makeSound(this, "random.bow", 1.0F, 1.0F / (random.nextFloat() * 0.4F + 0.8F)); - //this.world.addEntity(entityarrow); - } -} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index c8bc036..7c595dd 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,9 @@ name: "${project.name}" -version: "${project.version}-Samistine" -main: "uk.co.jacekk.bukkit.bloodmoon.BloodMoon" -load: startup +version: "${project.version}-${minecraft.version}" +main: "com.github.hexosse.bloodmoon.BloodMoon" + +load: STARTUP +softdepend: [MassiveCore, Factions] permissions: bloodmoon.admin.*: diff --git a/src/main/texture_pack/bloodmoon.zip b/src/main/texture_pack/bloodmoon.zip new file mode 100644 index 0000000..7acce90 Binary files /dev/null and b/src/main/texture_pack/bloodmoon.zip differ diff --git a/src/main/texture_pack/normal.zip b/src/main/texture_pack/normal.zip new file mode 100644 index 0000000..15cb0ec Binary files /dev/null and b/src/main/texture_pack/normal.zip differ