Minecraft 1.13.2 compatibility and optimizations

This commit is contained in:
mathias 2019-07-24 02:03:55 +03:00
parent b7c4d02f15
commit 68dbd1884d
5 changed files with 857 additions and 158 deletions

521
checkstyle.xml Normal file
View File

@ -0,0 +1,521 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<!--
If you set the basedir property below, then all reported file
names will be relative to the specified directory. See
https://checkstyle.org/config.html#Checker
<property name="basedir" value="${basedir}"/>
-->
<metadata name="org.checkstyle.principle" value="Practice What You Preach"/>
<metadata name="org.checkstyle.principle.description"
value="In our config we should use all Checks that Checkstyle has"/>
<property name="cacheFile" value="${checkstyle.cache.file}"/>
<property name="severity" value="error"/>
<property name="fileExtensions" value="java, properties, xml, vm, g, g4, dtd"/>
<!-- BeforeExecutionFileFilters is required for sources that are based on java9 -->
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$" />
</module>
<!-- Filters -->
<module name="SeverityMatchFilter">
<!-- report all violations except ignore -->
<property name="severity" value="ignore"/>
<property name="acceptOnMatch" value="false"/>
</module>
<module name="SuppressWithPlainTextCommentFilter">
<!--
Use suppressions.xml for suppressions, this is only example.
checkFormat will prevent suppression comments from being valid.
-->
<property name="checkFormat" value="IGNORETHIS"/>
<property name="offCommentFormat" value="CSOFF\: .*"/>
<property name="onCommentFormat" value="CSON\: .*"/>
</module>
<!-- Miscellaneous -->
<module name="NewlineAtEndOfFile"/>
<module name="Translation">
<property name="requiredTranslations" value="de, fr, fi, es, pt, ja, tr, zh"/>
</module>
<module name="UniqueProperties"/>
<!-- Regexp -->
<module name="RegexpMultiline"/>
<module name="RegexpMultiline">
<property name="format" value="\r?\n[\t ]*\r?\n[\t ]*\r?\n"/>
<property name="fileExtensions" value="java,xml,properties"/>
<property name="message" value="Unnecessary consecutive lines"/>
</module>
<module name="RegexpMultiline">
<property name="format" value="/\*\*\W+\* +\p{javaLowerCase}"/>
<property name="fileExtensions" value="java"/>
<property name="message"
value="First sentence in a comment should start with a capital letter"/>
</module>
<module name="RegexpSingleline">
<property name="format" value="\s+$"/>
<property name="minimum" value="0"/>
<property name="maximum" value="0"/>
</module>
<module name="RegexpSingleline">
<property name="format" value="/\*\* +\p{javaLowerCase}"/>
<property name="fileExtensions" value="java"/>
<property name="message"
value="First sentence in a comment should start with a capital letter"/>
</module>
<module name="RegexpSingleline">
<property name="format" value="^(?!(.*http|import)).{101,}$"/>
<property name="fileExtensions" value="g, g4"/>
<property name="message" value="Line should not be longer than 100 symbols"/>
</module>
<module name="RegexpSingleline">
<property name="format" value="^(?!(\s*&lt;a href=&quot;[^&quot;]+&quot;&gt;|.*http)).{101,}$"/>
<property name="fileExtensions" value="xml, vm"/>
<property name="message" value="Line should not be longer than 100 symbols"/>
</module>
<module name="RegexpSingleline">
<property name="id" value="noSourceforgeNetLinks"/>
<property name="format" value="checkstyle\.sourceforge\.net"/>
<property name="message"
value="Old site links should not be used, please use https://checkstyle.org"/>
</module>
<module name="RegexpSingleline">
<property name="id" value="noSourceforgeIoLinks"/>
<property name="format" value="checkstyle\.sourceforge\.io"/>
<property name="message"
value="Old site links should not be used, please use https://checkstyle.org"/>
</module>
<module name="RegexpOnFilename" />
<module name="RegexpOnFilename">
<property name="folderPattern" value="[\\/]src[\\/]\w+[\\/]java[\\/]"/>
<property name="fileNamePattern" value="\.java$"/>
<property name="match" value="false"/>
<message key="regexp.filepath.mismatch"
value="Only java files should be located in the ''src/*/java'' folders."/>
</module>
<module name="RegexpOnFilename">
<property name="folderPattern" value="[\\/]src[\\/]xdocs[\\/]"/>
<property name="fileNamePattern" value="\.(xml)|(vm)$"/>
<property name="match" value="false"/>
<message key="regexp.filepath.mismatch"
value="All files in the ''src/xdocs'' folder should have the ''xml'' or ''vm'' extension."/>
</module>
<module name="RegexpOnFilename">
<property name="folderPattern" value="[\\/]src[\\/]it[\\/]java[\\/]"/>
<property name="fileNamePattern" value="^((\w+Test)|(\w+TestSupport)|(Abstract\w+))\.java$"/>
<property name="match" value="false"/>
<message key="regexp.filepath.mismatch"
value="All files in the ''src/it/java'' folder
should be named ''*Test.java'' or ''Abstract*.java''."/>
</module>
<!-- Size Violations -->
<module name="FileLength">
<property name="fileExtensions" value="java"/>
</module>
<!-- Whitespace -->
<module name="TreeWalker">
<property name="tabWidth" value="4"/>
<!-- Annotations -->
<module name="AnnotationLocation">
<property name="tokens" value="ANNOTATION_DEF"/>
<property name="tokens" value="ANNOTATION_FIELD_DEF"/>
<property name="tokens" value="PACKAGE_DEF"/>
<property name="tokens" value="ENUM_CONSTANT_DEF"/>
<property name="tokens" value="VARIABLE_DEF"/>
<property name="allowSamelineSingleParameterlessAnnotation" value="false"/>
</module>
<module name="AnnotationOnSameLine">
<!-- we can not use it as it conflicts with AnnotationLocation -->
<property name="severity" value="ignore"/>
<property name="tokens" value="METHOD_DEF"/>
<property name="tokens" value="CTOR_DEF"/>
<property name="tokens" value="TYPECAST"/>
<property name="tokens" value="DOT"/>
<property name="tokens" value="CLASS_DEF"/>
<property name="tokens" value="ENUM_DEF"/>
<property name="tokens" value="INTERFACE_DEF"/>
<property name="tokens" value="TYPE_ARGUMENT"/>
<property name="tokens" value="ANNOTATION_DEF"/>
<property name="tokens" value="LITERAL_NEW"/>
<property name="tokens" value="LITERAL_THROWS"/>
<property name="tokens" value="VARIABLE_DEF"/>
<property name="tokens" value="PARAMETER_DEF"/>
<property name="tokens" value="IMPLEMENTS_CLAUSE"/>
<property name="tokens" value="ANNOTATION_FIELD_DEF"/>
</module>
<module name="AnnotationUseStyle"/>
<module name="MissingDeprecated"/>
<module name="MissingOverride"/>
<module name="PackageAnnotation"/>
<module name="SuppressWarnings">
<property name="format" value="^((?!unchecked|deprecation|rawtypes|resource).)*$"/>
<message key="suppressed.warning.not.allowed"
value="The warning ''{0}'' cannot be suppressed at this location.
Only few javac warnings are allowed to suppress.
If try to suppress checkstyle/pmd/..... violation please do this in their config file.
If you try to suppress IntelliJ IDEA inspection,
please use javadoc block tag @noinspection"
/>
</module>
<module name="SuppressWarningsHolder"/>
<!-- Block Checks -->
<module name="AvoidNestedBlocks">
<property name="allowInSwitchCase" value="true"/>
</module>
<module name="NeedBraces"/>
<module name="NeedBraces">
<property name="tokens" value="LAMBDA"/>
<property name="allowSingleLineStatement" value="true"/>
</module>
<!-- Class Design -->
<module name="DesignForExtension">
<property name="ignoredAnnotations"
value="Override, Test, Before, After, BeforeClass, AfterClass"/>
</module>
<module name="FinalClass"/>
<module name="HideUtilityClassConstructor"/>
<module name="InnerTypeLast"/>
<module name="InterfaceIsType"/>
<module name="MutableException"/>
<module name="OneTopLevelClass"/>
<module name="ThrowsCount">
<property name="max" value="2"/>
</module>
<module name="VisibilityModifier"/>
<!-- Coding -->
<module name="ArrayTrailingComma"/>
<module name="AvoidInlineConditionals"/>
<module name="CovariantEquals"/>
<module name="DeclarationOrder"/>
<module name="DefaultComesLast"/>
<module name="EmptyStatement"/>
<module name="EqualsAvoidNull"/>
<module name="EqualsHashCode"/>
<module name="ExplicitInitialization"/>
<module name="FallThrough"/>
<module name="FinalLocalVariable"/>
<module name="HiddenField">
<property name="ignoreConstructorParameter" value="true"/>
<property name="ignoreSetter" value="true"/>
<property name="setterCanReturnItsClass" value="true"/>
</module>
<module name="IllegalInstantiation">
<property name="classes"
value="org.xml.sax.SAXException, org.xml.sax.SAXParseException,
org.apache.commons.beanutils.ConversionException,
org.antlr.v4.runtime.misc.ParseCancellationException,
antlr.RecognitionException, antlr.TokenStreamException,
antlr.TokenStreamRecognitionException, antlr.ANTLRException,
java.lang.StringBuffer"/>
</module>
<module name="IllegalThrows"/>
<module name="IllegalToken">
<property name="tokens" value="LABELED_STAT"/>
<property name="tokens" value="LITERAL_NATIVE"/>
<property name="tokens" value="LITERAL_VOLATILE"/>
<property name="tokens" value="LITERAL_ASSERT"/>
</module>
<module name="IllegalTokenText">
<property name="tokens" value="STRING_LITERAL"/>
<property name="format" value="^(US-ASCII|ISO-8859-1|UTF-8|UTF-16BE|UTF-16LE|UTF-16)$"/>
<property name="ignoreCase" value="true"/>
</module>
<module name="IllegalType">
<property name="illegalClassNames"
value="java.util.HashSet, HashSet, java.util.LinkedHashMap, LinkedHashMap,
java.util.TreeMap, TreeMap, java.util.HashMap, HashMap,
java.util.LinkedHashSet, LinkedHashSet, java.util.TreeSet, TreeSet,
java.lang.StringBuffer, StringBuffer"/>
</module>
<module name="InnerAssignment"/>
<module name="MissingCtor">
<!--
we will not use that fanatic validation, extra code is not good
But this Check will exists as it was created by community demand.
-->
<property name="severity" value="ignore"/>
</module>
<module name="MissingSwitchDefault"/>
<module name="ModifiedControlVariable"/>
<module name="MultipleVariableDeclarations"/>
<module name="NestedForDepth">
<property name="max" value="2"/>
</module>
<module name="NestedIfDepth">
<property name="max" value="3"/>
</module>
<module name="NestedTryDepth"/>
<module name="NoClone"/>
<module name="NoFinalizer"/>
<module name="OneStatementPerLine"/>
<module name="OverloadMethodsDeclarationOrder"/>
<module name="PackageDeclaration"/>
<module name="ParameterAssignment"/>
<module name="RequireThis"/>
<module name="ReturnCount">
<property name="max" value="1"/>
<property name="maxForVoid" value="0"/>
</module>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
<module name="StringLiteralEquality"/>
<module name="SuperClone"/>
<module name="SuperFinalize"/>
<module name="UnnecessaryParentheses"/>
<module name="VariableDeclarationUsageDistance"/>
<!-- Filters-->
<module name="SuppressionCommentFilter">
<!--
Use suppressions.xml for suppressions, this is only example.
checkFormat will prevent suppression comments from being valid.
-->
<property name="checkFormat" value="IGNORETHIS"/>
<property name="offCommentFormat" value="CSOFF\: .*"/>
<property name="onCommentFormat" value="CSON\: .*"/>
</module>
<!-- Tone down the checking for test code -->
<module name="SuppressionXpathSingleFilter">
<property name="files" value="[\\/]internal[\\/].*[\\/]\w+Util\.java"/>
<property name="checks" value="IllegalCatch"/>
</module>
<module name="SuppressionXpathSingleFilter">
<property name="files" value=".*[\\/]src[\\/]test[\\/]"/>
<property name="checks" value="EmptyBlock"/>
</module>
<module name="SuppressionXpathSingleFilter">
<property name="files" value=".*[\\/]src[\\/](test|it)[\\/]"/>
<property name="checks" value="JavadocVariable"/>
</module>
<module name="SuppressionXpathSingleFilter">
<property name="files" value=".*[\\/]src[\\/](test|it)[\\/]"/>
<property name="checks" value="JavadocType"/>
</module>
<module name="SuppressionXpathSingleFilter">
<property name="files" value=".*[\\/]src[\\/](test|it)[\\/]"/>
<property name="checks" value="MagicNumber"/>
</module>
<module name="SuppressionXpathSingleFilter">
<property name="files" value=".*[\\/]src[\\/](test|it)[\\/]"/>
<property name="checks" value="AvoidStaticImport"/>
</module>
<module name="SuppressionXpathSingleFilter">
<property name="files" value=".*[\\/]src[\\/](test|it)[\\/]"/>
<property name="checks" value="WriteTag"/>
</module>
<module name="SuppressionXpathSingleFilter">
<property name="files" value=".*[\\/]src[\\/](test|it)[\\/]"/>
<property name="checks" value="MethodCount"/>
</module>
<!-- Fixing these cases will decrease code readability -->
<module name="SuppressionXpathSingleFilter">
<property name="files" value=".*[\\/]src[\\/](test|it)[\\/]"/>
<property name="checks" value="MultipleStringLiterals"/>
</module>
<module name="SuppressWithNearbyCommentFilter">
<property name="commentFormat"
value="-@cs\[(\w{8,}(\|\w{8,})*)\] \w[\(\)\-\.\'\`\,\:\;\w ]{10,}"/>
<property name="checkFormat" value="$1"/>
<property name="influenceFormat" value="3"/>
</module>
<!-- Imports -->
<module name="AvoidStarImport"/>
<module name="AvoidStaticImport"/>
<module name="CustomImportOrder">
<property name="customImportOrderRules"
value="STATIC###STANDARD_JAVA_PACKAGE###SPECIAL_IMPORTS"/>
<property name="specialImportsRegExp" value="^org\."/>
<property name="sortImportsInGroupAlphabetically" value="true"/>
<property name="separateLineBetweenGroups" value="true"/>
</module>
<module name="IllegalImport"/>
<module name="ImportOrder">
<property name="groups" value="/^java\./,javax,org"/>
<property name="ordered" value="true"/>
<property name="separated" value="true"/>
<property name="option" value="top"/>
<property name="sortStaticImportsAlphabetically" value="true"/>
</module>
<module name="RedundantImport"/>
<module name="UnusedImports"/>
<!-- Metrics -->
<module name="BooleanExpressionComplexity">
<property name="max" value="7"/>
</module>
<module name="ClassDataAbstractionCoupling">
<!-- Default classes are also listed-->
<property name="excludedClasses"
value="boolean, byte, char, double, float, int, long, short, void,
Boolean, Byte, Character, Double, Float, Integer, Long, Short, Void,
Object, Class, String, StringBuffer, StringBuilder,
ArrayIndexOutOfBoundsException, Exception, RuntimeException,
IllegalArgumentException, IllegalStateException,
IndexOutOfBoundsException, NullPointerException, Throwable,
SecurityException, UnsupportedOperationException, List, ArrayList,
Deque, Queue, LinkedList, Set, HashSet, SortedSet, TreeSet, Map,
HashMap, SortedMap, TreeMap, DetailsAST,
UnsupportedEncodingException, BuildException, ConversionException,
FileNotFoundException, TestException"/>
</module>
<module name="NPathComplexity"/>
<!-- Misc -->
<module name="ArrayTypeStyle"/>
<module name="AvoidEscapedUnicodeCharacters">
<property name="allowIfAllCharactersEscaped" value="true"/>
</module>
<module name="CommentsIndentation"/>
<module name="DescendantToken"/>
<module name="FinalParameters">
<!--
we will not use that fanatic validation, extra modifiers pollute a code
it is better to use extra validation(Check) that argument is reassigned
But this Check will exists as it was created by community demand.
-->
<property name="severity" value="ignore"/>
</module>
<module name="Indentation">
<property name="basicOffset" value="4"/>
<property name="braceAdjustment" value="0"/>
<property name="caseIndent" value="4"/>
<property name="throwsIndent" value="8"/>
</module>
<module name="OuterTypeFilename"/>
<module name="TodoComment">
<property name="format" value="(TODO)|(FIXME)" />
</module>
<module name="TrailingComment"/>
<module name="UncommentedMain">
<property name="excludedClasses" value="\.(Main|JavadocPropertiesGenerator)$"/>
</module>
<module name="UpperEll"/>
<!-- Modifiers -->
<module name="ClassMemberImpliedModifier">
<!-- effectively the opposite of RedundantModifier, so output must be ignored -->
<property name="severity" value="ignore"/>
</module>
<module name="InterfaceMemberImpliedModifier">
<!-- effectively the opposite of RedundantModifier, so output must be ignored -->
<property name="severity" value="ignore"/>
</module>
<module name="ModifierOrder"/>
<module name="RedundantModifier"/>
<!-- Naming Conventions -->
<module name="AbstractClassName"/>
<module name="ClassTypeParameterName"/>
<module name="ConstantName"/>
<module name="InterfaceTypeParameterName"/>
<module name="LocalFinalVariableName"/>
<module name="LocalVariableName">
<property name="format" value="^(id)|([a-z][a-z0-9][a-zA-Z0-9]+)$"/>
<property name="allowOneCharVarInForLoop" value="true"/>
</module>
<module name="MemberName">
<property name="format" value="^(id)|([a-z][a-z0-9][a-zA-Z0-9]+)$"/>
</module>
<module name="MethodName"/>
<module name="MethodTypeParameterName"/>
<module name="PackageName"/>
<module name="ParameterName">
<property name="format" value="^(id)|([a-z][a-z0-9][a-zA-Z0-9]+)$"/>
<property name="ignoreOverridden" value="true"/>
</module>
<module name="LambdaParameterName">
<property name="format" value="^(id)|([a-z][a-z0-9][a-zA-Z0-9]+)$"/>
</module>
<module name="CatchParameterName">
<property name="format" value="^(ex|[a-z][a-z][a-zA-Z]+)$"/>
</module>
<module name="StaticVariableName">
<property name="format" value="^(id)|([a-z][a-z0-9][a-zA-Z0-9]+)$"/>
</module>
<module name="TypeName"/>
<!-- Regexp -->
<module name="Regexp"/>
<module name="RegexpSinglelineJava"/>
<module name="RegexpSinglelineJava">
<property name="format" value="[^\p{ASCII}]"/>
<property name="ignoreComments" value="true"/>
</module>
<!-- Size Violations -->
<module name="AnonInnerLength"/>
<module name="ExecutableStatementCount">
<property name="max" value="30"/>
</module>
<module name="MethodCount">
<property name="maxTotal" value="34"/>
</module>
<module name="MethodLength"/>
<module name="OuterTypeNumber"/>
<module name="ParameterNumber"/>
<!-- Whitespace -->
<module name="EmptyForInitializerPad"/>
<module name="EmptyForIteratorPad"/>
<module name="EmptyLineSeparator">
<property name="allowNoEmptyLineBetweenFields" value="true"/>
<property name="allowMultipleEmptyLinesInsideClassMembers" value="false"/>
</module>
<module name="GenericWhitespace"/>
<module name="MethodParamPad"/>
<module name="NoLineWrap"/>
<module name="NoWhitespaceAfter">
<property name="tokens" value="ARRAY_INIT"/>
<property name="tokens" value="AT"/>
<property name="tokens" value="BNOT"/>
<property name="tokens" value="DEC"/>
<property name="tokens" value="DOT"/>
<property name="tokens" value="INC"/>
<property name="tokens" value="LNOT"/>
<property name="tokens" value="UNARY_MINUS"/>
<property name="tokens" value="UNARY_PLUS"/>
<property name="tokens" value="ARRAY_DECLARATOR"/>
<property name="tokens" value="INDEX_OP"/>
<property name="tokens" value="METHOD_REF"/>
</module>
<module name="NoWhitespaceBefore"/>
<module name="NoWhitespaceBefore">
<property name="tokens" value="DOT"/>
<property name="tokens" value="METHOD_REF"/>
<property name="allowLineBreaks" value="true"/>
</module>
<module name="ParenPad"/>
<module name="SeparatorWrap">
<property name="tokens" value="DOT"/>
<property name="tokens" value="AT"/>
<property name="tokens" value="METHOD_REF"/>
<property name="option" value="nl"/>
</module>
<module name="SingleSpaceSeparator">
<property name="validateComments" value="false"/>
</module>
<module name="TypecastParenPad"/>
<module name="WhitespaceAfter"/>
<module name="WhitespaceAround"/>
</module>
</module>

29
pom.xml
View File

@ -4,11 +4,16 @@
<artifactId>Weapons</artifactId>
<version>master</version>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<version>1.13.2-R0.1-SNAPSHOT</version>
</dependency>
</dependencies>
@ -21,6 +26,28 @@
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<configLocation>${basedir}/checkstyle.xml</configLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<enableRulesSummary>false</enableRulesSummary>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<compilerArgs>
<arg>-Xlint:all</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -15,26 +15,28 @@ import org.bukkit.inventory.meta.ItemMeta;
class CommandWeapons implements CommandExecutor {
private void addWeapon(Inventory inventory, Material material, String name) {
ItemStack item = new ItemStack(material, 1);
ItemMeta itemMeta = item.getItemMeta();
final ItemStack item = new ItemStack(material, 1);
final ItemMeta itemMeta = item.getItemMeta();
itemMeta.setDisplayName(name);
item.setItemMeta(itemMeta);
inventory.addItem(item);
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
Player player = (Player)sender;
Inventory inventory = Bukkit.createInventory(null, 18, "Weapons");
final Player player = (Player) sender;
final Inventory inventory = Bukkit.createInventory(null, 18, "Weapons");
addWeapon(inventory, Material.ANVIL, "§rAnvil Dropper");
addWeapon(inventory, Material.SPECTRAL_ARROW, "§rArcher");
addWeapon(inventory, Material.FIREBALL, "§rArmageddon");
addWeapon(inventory, Material.FIRE_CHARGE, "§rArmageddon");
addWeapon(inventory, Material.MAGMA_CREAM, "§rBlobinator");
addWeapon(inventory, Material.EGG, "§rGrenade");
addWeapon(inventory, Material.BLAZE_POWDER, "§rLaser");
addWeapon(inventory, Material.STICK, "§rLightning Stick");
addWeapon(inventory, Material.GOLD_BARDING, "§rMachine Gun");
addWeapon(inventory, Material.GOLDEN_HORSE_ARMOR, "§rMachine Gun");
addWeapon(inventory, Material.BLAZE_ROD, "§rNuker");
addWeapon(inventory, Material.IRON_BARDING, "§rSniper");
addWeapon(inventory, Material.IRON_HORSE_ARMOR, "§rSniper");
player.openInventory(inventory);
return true;
}

View File

@ -6,10 +6,7 @@ import java.util.Random;
import java.util.Set;
import java.util.UUID;
import com.destroystokyo.paper.event.entity.ProjectileCollideEvent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
@ -36,10 +33,12 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerEggThrowEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.material.MaterialData;
import org.bukkit.material.Wool;
import org.bukkit.potion.PotionEffect;
@ -49,6 +48,8 @@ import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import com.destroystokyo.paper.event.entity.ProjectileCollideEvent;
class Events implements Listener {
Main main;
Events(Main main) {
@ -57,80 +58,106 @@ class Events implements Listener {
@EventHandler
void onInventoryClick(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
if ("Weapons".equals(event.getView().getTitle())) {
final ItemStack item = event.getCurrentItem();
if (event.getInventory().getName().equals("Weapons")) {
if (event.getCurrentItem().getItemMeta().hasDisplayName() == true) {
player.getInventory().addItem(event.getCurrentItem());
if (item.getItemMeta().hasDisplayName() == true) {
final Player player = (Player) event.getWhoClicked();
player.getInventory().addItem(item);
player.closeInventory();
player.sendMessage("You have received the " + event.getCurrentItem().getItemMeta().getDisplayName().toLowerCase() + "!");
player.sendMessage("You have received the " + item.getItemMeta().getDisplayName().toLowerCase() + "!");
}
}
}
@EventHandler
void onPlayerEggThrow(PlayerEggThrowEvent event) {
final PlayerInventory inventory = event.getPlayer().getInventory();
final String name = inventory.getItemInMainHand().getItemMeta().getDisplayName();
if ("§rGrenade".equals(name)) {
final Egg egg = event.getEgg();
egg.setCustomName("weaponsGrenade");
event.setHatching(false);
}
}
@EventHandler
void onPlayerInteract(PlayerInteractEvent event) {
if (event.getItem() != null && event.getItem().getItemMeta().hasDisplayName() == true) {
Action action = event.getAction();
Player player = event.getPlayer();
Material item = event.getMaterial();
String name = event.getItem().getItemMeta().getDisplayName();
if (event.hasItem() == true &&
event.getItem().getItemMeta().hasDisplayName() == true) {
final Action action = event.getAction();
final Material item = event.getMaterial();
final String name = event.getItem().getItemMeta().getDisplayName();
World world = player.getLocation().getWorld();
Location eyePos = player.getEyeLocation();
Location lookPos = player.getTargetBlock((Set<Material>) null, 100).getLocation();
Location playerPos = player.getLocation();
Vector direction = eyePos.getDirection();
Location frontPos = playerPos.add(direction);
if (action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK) {
if (item == Material.ANVIL && name.equals("§rAnvil Dropper")) {
if (action == Action.LEFT_CLICK_AIR ||
action == Action.LEFT_CLICK_BLOCK) {
if (item == Material.ANVIL &&
"§rAnvil Dropper".equals(name)) {
for (int x = -2; x <= 2; x++) {
for (int z = -2; z <= 2; z++) {
Location blockPos = new Location(world, playerPos.getX() - x, playerPos.getY(), playerPos.getZ() - z);
MaterialData blockMaterial = new MaterialData(Material.ANVIL);
world.spawnFallingBlock(blockPos, blockMaterial);
final Location blockLocation = event.getPlayer().getLocation().subtract(x, 0, z);
final World world = event.getPlayer().getWorld();
world.spawnFallingBlock(
blockLocation,
Material.ANVIL.createBlockData()
);
}
}
event.setCancelled(true);
} else if (item == Material.SPECTRAL_ARROW && name.equals("§rArcher")) {
world.playSound(playerPos, Sound.BLOCK_ANVIL_DESTROY, 1.0F, 1.5F);
} else if (item == Material.SPECTRAL_ARROW &&
"§rArcher".equals(name)) {
final World world = event.getPlayer().getWorld();
for (int i = 0; i <= 20; i++) {
double randomX = (Math.random() * ((15 + 15) + 1)) - 15;
double randomY = (Math.random() * ((15 + 15) + 1)) - 15;
double randomZ = (Math.random() * ((15 + 15) + 1)) - 15;
final double randomX = (Math.random() * ((15 + 15) + 1)) - 15;
final double randomY = (Math.random() * ((15 + 15) + 1)) - 15;
final double randomZ = (Math.random() * ((15 + 15) + 1)) - 15;
Vector randomDirection = new Vector(randomX, randomY, randomZ).normalize().multiply(8);
final Player player = event.getPlayer();
final Vector randomDirection = new Vector(
randomX,
randomY,
randomZ).normalize().multiply(8);
SpectralArrow arrow = (SpectralArrow) world.spawnEntity(frontPos, EntityType.SPECTRAL_ARROW);
arrow.setCustomName("weaponsProjectileBlock");
final SpectralArrow arrow = (SpectralArrow) world.spawnEntity(
player.getLocation(),
EntityType.SPECTRAL_ARROW
);
arrow.setCustomName("weaponsCancelCollision");
arrow.setShooter(player);
arrow.setVelocity(randomDirection);
}
final Location eyeLocation = event.getPlayer().getEyeLocation();
final float volume = 1.0F;
final float pitch = 1.5F;
world.playSound(
eyeLocation,
Sound.BLOCK_ANVIL_DESTROY,
volume,
pitch
);
event.setCancelled(true);
} else if (item == Material.FIREBALL && name.equals("§rArmageddon")) {
/*for (int i = 0; i <= 30; i++) {
double randomX = (Math.random() * ((15 + 15) + 1)) - 15;
double randomY = (Math.random() * ((15 + 15) + 1)) - 15;
double randomZ = (Math.random() * ((15 + 15) + 1)) - 15;
} else if (item == Material.FIRE_CHARGE &&
"§rArmageddon".equals(name)) {
final World world = event.getPlayer().getWorld();
Vector direction = new Vector(randomX, randomY, randomZ).normalize().multiply(6);
Fireball arrow = player.launchProjectile(Fireball.class);
arrow.setCustomName(player.getName() + "fireballshooter");
arrow.setDirection(direction);
}*/
for (int i = -12; i <= 12; i += 4) {
double x = frontPos.getX() + (i * Math.cos(Math.toRadians(frontPos.getYaw())));
double z = frontPos.getZ() + (i * Math.sin(Math.toRadians(frontPos.getYaw())));
Vector velocity = direction.multiply(12);
final Player player = event.getPlayer();
final Location eyeLocation = player.getEyeLocation();
Fireball fireball = (Fireball) world.spawnEntity(
new Location(world, x, frontPos.getY(), z),
final double x = (i * Math.cos(Math.toRadians(eyeLocation.getYaw())));
final double z = (i * Math.sin(Math.toRadians(eyeLocation.getYaw())));
final Vector velocity = eyeLocation.getDirection().multiply(12);
final Fireball fireball = (Fireball) world.spawnEntity(
eyeLocation.add(x, 0, z),
EntityType.FIREBALL
);
@ -141,69 +168,163 @@ class Events implements Listener {
fireball.setYield(5);
}
world.playSound(eyePos, Sound.ENTITY_GHAST_SHOOT, 0.9F, 1.5F);
final Location eyeLocation = event.getPlayer().getEyeLocation();
final float volume = 0.9F;
final float pitch = 1.5F;
world.playSound(
eyeLocation,
Sound.ENTITY_GHAST_SHOOT,
volume,
pitch
);
event.setCancelled(true);
} else if (item == Material.MAGMA_CREAM && name.equals("§rBlobinator")) {
Vector velocity = direction.multiply(8);
} else if (item == Material.MAGMA_CREAM &&
"§rBlobinator".equals(name)) {
final Player player = event.getPlayer();
final Location eyeLocation = player.getEyeLocation();
final Vector velocity = eyeLocation.getDirection().multiply(8);
Snowball snowball = player.launchProjectile(Snowball.class);
final Snowball snowball = player.launchProjectile(Snowball.class);
snowball.setCustomName("weaponsBlobinatorBall");
snowball.setShooter(player);
snowball.setVelocity(velocity);
world.playSound(eyePos, Sound.ITEM_BOTTLE_EMPTY, 1.0F, 0.8F);
final World world = event.getPlayer().getWorld();
final float volume = 1.0F;
final float pitch = 0.8F;
world.playSound(
eyeLocation,
Sound.ITEM_BOTTLE_EMPTY,
volume,
pitch
);
event.setCancelled(true);
} else if (item == Material.STICK &&
"§rLightning Stick".equals(name)) {
final Player player = event.getPlayer();
final Location lookLocation = player.getTargetBlock((Set<Material>) null, 100).getLocation();
final World world = player.getWorld();
world.strikeLightning(lookLocation);
event.setCancelled(true);
} else if (item == Material.STICK && name.equals("§rLightning Stick")) {
world.strikeLightning(lookPos);
} else if (item == Material.BLAZE_ROD &&
"§rNuker".equals(name)) {
final Player player = event.getPlayer();
final Location eyeLocation = player.getEyeLocation();
final Vector velocity = eyeLocation.getDirection().multiply(10);
event.setCancelled(true);
} else if (item == Material.BLAZE_ROD && name.equals("§rNuker")) {
Vector velocity = direction.multiply(10);
Fireball fireball = player.launchProjectile(Fireball.class);
fireball.setCustomName("weaponsProjectileBlock");
final Fireball fireball = player.launchProjectile(Fireball.class);
fireball.setCustomName("weaponsCancelCollision");
fireball.setShooter(player);
fireball.setVelocity(velocity);
fireball.setYield(8);
world.playSound(eyePos, Sound.ENTITY_GHAST_SHOOT, 0.9F, 1.5F);
world.playSound(eyePos, Sound.ENTITY_BAT_TAKEOFF, 0.8F, 2.0F);
final World world = event.getPlayer().getWorld();
final float volume1 = 0.9F;
final float pitch1 = 1.5F;
final float volume2 = 0.8F;
final float pitch2 = 2.0F;
world.playSound(
eyeLocation,
Sound.ENTITY_GHAST_SHOOT,
volume1,
pitch1
);
world.playSound(
eyeLocation,
Sound.ENTITY_BAT_TAKEOFF,
volume2,
pitch2
);
event.setCancelled(true);
} else if (item == Material.IRON_BARDING && name.equals("§rSniper")) {
Vector velocity = direction.multiply(12);
} else if (item == Material.IRON_HORSE_ARMOR &&
"§rSniper".equals(name)) {
final Player player = event.getPlayer();
final Location eyeLocation = player.getEyeLocation();
final Vector velocity = eyeLocation.getDirection().multiply(12);
Snowball snowball = player.launchProjectile(Snowball.class);
snowball.setCustomName("weaponsProjectileBlock");
final Snowball snowball = player.launchProjectile(Snowball.class);
snowball.setCustomName("weaponsCancelCollision");
snowball.setShooter(player);
snowball.setVelocity(velocity);
world.playSound(eyePos, Sound.BLOCK_PISTON_CONTRACT, 1.0F, 63.0F);
final World world = event.getPlayer().getWorld();
final float volume = 1.0F;
final float pitch = 63.0F;
world.playSound(
eyeLocation,
Sound.BLOCK_PISTON_CONTRACT,
volume,
pitch
);
event.setCancelled(true);
}
} else if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) {
if (item == Material.BLAZE_POWDER && name.equals("§rLaser")) {
double distance = eyePos.distance(lookPos);
} else if (action == Action.RIGHT_CLICK_AIR ||
action == Action.RIGHT_CLICK_BLOCK) {
if (item == Material.BLAZE_POWDER &&
"§rLaser".equals(name)) {
final Player player = event.getPlayer();
final Location eyeLocation = player.getEyeLocation();
final Vector direction = eyeLocation.getDirection();
final Location lookLocation = player.getTargetBlock(
(Set<Material>) null,
100).getLocation();
double distance = eyeLocation.distance(lookLocation);
final Location particleLocation = player.getEyeLocation();
final World world = player.getWorld();
if (lookPos == null) {
if (lookLocation == null) {
distance = 50;
}
world.playSound(eyePos, Sound.ENTITY_FIREWORK_BLAST_FAR, 0.8F, 40.0F);
world.playSound(eyePos, Sound.ENTITY_FIREWORK_BLAST, 1.0F, 20.0F);
for (double i = 0; i <= distance; i++) {
frontPos.add(direction);
world.spawnParticle(Particle.REDSTONE, frontPos, 0, 1, 0, 0);
particleLocation.add(direction);
final int count = 1;
final double offsetX = 0;
final double offsetY = 0;
final double offsetZ = 0;
final Particle.DustOptions dustOptions = new Particle.DustOptions(Color.RED, 1);
world.spawnParticle(
Particle.REDSTONE,
particleLocation,
count,
offsetX,
offsetY,
offsetZ,
dustOptions
);
}
world.getBlockAt(lookPos).breakNaturally();
world.getBlockAt(lookLocation).breakNaturally();
final float volume1 = 0.8F;
final float pitch1 = 63.0F;
final float volume2 = 1.0F;
final float pitch2 = 20.0F;
world.playSound(
eyeLocation,
Sound.ENTITY_FIREWORK_ROCKET_BLAST_FAR,
volume1,
pitch1
);
world.playSound(
eyeLocation,
Sound.ENTITY_FIREWORK_ROCKET_BLAST,
volume2,
pitch2
);
event.setCancelled(true);
} else if (item == Material.GOLD_BARDING && name.equals("§rMachine Gun")) {
final UUID playerUUID = player.getUniqueId();
} else if (item == Material.GOLDEN_HORSE_ARMOR &&
"§rMachine Gun".equals(name)) {
final UUID playerUUID = event.getPlayer().getUniqueId();
if (!main.machineGunActive.contains(playerUUID)) {
main.machineGunActive.add(playerUUID);
@ -214,22 +335,40 @@ class Events implements Listener {
public void run() {
i++;
Player playerMachine = eventMachine.getPlayer();
Location eyePosMachine = playerMachine.getEyeLocation();
World worldMachine = playerMachine.getLocation().getWorld();
Vector velocity = eyePosMachine.getDirection().multiply(12);
final Player player = eventMachine.getPlayer();
final Location eyeLocation = player.getEyeLocation();
final World world = player.getWorld();
final Vector velocity = eyeLocation.getDirection().multiply(12);
TippedArrow arrow = playerMachine.launchProjectile(TippedArrow.class);
PotionEffect harm = new PotionEffect(PotionEffectType.HARM, 90000, 3, true, true);
PotionEffect slow = new PotionEffect(PotionEffectType.SLOW, 90000, 3, true, true);
final TippedArrow arrow = player.launchProjectile(TippedArrow.class);
final int duration = 90000;
final int amplifier = 3;
final boolean ambient = true;
final boolean particles = false;
final PotionEffect harm = new PotionEffect(
PotionEffectType.HARM,
duration,
amplifier,
ambient,
particles
);
arrow.setCustomName("weaponsProjectileBlock");
arrow.addCustomEffect(harm, true);
arrow.addCustomEffect(slow, true);
arrow.setShooter(playerMachine);
arrow.setShooter(player);
arrow.setVelocity(velocity);
worldMachine.playSound(eyePosMachine, Sound.ENTITY_GENERIC_EXPLODE, 1.0F, 63.0F);
final float volume = 1.0F;
final float pitch = 63.0F;
world.playSound(
eyeLocation,
Sound.ENTITY_GENERIC_EXPLODE,
volume,
pitch
);
if (i == 20) {
main.machineGunActive.remove(playerUUID);
@ -240,11 +379,21 @@ class Events implements Listener {
}
event.setCancelled(true);
} else if (item == Material.IRON_BARDING && name.equals("§rSniper")) {
} else if (item == Material.IRON_HORSE_ARMOR &&
"§rSniper".equals(name)) {
final Player player = event.getPlayer();
if (player.hasPotionEffect(PotionEffectType.SLOW)) {
player.removePotionEffect(PotionEffectType.SLOW);
} else {
PotionEffect effect = new PotionEffect(PotionEffectType.SLOW, 90000, 7);
final int duration = 90000;
final int amplifier = 7;
final PotionEffect effect = new PotionEffect(
PotionEffectType.SLOW,
duration,
amplifier
);
player.addPotionEffect(effect);
}
@ -254,40 +403,37 @@ class Events implements Listener {
}
}
@EventHandler
void onPlayerEggThrow(PlayerEggThrowEvent event) {
String name = event.getPlayer().getItemInHand().getItemMeta().getDisplayName();
if (name.equals("§rGrenade")) {
Egg egg = event.getEgg();
egg.setCustomName("weaponsGrenade");
event.setHatching(false);
}
}
@EventHandler
void onProjectileCollide(ProjectileCollideEvent event) {
Projectile projectile = event.getEntity();
Entity collidedWith = event.getCollidedWith();
if (event.getEntityType() == EntityType.FIREBALL) {
final Projectile projectile = event.getEntity();
if ("weaponsArmegaddonBall".equals(projectile.getCustomName())) {
final Entity collidedWith = event.getCollidedWith();
if (projectile.getCustomName() != null) {
if (projectile.getType() == EntityType.FIREBALL &&
projectile.getCustomName().equals("weaponsArmegaddonBall")) {
if (collidedWith.getType() == EntityType.PLAYER &&
projectile.getShooter() instanceof Player &&
((Player)projectile.getShooter()).getUniqueId().equals(collidedWith.getUniqueId())) {
projectile.getShooter() instanceof Player &&
((Player) projectile.getShooter()).getUniqueId().equals(collidedWith.getUniqueId())) {
event.setCancelled(true);
} else if (collidedWith.getType() == EntityType.FIREBALL) {
event.setCancelled(true);
}
} else if (projectile.getType() == EntityType.SNOWBALL &&
projectile.getCustomName().equals("weaponsBlobinatorBall")) {
}
} else if (event.getEntityType() == EntityType.SNOWBALL) {
final Projectile projectile = event.getEntity();
if ("weaponsBlobinatorBall".equals(projectile.getCustomName())) {
event.setCancelled(true);
} else if (projectile.getType() == EntityType.SPECTRAL_ARROW &&
projectile.getCustomName().equals("weaponsProjectileBlock")) {
}
} else if (event.getEntityType() == EntityType.SPECTRAL_ARROW) {
final Projectile projectile = event.getEntity();
if ("weaponsProjectileBlock".equals(projectile.getCustomName())) {
final Entity collidedWith = event.getCollidedWith();
if (collidedWith.getType() == EntityType.PLAYER &&
projectile.getShooter() instanceof Player &&
((Player)projectile.getShooter()).getUniqueId().equals(collidedWith.getUniqueId())) {
projectile.getShooter() instanceof Player &&
((Player) projectile.getShooter()).getUniqueId().equals(collidedWith.getUniqueId())) {
event.setCancelled(true);
}
}
@ -296,57 +442,59 @@ class Events implements Listener {
@EventHandler
void onProjectileHit(ProjectileHitEvent event) {
Projectile projectile = event.getEntity();
Block hitBlock = event.getHitBlock();
if (event.getEntityType() == EntityType.EGG) {
final Projectile projectile = event.getEntity();
if (projectile.getType() == EntityType.EGG &&
projectile.getCustomName() != null &&
projectile.getCustomName().equals("weaponsGrenade")) {
World world = projectile.getLocation().getWorld();
world.createExplosion(projectile.getLocation(), 6);
}
if ("weaponsGrenade".equals(projectile.getCustomName())) {
final Location location = projectile.getLocation();
final World world = location.getWorld();
final float power = 6;
if (projectile.getType() == EntityType.TIPPED_ARROW &&
projectile.getCustomName() != null &&
projectile.getCustomName().equals("weaponsProjectileBlock")) {
projectile.remove();
}
world.createExplosion(location, power);
}
} else if (event.getEntityType() == EntityType.TIPPED_ARROW) {
final Projectile projectile = event.getEntity();
if (projectile.getType() == EntityType.SNOWBALL &&
hitBlock != null &&
projectile.getShooter() != null) {
if (projectile.getCustomName() != null && projectile.getCustomName().equals("weaponsBlobinatorBall")) {
int radius = 4;
World world = projectile.getWorld();
if ("weaponsProjectileBlock".equals(projectile.getCustomName())) {
projectile.remove();
}
} else if (event.getEntityType() == EntityType.SNOWBALL) {
final Block hitBlock = event.getHitBlock();
final Projectile projectile = event.getEntity();
DyeColor[] colors = DyeColor.values();
Random random = new Random();
DyeColor color = colors[random.nextInt(colors.length)];
if (hitBlock != null &&
"weaponsBlobinatorBall".equals(projectile.getCustomName())) {
final int radius = 4;
final World world = projectile.getWorld();
HashSet<BlockFace> faces = new HashSet<BlockFace>(Arrays.asList(new BlockFace[] {
final DyeColor[] colors = DyeColor.values();
final Random random = new Random();
final DyeColor color = colors[random.nextInt(colors.length)];
final HashSet<BlockFace> faces = new HashSet<BlockFace>(Arrays.asList(new BlockFace[] {
BlockFace.NORTH,
BlockFace.SOUTH,
BlockFace.WEST,
BlockFace.EAST,
BlockFace.UP,
BlockFace.DOWN
BlockFace.DOWN,
}));
for (int x = -radius; x < radius; x++) {
for (int y = -radius; y < radius; y++) {
for (int z = -radius; z < radius; z++) {
Location blockLocation = new Location(world, hitBlock.getX() + x, hitBlock.getY() + y, hitBlock.getZ() + z);
final Location blockLocation = hitBlock.getLocation().add(x, y, z);
if (blockLocation.distance(hitBlock.getLocation()) <= radius) {
Block block = world.getBlockAt(blockLocation);
final Block block = world.getBlockAt(blockLocation);
if (block.getType() != Material.AIR) {
for (BlockFace face : faces) {
if (block.getRelative(face).getType() == Material.AIR) {
block.setType(Material.WOOL);
block.setType(Material.LEGACY_WOOL);
BlockState state = block.getState();
Wool wool = (Wool) state.getData();
final BlockState state = block.getState();
final Wool wool = (Wool) state.getData();
wool.setColor(color);
state.setData(wool);
state.update();

View File

@ -1,6 +1,7 @@
name: Weapons
main: pw.kaboom.weapons.Main
description: Plugin that implements various kinds of weapons.
api-version: 1.13
version: master
commands: