Skip to content

Commit

Permalink
improve code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
dasavick committed Oct 28, 2018
1 parent 0bec5e1 commit dd46045
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 79 deletions.
120 changes: 120 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
### Maven ###
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties


### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio

*.iml

## Directory-based project format:
.idea/
# if you remove the above rule, at least ignore the following:

# User-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# .idea/dictionaries

# Sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml
# .idea/uiDesigner.xml

# Gradle:
# .idea/gradle.xml
# .idea/libraries

# Mongo Explorer plugin:
# .idea/mongoSettings.xml

## File-based project format:
*.ipr
*.iws

## Plugin-specific files:

# IntelliJ
/out/
/bin/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties


### Eclipse ###
*.pydevproject
.metadata
.gradle
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath

# Eclipse Core
.project

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# JDT-specific (Eclipse Java Development Tools)
.classpath

# Java annotation processor (APT)
.factorypath

# PDT-specific
.buildpath

# sbteclipse plugin
.guild

# TeXlipse plugin
.texlipse


### Java ###
*.class

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# Personal debugging stuff
debugging/
11 changes: 9 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

<groupId>pl.daffit</groupId>
<artifactId>megakilof</artifactId>
<version>1.2-SNAPSHOT</version>
<name>MegaKilof Reloaded</name>
<version>2.0-SNAPSHOT</version>

<repositories>
<repository>
Expand All @@ -19,14 +20,20 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.11.2-R0.1-SNAPSHOT</version>
<version>1.12.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<finalName>megakilof-${project.version}</finalName>
<defaultGoal>clean install</defaultGoal>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

<properties>
Expand Down
76 changes: 50 additions & 26 deletions src/main/java/pl/daffit/megakilof/MegaKilofPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,87 @@
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import pl.daffit.megakilof.command.DajkilofaCommand;
import pl.daffit.megakilof.command.MegakilofCommand;
import pl.daffit.megakilof.listener.InventoryClickListener;

import java.util.Collections;
import java.util.List;

public class MegaKilofPlugin extends JavaPlugin {
public class MegaKilofPlugin extends JavaPlugin implements Listener {

public static final String MEGA_GUI_TITLE = ChatColor.translateAlternateColorCodes('&', "&a&lCRAF&f&lTING");
public static final String MEGA_ITEM_NAME = ChatColor.translateAlternateColorCodes('&', "&a&lMEGA &f&lKILOF");
public static final List<String> MEGA_ITEM_LORE = Collections.unmodifiableList(Collections.singletonList("Kilof Zostal Stworzony z kos z csgo"));
public static final String CONSOLE_DENY_MESSAGE = ChatColor.translateAlternateColorCodes('&', "&cKonsola Nie Moze Kilofa");
public static final String PERMISSION_DENY_MESSAGE = ChatColor.translateAlternateColorCodes('&', "&cKomenda Tylko Dla Adminow");
public static final String ADMIN_PERMISSION = "KILOF.ADMIN";

private Inventory megaInventory;
private ItemStack megaKilof;
private ItemStack megaItem;

public Inventory getMegaInventory() {
return megaInventory;
return this.megaInventory;
}

public ItemStack getMegaKilof() {
return megaKilof;
public ItemStack getMegaItem() {
return this.megaItem;
}

@Override
public void onEnable() {

// mega kilof
megaInventory = Bukkit.createInventory(null, 27, ChatColor.translateAlternateColorCodes('&', "&a&lCRAF&f&lTING"));
megaInventory.setItem(3, new ItemStack(Material.DIAMOND_BLOCK));
megaInventory.setItem(4, new ItemStack(Material.DIAMOND_BLOCK));
megaInventory.setItem(5, new ItemStack(Material.DIAMOND_BLOCK));
megaInventory.setItem(13, new ItemStack(Material.STICK));
megaInventory.setItem(22, new ItemStack(Material.STICK));

// mega kilof
this.megaKilof = new ItemStack(Material.DIAMOND_PICKAXE);
ItemMeta megaMeta = this.megaKilof.getItemMeta();
megaMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&a&lMEGA &f&lKILOF"));
megaMeta.setLore(Collections.singletonList("Kilof Zostal Stworzony z kos z csgo"));
// create mega inventory
this.megaInventory = Bukkit.createInventory(null, 27, MEGA_GUI_TITLE);
this.megaInventory.setItem(3, new ItemStack(Material.DIAMOND_BLOCK));
this.megaInventory.setItem(4, new ItemStack(Material.DIAMOND_BLOCK));
this.megaInventory.setItem(5, new ItemStack(Material.DIAMOND_BLOCK));
this.megaInventory.setItem(13, new ItemStack(Material.STICK));
this.megaInventory.setItem(22, new ItemStack(Material.STICK));

// create mega item
this.megaItem = new ItemStack(Material.DIAMOND_PICKAXE);
ItemMeta megaMeta = this.megaItem.getItemMeta();
megaMeta.setDisplayName(MEGA_ITEM_NAME);
megaMeta.setLore(MEGA_ITEM_LORE);
megaMeta.addEnchant(Enchantment.DIG_SPEED, 10, true);
megaMeta.addEnchant(Enchantment.LOOT_BONUS_BLOCKS, 5, true);
megaMeta.addEnchant(Enchantment.DURABILITY, 10, true);
this.megaKilof.setItemMeta(megaMeta);
// mega kilof
ShapedRecipe megaRecipe = new ShapedRecipe(megaKilof).shape("DDD", "ASA", "ASA");
this.megaItem.setItemMeta(megaMeta);

// register recipes
ShapedRecipe megaRecipe = new ShapedRecipe(this.megaItem).shape("DDD", "ASA", "ASA");
megaRecipe.setIngredient('D', Material.DIAMOND_BLOCK);
megaRecipe.setIngredient('A', Material.AIR);
megaRecipe.setIngredient('S', Material.STICK);
this.getServer().addRecipe(megaRecipe);

// mega kilof
// register commands
this.getCommand("megakilof").setExecutor(new MegakilofCommand(this));
this.getCommand("dajkilofa").setExecutor(new DajkilofaCommand(this));

// mega kilof
this.getServer().getPluginManager().registerEvents(new InventoryClickListener(this), this);
// register events
this.getServer().getPluginManager().registerEvents(this, this);
}

@EventHandler
public void onInventoryClickEvent(InventoryClickEvent megaEvent) {

if (megaEvent.getRawSlot() != megaEvent.getSlot()) {
return;
}

if (!MEGA_GUI_TITLE.equals(megaEvent.getClickedInventory().getName())) {
return;
}

megaEvent.setCancelled(true);
}
}
22 changes: 11 additions & 11 deletions src/main/java/pl/daffit/megakilof/command/DajkilofaCommand.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
package pl.daffit.megakilof.command;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import pl.daffit.megakilof.MegaKilofPlugin;

public class DajkilofaCommand implements CommandExecutor {

private final MegaKilofPlugin mega;

public DajkilofaCommand(MegaKilofPlugin mega) {
this.mega = mega;
public DajkilofaCommand(MegaKilofPlugin megaPlugin) {
}

@Override
public boolean onCommand(CommandSender mega, Command kilof, String jest, String[] meega) {
public boolean onCommand(CommandSender megaSender, Command megaCommand, String megaLabel, String[] megaArguments) {

if (!(mega instanceof Player)) {
mega.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cKonsola Nie Moze Kilofa"));
if (!(megaSender instanceof Player)) {
megaSender.sendMessage(MegaKilofPlugin.CONSOLE_DENY_MESSAGE);
return true;
}

if (!mega.hasPermission("KILOF.ADMIN")) {
mega.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cKomenda Tylko Dla Adminow"));
if (!megaSender.hasPermission(MegaKilofPlugin.ADMIN_PERMISSION)) {
megaSender.sendMessage(MegaKilofPlugin.PERMISSION_DENY_MESSAGE);
return true;
}

((Player) mega).getInventory().addItem(new ItemStack(Material.DIAMOND_BLOCK, 3), new ItemStack(Material.STICK, 2));
Player player = ((Player) megaSender);
PlayerInventory inventory = player.getInventory();
inventory.addItem(new ItemStack(Material.DIAMOND_BLOCK, 3), new ItemStack(Material.STICK, 2));

return true;
}
}
15 changes: 7 additions & 8 deletions src/main/java/pl/daffit/megakilof/command/MegakilofCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package pl.daffit.megakilof.command;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand All @@ -9,21 +8,21 @@

public class MegakilofCommand implements CommandExecutor {

private final MegaKilofPlugin mega;
private final MegaKilofPlugin megaPlugin;

public MegakilofCommand(MegaKilofPlugin mega) {
this.mega = mega;
public MegakilofCommand(MegaKilofPlugin megaPlugin) {
this.megaPlugin = megaPlugin;
}

@Override
public boolean onCommand(CommandSender mega, Command kilof, String jest, String[] megaa) {
public boolean onCommand(CommandSender megaSender, Command megaCommand, String megaLabel, String[] megaArguments) {

if (!(mega instanceof Player)) {
mega.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cKonsola Nie Moze Kilofa"));
if (!(megaSender instanceof Player)) {
megaSender.sendMessage(MegaKilofPlugin.CONSOLE_DENY_MESSAGE);
return true;
}

((Player) mega).openInventory(this.mega.getMegaInventory());
((Player) megaSender).openInventory(this.megaPlugin.getMegaInventory());
return true;
}
}

This file was deleted.

6 changes: 3 additions & 3 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: megakilof
version: x1.2
name: ${project.name}
version: ${project.version}
main: pl.daffit.megakilof.MegaKilofPlugin
author: Daffit
author: PinkLolicorn
commands:
megakilof: {}
dajkilofa: {}

0 comments on commit dd46045

Please sign in to comment.