First version

This commit is contained in:
mathias 2018-07-11 18:29:59 +03:00
parent 9f0dc4598a
commit be755ef2f2
6 changed files with 215 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.gradle/
target/

24
LICENSE Normal file
View File

@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org>

2
build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
mvn package

43
pom.xml Normal file
View File

@ -0,0 +1,43 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>pw.kaboom</groupId>
<artifactId>Weapons</artifactId>
<version>1.0.0</version>
<properties>
<maven.compiler.source>7</maven.compiler.source>
<maven.compiler.target>7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>destroystokyo-repo</id>
<url>https://repo.destroystokyo.com/repository/maven-public/</url>
</repository>
</repositories>
<build>
<finalName>${project.artifactId}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>

View File

@ -0,0 +1,133 @@
package pw.kaboom.weapons;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.material.MaterialData;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public class Main extends JavaPlugin implements Listener {
public void onEnable() {
this.getCommand("weapons").setExecutor(new CommandWeapons());
this.getServer().getPluginManager().registerEvents(this, this);
}
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
ItemStack clickedItem = event.getCurrentItem();
String name = clickedItem.getItemMeta().getDisplayName().toLowerCase();
if (event.getInventory().getName() == "Weapons") {
if (clickedItem != null) {
player.getInventory().addItem(clickedItem);
player.closeInventory();
player.sendMessage("You have received the " + name + "!");
}
}
}
@EventHandler
void onPlayerInteract(PlayerInteractEvent event) {
Action action = event.getAction();
Player player = event.getPlayer();
boolean hasName = event.getItem().getItemMeta().hasDisplayName();
Material item = event.getMaterial();
String name = event.getItem().getItemMeta().getDisplayName();
Location lookPos = player.getTargetBlock((Set<Material>) null, 100).getLocation();
Location playerPos = player.getLocation();
World world = player.getLocation().getWorld();
if (hasName == true) {
if (action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK) {
if (item == Material.ANVIL && name == "Anvil Dropper") {
for (int x = -2; x <= 2; x += 1) {
for (int z = -2; z <= 2; z += 1) {
Location blockPos = new Location(world, playerPos.getX() - x, playerPos.getY(), playerPos.getZ() - z);
MaterialData blockMaterial = new MaterialData(Material.ANVIL);
world.spawnFallingBlock(blockPos, blockMaterial);
}
}
event.setCancelled(true);
} else if (item == Material.STICK && name == "Lightning Stick") {
world.strikeLightning(lookPos);
event.setCancelled(true);
} else if (item == Material.BLAZE_ROD && name == "Nuker") {
Projectile projectile = (Projectile) world.spawnEntity(playerPos, EntityType.FIREBALL);
projectile.setShooter(player);
projectile.setVelocity(playerPos.getDirection().multiply(6));
world.createExplosion(lookPos, 6);
world.playSound(playerPos, Sound.ENTITY_GHAST_SHOOT, 0.9F, 1.5F);
world.playSound(playerPos, Sound.ENTITY_BAT_TAKEOFF, 0.8F, 2.0F);
event.setCancelled(true);
} else if (item == Material.IRON_BARDING && name == "Sniper") {
Location projectilePos = new Location(world, playerPos.getX(), playerPos.getY() + 1.5, playerPos.getZ());
Projectile projectile = (Projectile) world.spawnEntity(projectilePos, EntityType.SNOWBALL);
projectile.setShooter(player);
projectile.setVelocity(playerPos.getDirection().multiply(6));
world.playSound(playerPos, Sound.BLOCK_PISTON_CONTRACT, 1.0F, 63.0F);
event.setCancelled(true);
}
} else if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) {
if (item == Material.IRON_BARDING && name == "Sniper") {
if (player.hasPotionEffect(PotionEffectType.SLOW)) {
player.removePotionEffect(PotionEffectType.SLOW);
} else {
PotionEffect effect = new PotionEffect(PotionEffectType.SLOW, 90000, 7);
player.addPotionEffect(effect);
}
event.setCancelled(true);
}
}
}
}
}
class CommandWeapons implements CommandExecutor {
private void addWeapon(Inventory inventory, Material material, String name) {
ItemStack item = new ItemStack(material, 1);
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, 9, "Weapons");
addWeapon(inventory, Material.ANVIL, "Anvil Dropper");
addWeapon(inventory, Material.STICK, "Lightning Stick");
addWeapon(inventory, Material.BLAZE_ROD, "Nuker");
addWeapon(inventory, Material.IRON_BARDING, "Sniper");
player.openInventory(inventory);
return true;
}
}

View File

@ -0,0 +1,11 @@
name: Weapons
main: pw.kaboom.weapons.Main
description: Plugin that adds weapons.
version: ${project.version}
commands:
weapons:
aliases: weapon
description: Gives you a weapon
usage: /weapons
permission: weapons.command